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