blob: 4d8fd22ae9e8cea2253459490c00ed3fe3773d37 [file] [log] [blame]
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00005 *
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 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * 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/>.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +000017 *
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/**
Greg Rosef9b4b622014-03-06 09:02:28 +000032 * i40e_vc_disable_vf
33 * @pf: pointer to the pf info
34 * @vf: pointer to the vf info
35 *
36 * Disable the VF through a SW reset
37 **/
38static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
39{
40 struct i40e_hw *hw = &pf->hw;
41 u32 reg;
42
43 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
44 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
45 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
46 i40e_flush(hw);
47}
48
49/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +000050 * i40e_vc_isvalid_vsi_id
51 * @vf: pointer to the vf info
52 * @vsi_id: vf relative vsi id
53 *
54 * check for the valid vsi id
55 **/
56static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u8 vsi_id)
57{
58 struct i40e_pf *pf = vf->pf;
59
60 return pf->vsi[vsi_id]->vf_id == vf->vf_id;
61}
62
63/**
64 * i40e_vc_isvalid_queue_id
65 * @vf: pointer to the vf info
66 * @vsi_id: vsi id
67 * @qid: vsi relative queue id
68 *
69 * check for the valid queue id
70 **/
71static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u8 vsi_id,
72 u8 qid)
73{
74 struct i40e_pf *pf = vf->pf;
75
Ashish Shah5f5e33b2014-07-10 07:58:15 +000076 return qid < pf->vsi[vsi_id]->alloc_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +000077}
78
79/**
80 * i40e_vc_isvalid_vector_id
81 * @vf: pointer to the vf info
82 * @vector_id: vf relative vector id
83 *
84 * check for the valid vector id
85 **/
86static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
87{
88 struct i40e_pf *pf = vf->pf;
89
Mitch Williams9347eb72014-02-11 08:26:32 +000090 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +000091}
92
93/***********************vf resource mgmt routines*****************/
94
95/**
96 * i40e_vc_get_pf_queue_id
97 * @vf: pointer to the vf info
98 * @vsi_idx: index of VSI in PF struct
99 * @vsi_queue_id: vsi relative queue id
100 *
101 * return pf relative queue id
102 **/
103static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u8 vsi_idx,
104 u8 vsi_queue_id)
105{
106 struct i40e_pf *pf = vf->pf;
107 struct i40e_vsi *vsi = pf->vsi[vsi_idx];
108 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
109
110 if (le16_to_cpu(vsi->info.mapping_flags) &
111 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
112 pf_queue_id =
113 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
114 else
115 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
116 vsi_queue_id;
117
118 return pf_queue_id;
119}
120
121/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000122 * i40e_config_irq_link_list
123 * @vf: pointer to the vf info
124 * @vsi_idx: index of VSI in PF struct
125 * @vecmap: irq map info
126 *
127 * configure irq link list from the map
128 **/
129static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_idx,
130 struct i40e_virtchnl_vector_map *vecmap)
131{
132 unsigned long linklistmap = 0, tempmap;
133 struct i40e_pf *pf = vf->pf;
134 struct i40e_hw *hw = &pf->hw;
135 u16 vsi_queue_id, pf_queue_id;
136 enum i40e_queue_type qtype;
137 u16 next_q, vector_id;
138 u32 reg, reg_idx;
139 u16 itr_idx = 0;
140
141 vector_id = vecmap->vector_id;
142 /* setup the head */
143 if (0 == vector_id)
144 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
145 else
146 reg_idx = I40E_VPINT_LNKLSTN(
Mitch Williams9347eb72014-02-11 08:26:32 +0000147 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
148 (vector_id - 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000149
150 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
151 /* Special case - No queues mapped on this vector */
152 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
153 goto irq_list_done;
154 }
155 tempmap = vecmap->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000156 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000157 linklistmap |= (1 <<
158 (I40E_VIRTCHNL_SUPPORTED_QTYPES *
159 vsi_queue_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000160 }
161
162 tempmap = vecmap->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000163 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000164 linklistmap |= (1 <<
165 (I40E_VIRTCHNL_SUPPORTED_QTYPES * vsi_queue_id
166 + 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000167 }
168
169 next_q = find_first_bit(&linklistmap,
170 (I40E_MAX_VSI_QP *
171 I40E_VIRTCHNL_SUPPORTED_QTYPES));
172 vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES;
173 qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES;
174 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
175 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
176
177 wr32(hw, reg_idx, reg);
178
179 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
180 switch (qtype) {
181 case I40E_QUEUE_TYPE_RX:
182 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
183 itr_idx = vecmap->rxitr_idx;
184 break;
185 case I40E_QUEUE_TYPE_TX:
186 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
187 itr_idx = vecmap->txitr_idx;
188 break;
189 default:
190 break;
191 }
192
193 next_q = find_next_bit(&linklistmap,
194 (I40E_MAX_VSI_QP *
195 I40E_VIRTCHNL_SUPPORTED_QTYPES),
196 next_q + 1);
Mitch Williams829af3a2013-12-18 13:46:00 +0000197 if (next_q <
198 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000199 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
200 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
201 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx,
202 vsi_queue_id);
203 } else {
204 pf_queue_id = I40E_QUEUE_END_OF_LIST;
205 qtype = 0;
206 }
207
208 /* format for the RQCTL & TQCTL regs is same */
209 reg = (vector_id) |
210 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
211 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
212 (1 << I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
213 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
214 wr32(hw, reg_idx, reg);
215 }
216
217irq_list_done:
218 i40e_flush(hw);
219}
220
221/**
222 * i40e_config_vsi_tx_queue
223 * @vf: pointer to the vf info
224 * @vsi_idx: index of VSI in PF struct
225 * @vsi_queue_id: vsi relative queue index
226 * @info: config. info
227 *
228 * configure tx queue
229 **/
230static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_idx,
231 u16 vsi_queue_id,
232 struct i40e_virtchnl_txq_info *info)
233{
234 struct i40e_pf *pf = vf->pf;
235 struct i40e_hw *hw = &pf->hw;
236 struct i40e_hmc_obj_txq tx_ctx;
237 u16 pf_queue_id;
238 u32 qtx_ctl;
239 int ret = 0;
240
241 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
242
243 /* clear the context structure first */
244 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
245
246 /* only set the required fields */
247 tx_ctx.base = info->dma_ring_addr / 128;
248 tx_ctx.qlen = info->ring_len;
249 tx_ctx.rdylist = le16_to_cpu(pf->vsi[vsi_idx]->info.qs_handle[0]);
250 tx_ctx.rdylist_act = 0;
Ashish Shah5d298962014-05-22 06:31:25 +0000251 tx_ctx.head_wb_ena = info->headwb_enabled;
252 tx_ctx.head_wb_addr = info->dma_headwb_addr;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000253
254 /* clear the context in the HMC */
255 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
256 if (ret) {
257 dev_err(&pf->pdev->dev,
258 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
259 pf_queue_id, ret);
260 ret = -ENOENT;
261 goto error_context;
262 }
263
264 /* set the context in the HMC */
265 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
266 if (ret) {
267 dev_err(&pf->pdev->dev,
268 "Failed to set VF LAN Tx queue context %d error: %d\n",
269 pf_queue_id, ret);
270 ret = -ENOENT;
271 goto error_context;
272 }
273
274 /* associate this queue with the PCI VF function */
275 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +0000276 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000277 & I40E_QTX_CTL_PF_INDX_MASK);
278 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
279 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
280 & I40E_QTX_CTL_VFVM_INDX_MASK);
281 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
282 i40e_flush(hw);
283
284error_context:
285 return ret;
286}
287
288/**
289 * i40e_config_vsi_rx_queue
290 * @vf: pointer to the vf info
291 * @vsi_idx: index of VSI in PF struct
292 * @vsi_queue_id: vsi relative queue index
293 * @info: config. info
294 *
295 * configure rx queue
296 **/
297static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_idx,
298 u16 vsi_queue_id,
299 struct i40e_virtchnl_rxq_info *info)
300{
301 struct i40e_pf *pf = vf->pf;
302 struct i40e_hw *hw = &pf->hw;
303 struct i40e_hmc_obj_rxq rx_ctx;
304 u16 pf_queue_id;
305 int ret = 0;
306
307 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
308
309 /* clear the context structure first */
310 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
311
312 /* only set the required fields */
313 rx_ctx.base = info->dma_ring_addr / 128;
314 rx_ctx.qlen = info->ring_len;
315
316 if (info->splithdr_enabled) {
317 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
318 I40E_RX_SPLIT_IP |
319 I40E_RX_SPLIT_TCP_UDP |
320 I40E_RX_SPLIT_SCTP;
321 /* header length validation */
322 if (info->hdr_size > ((2 * 1024) - 64)) {
323 ret = -EINVAL;
324 goto error_param;
325 }
326 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
327
328 /* set splitalways mode 10b */
329 rx_ctx.dtype = 0x2;
330 }
331
332 /* databuffer length validation */
333 if (info->databuffer_size > ((16 * 1024) - 128)) {
334 ret = -EINVAL;
335 goto error_param;
336 }
337 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
338
339 /* max pkt. length validation */
340 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
341 ret = -EINVAL;
342 goto error_param;
343 }
344 rx_ctx.rxmax = info->max_pkt_size;
345
346 /* enable 32bytes desc always */
347 rx_ctx.dsize = 1;
348
349 /* default values */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000350 rx_ctx.lrxqthresh = 2;
351 rx_ctx.crcstrip = 1;
Mitch Williams50d41652014-04-09 05:58:55 +0000352 rx_ctx.prefena = 1;
Shannon Nelsonc1d11ce2014-07-29 04:01:03 +0000353 rx_ctx.l2tsel = 1;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000354
355 /* clear the context in the HMC */
356 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
357 if (ret) {
358 dev_err(&pf->pdev->dev,
359 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
360 pf_queue_id, ret);
361 ret = -ENOENT;
362 goto error_param;
363 }
364
365 /* set the context in the HMC */
366 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
367 if (ret) {
368 dev_err(&pf->pdev->dev,
369 "Failed to set VF LAN Rx queue context %d error: %d\n",
370 pf_queue_id, ret);
371 ret = -ENOENT;
372 goto error_param;
373 }
374
375error_param:
376 return ret;
377}
378
379/**
380 * i40e_alloc_vsi_res
381 * @vf: pointer to the vf info
382 * @type: type of VSI to allocate
383 *
384 * alloc vf vsi context & resources
385 **/
386static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
387{
388 struct i40e_mac_filter *f = NULL;
389 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000390 struct i40e_vsi *vsi;
391 int ret = 0;
392
393 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
394
395 if (!vsi) {
396 dev_err(&pf->pdev->dev,
397 "add vsi failed for vf %d, aq_err %d\n",
398 vf->vf_id, pf->hw.aq.asq_last_status);
399 ret = -ENOENT;
400 goto error_alloc_vsi_res;
401 }
402 if (type == I40E_VSI_SRIOV) {
Greg Rose1a103702013-11-28 06:42:39 +0000403 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000404 vf->lan_vsi_index = vsi->idx;
405 vf->lan_vsi_id = vsi->id;
406 dev_info(&pf->pdev->dev,
Mitch Williamsd4194992014-01-14 00:49:51 -0800407 "VF %d assigned LAN VSI index %d, VSI id %d\n",
408 vf->vf_id, vsi->idx, vsi->id);
Greg Rose6c12fcb2013-11-28 06:39:34 +0000409 /* If the port VLAN has been configured and then the
410 * VF driver was removed then the VSI port VLAN
411 * configuration was destroyed. Check if there is
412 * a port VLAN and restore the VSI configuration if
413 * needed.
414 */
415 if (vf->port_vlan_id)
416 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000417 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
Greg Rose6c12fcb2013-11-28 06:39:34 +0000418 vf->port_vlan_id, true, false);
Greg Rose1a103702013-11-28 06:42:39 +0000419 if (!f)
420 dev_info(&pf->pdev->dev,
421 "Could not allocate VF MAC addr\n");
422 f = i40e_add_filter(vsi, brdcast, vf->port_vlan_id,
423 true, false);
424 if (!f)
425 dev_info(&pf->pdev->dev,
426 "Could not allocate VF broadcast filter\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000427 }
Neerav Parikh6dbbbfb2013-11-26 10:49:24 +0000428
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000429 /* program mac filter */
430 ret = i40e_sync_vsi_filters(vsi);
Mitch Williamsfd1646e2014-02-13 03:48:44 -0800431 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000432 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000433
Mitch Williams6b192892014-03-06 09:02:29 +0000434 /* Set VF bandwidth if specified */
435 if (vf->tx_rate) {
436 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
437 vf->tx_rate / 50, 0, NULL);
438 if (ret)
439 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
440 vf->vf_id, ret);
441 }
442
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000443error_alloc_vsi_res:
444 return ret;
445}
446
447/**
Mitch Williams805bd5b2013-11-28 06:39:26 +0000448 * i40e_enable_vf_mappings
449 * @vf: pointer to the vf info
450 *
451 * enable vf mappings
452 **/
453static void i40e_enable_vf_mappings(struct i40e_vf *vf)
454{
455 struct i40e_pf *pf = vf->pf;
456 struct i40e_hw *hw = &pf->hw;
457 u32 reg, total_queue_pairs = 0;
458 int j;
459
460 /* Tell the hardware we're using noncontiguous mapping. HW requires
461 * that VF queues be mapped using this method, even when they are
462 * contiguous in real life
463 */
464 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
465 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
466
467 /* enable VF vplan_qtable mappings */
468 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
469 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
470
471 /* map PF queues to VF queues */
Ashish Shah5f5e33b2014-07-10 07:58:15 +0000472 for (j = 0; j < pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs; j++) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000473 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index, j);
474 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
475 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
476 total_queue_pairs++;
477 }
478
479 /* map PF queues to VSI */
480 for (j = 0; j < 7; j++) {
Ashish Shah5f5e33b2014-07-10 07:58:15 +0000481 if (j * 2 >= pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000482 reg = 0x07FF07FF; /* unused */
483 } else {
484 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
485 j * 2);
486 reg = qid;
487 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
488 (j * 2) + 1);
489 reg |= qid << 16;
490 }
491 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
492 }
493
494 i40e_flush(hw);
495}
496
497/**
498 * i40e_disable_vf_mappings
499 * @vf: pointer to the vf info
500 *
501 * disable vf mappings
502 **/
503static void i40e_disable_vf_mappings(struct i40e_vf *vf)
504{
505 struct i40e_pf *pf = vf->pf;
506 struct i40e_hw *hw = &pf->hw;
507 int i;
508
509 /* disable qp mappings */
510 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
511 for (i = 0; i < I40E_MAX_VSI_QP; i++)
512 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
513 I40E_QUEUE_END_OF_LIST);
514 i40e_flush(hw);
515}
516
517/**
518 * i40e_free_vf_res
519 * @vf: pointer to the vf info
520 *
521 * free vf resources
522 **/
523static void i40e_free_vf_res(struct i40e_vf *vf)
524{
525 struct i40e_pf *pf = vf->pf;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000526 struct i40e_hw *hw = &pf->hw;
527 u32 reg_idx, reg;
528 int i, msix_vf;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000529
530 /* free vsi & disconnect it from the parent uplink */
531 if (vf->lan_vsi_index) {
532 i40e_vsi_release(pf->vsi[vf->lan_vsi_index]);
533 vf->lan_vsi_index = 0;
534 vf->lan_vsi_id = 0;
535 }
Mitch Williams9347eb72014-02-11 08:26:32 +0000536 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
537
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000538 /* disable interrupts so the VF starts in a known state */
539 for (i = 0; i < msix_vf; i++) {
540 /* format is same for both registers */
541 if (0 == i)
542 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
543 else
544 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
545 (vf->vf_id))
546 + (i - 1));
547 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
548 i40e_flush(hw);
549 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000550
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000551 /* clear the irq settings */
552 for (i = 0; i < msix_vf; i++) {
553 /* format is same for both registers */
554 if (0 == i)
555 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
556 else
557 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
558 (vf->vf_id))
559 + (i - 1));
560 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
561 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
562 wr32(hw, reg_idx, reg);
563 i40e_flush(hw);
564 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000565 /* reset some of the state varibles keeping
566 * track of the resources
567 */
568 vf->num_queue_pairs = 0;
569 vf->vf_states = 0;
570}
571
572/**
573 * i40e_alloc_vf_res
574 * @vf: pointer to the vf info
575 *
576 * allocate vf resources
577 **/
578static int i40e_alloc_vf_res(struct i40e_vf *vf)
579{
580 struct i40e_pf *pf = vf->pf;
581 int total_queue_pairs = 0;
582 int ret;
583
584 /* allocate hw vsi context & associated resources */
585 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
586 if (ret)
587 goto error_alloc;
Ashish Shah5f5e33b2014-07-10 07:58:15 +0000588 total_queue_pairs += pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000589 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
590
591 /* store the total qps number for the runtime
592 * vf req validation
593 */
594 vf->num_queue_pairs = total_queue_pairs;
595
596 /* vf is now completely initialized */
597 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
598
599error_alloc:
600 if (ret)
601 i40e_free_vf_res(vf);
602
603 return ret;
604}
605
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000606#define VF_DEVICE_STATUS 0xAA
607#define VF_TRANS_PENDING_MASK 0x20
608/**
609 * i40e_quiesce_vf_pci
610 * @vf: pointer to the vf structure
611 *
612 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
613 * if the transactions never clear.
614 **/
615static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
616{
617 struct i40e_pf *pf = vf->pf;
618 struct i40e_hw *hw = &pf->hw;
619 int vf_abs_id, i;
620 u32 reg;
621
Mitch Williamsb141d612013-11-28 06:39:36 +0000622 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000623
624 wr32(hw, I40E_PF_PCI_CIAA,
625 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
626 for (i = 0; i < 100; i++) {
627 reg = rd32(hw, I40E_PF_PCI_CIAD);
628 if ((reg & VF_TRANS_PENDING_MASK) == 0)
629 return 0;
630 udelay(1);
631 }
632 return -EIO;
633}
634
Mitch Williams805bd5b2013-11-28 06:39:26 +0000635/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000636 * i40e_reset_vf
637 * @vf: pointer to the vf structure
638 * @flr: VFLR was issued or not
639 *
640 * reset the vf
641 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000642void i40e_reset_vf(struct i40e_vf *vf, bool flr)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000643{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000644 struct i40e_pf *pf = vf->pf;
645 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000646 bool rsd = false;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000647 int i;
648 u32 reg;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000649
650 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000651 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
652
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000653 /* In the case of a VFLR, the HW has already reset the VF and we
654 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000655 */
656 if (!flr) {
657 /* reset vf using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000658 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
659 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000660 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
661 i40e_flush(hw);
662 }
663
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000664 if (i40e_quiesce_vf_pci(vf))
665 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
666 vf->vf_id);
667
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000668 /* poll VPGEN_VFRSTAT reg to make sure
669 * that reset is complete
670 */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000671 for (i = 0; i < 100; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000672 /* vf reset requires driver to first reset the
Akeem G Abodunrin84a92082014-08-01 13:27:09 -0700673 * vf and then poll the status register to make sure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000674 * that the requested op was completed
675 * successfully
676 */
677 udelay(10);
678 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
679 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
680 rsd = true;
681 break;
682 }
683 }
684
685 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000686 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000687 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000688 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000689 /* clear the reset bit in the VPGEN_VFRTRIG reg */
690 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
691 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
692 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000693
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000694 /* On initial reset, we won't have any queues */
695 if (vf->lan_vsi_index == 0)
696 goto complete_reset;
697
698 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_index], false);
699complete_reset:
700 /* reallocate vf resources to reset the VSI state */
701 i40e_free_vf_res(vf);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000702 i40e_alloc_vf_res(vf);
703 i40e_enable_vf_mappings(vf);
Mitch Williamsc17b3622014-02-13 03:48:45 -0800704 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000705
706 /* tell the VF the reset is done */
707 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
708 i40e_flush(hw);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000709}
710
711/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000712 * i40e_vfs_are_assigned
713 * @pf: pointer to the pf structure
714 *
715 * Determine if any VFs are assigned to VMs
716 **/
717static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
718{
719 struct pci_dev *pdev = pf->pdev;
720 struct pci_dev *vfdev;
721
722 /* loop through all the VFs to see if we own any that are assigned */
Shannon Nelsonab600852014-01-17 15:36:39 -0800723 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000724 while (vfdev) {
725 /* if we don't own it we don't care */
726 if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
727 /* if it is assigned we cannot release it */
728 if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
729 return true;
730 }
731
732 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Shannon Nelsonab600852014-01-17 15:36:39 -0800733 I40E_DEV_ID_VF,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000734 vfdev);
735 }
736
737 return false;
738}
Greg Rosec3542292013-12-13 08:38:38 +0000739#ifdef CONFIG_PCI_IOV
740
741/**
742 * i40e_enable_pf_switch_lb
743 * @pf: pointer to the pf structure
744 *
745 * enable switch loop back or die - no point in a return value
746 **/
747static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
748{
749 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
750 struct i40e_vsi_context ctxt;
751 int aq_ret;
752
753 ctxt.seid = pf->main_vsi_seid;
754 ctxt.pf_num = pf->hw.pf_id;
755 ctxt.vf_num = 0;
756 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
757 if (aq_ret) {
758 dev_info(&pf->pdev->dev,
759 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
760 __func__, aq_ret, pf->hw.aq.asq_last_status);
761 return;
762 }
763 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
764 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
765 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
766
767 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
768 if (aq_ret) {
769 dev_info(&pf->pdev->dev,
770 "%s: update vsi switch failed, aq_err=%d\n",
771 __func__, vsi->back->hw.aq.asq_last_status);
772 }
773}
774#endif
775
776/**
777 * i40e_disable_pf_switch_lb
778 * @pf: pointer to the pf structure
779 *
780 * disable switch loop back or die - no point in a return value
781 **/
782static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
783{
784 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
785 struct i40e_vsi_context ctxt;
786 int aq_ret;
787
788 ctxt.seid = pf->main_vsi_seid;
789 ctxt.pf_num = pf->hw.pf_id;
790 ctxt.vf_num = 0;
791 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
792 if (aq_ret) {
793 dev_info(&pf->pdev->dev,
794 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
795 __func__, aq_ret, pf->hw.aq.asq_last_status);
796 return;
797 }
798 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
799 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
800 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
801
802 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
803 if (aq_ret) {
804 dev_info(&pf->pdev->dev,
805 "%s: update vsi switch failed, aq_err=%d\n",
806 __func__, vsi->back->hw.aq.asq_last_status);
807 }
808}
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000809
810/**
811 * i40e_free_vfs
812 * @pf: pointer to the pf structure
813 *
814 * free vf resources
815 **/
816void i40e_free_vfs(struct i40e_pf *pf)
817{
Mitch Williamsf7414532013-11-28 06:39:40 +0000818 struct i40e_hw *hw = &pf->hw;
819 u32 reg_idx, bit_idx;
820 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000821
822 if (!pf->vf)
823 return;
824
825 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000826 i40e_irq_dynamic_disable_icr0(pf);
827
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000828 mdelay(10); /* let any messages in transit get finished up */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000829 /* free up vf resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000830 tmp = pf->num_alloc_vfs;
831 pf->num_alloc_vfs = 0;
832 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000833 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
834 i40e_free_vf_res(&pf->vf[i]);
835 /* disable qp mappings */
836 i40e_disable_vf_mappings(&pf->vf[i]);
837 }
838
839 kfree(pf->vf);
840 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000841
Mitch Williams9e5634d2014-04-04 04:43:14 +0000842 /* This check is for when the driver is unloaded while VFs are
843 * assigned. Setting the number of VFs to 0 through sysfs is caught
844 * before this function ever gets called.
845 */
Mitch Williamsf7414532013-11-28 06:39:40 +0000846 if (!i40e_vfs_are_assigned(pf)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000847 pci_disable_sriov(pf->pdev);
Mitch Williamsf7414532013-11-28 06:39:40 +0000848 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
849 * work correctly when SR-IOV gets re-enabled.
850 */
851 for (vf_id = 0; vf_id < tmp; vf_id++) {
852 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
853 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
854 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
855 }
Greg Rosec3542292013-12-13 08:38:38 +0000856 i40e_disable_pf_switch_lb(pf);
857 } else {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000858 dev_warn(&pf->pdev->dev,
859 "unable to disable SR-IOV because VFs are assigned.\n");
Greg Rosec3542292013-12-13 08:38:38 +0000860 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000861
862 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000863 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000864}
865
866#ifdef CONFIG_PCI_IOV
867/**
868 * i40e_alloc_vfs
869 * @pf: pointer to the pf structure
870 * @num_alloc_vfs: number of vfs to allocate
871 *
872 * allocate vf resources
873 **/
Mitch Williams4aeec012014-02-13 03:48:47 -0800874int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000875{
876 struct i40e_vf *vfs;
877 int i, ret = 0;
878
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000879 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000880 i40e_irq_dynamic_disable_icr0(pf);
881
Mitch Williams4aeec012014-02-13 03:48:47 -0800882 /* Check to see if we're just allocating resources for extant VFs */
883 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
884 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
885 if (ret) {
886 dev_err(&pf->pdev->dev,
887 "Failed to enable SR-IOV, error %d.\n", ret);
888 pf->num_alloc_vfs = 0;
889 goto err_iov;
890 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000891 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000892 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +0000893 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000894 if (!vfs) {
895 ret = -ENOMEM;
896 goto err_alloc;
897 }
Mitch Williamsc674d122014-05-20 08:01:40 +0000898 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000899
900 /* apply default profile */
901 for (i = 0; i < num_alloc_vfs; i++) {
902 vfs[i].pf = pf;
903 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
904 vfs[i].vf_id = i;
905
906 /* assign default capabilities */
907 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +0000908 vfs[i].spoofchk = true;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000909 /* vf resources get allocated during reset */
910 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000911
912 /* enable vf vplan_qtable mappings */
913 i40e_enable_vf_mappings(&vfs[i]);
914 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000915 pf->num_alloc_vfs = num_alloc_vfs;
916
Greg Rosec3542292013-12-13 08:38:38 +0000917 i40e_enable_pf_switch_lb(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000918err_alloc:
919 if (ret)
920 i40e_free_vfs(pf);
921err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000922 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000923 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000924 return ret;
925}
926
927#endif
928/**
929 * i40e_pci_sriov_enable
930 * @pdev: pointer to a pci_dev structure
931 * @num_vfs: number of vfs to allocate
932 *
933 * Enable or change the number of VFs
934 **/
935static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
936{
937#ifdef CONFIG_PCI_IOV
938 struct i40e_pf *pf = pci_get_drvdata(pdev);
939 int pre_existing_vfs = pci_num_vf(pdev);
940 int err = 0;
941
942 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
943 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
944 i40e_free_vfs(pf);
945 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
946 goto out;
947
948 if (num_vfs > pf->num_req_vfs) {
949 err = -EPERM;
950 goto err_out;
951 }
952
953 err = i40e_alloc_vfs(pf, num_vfs);
954 if (err) {
955 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
956 goto err_out;
957 }
958
959out:
960 return num_vfs;
961
962err_out:
963 return err;
964#endif
965 return 0;
966}
967
968/**
969 * i40e_pci_sriov_configure
970 * @pdev: pointer to a pci_dev structure
971 * @num_vfs: number of vfs to allocate
972 *
973 * Enable or change the number of VFs. Called when the user updates the number
974 * of VFs in sysfs.
975 **/
976int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
977{
978 struct i40e_pf *pf = pci_get_drvdata(pdev);
979
980 if (num_vfs)
981 return i40e_pci_sriov_enable(pdev, num_vfs);
982
Mitch Williams9e5634d2014-04-04 04:43:14 +0000983 if (!i40e_vfs_are_assigned(pf)) {
984 i40e_free_vfs(pf);
985 } else {
986 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
987 return -EINVAL;
988 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000989 return 0;
990}
991
992/***********************virtual channel routines******************/
993
994/**
995 * i40e_vc_send_msg_to_vf
996 * @vf: pointer to the vf info
997 * @v_opcode: virtual channel opcode
998 * @v_retval: virtual channel return value
999 * @msg: pointer to the msg buffer
1000 * @msglen: msg length
1001 *
1002 * send msg to vf
1003 **/
1004static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1005 u32 v_retval, u8 *msg, u16 msglen)
1006{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001007 struct i40e_pf *pf;
1008 struct i40e_hw *hw;
1009 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001010 i40e_status aq_ret;
1011
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001012 /* validate the request */
1013 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1014 return -EINVAL;
1015
1016 pf = vf->pf;
1017 hw = &pf->hw;
1018 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1019
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001020 /* single place to detect unsuccessful return values */
1021 if (v_retval) {
1022 vf->num_invalid_msgs++;
1023 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1024 v_opcode, v_retval);
1025 if (vf->num_invalid_msgs >
1026 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1027 dev_err(&pf->pdev->dev,
1028 "Number of invalid messages exceeded for VF %d\n",
1029 vf->vf_id);
1030 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1031 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1032 }
1033 } else {
1034 vf->num_valid_msgs++;
1035 }
1036
Ashish Shahf19efbb2014-08-01 13:27:06 -07001037 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001038 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001039 if (aq_ret) {
1040 dev_err(&pf->pdev->dev,
1041 "Unable to send the message to VF %d aq_err %d\n",
1042 vf->vf_id, pf->hw.aq.asq_last_status);
1043 return -EIO;
1044 }
1045
1046 return 0;
1047}
1048
1049/**
1050 * i40e_vc_send_resp_to_vf
1051 * @vf: pointer to the vf info
1052 * @opcode: operation code
1053 * @retval: return value
1054 *
1055 * send resp msg to vf
1056 **/
1057static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1058 enum i40e_virtchnl_ops opcode,
1059 i40e_status retval)
1060{
1061 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1062}
1063
1064/**
1065 * i40e_vc_get_version_msg
1066 * @vf: pointer to the vf info
1067 *
1068 * called from the vf to request the API version used by the PF
1069 **/
1070static int i40e_vc_get_version_msg(struct i40e_vf *vf)
1071{
1072 struct i40e_virtchnl_version_info info = {
1073 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1074 };
1075
1076 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1077 I40E_SUCCESS, (u8 *)&info,
1078 sizeof(struct
1079 i40e_virtchnl_version_info));
1080}
1081
1082/**
1083 * i40e_vc_get_vf_resources_msg
1084 * @vf: pointer to the vf info
1085 * @msg: pointer to the msg buffer
1086 * @msglen: msg length
1087 *
1088 * called from the vf to request its resources
1089 **/
1090static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf)
1091{
1092 struct i40e_virtchnl_vf_resource *vfres = NULL;
1093 struct i40e_pf *pf = vf->pf;
1094 i40e_status aq_ret = 0;
1095 struct i40e_vsi *vsi;
1096 int i = 0, len = 0;
1097 int num_vsis = 1;
1098 int ret;
1099
1100 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1101 aq_ret = I40E_ERR_PARAM;
1102 goto err;
1103 }
1104
1105 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1106 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1107
1108 vfres = kzalloc(len, GFP_KERNEL);
1109 if (!vfres) {
1110 aq_ret = I40E_ERR_NO_MEMORY;
1111 len = 0;
1112 goto err;
1113 }
1114
1115 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1116 vsi = pf->vsi[vf->lan_vsi_index];
1117 if (!vsi->info.pvid)
1118 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1119
1120 vfres->num_vsis = num_vsis;
1121 vfres->num_queue_pairs = vf->num_queue_pairs;
1122 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1123 if (vf->lan_vsi_index) {
1124 vfres->vsi_res[i].vsi_id = vf->lan_vsi_index;
1125 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1126 vfres->vsi_res[i].num_queue_pairs =
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001127 pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001128 memcpy(vfres->vsi_res[i].default_mac_addr,
1129 vf->default_lan_addr.addr, ETH_ALEN);
1130 i++;
1131 }
1132 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1133
1134err:
1135 /* send the response back to the vf */
1136 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1137 aq_ret, (u8 *)vfres, len);
1138
1139 kfree(vfres);
1140 return ret;
1141}
1142
1143/**
1144 * i40e_vc_reset_vf_msg
1145 * @vf: pointer to the vf info
1146 * @msg: pointer to the msg buffer
1147 * @msglen: msg length
1148 *
1149 * called from the vf to reset itself,
1150 * unlike other virtchnl messages, pf driver
1151 * doesn't send the response back to the vf
1152 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001153static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001154{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001155 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1156 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001157}
1158
1159/**
1160 * i40e_vc_config_promiscuous_mode_msg
1161 * @vf: pointer to the vf info
1162 * @msg: pointer to the msg buffer
1163 * @msglen: msg length
1164 *
1165 * called from the vf to configure the promiscuous mode of
1166 * vf vsis
1167 **/
1168static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1169 u8 *msg, u16 msglen)
1170{
1171 struct i40e_virtchnl_promisc_info *info =
1172 (struct i40e_virtchnl_promisc_info *)msg;
1173 struct i40e_pf *pf = vf->pf;
1174 struct i40e_hw *hw = &pf->hw;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001175 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001176 bool allmulti = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001177 i40e_status aq_ret;
1178
1179 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1180 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1181 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1182 (pf->vsi[info->vsi_id]->type != I40E_VSI_FCOE)) {
1183 aq_ret = I40E_ERR_PARAM;
1184 goto error_param;
1185 }
Ashish Shah89cb86c2014-08-01 13:27:10 -07001186 vsi = pf->vsi[info->vsi_id];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001187 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1188 allmulti = true;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001189 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001190 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;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001213 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001214 u16 vsi_id, vsi_queue_id;
1215 i40e_status aq_ret = 0;
1216 int i;
1217
1218 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1219 aq_ret = I40E_ERR_PARAM;
1220 goto error_param;
1221 }
1222
1223 vsi_id = qci->vsi_id;
1224 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1225 aq_ret = I40E_ERR_PARAM;
1226 goto error_param;
1227 }
1228 for (i = 0; i < qci->num_queue_pairs; i++) {
1229 qpi = &qci->qpair[i];
1230 vsi_queue_id = qpi->txq.queue_id;
1231 if ((qpi->txq.vsi_id != vsi_id) ||
1232 (qpi->rxq.vsi_id != vsi_id) ||
1233 (qpi->rxq.queue_id != vsi_queue_id) ||
1234 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1235 aq_ret = I40E_ERR_PARAM;
1236 goto error_param;
1237 }
1238
1239 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1240 &qpi->rxq) ||
1241 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1242 &qpi->txq)) {
1243 aq_ret = I40E_ERR_PARAM;
1244 goto error_param;
1245 }
1246 }
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001247 /* set vsi num_queue_pairs in use to num configured by vf */
1248 pf->vsi[vf->lan_vsi_index]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001249
1250error_param:
1251 /* send the response to the vf */
1252 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1253 aq_ret);
1254}
1255
1256/**
1257 * i40e_vc_config_irq_map_msg
1258 * @vf: pointer to the vf info
1259 * @msg: pointer to the msg buffer
1260 * @msglen: msg length
1261 *
1262 * called from the vf to configure the irq to
1263 * queue map
1264 **/
1265static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1266{
1267 struct i40e_virtchnl_irq_map_info *irqmap_info =
1268 (struct i40e_virtchnl_irq_map_info *)msg;
1269 struct i40e_virtchnl_vector_map *map;
1270 u16 vsi_id, vsi_queue_id, vector_id;
1271 i40e_status aq_ret = 0;
1272 unsigned long tempmap;
1273 int i;
1274
1275 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1276 aq_ret = I40E_ERR_PARAM;
1277 goto error_param;
1278 }
1279
1280 for (i = 0; i < irqmap_info->num_vectors; i++) {
1281 map = &irqmap_info->vecmap[i];
1282
1283 vector_id = map->vector_id;
1284 vsi_id = map->vsi_id;
1285 /* validate msg params */
1286 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1287 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1288 aq_ret = I40E_ERR_PARAM;
1289 goto error_param;
1290 }
1291
1292 /* lookout for the invalid queue index */
1293 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001294 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001295 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1296 vsi_queue_id)) {
1297 aq_ret = I40E_ERR_PARAM;
1298 goto error_param;
1299 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001300 }
1301
1302 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001303 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001304 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1305 vsi_queue_id)) {
1306 aq_ret = I40E_ERR_PARAM;
1307 goto error_param;
1308 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001309 }
1310
1311 i40e_config_irq_link_list(vf, vsi_id, map);
1312 }
1313error_param:
1314 /* send the response to the vf */
1315 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1316 aq_ret);
1317}
1318
1319/**
1320 * i40e_vc_enable_queues_msg
1321 * @vf: pointer to the vf info
1322 * @msg: pointer to the msg buffer
1323 * @msglen: msg length
1324 *
1325 * called from the vf to enable all or specific queue(s)
1326 **/
1327static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1328{
1329 struct i40e_virtchnl_queue_select *vqs =
1330 (struct i40e_virtchnl_queue_select *)msg;
1331 struct i40e_pf *pf = vf->pf;
1332 u16 vsi_id = vqs->vsi_id;
1333 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001334
1335 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1336 aq_ret = I40E_ERR_PARAM;
1337 goto error_param;
1338 }
1339
1340 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1341 aq_ret = I40E_ERR_PARAM;
1342 goto error_param;
1343 }
1344
1345 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1346 aq_ret = I40E_ERR_PARAM;
1347 goto error_param;
1348 }
Mitch Williams88f65632013-11-28 06:39:28 +00001349 if (i40e_vsi_control_rings(pf->vsi[vsi_id], true))
1350 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001351error_param:
1352 /* send the response to the vf */
1353 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1354 aq_ret);
1355}
1356
1357/**
1358 * i40e_vc_disable_queues_msg
1359 * @vf: pointer to the vf info
1360 * @msg: pointer to the msg buffer
1361 * @msglen: msg length
1362 *
1363 * called from the vf to disable all or specific
1364 * queue(s)
1365 **/
1366static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1367{
1368 struct i40e_virtchnl_queue_select *vqs =
1369 (struct i40e_virtchnl_queue_select *)msg;
1370 struct i40e_pf *pf = vf->pf;
1371 u16 vsi_id = vqs->vsi_id;
1372 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001373
1374 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1375 aq_ret = I40E_ERR_PARAM;
1376 goto error_param;
1377 }
1378
1379 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1380 aq_ret = I40E_ERR_PARAM;
1381 goto error_param;
1382 }
1383
1384 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1385 aq_ret = I40E_ERR_PARAM;
1386 goto error_param;
1387 }
Mitch Williams88f65632013-11-28 06:39:28 +00001388 if (i40e_vsi_control_rings(pf->vsi[vsi_id], false))
1389 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001390
1391error_param:
1392 /* send the response to the vf */
1393 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1394 aq_ret);
1395}
1396
1397/**
1398 * i40e_vc_get_stats_msg
1399 * @vf: pointer to the vf info
1400 * @msg: pointer to the msg buffer
1401 * @msglen: msg length
1402 *
1403 * called from the vf to get vsi stats
1404 **/
1405static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1406{
1407 struct i40e_virtchnl_queue_select *vqs =
1408 (struct i40e_virtchnl_queue_select *)msg;
1409 struct i40e_pf *pf = vf->pf;
1410 struct i40e_eth_stats stats;
1411 i40e_status aq_ret = 0;
1412 struct i40e_vsi *vsi;
1413
1414 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1415
1416 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1417 aq_ret = I40E_ERR_PARAM;
1418 goto error_param;
1419 }
1420
1421 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1422 aq_ret = I40E_ERR_PARAM;
1423 goto error_param;
1424 }
1425
1426 vsi = pf->vsi[vqs->vsi_id];
1427 if (!vsi) {
1428 aq_ret = I40E_ERR_PARAM;
1429 goto error_param;
1430 }
1431 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001432 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001433
1434error_param:
1435 /* send the response back to the vf */
1436 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1437 (u8 *)&stats, sizeof(stats));
1438}
1439
1440/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001441 * i40e_check_vf_permission
1442 * @vf: pointer to the vf info
1443 * @macaddr: pointer to the MAC Address being checked
1444 *
1445 * Check if the VF has permission to add or delete unicast MAC address
1446 * filters and return error code -EPERM if not. Then check if the
1447 * address filter requested is broadcast or zero and if so return
1448 * an invalid MAC address error code.
1449 **/
1450static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1451{
1452 struct i40e_pf *pf = vf->pf;
1453 int ret = 0;
1454
1455 if (is_broadcast_ether_addr(macaddr) ||
1456 is_zero_ether_addr(macaddr)) {
1457 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1458 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001459 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1460 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001461 /* If the host VMM administrator has set the VF MAC address
1462 * administratively via the ndo_set_vf_mac command then deny
1463 * permission to the VF to add or delete unicast MAC addresses.
Greg Rose5017c2a2013-12-07 10:36:54 +00001464 * The VF may request to set the MAC address filter already
1465 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001466 */
1467 dev_err(&pf->pdev->dev,
1468 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1469 ret = -EPERM;
1470 }
1471 return ret;
1472}
1473
1474/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001475 * i40e_vc_add_mac_addr_msg
1476 * @vf: pointer to the vf info
1477 * @msg: pointer to the msg buffer
1478 * @msglen: msg length
1479 *
1480 * add guest mac address filter
1481 **/
1482static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1483{
1484 struct i40e_virtchnl_ether_addr_list *al =
1485 (struct i40e_virtchnl_ether_addr_list *)msg;
1486 struct i40e_pf *pf = vf->pf;
1487 struct i40e_vsi *vsi = NULL;
1488 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001489 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001490 int i;
1491
1492 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1493 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1494 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001495 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001496 goto error_param;
1497 }
1498
1499 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001500 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1501 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001502 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001503 }
1504 vsi = pf->vsi[vsi_id];
1505
1506 /* add new addresses to the list */
1507 for (i = 0; i < al->num_elements; i++) {
1508 struct i40e_mac_filter *f;
1509
1510 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001511 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001512 if (i40e_is_vsi_in_vlan(vsi))
1513 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1514 true, false);
1515 else
1516 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1517 true, false);
1518 }
1519
1520 if (!f) {
1521 dev_err(&pf->pdev->dev,
1522 "Unable to add VF MAC filter\n");
Greg Rosef657a6e2013-11-28 06:39:42 +00001523 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001524 goto error_param;
1525 }
1526 }
1527
1528 /* program the updated filter list */
1529 if (i40e_sync_vsi_filters(vsi))
1530 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1531
1532error_param:
1533 /* send the response to the vf */
1534 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001535 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001536}
1537
1538/**
1539 * i40e_vc_del_mac_addr_msg
1540 * @vf: pointer to the vf info
1541 * @msg: pointer to the msg buffer
1542 * @msglen: msg length
1543 *
1544 * remove guest mac address filter
1545 **/
1546static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1547{
1548 struct i40e_virtchnl_ether_addr_list *al =
1549 (struct i40e_virtchnl_ether_addr_list *)msg;
1550 struct i40e_pf *pf = vf->pf;
1551 struct i40e_vsi *vsi = NULL;
1552 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001553 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001554 int i;
1555
1556 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1557 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1558 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001559 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001560 goto error_param;
1561 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001562
1563 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00001564 if (is_broadcast_ether_addr(al->list[i].addr) ||
1565 is_zero_ether_addr(al->list[i].addr)) {
1566 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1567 al->list[i].addr);
1568 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00001569 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00001570 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001571 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001572 vsi = pf->vsi[vsi_id];
1573
1574 /* delete addresses from the list */
1575 for (i = 0; i < al->num_elements; i++)
1576 i40e_del_filter(vsi, al->list[i].addr,
1577 I40E_VLAN_ANY, true, false);
1578
1579 /* program the updated filter list */
1580 if (i40e_sync_vsi_filters(vsi))
1581 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1582
1583error_param:
1584 /* send the response to the vf */
1585 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001586 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001587}
1588
1589/**
1590 * i40e_vc_add_vlan_msg
1591 * @vf: pointer to the vf info
1592 * @msg: pointer to the msg buffer
1593 * @msglen: msg length
1594 *
1595 * program guest vlan id
1596 **/
1597static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1598{
1599 struct i40e_virtchnl_vlan_filter_list *vfl =
1600 (struct i40e_virtchnl_vlan_filter_list *)msg;
1601 struct i40e_pf *pf = vf->pf;
1602 struct i40e_vsi *vsi = NULL;
1603 u16 vsi_id = vfl->vsi_id;
1604 i40e_status aq_ret = 0;
1605 int i;
1606
1607 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1608 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1609 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1610 aq_ret = I40E_ERR_PARAM;
1611 goto error_param;
1612 }
1613
1614 for (i = 0; i < vfl->num_elements; i++) {
1615 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1616 aq_ret = I40E_ERR_PARAM;
1617 dev_err(&pf->pdev->dev,
1618 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1619 goto error_param;
1620 }
1621 }
1622 vsi = pf->vsi[vsi_id];
1623 if (vsi->info.pvid) {
1624 aq_ret = I40E_ERR_PARAM;
1625 goto error_param;
1626 }
1627
1628 i40e_vlan_stripping_enable(vsi);
1629 for (i = 0; i < vfl->num_elements; i++) {
1630 /* add new VLAN filter */
1631 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1632 if (ret)
1633 dev_err(&pf->pdev->dev,
1634 "Unable to add VF vlan filter %d, error %d\n",
1635 vfl->vlan_id[i], ret);
1636 }
1637
1638error_param:
1639 /* send the response to the vf */
1640 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1641}
1642
1643/**
1644 * i40e_vc_remove_vlan_msg
1645 * @vf: pointer to the vf info
1646 * @msg: pointer to the msg buffer
1647 * @msglen: msg length
1648 *
1649 * remove programmed guest vlan id
1650 **/
1651static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1652{
1653 struct i40e_virtchnl_vlan_filter_list *vfl =
1654 (struct i40e_virtchnl_vlan_filter_list *)msg;
1655 struct i40e_pf *pf = vf->pf;
1656 struct i40e_vsi *vsi = NULL;
1657 u16 vsi_id = vfl->vsi_id;
1658 i40e_status aq_ret = 0;
1659 int i;
1660
1661 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1662 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1663 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1664 aq_ret = I40E_ERR_PARAM;
1665 goto error_param;
1666 }
1667
1668 for (i = 0; i < vfl->num_elements; i++) {
1669 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1670 aq_ret = I40E_ERR_PARAM;
1671 goto error_param;
1672 }
1673 }
1674
1675 vsi = pf->vsi[vsi_id];
1676 if (vsi->info.pvid) {
1677 aq_ret = I40E_ERR_PARAM;
1678 goto error_param;
1679 }
1680
1681 for (i = 0; i < vfl->num_elements; i++) {
1682 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1683 if (ret)
1684 dev_err(&pf->pdev->dev,
1685 "Unable to delete VF vlan filter %d, error %d\n",
1686 vfl->vlan_id[i], ret);
1687 }
1688
1689error_param:
1690 /* send the response to the vf */
1691 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1692}
1693
1694/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001695 * i40e_vc_validate_vf_msg
1696 * @vf: pointer to the vf info
1697 * @msg: pointer to the msg buffer
1698 * @msglen: msg length
1699 * @msghndl: msg handle
1700 *
1701 * validate msg
1702 **/
1703static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1704 u32 v_retval, u8 *msg, u16 msglen)
1705{
1706 bool err_msg_format = false;
1707 int valid_len;
1708
1709 /* Check if VF is disabled. */
1710 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1711 return I40E_ERR_PARAM;
1712
1713 /* Validate message length. */
1714 switch (v_opcode) {
1715 case I40E_VIRTCHNL_OP_VERSION:
1716 valid_len = sizeof(struct i40e_virtchnl_version_info);
1717 break;
1718 case I40E_VIRTCHNL_OP_RESET_VF:
1719 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1720 valid_len = 0;
1721 break;
1722 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1723 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1724 break;
1725 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1726 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1727 break;
1728 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1729 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1730 if (msglen >= valid_len) {
1731 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1732 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1733 valid_len += (vqc->num_queue_pairs *
1734 sizeof(struct
1735 i40e_virtchnl_queue_pair_info));
1736 if (vqc->num_queue_pairs == 0)
1737 err_msg_format = true;
1738 }
1739 break;
1740 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1741 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1742 if (msglen >= valid_len) {
1743 struct i40e_virtchnl_irq_map_info *vimi =
1744 (struct i40e_virtchnl_irq_map_info *)msg;
1745 valid_len += (vimi->num_vectors *
1746 sizeof(struct i40e_virtchnl_vector_map));
1747 if (vimi->num_vectors == 0)
1748 err_msg_format = true;
1749 }
1750 break;
1751 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1752 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1753 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1754 break;
1755 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1756 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1757 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1758 if (msglen >= valid_len) {
1759 struct i40e_virtchnl_ether_addr_list *veal =
1760 (struct i40e_virtchnl_ether_addr_list *)msg;
1761 valid_len += veal->num_elements *
1762 sizeof(struct i40e_virtchnl_ether_addr);
1763 if (veal->num_elements == 0)
1764 err_msg_format = true;
1765 }
1766 break;
1767 case I40E_VIRTCHNL_OP_ADD_VLAN:
1768 case I40E_VIRTCHNL_OP_DEL_VLAN:
1769 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1770 if (msglen >= valid_len) {
1771 struct i40e_virtchnl_vlan_filter_list *vfl =
1772 (struct i40e_virtchnl_vlan_filter_list *)msg;
1773 valid_len += vfl->num_elements * sizeof(u16);
1774 if (vfl->num_elements == 0)
1775 err_msg_format = true;
1776 }
1777 break;
1778 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1779 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1780 break;
1781 case I40E_VIRTCHNL_OP_GET_STATS:
1782 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1783 break;
1784 /* These are always errors coming from the VF. */
1785 case I40E_VIRTCHNL_OP_EVENT:
1786 case I40E_VIRTCHNL_OP_UNKNOWN:
1787 default:
1788 return -EPERM;
1789 break;
1790 }
1791 /* few more checks */
1792 if ((valid_len != msglen) || (err_msg_format)) {
1793 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1794 return -EINVAL;
1795 } else {
1796 return 0;
1797 }
1798}
1799
1800/**
1801 * i40e_vc_process_vf_msg
1802 * @pf: pointer to the pf structure
1803 * @vf_id: source vf id
1804 * @msg: pointer to the msg buffer
1805 * @msglen: msg length
1806 * @msghndl: msg handle
1807 *
1808 * called from the common aeq/arq handler to
1809 * process request from vf
1810 **/
1811int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1812 u32 v_retval, u8 *msg, u16 msglen)
1813{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001814 struct i40e_hw *hw = &pf->hw;
Dan Carpenterc243e962014-01-15 06:43:39 +00001815 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001816 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001817 int ret;
1818
1819 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001820 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001821 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001822 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001823 /* perform basic checks on the msg */
1824 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1825
1826 if (ret) {
Mitch Williams499ec802013-11-28 06:39:31 +00001827 dev_err(&pf->pdev->dev, "Invalid message from vf %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001828 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001829 return ret;
1830 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08001831
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001832 switch (v_opcode) {
1833 case I40E_VIRTCHNL_OP_VERSION:
1834 ret = i40e_vc_get_version_msg(vf);
1835 break;
1836 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1837 ret = i40e_vc_get_vf_resources_msg(vf);
1838 break;
1839 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001840 i40e_vc_reset_vf_msg(vf);
1841 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001842 break;
1843 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1844 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1845 break;
1846 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1847 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1848 break;
1849 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1850 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1851 break;
1852 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1853 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1854 break;
1855 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1856 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1857 break;
1858 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1859 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1860 break;
1861 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1862 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1863 break;
1864 case I40E_VIRTCHNL_OP_ADD_VLAN:
1865 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1866 break;
1867 case I40E_VIRTCHNL_OP_DEL_VLAN:
1868 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1869 break;
1870 case I40E_VIRTCHNL_OP_GET_STATS:
1871 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1872 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001873 case I40E_VIRTCHNL_OP_UNKNOWN:
1874 default:
Mitch Williams7efa84b2013-11-28 06:39:41 +00001875 dev_err(&pf->pdev->dev, "Unsupported opcode %d from vf %d\n",
1876 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001877 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1878 I40E_ERR_NOT_IMPLEMENTED);
1879 break;
1880 }
1881
1882 return ret;
1883}
1884
1885/**
1886 * i40e_vc_process_vflr_event
1887 * @pf: pointer to the pf structure
1888 *
1889 * called from the vlfr irq handler to
1890 * free up vf resources and state variables
1891 **/
1892int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1893{
1894 u32 reg, reg_idx, bit_idx, vf_id;
1895 struct i40e_hw *hw = &pf->hw;
1896 struct i40e_vf *vf;
1897
1898 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1899 return 0;
1900
1901 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1902 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1903 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1904 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1905 /* read GLGEN_VFLRSTAT register to find out the flr vfs */
1906 vf = &pf->vf[vf_id];
1907 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1908 if (reg & (1 << bit_idx)) {
1909 /* clear the bit in GLGEN_VFLRSTAT */
1910 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
1911
Mitch Williamseb2d80b2014-02-13 03:48:48 -08001912 if (!test_bit(__I40E_DOWN, &pf->state))
1913 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001914 }
1915 }
1916
1917 /* re-enable vflr interrupt cause */
1918 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1919 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1920 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1921 i40e_flush(hw);
1922
1923 return 0;
1924}
1925
1926/**
1927 * i40e_vc_vf_broadcast
1928 * @pf: pointer to the pf structure
1929 * @opcode: operation code
1930 * @retval: return value
1931 * @msg: pointer to the msg buffer
1932 * @msglen: msg length
1933 *
1934 * send a message to all VFs on a given PF
1935 **/
1936static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1937 enum i40e_virtchnl_ops v_opcode,
1938 i40e_status v_retval, u8 *msg,
1939 u16 msglen)
1940{
1941 struct i40e_hw *hw = &pf->hw;
1942 struct i40e_vf *vf = pf->vf;
1943 int i;
1944
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001945 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1946 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00001947 /* Not all vfs are enabled so skip the ones that are not */
1948 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
1949 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1950 continue;
1951
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001952 /* Ignore return value on purpose - a given VF may fail, but
1953 * we need to keep going and send to all of them
1954 */
Ashish Shahf19efbb2014-08-01 13:27:06 -07001955 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001956 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001957 }
1958}
1959
1960/**
1961 * i40e_vc_notify_link_state
1962 * @pf: pointer to the pf structure
1963 *
1964 * send a link status message to all VFs on a given PF
1965 **/
1966void i40e_vc_notify_link_state(struct i40e_pf *pf)
1967{
1968 struct i40e_virtchnl_pf_event pfe;
Mitch Williams588aefa2014-02-11 08:27:49 +00001969 struct i40e_hw *hw = &pf->hw;
1970 struct i40e_vf *vf = pf->vf;
1971 struct i40e_link_status *ls = &pf->hw.phy.link_info;
1972 int i;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001973
1974 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1975 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001976 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1977 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00001978 if (vf->link_forced) {
1979 pfe.event_data.link_event.link_status = vf->link_up;
1980 pfe.event_data.link_event.link_speed =
1981 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
1982 } else {
1983 pfe.event_data.link_event.link_status =
1984 ls->link_info & I40E_AQ_LINK_UP;
1985 pfe.event_data.link_event.link_speed = ls->link_speed;
1986 }
Ashish Shahf19efbb2014-08-01 13:27:06 -07001987 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00001988 0, (u8 *)&pfe, sizeof(pfe),
1989 NULL);
Mitch Williams588aefa2014-02-11 08:27:49 +00001990 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001991}
1992
1993/**
1994 * i40e_vc_notify_reset
1995 * @pf: pointer to the pf structure
1996 *
1997 * indicate a pending reset to all VFs on a given PF
1998 **/
1999void i40e_vc_notify_reset(struct i40e_pf *pf)
2000{
2001 struct i40e_virtchnl_pf_event pfe;
2002
2003 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
2004 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
2005 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, I40E_SUCCESS,
2006 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
2007}
2008
2009/**
2010 * i40e_vc_notify_vf_reset
2011 * @vf: pointer to the vf structure
2012 *
2013 * indicate a pending reset to the given VF
2014 **/
2015void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
2016{
2017 struct i40e_virtchnl_pf_event pfe;
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00002018 int abs_vf_id;
2019
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00002020 /* validate the request */
2021 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
2022 return;
2023
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00002024 /* verify if the VF is in either init or active before proceeding */
2025 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
2026 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
2027 return;
2028
2029 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002030
2031 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
2032 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002033 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002034 I40E_SUCCESS, (u8 *)&pfe,
2035 sizeof(struct i40e_virtchnl_pf_event), NULL);
2036}
2037
2038/**
2039 * i40e_ndo_set_vf_mac
2040 * @netdev: network interface device structure
2041 * @vf_id: vf identifier
2042 * @mac: mac address
2043 *
2044 * program vf mac address
2045 **/
2046int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2047{
2048 struct i40e_netdev_priv *np = netdev_priv(netdev);
2049 struct i40e_vsi *vsi = np->vsi;
2050 struct i40e_pf *pf = vsi->back;
2051 struct i40e_mac_filter *f;
2052 struct i40e_vf *vf;
2053 int ret = 0;
2054
2055 /* validate the request */
2056 if (vf_id >= pf->num_alloc_vfs) {
2057 dev_err(&pf->pdev->dev,
2058 "Invalid VF Identifier %d\n", vf_id);
2059 ret = -EINVAL;
2060 goto error_param;
2061 }
2062
2063 vf = &(pf->vf[vf_id]);
2064 vsi = pf->vsi[vf->lan_vsi_index];
2065 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2066 dev_err(&pf->pdev->dev,
2067 "Uninitialized VF %d\n", vf_id);
2068 ret = -EINVAL;
2069 goto error_param;
2070 }
2071
2072 if (!is_valid_ether_addr(mac)) {
2073 dev_err(&pf->pdev->dev,
2074 "Invalid VF ethernet address\n");
2075 ret = -EINVAL;
2076 goto error_param;
2077 }
2078
2079 /* delete the temporary mac address */
Greg Rose37cc0d22014-04-01 07:11:44 +00002080 i40e_del_filter(vsi, vf->default_lan_addr.addr, vf->port_vlan_id,
2081 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002082
Greg Rose29f71bb2014-05-20 08:01:45 +00002083 /* Delete all the filters for this VSI - we're going to kill it
2084 * anyway.
2085 */
2086 list_for_each_entry(f, &vsi->mac_filter_list, list)
2087 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002088
2089 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2090 /* program mac filter */
2091 if (i40e_sync_vsi_filters(vsi)) {
2092 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2093 ret = -EIO;
2094 goto error_param;
2095 }
Greg Rose9a173902014-05-22 06:32:02 +00002096 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002097 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002098 /* Force the VF driver stop so it has to reload with new MAC address */
2099 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002100 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2101 ret = 0;
2102
2103error_param:
2104 return ret;
2105}
2106
2107/**
2108 * i40e_ndo_set_vf_port_vlan
2109 * @netdev: network interface device structure
2110 * @vf_id: vf identifier
2111 * @vlan_id: mac address
2112 * @qos: priority setting
2113 *
2114 * program vf vlan id and/or qos
2115 **/
2116int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2117 int vf_id, u16 vlan_id, u8 qos)
2118{
2119 struct i40e_netdev_priv *np = netdev_priv(netdev);
2120 struct i40e_pf *pf = np->vsi->back;
2121 struct i40e_vsi *vsi;
2122 struct i40e_vf *vf;
2123 int ret = 0;
2124
2125 /* validate the request */
2126 if (vf_id >= pf->num_alloc_vfs) {
2127 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2128 ret = -EINVAL;
2129 goto error_pvid;
2130 }
2131
2132 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2133 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2134 ret = -EINVAL;
2135 goto error_pvid;
2136 }
2137
2138 vf = &(pf->vf[vf_id]);
2139 vsi = pf->vsi[vf->lan_vsi_index];
2140 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2141 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2142 ret = -EINVAL;
2143 goto error_pvid;
2144 }
2145
Greg Rosef9b4b622014-03-06 09:02:28 +00002146 if (vsi->info.pvid == 0 && i40e_is_vsi_in_vlan(vsi)) {
Greg Rose99a49732014-01-13 16:13:03 -08002147 dev_err(&pf->pdev->dev,
2148 "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",
2149 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002150 /* Administrator Error - knock the VF offline until he does
2151 * the right thing by reconfiguring his network correctly
2152 * and then reloading the VF driver.
2153 */
2154 i40e_vc_disable_vf(pf, vf);
2155 }
Greg Rose99a49732014-01-13 16:13:03 -08002156
Greg Rose8d82a7c2014-01-13 16:13:04 -08002157 /* Check for condition where there was already a port VLAN ID
2158 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002159 * Additionally check for the condition where there was a port
2160 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002161 * Before deleting all the old VLAN filters we must add new ones
2162 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2163 * MAC addresses deleted.
2164 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002165 if ((!(vlan_id || qos) ||
2166 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2167 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002168 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2169
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002170 if (vsi->info.pvid) {
2171 /* kill old VLAN */
2172 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2173 VLAN_VID_MASK));
2174 if (ret) {
2175 dev_info(&vsi->back->pdev->dev,
2176 "remove VLAN failed, ret=%d, aq_err=%d\n",
2177 ret, pf->hw.aq.asq_last_status);
2178 }
2179 }
2180 if (vlan_id || qos)
2181 ret = i40e_vsi_add_pvid(vsi,
2182 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2183 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002184 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002185
2186 if (vlan_id) {
2187 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2188 vlan_id, qos, vf_id);
2189
2190 /* add new VLAN filter */
2191 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2192 if (ret) {
2193 dev_info(&vsi->back->pdev->dev,
2194 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2195 vsi->back->hw.aq.asq_last_status);
2196 goto error_pvid;
2197 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002198 /* Kill non-vlan MAC filters - ignore error return since
2199 * there might not be any non-vlan MAC filters.
2200 */
2201 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002202 }
2203
2204 if (ret) {
2205 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2206 goto error_pvid;
2207 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002208 /* The Port VLAN needs to be saved across resets the same as the
2209 * default LAN MAC address.
2210 */
2211 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002212 ret = 0;
2213
2214error_pvid:
2215 return ret;
2216}
2217
Mitch Williams84590fd2014-04-09 05:58:57 +00002218#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2219#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002220/**
2221 * i40e_ndo_set_vf_bw
2222 * @netdev: network interface device structure
2223 * @vf_id: vf identifier
2224 * @tx_rate: tx rate
2225 *
2226 * configure vf tx rate
2227 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002228int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2229 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002230{
Mitch Williams6b192892014-03-06 09:02:29 +00002231 struct i40e_netdev_priv *np = netdev_priv(netdev);
2232 struct i40e_pf *pf = np->vsi->back;
2233 struct i40e_vsi *vsi;
2234 struct i40e_vf *vf;
2235 int speed = 0;
2236 int ret = 0;
2237
2238 /* validate the request */
2239 if (vf_id >= pf->num_alloc_vfs) {
2240 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2241 ret = -EINVAL;
2242 goto error;
2243 }
2244
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002245 if (min_tx_rate) {
2246 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for vf %d.\n",
2247 min_tx_rate, vf_id);
2248 return -EINVAL;
2249 }
2250
Mitch Williams6b192892014-03-06 09:02:29 +00002251 vf = &(pf->vf[vf_id]);
2252 vsi = pf->vsi[vf->lan_vsi_index];
2253 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2254 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2255 ret = -EINVAL;
2256 goto error;
2257 }
2258
2259 switch (pf->hw.phy.link_info.link_speed) {
2260 case I40E_LINK_SPEED_40GB:
2261 speed = 40000;
2262 break;
2263 case I40E_LINK_SPEED_10GB:
2264 speed = 10000;
2265 break;
2266 case I40E_LINK_SPEED_1GB:
2267 speed = 1000;
2268 break;
2269 default:
2270 break;
2271 }
2272
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002273 if (max_tx_rate > speed) {
2274 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for vf %d.",
2275 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002276 ret = -EINVAL;
2277 goto error;
2278 }
2279
Mitch Williamsdac9b312014-04-09 05:58:56 +00002280 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2281 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2282 max_tx_rate = 50;
2283 }
2284
Mitch Williams6b192892014-03-06 09:02:29 +00002285 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002286 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2287 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2288 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002289 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002290 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002291 ret);
2292 ret = -EIO;
2293 goto error;
2294 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002295 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002296error:
2297 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002298}
2299
2300/**
2301 * i40e_ndo_get_vf_config
2302 * @netdev: network interface device structure
2303 * @vf_id: vf identifier
2304 * @ivi: vf configuration structure
2305 *
2306 * return vf configuration
2307 **/
2308int i40e_ndo_get_vf_config(struct net_device *netdev,
2309 int vf_id, struct ifla_vf_info *ivi)
2310{
2311 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002312 struct i40e_vsi *vsi = np->vsi;
2313 struct i40e_pf *pf = vsi->back;
2314 struct i40e_vf *vf;
2315 int ret = 0;
2316
2317 /* validate the request */
2318 if (vf_id >= pf->num_alloc_vfs) {
2319 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2320 ret = -EINVAL;
2321 goto error_param;
2322 }
2323
2324 vf = &(pf->vf[vf_id]);
2325 /* first vsi is always the LAN vsi */
2326 vsi = pf->vsi[vf->lan_vsi_index];
2327 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2328 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2329 ret = -EINVAL;
2330 goto error_param;
2331 }
2332
2333 ivi->vf = vf_id;
2334
Mitch Williamsf4a1c5c2013-11-28 06:39:34 +00002335 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002336
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002337 ivi->max_tx_rate = vf->tx_rate;
2338 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002339 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2340 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2341 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00002342 if (vf->link_forced == false)
2343 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2344 else if (vf->link_up == true)
2345 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2346 else
2347 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00002348 ivi->spoofchk = vf->spoofchk;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002349 ret = 0;
2350
2351error_param:
2352 return ret;
2353}
Mitch Williams588aefa2014-02-11 08:27:49 +00002354
2355/**
2356 * i40e_ndo_set_vf_link_state
2357 * @netdev: network interface device structure
2358 * @vf_id: vf identifier
2359 * @link: required link state
2360 *
2361 * Set the link state of a specified VF, regardless of physical link state
2362 **/
2363int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2364{
2365 struct i40e_netdev_priv *np = netdev_priv(netdev);
2366 struct i40e_pf *pf = np->vsi->back;
2367 struct i40e_virtchnl_pf_event pfe;
2368 struct i40e_hw *hw = &pf->hw;
2369 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002370 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002371 int ret = 0;
2372
2373 /* validate the request */
2374 if (vf_id >= pf->num_alloc_vfs) {
2375 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2376 ret = -EINVAL;
2377 goto error_out;
2378 }
2379
2380 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07002381 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002382
2383 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2384 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2385
2386 switch (link) {
2387 case IFLA_VF_LINK_STATE_AUTO:
2388 vf->link_forced = false;
2389 pfe.event_data.link_event.link_status =
2390 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2391 pfe.event_data.link_event.link_speed =
2392 pf->hw.phy.link_info.link_speed;
2393 break;
2394 case IFLA_VF_LINK_STATE_ENABLE:
2395 vf->link_forced = true;
2396 vf->link_up = true;
2397 pfe.event_data.link_event.link_status = true;
2398 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2399 break;
2400 case IFLA_VF_LINK_STATE_DISABLE:
2401 vf->link_forced = true;
2402 vf->link_up = false;
2403 pfe.event_data.link_event.link_status = false;
2404 pfe.event_data.link_event.link_speed = 0;
2405 break;
2406 default:
2407 ret = -EINVAL;
2408 goto error_out;
2409 }
2410 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07002411 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00002412 0, (u8 *)&pfe, sizeof(pfe), NULL);
2413
2414error_out:
2415 return ret;
2416}
Mitch Williamsc674d122014-05-20 08:01:40 +00002417
2418/**
2419 * i40e_ndo_set_vf_spoofchk
2420 * @netdev: network interface device structure
2421 * @vf_id: vf identifier
2422 * @enable: flag to enable or disable feature
2423 *
2424 * Enable or disable VF spoof checking
2425 **/
Serey Konge6d90042014-07-12 07:28:14 +00002426int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00002427{
2428 struct i40e_netdev_priv *np = netdev_priv(netdev);
2429 struct i40e_vsi *vsi = np->vsi;
2430 struct i40e_pf *pf = vsi->back;
2431 struct i40e_vsi_context ctxt;
2432 struct i40e_hw *hw = &pf->hw;
2433 struct i40e_vf *vf;
2434 int ret = 0;
2435
2436 /* validate the request */
2437 if (vf_id >= pf->num_alloc_vfs) {
2438 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2439 ret = -EINVAL;
2440 goto out;
2441 }
2442
2443 vf = &(pf->vf[vf_id]);
2444
2445 if (enable == vf->spoofchk)
2446 goto out;
2447
2448 vf->spoofchk = enable;
2449 memset(&ctxt, 0, sizeof(ctxt));
2450 ctxt.seid = pf->vsi[vf->lan_vsi_index]->seid;
2451 ctxt.pf_num = pf->hw.pf_id;
2452 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2453 if (enable)
2454 ctxt.info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
2455 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2456 if (ret) {
2457 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
2458 ret);
2459 ret = -EIO;
2460 }
2461out:
2462 return ret;
2463}