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;
do { // Since we don't read 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);
alloclen = min(totallen, 65536u);
if (use_sg) { if (use_sg) {
buffer = kmalloc(len, GFP_NOIO); buffer = kmalloc(alloclen, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
ptr = buffer;
} else {
ptr = dest;
} }
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;
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; if (use_sg)
sector += thistime; usb_stor_access_xfer_buf(buffer, len, us->srb,
&sg_idx, &sg_offset, TO_XFER_BUF);
if (use_sg) { else
us_copy_to_sgbuf(buffer, len, dest, buffer += len;
&sg_idx, &current_sg_offset, use_sg);
kfree(buffer);
} else {
dest += 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, alloclen = min(totallen, 65536u);
// first copy all to one big buffer if (use_sg) {
buffer = kmalloc(alloclen, GFP_NOIO);
buffer = us_copy_from_sgbuf(src, len, &sg_idx,
&sg_offset, use_sg);
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;
...@@ -270,17 +268,15 @@ static int jumpshot_write_data(struct us_data *us, ...@@ -270,17 +268,15 @@ 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; if (!use_sg)
sector += thistime; buffer += len;
if (use_sg)
kfree(buffer);
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:
......
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