1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 #include <linux/sched.h>
4 #include <linux/errno.h>
5 #include <linux/slab.h>
21 static void usb_stor_blocking_completion(
struct urb *
urb)
23 struct completion *urb_done_ptr = urb->context;
32 static int usb_stor_msg_common(
struct us_data *us,
int timeout)
42 init_completion(&urb_done);
51 us->
current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
93 us->
cr->bRequestType = requesttype;
101 (
unsigned char *) us->
cr, data, size,
102 usb_stor_blocking_completion,
NULL);
103 status = usb_stor_msg_common(us, timeout);
117 int endp = usb_pipeendpoint(pipe);
120 if (usb_pipein(pipe))
140 static int interpret_urb_result(
struct us_data *us,
unsigned int pipe,
147 if (partial != length) {
154 if (usb_pipecontrol(pipe)) {
184 void *
buf,
unsigned int length,
unsigned int *act_len)
192 length, usb_stor_blocking_completion,
NULL);
193 result = usb_stor_msg_common(us, 0);
199 return interpret_urb_result(us, pipe, length, result,
206 static int usb_stor_bulk_transfer_sglist(
struct us_data *us,
unsigned int pipe,
208 unsigned int *act_len)
245 return interpret_urb_result(us, pipe, length,
255 unsigned int partial;
256 int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
257 scsi_sg_count(srb), scsi_bufflen(srb),
260 scsi_set_resid(srb, scsi_bufflen(srb) - partial);
268 void *
buf,
unsigned int length_left,
int use_sg,
int *
residual)
271 unsigned int partial;
277 result = usb_stor_bulk_transfer_sglist(us, pipe,
279 length_left, &partial);
280 length_left -= partial;
284 length_left, &partial);
285 length_left -= partial;
290 *residual = length_left;
308 scsi_set_resid(srb, 0);
349 if (need_auto_sense) {
353 pr_info(
"Issuing auto-REQUEST_SENSE\n");
366 scsi_set_resid(srb, 0);
380 if (!(us->
fflags & US_FL_SCM_MULT_TARG))
434 scsi_set_resid(srb, 0);
510 pr_info(
"transport --- BuildSenseBuffer\n");
528 buf[0x02] = SrbStatus;
584 unsigned int transfer_length = scsi_bufflen(srb);
585 unsigned int residue;
604 if (us->
fflags & US_FL_SCM_MULT_TARG)
629 if (transfer_length) {
674 if (!(bcs->Tag == us->
tag ||
675 (us->
fflags & US_FL_BULK_IGNORE_TAG)) ||
695 if (residue && !(us->
fflags & US_FL_IGNORE_RESIDUE)) {
702 scsi_get_resid(srb) == 0 &&
704 transfer_length == 36) ||
706 transfer_length == 8))) {
707 us->
fflags |= US_FL_IGNORE_RESIDUE;
710 residue =
min(residue, transfer_length);
711 scsi_set_resid(srb,
max(scsi_get_resid(srb),
717 switch (bcs->Status) {
741 static int usb_stor_reset_common(
struct us_data *us,
755 request, requesttype, value, index, data, size, 5*
HZ);
807 pr_info(
"unable to lock device for reset: %d\n", result);