1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019-2021, Intel Corporation. */
3
4 #include "ice_pf_vsi_vlan_ops.h"
5 #include "ice_vf_vsi_vlan_ops.h"
6 #include "ice_sf_vsi_vlan_ops.h"
7 #include "ice_lib.h"
8 #include "ice.h"
9
10 static int
op_unsupported_vlan_arg(struct ice_vsi * __always_unused vsi,struct ice_vlan * __always_unused vlan)11 op_unsupported_vlan_arg(struct ice_vsi * __always_unused vsi,
12 struct ice_vlan * __always_unused vlan)
13 {
14 return -EOPNOTSUPP;
15 }
16
17 static int
op_unsupported_tpid_arg(struct ice_vsi * __always_unused vsi,u16 __always_unused tpid)18 op_unsupported_tpid_arg(struct ice_vsi *__always_unused vsi,
19 u16 __always_unused tpid)
20 {
21 return -EOPNOTSUPP;
22 }
23
op_unsupported(struct ice_vsi * __always_unused vsi)24 static int op_unsupported(struct ice_vsi *__always_unused vsi)
25 {
26 return -EOPNOTSUPP;
27 }
28
29 /* If any new ops are added to the VSI VLAN ops interface then an unsupported
30 * implementation should be set here.
31 */
32 static struct ice_vsi_vlan_ops ops_unsupported = {
33 .add_vlan = op_unsupported_vlan_arg,
34 .del_vlan = op_unsupported_vlan_arg,
35 .ena_stripping = op_unsupported_tpid_arg,
36 .dis_stripping = op_unsupported,
37 .ena_insertion = op_unsupported_tpid_arg,
38 .dis_insertion = op_unsupported,
39 .ena_rx_filtering = op_unsupported,
40 .dis_rx_filtering = op_unsupported,
41 .ena_tx_filtering = op_unsupported,
42 .dis_tx_filtering = op_unsupported,
43 .set_port_vlan = op_unsupported_vlan_arg,
44 };
45
46 /**
47 * ice_vsi_init_unsupported_vlan_ops - init all VSI VLAN ops to unsupported
48 * @vsi: VSI to initialize VSI VLAN ops to unsupported for
49 *
50 * By default all inner and outer VSI VLAN ops return -EOPNOTSUPP. This was done
51 * as oppsed to leaving the ops null to prevent unexpected crashes. Instead if
52 * an unsupported VSI VLAN op is called it will just return -EOPNOTSUPP.
53 *
54 */
ice_vsi_init_unsupported_vlan_ops(struct ice_vsi * vsi)55 static void ice_vsi_init_unsupported_vlan_ops(struct ice_vsi *vsi)
56 {
57 vsi->outer_vlan_ops = ops_unsupported;
58 vsi->inner_vlan_ops = ops_unsupported;
59 }
60
61 /**
62 * ice_vsi_init_vlan_ops - initialize type specific VSI VLAN ops
63 * @vsi: VSI to initialize ops for
64 *
65 * If any VSI types are added and/or require different ops than the PF or VF VSI
66 * then they will have to add a case here to handle that. Also, VSI type
67 * specific files should be added in the same manner that was done for PF VSI.
68 */
ice_vsi_init_vlan_ops(struct ice_vsi * vsi)69 void ice_vsi_init_vlan_ops(struct ice_vsi *vsi)
70 {
71 /* Initialize all VSI types to have unsupported VSI VLAN ops */
72 ice_vsi_init_unsupported_vlan_ops(vsi);
73
74 switch (vsi->type) {
75 case ICE_VSI_PF:
76 ice_pf_vsi_init_vlan_ops(vsi);
77 break;
78 case ICE_VSI_VF:
79 ice_vf_vsi_init_vlan_ops(vsi);
80 break;
81 case ICE_VSI_SF:
82 ice_sf_vsi_init_vlan_ops(vsi);
83 break;
84 default:
85 dev_dbg(ice_pf_to_dev(vsi->back), "%s does not support VLAN operations\n",
86 ice_vsi_type_str(vsi->type));
87 break;
88 }
89 }
90
91 /**
92 * ice_get_compat_vsi_vlan_ops - Get VSI VLAN ops based on VLAN mode
93 * @vsi: VSI used to get the VSI VLAN ops
94 *
95 * This function is meant to be used when the caller doesn't know which VLAN ops
96 * to use (i.e. inner or outer). This allows backward compatibility for VLANs
97 * since most of the Outer VSI VLAN functins are not supported when
98 * the device is configured in Single VLAN Mode (SVM).
99 */
ice_get_compat_vsi_vlan_ops(struct ice_vsi * vsi)100 struct ice_vsi_vlan_ops *ice_get_compat_vsi_vlan_ops(struct ice_vsi *vsi)
101 {
102 if (ice_is_dvm_ena(&vsi->back->hw))
103 return &vsi->outer_vlan_ops;
104 else
105 return &vsi->inner_vlan_ops;
106 }
107