[dma] Move I/O buffer DMA operations to iobuf.h
Include a potential DMA mapping within the definition of an I/O buffer, and move all I/O buffer DMA mapping functions from dma.h to iobuf.h. This avoids the need for drivers to maintain a separate list of DMA mappings for each I/O buffer that they may handle. Network device drivers typically do not keep track of transmit I/O buffers, since the network device core already maintains a transmit queue. Drivers will typically call netdev_tx_complete_next() to complete a transmission without first obtaining the relevant I/O buffer pointer (and will rely on the network device core automatically cancelling any pending transmissions when the device is closed). To allow this driver design approach to be retained, update the netdev_tx_complete() family of functions to automatically perform the DMA unmapping operation if required. For symmetry, also update the netdev_rx() family of functions to behave the same way. As a further convenience for drivers, allow the network device core to automatically perform DMA mapping on the transmit datapath before calling the driver's transmit() method. This avoids the need to introduce a mapping error handling code path into the typically error-free transmit methods. With these changes, the modifications required to update a typical network device driver to use the new DMA API are fairly minimal: - Allocate and free descriptor rings and similar coherent structures using dma_alloc()/dma_free() rather than malloc_phys()/free_phys() - Allocate and free receive buffers using alloc_rx_iob()/free_rx_iob() rather than alloc_iob()/free_iob() - Calculate DMA addresses using dma() or iob_dma() rather than virt_to_bus() - Set a 64-bit DMA mask if needed using dma_set_mask_64bit() and thereafter eliminate checks on DMA address ranges - Either record the DMA device in netdev->dma, or call iob_map_tx() as part of the transmit() method - Ensure that debug messages use virt_to_phys() when displaying "hardware" addresses Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
+17
-16
@@ -380,14 +380,14 @@ static int intelxlvf_admin_configure ( struct net_device *netdev ) {
|
||||
buf->cfg.count = cpu_to_le16 ( 1 );
|
||||
buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
|
||||
buf->cfg.tx.count = cpu_to_le16 ( INTELXL_TX_NUM_DESC );
|
||||
buf->cfg.tx.base = cpu_to_le64 ( dma ( &intelxl->tx.ring.map,
|
||||
intelxl->tx.ring.desc.raw ) );
|
||||
buf->cfg.tx.base = cpu_to_le64 ( dma ( &intelxl->tx.map,
|
||||
intelxl->tx.desc.raw ) );
|
||||
buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
|
||||
buf->cfg.rx.count = cpu_to_le32 ( INTELXL_RX_NUM_DESC );
|
||||
buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
|
||||
buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
|
||||
buf->cfg.rx.base = cpu_to_le64 ( dma ( &intelxl->rx.ring.map,
|
||||
intelxl->rx.ring.desc.raw ) );
|
||||
buf->cfg.rx.base = cpu_to_le64 ( dma ( &intelxl->rx.map,
|
||||
intelxl->rx.desc.raw ) );
|
||||
|
||||
/* Issue command */
|
||||
if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
|
||||
@@ -501,11 +501,11 @@ static int intelxlvf_open ( struct net_device *netdev ) {
|
||||
INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) );
|
||||
|
||||
/* Allocate transmit descriptor ring */
|
||||
if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->tx.ring ) ) != 0 )
|
||||
if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->tx ) ) != 0 )
|
||||
goto err_alloc_tx;
|
||||
|
||||
/* Allocate receive descriptor ring */
|
||||
if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->rx.ring ) ) != 0 )
|
||||
if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->rx ) ) != 0 )
|
||||
goto err_alloc_rx;
|
||||
|
||||
/* Configure queues */
|
||||
@@ -531,9 +531,9 @@ static int intelxlvf_open ( struct net_device *netdev ) {
|
||||
err_enable:
|
||||
err_irq_map:
|
||||
err_configure:
|
||||
intelxl_free_ring ( intelxl, &intelxl->rx.ring );
|
||||
intelxl_free_ring ( intelxl, &intelxl->rx );
|
||||
err_alloc_rx:
|
||||
intelxl_free_ring ( intelxl, &intelxl->tx.ring );
|
||||
intelxl_free_ring ( intelxl, &intelxl->tx );
|
||||
err_alloc_tx:
|
||||
return rc;
|
||||
}
|
||||
@@ -554,13 +554,13 @@ static void intelxlvf_close ( struct net_device *netdev ) {
|
||||
}
|
||||
|
||||
/* Free receive descriptor ring */
|
||||
intelxl_free_ring ( intelxl, &intelxl->rx.ring );
|
||||
intelxl_free_ring ( intelxl, &intelxl->rx );
|
||||
|
||||
/* Free transmit descriptor ring */
|
||||
intelxl_free_ring ( intelxl, &intelxl->tx.ring );
|
||||
intelxl_free_ring ( intelxl, &intelxl->tx );
|
||||
|
||||
/* Flush unused buffers */
|
||||
intelxl_flush ( intelxl );
|
||||
/* Discard any unused receive buffers */
|
||||
intelxl_empty_rx ( intelxl );
|
||||
}
|
||||
|
||||
/** Network device operations */
|
||||
@@ -605,11 +605,11 @@ static int intelxlvf_probe ( struct pci_device *pci ) {
|
||||
&intelxlvf_admin_command_offsets );
|
||||
intelxl_init_admin ( &intelxl->event, INTELXLVF_ADMIN,
|
||||
&intelxlvf_admin_event_offsets );
|
||||
intelxlvf_init_ring ( &intelxl->tx.ring, INTELXL_TX_NUM_DESC,
|
||||
sizeof ( intelxl->tx.ring.desc.tx[0] ),
|
||||
intelxlvf_init_ring ( &intelxl->tx, INTELXL_TX_NUM_DESC,
|
||||
sizeof ( intelxl->tx.desc.tx[0] ),
|
||||
INTELXLVF_QTX_TAIL );
|
||||
intelxlvf_init_ring ( &intelxl->rx.ring, INTELXL_RX_NUM_DESC,
|
||||
sizeof ( intelxl->rx.ring.desc.rx[0] ),
|
||||
intelxlvf_init_ring ( &intelxl->rx, INTELXL_RX_NUM_DESC,
|
||||
sizeof ( intelxl->rx.desc.rx[0] ),
|
||||
INTELXLVF_QRX_TAIL );
|
||||
|
||||
/* Fix up PCI device */
|
||||
@@ -625,6 +625,7 @@ static int intelxlvf_probe ( struct pci_device *pci ) {
|
||||
/* Configure DMA */
|
||||
intelxl->dma = &pci->dma;
|
||||
dma_set_mask_64bit ( intelxl->dma );
|
||||
netdev->dma = intelxl->dma;
|
||||
|
||||
/* Locate PCI Express capability */
|
||||
intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
|
||||
|
||||
Reference in New Issue
Block a user