blob: c8f59dbda46f77df6378f1afc7128b0deadcaf49 [file] [log] [blame]
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +02001.. SPDX-License-Identifier: GPL-2.0
2
3=====================
4Softnet Driver Issues
5=====================
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7Transmit path guidelines:
8
Ben Hutchingse34fac12012-04-05 14:40:25 +000091) The ndo_start_xmit method must not return NETDEV_TX_BUSY under
10 any normal circumstances. It is considered a hard error unless
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 there is no way your device can tell ahead of time when it's
12 transmit function will become busy.
13
14 Instead it must maintain the queue properly. For example,
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020015 for a driver implementing scatter-gather this means::
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Ben Hutchingse34fac12012-04-05 14:40:25 +000017 static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb,
18 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 {
Wang Chenb74ca3a2008-12-08 01:14:16 -080020 struct drv *dp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22 lock_tx(dp);
23 ...
24 /* This is a hard error log it. */
25 if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) {
26 netif_stop_queue(dev);
27 unlock_tx(dp);
28 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
29 dev->name);
Ben Hutchingse34fac12012-04-05 14:40:25 +000030 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 }
32
33 ... queue packet to card ...
34 ... update tx consumer index ...
35
36 if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1))
37 netif_stop_queue(dev);
38
39 ...
40 unlock_tx(dp);
41 ...
Ben Hutchingse34fac12012-04-05 14:40:25 +000042 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 }
44
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020045 And then at the end of your TX reclamation event handling::
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 if (netif_queue_stopped(dp->dev) &&
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020048 TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 netif_wake_queue(dp->dev);
50
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020051 For a non-scatter-gather supporting card, the three tests simply become::
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 /* This is a hard error log it. */
54 if (TX_BUFFS_AVAIL(dp) <= 0)
55
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020056 and::
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 if (TX_BUFFS_AVAIL(dp) == 0)
59
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020060 and::
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 if (netif_queue_stopped(dp->dev) &&
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020063 TX_BUFFS_AVAIL(dp) > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 netif_wake_queue(dp->dev);
65
Ben Hutchingsde7aca12012-04-05 14:40:06 +0000662) An ndo_start_xmit method must not modify the shared parts of a
Matti Linnanvuorice3ba132008-01-15 06:25:27 -080067 cloned SKB.
68
Ben Hutchingse34fac12012-04-05 14:40:25 +0000693) Do not forget that once you return NETDEV_TX_OK from your
70 ndo_start_xmit method, it is your driver's responsibility to free
71 up the SKB and in some finite amount of time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 For example, this means that it is not allowed for your TX
74 mitigation scheme to let TX packets "hang out" in the TX
75 ring unreclaimed forever if no new TX packets are sent.
76 This error can deadlock sockets waiting for send buffer room
77 to be freed up.
78
Ben Hutchingse34fac12012-04-05 14:40:25 +000079 If you return NETDEV_TX_BUSY from the ndo_start_xmit method, you
80 must not keep any reference to that SKB and you must not attempt
81 to free it up.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83Probing guidelines:
84
851) Any hardware layer address you obtain for your device should
86 be verified. For example, for ethernet check it with
87 linux/etherdevice.h:is_valid_ether_addr()
88
89Close/stop guidelines:
90
Ben Hutchingsb3cf6542012-04-05 14:39:47 +0000911) After the ndo_stop routine has been called, the hardware must
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 not receive or transmit any data. All in flight packets must
Mauro Carvalho Chehab28d23312020-04-28 00:01:33 +020093 be aborted. If necessary, poll or wait for completion of
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 any reset commands.
95
Ben Hutchingsb3cf6542012-04-05 14:39:47 +0000962) The ndo_stop routine will be called by unregister_netdevice
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if device is still UP.