Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ ethtool implementation framework and application in Linux     - DNF Command Tutorial (Linux)

- ARM runtime environment built from scratch using QEMU emulator (Linux)

- Achieve single backup of MySQL by innobackupex (Database)

- WebLogic 12c Configuration Node Manager Managed Server (Database)

- Install Ubuntu text editor KKEdit 0.2.10 (Linux)

- Atheros AR8161 / AR8162 network card driver problem solving in CentOS 6.4 (Linux)

- APF firewall installation and configuration under Linux (Linux)

- Java implementation of stacks and queues (Programming)

- Mhddfs: multiple smaller partitions into one large virtual storage (Linux)

- Use install_updates upgrade GAMIT / GLOBK (Linux)

- MySQL loose index scan (Database)

- Puppet 3.5 Source package Installation and Configuration (Server)

- Android webView URL redirects affect goBack () (Programming)

- Use IP address spoofing Intrusion Prevention Firewall (Linux)

- ARM Linux system call (Linux)

- Tomcat session clustering and server session (Server)

- Linux / Unix desktops interesting: Christmas tree on the terminal (Linux)

- Linux firewall settings instance (Linux)

- MyCAT log analysis (Database)

- Transfer files and permissions from Windows to Linux system by Samba (Linux)

 
         
  ethtool implementation framework and application in Linux
     
  Add Date : 2017-01-08      
         
         
         
  Linux is a notable feature is its powerful networking capabilities, Linux supports almost all network protocols, and provides a wealth of applications on the basis of these agreements. The importance of Linux network management goes without saying that these management tools depending on the network, such as the most commonly used ifconfig, route, ip, ethtool, etc., which provides a powerful ethtool NIC and NIC driver management capabilities, its specific implementation framework and network drivers and network hardware close relationship, easy to modify and extend to provide settings for the NIC hardware, drivers and network protocol stack for Linux developers and network managers, as well as view and debug features.

Linux NIC driver support and realization of ethtool

Speaking from the typical Ethernet Controller

NIC In the last two OSI network architecture, physical layer and the data link layer, physical layer defines the transmission and receipt of data required for electrical and optical signal, line status, clock reference, and data encoding circuit, to the data link layer device provides a standard interface. The physical layer chip called PHY. The data link layer provides addressing mechanism, an building data frame, data error checking, transmission control, the network layer provides a standard data interface and other functions. Chip Ethernet data link layer is called MAC controller. Both are part of many network cards do together. The relationship between them is a PCI bus interface bus MAC, MAC access PHY, PHY connection cable (of course, is not directly connected, there is a transformer device).

The data link layer Media Access Control MAC is the acronym MAC sublayer protocol. The agreement is located OSI seven layer protocol in the data link layer of the lower half, is responsible for the control and connection to the physical layer physical media. When sending data, the MAC protocol can determine whether data can be sent in advance, if the data will be transmitted together with some control information, the transmission format ultimately data and control information into a predetermined physical layer; at the time of receiving data, the MAC protocol first determines whether the information input and transmission errors occur, if there is no error, then remove the control information is transmitted to the LLC layer. Ethernet MAC is defined by the IEEE-802.3 Ethernet standard.

The physical layer PHY is the physical interface transceiver that implements the physical layer. Including MII / GMII (Media Independent Interface) sublayer, PCS (physical coding sublayer), PMA (physical medium attachment) sublayer, PMD (Physical Medium Dependent) sublayer, MDI sublayer.

That MII Media Independent Interface, "independent media" does not show in the MAC hardware redesign or replacement, any type of PHY devices are working properly. Including two independent channels, each for transmitter and receiver. Each channel has its own data, clock and control signals. MII data interface requires a total of 16 signals, including TX_ER, TXD <3: 0>, TX_EN, TX_CLK, COL, RXD <3: 0>, RX_EX, RX_CLK, CRS, RX_DV like.

RMII (Reduced Media Independant Interface) is a simplified MII interface to send and receive data on the MII interface less than double the signal line, it generally requires 50 megabytes of bus clock. RMII is generally used in a multi-port switch, it is not every port arrangement sending and receiving two clocks, but all the data ports for transmitting and receiving the common clock all the ports, where saving a lot of number of ports. A port RMII of claim 7 data lines, less than double the MII, so the switch port to access the data twice. Like and MII, RMII support 10 megabytes and 100 megabytes bus interface speed.

GMII (Gigabit MII) is a Gigabit Ethernet MII interface, which also has a corresponding RGMII interface represents a simplified GMII interface. GMII data using 8-bit interface that operates at clock 125MHz, transfer rates up to 1000Mbps. MII compatible under the 10/100 Mbps work.

MII management interface is a dual-signal interface, a clock signal MDC, the other is data signal MDIO. Through the management interface to monitor and control the PHY upper register. PHY registers inside part is defined by IEEE, and PHY his own to reflect the current state of the register inside, MAC through the PHY management interface constantly read the status register to know the current state of the PHY, such as connection speed, duplex capability. Of course, can be achieved by setting PHY management interface registers control purposes, such as opening and closing of the flow control, auto-negotiation mode or compulsory mode, which is the working principle of ethtool.

MDIO / MDC, namely PHY management interface to the serial communication bus, which is defined by the IEEE to several provisions of IEEE 802.3 Ethernet standard. MDIO is a simple two-wire serial interface, a management devices (such as MAC controllers, microprocessors) and management functions with a transceiver (such as multi-port gigabit Ethernet transceivers or 10GbE XAUI transceiver) connected to control the transceiver and collect status information from the transceiver. The information collected may include link status, transmission speed and choice, power, low-power hibernation state, TX / RX mode selection, auto-negotiation control, loop-back mode control. In addition to its function beyond the requirements of IEEE Transceiver vendors can also add more information-gathering capabilities.

MDC is the clock input to manage data rates up to 8.3MHz. MDIO management data input and output bi-directional interface, data is synchronized with the clock MDC. MDIO workflow is:

MDIO interface is not transmitting idle state (IDLE) MDIO data lines in a high impedance state.
MDIO A 2bit start code (01) a read / write operation starts.
MDIO appears to identify a 2bit data read operation (10) or write (01).
MDIO A 5bit data identifies PHY address.
A 5bitPHY MDIO register address.
MDIO need access time 2 clock.
MDIO serial read / write data register of 16bit.
MDIO restored to IDLE state while MDIO into a high impedance state.
Note: The above content part excerpt from the Internet.

Linux device driver support for the ethtool

Almost all of the NIC driver has to ethtool support its frame shown in Figure 2, ethtool frame contains the kernel space and user space into two parts: part responsible for user space to kernel sends ethtool command, and receives command execution results; parts of the kernel space in accordance with the appropriate command word, by MDIO / MDC write MII register, to achieve the management of the card, and the implementation of the results back to the user space. Because Linux network driver is a complex and huge system, here only driver in the definition of the MII register for MDIO / MDC support and drivers realize how ethtool Features section.

IEEE 802.3 MII predetermined register

Definition of MII / GMII Interface PHY register 802.3 in section 22.2.4 Management functions, such as the section of Table 22 -. 6 and Table 22 - 7 (both from http://standards.ieee.org/getieee802/ download / 802.3-2008_section2.pdf) shown

You can see the basic set and extended into the register set, defines the basic set because GMII and MII are different, the MII, the basic set includes a register 0 and 1 control register status register, and for GMII; 0,1 and basic set includes a register 15. The definition of control and status registers Register 0 1

Register 0 and register read 1 can achieve the management of the network card, Listing 1 shows a portion of the PHY management registers and control registers and each bit status register definitions.

Listing 1, / kernel / drivers / net / Mii.h, defined PHY management registers

 #define MII_BMCR 0x00 / * Basic mode control register * /
 #define MII_BMSR 0x01 / * Basic mode status register * /
 #define MII_PHYSID1 0x02 / * PHYS ID 1 * /
 #define MII_PHYSID2 0x03 / * PHYS ID 2 * /
 #define MII_ADVERTISE 0x04 / * Advertisement control reg * /
 #define MII_LPA 0x05 / * Link partner ability reg * /
 #define MII_EXPANSION 0x06 / * Expansion register * /
 #define MII_CTRL1000 0x09 / * 1000BASE-T control * /
 ...

 / * Basic mode control register. * /
 #define BMCR_RESV 0x003f / * Unused ... * /
 #define BMCR_SPEED1000 0x0040 / * MSB of Speed (1000) * /
 #define BMCR_CTST 0x0080 / * Collision test * /
 #define BMCR_FULLDPLX 0x0100 / * Full duplex * /
 #define BMCR_ANRESTART 0x0200 / * Auto negotiation restart * /
 #define BMCR_ISOLATE 0x0400 / * Disconnect DP83840 from MII * /
 #define BMCR_PDOWN 0x0800 / * Powerdown the DP83840 * /
 #define BMCR_ANENABLE 0x1000 / * Enable auto negotiation * /
 #define BMCR_SPEED100 0x2000 / * Select 100Mbps * /
 #define BMCR_LOOPBACK 0x4000 / * TXD loopback bits * /
 #define BMCR_RESET 0x8000 / * Reset the DP83840 * /

 / * Basic mode status register. * /
 #define BMSR_ERCAP 0x0001 / * Ext-reg capability * /
 #define BMSR_JCD 0x0002 / * Jabber detected * /
 #define BMSR_LSTATUS 0x0004 / * Link status * /
 #define BMSR_ANEGCAPABLE 0x0008 / * Able to do auto-negotiation * /
 #define BMSR_RFAULT 0x0010 / * Remote fault detected * /
 #define BMSR_ANEGCOMPLETE 0x0020 / * Auto-negotiation complete * /
 #define BMSR_RESV 0x00c0 / * Unused ... * /
 #define BMSR_ESTATEN 0x0100 / * Extended Status in R15 * /
 #define BMSR_100FULL2 0x0200 / * Can do 100BASE-T2 HDX * /
 #define BMSR_100HALF2 0x0400 / * Can do 100BASE-T2 FDX * /
 #define BMSR_10HALF 0x0800 / * Can do 10mbps, half-duplex * /
 #define BMSR_10FULL 0x1000 / * Can do 10mbps, full-duplex * /
 #define BMSR_100HALF 0x2000 / * Can do 100mbps, half-duplex * /
 #define BMSR_100FULL 0x4000 / * Can do 100mbps, full-duplex * /
 #define BMSR_100BASE4 0x8000 / * Can do 100mbps, 4k packets * /
By MDC / MDIO MII register read and write the specific implementation

In the previous section of this article introduced MDC / MDIO workflow, network card driver MDIO read and write functions mdio_read and mdio_write, that is, the specific implementation in Listing 3 function pointer is done in all NIC driver files, We have to comply with IEEE802.3 MDIO frame format. A typical frame format is the format defined in terms of section 22


Field Length (bit) Description
ST 2bits 01b
OP 2bits operation code, written as 01b, 10b read as
PHYADR 5bits PHY ID
REGADR 5bits register address
TA 2 bits state transition domain, reads as X0b, write to 10b
DATA 16 bits of data
Achieve ethtool function driver

In kernel / include / linux / ethtool.h defines the structure ethtool_ops, all members of this structure is a function pointer type defines ethtool can achieve the function, the structure members are more variable, is not listed here Listing; the same time, the structure is also a member variable net_device ethtool_ops shown in Listing 2,

Listing 2, kernel / include / linux / NetDevice.h, net_device member variables ethtool_ops

 struct net_device
 {
 ...
 const struct ethtool_ops * ethtool_ops;
 ...
 }
NIC driver needs to be initialized ethtool_ops and achieve its defined function, enabling support for ethtool to Dm9000.c example.

Listing 3, kernel / drivers / net / Dm9000.c, DM9000 driver support for the ethtool

 static const struct ethtool_ops dm9000_ethtool_ops = {
.get_drvinfo = dm9000_get_drvinfo,
 .get_settings = dm9000_get_settings,
.set_settings = dm9000_set_settings,
.get_msglevel = dm9000_get_msglevel,
.set_msglevel = dm9000_set_msglevel,
 .nway_reset = dm9000_nway_reset,
.get_link = dm9000_get_link,
 .get_eeprom_len = dm9000_get_eeprom_len,
 .get_eeprom = dm9000_get_eeprom,
 .set_eeprom = dm9000_set_eeprom,
 .get_rx_csum = dm9000_get_rx_csum,
 .set_rx_csum = dm9000_set_rx_csum,
 .get_tx_csum = ethtool_op_get_tx_csum,
 .set_tx_csum = dm9000_set_tx_csum,
 };
 ...
 ndev-> ethtool_ops = & dm9000_ethtool_ops;
 ...
Listing 3 individual functions are implemented in the DM9000 driver, for example, if you need to view the current network connections, can be obtained by dm9000_get_link specific implementation of the function shown in Listing 4:

Listing 4, dm9000_get_link

 static u32 dm9000_get_link (struct net_device * dev)
 {
board_info_t * dm = to_dm9000_board (dev);
 u32 ret;

if (dm-> flags & DM9000_PLATF_EXT_PHY)
ret = mii_link_ok (& dm-> mii);
else
ret = dm9000_read_locked (dm, DM9000_NSR) & NSR_LINKST 1:? 0;

return ret;
 }
 kernel / drivers / net / Mii.c
 int mii_link_ok (struct mii_if_info * mii)
 {
/ * First, a dummy read, needed to latch some MII phys * /
mii-> mdio_read (mii-> dev, mii-> phy_id, MII_BMSR);
if (mii-> mdio_read (mii-> dev, mii-> phy_id, MII_BMSR) & BMSR_LSTATUS)
return 1;
return 0;
 }
We can see the final implementation or by MDIO / MDC PHY registers are read.

In addition to managing the NIC commands, ethtool there's also other extended features, the framework ethtool very conducive to the expansion of new features, developers can add their own functions in this framework to achieve the other functions in addition to the card management, in fact, now ethtool has provided a number of other functions, such as network cards used to implement Firmware brush writing, and updating of the control network driver logs, these new features for debugging, error correction is very favorable.

Listing 5, some ethtool extensions: firmware update and change the log level

 ethtool -f | --flash DEVNAME FILENAME
 ethtool -s | --change DEVNAME msglvl% d
Use ethtool to configure and manage the network card

On a method and introduces the basic ethtool implemented, this section describes some uses of the ethtool, mainly in ethtool card usage in the configuration and management aspects.

Learn the best way to help is to use ethtool ethtool See the "ethtool -h" or "man ethtool", because the help a lot, not to list here, and will be an example of some practical application examples instead.

Example 1 using ethtool to view information about network interface eth4

Listing 6 interface information, view the card

 root @ IMMV2-DEV4: ~ # ethtool eth4
 Settings for eth4:
        Supported ports: [TP]
        Supported link modes: 10baseT / Half 10baseT / Full
                                100baseT / Half 100baseT / Full
                                1000baseT / Full
        Supports auto-negotiation: Yes
        Advertised link modes: 10baseT / Half 10baseT / Full
                                100baseT / Half 100baseT / Full
                                1000baseT / Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb / s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: g
        Link detected: yes
Example 2, close the card auto-negotiation and view the modifications.

Listing 7, turn off auto-negotiation NIC and view the modifications

 root @ IMMV2-DEV4: ~ # ethtool -s eth4 autoneg off
 root @ IMMV2-DEV4: ~ # ethtool eth4
 Settings for eth4:
Supported ports: [TP]
Supported link modes: 10baseT / Half 10baseT / Full
100baseT / Half 100baseT / Full
1000baseT / Full
Supports auto-negotiation: Yes
Advertised link modes: Not reported
Advertised auto-negotiation: No
Speed: 100Mb / s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Link detected: yes
Example 3, turn off auto-negotiation and modify the NIC card rate of 10Mb / s

Listing 8. Close the card automatically negotiate and modify the network card rate of 10Mb / s

 root @ IMMV2-DEV4: ~ # ethtool -s eth4 autoneg off speed 10
 root @ IMMV2-DEV4: ~ # ethtool eth4
 Settings for eth4:
        Supported ports: [TP]
        Supported link modes: 10baseT / Half 10baseT / Full
                                100baseT / Half 100baseT / Full
                                1000baseT / Full
        Supports auto-negotiation: Yes
        Advertised link modes: Not reported
        Advertised auto-negotiation: No
        Speed: 10Mb / s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Link detected: yes
Other functions in accordance with its ethtool can help to achieve a predetermined syntax, not list them here.

Extended ethtool

According to some of the features of the NIC can be extended to complete ethtool support special features on the card, a typical application is to increase the expansion of SideBand ethtool support functions, information about SideBand can refer to the IBM developerWorks "On the NCSI and on Linux achieve

. " Figure 6 is a block diagram by adding a custom cmd and corresponding implementation function to complete SideBand of select_channel, enable_channel disable_channel and other functions. In select_channel for example, can be achieved through the following steps.

ethtool in the user space and kernel space while adding command word ETHTOOL_SELCHANNEL;
Add the ETHTOOL_SELCHANNEL corresponding function is executed ethtool_select_channel in ethtool.ops in;
Achieve ethtool_select_channel in dev_ethtool function () function function, this function is NCSI command protocol packet packets use protocol stack interface to send the package to the NIC mac layer was, and receive appropriate responses, similar to ethtool_enable_channel (), ethtool_disable_channel can be extended in the same way, we can see that scalability ethtool is a good framework, conducive to the development staff tailored according to actual needs.
to sum up

ethtool is a Linux under the powerful network management tool, this paper introduces the principle and method of this tool, highlighting IEEE802.3.22 the MII management registers and MDIO / MDC and standard Linux network driver support for the ethtool and examples illustrate the use of this tool for managing card method, introduced last extended in ethtool SideBand management framework instance, can be used as a reference to the majority of developers.
     
         
         
         
  More:      
 
- RedHat command line and graphical interface switching (Linux)
- Java Cookie Comments (Programming)
- Zabbix monitors the status of TCP connections (Server)
- How to create a secure and easy to remember password (Linux)
- Linux security settings (Linux)
- Linux Security Module (LSM) Introduction (Linux)
- Set up MySQL master and slave servers under Ubuntu 14.04 (Server)
- A process of how to get the current traffic in GNU Linux (Linux)
- Linux Getting Started tutorial: XWindow what (Linux)
- CentOS 6.5 installation Python3.0 (Linux)
- C ++ free store and heap (Programming)
- MySQL development common query summary (Database)
- Realize screen recording and playback via Linux command (Linux)
- The oh-my-zsh into true my zsh (Linux)
- Oracle 11g partition maintenance (two) - Coalescing Partitions (Database)
- Ubuntu install Eclipse for C / C ++ and related configuration (Linux)
- Ubuntu server 8.04 Firewall Guide (Linux)
- Linux three ways to set environment variables (Linux)
- Linux at command (Linux)
- Python calls the API interface in several ways (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.