netdev-features.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. Netdev features mess and how to get out from it alive
  2. =====================================================
  3. Author:
  4. Michał Mirosław <mirq-linux@rere.qmqm.pl>
  5. Part I: Feature sets
  6. ======================
  7. Long gone are the days when a network card would just take and give packets
  8. verbatim. Today's devices add multiple features and bugs (read: offloads)
  9. that relieve an OS of various tasks like generating and checking checksums,
  10. splitting packets, classifying them. Those capabilities and their state
  11. are commonly referred to as netdev features in Linux kernel world.
  12. There are currently three sets of features relevant to the driver, and
  13. one used internally by network core:
  14. 1. netdev->hw_features set contains features whose state may possibly
  15. be changed (enabled or disabled) for a particular device by user's
  16. request. This set should be initialized in ndo_init callback and not
  17. changed later.
  18. 2. netdev->features set contains features which are currently enabled
  19. for a device. This should be changed only by network core or in
  20. error paths of ndo_set_features callback.
  21. 3. netdev->vlan_features set contains features whose state is inherited
  22. by child VLAN devices (limits netdev->features set). This is currently
  23. used for all VLAN devices whether tags are stripped or inserted in
  24. hardware or software.
  25. 4. netdev->wanted_features set contains feature set requested by user.
  26. This set is filtered by ndo_fix_features callback whenever it or
  27. some device-specific conditions change. This set is internal to
  28. networking core and should not be referenced in drivers.
  29. Part II: Controlling enabled features
  30. =======================================
  31. When current feature set (netdev->features) is to be changed, new set
  32. is calculated and filtered by calling ndo_fix_features callback
  33. and netdev_fix_features(). If the resulting set differs from current
  34. set, it is passed to ndo_set_features callback and (if the callback
  35. returns success) replaces value stored in netdev->features.
  36. NETDEV_FEAT_CHANGE notification is issued after that whenever current
  37. set might have changed.
  38. The following events trigger recalculation:
  39. 1. device's registration, after ndo_init returned success
  40. 2. user requested changes in features state
  41. 3. netdev_update_features() is called
  42. ndo_*_features callbacks are called with rtnl_lock held. Missing callbacks
  43. are treated as always returning success.
  44. A driver that wants to trigger recalculation must do so by calling
  45. netdev_update_features() while holding rtnl_lock. This should not be done
  46. from ndo_*_features callbacks. netdev->features should not be modified by
  47. driver except by means of ndo_fix_features callback.
  48. Part III: Implementation hints
  49. ================================
  50. * ndo_fix_features:
  51. All dependencies between features should be resolved here. The resulting
  52. set can be reduced further by networking core imposed limitations (as coded
  53. in netdev_fix_features()). For this reason it is safer to disable a feature
  54. when its dependencies are not met instead of forcing the dependency on.
  55. This callback should not modify hardware nor driver state (should be
  56. stateless). It can be called multiple times between successive
  57. ndo_set_features calls.
  58. Callback must not alter features contained in NETIF_F_SOFT_FEATURES or
  59. NETIF_F_NEVER_CHANGE sets. The exception is NETIF_F_VLAN_CHALLENGED but
  60. care must be taken as the change won't affect already configured VLANs.
  61. * ndo_set_features:
  62. Hardware should be reconfigured to match passed feature set. The set
  63. should not be altered unless some error condition happens that can't
  64. be reliably detected in ndo_fix_features. In this case, the callback
  65. should update netdev->features to match resulting hardware state.
  66. Errors returned are not (and cannot be) propagated anywhere except dmesg.
  67. (Note: successful return is zero, >0 means silent error.)
  68. Part IV: Features
  69. ===================
  70. For current list of features, see include/linux/netdev_features.h.
  71. This section describes semantics of some of them.
  72. * Transmit checksumming
  73. For complete description, see comments near the top of include/linux/skbuff.h.
  74. Note: NETIF_F_HW_CSUM is a superset of NETIF_F_IP_CSUM + NETIF_F_IPV6_CSUM.
  75. It means that device can fill TCP/UDP-like checksum anywhere in the packets
  76. whatever headers there might be.
  77. * Transmit TCP segmentation offload
  78. NETIF_F_TSO_ECN means that hardware can properly split packets with CWR bit
  79. set, be it TCPv4 (when NETIF_F_TSO is enabled) or TCPv6 (NETIF_F_TSO6).
  80. * Transmit DMA from high memory
  81. On platforms where this is relevant, NETIF_F_HIGHDMA signals that
  82. ndo_start_xmit can handle skbs with frags in high memory.
  83. * Transmit scatter-gather
  84. Those features say that ndo_start_xmit can handle fragmented skbs:
  85. NETIF_F_SG --- paged skbs (skb_shinfo()->frags), NETIF_F_FRAGLIST ---
  86. chained skbs (skb->next/prev list).
  87. * Software features
  88. Features contained in NETIF_F_SOFT_FEATURES are features of networking
  89. stack. Driver should not change behaviour based on them.
  90. * LLTX driver (deprecated for hardware drivers)
  91. NETIF_F_LLTX should be set in drivers that implement their own locking in
  92. transmit path or don't need locking at all (e.g. software tunnels).
  93. In ndo_start_xmit, it is recommended to use a try_lock and return
  94. NETDEV_TX_LOCKED when the spin lock fails. The locking should also properly
  95. protect against other callbacks (the rules you need to find out).
  96. Don't use it for new drivers.
  97. * netns-local device
  98. NETIF_F_NETNS_LOCAL is set for devices that are not allowed to move between
  99. network namespaces (e.g. loopback).
  100. Don't use it in drivers.
  101. * VLAN challenged
  102. NETIF_F_VLAN_CHALLENGED should be set for devices which can't cope with VLAN
  103. headers. Some drivers set this because the cards can't handle the bigger MTU.
  104. [FIXME: Those cases could be fixed in VLAN code by allowing only reduced-MTU
  105. VLANs. This may be not useful, though.]
  106. * rx-fcs
  107. This requests that the NIC append the Ethernet Frame Checksum (FCS)
  108. to the end of the skb data. This allows sniffers and other tools to
  109. read the CRC recorded by the NIC on receipt of the packet.
  110. * rx-all
  111. This requests that the NIC receive all possible frames, including errored
  112. frames (such as bad FCS, etc). This can be helpful when sniffing a link with
  113. bad packets on it. Some NICs may receive more packets if also put into normal
  114. PROMISC mode.