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