Commit 313b9054 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[PATCH] USB storage: Convert jumpshot to use the new s-g routines

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