10 ethtool 与 MMC 统计

10 ethtool 与 MMC 统计

源码:stmmac_ethtool.cmmc_core.cmmc.h
编译:CONFIG_STMMAC_ETHTOOL

1. ethtool 模块

1.1 注册

1
2
3
4
void stmmac_set_ethtool_ops(struct net_device *netdev)
{
netdev->ethtool_ops = &stmmac_ethtool_ops;
}

stmmac_dvr_probe() 早期调用。

1.2 主要接口

ethtool 操作 函数 说明
get_drvinfo stmmac_ethtool_getdrvinfo 驱动名、版本、bus
get_link phylink 委托 链路状态
get/set_link_ksettings stmmac_ethtool_get/set_link_ksettings 速率双工
get/set_ringparam stmmac_get/set_ringparam RX/TX ring 大小
get/set_pauseparam stmmac_get/set_pauseparam 流控
get_ethtool_stats stmmac_get_ethtool_stats 软件+硬件统计
get_sset_count / get_strings 统计项名称与数量
get/set_coalesce 中断合并参数
get/set_rxfh RSS indirection table
get/set_channels 队列数
get_ts_info PTP 时间戳信息
get/set_eee EEE 配置
get/set_wol Wake-on-LAN
self_test stmmac_selftest_run(可选)

1.3 统计数据源

软件统计stmmac_extra_statscommon.h):

  • TX/RX 错误分类(underflow、CRC、watchdog…)
  • IRQ 计数、NAPI poll 次数
  • PTP 报文类型计数
  • MTL/MAC debug 寄存器快照

队列统计stmmac_txq_stats / stmmac_rxq_stats

硬件统计 — 通过 MMC 读取(见下文)

stmmac_get_ethtool_stats() 合并上述来源到 u64 数组。

1.4 ring 参数

1
2
stmmac_get_ringparam()  → dma_rx_size, dma_tx_size
stmmac_set_ringparam() → 需 down 设备后 stmmac_reinit_ringparam()

范围:DMA_MIN_* (64) ~ DMA_MAX_* (1024)。

1.5 coalesce

Per-queue:

  • rx_coal_frames / rx_coal_timer → RIWT、RX IC bit
  • tx_coal_frames / tx_coal_timer → TX IC bit、hrtimer

2. MMC(MAC Management Counters)

2.1 模块职责

mmc_core.c 实现 stmmac_mmc_ops

  • 读 HW 计数寄存器到 struct stmmac_counters
  • 控制 reset-on-read、preset 等模式

2.2 寄存器布局

基址 priv->mmcaddr(GMAC4:MMC_GMAC4_OFFSET

类别 示例寄存器
TX MMC_TX_FRAMECOUNT_GBMMC_TX_OCTETCOUNT_GB
RX MMC_RX_FRAMECOUNT_GBMMC_RX_CRC_ERROR
IPC checksum offload 相关计数

2.3 使用策略

stmmac_mmc_setup() 在 open 时:

1
2
stmmac_mmc_intr_all_mask(priv, priv->mmcaddr);  // 屏蔽 MMC 中断
stmmac_mmc_ctrl(priv, priv->mmcaddr, mode); // reset-on-read 等

驱动 轮询读取 MMC 合并到 ethtool,而非 MMC 中断驱动。

2.4 mmc_ops

方法 说明
ctrl 控制寄存器模式
intr_all_mask 屏蔽所有 MMC 中断
read 批量读计数到 stmmac_counters

XGMAC 使用 dwxgmac_mmc_ops(扩展计数集)。

3. Selftests

CONFIG_STMMAC_SELFTESTS 启用 stmmac_selftests.c

  • ethtool -t 触发
  • MAC loopback、寄存器读写等

4. 常用命令

1
2
3
4
5
6
7
ethtool -i eth0          # 驱动信息
ethtool -S eth0 # 统计
ethtool -g eth0 # ring 参数
ethtool -c eth0 # coalesce
ethtool -k eth0 # offload
ethtool -T eth0 # 时间戳
ethtool -t eth0 online # 自测(若编译启用)

5. debugfs

CONFIG_DEBUG_FSstmmac_init_fs() 创建 debugfs 节点,可 dump MAC/DMA 寄存器(开发调试用)。

6. 相关文档

文章互动

阅读 --

留言

0 条留言

正在加载留言…