问题描述
我正在研究 realtek 设备驱动程序并遇到了像 ethtool_ops
这样的 ethtool 操作,操作对象中包含许多操作。以下是代码
static const struct ethtool_ops rtl8169_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES,.get_drvinfo = rtl8169_get_drvinfo,.get_regs_len = rtl8169_get_regs_len,.get_link = ethtool_op_get_link,.get_coalesce = rtl_get_coalesce,.set_coalesce = rtl_set_coalesce,.get_regs = rtl8169_get_regs,.get_wol = rtl8169_get_wol,.set_wol = rtl8169_set_wol,.get_strings = rtl8169_get_strings,.get_sset_count = rtl8169_get_sset_count,.get_ethtool_stats = rtl8169_get_ethtool_stats,.get_ts_info = ethtool_op_get_ts_info,.nway_reset = phy_ethtool_nway_reset,.get_eee = rtl8169_get_eee,.set_eee = rtl8169_set_eee,.get_link_ksettings = phy_ethtool_get_link_ksettings,.set_link_ksettings = phy_ethtool_set_link_ksettings,};
这些操作是什么
例如,提到了 eee
,所以我对它与更高级别的层(如 ip 或 tcp)的匹配功能感兴趣。
上面列表中的这些是什么:coalesce
、wol
、stats
、ksettings
、ts_info
和 eee
。我相信它们与 OSI 模型的物理层有关,但是如果您能给我它们实现的更高级别的功能。对于每个匹配高级简要信息的这些功能都会很棒
例如 wol 是这样的
局域网唤醒是一种以太网或令牌环计算机网络标准 它允许通过网络消息打开或唤醒计算机。 > 消息通常由在连接到同一局域网的设备上执行的程序发送到目标计算机,例如 手机。维基百科
而 Coalese 是
数据包合并是将数据包分组作为限制 接收中断的数量,从而降低了接收中断的数量 需要处理。
请给我一些关于这些函数的内核 API 的技术信息。谢谢
解决方法
长话短说,ethtool
是一种在用户空间应用程序中显示和调整通用 NIC/驱动程序参数(标识、接收和传输队列的数量、接收和传输卸载,等等)的方法。一方面,NIC 驱动程序连接到内核 API(特别是通过 struct ethtool_ops
)。另一方面,有一个名为 SIOCETHTOOL
的 ioctl 命令,用户空间应用程序可以使用它向内核端发送请求和获取回复。
存在枚举 SIOCETHTOOL
特定命令的子标识符,它们对应于 struct ethtool_ops
的方法。根据您的问题,应该解释的是 struct ethtool_ops
。
我建议你看看include/linux/ethtool.h
。在 struct ethtool_ops
的定义之前有一个注释部分。特别是:
* @get_wol: Report whether Wake-on-Lan is enabled
* @set_wol: Turn Wake-on-Lan on or off. Returns a negative error code
* @get_coalesce: Get interrupt coalescing parameters. Returns a negative
* error code or zero.
* @set_coalesce: Set interrupt coalescing parameters. Supported coalescing
* types should be set in @supported_coalesce_params.
* Returns a negative error code or zero.
* @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
* Drivers supporting transmit time stamps in software should set this to
* ethtool_op_get_ts_info().
* @get_eee: Get Energy-Efficient (EEE) supported and status.
* @set_eee: Set EEE status (enable/disable) as well as LPI timers.
对于 WoL 功能和中断合并,这些简短的评论大多与您问题中的解释相符。头文件中的其余注释也很有用。您可以参考它们以了解要点。
从用户空间的角度来看一下 ethtool
机制也可能会派上用场。最常用的使用 ethtool
机制的用户空间应用程序也被命名为 ethtool
;它可以在流行的发行版(Debian、Ubuntu 等)中作为软件包使用。它是包含有用信息的包的 man
页面。例如:
ethtool -c|--show-coalesce devname
ethtool -C|--coalesce devname [adaptive-rx on|off]
[adaptive-tx on|off] [rx-usecs N] [rx-frames N]
[rx-usecs-irq N] [rx-frames-irq N] [tx-usecs N]
[tx-frames N] [tx-usecs-irq N] [tx-frames-irq N]
[stats-block-usecs N] [pkt-rate-low N] [rx-usecs-low N]
[rx-frames-low N] [tx-usecs-low N] [tx-frames-low N]
[pkt-rate-high N] [rx-usecs-high N] [rx-frames-high N]
[tx-usecs-high N] [tx-frames-high N] [sample-interval N]
-c --show-coalesce
Queries the specified network device for coalescing
information.
-C --coalesce
Changes the coalescing settings of the specified network
device.
总而言之,您可以查看很多地方以阐明 ethtool
命令/方法的含义。这些命令(以及它们提供的功能)不一定与 OSI 模型的物理层有关。有些可能超出 OSI 模型的范围(如设备识别);有些可能对应于 OSI 模型的更高级别,例如,控制数据包卸载,如 TCP 分段卸载、RSS(接收端缩放)等。如果需要,可以单独讨论特定功能。