首页 > 解决方案 > 什么是 ethtool,它对可用的以太网 NIC 很重要。我可以从设备驱动程序中删除它并且仍然可以使用网络吗

问题描述

我正在研究 realtek 设备驱动程序并遇到了 ethtool 操作,例如ethtool_ops操作对象中包含许多操作。以下是代码

        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_infoeee来自上面的列表。我相信它们与 OSI 模型的物理层有关,但如果你能告诉我它们实现了哪些更高级别的功能。对于每个匹配高级简要信息的这些功能都会很棒

例如 wol 类似于

Wake-on-LAN 是一种以太网或令牌环计算机网络标准,它允许计算机被网络消息打开或唤醒。> 消息通常由连接到同一局域网的设备(例如智能手机)上执行的程序发送到目标计算机。维基百科

Coalese 是

数据包合并是将数据包分组,以限制接收中断的数量,从而降低所需的处理量。

只需给我一些关于这些函数的内核 api 技术信息。谢谢

标签: linuxlinux-device-driverethernetpci

解决方案


长话短说,ethtool是一种在用户空间应用程序中显示和调整通用 NIC/驱动程序参数(标识、接收和传输队列的数量、接收和传输卸载,您可以命名)的方法。一方面,有一个 NIC 驱动程序连接到的内核 API(特别是通过struct ethtool_ops)。另一方面,有一个名为ioctl 命令SIOCETHTOOL用户空间应用程序可以使用它向内核端发送请求并获得响应。

枚举特定命令的子标识符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接收端缩放)等。如果需要,可以单独讨论特定功能。


推荐阅读