1.. SPDX-License-Identifier: GPL-2.0 2 3===================== 4Softnet Driver Issues 5===================== 6 7Probing guidelines 8================== 9 10Address validation 11------------------ 12 13Any hardware layer address you obtain for your device should 14be verified. For example, for ethernet check it with 15linux/etherdevice.h:is_valid_ether_addr() 16 17Close/stop guidelines 18===================== 19 20Quiescence 21---------- 22 23After the ndo_stop routine has been called, the hardware must 24not receive or transmit any data. All in flight packets must 25be aborted. If necessary, poll or wait for completion of 26any reset commands. 27 28Auto-close 29---------- 30 31The ndo_stop routine will be called by unregister_netdevice 32if device is still UP. 33 34Transmit path guidelines 35======================== 36 37Stop queues in advance 38---------------------- 39 40The ndo_start_xmit method must not return NETDEV_TX_BUSY under 41any normal circumstances. It is considered a hard error unless 42there is no way your device can tell ahead of time when its 43transmit function will become busy. 44 45Instead it must maintain the queue properly. For example, 46for a driver implementing scatter-gather this means: 47 48.. code-block:: c 49 50 static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb, 51 struct net_device *dev) 52 { 53 struct drv *dp = netdev_priv(dev); 54 55 lock_tx(dp); 56 //... 57 /* This is a hard error log it. */ 58 if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) { 59 netif_stop_queue(dev); 60 unlock_tx(dp); 61 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n", 62 dev->name); 63 return NETDEV_TX_BUSY; 64 } 65 66 //... queue packet to card ... 67 //... update tx consumer index ... 68 69 if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1)) 70 netif_stop_queue(dev); 71 72 //... 73 unlock_tx(dp); 74 //... 75 return NETDEV_TX_OK; 76 } 77 78And then at the end of your TX reclamation event handling: 79 80.. code-block:: c 81 82 if (netif_queue_stopped(dp->dev) && 83 TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1)) 84 netif_wake_queue(dp->dev); 85 86For a non-scatter-gather supporting card, the three tests simply become: 87 88.. code-block:: c 89 90 /* This is a hard error log it. */ 91 if (TX_BUFFS_AVAIL(dp) <= 0) 92 93and: 94 95.. code-block:: c 96 97 if (TX_BUFFS_AVAIL(dp) == 0) 98 99and: 100 101.. code-block:: c 102 103 if (netif_queue_stopped(dp->dev) && 104 TX_BUFFS_AVAIL(dp) > 0) 105 netif_wake_queue(dp->dev); 106 107Lockless queue stop / wake helper macros 108~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 109 110.. kernel-doc:: include/net/netdev_queues.h 111 :doc: Lockless queue stopping / waking helpers. 112 113No exclusive ownership 114---------------------- 115 116An ndo_start_xmit method must not modify the shared parts of a 117cloned SKB. 118 119Timely completions 120------------------ 121 122Do not forget that once you return NETDEV_TX_OK from your 123ndo_start_xmit method, it is your driver's responsibility to free 124up the SKB and in some finite amount of time. 125 126For example, this means that it is not allowed for your TX 127mitigation scheme to let TX packets "hang out" in the TX 128ring unreclaimed forever if no new TX packets are sent. 129This error can deadlock sockets waiting for send buffer room 130to be freed up. 131 132If you return NETDEV_TX_BUSY from the ndo_start_xmit method, you 133must not keep any reference to that SKB and you must not attempt 134to free it up. 135