在 Linux 中强制以太网物理链路状态

在 Linux 中强制以太网物理链路状态

有没有一种通用的方法可以从 Linux 用户空间强制以太网物理链路状态?我知道至少英特尔 e1000 驱动程序在接口取消配置时将 PHY 置于断电状态

ifconfig eth0 down

这会导致物理链路断开(如果未启用局域网唤醒功能)。

但是,当使用 ifconfig 时,其他以太网芯片(例如 Realtek 的芯片)似乎不会修改其物理链路状态。

使用 mii-tool 重新启动自动协商会暂时关闭链接,但您可以强制彻底关闭它吗?或者您是否可以通过某些接口直接写入 PHY 寄存器来完成相同的操作?

答案1

在 r8125 realtek 驱动程序安装文件夹的自述文件中发现了这一点:

强制链接状态>

1. Force the link status when insert the driver.

   If the user is in the path ~/r8125, the link status can be forced
   to one of the 5 modes as following command.

    # insmod ./src/r8125.ko speed=SPEED_MODE duplex=DUPLEX_MODE autoneg=NWAY_OPTION

    ,where
        SPEED_MODE  = 1000  for 1000Mbps
                = 100   for 100Mbps
                = 10    for 10Mbps
        DUPLEX_MODE = 0 for half-duplex
                = 1 for full-duplex
        NWAY_OPTION = 0 for auto-negotiation off (true force)
                = 1 for auto-negotiation on (nway force)
    For example:

        # insmod ./src/r8125.ko speed=100 duplex=0 autoneg=1

    will force PHY to operate in 100Mpbs Half-duplex(nway force).

2. Force the link status by using ethtool.
    a. Insert the driver first.
    b. Make sure that ethtool exists in /sbin.
    c. Force the link status as the following command.

        # ethtool -s ethX speed SPEED_MODE duplex DUPLEX_MODE autoneg NWAY_OPTION

        ,where
            SPEED_MODE  = 1000  for 1000Mbps
                    = 100   for 100Mbps
                    = 10    for 10Mbps
            DUPLEX_MODE = half  for half-duplex
                    = full  for full-duplex
            NWAY_OPTION = off   for auto-negotiation off (true force)
                    = on    for auto-negotiation on (nway force)

    For example:

        # ethtool -s eth0 speed 100 duplex full autoneg on

    will force PHY to operate in 100Mpbs Full-duplex(nway force).

相关内容