Lines Matching refs:us
67 * sets the machine state and the ABORTING bit in us->dflags to prevent
69 * below, which atomically tests-and-clears the URB_ACTIVE bit in us->dflags
74 * When a disconnect occurs, the DISCONNECTING bit in us->dflags is set to
98 * This is the completion handler which will wake us up when an URB
115 static int usb_stor_msg_common(struct us_data *us, int timeout)
122 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
129 us->current_urb->context = &urb_done;
130 us->current_urb->transfer_flags = 0;
133 * we assume that if transfer_buffer isn't us->iobuf then it
135 * easier than always having the caller tell us whether the
138 if (us->current_urb->transfer_buffer == us->iobuf)
139 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
140 us->current_urb->transfer_dma = us->iobuf_dma;
143 status = usb_submit_urb(us->current_urb, GFP_NOIO);
153 set_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
156 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
159 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
160 usb_stor_dbg(us, "-- cancelling URB\n");
161 usb_unlink_urb(us->current_urb);
169 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
172 usb_stor_dbg(us, "%s -- cancelling URB\n",
174 usb_kill_urb(us->current_urb);
178 return us->current_urb->status;
185 int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
191 usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
195 us->cr->bRequestType = requesttype;
196 us->cr->bRequest = request;
197 us->cr->wValue = cpu_to_le16(value);
198 us->cr->wIndex = cpu_to_le16(index);
199 us->cr->wLength = cpu_to_le16(size);
202 usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
203 (unsigned char*) us->cr, data, size,
205 status = usb_stor_msg_common(us, timeout);
209 status = us->current_urb->actual_length;
227 int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
235 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
241 usb_reset_endpoint(us->pusb_dev, endp);
243 usb_stor_dbg(us, "result = %d\n", result);
256 static int interpret_urb_result(struct us_data *us, unsigned int pipe,
259 usb_stor_dbg(us, "Status code %d; transferred %u/%u\n",
266 usb_stor_dbg(us, "-- short transfer\n");
270 usb_stor_dbg(us, "-- transfer complete\n");
280 usb_stor_dbg(us, "-- stall on control pipe\n");
285 usb_stor_dbg(us, "clearing endpoint halt for pipe 0x%x\n",
287 if (usb_stor_clear_halt(us, pipe) < 0)
293 usb_stor_dbg(us, "-- babble\n");
298 usb_stor_dbg(us, "-- transfer cancelled\n");
303 usb_stor_dbg(us, "-- short read transfer\n");
308 usb_stor_dbg(us, "-- abort or disconnect in progress\n");
313 usb_stor_dbg(us, "-- unknown error\n");
322 int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
328 usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
332 us->cr->bRequestType = requesttype;
333 us->cr->bRequest = request;
334 us->cr->wValue = cpu_to_le16(value);
335 us->cr->wIndex = cpu_to_le16(index);
336 us->cr->wLength = cpu_to_le16(size);
339 usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
340 (unsigned char*) us->cr, data, size,
342 result = usb_stor_msg_common(us, 0);
344 return interpret_urb_result(us, pipe, size, result,
345 us->current_urb->actual_length);
353 * This routine always uses us->recv_intr_pipe as the pipe and
354 * us->ep_bInterval as the interrupt interval.
356 static int usb_stor_intr_transfer(struct us_data *us, void *buf,
360 unsigned int pipe = us->recv_intr_pipe;
363 usb_stor_dbg(us, "xfer %u bytes\n", length);
366 maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe));
371 usb_fill_int_urb(us->current_urb, us->pusb_dev, pipe, buf,
373 us->ep_bInterval);
374 result = usb_stor_msg_common(us, 0);
376 return interpret_urb_result(us, pipe, length, result,
377 us->current_urb->actual_length);
385 int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
390 usb_stor_dbg(us, "xfer %u bytes\n", length);
393 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length,
395 result = usb_stor_msg_common(us, 0);
399 *act_len = us->current_urb->actual_length;
400 return interpret_urb_result(us, pipe, length, result,
401 us->current_urb->actual_length);
411 static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
418 if (test_bit(US_FLIDX_ABORTING, &us->dflags))
422 usb_stor_dbg(us, "xfer %u bytes, %d entries\n", length, num_sg);
423 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0,
426 usb_stor_dbg(us, "usb_sg_init returned %d\n", result);
434 set_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
437 if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
440 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
441 usb_stor_dbg(us, "-- cancelling sg request\n");
442 usb_sg_cancel(&us->current_sg);
447 usb_sg_wait(&us->current_sg);
448 clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
450 result = us->current_sg.status;
452 *act_len = us->current_sg.bytes;
453 return interpret_urb_result(us, pipe, length, result,
454 us->current_sg.bytes);
461 int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
465 int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
483 int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
492 result = usb_stor_bulk_transfer_sglist(us, pipe,
498 result = usb_stor_bulk_transfer_buf(us, pipe, buf,
519 static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
539 if (!us->use_last_sector_hacks)
564 us->use_last_sector_hacks = 0;
576 if (++us->last_sector_retries < 3)
590 us->last_sector_retries = 0;
599 void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
606 result = us->transport(srb, us);
612 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
613 usb_stor_dbg(us, "-- command was aborted\n");
620 usb_stor_dbg(us, "-- transport indicates error, resetting\n");
628 last_sector_hacks(us, srb);
648 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
650 usb_stor_dbg(us, "-- CB transport device requiring auto-sense\n");
655 if ((us->fflags & US_FL_SENSE_AFTER_SYNC) &&
657 usb_stor_dbg(us, "-- sense after SYNC CACHE\n");
667 usb_stor_dbg(us, "-- transport indicates command failure\n");
679 !(us->fflags & US_FL_SANE_SENSE) &&
680 !(us->fflags & US_FL_BAD_SENSE) &&
682 usb_stor_dbg(us, "-- SAT supported, increasing auto-sense\n");
683 us->fflags |= US_FL_SANE_SENSE;
696 usb_stor_dbg(us, "-- unexpectedly short transfer\n");
709 if (us->fflags & US_FL_SANE_SENSE)
712 usb_stor_dbg(us, "Issuing auto-REQUEST_SENSE\n");
717 if (us->subclass == USB_SC_RBC || us->subclass == USB_SC_SCSI ||
718 us->subclass == USB_SC_CYP_ATACB)
725 temp_result = us->transport(us->srb, us);
730 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
731 usb_stor_dbg(us, "-- auto-sense aborted\n");
736 us->fflags &= ~US_FL_SANE_SENSE;
737 us->fflags |= US_FL_BAD_SENSE;
750 usb_stor_dbg(us, "-- auto-sense failure, retry small sense\n");
752 us->fflags &= ~US_FL_SANE_SENSE;
753 us->fflags |= US_FL_BAD_SENSE;
759 usb_stor_dbg(us, "-- auto-sense failure\n");
767 if (!(us->fflags & US_FL_SCM_MULT_TARG))
778 !(us->fflags & US_FL_SANE_SENSE) &&
779 !(us->fflags & US_FL_BAD_SENSE) &&
781 usb_stor_dbg(us, "-- SANE_SENSE support enabled\n");
782 us->fflags |= US_FL_SANE_SENSE;
788 usb_stor_dbg(us, "-- Sense data truncated to %i from %i\n",
797 usb_stor_dbg(us, "-- Result from auto-sense is %d\n",
799 usb_stor_dbg(us, "-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n",
803 usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
864 if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
867 set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
868 } else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
869 clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
870 set_bit(US_FLIDX_REDO_READ10, &us->dflags);
878 if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) {
879 clear_bit(US_FLIDX_REDO_READ10, &us->dflags);
890 last_sector_hacks(us, srb);
904 scsi_lock(us_to_host(us));
905 set_bit(US_FLIDX_RESETTING, &us->dflags);
906 clear_bit(US_FLIDX_ABORTING, &us->dflags);
907 scsi_unlock(us_to_host(us));
913 mutex_unlock(&us->dev_mutex);
914 result = usb_stor_port_reset(us);
915 mutex_lock(&us->dev_mutex);
918 scsi_lock(us_to_host(us));
919 usb_stor_report_device_reset(us);
920 scsi_unlock(us_to_host(us));
921 us->transport_reset(us);
923 clear_bit(US_FLIDX_RESETTING, &us->dflags);
924 last_sector_hacks(us, srb);
928 void usb_stor_stop_transport(struct us_data *us)
936 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
937 usb_stor_dbg(us, "-- cancelling URB\n");
938 usb_unlink_urb(us->current_urb);
942 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
943 usb_stor_dbg(us, "-- cancelling sg request\n");
944 usb_sg_cancel(&us->current_sg);
952 int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
962 * Stack may be vmallocated. So no DMA for us. Make a copy.
964 memcpy(us->iobuf, srb->cmnd, srb->cmd_len);
965 result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
968 us->ifnum, us->iobuf, srb->cmd_len);
971 usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n",
988 us->recv_bulk_pipe : us->send_bulk_pipe;
989 result = usb_stor_bulk_srb(us, pipe, srb);
990 usb_stor_dbg(us, "CBI data stage result is 0x%x\n", result);
1005 if (us->protocol != USB_PR_CBI)
1008 result = usb_stor_intr_transfer(us, us->iobuf, 2);
1009 usb_stor_dbg(us, "Got interrupt data (0x%x, 0x%x)\n",
1010 us->iobuf[0], us->iobuf[1]);
1015 * UFI gives us ASC and ASCQ, like a request sense
1022 if (us->subclass == USB_SC_UFI) {
1026 if (us->iobuf[0])
1038 if (us->iobuf[0]) {
1039 usb_stor_dbg(us, "CBI IRQ data showed reserved bType 0x%x\n",
1040 us->iobuf[0]);
1046 switch (us->iobuf[1] & 0x0F) {
1060 usb_stor_clear_halt(us, pipe);
1070 int usb_stor_Bulk_max_lun(struct us_data *us)
1075 us->iobuf[0] = 0;
1076 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
1080 0, us->ifnum, us->iobuf, 1, 10*HZ);
1082 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
1083 result, us->iobuf[0]);
1091 if (us->iobuf[0] < 16) {
1092 return us->iobuf[0];
1094 dev_info(&us->pusb_intf->dev,
1096 us->iobuf[0]);
1110 int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1112 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
1113 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
1122 if (unlikely(us->fflags & US_FL_BULK32)) {
1124 us->iobuf[31] = 0;
1132 bcb->Tag = ++us->tag;
1134 if (us->fflags & US_FL_SCM_MULT_TARG)
1143 usb_stor_dbg(us, "Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
1148 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
1150 usb_stor_dbg(us, "Bulk command transfer result=%d\n", result);
1158 * Some USB-IDE converter chips need a 100us delay between the
1162 if (unlikely(us->fflags & US_FL_GO_SLOW))
1167 us->recv_bulk_pipe : us->send_bulk_pipe;
1168 result = usb_stor_bulk_srb(us, pipe, srb);
1169 usb_stor_dbg(us, "Bulk data transfer result 0x%x\n", result);
1175 * amount requested, the spec requires us to transfer
1202 usb_stor_dbg(us, "Device skipped data phase\n");
1215 usb_stor_dbg(us, "Attempting to get CSW...\n");
1216 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1225 usb_stor_dbg(us, "Received 0-length CSW; retrying...\n");
1226 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1234 usb_stor_dbg(us, "Attempting to get CSW (2nd try)...\n");
1235 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1240 usb_stor_dbg(us, "Bulk status result = %d\n", result);
1247 usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1250 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
1252 usb_stor_dbg(us, "Bulk logical error\n");
1261 if (!us->bcs_signature) {
1262 us->bcs_signature = bcs->Signature;
1263 if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN))
1264 usb_stor_dbg(us, "Learnt BCS signature 0x%08X\n",
1265 le32_to_cpu(us->bcs_signature));
1266 } else if (bcs->Signature != us->bcs_signature) {
1267 usb_stor_dbg(us, "Signature mismatch: got %08X, expecting %08X\n",
1269 le32_to_cpu(us->bcs_signature));
1275 * was really transferred and what the device tells us
1277 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
1290 us->fflags |= US_FL_IGNORE_RESIDUE;
1342 static int usb_stor_reset_common(struct us_data *us,
1349 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1350 usb_stor_dbg(us, "No reset during disconnect\n");
1354 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
1358 usb_stor_dbg(us, "Soft reset failed: %d\n", result);
1366 wait_event_interruptible_timeout(us->delay_wait,
1367 test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
1369 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1370 usb_stor_dbg(us, "Reset interrupted by disconnect\n");
1374 usb_stor_dbg(us, "Soft reset: clearing bulk-in endpoint halt\n");
1375 result = usb_stor_clear_halt(us, us->recv_bulk_pipe);
1377 usb_stor_dbg(us, "Soft reset: clearing bulk-out endpoint halt\n");
1378 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
1384 usb_stor_dbg(us, "Soft reset failed\n");
1386 usb_stor_dbg(us, "Soft reset done\n");
1393 int usb_stor_CB_reset(struct us_data *us)
1395 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE);
1396 us->iobuf[0] = SEND_DIAGNOSTIC;
1397 us->iobuf[1] = 4;
1398 return usb_stor_reset_common(us, US_CBI_ADSC,
1400 0, us->ifnum, us->iobuf, CB_RESET_CMD_SIZE);
1408 int usb_stor_Bulk_reset(struct us_data *us)
1410 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
1412 0, us->ifnum, NULL, 0);
1418 * us->dev_mutex.
1420 int usb_stor_port_reset(struct us_data *us)
1425 if (us->pusb_dev->quirks & USB_QUIRK_RESET)
1428 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1430 usb_stor_dbg(us, "unable to lock device for reset: %d\n",
1434 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1436 usb_stor_dbg(us, "No reset during disconnect\n");
1438 result = usb_reset_device(us->pusb_dev);
1439 usb_stor_dbg(us, "usb_reset_device returns %d\n",
1442 usb_unlock_device(us->pusb_dev);