Commit eae28375 authored by Andries E. Brouwer's avatar Andries E. Brouwer Committed by Greg Kroah-Hartman

[PATCH] usb-storage

Created the first of a series of usb-storage patches
this afternoon. Please find it below or on ftp.XX.kernel.org
under people/aeb/2.5.16-us-patch .
It removes 5% of the usb-storage code, but should, if I made
no mistake, not affect the behaviour of the code.

(This is the introduction of raw_bulk.c to hold USB-bulk
and scatter-gather code that was repeated three-five times
in various drivers. The next patch is smartmedia.c.)
parent 9d74f116
...@@ -11,14 +11,14 @@ EXTRA_CFLAGS := -I../../scsi/ ...@@ -11,14 +11,14 @@ EXTRA_CFLAGS := -I../../scsi/
obj-$(CONFIG_USB_STORAGE) += usb-storage.o obj-$(CONFIG_USB_STORAGE) += usb-storage.o
usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o
usb-storage-obj-$(CONFIG_USB_STORAGE_HP8200e) += shuttle_usbat.o usb-storage-obj-$(CONFIG_USB_STORAGE_HP8200e) += shuttle_usbat.o raw_bulk.o
usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o raw_bulk.o
usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o raw_bulk.o
usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o
usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o
usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o
usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o raw_bulk.o
usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o raw_bulk.o
usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
initializers.o $(usb-storage-obj-y) initializers.o $(usb-storage-obj-y)
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
*/ */
#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"
...@@ -60,113 +61,31 @@ ...@@ -60,113 +61,31 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
extern int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe, static int datafab_determine_lun(struct us_data *us,
unsigned int len, unsigned int *act_len); struct datafab_info *info);
static int datafab_determine_lun(struct us_data *us, struct datafab_info *info);
static void datafab_dump_data(unsigned char *data, int len)
{
unsigned char buf[80];
int sofar = 0;
if (!data)
return;
memset(buf, 0, sizeof(buf));
for (sofar = 0; sofar < len; sofar++) {
sprintf(buf + strlen(buf), "%02x ",
((unsigned int) data[sofar]) & 0xFF);
if (sofar % 16 == 15) {
US_DEBUGP("datafab: %s\n", buf);
memset(buf, 0, sizeof(buf));
}
}
if (strlen(buf) != 0)
US_DEBUGP("datafab: %s\n", buf);
}
static int datafab_raw_bulk(int direction,
struct us_data *us,
unsigned char *data,
unsigned int len)
{
int result;
int act_len;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, &act_len);
// if we stall, we need to clear it before we go on
if (result == -EPIPE) {
US_DEBUGP("datafab_raw_bulk: EPIPE. clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n", pipe, act_len);
usb_stor_clear_halt(us, pipe);
}
if (result) {
// NAK - that means we've retried a few times already
if (result == -ETIMEDOUT) {
US_DEBUGP("datafab_raw_bulk: device NAKed\n");
return US_BULK_TRANSFER_FAILED;
}
// -ENOENT -- we canceled this transfer
if (result == -ENOENT) {
US_DEBUGP("datafab_raw_bulk: transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
if (result == -EPIPE) {
US_DEBUGP("datafab_raw_bulk: output pipe stalled\n");
return USB_STOR_TRANSPORT_FAILED;
}
// the catch-all case
US_DEBUGP("datafab_raw_bulk: unknown error\n");
return US_BULK_TRANSFER_FAILED;
}
if (act_len != len) { static inline int
US_DEBUGP("datafab_raw_bulk: Warning. Transferred only %d bytes\n", act_len); datafab_bulk_read(struct us_data *us, unsigned char *data, unsigned int len) {
return US_BULK_TRANSFER_SHORT; unsigned int act_len; /* ignored */
}
US_DEBUGP("datafab_raw_bulk: Transfered %d of %d bytes\n", act_len, len);
return US_BULK_TRANSFER_GOOD;
}
static inline int datafab_bulk_read(struct us_data *us,
unsigned char *data,
unsigned int len)
{
if (len == 0) if (len == 0)
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
US_DEBUGP("datafab_bulk_read: len = %d\n", len); US_DEBUGP("datafab_bulk_read: len = %d\n", len);
return datafab_raw_bulk(SCSI_DATA_READ, us, data, len); return usb_storage_raw_bulk(us, SCSI_DATA_READ, data, len, &act_len);
} }
static inline int datafab_bulk_write(struct us_data *us, static inline int
unsigned char *data, datafab_bulk_write(struct us_data *us, unsigned char *data, unsigned int len) {
unsigned int len) unsigned int act_len; /* ignored */
{
if (len == 0) if (len == 0)
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
US_DEBUGP("datafab_bulk_write: len = %d\n", len); US_DEBUGP("datafab_bulk_write: len = %d\n", len);
return datafab_raw_bulk(SCSI_DATA_WRITE, us, data, len); return usb_storage_raw_bulk(us, SCSI_DATA_WRITE, data, len, &act_len);
} }
...@@ -181,10 +100,9 @@ static int datafab_read_data(struct us_data *us, ...@@ -181,10 +100,9 @@ static int datafab_read_data(struct us_data *us,
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
unsigned char thistime; unsigned char thistime;
struct scatterlist *sg = NULL;
int totallen, len, result; int totallen, len, result;
int sg_idx = 0, current_sg_offset = 0; int sg_idx = 0, sg_offset = 0;
int transferred, rc; int rc;
// 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 Datafab // we can support up to 28-bit addressing. I don't know if Datafab
...@@ -202,28 +120,17 @@ static int datafab_read_data(struct us_data *us, ...@@ -202,28 +120,17 @@ static int datafab_read_data(struct us_data *us,
command[5] += (info->lun << 4); command[5] += (info->lun << 4);
// If we're using scatter-gather, we have to create a new
// buffer to read all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
totallen = sectors * info->ssize; totallen = sectors * info->ssize;
do { do {
// loop, never allocate or transfer more than 64k at once (min(128k, 255*info->ssize) is the real limit) // 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); len = min_t(int, totallen, 65536);
if (use_sg) { ptr = buffer = (use_sg ? kmalloc(len, GFP_NOIO) : dest);
sg = (struct scatterlist *) dest;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
ptr = buffer;
} else {
ptr = dest;
}
thistime = (len / info->ssize) & 0xff; thistime = (len / info->ssize) & 0xff;
...@@ -235,53 +142,22 @@ static int datafab_read_data(struct us_data *us, ...@@ -235,53 +142,22 @@ static int datafab_read_data(struct us_data *us,
command[5] |= (sector >> 24) & 0x0F; command[5] |= (sector >> 24) & 0x0F;
// send the command // send the read command
US_DEBUGP("datafab_read_data: sending following command\n");
datafab_dump_data(command, sizeof(command));
result = datafab_bulk_write(us, command, sizeof(command)); result = datafab_bulk_write(us, command, sizeof(command));
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
// read the result // read the result
result = datafab_bulk_read(us, ptr, len); result = datafab_bulk_read(us, ptr, len);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
US_DEBUGP("datafab_read_data results: %d bytes\n", len);
// datafab_dump_data(ptr, len);
sectors -= thistime; sectors -= thistime;
sector += thistime; sector += thistime;
if (use_sg) { if (use_sg) {
transferred = 0; us_copy_to_sgbuf(buffer, len, dest,
while (sg_idx < use_sg && transferred < len) { &sg_idx, &sg_offset, use_sg);
if (len - transferred >= sg[sg_idx].length - current_sg_offset) {
US_DEBUGP("datafab_read_data: adding %d bytes to %d byte sg buffer\n", sg[sg_idx].length - current_sg_offset, sg[sg_idx].length);
memcpy(page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
buffer + transferred,
sg[sg_idx].length - current_sg_offset);
transferred += sg[sg_idx].length - current_sg_offset;
current_sg_offset = 0;
// on to the next sg buffer
++sg_idx;
} else {
US_DEBUGP("datafab_read_data: adding %d bytes to %d byte sg buffer\n", len - transferred, sg[sg_idx].length);
memcpy(page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
buffer + transferred,
len - transferred);
current_sg_offset += len - transferred;
// this sg buffer is only partially full and we're out of data to copy in
break;
}
}
kfree(buffer); kfree(buffer);
} else { } else {
dest += len; dest += len;
...@@ -291,6 +167,11 @@ static int datafab_read_data(struct us_data *us, ...@@ -291,6 +167,11 @@ static int datafab_read_data(struct us_data *us,
} while (totallen > 0); } while (totallen > 0);
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
leave:
if (use_sg)
kfree(buffer);
return result;
} }
...@@ -306,10 +187,8 @@ static int datafab_write_data(struct us_data *us, ...@@ -306,10 +187,8 @@ static int datafab_write_data(struct us_data *us,
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
unsigned char thistime; unsigned char thistime;
struct scatterlist *sg = NULL; int totallen, len, result, rc;
int totallen, len, result; int sg_idx = 0, sg_offset = 0;
int sg_idx = 0, current_sg_offset = 0;
int transferred, rc;
// 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 Datafab // we can support up to 28-bit addressing. I don't know if Datafab
...@@ -337,44 +216,20 @@ static int datafab_write_data(struct us_data *us, ...@@ -337,44 +216,20 @@ static int datafab_write_data(struct us_data *us,
totallen = sectors * info->ssize; totallen = sectors * info->ssize;
do { do {
// loop, never allocate or transfer more than 64k at once (min(128k, 255*info->ssize) is the real limit) // 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); len = min_t(int, totallen, 65536);
if (use_sg) { // if we are using scatter-gather,
sg = (struct scatterlist *) src; // first copy all to one big buffer
buffer = kmalloc(len, 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;
memset(buffer, 0, len); ptr = buffer;
// copy the data from the sg bufs into the big contiguous buf
//
transferred = 0;
while (transferred < len) {
if (len - transferred >= sg[sg_idx].length - current_sg_offset) {
US_DEBUGP("datafab_write_data: getting %d bytes from %d byte sg buffer\n", sg[sg_idx].length - current_sg_offset, sg[sg_idx].length);
memcpy(ptr + transferred,
page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
sg[sg_idx].length - current_sg_offset);
transferred += sg[sg_idx].length - current_sg_offset;
current_sg_offset = 0;
// on to the next sg buffer
++sg_idx;
} else {
US_DEBUGP("datafab_write_data: getting %d bytes from %d byte sg buffer\n", len - transferred, sg[sg_idx].length);
memcpy(ptr + transferred,
page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
len - transferred);
current_sg_offset += len - transferred;
// we only copied part of this sg buffer
break;
}
}
} else {
ptr = src;
}
thistime = (len / info->ssize) & 0xff; thistime = (len / info->ssize) & 0xff;
...@@ -387,64 +242,57 @@ static int datafab_write_data(struct us_data *us, ...@@ -387,64 +242,57 @@ static int datafab_write_data(struct us_data *us,
command[5] |= (sector >> 24) & 0x0F; command[5] |= (sector >> 24) & 0x0F;
// send the command // send the command
US_DEBUGP("datafab_write_data: sending following command\n");
datafab_dump_data(command, sizeof(command));
result = datafab_bulk_write(us, command, sizeof(command)); result = datafab_bulk_write(us, command, sizeof(command));
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
// send the data // send the data
result = datafab_bulk_write(us, ptr, len); result = datafab_bulk_write(us, ptr, len);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
// read the result // read the result
result = datafab_bulk_read(us, reply, sizeof(reply)); result = datafab_bulk_read(us, reply, sizeof(reply));
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
if (reply[0] != 0x50 && reply[1] != 0) { if (reply[0] != 0x50 && reply[1] != 0) {
US_DEBUGP("datafab_write_data: Gah! write return code: %02x %02x\n", reply[0], reply[1]); US_DEBUGP("datafab_write_data: Gah! "
if (use_sg) "write return code: %02x %02x\n",
kfree(buffer); reply[0], reply[1]);
return USB_STOR_TRANSPORT_ERROR; result = USB_STOR_TRANSPORT_ERROR;
goto leave;
} }
sectors -= thistime; sectors -= thistime;
sector += thistime; sector += thistime;
if (use_sg) { if (use_sg)
kfree(buffer); kfree(buffer);
} else { else
src += len; src += len;
}
totallen -= len; totallen -= len;
} while (totallen > 0); } while (totallen > 0);
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
leave:
if (use_sg)
kfree(buffer);
return result;
} }
static int datafab_determine_lun(struct us_data *us, static int datafab_determine_lun(struct us_data *us,
struct datafab_info *info) struct datafab_info *info)
{ {
// dual-slot readers can be thought of as dual-LUN devices. we need to // Dual-slot readers can be thought of as dual-LUN devices.
// determine which card slot is being used. we'll send an IDENTIFY DEVICE // We need to determine which card slot is being used.
// command and see which LUN responds... // We'll send an IDENTIFY DEVICE command and see which LUN responds...
//
// there might be a better way of doing this?
// //
// There might be a better way of doing this?
unsigned char command[8] = { 0, 1, 0, 0, 0, 0xa0, 0xec, 1 }; unsigned char command[8] = { 0, 1, 0, 0, 0, 0xa0, 0xec, 1 };
unsigned char buf[512]; unsigned char buf[512];
int count = 0, rc; int count = 0, rc;
...@@ -454,9 +302,9 @@ static int datafab_determine_lun(struct us_data *us, ...@@ -454,9 +302,9 @@ static int datafab_determine_lun(struct us_data *us,
US_DEBUGP("datafab_determine_lun: locating...\n"); US_DEBUGP("datafab_determine_lun: locating...\n");
// we'll try 10 times before giving up... // we'll try 3 times before giving up...
// //
while (count++ < 10) { while (count++ < 3) {
command[5] = 0xa0; command[5] = 0xa0;
rc = datafab_bulk_write(us, command, 8); rc = datafab_bulk_write(us, command, 8);
...@@ -676,7 +524,8 @@ int datafab_transport(Scsi_Cmnd * srb, struct us_data *us) ...@@ -676,7 +524,8 @@ int datafab_transport(Scsi_Cmnd * srb, struct us_data *us)
if (!us->extra) { if (!us->extra) {
us->extra = kmalloc(sizeof(struct datafab_info), GFP_NOIO); us->extra = kmalloc(sizeof(struct datafab_info), GFP_NOIO);
if (!us->extra) { if (!us->extra) {
US_DEBUGP("datafab_transport: Gah! Can't allocate storage for Datafab info struct!\n"); US_DEBUGP("datafab_transport: Gah! "
"Can't allocate storage for Datafab info struct!\n");
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
} }
memset(us->extra, 0, sizeof(struct datafab_info)); memset(us->extra, 0, sizeof(struct datafab_info));
...@@ -827,6 +676,7 @@ int datafab_transport(Scsi_Cmnd * srb, struct us_data *us) ...@@ -827,6 +676,7 @@ int datafab_transport(Scsi_Cmnd * srb, struct us_data *us)
return rc; return rc;
} }
US_DEBUGP("datafab_transport: Gah! Unknown command: %d (0x%x)\n", srb->cmnd[0], srb->cmnd[0]); US_DEBUGP("datafab_transport: Gah! Unknown command: %d (0x%x)\n",
srb->cmnd[0], srb->cmnd[0]);
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
} }
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
*/ */
#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"
...@@ -57,164 +58,17 @@ ...@@ -57,164 +58,17 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
u8 request, u8 requesttype, u16 value,
u16 index, void *data, u16 size);
extern int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe,
unsigned int len, unsigned int *act_len);
#if 0
static void jumpshot_dump_data(unsigned char *data, int len)
{
unsigned char buf[80];
int sofar = 0;
if (!data)
return;
memset(buf, 0, sizeof(buf));
for (sofar = 0; sofar < len; sofar++) {
sprintf(buf + strlen(buf), "%02x ",
((unsigned int) data[sofar]) & 0xFF);
if (sofar % 16 == 15) {
US_DEBUGP("jumpshot: %s\n", buf);
memset(buf, 0, sizeof(buf));
}
}
if (strlen(buf) != 0)
US_DEBUGP("jumpshot: %s\n", buf);
}
#endif
/*
* Send a control message and wait for the response.
*
* us - the pointer to the us_data structure for the device to use
*
* request - the URB Setup Packet's first 6 bytes. The first byte always
* corresponds to the request type, and the second byte always corresponds
* to the request. The other 4 bytes do not correspond to value and index,
* since they are used in a custom way by the SCM protocol.
*
* xfer_data - a buffer from which to get, or to which to store, any data
* that gets send or received, respectively, with the URB. Even though
* it looks like we allocate a buffer in this code for the data, xfer_data
* must contain enough allocated space.
*
* xfer_len - the number of bytes to send or receive with the URB.
*
* This routine snarfed from the SanDisk SDDR-09 driver
*
*/
static int jumpshot_send_control(struct us_data *us,
int pipe,
unsigned char request,
unsigned char requesttype,
unsigned short value,
unsigned short index,
unsigned char *xfer_data,
unsigned int xfer_len)
{
int result;
// Send the URB to the device and wait for a response.
/* Why are request and request type reversed in this call? */
result = usb_stor_control_msg(us, pipe,
request, requesttype,
value, index, xfer_data, xfer_len);
// Check the return code for the command.
if (result < 0) {
/* if the command was aborted, indicate that */
if (result == -ENOENT)
return USB_STOR_TRANSPORT_ABORTED;
/* a stall is a fatal condition from the device */
if (result == -EPIPE) {
US_DEBUGP("jumpshot_send_control: -- Stall on control pipe. Clearing\n");
result = usb_stor_clear_halt(us, pipe);
US_DEBUGP("jumpshot_send_control: -- usb_stor_clear_halt() returns %d\n", result);
return USB_STOR_TRANSPORT_FAILED;
}
/* Uh oh... serious problem here */
return USB_STOR_TRANSPORT_ERROR;
}
return USB_STOR_TRANSPORT_GOOD;
}
static int jumpshot_raw_bulk(int direction,
struct us_data *us,
unsigned char *data,
unsigned int len)
{
int result;
int act_len;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, &act_len);
// if we stall, we need to clear it before we go on
if (result == -EPIPE) {
US_DEBUGP("jumpshot_raw_bulk: EPIPE. clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n", pipe, act_len);
usb_stor_clear_halt(us, pipe);
}
if (result) {
// NAK - that means we've retried a few times already
if (result == -ETIMEDOUT) {
US_DEBUGP("jumpshot_raw_bulk: device NAKed\n");
return US_BULK_TRANSFER_FAILED;
}
// -ENOENT -- we canceled this transfer
if (result == -ENOENT) {
US_DEBUGP("jumpshot_raw_bulk: transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
if (result == -EPIPE) {
US_DEBUGP("jumpshot_raw_bulk: output pipe stalled\n");
return USB_STOR_TRANSPORT_FAILED;
}
// the catch-all case
US_DEBUGP("jumpshot_raw_bulk: unknown error\n");
return US_BULK_TRANSFER_FAILED;
}
if (act_len != len) {
US_DEBUGP("jumpshot_raw_bulk: Warning. Transferred only %d bytes\n", act_len);
return US_BULK_TRANSFER_SHORT;
}
US_DEBUGP("jumpshot_raw_bulk: Transferred %d of %d bytes\n", act_len, len);
return US_BULK_TRANSFER_GOOD;
}
static inline int jumpshot_bulk_read(struct us_data *us, static inline int jumpshot_bulk_read(struct us_data *us,
unsigned char *data, unsigned char *data,
unsigned int len) unsigned int len)
{ {
unsigned int act_len; /* ignored */
if (len == 0) if (len == 0)
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
US_DEBUGP("jumpshot_bulk_read: len = %d\n", len); US_DEBUGP("jumpshot_bulk_read: len = %d\n", len);
return jumpshot_raw_bulk(SCSI_DATA_READ, us, data, len); return usb_storage_raw_bulk(us, SCSI_DATA_READ, data, len, &act_len);
} }
...@@ -222,11 +76,13 @@ static inline int jumpshot_bulk_write(struct us_data *us, ...@@ -222,11 +76,13 @@ static inline int jumpshot_bulk_write(struct us_data *us,
unsigned char *data, unsigned char *data,
unsigned int len) unsigned int len)
{ {
unsigned int act_len; /* ignored */
if (len == 0) if (len == 0)
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
US_DEBUGP("jumpshot_bulk_write: len = %d\n", len); US_DEBUGP("jumpshot_bulk_write: len = %d\n", len);
return jumpshot_raw_bulk(SCSI_DATA_WRITE, us, data, len); return usb_storage_raw_bulk(us, SCSI_DATA_WRITE, data, len, &act_len);
} }
...@@ -239,7 +95,7 @@ static int jumpshot_get_status(struct us_data *us) ...@@ -239,7 +95,7 @@ static int jumpshot_get_status(struct us_data *us)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
// send the setup // send the setup
rc = jumpshot_send_control(us, rc = usb_storage_send_control(us,
usb_rcvctrlpipe(us->pusb_dev, 0), usb_rcvctrlpipe(us->pusb_dev, 0),
0, 0xA0, 0, 7, &reply, 1); 0, 0xA0, 0, 7, &reply, 1);
...@@ -266,34 +122,25 @@ static int jumpshot_read_data(struct us_data *us, ...@@ -266,34 +122,25 @@ static int jumpshot_read_data(struct us_data *us,
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
unsigned char thistime; unsigned char thistime;
struct scatterlist *sg = NULL;
int totallen, len, result; int totallen, len, result;
int sg_idx = 0, current_sg_offset = 0; int sg_idx = 0, current_sg_offset = 0;
int transferred;
// 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
// supports beyond 24-bit addressing. It's kind of hard to test // supports beyond 24-bit addressing. It's kind of hard to test
// since it requires > 8GB CF card. // since it requires > 8GB CF card.
//
if (sector > 0x0FFFFFFF) if (sector > 0x0FFFFFFF)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
// If we're using scatter-gather, we have to create a new
// buffer to read all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
totallen = sectors * info->ssize; totallen = sectors * info->ssize;
do { do {
// loop, never allocate or transfer more than 64k at once (min(128k, 255*info->ssize) is the real limit) // 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); len = min_t(int, totallen, 65536);
if (use_sg) { if (use_sg) {
sg = (struct scatterlist *) dest;
buffer = kmalloc(len, GFP_NOIO); buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
...@@ -313,51 +160,25 @@ static int jumpshot_read_data(struct us_data *us, ...@@ -313,51 +160,25 @@ static int jumpshot_read_data(struct us_data *us,
command[5] |= (sector >> 24) & 0x0F; command[5] |= (sector >> 24) & 0x0F;
// send the setup + command // send the setup + command
result = jumpshot_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev, 0), usb_sndctrlpipe(us->pusb_dev, 0),
0, 0x20, 0, 1, command, 7); 0, 0x20, 0, 1, command, 7);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
// read the result // read the result
result = jumpshot_bulk_read(us, ptr, len); result = jumpshot_bulk_read(us, ptr, len);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
US_DEBUGP("jumpshot_read_data: %d bytes\n", len); US_DEBUGP("jumpshot_read_data: %d bytes\n", len);
//jumpshot_dump_data(ptr, len);
sectors -= thistime; sectors -= thistime;
sector += thistime; sector += thistime;
if (use_sg) { if (use_sg) {
transferred = 0; us_copy_to_sgbuf(buffer, len, dest,
while (sg_idx < use_sg && transferred < len) { &sg_idx, &current_sg_offset, use_sg);
if (len - transferred >= sg[sg_idx].length - current_sg_offset) {
US_DEBUGP("jumpshot_read_data: adding %d bytes to %d byte sg buffer\n", sg[sg_idx].length - current_sg_offset, sg[sg_idx].length);
memcpy(page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
buffer + transferred,
sg[sg_idx].length - current_sg_offset);
transferred += sg[sg_idx].length - current_sg_offset;
current_sg_offset = 0;
// on to the next sg buffer
++sg_idx;
} else {
US_DEBUGP("jumpshot_read_data: adding %d bytes to %d byte sg buffer\n", len - transferred, sg[sg_idx].length);
memcpy(page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
buffer + transferred,
len - transferred);
current_sg_offset += len - transferred;
// this sg buffer is only partially full and we're out of data to copy in
break;
}
}
kfree(buffer); kfree(buffer);
} else { } else {
dest += len; dest += len;
...@@ -367,6 +188,11 @@ static int jumpshot_read_data(struct us_data *us, ...@@ -367,6 +188,11 @@ static int jumpshot_read_data(struct us_data *us,
} while (totallen > 0); } while (totallen > 0);
return USB_STOR_TRANSPORT_GOOD; return USB_STOR_TRANSPORT_GOOD;
leave:
if (use_sg)
kfree(buffer);
return result;
} }
...@@ -381,10 +207,8 @@ static int jumpshot_write_data(struct us_data *us, ...@@ -381,10 +207,8 @@ static int jumpshot_write_data(struct us_data *us,
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
unsigned char thistime; unsigned char thistime;
struct scatterlist *sg = NULL;
int totallen, len, result, waitcount; int totallen, len, result, waitcount;
int sg_idx = 0, current_sg_offset = 0; int sg_idx = 0, sg_offset = 0;
int transferred;
// 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
...@@ -394,54 +218,23 @@ static int jumpshot_write_data(struct us_data *us, ...@@ -394,54 +218,23 @@ static int jumpshot_write_data(struct us_data *us,
if (sector > 0x0FFFFFFF) if (sector > 0x0FFFFFFF)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
// If we're using scatter-gather, we have to create a new
// buffer to read all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
totallen = sectors * info->ssize; totallen = sectors * info->ssize;
do { do {
// loop, never allocate or transfer more than 64k at once (min(128k, 255*info->ssize) is the real limit) // 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); len = min_t(int, totallen, 65536);
if (use_sg) { // if we are using scatter-gather,
sg = (struct scatterlist *) src; // first copy all to one big buffer
buffer = kmalloc(len, 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;
memset(buffer, 0, len);
// copy the data from the sg bufs into the big contiguous buf ptr = buffer;
//
transferred = 0;
while (transferred < len) {
if (len - transferred >= sg[sg_idx].length - current_sg_offset) {
US_DEBUGP("jumpshot_write_data: getting %d bytes from %d byte sg buffer\n", sg[sg_idx].length - current_sg_offset, sg[sg_idx].length);
memcpy(ptr + transferred,
page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
sg[sg_idx].length - current_sg_offset);
transferred += sg[sg_idx].length - current_sg_offset;
current_sg_offset = 0;
// on to the next sg buffer
++sg_idx;
} else {
US_DEBUGP("jumpshot_write_data: getting %d bytes from %d byte sg buffer\n", len - transferred, sg[sg_idx].length);
memcpy(ptr + transferred,
page_address(sg[sg_idx].page) + sg[sg_idx].offset + current_sg_offset,
len - transferred);
current_sg_offset += len - transferred;
// we only copied part of this sg buffer
break;
}
}
} else {
ptr = src;
}
thistime = (len / info->ssize) & 0xff; thistime = (len / info->ssize) & 0xff;
...@@ -454,21 +247,18 @@ static int jumpshot_write_data(struct us_data *us, ...@@ -454,21 +247,18 @@ static int jumpshot_write_data(struct us_data *us,
command[5] |= (sector >> 24) & 0x0F; command[5] |= (sector >> 24) & 0x0F;
// send the setup + command // send the setup + command
result = jumpshot_send_control(us, result = usb_storage_send_control(
usb_sndctrlpipe(us->pusb_dev, 0), us, usb_sndctrlpipe(us->pusb_dev, 0),
0, 0x20, 0, 1, command, 7); 0, 0x20, 0, 1, command, 7);
// send the data // send the data
result = jumpshot_bulk_write(us, ptr, len); result = jumpshot_bulk_write(us, ptr, len);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
// read the result. apparently the bulk write can complete before the // read the result. apparently the bulk write can complete
// jumpshot drive is finished writing. so we loop here until we // before the jumpshot drive is finished writing. so we loop
// get a good return code // here until we get a good return code
waitcount = 0; waitcount = 0;
do { do {
result = jumpshot_get_status(us); result = jumpshot_get_status(us);
...@@ -485,16 +275,20 @@ static int jumpshot_write_data(struct us_data *us, ...@@ -485,16 +275,20 @@ static int jumpshot_write_data(struct us_data *us,
sectors -= thistime; sectors -= thistime;
sector += thistime; sector += thistime;
if (use_sg) { if (use_sg)
kfree(buffer); kfree(buffer);
} else { else
src += len; src += len;
}
totallen -= len; totallen -= len;
} while (totallen > 0); } while (totallen > 0);
return result; return result;
leave:
if (use_sg)
kfree(buffer);
return result;
} }
static int jumpshot_id_device(struct us_data *us, static int jumpshot_id_device(struct us_data *us,
...@@ -508,12 +302,13 @@ static int jumpshot_id_device(struct us_data *us, ...@@ -508,12 +302,13 @@ static int jumpshot_id_device(struct us_data *us,
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
// send the setup // send the setup
rc = jumpshot_send_control(us, rc = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev, 0), usb_sndctrlpipe(us->pusb_dev, 0),
0, 0x20, 0, 6, command, 2); 0, 0x20, 0, 6, command, 2);
if (rc != USB_STOR_TRANSPORT_GOOD) { if (rc != USB_STOR_TRANSPORT_GOOD) {
US_DEBUGP("jumpshot_id_device: Gah! send_control for read_capacity failed\n"); US_DEBUGP("jumpshot_id_device: Gah! "
"send_control for read_capacity failed\n");
return rc; return rc;
} }
...@@ -826,6 +621,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, struct us_data *us) ...@@ -826,6 +621,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, struct us_data *us)
return rc; return rc;
} }
US_DEBUGP("jumpshot_transport: Gah! Unknown command: %d (0x%x)\n", srb->cmnd[0], srb->cmnd[0]); US_DEBUGP("jumpshot_transport: Gah! Unknown command: %d (0x%x)\n",
srb->cmnd[0], srb->cmnd[0]);
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
} }
/*
* Common routines for a handful of drivers.
* Unrelated to CF/SM - just USB stuff.
*
* This is mostly a thin layer on top of transport.c.
* It converts routines that return values like -ENOENT and -EPIPE
* into routines that return USB_STOR_TRANSPORT_ABORTED etc.
*
* There is also some debug printing here.
*/
#include "debug.h"
#include "transport.h"
#include "raw_bulk.h"
#ifdef CONFIG_USB_STORAGE_DEBUG
#define DEBUG_PRCT 12
#else
#define DEBUG_PRCT 0
#endif
/*
* Send a control message and wait for the response.
*
* us - the pointer to the us_data structure for the device to use
*
* request - the URB Setup Packet's first 6 bytes. The first byte always
* corresponds to the request type, and the second byte always corresponds
* to the request. The other 4 bytes do not correspond to value and index,
* since they are used in a custom way by the SCM protocol.
*
* xfer_data - a buffer from which to get, or to which to store, any data
* that gets send or received, respectively, with the URB. Even though
* it looks like we allocate a buffer in this code for the data, xfer_data
* must contain enough allocated space.
*
* xfer_len - the number of bytes to send or receive with the URB.
*
*/
int
usb_storage_send_control(struct us_data *us,
int pipe,
unsigned char request,
unsigned char requesttype,
unsigned int value,
unsigned int index,
unsigned char *xfer_data,
unsigned int xfer_len) {
int result;
// Send the URB to the device and wait for a response.
/* Why are request and request type reversed in this call? */
result = usb_stor_control_msg(us, pipe,
request, requesttype, value, index,
xfer_data, xfer_len);
// Check the return code for the command.
if (result < 0) {
/* if the command was aborted, indicate that */
if (result == -ENOENT)
return USB_STOR_TRANSPORT_ABORTED;
/* a stall is a fatal condition from the device */
if (result == -EPIPE) {
US_DEBUGP("-- Stall on control pipe. Clearing\n");
result = usb_stor_clear_halt(us, pipe);
US_DEBUGP("-- usb_stor_clear_halt() returns %d\n",
result);
return USB_STOR_TRANSPORT_FAILED;
}
/* Uh oh... serious problem here */
return USB_STOR_TRANSPORT_ERROR;
}
return USB_STOR_TRANSPORT_GOOD;
}
int
usb_storage_raw_bulk(struct us_data *us, int direction, unsigned char *data,
unsigned int len, unsigned int *act_len) {
int result;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, act_len);
/* if we stall, we need to clear it before we go on */
if (result == -EPIPE) {
US_DEBUGP("EPIPE: clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n",
pipe, *act_len);
usb_stor_clear_halt(us, pipe);
/* return US_BULK_TRANSFER_SHORT; */
}
if (result) {
/* -ENOENT -- we canceled this transfer */
if (result == -ENOENT) {
US_DEBUGP("raw_bulk(): transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
/* NAK - that means we've retried a few times already */
if (result == -ETIMEDOUT)
US_DEBUGP("raw_bulk(): device NAKed\n");
else if (result == -EOVERFLOW)
US_DEBUGP("raw_bulk(): babble/overflow\n");
else if (result == -ECONNRESET)
US_DEBUGP("raw_bulk(): asynchronous reset\n");
else if (result != -EPIPE)
US_DEBUGP("raw_bulk(): unknown error %d\n",
result);
return US_BULK_TRANSFER_FAILED;
}
if (*act_len != len) {
US_DEBUGP("Warning: Transferred only %d of %d bytes\n",
*act_len, len);
return US_BULK_TRANSFER_SHORT;
}
#if 0
US_DEBUGP("raw_bulk(): Transferred %s %d of %d bytes\n",
(direction == SCSI_DATA_READ) ? "in" : "out",
*act_len, len);
#endif
return US_BULK_TRANSFER_GOOD;
}
int
usb_storage_bulk_transport(struct us_data *us, int direction,
unsigned char *data, unsigned int len,
int use_sg) {
int result = USB_STOR_TRANSPORT_GOOD;
int transferred = 0;
int i;
struct scatterlist *sg;
unsigned int act_len;
if (len == 0)
return USB_STOR_TRANSPORT_GOOD;
#if DEBUG_PRCT
if (direction == SCSI_DATA_WRITE && !use_sg) {
char string[64];
/* Debug-print the first N bytes of the write transfer */
strcpy(string, "wr: ");
for (i=0; i<len && i<DEBUG_PRCT; i++) {
sprintf(string+strlen(string), "%02X ", data[i]);
if ((i%16) == 15) {
US_DEBUGP("%s\n", string);
strcpy(string, "wr: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
US_DEBUGP("SCM data %s transfer %d sg buffers %d\n",
(direction == SCSI_DATA_READ) ? "in" : "out",
len, use_sg);
#endif /* DEBUG_PRCT */
if (!use_sg)
result = usb_storage_raw_bulk(us, direction,
data, len, &act_len);
else {
sg = (struct scatterlist *)data;
for (i=0; i<use_sg && transferred<len; i++) {
unsigned char *buf;
unsigned int length;
buf = page_address(sg[i].page) + sg[i].offset;
length = len-transferred;
if (length > sg[i].length)
length = sg[i].length;
result = usb_storage_raw_bulk(us, direction,
buf, length, &act_len);
if (result != US_BULK_TRANSFER_GOOD)
break;
transferred += length;
}
}
#if DEBUG_PRCT
if (direction == SCSI_DATA_READ && !use_sg) {
char string[64];
/* Debug-print the first N bytes of the read transfer */
strcpy(string, "rd: ");
for (i=0; i<len && i<act_len && i<DEBUG_PRCT; i++) {
sprintf(string+strlen(string), "%02X ", data[i]);
if ((i%16) == 15) {
US_DEBUGP("%s\n", string);
strcpy(string, "rd: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
#endif /* DEBUG_PRCT */
return result;
}
/*
* The routines below convert scatter-gather to single buffer.
* Some drivers claim this is necessary.
* Nothing is done when use_sg is zero.
*/
/*
* Copy from scatter-gather buffer into a newly allocated single buffer,
* starting at a given index and offset.
* When done, update index and offset.
* Return a pointer to the single buffer.
*/
unsigned char *
us_copy_from_sgbuf(unsigned char *content, int len,
int *index, int *offset, int use_sg) {
struct scatterlist *sg;
unsigned char *buffer;
int transferred, i;
if (!use_sg)
return content;
sg = (struct scatterlist *)content;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL)
return NULL;
transferred = 0;
i = *index;
while (i < use_sg && transferred < len) {
unsigned char *ptr;
unsigned int length, room;
ptr = page_address(sg[i].page) + sg[i].offset + *offset;
room = sg[i].length - *offset;
length = len - transferred;
if (length > room)
length = room;
memcpy(buffer+transferred, ptr, length);
transferred += length;
*offset += length;
if (length == room) {
i++;
*offset = 0;
}
}
*index = i;
return buffer;
}
unsigned char *
us_copy_from_sgbuf_all(unsigned char *content, int len, int use_sg) {
int index, offset;
index = offset = 0;
return us_copy_from_sgbuf(content, len, &index, &offset, use_sg);
}
/*
* Copy from a single buffer into a scatter-gather buffer,
* starting at a given index and offset.
* When done, update index and offset.
*/
void
us_copy_to_sgbuf(unsigned char *buffer, int buflen,
void *content, int *index, int *offset, int use_sg) {
struct scatterlist *sg;
int i, transferred;
if (!use_sg)
return;
transferred = 0;
sg = content;
i = *index;
while (i < use_sg && transferred < buflen) {
unsigned char *ptr;
unsigned int length, room;
ptr = page_address(sg[i].page) + sg[i].offset + *offset;
room = sg[i].length - *offset;
length = buflen - transferred;
if (length > room)
length = room;
memcpy(ptr, buffer+transferred, length);
transferred += sg[i].length;
*offset += length;
if (length == room) {
i++;
*offset = 0;
}
}
*index = i;
}
void
us_copy_to_sgbuf_all(unsigned char *buffer, int buflen,
void *content, int use_sg) {
int index, offset;
index = offset = 0;
us_copy_to_sgbuf(buffer, buflen, content, &index, &offset, use_sg);
}
#ifndef _USB_STORAGE_RAW_BULK_H_
#define _USB_STORAGE_RAW_BULK_H_
/* usb bulk */
extern int usb_storage_send_control(
struct us_data *us, int pipe,
unsigned char request, unsigned char requesttype,
unsigned int value, unsigned int index,
unsigned char *xfer_data, unsigned int xfer_len);
extern int usb_storage_raw_bulk(
struct us_data *us, int direction,
unsigned char *data, unsigned int len, unsigned int *act_len);
extern int usb_storage_bulk_transport(
struct us_data *us, int direction,
unsigned char *data, unsigned int len, int use_sg);
/* scatter-gather */
extern unsigned char *us_copy_from_sgbuf(
unsigned char *content, int buflen,
int *index, int *offset, int use_sg);
extern unsigned char *us_copy_from_sgbuf_all(
unsigned char *content, int len, int use_sg);
extern void us_copy_to_sgbuf(
unsigned char *buffer, int buflen,
void *content, int *index, int *offset, int use_sg);
extern void us_copy_to_sgbuf_all(
unsigned char *buffer, int buflen,
void *content, int use_sg);
#endif
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
*/ */
#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"
...@@ -215,67 +216,6 @@ static void nand_store_ecc(unsigned char *data, unsigned char *ecc) { ...@@ -215,67 +216,6 @@ static void nand_store_ecc(unsigned char *data, unsigned char *ecc) {
static int erase_bad_lba_entries = 0; static int erase_bad_lba_entries = 0;
/*
* Send a control message and wait for the response.
*
* us - the pointer to the us_data structure for the device to use
*
* request - the URB Setup Packet's first 6 bytes. The first byte always
* corresponds to the request type, and the second byte always corresponds
* to the request. The other 4 bytes do not correspond to value and index,
* since they are used in a custom way by the SCM protocol.
*
* xfer_data - a buffer from which to get, or to which to store, any data
* that gets send or received, respectively, with the URB. Even though
* it looks like we allocate a buffer in this code for the data, xfer_data
* must contain enough allocated space.
*
* xfer_len - the number of bytes to send or receive with the URB.
*
*/
static int
sddr09_send_control(struct us_data *us,
int pipe,
unsigned char request,
unsigned char requesttype,
unsigned int value,
unsigned int index,
unsigned char *xfer_data,
unsigned int xfer_len) {
int result;
// Send the URB to the device and wait for a response.
/* Why are request and request type reversed in this call? */
result = usb_stor_control_msg(us, pipe,
request, requesttype, value, index,
xfer_data, xfer_len);
// Check the return code for the command.
if (result < 0) {
/* if the command was aborted, indicate that */
if (result == -ENOENT)
return USB_STOR_TRANSPORT_ABORTED;
/* a stall is a fatal condition from the device */
if (result == -EPIPE) {
US_DEBUGP("-- Stall on control pipe. Clearing\n");
result = usb_stor_clear_halt(us, pipe);
US_DEBUGP("-- usb_stor_clear_halt() returns %d\n", result);
return USB_STOR_TRANSPORT_FAILED;
}
return USB_STOR_TRANSPORT_ERROR;
}
return USB_STOR_TRANSPORT_GOOD;
}
/* send vendor interface command (0x41) */ /* send vendor interface command (0x41) */
/* called for requests 0, 1, 8 */ /* called for requests 0, 1, 8 */
static int static int
...@@ -294,7 +234,7 @@ sddr09_send_command(struct us_data *us, ...@@ -294,7 +234,7 @@ sddr09_send_command(struct us_data *us,
else else
pipe = usb_sndctrlpipe(us->pusb_dev,0); pipe = usb_sndctrlpipe(us->pusb_dev,0);
return sddr09_send_control(us, pipe, request, requesttype, return usb_storage_send_control(us, pipe, request, requesttype,
0, 0, xfer_data, xfer_len); 0, 0, xfer_data, xfer_len);
} }
...@@ -305,135 +245,6 @@ sddr09_send_scsi_command(struct us_data *us, ...@@ -305,135 +245,6 @@ sddr09_send_scsi_command(struct us_data *us,
return sddr09_send_command(us, 0, USB_DIR_OUT, command, command_len); return sddr09_send_command(us, 0, USB_DIR_OUT, command, command_len);
} }
static int
sddr09_raw_bulk(struct us_data *us, int direction,
unsigned char *data, unsigned int len) {
int result;
int act_len;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, &act_len);
/* if we stall, we need to clear it before we go on */
if (result == -EPIPE) {
US_DEBUGP("EPIPE: clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n",
pipe, act_len);
usb_stor_clear_halt(us, pipe);
}
if (result) {
/* -ENOENT -- we canceled this transfer */
if (result == -ENOENT) {
US_DEBUGP("usbat_raw_bulk(): transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
/* NAK - that means we've retried a few times already */
if (result == -ETIMEDOUT)
US_DEBUGP("usbat_raw_bulk(): device NAKed\n");
else if (result == -EOVERFLOW)
US_DEBUGP("us_transfer_partial(): babble/overflow\n");
else if (result != -EPIPE)
US_DEBUGP("us_transfer_partial(): unknown error %d\n",
result);
return US_BULK_TRANSFER_FAILED;
}
if (act_len != len) {
US_DEBUGP("Warning: Transferred only %d of %d bytes\n",
act_len, len);
return US_BULK_TRANSFER_SHORT;
}
return US_BULK_TRANSFER_GOOD;
}
static int
sddr09_bulk_transport(struct us_data *us, int direction,
unsigned char *data, unsigned int len,
int use_sg) {
int result = USB_STOR_TRANSPORT_GOOD;
int transferred = 0;
int i;
struct scatterlist *sg;
char string[64];
#define DEBUG_PRCT 12
if (len == 0)
return USB_STOR_TRANSPORT_GOOD;
if (direction == SCSI_DATA_WRITE && !use_sg) {
/* Debug-print the first N bytes of the write transfer */
strcpy(string, "wr: ");
for (i=0; i<len && i<DEBUG_PRCT; i++) {
sprintf(string+strlen(string), "%02X ",
data[i]);
if ((i%16) == 15) {
US_DEBUGP("%s\n", string);
strcpy(string, "wr: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
US_DEBUGP("SCM data %s transfer %d sg buffers %d\n",
(direction == SCSI_DATA_READ) ? "in" : "out",
len, use_sg);
if (!use_sg)
result = sddr09_raw_bulk(us, direction, data, len);
else {
sg = (struct scatterlist *)data;
for (i=0; i<use_sg && transferred<len; i++) {
unsigned char *buf;
unsigned int length;
buf = page_address(sg[i].page) + sg[i].offset;
length = len-transferred;
if (length > sg[i].length)
length = sg[i].length;
result = sddr09_raw_bulk(us, direction, buf, length);
if (result != US_BULK_TRANSFER_GOOD)
break;
transferred += sg[i].length;
}
}
if (direction == SCSI_DATA_READ && !use_sg) {
/* Debug-print the first N bytes of the read transfer */
strcpy(string, "rd: ");
for (i=0; i<len && i<DEBUG_PRCT; i++) {
sprintf(string+strlen(string), "%02X ",
data[i]);
if ((i%16) == 15) {
US_DEBUGP("%s\n", string);
strcpy(string, "rd: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
return result;
}
#if 0 #if 0
/* /*
* Test Unit Ready Command: 12 bytes. * Test Unit Ready Command: 12 bytes.
...@@ -465,6 +276,7 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) { ...@@ -465,6 +276,7 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) {
0x03, LUNBITS, 0, 0, buflen, 0, 0, 0, 0, 0, 0, 0 0x03, LUNBITS, 0, 0, buflen, 0, 0, 0, 0, 0, 0, 0
}; };
int result; int result;
unsigned int act_len;
result = sddr09_send_scsi_command(us, command, sizeof(command)); result = sddr09_send_scsi_command(us, command, sizeof(command));
if (result != USB_STOR_TRANSPORT_GOOD) { if (result != USB_STOR_TRANSPORT_GOOD) {
...@@ -472,7 +284,7 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) { ...@@ -472,7 +284,7 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) {
return result; return result;
} }
result = sddr09_raw_bulk(us, SCSI_DATA_READ, sensebuf, buflen); result = usb_storage_raw_bulk(us, SCSI_DATA_READ, sensebuf, buflen, &act_len);
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
US_DEBUGP("request sense bulk in failed\n"); US_DEBUGP("request sense bulk in failed\n");
else else
...@@ -529,7 +341,7 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress, ...@@ -529,7 +341,7 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
return result; return result;
} }
result = sddr09_bulk_transport(us, SCSI_DATA_READ, result = usb_storage_bulk_transport(us, SCSI_DATA_READ,
buf, bulklen, use_sg); buf, bulklen, use_sg);
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
...@@ -695,7 +507,7 @@ sddr09_writeX(struct us_data *us, ...@@ -695,7 +507,7 @@ sddr09_writeX(struct us_data *us,
return result; return result;
} }
result = sddr09_bulk_transport(us, SCSI_DATA_WRITE, result = usb_storage_bulk_transport(us, SCSI_DATA_WRITE,
buf, bulklen, use_sg); buf, bulklen, use_sg);
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
...@@ -776,7 +588,7 @@ sddr09_read_sg_test_only(struct us_data *us) { ...@@ -776,7 +588,7 @@ sddr09_read_sg_test_only(struct us_data *us) {
if (!buf) if (!buf)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
result = sddr09_bulk_transport(us, SCSI_DATA_READ, result = usb_storage_bulk_transport(us, SCSI_DATA_READ,
buf, bulklen, 0); buf, bulklen, 0);
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
US_DEBUGP("Result for bulk_transport in sddr09_read_sg %d\n", US_DEBUGP("Result for bulk_transport in sddr09_read_sg %d\n",
...@@ -814,7 +626,7 @@ sddr09_read_status(struct us_data *us, unsigned char *status) { ...@@ -814,7 +626,7 @@ sddr09_read_status(struct us_data *us, unsigned char *status) {
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
result = sddr09_bulk_transport(us, SCSI_DATA_READ, result = usb_storage_bulk_transport(us, SCSI_DATA_READ,
data, sizeof(data), 0); data, sizeof(data), 0);
*status = data[0]; *status = data[0];
return result; return result;
...@@ -832,8 +644,7 @@ sddr09_read_data(struct us_data *us, ...@@ -832,8 +644,7 @@ sddr09_read_data(struct us_data *us,
unsigned int page, pages; unsigned int page, pages;
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
struct scatterlist *sg = NULL; int result, len;
int result, i, len;
// If we're using scatter-gather, we have to create a new // If we're using scatter-gather, we have to create a new
// buffer to read all of the data in first, since a // buffer to read all of the data in first, since a
...@@ -844,14 +655,11 @@ sddr09_read_data(struct us_data *us, ...@@ -844,14 +655,11 @@ sddr09_read_data(struct us_data *us,
len = sectors*info->pagesize; len = sectors*info->pagesize;
if (use_sg) { buffer = (use_sg ? kmalloc(len, GFP_NOIO) : content);
sg = (struct scatterlist *)content;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
ptr = buffer; ptr = buffer;
} else
ptr = content;
// Figure out the initial LBA and page // Figure out the initial LBA and page
lba = address >> info->blockshift; lba = address >> info->blockshift;
...@@ -913,23 +721,8 @@ sddr09_read_data(struct us_data *us, ...@@ -913,23 +721,8 @@ sddr09_read_data(struct us_data *us,
ptr += (pages << info->pageshift); ptr += (pages << info->pageshift);
} }
if (use_sg && result == USB_STOR_TRANSPORT_GOOD) { if (use_sg && result == USB_STOR_TRANSPORT_GOOD)
int transferred = 0; us_copy_to_sgbuf_all(buffer, len, content, use_sg);
for (i=0; i<use_sg && transferred<len; i++) {
unsigned char *buf;
unsigned int length;
buf = page_address(sg[i].page) + sg[i].offset;
length = len-transferred;
if (length > sg[i].length)
length = sg[i].length;
memcpy(buf, buffer+transferred, length);
transferred += sg[i].length;
}
}
if (use_sg) if (use_sg)
kfree(buffer); kfree(buffer);
...@@ -1080,50 +873,20 @@ sddr09_write_data(struct us_data *us, ...@@ -1080,50 +873,20 @@ sddr09_write_data(struct us_data *us,
unsigned int lba, page, pages; unsigned int lba, page, pages;
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
struct scatterlist *sg = NULL; int result, len;
int result, i, len;
// If we're using scatter-gather, we have to create a new
// buffer to write all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
len = sectors*info->pagesize; len = sectors*info->pagesize;
if (use_sg) { buffer = us_copy_from_sgbuf_all(content, len, use_sg);
int transferred = 0;
sg = (struct scatterlist *)content;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
for (i=0; i<use_sg && transferred<len; i++) {
unsigned char *buf;
unsigned int length;
buf = page_address(sg[i].page) + sg[i].offset;
length = len-transferred;
if (length > sg[i].length)
length = sg[i].length;
memcpy(buffer+transferred, buf, length);
transferred += sg[i].length;
}
ptr = buffer; ptr = buffer;
} else
ptr = content;
// Figure out the initial LBA and page // Figure out the initial LBA and page
lba = address >> info->blockshift; lba = address >> info->blockshift;
page = (address & info->blockmask); page = (address & info->blockmask);
// This could be made much more efficient by checking for
// contiguous LBA's. Another exercise left to the student.
result = USB_STOR_TRANSPORT_GOOD; result = USB_STOR_TRANSPORT_GOOD;
while (sectors > 0) { while (sectors > 0) {
...@@ -1185,7 +948,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) { ...@@ -1185,7 +948,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
result = sddr09_bulk_transport(us, SCSI_DATA_READ, content, 64, 0); result = usb_storage_bulk_transport(us, SCSI_DATA_READ, content, 64, 0);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
deviceID[i] = content[i]; deviceID[i] = content[i];
...@@ -1792,7 +1555,7 @@ int sddr09_transport(Scsi_Cmnd *srb, struct us_data *us) ...@@ -1792,7 +1555,7 @@ int sddr09_transport(Scsi_Cmnd *srb, struct us_data *us)
"sending" : "receiving", "sending" : "receiving",
srb->request_bufflen); srb->request_bufflen);
result = sddr09_bulk_transport(us, result = usb_storage_bulk_transport(us,
srb->sc_data_direction, srb->sc_data_direction,
srb->request_buffer, srb->request_buffer,
srb->request_bufflen, srb->request_bufflen,
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
*/ */
#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"
...@@ -70,142 +71,16 @@ struct sddr55_card_info { ...@@ -70,142 +71,16 @@ struct sddr55_card_info {
#define CIS_BLOCK 0x400 #define CIS_BLOCK 0x400
#define UNUSED_BLOCK 0x3ff #define UNUSED_BLOCK 0x3ff
static int
sddr55_bulk_transport(struct us_data *us, int direction,
static int sddr55_raw_bulk(struct us_data *us, unsigned char *data, unsigned int len) {
int direction,
unsigned char *data,
unsigned int len) {
int result;
int act_len;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, &act_len);
/* if we stall, we need to clear it before we go on */
if (result == -EPIPE) {
US_DEBUGP("EPIPE: clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n",
pipe, act_len);
usb_clear_halt(us->pusb_dev, pipe);
}
if (result) {
/* NAK - that means we've retried a few times already */
if (result == -ETIMEDOUT) {
US_DEBUGP("usbat_raw_bulk():"
" device NAKed\n");
return US_BULK_TRANSFER_FAILED;
}
/* -ENOENT -- we canceled this transfer */
if (result == -ENOENT) {
US_DEBUGP("usbat_raw_bulk():"
" transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
if (result == -EPIPE) {
US_DEBUGP("usbat_raw_bulk():"
" output pipe stalled\n");
return US_BULK_TRANSFER_FAILED;
}
/* the catch-all case */
US_DEBUGP("us_transfer_partial(): unknown error\n");
return US_BULK_TRANSFER_FAILED;
}
if (act_len != len) {
US_DEBUGP("Warning: Transferred only %d bytes\n",
act_len);
return US_BULK_TRANSFER_SHORT;
}
US_DEBUGP("Transferred %d of %d bytes\n", act_len, len);
return US_BULK_TRANSFER_GOOD;
}
/*
* Note: direction must be set if command_len == 0.
*/
static int sddr55_bulk_transport(struct us_data *us,
int direction,
unsigned char *data,
unsigned int len) {
int result = USB_STOR_TRANSPORT_GOOD;
struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra; struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
if (len==0) if (len)
return USB_STOR_TRANSPORT_GOOD;
info->last_access = jiffies; info->last_access = jiffies;
return usb_storage_bulk_transport(us, direction, data, len, 0);
#ifdef CONFIG_USB_STORAGE_DEBUG
if (direction == SCSI_DATA_WRITE) {
int i;
char string[64];
/* Debug-print the first 48 bytes of the write transfer */
strcpy(string, "wr: ");
for (i=0; i<len && i<48; i++) {
sprintf(string+strlen(string), "%02X ",
data[i]);
if ((i%16)==15) {
US_DEBUGP("%s\n", string);
strcpy(string, "wr: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
#endif
/* transfer the data */
US_DEBUGP("SCM data %s transfer %d\n",
( direction==SCSI_DATA_READ ? "in" : "out"),
len);
result = sddr55_raw_bulk(us, direction, data, len);
#ifdef CONFIG_USB_STORAGE_DEBUG
if (direction == SCSI_DATA_READ) {
int i;
char string[64];
/* Debug-print the first 48 bytes of the read transfer */
strcpy(string, "rd: ");
for (i=0; i<len && i<48; i++) {
sprintf(string+strlen(string), "%02X ",
data[i]);
if ((i%16)==15) {
US_DEBUGP("%s\n", string);
strcpy(string, "rd: ");
}
}
if ((i%16)!=0)
US_DEBUGP("%s\n", string);
}
#endif
return result;
} }
/* check if card inserted, if there is, update read_only status /* check if card inserted, if there is, update read_only status
* return non zero if no card * return non zero if no card
*/ */
...@@ -278,7 +153,7 @@ static int sddr55_read_data(struct us_data *us, ...@@ -278,7 +153,7 @@ static int sddr55_read_data(struct us_data *us,
unsigned char *content, unsigned char *content,
int use_sg) { int use_sg) {
int result; int result = USB_STOR_TRANSPORT_GOOD;
unsigned char command[8] = { unsigned char command[8] = {
0, 0, 0, 0, 0, 0xb0, 0, 0x85 0, 0, 0, 0, 0, 0xb0, 0, 0x85
}; };
...@@ -291,31 +166,15 @@ static int sddr55_read_data(struct us_data *us, ...@@ -291,31 +166,15 @@ static int sddr55_read_data(struct us_data *us,
unsigned short pages; unsigned short pages;
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
struct scatterlist *sg = NULL;
int i;
int len; int len;
int transferred;
// If we're using scatter-gather, we have to create a new
// buffer to read all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
len = sectors * PAGESIZE; len = sectors * PAGESIZE;
if (use_sg) { buffer = (use_sg ? kmalloc(len, GFP_NOIO) : content);
sg = (struct scatterlist *)content;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR; /* out of memory */
ptr = buffer;
} else
ptr = content;
// This could be made much more efficient by checking for ptr = buffer;
// contiguous LBA's. Another exercise left to the student.
while (sectors>0) { while (sectors>0) {
...@@ -355,42 +214,30 @@ static int sddr55_read_data(struct us_data *us, ...@@ -355,42 +214,30 @@ static int sddr55_read_data(struct us_data *us,
US_DEBUGP("Result for send_command in read_data %d\n", US_DEBUGP("Result for send_command in read_data %d\n",
result); result);
if (result != US_BULK_TRANSFER_GOOD) { if (result != US_BULK_TRANSFER_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
/* read data */ /* read data */
result = sddr55_bulk_transport(us, result = sddr55_bulk_transport(us,
SCSI_DATA_READ, ptr, SCSI_DATA_READ, ptr,
pages<<info->pageshift); pages<<info->pageshift);
if (result != US_BULK_TRANSFER_GOOD) { if (result != US_BULK_TRANSFER_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
/* now read status */ /* now read status */
result = sddr55_bulk_transport(us, result = sddr55_bulk_transport(us,
SCSI_DATA_READ, status, 2); SCSI_DATA_READ, status, 2);
if (result != US_BULK_TRANSFER_GOOD) { if (result != US_BULK_TRANSFER_GOOD)
if (use_sg) goto leave;
kfree(buffer);
return result;
}
/* check status for error */ /* check status for error */
if (status[0] == 0xff && status[1] == 0x4) { if (status[0] == 0xff && status[1] == 0x4) {
set_sense_info (3, 0x11, 0); set_sense_info (3, 0x11, 0);
if (use_sg) result = USB_STOR_TRANSPORT_FAILED;
kfree(buffer); goto leave;
return USB_STOR_TRANSPORT_FAILED;
} }
} }
page = 0; page = 0;
...@@ -399,18 +246,13 @@ static int sddr55_read_data(struct us_data *us, ...@@ -399,18 +246,13 @@ static int sddr55_read_data(struct us_data *us,
ptr += (pages << info->pageshift); ptr += (pages << info->pageshift);
} }
if (use_sg) { us_copy_to_sgbuf_all(buffer, len, content, use_sg);
transferred = 0;
for (i=0; i<use_sg && transferred<len; i++) { leave:
memcpy(page_address(sg[i].page) + sg[i].offset, buffer+transferred, if (use_sg)
len-transferred > sg[i].length ?
sg[i].length : len-transferred);
transferred += sg[i].length;
}
kfree(buffer); kfree(buffer);
}
return USB_STOR_TRANSPORT_GOOD; return result;
} }
static int sddr55_write_data(struct us_data *us, static int sddr55_write_data(struct us_data *us,
...@@ -420,7 +262,7 @@ static int sddr55_write_data(struct us_data *us, ...@@ -420,7 +262,7 @@ static int sddr55_write_data(struct us_data *us,
unsigned char *content, unsigned char *content,
int use_sg) { int use_sg) {
int result; int result = USB_STOR_TRANSPORT_GOOD;
unsigned char command[8] = { unsigned char command[8] = {
0, 0, 0, 0, 0, 0xb0, 0, 0x86 0, 0, 0, 0, 0, 0xb0, 0, 0x86
}; };
...@@ -434,10 +276,7 @@ static int sddr55_write_data(struct us_data *us, ...@@ -434,10 +276,7 @@ static int sddr55_write_data(struct us_data *us,
unsigned short pages; unsigned short pages;
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
unsigned char *ptr; unsigned char *ptr;
struct scatterlist *sg = NULL; int i, len;
int i;
int len;
int transferred;
/* 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) {
...@@ -445,33 +284,13 @@ static int sddr55_write_data(struct us_data *us, ...@@ -445,33 +284,13 @@ static int sddr55_write_data(struct us_data *us,
return USB_STOR_TRANSPORT_FAILED; return USB_STOR_TRANSPORT_FAILED;
} }
// If we're using scatter-gather, we have to create a new
// buffer to write all of the data in first, since a
// scatter-gather buffer could in theory start in the middle
// of a page, which would be bad. A developer who wants a
// challenge might want to write a limited-buffer
// version of this code.
len = sectors * PAGESIZE; len = sectors * PAGESIZE;
if (use_sg) { buffer = us_copy_from_sgbuf_all(content, len, use_sg);
sg = (struct scatterlist *)content;
buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) if (buffer == NULL)
return USB_STOR_TRANSPORT_ERROR; return USB_STOR_TRANSPORT_ERROR;
transferred = 0;
for (i=0; i<use_sg && transferred<len; i++) {
memcpy(buffer+transferred,
page_address(sg[i].page) + sg[i].offset,
len-transferred > sg[i].length ?
sg[i].length : len-transferred);
transferred += sg[i].length;
}
ptr = buffer; ptr = buffer;
} else
ptr = content;
while (sectors > 0) { while (sectors > 0) {
...@@ -508,10 +327,12 @@ static int sddr55_write_data(struct us_data *us, ...@@ -508,10 +327,12 @@ static int sddr55_write_data(struct us_data *us,
if (max_pba > 1024) if (max_pba > 1024)
max_pba = 1024; max_pba = 1024;
/* scan through the map lookiong for an unused block /*
* leave 16 unused blocks at start (or as many as possible) * Scan through the map looking for an unused block
* since the sddr55 seems to reuse a used block when it shouldn't * leave 16 unused blocks at start (or as many as
* if we don't leave space */ * possible) since the sddr55 seems to reuse a used
* block when it shouldn't if we don't leave space.
*/
for (i = 0; i < max_pba; i++, pba++) { for (i = 0; i < max_pba; i++, pba++) {
if (info->pba_to_lba[pba] == UNUSED_BLOCK) { if (info->pba_to_lba[pba] == UNUSED_BLOCK) {
found_pba = pba; found_pba = pba;
...@@ -523,15 +344,12 @@ static int sddr55_write_data(struct us_data *us, ...@@ -523,15 +344,12 @@ static int sddr55_write_data(struct us_data *us,
pba = found_pba; pba = found_pba;
if (pba == -1) { if (pba == -1) {
/* oh dear, couldn't find an unallocated block */ /* oh dear */
US_DEBUGP("Couldn't find unallocated block\n"); US_DEBUGP("Couldn't find unallocated block\n");
set_sense_info (3, 0x31, 0); /* medium error */ set_sense_info (3, 0x31, 0); /* medium error */
result = USB_STOR_TRANSPORT_FAILED;
if (use_sg) goto leave;
kfree(buffer);
return USB_STOR_TRANSPORT_FAILED;
} }
US_DEBUGP("Allocating PBA %04X for LBA %04X\n", pba, lba); US_DEBUGP("Allocating PBA %04X for LBA %04X\n", pba, lba);
...@@ -560,11 +378,9 @@ static int sddr55_write_data(struct us_data *us, ...@@ -560,11 +378,9 @@ static int sddr55_write_data(struct us_data *us,
US_DEBUGP("Result for send_command in write_data %d\n", US_DEBUGP("Result for send_command in write_data %d\n",
result); result);
set_sense_info (3, 0x3, 0); /* peripheral write error */ /* set_sense_info is superfluous here? */
set_sense_info (3, 0x3, 0);/* peripheral write error */
if (use_sg) goto leave;
kfree(buffer);
return result;
} }
/* send the data */ /* send the data */
...@@ -576,39 +392,33 @@ static int sddr55_write_data(struct us_data *us, ...@@ -576,39 +392,33 @@ static int sddr55_write_data(struct us_data *us,
US_DEBUGP("Result for send_data in write_data %d\n", US_DEBUGP("Result for send_data in write_data %d\n",
result); result);
set_sense_info (3, 0x3, 0); /* peripheral write error */ /* set_sense_info is superfluous here? */
set_sense_info (3, 0x3, 0);/* peripheral write error */
if (use_sg) goto leave;
kfree(buffer);
return result;
} }
/* now read status */ /* now read status */
result = sddr55_bulk_transport(us, result = sddr55_bulk_transport(us, SCSI_DATA_READ, status, 6);
SCSI_DATA_READ, status, 6);
if (result != US_BULK_TRANSFER_GOOD) { if (result != US_BULK_TRANSFER_GOOD) {
US_DEBUGP("Result for get_status in write_data %d\n", US_DEBUGP("Result for get_status in write_data %d\n",
result); result);
set_sense_info (3, 0x3, 0); /* peripheral write error */ /* set_sense_info is superfluous here? */
set_sense_info (3, 0x3, 0);/* peripheral write error */
if (use_sg) goto leave;
kfree(buffer);
return result;
} }
new_pba = (status[3] + (status[4] << 8) + (status[5] << 16)) >> info->blockshift; new_pba = (status[3] + (status[4] << 8) + (status[5] << 16))
>> info->blockshift;
/* check status for error */ /* check status for error */
if (status[0] == 0xff && status[1] == 0x4) { if (status[0] == 0xff && status[1] == 0x4) {
set_sense_info (3, 0x0c, 0);
if (use_sg)
kfree(buffer);
info->pba_to_lba[new_pba] = BAD_BLOCK; info->pba_to_lba[new_pba] = BAD_BLOCK;
return USB_STOR_TRANSPORT_FAILED; set_sense_info (3, 0x0c, 0);
result = USB_STOR_TRANSPORT_FAILED;
goto leave;
} }
US_DEBUGP("Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n", US_DEBUGP("Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n",
...@@ -624,10 +434,8 @@ static int sddr55_write_data(struct us_data *us, ...@@ -624,10 +434,8 @@ static int sddr55_write_data(struct us_data *us,
new_pba, info->pba_to_lba[new_pba]); new_pba, info->pba_to_lba[new_pba]);
info->fatal_error = 1; info->fatal_error = 1;
set_sense_info (3, 0x31, 0); set_sense_info (3, 0x31, 0);
if (use_sg) result = USB_STOR_TRANSPORT_FAILED;
kfree(buffer); goto leave;
return USB_STOR_TRANSPORT_FAILED;
} }
/* update the pba<->lba maps for new_pba */ /* update the pba<->lba maps for new_pba */
...@@ -639,11 +447,10 @@ static int sddr55_write_data(struct us_data *us, ...@@ -639,11 +447,10 @@ static int sddr55_write_data(struct us_data *us,
ptr += (pages << info->pageshift); ptr += (pages << info->pageshift);
} }
if (use_sg) { leave:
if (use_sg)
kfree(buffer); kfree(buffer);
} return result;
return USB_STOR_TRANSPORT_GOOD;
} }
static int sddr55_read_deviceID(struct us_data *us, static int sddr55_read_deviceID(struct us_data *us,
...@@ -982,7 +789,8 @@ int sddr55_transport(Scsi_Cmnd *srb, struct us_data *us) ...@@ -982,7 +789,8 @@ int sddr55_transport(Scsi_Cmnd *srb, struct us_data *us)
} }
} }
/* if we detected a problem with the map when writing, don't allow any more access */ /* if we detected a problem with the map when writing,
don't allow any more access */
if (info->fatal_error) { if (info->fatal_error) {
set_sense_info (3, 0x31, 0); set_sense_info (3, 0x31, 0);
...@@ -1000,8 +808,8 @@ int sddr55_transport(Scsi_Cmnd *srb, struct us_data *us) ...@@ -1000,8 +808,8 @@ int sddr55_transport(Scsi_Cmnd *srb, struct us_data *us)
info->capacity = capacity; info->capacity = capacity;
/* figure out the maximum logical block number, allowing for the fact /* figure out the maximum logical block number, allowing for
* that only 250 out of every 256 are used */ * the fact that only 250 out of every 256 are used */
info->max_log_blks = ((info->capacity >> (info->pageshift + info->blockshift)) / 256) * 250; info->max_log_blks = ((info->capacity >> (info->pageshift + info->blockshift)) / 256) * 250;
/* Last page in the card, adjust as we only use 250 out of every 256 pages */ /* Last page in the card, adjust as we only use 250 out of every 256 pages */
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
*/ */
#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"
...@@ -61,174 +62,6 @@ extern int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe, ...@@ -61,174 +62,6 @@ extern int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe,
int transferred = 0; int transferred = 0;
/*
* Send a control message and wait for the response.
*
* us - the pointer to the us_data structure for the device to use
*
* request - the URB Setup Packet's first 6 bytes. The first byte always
* corresponds to the request type, and the second byte always corresponds
* to the request. The other 4 bytes do not correspond to value and index,
* since they are used in a custom way by the SCM protocol.
*
* xfer_data - a buffer from which to get, or to which to store, any data
* that gets send or received, respectively, with the URB. Even though
* it looks like we allocate a buffer in this code for the data, xfer_data
* must contain enough allocated space.
*
* xfer_len - the number of bytes to send or receive with the URB.
*
*/
static int usbat_send_control(struct us_data *us,
int pipe,
unsigned char request,
unsigned char requesttype,
unsigned short value,
unsigned short index,
unsigned char *xfer_data,
unsigned int xfer_len) {
int result;
// Send the URB to the device and wait for a response.
/* Why are request and request type reversed in this call? */
result = usb_stor_control_msg(us, pipe,
request, requesttype, value, index,
xfer_data, xfer_len);
// Check the return code for the command.
if (result < 0) {
/* if the command was aborted, indicate that */
if (result == -ENOENT)
return USB_STOR_TRANSPORT_ABORTED;
/* a stall is a fatal condition from the device */
if (result == -EPIPE) {
US_DEBUGP("-- Stall on control pipe. Clearing\n");
result = usb_stor_clear_halt(us, pipe);
US_DEBUGP("-- usb_stor_clear_halt() returns %d\n", result);
return USB_STOR_TRANSPORT_FAILED;
}
/* Uh oh... serious problem here */
return USB_STOR_TRANSPORT_ERROR;
}
return USB_STOR_TRANSPORT_GOOD;
}
static int usbat_raw_bulk(struct us_data *us,
int direction,
unsigned char *data,
unsigned short len) {
int result;
int act_len;
int pipe;
if (direction == SCSI_DATA_READ)
pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
result = usb_stor_bulk_msg(us, data, pipe, len, &act_len);
/* if we stall, we need to clear it before we go on */
if (result == -EPIPE) {
US_DEBUGP("EPIPE: clearing endpoint halt for"
" pipe 0x%x, stalled at %d bytes\n",
pipe, act_len);
usb_stor_clear_halt(us, pipe);
}
if (result) {
/* NAK - that means we've retried a few times already */
if (result == -ETIMEDOUT) {
US_DEBUGP("usbat_raw_bulk():"
" device NAKed\n");
return US_BULK_TRANSFER_FAILED;
}
/* -ENOENT -- we canceled this transfer */
if (result == -ENOENT) {
US_DEBUGP("usbat_raw_bulk():"
" transfer aborted\n");
return US_BULK_TRANSFER_ABORTED;
}
if (result == -EPIPE) {
US_DEBUGP("usbat_raw_bulk():"
" output pipe stalled\n");
return US_BULK_TRANSFER_SHORT;
}
/* the catch-all case */
US_DEBUGP("us_transfer_partial(): unknown error\n");
return US_BULK_TRANSFER_FAILED;
}
if (act_len != len) {
US_DEBUGP("Warning: Transferred only %d bytes\n",
act_len);
return US_BULK_TRANSFER_SHORT;
}
US_DEBUGP("Transferred %s %d of %d bytes\n",
direction==SCSI_DATA_READ ? "in" : "out", act_len, len);
return US_BULK_TRANSFER_GOOD;
}
/*
* Note: direction must be set if command_len == 0.
*/
static int usbat_bulk_transport(struct us_data *us,
unsigned char *command,
unsigned short command_len,
int direction,
unsigned char *data,
unsigned short len,
int use_sg) {
int result = USB_STOR_TRANSPORT_GOOD;
int transferred = 0;
int i;
struct scatterlist *sg;
if (len==0)
return USB_STOR_TRANSPORT_GOOD;
/* transfer the data payload for the command, if there is any */
if (command_len != 0)
direction = (command[0]&0x80) ? SCSI_DATA_READ :
SCSI_DATA_WRITE;
if (!use_sg)
result = usbat_raw_bulk(us, direction, data, len);
else {
sg = (struct scatterlist *)data;
for (i=0; i<use_sg && transferred<len; i++) {
result = usbat_raw_bulk(us, direction,
page_address(sg[i].page) + sg[i].offset,
len-transferred > sg[i].length ?
sg[i].length : len-transferred);
if (result!=US_BULK_TRANSFER_GOOD)
break;
transferred += sg[i].length;
}
}
return result;
}
int usbat_read(struct us_data *us, int usbat_read(struct us_data *us,
unsigned char access, unsigned char access,
unsigned char reg, unsigned char reg,
...@@ -236,7 +69,7 @@ int usbat_read(struct us_data *us, ...@@ -236,7 +69,7 @@ int usbat_read(struct us_data *us,
int result; int result;
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_rcvctrlpipe(us->pusb_dev,0), usb_rcvctrlpipe(us->pusb_dev,0),
access, access,
0xC0, 0xC0,
...@@ -255,7 +88,7 @@ int usbat_write(struct us_data *us, ...@@ -255,7 +88,7 @@ int usbat_write(struct us_data *us,
int result; int result;
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
access|0x01, access|0x01,
0x40, 0x40,
...@@ -281,7 +114,7 @@ int usbat_set_shuttle_features(struct us_data *us, ...@@ -281,7 +114,7 @@ int usbat_set_shuttle_features(struct us_data *us,
test_pattern, mask_byte, subcountL, subcountH test_pattern, mask_byte, subcountL, subcountH
}; };
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x80, 0x80,
0x40, 0x40,
...@@ -306,7 +139,7 @@ int usbat_read_block(struct us_data *us, ...@@ -306,7 +139,7 @@ int usbat_read_block(struct us_data *us,
LSB_of(len), MSB_of(len) LSB_of(len), MSB_of(len)
}; };
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x80, 0x80,
0x40, 0x40,
...@@ -318,8 +151,7 @@ int usbat_read_block(struct us_data *us, ...@@ -318,8 +151,7 @@ int usbat_read_block(struct us_data *us,
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
result = usbat_bulk_transport(us, result = usb_storage_bulk_transport(us, SCSI_DATA_READ, content, len, use_sg);
NULL, 0, SCSI_DATA_READ, content, len, use_sg);
return result; return result;
} }
...@@ -388,7 +220,7 @@ int usbat_write_block(struct us_data *us, ...@@ -388,7 +220,7 @@ int usbat_write_block(struct us_data *us,
LSB_of(len), MSB_of(len) LSB_of(len), MSB_of(len)
}; };
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x80, 0x80,
0x40, 0x40,
...@@ -400,8 +232,7 @@ int usbat_write_block(struct us_data *us, ...@@ -400,8 +232,7 @@ int usbat_write_block(struct us_data *us,
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
result = usbat_bulk_transport(us, result = usb_storage_bulk_transport(us, SCSI_DATA_WRITE, content, len, use_sg);
NULL, 0, SCSI_DATA_WRITE, content, len, use_sg);
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
...@@ -460,7 +291,7 @@ int usbat_rw_block_test(struct us_data *us, ...@@ -460,7 +291,7 @@ int usbat_rw_block_test(struct us_data *us,
* that, we just return a failure. * that, we just return a failure.
*/ */
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x80, 0x80,
0x40, 0x40,
...@@ -474,8 +305,8 @@ int usbat_rw_block_test(struct us_data *us, ...@@ -474,8 +305,8 @@ int usbat_rw_block_test(struct us_data *us,
if (i==0) { if (i==0) {
result = usbat_bulk_transport(us, result = usb_storage_bulk_transport(us,
NULL, 0, SCSI_DATA_WRITE, SCSI_DATA_WRITE,
data, num_registers*2, 0); data, num_registers*2, 0);
if (result!=USB_STOR_TRANSPORT_GOOD) if (result!=USB_STOR_TRANSPORT_GOOD)
...@@ -488,8 +319,8 @@ int usbat_rw_block_test(struct us_data *us, ...@@ -488,8 +319,8 @@ int usbat_rw_block_test(struct us_data *us,
// direction == SCSI_DATA_WRITE ? "out" : "in", // direction == SCSI_DATA_WRITE ? "out" : "in",
// len, use_sg); // len, use_sg);
result = usbat_bulk_transport(us, result = usb_storage_bulk_transport(us,
NULL, 0, direction, content, len, use_sg); direction, content, len, use_sg);
/* /*
* If we get a stall on the bulk download, we'll retry * If we get a stall on the bulk download, we'll retry
...@@ -576,7 +407,7 @@ int usbat_multiple_write(struct us_data *us, ...@@ -576,7 +407,7 @@ int usbat_multiple_write(struct us_data *us,
data[1+(i<<1)] = data_out[i]; data[1+(i<<1)] = data_out[i];
} }
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x80, 0x80,
0x40, 0x40,
...@@ -588,10 +419,10 @@ int usbat_multiple_write(struct us_data *us, ...@@ -588,10 +419,10 @@ int usbat_multiple_write(struct us_data *us,
if (result != USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
result = usbat_bulk_transport(us, result = usb_storage_bulk_transport(us,
NULL, 0, SCSI_DATA_WRITE, data, num_registers*2, 0); SCSI_DATA_WRITE, data, num_registers*2, 0);
if (result!=USB_STOR_TRANSPORT_GOOD) if (result != USB_STOR_TRANSPORT_GOOD)
return result; return result;
return usbat_wait_not_busy(us, 0); return usbat_wait_not_busy(us, 0);
...@@ -602,7 +433,7 @@ int usbat_read_user_io(struct us_data *us, ...@@ -602,7 +433,7 @@ int usbat_read_user_io(struct us_data *us,
int result; int result;
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_rcvctrlpipe(us->pusb_dev,0), usb_rcvctrlpipe(us->pusb_dev,0),
0x82, 0x82,
0xC0, 0xC0,
...@@ -620,7 +451,7 @@ int usbat_write_user_io(struct us_data *us, ...@@ -620,7 +451,7 @@ int usbat_write_user_io(struct us_data *us,
int result; int result;
result = usbat_send_control(us, result = usb_storage_send_control(us,
usb_sndctrlpipe(us->pusb_dev,0), usb_sndctrlpipe(us->pusb_dev,0),
0x82, 0x82,
0x40, 0x40,
...@@ -646,7 +477,6 @@ int usbat_handle_read10(struct us_data *us, ...@@ -646,7 +477,6 @@ int usbat_handle_read10(struct us_data *us,
unsigned char *buffer; unsigned char *buffer;
unsigned int len; unsigned int len;
unsigned int sector; unsigned int sector;
unsigned int amount;
struct scatterlist *sg = NULL; struct scatterlist *sg = NULL;
int sg_segment = 0; int sg_segment = 0;
int sg_offset = 0; int sg_offset = 0;
...@@ -735,31 +565,11 @@ int usbat_handle_read10(struct us_data *us, ...@@ -735,31 +565,11 @@ int usbat_handle_read10(struct us_data *us,
// Transfer the received data into the srb buffer // Transfer the received data into the srb buffer
if (!srb->use_sg) { if (srb->use_sg)
us_copy_to_sgbuf(buffer, len, sg,
&sg_segment, &sg_offset, srb->use_sg);
else
memcpy(srb->request_buffer+transferred, buffer, len); memcpy(srb->request_buffer+transferred, buffer, len);
} else {
amount = 0;
while (amount<len) {
if (len - amount >=
sg[sg_segment].length-sg_offset) {
memcpy(page_address(sg[sg_segment].page) +
sg[sg_segment].offset + sg_offset,
buffer + amount,
sg[sg_segment].length - sg_offset);
amount +=
sg[sg_segment].length-sg_offset;
sg_segment++;
sg_offset=0;
} else {
memcpy(page_address(sg[sg_segment].page) +
sg[sg_segment].offset + sg_offset,
buffer + amount,
len - amount);
sg_offset += (len - amount);
amount = len;
}
}
}
// Update the amount transferred and the sector number // Update the amount transferred and the sector number
......
...@@ -151,10 +151,13 @@ extern unsigned int usb_stor_transfer_length(Scsi_Cmnd*); ...@@ -151,10 +151,13 @@ extern unsigned int usb_stor_transfer_length(Scsi_Cmnd*);
extern void usb_stor_invoke_transport(Scsi_Cmnd*, struct us_data*); extern void usb_stor_invoke_transport(Scsi_Cmnd*, struct us_data*);
extern void usb_stor_abort_transport(struct us_data*); extern void usb_stor_abort_transport(struct us_data*);
extern int usb_stor_transfer_partial(struct us_data*, char*, int); extern int usb_stor_transfer_partial(struct us_data*, char*, int);
extern int usb_stor_bulk_msg(struct us_data*, void*, int, unsigned int,
unsigned int*); extern int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe,
extern int usb_stor_control_msg(struct us_data*, unsigned int, u8, u8, unsigned int len, unsigned int *act_len);
u16, u16, void*, u16); extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
u8 request, u8 requesttype, u16 value, u16 index,
void *data, u16 size);
extern int usb_stor_clear_halt(struct us_data*, int ); extern int usb_stor_clear_halt(struct us_data*, int );
extern void usb_stor_transfer(Scsi_Cmnd*, struct us_data*); extern void usb_stor_transfer(Scsi_Cmnd*, struct us_data*);
#endif #endif
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