This patch updates the jumpshot driver to the new scatter-gather routines.

Greg, please apply.

Matt

----- Forwarded message from Alan Stern <[EMAIL PROTECTED]> -----

Date: Mon, 1 Dec 2003 10:53:54 -0500 (EST)
From: Alan Stern <[EMAIL PROTECTED]>
Subject: PATCH: (as144)  Convert jumpshot to use the new s-g routines
To: Matthew Dharm <[EMAIL PROTECTED]>
cc: USB Storage List <[EMAIL PROTECTED]>
X-Spam-Status: No, hits=0.7 required=5.0
        tests=AWL,PATCH_UNIFIED_DIFF,RCVD_IN_OSIRUSOFT_COM,
              SPAM_PHRASE_00_01,USER_AGENT_PINE,X_OSIRU_OPEN_RELAY
        version=2.44

Matt:

This patch converts the jumpshot driver to use the new scatter-gather 
routines.  It has not been tested.

Alan Stern


===== jumpshot.c 1.22 vs edited =====
--- 1.22/drivers/usb/storage/jumpshot.c Mon Jul 28 14:29:04 2003
+++ edited/drivers/usb/storage/jumpshot.c       Mon Nov 24 14:29:04 2003
@@ -48,7 +48,6 @@
   */
 
 #include "transport.h"
-#include "raw_bulk.h"
 #include "protocol.h"
 #include "usb.h"
 #include "debug.h"
@@ -111,15 +110,14 @@
                              struct jumpshot_info *info,
                              u32 sector,
                              u32 sectors, 
-                             unsigned char *dest, 
+                             unsigned char *buffer, 
                              int use_sg)
 {
        unsigned char *command = us->iobuf;
-       unsigned char *buffer = NULL;
-       unsigned char *ptr;
        unsigned char  thistime;
-       int totallen, len, result;
-       int sg_idx = 0, current_sg_offset = 0;
+       unsigned int totallen, alloclen;
+       int len, result;
+       unsigned int sg_idx = 0, sg_offset = 0;
 
        // we're working in LBA mode.  according to the ATA spec, 
        // we can support up to 28-bit addressing.  I don't know if Jumpshot
@@ -131,20 +129,20 @@
 
        totallen = sectors * info->ssize;
 
+       // Since we don't read more than 64 KB at a time, we have to create
+       // a bounce buffer if the transfer uses scatter-gather.
+
+       alloclen = min(totallen, 65536u);
+       if (use_sg) {
+               buffer = kmalloc(alloclen, GFP_NOIO);
+               if (buffer == NULL)
+                       return USB_STOR_TRANSPORT_ERROR;
+       }
+
        do {
                // loop, never allocate or transfer more than 64k at once
                // (min(128k, 255*info->ssize) is the real limit)
-               len = min_t(int, totallen, 65536);
-
-               if (use_sg) {
-                       buffer = kmalloc(len, GFP_NOIO);
-                       if (buffer == NULL)
-                               return USB_STOR_TRANSPORT_ERROR;
-                       ptr = buffer;
-               } else {
-                       ptr = dest;
-               }
-
+               len = min(totallen, alloclen);
                thistime = (len / info->ssize) & 0xff;
 
                command[0] = 0;
@@ -163,26 +161,24 @@
                        goto leave;
 
                // read the result
-               result = jumpshot_bulk_read(us, ptr, len);
+               result = jumpshot_bulk_read(us, buffer, len);
                if (result != USB_STOR_XFER_GOOD)
                        goto leave;
 
                US_DEBUGP("jumpshot_read_data:  %d bytes\n", len);
-       
-               sectors -= thistime;
-               sector  += thistime;
-
-               if (use_sg) {
-                       us_copy_to_sgbuf(buffer, len, dest,
-                                        &sg_idx, &current_sg_offset, use_sg);
-                       kfree(buffer);
-               } else {
-                       dest += len;
-               }
 
+               if (use_sg)
+                       usb_stor_access_xfer_buf(buffer, len, us->srb,
+                                        &sg_idx, &sg_offset, TO_XFER_BUF);
+               else
+                       buffer += len;
+
+               sector += thistime;
                totallen -= len;
        } while (totallen > 0);
 
+       if (use_sg)
+               kfree(buffer);
        return USB_STOR_TRANSPORT_GOOD;
 
  leave:
@@ -196,15 +192,14 @@
                               struct jumpshot_info *info,
                               u32 sector,
                               u32 sectors, 
-                              unsigned char *src, 
+                              unsigned char *buffer, 
                               int use_sg)
 {
        unsigned char *command = us->iobuf;
-       unsigned char *buffer = NULL;
-       unsigned char *ptr;
        unsigned char  thistime;
-       int totallen, len, result, waitcount;
-       int sg_idx = 0, sg_offset = 0;
+       unsigned int totallen, alloclen;
+       int len, result, waitcount;
+       unsigned int sg_idx = 0, sg_offset = 0;
 
        // we're working in LBA mode.  according to the ATA spec, 
        // we can support up to 28-bit addressing.  I don't know if Jumpshot
@@ -216,24 +211,27 @@
 
        totallen = sectors * info->ssize;
 
-       do {
-               // loop, never allocate or transfer more than 64k at once
-               // (min(128k, 255*info->ssize) is the real limit)
-
-               len = min_t(int, totallen, 65536);
+       // Since we don't write more than 64 KB at a time, we have to create
+       // a bounce buffer if the transfer uses scatter-gather.
 
-               // if we are using scatter-gather,
-               // first copy all to one big buffer
-
-               buffer = us_copy_from_sgbuf(src, len, &sg_idx,
-                                           &sg_offset, use_sg);
+       alloclen = min(totallen, 65536u);
+       if (use_sg) {
+               buffer = kmalloc(alloclen, GFP_NOIO);
                if (buffer == NULL)
                        return USB_STOR_TRANSPORT_ERROR;
+       }
 
-               ptr = buffer;
+       do {
+               // loop, never allocate or transfer more than 64k at once
+               // (min(128k, 255*info->ssize) is the real limit)
 
+               len = min(totallen, alloclen);
                thistime = (len / info->ssize) & 0xff;
 
+               if (use_sg)
+                       usb_stor_access_xfer_buf(buffer, len, us->srb,
+                                       &sg_idx, &sg_offset, FROM_XFER_BUF);
+
                command[0] = 0;
                command[1] = thistime;
                command[2] = sector & 0xFF;
@@ -250,7 +248,7 @@
                        goto leave;
 
                // send the data
-               result = jumpshot_bulk_write(us, ptr, len);
+               result = jumpshot_bulk_write(us, buffer, len);
                if (result != USB_STOR_XFER_GOOD)
                        goto leave;
 
@@ -269,18 +267,16 @@
 
                if (result != USB_STOR_TRANSPORT_GOOD)
                        US_DEBUGP("jumpshot_write_data:  Gah!  Waitcount = 10.  Bad 
write!?\n");
-               
-               sectors -= thistime;
-               sector  += thistime;
 
-               if (use_sg)
-                       kfree(buffer);
-               else
-                       src += len;
+               if (!use_sg)
+                       buffer += len;
 
+               sector += thistime;
                totallen -= len;
        } while (totallen > 0);
 
+       if (use_sg)
+               kfree(buffer);
        return result;
 
  leave:
@@ -605,14 +601,14 @@
                US_DEBUGP("jumpshot_transport:  MODE_SENSE_10 detected\n");
                return jumpshot_handle_mode_sense(us, srb, ptr, FALSE);
        }
-       
+
        if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
                // sure.  whatever.  not like we can stop the user from popping
                // the media out of the device (no locking doors, etc)
                //
                return USB_STOR_TRANSPORT_GOOD;
        }
-       
+
        if (srb->cmnd[0] == START_STOP) {
                /* this is used by sd.c'check_scsidisk_media_change to detect
                   media change */

----- End forwarded message -----

-- 
Matthew Dharm                              Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

I need a computer?
                                        -- Customer
User Friendly, 2/19/1998

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to