blob: 44462b40f2d7666f059b6741123107755e18e415 [file] [log] [blame]
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Neerav Parikh51616012015-02-06 08:52:14 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40e.h"
28
Mitch Williams532b0452015-04-07 19:45:34 -040029/*********************notification routines***********************/
30
31/**
32 * i40e_vc_vf_broadcast
33 * @pf: pointer to the PF structure
34 * @opcode: operation code
35 * @retval: return value
36 * @msg: pointer to the msg buffer
37 * @msglen: msg length
38 *
39 * send a message to all VFs on a given PF
40 **/
41static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
42 enum i40e_virtchnl_ops v_opcode,
43 i40e_status v_retval, u8 *msg,
44 u16 msglen)
45{
46 struct i40e_hw *hw = &pf->hw;
47 struct i40e_vf *vf = pf->vf;
48 int i;
49
50 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
51 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
54 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
55 continue;
56
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
59 */
60 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
61 msg, msglen, NULL);
62 }
63}
64
65/**
66 * i40e_vc_notify_link_state
67 * @vf: pointer to the VF structure
68 *
69 * send a link status message to a single VF
70 **/
71static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
72{
73 struct i40e_virtchnl_pf_event pfe;
74 struct i40e_pf *pf = vf->pf;
75 struct i40e_hw *hw = &pf->hw;
76 struct i40e_link_status *ls = &pf->hw.phy.link_info;
77 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
78
79 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
80 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
81 if (vf->link_forced) {
82 pfe.event_data.link_event.link_status = vf->link_up;
83 pfe.event_data.link_event.link_speed =
84 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
85 } else {
86 pfe.event_data.link_event.link_status =
87 ls->link_info & I40E_AQ_LINK_UP;
88 pfe.event_data.link_event.link_speed = ls->link_speed;
89 }
90 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
91 0, (u8 *)&pfe, sizeof(pfe), NULL);
92}
93
94/**
95 * i40e_vc_notify_link_state
96 * @pf: pointer to the PF structure
97 *
98 * send a link status message to all VFs on a given PF
99 **/
100void i40e_vc_notify_link_state(struct i40e_pf *pf)
101{
102 int i;
103
104 for (i = 0; i < pf->num_alloc_vfs; i++)
105 i40e_vc_notify_vf_link_state(&pf->vf[i]);
106}
107
108/**
109 * i40e_vc_notify_reset
110 * @pf: pointer to the PF structure
111 *
112 * indicate a pending reset to all VFs on a given PF
113 **/
114void i40e_vc_notify_reset(struct i40e_pf *pf)
115{
116 struct i40e_virtchnl_pf_event pfe;
117
118 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
119 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
120 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0,
121 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
122}
123
124/**
125 * i40e_vc_notify_vf_reset
126 * @vf: pointer to the VF structure
127 *
128 * indicate a pending reset to the given VF
129 **/
130void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
131{
132 struct i40e_virtchnl_pf_event pfe;
133 int abs_vf_id;
134
135 /* validate the request */
136 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
137 return;
138
139 /* verify if the VF is in either init or active before proceeding */
140 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
141 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
142 return;
143
144 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
145
146 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
147 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
148 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
149 0, (u8 *)&pfe,
150 sizeof(struct i40e_virtchnl_pf_event), NULL);
151}
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000152/***********************misc routines*****************************/
153
154/**
Greg Rosef9b4b622014-03-06 09:02:28 +0000155 * i40e_vc_disable_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000156 * @pf: pointer to the PF info
157 * @vf: pointer to the VF info
Greg Rosef9b4b622014-03-06 09:02:28 +0000158 *
159 * Disable the VF through a SW reset
160 **/
161static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
162{
Mitch Williams54f455e2015-04-27 14:57:14 -0400163 i40e_vc_notify_vf_reset(vf);
164 i40e_reset_vf(vf, false);
Greg Rosef9b4b622014-03-06 09:02:28 +0000165}
166
167/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000168 * i40e_vc_isvalid_vsi_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000169 * @vf: pointer to the VF info
170 * @vsi_id: VF relative VSI id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000171 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000172 * check for the valid VSI id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000173 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700174static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000175{
176 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700177 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000178
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700179 return (vsi && (vsi->vf_id == vf->vf_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000180}
181
182/**
183 * i40e_vc_isvalid_queue_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000184 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000185 * @vsi_id: vsi id
186 * @qid: vsi relative queue id
187 *
188 * check for the valid queue id
189 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700190static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000191 u8 qid)
192{
193 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700194 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000195
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700196 return (vsi && (qid < vsi->alloc_queue_pairs));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000197}
198
199/**
200 * i40e_vc_isvalid_vector_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000201 * @vf: pointer to the VF info
202 * @vector_id: VF relative vector id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000203 *
204 * check for the valid vector id
205 **/
206static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
207{
208 struct i40e_pf *pf = vf->pf;
209
Mitch Williams9347eb72014-02-11 08:26:32 +0000210 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000211}
212
213/***********************vf resource mgmt routines*****************/
214
215/**
216 * i40e_vc_get_pf_queue_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000217 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700218 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000219 * @vsi_queue_id: vsi relative queue id
220 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000221 * return PF relative queue id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000222 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700223static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000224 u8 vsi_queue_id)
225{
226 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700227 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000228 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
229
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700230 if (!vsi)
231 return pf_queue_id;
232
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000233 if (le16_to_cpu(vsi->info.mapping_flags) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
235 pf_queue_id =
236 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
237 else
238 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
239 vsi_queue_id;
240
241 return pf_queue_id;
242}
243
244/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000245 * i40e_config_irq_link_list
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000246 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700247 * @vsi_id: id of VSI as given by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000248 * @vecmap: irq map info
249 *
250 * configure irq link list from the map
251 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700252static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000253 struct i40e_virtchnl_vector_map *vecmap)
254{
255 unsigned long linklistmap = 0, tempmap;
256 struct i40e_pf *pf = vf->pf;
257 struct i40e_hw *hw = &pf->hw;
258 u16 vsi_queue_id, pf_queue_id;
259 enum i40e_queue_type qtype;
260 u16 next_q, vector_id;
261 u32 reg, reg_idx;
262 u16 itr_idx = 0;
263
264 vector_id = vecmap->vector_id;
265 /* setup the head */
266 if (0 == vector_id)
267 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
268 else
269 reg_idx = I40E_VPINT_LNKLSTN(
Mitch Williams9347eb72014-02-11 08:26:32 +0000270 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
271 (vector_id - 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000272
273 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
274 /* Special case - No queues mapped on this vector */
275 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
276 goto irq_list_done;
277 }
278 tempmap = vecmap->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000279 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400280 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
281 vsi_queue_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000282 }
283
284 tempmap = vecmap->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000285 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400286 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
287 vsi_queue_id + 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000288 }
289
290 next_q = find_first_bit(&linklistmap,
291 (I40E_MAX_VSI_QP *
292 I40E_VIRTCHNL_SUPPORTED_QTYPES));
293 vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES;
294 qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700295 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000296 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
297
298 wr32(hw, reg_idx, reg);
299
300 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
301 switch (qtype) {
302 case I40E_QUEUE_TYPE_RX:
303 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
304 itr_idx = vecmap->rxitr_idx;
305 break;
306 case I40E_QUEUE_TYPE_TX:
307 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
308 itr_idx = vecmap->txitr_idx;
309 break;
310 default:
311 break;
312 }
313
314 next_q = find_next_bit(&linklistmap,
315 (I40E_MAX_VSI_QP *
316 I40E_VIRTCHNL_SUPPORTED_QTYPES),
317 next_q + 1);
Mitch Williams829af3a2013-12-18 13:46:00 +0000318 if (next_q <
319 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700322 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000323 vsi_queue_id);
324 } else {
325 pf_queue_id = I40E_QUEUE_END_OF_LIST;
326 qtype = 0;
327 }
328
329 /* format for the RQCTL & TQCTL regs is same */
330 reg = (vector_id) |
331 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
332 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000334 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
335 wr32(hw, reg_idx, reg);
336 }
337
Anjali Singhai Jainb8262a62015-07-10 19:36:08 -0400338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
340 */
341 if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
342 (vector_id == 0)) {
343 reg = rd32(hw, I40E_GLINT_CTL);
344 if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
345 reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
346 wr32(hw, I40E_GLINT_CTL, reg);
347 }
348 }
349
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000350irq_list_done:
351 i40e_flush(hw);
352}
353
354/**
355 * i40e_config_vsi_tx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000356 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700357 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000358 * @vsi_queue_id: vsi relative queue index
359 * @info: config. info
360 *
361 * configure tx queue
362 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700363static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000364 u16 vsi_queue_id,
365 struct i40e_virtchnl_txq_info *info)
366{
367 struct i40e_pf *pf = vf->pf;
368 struct i40e_hw *hw = &pf->hw;
369 struct i40e_hmc_obj_txq tx_ctx;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700370 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000371 u16 pf_queue_id;
372 u32 qtx_ctl;
373 int ret = 0;
374
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700375 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
376 vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000377
378 /* clear the context structure first */
379 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
380
381 /* only set the required fields */
382 tx_ctx.base = info->dma_ring_addr / 128;
383 tx_ctx.qlen = info->ring_len;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700384 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000385 tx_ctx.rdylist_act = 0;
Ashish Shah5d298962014-05-22 06:31:25 +0000386 tx_ctx.head_wb_ena = info->headwb_enabled;
387 tx_ctx.head_wb_addr = info->dma_headwb_addr;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000388
389 /* clear the context in the HMC */
390 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
391 if (ret) {
392 dev_err(&pf->pdev->dev,
393 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
394 pf_queue_id, ret);
395 ret = -ENOENT;
396 goto error_context;
397 }
398
399 /* set the context in the HMC */
400 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
401 if (ret) {
402 dev_err(&pf->pdev->dev,
403 "Failed to set VF LAN Tx queue context %d error: %d\n",
404 pf_queue_id, ret);
405 ret = -ENOENT;
406 goto error_context;
407 }
408
409 /* associate this queue with the PCI VF function */
410 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +0000411 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000412 & I40E_QTX_CTL_PF_INDX_MASK);
413 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
414 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
415 & I40E_QTX_CTL_VFVM_INDX_MASK);
416 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
417 i40e_flush(hw);
418
419error_context:
420 return ret;
421}
422
423/**
424 * i40e_config_vsi_rx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000425 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700426 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000427 * @vsi_queue_id: vsi relative queue index
428 * @info: config. info
429 *
430 * configure rx queue
431 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700432static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000433 u16 vsi_queue_id,
434 struct i40e_virtchnl_rxq_info *info)
435{
436 struct i40e_pf *pf = vf->pf;
437 struct i40e_hw *hw = &pf->hw;
438 struct i40e_hmc_obj_rxq rx_ctx;
439 u16 pf_queue_id;
440 int ret = 0;
441
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700442 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000443
444 /* clear the context structure first */
445 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
446
447 /* only set the required fields */
448 rx_ctx.base = info->dma_ring_addr / 128;
449 rx_ctx.qlen = info->ring_len;
450
451 if (info->splithdr_enabled) {
452 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
453 I40E_RX_SPLIT_IP |
454 I40E_RX_SPLIT_TCP_UDP |
455 I40E_RX_SPLIT_SCTP;
456 /* header length validation */
457 if (info->hdr_size > ((2 * 1024) - 64)) {
458 ret = -EINVAL;
459 goto error_param;
460 }
461 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
462
463 /* set splitalways mode 10b */
464 rx_ctx.dtype = 0x2;
465 }
466
467 /* databuffer length validation */
468 if (info->databuffer_size > ((16 * 1024) - 128)) {
469 ret = -EINVAL;
470 goto error_param;
471 }
472 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
473
474 /* max pkt. length validation */
475 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
476 ret = -EINVAL;
477 goto error_param;
478 }
479 rx_ctx.rxmax = info->max_pkt_size;
480
481 /* enable 32bytes desc always */
482 rx_ctx.dsize = 1;
483
484 /* default values */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000485 rx_ctx.lrxqthresh = 2;
486 rx_ctx.crcstrip = 1;
Mitch Williams50d41652014-04-09 05:58:55 +0000487 rx_ctx.prefena = 1;
Shannon Nelsonc1d11ce2014-07-29 04:01:03 +0000488 rx_ctx.l2tsel = 1;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000489
490 /* clear the context in the HMC */
491 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
492 if (ret) {
493 dev_err(&pf->pdev->dev,
494 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
495 pf_queue_id, ret);
496 ret = -ENOENT;
497 goto error_param;
498 }
499
500 /* set the context in the HMC */
501 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
502 if (ret) {
503 dev_err(&pf->pdev->dev,
504 "Failed to set VF LAN Rx queue context %d error: %d\n",
505 pf_queue_id, ret);
506 ret = -ENOENT;
507 goto error_param;
508 }
509
510error_param:
511 return ret;
512}
513
514/**
515 * i40e_alloc_vsi_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000516 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000517 * @type: type of VSI to allocate
518 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000519 * alloc VF vsi context & resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000520 **/
521static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
522{
523 struct i40e_mac_filter *f = NULL;
524 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000525 struct i40e_vsi *vsi;
526 int ret = 0;
527
528 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
529
530 if (!vsi) {
531 dev_err(&pf->pdev->dev,
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000532 "add vsi failed for VF %d, aq_err %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000533 vf->vf_id, pf->hw.aq.asq_last_status);
534 ret = -ENOENT;
535 goto error_alloc_vsi_res;
536 }
537 if (type == I40E_VSI_SRIOV) {
Greg Rose1a103702013-11-28 06:42:39 +0000538 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400539
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700540 vf->lan_vsi_idx = vsi->idx;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000541 vf->lan_vsi_id = vsi->id;
Greg Rose6c12fcb2013-11-28 06:39:34 +0000542 /* If the port VLAN has been configured and then the
543 * VF driver was removed then the VSI port VLAN
544 * configuration was destroyed. Check if there is
545 * a port VLAN and restore the VSI configuration if
546 * needed.
547 */
548 if (vf->port_vlan_id)
549 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
Kiran Patil21659032015-09-30 14:09:03 -0400550
551 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000552 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
Mitch Williamse9951632015-04-27 14:57:13 -0400553 vf->port_vlan_id ? vf->port_vlan_id : -1,
554 true, false);
Greg Rose1a103702013-11-28 06:42:39 +0000555 if (!f)
556 dev_info(&pf->pdev->dev,
557 "Could not allocate VF MAC addr\n");
Mitch Williamse9951632015-04-27 14:57:13 -0400558 f = i40e_add_filter(vsi, brdcast,
559 vf->port_vlan_id ? vf->port_vlan_id : -1,
Greg Rose1a103702013-11-28 06:42:39 +0000560 true, false);
561 if (!f)
562 dev_info(&pf->pdev->dev,
563 "Could not allocate VF broadcast filter\n");
Kiran Patil21659032015-09-30 14:09:03 -0400564 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000565 }
Neerav Parikh6dbbbfb2013-11-26 10:49:24 +0000566
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000567 /* program mac filter */
Anjali Singhai30e25612015-09-28 13:37:12 -0700568 ret = i40e_sync_vsi_filters(vsi, false);
Mitch Williamsfd1646e2014-02-13 03:48:44 -0800569 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000570 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000571
Mitch Williams6b192892014-03-06 09:02:29 +0000572 /* Set VF bandwidth if specified */
573 if (vf->tx_rate) {
574 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
575 vf->tx_rate / 50, 0, NULL);
576 if (ret)
577 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
578 vf->vf_id, ret);
579 }
580
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000581error_alloc_vsi_res:
582 return ret;
583}
584
585/**
Mitch Williams805bd5b2013-11-28 06:39:26 +0000586 * i40e_enable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000587 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000588 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000589 * enable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000590 **/
591static void i40e_enable_vf_mappings(struct i40e_vf *vf)
592{
593 struct i40e_pf *pf = vf->pf;
594 struct i40e_hw *hw = &pf->hw;
595 u32 reg, total_queue_pairs = 0;
596 int j;
597
598 /* Tell the hardware we're using noncontiguous mapping. HW requires
599 * that VF queues be mapped using this method, even when they are
600 * contiguous in real life
601 */
602 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
603 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
604
605 /* enable VF vplan_qtable mappings */
606 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
607 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
608
609 /* map PF queues to VF queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700610 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
611 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400612
Mitch Williams805bd5b2013-11-28 06:39:26 +0000613 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
614 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
615 total_queue_pairs++;
616 }
617
618 /* map PF queues to VSI */
619 for (j = 0; j < 7; j++) {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700620 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000621 reg = 0x07FF07FF; /* unused */
622 } else {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700623 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000624 j * 2);
625 reg = qid;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700626 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000627 (j * 2) + 1);
628 reg |= qid << 16;
629 }
630 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
631 }
632
633 i40e_flush(hw);
634}
635
636/**
637 * i40e_disable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000638 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000639 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000640 * disable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000641 **/
642static void i40e_disable_vf_mappings(struct i40e_vf *vf)
643{
644 struct i40e_pf *pf = vf->pf;
645 struct i40e_hw *hw = &pf->hw;
646 int i;
647
648 /* disable qp mappings */
649 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
650 for (i = 0; i < I40E_MAX_VSI_QP; i++)
651 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
652 I40E_QUEUE_END_OF_LIST);
653 i40e_flush(hw);
654}
655
656/**
657 * i40e_free_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000658 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000659 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000660 * free VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000661 **/
662static void i40e_free_vf_res(struct i40e_vf *vf)
663{
664 struct i40e_pf *pf = vf->pf;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000665 struct i40e_hw *hw = &pf->hw;
666 u32 reg_idx, reg;
667 int i, msix_vf;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000668
669 /* free vsi & disconnect it from the parent uplink */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700670 if (vf->lan_vsi_idx) {
671 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
672 vf->lan_vsi_idx = 0;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000673 vf->lan_vsi_id = 0;
674 }
Mitch Williams9347eb72014-02-11 08:26:32 +0000675 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
676
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000677 /* disable interrupts so the VF starts in a known state */
678 for (i = 0; i < msix_vf; i++) {
679 /* format is same for both registers */
680 if (0 == i)
681 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
682 else
683 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
684 (vf->vf_id))
685 + (i - 1));
686 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
687 i40e_flush(hw);
688 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000689
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000690 /* clear the irq settings */
691 for (i = 0; i < msix_vf; i++) {
692 /* format is same for both registers */
693 if (0 == i)
694 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
695 else
696 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
697 (vf->vf_id))
698 + (i - 1));
699 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
700 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
701 wr32(hw, reg_idx, reg);
702 i40e_flush(hw);
703 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000704 /* reset some of the state varibles keeping
705 * track of the resources
706 */
707 vf->num_queue_pairs = 0;
708 vf->vf_states = 0;
Mitch Williams21be99e2015-08-31 19:54:48 -0400709 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000710}
711
712/**
713 * i40e_alloc_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000714 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000715 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000716 * allocate VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000717 **/
718static int i40e_alloc_vf_res(struct i40e_vf *vf)
719{
720 struct i40e_pf *pf = vf->pf;
721 int total_queue_pairs = 0;
722 int ret;
723
724 /* allocate hw vsi context & associated resources */
725 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
726 if (ret)
727 goto error_alloc;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700728 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000729 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
730
731 /* store the total qps number for the runtime
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000732 * VF req validation
Mitch Williams805bd5b2013-11-28 06:39:26 +0000733 */
734 vf->num_queue_pairs = total_queue_pairs;
735
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000736 /* VF is now completely initialized */
Mitch Williams805bd5b2013-11-28 06:39:26 +0000737 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
738
739error_alloc:
740 if (ret)
741 i40e_free_vf_res(vf);
742
743 return ret;
744}
745
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000746#define VF_DEVICE_STATUS 0xAA
747#define VF_TRANS_PENDING_MASK 0x20
748/**
749 * i40e_quiesce_vf_pci
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000750 * @vf: pointer to the VF structure
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000751 *
752 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
753 * if the transactions never clear.
754 **/
755static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
756{
757 struct i40e_pf *pf = vf->pf;
758 struct i40e_hw *hw = &pf->hw;
759 int vf_abs_id, i;
760 u32 reg;
761
Mitch Williamsb141d612013-11-28 06:39:36 +0000762 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000763
764 wr32(hw, I40E_PF_PCI_CIAA,
765 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
766 for (i = 0; i < 100; i++) {
767 reg = rd32(hw, I40E_PF_PCI_CIAD);
768 if ((reg & VF_TRANS_PENDING_MASK) == 0)
769 return 0;
770 udelay(1);
771 }
772 return -EIO;
773}
774
Mitch Williams805bd5b2013-11-28 06:39:26 +0000775/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000776 * i40e_reset_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000777 * @vf: pointer to the VF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000778 * @flr: VFLR was issued or not
779 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000780 * reset the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000781 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000782void i40e_reset_vf(struct i40e_vf *vf, bool flr)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000783{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000784 struct i40e_pf *pf = vf->pf;
785 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000786 bool rsd = false;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000787 int i;
788 u32 reg;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000789
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000790 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
791 return;
792
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000793 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000794 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
795
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000796 /* In the case of a VFLR, the HW has already reset the VF and we
797 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000798 */
799 if (!flr) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000800 /* reset VF using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000801 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
802 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000803 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
804 i40e_flush(hw);
805 }
806
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000807 if (i40e_quiesce_vf_pci(vf))
808 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
809 vf->vf_id);
810
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000811 /* poll VPGEN_VFRSTAT reg to make sure
812 * that reset is complete
813 */
Mitch Williams1750a222015-01-09 11:18:13 +0000814 for (i = 0; i < 10; i++) {
815 /* VF reset requires driver to first reset the VF and then
816 * poll the status register to make sure that the reset
817 * completed successfully. Due to internal HW FIFO flushes,
818 * we must wait 10ms before the register will be valid.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000819 */
Mitch Williams1750a222015-01-09 11:18:13 +0000820 usleep_range(10000, 20000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000821 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
822 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
823 rsd = true;
824 break;
825 }
826 }
827
Anjali Singhai Jain57175ac2015-04-07 19:45:35 -0400828 if (flr)
829 usleep_range(10000, 20000);
830
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000831 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000832 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000833 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000834 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000835 /* clear the reset bit in the VPGEN_VFRTRIG reg */
836 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
837 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
838 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000839
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000840 /* On initial reset, we won't have any queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700841 if (vf->lan_vsi_idx == 0)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000842 goto complete_reset;
843
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700844 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000845complete_reset:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000846 /* reallocate VF resources to reset the VSI state */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000847 i40e_free_vf_res(vf);
Mitch Williams21be99e2015-08-31 19:54:48 -0400848 if (!i40e_alloc_vf_res(vf)) {
849 i40e_enable_vf_mappings(vf);
850 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
851 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
852 }
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000853 /* tell the VF the reset is done */
854 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
855 i40e_flush(hw);
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000856 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000857}
Greg Rosec3542292013-12-13 08:38:38 +0000858
859/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000860 * i40e_free_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000861 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000862 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000863 * free VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000864 **/
865void i40e_free_vfs(struct i40e_pf *pf)
866{
Mitch Williamsf7414532013-11-28 06:39:40 +0000867 struct i40e_hw *hw = &pf->hw;
868 u32 reg_idx, bit_idx;
869 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000870
871 if (!pf->vf)
872 return;
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000873 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
874 usleep_range(1000, 2000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000875
Mitch Williams44434632015-04-07 11:32:55 -0700876 for (i = 0; i < pf->num_alloc_vfs; i++)
877 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
878 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
879 false);
880
Mitch Williams0325fca2015-08-26 15:14:09 -0400881 for (i = 0; i < pf->num_alloc_vfs; i++)
882 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
883 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
884 false);
885
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000886 /* Disable IOV before freeing resources. This lets any VF drivers
887 * running in the host get themselves cleaned up before we yank
888 * the carpet out from underneath their feet.
889 */
890 if (!pci_vfs_assigned(pf->pdev))
891 pci_disable_sriov(pf->pdev);
Mitch Williams6d7b9672015-03-31 00:45:02 -0700892 else
893 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
Mitch A Williams6a9ddb32014-12-09 08:53:01 +0000894
895 msleep(20); /* let any messages in transit get finished up */
896
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000897 /* free up VF resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000898 tmp = pf->num_alloc_vfs;
899 pf->num_alloc_vfs = 0;
900 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000901 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
902 i40e_free_vf_res(&pf->vf[i]);
903 /* disable qp mappings */
904 i40e_disable_vf_mappings(&pf->vf[i]);
905 }
906
907 kfree(pf->vf);
908 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000909
Mitch Williams9e5634d2014-04-04 04:43:14 +0000910 /* This check is for when the driver is unloaded while VFs are
911 * assigned. Setting the number of VFs to 0 through sysfs is caught
912 * before this function ever gets called.
913 */
Ethan Zhaoc24817b2014-07-22 18:36:43 +0000914 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williamsf7414532013-11-28 06:39:40 +0000915 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
916 * work correctly when SR-IOV gets re-enabled.
917 */
918 for (vf_id = 0; vf_id < tmp; vf_id++) {
919 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
920 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400921 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Mitch Williamsf7414532013-11-28 06:39:40 +0000922 }
Greg Rosec3542292013-12-13 08:38:38 +0000923 }
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000924 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000925}
926
927#ifdef CONFIG_PCI_IOV
928/**
929 * i40e_alloc_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000930 * @pf: pointer to the PF structure
931 * @num_alloc_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000932 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000933 * allocate VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000934 **/
Mitch Williams4aeec012014-02-13 03:48:47 -0800935int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000936{
937 struct i40e_vf *vfs;
938 int i, ret = 0;
939
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000940 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000941 i40e_irq_dynamic_disable_icr0(pf);
942
Mitch Williams4aeec012014-02-13 03:48:47 -0800943 /* Check to see if we're just allocating resources for extant VFs */
944 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
945 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
946 if (ret) {
Akeem G Abodunrinde445b32015-10-01 14:37:40 -0400947 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
Mitch Williams4aeec012014-02-13 03:48:47 -0800948 pf->num_alloc_vfs = 0;
949 goto err_iov;
950 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000951 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000952 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +0000953 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000954 if (!vfs) {
955 ret = -ENOMEM;
956 goto err_alloc;
957 }
Mitch Williamsc674d122014-05-20 08:01:40 +0000958 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000959
960 /* apply default profile */
961 for (i = 0; i < num_alloc_vfs; i++) {
962 vfs[i].pf = pf;
963 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
964 vfs[i].vf_id = i;
965
966 /* assign default capabilities */
967 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +0000968 vfs[i].spoofchk = true;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000969 /* VF resources get allocated during reset */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000970 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000971
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000972 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000973 pf->num_alloc_vfs = num_alloc_vfs;
974
975err_alloc:
976 if (ret)
977 i40e_free_vfs(pf);
978err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +0000979 /* Re-enable interrupt 0. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +0000980 i40e_irq_dynamic_enable_icr0(pf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000981 return ret;
982}
983
984#endif
985/**
986 * i40e_pci_sriov_enable
987 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000988 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000989 *
990 * Enable or change the number of VFs
991 **/
992static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
993{
994#ifdef CONFIG_PCI_IOV
995 struct i40e_pf *pf = pci_get_drvdata(pdev);
996 int pre_existing_vfs = pci_num_vf(pdev);
997 int err = 0;
998
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400999 if (test_bit(__I40E_TESTING, &pf->state)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001000 dev_warn(&pdev->dev,
1001 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1002 err = -EPERM;
1003 goto err_out;
1004 }
1005
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001006 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1007 i40e_free_vfs(pf);
1008 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1009 goto out;
1010
1011 if (num_vfs > pf->num_req_vfs) {
Mitch Williams96c8d072015-08-27 11:42:35 -04001012 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1013 num_vfs, pf->num_req_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001014 err = -EPERM;
1015 goto err_out;
1016 }
1017
Mitch Williams96c8d072015-08-27 11:42:35 -04001018 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001019 err = i40e_alloc_vfs(pf, num_vfs);
1020 if (err) {
1021 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1022 goto err_out;
1023 }
1024
1025out:
1026 return num_vfs;
1027
1028err_out:
1029 return err;
1030#endif
1031 return 0;
1032}
1033
1034/**
1035 * i40e_pci_sriov_configure
1036 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001037 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001038 *
1039 * Enable or change the number of VFs. Called when the user updates the number
1040 * of VFs in sysfs.
1041 **/
1042int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1043{
1044 struct i40e_pf *pf = pci_get_drvdata(pdev);
1045
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001046 if (num_vfs) {
1047 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1048 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1049 i40e_do_reset_safe(pf,
1050 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1051 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001052 return i40e_pci_sriov_enable(pdev, num_vfs);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001053 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001054
Ethan Zhaoc24817b2014-07-22 18:36:43 +00001055 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williams9e5634d2014-04-04 04:43:14 +00001056 i40e_free_vfs(pf);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001057 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1058 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Mitch Williams9e5634d2014-04-04 04:43:14 +00001059 } else {
1060 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1061 return -EINVAL;
1062 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001063 return 0;
1064}
1065
1066/***********************virtual channel routines******************/
1067
1068/**
1069 * i40e_vc_send_msg_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001070 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001071 * @v_opcode: virtual channel opcode
1072 * @v_retval: virtual channel return value
1073 * @msg: pointer to the msg buffer
1074 * @msglen: msg length
1075 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001076 * send msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001077 **/
1078static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1079 u32 v_retval, u8 *msg, u16 msglen)
1080{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001081 struct i40e_pf *pf;
1082 struct i40e_hw *hw;
1083 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001084 i40e_status aq_ret;
1085
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001086 /* validate the request */
1087 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1088 return -EINVAL;
1089
1090 pf = vf->pf;
1091 hw = &pf->hw;
1092 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1093
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001094 /* single place to detect unsuccessful return values */
1095 if (v_retval) {
1096 vf->num_invalid_msgs++;
1097 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1098 v_opcode, v_retval);
1099 if (vf->num_invalid_msgs >
1100 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1101 dev_err(&pf->pdev->dev,
1102 "Number of invalid messages exceeded for VF %d\n",
1103 vf->vf_id);
1104 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1105 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1106 }
1107 } else {
1108 vf->num_valid_msgs++;
Jingjing Wu5d38c932015-09-28 14:12:39 -04001109 /* reset the invalid counter, if a valid message is received. */
1110 vf->num_invalid_msgs = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001111 }
1112
Ashish Shahf19efbb2014-08-01 13:27:06 -07001113 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001114 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001115 if (aq_ret) {
1116 dev_err(&pf->pdev->dev,
1117 "Unable to send the message to VF %d aq_err %d\n",
1118 vf->vf_id, pf->hw.aq.asq_last_status);
1119 return -EIO;
1120 }
1121
1122 return 0;
1123}
1124
1125/**
1126 * i40e_vc_send_resp_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001127 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001128 * @opcode: operation code
1129 * @retval: return value
1130 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001131 * send resp msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001132 **/
1133static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1134 enum i40e_virtchnl_ops opcode,
1135 i40e_status retval)
1136{
1137 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1138}
1139
1140/**
1141 * i40e_vc_get_version_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001142 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001143 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001144 * called from the VF to request the API version used by the PF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001145 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001146static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001147{
1148 struct i40e_virtchnl_version_info info = {
1149 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1150 };
1151
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001152 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
Mitch Williams606a5482015-06-04 16:24:00 -04001153 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1154 if (VF_IS_V10(vf))
1155 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001156 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1157 I40E_SUCCESS, (u8 *)&info,
1158 sizeof(struct
1159 i40e_virtchnl_version_info));
1160}
1161
1162/**
1163 * i40e_vc_get_vf_resources_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001164 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001165 * @msg: pointer to the msg buffer
1166 * @msglen: msg length
1167 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001168 * called from the VF to request its resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001169 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001170static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001171{
1172 struct i40e_virtchnl_vf_resource *vfres = NULL;
1173 struct i40e_pf *pf = vf->pf;
1174 i40e_status aq_ret = 0;
1175 struct i40e_vsi *vsi;
1176 int i = 0, len = 0;
1177 int num_vsis = 1;
1178 int ret;
1179
1180 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1181 aq_ret = I40E_ERR_PARAM;
1182 goto err;
1183 }
1184
1185 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1186 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1187
1188 vfres = kzalloc(len, GFP_KERNEL);
1189 if (!vfres) {
1190 aq_ret = I40E_ERR_NO_MEMORY;
1191 len = 0;
1192 goto err;
1193 }
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001194 if (VF_IS_V11(vf))
1195 vf->driver_caps = *(u32 *)msg;
1196 else
1197 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1198 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1199 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001200
1201 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001202 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001203 if (!vsi->info.pvid)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001204 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1205 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1206 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1207 vfres->vf_offload_flags |=
1208 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1209 } else {
1210 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1211 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001212
1213 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING)
1214 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1215
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001216 vfres->num_vsis = num_vsis;
1217 vfres->num_queue_pairs = vf->num_queue_pairs;
1218 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001219 if (vf->lan_vsi_idx) {
1220 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001221 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04001222 vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs;
1223 /* VFs only use TC 0 */
1224 vfres->vsi_res[i].qset_handle
1225 = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001226 ether_addr_copy(vfres->vsi_res[i].default_mac_addr,
1227 vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001228 i++;
1229 }
1230 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1231
1232err:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001233 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001234 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1235 aq_ret, (u8 *)vfres, len);
1236
1237 kfree(vfres);
1238 return ret;
1239}
1240
1241/**
1242 * i40e_vc_reset_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001243 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001244 * @msg: pointer to the msg buffer
1245 * @msglen: msg length
1246 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001247 * called from the VF to reset itself,
1248 * unlike other virtchnl messages, PF driver
1249 * doesn't send the response back to the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001250 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001251static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001252{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001253 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1254 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001255}
1256
1257/**
1258 * i40e_vc_config_promiscuous_mode_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001259 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001260 * @msg: pointer to the msg buffer
1261 * @msglen: msg length
1262 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001263 * called from the VF to configure the promiscuous mode of
1264 * VF vsis
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001265 **/
1266static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1267 u8 *msg, u16 msglen)
1268{
1269 struct i40e_virtchnl_promisc_info *info =
1270 (struct i40e_virtchnl_promisc_info *)msg;
1271 struct i40e_pf *pf = vf->pf;
1272 struct i40e_hw *hw = &pf->hw;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001273 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001274 bool allmulti = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001275 i40e_status aq_ret;
1276
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001277 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001278 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1279 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1280 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001281 (vsi->type != I40E_VSI_FCOE)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001282 aq_ret = I40E_ERR_PARAM;
1283 goto error_param;
1284 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001285 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1286 allmulti = true;
Ashish Shah89cb86c2014-08-01 13:27:10 -07001287 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001288 allmulti, NULL);
1289
1290error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001291 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001292 return i40e_vc_send_resp_to_vf(vf,
1293 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1294 aq_ret);
1295}
1296
1297/**
1298 * i40e_vc_config_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001299 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001300 * @msg: pointer to the msg buffer
1301 * @msglen: msg length
1302 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001303 * called from the VF to configure the rx/tx
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001304 * queues
1305 **/
1306static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1307{
1308 struct i40e_virtchnl_vsi_queue_config_info *qci =
1309 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1310 struct i40e_virtchnl_queue_pair_info *qpi;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001311 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001312 u16 vsi_id, vsi_queue_id;
1313 i40e_status aq_ret = 0;
1314 int i;
1315
1316 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1317 aq_ret = I40E_ERR_PARAM;
1318 goto error_param;
1319 }
1320
1321 vsi_id = qci->vsi_id;
1322 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1323 aq_ret = I40E_ERR_PARAM;
1324 goto error_param;
1325 }
1326 for (i = 0; i < qci->num_queue_pairs; i++) {
1327 qpi = &qci->qpair[i];
1328 vsi_queue_id = qpi->txq.queue_id;
1329 if ((qpi->txq.vsi_id != vsi_id) ||
1330 (qpi->rxq.vsi_id != vsi_id) ||
1331 (qpi->rxq.queue_id != vsi_queue_id) ||
1332 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1333 aq_ret = I40E_ERR_PARAM;
1334 goto error_param;
1335 }
1336
1337 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1338 &qpi->rxq) ||
1339 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1340 &qpi->txq)) {
1341 aq_ret = I40E_ERR_PARAM;
1342 goto error_param;
1343 }
1344 }
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001345 /* set vsi num_queue_pairs in use to num configured by VF */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001346 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001347
1348error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001349 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001350 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1351 aq_ret);
1352}
1353
1354/**
1355 * i40e_vc_config_irq_map_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001356 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001357 * @msg: pointer to the msg buffer
1358 * @msglen: msg length
1359 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001360 * called from the VF to configure the irq to
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001361 * queue map
1362 **/
1363static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1364{
1365 struct i40e_virtchnl_irq_map_info *irqmap_info =
1366 (struct i40e_virtchnl_irq_map_info *)msg;
1367 struct i40e_virtchnl_vector_map *map;
1368 u16 vsi_id, vsi_queue_id, vector_id;
1369 i40e_status aq_ret = 0;
1370 unsigned long tempmap;
1371 int i;
1372
1373 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1374 aq_ret = I40E_ERR_PARAM;
1375 goto error_param;
1376 }
1377
1378 for (i = 0; i < irqmap_info->num_vectors; i++) {
1379 map = &irqmap_info->vecmap[i];
1380
1381 vector_id = map->vector_id;
1382 vsi_id = map->vsi_id;
1383 /* validate msg params */
1384 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1385 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1386 aq_ret = I40E_ERR_PARAM;
1387 goto error_param;
1388 }
1389
1390 /* lookout for the invalid queue index */
1391 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001392 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001393 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1394 vsi_queue_id)) {
1395 aq_ret = I40E_ERR_PARAM;
1396 goto error_param;
1397 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001398 }
1399
1400 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001401 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001402 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1403 vsi_queue_id)) {
1404 aq_ret = I40E_ERR_PARAM;
1405 goto error_param;
1406 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001407 }
1408
1409 i40e_config_irq_link_list(vf, vsi_id, map);
1410 }
1411error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001412 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001413 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1414 aq_ret);
1415}
1416
1417/**
1418 * i40e_vc_enable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001419 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001420 * @msg: pointer to the msg buffer
1421 * @msglen: msg length
1422 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001423 * called from the VF to enable all or specific queue(s)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001424 **/
1425static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1426{
1427 struct i40e_virtchnl_queue_select *vqs =
1428 (struct i40e_virtchnl_queue_select *)msg;
1429 struct i40e_pf *pf = vf->pf;
1430 u16 vsi_id = vqs->vsi_id;
1431 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001432
1433 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1434 aq_ret = I40E_ERR_PARAM;
1435 goto error_param;
1436 }
1437
1438 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1439 aq_ret = I40E_ERR_PARAM;
1440 goto error_param;
1441 }
1442
1443 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1444 aq_ret = I40E_ERR_PARAM;
1445 goto error_param;
1446 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001447
1448 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
Mitch Williams88f65632013-11-28 06:39:28 +00001449 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001450error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001451 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001452 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1453 aq_ret);
1454}
1455
1456/**
1457 * i40e_vc_disable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001458 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001459 * @msg: pointer to the msg buffer
1460 * @msglen: msg length
1461 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001462 * called from the VF to disable all or specific
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001463 * queue(s)
1464 **/
1465static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1466{
1467 struct i40e_virtchnl_queue_select *vqs =
1468 (struct i40e_virtchnl_queue_select *)msg;
1469 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001470 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001471
1472 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1473 aq_ret = I40E_ERR_PARAM;
1474 goto error_param;
1475 }
1476
1477 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1478 aq_ret = I40E_ERR_PARAM;
1479 goto error_param;
1480 }
1481
1482 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1483 aq_ret = I40E_ERR_PARAM;
1484 goto error_param;
1485 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001486
1487 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
Mitch Williams88f65632013-11-28 06:39:28 +00001488 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001489
1490error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001491 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001492 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1493 aq_ret);
1494}
1495
1496/**
1497 * i40e_vc_get_stats_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001498 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001499 * @msg: pointer to the msg buffer
1500 * @msglen: msg length
1501 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001502 * called from the VF to get vsi stats
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001503 **/
1504static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1505{
1506 struct i40e_virtchnl_queue_select *vqs =
1507 (struct i40e_virtchnl_queue_select *)msg;
1508 struct i40e_pf *pf = vf->pf;
1509 struct i40e_eth_stats stats;
1510 i40e_status aq_ret = 0;
1511 struct i40e_vsi *vsi;
1512
1513 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1514
1515 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1516 aq_ret = I40E_ERR_PARAM;
1517 goto error_param;
1518 }
1519
1520 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1521 aq_ret = I40E_ERR_PARAM;
1522 goto error_param;
1523 }
1524
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001525 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001526 if (!vsi) {
1527 aq_ret = I40E_ERR_PARAM;
1528 goto error_param;
1529 }
1530 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001531 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001532
1533error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001534 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001535 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1536 (u8 *)&stats, sizeof(stats));
1537}
1538
1539/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001540 * i40e_check_vf_permission
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001541 * @vf: pointer to the VF info
Greg Rosef657a6e2013-11-28 06:39:42 +00001542 * @macaddr: pointer to the MAC Address being checked
1543 *
1544 * Check if the VF has permission to add or delete unicast MAC address
1545 * filters and return error code -EPERM if not. Then check if the
1546 * address filter requested is broadcast or zero and if so return
1547 * an invalid MAC address error code.
1548 **/
1549static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1550{
1551 struct i40e_pf *pf = vf->pf;
1552 int ret = 0;
1553
1554 if (is_broadcast_ether_addr(macaddr) ||
1555 is_zero_ether_addr(macaddr)) {
1556 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1557 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001558 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1559 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001560 /* If the host VMM administrator has set the VF MAC address
1561 * administratively via the ndo_set_vf_mac command then deny
1562 * permission to the VF to add or delete unicast MAC addresses.
Greg Rose5017c2a2013-12-07 10:36:54 +00001563 * The VF may request to set the MAC address filter already
1564 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001565 */
1566 dev_err(&pf->pdev->dev,
1567 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1568 ret = -EPERM;
1569 }
1570 return ret;
1571}
1572
1573/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001574 * i40e_vc_add_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001575 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001576 * @msg: pointer to the msg buffer
1577 * @msglen: msg length
1578 *
1579 * add guest mac address filter
1580 **/
1581static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1582{
1583 struct i40e_virtchnl_ether_addr_list *al =
1584 (struct i40e_virtchnl_ether_addr_list *)msg;
1585 struct i40e_pf *pf = vf->pf;
1586 struct i40e_vsi *vsi = NULL;
1587 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001588 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001589 int i;
1590
1591 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1592 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1593 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001594 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001595 goto error_param;
1596 }
1597
1598 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001599 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1600 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001601 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001602 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001603 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001604
Kiran Patil21659032015-09-30 14:09:03 -04001605 /* Lock once, because all function inside for loop accesses VSI's
1606 * MAC filter list which needs to be protected using same lock.
1607 */
1608 spin_lock_bh(&vsi->mac_filter_list_lock);
1609
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001610 /* add new addresses to the list */
1611 for (i = 0; i < al->num_elements; i++) {
1612 struct i40e_mac_filter *f;
1613
1614 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001615 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001616 if (i40e_is_vsi_in_vlan(vsi))
1617 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1618 true, false);
1619 else
1620 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1621 true, false);
1622 }
1623
1624 if (!f) {
1625 dev_err(&pf->pdev->dev,
1626 "Unable to add VF MAC filter\n");
Greg Rosef657a6e2013-11-28 06:39:42 +00001627 ret = I40E_ERR_PARAM;
Kiran Patil21659032015-09-30 14:09:03 -04001628 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001629 goto error_param;
1630 }
1631 }
Kiran Patil21659032015-09-30 14:09:03 -04001632 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001633
1634 /* program the updated filter list */
Anjali Singhai30e25612015-09-28 13:37:12 -07001635 if (i40e_sync_vsi_filters(vsi, false))
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001636 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1637
1638error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001639 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001640 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001641 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001642}
1643
1644/**
1645 * i40e_vc_del_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001646 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001647 * @msg: pointer to the msg buffer
1648 * @msglen: msg length
1649 *
1650 * remove guest mac address filter
1651 **/
1652static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1653{
1654 struct i40e_virtchnl_ether_addr_list *al =
1655 (struct i40e_virtchnl_ether_addr_list *)msg;
1656 struct i40e_pf *pf = vf->pf;
1657 struct i40e_vsi *vsi = NULL;
1658 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001659 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001660 int i;
1661
1662 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1663 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1664 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001665 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001666 goto error_param;
1667 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001668
1669 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00001670 if (is_broadcast_ether_addr(al->list[i].addr) ||
1671 is_zero_ether_addr(al->list[i].addr)) {
1672 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1673 al->list[i].addr);
1674 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00001675 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00001676 }
Greg Rosef657a6e2013-11-28 06:39:42 +00001677 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001678 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001679
Kiran Patil21659032015-09-30 14:09:03 -04001680 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001681 /* delete addresses from the list */
1682 for (i = 0; i < al->num_elements; i++)
1683 i40e_del_filter(vsi, al->list[i].addr,
1684 I40E_VLAN_ANY, true, false);
Kiran Patil21659032015-09-30 14:09:03 -04001685 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001686
1687 /* program the updated filter list */
Anjali Singhai30e25612015-09-28 13:37:12 -07001688 if (i40e_sync_vsi_filters(vsi, false))
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001689 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1690
1691error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001692 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001693 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001694 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001695}
1696
1697/**
1698 * i40e_vc_add_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001699 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001700 * @msg: pointer to the msg buffer
1701 * @msglen: msg length
1702 *
1703 * program guest vlan id
1704 **/
1705static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1706{
1707 struct i40e_virtchnl_vlan_filter_list *vfl =
1708 (struct i40e_virtchnl_vlan_filter_list *)msg;
1709 struct i40e_pf *pf = vf->pf;
1710 struct i40e_vsi *vsi = NULL;
1711 u16 vsi_id = vfl->vsi_id;
1712 i40e_status aq_ret = 0;
1713 int i;
1714
1715 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1716 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1717 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1718 aq_ret = I40E_ERR_PARAM;
1719 goto error_param;
1720 }
1721
1722 for (i = 0; i < vfl->num_elements; i++) {
1723 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1724 aq_ret = I40E_ERR_PARAM;
1725 dev_err(&pf->pdev->dev,
1726 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1727 goto error_param;
1728 }
1729 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001730 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001731 if (vsi->info.pvid) {
1732 aq_ret = I40E_ERR_PARAM;
1733 goto error_param;
1734 }
1735
1736 i40e_vlan_stripping_enable(vsi);
1737 for (i = 0; i < vfl->num_elements; i++) {
1738 /* add new VLAN filter */
1739 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001740
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001741 if (ret)
1742 dev_err(&pf->pdev->dev,
1743 "Unable to add VF vlan filter %d, error %d\n",
1744 vfl->vlan_id[i], ret);
1745 }
1746
1747error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001748 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001749 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1750}
1751
1752/**
1753 * i40e_vc_remove_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001754 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001755 * @msg: pointer to the msg buffer
1756 * @msglen: msg length
1757 *
1758 * remove programmed guest vlan id
1759 **/
1760static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1761{
1762 struct i40e_virtchnl_vlan_filter_list *vfl =
1763 (struct i40e_virtchnl_vlan_filter_list *)msg;
1764 struct i40e_pf *pf = vf->pf;
1765 struct i40e_vsi *vsi = NULL;
1766 u16 vsi_id = vfl->vsi_id;
1767 i40e_status aq_ret = 0;
1768 int i;
1769
1770 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1771 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1772 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1773 aq_ret = I40E_ERR_PARAM;
1774 goto error_param;
1775 }
1776
1777 for (i = 0; i < vfl->num_elements; i++) {
1778 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1779 aq_ret = I40E_ERR_PARAM;
1780 goto error_param;
1781 }
1782 }
1783
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001784 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001785 if (vsi->info.pvid) {
1786 aq_ret = I40E_ERR_PARAM;
1787 goto error_param;
1788 }
1789
1790 for (i = 0; i < vfl->num_elements; i++) {
1791 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001792
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001793 if (ret)
1794 dev_err(&pf->pdev->dev,
1795 "Unable to delete VF vlan filter %d, error %d\n",
1796 vfl->vlan_id[i], ret);
1797 }
1798
1799error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001800 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001801 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1802}
1803
1804/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001805 * i40e_vc_validate_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001806 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001807 * @msg: pointer to the msg buffer
1808 * @msglen: msg length
1809 * @msghndl: msg handle
1810 *
1811 * validate msg
1812 **/
1813static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1814 u32 v_retval, u8 *msg, u16 msglen)
1815{
1816 bool err_msg_format = false;
1817 int valid_len;
1818
1819 /* Check if VF is disabled. */
1820 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1821 return I40E_ERR_PARAM;
1822
1823 /* Validate message length. */
1824 switch (v_opcode) {
1825 case I40E_VIRTCHNL_OP_VERSION:
1826 valid_len = sizeof(struct i40e_virtchnl_version_info);
1827 break;
1828 case I40E_VIRTCHNL_OP_RESET_VF:
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001829 valid_len = 0;
1830 break;
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001831 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1832 if (VF_IS_V11(vf))
1833 valid_len = sizeof(u32);
1834 else
1835 valid_len = 0;
1836 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001837 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1838 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1839 break;
1840 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1841 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1842 break;
1843 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1844 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1845 if (msglen >= valid_len) {
1846 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1847 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1848 valid_len += (vqc->num_queue_pairs *
1849 sizeof(struct
1850 i40e_virtchnl_queue_pair_info));
1851 if (vqc->num_queue_pairs == 0)
1852 err_msg_format = true;
1853 }
1854 break;
1855 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1856 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1857 if (msglen >= valid_len) {
1858 struct i40e_virtchnl_irq_map_info *vimi =
1859 (struct i40e_virtchnl_irq_map_info *)msg;
1860 valid_len += (vimi->num_vectors *
1861 sizeof(struct i40e_virtchnl_vector_map));
1862 if (vimi->num_vectors == 0)
1863 err_msg_format = true;
1864 }
1865 break;
1866 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1867 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1868 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1869 break;
1870 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1871 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1872 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1873 if (msglen >= valid_len) {
1874 struct i40e_virtchnl_ether_addr_list *veal =
1875 (struct i40e_virtchnl_ether_addr_list *)msg;
1876 valid_len += veal->num_elements *
1877 sizeof(struct i40e_virtchnl_ether_addr);
1878 if (veal->num_elements == 0)
1879 err_msg_format = true;
1880 }
1881 break;
1882 case I40E_VIRTCHNL_OP_ADD_VLAN:
1883 case I40E_VIRTCHNL_OP_DEL_VLAN:
1884 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1885 if (msglen >= valid_len) {
1886 struct i40e_virtchnl_vlan_filter_list *vfl =
1887 (struct i40e_virtchnl_vlan_filter_list *)msg;
1888 valid_len += vfl->num_elements * sizeof(u16);
1889 if (vfl->num_elements == 0)
1890 err_msg_format = true;
1891 }
1892 break;
1893 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1894 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1895 break;
1896 case I40E_VIRTCHNL_OP_GET_STATS:
1897 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1898 break;
1899 /* These are always errors coming from the VF. */
1900 case I40E_VIRTCHNL_OP_EVENT:
1901 case I40E_VIRTCHNL_OP_UNKNOWN:
1902 default:
1903 return -EPERM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001904 }
1905 /* few more checks */
1906 if ((valid_len != msglen) || (err_msg_format)) {
1907 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1908 return -EINVAL;
1909 } else {
1910 return 0;
1911 }
1912}
1913
1914/**
1915 * i40e_vc_process_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001916 * @pf: pointer to the PF structure
1917 * @vf_id: source VF id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001918 * @msg: pointer to the msg buffer
1919 * @msglen: msg length
1920 * @msghndl: msg handle
1921 *
1922 * called from the common aeq/arq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001923 * process request from VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001924 **/
1925int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1926 u32 v_retval, u8 *msg, u16 msglen)
1927{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001928 struct i40e_hw *hw = &pf->hw;
Dan Carpenterc243e962014-01-15 06:43:39 +00001929 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001930 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001931 int ret;
1932
1933 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001934 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001935 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00001936 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001937 /* perform basic checks on the msg */
1938 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1939
1940 if (ret) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001941 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001942 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001943 return ret;
1944 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08001945
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001946 switch (v_opcode) {
1947 case I40E_VIRTCHNL_OP_VERSION:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001948 ret = i40e_vc_get_version_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001949 break;
1950 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001951 ret = i40e_vc_get_vf_resources_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001952 break;
1953 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001954 i40e_vc_reset_vf_msg(vf);
1955 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001956 break;
1957 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1958 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1959 break;
1960 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1961 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1962 break;
1963 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1964 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1965 break;
1966 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1967 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
Mitch Williams055b2952015-04-07 19:45:33 -04001968 i40e_vc_notify_vf_link_state(vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001969 break;
1970 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1971 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1972 break;
1973 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1974 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1975 break;
1976 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1977 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1978 break;
1979 case I40E_VIRTCHNL_OP_ADD_VLAN:
1980 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1981 break;
1982 case I40E_VIRTCHNL_OP_DEL_VLAN:
1983 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1984 break;
1985 case I40E_VIRTCHNL_OP_GET_STATS:
1986 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1987 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001988 case I40E_VIRTCHNL_OP_UNKNOWN:
1989 default:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001990 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00001991 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001992 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1993 I40E_ERR_NOT_IMPLEMENTED);
1994 break;
1995 }
1996
1997 return ret;
1998}
1999
2000/**
2001 * i40e_vc_process_vflr_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002002 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002003 *
2004 * called from the vlfr irq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002005 * free up VF resources and state variables
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002006 **/
2007int i40e_vc_process_vflr_event(struct i40e_pf *pf)
2008{
2009 u32 reg, reg_idx, bit_idx, vf_id;
2010 struct i40e_hw *hw = &pf->hw;
2011 struct i40e_vf *vf;
2012
2013 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2014 return 0;
2015
Mitch Williamsc5c2f7c2014-11-11 03:15:04 +00002016 /* re-enable vflr interrupt cause */
2017 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2018 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2019 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2020 i40e_flush(hw);
2021
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002022 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2023 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2024 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2025 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002026 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002027 vf = &pf->vf[vf_id];
2028 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002029 if (reg & BIT(bit_idx)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002030 /* clear the bit in GLGEN_VFLRSTAT */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002031 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002032
Mitch Williamseb2d80b2014-02-13 03:48:48 -08002033 if (!test_bit(__I40E_DOWN, &pf->state))
2034 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002035 }
2036 }
2037
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002038 return 0;
2039}
2040
2041/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002042 * i40e_ndo_set_vf_mac
2043 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002044 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002045 * @mac: mac address
2046 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002047 * program VF mac address
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002048 **/
2049int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2050{
2051 struct i40e_netdev_priv *np = netdev_priv(netdev);
2052 struct i40e_vsi *vsi = np->vsi;
2053 struct i40e_pf *pf = vsi->back;
2054 struct i40e_mac_filter *f;
2055 struct i40e_vf *vf;
2056 int ret = 0;
2057
2058 /* validate the request */
2059 if (vf_id >= pf->num_alloc_vfs) {
2060 dev_err(&pf->pdev->dev,
2061 "Invalid VF Identifier %d\n", vf_id);
2062 ret = -EINVAL;
2063 goto error_param;
2064 }
2065
2066 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002067 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002068 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2069 dev_err(&pf->pdev->dev,
2070 "Uninitialized VF %d\n", vf_id);
2071 ret = -EINVAL;
2072 goto error_param;
2073 }
2074
2075 if (!is_valid_ether_addr(mac)) {
2076 dev_err(&pf->pdev->dev,
2077 "Invalid VF ethernet address\n");
2078 ret = -EINVAL;
2079 goto error_param;
2080 }
2081
Kiran Patil21659032015-09-30 14:09:03 -04002082 /* Lock once because below invoked function add/del_filter requires
2083 * mac_filter_list_lock to be held
2084 */
2085 spin_lock_bh(&vsi->mac_filter_list_lock);
2086
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002087 /* delete the temporary mac address */
Mitch Williamse9951632015-04-27 14:57:13 -04002088 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2089 vf->port_vlan_id ? vf->port_vlan_id : -1,
Greg Rose37cc0d22014-04-01 07:11:44 +00002090 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002091
Greg Rose29f71bb2014-05-20 08:01:45 +00002092 /* Delete all the filters for this VSI - we're going to kill it
2093 * anyway.
2094 */
2095 list_for_each_entry(f, &vsi->mac_filter_list, list)
2096 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002097
Kiran Patil21659032015-09-30 14:09:03 -04002098 spin_unlock_bh(&vsi->mac_filter_list_lock);
2099
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002100 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2101 /* program mac filter */
Anjali Singhai30e25612015-09-28 13:37:12 -07002102 if (i40e_sync_vsi_filters(vsi, false)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002103 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2104 ret = -EIO;
2105 goto error_param;
2106 }
Greg Rose9a173902014-05-22 06:32:02 +00002107 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002108 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002109 /* Force the VF driver stop so it has to reload with new MAC address */
2110 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002111 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002112
2113error_param:
2114 return ret;
2115}
2116
2117/**
2118 * i40e_ndo_set_vf_port_vlan
2119 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002120 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002121 * @vlan_id: mac address
2122 * @qos: priority setting
2123 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002124 * program VF vlan id and/or qos
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002125 **/
2126int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2127 int vf_id, u16 vlan_id, u8 qos)
2128{
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002129 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002130 struct i40e_netdev_priv *np = netdev_priv(netdev);
2131 struct i40e_pf *pf = np->vsi->back;
Kiran Patil21659032015-09-30 14:09:03 -04002132 bool is_vsi_in_vlan = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002133 struct i40e_vsi *vsi;
2134 struct i40e_vf *vf;
2135 int ret = 0;
2136
2137 /* validate the request */
2138 if (vf_id >= pf->num_alloc_vfs) {
2139 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2140 ret = -EINVAL;
2141 goto error_pvid;
2142 }
2143
2144 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2145 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2146 ret = -EINVAL;
2147 goto error_pvid;
2148 }
2149
2150 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002151 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002152 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2153 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2154 ret = -EINVAL;
2155 goto error_pvid;
2156 }
2157
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002158 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
Mitch Williams85927ec2015-04-27 14:57:10 -04002159 /* duplicate request, so just return success */
2160 goto error_pvid;
2161
Kiran Patil21659032015-09-30 14:09:03 -04002162 spin_lock_bh(&vsi->mac_filter_list_lock);
2163 is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
2164 spin_unlock_bh(&vsi->mac_filter_list_lock);
2165
2166 if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
Greg Rose99a49732014-01-13 16:13:03 -08002167 dev_err(&pf->pdev->dev,
2168 "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",
2169 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002170 /* Administrator Error - knock the VF offline until he does
2171 * the right thing by reconfiguring his network correctly
2172 * and then reloading the VF driver.
2173 */
2174 i40e_vc_disable_vf(pf, vf);
2175 }
Greg Rose99a49732014-01-13 16:13:03 -08002176
Greg Rose8d82a7c2014-01-13 16:13:04 -08002177 /* Check for condition where there was already a port VLAN ID
2178 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002179 * Additionally check for the condition where there was a port
2180 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002181 * Before deleting all the old VLAN filters we must add new ones
2182 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2183 * MAC addresses deleted.
2184 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002185 if ((!(vlan_id || qos) ||
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002186 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
Greg Rose1315f7c2014-03-14 07:32:20 +00002187 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002188 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2189
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002190 if (vsi->info.pvid) {
2191 /* kill old VLAN */
2192 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2193 VLAN_VID_MASK));
2194 if (ret) {
2195 dev_info(&vsi->back->pdev->dev,
2196 "remove VLAN failed, ret=%d, aq_err=%d\n",
2197 ret, pf->hw.aq.asq_last_status);
2198 }
2199 }
2200 if (vlan_id || qos)
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002201 ret = i40e_vsi_add_pvid(vsi, vlanprio);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002202 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002203 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002204
2205 if (vlan_id) {
2206 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2207 vlan_id, qos, vf_id);
2208
2209 /* add new VLAN filter */
2210 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2211 if (ret) {
2212 dev_info(&vsi->back->pdev->dev,
2213 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2214 vsi->back->hw.aq.asq_last_status);
2215 goto error_pvid;
2216 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002217 /* Kill non-vlan MAC filters - ignore error return since
2218 * there might not be any non-vlan MAC filters.
2219 */
2220 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002221 }
2222
2223 if (ret) {
2224 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2225 goto error_pvid;
2226 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002227 /* The Port VLAN needs to be saved across resets the same as the
2228 * default LAN MAC address.
2229 */
2230 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002231 ret = 0;
2232
2233error_pvid:
2234 return ret;
2235}
2236
Mitch Williams84590fd2014-04-09 05:58:57 +00002237#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2238#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002239/**
2240 * i40e_ndo_set_vf_bw
2241 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002242 * @vf_id: VF identifier
2243 * @tx_rate: Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002244 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002245 * configure VF Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002246 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002247int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2248 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002249{
Mitch Williams6b192892014-03-06 09:02:29 +00002250 struct i40e_netdev_priv *np = netdev_priv(netdev);
2251 struct i40e_pf *pf = np->vsi->back;
2252 struct i40e_vsi *vsi;
2253 struct i40e_vf *vf;
2254 int speed = 0;
2255 int ret = 0;
2256
2257 /* validate the request */
2258 if (vf_id >= pf->num_alloc_vfs) {
2259 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2260 ret = -EINVAL;
2261 goto error;
2262 }
2263
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002264 if (min_tx_rate) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002265 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 -04002266 min_tx_rate, vf_id);
2267 return -EINVAL;
2268 }
2269
Mitch Williams6b192892014-03-06 09:02:29 +00002270 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002271 vsi = pf->vsi[vf->lan_vsi_idx];
Mitch Williams6b192892014-03-06 09:02:29 +00002272 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2273 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2274 ret = -EINVAL;
2275 goto error;
2276 }
2277
2278 switch (pf->hw.phy.link_info.link_speed) {
2279 case I40E_LINK_SPEED_40GB:
2280 speed = 40000;
2281 break;
2282 case I40E_LINK_SPEED_10GB:
2283 speed = 10000;
2284 break;
2285 case I40E_LINK_SPEED_1GB:
2286 speed = 1000;
2287 break;
2288 default:
2289 break;
2290 }
2291
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002292 if (max_tx_rate > speed) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002293 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002294 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002295 ret = -EINVAL;
2296 goto error;
2297 }
2298
Mitch Williamsdac9b312014-04-09 05:58:56 +00002299 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2300 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2301 max_tx_rate = 50;
2302 }
2303
Mitch Williams6b192892014-03-06 09:02:29 +00002304 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002305 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2306 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2307 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002308 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002309 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002310 ret);
2311 ret = -EIO;
2312 goto error;
2313 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002314 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002315error:
2316 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002317}
2318
2319/**
2320 * i40e_ndo_get_vf_config
2321 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002322 * @vf_id: VF identifier
2323 * @ivi: VF configuration structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002324 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002325 * return VF configuration
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002326 **/
2327int i40e_ndo_get_vf_config(struct net_device *netdev,
2328 int vf_id, struct ifla_vf_info *ivi)
2329{
2330 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002331 struct i40e_vsi *vsi = np->vsi;
2332 struct i40e_pf *pf = vsi->back;
2333 struct i40e_vf *vf;
2334 int ret = 0;
2335
2336 /* validate the request */
2337 if (vf_id >= pf->num_alloc_vfs) {
2338 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2339 ret = -EINVAL;
2340 goto error_param;
2341 }
2342
2343 vf = &(pf->vf[vf_id]);
2344 /* first vsi is always the LAN vsi */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002345 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002346 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2347 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2348 ret = -EINVAL;
2349 goto error_param;
2350 }
2351
2352 ivi->vf = vf_id;
2353
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002354 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002355
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002356 ivi->max_tx_rate = vf->tx_rate;
2357 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002358 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2359 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2360 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00002361 if (vf->link_forced == false)
2362 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2363 else if (vf->link_up == true)
2364 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2365 else
2366 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00002367 ivi->spoofchk = vf->spoofchk;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002368 ret = 0;
2369
2370error_param:
2371 return ret;
2372}
Mitch Williams588aefa2014-02-11 08:27:49 +00002373
2374/**
2375 * i40e_ndo_set_vf_link_state
2376 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002377 * @vf_id: VF identifier
Mitch Williams588aefa2014-02-11 08:27:49 +00002378 * @link: required link state
2379 *
2380 * Set the link state of a specified VF, regardless of physical link state
2381 **/
2382int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2383{
2384 struct i40e_netdev_priv *np = netdev_priv(netdev);
2385 struct i40e_pf *pf = np->vsi->back;
2386 struct i40e_virtchnl_pf_event pfe;
2387 struct i40e_hw *hw = &pf->hw;
2388 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07002389 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002390 int ret = 0;
2391
2392 /* validate the request */
2393 if (vf_id >= pf->num_alloc_vfs) {
2394 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2395 ret = -EINVAL;
2396 goto error_out;
2397 }
2398
2399 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07002400 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00002401
2402 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2403 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2404
2405 switch (link) {
2406 case IFLA_VF_LINK_STATE_AUTO:
2407 vf->link_forced = false;
2408 pfe.event_data.link_event.link_status =
2409 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2410 pfe.event_data.link_event.link_speed =
2411 pf->hw.phy.link_info.link_speed;
2412 break;
2413 case IFLA_VF_LINK_STATE_ENABLE:
2414 vf->link_forced = true;
2415 vf->link_up = true;
2416 pfe.event_data.link_event.link_status = true;
2417 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2418 break;
2419 case IFLA_VF_LINK_STATE_DISABLE:
2420 vf->link_forced = true;
2421 vf->link_up = false;
2422 pfe.event_data.link_event.link_status = false;
2423 pfe.event_data.link_event.link_speed = 0;
2424 break;
2425 default:
2426 ret = -EINVAL;
2427 goto error_out;
2428 }
2429 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07002430 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00002431 0, (u8 *)&pfe, sizeof(pfe), NULL);
2432
2433error_out:
2434 return ret;
2435}
Mitch Williamsc674d122014-05-20 08:01:40 +00002436
2437/**
2438 * i40e_ndo_set_vf_spoofchk
2439 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002440 * @vf_id: VF identifier
Mitch Williamsc674d122014-05-20 08:01:40 +00002441 * @enable: flag to enable or disable feature
2442 *
2443 * Enable or disable VF spoof checking
2444 **/
Serey Konge6d90042014-07-12 07:28:14 +00002445int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00002446{
2447 struct i40e_netdev_priv *np = netdev_priv(netdev);
2448 struct i40e_vsi *vsi = np->vsi;
2449 struct i40e_pf *pf = vsi->back;
2450 struct i40e_vsi_context ctxt;
2451 struct i40e_hw *hw = &pf->hw;
2452 struct i40e_vf *vf;
2453 int ret = 0;
2454
2455 /* validate the request */
2456 if (vf_id >= pf->num_alloc_vfs) {
2457 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2458 ret = -EINVAL;
2459 goto out;
2460 }
2461
2462 vf = &(pf->vf[vf_id]);
2463
2464 if (enable == vf->spoofchk)
2465 goto out;
2466
2467 vf->spoofchk = enable;
2468 memset(&ctxt, 0, sizeof(ctxt));
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002469 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
Mitch Williamsc674d122014-05-20 08:01:40 +00002470 ctxt.pf_num = pf->hw.pf_id;
2471 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2472 if (enable)
Greg Rose30d71af2015-01-29 07:17:17 +00002473 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2474 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
Mitch Williamsc674d122014-05-20 08:01:40 +00002475 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2476 if (ret) {
2477 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
2478 ret);
2479 ret = -EIO;
2480 }
2481out:
2482 return ret;
2483}