netdev_features.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Network device features.
  4. */
  5. #ifndef _LINUX_NETDEV_FEATURES_H
  6. #define _LINUX_NETDEV_FEATURES_H
  7. #include <linux/types.h>
  8. #include <linux/bitops.h>
  9. #include <asm/byteorder.h>
  10. typedef u64 netdev_features_t;
  11. enum {
  12. NETIF_F_SG_BIT, /* Scatter/gather IO. */
  13. NETIF_F_IP_CSUM_BIT, /* Can checksum TCP/UDP over IPv4. */
  14. __UNUSED_NETIF_F_1,
  15. NETIF_F_HW_CSUM_BIT, /* Can checksum all the packets. */
  16. NETIF_F_IPV6_CSUM_BIT, /* Can checksum TCP/UDP over IPV6 */
  17. NETIF_F_HIGHDMA_BIT, /* Can DMA to high memory. */
  18. NETIF_F_FRAGLIST_BIT, /* Scatter/gather IO. */
  19. NETIF_F_HW_VLAN_CTAG_TX_BIT, /* Transmit VLAN CTAG HW acceleration */
  20. NETIF_F_HW_VLAN_CTAG_RX_BIT, /* Receive VLAN CTAG HW acceleration */
  21. NETIF_F_HW_VLAN_CTAG_FILTER_BIT,/* Receive filtering on VLAN CTAGs */
  22. NETIF_F_VLAN_CHALLENGED_BIT, /* Device cannot handle VLAN packets */
  23. NETIF_F_GSO_BIT, /* Enable software GSO. */
  24. NETIF_F_LLTX_BIT, /* LockLess TX - deprecated. Please */
  25. /* do not use LLTX in new drivers */
  26. NETIF_F_NETNS_LOCAL_BIT, /* Does not change network namespaces */
  27. NETIF_F_GRO_BIT, /* Generic receive offload */
  28. NETIF_F_LRO_BIT, /* large receive offload */
  29. /**/NETIF_F_GSO_SHIFT, /* keep the order of SKB_GSO_* bits */
  30. NETIF_F_TSO_BIT /* ... TCPv4 segmentation */
  31. = NETIF_F_GSO_SHIFT,
  32. NETIF_F_GSO_ROBUST_BIT, /* ... ->SKB_GSO_DODGY */
  33. NETIF_F_TSO_ECN_BIT, /* ... TCP ECN support */
  34. NETIF_F_TSO_MANGLEID_BIT, /* ... IPV4 ID mangling allowed */
  35. NETIF_F_TSO6_BIT, /* ... TCPv6 segmentation */
  36. NETIF_F_FSO_BIT, /* ... FCoE segmentation */
  37. NETIF_F_GSO_GRE_BIT, /* ... GRE with TSO */
  38. NETIF_F_GSO_GRE_CSUM_BIT, /* ... GRE with csum with TSO */
  39. NETIF_F_GSO_IPXIP4_BIT, /* ... IP4 or IP6 over IP4 with TSO */
  40. NETIF_F_GSO_IPXIP6_BIT, /* ... IP4 or IP6 over IP6 with TSO */
  41. NETIF_F_GSO_UDP_TUNNEL_BIT, /* ... UDP TUNNEL with TSO */
  42. NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT,/* ... UDP TUNNEL with TSO & CSUM */
  43. NETIF_F_GSO_PARTIAL_BIT, /* ... Only segment inner-most L4
  44. * in hardware and all other
  45. * headers in software.
  46. */
  47. NETIF_F_GSO_TUNNEL_REMCSUM_BIT, /* ... TUNNEL with TSO & REMCSUM */
  48. NETIF_F_GSO_SCTP_BIT, /* ... SCTP fragmentation */
  49. NETIF_F_GSO_ESP_BIT, /* ... ESP with TSO */
  50. NETIF_F_GSO_UDP_BIT, /* ... UFO, deprecated except tuntap */
  51. NETIF_F_GSO_UDP_L4_BIT, /* ... UDP payload GSO (not UFO) */
  52. NETIF_F_GSO_FRAGLIST_BIT, /* ... Fraglist GSO */
  53. /**/NETIF_F_GSO_LAST = /* last bit, see GSO_MASK */
  54. NETIF_F_GSO_FRAGLIST_BIT,
  55. NETIF_F_FCOE_CRC_BIT, /* FCoE CRC32 */
  56. NETIF_F_SCTP_CRC_BIT, /* SCTP checksum offload */
  57. NETIF_F_FCOE_MTU_BIT, /* Supports max FCoE MTU, 2158 bytes*/
  58. NETIF_F_NTUPLE_BIT, /* N-tuple filters supported */
  59. NETIF_F_RXHASH_BIT, /* Receive hashing offload */
  60. NETIF_F_RXCSUM_BIT, /* Receive checksumming offload */
  61. NETIF_F_NOCACHE_COPY_BIT, /* Use no-cache copyfromuser */
  62. NETIF_F_LOOPBACK_BIT, /* Enable loopback */
  63. NETIF_F_RXFCS_BIT, /* Append FCS to skb pkt data */
  64. NETIF_F_RXALL_BIT, /* Receive errored frames too */
  65. NETIF_F_HW_VLAN_STAG_TX_BIT, /* Transmit VLAN STAG HW acceleration */
  66. NETIF_F_HW_VLAN_STAG_RX_BIT, /* Receive VLAN STAG HW acceleration */
  67. NETIF_F_HW_VLAN_STAG_FILTER_BIT,/* Receive filtering on VLAN STAGs */
  68. NETIF_F_HW_L2FW_DOFFLOAD_BIT, /* Allow L2 Forwarding in Hardware */
  69. NETIF_F_HW_TC_BIT, /* Offload TC infrastructure */
  70. NETIF_F_HW_ESP_BIT, /* Hardware ESP transformation offload */
  71. NETIF_F_HW_ESP_TX_CSUM_BIT, /* ESP with TX checksum offload */
  72. NETIF_F_RX_UDP_TUNNEL_PORT_BIT, /* Offload of RX port for UDP tunnels */
  73. NETIF_F_HW_TLS_TX_BIT, /* Hardware TLS TX offload */
  74. NETIF_F_HW_TLS_RX_BIT, /* Hardware TLS RX offload */
  75. NETIF_F_GRO_HW_BIT, /* Hardware Generic receive offload */
  76. NETIF_F_HW_TLS_RECORD_BIT, /* Offload TLS record */
  77. NETIF_F_GRO_FRAGLIST_BIT, /* Fraglist GRO */
  78. NETIF_F_HW_MACSEC_BIT, /* Offload MACsec operations */
  79. /*
  80. * Add your fresh new feature above and remember to update
  81. * netdev_features_strings[] in net/ethtool/common.c and maybe
  82. * some feature mask #defines below. Please also describe it
  83. * in Documentation/networking/netdev-features.rst.
  84. */
  85. /**/NETDEV_FEATURE_COUNT
  86. };
  87. /* copy'n'paste compression ;) */
  88. #define __NETIF_F_BIT(bit) ((netdev_features_t)1 << (bit))
  89. #define __NETIF_F(name) __NETIF_F_BIT(NETIF_F_##name##_BIT)
  90. #define NETIF_F_FCOE_CRC __NETIF_F(FCOE_CRC)
  91. #define NETIF_F_FCOE_MTU __NETIF_F(FCOE_MTU)
  92. #define NETIF_F_FRAGLIST __NETIF_F(FRAGLIST)
  93. #define NETIF_F_FSO __NETIF_F(FSO)
  94. #define NETIF_F_GRO __NETIF_F(GRO)
  95. #define NETIF_F_GRO_HW __NETIF_F(GRO_HW)
  96. #define NETIF_F_GSO __NETIF_F(GSO)
  97. #define NETIF_F_GSO_ROBUST __NETIF_F(GSO_ROBUST)
  98. #define NETIF_F_HIGHDMA __NETIF_F(HIGHDMA)
  99. #define NETIF_F_HW_CSUM __NETIF_F(HW_CSUM)
  100. #define NETIF_F_HW_VLAN_CTAG_FILTER __NETIF_F(HW_VLAN_CTAG_FILTER)
  101. #define NETIF_F_HW_VLAN_CTAG_RX __NETIF_F(HW_VLAN_CTAG_RX)
  102. #define NETIF_F_HW_VLAN_CTAG_TX __NETIF_F(HW_VLAN_CTAG_TX)
  103. #define NETIF_F_IP_CSUM __NETIF_F(IP_CSUM)
  104. #define NETIF_F_IPV6_CSUM __NETIF_F(IPV6_CSUM)
  105. #define NETIF_F_LLTX __NETIF_F(LLTX)
  106. #define NETIF_F_LOOPBACK __NETIF_F(LOOPBACK)
  107. #define NETIF_F_LRO __NETIF_F(LRO)
  108. #define NETIF_F_NETNS_LOCAL __NETIF_F(NETNS_LOCAL)
  109. #define NETIF_F_NOCACHE_COPY __NETIF_F(NOCACHE_COPY)
  110. #define NETIF_F_NTUPLE __NETIF_F(NTUPLE)
  111. #define NETIF_F_RXCSUM __NETIF_F(RXCSUM)
  112. #define NETIF_F_RXHASH __NETIF_F(RXHASH)
  113. #define NETIF_F_SCTP_CRC __NETIF_F(SCTP_CRC)
  114. #define NETIF_F_SG __NETIF_F(SG)
  115. #define NETIF_F_TSO6 __NETIF_F(TSO6)
  116. #define NETIF_F_TSO_ECN __NETIF_F(TSO_ECN)
  117. #define NETIF_F_TSO __NETIF_F(TSO)
  118. #define NETIF_F_VLAN_CHALLENGED __NETIF_F(VLAN_CHALLENGED)
  119. #define NETIF_F_RXFCS __NETIF_F(RXFCS)
  120. #define NETIF_F_RXALL __NETIF_F(RXALL)
  121. #define NETIF_F_GSO_GRE __NETIF_F(GSO_GRE)
  122. #define NETIF_F_GSO_GRE_CSUM __NETIF_F(GSO_GRE_CSUM)
  123. #define NETIF_F_GSO_IPXIP4 __NETIF_F(GSO_IPXIP4)
  124. #define NETIF_F_GSO_IPXIP6 __NETIF_F(GSO_IPXIP6)
  125. #define NETIF_F_GSO_UDP_TUNNEL __NETIF_F(GSO_UDP_TUNNEL)
  126. #define NETIF_F_GSO_UDP_TUNNEL_CSUM __NETIF_F(GSO_UDP_TUNNEL_CSUM)
  127. #define NETIF_F_TSO_MANGLEID __NETIF_F(TSO_MANGLEID)
  128. #define NETIF_F_GSO_PARTIAL __NETIF_F(GSO_PARTIAL)
  129. #define NETIF_F_GSO_TUNNEL_REMCSUM __NETIF_F(GSO_TUNNEL_REMCSUM)
  130. #define NETIF_F_GSO_SCTP __NETIF_F(GSO_SCTP)
  131. #define NETIF_F_GSO_ESP __NETIF_F(GSO_ESP)
  132. #define NETIF_F_GSO_UDP __NETIF_F(GSO_UDP)
  133. #define NETIF_F_HW_VLAN_STAG_FILTER __NETIF_F(HW_VLAN_STAG_FILTER)
  134. #define NETIF_F_HW_VLAN_STAG_RX __NETIF_F(HW_VLAN_STAG_RX)
  135. #define NETIF_F_HW_VLAN_STAG_TX __NETIF_F(HW_VLAN_STAG_TX)
  136. #define NETIF_F_HW_L2FW_DOFFLOAD __NETIF_F(HW_L2FW_DOFFLOAD)
  137. #define NETIF_F_HW_TC __NETIF_F(HW_TC)
  138. #define NETIF_F_HW_ESP __NETIF_F(HW_ESP)
  139. #define NETIF_F_HW_ESP_TX_CSUM __NETIF_F(HW_ESP_TX_CSUM)
  140. #define NETIF_F_RX_UDP_TUNNEL_PORT __NETIF_F(RX_UDP_TUNNEL_PORT)
  141. #define NETIF_F_HW_TLS_RECORD __NETIF_F(HW_TLS_RECORD)
  142. #define NETIF_F_GSO_UDP_L4 __NETIF_F(GSO_UDP_L4)
  143. #define NETIF_F_HW_TLS_TX __NETIF_F(HW_TLS_TX)
  144. #define NETIF_F_HW_TLS_RX __NETIF_F(HW_TLS_RX)
  145. #define NETIF_F_GRO_FRAGLIST __NETIF_F(GRO_FRAGLIST)
  146. #define NETIF_F_GSO_FRAGLIST __NETIF_F(GSO_FRAGLIST)
  147. #define NETIF_F_HW_MACSEC __NETIF_F(HW_MACSEC)
  148. /* Finds the next feature with the highest number of the range of start till 0.
  149. */
  150. static inline int find_next_netdev_feature(u64 feature, unsigned long start)
  151. {
  152. /* like BITMAP_LAST_WORD_MASK() for u64
  153. * this sets the most significant 64 - start to 0.
  154. */
  155. feature &= ~0ULL >> (-start & ((sizeof(feature) * 8) - 1));
  156. return fls64(feature) - 1;
  157. }
  158. /* This goes for the MSB to the LSB through the set feature bits,
  159. * mask_addr should be a u64 and bit an int
  160. */
  161. #define for_each_netdev_feature(mask_addr, bit) \
  162. for ((bit) = find_next_netdev_feature((mask_addr), \
  163. NETDEV_FEATURE_COUNT); \
  164. (bit) >= 0; \
  165. (bit) = find_next_netdev_feature((mask_addr), (bit) - 1))
  166. /* Features valid for ethtool to change */
  167. /* = all defined minus driver/device-class-related */
  168. #define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \
  169. NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
  170. /* remember that ((t)1 << t_BITS) is undefined in C99 */
  171. #define NETIF_F_ETHTOOL_BITS ((__NETIF_F_BIT(NETDEV_FEATURE_COUNT - 1) | \
  172. (__NETIF_F_BIT(NETDEV_FEATURE_COUNT - 1) - 1)) & \
  173. ~NETIF_F_NEVER_CHANGE)
  174. /* Segmentation offload feature mask */
  175. #define NETIF_F_GSO_MASK (__NETIF_F_BIT(NETIF_F_GSO_LAST + 1) - \
  176. __NETIF_F_BIT(NETIF_F_GSO_SHIFT))
  177. /* List of IP checksum features. Note that NETIF_F_HW_CSUM should not be
  178. * set in features when NETIF_F_IP_CSUM or NETIF_F_IPV6_CSUM are set--
  179. * this would be contradictory
  180. */
  181. #define NETIF_F_CSUM_MASK (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
  182. NETIF_F_HW_CSUM)
  183. #define NETIF_F_ALL_TSO (NETIF_F_TSO | NETIF_F_TSO6 | \
  184. NETIF_F_TSO_ECN | NETIF_F_TSO_MANGLEID)
  185. #define NETIF_F_ALL_FCOE (NETIF_F_FCOE_CRC | NETIF_F_FCOE_MTU | \
  186. NETIF_F_FSO)
  187. /* List of features with software fallbacks. */
  188. #define NETIF_F_GSO_SOFTWARE (NETIF_F_ALL_TSO | \
  189. NETIF_F_GSO_SCTP)
  190. /*
  191. * If one device supports one of these features, then enable them
  192. * for all in netdev_increment_features.
  193. */
  194. #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \
  195. NETIF_F_SG | NETIF_F_HIGHDMA | \
  196. NETIF_F_FRAGLIST | NETIF_F_VLAN_CHALLENGED)
  197. /*
  198. * If one device doesn't support one of these features, then disable it
  199. * for all in netdev_increment_features.
  200. */
  201. #define NETIF_F_ALL_FOR_ALL (NETIF_F_NOCACHE_COPY | NETIF_F_FSO)
  202. /*
  203. * If upper/master device has these features disabled, they must be disabled
  204. * on all lower/slave devices as well.
  205. */
  206. #define NETIF_F_UPPER_DISABLES NETIF_F_LRO
  207. /* changeable features with no special hardware requirements */
  208. #define NETIF_F_SOFT_FEATURES (NETIF_F_GSO | NETIF_F_GRO)
  209. /* Changeable features with no special hardware requirements that defaults to off. */
  210. #define NETIF_F_SOFT_FEATURES_OFF NETIF_F_GRO_FRAGLIST
  211. #define NETIF_F_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
  212. NETIF_F_HW_VLAN_CTAG_RX | \
  213. NETIF_F_HW_VLAN_CTAG_TX | \
  214. NETIF_F_HW_VLAN_STAG_FILTER | \
  215. NETIF_F_HW_VLAN_STAG_RX | \
  216. NETIF_F_HW_VLAN_STAG_TX)
  217. #define NETIF_F_GSO_ENCAP_ALL (NETIF_F_GSO_GRE | \
  218. NETIF_F_GSO_GRE_CSUM | \
  219. NETIF_F_GSO_IPXIP4 | \
  220. NETIF_F_GSO_IPXIP6 | \
  221. NETIF_F_GSO_UDP_TUNNEL | \
  222. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  223. #endif /* _LINUX_NETDEV_FEATURES_H */