drivers/usb/core/port.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/port.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/port.c- Extension
.c- Size
- 21944 bytes
- Lines
- 865
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/kstrtox.hlinux/slab.hlinux/string_choices.hlinux/sysfs.hlinux/pm_qos.hlinux/component.hlinux/usb/of.hhub.h
Detected Declarations
function usb_port_allow_power_offfunction early_stop_showfunction early_stop_storefunction disable_showfunction disable_storefunction location_showfunction connect_type_showfunction state_showfunction over_current_count_showfunction quirks_showfunction quirks_storefunction usb3_lpm_permit_showfunction usb3_lpm_permit_storefunction usb_port_device_releasefunction usb_port_runtime_resumefunction recoveryfunction usb_port_runtime_suspendfunction usb_port_shutdownfunction link_peersfunction link_peers_reportfunction unlink_peersfunction usb_port_runtime_resumefunction match_locationfunction find_and_link_peerfunction connector_bindfunction connector_unbindfunction usb_hub_create_port_devicefunction usb_hub_remove_port_device
Annotated Snippet
static struct device_driver usb_port_driver = {
.name = "usb",
.owner = THIS_MODULE,
.shutdown = usb_port_shutdown,
};
static int link_peers(struct usb_port *left, struct usb_port *right)
{
struct usb_port *ss_port, *hs_port;
int rc;
if (left->peer == right && right->peer == left)
return 0;
if (left->peer || right->peer) {
struct usb_port *lpeer = left->peer;
struct usb_port *rpeer = right->peer;
char *method;
if (left->location && left->location == right->location)
method = "location";
else
method = "default";
pr_debug("usb: failed to peer %s and %s by %s (%s:%s) (%s:%s)\n",
dev_name(&left->dev), dev_name(&right->dev), method,
dev_name(&left->dev),
lpeer ? dev_name(&lpeer->dev) : "none",
dev_name(&right->dev),
rpeer ? dev_name(&rpeer->dev) : "none");
return -EBUSY;
}
rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer");
if (rc)
return rc;
rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer");
if (rc) {
sysfs_remove_link(&left->dev.kobj, "peer");
return rc;
}
/*
* We need to wake the HiSpeed port to make sure we don't race
* setting ->peer with usb_port_runtime_suspend(). Otherwise we
* may miss a suspend event for the SuperSpeed port.
*/
if (left->is_superspeed) {
ss_port = left;
WARN_ON(right->is_superspeed);
hs_port = right;
} else {
ss_port = right;
WARN_ON(!right->is_superspeed);
hs_port = left;
}
pm_runtime_get_sync(&hs_port->dev);
left->peer = right;
right->peer = left;
/*
* The SuperSpeed reference is dropped when the HiSpeed port in
* this relationship suspends, i.e. when it is safe to allow a
* SuperSpeed connection to drop since there is no risk of a
* device degrading to its powered-off HiSpeed connection.
*
* Also, drop the HiSpeed ref taken above.
*/
pm_runtime_get_sync(&ss_port->dev);
pm_runtime_put(&hs_port->dev);
return 0;
}
static void link_peers_report(struct usb_port *left, struct usb_port *right)
{
int rc;
rc = link_peers(left, right);
if (rc == 0) {
dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev));
} else {
dev_dbg(&left->dev, "failed to peer to %s (%d)\n",
dev_name(&right->dev), rc);
pr_warn_once("usb: port power management may be unreliable\n");
usb_port_block_power_off = 1;
}
}
Annotation
- Immediate include surface: `linux/kstrtox.h`, `linux/slab.h`, `linux/string_choices.h`, `linux/sysfs.h`, `linux/pm_qos.h`, `linux/component.h`, `linux/usb/of.h`, `hub.h`.
- Detected declarations: `function usb_port_allow_power_off`, `function early_stop_show`, `function early_stop_store`, `function disable_show`, `function disable_store`, `function location_show`, `function connect_type_show`, `function state_show`, `function over_current_count_show`, `function quirks_show`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern 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.