blob: 2128e4169c5b40ec6605f5952a2516003c531402 [file] [log] [blame]
Randy Dunlap98766fb2005-11-21 21:32:31 -08001Document about softnet driver issues
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
3Transmit path guidelines:
4
Ben Hutchingsb3cf6542012-04-05 14:39:47 +000051) The ndo_start_xmit method must never return '1' under any
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 normal circumstances. It is considered a hard error unless
7 there is no way your device can tell ahead of time when it's
8 transmit function will become busy.
9
10 Instead it must maintain the queue properly. For example,
11 for a driver implementing scatter-gather this means:
12
13 static int drv_hard_start_xmit(struct sk_buff *skb,
14 struct net_device *dev)
15 {
Wang Chenb74ca3a2008-12-08 01:14:16 -080016 struct drv *dp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18 lock_tx(dp);
19 ...
20 /* This is a hard error log it. */
21 if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) {
22 netif_stop_queue(dev);
23 unlock_tx(dp);
24 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
25 dev->name);
26 return 1;
27 }
28
29 ... queue packet to card ...
30 ... update tx consumer index ...
31
32 if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1))
33 netif_stop_queue(dev);
34
35 ...
36 unlock_tx(dp);
37 ...
38 }
39
Matt LaPlanted6bc8ac2006-10-03 22:54:15 +020040 And then at the end of your TX reclamation event handling:
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 if (netif_queue_stopped(dp->dev) &&
43 TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1))
44 netif_wake_queue(dp->dev);
45
46 For a non-scatter-gather supporting card, the three tests simply become:
47
48 /* This is a hard error log it. */
49 if (TX_BUFFS_AVAIL(dp) <= 0)
50
51 and:
52
53 if (TX_BUFFS_AVAIL(dp) == 0)
54
55 and:
56
57 if (netif_queue_stopped(dp->dev) &&
58 TX_BUFFS_AVAIL(dp) > 0)
59 netif_wake_queue(dp->dev);
60
Ben Hutchingsde7aca12012-04-05 14:40:06 +0000612) An ndo_start_xmit method must not modify the shared parts of a
Matti Linnanvuorice3ba132008-01-15 06:25:27 -080062 cloned SKB.
63
Ben Hutchingsde7aca12012-04-05 14:40:06 +0000643) Do not forget that once you return 0 from your ndo_start_xmit
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 method, it is your driver's responsibility to free up the SKB
66 and in some finite amount of time.
67
68 For example, this means that it is not allowed for your TX
69 mitigation scheme to let TX packets "hang out" in the TX
70 ring unreclaimed forever if no new TX packets are sent.
71 This error can deadlock sockets waiting for send buffer room
72 to be freed up.
73
Ben Hutchingsb3cf6542012-04-05 14:39:47 +000074 If you return 1 from the ndo_start_xmit method, you must not keep
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 any reference to that SKB and you must not attempt to free it up.
76
77Probing guidelines:
78
791) Any hardware layer address you obtain for your device should
80 be verified. For example, for ethernet check it with
81 linux/etherdevice.h:is_valid_ether_addr()
82
83Close/stop guidelines:
84
Ben Hutchingsb3cf6542012-04-05 14:39:47 +0000851) After the ndo_stop routine has been called, the hardware must
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 not receive or transmit any data. All in flight packets must
87 be aborted. If necessary, poll or wait for completion of
88 any reset commands.
89
Ben Hutchingsb3cf6542012-04-05 14:39:47 +0000902) The ndo_stop routine will be called by unregister_netdevice
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if device is still UP.