A short network guide

This page is a compilation of various items of useful information about how to configure Ethernet interfaces under Linux, how to test the VLAN support, how to use the ethtool support and so forth.

Although, this page contains generic network information for Linux, the targets used for examples are the MAC/GMAC embedded devices.

Enable and disable the interface

After booting the kernel, enable or disable the interface manually by using the following command:

ifconfig eth0 up | down 

How to set the MAC address

  1. Bring down the interface with ifconfig eth0 down.
  2. Assign a MAC address with ifconfig eth0 hw ether <new_MAC_address>.
  3. Bring up the interface with ifconfig eth0 up.

How to modify the MTU

As with setting the MAC address, this is also a three step process:

ifconfig eth0 down
ifconfig eth0 mtu <new_value>
ifconfig eth0 up

VLAN support

VLAN is an implementation of the 802.1Q VLAN protocol for Linux. With VLAN, it is possible to have Virtual LANs on a single Ethernet cable.

To test that VLAN is working correctly, follow the steps below:

  1. Make sure that the kernel has VLAN support

  2. Create the VLAN interface by defining the vlan ID. To do that, use the vconfig command:

    vconfig add eth0 <vlan ID>

    where vlan ID is any integer number. The VLAN ID should be same on both machines.

  3. Assign an IP address to the VLAN interface using:

    ifconfig eth0,2 <IP address> up.

  4. Ping the remote machine. Ping should be successful without any error.

  5. The VLAN interface has been created successfully. This can be verified by using the ifconfig -a command.

Hardware notes

The latest MAC/GMAC cores support IEEE 802.1Q VLAN tag detection for reception frames without VLAN filtering.

The MAC core compares the TIPD field (bytes 13,14 within the frame) and, if they match the value in the VLAN Tag register, the length of the frame is incremented from 1518 to 1522 octets.

Ethtool Support

Use ethtool to display or change ethernet card settings.

How to get general driver information

Use the ethtool command to get interface information such as ports, speed, duplex, auto negotiation (ANE) and so forth:

target# ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 14
        Transceiver: external
        Auto-negotiation: on
        Supports Wake-on: d
        Wake-on: d
        Current message level: 0x0000003f (63)
        Link detected: yes
How to change the debug level

Use ethtool to change the debug level as follows:

target# ethtool -s eth0 msglvl 0xffff

where 0xffff is the maximum debug level for the drivers.

Note: The driver debug level has been written following the NETIF linux standard message level.
See the Documentation/networking/netif-msg.tx file included in the Linux Kernel source tree for more information.

Dump registers

With STLinux-2.3 and higher, ethtool can dump the mac 10/100/1000 registers. Use the -d option:

target# ethtool -d eth0
MAC 10/100 Registers
control reg  0x1010210C
addr HI 0x00004718
addr LO 0x12E18000
multicast hash HI 0x00000000
multicast hash LO 0x80000000
MII addr 0x00007440
MII data 00000380
flow control 0x02000002
VLAN1 tag 0x0000FFFF
VLAN2 tag 0x0000FFFF
mac wakeup frame 0x00000000
mac wakeup crtl 0x00000000
 
DMA Registers
CSR0  0x00002000
CSR1  0x00000000
CSR2  0x00000000
CSR3  0x42C06000
CSR4  0x433D9000
CSR5  0x00660004
CSR6  0x0040A002
CSR7  0x00018041
CSR8  0x00000000
DMA cur tx buf addr 0x00000000
DMA cur rx buf addr 0x00000000
Get extra statistics

Use the -S option to get extra statistics relating to the ethernet card:

target# ethtool -S eth0
NIC statistics:
     tx_underflow: 0
     tx_carrier: 0
     tx_losscarrier: 0
     tx_heartbeat: 0
     tx_deferred: 0
     tx_vlan: 0
     tx_jabber: 0
     tx_frame_flushed: 0
     rx_desc: 0
     rx_partial: 0
     rx_runt: 0
     rx_toolong: 0
     rx_collision: 0
     rx_crc: 0
     rx_lenght: 0
     rx_mii: 0
     rx_multicast: 0
     rx_overflow: 0
     rx_watchdog: 0
     rx_filter: 0
     rx_dropped: 0
     rx_bytes: 0
     tx_bytes: 0
     tx_irq_n: 0
     rx_irq_n: 0
     tx_undeflow_irq: 0
     tx_threshold: 32
     tx_process_stopped_irq: 0
     tx_jabber_irq: 0
     rx_overflow_irq: 0
     rx_buf_unav_irq: 0
     rx_process_stopped_irq: 0
     rx_watchdog_irq: 0
     tx_early_irq: 0
     fatal_bus_error_irq: 0
     rx_poll_n: 0

Flow Control

The latest MAC and GMAC embedded devices allow flow control in Full Duplex by using the PAUSE operation and control frame transmission. They also support flow control in Half Duplex by using back pressure.

See the driver's command line options for details about how to change the pause value and turn-on flow-control.

You can change the pause parameters by using ethtool, as shown below:

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

Offload parameters

Use ethtool to get offload information, as follows:

target# ethtool -k eth0
Offload parameters for eth0:
rx-checksumming: on
tx-checksumming: on
scatter-gather: on
tcp segmentation offload: off
udp fragmentation offload: off
generic segmentation offload: off

Turn on scatter-gather (which is enabled by default for the stmmac driver):

target# ethtool -K eth0 sg on

Turn on rx or tx checksumming:

target# ethtool -K eth0 rx on
target# ethtool -K eth0 tx on

Multicast

Multicast packets send the same data to multiple network devices at the same time within the same packet stream. A common situation in which Multicast is used is to distribute real time audio and video.

Configuring the Kernel for multicast

To use multicast, the kernel configuration requires the CONFIG_IP_MULTICAST option to be set.

Enable or disable all-multicast mode with ifconfig

Use ifconfig to enable and disable all-multicast mode.

  1. Disable promisc by running ifconfig eth0 -promisc
  2. Enable allmulti mode with the command ifconfig eth0 allmulti
  3. As a test, ping any multicast IP address from a remote machine:

    ping -I eth0 <multicast_ip_addr>
  4. On the target enabled with allmulti mode, check the RX packets count.
  5. Disable allmulti by running ifconfig eth0 -allmulti on the target.

If allmulti is enabled, the ifconfig eth0 output displays the keyword ALLMULTI in the second line.

Testing multicast

First, make sure that the kernel does not ignore all ICMP ECHO and TIMESTAMP requests sent to it using either broadcast or multicast.

On the target, execute the following:

target# echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

This sets all class D (that is, multicast) IP routes to use "eth0":

target#  route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

To join a multicast group, execute the following:

target# ./mjoin eth0 224.1.0.37

The mjoin C source can be obtained from here.

Ping multicast IP address:

host# ping -r -I eth0 224.1.0.37

To display the multicast group membership information on the target:

target# netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
eth0            1      224.1.0.37
eth0            1      224.0.0.1
<code>