xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/intel/ice/ice_switch.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* Copyright (c) 2018, Intel Corporation. */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #ifndef _ICE_SWITCH_H_
5*4882a593Smuzhiyun #define _ICE_SWITCH_H_
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include "ice_common.h"
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #define ICE_SW_CFG_MAX_BUF_LEN 2048
10*4882a593Smuzhiyun #define ICE_DFLT_VSI_INVAL 0xff
11*4882a593Smuzhiyun #define ICE_FLTR_RX BIT(0)
12*4882a593Smuzhiyun #define ICE_FLTR_TX BIT(1)
13*4882a593Smuzhiyun #define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX)
14*4882a593Smuzhiyun #define ICE_VSI_INVAL_ID 0xffff
15*4882a593Smuzhiyun #define ICE_INVAL_Q_HANDLE 0xFFFF
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* VSI context structure for add/get/update/free operations */
18*4882a593Smuzhiyun struct ice_vsi_ctx {
19*4882a593Smuzhiyun 	u16 vsi_num;
20*4882a593Smuzhiyun 	u16 vsis_allocd;
21*4882a593Smuzhiyun 	u16 vsis_unallocated;
22*4882a593Smuzhiyun 	u16 flags;
23*4882a593Smuzhiyun 	struct ice_aqc_vsi_props info;
24*4882a593Smuzhiyun 	struct ice_sched_vsi_info sched;
25*4882a593Smuzhiyun 	u8 alloc_from_pool;
26*4882a593Smuzhiyun 	u8 vf_num;
27*4882a593Smuzhiyun 	u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS];
28*4882a593Smuzhiyun 	struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS];
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun enum ice_sw_fwd_act_type {
32*4882a593Smuzhiyun 	ICE_FWD_TO_VSI = 0,
33*4882a593Smuzhiyun 	ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
34*4882a593Smuzhiyun 	ICE_FWD_TO_Q,
35*4882a593Smuzhiyun 	ICE_FWD_TO_QGRP,
36*4882a593Smuzhiyun 	ICE_DROP_PACKET,
37*4882a593Smuzhiyun 	ICE_INVAL_ACT
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* Switch recipe ID enum values are specific to hardware */
41*4882a593Smuzhiyun enum ice_sw_lkup_type {
42*4882a593Smuzhiyun 	ICE_SW_LKUP_ETHERTYPE = 0,
43*4882a593Smuzhiyun 	ICE_SW_LKUP_MAC = 1,
44*4882a593Smuzhiyun 	ICE_SW_LKUP_MAC_VLAN = 2,
45*4882a593Smuzhiyun 	ICE_SW_LKUP_PROMISC = 3,
46*4882a593Smuzhiyun 	ICE_SW_LKUP_VLAN = 4,
47*4882a593Smuzhiyun 	ICE_SW_LKUP_DFLT = 5,
48*4882a593Smuzhiyun 	ICE_SW_LKUP_ETHERTYPE_MAC = 8,
49*4882a593Smuzhiyun 	ICE_SW_LKUP_PROMISC_VLAN = 9,
50*4882a593Smuzhiyun 	ICE_SW_LKUP_LAST
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /* type of filter src ID */
54*4882a593Smuzhiyun enum ice_src_id {
55*4882a593Smuzhiyun 	ICE_SRC_ID_UNKNOWN = 0,
56*4882a593Smuzhiyun 	ICE_SRC_ID_VSI,
57*4882a593Smuzhiyun 	ICE_SRC_ID_QUEUE,
58*4882a593Smuzhiyun 	ICE_SRC_ID_LPORT,
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun struct ice_fltr_info {
62*4882a593Smuzhiyun 	/* Look up information: how to look up packet */
63*4882a593Smuzhiyun 	enum ice_sw_lkup_type lkup_type;
64*4882a593Smuzhiyun 	/* Forward action: filter action to do after lookup */
65*4882a593Smuzhiyun 	enum ice_sw_fwd_act_type fltr_act;
66*4882a593Smuzhiyun 	/* rule ID returned by firmware once filter rule is created */
67*4882a593Smuzhiyun 	u16 fltr_rule_id;
68*4882a593Smuzhiyun 	u16 flag;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	/* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
71*4882a593Smuzhiyun 	u16 src;
72*4882a593Smuzhiyun 	enum ice_src_id src_id;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	union {
75*4882a593Smuzhiyun 		struct {
76*4882a593Smuzhiyun 			u8 mac_addr[ETH_ALEN];
77*4882a593Smuzhiyun 		} mac;
78*4882a593Smuzhiyun 		struct {
79*4882a593Smuzhiyun 			u8 mac_addr[ETH_ALEN];
80*4882a593Smuzhiyun 			u16 vlan_id;
81*4882a593Smuzhiyun 		} mac_vlan;
82*4882a593Smuzhiyun 		struct {
83*4882a593Smuzhiyun 			u16 vlan_id;
84*4882a593Smuzhiyun 		} vlan;
85*4882a593Smuzhiyun 		/* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
86*4882a593Smuzhiyun 		 * if just using ethertype as filter. Set lkup_type as
87*4882a593Smuzhiyun 		 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
88*4882a593Smuzhiyun 		 * passed in as filter.
89*4882a593Smuzhiyun 		 */
90*4882a593Smuzhiyun 		struct {
91*4882a593Smuzhiyun 			u16 ethertype;
92*4882a593Smuzhiyun 			u8 mac_addr[ETH_ALEN]; /* optional */
93*4882a593Smuzhiyun 		} ethertype_mac;
94*4882a593Smuzhiyun 	} l_data; /* Make sure to zero out the memory of l_data before using
95*4882a593Smuzhiyun 		   * it or only set the data associated with lookup match
96*4882a593Smuzhiyun 		   * rest everything should be zero
97*4882a593Smuzhiyun 		   */
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	/* Depending on filter action */
100*4882a593Smuzhiyun 	union {
101*4882a593Smuzhiyun 		/* queue ID in case of ICE_FWD_TO_Q and starting
102*4882a593Smuzhiyun 		 * queue ID in case of ICE_FWD_TO_QGRP.
103*4882a593Smuzhiyun 		 */
104*4882a593Smuzhiyun 		u16 q_id:11;
105*4882a593Smuzhiyun 		u16 hw_vsi_id:10;
106*4882a593Smuzhiyun 		u16 vsi_list_id:10;
107*4882a593Smuzhiyun 	} fwd_id;
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	/* Sw VSI handle */
110*4882a593Smuzhiyun 	u16 vsi_handle;
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	/* Set to num_queues if action is ICE_FWD_TO_QGRP. This field
113*4882a593Smuzhiyun 	 * determines the range of queues the packet needs to be forwarded to.
114*4882a593Smuzhiyun 	 * Note that qgrp_size must be set to a power of 2.
115*4882a593Smuzhiyun 	 */
116*4882a593Smuzhiyun 	u8 qgrp_size;
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	/* Rule creations populate these indicators basing on the switch type */
119*4882a593Smuzhiyun 	u8 lb_en;	/* Indicate if packet can be looped back */
120*4882a593Smuzhiyun 	u8 lan_en;	/* Indicate if packet can be forwarded to the uplink */
121*4882a593Smuzhiyun };
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun struct ice_sw_recipe {
124*4882a593Smuzhiyun 	struct list_head l_entry;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	/* To protect modification of filt_rule list
127*4882a593Smuzhiyun 	 * defined below
128*4882a593Smuzhiyun 	 */
129*4882a593Smuzhiyun 	struct mutex filt_rule_lock;
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	/* List of type ice_fltr_mgmt_list_entry */
132*4882a593Smuzhiyun 	struct list_head filt_rules;
133*4882a593Smuzhiyun 	struct list_head filt_replay_rules;
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	/* linked list of type recipe_list_entry */
136*4882a593Smuzhiyun 	struct list_head rg_list;
137*4882a593Smuzhiyun 	/* linked list of type ice_sw_fv_list_entry*/
138*4882a593Smuzhiyun 	struct list_head fv_list;
139*4882a593Smuzhiyun 	struct ice_aqc_recipe_data_elem *r_buf;
140*4882a593Smuzhiyun 	u8 recp_count;
141*4882a593Smuzhiyun 	u8 root_rid;
142*4882a593Smuzhiyun 	u8 num_profs;
143*4882a593Smuzhiyun 	u8 *prof_ids;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	/* recipe bitmap: what all recipes makes this recipe */
146*4882a593Smuzhiyun 	DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */
150*4882a593Smuzhiyun struct ice_vsi_list_map_info {
151*4882a593Smuzhiyun 	struct list_head list_entry;
152*4882a593Smuzhiyun 	DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
153*4882a593Smuzhiyun 	u16 vsi_list_id;
154*4882a593Smuzhiyun 	/* counter to track how many rules are reusing this VSI list */
155*4882a593Smuzhiyun 	u16 ref_cnt;
156*4882a593Smuzhiyun };
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun struct ice_fltr_list_entry {
159*4882a593Smuzhiyun 	struct list_head list_entry;
160*4882a593Smuzhiyun 	enum ice_status status;
161*4882a593Smuzhiyun 	struct ice_fltr_info fltr_info;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /* This defines an entry in the list that maintains MAC or VLAN membership
165*4882a593Smuzhiyun  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
166*4882a593Smuzhiyun  * VLAN. As an optimization the VSI list should be created only when a
167*4882a593Smuzhiyun  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
168*4882a593Smuzhiyun  * used for VLAN membership.
169*4882a593Smuzhiyun  */
170*4882a593Smuzhiyun struct ice_fltr_mgmt_list_entry {
171*4882a593Smuzhiyun 	/* back pointer to VSI list ID to VSI list mapping */
172*4882a593Smuzhiyun 	struct ice_vsi_list_map_info *vsi_list_info;
173*4882a593Smuzhiyun 	u16 vsi_count;
174*4882a593Smuzhiyun #define ICE_INVAL_LG_ACT_INDEX 0xffff
175*4882a593Smuzhiyun 	u16 lg_act_idx;
176*4882a593Smuzhiyun #define ICE_INVAL_SW_MARKER_ID 0xffff
177*4882a593Smuzhiyun 	u16 sw_marker_id;
178*4882a593Smuzhiyun 	struct list_head list_entry;
179*4882a593Smuzhiyun 	struct ice_fltr_info fltr_info;
180*4882a593Smuzhiyun #define ICE_INVAL_COUNTER_ID 0xff
181*4882a593Smuzhiyun 	u8 counter_index;
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun enum ice_promisc_flags {
185*4882a593Smuzhiyun 	ICE_PROMISC_UCAST_RX = 0x1,
186*4882a593Smuzhiyun 	ICE_PROMISC_UCAST_TX = 0x2,
187*4882a593Smuzhiyun 	ICE_PROMISC_MCAST_RX = 0x4,
188*4882a593Smuzhiyun 	ICE_PROMISC_MCAST_TX = 0x8,
189*4882a593Smuzhiyun 	ICE_PROMISC_BCAST_RX = 0x10,
190*4882a593Smuzhiyun 	ICE_PROMISC_BCAST_TX = 0x20,
191*4882a593Smuzhiyun 	ICE_PROMISC_VLAN_RX = 0x40,
192*4882a593Smuzhiyun 	ICE_PROMISC_VLAN_TX = 0x80,
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /* VSI related commands */
196*4882a593Smuzhiyun enum ice_status
197*4882a593Smuzhiyun ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
198*4882a593Smuzhiyun 	    struct ice_sq_cd *cd);
199*4882a593Smuzhiyun enum ice_status
200*4882a593Smuzhiyun ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
201*4882a593Smuzhiyun 	     bool keep_vsi_alloc, struct ice_sq_cd *cd);
202*4882a593Smuzhiyun enum ice_status
203*4882a593Smuzhiyun ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
204*4882a593Smuzhiyun 	       struct ice_sq_cd *cd);
205*4882a593Smuzhiyun bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
206*4882a593Smuzhiyun struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
207*4882a593Smuzhiyun void ice_clear_all_vsi_ctx(struct ice_hw *hw);
208*4882a593Smuzhiyun /* Switch config */
209*4882a593Smuzhiyun enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun enum ice_status
212*4882a593Smuzhiyun ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
213*4882a593Smuzhiyun 		   u16 *counter_id);
214*4882a593Smuzhiyun enum ice_status
215*4882a593Smuzhiyun ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
216*4882a593Smuzhiyun 		  u16 counter_id);
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun /* Switch/bridge related commands */
219*4882a593Smuzhiyun enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
220*4882a593Smuzhiyun enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
221*4882a593Smuzhiyun enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
222*4882a593Smuzhiyun enum ice_status
223*4882a593Smuzhiyun ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list);
224*4882a593Smuzhiyun enum ice_status
225*4882a593Smuzhiyun ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list);
226*4882a593Smuzhiyun void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
227*4882a593Smuzhiyun enum ice_status
228*4882a593Smuzhiyun ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
229*4882a593Smuzhiyun enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /* Promisc/defport setup for VSIs */
232*4882a593Smuzhiyun enum ice_status
233*4882a593Smuzhiyun ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction);
234*4882a593Smuzhiyun enum ice_status
235*4882a593Smuzhiyun ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
236*4882a593Smuzhiyun 		    u16 vid);
237*4882a593Smuzhiyun enum ice_status
238*4882a593Smuzhiyun ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
239*4882a593Smuzhiyun 		      u16 vid);
240*4882a593Smuzhiyun enum ice_status
241*4882a593Smuzhiyun ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
242*4882a593Smuzhiyun 			 bool rm_vlan_promisc);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);
245*4882a593Smuzhiyun u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
246*4882a593Smuzhiyun bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
249*4882a593Smuzhiyun void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun #endif /* _ICE_SWITCH_H_ */
252