1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2018
5 #include "ice_switch.h"
6 #include "ice_flex_type.h"
10 #define ICE_ETH_DA_OFFSET 0
11 #define ICE_ETH_ETHTYPE_OFFSET 12
12 #define ICE_ETH_VLAN_TCI_OFFSET 14
13 #define ICE_MAX_VLAN_ID 0xFFF
15 /* Dummy ethernet header needed in the ice_aqc_sw_rules_elem
16 * struct to configure any switch filter rules.
17 * {DA (6 bytes), SA(6 bytes),
18 * Ether type (2 bytes for header without VLAN tag) OR
19 * VLAN tag (4 bytes for header with VLAN tag) }
21 * Word on Hardcoded values
22 * byte 0 = 0x2: to identify it as locally administered DA MAC
23 * byte 6 = 0x2: to identify it as locally administered SA MAC
24 * byte 12 = 0x81 & byte 13 = 0x00:
25 * In case of VLAN filter first two bytes defines ether type (0x8100)
26 * and remaining two bytes are placeholder for programming a given VLAN ID
27 * In case of Ether type filter it is treated as header without VLAN tag
28 * and byte 12 and 13 is used to program a given Ether type instead
30 #define DUMMY_ETH_HDR_LEN 16
31 static const u8 dummy_eth_header[DUMMY_ETH_HDR_LEN] = { 0x2, 0, 0, 0, 0, 0,
35 #define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
36 (sizeof(struct ice_aqc_sw_rules_elem) - \
37 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
38 sizeof(struct ice_sw_rule_lkup_rx_tx) + DUMMY_ETH_HDR_LEN - 1)
39 #define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
40 (sizeof(struct ice_aqc_sw_rules_elem) - \
41 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
42 sizeof(struct ice_sw_rule_lkup_rx_tx) - 1)
43 #define ICE_SW_RULE_LG_ACT_SIZE(n) \
44 (sizeof(struct ice_aqc_sw_rules_elem) - \
45 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
46 sizeof(struct ice_sw_rule_lg_act) - \
47 sizeof(((struct ice_sw_rule_lg_act *)0)->act) + \
48 ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act)))
49 #define ICE_SW_RULE_VSI_LIST_SIZE(n) \
50 (sizeof(struct ice_aqc_sw_rules_elem) - \
51 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
52 sizeof(struct ice_sw_rule_vsi_list) - \
53 sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi) + \
54 ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi)))
58 * ice_init_def_sw_recp - initialize the recipe book keeping tables
59 * @hw: pointer to the HW struct
61 * Allocate memory for the entire recipe table and initialize the structures/
62 * entries corresponding to basic recipes.
64 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw)
66 struct ice_sw_recipe *recps;
69 recps = (struct ice_sw_recipe *)
70 ice_calloc(hw, ICE_MAX_NUM_RECIPES, sizeof(*recps));
72 return ICE_ERR_NO_MEMORY;
74 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
75 recps[i].root_rid = i;
76 INIT_LIST_HEAD(&recps[i].filt_rules);
77 INIT_LIST_HEAD(&recps[i].filt_replay_rules);
78 ice_init_lock(&recps[i].filt_rule_lock);
81 hw->switch_info->recp_list = recps;
87 * ice_aq_get_sw_cfg - get switch configuration
88 * @hw: pointer to the hardware structure
89 * @buf: pointer to the result buffer
90 * @buf_size: length of the buffer available for response
91 * @req_desc: pointer to requested descriptor
92 * @num_elems: pointer to number of elements
93 * @cd: pointer to command details structure or NULL
95 * Get switch configuration (0x0200) to be placed in 'buff'.
96 * This admin command returns information such as initial VSI/port number
97 * and switch ID it belongs to.
99 * NOTE: *req_desc is both an input/output parameter.
100 * The caller of this function first calls this function with *request_desc set
101 * to 0. If the response from f/w has *req_desc set to 0, all the switch
102 * configuration information has been returned; if non-zero (meaning not all
103 * the information was returned), the caller should call this function again
104 * with *req_desc set to the previous value returned by f/w to get the
105 * next block of switch configuration information.
107 * *num_elems is output only parameter. This reflects the number of elements
108 * in response buffer. The caller of this function to use *num_elems while
109 * parsing the response buffer.
111 static enum ice_status
112 ice_aq_get_sw_cfg(struct ice_hw *hw, struct ice_aqc_get_sw_cfg_resp *buf,
113 u16 buf_size, u16 *req_desc, u16 *num_elems,
114 struct ice_sq_cd *cd)
116 struct ice_aqc_get_sw_cfg *cmd;
117 enum ice_status status;
118 struct ice_aq_desc desc;
120 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_sw_cfg);
121 cmd = &desc.params.get_sw_conf;
122 cmd->element = CPU_TO_LE16(*req_desc);
124 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
126 *req_desc = LE16_TO_CPU(cmd->element);
127 *num_elems = LE16_TO_CPU(cmd->num_elems);
135 * ice_alloc_sw - allocate resources specific to switch
136 * @hw: pointer to the HW struct
137 * @ena_stats: true to turn on VEB stats
138 * @shared_res: true for shared resource, false for dedicated resource
139 * @sw_id: switch ID returned
140 * @counter_id: VEB counter ID returned
142 * allocates switch resources (SWID and VEB counter) (0x0208)
145 ice_alloc_sw(struct ice_hw *hw, bool ena_stats, bool shared_res, u16 *sw_id,
148 struct ice_aqc_alloc_free_res_elem *sw_buf;
149 struct ice_aqc_res_elem *sw_ele;
150 enum ice_status status;
153 buf_len = sizeof(*sw_buf);
154 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
155 ice_malloc(hw, buf_len);
157 return ICE_ERR_NO_MEMORY;
159 /* Prepare buffer for switch ID.
160 * The number of resource entries in buffer is passed as 1 since only a
161 * single switch/VEB instance is allocated, and hence a single sw_id
164 sw_buf->num_elems = CPU_TO_LE16(1);
166 CPU_TO_LE16(ICE_AQC_RES_TYPE_SWID |
167 (shared_res ? ICE_AQC_RES_TYPE_FLAG_SHARED :
168 ICE_AQC_RES_TYPE_FLAG_DEDICATED));
170 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
171 ice_aqc_opc_alloc_res, NULL);
174 goto ice_alloc_sw_exit;
176 sw_ele = &sw_buf->elem[0];
177 *sw_id = LE16_TO_CPU(sw_ele->e.sw_resp);
180 /* Prepare buffer for VEB Counter */
181 enum ice_adminq_opc opc = ice_aqc_opc_alloc_res;
182 struct ice_aqc_alloc_free_res_elem *counter_buf;
183 struct ice_aqc_res_elem *counter_ele;
185 counter_buf = (struct ice_aqc_alloc_free_res_elem *)
186 ice_malloc(hw, buf_len);
188 status = ICE_ERR_NO_MEMORY;
189 goto ice_alloc_sw_exit;
192 /* The number of resource entries in buffer is passed as 1 since
193 * only a single switch/VEB instance is allocated, and hence a
194 * single VEB counter is requested.
196 counter_buf->num_elems = CPU_TO_LE16(1);
197 counter_buf->res_type =
198 CPU_TO_LE16(ICE_AQC_RES_TYPE_VEB_COUNTER |
199 ICE_AQC_RES_TYPE_FLAG_DEDICATED);
200 status = ice_aq_alloc_free_res(hw, 1, counter_buf, buf_len,
204 ice_free(hw, counter_buf);
205 goto ice_alloc_sw_exit;
207 counter_ele = &counter_buf->elem[0];
208 *counter_id = LE16_TO_CPU(counter_ele->e.sw_resp);
209 ice_free(hw, counter_buf);
213 ice_free(hw, sw_buf);
218 * ice_free_sw - free resources specific to switch
219 * @hw: pointer to the HW struct
220 * @sw_id: switch ID returned
221 * @counter_id: VEB counter ID returned
223 * free switch resources (SWID and VEB counter) (0x0209)
225 * NOTE: This function frees multiple resources. It continues
226 * releasing other resources even after it encounters error.
227 * The error code returned is the last error it encountered.
229 enum ice_status ice_free_sw(struct ice_hw *hw, u16 sw_id, u16 counter_id)
231 struct ice_aqc_alloc_free_res_elem *sw_buf, *counter_buf;
232 enum ice_status status, ret_status;
235 buf_len = sizeof(*sw_buf);
236 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
237 ice_malloc(hw, buf_len);
239 return ICE_ERR_NO_MEMORY;
241 /* Prepare buffer to free for switch ID res.
242 * The number of resource entries in buffer is passed as 1 since only a
243 * single switch/VEB instance is freed, and hence a single sw_id
246 sw_buf->num_elems = CPU_TO_LE16(1);
247 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_SWID);
248 sw_buf->elem[0].e.sw_resp = CPU_TO_LE16(sw_id);
250 ret_status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
251 ice_aqc_opc_free_res, NULL);
254 ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
256 /* Prepare buffer to free for VEB Counter resource */
257 counter_buf = (struct ice_aqc_alloc_free_res_elem *)
258 ice_malloc(hw, buf_len);
260 ice_free(hw, sw_buf);
261 return ICE_ERR_NO_MEMORY;
264 /* The number of resource entries in buffer is passed as 1 since only a
265 * single switch/VEB instance is freed, and hence a single VEB counter
268 counter_buf->num_elems = CPU_TO_LE16(1);
269 counter_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_VEB_COUNTER);
270 counter_buf->elem[0].e.sw_resp = CPU_TO_LE16(counter_id);
272 status = ice_aq_alloc_free_res(hw, 1, counter_buf, buf_len,
273 ice_aqc_opc_free_res, NULL);
275 ice_debug(hw, ICE_DBG_SW,
276 "VEB counter resource could not be freed\n");
280 ice_free(hw, counter_buf);
281 ice_free(hw, sw_buf);
287 * @hw: pointer to the HW struct
288 * @vsi_ctx: pointer to a VSI context struct
289 * @cd: pointer to command details structure or NULL
291 * Add a VSI context to the hardware (0x0210)
294 ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
295 struct ice_sq_cd *cd)
297 struct ice_aqc_add_update_free_vsi_resp *res;
298 struct ice_aqc_add_get_update_free_vsi *cmd;
299 struct ice_aq_desc desc;
300 enum ice_status status;
302 cmd = &desc.params.vsi_cmd;
303 res = &desc.params.add_update_free_vsi_res;
305 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_vsi);
307 if (!vsi_ctx->alloc_from_pool)
308 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num |
309 ICE_AQ_VSI_IS_VALID);
311 cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
313 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
315 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
316 sizeof(vsi_ctx->info), cd);
319 vsi_ctx->vsi_num = LE16_TO_CPU(res->vsi_num) & ICE_AQ_VSI_NUM_M;
320 vsi_ctx->vsis_allocd = LE16_TO_CPU(res->vsi_used);
321 vsi_ctx->vsis_unallocated = LE16_TO_CPU(res->vsi_free);
329 * @hw: pointer to the HW struct
330 * @vsi_ctx: pointer to a VSI context struct
331 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
332 * @cd: pointer to command details structure or NULL
334 * Free VSI context info from hardware (0x0213)
337 ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
338 bool keep_vsi_alloc, struct ice_sq_cd *cd)
340 struct ice_aqc_add_update_free_vsi_resp *resp;
341 struct ice_aqc_add_get_update_free_vsi *cmd;
342 struct ice_aq_desc desc;
343 enum ice_status status;
345 cmd = &desc.params.vsi_cmd;
346 resp = &desc.params.add_update_free_vsi_res;
348 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_free_vsi);
350 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
352 cmd->cmd_flags = CPU_TO_LE16(ICE_AQ_VSI_KEEP_ALLOC);
354 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
356 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
357 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
365 * @hw: pointer to the HW struct
366 * @vsi_ctx: pointer to a VSI context struct
367 * @cd: pointer to command details structure or NULL
369 * Update VSI context in the hardware (0x0211)
372 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
373 struct ice_sq_cd *cd)
375 struct ice_aqc_add_update_free_vsi_resp *resp;
376 struct ice_aqc_add_get_update_free_vsi *cmd;
377 struct ice_aq_desc desc;
378 enum ice_status status;
380 cmd = &desc.params.vsi_cmd;
381 resp = &desc.params.add_update_free_vsi_res;
383 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_vsi);
385 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
387 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
389 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
390 sizeof(vsi_ctx->info), cd);
393 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
394 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
401 * ice_is_vsi_valid - check whether the VSI is valid or not
402 * @hw: pointer to the HW struct
403 * @vsi_handle: VSI handle
405 * check whether the VSI is valid or not
407 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle)
409 return vsi_handle < ICE_MAX_VSI && hw->vsi_ctx[vsi_handle];
413 * ice_get_hw_vsi_num - return the HW VSI number
414 * @hw: pointer to the HW struct
415 * @vsi_handle: VSI handle
417 * return the HW VSI number
418 * Caution: call this function only if VSI is valid (ice_is_vsi_valid)
420 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle)
422 return hw->vsi_ctx[vsi_handle]->vsi_num;
426 * ice_get_vsi_ctx - return the VSI context entry for a given VSI handle
427 * @hw: pointer to the HW struct
428 * @vsi_handle: VSI handle
430 * return the VSI context entry for a given VSI handle
432 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
434 return (vsi_handle >= ICE_MAX_VSI) ? NULL : hw->vsi_ctx[vsi_handle];
438 * ice_save_vsi_ctx - save the VSI context for a given VSI handle
439 * @hw: pointer to the HW struct
440 * @vsi_handle: VSI handle
441 * @vsi: VSI context pointer
443 * save the VSI context entry for a given VSI handle
446 ice_save_vsi_ctx(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi)
448 hw->vsi_ctx[vsi_handle] = vsi;
452 * ice_clear_vsi_q_ctx - clear VSI queue contexts for all TCs
453 * @hw: pointer to the HW struct
454 * @vsi_handle: VSI handle
456 static void ice_clear_vsi_q_ctx(struct ice_hw *hw, u16 vsi_handle)
458 struct ice_vsi_ctx *vsi;
461 vsi = ice_get_vsi_ctx(hw, vsi_handle);
464 ice_for_each_traffic_class(i) {
465 if (vsi->lan_q_ctx[i]) {
466 ice_free(hw, vsi->lan_q_ctx[i]);
467 vsi->lan_q_ctx[i] = NULL;
473 * ice_clear_vsi_ctx - clear the VSI context entry
474 * @hw: pointer to the HW struct
475 * @vsi_handle: VSI handle
477 * clear the VSI context entry
479 static void ice_clear_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
481 struct ice_vsi_ctx *vsi;
483 vsi = ice_get_vsi_ctx(hw, vsi_handle);
485 if (!LIST_EMPTY(&vsi->rss_list_head))
486 ice_rem_all_rss_vsi_ctx(hw, vsi_handle);
487 ice_clear_vsi_q_ctx(hw, vsi_handle);
488 ice_destroy_lock(&vsi->rss_locks);
490 hw->vsi_ctx[vsi_handle] = NULL;
495 * ice_clear_all_vsi_ctx - clear all the VSI context entries
496 * @hw: pointer to the HW struct
498 void ice_clear_all_vsi_ctx(struct ice_hw *hw)
502 for (i = 0; i < ICE_MAX_VSI; i++)
503 ice_clear_vsi_ctx(hw, i);
507 * ice_add_vsi - add VSI context to the hardware and VSI handle list
508 * @hw: pointer to the HW struct
509 * @vsi_handle: unique VSI handle provided by drivers
510 * @vsi_ctx: pointer to a VSI context struct
511 * @cd: pointer to command details structure or NULL
513 * Add a VSI context to the hardware also add it into the VSI handle list.
514 * If this function gets called after reset for existing VSIs then update
515 * with the new HW VSI number in the corresponding VSI handle list entry.
518 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
519 struct ice_sq_cd *cd)
521 struct ice_vsi_ctx *tmp_vsi_ctx;
522 enum ice_status status;
524 if (vsi_handle >= ICE_MAX_VSI)
525 return ICE_ERR_PARAM;
526 status = ice_aq_add_vsi(hw, vsi_ctx, cd);
529 tmp_vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
531 /* Create a new VSI context */
532 tmp_vsi_ctx = (struct ice_vsi_ctx *)
533 ice_malloc(hw, sizeof(*tmp_vsi_ctx));
535 ice_aq_free_vsi(hw, vsi_ctx, false, cd);
536 return ICE_ERR_NO_MEMORY;
538 *tmp_vsi_ctx = *vsi_ctx;
539 ice_init_lock(&tmp_vsi_ctx->rss_locks);
540 INIT_LIST_HEAD(&tmp_vsi_ctx->rss_list_head);
541 ice_save_vsi_ctx(hw, vsi_handle, tmp_vsi_ctx);
543 /* update with new HW VSI num */
544 if (tmp_vsi_ctx->vsi_num != vsi_ctx->vsi_num)
545 tmp_vsi_ctx->vsi_num = vsi_ctx->vsi_num;
552 * ice_free_vsi- free VSI context from hardware and VSI handle list
553 * @hw: pointer to the HW struct
554 * @vsi_handle: unique VSI handle
555 * @vsi_ctx: pointer to a VSI context struct
556 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
557 * @cd: pointer to command details structure or NULL
559 * Free VSI context info from hardware as well as from VSI handle list
562 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
563 bool keep_vsi_alloc, struct ice_sq_cd *cd)
565 enum ice_status status;
567 if (!ice_is_vsi_valid(hw, vsi_handle))
568 return ICE_ERR_PARAM;
569 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
570 status = ice_aq_free_vsi(hw, vsi_ctx, keep_vsi_alloc, cd);
572 ice_clear_vsi_ctx(hw, vsi_handle);
578 * @hw: pointer to the HW struct
579 * @vsi_handle: unique VSI handle
580 * @vsi_ctx: pointer to a VSI context struct
581 * @cd: pointer to command details structure or NULL
583 * Update VSI context in the hardware
586 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
587 struct ice_sq_cd *cd)
589 if (!ice_is_vsi_valid(hw, vsi_handle))
590 return ICE_ERR_PARAM;
591 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
592 return ice_aq_update_vsi(hw, vsi_ctx, cd);
596 * ice_aq_get_vsi_params
597 * @hw: pointer to the HW struct
598 * @vsi_ctx: pointer to a VSI context struct
599 * @cd: pointer to command details structure or NULL
601 * Get VSI context info from hardware (0x0212)
604 ice_aq_get_vsi_params(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
605 struct ice_sq_cd *cd)
607 struct ice_aqc_add_get_update_free_vsi *cmd;
608 struct ice_aqc_get_vsi_resp *resp;
609 struct ice_aq_desc desc;
610 enum ice_status status;
612 cmd = &desc.params.vsi_cmd;
613 resp = &desc.params.get_vsi_resp;
615 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_vsi_params);
617 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
619 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
620 sizeof(vsi_ctx->info), cd);
622 vsi_ctx->vsi_num = LE16_TO_CPU(resp->vsi_num) &
624 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
625 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
632 * ice_aq_add_update_mir_rule - add/update a mirror rule
633 * @hw: pointer to the HW struct
634 * @rule_type: Rule Type
635 * @dest_vsi: VSI number to which packets will be mirrored
636 * @count: length of the list
637 * @mr_buf: buffer for list of mirrored VSI numbers
638 * @cd: pointer to command details structure or NULL
641 * Add/Update Mirror Rule (0x260).
644 ice_aq_add_update_mir_rule(struct ice_hw *hw, u16 rule_type, u16 dest_vsi,
645 u16 count, struct ice_mir_rule_buf *mr_buf,
646 struct ice_sq_cd *cd, u16 *rule_id)
648 struct ice_aqc_add_update_mir_rule *cmd;
649 struct ice_aq_desc desc;
650 enum ice_status status;
651 __le16 *mr_list = NULL;
655 case ICE_AQC_RULE_TYPE_VPORT_INGRESS:
656 case ICE_AQC_RULE_TYPE_VPORT_EGRESS:
657 /* Make sure count and mr_buf are set for these rule_types */
658 if (!(count && mr_buf))
659 return ICE_ERR_PARAM;
661 buf_size = count * sizeof(__le16);
662 mr_list = (__le16 *)ice_malloc(hw, buf_size);
664 return ICE_ERR_NO_MEMORY;
666 case ICE_AQC_RULE_TYPE_PPORT_INGRESS:
667 case ICE_AQC_RULE_TYPE_PPORT_EGRESS:
668 /* Make sure count and mr_buf are not set for these
672 return ICE_ERR_PARAM;
675 ice_debug(hw, ICE_DBG_SW,
676 "Error due to unsupported rule_type %u\n", rule_type);
677 return ICE_ERR_OUT_OF_RANGE;
680 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_update_mir_rule);
682 /* Pre-process 'mr_buf' items for add/update of virtual port
683 * ingress/egress mirroring (but not physical port ingress/egress
689 for (i = 0; i < count; i++) {
692 id = mr_buf[i].vsi_idx & ICE_AQC_RULE_MIRRORED_VSI_M;
694 /* Validate specified VSI number, make sure it is less
695 * than ICE_MAX_VSI, if not return with error.
697 if (id >= ICE_MAX_VSI) {
698 ice_debug(hw, ICE_DBG_SW,
699 "Error VSI index (%u) out-of-range\n",
701 ice_free(hw, mr_list);
702 return ICE_ERR_OUT_OF_RANGE;
705 /* add VSI to mirror rule */
708 CPU_TO_LE16(id | ICE_AQC_RULE_ACT_M);
709 else /* remove VSI from mirror rule */
710 mr_list[i] = CPU_TO_LE16(id);
714 cmd = &desc.params.add_update_rule;
715 if ((*rule_id) != ICE_INVAL_MIRROR_RULE_ID)
716 cmd->rule_id = CPU_TO_LE16(((*rule_id) & ICE_AQC_RULE_ID_M) |
717 ICE_AQC_RULE_ID_VALID_M);
718 cmd->rule_type = CPU_TO_LE16(rule_type & ICE_AQC_RULE_TYPE_M);
719 cmd->num_entries = CPU_TO_LE16(count);
720 cmd->dest = CPU_TO_LE16(dest_vsi);
722 status = ice_aq_send_cmd(hw, &desc, mr_list, buf_size, cd);
724 *rule_id = LE16_TO_CPU(cmd->rule_id) & ICE_AQC_RULE_ID_M;
726 ice_free(hw, mr_list);
732 * ice_aq_delete_mir_rule - delete a mirror rule
733 * @hw: pointer to the HW struct
734 * @rule_id: Mirror rule ID (to be deleted)
735 * @keep_allocd: if set, the VSI stays part of the PF allocated res,
736 * otherwise it is returned to the shared pool
737 * @cd: pointer to command details structure or NULL
739 * Delete Mirror Rule (0x261).
742 ice_aq_delete_mir_rule(struct ice_hw *hw, u16 rule_id, bool keep_allocd,
743 struct ice_sq_cd *cd)
745 struct ice_aqc_delete_mir_rule *cmd;
746 struct ice_aq_desc desc;
748 /* rule_id should be in the range 0...63 */
749 if (rule_id >= ICE_MAX_NUM_MIRROR_RULES)
750 return ICE_ERR_OUT_OF_RANGE;
752 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_del_mir_rule);
754 cmd = &desc.params.del_rule;
755 rule_id |= ICE_AQC_RULE_ID_VALID_M;
756 cmd->rule_id = CPU_TO_LE16(rule_id);
759 cmd->flags = CPU_TO_LE16(ICE_AQC_FLAG_KEEP_ALLOCD_M);
761 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
765 * ice_aq_alloc_free_vsi_list
766 * @hw: pointer to the HW struct
767 * @vsi_list_id: VSI list ID returned or used for lookup
768 * @lkup_type: switch rule filter lookup type
769 * @opc: switch rules population command type - pass in the command opcode
771 * allocates or free a VSI list resource
773 static enum ice_status
774 ice_aq_alloc_free_vsi_list(struct ice_hw *hw, u16 *vsi_list_id,
775 enum ice_sw_lkup_type lkup_type,
776 enum ice_adminq_opc opc)
778 struct ice_aqc_alloc_free_res_elem *sw_buf;
779 struct ice_aqc_res_elem *vsi_ele;
780 enum ice_status status;
783 buf_len = sizeof(*sw_buf);
784 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
785 ice_malloc(hw, buf_len);
787 return ICE_ERR_NO_MEMORY;
788 sw_buf->num_elems = CPU_TO_LE16(1);
790 if (lkup_type == ICE_SW_LKUP_MAC ||
791 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
792 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
793 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
794 lkup_type == ICE_SW_LKUP_PROMISC ||
795 lkup_type == ICE_SW_LKUP_PROMISC_VLAN) {
796 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_REP);
797 } else if (lkup_type == ICE_SW_LKUP_VLAN) {
799 CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_PRUNE);
801 status = ICE_ERR_PARAM;
802 goto ice_aq_alloc_free_vsi_list_exit;
805 if (opc == ice_aqc_opc_free_res)
806 sw_buf->elem[0].e.sw_resp = CPU_TO_LE16(*vsi_list_id);
808 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len, opc, NULL);
810 goto ice_aq_alloc_free_vsi_list_exit;
812 if (opc == ice_aqc_opc_alloc_res) {
813 vsi_ele = &sw_buf->elem[0];
814 *vsi_list_id = LE16_TO_CPU(vsi_ele->e.sw_resp);
817 ice_aq_alloc_free_vsi_list_exit:
818 ice_free(hw, sw_buf);
823 * ice_aq_set_storm_ctrl - Sets storm control configuration
824 * @hw: pointer to the HW struct
825 * @bcast_thresh: represents the upper threshold for broadcast storm control
826 * @mcast_thresh: represents the upper threshold for multicast storm control
827 * @ctl_bitmask: storm control control knobs
829 * Sets the storm control configuration (0x0280)
832 ice_aq_set_storm_ctrl(struct ice_hw *hw, u32 bcast_thresh, u32 mcast_thresh,
835 struct ice_aqc_storm_cfg *cmd;
836 struct ice_aq_desc desc;
838 cmd = &desc.params.storm_conf;
840 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_storm_cfg);
842 cmd->bcast_thresh_size = CPU_TO_LE32(bcast_thresh & ICE_AQ_THRESHOLD_M);
843 cmd->mcast_thresh_size = CPU_TO_LE32(mcast_thresh & ICE_AQ_THRESHOLD_M);
844 cmd->storm_ctrl_ctrl = CPU_TO_LE32(ctl_bitmask);
846 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
850 * ice_aq_get_storm_ctrl - gets storm control configuration
851 * @hw: pointer to the HW struct
852 * @bcast_thresh: represents the upper threshold for broadcast storm control
853 * @mcast_thresh: represents the upper threshold for multicast storm control
854 * @ctl_bitmask: storm control control knobs
856 * Gets the storm control configuration (0x0281)
859 ice_aq_get_storm_ctrl(struct ice_hw *hw, u32 *bcast_thresh, u32 *mcast_thresh,
862 enum ice_status status;
863 struct ice_aq_desc desc;
865 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_storm_cfg);
867 status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
869 struct ice_aqc_storm_cfg *resp = &desc.params.storm_conf;
872 *bcast_thresh = LE32_TO_CPU(resp->bcast_thresh_size) &
875 *mcast_thresh = LE32_TO_CPU(resp->mcast_thresh_size) &
878 *ctl_bitmask = LE32_TO_CPU(resp->storm_ctrl_ctrl);
885 * ice_aq_sw_rules - add/update/remove switch rules
886 * @hw: pointer to the HW struct
887 * @rule_list: pointer to switch rule population list
888 * @rule_list_sz: total size of the rule list in bytes
889 * @num_rules: number of switch rules in the rule_list
890 * @opc: switch rules population command type - pass in the command opcode
891 * @cd: pointer to command details structure or NULL
893 * Add(0x02a0)/Update(0x02a1)/Remove(0x02a2) switch rules commands to firmware
895 static enum ice_status
896 ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
897 u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd)
899 struct ice_aq_desc desc;
901 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_sw_rules");
903 if (opc != ice_aqc_opc_add_sw_rules &&
904 opc != ice_aqc_opc_update_sw_rules &&
905 opc != ice_aqc_opc_remove_sw_rules)
906 return ICE_ERR_PARAM;
908 ice_fill_dflt_direct_cmd_desc(&desc, opc);
910 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
911 desc.params.sw_rules.num_rules_fltr_entry_index =
912 CPU_TO_LE16(num_rules);
913 return ice_aq_send_cmd(hw, &desc, rule_list, rule_list_sz, cd);
917 /* ice_init_port_info - Initialize port_info with switch configuration data
918 * @pi: pointer to port_info
919 * @vsi_port_num: VSI number or port number
920 * @type: Type of switch element (port or VSI)
921 * @swid: switch ID of the switch the element is attached to
922 * @pf_vf_num: PF or VF number
923 * @is_vf: true if the element is a VF, false otherwise
926 ice_init_port_info(struct ice_port_info *pi, u16 vsi_port_num, u8 type,
927 u16 swid, u16 pf_vf_num, bool is_vf)
930 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
931 pi->lport = (u8)(vsi_port_num & ICE_LPORT_MASK);
933 pi->pf_vf_num = pf_vf_num;
935 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
936 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
939 ice_debug(pi->hw, ICE_DBG_SW,
940 "incorrect VSI/port type received\n");
945 /* ice_get_initial_sw_cfg - Get initial port and default VSI data
946 * @hw: pointer to the hardware structure
948 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw)
950 struct ice_aqc_get_sw_cfg_resp *rbuf;
951 enum ice_status status;
960 rbuf = (struct ice_aqc_get_sw_cfg_resp *)
961 ice_malloc(hw, ICE_SW_CFG_MAX_BUF_LEN);
964 return ICE_ERR_NO_MEMORY;
966 /* Multiple calls to ice_aq_get_sw_cfg may be required
967 * to get all the switch configuration information. The need
968 * for additional calls is indicated by ice_aq_get_sw_cfg
969 * writing a non-zero value in req_desc
972 status = ice_aq_get_sw_cfg(hw, rbuf, ICE_SW_CFG_MAX_BUF_LEN,
973 &req_desc, &num_elems, NULL);
978 for (i = 0; i < num_elems; i++) {
979 struct ice_aqc_get_sw_cfg_resp_elem *ele;
980 u16 pf_vf_num, swid, vsi_port_num;
984 ele = rbuf[i].elements;
985 vsi_port_num = LE16_TO_CPU(ele->vsi_port_num) &
986 ICE_AQC_GET_SW_CONF_RESP_VSI_PORT_NUM_M;
988 pf_vf_num = LE16_TO_CPU(ele->pf_vf_num) &
989 ICE_AQC_GET_SW_CONF_RESP_FUNC_NUM_M;
991 swid = LE16_TO_CPU(ele->swid);
993 if (LE16_TO_CPU(ele->pf_vf_num) &
994 ICE_AQC_GET_SW_CONF_RESP_IS_VF)
997 type = LE16_TO_CPU(ele->vsi_port_num) >>
998 ICE_AQC_GET_SW_CONF_RESP_TYPE_S;
1001 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
1002 case ICE_AQC_GET_SW_CONF_RESP_VIRT_PORT:
1003 if (j == num_total_ports) {
1004 ice_debug(hw, ICE_DBG_SW,
1005 "more ports than expected\n");
1006 status = ICE_ERR_CFG;
1009 ice_init_port_info(hw->port_info,
1010 vsi_port_num, type, swid,
1018 } while (req_desc && !status);
1022 ice_free(hw, (void *)rbuf);
1028 * ice_fill_sw_info - Helper function to populate lb_en and lan_en
1029 * @hw: pointer to the hardware structure
1030 * @fi: filter info structure to fill/update
1032 * This helper function populates the lb_en and lan_en elements of the provided
1033 * ice_fltr_info struct using the switch's type and characteristics of the
1034 * switch rule being configured.
1036 static void ice_fill_sw_info(struct ice_hw *hw, struct ice_fltr_info *fi)
1040 if ((fi->flag & ICE_FLTR_TX) &&
1041 (fi->fltr_act == ICE_FWD_TO_VSI ||
1042 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1043 fi->fltr_act == ICE_FWD_TO_Q ||
1044 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1045 /* Setting LB for prune actions will result in replicated
1046 * packets to the internal switch that will be dropped.
1048 if (fi->lkup_type != ICE_SW_LKUP_VLAN)
1051 /* Set lan_en to TRUE if
1052 * 1. The switch is a VEB AND
1054 * 2.1 The lookup is a directional lookup like ethertype,
1055 * promiscuous, ethertype-MAC, promiscuous-VLAN
1056 * and default-port OR
1057 * 2.2 The lookup is VLAN, OR
1058 * 2.3 The lookup is MAC with mcast or bcast addr for MAC, OR
1059 * 2.4 The lookup is MAC_VLAN with mcast or bcast addr for MAC.
1063 * The switch is a VEPA.
1065 * In all other cases, the LAN enable has to be set to false.
1068 if (fi->lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1069 fi->lkup_type == ICE_SW_LKUP_PROMISC ||
1070 fi->lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1071 fi->lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
1072 fi->lkup_type == ICE_SW_LKUP_DFLT ||
1073 fi->lkup_type == ICE_SW_LKUP_VLAN ||
1074 (fi->lkup_type == ICE_SW_LKUP_MAC &&
1075 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)) ||
1076 (fi->lkup_type == ICE_SW_LKUP_MAC_VLAN &&
1077 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)))
1086 * ice_ilog2 - Calculates integer log base 2 of a number
1087 * @n: number on which to perform operation
1089 static int ice_ilog2(u64 n)
1093 for (i = 63; i >= 0; i--)
1094 if (((u64)1 << i) & n)
1102 * ice_fill_sw_rule - Helper function to fill switch rule structure
1103 * @hw: pointer to the hardware structure
1104 * @f_info: entry containing packet forwarding information
1105 * @s_rule: switch rule structure to be filled in based on mac_entry
1106 * @opc: switch rules population command type - pass in the command opcode
1109 ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
1110 struct ice_aqc_sw_rules_elem *s_rule, enum ice_adminq_opc opc)
1112 u16 vlan_id = ICE_MAX_VLAN_ID + 1;
1121 if (opc == ice_aqc_opc_remove_sw_rules) {
1122 s_rule->pdata.lkup_tx_rx.act = 0;
1123 s_rule->pdata.lkup_tx_rx.index =
1124 CPU_TO_LE16(f_info->fltr_rule_id);
1125 s_rule->pdata.lkup_tx_rx.hdr_len = 0;
1129 eth_hdr_sz = sizeof(dummy_eth_header);
1130 eth_hdr = s_rule->pdata.lkup_tx_rx.hdr;
1132 /* initialize the ether header with a dummy header */
1133 ice_memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz, ICE_NONDMA_TO_NONDMA);
1134 ice_fill_sw_info(hw, f_info);
1136 switch (f_info->fltr_act) {
1137 case ICE_FWD_TO_VSI:
1138 act |= (f_info->fwd_id.hw_vsi_id << ICE_SINGLE_ACT_VSI_ID_S) &
1139 ICE_SINGLE_ACT_VSI_ID_M;
1140 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
1141 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
1142 ICE_SINGLE_ACT_VALID_BIT;
1144 case ICE_FWD_TO_VSI_LIST:
1145 act |= ICE_SINGLE_ACT_VSI_LIST;
1146 act |= (f_info->fwd_id.vsi_list_id <<
1147 ICE_SINGLE_ACT_VSI_LIST_ID_S) &
1148 ICE_SINGLE_ACT_VSI_LIST_ID_M;
1149 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
1150 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
1151 ICE_SINGLE_ACT_VALID_BIT;
1154 act |= ICE_SINGLE_ACT_TO_Q;
1155 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
1156 ICE_SINGLE_ACT_Q_INDEX_M;
1158 case ICE_DROP_PACKET:
1159 act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
1160 ICE_SINGLE_ACT_VALID_BIT;
1162 case ICE_FWD_TO_QGRP:
1163 q_rgn = f_info->qgrp_size > 0 ?
1164 (u8)ice_ilog2(f_info->qgrp_size) : 0;
1165 act |= ICE_SINGLE_ACT_TO_Q;
1166 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
1167 ICE_SINGLE_ACT_Q_INDEX_M;
1168 act |= (q_rgn << ICE_SINGLE_ACT_Q_REGION_S) &
1169 ICE_SINGLE_ACT_Q_REGION_M;
1176 act |= ICE_SINGLE_ACT_LB_ENABLE;
1178 act |= ICE_SINGLE_ACT_LAN_ENABLE;
1180 switch (f_info->lkup_type) {
1181 case ICE_SW_LKUP_MAC:
1182 daddr = f_info->l_data.mac.mac_addr;
1184 case ICE_SW_LKUP_VLAN:
1185 vlan_id = f_info->l_data.vlan.vlan_id;
1186 if (f_info->fltr_act == ICE_FWD_TO_VSI ||
1187 f_info->fltr_act == ICE_FWD_TO_VSI_LIST) {
1188 act |= ICE_SINGLE_ACT_PRUNE;
1189 act |= ICE_SINGLE_ACT_EGRESS | ICE_SINGLE_ACT_INGRESS;
1192 case ICE_SW_LKUP_ETHERTYPE_MAC:
1193 daddr = f_info->l_data.ethertype_mac.mac_addr;
1195 case ICE_SW_LKUP_ETHERTYPE:
1196 off = (__be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
1197 *off = CPU_TO_BE16(f_info->l_data.ethertype_mac.ethertype);
1199 case ICE_SW_LKUP_MAC_VLAN:
1200 daddr = f_info->l_data.mac_vlan.mac_addr;
1201 vlan_id = f_info->l_data.mac_vlan.vlan_id;
1203 case ICE_SW_LKUP_PROMISC_VLAN:
1204 vlan_id = f_info->l_data.mac_vlan.vlan_id;
1206 case ICE_SW_LKUP_PROMISC:
1207 daddr = f_info->l_data.mac_vlan.mac_addr;
1213 s_rule->type = (f_info->flag & ICE_FLTR_RX) ?
1214 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_RX) :
1215 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_TX);
1217 /* Recipe set depending on lookup type */
1218 s_rule->pdata.lkup_tx_rx.recipe_id = CPU_TO_LE16(f_info->lkup_type);
1219 s_rule->pdata.lkup_tx_rx.src = CPU_TO_LE16(f_info->src);
1220 s_rule->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
1223 ice_memcpy(eth_hdr + ICE_ETH_DA_OFFSET, daddr, ETH_ALEN,
1224 ICE_NONDMA_TO_NONDMA);
1226 if (!(vlan_id > ICE_MAX_VLAN_ID)) {
1227 off = (__be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
1228 *off = CPU_TO_BE16(vlan_id);
1231 /* Create the switch rule with the final dummy Ethernet header */
1232 if (opc != ice_aqc_opc_update_sw_rules)
1233 s_rule->pdata.lkup_tx_rx.hdr_len = CPU_TO_LE16(eth_hdr_sz);
1237 * ice_add_marker_act
1238 * @hw: pointer to the hardware structure
1239 * @m_ent: the management entry for which sw marker needs to be added
1240 * @sw_marker: sw marker to tag the Rx descriptor with
1241 * @l_id: large action resource ID
1243 * Create a large action to hold software marker and update the switch rule
1244 * entry pointed by m_ent with newly created large action
1246 static enum ice_status
1247 ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
1248 u16 sw_marker, u16 l_id)
1250 struct ice_aqc_sw_rules_elem *lg_act, *rx_tx;
1251 /* For software marker we need 3 large actions
1252 * 1. FWD action: FWD TO VSI or VSI LIST
1253 * 2. GENERIC VALUE action to hold the profile ID
1254 * 3. GENERIC VALUE action to hold the software marker ID
1256 const u16 num_lg_acts = 3;
1257 enum ice_status status;
1263 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
1264 return ICE_ERR_PARAM;
1266 /* Create two back-to-back switch rules and submit them to the HW using
1267 * one memory buffer:
1271 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_lg_acts);
1272 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1273 lg_act = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, rules_size);
1275 return ICE_ERR_NO_MEMORY;
1277 rx_tx = (struct ice_aqc_sw_rules_elem *)((u8 *)lg_act + lg_act_size);
1279 /* Fill in the first switch rule i.e. large action */
1280 lg_act->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_LG_ACT);
1281 lg_act->pdata.lg_act.index = CPU_TO_LE16(l_id);
1282 lg_act->pdata.lg_act.size = CPU_TO_LE16(num_lg_acts);
1284 /* First action VSI forwarding or VSI list forwarding depending on how
1287 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
1288 m_ent->fltr_info.fwd_id.hw_vsi_id;
1290 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
1291 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) &
1292 ICE_LG_ACT_VSI_LIST_ID_M;
1293 if (m_ent->vsi_count > 1)
1294 act |= ICE_LG_ACT_VSI_LIST;
1295 lg_act->pdata.lg_act.act[0] = CPU_TO_LE32(act);
1297 /* Second action descriptor type */
1298 act = ICE_LG_ACT_GENERIC;
1300 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
1301 lg_act->pdata.lg_act.act[1] = CPU_TO_LE32(act);
1303 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
1304 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
1306 /* Third action Marker value */
1307 act |= ICE_LG_ACT_GENERIC;
1308 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
1309 ICE_LG_ACT_GENERIC_VALUE_M;
1311 lg_act->pdata.lg_act.act[2] = CPU_TO_LE32(act);
1313 /* call the fill switch rule to fill the lookup Tx Rx structure */
1314 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
1315 ice_aqc_opc_update_sw_rules);
1317 /* Update the action to point to the large action ID */
1318 rx_tx->pdata.lkup_tx_rx.act =
1319 CPU_TO_LE32(ICE_SINGLE_ACT_PTR |
1320 ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
1321 ICE_SINGLE_ACT_PTR_VAL_M));
1323 /* Use the filter rule ID of the previously created rule with single
1324 * act. Once the update happens, hardware will treat this as large
1327 rx_tx->pdata.lkup_tx_rx.index =
1328 CPU_TO_LE16(m_ent->fltr_info.fltr_rule_id);
1330 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
1331 ice_aqc_opc_update_sw_rules, NULL);
1333 m_ent->lg_act_idx = l_id;
1334 m_ent->sw_marker_id = sw_marker;
1337 ice_free(hw, lg_act);
1343 * ice_create_vsi_list_map
1344 * @hw: pointer to the hardware structure
1345 * @vsi_handle_arr: array of VSI handles to set in the VSI mapping
1346 * @num_vsi: number of VSI handles in the array
1347 * @vsi_list_id: VSI list ID generated as part of allocate resource
1349 * Helper function to create a new entry of VSI list ID to VSI mapping
1350 * using the given VSI list ID
1352 static struct ice_vsi_list_map_info *
1353 ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1356 struct ice_switch_info *sw = hw->switch_info;
1357 struct ice_vsi_list_map_info *v_map;
1360 v_map = (struct ice_vsi_list_map_info *)ice_calloc(hw, 1,
1365 v_map->vsi_list_id = vsi_list_id;
1367 for (i = 0; i < num_vsi; i++)
1368 ice_set_bit(vsi_handle_arr[i], v_map->vsi_map);
1370 LIST_ADD(&v_map->list_entry, &sw->vsi_list_map_head);
1375 * ice_update_vsi_list_rule
1376 * @hw: pointer to the hardware structure
1377 * @vsi_handle_arr: array of VSI handles to form a VSI list
1378 * @num_vsi: number of VSI handles in the array
1379 * @vsi_list_id: VSI list ID generated as part of allocate resource
1380 * @remove: Boolean value to indicate if this is a remove action
1381 * @opc: switch rules population command type - pass in the command opcode
1382 * @lkup_type: lookup type of the filter
1384 * Call AQ command to add a new switch rule or update existing switch rule
1385 * using the given VSI list ID
1387 static enum ice_status
1388 ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1389 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
1390 enum ice_sw_lkup_type lkup_type)
1392 struct ice_aqc_sw_rules_elem *s_rule;
1393 enum ice_status status;
1399 return ICE_ERR_PARAM;
1401 if (lkup_type == ICE_SW_LKUP_MAC ||
1402 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
1403 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1404 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1405 lkup_type == ICE_SW_LKUP_PROMISC ||
1406 lkup_type == ICE_SW_LKUP_PROMISC_VLAN)
1407 type = remove ? ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR :
1408 ICE_AQC_SW_RULES_T_VSI_LIST_SET;
1409 else if (lkup_type == ICE_SW_LKUP_VLAN)
1410 type = remove ? ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR :
1411 ICE_AQC_SW_RULES_T_PRUNE_LIST_SET;
1413 return ICE_ERR_PARAM;
1415 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
1416 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1418 return ICE_ERR_NO_MEMORY;
1419 for (i = 0; i < num_vsi; i++) {
1420 if (!ice_is_vsi_valid(hw, vsi_handle_arr[i])) {
1421 status = ICE_ERR_PARAM;
1424 /* AQ call requires hw_vsi_id(s) */
1425 s_rule->pdata.vsi_list.vsi[i] =
1426 CPU_TO_LE16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
1429 s_rule->type = CPU_TO_LE16(type);
1430 s_rule->pdata.vsi_list.number_vsi = CPU_TO_LE16(num_vsi);
1431 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1433 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
1436 ice_free(hw, s_rule);
1441 * ice_create_vsi_list_rule - Creates and populates a VSI list rule
1442 * @hw: pointer to the HW struct
1443 * @vsi_handle_arr: array of VSI handles to form a VSI list
1444 * @num_vsi: number of VSI handles in the array
1445 * @vsi_list_id: stores the ID of the VSI list to be created
1446 * @lkup_type: switch rule filter's lookup type
1448 static enum ice_status
1449 ice_create_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1450 u16 *vsi_list_id, enum ice_sw_lkup_type lkup_type)
1452 enum ice_status status;
1454 status = ice_aq_alloc_free_vsi_list(hw, vsi_list_id, lkup_type,
1455 ice_aqc_opc_alloc_res);
1459 /* Update the newly created VSI list to include the specified VSIs */
1460 return ice_update_vsi_list_rule(hw, vsi_handle_arr, num_vsi,
1461 *vsi_list_id, false,
1462 ice_aqc_opc_add_sw_rules, lkup_type);
1466 * ice_create_pkt_fwd_rule
1467 * @hw: pointer to the hardware structure
1468 * @f_entry: entry containing packet forwarding information
1470 * Create switch rule with given filter information and add an entry
1471 * to the corresponding filter management list to track this switch rule
1474 static enum ice_status
1475 ice_create_pkt_fwd_rule(struct ice_hw *hw,
1476 struct ice_fltr_list_entry *f_entry)
1478 struct ice_fltr_mgmt_list_entry *fm_entry;
1479 struct ice_aqc_sw_rules_elem *s_rule;
1480 enum ice_sw_lkup_type l_type;
1481 struct ice_sw_recipe *recp;
1482 enum ice_status status;
1484 s_rule = (struct ice_aqc_sw_rules_elem *)
1485 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1487 return ICE_ERR_NO_MEMORY;
1488 fm_entry = (struct ice_fltr_mgmt_list_entry *)
1489 ice_malloc(hw, sizeof(*fm_entry));
1491 status = ICE_ERR_NO_MEMORY;
1492 goto ice_create_pkt_fwd_rule_exit;
1495 fm_entry->fltr_info = f_entry->fltr_info;
1497 /* Initialize all the fields for the management entry */
1498 fm_entry->vsi_count = 1;
1499 fm_entry->lg_act_idx = ICE_INVAL_LG_ACT_INDEX;
1500 fm_entry->sw_marker_id = ICE_INVAL_SW_MARKER_ID;
1501 fm_entry->counter_index = ICE_INVAL_COUNTER_ID;
1503 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
1504 ice_aqc_opc_add_sw_rules);
1506 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1507 ice_aqc_opc_add_sw_rules, NULL);
1509 ice_free(hw, fm_entry);
1510 goto ice_create_pkt_fwd_rule_exit;
1513 f_entry->fltr_info.fltr_rule_id =
1514 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1515 fm_entry->fltr_info.fltr_rule_id =
1516 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1518 /* The book keeping entries will get removed when base driver
1519 * calls remove filter AQ command
1521 l_type = fm_entry->fltr_info.lkup_type;
1522 recp = &hw->switch_info->recp_list[l_type];
1523 LIST_ADD(&fm_entry->list_entry, &recp->filt_rules);
1525 ice_create_pkt_fwd_rule_exit:
1526 ice_free(hw, s_rule);
1531 * ice_update_pkt_fwd_rule
1532 * @hw: pointer to the hardware structure
1533 * @f_info: filter information for switch rule
1535 * Call AQ command to update a previously created switch rule with a
1538 static enum ice_status
1539 ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
1541 struct ice_aqc_sw_rules_elem *s_rule;
1542 enum ice_status status;
1544 s_rule = (struct ice_aqc_sw_rules_elem *)
1545 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1547 return ICE_ERR_NO_MEMORY;
1549 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
1551 s_rule->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_info->fltr_rule_id);
1553 /* Update switch rule with new rule set to forward VSI list */
1554 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1555 ice_aqc_opc_update_sw_rules, NULL);
1557 ice_free(hw, s_rule);
1562 * ice_update_sw_rule_bridge_mode
1563 * @hw: pointer to the HW struct
1565 * Updates unicast switch filter rules based on VEB/VEPA mode
1567 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw)
1569 struct ice_switch_info *sw = hw->switch_info;
1570 struct ice_fltr_mgmt_list_entry *fm_entry;
1571 enum ice_status status = ICE_SUCCESS;
1572 struct LIST_HEAD_TYPE *rule_head;
1573 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1575 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1576 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1578 ice_acquire_lock(rule_lock);
1579 LIST_FOR_EACH_ENTRY(fm_entry, rule_head, ice_fltr_mgmt_list_entry,
1581 struct ice_fltr_info *fi = &fm_entry->fltr_info;
1582 u8 *addr = fi->l_data.mac.mac_addr;
1584 /* Update unicast Tx rules to reflect the selected
1587 if ((fi->flag & ICE_FLTR_TX) && IS_UNICAST_ETHER_ADDR(addr) &&
1588 (fi->fltr_act == ICE_FWD_TO_VSI ||
1589 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1590 fi->fltr_act == ICE_FWD_TO_Q ||
1591 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1592 status = ice_update_pkt_fwd_rule(hw, fi);
1598 ice_release_lock(rule_lock);
1604 * ice_add_update_vsi_list
1605 * @hw: pointer to the hardware structure
1606 * @m_entry: pointer to current filter management list entry
1607 * @cur_fltr: filter information from the book keeping entry
1608 * @new_fltr: filter information with the new VSI to be added
1610 * Call AQ command to add or update previously created VSI list with new VSI.
1612 * Helper function to do book keeping associated with adding filter information
1613 * The algorithm to do the book keeping is described below :
1614 * When a VSI needs to subscribe to a given filter (MAC/VLAN/Ethtype etc.)
1615 * if only one VSI has been added till now
1616 * Allocate a new VSI list and add two VSIs
1617 * to this list using switch rule command
1618 * Update the previously created switch rule with the
1619 * newly created VSI list ID
1620 * if a VSI list was previously created
1621 * Add the new VSI to the previously created VSI list set
1622 * using the update switch rule command
1624 static enum ice_status
1625 ice_add_update_vsi_list(struct ice_hw *hw,
1626 struct ice_fltr_mgmt_list_entry *m_entry,
1627 struct ice_fltr_info *cur_fltr,
1628 struct ice_fltr_info *new_fltr)
1630 enum ice_status status = ICE_SUCCESS;
1631 u16 vsi_list_id = 0;
1633 if ((cur_fltr->fltr_act == ICE_FWD_TO_Q ||
1634 cur_fltr->fltr_act == ICE_FWD_TO_QGRP))
1635 return ICE_ERR_NOT_IMPL;
1637 if ((new_fltr->fltr_act == ICE_FWD_TO_Q ||
1638 new_fltr->fltr_act == ICE_FWD_TO_QGRP) &&
1639 (cur_fltr->fltr_act == ICE_FWD_TO_VSI ||
1640 cur_fltr->fltr_act == ICE_FWD_TO_VSI_LIST))
1641 return ICE_ERR_NOT_IMPL;
1643 if (m_entry->vsi_count < 2 && !m_entry->vsi_list_info) {
1644 /* Only one entry existed in the mapping and it was not already
1645 * a part of a VSI list. So, create a VSI list with the old and
1648 struct ice_fltr_info tmp_fltr;
1649 u16 vsi_handle_arr[2];
1651 /* A rule already exists with the new VSI being added */
1652 if (cur_fltr->fwd_id.hw_vsi_id == new_fltr->fwd_id.hw_vsi_id)
1653 return ICE_ERR_ALREADY_EXISTS;
1655 vsi_handle_arr[0] = cur_fltr->vsi_handle;
1656 vsi_handle_arr[1] = new_fltr->vsi_handle;
1657 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1659 new_fltr->lkup_type);
1663 tmp_fltr = *new_fltr;
1664 tmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;
1665 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1666 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1667 /* Update the previous switch rule of "MAC forward to VSI" to
1668 * "MAC fwd to VSI list"
1670 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1674 cur_fltr->fwd_id.vsi_list_id = vsi_list_id;
1675 cur_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1676 m_entry->vsi_list_info =
1677 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1680 /* If this entry was large action then the large action needs
1681 * to be updated to point to FWD to VSI list
1683 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID)
1685 ice_add_marker_act(hw, m_entry,
1686 m_entry->sw_marker_id,
1687 m_entry->lg_act_idx);
1689 u16 vsi_handle = new_fltr->vsi_handle;
1690 enum ice_adminq_opc opcode;
1692 if (!m_entry->vsi_list_info)
1695 /* A rule already exists with the new VSI being added */
1696 if (ice_is_bit_set(m_entry->vsi_list_info->vsi_map, vsi_handle))
1699 /* Update the previously created VSI list set with
1700 * the new VSI ID passed in
1702 vsi_list_id = cur_fltr->fwd_id.vsi_list_id;
1703 opcode = ice_aqc_opc_update_sw_rules;
1705 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1,
1706 vsi_list_id, false, opcode,
1707 new_fltr->lkup_type);
1708 /* update VSI list mapping info with new VSI ID */
1710 ice_set_bit(vsi_handle,
1711 m_entry->vsi_list_info->vsi_map);
1714 m_entry->vsi_count++;
1719 * ice_find_rule_entry - Search a rule entry
1720 * @hw: pointer to the hardware structure
1721 * @recp_id: lookup type for which the specified rule needs to be searched
1722 * @f_info: rule information
1724 * Helper function to search for a given rule entry
1725 * Returns pointer to entry storing the rule if found
1727 static struct ice_fltr_mgmt_list_entry *
1728 ice_find_rule_entry(struct ice_hw *hw, u8 recp_id, struct ice_fltr_info *f_info)
1730 struct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;
1731 struct ice_switch_info *sw = hw->switch_info;
1732 struct LIST_HEAD_TYPE *list_head;
1734 list_head = &sw->recp_list[recp_id].filt_rules;
1735 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1737 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
1738 sizeof(f_info->l_data)) &&
1739 f_info->flag == list_itr->fltr_info.flag) {
1748 * ice_find_vsi_list_entry - Search VSI list map with VSI count 1
1749 * @hw: pointer to the hardware structure
1750 * @recp_id: lookup type for which VSI lists needs to be searched
1751 * @vsi_handle: VSI handle to be found in VSI list
1752 * @vsi_list_id: VSI list ID found containing vsi_handle
1754 * Helper function to search a VSI list with single entry containing given VSI
1755 * handle element. This can be extended further to search VSI list with more
1756 * than 1 vsi_count. Returns pointer to VSI list entry if found.
1758 static struct ice_vsi_list_map_info *
1759 ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
1762 struct ice_vsi_list_map_info *map_info = NULL;
1763 struct ice_switch_info *sw = hw->switch_info;
1764 struct ice_fltr_mgmt_list_entry *list_itr;
1765 struct LIST_HEAD_TYPE *list_head;
1767 list_head = &sw->recp_list[recp_id].filt_rules;
1768 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1770 if (list_itr->vsi_count == 1 && list_itr->vsi_list_info) {
1771 map_info = list_itr->vsi_list_info;
1772 if (ice_is_bit_set(map_info->vsi_map, vsi_handle)) {
1773 *vsi_list_id = map_info->vsi_list_id;
1782 * ice_add_rule_internal - add rule for a given lookup type
1783 * @hw: pointer to the hardware structure
1784 * @recp_id: lookup type (recipe ID) for which rule has to be added
1785 * @f_entry: structure containing MAC forwarding information
1787 * Adds or updates the rule lists for a given recipe
1789 static enum ice_status
1790 ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,
1791 struct ice_fltr_list_entry *f_entry)
1793 struct ice_switch_info *sw = hw->switch_info;
1794 struct ice_fltr_info *new_fltr, *cur_fltr;
1795 struct ice_fltr_mgmt_list_entry *m_entry;
1796 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1797 enum ice_status status = ICE_SUCCESS;
1799 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1800 return ICE_ERR_PARAM;
1802 /* Load the hw_vsi_id only if the fwd action is fwd to VSI */
1803 if (f_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI)
1804 f_entry->fltr_info.fwd_id.hw_vsi_id =
1805 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1807 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1809 ice_acquire_lock(rule_lock);
1810 new_fltr = &f_entry->fltr_info;
1811 if (new_fltr->flag & ICE_FLTR_RX)
1812 new_fltr->src = hw->port_info->lport;
1813 else if (new_fltr->flag & ICE_FLTR_TX)
1815 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1817 m_entry = ice_find_rule_entry(hw, recp_id, new_fltr);
1819 ice_release_lock(rule_lock);
1820 return ice_create_pkt_fwd_rule(hw, f_entry);
1823 cur_fltr = &m_entry->fltr_info;
1824 status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
1825 ice_release_lock(rule_lock);
1831 * ice_remove_vsi_list_rule
1832 * @hw: pointer to the hardware structure
1833 * @vsi_list_id: VSI list ID generated as part of allocate resource
1834 * @lkup_type: switch rule filter lookup type
1836 * The VSI list should be emptied before this function is called to remove the
1839 static enum ice_status
1840 ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
1841 enum ice_sw_lkup_type lkup_type)
1843 struct ice_aqc_sw_rules_elem *s_rule;
1844 enum ice_status status;
1847 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
1848 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1850 return ICE_ERR_NO_MEMORY;
1852 s_rule->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
1853 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1855 /* Free the vsi_list resource that we allocated. It is assumed that the
1856 * list is empty at this point.
1858 status = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,
1859 ice_aqc_opc_free_res);
1861 ice_free(hw, s_rule);
1866 * ice_rem_update_vsi_list
1867 * @hw: pointer to the hardware structure
1868 * @vsi_handle: VSI handle of the VSI to remove
1869 * @fm_list: filter management entry for which the VSI list management needs to
1872 static enum ice_status
1873 ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
1874 struct ice_fltr_mgmt_list_entry *fm_list)
1876 enum ice_sw_lkup_type lkup_type;
1877 enum ice_status status = ICE_SUCCESS;
1880 if (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||
1881 fm_list->vsi_count == 0)
1882 return ICE_ERR_PARAM;
1884 /* A rule with the VSI being removed does not exist */
1885 if (!ice_is_bit_set(fm_list->vsi_list_info->vsi_map, vsi_handle))
1886 return ICE_ERR_DOES_NOT_EXIST;
1888 lkup_type = fm_list->fltr_info.lkup_type;
1889 vsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;
1890 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
1891 ice_aqc_opc_update_sw_rules,
1896 fm_list->vsi_count--;
1897 ice_clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
1899 if (fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) {
1900 struct ice_fltr_info tmp_fltr_info = fm_list->fltr_info;
1901 struct ice_vsi_list_map_info *vsi_list_info =
1902 fm_list->vsi_list_info;
1905 rem_vsi_handle = ice_find_first_bit(vsi_list_info->vsi_map,
1907 if (!ice_is_vsi_valid(hw, rem_vsi_handle))
1908 return ICE_ERR_OUT_OF_RANGE;
1910 /* Make sure VSI list is empty before removing it below */
1911 status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
1913 ice_aqc_opc_update_sw_rules,
1918 tmp_fltr_info.fltr_act = ICE_FWD_TO_VSI;
1919 tmp_fltr_info.fwd_id.hw_vsi_id =
1920 ice_get_hw_vsi_num(hw, rem_vsi_handle);
1921 tmp_fltr_info.vsi_handle = rem_vsi_handle;
1922 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr_info);
1924 ice_debug(hw, ICE_DBG_SW,
1925 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
1926 tmp_fltr_info.fwd_id.hw_vsi_id, status);
1930 fm_list->fltr_info = tmp_fltr_info;
1933 if ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||
1934 (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {
1935 struct ice_vsi_list_map_info *vsi_list_info =
1936 fm_list->vsi_list_info;
1938 /* Remove the VSI list since it is no longer used */
1939 status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
1941 ice_debug(hw, ICE_DBG_SW,
1942 "Failed to remove VSI list %d, error %d\n",
1943 vsi_list_id, status);
1947 LIST_DEL(&vsi_list_info->list_entry);
1948 ice_free(hw, vsi_list_info);
1949 fm_list->vsi_list_info = NULL;
1956 * ice_remove_rule_internal - Remove a filter rule of a given type
1958 * @hw: pointer to the hardware structure
1959 * @recp_id: recipe ID for which the rule needs to removed
1960 * @f_entry: rule entry containing filter information
1962 static enum ice_status
1963 ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id,
1964 struct ice_fltr_list_entry *f_entry)
1966 struct ice_switch_info *sw = hw->switch_info;
1967 struct ice_fltr_mgmt_list_entry *list_elem;
1968 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1969 enum ice_status status = ICE_SUCCESS;
1970 bool remove_rule = false;
1973 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1974 return ICE_ERR_PARAM;
1975 f_entry->fltr_info.fwd_id.hw_vsi_id =
1976 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1978 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1979 ice_acquire_lock(rule_lock);
1980 list_elem = ice_find_rule_entry(hw, recp_id, &f_entry->fltr_info);
1982 status = ICE_ERR_DOES_NOT_EXIST;
1986 if (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {
1988 } else if (!list_elem->vsi_list_info) {
1989 status = ICE_ERR_DOES_NOT_EXIST;
1991 } else if (list_elem->vsi_list_info->ref_cnt > 1) {
1992 /* a ref_cnt > 1 indicates that the vsi_list is being
1993 * shared by multiple rules. Decrement the ref_cnt and
1994 * remove this rule, but do not modify the list, as it
1995 * is in-use by other rules.
1997 list_elem->vsi_list_info->ref_cnt--;
2000 /* a ref_cnt of 1 indicates the vsi_list is only used
2001 * by one rule. However, the original removal request is only
2002 * for a single VSI. Update the vsi_list first, and only
2003 * remove the rule if there are no further VSIs in this list.
2005 vsi_handle = f_entry->fltr_info.vsi_handle;
2006 status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem);
2009 /* if VSI count goes to zero after updating the VSI list */
2010 if (list_elem->vsi_count == 0)
2015 /* Remove the lookup rule */
2016 struct ice_aqc_sw_rules_elem *s_rule;
2018 s_rule = (struct ice_aqc_sw_rules_elem *)
2019 ice_malloc(hw, ICE_SW_RULE_RX_TX_NO_HDR_SIZE);
2021 status = ICE_ERR_NO_MEMORY;
2025 ice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,
2026 ice_aqc_opc_remove_sw_rules);
2028 status = ice_aq_sw_rules(hw, s_rule,
2029 ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
2030 ice_aqc_opc_remove_sw_rules, NULL);
2034 /* Remove a book keeping from the list */
2035 ice_free(hw, s_rule);
2037 LIST_DEL(&list_elem->list_entry);
2038 ice_free(hw, list_elem);
2041 ice_release_lock(rule_lock);
2047 * ice_add_mac - Add a MAC address based filter rule
2048 * @hw: pointer to the hardware structure
2049 * @m_list: list of MAC addresses and forwarding information
2051 * IMPORTANT: When the ucast_shared flag is set to false and m_list has
2052 * multiple unicast addresses, the function assumes that all the
2053 * addresses are unique in a given add_mac call. It doesn't
2054 * check for duplicates in this case, removing duplicates from a given
2055 * list should be taken care of in the caller of this function.
2058 ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2060 struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
2061 struct ice_fltr_list_entry *m_list_itr;
2062 struct LIST_HEAD_TYPE *rule_head;
2063 u16 elem_sent, total_elem_left;
2064 struct ice_switch_info *sw;
2065 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2066 enum ice_status status = ICE_SUCCESS;
2067 u16 num_unicast = 0;
2071 return ICE_ERR_PARAM;
2073 sw = hw->switch_info;
2074 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
2075 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2077 u8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];
2081 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
2082 vsi_handle = m_list_itr->fltr_info.vsi_handle;
2083 if (!ice_is_vsi_valid(hw, vsi_handle))
2084 return ICE_ERR_PARAM;
2085 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2086 m_list_itr->fltr_info.fwd_id.hw_vsi_id = hw_vsi_id;
2087 /* update the src in case it is VSI num */
2088 if (m_list_itr->fltr_info.src_id != ICE_SRC_ID_VSI)
2089 return ICE_ERR_PARAM;
2090 m_list_itr->fltr_info.src = hw_vsi_id;
2091 if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
2092 IS_ZERO_ETHER_ADDR(add))
2093 return ICE_ERR_PARAM;
2094 if (IS_UNICAST_ETHER_ADDR(add) && !hw->ucast_shared) {
2095 /* Don't overwrite the unicast address */
2096 ice_acquire_lock(rule_lock);
2097 if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
2098 &m_list_itr->fltr_info)) {
2099 ice_release_lock(rule_lock);
2100 return ICE_ERR_ALREADY_EXISTS;
2102 ice_release_lock(rule_lock);
2104 } else if (IS_MULTICAST_ETHER_ADDR(add) ||
2105 (IS_UNICAST_ETHER_ADDR(add) && hw->ucast_shared)) {
2106 m_list_itr->status =
2107 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
2109 if (m_list_itr->status)
2110 return m_list_itr->status;
2114 ice_acquire_lock(rule_lock);
2115 /* Exit if no suitable entries were found for adding bulk switch rule */
2117 status = ICE_SUCCESS;
2118 goto ice_add_mac_exit;
2121 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
2123 /* Allocate switch rule buffer for the bulk update for unicast */
2124 s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
2125 s_rule = (struct ice_aqc_sw_rules_elem *)
2126 ice_calloc(hw, num_unicast, s_rule_size);
2128 status = ICE_ERR_NO_MEMORY;
2129 goto ice_add_mac_exit;
2133 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2135 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2136 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2138 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2139 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
2140 ice_aqc_opc_add_sw_rules);
2141 r_iter = (struct ice_aqc_sw_rules_elem *)
2142 ((u8 *)r_iter + s_rule_size);
2146 /* Call AQ bulk switch rule update for all unicast addresses */
2148 /* Call AQ switch rule in AQ_MAX chunk */
2149 for (total_elem_left = num_unicast; total_elem_left > 0;
2150 total_elem_left -= elem_sent) {
2151 struct ice_aqc_sw_rules_elem *entry = r_iter;
2153 elem_sent = min(total_elem_left,
2154 (u16)(ICE_AQ_MAX_BUF_LEN / s_rule_size));
2155 status = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,
2156 elem_sent, ice_aqc_opc_add_sw_rules,
2159 goto ice_add_mac_exit;
2160 r_iter = (struct ice_aqc_sw_rules_elem *)
2161 ((u8 *)r_iter + (elem_sent * s_rule_size));
2164 /* Fill up rule ID based on the value returned from FW */
2166 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2168 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2169 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2170 struct ice_fltr_mgmt_list_entry *fm_entry;
2172 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2173 f_info->fltr_rule_id =
2174 LE16_TO_CPU(r_iter->pdata.lkup_tx_rx.index);
2175 f_info->fltr_act = ICE_FWD_TO_VSI;
2176 /* Create an entry to track this MAC address */
2177 fm_entry = (struct ice_fltr_mgmt_list_entry *)
2178 ice_malloc(hw, sizeof(*fm_entry));
2180 status = ICE_ERR_NO_MEMORY;
2181 goto ice_add_mac_exit;
2183 fm_entry->fltr_info = *f_info;
2184 fm_entry->vsi_count = 1;
2185 /* The book keeping entries will get removed when
2186 * base driver calls remove filter AQ command
2189 LIST_ADD(&fm_entry->list_entry, rule_head);
2190 r_iter = (struct ice_aqc_sw_rules_elem *)
2191 ((u8 *)r_iter + s_rule_size);
2196 ice_release_lock(rule_lock);
2198 ice_free(hw, s_rule);
2203 * ice_add_vlan_internal - Add one VLAN based filter rule
2204 * @hw: pointer to the hardware structure
2205 * @f_entry: filter entry containing one VLAN information
2207 static enum ice_status
2208 ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)
2210 struct ice_switch_info *sw = hw->switch_info;
2211 struct ice_fltr_mgmt_list_entry *v_list_itr;
2212 struct ice_fltr_info *new_fltr, *cur_fltr;
2213 enum ice_sw_lkup_type lkup_type;
2214 u16 vsi_list_id = 0, vsi_handle;
2215 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2216 enum ice_status status = ICE_SUCCESS;
2218 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
2219 return ICE_ERR_PARAM;
2221 f_entry->fltr_info.fwd_id.hw_vsi_id =
2222 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
2223 new_fltr = &f_entry->fltr_info;
2225 /* VLAN ID should only be 12 bits */
2226 if (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)
2227 return ICE_ERR_PARAM;
2229 if (new_fltr->src_id != ICE_SRC_ID_VSI)
2230 return ICE_ERR_PARAM;
2232 new_fltr->src = new_fltr->fwd_id.hw_vsi_id;
2233 lkup_type = new_fltr->lkup_type;
2234 vsi_handle = new_fltr->vsi_handle;
2235 rule_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
2236 ice_acquire_lock(rule_lock);
2237 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN, new_fltr);
2239 struct ice_vsi_list_map_info *map_info = NULL;
2241 if (new_fltr->fltr_act == ICE_FWD_TO_VSI) {
2242 /* All VLAN pruning rules use a VSI list. Check if
2243 * there is already a VSI list containing VSI that we
2244 * want to add. If found, use the same vsi_list_id for
2245 * this new VLAN rule or else create a new list.
2247 map_info = ice_find_vsi_list_entry(hw, ICE_SW_LKUP_VLAN,
2251 status = ice_create_vsi_list_rule(hw,
2259 /* Convert the action to forwarding to a VSI list. */
2260 new_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
2261 new_fltr->fwd_id.vsi_list_id = vsi_list_id;
2264 status = ice_create_pkt_fwd_rule(hw, f_entry);
2266 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN,
2269 status = ICE_ERR_DOES_NOT_EXIST;
2272 /* reuse VSI list for new rule and increment ref_cnt */
2274 v_list_itr->vsi_list_info = map_info;
2275 map_info->ref_cnt++;
2277 v_list_itr->vsi_list_info =
2278 ice_create_vsi_list_map(hw, &vsi_handle,
2282 } else if (v_list_itr->vsi_list_info->ref_cnt == 1) {
2283 /* Update existing VSI list to add new VSI ID only if it used
2286 cur_fltr = &v_list_itr->fltr_info;
2287 status = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr,
2290 /* If VLAN rule exists and VSI list being used by this rule is
2291 * referenced by more than 1 VLAN rule. Then create a new VSI
2292 * list appending previous VSI with new VSI and update existing
2293 * VLAN rule to point to new VSI list ID
2295 struct ice_fltr_info tmp_fltr;
2296 u16 vsi_handle_arr[2];
2299 /* Current implementation only supports reusing VSI list with
2300 * one VSI count. We should never hit below condition
2302 if (v_list_itr->vsi_count > 1 &&
2303 v_list_itr->vsi_list_info->ref_cnt > 1) {
2304 ice_debug(hw, ICE_DBG_SW,
2305 "Invalid configuration: Optimization to reuse VSI list with more than one VSI is not being done yet\n");
2306 status = ICE_ERR_CFG;
2311 ice_find_first_bit(v_list_itr->vsi_list_info->vsi_map,
2314 /* A rule already exists with the new VSI being added */
2315 if (cur_handle == vsi_handle) {
2316 status = ICE_ERR_ALREADY_EXISTS;
2320 vsi_handle_arr[0] = cur_handle;
2321 vsi_handle_arr[1] = vsi_handle;
2322 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
2323 &vsi_list_id, lkup_type);
2327 tmp_fltr = v_list_itr->fltr_info;
2328 tmp_fltr.fltr_rule_id = v_list_itr->fltr_info.fltr_rule_id;
2329 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
2330 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
2331 /* Update the previous switch rule to a new VSI list which
2332 * includes current VSI that is requested
2334 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
2338 /* before overriding VSI list map info. decrement ref_cnt of
2341 v_list_itr->vsi_list_info->ref_cnt--;
2343 /* now update to newly created list */
2344 v_list_itr->fltr_info.fwd_id.vsi_list_id = vsi_list_id;
2345 v_list_itr->vsi_list_info =
2346 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
2348 v_list_itr->vsi_count++;
2352 ice_release_lock(rule_lock);
2357 * ice_add_vlan - Add VLAN based filter rule
2358 * @hw: pointer to the hardware structure
2359 * @v_list: list of VLAN entries and forwarding information
2362 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2364 struct ice_fltr_list_entry *v_list_itr;
2367 return ICE_ERR_PARAM;
2369 LIST_FOR_EACH_ENTRY(v_list_itr, v_list, ice_fltr_list_entry,
2371 if (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)
2372 return ICE_ERR_PARAM;
2373 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
2374 v_list_itr->status = ice_add_vlan_internal(hw, v_list_itr);
2375 if (v_list_itr->status)
2376 return v_list_itr->status;
2381 #ifndef NO_MACVLAN_SUPPORT
2383 * ice_add_mac_vlan - Add MAC and VLAN pair based filter rule
2384 * @hw: pointer to the hardware structure
2385 * @mv_list: list of MAC and VLAN filters
2387 * If the VSI on which the MAC-VLAN pair has to be added has Rx and Tx VLAN
2388 * pruning bits enabled, then it is the responsibility of the caller to make
2389 * sure to add a VLAN only filter on the same VSI. Packets belonging to that
2390 * VLAN won't be received on that VSI otherwise.
2393 ice_add_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *mv_list)
2395 struct ice_fltr_list_entry *mv_list_itr;
2397 if (!mv_list || !hw)
2398 return ICE_ERR_PARAM;
2400 LIST_FOR_EACH_ENTRY(mv_list_itr, mv_list, ice_fltr_list_entry,
2402 enum ice_sw_lkup_type l_type =
2403 mv_list_itr->fltr_info.lkup_type;
2405 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2406 return ICE_ERR_PARAM;
2407 mv_list_itr->fltr_info.flag = ICE_FLTR_TX;
2408 mv_list_itr->status =
2409 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2411 if (mv_list_itr->status)
2412 return mv_list_itr->status;
2421 * ice_rem_sw_rule_info
2422 * @hw: pointer to the hardware structure
2423 * @rule_head: pointer to the switch list structure that we want to delete
2426 ice_rem_sw_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
2428 if (!LIST_EMPTY(rule_head)) {
2429 struct ice_fltr_mgmt_list_entry *entry;
2430 struct ice_fltr_mgmt_list_entry *tmp;
2432 LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, rule_head,
2433 ice_fltr_mgmt_list_entry, list_entry) {
2434 LIST_DEL(&entry->list_entry);
2435 ice_free(hw, entry);
2443 * ice_cfg_dflt_vsi - change state of VSI to set/clear default
2444 * @pi: pointer to the port_info structure
2445 * @vsi_handle: VSI handle to set as default
2446 * @set: true to add the above mentioned switch rule, false to remove it
2447 * @direction: ICE_FLTR_RX or ICE_FLTR_TX
2449 * add filter rule to set/unset given VSI as default VSI for the switch
2450 * (represented by swid)
2453 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
2456 struct ice_aqc_sw_rules_elem *s_rule;
2457 struct ice_fltr_info f_info;
2458 struct ice_hw *hw = pi->hw;
2459 enum ice_adminq_opc opcode;
2460 enum ice_status status;
2464 if (!ice_is_vsi_valid(hw, vsi_handle))
2465 return ICE_ERR_PARAM;
2466 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2468 s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
2469 ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
2470 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
2472 return ICE_ERR_NO_MEMORY;
2474 ice_memset(&f_info, 0, sizeof(f_info), ICE_NONDMA_MEM);
2476 f_info.lkup_type = ICE_SW_LKUP_DFLT;
2477 f_info.flag = direction;
2478 f_info.fltr_act = ICE_FWD_TO_VSI;
2479 f_info.fwd_id.hw_vsi_id = hw_vsi_id;
2481 if (f_info.flag & ICE_FLTR_RX) {
2482 f_info.src = pi->lport;
2483 f_info.src_id = ICE_SRC_ID_LPORT;
2485 f_info.fltr_rule_id =
2486 pi->dflt_rx_vsi_rule_id;
2487 } else if (f_info.flag & ICE_FLTR_TX) {
2488 f_info.src_id = ICE_SRC_ID_VSI;
2489 f_info.src = hw_vsi_id;
2491 f_info.fltr_rule_id =
2492 pi->dflt_tx_vsi_rule_id;
2496 opcode = ice_aqc_opc_add_sw_rules;
2498 opcode = ice_aqc_opc_remove_sw_rules;
2500 ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
2502 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
2503 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
2506 u16 index = LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
2508 if (f_info.flag & ICE_FLTR_TX) {
2509 pi->dflt_tx_vsi_num = hw_vsi_id;
2510 pi->dflt_tx_vsi_rule_id = index;
2511 } else if (f_info.flag & ICE_FLTR_RX) {
2512 pi->dflt_rx_vsi_num = hw_vsi_id;
2513 pi->dflt_rx_vsi_rule_id = index;
2516 if (f_info.flag & ICE_FLTR_TX) {
2517 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
2518 pi->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
2519 } else if (f_info.flag & ICE_FLTR_RX) {
2520 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
2521 pi->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
2526 ice_free(hw, s_rule);
2531 * ice_remove_mac - remove a MAC address based filter rule
2532 * @hw: pointer to the hardware structure
2533 * @m_list: list of MAC addresses and forwarding information
2535 * This function removes either a MAC filter rule or a specific VSI from a
2536 * VSI list for a multicast MAC address.
2538 * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by
2539 * ice_add_mac. Caller should be aware that this call will only work if all
2540 * the entries passed into m_list were added previously. It will not attempt to
2541 * do a partial remove of entries that were found.
2544 ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2546 struct ice_fltr_list_entry *list_itr, *tmp;
2549 return ICE_ERR_PARAM;
2551 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, m_list, ice_fltr_list_entry,
2553 enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
2555 if (l_type != ICE_SW_LKUP_MAC)
2556 return ICE_ERR_PARAM;
2557 list_itr->status = ice_remove_rule_internal(hw,
2560 if (list_itr->status)
2561 return list_itr->status;
2567 * ice_remove_vlan - Remove VLAN based filter rule
2568 * @hw: pointer to the hardware structure
2569 * @v_list: list of VLAN entries and forwarding information
2572 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2574 struct ice_fltr_list_entry *v_list_itr, *tmp;
2577 return ICE_ERR_PARAM;
2579 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2581 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2583 if (l_type != ICE_SW_LKUP_VLAN)
2584 return ICE_ERR_PARAM;
2585 v_list_itr->status = ice_remove_rule_internal(hw,
2588 if (v_list_itr->status)
2589 return v_list_itr->status;
2594 #ifndef NO_MACVLAN_SUPPORT
2596 * ice_remove_mac_vlan - Remove MAC VLAN based filter rule
2597 * @hw: pointer to the hardware structure
2598 * @v_list: list of MAC VLAN entries and forwarding information
2601 ice_remove_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2603 struct ice_fltr_list_entry *v_list_itr, *tmp;
2606 return ICE_ERR_PARAM;
2608 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2610 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2612 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2613 return ICE_ERR_PARAM;
2614 v_list_itr->status =
2615 ice_remove_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2617 if (v_list_itr->status)
2618 return v_list_itr->status;
2622 #endif /* !NO_MACVLAN_SUPPORT */
2625 * ice_vsi_uses_fltr - Determine if given VSI uses specified filter
2626 * @fm_entry: filter entry to inspect
2627 * @vsi_handle: VSI handle to compare with filter info
2630 ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle)
2632 return ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&
2633 fm_entry->fltr_info.vsi_handle == vsi_handle) ||
2634 (fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&
2635 (ice_is_bit_set(fm_entry->vsi_list_info->vsi_map,
2640 * ice_add_entry_to_vsi_fltr_list - Add copy of fltr_list_entry to remove list
2641 * @hw: pointer to the hardware structure
2642 * @vsi_handle: VSI handle to remove filters from
2643 * @vsi_list_head: pointer to the list to add entry to
2644 * @fi: pointer to fltr_info of filter entry to copy & add
2646 * Helper function, used when creating a list of filters to remove from
2647 * a specific VSI. The entry added to vsi_list_head is a COPY of the
2648 * original filter entry, with the exception of fltr_info.fltr_act and
2649 * fltr_info.fwd_id fields. These are set such that later logic can
2650 * extract which VSI to remove the fltr from, and pass on that information.
2652 static enum ice_status
2653 ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2654 struct LIST_HEAD_TYPE *vsi_list_head,
2655 struct ice_fltr_info *fi)
2657 struct ice_fltr_list_entry *tmp;
2659 /* this memory is freed up in the caller function
2660 * once filters for this VSI are removed
2662 tmp = (struct ice_fltr_list_entry *)ice_malloc(hw, sizeof(*tmp));
2664 return ICE_ERR_NO_MEMORY;
2666 tmp->fltr_info = *fi;
2668 /* Overwrite these fields to indicate which VSI to remove filter from,
2669 * so find and remove logic can extract the information from the
2670 * list entries. Note that original entries will still have proper
2673 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2674 tmp->fltr_info.vsi_handle = vsi_handle;
2675 tmp->fltr_info.fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2677 LIST_ADD(&tmp->list_entry, vsi_list_head);
2683 * ice_add_to_vsi_fltr_list - Add VSI filters to the list
2684 * @hw: pointer to the hardware structure
2685 * @vsi_handle: VSI handle to remove filters from
2686 * @lkup_list_head: pointer to the list that has certain lookup type filters
2687 * @vsi_list_head: pointer to the list pertaining to VSI with vsi_handle
2689 * Locates all filters in lkup_list_head that are used by the given VSI,
2690 * and adds COPIES of those entries to vsi_list_head (intended to be used
2691 * to remove the listed filters).
2692 * Note that this means all entries in vsi_list_head must be explicitly
2693 * deallocated by the caller when done with list.
2695 static enum ice_status
2696 ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2697 struct LIST_HEAD_TYPE *lkup_list_head,
2698 struct LIST_HEAD_TYPE *vsi_list_head)
2700 struct ice_fltr_mgmt_list_entry *fm_entry;
2701 enum ice_status status = ICE_SUCCESS;
2703 /* check to make sure VSI ID is valid and within boundary */
2704 if (!ice_is_vsi_valid(hw, vsi_handle))
2705 return ICE_ERR_PARAM;
2707 LIST_FOR_EACH_ENTRY(fm_entry, lkup_list_head,
2708 ice_fltr_mgmt_list_entry, list_entry) {
2709 struct ice_fltr_info *fi;
2711 fi = &fm_entry->fltr_info;
2712 if (!fi || !ice_vsi_uses_fltr(fm_entry, vsi_handle))
2715 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2725 * ice_determine_promisc_mask
2726 * @fi: filter info to parse
2728 * Helper function to determine which ICE_PROMISC_ mask corresponds
2729 * to given filter into.
2731 static u8 ice_determine_promisc_mask(struct ice_fltr_info *fi)
2733 u16 vid = fi->l_data.mac_vlan.vlan_id;
2734 u8 *macaddr = fi->l_data.mac.mac_addr;
2735 bool is_tx_fltr = false;
2736 u8 promisc_mask = 0;
2738 if (fi->flag == ICE_FLTR_TX)
2741 if (IS_BROADCAST_ETHER_ADDR(macaddr))
2742 promisc_mask |= is_tx_fltr ?
2743 ICE_PROMISC_BCAST_TX : ICE_PROMISC_BCAST_RX;
2744 else if (IS_MULTICAST_ETHER_ADDR(macaddr))
2745 promisc_mask |= is_tx_fltr ?
2746 ICE_PROMISC_MCAST_TX : ICE_PROMISC_MCAST_RX;
2747 else if (IS_UNICAST_ETHER_ADDR(macaddr))
2748 promisc_mask |= is_tx_fltr ?
2749 ICE_PROMISC_UCAST_TX : ICE_PROMISC_UCAST_RX;
2751 promisc_mask |= is_tx_fltr ?
2752 ICE_PROMISC_VLAN_TX : ICE_PROMISC_VLAN_RX;
2754 return promisc_mask;
2759 * ice_remove_promisc - Remove promisc based filter rules
2760 * @hw: pointer to the hardware structure
2761 * @recp_id: recipe ID for which the rule needs to removed
2762 * @v_list: list of promisc entries
2764 static enum ice_status
2765 ice_remove_promisc(struct ice_hw *hw, u8 recp_id,
2766 struct LIST_HEAD_TYPE *v_list)
2768 struct ice_fltr_list_entry *v_list_itr, *tmp;
2770 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2772 v_list_itr->status =
2773 ice_remove_rule_internal(hw, recp_id, v_list_itr);
2774 if (v_list_itr->status)
2775 return v_list_itr->status;
2781 * ice_clear_vsi_promisc - clear specified promiscuous mode(s) for given VSI
2782 * @hw: pointer to the hardware structure
2783 * @vsi_handle: VSI handle to clear mode
2784 * @promisc_mask: mask of promiscuous config bits to clear
2785 * @vid: VLAN ID to clear VLAN promiscuous
2788 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2791 struct ice_switch_info *sw = hw->switch_info;
2792 struct ice_fltr_list_entry *fm_entry, *tmp;
2793 struct LIST_HEAD_TYPE remove_list_head;
2794 struct ice_fltr_mgmt_list_entry *itr;
2795 struct LIST_HEAD_TYPE *rule_head;
2796 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2797 enum ice_status status = ICE_SUCCESS;
2800 if (!ice_is_vsi_valid(hw, vsi_handle))
2801 return ICE_ERR_PARAM;
2804 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2806 recipe_id = ICE_SW_LKUP_PROMISC;
2808 rule_head = &sw->recp_list[recipe_id].filt_rules;
2809 rule_lock = &sw->recp_list[recipe_id].filt_rule_lock;
2811 INIT_LIST_HEAD(&remove_list_head);
2813 ice_acquire_lock(rule_lock);
2814 LIST_FOR_EACH_ENTRY(itr, rule_head,
2815 ice_fltr_mgmt_list_entry, list_entry) {
2816 u8 fltr_promisc_mask = 0;
2818 if (!ice_vsi_uses_fltr(itr, vsi_handle))
2821 fltr_promisc_mask |=
2822 ice_determine_promisc_mask(&itr->fltr_info);
2824 /* Skip if filter is not completely specified by given mask */
2825 if (fltr_promisc_mask & ~promisc_mask)
2828 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2832 ice_release_lock(rule_lock);
2833 goto free_fltr_list;
2836 ice_release_lock(rule_lock);
2838 status = ice_remove_promisc(hw, recipe_id, &remove_list_head);
2841 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
2842 ice_fltr_list_entry, list_entry) {
2843 LIST_DEL(&fm_entry->list_entry);
2844 ice_free(hw, fm_entry);
2851 * ice_set_vsi_promisc - set given VSI to given promiscuous mode(s)
2852 * @hw: pointer to the hardware structure
2853 * @vsi_handle: VSI handle to configure
2854 * @promisc_mask: mask of promiscuous config bits
2855 * @vid: VLAN ID to set VLAN promiscuous
2858 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, u16 vid)
2860 enum { UCAST_FLTR = 1, MCAST_FLTR, BCAST_FLTR };
2861 struct ice_fltr_list_entry f_list_entry;
2862 struct ice_fltr_info new_fltr;
2863 enum ice_status status = ICE_SUCCESS;
2869 ice_debug(hw, ICE_DBG_TRACE, "ice_set_vsi_promisc\n");
2871 if (!ice_is_vsi_valid(hw, vsi_handle))
2872 return ICE_ERR_PARAM;
2873 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2875 ice_memset(&new_fltr, 0, sizeof(new_fltr), ICE_NONDMA_MEM);
2877 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX)) {
2878 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC_VLAN;
2879 new_fltr.l_data.mac_vlan.vlan_id = vid;
2880 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2882 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC;
2883 recipe_id = ICE_SW_LKUP_PROMISC;
2886 /* Separate filters must be set for each direction/packet type
2887 * combination, so we will loop over the mask value, store the
2888 * individual type, and clear it out in the input mask as it
2891 while (promisc_mask) {
2897 if (promisc_mask & ICE_PROMISC_UCAST_RX) {
2898 promisc_mask &= ~ICE_PROMISC_UCAST_RX;
2899 pkt_type = UCAST_FLTR;
2900 } else if (promisc_mask & ICE_PROMISC_UCAST_TX) {
2901 promisc_mask &= ~ICE_PROMISC_UCAST_TX;
2902 pkt_type = UCAST_FLTR;
2904 } else if (promisc_mask & ICE_PROMISC_MCAST_RX) {
2905 promisc_mask &= ~ICE_PROMISC_MCAST_RX;
2906 pkt_type = MCAST_FLTR;
2907 } else if (promisc_mask & ICE_PROMISC_MCAST_TX) {
2908 promisc_mask &= ~ICE_PROMISC_MCAST_TX;
2909 pkt_type = MCAST_FLTR;
2911 } else if (promisc_mask & ICE_PROMISC_BCAST_RX) {
2912 promisc_mask &= ~ICE_PROMISC_BCAST_RX;
2913 pkt_type = BCAST_FLTR;
2914 } else if (promisc_mask & ICE_PROMISC_BCAST_TX) {
2915 promisc_mask &= ~ICE_PROMISC_BCAST_TX;
2916 pkt_type = BCAST_FLTR;
2920 /* Check for VLAN promiscuous flag */
2921 if (promisc_mask & ICE_PROMISC_VLAN_RX) {
2922 promisc_mask &= ~ICE_PROMISC_VLAN_RX;
2923 } else if (promisc_mask & ICE_PROMISC_VLAN_TX) {
2924 promisc_mask &= ~ICE_PROMISC_VLAN_TX;
2928 /* Set filter DA based on packet type */
2929 mac_addr = new_fltr.l_data.mac.mac_addr;
2930 if (pkt_type == BCAST_FLTR) {
2931 ice_memset(mac_addr, 0xff, ETH_ALEN, ICE_NONDMA_MEM);
2932 } else if (pkt_type == MCAST_FLTR ||
2933 pkt_type == UCAST_FLTR) {
2934 /* Use the dummy ether header DA */
2935 ice_memcpy(mac_addr, dummy_eth_header, ETH_ALEN,
2936 ICE_NONDMA_TO_NONDMA);
2937 if (pkt_type == MCAST_FLTR)
2938 mac_addr[0] |= 0x1; /* Set multicast bit */
2941 /* Need to reset this to zero for all iterations */
2944 new_fltr.flag |= ICE_FLTR_TX;
2945 new_fltr.src = hw_vsi_id;
2947 new_fltr.flag |= ICE_FLTR_RX;
2948 new_fltr.src = hw->port_info->lport;
2951 new_fltr.fltr_act = ICE_FWD_TO_VSI;
2952 new_fltr.vsi_handle = vsi_handle;
2953 new_fltr.fwd_id.hw_vsi_id = hw_vsi_id;
2954 f_list_entry.fltr_info = new_fltr;
2956 status = ice_add_rule_internal(hw, recipe_id, &f_list_entry);
2957 if (status != ICE_SUCCESS)
2958 goto set_promisc_exit;
2966 * ice_set_vlan_vsi_promisc
2967 * @hw: pointer to the hardware structure
2968 * @vsi_handle: VSI handle to configure
2969 * @promisc_mask: mask of promiscuous config bits
2970 * @rm_vlan_promisc: Clear VLANs VSI promisc mode
2972 * Configure VSI with all associated VLANs to given promiscuous mode(s)
2975 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2976 bool rm_vlan_promisc)
2978 struct ice_switch_info *sw = hw->switch_info;
2979 struct ice_fltr_list_entry *list_itr, *tmp;
2980 struct LIST_HEAD_TYPE vsi_list_head;
2981 struct LIST_HEAD_TYPE *vlan_head;
2982 struct ice_lock *vlan_lock; /* Lock to protect filter rule list */
2983 enum ice_status status;
2986 INIT_LIST_HEAD(&vsi_list_head);
2987 vlan_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
2988 vlan_head = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rules;
2989 ice_acquire_lock(vlan_lock);
2990 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, vlan_head,
2992 ice_release_lock(vlan_lock);
2994 goto free_fltr_list;
2996 LIST_FOR_EACH_ENTRY(list_itr, &vsi_list_head, ice_fltr_list_entry,
2998 vlan_id = list_itr->fltr_info.l_data.vlan.vlan_id;
2999 if (rm_vlan_promisc)
3000 status = ice_clear_vsi_promisc(hw, vsi_handle,
3001 promisc_mask, vlan_id);
3003 status = ice_set_vsi_promisc(hw, vsi_handle,
3004 promisc_mask, vlan_id);
3010 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, &vsi_list_head,
3011 ice_fltr_list_entry, list_entry) {
3012 LIST_DEL(&list_itr->list_entry);
3013 ice_free(hw, list_itr);
3019 * ice_remove_vsi_lkup_fltr - Remove lookup type filters for a VSI
3020 * @hw: pointer to the hardware structure
3021 * @vsi_handle: VSI handle to remove filters from
3022 * @lkup: switch rule filter lookup type
3025 ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
3026 enum ice_sw_lkup_type lkup)
3028 struct ice_switch_info *sw = hw->switch_info;
3029 struct ice_fltr_list_entry *fm_entry;
3030 struct LIST_HEAD_TYPE remove_list_head;
3031 struct LIST_HEAD_TYPE *rule_head;
3032 struct ice_fltr_list_entry *tmp;
3033 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3034 enum ice_status status;
3036 INIT_LIST_HEAD(&remove_list_head);
3037 rule_lock = &sw->recp_list[lkup].filt_rule_lock;
3038 rule_head = &sw->recp_list[lkup].filt_rules;
3039 ice_acquire_lock(rule_lock);
3040 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, rule_head,
3042 ice_release_lock(rule_lock);
3047 case ICE_SW_LKUP_MAC:
3048 ice_remove_mac(hw, &remove_list_head);
3050 case ICE_SW_LKUP_VLAN:
3051 ice_remove_vlan(hw, &remove_list_head);
3053 case ICE_SW_LKUP_PROMISC:
3054 case ICE_SW_LKUP_PROMISC_VLAN:
3055 ice_remove_promisc(hw, lkup, &remove_list_head);
3057 case ICE_SW_LKUP_MAC_VLAN:
3058 #ifndef NO_MACVLAN_SUPPORT
3059 ice_remove_mac_vlan(hw, &remove_list_head);
3061 ice_debug(hw, ICE_DBG_SW, "MAC VLAN look up is not supported yet\n");
3062 #endif /* !NO_MACVLAN_SUPPORT */
3064 case ICE_SW_LKUP_ETHERTYPE:
3065 case ICE_SW_LKUP_ETHERTYPE_MAC:
3066 case ICE_SW_LKUP_DFLT:
3067 ice_debug(hw, ICE_DBG_SW,
3068 "Remove filters for this lookup type hasn't been implemented yet\n");
3070 case ICE_SW_LKUP_LAST:
3071 ice_debug(hw, ICE_DBG_SW, "Unsupported lookup type\n");
3075 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
3076 ice_fltr_list_entry, list_entry) {
3077 LIST_DEL(&fm_entry->list_entry);
3078 ice_free(hw, fm_entry);
3083 * ice_remove_vsi_fltr - Remove all filters for a VSI
3084 * @hw: pointer to the hardware structure
3085 * @vsi_handle: VSI handle to remove filters from
3087 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle)
3089 ice_debug(hw, ICE_DBG_TRACE, "ice_remove_vsi_fltr\n");
3091 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC);
3092 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC_VLAN);
3093 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC);
3094 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_VLAN);
3095 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_DFLT);
3096 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE);
3097 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE_MAC);
3098 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC_VLAN);
3106 * ice_replay_vsi_fltr - Replay filters for requested VSI
3107 * @hw: pointer to the hardware structure
3108 * @vsi_handle: driver VSI handle
3109 * @recp_id: Recipe ID for which rules need to be replayed
3110 * @list_head: list for which filters need to be replayed
3112 * Replays the filter of recipe recp_id for a VSI represented via vsi_handle.
3113 * It is required to pass valid VSI handle.
3115 static enum ice_status
3116 ice_replay_vsi_fltr(struct ice_hw *hw, u16 vsi_handle, u8 recp_id,
3117 struct LIST_HEAD_TYPE *list_head)
3119 struct ice_fltr_mgmt_list_entry *itr;
3120 enum ice_status status = ICE_SUCCESS;
3123 if (LIST_EMPTY(list_head))
3125 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3127 LIST_FOR_EACH_ENTRY(itr, list_head, ice_fltr_mgmt_list_entry,
3129 struct ice_fltr_list_entry f_entry;
3131 f_entry.fltr_info = itr->fltr_info;
3132 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN &&
3133 itr->fltr_info.vsi_handle == vsi_handle) {
3134 /* update the src in case it is VSI num */
3135 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
3136 f_entry.fltr_info.src = hw_vsi_id;
3137 status = ice_add_rule_internal(hw, recp_id, &f_entry);
3138 if (status != ICE_SUCCESS)
3142 if (!itr->vsi_list_info ||
3143 !ice_is_bit_set(itr->vsi_list_info->vsi_map, vsi_handle))
3145 /* Clearing it so that the logic can add it back */
3146 ice_clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
3147 f_entry.fltr_info.vsi_handle = vsi_handle;
3148 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
3149 /* update the src in case it is VSI num */
3150 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
3151 f_entry.fltr_info.src = hw_vsi_id;
3152 if (recp_id == ICE_SW_LKUP_VLAN)
3153 status = ice_add_vlan_internal(hw, &f_entry);
3155 status = ice_add_rule_internal(hw, recp_id, &f_entry);
3156 if (status != ICE_SUCCESS)
3165 * ice_replay_vsi_all_fltr - replay all filters stored in bookkeeping lists
3166 * @hw: pointer to the hardware structure
3167 * @vsi_handle: driver VSI handle
3169 * Replays filters for requested VSI via vsi_handle.
3171 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
3173 struct ice_switch_info *sw = hw->switch_info;
3174 enum ice_status status = ICE_SUCCESS;
3177 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
3178 /* Update the default recipe lines and ones that were created */
3179 if (i < ICE_MAX_NUM_RECIPES || sw->recp_list[i].recp_created) {
3180 struct LIST_HEAD_TYPE *head;
3182 head = &sw->recp_list[i].filt_replay_rules;
3183 if (!sw->recp_list[i].adv_rule)
3184 status = ice_replay_vsi_fltr(hw, vsi_handle, i,
3186 if (status != ICE_SUCCESS)
3194 * ice_rm_all_sw_replay_rule_info - deletes filter replay rules
3195 * @hw: pointer to the HW struct
3197 * Deletes the filter replay rules.
3199 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
3201 struct ice_switch_info *sw = hw->switch_info;
3207 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
3208 if (!LIST_EMPTY(&sw->recp_list[i].filt_replay_rules)) {
3209 struct LIST_HEAD_TYPE *l_head;
3211 l_head = &sw->recp_list[i].filt_replay_rules;
3212 if (!sw->recp_list[i].adv_rule)
3213 ice_rem_sw_rule_info(hw, l_head);