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
11 static int
noop_vlan_arg(struct ice_vsi __always_unused * vsi,struct ice_vlan __always_unused * vlan)12 noop_vlan_arg(struct ice_vsi __always_unused *vsi,
13 struct ice_vlan __always_unused *vlan)
14 {
15 return 0;
16 }
17
18 static int
noop_vlan(struct ice_vsi __always_unused * vsi)19 noop_vlan(struct ice_vsi __always_unused *vsi)
20 {
21 return 0;
22 }
23
ice_port_vlan_on(struct ice_vsi * vsi)24 static 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(&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
36 /* setup inner VLAN ops */
37 vlan_ops = &vsi->inner_vlan_ops;
38 vlan_ops->add_vlan = noop_vlan_arg;
39 vlan_ops->del_vlan = noop_vlan_arg;
40 vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
41 vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
42 vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
43 vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
44 } else {
45 vlan_ops = &vsi->inner_vlan_ops;
46
47 vlan_ops->set_port_vlan = ice_vsi_set_inner_port_vlan;
48 vlan_ops->clear_port_vlan = ice_vsi_clear_inner_port_vlan;
49 }
50
51 /* all Rx traffic should be in the domain of the assigned port VLAN,
52 * so prevent disabling Rx VLAN filtering
53 */
54 vlan_ops->dis_rx_filtering = noop_vlan;
55
56 vlan_ops->ena_rx_filtering = ice_vsi_ena_rx_vlan_filtering;
57 }
58
ice_port_vlan_off(struct ice_vsi * vsi)59 static void ice_port_vlan_off(struct ice_vsi *vsi)
60 {
61 struct ice_vsi_vlan_ops *vlan_ops;
62 struct ice_pf *pf = vsi->back;
63
64 /* setup inner VLAN ops */
65 vlan_ops = &vsi->inner_vlan_ops;
66
67 vlan_ops->ena_stripping = ice_vsi_ena_inner_stripping;
68 vlan_ops->dis_stripping = ice_vsi_dis_inner_stripping;
69 vlan_ops->ena_insertion = ice_vsi_ena_inner_insertion;
70 vlan_ops->dis_insertion = ice_vsi_dis_inner_insertion;
71
72 if (ice_is_dvm_ena(&pf->hw)) {
73 vlan_ops = &vsi->outer_vlan_ops;
74
75 vlan_ops->del_vlan = ice_vsi_del_vlan;
76 vlan_ops->ena_stripping = ice_vsi_ena_outer_stripping;
77 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
78 vlan_ops->ena_insertion = ice_vsi_ena_outer_insertion;
79 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
80 } else {
81 vlan_ops->del_vlan = ice_vsi_del_vlan;
82 }
83
84 vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
85
86 if (!test_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags))
87 vlan_ops->ena_rx_filtering = noop_vlan;
88 else
89 vlan_ops->ena_rx_filtering =
90 ice_vsi_ena_rx_vlan_filtering;
91 }
92
93 /**
94 * ice_vf_vsi_enable_port_vlan - Set VSI VLAN ops to support port VLAN
95 * @vsi: VF's VSI being configured
96 *
97 * The function won't create port VLAN, it only allows to create port VLAN
98 * using VLAN ops on the VF VSI.
99 */
ice_vf_vsi_enable_port_vlan(struct ice_vsi * vsi)100 void ice_vf_vsi_enable_port_vlan(struct ice_vsi *vsi)
101 {
102 if (WARN_ON_ONCE(!vsi->vf))
103 return;
104
105 ice_port_vlan_on(vsi);
106 }
107
108 /**
109 * ice_vf_vsi_disable_port_vlan - Clear VSI support for creating port VLAN
110 * @vsi: VF's VSI being configured
111 *
112 * The function should be called after removing port VLAN on VSI
113 * (using VLAN ops)
114 */
ice_vf_vsi_disable_port_vlan(struct ice_vsi * vsi)115 void ice_vf_vsi_disable_port_vlan(struct ice_vsi *vsi)
116 {
117 if (WARN_ON_ONCE(!vsi->vf))
118 return;
119
120 ice_port_vlan_off(vsi);
121 }
122
123 /**
124 * ice_vf_vsi_init_vlan_ops - Initialize default VSI VLAN ops for VF VSI
125 * @vsi: VF's VSI being configured
126 *
127 * If Double VLAN Mode (DVM) is enabled, assume that the VF supports the new
128 * VIRTCHNL_VF_VLAN_OFFLOAD_V2 capability and set up the VLAN ops accordingly.
129 * If SVM is enabled maintain the same level of VLAN support previous to
130 * VIRTCHNL_VF_VLAN_OFFLOAD_V2.
131 */
ice_vf_vsi_init_vlan_ops(struct ice_vsi * vsi)132 void ice_vf_vsi_init_vlan_ops(struct ice_vsi *vsi)
133 {
134 struct ice_vsi_vlan_ops *vlan_ops;
135 struct ice_pf *pf = vsi->back;
136 struct ice_vf *vf = vsi->vf;
137
138 if (WARN_ON(!vf))
139 return;
140
141 if (ice_vf_is_port_vlan_ena(vf))
142 ice_port_vlan_on(vsi);
143 else
144 ice_port_vlan_off(vsi);
145
146 vlan_ops = ice_is_dvm_ena(&pf->hw) ?
147 &vsi->outer_vlan_ops : &vsi->inner_vlan_ops;
148
149 vlan_ops->add_vlan = ice_vsi_add_vlan;
150 vlan_ops->ena_tx_filtering = ice_vsi_ena_tx_vlan_filtering;
151 vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
152 }
153
154 /**
155 * ice_vf_vsi_cfg_dvm_legacy_vlan_mode - Config VLAN mode for old VFs in DVM
156 * @vsi: VF's VSI being configured
157 *
158 * This should only be called when Double VLAN Mode (DVM) is enabled, there
159 * is not a port VLAN enabled on this VF, and the VF negotiates
160 * VIRTCHNL_VF_OFFLOAD_VLAN.
161 *
162 * This function sets up the VF VSI's inner and outer ice_vsi_vlan_ops and also
163 * initializes software only VLAN mode (i.e. allow all VLANs). Also, use no-op
164 * implementations for any functions that may be called during the lifetime of
165 * the VF so these methods do nothing and succeed.
166 */
ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi * vsi)167 void ice_vf_vsi_cfg_dvm_legacy_vlan_mode(struct ice_vsi *vsi)
168 {
169 struct ice_vsi_vlan_ops *vlan_ops;
170 struct ice_vf *vf = vsi->vf;
171 struct device *dev;
172
173 if (WARN_ON(!vf))
174 return;
175
176 dev = ice_pf_to_dev(vf->pf);
177
178 if (!ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
179 return;
180
181 vlan_ops = &vsi->outer_vlan_ops;
182
183 /* Rx VLAN filtering always disabled to allow software offloaded VLANs
184 * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
185 * port VLAN configured
186 */
187 vlan_ops->dis_rx_filtering = ice_vsi_dis_rx_vlan_filtering;
188 /* Don't fail when attempting to enable Rx VLAN filtering */
189 vlan_ops->ena_rx_filtering = noop_vlan;
190
191 /* Tx VLAN filtering always disabled to allow software offloaded VLANs
192 * for VFs that only support VIRTCHNL_VF_OFFLOAD_VLAN and don't have a
193 * port VLAN configured
194 */
195 vlan_ops->dis_tx_filtering = ice_vsi_dis_tx_vlan_filtering;
196 /* Don't fail when attempting to enable Tx VLAN filtering */
197 vlan_ops->ena_tx_filtering = noop_vlan;
198
199 if (vlan_ops->dis_rx_filtering(vsi))
200 dev_dbg(dev, "Failed to disable Rx VLAN filtering for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
201 if (vlan_ops->dis_tx_filtering(vsi))
202 dev_dbg(dev, "Failed to disable Tx VLAN filtering for old VF without VIRTHCNL_VF_OFFLOAD_VLAN_V2 support\n");
203
204 /* All outer VLAN offloads must be disabled */
205 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
206 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
207
208 if (vlan_ops->dis_stripping(vsi))
209 dev_dbg(dev, "Failed to disable outer VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
210
211 if (vlan_ops->dis_insertion(vsi))
212 dev_dbg(dev, "Failed to disable outer VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
213
214 /* All inner VLAN offloads must be disabled */
215 vlan_ops = &vsi->inner_vlan_ops;
216
217 vlan_ops->dis_stripping = ice_vsi_dis_outer_stripping;
218 vlan_ops->dis_insertion = ice_vsi_dis_outer_insertion;
219
220 if (vlan_ops->dis_stripping(vsi))
221 dev_dbg(dev, "Failed to disable inner VLAN stripping for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
222
223 if (vlan_ops->dis_insertion(vsi))
224 dev_dbg(dev, "Failed to disable inner VLAN insertion for old VF without VIRTCHNL_VF_OFFLOAD_VLAN_V2 support\n");
225 }
226
227 /**
228 * ice_vf_vsi_cfg_svm_legacy_vlan_mode - Config VLAN mode for old VFs in SVM
229 * @vsi: VF's VSI being configured
230 *
231 * This should only be called when Single VLAN Mode (SVM) is enabled, there is
232 * not a port VLAN enabled on this VF, and the VF negotiates
233 * VIRTCHNL_VF_OFFLOAD_VLAN.
234 *
235 * All of the normal SVM VLAN ops are identical for this case. However, by
236 * default Rx VLAN filtering should be turned off by default in this case.
237 */
ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi * vsi)238 void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi)
239 {
240 struct ice_vf *vf = vsi->vf;
241
242 if (WARN_ON(!vf))
243 return;
244
245 if (ice_is_dvm_ena(&vsi->back->hw) || ice_vf_is_port_vlan_ena(vf))
246 return;
247
248 if (vsi->inner_vlan_ops.dis_rx_filtering(vsi))
249 dev_dbg(ice_pf_to_dev(vf->pf), "Failed to disable Rx VLAN filtering for old VF with VIRTCHNL_VF_OFFLOAD_VLAN support\n");
250 }
251