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