drivers/net/ethernet/hisilicon/hisi_femac.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/hisilicon/hisi_femac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/hisilicon/hisi_femac.c- Extension
.c- Size
- 24161 bytes
- Lines
- 975
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/circ_buf.hlinux/clk.hlinux/etherdevice.hlinux/interrupt.hlinux/module.hlinux/of_mdio.hlinux/of_net.hlinux/platform_device.hlinux/reset.h
Detected Declarations
struct hisi_femac_queuestruct hisi_femac_privenum phy_reset_delaysfunction hisi_femac_irq_enablefunction hisi_femac_irq_disablefunction hisi_femac_tx_dma_unmapfunction hisi_femac_xmit_reclaimfunction hisi_femac_adjust_linkfunction hisi_femac_rx_refillfunction hisi_femac_rxfunction hisi_femac_pollfunction hisi_femac_interruptfunction hisi_femac_init_queuefunction hisi_femac_init_tx_and_rx_queuesfunction hisi_femac_free_skb_ringsfunction hisi_femac_set_hw_mac_addrfunction hisi_femac_port_resetfunction hisi_femac_net_openfunction hisi_femac_net_closefunction hisi_femac_net_xmitfunction hisi_femac_set_mac_addressfunction hisi_femac_enable_hw_addr_filterfunction hisi_femac_set_hw_addr_filterfunction hisi_femac_set_promisc_modefunction hisi_femac_set_mc_addr_filterfunction netdev_for_each_mc_addrfunction hisi_femac_set_uc_addr_filterfunction netdev_for_each_uc_addrfunction hisi_femac_net_set_rx_modefunction hisi_femac_core_resetfunction hisi_femac_sleep_usfunction hisi_femac_phy_resetfunction hisi_femac_port_initfunction hisi_femac_drv_probefunction hisi_femac_drv_removefunction hisi_femac_drv_suspendfunction hisi_femac_drv_resume
Annotated Snippet
static const struct net_device_ops hisi_femac_netdev_ops = {
.ndo_open = hisi_femac_net_open,
.ndo_stop = hisi_femac_net_close,
.ndo_start_xmit = hisi_femac_net_xmit,
.ndo_eth_ioctl = phy_do_ioctl_running,
.ndo_set_mac_address = hisi_femac_set_mac_address,
.ndo_set_rx_mode = hisi_femac_net_set_rx_mode,
};
static void hisi_femac_core_reset(struct hisi_femac_priv *priv)
{
reset_control_assert(priv->mac_rst);
reset_control_deassert(priv->mac_rst);
}
static void hisi_femac_sleep_us(u32 time_us)
{
u32 time_ms;
if (!time_us)
return;
time_ms = DIV_ROUND_UP(time_us, 1000);
if (time_ms < 20)
usleep_range(time_us, time_us + 500);
else
msleep(time_ms);
}
static void hisi_femac_phy_reset(struct hisi_femac_priv *priv)
{
/* To make sure PHY hardware reset success,
* we must keep PHY in deassert state first and
* then complete the hardware reset operation
*/
reset_control_deassert(priv->phy_rst);
hisi_femac_sleep_us(priv->phy_reset_delays[PRE_DELAY]);
reset_control_assert(priv->phy_rst);
/* delay some time to ensure reset ok,
* this depends on PHY hardware feature
*/
hisi_femac_sleep_us(priv->phy_reset_delays[PULSE]);
reset_control_deassert(priv->phy_rst);
/* delay some time to ensure later MDIO access */
hisi_femac_sleep_us(priv->phy_reset_delays[POST_DELAY]);
}
static void hisi_femac_port_init(struct hisi_femac_priv *priv)
{
u32 val;
/* MAC gets link status info and phy mode by software config */
val = MAC_PORTSEL_STAT_CPU;
if (priv->ndev->phydev->interface == PHY_INTERFACE_MODE_RMII)
val |= MAC_PORTSEL_RMII;
writel(val, priv->port_base + MAC_PORTSEL);
/*clear all interrupt status */
writel(IRQ_ENA_PORT0_MASK, priv->glb_base + GLB_IRQ_RAW);
hisi_femac_irq_disable(priv, IRQ_ENA_PORT0_MASK | IRQ_ENA_PORT0);
val = readl(priv->glb_base + GLB_FWCTRL);
val &= ~(FWCTRL_VLAN_ENABLE | FWCTRL_FWALL2CPU);
val |= FWCTRL_FW2CPU_ENA;
writel(val, priv->glb_base + GLB_FWCTRL);
val = readl(priv->glb_base + GLB_MACTCTRL);
val |= (MACTCTRL_BROAD2CPU | MACTCTRL_MACT_ENA);
writel(val, priv->glb_base + GLB_MACTCTRL);
val = readl(priv->port_base + MAC_SET);
val &= ~MAX_FRAME_SIZE_MASK;
val |= MAX_FRAME_SIZE;
writel(val, priv->port_base + MAC_SET);
val = RX_COALESCED_TIMER |
(RX_COALESCED_FRAMES << RX_COALESCED_FRAME_OFFSET);
writel(val, priv->port_base + RX_COALESCE_SET);
val = (HW_RX_FIFO_DEPTH << RX_DEPTH_OFFSET) | HW_TX_FIFO_DEPTH;
writel(val, priv->port_base + QLEN_SET);
}
static int hisi_femac_drv_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
struct net_device *ndev;
struct hisi_femac_priv *priv;
Annotation
- Immediate include surface: `linux/circ_buf.h`, `linux/clk.h`, `linux/etherdevice.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of_mdio.h`, `linux/of_net.h`, `linux/platform_device.h`.
- Detected declarations: `struct hisi_femac_queue`, `struct hisi_femac_priv`, `enum phy_reset_delays`, `function hisi_femac_irq_enable`, `function hisi_femac_irq_disable`, `function hisi_femac_tx_dma_unmap`, `function hisi_femac_xmit_reclaim`, `function hisi_femac_adjust_link`, `function hisi_femac_rx_refill`, `function hisi_femac_rx`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- 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.