2002-03-06 11:22:27

by Adam J. Richter

[permalink] [raw]
Subject: Patch?: Centralized DMA mapping in linux-2.5.6-pre2/drivers/scsi/scsi.c

I have been exploring the daunting task of trying to port
the numerous scsi drivers in 2.5.6-pre2 that no longer build to
the DMA mapping interface described in Documentation/DMA-mapping.txt.
There are approximately 90 scsi host controller drivers in Linus's
tree. I believe that most of the effected drivers will need to
implement almost exactly the same code.

So, I have created the following patch which defines two
new flags that scsi host templates can set, which tell scsi.c to
handle mapping (and unmapping) or Scsi_Request.request_buffer and
Scsi_Request.sense_buffer, respectively (some drivers have no use
for mapping sense_buffer). All of the executable code is contained
in two static routines, scsi_map_dma and scsi_unmap_dma. So, the
patch should be pretty readable.

I believe this approach has the following advantages:

o less code to maintain
o faster cleanup of drivers/scsi
o saves a few bytes of system size if more than one
device driver
o drivers that do not use this facility should be unaffected,
o easier to make changes in the future, for example:
- scsi_map_dma could change all requests
that have use_sg=0 to one that have use_sg=1,
so drivers could eliminate the use_sg=0 case
before it becomes necessary to change all clients
to avoid use_sg=0.
- Perhaps DMA mapping could be moved out to
scsi_allocate_device and scsi_release_request,
so that it could be done a little less often.
- Perhaps allocate sense_buffer or request_buffer
via pci_pool_alloc, so it can be allocated from
high memory on systems that can DMA to it.

Here are some small disadvantages, and why this the change is worth it.

o Any driver that does not use named initializers for
its Scsi_Host_Template will break, but it's really unlikely
that such drivers have been maintained to reflect the
other 2.5 changes and not have named initializers.

o This change 20 bytes to Scsi_Request, but its a big
data structure to begin with and some of that
size can be made up if we can eliminate the use_sg=0
and, in many cases, the new variables are eliminating
the need to create the same variables in driver private
data.

o Right now, I only know that it compiles and links without
undefined symbols, but drivers that do not set the new
flags should not be affected.

Comments? Bugs in my implementation?

--
Adam J. Richter __ ______________ 4880 Stevens Creek Blvd, Suite 104
[email protected] \ / San Jose, California 95129-1034
+1 408 261-6630 | g g d r a s i l United States of America
fax +1 408 261-6631 "Free Software For The Rest Of Us."


Attachments:
(No filename) (2.65 kB)
dmamap.diff (4.05 kB)
Download all attachments