~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/networking/driver.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php