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

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

This patch changes the sddr55 driver to make it use the new scatter-gather
routines.  It has not been tested, but perhaps Andries Brouwer will be
able to try it out.
parent 0ab5aead
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,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"
...@@ -155,7 +154,7 @@ static int sddr55_read_data(struct us_data *us, ...@@ -155,7 +154,7 @@ static int sddr55_read_data(struct us_data *us,
unsigned int lba, unsigned int lba,
unsigned int page, unsigned int page,
unsigned short sectors, unsigned short sectors,
unsigned char *content, unsigned char *buffer,
int use_sg) { int use_sg) {
int result = USB_STOR_TRANSPORT_GOOD; int result = USB_STOR_TRANSPORT_GOOD;
...@@ -167,17 +166,20 @@ static int sddr55_read_data(struct us_data *us, ...@@ -167,17 +166,20 @@ static int sddr55_read_data(struct us_data *us,
unsigned long address; unsigned long address;
unsigned short pages; unsigned short pages;
unsigned char *buffer = NULL; unsigned int len, index, offset;
unsigned char *ptr;
int len; // Since we only read in one block at a time, we have to create
// a bounce buffer if the transfer uses scatter-gather.
len = sectors * PAGESIZE;
if (use_sg) {
buffer = (use_sg ? kmalloc(len, GFP_NOIO) : content); len = min((unsigned int) sectors,
if (buffer == NULL) (unsigned int) info->blocksize >>
return USB_STOR_TRANSPORT_ERROR; /* out of memory */ info->smallpageshift) * PAGESIZE;
buffer = kmalloc(len, GFP_NOIO);
ptr = buffer; if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; /* out of memory */
}
index = offset = 0;
while (sectors>0) { while (sectors>0) {
...@@ -189,9 +191,9 @@ static int sddr55_read_data(struct us_data *us, ...@@ -189,9 +191,9 @@ static int sddr55_read_data(struct us_data *us,
// Read as many sectors as possible in this block // Read as many sectors as possible in this block
pages = info->blocksize - page; pages = min((unsigned int) sectors << info->smallpageshift,
if (pages > (sectors << info->smallpageshift)) info->blocksize - page);
pages = (sectors << info->smallpageshift); len = pages << info->pageshift;
US_DEBUGP("Read %02X pages, from PBA %04X" US_DEBUGP("Read %02X pages, from PBA %04X"
" (LBA %04X) page %02X\n", " (LBA %04X) page %02X\n",
...@@ -199,7 +201,7 @@ static int sddr55_read_data(struct us_data *us, ...@@ -199,7 +201,7 @@ static int sddr55_read_data(struct us_data *us,
if (pba == NOT_ALLOCATED) { if (pba == NOT_ALLOCATED) {
/* no pba for this lba, fill with zeroes */ /* no pba for this lba, fill with zeroes */
memset (ptr, 0, pages << info->pageshift); memset (buffer, 0, len);
} else { } else {
address = (pba << info->blockshift) + page; address = (pba << info->blockshift) + page;
...@@ -228,8 +230,7 @@ static int sddr55_read_data(struct us_data *us, ...@@ -228,8 +230,7 @@ static int sddr55_read_data(struct us_data *us,
/* read data */ /* read data */
result = sddr55_bulk_transport(us, result = sddr55_bulk_transport(us,
SCSI_DATA_READ, ptr, SCSI_DATA_READ, buffer, len);
pages<<info->pageshift);
if (result != USB_STOR_XFER_GOOD) { if (result != USB_STOR_XFER_GOOD) {
result = USB_STOR_TRANSPORT_ERROR; result = USB_STOR_TRANSPORT_ERROR;
...@@ -252,14 +253,17 @@ static int sddr55_read_data(struct us_data *us, ...@@ -252,14 +253,17 @@ static int sddr55_read_data(struct us_data *us,
goto leave; goto leave;
} }
} }
if (use_sg)
usb_stor_access_xfer_buf(buffer, len, us->srb,
&index, &offset, TO_XFER_BUF);
else
buffer += len;
page = 0; page = 0;
lba++; lba++;
sectors -= pages >> info->smallpageshift; sectors -= pages >> info->smallpageshift;
ptr += (pages << info->pageshift);
} }
us_copy_to_sgbuf_all(buffer, len, content, use_sg);
result = USB_STOR_TRANSPORT_GOOD; result = USB_STOR_TRANSPORT_GOOD;
leave: leave:
...@@ -273,7 +277,7 @@ static int sddr55_write_data(struct us_data *us, ...@@ -273,7 +277,7 @@ static int sddr55_write_data(struct us_data *us,
unsigned int lba, unsigned int lba,
unsigned int page, unsigned int page,
unsigned short sectors, unsigned short sectors,
unsigned char *content, unsigned char *buffer,
int use_sg) { int use_sg) {
int result = USB_STOR_TRANSPORT_GOOD; int result = USB_STOR_TRANSPORT_GOOD;
...@@ -286,9 +290,8 @@ static int sddr55_write_data(struct us_data *us, ...@@ -286,9 +290,8 @@ static int sddr55_write_data(struct us_data *us,
unsigned long address; unsigned long address;
unsigned short pages; unsigned short pages;
unsigned char *buffer = NULL; int i;
unsigned char *ptr; unsigned int len, index, offset;
int i, len;
/* check if we are allowed to write */ /* check if we are allowed to write */
if (info->read_only || info->force_read_only) { if (info->read_only || info->force_read_only) {
...@@ -296,13 +299,18 @@ static int sddr55_write_data(struct us_data *us, ...@@ -296,13 +299,18 @@ static int sddr55_write_data(struct us_data *us,
return USB_STOR_TRANSPORT_FAILED; return USB_STOR_TRANSPORT_FAILED;
} }
len = sectors * PAGESIZE; // Since we only write one block at a time, we have to create
// a bounce buffer if the transfer uses scatter-gather.
buffer = us_copy_from_sgbuf_all(content, len, use_sg);
if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR;
ptr = buffer; if (use_sg) {
len = min((unsigned int) sectors,
(unsigned int) info->blocksize >>
info->smallpageshift) * PAGESIZE;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR;
}
index = offset = 0;
while (sectors > 0) { while (sectors > 0) {
...@@ -314,9 +322,12 @@ static int sddr55_write_data(struct us_data *us, ...@@ -314,9 +322,12 @@ static int sddr55_write_data(struct us_data *us,
// Write as many sectors as possible in this block // Write as many sectors as possible in this block
pages = info->blocksize - page; pages = min((unsigned int) sectors << info->smallpageshift,
if (pages > (sectors << info->smallpageshift)) info->blocksize - page);
pages = (sectors << info->smallpageshift); len = pages << info->pageshift;
if (use_sg)
usb_stor_access_xfer_buf(buffer, len, us->srb,
&index, &offset, FROM_XFER_BUF);
US_DEBUGP("Write %02X pages, to PBA %04X" US_DEBUGP("Write %02X pages, to PBA %04X"
" (LBA %04X) page %02X\n", " (LBA %04X) page %02X\n",
...@@ -400,8 +411,7 @@ static int sddr55_write_data(struct us_data *us, ...@@ -400,8 +411,7 @@ static int sddr55_write_data(struct us_data *us,
/* send the data */ /* send the data */
result = sddr55_bulk_transport(us, result = sddr55_bulk_transport(us,
SCSI_DATA_WRITE, ptr, SCSI_DATA_WRITE, buffer, len);
pages<<info->pageshift);
if (result != USB_STOR_XFER_GOOD) { if (result != USB_STOR_XFER_GOOD) {
US_DEBUGP("Result for send_data in write_data %d\n", US_DEBUGP("Result for send_data in write_data %d\n",
...@@ -458,10 +468,11 @@ static int sddr55_write_data(struct us_data *us, ...@@ -458,10 +468,11 @@ static int sddr55_write_data(struct us_data *us,
/* update the pba<->lba maps for new_pba */ /* update the pba<->lba maps for new_pba */
info->pba_to_lba[new_pba] = lba % 1000; info->pba_to_lba[new_pba] = lba % 1000;
if (!use_sg)
buffer += len;
page = 0; page = 0;
lba++; lba++;
sectors -= pages >> info->smallpageshift; sectors -= pages >> info->smallpageshift;
ptr += (pages << info->pageshift);
} }
result = USB_STOR_TRANSPORT_GOOD; result = USB_STOR_TRANSPORT_GOOD;
......
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