Blame view

Documentation/networking/driver.txt 2.66 KB
98766fbe6   Randy Dunlap   [PATCH] kernel Do...
1
  Document about softnet driver issues
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  
  Transmit path guidelines:
e34fac1c2   Ben Hutchings   doc, net: Update ...
4
5
  1) The ndo_start_xmit method must not return NETDEV_TX_BUSY under
     any normal circumstances.  It is considered a hard error unless
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
8
9
10
     there is no way your device can tell ahead of time when it's
     transmit function will become busy.
  
     Instead it must maintain the queue properly.  For example,
     for a driver implementing scatter-gather this means:
e34fac1c2   Ben Hutchings   doc, net: Update ...
11
12
  	static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb,
  					       struct net_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  	{
b74ca3a89   Wang Chen   netdevice: Kill n...
14
  		struct drv *dp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
18
19
20
21
22
23
24
  
  		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!
  ",
  			       dev->name);
e34fac1c2   Ben Hutchings   doc, net: Update ...
25
  			return NETDEV_TX_BUSY;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
30
31
32
33
34
35
36
  		}
  
  		... queue packet to card ...
  		... update tx consumer index ...
  
  		if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1))
  			netif_stop_queue(dev);
  
  		...
  		unlock_tx(dp);
  		...
e34fac1c2   Ben Hutchings   doc, net: Update ...
37
  		return NETDEV_TX_OK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
  	}
d6bc8ac9e   Matt LaPlante   Fix typos in Docu...
39
     And then at the end of your TX reclamation event handling:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
  	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);
de7aca16f   Ben Hutchings   doc, net: Remove ...
59
  2) An ndo_start_xmit method must not modify the shared parts of a
ce3ba1399   Matti Linnanvuori   Documentation: ad...
60
     cloned SKB.
e34fac1c2   Ben Hutchings   doc, net: Update ...
61
62
63
  3) Do not forget that once you return NETDEV_TX_OK from your
     ndo_start_xmit method, it is your driver's responsibility to free
     up the SKB and in some finite amount of time.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
67
68
69
  
     For example, this means that it is not allowed for your TX
     mitigation scheme to let TX packets "hang out" in the TX
     ring unreclaimed forever if no new TX packets are sent.
     This error can deadlock sockets waiting for send buffer room
     to be freed up.
e34fac1c2   Ben Hutchings   doc, net: Update ...
70
71
72
     If you return NETDEV_TX_BUSY from the ndo_start_xmit method, you
     must not keep any reference to that SKB and you must not attempt
     to free it up.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
77
78
79
80
  
  Probing guidelines:
  
  1) Any hardware layer address you obtain for your device should
     be verified.  For example, for ethernet check it with
     linux/etherdevice.h:is_valid_ether_addr()
  
  Close/stop guidelines:
b3cf65457   Ben Hutchings   doc, net: Update ...
81
  1) After the ndo_stop routine has been called, the hardware must
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
     not receive or transmit any data.  All in flight packets must
     be aborted. If necessary, poll or wait for completion of 
     any reset commands.
b3cf65457   Ben Hutchings   doc, net: Update ...
85
  2) The ndo_stop routine will be called by unregister_netdevice
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
     if device is still UP.