alloc_netdev_mqs() / alloc_netdev() reserve extra space for driver
private data which gets freed when the network device is freed. If
separately allocated data is attached to the network device
-(netdev_priv()) then it is up to the module exit handler to free that.
+(extra pointers stored in the device private struct) then it is up
+to the module exit handler to free that.
There are two groups of APIs for registering struct net_device.
First group can be used in normal contexts where ``rtnl_lock`` is not already
held: register_netdev(), unregister_netdev().
Second group can be used when ``rtnl_lock`` is already held:
-register_netdevice(), unregister_netdevice(), free_netdevice().
+register_netdevice(), unregister_netdevice(), free_netdev().
Simple drivers
--------------
goto err_undo;
/* net_device is visible to the user! */
+ return 0;
err_undo:
/* ... undo the device setup ... */
Note that after calling register_netdev() the device is visible in the system.
Users can open it and start sending / receiving traffic immediately,
-or run any other callback, so all initialization must be done prior to
+or run any other callback, so all initialization must be **complete** prior to
registration.
unregister_netdev() closes the device and waits for all users to be done
There is no explicit constructor callback, driver "constructs" the private
netdev state after allocating it and before registration.
-Setting struct net_device.needs_free_netdev makes core call free_netdevice()
+Setting struct net_device.needs_free_netdev makes core call free_netdev()
automatically after unregister_netdevice() when all references to the device
are gone. It only takes effect after a successful call to register_netdevice()
so if register_netdevice() fails driver is responsible for calling
lock if the driver implements queue management or shaper API.
Context: process
-ndo_get_stats:
+ndo_get_stats / ndo_get_stats64:
Synchronization: RCU (can be called concurrently with the stats
update path).
Context: atomic (can't sleep under RCU)
ndo_start_xmit:
Synchronization: __netif_tx_lock spinlock.
- When the driver sets dev->lltx this will be
- called without holding netif_tx_lock. In this case the driver
- has to lock by itself when needed.
- The locking there should also properly protect against
- set_rx_mode. WARNING: use of dev->lltx is deprecated.
- Don't use it for new drivers.
+ When the driver sets dev->lltx this will be called without holding
+ netif_tx_lock. dev->lltx is meant for software drivers only, since
+ they often have no per-queue state.
Context: Process with BHs disabled or BH (timer),
will be called with interrupts disabled by netconsole.
lock if the driver implements queue management or shaper API.
ndo_setup_tc:
- ``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
- (i.e. no ``rtnl_lock`` and no device instance lock). The rest of
- ``tc_setup_type`` types run under netdev instance lock if the driver
+ Locking depends on ``tc_setup_type``. For most types the callback
+ is invoked under ``rtnl_lock`` and netdev instance lock if the driver
implements queue management or shaper API.
+ For ``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` ``rtnl_lock`` may or
+ may not be held, and the netdev instance lock is not held.
+ ``TC_SETUP_BLOCK`` runs under ``block->cb_lock`` and ``TC_SETUP_FT``
+ runs under ``flowtable->flow_block_lock``.
+
Most ndo callbacks not specified in the list above are running
under ``rtnl_lock``. In addition, netdev instance lock is taken as well if
the driver implements queue management or shaper API.