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);
1342 * ice_add_counter_act - add/update filter rule with counter action
1343 * @hw: pointer to the hardware structure
1344 * @m_ent: the management entry for which counter needs to be added
1345 * @counter_id: VLAN counter ID returned as part of allocate resource
1346 * @l_id: large action resource ID
1348 static enum ice_status
1349 ice_add_counter_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
1350 u16 counter_id, u16 l_id)
1352 struct ice_aqc_sw_rules_elem *lg_act;
1353 struct ice_aqc_sw_rules_elem *rx_tx;
1354 enum ice_status status;
1355 /* 2 actions will be added while adding a large action counter */
1356 const int num_acts = 2;
1363 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
1364 return ICE_ERR_PARAM;
1366 /* Create two back-to-back switch rules and submit them to the HW using
1367 * one memory buffer:
1371 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_acts);
1372 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1373 lg_act = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw,
1376 return ICE_ERR_NO_MEMORY;
1378 rx_tx = (struct ice_aqc_sw_rules_elem *)
1379 ((u8 *)lg_act + lg_act_size);
1381 /* Fill in the first switch rule i.e. large action */
1382 lg_act->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_LG_ACT);
1383 lg_act->pdata.lg_act.index = CPU_TO_LE16(l_id);
1384 lg_act->pdata.lg_act.size = CPU_TO_LE16(num_acts);
1386 /* First action VSI forwarding or VSI list forwarding depending on how
1389 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
1390 m_ent->fltr_info.fwd_id.hw_vsi_id;
1392 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
1393 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) &
1394 ICE_LG_ACT_VSI_LIST_ID_M;
1395 if (m_ent->vsi_count > 1)
1396 act |= ICE_LG_ACT_VSI_LIST;
1397 lg_act->pdata.lg_act.act[0] = CPU_TO_LE32(act);
1399 /* Second action counter ID */
1400 act = ICE_LG_ACT_STAT_COUNT;
1401 act |= (counter_id << ICE_LG_ACT_STAT_COUNT_S) &
1402 ICE_LG_ACT_STAT_COUNT_M;
1403 lg_act->pdata.lg_act.act[1] = CPU_TO_LE32(act);
1405 /* call the fill switch rule to fill the lookup Tx Rx structure */
1406 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
1407 ice_aqc_opc_update_sw_rules);
1409 act = ICE_SINGLE_ACT_PTR;
1410 act |= (l_id << ICE_SINGLE_ACT_PTR_VAL_S) & ICE_SINGLE_ACT_PTR_VAL_M;
1411 rx_tx->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
1413 /* Use the filter rule ID of the previously created rule with single
1414 * act. Once the update happens, hardware will treat this as large
1417 f_rule_id = m_ent->fltr_info.fltr_rule_id;
1418 rx_tx->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_rule_id);
1420 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
1421 ice_aqc_opc_update_sw_rules, NULL);
1423 m_ent->lg_act_idx = l_id;
1424 m_ent->counter_index = counter_id;
1427 ice_free(hw, lg_act);
1432 * ice_create_vsi_list_map
1433 * @hw: pointer to the hardware structure
1434 * @vsi_handle_arr: array of VSI handles to set in the VSI mapping
1435 * @num_vsi: number of VSI handles in the array
1436 * @vsi_list_id: VSI list ID generated as part of allocate resource
1438 * Helper function to create a new entry of VSI list ID to VSI mapping
1439 * using the given VSI list ID
1441 static struct ice_vsi_list_map_info *
1442 ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1445 struct ice_switch_info *sw = hw->switch_info;
1446 struct ice_vsi_list_map_info *v_map;
1449 v_map = (struct ice_vsi_list_map_info *)ice_calloc(hw, 1,
1454 v_map->vsi_list_id = vsi_list_id;
1456 for (i = 0; i < num_vsi; i++)
1457 ice_set_bit(vsi_handle_arr[i], v_map->vsi_map);
1459 LIST_ADD(&v_map->list_entry, &sw->vsi_list_map_head);
1464 * ice_update_vsi_list_rule
1465 * @hw: pointer to the hardware structure
1466 * @vsi_handle_arr: array of VSI handles to form a VSI list
1467 * @num_vsi: number of VSI handles in the array
1468 * @vsi_list_id: VSI list ID generated as part of allocate resource
1469 * @remove: Boolean value to indicate if this is a remove action
1470 * @opc: switch rules population command type - pass in the command opcode
1471 * @lkup_type: lookup type of the filter
1473 * Call AQ command to add a new switch rule or update existing switch rule
1474 * using the given VSI list ID
1476 static enum ice_status
1477 ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1478 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
1479 enum ice_sw_lkup_type lkup_type)
1481 struct ice_aqc_sw_rules_elem *s_rule;
1482 enum ice_status status;
1488 return ICE_ERR_PARAM;
1490 if (lkup_type == ICE_SW_LKUP_MAC ||
1491 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
1492 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1493 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1494 lkup_type == ICE_SW_LKUP_PROMISC ||
1495 lkup_type == ICE_SW_LKUP_PROMISC_VLAN)
1496 type = remove ? ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR :
1497 ICE_AQC_SW_RULES_T_VSI_LIST_SET;
1498 else if (lkup_type == ICE_SW_LKUP_VLAN)
1499 type = remove ? ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR :
1500 ICE_AQC_SW_RULES_T_PRUNE_LIST_SET;
1502 return ICE_ERR_PARAM;
1504 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
1505 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1507 return ICE_ERR_NO_MEMORY;
1508 for (i = 0; i < num_vsi; i++) {
1509 if (!ice_is_vsi_valid(hw, vsi_handle_arr[i])) {
1510 status = ICE_ERR_PARAM;
1513 /* AQ call requires hw_vsi_id(s) */
1514 s_rule->pdata.vsi_list.vsi[i] =
1515 CPU_TO_LE16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
1518 s_rule->type = CPU_TO_LE16(type);
1519 s_rule->pdata.vsi_list.number_vsi = CPU_TO_LE16(num_vsi);
1520 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1522 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
1525 ice_free(hw, s_rule);
1530 * ice_create_vsi_list_rule - Creates and populates a VSI list rule
1531 * @hw: pointer to the HW struct
1532 * @vsi_handle_arr: array of VSI handles to form a VSI list
1533 * @num_vsi: number of VSI handles in the array
1534 * @vsi_list_id: stores the ID of the VSI list to be created
1535 * @lkup_type: switch rule filter's lookup type
1537 static enum ice_status
1538 ice_create_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1539 u16 *vsi_list_id, enum ice_sw_lkup_type lkup_type)
1541 enum ice_status status;
1543 status = ice_aq_alloc_free_vsi_list(hw, vsi_list_id, lkup_type,
1544 ice_aqc_opc_alloc_res);
1548 /* Update the newly created VSI list to include the specified VSIs */
1549 return ice_update_vsi_list_rule(hw, vsi_handle_arr, num_vsi,
1550 *vsi_list_id, false,
1551 ice_aqc_opc_add_sw_rules, lkup_type);
1555 * ice_create_pkt_fwd_rule
1556 * @hw: pointer to the hardware structure
1557 * @f_entry: entry containing packet forwarding information
1559 * Create switch rule with given filter information and add an entry
1560 * to the corresponding filter management list to track this switch rule
1563 static enum ice_status
1564 ice_create_pkt_fwd_rule(struct ice_hw *hw,
1565 struct ice_fltr_list_entry *f_entry)
1567 struct ice_fltr_mgmt_list_entry *fm_entry;
1568 struct ice_aqc_sw_rules_elem *s_rule;
1569 enum ice_sw_lkup_type l_type;
1570 struct ice_sw_recipe *recp;
1571 enum ice_status status;
1573 s_rule = (struct ice_aqc_sw_rules_elem *)
1574 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1576 return ICE_ERR_NO_MEMORY;
1577 fm_entry = (struct ice_fltr_mgmt_list_entry *)
1578 ice_malloc(hw, sizeof(*fm_entry));
1580 status = ICE_ERR_NO_MEMORY;
1581 goto ice_create_pkt_fwd_rule_exit;
1584 fm_entry->fltr_info = f_entry->fltr_info;
1586 /* Initialize all the fields for the management entry */
1587 fm_entry->vsi_count = 1;
1588 fm_entry->lg_act_idx = ICE_INVAL_LG_ACT_INDEX;
1589 fm_entry->sw_marker_id = ICE_INVAL_SW_MARKER_ID;
1590 fm_entry->counter_index = ICE_INVAL_COUNTER_ID;
1592 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
1593 ice_aqc_opc_add_sw_rules);
1595 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1596 ice_aqc_opc_add_sw_rules, NULL);
1598 ice_free(hw, fm_entry);
1599 goto ice_create_pkt_fwd_rule_exit;
1602 f_entry->fltr_info.fltr_rule_id =
1603 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1604 fm_entry->fltr_info.fltr_rule_id =
1605 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1607 /* The book keeping entries will get removed when base driver
1608 * calls remove filter AQ command
1610 l_type = fm_entry->fltr_info.lkup_type;
1611 recp = &hw->switch_info->recp_list[l_type];
1612 LIST_ADD(&fm_entry->list_entry, &recp->filt_rules);
1614 ice_create_pkt_fwd_rule_exit:
1615 ice_free(hw, s_rule);
1620 * ice_update_pkt_fwd_rule
1621 * @hw: pointer to the hardware structure
1622 * @f_info: filter information for switch rule
1624 * Call AQ command to update a previously created switch rule with a
1627 static enum ice_status
1628 ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
1630 struct ice_aqc_sw_rules_elem *s_rule;
1631 enum ice_status status;
1633 s_rule = (struct ice_aqc_sw_rules_elem *)
1634 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1636 return ICE_ERR_NO_MEMORY;
1638 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
1640 s_rule->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_info->fltr_rule_id);
1642 /* Update switch rule with new rule set to forward VSI list */
1643 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1644 ice_aqc_opc_update_sw_rules, NULL);
1646 ice_free(hw, s_rule);
1651 * ice_update_sw_rule_bridge_mode
1652 * @hw: pointer to the HW struct
1654 * Updates unicast switch filter rules based on VEB/VEPA mode
1656 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw)
1658 struct ice_switch_info *sw = hw->switch_info;
1659 struct ice_fltr_mgmt_list_entry *fm_entry;
1660 enum ice_status status = ICE_SUCCESS;
1661 struct LIST_HEAD_TYPE *rule_head;
1662 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1664 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1665 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1667 ice_acquire_lock(rule_lock);
1668 LIST_FOR_EACH_ENTRY(fm_entry, rule_head, ice_fltr_mgmt_list_entry,
1670 struct ice_fltr_info *fi = &fm_entry->fltr_info;
1671 u8 *addr = fi->l_data.mac.mac_addr;
1673 /* Update unicast Tx rules to reflect the selected
1676 if ((fi->flag & ICE_FLTR_TX) && IS_UNICAST_ETHER_ADDR(addr) &&
1677 (fi->fltr_act == ICE_FWD_TO_VSI ||
1678 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1679 fi->fltr_act == ICE_FWD_TO_Q ||
1680 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1681 status = ice_update_pkt_fwd_rule(hw, fi);
1687 ice_release_lock(rule_lock);
1693 * ice_add_update_vsi_list
1694 * @hw: pointer to the hardware structure
1695 * @m_entry: pointer to current filter management list entry
1696 * @cur_fltr: filter information from the book keeping entry
1697 * @new_fltr: filter information with the new VSI to be added
1699 * Call AQ command to add or update previously created VSI list with new VSI.
1701 * Helper function to do book keeping associated with adding filter information
1702 * The algorithm to do the book keeping is described below :
1703 * When a VSI needs to subscribe to a given filter (MAC/VLAN/Ethtype etc.)
1704 * if only one VSI has been added till now
1705 * Allocate a new VSI list and add two VSIs
1706 * to this list using switch rule command
1707 * Update the previously created switch rule with the
1708 * newly created VSI list ID
1709 * if a VSI list was previously created
1710 * Add the new VSI to the previously created VSI list set
1711 * using the update switch rule command
1713 static enum ice_status
1714 ice_add_update_vsi_list(struct ice_hw *hw,
1715 struct ice_fltr_mgmt_list_entry *m_entry,
1716 struct ice_fltr_info *cur_fltr,
1717 struct ice_fltr_info *new_fltr)
1719 enum ice_status status = ICE_SUCCESS;
1720 u16 vsi_list_id = 0;
1722 if ((cur_fltr->fltr_act == ICE_FWD_TO_Q ||
1723 cur_fltr->fltr_act == ICE_FWD_TO_QGRP))
1724 return ICE_ERR_NOT_IMPL;
1726 if ((new_fltr->fltr_act == ICE_FWD_TO_Q ||
1727 new_fltr->fltr_act == ICE_FWD_TO_QGRP) &&
1728 (cur_fltr->fltr_act == ICE_FWD_TO_VSI ||
1729 cur_fltr->fltr_act == ICE_FWD_TO_VSI_LIST))
1730 return ICE_ERR_NOT_IMPL;
1732 if (m_entry->vsi_count < 2 && !m_entry->vsi_list_info) {
1733 /* Only one entry existed in the mapping and it was not already
1734 * a part of a VSI list. So, create a VSI list with the old and
1737 struct ice_fltr_info tmp_fltr;
1738 u16 vsi_handle_arr[2];
1740 /* A rule already exists with the new VSI being added */
1741 if (cur_fltr->fwd_id.hw_vsi_id == new_fltr->fwd_id.hw_vsi_id)
1742 return ICE_ERR_ALREADY_EXISTS;
1744 vsi_handle_arr[0] = cur_fltr->vsi_handle;
1745 vsi_handle_arr[1] = new_fltr->vsi_handle;
1746 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1748 new_fltr->lkup_type);
1752 tmp_fltr = *new_fltr;
1753 tmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;
1754 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1755 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1756 /* Update the previous switch rule of "MAC forward to VSI" to
1757 * "MAC fwd to VSI list"
1759 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1763 cur_fltr->fwd_id.vsi_list_id = vsi_list_id;
1764 cur_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1765 m_entry->vsi_list_info =
1766 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1769 /* If this entry was large action then the large action needs
1770 * to be updated to point to FWD to VSI list
1772 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID)
1774 ice_add_marker_act(hw, m_entry,
1775 m_entry->sw_marker_id,
1776 m_entry->lg_act_idx);
1778 u16 vsi_handle = new_fltr->vsi_handle;
1779 enum ice_adminq_opc opcode;
1781 if (!m_entry->vsi_list_info)
1784 /* A rule already exists with the new VSI being added */
1785 if (ice_is_bit_set(m_entry->vsi_list_info->vsi_map, vsi_handle))
1788 /* Update the previously created VSI list set with
1789 * the new VSI ID passed in
1791 vsi_list_id = cur_fltr->fwd_id.vsi_list_id;
1792 opcode = ice_aqc_opc_update_sw_rules;
1794 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1,
1795 vsi_list_id, false, opcode,
1796 new_fltr->lkup_type);
1797 /* update VSI list mapping info with new VSI ID */
1799 ice_set_bit(vsi_handle,
1800 m_entry->vsi_list_info->vsi_map);
1803 m_entry->vsi_count++;
1808 * ice_find_rule_entry - Search a rule entry
1809 * @hw: pointer to the hardware structure
1810 * @recp_id: lookup type for which the specified rule needs to be searched
1811 * @f_info: rule information
1813 * Helper function to search for a given rule entry
1814 * Returns pointer to entry storing the rule if found
1816 static struct ice_fltr_mgmt_list_entry *
1817 ice_find_rule_entry(struct ice_hw *hw, u8 recp_id, struct ice_fltr_info *f_info)
1819 struct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;
1820 struct ice_switch_info *sw = hw->switch_info;
1821 struct LIST_HEAD_TYPE *list_head;
1823 list_head = &sw->recp_list[recp_id].filt_rules;
1824 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1826 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
1827 sizeof(f_info->l_data)) &&
1828 f_info->flag == list_itr->fltr_info.flag) {
1837 * ice_find_vsi_list_entry - Search VSI list map with VSI count 1
1838 * @hw: pointer to the hardware structure
1839 * @recp_id: lookup type for which VSI lists needs to be searched
1840 * @vsi_handle: VSI handle to be found in VSI list
1841 * @vsi_list_id: VSI list ID found containing vsi_handle
1843 * Helper function to search a VSI list with single entry containing given VSI
1844 * handle element. This can be extended further to search VSI list with more
1845 * than 1 vsi_count. Returns pointer to VSI list entry if found.
1847 static struct ice_vsi_list_map_info *
1848 ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
1851 struct ice_vsi_list_map_info *map_info = NULL;
1852 struct ice_switch_info *sw = hw->switch_info;
1853 struct ice_fltr_mgmt_list_entry *list_itr;
1854 struct LIST_HEAD_TYPE *list_head;
1856 list_head = &sw->recp_list[recp_id].filt_rules;
1857 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1859 if (list_itr->vsi_count == 1 && list_itr->vsi_list_info) {
1860 map_info = list_itr->vsi_list_info;
1861 if (ice_is_bit_set(map_info->vsi_map, vsi_handle)) {
1862 *vsi_list_id = map_info->vsi_list_id;
1871 * ice_add_rule_internal - add rule for a given lookup type
1872 * @hw: pointer to the hardware structure
1873 * @recp_id: lookup type (recipe ID) for which rule has to be added
1874 * @f_entry: structure containing MAC forwarding information
1876 * Adds or updates the rule lists for a given recipe
1878 static enum ice_status
1879 ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,
1880 struct ice_fltr_list_entry *f_entry)
1882 struct ice_switch_info *sw = hw->switch_info;
1883 struct ice_fltr_info *new_fltr, *cur_fltr;
1884 struct ice_fltr_mgmt_list_entry *m_entry;
1885 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1886 enum ice_status status = ICE_SUCCESS;
1888 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1889 return ICE_ERR_PARAM;
1891 /* Load the hw_vsi_id only if the fwd action is fwd to VSI */
1892 if (f_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI)
1893 f_entry->fltr_info.fwd_id.hw_vsi_id =
1894 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1896 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1898 ice_acquire_lock(rule_lock);
1899 new_fltr = &f_entry->fltr_info;
1900 if (new_fltr->flag & ICE_FLTR_RX)
1901 new_fltr->src = hw->port_info->lport;
1902 else if (new_fltr->flag & ICE_FLTR_TX)
1904 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1906 m_entry = ice_find_rule_entry(hw, recp_id, new_fltr);
1908 ice_release_lock(rule_lock);
1909 return ice_create_pkt_fwd_rule(hw, f_entry);
1912 cur_fltr = &m_entry->fltr_info;
1913 status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
1914 ice_release_lock(rule_lock);
1920 * ice_remove_vsi_list_rule
1921 * @hw: pointer to the hardware structure
1922 * @vsi_list_id: VSI list ID generated as part of allocate resource
1923 * @lkup_type: switch rule filter lookup type
1925 * The VSI list should be emptied before this function is called to remove the
1928 static enum ice_status
1929 ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
1930 enum ice_sw_lkup_type lkup_type)
1932 struct ice_aqc_sw_rules_elem *s_rule;
1933 enum ice_status status;
1936 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
1937 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1939 return ICE_ERR_NO_MEMORY;
1941 s_rule->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
1942 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1944 /* Free the vsi_list resource that we allocated. It is assumed that the
1945 * list is empty at this point.
1947 status = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,
1948 ice_aqc_opc_free_res);
1950 ice_free(hw, s_rule);
1955 * ice_rem_update_vsi_list
1956 * @hw: pointer to the hardware structure
1957 * @vsi_handle: VSI handle of the VSI to remove
1958 * @fm_list: filter management entry for which the VSI list management needs to
1961 static enum ice_status
1962 ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
1963 struct ice_fltr_mgmt_list_entry *fm_list)
1965 enum ice_sw_lkup_type lkup_type;
1966 enum ice_status status = ICE_SUCCESS;
1969 if (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||
1970 fm_list->vsi_count == 0)
1971 return ICE_ERR_PARAM;
1973 /* A rule with the VSI being removed does not exist */
1974 if (!ice_is_bit_set(fm_list->vsi_list_info->vsi_map, vsi_handle))
1975 return ICE_ERR_DOES_NOT_EXIST;
1977 lkup_type = fm_list->fltr_info.lkup_type;
1978 vsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;
1979 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
1980 ice_aqc_opc_update_sw_rules,
1985 fm_list->vsi_count--;
1986 ice_clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
1988 if (fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) {
1989 struct ice_fltr_info tmp_fltr_info = fm_list->fltr_info;
1990 struct ice_vsi_list_map_info *vsi_list_info =
1991 fm_list->vsi_list_info;
1994 rem_vsi_handle = ice_find_first_bit(vsi_list_info->vsi_map,
1996 if (!ice_is_vsi_valid(hw, rem_vsi_handle))
1997 return ICE_ERR_OUT_OF_RANGE;
1999 /* Make sure VSI list is empty before removing it below */
2000 status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
2002 ice_aqc_opc_update_sw_rules,
2007 tmp_fltr_info.fltr_act = ICE_FWD_TO_VSI;
2008 tmp_fltr_info.fwd_id.hw_vsi_id =
2009 ice_get_hw_vsi_num(hw, rem_vsi_handle);
2010 tmp_fltr_info.vsi_handle = rem_vsi_handle;
2011 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr_info);
2013 ice_debug(hw, ICE_DBG_SW,
2014 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
2015 tmp_fltr_info.fwd_id.hw_vsi_id, status);
2019 fm_list->fltr_info = tmp_fltr_info;
2022 if ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||
2023 (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {
2024 struct ice_vsi_list_map_info *vsi_list_info =
2025 fm_list->vsi_list_info;
2027 /* Remove the VSI list since it is no longer used */
2028 status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
2030 ice_debug(hw, ICE_DBG_SW,
2031 "Failed to remove VSI list %d, error %d\n",
2032 vsi_list_id, status);
2036 LIST_DEL(&vsi_list_info->list_entry);
2037 ice_free(hw, vsi_list_info);
2038 fm_list->vsi_list_info = NULL;
2045 * ice_remove_rule_internal - Remove a filter rule of a given type
2047 * @hw: pointer to the hardware structure
2048 * @recp_id: recipe ID for which the rule needs to removed
2049 * @f_entry: rule entry containing filter information
2051 static enum ice_status
2052 ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id,
2053 struct ice_fltr_list_entry *f_entry)
2055 struct ice_switch_info *sw = hw->switch_info;
2056 struct ice_fltr_mgmt_list_entry *list_elem;
2057 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2058 enum ice_status status = ICE_SUCCESS;
2059 bool remove_rule = false;
2062 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
2063 return ICE_ERR_PARAM;
2064 f_entry->fltr_info.fwd_id.hw_vsi_id =
2065 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
2067 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
2068 ice_acquire_lock(rule_lock);
2069 list_elem = ice_find_rule_entry(hw, recp_id, &f_entry->fltr_info);
2071 status = ICE_ERR_DOES_NOT_EXIST;
2075 if (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {
2077 } else if (!list_elem->vsi_list_info) {
2078 status = ICE_ERR_DOES_NOT_EXIST;
2080 } else if (list_elem->vsi_list_info->ref_cnt > 1) {
2081 /* a ref_cnt > 1 indicates that the vsi_list is being
2082 * shared by multiple rules. Decrement the ref_cnt and
2083 * remove this rule, but do not modify the list, as it
2084 * is in-use by other rules.
2086 list_elem->vsi_list_info->ref_cnt--;
2089 /* a ref_cnt of 1 indicates the vsi_list is only used
2090 * by one rule. However, the original removal request is only
2091 * for a single VSI. Update the vsi_list first, and only
2092 * remove the rule if there are no further VSIs in this list.
2094 vsi_handle = f_entry->fltr_info.vsi_handle;
2095 status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem);
2098 /* if VSI count goes to zero after updating the VSI list */
2099 if (list_elem->vsi_count == 0)
2104 /* Remove the lookup rule */
2105 struct ice_aqc_sw_rules_elem *s_rule;
2107 s_rule = (struct ice_aqc_sw_rules_elem *)
2108 ice_malloc(hw, ICE_SW_RULE_RX_TX_NO_HDR_SIZE);
2110 status = ICE_ERR_NO_MEMORY;
2114 ice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,
2115 ice_aqc_opc_remove_sw_rules);
2117 status = ice_aq_sw_rules(hw, s_rule,
2118 ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
2119 ice_aqc_opc_remove_sw_rules, NULL);
2123 /* Remove a book keeping from the list */
2124 ice_free(hw, s_rule);
2126 LIST_DEL(&list_elem->list_entry);
2127 ice_free(hw, list_elem);
2130 ice_release_lock(rule_lock);
2135 * ice_aq_get_res_alloc - get allocated resources
2136 * @hw: pointer to the HW struct
2137 * @num_entries: pointer to u16 to store the number of resource entries returned
2138 * @buf: pointer to user-supplied buffer
2139 * @buf_size: size of buff
2140 * @cd: pointer to command details structure or NULL
2142 * The user-supplied buffer must be large enough to store the resource
2143 * information for all resource types. Each resource type is an
2144 * ice_aqc_get_res_resp_data_elem structure.
2147 ice_aq_get_res_alloc(struct ice_hw *hw, u16 *num_entries, void *buf,
2148 u16 buf_size, struct ice_sq_cd *cd)
2150 struct ice_aqc_get_res_alloc *resp;
2151 enum ice_status status;
2152 struct ice_aq_desc desc;
2155 return ICE_ERR_BAD_PTR;
2157 if (buf_size < ICE_AQ_GET_RES_ALLOC_BUF_LEN)
2158 return ICE_ERR_INVAL_SIZE;
2160 resp = &desc.params.get_res;
2162 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_res_alloc);
2163 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2165 if (!status && num_entries)
2166 *num_entries = LE16_TO_CPU(resp->resp_elem_num);
2172 * ice_aq_get_res_descs - get allocated resource descriptors
2173 * @hw: pointer to the hardware structure
2174 * @num_entries: number of resource entries in buffer
2175 * @buf: Indirect buffer to hold data parameters and response
2176 * @buf_size: size of buffer for indirect commands
2177 * @res_type: resource type
2178 * @res_shared: is resource shared
2179 * @desc_id: input - first desc ID to start; output - next desc ID
2180 * @cd: pointer to command details structure or NULL
2183 ice_aq_get_res_descs(struct ice_hw *hw, u16 num_entries,
2184 struct ice_aqc_get_allocd_res_desc_resp *buf,
2185 u16 buf_size, u16 res_type, bool res_shared, u16 *desc_id,
2186 struct ice_sq_cd *cd)
2188 struct ice_aqc_get_allocd_res_desc *cmd;
2189 struct ice_aq_desc desc;
2190 enum ice_status status;
2192 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_get_res_descs");
2194 cmd = &desc.params.get_res_desc;
2197 return ICE_ERR_PARAM;
2199 if (buf_size != (num_entries * sizeof(*buf)))
2200 return ICE_ERR_PARAM;
2202 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_allocd_res_desc);
2204 cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2205 ICE_AQC_RES_TYPE_M) | (res_shared ?
2206 ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2207 cmd->ops.cmd.first_desc = CPU_TO_LE16(*desc_id);
2209 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
2211 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2213 *desc_id = LE16_TO_CPU(cmd->ops.resp.next_desc);
2219 * ice_add_mac - Add a MAC address based filter rule
2220 * @hw: pointer to the hardware structure
2221 * @m_list: list of MAC addresses and forwarding information
2223 * IMPORTANT: When the ucast_shared flag is set to false and m_list has
2224 * multiple unicast addresses, the function assumes that all the
2225 * addresses are unique in a given add_mac call. It doesn't
2226 * check for duplicates in this case, removing duplicates from a given
2227 * list should be taken care of in the caller of this function.
2230 ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2232 struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
2233 struct ice_fltr_list_entry *m_list_itr;
2234 struct LIST_HEAD_TYPE *rule_head;
2235 u16 elem_sent, total_elem_left;
2236 struct ice_switch_info *sw;
2237 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2238 enum ice_status status = ICE_SUCCESS;
2239 u16 num_unicast = 0;
2243 return ICE_ERR_PARAM;
2245 sw = hw->switch_info;
2246 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
2247 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2249 u8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];
2253 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
2254 vsi_handle = m_list_itr->fltr_info.vsi_handle;
2255 if (!ice_is_vsi_valid(hw, vsi_handle))
2256 return ICE_ERR_PARAM;
2257 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2258 m_list_itr->fltr_info.fwd_id.hw_vsi_id = hw_vsi_id;
2259 /* update the src in case it is VSI num */
2260 if (m_list_itr->fltr_info.src_id != ICE_SRC_ID_VSI)
2261 return ICE_ERR_PARAM;
2262 m_list_itr->fltr_info.src = hw_vsi_id;
2263 if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
2264 IS_ZERO_ETHER_ADDR(add))
2265 return ICE_ERR_PARAM;
2266 if (IS_UNICAST_ETHER_ADDR(add) && !hw->ucast_shared) {
2267 /* Don't overwrite the unicast address */
2268 ice_acquire_lock(rule_lock);
2269 if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
2270 &m_list_itr->fltr_info)) {
2271 ice_release_lock(rule_lock);
2272 return ICE_ERR_ALREADY_EXISTS;
2274 ice_release_lock(rule_lock);
2276 } else if (IS_MULTICAST_ETHER_ADDR(add) ||
2277 (IS_UNICAST_ETHER_ADDR(add) && hw->ucast_shared)) {
2278 m_list_itr->status =
2279 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
2281 if (m_list_itr->status)
2282 return m_list_itr->status;
2286 ice_acquire_lock(rule_lock);
2287 /* Exit if no suitable entries were found for adding bulk switch rule */
2289 status = ICE_SUCCESS;
2290 goto ice_add_mac_exit;
2293 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
2295 /* Allocate switch rule buffer for the bulk update for unicast */
2296 s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
2297 s_rule = (struct ice_aqc_sw_rules_elem *)
2298 ice_calloc(hw, num_unicast, s_rule_size);
2300 status = ICE_ERR_NO_MEMORY;
2301 goto ice_add_mac_exit;
2305 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2307 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2308 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2310 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2311 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
2312 ice_aqc_opc_add_sw_rules);
2313 r_iter = (struct ice_aqc_sw_rules_elem *)
2314 ((u8 *)r_iter + s_rule_size);
2318 /* Call AQ bulk switch rule update for all unicast addresses */
2320 /* Call AQ switch rule in AQ_MAX chunk */
2321 for (total_elem_left = num_unicast; total_elem_left > 0;
2322 total_elem_left -= elem_sent) {
2323 struct ice_aqc_sw_rules_elem *entry = r_iter;
2325 elem_sent = min(total_elem_left,
2326 (u16)(ICE_AQ_MAX_BUF_LEN / s_rule_size));
2327 status = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,
2328 elem_sent, ice_aqc_opc_add_sw_rules,
2331 goto ice_add_mac_exit;
2332 r_iter = (struct ice_aqc_sw_rules_elem *)
2333 ((u8 *)r_iter + (elem_sent * s_rule_size));
2336 /* Fill up rule ID based on the value returned from FW */
2338 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2340 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2341 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2342 struct ice_fltr_mgmt_list_entry *fm_entry;
2344 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2345 f_info->fltr_rule_id =
2346 LE16_TO_CPU(r_iter->pdata.lkup_tx_rx.index);
2347 f_info->fltr_act = ICE_FWD_TO_VSI;
2348 /* Create an entry to track this MAC address */
2349 fm_entry = (struct ice_fltr_mgmt_list_entry *)
2350 ice_malloc(hw, sizeof(*fm_entry));
2352 status = ICE_ERR_NO_MEMORY;
2353 goto ice_add_mac_exit;
2355 fm_entry->fltr_info = *f_info;
2356 fm_entry->vsi_count = 1;
2357 /* The book keeping entries will get removed when
2358 * base driver calls remove filter AQ command
2361 LIST_ADD(&fm_entry->list_entry, rule_head);
2362 r_iter = (struct ice_aqc_sw_rules_elem *)
2363 ((u8 *)r_iter + s_rule_size);
2368 ice_release_lock(rule_lock);
2370 ice_free(hw, s_rule);
2375 * ice_add_vlan_internal - Add one VLAN based filter rule
2376 * @hw: pointer to the hardware structure
2377 * @f_entry: filter entry containing one VLAN information
2379 static enum ice_status
2380 ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)
2382 struct ice_switch_info *sw = hw->switch_info;
2383 struct ice_fltr_mgmt_list_entry *v_list_itr;
2384 struct ice_fltr_info *new_fltr, *cur_fltr;
2385 enum ice_sw_lkup_type lkup_type;
2386 u16 vsi_list_id = 0, vsi_handle;
2387 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2388 enum ice_status status = ICE_SUCCESS;
2390 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
2391 return ICE_ERR_PARAM;
2393 f_entry->fltr_info.fwd_id.hw_vsi_id =
2394 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
2395 new_fltr = &f_entry->fltr_info;
2397 /* VLAN ID should only be 12 bits */
2398 if (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)
2399 return ICE_ERR_PARAM;
2401 if (new_fltr->src_id != ICE_SRC_ID_VSI)
2402 return ICE_ERR_PARAM;
2404 new_fltr->src = new_fltr->fwd_id.hw_vsi_id;
2405 lkup_type = new_fltr->lkup_type;
2406 vsi_handle = new_fltr->vsi_handle;
2407 rule_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
2408 ice_acquire_lock(rule_lock);
2409 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN, new_fltr);
2411 struct ice_vsi_list_map_info *map_info = NULL;
2413 if (new_fltr->fltr_act == ICE_FWD_TO_VSI) {
2414 /* All VLAN pruning rules use a VSI list. Check if
2415 * there is already a VSI list containing VSI that we
2416 * want to add. If found, use the same vsi_list_id for
2417 * this new VLAN rule or else create a new list.
2419 map_info = ice_find_vsi_list_entry(hw, ICE_SW_LKUP_VLAN,
2423 status = ice_create_vsi_list_rule(hw,
2431 /* Convert the action to forwarding to a VSI list. */
2432 new_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
2433 new_fltr->fwd_id.vsi_list_id = vsi_list_id;
2436 status = ice_create_pkt_fwd_rule(hw, f_entry);
2438 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN,
2441 status = ICE_ERR_DOES_NOT_EXIST;
2444 /* reuse VSI list for new rule and increment ref_cnt */
2446 v_list_itr->vsi_list_info = map_info;
2447 map_info->ref_cnt++;
2449 v_list_itr->vsi_list_info =
2450 ice_create_vsi_list_map(hw, &vsi_handle,
2454 } else if (v_list_itr->vsi_list_info->ref_cnt == 1) {
2455 /* Update existing VSI list to add new VSI ID only if it used
2458 cur_fltr = &v_list_itr->fltr_info;
2459 status = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr,
2462 /* If VLAN rule exists and VSI list being used by this rule is
2463 * referenced by more than 1 VLAN rule. Then create a new VSI
2464 * list appending previous VSI with new VSI and update existing
2465 * VLAN rule to point to new VSI list ID
2467 struct ice_fltr_info tmp_fltr;
2468 u16 vsi_handle_arr[2];
2471 /* Current implementation only supports reusing VSI list with
2472 * one VSI count. We should never hit below condition
2474 if (v_list_itr->vsi_count > 1 &&
2475 v_list_itr->vsi_list_info->ref_cnt > 1) {
2476 ice_debug(hw, ICE_DBG_SW,
2477 "Invalid configuration: Optimization to reuse VSI list with more than one VSI is not being done yet\n");
2478 status = ICE_ERR_CFG;
2483 ice_find_first_bit(v_list_itr->vsi_list_info->vsi_map,
2486 /* A rule already exists with the new VSI being added */
2487 if (cur_handle == vsi_handle) {
2488 status = ICE_ERR_ALREADY_EXISTS;
2492 vsi_handle_arr[0] = cur_handle;
2493 vsi_handle_arr[1] = vsi_handle;
2494 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
2495 &vsi_list_id, lkup_type);
2499 tmp_fltr = v_list_itr->fltr_info;
2500 tmp_fltr.fltr_rule_id = v_list_itr->fltr_info.fltr_rule_id;
2501 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
2502 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
2503 /* Update the previous switch rule to a new VSI list which
2504 * includes current VSI that is requested
2506 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
2510 /* before overriding VSI list map info. decrement ref_cnt of
2513 v_list_itr->vsi_list_info->ref_cnt--;
2515 /* now update to newly created list */
2516 v_list_itr->fltr_info.fwd_id.vsi_list_id = vsi_list_id;
2517 v_list_itr->vsi_list_info =
2518 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
2520 v_list_itr->vsi_count++;
2524 ice_release_lock(rule_lock);
2529 * ice_add_vlan - Add VLAN based filter rule
2530 * @hw: pointer to the hardware structure
2531 * @v_list: list of VLAN entries and forwarding information
2534 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2536 struct ice_fltr_list_entry *v_list_itr;
2539 return ICE_ERR_PARAM;
2541 LIST_FOR_EACH_ENTRY(v_list_itr, v_list, ice_fltr_list_entry,
2543 if (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)
2544 return ICE_ERR_PARAM;
2545 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
2546 v_list_itr->status = ice_add_vlan_internal(hw, v_list_itr);
2547 if (v_list_itr->status)
2548 return v_list_itr->status;
2553 #ifndef NO_MACVLAN_SUPPORT
2555 * ice_add_mac_vlan - Add MAC and VLAN pair based filter rule
2556 * @hw: pointer to the hardware structure
2557 * @mv_list: list of MAC and VLAN filters
2559 * If the VSI on which the MAC-VLAN pair has to be added has Rx and Tx VLAN
2560 * pruning bits enabled, then it is the responsibility of the caller to make
2561 * sure to add a VLAN only filter on the same VSI. Packets belonging to that
2562 * VLAN won't be received on that VSI otherwise.
2565 ice_add_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *mv_list)
2567 struct ice_fltr_list_entry *mv_list_itr;
2569 if (!mv_list || !hw)
2570 return ICE_ERR_PARAM;
2572 LIST_FOR_EACH_ENTRY(mv_list_itr, mv_list, ice_fltr_list_entry,
2574 enum ice_sw_lkup_type l_type =
2575 mv_list_itr->fltr_info.lkup_type;
2577 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2578 return ICE_ERR_PARAM;
2579 mv_list_itr->fltr_info.flag = ICE_FLTR_TX;
2580 mv_list_itr->status =
2581 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2583 if (mv_list_itr->status)
2584 return mv_list_itr->status;
2591 * ice_add_eth_mac - Add ethertype and MAC based filter rule
2592 * @hw: pointer to the hardware structure
2593 * @em_list: list of ether type MAC filter, MAC is optional
2596 ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
2598 struct ice_fltr_list_entry *em_list_itr;
2600 LIST_FOR_EACH_ENTRY(em_list_itr, em_list, ice_fltr_list_entry,
2602 enum ice_sw_lkup_type l_type =
2603 em_list_itr->fltr_info.lkup_type;
2605 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
2606 l_type != ICE_SW_LKUP_ETHERTYPE)
2607 return ICE_ERR_PARAM;
2609 em_list_itr->fltr_info.flag = ICE_FLTR_TX;
2610 em_list_itr->status = ice_add_rule_internal(hw, l_type,
2612 if (em_list_itr->status)
2613 return em_list_itr->status;
2619 * ice_remove_eth_mac - Remove an ethertype (or MAC) based filter rule
2620 * @hw: pointer to the hardware structure
2621 * @em_list: list of ethertype or ethertype MAC entries
2624 ice_remove_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
2626 struct ice_fltr_list_entry *em_list_itr, *tmp;
2628 if (!em_list || !hw)
2629 return ICE_ERR_PARAM;
2631 LIST_FOR_EACH_ENTRY_SAFE(em_list_itr, tmp, em_list, ice_fltr_list_entry,
2633 enum ice_sw_lkup_type l_type =
2634 em_list_itr->fltr_info.lkup_type;
2636 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
2637 l_type != ICE_SW_LKUP_ETHERTYPE)
2638 return ICE_ERR_PARAM;
2640 em_list_itr->status = ice_remove_rule_internal(hw, l_type,
2642 if (em_list_itr->status)
2643 return em_list_itr->status;
2650 * ice_rem_sw_rule_info
2651 * @hw: pointer to the hardware structure
2652 * @rule_head: pointer to the switch list structure that we want to delete
2655 ice_rem_sw_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
2657 if (!LIST_EMPTY(rule_head)) {
2658 struct ice_fltr_mgmt_list_entry *entry;
2659 struct ice_fltr_mgmt_list_entry *tmp;
2661 LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, rule_head,
2662 ice_fltr_mgmt_list_entry, list_entry) {
2663 LIST_DEL(&entry->list_entry);
2664 ice_free(hw, entry);
2672 * ice_cfg_dflt_vsi - change state of VSI to set/clear default
2673 * @pi: pointer to the port_info structure
2674 * @vsi_handle: VSI handle to set as default
2675 * @set: true to add the above mentioned switch rule, false to remove it
2676 * @direction: ICE_FLTR_RX or ICE_FLTR_TX
2678 * add filter rule to set/unset given VSI as default VSI for the switch
2679 * (represented by swid)
2682 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
2685 struct ice_aqc_sw_rules_elem *s_rule;
2686 struct ice_fltr_info f_info;
2687 struct ice_hw *hw = pi->hw;
2688 enum ice_adminq_opc opcode;
2689 enum ice_status status;
2693 if (!ice_is_vsi_valid(hw, vsi_handle))
2694 return ICE_ERR_PARAM;
2695 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2697 s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
2698 ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
2699 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
2701 return ICE_ERR_NO_MEMORY;
2703 ice_memset(&f_info, 0, sizeof(f_info), ICE_NONDMA_MEM);
2705 f_info.lkup_type = ICE_SW_LKUP_DFLT;
2706 f_info.flag = direction;
2707 f_info.fltr_act = ICE_FWD_TO_VSI;
2708 f_info.fwd_id.hw_vsi_id = hw_vsi_id;
2710 if (f_info.flag & ICE_FLTR_RX) {
2711 f_info.src = pi->lport;
2712 f_info.src_id = ICE_SRC_ID_LPORT;
2714 f_info.fltr_rule_id =
2715 pi->dflt_rx_vsi_rule_id;
2716 } else if (f_info.flag & ICE_FLTR_TX) {
2717 f_info.src_id = ICE_SRC_ID_VSI;
2718 f_info.src = hw_vsi_id;
2720 f_info.fltr_rule_id =
2721 pi->dflt_tx_vsi_rule_id;
2725 opcode = ice_aqc_opc_add_sw_rules;
2727 opcode = ice_aqc_opc_remove_sw_rules;
2729 ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
2731 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
2732 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
2735 u16 index = LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
2737 if (f_info.flag & ICE_FLTR_TX) {
2738 pi->dflt_tx_vsi_num = hw_vsi_id;
2739 pi->dflt_tx_vsi_rule_id = index;
2740 } else if (f_info.flag & ICE_FLTR_RX) {
2741 pi->dflt_rx_vsi_num = hw_vsi_id;
2742 pi->dflt_rx_vsi_rule_id = index;
2745 if (f_info.flag & ICE_FLTR_TX) {
2746 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
2747 pi->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
2748 } else if (f_info.flag & ICE_FLTR_RX) {
2749 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
2750 pi->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
2755 ice_free(hw, s_rule);
2760 * ice_remove_mac - remove a MAC address based filter rule
2761 * @hw: pointer to the hardware structure
2762 * @m_list: list of MAC addresses and forwarding information
2764 * This function removes either a MAC filter rule or a specific VSI from a
2765 * VSI list for a multicast MAC address.
2767 * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by
2768 * ice_add_mac. Caller should be aware that this call will only work if all
2769 * the entries passed into m_list were added previously. It will not attempt to
2770 * do a partial remove of entries that were found.
2773 ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2775 struct ice_fltr_list_entry *list_itr, *tmp;
2778 return ICE_ERR_PARAM;
2780 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, m_list, ice_fltr_list_entry,
2782 enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
2784 if (l_type != ICE_SW_LKUP_MAC)
2785 return ICE_ERR_PARAM;
2786 list_itr->status = ice_remove_rule_internal(hw,
2789 if (list_itr->status)
2790 return list_itr->status;
2796 * ice_remove_vlan - Remove VLAN based filter rule
2797 * @hw: pointer to the hardware structure
2798 * @v_list: list of VLAN entries and forwarding information
2801 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2803 struct ice_fltr_list_entry *v_list_itr, *tmp;
2806 return ICE_ERR_PARAM;
2808 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2810 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2812 if (l_type != ICE_SW_LKUP_VLAN)
2813 return ICE_ERR_PARAM;
2814 v_list_itr->status = ice_remove_rule_internal(hw,
2817 if (v_list_itr->status)
2818 return v_list_itr->status;
2823 #ifndef NO_MACVLAN_SUPPORT
2825 * ice_remove_mac_vlan - Remove MAC VLAN based filter rule
2826 * @hw: pointer to the hardware structure
2827 * @v_list: list of MAC VLAN entries and forwarding information
2830 ice_remove_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2832 struct ice_fltr_list_entry *v_list_itr, *tmp;
2835 return ICE_ERR_PARAM;
2837 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2839 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2841 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2842 return ICE_ERR_PARAM;
2843 v_list_itr->status =
2844 ice_remove_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2846 if (v_list_itr->status)
2847 return v_list_itr->status;
2851 #endif /* !NO_MACVLAN_SUPPORT */
2854 * ice_vsi_uses_fltr - Determine if given VSI uses specified filter
2855 * @fm_entry: filter entry to inspect
2856 * @vsi_handle: VSI handle to compare with filter info
2859 ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle)
2861 return ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&
2862 fm_entry->fltr_info.vsi_handle == vsi_handle) ||
2863 (fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&
2864 (ice_is_bit_set(fm_entry->vsi_list_info->vsi_map,
2869 * ice_add_entry_to_vsi_fltr_list - Add copy of fltr_list_entry to remove list
2870 * @hw: pointer to the hardware structure
2871 * @vsi_handle: VSI handle to remove filters from
2872 * @vsi_list_head: pointer to the list to add entry to
2873 * @fi: pointer to fltr_info of filter entry to copy & add
2875 * Helper function, used when creating a list of filters to remove from
2876 * a specific VSI. The entry added to vsi_list_head is a COPY of the
2877 * original filter entry, with the exception of fltr_info.fltr_act and
2878 * fltr_info.fwd_id fields. These are set such that later logic can
2879 * extract which VSI to remove the fltr from, and pass on that information.
2881 static enum ice_status
2882 ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2883 struct LIST_HEAD_TYPE *vsi_list_head,
2884 struct ice_fltr_info *fi)
2886 struct ice_fltr_list_entry *tmp;
2888 /* this memory is freed up in the caller function
2889 * once filters for this VSI are removed
2891 tmp = (struct ice_fltr_list_entry *)ice_malloc(hw, sizeof(*tmp));
2893 return ICE_ERR_NO_MEMORY;
2895 tmp->fltr_info = *fi;
2897 /* Overwrite these fields to indicate which VSI to remove filter from,
2898 * so find and remove logic can extract the information from the
2899 * list entries. Note that original entries will still have proper
2902 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2903 tmp->fltr_info.vsi_handle = vsi_handle;
2904 tmp->fltr_info.fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2906 LIST_ADD(&tmp->list_entry, vsi_list_head);
2912 * ice_add_to_vsi_fltr_list - Add VSI filters to the list
2913 * @hw: pointer to the hardware structure
2914 * @vsi_handle: VSI handle to remove filters from
2915 * @lkup_list_head: pointer to the list that has certain lookup type filters
2916 * @vsi_list_head: pointer to the list pertaining to VSI with vsi_handle
2918 * Locates all filters in lkup_list_head that are used by the given VSI,
2919 * and adds COPIES of those entries to vsi_list_head (intended to be used
2920 * to remove the listed filters).
2921 * Note that this means all entries in vsi_list_head must be explicitly
2922 * deallocated by the caller when done with list.
2924 static enum ice_status
2925 ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2926 struct LIST_HEAD_TYPE *lkup_list_head,
2927 struct LIST_HEAD_TYPE *vsi_list_head)
2929 struct ice_fltr_mgmt_list_entry *fm_entry;
2930 enum ice_status status = ICE_SUCCESS;
2932 /* check to make sure VSI ID is valid and within boundary */
2933 if (!ice_is_vsi_valid(hw, vsi_handle))
2934 return ICE_ERR_PARAM;
2936 LIST_FOR_EACH_ENTRY(fm_entry, lkup_list_head,
2937 ice_fltr_mgmt_list_entry, list_entry) {
2938 struct ice_fltr_info *fi;
2940 fi = &fm_entry->fltr_info;
2941 if (!fi || !ice_vsi_uses_fltr(fm_entry, vsi_handle))
2944 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2954 * ice_determine_promisc_mask
2955 * @fi: filter info to parse
2957 * Helper function to determine which ICE_PROMISC_ mask corresponds
2958 * to given filter into.
2960 static u8 ice_determine_promisc_mask(struct ice_fltr_info *fi)
2962 u16 vid = fi->l_data.mac_vlan.vlan_id;
2963 u8 *macaddr = fi->l_data.mac.mac_addr;
2964 bool is_tx_fltr = false;
2965 u8 promisc_mask = 0;
2967 if (fi->flag == ICE_FLTR_TX)
2970 if (IS_BROADCAST_ETHER_ADDR(macaddr))
2971 promisc_mask |= is_tx_fltr ?
2972 ICE_PROMISC_BCAST_TX : ICE_PROMISC_BCAST_RX;
2973 else if (IS_MULTICAST_ETHER_ADDR(macaddr))
2974 promisc_mask |= is_tx_fltr ?
2975 ICE_PROMISC_MCAST_TX : ICE_PROMISC_MCAST_RX;
2976 else if (IS_UNICAST_ETHER_ADDR(macaddr))
2977 promisc_mask |= is_tx_fltr ?
2978 ICE_PROMISC_UCAST_TX : ICE_PROMISC_UCAST_RX;
2980 promisc_mask |= is_tx_fltr ?
2981 ICE_PROMISC_VLAN_TX : ICE_PROMISC_VLAN_RX;
2983 return promisc_mask;
2987 * ice_get_vsi_promisc - get promiscuous mode of given VSI
2988 * @hw: pointer to the hardware structure
2989 * @vsi_handle: VSI handle to retrieve info from
2990 * @promisc_mask: pointer to mask to be filled in
2991 * @vid: VLAN ID of promisc VLAN VSI
2994 ice_get_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
2997 struct ice_switch_info *sw = hw->switch_info;
2998 struct ice_fltr_mgmt_list_entry *itr;
2999 struct LIST_HEAD_TYPE *rule_head;
3000 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3002 if (!ice_is_vsi_valid(hw, vsi_handle))
3003 return ICE_ERR_PARAM;
3007 rule_head = &sw->recp_list[ICE_SW_LKUP_PROMISC].filt_rules;
3008 rule_lock = &sw->recp_list[ICE_SW_LKUP_PROMISC].filt_rule_lock;
3010 ice_acquire_lock(rule_lock);
3011 LIST_FOR_EACH_ENTRY(itr, rule_head,
3012 ice_fltr_mgmt_list_entry, list_entry) {
3013 /* Continue if this filter doesn't apply to this VSI or the
3014 * VSI ID is not in the VSI map for this filter
3016 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3019 *promisc_mask |= ice_determine_promisc_mask(&itr->fltr_info);
3021 ice_release_lock(rule_lock);
3027 * ice_get_vsi_vlan_promisc - get VLAN promiscuous mode of given VSI
3028 * @hw: pointer to the hardware structure
3029 * @vsi_handle: VSI handle to retrieve info from
3030 * @promisc_mask: pointer to mask to be filled in
3031 * @vid: VLAN ID of promisc VLAN VSI
3034 ice_get_vsi_vlan_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
3037 struct ice_switch_info *sw = hw->switch_info;
3038 struct ice_fltr_mgmt_list_entry *itr;
3039 struct LIST_HEAD_TYPE *rule_head;
3040 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3042 if (!ice_is_vsi_valid(hw, vsi_handle))
3043 return ICE_ERR_PARAM;
3047 rule_head = &sw->recp_list[ICE_SW_LKUP_PROMISC_VLAN].filt_rules;
3048 rule_lock = &sw->recp_list[ICE_SW_LKUP_PROMISC_VLAN].filt_rule_lock;
3050 ice_acquire_lock(rule_lock);
3051 LIST_FOR_EACH_ENTRY(itr, rule_head, ice_fltr_mgmt_list_entry,
3053 /* Continue if this filter doesn't apply to this VSI or the
3054 * VSI ID is not in the VSI map for this filter
3056 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3059 *promisc_mask |= ice_determine_promisc_mask(&itr->fltr_info);
3061 ice_release_lock(rule_lock);
3067 * ice_remove_promisc - Remove promisc based filter rules
3068 * @hw: pointer to the hardware structure
3069 * @recp_id: recipe ID for which the rule needs to removed
3070 * @v_list: list of promisc entries
3072 static enum ice_status
3073 ice_remove_promisc(struct ice_hw *hw, u8 recp_id,
3074 struct LIST_HEAD_TYPE *v_list)
3076 struct ice_fltr_list_entry *v_list_itr, *tmp;
3078 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
3080 v_list_itr->status =
3081 ice_remove_rule_internal(hw, recp_id, v_list_itr);
3082 if (v_list_itr->status)
3083 return v_list_itr->status;
3089 * ice_clear_vsi_promisc - clear specified promiscuous mode(s) for given VSI
3090 * @hw: pointer to the hardware structure
3091 * @vsi_handle: VSI handle to clear mode
3092 * @promisc_mask: mask of promiscuous config bits to clear
3093 * @vid: VLAN ID to clear VLAN promiscuous
3096 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
3099 struct ice_switch_info *sw = hw->switch_info;
3100 struct ice_fltr_list_entry *fm_entry, *tmp;
3101 struct LIST_HEAD_TYPE remove_list_head;
3102 struct ice_fltr_mgmt_list_entry *itr;
3103 struct LIST_HEAD_TYPE *rule_head;
3104 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3105 enum ice_status status = ICE_SUCCESS;
3108 if (!ice_is_vsi_valid(hw, vsi_handle))
3109 return ICE_ERR_PARAM;
3112 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
3114 recipe_id = ICE_SW_LKUP_PROMISC;
3116 rule_head = &sw->recp_list[recipe_id].filt_rules;
3117 rule_lock = &sw->recp_list[recipe_id].filt_rule_lock;
3119 INIT_LIST_HEAD(&remove_list_head);
3121 ice_acquire_lock(rule_lock);
3122 LIST_FOR_EACH_ENTRY(itr, rule_head,
3123 ice_fltr_mgmt_list_entry, list_entry) {
3124 u8 fltr_promisc_mask = 0;
3126 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3129 fltr_promisc_mask |=
3130 ice_determine_promisc_mask(&itr->fltr_info);
3132 /* Skip if filter is not completely specified by given mask */
3133 if (fltr_promisc_mask & ~promisc_mask)
3136 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
3140 ice_release_lock(rule_lock);
3141 goto free_fltr_list;
3144 ice_release_lock(rule_lock);
3146 status = ice_remove_promisc(hw, recipe_id, &remove_list_head);
3149 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
3150 ice_fltr_list_entry, list_entry) {
3151 LIST_DEL(&fm_entry->list_entry);
3152 ice_free(hw, fm_entry);
3159 * ice_set_vsi_promisc - set given VSI to given promiscuous mode(s)
3160 * @hw: pointer to the hardware structure
3161 * @vsi_handle: VSI handle to configure
3162 * @promisc_mask: mask of promiscuous config bits
3163 * @vid: VLAN ID to set VLAN promiscuous
3166 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, u16 vid)
3168 enum { UCAST_FLTR = 1, MCAST_FLTR, BCAST_FLTR };
3169 struct ice_fltr_list_entry f_list_entry;
3170 struct ice_fltr_info new_fltr;
3171 enum ice_status status = ICE_SUCCESS;
3177 ice_debug(hw, ICE_DBG_TRACE, "ice_set_vsi_promisc\n");
3179 if (!ice_is_vsi_valid(hw, vsi_handle))
3180 return ICE_ERR_PARAM;
3181 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3183 ice_memset(&new_fltr, 0, sizeof(new_fltr), ICE_NONDMA_MEM);
3185 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX)) {
3186 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC_VLAN;
3187 new_fltr.l_data.mac_vlan.vlan_id = vid;
3188 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
3190 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC;
3191 recipe_id = ICE_SW_LKUP_PROMISC;
3194 /* Separate filters must be set for each direction/packet type
3195 * combination, so we will loop over the mask value, store the
3196 * individual type, and clear it out in the input mask as it
3199 while (promisc_mask) {
3205 if (promisc_mask & ICE_PROMISC_UCAST_RX) {
3206 promisc_mask &= ~ICE_PROMISC_UCAST_RX;
3207 pkt_type = UCAST_FLTR;
3208 } else if (promisc_mask & ICE_PROMISC_UCAST_TX) {
3209 promisc_mask &= ~ICE_PROMISC_UCAST_TX;
3210 pkt_type = UCAST_FLTR;
3212 } else if (promisc_mask & ICE_PROMISC_MCAST_RX) {
3213 promisc_mask &= ~ICE_PROMISC_MCAST_RX;
3214 pkt_type = MCAST_FLTR;
3215 } else if (promisc_mask & ICE_PROMISC_MCAST_TX) {
3216 promisc_mask &= ~ICE_PROMISC_MCAST_TX;
3217 pkt_type = MCAST_FLTR;
3219 } else if (promisc_mask & ICE_PROMISC_BCAST_RX) {
3220 promisc_mask &= ~ICE_PROMISC_BCAST_RX;
3221 pkt_type = BCAST_FLTR;
3222 } else if (promisc_mask & ICE_PROMISC_BCAST_TX) {
3223 promisc_mask &= ~ICE_PROMISC_BCAST_TX;
3224 pkt_type = BCAST_FLTR;
3228 /* Check for VLAN promiscuous flag */
3229 if (promisc_mask & ICE_PROMISC_VLAN_RX) {
3230 promisc_mask &= ~ICE_PROMISC_VLAN_RX;
3231 } else if (promisc_mask & ICE_PROMISC_VLAN_TX) {
3232 promisc_mask &= ~ICE_PROMISC_VLAN_TX;
3236 /* Set filter DA based on packet type */
3237 mac_addr = new_fltr.l_data.mac.mac_addr;
3238 if (pkt_type == BCAST_FLTR) {
3239 ice_memset(mac_addr, 0xff, ETH_ALEN, ICE_NONDMA_MEM);
3240 } else if (pkt_type == MCAST_FLTR ||
3241 pkt_type == UCAST_FLTR) {
3242 /* Use the dummy ether header DA */
3243 ice_memcpy(mac_addr, dummy_eth_header, ETH_ALEN,
3244 ICE_NONDMA_TO_NONDMA);
3245 if (pkt_type == MCAST_FLTR)
3246 mac_addr[0] |= 0x1; /* Set multicast bit */
3249 /* Need to reset this to zero for all iterations */
3252 new_fltr.flag |= ICE_FLTR_TX;
3253 new_fltr.src = hw_vsi_id;
3255 new_fltr.flag |= ICE_FLTR_RX;
3256 new_fltr.src = hw->port_info->lport;
3259 new_fltr.fltr_act = ICE_FWD_TO_VSI;
3260 new_fltr.vsi_handle = vsi_handle;
3261 new_fltr.fwd_id.hw_vsi_id = hw_vsi_id;
3262 f_list_entry.fltr_info = new_fltr;
3264 status = ice_add_rule_internal(hw, recipe_id, &f_list_entry);
3265 if (status != ICE_SUCCESS)
3266 goto set_promisc_exit;
3274 * ice_set_vlan_vsi_promisc
3275 * @hw: pointer to the hardware structure
3276 * @vsi_handle: VSI handle to configure
3277 * @promisc_mask: mask of promiscuous config bits
3278 * @rm_vlan_promisc: Clear VLANs VSI promisc mode
3280 * Configure VSI with all associated VLANs to given promiscuous mode(s)
3283 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
3284 bool rm_vlan_promisc)
3286 struct ice_switch_info *sw = hw->switch_info;
3287 struct ice_fltr_list_entry *list_itr, *tmp;
3288 struct LIST_HEAD_TYPE vsi_list_head;
3289 struct LIST_HEAD_TYPE *vlan_head;
3290 struct ice_lock *vlan_lock; /* Lock to protect filter rule list */
3291 enum ice_status status;
3294 INIT_LIST_HEAD(&vsi_list_head);
3295 vlan_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
3296 vlan_head = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rules;
3297 ice_acquire_lock(vlan_lock);
3298 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, vlan_head,
3300 ice_release_lock(vlan_lock);
3302 goto free_fltr_list;
3304 LIST_FOR_EACH_ENTRY(list_itr, &vsi_list_head, ice_fltr_list_entry,
3306 vlan_id = list_itr->fltr_info.l_data.vlan.vlan_id;
3307 if (rm_vlan_promisc)
3308 status = ice_clear_vsi_promisc(hw, vsi_handle,
3309 promisc_mask, vlan_id);
3311 status = ice_set_vsi_promisc(hw, vsi_handle,
3312 promisc_mask, vlan_id);
3318 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, &vsi_list_head,
3319 ice_fltr_list_entry, list_entry) {
3320 LIST_DEL(&list_itr->list_entry);
3321 ice_free(hw, list_itr);
3327 * ice_remove_vsi_lkup_fltr - Remove lookup type filters for a VSI
3328 * @hw: pointer to the hardware structure
3329 * @vsi_handle: VSI handle to remove filters from
3330 * @lkup: switch rule filter lookup type
3333 ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
3334 enum ice_sw_lkup_type lkup)
3336 struct ice_switch_info *sw = hw->switch_info;
3337 struct ice_fltr_list_entry *fm_entry;
3338 struct LIST_HEAD_TYPE remove_list_head;
3339 struct LIST_HEAD_TYPE *rule_head;
3340 struct ice_fltr_list_entry *tmp;
3341 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3342 enum ice_status status;
3344 INIT_LIST_HEAD(&remove_list_head);
3345 rule_lock = &sw->recp_list[lkup].filt_rule_lock;
3346 rule_head = &sw->recp_list[lkup].filt_rules;
3347 ice_acquire_lock(rule_lock);
3348 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, rule_head,
3350 ice_release_lock(rule_lock);
3355 case ICE_SW_LKUP_MAC:
3356 ice_remove_mac(hw, &remove_list_head);
3358 case ICE_SW_LKUP_VLAN:
3359 ice_remove_vlan(hw, &remove_list_head);
3361 case ICE_SW_LKUP_PROMISC:
3362 case ICE_SW_LKUP_PROMISC_VLAN:
3363 ice_remove_promisc(hw, lkup, &remove_list_head);
3365 case ICE_SW_LKUP_MAC_VLAN:
3366 #ifndef NO_MACVLAN_SUPPORT
3367 ice_remove_mac_vlan(hw, &remove_list_head);
3369 ice_debug(hw, ICE_DBG_SW, "MAC VLAN look up is not supported yet\n");
3370 #endif /* !NO_MACVLAN_SUPPORT */
3372 case ICE_SW_LKUP_ETHERTYPE:
3373 case ICE_SW_LKUP_ETHERTYPE_MAC:
3374 case ICE_SW_LKUP_DFLT:
3375 ice_debug(hw, ICE_DBG_SW,
3376 "Remove filters for this lookup type hasn't been implemented yet\n");
3378 case ICE_SW_LKUP_LAST:
3379 ice_debug(hw, ICE_DBG_SW, "Unsupported lookup type\n");
3383 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
3384 ice_fltr_list_entry, list_entry) {
3385 LIST_DEL(&fm_entry->list_entry);
3386 ice_free(hw, fm_entry);
3391 * ice_remove_vsi_fltr - Remove all filters for a VSI
3392 * @hw: pointer to the hardware structure
3393 * @vsi_handle: VSI handle to remove filters from
3395 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle)
3397 ice_debug(hw, ICE_DBG_TRACE, "ice_remove_vsi_fltr\n");
3399 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC);
3400 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC_VLAN);
3401 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC);
3402 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_VLAN);
3403 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_DFLT);
3404 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE);
3405 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE_MAC);
3406 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC_VLAN);
3410 * ice_alloc_res_cntr - allocating resource counter
3411 * @hw: pointer to the hardware structure
3412 * @type: type of resource
3413 * @alloc_shared: if set it is shared else dedicated
3414 * @num_items: number of entries requested for FD resource type
3415 * @counter_id: counter index returned by AQ call
3418 ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
3421 struct ice_aqc_alloc_free_res_elem *buf;
3422 enum ice_status status;
3425 /* Allocate resource */
3426 buf_len = sizeof(*buf);
3427 buf = (struct ice_aqc_alloc_free_res_elem *)
3428 ice_malloc(hw, buf_len);
3430 return ICE_ERR_NO_MEMORY;
3432 buf->num_elems = CPU_TO_LE16(num_items);
3433 buf->res_type = CPU_TO_LE16(((type << ICE_AQC_RES_TYPE_S) &
3434 ICE_AQC_RES_TYPE_M) | alloc_shared);
3436 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
3437 ice_aqc_opc_alloc_res, NULL);
3441 *counter_id = LE16_TO_CPU(buf->elem[0].e.sw_resp);
3449 * ice_free_res_cntr - free resource counter
3450 * @hw: pointer to the hardware structure
3451 * @type: type of resource
3452 * @alloc_shared: if set it is shared else dedicated
3453 * @num_items: number of entries to be freed for FD resource type
3454 * @counter_id: counter ID resource which needs to be freed
3457 ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
3460 struct ice_aqc_alloc_free_res_elem *buf;
3461 enum ice_status status;
3465 buf_len = sizeof(*buf);
3466 buf = (struct ice_aqc_alloc_free_res_elem *)
3467 ice_malloc(hw, buf_len);
3469 return ICE_ERR_NO_MEMORY;
3471 buf->num_elems = CPU_TO_LE16(num_items);
3472 buf->res_type = CPU_TO_LE16(((type << ICE_AQC_RES_TYPE_S) &
3473 ICE_AQC_RES_TYPE_M) | alloc_shared);
3474 buf->elem[0].e.sw_resp = CPU_TO_LE16(counter_id);
3476 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
3477 ice_aqc_opc_free_res, NULL);
3479 ice_debug(hw, ICE_DBG_SW,
3480 "counter resource could not be freed\n");
3487 * ice_alloc_vlan_res_counter - obtain counter resource for VLAN type
3488 * @hw: pointer to the hardware structure
3489 * @counter_id: returns counter index
3491 enum ice_status ice_alloc_vlan_res_counter(struct ice_hw *hw, u16 *counter_id)
3493 return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_VLAN_COUNTER,
3494 ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1,
3499 * ice_free_vlan_res_counter - Free counter resource for VLAN type
3500 * @hw: pointer to the hardware structure
3501 * @counter_id: counter index to be freed
3503 enum ice_status ice_free_vlan_res_counter(struct ice_hw *hw, u16 counter_id)
3505 return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_VLAN_COUNTER,
3506 ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1,
3511 * ice_alloc_res_lg_act - add large action resource
3512 * @hw: pointer to the hardware structure
3513 * @l_id: large action ID to fill it in
3514 * @num_acts: number of actions to hold with a large action entry
3516 static enum ice_status
3517 ice_alloc_res_lg_act(struct ice_hw *hw, u16 *l_id, u16 num_acts)
3519 struct ice_aqc_alloc_free_res_elem *sw_buf;
3520 enum ice_status status;
3523 if (num_acts > ICE_MAX_LG_ACT || num_acts == 0)
3524 return ICE_ERR_PARAM;
3526 /* Allocate resource for large action */
3527 buf_len = sizeof(*sw_buf);
3528 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
3529 ice_malloc(hw, buf_len);
3531 return ICE_ERR_NO_MEMORY;
3533 sw_buf->num_elems = CPU_TO_LE16(1);
3535 /* If num_acts is 1, use ICE_AQC_RES_TYPE_WIDE_TABLE_1.
3536 * If num_acts is 2, use ICE_AQC_RES_TYPE_WIDE_TABLE_3.
3537 * If num_acts is greater than 2, then use
3538 * ICE_AQC_RES_TYPE_WIDE_TABLE_4.
3539 * The num_acts cannot exceed 4. This was ensured at the
3540 * beginning of the function.
3543 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_1);
3544 else if (num_acts == 2)
3545 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_2);
3547 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_4);
3549 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
3550 ice_aqc_opc_alloc_res, NULL);
3552 *l_id = LE16_TO_CPU(sw_buf->elem[0].e.sw_resp);
3554 ice_free(hw, sw_buf);
3559 * ice_add_mac_with_sw_marker - add filter with sw marker
3560 * @hw: pointer to the hardware structure
3561 * @f_info: filter info structure containing the MAC filter information
3562 * @sw_marker: sw marker to tag the Rx descriptor with
3565 ice_add_mac_with_sw_marker(struct ice_hw *hw, struct ice_fltr_info *f_info,
3568 struct ice_switch_info *sw = hw->switch_info;
3569 struct ice_fltr_mgmt_list_entry *m_entry;
3570 struct ice_fltr_list_entry fl_info;
3571 struct LIST_HEAD_TYPE l_head;
3572 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3573 enum ice_status ret;
3577 if (f_info->fltr_act != ICE_FWD_TO_VSI)
3578 return ICE_ERR_PARAM;
3580 if (f_info->lkup_type != ICE_SW_LKUP_MAC)
3581 return ICE_ERR_PARAM;
3583 if (sw_marker == ICE_INVAL_SW_MARKER_ID)
3584 return ICE_ERR_PARAM;
3586 if (!ice_is_vsi_valid(hw, f_info->vsi_handle))
3587 return ICE_ERR_PARAM;
3588 f_info->fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, f_info->vsi_handle);
3590 /* Add filter if it doesn't exist so then the adding of large
3591 * action always results in update
3594 INIT_LIST_HEAD(&l_head);
3595 fl_info.fltr_info = *f_info;
3596 LIST_ADD(&fl_info.list_entry, &l_head);
3598 entry_exists = false;
3599 ret = ice_add_mac(hw, &l_head);
3600 if (ret == ICE_ERR_ALREADY_EXISTS)
3601 entry_exists = true;
3605 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
3606 ice_acquire_lock(rule_lock);
3607 /* Get the book keeping entry for the filter */
3608 m_entry = ice_find_rule_entry(hw, ICE_SW_LKUP_MAC, f_info);
3612 /* If counter action was enabled for this rule then don't enable
3613 * sw marker large action
3615 if (m_entry->counter_index != ICE_INVAL_COUNTER_ID) {
3616 ret = ICE_ERR_PARAM;
3620 /* if same marker was added before */
3621 if (m_entry->sw_marker_id == sw_marker) {
3622 ret = ICE_ERR_ALREADY_EXISTS;
3626 /* Allocate a hardware table entry to hold large act. Three actions
3627 * for marker based large action
3629 ret = ice_alloc_res_lg_act(hw, &lg_act_id, 3);
3633 if (lg_act_id == ICE_INVAL_LG_ACT_INDEX)
3636 /* Update the switch rule to add the marker action */
3637 ret = ice_add_marker_act(hw, m_entry, sw_marker, lg_act_id);
3639 ice_release_lock(rule_lock);
3644 ice_release_lock(rule_lock);
3645 /* only remove entry if it did not exist previously */
3647 ret = ice_remove_mac(hw, &l_head);
3653 * ice_add_mac_with_counter - add filter with counter enabled
3654 * @hw: pointer to the hardware structure
3655 * @f_info: pointer to filter info structure containing the MAC filter
3659 ice_add_mac_with_counter(struct ice_hw *hw, struct ice_fltr_info *f_info)
3661 struct ice_switch_info *sw = hw->switch_info;
3662 struct ice_fltr_mgmt_list_entry *m_entry;
3663 struct ice_fltr_list_entry fl_info;
3664 struct LIST_HEAD_TYPE l_head;
3665 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3666 enum ice_status ret;
3671 if (f_info->fltr_act != ICE_FWD_TO_VSI)
3672 return ICE_ERR_PARAM;
3674 if (f_info->lkup_type != ICE_SW_LKUP_MAC)
3675 return ICE_ERR_PARAM;
3677 if (!ice_is_vsi_valid(hw, f_info->vsi_handle))
3678 return ICE_ERR_PARAM;
3679 f_info->fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, f_info->vsi_handle);
3681 entry_exist = false;
3683 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
3685 /* Add filter if it doesn't exist so then the adding of large
3686 * action always results in update
3688 INIT_LIST_HEAD(&l_head);
3690 fl_info.fltr_info = *f_info;
3691 LIST_ADD(&fl_info.list_entry, &l_head);
3693 ret = ice_add_mac(hw, &l_head);
3694 if (ret == ICE_ERR_ALREADY_EXISTS)
3699 ice_acquire_lock(rule_lock);
3700 m_entry = ice_find_rule_entry(hw, ICE_SW_LKUP_MAC, f_info);
3702 ret = ICE_ERR_BAD_PTR;
3706 /* Don't enable counter for a filter for which sw marker was enabled */
3707 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID) {
3708 ret = ICE_ERR_PARAM;
3712 /* If a counter was already enabled then don't need to add again */
3713 if (m_entry->counter_index != ICE_INVAL_COUNTER_ID) {
3714 ret = ICE_ERR_ALREADY_EXISTS;
3718 /* Allocate a hardware table entry to VLAN counter */
3719 ret = ice_alloc_vlan_res_counter(hw, &counter_id);
3723 /* Allocate a hardware table entry to hold large act. Two actions for
3724 * counter based large action
3726 ret = ice_alloc_res_lg_act(hw, &lg_act_id, 2);
3730 if (lg_act_id == ICE_INVAL_LG_ACT_INDEX)
3733 /* Update the switch rule to add the counter action */
3734 ret = ice_add_counter_act(hw, m_entry, counter_id, lg_act_id);
3736 ice_release_lock(rule_lock);
3741 ice_release_lock(rule_lock);
3742 /* only remove entry if it did not exist previously */
3744 ret = ice_remove_mac(hw, &l_head);
3750 * ice_replay_vsi_fltr - Replay filters for requested VSI
3751 * @hw: pointer to the hardware structure
3752 * @vsi_handle: driver VSI handle
3753 * @recp_id: Recipe ID for which rules need to be replayed
3754 * @list_head: list for which filters need to be replayed
3756 * Replays the filter of recipe recp_id for a VSI represented via vsi_handle.
3757 * It is required to pass valid VSI handle.
3759 static enum ice_status
3760 ice_replay_vsi_fltr(struct ice_hw *hw, u16 vsi_handle, u8 recp_id,
3761 struct LIST_HEAD_TYPE *list_head)
3763 struct ice_fltr_mgmt_list_entry *itr;
3764 enum ice_status status = ICE_SUCCESS;
3767 if (LIST_EMPTY(list_head))
3769 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3771 LIST_FOR_EACH_ENTRY(itr, list_head, ice_fltr_mgmt_list_entry,
3773 struct ice_fltr_list_entry f_entry;
3775 f_entry.fltr_info = itr->fltr_info;
3776 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN &&
3777 itr->fltr_info.vsi_handle == vsi_handle) {
3778 /* update the src in case it is VSI num */
3779 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
3780 f_entry.fltr_info.src = hw_vsi_id;
3781 status = ice_add_rule_internal(hw, recp_id, &f_entry);
3782 if (status != ICE_SUCCESS)
3786 if (!itr->vsi_list_info ||
3787 !ice_is_bit_set(itr->vsi_list_info->vsi_map, vsi_handle))
3789 /* Clearing it so that the logic can add it back */
3790 ice_clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
3791 f_entry.fltr_info.vsi_handle = vsi_handle;
3792 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
3793 /* update the src in case it is VSI num */
3794 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
3795 f_entry.fltr_info.src = hw_vsi_id;
3796 if (recp_id == ICE_SW_LKUP_VLAN)
3797 status = ice_add_vlan_internal(hw, &f_entry);
3799 status = ice_add_rule_internal(hw, recp_id, &f_entry);
3800 if (status != ICE_SUCCESS)
3809 * ice_replay_vsi_all_fltr - replay all filters stored in bookkeeping lists
3810 * @hw: pointer to the hardware structure
3811 * @vsi_handle: driver VSI handle
3813 * Replays filters for requested VSI via vsi_handle.
3815 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
3817 struct ice_switch_info *sw = hw->switch_info;
3818 enum ice_status status = ICE_SUCCESS;
3821 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
3822 /* Update the default recipe lines and ones that were created */
3823 if (i < ICE_MAX_NUM_RECIPES || sw->recp_list[i].recp_created) {
3824 struct LIST_HEAD_TYPE *head;
3826 head = &sw->recp_list[i].filt_replay_rules;
3827 if (!sw->recp_list[i].adv_rule)
3828 status = ice_replay_vsi_fltr(hw, vsi_handle, i,
3830 if (status != ICE_SUCCESS)
3838 * ice_rm_all_sw_replay_rule_info - deletes filter replay rules
3839 * @hw: pointer to the HW struct
3841 * Deletes the filter replay rules.
3843 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
3845 struct ice_switch_info *sw = hw->switch_info;
3851 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
3852 if (!LIST_EMPTY(&sw->recp_list[i].filt_replay_rules)) {
3853 struct LIST_HEAD_TYPE *l_head;
3855 l_head = &sw->recp_list[i].filt_replay_rules;
3856 if (!sw->recp_list[i].adv_rule)
3857 ice_rem_sw_rule_info(hw, l_head);