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