Commit 2167f96c authored by Matthew Dharm's avatar Matthew Dharm Committed by Linus Torvalds

[PATCH] usb-storage: generalize transfer functions

This patch generalizes the transfer functions.  This is in preparation for
consolidating all sub-drivers to use a common set of functions.

Oh, and this patch makes the residue field be initialized.  Making this the
correct value is still on the TODO list.
parent 3f3279aa
......@@ -522,6 +522,7 @@ int datafab_transport(Scsi_Cmnd * srb, struct us_data *us)
0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
};
srb->resid = 0;
if (!us->extra) {
us->extra = kmalloc(sizeof(struct datafab_info), GFP_NOIO);
if (!us->extra) {
......
......@@ -108,69 +108,6 @@ struct freecom_status {
/* All packets (except for status) are 64 bytes long. */
#define FCM_PACKET_LENGTH 64
/*
* Transfer an entire SCSI command's worth of data payload over the bulk
* pipe.
*
* Note that this uses usb_stor_transfer_partial to achieve it's goals -- this
* function simply determines if we're going to use scatter-gather or not,
* and acts appropriately. For now, it also re-interprets the error codes.
*/
static void us_transfer_freecom(Scsi_Cmnd *srb, struct us_data* us, int transfer_amount)
{
int i;
int result = -1;
struct scatterlist *sg;
unsigned int total_transferred = 0;
/* was someone foolish enough to request more data than available
* buffer space? */
if (transfer_amount > srb->request_bufflen)
transfer_amount = srb->request_bufflen;
/* are we scatter-gathering? */
if (srb->use_sg) {
/* loop over all the scatter gather structures and
* make the appropriate requests for each, until done
*/
sg = (struct scatterlist *) srb->request_buffer;
for (i = 0; i < srb->use_sg; i++) {
US_DEBUGP("transfer_amount: %d and total_transferred: %d\n", transfer_amount, total_transferred);
/* End this if we're done */
if (transfer_amount == total_transferred)
break;
/* transfer the lesser of the next buffer or the
* remaining data */
if (transfer_amount - total_transferred >=
sg[i].length) {
result = usb_stor_transfer_partial(us,
sg_address(sg[i]), sg[i].length);
total_transferred += sg[i].length;
} else {
result = usb_stor_transfer_partial(us,
sg_address(sg[i]),
transfer_amount - total_transferred);
total_transferred += transfer_amount - total_transferred;
}
/* if we get an error, end the loop here */
if (result)
break;
}
}
else
/* no scatter-gather, just make the request */
result = usb_stor_transfer_partial(us, srb->request_buffer,
transfer_amount);
/* return the result in the data structure itself */
srb->result = result;
}
static int
freecom_readdata (Scsi_Cmnd *srb, struct us_data *us,
unsigned int ipipe, unsigned int opipe, int count)
......@@ -206,10 +143,10 @@ freecom_readdata (Scsi_Cmnd *srb, struct us_data *us,
/* Now transfer all of our blocks. */
US_DEBUGP("Start of read\n");
us_transfer_freecom(srb, us, count);
result = usb_stor_bulk_transfer_srb(us, ipipe, srb, count);
US_DEBUGP("freecom_readdata done!\n");
return USB_STOR_TRANSPORT_GOOD;
return result;
}
static int
......@@ -248,10 +185,10 @@ freecom_writedata (Scsi_Cmnd *srb, struct us_data *us,
/* Now transfer all of our blocks. */
US_DEBUGP("Start of write\n");
us_transfer_freecom(srb, us, count);
result = usb_stor_bulk_transfer_srb(us, opipe, srb, count);
US_DEBUGP("freecom_writedata done!\n");
return USB_STOR_TRANSPORT_GOOD;
return result;
}
/*
......
......@@ -464,7 +464,7 @@ int jumpshot_transport(Scsi_Cmnd * srb, struct us_data *us)
0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
};
srb->resid = 0;
if (!us->extra) {
us->extra = kmalloc(sizeof(struct jumpshot_info), GFP_NOIO);
if (!us->extra) {
......
......@@ -1368,6 +1368,7 @@ int sddr09_transport(Scsi_Cmnd *srb, struct us_data *us)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
srb->resid = 0;
info = (struct sddr09_card_info *)us->extra;
if (!info) {
nand_init_ecc();
......
......@@ -743,6 +743,7 @@ int sddr55_transport(Scsi_Cmnd *srb, struct us_data *us)
unsigned short pages;
struct sddr55_card_info *info;
srb->resid = 0;
if (!us->extra) {
us->extra = kmalloc(
sizeof(struct sddr55_card_info), GFP_NOIO);
......
......@@ -766,6 +766,7 @@ int hp8200e_transport(Scsi_Cmnd *srb, struct us_data *us)
int i;
char string[64];
srb->resid = 0;
len = srb->request_bufflen;
/* Send A0 (ATA PACKET COMMAND).
......
This diff is collapsed.
......@@ -115,7 +115,7 @@ struct bulk_cs_wrap {
#define US_BULK_GET_MAX_LUN 0xfe
/*
* usb_stor_transfer() return codes, in order of severity
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
*/
#define USB_STOR_XFER_GOOD 0 /* good transfer */
#define USB_STOR_XFER_SHORT 1 /* transfered less than expected */
......@@ -151,7 +151,6 @@ extern int usb_stor_Bulk_reset(struct us_data*);
extern unsigned int usb_stor_transfer_length(Scsi_Cmnd*);
extern void usb_stor_invoke_transport(Scsi_Cmnd*, 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_bulk_msg(struct us_data *us, void *data,
unsigned int pipe, unsigned int len, unsigned int *act_len);
......@@ -160,5 +159,18 @@ extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
void *data, u16 size);
extern int usb_stor_clear_halt(struct us_data*, unsigned int pipe);
extern void usb_stor_transfer(Scsi_Cmnd*, struct us_data*);
extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
u8 request, u8 requesttype, u16 value, u16 index,
void *data, u16 size);
extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
char *buf, unsigned int length, unsigned int *act_len);
extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
char *buf, unsigned int length, int use_sg, int *residual);
static __inline__ int usb_stor_bulk_transfer_srb(struct us_data *us,
unsigned int pipe, Scsi_Cmnd *srb, unsigned int length) {
return usb_stor_bulk_transfer_sg(us, pipe, srb->request_buffer,
length, srb->use_sg, &srb->resid);
}
#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