1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
4 #ifndef __MLX5E_FLOW_STEER_H__
5 #define __MLX5E_FLOW_STEER_H__
8 #include "lib/fs_ttc.h"
10 struct mlx5e_post_act;
13 MLX5E_TC_FT_LEVEL = 0,
14 MLX5E_TC_TTC_FT_LEVEL,
17 struct mlx5e_tc_table {
18 /* Protects the dynamic assignment of the t parameter
19 * which is the nic tc root table.
22 struct mlx5_flow_table *t;
23 struct mlx5_fs_chains *chains;
24 struct mlx5e_post_act *post_act;
28 struct mod_hdr_tbl mod_hdr;
29 struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
30 DECLARE_HASHTABLE(hairpin_tbl, 8);
32 struct notifier_block netdevice_nb;
33 struct netdev_net_notifier netdevice_nn;
35 struct mlx5_tc_ct_priv *ct;
36 struct mapping_ctx *mapping;
39 struct mlx5e_flow_table {
41 struct mlx5_flow_table *t;
42 struct mlx5_flow_group **g;
45 struct mlx5e_l2_rule {
46 u8 addr[ETH_ALEN + 2];
47 struct mlx5_flow_handle *rule;
50 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
52 struct mlx5e_promisc_table {
53 struct mlx5e_flow_table ft;
54 struct mlx5_flow_handle *rule;
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);
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;
74 #define MLX5E_NUM_INDIR_TIRS (MLX5_NUM_TT - 1)
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)
88 MLX5E_PROMISC_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,
98 #ifdef CONFIG_MLX5_EN_ARFS
99 MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
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,
109 #ifdef CONFIG_MLX5_EN_RXNFC
111 struct mlx5e_ethtool_table {
112 struct mlx5_flow_table *ft;
116 #define ETHTOOL_NUM_L3_L4_FTS 7
117 #define ETHTOOL_NUM_L2_FTS 4
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;
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 net_device *dev, struct ethtool_rxnfc *cmd);
129 int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
130 struct ethtool_rxnfc *info, u32 *rule_locs);
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 net_device *dev, struct ethtool_rxnfc *cmd)
135 { return -EOPNOTSUPP; }
136 static inline int mlx5e_ethtool_get_rxnfc(struct net_device *dev,
137 struct ethtool_rxnfc *info, u32 *rule_locs)
138 { return -EOPNOTSUPP; }
139 #endif /* CONFIG_MLX5_EN_RXNFC */
141 #ifdef CONFIG_MLX5_EN_ARFS
142 struct mlx5e_arfs_tables;
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);
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; }
157 #ifdef CONFIG_MLX5_EN_TLS
158 struct mlx5e_accel_fs_tcp;
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;
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;
180 #ifdef CONFIG_MLX5_EN_TLS
181 struct mlx5e_accel_fs_tcp *accel_tcp;
183 struct mlx5e_fs_udp *udp;
184 struct mlx5e_fs_any *any;
185 struct mlx5e_ptp_fs *ptp_fs;
188 void mlx5e_set_ttc_params(struct mlx5e_priv *priv,
189 struct ttc_params *ttc_params, bool tunnel);
191 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv);
192 int mlx5e_create_ttc_table(struct mlx5e_priv *priv);
194 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
196 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
197 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
199 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
200 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
202 int mlx5e_fs_init(struct mlx5e_priv *priv);
203 void mlx5e_fs_cleanup(struct mlx5e_priv *priv);
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);
210 #endif /* __MLX5E_FLOW_STEER_H__ */