1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019-2021, Intel Corporation. */
4 #include "ice_vsi_vlan_lib.h"
9 static void print_invalid_tpid(struct ice_vsi *vsi, u16 tpid)
11 dev_err(ice_pf_to_dev(vsi->back), "%s %d specified invalid VLAN tpid 0x%04x\n",
12 ice_vsi_type_str(vsi->type), vsi->idx, tpid);
16 * validate_vlan - check if the ice_vlan passed in is valid
17 * @vsi: VSI used for printing error message
18 * @vlan: ice_vlan structure to validate
20 * Return true if the VLAN TPID is valid or if the VLAN TPID is 0 and the VLAN
21 * VID is 0, which allows for non-zero VLAN filters with the specified VLAN TPID
22 * and untagged VLAN 0 filters to be added to the prune list respectively.
24 static bool validate_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
26 if (vlan->tpid != ETH_P_8021Q && vlan->tpid != ETH_P_8021AD &&
27 vlan->tpid != ETH_P_QINQ1 && (vlan->tpid || vlan->vid)) {
28 print_invalid_tpid(vsi, vlan->tpid);
36 * ice_vsi_add_vlan - default add VLAN implementation for all VSI types
37 * @vsi: VSI being configured
38 * @vlan: VLAN filter to add
40 int ice_vsi_add_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
44 if (!validate_vlan(vsi, vlan))
47 err = ice_fltr_add_vlan(vsi, vlan);
48 if (err && err != -EEXIST) {
49 dev_err(ice_pf_to_dev(vsi->back), "Failure Adding VLAN %d on VSI %i, status %d\n",
50 vlan->vid, vsi->vsi_num, err);
59 * ice_vsi_del_vlan - default del VLAN implementation for all VSI types
60 * @vsi: VSI being configured
61 * @vlan: VLAN filter to delete
63 int ice_vsi_del_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
65 struct ice_pf *pf = vsi->back;
69 if (!validate_vlan(vsi, vlan))
72 dev = ice_pf_to_dev(pf);
74 err = ice_fltr_remove_vlan(vsi, vlan);
77 else if (err == -ENOENT || err == -EBUSY)
80 dev_err(dev, "Error removing VLAN %d on VSI %i error: %d\n",
81 vlan->vid, vsi->vsi_num, err);
87 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
88 * @vsi: the VSI being changed
90 static int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
92 struct ice_hw *hw = &vsi->back->hw;
93 struct ice_vsi_ctx *ctxt;
96 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
100 /* Here we are configuring the VSI to let the driver add VLAN tags by
101 * setting inner_vlan_flags to ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL. The actual VLAN tag
102 * insertion happens in the Tx hot path, in ice_tx_map.
104 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
106 /* Preserve existing VLAN strip setting */
107 ctxt->info.inner_vlan_flags |= (vsi->info.inner_vlan_flags &
108 ICE_AQ_VSI_INNER_VLAN_EMODE_M);
110 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
112 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
114 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN insert failed, err %d aq_err %s\n",
115 err, ice_aq_str(hw->adminq.sq_last_status));
119 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
126 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
127 * @vsi: the VSI being changed
128 * @ena: boolean value indicating if this is a enable or disable request
130 static int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
132 struct ice_hw *hw = &vsi->back->hw;
133 struct ice_vsi_ctx *ctxt;
136 /* do not allow modifying VLAN stripping when a port VLAN is configured
139 if (vsi->info.port_based_inner_vlan)
142 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
146 /* Here we are configuring what the VSI should do with the VLAN tag in
147 * the Rx packet. We can either leave the tag in the packet or put it in
151 /* Strip VLAN tag from Rx packet and put it in the desc */
152 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
154 /* Disable stripping. Leave tag in packet */
155 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
157 /* Allow all packets untagged/tagged */
158 ctxt->info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
160 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
162 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
164 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN strip failed, ena = %d err %d aq_err %s\n",
165 ena, err, ice_aq_str(hw->adminq.sq_last_status));
169 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
175 int ice_vsi_ena_inner_stripping(struct ice_vsi *vsi, const u16 tpid)
177 if (tpid != ETH_P_8021Q) {
178 print_invalid_tpid(vsi, tpid);
182 return ice_vsi_manage_vlan_stripping(vsi, true);
185 int ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
187 return ice_vsi_manage_vlan_stripping(vsi, false);
190 int ice_vsi_ena_inner_insertion(struct ice_vsi *vsi, const u16 tpid)
192 if (tpid != ETH_P_8021Q) {
193 print_invalid_tpid(vsi, tpid);
197 return ice_vsi_manage_vlan_insertion(vsi);
200 int ice_vsi_dis_inner_insertion(struct ice_vsi *vsi)
202 return ice_vsi_manage_vlan_insertion(vsi);
206 ice_save_vlan_info(struct ice_aqc_vsi_props *info,
207 struct ice_vsi_vlan_info *vlan)
209 vlan->sw_flags2 = info->sw_flags2;
210 vlan->inner_vlan_flags = info->inner_vlan_flags;
211 vlan->outer_vlan_flags = info->outer_vlan_flags;
215 ice_restore_vlan_info(struct ice_aqc_vsi_props *info,
216 struct ice_vsi_vlan_info *vlan)
218 info->sw_flags2 = vlan->sw_flags2;
219 info->inner_vlan_flags = vlan->inner_vlan_flags;
220 info->outer_vlan_flags = vlan->outer_vlan_flags;
224 * __ice_vsi_set_inner_port_vlan - set port VLAN VSI context settings to enable a port VLAN
225 * @vsi: the VSI to update
226 * @pvid_info: VLAN ID and QoS used to set the PVID VSI context field
228 static int __ice_vsi_set_inner_port_vlan(struct ice_vsi *vsi, u16 pvid_info)
230 struct ice_hw *hw = &vsi->back->hw;
231 struct ice_aqc_vsi_props *info;
232 struct ice_vsi_ctx *ctxt;
235 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
239 ice_save_vlan_info(&vsi->info, &vsi->vlan_info);
240 ctxt->info = vsi->info;
242 info->inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED |
243 ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
244 ICE_AQ_VSI_INNER_VLAN_EMODE_STR;
245 info->sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
247 info->port_based_inner_vlan = cpu_to_le16(pvid_info);
248 info->valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
249 ICE_AQ_VSI_PROP_SW_VALID);
251 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
253 dev_info(ice_hw_to_dev(hw), "update VSI for port VLAN failed, err %d aq_err %s\n",
254 ret, ice_aq_str(hw->adminq.sq_last_status));
258 vsi->info.inner_vlan_flags = info->inner_vlan_flags;
259 vsi->info.sw_flags2 = info->sw_flags2;
260 vsi->info.port_based_inner_vlan = info->port_based_inner_vlan;
266 int ice_vsi_set_inner_port_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
270 if (vlan->tpid != ETH_P_8021Q)
276 port_vlan_info = vlan->vid | (vlan->prio << VLAN_PRIO_SHIFT);
278 return __ice_vsi_set_inner_port_vlan(vsi, port_vlan_info);
281 int ice_vsi_clear_inner_port_vlan(struct ice_vsi *vsi)
283 struct ice_hw *hw = &vsi->back->hw;
284 struct ice_aqc_vsi_props *info;
285 struct ice_vsi_ctx *ctxt;
288 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
292 ice_restore_vlan_info(&vsi->info, &vsi->vlan_info);
293 vsi->info.port_based_inner_vlan = 0;
294 ctxt->info = vsi->info;
296 info->valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
297 ICE_AQ_VSI_PROP_SW_VALID);
299 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
301 dev_err(ice_hw_to_dev(hw), "update VSI for port VLAN failed, err %d aq_err %s\n",
302 ret, ice_aq_str(hw->adminq.sq_last_status));
309 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
310 * @vsi: VSI to enable or disable VLAN pruning on
311 * @ena: set to true to enable VLAN pruning and false to disable it
313 * returns 0 if VSI is updated, negative otherwise
315 static int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena)
317 struct ice_vsi_ctx *ctxt;
324 /* Don't enable VLAN pruning if the netdev is currently in promiscuous
325 * mode. VLAN pruning will be enabled when the interface exits
326 * promiscuous mode if any VLAN filters are active.
328 if (vsi->netdev && vsi->netdev->flags & IFF_PROMISC && ena)
332 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
336 ctxt->info = vsi->info;
339 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
341 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
343 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
345 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
347 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %d, aq_err = %s\n",
348 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num, status,
349 ice_aq_str(pf->hw.adminq.sq_last_status));
353 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
363 int ice_vsi_ena_rx_vlan_filtering(struct ice_vsi *vsi)
365 return ice_cfg_vlan_pruning(vsi, true);
368 int ice_vsi_dis_rx_vlan_filtering(struct ice_vsi *vsi)
370 return ice_cfg_vlan_pruning(vsi, false);
373 static int ice_cfg_vlan_antispoof(struct ice_vsi *vsi, bool enable)
375 struct ice_vsi_ctx *ctx;
378 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
382 ctx->info.sec_flags = vsi->info.sec_flags;
383 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
386 ctx->info.sec_flags |= ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
387 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S;
389 ctx->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
390 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
392 err = ice_update_vsi(&vsi->back->hw, vsi->idx, ctx, NULL);
394 dev_err(ice_pf_to_dev(vsi->back), "Failed to configure Tx VLAN anti-spoof %s for VSI %d, error %d\n",
395 enable ? "ON" : "OFF", vsi->vsi_num, err);
397 vsi->info.sec_flags = ctx->info.sec_flags;
404 int ice_vsi_ena_tx_vlan_filtering(struct ice_vsi *vsi)
406 return ice_cfg_vlan_antispoof(vsi, true);
409 int ice_vsi_dis_tx_vlan_filtering(struct ice_vsi *vsi)
411 return ice_cfg_vlan_antispoof(vsi, false);
415 * tpid_to_vsi_outer_vlan_type - convert from TPID to VSI context based tag_type
416 * @tpid: tpid used to translate into VSI context based tag_type
417 * @tag_type: output variable to hold the VSI context based tag type
419 static int tpid_to_vsi_outer_vlan_type(u16 tpid, u8 *tag_type)
423 *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_8100;
426 *tag_type = ICE_AQ_VSI_OUTER_TAG_STAG;
429 *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_9100;
440 * ice_vsi_ena_outer_stripping - enable outer VLAN stripping
441 * @vsi: VSI to configure
442 * @tpid: TPID to enable outer VLAN stripping for
444 * Enable outer VLAN stripping via VSI context. This function should only be
445 * used if DVM is supported. Also, this function should never be called directly
446 * as it should be part of ice_vsi_vlan_ops if it's needed.
448 * Since the VSI context only supports a single TPID for insertion and
449 * stripping, setting the TPID for stripping will affect the TPID for insertion.
450 * Callers need to be aware of this limitation.
452 * Only modify outer VLAN stripping settings and the VLAN TPID. Outer VLAN
453 * insertion settings are unmodified.
455 * This enables hardware to strip a VLAN tag with the specified TPID to be
456 * stripped from the packet and placed in the receive descriptor.
458 int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi, u16 tpid)
460 struct ice_hw *hw = &vsi->back->hw;
461 struct ice_vsi_ctx *ctxt;
465 /* do not allow modifying VLAN stripping when a port VLAN is configured
468 if (vsi->info.port_based_outer_vlan)
471 if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
474 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
478 ctxt->info.valid_sections =
479 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
480 /* clear current outer VLAN strip settings */
481 ctxt->info.outer_vlan_flags = vsi->info.outer_vlan_flags &
482 ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
483 ctxt->info.outer_vlan_flags |=
484 ((ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
485 ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
486 ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
487 ICE_AQ_VSI_OUTER_TAG_TYPE_M));
489 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
491 dev_err(ice_pf_to_dev(vsi->back), "update VSI for enabling outer VLAN stripping failed, err %d aq_err %s\n",
492 err, ice_aq_str(hw->adminq.sq_last_status));
494 vsi->info.outer_vlan_flags = ctxt->info.outer_vlan_flags;
501 * ice_vsi_dis_outer_stripping - disable outer VLAN stripping
502 * @vsi: VSI to configure
504 * Disable outer VLAN stripping via VSI context. This function should only be
505 * used if DVM is supported. Also, this function should never be called directly
506 * as it should be part of ice_vsi_vlan_ops if it's needed.
508 * Only modify the outer VLAN stripping settings. The VLAN TPID and outer VLAN
509 * insertion settings are unmodified.
511 * This tells the hardware to not strip any VLAN tagged packets, thus leaving
512 * them in the packet. This enables software offloaded VLAN stripping and
513 * disables hardware offloaded VLAN stripping.
515 int ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
517 struct ice_hw *hw = &vsi->back->hw;
518 struct ice_vsi_ctx *ctxt;
521 if (vsi->info.port_based_outer_vlan)
524 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
528 ctxt->info.valid_sections =
529 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
530 /* clear current outer VLAN strip settings */
531 ctxt->info.outer_vlan_flags = vsi->info.outer_vlan_flags &
532 ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
533 ctxt->info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
534 ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
536 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
538 dev_err(ice_pf_to_dev(vsi->back), "update VSI for disabling outer VLAN stripping failed, err %d aq_err %s\n",
539 err, ice_aq_str(hw->adminq.sq_last_status));
541 vsi->info.outer_vlan_flags = ctxt->info.outer_vlan_flags;
548 * ice_vsi_ena_outer_insertion - enable outer VLAN insertion
549 * @vsi: VSI to configure
550 * @tpid: TPID to enable outer VLAN insertion for
552 * Enable outer VLAN insertion via VSI context. This function should only be
553 * used if DVM is supported. Also, this function should never be called directly
554 * as it should be part of ice_vsi_vlan_ops if it's needed.
556 * Since the VSI context only supports a single TPID for insertion and
557 * stripping, setting the TPID for insertion will affect the TPID for stripping.
558 * Callers need to be aware of this limitation.
560 * Only modify outer VLAN insertion settings and the VLAN TPID. Outer VLAN
561 * stripping settings are unmodified.
563 * This allows a VLAN tag with the specified TPID to be inserted in the transmit
566 int ice_vsi_ena_outer_insertion(struct ice_vsi *vsi, u16 tpid)
568 struct ice_hw *hw = &vsi->back->hw;
569 struct ice_vsi_ctx *ctxt;
573 if (vsi->info.port_based_outer_vlan)
576 if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
579 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
583 ctxt->info.valid_sections =
584 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
585 /* clear current outer VLAN insertion settings */
586 ctxt->info.outer_vlan_flags = vsi->info.outer_vlan_flags &
587 ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
588 ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
589 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M |
590 ICE_AQ_VSI_OUTER_TAG_TYPE_M);
591 ctxt->info.outer_vlan_flags |=
592 ((ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
593 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
594 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M) |
595 ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
596 ICE_AQ_VSI_OUTER_TAG_TYPE_M);
598 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
600 dev_err(ice_pf_to_dev(vsi->back), "update VSI for enabling outer VLAN insertion failed, err %d aq_err %s\n",
601 err, ice_aq_str(hw->adminq.sq_last_status));
603 vsi->info.outer_vlan_flags = ctxt->info.outer_vlan_flags;
610 * ice_vsi_dis_outer_insertion - disable outer VLAN insertion
611 * @vsi: VSI to configure
613 * Disable outer VLAN insertion via VSI context. This function should only be
614 * used if DVM is supported. Also, this function should never be called directly
615 * as it should be part of ice_vsi_vlan_ops if it's needed.
617 * Only modify the outer VLAN insertion settings. The VLAN TPID and outer VLAN
618 * settings are unmodified.
620 * This tells the hardware to not allow any VLAN tagged packets in the transmit
621 * descriptor. This enables software offloaded VLAN insertion and disables
622 * hardware offloaded VLAN insertion.
624 int ice_vsi_dis_outer_insertion(struct ice_vsi *vsi)
626 struct ice_hw *hw = &vsi->back->hw;
627 struct ice_vsi_ctx *ctxt;
630 if (vsi->info.port_based_outer_vlan)
633 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
637 ctxt->info.valid_sections =
638 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
639 /* clear current outer VLAN insertion settings */
640 ctxt->info.outer_vlan_flags = vsi->info.outer_vlan_flags &
641 ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
642 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
643 ctxt->info.outer_vlan_flags |=
644 ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
645 ((ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
646 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
647 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
649 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
651 dev_err(ice_pf_to_dev(vsi->back), "update VSI for disabling outer VLAN insertion failed, err %d aq_err %s\n",
652 err, ice_aq_str(hw->adminq.sq_last_status));
654 vsi->info.outer_vlan_flags = ctxt->info.outer_vlan_flags;
661 * __ice_vsi_set_outer_port_vlan - set the outer port VLAN and related settings
662 * @vsi: VSI to configure
663 * @vlan_info: packed u16 that contains the VLAN prio and ID
664 * @tpid: TPID of the port VLAN
666 * Set the port VLAN prio, ID, and TPID.
668 * Enable VLAN pruning so the VSI doesn't receive any traffic that doesn't match
669 * a VLAN prune rule. The caller should take care to add a VLAN prune rule that
670 * matches the port VLAN ID and TPID.
672 * Tell hardware to strip outer VLAN tagged packets on receive and don't put
673 * them in the receive descriptor. VSI(s) in port VLANs should not be aware of
674 * the port VLAN ID or TPID they are assigned to.
676 * Tell hardware to prevent outer VLAN tag insertion on transmit and only allow
677 * untagged outer packets from the transmit descriptor.
679 * Also, tell the hardware to insert the port VLAN on transmit.
682 __ice_vsi_set_outer_port_vlan(struct ice_vsi *vsi, u16 vlan_info, u16 tpid)
684 struct ice_hw *hw = &vsi->back->hw;
685 struct ice_vsi_ctx *ctxt;
689 if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
692 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
696 ice_save_vlan_info(&vsi->info, &vsi->vlan_info);
697 ctxt->info = vsi->info;
699 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
701 ctxt->info.port_based_outer_vlan = cpu_to_le16(vlan_info);
702 ctxt->info.outer_vlan_flags =
703 (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW <<
704 ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
705 ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
706 ICE_AQ_VSI_OUTER_TAG_TYPE_M) |
707 ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
708 (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTUNTAGGED <<
709 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) |
710 ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT;
712 ctxt->info.valid_sections =
713 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID |
714 ICE_AQ_VSI_PROP_SW_VALID);
716 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
718 dev_err(ice_pf_to_dev(vsi->back), "update VSI for setting outer port based VLAN failed, err %d aq_err %s\n",
719 err, ice_aq_str(hw->adminq.sq_last_status));
721 vsi->info.port_based_outer_vlan = ctxt->info.port_based_outer_vlan;
722 vsi->info.outer_vlan_flags = ctxt->info.outer_vlan_flags;
723 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
731 * ice_vsi_set_outer_port_vlan - public version of __ice_vsi_set_outer_port_vlan
732 * @vsi: VSI to configure
733 * @vlan: ice_vlan structure used to set the port VLAN
735 * Set the outer port VLAN via VSI context. This function should only be
736 * used if DVM is supported. Also, this function should never be called directly
737 * as it should be part of ice_vsi_vlan_ops if it's needed.
739 * Use the ice_vlan structure passed in to set this VSI in a port VLAN.
741 int ice_vsi_set_outer_port_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
745 if (vlan->prio > (VLAN_PRIO_MASK >> VLAN_PRIO_SHIFT))
748 port_vlan_info = vlan->vid | (vlan->prio << VLAN_PRIO_SHIFT);
750 return __ice_vsi_set_outer_port_vlan(vsi, port_vlan_info, vlan->tpid);
754 * ice_vsi_clear_outer_port_vlan - clear outer port vlan
755 * @vsi: VSI to configure
757 * The function is restoring previously set vlan config (saved in
758 * vsi->vlan_info). Setting happens in port vlan configuration.
760 int ice_vsi_clear_outer_port_vlan(struct ice_vsi *vsi)
762 struct ice_hw *hw = &vsi->back->hw;
763 struct ice_vsi_ctx *ctxt;
766 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
770 ice_restore_vlan_info(&vsi->info, &vsi->vlan_info);
771 vsi->info.port_based_outer_vlan = 0;
772 ctxt->info = vsi->info;
774 ctxt->info.valid_sections =
775 cpu_to_le16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID |
776 ICE_AQ_VSI_PROP_SW_VALID);
778 err = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
780 dev_err(ice_pf_to_dev(vsi->back), "update VSI for clearing outer port based VLAN failed, err %d aq_err %s\n",
781 err, ice_aq_str(hw->adminq.sq_last_status));