Table of Contents

Driver test: link detection

Rationale

Users expect link state errors to be reported as such, rather than having to be inferred from DHCP timeouts etc. Drivers should therefore update the link state in response to external link up and link down events (e.g. disconnecting or reconnecting a network cable).

Background

The driver should update the link state using netdev_link_up(), netdev_link_down() and/or netdev_link_err(). The user can observe the link state from the command line using ifstat.

A network card

Test sequence

  1. Before starting, ensure that system power is off and the network cable is connected.
  2. Power on and boot to the iPXE command line.
  3. Use ifstat to identify the name of your network interface (hereafter assumed to be net0).
  4. Open the interface using ifopen net0.
  5. Use ifstat to verify that the link state is reported as Up. Some networks (e.g. Infiniband) take a long time to reach link-up; you may have to wait several seconds.
  6. Disconnect the network cable.
  7. Use ifstat to verify that the link state is reported as Down (or some more specific link error, if the driver uses netdev_link_err())
  8. Reconnect the network cable.
  9. Use ifstat to verify that the link state is again reported as Up.

Troubleshooting

You may find that your driver is capable of detecting the link state at the time that the interface is opened (using ifopen), but does not respond to subsequent link state changes such as a cable being disconnected.

Most NICs support a link state change interrupt, which is typically reported via the same mechanism used to report TX and RX completions. Your poll() routine should check for a reported link state change and react appropriately.