drivers/net/phy/phy_port.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/phy_port.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/phy_port.c- Extension
.c- Size
- 5850 bytes
- Lines
- 218
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- 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/linkmode.hlinux/of.hlinux/phy_port.hphy-caps.h
Detected Declarations
function Copyrightfunction phy_port_destroyfunction phy_of_parse_portfunction phy_port_update_supportedfunction for_each_set_bitfunction phy_port_filter_supportedfunction phy_port_restrict_mediumsfunction phy_port_get_typeexport phy_port_allocexport phy_port_destroyexport phy_of_parse_portexport phy_port_update_supportedexport phy_port_restrict_mediumsexport phy_port_get_type
Annotated Snippet
switch (pairs) {
case 1: /* BaseT1 */
case 2: /* 100BaseTX */
case 4:
break;
default:
pr_err("%u is not a valid number of pairs\n", pairs);
return ERR_PTR(-EINVAL);
}
}
if (pairs && medium != ETHTOOL_LINK_MEDIUM_BASET) {
pr_err("pairs property is only compatible with BaseT medium\n");
return ERR_PTR(-EINVAL);
}
port = phy_port_alloc();
if (!port)
return ERR_PTR(-ENOMEM);
port->pairs = pairs;
port->mediums = BIT(medium);
return port;
}
EXPORT_SYMBOL_GPL(phy_of_parse_port);
/**
* phy_port_update_supported() - Setup the port->supported field
* @port: the port to update
*
* Once the port's medium list and number of pairs has been configured based
* on firmware, straps and vendor-specific properties, this function may be
* called to update the port's supported linkmodes list.
*
* Any mode that was manually set in the port's supported list remains set.
*/
void phy_port_update_supported(struct phy_port *port)
{
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = {0};
unsigned long mode;
int i;
/* If there's no pairs specified, we grab the default number of
* pairs as the max of the default pairs for each linkmode
*/
if (!port->pairs)
for_each_set_bit(mode, port->supported,
__ETHTOOL_LINK_MODE_MASK_NBITS)
port->pairs = max_t(int, port->pairs,
ethtool_linkmode_n_pairs(mode));
for_each_set_bit(i, &port->mediums, __ETHTOOL_LINK_MEDIUM_LAST) {
__ETHTOOL_DECLARE_LINK_MODE_MASK(med_supported) = {0};
phy_caps_medium_get_supported(med_supported, i, port->pairs);
linkmode_or(supported, supported, med_supported);
}
/* If port->supported is already populated, filter it out with the
* medium/pair support. Otherwise, let's just use this medium-based
* support as the port's supported list.
*/
if (linkmode_empty(port->supported))
linkmode_copy(port->supported, supported);
else
linkmode_and(port->supported, supported, port->supported);
/* Serdes ports supported through SFP may not have any medium set,
* as they will output PHY_INTERFACE_MODE_XXX modes. In that case, derive
* the supported list based on these interfaces
*/
if (port->is_mii && !port->mediums) {
unsigned long interface, link_caps = 0;
/* Get each interface's caps */
for_each_set_bit(interface, port->interfaces,
PHY_INTERFACE_MODE_MAX)
link_caps |= phy_caps_from_interface(interface);
phy_caps_linkmodes(link_caps, port->supported);
}
}
EXPORT_SYMBOL_GPL(phy_port_update_supported);
/**
* phy_port_filter_supported() - Make sure that port->supported match port->mediums
* @port: The port to filter
*
* After updating a port's mediums to a more restricted subset, this helper will
Annotation
- Immediate include surface: `linux/linkmode.h`, `linux/of.h`, `linux/phy_port.h`, `phy-caps.h`.
- Detected declarations: `function Copyright`, `function phy_port_destroy`, `function phy_of_parse_port`, `function phy_port_update_supported`, `function for_each_set_bit`, `function phy_port_filter_supported`, `function phy_port_restrict_mediums`, `function phy_port_get_type`, `export phy_port_alloc`, `export phy_port_destroy`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
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.