1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2018
5 #include "ice_switch.h"
8 #define ICE_ETH_DA_OFFSET 0
9 #define ICE_ETH_ETHTYPE_OFFSET 12
10 #define ICE_ETH_VLAN_TCI_OFFSET 14
11 #define ICE_MAX_VLAN_ID 0xFFF
13 /* Dummy ethernet header needed in the ice_aqc_sw_rules_elem
14 * struct to configure any switch filter rules.
15 * {DA (6 bytes), SA(6 bytes),
16 * Ether type (2 bytes for header without VLAN tag) OR
17 * VLAN tag (4 bytes for header with VLAN tag) }
19 * Word on Hardcoded values
20 * byte 0 = 0x2: to identify it as locally administered DA MAC
21 * byte 6 = 0x2: to identify it as locally administered SA MAC
22 * byte 12 = 0x81 & byte 13 = 0x00:
23 * In case of VLAN filter first two bytes defines ether type (0x8100)
24 * and remaining two bytes are placeholder for programming a given VLAN id
25 * In case of Ether type filter it is treated as header without VLAN tag
26 * and byte 12 and 13 is used to program a given Ether type instead
28 #define DUMMY_ETH_HDR_LEN 16
29 static const u8 dummy_eth_header[DUMMY_ETH_HDR_LEN] = { 0x2, 0, 0, 0, 0, 0,
33 #define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
34 (sizeof(struct ice_aqc_sw_rules_elem) - \
35 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
36 sizeof(struct ice_sw_rule_lkup_rx_tx) + DUMMY_ETH_HDR_LEN - 1)
37 #define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
38 (sizeof(struct ice_aqc_sw_rules_elem) - \
39 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
40 sizeof(struct ice_sw_rule_lkup_rx_tx) - 1)
41 #define ICE_SW_RULE_LG_ACT_SIZE(n) \
42 (sizeof(struct ice_aqc_sw_rules_elem) - \
43 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
44 sizeof(struct ice_sw_rule_lg_act) - \
45 sizeof(((struct ice_sw_rule_lg_act *)0)->act) + \
46 ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act)))
47 #define ICE_SW_RULE_VSI_LIST_SIZE(n) \
48 (sizeof(struct ice_aqc_sw_rules_elem) - \
49 sizeof(((struct ice_aqc_sw_rules_elem *)0)->pdata) + \
50 sizeof(struct ice_sw_rule_vsi_list) - \
51 sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi) + \
52 ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi)))
56 * ice_init_def_sw_recp - initialize the recipe book keeping tables
57 * @hw: pointer to the hw struct
59 * Allocate memory for the entire recipe table and initialize the structures/
60 * entries corresponding to basic recipes.
62 enum ice_status ice_init_def_sw_recp(struct ice_hw *hw)
64 struct ice_sw_recipe *recps;
67 recps = (struct ice_sw_recipe *)
68 ice_calloc(hw, ICE_MAX_NUM_RECIPES, sizeof(*recps));
70 return ICE_ERR_NO_MEMORY;
72 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
73 recps[i].root_rid = i;
74 INIT_LIST_HEAD(&recps[i].filt_rules);
75 INIT_LIST_HEAD(&recps[i].filt_replay_rules);
76 ice_init_lock(&recps[i].filt_rule_lock);
79 hw->switch_info->recp_list = recps;
85 * ice_aq_get_sw_cfg - get switch configuration
86 * @hw: pointer to the hardware structure
87 * @buf: pointer to the result buffer
88 * @buf_size: length of the buffer available for response
89 * @req_desc: pointer to requested descriptor
90 * @num_elems: pointer to number of elements
91 * @cd: pointer to command details structure or NULL
93 * Get switch configuration (0x0200) to be placed in 'buff'.
94 * This admin command returns information such as initial VSI/port number
95 * and switch ID it belongs to.
97 * NOTE: *req_desc is both an input/output parameter.
98 * The caller of this function first calls this function with *request_desc set
99 * to 0. If the response from f/w has *req_desc set to 0, all the switch
100 * configuration information has been returned; if non-zero (meaning not all
101 * the information was returned), the caller should call this function again
102 * with *req_desc set to the previous value returned by f/w to get the
103 * next block of switch configuration information.
105 * *num_elems is output only parameter. This reflects the number of elements
106 * in response buffer. The caller of this function to use *num_elems while
107 * parsing the response buffer.
109 static enum ice_status
110 ice_aq_get_sw_cfg(struct ice_hw *hw, struct ice_aqc_get_sw_cfg_resp *buf,
111 u16 buf_size, u16 *req_desc, u16 *num_elems,
112 struct ice_sq_cd *cd)
114 struct ice_aqc_get_sw_cfg *cmd;
115 enum ice_status status;
116 struct ice_aq_desc desc;
118 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_sw_cfg);
119 cmd = &desc.params.get_sw_conf;
120 cmd->element = CPU_TO_LE16(*req_desc);
122 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
124 *req_desc = LE16_TO_CPU(cmd->element);
125 *num_elems = LE16_TO_CPU(cmd->num_elems);
135 * @hw: pointer to the hw struct
136 * @vsi_ctx: pointer to a VSI context struct
137 * @cd: pointer to command details structure or NULL
139 * Add a VSI context to the hardware (0x0210)
141 static enum ice_status
142 ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
143 struct ice_sq_cd *cd)
145 struct ice_aqc_add_update_free_vsi_resp *res;
146 struct ice_aqc_add_get_update_free_vsi *cmd;
147 struct ice_aq_desc desc;
148 enum ice_status status;
150 cmd = &desc.params.vsi_cmd;
151 res = &desc.params.add_update_free_vsi_res;
153 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_vsi);
155 if (!vsi_ctx->alloc_from_pool)
156 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num |
157 ICE_AQ_VSI_IS_VALID);
159 cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
161 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
163 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
164 sizeof(vsi_ctx->info), cd);
167 vsi_ctx->vsi_num = LE16_TO_CPU(res->vsi_num) & ICE_AQ_VSI_NUM_M;
168 vsi_ctx->vsis_allocd = LE16_TO_CPU(res->vsi_used);
169 vsi_ctx->vsis_unallocated = LE16_TO_CPU(res->vsi_free);
177 * @hw: pointer to the hw struct
178 * @vsi_ctx: pointer to a VSI context struct
179 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
180 * @cd: pointer to command details structure or NULL
182 * Free VSI context info from hardware (0x0213)
184 static enum ice_status
185 ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
186 bool keep_vsi_alloc, struct ice_sq_cd *cd)
188 struct ice_aqc_add_update_free_vsi_resp *resp;
189 struct ice_aqc_add_get_update_free_vsi *cmd;
190 struct ice_aq_desc desc;
191 enum ice_status status;
193 cmd = &desc.params.vsi_cmd;
194 resp = &desc.params.add_update_free_vsi_res;
196 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_free_vsi);
198 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
200 cmd->cmd_flags = CPU_TO_LE16(ICE_AQ_VSI_KEEP_ALLOC);
202 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
204 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
205 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
213 * @hw: pointer to the hw struct
214 * @vsi_ctx: pointer to a VSI context struct
215 * @cd: pointer to command details structure or NULL
217 * Update VSI context in the hardware (0x0211)
219 static enum ice_status
220 ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
221 struct ice_sq_cd *cd)
223 struct ice_aqc_add_update_free_vsi_resp *resp;
224 struct ice_aqc_add_get_update_free_vsi *cmd;
225 struct ice_aq_desc desc;
226 enum ice_status status;
228 cmd = &desc.params.vsi_cmd;
229 resp = &desc.params.add_update_free_vsi_res;
231 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_vsi);
233 cmd->vsi_num = CPU_TO_LE16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
235 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
237 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
238 sizeof(vsi_ctx->info), cd);
241 vsi_ctx->vsis_allocd = LE16_TO_CPU(resp->vsi_used);
242 vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
249 * ice_is_vsi_valid - check whether the VSI is valid or not
250 * @hw: pointer to the hw struct
251 * @vsi_handle: VSI handle
253 * check whether the VSI is valid or not
255 bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle)
257 return vsi_handle < ICE_MAX_VSI && hw->vsi_ctx[vsi_handle];
261 * ice_get_hw_vsi_num - return the hw VSI number
262 * @hw: pointer to the hw struct
263 * @vsi_handle: VSI handle
265 * return the hw VSI number
266 * Caution: call this function only if VSI is valid (ice_is_vsi_valid)
268 u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle)
270 return hw->vsi_ctx[vsi_handle]->vsi_num;
274 * ice_get_vsi_ctx - return the VSI context entry for a given VSI handle
275 * @hw: pointer to the hw struct
276 * @vsi_handle: VSI handle
278 * return the VSI context entry for a given VSI handle
280 struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
282 return (vsi_handle >= ICE_MAX_VSI) ? NULL : hw->vsi_ctx[vsi_handle];
286 * ice_save_vsi_ctx - save the VSI context for a given VSI handle
287 * @hw: pointer to the hw struct
288 * @vsi_handle: VSI handle
289 * @vsi: VSI context pointer
291 * save the VSI context entry for a given VSI handle
294 ice_save_vsi_ctx(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi)
296 hw->vsi_ctx[vsi_handle] = vsi;
300 * ice_clear_vsi_ctx - clear the VSI context entry
301 * @hw: pointer to the hw struct
302 * @vsi_handle: VSI handle
304 * clear the VSI context entry
306 static void ice_clear_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
308 struct ice_vsi_ctx *vsi;
310 vsi = ice_get_vsi_ctx(hw, vsi_handle);
312 ice_destroy_lock(&vsi->rss_locks);
314 hw->vsi_ctx[vsi_handle] = NULL;
319 * ice_clear_all_vsi_ctx - clear all the VSI context entries
320 * @hw: pointer to the hw struct
322 void ice_clear_all_vsi_ctx(struct ice_hw *hw)
326 for (i = 0; i < ICE_MAX_VSI; i++)
327 ice_clear_vsi_ctx(hw, i);
331 * ice_add_vsi - add VSI context to the hardware and VSI handle list
332 * @hw: pointer to the hw struct
333 * @vsi_handle: unique VSI handle provided by drivers
334 * @vsi_ctx: pointer to a VSI context struct
335 * @cd: pointer to command details structure or NULL
337 * Add a VSI context to the hardware also add it into the VSI handle list.
338 * If this function gets called after reset for exisiting VSIs then update
339 * with the new HW VSI number in the corresponding VSI handle list entry.
342 ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
343 struct ice_sq_cd *cd)
345 struct ice_vsi_ctx *tmp_vsi_ctx;
346 enum ice_status status;
348 if (vsi_handle >= ICE_MAX_VSI)
349 return ICE_ERR_PARAM;
350 status = ice_aq_add_vsi(hw, vsi_ctx, cd);
353 tmp_vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
355 /* Create a new vsi context */
356 tmp_vsi_ctx = (struct ice_vsi_ctx *)
357 ice_malloc(hw, sizeof(*tmp_vsi_ctx));
359 ice_aq_free_vsi(hw, vsi_ctx, false, cd);
360 return ICE_ERR_NO_MEMORY;
362 *tmp_vsi_ctx = *vsi_ctx;
363 ice_init_lock(&tmp_vsi_ctx->rss_locks);
364 INIT_LIST_HEAD(&tmp_vsi_ctx->rss_list_head);
365 ice_save_vsi_ctx(hw, vsi_handle, tmp_vsi_ctx);
367 /* update with new HW VSI num */
368 if (tmp_vsi_ctx->vsi_num != vsi_ctx->vsi_num)
369 tmp_vsi_ctx->vsi_num = vsi_ctx->vsi_num;
376 * ice_free_vsi- free VSI context from hardware and VSI handle list
377 * @hw: pointer to the hw struct
378 * @vsi_handle: unique VSI handle
379 * @vsi_ctx: pointer to a VSI context struct
380 * @keep_vsi_alloc: keep VSI allocation as part of this PF's resources
381 * @cd: pointer to command details structure or NULL
383 * Free VSI context info from hardware as well as from VSI handle list
386 ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
387 bool keep_vsi_alloc, struct ice_sq_cd *cd)
389 enum ice_status status;
391 if (!ice_is_vsi_valid(hw, vsi_handle))
392 return ICE_ERR_PARAM;
393 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
394 status = ice_aq_free_vsi(hw, vsi_ctx, keep_vsi_alloc, cd);
396 ice_clear_vsi_ctx(hw, vsi_handle);
402 * @hw: pointer to the hw struct
403 * @vsi_handle: unique VSI handle
404 * @vsi_ctx: pointer to a VSI context struct
405 * @cd: pointer to command details structure or NULL
407 * Update VSI context in the hardware
410 ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
411 struct ice_sq_cd *cd)
413 if (!ice_is_vsi_valid(hw, vsi_handle))
414 return ICE_ERR_PARAM;
415 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
416 return ice_aq_update_vsi(hw, vsi_ctx, cd);
422 * ice_aq_alloc_free_vsi_list
423 * @hw: pointer to the hw struct
424 * @vsi_list_id: VSI list id returned or used for lookup
425 * @lkup_type: switch rule filter lookup type
426 * @opc: switch rules population command type - pass in the command opcode
428 * allocates or free a VSI list resource
430 static enum ice_status
431 ice_aq_alloc_free_vsi_list(struct ice_hw *hw, u16 *vsi_list_id,
432 enum ice_sw_lkup_type lkup_type,
433 enum ice_adminq_opc opc)
435 struct ice_aqc_alloc_free_res_elem *sw_buf;
436 struct ice_aqc_res_elem *vsi_ele;
437 enum ice_status status;
440 buf_len = sizeof(*sw_buf);
441 sw_buf = (struct ice_aqc_alloc_free_res_elem *)
442 ice_malloc(hw, buf_len);
444 return ICE_ERR_NO_MEMORY;
445 sw_buf->num_elems = CPU_TO_LE16(1);
447 if (lkup_type == ICE_SW_LKUP_MAC ||
448 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
449 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
450 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
451 lkup_type == ICE_SW_LKUP_PROMISC ||
452 lkup_type == ICE_SW_LKUP_PROMISC_VLAN) {
453 sw_buf->res_type = CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_REP);
454 } else if (lkup_type == ICE_SW_LKUP_VLAN) {
456 CPU_TO_LE16(ICE_AQC_RES_TYPE_VSI_LIST_PRUNE);
458 status = ICE_ERR_PARAM;
459 goto ice_aq_alloc_free_vsi_list_exit;
462 if (opc == ice_aqc_opc_free_res)
463 sw_buf->elem[0].e.sw_resp = CPU_TO_LE16(*vsi_list_id);
465 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len, opc, NULL);
467 goto ice_aq_alloc_free_vsi_list_exit;
469 if (opc == ice_aqc_opc_alloc_res) {
470 vsi_ele = &sw_buf->elem[0];
471 *vsi_list_id = LE16_TO_CPU(vsi_ele->e.sw_resp);
474 ice_aq_alloc_free_vsi_list_exit:
475 ice_free(hw, sw_buf);
481 * ice_aq_sw_rules - add/update/remove switch rules
482 * @hw: pointer to the hw struct
483 * @rule_list: pointer to switch rule population list
484 * @rule_list_sz: total size of the rule list in bytes
485 * @num_rules: number of switch rules in the rule_list
486 * @opc: switch rules population command type - pass in the command opcode
487 * @cd: pointer to command details structure or NULL
489 * Add(0x02a0)/Update(0x02a1)/Remove(0x02a2) switch rules commands to firmware
491 static enum ice_status
492 ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
493 u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd)
495 struct ice_aq_desc desc;
497 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_sw_rules");
499 if (opc != ice_aqc_opc_add_sw_rules &&
500 opc != ice_aqc_opc_update_sw_rules &&
501 opc != ice_aqc_opc_remove_sw_rules)
502 return ICE_ERR_PARAM;
504 ice_fill_dflt_direct_cmd_desc(&desc, opc);
506 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
507 desc.params.sw_rules.num_rules_fltr_entry_index =
508 CPU_TO_LE16(num_rules);
509 return ice_aq_send_cmd(hw, &desc, rule_list, rule_list_sz, cd);
513 /* ice_init_port_info - Initialize port_info with switch configuration data
514 * @pi: pointer to port_info
515 * @vsi_port_num: VSI number or port number
516 * @type: Type of switch element (port or VSI)
517 * @swid: switch ID of the switch the element is attached to
518 * @pf_vf_num: PF or VF number
519 * @is_vf: true if the element is a VF, false otherwise
522 ice_init_port_info(struct ice_port_info *pi, u16 vsi_port_num, u8 type,
523 u16 swid, u16 pf_vf_num, bool is_vf)
526 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
527 pi->lport = (u8)(vsi_port_num & ICE_LPORT_MASK);
529 pi->pf_vf_num = pf_vf_num;
531 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
532 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
535 ice_debug(pi->hw, ICE_DBG_SW,
536 "incorrect VSI/port type received\n");
541 /* ice_get_initial_sw_cfg - Get initial port and default VSI data
542 * @hw: pointer to the hardware structure
544 enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw)
546 struct ice_aqc_get_sw_cfg_resp *rbuf;
547 enum ice_status status;
556 rbuf = (struct ice_aqc_get_sw_cfg_resp *)
557 ice_malloc(hw, ICE_SW_CFG_MAX_BUF_LEN);
560 return ICE_ERR_NO_MEMORY;
562 /* Multiple calls to ice_aq_get_sw_cfg may be required
563 * to get all the switch configuration information. The need
564 * for additional calls is indicated by ice_aq_get_sw_cfg
565 * writing a non-zero value in req_desc
568 status = ice_aq_get_sw_cfg(hw, rbuf, ICE_SW_CFG_MAX_BUF_LEN,
569 &req_desc, &num_elems, NULL);
574 for (i = 0; i < num_elems; i++) {
575 struct ice_aqc_get_sw_cfg_resp_elem *ele;
576 u16 pf_vf_num, swid, vsi_port_num;
580 ele = rbuf[i].elements;
581 vsi_port_num = LE16_TO_CPU(ele->vsi_port_num) &
582 ICE_AQC_GET_SW_CONF_RESP_VSI_PORT_NUM_M;
584 pf_vf_num = LE16_TO_CPU(ele->pf_vf_num) &
585 ICE_AQC_GET_SW_CONF_RESP_FUNC_NUM_M;
587 swid = LE16_TO_CPU(ele->swid);
589 if (LE16_TO_CPU(ele->pf_vf_num) &
590 ICE_AQC_GET_SW_CONF_RESP_IS_VF)
593 type = LE16_TO_CPU(ele->vsi_port_num) >>
594 ICE_AQC_GET_SW_CONF_RESP_TYPE_S;
597 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
598 case ICE_AQC_GET_SW_CONF_RESP_VIRT_PORT:
599 if (j == num_total_ports) {
600 ice_debug(hw, ICE_DBG_SW,
601 "more ports than expected\n");
602 status = ICE_ERR_CFG;
605 ice_init_port_info(hw->port_info,
606 vsi_port_num, type, swid,
614 } while (req_desc && !status);
618 ice_free(hw, (void *)rbuf);
624 * ice_fill_sw_info - Helper function to populate lb_en and lan_en
625 * @hw: pointer to the hardware structure
626 * @fi: filter info structure to fill/update
628 * This helper function populates the lb_en and lan_en elements of the provided
629 * ice_fltr_info struct using the switch's type and characteristics of the
630 * switch rule being configured.
632 static void ice_fill_sw_info(struct ice_hw *hw, struct ice_fltr_info *fi)
636 if ((fi->flag & ICE_FLTR_TX) &&
637 (fi->fltr_act == ICE_FWD_TO_VSI ||
638 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
639 fi->fltr_act == ICE_FWD_TO_Q ||
640 fi->fltr_act == ICE_FWD_TO_QGRP)) {
641 /* Setting LB for prune actions will result in replicated
642 * packets to the internal switch that will be dropped.
644 if (fi->lkup_type != ICE_SW_LKUP_VLAN)
647 /* Set lan_en to TRUE if
648 * 1. The switch is a VEB AND
650 * 2.1 The lookup is a directional lookup like ethertype,
651 * promiscuous, ethertype-mac, promiscuous-vlan
652 * and default-port OR
653 * 2.2 The lookup is VLAN, OR
654 * 2.3 The lookup is MAC with mcast or bcast addr for MAC, OR
655 * 2.4 The lookup is MAC_VLAN with mcast or bcast addr for MAC.
659 * The switch is a VEPA.
661 * In all other cases, the LAN enable has to be set to false.
664 if (fi->lkup_type == ICE_SW_LKUP_ETHERTYPE ||
665 fi->lkup_type == ICE_SW_LKUP_PROMISC ||
666 fi->lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
667 fi->lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
668 fi->lkup_type == ICE_SW_LKUP_DFLT ||
669 fi->lkup_type == ICE_SW_LKUP_VLAN ||
670 (fi->lkup_type == ICE_SW_LKUP_MAC &&
671 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)) ||
672 (fi->lkup_type == ICE_SW_LKUP_MAC_VLAN &&
673 !IS_UNICAST_ETHER_ADDR(fi->l_data.mac.mac_addr)))
682 * ice_ilog2 - Caculates integer log base 2 of a number
683 * @n: number on which to perform operation
685 static int ice_ilog2(u64 n)
689 for (i = 63; i >= 0; i--)
690 if (((u64)1 << i) & n)
698 * ice_fill_sw_rule - Helper function to fill switch rule structure
699 * @hw: pointer to the hardware structure
700 * @f_info: entry containing packet forwarding information
701 * @s_rule: switch rule structure to be filled in based on mac_entry
702 * @opc: switch rules population command type - pass in the command opcode
705 ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
706 struct ice_aqc_sw_rules_elem *s_rule, enum ice_adminq_opc opc)
708 u16 vlan_id = ICE_MAX_VLAN_ID + 1;
717 if (opc == ice_aqc_opc_remove_sw_rules) {
718 s_rule->pdata.lkup_tx_rx.act = 0;
719 s_rule->pdata.lkup_tx_rx.index =
720 CPU_TO_LE16(f_info->fltr_rule_id);
721 s_rule->pdata.lkup_tx_rx.hdr_len = 0;
725 eth_hdr_sz = sizeof(dummy_eth_header);
726 eth_hdr = s_rule->pdata.lkup_tx_rx.hdr;
728 /* initialize the ether header with a dummy header */
729 ice_memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz, ICE_NONDMA_TO_NONDMA);
730 ice_fill_sw_info(hw, f_info);
732 switch (f_info->fltr_act) {
734 act |= (f_info->fwd_id.hw_vsi_id << ICE_SINGLE_ACT_VSI_ID_S) &
735 ICE_SINGLE_ACT_VSI_ID_M;
736 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
737 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
738 ICE_SINGLE_ACT_VALID_BIT;
740 case ICE_FWD_TO_VSI_LIST:
741 act |= ICE_SINGLE_ACT_VSI_LIST;
742 act |= (f_info->fwd_id.vsi_list_id <<
743 ICE_SINGLE_ACT_VSI_LIST_ID_S) &
744 ICE_SINGLE_ACT_VSI_LIST_ID_M;
745 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
746 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
747 ICE_SINGLE_ACT_VALID_BIT;
750 act |= ICE_SINGLE_ACT_TO_Q;
751 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
752 ICE_SINGLE_ACT_Q_INDEX_M;
754 case ICE_DROP_PACKET:
755 act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
756 ICE_SINGLE_ACT_VALID_BIT;
758 case ICE_FWD_TO_QGRP:
759 q_rgn = f_info->qgrp_size > 0 ?
760 (u8)ice_ilog2(f_info->qgrp_size) : 0;
761 act |= ICE_SINGLE_ACT_TO_Q;
762 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
763 ICE_SINGLE_ACT_Q_INDEX_M;
764 act |= (q_rgn << ICE_SINGLE_ACT_Q_REGION_S) &
765 ICE_SINGLE_ACT_Q_REGION_M;
772 act |= ICE_SINGLE_ACT_LB_ENABLE;
774 act |= ICE_SINGLE_ACT_LAN_ENABLE;
776 switch (f_info->lkup_type) {
777 case ICE_SW_LKUP_MAC:
778 daddr = f_info->l_data.mac.mac_addr;
780 case ICE_SW_LKUP_VLAN:
781 vlan_id = f_info->l_data.vlan.vlan_id;
782 if (f_info->fltr_act == ICE_FWD_TO_VSI ||
783 f_info->fltr_act == ICE_FWD_TO_VSI_LIST) {
784 act |= ICE_SINGLE_ACT_PRUNE;
785 act |= ICE_SINGLE_ACT_EGRESS | ICE_SINGLE_ACT_INGRESS;
788 case ICE_SW_LKUP_ETHERTYPE_MAC:
789 daddr = f_info->l_data.ethertype_mac.mac_addr;
791 case ICE_SW_LKUP_ETHERTYPE:
792 off = (__be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
793 *off = CPU_TO_BE16(f_info->l_data.ethertype_mac.ethertype);
795 case ICE_SW_LKUP_MAC_VLAN:
796 daddr = f_info->l_data.mac_vlan.mac_addr;
797 vlan_id = f_info->l_data.mac_vlan.vlan_id;
799 case ICE_SW_LKUP_PROMISC_VLAN:
800 vlan_id = f_info->l_data.mac_vlan.vlan_id;
802 case ICE_SW_LKUP_PROMISC:
803 daddr = f_info->l_data.mac_vlan.mac_addr;
809 s_rule->type = (f_info->flag & ICE_FLTR_RX) ?
810 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_RX) :
811 CPU_TO_LE16(ICE_AQC_SW_RULES_T_LKUP_TX);
813 /* Recipe set depending on lookup type */
814 s_rule->pdata.lkup_tx_rx.recipe_id = CPU_TO_LE16(f_info->lkup_type);
815 s_rule->pdata.lkup_tx_rx.src = CPU_TO_LE16(f_info->src);
816 s_rule->pdata.lkup_tx_rx.act = CPU_TO_LE32(act);
819 ice_memcpy(eth_hdr + ICE_ETH_DA_OFFSET, daddr, ETH_ALEN,
820 ICE_NONDMA_TO_NONDMA);
822 if (!(vlan_id > ICE_MAX_VLAN_ID)) {
823 off = (__be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
824 *off = CPU_TO_BE16(vlan_id);
827 /* Create the switch rule with the final dummy Ethernet header */
828 if (opc != ice_aqc_opc_update_sw_rules)
829 s_rule->pdata.lkup_tx_rx.hdr_len = CPU_TO_LE16(eth_hdr_sz);
834 * @hw: pointer to the hardware structure
835 * @m_ent: the management entry for which sw marker needs to be added
836 * @sw_marker: sw marker to tag the Rx descriptor with
837 * @l_id: large action resource id
839 * Create a large action to hold software marker and update the switch rule
840 * entry pointed by m_ent with newly created large action
842 static enum ice_status
843 ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
844 u16 sw_marker, u16 l_id)
846 struct ice_aqc_sw_rules_elem *lg_act, *rx_tx;
847 /* For software marker we need 3 large actions
848 * 1. FWD action: FWD TO VSI or VSI LIST
849 * 2. GENERIC VALUE action to hold the profile id
850 * 3. GENERIC VALUE action to hold the software marker id
852 const u16 num_lg_acts = 3;
853 enum ice_status status;
859 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
860 return ICE_ERR_PARAM;
862 /* Create two back-to-back switch rules and submit them to the HW using
867 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_lg_acts);
868 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
869 lg_act = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, rules_size);
871 return ICE_ERR_NO_MEMORY;
873 rx_tx = (struct ice_aqc_sw_rules_elem *)((u8 *)lg_act + lg_act_size);
875 /* Fill in the first switch rule i.e. large action */
876 lg_act->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_LG_ACT);
877 lg_act->pdata.lg_act.index = CPU_TO_LE16(l_id);
878 lg_act->pdata.lg_act.size = CPU_TO_LE16(num_lg_acts);
880 /* First action VSI forwarding or VSI list forwarding depending on how
883 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
884 m_ent->fltr_info.fwd_id.hw_vsi_id;
886 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
887 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) &
888 ICE_LG_ACT_VSI_LIST_ID_M;
889 if (m_ent->vsi_count > 1)
890 act |= ICE_LG_ACT_VSI_LIST;
891 lg_act->pdata.lg_act.act[0] = CPU_TO_LE32(act);
893 /* Second action descriptor type */
894 act = ICE_LG_ACT_GENERIC;
896 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
897 lg_act->pdata.lg_act.act[1] = CPU_TO_LE32(act);
899 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
900 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
902 /* Third action Marker value */
903 act |= ICE_LG_ACT_GENERIC;
904 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
905 ICE_LG_ACT_GENERIC_VALUE_M;
907 lg_act->pdata.lg_act.act[2] = CPU_TO_LE32(act);
909 /* call the fill switch rule to fill the lookup Tx Rx structure */
910 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
911 ice_aqc_opc_update_sw_rules);
913 /* Update the action to point to the large action id */
914 rx_tx->pdata.lkup_tx_rx.act =
915 CPU_TO_LE32(ICE_SINGLE_ACT_PTR |
916 ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
917 ICE_SINGLE_ACT_PTR_VAL_M));
919 /* Use the filter rule id of the previously created rule with single
920 * act. Once the update happens, hardware will treat this as large
923 rx_tx->pdata.lkup_tx_rx.index =
924 CPU_TO_LE16(m_ent->fltr_info.fltr_rule_id);
926 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
927 ice_aqc_opc_update_sw_rules, NULL);
929 m_ent->lg_act_idx = l_id;
930 m_ent->sw_marker_id = sw_marker;
933 ice_free(hw, lg_act);
939 * ice_create_vsi_list_map
940 * @hw: pointer to the hardware structure
941 * @vsi_handle_arr: array of VSI handles to set in the VSI mapping
942 * @num_vsi: number of VSI handles in the array
943 * @vsi_list_id: VSI list id generated as part of allocate resource
945 * Helper function to create a new entry of VSI list id to VSI mapping
946 * using the given VSI list id
948 static struct ice_vsi_list_map_info *
949 ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
952 struct ice_switch_info *sw = hw->switch_info;
953 struct ice_vsi_list_map_info *v_map;
956 v_map = (struct ice_vsi_list_map_info *)ice_calloc(hw, 1,
961 v_map->vsi_list_id = vsi_list_id;
963 for (i = 0; i < num_vsi; i++)
964 ice_set_bit(vsi_handle_arr[i], v_map->vsi_map);
966 LIST_ADD(&v_map->list_entry, &sw->vsi_list_map_head);
971 * ice_update_vsi_list_rule
972 * @hw: pointer to the hardware structure
973 * @vsi_handle_arr: array of VSI handles to form a VSI list
974 * @num_vsi: number of VSI handles in the array
975 * @vsi_list_id: VSI list id generated as part of allocate resource
976 * @remove: Boolean value to indicate if this is a remove action
977 * @opc: switch rules population command type - pass in the command opcode
978 * @lkup_type: lookup type of the filter
980 * Call AQ command to add a new switch rule or update existing switch rule
981 * using the given VSI list id
983 static enum ice_status
984 ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
985 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
986 enum ice_sw_lkup_type lkup_type)
988 struct ice_aqc_sw_rules_elem *s_rule;
989 enum ice_status status;
995 return ICE_ERR_PARAM;
997 if (lkup_type == ICE_SW_LKUP_MAC ||
998 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
999 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
1000 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
1001 lkup_type == ICE_SW_LKUP_PROMISC ||
1002 lkup_type == ICE_SW_LKUP_PROMISC_VLAN)
1003 type = remove ? ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR :
1004 ICE_AQC_SW_RULES_T_VSI_LIST_SET;
1005 else if (lkup_type == ICE_SW_LKUP_VLAN)
1006 type = remove ? ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR :
1007 ICE_AQC_SW_RULES_T_PRUNE_LIST_SET;
1009 return ICE_ERR_PARAM;
1011 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
1012 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1014 return ICE_ERR_NO_MEMORY;
1015 for (i = 0; i < num_vsi; i++) {
1016 if (!ice_is_vsi_valid(hw, vsi_handle_arr[i])) {
1017 status = ICE_ERR_PARAM;
1020 /* AQ call requires hw_vsi_id(s) */
1021 s_rule->pdata.vsi_list.vsi[i] =
1022 CPU_TO_LE16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
1025 s_rule->type = CPU_TO_LE16(type);
1026 s_rule->pdata.vsi_list.number_vsi = CPU_TO_LE16(num_vsi);
1027 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1029 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
1032 ice_free(hw, s_rule);
1037 * ice_create_vsi_list_rule - Creates and populates a VSI list rule
1038 * @hw: pointer to the hw struct
1039 * @vsi_handle_arr: array of VSI handles to form a VSI list
1040 * @num_vsi: number of VSI handles in the array
1041 * @vsi_list_id: stores the ID of the VSI list to be created
1042 * @lkup_type: switch rule filter's lookup type
1044 static enum ice_status
1045 ice_create_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1046 u16 *vsi_list_id, enum ice_sw_lkup_type lkup_type)
1048 enum ice_status status;
1050 status = ice_aq_alloc_free_vsi_list(hw, vsi_list_id, lkup_type,
1051 ice_aqc_opc_alloc_res);
1055 /* Update the newly created VSI list to include the specified VSIs */
1056 return ice_update_vsi_list_rule(hw, vsi_handle_arr, num_vsi,
1057 *vsi_list_id, false,
1058 ice_aqc_opc_add_sw_rules, lkup_type);
1062 * ice_create_pkt_fwd_rule
1063 * @hw: pointer to the hardware structure
1064 * @f_entry: entry containing packet forwarding information
1066 * Create switch rule with given filter information and add an entry
1067 * to the corresponding filter management list to track this switch rule
1070 static enum ice_status
1071 ice_create_pkt_fwd_rule(struct ice_hw *hw,
1072 struct ice_fltr_list_entry *f_entry)
1074 struct ice_fltr_mgmt_list_entry *fm_entry;
1075 struct ice_aqc_sw_rules_elem *s_rule;
1076 enum ice_sw_lkup_type l_type;
1077 struct ice_sw_recipe *recp;
1078 enum ice_status status;
1080 s_rule = (struct ice_aqc_sw_rules_elem *)
1081 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1083 return ICE_ERR_NO_MEMORY;
1084 fm_entry = (struct ice_fltr_mgmt_list_entry *)
1085 ice_malloc(hw, sizeof(*fm_entry));
1087 status = ICE_ERR_NO_MEMORY;
1088 goto ice_create_pkt_fwd_rule_exit;
1091 fm_entry->fltr_info = f_entry->fltr_info;
1093 /* Initialize all the fields for the management entry */
1094 fm_entry->vsi_count = 1;
1095 fm_entry->lg_act_idx = ICE_INVAL_LG_ACT_INDEX;
1096 fm_entry->sw_marker_id = ICE_INVAL_SW_MARKER_ID;
1097 fm_entry->counter_index = ICE_INVAL_COUNTER_ID;
1099 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
1100 ice_aqc_opc_add_sw_rules);
1102 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1103 ice_aqc_opc_add_sw_rules, NULL);
1105 ice_free(hw, fm_entry);
1106 goto ice_create_pkt_fwd_rule_exit;
1109 f_entry->fltr_info.fltr_rule_id =
1110 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1111 fm_entry->fltr_info.fltr_rule_id =
1112 LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
1114 /* The book keeping entries will get removed when base driver
1115 * calls remove filter AQ command
1117 l_type = fm_entry->fltr_info.lkup_type;
1118 recp = &hw->switch_info->recp_list[l_type];
1119 LIST_ADD(&fm_entry->list_entry, &recp->filt_rules);
1121 ice_create_pkt_fwd_rule_exit:
1122 ice_free(hw, s_rule);
1127 * ice_update_pkt_fwd_rule
1128 * @hw: pointer to the hardware structure
1129 * @f_info: filter information for switch rule
1131 * Call AQ command to update a previously created switch rule with a
1134 static enum ice_status
1135 ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
1137 struct ice_aqc_sw_rules_elem *s_rule;
1138 enum ice_status status;
1140 s_rule = (struct ice_aqc_sw_rules_elem *)
1141 ice_malloc(hw, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE);
1143 return ICE_ERR_NO_MEMORY;
1145 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
1147 s_rule->pdata.lkup_tx_rx.index = CPU_TO_LE16(f_info->fltr_rule_id);
1149 /* Update switch rule with new rule set to forward VSI list */
1150 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1151 ice_aqc_opc_update_sw_rules, NULL);
1153 ice_free(hw, s_rule);
1158 * ice_update_sw_rule_bridge_mode
1159 * @hw: pointer to the hw struct
1161 * Updates unicast switch filter rules based on VEB/VEPA mode
1163 enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw)
1165 struct ice_switch_info *sw = hw->switch_info;
1166 struct ice_fltr_mgmt_list_entry *fm_entry;
1167 enum ice_status status = ICE_SUCCESS;
1168 struct LIST_HEAD_TYPE *rule_head;
1169 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1171 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1172 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1174 ice_acquire_lock(rule_lock);
1175 LIST_FOR_EACH_ENTRY(fm_entry, rule_head, ice_fltr_mgmt_list_entry,
1177 struct ice_fltr_info *fi = &fm_entry->fltr_info;
1178 u8 *addr = fi->l_data.mac.mac_addr;
1180 /* Update unicast Tx rules to reflect the selected
1183 if ((fi->flag & ICE_FLTR_TX) && IS_UNICAST_ETHER_ADDR(addr) &&
1184 (fi->fltr_act == ICE_FWD_TO_VSI ||
1185 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1186 fi->fltr_act == ICE_FWD_TO_Q ||
1187 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1188 status = ice_update_pkt_fwd_rule(hw, fi);
1194 ice_release_lock(rule_lock);
1200 * ice_add_update_vsi_list
1201 * @hw: pointer to the hardware structure
1202 * @m_entry: pointer to current filter management list entry
1203 * @cur_fltr: filter information from the book keeping entry
1204 * @new_fltr: filter information with the new VSI to be added
1206 * Call AQ command to add or update previously created VSI list with new VSI.
1208 * Helper function to do book keeping associated with adding filter information
1209 * The algorithm to do the book keeping is described below :
1210 * When a VSI needs to subscribe to a given filter (MAC/VLAN/Ethtype etc.)
1211 * if only one VSI has been added till now
1212 * Allocate a new VSI list and add two VSIs
1213 * to this list using switch rule command
1214 * Update the previously created switch rule with the
1215 * newly created VSI list id
1216 * if a VSI list was previously created
1217 * Add the new VSI to the previously created VSI list set
1218 * using the update switch rule command
1220 static enum ice_status
1221 ice_add_update_vsi_list(struct ice_hw *hw,
1222 struct ice_fltr_mgmt_list_entry *m_entry,
1223 struct ice_fltr_info *cur_fltr,
1224 struct ice_fltr_info *new_fltr)
1226 enum ice_status status = ICE_SUCCESS;
1227 u16 vsi_list_id = 0;
1229 if ((cur_fltr->fltr_act == ICE_FWD_TO_Q ||
1230 cur_fltr->fltr_act == ICE_FWD_TO_QGRP))
1231 return ICE_ERR_NOT_IMPL;
1233 if ((new_fltr->fltr_act == ICE_FWD_TO_Q ||
1234 new_fltr->fltr_act == ICE_FWD_TO_QGRP) &&
1235 (cur_fltr->fltr_act == ICE_FWD_TO_VSI ||
1236 cur_fltr->fltr_act == ICE_FWD_TO_VSI_LIST))
1237 return ICE_ERR_NOT_IMPL;
1239 if (m_entry->vsi_count < 2 && !m_entry->vsi_list_info) {
1240 /* Only one entry existed in the mapping and it was not already
1241 * a part of a VSI list. So, create a VSI list with the old and
1244 struct ice_fltr_info tmp_fltr;
1245 u16 vsi_handle_arr[2];
1247 /* A rule already exists with the new VSI being added */
1248 if (cur_fltr->fwd_id.hw_vsi_id == new_fltr->fwd_id.hw_vsi_id)
1249 return ICE_ERR_ALREADY_EXISTS;
1251 vsi_handle_arr[0] = cur_fltr->vsi_handle;
1252 vsi_handle_arr[1] = new_fltr->vsi_handle;
1253 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1255 new_fltr->lkup_type);
1259 tmp_fltr = *new_fltr;
1260 tmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;
1261 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1262 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1263 /* Update the previous switch rule of "MAC forward to VSI" to
1264 * "MAC fwd to VSI list"
1266 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1270 cur_fltr->fwd_id.vsi_list_id = vsi_list_id;
1271 cur_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1272 m_entry->vsi_list_info =
1273 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1276 /* If this entry was large action then the large action needs
1277 * to be updated to point to FWD to VSI list
1279 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID)
1281 ice_add_marker_act(hw, m_entry,
1282 m_entry->sw_marker_id,
1283 m_entry->lg_act_idx);
1285 u16 vsi_handle = new_fltr->vsi_handle;
1286 enum ice_adminq_opc opcode;
1288 if (!m_entry->vsi_list_info)
1291 /* A rule already exists with the new VSI being added */
1292 if (ice_is_bit_set(m_entry->vsi_list_info->vsi_map, vsi_handle))
1295 /* Update the previously created VSI list set with
1296 * the new VSI id passed in
1298 vsi_list_id = cur_fltr->fwd_id.vsi_list_id;
1299 opcode = ice_aqc_opc_update_sw_rules;
1301 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1,
1302 vsi_list_id, false, opcode,
1303 new_fltr->lkup_type);
1304 /* update VSI list mapping info with new VSI id */
1306 ice_set_bit(vsi_handle,
1307 m_entry->vsi_list_info->vsi_map);
1310 m_entry->vsi_count++;
1315 * ice_find_rule_entry - Search a rule entry
1316 * @hw: pointer to the hardware structure
1317 * @recp_id: lookup type for which the specified rule needs to be searched
1318 * @f_info: rule information
1320 * Helper function to search for a given rule entry
1321 * Returns pointer to entry storing the rule if found
1323 static struct ice_fltr_mgmt_list_entry *
1324 ice_find_rule_entry(struct ice_hw *hw, u8 recp_id, struct ice_fltr_info *f_info)
1326 struct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;
1327 struct ice_switch_info *sw = hw->switch_info;
1328 struct LIST_HEAD_TYPE *list_head;
1330 list_head = &sw->recp_list[recp_id].filt_rules;
1331 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1333 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
1334 sizeof(f_info->l_data)) &&
1335 f_info->flag == list_itr->fltr_info.flag) {
1344 * ice_find_vsi_list_entry - Search VSI list map with VSI count 1
1345 * @hw: pointer to the hardware structure
1346 * @recp_id: lookup type for which VSI lists needs to be searched
1347 * @vsi_handle: VSI handle to be found in VSI list
1348 * @vsi_list_id: VSI list id found contaning vsi_handle
1350 * Helper function to search a VSI list with single entry containing given VSI
1351 * handle element. This can be extended further to search VSI list with more
1352 * than 1 vsi_count. Returns pointer to VSI list entry if found.
1354 static struct ice_vsi_list_map_info *
1355 ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
1358 struct ice_vsi_list_map_info *map_info = NULL;
1359 struct ice_switch_info *sw = hw->switch_info;
1360 struct ice_fltr_mgmt_list_entry *list_itr;
1361 struct LIST_HEAD_TYPE *list_head;
1363 list_head = &sw->recp_list[recp_id].filt_rules;
1364 LIST_FOR_EACH_ENTRY(list_itr, list_head, ice_fltr_mgmt_list_entry,
1366 if (list_itr->vsi_count == 1 && list_itr->vsi_list_info) {
1367 map_info = list_itr->vsi_list_info;
1368 if (ice_is_bit_set(map_info->vsi_map, vsi_handle)) {
1369 *vsi_list_id = map_info->vsi_list_id;
1378 * ice_add_rule_internal - add rule for a given lookup type
1379 * @hw: pointer to the hardware structure
1380 * @recp_id: lookup type (recipe id) for which rule has to be added
1381 * @f_entry: structure containing MAC forwarding information
1383 * Adds or updates the rule lists for a given recipe
1385 static enum ice_status
1386 ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,
1387 struct ice_fltr_list_entry *f_entry)
1389 struct ice_switch_info *sw = hw->switch_info;
1390 struct ice_fltr_info *new_fltr, *cur_fltr;
1391 struct ice_fltr_mgmt_list_entry *m_entry;
1392 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1393 enum ice_status status = ICE_SUCCESS;
1395 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1396 return ICE_ERR_PARAM;
1398 /* Load the hw_vsi_id only if the fwd action is fwd to VSI */
1399 if (f_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI)
1400 f_entry->fltr_info.fwd_id.hw_vsi_id =
1401 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1403 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1405 ice_acquire_lock(rule_lock);
1406 new_fltr = &f_entry->fltr_info;
1407 if (new_fltr->flag & ICE_FLTR_RX)
1408 new_fltr->src = hw->port_info->lport;
1409 else if (new_fltr->flag & ICE_FLTR_TX)
1411 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1413 m_entry = ice_find_rule_entry(hw, recp_id, new_fltr);
1415 ice_release_lock(rule_lock);
1416 return ice_create_pkt_fwd_rule(hw, f_entry);
1419 cur_fltr = &m_entry->fltr_info;
1420 status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
1421 ice_release_lock(rule_lock);
1427 * ice_remove_vsi_list_rule
1428 * @hw: pointer to the hardware structure
1429 * @vsi_list_id: VSI list id generated as part of allocate resource
1430 * @lkup_type: switch rule filter lookup type
1432 * The VSI list should be emptied before this function is called to remove the
1435 static enum ice_status
1436 ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
1437 enum ice_sw_lkup_type lkup_type)
1439 struct ice_aqc_sw_rules_elem *s_rule;
1440 enum ice_status status;
1443 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
1444 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
1446 return ICE_ERR_NO_MEMORY;
1448 s_rule->type = CPU_TO_LE16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
1449 s_rule->pdata.vsi_list.index = CPU_TO_LE16(vsi_list_id);
1451 /* Free the vsi_list resource that we allocated. It is assumed that the
1452 * list is empty at this point.
1454 status = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,
1455 ice_aqc_opc_free_res);
1457 ice_free(hw, s_rule);
1462 * ice_rem_update_vsi_list
1463 * @hw: pointer to the hardware structure
1464 * @vsi_handle: VSI handle of the VSI to remove
1465 * @fm_list: filter management entry for which the VSI list management needs to
1468 static enum ice_status
1469 ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
1470 struct ice_fltr_mgmt_list_entry *fm_list)
1472 enum ice_sw_lkup_type lkup_type;
1473 enum ice_status status = ICE_SUCCESS;
1476 if (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||
1477 fm_list->vsi_count == 0)
1478 return ICE_ERR_PARAM;
1480 /* A rule with the VSI being removed does not exist */
1481 if (!ice_is_bit_set(fm_list->vsi_list_info->vsi_map, vsi_handle))
1482 return ICE_ERR_DOES_NOT_EXIST;
1484 lkup_type = fm_list->fltr_info.lkup_type;
1485 vsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;
1486 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
1487 ice_aqc_opc_update_sw_rules,
1492 fm_list->vsi_count--;
1493 ice_clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
1495 if (fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) {
1496 struct ice_fltr_info tmp_fltr_info = fm_list->fltr_info;
1497 struct ice_vsi_list_map_info *vsi_list_info =
1498 fm_list->vsi_list_info;
1501 rem_vsi_handle = ice_find_first_bit(vsi_list_info->vsi_map,
1503 if (!ice_is_vsi_valid(hw, rem_vsi_handle))
1504 return ICE_ERR_OUT_OF_RANGE;
1506 /* Make sure VSI list is empty before removing it below */
1507 status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
1509 ice_aqc_opc_update_sw_rules,
1514 tmp_fltr_info.fltr_act = ICE_FWD_TO_VSI;
1515 tmp_fltr_info.fwd_id.hw_vsi_id =
1516 ice_get_hw_vsi_num(hw, rem_vsi_handle);
1517 tmp_fltr_info.vsi_handle = rem_vsi_handle;
1518 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr_info);
1520 ice_debug(hw, ICE_DBG_SW,
1521 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
1522 tmp_fltr_info.fwd_id.hw_vsi_id, status);
1526 fm_list->fltr_info = tmp_fltr_info;
1529 if ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||
1530 (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {
1531 struct ice_vsi_list_map_info *vsi_list_info =
1532 fm_list->vsi_list_info;
1534 /* Remove the VSI list since it is no longer used */
1535 status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
1537 ice_debug(hw, ICE_DBG_SW,
1538 "Failed to remove VSI list %d, error %d\n",
1539 vsi_list_id, status);
1543 LIST_DEL(&vsi_list_info->list_entry);
1544 ice_free(hw, vsi_list_info);
1545 fm_list->vsi_list_info = NULL;
1552 * ice_remove_rule_internal - Remove a filter rule of a given type
1554 * @hw: pointer to the hardware structure
1555 * @recp_id: recipe id for which the rule needs to removed
1556 * @f_entry: rule entry containing filter information
1558 static enum ice_status
1559 ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id,
1560 struct ice_fltr_list_entry *f_entry)
1562 struct ice_switch_info *sw = hw->switch_info;
1563 struct ice_fltr_mgmt_list_entry *list_elem;
1564 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1565 enum ice_status status = ICE_SUCCESS;
1566 bool remove_rule = false;
1569 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1570 return ICE_ERR_PARAM;
1571 f_entry->fltr_info.fwd_id.hw_vsi_id =
1572 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1574 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1575 ice_acquire_lock(rule_lock);
1576 list_elem = ice_find_rule_entry(hw, recp_id, &f_entry->fltr_info);
1578 status = ICE_ERR_DOES_NOT_EXIST;
1582 if (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {
1584 } else if (!list_elem->vsi_list_info) {
1585 status = ICE_ERR_DOES_NOT_EXIST;
1587 } else if (list_elem->vsi_list_info->ref_cnt > 1) {
1588 /* a ref_cnt > 1 indicates that the vsi_list is being
1589 * shared by multiple rules. Decrement the ref_cnt and
1590 * remove this rule, but do not modify the list, as it
1591 * is in-use by other rules.
1593 list_elem->vsi_list_info->ref_cnt--;
1596 /* a ref_cnt of 1 indicates the vsi_list is only used
1597 * by one rule. However, the original removal request is only
1598 * for a single VSI. Update the vsi_list first, and only
1599 * remove the rule if there are no further VSIs in this list.
1601 vsi_handle = f_entry->fltr_info.vsi_handle;
1602 status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem);
1605 /* if vsi count goes to zero after updating the vsi list */
1606 if (list_elem->vsi_count == 0)
1611 /* Remove the lookup rule */
1612 struct ice_aqc_sw_rules_elem *s_rule;
1614 s_rule = (struct ice_aqc_sw_rules_elem *)
1615 ice_malloc(hw, ICE_SW_RULE_RX_TX_NO_HDR_SIZE);
1617 status = ICE_ERR_NO_MEMORY;
1621 ice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,
1622 ice_aqc_opc_remove_sw_rules);
1624 status = ice_aq_sw_rules(hw, s_rule,
1625 ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
1626 ice_aqc_opc_remove_sw_rules, NULL);
1630 /* Remove a book keeping from the list */
1631 ice_free(hw, s_rule);
1633 LIST_DEL(&list_elem->list_entry);
1634 ice_free(hw, list_elem);
1637 ice_release_lock(rule_lock);
1643 * ice_add_mac - Add a MAC address based filter rule
1644 * @hw: pointer to the hardware structure
1645 * @m_list: list of MAC addresses and forwarding information
1647 * IMPORTANT: When the ucast_shared flag is set to false and m_list has
1648 * multiple unicast addresses, the function assumes that all the
1649 * addresses are unique in a given add_mac call. It doesn't
1650 * check for duplicates in this case, removing duplicates from a given
1651 * list should be taken care of in the caller of this function.
1654 ice_add_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
1656 struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
1657 struct ice_fltr_list_entry *m_list_itr;
1658 struct LIST_HEAD_TYPE *rule_head;
1659 u16 elem_sent, total_elem_left;
1660 struct ice_switch_info *sw;
1661 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1662 enum ice_status status = ICE_SUCCESS;
1663 u16 num_unicast = 0;
1667 return ICE_ERR_PARAM;
1669 sw = hw->switch_info;
1670 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1671 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
1673 u8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];
1677 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
1678 vsi_handle = m_list_itr->fltr_info.vsi_handle;
1679 if (!ice_is_vsi_valid(hw, vsi_handle))
1680 return ICE_ERR_PARAM;
1681 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
1682 m_list_itr->fltr_info.fwd_id.hw_vsi_id = hw_vsi_id;
1683 /* update the src in case it is vsi num */
1684 if (m_list_itr->fltr_info.src_id != ICE_SRC_ID_VSI)
1685 return ICE_ERR_PARAM;
1686 m_list_itr->fltr_info.src = hw_vsi_id;
1687 if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
1688 IS_ZERO_ETHER_ADDR(add))
1689 return ICE_ERR_PARAM;
1690 if (IS_UNICAST_ETHER_ADDR(add) && !hw->ucast_shared) {
1691 /* Don't overwrite the unicast address */
1692 ice_acquire_lock(rule_lock);
1693 if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
1694 &m_list_itr->fltr_info)) {
1695 ice_release_lock(rule_lock);
1696 return ICE_ERR_ALREADY_EXISTS;
1698 ice_release_lock(rule_lock);
1700 } else if (IS_MULTICAST_ETHER_ADDR(add) ||
1701 (IS_UNICAST_ETHER_ADDR(add) && hw->ucast_shared)) {
1702 m_list_itr->status =
1703 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
1705 if (m_list_itr->status)
1706 return m_list_itr->status;
1710 ice_acquire_lock(rule_lock);
1711 /* Exit if no suitable entries were found for adding bulk switch rule */
1713 status = ICE_SUCCESS;
1714 goto ice_add_mac_exit;
1717 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1719 /* Allocate switch rule buffer for the bulk update for unicast */
1720 s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1721 s_rule = (struct ice_aqc_sw_rules_elem *)
1722 ice_calloc(hw, num_unicast, s_rule_size);
1724 status = ICE_ERR_NO_MEMORY;
1725 goto ice_add_mac_exit;
1729 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
1731 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
1732 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
1734 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
1735 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
1736 ice_aqc_opc_add_sw_rules);
1737 r_iter = (struct ice_aqc_sw_rules_elem *)
1738 ((u8 *)r_iter + s_rule_size);
1742 /* Call AQ bulk switch rule update for all unicast addresses */
1744 /* Call AQ switch rule in AQ_MAX chunk */
1745 for (total_elem_left = num_unicast; total_elem_left > 0;
1746 total_elem_left -= elem_sent) {
1747 struct ice_aqc_sw_rules_elem *entry = r_iter;
1749 elem_sent = min(total_elem_left,
1750 (u16)(ICE_AQ_MAX_BUF_LEN / s_rule_size));
1751 status = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,
1752 elem_sent, ice_aqc_opc_add_sw_rules,
1755 goto ice_add_mac_exit;
1756 r_iter = (struct ice_aqc_sw_rules_elem *)
1757 ((u8 *)r_iter + (elem_sent * s_rule_size));
1760 /* Fill up rule id based on the value returned from FW */
1762 LIST_FOR_EACH_ENTRY(m_list_itr, m_list, ice_fltr_list_entry,
1764 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
1765 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
1766 struct ice_fltr_mgmt_list_entry *fm_entry;
1768 if (IS_UNICAST_ETHER_ADDR(mac_addr)) {
1769 f_info->fltr_rule_id =
1770 LE16_TO_CPU(r_iter->pdata.lkup_tx_rx.index);
1771 f_info->fltr_act = ICE_FWD_TO_VSI;
1772 /* Create an entry to track this MAC address */
1773 fm_entry = (struct ice_fltr_mgmt_list_entry *)
1774 ice_malloc(hw, sizeof(*fm_entry));
1776 status = ICE_ERR_NO_MEMORY;
1777 goto ice_add_mac_exit;
1779 fm_entry->fltr_info = *f_info;
1780 fm_entry->vsi_count = 1;
1781 /* The book keeping entries will get removed when
1782 * base driver calls remove filter AQ command
1785 LIST_ADD(&fm_entry->list_entry, rule_head);
1786 r_iter = (struct ice_aqc_sw_rules_elem *)
1787 ((u8 *)r_iter + s_rule_size);
1792 ice_release_lock(rule_lock);
1794 ice_free(hw, s_rule);
1799 * ice_add_vlan_internal - Add one VLAN based filter rule
1800 * @hw: pointer to the hardware structure
1801 * @f_entry: filter entry containing one VLAN information
1803 static enum ice_status
1804 ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)
1806 struct ice_switch_info *sw = hw->switch_info;
1807 struct ice_fltr_mgmt_list_entry *v_list_itr;
1808 struct ice_fltr_info *new_fltr, *cur_fltr;
1809 enum ice_sw_lkup_type lkup_type;
1810 u16 vsi_list_id = 0, vsi_handle;
1811 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
1812 enum ice_status status = ICE_SUCCESS;
1814 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1815 return ICE_ERR_PARAM;
1817 f_entry->fltr_info.fwd_id.hw_vsi_id =
1818 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1819 new_fltr = &f_entry->fltr_info;
1821 /* VLAN id should only be 12 bits */
1822 if (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)
1823 return ICE_ERR_PARAM;
1825 if (new_fltr->src_id != ICE_SRC_ID_VSI)
1826 return ICE_ERR_PARAM;
1828 new_fltr->src = new_fltr->fwd_id.hw_vsi_id;
1829 lkup_type = new_fltr->lkup_type;
1830 vsi_handle = new_fltr->vsi_handle;
1831 rule_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
1832 ice_acquire_lock(rule_lock);
1833 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN, new_fltr);
1835 struct ice_vsi_list_map_info *map_info = NULL;
1837 if (new_fltr->fltr_act == ICE_FWD_TO_VSI) {
1838 /* All VLAN pruning rules use a VSI list. Check if
1839 * there is already a VSI list containing VSI that we
1840 * want to add. If found, use the same vsi_list_id for
1841 * this new VLAN rule or else create a new list.
1843 map_info = ice_find_vsi_list_entry(hw, ICE_SW_LKUP_VLAN,
1847 status = ice_create_vsi_list_rule(hw,
1855 /* Convert the action to forwarding to a VSI list. */
1856 new_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1857 new_fltr->fwd_id.vsi_list_id = vsi_list_id;
1860 status = ice_create_pkt_fwd_rule(hw, f_entry);
1862 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN,
1865 status = ICE_ERR_DOES_NOT_EXIST;
1868 /* reuse VSI list for new rule and increment ref_cnt */
1870 v_list_itr->vsi_list_info = map_info;
1871 map_info->ref_cnt++;
1873 v_list_itr->vsi_list_info =
1874 ice_create_vsi_list_map(hw, &vsi_handle,
1878 } else if (v_list_itr->vsi_list_info->ref_cnt == 1) {
1879 /* Update existing VSI list to add new VSI id only if it used
1882 cur_fltr = &v_list_itr->fltr_info;
1883 status = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr,
1886 /* If VLAN rule exists and VSI list being used by this rule is
1887 * referenced by more than 1 VLAN rule. Then create a new VSI
1888 * list appending previous VSI with new VSI and update existing
1889 * VLAN rule to point to new VSI list id
1891 struct ice_fltr_info tmp_fltr;
1892 u16 vsi_handle_arr[2];
1895 /* Current implementation only supports reusing VSI list with
1896 * one VSI count. We should never hit below condition
1898 if (v_list_itr->vsi_count > 1 &&
1899 v_list_itr->vsi_list_info->ref_cnt > 1) {
1900 ice_debug(hw, ICE_DBG_SW,
1901 "Invalid configuration: Optimization to reuse VSI list with more than one VSI is not being done yet\n");
1902 status = ICE_ERR_CFG;
1907 ice_find_first_bit(v_list_itr->vsi_list_info->vsi_map,
1910 /* A rule already exists with the new VSI being added */
1911 if (cur_handle == vsi_handle) {
1912 status = ICE_ERR_ALREADY_EXISTS;
1916 vsi_handle_arr[0] = cur_handle;
1917 vsi_handle_arr[1] = vsi_handle;
1918 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1919 &vsi_list_id, lkup_type);
1923 tmp_fltr = v_list_itr->fltr_info;
1924 tmp_fltr.fltr_rule_id = v_list_itr->fltr_info.fltr_rule_id;
1925 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1926 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1927 /* Update the previous switch rule to a new VSI list which
1928 * includes current VSI that is requested
1930 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1934 /* before overriding VSI list map info. decrement ref_cnt of
1937 v_list_itr->vsi_list_info->ref_cnt--;
1939 /* now update to newly created list */
1940 v_list_itr->fltr_info.fwd_id.vsi_list_id = vsi_list_id;
1941 v_list_itr->vsi_list_info =
1942 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1944 v_list_itr->vsi_count++;
1948 ice_release_lock(rule_lock);
1953 * ice_add_vlan - Add VLAN based filter rule
1954 * @hw: pointer to the hardware structure
1955 * @v_list: list of VLAN entries and forwarding information
1958 ice_add_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
1960 struct ice_fltr_list_entry *v_list_itr;
1963 return ICE_ERR_PARAM;
1965 LIST_FOR_EACH_ENTRY(v_list_itr, v_list, ice_fltr_list_entry,
1967 if (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)
1968 return ICE_ERR_PARAM;
1969 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1970 v_list_itr->status = ice_add_vlan_internal(hw, v_list_itr);
1971 if (v_list_itr->status)
1972 return v_list_itr->status;
1977 #ifndef NO_MACVLAN_SUPPORT
1979 * ice_add_mac_vlan - Add MAC and VLAN pair based filter rule
1980 * @hw: pointer to the hardware structure
1981 * @mv_list: list of MAC and VLAN filters
1983 * If the VSI on which the mac-vlan pair has to be added has RX and Tx VLAN
1984 * pruning bits enabled, then it is the responsibility of the caller to make
1985 * sure to add a vlan only filter on the same VSI. Packets belonging to that
1986 * VLAN won't be received on that VSI otherwise.
1989 ice_add_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *mv_list)
1991 struct ice_fltr_list_entry *mv_list_itr;
1993 if (!mv_list || !hw)
1994 return ICE_ERR_PARAM;
1996 LIST_FOR_EACH_ENTRY(mv_list_itr, mv_list, ice_fltr_list_entry,
1998 enum ice_sw_lkup_type l_type =
1999 mv_list_itr->fltr_info.lkup_type;
2001 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2002 return ICE_ERR_PARAM;
2003 mv_list_itr->fltr_info.flag = ICE_FLTR_TX;
2004 mv_list_itr->status =
2005 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2007 if (mv_list_itr->status)
2008 return mv_list_itr->status;
2017 * ice_rem_sw_rule_info
2018 * @hw: pointer to the hardware structure
2019 * @rule_head: pointer to the switch list structure that we want to delete
2022 ice_rem_sw_rule_info(struct ice_hw *hw, struct LIST_HEAD_TYPE *rule_head)
2024 if (!LIST_EMPTY(rule_head)) {
2025 struct ice_fltr_mgmt_list_entry *entry;
2026 struct ice_fltr_mgmt_list_entry *tmp;
2028 LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, rule_head,
2029 ice_fltr_mgmt_list_entry, list_entry) {
2030 LIST_DEL(&entry->list_entry);
2031 ice_free(hw, entry);
2039 * ice_cfg_dflt_vsi - change state of VSI to set/clear default
2040 * @pi: pointer to the port_info structure
2041 * @vsi_handle: VSI handle to set as default
2042 * @set: true to add the above mentioned switch rule, false to remove it
2043 * @direction: ICE_FLTR_RX or ICE_FLTR_TX
2045 * add filter rule to set/unset given VSI as default VSI for the switch
2046 * (represented by swid)
2049 ice_cfg_dflt_vsi(struct ice_port_info *pi, u16 vsi_handle, bool set,
2052 struct ice_aqc_sw_rules_elem *s_rule;
2053 struct ice_fltr_info f_info;
2054 struct ice_hw *hw = pi->hw;
2055 enum ice_adminq_opc opcode;
2056 enum ice_status status;
2060 if (!ice_is_vsi_valid(hw, vsi_handle))
2061 return ICE_ERR_PARAM;
2062 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2064 s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
2065 ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
2066 s_rule = (struct ice_aqc_sw_rules_elem *)ice_malloc(hw, s_rule_size);
2068 return ICE_ERR_NO_MEMORY;
2070 ice_memset(&f_info, 0, sizeof(f_info), ICE_NONDMA_MEM);
2072 f_info.lkup_type = ICE_SW_LKUP_DFLT;
2073 f_info.flag = direction;
2074 f_info.fltr_act = ICE_FWD_TO_VSI;
2075 f_info.fwd_id.hw_vsi_id = hw_vsi_id;
2077 if (f_info.flag & ICE_FLTR_RX) {
2078 f_info.src = pi->lport;
2079 f_info.src_id = ICE_SRC_ID_LPORT;
2081 f_info.fltr_rule_id =
2082 pi->dflt_rx_vsi_rule_id;
2083 } else if (f_info.flag & ICE_FLTR_TX) {
2084 f_info.src_id = ICE_SRC_ID_VSI;
2085 f_info.src = hw_vsi_id;
2087 f_info.fltr_rule_id =
2088 pi->dflt_tx_vsi_rule_id;
2092 opcode = ice_aqc_opc_add_sw_rules;
2094 opcode = ice_aqc_opc_remove_sw_rules;
2096 ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
2098 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
2099 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
2102 u16 index = LE16_TO_CPU(s_rule->pdata.lkup_tx_rx.index);
2104 if (f_info.flag & ICE_FLTR_TX) {
2105 pi->dflt_tx_vsi_num = hw_vsi_id;
2106 pi->dflt_tx_vsi_rule_id = index;
2107 } else if (f_info.flag & ICE_FLTR_RX) {
2108 pi->dflt_rx_vsi_num = hw_vsi_id;
2109 pi->dflt_rx_vsi_rule_id = index;
2112 if (f_info.flag & ICE_FLTR_TX) {
2113 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
2114 pi->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
2115 } else if (f_info.flag & ICE_FLTR_RX) {
2116 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
2117 pi->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
2122 ice_free(hw, s_rule);
2127 * ice_remove_mac - remove a MAC address based filter rule
2128 * @hw: pointer to the hardware structure
2129 * @m_list: list of MAC addresses and forwarding information
2131 * This function removes either a MAC filter rule or a specific VSI from a
2132 * VSI list for a multicast MAC address.
2134 * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by
2135 * ice_add_mac. Caller should be aware that this call will only work if all
2136 * the entries passed into m_list were added previously. It will not attempt to
2137 * do a partial remove of entries that were found.
2140 ice_remove_mac(struct ice_hw *hw, struct LIST_HEAD_TYPE *m_list)
2142 struct ice_fltr_list_entry *list_itr, *tmp;
2145 return ICE_ERR_PARAM;
2147 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, m_list, ice_fltr_list_entry,
2149 enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
2151 if (l_type != ICE_SW_LKUP_MAC)
2152 return ICE_ERR_PARAM;
2153 list_itr->status = ice_remove_rule_internal(hw,
2156 if (list_itr->status)
2157 return list_itr->status;
2163 * ice_remove_vlan - Remove VLAN based filter rule
2164 * @hw: pointer to the hardware structure
2165 * @v_list: list of VLAN entries and forwarding information
2168 ice_remove_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2170 struct ice_fltr_list_entry *v_list_itr, *tmp;
2173 return ICE_ERR_PARAM;
2175 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2177 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2179 if (l_type != ICE_SW_LKUP_VLAN)
2180 return ICE_ERR_PARAM;
2181 v_list_itr->status = ice_remove_rule_internal(hw,
2184 if (v_list_itr->status)
2185 return v_list_itr->status;
2190 #ifndef NO_MACVLAN_SUPPORT
2192 * ice_remove_mac_vlan - Remove MAC VLAN based filter rule
2193 * @hw: pointer to the hardware structure
2194 * @v_list: list of MAC VLAN entries and forwarding information
2197 ice_remove_mac_vlan(struct ice_hw *hw, struct LIST_HEAD_TYPE *v_list)
2199 struct ice_fltr_list_entry *v_list_itr, *tmp;
2202 return ICE_ERR_PARAM;
2204 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2206 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2208 if (l_type != ICE_SW_LKUP_MAC_VLAN)
2209 return ICE_ERR_PARAM;
2210 v_list_itr->status =
2211 ice_remove_rule_internal(hw, ICE_SW_LKUP_MAC_VLAN,
2213 if (v_list_itr->status)
2214 return v_list_itr->status;
2218 #endif /* !NO_MACVLAN_SUPPORT */
2221 * ice_vsi_uses_fltr - Determine if given VSI uses specified filter
2222 * @fm_entry: filter entry to inspect
2223 * @vsi_handle: VSI handle to compare with filter info
2226 ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle)
2228 return ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&
2229 fm_entry->fltr_info.vsi_handle == vsi_handle) ||
2230 (fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&
2231 (ice_is_bit_set(fm_entry->vsi_list_info->vsi_map,
2236 * ice_add_entry_to_vsi_fltr_list - Add copy of fltr_list_entry to remove list
2237 * @hw: pointer to the hardware structure
2238 * @vsi_handle: VSI handle to remove filters from
2239 * @vsi_list_head: pointer to the list to add entry to
2240 * @fi: pointer to fltr_info of filter entry to copy & add
2242 * Helper function, used when creating a list of filters to remove from
2243 * a specific VSI. The entry added to vsi_list_head is a COPY of the
2244 * original filter entry, with the exception of fltr_info.fltr_act and
2245 * fltr_info.fwd_id fields. These are set such that later logic can
2246 * extract which VSI to remove the fltr from, and pass on that information.
2248 static enum ice_status
2249 ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2250 struct LIST_HEAD_TYPE *vsi_list_head,
2251 struct ice_fltr_info *fi)
2253 struct ice_fltr_list_entry *tmp;
2255 /* this memory is freed up in the caller function
2256 * once filters for this VSI are removed
2258 tmp = (struct ice_fltr_list_entry *)ice_malloc(hw, sizeof(*tmp));
2260 return ICE_ERR_NO_MEMORY;
2262 tmp->fltr_info = *fi;
2264 /* Overwrite these fields to indicate which VSI to remove filter from,
2265 * so find and remove logic can extract the information from the
2266 * list entries. Note that original entries will still have proper
2269 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2270 tmp->fltr_info.vsi_handle = vsi_handle;
2271 tmp->fltr_info.fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2273 LIST_ADD(&tmp->list_entry, vsi_list_head);
2279 * ice_add_to_vsi_fltr_list - Add VSI filters to the list
2280 * @hw: pointer to the hardware structure
2281 * @vsi_handle: VSI handle to remove filters from
2282 * @lkup_list_head: pointer to the list that has certain lookup type filters
2283 * @vsi_list_head: pointer to the list pertaining to VSI with vsi_handle
2285 * Locates all filters in lkup_list_head that are used by the given VSI,
2286 * and adds COPIES of those entries to vsi_list_head (intended to be used
2287 * to remove the listed filters).
2288 * Note that this means all entries in vsi_list_head must be explicitly
2289 * deallocated by the caller when done with list.
2291 static enum ice_status
2292 ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2293 struct LIST_HEAD_TYPE *lkup_list_head,
2294 struct LIST_HEAD_TYPE *vsi_list_head)
2296 struct ice_fltr_mgmt_list_entry *fm_entry;
2297 enum ice_status status = ICE_SUCCESS;
2299 /* check to make sure VSI id is valid and within boundary */
2300 if (!ice_is_vsi_valid(hw, vsi_handle))
2301 return ICE_ERR_PARAM;
2303 LIST_FOR_EACH_ENTRY(fm_entry, lkup_list_head,
2304 ice_fltr_mgmt_list_entry, list_entry) {
2305 struct ice_fltr_info *fi;
2307 fi = &fm_entry->fltr_info;
2308 if (!fi || !ice_vsi_uses_fltr(fm_entry, vsi_handle))
2311 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2321 * ice_determine_promisc_mask
2322 * @fi: filter info to parse
2324 * Helper function to determine which ICE_PROMISC_ mask corresponds
2325 * to given filter into.
2327 static u8 ice_determine_promisc_mask(struct ice_fltr_info *fi)
2329 u16 vid = fi->l_data.mac_vlan.vlan_id;
2330 u8 *macaddr = fi->l_data.mac.mac_addr;
2331 bool is_tx_fltr = false;
2332 u8 promisc_mask = 0;
2334 if (fi->flag == ICE_FLTR_TX)
2337 if (IS_BROADCAST_ETHER_ADDR(macaddr))
2338 promisc_mask |= is_tx_fltr ?
2339 ICE_PROMISC_BCAST_TX : ICE_PROMISC_BCAST_RX;
2340 else if (IS_MULTICAST_ETHER_ADDR(macaddr))
2341 promisc_mask |= is_tx_fltr ?
2342 ICE_PROMISC_MCAST_TX : ICE_PROMISC_MCAST_RX;
2343 else if (IS_UNICAST_ETHER_ADDR(macaddr))
2344 promisc_mask |= is_tx_fltr ?
2345 ICE_PROMISC_UCAST_TX : ICE_PROMISC_UCAST_RX;
2347 promisc_mask |= is_tx_fltr ?
2348 ICE_PROMISC_VLAN_TX : ICE_PROMISC_VLAN_RX;
2350 return promisc_mask;
2355 * ice_remove_promisc - Remove promisc based filter rules
2356 * @hw: pointer to the hardware structure
2357 * @recp_id: recipe id for which the rule needs to removed
2358 * @v_list: list of promisc entries
2360 static enum ice_status
2361 ice_remove_promisc(struct ice_hw *hw, u8 recp_id,
2362 struct LIST_HEAD_TYPE *v_list)
2364 struct ice_fltr_list_entry *v_list_itr, *tmp;
2366 LIST_FOR_EACH_ENTRY_SAFE(v_list_itr, tmp, v_list, ice_fltr_list_entry,
2368 v_list_itr->status =
2369 ice_remove_rule_internal(hw, recp_id, v_list_itr);
2370 if (v_list_itr->status)
2371 return v_list_itr->status;
2377 * ice_clear_vsi_promisc - clear specified promiscuous mode(s) for given VSI
2378 * @hw: pointer to the hardware structure
2379 * @vsi_handle: VSI handle to clear mode
2380 * @promisc_mask: mask of promiscuous config bits to clear
2381 * @vid: VLAN ID to clear VLAN promiscuous
2384 ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2387 struct ice_switch_info *sw = hw->switch_info;
2388 struct ice_fltr_list_entry *fm_entry, *tmp;
2389 struct LIST_HEAD_TYPE remove_list_head;
2390 struct ice_fltr_mgmt_list_entry *itr;
2391 struct LIST_HEAD_TYPE *rule_head;
2392 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2393 enum ice_status status = ICE_SUCCESS;
2396 if (!ice_is_vsi_valid(hw, vsi_handle))
2397 return ICE_ERR_PARAM;
2400 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2402 recipe_id = ICE_SW_LKUP_PROMISC;
2404 rule_head = &sw->recp_list[recipe_id].filt_rules;
2405 rule_lock = &sw->recp_list[recipe_id].filt_rule_lock;
2407 INIT_LIST_HEAD(&remove_list_head);
2409 ice_acquire_lock(rule_lock);
2410 LIST_FOR_EACH_ENTRY(itr, rule_head,
2411 ice_fltr_mgmt_list_entry, list_entry) {
2412 u8 fltr_promisc_mask = 0;
2414 if (!ice_vsi_uses_fltr(itr, vsi_handle))
2417 fltr_promisc_mask |=
2418 ice_determine_promisc_mask(&itr->fltr_info);
2420 /* Skip if filter is not completely specified by given mask */
2421 if (fltr_promisc_mask & ~promisc_mask)
2424 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2428 ice_release_lock(rule_lock);
2429 goto free_fltr_list;
2432 ice_release_lock(rule_lock);
2434 status = ice_remove_promisc(hw, recipe_id, &remove_list_head);
2437 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
2438 ice_fltr_list_entry, list_entry) {
2439 LIST_DEL(&fm_entry->list_entry);
2440 ice_free(hw, fm_entry);
2447 * ice_set_vsi_promisc - set given VSI to given promiscuous mode(s)
2448 * @hw: pointer to the hardware structure
2449 * @vsi_handle: VSI handle to configure
2450 * @promisc_mask: mask of promiscuous config bits
2451 * @vid: VLAN ID to set VLAN promiscuous
2454 ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, u16 vid)
2456 enum { UCAST_FLTR = 1, MCAST_FLTR, BCAST_FLTR };
2457 struct ice_fltr_list_entry f_list_entry;
2458 struct ice_fltr_info new_fltr;
2459 enum ice_status status = ICE_SUCCESS;
2465 ice_debug(hw, ICE_DBG_TRACE, "ice_set_vsi_promisc\n");
2467 if (!ice_is_vsi_valid(hw, vsi_handle))
2468 return ICE_ERR_PARAM;
2469 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2471 ice_memset(&new_fltr, 0, sizeof(new_fltr), ICE_NONDMA_MEM);
2473 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX)) {
2474 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC_VLAN;
2475 new_fltr.l_data.mac_vlan.vlan_id = vid;
2476 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2478 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC;
2479 recipe_id = ICE_SW_LKUP_PROMISC;
2482 /* Separate filters must be set for each direction/packet type
2483 * combination, so we will loop over the mask value, store the
2484 * individual type, and clear it out in the input mask as it
2487 while (promisc_mask) {
2493 if (promisc_mask & ICE_PROMISC_UCAST_RX) {
2494 promisc_mask &= ~ICE_PROMISC_UCAST_RX;
2495 pkt_type = UCAST_FLTR;
2496 } else if (promisc_mask & ICE_PROMISC_UCAST_TX) {
2497 promisc_mask &= ~ICE_PROMISC_UCAST_TX;
2498 pkt_type = UCAST_FLTR;
2500 } else if (promisc_mask & ICE_PROMISC_MCAST_RX) {
2501 promisc_mask &= ~ICE_PROMISC_MCAST_RX;
2502 pkt_type = MCAST_FLTR;
2503 } else if (promisc_mask & ICE_PROMISC_MCAST_TX) {
2504 promisc_mask &= ~ICE_PROMISC_MCAST_TX;
2505 pkt_type = MCAST_FLTR;
2507 } else if (promisc_mask & ICE_PROMISC_BCAST_RX) {
2508 promisc_mask &= ~ICE_PROMISC_BCAST_RX;
2509 pkt_type = BCAST_FLTR;
2510 } else if (promisc_mask & ICE_PROMISC_BCAST_TX) {
2511 promisc_mask &= ~ICE_PROMISC_BCAST_TX;
2512 pkt_type = BCAST_FLTR;
2516 /* Check for VLAN promiscuous flag */
2517 if (promisc_mask & ICE_PROMISC_VLAN_RX) {
2518 promisc_mask &= ~ICE_PROMISC_VLAN_RX;
2519 } else if (promisc_mask & ICE_PROMISC_VLAN_TX) {
2520 promisc_mask &= ~ICE_PROMISC_VLAN_TX;
2524 /* Set filter DA based on packet type */
2525 mac_addr = new_fltr.l_data.mac.mac_addr;
2526 if (pkt_type == BCAST_FLTR) {
2527 ice_memset(mac_addr, 0xff, ETH_ALEN, ICE_NONDMA_MEM);
2528 } else if (pkt_type == MCAST_FLTR ||
2529 pkt_type == UCAST_FLTR) {
2530 /* Use the dummy ether header DA */
2531 ice_memcpy(mac_addr, dummy_eth_header, ETH_ALEN,
2532 ICE_NONDMA_TO_NONDMA);
2533 if (pkt_type == MCAST_FLTR)
2534 mac_addr[0] |= 0x1; /* Set multicast bit */
2537 /* Need to reset this to zero for all iterations */
2540 new_fltr.flag |= ICE_FLTR_TX;
2541 new_fltr.src = hw_vsi_id;
2543 new_fltr.flag |= ICE_FLTR_RX;
2544 new_fltr.src = hw->port_info->lport;
2547 new_fltr.fltr_act = ICE_FWD_TO_VSI;
2548 new_fltr.vsi_handle = vsi_handle;
2549 new_fltr.fwd_id.hw_vsi_id = hw_vsi_id;
2550 f_list_entry.fltr_info = new_fltr;
2552 status = ice_add_rule_internal(hw, recipe_id, &f_list_entry);
2553 if (status != ICE_SUCCESS)
2554 goto set_promisc_exit;
2562 * ice_set_vlan_vsi_promisc
2563 * @hw: pointer to the hardware structure
2564 * @vsi_handle: VSI handle to configure
2565 * @promisc_mask: mask of promiscuous config bits
2566 * @rm_vlan_promisc: Clear VLANs VSI promisc mode
2568 * Configure VSI with all associated VLANs to given promiscuous mode(s)
2571 ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2572 bool rm_vlan_promisc)
2574 struct ice_switch_info *sw = hw->switch_info;
2575 struct ice_fltr_list_entry *list_itr, *tmp;
2576 struct LIST_HEAD_TYPE vsi_list_head;
2577 struct LIST_HEAD_TYPE *vlan_head;
2578 struct ice_lock *vlan_lock; /* Lock to protect filter rule list */
2579 enum ice_status status;
2582 INIT_LIST_HEAD(&vsi_list_head);
2583 vlan_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
2584 vlan_head = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rules;
2585 ice_acquire_lock(vlan_lock);
2586 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, vlan_head,
2588 ice_release_lock(vlan_lock);
2590 goto free_fltr_list;
2592 LIST_FOR_EACH_ENTRY(list_itr, &vsi_list_head, ice_fltr_list_entry,
2594 vlan_id = list_itr->fltr_info.l_data.vlan.vlan_id;
2595 if (rm_vlan_promisc)
2596 status = ice_clear_vsi_promisc(hw, vsi_handle,
2597 promisc_mask, vlan_id);
2599 status = ice_set_vsi_promisc(hw, vsi_handle,
2600 promisc_mask, vlan_id);
2606 LIST_FOR_EACH_ENTRY_SAFE(list_itr, tmp, &vsi_list_head,
2607 ice_fltr_list_entry, list_entry) {
2608 LIST_DEL(&list_itr->list_entry);
2609 ice_free(hw, list_itr);
2615 * ice_remove_vsi_lkup_fltr - Remove lookup type filters for a VSI
2616 * @hw: pointer to the hardware structure
2617 * @vsi_handle: VSI handle to remove filters from
2618 * @lkup: switch rule filter lookup type
2621 ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
2622 enum ice_sw_lkup_type lkup)
2624 struct ice_switch_info *sw = hw->switch_info;
2625 struct ice_fltr_list_entry *fm_entry;
2626 struct LIST_HEAD_TYPE remove_list_head;
2627 struct LIST_HEAD_TYPE *rule_head;
2628 struct ice_fltr_list_entry *tmp;
2629 struct ice_lock *rule_lock; /* Lock to protect filter rule list */
2630 enum ice_status status;
2632 INIT_LIST_HEAD(&remove_list_head);
2633 rule_lock = &sw->recp_list[lkup].filt_rule_lock;
2634 rule_head = &sw->recp_list[lkup].filt_rules;
2635 ice_acquire_lock(rule_lock);
2636 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, rule_head,
2638 ice_release_lock(rule_lock);
2643 case ICE_SW_LKUP_MAC:
2644 ice_remove_mac(hw, &remove_list_head);
2646 case ICE_SW_LKUP_VLAN:
2647 ice_remove_vlan(hw, &remove_list_head);
2649 case ICE_SW_LKUP_PROMISC:
2650 case ICE_SW_LKUP_PROMISC_VLAN:
2651 ice_remove_promisc(hw, lkup, &remove_list_head);
2653 case ICE_SW_LKUP_MAC_VLAN:
2654 #ifndef NO_MACVLAN_SUPPORT
2655 ice_remove_mac_vlan(hw, &remove_list_head);
2657 ice_debug(hw, ICE_DBG_SW, "MAC VLAN look up is not supported yet\n");
2658 #endif /* !NO_MACVLAN_SUPPORT */
2660 case ICE_SW_LKUP_ETHERTYPE:
2661 case ICE_SW_LKUP_ETHERTYPE_MAC:
2662 case ICE_SW_LKUP_DFLT:
2663 ice_debug(hw, ICE_DBG_SW,
2664 "Remove filters for this lookup type hasn't been implemented yet\n");
2666 case ICE_SW_LKUP_LAST:
2667 ice_debug(hw, ICE_DBG_SW, "Unsupported lookup type\n");
2671 LIST_FOR_EACH_ENTRY_SAFE(fm_entry, tmp, &remove_list_head,
2672 ice_fltr_list_entry, list_entry) {
2673 LIST_DEL(&fm_entry->list_entry);
2674 ice_free(hw, fm_entry);
2679 * ice_remove_vsi_fltr - Remove all filters for a VSI
2680 * @hw: pointer to the hardware structure
2681 * @vsi_handle: VSI handle to remove filters from
2683 void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle)
2685 ice_debug(hw, ICE_DBG_TRACE, "ice_remove_vsi_fltr\n");
2687 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC);
2688 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC_VLAN);
2689 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC);
2690 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_VLAN);
2691 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_DFLT);
2692 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE);
2693 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE_MAC);
2694 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC_VLAN);
2702 * ice_replay_vsi_fltr - Replay filters for requested VSI
2703 * @hw: pointer to the hardware structure
2704 * @vsi_handle: driver vsi handle
2705 * @recp_id: Recipe id for which rules need to be replayed
2706 * @list_head: list for which filters need to be replayed
2708 * Replays the filter of recipe recp_id for a VSI represented via vsi_handle.
2709 * It is required to pass valid VSI handle.
2711 static enum ice_status
2712 ice_replay_vsi_fltr(struct ice_hw *hw, u16 vsi_handle, u8 recp_id,
2713 struct LIST_HEAD_TYPE *list_head)
2715 struct ice_fltr_mgmt_list_entry *itr;
2716 enum ice_status status = ICE_SUCCESS;
2719 if (LIST_EMPTY(list_head))
2721 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2723 LIST_FOR_EACH_ENTRY(itr, list_head, ice_fltr_mgmt_list_entry,
2725 struct ice_fltr_list_entry f_entry;
2727 f_entry.fltr_info = itr->fltr_info;
2728 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN &&
2729 itr->fltr_info.vsi_handle == vsi_handle) {
2730 /* update the src in case it is vsi num */
2731 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
2732 f_entry.fltr_info.src = hw_vsi_id;
2733 status = ice_add_rule_internal(hw, recp_id, &f_entry);
2734 if (status != ICE_SUCCESS)
2738 if (!itr->vsi_list_info ||
2739 !ice_is_bit_set(itr->vsi_list_info->vsi_map, vsi_handle))
2741 /* Clearing it so that the logic can add it back */
2742 ice_clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
2743 f_entry.fltr_info.vsi_handle = vsi_handle;
2744 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
2745 /* update the src in case it is vsi num */
2746 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
2747 f_entry.fltr_info.src = hw_vsi_id;
2748 if (recp_id == ICE_SW_LKUP_VLAN)
2749 status = ice_add_vlan_internal(hw, &f_entry);
2751 status = ice_add_rule_internal(hw, recp_id, &f_entry);
2752 if (status != ICE_SUCCESS)
2761 * ice_replay_vsi_all_fltr - replay all filters stored in bookkeeping lists
2762 * @hw: pointer to the hardware structure
2763 * @vsi_handle: driver vsi handle
2765 * Replays filters for requested VSI via vsi_handle.
2767 enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
2769 struct ice_switch_info *sw = hw->switch_info;
2770 enum ice_status status = ICE_SUCCESS;
2773 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
2774 /* Update the default recipe lines and ones that were created */
2775 if (i < ICE_MAX_NUM_RECIPES || sw->recp_list[i].recp_created) {
2776 struct LIST_HEAD_TYPE *head;
2778 head = &sw->recp_list[i].filt_replay_rules;
2779 if (!sw->recp_list[i].adv_rule)
2780 status = ice_replay_vsi_fltr(hw, vsi_handle, i,
2782 if (status != ICE_SUCCESS)
2790 * ice_rm_all_sw_replay_rule_info - deletes filter replay rules
2791 * @hw: pointer to the hw struct
2793 * Deletes the filter replay rules.
2795 void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
2797 struct ice_switch_info *sw = hw->switch_info;
2803 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
2804 if (!LIST_EMPTY(&sw->recp_list[i].filt_replay_rules)) {
2805 struct LIST_HEAD_TYPE *l_head;
2807 l_head = &sw->recp_list[i].filt_replay_rules;
2808 if (!sw->recp_list[i].adv_rule)
2809 ice_rem_sw_rule_info(hw, l_head);