aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netback
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@citrix.com>2011-09-29 11:53:31 -0400
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-10-26 10:02:56 -0400
commitc9d6369978411f690513994e6e53e2e6410874a4 (patch)
treea75b386938b3f8f993c774c06f0e7b2ae830c1de /drivers/net/xen-netback
parent2d073846b891c3f49c4ea03c5db3ac92f92742f1 (diff)
net: xen-netback: use API provided by xenbus module to map rings
The xenbus module provides xenbus_map_ring_valloc() and xenbus_map_ring_vfree(). Use these to map the Tx and Rx ring pages granted by the frontend. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/net/xen-netback')
-rw-r--r--drivers/net/xen-netback/common.h11
-rw-r--r--drivers/net/xen-netback/netback.c80
2 files changed, 22 insertions, 69 deletions
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 161f207786a4..94b79c3338c4 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -58,10 +58,6 @@ struct xenvif {
58 u8 fe_dev_addr[6]; 58 u8 fe_dev_addr[6];
59 59
60 /* Physical parameters of the comms window. */ 60 /* Physical parameters of the comms window. */
61 grant_handle_t tx_shmem_handle;
62 grant_ref_t tx_shmem_ref;
63 grant_handle_t rx_shmem_handle;
64 grant_ref_t rx_shmem_ref;
65 unsigned int irq; 61 unsigned int irq;
66 62
67 /* List of frontends to notify after a batch of frames sent. */ 63 /* List of frontends to notify after a batch of frames sent. */
@@ -70,8 +66,6 @@ struct xenvif {
70 /* The shared rings and indexes. */ 66 /* The shared rings and indexes. */
71 struct xen_netif_tx_back_ring tx; 67 struct xen_netif_tx_back_ring tx;
72 struct xen_netif_rx_back_ring rx; 68 struct xen_netif_rx_back_ring rx;
73 struct vm_struct *tx_comms_area;
74 struct vm_struct *rx_comms_area;
75 69
76 /* Frontend feature information. */ 70 /* Frontend feature information. */
77 u8 can_sg:1; 71 u8 can_sg:1;
@@ -106,6 +100,11 @@ struct xenvif {
106 wait_queue_head_t waiting_to_free; 100 wait_queue_head_t waiting_to_free;
107}; 101};
108 102
103static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
104{
105 return to_xenbus_device(vif->dev->dev.parent);
106}
107
109#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) 108#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
110#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) 109#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
111 110
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index fd00f25d9850..3af2924fe058 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1577,88 +1577,42 @@ static int xen_netbk_kthread(void *data)
1577 1577
1578void xen_netbk_unmap_frontend_rings(struct xenvif *vif) 1578void xen_netbk_unmap_frontend_rings(struct xenvif *vif)
1579{ 1579{
1580 struct gnttab_unmap_grant_ref op; 1580 if (vif->tx.sring)
1581 1581 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1582 if (vif->tx.sring) { 1582 vif->tx.sring);
1583 gnttab_set_unmap_op(&op, (unsigned long)vif->tx_comms_area->addr, 1583 if (vif->rx.sring)
1584 GNTMAP_host_map, vif->tx_shmem_handle); 1584 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1585 1585 vif->rx.sring);
1586 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1587 BUG();
1588 }
1589
1590 if (vif->rx.sring) {
1591 gnttab_set_unmap_op(&op, (unsigned long)vif->rx_comms_area->addr,
1592 GNTMAP_host_map, vif->rx_shmem_handle);
1593
1594 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1595 BUG();
1596 }
1597 if (vif->rx_comms_area)
1598 free_vm_area(vif->rx_comms_area);
1599 if (vif->tx_comms_area)
1600 free_vm_area(vif->tx_comms_area);
1601} 1586}
1602 1587
1603int xen_netbk_map_frontend_rings(struct xenvif *vif, 1588int xen_netbk_map_frontend_rings(struct xenvif *vif,
1604 grant_ref_t tx_ring_ref, 1589 grant_ref_t tx_ring_ref,
1605 grant_ref_t rx_ring_ref) 1590 grant_ref_t rx_ring_ref)
1606{ 1591{
1607 struct gnttab_map_grant_ref op; 1592 void *addr;
1608 struct xen_netif_tx_sring *txs; 1593 struct xen_netif_tx_sring *txs;
1609 struct xen_netif_rx_sring *rxs; 1594 struct xen_netif_rx_sring *rxs;
1610 1595
1611 int err = -ENOMEM; 1596 int err = -ENOMEM;
1612 1597
1613 vif->tx_comms_area = alloc_vm_area(PAGE_SIZE); 1598 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1614 if (vif->tx_comms_area == NULL) 1599 tx_ring_ref, &addr);
1600 if (err)
1615 goto err; 1601 goto err;
1616 1602
1617 vif->rx_comms_area = alloc_vm_area(PAGE_SIZE); 1603 txs = (struct xen_netif_tx_sring *)addr;
1618 if (vif->rx_comms_area == NULL)
1619 goto err;
1620
1621 gnttab_set_map_op(&op, (unsigned long)vif->tx_comms_area->addr,
1622 GNTMAP_host_map, tx_ring_ref, vif->domid);
1623
1624 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1625 BUG();
1626
1627 if (op.status) {
1628 netdev_warn(vif->dev,
1629 "failed to map tx ring. err=%d status=%d\n",
1630 err, op.status);
1631 err = op.status;
1632 goto err;
1633 }
1634
1635 vif->tx_shmem_ref = tx_ring_ref;
1636 vif->tx_shmem_handle = op.handle;
1637
1638 txs = (struct xen_netif_tx_sring *)vif->tx_comms_area->addr;
1639 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); 1604 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
1640 1605
1641 gnttab_set_map_op(&op, (unsigned long)vif->rx_comms_area->addr, 1606 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1642 GNTMAP_host_map, rx_ring_ref, vif->domid); 1607 rx_ring_ref, &addr);
1643 1608 if (err)
1644 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1645 BUG();
1646
1647 if (op.status) {
1648 netdev_warn(vif->dev,
1649 "failed to map rx ring. err=%d status=%d\n",
1650 err, op.status);
1651 err = op.status;
1652 goto err; 1609 goto err;
1653 }
1654
1655 vif->rx_shmem_ref = rx_ring_ref;
1656 vif->rx_shmem_handle = op.handle;
1657 vif->rx_req_cons_peek = 0;
1658 1610
1659 rxs = (struct xen_netif_rx_sring *)vif->rx_comms_area->addr; 1611 rxs = (struct xen_netif_rx_sring *)addr;
1660 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); 1612 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
1661 1613
1614 vif->rx_req_cons_peek = 0;
1615
1662 return 0; 1616 return 0;
1663 1617
1664err: 1618err: