drivers/net/phy/sfp-bus.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/sfp-bus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/sfp-bus.c- Extension
.c- Size
- 23281 bytes
- Lines
- 866
- Domain
- Driver Families
- Bucket
- drivers/net
- 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/export.hlinux/kref.hlinux/list.hlinux/mutex.hlinux/phylink.hlinux/property.hlinux/rtnetlink.hlinux/slab.hsfp.h
Detected Declarations
struct sfp_busfunction sfp_module_parse_portfunction sfp_module_parse_may_have_phyfunction sfp_module_parse_supportfunction sfp_init_modulefunction sfp_select_interfacefunction list_for_each_entryfunction sfp_bus_releasefunction sfp_bus_putfunction sfp_register_busfunction sfp_unregister_busfunction sfp_get_module_infofunction sfp_get_module_eepromfunction sfp_get_module_eeprom_by_pagefunction sfp_upstream_startfunction sfp_upstream_stopfunction sfp_upstream_clearfunction sfp_upstream_set_signal_ratefunction sfp_bus_find_fwnodefunction sfp_bus_add_upstreamfunction sfp_bus_del_upstreamfunction sfp_get_namefunction sfp_add_phyfunction sfp_remove_phyfunction sfp_link_upfunction sfp_link_downfunction sfp_module_insertfunction sfp_module_removefunction sfp_module_startfunction sfp_module_stopfunction sfp_socket_clearfunction sfp_unregister_socketexport sfp_get_module_capsexport sfp_select_interfaceexport sfp_bus_putexport sfp_get_module_infoexport sfp_get_module_eepromexport sfp_get_module_eeprom_by_pageexport sfp_upstream_startexport sfp_upstream_stopexport sfp_upstream_set_signal_rateexport sfp_bus_find_fwnodeexport sfp_bus_add_upstreamexport sfp_bus_del_upstreamexport sfp_get_nameexport sfp_add_phyexport sfp_remove_phyexport sfp_link_up
Annotated Snippet
* should be called from the network device driver's &struct net_device_ops
* ndo_open() method.
*/
void sfp_upstream_start(struct sfp_bus *bus)
{
if (bus->registered)
bus->socket_ops->start(bus->sfp);
bus->started = true;
}
EXPORT_SYMBOL_GPL(sfp_upstream_start);
/**
* sfp_upstream_stop() - Inform the SFP that the network device is down
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
*
* Inform the SFP socket that the network device is now up, so that the
* module can be disabled by asserting TX_DISABLE, disabling the laser
* in optical modules. This should be called from the network device
* driver's &struct net_device_ops ndo_stop() method.
*/
void sfp_upstream_stop(struct sfp_bus *bus)
{
if (bus->registered)
bus->socket_ops->stop(bus->sfp);
bus->started = false;
}
EXPORT_SYMBOL_GPL(sfp_upstream_stop);
static void sfp_upstream_clear(struct sfp_bus *bus)
{
bus->upstream_ops = NULL;
bus->upstream = NULL;
}
/**
* sfp_upstream_set_signal_rate() - set data signalling rate
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
* @rate_kbd: signalling rate in units of 1000 baud
*
* Configure the rate select settings on the SFP module for the signalling
* rate (not the same as the data rate).
*
* Locks that may be held:
* Phylink's state_mutex
* rtnl lock
* SFP's sm_mutex
*/
void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd)
{
if (bus->registered)
bus->socket_ops->set_signal_rate(bus->sfp, rate_kbd);
}
EXPORT_SYMBOL_GPL(sfp_upstream_set_signal_rate);
/**
* sfp_bus_find_fwnode() - parse and locate the SFP bus from fwnode
* @fwnode: firmware node for the parent device (MAC or PHY)
*
* Parse the parent device's firmware node for a SFP bus, and locate
* the sfp_bus structure, incrementing its reference count. This must
* be put via sfp_bus_put() when done.
*
* Returns:
* - on success, a pointer to the sfp_bus structure,
* - %NULL if no SFP is specified,
* - on failure, an error pointer value:
*
* - corresponding to the errors detailed for
* fwnode_property_get_reference_args().
* - %-ENOMEM if we failed to allocate the bus.
* - an error from the upstream's connect_phy() method.
*/
struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode)
{
struct fwnode_reference_args ref;
struct sfp_bus *bus;
int ret;
ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
0, 0, &ref);
if (ret == -ENOENT)
return NULL;
else if (ret < 0)
return ERR_PTR(ret);
if (!fwnode_device_is_available(ref.fwnode)) {
fwnode_handle_put(ref.fwnode);
return NULL;
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/kref.h`, `linux/list.h`, `linux/mutex.h`, `linux/phylink.h`, `linux/property.h`, `linux/rtnetlink.h`, `linux/slab.h`.
- Detected declarations: `struct sfp_bus`, `function sfp_module_parse_port`, `function sfp_module_parse_may_have_phy`, `function sfp_module_parse_support`, `function sfp_init_module`, `function sfp_select_interface`, `function list_for_each_entry`, `function sfp_bus_release`, `function sfp_bus_put`, `function sfp_register_bus`.
- Atlas domain: Driver Families / drivers/net.
- 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.