1 #include <linux/sched.h>
2 #include <linux/errno.h>
3 #include <linux/slab.h>
6 #include <scsi/scsi_eh.h>
7 #include <scsi/scsi_device.h>
11 #include "transport.h"
13 /***********************************************************************
14 * Data transfer routines
15 ***********************************************************************/
16 //----- usb_stor_blocking_completion() ---------------------
17 static void usb_stor_blocking_completion(struct urb
*urb
)
19 struct completion
*urb_done_ptr
= urb
->context
;
21 //printk("transport --- usb_stor_blocking_completion\n");
22 complete(urb_done_ptr
);
25 //----- usb_stor_msg_common() ---------------------
26 static int usb_stor_msg_common(struct us_data
*us
, int timeout
)
28 struct completion urb_done
;
32 //printk("transport --- usb_stor_msg_common\n");
33 if (test_bit(US_FLIDX_ABORTING
, &us
->dflags
))
36 init_completion(&urb_done
);
38 us
->current_urb
->context
= &urb_done
;
39 us
->current_urb
->actual_length
= 0;
40 us
->current_urb
->error_count
= 0;
41 us
->current_urb
->status
= 0;
43 us
->current_urb
->transfer_flags
= 0;
44 if (us
->current_urb
->transfer_buffer
== us
->iobuf
)
45 us
->current_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
46 us
->current_urb
->transfer_dma
= us
->iobuf_dma
;
47 us
->current_urb
->setup_dma
= us
->cr_dma
;
49 status
= usb_submit_urb(us
->current_urb
, GFP_NOIO
);
53 set_bit(US_FLIDX_URB_ACTIVE
, &us
->dflags
);
55 if (test_bit(US_FLIDX_ABORTING
, &us
->dflags
))
57 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE
, &us
->dflags
))
59 //printk("-- cancelling URB\n");
60 usb_unlink_urb(us
->current_urb
);
64 timeleft
= wait_for_completion_interruptible_timeout(&urb_done
, timeout
? : MAX_SCHEDULE_TIMEOUT
);
65 clear_bit(US_FLIDX_URB_ACTIVE
, &us
->dflags
);
69 //printk("%s -- cancelling URB\n", timeleft == 0 ? "Timeout" : "Signal");
70 usb_kill_urb(us
->current_urb
);
73 return us
->current_urb
->status
;
76 //----- usb_stor_control_msg() ---------------------
77 int usb_stor_control_msg(struct us_data
*us
, unsigned int pipe
,
78 u8 request
, u8 requesttype
, u16 value
, u16 index
,
79 void *data
, u16 size
, int timeout
)
83 //printk("transport --- usb_stor_control_msg\n");
85 /* fill in the devrequest structure */
86 us
->cr
->bRequestType
= requesttype
;
87 us
->cr
->bRequest
= request
;
88 us
->cr
->wValue
= cpu_to_le16(value
);
89 us
->cr
->wIndex
= cpu_to_le16(index
);
90 us
->cr
->wLength
= cpu_to_le16(size
);
92 /* fill and submit the URB */
93 usb_fill_control_urb(us
->current_urb
, us
->pusb_dev
, pipe
,
94 (unsigned char*) us
->cr
, data
, size
,
95 usb_stor_blocking_completion
, NULL
);
96 status
= usb_stor_msg_common(us
, timeout
);
98 /* return the actual length of the data transferred if no error */
100 status
= us
->current_urb
->actual_length
;
104 //----- usb_stor_clear_halt() ---------------------
105 int usb_stor_clear_halt(struct us_data
*us
, unsigned int pipe
)
108 int endp
= usb_pipeendpoint(pipe
);
110 //printk("transport --- usb_stor_clear_halt\n");
111 if (usb_pipein (pipe
))
114 result
= usb_stor_control_msg(us
, us
->send_ctrl_pipe
,
115 USB_REQ_CLEAR_FEATURE
, USB_RECIP_ENDPOINT
,
116 USB_ENDPOINT_HALT
, endp
,
119 /* reset the endpoint toggle */
121 //usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0);
122 usb_reset_endpoint(us
->pusb_dev
, endp
);
127 //----- interpret_urb_result() ---------------------
128 static int interpret_urb_result(struct us_data
*us
, unsigned int pipe
,
129 unsigned int length
, int result
, unsigned int partial
)
131 //printk("transport --- interpret_urb_result\n");
133 /* no error code; did we send all the data? */
135 if (partial
!= length
)
137 //printk("-- short transfer\n");
138 return USB_STOR_XFER_SHORT
;
140 //printk("-- transfer complete\n");
141 return USB_STOR_XFER_GOOD
;
143 if (usb_pipecontrol(pipe
))
145 //printk("-- stall on control pipe\n");
146 return USB_STOR_XFER_STALLED
;
148 //printk("clearing endpoint halt for pipe 0x%x\n", pipe);
149 if (usb_stor_clear_halt(us
, pipe
) < 0)
150 return USB_STOR_XFER_ERROR
;
151 return USB_STOR_XFER_STALLED
;
153 //printk("-- babble\n");
154 return USB_STOR_XFER_LONG
;
156 //printk("-- transfer cancelled\n");
157 return USB_STOR_XFER_ERROR
;
159 //printk("-- short read transfer\n");
160 return USB_STOR_XFER_SHORT
;
162 //printk("-- abort or disconnect in progress\n");
163 return USB_STOR_XFER_ERROR
;
165 //printk("-- unknown error\n");
166 return USB_STOR_XFER_ERROR
;
170 //----- usb_stor_bulk_transfer_buf() ---------------------
171 int usb_stor_bulk_transfer_buf(struct us_data
*us
, unsigned int pipe
,
172 void *buf
, unsigned int length
, unsigned int *act_len
)
176 //printk("transport --- usb_stor_bulk_transfer_buf\n");
178 /* fill and submit the URB */
179 usb_fill_bulk_urb(us
->current_urb
, us
->pusb_dev
, pipe
, buf
, length
, usb_stor_blocking_completion
, NULL
);
180 result
= usb_stor_msg_common(us
, 0);
182 /* store the actual length of the data transferred */
184 *act_len
= us
->current_urb
->actual_length
;
186 return interpret_urb_result(us
, pipe
, length
, result
, us
->current_urb
->actual_length
);
189 //----- usb_stor_bulk_transfer_sglist() ---------------------
190 static int usb_stor_bulk_transfer_sglist(struct us_data
*us
, unsigned int pipe
,
191 struct scatterlist
*sg
, int num_sg
, unsigned int length
,
192 unsigned int *act_len
)
196 //printk("transport --- usb_stor_bulk_transfer_sglist\n");
197 if (test_bit(US_FLIDX_ABORTING
, &us
->dflags
))
198 return USB_STOR_XFER_ERROR
;
200 /* initialize the scatter-gather request block */
201 result
= usb_sg_init(&us
->current_sg
, us
->pusb_dev
, pipe
, 0, sg
, num_sg
, length
, GFP_NOIO
);
204 //printk("usb_sg_init returned %d\n", result);
205 return USB_STOR_XFER_ERROR
;
208 /* since the block has been initialized successfully, it's now okay to cancel it */
209 set_bit(US_FLIDX_SG_ACTIVE
, &us
->dflags
);
211 /* did an abort/disconnect occur during the submission? */
212 if (test_bit(US_FLIDX_ABORTING
, &us
->dflags
))
214 /* cancel the request, if it hasn't been cancelled already */
215 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE
, &us
->dflags
))
217 //printk("-- cancelling sg request\n");
218 usb_sg_cancel(&us
->current_sg
);
222 /* wait for the completion of the transfer */
223 usb_sg_wait(&us
->current_sg
);
224 clear_bit(US_FLIDX_SG_ACTIVE
, &us
->dflags
);
226 result
= us
->current_sg
.status
;
228 *act_len
= us
->current_sg
.bytes
;
230 return interpret_urb_result(us
, pipe
, length
, result
, us
->current_sg
.bytes
);
233 //----- usb_stor_bulk_srb() ---------------------
234 int usb_stor_bulk_srb(struct us_data
* us
, unsigned int pipe
, struct scsi_cmnd
* srb
)
236 unsigned int partial
;
237 int result
= usb_stor_bulk_transfer_sglist(us
, pipe
, scsi_sglist(srb
),
238 scsi_sg_count(srb
), scsi_bufflen(srb
),
241 scsi_set_resid(srb
, scsi_bufflen(srb
) - partial
);
245 //----- usb_stor_bulk_transfer_sg() ---------------------
246 int usb_stor_bulk_transfer_sg(struct us_data
* us
, unsigned int pipe
,
247 void *buf
, unsigned int length_left
, int use_sg
, int *residual
)
250 unsigned int partial
;
252 //printk("transport --- usb_stor_bulk_transfer_sg\n");
253 /* are we scatter-gathering? */
256 /* use the usb core scatter-gather primitives */
257 result
= usb_stor_bulk_transfer_sglist(us
, pipe
,
258 (struct scatterlist
*) buf
, use_sg
,
259 length_left
, &partial
);
260 length_left
-= partial
;
264 /* no scatter-gather, just make the request */
265 result
= usb_stor_bulk_transfer_buf(us
, pipe
, buf
, length_left
, &partial
);
266 length_left
-= partial
;
269 /* store the residual and return the error code */
271 *residual
= length_left
;
275 /***********************************************************************
277 ***********************************************************************/
278 //----- usb_stor_invoke_transport() ---------------------
279 void usb_stor_invoke_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
284 //printk("transport --- usb_stor_invoke_transport\n");
285 usb_stor_print_cmd(srb
);
286 /* send the command to the transport layer */
287 scsi_set_resid(srb
, 0);
288 result
= us
->transport(srb
, us
); //usb_stor_Bulk_transport;
290 /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */
291 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->dflags
))
293 //printk("-- command was aborted\n");
294 srb
->result
= DID_ABORT
<< 16;
298 /* if there is a transport error, reset and don't auto-sense */
299 if (result
== USB_STOR_TRANSPORT_ERROR
)
301 //printk("-- transport indicates error, resetting\n");
302 srb
->result
= DID_ERROR
<< 16;
306 /* if the transport provided its own sense data, don't auto-sense */
307 if (result
== USB_STOR_TRANSPORT_NO_SENSE
)
309 srb
->result
= SAM_STAT_CHECK_CONDITION
;
313 srb
->result
= SAM_STAT_GOOD
;
315 /* Determine if we need to auto-sense */
318 if ((us
->protocol
== USB_PR_CB
|| us
->protocol
== USB_PR_DPCM_USB
) && srb
->sc_data_direction
!= DMA_FROM_DEVICE
)
320 //printk("-- CB transport device requiring auto-sense\n");
324 if (result
== USB_STOR_TRANSPORT_FAILED
)
326 //printk("-- transport indicates command failure\n");
330 /* Now, if we need to do the auto-sense, let's do it */
334 struct scsi_eh_save ses
;
336 printk("Issuing auto-REQUEST_SENSE\n");
338 scsi_eh_prep_cmnd(srb
, &ses
, NULL
, 0, US_SENSE_SIZE
);
340 /* we must do the protocol translation here */
341 if (us
->subclass
== USB_SC_RBC
|| us
->subclass
== USB_SC_SCSI
|| us
->subclass
== USB_SC_CYP_ATACB
)
346 /* issue the auto-sense command */
347 scsi_set_resid(srb
, 0);
348 temp_result
= us
->transport(us
->srb
, us
);
350 /* let's clean up right away */
351 scsi_eh_restore_cmnd(srb
, &ses
);
353 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->dflags
))
355 //printk("-- auto-sense aborted\n");
356 srb
->result
= DID_ABORT
<< 16;
359 if (temp_result
!= USB_STOR_TRANSPORT_GOOD
)
361 //printk("-- auto-sense failure\n");
362 srb
->result
= DID_ERROR
<< 16;
363 if (!(us
->fflags
& US_FL_SCM_MULT_TARG
))
368 /* set the result so the higher layers expect this data */
369 srb
->result
= SAM_STAT_CHECK_CONDITION
;
371 if (result
== USB_STOR_TRANSPORT_GOOD
&&
372 (srb
->sense_buffer
[2] & 0xaf) == 0 &&
373 srb
->sense_buffer
[12] == 0 &&
374 srb
->sense_buffer
[13] == 0)
376 srb
->result
= SAM_STAT_GOOD
;
377 srb
->sense_buffer
[0] = 0x0;
381 /* Did we transfer less than the minimum amount required? */
382 if (srb
->result
== SAM_STAT_GOOD
&& scsi_bufflen(srb
) - scsi_get_resid(srb
) < srb
->underflow
)
383 srb
->result
= (DID_ERROR
<< 16);//v02 | (SUGGEST_RETRY << 24);
388 scsi_lock(us_to_host(us
));
389 set_bit(US_FLIDX_RESETTING
, &us
->dflags
);
390 clear_bit(US_FLIDX_ABORTING
, &us
->dflags
);
391 scsi_unlock(us_to_host(us
));
393 mutex_unlock(&us
->dev_mutex
);
394 result
= usb_stor_port_reset(us
);
395 mutex_lock(&us
->dev_mutex
);
399 scsi_lock(us_to_host(us
));
400 usb_stor_report_device_reset(us
);
401 scsi_unlock(us_to_host(us
));
402 us
->transport_reset(us
);
404 clear_bit(US_FLIDX_RESETTING
, &us
->dflags
);
407 //----- ENE_stor_invoke_transport() ---------------------
408 void ENE_stor_invoke_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
412 //printk("transport --- ENE_stor_invoke_transport\n");
413 usb_stor_print_cmd(srb
);
414 /* send the command to the transport layer */
415 scsi_set_resid(srb
, 0);
416 if ( !(us
->SD_Status
.Ready
|| us
->MS_Status
.Ready
|| us
->SM_Status
.Ready
) )
417 result
= ENE_InitMedia(us
);
419 if (us
->Power_IsResum
== true) {
420 result
= ENE_InitMedia(us
);
421 us
->Power_IsResum
= false;
424 if (us
->SD_Status
.Ready
) result
= SD_SCSIIrp(us
, srb
);
425 if (us
->MS_Status
.Ready
) result
= MS_SCSIIrp(us
, srb
);
426 if (us
->SM_Status
.Ready
) result
= SM_SCSIIrp(us
, srb
);
428 /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */
429 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->dflags
))
431 //printk("-- command was aborted\n");
432 srb
->result
= DID_ABORT
<< 16;
436 /* if there is a transport error, reset and don't auto-sense */
437 if (result
== USB_STOR_TRANSPORT_ERROR
)
439 //printk("-- transport indicates error, resetting\n");
440 srb
->result
= DID_ERROR
<< 16;
444 /* if the transport provided its own sense data, don't auto-sense */
445 if (result
== USB_STOR_TRANSPORT_NO_SENSE
)
447 srb
->result
= SAM_STAT_CHECK_CONDITION
;
451 srb
->result
= SAM_STAT_GOOD
;
452 if (result
== USB_STOR_TRANSPORT_FAILED
)
454 //printk("-- transport indicates command failure\n");
455 //need_auto_sense = 1;
456 BuildSenseBuffer(srb
, us
->SrbStatus
);
457 srb
->result
= SAM_STAT_CHECK_CONDITION
;
460 /* Did we transfer less than the minimum amount required? */
461 if (srb
->result
== SAM_STAT_GOOD
&& scsi_bufflen(srb
) - scsi_get_resid(srb
) < srb
->underflow
)
462 srb
->result
= (DID_ERROR
<< 16);//v02 | (SUGGEST_RETRY << 24);
467 scsi_lock(us_to_host(us
));
468 set_bit(US_FLIDX_RESETTING
, &us
->dflags
);
469 clear_bit(US_FLIDX_ABORTING
, &us
->dflags
);
470 scsi_unlock(us_to_host(us
));
472 mutex_unlock(&us
->dev_mutex
);
473 result
= usb_stor_port_reset(us
);
474 mutex_lock(&us
->dev_mutex
);
478 scsi_lock(us_to_host(us
));
479 usb_stor_report_device_reset(us
);
480 scsi_unlock(us_to_host(us
));
481 us
->transport_reset(us
);
483 clear_bit(US_FLIDX_RESETTING
, &us
->dflags
);
486 //----- BuildSenseBuffer() -------------------------------------------
487 void BuildSenseBuffer(struct scsi_cmnd
*srb
, int SrbStatus
)
489 BYTE
*buf
= srb
->sense_buffer
;
492 printk("transport --- BuildSenseBuffer\n");
495 case SS_NOT_READY
: asc
= 0x3a; break; // sense key = 0x02
496 case SS_MEDIUM_ERR
: asc
= 0x0c; break; // sense key = 0x03
497 case SS_ILLEGAL_REQUEST
: asc
= 0x20; break; // sense key = 0x05
498 default: asc
= 0x00; break; // ??
503 buf
[0x02] = SrbStatus
;
508 //----- usb_stor_stop_transport() ---------------------
509 void usb_stor_stop_transport(struct us_data
*us
)
511 //printk("transport --- usb_stor_stop_transport\n");
513 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE
, &us
->dflags
))
515 //printk("-- cancelling URB\n");
516 usb_unlink_urb(us
->current_urb
);
519 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE
, &us
->dflags
))
521 //printk("-- cancelling sg request\n");
522 usb_sg_cancel(&us
->current_sg
);
526 //----- usb_stor_Bulk_max_lun() ---------------------
527 int usb_stor_Bulk_max_lun(struct us_data
*us
)
531 //printk("transport --- usb_stor_Bulk_max_lun\n");
532 /* issue the command */
534 result
= usb_stor_control_msg(us
, us
->recv_ctrl_pipe
,
536 USB_DIR_IN
| USB_TYPE_CLASS
|
538 0, us
->ifnum
, us
->iobuf
, 1, HZ
);
540 //printk("GetMaxLUN command result is %d, data is %d\n", result, us->iobuf[0]);
542 /* if we have a successful request, return the result */
549 //----- usb_stor_Bulk_transport() ---------------------
550 int usb_stor_Bulk_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
552 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
553 struct bulk_cs_wrap
*bcs
= (struct bulk_cs_wrap
*) us
->iobuf
;
554 unsigned int transfer_length
= scsi_bufflen(srb
);
555 unsigned int residue
;
559 unsigned int cbwlen
= US_BULK_CB_WRAP_LEN
;
561 //printk("transport --- usb_stor_Bulk_transport\n");
562 /* Take care of BULK32 devices; set extra byte to 0 */
563 if (unlikely(us
->fflags
& US_FL_BULK32
))
569 /* set up the command wrapper */
570 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
571 bcb
->DataTransferLength
= cpu_to_le32(transfer_length
);
572 bcb
->Flags
= srb
->sc_data_direction
== DMA_FROM_DEVICE
? 1 << 7 : 0;
573 bcb
->Tag
= ++us
->tag
;
574 bcb
->Lun
= srb
->device
->lun
;
575 if (us
->fflags
& US_FL_SCM_MULT_TARG
)
576 bcb
->Lun
|= srb
->device
->id
<< 4;
577 bcb
->Length
= srb
->cmd_len
;
579 /* copy the command payload */
580 memset(bcb
->CDB
, 0, sizeof(bcb
->CDB
));
581 memcpy(bcb
->CDB
, srb
->cmnd
, bcb
->Length
);
584 /* send it to out endpoint */
585 /*printk("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
586 le32_to_cpu(bcb->Signature), bcb->Tag,
587 le32_to_cpu(bcb->DataTransferLength), bcb->Flags,
588 (bcb->Lun >> 4), (bcb->Lun & 0x0F),
590 result
= usb_stor_bulk_transfer_buf(us
, us
->send_bulk_pipe
, bcb
, cbwlen
, NULL
);
591 //printk("Bulk command transfer result=%d\n", result);
592 if (result
!= USB_STOR_XFER_GOOD
)
593 return USB_STOR_TRANSPORT_ERROR
;
595 if (unlikely(us
->fflags
& US_FL_GO_SLOW
))
601 unsigned int pipe
= srb
->sc_data_direction
== DMA_FROM_DEVICE
? us
->recv_bulk_pipe
: us
->send_bulk_pipe
;
602 result
= usb_stor_bulk_srb(us
, pipe
, srb
);
603 //printk("Bulk data transfer result 0x%x\n", result);
604 if (result
== USB_STOR_XFER_ERROR
)
605 return USB_STOR_TRANSPORT_ERROR
;
607 if (result
== USB_STOR_XFER_LONG
)
611 /* get CSW for device status */
612 //printk("Attempting to get CSW...\n");
613 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
, US_BULK_CS_WRAP_LEN
, &cswlen
);
615 if (result
== USB_STOR_XFER_SHORT
&& cswlen
== 0)
617 //printk("Received 0-length CSW; retrying...\n");
618 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
, US_BULK_CS_WRAP_LEN
, &cswlen
);
621 /* did the attempt to read the CSW fail? */
622 if (result
== USB_STOR_XFER_STALLED
)
624 /* get the status again */
625 //printk("Attempting to get CSW (2nd try)...\n");
626 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
, US_BULK_CS_WRAP_LEN
, NULL
);
629 /* if we still have a failure at this point, we're in trouble */
630 //printk("Bulk status result = %d\n", result);
631 if (result
!= USB_STOR_XFER_GOOD
)
632 return USB_STOR_TRANSPORT_ERROR
;
634 /* check bulk status */
635 residue
= le32_to_cpu(bcs
->Residue
);
636 //printk("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", le32_to_cpu(bcs->Signature), bcs->Tag, residue, bcs->Status);
637 if (!(bcs
->Tag
== us
->tag
|| (us
->fflags
& US_FL_BULK_IGNORE_TAG
)) || bcs
->Status
> US_BULK_STAT_PHASE
)
639 //printk("Bulk logical error\n");
640 return USB_STOR_TRANSPORT_ERROR
;
643 if (!us
->bcs_signature
)
645 us
->bcs_signature
= bcs
->Signature
;
646 //if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN))
647 // printk("Learnt BCS signature 0x%08X\n", le32_to_cpu(us->bcs_signature));
649 else if (bcs
->Signature
!= us
->bcs_signature
)
651 /*printk("Signature mismatch: got %08X, expecting %08X\n",
652 le32_to_cpu(bcs->Signature),
653 le32_to_cpu(us->bcs_signature));*/
654 return USB_STOR_TRANSPORT_ERROR
;
657 /* try to compute the actual residue, based on how much data
658 * was really transferred and what the device tells us */
659 if (residue
&& !(us
->fflags
& US_FL_IGNORE_RESIDUE
))
662 /* Heuristically detect devices that generate bogus residues
663 * by seeing what happens with INQUIRY and READ CAPACITY
666 if (bcs
->Status
== US_BULK_STAT_OK
&&
667 scsi_get_resid(srb
) == 0 &&
668 ((srb
->cmnd
[0] == INQUIRY
&&
669 transfer_length
== 36) ||
670 (srb
->cmnd
[0] == READ_CAPACITY
&&
671 transfer_length
== 8)))
673 us
->fflags
|= US_FL_IGNORE_RESIDUE
;
678 residue
= min(residue
, transfer_length
);
679 scsi_set_resid(srb
, max(scsi_get_resid(srb
), (int) residue
));
683 /* based on the status code, we report good or bad */
686 case US_BULK_STAT_OK
:
689 memcpy(srb
->sense_buffer
, usb_stor_sense_invalidCDB
, sizeof(usb_stor_sense_invalidCDB
));
690 return USB_STOR_TRANSPORT_NO_SENSE
;
692 return USB_STOR_TRANSPORT_GOOD
;
694 case US_BULK_STAT_FAIL
:
695 return USB_STOR_TRANSPORT_FAILED
;
697 case US_BULK_STAT_PHASE
:
698 return USB_STOR_TRANSPORT_ERROR
;
700 return USB_STOR_TRANSPORT_ERROR
;
703 /***********************************************************************
705 ***********************************************************************/
706 //----- usb_stor_reset_common() ---------------------
707 static int usb_stor_reset_common(struct us_data
*us
,
708 u8 request
, u8 requesttype
,
709 u16 value
, u16 index
, void *data
, u16 size
)
714 //printk("transport --- usb_stor_reset_common\n");
715 if (test_bit(US_FLIDX_DISCONNECTING
, &us
->dflags
))
717 //printk("No reset during disconnect\n");
721 result
= usb_stor_control_msg(us
, us
->send_ctrl_pipe
, request
, requesttype
, value
, index
, data
, size
, 5*HZ
);
724 //printk("Soft reset failed: %d\n", result);
728 wait_event_interruptible_timeout(us
->delay_wait
, test_bit(US_FLIDX_DISCONNECTING
, &us
->dflags
), HZ
*6);
729 if (test_bit(US_FLIDX_DISCONNECTING
, &us
->dflags
))
731 //printk("Reset interrupted by disconnect\n");
735 //printk("Soft reset: clearing bulk-in endpoint halt\n");
736 result
= usb_stor_clear_halt(us
, us
->recv_bulk_pipe
);
738 //printk("Soft reset: clearing bulk-out endpoint halt\n");
739 result2
= usb_stor_clear_halt(us
, us
->send_bulk_pipe
);
741 /* return a result code based on the result of the clear-halts */
745 // printk("Soft reset failed\n");
747 // printk("Soft reset done\n");
751 //----- usb_stor_Bulk_reset() ---------------------
752 int usb_stor_Bulk_reset(struct us_data
*us
)
754 //printk("transport --- usb_stor_Bulk_reset\n");
755 return usb_stor_reset_common(us
, US_BULK_RESET_REQUEST
,
756 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
757 0, us
->ifnum
, NULL
, 0);
760 //----- usb_stor_port_reset() ---------------------
761 int usb_stor_port_reset(struct us_data
*us
)
765 //printk("transport --- usb_stor_port_reset\n");
766 result
= usb_lock_device_for_reset(us
->pusb_dev
, us
->pusb_intf
);
768 printk("unable to lock device for reset: %d\n", result
);
770 /* Were we disconnected while waiting for the lock? */
771 if (test_bit(US_FLIDX_DISCONNECTING
, &us
->dflags
)) {
773 //printk("No reset during disconnect\n");
775 result
= usb_reset_device(us
->pusb_dev
);
776 //printk("usb_reset_composite_device returns %d\n", result);
778 usb_unlock_device(us
->pusb_dev
);