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_VSI_INVAL_ID 0xffff
12 
13 /* VSI context structure for add/get/update/free operations */
14 struct ice_vsi_ctx {
15 	u16 vsi_num;
16 	u16 vsis_allocd;
17 	u16 vsis_unallocated;
18 	u16 flags;
19 	struct ice_aqc_vsi_props info;
20 	struct ice_sched_vsi_info sched;
21 	u8 alloc_from_pool;
22 	u8 vf_num;
23 };
24 
25 enum ice_sw_fwd_act_type {
26 	ICE_FWD_TO_VSI = 0,
27 	ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */
28 	ICE_FWD_TO_Q,
29 	ICE_FWD_TO_QGRP,
30 	ICE_DROP_PACKET,
31 	ICE_INVAL_ACT
32 };
33 
34 /* Switch recipe ID enum values are specific to hardware */
35 enum ice_sw_lkup_type {
36 	ICE_SW_LKUP_ETHERTYPE = 0,
37 	ICE_SW_LKUP_MAC = 1,
38 	ICE_SW_LKUP_MAC_VLAN = 2,
39 	ICE_SW_LKUP_PROMISC = 3,
40 	ICE_SW_LKUP_VLAN = 4,
41 	ICE_SW_LKUP_DFLT = 5,
42 	ICE_SW_LKUP_ETHERTYPE_MAC = 8,
43 	ICE_SW_LKUP_PROMISC_VLAN = 9,
44 	ICE_SW_LKUP_LAST
45 };
46 
47 /* type of filter src id */
48 enum ice_src_id {
49 	ICE_SRC_ID_UNKNOWN = 0,
50 	ICE_SRC_ID_VSI,
51 	ICE_SRC_ID_QUEUE,
52 	ICE_SRC_ID_LPORT,
53 };
54 
55 struct ice_fltr_info {
56 	/* Look up information: how to look up packet */
57 	enum ice_sw_lkup_type lkup_type;
58 	/* Forward action: filter action to do after lookup */
59 	enum ice_sw_fwd_act_type fltr_act;
60 	/* rule ID returned by firmware once filter rule is created */
61 	u16 fltr_rule_id;
62 	u16 flag;
63 #define ICE_FLTR_RX		BIT(0)
64 #define ICE_FLTR_TX		BIT(1)
65 #define ICE_FLTR_TX_RX		(ICE_FLTR_RX | ICE_FLTR_TX)
66 
67 	/* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */
68 	u16 src;
69 	enum ice_src_id src_id;
70 
71 	union {
72 		struct {
73 			u8 mac_addr[ETH_ALEN];
74 		} mac;
75 		struct {
76 			u8 mac_addr[ETH_ALEN];
77 			u16 vlan_id;
78 		} mac_vlan;
79 		struct {
80 			u16 vlan_id;
81 		} vlan;
82 		/* Set lkup_type as ICE_SW_LKUP_ETHERTYPE
83 		 * if just using ethertype as filter. Set lkup_type as
84 		 * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be
85 		 * passed in as filter.
86 		 */
87 		struct {
88 			u16 ethertype;
89 			u8 mac_addr[ETH_ALEN]; /* optional */
90 		} ethertype_mac;
91 	} l_data; /* Make sure to zero out the memory of l_data before using
92 		   * it or only set the data associated with lookup match
93 		   * rest everything should be zero
94 		   */
95 
96 	/* Depending on filter action */
97 	union {
98 		/* queue id in case of ICE_FWD_TO_Q and starting
99 		 * queue id in case of ICE_FWD_TO_QGRP.
100 		 */
101 		u16 q_id:11;
102 		u16 hw_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_sw_recipe {
121 	struct list_head l_entry;
122 
123 	/* To protect modification of filt_rule list
124 	 * defined below
125 	 */
126 	struct mutex filt_rule_lock;
127 
128 	/* List of type ice_fltr_mgmt_list_entry */
129 	struct list_head filt_rules;
130 	struct list_head filt_replay_rules;
131 
132 	/* linked list of type recipe_list_entry */
133 	struct list_head rg_list;
134 	/* linked list of type ice_sw_fv_list_entry*/
135 	struct list_head fv_list;
136 	struct ice_aqc_recipe_data_elem *r_buf;
137 	u8 recp_count;
138 	u8 root_rid;
139 	u8 num_profs;
140 	u8 *prof_ids;
141 
142 	/* recipe bitmap: what all recipes makes this recipe */
143 	DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);
144 };
145 
146 /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */
147 struct ice_vsi_list_map_info {
148 	struct list_head list_entry;
149 	DECLARE_BITMAP(vsi_map, ICE_MAX_VSI);
150 	u16 vsi_list_id;
151 	/* counter to track how many rules are reusing this VSI list */
152 	u16 ref_cnt;
153 };
154 
155 struct ice_fltr_list_entry {
156 	struct list_head list_entry;
157 	enum ice_status status;
158 	struct ice_fltr_info fltr_info;
159 };
160 
161 /* This defines an entry in the list that maintains MAC or VLAN membership
162  * to HW list mapping, since multiple VSIs can subscribe to the same MAC or
163  * VLAN. As an optimization the VSI list should be created only when a
164  * second VSI becomes a subscriber to the same MAC address. VSI lists are always
165  * used for VLAN membership.
166  */
167 struct ice_fltr_mgmt_list_entry {
168 	/* back pointer to VSI list id to VSI list mapping */
169 	struct ice_vsi_list_map_info *vsi_list_info;
170 	u16 vsi_count;
171 #define ICE_INVAL_LG_ACT_INDEX 0xffff
172 	u16 lg_act_idx;
173 #define ICE_INVAL_SW_MARKER_ID 0xffff
174 	u16 sw_marker_id;
175 	struct list_head list_entry;
176 	struct ice_fltr_info fltr_info;
177 #define ICE_INVAL_COUNTER_ID 0xff
178 	u8 counter_index;
179 };
180 
181 /* VSI related commands */
182 enum ice_status
183 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
184 	    struct ice_sq_cd *cd);
185 enum ice_status
186 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
187 	     bool keep_vsi_alloc, struct ice_sq_cd *cd);
188 enum ice_status
189 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
190 	       struct ice_sq_cd *cd);
191 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
192 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
193 void ice_clear_all_vsi_ctx(struct ice_hw *hw);
194 /* Switch config */
195 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw);
196 
197 /* Switch/bridge related commands */
198 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw);
199 enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst);
200 enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst);
201 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle);
202 enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);
203 enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);
204 enum ice_status
205 ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction);
206 
207 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);
208 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle);
209 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle);
210 
211 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle);
212 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw);
213 
214 #endif /* _ICE_SWITCH_H_ */
215