Merge tag 'mmc-v5.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
[linux-2.6-microblaze.git] / drivers / net / ethernet / intel / ice / ice_switch.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 #ifndef _ICE_SWITCH_H_
5 #define _ICE_SWITCH_H_
6
7 #include "ice_common.h"
8
9 #define ICE_SW_CFG_MAX_BUF_LEN 2048
10 #define ICE_DFLT_VSI_INVAL 0xff
11 #define ICE_FLTR_RX BIT(0)
12 #define ICE_FLTR_TX BIT(1)
13 #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
14 #define ICE_VSI_INVAL_ID 0xffff
15 #define ICE_INVAL_Q_HANDLE 0xFFFF
16
17 /* Switch Profile IDs for Profile related switch rules */
18 #define ICE_PROFID_IPV4_GTPC_TEID                       41
19 #define ICE_PROFID_IPV4_GTPC_NO_TEID                    42
20 #define ICE_PROFID_IPV4_GTPU_TEID                       43
21 #define ICE_PROFID_IPV6_GTPC_TEID                       44
22 #define ICE_PROFID_IPV6_GTPC_NO_TEID                    45
23 #define ICE_PROFID_IPV6_GTPU_TEID                       46
24 #define ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER             70
25
26 /* VSI context structure for add/get/update/free operations */
27 struct ice_vsi_ctx {
28         u16 vsi_num;
29         u16 vsis_allocd;
30         u16 vsis_unallocated;
31         u16 flags;
32         struct ice_aqc_vsi_props info;
33         struct ice_sched_vsi_info sched;
34         u8 alloc_from_pool;
35         u8 vf_num;
36         u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
37         struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
38         u16 num_rdma_q_entries[ICE_MAX_TRAFFIC_CLASS];
39         struct ice_q_ctx *rdma_q_ctx[ICE_MAX_TRAFFIC_CLASS];
40 };
41
42 /* Switch recipe ID enum values are specific to hardware */
43 enum ice_sw_lkup_type {
44         ICE_SW_LKUP_ETHERTYPE = 0,
45         ICE_SW_LKUP_MAC = 1,
46         ICE_SW_LKUP_MAC_VLAN = 2,
47         ICE_SW_LKUP_PROMISC = 3,
48         ICE_SW_LKUP_VLAN = 4,
49         ICE_SW_LKUP_DFLT = 5,
50         ICE_SW_LKUP_ETHERTYPE_MAC = 8,
51         ICE_SW_LKUP_PROMISC_VLAN = 9,
52         ICE_SW_LKUP_LAST
53 };
54
55 /* type of filter src ID */
56 enum ice_src_id {
57         ICE_SRC_ID_UNKNOWN = 0,
58         ICE_SRC_ID_VSI,
59         ICE_SRC_ID_QUEUE,
60         ICE_SRC_ID_LPORT,
61 };
62
63 struct ice_fltr_info {
64         /* Look up information: how to look up packet */
65         enum ice_sw_lkup_type lkup_type;
66         /* Forward action: filter action to do after lookup */
67         enum ice_sw_fwd_act_type fltr_act;
68         /* rule ID returned by firmware once filter rule is created */
69         u16 fltr_rule_id;
70         u16 flag;
71
72         /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
73         u16 src;
74         enum ice_src_id src_id;
75
76         union {
77                 struct {
78                         u8 mac_addr[ETH_ALEN];
79                 } mac;
80                 struct {
81                         u8 mac_addr[ETH_ALEN];
82                         u16 vlan_id;
83                 } mac_vlan;
84                 struct {
85                         u16 vlan_id;
86                         u16 tpid;
87                         u8 tpid_valid;
88                 } vlan;
89                 /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
90                  * if just using ethertype as filter. Set lkup_type as
91                  * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
92                  * passed in as filter.
93                  */
94                 struct {
95                         u16 ethertype;
96                         u8 mac_addr[ETH_ALEN]; /* optional */
97                 } ethertype_mac;
98         } l_data; /* Make sure to zero out the memory of l_data before using
99                    * it or only set the data associated with lookup match
100                    * rest everything should be zero
101                    */
102
103         /* Depending on filter action */
104         union {
105                 /* queue ID in case of ICE_FWD_TO_Q and starting
106                  * queue ID in case of ICE_FWD_TO_QGRP.
107                  */
108                 u16 q_id:11;
109                 u16 hw_vsi_id:10;
110                 u16 vsi_list_id:10;
111         } fwd_id;
112
113         /* Sw VSI handle */
114         u16 vsi_handle;
115
116         /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
117          * determines the range of queues the packet needs to be forwarded to.
118          * Note that qgrp_size must be set to a power of 2.
119          */
120         u8 qgrp_size;
121
122         /* Rule creations populate these indicators basing on the switch type */
123         u8 lb_en;       /* Indicate if packet can be looped back */
124         u8 lan_en;      /* Indicate if packet can be forwarded to the uplink */
125 };
126
127 struct ice_update_recipe_lkup_idx_params {
128         u16 rid;
129         u16 fv_idx;
130         bool ignore_valid;
131         u16 mask;
132         bool mask_valid;
133         u8 lkup_idx;
134 };
135
136 struct ice_adv_lkup_elem {
137         enum ice_protocol_type type;
138         union {
139                 union ice_prot_hdr h_u; /* Header values */
140                 /* Used to iterate over the headers */
141                 u16 h_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
142         };
143         union {
144                 union ice_prot_hdr m_u; /* Mask of header values to match */
145                 /* Used to iterate over header mask */
146                 u16 m_raw[sizeof(union ice_prot_hdr) / sizeof(u16)];
147         };
148 };
149
150 struct ice_sw_act_ctrl {
151         /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
152         u16 src;
153         u16 flag;
154         enum ice_sw_fwd_act_type fltr_act;
155         /* Depending on filter action */
156         union {
157                 /* This is a queue ID in case of ICE_FWD_TO_Q and starting
158                  * queue ID in case of ICE_FWD_TO_QGRP.
159                  */
160                 u16 q_id:11;
161                 u16 vsi_id:10;
162                 u16 hw_vsi_id:10;
163                 u16 vsi_list_id:10;
164         } fwd_id;
165         /* software VSI handle */
166         u16 vsi_handle;
167         u8 qgrp_size;
168 };
169
170 struct ice_rule_query_data {
171         /* Recipe ID for which the requested rule was added */
172         u16 rid;
173         /* Rule ID that was added or is supposed to be removed */
174         u16 rule_id;
175         /* vsi_handle for which Rule was added or is supposed to be removed */
176         u16 vsi_handle;
177 };
178
179 /* This structure allows to pass info about lb_en and lan_en
180  * flags to ice_add_adv_rule. Values in act would be used
181  * only if act_valid was set to true, otherwise default
182  * values would be used.
183  */
184 struct ice_adv_rule_flags_info {
185         u32 act;
186         u8 act_valid;           /* indicate if flags in act are valid */
187 };
188
189 struct ice_adv_rule_info {
190         enum ice_sw_tunnel_type tun_type;
191         struct ice_sw_act_ctrl sw_act;
192         u32 priority;
193         u8 rx; /* true means LOOKUP_RX otherwise LOOKUP_TX */
194         u16 fltr_rule_id;
195         struct ice_adv_rule_flags_info flags_info;
196 };
197
198 /* A collection of one or more four word recipe */
199 struct ice_sw_recipe {
200         /* For a chained recipe the root recipe is what should be used for
201          * programming rules
202          */
203         u8 is_root;
204         u8 root_rid;
205         u8 recp_created;
206
207         /* Number of extraction words */
208         u8 n_ext_words;
209         /* Protocol ID and Offset pair (extraction word) to describe the
210          * recipe
211          */
212         struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
213         u16 word_masks[ICE_MAX_CHAIN_WORDS];
214
215         /* if this recipe is a collection of other recipe */
216         u8 big_recp;
217
218         /* if this recipe is part of another bigger recipe then chain index
219          * corresponding to this recipe
220          */
221         u8 chain_idx;
222
223         /* if this recipe is a collection of other recipe then count of other
224          * recipes and recipe IDs of those recipes
225          */
226         u8 n_grp_count;
227
228         /* Bit map specifying the IDs associated with this group of recipe */
229         DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
230
231         enum ice_sw_tunnel_type tun_type;
232
233         /* List of type ice_fltr_mgmt_list_entry or adv_rule */
234         u8 adv_rule;
235         struct list_head filt_rules;
236         struct list_head filt_replay_rules;
237
238         struct mutex filt_rule_lock;    /* protect filter rule structure */
239
240         /* Profiles this recipe should be associated with */
241         struct list_head fv_list;
242
243         /* Profiles this recipe is associated with */
244         u8 num_profs, *prof_ids;
245
246         /* Bit map for possible result indexes */
247         DECLARE_BITMAP(res_idxs, ICE_MAX_FV_WORDS);
248
249         /* This allows user to specify the recipe priority.
250          * For now, this becomes 'fwd_priority' when recipe
251          * is created, usually recipes can have 'fwd' and 'join'
252          * priority.
253          */
254         u8 priority;
255
256         struct list_head rg_list;
257
258         /* AQ buffer associated with this recipe */
259         struct ice_aqc_recipe_data_elem *root_buf;
260         /* This struct saves the fv_words for a given lookup */
261         struct ice_prot_lkup_ext lkup_exts;
262 };
263
264 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
265 struct ice_vsi_list_map_info {
266         struct list_head list_entry;
267         DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
268         u16 vsi_list_id;
269         /* counter to track how many rules are reusing this VSI list */
270         u16 ref_cnt;
271 };
272
273 struct ice_fltr_list_entry {
274         struct list_head list_entry;
275         int status;
276         struct ice_fltr_info fltr_info;
277 };
278
279 /* This defines an entry in the list that maintains MAC or VLAN membership
280  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
281  * VLAN. As an optimization the VSI list should be created only when a
282  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
283  * used for VLAN membership.
284  */
285 struct ice_fltr_mgmt_list_entry {
286         /* back pointer to VSI list ID to VSI list mapping */
287         struct ice_vsi_list_map_info *vsi_list_info;
288         u16 vsi_count;
289 #define ICE_INVAL_LG_ACT_INDEX 0xffff
290         u16 lg_act_idx;
291 #define ICE_INVAL_SW_MARKER_ID 0xffff
292         u16 sw_marker_id;
293         struct list_head list_entry;
294         struct ice_fltr_info fltr_info;
295 #define ICE_INVAL_COUNTER_ID 0xff
296         u8 counter_index;
297 };
298
299 struct ice_adv_fltr_mgmt_list_entry {
300         struct list_head list_entry;
301
302         struct ice_adv_lkup_elem *lkups;
303         struct ice_adv_rule_info rule_info;
304         u16 lkups_cnt;
305         struct ice_vsi_list_map_info *vsi_list_info;
306         u16 vsi_count;
307 };
308
309 enum ice_promisc_flags {
310         ICE_PROMISC_UCAST_RX = 0x1,
311         ICE_PROMISC_UCAST_TX = 0x2,
312         ICE_PROMISC_MCAST_RX = 0x4,
313         ICE_PROMISC_MCAST_TX = 0x8,
314         ICE_PROMISC_BCAST_RX = 0x10,
315         ICE_PROMISC_BCAST_TX = 0x20,
316         ICE_PROMISC_VLAN_RX = 0x40,
317         ICE_PROMISC_VLAN_TX = 0x80,
318 };
319
320 /* VSI related commands */
321 int
322 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
323             struct ice_sq_cd *cd);
324 int
325 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
326              bool keep_vsi_alloc, struct ice_sq_cd *cd);
327 int
328 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
329                struct ice_sq_cd *cd);
330 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
331 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
332 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
333 /* Switch config */
334 int ice_get_initial_sw_cfg(struct ice_hw *hw);
335
336 int
337 ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
338                    u16 *counter_id);
339 int
340 ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
341                   u16 counter_id);
342
343 /* Switch/bridge related commands */
344 int
345 ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
346                  u16 lkups_cnt, struct ice_adv_rule_info *rinfo,
347                  struct ice_rule_query_data *added_entry);
348 int ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
349 int ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
350 int ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
351 int ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
352 int ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
353 bool ice_mac_fltr_exist(struct ice_hw *hw, u8 *mac, u16 vsi_handle);
354 bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle);
355 int ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list);
356 int ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list);
357 int ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable);
358 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
359
360 /* Promisc/defport setup for VSIs */
361 int ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction);
362 int
363 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
364                     u16 vid);
365 int
366 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
367                       u16 vid);
368 int
369 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
370                          bool rm_vlan_promisc);
371
372 int ice_rem_adv_rule_for_vsi(struct ice_hw *hw, u16 vsi_handle);
373 int
374 ice_rem_adv_rule_by_id(struct ice_hw *hw,
375                        struct ice_rule_query_data *remove_entry);
376
377 int ice_init_def_sw_recp(struct ice_hw *hw);
378 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
379
380 int ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
381 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
382
383 int
384 ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
385                 u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd);
386 int
387 ice_update_recipe_lkup_idx(struct ice_hw *hw,
388                            struct ice_update_recipe_lkup_idx_params *params);
389 void ice_change_proto_id_to_dvm(void);
390 #endif /* _ICE_SWITCH_H_ */