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