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 struct mlx5e_tc_table; 12 13 enum { 14 MLX5E_TC_FT_LEVEL = 0, 15 MLX5E_TC_TTC_FT_LEVEL, 16 MLX5E_TC_MISS_LEVEL, 17 }; 18 19 enum { 20 MLX5E_TC_PRIO = 0, 21 MLX5E_PROMISC_PRIO, 22 MLX5E_NIC_PRIO, 23 }; 24 25 struct mlx5e_flow_table { 26 int num_groups; 27 struct mlx5_flow_table *t; 28 struct mlx5_flow_group **g; 29 }; 30 31 struct mlx5e_l2_rule { 32 u8 addr[ETH_ALEN + 2]; 33 struct mlx5_flow_handle *rule; 34 }; 35 36 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE) 37 38 struct mlx5e_promisc_table { 39 struct mlx5e_flow_table ft; 40 struct mlx5_flow_handle *rule; 41 }; 42 43 /* Forward declaration and APIs to get private fields of vlan_table */ 44 struct mlx5e_vlan_table; 45 unsigned long *mlx5e_vlan_get_active_svlans(struct mlx5e_vlan_table *vlan); 46 struct mlx5_flow_table *mlx5e_vlan_get_flowtable(struct mlx5e_vlan_table *vlan); 47 48 struct mlx5e_l2_table { 49 struct mlx5e_flow_table ft; 50 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE]; 51 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE]; 52 struct mlx5e_l2_rule broadcast; 53 struct mlx5e_l2_rule allmulti; 54 struct mlx5_flow_handle *trap_rule; 55 bool broadcast_enabled; 56 bool allmulti_enabled; 57 bool promisc_enabled; 58 }; 59 60 #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_INDIR_TIRS) 61 62 #define MLX5_HASH_IP (MLX5_HASH_FIELD_SEL_SRC_IP |\ 63 MLX5_HASH_FIELD_SEL_DST_IP) 64 #define MLX5_HASH_IP_L4PORTS (MLX5_HASH_FIELD_SEL_SRC_IP |\ 65 MLX5_HASH_FIELD_SEL_DST_IP |\ 66 MLX5_HASH_FIELD_SEL_L4_SPORT |\ 67 MLX5_HASH_FIELD_SEL_L4_DPORT) 68 #define MLX5_HASH_IP_IPSEC_SPI (MLX5_HASH_FIELD_SEL_SRC_IP |\ 69 MLX5_HASH_FIELD_SEL_DST_IP |\ 70 MLX5_HASH_FIELD_SEL_IPSEC_SPI) 71 72 /* NIC promisc FT level */ 73 enum { 74 MLX5E_PROMISC_FT_LEVEL, 75 }; 76 77 /* NIC prio FTS */ 78 enum { 79 MLX5E_VLAN_FT_LEVEL, 80 MLX5E_L2_FT_LEVEL, 81 MLX5E_TTC_FT_LEVEL, 82 MLX5E_INNER_TTC_FT_LEVEL, 83 MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 84 MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 85 #ifdef CONFIG_MLX5_EN_TLS 86 MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 87 #endif 88 #ifdef CONFIG_MLX5_EN_ARFS 89 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 90 #endif 91 #if defined(CONFIG_MLX5_EN_IPSEC) 92 MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 93 MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL, 94 MLX5E_ACCEL_FS_POL_FT_LEVEL, 95 MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL, 96 MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL, 97 #endif 98 #if defined(CONFIG_MLX5_EN_PSP) 99 MLX5E_ACCEL_FS_PSP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, 100 MLX5E_ACCEL_FS_PSP_ERR_FT_LEVEL, 101 MLX5E_ACCEL_FS_PSP_RX_FT_LEVEL, 102 #endif 103 }; 104 105 struct mlx5e_flow_steering; 106 struct mlx5e_rx_res; 107 108 #ifdef CONFIG_MLX5_EN_ARFS 109 struct mlx5e_arfs_tables; 110 111 int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs, 112 struct mlx5e_rx_res *rx_res, bool ntuple); 113 void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple); 114 int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs); 115 int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs); 116 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, 117 u16 rxq_index, u32 flow_id); 118 #else 119 static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs, 120 struct mlx5e_rx_res *rx_res, bool ntuple) 121 { return 0; } 122 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple) {} 123 static inline int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs) 124 { return -EOPNOTSUPP; } 125 static inline int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs) 126 { return -EOPNOTSUPP; } 127 #endif 128 129 #ifdef CONFIG_MLX5_EN_TLS 130 struct mlx5e_accel_fs_tcp; 131 #endif 132 133 struct mlx5e_profile; 134 struct mlx5e_fs_udp; 135 struct mlx5e_fs_any; 136 struct mlx5e_ptp_fs; 137 138 void mlx5e_set_ttc_params(struct mlx5e_flow_steering *fs, 139 struct mlx5e_rx_res *rx_res, 140 struct ttc_params *ttc_params, bool tunnel, 141 bool ipsec_rss); 142 143 void mlx5e_destroy_ttc_table(struct mlx5e_flow_steering *fs); 144 int mlx5e_create_ttc_table(struct mlx5e_flow_steering *fs, 145 struct mlx5e_rx_res *rx_res); 146 147 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft); 148 149 void mlx5e_enable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc); 150 void mlx5e_disable_cvlan_filter(struct mlx5e_flow_steering *fs, bool promisc); 151 152 int mlx5e_create_flow_steering(struct mlx5e_flow_steering *fs, 153 struct mlx5e_rx_res *rx_res, 154 const struct mlx5e_profile *profile, 155 struct net_device *netdev); 156 void mlx5e_destroy_flow_steering(struct mlx5e_flow_steering *fs, bool ntuple, 157 const struct mlx5e_profile *profile); 158 159 struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile, 160 struct mlx5_core_dev *mdev, 161 bool rx_mode_active, 162 struct dentry *dfs_root); 163 void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs); 164 struct mlx5e_vlan_table *mlx5e_fs_get_vlan(struct mlx5e_flow_steering *fs); 165 struct mlx5e_tc_table *mlx5e_fs_get_tc(struct mlx5e_flow_steering *fs); 166 struct mlx5e_l2_table *mlx5e_fs_get_l2(struct mlx5e_flow_steering *fs); 167 struct mlx5_flow_namespace *mlx5e_fs_get_ns(struct mlx5e_flow_steering *fs, bool egress); 168 void mlx5e_fs_set_ns(struct mlx5e_flow_steering *fs, struct mlx5_flow_namespace *ns, bool egress); 169 170 static inline bool mlx5e_fs_has_arfs(struct net_device *netdev) 171 { 172 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) && 173 netdev->hw_features & NETIF_F_NTUPLE; 174 } 175 176 static inline bool mlx5e_fs_want_arfs(struct net_device *netdev) 177 { 178 return IS_ENABLED(CONFIG_MLX5_EN_ARFS) && 179 netdev->features & NETIF_F_NTUPLE; 180 } 181 182 #ifdef CONFIG_MLX5_EN_RXNFC 183 struct mlx5e_ethtool_steering *mlx5e_fs_get_ethtool(struct mlx5e_flow_steering *fs); 184 #endif 185 struct mlx5_ttc_table *mlx5e_fs_get_ttc(struct mlx5e_flow_steering *fs, bool inner); 186 void mlx5e_fs_set_ttc(struct mlx5e_flow_steering *fs, struct mlx5_ttc_table *ttc, bool inner); 187 #ifdef CONFIG_MLX5_EN_ARFS 188 struct mlx5e_arfs_tables *mlx5e_fs_get_arfs(struct mlx5e_flow_steering *fs); 189 void mlx5e_fs_set_arfs(struct mlx5e_flow_steering *fs, struct mlx5e_arfs_tables *arfs); 190 #endif 191 struct mlx5e_ptp_fs *mlx5e_fs_get_ptp(struct mlx5e_flow_steering *fs); 192 void mlx5e_fs_set_ptp(struct mlx5e_flow_steering *fs, struct mlx5e_ptp_fs *ptp_fs); 193 struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs); 194 void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any); 195 struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs); 196 void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp); 197 #ifdef CONFIG_MLX5_EN_TLS 198 struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs); 199 void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp); 200 #endif 201 void mlx5e_fs_set_rx_mode_active(struct mlx5e_flow_steering *fs, 202 bool rx_mode_active); 203 void mlx5e_fs_set_vlan_strip_disable(struct mlx5e_flow_steering *fs, bool vlan_strip_disable); 204 205 struct mlx5_core_dev *mlx5e_fs_get_mdev(struct mlx5e_flow_steering *fs); 206 int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num); 207 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs); 208 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int trap_id, int tir_num); 209 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs); 210 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, 211 struct net_device *netdev, 212 struct netdev_hw_addr_list *uc, 213 struct netdev_hw_addr_list *mc); 214 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs, 215 struct net_device *netdev, 216 __be16 proto, u16 vid); 217 int mlx5e_fs_vlan_rx_kill_vid(struct mlx5e_flow_steering *fs, 218 struct net_device *netdev, 219 __be16 proto, u16 vid); 220 void mlx5e_fs_init_l2_addr(struct mlx5e_flow_steering *fs, struct net_device *netdev); 221 222 struct dentry *mlx5e_fs_get_debugfs_root(struct mlx5e_flow_steering *fs); 223 224 #define fs_err(fs, fmt, ...) \ 225 mlx5_core_err(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__) 226 227 #define fs_dbg(fs, fmt, ...) \ 228 mlx5_core_dbg(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__) 229 230 #define fs_warn(fs, fmt, ...) \ 231 mlx5_core_warn(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__) 232 233 #define fs_warn_once(fs, fmt, ...) \ 234 mlx5_core_warn_once(mlx5e_fs_get_mdev(fs), fmt, ##__VA_ARGS__) 235 236 #endif /* __MLX5E_FLOW_STEER_H__ */ 237 238