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);
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);
466 int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
470 int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
488 int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
497 result = usb_stor_bulk_transfer_sglist(us, pipe,
503 result = usb_stor_bulk_transfer_buf(us, pipe, buf,
524 static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
544 if (!us->use_last_sector_hacks)
569 us->use_last_sector_hacks = 0;
581 if (++us->last_sector_retries < 3)
595 us->last_sector_retries = 0;
604 void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
611 result = us->transport(srb, us);
617 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
618 usb_stor_dbg(us, "-- command was aborted\n");
625 usb_stor_dbg(us, "-- transport indicates error, resetting\n");
633 last_sector_hacks(us, srb);
653 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
655 usb_stor_dbg(us, "-- CB transport device requiring auto-sense\n");
660 if ((us->fflags & US_FL_SENSE_AFTER_SYNC) &&
662 usb_stor_dbg(us, "-- sense after SYNC CACHE\n");
672 usb_stor_dbg(us, "-- transport indicates command failure\n");
684 !(us->fflags & US_FL_SANE_SENSE) &&
685 !(us->fflags & US_FL_BAD_SENSE) &&
687 usb_stor_dbg(us, "-- SAT supported, increasing auto-sense\n");
688 us->fflags |= US_FL_SANE_SENSE;
701 usb_stor_dbg(us, "-- unexpectedly short transfer\n");
714 if (us->fflags & US_FL_SANE_SENSE)
717 usb_stor_dbg(us, "Issuing auto-REQUEST_SENSE\n");
722 if (us->subclass == USB_SC_RBC || us->subclass == USB_SC_SCSI ||
723 us->subclass == USB_SC_CYP_ATACB)
730 temp_result = us->transport(us->srb, us);
735 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
736 usb_stor_dbg(us, "-- auto-sense aborted\n");
741 us->fflags &= ~US_FL_SANE_SENSE;
742 us->fflags |= US_FL_BAD_SENSE;
755 usb_stor_dbg(us, "-- auto-sense failure, retry small sense\n");
757 us->fflags &= ~US_FL_SANE_SENSE;
758 us->fflags |= US_FL_BAD_SENSE;
764 usb_stor_dbg(us, "-- auto-sense failure\n");
772 if (!(us->fflags & US_FL_SCM_MULT_TARG))
783 !(us->fflags & US_FL_SANE_SENSE) &&
784 !(us->fflags & US_FL_BAD_SENSE) &&
786 usb_stor_dbg(us, "-- SANE_SENSE support enabled\n");
787 us->fflags |= US_FL_SANE_SENSE;
793 usb_stor_dbg(us, "-- Sense data truncated to %i from %i\n",
802 usb_stor_dbg(us, "-- Result from auto-sense is %d\n",
804 usb_stor_dbg(us, "-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n",
808 usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
869 if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
872 set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
873 } else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
874 clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
875 set_bit(US_FLIDX_REDO_READ10, &us->dflags);
883 if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) {
884 clear_bit(US_FLIDX_REDO_READ10, &us->dflags);
895 last_sector_hacks(us, srb);
909 scsi_lock(us_to_host(us));
910 set_bit(US_FLIDX_RESETTING, &us->dflags);
911 clear_bit(US_FLIDX_ABORTING, &us->dflags);
912 scsi_unlock(us_to_host(us));
918 mutex_unlock(&us->dev_mutex);
919 result = usb_stor_port_reset(us);
920 mutex_lock(&us->dev_mutex);
923 scsi_lock(us_to_host(us));
924 usb_stor_report_device_reset(us);
925 scsi_unlock(us_to_host(us));
926 us->transport_reset(us);
928 clear_bit(US_FLIDX_RESETTING, &us->dflags);
929 last_sector_hacks(us, srb);
933 void usb_stor_stop_transport(struct us_data *us)
941 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
942 usb_stor_dbg(us, "-- cancelling URB\n");
943 usb_unlink_urb(us->current_urb);
947 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
948 usb_stor_dbg(us, "-- cancelling sg request\n");
949 usb_sg_cancel(&us->current_sg);
957 int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
967 * Stack may be vmallocated. So no DMA for us. Make a copy.
969 memcpy(us->iobuf, srb->cmnd, srb->cmd_len);
970 result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
973 us->ifnum, us->iobuf, srb->cmd_len);
976 usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n",
993 us->recv_bulk_pipe : us->send_bulk_pipe;
994 result = usb_stor_bulk_srb(us, pipe, srb);
995 usb_stor_dbg(us, "CBI data stage result is 0x%x\n", result);
1010 if (us->protocol != USB_PR_CBI)
1013 result = usb_stor_intr_transfer(us, us->iobuf, 2);
1014 usb_stor_dbg(us, "Got interrupt data (0x%x, 0x%x)\n",
1015 us->iobuf[0], us->iobuf[1]);
1020 * UFI gives us ASC and ASCQ, like a request sense
1027 if (us->subclass == USB_SC_UFI) {
1031 if (us->iobuf[0])
1043 if (us->iobuf[0]) {
1044 usb_stor_dbg(us, "CBI IRQ data showed reserved bType 0x%x\n",
1045 us->iobuf[0]);
1051 switch (us->iobuf[1] & 0x0F) {
1065 usb_stor_clear_halt(us, pipe);
1075 int usb_stor_Bulk_max_lun(struct us_data *us)
1080 us->iobuf[0] = 0;
1081 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
1085 0, us->ifnum, us->iobuf, 1, 10*HZ);
1087 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
1088 result, us->iobuf[0]);
1096 if (us->iobuf[0] < 16) {
1097 return us->iobuf[0];
1099 dev_info(&us->pusb_intf->dev,
1101 us->iobuf[0]);
1115 int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1117 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
1118 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
1127 if (unlikely(us->fflags & US_FL_BULK32)) {
1129 us->iobuf[31] = 0;
1137 bcb->Tag = ++us->tag;
1139 if (us->fflags & US_FL_SCM_MULT_TARG)
1148 usb_stor_dbg(us, "Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
1153 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
1155 usb_stor_dbg(us, "Bulk command transfer result=%d\n", result);
1163 * Some USB-IDE converter chips need a 100us delay between the
1167 if (unlikely(us->fflags & US_FL_GO_SLOW))
1172 us->recv_bulk_pipe : us->send_bulk_pipe;
1173 result = usb_stor_bulk_srb(us, pipe, srb);
1174 usb_stor_dbg(us, "Bulk data transfer result 0x%x\n", result);
1180 * amount requested, the spec requires us to transfer
1207 usb_stor_dbg(us, "Device skipped data phase\n");
1220 usb_stor_dbg(us, "Attempting to get CSW...\n");
1221 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1230 usb_stor_dbg(us, "Received 0-length CSW; retrying...\n");
1231 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1239 usb_stor_dbg(us, "Attempting to get CSW (2nd try)...\n");
1240 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1245 usb_stor_dbg(us, "Bulk status result = %d\n", result);
1252 usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1255 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
1257 usb_stor_dbg(us, "Bulk logical error\n");
1266 if (!us->bcs_signature) {
1267 us->bcs_signature = bcs->Signature;
1268 if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN))
1269 usb_stor_dbg(us, "Learnt BCS signature 0x%08X\n",
1270 le32_to_cpu(us->bcs_signature));
1271 } else if (bcs->Signature != us->bcs_signature) {
1272 usb_stor_dbg(us, "Signature mismatch: got %08X, expecting %08X\n",
1274 le32_to_cpu(us->bcs_signature));
1280 * was really transferred and what the device tells us
1282 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
1295 us->fflags |= US_FL_IGNORE_RESIDUE;
1347 static int usb_stor_reset_common(struct us_data *us,
1354 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1355 usb_stor_dbg(us, "No reset during disconnect\n");
1359 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
1363 usb_stor_dbg(us, "Soft reset failed: %d\n", result);
1371 wait_event_interruptible_timeout(us->delay_wait,
1372 test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
1374 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1375 usb_stor_dbg(us, "Reset interrupted by disconnect\n");
1379 usb_stor_dbg(us, "Soft reset: clearing bulk-in endpoint halt\n");
1380 result = usb_stor_clear_halt(us, us->recv_bulk_pipe);
1382 usb_stor_dbg(us, "Soft reset: clearing bulk-out endpoint halt\n");
1383 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
1389 usb_stor_dbg(us, "Soft reset failed\n");
1391 usb_stor_dbg(us, "Soft reset done\n");
1398 int usb_stor_CB_reset(struct us_data *us)
1400 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE);
1401 us->iobuf[0] = SEND_DIAGNOSTIC;
1402 us->iobuf[1] = 4;
1403 return usb_stor_reset_common(us, US_CBI_ADSC,
1405 0, us->ifnum, us->iobuf, CB_RESET_CMD_SIZE);
1413 int usb_stor_Bulk_reset(struct us_data *us)
1415 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
1417 0, us->ifnum, NULL, 0);
1423 * us->dev_mutex.
1425 int usb_stor_port_reset(struct us_data *us)
1430 if (us->pusb_dev->quirks & USB_QUIRK_RESET)
1433 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1435 usb_stor_dbg(us, "unable to lock device for reset: %d\n",
1439 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1441 usb_stor_dbg(us, "No reset during disconnect\n");
1443 result = usb_reset_device(us->pusb_dev);
1444 usb_stor_dbg(us, "usb_reset_device returns %d\n",
1447 usb_unlock_device(us->pusb_dev);