aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 20:19:08 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-01-25 20:19:08 -0500
commit9b73e76f3cf63379dcf45fcd4f112f5812418d0a (patch)
tree4e6bef87cd0cd6d848fc39a5ae25b981dbbe035b /drivers/usb
parent50d9a126240f9961cfdd063336bbeb91f77a7dce (diff)
parent23c3e290fb9ce38cabc2822b47583fc8702411bf (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (200 commits) [SCSI] usbstorage: use last_sector_bug flag universally [SCSI] libsas: abstract STP task status into a function [SCSI] ultrastor: clean up inline asm warnings [SCSI] aic7xxx: fix firmware build [SCSI] aacraid: fib context lock for management ioctls [SCSI] ch: remove forward declarations [SCSI] ch: fix device minor number management bug [SCSI] ch: handle class_device_create failure properly [SCSI] NCR5380: fix section mismatch [SCSI] sg: fix /proc/scsi/sg/devices when no SCSI devices [SCSI] IB/iSER: add logical unit reset support [SCSI] don't use __GFP_DMA for sense buffers if not required [SCSI] use dynamically allocated sense buffer [SCSI] scsi.h: add macro for enclosure bit of inquiry data [SCSI] sd: add fix for devices with last sector access problems [SCSI] fix pcmcia compile problem [SCSI] aacraid: add Voodoo Lite class of cards. [SCSI] aacraid: add new driver features flags [SCSI] qla2xxx: Update version number to 8.02.00-k7. [SCSI] qla2xxx: Issue correct MBC_INITIALIZE_FIRMWARE command. ...
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/storage/freecom.c14
-rw-r--r--drivers/usb/storage/isd200.c66
-rw-r--r--drivers/usb/storage/protocol.c126
-rw-r--r--drivers/usb/storage/scsiglue.c24
-rw-r--r--drivers/usb/storage/sddr09.c9
-rw-r--r--drivers/usb/storage/shuttle_usbat.c68
-rw-r--r--drivers/usb/storage/transport.c45
-rw-r--r--drivers/usb/storage/transport.h2
8 files changed, 178 insertions, 176 deletions
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index 88aa59ab7563..f5a4e8d6a3b1 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -132,8 +132,7 @@ freecom_readdata (struct scsi_cmnd *srb, struct us_data *us,
132 132
133 /* Now transfer all of our blocks. */ 133 /* Now transfer all of our blocks. */
134 US_DEBUGP("Start of read\n"); 134 US_DEBUGP("Start of read\n");
135 result = usb_stor_bulk_transfer_sg(us, ipipe, srb->request_buffer, 135 result = usb_stor_bulk_srb(us, ipipe, srb);
136 count, srb->use_sg, &srb->resid);
137 US_DEBUGP("freecom_readdata done!\n"); 136 US_DEBUGP("freecom_readdata done!\n");
138 137
139 if (result > USB_STOR_XFER_SHORT) 138 if (result > USB_STOR_XFER_SHORT)
@@ -166,8 +165,7 @@ freecom_writedata (struct scsi_cmnd *srb, struct us_data *us,
166 165
167 /* Now transfer all of our blocks. */ 166 /* Now transfer all of our blocks. */
168 US_DEBUGP("Start of write\n"); 167 US_DEBUGP("Start of write\n");
169 result = usb_stor_bulk_transfer_sg(us, opipe, srb->request_buffer, 168 result = usb_stor_bulk_srb(us, opipe, srb);
170 count, srb->use_sg, &srb->resid);
171 169
172 US_DEBUGP("freecom_writedata done!\n"); 170 US_DEBUGP("freecom_writedata done!\n");
173 if (result > USB_STOR_XFER_SHORT) 171 if (result > USB_STOR_XFER_SHORT)
@@ -281,7 +279,7 @@ int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
281 * and such will hang. */ 279 * and such will hang. */
282 US_DEBUGP("Device indicates that it has %d bytes available\n", 280 US_DEBUGP("Device indicates that it has %d bytes available\n",
283 le16_to_cpu (fst->Count)); 281 le16_to_cpu (fst->Count));
284 US_DEBUGP("SCSI requested %d\n", srb->request_bufflen); 282 US_DEBUGP("SCSI requested %d\n", scsi_bufflen(srb));
285 283
286 /* Find the length we desire to read. */ 284 /* Find the length we desire to read. */
287 switch (srb->cmnd[0]) { 285 switch (srb->cmnd[0]) {
@@ -292,12 +290,12 @@ int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
292 length = le16_to_cpu(fst->Count); 290 length = le16_to_cpu(fst->Count);
293 break; 291 break;
294 default: 292 default:
295 length = srb->request_bufflen; 293 length = scsi_bufflen(srb);
296 } 294 }
297 295
298 /* verify that this amount is legal */ 296 /* verify that this amount is legal */
299 if (length > srb->request_bufflen) { 297 if (length > scsi_bufflen(srb)) {
300 length = srb->request_bufflen; 298 length = scsi_bufflen(srb);
301 US_DEBUGP("Truncating request to match buffer length: %d\n", length); 299 US_DEBUGP("Truncating request to match buffer length: %d\n", length);
302 } 300 }
303 301
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 49ba6c0ff1e8..178e8c2a8a2f 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -49,6 +49,7 @@
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/hdreg.h> 50#include <linux/hdreg.h>
51#include <linux/ide.h> 51#include <linux/ide.h>
52#include <linux/scatterlist.h>
52 53
53#include <scsi/scsi.h> 54#include <scsi/scsi.h>
54#include <scsi/scsi_cmnd.h> 55#include <scsi/scsi_cmnd.h>
@@ -287,6 +288,7 @@ struct isd200_info {
287 /* maximum number of LUNs supported */ 288 /* maximum number of LUNs supported */
288 unsigned char MaxLUNs; 289 unsigned char MaxLUNs;
289 struct scsi_cmnd srb; 290 struct scsi_cmnd srb;
291 struct scatterlist sg;
290}; 292};
291 293
292 294
@@ -398,6 +400,31 @@ static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb)
398 * Transport routines 400 * Transport routines
399 ***********************************************************************/ 401 ***********************************************************************/
400 402
403/**************************************************************************
404 * isd200_set_srb(), isd200_srb_set_bufflen()
405 *
406 * Two helpers to facilitate in initialization of scsi_cmnd structure
407 * Will need to change when struct scsi_cmnd changes
408 */
409static void isd200_set_srb(struct isd200_info *info,
410 enum dma_data_direction dir, void* buff, unsigned bufflen)
411{
412 struct scsi_cmnd *srb = &info->srb;
413
414 if (buff)
415 sg_init_one(&info->sg, buff, bufflen);
416
417 srb->sc_data_direction = dir;
418 srb->request_buffer = buff ? &info->sg : NULL;
419 srb->request_bufflen = bufflen;
420 srb->use_sg = buff ? 1 : 0;
421}
422
423static void isd200_srb_set_bufflen(struct scsi_cmnd *srb, unsigned bufflen)
424{
425 srb->request_bufflen = bufflen;
426}
427
401 428
402/************************************************************************** 429/**************************************************************************
403 * isd200_action 430 * isd200_action
@@ -432,9 +459,7 @@ static int isd200_action( struct us_data *us, int action,
432 ata.generic.RegisterSelect = 459 ata.generic.RegisterSelect =
433 REG_CYLINDER_LOW | REG_CYLINDER_HIGH | 460 REG_CYLINDER_LOW | REG_CYLINDER_HIGH |
434 REG_STATUS | REG_ERROR; 461 REG_STATUS | REG_ERROR;
435 srb->sc_data_direction = DMA_FROM_DEVICE; 462 isd200_set_srb(info, DMA_FROM_DEVICE, pointer, value);
436 srb->request_buffer = pointer;
437 srb->request_bufflen = value;
438 break; 463 break;
439 464
440 case ACTION_ENUM: 465 case ACTION_ENUM:
@@ -444,7 +469,7 @@ static int isd200_action( struct us_data *us, int action,
444 ACTION_SELECT_5; 469 ACTION_SELECT_5;
445 ata.generic.RegisterSelect = REG_DEVICE_HEAD; 470 ata.generic.RegisterSelect = REG_DEVICE_HEAD;
446 ata.write.DeviceHeadByte = value; 471 ata.write.DeviceHeadByte = value;
447 srb->sc_data_direction = DMA_NONE; 472 isd200_set_srb(info, DMA_NONE, NULL, 0);
448 break; 473 break;
449 474
450 case ACTION_RESET: 475 case ACTION_RESET:
@@ -453,7 +478,7 @@ static int isd200_action( struct us_data *us, int action,
453 ACTION_SELECT_3|ACTION_SELECT_4; 478 ACTION_SELECT_3|ACTION_SELECT_4;
454 ata.generic.RegisterSelect = REG_DEVICE_CONTROL; 479 ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
455 ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER; 480 ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER;
456 srb->sc_data_direction = DMA_NONE; 481 isd200_set_srb(info, DMA_NONE, NULL, 0);
457 break; 482 break;
458 483
459 case ACTION_REENABLE: 484 case ACTION_REENABLE:
@@ -462,7 +487,7 @@ static int isd200_action( struct us_data *us, int action,
462 ACTION_SELECT_3|ACTION_SELECT_4; 487 ACTION_SELECT_3|ACTION_SELECT_4;
463 ata.generic.RegisterSelect = REG_DEVICE_CONTROL; 488 ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
464 ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER; 489 ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER;
465 srb->sc_data_direction = DMA_NONE; 490 isd200_set_srb(info, DMA_NONE, NULL, 0);
466 break; 491 break;
467 492
468 case ACTION_SOFT_RESET: 493 case ACTION_SOFT_RESET:
@@ -471,21 +496,20 @@ static int isd200_action( struct us_data *us, int action,
471 ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND; 496 ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND;
472 ata.write.DeviceHeadByte = info->DeviceHead; 497 ata.write.DeviceHeadByte = info->DeviceHead;
473 ata.write.CommandByte = WIN_SRST; 498 ata.write.CommandByte = WIN_SRST;
474 srb->sc_data_direction = DMA_NONE; 499 isd200_set_srb(info, DMA_NONE, NULL, 0);
475 break; 500 break;
476 501
477 case ACTION_IDENTIFY: 502 case ACTION_IDENTIFY:
478 US_DEBUGP(" isd200_action(IDENTIFY)\n"); 503 US_DEBUGP(" isd200_action(IDENTIFY)\n");
479 ata.generic.RegisterSelect = REG_COMMAND; 504 ata.generic.RegisterSelect = REG_COMMAND;
480 ata.write.CommandByte = WIN_IDENTIFY; 505 ata.write.CommandByte = WIN_IDENTIFY;
481 srb->sc_data_direction = DMA_FROM_DEVICE; 506 isd200_set_srb(info, DMA_FROM_DEVICE, info->id,
482 srb->request_buffer = (void *) info->id; 507 sizeof(struct hd_driveid));
483 srb->request_bufflen = sizeof(struct hd_driveid);
484 break; 508 break;
485 509
486 default: 510 default:
487 US_DEBUGP("Error: Undefined action %d\n",action); 511 US_DEBUGP("Error: Undefined action %d\n",action);
488 break; 512 return ISD200_ERROR;
489 } 513 }
490 514
491 memcpy(srb->cmnd, &ata, sizeof(ata.generic)); 515 memcpy(srb->cmnd, &ata, sizeof(ata.generic));
@@ -590,7 +614,7 @@ static void isd200_invoke_transport( struct us_data *us,
590 return; 614 return;
591 } 615 }
592 616
593 if ((srb->resid > 0) && 617 if ((scsi_get_resid(srb) > 0) &&
594 !((srb->cmnd[0] == REQUEST_SENSE) || 618 !((srb->cmnd[0] == REQUEST_SENSE) ||
595 (srb->cmnd[0] == INQUIRY) || 619 (srb->cmnd[0] == INQUIRY) ||
596 (srb->cmnd[0] == MODE_SENSE) || 620 (srb->cmnd[0] == MODE_SENSE) ||
@@ -1217,7 +1241,6 @@ static int isd200_get_inquiry_data( struct us_data *us )
1217 return(retStatus); 1241 return(retStatus);
1218} 1242}
1219 1243
1220
1221/************************************************************************** 1244/**************************************************************************
1222 * isd200_scsi_to_ata 1245 * isd200_scsi_to_ata
1223 * 1246 *
@@ -1266,7 +1289,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1266 ataCdb->generic.TransferBlockSize = 1; 1289 ataCdb->generic.TransferBlockSize = 1;
1267 ataCdb->generic.RegisterSelect = REG_COMMAND; 1290 ataCdb->generic.RegisterSelect = REG_COMMAND;
1268 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1291 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1269 srb->request_bufflen = 0; 1292 isd200_srb_set_bufflen(srb, 0);
1270 } else { 1293 } else {
1271 US_DEBUGP(" Media Status not supported, just report okay\n"); 1294 US_DEBUGP(" Media Status not supported, just report okay\n");
1272 srb->result = SAM_STAT_GOOD; 1295 srb->result = SAM_STAT_GOOD;
@@ -1284,7 +1307,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1284 ataCdb->generic.TransferBlockSize = 1; 1307 ataCdb->generic.TransferBlockSize = 1;
1285 ataCdb->generic.RegisterSelect = REG_COMMAND; 1308 ataCdb->generic.RegisterSelect = REG_COMMAND;
1286 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1309 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1287 srb->request_bufflen = 0; 1310 isd200_srb_set_bufflen(srb, 0);
1288 } else { 1311 } else {
1289 US_DEBUGP(" Media Status not supported, just report okay\n"); 1312 US_DEBUGP(" Media Status not supported, just report okay\n");
1290 srb->result = SAM_STAT_GOOD; 1313 srb->result = SAM_STAT_GOOD;
@@ -1390,7 +1413,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1390 ataCdb->generic.RegisterSelect = REG_COMMAND; 1413 ataCdb->generic.RegisterSelect = REG_COMMAND;
1391 ataCdb->write.CommandByte = (srb->cmnd[4] & 0x1) ? 1414 ataCdb->write.CommandByte = (srb->cmnd[4] & 0x1) ?
1392 WIN_DOORLOCK : WIN_DOORUNLOCK; 1415 WIN_DOORLOCK : WIN_DOORUNLOCK;
1393 srb->request_bufflen = 0; 1416 isd200_srb_set_bufflen(srb, 0);
1394 } else { 1417 } else {
1395 US_DEBUGP(" Not removeable media, just report okay\n"); 1418 US_DEBUGP(" Not removeable media, just report okay\n");
1396 srb->result = SAM_STAT_GOOD; 1419 srb->result = SAM_STAT_GOOD;
@@ -1416,7 +1439,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1416 ataCdb->generic.TransferBlockSize = 1; 1439 ataCdb->generic.TransferBlockSize = 1;
1417 ataCdb->generic.RegisterSelect = REG_COMMAND; 1440 ataCdb->generic.RegisterSelect = REG_COMMAND;
1418 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1441 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1419 srb->request_bufflen = 0; 1442 isd200_srb_set_bufflen(srb, 0);
1420 } else { 1443 } else {
1421 US_DEBUGP(" Nothing to do, just report okay\n"); 1444 US_DEBUGP(" Nothing to do, just report okay\n");
1422 srb->result = SAM_STAT_GOOD; 1445 srb->result = SAM_STAT_GOOD;
@@ -1525,7 +1548,7 @@ int isd200_Initialization(struct us_data *us)
1525 1548
1526void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us) 1549void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
1527{ 1550{
1528 int sendToTransport = 1; 1551 int sendToTransport = 1, orig_bufflen;
1529 union ata_cdb ataCdb; 1552 union ata_cdb ataCdb;
1530 1553
1531 /* Make sure driver was initialized */ 1554 /* Make sure driver was initialized */
@@ -1533,11 +1556,14 @@ void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
1533 if (us->extra == NULL) 1556 if (us->extra == NULL)
1534 US_DEBUGP("ERROR Driver not initialized\n"); 1557 US_DEBUGP("ERROR Driver not initialized\n");
1535 1558
1536 /* Convert command */ 1559 scsi_set_resid(srb, 0);
1537 srb->resid = 0; 1560 /* scsi_bufflen might change in protocol translation to ata */
1561 orig_bufflen = scsi_bufflen(srb);
1538 sendToTransport = isd200_scsi_to_ata(srb, us, &ataCdb); 1562 sendToTransport = isd200_scsi_to_ata(srb, us, &ataCdb);
1539 1563
1540 /* send the command to the transport layer */ 1564 /* send the command to the transport layer */
1541 if (sendToTransport) 1565 if (sendToTransport)
1542 isd200_invoke_transport(us, srb, &ataCdb); 1566 isd200_invoke_transport(us, srb, &ataCdb);
1567
1568 isd200_srb_set_bufflen(srb, orig_bufflen);
1543} 1569}
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index 889622baac20..a41ce21c0697 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -149,11 +149,7 @@ void usb_stor_transparent_scsi_command(struct scsi_cmnd *srb,
149 ***********************************************************************/ 149 ***********************************************************************/
150 150
151/* Copy a buffer of length buflen to/from the srb's transfer buffer. 151/* Copy a buffer of length buflen to/from the srb's transfer buffer.
152 * (Note: for scatter-gather transfers (srb->use_sg > 0), srb->request_buffer 152 * Update the **sgptr and *offset variables so that the next copy will
153 * points to a list of s-g entries and we ignore srb->request_bufflen.
154 * For non-scatter-gather transfers, srb->request_buffer points to the
155 * transfer buffer itself and srb->request_bufflen is the buffer's length.)
156 * Update the *index and *offset variables so that the next copy will
157 * pick up from where this one left off. */ 153 * pick up from where this one left off. */
158 154
159unsigned int usb_stor_access_xfer_buf(unsigned char *buffer, 155unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
@@ -162,80 +158,64 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
162{ 158{
163 unsigned int cnt; 159 unsigned int cnt;
164 160
165 /* If not using scatter-gather, just transfer the data directly. 161 /* We have to go through the list one entry
166 * Make certain it will fit in the available buffer space. */
167 if (srb->use_sg == 0) {
168 if (*offset >= srb->request_bufflen)
169 return 0;
170 cnt = min(buflen, srb->request_bufflen - *offset);
171 if (dir == TO_XFER_BUF)
172 memcpy((unsigned char *) srb->request_buffer + *offset,
173 buffer, cnt);
174 else
175 memcpy(buffer, (unsigned char *) srb->request_buffer +
176 *offset, cnt);
177 *offset += cnt;
178
179 /* Using scatter-gather. We have to go through the list one entry
180 * at a time. Each s-g entry contains some number of pages, and 162 * at a time. Each s-g entry contains some number of pages, and
181 * each page has to be kmap()'ed separately. If the page is already 163 * each page has to be kmap()'ed separately. If the page is already
182 * in kernel-addressable memory then kmap() will return its address. 164 * in kernel-addressable memory then kmap() will return its address.
183 * If the page is not directly accessible -- such as a user buffer 165 * If the page is not directly accessible -- such as a user buffer
184 * located in high memory -- then kmap() will map it to a temporary 166 * located in high memory -- then kmap() will map it to a temporary
185 * position in the kernel's virtual address space. */ 167 * position in the kernel's virtual address space. */
186 } else { 168 struct scatterlist *sg = *sgptr;
187 struct scatterlist *sg = *sgptr; 169
188 170 if (!sg)
189 if (!sg) 171 sg = scsi_sglist(srb);
190 sg = (struct scatterlist *) srb->request_buffer; 172
191 173 /* This loop handles a single s-g list entry, which may
192 /* This loop handles a single s-g list entry, which may 174 * include multiple pages. Find the initial page structure
193 * include multiple pages. Find the initial page structure 175 * and the starting offset within the page, and update
194 * and the starting offset within the page, and update 176 * the *offset and **sgptr values for the next loop. */
195 * the *offset and *index values for the next loop. */ 177 cnt = 0;
196 cnt = 0; 178 while (cnt < buflen) {
197 while (cnt < buflen) { 179 struct page *page = sg_page(sg) +
198 struct page *page = sg_page(sg) + 180 ((sg->offset + *offset) >> PAGE_SHIFT);
199 ((sg->offset + *offset) >> PAGE_SHIFT); 181 unsigned int poff =
200 unsigned int poff = 182 (sg->offset + *offset) & (PAGE_SIZE-1);
201 (sg->offset + *offset) & (PAGE_SIZE-1); 183 unsigned int sglen = sg->length - *offset;
202 unsigned int sglen = sg->length - *offset; 184
203 185 if (sglen > buflen - cnt) {
204 if (sglen > buflen - cnt) { 186
205 187 /* Transfer ends within this s-g entry */
206 /* Transfer ends within this s-g entry */ 188 sglen = buflen - cnt;
207 sglen = buflen - cnt; 189 *offset += sglen;
208 *offset += sglen; 190 } else {
209 } else { 191
210 192 /* Transfer continues to next s-g entry */
211 /* Transfer continues to next s-g entry */ 193 *offset = 0;
212 *offset = 0; 194 sg = sg_next(sg);
213 sg = sg_next(sg); 195 }
214 } 196
215 197 /* Transfer the data for all the pages in this
216 /* Transfer the data for all the pages in this 198 * s-g entry. For each page: call kmap(), do the
217 * s-g entry. For each page: call kmap(), do the 199 * transfer, and call kunmap() immediately after. */
218 * transfer, and call kunmap() immediately after. */ 200 while (sglen > 0) {
219 while (sglen > 0) { 201 unsigned int plen = min(sglen, (unsigned int)
220 unsigned int plen = min(sglen, (unsigned int) 202 PAGE_SIZE - poff);
221 PAGE_SIZE - poff); 203 unsigned char *ptr = kmap(page);
222 unsigned char *ptr = kmap(page); 204
223 205 if (dir == TO_XFER_BUF)
224 if (dir == TO_XFER_BUF) 206 memcpy(ptr + poff, buffer + cnt, plen);
225 memcpy(ptr + poff, buffer + cnt, plen); 207 else
226 else 208 memcpy(buffer + cnt, ptr + poff, plen);
227 memcpy(buffer + cnt, ptr + poff, plen); 209 kunmap(page);
228 kunmap(page); 210
229 211 /* Start at the beginning of the next page */
230 /* Start at the beginning of the next page */ 212 poff = 0;
231 poff = 0; 213 ++page;
232 ++page; 214 cnt += plen;
233 cnt += plen; 215 sglen -= plen;
234 sglen -= plen;
235 }
236 } 216 }
237 *sgptr = sg;
238 } 217 }
218 *sgptr = sg;
239 219
240 /* Return the amount actually transferred */ 220 /* Return the amount actually transferred */
241 return cnt; 221 return cnt;
@@ -251,6 +231,6 @@ void usb_stor_set_xfer_buf(unsigned char *buffer,
251 231
252 usb_stor_access_xfer_buf(buffer, buflen, srb, &sg, &offset, 232 usb_stor_access_xfer_buf(buffer, buflen, srb, &sg, &offset,
253 TO_XFER_BUF); 233 TO_XFER_BUF);
254 if (buflen < srb->request_bufflen) 234 if (buflen < scsi_bufflen(srb))
255 srb->resid = srb->request_bufflen - buflen; 235 scsi_set_resid(srb, scsi_bufflen(srb) - buflen);
256} 236}
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 7c9593b7b04e..8c1e2954f3b9 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -81,6 +81,16 @@ static int slave_alloc (struct scsi_device *sdev)
81 */ 81 */
82 sdev->inquiry_len = 36; 82 sdev->inquiry_len = 36;
83 83
84 /* Scatter-gather buffers (all but the last) must have a length
85 * divisible by the bulk maxpacket size. Otherwise a data packet
86 * would end up being short, causing a premature end to the data
87 * transfer. Since high-speed bulk pipes have a maxpacket size
88 * of 512, we'll use that as the scsi device queue's DMA alignment
89 * mask. Guaranteeing proper alignment of the first buffer will
90 * have the desired effect because, except at the beginning and
91 * the end, scatter-gather buffers follow page boundaries. */
92 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
93
84 /* 94 /*
85 * The UFI spec treates the Peripheral Qualifier bits in an 95 * The UFI spec treates the Peripheral Qualifier bits in an
86 * INQUIRY result as reserved and requires devices to set them 96 * INQUIRY result as reserved and requires devices to set them
@@ -100,16 +110,6 @@ static int slave_configure(struct scsi_device *sdev)
100{ 110{
101 struct us_data *us = host_to_us(sdev->host); 111 struct us_data *us = host_to_us(sdev->host);
102 112
103 /* Scatter-gather buffers (all but the last) must have a length
104 * divisible by the bulk maxpacket size. Otherwise a data packet
105 * would end up being short, causing a premature end to the data
106 * transfer. Since high-speed bulk pipes have a maxpacket size
107 * of 512, we'll use that as the scsi device queue's DMA alignment
108 * mask. Guaranteeing proper alignment of the first buffer will
109 * have the desired effect because, except at the beginning and
110 * the end, scatter-gather buffers follow page boundaries. */
111 blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
112
113 /* Many devices have trouble transfering more than 32KB at a time, 113 /* Many devices have trouble transfering more than 32KB at a time,
114 * while others have trouble with more than 64K. At this time we 114 * while others have trouble with more than 64K. At this time we
115 * are limiting both to 32K (64 sectores). 115 * are limiting both to 32K (64 sectores).
@@ -187,6 +187,10 @@ static int slave_configure(struct scsi_device *sdev)
187 * automatically, requiring a START-STOP UNIT command. */ 187 * automatically, requiring a START-STOP UNIT command. */
188 sdev->allow_restart = 1; 188 sdev->allow_restart = 1;
189 189
190 /* Some USB cardreaders have trouble reading an sdcard's last
191 * sector in a larger then 1 sector read, since the performance
192 * impact is negible we set this flag for all USB disks */
193 sdev->last_sector_bug = 1;
190 } else { 194 } else {
191 195
192 /* Non-disk-type devices don't need to blacklist any pages 196 /* Non-disk-type devices don't need to blacklist any pages
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index b12202c5da2d..8972b17da843 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -1623,7 +1623,7 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1623 return USB_STOR_TRANSPORT_ERROR; 1623 return USB_STOR_TRANSPORT_ERROR;
1624 } 1624 }
1625 1625
1626 if (srb->request_bufflen == 0) 1626 if (scsi_bufflen(srb) == 0)
1627 return USB_STOR_TRANSPORT_GOOD; 1627 return USB_STOR_TRANSPORT_GOOD;
1628 1628
1629 if (srb->sc_data_direction == DMA_TO_DEVICE || 1629 if (srb->sc_data_direction == DMA_TO_DEVICE ||
@@ -1634,12 +1634,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1634 US_DEBUGP("SDDR09: %s %d bytes\n", 1634 US_DEBUGP("SDDR09: %s %d bytes\n",
1635 (srb->sc_data_direction == DMA_TO_DEVICE) ? 1635 (srb->sc_data_direction == DMA_TO_DEVICE) ?
1636 "sending" : "receiving", 1636 "sending" : "receiving",
1637 srb->request_bufflen); 1637 scsi_bufflen(srb));
1638 1638
1639 result = usb_stor_bulk_transfer_sg(us, pipe, 1639 result = usb_stor_bulk_srb(us, pipe, srb);
1640 srb->request_buffer,
1641 srb->request_bufflen,
1642 srb->use_sg, &srb->resid);
1643 1640
1644 return (result == USB_STOR_XFER_GOOD ? 1641 return (result == USB_STOR_XFER_GOOD ?
1645 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR); 1642 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index cb22a9ad1694..570c1250f6f3 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -130,7 +130,7 @@ static int usbat_write(struct us_data *us,
130 * Convenience function to perform a bulk read 130 * Convenience function to perform a bulk read
131 */ 131 */
132static int usbat_bulk_read(struct us_data *us, 132static int usbat_bulk_read(struct us_data *us,
133 unsigned char *data, 133 void* buf,
134 unsigned int len, 134 unsigned int len,
135 int use_sg) 135 int use_sg)
136{ 136{
@@ -138,14 +138,14 @@ static int usbat_bulk_read(struct us_data *us,
138 return USB_STOR_XFER_GOOD; 138 return USB_STOR_XFER_GOOD;
139 139
140 US_DEBUGP("usbat_bulk_read: len = %d\n", len); 140 US_DEBUGP("usbat_bulk_read: len = %d\n", len);
141 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, data, len, use_sg, NULL); 141 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL);
142} 142}
143 143
144/* 144/*
145 * Convenience function to perform a bulk write 145 * Convenience function to perform a bulk write
146 */ 146 */
147static int usbat_bulk_write(struct us_data *us, 147static int usbat_bulk_write(struct us_data *us,
148 unsigned char *data, 148 void* buf,
149 unsigned int len, 149 unsigned int len,
150 int use_sg) 150 int use_sg)
151{ 151{
@@ -153,7 +153,7 @@ static int usbat_bulk_write(struct us_data *us,
153 return USB_STOR_XFER_GOOD; 153 return USB_STOR_XFER_GOOD;
154 154
155 US_DEBUGP("usbat_bulk_write: len = %d\n", len); 155 US_DEBUGP("usbat_bulk_write: len = %d\n", len);
156 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, data, len, use_sg, NULL); 156 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL);
157} 157}
158 158
159/* 159/*
@@ -314,7 +314,7 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
314 * Read block data from the data register 314 * Read block data from the data register
315 */ 315 */
316static int usbat_read_block(struct us_data *us, 316static int usbat_read_block(struct us_data *us,
317 unsigned char *content, 317 void* buf,
318 unsigned short len, 318 unsigned short len,
319 int use_sg) 319 int use_sg)
320{ 320{
@@ -337,7 +337,7 @@ static int usbat_read_block(struct us_data *us,
337 if (result != USB_STOR_XFER_GOOD) 337 if (result != USB_STOR_XFER_GOOD)
338 return USB_STOR_TRANSPORT_ERROR; 338 return USB_STOR_TRANSPORT_ERROR;
339 339
340 result = usbat_bulk_read(us, content, len, use_sg); 340 result = usbat_bulk_read(us, buf, len, use_sg);
341 return (result == USB_STOR_XFER_GOOD ? 341 return (result == USB_STOR_XFER_GOOD ?
342 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR); 342 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
343} 343}
@@ -347,7 +347,7 @@ static int usbat_read_block(struct us_data *us,
347 */ 347 */
348static int usbat_write_block(struct us_data *us, 348static int usbat_write_block(struct us_data *us,
349 unsigned char access, 349 unsigned char access,
350 unsigned char *content, 350 void* buf,
351 unsigned short len, 351 unsigned short len,
352 int minutes, 352 int minutes,
353 int use_sg) 353 int use_sg)
@@ -372,7 +372,7 @@ static int usbat_write_block(struct us_data *us,
372 if (result != USB_STOR_XFER_GOOD) 372 if (result != USB_STOR_XFER_GOOD)
373 return USB_STOR_TRANSPORT_ERROR; 373 return USB_STOR_TRANSPORT_ERROR;
374 374
375 result = usbat_bulk_write(us, content, len, use_sg); 375 result = usbat_bulk_write(us, buf, len, use_sg);
376 if (result != USB_STOR_XFER_GOOD) 376 if (result != USB_STOR_XFER_GOOD)
377 return USB_STOR_TRANSPORT_ERROR; 377 return USB_STOR_TRANSPORT_ERROR;
378 378
@@ -392,7 +392,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
392 unsigned char timeout, 392 unsigned char timeout,
393 unsigned char qualifier, 393 unsigned char qualifier,
394 int direction, 394 int direction,
395 unsigned char *content, 395 void *buf,
396 unsigned short len, 396 unsigned short len,
397 int use_sg, 397 int use_sg,
398 int minutes) 398 int minutes)
@@ -472,7 +472,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
472 } 472 }
473 473
474 result = usb_stor_bulk_transfer_sg(us, 474 result = usb_stor_bulk_transfer_sg(us,
475 pipe, content, len, use_sg, NULL); 475 pipe, buf, len, use_sg, NULL);
476 476
477 /* 477 /*
478 * If we get a stall on the bulk download, we'll retry 478 * If we get a stall on the bulk download, we'll retry
@@ -606,7 +606,7 @@ static int usbat_multiple_write(struct us_data *us,
606 * other related details) are defined beforehand with _set_shuttle_features(). 606 * other related details) are defined beforehand with _set_shuttle_features().
607 */ 607 */
608static int usbat_read_blocks(struct us_data *us, 608static int usbat_read_blocks(struct us_data *us,
609 unsigned char *buffer, 609 void* buffer,
610 int len, 610 int len,
611 int use_sg) 611 int use_sg)
612{ 612{
@@ -648,7 +648,7 @@ static int usbat_read_blocks(struct us_data *us,
648 * other related details) are defined beforehand with _set_shuttle_features(). 648 * other related details) are defined beforehand with _set_shuttle_features().
649 */ 649 */
650static int usbat_write_blocks(struct us_data *us, 650static int usbat_write_blocks(struct us_data *us,
651 unsigned char *buffer, 651 void* buffer,
652 int len, 652 int len,
653 int use_sg) 653 int use_sg)
654{ 654{
@@ -1170,15 +1170,15 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1170 US_DEBUGP("handle_read10: transfersize %d\n", 1170 US_DEBUGP("handle_read10: transfersize %d\n",
1171 srb->transfersize); 1171 srb->transfersize);
1172 1172
1173 if (srb->request_bufflen < 0x10000) { 1173 if (scsi_bufflen(srb) < 0x10000) {
1174 1174
1175 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, 1175 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
1176 registers, data, 19, 1176 registers, data, 19,
1177 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD, 1177 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD,
1178 (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ), 1178 (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ),
1179 DMA_FROM_DEVICE, 1179 DMA_FROM_DEVICE,
1180 srb->request_buffer, 1180 scsi_sglist(srb),
1181 srb->request_bufflen, srb->use_sg, 1); 1181 scsi_bufflen(srb), scsi_sg_count(srb), 1);
1182 1182
1183 return result; 1183 return result;
1184 } 1184 }
@@ -1196,7 +1196,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1196 len <<= 16; 1196 len <<= 16;
1197 len |= data[7+7]; 1197 len |= data[7+7];
1198 US_DEBUGP("handle_read10: GPCMD_READ_CD: len %d\n", len); 1198 US_DEBUGP("handle_read10: GPCMD_READ_CD: len %d\n", len);
1199 srb->transfersize = srb->request_bufflen/len; 1199 srb->transfersize = scsi_bufflen(srb)/len;
1200 } 1200 }
1201 1201
1202 if (!srb->transfersize) { 1202 if (!srb->transfersize) {
@@ -1213,7 +1213,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1213 1213
1214 len = (65535/srb->transfersize) * srb->transfersize; 1214 len = (65535/srb->transfersize) * srb->transfersize;
1215 US_DEBUGP("Max read is %d bytes\n", len); 1215 US_DEBUGP("Max read is %d bytes\n", len);
1216 len = min(len, srb->request_bufflen); 1216 len = min(len, scsi_bufflen(srb));
1217 buffer = kmalloc(len, GFP_NOIO); 1217 buffer = kmalloc(len, GFP_NOIO);
1218 if (buffer == NULL) /* bloody hell! */ 1218 if (buffer == NULL) /* bloody hell! */
1219 return USB_STOR_TRANSPORT_FAILED; 1219 return USB_STOR_TRANSPORT_FAILED;
@@ -1222,10 +1222,10 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1222 sector |= short_pack(data[7+5], data[7+4]); 1222 sector |= short_pack(data[7+5], data[7+4]);
1223 transferred = 0; 1223 transferred = 0;
1224 1224
1225 while (transferred != srb->request_bufflen) { 1225 while (transferred != scsi_bufflen(srb)) {
1226 1226
1227 if (len > srb->request_bufflen - transferred) 1227 if (len > scsi_bufflen(srb) - transferred)
1228 len = srb->request_bufflen - transferred; 1228 len = scsi_bufflen(srb) - transferred;
1229 1229
1230 data[3] = len&0xFF; /* (cylL) = expected length (L) */ 1230 data[3] = len&0xFF; /* (cylL) = expected length (L) */
1231 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */ 1231 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
@@ -1261,7 +1261,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1261 transferred += len; 1261 transferred += len;
1262 sector += len / srb->transfersize; 1262 sector += len / srb->transfersize;
1263 1263
1264 } /* while transferred != srb->request_bufflen */ 1264 } /* while transferred != scsi_bufflen(srb) */
1265 1265
1266 kfree(buffer); 1266 kfree(buffer);
1267 return result; 1267 return result;
@@ -1429,9 +1429,8 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1429 unsigned char data[32]; 1429 unsigned char data[32];
1430 unsigned int len; 1430 unsigned int len;
1431 int i; 1431 int i;
1432 char string[64];
1433 1432
1434 len = srb->request_bufflen; 1433 len = scsi_bufflen(srb);
1435 1434
1436 /* Send A0 (ATA PACKET COMMAND). 1435 /* Send A0 (ATA PACKET COMMAND).
1437 Note: I guess we're never going to get any of the ATA 1436 Note: I guess we're never going to get any of the ATA
@@ -1472,8 +1471,8 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1472 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD, 1471 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD,
1473 (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ), 1472 (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ),
1474 DMA_TO_DEVICE, 1473 DMA_TO_DEVICE,
1475 srb->request_buffer, 1474 scsi_sglist(srb),
1476 len, srb->use_sg, 10); 1475 len, scsi_sg_count(srb), 10);
1477 1476
1478 if (result == USB_STOR_TRANSPORT_GOOD) { 1477 if (result == USB_STOR_TRANSPORT_GOOD) {
1479 transferred += len; 1478 transferred += len;
@@ -1540,23 +1539,8 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1540 len = *status; 1539 len = *status;
1541 1540
1542 1541
1543 result = usbat_read_block(us, srb->request_buffer, len, srb->use_sg); 1542 result = usbat_read_block(us, scsi_sglist(srb), len,
1544 1543 scsi_sg_count(srb));
1545 /* Debug-print the first 32 bytes of the transfer */
1546
1547 if (!srb->use_sg) {
1548 string[0] = 0;
1549 for (i=0; i<len && i<32; i++) {
1550 sprintf(string+strlen(string), "%02X ",
1551 ((unsigned char *)srb->request_buffer)[i]);
1552 if ((i%16)==15) {
1553 US_DEBUGP("%s\n", string);
1554 string[0] = 0;
1555 }
1556 }
1557 if (string[0]!=0)
1558 US_DEBUGP("%s\n", string);
1559 }
1560 } 1544 }
1561 1545
1562 return result; 1546 return result;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index c646750ccc30..d9f4912f873d 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -459,6 +459,22 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
459} 459}
460 460
461/* 461/*
462 * Common used function. Transfer a complete command
463 * via usb_stor_bulk_transfer_sglist() above. Set cmnd resid
464 */
465int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
466 struct scsi_cmnd* srb)
467{
468 unsigned int partial;
469 int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
470 scsi_sg_count(srb), scsi_bufflen(srb),
471 &partial);
472
473 scsi_set_resid(srb, scsi_bufflen(srb) - partial);
474 return result;
475}
476
477/*
462 * Transfer an entire SCSI command's worth of data payload over the bulk 478 * Transfer an entire SCSI command's worth of data payload over the bulk
463 * pipe. 479 * pipe.
464 * 480 *
@@ -508,7 +524,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
508 int result; 524 int result;
509 525
510 /* send the command to the transport layer */ 526 /* send the command to the transport layer */
511 srb->resid = 0; 527 scsi_set_resid(srb, 0);
512 result = us->transport(srb, us); 528 result = us->transport(srb, us);
513 529
514 /* if the command gets aborted by the higher layers, we need to 530 /* if the command gets aborted by the higher layers, we need to
@@ -568,7 +584,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
568 * A short transfer on a command where we don't expect it 584 * A short transfer on a command where we don't expect it
569 * is unusual, but it doesn't mean we need to auto-sense. 585 * is unusual, but it doesn't mean we need to auto-sense.
570 */ 586 */
571 if ((srb->resid > 0) && 587 if ((scsi_get_resid(srb) > 0) &&
572 !((srb->cmnd[0] == REQUEST_SENSE) || 588 !((srb->cmnd[0] == REQUEST_SENSE) ||
573 (srb->cmnd[0] == INQUIRY) || 589 (srb->cmnd[0] == INQUIRY) ||
574 (srb->cmnd[0] == MODE_SENSE) || 590 (srb->cmnd[0] == MODE_SENSE) ||
@@ -593,7 +609,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
593 srb->cmd_len = 12; 609 srb->cmd_len = 12;
594 610
595 /* issue the auto-sense command */ 611 /* issue the auto-sense command */
596 srb->resid = 0; 612 scsi_set_resid(srb, 0);
597 temp_result = us->transport(us->srb, us); 613 temp_result = us->transport(us->srb, us);
598 614
599 /* let's clean up right away */ 615 /* let's clean up right away */
@@ -649,7 +665,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
649 665
650 /* Did we transfer less than the minimum amount required? */ 666 /* Did we transfer less than the minimum amount required? */
651 if (srb->result == SAM_STAT_GOOD && 667 if (srb->result == SAM_STAT_GOOD &&
652 srb->request_bufflen - srb->resid < srb->underflow) 668 scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
653 srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24); 669 srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24);
654 670
655 return; 671 return;
@@ -708,7 +724,7 @@ void usb_stor_stop_transport(struct us_data *us)
708 724
709int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us) 725int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us)
710{ 726{
711 unsigned int transfer_length = srb->request_bufflen; 727 unsigned int transfer_length = scsi_bufflen(srb);
712 unsigned int pipe = 0; 728 unsigned int pipe = 0;
713 int result; 729 int result;
714 730
@@ -737,9 +753,7 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us)
737 if (transfer_length) { 753 if (transfer_length) {
738 pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 754 pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
739 us->recv_bulk_pipe : us->send_bulk_pipe; 755 us->recv_bulk_pipe : us->send_bulk_pipe;
740 result = usb_stor_bulk_transfer_sg(us, pipe, 756 result = usb_stor_bulk_srb(us, pipe, srb);
741 srb->request_buffer, transfer_length,
742 srb->use_sg, &srb->resid);
743 US_DEBUGP("CBI data stage result is 0x%x\n", result); 757 US_DEBUGP("CBI data stage result is 0x%x\n", result);
744 758
745 /* if we stalled the data transfer it means command failed */ 759 /* if we stalled the data transfer it means command failed */
@@ -808,7 +822,7 @@ int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us)
808 */ 822 */
809int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us) 823int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
810{ 824{
811 unsigned int transfer_length = srb->request_bufflen; 825 unsigned int transfer_length = scsi_bufflen(srb);
812 int result; 826 int result;
813 827
814 /* COMMAND STAGE */ 828 /* COMMAND STAGE */
@@ -836,9 +850,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
836 if (transfer_length) { 850 if (transfer_length) {
837 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 851 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
838 us->recv_bulk_pipe : us->send_bulk_pipe; 852 us->recv_bulk_pipe : us->send_bulk_pipe;
839 result = usb_stor_bulk_transfer_sg(us, pipe, 853 result = usb_stor_bulk_srb(us, pipe, srb);
840 srb->request_buffer, transfer_length,
841 srb->use_sg, &srb->resid);
842 US_DEBUGP("CB data stage result is 0x%x\n", result); 854 US_DEBUGP("CB data stage result is 0x%x\n", result);
843 855
844 /* if we stalled the data transfer it means command failed */ 856 /* if we stalled the data transfer it means command failed */
@@ -904,7 +916,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
904{ 916{
905 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 917 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
906 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 918 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
907 unsigned int transfer_length = srb->request_bufflen; 919 unsigned int transfer_length = scsi_bufflen(srb);
908 unsigned int residue; 920 unsigned int residue;
909 int result; 921 int result;
910 int fake_sense = 0; 922 int fake_sense = 0;
@@ -955,9 +967,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
955 if (transfer_length) { 967 if (transfer_length) {
956 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 968 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
957 us->recv_bulk_pipe : us->send_bulk_pipe; 969 us->recv_bulk_pipe : us->send_bulk_pipe;
958 result = usb_stor_bulk_transfer_sg(us, pipe, 970 result = usb_stor_bulk_srb(us, pipe, srb);
959 srb->request_buffer, transfer_length,
960 srb->use_sg, &srb->resid);
961 US_DEBUGP("Bulk data transfer result 0x%x\n", result); 971 US_DEBUGP("Bulk data transfer result 0x%x\n", result);
962 if (result == USB_STOR_XFER_ERROR) 972 if (result == USB_STOR_XFER_ERROR)
963 return USB_STOR_TRANSPORT_ERROR; 973 return USB_STOR_TRANSPORT_ERROR;
@@ -1036,7 +1046,8 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1036 if (residue) { 1046 if (residue) {
1037 if (!(us->flags & US_FL_IGNORE_RESIDUE)) { 1047 if (!(us->flags & US_FL_IGNORE_RESIDUE)) {
1038 residue = min(residue, transfer_length); 1048 residue = min(residue, transfer_length);
1039 srb->resid = max(srb->resid, (int) residue); 1049 scsi_set_resid(srb, max(scsi_get_resid(srb),
1050 (int) residue));
1040 } 1051 }
1041 } 1052 }
1042 1053
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index 633a715850a4..ada7c2f43f84 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -139,6 +139,8 @@ extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
139 void *buf, unsigned int length, unsigned int *act_len); 139 void *buf, unsigned int length, unsigned int *act_len);
140extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 140extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
141 void *buf, unsigned int length, int use_sg, int *residual); 141 void *buf, unsigned int length, int use_sg, int *residual);
142extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
143 struct scsi_cmnd* srb);
142 144
143extern int usb_stor_port_reset(struct us_data *us); 145extern int usb_stor_port_reset(struct us_data *us);
144#endif 146#endif