blob: 5450b9f1aa3a3e8cc635f17269f0b60d5c027203 [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
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000650 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
651 return;
652
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000653 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000654 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
655
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000656 /* In the case of a VFLR, the HW has already reset the VF and we
657 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000658 */
659 if (!flr) {
660 /* reset vf using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000661 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
662 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000663 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
664 i40e_flush(hw);
665 }
666
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000667 if (i40e_quiesce_vf_pci(vf))
668 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
669 vf->vf_id);
670
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000671 /* poll VPGEN_VFRSTAT reg to make sure
672 * that reset is complete
673 */
Mitch Williams1750a222015-01-09 11:18:13 +0000674 for (i = 0; i < 10; i++) {
675 /* VF reset requires driver to first reset the VF and then
676 * poll the status register to make sure that the reset
677 * completed successfully. Due to internal HW FIFO flushes,
678 * we must wait 10ms before the register will be valid.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000679 */
Mitch Williams1750a222015-01-09 11:18:13 +0000680 usleep_range(10000, 20000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000681 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
682 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
683 rsd = true;
684 break;
685 }
686 }
687
688 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000689 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000690 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000691 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000692 /* clear the reset bit in the VPGEN_VFRTRIG reg */
693 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
694 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
695 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000696
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000697 /* On initial reset, we won't have any queues */
698 if (vf->lan_vsi_index == 0)
699 goto complete_reset;
700
701 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_index], false);
702complete_reset:
703 /* reallocate vf resources to reset the VSI state */
704 i40e_free_vf_res(vf);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000705 i40e_alloc_vf_res(vf);
706 i40e_enable_vf_mappings(vf);
Mitch Williamsc17b3622014-02-13 03:48:45 -0800707 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000708
709 /* tell the VF the reset is done */
710 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
711 i40e_flush(hw);
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000712 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000713}
Greg Rosec3542292013-12-13 08:38:38 +0000714
715/**
716 * i40e_enable_pf_switch_lb
717 * @pf: pointer to the pf structure
718 *
719 * enable switch loop back or die - no point in a return value
720 **/
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +0000721void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
Greg Rosec3542292013-12-13 08:38:38 +0000722{
723 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
724 struct i40e_vsi_context ctxt;
725 int aq_ret;
726
727 ctxt.seid = pf->main_vsi_seid;
728 ctxt.pf_num = pf->hw.pf_id;
729 ctxt.vf_num = 0;
730 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
731 if (aq_ret) {
732 dev_info(&pf->pdev->dev,
733 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
734 __func__, aq_ret, pf->hw.aq.asq_last_status);
735 return;
736 }
737 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
738 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
739 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
740
741 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
742 if (aq_ret) {
743 dev_info(&pf->pdev->dev,
744 "%s: update vsi switch failed, aq_err=%d\n",
745 __func__, vsi->back->hw.aq.asq_last_status);
746 }
747}
Greg Rosec3542292013-12-13 08:38:38 +0000748
749/**
750 * i40e_disable_pf_switch_lb
751 * @pf: pointer to the pf structure
752 *
753 * disable switch loop back or die - no point in a return value
754 **/
755static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
756{
757 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
758 struct i40e_vsi_context ctxt;
759 int aq_ret;
760
761 ctxt.seid = pf->main_vsi_seid;
762 ctxt.pf_num = pf->hw.pf_id;
763 ctxt.vf_num = 0;
764 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
765 if (aq_ret) {
766 dev_info(&pf->pdev->dev,
767 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
768 __func__, aq_ret, pf->hw.aq.asq_last_status);
769 return;
770 }
771 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
772 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
773 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
774
775 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
776 if (aq_ret) {
777 dev_info(&pf->pdev->dev,
778 "%s: update vsi switch failed, aq_err=%d\n",
779 __func__, vsi->back->hw.aq.asq_last_status);
780 }
781}
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000782
783/**
784 * i40e_free_vfs
785 * @pf: pointer to the pf structure
786 *
787 * free vf resources
788 **/
789void i40e_free_vfs(struct i40e_pf *pf)
790{
Mitch Williamsf7414532013-11-28 06:39:40 +0000791 struct i40e_hw *hw = &pf->hw;
792 u32 reg_idx, bit_idx;
793 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000794
795 if (!pf->vf)
796 return;
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000797 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
798 usleep_range(1000, 2000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000799
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000800 /* Disable IOV before freeing resources. This lets any VF drivers
801 * running in the host get themselves cleaned up before we yank
802 * the carpet out from underneath their feet.
803 */
804 if (!pci_vfs_assigned(pf->pdev))
805 pci_disable_sriov(pf->pdev);
806
807 msleep(20); /* let any messages in transit get finished up */
808
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000809 /* free up vf resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000810 tmp = pf->num_alloc_vfs;
811 pf->num_alloc_vfs = 0;
812 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000813 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
814 i40e_free_vf_res(&pf->vf[i]);
815 /* disable qp mappings */
816 i40e_disable_vf_mappings(&pf->vf[i]);
817 }
818
819 kfree(pf->vf);
820 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000821
Mitch Williams9e5634d2014-04-04 04:43:14 +0000822 /* This check is for when the driver is unloaded while VFs are
823 * assigned. Setting the number of VFs to 0 through sysfs is caught
824 * before this function ever gets called.
825 */
Ethan Zhaoc24817b2014-07-22 18:36:43 +0000826 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williamsf7414532013-11-28 06:39:40 +0000827 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
828 * work correctly when SR-IOV gets re-enabled.
829 */
830 for (vf_id = 0; vf_id < tmp; vf_id++) {
831 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
832 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
833 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
834 }
Greg Rosec3542292013-12-13 08:38:38 +0000835 i40e_disable_pf_switch_lb(pf);
836 } else {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000837 dev_warn(&pf->pdev->dev,
838 "unable to disable SR-IOV because VFs are assigned.\n");
Greg Rosec3542292013-12-13 08:38:38 +0000839 }
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000840 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000841}
842
843#ifdef CONFIG_PCI_IOV
844/**
845 * i40e_alloc_vfs
846 * @pf: pointer to the pf structure
847 * @num_alloc_vfs: number of vfs to allocate
848 *
849 * allocate vf resources
850 **/
Mitch Williams4aeec012014-02-13 03:48:47 -0800851int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000852{
853 struct i40e_vf *vfs;
854 int i, ret = 0;
855
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000856 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000857 i40e_irq_dynamic_disable_icr0(pf);
858
Mitch Williams4aeec012014-02-13 03:48:47 -0800859 /* Check to see if we're just allocating resources for extant VFs */
860 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
861 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
862 if (ret) {
863 dev_err(&pf->pdev->dev,
864 "Failed to enable SR-IOV, error %d.\n", ret);
865 pf->num_alloc_vfs = 0;
866 goto err_iov;
867 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000868 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000869 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +0000870 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000871 if (!vfs) {
872 ret = -ENOMEM;
873 goto err_alloc;
874 }
Mitch Williamsc674d122014-05-20 08:01:40 +0000875 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000876
877 /* apply default profile */
878 for (i = 0; i < num_alloc_vfs; i++) {
879 vfs[i].pf = pf;
880 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
881 vfs[i].vf_id = i;
882
883 /* assign default capabilities */
884 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +0000885 vfs[i].spoofchk = true;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000886 /* vf resources get allocated during reset */
887 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000888
889 /* enable vf vplan_qtable mappings */
890 i40e_enable_vf_mappings(&vfs[i]);
891 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000892 pf->num_alloc_vfs = num_alloc_vfs;
893
Greg Rosec3542292013-12-13 08:38:38 +0000894 i40e_enable_pf_switch_lb(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000895err_alloc:
896 if (ret)
897 i40e_free_vfs(pf);
898err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000899 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000900 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000901 return ret;
902}
903
904#endif
905/**
906 * i40e_pci_sriov_enable
907 * @pdev: pointer to a pci_dev structure
908 * @num_vfs: number of vfs to allocate
909 *
910 * Enable or change the number of VFs
911 **/
912static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
913{
914#ifdef CONFIG_PCI_IOV
915 struct i40e_pf *pf = pci_get_drvdata(pdev);
916 int pre_existing_vfs = pci_num_vf(pdev);
917 int err = 0;
918
919 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
920 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
921 i40e_free_vfs(pf);
922 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
923 goto out;
924
925 if (num_vfs > pf->num_req_vfs) {
926 err = -EPERM;
927 goto err_out;
928 }
929
930 err = i40e_alloc_vfs(pf, num_vfs);
931 if (err) {
932 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
933 goto err_out;
934 }
935
936out:
937 return num_vfs;
938
939err_out:
940 return err;
941#endif
942 return 0;
943}
944
945/**
946 * i40e_pci_sriov_configure
947 * @pdev: pointer to a pci_dev structure
948 * @num_vfs: number of vfs to allocate
949 *
950 * Enable or change the number of VFs. Called when the user updates the number
951 * of VFs in sysfs.
952 **/
953int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
954{
955 struct i40e_pf *pf = pci_get_drvdata(pdev);
956
957 if (num_vfs)
958 return i40e_pci_sriov_enable(pdev, num_vfs);
959
Ethan Zhaoc24817b2014-07-22 18:36:43 +0000960 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williams9e5634d2014-04-04 04:43:14 +0000961 i40e_free_vfs(pf);
962 } else {
963 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
964 return -EINVAL;
965 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000966 return 0;
967}
968
969/***********************virtual channel routines******************/
970
971/**
972 * i40e_vc_send_msg_to_vf
973 * @vf: pointer to the vf info
974 * @v_opcode: virtual channel opcode
975 * @v_retval: virtual channel return value
976 * @msg: pointer to the msg buffer
977 * @msglen: msg length
978 *
979 * send msg to vf
980 **/
981static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
982 u32 v_retval, u8 *msg, u16 msglen)
983{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +0000984 struct i40e_pf *pf;
985 struct i40e_hw *hw;
986 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000987 i40e_status aq_ret;
988
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +0000989 /* validate the request */
990 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
991 return -EINVAL;
992
993 pf = vf->pf;
994 hw = &pf->hw;
995 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
996
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000997 /* single place to detect unsuccessful return values */
998 if (v_retval) {
999 vf->num_invalid_msgs++;
1000 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1001 v_opcode, v_retval);
1002 if (vf->num_invalid_msgs >
1003 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1004 dev_err(&pf->pdev->dev,
1005 "Number of invalid messages exceeded for VF %d\n",
1006 vf->vf_id);
1007 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1008 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1009 }
1010 } else {
1011 vf->num_valid_msgs++;
1012 }
1013
Ashish Shahf19efbb2014-08-01 13:27:06 -07001014 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001015 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001016 if (aq_ret) {
1017 dev_err(&pf->pdev->dev,
1018 "Unable to send the message to VF %d aq_err %d\n",
1019 vf->vf_id, pf->hw.aq.asq_last_status);
1020 return -EIO;
1021 }
1022
1023 return 0;
1024}
1025
1026/**
1027 * i40e_vc_send_resp_to_vf
1028 * @vf: pointer to the vf info
1029 * @opcode: operation code
1030 * @retval: return value
1031 *
1032 * send resp msg to vf
1033 **/
1034static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1035 enum i40e_virtchnl_ops opcode,
1036 i40e_status retval)
1037{
1038 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1039}
1040
1041/**
1042 * i40e_vc_get_version_msg
1043 * @vf: pointer to the vf info
1044 *
1045 * called from the vf to request the API version used by the PF
1046 **/
1047static int i40e_vc_get_version_msg(struct i40e_vf *vf)
1048{
1049 struct i40e_virtchnl_version_info info = {
1050 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1051 };
1052
1053 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1054 I40E_SUCCESS, (u8 *)&info,
1055 sizeof(struct
1056 i40e_virtchnl_version_info));
1057}
1058
1059/**
1060 * i40e_vc_get_vf_resources_msg
1061 * @vf: pointer to the vf info
1062 * @msg: pointer to the msg buffer
1063 * @msglen: msg length
1064 *
1065 * called from the vf to request its resources
1066 **/
1067static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf)
1068{
1069 struct i40e_virtchnl_vf_resource *vfres = NULL;
1070 struct i40e_pf *pf = vf->pf;
1071 i40e_status aq_ret = 0;
1072 struct i40e_vsi *vsi;
1073 int i = 0, len = 0;
1074 int num_vsis = 1;
1075 int ret;
1076
1077 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1078 aq_ret = I40E_ERR_PARAM;
1079 goto err;
1080 }
1081
1082 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1083 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1084
1085 vfres = kzalloc(len, GFP_KERNEL);
1086 if (!vfres) {
1087 aq_ret = I40E_ERR_NO_MEMORY;
1088 len = 0;
1089 goto err;
1090 }
1091
1092 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1093 vsi = pf->vsi[vf->lan_vsi_index];
1094 if (!vsi->info.pvid)
1095 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1096
1097 vfres->num_vsis = num_vsis;
1098 vfres->num_queue_pairs = vf->num_queue_pairs;
1099 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1100 if (vf->lan_vsi_index) {
1101 vfres->vsi_res[i].vsi_id = vf->lan_vsi_index;
1102 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1103 vfres->vsi_res[i].num_queue_pairs =
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001104 pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001105 memcpy(vfres->vsi_res[i].default_mac_addr,
1106 vf->default_lan_addr.addr, ETH_ALEN);
1107 i++;
1108 }
1109 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1110
1111err:
1112 /* send the response back to the vf */
1113 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1114 aq_ret, (u8 *)vfres, len);
1115
1116 kfree(vfres);
1117 return ret;
1118}
1119
1120/**
1121 * i40e_vc_reset_vf_msg
1122 * @vf: pointer to the vf info
1123 * @msg: pointer to the msg buffer
1124 * @msglen: msg length
1125 *
1126 * called from the vf to reset itself,
1127 * unlike other virtchnl messages, pf driver
1128 * doesn't send the response back to the vf
1129 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001130static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001131{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001132 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1133 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001134}
1135
1136/**
1137 * i40e_vc_config_promiscuous_mode_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 configure the promiscuous mode of
1143 * vf vsis
1144 **/
1145static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1146 u8 *msg, u16 msglen)
1147{
1148 struct i40e_virtchnl_promisc_info *info =
1149 (struct i40e_virtchnl_promisc_info *)msg;
1150 struct i40e_pf *pf = vf->pf;
1151 struct i40e_hw *hw = &pf->hw;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001152 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001153 bool allmulti = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001154 i40e_status aq_ret;
1155
1156 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1157 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1158 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1159 (pf->vsi[info->vsi_id]->type != I40E_VSI_FCOE)) {
1160 aq_ret = I40E_ERR_PARAM;
1161 goto error_param;
1162 }
Ashish Shah89cb86c2014-08-01 13:27:10 -07001163 vsi = pf->vsi[info->vsi_id];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001164 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1165 allmulti = true;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001166 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001167 allmulti, NULL);
1168
1169error_param:
1170 /* send the response to the vf */
1171 return i40e_vc_send_resp_to_vf(vf,
1172 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1173 aq_ret);
1174}
1175
1176/**
1177 * i40e_vc_config_queues_msg
1178 * @vf: pointer to the vf info
1179 * @msg: pointer to the msg buffer
1180 * @msglen: msg length
1181 *
1182 * called from the vf to configure the rx/tx
1183 * queues
1184 **/
1185static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1186{
1187 struct i40e_virtchnl_vsi_queue_config_info *qci =
1188 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1189 struct i40e_virtchnl_queue_pair_info *qpi;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001190 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001191 u16 vsi_id, vsi_queue_id;
1192 i40e_status aq_ret = 0;
1193 int i;
1194
1195 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1196 aq_ret = I40E_ERR_PARAM;
1197 goto error_param;
1198 }
1199
1200 vsi_id = qci->vsi_id;
1201 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1202 aq_ret = I40E_ERR_PARAM;
1203 goto error_param;
1204 }
1205 for (i = 0; i < qci->num_queue_pairs; i++) {
1206 qpi = &qci->qpair[i];
1207 vsi_queue_id = qpi->txq.queue_id;
1208 if ((qpi->txq.vsi_id != vsi_id) ||
1209 (qpi->rxq.vsi_id != vsi_id) ||
1210 (qpi->rxq.queue_id != vsi_queue_id) ||
1211 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1212 aq_ret = I40E_ERR_PARAM;
1213 goto error_param;
1214 }
1215
1216 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1217 &qpi->rxq) ||
1218 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1219 &qpi->txq)) {
1220 aq_ret = I40E_ERR_PARAM;
1221 goto error_param;
1222 }
1223 }
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001224 /* set vsi num_queue_pairs in use to num configured by vf */
1225 pf->vsi[vf->lan_vsi_index]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001226
1227error_param:
1228 /* send the response to the vf */
1229 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1230 aq_ret);
1231}
1232
1233/**
1234 * i40e_vc_config_irq_map_msg
1235 * @vf: pointer to the vf info
1236 * @msg: pointer to the msg buffer
1237 * @msglen: msg length
1238 *
1239 * called from the vf to configure the irq to
1240 * queue map
1241 **/
1242static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1243{
1244 struct i40e_virtchnl_irq_map_info *irqmap_info =
1245 (struct i40e_virtchnl_irq_map_info *)msg;
1246 struct i40e_virtchnl_vector_map *map;
1247 u16 vsi_id, vsi_queue_id, vector_id;
1248 i40e_status aq_ret = 0;
1249 unsigned long tempmap;
1250 int i;
1251
1252 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1253 aq_ret = I40E_ERR_PARAM;
1254 goto error_param;
1255 }
1256
1257 for (i = 0; i < irqmap_info->num_vectors; i++) {
1258 map = &irqmap_info->vecmap[i];
1259
1260 vector_id = map->vector_id;
1261 vsi_id = map->vsi_id;
1262 /* validate msg params */
1263 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1264 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1265 aq_ret = I40E_ERR_PARAM;
1266 goto error_param;
1267 }
1268
1269 /* lookout for the invalid queue index */
1270 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001271 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001272 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1273 vsi_queue_id)) {
1274 aq_ret = I40E_ERR_PARAM;
1275 goto error_param;
1276 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001277 }
1278
1279 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001280 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001281 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1282 vsi_queue_id)) {
1283 aq_ret = I40E_ERR_PARAM;
1284 goto error_param;
1285 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001286 }
1287
1288 i40e_config_irq_link_list(vf, vsi_id, map);
1289 }
1290error_param:
1291 /* send the response to the vf */
1292 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1293 aq_ret);
1294}
1295
1296/**
1297 * i40e_vc_enable_queues_msg
1298 * @vf: pointer to the vf info
1299 * @msg: pointer to the msg buffer
1300 * @msglen: msg length
1301 *
1302 * called from the vf to enable all or specific queue(s)
1303 **/
1304static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1305{
1306 struct i40e_virtchnl_queue_select *vqs =
1307 (struct i40e_virtchnl_queue_select *)msg;
1308 struct i40e_pf *pf = vf->pf;
1309 u16 vsi_id = vqs->vsi_id;
1310 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001311
1312 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1313 aq_ret = I40E_ERR_PARAM;
1314 goto error_param;
1315 }
1316
1317 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1318 aq_ret = I40E_ERR_PARAM;
1319 goto error_param;
1320 }
1321
1322 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1323 aq_ret = I40E_ERR_PARAM;
1324 goto error_param;
1325 }
Mitch Williams88f65632013-11-28 06:39:28 +00001326 if (i40e_vsi_control_rings(pf->vsi[vsi_id], true))
1327 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001328error_param:
1329 /* send the response to the vf */
1330 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1331 aq_ret);
1332}
1333
1334/**
1335 * i40e_vc_disable_queues_msg
1336 * @vf: pointer to the vf info
1337 * @msg: pointer to the msg buffer
1338 * @msglen: msg length
1339 *
1340 * called from the vf to disable all or specific
1341 * queue(s)
1342 **/
1343static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1344{
1345 struct i40e_virtchnl_queue_select *vqs =
1346 (struct i40e_virtchnl_queue_select *)msg;
1347 struct i40e_pf *pf = vf->pf;
1348 u16 vsi_id = vqs->vsi_id;
1349 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001350
1351 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1352 aq_ret = I40E_ERR_PARAM;
1353 goto error_param;
1354 }
1355
1356 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1357 aq_ret = I40E_ERR_PARAM;
1358 goto error_param;
1359 }
1360
1361 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1362 aq_ret = I40E_ERR_PARAM;
1363 goto error_param;
1364 }
Mitch Williams88f65632013-11-28 06:39:28 +00001365 if (i40e_vsi_control_rings(pf->vsi[vsi_id], false))
1366 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001367
1368error_param:
1369 /* send the response to the vf */
1370 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1371 aq_ret);
1372}
1373
1374/**
1375 * i40e_vc_get_stats_msg
1376 * @vf: pointer to the vf info
1377 * @msg: pointer to the msg buffer
1378 * @msglen: msg length
1379 *
1380 * called from the vf to get vsi stats
1381 **/
1382static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1383{
1384 struct i40e_virtchnl_queue_select *vqs =
1385 (struct i40e_virtchnl_queue_select *)msg;
1386 struct i40e_pf *pf = vf->pf;
1387 struct i40e_eth_stats stats;
1388 i40e_status aq_ret = 0;
1389 struct i40e_vsi *vsi;
1390
1391 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1392
1393 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1394 aq_ret = I40E_ERR_PARAM;
1395 goto error_param;
1396 }
1397
1398 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1399 aq_ret = I40E_ERR_PARAM;
1400 goto error_param;
1401 }
1402
1403 vsi = pf->vsi[vqs->vsi_id];
1404 if (!vsi) {
1405 aq_ret = I40E_ERR_PARAM;
1406 goto error_param;
1407 }
1408 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001409 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001410
1411error_param:
1412 /* send the response back to the vf */
1413 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1414 (u8 *)&stats, sizeof(stats));
1415}
1416
1417/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001418 * i40e_check_vf_permission
1419 * @vf: pointer to the vf info
1420 * @macaddr: pointer to the MAC Address being checked
1421 *
1422 * Check if the VF has permission to add or delete unicast MAC address
1423 * filters and return error code -EPERM if not. Then check if the
1424 * address filter requested is broadcast or zero and if so return
1425 * an invalid MAC address error code.
1426 **/
1427static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1428{
1429 struct i40e_pf *pf = vf->pf;
1430 int ret = 0;
1431
1432 if (is_broadcast_ether_addr(macaddr) ||
1433 is_zero_ether_addr(macaddr)) {
1434 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1435 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001436 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1437 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001438 /* If the host VMM administrator has set the VF MAC address
1439 * administratively via the ndo_set_vf_mac command then deny
1440 * permission to the VF to add or delete unicast MAC addresses.
Greg Rose5017c2a2013-12-07 10:36:54 +00001441 * The VF may request to set the MAC address filter already
1442 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001443 */
1444 dev_err(&pf->pdev->dev,
1445 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1446 ret = -EPERM;
1447 }
1448 return ret;
1449}
1450
1451/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001452 * i40e_vc_add_mac_addr_msg
1453 * @vf: pointer to the vf info
1454 * @msg: pointer to the msg buffer
1455 * @msglen: msg length
1456 *
1457 * add guest mac address filter
1458 **/
1459static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1460{
1461 struct i40e_virtchnl_ether_addr_list *al =
1462 (struct i40e_virtchnl_ether_addr_list *)msg;
1463 struct i40e_pf *pf = vf->pf;
1464 struct i40e_vsi *vsi = NULL;
1465 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001466 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001467 int i;
1468
1469 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1470 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1471 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001472 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001473 goto error_param;
1474 }
1475
1476 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001477 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1478 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001479 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001480 }
1481 vsi = pf->vsi[vsi_id];
1482
1483 /* add new addresses to the list */
1484 for (i = 0; i < al->num_elements; i++) {
1485 struct i40e_mac_filter *f;
1486
1487 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001488 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001489 if (i40e_is_vsi_in_vlan(vsi))
1490 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1491 true, false);
1492 else
1493 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1494 true, false);
1495 }
1496
1497 if (!f) {
1498 dev_err(&pf->pdev->dev,
1499 "Unable to add VF MAC filter\n");
Greg Rosef657a6e2013-11-28 06:39:42 +00001500 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001501 goto error_param;
1502 }
1503 }
1504
1505 /* program the updated filter list */
1506 if (i40e_sync_vsi_filters(vsi))
1507 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1508
1509error_param:
1510 /* send the response to the vf */
1511 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001512 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001513}
1514
1515/**
1516 * i40e_vc_del_mac_addr_msg
1517 * @vf: pointer to the vf info
1518 * @msg: pointer to the msg buffer
1519 * @msglen: msg length
1520 *
1521 * remove guest mac address filter
1522 **/
1523static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1524{
1525 struct i40e_virtchnl_ether_addr_list *al =
1526 (struct i40e_virtchnl_ether_addr_list *)msg;
1527 struct i40e_pf *pf = vf->pf;
1528 struct i40e_vsi *vsi = NULL;
1529 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001530 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001531 int i;
1532
1533 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1534 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1535 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001536 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001537 goto error_param;
1538 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001539
1540 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00001541 if (is_broadcast_ether_addr(al->list[i].addr) ||
1542 is_zero_ether_addr(al->list[i].addr)) {
1543 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1544 al->list[i].addr);
1545 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00001546 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00001547 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001548 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001549 vsi = pf->vsi[vsi_id];
1550
1551 /* delete addresses from the list */
1552 for (i = 0; i < al->num_elements; i++)
1553 i40e_del_filter(vsi, al->list[i].addr,
1554 I40E_VLAN_ANY, true, false);
1555
1556 /* program the updated filter list */
1557 if (i40e_sync_vsi_filters(vsi))
1558 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1559
1560error_param:
1561 /* send the response to the vf */
1562 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001563 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001564}
1565
1566/**
1567 * i40e_vc_add_vlan_msg
1568 * @vf: pointer to the vf info
1569 * @msg: pointer to the msg buffer
1570 * @msglen: msg length
1571 *
1572 * program guest vlan id
1573 **/
1574static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1575{
1576 struct i40e_virtchnl_vlan_filter_list *vfl =
1577 (struct i40e_virtchnl_vlan_filter_list *)msg;
1578 struct i40e_pf *pf = vf->pf;
1579 struct i40e_vsi *vsi = NULL;
1580 u16 vsi_id = vfl->vsi_id;
1581 i40e_status aq_ret = 0;
1582 int i;
1583
1584 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1585 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1586 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1587 aq_ret = I40E_ERR_PARAM;
1588 goto error_param;
1589 }
1590
1591 for (i = 0; i < vfl->num_elements; i++) {
1592 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1593 aq_ret = I40E_ERR_PARAM;
1594 dev_err(&pf->pdev->dev,
1595 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1596 goto error_param;
1597 }
1598 }
1599 vsi = pf->vsi[vsi_id];
1600 if (vsi->info.pvid) {
1601 aq_ret = I40E_ERR_PARAM;
1602 goto error_param;
1603 }
1604
1605 i40e_vlan_stripping_enable(vsi);
1606 for (i = 0; i < vfl->num_elements; i++) {
1607 /* add new VLAN filter */
1608 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1609 if (ret)
1610 dev_err(&pf->pdev->dev,
1611 "Unable to add VF vlan filter %d, error %d\n",
1612 vfl->vlan_id[i], ret);
1613 }
1614
1615error_param:
1616 /* send the response to the vf */
1617 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1618}
1619
1620/**
1621 * i40e_vc_remove_vlan_msg
1622 * @vf: pointer to the vf info
1623 * @msg: pointer to the msg buffer
1624 * @msglen: msg length
1625 *
1626 * remove programmed guest vlan id
1627 **/
1628static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1629{
1630 struct i40e_virtchnl_vlan_filter_list *vfl =
1631 (struct i40e_virtchnl_vlan_filter_list *)msg;
1632 struct i40e_pf *pf = vf->pf;
1633 struct i40e_vsi *vsi = NULL;
1634 u16 vsi_id = vfl->vsi_id;
1635 i40e_status aq_ret = 0;
1636 int i;
1637
1638 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1639 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1640 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1641 aq_ret = I40E_ERR_PARAM;
1642 goto error_param;
1643 }
1644
1645 for (i = 0; i < vfl->num_elements; i++) {
1646 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1647 aq_ret = I40E_ERR_PARAM;
1648 goto error_param;
1649 }
1650 }
1651
1652 vsi = pf->vsi[vsi_id];
1653 if (vsi->info.pvid) {
1654 aq_ret = I40E_ERR_PARAM;
1655 goto error_param;
1656 }
1657
1658 for (i = 0; i < vfl->num_elements; i++) {
1659 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1660 if (ret)
1661 dev_err(&pf->pdev->dev,
1662 "Unable to delete VF vlan filter %d, error %d\n",
1663 vfl->vlan_id[i], ret);
1664 }
1665
1666error_param:
1667 /* send the response to the vf */
1668 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1669}
1670
1671/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001672 * i40e_vc_validate_vf_msg
1673 * @vf: pointer to the vf info
1674 * @msg: pointer to the msg buffer
1675 * @msglen: msg length
1676 * @msghndl: msg handle
1677 *
1678 * validate msg
1679 **/
1680static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1681 u32 v_retval, u8 *msg, u16 msglen)
1682{
1683 bool err_msg_format = false;
1684 int valid_len;
1685
1686 /* Check if VF is disabled. */
1687 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1688 return I40E_ERR_PARAM;
1689
1690 /* Validate message length. */
1691 switch (v_opcode) {
1692 case I40E_VIRTCHNL_OP_VERSION:
1693 valid_len = sizeof(struct i40e_virtchnl_version_info);
1694 break;
1695 case I40E_VIRTCHNL_OP_RESET_VF:
1696 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1697 valid_len = 0;
1698 break;
1699 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1700 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1701 break;
1702 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1703 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1704 break;
1705 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1706 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1707 if (msglen >= valid_len) {
1708 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1709 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1710 valid_len += (vqc->num_queue_pairs *
1711 sizeof(struct
1712 i40e_virtchnl_queue_pair_info));
1713 if (vqc->num_queue_pairs == 0)
1714 err_msg_format = true;
1715 }
1716 break;
1717 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1718 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1719 if (msglen >= valid_len) {
1720 struct i40e_virtchnl_irq_map_info *vimi =
1721 (struct i40e_virtchnl_irq_map_info *)msg;
1722 valid_len += (vimi->num_vectors *
1723 sizeof(struct i40e_virtchnl_vector_map));
1724 if (vimi->num_vectors == 0)
1725 err_msg_format = true;
1726 }
1727 break;
1728 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1729 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1730 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1731 break;
1732 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1733 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1734 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1735 if (msglen >= valid_len) {
1736 struct i40e_virtchnl_ether_addr_list *veal =
1737 (struct i40e_virtchnl_ether_addr_list *)msg;
1738 valid_len += veal->num_elements *
1739 sizeof(struct i40e_virtchnl_ether_addr);
1740 if (veal->num_elements == 0)
1741 err_msg_format = true;
1742 }
1743 break;
1744 case I40E_VIRTCHNL_OP_ADD_VLAN:
1745 case I40E_VIRTCHNL_OP_DEL_VLAN:
1746 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1747 if (msglen >= valid_len) {
1748 struct i40e_virtchnl_vlan_filter_list *vfl =
1749 (struct i40e_virtchnl_vlan_filter_list *)msg;
1750 valid_len += vfl->num_elements * sizeof(u16);
1751 if (vfl->num_elements == 0)
1752 err_msg_format = true;
1753 }
1754 break;
1755 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1756 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1757 break;
1758 case I40E_VIRTCHNL_OP_GET_STATS:
1759 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1760 break;
1761 /* These are always errors coming from the VF. */
1762 case I40E_VIRTCHNL_OP_EVENT:
1763 case I40E_VIRTCHNL_OP_UNKNOWN:
1764 default:
1765 return -EPERM;
1766 break;
1767 }
1768 /* few more checks */
1769 if ((valid_len != msglen) || (err_msg_format)) {
1770 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1771 return -EINVAL;
1772 } else {
1773 return 0;
1774 }
1775}
1776
1777/**
1778 * i40e_vc_process_vf_msg
1779 * @pf: pointer to the pf structure
1780 * @vf_id: source vf id
1781 * @msg: pointer to the msg buffer
1782 * @msglen: msg length
1783 * @msghndl: msg handle
1784 *
1785 * called from the common aeq/arq handler to
1786 * process request from vf
1787 **/
1788int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1789 u32 v_retval, u8 *msg, u16 msglen)
1790{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001791 struct i40e_hw *hw = &pf->hw;
Dan Carpenterc243e962014-01-15 06:43:39 +00001792 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001793 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001794 int ret;
1795
1796 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001797 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001798 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001799 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001800 /* perform basic checks on the msg */
1801 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1802
1803 if (ret) {
Mitch Williams499ec802013-11-28 06:39:31 +00001804 dev_err(&pf->pdev->dev, "Invalid message from vf %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001805 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001806 return ret;
1807 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08001808
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001809 switch (v_opcode) {
1810 case I40E_VIRTCHNL_OP_VERSION:
1811 ret = i40e_vc_get_version_msg(vf);
1812 break;
1813 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1814 ret = i40e_vc_get_vf_resources_msg(vf);
1815 break;
1816 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001817 i40e_vc_reset_vf_msg(vf);
1818 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001819 break;
1820 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1821 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1822 break;
1823 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1824 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1825 break;
1826 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1827 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1828 break;
1829 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1830 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1831 break;
1832 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1833 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1834 break;
1835 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1836 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1837 break;
1838 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1839 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1840 break;
1841 case I40E_VIRTCHNL_OP_ADD_VLAN:
1842 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1843 break;
1844 case I40E_VIRTCHNL_OP_DEL_VLAN:
1845 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1846 break;
1847 case I40E_VIRTCHNL_OP_GET_STATS:
1848 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1849 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001850 case I40E_VIRTCHNL_OP_UNKNOWN:
1851 default:
Mitch Williams7efa84b2013-11-28 06:39:41 +00001852 dev_err(&pf->pdev->dev, "Unsupported opcode %d from vf %d\n",
1853 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001854 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1855 I40E_ERR_NOT_IMPLEMENTED);
1856 break;
1857 }
1858
1859 return ret;
1860}
1861
1862/**
1863 * i40e_vc_process_vflr_event
1864 * @pf: pointer to the pf structure
1865 *
1866 * called from the vlfr irq handler to
1867 * free up vf resources and state variables
1868 **/
1869int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1870{
1871 u32 reg, reg_idx, bit_idx, vf_id;
1872 struct i40e_hw *hw = &pf->hw;
1873 struct i40e_vf *vf;
1874
1875 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1876 return 0;
1877
Mitch Williamsc5c2f7c2014-11-11 03:15:04 +00001878 /* re-enable vflr interrupt cause */
1879 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1880 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1881 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1882 i40e_flush(hw);
1883
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001884 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1885 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1886 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1887 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1888 /* read GLGEN_VFLRSTAT register to find out the flr vfs */
1889 vf = &pf->vf[vf_id];
1890 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1891 if (reg & (1 << bit_idx)) {
1892 /* clear the bit in GLGEN_VFLRSTAT */
1893 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
1894
Mitch Williamseb2d80b2014-02-13 03:48:48 -08001895 if (!test_bit(__I40E_DOWN, &pf->state))
1896 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001897 }
1898 }
1899
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001900 return 0;
1901}
1902
1903/**
1904 * i40e_vc_vf_broadcast
1905 * @pf: pointer to the pf structure
1906 * @opcode: operation code
1907 * @retval: return value
1908 * @msg: pointer to the msg buffer
1909 * @msglen: msg length
1910 *
1911 * send a message to all VFs on a given PF
1912 **/
1913static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1914 enum i40e_virtchnl_ops v_opcode,
1915 i40e_status v_retval, u8 *msg,
1916 u16 msglen)
1917{
1918 struct i40e_hw *hw = &pf->hw;
1919 struct i40e_vf *vf = pf->vf;
1920 int i;
1921
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001922 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1923 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00001924 /* Not all vfs are enabled so skip the ones that are not */
1925 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
1926 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1927 continue;
1928
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001929 /* Ignore return value on purpose - a given VF may fail, but
1930 * we need to keep going and send to all of them
1931 */
Ashish Shahf19efbb2014-08-01 13:27:06 -07001932 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001933 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001934 }
1935}
1936
1937/**
1938 * i40e_vc_notify_link_state
1939 * @pf: pointer to the pf structure
1940 *
1941 * send a link status message to all VFs on a given PF
1942 **/
1943void i40e_vc_notify_link_state(struct i40e_pf *pf)
1944{
1945 struct i40e_virtchnl_pf_event pfe;
Mitch Williams588aefa2014-02-11 08:27:49 +00001946 struct i40e_hw *hw = &pf->hw;
1947 struct i40e_vf *vf = pf->vf;
1948 struct i40e_link_status *ls = &pf->hw.phy.link_info;
1949 int i;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001950
1951 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1952 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001953 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1954 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00001955 if (vf->link_forced) {
1956 pfe.event_data.link_event.link_status = vf->link_up;
1957 pfe.event_data.link_event.link_speed =
1958 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
1959 } else {
1960 pfe.event_data.link_event.link_status =
1961 ls->link_info & I40E_AQ_LINK_UP;
1962 pfe.event_data.link_event.link_speed = ls->link_speed;
1963 }
Ashish Shahf19efbb2014-08-01 13:27:06 -07001964 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00001965 0, (u8 *)&pfe, sizeof(pfe),
1966 NULL);
Mitch Williams588aefa2014-02-11 08:27:49 +00001967 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001968}
1969
1970/**
1971 * i40e_vc_notify_reset
1972 * @pf: pointer to the pf structure
1973 *
1974 * indicate a pending reset to all VFs on a given PF
1975 **/
1976void i40e_vc_notify_reset(struct i40e_pf *pf)
1977{
1978 struct i40e_virtchnl_pf_event pfe;
1979
1980 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
1981 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
1982 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, I40E_SUCCESS,
1983 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
1984}
1985
1986/**
1987 * i40e_vc_notify_vf_reset
1988 * @vf: pointer to the vf structure
1989 *
1990 * indicate a pending reset to the given VF
1991 **/
1992void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
1993{
1994 struct i40e_virtchnl_pf_event pfe;
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00001995 int abs_vf_id;
1996
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001997 /* validate the request */
1998 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1999 return;
2000
Anjali Singhai Jain478c9e72014-07-10 07:58:18 +00002001 /* verify if the VF is in either init or active before proceeding */
2002 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
2003 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
2004 return;
2005
2006 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002007
2008 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
2009 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002010 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002011 I40E_SUCCESS, (u8 *)&pfe,
2012 sizeof(struct i40e_virtchnl_pf_event), NULL);
2013}
2014
2015/**
2016 * i40e_ndo_set_vf_mac
2017 * @netdev: network interface device structure
2018 * @vf_id: vf identifier
2019 * @mac: mac address
2020 *
2021 * program vf mac address
2022 **/
2023int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2024{
2025 struct i40e_netdev_priv *np = netdev_priv(netdev);
2026 struct i40e_vsi *vsi = np->vsi;
2027 struct i40e_pf *pf = vsi->back;
2028 struct i40e_mac_filter *f;
2029 struct i40e_vf *vf;
2030 int ret = 0;
2031
2032 /* validate the request */
2033 if (vf_id >= pf->num_alloc_vfs) {
2034 dev_err(&pf->pdev->dev,
2035 "Invalid VF Identifier %d\n", vf_id);
2036 ret = -EINVAL;
2037 goto error_param;
2038 }
2039
2040 vf = &(pf->vf[vf_id]);
2041 vsi = pf->vsi[vf->lan_vsi_index];
2042 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2043 dev_err(&pf->pdev->dev,
2044 "Uninitialized VF %d\n", vf_id);
2045 ret = -EINVAL;
2046 goto error_param;
2047 }
2048
2049 if (!is_valid_ether_addr(mac)) {
2050 dev_err(&pf->pdev->dev,
2051 "Invalid VF ethernet address\n");
2052 ret = -EINVAL;
2053 goto error_param;
2054 }
2055
2056 /* delete the temporary mac address */
Greg Rose37cc0d22014-04-01 07:11:44 +00002057 i40e_del_filter(vsi, vf->default_lan_addr.addr, vf->port_vlan_id,
2058 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002059
Greg Rose29f71bb2014-05-20 08:01:45 +00002060 /* Delete all the filters for this VSI - we're going to kill it
2061 * anyway.
2062 */
2063 list_for_each_entry(f, &vsi->mac_filter_list, list)
2064 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002065
2066 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2067 /* program mac filter */
2068 if (i40e_sync_vsi_filters(vsi)) {
2069 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2070 ret = -EIO;
2071 goto error_param;
2072 }
Greg Rose9a173902014-05-22 06:32:02 +00002073 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002074 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002075 /* Force the VF driver stop so it has to reload with new MAC address */
2076 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002077 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002078
2079error_param:
2080 return ret;
2081}
2082
2083/**
2084 * i40e_ndo_set_vf_port_vlan
2085 * @netdev: network interface device structure
2086 * @vf_id: vf identifier
2087 * @vlan_id: mac address
2088 * @qos: priority setting
2089 *
2090 * program vf vlan id and/or qos
2091 **/
2092int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2093 int vf_id, u16 vlan_id, u8 qos)
2094{
2095 struct i40e_netdev_priv *np = netdev_priv(netdev);
2096 struct i40e_pf *pf = np->vsi->back;
2097 struct i40e_vsi *vsi;
2098 struct i40e_vf *vf;
2099 int ret = 0;
2100
2101 /* validate the request */
2102 if (vf_id >= pf->num_alloc_vfs) {
2103 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2104 ret = -EINVAL;
2105 goto error_pvid;
2106 }
2107
2108 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2109 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2110 ret = -EINVAL;
2111 goto error_pvid;
2112 }
2113
2114 vf = &(pf->vf[vf_id]);
2115 vsi = pf->vsi[vf->lan_vsi_index];
2116 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2117 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2118 ret = -EINVAL;
2119 goto error_pvid;
2120 }
2121
Greg Rosef9b4b622014-03-06 09:02:28 +00002122 if (vsi->info.pvid == 0 && i40e_is_vsi_in_vlan(vsi)) {
Greg Rose99a49732014-01-13 16:13:03 -08002123 dev_err(&pf->pdev->dev,
2124 "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",
2125 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002126 /* Administrator Error - knock the VF offline until he does
2127 * the right thing by reconfiguring his network correctly
2128 * and then reloading the VF driver.
2129 */
2130 i40e_vc_disable_vf(pf, vf);
2131 }
Greg Rose99a49732014-01-13 16:13:03 -08002132
Greg Rose8d82a7c2014-01-13 16:13:04 -08002133 /* Check for condition where there was already a port VLAN ID
2134 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002135 * Additionally check for the condition where there was a port
2136 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002137 * Before deleting all the old VLAN filters we must add new ones
2138 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2139 * MAC addresses deleted.
2140 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002141 if ((!(vlan_id || qos) ||
2142 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2143 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002144 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2145
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002146 if (vsi->info.pvid) {
2147 /* kill old VLAN */
2148 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2149 VLAN_VID_MASK));
2150 if (ret) {
2151 dev_info(&vsi->back->pdev->dev,
2152 "remove VLAN failed, ret=%d, aq_err=%d\n",
2153 ret, pf->hw.aq.asq_last_status);
2154 }
2155 }
2156 if (vlan_id || qos)
2157 ret = i40e_vsi_add_pvid(vsi,
2158 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2159 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002160 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002161
2162 if (vlan_id) {
2163 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2164 vlan_id, qos, vf_id);
2165
2166 /* add new VLAN filter */
2167 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2168 if (ret) {
2169 dev_info(&vsi->back->pdev->dev,
2170 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2171 vsi->back->hw.aq.asq_last_status);
2172 goto error_pvid;
2173 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002174 /* Kill non-vlan MAC filters - ignore error return since
2175 * there might not be any non-vlan MAC filters.
2176 */
2177 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002178 }
2179
2180 if (ret) {
2181 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2182 goto error_pvid;
2183 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002184 /* The Port VLAN needs to be saved across resets the same as the
2185 * default LAN MAC address.
2186 */
2187 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002188 ret = 0;
2189
2190error_pvid:
2191 return ret;
2192}
2193
Mitch Williams84590fd2014-04-09 05:58:57 +00002194#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2195#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002196/**
2197 * i40e_ndo_set_vf_bw
2198 * @netdev: network interface device structure
2199 * @vf_id: vf identifier
2200 * @tx_rate: tx rate
2201 *
2202 * configure vf tx rate
2203 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002204int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2205 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002206{
Mitch Williams6b192892014-03-06 09:02:29 +00002207 struct i40e_netdev_priv *np = netdev_priv(netdev);
2208 struct i40e_pf *pf = np->vsi->back;
2209 struct i40e_vsi *vsi;
2210 struct i40e_vf *vf;
2211 int speed = 0;
2212 int ret = 0;
2213
2214 /* validate the request */
2215 if (vf_id >= pf->num_alloc_vfs) {
2216 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2217 ret = -EINVAL;
2218 goto error;
2219 }
2220
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002221 if (min_tx_rate) {
2222 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for vf %d.\n",
2223 min_tx_rate, vf_id);
2224 return -EINVAL;
2225 }
2226
Mitch Williams6b192892014-03-06 09:02:29 +00002227 vf = &(pf->vf[vf_id]);
2228 vsi = pf->vsi[vf->lan_vsi_index];
2229 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2230 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2231 ret = -EINVAL;
2232 goto error;
2233 }
2234
2235 switch (pf->hw.phy.link_info.link_speed) {
2236 case I40E_LINK_SPEED_40GB:
2237 speed = 40000;
2238 break;
2239 case I40E_LINK_SPEED_10GB:
2240 speed = 10000;
2241 break;
2242 case I40E_LINK_SPEED_1GB:
2243 speed = 1000;
2244 break;
2245 default:
2246 break;
2247 }
2248
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002249 if (max_tx_rate > speed) {
2250 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for vf %d.",
2251 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002252 ret = -EINVAL;
2253 goto error;
2254 }
2255
Mitch Williamsdac9b312014-04-09 05:58:56 +00002256 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2257 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2258 max_tx_rate = 50;
2259 }
2260
Mitch Williams6b192892014-03-06 09:02:29 +00002261 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002262 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2263 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2264 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002265 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002266 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002267 ret);
2268 ret = -EIO;
2269 goto error;
2270 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002271 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002272error:
2273 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002274}
2275
2276/**
2277 * i40e_ndo_get_vf_config
2278 * @netdev: network interface device structure
2279 * @vf_id: vf identifier
2280 * @ivi: vf configuration structure
2281 *
2282 * return vf configuration
2283 **/
2284int i40e_ndo_get_vf_config(struct net_device *netdev,
2285 int vf_id, struct ifla_vf_info *ivi)
2286{
2287 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002288 struct i40e_vsi *vsi = np->vsi;
2289 struct i40e_pf *pf = vsi->back;
2290 struct i40e_vf *vf;
2291 int ret = 0;
2292
2293 /* validate the request */
2294 if (vf_id >= pf->num_alloc_vfs) {
2295 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2296 ret = -EINVAL;
2297 goto error_param;
2298 }
2299
2300 vf = &(pf->vf[vf_id]);
2301 /* first vsi is always the LAN vsi */
2302 vsi = pf->vsi[vf->lan_vsi_index];
2303 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2304 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2305 ret = -EINVAL;
2306 goto error_param;
2307 }
2308
2309 ivi->vf = vf_id;
2310
Mitch Williamsf4a1c5c2013-11-28 06:39:34 +00002311 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002312
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002313 ivi->max_tx_rate = vf->tx_rate;
2314 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002315 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2316 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2317 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00002318 if (vf->link_forced == false)
2319 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2320 else if (vf->link_up == true)
2321 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2322 else
2323 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00002324 ivi->spoofchk = vf->spoofchk;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002325 ret = 0;
2326
2327error_param:
2328 return ret;
2329}
Mitch Williams588aefa2014-02-11 08:27:49 +00002330
2331/**
2332 * i40e_ndo_set_vf_link_state
2333 * @netdev: network interface device structure
2334 * @vf_id: vf identifier
2335 * @link: required link state
2336 *
2337 * Set the link state of a specified VF, regardless of physical link state
2338 **/
2339int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2340{
2341 struct i40e_netdev_priv *np = netdev_priv(netdev);
2342 struct i40e_pf *pf = np->vsi->back;
2343 struct i40e_virtchnl_pf_event pfe;
2344 struct i40e_hw *hw = &pf->hw;
2345 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002346 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002347 int ret = 0;
2348
2349 /* validate the request */
2350 if (vf_id >= pf->num_alloc_vfs) {
2351 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2352 ret = -EINVAL;
2353 goto error_out;
2354 }
2355
2356 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07002357 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002358
2359 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2360 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2361
2362 switch (link) {
2363 case IFLA_VF_LINK_STATE_AUTO:
2364 vf->link_forced = false;
2365 pfe.event_data.link_event.link_status =
2366 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2367 pfe.event_data.link_event.link_speed =
2368 pf->hw.phy.link_info.link_speed;
2369 break;
2370 case IFLA_VF_LINK_STATE_ENABLE:
2371 vf->link_forced = true;
2372 vf->link_up = true;
2373 pfe.event_data.link_event.link_status = true;
2374 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2375 break;
2376 case IFLA_VF_LINK_STATE_DISABLE:
2377 vf->link_forced = true;
2378 vf->link_up = false;
2379 pfe.event_data.link_event.link_status = false;
2380 pfe.event_data.link_event.link_speed = 0;
2381 break;
2382 default:
2383 ret = -EINVAL;
2384 goto error_out;
2385 }
2386 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07002387 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00002388 0, (u8 *)&pfe, sizeof(pfe), NULL);
2389
2390error_out:
2391 return ret;
2392}
Mitch Williamsc674d122014-05-20 08:01:40 +00002393
2394/**
2395 * i40e_ndo_set_vf_spoofchk
2396 * @netdev: network interface device structure
2397 * @vf_id: vf identifier
2398 * @enable: flag to enable or disable feature
2399 *
2400 * Enable or disable VF spoof checking
2401 **/
Serey Konge6d90042014-07-12 07:28:14 +00002402int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00002403{
2404 struct i40e_netdev_priv *np = netdev_priv(netdev);
2405 struct i40e_vsi *vsi = np->vsi;
2406 struct i40e_pf *pf = vsi->back;
2407 struct i40e_vsi_context ctxt;
2408 struct i40e_hw *hw = &pf->hw;
2409 struct i40e_vf *vf;
2410 int ret = 0;
2411
2412 /* validate the request */
2413 if (vf_id >= pf->num_alloc_vfs) {
2414 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2415 ret = -EINVAL;
2416 goto out;
2417 }
2418
2419 vf = &(pf->vf[vf_id]);
2420
2421 if (enable == vf->spoofchk)
2422 goto out;
2423
2424 vf->spoofchk = enable;
2425 memset(&ctxt, 0, sizeof(ctxt));
2426 ctxt.seid = pf->vsi[vf->lan_vsi_index]->seid;
2427 ctxt.pf_num = pf->hw.pf_id;
2428 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2429 if (enable)
Greg Rose30d71af2015-01-29 07:17:17 +00002430 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2431 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
Mitch Williamsc674d122014-05-20 08:01:40 +00002432 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2433 if (ret) {
2434 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
2435 ret);
2436 ret = -EIO;
2437 }
2438out:
2439 return ret;
2440}