1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2019-2021, Intel Corporation. */
4 #include "ice_vsi_vlan_ops.h"
5 #include "ice_vsi_vlan_lib.h"
6 #include "ice_vlan_mode.h"
8 #include "ice_vf_vsi_vlan_ops.h"
12 noop_vlan_arg(struct ice_vsi __always_unused *vsi,
13 struct ice_vlan __always_unused *vlan)
19 noop_vlan(struct ice_vsi __always_unused *vsi)
24 static void ice_port_vlan_on(struct ice_vsi *vsi)
26 struct ice_vsi_vlan_ops *vlan_ops;
27 struct ice_pf *pf = vsi->back;
29 if (ice_is_dvm_ena(&pf->hw)) {
30 vlan_ops = &vsi->outer_vlan_ops;
32 /* setup outer VLAN ops */
33 vlan_ops->set_port_vlan = ice_vsi_set_outer_port_vlan;
34 vlan_ops->clear_port_vlan = ice_vsi_clear_outer_port_vlan;
35 vlan_ops->clear_port_vlan = ice_vsi_clear_outer_port_vlan;
37 /* setup inner VLAN ops */
38 vlan_ops = &vsi->inner_vlan_ops;
39 vlan_ops->add_vlan = noop_vlan_arg;
40 vlan_ops->del_vlan = noop_vlan_arg;
41 vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
42 vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
43 vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
44 vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
46 vlan_ops = &vsi->inner_vlan_ops;
48 vlan_ops->set_port_vlan = ice_vsi_set_inner_port_vlan;
49 vlan_ops->clear_port_vlan = ice_vsi_clear_inner_port_vlan;
50 vlan_ops->clear_port_vlan = ice_vsi_clear_inner_port_vlan;
52 vlan_ops->ena_rx_filtering = ice_vsi_ena_rx_vlan_filtering;
55 static void ice_port_vlan_off(struct ice_vsi *vsi)
57 struct ice_vsi_vlan_ops *vlan_ops;
58 struct ice_pf *pf = vsi->back;
60 /* setup inner VLAN ops */
61 vlan_ops = &vsi->inner_vlan_ops;
63 vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
64 vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
65 vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
66 vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
68 if (ice_is_dvm_ena(&pf->hw)) {
69 vlan_ops = &vsi->outer_vlan_ops;
71 vlan_ops->del_vlan = ice_vsi_del_vlan;
72 vlan_ops->ena_stripping = ice_vsi_ena_outer_stripping;
73 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
74 vlan_ops->ena_insertion = ice_vsi_ena_outer_insertion;
75 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
77 vlan_ops->del_vlan = ice_vsi_del_vlan;
80 if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
81 vlan_ops->ena_rx_filtering = noop_vlan;
83 vlan_ops->ena_rx_filtering =
84 ice_vsi_ena_rx_vlan_filtering;
88 * ice_vf_vsi_enable_port_vlan - Set VSI VLAN ops to support port VLAN
89 * @vsi: VF's VSI being configured
91 * The function won't create port VLAN, it only allows to create port VLAN
92 * using VLAN ops on the VF VSI.
94 void ice_vf_vsi_enable_port_vlan(struct ice_vsi *vsi)
96 if (WARN_ON_ONCE(!vsi->vf))
99 ice_port_vlan_on(vsi);
103 * ice_vf_vsi_disable_port_vlan - Clear VSI support for creating port VLAN
104 * @vsi: VF's VSI being configured
106 * The function should be called after removing port VLAN on VSI
109 void ice_vf_vsi_disable_port_vlan(struct ice_vsi *vsi)
111 if (WARN_ON_ONCE(!vsi->vf))
114 ice_port_vlan_off(vsi);
118 * ice_vf_vsi_init_vlan_ops - Initialize default VSI VLAN ops for VF VSI
119 * @vsi: VF's VSI being configured
121 * If Double VLAN Mode (DVM) is enabled, assume that the VF supports the new
122 * VIRTCHNL_VF_VLAN_OFFLOAD_V2 capability and set up the VLAN ops accordingly.
123 * If SVM is enabled maintain the same level of VLAN support previous to
124 * VIRTCHNL_VF_VLAN_OFFLOAD_V2.
126 void ice_vf_vsi_init_vlan_ops(struct ice_vsi *vsi)
128 struct ice_vsi_vlan_ops *vlan_ops;
129 struct ice_pf *pf = vsi->back;
130 struct ice_vf *vf = vsi->vf;
135 if (ice_vf_is_port_vlan_ena(vf))
136 ice_port_vlan_on(vsi);
138 ice_port_vlan_off(vsi);
140 vlan_ops = ice_is_dvm_ena(&pf->hw) ?
141 &vsi->outer_vlan_ops : &vsi->inner_vlan_ops;
143 vlan_ops->add_vlan = ice_vsi_add_vlan;
144 vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
145 vlan_ops->ena_tx_filtering = ice_vsi_ena_tx_vlan_filtering;
146 vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
150 * ice_vf_vsi_cfg_dvm_legacy_vlan_mode - Config VLAN mode for old VFs in DVM
151 * @vsi: VF's VSI being configured
153 * This should only be called when Double VLAN Mode (DVM) is enabled, there
154 * is not a port VLAN enabled on this VF, and the VF negotiates
155 * VIRTCHNL_VF_OFFLOAD_VLAN.
157 * This function sets up the VF VSI's inner and outer ice_vsi_vlan_ops and also
158 * initializes software only VLAN mode (i.e. allow all VLANs). Also, use no-op
159 * implementations for any functions that may be called during the lifetime of
160 * the VF so these methods do nothing and succeed.
162 void ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi *vsi)
164 struct ice_vsi_vlan_ops *vlan_ops;
165 struct ice_vf *vf = vsi->vf;
171 dev = ice_pf_to_dev(vf->pf);
173 if (!ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
176 vlan_ops = &vsi->outer_vlan_ops;
178 /* Rx VLAN filtering always disabled to allow software offloaded VLANs
179 * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
180 * port VLAN configured
182 vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
183 /* Don't fail when attempting to enable Rx VLAN filtering */
184 vlan_ops->ena_rx_filtering = noop_vlan;
186 /* Tx VLAN filtering always disabled to allow software offloaded VLANs
187 * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
188 * port VLAN configured
190 vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
191 /* Don't fail when attempting to enable Tx VLAN filtering */
192 vlan_ops->ena_tx_filtering = noop_vlan;
194 if (vlan_ops->dis_rx_filtering(vsi))
195 dev_dbg(dev, "Failed to disable Rx VLAN filtering for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
196 if (vlan_ops->dis_tx_filtering(vsi))
197 dev_dbg(dev, "Failed to disable Tx VLAN filtering for old VF without VIRTHCNL_VF_OFFLOAD_VLAN_V2 support\n");
199 /* All outer VLAN offloads must be disabled */
200 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
201 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
203 if (vlan_ops->dis_stripping(vsi))
204 dev_dbg(dev, "Failed to disable outer VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
206 if (vlan_ops->dis_insertion(vsi))
207 dev_dbg(dev, "Failed to disable outer VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
209 /* All inner VLAN offloads must be disabled */
210 vlan_ops = &vsi->inner_vlan_ops;
212 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
213 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
215 if (vlan_ops->dis_stripping(vsi))
216 dev_dbg(dev, "Failed to disable inner VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
218 if (vlan_ops->dis_insertion(vsi))
219 dev_dbg(dev, "Failed to disable inner VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
223 * ice_vf_vsi_cfg_svm_legacy_vlan_mode - Config VLAN mode for old VFs in SVM
224 * @vsi: VF's VSI being configured
226 * This should only be called when Single VLAN Mode (SVM) is enabled, there is
227 * not a port VLAN enabled on this VF, and the VF negotiates
228 * VIRTCHNL_VF_OFFLOAD_VLAN.
230 * All of the normal SVM VLAN ops are identical for this case. However, by
231 * default Rx VLAN filtering should be turned off by default in this case.
233 void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi)
235 struct ice_vf *vf = vsi->vf;
240 if (ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
243 if (vsi->inner_vlan_ops.dis_rx_filtering(vsi))
244 dev_dbg(ice_pf_to_dev(vf->pf), "Failed to disable Rx VLAN filtering for old VF with VIRTCHNL_VF_OFFLOAD_VLAN support\n");