Commit | Line | Data |
---|---|---|
5c3c48ac JB |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Driver | |
51616018 | 4 | * Copyright(c) 2013 - 2015 Intel Corporation. |
5c3c48ac JB |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
dc641b73 GR |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
5c3c48ac JB |
17 | * |
18 | * The full GNU General Public License is included in this distribution in | |
19 | * the file called "COPYING". | |
20 | * | |
21 | * Contact Information: | |
22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
24 | * | |
25 | ******************************************************************************/ | |
26 | ||
27 | #include "i40e.h" | |
28 | ||
532b0455 MW |
29 | /*********************notification routines***********************/ |
30 | ||
31 | /** | |
32 | * i40e_vc_vf_broadcast | |
33 | * @pf: pointer to the PF structure | |
34 | * @opcode: operation code | |
35 | * @retval: return value | |
36 | * @msg: pointer to the msg buffer | |
37 | * @msglen: msg length | |
38 | * | |
39 | * send a message to all VFs on a given PF | |
40 | **/ | |
41 | static void i40e_vc_vf_broadcast(struct i40e_pf *pf, | |
42 | enum i40e_virtchnl_ops v_opcode, | |
43 | i40e_status v_retval, u8 *msg, | |
44 | u16 msglen) | |
45 | { | |
46 | struct i40e_hw *hw = &pf->hw; | |
47 | struct i40e_vf *vf = pf->vf; | |
48 | int i; | |
49 | ||
50 | for (i = 0; i < pf->num_alloc_vfs; i++, vf++) { | |
51 | int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; | |
52 | /* Not all vfs are enabled so skip the ones that are not */ | |
53 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && | |
54 | !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) | |
55 | continue; | |
56 | ||
57 | /* Ignore return value on purpose - a given VF may fail, but | |
58 | * we need to keep going and send to all of them | |
59 | */ | |
60 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval, | |
61 | msg, msglen, NULL); | |
62 | } | |
63 | } | |
64 | ||
65 | /** | |
66 | * i40e_vc_notify_link_state | |
67 | * @vf: pointer to the VF structure | |
68 | * | |
69 | * send a link status message to a single VF | |
70 | **/ | |
71 | static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf) | |
72 | { | |
73 | struct i40e_virtchnl_pf_event pfe; | |
74 | struct i40e_pf *pf = vf->pf; | |
75 | struct i40e_hw *hw = &pf->hw; | |
76 | struct i40e_link_status *ls = &pf->hw.phy.link_info; | |
77 | int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; | |
78 | ||
79 | pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; | |
80 | pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; | |
81 | if (vf->link_forced) { | |
82 | pfe.event_data.link_event.link_status = vf->link_up; | |
83 | pfe.event_data.link_event.link_speed = | |
84 | (vf->link_up ? I40E_LINK_SPEED_40GB : 0); | |
85 | } else { | |
86 | pfe.event_data.link_event.link_status = | |
87 | ls->link_info & I40E_AQ_LINK_UP; | |
88 | pfe.event_data.link_event.link_speed = ls->link_speed; | |
89 | } | |
90 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, | |
91 | 0, (u8 *)&pfe, sizeof(pfe), NULL); | |
92 | } | |
93 | ||
94 | /** | |
95 | * i40e_vc_notify_link_state | |
96 | * @pf: pointer to the PF structure | |
97 | * | |
98 | * send a link status message to all VFs on a given PF | |
99 | **/ | |
100 | void i40e_vc_notify_link_state(struct i40e_pf *pf) | |
101 | { | |
102 | int i; | |
103 | ||
104 | for (i = 0; i < pf->num_alloc_vfs; i++) | |
105 | i40e_vc_notify_vf_link_state(&pf->vf[i]); | |
106 | } | |
107 | ||
108 | /** | |
109 | * i40e_vc_notify_reset | |
110 | * @pf: pointer to the PF structure | |
111 | * | |
112 | * indicate a pending reset to all VFs on a given PF | |
113 | **/ | |
114 | void i40e_vc_notify_reset(struct i40e_pf *pf) | |
115 | { | |
116 | struct i40e_virtchnl_pf_event pfe; | |
117 | ||
118 | pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING; | |
119 | pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM; | |
120 | i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0, | |
121 | (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event)); | |
122 | } | |
123 | ||
124 | /** | |
125 | * i40e_vc_notify_vf_reset | |
126 | * @vf: pointer to the VF structure | |
127 | * | |
128 | * indicate a pending reset to the given VF | |
129 | **/ | |
130 | void i40e_vc_notify_vf_reset(struct i40e_vf *vf) | |
131 | { | |
132 | struct i40e_virtchnl_pf_event pfe; | |
133 | int abs_vf_id; | |
134 | ||
135 | /* validate the request */ | |
136 | if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) | |
137 | return; | |
138 | ||
139 | /* verify if the VF is in either init or active before proceeding */ | |
140 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) && | |
141 | !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) | |
142 | return; | |
143 | ||
144 | abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id; | |
145 | ||
146 | pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING; | |
147 | pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM; | |
148 | i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, | |
149 | 0, (u8 *)&pfe, | |
150 | sizeof(struct i40e_virtchnl_pf_event), NULL); | |
151 | } | |
5c3c48ac JB |
152 | /***********************misc routines*****************************/ |
153 | ||
f9b4b627 GR |
154 | /** |
155 | * i40e_vc_disable_vf | |
b40c82e6 JK |
156 | * @pf: pointer to the PF info |
157 | * @vf: pointer to the VF info | |
f9b4b627 GR |
158 | * |
159 | * Disable the VF through a SW reset | |
160 | **/ | |
161 | static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf) | |
162 | { | |
163 | struct i40e_hw *hw = &pf->hw; | |
164 | u32 reg; | |
165 | ||
166 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); | |
167 | reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK; | |
168 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); | |
169 | i40e_flush(hw); | |
170 | } | |
171 | ||
5c3c48ac JB |
172 | /** |
173 | * i40e_vc_isvalid_vsi_id | |
b40c82e6 JK |
174 | * @vf: pointer to the VF info |
175 | * @vsi_id: VF relative VSI id | |
5c3c48ac | 176 | * |
b40c82e6 | 177 | * check for the valid VSI id |
5c3c48ac | 178 | **/ |
fdf0e0bf | 179 | static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id) |
5c3c48ac JB |
180 | { |
181 | struct i40e_pf *pf = vf->pf; | |
fdf0e0bf | 182 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
5c3c48ac | 183 | |
fdf0e0bf | 184 | return (vsi && (vsi->vf_id == vf->vf_id)); |
5c3c48ac JB |
185 | } |
186 | ||
187 | /** | |
188 | * i40e_vc_isvalid_queue_id | |
b40c82e6 | 189 | * @vf: pointer to the VF info |
5c3c48ac JB |
190 | * @vsi_id: vsi id |
191 | * @qid: vsi relative queue id | |
192 | * | |
193 | * check for the valid queue id | |
194 | **/ | |
fdf0e0bf | 195 | static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id, |
5c3c48ac JB |
196 | u8 qid) |
197 | { | |
198 | struct i40e_pf *pf = vf->pf; | |
fdf0e0bf | 199 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
5c3c48ac | 200 | |
fdf0e0bf | 201 | return (vsi && (qid < vsi->alloc_queue_pairs)); |
5c3c48ac JB |
202 | } |
203 | ||
204 | /** | |
205 | * i40e_vc_isvalid_vector_id | |
b40c82e6 JK |
206 | * @vf: pointer to the VF info |
207 | * @vector_id: VF relative vector id | |
5c3c48ac JB |
208 | * |
209 | * check for the valid vector id | |
210 | **/ | |
211 | static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id) | |
212 | { | |
213 | struct i40e_pf *pf = vf->pf; | |
214 | ||
9347eb77 | 215 | return vector_id < pf->hw.func_caps.num_msix_vectors_vf; |
5c3c48ac JB |
216 | } |
217 | ||
218 | /***********************vf resource mgmt routines*****************/ | |
219 | ||
220 | /** | |
221 | * i40e_vc_get_pf_queue_id | |
b40c82e6 | 222 | * @vf: pointer to the VF info |
fdf0e0bf | 223 | * @vsi_id: id of VSI as provided by the FW |
5c3c48ac JB |
224 | * @vsi_queue_id: vsi relative queue id |
225 | * | |
b40c82e6 | 226 | * return PF relative queue id |
5c3c48ac | 227 | **/ |
fdf0e0bf | 228 | static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id, |
5c3c48ac JB |
229 | u8 vsi_queue_id) |
230 | { | |
231 | struct i40e_pf *pf = vf->pf; | |
fdf0e0bf | 232 | struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); |
5c3c48ac JB |
233 | u16 pf_queue_id = I40E_QUEUE_END_OF_LIST; |
234 | ||
fdf0e0bf ASJ |
235 | if (!vsi) |
236 | return pf_queue_id; | |
237 | ||
5c3c48ac JB |
238 | if (le16_to_cpu(vsi->info.mapping_flags) & |
239 | I40E_AQ_VSI_QUE_MAP_NONCONTIG) | |
240 | pf_queue_id = | |
241 | le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]); | |
242 | else | |
243 | pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) + | |
244 | vsi_queue_id; | |
245 | ||
246 | return pf_queue_id; | |
247 | } | |
248 | ||
5c3c48ac JB |
249 | /** |
250 | * i40e_config_irq_link_list | |
b40c82e6 | 251 | * @vf: pointer to the VF info |
fdf0e0bf | 252 | * @vsi_id: id of VSI as given by the FW |
5c3c48ac JB |
253 | * @vecmap: irq map info |
254 | * | |
255 | * configure irq link list from the map | |
256 | **/ | |
fdf0e0bf | 257 | static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id, |
5c3c48ac JB |
258 | struct i40e_virtchnl_vector_map *vecmap) |
259 | { | |
260 | unsigned long linklistmap = 0, tempmap; | |
261 | struct i40e_pf *pf = vf->pf; | |
262 | struct i40e_hw *hw = &pf->hw; | |
263 | u16 vsi_queue_id, pf_queue_id; | |
264 | enum i40e_queue_type qtype; | |
265 | u16 next_q, vector_id; | |
266 | u32 reg, reg_idx; | |
267 | u16 itr_idx = 0; | |
268 | ||
269 | vector_id = vecmap->vector_id; | |
270 | /* setup the head */ | |
271 | if (0 == vector_id) | |
272 | reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); | |
273 | else | |
274 | reg_idx = I40E_VPINT_LNKLSTN( | |
9347eb77 MW |
275 | ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) + |
276 | (vector_id - 1)); | |
5c3c48ac JB |
277 | |
278 | if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) { | |
279 | /* Special case - No queues mapped on this vector */ | |
280 | wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK); | |
281 | goto irq_list_done; | |
282 | } | |
283 | tempmap = vecmap->rxq_map; | |
4836650b | 284 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
5c3c48ac JB |
285 | linklistmap |= (1 << |
286 | (I40E_VIRTCHNL_SUPPORTED_QTYPES * | |
287 | vsi_queue_id)); | |
5c3c48ac JB |
288 | } |
289 | ||
290 | tempmap = vecmap->txq_map; | |
4836650b | 291 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
5c3c48ac JB |
292 | linklistmap |= (1 << |
293 | (I40E_VIRTCHNL_SUPPORTED_QTYPES * vsi_queue_id | |
294 | + 1)); | |
5c3c48ac JB |
295 | } |
296 | ||
297 | next_q = find_first_bit(&linklistmap, | |
298 | (I40E_MAX_VSI_QP * | |
299 | I40E_VIRTCHNL_SUPPORTED_QTYPES)); | |
300 | vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES; | |
301 | qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES; | |
fdf0e0bf | 302 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
5c3c48ac JB |
303 | reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id); |
304 | ||
305 | wr32(hw, reg_idx, reg); | |
306 | ||
307 | while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) { | |
308 | switch (qtype) { | |
309 | case I40E_QUEUE_TYPE_RX: | |
310 | reg_idx = I40E_QINT_RQCTL(pf_queue_id); | |
311 | itr_idx = vecmap->rxitr_idx; | |
312 | break; | |
313 | case I40E_QUEUE_TYPE_TX: | |
314 | reg_idx = I40E_QINT_TQCTL(pf_queue_id); | |
315 | itr_idx = vecmap->txitr_idx; | |
316 | break; | |
317 | default: | |
318 | break; | |
319 | } | |
320 | ||
321 | next_q = find_next_bit(&linklistmap, | |
322 | (I40E_MAX_VSI_QP * | |
323 | I40E_VIRTCHNL_SUPPORTED_QTYPES), | |
324 | next_q + 1); | |
829af3ac MW |
325 | if (next_q < |
326 | (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) { | |
5c3c48ac JB |
327 | vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES; |
328 | qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES; | |
fdf0e0bf | 329 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, |
5c3c48ac JB |
330 | vsi_queue_id); |
331 | } else { | |
332 | pf_queue_id = I40E_QUEUE_END_OF_LIST; | |
333 | qtype = 0; | |
334 | } | |
335 | ||
336 | /* format for the RQCTL & TQCTL regs is same */ | |
337 | reg = (vector_id) | | |
338 | (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) | | |
339 | (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | | |
340 | (1 << I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) | | |
341 | (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT); | |
342 | wr32(hw, reg_idx, reg); | |
343 | } | |
344 | ||
345 | irq_list_done: | |
346 | i40e_flush(hw); | |
347 | } | |
348 | ||
349 | /** | |
350 | * i40e_config_vsi_tx_queue | |
b40c82e6 | 351 | * @vf: pointer to the VF info |
fdf0e0bf | 352 | * @vsi_id: id of VSI as provided by the FW |
5c3c48ac JB |
353 | * @vsi_queue_id: vsi relative queue index |
354 | * @info: config. info | |
355 | * | |
356 | * configure tx queue | |
357 | **/ | |
fdf0e0bf | 358 | static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id, |
5c3c48ac JB |
359 | u16 vsi_queue_id, |
360 | struct i40e_virtchnl_txq_info *info) | |
361 | { | |
362 | struct i40e_pf *pf = vf->pf; | |
363 | struct i40e_hw *hw = &pf->hw; | |
364 | struct i40e_hmc_obj_txq tx_ctx; | |
fdf0e0bf | 365 | struct i40e_vsi *vsi; |
5c3c48ac JB |
366 | u16 pf_queue_id; |
367 | u32 qtx_ctl; | |
368 | int ret = 0; | |
369 | ||
fdf0e0bf ASJ |
370 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
371 | vsi = i40e_find_vsi_from_id(pf, vsi_id); | |
5c3c48ac JB |
372 | |
373 | /* clear the context structure first */ | |
374 | memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq)); | |
375 | ||
376 | /* only set the required fields */ | |
377 | tx_ctx.base = info->dma_ring_addr / 128; | |
378 | tx_ctx.qlen = info->ring_len; | |
fdf0e0bf | 379 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]); |
5c3c48ac | 380 | tx_ctx.rdylist_act = 0; |
5d29896a AS |
381 | tx_ctx.head_wb_ena = info->headwb_enabled; |
382 | tx_ctx.head_wb_addr = info->dma_headwb_addr; | |
5c3c48ac JB |
383 | |
384 | /* clear the context in the HMC */ | |
385 | ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id); | |
386 | if (ret) { | |
387 | dev_err(&pf->pdev->dev, | |
388 | "Failed to clear VF LAN Tx queue context %d, error: %d\n", | |
389 | pf_queue_id, ret); | |
390 | ret = -ENOENT; | |
391 | goto error_context; | |
392 | } | |
393 | ||
394 | /* set the context in the HMC */ | |
395 | ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx); | |
396 | if (ret) { | |
397 | dev_err(&pf->pdev->dev, | |
398 | "Failed to set VF LAN Tx queue context %d error: %d\n", | |
399 | pf_queue_id, ret); | |
400 | ret = -ENOENT; | |
401 | goto error_context; | |
402 | } | |
403 | ||
404 | /* associate this queue with the PCI VF function */ | |
405 | qtx_ctl = I40E_QTX_CTL_VF_QUEUE; | |
13fd9774 | 406 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) |
5c3c48ac JB |
407 | & I40E_QTX_CTL_PF_INDX_MASK); |
408 | qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id) | |
409 | << I40E_QTX_CTL_VFVM_INDX_SHIFT) | |
410 | & I40E_QTX_CTL_VFVM_INDX_MASK); | |
411 | wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl); | |
412 | i40e_flush(hw); | |
413 | ||
414 | error_context: | |
415 | return ret; | |
416 | } | |
417 | ||
418 | /** | |
419 | * i40e_config_vsi_rx_queue | |
b40c82e6 | 420 | * @vf: pointer to the VF info |
fdf0e0bf | 421 | * @vsi_id: id of VSI as provided by the FW |
5c3c48ac JB |
422 | * @vsi_queue_id: vsi relative queue index |
423 | * @info: config. info | |
424 | * | |
425 | * configure rx queue | |
426 | **/ | |
fdf0e0bf | 427 | static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id, |
5c3c48ac JB |
428 | u16 vsi_queue_id, |
429 | struct i40e_virtchnl_rxq_info *info) | |
430 | { | |
431 | struct i40e_pf *pf = vf->pf; | |
432 | struct i40e_hw *hw = &pf->hw; | |
433 | struct i40e_hmc_obj_rxq rx_ctx; | |
434 | u16 pf_queue_id; | |
435 | int ret = 0; | |
436 | ||
fdf0e0bf | 437 | pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id); |
5c3c48ac JB |
438 | |
439 | /* clear the context structure first */ | |
440 | memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq)); | |
441 | ||
442 | /* only set the required fields */ | |
443 | rx_ctx.base = info->dma_ring_addr / 128; | |
444 | rx_ctx.qlen = info->ring_len; | |
445 | ||
446 | if (info->splithdr_enabled) { | |
447 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | | |
448 | I40E_RX_SPLIT_IP | | |
449 | I40E_RX_SPLIT_TCP_UDP | | |
450 | I40E_RX_SPLIT_SCTP; | |
451 | /* header length validation */ | |
452 | if (info->hdr_size > ((2 * 1024) - 64)) { | |
453 | ret = -EINVAL; | |
454 | goto error_param; | |
455 | } | |
456 | rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT; | |
457 | ||
458 | /* set splitalways mode 10b */ | |
459 | rx_ctx.dtype = 0x2; | |
460 | } | |
461 | ||
462 | /* databuffer length validation */ | |
463 | if (info->databuffer_size > ((16 * 1024) - 128)) { | |
464 | ret = -EINVAL; | |
465 | goto error_param; | |
466 | } | |
467 | rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT; | |
468 | ||
469 | /* max pkt. length validation */ | |
470 | if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) { | |
471 | ret = -EINVAL; | |
472 | goto error_param; | |
473 | } | |
474 | rx_ctx.rxmax = info->max_pkt_size; | |
475 | ||
476 | /* enable 32bytes desc always */ | |
477 | rx_ctx.dsize = 1; | |
478 | ||
479 | /* default values */ | |
5c3c48ac JB |
480 | rx_ctx.lrxqthresh = 2; |
481 | rx_ctx.crcstrip = 1; | |
50d41659 | 482 | rx_ctx.prefena = 1; |
c1d11cef | 483 | rx_ctx.l2tsel = 1; |
5c3c48ac JB |
484 | |
485 | /* clear the context in the HMC */ | |
486 | ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id); | |
487 | if (ret) { | |
488 | dev_err(&pf->pdev->dev, | |
489 | "Failed to clear VF LAN Rx queue context %d, error: %d\n", | |
490 | pf_queue_id, ret); | |
491 | ret = -ENOENT; | |
492 | goto error_param; | |
493 | } | |
494 | ||
495 | /* set the context in the HMC */ | |
496 | ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx); | |
497 | if (ret) { | |
498 | dev_err(&pf->pdev->dev, | |
499 | "Failed to set VF LAN Rx queue context %d error: %d\n", | |
500 | pf_queue_id, ret); | |
501 | ret = -ENOENT; | |
502 | goto error_param; | |
503 | } | |
504 | ||
505 | error_param: | |
506 | return ret; | |
507 | } | |
508 | ||
509 | /** | |
510 | * i40e_alloc_vsi_res | |
b40c82e6 | 511 | * @vf: pointer to the VF info |
5c3c48ac JB |
512 | * @type: type of VSI to allocate |
513 | * | |
b40c82e6 | 514 | * alloc VF vsi context & resources |
5c3c48ac JB |
515 | **/ |
516 | static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type) | |
517 | { | |
518 | struct i40e_mac_filter *f = NULL; | |
519 | struct i40e_pf *pf = vf->pf; | |
5c3c48ac JB |
520 | struct i40e_vsi *vsi; |
521 | int ret = 0; | |
522 | ||
523 | vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id); | |
524 | ||
525 | if (!vsi) { | |
526 | dev_err(&pf->pdev->dev, | |
b40c82e6 | 527 | "add vsi failed for VF %d, aq_err %d\n", |
5c3c48ac JB |
528 | vf->vf_id, pf->hw.aq.asq_last_status); |
529 | ret = -ENOENT; | |
530 | goto error_alloc_vsi_res; | |
531 | } | |
532 | if (type == I40E_VSI_SRIOV) { | |
1a10370a | 533 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
fdf0e0bf | 534 | vf->lan_vsi_idx = vsi->idx; |
5c3c48ac | 535 | vf->lan_vsi_id = vsi->id; |
6c12fcbf GR |
536 | /* If the port VLAN has been configured and then the |
537 | * VF driver was removed then the VSI port VLAN | |
538 | * configuration was destroyed. Check if there is | |
539 | * a port VLAN and restore the VSI configuration if | |
540 | * needed. | |
541 | */ | |
542 | if (vf->port_vlan_id) | |
543 | i40e_vsi_add_pvid(vsi, vf->port_vlan_id); | |
5c3c48ac | 544 | f = i40e_add_filter(vsi, vf->default_lan_addr.addr, |
6c12fcbf | 545 | vf->port_vlan_id, true, false); |
1a10370a GR |
546 | if (!f) |
547 | dev_info(&pf->pdev->dev, | |
548 | "Could not allocate VF MAC addr\n"); | |
549 | f = i40e_add_filter(vsi, brdcast, vf->port_vlan_id, | |
550 | true, false); | |
551 | if (!f) | |
552 | dev_info(&pf->pdev->dev, | |
553 | "Could not allocate VF broadcast filter\n"); | |
5c3c48ac | 554 | } |
6dbbbfb2 | 555 | |
5c3c48ac JB |
556 | /* program mac filter */ |
557 | ret = i40e_sync_vsi_filters(vsi); | |
fd1646ee | 558 | if (ret) |
5c3c48ac | 559 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); |
5c3c48ac | 560 | |
6b192891 MW |
561 | /* Set VF bandwidth if specified */ |
562 | if (vf->tx_rate) { | |
563 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, | |
564 | vf->tx_rate / 50, 0, NULL); | |
565 | if (ret) | |
566 | dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n", | |
567 | vf->vf_id, ret); | |
568 | } | |
569 | ||
5c3c48ac JB |
570 | error_alloc_vsi_res: |
571 | return ret; | |
572 | } | |
573 | ||
805bd5bd MW |
574 | /** |
575 | * i40e_enable_vf_mappings | |
b40c82e6 | 576 | * @vf: pointer to the VF info |
805bd5bd | 577 | * |
b40c82e6 | 578 | * enable VF mappings |
805bd5bd MW |
579 | **/ |
580 | static void i40e_enable_vf_mappings(struct i40e_vf *vf) | |
581 | { | |
582 | struct i40e_pf *pf = vf->pf; | |
583 | struct i40e_hw *hw = &pf->hw; | |
584 | u32 reg, total_queue_pairs = 0; | |
585 | int j; | |
586 | ||
587 | /* Tell the hardware we're using noncontiguous mapping. HW requires | |
588 | * that VF queues be mapped using this method, even when they are | |
589 | * contiguous in real life | |
590 | */ | |
591 | wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id), | |
592 | I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK); | |
593 | ||
594 | /* enable VF vplan_qtable mappings */ | |
595 | reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK; | |
596 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg); | |
597 | ||
598 | /* map PF queues to VF queues */ | |
fdf0e0bf ASJ |
599 | for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) { |
600 | u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j); | |
805bd5bd MW |
601 | reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK); |
602 | wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg); | |
603 | total_queue_pairs++; | |
604 | } | |
605 | ||
606 | /* map PF queues to VSI */ | |
607 | for (j = 0; j < 7; j++) { | |
fdf0e0bf | 608 | if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) { |
805bd5bd MW |
609 | reg = 0x07FF07FF; /* unused */ |
610 | } else { | |
fdf0e0bf | 611 | u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, |
805bd5bd MW |
612 | j * 2); |
613 | reg = qid; | |
fdf0e0bf | 614 | qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, |
805bd5bd MW |
615 | (j * 2) + 1); |
616 | reg |= qid << 16; | |
617 | } | |
618 | wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg); | |
619 | } | |
620 | ||
621 | i40e_flush(hw); | |
622 | } | |
623 | ||
624 | /** | |
625 | * i40e_disable_vf_mappings | |
b40c82e6 | 626 | * @vf: pointer to the VF info |
805bd5bd | 627 | * |
b40c82e6 | 628 | * disable VF mappings |
805bd5bd MW |
629 | **/ |
630 | static void i40e_disable_vf_mappings(struct i40e_vf *vf) | |
631 | { | |
632 | struct i40e_pf *pf = vf->pf; | |
633 | struct i40e_hw *hw = &pf->hw; | |
634 | int i; | |
635 | ||
636 | /* disable qp mappings */ | |
637 | wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0); | |
638 | for (i = 0; i < I40E_MAX_VSI_QP; i++) | |
639 | wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id), | |
640 | I40E_QUEUE_END_OF_LIST); | |
641 | i40e_flush(hw); | |
642 | } | |
643 | ||
644 | /** | |
645 | * i40e_free_vf_res | |
b40c82e6 | 646 | * @vf: pointer to the VF info |
805bd5bd | 647 | * |
b40c82e6 | 648 | * free VF resources |
805bd5bd MW |
649 | **/ |
650 | static void i40e_free_vf_res(struct i40e_vf *vf) | |
651 | { | |
652 | struct i40e_pf *pf = vf->pf; | |
fc18eaa0 MW |
653 | struct i40e_hw *hw = &pf->hw; |
654 | u32 reg_idx, reg; | |
655 | int i, msix_vf; | |
805bd5bd MW |
656 | |
657 | /* free vsi & disconnect it from the parent uplink */ | |
fdf0e0bf ASJ |
658 | if (vf->lan_vsi_idx) { |
659 | i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]); | |
660 | vf->lan_vsi_idx = 0; | |
805bd5bd MW |
661 | vf->lan_vsi_id = 0; |
662 | } | |
9347eb77 MW |
663 | msix_vf = pf->hw.func_caps.num_msix_vectors_vf; |
664 | ||
fc18eaa0 MW |
665 | /* disable interrupts so the VF starts in a known state */ |
666 | for (i = 0; i < msix_vf; i++) { | |
667 | /* format is same for both registers */ | |
668 | if (0 == i) | |
669 | reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id); | |
670 | else | |
671 | reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) * | |
672 | (vf->vf_id)) | |
673 | + (i - 1)); | |
674 | wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK); | |
675 | i40e_flush(hw); | |
676 | } | |
805bd5bd | 677 | |
fc18eaa0 MW |
678 | /* clear the irq settings */ |
679 | for (i = 0; i < msix_vf; i++) { | |
680 | /* format is same for both registers */ | |
681 | if (0 == i) | |
682 | reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); | |
683 | else | |
684 | reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) * | |
685 | (vf->vf_id)) | |
686 | + (i - 1)); | |
687 | reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK | | |
688 | I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK); | |
689 | wr32(hw, reg_idx, reg); | |
690 | i40e_flush(hw); | |
691 | } | |
805bd5bd MW |
692 | /* reset some of the state varibles keeping |
693 | * track of the resources | |
694 | */ | |
695 | vf->num_queue_pairs = 0; | |
696 | vf->vf_states = 0; | |
697 | } | |
698 | ||
699 | /** | |
700 | * i40e_alloc_vf_res | |
b40c82e6 | 701 | * @vf: pointer to the VF info |
805bd5bd | 702 | * |
b40c82e6 | 703 | * allocate VF resources |
805bd5bd MW |
704 | **/ |
705 | static int i40e_alloc_vf_res(struct i40e_vf *vf) | |
706 | { | |
707 | struct i40e_pf *pf = vf->pf; | |
708 | int total_queue_pairs = 0; | |
709 | int ret; | |
710 | ||
711 | /* allocate hw vsi context & associated resources */ | |
712 | ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV); | |
713 | if (ret) | |
714 | goto error_alloc; | |
fdf0e0bf | 715 | total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; |
805bd5bd MW |
716 | set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); |
717 | ||
718 | /* store the total qps number for the runtime | |
b40c82e6 | 719 | * VF req validation |
805bd5bd MW |
720 | */ |
721 | vf->num_queue_pairs = total_queue_pairs; | |
722 | ||
b40c82e6 | 723 | /* VF is now completely initialized */ |
805bd5bd MW |
724 | set_bit(I40E_VF_STAT_INIT, &vf->vf_states); |
725 | ||
726 | error_alloc: | |
727 | if (ret) | |
728 | i40e_free_vf_res(vf); | |
729 | ||
730 | return ret; | |
731 | } | |
732 | ||
fc18eaa0 MW |
733 | #define VF_DEVICE_STATUS 0xAA |
734 | #define VF_TRANS_PENDING_MASK 0x20 | |
735 | /** | |
736 | * i40e_quiesce_vf_pci | |
b40c82e6 | 737 | * @vf: pointer to the VF structure |
fc18eaa0 MW |
738 | * |
739 | * Wait for VF PCI transactions to be cleared after reset. Returns -EIO | |
740 | * if the transactions never clear. | |
741 | **/ | |
742 | static int i40e_quiesce_vf_pci(struct i40e_vf *vf) | |
743 | { | |
744 | struct i40e_pf *pf = vf->pf; | |
745 | struct i40e_hw *hw = &pf->hw; | |
746 | int vf_abs_id, i; | |
747 | u32 reg; | |
748 | ||
b141d619 | 749 | vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id; |
fc18eaa0 MW |
750 | |
751 | wr32(hw, I40E_PF_PCI_CIAA, | |
752 | VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT)); | |
753 | for (i = 0; i < 100; i++) { | |
754 | reg = rd32(hw, I40E_PF_PCI_CIAD); | |
755 | if ((reg & VF_TRANS_PENDING_MASK) == 0) | |
756 | return 0; | |
757 | udelay(1); | |
758 | } | |
759 | return -EIO; | |
760 | } | |
761 | ||
5c3c48ac JB |
762 | /** |
763 | * i40e_reset_vf | |
b40c82e6 | 764 | * @vf: pointer to the VF structure |
5c3c48ac JB |
765 | * @flr: VFLR was issued or not |
766 | * | |
b40c82e6 | 767 | * reset the VF |
5c3c48ac | 768 | **/ |
fc18eaa0 | 769 | void i40e_reset_vf(struct i40e_vf *vf, bool flr) |
5c3c48ac | 770 | { |
5c3c48ac JB |
771 | struct i40e_pf *pf = vf->pf; |
772 | struct i40e_hw *hw = &pf->hw; | |
5c3c48ac | 773 | bool rsd = false; |
fc18eaa0 MW |
774 | int i; |
775 | u32 reg; | |
5c3c48ac | 776 | |
3ba9bcb4 MW |
777 | if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
778 | return; | |
779 | ||
5c3c48ac | 780 | /* warn the VF */ |
5c3c48ac JB |
781 | clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
782 | ||
fc18eaa0 MW |
783 | /* In the case of a VFLR, the HW has already reset the VF and we |
784 | * just need to clean up, so don't hit the VFRTRIG register. | |
5c3c48ac JB |
785 | */ |
786 | if (!flr) { | |
b40c82e6 | 787 | /* reset VF using VPGEN_VFRTRIG reg */ |
fc18eaa0 MW |
788 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); |
789 | reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK; | |
5c3c48ac JB |
790 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); |
791 | i40e_flush(hw); | |
792 | } | |
793 | ||
fc18eaa0 MW |
794 | if (i40e_quiesce_vf_pci(vf)) |
795 | dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n", | |
796 | vf->vf_id); | |
797 | ||
5c3c48ac JB |
798 | /* poll VPGEN_VFRSTAT reg to make sure |
799 | * that reset is complete | |
800 | */ | |
1750a22f MW |
801 | for (i = 0; i < 10; i++) { |
802 | /* VF reset requires driver to first reset the VF and then | |
803 | * poll the status register to make sure that the reset | |
804 | * completed successfully. Due to internal HW FIFO flushes, | |
805 | * we must wait 10ms before the register will be valid. | |
5c3c48ac | 806 | */ |
1750a22f | 807 | usleep_range(10000, 20000); |
5c3c48ac JB |
808 | reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id)); |
809 | if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) { | |
810 | rsd = true; | |
811 | break; | |
812 | } | |
813 | } | |
814 | ||
57175ac1 ASJ |
815 | if (flr) |
816 | usleep_range(10000, 20000); | |
817 | ||
5c3c48ac | 818 | if (!rsd) |
fc18eaa0 | 819 | dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n", |
5c3c48ac | 820 | vf->vf_id); |
fc18eaa0 | 821 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED); |
5c3c48ac JB |
822 | /* clear the reset bit in the VPGEN_VFRTRIG reg */ |
823 | reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id)); | |
824 | reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK; | |
825 | wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg); | |
fc18eaa0 MW |
826 | |
827 | /* On initial reset, we won't have any queues */ | |
fdf0e0bf | 828 | if (vf->lan_vsi_idx == 0) |
fc18eaa0 MW |
829 | goto complete_reset; |
830 | ||
fdf0e0bf | 831 | i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false); |
fc18eaa0 | 832 | complete_reset: |
b40c82e6 | 833 | /* reallocate VF resources to reset the VSI state */ |
fc18eaa0 | 834 | i40e_free_vf_res(vf); |
fc18eaa0 MW |
835 | i40e_alloc_vf_res(vf); |
836 | i40e_enable_vf_mappings(vf); | |
c17b362b | 837 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); |
fc18eaa0 | 838 | |
5c3c48ac | 839 | /* tell the VF the reset is done */ |
fc18eaa0 | 840 | wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE); |
5c3c48ac | 841 | i40e_flush(hw); |
3ba9bcb4 | 842 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
5c3c48ac | 843 | } |
c354229f | 844 | |
5c3c48ac JB |
845 | /** |
846 | * i40e_free_vfs | |
b40c82e6 | 847 | * @pf: pointer to the PF structure |
5c3c48ac | 848 | * |
b40c82e6 | 849 | * free VF resources |
5c3c48ac JB |
850 | **/ |
851 | void i40e_free_vfs(struct i40e_pf *pf) | |
852 | { | |
f7414531 MW |
853 | struct i40e_hw *hw = &pf->hw; |
854 | u32 reg_idx, bit_idx; | |
855 | int i, tmp, vf_id; | |
5c3c48ac JB |
856 | |
857 | if (!pf->vf) | |
858 | return; | |
3ba9bcb4 MW |
859 | while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state)) |
860 | usleep_range(1000, 2000); | |
5c3c48ac | 861 | |
44434638 MW |
862 | for (i = 0; i < pf->num_alloc_vfs; i++) |
863 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) | |
864 | i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx], | |
865 | false); | |
866 | ||
6a9ddb36 MW |
867 | /* Disable IOV before freeing resources. This lets any VF drivers |
868 | * running in the host get themselves cleaned up before we yank | |
869 | * the carpet out from underneath their feet. | |
870 | */ | |
871 | if (!pci_vfs_assigned(pf->pdev)) | |
872 | pci_disable_sriov(pf->pdev); | |
6d7b967d MW |
873 | else |
874 | dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n"); | |
6a9ddb36 MW |
875 | |
876 | msleep(20); /* let any messages in transit get finished up */ | |
877 | ||
b40c82e6 | 878 | /* free up VF resources */ |
6c1b5bff MW |
879 | tmp = pf->num_alloc_vfs; |
880 | pf->num_alloc_vfs = 0; | |
881 | for (i = 0; i < tmp; i++) { | |
5c3c48ac JB |
882 | if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states)) |
883 | i40e_free_vf_res(&pf->vf[i]); | |
884 | /* disable qp mappings */ | |
885 | i40e_disable_vf_mappings(&pf->vf[i]); | |
886 | } | |
887 | ||
888 | kfree(pf->vf); | |
889 | pf->vf = NULL; | |
5c3c48ac | 890 | |
9e5634df MW |
891 | /* This check is for when the driver is unloaded while VFs are |
892 | * assigned. Setting the number of VFs to 0 through sysfs is caught | |
893 | * before this function ever gets called. | |
894 | */ | |
c24817b6 | 895 | if (!pci_vfs_assigned(pf->pdev)) { |
f7414531 MW |
896 | /* Acknowledge VFLR for all VFS. Without this, VFs will fail to |
897 | * work correctly when SR-IOV gets re-enabled. | |
898 | */ | |
899 | for (vf_id = 0; vf_id < tmp; vf_id++) { | |
900 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; | |
901 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; | |
902 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx)); | |
903 | } | |
c354229f | 904 | } |
3ba9bcb4 | 905 | clear_bit(__I40E_VF_DISABLE, &pf->state); |
5c3c48ac JB |
906 | } |
907 | ||
908 | #ifdef CONFIG_PCI_IOV | |
909 | /** | |
910 | * i40e_alloc_vfs | |
b40c82e6 JK |
911 | * @pf: pointer to the PF structure |
912 | * @num_alloc_vfs: number of VFs to allocate | |
5c3c48ac | 913 | * |
b40c82e6 | 914 | * allocate VF resources |
5c3c48ac | 915 | **/ |
4aeec010 | 916 | int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs) |
5c3c48ac JB |
917 | { |
918 | struct i40e_vf *vfs; | |
919 | int i, ret = 0; | |
920 | ||
6c1b5bff | 921 | /* Disable interrupt 0 so we don't try to handle the VFLR. */ |
2ef28cfb MW |
922 | i40e_irq_dynamic_disable_icr0(pf); |
923 | ||
4aeec010 MW |
924 | /* Check to see if we're just allocating resources for extant VFs */ |
925 | if (pci_num_vf(pf->pdev) != num_alloc_vfs) { | |
926 | ret = pci_enable_sriov(pf->pdev, num_alloc_vfs); | |
927 | if (ret) { | |
928 | dev_err(&pf->pdev->dev, | |
929 | "Failed to enable SR-IOV, error %d.\n", ret); | |
930 | pf->num_alloc_vfs = 0; | |
931 | goto err_iov; | |
932 | } | |
5c3c48ac | 933 | } |
5c3c48ac | 934 | /* allocate memory */ |
cc6456af | 935 | vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL); |
5c3c48ac JB |
936 | if (!vfs) { |
937 | ret = -ENOMEM; | |
938 | goto err_alloc; | |
939 | } | |
c674d125 | 940 | pf->vf = vfs; |
5c3c48ac JB |
941 | |
942 | /* apply default profile */ | |
943 | for (i = 0; i < num_alloc_vfs; i++) { | |
944 | vfs[i].pf = pf; | |
945 | vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB; | |
946 | vfs[i].vf_id = i; | |
947 | ||
948 | /* assign default capabilities */ | |
949 | set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps); | |
c674d125 | 950 | vfs[i].spoofchk = true; |
b40c82e6 | 951 | /* VF resources get allocated during reset */ |
fc18eaa0 | 952 | i40e_reset_vf(&vfs[i], false); |
5c3c48ac | 953 | |
b40c82e6 | 954 | /* enable VF vplan_qtable mappings */ |
5c3c48ac JB |
955 | i40e_enable_vf_mappings(&vfs[i]); |
956 | } | |
5c3c48ac JB |
957 | pf->num_alloc_vfs = num_alloc_vfs; |
958 | ||
959 | err_alloc: | |
960 | if (ret) | |
961 | i40e_free_vfs(pf); | |
962 | err_iov: | |
6c1b5bff | 963 | /* Re-enable interrupt 0. */ |
2ef28cfb | 964 | i40e_irq_dynamic_enable_icr0(pf); |
5c3c48ac JB |
965 | return ret; |
966 | } | |
967 | ||
968 | #endif | |
969 | /** | |
970 | * i40e_pci_sriov_enable | |
971 | * @pdev: pointer to a pci_dev structure | |
b40c82e6 | 972 | * @num_vfs: number of VFs to allocate |
5c3c48ac JB |
973 | * |
974 | * Enable or change the number of VFs | |
975 | **/ | |
976 | static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs) | |
977 | { | |
978 | #ifdef CONFIG_PCI_IOV | |
979 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
980 | int pre_existing_vfs = pci_num_vf(pdev); | |
981 | int err = 0; | |
982 | ||
e17bc411 GR |
983 | if (pf->state & __I40E_TESTING) { |
984 | dev_warn(&pdev->dev, | |
985 | "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n"); | |
986 | err = -EPERM; | |
987 | goto err_out; | |
988 | } | |
989 | ||
5c3c48ac JB |
990 | dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs); |
991 | if (pre_existing_vfs && pre_existing_vfs != num_vfs) | |
992 | i40e_free_vfs(pf); | |
993 | else if (pre_existing_vfs && pre_existing_vfs == num_vfs) | |
994 | goto out; | |
995 | ||
996 | if (num_vfs > pf->num_req_vfs) { | |
997 | err = -EPERM; | |
998 | goto err_out; | |
999 | } | |
1000 | ||
1001 | err = i40e_alloc_vfs(pf, num_vfs); | |
1002 | if (err) { | |
1003 | dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err); | |
1004 | goto err_out; | |
1005 | } | |
1006 | ||
1007 | out: | |
1008 | return num_vfs; | |
1009 | ||
1010 | err_out: | |
1011 | return err; | |
1012 | #endif | |
1013 | return 0; | |
1014 | } | |
1015 | ||
1016 | /** | |
1017 | * i40e_pci_sriov_configure | |
1018 | * @pdev: pointer to a pci_dev structure | |
b40c82e6 | 1019 | * @num_vfs: number of VFs to allocate |
5c3c48ac JB |
1020 | * |
1021 | * Enable or change the number of VFs. Called when the user updates the number | |
1022 | * of VFs in sysfs. | |
1023 | **/ | |
1024 | int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) | |
1025 | { | |
1026 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
1027 | ||
fc60861e ASJ |
1028 | if (num_vfs) { |
1029 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { | |
1030 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; | |
1031 | i40e_do_reset_safe(pf, | |
1032 | BIT_ULL(__I40E_PF_RESET_REQUESTED)); | |
1033 | } | |
5c3c48ac | 1034 | return i40e_pci_sriov_enable(pdev, num_vfs); |
fc60861e | 1035 | } |
5c3c48ac | 1036 | |
c24817b6 | 1037 | if (!pci_vfs_assigned(pf->pdev)) { |
9e5634df | 1038 | i40e_free_vfs(pf); |
fc60861e ASJ |
1039 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
1040 | i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); | |
9e5634df MW |
1041 | } else { |
1042 | dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n"); | |
1043 | return -EINVAL; | |
1044 | } | |
5c3c48ac JB |
1045 | return 0; |
1046 | } | |
1047 | ||
1048 | /***********************virtual channel routines******************/ | |
1049 | ||
1050 | /** | |
1051 | * i40e_vc_send_msg_to_vf | |
b40c82e6 | 1052 | * @vf: pointer to the VF info |
5c3c48ac JB |
1053 | * @v_opcode: virtual channel opcode |
1054 | * @v_retval: virtual channel return value | |
1055 | * @msg: pointer to the msg buffer | |
1056 | * @msglen: msg length | |
1057 | * | |
b40c82e6 | 1058 | * send msg to VF |
5c3c48ac JB |
1059 | **/ |
1060 | static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode, | |
1061 | u32 v_retval, u8 *msg, u16 msglen) | |
1062 | { | |
6e7b5bd3 ASJ |
1063 | struct i40e_pf *pf; |
1064 | struct i40e_hw *hw; | |
1065 | int abs_vf_id; | |
5c3c48ac JB |
1066 | i40e_status aq_ret; |
1067 | ||
6e7b5bd3 ASJ |
1068 | /* validate the request */ |
1069 | if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) | |
1070 | return -EINVAL; | |
1071 | ||
1072 | pf = vf->pf; | |
1073 | hw = &pf->hw; | |
1074 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; | |
1075 | ||
5c3c48ac JB |
1076 | /* single place to detect unsuccessful return values */ |
1077 | if (v_retval) { | |
1078 | vf->num_invalid_msgs++; | |
1079 | dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n", | |
1080 | v_opcode, v_retval); | |
1081 | if (vf->num_invalid_msgs > | |
1082 | I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) { | |
1083 | dev_err(&pf->pdev->dev, | |
1084 | "Number of invalid messages exceeded for VF %d\n", | |
1085 | vf->vf_id); | |
1086 | dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n"); | |
1087 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); | |
1088 | } | |
1089 | } else { | |
1090 | vf->num_valid_msgs++; | |
1091 | } | |
1092 | ||
f19efbb5 | 1093 | aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval, |
7efa84b7 | 1094 | msg, msglen, NULL); |
5c3c48ac JB |
1095 | if (aq_ret) { |
1096 | dev_err(&pf->pdev->dev, | |
1097 | "Unable to send the message to VF %d aq_err %d\n", | |
1098 | vf->vf_id, pf->hw.aq.asq_last_status); | |
1099 | return -EIO; | |
1100 | } | |
1101 | ||
1102 | return 0; | |
1103 | } | |
1104 | ||
1105 | /** | |
1106 | * i40e_vc_send_resp_to_vf | |
b40c82e6 | 1107 | * @vf: pointer to the VF info |
5c3c48ac JB |
1108 | * @opcode: operation code |
1109 | * @retval: return value | |
1110 | * | |
b40c82e6 | 1111 | * send resp msg to VF |
5c3c48ac JB |
1112 | **/ |
1113 | static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf, | |
1114 | enum i40e_virtchnl_ops opcode, | |
1115 | i40e_status retval) | |
1116 | { | |
1117 | return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0); | |
1118 | } | |
1119 | ||
1120 | /** | |
1121 | * i40e_vc_get_version_msg | |
b40c82e6 | 1122 | * @vf: pointer to the VF info |
5c3c48ac | 1123 | * |
b40c82e6 | 1124 | * called from the VF to request the API version used by the PF |
5c3c48ac JB |
1125 | **/ |
1126 | static int i40e_vc_get_version_msg(struct i40e_vf *vf) | |
1127 | { | |
1128 | struct i40e_virtchnl_version_info info = { | |
1129 | I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR | |
1130 | }; | |
1131 | ||
1132 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION, | |
1133 | I40E_SUCCESS, (u8 *)&info, | |
1134 | sizeof(struct | |
1135 | i40e_virtchnl_version_info)); | |
1136 | } | |
1137 | ||
1138 | /** | |
1139 | * i40e_vc_get_vf_resources_msg | |
b40c82e6 | 1140 | * @vf: pointer to the VF info |
5c3c48ac JB |
1141 | * @msg: pointer to the msg buffer |
1142 | * @msglen: msg length | |
1143 | * | |
b40c82e6 | 1144 | * called from the VF to request its resources |
5c3c48ac JB |
1145 | **/ |
1146 | static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf) | |
1147 | { | |
1148 | struct i40e_virtchnl_vf_resource *vfres = NULL; | |
1149 | struct i40e_pf *pf = vf->pf; | |
1150 | i40e_status aq_ret = 0; | |
1151 | struct i40e_vsi *vsi; | |
1152 | int i = 0, len = 0; | |
1153 | int num_vsis = 1; | |
1154 | int ret; | |
1155 | ||
1156 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { | |
1157 | aq_ret = I40E_ERR_PARAM; | |
1158 | goto err; | |
1159 | } | |
1160 | ||
1161 | len = (sizeof(struct i40e_virtchnl_vf_resource) + | |
1162 | sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis); | |
1163 | ||
1164 | vfres = kzalloc(len, GFP_KERNEL); | |
1165 | if (!vfres) { | |
1166 | aq_ret = I40E_ERR_NO_MEMORY; | |
1167 | len = 0; | |
1168 | goto err; | |
1169 | } | |
1170 | ||
1171 | vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2; | |
fdf0e0bf | 1172 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1173 | if (!vsi->info.pvid) |
1174 | vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN; | |
1175 | ||
1176 | vfres->num_vsis = num_vsis; | |
1177 | vfres->num_queue_pairs = vf->num_queue_pairs; | |
1178 | vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf; | |
fdf0e0bf ASJ |
1179 | if (vf->lan_vsi_idx) { |
1180 | vfres->vsi_res[i].vsi_id = vf->lan_vsi_id; | |
5c3c48ac JB |
1181 | vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV; |
1182 | vfres->vsi_res[i].num_queue_pairs = | |
fdf0e0bf | 1183 | pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; |
5c3c48ac JB |
1184 | memcpy(vfres->vsi_res[i].default_mac_addr, |
1185 | vf->default_lan_addr.addr, ETH_ALEN); | |
1186 | i++; | |
1187 | } | |
1188 | set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states); | |
1189 | ||
1190 | err: | |
b40c82e6 | 1191 | /* send the response back to the VF */ |
5c3c48ac JB |
1192 | ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, |
1193 | aq_ret, (u8 *)vfres, len); | |
1194 | ||
1195 | kfree(vfres); | |
1196 | return ret; | |
1197 | } | |
1198 | ||
1199 | /** | |
1200 | * i40e_vc_reset_vf_msg | |
b40c82e6 | 1201 | * @vf: pointer to the VF info |
5c3c48ac JB |
1202 | * @msg: pointer to the msg buffer |
1203 | * @msglen: msg length | |
1204 | * | |
b40c82e6 JK |
1205 | * called from the VF to reset itself, |
1206 | * unlike other virtchnl messages, PF driver | |
1207 | * doesn't send the response back to the VF | |
5c3c48ac | 1208 | **/ |
fc18eaa0 | 1209 | static void i40e_vc_reset_vf_msg(struct i40e_vf *vf) |
5c3c48ac | 1210 | { |
fc18eaa0 MW |
1211 | if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) |
1212 | i40e_reset_vf(vf, false); | |
5c3c48ac JB |
1213 | } |
1214 | ||
1215 | /** | |
1216 | * i40e_vc_config_promiscuous_mode_msg | |
b40c82e6 | 1217 | * @vf: pointer to the VF info |
5c3c48ac JB |
1218 | * @msg: pointer to the msg buffer |
1219 | * @msglen: msg length | |
1220 | * | |
b40c82e6 JK |
1221 | * called from the VF to configure the promiscuous mode of |
1222 | * VF vsis | |
5c3c48ac JB |
1223 | **/ |
1224 | static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf, | |
1225 | u8 *msg, u16 msglen) | |
1226 | { | |
1227 | struct i40e_virtchnl_promisc_info *info = | |
1228 | (struct i40e_virtchnl_promisc_info *)msg; | |
1229 | struct i40e_pf *pf = vf->pf; | |
1230 | struct i40e_hw *hw = &pf->hw; | |
89cb86c3 | 1231 | struct i40e_vsi *vsi; |
5c3c48ac | 1232 | bool allmulti = false; |
5c3c48ac JB |
1233 | i40e_status aq_ret; |
1234 | ||
fdf0e0bf | 1235 | vsi = i40e_find_vsi_from_id(pf, info->vsi_id); |
5c3c48ac JB |
1236 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || |
1237 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || | |
1238 | !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) || | |
fdf0e0bf | 1239 | (vsi->type != I40E_VSI_FCOE)) { |
5c3c48ac JB |
1240 | aq_ret = I40E_ERR_PARAM; |
1241 | goto error_param; | |
1242 | } | |
5c3c48ac JB |
1243 | if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC) |
1244 | allmulti = true; | |
89cb86c3 | 1245 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, |
5c3c48ac JB |
1246 | allmulti, NULL); |
1247 | ||
1248 | error_param: | |
b40c82e6 | 1249 | /* send the response to the VF */ |
5c3c48ac JB |
1250 | return i40e_vc_send_resp_to_vf(vf, |
1251 | I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, | |
1252 | aq_ret); | |
1253 | } | |
1254 | ||
1255 | /** | |
1256 | * i40e_vc_config_queues_msg | |
b40c82e6 | 1257 | * @vf: pointer to the VF info |
5c3c48ac JB |
1258 | * @msg: pointer to the msg buffer |
1259 | * @msglen: msg length | |
1260 | * | |
b40c82e6 | 1261 | * called from the VF to configure the rx/tx |
5c3c48ac JB |
1262 | * queues |
1263 | **/ | |
1264 | static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1265 | { | |
1266 | struct i40e_virtchnl_vsi_queue_config_info *qci = | |
1267 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; | |
1268 | struct i40e_virtchnl_queue_pair_info *qpi; | |
5f5e33b6 | 1269 | struct i40e_pf *pf = vf->pf; |
5c3c48ac JB |
1270 | u16 vsi_id, vsi_queue_id; |
1271 | i40e_status aq_ret = 0; | |
1272 | int i; | |
1273 | ||
1274 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { | |
1275 | aq_ret = I40E_ERR_PARAM; | |
1276 | goto error_param; | |
1277 | } | |
1278 | ||
1279 | vsi_id = qci->vsi_id; | |
1280 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
1281 | aq_ret = I40E_ERR_PARAM; | |
1282 | goto error_param; | |
1283 | } | |
1284 | for (i = 0; i < qci->num_queue_pairs; i++) { | |
1285 | qpi = &qci->qpair[i]; | |
1286 | vsi_queue_id = qpi->txq.queue_id; | |
1287 | if ((qpi->txq.vsi_id != vsi_id) || | |
1288 | (qpi->rxq.vsi_id != vsi_id) || | |
1289 | (qpi->rxq.queue_id != vsi_queue_id) || | |
1290 | !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) { | |
1291 | aq_ret = I40E_ERR_PARAM; | |
1292 | goto error_param; | |
1293 | } | |
1294 | ||
1295 | if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id, | |
1296 | &qpi->rxq) || | |
1297 | i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id, | |
1298 | &qpi->txq)) { | |
1299 | aq_ret = I40E_ERR_PARAM; | |
1300 | goto error_param; | |
1301 | } | |
1302 | } | |
b40c82e6 | 1303 | /* set vsi num_queue_pairs in use to num configured by VF */ |
fdf0e0bf | 1304 | pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs; |
5c3c48ac JB |
1305 | |
1306 | error_param: | |
b40c82e6 | 1307 | /* send the response to the VF */ |
5c3c48ac JB |
1308 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, |
1309 | aq_ret); | |
1310 | } | |
1311 | ||
1312 | /** | |
1313 | * i40e_vc_config_irq_map_msg | |
b40c82e6 | 1314 | * @vf: pointer to the VF info |
5c3c48ac JB |
1315 | * @msg: pointer to the msg buffer |
1316 | * @msglen: msg length | |
1317 | * | |
b40c82e6 | 1318 | * called from the VF to configure the irq to |
5c3c48ac JB |
1319 | * queue map |
1320 | **/ | |
1321 | static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1322 | { | |
1323 | struct i40e_virtchnl_irq_map_info *irqmap_info = | |
1324 | (struct i40e_virtchnl_irq_map_info *)msg; | |
1325 | struct i40e_virtchnl_vector_map *map; | |
1326 | u16 vsi_id, vsi_queue_id, vector_id; | |
1327 | i40e_status aq_ret = 0; | |
1328 | unsigned long tempmap; | |
1329 | int i; | |
1330 | ||
1331 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { | |
1332 | aq_ret = I40E_ERR_PARAM; | |
1333 | goto error_param; | |
1334 | } | |
1335 | ||
1336 | for (i = 0; i < irqmap_info->num_vectors; i++) { | |
1337 | map = &irqmap_info->vecmap[i]; | |
1338 | ||
1339 | vector_id = map->vector_id; | |
1340 | vsi_id = map->vsi_id; | |
1341 | /* validate msg params */ | |
1342 | if (!i40e_vc_isvalid_vector_id(vf, vector_id) || | |
1343 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
1344 | aq_ret = I40E_ERR_PARAM; | |
1345 | goto error_param; | |
1346 | } | |
1347 | ||
1348 | /* lookout for the invalid queue index */ | |
1349 | tempmap = map->rxq_map; | |
4836650b | 1350 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
5c3c48ac JB |
1351 | if (!i40e_vc_isvalid_queue_id(vf, vsi_id, |
1352 | vsi_queue_id)) { | |
1353 | aq_ret = I40E_ERR_PARAM; | |
1354 | goto error_param; | |
1355 | } | |
5c3c48ac JB |
1356 | } |
1357 | ||
1358 | tempmap = map->txq_map; | |
4836650b | 1359 | for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) { |
5c3c48ac JB |
1360 | if (!i40e_vc_isvalid_queue_id(vf, vsi_id, |
1361 | vsi_queue_id)) { | |
1362 | aq_ret = I40E_ERR_PARAM; | |
1363 | goto error_param; | |
1364 | } | |
5c3c48ac JB |
1365 | } |
1366 | ||
1367 | i40e_config_irq_link_list(vf, vsi_id, map); | |
1368 | } | |
1369 | error_param: | |
b40c82e6 | 1370 | /* send the response to the VF */ |
5c3c48ac JB |
1371 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, |
1372 | aq_ret); | |
1373 | } | |
1374 | ||
1375 | /** | |
1376 | * i40e_vc_enable_queues_msg | |
b40c82e6 | 1377 | * @vf: pointer to the VF info |
5c3c48ac JB |
1378 | * @msg: pointer to the msg buffer |
1379 | * @msglen: msg length | |
1380 | * | |
b40c82e6 | 1381 | * called from the VF to enable all or specific queue(s) |
5c3c48ac JB |
1382 | **/ |
1383 | static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1384 | { | |
1385 | struct i40e_virtchnl_queue_select *vqs = | |
1386 | (struct i40e_virtchnl_queue_select *)msg; | |
1387 | struct i40e_pf *pf = vf->pf; | |
1388 | u16 vsi_id = vqs->vsi_id; | |
1389 | i40e_status aq_ret = 0; | |
5c3c48ac JB |
1390 | |
1391 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { | |
1392 | aq_ret = I40E_ERR_PARAM; | |
1393 | goto error_param; | |
1394 | } | |
1395 | ||
1396 | if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
1397 | aq_ret = I40E_ERR_PARAM; | |
1398 | goto error_param; | |
1399 | } | |
1400 | ||
1401 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { | |
1402 | aq_ret = I40E_ERR_PARAM; | |
1403 | goto error_param; | |
1404 | } | |
fdf0e0bf ASJ |
1405 | |
1406 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true)) | |
88f6563d | 1407 | aq_ret = I40E_ERR_TIMEOUT; |
5c3c48ac | 1408 | error_param: |
b40c82e6 | 1409 | /* send the response to the VF */ |
5c3c48ac JB |
1410 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, |
1411 | aq_ret); | |
1412 | } | |
1413 | ||
1414 | /** | |
1415 | * i40e_vc_disable_queues_msg | |
b40c82e6 | 1416 | * @vf: pointer to the VF info |
5c3c48ac JB |
1417 | * @msg: pointer to the msg buffer |
1418 | * @msglen: msg length | |
1419 | * | |
b40c82e6 | 1420 | * called from the VF to disable all or specific |
5c3c48ac JB |
1421 | * queue(s) |
1422 | **/ | |
1423 | static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1424 | { | |
1425 | struct i40e_virtchnl_queue_select *vqs = | |
1426 | (struct i40e_virtchnl_queue_select *)msg; | |
1427 | struct i40e_pf *pf = vf->pf; | |
5c3c48ac | 1428 | i40e_status aq_ret = 0; |
5c3c48ac JB |
1429 | |
1430 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { | |
1431 | aq_ret = I40E_ERR_PARAM; | |
1432 | goto error_param; | |
1433 | } | |
1434 | ||
1435 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { | |
1436 | aq_ret = I40E_ERR_PARAM; | |
1437 | goto error_param; | |
1438 | } | |
1439 | ||
1440 | if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) { | |
1441 | aq_ret = I40E_ERR_PARAM; | |
1442 | goto error_param; | |
1443 | } | |
fdf0e0bf ASJ |
1444 | |
1445 | if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false)) | |
88f6563d | 1446 | aq_ret = I40E_ERR_TIMEOUT; |
5c3c48ac JB |
1447 | |
1448 | error_param: | |
b40c82e6 | 1449 | /* send the response to the VF */ |
5c3c48ac JB |
1450 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, |
1451 | aq_ret); | |
1452 | } | |
1453 | ||
1454 | /** | |
1455 | * i40e_vc_get_stats_msg | |
b40c82e6 | 1456 | * @vf: pointer to the VF info |
5c3c48ac JB |
1457 | * @msg: pointer to the msg buffer |
1458 | * @msglen: msg length | |
1459 | * | |
b40c82e6 | 1460 | * called from the VF to get vsi stats |
5c3c48ac JB |
1461 | **/ |
1462 | static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1463 | { | |
1464 | struct i40e_virtchnl_queue_select *vqs = | |
1465 | (struct i40e_virtchnl_queue_select *)msg; | |
1466 | struct i40e_pf *pf = vf->pf; | |
1467 | struct i40e_eth_stats stats; | |
1468 | i40e_status aq_ret = 0; | |
1469 | struct i40e_vsi *vsi; | |
1470 | ||
1471 | memset(&stats, 0, sizeof(struct i40e_eth_stats)); | |
1472 | ||
1473 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) { | |
1474 | aq_ret = I40E_ERR_PARAM; | |
1475 | goto error_param; | |
1476 | } | |
1477 | ||
1478 | if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) { | |
1479 | aq_ret = I40E_ERR_PARAM; | |
1480 | goto error_param; | |
1481 | } | |
1482 | ||
fdf0e0bf | 1483 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1484 | if (!vsi) { |
1485 | aq_ret = I40E_ERR_PARAM; | |
1486 | goto error_param; | |
1487 | } | |
1488 | i40e_update_eth_stats(vsi); | |
5a9769c8 | 1489 | stats = vsi->eth_stats; |
5c3c48ac JB |
1490 | |
1491 | error_param: | |
b40c82e6 | 1492 | /* send the response back to the VF */ |
5c3c48ac JB |
1493 | return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret, |
1494 | (u8 *)&stats, sizeof(stats)); | |
1495 | } | |
1496 | ||
f657a6e1 GR |
1497 | /** |
1498 | * i40e_check_vf_permission | |
b40c82e6 | 1499 | * @vf: pointer to the VF info |
f657a6e1 GR |
1500 | * @macaddr: pointer to the MAC Address being checked |
1501 | * | |
1502 | * Check if the VF has permission to add or delete unicast MAC address | |
1503 | * filters and return error code -EPERM if not. Then check if the | |
1504 | * address filter requested is broadcast or zero and if so return | |
1505 | * an invalid MAC address error code. | |
1506 | **/ | |
1507 | static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr) | |
1508 | { | |
1509 | struct i40e_pf *pf = vf->pf; | |
1510 | int ret = 0; | |
1511 | ||
1512 | if (is_broadcast_ether_addr(macaddr) || | |
1513 | is_zero_ether_addr(macaddr)) { | |
1514 | dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr); | |
1515 | ret = I40E_ERR_INVALID_MAC_ADDR; | |
5017c2a8 GR |
1516 | } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) && |
1517 | !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) { | |
f657a6e1 GR |
1518 | /* If the host VMM administrator has set the VF MAC address |
1519 | * administratively via the ndo_set_vf_mac command then deny | |
1520 | * permission to the VF to add or delete unicast MAC addresses. | |
5017c2a8 GR |
1521 | * The VF may request to set the MAC address filter already |
1522 | * assigned to it so do not return an error in that case. | |
f657a6e1 GR |
1523 | */ |
1524 | dev_err(&pf->pdev->dev, | |
1525 | "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n"); | |
1526 | ret = -EPERM; | |
1527 | } | |
1528 | return ret; | |
1529 | } | |
1530 | ||
5c3c48ac JB |
1531 | /** |
1532 | * i40e_vc_add_mac_addr_msg | |
b40c82e6 | 1533 | * @vf: pointer to the VF info |
5c3c48ac JB |
1534 | * @msg: pointer to the msg buffer |
1535 | * @msglen: msg length | |
1536 | * | |
1537 | * add guest mac address filter | |
1538 | **/ | |
1539 | static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1540 | { | |
1541 | struct i40e_virtchnl_ether_addr_list *al = | |
1542 | (struct i40e_virtchnl_ether_addr_list *)msg; | |
1543 | struct i40e_pf *pf = vf->pf; | |
1544 | struct i40e_vsi *vsi = NULL; | |
1545 | u16 vsi_id = al->vsi_id; | |
f657a6e1 | 1546 | i40e_status ret = 0; |
5c3c48ac JB |
1547 | int i; |
1548 | ||
1549 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || | |
1550 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || | |
1551 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
f657a6e1 | 1552 | ret = I40E_ERR_PARAM; |
5c3c48ac JB |
1553 | goto error_param; |
1554 | } | |
1555 | ||
1556 | for (i = 0; i < al->num_elements; i++) { | |
f657a6e1 GR |
1557 | ret = i40e_check_vf_permission(vf, al->list[i].addr); |
1558 | if (ret) | |
5c3c48ac | 1559 | goto error_param; |
5c3c48ac | 1560 | } |
fdf0e0bf | 1561 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1562 | |
1563 | /* add new addresses to the list */ | |
1564 | for (i = 0; i < al->num_elements; i++) { | |
1565 | struct i40e_mac_filter *f; | |
1566 | ||
1567 | f = i40e_find_mac(vsi, al->list[i].addr, true, false); | |
7e68edf9 | 1568 | if (!f) { |
5c3c48ac JB |
1569 | if (i40e_is_vsi_in_vlan(vsi)) |
1570 | f = i40e_put_mac_in_vlan(vsi, al->list[i].addr, | |
1571 | true, false); | |
1572 | else | |
1573 | f = i40e_add_filter(vsi, al->list[i].addr, -1, | |
1574 | true, false); | |
1575 | } | |
1576 | ||
1577 | if (!f) { | |
1578 | dev_err(&pf->pdev->dev, | |
1579 | "Unable to add VF MAC filter\n"); | |
f657a6e1 | 1580 | ret = I40E_ERR_PARAM; |
5c3c48ac JB |
1581 | goto error_param; |
1582 | } | |
1583 | } | |
1584 | ||
1585 | /* program the updated filter list */ | |
1586 | if (i40e_sync_vsi_filters(vsi)) | |
1587 | dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n"); | |
1588 | ||
1589 | error_param: | |
b40c82e6 | 1590 | /* send the response to the VF */ |
5c3c48ac | 1591 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, |
f657a6e1 | 1592 | ret); |
5c3c48ac JB |
1593 | } |
1594 | ||
1595 | /** | |
1596 | * i40e_vc_del_mac_addr_msg | |
b40c82e6 | 1597 | * @vf: pointer to the VF info |
5c3c48ac JB |
1598 | * @msg: pointer to the msg buffer |
1599 | * @msglen: msg length | |
1600 | * | |
1601 | * remove guest mac address filter | |
1602 | **/ | |
1603 | static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1604 | { | |
1605 | struct i40e_virtchnl_ether_addr_list *al = | |
1606 | (struct i40e_virtchnl_ether_addr_list *)msg; | |
1607 | struct i40e_pf *pf = vf->pf; | |
1608 | struct i40e_vsi *vsi = NULL; | |
1609 | u16 vsi_id = al->vsi_id; | |
f657a6e1 | 1610 | i40e_status ret = 0; |
5c3c48ac JB |
1611 | int i; |
1612 | ||
1613 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || | |
1614 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || | |
1615 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
f657a6e1 | 1616 | ret = I40E_ERR_PARAM; |
5c3c48ac JB |
1617 | goto error_param; |
1618 | } | |
f657a6e1 GR |
1619 | |
1620 | for (i = 0; i < al->num_elements; i++) { | |
700bbf6c MW |
1621 | if (is_broadcast_ether_addr(al->list[i].addr) || |
1622 | is_zero_ether_addr(al->list[i].addr)) { | |
1623 | dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", | |
1624 | al->list[i].addr); | |
1625 | ret = I40E_ERR_INVALID_MAC_ADDR; | |
f657a6e1 | 1626 | goto error_param; |
700bbf6c | 1627 | } |
f657a6e1 | 1628 | } |
fdf0e0bf | 1629 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1630 | |
1631 | /* delete addresses from the list */ | |
1632 | for (i = 0; i < al->num_elements; i++) | |
1633 | i40e_del_filter(vsi, al->list[i].addr, | |
1634 | I40E_VLAN_ANY, true, false); | |
1635 | ||
1636 | /* program the updated filter list */ | |
1637 | if (i40e_sync_vsi_filters(vsi)) | |
1638 | dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n"); | |
1639 | ||
1640 | error_param: | |
b40c82e6 | 1641 | /* send the response to the VF */ |
5c3c48ac | 1642 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS, |
f657a6e1 | 1643 | ret); |
5c3c48ac JB |
1644 | } |
1645 | ||
1646 | /** | |
1647 | * i40e_vc_add_vlan_msg | |
b40c82e6 | 1648 | * @vf: pointer to the VF info |
5c3c48ac JB |
1649 | * @msg: pointer to the msg buffer |
1650 | * @msglen: msg length | |
1651 | * | |
1652 | * program guest vlan id | |
1653 | **/ | |
1654 | static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1655 | { | |
1656 | struct i40e_virtchnl_vlan_filter_list *vfl = | |
1657 | (struct i40e_virtchnl_vlan_filter_list *)msg; | |
1658 | struct i40e_pf *pf = vf->pf; | |
1659 | struct i40e_vsi *vsi = NULL; | |
1660 | u16 vsi_id = vfl->vsi_id; | |
1661 | i40e_status aq_ret = 0; | |
1662 | int i; | |
1663 | ||
1664 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || | |
1665 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || | |
1666 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
1667 | aq_ret = I40E_ERR_PARAM; | |
1668 | goto error_param; | |
1669 | } | |
1670 | ||
1671 | for (i = 0; i < vfl->num_elements; i++) { | |
1672 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { | |
1673 | aq_ret = I40E_ERR_PARAM; | |
1674 | dev_err(&pf->pdev->dev, | |
1675 | "invalid VF VLAN id %d\n", vfl->vlan_id[i]); | |
1676 | goto error_param; | |
1677 | } | |
1678 | } | |
fdf0e0bf | 1679 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1680 | if (vsi->info.pvid) { |
1681 | aq_ret = I40E_ERR_PARAM; | |
1682 | goto error_param; | |
1683 | } | |
1684 | ||
1685 | i40e_vlan_stripping_enable(vsi); | |
1686 | for (i = 0; i < vfl->num_elements; i++) { | |
1687 | /* add new VLAN filter */ | |
1688 | int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]); | |
1689 | if (ret) | |
1690 | dev_err(&pf->pdev->dev, | |
1691 | "Unable to add VF vlan filter %d, error %d\n", | |
1692 | vfl->vlan_id[i], ret); | |
1693 | } | |
1694 | ||
1695 | error_param: | |
b40c82e6 | 1696 | /* send the response to the VF */ |
5c3c48ac JB |
1697 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret); |
1698 | } | |
1699 | ||
1700 | /** | |
1701 | * i40e_vc_remove_vlan_msg | |
b40c82e6 | 1702 | * @vf: pointer to the VF info |
5c3c48ac JB |
1703 | * @msg: pointer to the msg buffer |
1704 | * @msglen: msg length | |
1705 | * | |
1706 | * remove programmed guest vlan id | |
1707 | **/ | |
1708 | static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen) | |
1709 | { | |
1710 | struct i40e_virtchnl_vlan_filter_list *vfl = | |
1711 | (struct i40e_virtchnl_vlan_filter_list *)msg; | |
1712 | struct i40e_pf *pf = vf->pf; | |
1713 | struct i40e_vsi *vsi = NULL; | |
1714 | u16 vsi_id = vfl->vsi_id; | |
1715 | i40e_status aq_ret = 0; | |
1716 | int i; | |
1717 | ||
1718 | if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) || | |
1719 | !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) || | |
1720 | !i40e_vc_isvalid_vsi_id(vf, vsi_id)) { | |
1721 | aq_ret = I40E_ERR_PARAM; | |
1722 | goto error_param; | |
1723 | } | |
1724 | ||
1725 | for (i = 0; i < vfl->num_elements; i++) { | |
1726 | if (vfl->vlan_id[i] > I40E_MAX_VLANID) { | |
1727 | aq_ret = I40E_ERR_PARAM; | |
1728 | goto error_param; | |
1729 | } | |
1730 | } | |
1731 | ||
fdf0e0bf | 1732 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
1733 | if (vsi->info.pvid) { |
1734 | aq_ret = I40E_ERR_PARAM; | |
1735 | goto error_param; | |
1736 | } | |
1737 | ||
1738 | for (i = 0; i < vfl->num_elements; i++) { | |
1739 | int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]); | |
1740 | if (ret) | |
1741 | dev_err(&pf->pdev->dev, | |
1742 | "Unable to delete VF vlan filter %d, error %d\n", | |
1743 | vfl->vlan_id[i], ret); | |
1744 | } | |
1745 | ||
1746 | error_param: | |
b40c82e6 | 1747 | /* send the response to the VF */ |
5c3c48ac JB |
1748 | return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret); |
1749 | } | |
1750 | ||
5c3c48ac JB |
1751 | /** |
1752 | * i40e_vc_validate_vf_msg | |
b40c82e6 | 1753 | * @vf: pointer to the VF info |
5c3c48ac JB |
1754 | * @msg: pointer to the msg buffer |
1755 | * @msglen: msg length | |
1756 | * @msghndl: msg handle | |
1757 | * | |
1758 | * validate msg | |
1759 | **/ | |
1760 | static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode, | |
1761 | u32 v_retval, u8 *msg, u16 msglen) | |
1762 | { | |
1763 | bool err_msg_format = false; | |
1764 | int valid_len; | |
1765 | ||
1766 | /* Check if VF is disabled. */ | |
1767 | if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states)) | |
1768 | return I40E_ERR_PARAM; | |
1769 | ||
1770 | /* Validate message length. */ | |
1771 | switch (v_opcode) { | |
1772 | case I40E_VIRTCHNL_OP_VERSION: | |
1773 | valid_len = sizeof(struct i40e_virtchnl_version_info); | |
1774 | break; | |
1775 | case I40E_VIRTCHNL_OP_RESET_VF: | |
1776 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: | |
1777 | valid_len = 0; | |
1778 | break; | |
1779 | case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE: | |
1780 | valid_len = sizeof(struct i40e_virtchnl_txq_info); | |
1781 | break; | |
1782 | case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE: | |
1783 | valid_len = sizeof(struct i40e_virtchnl_rxq_info); | |
1784 | break; | |
1785 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: | |
1786 | valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info); | |
1787 | if (msglen >= valid_len) { | |
1788 | struct i40e_virtchnl_vsi_queue_config_info *vqc = | |
1789 | (struct i40e_virtchnl_vsi_queue_config_info *)msg; | |
1790 | valid_len += (vqc->num_queue_pairs * | |
1791 | sizeof(struct | |
1792 | i40e_virtchnl_queue_pair_info)); | |
1793 | if (vqc->num_queue_pairs == 0) | |
1794 | err_msg_format = true; | |
1795 | } | |
1796 | break; | |
1797 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: | |
1798 | valid_len = sizeof(struct i40e_virtchnl_irq_map_info); | |
1799 | if (msglen >= valid_len) { | |
1800 | struct i40e_virtchnl_irq_map_info *vimi = | |
1801 | (struct i40e_virtchnl_irq_map_info *)msg; | |
1802 | valid_len += (vimi->num_vectors * | |
1803 | sizeof(struct i40e_virtchnl_vector_map)); | |
1804 | if (vimi->num_vectors == 0) | |
1805 | err_msg_format = true; | |
1806 | } | |
1807 | break; | |
1808 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: | |
1809 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: | |
1810 | valid_len = sizeof(struct i40e_virtchnl_queue_select); | |
1811 | break; | |
1812 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: | |
1813 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: | |
1814 | valid_len = sizeof(struct i40e_virtchnl_ether_addr_list); | |
1815 | if (msglen >= valid_len) { | |
1816 | struct i40e_virtchnl_ether_addr_list *veal = | |
1817 | (struct i40e_virtchnl_ether_addr_list *)msg; | |
1818 | valid_len += veal->num_elements * | |
1819 | sizeof(struct i40e_virtchnl_ether_addr); | |
1820 | if (veal->num_elements == 0) | |
1821 | err_msg_format = true; | |
1822 | } | |
1823 | break; | |
1824 | case I40E_VIRTCHNL_OP_ADD_VLAN: | |
1825 | case I40E_VIRTCHNL_OP_DEL_VLAN: | |
1826 | valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list); | |
1827 | if (msglen >= valid_len) { | |
1828 | struct i40e_virtchnl_vlan_filter_list *vfl = | |
1829 | (struct i40e_virtchnl_vlan_filter_list *)msg; | |
1830 | valid_len += vfl->num_elements * sizeof(u16); | |
1831 | if (vfl->num_elements == 0) | |
1832 | err_msg_format = true; | |
1833 | } | |
1834 | break; | |
1835 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: | |
1836 | valid_len = sizeof(struct i40e_virtchnl_promisc_info); | |
1837 | break; | |
1838 | case I40E_VIRTCHNL_OP_GET_STATS: | |
1839 | valid_len = sizeof(struct i40e_virtchnl_queue_select); | |
1840 | break; | |
1841 | /* These are always errors coming from the VF. */ | |
1842 | case I40E_VIRTCHNL_OP_EVENT: | |
1843 | case I40E_VIRTCHNL_OP_UNKNOWN: | |
1844 | default: | |
1845 | return -EPERM; | |
1846 | break; | |
1847 | } | |
1848 | /* few more checks */ | |
1849 | if ((valid_len != msglen) || (err_msg_format)) { | |
1850 | i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM); | |
1851 | return -EINVAL; | |
1852 | } else { | |
1853 | return 0; | |
1854 | } | |
1855 | } | |
1856 | ||
1857 | /** | |
1858 | * i40e_vc_process_vf_msg | |
b40c82e6 JK |
1859 | * @pf: pointer to the PF structure |
1860 | * @vf_id: source VF id | |
5c3c48ac JB |
1861 | * @msg: pointer to the msg buffer |
1862 | * @msglen: msg length | |
1863 | * @msghndl: msg handle | |
1864 | * | |
1865 | * called from the common aeq/arq handler to | |
b40c82e6 | 1866 | * process request from VF |
5c3c48ac JB |
1867 | **/ |
1868 | int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode, | |
1869 | u32 v_retval, u8 *msg, u16 msglen) | |
1870 | { | |
5c3c48ac | 1871 | struct i40e_hw *hw = &pf->hw; |
c243e963 | 1872 | unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id; |
6c1b5bff | 1873 | struct i40e_vf *vf; |
5c3c48ac JB |
1874 | int ret; |
1875 | ||
1876 | pf->vf_aq_requests++; | |
7efa84b7 | 1877 | if (local_vf_id >= pf->num_alloc_vfs) |
6c1b5bff | 1878 | return -EINVAL; |
7efa84b7 | 1879 | vf = &(pf->vf[local_vf_id]); |
5c3c48ac JB |
1880 | /* perform basic checks on the msg */ |
1881 | ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen); | |
1882 | ||
1883 | if (ret) { | |
b40c82e6 | 1884 | dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n", |
7efa84b7 | 1885 | local_vf_id, v_opcode, msglen); |
5c3c48ac JB |
1886 | return ret; |
1887 | } | |
bae3cae4 | 1888 | |
5c3c48ac JB |
1889 | switch (v_opcode) { |
1890 | case I40E_VIRTCHNL_OP_VERSION: | |
1891 | ret = i40e_vc_get_version_msg(vf); | |
1892 | break; | |
1893 | case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: | |
1894 | ret = i40e_vc_get_vf_resources_msg(vf); | |
1895 | break; | |
1896 | case I40E_VIRTCHNL_OP_RESET_VF: | |
fc18eaa0 MW |
1897 | i40e_vc_reset_vf_msg(vf); |
1898 | ret = 0; | |
5c3c48ac JB |
1899 | break; |
1900 | case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: | |
1901 | ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen); | |
1902 | break; | |
1903 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: | |
1904 | ret = i40e_vc_config_queues_msg(vf, msg, msglen); | |
1905 | break; | |
1906 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: | |
1907 | ret = i40e_vc_config_irq_map_msg(vf, msg, msglen); | |
1908 | break; | |
1909 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: | |
1910 | ret = i40e_vc_enable_queues_msg(vf, msg, msglen); | |
055b295d | 1911 | i40e_vc_notify_vf_link_state(vf); |
5c3c48ac JB |
1912 | break; |
1913 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: | |
1914 | ret = i40e_vc_disable_queues_msg(vf, msg, msglen); | |
1915 | break; | |
1916 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: | |
1917 | ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen); | |
1918 | break; | |
1919 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: | |
1920 | ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen); | |
1921 | break; | |
1922 | case I40E_VIRTCHNL_OP_ADD_VLAN: | |
1923 | ret = i40e_vc_add_vlan_msg(vf, msg, msglen); | |
1924 | break; | |
1925 | case I40E_VIRTCHNL_OP_DEL_VLAN: | |
1926 | ret = i40e_vc_remove_vlan_msg(vf, msg, msglen); | |
1927 | break; | |
1928 | case I40E_VIRTCHNL_OP_GET_STATS: | |
1929 | ret = i40e_vc_get_stats_msg(vf, msg, msglen); | |
1930 | break; | |
5c3c48ac JB |
1931 | case I40E_VIRTCHNL_OP_UNKNOWN: |
1932 | default: | |
b40c82e6 | 1933 | dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n", |
7efa84b7 | 1934 | v_opcode, local_vf_id); |
5c3c48ac JB |
1935 | ret = i40e_vc_send_resp_to_vf(vf, v_opcode, |
1936 | I40E_ERR_NOT_IMPLEMENTED); | |
1937 | break; | |
1938 | } | |
1939 | ||
1940 | return ret; | |
1941 | } | |
1942 | ||
1943 | /** | |
1944 | * i40e_vc_process_vflr_event | |
b40c82e6 | 1945 | * @pf: pointer to the PF structure |
5c3c48ac JB |
1946 | * |
1947 | * called from the vlfr irq handler to | |
b40c82e6 | 1948 | * free up VF resources and state variables |
5c3c48ac JB |
1949 | **/ |
1950 | int i40e_vc_process_vflr_event(struct i40e_pf *pf) | |
1951 | { | |
1952 | u32 reg, reg_idx, bit_idx, vf_id; | |
1953 | struct i40e_hw *hw = &pf->hw; | |
1954 | struct i40e_vf *vf; | |
1955 | ||
1956 | if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) | |
1957 | return 0; | |
1958 | ||
c5c2f7c3 MW |
1959 | /* re-enable vflr interrupt cause */ |
1960 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); | |
1961 | reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK; | |
1962 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); | |
1963 | i40e_flush(hw); | |
1964 | ||
5c3c48ac JB |
1965 | clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
1966 | for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) { | |
1967 | reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32; | |
1968 | bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; | |
b40c82e6 | 1969 | /* read GLGEN_VFLRSTAT register to find out the flr VFs */ |
5c3c48ac JB |
1970 | vf = &pf->vf[vf_id]; |
1971 | reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx)); | |
1972 | if (reg & (1 << bit_idx)) { | |
1973 | /* clear the bit in GLGEN_VFLRSTAT */ | |
1974 | wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx)); | |
1975 | ||
eb2d80bc MW |
1976 | if (!test_bit(__I40E_DOWN, &pf->state)) |
1977 | i40e_reset_vf(vf, true); | |
5c3c48ac JB |
1978 | } |
1979 | } | |
1980 | ||
5c3c48ac JB |
1981 | return 0; |
1982 | } | |
1983 | ||
5c3c48ac JB |
1984 | /** |
1985 | * i40e_ndo_set_vf_mac | |
1986 | * @netdev: network interface device structure | |
b40c82e6 | 1987 | * @vf_id: VF identifier |
5c3c48ac JB |
1988 | * @mac: mac address |
1989 | * | |
b40c82e6 | 1990 | * program VF mac address |
5c3c48ac JB |
1991 | **/ |
1992 | int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) | |
1993 | { | |
1994 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1995 | struct i40e_vsi *vsi = np->vsi; | |
1996 | struct i40e_pf *pf = vsi->back; | |
1997 | struct i40e_mac_filter *f; | |
1998 | struct i40e_vf *vf; | |
1999 | int ret = 0; | |
2000 | ||
2001 | /* validate the request */ | |
2002 | if (vf_id >= pf->num_alloc_vfs) { | |
2003 | dev_err(&pf->pdev->dev, | |
2004 | "Invalid VF Identifier %d\n", vf_id); | |
2005 | ret = -EINVAL; | |
2006 | goto error_param; | |
2007 | } | |
2008 | ||
2009 | vf = &(pf->vf[vf_id]); | |
fdf0e0bf | 2010 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
2011 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
2012 | dev_err(&pf->pdev->dev, | |
2013 | "Uninitialized VF %d\n", vf_id); | |
2014 | ret = -EINVAL; | |
2015 | goto error_param; | |
2016 | } | |
2017 | ||
2018 | if (!is_valid_ether_addr(mac)) { | |
2019 | dev_err(&pf->pdev->dev, | |
2020 | "Invalid VF ethernet address\n"); | |
2021 | ret = -EINVAL; | |
2022 | goto error_param; | |
2023 | } | |
2024 | ||
2025 | /* delete the temporary mac address */ | |
37cc0d2f GR |
2026 | i40e_del_filter(vsi, vf->default_lan_addr.addr, vf->port_vlan_id, |
2027 | true, false); | |
5c3c48ac | 2028 | |
29f71bb0 GR |
2029 | /* Delete all the filters for this VSI - we're going to kill it |
2030 | * anyway. | |
2031 | */ | |
2032 | list_for_each_entry(f, &vsi->mac_filter_list, list) | |
2033 | i40e_del_filter(vsi, f->macaddr, f->vlan, true, false); | |
5c3c48ac JB |
2034 | |
2035 | dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id); | |
2036 | /* program mac filter */ | |
2037 | if (i40e_sync_vsi_filters(vsi)) { | |
2038 | dev_err(&pf->pdev->dev, "Unable to program ucast filters\n"); | |
2039 | ret = -EIO; | |
2040 | goto error_param; | |
2041 | } | |
9a173901 | 2042 | ether_addr_copy(vf->default_lan_addr.addr, mac); |
f657a6e1 | 2043 | vf->pf_set_mac = true; |
17413a80 GR |
2044 | /* Force the VF driver stop so it has to reload with new MAC address */ |
2045 | i40e_vc_disable_vf(pf, vf); | |
5c3c48ac | 2046 | dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n"); |
5c3c48ac JB |
2047 | |
2048 | error_param: | |
2049 | return ret; | |
2050 | } | |
2051 | ||
2052 | /** | |
2053 | * i40e_ndo_set_vf_port_vlan | |
2054 | * @netdev: network interface device structure | |
b40c82e6 | 2055 | * @vf_id: VF identifier |
5c3c48ac JB |
2056 | * @vlan_id: mac address |
2057 | * @qos: priority setting | |
2058 | * | |
b40c82e6 | 2059 | * program VF vlan id and/or qos |
5c3c48ac JB |
2060 | **/ |
2061 | int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, | |
2062 | int vf_id, u16 vlan_id, u8 qos) | |
2063 | { | |
2064 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2065 | struct i40e_pf *pf = np->vsi->back; | |
2066 | struct i40e_vsi *vsi; | |
2067 | struct i40e_vf *vf; | |
2068 | int ret = 0; | |
2069 | ||
2070 | /* validate the request */ | |
2071 | if (vf_id >= pf->num_alloc_vfs) { | |
2072 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); | |
2073 | ret = -EINVAL; | |
2074 | goto error_pvid; | |
2075 | } | |
2076 | ||
2077 | if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) { | |
2078 | dev_err(&pf->pdev->dev, "Invalid VF Parameters\n"); | |
2079 | ret = -EINVAL; | |
2080 | goto error_pvid; | |
2081 | } | |
2082 | ||
2083 | vf = &(pf->vf[vf_id]); | |
fdf0e0bf | 2084 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
2085 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
2086 | dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id); | |
2087 | ret = -EINVAL; | |
2088 | goto error_pvid; | |
2089 | } | |
2090 | ||
85927ec1 MW |
2091 | if (vsi->info.pvid == (vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT))) |
2092 | /* duplicate request, so just return success */ | |
2093 | goto error_pvid; | |
2094 | ||
f9b4b627 | 2095 | if (vsi->info.pvid == 0 && i40e_is_vsi_in_vlan(vsi)) { |
99a4973c GR |
2096 | dev_err(&pf->pdev->dev, |
2097 | "VF %d has already configured VLAN filters and the administrator is requesting a port VLAN override.\nPlease unload and reload the VF driver for this change to take effect.\n", | |
2098 | vf_id); | |
f9b4b627 GR |
2099 | /* Administrator Error - knock the VF offline until he does |
2100 | * the right thing by reconfiguring his network correctly | |
2101 | * and then reloading the VF driver. | |
2102 | */ | |
2103 | i40e_vc_disable_vf(pf, vf); | |
2104 | } | |
99a4973c | 2105 | |
8d82a7c5 GR |
2106 | /* Check for condition where there was already a port VLAN ID |
2107 | * filter set and now it is being deleted by setting it to zero. | |
1315f7c3 GR |
2108 | * Additionally check for the condition where there was a port |
2109 | * VLAN but now there is a new and different port VLAN being set. | |
8d82a7c5 GR |
2110 | * Before deleting all the old VLAN filters we must add new ones |
2111 | * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our | |
2112 | * MAC addresses deleted. | |
2113 | */ | |
1315f7c3 GR |
2114 | if ((!(vlan_id || qos) || |
2115 | (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) && | |
2116 | vsi->info.pvid) | |
8d82a7c5 GR |
2117 | ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY); |
2118 | ||
5c3c48ac JB |
2119 | if (vsi->info.pvid) { |
2120 | /* kill old VLAN */ | |
2121 | ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) & | |
2122 | VLAN_VID_MASK)); | |
2123 | if (ret) { | |
2124 | dev_info(&vsi->back->pdev->dev, | |
2125 | "remove VLAN failed, ret=%d, aq_err=%d\n", | |
2126 | ret, pf->hw.aq.asq_last_status); | |
2127 | } | |
2128 | } | |
2129 | if (vlan_id || qos) | |
2130 | ret = i40e_vsi_add_pvid(vsi, | |
2131 | vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT)); | |
2132 | else | |
6c12fcbf | 2133 | i40e_vsi_remove_pvid(vsi); |
5c3c48ac JB |
2134 | |
2135 | if (vlan_id) { | |
2136 | dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n", | |
2137 | vlan_id, qos, vf_id); | |
2138 | ||
2139 | /* add new VLAN filter */ | |
2140 | ret = i40e_vsi_add_vlan(vsi, vlan_id); | |
2141 | if (ret) { | |
2142 | dev_info(&vsi->back->pdev->dev, | |
2143 | "add VF VLAN failed, ret=%d aq_err=%d\n", ret, | |
2144 | vsi->back->hw.aq.asq_last_status); | |
2145 | goto error_pvid; | |
2146 | } | |
8d82a7c5 GR |
2147 | /* Kill non-vlan MAC filters - ignore error return since |
2148 | * there might not be any non-vlan MAC filters. | |
2149 | */ | |
2150 | i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY); | |
5c3c48ac JB |
2151 | } |
2152 | ||
2153 | if (ret) { | |
2154 | dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n"); | |
2155 | goto error_pvid; | |
2156 | } | |
6c12fcbf GR |
2157 | /* The Port VLAN needs to be saved across resets the same as the |
2158 | * default LAN MAC address. | |
2159 | */ | |
2160 | vf->port_vlan_id = le16_to_cpu(vsi->info.pvid); | |
5c3c48ac JB |
2161 | ret = 0; |
2162 | ||
2163 | error_pvid: | |
2164 | return ret; | |
2165 | } | |
2166 | ||
84590fd9 MW |
2167 | #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */ |
2168 | #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */ | |
5c3c48ac JB |
2169 | /** |
2170 | * i40e_ndo_set_vf_bw | |
2171 | * @netdev: network interface device structure | |
b40c82e6 JK |
2172 | * @vf_id: VF identifier |
2173 | * @tx_rate: Tx rate | |
5c3c48ac | 2174 | * |
b40c82e6 | 2175 | * configure VF Tx rate |
5c3c48ac | 2176 | **/ |
ed616689 SC |
2177 | int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, |
2178 | int max_tx_rate) | |
5c3c48ac | 2179 | { |
6b192891 MW |
2180 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
2181 | struct i40e_pf *pf = np->vsi->back; | |
2182 | struct i40e_vsi *vsi; | |
2183 | struct i40e_vf *vf; | |
2184 | int speed = 0; | |
2185 | int ret = 0; | |
2186 | ||
2187 | /* validate the request */ | |
2188 | if (vf_id >= pf->num_alloc_vfs) { | |
2189 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id); | |
2190 | ret = -EINVAL; | |
2191 | goto error; | |
2192 | } | |
2193 | ||
ed616689 | 2194 | if (min_tx_rate) { |
b40c82e6 | 2195 | dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n", |
ed616689 SC |
2196 | min_tx_rate, vf_id); |
2197 | return -EINVAL; | |
2198 | } | |
2199 | ||
6b192891 | 2200 | vf = &(pf->vf[vf_id]); |
fdf0e0bf | 2201 | vsi = pf->vsi[vf->lan_vsi_idx]; |
6b192891 MW |
2202 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
2203 | dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id); | |
2204 | ret = -EINVAL; | |
2205 | goto error; | |
2206 | } | |
2207 | ||
2208 | switch (pf->hw.phy.link_info.link_speed) { | |
2209 | case I40E_LINK_SPEED_40GB: | |
2210 | speed = 40000; | |
2211 | break; | |
2212 | case I40E_LINK_SPEED_10GB: | |
2213 | speed = 10000; | |
2214 | break; | |
2215 | case I40E_LINK_SPEED_1GB: | |
2216 | speed = 1000; | |
2217 | break; | |
2218 | default: | |
2219 | break; | |
2220 | } | |
2221 | ||
ed616689 | 2222 | if (max_tx_rate > speed) { |
b40c82e6 | 2223 | dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.", |
ed616689 | 2224 | max_tx_rate, vf->vf_id); |
6b192891 MW |
2225 | ret = -EINVAL; |
2226 | goto error; | |
2227 | } | |
2228 | ||
dac9b31a MW |
2229 | if ((max_tx_rate < 50) && (max_tx_rate > 0)) { |
2230 | dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n"); | |
2231 | max_tx_rate = 50; | |
2232 | } | |
2233 | ||
6b192891 | 2234 | /* Tx rate credits are in values of 50Mbps, 0 is disabled*/ |
84590fd9 MW |
2235 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid, |
2236 | max_tx_rate / I40E_BW_CREDIT_DIVISOR, | |
2237 | I40E_MAX_BW_INACTIVE_ACCUM, NULL); | |
6b192891 | 2238 | if (ret) { |
ed616689 | 2239 | dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n", |
6b192891 MW |
2240 | ret); |
2241 | ret = -EIO; | |
2242 | goto error; | |
2243 | } | |
ed616689 | 2244 | vf->tx_rate = max_tx_rate; |
6b192891 MW |
2245 | error: |
2246 | return ret; | |
5c3c48ac JB |
2247 | } |
2248 | ||
2249 | /** | |
2250 | * i40e_ndo_get_vf_config | |
2251 | * @netdev: network interface device structure | |
b40c82e6 JK |
2252 | * @vf_id: VF identifier |
2253 | * @ivi: VF configuration structure | |
5c3c48ac | 2254 | * |
b40c82e6 | 2255 | * return VF configuration |
5c3c48ac JB |
2256 | **/ |
2257 | int i40e_ndo_get_vf_config(struct net_device *netdev, | |
2258 | int vf_id, struct ifla_vf_info *ivi) | |
2259 | { | |
2260 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
5c3c48ac JB |
2261 | struct i40e_vsi *vsi = np->vsi; |
2262 | struct i40e_pf *pf = vsi->back; | |
2263 | struct i40e_vf *vf; | |
2264 | int ret = 0; | |
2265 | ||
2266 | /* validate the request */ | |
2267 | if (vf_id >= pf->num_alloc_vfs) { | |
2268 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); | |
2269 | ret = -EINVAL; | |
2270 | goto error_param; | |
2271 | } | |
2272 | ||
2273 | vf = &(pf->vf[vf_id]); | |
2274 | /* first vsi is always the LAN vsi */ | |
fdf0e0bf | 2275 | vsi = pf->vsi[vf->lan_vsi_idx]; |
5c3c48ac JB |
2276 | if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) { |
2277 | dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id); | |
2278 | ret = -EINVAL; | |
2279 | goto error_param; | |
2280 | } | |
2281 | ||
2282 | ivi->vf = vf_id; | |
2283 | ||
f4a1c5cf | 2284 | memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN); |
5c3c48ac | 2285 | |
ed616689 SC |
2286 | ivi->max_tx_rate = vf->tx_rate; |
2287 | ivi->min_tx_rate = 0; | |
5c3c48ac JB |
2288 | ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK; |
2289 | ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >> | |
2290 | I40E_VLAN_PRIORITY_SHIFT; | |
84ca55a0 MW |
2291 | if (vf->link_forced == false) |
2292 | ivi->linkstate = IFLA_VF_LINK_STATE_AUTO; | |
2293 | else if (vf->link_up == true) | |
2294 | ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE; | |
2295 | else | |
2296 | ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE; | |
c674d125 | 2297 | ivi->spoofchk = vf->spoofchk; |
5c3c48ac JB |
2298 | ret = 0; |
2299 | ||
2300 | error_param: | |
2301 | return ret; | |
2302 | } | |
588aefa0 MW |
2303 | |
2304 | /** | |
2305 | * i40e_ndo_set_vf_link_state | |
2306 | * @netdev: network interface device structure | |
b40c82e6 | 2307 | * @vf_id: VF identifier |
588aefa0 MW |
2308 | * @link: required link state |
2309 | * | |
2310 | * Set the link state of a specified VF, regardless of physical link state | |
2311 | **/ | |
2312 | int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link) | |
2313 | { | |
2314 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2315 | struct i40e_pf *pf = np->vsi->back; | |
2316 | struct i40e_virtchnl_pf_event pfe; | |
2317 | struct i40e_hw *hw = &pf->hw; | |
2318 | struct i40e_vf *vf; | |
f19efbb5 | 2319 | int abs_vf_id; |
588aefa0 MW |
2320 | int ret = 0; |
2321 | ||
2322 | /* validate the request */ | |
2323 | if (vf_id >= pf->num_alloc_vfs) { | |
2324 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); | |
2325 | ret = -EINVAL; | |
2326 | goto error_out; | |
2327 | } | |
2328 | ||
2329 | vf = &pf->vf[vf_id]; | |
f19efbb5 | 2330 | abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id; |
588aefa0 MW |
2331 | |
2332 | pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE; | |
2333 | pfe.severity = I40E_PF_EVENT_SEVERITY_INFO; | |
2334 | ||
2335 | switch (link) { | |
2336 | case IFLA_VF_LINK_STATE_AUTO: | |
2337 | vf->link_forced = false; | |
2338 | pfe.event_data.link_event.link_status = | |
2339 | pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP; | |
2340 | pfe.event_data.link_event.link_speed = | |
2341 | pf->hw.phy.link_info.link_speed; | |
2342 | break; | |
2343 | case IFLA_VF_LINK_STATE_ENABLE: | |
2344 | vf->link_forced = true; | |
2345 | vf->link_up = true; | |
2346 | pfe.event_data.link_event.link_status = true; | |
2347 | pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB; | |
2348 | break; | |
2349 | case IFLA_VF_LINK_STATE_DISABLE: | |
2350 | vf->link_forced = true; | |
2351 | vf->link_up = false; | |
2352 | pfe.event_data.link_event.link_status = false; | |
2353 | pfe.event_data.link_event.link_speed = 0; | |
2354 | break; | |
2355 | default: | |
2356 | ret = -EINVAL; | |
2357 | goto error_out; | |
2358 | } | |
2359 | /* Notify the VF of its new link state */ | |
f19efbb5 | 2360 | i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT, |
588aefa0 MW |
2361 | 0, (u8 *)&pfe, sizeof(pfe), NULL); |
2362 | ||
2363 | error_out: | |
2364 | return ret; | |
2365 | } | |
c674d125 MW |
2366 | |
2367 | /** | |
2368 | * i40e_ndo_set_vf_spoofchk | |
2369 | * @netdev: network interface device structure | |
b40c82e6 | 2370 | * @vf_id: VF identifier |
c674d125 MW |
2371 | * @enable: flag to enable or disable feature |
2372 | * | |
2373 | * Enable or disable VF spoof checking | |
2374 | **/ | |
e6d9004d | 2375 | int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable) |
c674d125 MW |
2376 | { |
2377 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2378 | struct i40e_vsi *vsi = np->vsi; | |
2379 | struct i40e_pf *pf = vsi->back; | |
2380 | struct i40e_vsi_context ctxt; | |
2381 | struct i40e_hw *hw = &pf->hw; | |
2382 | struct i40e_vf *vf; | |
2383 | int ret = 0; | |
2384 | ||
2385 | /* validate the request */ | |
2386 | if (vf_id >= pf->num_alloc_vfs) { | |
2387 | dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id); | |
2388 | ret = -EINVAL; | |
2389 | goto out; | |
2390 | } | |
2391 | ||
2392 | vf = &(pf->vf[vf_id]); | |
2393 | ||
2394 | if (enable == vf->spoofchk) | |
2395 | goto out; | |
2396 | ||
2397 | vf->spoofchk = enable; | |
2398 | memset(&ctxt, 0, sizeof(ctxt)); | |
fdf0e0bf | 2399 | ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid; |
c674d125 MW |
2400 | ctxt.pf_num = pf->hw.pf_id; |
2401 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); | |
2402 | if (enable) | |
30d71af5 GR |
2403 | ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
2404 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); | |
c674d125 MW |
2405 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
2406 | if (ret) { | |
2407 | dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n", | |
2408 | ret); | |
2409 | ret = -EIO; | |
2410 | } | |
2411 | out: | |
2412 | return ret; | |
2413 | } |