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 #include "lib/fs_ttc.h" 9 10 struct mlx5e_post_act; 11 12 enum { 13 MLX5E_TC_FT_LEVEL = 0, 14 MLX5E_TC_TTC_FT_LEVEL, 15 }; 16 17 struct mlx5e_tc_table { 18 /* Protects the dynamic assignment of the t parameter 19 * which is the nic tc root table. 20 */ 21 struct mutex t_lock; 22 struct mlx5_flow_table *t; 23 struct mlx5_fs_chains *chains; 24 struct mlx5e_post_act *post_act; 25 26 struct rhashtable ht; 27 28 struct mod_hdr_tbl mod_hdr; 29 struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */ 30 DECLARE_HASHTABLE(hairpin_tbl, 8); 31 32 struct notifier_block netdevice_nb; 33 struct netdev_net_notifier netdevice_nn; 34 35 struct mlx5_tc_ct_priv *ct; 36 struct mapping_ctx *mapping; 37 }; 38 39 struct mlx5e_flow_table { 40 int num_groups; 41 struct mlx5_flow_table *t; 42 struct mlx5_flow_group **g; 43 }; 44 45 struct mlx5e_l2_rule { 46 u8 addr[ETH_ALEN + 2]; 47 struct mlx5_flow_handle *rule; 48 }; 49 50 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE) 51 52 struct mlx5e_promisc_table { 53 struct mlx5e_flow_table ft; 54 struct mlx5_flow_handle *rule; 55 }; 56 57 /* Forward declaration and APIs to get private fields of vlan_table */ 58 struct mlx5e_vlan_table; 59 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan); 60 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan); 61 62 struct mlx5e_l2_table { 63 struct mlx5e_flow_table ft; 64 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE]; 65 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE]; 66 struct mlx5e_l2_rule broadcast; 67 struct mlx5e_l2_rule allmulti; 68 struct mlx5_flow_handle *trap_rule; 69 bool broadcast_enabled; 70 bool allmulti_enabled; 71 bool promisc_enabled; 72 }; 73 74 #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_TT - 1) 75 76 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\ 77 MLX5_HASH_FIELD_SEL_DST_IP) 78 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\ 79 MLX5_HASH_FIELD_SEL_DST_IP |\ 80 MLX5_HASH_FIELD_SEL_L4_SPORT |\ 81 MLX5_HASH_FIELD_SEL_L4_DPORT) 82 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\ 83 MLX5_HASH_FIELD_SEL_DST_IP |\ 84 MLX5_HASH_FIELD_SEL_IPSEC_SPI) 85 86 /* NIC prio FTS */ 87 enum { 88 MLX5E_PROMISC_FT_LEVEL, 89 MLX5E_VLAN_FT_LEVEL, 90 MLX5E_L2_FT_LEVEL, 91 MLX5E_TTC_FT_LEVEL, 92 MLX5E_INNER_TTC_FT_LEVEL, 93 MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 94 MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 95 #ifdef CONFIG_MLX5_EN_TLS 96 MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 97 #endif 98 #ifdef CONFIG_MLX5_EN_ARFS 99 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 100 #endif 101 #ifdef CONFIG_MLX5_EN_IPSEC 102 MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 103 MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL, 104 #endif 105 }; 106 107 struct mlx5e_priv; 108 109 #ifdef CONFIG_MLX5_EN_RXNFC 110 111 struct mlx5e_ethtool_table { 112 struct mlx5_flow_table *ft; 113 int num_rules; 114 }; 115 116 #define ETHTOOL_NUM_L3_L4_FTS 7 117 #define ETHTOOL_NUM_L2_FTS 4 118 119 struct mlx5e_ethtool_steering { 120 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS]; 121 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS]; 122 struct list_head rules; 123 int tot_num_rules; 124 }; 125 126 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv); 127 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv); 128 int mlx5e_ethtool_set_rxnfc(struct mlx5e_priv *priv, struct ethtool_rxnfc *cmd); 129 int mlx5e_ethtool_get_rxnfc(struct mlx5e_priv *priv, 130 struct ethtool_rxnfc *info, u32 *rule_locs); 131 #else 132 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv) { } 133 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { } 134 static inline int mlx5e_ethtool_set_rxnfc(struct mlx5e_priv *priv, struct ethtool_rxnfc *cmd) 135 { return -EOPNOTSUPP; } 136 static inline int mlx5e_ethtool_get_rxnfc(struct mlx5e_priv *priv, 137 struct ethtool_rxnfc *info, u32 *rule_locs) 138 { return -EOPNOTSUPP; } 139 #endif /* CONFIG_MLX5_EN_RXNFC */ 140 141 #ifdef CONFIG_MLX5_EN_ARFS 142 struct mlx5e_arfs_tables; 143 144 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv); 145 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv); 146 int mlx5e_arfs_enable(struct mlx5e_priv *priv); 147 int mlx5e_arfs_disable(struct mlx5e_priv *priv); 148 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, 149 u16 rxq_index, u32 flow_id); 150 #else 151 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; } 152 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {} 153 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; } 154 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; } 155 #endif 156 157 #ifdef CONFIG_MLX5_EN_TLS 158 struct mlx5e_accel_fs_tcp; 159 #endif 160 161 struct mlx5e_fs_udp; 162 struct mlx5e_fs_any; 163 struct mlx5e_ptp_fs; 164 165 struct mlx5e_flow_steering { 166 struct mlx5_flow_namespace *ns; 167 struct mlx5_flow_namespace *egress_ns; 168 #ifdef CONFIG_MLX5_EN_RXNFC 169 struct mlx5e_ethtool_steering ethtool; 170 #endif 171 struct mlx5e_tc_table tc; 172 struct mlx5e_promisc_table promisc; 173 struct mlx5e_vlan_table *vlan; 174 struct mlx5e_l2_table l2; 175 struct mlx5_ttc_table *ttc; 176 struct mlx5_ttc_table *inner_ttc; 177 #ifdef CONFIG_MLX5_EN_ARFS 178 struct mlx5e_arfs_tables *arfs; 179 #endif 180 #ifdef CONFIG_MLX5_EN_TLS 181 struct mlx5e_accel_fs_tcp *accel_tcp; 182 #endif 183 struct mlx5e_fs_udp *udp; 184 struct mlx5e_fs_any *any; 185 struct mlx5e_ptp_fs *ptp_fs; 186 }; 187 188 void mlx5e_set_ttc_params(struct mlx5e_priv *priv, 189 struct ttc_params *ttc_params, bool tunnel); 190 191 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv); 192 int mlx5e_create_ttc_table(struct mlx5e_priv *priv); 193 194 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft); 195 196 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv); 197 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv); 198 199 int mlx5e_create_flow_steering(struct mlx5e_priv *priv); 200 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv); 201 202 int mlx5e_fs_init(struct mlx5e_priv *priv); 203 void mlx5e_fs_cleanup(struct mlx5e_priv *priv); 204 205 int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int trap_id, int tir_num); 206 void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv); 207 int mlx5e_add_mac_trap(struct mlx5e_priv *priv, int trap_id, int tir_num); 208 void mlx5e_remove_mac_trap(struct mlx5e_priv *priv); 209 210 #endif /* __MLX5E_FLOW_STEER_H__ */ 211 212