Softnet Driver Issues¶
Transmit path guidelines:
The ndo_start_xmit method must not return NETDEV_TX_BUSY underany normal circumstances. It is considered a hard error unlessthere is no way your device can tell ahead of time when it’stransmit function will become busy.
Instead it must maintain the queue properly. For example,for a driver implementing scatter-gather this means:
static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb, struct net_device *dev){ struct drv *dp = netdev_priv(dev); lock_tx(dp); ... /* This is a hard error log it. */ if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) { netif_stop_queue(dev); unlock_tx(dp); printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n", dev->name); return NETDEV_TX_BUSY; } ... queue packet to card ... ... update tx consumer index ... if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1)) netif_stop_queue(dev); ... unlock_tx(dp); ... return NETDEV_TX_OK;}And then at the end of your TX reclamation event handling:
if (netif_queue_stopped(dp->dev) && TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1)) netif_wake_queue(dp->dev);
For a non-scatter-gather supporting card, the three tests simply become:
/* This is a hard error log it. */if (TX_BUFFS_AVAIL(dp) <= 0)
and:
if (TX_BUFFS_AVAIL(dp) == 0)
and:
if (netif_queue_stopped(dp->dev) && TX_BUFFS_AVAIL(dp) > 0) netif_wake_queue(dp->dev);
An ndo_start_xmit method must not modify the shared parts of acloned SKB.
Do not forget that once you return NETDEV_TX_OK from yourndo_start_xmit method, it is your driver’s responsibility to freeup the SKB and in some finite amount of time.
For example, this means that it is not allowed for your TXmitigation scheme to let TX packets “hang out” in the TXring unreclaimed forever if no new TX packets are sent.This error can deadlock sockets waiting for send buffer roomto be freed up.
If you return NETDEV_TX_BUSY from the ndo_start_xmit method, youmust not keep any reference to that SKB and you must not attemptto free it up.
Probing guidelines:
- Any hardware layer address you obtain for your device shouldbe verified. For example, for ethernet check it withlinux/etherdevice.h:
is_valid_ether_addr()
Close/stop guidelines:
- After the ndo_stop routine has been called, the hardware mustnot receive or transmit any data. All in flight packets mustbe aborted. If necessary, poll or wait for completion ofany reset commands.
- The ndo_stop routine will be called by unregister_netdeviceif device is still UP.