Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (C) 2019-2021, Intel Corporation. */
0003 
0004 #include "ice_pf_vsi_vlan_ops.h"
0005 #include "ice_vf_vsi_vlan_ops.h"
0006 #include "ice_lib.h"
0007 #include "ice.h"
0008 
0009 static int
0010 op_unsupported_vlan_arg(struct ice_vsi * __always_unused vsi,
0011             struct ice_vlan * __always_unused vlan)
0012 {
0013     return -EOPNOTSUPP;
0014 }
0015 
0016 static int
0017 op_unsupported_tpid_arg(struct ice_vsi *__always_unused vsi,
0018             u16 __always_unused tpid)
0019 {
0020     return -EOPNOTSUPP;
0021 }
0022 
0023 static int op_unsupported(struct ice_vsi *__always_unused vsi)
0024 {
0025     return -EOPNOTSUPP;
0026 }
0027 
0028 /* If any new ops are added to the VSI VLAN ops interface then an unsupported
0029  * implementation should be set here.
0030  */
0031 static struct ice_vsi_vlan_ops ops_unsupported = {
0032     .add_vlan = op_unsupported_vlan_arg,
0033     .del_vlan = op_unsupported_vlan_arg,
0034     .ena_stripping = op_unsupported_tpid_arg,
0035     .dis_stripping = op_unsupported,
0036     .ena_insertion = op_unsupported_tpid_arg,
0037     .dis_insertion = op_unsupported,
0038     .ena_rx_filtering = op_unsupported,
0039     .dis_rx_filtering = op_unsupported,
0040     .ena_tx_filtering = op_unsupported,
0041     .dis_tx_filtering = op_unsupported,
0042     .set_port_vlan = op_unsupported_vlan_arg,
0043 };
0044 
0045 /**
0046  * ice_vsi_init_unsupported_vlan_ops - init all VSI VLAN ops to unsupported
0047  * @vsi: VSI to initialize VSI VLAN ops to unsupported for
0048  *
0049  * By default all inner and outer VSI VLAN ops return -EOPNOTSUPP. This was done
0050  * as oppsed to leaving the ops null to prevent unexpected crashes. Instead if
0051  * an unsupported VSI VLAN op is called it will just return -EOPNOTSUPP.
0052  *
0053  */
0054 static void ice_vsi_init_unsupported_vlan_ops(struct ice_vsi *vsi)
0055 {
0056     vsi->outer_vlan_ops = ops_unsupported;
0057     vsi->inner_vlan_ops = ops_unsupported;
0058 }
0059 
0060 /**
0061  * ice_vsi_init_vlan_ops - initialize type specific VSI VLAN ops
0062  * @vsi: VSI to initialize ops for
0063  *
0064  * If any VSI types are added and/or require different ops than the PF or VF VSI
0065  * then they will have to add a case here to handle that. Also, VSI type
0066  * specific files should be added in the same manner that was done for PF VSI.
0067  */
0068 void ice_vsi_init_vlan_ops(struct ice_vsi *vsi)
0069 {
0070     /* Initialize all VSI types to have unsupported VSI VLAN ops */
0071     ice_vsi_init_unsupported_vlan_ops(vsi);
0072 
0073     switch (vsi->type) {
0074     case ICE_VSI_PF:
0075     case ICE_VSI_SWITCHDEV_CTRL:
0076         ice_pf_vsi_init_vlan_ops(vsi);
0077         break;
0078     case ICE_VSI_VF:
0079         ice_vf_vsi_init_vlan_ops(vsi);
0080         break;
0081     default:
0082         dev_dbg(ice_pf_to_dev(vsi->back), "%s does not support VLAN operations\n",
0083             ice_vsi_type_str(vsi->type));
0084         break;
0085     }
0086 }
0087 
0088 /**
0089  * ice_get_compat_vsi_vlan_ops - Get VSI VLAN ops based on VLAN mode
0090  * @vsi: VSI used to get the VSI VLAN ops
0091  *
0092  * This function is meant to be used when the caller doesn't know which VLAN ops
0093  * to use (i.e. inner or outer). This allows backward compatibility for VLANs
0094  * since most of the Outer VSI VLAN functins are not supported when
0095  * the device is configured in Single VLAN Mode (SVM).
0096  */
0097 struct ice_vsi_vlan_ops *ice_get_compat_vsi_vlan_ops(struct ice_vsi *vsi)
0098 {
0099     if (ice_is_dvm_ena(&vsi->back->hw))
0100         return &vsi->outer_vlan_ops;
0101     else
0102         return &vsi->inner_vlan_ops;
0103 }