[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:
Michael Brown
2020-11-28 20:26:28 +00:00
parent 70e6e83243
commit 8d337ecdae
16 changed files with 342 additions and 391 deletions
+15 -31
View File
@@ -276,24 +276,6 @@ intel_init_mbox ( struct intel_mailbox *mbox, unsigned int ctrl,
mbox->mem = mem;
}
/** Transmit ring */
struct intel_tx_ring {
/** Descriptor ring */
struct intel_ring ring;
/** DMA mappings */
struct dma_mapping map[INTEL_NUM_TX_DESC];
};
/** Receive ring */
struct intel_rx_ring {
/** Descriptor ring */
struct intel_ring ring;
/** I/O buffers */
struct io_buffer *iobuf[INTEL_NUM_RX_DESC];
/** DMA mappings */
struct dma_mapping map[INTEL_NUM_RX_DESC];
};
/** An Intel network card */
struct intel_nic {
/** Registers */
@@ -317,10 +299,12 @@ struct intel_nic {
/** Mailbox */
struct intel_mailbox mbox;
/** Transmit ring */
struct intel_tx_ring tx;
/** Receive ring */
struct intel_rx_ring rx;
/** Transmit descriptor ring */
struct intel_ring tx;
/** Receive descriptor ring */
struct intel_ring rx;
/** Receive I/O buffers */
struct io_buffer *rx_iobuf[INTEL_NUM_RX_DESC];
};
/** Driver flags */
@@ -349,14 +333,14 @@ static inline void intel_diag ( struct intel_nic *intel ) {
DBGC ( intel, "INTEL %p TX %04x(%02x)/%04x(%02x) "
"RX %04x(%02x)/%04x(%02x)\n", intel,
( intel->tx.ring.cons & 0xffff ),
readl ( intel->regs + intel->tx.ring.reg + INTEL_xDH ),
( intel->tx.ring.prod & 0xffff ),
readl ( intel->regs + intel->tx.ring.reg + INTEL_xDT ),
( intel->rx.ring.cons & 0xffff ),
readl ( intel->regs + intel->rx.ring.reg + INTEL_xDH ),
( intel->rx.ring.prod & 0xffff ),
readl ( intel->regs + intel->rx.ring.reg + INTEL_xDT ) );
( intel->tx.cons & 0xffff ),
readl ( intel->regs + intel->tx.reg + INTEL_xDH ),
( intel->tx.prod & 0xffff ),
readl ( intel->regs + intel->tx.reg + INTEL_xDT ),
( intel->rx.cons & 0xffff ),
readl ( intel->regs + intel->rx.reg + INTEL_xDH ),
( intel->rx.prod & 0xffff ),
readl ( intel->regs + intel->rx.reg + INTEL_xDT ) );
}
extern void intel_describe_tx ( struct intel_descriptor *tx,
@@ -371,7 +355,7 @@ extern int intel_create_ring ( struct intel_nic *intel,
extern void intel_destroy_ring ( struct intel_nic *intel,
struct intel_ring *ring );
extern void intel_refill_rx ( struct intel_nic *intel );
extern void intel_flush ( struct intel_nic *intel );
extern void intel_empty_rx ( struct intel_nic *intel );
extern int intel_transmit ( struct net_device *netdev,
struct io_buffer *iobuf );
extern void intel_poll_tx ( struct net_device *netdev );