1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 #include <linux/sched.h>
4 #include <linux/errno.h>
5 #include <linux/slab.h>
8 #include <scsi/scsi_eh.h>
9 #include <scsi/scsi_device.h>
13 #include "transport.h"
15 /***********************************************************************
16 * Data transfer routines
17 ***********************************************************************/
19 * usb_stor_blocking_completion()
21 static void usb_stor_blocking_completion(struct urb *urb)
23 struct completion *urb_done_ptr = urb->context;
25 /* pr_info("transport --- usb_stor_blocking_completion\n"); */
26 complete(urb_done_ptr);
30 * usb_stor_msg_common()
32 static int usb_stor_msg_common(struct us_data *us, int timeout)
34 struct completion urb_done;
38 /* pr_info("transport --- usb_stor_msg_common\n"); */
39 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
42 init_completion(&urb_done);
44 us->current_urb->context = &urb_done;
45 us->current_urb->actual_length = 0;
46 us->current_urb->error_count = 0;
47 us->current_urb->status = 0;
49 us->current_urb->transfer_flags = 0;
50 if (us->current_urb->transfer_buffer == us->iobuf)
51 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
52 us->current_urb->transfer_dma = us->iobuf_dma;
53 us->current_urb->setup_dma = us->cr_dma;
55 status = usb_submit_urb(us->current_urb, GFP_NOIO);
59 set_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
61 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
62 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
63 /* pr_info("-- cancelling URB\n"); */
64 usb_unlink_urb(us->current_urb);
68 timeleft = wait_for_completion_interruptible_timeout(&urb_done,
69 timeout ? : MAX_SCHEDULE_TIMEOUT);
70 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
73 /* pr_info("%s -- cancelling URB\n",
74 timeleft == 0 ? "Timeout" : "Signal"); */
75 usb_kill_urb(us->current_urb);
78 return us->current_urb->status;
82 * usb_stor_print_cmd():
84 static void usb_stor_print_cmd(struct us_data *us, struct scsi_cmnd *srb)
93 dev_dbg(&us->pusb_dev->dev,
94 "scsi cmd %X --- SCSIOP_INQUIRY\n", cmd);
97 dev_dbg(&us->pusb_dev->dev,
98 "scsi cmd %X --- SCSIOP_MODE_SENSE\n", cmd);
101 dev_dbg(&us->pusb_dev->dev,
102 "scsi cmd %X --- SCSIOP_START_STOP\n", cmd);
105 dev_dbg(&us->pusb_dev->dev,
106 "scsi cmd %X --- SCSIOP_READ_CAPACITY\n", cmd);
112 case ALLOW_MEDIUM_REMOVAL:
113 dev_dbg(&us->pusb_dev->dev,
114 "scsi cmd %X --- SCSIOP_ALLOW_MEDIUM_REMOVAL\n", cmd);
117 dev_dbg(&us->pusb_dev->dev, "scsi cmd %X --- Other cmd\n", cmd);
123 * usb_stor_control_msg()
125 int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
126 u8 request, u8 requesttype, u16 value, u16 index,
127 void *data, u16 size, int timeout)
131 /* pr_info("transport --- usb_stor_control_msg\n"); */
133 /* fill in the devrequest structure */
134 us->cr->bRequestType = requesttype;
135 us->cr->bRequest = request;
136 us->cr->wValue = cpu_to_le16(value);
137 us->cr->wIndex = cpu_to_le16(index);
138 us->cr->wLength = cpu_to_le16(size);
140 /* fill and submit the URB */
141 usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
142 (unsigned char *) us->cr, data, size,
143 usb_stor_blocking_completion, NULL);
144 status = usb_stor_msg_common(us, timeout);
146 /* return the actual length of the data transferred if no error */
148 status = us->current_urb->actual_length;
153 * usb_stor_clear_halt()
155 int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
158 int endp = usb_pipeendpoint(pipe);
160 /* pr_info("transport --- usb_stor_clear_halt\n"); */
161 if (usb_pipein(pipe))
164 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
165 USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT,
166 USB_ENDPOINT_HALT, endp,
169 /* reset the endpoint toggle */
171 /* usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe),
172 usb_pipeout(pipe), 0); */
173 usb_reset_endpoint(us->pusb_dev, endp);
179 * interpret_urb_result()
181 static int interpret_urb_result(struct us_data *us, unsigned int pipe,
182 unsigned int length, int result, unsigned int partial)
184 /* pr_info("transport --- interpret_urb_result\n"); */
186 /* no error code; did we send all the data? */
188 if (partial != length) {
189 /* pr_info("-- short transfer\n"); */
190 return USB_STOR_XFER_SHORT;
192 /* pr_info("-- transfer complete\n"); */
193 return USB_STOR_XFER_GOOD;
195 if (usb_pipecontrol(pipe)) {
196 /* pr_info("-- stall on control pipe\n"); */
197 return USB_STOR_XFER_STALLED;
199 /* pr_info("clearing endpoint halt for pipe 0x%x\n", pipe); */
200 if (usb_stor_clear_halt(us, pipe) < 0)
201 return USB_STOR_XFER_ERROR;
202 return USB_STOR_XFER_STALLED;
204 /* pr_info("-- babble\n"); */
205 return USB_STOR_XFER_LONG;
207 /* pr_info("-- transfer cancelled\n"); */
208 return USB_STOR_XFER_ERROR;
210 /* pr_info("-- short read transfer\n"); */
211 return USB_STOR_XFER_SHORT;
213 /* pr_info("-- abort or disconnect in progress\n"); */
214 return USB_STOR_XFER_ERROR;
216 /* pr_info("-- unknown error\n"); */
217 return USB_STOR_XFER_ERROR;
222 * usb_stor_bulk_transfer_buf()
224 int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
225 void *buf, unsigned int length, unsigned int *act_len)
229 /* pr_info("transport --- usb_stor_bulk_transfer_buf\n"); */
231 /* fill and submit the URB */
232 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf,
233 length, usb_stor_blocking_completion, NULL);
234 result = usb_stor_msg_common(us, 0);
236 /* store the actual length of the data transferred */
238 *act_len = us->current_urb->actual_length;
240 return interpret_urb_result(us, pipe, length, result,
241 us->current_urb->actual_length);
245 * usb_stor_bulk_transfer_sglist()
247 static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
248 struct scatterlist *sg, int num_sg, unsigned int length,
249 unsigned int *act_len)
253 /* pr_info("transport --- usb_stor_bulk_transfer_sglist\n"); */
254 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
255 return USB_STOR_XFER_ERROR;
257 /* initialize the scatter-gather request block */
258 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0,
259 sg, num_sg, length, GFP_NOIO);
261 /* pr_info("usb_sg_init returned %d\n", result); */
262 return USB_STOR_XFER_ERROR;
265 /* since the block has been initialized successfully,
266 it's now okay to cancel it */
267 set_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
269 /* did an abort/disconnect occur during the submission? */
270 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
271 /* cancel the request, if it hasn't been cancelled already */
272 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
273 /* pr_info("-- cancelling sg request\n"); */
274 usb_sg_cancel(&us->current_sg);
278 /* wait for the completion of the transfer */
279 usb_sg_wait(&us->current_sg);
280 clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
282 result = us->current_sg.status;
284 *act_len = us->current_sg.bytes;
286 return interpret_urb_result(us, pipe, length,
287 result, us->current_sg.bytes);
291 * usb_stor_bulk_srb()
293 int usb_stor_bulk_srb(struct us_data *us, unsigned int pipe,
294 struct scsi_cmnd *srb)
296 unsigned int partial;
297 int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
298 scsi_sg_count(srb), scsi_bufflen(srb),
301 scsi_set_resid(srb, scsi_bufflen(srb) - partial);
306 * usb_stor_bulk_transfer_sg()
308 int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
309 void *buf, unsigned int length_left, int use_sg, int *residual)
312 unsigned int partial;
314 /* pr_info("transport --- usb_stor_bulk_transfer_sg\n"); */
315 /* are we scatter-gathering? */
317 /* use the usb core scatter-gather primitives */
318 result = usb_stor_bulk_transfer_sglist(us, pipe,
319 (struct scatterlist *) buf, use_sg,
320 length_left, &partial);
321 length_left -= partial;
323 /* no scatter-gather, just make the request */
324 result = usb_stor_bulk_transfer_buf(us, pipe, buf,
325 length_left, &partial);
326 length_left -= partial;
329 /* store the residual and return the error code */
331 *residual = length_left;
335 /***********************************************************************
337 ***********************************************************************/
339 * usb_stor_invoke_transport()
341 void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
346 /* pr_info("transport --- usb_stor_invoke_transport\n"); */
347 usb_stor_print_cmd(us, srb);
348 /* send the command to the transport layer */
349 scsi_set_resid(srb, 0);
350 result = us->transport(srb, us); /* usb_stor_Bulk_transport; */
352 /* if the command gets aborted by the higher layers,
353 we need to short-circuit all other processing */
354 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
355 /* pr_info("-- command was aborted\n"); */
356 srb->result = DID_ABORT << 16;
360 /* if there is a transport error, reset and don't auto-sense */
361 if (result == USB_STOR_TRANSPORT_ERROR) {
362 /* pr_info("-- transport indicates error, resetting\n"); */
363 srb->result = DID_ERROR << 16;
367 /* if the transport provided its own sense data, don't auto-sense */
368 if (result == USB_STOR_TRANSPORT_NO_SENSE) {
369 srb->result = SAM_STAT_CHECK_CONDITION;
373 srb->result = SAM_STAT_GOOD;
375 /* Determine if we need to auto-sense */
378 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
379 srb->sc_data_direction != DMA_FROM_DEVICE) {
380 /* pr_info("-- CB transport device requiring auto-sense\n"); */
384 if (result == USB_STOR_TRANSPORT_FAILED) {
385 /* pr_info("-- transport indicates command failure\n"); */
389 /* Now, if we need to do the auto-sense, let's do it */
390 if (need_auto_sense) {
392 struct scsi_eh_save ses;
394 pr_info("Issuing auto-REQUEST_SENSE\n");
396 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE);
398 /* we must do the protocol translation here */
399 if (us->subclass == USB_SC_RBC ||
400 us->subclass == USB_SC_SCSI ||
401 us->subclass == USB_SC_CYP_ATACB) {
406 /* issue the auto-sense command */
407 scsi_set_resid(srb, 0);
408 temp_result = us->transport(us->srb, us);
410 /* let's clean up right away */
411 scsi_eh_restore_cmnd(srb, &ses);
413 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
414 /* pr_info("-- auto-sense aborted\n"); */
415 srb->result = DID_ABORT << 16;
418 if (temp_result != USB_STOR_TRANSPORT_GOOD) {
419 /* pr_info("-- auto-sense failure\n"); */
420 srb->result = DID_ERROR << 16;
421 if (!(us->fflags & US_FL_SCM_MULT_TARG))
426 /* set the result so the higher layers expect this data */
427 srb->result = SAM_STAT_CHECK_CONDITION;
429 if (result == USB_STOR_TRANSPORT_GOOD &&
430 (srb->sense_buffer[2] & 0xaf) == 0 &&
431 srb->sense_buffer[12] == 0 &&
432 srb->sense_buffer[13] == 0) {
433 srb->result = SAM_STAT_GOOD;
434 srb->sense_buffer[0] = 0x0;
438 /* Did we transfer less than the minimum amount required? */
439 if (srb->result == SAM_STAT_GOOD && scsi_bufflen(srb) -
440 scsi_get_resid(srb) < srb->underflow)
441 srb->result = (DID_ERROR << 16);
442 /* v02 | (SUGGEST_RETRY << 24); */
447 scsi_lock(us_to_host(us));
448 set_bit(US_FLIDX_RESETTING, &us->dflags);
449 clear_bit(US_FLIDX_ABORTING, &us->dflags);
450 scsi_unlock(us_to_host(us));
452 mutex_unlock(&us->dev_mutex);
453 result = usb_stor_port_reset(us);
454 mutex_lock(&us->dev_mutex);
457 scsi_lock(us_to_host(us));
458 usb_stor_report_device_reset(us);
459 scsi_unlock(us_to_host(us));
460 us->transport_reset(us);
462 clear_bit(US_FLIDX_RESETTING, &us->dflags);
466 * ENE_stor_invoke_transport()
468 void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
472 /* pr_info("transport --- ENE_stor_invoke_transport\n"); */
473 usb_stor_print_cmd(us, srb);
474 /* send the command to the transport layer */
475 scsi_set_resid(srb, 0);
476 if (!(us->SM_Status.Ready))
477 result = ENE_InitMedia(us);
479 if (us->Power_IsResum == true) {
480 result = ENE_InitMedia(us);
481 us->Power_IsResum = false;
484 if (us->SM_Status.Ready)
485 result = SM_SCSIIrp(us, srb);
487 /* if the command gets aborted by the higher layers,
488 we need to short-circuit all other processing */
489 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
490 /* pr_info("-- command was aborted\n"); */
491 srb->result = DID_ABORT << 16;
495 /* if there is a transport error, reset and don't auto-sense */
496 if (result == USB_STOR_TRANSPORT_ERROR) {
497 /* pr_info("-- transport indicates error, resetting\n"); */
498 srb->result = DID_ERROR << 16;
502 /* if the transport provided its own sense data, don't auto-sense */
503 if (result == USB_STOR_TRANSPORT_NO_SENSE) {
504 srb->result = SAM_STAT_CHECK_CONDITION;
508 srb->result = SAM_STAT_GOOD;
509 if (result == USB_STOR_TRANSPORT_FAILED) {
510 /* pr_info("-- transport indicates command failure\n"); */
511 /* need_auto_sense = 1; */
512 BuildSenseBuffer(srb, us->SrbStatus);
513 srb->result = SAM_STAT_CHECK_CONDITION;
516 /* Did we transfer less than the minimum amount required? */
517 if (srb->result == SAM_STAT_GOOD && scsi_bufflen(srb) -
518 scsi_get_resid(srb) < srb->underflow)
519 srb->result = (DID_ERROR << 16);
520 /* v02 | (SUGGEST_RETRY << 24); */
525 scsi_lock(us_to_host(us));
526 set_bit(US_FLIDX_RESETTING, &us->dflags);
527 clear_bit(US_FLIDX_ABORTING, &us->dflags);
528 scsi_unlock(us_to_host(us));
530 mutex_unlock(&us->dev_mutex);
531 result = usb_stor_port_reset(us);
532 mutex_lock(&us->dev_mutex);
535 scsi_lock(us_to_host(us));
536 usb_stor_report_device_reset(us);
537 scsi_unlock(us_to_host(us));
538 us->transport_reset(us);
540 clear_bit(US_FLIDX_RESETTING, &us->dflags);
546 void BuildSenseBuffer(struct scsi_cmnd *srb, int SrbStatus)
548 u8 *buf = srb->sense_buffer;
551 pr_info("transport --- BuildSenseBuffer\n");
555 break; /* sense key = 0x02 */
558 break; /* sense key = 0x03 */
559 case SS_ILLEGAL_REQUEST:
561 break; /* sense key = 0x05 */
569 buf[0x02] = SrbStatus;
575 * usb_stor_stop_transport()
577 void usb_stor_stop_transport(struct us_data *us)
579 /* pr_info("transport --- usb_stor_stop_transport\n"); */
581 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
582 /* pr_info("-- cancelling URB\n"); */
583 usb_unlink_urb(us->current_urb);
586 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
587 /* pr_info("-- cancelling sg request\n"); */
588 usb_sg_cancel(&us->current_sg);
593 * usb_stor_Bulk_max_lun()
595 int usb_stor_Bulk_max_lun(struct us_data *us)
599 /* pr_info("transport --- usb_stor_Bulk_max_lun\n"); */
600 /* issue the command */
602 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
604 USB_DIR_IN | USB_TYPE_CLASS |
606 0, us->ifnum, us->iobuf, 1, HZ);
608 /* pr_info("GetMaxLUN command result is %d, data is %d\n",
609 result, us->iobuf[0]); */
611 /* if we have a successful request, return the result */
619 * usb_stor_Bulk_transport()
621 int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
623 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
624 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
625 unsigned int transfer_length = scsi_bufflen(srb);
626 unsigned int residue;
630 unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
632 /* pr_info("transport --- usb_stor_Bulk_transport\n"); */
633 /* Take care of BULK32 devices; set extra byte to 0 */
634 if (unlikely(us->fflags & US_FL_BULK32)) {
639 /* set up the command wrapper */
640 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
641 bcb->DataTransferLength = cpu_to_le32(transfer_length);
642 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0;
643 bcb->Tag = ++us->tag;
644 bcb->Lun = srb->device->lun;
645 if (us->fflags & US_FL_SCM_MULT_TARG)
646 bcb->Lun |= srb->device->id << 4;
647 bcb->Length = srb->cmd_len;
649 /* copy the command payload */
650 memset(bcb->CDB, 0, sizeof(bcb->CDB));
651 memcpy(bcb->CDB, srb->cmnd, bcb->Length);
654 /* send it to out endpoint */
655 /* pr_info("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
656 le32_to_cpu(bcb->Signature), bcb->Tag,
657 le32_to_cpu(bcb->DataTransferLength), bcb->Flags,
658 (bcb->Lun >> 4), (bcb->Lun & 0x0F),
660 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
662 /* pr_info("Bulk command transfer result=%d\n", result); */
663 if (result != USB_STOR_XFER_GOOD)
664 return USB_STOR_TRANSPORT_ERROR;
666 if (unlikely(us->fflags & US_FL_GO_SLOW))
670 if (transfer_length) {
673 if (srb->sc_data_direction == DMA_FROM_DEVICE)
674 pipe = us->recv_bulk_pipe;
676 pipe = us->send_bulk_pipe;
678 result = usb_stor_bulk_srb(us, pipe, srb);
679 /* pr_info("Bulk data transfer result 0x%x\n", result); */
680 if (result == USB_STOR_XFER_ERROR)
681 return USB_STOR_TRANSPORT_ERROR;
683 if (result == USB_STOR_XFER_LONG)
687 /* get CSW for device status */
688 /* pr_info("Attempting to get CSW...\n"); */
689 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
690 US_BULK_CS_WRAP_LEN, &cswlen);
692 if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
693 /* pr_info("Received 0-length CSW; retrying...\n"); */
694 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
695 US_BULK_CS_WRAP_LEN, &cswlen);
698 /* did the attempt to read the CSW fail? */
699 if (result == USB_STOR_XFER_STALLED) {
700 /* get the status again */
701 /* pr_info("Attempting to get CSW (2nd try)...\n"); */
702 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
703 US_BULK_CS_WRAP_LEN, NULL);
706 /* if we still have a failure at this point, we're in trouble */
707 /* pr_info("Bulk status result = %d\n", result); */
708 if (result != USB_STOR_XFER_GOOD)
709 return USB_STOR_TRANSPORT_ERROR;
711 /* check bulk status */
712 residue = le32_to_cpu(bcs->Residue);
713 /* pr_info("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
714 le32_to_cpu(bcs->Signature),
715 bcs->Tag, residue, bcs->Status); */
716 if (!(bcs->Tag == us->tag ||
717 (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
718 bcs->Status > US_BULK_STAT_PHASE) {
719 /* pr_info("Bulk logical error\n"); */
720 return USB_STOR_TRANSPORT_ERROR;
723 if (!us->bcs_signature) {
724 us->bcs_signature = bcs->Signature;
725 /* if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN)) */
726 /* pr_info("Learnt BCS signature 0x%08X\n",
727 le32_to_cpu(us->bcs_signature)); */
728 } else if (bcs->Signature != us->bcs_signature) {
729 /* pr_info("Signature mismatch: got %08X, expecting %08X\n",
730 le32_to_cpu(bcs->Signature),
731 le32_to_cpu(us->bcs_signature)); */
732 return USB_STOR_TRANSPORT_ERROR;
735 /* try to compute the actual residue, based on how much data
736 * was really transferred and what the device tells us */
737 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
739 /* Heuristically detect devices that generate bogus residues
740 * by seeing what happens with INQUIRY and READ CAPACITY
743 if (bcs->Status == US_BULK_STAT_OK &&
744 scsi_get_resid(srb) == 0 &&
745 ((srb->cmnd[0] == INQUIRY &&
746 transfer_length == 36) ||
747 (srb->cmnd[0] == READ_CAPACITY &&
748 transfer_length == 8))) {
749 us->fflags |= US_FL_IGNORE_RESIDUE;
752 residue = min(residue, transfer_length);
753 scsi_set_resid(srb, max_t(int, scsi_get_resid(srb),
758 /* based on the status code, we report good or bad */
759 switch (bcs->Status) {
760 case US_BULK_STAT_OK:
762 memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB,
763 sizeof(usb_stor_sense_invalidCDB));
764 return USB_STOR_TRANSPORT_NO_SENSE;
766 return USB_STOR_TRANSPORT_GOOD;
768 case US_BULK_STAT_FAIL:
769 return USB_STOR_TRANSPORT_FAILED;
771 case US_BULK_STAT_PHASE:
772 return USB_STOR_TRANSPORT_ERROR;
774 return USB_STOR_TRANSPORT_ERROR;
777 /***********************************************************************
779 ***********************************************************************/
781 * usb_stor_reset_common()
783 static int usb_stor_reset_common(struct us_data *us,
784 u8 request, u8 requesttype,
785 u16 value, u16 index, void *data, u16 size)
790 /* pr_info("transport --- usb_stor_reset_common\n"); */
791 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
792 /* pr_info("No reset during disconnect\n"); */
796 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
797 request, requesttype, value, index, data, size, 5*HZ);
800 /* pr_info("Soft reset failed: %d\n", result); */
804 wait_event_interruptible_timeout(us->delay_wait,
805 test_bit(US_FLIDX_DISCONNECTING, &us->dflags), HZ*6);
807 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
808 /* pr_info("Reset interrupted by disconnect\n"); */
812 /* pr_info("Soft reset: clearing bulk-in endpoint halt\n"); */
813 result = usb_stor_clear_halt(us, us->recv_bulk_pipe);
815 /* pr_info("Soft reset: clearing bulk-out endpoint halt\n"); */
816 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
818 /* return a result code based on the result of the clear-halts */
821 /* if (result < 0) */
822 /* pr_info("Soft reset failed\n"); */
824 /* pr_info("Soft reset done\n"); */
829 * usb_stor_Bulk_reset()
831 int usb_stor_Bulk_reset(struct us_data *us)
833 /* pr_info("transport --- usb_stor_Bulk_reset\n"); */
834 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
835 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
836 0, us->ifnum, NULL, 0);
840 * usb_stor_port_reset()
842 int usb_stor_port_reset(struct us_data *us)
846 /* pr_info("transport --- usb_stor_port_reset\n"); */
847 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
849 pr_info("unable to lock device for reset: %d\n", result);
851 /* Were we disconnected while waiting for the lock? */
852 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
854 /* pr_info("No reset during disconnect\n"); */
856 result = usb_reset_device(us->pusb_dev);
857 /* pr_info("usb_reset_composite_device returns %d\n",
860 usb_unlock_device(us->pusb_dev);