1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2020, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include "ice_switch.h"
34 #include "ice_flex_type.h"
37 #define ICE_ETH_DA_OFFSET 0
38 #define ICE_ETH_ETHTYPE_OFFSET 12
39 #define ICE_ETH_VLAN_TCI_OFFSET 14
40 #define ICE_MAX_VLAN_ID 0xFFF
42 /* Dummy ethernet header needed in the ice_aqc_sw_rules_elem
43 * struct to configure any switch filter rules.
44 * {DA (6 bytes), SA(6 bytes),
45 * Ether type (2 bytes for header without VLAN tag) OR
46 * VLAN tag (4 bytes for header with VLAN tag) }
48 * Word on Hardcoded values
49 * byte 0 = 0x2: to identify it as locally administered DA MAC
50 * byte 6 = 0x2: to identify it as locally administered SA MAC
51 * byte 12 = 0x81 & byte 13 = 0x00:
52 * In case of VLAN filter first two bytes defines ether type (0x8100)
53 * and remaining two bytes are placeholder for programming a given VLAN ID
54 * In case of Ether type filter it is treated as header without VLAN tag
55 * and byte 12 and 13 is used to program a given Ether type instead
57 #define DUMMY_ETH_HDR_LEN 16
58 static const u8 dummy_eth_header[DUMMY_ETH_HDR_LEN] = { 0x2, 0, 0, 0, 0, 0,
62 #define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
63 (sizeof(struct ice_aqc_sw_rules_elem) - \
64 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
65 sizeof(struct ice_sw_rule_lkup_rx_tx) + DUMMY_ETH_HDR_LEN - 1)
66 #define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
67 (sizeof(struct ice_aqc_sw_rules_elem) - \
68 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
69 sizeof(struct ice_sw_rule_lkup_rx_tx) - 1)
70 #define ICE_SW_RULE_LG_ACT_SIZE(n) \
71 (sizeof(struct ice_aqc_sw_rules_elem) - \
72 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
73 sizeof(struct ice_sw_rule_lg_act) - \
74 sizeof(((struct ice_sw_rule_lg_act *)0)->act) + \
75 ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act)))
76 #define ICE_SW_RULE_VSI_LIST_SIZE(n) \
77 (sizeof(struct ice_aqc_sw_rules_elem) - \
78 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
79 sizeof(struct ice_sw_rule_vsi_list) - \
80 sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi) + \
81 ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi)))
84 * ice_init_def_sw_recp - initialize the recipe book keeping tables
85 * @hw: pointer to the HW struct
86 * @recp_list: pointer to sw recipe list
88 * Allocate memory for the entire recipe table and initialize the structures/
89 * entries corresponding to basic recipes.
92 ice_init_def_sw_recp(struct ice_hw *hw, struct ice_sw_recipe **recp_list)
94 struct ice_sw_recipe *recps;
97 recps = (struct ice_sw_recipe *)
98 ice_calloc(hw, ICE_MAX_NUM_RECIPES, sizeof(*recps));
100 return ICE_ERR_NO_MEMORY;
102 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
103 recps[i].root_rid = i;
104 INIT_LIST_HEAD(&recps[i].filt_rules);
105 INIT_LIST_HEAD(&recps[i].filt_replay_rules);
106 INIT_LIST_HEAD(&recps[i].rg_list);
107 ice_init_lock(&recps[i].filt_rule_lock);
116 * ice_aq_get_sw_cfg - get switch configuration
117 * @hw: pointer to the hardware structure
118 * @buf: pointer to the result buffer
119 * @buf_size: length of the buffer available for response
120 * @req_desc: pointer to requested descriptor
121 * @num_elems: pointer to number of elements
122 * @cd: pointer to command details structure or NULL
124 * Get switch configuration (0x0200) to be placed in 'buff'.
125 * This admin command returns information such as initial VSI/port number
126 * and switch ID it belongs to.
128 * NOTE: *req_desc is both an input/output parameter.
129 * The caller of this function first calls this function with *request_desc set
130 * to 0. If the response from f/w has *req_desc set to 0, all the switch
131 * configuration information has been returned; if non-zero (meaning not all
132 * the information was returned), the caller should call this function again
133 * with *req_desc set to the previous value returned by f/w to get the
134 * next block of switch configuration information.
136 * *num_elems is output only parameter. This reflects the number of elements
137 * in response buffer. The caller of this function to use *num_elems while
138 * parsing the response buffer.
140 static enum ice_status
141 ice_aq_get_sw_cfg(struct ice_hw *hw, struct ice_aqc_get_sw_cfg_resp *buf,
142 u16 buf_size, u16 *req_desc, u16 *num_elems,
143 struct ice_sq_cd *cd)
145 struct ice_aqc_get_sw_cfg *cmd;
146 enum ice_status status;
147 struct ice_aq_desc desc;
149 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_sw_cfg);
150 cmd = &desc.params.get_sw_conf;
151 cmd->element = CPU_TO_LE16(*req_desc);
153 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
155 *req_desc = LE16_TO_CPU(cmd->element);
156 *num_elems = LE16_TO_CPU(cmd->num_elems);
163 * ice_alloc_sw - allocate resources specific to switch
164 * @hw: pointer to the HW struct
165 * @ena_stats: true to turn on VEB stats
166 * @shared_res: true for shared resource, false for dedicated resource
167 * @sw_id: switch ID returned
168 * @counter_id: VEB counter ID returned
170 * allocates switch resources (SWID and VEB counter) (0x0208)
173 ice_alloc_sw(struct ice_hw *hw, bool ena_stats, bool shared_res, u16 *sw_id,
176 struct ice_aqc_alloc_free_res_elem *sw_buf;
177 struct ice_aqc_res_elem *sw_ele;
178 enum ice_status status;
181 buf_len = sizeof(*sw_buf);
182 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
183 ice_malloc(hw, buf_len);
185 return ICE_ERR_NO_MEMORY;
187 /* Prepare buffer for switch ID.
188 * The number of resource entries in buffer is passed as 1 since only a
189 * single switch/VEB instance is allocated, and hence a single sw_id
192 sw_buf->num_elems = CPU_TO_LE16(1);
194 CPU_TO_LE16(ICE_AQC_RES_TYPE_SWID |
195 (shared_res ? ICE_AQC_RES_TYPE_FLAG_SHARED :
196 ICE_AQC_RES_TYPE_FLAG_DEDICATED));
198 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
199 ice_aqc_opc_alloc_res, NULL);
202 goto ice_alloc_sw_exit;
204 sw_ele = &sw_buf->elem[0];
205 *sw_id = LE16_TO_CPU(sw_ele->e.sw_resp);
208 /* Prepare buffer for VEB Counter */
209 enum ice_adminq_opc opc = ice_aqc_opc_alloc_res;
210 struct ice_aqc_alloc_free_res_elem *counter_buf;
211 struct ice_aqc_res_elem *counter_ele;
213 counter_buf = (struct ice_aqc_alloc_free_res_elem *)
214 ice_malloc(hw, buf_len);
216 status = ICE_ERR_NO_MEMORY;
217 goto ice_alloc_sw_exit;
220 /* The number of resource entries in buffer is passed as 1 since
221 * only a single switch/VEB instance is allocated, and hence a
222 * single VEB counter is requested.
224 counter_buf->num_elems = CPU_TO_LE16(1);
225 counter_buf->res_type =
226 CPU_TO_LE16(ICE_AQC_RES_TYPE_VEB_COUNTER |
227 ICE_AQC_RES_TYPE_FLAG_DEDICATED);
228 status = ice_aq_alloc_free_res(hw, 1, counter_buf, buf_len,
232 ice_free(hw, counter_buf);
233 goto ice_alloc_sw_exit;
235 counter_ele = &counter_buf->elem[0];
236 *counter_id = LE16_TO_CPU(counter_ele->e.sw_resp);
237 ice_free(hw, counter_buf);
241 ice_free(hw, sw_buf);
246 * ice_free_sw - free resources specific to switch
247 * @hw: pointer to the HW struct
248 * @sw_id: switch ID returned
249 * @counter_id: VEB counter ID returned
251 * free switch resources (SWID and VEB counter) (0x0209)
253 * NOTE: This function frees multiple resources. It continues
254 * releasing other resources even after it encounters error.
255 * The error code returned is the last error it encountered.
257 enum ice_status ice_free_sw(struct ice_hw *hw, u16 sw_id, u16 counter_id)
259 struct ice_aqc_alloc_free_res_elem *sw_buf, *counter_buf;
260 enum ice_status status, ret_status;
263 buf_len = sizeof(*sw_buf);
264 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
265 ice_malloc(hw, buf_len);
267 return ICE_ERR_NO_MEMORY;
269 /* Prepare buffer to free for switch ID res.
270 * The number of resource entries in buffer is passed as 1 since only a
271 * single switch/VEB instance is freed, and hence a single sw_id
274 sw_buf->num_elems = CPU_TO_LE16(1);
275 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_SWID);
276 sw_buf->elem[0].e.sw_resp = CPU_TO_LE16(sw_id);
278 ret_status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
279 ice_aqc_opc_free_res, NULL);
282 ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
284 /* Prepare buffer to free for VEB Counter resource */
285 counter_buf = (struct ice_aqc_alloc_free_res_elem *)
286 ice_malloc(hw, buf_len);
288 ice_free(hw, sw_buf);
289 return ICE_ERR_NO_MEMORY;
292 /* The number of resource entries in buffer is passed as 1 since only a
293 * single switch/VEB instance is freed, and hence a single VEB counter
296 counter_buf->num_elems = CPU_TO_LE16(1);
297 counter_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_VEB_COUNTER);
298 counter_buf->elem[0].e.sw_resp = CPU_TO_LE16(counter_id);
300 status = ice_aq_alloc_free_res(hw, 1, counter_buf, buf_len,
301 ice_aqc_opc_free_res, NULL);
303 ice_debug(hw, ICE_DBG_SW,
304 "VEB counter resource could not be freed\n");
308 ice_free(hw, counter_buf);
309 ice_free(hw, sw_buf);
315 * @hw: pointer to the HW struct
316 * @vsi_ctx: pointer to a VSI context struct
317 * @cd: pointer to command details structure or NULL
319 * Add a VSI context to the hardware (0x0210)
322 ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
323 struct ice_sq_cd *cd)
325 struct ice_aqc_add_update_free_vsi_resp *res;
326 struct ice_aqc_add_get_update_free_vsi *cmd;
327 struct ice_aq_desc desc;
328 enum ice_status status;
330 cmd = &desc.params.vsi_cmd;
331 res = &desc.params.add_update_free_vsi_res;
333 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_vsi);
335 if (!vsi_ctx->alloc_from_pool)
336 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num |
337 ICE_AQ_VSI_IS_VALID);
338 cmd->vf_id = vsi_ctx->vf_num;
340 cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
342 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
344 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
345 sizeof(vsi_ctx->info), cd);
348 vsi_ctx->vsi_num = LE16_TO_CPU(res->vsi_num) & ICE_AQ_VSI_NUM_M;
349 vsi_ctx->vsis_allocd = LE16_TO_CPU(res->vsi_used);
350 vsi_ctx->vsis_unallocated = LE16_TO_CPU(res->vsi_free);
358 * @hw: pointer to the HW struct
359 * @vsi_ctx: pointer to a VSI context struct
360 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
361 * @cd: pointer to command details structure or NULL
363 * Free VSI context info from hardware (0x0213)
366 ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
367 bool keep_vsi_alloc, struct ice_sq_cd *cd)
369 struct ice_aqc_add_update_free_vsi_resp *resp;
370 struct ice_aqc_add_get_update_free_vsi *cmd;
371 struct ice_aq_desc desc;
372 enum ice_status status;
374 cmd = &desc.params.vsi_cmd;
375 resp = &desc.params.add_update_free_vsi_res;
377 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_free_vsi);
379 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
381 cmd->cmd_flags = CPU_TO_LE16(ICE_AQ_VSI_KEEP_ALLOC);
383 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
385 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
386 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
394 * @hw: pointer to the HW struct
395 * @vsi_ctx: pointer to a VSI context struct
396 * @cd: pointer to command details structure or NULL
398 * Update VSI context in the hardware (0x0211)
401 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
402 struct ice_sq_cd *cd)
404 struct ice_aqc_add_update_free_vsi_resp *resp;
405 struct ice_aqc_add_get_update_free_vsi *cmd;
406 struct ice_aq_desc desc;
407 enum ice_status status;
409 cmd = &desc.params.vsi_cmd;
410 resp = &desc.params.add_update_free_vsi_res;
412 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_vsi);
414 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
416 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
418 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
419 sizeof(vsi_ctx->info), cd);
422 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
423 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
430 * ice_is_vsi_valid - check whether the VSI is valid or not
431 * @hw: pointer to the HW struct
432 * @vsi_handle: VSI handle
434 * check whether the VSI is valid or not
436 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle)
438 return vsi_handle < ICE_MAX_VSI && hw->vsi_ctx[vsi_handle];
442 * ice_get_hw_vsi_num - return the HW VSI number
443 * @hw: pointer to the HW struct
444 * @vsi_handle: VSI handle
446 * return the HW VSI number
447 * Caution: call this function only if VSI is valid (ice_is_vsi_valid)
449 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle)
451 return hw->vsi_ctx[vsi_handle]->vsi_num;
455 * ice_get_vsi_ctx - return the VSI context entry for a given VSI handle
456 * @hw: pointer to the HW struct
457 * @vsi_handle: VSI handle
459 * return the VSI context entry for a given VSI handle
461 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
463 return (vsi_handle >= ICE_MAX_VSI) ? NULL : hw->vsi_ctx[vsi_handle];
467 * ice_save_vsi_ctx - save the VSI context for a given VSI handle
468 * @hw: pointer to the HW struct
469 * @vsi_handle: VSI handle
470 * @vsi: VSI context pointer
472 * save the VSI context entry for a given VSI handle
475 ice_save_vsi_ctx(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi)
477 hw->vsi_ctx[vsi_handle] = vsi;
481 * ice_clear_vsi_q_ctx - clear VSI queue contexts for all TCs
482 * @hw: pointer to the HW struct
483 * @vsi_handle: VSI handle
485 static void ice_clear_vsi_q_ctx(struct ice_hw *hw, u16 vsi_handle)
487 struct ice_vsi_ctx *vsi;
490 vsi = ice_get_vsi_ctx(hw, vsi_handle);
493 ice_for_each_traffic_class(i) {
494 if (vsi->lan_q_ctx[i]) {
495 ice_free(hw, vsi->lan_q_ctx[i]);
496 vsi->lan_q_ctx[i] = NULL;
502 * ice_clear_vsi_ctx - clear the VSI context entry
503 * @hw: pointer to the HW struct
504 * @vsi_handle: VSI handle
506 * clear the VSI context entry
508 static void ice_clear_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
510 struct ice_vsi_ctx *vsi;
512 vsi = ice_get_vsi_ctx(hw, vsi_handle);
514 ice_clear_vsi_q_ctx(hw, vsi_handle);
516 hw->vsi_ctx[vsi_handle] = NULL;
521 * ice_clear_all_vsi_ctx - clear all the VSI context entries
522 * @hw: pointer to the HW struct
524 void ice_clear_all_vsi_ctx(struct ice_hw *hw)
528 for (i = 0; i < ICE_MAX_VSI; i++)
529 ice_clear_vsi_ctx(hw, i);
533 * ice_add_vsi - add VSI context to the hardware and VSI handle list
534 * @hw: pointer to the HW struct
535 * @vsi_handle: unique VSI handle provided by drivers
536 * @vsi_ctx: pointer to a VSI context struct
537 * @cd: pointer to command details structure or NULL
539 * Add a VSI context to the hardware also add it into the VSI handle list.
540 * If this function gets called after reset for existing VSIs then update
541 * with the new HW VSI number in the corresponding VSI handle list entry.
544 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
545 struct ice_sq_cd *cd)
547 struct ice_vsi_ctx *tmp_vsi_ctx;
548 enum ice_status status;
550 if (vsi_handle >= ICE_MAX_VSI)
551 return ICE_ERR_PARAM;
552 status = ice_aq_add_vsi(hw, vsi_ctx, cd);
555 tmp_vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
557 /* Create a new VSI context */
558 tmp_vsi_ctx = (struct ice_vsi_ctx *)
559 ice_malloc(hw, sizeof(*tmp_vsi_ctx));
561 ice_aq_free_vsi(hw, vsi_ctx, false, cd);
562 return ICE_ERR_NO_MEMORY;
564 *tmp_vsi_ctx = *vsi_ctx;
566 ice_save_vsi_ctx(hw, vsi_handle, tmp_vsi_ctx);
568 /* update with new HW VSI num */
569 tmp_vsi_ctx->vsi_num = vsi_ctx->vsi_num;
576 * ice_free_vsi- free VSI context from hardware and VSI handle list
577 * @hw: pointer to the HW struct
578 * @vsi_handle: unique VSI handle
579 * @vsi_ctx: pointer to a VSI context struct
580 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
581 * @cd: pointer to command details structure or NULL
583 * Free VSI context info from hardware as well as from VSI handle list
586 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
587 bool keep_vsi_alloc, struct ice_sq_cd *cd)
589 enum ice_status status;
591 if (!ice_is_vsi_valid(hw, vsi_handle))
592 return ICE_ERR_PARAM;
593 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
594 status = ice_aq_free_vsi(hw, vsi_ctx, keep_vsi_alloc, cd);
596 ice_clear_vsi_ctx(hw, vsi_handle);
602 * @hw: pointer to the HW struct
603 * @vsi_handle: unique VSI handle
604 * @vsi_ctx: pointer to a VSI context struct
605 * @cd: pointer to command details structure or NULL
607 * Update VSI context in the hardware
610 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
611 struct ice_sq_cd *cd)
613 if (!ice_is_vsi_valid(hw, vsi_handle))
614 return ICE_ERR_PARAM;
615 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
616 return ice_aq_update_vsi(hw, vsi_ctx, cd);
620 * ice_aq_get_vsi_params
621 * @hw: pointer to the HW struct
622 * @vsi_ctx: pointer to a VSI context struct
623 * @cd: pointer to command details structure or NULL
625 * Get VSI context info from hardware (0x0212)
628 ice_aq_get_vsi_params(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
629 struct ice_sq_cd *cd)
631 struct ice_aqc_add_get_update_free_vsi *cmd;
632 struct ice_aqc_get_vsi_resp *resp;
633 struct ice_aq_desc desc;
634 enum ice_status status;
636 cmd = &desc.params.vsi_cmd;
637 resp = &desc.params.get_vsi_resp;
639 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_vsi_params);
641 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
643 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
644 sizeof(vsi_ctx->info), cd);
646 vsi_ctx->vsi_num = LE16_TO_CPU(resp->vsi_num) &
648 vsi_ctx->vf_num = resp->vf_id;
649 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
650 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
657 * ice_aq_add_update_mir_rule - add/update a mirror rule
658 * @hw: pointer to the HW struct
659 * @rule_type: Rule Type
660 * @dest_vsi: VSI number to which packets will be mirrored
661 * @count: length of the list
662 * @mr_buf: buffer for list of mirrored VSI numbers
663 * @cd: pointer to command details structure or NULL
666 * Add/Update Mirror Rule (0x260).
669 ice_aq_add_update_mir_rule(struct ice_hw *hw, u16 rule_type, u16 dest_vsi,
670 u16 count, struct ice_mir_rule_buf *mr_buf,
671 struct ice_sq_cd *cd, u16 *rule_id)
673 struct ice_aqc_add_update_mir_rule *cmd;
674 struct ice_aq_desc desc;
675 enum ice_status status;
676 __le16 *mr_list = NULL;
680 case ICE_AQC_RULE_TYPE_VPORT_INGRESS:
681 case ICE_AQC_RULE_TYPE_VPORT_EGRESS:
682 /* Make sure count and mr_buf are set for these rule_types */
683 if (!(count && mr_buf))
684 return ICE_ERR_PARAM;
686 buf_size = count * sizeof(__le16);
687 mr_list = (_FORCE_ __le16 *)ice_malloc(hw, buf_size);
689 return ICE_ERR_NO_MEMORY;
691 case ICE_AQC_RULE_TYPE_PPORT_INGRESS:
692 case ICE_AQC_RULE_TYPE_PPORT_EGRESS:
693 /* Make sure count and mr_buf are not set for these
697 return ICE_ERR_PARAM;
700 ice_debug(hw, ICE_DBG_SW,
701 "Error due to unsupported rule_type %u\n", rule_type);
702 return ICE_ERR_OUT_OF_RANGE;
705 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_update_mir_rule);
707 /* Pre-process 'mr_buf' items for add/update of virtual port
708 * ingress/egress mirroring (but not physical port ingress/egress
714 for (i = 0; i < count; i++) {
717 id = mr_buf[i].vsi_idx & ICE_AQC_RULE_MIRRORED_VSI_M;
719 /* Validate specified VSI number, make sure it is less
720 * than ICE_MAX_VSI, if not return with error.
722 if (id >= ICE_MAX_VSI) {
723 ice_debug(hw, ICE_DBG_SW,
724 "Error VSI index (%u) out-of-range\n",
726 ice_free(hw, mr_list);
727 return ICE_ERR_OUT_OF_RANGE;
730 /* add VSI to mirror rule */
733 CPU_TO_LE16(id | ICE_AQC_RULE_ACT_M);
734 else /* remove VSI from mirror rule */
735 mr_list[i] = CPU_TO_LE16(id);
739 cmd = &desc.params.add_update_rule;
740 if ((*rule_id) != ICE_INVAL_MIRROR_RULE_ID)
741 cmd->rule_id = CPU_TO_LE16(((*rule_id) & ICE_AQC_RULE_ID_M) |
742 ICE_AQC_RULE_ID_VALID_M);
743 cmd->rule_type = CPU_TO_LE16(rule_type & ICE_AQC_RULE_TYPE_M);
744 cmd->num_entries = CPU_TO_LE16(count);
745 cmd->dest = CPU_TO_LE16(dest_vsi);
747 status = ice_aq_send_cmd(hw, &desc, mr_list, buf_size, cd);
749 *rule_id = LE16_TO_CPU(cmd->rule_id) & ICE_AQC_RULE_ID_M;
751 ice_free(hw, mr_list);
757 * ice_aq_delete_mir_rule - delete a mirror rule
758 * @hw: pointer to the HW struct
759 * @rule_id: Mirror rule ID (to be deleted)
760 * @keep_allocd: if set, the VSI stays part of the PF allocated res,
761 * otherwise it is returned to the shared pool
762 * @cd: pointer to command details structure or NULL
764 * Delete Mirror Rule (0x261).
767 ice_aq_delete_mir_rule(struct ice_hw *hw, u16 rule_id, bool keep_allocd,
768 struct ice_sq_cd *cd)
770 struct ice_aqc_delete_mir_rule *cmd;
771 struct ice_aq_desc desc;
773 /* rule_id should be in the range 0...63 */
774 if (rule_id >= ICE_MAX_NUM_MIRROR_RULES)
775 return ICE_ERR_OUT_OF_RANGE;
777 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_del_mir_rule);
779 cmd = &desc.params.del_rule;
780 rule_id |= ICE_AQC_RULE_ID_VALID_M;
781 cmd->rule_id = CPU_TO_LE16(rule_id);
784 cmd->flags = CPU_TO_LE16(ICE_AQC_FLAG_KEEP_ALLOCD_M);
786 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
790 * ice_aq_alloc_free_vsi_list
791 * @hw: pointer to the HW struct
792 * @vsi_list_id: VSI list ID returned or used for lookup
793 * @lkup_type: switch rule filter lookup type
794 * @opc: switch rules population command type - pass in the command opcode
796 * allocates or free a VSI list resource
798 static enum ice_status
799 ice_aq_alloc_free_vsi_list(struct ice_hw *hw, u16 *vsi_list_id,
800 enum ice_sw_lkup_type lkup_type,
801 enum ice_adminq_opc opc)
803 struct ice_aqc_alloc_free_res_elem *sw_buf;
804 struct ice_aqc_res_elem *vsi_ele;
805 enum ice_status status;
808 buf_len = sizeof(*sw_buf);
809 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
810 ice_malloc(hw, buf_len);
812 return ICE_ERR_NO_MEMORY;
813 sw_buf->num_elems = CPU_TO_LE16(1);
815 if (lkup_type == ICE_SW_LKUP_MAC ||
816 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
817 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
818 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
819 lkup_type == ICE_SW_LKUP_PROMISC ||
820 lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
821 lkup_type == ICE_SW_LKUP_LAST) {
822 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_REP);
823 } else if (lkup_type == ICE_SW_LKUP_VLAN) {
825 CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_PRUNE);
827 status = ICE_ERR_PARAM;
828 goto ice_aq_alloc_free_vsi_list_exit;
831 if (opc == ice_aqc_opc_free_res)
832 sw_buf->elem[0].e.sw_resp = CPU_TO_LE16(*vsi_list_id);
834 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len, opc, NULL);
836 goto ice_aq_alloc_free_vsi_list_exit;
838 if (opc == ice_aqc_opc_alloc_res) {
839 vsi_ele = &sw_buf->elem[0];
840 *vsi_list_id = LE16_TO_CPU(vsi_ele->e.sw_resp);
843 ice_aq_alloc_free_vsi_list_exit:
844 ice_free(hw, sw_buf);
849 * ice_aq_set_storm_ctrl - Sets storm control configuration
850 * @hw: pointer to the HW struct
851 * @bcast_thresh: represents the upper threshold for broadcast storm control
852 * @mcast_thresh: represents the upper threshold for multicast storm control
853 * @ctl_bitmask: storm control control knobs
855 * Sets the storm control configuration (0x0280)
858 ice_aq_set_storm_ctrl(struct ice_hw *hw, u32 bcast_thresh, u32 mcast_thresh,
861 struct ice_aqc_storm_cfg *cmd;
862 struct ice_aq_desc desc;
864 cmd = &desc.params.storm_conf;
866 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_storm_cfg);
868 cmd->bcast_thresh_size = CPU_TO_LE32(bcast_thresh & ICE_AQ_THRESHOLD_M);
869 cmd->mcast_thresh_size = CPU_TO_LE32(mcast_thresh & ICE_AQ_THRESHOLD_M);
870 cmd->storm_ctrl_ctrl = CPU_TO_LE32(ctl_bitmask);
872 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
876 * ice_aq_get_storm_ctrl - gets storm control configuration
877 * @hw: pointer to the HW struct
878 * @bcast_thresh: represents the upper threshold for broadcast storm control
879 * @mcast_thresh: represents the upper threshold for multicast storm control
880 * @ctl_bitmask: storm control control knobs
882 * Gets the storm control configuration (0x0281)
885 ice_aq_get_storm_ctrl(struct ice_hw *hw, u32 *bcast_thresh, u32 *mcast_thresh,
888 enum ice_status status;
889 struct ice_aq_desc desc;
891 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_storm_cfg);
893 status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
895 struct ice_aqc_storm_cfg *resp = &desc.params.storm_conf;
898 *bcast_thresh = LE32_TO_CPU(resp->bcast_thresh_size) &
901 *mcast_thresh = LE32_TO_CPU(resp->mcast_thresh_size) &
904 *ctl_bitmask = LE32_TO_CPU(resp->storm_ctrl_ctrl);
911 * ice_aq_sw_rules - add/update/remove switch rules
912 * @hw: pointer to the HW struct
913 * @rule_list: pointer to switch rule population list
914 * @rule_list_sz: total size of the rule list in bytes
915 * @num_rules: number of switch rules in the rule_list
916 * @opc: switch rules population command type - pass in the command opcode
917 * @cd: pointer to command details structure or NULL
919 * Add(0x02a0)/Update(0x02a1)/Remove(0x02a2) switch rules commands to firmware
921 static enum ice_status
922 ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
923 u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd)
925 struct ice_aq_desc desc;
927 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
929 if (opc != ice_aqc_opc_add_sw_rules &&
930 opc != ice_aqc_opc_update_sw_rules &&
931 opc != ice_aqc_opc_remove_sw_rules)
932 return ICE_ERR_PARAM;
934 ice_fill_dflt_direct_cmd_desc(&desc, opc);
936 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
937 desc.params.sw_rules.num_rules_fltr_entry_index =
938 CPU_TO_LE16(num_rules);
939 return ice_aq_send_cmd(hw, &desc, rule_list, rule_list_sz, cd);
942 /* ice_init_port_info - Initialize port_info with switch configuration data
943 * @pi: pointer to port_info
944 * @vsi_port_num: VSI number or port number
945 * @type: Type of switch element (port or VSI)
946 * @swid: switch ID of the switch the element is attached to
947 * @pf_vf_num: PF or VF number
948 * @is_vf: true if the element is a VF, false otherwise
951 ice_init_port_info(struct ice_port_info *pi, u16 vsi_port_num, u8 type,
952 u16 swid, u16 pf_vf_num, bool is_vf)
955 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
956 pi->lport = (u8)(vsi_port_num & ICE_LPORT_MASK);
958 pi->pf_vf_num = pf_vf_num;
960 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
961 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
964 ice_debug(pi->hw, ICE_DBG_SW,
965 "incorrect VSI/port type received\n");
970 /* ice_get_initial_sw_cfg - Get initial port and default VSI data
971 * @hw: pointer to the hardware structure
973 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw)
975 struct ice_aqc_get_sw_cfg_resp *rbuf;
976 enum ice_status status;
985 rbuf = (struct ice_aqc_get_sw_cfg_resp *)
986 ice_malloc(hw, ICE_SW_CFG_MAX_BUF_LEN);
989 return ICE_ERR_NO_MEMORY;
991 /* Multiple calls to ice_aq_get_sw_cfg may be required
992 * to get all the switch configuration information. The need
993 * for additional calls is indicated by ice_aq_get_sw_cfg
994 * writing a non-zero value in req_desc
997 status = ice_aq_get_sw_cfg(hw, rbuf, ICE_SW_CFG_MAX_BUF_LEN,
998 &req_desc, &num_elems, NULL);
1003 for (i = 0; i < num_elems; i++) {
1004 struct ice_aqc_get_sw_cfg_resp_elem *ele;
1005 u16 pf_vf_num, swid, vsi_port_num;
1009 ele = rbuf[i].elements;
1010 vsi_port_num = LE16_TO_CPU(ele->vsi_port_num) &
1011 ICE_AQC_GET_SW_CONF_RESP_VSI_PORT_NUM_M;
1013 pf_vf_num = LE16_TO_CPU(ele->pf_vf_num) &
1014 ICE_AQC_GET_SW_CONF_RESP_FUNC_NUM_M;
1016 swid = LE16_TO_CPU(ele->swid);
1018 if (LE16_TO_CPU(ele->pf_vf_num) &
1019 ICE_AQC_GET_SW_CONF_RESP_IS_VF)
1022 res_type = (u8)(LE16_TO_CPU(ele->vsi_port_num) >>
1023 ICE_AQC_GET_SW_CONF_RESP_TYPE_S);
1026 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
1027 case ICE_AQC_GET_SW_CONF_RESP_VIRT_PORT:
1028 if (j == num_total_ports) {
1029 ice_debug(hw, ICE_DBG_SW,
1030 "more ports than expected\n");
1031 status = ICE_ERR_CFG;
1034 ice_init_port_info(hw->port_info,
1035 vsi_port_num, res_type, swid,
1043 } while (req_desc && !status);
1046 ice_free(hw, (void *)rbuf);
1051 * ice_fill_sw_info - Helper function to populate lb_en and lan_en
1052 * @hw: pointer to the hardware structure
1053 * @fi: filter info structure to fill/update
1055 * This helper function populates the lb_en and lan_en elements of the provided
1056 * ice_fltr_info struct using the switch's type and characteristics of the
1057 * switch rule being configured.
1059 static void ice_fill_sw_info(struct ice_hw *hw, struct ice_fltr_info *fi)
1063 if ((fi->flag & ICE_FLTR_TX) &&
1064 (fi->fltr_act == ICE_FWD_TO_VSI ||
1065 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1066 fi->fltr_act == ICE_FWD_TO_Q ||
1067 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1068 /* Setting LB for prune actions will result in replicated
1069 * packets to the internal switch that will be dropped.
1071 if (fi->lkup_type != ICE_SW_LKUP_VLAN)
1074 /* Set lan_en to TRUE if
1075 * 1. The switch is a VEB AND
1077 * 2.1 The lookup is a directional lookup like ethertype,
1078 * promiscuous, ethertype-MAC, promiscuous-VLAN
1079 * and default-port OR
1080 * 2.2 The lookup is VLAN, OR
1081 * 2.3 The lookup is MAC with mcast or bcast addr for MAC, OR
1082 * 2.4 The lookup is MAC_VLAN with mcast or bcast addr for MAC.
1086 * The switch is a VEPA.
1088 * In all other cases, the LAN enable has to be set to false.
1091 if (fi->lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1092 fi->lkup_type == ICE_SW_LKUP_PROMISC ||
1093 fi->lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1094 fi->lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
1095 fi->lkup_type == ICE_SW_LKUP_DFLT ||
1096 fi->lkup_type == ICE_SW_LKUP_VLAN ||
1097 (fi->lkup_type == ICE_SW_LKUP_MAC &&
1098 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)) ||
1099 (fi->lkup_type == ICE_SW_LKUP_MAC_VLAN &&
1100 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)))
1109 * ice_fill_sw_rule - Helper function to fill switch rule structure
1110 * @hw: pointer to the hardware structure
1111 * @f_info: entry containing packet forwarding information
1112 * @s_rule: switch rule structure to be filled in based on mac_entry
1113 * @opc: switch rules population command type - pass in the command opcode
1116 ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
1117 struct ice_aqc_sw_rules_elem *s_rule, enum ice_adminq_opc opc)
1119 u16 vlan_id = ICE_MAX_VLAN_ID + 1;
1127 if (opc == ice_aqc_opc_remove_sw_rules) {
1128 s_rule->pdata.lkup_tx_rx.act = 0;
1129 s_rule->pdata.lkup_tx_rx.index =
1130 CPU_TO_LE16(f_info->fltr_rule_id);
1131 s_rule->pdata.lkup_tx_rx.hdr_len = 0;
1135 eth_hdr_sz = sizeof(dummy_eth_header);
1136 eth_hdr = s_rule->pdata.lkup_tx_rx.hdr;
1138 /* initialize the ether header with a dummy header */
1139 ice_memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz, ICE_NONDMA_TO_NONDMA);
1140 ice_fill_sw_info(hw, f_info);
1142 switch (f_info->fltr_act) {
1143 case ICE_FWD_TO_VSI:
1144 act |= (f_info->fwd_id.hw_vsi_id << ICE_SINGLE_ACT_VSI_ID_S) &
1145 ICE_SINGLE_ACT_VSI_ID_M;
1146 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
1147 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
1148 ICE_SINGLE_ACT_VALID_BIT;
1150 case ICE_FWD_TO_VSI_LIST:
1151 act |= ICE_SINGLE_ACT_VSI_LIST;
1152 act |= (f_info->fwd_id.vsi_list_id <<
1153 ICE_SINGLE_ACT_VSI_LIST_ID_S) &
1154 ICE_SINGLE_ACT_VSI_LIST_ID_M;
1155 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
1156 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
1157 ICE_SINGLE_ACT_VALID_BIT;
1160 act |= ICE_SINGLE_ACT_TO_Q;
1161 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
1162 ICE_SINGLE_ACT_Q_INDEX_M;
1164 case ICE_DROP_PACKET:
1165 act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
1166 ICE_SINGLE_ACT_VALID_BIT;
1168 case ICE_FWD_TO_QGRP:
1169 q_rgn = f_info->qgrp_size > 0 ?
1170 (u8)ice_ilog2(f_info->qgrp_size) : 0;
1171 act |= ICE_SINGLE_ACT_TO_Q;
1172 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
1173 ICE_SINGLE_ACT_Q_INDEX_M;
1174 act |= (q_rgn << ICE_SINGLE_ACT_Q_REGION_S) &
1175 ICE_SINGLE_ACT_Q_REGION_M;
1182 act |= ICE_SINGLE_ACT_LB_ENABLE;
1184 act |= ICE_SINGLE_ACT_LAN_ENABLE;
1186 switch (f_info->lkup_type) {
1187 case ICE_SW_LKUP_MAC:
1188 daddr = f_info->l_data.mac.mac_addr;
1190 case ICE_SW_LKUP_VLAN:
1191 vlan_id = f_info->l_data.vlan.vlan_id;
1192 if (f_info->fltr_act == ICE_FWD_TO_VSI ||
1193 f_info->fltr_act == ICE_FWD_TO_VSI_LIST) {
1194 act |= ICE_SINGLE_ACT_PRUNE;
1195 act |= ICE_SINGLE_ACT_EGRESS | ICE_SINGLE_ACT_INGRESS;
1198 case ICE_SW_LKUP_ETHERTYPE_MAC:
1199 daddr = f_info->l_data.ethertype_mac.mac_addr;
1201 case ICE_SW_LKUP_ETHERTYPE:
1202 off = (_FORCE_ __be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
1203 *off = CPU_TO_BE16(f_info->l_data.ethertype_mac.ethertype);
1205 case ICE_SW_LKUP_MAC_VLAN:
1206 daddr = f_info->l_data.mac_vlan.mac_addr;
1207 vlan_id = f_info->l_data.mac_vlan.vlan_id;
1209 case ICE_SW_LKUP_PROMISC_VLAN:
1210 vlan_id = f_info->l_data.mac_vlan.vlan_id;
1212 case ICE_SW_LKUP_PROMISC:
1213 daddr = f_info->l_data.mac_vlan.mac_addr;
1219 s_rule->type = (f_info->flag & ICE_FLTR_RX) ?
1220 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_RX) :
1221 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_TX);
1223 /* Recipe set depending on lookup type */
1224 s_rule->pdata.lkup_tx_rx.recipe_id = CPU_TO_LE16(f_info->lkup_type);
1225 s_rule->pdata.lkup_tx_rx.src = CPU_TO_LE16(f_info->src);
1226 s_rule->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
1229 ice_memcpy(eth_hdr + ICE_ETH_DA_OFFSET, daddr, ETH_ALEN,
1230 ICE_NONDMA_TO_NONDMA);
1232 if (!(vlan_id > ICE_MAX_VLAN_ID)) {
1233 off = (_FORCE_ __be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
1234 *off = CPU_TO_BE16(vlan_id);
1237 /* Create the switch rule with the final dummy Ethernet header */
1238 if (opc != ice_aqc_opc_update_sw_rules)
1239 s_rule->pdata.lkup_tx_rx.hdr_len = CPU_TO_LE16(eth_hdr_sz);
1243 * ice_add_marker_act
1244 * @hw: pointer to the hardware structure
1245 * @m_ent: the management entry for which sw marker needs to be added
1246 * @sw_marker: sw marker to tag the Rx descriptor with
1247 * @l_id: large action resource ID
1249 * Create a large action to hold software marker and update the switch rule
1250 * entry pointed by m_ent with newly created large action
1252 static enum ice_status
1253 ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
1254 u16 sw_marker, u16 l_id)
1256 struct ice_aqc_sw_rules_elem *lg_act, *rx_tx;
1257 /* For software marker we need 3 large actions
1258 * 1. FWD action: FWD TO VSI or VSI LIST
1259 * 2. GENERIC VALUE action to hold the profile ID
1260 * 3. GENERIC VALUE action to hold the software marker ID
1262 const u16 num_lg_acts = 3;
1263 enum ice_status status;
1269 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
1270 return ICE_ERR_PARAM;
1272 /* Create two back-to-back switch rules and submit them to the HW using
1273 * one memory buffer:
1277 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_lg_acts);
1278 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1279 lg_act = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, rules_size);
1281 return ICE_ERR_NO_MEMORY;
1283 rx_tx = (struct ice_aqc_sw_rules_elem *)((u8 *)lg_act + lg_act_size);
1285 /* Fill in the first switch rule i.e. large action */
1286 lg_act->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_LG_ACT);
1287 lg_act->pdata.lg_act.index = CPU_TO_LE16(l_id);
1288 lg_act->pdata.lg_act.size = CPU_TO_LE16(num_lg_acts);
1290 /* First action VSI forwarding or VSI list forwarding depending on how
1293 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
1294 m_ent->fltr_info.fwd_id.hw_vsi_id;
1296 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
1297 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) &
1298 ICE_LG_ACT_VSI_LIST_ID_M;
1299 if (m_ent->vsi_count > 1)
1300 act |= ICE_LG_ACT_VSI_LIST;
1301 lg_act->pdata.lg_act.act[0] = CPU_TO_LE32(act);
1303 /* Second action descriptor type */
1304 act = ICE_LG_ACT_GENERIC;
1306 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
1307 lg_act->pdata.lg_act.act[1] = CPU_TO_LE32(act);
1309 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
1310 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
1312 /* Third action Marker value */
1313 act |= ICE_LG_ACT_GENERIC;
1314 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
1315 ICE_LG_ACT_GENERIC_VALUE_M;
1317 lg_act->pdata.lg_act.act[2] = CPU_TO_LE32(act);
1319 /* call the fill switch rule to fill the lookup Tx Rx structure */
1320 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
1321 ice_aqc_opc_update_sw_rules);
1323 /* Update the action to point to the large action ID */
1324 rx_tx->pdata.lkup_tx_rx.act =
1325 CPU_TO_LE32(ICE_SINGLE_ACT_PTR |
1326 ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
1327 ICE_SINGLE_ACT_PTR_VAL_M));
1329 /* Use the filter rule ID of the previously created rule with single
1330 * act. Once the update happens, hardware will treat this as large
1333 rx_tx->pdata.lkup_tx_rx.index =
1334 CPU_TO_LE16(m_ent->fltr_info.fltr_rule_id);
1336 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
1337 ice_aqc_opc_update_sw_rules, NULL);
1339 m_ent->lg_act_idx = l_id;
1340 m_ent->sw_marker_id = sw_marker;
1343 ice_free(hw, lg_act);
1348 * ice_add_counter_act - add/update filter rule with counter action
1349 * @hw: pointer to the hardware structure
1350 * @m_ent: the management entry for which counter needs to be added
1351 * @counter_id: VLAN counter ID returned as part of allocate resource
1352 * @l_id: large action resource ID
1354 static enum ice_status
1355 ice_add_counter_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
1356 u16 counter_id, u16 l_id)
1358 struct ice_aqc_sw_rules_elem *lg_act;
1359 struct ice_aqc_sw_rules_elem *rx_tx;
1360 enum ice_status status;
1361 /* 2 actions will be added while adding a large action counter */
1362 const int num_acts = 2;
1369 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
1370 return ICE_ERR_PARAM;
1372 /* Create two back-to-back switch rules and submit them to the HW using
1373 * one memory buffer:
1377 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_acts);
1378 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1379 lg_act = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw,
1382 return ICE_ERR_NO_MEMORY;
1384 rx_tx = (struct ice_aqc_sw_rules_elem *)
1385 ((u8 *)lg_act + lg_act_size);
1387 /* Fill in the first switch rule i.e. large action */
1388 lg_act->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_LG_ACT);
1389 lg_act->pdata.lg_act.index = CPU_TO_LE16(l_id);
1390 lg_act->pdata.lg_act.size = CPU_TO_LE16(num_acts);
1392 /* First action VSI forwarding or VSI list forwarding depending on how
1395 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
1396 m_ent->fltr_info.fwd_id.hw_vsi_id;
1398 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
1399 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) &
1400 ICE_LG_ACT_VSI_LIST_ID_M;
1401 if (m_ent->vsi_count > 1)
1402 act |= ICE_LG_ACT_VSI_LIST;
1403 lg_act->pdata.lg_act.act[0] = CPU_TO_LE32(act);
1405 /* Second action counter ID */
1406 act = ICE_LG_ACT_STAT_COUNT;
1407 act |= (counter_id << ICE_LG_ACT_STAT_COUNT_S) &
1408 ICE_LG_ACT_STAT_COUNT_M;
1409 lg_act->pdata.lg_act.act[1] = CPU_TO_LE32(act);
1411 /* call the fill switch rule to fill the lookup Tx Rx structure */
1412 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
1413 ice_aqc_opc_update_sw_rules);
1415 act = ICE_SINGLE_ACT_PTR;
1416 act |= (l_id << ICE_SINGLE_ACT_PTR_VAL_S) & ICE_SINGLE_ACT_PTR_VAL_M;
1417 rx_tx->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
1419 /* Use the filter rule ID of the previously created rule with single
1420 * act. Once the update happens, hardware will treat this as large
1423 f_rule_id = m_ent->fltr_info.fltr_rule_id;
1424 rx_tx->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_rule_id);
1426 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
1427 ice_aqc_opc_update_sw_rules, NULL);
1429 m_ent->lg_act_idx = l_id;
1430 m_ent->counter_index = counter_id;
1433 ice_free(hw, lg_act);
1438 * ice_create_vsi_list_map
1439 * @hw: pointer to the hardware structure
1440 * @vsi_handle_arr: array of VSI handles to set in the VSI mapping
1441 * @num_vsi: number of VSI handles in the array
1442 * @vsi_list_id: VSI list ID generated as part of allocate resource
1444 * Helper function to create a new entry of VSI list ID to VSI mapping
1445 * using the given VSI list ID
1447 static struct ice_vsi_list_map_info *
1448 ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1451 struct ice_switch_info *sw = hw->switch_info;
1452 struct ice_vsi_list_map_info *v_map;
1455 v_map = (struct ice_vsi_list_map_info *)ice_calloc(hw, 1,
1460 v_map->vsi_list_id = vsi_list_id;
1462 for (i = 0; i < num_vsi; i++)
1463 ice_set_bit(vsi_handle_arr[i], v_map->vsi_map);
1465 LIST_ADD(&v_map->list_entry, &sw->vsi_list_map_head);
1470 * ice_update_vsi_list_rule
1471 * @hw: pointer to the hardware structure
1472 * @vsi_handle_arr: array of VSI handles to form a VSI list
1473 * @num_vsi: number of VSI handles in the array
1474 * @vsi_list_id: VSI list ID generated as part of allocate resource
1475 * @remove: Boolean value to indicate if this is a remove action
1476 * @opc: switch rules population command type - pass in the command opcode
1477 * @lkup_type: lookup type of the filter
1479 * Call AQ command to add a new switch rule or update existing switch rule
1480 * using the given VSI list ID
1482 static enum ice_status
1483 ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1484 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
1485 enum ice_sw_lkup_type lkup_type)
1487 struct ice_aqc_sw_rules_elem *s_rule;
1488 enum ice_status status;
1494 return ICE_ERR_PARAM;
1496 if (lkup_type == ICE_SW_LKUP_MAC ||
1497 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
1498 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1499 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1500 lkup_type == ICE_SW_LKUP_PROMISC ||
1501 lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
1502 lkup_type == ICE_SW_LKUP_LAST)
1503 rule_type = remove ? ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR :
1504 ICE_AQC_SW_RULES_T_VSI_LIST_SET;
1505 else if (lkup_type == ICE_SW_LKUP_VLAN)
1506 rule_type = remove ? ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR :
1507 ICE_AQC_SW_RULES_T_PRUNE_LIST_SET;
1509 return ICE_ERR_PARAM;
1511 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
1512 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1514 return ICE_ERR_NO_MEMORY;
1515 for (i = 0; i < num_vsi; i++) {
1516 if (!ice_is_vsi_valid(hw, vsi_handle_arr[i])) {
1517 status = ICE_ERR_PARAM;
1520 /* AQ call requires hw_vsi_id(s) */
1521 s_rule->pdata.vsi_list.vsi[i] =
1522 CPU_TO_LE16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
1525 s_rule->type = CPU_TO_LE16(rule_type);
1526 s_rule->pdata.vsi_list.number_vsi = CPU_TO_LE16(num_vsi);
1527 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1529 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
1532 ice_free(hw, s_rule);
1537 * ice_create_vsi_list_rule - Creates and populates a VSI list rule
1538 * @hw: pointer to the HW struct
1539 * @vsi_handle_arr: array of VSI handles to form a VSI list
1540 * @num_vsi: number of VSI handles in the array
1541 * @vsi_list_id: stores the ID of the VSI list to be created
1542 * @lkup_type: switch rule filter's lookup type
1544 static enum ice_status
1545 ice_create_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1546 u16 *vsi_list_id, enum ice_sw_lkup_type lkup_type)
1548 enum ice_status status;
1550 status = ice_aq_alloc_free_vsi_list(hw, vsi_list_id, lkup_type,
1551 ice_aqc_opc_alloc_res);
1555 /* Update the newly created VSI list to include the specified VSIs */
1556 return ice_update_vsi_list_rule(hw, vsi_handle_arr, num_vsi,
1557 *vsi_list_id, false,
1558 ice_aqc_opc_add_sw_rules, lkup_type);
1562 * ice_create_pkt_fwd_rule
1563 * @hw: pointer to the hardware structure
1564 * @recp_list: corresponding filter management list
1565 * @f_entry: entry containing packet forwarding information
1567 * Create switch rule with given filter information and add an entry
1568 * to the corresponding filter management list to track this switch rule
1571 static enum ice_status
1572 ice_create_pkt_fwd_rule(struct ice_hw *hw, struct ice_sw_recipe *recp_list,
1573 struct ice_fltr_list_entry *f_entry)
1575 struct ice_fltr_mgmt_list_entry *fm_entry;
1576 struct ice_aqc_sw_rules_elem *s_rule;
1577 enum ice_status status;
1579 s_rule = (struct ice_aqc_sw_rules_elem *)
1580 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1582 return ICE_ERR_NO_MEMORY;
1583 fm_entry = (struct ice_fltr_mgmt_list_entry *)
1584 ice_malloc(hw, sizeof(*fm_entry));
1586 status = ICE_ERR_NO_MEMORY;
1587 goto ice_create_pkt_fwd_rule_exit;
1590 fm_entry->fltr_info = f_entry->fltr_info;
1592 /* Initialize all the fields for the management entry */
1593 fm_entry->vsi_count = 1;
1594 fm_entry->lg_act_idx = ICE_INVAL_LG_ACT_INDEX;
1595 fm_entry->sw_marker_id = ICE_INVAL_SW_MARKER_ID;
1596 fm_entry->counter_index = ICE_INVAL_COUNTER_ID;
1598 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
1599 ice_aqc_opc_add_sw_rules);
1601 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1602 ice_aqc_opc_add_sw_rules, NULL);
1604 ice_free(hw, fm_entry);
1605 goto ice_create_pkt_fwd_rule_exit;
1608 f_entry->fltr_info.fltr_rule_id =
1609 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1610 fm_entry->fltr_info.fltr_rule_id =
1611 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1613 /* The book keeping entries will get removed when base driver
1614 * calls remove filter AQ command
1616 LIST_ADD(&fm_entry->list_entry, &recp_list->filt_rules);
1618 ice_create_pkt_fwd_rule_exit:
1619 ice_free(hw, s_rule);
1624 * ice_update_pkt_fwd_rule
1625 * @hw: pointer to the hardware structure
1626 * @f_info: filter information for switch rule
1628 * Call AQ command to update a previously created switch rule with a
1631 static enum ice_status
1632 ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
1634 struct ice_aqc_sw_rules_elem *s_rule;
1635 enum ice_status status;
1637 s_rule = (struct ice_aqc_sw_rules_elem *)
1638 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1640 return ICE_ERR_NO_MEMORY;
1642 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
1644 s_rule->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_info->fltr_rule_id);
1646 /* Update switch rule with new rule set to forward VSI list */
1647 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1648 ice_aqc_opc_update_sw_rules, NULL);
1650 ice_free(hw, s_rule);
1655 * ice_update_sw_rule_bridge_mode
1656 * @hw: pointer to the HW struct
1658 * Updates unicast switch filter rules based on VEB/VEPA mode
1660 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw)
1662 struct ice_switch_info *sw = hw->switch_info;
1663 struct ice_fltr_mgmt_list_entry *fm_entry;
1664 enum ice_status status = ICE_SUCCESS;
1665 struct LIST_HEAD_TYPE *rule_head;
1666 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1668 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1669 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1671 ice_acquire_lock(rule_lock);
1672 LIST_FOR_EACH_ENTRY(fm_entry, rule_head, ice_fltr_mgmt_list_entry,
1674 struct ice_fltr_info *fi = &fm_entry->fltr_info;
1675 u8 *addr = fi->l_data.mac.mac_addr;
1677 /* Update unicast Tx rules to reflect the selected
1680 if ((fi->flag & ICE_FLTR_TX) && IS_UNICAST_ETHER_ADDR(addr) &&
1681 (fi->fltr_act == ICE_FWD_TO_VSI ||
1682 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1683 fi->fltr_act == ICE_FWD_TO_Q ||
1684 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1685 status = ice_update_pkt_fwd_rule(hw, fi);
1691 ice_release_lock(rule_lock);
1697 * ice_add_update_vsi_list
1698 * @hw: pointer to the hardware structure
1699 * @m_entry: pointer to current filter management list entry
1700 * @cur_fltr: filter information from the book keeping entry
1701 * @new_fltr: filter information with the new VSI to be added
1703 * Call AQ command to add or update previously created VSI list with new VSI.
1705 * Helper function to do book keeping associated with adding filter information
1706 * The algorithm to do the book keeping is described below :
1707 * When a VSI needs to subscribe to a given filter (MAC/VLAN/Ethtype etc.)
1708 * if only one VSI has been added till now
1709 * Allocate a new VSI list and add two VSIs
1710 * to this list using switch rule command
1711 * Update the previously created switch rule with the
1712 * newly created VSI list ID
1713 * if a VSI list was previously created
1714 * Add the new VSI to the previously created VSI list set
1715 * using the update switch rule command
1717 static enum ice_status
1718 ice_add_update_vsi_list(struct ice_hw *hw,
1719 struct ice_fltr_mgmt_list_entry *m_entry,
1720 struct ice_fltr_info *cur_fltr,
1721 struct ice_fltr_info *new_fltr)
1723 enum ice_status status = ICE_SUCCESS;
1724 u16 vsi_list_id = 0;
1726 if ((cur_fltr->fltr_act == ICE_FWD_TO_Q ||
1727 cur_fltr->fltr_act == ICE_FWD_TO_QGRP))
1728 return ICE_ERR_NOT_IMPL;
1730 if ((new_fltr->fltr_act == ICE_FWD_TO_Q ||
1731 new_fltr->fltr_act == ICE_FWD_TO_QGRP) &&
1732 (cur_fltr->fltr_act == ICE_FWD_TO_VSI ||
1733 cur_fltr->fltr_act == ICE_FWD_TO_VSI_LIST))
1734 return ICE_ERR_NOT_IMPL;
1736 if (m_entry->vsi_count < 2 && !m_entry->vsi_list_info) {
1737 /* Only one entry existed in the mapping and it was not already
1738 * a part of a VSI list. So, create a VSI list with the old and
1741 struct ice_fltr_info tmp_fltr;
1742 u16 vsi_handle_arr[2];
1744 /* A rule already exists with the new VSI being added */
1745 if (cur_fltr->fwd_id.hw_vsi_id == new_fltr->fwd_id.hw_vsi_id)
1746 return ICE_ERR_ALREADY_EXISTS;
1748 vsi_handle_arr[0] = cur_fltr->vsi_handle;
1749 vsi_handle_arr[1] = new_fltr->vsi_handle;
1750 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1752 new_fltr->lkup_type);
1756 tmp_fltr = *new_fltr;
1757 tmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;
1758 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1759 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1760 /* Update the previous switch rule of "MAC forward to VSI" to
1761 * "MAC fwd to VSI list"
1763 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1767 cur_fltr->fwd_id.vsi_list_id = vsi_list_id;
1768 cur_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1769 m_entry->vsi_list_info =
1770 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1773 /* If this entry was large action then the large action needs
1774 * to be updated to point to FWD to VSI list
1776 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID)
1778 ice_add_marker_act(hw, m_entry,
1779 m_entry->sw_marker_id,
1780 m_entry->lg_act_idx);
1782 u16 vsi_handle = new_fltr->vsi_handle;
1783 enum ice_adminq_opc opcode;
1785 if (!m_entry->vsi_list_info)
1788 /* A rule already exists with the new VSI being added */
1789 if (ice_is_bit_set(m_entry->vsi_list_info->vsi_map, vsi_handle))
1792 /* Update the previously created VSI list set with
1793 * the new VSI ID passed in
1795 vsi_list_id = cur_fltr->fwd_id.vsi_list_id;
1796 opcode = ice_aqc_opc_update_sw_rules;
1798 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1,
1799 vsi_list_id, false, opcode,
1800 new_fltr->lkup_type);
1801 /* update VSI list mapping info with new VSI ID */
1803 ice_set_bit(vsi_handle,
1804 m_entry->vsi_list_info->vsi_map);
1807 m_entry->vsi_count++;
1812 * ice_find_rule_entry - Search a rule entry
1813 * @list_head: head of rule list
1814 * @f_info: rule information
1816 * Helper function to search for a given rule entry
1817 * Returns pointer to entry storing the rule if found
1819 static struct ice_fltr_mgmt_list_entry *
1820 ice_find_rule_entry(struct LIST_HEAD_TYPE *list_head,
1821 struct ice_fltr_info *f_info)
1823 struct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;
1825 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1827 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
1828 sizeof(f_info->l_data)) &&
1829 f_info->flag == list_itr->fltr_info.flag) {
1838 * ice_find_vsi_list_entry - Search VSI list map with VSI count 1
1839 * @recp_list: 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_sw_recipe *recp_list, u16 vsi_handle,
1851 struct ice_vsi_list_map_info *map_info = NULL;
1852 struct LIST_HEAD_TYPE *list_head;
1854 list_head = &recp_list->filt_rules;
1855 if (recp_list->adv_rule) {
1856 struct ice_adv_fltr_mgmt_list_entry *list_itr;
1858 LIST_FOR_EACH_ENTRY(list_itr, list_head,
1859 ice_adv_fltr_mgmt_list_entry,
1861 if (list_itr->vsi_list_info) {
1862 map_info = list_itr->vsi_list_info;
1863 if (ice_is_bit_set(map_info->vsi_map,
1865 *vsi_list_id = map_info->vsi_list_id;
1871 struct ice_fltr_mgmt_list_entry *list_itr;
1873 LIST_FOR_EACH_ENTRY(list_itr, list_head,
1874 ice_fltr_mgmt_list_entry,
1876 if (list_itr->vsi_count == 1 &&
1877 list_itr->vsi_list_info) {
1878 map_info = list_itr->vsi_list_info;
1879 if (ice_is_bit_set(map_info->vsi_map,
1881 *vsi_list_id = map_info->vsi_list_id;
1891 * ice_add_rule_internal - add rule for a given lookup type
1892 * @hw: pointer to the hardware structure
1893 * @recp_list: recipe list for which rule has to be added
1894 * @lport: logic port number on which function add rule
1895 * @f_entry: structure containing MAC forwarding information
1897 * Adds or updates the rule lists for a given recipe
1899 static enum ice_status
1900 ice_add_rule_internal(struct ice_hw *hw, struct ice_sw_recipe *recp_list,
1901 u8 lport, struct ice_fltr_list_entry *f_entry)
1903 struct ice_fltr_info *new_fltr, *cur_fltr;
1904 struct ice_fltr_mgmt_list_entry *m_entry;
1905 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1906 enum ice_status status = ICE_SUCCESS;
1908 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1909 return ICE_ERR_PARAM;
1911 /* Load the hw_vsi_id only if the fwd action is fwd to VSI */
1912 if (f_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI)
1913 f_entry->fltr_info.fwd_id.hw_vsi_id =
1914 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1916 rule_lock = &recp_list->filt_rule_lock;
1918 ice_acquire_lock(rule_lock);
1919 new_fltr = &f_entry->fltr_info;
1920 if (new_fltr->flag & ICE_FLTR_RX)
1921 new_fltr->src = lport;
1922 else if (new_fltr->flag & ICE_FLTR_TX)
1924 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1926 m_entry = ice_find_rule_entry(&recp_list->filt_rules, new_fltr);
1928 status = ice_create_pkt_fwd_rule(hw, recp_list, f_entry);
1929 goto exit_add_rule_internal;
1932 cur_fltr = &m_entry->fltr_info;
1933 status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
1935 exit_add_rule_internal:
1936 ice_release_lock(rule_lock);
1941 * ice_remove_vsi_list_rule
1942 * @hw: pointer to the hardware structure
1943 * @vsi_list_id: VSI list ID generated as part of allocate resource
1944 * @lkup_type: switch rule filter lookup type
1946 * The VSI list should be emptied before this function is called to remove the
1949 static enum ice_status
1950 ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
1951 enum ice_sw_lkup_type lkup_type)
1953 struct ice_aqc_sw_rules_elem *s_rule;
1954 enum ice_status status;
1957 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
1958 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1960 return ICE_ERR_NO_MEMORY;
1962 s_rule->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
1963 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1965 /* Free the vsi_list resource that we allocated. It is assumed that the
1966 * list is empty at this point.
1968 status = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,
1969 ice_aqc_opc_free_res);
1971 ice_free(hw, s_rule);
1976 * ice_rem_update_vsi_list
1977 * @hw: pointer to the hardware structure
1978 * @vsi_handle: VSI handle of the VSI to remove
1979 * @fm_list: filter management entry for which the VSI list management needs to
1982 static enum ice_status
1983 ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
1984 struct ice_fltr_mgmt_list_entry *fm_list)
1986 enum ice_sw_lkup_type lkup_type;
1987 enum ice_status status = ICE_SUCCESS;
1990 if (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||
1991 fm_list->vsi_count == 0)
1992 return ICE_ERR_PARAM;
1994 /* A rule with the VSI being removed does not exist */
1995 if (!ice_is_bit_set(fm_list->vsi_list_info->vsi_map, vsi_handle))
1996 return ICE_ERR_DOES_NOT_EXIST;
1998 lkup_type = fm_list->fltr_info.lkup_type;
1999 vsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;
2000 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
2001 ice_aqc_opc_update_sw_rules,
2006 fm_list->vsi_count--;
2007 ice_clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
2009 if (fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) {
2010 struct ice_fltr_info tmp_fltr_info = fm_list->fltr_info;
2011 struct ice_vsi_list_map_info *vsi_list_info =
2012 fm_list->vsi_list_info;
2015 rem_vsi_handle = ice_find_first_bit(vsi_list_info->vsi_map,
2017 if (!ice_is_vsi_valid(hw, rem_vsi_handle))
2018 return ICE_ERR_OUT_OF_RANGE;
2020 /* Make sure VSI list is empty before removing it below */
2021 status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
2023 ice_aqc_opc_update_sw_rules,
2028 tmp_fltr_info.fltr_act = ICE_FWD_TO_VSI;
2029 tmp_fltr_info.fwd_id.hw_vsi_id =
2030 ice_get_hw_vsi_num(hw, rem_vsi_handle);
2031 tmp_fltr_info.vsi_handle = rem_vsi_handle;
2032 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr_info);
2034 ice_debug(hw, ICE_DBG_SW,
2035 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
2036 tmp_fltr_info.fwd_id.hw_vsi_id, status);
2040 fm_list->fltr_info = tmp_fltr_info;
2043 if ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||
2044 (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {
2045 struct ice_vsi_list_map_info *vsi_list_info =
2046 fm_list->vsi_list_info;
2048 /* Remove the VSI list since it is no longer used */
2049 status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
2051 ice_debug(hw, ICE_DBG_SW,
2052 "Failed to remove VSI list %d, error %d\n",
2053 vsi_list_id, status);
2057 LIST_DEL(&vsi_list_info->list_entry);
2058 ice_free(hw, vsi_list_info);
2059 fm_list->vsi_list_info = NULL;
2066 * ice_remove_rule_internal - Remove a filter rule of a given type
2068 * @hw: pointer to the hardware structure
2069 * @recp_list: recipe list for which the rule needs to removed
2070 * @f_entry: rule entry containing filter information
2072 static enum ice_status
2073 ice_remove_rule_internal(struct ice_hw *hw, struct ice_sw_recipe *recp_list,
2074 struct ice_fltr_list_entry *f_entry)
2076 struct ice_fltr_mgmt_list_entry *list_elem;
2077 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2078 enum ice_status status = ICE_SUCCESS;
2079 bool remove_rule = false;
2082 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
2083 return ICE_ERR_PARAM;
2084 f_entry->fltr_info.fwd_id.hw_vsi_id =
2085 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
2087 rule_lock = &recp_list->filt_rule_lock;
2088 ice_acquire_lock(rule_lock);
2089 list_elem = ice_find_rule_entry(&recp_list->filt_rules,
2090 &f_entry->fltr_info);
2092 status = ICE_ERR_DOES_NOT_EXIST;
2096 if (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {
2098 } else if (!list_elem->vsi_list_info) {
2099 status = ICE_ERR_DOES_NOT_EXIST;
2101 } else if (list_elem->vsi_list_info->ref_cnt > 1) {
2102 /* a ref_cnt > 1 indicates that the vsi_list is being
2103 * shared by multiple rules. Decrement the ref_cnt and
2104 * remove this rule, but do not modify the list, as it
2105 * is in-use by other rules.
2107 list_elem->vsi_list_info->ref_cnt--;
2110 /* a ref_cnt of 1 indicates the vsi_list is only used
2111 * by one rule. However, the original removal request is only
2112 * for a single VSI. Update the vsi_list first, and only
2113 * remove the rule if there are no further VSIs in this list.
2115 vsi_handle = f_entry->fltr_info.vsi_handle;
2116 status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem);
2119 /* if VSI count goes to zero after updating the VSI list */
2120 if (list_elem->vsi_count == 0)
2125 /* Remove the lookup rule */
2126 struct ice_aqc_sw_rules_elem *s_rule;
2128 s_rule = (struct ice_aqc_sw_rules_elem *)
2129 ice_malloc(hw, ICE_SW_RULE_RX_TX_NO_HDR_SIZE);
2131 status = ICE_ERR_NO_MEMORY;
2135 ice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,
2136 ice_aqc_opc_remove_sw_rules);
2138 status = ice_aq_sw_rules(hw, s_rule,
2139 ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
2140 ice_aqc_opc_remove_sw_rules, NULL);
2142 /* Remove a book keeping from the list */
2143 ice_free(hw, s_rule);
2148 LIST_DEL(&list_elem->list_entry);
2149 ice_free(hw, list_elem);
2152 ice_release_lock(rule_lock);
2157 * ice_aq_get_res_alloc - get allocated resources
2158 * @hw: pointer to the HW struct
2159 * @num_entries: pointer to u16 to store the number of resource entries returned
2160 * @buf: pointer to user-supplied buffer
2161 * @buf_size: size of buff
2162 * @cd: pointer to command details structure or NULL
2164 * The user-supplied buffer must be large enough to store the resource
2165 * information for all resource types. Each resource type is an
2166 * ice_aqc_get_res_resp_data_elem structure.
2169 ice_aq_get_res_alloc(struct ice_hw *hw, u16 *num_entries, void *buf,
2170 u16 buf_size, struct ice_sq_cd *cd)
2172 struct ice_aqc_get_res_alloc *resp;
2173 enum ice_status status;
2174 struct ice_aq_desc desc;
2177 return ICE_ERR_BAD_PTR;
2179 if (buf_size < ICE_AQ_GET_RES_ALLOC_BUF_LEN)
2180 return ICE_ERR_INVAL_SIZE;
2182 resp = &desc.params.get_res;
2184 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_res_alloc);
2185 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2187 if (!status && num_entries)
2188 *num_entries = LE16_TO_CPU(resp->resp_elem_num);
2194 * ice_aq_get_res_descs - get allocated resource descriptors
2195 * @hw: pointer to the hardware structure
2196 * @num_entries: number of resource entries in buffer
2197 * @buf: Indirect buffer to hold data parameters and response
2198 * @buf_size: size of buffer for indirect commands
2199 * @res_type: resource type
2200 * @res_shared: is resource shared
2201 * @desc_id: input - first desc ID to start; output - next desc ID
2202 * @cd: pointer to command details structure or NULL
2205 ice_aq_get_res_descs(struct ice_hw *hw, u16 num_entries,
2206 struct ice_aqc_get_allocd_res_desc_resp *buf,
2207 u16 buf_size, u16 res_type, bool res_shared, u16 *desc_id,
2208 struct ice_sq_cd *cd)
2210 struct ice_aqc_get_allocd_res_desc *cmd;
2211 struct ice_aq_desc desc;
2212 enum ice_status status;
2214 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
2216 cmd = &desc.params.get_res_desc;
2219 return ICE_ERR_PARAM;
2221 if (buf_size != (num_entries * sizeof(*buf)))
2222 return ICE_ERR_PARAM;
2224 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_allocd_res_desc);
2226 cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2227 ICE_AQC_RES_TYPE_M) | (res_shared ?
2228 ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2229 cmd->ops.cmd.first_desc = CPU_TO_LE16(*desc_id);
2231 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2233 *desc_id = LE16_TO_CPU(cmd->ops.resp.next_desc);
2239 * ice_add_mac_rule - Add a MAC address based filter rule
2240 * @hw: pointer to the hardware structure
2241 * @m_list: list of MAC addresses and forwarding information
2242 * @sw: pointer to switch info struct for which function add rule
2243 * @lport: logic port number on which function add rule
2245 * IMPORTANT: When the ucast_shared flag is set to false and m_list has
2246 * multiple unicast addresses, the function assumes that all the
2247 * addresses are unique in a given add_mac call. It doesn't
2248 * check for duplicates in this case, removing duplicates from a given
2249 * list should be taken care of in the caller of this function.
2251 static enum ice_status
2252 ice_add_mac_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list,
2253 struct ice_switch_info *sw, u8 lport)
2255 struct ice_sw_recipe *recp_list = &sw->recp_list[ICE_SW_LKUP_MAC];
2256 struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
2257 struct ice_fltr_list_entry *m_list_itr;
2258 struct LIST_HEAD_TYPE *rule_head;
2259 u16 total_elem_left, s_rule_size;
2260 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2261 enum ice_status status = ICE_SUCCESS;
2262 u16 num_unicast = 0;
2266 rule_lock = &recp_list->filt_rule_lock;
2267 rule_head = &recp_list->filt_rules;
2269 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2271 u8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];
2275 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
2276 vsi_handle = m_list_itr->fltr_info.vsi_handle;
2277 if (!ice_is_vsi_valid(hw, vsi_handle))
2278 return ICE_ERR_PARAM;
2279 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2280 m_list_itr->fltr_info.fwd_id.hw_vsi_id = hw_vsi_id;
2281 /* update the src in case it is VSI num */
2282 if (m_list_itr->fltr_info.src_id != ICE_SRC_ID_VSI)
2283 return ICE_ERR_PARAM;
2284 m_list_itr->fltr_info.src = hw_vsi_id;
2285 if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
2286 IS_ZERO_ETHER_ADDR(add))
2287 return ICE_ERR_PARAM;
2288 if (IS_UNICAST_ETHER_ADDR(add) && !hw->ucast_shared) {
2289 /* Don't overwrite the unicast address */
2290 ice_acquire_lock(rule_lock);
2291 if (ice_find_rule_entry(rule_head,
2292 &m_list_itr->fltr_info)) {
2293 ice_release_lock(rule_lock);
2294 return ICE_ERR_ALREADY_EXISTS;
2296 ice_release_lock(rule_lock);
2298 } else if (IS_MULTICAST_ETHER_ADDR(add) ||
2299 (IS_UNICAST_ETHER_ADDR(add) && hw->ucast_shared)) {
2300 m_list_itr->status =
2301 ice_add_rule_internal(hw, recp_list, lport,
2303 if (m_list_itr->status)
2304 return m_list_itr->status;
2308 ice_acquire_lock(rule_lock);
2309 /* Exit if no suitable entries were found for adding bulk switch rule */
2311 status = ICE_SUCCESS;
2312 goto ice_add_mac_exit;
2315 /* Allocate switch rule buffer for the bulk update for unicast */
2316 s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
2317 s_rule = (struct ice_aqc_sw_rules_elem *)
2318 ice_calloc(hw, num_unicast, s_rule_size);
2320 status = ICE_ERR_NO_MEMORY;
2321 goto ice_add_mac_exit;
2325 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2327 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2328 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2330 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2331 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
2332 ice_aqc_opc_add_sw_rules);
2333 r_iter = (struct ice_aqc_sw_rules_elem *)
2334 ((u8 *)r_iter + s_rule_size);
2338 /* Call AQ bulk switch rule update for all unicast addresses */
2340 /* Call AQ switch rule in AQ_MAX chunk */
2341 for (total_elem_left = num_unicast; total_elem_left > 0;
2342 total_elem_left -= elem_sent) {
2343 struct ice_aqc_sw_rules_elem *entry = r_iter;
2345 elem_sent = MIN_T(u8, total_elem_left,
2346 (ICE_AQ_MAX_BUF_LEN / s_rule_size));
2347 status = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,
2348 elem_sent, ice_aqc_opc_add_sw_rules,
2351 goto ice_add_mac_exit;
2352 r_iter = (struct ice_aqc_sw_rules_elem *)
2353 ((u8 *)r_iter + (elem_sent * s_rule_size));
2356 /* Fill up rule ID based on the value returned from FW */
2358 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
2360 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
2361 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
2362 struct ice_fltr_mgmt_list_entry *fm_entry;
2364 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
2365 f_info->fltr_rule_id =
2366 LE16_TO_CPU(r_iter->pdata.lkup_tx_rx.index);
2367 f_info->fltr_act = ICE_FWD_TO_VSI;
2368 /* Create an entry to track this MAC address */
2369 fm_entry = (struct ice_fltr_mgmt_list_entry *)
2370 ice_malloc(hw, sizeof(*fm_entry));
2372 status = ICE_ERR_NO_MEMORY;
2373 goto ice_add_mac_exit;
2375 fm_entry->fltr_info = *f_info;
2376 fm_entry->vsi_count = 1;
2377 /* The book keeping entries will get removed when
2378 * base driver calls remove filter AQ command
2381 LIST_ADD(&fm_entry->list_entry, rule_head);
2382 r_iter = (struct ice_aqc_sw_rules_elem *)
2383 ((u8 *)r_iter + s_rule_size);
2388 ice_release_lock(rule_lock);
2390 ice_free(hw, s_rule);
2395 * ice_add_mac - Add a MAC address based filter rule
2396 * @hw: pointer to the hardware structure
2397 * @m_list: list of MAC addresses and forwarding information
2399 * Function add MAC rule for logical port from HW struct
2402 ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2405 return ICE_ERR_PARAM;
2407 return ice_add_mac_rule(hw, m_list, hw->switch_info,
2408 hw->port_info->lport);
2412 * ice_add_vlan_internal - Add one VLAN based filter rule
2413 * @hw: pointer to the hardware structure
2414 * @recp_list: recipe list for which rule has to be added
2415 * @f_entry: filter entry containing one VLAN information
2417 static enum ice_status
2418 ice_add_vlan_internal(struct ice_hw *hw, struct ice_sw_recipe *recp_list,
2419 struct ice_fltr_list_entry *f_entry)
2421 struct ice_fltr_mgmt_list_entry *v_list_itr;
2422 struct ice_fltr_info *new_fltr, *cur_fltr;
2423 enum ice_sw_lkup_type lkup_type;
2424 u16 vsi_list_id = 0, vsi_handle;
2425 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2426 enum ice_status status = ICE_SUCCESS;
2428 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
2429 return ICE_ERR_PARAM;
2431 f_entry->fltr_info.fwd_id.hw_vsi_id =
2432 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
2433 new_fltr = &f_entry->fltr_info;
2435 /* VLAN ID should only be 12 bits */
2436 if (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)
2437 return ICE_ERR_PARAM;
2439 if (new_fltr->src_id != ICE_SRC_ID_VSI)
2440 return ICE_ERR_PARAM;
2442 new_fltr->src = new_fltr->fwd_id.hw_vsi_id;
2443 lkup_type = new_fltr->lkup_type;
2444 vsi_handle = new_fltr->vsi_handle;
2445 rule_lock = &recp_list->filt_rule_lock;
2446 ice_acquire_lock(rule_lock);
2447 v_list_itr = ice_find_rule_entry(&recp_list->filt_rules, new_fltr);
2449 struct ice_vsi_list_map_info *map_info = NULL;
2451 if (new_fltr->fltr_act == ICE_FWD_TO_VSI) {
2452 /* All VLAN pruning rules use a VSI list. Check if
2453 * there is already a VSI list containing VSI that we
2454 * want to add. If found, use the same vsi_list_id for
2455 * this new VLAN rule or else create a new list.
2457 map_info = ice_find_vsi_list_entry(recp_list,
2461 status = ice_create_vsi_list_rule(hw,
2469 /* Convert the action to forwarding to a VSI list. */
2470 new_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
2471 new_fltr->fwd_id.vsi_list_id = vsi_list_id;
2474 status = ice_create_pkt_fwd_rule(hw, recp_list, f_entry);
2476 v_list_itr = ice_find_rule_entry(&recp_list->filt_rules,
2479 status = ICE_ERR_DOES_NOT_EXIST;
2482 /* reuse VSI list for new rule and increment ref_cnt */
2484 v_list_itr->vsi_list_info = map_info;
2485 map_info->ref_cnt++;
2487 v_list_itr->vsi_list_info =
2488 ice_create_vsi_list_map(hw, &vsi_handle,
2492 } else if (v_list_itr->vsi_list_info->ref_cnt == 1) {
2493 /* Update existing VSI list to add new VSI ID only if it used
2496 cur_fltr = &v_list_itr->fltr_info;
2497 status = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr,
2500 /* If VLAN rule exists and VSI list being used by this rule is
2501 * referenced by more than 1 VLAN rule. Then create a new VSI
2502 * list appending previous VSI with new VSI and update existing
2503 * VLAN rule to point to new VSI list ID
2505 struct ice_fltr_info tmp_fltr;
2506 u16 vsi_handle_arr[2];
2509 /* Current implementation only supports reusing VSI list with
2510 * one VSI count. We should never hit below condition
2512 if (v_list_itr->vsi_count > 1 &&
2513 v_list_itr->vsi_list_info->ref_cnt > 1) {
2514 ice_debug(hw, ICE_DBG_SW,
2515 "Invalid configuration: Optimization to reuse VSI list with more than one VSI is not being done yet\n");
2516 status = ICE_ERR_CFG;
2521 ice_find_first_bit(v_list_itr->vsi_list_info->vsi_map,
2524 /* A rule already exists with the new VSI being added */
2525 if (cur_handle == vsi_handle) {
2526 status = ICE_ERR_ALREADY_EXISTS;
2530 vsi_handle_arr[0] = cur_handle;
2531 vsi_handle_arr[1] = vsi_handle;
2532 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
2533 &vsi_list_id, lkup_type);
2537 tmp_fltr = v_list_itr->fltr_info;
2538 tmp_fltr.fltr_rule_id = v_list_itr->fltr_info.fltr_rule_id;
2539 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
2540 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
2541 /* Update the previous switch rule to a new VSI list which
2542 * includes current VSI that is requested
2544 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
2548 /* before overriding VSI list map info. decrement ref_cnt of
2551 v_list_itr->vsi_list_info->ref_cnt--;
2553 /* now update to newly created list */
2554 v_list_itr->fltr_info.fwd_id.vsi_list_id = vsi_list_id;
2555 v_list_itr->vsi_list_info =
2556 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
2558 v_list_itr->vsi_count++;
2562 ice_release_lock(rule_lock);
2567 * ice_add_vlan_rule - Add VLAN based filter rule
2568 * @hw: pointer to the hardware structure
2569 * @v_list: list of VLAN entries and forwarding information
2570 * @sw: pointer to switch info struct for which function add rule
2572 static enum ice_status
2573 ice_add_vlan_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list,
2574 struct ice_switch_info *sw)
2576 struct ice_fltr_list_entry *v_list_itr;
2577 struct ice_sw_recipe *recp_list;
2579 recp_list = &sw->recp_list[ICE_SW_LKUP_VLAN];
2580 LIST_FOR_EACH_ENTRY(v_list_itr, v_list, ice_fltr_list_entry,
2582 if (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)
2583 return ICE_ERR_PARAM;
2584 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
2585 v_list_itr->status = ice_add_vlan_internal(hw, recp_list,
2587 if (v_list_itr->status)
2588 return v_list_itr->status;
2594 * ice_add_vlan - Add a VLAN based filter rule
2595 * @hw: pointer to the hardware structure
2596 * @v_list: list of VLAN and forwarding information
2598 * Function add VLAN rule for logical port from HW struct
2601 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2604 return ICE_ERR_PARAM;
2606 return ice_add_vlan_rule(hw, v_list, hw->switch_info);
2610 * ice_add_eth_mac_rule - Add ethertype and MAC based filter rule
2611 * @hw: pointer to the hardware structure
2612 * @em_list: list of ether type MAC filter, MAC is optional
2613 * @sw: pointer to switch info struct for which function add rule
2614 * @lport: logic port number on which function add rule
2616 * This function requires the caller to populate the entries in
2617 * the filter list with the necessary fields (including flags to
2618 * indicate Tx or Rx rules).
2620 static enum ice_status
2621 ice_add_eth_mac_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list,
2622 struct ice_switch_info *sw, u8 lport)
2624 struct ice_fltr_list_entry *em_list_itr;
2626 LIST_FOR_EACH_ENTRY(em_list_itr, em_list, ice_fltr_list_entry,
2628 struct ice_sw_recipe *recp_list;
2629 enum ice_sw_lkup_type l_type;
2631 l_type = em_list_itr->fltr_info.lkup_type;
2632 recp_list = &sw->recp_list[l_type];
2634 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
2635 l_type != ICE_SW_LKUP_ETHERTYPE)
2636 return ICE_ERR_PARAM;
2638 em_list_itr->status = ice_add_rule_internal(hw, recp_list,
2641 if (em_list_itr->status)
2642 return em_list_itr->status;
2649 * ice_add_eth_mac - Add a ethertype based filter rule
2650 * @hw: pointer to the hardware structure
2651 * @em_list: list of ethertype and forwarding information
2653 * Function add ethertype rule for logical port from HW struct
2655 ice_add_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
2657 if (!em_list || !hw)
2658 return ICE_ERR_PARAM;
2660 return ice_add_eth_mac_rule(hw, em_list, hw->switch_info,
2661 hw->port_info->lport);
2665 * ice_remove_eth_mac_rule - Remove an ethertype (or MAC) based filter rule
2666 * @hw: pointer to the hardware structure
2667 * @em_list: list of ethertype or ethertype MAC entries
2668 * @sw: pointer to switch info struct for which function add rule
2670 static enum ice_status
2671 ice_remove_eth_mac_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list,
2672 struct ice_switch_info *sw)
2674 struct ice_fltr_list_entry *em_list_itr, *tmp;
2676 LIST_FOR_EACH_ENTRY_SAFE(em_list_itr, tmp, em_list, ice_fltr_list_entry,
2678 struct ice_sw_recipe *recp_list;
2679 enum ice_sw_lkup_type l_type;
2681 l_type = em_list_itr->fltr_info.lkup_type;
2683 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
2684 l_type != ICE_SW_LKUP_ETHERTYPE)
2685 return ICE_ERR_PARAM;
2687 recp_list = &sw->recp_list[l_type];
2688 em_list_itr->status = ice_remove_rule_internal(hw, recp_list,
2690 if (em_list_itr->status)
2691 return em_list_itr->status;
2697 * ice_remove_eth_mac - remove a ethertype based filter rule
2698 * @hw: pointer to the hardware structure
2699 * @em_list: list of ethertype and forwarding information
2703 ice_remove_eth_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *em_list)
2705 if (!em_list || !hw)
2706 return ICE_ERR_PARAM;
2708 return ice_remove_eth_mac_rule(hw, em_list, hw->switch_info);
2712 * ice_rem_sw_rule_info
2713 * @hw: pointer to the hardware structure
2714 * @rule_head: pointer to the switch list structure that we want to delete
2717 ice_rem_sw_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
2719 if (!LIST_EMPTY(rule_head)) {
2720 struct ice_fltr_mgmt_list_entry *entry;
2721 struct ice_fltr_mgmt_list_entry *tmp;
2723 LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, rule_head,
2724 ice_fltr_mgmt_list_entry, list_entry) {
2725 LIST_DEL(&entry->list_entry);
2726 ice_free(hw, entry);
2732 * ice_rem_all_sw_rules_info
2733 * @hw: pointer to the hardware structure
2735 void ice_rem_all_sw_rules_info(struct ice_hw *hw)
2737 struct ice_switch_info *sw = hw->switch_info;
2740 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
2741 struct LIST_HEAD_TYPE *rule_head;
2743 rule_head = &sw->recp_list[i].filt_rules;
2744 if (!sw->recp_list[i].adv_rule)
2745 ice_rem_sw_rule_info(hw, rule_head);
2750 * ice_cfg_dflt_vsi - change state of VSI to set/clear default
2751 * @pi: pointer to the port_info structure
2752 * @vsi_handle: VSI handle to set as default
2753 * @set: true to add the above mentioned switch rule, false to remove it
2754 * @direction: ICE_FLTR_RX or ICE_FLTR_TX
2756 * add filter rule to set/unset given VSI as default VSI for the switch
2757 * (represented by swid)
2760 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
2763 struct ice_aqc_sw_rules_elem *s_rule;
2764 struct ice_fltr_info f_info;
2765 struct ice_hw *hw = pi->hw;
2766 enum ice_adminq_opc opcode;
2767 enum ice_status status;
2771 if (!ice_is_vsi_valid(hw, vsi_handle))
2772 return ICE_ERR_PARAM;
2773 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2775 s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
2776 ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
2777 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
2779 return ICE_ERR_NO_MEMORY;
2781 ice_memset(&f_info, 0, sizeof(f_info), ICE_NONDMA_MEM);
2783 f_info.lkup_type = ICE_SW_LKUP_DFLT;
2784 f_info.flag = direction;
2785 f_info.fltr_act = ICE_FWD_TO_VSI;
2786 f_info.fwd_id.hw_vsi_id = hw_vsi_id;
2788 if (f_info.flag & ICE_FLTR_RX) {
2789 f_info.src = pi->lport;
2790 f_info.src_id = ICE_SRC_ID_LPORT;
2792 f_info.fltr_rule_id =
2793 pi->dflt_rx_vsi_rule_id;
2794 } else if (f_info.flag & ICE_FLTR_TX) {
2795 f_info.src_id = ICE_SRC_ID_VSI;
2796 f_info.src = hw_vsi_id;
2798 f_info.fltr_rule_id =
2799 pi->dflt_tx_vsi_rule_id;
2803 opcode = ice_aqc_opc_add_sw_rules;
2805 opcode = ice_aqc_opc_remove_sw_rules;
2807 ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
2809 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
2810 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
2813 u16 index = LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
2815 if (f_info.flag & ICE_FLTR_TX) {
2816 pi->dflt_tx_vsi_num = hw_vsi_id;
2817 pi->dflt_tx_vsi_rule_id = index;
2818 } else if (f_info.flag & ICE_FLTR_RX) {
2819 pi->dflt_rx_vsi_num = hw_vsi_id;
2820 pi->dflt_rx_vsi_rule_id = index;
2823 if (f_info.flag & ICE_FLTR_TX) {
2824 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
2825 pi->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
2826 } else if (f_info.flag & ICE_FLTR_RX) {
2827 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
2828 pi->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
2833 ice_free(hw, s_rule);
2838 * ice_find_ucast_rule_entry - Search for a unicast MAC filter rule entry
2839 * @list_head: head of rule list
2840 * @f_info: rule information
2842 * Helper function to search for a unicast rule entry - this is to be used
2843 * to remove unicast MAC filter that is not shared with other VSIs on the
2846 * Returns pointer to entry storing the rule if found
2848 static struct ice_fltr_mgmt_list_entry *
2849 ice_find_ucast_rule_entry(struct LIST_HEAD_TYPE *list_head,
2850 struct ice_fltr_info *f_info)
2852 struct ice_fltr_mgmt_list_entry *list_itr;
2854 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
2856 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
2857 sizeof(f_info->l_data)) &&
2858 f_info->fwd_id.hw_vsi_id ==
2859 list_itr->fltr_info.fwd_id.hw_vsi_id &&
2860 f_info->flag == list_itr->fltr_info.flag)
2867 * ice_remove_mac_rule - remove a MAC based filter rule
2868 * @hw: pointer to the hardware structure
2869 * @m_list: list of MAC addresses and forwarding information
2870 * @recp_list: list from which function remove MAC address
2872 * This function removes either a MAC filter rule or a specific VSI from a
2873 * VSI list for a multicast MAC address.
2875 * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by
2876 * ice_add_mac. Caller should be aware that this call will only work if all
2877 * the entries passed into m_list were added previously. It will not attempt to
2878 * do a partial remove of entries that were found.
2880 static enum ice_status
2881 ice_remove_mac_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list,
2882 struct ice_sw_recipe *recp_list)
2884 struct ice_fltr_list_entry *list_itr, *tmp;
2885 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2888 return ICE_ERR_PARAM;
2890 rule_lock = &recp_list->filt_rule_lock;
2891 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, m_list, ice_fltr_list_entry,
2893 enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
2894 u8 *add = &list_itr->fltr_info.l_data.mac.mac_addr[0];
2897 if (l_type != ICE_SW_LKUP_MAC)
2898 return ICE_ERR_PARAM;
2900 vsi_handle = list_itr->fltr_info.vsi_handle;
2901 if (!ice_is_vsi_valid(hw, vsi_handle))
2902 return ICE_ERR_PARAM;
2904 list_itr->fltr_info.fwd_id.hw_vsi_id =
2905 ice_get_hw_vsi_num(hw, vsi_handle);
2906 if (IS_UNICAST_ETHER_ADDR(add) && !hw->ucast_shared) {
2907 /* Don't remove the unicast address that belongs to
2908 * another VSI on the switch, since it is not being
2911 ice_acquire_lock(rule_lock);
2912 if (!ice_find_ucast_rule_entry(&recp_list->filt_rules,
2913 &list_itr->fltr_info)) {
2914 ice_release_lock(rule_lock);
2915 return ICE_ERR_DOES_NOT_EXIST;
2917 ice_release_lock(rule_lock);
2919 list_itr->status = ice_remove_rule_internal(hw, recp_list,
2921 if (list_itr->status)
2922 return list_itr->status;
2928 * ice_remove_mac - remove a MAC address based filter rule
2929 * @hw: pointer to the hardware structure
2930 * @m_list: list of MAC addresses and forwarding information
2934 ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2936 struct ice_sw_recipe *recp_list;
2938 recp_list = &hw->switch_info->recp_list[ICE_SW_LKUP_MAC];
2939 return ice_remove_mac_rule(hw, m_list, recp_list);
2943 * ice_remove_vlan_rule - Remove VLAN based filter rule
2944 * @hw: pointer to the hardware structure
2945 * @v_list: list of VLAN entries and forwarding information
2946 * @recp_list: list from which function remove VLAN
2948 static enum ice_status
2949 ice_remove_vlan_rule(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list,
2950 struct ice_sw_recipe *recp_list)
2952 struct ice_fltr_list_entry *v_list_itr, *tmp;
2954 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2956 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2958 if (l_type != ICE_SW_LKUP_VLAN)
2959 return ICE_ERR_PARAM;
2960 v_list_itr->status = ice_remove_rule_internal(hw, recp_list,
2962 if (v_list_itr->status)
2963 return v_list_itr->status;
2969 * ice_remove_vlan - remove a VLAN address based filter rule
2970 * @hw: pointer to the hardware structure
2971 * @v_list: list of VLAN and forwarding information
2975 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2977 struct ice_sw_recipe *recp_list;
2980 return ICE_ERR_PARAM;
2982 recp_list = &hw->switch_info->recp_list[ICE_SW_LKUP_VLAN];
2983 return ice_remove_vlan_rule(hw, v_list, recp_list);
2987 * ice_vsi_uses_fltr - Determine if given VSI uses specified filter
2988 * @fm_entry: filter entry to inspect
2989 * @vsi_handle: VSI handle to compare with filter info
2992 ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle)
2994 return ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&
2995 fm_entry->fltr_info.vsi_handle == vsi_handle) ||
2996 (fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&
2997 (ice_is_bit_set(fm_entry->vsi_list_info->vsi_map,
3002 * ice_add_entry_to_vsi_fltr_list - Add copy of fltr_list_entry to remove list
3003 * @hw: pointer to the hardware structure
3004 * @vsi_handle: VSI handle to remove filters from
3005 * @vsi_list_head: pointer to the list to add entry to
3006 * @fi: pointer to fltr_info of filter entry to copy & add
3008 * Helper function, used when creating a list of filters to remove from
3009 * a specific VSI. The entry added to vsi_list_head is a COPY of the
3010 * original filter entry, with the exception of fltr_info.fltr_act and
3011 * fltr_info.fwd_id fields. These are set such that later logic can
3012 * extract which VSI to remove the fltr from, and pass on that information.
3014 static enum ice_status
3015 ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
3016 struct LIST_HEAD_TYPE *vsi_list_head,
3017 struct ice_fltr_info *fi)
3019 struct ice_fltr_list_entry *tmp;
3021 /* this memory is freed up in the caller function
3022 * once filters for this VSI are removed
3024 tmp = (struct ice_fltr_list_entry *)ice_malloc(hw, sizeof(*tmp));
3026 return ICE_ERR_NO_MEMORY;
3028 tmp->fltr_info = *fi;
3030 /* Overwrite these fields to indicate which VSI to remove filter from,
3031 * so find and remove logic can extract the information from the
3032 * list entries. Note that original entries will still have proper
3035 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
3036 tmp->fltr_info.vsi_handle = vsi_handle;
3037 tmp->fltr_info.fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3039 LIST_ADD(&tmp->list_entry, vsi_list_head);
3045 * ice_add_to_vsi_fltr_list - Add VSI filters to the list
3046 * @hw: pointer to the hardware structure
3047 * @vsi_handle: VSI handle to remove filters from
3048 * @lkup_list_head: pointer to the list that has certain lookup type filters
3049 * @vsi_list_head: pointer to the list pertaining to VSI with vsi_handle
3051 * Locates all filters in lkup_list_head that are used by the given VSI,
3052 * and adds COPIES of those entries to vsi_list_head (intended to be used
3053 * to remove the listed filters).
3054 * Note that this means all entries in vsi_list_head must be explicitly
3055 * deallocated by the caller when done with list.
3057 static enum ice_status
3058 ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
3059 struct LIST_HEAD_TYPE *lkup_list_head,
3060 struct LIST_HEAD_TYPE *vsi_list_head)
3062 struct ice_fltr_mgmt_list_entry *fm_entry;
3063 enum ice_status status = ICE_SUCCESS;
3065 /* check to make sure VSI ID is valid and within boundary */
3066 if (!ice_is_vsi_valid(hw, vsi_handle))
3067 return ICE_ERR_PARAM;
3069 LIST_FOR_EACH_ENTRY(fm_entry, lkup_list_head,
3070 ice_fltr_mgmt_list_entry, list_entry) {
3071 struct ice_fltr_info *fi;
3073 fi = &fm_entry->fltr_info;
3074 if (!fi || !ice_vsi_uses_fltr(fm_entry, vsi_handle))
3077 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
3086 * ice_determine_promisc_mask
3087 * @fi: filter info to parse
3089 * Helper function to determine which ICE_PROMISC_ mask corresponds
3090 * to given filter into.
3092 static u8 ice_determine_promisc_mask(struct ice_fltr_info *fi)
3094 u16 vid = fi->l_data.mac_vlan.vlan_id;
3095 u8 *macaddr = fi->l_data.mac.mac_addr;
3096 bool is_tx_fltr = false;
3097 u8 promisc_mask = 0;
3099 if (fi->flag == ICE_FLTR_TX)
3102 if (IS_BROADCAST_ETHER_ADDR(macaddr))
3103 promisc_mask |= is_tx_fltr ?
3104 ICE_PROMISC_BCAST_TX : ICE_PROMISC_BCAST_RX;
3105 else if (IS_MULTICAST_ETHER_ADDR(macaddr))
3106 promisc_mask |= is_tx_fltr ?
3107 ICE_PROMISC_MCAST_TX : ICE_PROMISC_MCAST_RX;
3108 else if (IS_UNICAST_ETHER_ADDR(macaddr))
3109 promisc_mask |= is_tx_fltr ?
3110 ICE_PROMISC_UCAST_TX : ICE_PROMISC_UCAST_RX;
3112 promisc_mask |= is_tx_fltr ?
3113 ICE_PROMISC_VLAN_TX : ICE_PROMISC_VLAN_RX;
3115 return promisc_mask;
3119 * ice_get_vsi_promisc - get promiscuous mode of given VSI
3120 * @hw: pointer to the hardware structure
3121 * @vsi_handle: VSI handle to retrieve info from
3122 * @promisc_mask: pointer to mask to be filled in
3123 * @vid: VLAN ID of promisc VLAN VSI
3126 ice_get_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
3129 struct ice_switch_info *sw = hw->switch_info;
3130 struct ice_fltr_mgmt_list_entry *itr;
3131 struct LIST_HEAD_TYPE *rule_head;
3132 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3134 if (!ice_is_vsi_valid(hw, vsi_handle))
3135 return ICE_ERR_PARAM;
3139 rule_head = &sw->recp_list[ICE_SW_LKUP_PROMISC].filt_rules;
3140 rule_lock = &sw->recp_list[ICE_SW_LKUP_PROMISC].filt_rule_lock;
3142 ice_acquire_lock(rule_lock);
3143 LIST_FOR_EACH_ENTRY(itr, rule_head,
3144 ice_fltr_mgmt_list_entry, list_entry) {
3145 /* Continue if this filter doesn't apply to this VSI or the
3146 * VSI ID is not in the VSI map for this filter
3148 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3151 *promisc_mask |= ice_determine_promisc_mask(&itr->fltr_info);
3153 ice_release_lock(rule_lock);
3159 * ice_get_vsi_vlan_promisc - get VLAN promiscuous mode of given VSI
3160 * @hw: pointer to the hardware structure
3161 * @vsi_handle: VSI handle to retrieve info from
3162 * @promisc_mask: pointer to mask to be filled in
3163 * @vid: VLAN ID of promisc VLAN VSI
3166 ice_get_vsi_vlan_promisc(struct ice_hw *hw, u16 vsi_handle, u8 *promisc_mask,
3169 struct ice_switch_info *sw = hw->switch_info;
3170 struct ice_fltr_mgmt_list_entry *itr;
3171 struct LIST_HEAD_TYPE *rule_head;
3172 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3174 if (!ice_is_vsi_valid(hw, vsi_handle))
3175 return ICE_ERR_PARAM;
3179 rule_head = &sw->recp_list[ICE_SW_LKUP_PROMISC_VLAN].filt_rules;
3180 rule_lock = &sw->recp_list[ICE_SW_LKUP_PROMISC_VLAN].filt_rule_lock;
3182 ice_acquire_lock(rule_lock);
3183 LIST_FOR_EACH_ENTRY(itr, rule_head, ice_fltr_mgmt_list_entry,
3185 /* Continue if this filter doesn't apply to this VSI or the
3186 * VSI ID is not in the VSI map for this filter
3188 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3191 *promisc_mask |= ice_determine_promisc_mask(&itr->fltr_info);
3193 ice_release_lock(rule_lock);
3199 * ice_remove_promisc - Remove promisc based filter rules
3200 * @hw: pointer to the hardware structure
3201 * @recp_id: recipe ID for which the rule needs to removed
3202 * @v_list: list of promisc entries
3204 static enum ice_status
3205 ice_remove_promisc(struct ice_hw *hw, u8 recp_id,
3206 struct LIST_HEAD_TYPE *v_list)
3208 struct ice_fltr_list_entry *v_list_itr, *tmp;
3209 struct ice_sw_recipe *recp_list;
3211 recp_list = &hw->switch_info->recp_list[recp_id];
3212 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
3214 v_list_itr->status =
3215 ice_remove_rule_internal(hw, recp_list, v_list_itr);
3216 if (v_list_itr->status)
3217 return v_list_itr->status;
3223 * ice_clear_vsi_promisc - clear specified promiscuous mode(s) for given VSI
3224 * @hw: pointer to the hardware structure
3225 * @vsi_handle: VSI handle to clear mode
3226 * @promisc_mask: mask of promiscuous config bits to clear
3227 * @vid: VLAN ID to clear VLAN promiscuous
3230 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
3233 struct ice_switch_info *sw = hw->switch_info;
3234 struct ice_fltr_list_entry *fm_entry, *tmp;
3235 struct LIST_HEAD_TYPE remove_list_head;
3236 struct ice_fltr_mgmt_list_entry *itr;
3237 struct LIST_HEAD_TYPE *rule_head;
3238 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3239 enum ice_status status = ICE_SUCCESS;
3242 if (!ice_is_vsi_valid(hw, vsi_handle))
3243 return ICE_ERR_PARAM;
3245 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX))
3246 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
3248 recipe_id = ICE_SW_LKUP_PROMISC;
3250 rule_head = &sw->recp_list[recipe_id].filt_rules;
3251 rule_lock = &sw->recp_list[recipe_id].filt_rule_lock;
3253 INIT_LIST_HEAD(&remove_list_head);
3255 ice_acquire_lock(rule_lock);
3256 LIST_FOR_EACH_ENTRY(itr, rule_head,
3257 ice_fltr_mgmt_list_entry, list_entry) {
3258 struct ice_fltr_info *fltr_info;
3259 u8 fltr_promisc_mask = 0;
3261 if (!ice_vsi_uses_fltr(itr, vsi_handle))
3263 fltr_info = &itr->fltr_info;
3265 if (recipe_id == ICE_SW_LKUP_PROMISC_VLAN &&
3266 vid != fltr_info->l_data.mac_vlan.vlan_id)
3269 fltr_promisc_mask |= ice_determine_promisc_mask(fltr_info);
3271 /* Skip if filter is not completely specified by given mask */
3272 if (fltr_promisc_mask & ~promisc_mask)
3275 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
3279 ice_release_lock(rule_lock);
3280 goto free_fltr_list;
3283 ice_release_lock(rule_lock);
3285 status = ice_remove_promisc(hw, recipe_id, &remove_list_head);
3288 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
3289 ice_fltr_list_entry, list_entry) {
3290 LIST_DEL(&fm_entry->list_entry);
3291 ice_free(hw, fm_entry);
3298 * ice_set_vsi_promisc - set given VSI to given promiscuous mode(s)
3299 * @hw: pointer to the hardware structure
3300 * @vsi_handle: VSI handle to configure
3301 * @promisc_mask: mask of promiscuous config bits
3302 * @vid: VLAN ID to set VLAN promiscuous
3305 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, u16 vid)
3307 enum { UCAST_FLTR = 1, MCAST_FLTR, BCAST_FLTR };
3308 struct ice_fltr_list_entry f_list_entry;
3309 struct ice_fltr_info new_fltr;
3310 enum ice_status status = ICE_SUCCESS;
3316 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3318 if (!ice_is_vsi_valid(hw, vsi_handle))
3319 return ICE_ERR_PARAM;
3320 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3322 ice_memset(&new_fltr, 0, sizeof(new_fltr), ICE_NONDMA_MEM);
3324 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX)) {
3325 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC_VLAN;
3326 new_fltr.l_data.mac_vlan.vlan_id = vid;
3327 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
3329 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC;
3330 recipe_id = ICE_SW_LKUP_PROMISC;
3333 /* Separate filters must be set for each direction/packet type
3334 * combination, so we will loop over the mask value, store the
3335 * individual type, and clear it out in the input mask as it
3338 while (promisc_mask) {
3339 struct ice_sw_recipe *recp_list;
3345 if (promisc_mask & ICE_PROMISC_UCAST_RX) {
3346 promisc_mask &= ~ICE_PROMISC_UCAST_RX;
3347 pkt_type = UCAST_FLTR;
3348 } else if (promisc_mask & ICE_PROMISC_UCAST_TX) {
3349 promisc_mask &= ~ICE_PROMISC_UCAST_TX;
3350 pkt_type = UCAST_FLTR;
3352 } else if (promisc_mask & ICE_PROMISC_MCAST_RX) {
3353 promisc_mask &= ~ICE_PROMISC_MCAST_RX;
3354 pkt_type = MCAST_FLTR;
3355 } else if (promisc_mask & ICE_PROMISC_MCAST_TX) {
3356 promisc_mask &= ~ICE_PROMISC_MCAST_TX;
3357 pkt_type = MCAST_FLTR;
3359 } else if (promisc_mask & ICE_PROMISC_BCAST_RX) {
3360 promisc_mask &= ~ICE_PROMISC_BCAST_RX;
3361 pkt_type = BCAST_FLTR;
3362 } else if (promisc_mask & ICE_PROMISC_BCAST_TX) {
3363 promisc_mask &= ~ICE_PROMISC_BCAST_TX;
3364 pkt_type = BCAST_FLTR;
3368 /* Check for VLAN promiscuous flag */
3369 if (promisc_mask & ICE_PROMISC_VLAN_RX) {
3370 promisc_mask &= ~ICE_PROMISC_VLAN_RX;
3371 } else if (promisc_mask & ICE_PROMISC_VLAN_TX) {
3372 promisc_mask &= ~ICE_PROMISC_VLAN_TX;
3376 /* Set filter DA based on packet type */
3377 mac_addr = new_fltr.l_data.mac.mac_addr;
3378 if (pkt_type == BCAST_FLTR) {
3379 ice_memset(mac_addr, 0xff, ETH_ALEN, ICE_NONDMA_MEM);
3380 } else if (pkt_type == MCAST_FLTR ||
3381 pkt_type == UCAST_FLTR) {
3382 /* Use the dummy ether header DA */
3383 ice_memcpy(mac_addr, dummy_eth_header, ETH_ALEN,
3384 ICE_NONDMA_TO_NONDMA);
3385 if (pkt_type == MCAST_FLTR)
3386 mac_addr[0] |= 0x1; /* Set multicast bit */
3389 /* Need to reset this to zero for all iterations */
3392 new_fltr.flag |= ICE_FLTR_TX;
3393 new_fltr.src = hw_vsi_id;
3395 new_fltr.flag |= ICE_FLTR_RX;
3396 new_fltr.src = hw->port_info->lport;
3399 new_fltr.fltr_act = ICE_FWD_TO_VSI;
3400 new_fltr.vsi_handle = vsi_handle;
3401 new_fltr.fwd_id.hw_vsi_id = hw_vsi_id;
3402 f_list_entry.fltr_info = new_fltr;
3403 recp_list = &hw->switch_info->recp_list[recipe_id];
3405 status = ice_add_rule_internal(hw, recp_list,
3406 hw->port_info->lport,
3408 if (status != ICE_SUCCESS)
3409 goto set_promisc_exit;
3417 * ice_set_vlan_vsi_promisc
3418 * @hw: pointer to the hardware structure
3419 * @vsi_handle: VSI handle to configure
3420 * @promisc_mask: mask of promiscuous config bits
3421 * @rm_vlan_promisc: Clear VLANs VSI promisc mode
3423 * Configure VSI with all associated VLANs to given promiscuous mode(s)
3426 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
3427 bool rm_vlan_promisc)
3429 struct ice_switch_info *sw = hw->switch_info;
3430 struct ice_fltr_list_entry *list_itr, *tmp;
3431 struct LIST_HEAD_TYPE vsi_list_head;
3432 struct LIST_HEAD_TYPE *vlan_head;
3433 struct ice_lock *vlan_lock; /* Lock to protect filter rule list */
3434 enum ice_status status;
3437 INIT_LIST_HEAD(&vsi_list_head);
3438 vlan_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
3439 vlan_head = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rules;
3440 ice_acquire_lock(vlan_lock);
3441 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, vlan_head,
3443 ice_release_lock(vlan_lock);
3445 goto free_fltr_list;
3447 LIST_FOR_EACH_ENTRY(list_itr, &vsi_list_head, ice_fltr_list_entry,
3449 vlan_id = list_itr->fltr_info.l_data.vlan.vlan_id;
3450 if (rm_vlan_promisc)
3451 status = ice_clear_vsi_promisc(hw, vsi_handle,
3452 promisc_mask, vlan_id);
3454 status = ice_set_vsi_promisc(hw, vsi_handle,
3455 promisc_mask, vlan_id);
3461 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, &vsi_list_head,
3462 ice_fltr_list_entry, list_entry) {
3463 LIST_DEL(&list_itr->list_entry);
3464 ice_free(hw, list_itr);
3470 * ice_remove_vsi_lkup_fltr - Remove lookup type filters for a VSI
3471 * @hw: pointer to the hardware structure
3472 * @vsi_handle: VSI handle to remove filters from
3473 * @recp_list: recipe list from which function remove fltr
3474 * @lkup: switch rule filter lookup type
3477 ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
3478 struct ice_sw_recipe *recp_list,
3479 enum ice_sw_lkup_type lkup)
3481 struct ice_fltr_list_entry *fm_entry;
3482 struct LIST_HEAD_TYPE remove_list_head;
3483 struct LIST_HEAD_TYPE *rule_head;
3484 struct ice_fltr_list_entry *tmp;
3485 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3486 enum ice_status status;
3488 INIT_LIST_HEAD(&remove_list_head);
3489 rule_lock = &recp_list[lkup].filt_rule_lock;
3490 rule_head = &recp_list[lkup].filt_rules;
3491 ice_acquire_lock(rule_lock);
3492 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, rule_head,
3494 ice_release_lock(rule_lock);
3499 case ICE_SW_LKUP_MAC:
3500 ice_remove_mac_rule(hw, &remove_list_head, &recp_list[lkup]);
3502 case ICE_SW_LKUP_VLAN:
3503 ice_remove_vlan_rule(hw, &remove_list_head, &recp_list[lkup]);
3505 case ICE_SW_LKUP_PROMISC:
3506 case ICE_SW_LKUP_PROMISC_VLAN:
3507 ice_remove_promisc(hw, lkup, &remove_list_head);
3509 case ICE_SW_LKUP_MAC_VLAN:
3510 ice_debug(hw, ICE_DBG_SW, "MAC VLAN look up is not supported yet\n");
3512 case ICE_SW_LKUP_ETHERTYPE:
3513 case ICE_SW_LKUP_ETHERTYPE_MAC:
3514 ice_remove_eth_mac(hw, &remove_list_head);
3516 case ICE_SW_LKUP_DFLT:
3517 ice_debug(hw, ICE_DBG_SW,
3518 "Remove filters for this lookup type hasn't been implemented yet\n");
3520 case ICE_SW_LKUP_LAST:
3521 ice_debug(hw, ICE_DBG_SW, "Unsupported lookup type\n");
3525 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
3526 ice_fltr_list_entry, list_entry) {
3527 LIST_DEL(&fm_entry->list_entry);
3528 ice_free(hw, fm_entry);
3533 * ice_remove_vsi_fltr_rule - Remove all filters for a VSI
3534 * @hw: pointer to the hardware structure
3535 * @vsi_handle: VSI handle to remove filters from
3536 * @sw: pointer to switch info struct
3539 ice_remove_vsi_fltr_rule(struct ice_hw *hw, u16 vsi_handle,
3540 struct ice_switch_info *sw)
3542 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3544 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3545 sw->recp_list, ICE_SW_LKUP_MAC);
3546 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3547 sw->recp_list, ICE_SW_LKUP_MAC_VLAN);
3548 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3549 sw->recp_list, ICE_SW_LKUP_PROMISC);
3550 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3551 sw->recp_list, ICE_SW_LKUP_VLAN);
3552 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3553 sw->recp_list, ICE_SW_LKUP_DFLT);
3554 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3555 sw->recp_list, ICE_SW_LKUP_ETHERTYPE);
3556 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3557 sw->recp_list, ICE_SW_LKUP_ETHERTYPE_MAC);
3558 ice_remove_vsi_lkup_fltr(hw, vsi_handle,
3559 sw->recp_list, ICE_SW_LKUP_PROMISC_VLAN);
3563 * ice_remove_vsi_fltr - Remove all filters for a VSI
3564 * @hw: pointer to the hardware structure
3565 * @vsi_handle: VSI handle to remove filters from
3567 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle)
3569 ice_remove_vsi_fltr_rule(hw, vsi_handle, hw->switch_info);
3573 * ice_alloc_res_cntr - allocating resource counter
3574 * @hw: pointer to the hardware structure
3575 * @type: type of resource
3576 * @alloc_shared: if set it is shared else dedicated
3577 * @num_items: number of entries requested for FD resource type
3578 * @counter_id: counter index returned by AQ call
3580 static enum ice_status
3581 ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
3584 struct ice_aqc_alloc_free_res_elem *buf;
3585 enum ice_status status;
3588 /* Allocate resource */
3589 buf_len = sizeof(*buf);
3590 buf = (struct ice_aqc_alloc_free_res_elem *)
3591 ice_malloc(hw, buf_len);
3593 return ICE_ERR_NO_MEMORY;
3595 buf->num_elems = CPU_TO_LE16(num_items);
3596 buf->res_type = CPU_TO_LE16(((type << ICE_AQC_RES_TYPE_S) &
3597 ICE_AQC_RES_TYPE_M) | alloc_shared);
3599 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
3600 ice_aqc_opc_alloc_res, NULL);
3604 *counter_id = LE16_TO_CPU(buf->elem[0].e.sw_resp);
3612 * ice_free_res_cntr - free resource counter
3613 * @hw: pointer to the hardware structure
3614 * @type: type of resource
3615 * @alloc_shared: if set it is shared else dedicated
3616 * @num_items: number of entries to be freed for FD resource type
3617 * @counter_id: counter ID resource which needs to be freed
3619 static enum ice_status
3620 ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
3623 struct ice_aqc_alloc_free_res_elem *buf;
3624 enum ice_status status;
3628 buf_len = sizeof(*buf);
3629 buf = (struct ice_aqc_alloc_free_res_elem *)
3630 ice_malloc(hw, buf_len);
3632 return ICE_ERR_NO_MEMORY;
3634 buf->num_elems = CPU_TO_LE16(num_items);
3635 buf->res_type = CPU_TO_LE16(((type << ICE_AQC_RES_TYPE_S) &
3636 ICE_AQC_RES_TYPE_M) | alloc_shared);
3637 buf->elem[0].e.sw_resp = CPU_TO_LE16(counter_id);
3639 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
3640 ice_aqc_opc_free_res, NULL);
3642 ice_debug(hw, ICE_DBG_SW,
3643 "counter resource could not be freed\n");
3650 * ice_alloc_vlan_res_counter - obtain counter resource for VLAN type
3651 * @hw: pointer to the hardware structure
3652 * @counter_id: returns counter index
3654 enum ice_status ice_alloc_vlan_res_counter(struct ice_hw *hw, u16 *counter_id)
3656 return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_VLAN_COUNTER,
3657 ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1,
3662 * ice_free_vlan_res_counter - Free counter resource for VLAN type
3663 * @hw: pointer to the hardware structure
3664 * @counter_id: counter index to be freed
3666 enum ice_status ice_free_vlan_res_counter(struct ice_hw *hw, u16 counter_id)
3668 return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_VLAN_COUNTER,
3669 ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1,
3674 * ice_alloc_res_lg_act - add large action resource
3675 * @hw: pointer to the hardware structure
3676 * @l_id: large action ID to fill it in
3677 * @num_acts: number of actions to hold with a large action entry
3679 static enum ice_status
3680 ice_alloc_res_lg_act(struct ice_hw *hw, u16 *l_id, u16 num_acts)
3682 struct ice_aqc_alloc_free_res_elem *sw_buf;
3683 enum ice_status status;
3686 if (num_acts > ICE_MAX_LG_ACT || num_acts == 0)
3687 return ICE_ERR_PARAM;
3689 /* Allocate resource for large action */
3690 buf_len = sizeof(*sw_buf);
3691 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
3692 ice_malloc(hw, buf_len);
3694 return ICE_ERR_NO_MEMORY;
3696 sw_buf->num_elems = CPU_TO_LE16(1);
3698 /* If num_acts is 1, use ICE_AQC_RES_TYPE_WIDE_TABLE_1.
3699 * If num_acts is 2, use ICE_AQC_RES_TYPE_WIDE_TABLE_3.
3700 * If num_acts is greater than 2, then use
3701 * ICE_AQC_RES_TYPE_WIDE_TABLE_4.
3702 * The num_acts cannot exceed 4. This was ensured at the
3703 * beginning of the function.
3706 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_1);
3707 else if (num_acts == 2)
3708 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_2);
3710 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_WIDE_TABLE_4);
3712 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len,
3713 ice_aqc_opc_alloc_res, NULL);
3715 *l_id = LE16_TO_CPU(sw_buf->elem[0].e.sw_resp);
3717 ice_free(hw, sw_buf);
3722 * ice_add_mac_with_sw_marker - add filter with sw marker
3723 * @hw: pointer to the hardware structure
3724 * @f_info: filter info structure containing the MAC filter information
3725 * @sw_marker: sw marker to tag the Rx descriptor with
3728 ice_add_mac_with_sw_marker(struct ice_hw *hw, struct ice_fltr_info *f_info,
3731 struct ice_fltr_mgmt_list_entry *m_entry;
3732 struct ice_fltr_list_entry fl_info;
3733 struct ice_sw_recipe *recp_list;
3734 struct LIST_HEAD_TYPE l_head;
3735 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3736 enum ice_status ret;
3740 if (f_info->fltr_act != ICE_FWD_TO_VSI)
3741 return ICE_ERR_PARAM;
3743 if (f_info->lkup_type != ICE_SW_LKUP_MAC)
3744 return ICE_ERR_PARAM;
3746 if (sw_marker == ICE_INVAL_SW_MARKER_ID)
3747 return ICE_ERR_PARAM;
3749 if (!ice_is_vsi_valid(hw, f_info->vsi_handle))
3750 return ICE_ERR_PARAM;
3751 f_info->fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, f_info->vsi_handle);
3753 /* Add filter if it doesn't exist so then the adding of large
3754 * action always results in update
3757 INIT_LIST_HEAD(&l_head);
3758 fl_info.fltr_info = *f_info;
3759 LIST_ADD(&fl_info.list_entry, &l_head);
3761 entry_exists = false;
3762 ret = ice_add_mac_rule(hw, &l_head, hw->switch_info,
3763 hw->port_info->lport);
3764 if (ret == ICE_ERR_ALREADY_EXISTS)
3765 entry_exists = true;
3769 recp_list = &hw->switch_info->recp_list[ICE_SW_LKUP_MAC];
3770 rule_lock = &recp_list->filt_rule_lock;
3771 ice_acquire_lock(rule_lock);
3772 /* Get the book keeping entry for the filter */
3773 m_entry = ice_find_rule_entry(&recp_list->filt_rules, f_info);
3777 /* If counter action was enabled for this rule then don't enable
3778 * sw marker large action
3780 if (m_entry->counter_index != ICE_INVAL_COUNTER_ID) {
3781 ret = ICE_ERR_PARAM;
3785 /* if same marker was added before */
3786 if (m_entry->sw_marker_id == sw_marker) {
3787 ret = ICE_ERR_ALREADY_EXISTS;
3791 /* Allocate a hardware table entry to hold large act. Three actions
3792 * for marker based large action
3794 ret = ice_alloc_res_lg_act(hw, &lg_act_id, 3);
3798 if (lg_act_id == ICE_INVAL_LG_ACT_INDEX)
3801 /* Update the switch rule to add the marker action */
3802 ret = ice_add_marker_act(hw, m_entry, sw_marker, lg_act_id);
3804 ice_release_lock(rule_lock);
3809 ice_release_lock(rule_lock);
3810 /* only remove entry if it did not exist previously */
3812 ret = ice_remove_mac(hw, &l_head);
3818 * ice_add_mac_with_counter - add filter with counter enabled
3819 * @hw: pointer to the hardware structure
3820 * @f_info: pointer to filter info structure containing the MAC filter
3824 ice_add_mac_with_counter(struct ice_hw *hw, struct ice_fltr_info *f_info)
3826 struct ice_fltr_mgmt_list_entry *m_entry;
3827 struct ice_fltr_list_entry fl_info;
3828 struct ice_sw_recipe *recp_list;
3829 struct LIST_HEAD_TYPE l_head;
3830 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
3831 enum ice_status ret;
3836 if (f_info->fltr_act != ICE_FWD_TO_VSI)
3837 return ICE_ERR_PARAM;
3839 if (f_info->lkup_type != ICE_SW_LKUP_MAC)
3840 return ICE_ERR_PARAM;
3842 if (!ice_is_vsi_valid(hw, f_info->vsi_handle))
3843 return ICE_ERR_PARAM;
3844 f_info->fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, f_info->vsi_handle);
3845 recp_list = &hw->switch_info->recp_list[ICE_SW_LKUP_MAC];
3847 entry_exist = false;
3849 rule_lock = &recp_list->filt_rule_lock;
3851 /* Add filter if it doesn't exist so then the adding of large
3852 * action always results in update
3854 INIT_LIST_HEAD(&l_head);
3856 fl_info.fltr_info = *f_info;
3857 LIST_ADD(&fl_info.list_entry, &l_head);
3859 ret = ice_add_mac_rule(hw, &l_head, hw->switch_info,
3860 hw->port_info->lport);
3861 if (ret == ICE_ERR_ALREADY_EXISTS)
3866 ice_acquire_lock(rule_lock);
3867 m_entry = ice_find_rule_entry(&recp_list->filt_rules, f_info);
3869 ret = ICE_ERR_BAD_PTR;
3873 /* Don't enable counter for a filter for which sw marker was enabled */
3874 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID) {
3875 ret = ICE_ERR_PARAM;
3879 /* If a counter was already enabled then don't need to add again */
3880 if (m_entry->counter_index != ICE_INVAL_COUNTER_ID) {
3881 ret = ICE_ERR_ALREADY_EXISTS;
3885 /* Allocate a hardware table entry to VLAN counter */
3886 ret = ice_alloc_vlan_res_counter(hw, &counter_id);
3890 /* Allocate a hardware table entry to hold large act. Two actions for
3891 * counter based large action
3893 ret = ice_alloc_res_lg_act(hw, &lg_act_id, 2);
3897 if (lg_act_id == ICE_INVAL_LG_ACT_INDEX)
3900 /* Update the switch rule to add the counter action */
3901 ret = ice_add_counter_act(hw, m_entry, counter_id, lg_act_id);
3903 ice_release_lock(rule_lock);
3908 ice_release_lock(rule_lock);
3909 /* only remove entry if it did not exist previously */
3911 ret = ice_remove_mac(hw, &l_head);
3917 * ice_replay_fltr - Replay all the filters stored by a specific list head
3918 * @hw: pointer to the hardware structure
3919 * @list_head: list for which filters needs to be replayed
3920 * @recp_id: Recipe ID for which rules need to be replayed
3922 static enum ice_status
3923 ice_replay_fltr(struct ice_hw *hw, u8 recp_id, struct LIST_HEAD_TYPE *list_head)
3925 struct ice_fltr_mgmt_list_entry *itr;
3926 enum ice_status status = ICE_SUCCESS;
3927 struct ice_sw_recipe *recp_list;
3928 u8 lport = hw->port_info->lport;
3929 struct LIST_HEAD_TYPE l_head;
3931 if (LIST_EMPTY(list_head))
3934 recp_list = &hw->switch_info->recp_list[recp_id];
3935 /* Move entries from the given list_head to a temporary l_head so that
3936 * they can be replayed. Otherwise when trying to re-add the same
3937 * filter, the function will return already exists
3939 LIST_REPLACE_INIT(list_head, &l_head);
3941 /* Mark the given list_head empty by reinitializing it so filters
3942 * could be added again by *handler
3944 LIST_FOR_EACH_ENTRY(itr, &l_head, ice_fltr_mgmt_list_entry,
3946 struct ice_fltr_list_entry f_entry;
3948 f_entry.fltr_info = itr->fltr_info;
3949 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN) {
3950 status = ice_add_rule_internal(hw, recp_list, lport,
3952 if (status != ICE_SUCCESS)
3957 /* Add a filter per VSI separately */
3962 ice_find_first_bit(itr->vsi_list_info->vsi_map,
3964 if (!ice_is_vsi_valid(hw, vsi_handle))
3967 ice_clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
3968 f_entry.fltr_info.vsi_handle = vsi_handle;
3969 f_entry.fltr_info.fwd_id.hw_vsi_id =
3970 ice_get_hw_vsi_num(hw, vsi_handle);
3971 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
3972 if (recp_id == ICE_SW_LKUP_VLAN)
3973 status = ice_add_vlan_internal(hw, recp_list,
3976 status = ice_add_rule_internal(hw, recp_list,
3979 if (status != ICE_SUCCESS)
3984 /* Clear the filter management list */
3985 ice_rem_sw_rule_info(hw, &l_head);
3990 * ice_replay_all_fltr - replay all filters stored in bookkeeping lists
3991 * @hw: pointer to the hardware structure
3993 * NOTE: This function does not clean up partially added filters on error.
3994 * It is up to caller of the function to issue a reset or fail early.
3996 enum ice_status ice_replay_all_fltr(struct ice_hw *hw)
3998 struct ice_switch_info *sw = hw->switch_info;
3999 enum ice_status status = ICE_SUCCESS;
4002 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
4003 struct LIST_HEAD_TYPE *head = &sw->recp_list[i].filt_rules;
4005 status = ice_replay_fltr(hw, i, head);
4006 if (status != ICE_SUCCESS)
4013 * ice_replay_vsi_fltr - Replay filters for requested VSI
4014 * @hw: pointer to the hardware structure
4015 * @vsi_handle: driver VSI handle
4016 * @recp_id: Recipe ID for which rules need to be replayed
4017 * @list_head: list for which filters need to be replayed
4019 * Replays the filter of recipe recp_id for a VSI represented via vsi_handle.
4020 * It is required to pass valid VSI handle.
4022 static enum ice_status
4023 ice_replay_vsi_fltr(struct ice_hw *hw, u16 vsi_handle, u8 recp_id,
4024 struct LIST_HEAD_TYPE *list_head)
4026 struct ice_fltr_mgmt_list_entry *itr;
4027 enum ice_status status = ICE_SUCCESS;
4028 struct ice_sw_recipe *recp_list;
4031 if (LIST_EMPTY(list_head))
4033 recp_list = &hw->switch_info->recp_list[recp_id];
4034 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
4036 LIST_FOR_EACH_ENTRY(itr, list_head, ice_fltr_mgmt_list_entry,
4038 struct ice_fltr_list_entry f_entry;
4040 f_entry.fltr_info = itr->fltr_info;
4041 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN &&
4042 itr->fltr_info.vsi_handle == vsi_handle) {
4043 /* update the src in case it is VSI num */
4044 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
4045 f_entry.fltr_info.src = hw_vsi_id;
4046 status = ice_add_rule_internal(hw, recp_list,
4047 hw->port_info->lport,
4049 if (status != ICE_SUCCESS)
4053 if (!itr->vsi_list_info ||
4054 !ice_is_bit_set(itr->vsi_list_info->vsi_map, vsi_handle))
4056 /* Clearing it so that the logic can add it back */
4057 ice_clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
4058 f_entry.fltr_info.vsi_handle = vsi_handle;
4059 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
4060 /* update the src in case it is VSI num */
4061 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
4062 f_entry.fltr_info.src = hw_vsi_id;
4063 if (recp_id == ICE_SW_LKUP_VLAN)
4064 status = ice_add_vlan_internal(hw, recp_list, &f_entry);
4066 status = ice_add_rule_internal(hw, recp_list,
4067 hw->port_info->lport,
4069 if (status != ICE_SUCCESS)
4077 * ice_replay_vsi_all_fltr - replay all filters stored in bookkeeping lists
4078 * @hw: pointer to the hardware structure
4079 * @vsi_handle: driver VSI handle
4081 * Replays filters for requested VSI via vsi_handle.
4083 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
4085 struct ice_switch_info *sw = hw->switch_info;
4086 enum ice_status status = ICE_SUCCESS;
4089 /* Update the recipes that were created */
4090 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
4091 struct LIST_HEAD_TYPE *head;
4093 head = &sw->recp_list[i].filt_replay_rules;
4094 if (!sw->recp_list[i].adv_rule)
4095 status = ice_replay_vsi_fltr(hw, vsi_handle, i, head);
4096 if (status != ICE_SUCCESS)
4104 * ice_rm_all_sw_replay_rule_info - deletes filter replay rules
4105 * @hw: pointer to the HW struct
4107 * Deletes the filter replay rules.
4109 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
4111 struct ice_switch_info *sw = hw->switch_info;
4117 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
4118 if (!LIST_EMPTY(&sw->recp_list[i].filt_replay_rules)) {
4119 struct LIST_HEAD_TYPE *l_head;
4121 l_head = &sw->recp_list[i].filt_replay_rules;
4122 if (!sw->recp_list[i].adv_rule)
4123 ice_rem_sw_rule_info(hw, l_head);