blob: a35a204b4eeb54e2009e8091d6eb4d8a27466d23 [file] [log] [blame]
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Neerav Parikh51616012015-02-06 08:52:14 +00004 * Copyright(c) 2013 - 2015 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
Mitch Williams532b0452015-04-07 19:45:34 -040029/*********************notification routines***********************/
30
31/**
32 * i40e_vc_vf_broadcast
33 * @pf: pointer to the PF structure
34 * @opcode: operation code
35 * @retval: return value
36 * @msg: pointer to the msg buffer
37 * @msglen: msg length
38 *
39 * send a message to all VFs on a given PF
40 **/
41static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
42 enum i40e_virtchnl_ops v_opcode,
43 i40e_status v_retval, u8 *msg,
44 u16 msglen)
45{
46 struct i40e_hw *hw = &pf->hw;
47 struct i40e_vf *vf = pf->vf;
48 int i;
49
50 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
51 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
54 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
55 continue;
56
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
59 */
60 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
61 msg, msglen, NULL);
62 }
63}
64
65/**
66 * i40e_vc_notify_link_state
67 * @vf: pointer to the VF structure
68 *
69 * send a link status message to a single VF
70 **/
71static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
72{
73 struct i40e_virtchnl_pf_event pfe;
74 struct i40e_pf *pf = vf->pf;
75 struct i40e_hw *hw = &pf->hw;
76 struct i40e_link_status *ls = &pf->hw.phy.link_info;
77 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
78
79 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
80 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
81 if (vf->link_forced) {
82 pfe.event_data.link_event.link_status = vf->link_up;
83 pfe.event_data.link_event.link_speed =
84 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
85 } else {
86 pfe.event_data.link_event.link_status =
87 ls->link_info & I40E_AQ_LINK_UP;
88 pfe.event_data.link_event.link_speed = ls->link_speed;
89 }
90 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
91 0, (u8 *)&pfe, sizeof(pfe), NULL);
92}
93
94/**
95 * i40e_vc_notify_link_state
96 * @pf: pointer to the PF structure
97 *
98 * send a link status message to all VFs on a given PF
99 **/
100void i40e_vc_notify_link_state(struct i40e_pf *pf)
101{
102 int i;
103
104 for (i = 0; i < pf->num_alloc_vfs; i++)
105 i40e_vc_notify_vf_link_state(&pf->vf[i]);
106}
107
108/**
109 * i40e_vc_notify_reset
110 * @pf: pointer to the PF structure
111 *
112 * indicate a pending reset to all VFs on a given PF
113 **/
114void i40e_vc_notify_reset(struct i40e_pf *pf)
115{
116 struct i40e_virtchnl_pf_event pfe;
117
118 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
119 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
120 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0,
121 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
122}
123
124/**
125 * i40e_vc_notify_vf_reset
126 * @vf: pointer to the VF structure
127 *
128 * indicate a pending reset to the given VF
129 **/
130void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
131{
132 struct i40e_virtchnl_pf_event pfe;
133 int abs_vf_id;
134
135 /* validate the request */
136 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
137 return;
138
139 /* verify if the VF is in either init or active before proceeding */
140 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
141 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
142 return;
143
144 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
145
146 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
147 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
148 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
149 0, (u8 *)&pfe,
150 sizeof(struct i40e_virtchnl_pf_event), NULL);
151}
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000152/***********************misc routines*****************************/
153
154/**
Greg Rosef9b4b622014-03-06 09:02:28 +0000155 * i40e_vc_disable_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000156 * @pf: pointer to the PF info
157 * @vf: pointer to the VF info
Greg Rosef9b4b622014-03-06 09:02:28 +0000158 *
159 * Disable the VF through a SW reset
160 **/
161static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
162{
Mitch Williams54f455e2015-04-27 14:57:14 -0400163 i40e_vc_notify_vf_reset(vf);
164 i40e_reset_vf(vf, false);
Greg Rosef9b4b622014-03-06 09:02:28 +0000165}
166
167/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000168 * i40e_vc_isvalid_vsi_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000169 * @vf: pointer to the VF info
170 * @vsi_id: VF relative VSI id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000171 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000172 * check for the valid VSI id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000173 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700174static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000175{
176 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700177 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000178
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700179 return (vsi && (vsi->vf_id == vf->vf_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000180}
181
182/**
183 * i40e_vc_isvalid_queue_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000184 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000185 * @vsi_id: vsi id
186 * @qid: vsi relative queue id
187 *
188 * check for the valid queue id
189 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700190static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000191 u8 qid)
192{
193 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700194 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000195
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700196 return (vsi && (qid < vsi->alloc_queue_pairs));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000197}
198
199/**
200 * i40e_vc_isvalid_vector_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000201 * @vf: pointer to the VF info
202 * @vector_id: VF relative vector id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000203 *
204 * check for the valid vector id
205 **/
206static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
207{
208 struct i40e_pf *pf = vf->pf;
209
Mitch Williams9347eb72014-02-11 08:26:32 +0000210 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000211}
212
213/***********************vf resource mgmt routines*****************/
214
215/**
216 * i40e_vc_get_pf_queue_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000217 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700218 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000219 * @vsi_queue_id: vsi relative queue id
220 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000221 * return PF relative queue id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000222 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700223static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000224 u8 vsi_queue_id)
225{
226 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700227 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000228 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
229
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700230 if (!vsi)
231 return pf_queue_id;
232
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000233 if (le16_to_cpu(vsi->info.mapping_flags) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
235 pf_queue_id =
236 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
237 else
238 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
239 vsi_queue_id;
240
241 return pf_queue_id;
242}
243
244/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000245 * i40e_config_irq_link_list
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000246 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700247 * @vsi_id: id of VSI as given by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000248 * @vecmap: irq map info
249 *
250 * configure irq link list from the map
251 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700252static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000253 struct i40e_virtchnl_vector_map *vecmap)
254{
255 unsigned long linklistmap = 0, tempmap;
256 struct i40e_pf *pf = vf->pf;
257 struct i40e_hw *hw = &pf->hw;
258 u16 vsi_queue_id, pf_queue_id;
259 enum i40e_queue_type qtype;
260 u16 next_q, vector_id;
261 u32 reg, reg_idx;
262 u16 itr_idx = 0;
263
264 vector_id = vecmap->vector_id;
265 /* setup the head */
266 if (0 == vector_id)
267 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
268 else
269 reg_idx = I40E_VPINT_LNKLSTN(
Mitch Williams9347eb72014-02-11 08:26:32 +0000270 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
271 (vector_id - 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000272
273 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
274 /* Special case - No queues mapped on this vector */
275 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
276 goto irq_list_done;
277 }
278 tempmap = vecmap->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000279 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400280 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
281 vsi_queue_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000282 }
283
284 tempmap = vecmap->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000285 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400286 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
287 vsi_queue_id + 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000288 }
289
290 next_q = find_first_bit(&linklistmap,
291 (I40E_MAX_VSI_QP *
292 I40E_VIRTCHNL_SUPPORTED_QTYPES));
293 vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES;
294 qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700295 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000296 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
297
298 wr32(hw, reg_idx, reg);
299
300 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
301 switch (qtype) {
302 case I40E_QUEUE_TYPE_RX:
303 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
304 itr_idx = vecmap->rxitr_idx;
305 break;
306 case I40E_QUEUE_TYPE_TX:
307 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
308 itr_idx = vecmap->txitr_idx;
309 break;
310 default:
311 break;
312 }
313
314 next_q = find_next_bit(&linklistmap,
315 (I40E_MAX_VSI_QP *
316 I40E_VIRTCHNL_SUPPORTED_QTYPES),
317 next_q + 1);
Mitch Williams829af3a2013-12-18 13:46:00 +0000318 if (next_q <
319 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700322 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000323 vsi_queue_id);
324 } else {
325 pf_queue_id = I40E_QUEUE_END_OF_LIST;
326 qtype = 0;
327 }
328
329 /* format for the RQCTL & TQCTL regs is same */
330 reg = (vector_id) |
331 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
332 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000334 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
335 wr32(hw, reg_idx, reg);
336 }
337
Anjali Singhai Jainb8262a62015-07-10 19:36:08 -0400338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
340 */
341 if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
342 (vector_id == 0)) {
343 reg = rd32(hw, I40E_GLINT_CTL);
344 if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
345 reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
346 wr32(hw, I40E_GLINT_CTL, reg);
347 }
348 }
349
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000350irq_list_done:
351 i40e_flush(hw);
352}
353
354/**
355 * i40e_config_vsi_tx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000356 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700357 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000358 * @vsi_queue_id: vsi relative queue index
359 * @info: config. info
360 *
361 * configure tx queue
362 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700363static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000364 u16 vsi_queue_id,
365 struct i40e_virtchnl_txq_info *info)
366{
367 struct i40e_pf *pf = vf->pf;
368 struct i40e_hw *hw = &pf->hw;
369 struct i40e_hmc_obj_txq tx_ctx;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700370 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000371 u16 pf_queue_id;
372 u32 qtx_ctl;
373 int ret = 0;
374
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700375 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
376 vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000377
378 /* clear the context structure first */
379 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
380
381 /* only set the required fields */
382 tx_ctx.base = info->dma_ring_addr / 128;
383 tx_ctx.qlen = info->ring_len;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700384 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000385 tx_ctx.rdylist_act = 0;
Ashish Shah5d298962014-05-22 06:31:25 +0000386 tx_ctx.head_wb_ena = info->headwb_enabled;
387 tx_ctx.head_wb_addr = info->dma_headwb_addr;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000388
389 /* clear the context in the HMC */
390 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
391 if (ret) {
392 dev_err(&pf->pdev->dev,
393 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
394 pf_queue_id, ret);
395 ret = -ENOENT;
396 goto error_context;
397 }
398
399 /* set the context in the HMC */
400 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
401 if (ret) {
402 dev_err(&pf->pdev->dev,
403 "Failed to set VF LAN Tx queue context %d error: %d\n",
404 pf_queue_id, ret);
405 ret = -ENOENT;
406 goto error_context;
407 }
408
409 /* associate this queue with the PCI VF function */
410 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +0000411 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000412 & I40E_QTX_CTL_PF_INDX_MASK);
413 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
414 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
415 & I40E_QTX_CTL_VFVM_INDX_MASK);
416 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
417 i40e_flush(hw);
418
419error_context:
420 return ret;
421}
422
423/**
424 * i40e_config_vsi_rx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000425 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700426 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000427 * @vsi_queue_id: vsi relative queue index
428 * @info: config. info
429 *
430 * configure rx queue
431 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700432static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000433 u16 vsi_queue_id,
434 struct i40e_virtchnl_rxq_info *info)
435{
436 struct i40e_pf *pf = vf->pf;
437 struct i40e_hw *hw = &pf->hw;
438 struct i40e_hmc_obj_rxq rx_ctx;
439 u16 pf_queue_id;
440 int ret = 0;
441
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700442 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000443
444 /* clear the context structure first */
445 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
446
447 /* only set the required fields */
448 rx_ctx.base = info->dma_ring_addr / 128;
449 rx_ctx.qlen = info->ring_len;
450
451 if (info->splithdr_enabled) {
452 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
453 I40E_RX_SPLIT_IP |
454 I40E_RX_SPLIT_TCP_UDP |
455 I40E_RX_SPLIT_SCTP;
456 /* header length validation */
457 if (info->hdr_size > ((2 * 1024) - 64)) {
458 ret = -EINVAL;
459 goto error_param;
460 }
461 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
462
463 /* set splitalways mode 10b */
464 rx_ctx.dtype = 0x2;
465 }
466
467 /* databuffer length validation */
468 if (info->databuffer_size > ((16 * 1024) - 128)) {
469 ret = -EINVAL;
470 goto error_param;
471 }
472 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
473
474 /* max pkt. length validation */
475 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
476 ret = -EINVAL;
477 goto error_param;
478 }
479 rx_ctx.rxmax = info->max_pkt_size;
480
481 /* enable 32bytes desc always */
482 rx_ctx.dsize = 1;
483
484 /* default values */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000485 rx_ctx.lrxqthresh = 2;
486 rx_ctx.crcstrip = 1;
Mitch Williams50d41652014-04-09 05:58:55 +0000487 rx_ctx.prefena = 1;
Shannon Nelsonc1d11ce2014-07-29 04:01:03 +0000488 rx_ctx.l2tsel = 1;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000489
490 /* clear the context in the HMC */
491 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
492 if (ret) {
493 dev_err(&pf->pdev->dev,
494 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
495 pf_queue_id, ret);
496 ret = -ENOENT;
497 goto error_param;
498 }
499
500 /* set the context in the HMC */
501 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
502 if (ret) {
503 dev_err(&pf->pdev->dev,
504 "Failed to set VF LAN Rx queue context %d error: %d\n",
505 pf_queue_id, ret);
506 ret = -ENOENT;
507 goto error_param;
508 }
509
510error_param:
511 return ret;
512}
513
514/**
515 * i40e_alloc_vsi_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000516 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000517 * @type: type of VSI to allocate
518 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000519 * alloc VF vsi context & resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000520 **/
521static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
522{
523 struct i40e_mac_filter *f = NULL;
524 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000525 struct i40e_vsi *vsi;
526 int ret = 0;
527
528 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
529
530 if (!vsi) {
531 dev_err(&pf->pdev->dev,
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000532 "add vsi failed for VF %d, aq_err %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000533 vf->vf_id, pf->hw.aq.asq_last_status);
534 ret = -ENOENT;
535 goto error_alloc_vsi_res;
536 }
537 if (type == I40E_VSI_SRIOV) {
Greg Rose1a103702013-11-28 06:42:39 +0000538 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400539
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700540 vf->lan_vsi_idx = vsi->idx;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000541 vf->lan_vsi_id = vsi->id;
Greg Rose6c12fcb2013-11-28 06:39:34 +0000542 /* If the port VLAN has been configured and then the
543 * VF driver was removed then the VSI port VLAN
544 * configuration was destroyed. Check if there is
545 * a port VLAN and restore the VSI configuration if
546 * needed.
547 */
548 if (vf->port_vlan_id)
549 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000550 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
Mitch Williamse9951632015-04-27 14:57:13 -0400551 vf->port_vlan_id ? vf->port_vlan_id : -1,
552 true, false);
Greg Rose1a103702013-11-28 06:42:39 +0000553 if (!f)
554 dev_info(&pf->pdev->dev,
555 "Could not allocate VF MAC addr\n");
Mitch Williamse9951632015-04-27 14:57:13 -0400556 f = i40e_add_filter(vsi, brdcast,
557 vf->port_vlan_id ? vf->port_vlan_id : -1,
Greg Rose1a103702013-11-28 06:42:39 +0000558 true, false);
559 if (!f)
560 dev_info(&pf->pdev->dev,
561 "Could not allocate VF broadcast filter\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000562 }
Neerav Parikh6dbbbfb2013-11-26 10:49:24 +0000563
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000564 /* program mac filter */
Anjali Singhai30e25612015-09-28 13:37:12 -0700565 ret = i40e_sync_vsi_filters(vsi, false);
Mitch Williamsfd1646e2014-02-13 03:48:44 -0800566 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000567 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000568
Mitch Williams6b192892014-03-06 09:02:29 +0000569 /* Set VF bandwidth if specified */
570 if (vf->tx_rate) {
571 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
572 vf->tx_rate / 50, 0, NULL);
573 if (ret)
574 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
575 vf->vf_id, ret);
576 }
577
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000578error_alloc_vsi_res:
579 return ret;
580}
581
582/**
Mitch Williams805bd5b2013-11-28 06:39:26 +0000583 * i40e_enable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000584 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000585 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000586 * enable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000587 **/
588static void i40e_enable_vf_mappings(struct i40e_vf *vf)
589{
590 struct i40e_pf *pf = vf->pf;
591 struct i40e_hw *hw = &pf->hw;
592 u32 reg, total_queue_pairs = 0;
593 int j;
594
595 /* Tell the hardware we're using noncontiguous mapping. HW requires
596 * that VF queues be mapped using this method, even when they are
597 * contiguous in real life
598 */
599 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
600 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
601
602 /* enable VF vplan_qtable mappings */
603 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
604 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
605
606 /* map PF queues to VF queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700607 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
608 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400609
Mitch Williams805bd5b2013-11-28 06:39:26 +0000610 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
611 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
612 total_queue_pairs++;
613 }
614
615 /* map PF queues to VSI */
616 for (j = 0; j < 7; j++) {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700617 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000618 reg = 0x07FF07FF; /* unused */
619 } else {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700620 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000621 j * 2);
622 reg = qid;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700623 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000624 (j * 2) + 1);
625 reg |= qid << 16;
626 }
627 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
628 }
629
630 i40e_flush(hw);
631}
632
633/**
634 * i40e_disable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000635 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000636 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000637 * disable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000638 **/
639static void i40e_disable_vf_mappings(struct i40e_vf *vf)
640{
641 struct i40e_pf *pf = vf->pf;
642 struct i40e_hw *hw = &pf->hw;
643 int i;
644
645 /* disable qp mappings */
646 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
647 for (i = 0; i < I40E_MAX_VSI_QP; i++)
648 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
649 I40E_QUEUE_END_OF_LIST);
650 i40e_flush(hw);
651}
652
653/**
654 * i40e_free_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000655 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000656 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000657 * free VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000658 **/
659static void i40e_free_vf_res(struct i40e_vf *vf)
660{
661 struct i40e_pf *pf = vf->pf;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000662 struct i40e_hw *hw = &pf->hw;
663 u32 reg_idx, reg;
664 int i, msix_vf;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000665
666 /* free vsi & disconnect it from the parent uplink */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700667 if (vf->lan_vsi_idx) {
668 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
669 vf->lan_vsi_idx = 0;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000670 vf->lan_vsi_id = 0;
671 }
Mitch Williams9347eb72014-02-11 08:26:32 +0000672 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
673
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000674 /* disable interrupts so the VF starts in a known state */
675 for (i = 0; i < msix_vf; i++) {
676 /* format is same for both registers */
677 if (0 == i)
678 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
679 else
680 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
681 (vf->vf_id))
682 + (i - 1));
683 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
684 i40e_flush(hw);
685 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000686
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000687 /* clear the irq settings */
688 for (i = 0; i < msix_vf; i++) {
689 /* format is same for both registers */
690 if (0 == i)
691 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
692 else
693 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
694 (vf->vf_id))
695 + (i - 1));
696 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
697 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
698 wr32(hw, reg_idx, reg);
699 i40e_flush(hw);
700 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000701 /* reset some of the state varibles keeping
702 * track of the resources
703 */
704 vf->num_queue_pairs = 0;
705 vf->vf_states = 0;
Mitch Williams21be99e2015-08-31 19:54:48 -0400706 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000707}
708
709/**
710 * i40e_alloc_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000711 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000712 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000713 * allocate VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000714 **/
715static int i40e_alloc_vf_res(struct i40e_vf *vf)
716{
717 struct i40e_pf *pf = vf->pf;
718 int total_queue_pairs = 0;
719 int ret;
720
721 /* allocate hw vsi context & associated resources */
722 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
723 if (ret)
724 goto error_alloc;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700725 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000726 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
727
728 /* store the total qps number for the runtime
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000729 * VF req validation
Mitch Williams805bd5b2013-11-28 06:39:26 +0000730 */
731 vf->num_queue_pairs = total_queue_pairs;
732
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000733 /* VF is now completely initialized */
Mitch Williams805bd5b2013-11-28 06:39:26 +0000734 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
735
736error_alloc:
737 if (ret)
738 i40e_free_vf_res(vf);
739
740 return ret;
741}
742
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000743#define VF_DEVICE_STATUS 0xAA
744#define VF_TRANS_PENDING_MASK 0x20
745/**
746 * i40e_quiesce_vf_pci
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000747 * @vf: pointer to the VF structure
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000748 *
749 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
750 * if the transactions never clear.
751 **/
752static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
753{
754 struct i40e_pf *pf = vf->pf;
755 struct i40e_hw *hw = &pf->hw;
756 int vf_abs_id, i;
757 u32 reg;
758
Mitch Williamsb141d612013-11-28 06:39:36 +0000759 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000760
761 wr32(hw, I40E_PF_PCI_CIAA,
762 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
763 for (i = 0; i < 100; i++) {
764 reg = rd32(hw, I40E_PF_PCI_CIAD);
765 if ((reg & VF_TRANS_PENDING_MASK) == 0)
766 return 0;
767 udelay(1);
768 }
769 return -EIO;
770}
771
Mitch Williams805bd5b2013-11-28 06:39:26 +0000772/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000773 * i40e_reset_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000774 * @vf: pointer to the VF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000775 * @flr: VFLR was issued or not
776 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000777 * reset the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000778 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000779void i40e_reset_vf(struct i40e_vf *vf, bool flr)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000780{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000781 struct i40e_pf *pf = vf->pf;
782 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000783 bool rsd = false;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000784 int i;
785 u32 reg;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000786
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000787 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
788 return;
789
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000790 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000791 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
792
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000793 /* In the case of a VFLR, the HW has already reset the VF and we
794 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000795 */
796 if (!flr) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000797 /* reset VF using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000798 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
799 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000800 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
801 i40e_flush(hw);
802 }
803
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000804 if (i40e_quiesce_vf_pci(vf))
805 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
806 vf->vf_id);
807
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000808 /* poll VPGEN_VFRSTAT reg to make sure
809 * that reset is complete
810 */
Mitch Williams1750a222015-01-09 11:18:13 +0000811 for (i = 0; i < 10; i++) {
812 /* VF reset requires driver to first reset the VF and then
813 * poll the status register to make sure that the reset
814 * completed successfully. Due to internal HW FIFO flushes,
815 * we must wait 10ms before the register will be valid.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000816 */
Mitch Williams1750a222015-01-09 11:18:13 +0000817 usleep_range(10000, 20000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000818 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
819 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
820 rsd = true;
821 break;
822 }
823 }
824
Anjali Singhai Jain57175ac2015-04-07 19:45:35 -0400825 if (flr)
826 usleep_range(10000, 20000);
827
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000828 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000829 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000830 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000831 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000832 /* clear the reset bit in the VPGEN_VFRTRIG reg */
833 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
834 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
835 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000836
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000837 /* On initial reset, we won't have any queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700838 if (vf->lan_vsi_idx == 0)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000839 goto complete_reset;
840
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700841 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000842complete_reset:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000843 /* reallocate VF resources to reset the VSI state */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000844 i40e_free_vf_res(vf);
Mitch Williams21be99e2015-08-31 19:54:48 -0400845 if (!i40e_alloc_vf_res(vf)) {
846 i40e_enable_vf_mappings(vf);
847 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
848 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
849 }
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000850 /* tell the VF the reset is done */
851 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
852 i40e_flush(hw);
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000853 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000854}
Greg Rosec3542292013-12-13 08:38:38 +0000855
856/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000857 * i40e_free_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000858 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000859 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000860 * free VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000861 **/
862void i40e_free_vfs(struct i40e_pf *pf)
863{
Mitch Williamsf7414532013-11-28 06:39:40 +0000864 struct i40e_hw *hw = &pf->hw;
865 u32 reg_idx, bit_idx;
866 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000867
868 if (!pf->vf)
869 return;
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000870 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
871 usleep_range(1000, 2000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000872
Mitch Williams44434632015-04-07 11:32:55 -0700873 for (i = 0; i < pf->num_alloc_vfs; i++)
874 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
875 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
876 false);
877
Mitch Williams0325fca2015-08-26 15:14:09 -0400878 for (i = 0; i < pf->num_alloc_vfs; i++)
879 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
880 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
881 false);
882
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000883 /* Disable IOV before freeing resources. This lets any VF drivers
884 * running in the host get themselves cleaned up before we yank
885 * the carpet out from underneath their feet.
886 */
887 if (!pci_vfs_assigned(pf->pdev))
888 pci_disable_sriov(pf->pdev);
Mitch Williams6d7b9672015-03-31 00:45:02 -0700889 else
890 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000891
892 msleep(20); /* let any messages in transit get finished up */
893
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000894 /* free up VF resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000895 tmp = pf->num_alloc_vfs;
896 pf->num_alloc_vfs = 0;
897 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000898 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
899 i40e_free_vf_res(&pf->vf[i]);
900 /* disable qp mappings */
901 i40e_disable_vf_mappings(&pf->vf[i]);
902 }
903
904 kfree(pf->vf);
905 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000906
Mitch Williams9e5634d2014-04-04 04:43:14 +0000907 /* This check is for when the driver is unloaded while VFs are
908 * assigned. Setting the number of VFs to 0 through sysfs is caught
909 * before this function ever gets called.
910 */
Ethan Zhaoc24817b2014-07-22 18:36:43 +0000911 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williamsf7414532013-11-28 06:39:40 +0000912 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
913 * work correctly when SR-IOV gets re-enabled.
914 */
915 for (vf_id = 0; vf_id < tmp; vf_id++) {
916 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
917 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400918 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Mitch Williamsf7414532013-11-28 06:39:40 +0000919 }
Greg Rosec3542292013-12-13 08:38:38 +0000920 }
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000921 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000922}
923
924#ifdef CONFIG_PCI_IOV
925/**
926 * i40e_alloc_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000927 * @pf: pointer to the PF structure
928 * @num_alloc_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000929 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000930 * allocate VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000931 **/
Mitch Williams4aeec012014-02-13 03:48:47 -0800932int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000933{
934 struct i40e_vf *vfs;
935 int i, ret = 0;
936
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000937 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000938 i40e_irq_dynamic_disable_icr0(pf);
939
Mitch Williams4aeec012014-02-13 03:48:47 -0800940 /* Check to see if we're just allocating resources for extant VFs */
941 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
942 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
943 if (ret) {
Mitch Williams4aeec012014-02-13 03:48:47 -0800944 pf->num_alloc_vfs = 0;
945 goto err_iov;
946 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000947 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000948 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +0000949 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000950 if (!vfs) {
951 ret = -ENOMEM;
952 goto err_alloc;
953 }
Mitch Williamsc674d122014-05-20 08:01:40 +0000954 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000955
956 /* apply default profile */
957 for (i = 0; i < num_alloc_vfs; i++) {
958 vfs[i].pf = pf;
959 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
960 vfs[i].vf_id = i;
961
962 /* assign default capabilities */
963 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +0000964 vfs[i].spoofchk = true;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000965 /* VF resources get allocated during reset */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000966 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000967
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000968 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000969 pf->num_alloc_vfs = num_alloc_vfs;
970
971err_alloc:
972 if (ret)
973 i40e_free_vfs(pf);
974err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000975 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000976 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000977 return ret;
978}
979
980#endif
981/**
982 * i40e_pci_sriov_enable
983 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000984 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000985 *
986 * Enable or change the number of VFs
987 **/
988static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
989{
990#ifdef CONFIG_PCI_IOV
991 struct i40e_pf *pf = pci_get_drvdata(pdev);
992 int pre_existing_vfs = pci_num_vf(pdev);
993 int err = 0;
994
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400995 if (test_bit(__I40E_TESTING, &pf->state)) {
Greg Rosee17bc412015-04-16 20:05:59 -0400996 dev_warn(&pdev->dev,
997 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
998 err = -EPERM;
999 goto err_out;
1000 }
1001
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001002 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1003 i40e_free_vfs(pf);
1004 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1005 goto out;
1006
1007 if (num_vfs > pf->num_req_vfs) {
Mitch Williams96c8d072015-08-27 11:42:35 -04001008 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1009 num_vfs, pf->num_req_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001010 err = -EPERM;
1011 goto err_out;
1012 }
1013
Mitch Williams96c8d072015-08-27 11:42:35 -04001014 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001015 err = i40e_alloc_vfs(pf, num_vfs);
1016 if (err) {
1017 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1018 goto err_out;
1019 }
1020
1021out:
1022 return num_vfs;
1023
1024err_out:
1025 return err;
1026#endif
1027 return 0;
1028}
1029
1030/**
1031 * i40e_pci_sriov_configure
1032 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001033 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001034 *
1035 * Enable or change the number of VFs. Called when the user updates the number
1036 * of VFs in sysfs.
1037 **/
1038int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1039{
1040 struct i40e_pf *pf = pci_get_drvdata(pdev);
1041
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001042 if (num_vfs) {
1043 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1044 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1045 i40e_do_reset_safe(pf,
1046 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1047 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001048 return i40e_pci_sriov_enable(pdev, num_vfs);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001049 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001050
Ethan Zhaoc24817b2014-07-22 18:36:43 +00001051 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williams9e5634d2014-04-04 04:43:14 +00001052 i40e_free_vfs(pf);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001053 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1054 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Mitch Williams9e5634d2014-04-04 04:43:14 +00001055 } else {
1056 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1057 return -EINVAL;
1058 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001059 return 0;
1060}
1061
1062/***********************virtual channel routines******************/
1063
1064/**
1065 * i40e_vc_send_msg_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001066 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001067 * @v_opcode: virtual channel opcode
1068 * @v_retval: virtual channel return value
1069 * @msg: pointer to the msg buffer
1070 * @msglen: msg length
1071 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001072 * send msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001073 **/
1074static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1075 u32 v_retval, u8 *msg, u16 msglen)
1076{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001077 struct i40e_pf *pf;
1078 struct i40e_hw *hw;
1079 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001080 i40e_status aq_ret;
1081
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001082 /* validate the request */
1083 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1084 return -EINVAL;
1085
1086 pf = vf->pf;
1087 hw = &pf->hw;
1088 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1089
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001090 /* single place to detect unsuccessful return values */
1091 if (v_retval) {
1092 vf->num_invalid_msgs++;
1093 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1094 v_opcode, v_retval);
1095 if (vf->num_invalid_msgs >
1096 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1097 dev_err(&pf->pdev->dev,
1098 "Number of invalid messages exceeded for VF %d\n",
1099 vf->vf_id);
1100 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1101 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1102 }
1103 } else {
1104 vf->num_valid_msgs++;
Jingjing Wu5d38c932015-09-28 14:12:39 -04001105 /* reset the invalid counter, if a valid message is received. */
1106 vf->num_invalid_msgs = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001107 }
1108
Ashish Shahf19efbb2014-08-01 13:27:06 -07001109 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001110 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001111 if (aq_ret) {
1112 dev_err(&pf->pdev->dev,
1113 "Unable to send the message to VF %d aq_err %d\n",
1114 vf->vf_id, pf->hw.aq.asq_last_status);
1115 return -EIO;
1116 }
1117
1118 return 0;
1119}
1120
1121/**
1122 * i40e_vc_send_resp_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001123 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001124 * @opcode: operation code
1125 * @retval: return value
1126 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001127 * send resp msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001128 **/
1129static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1130 enum i40e_virtchnl_ops opcode,
1131 i40e_status retval)
1132{
1133 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1134}
1135
1136/**
1137 * i40e_vc_get_version_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001138 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001139 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001140 * called from the VF to request the API version used by the PF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001141 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001142static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001143{
1144 struct i40e_virtchnl_version_info info = {
1145 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1146 };
1147
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001148 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
Mitch Williams606a5482015-06-04 16:24:00 -04001149 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1150 if (VF_IS_V10(vf))
1151 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001152 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1153 I40E_SUCCESS, (u8 *)&info,
1154 sizeof(struct
1155 i40e_virtchnl_version_info));
1156}
1157
1158/**
1159 * i40e_vc_get_vf_resources_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001160 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001161 * @msg: pointer to the msg buffer
1162 * @msglen: msg length
1163 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001164 * called from the VF to request its resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001165 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001166static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001167{
1168 struct i40e_virtchnl_vf_resource *vfres = NULL;
1169 struct i40e_pf *pf = vf->pf;
1170 i40e_status aq_ret = 0;
1171 struct i40e_vsi *vsi;
1172 int i = 0, len = 0;
1173 int num_vsis = 1;
1174 int ret;
1175
1176 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1177 aq_ret = I40E_ERR_PARAM;
1178 goto err;
1179 }
1180
1181 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1182 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1183
1184 vfres = kzalloc(len, GFP_KERNEL);
1185 if (!vfres) {
1186 aq_ret = I40E_ERR_NO_MEMORY;
1187 len = 0;
1188 goto err;
1189 }
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001190 if (VF_IS_V11(vf))
1191 vf->driver_caps = *(u32 *)msg;
1192 else
1193 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1194 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1195 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001196
1197 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001198 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001199 if (!vsi->info.pvid)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001200 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1201 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1202 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1203 vfres->vf_offload_flags |=
1204 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1205 } else {
1206 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1207 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001208
1209 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING)
1210 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1211
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001212 vfres->num_vsis = num_vsis;
1213 vfres->num_queue_pairs = vf->num_queue_pairs;
1214 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001215 if (vf->lan_vsi_idx) {
1216 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001217 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04001218 vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs;
1219 /* VFs only use TC 0 */
1220 vfres->vsi_res[i].qset_handle
1221 = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001222 ether_addr_copy(vfres->vsi_res[i].default_mac_addr,
1223 vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001224 i++;
1225 }
1226 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1227
1228err:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001229 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001230 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1231 aq_ret, (u8 *)vfres, len);
1232
1233 kfree(vfres);
1234 return ret;
1235}
1236
1237/**
1238 * i40e_vc_reset_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001239 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001240 * @msg: pointer to the msg buffer
1241 * @msglen: msg length
1242 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001243 * called from the VF to reset itself,
1244 * unlike other virtchnl messages, PF driver
1245 * doesn't send the response back to the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001246 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001247static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001248{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001249 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1250 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001251}
1252
1253/**
1254 * i40e_vc_config_promiscuous_mode_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001255 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001256 * @msg: pointer to the msg buffer
1257 * @msglen: msg length
1258 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001259 * called from the VF to configure the promiscuous mode of
1260 * VF vsis
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001261 **/
1262static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1263 u8 *msg, u16 msglen)
1264{
1265 struct i40e_virtchnl_promisc_info *info =
1266 (struct i40e_virtchnl_promisc_info *)msg;
1267 struct i40e_pf *pf = vf->pf;
1268 struct i40e_hw *hw = &pf->hw;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001269 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001270 bool allmulti = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001271 i40e_status aq_ret;
1272
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001273 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001274 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1275 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1276 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001277 (vsi->type != I40E_VSI_FCOE)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001278 aq_ret = I40E_ERR_PARAM;
1279 goto error_param;
1280 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001281 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1282 allmulti = true;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001283 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001284 allmulti, NULL);
1285
1286error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001287 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001288 return i40e_vc_send_resp_to_vf(vf,
1289 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1290 aq_ret);
1291}
1292
1293/**
1294 * i40e_vc_config_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001295 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001296 * @msg: pointer to the msg buffer
1297 * @msglen: msg length
1298 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001299 * called from the VF to configure the rx/tx
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001300 * queues
1301 **/
1302static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1303{
1304 struct i40e_virtchnl_vsi_queue_config_info *qci =
1305 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1306 struct i40e_virtchnl_queue_pair_info *qpi;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001307 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001308 u16 vsi_id, vsi_queue_id;
1309 i40e_status aq_ret = 0;
1310 int i;
1311
1312 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1313 aq_ret = I40E_ERR_PARAM;
1314 goto error_param;
1315 }
1316
1317 vsi_id = qci->vsi_id;
1318 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1319 aq_ret = I40E_ERR_PARAM;
1320 goto error_param;
1321 }
1322 for (i = 0; i < qci->num_queue_pairs; i++) {
1323 qpi = &qci->qpair[i];
1324 vsi_queue_id = qpi->txq.queue_id;
1325 if ((qpi->txq.vsi_id != vsi_id) ||
1326 (qpi->rxq.vsi_id != vsi_id) ||
1327 (qpi->rxq.queue_id != vsi_queue_id) ||
1328 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1329 aq_ret = I40E_ERR_PARAM;
1330 goto error_param;
1331 }
1332
1333 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1334 &qpi->rxq) ||
1335 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1336 &qpi->txq)) {
1337 aq_ret = I40E_ERR_PARAM;
1338 goto error_param;
1339 }
1340 }
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001341 /* set vsi num_queue_pairs in use to num configured by VF */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001342 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001343
1344error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001345 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001346 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1347 aq_ret);
1348}
1349
1350/**
1351 * i40e_vc_config_irq_map_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001352 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001353 * @msg: pointer to the msg buffer
1354 * @msglen: msg length
1355 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001356 * called from the VF to configure the irq to
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001357 * queue map
1358 **/
1359static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1360{
1361 struct i40e_virtchnl_irq_map_info *irqmap_info =
1362 (struct i40e_virtchnl_irq_map_info *)msg;
1363 struct i40e_virtchnl_vector_map *map;
1364 u16 vsi_id, vsi_queue_id, vector_id;
1365 i40e_status aq_ret = 0;
1366 unsigned long tempmap;
1367 int i;
1368
1369 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1370 aq_ret = I40E_ERR_PARAM;
1371 goto error_param;
1372 }
1373
1374 for (i = 0; i < irqmap_info->num_vectors; i++) {
1375 map = &irqmap_info->vecmap[i];
1376
1377 vector_id = map->vector_id;
1378 vsi_id = map->vsi_id;
1379 /* validate msg params */
1380 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1381 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1382 aq_ret = I40E_ERR_PARAM;
1383 goto error_param;
1384 }
1385
1386 /* lookout for the invalid queue index */
1387 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001388 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001389 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1390 vsi_queue_id)) {
1391 aq_ret = I40E_ERR_PARAM;
1392 goto error_param;
1393 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001394 }
1395
1396 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001397 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001398 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1399 vsi_queue_id)) {
1400 aq_ret = I40E_ERR_PARAM;
1401 goto error_param;
1402 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001403 }
1404
1405 i40e_config_irq_link_list(vf, vsi_id, map);
1406 }
1407error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001408 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001409 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1410 aq_ret);
1411}
1412
1413/**
1414 * i40e_vc_enable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001415 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001416 * @msg: pointer to the msg buffer
1417 * @msglen: msg length
1418 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001419 * called from the VF to enable all or specific queue(s)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001420 **/
1421static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1422{
1423 struct i40e_virtchnl_queue_select *vqs =
1424 (struct i40e_virtchnl_queue_select *)msg;
1425 struct i40e_pf *pf = vf->pf;
1426 u16 vsi_id = vqs->vsi_id;
1427 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001428
1429 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1430 aq_ret = I40E_ERR_PARAM;
1431 goto error_param;
1432 }
1433
1434 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1435 aq_ret = I40E_ERR_PARAM;
1436 goto error_param;
1437 }
1438
1439 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1440 aq_ret = I40E_ERR_PARAM;
1441 goto error_param;
1442 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001443
1444 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
Mitch Williams88f65632013-11-28 06:39:28 +00001445 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001446error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001447 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001448 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1449 aq_ret);
1450}
1451
1452/**
1453 * i40e_vc_disable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001454 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001455 * @msg: pointer to the msg buffer
1456 * @msglen: msg length
1457 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001458 * called from the VF to disable all or specific
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001459 * queue(s)
1460 **/
1461static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1462{
1463 struct i40e_virtchnl_queue_select *vqs =
1464 (struct i40e_virtchnl_queue_select *)msg;
1465 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001466 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001467
1468 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1469 aq_ret = I40E_ERR_PARAM;
1470 goto error_param;
1471 }
1472
1473 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1474 aq_ret = I40E_ERR_PARAM;
1475 goto error_param;
1476 }
1477
1478 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1479 aq_ret = I40E_ERR_PARAM;
1480 goto error_param;
1481 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001482
1483 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
Mitch Williams88f65632013-11-28 06:39:28 +00001484 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001485
1486error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001487 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001488 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1489 aq_ret);
1490}
1491
1492/**
1493 * i40e_vc_get_stats_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001494 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001495 * @msg: pointer to the msg buffer
1496 * @msglen: msg length
1497 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001498 * called from the VF to get vsi stats
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001499 **/
1500static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1501{
1502 struct i40e_virtchnl_queue_select *vqs =
1503 (struct i40e_virtchnl_queue_select *)msg;
1504 struct i40e_pf *pf = vf->pf;
1505 struct i40e_eth_stats stats;
1506 i40e_status aq_ret = 0;
1507 struct i40e_vsi *vsi;
1508
1509 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1510
1511 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1512 aq_ret = I40E_ERR_PARAM;
1513 goto error_param;
1514 }
1515
1516 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1517 aq_ret = I40E_ERR_PARAM;
1518 goto error_param;
1519 }
1520
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001521 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001522 if (!vsi) {
1523 aq_ret = I40E_ERR_PARAM;
1524 goto error_param;
1525 }
1526 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001527 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001528
1529error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001530 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001531 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1532 (u8 *)&stats, sizeof(stats));
1533}
1534
1535/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001536 * i40e_check_vf_permission
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001537 * @vf: pointer to the VF info
Greg Rosef657a6e2013-11-28 06:39:42 +00001538 * @macaddr: pointer to the MAC Address being checked
1539 *
1540 * Check if the VF has permission to add or delete unicast MAC address
1541 * filters and return error code -EPERM if not. Then check if the
1542 * address filter requested is broadcast or zero and if so return
1543 * an invalid MAC address error code.
1544 **/
1545static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1546{
1547 struct i40e_pf *pf = vf->pf;
1548 int ret = 0;
1549
1550 if (is_broadcast_ether_addr(macaddr) ||
1551 is_zero_ether_addr(macaddr)) {
1552 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1553 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001554 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1555 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001556 /* If the host VMM administrator has set the VF MAC address
1557 * administratively via the ndo_set_vf_mac command then deny
1558 * permission to the VF to add or delete unicast MAC addresses.
Greg Rose5017c2a2013-12-07 10:36:54 +00001559 * The VF may request to set the MAC address filter already
1560 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001561 */
1562 dev_err(&pf->pdev->dev,
1563 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1564 ret = -EPERM;
1565 }
1566 return ret;
1567}
1568
1569/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001570 * i40e_vc_add_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001571 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001572 * @msg: pointer to the msg buffer
1573 * @msglen: msg length
1574 *
1575 * add guest mac address filter
1576 **/
1577static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1578{
1579 struct i40e_virtchnl_ether_addr_list *al =
1580 (struct i40e_virtchnl_ether_addr_list *)msg;
1581 struct i40e_pf *pf = vf->pf;
1582 struct i40e_vsi *vsi = NULL;
1583 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001584 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001585 int i;
1586
1587 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1588 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1589 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001590 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001591 goto error_param;
1592 }
1593
1594 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001595 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1596 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001597 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001598 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001599 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001600
1601 /* add new addresses to the list */
1602 for (i = 0; i < al->num_elements; i++) {
1603 struct i40e_mac_filter *f;
1604
1605 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001606 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001607 if (i40e_is_vsi_in_vlan(vsi))
1608 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1609 true, false);
1610 else
1611 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1612 true, false);
1613 }
1614
1615 if (!f) {
1616 dev_err(&pf->pdev->dev,
1617 "Unable to add VF MAC filter\n");
Greg Rosef657a6e2013-11-28 06:39:42 +00001618 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001619 goto error_param;
1620 }
1621 }
1622
1623 /* program the updated filter list */
Anjali Singhai30e25612015-09-28 13:37:12 -07001624 if (i40e_sync_vsi_filters(vsi, false))
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001625 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1626
1627error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001628 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001629 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001630 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001631}
1632
1633/**
1634 * i40e_vc_del_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001635 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001636 * @msg: pointer to the msg buffer
1637 * @msglen: msg length
1638 *
1639 * remove guest mac address filter
1640 **/
1641static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1642{
1643 struct i40e_virtchnl_ether_addr_list *al =
1644 (struct i40e_virtchnl_ether_addr_list *)msg;
1645 struct i40e_pf *pf = vf->pf;
1646 struct i40e_vsi *vsi = NULL;
1647 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001648 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001649 int i;
1650
1651 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1652 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1653 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001654 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001655 goto error_param;
1656 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001657
1658 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00001659 if (is_broadcast_ether_addr(al->list[i].addr) ||
1660 is_zero_ether_addr(al->list[i].addr)) {
1661 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1662 al->list[i].addr);
1663 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00001664 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00001665 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001666 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001667 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001668
1669 /* delete addresses from the list */
1670 for (i = 0; i < al->num_elements; i++)
1671 i40e_del_filter(vsi, al->list[i].addr,
1672 I40E_VLAN_ANY, true, false);
1673
1674 /* program the updated filter list */
Anjali Singhai30e25612015-09-28 13:37:12 -07001675 if (i40e_sync_vsi_filters(vsi, false))
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001676 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1677
1678error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001679 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001680 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001681 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001682}
1683
1684/**
1685 * i40e_vc_add_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001686 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001687 * @msg: pointer to the msg buffer
1688 * @msglen: msg length
1689 *
1690 * program guest vlan id
1691 **/
1692static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1693{
1694 struct i40e_virtchnl_vlan_filter_list *vfl =
1695 (struct i40e_virtchnl_vlan_filter_list *)msg;
1696 struct i40e_pf *pf = vf->pf;
1697 struct i40e_vsi *vsi = NULL;
1698 u16 vsi_id = vfl->vsi_id;
1699 i40e_status aq_ret = 0;
1700 int i;
1701
1702 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1703 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1704 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1705 aq_ret = I40E_ERR_PARAM;
1706 goto error_param;
1707 }
1708
1709 for (i = 0; i < vfl->num_elements; i++) {
1710 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1711 aq_ret = I40E_ERR_PARAM;
1712 dev_err(&pf->pdev->dev,
1713 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1714 goto error_param;
1715 }
1716 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001717 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001718 if (vsi->info.pvid) {
1719 aq_ret = I40E_ERR_PARAM;
1720 goto error_param;
1721 }
1722
1723 i40e_vlan_stripping_enable(vsi);
1724 for (i = 0; i < vfl->num_elements; i++) {
1725 /* add new VLAN filter */
1726 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001727
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001728 if (ret)
1729 dev_err(&pf->pdev->dev,
1730 "Unable to add VF vlan filter %d, error %d\n",
1731 vfl->vlan_id[i], ret);
1732 }
1733
1734error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001735 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001736 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1737}
1738
1739/**
1740 * i40e_vc_remove_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001741 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001742 * @msg: pointer to the msg buffer
1743 * @msglen: msg length
1744 *
1745 * remove programmed guest vlan id
1746 **/
1747static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1748{
1749 struct i40e_virtchnl_vlan_filter_list *vfl =
1750 (struct i40e_virtchnl_vlan_filter_list *)msg;
1751 struct i40e_pf *pf = vf->pf;
1752 struct i40e_vsi *vsi = NULL;
1753 u16 vsi_id = vfl->vsi_id;
1754 i40e_status aq_ret = 0;
1755 int i;
1756
1757 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1758 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1759 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1760 aq_ret = I40E_ERR_PARAM;
1761 goto error_param;
1762 }
1763
1764 for (i = 0; i < vfl->num_elements; i++) {
1765 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1766 aq_ret = I40E_ERR_PARAM;
1767 goto error_param;
1768 }
1769 }
1770
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001771 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001772 if (vsi->info.pvid) {
1773 aq_ret = I40E_ERR_PARAM;
1774 goto error_param;
1775 }
1776
1777 for (i = 0; i < vfl->num_elements; i++) {
1778 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001779
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001780 if (ret)
1781 dev_err(&pf->pdev->dev,
1782 "Unable to delete VF vlan filter %d, error %d\n",
1783 vfl->vlan_id[i], ret);
1784 }
1785
1786error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001787 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001788 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1789}
1790
1791/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001792 * i40e_vc_validate_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001793 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001794 * @msg: pointer to the msg buffer
1795 * @msglen: msg length
1796 * @msghndl: msg handle
1797 *
1798 * validate msg
1799 **/
1800static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1801 u32 v_retval, u8 *msg, u16 msglen)
1802{
1803 bool err_msg_format = false;
1804 int valid_len;
1805
1806 /* Check if VF is disabled. */
1807 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1808 return I40E_ERR_PARAM;
1809
1810 /* Validate message length. */
1811 switch (v_opcode) {
1812 case I40E_VIRTCHNL_OP_VERSION:
1813 valid_len = sizeof(struct i40e_virtchnl_version_info);
1814 break;
1815 case I40E_VIRTCHNL_OP_RESET_VF:
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001816 valid_len = 0;
1817 break;
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001818 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1819 if (VF_IS_V11(vf))
1820 valid_len = sizeof(u32);
1821 else
1822 valid_len = 0;
1823 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001824 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1825 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1826 break;
1827 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1828 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1829 break;
1830 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1831 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1832 if (msglen >= valid_len) {
1833 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1834 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1835 valid_len += (vqc->num_queue_pairs *
1836 sizeof(struct
1837 i40e_virtchnl_queue_pair_info));
1838 if (vqc->num_queue_pairs == 0)
1839 err_msg_format = true;
1840 }
1841 break;
1842 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1843 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1844 if (msglen >= valid_len) {
1845 struct i40e_virtchnl_irq_map_info *vimi =
1846 (struct i40e_virtchnl_irq_map_info *)msg;
1847 valid_len += (vimi->num_vectors *
1848 sizeof(struct i40e_virtchnl_vector_map));
1849 if (vimi->num_vectors == 0)
1850 err_msg_format = true;
1851 }
1852 break;
1853 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1854 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1855 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1856 break;
1857 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1858 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1859 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1860 if (msglen >= valid_len) {
1861 struct i40e_virtchnl_ether_addr_list *veal =
1862 (struct i40e_virtchnl_ether_addr_list *)msg;
1863 valid_len += veal->num_elements *
1864 sizeof(struct i40e_virtchnl_ether_addr);
1865 if (veal->num_elements == 0)
1866 err_msg_format = true;
1867 }
1868 break;
1869 case I40E_VIRTCHNL_OP_ADD_VLAN:
1870 case I40E_VIRTCHNL_OP_DEL_VLAN:
1871 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1872 if (msglen >= valid_len) {
1873 struct i40e_virtchnl_vlan_filter_list *vfl =
1874 (struct i40e_virtchnl_vlan_filter_list *)msg;
1875 valid_len += vfl->num_elements * sizeof(u16);
1876 if (vfl->num_elements == 0)
1877 err_msg_format = true;
1878 }
1879 break;
1880 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1881 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1882 break;
1883 case I40E_VIRTCHNL_OP_GET_STATS:
1884 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1885 break;
1886 /* These are always errors coming from the VF. */
1887 case I40E_VIRTCHNL_OP_EVENT:
1888 case I40E_VIRTCHNL_OP_UNKNOWN:
1889 default:
1890 return -EPERM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001891 }
1892 /* few more checks */
1893 if ((valid_len != msglen) || (err_msg_format)) {
1894 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1895 return -EINVAL;
1896 } else {
1897 return 0;
1898 }
1899}
1900
1901/**
1902 * i40e_vc_process_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001903 * @pf: pointer to the PF structure
1904 * @vf_id: source VF id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001905 * @msg: pointer to the msg buffer
1906 * @msglen: msg length
1907 * @msghndl: msg handle
1908 *
1909 * called from the common aeq/arq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001910 * process request from VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001911 **/
1912int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1913 u32 v_retval, u8 *msg, u16 msglen)
1914{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001915 struct i40e_hw *hw = &pf->hw;
Dan Carpenterc243e962014-01-15 06:43:39 +00001916 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001917 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001918 int ret;
1919
1920 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001921 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001922 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001923 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001924 /* perform basic checks on the msg */
1925 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1926
1927 if (ret) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001928 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001929 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001930 return ret;
1931 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08001932
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001933 switch (v_opcode) {
1934 case I40E_VIRTCHNL_OP_VERSION:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001935 ret = i40e_vc_get_version_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001936 break;
1937 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001938 ret = i40e_vc_get_vf_resources_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001939 break;
1940 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001941 i40e_vc_reset_vf_msg(vf);
1942 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001943 break;
1944 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1945 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1946 break;
1947 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1948 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1949 break;
1950 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1951 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1952 break;
1953 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1954 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
Mitch Williams055b2952015-04-07 19:45:33 -04001955 i40e_vc_notify_vf_link_state(vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001956 break;
1957 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1958 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1959 break;
1960 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1961 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1962 break;
1963 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1964 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1965 break;
1966 case I40E_VIRTCHNL_OP_ADD_VLAN:
1967 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1968 break;
1969 case I40E_VIRTCHNL_OP_DEL_VLAN:
1970 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1971 break;
1972 case I40E_VIRTCHNL_OP_GET_STATS:
1973 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1974 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001975 case I40E_VIRTCHNL_OP_UNKNOWN:
1976 default:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001977 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001978 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001979 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1980 I40E_ERR_NOT_IMPLEMENTED);
1981 break;
1982 }
1983
1984 return ret;
1985}
1986
1987/**
1988 * i40e_vc_process_vflr_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001989 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001990 *
1991 * called from the vlfr irq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001992 * free up VF resources and state variables
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001993 **/
1994int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1995{
1996 u32 reg, reg_idx, bit_idx, vf_id;
1997 struct i40e_hw *hw = &pf->hw;
1998 struct i40e_vf *vf;
1999
2000 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2001 return 0;
2002
Mitch Williamsc5c2f7c2014-11-11 03:15:04 +00002003 /* re-enable vflr interrupt cause */
2004 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2005 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2006 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2007 i40e_flush(hw);
2008
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002009 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2010 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2011 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2012 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002013 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002014 vf = &pf->vf[vf_id];
2015 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002016 if (reg & BIT(bit_idx)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002017 /* clear the bit in GLGEN_VFLRSTAT */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002018 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002019
Mitch Williamseb2d80b2014-02-13 03:48:48 -08002020 if (!test_bit(__I40E_DOWN, &pf->state))
2021 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002022 }
2023 }
2024
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002025 return 0;
2026}
2027
2028/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002029 * i40e_ndo_set_vf_mac
2030 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002031 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002032 * @mac: mac address
2033 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002034 * program VF mac address
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002035 **/
2036int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2037{
2038 struct i40e_netdev_priv *np = netdev_priv(netdev);
2039 struct i40e_vsi *vsi = np->vsi;
2040 struct i40e_pf *pf = vsi->back;
2041 struct i40e_mac_filter *f;
2042 struct i40e_vf *vf;
2043 int ret = 0;
2044
2045 /* validate the request */
2046 if (vf_id >= pf->num_alloc_vfs) {
2047 dev_err(&pf->pdev->dev,
2048 "Invalid VF Identifier %d\n", vf_id);
2049 ret = -EINVAL;
2050 goto error_param;
2051 }
2052
2053 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002054 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002055 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2056 dev_err(&pf->pdev->dev,
2057 "Uninitialized VF %d\n", vf_id);
2058 ret = -EINVAL;
2059 goto error_param;
2060 }
2061
2062 if (!is_valid_ether_addr(mac)) {
2063 dev_err(&pf->pdev->dev,
2064 "Invalid VF ethernet address\n");
2065 ret = -EINVAL;
2066 goto error_param;
2067 }
2068
2069 /* delete the temporary mac address */
Mitch Williamse9951632015-04-27 14:57:13 -04002070 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2071 vf->port_vlan_id ? vf->port_vlan_id : -1,
Greg Rose37cc0d22014-04-01 07:11:44 +00002072 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002073
Greg Rose29f71bb2014-05-20 08:01:45 +00002074 /* Delete all the filters for this VSI - we're going to kill it
2075 * anyway.
2076 */
2077 list_for_each_entry(f, &vsi->mac_filter_list, list)
2078 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002079
2080 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2081 /* program mac filter */
Anjali Singhai30e25612015-09-28 13:37:12 -07002082 if (i40e_sync_vsi_filters(vsi, false)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002083 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2084 ret = -EIO;
2085 goto error_param;
2086 }
Greg Rose9a173902014-05-22 06:32:02 +00002087 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002088 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002089 /* Force the VF driver stop so it has to reload with new MAC address */
2090 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002091 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002092
2093error_param:
2094 return ret;
2095}
2096
2097/**
2098 * i40e_ndo_set_vf_port_vlan
2099 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002100 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002101 * @vlan_id: mac address
2102 * @qos: priority setting
2103 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002104 * program VF vlan id and/or qos
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002105 **/
2106int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2107 int vf_id, u16 vlan_id, u8 qos)
2108{
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002109 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002110 struct i40e_netdev_priv *np = netdev_priv(netdev);
2111 struct i40e_pf *pf = np->vsi->back;
2112 struct i40e_vsi *vsi;
2113 struct i40e_vf *vf;
2114 int ret = 0;
2115
2116 /* validate the request */
2117 if (vf_id >= pf->num_alloc_vfs) {
2118 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2119 ret = -EINVAL;
2120 goto error_pvid;
2121 }
2122
2123 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2124 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2125 ret = -EINVAL;
2126 goto error_pvid;
2127 }
2128
2129 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002130 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002131 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2132 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2133 ret = -EINVAL;
2134 goto error_pvid;
2135 }
2136
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002137 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
Mitch Williams85927ec2015-04-27 14:57:10 -04002138 /* duplicate request, so just return success */
2139 goto error_pvid;
2140
Mitch Williamsecbb44e2015-07-10 19:35:56 -04002141 if (le16_to_cpu(vsi->info.pvid) == 0 && i40e_is_vsi_in_vlan(vsi)) {
Greg Rose99a49732014-01-13 16:13:03 -08002142 dev_err(&pf->pdev->dev,
2143 "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",
2144 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002145 /* Administrator Error - knock the VF offline until he does
2146 * the right thing by reconfiguring his network correctly
2147 * and then reloading the VF driver.
2148 */
2149 i40e_vc_disable_vf(pf, vf);
2150 }
Greg Rose99a49732014-01-13 16:13:03 -08002151
Greg Rose8d82a7c2014-01-13 16:13:04 -08002152 /* Check for condition where there was already a port VLAN ID
2153 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002154 * Additionally check for the condition where there was a port
2155 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002156 * Before deleting all the old VLAN filters we must add new ones
2157 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2158 * MAC addresses deleted.
2159 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002160 if ((!(vlan_id || qos) ||
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002161 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
Greg Rose1315f7c2014-03-14 07:32:20 +00002162 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002163 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2164
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002165 if (vsi->info.pvid) {
2166 /* kill old VLAN */
2167 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2168 VLAN_VID_MASK));
2169 if (ret) {
2170 dev_info(&vsi->back->pdev->dev,
2171 "remove VLAN failed, ret=%d, aq_err=%d\n",
2172 ret, pf->hw.aq.asq_last_status);
2173 }
2174 }
2175 if (vlan_id || qos)
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002176 ret = i40e_vsi_add_pvid(vsi, vlanprio);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002177 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002178 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002179
2180 if (vlan_id) {
2181 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2182 vlan_id, qos, vf_id);
2183
2184 /* add new VLAN filter */
2185 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2186 if (ret) {
2187 dev_info(&vsi->back->pdev->dev,
2188 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2189 vsi->back->hw.aq.asq_last_status);
2190 goto error_pvid;
2191 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002192 /* Kill non-vlan MAC filters - ignore error return since
2193 * there might not be any non-vlan MAC filters.
2194 */
2195 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002196 }
2197
2198 if (ret) {
2199 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2200 goto error_pvid;
2201 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002202 /* The Port VLAN needs to be saved across resets the same as the
2203 * default LAN MAC address.
2204 */
2205 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002206 ret = 0;
2207
2208error_pvid:
2209 return ret;
2210}
2211
Mitch Williams84590fd2014-04-09 05:58:57 +00002212#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2213#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002214/**
2215 * i40e_ndo_set_vf_bw
2216 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002217 * @vf_id: VF identifier
2218 * @tx_rate: Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002219 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002220 * configure VF Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002221 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002222int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2223 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002224{
Mitch Williams6b192892014-03-06 09:02:29 +00002225 struct i40e_netdev_priv *np = netdev_priv(netdev);
2226 struct i40e_pf *pf = np->vsi->back;
2227 struct i40e_vsi *vsi;
2228 struct i40e_vf *vf;
2229 int speed = 0;
2230 int ret = 0;
2231
2232 /* validate the request */
2233 if (vf_id >= pf->num_alloc_vfs) {
2234 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2235 ret = -EINVAL;
2236 goto error;
2237 }
2238
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002239 if (min_tx_rate) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002240 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002241 min_tx_rate, vf_id);
2242 return -EINVAL;
2243 }
2244
Mitch Williams6b192892014-03-06 09:02:29 +00002245 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002246 vsi = pf->vsi[vf->lan_vsi_idx];
Mitch Williams6b192892014-03-06 09:02:29 +00002247 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2248 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2249 ret = -EINVAL;
2250 goto error;
2251 }
2252
2253 switch (pf->hw.phy.link_info.link_speed) {
2254 case I40E_LINK_SPEED_40GB:
2255 speed = 40000;
2256 break;
2257 case I40E_LINK_SPEED_10GB:
2258 speed = 10000;
2259 break;
2260 case I40E_LINK_SPEED_1GB:
2261 speed = 1000;
2262 break;
2263 default:
2264 break;
2265 }
2266
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002267 if (max_tx_rate > speed) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002268 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002269 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002270 ret = -EINVAL;
2271 goto error;
2272 }
2273
Mitch Williamsdac9b312014-04-09 05:58:56 +00002274 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2275 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2276 max_tx_rate = 50;
2277 }
2278
Mitch Williams6b192892014-03-06 09:02:29 +00002279 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002280 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2281 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2282 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002283 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002284 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002285 ret);
2286 ret = -EIO;
2287 goto error;
2288 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002289 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002290error:
2291 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002292}
2293
2294/**
2295 * i40e_ndo_get_vf_config
2296 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002297 * @vf_id: VF identifier
2298 * @ivi: VF configuration structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002299 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002300 * return VF configuration
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002301 **/
2302int i40e_ndo_get_vf_config(struct net_device *netdev,
2303 int vf_id, struct ifla_vf_info *ivi)
2304{
2305 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002306 struct i40e_vsi *vsi = np->vsi;
2307 struct i40e_pf *pf = vsi->back;
2308 struct i40e_vf *vf;
2309 int ret = 0;
2310
2311 /* validate the request */
2312 if (vf_id >= pf->num_alloc_vfs) {
2313 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2314 ret = -EINVAL;
2315 goto error_param;
2316 }
2317
2318 vf = &(pf->vf[vf_id]);
2319 /* first vsi is always the LAN vsi */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002320 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002321 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2322 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2323 ret = -EINVAL;
2324 goto error_param;
2325 }
2326
2327 ivi->vf = vf_id;
2328
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002329 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002330
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002331 ivi->max_tx_rate = vf->tx_rate;
2332 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002333 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2334 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2335 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00002336 if (vf->link_forced == false)
2337 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2338 else if (vf->link_up == true)
2339 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2340 else
2341 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00002342 ivi->spoofchk = vf->spoofchk;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002343 ret = 0;
2344
2345error_param:
2346 return ret;
2347}
Mitch Williams588aefa2014-02-11 08:27:49 +00002348
2349/**
2350 * i40e_ndo_set_vf_link_state
2351 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002352 * @vf_id: VF identifier
Mitch Williams588aefa2014-02-11 08:27:49 +00002353 * @link: required link state
2354 *
2355 * Set the link state of a specified VF, regardless of physical link state
2356 **/
2357int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2358{
2359 struct i40e_netdev_priv *np = netdev_priv(netdev);
2360 struct i40e_pf *pf = np->vsi->back;
2361 struct i40e_virtchnl_pf_event pfe;
2362 struct i40e_hw *hw = &pf->hw;
2363 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002364 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002365 int ret = 0;
2366
2367 /* validate the request */
2368 if (vf_id >= pf->num_alloc_vfs) {
2369 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2370 ret = -EINVAL;
2371 goto error_out;
2372 }
2373
2374 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07002375 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002376
2377 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2378 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2379
2380 switch (link) {
2381 case IFLA_VF_LINK_STATE_AUTO:
2382 vf->link_forced = false;
2383 pfe.event_data.link_event.link_status =
2384 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2385 pfe.event_data.link_event.link_speed =
2386 pf->hw.phy.link_info.link_speed;
2387 break;
2388 case IFLA_VF_LINK_STATE_ENABLE:
2389 vf->link_forced = true;
2390 vf->link_up = true;
2391 pfe.event_data.link_event.link_status = true;
2392 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2393 break;
2394 case IFLA_VF_LINK_STATE_DISABLE:
2395 vf->link_forced = true;
2396 vf->link_up = false;
2397 pfe.event_data.link_event.link_status = false;
2398 pfe.event_data.link_event.link_speed = 0;
2399 break;
2400 default:
2401 ret = -EINVAL;
2402 goto error_out;
2403 }
2404 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07002405 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00002406 0, (u8 *)&pfe, sizeof(pfe), NULL);
2407
2408error_out:
2409 return ret;
2410}
Mitch Williamsc674d122014-05-20 08:01:40 +00002411
2412/**
2413 * i40e_ndo_set_vf_spoofchk
2414 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002415 * @vf_id: VF identifier
Mitch Williamsc674d122014-05-20 08:01:40 +00002416 * @enable: flag to enable or disable feature
2417 *
2418 * Enable or disable VF spoof checking
2419 **/
Serey Konge6d90042014-07-12 07:28:14 +00002420int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00002421{
2422 struct i40e_netdev_priv *np = netdev_priv(netdev);
2423 struct i40e_vsi *vsi = np->vsi;
2424 struct i40e_pf *pf = vsi->back;
2425 struct i40e_vsi_context ctxt;
2426 struct i40e_hw *hw = &pf->hw;
2427 struct i40e_vf *vf;
2428 int ret = 0;
2429
2430 /* validate the request */
2431 if (vf_id >= pf->num_alloc_vfs) {
2432 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2433 ret = -EINVAL;
2434 goto out;
2435 }
2436
2437 vf = &(pf->vf[vf_id]);
2438
2439 if (enable == vf->spoofchk)
2440 goto out;
2441
2442 vf->spoofchk = enable;
2443 memset(&ctxt, 0, sizeof(ctxt));
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002444 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
Mitch Williamsc674d122014-05-20 08:01:40 +00002445 ctxt.pf_num = pf->hw.pf_id;
2446 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2447 if (enable)
Greg Rose30d71af2015-01-29 07:17:17 +00002448 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2449 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
Mitch Williamsc674d122014-05-20 08:01:40 +00002450 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2451 if (ret) {
2452 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
2453 ret);
2454 ret = -EIO;
2455 }
2456out:
2457 return ret;
2458}