drivers/usb/storage/transport.c
Source file repositories/reference/linux-study-clean/drivers/usb/storage/transport.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/storage/transport.c- Extension
.c- Size
- 45105 bytes
- Lines
- 1463
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/gfp.hlinux/errno.hlinux/export.hlinux/usb/quirks.hscsi/scsi.hscsi/scsi_eh.hscsi/scsi_device.husb.htransport.hprotocol.hscsiglue.hdebug.hlinux/blkdev.h../../scsi/sd.h
Detected Declarations
function functionfunction functionfunction usb_stor_control_msgfunction usb_clear_haltfunction interpret_urb_resultfunction usb_stor_ctrl_transferfunction usb_stor_intr_transferfunction usb_stor_bulk_transfer_buffunction usb_stor_bulk_transfer_buffunction usb_stor_bulk_transfer_sglistfunction usb_stor_bulk_transfer_buffunction last_sector_hacksfunction usb_stor_invoke_transportfunction READfunction READfunction usb_stor_stop_transportfunction usb_stor_CB_transportfunction usb_stor_Bulk_max_lunfunction usb_stor_Bulk_transportfunction usb_stor_reset_commonfunction usb_stor_CB_resetfunction usb_stor_Bulk_resetfunction usb_stor_port_resetexport usb_stor_control_msgexport usb_stor_clear_haltexport usb_stor_ctrl_transferexport usb_stor_bulk_transfer_bufexport usb_stor_bulk_srbexport usb_stor_bulk_transfer_sgexport usb_stor_CB_transportexport usb_stor_Bulk_transportexport usb_stor_CB_resetexport usb_stor_Bulk_reset
Annotated Snippet
if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
usb_stor_dbg(us, "-- cancelling URB\n");
usb_unlink_urb(us->current_urb);
}
}
/* wait for the completion of the URB */
timeleft = wait_for_completion_interruptible_timeout(
&urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT);
clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
if (timeleft <= 0) {
usb_stor_dbg(us, "%s -- cancelling URB\n",
timeleft == 0 ? "Timeout" : "Signal");
usb_kill_urb(us->current_urb);
}
/* return the URB status */
return us->current_urb->status;
}
/*
* Transfer one control message, with timeouts, and allowing early
* termination. Return codes are usual -Exxx, *not* USB_STOR_XFER_xxx.
*/
int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
u8 request, u8 requesttype, u16 value, u16 index,
void *data, u16 size, int timeout)
{
int status;
usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
request, requesttype, value, index, size);
/* fill in the devrequest structure */
us->cr->bRequestType = requesttype;
us->cr->bRequest = request;
us->cr->wValue = cpu_to_le16(value);
us->cr->wIndex = cpu_to_le16(index);
us->cr->wLength = cpu_to_le16(size);
/* fill and submit the URB */
usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
(unsigned char*) us->cr, data, size,
usb_stor_blocking_completion, NULL);
status = usb_stor_msg_common(us, timeout);
/* return the actual length of the data transferred if no error */
if (status == 0)
status = us->current_urb->actual_length;
return status;
}
EXPORT_SYMBOL_GPL(usb_stor_control_msg);
/*
* This is a version of usb_clear_halt() that allows early termination and
* doesn't read the status from the device -- this is because some devices
* crash their internal firmware when the status is requested after a halt.
*
* A definitive list of these 'bad' devices is too difficult to maintain or
* make complete enough to be useful. This problem was first observed on the
* Hagiwara FlashGate DUAL unit. However, bus traces reveal that neither
* MacOS nor Windows checks the status after clearing a halt.
*
* Since many vendors in this space limit their testing to interoperability
* with these two OSes, specification violations like this one are common.
*/
int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
{
int result;
int endp = usb_pipeendpoint(pipe);
if (usb_pipein (pipe))
endp |= USB_DIR_IN;
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT,
USB_ENDPOINT_HALT, endp,
NULL, 0, 3*HZ);
if (result >= 0)
usb_reset_endpoint(us->pusb_dev, endp);
usb_stor_dbg(us, "result = %d\n", result);
return result;
}
EXPORT_SYMBOL_GPL(usb_stor_clear_halt);
Annotation
- Immediate include surface: `linux/sched.h`, `linux/gfp.h`, `linux/errno.h`, `linux/export.h`, `linux/usb/quirks.h`, `scsi/scsi.h`, `scsi/scsi_eh.h`, `scsi/scsi_device.h`.
- Detected declarations: `function function`, `function function`, `function usb_stor_control_msg`, `function usb_clear_halt`, `function interpret_urb_result`, `function usb_stor_ctrl_transfer`, `function usb_stor_intr_transfer`, `function usb_stor_bulk_transfer_buf`, `function usb_stor_bulk_transfer_buf`, `function usb_stor_bulk_transfer_sglist`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.