Commit c9d6369978411f690513994e6e53e2e6410874a4
Committed by
Konrad Rzeszutek Wilk
1 parent
2d073846b8
Exists in
master
and in
6 other branches
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>
Showing 2 changed files with 22 additions and 69 deletions Side-by-side Diff
drivers/net/xen-netback/common.h
... | ... | @@ -58,10 +58,6 @@ |
58 | 58 | u8 fe_dev_addr[6]; |
59 | 59 | |
60 | 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 | 61 | unsigned int irq; |
66 | 62 | |
67 | 63 | /* List of frontends to notify after a batch of frames sent. */ |
... | ... | @@ -70,8 +66,6 @@ |
70 | 66 | /* The shared rings and indexes. */ |
71 | 67 | struct xen_netif_tx_back_ring tx; |
72 | 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 | 70 | /* Frontend feature information. */ |
77 | 71 | u8 can_sg:1; |
... | ... | @@ -105,6 +99,11 @@ |
105 | 99 | |
106 | 100 | wait_queue_head_t waiting_to_free; |
107 | 101 | }; |
102 | + | |
103 | +static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) | |
104 | +{ | |
105 | + return to_xenbus_device(vif->dev->dev.parent); | |
106 | +} | |
108 | 107 | |
109 | 108 | #define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) |
110 | 109 | #define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) |
drivers/net/xen-netback/netback.c
... | ... | @@ -1577,87 +1577,41 @@ |
1577 | 1577 | |
1578 | 1578 | void xen_netbk_unmap_frontend_rings(struct xenvif *vif) |
1579 | 1579 | { |
1580 | - struct gnttab_unmap_grant_ref op; | |
1581 | - | |
1582 | - if (vif->tx.sring) { | |
1583 | - gnttab_set_unmap_op(&op, (unsigned long)vif->tx_comms_area->addr, | |
1584 | - GNTMAP_host_map, vif->tx_shmem_handle); | |
1585 | - | |
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); | |
1580 | + if (vif->tx.sring) | |
1581 | + xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif), | |
1582 | + vif->tx.sring); | |
1583 | + if (vif->rx.sring) | |
1584 | + xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif), | |
1585 | + vif->rx.sring); | |
1601 | 1586 | } |
1602 | 1587 | |
1603 | 1588 | int xen_netbk_map_frontend_rings(struct xenvif *vif, |
1604 | 1589 | grant_ref_t tx_ring_ref, |
1605 | 1590 | grant_ref_t rx_ring_ref) |
1606 | 1591 | { |
1607 | - struct gnttab_map_grant_ref op; | |
1592 | + void *addr; | |
1608 | 1593 | struct xen_netif_tx_sring *txs; |
1609 | 1594 | struct xen_netif_rx_sring *rxs; |
1610 | 1595 | |
1611 | 1596 | int err = -ENOMEM; |
1612 | 1597 | |
1613 | - vif->tx_comms_area = alloc_vm_area(PAGE_SIZE); | |
1614 | - if (vif->tx_comms_area == NULL) | |
1598 | + err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), | |
1599 | + tx_ring_ref, &addr); | |
1600 | + if (err) | |
1615 | 1601 | goto err; |
1616 | 1602 | |
1617 | - vif->rx_comms_area = alloc_vm_area(PAGE_SIZE); | |
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; | |
1603 | + txs = (struct xen_netif_tx_sring *)addr; | |
1639 | 1604 | BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); |
1640 | 1605 | |
1641 | - gnttab_set_map_op(&op, (unsigned long)vif->rx_comms_area->addr, | |
1642 | - GNTMAP_host_map, rx_ring_ref, vif->domid); | |
1643 | - | |
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; | |
1606 | + err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), | |
1607 | + rx_ring_ref, &addr); | |
1608 | + if (err) | |
1652 | 1609 | goto err; |
1653 | - } | |
1654 | 1610 | |
1655 | - vif->rx_shmem_ref = rx_ring_ref; | |
1656 | - vif->rx_shmem_handle = op.handle; | |
1657 | - vif->rx_req_cons_peek = 0; | |
1658 | - | |
1659 | - rxs = (struct xen_netif_rx_sring *)vif->rx_comms_area->addr; | |
1611 | + rxs = (struct xen_netif_rx_sring *)addr; | |
1660 | 1612 | BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); |
1613 | + | |
1614 | + vif->rx_req_cons_peek = 0; | |
1661 | 1615 | |
1662 | 1616 | return 0; |
1663 | 1617 |