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