05 Platform 平台 Glue 层

05 Platform 平台 Glue 层

源码:stmmac_platform.cstmmac_platform.hdwmac-generic.c
各 SoC 专用:dwmac-rk.cdwmac-imx.c

1. 模块职责

Platform Glue 是 STMMAC 与 具体 SoC/板级 之间的适配层:

  • 解析 Device Tree,构建 plat_stmmacenet_data
  • 获取 MMIO、IRQ、MAC 地址等资源
  • 提供时钟/复位/引脚复用回调
  • 调用统一核心入口 stmmac_dvr_probe()

核心驱动 不依赖 任何特定 SoC 头文件。

2. 通用平台框架

2.1 stmmac_platform.c

函数 说明
stmmac_get_platform_resources() 映射 reg、解析 interrupt
stmmac_probe_config_dt() 解析 DT → plat_stmmacenet_data
stmmac_remove_config_dt() 释放 DT 相关内存
stmmac_pltfr_probe() 通用 platform probe(部分平台)
stmmac_pltfr_remove() 通用 remove

2.2 DT 解析要点

snps,dwmac 或厂商 compatible 节点读取:

属性 映射字段
snps,tx-sched-sp TX 调度算法
snps,rx-queues-config RX 队列 DCB/AVB
snps,tx-queues-config TX 队列配置
snps,axi-config AXI 总线 tuning
snps,mixed-burst DMA burst
max-speed max_speed
tx-fifo-depth / rx-fifo-depth FIFO 大小
dma-rx-size / dma-tx-size ring 深度

phy-modemdiophy-handle 供 phylink 使用。

2.3 plat_stmmacenet_data 关键字段

定义于 include/linux/stmmac.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct plat_stmmacenet_data {
int phy_addr;
phy_interface_t phy_interface;
struct stmmac_dma_cfg *dma_cfg;
u32 rx_queues_to_use;
u32 tx_queues_to_use;
void (*fix_mac_speed)(void *priv, unsigned int speed);
void (*get_eth_addr)(void *priv, unsigned char *addr);
void *bsp_priv;
struct reset_control *stmmac_rst;
int has_gmac4;
bool tso_en;
// ...
};

3. Probe 统一模式

所有 Platform 驱动遵循相同模板:

1
2
3
4
5
6
7
8
9
10
11
12
static int xxx_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
struct stmmac_resources res;

ret = stmmac_get_platform_resources(pdev, &res);
plat_dat = stmmac_probe_config_dt(pdev, res.mac);
plat_dat->bsp_priv = xxx_setup(pdev, plat_dat);
/* 填充平台回调 */
plat_dat->fix_mac_speed = xxx_fix_speed;
return stmmac_dvr_probe(&pdev->dev, plat_dat, &res);
}

4. 各 Platform 驱动一览

模块文件 Kconfig 平台
dwmac-rk.c DWMAC_ROCKCHIP Rockchip 全系
dwmac-imx.c DWMAC_IMX8 NXP i.MX
dwmac-qcom-ethqos.c DWMAC_QCOM_ETHQOS Qualcomm
dwmac-stm32.c DWMAC_STM32 STM32
dwmac-generic.c DWMAC_GENERIC 无特殊逻辑
dwmac-dwc-qos-eth.c DWMAC_DWC_QOS_ETH DWC QoS binding
stmmac_pci.c STMMAC_PCI PCI 设备

Makefile 注释:Generic driver must be last(避免覆盖专用匹配)。

5. stmmac_resources

1
2
3
4
5
6
7
8
struct stmmac_resources {
void __iomem *addr;
u8 mac[ETH_ALEN];
int irq; // 主中断
int wol_irq, lpi_irq;
int rx_irq[MTL_MAX_RX_QUEUES];
int tx_irq[MTL_MAX_TX_QUEUES];
};

multi_msi_en 时 per-queue IRQ 从 DT interrupt-names 解析。

6. PCI 路径

stmmac_pci.c

  • PCI probe → 映射 BAR
  • 构建 plat_stmmacenet_data(较固定)
  • 同样调用 stmmac_dvr_probe()

Intel 专用:dwmac-intel.c + dwmac-intel-plat.c

7. 电源管理

Platform glue 通常注册:

1
2
3
4
#ifdef CONFIG_PM
.suspend = stmmac_suspend,
.resume = stmmac_resume,
#endif

或通过 dev_pm_ops 委托给 stmmac_suspend/resume(),内部处理 DMA stop、PHY、时钟。

8. UIO 变体

stmmac_uio.cCONFIG_STMMAC_UIO):

  • 将 MAC 暴露给 DPDK 等用户态
  • 绕过内核 netdev 数据路径
  • 默认更大 ring(1024)

9. RK3588 详见

Rockchip 专用逻辑见 11-dwmac-rockchip-RK3588.md

10. 新增 Platform 检查清单

  • DTS binding 文档
  • 时钟/复位/电源域
  • phy-mode 与 GRF 引脚配置
  • MAC 地址来源(DT / OTP / 随机)
  • has_gmac4has_xgmac 正确设置
  • Kconfig + Makefile 注册
  • 调用 stmmac_dvr_probe / stmmac_dvr_remove

11. 相关文档

文章互动

阅读 --

留言

0 条留言

正在加载留言…