/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h

https://github.com/srikard/linux · C Header · 294 lines · 241 code · 45 blank · 8 comment · 0 complexity · 9333b34e9ecfa13775006f2e9a735f3e MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /* Copyright (c) 2018 Mellanox Technologies. */
  3. #ifndef __MLX5E_FLOW_STEER_H__
  4. #define __MLX5E_FLOW_STEER_H__
  5. #include "mod_hdr.h"
  6. enum {
  7. MLX5E_TC_FT_LEVEL = 0,
  8. MLX5E_TC_TTC_FT_LEVEL,
  9. };
  10. struct mlx5e_tc_table {
  11. /* Protects the dynamic assignment of the t parameter
  12. * which is the nic tc root table.
  13. */
  14. struct mutex t_lock;
  15. struct mlx5_flow_table *t;
  16. struct mlx5_fs_chains *chains;
  17. struct rhashtable ht;
  18. struct mod_hdr_tbl mod_hdr;
  19. struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
  20. DECLARE_HASHTABLE(hairpin_tbl, 8);
  21. struct notifier_block netdevice_nb;
  22. struct netdev_net_notifier netdevice_nn;
  23. struct mlx5_tc_ct_priv *ct;
  24. };
  25. struct mlx5e_flow_table {
  26. int num_groups;
  27. struct mlx5_flow_table *t;
  28. struct mlx5_flow_group **g;
  29. };
  30. struct mlx5e_l2_rule {
  31. u8 addr[ETH_ALEN + 2];
  32. struct mlx5_flow_handle *rule;
  33. };
  34. #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
  35. struct mlx5e_vlan_table {
  36. struct mlx5e_flow_table ft;
  37. DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
  38. DECLARE_BITMAP(active_svlans, VLAN_N_VID);
  39. struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
  40. struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
  41. struct mlx5_flow_handle *untagged_rule;
  42. struct mlx5_flow_handle *any_cvlan_rule;
  43. struct mlx5_flow_handle *any_svlan_rule;
  44. bool cvlan_filter_disabled;
  45. };
  46. struct mlx5e_l2_table {
  47. struct mlx5e_flow_table ft;
  48. struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
  49. struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
  50. struct mlx5e_l2_rule broadcast;
  51. struct mlx5e_l2_rule allmulti;
  52. struct mlx5e_l2_rule promisc;
  53. bool broadcast_enabled;
  54. bool allmulti_enabled;
  55. bool promisc_enabled;
  56. };
  57. enum mlx5e_traffic_types {
  58. MLX5E_TT_IPV4_TCP,
  59. MLX5E_TT_IPV6_TCP,
  60. MLX5E_TT_IPV4_UDP,
  61. MLX5E_TT_IPV6_UDP,
  62. MLX5E_TT_IPV4_IPSEC_AH,
  63. MLX5E_TT_IPV6_IPSEC_AH,
  64. MLX5E_TT_IPV4_IPSEC_ESP,
  65. MLX5E_TT_IPV6_IPSEC_ESP,
  66. MLX5E_TT_IPV4,
  67. MLX5E_TT_IPV6,
  68. MLX5E_TT_ANY,
  69. MLX5E_NUM_TT,
  70. MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
  71. };
  72. struct mlx5e_tirc_config {
  73. u8 l3_prot_type;
  74. u8 l4_prot_type;
  75. u32 rx_hash_fields;
  76. };
  77. #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\
  78. MLX5_HASH_FIELD_SEL_DST_IP)
  79. #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\
  80. MLX5_HASH_FIELD_SEL_DST_IP |\
  81. MLX5_HASH_FIELD_SEL_L4_SPORT |\
  82. MLX5_HASH_FIELD_SEL_L4_DPORT)
  83. #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\
  84. MLX5_HASH_FIELD_SEL_DST_IP |\
  85. MLX5_HASH_FIELD_SEL_IPSEC_SPI)
  86. enum mlx5e_tunnel_types {
  87. MLX5E_TT_IPV4_GRE,
  88. MLX5E_TT_IPV6_GRE,
  89. MLX5E_TT_IPV4_IPIP,
  90. MLX5E_TT_IPV6_IPIP,
  91. MLX5E_TT_IPV4_IPV6,
  92. MLX5E_TT_IPV6_IPV6,
  93. MLX5E_NUM_TUNNEL_TT,
  94. };
  95. bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev);
  96. struct mlx5e_ttc_rule {
  97. struct mlx5_flow_handle *rule;
  98. struct mlx5_flow_destination default_dest;
  99. };
  100. /* L3/L4 traffic type classifier */
  101. struct mlx5e_ttc_table {
  102. struct mlx5e_flow_table ft;
  103. struct mlx5e_ttc_rule rules[MLX5E_NUM_TT];
  104. struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
  105. };
  106. /* NIC prio FTS */
  107. enum {
  108. MLX5E_VLAN_FT_LEVEL = 0,
  109. MLX5E_L2_FT_LEVEL,
  110. MLX5E_TTC_FT_LEVEL,
  111. MLX5E_INNER_TTC_FT_LEVEL,
  112. #ifdef CONFIG_MLX5_EN_TLS
  113. MLX5E_ACCEL_FS_TCP_FT_LEVEL,
  114. #endif
  115. #ifdef CONFIG_MLX5_EN_ARFS
  116. MLX5E_ARFS_FT_LEVEL,
  117. #endif
  118. #ifdef CONFIG_MLX5_EN_IPSEC
  119. MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
  120. MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
  121. #endif
  122. };
  123. #define MLX5E_TTC_NUM_GROUPS 3
  124. #define MLX5E_TTC_GROUP1_SIZE (BIT(3) + MLX5E_NUM_TUNNEL_TT)
  125. #define MLX5E_TTC_GROUP2_SIZE BIT(1)
  126. #define MLX5E_TTC_GROUP3_SIZE BIT(0)
  127. #define MLX5E_TTC_TABLE_SIZE (MLX5E_TTC_GROUP1_SIZE +\
  128. MLX5E_TTC_GROUP2_SIZE +\
  129. MLX5E_TTC_GROUP3_SIZE)
  130. #define MLX5E_INNER_TTC_NUM_GROUPS 3
  131. #define MLX5E_INNER_TTC_GROUP1_SIZE BIT(3)
  132. #define MLX5E_INNER_TTC_GROUP2_SIZE BIT(1)
  133. #define MLX5E_INNER_TTC_GROUP3_SIZE BIT(0)
  134. #define MLX5E_INNER_TTC_TABLE_SIZE (MLX5E_INNER_TTC_GROUP1_SIZE +\
  135. MLX5E_INNER_TTC_GROUP2_SIZE +\
  136. MLX5E_INNER_TTC_GROUP3_SIZE)
  137. #ifdef CONFIG_MLX5_EN_RXNFC
  138. struct mlx5e_ethtool_table {
  139. struct mlx5_flow_table *ft;
  140. int num_rules;
  141. };
  142. #define ETHTOOL_NUM_L3_L4_FTS 7
  143. #define ETHTOOL_NUM_L2_FTS 4
  144. struct mlx5e_ethtool_steering {
  145. struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
  146. struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
  147. struct list_head rules;
  148. int tot_num_rules;
  149. };
  150. void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
  151. void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
  152. int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
  153. int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
  154. struct ethtool_rxnfc *info, u32 *rule_locs);
  155. #else
  156. static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { }
  157. static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
  158. static inline int mlx5e_ethtool_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  159. { return -EOPNOTSUPP; }
  160. static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
  161. struct ethtool_rxnfc *info, u32 *rule_locs)
  162. { return -EOPNOTSUPP; }
  163. #endif /* CONFIG_MLX5_EN_RXNFC */
  164. #ifdef CONFIG_MLX5_EN_ARFS
  165. #define ARFS_HASH_SHIFT BITS_PER_BYTE
  166. #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
  167. struct arfs_table {
  168. struct mlx5e_flow_table ft;
  169. struct mlx5_flow_handle *default_rule;
  170. struct hlist_head rules_hash[ARFS_HASH_SIZE];
  171. };
  172. enum arfs_type {
  173. ARFS_IPV4_TCP,
  174. ARFS_IPV6_TCP,
  175. ARFS_IPV4_UDP,
  176. ARFS_IPV6_UDP,
  177. ARFS_NUM_TYPES,
  178. };
  179. struct mlx5e_arfs_tables {
  180. struct arfs_table arfs_tables[ARFS_NUM_TYPES];
  181. /* Protect aRFS rules list */
  182. spinlock_t arfs_lock;
  183. struct list_head rules;
  184. int last_filter_id;
  185. struct workqueue_struct *wq;
  186. };
  187. int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
  188. void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
  189. int mlx5e_arfs_enable(struct mlx5e_priv *priv);
  190. int mlx5e_arfs_disable(struct mlx5e_priv *priv);
  191. int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
  192. u16 rxq_index, u32 flow_id);
  193. #else
  194. static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
  195. static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
  196. static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
  197. static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
  198. #endif
  199. #ifdef CONFIG_MLX5_EN_TLS
  200. struct mlx5e_accel_fs_tcp;
  201. #endif
  202. struct mlx5e_flow_steering {
  203. struct mlx5_flow_namespace *ns;
  204. struct mlx5_flow_namespace *egress_ns;
  205. #ifdef CONFIG_MLX5_EN_RXNFC
  206. struct mlx5e_ethtool_steering ethtool;
  207. #endif
  208. struct mlx5e_tc_table tc;
  209. struct mlx5e_vlan_table vlan;
  210. struct mlx5e_l2_table l2;
  211. struct mlx5e_ttc_table ttc;
  212. struct mlx5e_ttc_table inner_ttc;
  213. #ifdef CONFIG_MLX5_EN_ARFS
  214. struct mlx5e_arfs_tables arfs;
  215. #endif
  216. #ifdef CONFIG_MLX5_EN_TLS
  217. struct mlx5e_accel_fs_tcp *accel_tcp;
  218. #endif
  219. };
  220. struct ttc_params {
  221. struct mlx5_flow_table_attr ft_attr;
  222. u32 any_tt_tirn;
  223. u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
  224. struct mlx5e_ttc_table *inner_ttc;
  225. };
  226. void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
  227. void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
  228. void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
  229. int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
  230. struct mlx5e_ttc_table *ttc);
  231. void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
  232. struct mlx5e_ttc_table *ttc);
  233. int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
  234. struct mlx5e_ttc_table *ttc);
  235. void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
  236. struct mlx5e_ttc_table *ttc);
  237. void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
  238. int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
  239. struct mlx5_flow_destination *new_dest);
  240. struct mlx5_flow_destination
  241. mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
  242. int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type);
  243. void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
  244. void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
  245. int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
  246. void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
  247. bool mlx5e_tunnel_proto_supported(struct mlx5_core_dev *mdev, u8 proto_type);
  248. bool mlx5e_any_tunnel_proto_supported(struct mlx5_core_dev *mdev);
  249. #endif /* __MLX5E_FLOW_STEER_H__ */