Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (C) 2019-2021, Intel Corporation. */
0003 
0004 #include "ice_vsi_vlan_ops.h"
0005 #include "ice_vsi_vlan_lib.h"
0006 #include "ice_vlan_mode.h"
0007 #include "ice.h"
0008 #include "ice_vf_vsi_vlan_ops.h"
0009 #include "ice_sriov.h"
0010 
0011 static int
0012 noop_vlan_arg(struct ice_vsi __always_unused *vsi,
0013           struct ice_vlan __always_unused *vlan)
0014 {
0015     return 0;
0016 }
0017 
0018 static int
0019 noop_vlan(struct ice_vsi __always_unused *vsi)
0020 {
0021     return 0;
0022 }
0023 
0024 /**
0025  * ice_vf_vsi_init_vlan_ops - Initialize default VSI VLAN ops for VF VSI
0026  * @vsi: VF's VSI being configured
0027  *
0028  * If Double VLAN Mode (DVM) is enabled, assume that the VF supports the new
0029  * VIRTCHNL_VF_VLAN_OFFLOAD_V2 capability and set up the VLAN ops accordingly.
0030  * If SVM is enabled maintain the same level of VLAN support previous to
0031  * VIRTCHNL_VF_VLAN_OFFLOAD_V2.
0032  */
0033 void ice_vf_vsi_init_vlan_ops(struct ice_vsi *vsi)
0034 {
0035     struct ice_vsi_vlan_ops *vlan_ops;
0036     struct ice_pf *pf = vsi->back;
0037     struct ice_vf *vf = vsi->vf;
0038 
0039     if (WARN_ON(!vf))
0040         return;
0041 
0042     if (ice_is_dvm_ena(&pf->hw)) {
0043         vlan_ops = &vsi->outer_vlan_ops;
0044 
0045         /* outer VLAN ops regardless of port VLAN config */
0046         vlan_ops->add_vlan = ice_vsi_add_vlan;
0047         vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
0048         vlan_ops->ena_tx_filtering = ice_vsi_ena_tx_vlan_filtering;
0049         vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
0050 
0051         if (ice_vf_is_port_vlan_ena(vf)) {
0052             /* setup outer VLAN ops */
0053             vlan_ops->set_port_vlan = ice_vsi_set_outer_port_vlan;
0054             vlan_ops->ena_rx_filtering =
0055                 ice_vsi_ena_rx_vlan_filtering;
0056 
0057             /* setup inner VLAN ops */
0058             vlan_ops = &vsi->inner_vlan_ops;
0059             vlan_ops->add_vlan = noop_vlan_arg;
0060             vlan_ops->del_vlan = noop_vlan_arg;
0061             vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
0062             vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
0063             vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
0064             vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
0065         } else {
0066             if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
0067                 vlan_ops->ena_rx_filtering = noop_vlan;
0068             else
0069                 vlan_ops->ena_rx_filtering =
0070                     ice_vsi_ena_rx_vlan_filtering;
0071 
0072             vlan_ops->del_vlan = ice_vsi_del_vlan;
0073             vlan_ops->ena_stripping = ice_vsi_ena_outer_stripping;
0074             vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
0075             vlan_ops->ena_insertion = ice_vsi_ena_outer_insertion;
0076             vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
0077 
0078             /* setup inner VLAN ops */
0079             vlan_ops = &vsi->inner_vlan_ops;
0080 
0081             vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
0082             vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
0083             vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
0084             vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
0085         }
0086     } else {
0087         vlan_ops = &vsi->inner_vlan_ops;
0088 
0089         /* inner VLAN ops regardless of port VLAN config */
0090         vlan_ops->add_vlan = ice_vsi_add_vlan;
0091         vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
0092         vlan_ops->ena_tx_filtering = ice_vsi_ena_tx_vlan_filtering;
0093         vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
0094 
0095         if (ice_vf_is_port_vlan_ena(vf)) {
0096             vlan_ops->set_port_vlan = ice_vsi_set_inner_port_vlan;
0097             vlan_ops->ena_rx_filtering =
0098                 ice_vsi_ena_rx_vlan_filtering;
0099         } else {
0100             if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
0101                 vlan_ops->ena_rx_filtering = noop_vlan;
0102             else
0103                 vlan_ops->ena_rx_filtering =
0104                     ice_vsi_ena_rx_vlan_filtering;
0105 
0106             vlan_ops->del_vlan = ice_vsi_del_vlan;
0107             vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
0108             vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
0109             vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
0110             vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
0111         }
0112     }
0113 }
0114 
0115 /**
0116  * ice_vf_vsi_cfg_dvm_legacy_vlan_mode - Config VLAN mode for old VFs in DVM
0117  * @vsi: VF's VSI being configured
0118  *
0119  * This should only be called when Double VLAN Mode (DVM) is enabled, there
0120  * is not a port VLAN enabled on this VF, and the VF negotiates
0121  * VIRTCHNL_VF_OFFLOAD_VLAN.
0122  *
0123  * This function sets up the VF VSI's inner and outer ice_vsi_vlan_ops and also
0124  * initializes software only VLAN mode (i.e. allow all VLANs). Also, use no-op
0125  * implementations for any functions that may be called during the lifetime of
0126  * the VF so these methods do nothing and succeed.
0127  */
0128 void ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi *vsi)
0129 {
0130     struct ice_vsi_vlan_ops *vlan_ops;
0131     struct ice_vf *vf = vsi->vf;
0132     struct device *dev;
0133 
0134     if (WARN_ON(!vf))
0135         return;
0136 
0137     dev = ice_pf_to_dev(vf->pf);
0138 
0139     if (!ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
0140         return;
0141 
0142     vlan_ops = &vsi->outer_vlan_ops;
0143 
0144     /* Rx VLAN filtering always disabled to allow software offloaded VLANs
0145      * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
0146      * port VLAN configured
0147      */
0148     vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
0149     /* Don't fail when attempting to enable Rx VLAN filtering */
0150     vlan_ops->ena_rx_filtering = noop_vlan;
0151 
0152     /* Tx VLAN filtering always disabled to allow software offloaded VLANs
0153      * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
0154      * port VLAN configured
0155      */
0156     vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
0157     /* Don't fail when attempting to enable Tx VLAN filtering */
0158     vlan_ops->ena_tx_filtering = noop_vlan;
0159 
0160     if (vlan_ops->dis_rx_filtering(vsi))
0161         dev_dbg(dev, "Failed to disable Rx VLAN filtering for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
0162     if (vlan_ops->dis_tx_filtering(vsi))
0163         dev_dbg(dev, "Failed to disable Tx VLAN filtering for old VF without VIRTHCNL_VF_OFFLOAD_VLAN_V2 support\n");
0164 
0165     /* All outer VLAN offloads must be disabled */
0166     vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
0167     vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
0168 
0169     if (vlan_ops->dis_stripping(vsi))
0170         dev_dbg(dev, "Failed to disable outer VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
0171 
0172     if (vlan_ops->dis_insertion(vsi))
0173         dev_dbg(dev, "Failed to disable outer VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
0174 
0175     /* All inner VLAN offloads must be disabled */
0176     vlan_ops = &vsi->inner_vlan_ops;
0177 
0178     vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
0179     vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
0180 
0181     if (vlan_ops->dis_stripping(vsi))
0182         dev_dbg(dev, "Failed to disable inner VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
0183 
0184     if (vlan_ops->dis_insertion(vsi))
0185         dev_dbg(dev, "Failed to disable inner VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
0186 }
0187 
0188 /**
0189  * ice_vf_vsi_cfg_svm_legacy_vlan_mode - Config VLAN mode for old VFs in SVM
0190  * @vsi: VF's VSI being configured
0191  *
0192  * This should only be called when Single VLAN Mode (SVM) is enabled, there is
0193  * not a port VLAN enabled on this VF, and the VF negotiates
0194  * VIRTCHNL_VF_OFFLOAD_VLAN.
0195  *
0196  * All of the normal SVM VLAN ops are identical for this case. However, by
0197  * default Rx VLAN filtering should be turned off by default in this case.
0198  */
0199 void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi)
0200 {
0201     struct ice_vf *vf = vsi->vf;
0202 
0203     if (WARN_ON(!vf))
0204         return;
0205 
0206     if (ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
0207         return;
0208 
0209     if (vsi->inner_vlan_ops.dis_rx_filtering(vsi))
0210         dev_dbg(ice_pf_to_dev(vf->pf), "Failed to disable Rx VLAN filtering for old VF with VIRTCHNL_VF_OFFLOAD_VLAN support\n");
0211 }