netdevices.txt 2.6 KB

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