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