net/ice/base: add some helper macros
[dpdk.git] / drivers / net / ice / base / ice_switch.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2018
3  */
4
5 #ifndef _ICE_SWITCH_H_
6 #define _ICE_SWITCH_H_
7
8 #include "ice_common.h"
9 #include "ice_protocol_type.h"
10
11 #define ICE_SW_CFG_MAX_BUF_LEN 2048
12 #define ICE_MAX_SW 256
13 #define ICE_DFLT_VSI_INVAL 0xff
14
15
16
17 #define ICE_VSI_INVAL_ID 0xFFFF
18
19 /* VSI context structure for add/get/update/free operations */
20 struct ice_vsi_ctx {
21         u16 vsi_num;
22         u16 vsis_allocd;
23         u16 vsis_unallocated;
24         u16 flags;
25         struct ice_aqc_vsi_props info;
26         struct ice_sched_vsi_info sched;
27         u8 alloc_from_pool;
28         struct ice_lock rss_locks;      /* protect rss config in VSI ctx */
29         struct LIST_HEAD_TYPE rss_list_head;
30 };
31
32
33 /* Switch recipe ID enum values are specific to hardware */
34 enum ice_sw_lkup_type {
35         ICE_SW_LKUP_ETHERTYPE = 0,
36         ICE_SW_LKUP_MAC = 1,
37         ICE_SW_LKUP_MAC_VLAN = 2,
38         ICE_SW_LKUP_PROMISC = 3,
39         ICE_SW_LKUP_VLAN = 4,
40         ICE_SW_LKUP_DFLT = 5,
41         ICE_SW_LKUP_ETHERTYPE_MAC = 8,
42         ICE_SW_LKUP_PROMISC_VLAN = 9,
43         ICE_SW_LKUP_LAST,
44 };
45
46 /* type of filter src id */
47 enum ice_src_id {
48         ICE_SRC_ID_UNKNOWN = 0,
49         ICE_SRC_ID_VSI,
50         ICE_SRC_ID_QUEUE,
51         ICE_SRC_ID_LPORT,
52 };
53
54 struct ice_fltr_info {
55         /* Look up information: how to look up packet */
56         enum ice_sw_lkup_type lkup_type;
57         /* Forward action: filter action to do after lookup */
58         enum ice_sw_fwd_act_type fltr_act;
59         /* rule ID returned by firmware once filter rule is created */
60         u16 fltr_rule_id;
61         u16 flag;
62 #define ICE_FLTR_RX             BIT(0)
63 #define ICE_FLTR_TX             BIT(1)
64 #define ICE_FLTR_TX_RX          (ICE_FLTR_RX | ICE_FLTR_TX)
65
66         /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
67         u16 src;
68         enum ice_src_id src_id;
69
70         union {
71                 struct {
72                         u8 mac_addr[ETH_ALEN];
73                 } mac;
74                 struct {
75                         u8 mac_addr[ETH_ALEN];
76                         u16 vlan_id;
77                 } mac_vlan;
78                 struct {
79                         u16 vlan_id;
80                 } vlan;
81                 /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
82                  * if just using ethertype as filter. Set lkup_type as
83                  * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
84                  * passed in as filter.
85                  */
86                 struct {
87                         u16 ethertype;
88                         u8 mac_addr[ETH_ALEN]; /* optional */
89                 } ethertype_mac;
90         } l_data; /* Make sure to zero out the memory of l_data before using
91                    * it or only set the data associated with lookup match
92                    * rest everything should be zero
93                    */
94
95         /* Depending on filter action */
96         union {
97                 /* queue id in case of ICE_FWD_TO_Q and starting
98                  * queue id in case of ICE_FWD_TO_QGRP.
99                  */
100                 u16 q_id:11;
101                 u16 hw_vsi_id:10;
102                 u16 vsi_id:10;
103                 u16 vsi_list_id:10;
104         } fwd_id;
105
106         /* Sw VSI handle */
107         u16 vsi_handle;
108
109         /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
110          * determines the range of queues the packet needs to be forwarded to.
111          * Note that qgrp_size must be set to a power of 2.
112          */
113         u8 qgrp_size;
114
115         /* Rule creations populate these indicators basing on the switch type */
116         u8 lb_en;       /* Indicate if packet can be looped back */
117         u8 lan_en;      /* Indicate if packet can be forwarded to the uplink */
118 };
119
120 struct ice_adv_lkup_elem {
121         enum ice_protocol_type type;
122         union ice_prot_hdr h_u; /* Header values */
123         union ice_prot_hdr m_u; /* Mask of header values to match */
124 };
125
126 struct ice_sw_act_ctrl {
127         /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
128         u16 src;
129         u16 flag;
130 #define ICE_FLTR_RX             BIT(0)
131 #define ICE_FLTR_TX             BIT(1)
132 #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
133
134         enum ice_sw_fwd_act_type fltr_act;
135         /* Depending on filter action */
136         union {
137                 /* This is a queue id in case of ICE_FWD_TO_Q and starting
138                  * queue id in case of ICE_FWD_TO_QGRP.
139                  */
140                 u16 q_id:11;
141                 u16 vsi_id:10;
142                 u16 hw_vsi_id:10;
143                 u16 vsi_list_id:10;
144         } fwd_id;
145         /* software VSI handle */
146         u16 vsi_handle;
147         u8 qgrp_size;
148 };
149
150 struct ice_adv_rule_info {
151         enum ice_sw_tunnel_type tun_type;
152         struct ice_sw_act_ctrl sw_act;
153         u32 priority;
154         u8 rx; /* true means LOOKUP_RX otherwise LOOKUP_TX */
155 };
156
157 /* A collection of one or more four word recipe */
158 struct ice_sw_recipe {
159         /* For a chained recipe the root recipe is what should be used for
160          * programming rules
161          */
162         u8 root_rid;
163         u8 recp_created;
164
165         /* Number of extraction words */
166         u8 n_ext_words;
167         /* Protocol ID and Offset pair (extraction word) to describe the
168          * recipe
169          */
170         struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS];
171
172         /* if this recipe is a collection of other recipe */
173         u8 big_recp;
174
175         /* if this recipe is part of another bigger recipe then chain index
176          * corresponding to this recipe
177          */
178         u8 chain_idx;
179
180         /* if this recipe is a collection of other recipe then count of other
181          * recipes and recipe ids of those recipes
182          */
183         u8 n_grp_count;
184
185         /* Bit map specifying the IDs associated with this group of recipe */
186         ice_declare_bitmap(r_bitmap, ICE_MAX_NUM_RECIPES);
187
188         enum ice_sw_tunnel_type tun_type;
189
190         /* List of type ice_fltr_mgmt_list_entry or adv_rule */
191         u8 adv_rule;
192         struct LIST_HEAD_TYPE filt_rules;
193         struct LIST_HEAD_TYPE filt_replay_rules;
194
195         struct ice_lock filt_rule_lock; /* protect filter rule structure */
196
197         /* Profiles this recipe should be associated with */
198         struct LIST_HEAD_TYPE fv_list;
199
200         /* Profiles this recipe is associated with */
201         u8 num_profs, *prof_ids;
202
203         /* This allows user to specify the recipe priority.
204          * For now, this becomes 'fwd_priority' when recipe
205          * is created, usually recipes can have 'fwd' and 'join'
206          * priority.
207          */
208         u8 priority;
209
210         struct LIST_HEAD_TYPE rg_list;
211
212         /* AQ buffer associated with this recipe */
213         struct ice_aqc_recipe_data_elem *root_buf;
214 };
215
216 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */
217 struct ice_vsi_list_map_info {
218         struct LIST_ENTRY_TYPE list_entry;
219         ice_declare_bitmap(vsi_map, ICE_MAX_VSI);
220         u16 vsi_list_id;
221         /* counter to track how many rules are reusing this VSI list */
222         u16 ref_cnt;
223 };
224
225 struct ice_fltr_list_entry {
226         struct LIST_ENTRY_TYPE list_entry;
227         enum ice_status status;
228         struct ice_fltr_info fltr_info;
229 };
230
231 /* This defines an entry in the list that maintains MAC or VLAN membership
232  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
233  * VLAN. As an optimization the VSI list should be created only when a
234  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
235  * used for VLAN membership.
236  */
237 struct ice_fltr_mgmt_list_entry {
238         /* back pointer to VSI list id to VSI list mapping */
239         struct ice_vsi_list_map_info *vsi_list_info;
240         u16 vsi_count;
241 #define ICE_INVAL_LG_ACT_INDEX 0xffff
242         u16 lg_act_idx;
243 #define ICE_INVAL_SW_MARKER_ID 0xffff
244         u16 sw_marker_id;
245         struct LIST_ENTRY_TYPE list_entry;
246         struct ice_fltr_info fltr_info;
247 #define ICE_INVAL_COUNTER_ID 0xff
248         u8 counter_index;
249 };
250
251 struct ice_adv_fltr_mgmt_list_entry {
252         struct LIST_ENTRY_TYPE list_entry;
253
254         struct ice_adv_lkup_elem *lkups;
255         struct ice_adv_rule_info rule_info;
256         u16 lkups_cnt;
257 };
258
259 enum ice_promisc_flags {
260         ICE_PROMISC_UCAST_RX = 0x1,
261         ICE_PROMISC_UCAST_TX = 0x2,
262         ICE_PROMISC_MCAST_RX = 0x4,
263         ICE_PROMISC_MCAST_TX = 0x8,
264         ICE_PROMISC_BCAST_RX = 0x10,
265         ICE_PROMISC_BCAST_TX = 0x20,
266         ICE_PROMISC_VLAN_RX = 0x40,
267         ICE_PROMISC_VLAN_TX = 0x80,
268 };
269
270 /* VSI related commands */
271 enum ice_status
272 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
273             struct ice_sq_cd *cd);
274 enum ice_status
275 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
276              bool keep_vsi_alloc, struct ice_sq_cd *cd);
277 enum ice_status
278 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
279                struct ice_sq_cd *cd);
280 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
281 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
282 /* Switch config */
283 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
284
285 enum ice_status
286 ice_alloc_vlan_res_counter(struct ice_hw *hw, u16 *counter_id);
287 enum ice_status
288 ice_free_vlan_res_counter(struct ice_hw *hw, u16 counter_id);
289
290 /* Switch/bridge related commands */
291 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
292 enum ice_status
293 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list);
294 enum ice_status ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
295 enum ice_status ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_lst);
296 enum ice_status
297 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list);
298 #ifndef NO_MACVLAN_SUPPORT
299 enum ice_status
300 ice_add_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list);
301 enum ice_status
302 ice_remove_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list);
303 #endif /* !NO_MACVLAN_SUPPORT */
304
305 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
306
307
308 /* Promisc/defport setup for VSIs */
309 enum ice_status
310 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
311                  u8 direction);
312 enum ice_status
313 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
314                     u16 vid);
315 enum ice_status
316 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
317                       u16 vid);
318 enum ice_status
319 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
320                          bool rm_vlan_promisc);
321
322
323
324
325
326 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);
327 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
328 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
329
330 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
331 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
332
333 #endif /* _ICE_SWITCH_H_ */