Skip to contentSkip to conversation

Patch?: Centralized DMA mapping in linux-2.5.6-pre2/drivers/scsi/scsi.c

PATCH Adam J. Richter 1 participant 1 message Mar 6, 2002 SCSI

lore
Share & tools
lore
#0 lore raw

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?

Signature · 4 lines
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."
drivers/scsi/hosts.h +5 -0
@@ -286,6 +286,11 @@
 
     unsigned highmem_io:1;
 
+    /* Have the high level code automatically handle DMA mapping of
+       Scsi_Request->request_buffer and Scsi_Request->sense_buf. */
+    unsigned dma_map_request:1;
+    unsigned dma_map_sense:1;
+
     /*
      * Name of proc directory
      */
drivers/scsi/scsi.h +3 -0
@@ -734,12 +732,14 @@
 
 	struct timer_list eh_timeout;	/* Used to time out the command. */
 	void *request_buffer;		/* Actual requested buffer */
+	dma_addr_t request_dma_addr;
 
 	/* These elements define the operation we ultimately want to perform */
 	unsigned char data_cmnd[MAX_COMMAND_SIZE];
 	unsigned short old_use_sg;	/* We save  use_sg here when requesting
 					 * sense info */
 	unsigned short use_sg;	/* Number of pieces of scatter-gather */
+	unsigned short sgcnt_dma;	/* Returned by pci_map_sg. */
 	unsigned short sglist_len;	/* size of malloc'd scatter-gather list */
 	unsigned short abort_reason;	/* If the mid-level code requests an
 					 * abort, this is the reason. */
@@ -768,6 +768,7 @@
 						 * when CHECK CONDITION is
 						 * received on original command 
 						 * (auto-sense) */
+	dma_addr_t sense_dma_addr;
 
 	unsigned flags;
 
drivers/scsi/scsi.c +72 -0

90 lines not on this page · raw message