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