blob: 63e62f9aec6ef45e73e08970d5fca6152ac102c3 [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));
Mitch Williamsb82bc49e2015-11-06 15:26:10 -0800293 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);
Kiran Patil21659032015-09-30 14:09:03 -0400550
551 spin_lock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsb7b713a2015-11-19 11:34:17 -0800552 if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
553 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
554 vf->port_vlan_id ? vf->port_vlan_id : -1,
555 true, false);
556 if (!f)
557 dev_info(&pf->pdev->dev,
558 "Could not add MAC filter %pM for VF %d\n",
559 vf->default_lan_addr.addr, vf->vf_id);
560 }
Mitch Williamse9951632015-04-27 14:57:13 -0400561 f = i40e_add_filter(vsi, brdcast,
562 vf->port_vlan_id ? vf->port_vlan_id : -1,
Greg Rose1a103702013-11-28 06:42:39 +0000563 true, false);
564 if (!f)
565 dev_info(&pf->pdev->dev,
566 "Could not allocate VF broadcast filter\n");
Kiran Patil21659032015-09-30 14:09:03 -0400567 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000568 }
Neerav Parikh6dbbbfb2013-11-26 10:49:24 +0000569
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000570 /* program mac filter */
Jesse Brandeburg17652c62015-11-05 17:01:02 -0800571 ret = i40e_sync_vsi_filters(vsi);
Mitch Williamsfd1646e2014-02-13 03:48:44 -0800572 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000573 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000574
Mitch Williams6b192892014-03-06 09:02:29 +0000575 /* Set VF bandwidth if specified */
576 if (vf->tx_rate) {
577 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
578 vf->tx_rate / 50, 0, NULL);
579 if (ret)
580 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
581 vf->vf_id, ret);
582 }
583
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000584error_alloc_vsi_res:
585 return ret;
586}
587
588/**
Mitch Williams805bd5b2013-11-28 06:39:26 +0000589 * i40e_enable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000590 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000591 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000592 * enable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000593 **/
594static void i40e_enable_vf_mappings(struct i40e_vf *vf)
595{
596 struct i40e_pf *pf = vf->pf;
597 struct i40e_hw *hw = &pf->hw;
598 u32 reg, total_queue_pairs = 0;
599 int j;
600
601 /* Tell the hardware we're using noncontiguous mapping. HW requires
602 * that VF queues be mapped using this method, even when they are
603 * contiguous in real life
604 */
605 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
606 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
607
608 /* enable VF vplan_qtable mappings */
609 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
610 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
611
612 /* map PF queues to VF queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700613 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
614 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400615
Mitch Williams805bd5b2013-11-28 06:39:26 +0000616 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
617 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
618 total_queue_pairs++;
619 }
620
621 /* map PF queues to VSI */
622 for (j = 0; j < 7; j++) {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700623 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000624 reg = 0x07FF07FF; /* unused */
625 } else {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700626 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000627 j * 2);
628 reg = qid;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700629 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000630 (j * 2) + 1);
631 reg |= qid << 16;
632 }
633 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
634 }
635
636 i40e_flush(hw);
637}
638
639/**
640 * i40e_disable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000641 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000642 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000643 * disable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000644 **/
645static void i40e_disable_vf_mappings(struct i40e_vf *vf)
646{
647 struct i40e_pf *pf = vf->pf;
648 struct i40e_hw *hw = &pf->hw;
649 int i;
650
651 /* disable qp mappings */
652 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
653 for (i = 0; i < I40E_MAX_VSI_QP; i++)
654 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
655 I40E_QUEUE_END_OF_LIST);
656 i40e_flush(hw);
657}
658
659/**
660 * i40e_free_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000661 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000662 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000663 * free VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000664 **/
665static void i40e_free_vf_res(struct i40e_vf *vf)
666{
667 struct i40e_pf *pf = vf->pf;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000668 struct i40e_hw *hw = &pf->hw;
669 u32 reg_idx, reg;
670 int i, msix_vf;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000671
672 /* free vsi & disconnect it from the parent uplink */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700673 if (vf->lan_vsi_idx) {
674 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
675 vf->lan_vsi_idx = 0;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000676 vf->lan_vsi_id = 0;
677 }
Mitch Williams9347eb72014-02-11 08:26:32 +0000678 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
679
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000680 /* disable interrupts so the VF starts in a known state */
681 for (i = 0; i < msix_vf; i++) {
682 /* format is same for both registers */
683 if (0 == i)
684 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
685 else
686 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
687 (vf->vf_id))
688 + (i - 1));
689 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
690 i40e_flush(hw);
691 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000692
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000693 /* clear the irq settings */
694 for (i = 0; i < msix_vf; i++) {
695 /* format is same for both registers */
696 if (0 == i)
697 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
698 else
699 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
700 (vf->vf_id))
701 + (i - 1));
702 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
703 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
704 wr32(hw, reg_idx, reg);
705 i40e_flush(hw);
706 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000707 /* reset some of the state varibles keeping
708 * track of the resources
709 */
710 vf->num_queue_pairs = 0;
711 vf->vf_states = 0;
Mitch Williams21be99e2015-08-31 19:54:48 -0400712 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000713}
714
715/**
716 * i40e_alloc_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000717 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000718 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000719 * allocate VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000720 **/
721static int i40e_alloc_vf_res(struct i40e_vf *vf)
722{
723 struct i40e_pf *pf = vf->pf;
724 int total_queue_pairs = 0;
725 int ret;
726
727 /* allocate hw vsi context & associated resources */
728 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
729 if (ret)
730 goto error_alloc;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700731 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000732 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
733
734 /* store the total qps number for the runtime
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000735 * VF req validation
Mitch Williams805bd5b2013-11-28 06:39:26 +0000736 */
737 vf->num_queue_pairs = total_queue_pairs;
738
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000739 /* VF is now completely initialized */
Mitch Williams805bd5b2013-11-28 06:39:26 +0000740 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
741
742error_alloc:
743 if (ret)
744 i40e_free_vf_res(vf);
745
746 return ret;
747}
748
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000749#define VF_DEVICE_STATUS 0xAA
750#define VF_TRANS_PENDING_MASK 0x20
751/**
752 * i40e_quiesce_vf_pci
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000753 * @vf: pointer to the VF structure
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000754 *
755 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
756 * if the transactions never clear.
757 **/
758static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
759{
760 struct i40e_pf *pf = vf->pf;
761 struct i40e_hw *hw = &pf->hw;
762 int vf_abs_id, i;
763 u32 reg;
764
Mitch Williamsb141d612013-11-28 06:39:36 +0000765 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000766
767 wr32(hw, I40E_PF_PCI_CIAA,
768 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
769 for (i = 0; i < 100; i++) {
770 reg = rd32(hw, I40E_PF_PCI_CIAD);
771 if ((reg & VF_TRANS_PENDING_MASK) == 0)
772 return 0;
773 udelay(1);
774 }
775 return -EIO;
776}
777
Mitch Williams805bd5b2013-11-28 06:39:26 +0000778/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000779 * i40e_reset_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000780 * @vf: pointer to the VF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000781 * @flr: VFLR was issued or not
782 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000783 * reset the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000784 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000785void i40e_reset_vf(struct i40e_vf *vf, bool flr)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000786{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000787 struct i40e_pf *pf = vf->pf;
788 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000789 bool rsd = false;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000790 int i;
791 u32 reg;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000792
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000793 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
794 return;
795
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000796 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000797 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
798
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000799 /* In the case of a VFLR, the HW has already reset the VF and we
800 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000801 */
802 if (!flr) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000803 /* reset VF using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000804 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
805 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000806 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
807 i40e_flush(hw);
808 }
809
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000810 if (i40e_quiesce_vf_pci(vf))
811 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
812 vf->vf_id);
813
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000814 /* poll VPGEN_VFRSTAT reg to make sure
815 * that reset is complete
816 */
Mitch Williams1750a222015-01-09 11:18:13 +0000817 for (i = 0; i < 10; i++) {
818 /* VF reset requires driver to first reset the VF and then
819 * poll the status register to make sure that the reset
820 * completed successfully. Due to internal HW FIFO flushes,
821 * we must wait 10ms before the register will be valid.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000822 */
Mitch Williams1750a222015-01-09 11:18:13 +0000823 usleep_range(10000, 20000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000824 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
825 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
826 rsd = true;
827 break;
828 }
829 }
830
Anjali Singhai Jain57175ac2015-04-07 19:45:35 -0400831 if (flr)
832 usleep_range(10000, 20000);
833
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000834 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000835 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000836 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000837 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000838 /* clear the reset bit in the VPGEN_VFRTRIG reg */
839 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
840 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
841 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000842
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000843 /* On initial reset, we won't have any queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700844 if (vf->lan_vsi_idx == 0)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000845 goto complete_reset;
846
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700847 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000848complete_reset:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000849 /* reallocate VF resources to reset the VSI state */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000850 i40e_free_vf_res(vf);
Mitch Williams21be99e2015-08-31 19:54:48 -0400851 if (!i40e_alloc_vf_res(vf)) {
852 i40e_enable_vf_mappings(vf);
853 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
854 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
855 }
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000856 /* tell the VF the reset is done */
857 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
858 i40e_flush(hw);
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000859 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000860}
Greg Rosec3542292013-12-13 08:38:38 +0000861
862/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000863 * i40e_free_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000864 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000865 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000866 * free VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000867 **/
868void i40e_free_vfs(struct i40e_pf *pf)
869{
Mitch Williamsf7414532013-11-28 06:39:40 +0000870 struct i40e_hw *hw = &pf->hw;
871 u32 reg_idx, bit_idx;
872 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000873
874 if (!pf->vf)
875 return;
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000876 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
877 usleep_range(1000, 2000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000878
Mitch Williams44434632015-04-07 11:32:55 -0700879 for (i = 0; i < pf->num_alloc_vfs; i++)
880 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
881 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
882 false);
883
Mitch Williams0325fca2015-08-26 15:14:09 -0400884 for (i = 0; i < pf->num_alloc_vfs; i++)
885 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
886 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
887 false);
888
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000889 /* Disable IOV before freeing resources. This lets any VF drivers
890 * running in the host get themselves cleaned up before we yank
891 * the carpet out from underneath their feet.
892 */
893 if (!pci_vfs_assigned(pf->pdev))
894 pci_disable_sriov(pf->pdev);
Mitch Williams6d7b9672015-03-31 00:45:02 -0700895 else
896 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000897
898 msleep(20); /* let any messages in transit get finished up */
899
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000900 /* free up VF resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000901 tmp = pf->num_alloc_vfs;
902 pf->num_alloc_vfs = 0;
903 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000904 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
905 i40e_free_vf_res(&pf->vf[i]);
906 /* disable qp mappings */
907 i40e_disable_vf_mappings(&pf->vf[i]);
908 }
909
910 kfree(pf->vf);
911 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000912
Mitch Williams9e5634d2014-04-04 04:43:14 +0000913 /* This check is for when the driver is unloaded while VFs are
914 * assigned. Setting the number of VFs to 0 through sysfs is caught
915 * before this function ever gets called.
916 */
Ethan Zhaoc24817b2014-07-22 18:36:43 +0000917 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williamsf7414532013-11-28 06:39:40 +0000918 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
919 * work correctly when SR-IOV gets re-enabled.
920 */
921 for (vf_id = 0; vf_id < tmp; vf_id++) {
922 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
923 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400924 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Mitch Williamsf7414532013-11-28 06:39:40 +0000925 }
Greg Rosec3542292013-12-13 08:38:38 +0000926 }
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000927 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000928}
929
930#ifdef CONFIG_PCI_IOV
931/**
932 * i40e_alloc_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000933 * @pf: pointer to the PF structure
934 * @num_alloc_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000935 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000936 * allocate VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000937 **/
Mitch Williams4aeec012014-02-13 03:48:47 -0800938int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000939{
940 struct i40e_vf *vfs;
941 int i, ret = 0;
942
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000943 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000944 i40e_irq_dynamic_disable_icr0(pf);
945
Mitch Williams4aeec012014-02-13 03:48:47 -0800946 /* Check to see if we're just allocating resources for extant VFs */
947 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
948 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
949 if (ret) {
Akeem G Abodunrinde445b32015-10-01 14:37:40 -0400950 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
Mitch Williams4aeec012014-02-13 03:48:47 -0800951 pf->num_alloc_vfs = 0;
952 goto err_iov;
953 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000954 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000955 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +0000956 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000957 if (!vfs) {
958 ret = -ENOMEM;
959 goto err_alloc;
960 }
Mitch Williamsc674d122014-05-20 08:01:40 +0000961 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000962
963 /* apply default profile */
964 for (i = 0; i < num_alloc_vfs; i++) {
965 vfs[i].pf = pf;
966 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
967 vfs[i].vf_id = i;
968
969 /* assign default capabilities */
970 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +0000971 vfs[i].spoofchk = true;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000972 /* VF resources get allocated during reset */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000973 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000974
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000975 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000976 pf->num_alloc_vfs = num_alloc_vfs;
977
978err_alloc:
979 if (ret)
980 i40e_free_vfs(pf);
981err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000982 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000983 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000984 return ret;
985}
986
987#endif
988/**
989 * i40e_pci_sriov_enable
990 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000991 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000992 *
993 * Enable or change the number of VFs
994 **/
995static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
996{
997#ifdef CONFIG_PCI_IOV
998 struct i40e_pf *pf = pci_get_drvdata(pdev);
999 int pre_existing_vfs = pci_num_vf(pdev);
1000 int err = 0;
1001
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001002 if (test_bit(__I40E_TESTING, &pf->state)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001003 dev_warn(&pdev->dev,
1004 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1005 err = -EPERM;
1006 goto err_out;
1007 }
1008
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001009 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1010 i40e_free_vfs(pf);
1011 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1012 goto out;
1013
1014 if (num_vfs > pf->num_req_vfs) {
Mitch Williams96c8d072015-08-27 11:42:35 -04001015 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1016 num_vfs, pf->num_req_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001017 err = -EPERM;
1018 goto err_out;
1019 }
1020
Mitch Williams96c8d072015-08-27 11:42:35 -04001021 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001022 err = i40e_alloc_vfs(pf, num_vfs);
1023 if (err) {
1024 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1025 goto err_out;
1026 }
1027
1028out:
1029 return num_vfs;
1030
1031err_out:
1032 return err;
1033#endif
1034 return 0;
1035}
1036
1037/**
1038 * i40e_pci_sriov_configure
1039 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001040 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001041 *
1042 * Enable or change the number of VFs. Called when the user updates the number
1043 * of VFs in sysfs.
1044 **/
1045int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1046{
1047 struct i40e_pf *pf = pci_get_drvdata(pdev);
1048
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001049 if (num_vfs) {
1050 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1051 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1052 i40e_do_reset_safe(pf,
1053 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1054 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001055 return i40e_pci_sriov_enable(pdev, num_vfs);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001056 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001057
Ethan Zhaoc24817b2014-07-22 18:36:43 +00001058 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williams9e5634d2014-04-04 04:43:14 +00001059 i40e_free_vfs(pf);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001060 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1061 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Mitch Williams9e5634d2014-04-04 04:43:14 +00001062 } else {
1063 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1064 return -EINVAL;
1065 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001066 return 0;
1067}
1068
1069/***********************virtual channel routines******************/
1070
1071/**
1072 * i40e_vc_send_msg_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001073 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001074 * @v_opcode: virtual channel opcode
1075 * @v_retval: virtual channel return value
1076 * @msg: pointer to the msg buffer
1077 * @msglen: msg length
1078 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001079 * send msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001080 **/
1081static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1082 u32 v_retval, u8 *msg, u16 msglen)
1083{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001084 struct i40e_pf *pf;
1085 struct i40e_hw *hw;
1086 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001087 i40e_status aq_ret;
1088
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001089 /* validate the request */
1090 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1091 return -EINVAL;
1092
1093 pf = vf->pf;
1094 hw = &pf->hw;
1095 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1096
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001097 /* single place to detect unsuccessful return values */
1098 if (v_retval) {
1099 vf->num_invalid_msgs++;
Mitch Williamse7ffb722015-10-26 19:44:37 -04001100 dev_err(&pf->pdev->dev, "VF %d failed opcode %d, error: %d\n",
1101 vf->vf_id, v_opcode, v_retval);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001102 if (vf->num_invalid_msgs >
1103 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1104 dev_err(&pf->pdev->dev,
1105 "Number of invalid messages exceeded for VF %d\n",
1106 vf->vf_id);
1107 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1108 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1109 }
1110 } else {
1111 vf->num_valid_msgs++;
Jingjing Wu5d38c932015-09-28 14:12:39 -04001112 /* reset the invalid counter, if a valid message is received. */
1113 vf->num_invalid_msgs = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001114 }
1115
Ashish Shahf19efbb2014-08-01 13:27:06 -07001116 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001117 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001118 if (aq_ret) {
1119 dev_err(&pf->pdev->dev,
1120 "Unable to send the message to VF %d aq_err %d\n",
1121 vf->vf_id, pf->hw.aq.asq_last_status);
1122 return -EIO;
1123 }
1124
1125 return 0;
1126}
1127
1128/**
1129 * i40e_vc_send_resp_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001130 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001131 * @opcode: operation code
1132 * @retval: return value
1133 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001134 * send resp msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001135 **/
1136static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1137 enum i40e_virtchnl_ops opcode,
1138 i40e_status retval)
1139{
1140 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1141}
1142
1143/**
1144 * i40e_vc_get_version_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001145 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001146 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001147 * called from the VF to request the API version used by the PF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001148 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001149static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001150{
1151 struct i40e_virtchnl_version_info info = {
1152 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1153 };
1154
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001155 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
Mitch Williams606a5482015-06-04 16:24:00 -04001156 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1157 if (VF_IS_V10(vf))
1158 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001159 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1160 I40E_SUCCESS, (u8 *)&info,
1161 sizeof(struct
1162 i40e_virtchnl_version_info));
1163}
1164
1165/**
1166 * i40e_vc_get_vf_resources_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001167 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001168 * @msg: pointer to the msg buffer
1169 * @msglen: msg length
1170 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001171 * called from the VF to request its resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001172 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001173static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001174{
1175 struct i40e_virtchnl_vf_resource *vfres = NULL;
1176 struct i40e_pf *pf = vf->pf;
1177 i40e_status aq_ret = 0;
1178 struct i40e_vsi *vsi;
1179 int i = 0, len = 0;
1180 int num_vsis = 1;
1181 int ret;
1182
1183 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1184 aq_ret = I40E_ERR_PARAM;
1185 goto err;
1186 }
1187
1188 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1189 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1190
1191 vfres = kzalloc(len, GFP_KERNEL);
1192 if (!vfres) {
1193 aq_ret = I40E_ERR_NO_MEMORY;
1194 len = 0;
1195 goto err;
1196 }
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001197 if (VF_IS_V11(vf))
1198 vf->driver_caps = *(u32 *)msg;
1199 else
1200 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1201 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1202 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001203
1204 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001205 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001206 if (!vsi->info.pvid)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001207 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1208 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1209 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1210 vfres->vf_offload_flags |=
1211 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1212 } else {
1213 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1214 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001215
1216 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING)
1217 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1218
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001219 vfres->num_vsis = num_vsis;
1220 vfres->num_queue_pairs = vf->num_queue_pairs;
1221 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001222 if (vf->lan_vsi_idx) {
1223 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001224 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04001225 vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs;
1226 /* VFs only use TC 0 */
1227 vfres->vsi_res[i].qset_handle
1228 = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001229 ether_addr_copy(vfres->vsi_res[i].default_mac_addr,
1230 vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001231 i++;
1232 }
1233 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1234
1235err:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001236 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001237 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1238 aq_ret, (u8 *)vfres, len);
1239
1240 kfree(vfres);
1241 return ret;
1242}
1243
1244/**
1245 * i40e_vc_reset_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001246 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001247 * @msg: pointer to the msg buffer
1248 * @msglen: msg length
1249 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001250 * called from the VF to reset itself,
1251 * unlike other virtchnl messages, PF driver
1252 * doesn't send the response back to the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001253 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001254static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001255{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001256 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1257 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001258}
1259
1260/**
1261 * i40e_vc_config_promiscuous_mode_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001262 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001263 * @msg: pointer to the msg buffer
1264 * @msglen: msg length
1265 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001266 * called from the VF to configure the promiscuous mode of
1267 * VF vsis
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001268 **/
1269static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1270 u8 *msg, u16 msglen)
1271{
1272 struct i40e_virtchnl_promisc_info *info =
1273 (struct i40e_virtchnl_promisc_info *)msg;
1274 struct i40e_pf *pf = vf->pf;
1275 struct i40e_hw *hw = &pf->hw;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001276 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001277 bool allmulti = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001278 i40e_status aq_ret;
1279
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001280 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001281 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1282 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1283 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001284 (vsi->type != I40E_VSI_FCOE)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001285 aq_ret = I40E_ERR_PARAM;
1286 goto error_param;
1287 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001288 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1289 allmulti = true;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001290 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001291 allmulti, NULL);
1292
1293error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001294 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001295 return i40e_vc_send_resp_to_vf(vf,
1296 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1297 aq_ret);
1298}
1299
1300/**
1301 * i40e_vc_config_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001302 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001303 * @msg: pointer to the msg buffer
1304 * @msglen: msg length
1305 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001306 * called from the VF to configure the rx/tx
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001307 * queues
1308 **/
1309static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1310{
1311 struct i40e_virtchnl_vsi_queue_config_info *qci =
1312 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1313 struct i40e_virtchnl_queue_pair_info *qpi;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001314 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001315 u16 vsi_id, vsi_queue_id;
1316 i40e_status aq_ret = 0;
1317 int i;
1318
1319 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1320 aq_ret = I40E_ERR_PARAM;
1321 goto error_param;
1322 }
1323
1324 vsi_id = qci->vsi_id;
1325 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1326 aq_ret = I40E_ERR_PARAM;
1327 goto error_param;
1328 }
1329 for (i = 0; i < qci->num_queue_pairs; i++) {
1330 qpi = &qci->qpair[i];
1331 vsi_queue_id = qpi->txq.queue_id;
1332 if ((qpi->txq.vsi_id != vsi_id) ||
1333 (qpi->rxq.vsi_id != vsi_id) ||
1334 (qpi->rxq.queue_id != vsi_queue_id) ||
1335 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1336 aq_ret = I40E_ERR_PARAM;
1337 goto error_param;
1338 }
1339
1340 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1341 &qpi->rxq) ||
1342 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1343 &qpi->txq)) {
1344 aq_ret = I40E_ERR_PARAM;
1345 goto error_param;
1346 }
1347 }
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001348 /* set vsi num_queue_pairs in use to num configured by VF */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001349 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001350
1351error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001352 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001353 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1354 aq_ret);
1355}
1356
1357/**
1358 * i40e_vc_config_irq_map_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001359 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001360 * @msg: pointer to the msg buffer
1361 * @msglen: msg length
1362 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001363 * called from the VF to configure the irq to
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001364 * queue map
1365 **/
1366static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1367{
1368 struct i40e_virtchnl_irq_map_info *irqmap_info =
1369 (struct i40e_virtchnl_irq_map_info *)msg;
1370 struct i40e_virtchnl_vector_map *map;
1371 u16 vsi_id, vsi_queue_id, vector_id;
1372 i40e_status aq_ret = 0;
1373 unsigned long tempmap;
1374 int i;
1375
1376 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1377 aq_ret = I40E_ERR_PARAM;
1378 goto error_param;
1379 }
1380
1381 for (i = 0; i < irqmap_info->num_vectors; i++) {
1382 map = &irqmap_info->vecmap[i];
1383
1384 vector_id = map->vector_id;
1385 vsi_id = map->vsi_id;
1386 /* validate msg params */
1387 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1388 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1389 aq_ret = I40E_ERR_PARAM;
1390 goto error_param;
1391 }
1392
1393 /* lookout for the invalid queue index */
1394 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001395 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001396 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1397 vsi_queue_id)) {
1398 aq_ret = I40E_ERR_PARAM;
1399 goto error_param;
1400 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001401 }
1402
1403 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001404 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001405 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1406 vsi_queue_id)) {
1407 aq_ret = I40E_ERR_PARAM;
1408 goto error_param;
1409 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001410 }
1411
1412 i40e_config_irq_link_list(vf, vsi_id, map);
1413 }
1414error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001415 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001416 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1417 aq_ret);
1418}
1419
1420/**
1421 * i40e_vc_enable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001422 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001423 * @msg: pointer to the msg buffer
1424 * @msglen: msg length
1425 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001426 * called from the VF to enable all or specific queue(s)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001427 **/
1428static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1429{
1430 struct i40e_virtchnl_queue_select *vqs =
1431 (struct i40e_virtchnl_queue_select *)msg;
1432 struct i40e_pf *pf = vf->pf;
1433 u16 vsi_id = vqs->vsi_id;
1434 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001435
1436 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1437 aq_ret = I40E_ERR_PARAM;
1438 goto error_param;
1439 }
1440
1441 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1442 aq_ret = I40E_ERR_PARAM;
1443 goto error_param;
1444 }
1445
1446 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1447 aq_ret = I40E_ERR_PARAM;
1448 goto error_param;
1449 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001450
1451 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
Mitch Williams88f65632013-11-28 06:39:28 +00001452 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001453error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001454 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001455 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1456 aq_ret);
1457}
1458
1459/**
1460 * i40e_vc_disable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001461 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001462 * @msg: pointer to the msg buffer
1463 * @msglen: msg length
1464 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001465 * called from the VF to disable all or specific
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001466 * queue(s)
1467 **/
1468static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1469{
1470 struct i40e_virtchnl_queue_select *vqs =
1471 (struct i40e_virtchnl_queue_select *)msg;
1472 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001473 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001474
1475 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1476 aq_ret = I40E_ERR_PARAM;
1477 goto error_param;
1478 }
1479
1480 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1481 aq_ret = I40E_ERR_PARAM;
1482 goto error_param;
1483 }
1484
1485 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1486 aq_ret = I40E_ERR_PARAM;
1487 goto error_param;
1488 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001489
1490 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
Mitch Williams88f65632013-11-28 06:39:28 +00001491 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001492
1493error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001494 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001495 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1496 aq_ret);
1497}
1498
1499/**
1500 * i40e_vc_get_stats_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001501 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001502 * @msg: pointer to the msg buffer
1503 * @msglen: msg length
1504 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001505 * called from the VF to get vsi stats
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001506 **/
1507static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1508{
1509 struct i40e_virtchnl_queue_select *vqs =
1510 (struct i40e_virtchnl_queue_select *)msg;
1511 struct i40e_pf *pf = vf->pf;
1512 struct i40e_eth_stats stats;
1513 i40e_status aq_ret = 0;
1514 struct i40e_vsi *vsi;
1515
1516 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1517
1518 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1519 aq_ret = I40E_ERR_PARAM;
1520 goto error_param;
1521 }
1522
1523 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1524 aq_ret = I40E_ERR_PARAM;
1525 goto error_param;
1526 }
1527
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001528 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001529 if (!vsi) {
1530 aq_ret = I40E_ERR_PARAM;
1531 goto error_param;
1532 }
1533 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001534 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001535
1536error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001537 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001538 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1539 (u8 *)&stats, sizeof(stats));
1540}
1541
1542/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001543 * i40e_check_vf_permission
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001544 * @vf: pointer to the VF info
Greg Rosef657a6e2013-11-28 06:39:42 +00001545 * @macaddr: pointer to the MAC Address being checked
1546 *
1547 * Check if the VF has permission to add or delete unicast MAC address
1548 * filters and return error code -EPERM if not. Then check if the
1549 * address filter requested is broadcast or zero and if so return
1550 * an invalid MAC address error code.
1551 **/
1552static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1553{
1554 struct i40e_pf *pf = vf->pf;
1555 int ret = 0;
1556
1557 if (is_broadcast_ether_addr(macaddr) ||
1558 is_zero_ether_addr(macaddr)) {
1559 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1560 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001561 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1562 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001563 /* If the host VMM administrator has set the VF MAC address
1564 * administratively via the ndo_set_vf_mac command then deny
1565 * permission to the VF to add or delete unicast MAC addresses.
Greg Rose5017c2a2013-12-07 10:36:54 +00001566 * The VF may request to set the MAC address filter already
1567 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001568 */
1569 dev_err(&pf->pdev->dev,
1570 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1571 ret = -EPERM;
1572 }
1573 return ret;
1574}
1575
1576/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001577 * i40e_vc_add_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001578 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001579 * @msg: pointer to the msg buffer
1580 * @msglen: msg length
1581 *
1582 * add guest mac address filter
1583 **/
1584static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1585{
1586 struct i40e_virtchnl_ether_addr_list *al =
1587 (struct i40e_virtchnl_ether_addr_list *)msg;
1588 struct i40e_pf *pf = vf->pf;
1589 struct i40e_vsi *vsi = NULL;
1590 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001591 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001592 int i;
1593
1594 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1595 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1596 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001597 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001598 goto error_param;
1599 }
1600
1601 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001602 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1603 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001604 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001605 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001606 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001607
Kiran Patil21659032015-09-30 14:09:03 -04001608 /* Lock once, because all function inside for loop accesses VSI's
1609 * MAC filter list which needs to be protected using same lock.
1610 */
1611 spin_lock_bh(&vsi->mac_filter_list_lock);
1612
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001613 /* add new addresses to the list */
1614 for (i = 0; i < al->num_elements; i++) {
1615 struct i40e_mac_filter *f;
1616
1617 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001618 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001619 if (i40e_is_vsi_in_vlan(vsi))
1620 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1621 true, false);
1622 else
1623 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1624 true, false);
1625 }
1626
1627 if (!f) {
1628 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04001629 "Unable to add MAC filter %pM for VF %d\n",
1630 al->list[i].addr, vf->vf_id);
Greg Rosef657a6e2013-11-28 06:39:42 +00001631 ret = I40E_ERR_PARAM;
Kiran Patil21659032015-09-30 14:09:03 -04001632 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001633 goto error_param;
1634 }
1635 }
Kiran Patil21659032015-09-30 14:09:03 -04001636 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001637
1638 /* program the updated filter list */
Mitch Williamsea02e902015-11-09 15:35:50 -08001639 ret = i40e_sync_vsi_filters(vsi);
1640 if (ret)
1641 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
1642 vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001643
1644error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001645 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001646 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001647 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001648}
1649
1650/**
1651 * i40e_vc_del_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001652 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001653 * @msg: pointer to the msg buffer
1654 * @msglen: msg length
1655 *
1656 * remove guest mac address filter
1657 **/
1658static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1659{
1660 struct i40e_virtchnl_ether_addr_list *al =
1661 (struct i40e_virtchnl_ether_addr_list *)msg;
1662 struct i40e_pf *pf = vf->pf;
1663 struct i40e_vsi *vsi = NULL;
1664 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001665 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001666 int i;
1667
1668 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1669 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1670 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001671 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001672 goto error_param;
1673 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001674
1675 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00001676 if (is_broadcast_ether_addr(al->list[i].addr) ||
1677 is_zero_ether_addr(al->list[i].addr)) {
Mitch Williams8d8f2292015-10-21 19:47:11 -04001678 dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
1679 al->list[i].addr, vf->vf_id);
Mitch Williams700bbf62013-12-21 05:44:45 +00001680 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00001681 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00001682 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001683 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001684 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001685
Kiran Patil21659032015-09-30 14:09:03 -04001686 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001687 /* delete addresses from the list */
1688 for (i = 0; i < al->num_elements; i++)
Mitch Williamsb36e9ab2015-11-19 11:34:16 -08001689 if (i40e_del_mac_all_vlan(vsi, al->list[i].addr, true, false)) {
1690 ret = I40E_ERR_INVALID_MAC_ADDR;
1691 spin_unlock_bh(&vsi->mac_filter_list_lock);
1692 goto error_param;
1693 }
1694
Kiran Patil21659032015-09-30 14:09:03 -04001695 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001696
1697 /* program the updated filter list */
Mitch Williamsea02e902015-11-09 15:35:50 -08001698 ret = i40e_sync_vsi_filters(vsi);
1699 if (ret)
1700 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
1701 vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001702
1703error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001704 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001705 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001706 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001707}
1708
1709/**
1710 * i40e_vc_add_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001711 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001712 * @msg: pointer to the msg buffer
1713 * @msglen: msg length
1714 *
1715 * program guest vlan id
1716 **/
1717static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1718{
1719 struct i40e_virtchnl_vlan_filter_list *vfl =
1720 (struct i40e_virtchnl_vlan_filter_list *)msg;
1721 struct i40e_pf *pf = vf->pf;
1722 struct i40e_vsi *vsi = NULL;
1723 u16 vsi_id = vfl->vsi_id;
1724 i40e_status aq_ret = 0;
1725 int i;
1726
1727 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1728 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1729 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1730 aq_ret = I40E_ERR_PARAM;
1731 goto error_param;
1732 }
1733
1734 for (i = 0; i < vfl->num_elements; i++) {
1735 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1736 aq_ret = I40E_ERR_PARAM;
1737 dev_err(&pf->pdev->dev,
1738 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1739 goto error_param;
1740 }
1741 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001742 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001743 if (vsi->info.pvid) {
1744 aq_ret = I40E_ERR_PARAM;
1745 goto error_param;
1746 }
1747
1748 i40e_vlan_stripping_enable(vsi);
1749 for (i = 0; i < vfl->num_elements; i++) {
1750 /* add new VLAN filter */
1751 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001752
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001753 if (ret)
1754 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04001755 "Unable to add VLAN filter %d for VF %d, error %d\n",
1756 vfl->vlan_id[i], vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001757 }
1758
1759error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001760 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001761 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1762}
1763
1764/**
1765 * i40e_vc_remove_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001766 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001767 * @msg: pointer to the msg buffer
1768 * @msglen: msg length
1769 *
1770 * remove programmed guest vlan id
1771 **/
1772static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1773{
1774 struct i40e_virtchnl_vlan_filter_list *vfl =
1775 (struct i40e_virtchnl_vlan_filter_list *)msg;
1776 struct i40e_pf *pf = vf->pf;
1777 struct i40e_vsi *vsi = NULL;
1778 u16 vsi_id = vfl->vsi_id;
1779 i40e_status aq_ret = 0;
1780 int i;
1781
1782 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1783 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1784 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1785 aq_ret = I40E_ERR_PARAM;
1786 goto error_param;
1787 }
1788
1789 for (i = 0; i < vfl->num_elements; i++) {
1790 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1791 aq_ret = I40E_ERR_PARAM;
1792 goto error_param;
1793 }
1794 }
1795
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001796 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001797 if (vsi->info.pvid) {
1798 aq_ret = I40E_ERR_PARAM;
1799 goto error_param;
1800 }
1801
1802 for (i = 0; i < vfl->num_elements; i++) {
1803 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001804
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001805 if (ret)
1806 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04001807 "Unable to delete VLAN filter %d for VF %d, error %d\n",
1808 vfl->vlan_id[i], vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001809 }
1810
1811error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001812 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001813 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1814}
1815
1816/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001817 * i40e_vc_validate_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001818 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001819 * @msg: pointer to the msg buffer
1820 * @msglen: msg length
1821 * @msghndl: msg handle
1822 *
1823 * validate msg
1824 **/
1825static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1826 u32 v_retval, u8 *msg, u16 msglen)
1827{
1828 bool err_msg_format = false;
1829 int valid_len;
1830
1831 /* Check if VF is disabled. */
1832 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1833 return I40E_ERR_PARAM;
1834
1835 /* Validate message length. */
1836 switch (v_opcode) {
1837 case I40E_VIRTCHNL_OP_VERSION:
1838 valid_len = sizeof(struct i40e_virtchnl_version_info);
1839 break;
1840 case I40E_VIRTCHNL_OP_RESET_VF:
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001841 valid_len = 0;
1842 break;
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001843 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1844 if (VF_IS_V11(vf))
1845 valid_len = sizeof(u32);
1846 else
1847 valid_len = 0;
1848 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001849 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1850 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1851 break;
1852 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1853 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1854 break;
1855 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1856 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1857 if (msglen >= valid_len) {
1858 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1859 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1860 valid_len += (vqc->num_queue_pairs *
1861 sizeof(struct
1862 i40e_virtchnl_queue_pair_info));
1863 if (vqc->num_queue_pairs == 0)
1864 err_msg_format = true;
1865 }
1866 break;
1867 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1868 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1869 if (msglen >= valid_len) {
1870 struct i40e_virtchnl_irq_map_info *vimi =
1871 (struct i40e_virtchnl_irq_map_info *)msg;
1872 valid_len += (vimi->num_vectors *
1873 sizeof(struct i40e_virtchnl_vector_map));
1874 if (vimi->num_vectors == 0)
1875 err_msg_format = true;
1876 }
1877 break;
1878 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1879 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1880 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1881 break;
1882 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1883 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1884 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1885 if (msglen >= valid_len) {
1886 struct i40e_virtchnl_ether_addr_list *veal =
1887 (struct i40e_virtchnl_ether_addr_list *)msg;
1888 valid_len += veal->num_elements *
1889 sizeof(struct i40e_virtchnl_ether_addr);
1890 if (veal->num_elements == 0)
1891 err_msg_format = true;
1892 }
1893 break;
1894 case I40E_VIRTCHNL_OP_ADD_VLAN:
1895 case I40E_VIRTCHNL_OP_DEL_VLAN:
1896 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1897 if (msglen >= valid_len) {
1898 struct i40e_virtchnl_vlan_filter_list *vfl =
1899 (struct i40e_virtchnl_vlan_filter_list *)msg;
1900 valid_len += vfl->num_elements * sizeof(u16);
1901 if (vfl->num_elements == 0)
1902 err_msg_format = true;
1903 }
1904 break;
1905 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1906 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1907 break;
1908 case I40E_VIRTCHNL_OP_GET_STATS:
1909 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1910 break;
1911 /* These are always errors coming from the VF. */
1912 case I40E_VIRTCHNL_OP_EVENT:
1913 case I40E_VIRTCHNL_OP_UNKNOWN:
1914 default:
1915 return -EPERM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001916 }
1917 /* few more checks */
1918 if ((valid_len != msglen) || (err_msg_format)) {
1919 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1920 return -EINVAL;
1921 } else {
1922 return 0;
1923 }
1924}
1925
1926/**
1927 * i40e_vc_process_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001928 * @pf: pointer to the PF structure
1929 * @vf_id: source VF id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001930 * @msg: pointer to the msg buffer
1931 * @msglen: msg length
1932 * @msghndl: msg handle
1933 *
1934 * called from the common aeq/arq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001935 * process request from VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001936 **/
1937int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1938 u32 v_retval, u8 *msg, u16 msglen)
1939{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001940 struct i40e_hw *hw = &pf->hw;
Dan Carpenterc243e962014-01-15 06:43:39 +00001941 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001942 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001943 int ret;
1944
1945 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001946 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001947 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001948 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001949 /* perform basic checks on the msg */
1950 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1951
1952 if (ret) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001953 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001954 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001955 return ret;
1956 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08001957
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001958 switch (v_opcode) {
1959 case I40E_VIRTCHNL_OP_VERSION:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001960 ret = i40e_vc_get_version_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001961 break;
1962 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001963 ret = i40e_vc_get_vf_resources_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001964 break;
1965 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001966 i40e_vc_reset_vf_msg(vf);
1967 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001968 break;
1969 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1970 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1971 break;
1972 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1973 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1974 break;
1975 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1976 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1977 break;
1978 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1979 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
Mitch Williams055b2952015-04-07 19:45:33 -04001980 i40e_vc_notify_vf_link_state(vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001981 break;
1982 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1983 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1984 break;
1985 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1986 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1987 break;
1988 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1989 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1990 break;
1991 case I40E_VIRTCHNL_OP_ADD_VLAN:
1992 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1993 break;
1994 case I40E_VIRTCHNL_OP_DEL_VLAN:
1995 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1996 break;
1997 case I40E_VIRTCHNL_OP_GET_STATS:
1998 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1999 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002000 case I40E_VIRTCHNL_OP_UNKNOWN:
2001 default:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002002 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00002003 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002004 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
2005 I40E_ERR_NOT_IMPLEMENTED);
2006 break;
2007 }
2008
2009 return ret;
2010}
2011
2012/**
2013 * i40e_vc_process_vflr_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002014 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002015 *
2016 * called from the vlfr irq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002017 * free up VF resources and state variables
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002018 **/
2019int i40e_vc_process_vflr_event(struct i40e_pf *pf)
2020{
2021 u32 reg, reg_idx, bit_idx, vf_id;
2022 struct i40e_hw *hw = &pf->hw;
2023 struct i40e_vf *vf;
2024
2025 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2026 return 0;
2027
Mitch Williamsc5c2f7c2014-11-11 03:15:04 +00002028 /* re-enable vflr interrupt cause */
2029 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2030 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2031 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2032 i40e_flush(hw);
2033
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002034 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2035 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2036 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2037 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002038 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002039 vf = &pf->vf[vf_id];
2040 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002041 if (reg & BIT(bit_idx)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002042 /* clear the bit in GLGEN_VFLRSTAT */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002043 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002044
Mitch Williamseb2d80b2014-02-13 03:48:48 -08002045 if (!test_bit(__I40E_DOWN, &pf->state))
2046 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002047 }
2048 }
2049
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002050 return 0;
2051}
2052
2053/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002054 * i40e_ndo_set_vf_mac
2055 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002056 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002057 * @mac: mac address
2058 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002059 * program VF mac address
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002060 **/
2061int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2062{
2063 struct i40e_netdev_priv *np = netdev_priv(netdev);
2064 struct i40e_vsi *vsi = np->vsi;
2065 struct i40e_pf *pf = vsi->back;
2066 struct i40e_mac_filter *f;
2067 struct i40e_vf *vf;
2068 int ret = 0;
2069
2070 /* validate the request */
2071 if (vf_id >= pf->num_alloc_vfs) {
2072 dev_err(&pf->pdev->dev,
2073 "Invalid VF Identifier %d\n", vf_id);
2074 ret = -EINVAL;
2075 goto error_param;
2076 }
2077
2078 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002079 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002080 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002081 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2082 vf_id);
2083 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002084 goto error_param;
2085 }
2086
Mitch Williamsefd8e392015-12-22 15:34:43 -08002087 if (is_multicast_ether_addr(mac)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002088 dev_err(&pf->pdev->dev,
Mitch Williamsefd8e392015-12-22 15:34:43 -08002089 "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002090 ret = -EINVAL;
2091 goto error_param;
2092 }
2093
Kiran Patil21659032015-09-30 14:09:03 -04002094 /* Lock once because below invoked function add/del_filter requires
2095 * mac_filter_list_lock to be held
2096 */
2097 spin_lock_bh(&vsi->mac_filter_list_lock);
2098
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002099 /* delete the temporary mac address */
Mitch Williamsefd8e392015-12-22 15:34:43 -08002100 if (!is_zero_ether_addr(vf->default_lan_addr.addr))
2101 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2102 vf->port_vlan_id ? vf->port_vlan_id : -1,
2103 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002104
Greg Rose29f71bb2014-05-20 08:01:45 +00002105 /* Delete all the filters for this VSI - we're going to kill it
2106 * anyway.
2107 */
2108 list_for_each_entry(f, &vsi->mac_filter_list, list)
2109 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002110
Kiran Patil21659032015-09-30 14:09:03 -04002111 spin_unlock_bh(&vsi->mac_filter_list_lock);
2112
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002113 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2114 /* program mac filter */
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002115 if (i40e_sync_vsi_filters(vsi)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002116 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2117 ret = -EIO;
2118 goto error_param;
2119 }
Greg Rose9a173902014-05-22 06:32:02 +00002120 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002121 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002122 /* Force the VF driver stop so it has to reload with new MAC address */
2123 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002124 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002125
2126error_param:
2127 return ret;
2128}
2129
2130/**
2131 * i40e_ndo_set_vf_port_vlan
2132 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002133 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002134 * @vlan_id: mac address
2135 * @qos: priority setting
2136 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002137 * program VF vlan id and/or qos
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002138 **/
2139int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2140 int vf_id, u16 vlan_id, u8 qos)
2141{
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002142 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002143 struct i40e_netdev_priv *np = netdev_priv(netdev);
2144 struct i40e_pf *pf = np->vsi->back;
Kiran Patil21659032015-09-30 14:09:03 -04002145 bool is_vsi_in_vlan = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002146 struct i40e_vsi *vsi;
2147 struct i40e_vf *vf;
2148 int ret = 0;
2149
2150 /* validate the request */
2151 if (vf_id >= pf->num_alloc_vfs) {
2152 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2153 ret = -EINVAL;
2154 goto error_pvid;
2155 }
2156
2157 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2158 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2159 ret = -EINVAL;
2160 goto error_pvid;
2161 }
2162
2163 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002164 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002165 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002166 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2167 vf_id);
2168 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002169 goto error_pvid;
2170 }
2171
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002172 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
Mitch Williams85927ec2015-04-27 14:57:10 -04002173 /* duplicate request, so just return success */
2174 goto error_pvid;
2175
Kiran Patil21659032015-09-30 14:09:03 -04002176 spin_lock_bh(&vsi->mac_filter_list_lock);
2177 is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
2178 spin_unlock_bh(&vsi->mac_filter_list_lock);
2179
2180 if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
Greg Rose99a49732014-01-13 16:13:03 -08002181 dev_err(&pf->pdev->dev,
2182 "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",
2183 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002184 /* Administrator Error - knock the VF offline until he does
2185 * the right thing by reconfiguring his network correctly
2186 * and then reloading the VF driver.
2187 */
2188 i40e_vc_disable_vf(pf, vf);
2189 }
Greg Rose99a49732014-01-13 16:13:03 -08002190
Greg Rose8d82a7c2014-01-13 16:13:04 -08002191 /* Check for condition where there was already a port VLAN ID
2192 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002193 * Additionally check for the condition where there was a port
2194 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002195 * Before deleting all the old VLAN filters we must add new ones
2196 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2197 * MAC addresses deleted.
2198 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002199 if ((!(vlan_id || qos) ||
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002200 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
Greg Rose1315f7c2014-03-14 07:32:20 +00002201 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002202 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2203
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002204 if (vsi->info.pvid) {
2205 /* kill old VLAN */
2206 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2207 VLAN_VID_MASK));
2208 if (ret) {
2209 dev_info(&vsi->back->pdev->dev,
2210 "remove VLAN failed, ret=%d, aq_err=%d\n",
2211 ret, pf->hw.aq.asq_last_status);
2212 }
2213 }
2214 if (vlan_id || qos)
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002215 ret = i40e_vsi_add_pvid(vsi, vlanprio);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002216 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002217 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002218
2219 if (vlan_id) {
2220 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2221 vlan_id, qos, vf_id);
2222
2223 /* add new VLAN filter */
2224 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2225 if (ret) {
2226 dev_info(&vsi->back->pdev->dev,
2227 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2228 vsi->back->hw.aq.asq_last_status);
2229 goto error_pvid;
2230 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002231 /* Kill non-vlan MAC filters - ignore error return since
2232 * there might not be any non-vlan MAC filters.
2233 */
2234 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002235 }
2236
2237 if (ret) {
2238 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2239 goto error_pvid;
2240 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002241 /* The Port VLAN needs to be saved across resets the same as the
2242 * default LAN MAC address.
2243 */
2244 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002245 ret = 0;
2246
2247error_pvid:
2248 return ret;
2249}
2250
Mitch Williams84590fd2014-04-09 05:58:57 +00002251#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2252#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002253/**
2254 * i40e_ndo_set_vf_bw
2255 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002256 * @vf_id: VF identifier
2257 * @tx_rate: Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002258 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002259 * configure VF Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002260 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002261int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2262 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002263{
Mitch Williams6b192892014-03-06 09:02:29 +00002264 struct i40e_netdev_priv *np = netdev_priv(netdev);
2265 struct i40e_pf *pf = np->vsi->back;
2266 struct i40e_vsi *vsi;
2267 struct i40e_vf *vf;
2268 int speed = 0;
2269 int ret = 0;
2270
2271 /* validate the request */
2272 if (vf_id >= pf->num_alloc_vfs) {
2273 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2274 ret = -EINVAL;
2275 goto error;
2276 }
2277
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002278 if (min_tx_rate) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002279 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 -04002280 min_tx_rate, vf_id);
2281 return -EINVAL;
2282 }
2283
Mitch Williams6b192892014-03-06 09:02:29 +00002284 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002285 vsi = pf->vsi[vf->lan_vsi_idx];
Mitch Williams6b192892014-03-06 09:02:29 +00002286 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002287 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2288 vf_id);
2289 ret = -EAGAIN;
Mitch Williams6b192892014-03-06 09:02:29 +00002290 goto error;
2291 }
2292
2293 switch (pf->hw.phy.link_info.link_speed) {
2294 case I40E_LINK_SPEED_40GB:
2295 speed = 40000;
2296 break;
2297 case I40E_LINK_SPEED_10GB:
2298 speed = 10000;
2299 break;
2300 case I40E_LINK_SPEED_1GB:
2301 speed = 1000;
2302 break;
2303 default:
2304 break;
2305 }
2306
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002307 if (max_tx_rate > speed) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002308 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002309 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002310 ret = -EINVAL;
2311 goto error;
2312 }
2313
Mitch Williamsdac9b312014-04-09 05:58:56 +00002314 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2315 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2316 max_tx_rate = 50;
2317 }
2318
Mitch Williams6b192892014-03-06 09:02:29 +00002319 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002320 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2321 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2322 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002323 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002324 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002325 ret);
2326 ret = -EIO;
2327 goto error;
2328 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002329 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002330error:
2331 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002332}
2333
2334/**
2335 * i40e_ndo_get_vf_config
2336 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002337 * @vf_id: VF identifier
2338 * @ivi: VF configuration structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002339 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002340 * return VF configuration
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002341 **/
2342int i40e_ndo_get_vf_config(struct net_device *netdev,
2343 int vf_id, struct ifla_vf_info *ivi)
2344{
2345 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002346 struct i40e_vsi *vsi = np->vsi;
2347 struct i40e_pf *pf = vsi->back;
2348 struct i40e_vf *vf;
2349 int ret = 0;
2350
2351 /* validate the request */
2352 if (vf_id >= pf->num_alloc_vfs) {
2353 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2354 ret = -EINVAL;
2355 goto error_param;
2356 }
2357
2358 vf = &(pf->vf[vf_id]);
2359 /* first vsi is always the LAN vsi */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002360 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002361 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002362 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2363 vf_id);
2364 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002365 goto error_param;
2366 }
2367
2368 ivi->vf = vf_id;
2369
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002370 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002371
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002372 ivi->max_tx_rate = vf->tx_rate;
2373 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002374 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2375 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2376 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00002377 if (vf->link_forced == false)
2378 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2379 else if (vf->link_up == true)
2380 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2381 else
2382 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00002383 ivi->spoofchk = vf->spoofchk;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002384 ret = 0;
2385
2386error_param:
2387 return ret;
2388}
Mitch Williams588aefa2014-02-11 08:27:49 +00002389
2390/**
2391 * i40e_ndo_set_vf_link_state
2392 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002393 * @vf_id: VF identifier
Mitch Williams588aefa2014-02-11 08:27:49 +00002394 * @link: required link state
2395 *
2396 * Set the link state of a specified VF, regardless of physical link state
2397 **/
2398int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2399{
2400 struct i40e_netdev_priv *np = netdev_priv(netdev);
2401 struct i40e_pf *pf = np->vsi->back;
2402 struct i40e_virtchnl_pf_event pfe;
2403 struct i40e_hw *hw = &pf->hw;
2404 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002405 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002406 int ret = 0;
2407
2408 /* validate the request */
2409 if (vf_id >= pf->num_alloc_vfs) {
2410 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2411 ret = -EINVAL;
2412 goto error_out;
2413 }
2414
2415 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07002416 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002417
2418 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2419 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2420
2421 switch (link) {
2422 case IFLA_VF_LINK_STATE_AUTO:
2423 vf->link_forced = false;
2424 pfe.event_data.link_event.link_status =
2425 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2426 pfe.event_data.link_event.link_speed =
2427 pf->hw.phy.link_info.link_speed;
2428 break;
2429 case IFLA_VF_LINK_STATE_ENABLE:
2430 vf->link_forced = true;
2431 vf->link_up = true;
2432 pfe.event_data.link_event.link_status = true;
2433 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2434 break;
2435 case IFLA_VF_LINK_STATE_DISABLE:
2436 vf->link_forced = true;
2437 vf->link_up = false;
2438 pfe.event_data.link_event.link_status = false;
2439 pfe.event_data.link_event.link_speed = 0;
2440 break;
2441 default:
2442 ret = -EINVAL;
2443 goto error_out;
2444 }
2445 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07002446 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00002447 0, (u8 *)&pfe, sizeof(pfe), NULL);
2448
2449error_out:
2450 return ret;
2451}
Mitch Williamsc674d122014-05-20 08:01:40 +00002452
2453/**
2454 * i40e_ndo_set_vf_spoofchk
2455 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002456 * @vf_id: VF identifier
Mitch Williamsc674d122014-05-20 08:01:40 +00002457 * @enable: flag to enable or disable feature
2458 *
2459 * Enable or disable VF spoof checking
2460 **/
Serey Konge6d90042014-07-12 07:28:14 +00002461int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00002462{
2463 struct i40e_netdev_priv *np = netdev_priv(netdev);
2464 struct i40e_vsi *vsi = np->vsi;
2465 struct i40e_pf *pf = vsi->back;
2466 struct i40e_vsi_context ctxt;
2467 struct i40e_hw *hw = &pf->hw;
2468 struct i40e_vf *vf;
2469 int ret = 0;
2470
2471 /* validate the request */
2472 if (vf_id >= pf->num_alloc_vfs) {
2473 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2474 ret = -EINVAL;
2475 goto out;
2476 }
2477
2478 vf = &(pf->vf[vf_id]);
Mitch Williams2d166c32015-12-22 15:34:42 -08002479 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2480 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2481 vf_id);
2482 ret = -EAGAIN;
2483 goto out;
2484 }
Mitch Williamsc674d122014-05-20 08:01:40 +00002485
2486 if (enable == vf->spoofchk)
2487 goto out;
2488
2489 vf->spoofchk = enable;
2490 memset(&ctxt, 0, sizeof(ctxt));
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002491 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
Mitch Williamsc674d122014-05-20 08:01:40 +00002492 ctxt.pf_num = pf->hw.pf_id;
2493 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2494 if (enable)
Greg Rose30d71af2015-01-29 07:17:17 +00002495 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2496 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
Mitch Williamsc674d122014-05-20 08:01:40 +00002497 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2498 if (ret) {
2499 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
2500 ret);
2501 ret = -EIO;
2502 }
2503out:
2504 return ret;
2505}