blob: a6cab674b676d20eea79fcc1af265cbe22df60ae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2Network Devices, the Kernel, and You!
3
4
5Introduction
6============
7The following is a random collection of documentation regarding
8network devices.
9
10struct net_device allocation rules
11==================================
12Network device structures need to persist even after module is unloaded and
13must be allocated with kmalloc. If device has registered successfully,
14it will be freed on last use by free_netdev. This is required to handle the
15pathologic case cleanly (example: rmmod mydriver </sys/class/net/myeth/mtu )
16
17There are routines in net_init.c to handle the common cases of
18alloc_etherdev, alloc_netdev. These reserve extra space for driver
19private data which gets freed when the network device is freed. If
20separately allocated data is attached to the network device
21(dev->priv) then it is up to the module exit handler to free that.
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct net_device synchronization rules
24=======================================
25dev->open:
26 Synchronization: rtnl_lock() semaphore.
27 Context: process
28
29dev->stop:
30 Synchronization: rtnl_lock() semaphore.
31 Context: process
32 Note1: netif_running() is guaranteed false
33 Note2: dev->poll() is guaranteed to be stopped
34
35dev->do_ioctl:
36 Synchronization: rtnl_lock() semaphore.
37 Context: process
38
39dev->get_stats:
40 Synchronization: dev_base_lock rwlock.
41 Context: nominally process, but don't sleep inside an rwlock
42
43dev->hard_start_xmit:
Herbert Xu932ff272006-06-09 12:20:56 -070044 Synchronization: netif_tx_lock spinlock.
Stephen Hemminger17229332007-07-07 22:59:14 -070045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 When the driver sets NETIF_F_LLTX in dev->features this will be
Herbert Xu932ff272006-06-09 12:20:56 -070047 called without holding netif_tx_lock. In this case the driver
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 has to lock by itself when needed. It is recommended to use a try lock
Stephen Hemminger17229332007-07-07 22:59:14 -070049 for this and return NETDEV_TX_LOCKED when the spin lock fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 The locking there should also properly protect against
Stephen Hemminger17229332007-07-07 22:59:14 -070051 set_multicast_list.
52
53 Context: Process with BHs disabled or BH (timer),
54 will be called with interrupts disabled by netconsole.
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 Return codes:
57 o NETDEV_TX_OK everything ok.
58 o NETDEV_TX_BUSY Cannot transmit packet, try later
59 Usually a bug, means queue start/stop flow control is broken in
60 the driver. Note: the driver must NOT put the skb in its DMA ring.
61 o NETDEV_TX_LOCKED Locking failed, please retry quickly.
62 Only valid when NETIF_F_LLTX is set.
63
64dev->tx_timeout:
Herbert Xu932ff272006-06-09 12:20:56 -070065 Synchronization: netif_tx_lock spinlock.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 Context: BHs disabled
67 Notes: netif_queue_stopped() is guaranteed true
68
69dev->set_multicast_list:
Herbert Xu932ff272006-06-09 12:20:56 -070070 Synchronization: netif_tx_lock spinlock.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 Context: BHs disabled
72
73dev->poll:
74 Synchronization: __LINK_STATE_RX_SCHED bit in dev->state. See
75 dev_close code and comments in net/core/dev.c for more info.
76 Context: softirq
Stephen Hemminger17229332007-07-07 22:59:14 -070077 will be called with interrupts disabled by netconsole.
Linus Torvalds1da177e2005-04-16 15:20:36 -070078