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 enum {
8 	MLX5E_TC_FT_LEVEL = 0,
9 	MLX5E_TC_TTC_FT_LEVEL,
10 };
11 
12 struct mlx5e_tc_table {
13 	struct mlx5_flow_table		*t;
14 
15 	struct rhashtable               ht;
16 
17 	DECLARE_HASHTABLE(mod_hdr_tbl, 8);
18 	DECLARE_HASHTABLE(hairpin_tbl, 8);
19 };
20 
21 struct mlx5e_flow_table {
22 	int num_groups;
23 	struct mlx5_flow_table *t;
24 	struct mlx5_flow_group **g;
25 };
26 
27 struct mlx5e_l2_rule {
28 	u8  addr[ETH_ALEN + 2];
29 	struct mlx5_flow_handle *rule;
30 };
31 
32 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
33 
34 struct mlx5e_vlan_table {
35 	struct mlx5e_flow_table		ft;
36 	DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
37 	DECLARE_BITMAP(active_svlans, VLAN_N_VID);
38 	struct mlx5_flow_handle	*active_cvlans_rule[VLAN_N_VID];
39 	struct mlx5_flow_handle	*active_svlans_rule[VLAN_N_VID];
40 	struct mlx5_flow_handle	*untagged_rule;
41 	struct mlx5_flow_handle	*any_cvlan_rule;
42 	struct mlx5_flow_handle	*any_svlan_rule;
43 	bool			cvlan_filter_disabled;
44 };
45 
46 struct mlx5e_l2_table {
47 	struct mlx5e_flow_table    ft;
48 	struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
49 	struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
50 	struct mlx5e_l2_rule	   broadcast;
51 	struct mlx5e_l2_rule	   allmulti;
52 	struct mlx5e_l2_rule	   promisc;
53 	bool                       broadcast_enabled;
54 	bool                       allmulti_enabled;
55 	bool                       promisc_enabled;
56 };
57 
58 enum mlx5e_traffic_types {
59 	MLX5E_TT_IPV4_TCP,
60 	MLX5E_TT_IPV6_TCP,
61 	MLX5E_TT_IPV4_UDP,
62 	MLX5E_TT_IPV6_UDP,
63 	MLX5E_TT_IPV4_IPSEC_AH,
64 	MLX5E_TT_IPV6_IPSEC_AH,
65 	MLX5E_TT_IPV4_IPSEC_ESP,
66 	MLX5E_TT_IPV6_IPSEC_ESP,
67 	MLX5E_TT_IPV4,
68 	MLX5E_TT_IPV6,
69 	MLX5E_TT_ANY,
70 	MLX5E_NUM_TT,
71 	MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
72 };
73 
74 enum mlx5e_tunnel_types {
75 	MLX5E_TT_IPV4_GRE,
76 	MLX5E_TT_IPV6_GRE,
77 	MLX5E_NUM_TUNNEL_TT,
78 };
79 
80 /* L3/L4 traffic type classifier */
81 struct mlx5e_ttc_table {
82 	struct mlx5e_flow_table  ft;
83 	struct mlx5_flow_handle	 *rules[MLX5E_NUM_TT];
84 	struct mlx5_flow_handle  *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
85 };
86 
87 /* NIC prio FTS */
88 enum {
89 	MLX5E_VLAN_FT_LEVEL = 0,
90 	MLX5E_L2_FT_LEVEL,
91 	MLX5E_TTC_FT_LEVEL,
92 	MLX5E_INNER_TTC_FT_LEVEL,
93 #ifdef CONFIG_MLX5_EN_ARFS
94 	MLX5E_ARFS_FT_LEVEL
95 #endif
96 };
97 
98 #ifdef CONFIG_MLX5_EN_RXNFC
99 
100 struct mlx5e_ethtool_table {
101 	struct mlx5_flow_table *ft;
102 	int                    num_rules;
103 };
104 
105 #define ETHTOOL_NUM_L3_L4_FTS 7
106 #define ETHTOOL_NUM_L2_FTS 4
107 
108 struct mlx5e_ethtool_steering {
109 	struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
110 	struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
111 	struct list_head                rules;
112 	int                             tot_num_rules;
113 };
114 
115 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
116 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
117 int mlx5e_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
118 int mlx5e_get_rxnfc(struct net_device *dev,
119 		    struct ethtool_rxnfc *info, u32 *rule_locs);
120 #else
121 static inline void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv)    { }
122 static inline void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv) { }
123 #endif /* CONFIG_MLX5_EN_RXNFC */
124 
125 #ifdef CONFIG_MLX5_EN_ARFS
126 #define ARFS_HASH_SHIFT BITS_PER_BYTE
127 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
128 
129 struct arfs_table {
130 	struct mlx5e_flow_table  ft;
131 	struct mlx5_flow_handle	 *default_rule;
132 	struct hlist_head	 rules_hash[ARFS_HASH_SIZE];
133 };
134 
135 enum  arfs_type {
136 	ARFS_IPV4_TCP,
137 	ARFS_IPV6_TCP,
138 	ARFS_IPV4_UDP,
139 	ARFS_IPV6_UDP,
140 	ARFS_NUM_TYPES,
141 };
142 
143 struct mlx5e_arfs_tables {
144 	struct arfs_table arfs_tables[ARFS_NUM_TYPES];
145 	/* Protect aRFS rules list */
146 	spinlock_t                     arfs_lock;
147 	struct list_head               rules;
148 	int                            last_filter_id;
149 	struct workqueue_struct        *wq;
150 };
151 
152 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
153 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
154 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
155 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
156 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
157 			u16 rxq_index, u32 flow_id);
158 #else
159 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
160 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
161 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
162 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) {	return -EOPNOTSUPP; }
163 #endif
164 
165 struct mlx5e_flow_steering {
166 	struct mlx5_flow_namespace      *ns;
167 #ifdef CONFIG_MLX5_EN_RXNFC
168 	struct mlx5e_ethtool_steering   ethtool;
169 #endif
170 	struct mlx5e_tc_table           tc;
171 	struct mlx5e_vlan_table         vlan;
172 	struct mlx5e_l2_table           l2;
173 	struct mlx5e_ttc_table          ttc;
174 	struct mlx5e_ttc_table          inner_ttc;
175 #ifdef CONFIG_MLX5_EN_ARFS
176 	struct mlx5e_arfs_tables        arfs;
177 #endif
178 };
179 
180 struct ttc_params {
181 	struct mlx5_flow_table_attr ft_attr;
182 	u32 any_tt_tirn;
183 	u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
184 	struct mlx5e_ttc_table *inner_ttc;
185 };
186 
187 void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
188 void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
189 void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
190 
191 int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
192 			   struct mlx5e_ttc_table *ttc);
193 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
194 			     struct mlx5e_ttc_table *ttc);
195 
196 int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
197 				 struct mlx5e_ttc_table *ttc);
198 void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
199 				   struct mlx5e_ttc_table *ttc);
200 
201 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
202 
203 void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
204 void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
205 
206 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
207 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
208 
209 #endif /* __MLX5E_FLOW_STEER_H__ */
210 
211