drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c- Extension
.c- Size
- 236092 bytes
- Lines
- 8436
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/circ_buf.hlinux/clk.hlinux/kernel.hlinux/interrupt.hlinux/ip.hlinux/tcp.hlinux/skbuff.hlinux/ethtool.hlinux/if_ether.hlinux/crc32.hlinux/mii.hlinux/if.hlinux/if_vlan.hlinux/dma-mapping.hlinux/slab.hlinux/pm_runtime.hlinux/pm_wakeirq.hlinux/prefetch.hlinux/pinctrl/consumer.hlinux/debugfs.hlinux/seq_file.hlinux/net_tstamp.hlinux/phylink.hlinux/udp.hlinux/bpf_trace.hnet/devlink.hnet/page_pool/helpers.hnet/pkt_cls.hnet/xdp_sock_drv.hstmmac_ptp.hstmmac_fpe.hstmmac.h
Detected Declarations
struct stmmac_devlink_privenum stmmac_dl_param_idfunction stmmac_set_clk_tx_ratefunction stmmac_axi_blen_to_maskfunction stmmac_verify_argsfunction __stmmac_disable_all_queuesfunction stmmac_disable_all_queuesfunction stmmac_enable_all_queuesfunction stmmac_service_event_schedulefunction stmmac_global_errfunction print_pktfunction stmmac_tx_availfunction stmmac_get_tx_desc_sizefunction stmmac_set_queue_tx_tail_ptrfunction stmmac_get_rx_desc_sizefunction stmmac_set_queue_rx_tail_ptrfunction stmmac_set_queue_rx_buf_sizefunction stmmac_rx_dirtyfunction stmmac_eee_tx_busyfunction stmmac_restart_sw_lpi_timerfunction stmmac_try_to_start_sw_lpifunction stmmac_stop_sw_lpifunction stmmac_eee_ctrl_timerfunction stmmac_get_tx_hwtstampfunction stmmac_get_rx_hwtstampfunction stmmac_update_subsecond_incrementfunction incomingfunction stmmac_hwtstamp_getfunction stmmac_hwtstamp_setfunction stmmac_init_timestampingfunction stmmac_setup_ptpfunction stmmac_release_ptpfunction stmmac_legacy_serdes_power_downfunction stmmac_legacy_serdes_power_upfunction stmmac_mac_flow_ctrlfunction stmmac_mac_get_capsfunction stmmac_mac_configfunction stmmac_mac_link_downfunction stmmac_mac_link_upfunction stmmac_mac_disable_tx_lpifunction stmmac_mac_enable_tx_lpifunction stmmac_mac_wol_setfunction Sublayerfunction stmmac_init_phyfunction stmmac_phylink_setupfunction stmmac_display_rx_ringsfunction stmmac_display_tx_ringsfunction stmmac_display_rings
Annotated Snippet
static const struct net_device_ops stmmac_netdev_ops;
static void stmmac_init_fs(struct net_device *dev);
static void stmmac_exit_fs(struct net_device *dev);
#endif
#define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC))
struct stmmac_devlink_priv {
struct stmmac_priv *stmmac_priv;
};
enum stmmac_dl_param_id {
STMMAC_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
STMMAC_DEVLINK_PARAM_ID_TS_COARSE,
};
/**
* stmmac_set_clk_tx_rate() - set the clock rate for the MAC transmit clock
* @bsp_priv: BSP private data structure (unused)
* @clk_tx_i: the transmit clock
* @interface: the selected interface mode
* @speed: the speed that the MAC will be operating at
*
* Set the transmit clock rate for the MAC, normally 2.5MHz for 10Mbps,
* 25MHz for 100Mbps and 125MHz for 1Gbps. This is suitable for at least
* MII, GMII, RGMII and RMII interface modes. Platforms can hook this into
* the plat_data->set_clk_tx_rate method directly, call it via their own
* implementation, or implement their own method should they have more
* complex requirements. It is intended to only be used in this method.
*
* plat_data->clk_tx_i must be filled in.
*/
int stmmac_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i,
phy_interface_t interface, int speed)
{
long rate = rgmii_clock(speed);
/* Silently ignore unsupported speeds as rgmii_clock() only
* supports 10, 100 and 1000Mbps. We do not want to spit
* errors for 2500 and higher speeds here.
*/
if (rate < 0)
return 0;
return clk_set_rate(clk_tx_i, rate);
}
EXPORT_SYMBOL_GPL(stmmac_set_clk_tx_rate);
/**
* stmmac_axi_blen_to_mask() - convert a burst length array to reg value
* @regval: pointer to a u32 for the resulting register value
* @blen: pointer to an array of u32 containing the burst length values in bytes
* @len: the number of entries in the @blen array
*/
void stmmac_axi_blen_to_mask(u32 *regval, const u32 *blen, size_t len)
{
size_t i;
u32 val;
for (val = i = 0; i < len; i++) {
u32 burst = blen[i];
/* Burst values of zero must be skipped. */
if (!burst)
continue;
/* The valid range for the burst length is 4 to 256 inclusive,
* and it must be a power of two.
*/
if (burst < 4 || burst > 256 || !is_power_of_2(burst)) {
pr_err("stmmac: invalid burst length %u at index %zu\n",
burst, i);
continue;
}
/* Since burst is a power of two, and the register field starts
* with burst = 4, shift right by two bits so bit 0 of the field
* corresponds with the minimum value.
*/
val |= burst >> 2;
}
*regval = FIELD_PREP(DMA_AXI_BLEN_MASK, val);
}
EXPORT_SYMBOL_GPL(stmmac_axi_blen_to_mask);
/**
* stmmac_verify_args - verify the driver parameters.
* Description: it checks the driver parameters and set a default in case of
* errors.
Annotation
- Immediate include surface: `linux/circ_buf.h`, `linux/clk.h`, `linux/kernel.h`, `linux/interrupt.h`, `linux/ip.h`, `linux/tcp.h`, `linux/skbuff.h`, `linux/ethtool.h`.
- Detected declarations: `struct stmmac_devlink_priv`, `enum stmmac_dl_param_id`, `function stmmac_set_clk_tx_rate`, `function stmmac_axi_blen_to_mask`, `function stmmac_verify_args`, `function __stmmac_disable_all_queues`, `function stmmac_disable_all_queues`, `function stmmac_enable_all_queues`, `function stmmac_service_event_schedule`, `function stmmac_global_err`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.