1 .. SPDX-License-Identifier: GPL-2.0
3 =====================================
4 Network Devices, the Kernel, and You!
5 =====================================
10 The following is a random collection of documentation regarding
13 struct net_device allocation rules
14 ==================================
15 Network device structures need to persist even after module is unloaded and
16 must be allocated with alloc_netdev_mqs() and friends.
17 If device has registered successfully, it will be freed on last use
18 by free_netdev(). This is required to handle the pathologic case cleanly
19 (example: rmmod mydriver </sys/class/net/myeth/mtu )
21 alloc_netdev_mqs()/alloc_netdev() reserve extra space for driver
22 private data which gets freed when the network device is freed. If
23 separately allocated data is attached to the network device
24 (netdev_priv(dev)) then it is up to the module exit handler to free that.
28 Each network device has a Maximum Transfer Unit. The MTU does not
29 include any link layer protocol overhead. Upper layer protocols must
30 not pass a socket buffer (skb) to a device to transmit with more data
31 than the mtu. The MTU does not include link layer header overhead, so
32 for example on Ethernet if the standard MTU is 1500 bytes used, the
33 actual skb will contain up to 1514 bytes because of the Ethernet
34 header. Devices should allow for the 4 byte VLAN header as well.
36 Segmentation Offload (GSO, TSO) is an exception to this rule. The
37 upper layer protocol may pass a large socket buffer to the device
38 transmit routine, and the device will break that up into separate
39 packets based on the current MTU.
41 MTU is symmetrical and applies both to receive and transmit. A device
42 must be able to receive at least the maximum size packet allowed by
43 the MTU. A network device may use the MTU as mechanism to size receive
44 buffers, but the device should allow packets with VLAN header. With
45 standard Ethernet mtu of 1500 bytes, the device should allow up to
46 1518 byte packets (1500 + 14 header + 4 tag). The device may either:
47 drop, truncate, or pass up oversize packets, but dropping oversize
51 struct net_device synchronization rules
52 =======================================
54 Synchronization: rtnl_lock() semaphore.
58 Synchronization: rtnl_lock() semaphore.
60 Note: netif_running() is guaranteed false
63 Synchronization: rtnl_lock() semaphore.
67 Synchronization: rtnl_lock() semaphore, dev_base_lock rwlock, or RCU.
68 Context: atomic (can't sleep under rwlock or RCU)
71 Synchronization: __netif_tx_lock spinlock.
73 When the driver sets NETIF_F_LLTX in dev->features this will be
74 called without holding netif_tx_lock. In this case the driver
75 has to lock by itself when needed.
76 The locking there should also properly protect against
77 set_rx_mode. WARNING: use of NETIF_F_LLTX is deprecated.
78 Don't use it for new drivers.
80 Context: Process with BHs disabled or BH (timer),
81 will be called with interrupts disabled by netconsole.
85 * NETDEV_TX_OK everything ok.
86 * NETDEV_TX_BUSY Cannot transmit packet, try later
87 Usually a bug, means queue start/stop flow control is broken in
88 the driver. Note: the driver must NOT put the skb in its DMA ring.
91 Synchronization: netif_tx_lock spinlock; all TX queues frozen.
93 Notes: netif_queue_stopped() is guaranteed true
96 Synchronization: netif_addr_lock spinlock.
99 struct napi_struct synchronization rules
100 ========================================
103 NAPI_STATE_SCHED bit in napi->state. Device
104 driver's ndo_stop method will invoke napi_disable() on
105 all NAPI instances which will do a sleeping poll on the
106 NAPI_STATE_SCHED napi->state bit, waiting for all pending
107 NAPI activity to cease.
111 will be called with interrupts disabled by netconsole.