API change for bus_dma
scott_long at btc.adaptec.com
Fri Jun 27 12:50:09 PDT 2003
Andrew Gallatin wrote:
> Scott Long writes:
> > All,
> > As I work towards locking down storage drivers, I'm also preening their
> > use of busdma. A common theme among them is a misuse of
> > bus_dmamap_load() and the associated callback mechanism. For most, the
> Why not just add a way to avoid deferring the callback entirely? I'm
> talking about something like Solaris' ability to pass DDI_DMA_DONTWAIT
> as the callback function to ddi_dma_buf_bind_handle().
As you hinted below, BUS_DMA_NOWAIT does what you want. It will return
ENOMEM to the caller if the bounce buffers cannot be pre-allocated
> My desire is to know immediately whether the DMA mapping failed. If
> it failed, that's OK with me. Since my driver locks users memory and maps
> it for DMA for a potentially unbounded amount of time, I want to
> know about a failure right away, not pile up requests that will never
> be satisfied.
bus_dmamap_load() is designed to always return immediately with either
sucess (meaning that the callback was called), or some sort of error
code. A return of EINPROGRESS means that bouncing was required but
bounce buffers were not available so the callback was defered.
There is a flaw in that bus_dmamap_load() treats every request
individually. If a request comes in that has to be deferred, and
a second request comes in that doesn't need to be deferred, it's
likely that the second request will be serviced before the first.
SCSI drivers (that check EINPROGRESS correctly) get around this by
telling CAM to freeze the queue until the deferred request is
serviced. The better solution is probably for bus_dmamap_load() to
defer any new requests while prior ones are still pending.
More information about the freebsd-arch