1c31af68aSBrett Creeley // SPDX-License-Identifier: GPL-2.0
2c31af68aSBrett Creeley /* Copyright (C) 2019-2021, Intel Corporation. */
3c31af68aSBrett Creeley
4c31af68aSBrett Creeley #include "ice_vsi_vlan_ops.h"
5c31af68aSBrett Creeley #include "ice_vsi_vlan_lib.h"
6a1ffafb0SBrett Creeley #include "ice_vlan_mode.h"
7c31af68aSBrett Creeley #include "ice.h"
8c31af68aSBrett Creeley #include "ice_vf_vsi_vlan_ops.h"
90deb0bf7SJacob Keller #include "ice_sriov.h"
10c31af68aSBrett Creeley
11c31af68aSBrett Creeley static int
noop_vlan_arg(struct ice_vsi __always_unused * vsi,struct ice_vlan __always_unused * vlan)12c31af68aSBrett Creeley noop_vlan_arg(struct ice_vsi __always_unused *vsi,
13c31af68aSBrett Creeley struct ice_vlan __always_unused *vlan)
14c31af68aSBrett Creeley {
15c31af68aSBrett Creeley return 0;
16c31af68aSBrett Creeley }
17c31af68aSBrett Creeley
18cc71de8fSBrett Creeley static int
noop_vlan(struct ice_vsi __always_unused * vsi)19cc71de8fSBrett Creeley noop_vlan(struct ice_vsi __always_unused *vsi)
20cc71de8fSBrett Creeley {
21cc71de8fSBrett Creeley return 0;
22cc71de8fSBrett Creeley }
23cc71de8fSBrett Creeley
ice_port_vlan_on(struct ice_vsi * vsi)242946204bSMichal Swiatkowski static void ice_port_vlan_on(struct ice_vsi *vsi)
252946204bSMichal Swiatkowski {
262946204bSMichal Swiatkowski struct ice_vsi_vlan_ops *vlan_ops;
272946204bSMichal Swiatkowski struct ice_pf *pf = vsi->back;
282946204bSMichal Swiatkowski
292946204bSMichal Swiatkowski /* setup inner VLAN ops */
302946204bSMichal Swiatkowski vlan_ops = &vsi->inner_vlan_ops;
31*b9bd1498SPetr Oros
32*b9bd1498SPetr Oros if (ice_is_dvm_ena(&pf->hw)) {
332946204bSMichal Swiatkowski vlan_ops->add_vlan = noop_vlan_arg;
342946204bSMichal Swiatkowski vlan_ops->del_vlan = noop_vlan_arg;
352946204bSMichal Swiatkowski vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
362946204bSMichal Swiatkowski vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
372946204bSMichal Swiatkowski vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
382946204bSMichal Swiatkowski vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
392946204bSMichal Swiatkowski
40*b9bd1498SPetr Oros /* setup outer VLAN ops */
41*b9bd1498SPetr Oros vlan_ops = &vsi->outer_vlan_ops;
42*b9bd1498SPetr Oros vlan_ops->set_port_vlan = ice_vsi_set_outer_port_vlan;
43*b9bd1498SPetr Oros vlan_ops->clear_port_vlan = ice_vsi_clear_outer_port_vlan;
44*b9bd1498SPetr Oros } else {
452946204bSMichal Swiatkowski vlan_ops->set_port_vlan = ice_vsi_set_inner_port_vlan;
462946204bSMichal Swiatkowski vlan_ops->clear_port_vlan = ice_vsi_clear_inner_port_vlan;
472946204bSMichal Swiatkowski }
482442e9cbSMarcin Szycik
492442e9cbSMarcin Szycik /* all Rx traffic should be in the domain of the assigned port VLAN,
502442e9cbSMarcin Szycik * so prevent disabling Rx VLAN filtering
512442e9cbSMarcin Szycik */
522442e9cbSMarcin Szycik vlan_ops->dis_rx_filtering = noop_vlan;
532442e9cbSMarcin Szycik
542946204bSMichal Swiatkowski vlan_ops->ena_rx_filtering = ice_vsi_ena_rx_vlan_filtering;
552946204bSMichal Swiatkowski }
562946204bSMichal Swiatkowski
ice_port_vlan_off(struct ice_vsi * vsi)572946204bSMichal Swiatkowski static void ice_port_vlan_off(struct ice_vsi *vsi)
582946204bSMichal Swiatkowski {
592946204bSMichal Swiatkowski struct ice_vsi_vlan_ops *vlan_ops;
602946204bSMichal Swiatkowski struct ice_pf *pf = vsi->back;
612946204bSMichal Swiatkowski
622946204bSMichal Swiatkowski /* setup inner VLAN ops */
632946204bSMichal Swiatkowski vlan_ops = &vsi->inner_vlan_ops;
642946204bSMichal Swiatkowski
652946204bSMichal Swiatkowski vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
662946204bSMichal Swiatkowski vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
672946204bSMichal Swiatkowski vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
682946204bSMichal Swiatkowski vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
692946204bSMichal Swiatkowski
702946204bSMichal Swiatkowski if (ice_is_dvm_ena(&pf->hw)) {
712946204bSMichal Swiatkowski vlan_ops = &vsi->outer_vlan_ops;
722946204bSMichal Swiatkowski
732946204bSMichal Swiatkowski vlan_ops->del_vlan = ice_vsi_del_vlan;
742946204bSMichal Swiatkowski vlan_ops->ena_stripping = ice_vsi_ena_outer_stripping;
752946204bSMichal Swiatkowski vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
762946204bSMichal Swiatkowski vlan_ops->ena_insertion = ice_vsi_ena_outer_insertion;
772946204bSMichal Swiatkowski vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
782946204bSMichal Swiatkowski } else {
792946204bSMichal Swiatkowski vlan_ops->del_vlan = ice_vsi_del_vlan;
802946204bSMichal Swiatkowski }
812946204bSMichal Swiatkowski
822442e9cbSMarcin Szycik vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
832442e9cbSMarcin Szycik
842946204bSMichal Swiatkowski if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
852946204bSMichal Swiatkowski vlan_ops->ena_rx_filtering = noop_vlan;
862946204bSMichal Swiatkowski else
872946204bSMichal Swiatkowski vlan_ops->ena_rx_filtering =
882946204bSMichal Swiatkowski ice_vsi_ena_rx_vlan_filtering;
892946204bSMichal Swiatkowski }
902946204bSMichal Swiatkowski
912946204bSMichal Swiatkowski /**
922946204bSMichal Swiatkowski * ice_vf_vsi_enable_port_vlan - Set VSI VLAN ops to support port VLAN
932946204bSMichal Swiatkowski * @vsi: VF's VSI being configured
942946204bSMichal Swiatkowski *
952946204bSMichal Swiatkowski * The function won't create port VLAN, it only allows to create port VLAN
962946204bSMichal Swiatkowski * using VLAN ops on the VF VSI.
972946204bSMichal Swiatkowski */
ice_vf_vsi_enable_port_vlan(struct ice_vsi * vsi)982946204bSMichal Swiatkowski void ice_vf_vsi_enable_port_vlan(struct ice_vsi *vsi)
992946204bSMichal Swiatkowski {
1002946204bSMichal Swiatkowski if (WARN_ON_ONCE(!vsi->vf))
1012946204bSMichal Swiatkowski return;
1022946204bSMichal Swiatkowski
1032946204bSMichal Swiatkowski ice_port_vlan_on(vsi);
1042946204bSMichal Swiatkowski }
1052946204bSMichal Swiatkowski
1062946204bSMichal Swiatkowski /**
1072946204bSMichal Swiatkowski * ice_vf_vsi_disable_port_vlan - Clear VSI support for creating port VLAN
1082946204bSMichal Swiatkowski * @vsi: VF's VSI being configured
1092946204bSMichal Swiatkowski *
1102946204bSMichal Swiatkowski * The function should be called after removing port VLAN on VSI
1112946204bSMichal Swiatkowski * (using VLAN ops)
1122946204bSMichal Swiatkowski */
ice_vf_vsi_disable_port_vlan(struct ice_vsi * vsi)1132946204bSMichal Swiatkowski void ice_vf_vsi_disable_port_vlan(struct ice_vsi *vsi)
1142946204bSMichal Swiatkowski {
1152946204bSMichal Swiatkowski if (WARN_ON_ONCE(!vsi->vf))
1162946204bSMichal Swiatkowski return;
1172946204bSMichal Swiatkowski
1182946204bSMichal Swiatkowski ice_port_vlan_off(vsi);
1192946204bSMichal Swiatkowski }
1202946204bSMichal Swiatkowski
121c31af68aSBrett Creeley /**
122c31af68aSBrett Creeley * ice_vf_vsi_init_vlan_ops - Initialize default VSI VLAN ops for VF VSI
123c31af68aSBrett Creeley * @vsi: VF's VSI being configured
124cc71de8fSBrett Creeley *
125cc71de8fSBrett Creeley * If Double VLAN Mode (DVM) is enabled, assume that the VF supports the new
126cc71de8fSBrett Creeley * VIRTCHNL_VF_VLAN_OFFLOAD_V2 capability and set up the VLAN ops accordingly.
127cc71de8fSBrett Creeley * If SVM is enabled maintain the same level of VLAN support previous to
128cc71de8fSBrett Creeley * VIRTCHNL_VF_VLAN_OFFLOAD_V2.
129c31af68aSBrett Creeley */
ice_vf_vsi_init_vlan_ops(struct ice_vsi * vsi)130c31af68aSBrett Creeley void ice_vf_vsi_init_vlan_ops(struct ice_vsi *vsi)
131c31af68aSBrett Creeley {
132c31af68aSBrett Creeley struct ice_vsi_vlan_ops *vlan_ops;
133c31af68aSBrett Creeley struct ice_pf *pf = vsi->back;
134b03d519dSJacob Keller struct ice_vf *vf = vsi->vf;
135c31af68aSBrett Creeley
136b03d519dSJacob Keller if (WARN_ON(!vf))
137b03d519dSJacob Keller return;
138c31af68aSBrett Creeley
1392946204bSMichal Swiatkowski if (ice_vf_is_port_vlan_ena(vf))
1402946204bSMichal Swiatkowski ice_port_vlan_on(vsi);
141f1da5a08SBrett Creeley else
1422946204bSMichal Swiatkowski ice_port_vlan_off(vsi);
143f1da5a08SBrett Creeley
1442946204bSMichal Swiatkowski vlan_ops = ice_is_dvm_ena(&pf->hw) ?
1452946204bSMichal Swiatkowski &vsi->outer_vlan_ops : &vsi->inner_vlan_ops;
146cc71de8fSBrett Creeley
147c31af68aSBrett Creeley vlan_ops->add_vlan = ice_vsi_add_vlan;
148c31af68aSBrett Creeley vlan_ops->ena_tx_filtering = ice_vsi_ena_tx_vlan_filtering;
149c31af68aSBrett Creeley vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
150c31af68aSBrett Creeley }
151cc71de8fSBrett Creeley
152cc71de8fSBrett Creeley /**
153cc71de8fSBrett Creeley * ice_vf_vsi_cfg_dvm_legacy_vlan_mode - Config VLAN mode for old VFs in DVM
154cc71de8fSBrett Creeley * @vsi: VF's VSI being configured
155cc71de8fSBrett Creeley *
156cc71de8fSBrett Creeley * This should only be called when Double VLAN Mode (DVM) is enabled, there
157cc71de8fSBrett Creeley * is not a port VLAN enabled on this VF, and the VF negotiates
158cc71de8fSBrett Creeley * VIRTCHNL_VF_OFFLOAD_VLAN.
159cc71de8fSBrett Creeley *
160cc71de8fSBrett Creeley * This function sets up the VF VSI's inner and outer ice_vsi_vlan_ops and also
161cc71de8fSBrett Creeley * initializes software only VLAN mode (i.e. allow all VLANs). Also, use no-op
162cc71de8fSBrett Creeley * implementations for any functions that may be called during the lifetime of
163cc71de8fSBrett Creeley * the VF so these methods do nothing and succeed.
164cc71de8fSBrett Creeley */
ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi * vsi)165cc71de8fSBrett Creeley void ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi *vsi)
166cc71de8fSBrett Creeley {
167cc71de8fSBrett Creeley struct ice_vsi_vlan_ops *vlan_ops;
168b03d519dSJacob Keller struct ice_vf *vf = vsi->vf;
169b03d519dSJacob Keller struct device *dev;
170b03d519dSJacob Keller
171b03d519dSJacob Keller if (WARN_ON(!vf))
172b03d519dSJacob Keller return;
173b03d519dSJacob Keller
174b03d519dSJacob Keller dev = ice_pf_to_dev(vf->pf);
175cc71de8fSBrett Creeley
176cc71de8fSBrett Creeley if (!ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
177cc71de8fSBrett Creeley return;
178cc71de8fSBrett Creeley
179cc71de8fSBrett Creeley vlan_ops = &vsi->outer_vlan_ops;
180cc71de8fSBrett Creeley
181cc71de8fSBrett Creeley /* Rx VLAN filtering always disabled to allow software offloaded VLANs
182cc71de8fSBrett Creeley * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
183cc71de8fSBrett Creeley * port VLAN configured
184cc71de8fSBrett Creeley */
185cc71de8fSBrett Creeley vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
186cc71de8fSBrett Creeley /* Don't fail when attempting to enable Rx VLAN filtering */
187cc71de8fSBrett Creeley vlan_ops->ena_rx_filtering = noop_vlan;
188cc71de8fSBrett Creeley
189cc71de8fSBrett Creeley /* Tx VLAN filtering always disabled to allow software offloaded VLANs
190cc71de8fSBrett Creeley * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
191cc71de8fSBrett Creeley * port VLAN configured
192cc71de8fSBrett Creeley */
193cc71de8fSBrett Creeley vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
194cc71de8fSBrett Creeley /* Don't fail when attempting to enable Tx VLAN filtering */
195cc71de8fSBrett Creeley vlan_ops->ena_tx_filtering = noop_vlan;
196cc71de8fSBrett Creeley
197cc71de8fSBrett Creeley if (vlan_ops->dis_rx_filtering(vsi))
198cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable Rx VLAN filtering for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
199cc71de8fSBrett Creeley if (vlan_ops->dis_tx_filtering(vsi))
200cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable Tx VLAN filtering for old VF without VIRTHCNL_VF_OFFLOAD_VLAN_V2 support\n");
201cc71de8fSBrett Creeley
202cc71de8fSBrett Creeley /* All outer VLAN offloads must be disabled */
203cc71de8fSBrett Creeley vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
204cc71de8fSBrett Creeley vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
205cc71de8fSBrett Creeley
206cc71de8fSBrett Creeley if (vlan_ops->dis_stripping(vsi))
207cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable outer VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
208cc71de8fSBrett Creeley
209cc71de8fSBrett Creeley if (vlan_ops->dis_insertion(vsi))
210cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable outer VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
211cc71de8fSBrett Creeley
212cc71de8fSBrett Creeley /* All inner VLAN offloads must be disabled */
213cc71de8fSBrett Creeley vlan_ops = &vsi->inner_vlan_ops;
214cc71de8fSBrett Creeley
215cc71de8fSBrett Creeley vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
216cc71de8fSBrett Creeley vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
217cc71de8fSBrett Creeley
218cc71de8fSBrett Creeley if (vlan_ops->dis_stripping(vsi))
219cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable inner VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
220cc71de8fSBrett Creeley
221cc71de8fSBrett Creeley if (vlan_ops->dis_insertion(vsi))
222cc71de8fSBrett Creeley dev_dbg(dev, "Failed to disable inner VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
223cc71de8fSBrett Creeley }
224cc71de8fSBrett Creeley
225cc71de8fSBrett Creeley /**
226cc71de8fSBrett Creeley * ice_vf_vsi_cfg_svm_legacy_vlan_mode - Config VLAN mode for old VFs in SVM
227cc71de8fSBrett Creeley * @vsi: VF's VSI being configured
228cc71de8fSBrett Creeley *
229cc71de8fSBrett Creeley * This should only be called when Single VLAN Mode (SVM) is enabled, there is
230cc71de8fSBrett Creeley * not a port VLAN enabled on this VF, and the VF negotiates
231cc71de8fSBrett Creeley * VIRTCHNL_VF_OFFLOAD_VLAN.
232cc71de8fSBrett Creeley *
233cc71de8fSBrett Creeley * All of the normal SVM VLAN ops are identical for this case. However, by
234cc71de8fSBrett Creeley * default Rx VLAN filtering should be turned off by default in this case.
235cc71de8fSBrett Creeley */
ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi * vsi)236cc71de8fSBrett Creeley void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi)
237cc71de8fSBrett Creeley {
238b03d519dSJacob Keller struct ice_vf *vf = vsi->vf;
239b03d519dSJacob Keller
240b03d519dSJacob Keller if (WARN_ON(!vf))
241b03d519dSJacob Keller return;
242cc71de8fSBrett Creeley
243cc71de8fSBrett Creeley if (ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
244cc71de8fSBrett Creeley return;
245cc71de8fSBrett Creeley
246cc71de8fSBrett Creeley if (vsi->inner_vlan_ops.dis_rx_filtering(vsi))
247cc71de8fSBrett Creeley dev_dbg(ice_pf_to_dev(vf->pf), "Failed to disable Rx VLAN filtering for old VF with VIRTCHNL_VF_OFFLOAD_VLAN support\n");
248cc71de8fSBrett Creeley }
249