1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (C) 2019-2021, Intel Corporation. */
3
4#include "ice_vsi_vlan_ops.h"
5#include "ice_vsi_vlan_lib.h"
6#include "ice_vlan_mode.h"
7#include "ice.h"
8#include "ice_vf_vsi_vlan_ops.h"
9#include "ice_sriov.h"
10
11static int
12noop_vlan_arg(struct ice_vsi __always_unused *vsi,
13 struct ice_vlan __always_unused *vlan)
14{
15 return 0;
16}
17
18static int
19noop_vlan(struct ice_vsi __always_unused *vsi)
20{
21 return 0;
22}
23
24static void ice_port_vlan_on(struct ice_vsi *vsi)
25{
26 struct ice_vsi_vlan_ops *vlan_ops;
27 struct ice_pf *pf = vsi->back;
28
29 if (ice_is_dvm_ena(hw: &pf->hw)) {
30 vlan_ops = &vsi->outer_vlan_ops;
31
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;
36
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;
45 } else {
46 vlan_ops = &vsi->inner_vlan_ops;
47
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;
51 }
52 vlan_ops->ena_rx_filtering = ice_vsi_ena_rx_vlan_filtering;
53}
54
55static void ice_port_vlan_off(struct ice_vsi *vsi)
56{
57 struct ice_vsi_vlan_ops *vlan_ops;
58 struct ice_pf *pf = vsi->back;
59
60 /* setup inner VLAN ops */
61 vlan_ops = &vsi->inner_vlan_ops;
62
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;
67
68 if (ice_is_dvm_ena(hw: &pf->hw)) {
69 vlan_ops = &vsi->outer_vlan_ops;
70
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;
76 } else {
77 vlan_ops->del_vlan = ice_vsi_del_vlan;
78 }
79
80 if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
81 vlan_ops->ena_rx_filtering = noop_vlan;
82 else
83 vlan_ops->ena_rx_filtering =
84 ice_vsi_ena_rx_vlan_filtering;
85}
86
87/**
88 * ice_vf_vsi_enable_port_vlan - Set VSI VLAN ops to support port VLAN
89 * @vsi: VF's VSI being configured
90 *
91 * The function won't create port VLAN, it only allows to create port VLAN
92 * using VLAN ops on the VF VSI.
93 */
94void ice_vf_vsi_enable_port_vlan(struct ice_vsi *vsi)
95{
96 if (WARN_ON_ONCE(!vsi->vf))
97 return;
98
99 ice_port_vlan_on(vsi);
100}
101
102/**
103 * ice_vf_vsi_disable_port_vlan - Clear VSI support for creating port VLAN
104 * @vsi: VF's VSI being configured
105 *
106 * The function should be called after removing port VLAN on VSI
107 * (using VLAN ops)
108 */
109void ice_vf_vsi_disable_port_vlan(struct ice_vsi *vsi)
110{
111 if (WARN_ON_ONCE(!vsi->vf))
112 return;
113
114 ice_port_vlan_off(vsi);
115}
116
117/**
118 * ice_vf_vsi_init_vlan_ops - Initialize default VSI VLAN ops for VF VSI
119 * @vsi: VF's VSI being configured
120 *
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.
125 */
126void ice_vf_vsi_init_vlan_ops(struct ice_vsi *vsi)
127{
128 struct ice_vsi_vlan_ops *vlan_ops;
129 struct ice_pf *pf = vsi->back;
130 struct ice_vf *vf = vsi->vf;
131
132 if (WARN_ON(!vf))
133 return;
134
135 if (ice_vf_is_port_vlan_ena(vf))
136 ice_port_vlan_on(vsi);
137 else
138 ice_port_vlan_off(vsi);
139
140 vlan_ops = ice_is_dvm_ena(hw: &pf->hw) ?
141 &vsi->outer_vlan_ops : &vsi->inner_vlan_ops;
142
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;
147}
148
149/**
150 * ice_vf_vsi_cfg_dvm_legacy_vlan_mode - Config VLAN mode for old VFs in DVM
151 * @vsi: VF's VSI being configured
152 *
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.
156 *
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.
161 */
162void ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi *vsi)
163{
164 struct ice_vsi_vlan_ops *vlan_ops;
165 struct ice_vf *vf = vsi->vf;
166 struct device *dev;
167
168 if (WARN_ON(!vf))
169 return;
170
171 dev = ice_pf_to_dev(vf->pf);
172
173 if (!ice_is_dvm_ena(hw: &vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
174 return;
175
176 vlan_ops = &vsi->outer_vlan_ops;
177
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
181 */
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;
185
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
189 */
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;
193
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");
198
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;
202
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");
205
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");
208
209 /* All inner VLAN offloads must be disabled */
210 vlan_ops = &vsi->inner_vlan_ops;
211
212 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
213 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
214
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");
217
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");
220}
221
222/**
223 * ice_vf_vsi_cfg_svm_legacy_vlan_mode - Config VLAN mode for old VFs in SVM
224 * @vsi: VF's VSI being configured
225 *
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.
229 *
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.
232 */
233void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi)
234{
235 struct ice_vf *vf = vsi->vf;
236
237 if (WARN_ON(!vf))
238 return;
239
240 if (ice_is_dvm_ena(hw: &vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
241 return;
242
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");
245}
246

source code of linux/drivers/net/ethernet/intel/ice/ice_vf_vsi_vlan_ops.c