使用ethtool查看MAC和PHY的相关信息

时间:2024-03-04 21:31:07

查看MAC和PHY配置和状态工具有 mii-tool/ethtool. 经常使用的工具是ethtool, ethtool可以详细的描述MAC和PHY的相关信息,包括寄存器的配置,相关的统计。

使用语法

ethtool [ -a | -c | -g | -i | -d | -k | -r | -S |] ethX

ethtool [-A] ethX [autoneg on|off] [rx on|off] [tx on|off]

ethtool [-C] ethX [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]

ethtool [-G] ethX [rx N] [rx-mini N] [rx-jumbo N] [tx N]

ethtool [-e] ethX [raw on|off] [offset N] [length N]

ethtool [-E] ethX [magic N] [offset N] [value N]

ethtool [-K] ethX [rx on|off] [tx on|off] [sg on|off] [tso on|off]

ethtool [-p] ethX [N]

ethtool [-t] ethX [offline|online]

ethtool [-s] ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off]  [port tp|aui|bnc|mii] [phyad N] [xcvr internal|external]

命令参数说明

-a     查看网卡中接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。

-A    修改网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。

-c    display the Coalesce(聚合、联合) information of the specified ethernet card.聚合网口信息,使看起来更有规律。

-C    Change the Coalesce setting of the specified ethernet card.修改网卡聚合信息。

-g    Display the rx/tx ring parameter information of the specified ethernet card. 显示网卡的接收/发送环形参数。

-G    Change the rx/tx ring setting of the specified ethernet card. 修改网卡的接收/发送环形参数。

-i    显示网卡驱动的信息,如驱动的名称、版本等

-d   显示register dump信息, 部分网卡驱动不支持该选项

-e   显示EEPROM dump信息,部分网卡驱动不支持该选项

-E   修改网卡EEPROM byte

-k   显示网卡Offload参数的状态:on 或 off,包括rx-checksumming、tx-checksumming等

-K  修改网卡Offload参数的状态

-p  用于区别不同ethX对应网卡的物理位置,常用的方法是使网卡port上的led不断的闪;N指示了网卡闪的持续时间,以秒为单位

-r  如果auto-negotiation模块的状态为on,则restarts auto-negotiation

-s  修改网卡的部分配置,包括网卡速度、单工/全双工模式、mac地址等。加上-s选项修改的内容才会生效

-S  显示NIC- and driver-specific 的统计参数,如网卡接收/发送的字节数、接收/发送的广播包个数等。

-t  让网卡执行自我检测,有两种模式:offline or online

 

用法举例

1. 查看ethtool的详细功能

ethtool --help

2. 查看基本信息

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool eth0
Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off (auto)
    Supports Wake-on: umbg
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

 

3. 查看MAC和PHY的相关寄存器

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool -d eth0
MAC Registers
-------------
0x00000: CTRL (Device control register)  0x48000249
      Endian mode (buffers):             little
      Link reset:                        reset
      Set link up:                       1
      Invert Loss-Of-Signal:             no
      Receive flow control:              enabled
      Transmit flow control:             disabled
      VLAN mode:                         enabled
      Auto speed detect:                 disabled
      Speed select:                      1000Mb/s
      Force speed:                       no
      Force duplex:                      no
0x00008: STATUS (Device status register) 0x00000083
      Duplex:                            full
      Link up:                           link config
      TBI mode:                          disabled
      Link speed:                        1000Mb/s
      Bus type:                          PCI
      Bus speed:                         33MHz
      Bus width:                         32-bit
0x00100: RCTL (Receive control register) 0x00008002
      Receiver:                          enabled
      Store bad packets:                 disabled
      Unicast promiscuous:               disabled
      Multicast promiscuous:             disabled
      Long packet:                       disabled
      Descriptor minimum threshold size: 1/2
      Broadcast accept mode:             accept
      VLAN filter:                       disabled
      Canonical form indicator:          disabled
      Discard pause frames:              filtered
      Pass MAC control frames:           don\'t pass
      Receive buffer size:               2048
0x02808: RDLEN (Receive desc length)     0x00001000
0x02810: RDH   (Receive desc head)       0x000000AE
0x02818: RDT   (Receive desc tail)       0x000000AC
0x02820: RDTR  (Receive delay timer)     0x00000000
0x00400: TCTL (Transmit ctrl register)   0x0103F0FA
      Transmitter:                       enabled
      Pad short packets:                 enabled
      Software XOFF Transmission:        disabled
      Re-transmit on late collision:     enabled
0x03808: TDLEN (Transmit desc length)    0x00001000
0x03810: TDH   (Transmit desc head)      0x0000008D
0x03818: TDT   (Transmit desc tail)      0x0000008D
0x03820: TIDV  (Transmit delay timer)    0x00000008
PHY type:                                M88
M88 PHY STATUS REGISTER:                 0x0000BC08
      Jabber:                            no
      Polarity:                          normal
      Downshifted:                       no
      MDI/MDIX:                          MDI
      Cable Length Estimate:             0-50 meters
      Link State:                        Up
      Speed & Duplex Resolved:           Yes
      Page Received:                     Yes
      Duplex:                            Full
      Speed:                             1000 mbps
M88 PHY CONTROL REGISTER:                0x00000868
      Jabber function:                   enabled
      Auto-polarity:                     disabled
      SQE Test:                          disabled
      CLK125:                            enabled
      Auto-MDIX:                         auto
      Extended 10Base-T Distance:        disabled
      100Base-TX Interface:              MII
      Scrambler:                         enabled
      Force Link Good:                   disabled
      Assert CRS on Transmit:            enabled

4. 查看收发包统计

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool -S eth0
NIC statistics:
     rx_packets: 105902
     tx_packets: 14458
     rx_bytes: 7561476
     tx_bytes: 2602118
     rx_broadcast: 105692
     tx_broadcast: 3406
     rx_multicast: 4
     tx_multicast: 10756
     rx_errors: 0
     tx_errors: 0
     tx_dropped: 0
     multicast: 4
     collisions: 0
     rx_length_errors: 0
     rx_over_errors: 0
     rx_crc_errors: 0
     rx_frame_errors: 0
     rx_no_buffer_count: 0
     rx_missed_errors: 0
     tx_aborted_errors: 0
     tx_carrier_errors: 0
     tx_fifo_errors: 0
     tx_heartbeat_errors: 0
     tx_window_errors: 0
     tx_abort_late_coll: 0
     tx_deferred_ok: 0
     tx_single_coll_ok: 0
     tx_multi_coll_ok: 0
     tx_timeout_count: 0
     tx_restart_queue: 0
     rx_long_length_errors: 0
     rx_short_length_errors: 0
     rx_align_errors: 0
     tx_tcp_seg_good: 0
     tx_tcp_seg_failed: 0
     rx_flow_control_xon: 0
     rx_flow_control_xoff: 0
     tx_flow_control_xon: 0
     tx_flow_control_xoff: 0
     rx_long_byte_count: 7561476
     rx_csum_offload_good: 0
     rx_csum_offload_errors: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0

5. 设置PHY的动作方式,速度/半双工/自动协商

ethtool -s ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off]

ethtool -s eth0 autoneg off speed 100 duplex full

 

将 ethtool 设置永久保存在网络设备:

1. ethtool 设置可通过 /etc/sysconfig/network-scripts/ifcfg-ethx 文件保存,从而在设备下次启动时激活选项

ethtool -s eth0 speed 100 duplex full autoneg off

此指令将eth1设备设置为全双工自适应,速度为100Mbs。若要eth0启动时设置这些参数, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth1 ,添加如下一行

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

2. 将ethtool设置写入/etc/rc.d/rc.local之中,开机自动执行命令设置

ethtool -s eth0 speed 100 duplex full autoneg off

相关文章