Page MenuHomeFreeBSD

xDMA enqueuing (scatter-gather) support
AbandonedPublic

Authored by br on Feb 15 2017, 4:14 PM.
Tags
None
Referenced Files
F83124409: D9617.id25434.diff
Mon, May 6, 3:42 PM
Unknown Object (File)
Fri, Apr 26, 8:57 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Unknown Object (File)
Fri, Apr 26, 8:56 PM
Subscribers
None

Details

Reviewers
kan
jhb
rwatson
Summary

Typical operation example:

Network device driver call flow:

/* Get xDMA controller */
sc->xdma_tx = xdma_ofw_get(sc->dev, "tx");

/* Allocate virtual channel */
sc->xchan_tx = xdma_channel_alloc(sc->xdma_tx, caps);
int
atse_xdma_tx_intr(void *arg, xdma_transfer_status_t *status)
{
    for (;;) {
            err = xdma_dequeue_mbuf(sc->xchan_tx, &m, &st);
            if (err != 0) {
                    break;
            }
    }
}

/* Setup interrupt handler. */
xdma_setup_intr(sc->xchan_tx, atse_xdma_tx_intr, sc, &sc->ih_tx);

/* Prepare SG transfer */
xdma_prep_sg(sc->xchan_tx, TX_QUEUE_SIZE);
/* Enqueue (multiple) mbufs to receive */
m = m_getcl();
xdma_enqueue_mbuf(sc->xchan_rx, &m, 0, 4, 4, XDMA_DEV_TO_MEM);
m = m_getcl();
xdma_enqueue_mbuf(sc->xchan_rx, &m, 0, 4, 4, XDMA_DEV_TO_MEM);
...
xdma_queue_submit(sc->xchan_rx);
/* Enqueue mbuf to transmit */
xdma_enqueue_mbuf(sc->xchan_tx, &m, 0, 4, 4, XDMA_MEM_TO_DEV);
xdma_queue_submit(sc->xchan_tx);

DMA engine driver functions:

/* Prepare a channel for SG transfer */
softdma_channel_prep_sg(device_t dev, struct xdma_channel *xchan)
{
...
}

/* Submit sg list */
softdma_channel_submit_sg(device_t dev, struct xdma_channel *xchan,
    struct xdma_sglist *sg, uint32_t sg_n) 
{
...
}

/* Provide the amount of free entries for requests. */
softdma_channel_capacity(device_t dev, xdma_channel_t *xchan,
    uint32_t *capacity)
{
...
}

Example usage:
xDMA support for atse(4) D9618
mSGDMA driver D9619
SoftDMA® driver D9620
ARM PrimeCell® PL330 driver D10201
Cadence Quad SPI Flash driver D10245

Test Plan

tested with:

  • atse(4) driver, Altera SoftDMA® and mSGDMA engines.
  • Cadence QSPI driver and ARM PrimeCell® DMA engine.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
br updated this object.
br updated this object.
br updated this object.
br edited the test plan for this revision. (Show Details)

don't use busdma for SoftDMA®

request caps on channel allocation

sys/dev/xdma/xdma.h
153

Can you use little more consistent naming please? xchan_buf is turning into xdma_buf magically here.

kan requested changes to this revision.Feb 20 2017, 5:26 PM
kan edited edge metadata.

This kinda somewhat works for mbufs, but not much more.

sys/dev/xdma/xdma.c
386

Why? How xchan knows boundaries handed by the underlying DMA device? How does it even know if bus_get_dma_tag(xdma->dev) is even a right tag to be used for descriptors? Descriptors often have much stricter requirements on alignment and locations of descriptors and just 'uint32_t desc_size, uint32_t align' cannot possibly describe them. The operation does not belong in generic xchan layer at all and is better left to an actual pdma implementation.

449

Error handling, in particular, freeing already allocated memory and descriptors and unmapping mapped descriptors is considered futile?

465

The name of the function and later use of MCLBYTES do correspond to each other rather weakly. It if an mbuf-specific functionality, name better should reflect that.

470

Same thing. This seems to be very mbuf specific and ridden with arbitrary limitations.

493

Again, WHY???

512

BUS_DMA_COHERENT???

626

You did not protect XCHAN_DESC_ALLOCATED with ()'s above, why now?

650

Same here? Why ()'?

998

()'s again

sys/dev/xdma/xdma.h
227–232

Why is this a function? Asserts are supposed to maintain the call site information in form of file:line and functions are good at obscuring that.

This revision now requires changes to proceed.Feb 20 2017, 5:26 PM
sys/dev/xdma/xdma.c
348–349

This is a xdma_desc_dmamap_cb in , the name is too short and nondescript. I do not think descriptor allocation belongs in xdma at all, but this is wrong nonetheless.

642

This is unconditional? You did not call map_create for !XCHAN_CAP_BUSDMA case.

647

You did not create tag either.

985

By using circular buffer here you encode the requirement that dma requests should be completed by the controller in the order they were submitted, but that is not necessarily the case. I guess same applies by sglists.

1057

Is there a direct relationship of number of mbuf fragments and number of physical addresses it can result in?

1072

What happens if segment in the middle completes with the error?
Also, what is st_trasferred and in what units it is specified? You invoke callback in per-desc (WHY? DMA driver is not allowed to do desc chaining?), but then only report status on the last desc up the consumer chain.

br updated this object.
br edited edge metadata.

move descriptors allocation out of xDMA

br edited edge metadata.

remove any evidence of descriptors existence
add xchan_capacity method

remove xdma_assert_locked function. Using macro is better way

br marked 2 inline comments as done.Feb 22 2017, 2:23 PM
br added inline comments.
sys/dev/xdma/xdma.c
386

Sounds right, thanks. I moved all the descriptors allocation/handling to DMA engine driver.

sys/dev/xdma/xdma.h
227–232

Agree. We have to use macro, not a function here. So removed

br edited edge metadata.
br marked 3 inline comments as done.

Add support for enqueuing bio: xdma_enqueue_bio()

specify port width for bio transfers

br edited the summary of this revision. (Show Details)
br marked 4 inline comments as done.Apr 4 2017, 12:56 PM
br added inline comments.
sys/dev/xdma/xdma.c
348–349

I moved descriptors allocation to DMA engine drivers. Thanks

470

tag parameters now specified by transfer preparation functions, e.g. xdma_prep_sg

br marked 3 inline comments as done.Apr 4 2017, 1:04 PM
br added inline comments.
sys/dev/xdma/xdma.c
642

Fixed. thanks!

br marked an inline comment as done.

use linked-lists of requests, instead of ring queue

br marked an inline comment as done.

remove xchan_buf_t as not commonly used

sys/dev/xdma/xdma.c
985

I switched back to linked lists. Works a bit slower due to locking, but easier to improve /add features in future.
thanks!

  • add xdma_bank_put() method.
  • BIO queues locking

dehardcode maxnsegs: add it as a parameter to xdma_prep_sg()

ensure sglist is not full

  • add xchan_bank_init()
  • create busdma tag in busdma case only
  • add xchan_bank_free()
  • release resources on xdma_prep_sg() errors

cleanup, ensure kproc_create succeeded

br marked 3 inline comments as done.Apr 19 2017, 12:31 PM