Netdev features mess and how to get out from it alive¶
- Author:
- Michał Mirosław <mirq-linux@rere.qmqm.pl>
Part I: Feature sets¶
Long gone are the days when a network card would just take and give packetsverbatim. Today’s devices add multiple features and bugs (read: offloads)that relieve an OS of various tasks like generating and checking checksums,splitting packets, classifying them. Those capabilities and their stateare commonly referred to as netdev features in Linux kernel world.
There are currently three sets of features relevant to the driver, andone used internally by network core:
- netdev->hw_features set contains features whose state may possiblybe changed (enabled or disabled) for a particular device by user’srequest. This set should be initialized in ndo_init callback and notchanged later.
- netdev->features set contains features which are currently enabledfor a device. This should be changed only by network core or inerror paths of ndo_set_features callback.
- netdev->vlan_features set contains features whose state is inheritedby child VLAN devices (limits netdev->features set). This is currentlyused for all VLAN devices whether tags are stripped or inserted inhardware or software.
- netdev->wanted_features set contains feature set requested by user.This set is filtered by ndo_fix_features callback whenever it orsome device-specific conditions change. This set is internal tonetworking core and should not be referenced in drivers.
Part II: Controlling enabled features¶
When current feature set (netdev->features) is to be changed, new setis calculated and filtered by calling ndo_fix_features callbackand netdev_fix_features(). If the resulting set differs from currentset, it is passed to ndo_set_features callback and (if the callbackreturns success) replaces value stored in netdev->features.NETDEV_FEAT_CHANGE notification is issued after that whenever currentset might have changed.
- The following events trigger recalculation:
- device’s registration, after ndo_init returned success
- user requested changes in features state
netdev_update_features()is called
ndo_*_features callbacks are called with rtnl_lock held. Missing callbacksare treated as always returning success.
A driver that wants to trigger recalculation must do so by callingnetdev_update_features() while holding rtnl_lock. This should not be donefrom ndo_*_features callbacks. netdev->features should not be modified bydriver except by means of ndo_fix_features callback.
Part III: Implementation hints¶
- ndo_fix_features:
All dependencies between features should be resolved here. The resultingset can be reduced further by networking core imposed limitations (as codedin netdev_fix_features()). For this reason it is safer to disable a featurewhen its dependencies are not met instead of forcing the dependency on.
This callback should not modify hardware nor driver state (should bestateless). It can be called multiple times between successivendo_set_features calls.
Callback must not alter features contained in NETIF_F_SOFT_FEATURES orNETIF_F_NEVER_CHANGE sets. The exception is NETIF_F_VLAN_CHALLENGED butcare must be taken as the change won’t affect already configured VLANs.
- ndo_set_features:
Hardware should be reconfigured to match passed feature set. The setshould not be altered unless some error condition happens that can’tbe reliably detected in ndo_fix_features. In this case, the callbackshould update netdev->features to match resulting hardware state.Errors returned are not (and cannot be) propagated anywhere except dmesg.(Note: successful return is zero, >0 means silent error.)
Part IV: Features¶
For current list of features, see include/linux/netdev_features.h.This section describes semantics of some of them.
- Transmit checksumming
For complete description, see comments near the top of include/linux/skbuff.h.
Note: NETIF_F_HW_CSUM is a superset of NETIF_F_IP_CSUM + NETIF_F_IPV6_CSUM.It means that device can fill TCP/UDP-like checksum anywhere in the packetswhatever headers there might be.
- Transmit TCP segmentation offload
NETIF_F_TSO_ECN means that hardware can properly split packets with CWR bitset, be it TCPv4 (when NETIF_F_TSO is enabled) or TCPv6 (NETIF_F_TSO6).
- Transmit UDP segmentation offload
NETIF_F_GSO_UDP_L4 accepts a single UDP header with a payload that exceedsgso_size. On segmentation, it segments the payload on gso_size boundaries andreplicates the network and UDP headers (fixing up the last one if less thangso_size).
- Transmit DMA from high memory
On platforms where this is relevant, NETIF_F_HIGHDMA signals thatndo_start_xmit can handle skbs with frags in high memory.
- Transmit scatter-gather
Those features say that ndo_start_xmit can handle fragmented skbs:NETIF_F_SG — paged skbs (skb_shinfo()->frags), NETIF_F_FRAGLIST —chained skbs (skb->next/prev list).
- Software features
Features contained in NETIF_F_SOFT_FEATURES are features of networkingstack. Driver should not change behaviour based on them.
- LLTX driver (deprecated for hardware drivers)
NETIF_F_LLTX is meant to be used by drivers that don’t need locking at all,e.g. software tunnels.
This is also used in a few legacy drivers that implement theirown locking, don’t use it for new (hardware) drivers.
- netns-local device
NETIF_F_NETNS_LOCAL is set for devices that are not allowed to move betweennetwork namespaces (e.g. loopback).
Don’t use it in drivers.
- VLAN challenged
NETIF_F_VLAN_CHALLENGED should be set for devices which can’t cope with VLANheaders. Some drivers set this because the cards can’t handle the bigger MTU.[FIXME: Those cases could be fixed in VLAN code by allowing only reduced-MTUVLANs. This may be not useful, though.]
- rx-fcs
This requests that the NIC append the Ethernet Frame Checksum (FCS)to the end of the skb data. This allows sniffers and other tools toread the CRC recorded by the NIC on receipt of the packet.
- rx-all
This requests that the NIC receive all possible frames, including erroredframes (such as bad FCS, etc). This can be helpful when sniffing a link withbad packets on it. Some NICs may receive more packets if also put into normalPROMISC mode.
- rx-gro-hw
This requests that the NIC enables Hardware GRO (generic receive offload).Hardware GRO is basically the exact reverse of TSO, and is generallystricter than Hardware LRO. A packet stream merged by Hardware GRO mustbe re-segmentable by GSO or TSO back to the exact original packet stream.Hardware GRO is dependent on RXCSUM since every packet successfully mergedby hardware must also have the checksum verified by hardware.