blob: e6798b0d1cae02dd3275ab19fdc2d6fb1d0ca5fc [file] [log] [blame]
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08004 * Copyright(c) 2013 - 2016 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++) {
Jesse Brandeburga1b5a242016-04-13 03:08:29 -070051 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
Mitch Williams532b0452015-04-07 19:45:34 -040052 /* 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/**
Mitch Williams55f7d722016-03-10 14:59:50 -080066 * i40e_vc_notify_vf_link_state
Mitch Williams532b0452015-04-07 19:45:34 -040067 * @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;
Jesse Brandeburga1b5a242016-04-13 03:08:29 -070077 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
Mitch Williams532b0452015-04-07 19:45:34 -040078
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
Jesse Brandeburga1b5a242016-04-13 03:08:29 -0700144 abs_vf_id = vf->vf_id + (int)vf->pf->hw.func_caps.vf_base_id;
Mitch Williams532b0452015-04-07 19:45:34 -0400145
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,
Martyna Szapar7f5e6e02019-04-15 14:43:07 -0700191 u16 qid)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000192{
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 **/
Grzegorz Siwikb7715c92019-03-29 15:08:37 -0700206static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u32 vector_id)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000207{
208 struct i40e_pf *pf = vf->pf;
209
Mitch Williams9347eb72014-02-11 08:26:32 +0000210 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000211}
212
213/***********************vf resource mgmt routines*****************/
214
215/**
216 * i40e_vc_get_pf_queue_id
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000217 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700218 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000219 * @vsi_queue_id: vsi relative queue id
220 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000221 * return PF relative queue id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000222 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700223static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000224 u8 vsi_queue_id)
225{
226 struct i40e_pf *pf = vf->pf;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700227 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000228 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
229
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700230 if (!vsi)
231 return pf_queue_id;
232
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000233 if (le16_to_cpu(vsi->info.mapping_flags) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
235 pf_queue_id =
236 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
237 else
238 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
239 vsi_queue_id;
240
241 return pf_queue_id;
242}
243
244/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000245 * i40e_config_irq_link_list
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000246 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700247 * @vsi_id: id of VSI as given by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000248 * @vecmap: irq map info
249 *
250 * configure irq link list from the map
251 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700252static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000253 struct i40e_virtchnl_vector_map *vecmap)
254{
255 unsigned long linklistmap = 0, tempmap;
256 struct i40e_pf *pf = vf->pf;
257 struct i40e_hw *hw = &pf->hw;
258 u16 vsi_queue_id, pf_queue_id;
259 enum i40e_queue_type qtype;
260 u16 next_q, vector_id;
261 u32 reg, reg_idx;
262 u16 itr_idx = 0;
263
264 vector_id = vecmap->vector_id;
265 /* setup the head */
266 if (0 == vector_id)
267 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
268 else
269 reg_idx = I40E_VPINT_LNKLSTN(
Mitch Williams9347eb72014-02-11 08:26:32 +0000270 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
271 (vector_id - 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000272
273 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
274 /* Special case - No queues mapped on this vector */
275 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
276 goto irq_list_done;
277 }
278 tempmap = vecmap->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000279 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400280 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
281 vsi_queue_id));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000282 }
283
284 tempmap = vecmap->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +0000285 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400286 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
287 vsi_queue_id + 1));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000288 }
289
290 next_q = find_first_bit(&linklistmap,
291 (I40E_MAX_VSI_QP *
292 I40E_VIRTCHNL_SUPPORTED_QTYPES));
Mitch Williamsb82bc49e2015-11-06 15:26:10 -0800293 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
294 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700295 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000296 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
297
298 wr32(hw, reg_idx, reg);
299
300 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
301 switch (qtype) {
302 case I40E_QUEUE_TYPE_RX:
303 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
304 itr_idx = vecmap->rxitr_idx;
305 break;
306 case I40E_QUEUE_TYPE_TX:
307 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
308 itr_idx = vecmap->txitr_idx;
309 break;
310 default:
311 break;
312 }
313
314 next_q = find_next_bit(&linklistmap,
315 (I40E_MAX_VSI_QP *
316 I40E_VIRTCHNL_SUPPORTED_QTYPES),
317 next_q + 1);
Mitch Williams829af3a2013-12-18 13:46:00 +0000318 if (next_q <
319 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700322 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000323 vsi_queue_id);
324 } else {
325 pf_queue_id = I40E_QUEUE_END_OF_LIST;
326 qtype = 0;
327 }
328
329 /* format for the RQCTL & TQCTL regs is same */
330 reg = (vector_id) |
331 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
332 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000334 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
335 wr32(hw, reg_idx, reg);
336 }
337
Anjali Singhai Jainb8262a62015-07-10 19:36:08 -0400338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
340 */
341 if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
342 (vector_id == 0)) {
343 reg = rd32(hw, I40E_GLINT_CTL);
344 if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
345 reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
346 wr32(hw, I40E_GLINT_CTL, reg);
347 }
348 }
349
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000350irq_list_done:
351 i40e_flush(hw);
352}
353
354/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600355 * i40e_release_iwarp_qvlist
356 * @vf: pointer to the VF.
357 *
358 **/
359static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
360{
361 struct i40e_pf *pf = vf->pf;
362 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
363 u32 msix_vf;
364 u32 i;
365
366 if (!vf->qvlist_info)
367 return;
368
369 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
370 for (i = 0; i < qvlist_info->num_vectors; i++) {
371 struct i40e_virtchnl_iwarp_qv_info *qv_info;
372 u32 next_q_index, next_q_type;
373 struct i40e_hw *hw = &pf->hw;
374 u32 v_idx, reg_idx, reg;
375
376 qv_info = &qvlist_info->qv_info[i];
377 if (!qv_info)
378 continue;
379 v_idx = qv_info->v_idx;
380 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
381 /* Figure out the queue after CEQ and make that the
382 * first queue.
383 */
384 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
385 reg = rd32(hw, I40E_VPINT_CEQCTL(reg_idx));
386 next_q_index = (reg & I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK)
387 >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT;
388 next_q_type = (reg & I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK)
389 >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT;
390
391 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
392 reg = (next_q_index &
393 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
394 (next_q_type <<
395 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
396
397 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
398 }
399 }
400 kfree(vf->qvlist_info);
401 vf->qvlist_info = NULL;
402}
403
404/**
405 * i40e_config_iwarp_qvlist
406 * @vf: pointer to the VF info
407 * @qvlist_info: queue and vector list
408 *
409 * Return 0 on success or < 0 on error
410 **/
411static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
412 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info)
413{
414 struct i40e_pf *pf = vf->pf;
415 struct i40e_hw *hw = &pf->hw;
416 struct i40e_virtchnl_iwarp_qv_info *qv_info;
417 u32 v_idx, i, reg_idx, reg;
418 u32 next_q_idx, next_q_type;
419 u32 msix_vf, size;
420
Sergey Nemovf4a3ff42019-03-29 15:08:36 -0700421 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
422
423 if (qvlist_info->num_vectors > msix_vf) {
424 dev_warn(&pf->pdev->dev,
425 "Incorrect number of iwarp vectors %u. Maximum %u allowed.\n",
426 qvlist_info->num_vectors,
427 msix_vf);
428 goto err;
429 }
430
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600431 size = sizeof(struct i40e_virtchnl_iwarp_qvlist_info) +
432 (sizeof(struct i40e_virtchnl_iwarp_qv_info) *
433 (qvlist_info->num_vectors - 1));
434 vf->qvlist_info = kzalloc(size, GFP_KERNEL);
Christophe JAILLET8f298812017-08-06 23:37:01 +0200435 if (!vf->qvlist_info)
436 return -ENOMEM;
437
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600438 vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
439
440 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
441 for (i = 0; i < qvlist_info->num_vectors; i++) {
442 qv_info = &qvlist_info->qv_info[i];
443 if (!qv_info)
444 continue;
445 v_idx = qv_info->v_idx;
446
447 /* Validate vector id belongs to this vf */
448 if (!i40e_vc_isvalid_vector_id(vf, v_idx))
449 goto err;
450
451 vf->qvlist_info->qv_info[i] = *qv_info;
452
453 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
454 /* We might be sharing the interrupt, so get the first queue
455 * index and type, push it down the list by adding the new
456 * queue on top. Also link it with the new queue in CEQCTL.
457 */
458 reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
459 next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
460 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
461 next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
462 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
463
464 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
465 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
466 reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
467 (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
468 (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
469 (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
470 (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
471 wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
472
473 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
474 reg = (qv_info->ceq_idx &
475 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
476 (I40E_QUEUE_TYPE_PE_CEQ <<
477 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
478 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
479 }
480
481 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
482 reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
483 (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
484 (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
485
486 wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
487 }
488 }
489
490 return 0;
491err:
492 kfree(vf->qvlist_info);
493 vf->qvlist_info = NULL;
494 return -EINVAL;
495}
496
497/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000498 * i40e_config_vsi_tx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000499 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700500 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000501 * @vsi_queue_id: vsi relative queue index
502 * @info: config. info
503 *
504 * configure tx queue
505 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700506static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000507 u16 vsi_queue_id,
508 struct i40e_virtchnl_txq_info *info)
509{
510 struct i40e_pf *pf = vf->pf;
511 struct i40e_hw *hw = &pf->hw;
512 struct i40e_hmc_obj_txq tx_ctx;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700513 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000514 u16 pf_queue_id;
515 u32 qtx_ctl;
516 int ret = 0;
517
Carolyn Wybornyd4a06582016-08-24 11:33:50 -0700518 if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
519 ret = -ENOENT;
520 goto error_context;
521 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700522 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
523 vsi = i40e_find_vsi_from_id(pf, vsi_id);
Carolyn Wybornyd4a06582016-08-24 11:33:50 -0700524 if (!vsi) {
525 ret = -ENOENT;
526 goto error_context;
527 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000528
529 /* clear the context structure first */
530 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
531
532 /* only set the required fields */
533 tx_ctx.base = info->dma_ring_addr / 128;
534 tx_ctx.qlen = info->ring_len;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700535 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000536 tx_ctx.rdylist_act = 0;
Ashish Shah5d298962014-05-22 06:31:25 +0000537 tx_ctx.head_wb_ena = info->headwb_enabled;
538 tx_ctx.head_wb_addr = info->dma_headwb_addr;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000539
540 /* clear the context in the HMC */
541 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
542 if (ret) {
543 dev_err(&pf->pdev->dev,
544 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
545 pf_queue_id, ret);
546 ret = -ENOENT;
547 goto error_context;
548 }
549
550 /* set the context in the HMC */
551 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
552 if (ret) {
553 dev_err(&pf->pdev->dev,
554 "Failed to set VF LAN Tx queue context %d error: %d\n",
555 pf_queue_id, ret);
556 ret = -ENOENT;
557 goto error_context;
558 }
559
560 /* associate this queue with the PCI VF function */
561 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +0000562 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000563 & I40E_QTX_CTL_PF_INDX_MASK);
564 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
565 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
566 & I40E_QTX_CTL_VFVM_INDX_MASK);
567 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
568 i40e_flush(hw);
569
570error_context:
571 return ret;
572}
573
574/**
575 * i40e_config_vsi_rx_queue
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000576 * @vf: pointer to the VF info
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700577 * @vsi_id: id of VSI as provided by the FW
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000578 * @vsi_queue_id: vsi relative queue index
579 * @info: config. info
580 *
581 * configure rx queue
582 **/
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700583static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000584 u16 vsi_queue_id,
585 struct i40e_virtchnl_rxq_info *info)
586{
587 struct i40e_pf *pf = vf->pf;
588 struct i40e_hw *hw = &pf->hw;
589 struct i40e_hmc_obj_rxq rx_ctx;
590 u16 pf_queue_id;
591 int ret = 0;
592
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700593 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000594
595 /* clear the context structure first */
596 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
597
598 /* only set the required fields */
599 rx_ctx.base = info->dma_ring_addr / 128;
600 rx_ctx.qlen = info->ring_len;
601
602 if (info->splithdr_enabled) {
603 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
604 I40E_RX_SPLIT_IP |
605 I40E_RX_SPLIT_TCP_UDP |
606 I40E_RX_SPLIT_SCTP;
607 /* header length validation */
608 if (info->hdr_size > ((2 * 1024) - 64)) {
609 ret = -EINVAL;
610 goto error_param;
611 }
612 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
613
Jesse Brandeburg19b85e62016-04-18 11:33:45 -0700614 /* set split mode 10b */
Mitch Williamsd6b3bca2016-01-15 14:33:08 -0800615 rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000616 }
617
618 /* databuffer length validation */
619 if (info->databuffer_size > ((16 * 1024) - 128)) {
620 ret = -EINVAL;
621 goto error_param;
622 }
623 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
624
625 /* max pkt. length validation */
626 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
627 ret = -EINVAL;
628 goto error_param;
629 }
630 rx_ctx.rxmax = info->max_pkt_size;
631
632 /* enable 32bytes desc always */
633 rx_ctx.dsize = 1;
634
635 /* default values */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000636 rx_ctx.lrxqthresh = 2;
637 rx_ctx.crcstrip = 1;
Mitch Williams50d41652014-04-09 05:58:55 +0000638 rx_ctx.prefena = 1;
Shannon Nelsonc1d11ce2014-07-29 04:01:03 +0000639 rx_ctx.l2tsel = 1;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000640
641 /* clear the context in the HMC */
642 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
643 if (ret) {
644 dev_err(&pf->pdev->dev,
645 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
646 pf_queue_id, ret);
647 ret = -ENOENT;
648 goto error_param;
649 }
650
651 /* set the context in the HMC */
652 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
653 if (ret) {
654 dev_err(&pf->pdev->dev,
655 "Failed to set VF LAN Rx queue context %d error: %d\n",
656 pf_queue_id, ret);
657 ret = -ENOENT;
658 goto error_param;
659 }
660
661error_param:
662 return ret;
663}
664
665/**
666 * i40e_alloc_vsi_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000667 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000668 * @type: type of VSI to allocate
669 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000670 * alloc VF vsi context & resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000671 **/
672static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
673{
674 struct i40e_mac_filter *f = NULL;
675 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000676 struct i40e_vsi *vsi;
677 int ret = 0;
678
679 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
680
681 if (!vsi) {
682 dev_err(&pf->pdev->dev,
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000683 "add vsi failed for VF %d, aq_err %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000684 vf->vf_id, pf->hw.aq.asq_last_status);
685 ret = -ENOENT;
686 goto error_alloc_vsi_res;
687 }
688 if (type == I40E_VSI_SRIOV) {
Mitch Williamsbb3607172016-05-16 10:26:33 -0700689 u64 hena = i40e_pf_get_default_rss_hena(pf);
690
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700691 vf->lan_vsi_idx = vsi->idx;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000692 vf->lan_vsi_id = vsi->id;
Greg Rose6c12fcb2013-11-28 06:39:34 +0000693 /* If the port VLAN has been configured and then the
694 * VF driver was removed then the VSI port VLAN
695 * configuration was destroyed. Check if there is
696 * a port VLAN and restore the VSI configuration if
697 * needed.
698 */
699 if (vf->port_vlan_id)
700 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
Kiran Patil21659032015-09-30 14:09:03 -0400701
702 spin_lock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsb7b713a2015-11-19 11:34:17 -0800703 if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
704 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
705 vf->port_vlan_id ? vf->port_vlan_id : -1,
706 true, false);
707 if (!f)
708 dev_info(&pf->pdev->dev,
709 "Could not add MAC filter %pM for VF %d\n",
710 vf->default_lan_addr.addr, vf->vf_id);
711 }
Kiran Patil21659032015-09-30 14:09:03 -0400712 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsbb3607172016-05-16 10:26:33 -0700713 i40e_write_rx_ctl(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id),
714 (u32)hena);
715 i40e_write_rx_ctl(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id),
716 (u32)(hena >> 32));
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000717 }
Neerav Parikh6dbbbfb2013-11-26 10:49:24 +0000718
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000719 /* program mac filter */
Jesse Brandeburg17652c62015-11-05 17:01:02 -0800720 ret = i40e_sync_vsi_filters(vsi);
Mitch Williamsfd1646e2014-02-13 03:48:44 -0800721 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000722 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000723
Mitch Williams6b192892014-03-06 09:02:29 +0000724 /* Set VF bandwidth if specified */
725 if (vf->tx_rate) {
726 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
727 vf->tx_rate / 50, 0, NULL);
728 if (ret)
729 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
730 vf->vf_id, ret);
731 }
732
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000733error_alloc_vsi_res:
734 return ret;
735}
736
737/**
Mitch Williams805bd5b2013-11-28 06:39:26 +0000738 * i40e_enable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000739 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000740 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000741 * enable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000742 **/
743static void i40e_enable_vf_mappings(struct i40e_vf *vf)
744{
745 struct i40e_pf *pf = vf->pf;
746 struct i40e_hw *hw = &pf->hw;
747 u32 reg, total_queue_pairs = 0;
748 int j;
749
750 /* Tell the hardware we're using noncontiguous mapping. HW requires
751 * that VF queues be mapped using this method, even when they are
752 * contiguous in real life
753 */
Shannon Nelson272cdaf22016-02-17 16:12:21 -0800754 i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
755 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000756
757 /* enable VF vplan_qtable mappings */
758 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
759 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
760
761 /* map PF queues to VF queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700762 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
763 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400764
Mitch Williams805bd5b2013-11-28 06:39:26 +0000765 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
766 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
767 total_queue_pairs++;
768 }
769
770 /* map PF queues to VSI */
771 for (j = 0; j < 7; j++) {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700772 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
Mitch Williams805bd5b2013-11-28 06:39:26 +0000773 reg = 0x07FF07FF; /* unused */
774 } else {
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700775 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000776 j * 2);
777 reg = qid;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700778 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
Mitch Williams805bd5b2013-11-28 06:39:26 +0000779 (j * 2) + 1);
780 reg |= qid << 16;
781 }
Shannon Nelson272cdaf22016-02-17 16:12:21 -0800782 i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id),
783 reg);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000784 }
785
786 i40e_flush(hw);
787}
788
789/**
790 * i40e_disable_vf_mappings
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000791 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000792 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000793 * disable VF mappings
Mitch Williams805bd5b2013-11-28 06:39:26 +0000794 **/
795static void i40e_disable_vf_mappings(struct i40e_vf *vf)
796{
797 struct i40e_pf *pf = vf->pf;
798 struct i40e_hw *hw = &pf->hw;
799 int i;
800
801 /* disable qp mappings */
802 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
803 for (i = 0; i < I40E_MAX_VSI_QP; i++)
804 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
805 I40E_QUEUE_END_OF_LIST);
806 i40e_flush(hw);
807}
808
809/**
810 * i40e_free_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000811 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000812 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000813 * free VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000814 **/
815static void i40e_free_vf_res(struct i40e_vf *vf)
816{
817 struct i40e_pf *pf = vf->pf;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000818 struct i40e_hw *hw = &pf->hw;
819 u32 reg_idx, reg;
820 int i, msix_vf;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000821
822 /* free vsi & disconnect it from the parent uplink */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700823 if (vf->lan_vsi_idx) {
824 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
825 vf->lan_vsi_idx = 0;
Mitch Williams805bd5b2013-11-28 06:39:26 +0000826 vf->lan_vsi_id = 0;
827 }
Mitch Williams9347eb72014-02-11 08:26:32 +0000828 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
829
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000830 /* disable interrupts so the VF starts in a known state */
831 for (i = 0; i < msix_vf; i++) {
832 /* format is same for both registers */
833 if (0 == i)
834 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
835 else
836 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
837 (vf->vf_id))
838 + (i - 1));
839 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
840 i40e_flush(hw);
841 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000842
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000843 /* clear the irq settings */
844 for (i = 0; i < msix_vf; i++) {
845 /* format is same for both registers */
846 if (0 == i)
847 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
848 else
849 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
850 (vf->vf_id))
851 + (i - 1));
852 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
853 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
854 wr32(hw, reg_idx, reg);
855 i40e_flush(hw);
856 }
Mitch Williams805bd5b2013-11-28 06:39:26 +0000857 /* reset some of the state varibles keeping
858 * track of the resources
859 */
860 vf->num_queue_pairs = 0;
861 vf->vf_states = 0;
Mitch Williams21be99e2015-08-31 19:54:48 -0400862 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000863}
864
865/**
866 * i40e_alloc_vf_res
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000867 * @vf: pointer to the VF info
Mitch Williams805bd5b2013-11-28 06:39:26 +0000868 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000869 * allocate VF resources
Mitch Williams805bd5b2013-11-28 06:39:26 +0000870 **/
871static int i40e_alloc_vf_res(struct i40e_vf *vf)
872{
873 struct i40e_pf *pf = vf->pf;
874 int total_queue_pairs = 0;
875 int ret;
876
877 /* allocate hw vsi context & associated resources */
878 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
879 if (ret)
880 goto error_alloc;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700881 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -0700882
883 if (vf->trusted)
884 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
885 else
886 clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
Mitch Williams805bd5b2013-11-28 06:39:26 +0000887
888 /* store the total qps number for the runtime
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000889 * VF req validation
Mitch Williams805bd5b2013-11-28 06:39:26 +0000890 */
891 vf->num_queue_pairs = total_queue_pairs;
892
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000893 /* VF is now completely initialized */
Mitch Williams805bd5b2013-11-28 06:39:26 +0000894 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
895
896error_alloc:
897 if (ret)
898 i40e_free_vf_res(vf);
899
900 return ret;
901}
902
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000903#define VF_DEVICE_STATUS 0xAA
904#define VF_TRANS_PENDING_MASK 0x20
905/**
906 * i40e_quiesce_vf_pci
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000907 * @vf: pointer to the VF structure
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000908 *
909 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
910 * if the transactions never clear.
911 **/
912static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
913{
914 struct i40e_pf *pf = vf->pf;
915 struct i40e_hw *hw = &pf->hw;
916 int vf_abs_id, i;
917 u32 reg;
918
Mitch Williamsb141d612013-11-28 06:39:36 +0000919 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000920
921 wr32(hw, I40E_PF_PCI_CIAA,
922 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
923 for (i = 0; i < 100; i++) {
924 reg = rd32(hw, I40E_PF_PCI_CIAD);
925 if ((reg & VF_TRANS_PENDING_MASK) == 0)
926 return 0;
927 udelay(1);
928 }
929 return -EIO;
930}
931
Mitch Williams805bd5b2013-11-28 06:39:26 +0000932/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000933 * i40e_reset_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000934 * @vf: pointer to the VF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000935 * @flr: VFLR was issued or not
936 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000937 * reset the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000938 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000939void i40e_reset_vf(struct i40e_vf *vf, bool flr)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000940{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000941 struct i40e_pf *pf = vf->pf;
942 struct i40e_hw *hw = &pf->hw;
Mitch Williams7e5a3132016-03-10 14:59:47 -0800943 u32 reg, reg_idx, bit_idx;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000944 bool rsd = false;
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000945 int i;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000946
Mitch Williams3ba9bcb2015-01-09 11:18:15 +0000947 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
948 return;
949
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000950 /* warn the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000951 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
952
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000953 /* In the case of a VFLR, the HW has already reset the VF and we
954 * just need to clean up, so don't hit the VFRTRIG register.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000955 */
956 if (!flr) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000957 /* reset VF using VPGEN_VFRTRIG reg */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000958 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
959 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000960 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
961 i40e_flush(hw);
962 }
Mitch Williams7369ca82016-03-18 12:18:09 -0700963 /* clear the VFLR bit in GLGEN_VFLRSTAT */
964 reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
965 bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
966 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Akeem G Abodunrin30728c52016-04-01 03:56:03 -0700967 i40e_flush(hw);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000968
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000969 if (i40e_quiesce_vf_pci(vf))
970 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
971 vf->vf_id);
972
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000973 /* poll VPGEN_VFRSTAT reg to make sure
974 * that reset is complete
975 */
Mitch Williams1750a222015-01-09 11:18:13 +0000976 for (i = 0; i < 10; i++) {
977 /* VF reset requires driver to first reset the VF and then
978 * poll the status register to make sure that the reset
979 * completed successfully. Due to internal HW FIFO flushes,
980 * we must wait 10ms before the register will be valid.
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000981 */
Mitch Williams1750a222015-01-09 11:18:13 +0000982 usleep_range(10000, 20000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000983 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
984 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
985 rsd = true;
986 break;
987 }
988 }
989
Anjali Singhai Jain57175ac2015-04-07 19:45:35 -0400990 if (flr)
991 usleep_range(10000, 20000);
992
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000993 if (!rsd)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000994 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000995 vf->vf_id);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +0000996 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +0000997 /* clear the reset bit in the VPGEN_VFRTRIG reg */
998 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
999 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
1000 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001001
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001002 /* On initial reset, we won't have any queues */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001003 if (vf->lan_vsi_idx == 0)
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001004 goto complete_reset;
1005
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001006 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001007complete_reset:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001008 /* reallocate VF resources to reset the VSI state */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001009 i40e_free_vf_res(vf);
Mitch Williams21be99e2015-08-31 19:54:48 -04001010 if (!i40e_alloc_vf_res(vf)) {
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06001011 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams21be99e2015-08-31 19:54:48 -04001012 i40e_enable_vf_mappings(vf);
1013 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1014 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
Avinash Dayanand6a234492016-07-27 12:02:37 -07001015 /* Do not notify the client during VF init */
1016 if (vf->pf->num_alloc_vfs)
1017 i40e_notify_client_of_vf_reset(pf, abs_vf_id);
Catherine Sullivandc5b4e92016-07-27 12:02:31 -07001018 vf->num_vlan = 0;
Mitch Williams21be99e2015-08-31 19:54:48 -04001019 }
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001020 /* tell the VF the reset is done */
1021 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
Mitch Williams7e5a3132016-03-10 14:59:47 -08001022
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001023 i40e_flush(hw);
Mitch Williams3ba9bcb2015-01-09 11:18:15 +00001024 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001025}
Greg Rosec3542292013-12-13 08:38:38 +00001026
1027/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001028 * i40e_free_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001029 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001030 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001031 * free VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001032 **/
1033void i40e_free_vfs(struct i40e_pf *pf)
1034{
Mitch Williamsf7414532013-11-28 06:39:40 +00001035 struct i40e_hw *hw = &pf->hw;
1036 u32 reg_idx, bit_idx;
1037 int i, tmp, vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001038
1039 if (!pf->vf)
1040 return;
Mitch Williams3ba9bcb2015-01-09 11:18:15 +00001041 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
1042 usleep_range(1000, 2000);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001043
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06001044 i40e_notify_client_of_vf_enable(pf, 0);
Mitch Williams0325fca2015-08-26 15:14:09 -04001045 for (i = 0; i < pf->num_alloc_vfs; i++)
1046 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
1047 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
1048 false);
1049
Mitch A Williams6a9ddb32014-12-09 08:53:01 +00001050 /* Disable IOV before freeing resources. This lets any VF drivers
1051 * running in the host get themselves cleaned up before we yank
1052 * the carpet out from underneath their feet.
1053 */
1054 if (!pci_vfs_assigned(pf->pdev))
1055 pci_disable_sriov(pf->pdev);
Mitch Williams6d7b9672015-03-31 00:45:02 -07001056 else
1057 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
Mitch A Williams6a9ddb32014-12-09 08:53:01 +00001058
1059 msleep(20); /* let any messages in transit get finished up */
1060
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001061 /* free up VF resources */
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001062 tmp = pf->num_alloc_vfs;
1063 pf->num_alloc_vfs = 0;
1064 for (i = 0; i < tmp; i++) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001065 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
1066 i40e_free_vf_res(&pf->vf[i]);
1067 /* disable qp mappings */
1068 i40e_disable_vf_mappings(&pf->vf[i]);
1069 }
1070
1071 kfree(pf->vf);
1072 pf->vf = NULL;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001073
Mitch Williams9e5634d2014-04-04 04:43:14 +00001074 /* This check is for when the driver is unloaded while VFs are
1075 * assigned. Setting the number of VFs to 0 through sysfs is caught
1076 * before this function ever gets called.
1077 */
Ethan Zhaoc24817b2014-07-22 18:36:43 +00001078 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williamsf7414532013-11-28 06:39:40 +00001079 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
1080 * work correctly when SR-IOV gets re-enabled.
1081 */
1082 for (vf_id = 0; vf_id < tmp; vf_id++) {
1083 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1084 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001085 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
Mitch Williamsf7414532013-11-28 06:39:40 +00001086 }
Greg Rosec3542292013-12-13 08:38:38 +00001087 }
Mitch Williams3ba9bcb2015-01-09 11:18:15 +00001088 clear_bit(__I40E_VF_DISABLE, &pf->state);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001089}
1090
1091#ifdef CONFIG_PCI_IOV
1092/**
1093 * i40e_alloc_vfs
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001094 * @pf: pointer to the PF structure
1095 * @num_alloc_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001096 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001097 * allocate VF resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001098 **/
Mitch Williams4aeec012014-02-13 03:48:47 -08001099int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001100{
1101 struct i40e_vf *vfs;
1102 int i, ret = 0;
1103
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001104 /* Disable interrupt 0 so we don't try to handle the VFLR. */
Mitch Williams2ef28cf2013-11-28 06:39:32 +00001105 i40e_irq_dynamic_disable_icr0(pf);
1106
Mitch Williams4aeec012014-02-13 03:48:47 -08001107 /* Check to see if we're just allocating resources for extant VFs */
1108 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
1109 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
1110 if (ret) {
Akeem G Abodunrinde445b32015-10-01 14:37:40 -04001111 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
Mitch Williams4aeec012014-02-13 03:48:47 -08001112 pf->num_alloc_vfs = 0;
1113 goto err_iov;
1114 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001115 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001116 /* allocate memory */
Akeem G Abodunrincc6456a2014-02-06 05:51:02 +00001117 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001118 if (!vfs) {
1119 ret = -ENOMEM;
1120 goto err_alloc;
1121 }
Mitch Williamsc674d122014-05-20 08:01:40 +00001122 pf->vf = vfs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001123
1124 /* apply default profile */
1125 for (i = 0; i < num_alloc_vfs; i++) {
1126 vfs[i].pf = pf;
1127 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
1128 vfs[i].vf_id = i;
1129
1130 /* assign default capabilities */
1131 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
Mitch Williamsc674d122014-05-20 08:01:40 +00001132 vfs[i].spoofchk = true;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001133 /* VF resources get allocated during reset */
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001134 i40e_reset_vf(&vfs[i], false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001135
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001136 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001137 pf->num_alloc_vfs = num_alloc_vfs;
1138
Avinash Dayanand6a234492016-07-27 12:02:37 -07001139 i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
1140
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001141err_alloc:
1142 if (ret)
1143 i40e_free_vfs(pf);
1144err_iov:
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00001145 /* Re-enable interrupt 0. */
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08001146 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001147 return ret;
1148}
1149
1150#endif
1151/**
1152 * i40e_pci_sriov_enable
1153 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001154 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001155 *
1156 * Enable or change the number of VFs
1157 **/
1158static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
1159{
1160#ifdef CONFIG_PCI_IOV
1161 struct i40e_pf *pf = pci_get_drvdata(pdev);
1162 int pre_existing_vfs = pci_num_vf(pdev);
1163 int err = 0;
1164
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001165 if (test_bit(__I40E_TESTING, &pf->state)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001166 dev_warn(&pdev->dev,
1167 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1168 err = -EPERM;
1169 goto err_out;
1170 }
1171
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001172 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1173 i40e_free_vfs(pf);
1174 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1175 goto out;
1176
1177 if (num_vfs > pf->num_req_vfs) {
Mitch Williams96c8d072015-08-27 11:42:35 -04001178 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1179 num_vfs, pf->num_req_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001180 err = -EPERM;
1181 goto err_out;
1182 }
1183
Mitch Williams96c8d072015-08-27 11:42:35 -04001184 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001185 err = i40e_alloc_vfs(pf, num_vfs);
1186 if (err) {
1187 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1188 goto err_out;
1189 }
1190
1191out:
1192 return num_vfs;
1193
1194err_out:
1195 return err;
1196#endif
1197 return 0;
1198}
1199
1200/**
1201 * i40e_pci_sriov_configure
1202 * @pdev: pointer to a pci_dev structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001203 * @num_vfs: number of VFs to allocate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001204 *
1205 * Enable or change the number of VFs. Called when the user updates the number
1206 * of VFs in sysfs.
1207 **/
1208int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1209{
1210 struct i40e_pf *pf = pci_get_drvdata(pdev);
1211
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001212 if (num_vfs) {
1213 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1214 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1215 i40e_do_reset_safe(pf,
1216 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1217 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001218 return i40e_pci_sriov_enable(pdev, num_vfs);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001219 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001220
Ethan Zhaoc24817b2014-07-22 18:36:43 +00001221 if (!pci_vfs_assigned(pf->pdev)) {
Mitch Williams9e5634d2014-04-04 04:43:14 +00001222 i40e_free_vfs(pf);
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07001223 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1224 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Mitch Williams9e5634d2014-04-04 04:43:14 +00001225 } else {
1226 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1227 return -EINVAL;
1228 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001229 return 0;
1230}
1231
1232/***********************virtual channel routines******************/
1233
1234/**
1235 * i40e_vc_send_msg_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001236 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001237 * @v_opcode: virtual channel opcode
1238 * @v_retval: virtual channel return value
1239 * @msg: pointer to the msg buffer
1240 * @msglen: msg length
1241 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001242 * send msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001243 **/
1244static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1245 u32 v_retval, u8 *msg, u16 msglen)
1246{
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001247 struct i40e_pf *pf;
1248 struct i40e_hw *hw;
1249 int abs_vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001250 i40e_status aq_ret;
1251
Anjali Singhai Jain6e7b5bd2014-07-10 07:58:21 +00001252 /* validate the request */
1253 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1254 return -EINVAL;
1255
1256 pf = vf->pf;
1257 hw = &pf->hw;
1258 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1259
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001260 /* single place to detect unsuccessful return values */
1261 if (v_retval) {
1262 vf->num_invalid_msgs++;
Mitch Williams18b7af52016-03-18 12:18:14 -07001263 dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
1264 vf->vf_id, v_opcode, v_retval);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001265 if (vf->num_invalid_msgs >
1266 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1267 dev_err(&pf->pdev->dev,
1268 "Number of invalid messages exceeded for VF %d\n",
1269 vf->vf_id);
1270 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1271 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1272 }
1273 } else {
1274 vf->num_valid_msgs++;
Jingjing Wu5d38c932015-09-28 14:12:39 -04001275 /* reset the invalid counter, if a valid message is received. */
1276 vf->num_invalid_msgs = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001277 }
1278
Ashish Shahf19efbb2014-08-01 13:27:06 -07001279 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
Mitch Williams7efa84b2013-11-28 06:39:41 +00001280 msg, msglen, NULL);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001281 if (aq_ret) {
Mitch Williams18b7af52016-03-18 12:18:14 -07001282 dev_info(&pf->pdev->dev,
1283 "Unable to send the message to VF %d aq_err %d\n",
1284 vf->vf_id, pf->hw.aq.asq_last_status);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001285 return -EIO;
1286 }
1287
1288 return 0;
1289}
1290
1291/**
1292 * i40e_vc_send_resp_to_vf
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001293 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001294 * @opcode: operation code
1295 * @retval: return value
1296 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001297 * send resp msg to VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001298 **/
1299static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1300 enum i40e_virtchnl_ops opcode,
1301 i40e_status retval)
1302{
1303 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1304}
1305
1306/**
1307 * i40e_vc_get_version_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001308 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001309 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001310 * called from the VF to request the API version used by the PF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001311 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001312static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001313{
1314 struct i40e_virtchnl_version_info info = {
1315 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1316 };
1317
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001318 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
Mitch Williams606a5482015-06-04 16:24:00 -04001319 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1320 if (VF_IS_V10(vf))
1321 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001322 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1323 I40E_SUCCESS, (u8 *)&info,
1324 sizeof(struct
1325 i40e_virtchnl_version_info));
1326}
1327
1328/**
1329 * i40e_vc_get_vf_resources_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001330 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001331 * @msg: pointer to the msg buffer
1332 * @msglen: msg length
1333 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001334 * called from the VF to request its resources
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001335 **/
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001336static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001337{
1338 struct i40e_virtchnl_vf_resource *vfres = NULL;
1339 struct i40e_pf *pf = vf->pf;
1340 i40e_status aq_ret = 0;
1341 struct i40e_vsi *vsi;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001342 int num_vsis = 1;
Mitch Williams442b25e2016-03-18 12:18:06 -07001343 int len = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001344 int ret;
1345
1346 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1347 aq_ret = I40E_ERR_PARAM;
1348 goto err;
1349 }
1350
1351 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1352 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1353
1354 vfres = kzalloc(len, GFP_KERNEL);
1355 if (!vfres) {
1356 aq_ret = I40E_ERR_NO_MEMORY;
1357 len = 0;
1358 goto err;
1359 }
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04001360 if (VF_IS_V11(vf))
1361 vf->driver_caps = *(u32 *)msg;
1362 else
1363 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1364 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1365 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001366
1367 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001368 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001369 if (!vsi->info.pvid)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001370 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06001371
1372 if (i40e_vf_client_capable(pf, vf->vf_id, I40E_CLIENT_IWARP) &&
1373 (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_IWARP)) {
1374 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_IWARP;
1375 set_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states);
1376 }
1377
Mitch Williamsc4e18682016-04-12 08:30:40 -07001378 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1379 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001380 } else {
Mitch Williamsc4e18682016-04-12 08:30:40 -07001381 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
1382 (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ))
1383 vfres->vf_offload_flags |=
1384 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1385 else
1386 vfres->vf_offload_flags |=
1387 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001388 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001389
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08001390 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
1391 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1392 vfres->vf_offload_flags |=
1393 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
1394 }
1395
Shannon Nelson14c5f5d2016-04-01 03:56:08 -07001396 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) {
1397 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
1398 dev_err(&pf->pdev->dev,
1399 "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
1400 vf->vf_id);
1401 ret = I40E_ERR_PARAM;
1402 goto err;
1403 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001404 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
Shannon Nelson14c5f5d2016-04-01 03:56:08 -07001405 }
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001406
Anjali Singhai Jainf6d83d12015-12-22 14:25:07 -08001407 if (pf->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) {
1408 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1409 vfres->vf_offload_flags |=
1410 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
1411 }
1412
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001413 vfres->num_vsis = num_vsis;
1414 vfres->num_queue_pairs = vf->num_queue_pairs;
1415 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
Mitch Williamsc4e18682016-04-12 08:30:40 -07001416 vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
1417 vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
1418
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001419 if (vf->lan_vsi_idx) {
Mitch Williams442b25e2016-03-18 12:18:06 -07001420 vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
1421 vfres->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
1422 vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04001423 /* VFs only use TC 0 */
Mitch Williams442b25e2016-03-18 12:18:06 -07001424 vfres->vsi_res[0].qset_handle
Mitch Williamsf578f5f2015-08-28 17:55:58 -04001425 = le16_to_cpu(vsi->info.qs_handle[0]);
Mitch Williams442b25e2016-03-18 12:18:06 -07001426 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001427 vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001428 }
1429 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1430
1431err:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001432 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001433 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1434 aq_ret, (u8 *)vfres, len);
1435
1436 kfree(vfres);
1437 return ret;
1438}
1439
1440/**
1441 * i40e_vc_reset_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001442 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001443 * @msg: pointer to the msg buffer
1444 * @msglen: msg length
1445 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001446 * called from the VF to reset itself,
1447 * unlike other virtchnl messages, PF driver
1448 * doesn't send the response back to the VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001449 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001450static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001451{
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00001452 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1453 i40e_reset_vf(vf, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001454}
1455
1456/**
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001457 * i40e_getnum_vf_vsi_vlan_filters
1458 * @vsi: pointer to the vsi
1459 *
1460 * called to get the number of VLANs offloaded on this VF
1461 **/
1462static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1463{
1464 struct i40e_mac_filter *f;
1465 int num_vlans = 0;
1466
1467 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1468 if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
1469 num_vlans++;
1470 }
1471
1472 return num_vlans;
1473}
1474
1475/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001476 * i40e_vc_config_promiscuous_mode_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001477 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001478 * @msg: pointer to the msg buffer
1479 * @msglen: msg length
1480 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001481 * called from the VF to configure the promiscuous mode of
1482 * VF vsis
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001483 **/
1484static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1485 u8 *msg, u16 msglen)
1486{
1487 struct i40e_virtchnl_promisc_info *info =
1488 (struct i40e_virtchnl_promisc_info *)msg;
1489 struct i40e_pf *pf = vf->pf;
1490 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001491 struct i40e_mac_filter *f;
1492 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001493 bool allmulti = false;
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001494 struct i40e_vsi *vsi;
1495 bool alluni = false;
1496 int aq_err = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001497
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001498 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001499 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Carolyn Wybornyd4a06582016-08-24 11:33:50 -07001500 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1501 !vsi) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001502 aq_ret = I40E_ERR_PARAM;
1503 goto error_param;
1504 }
Mitch Williamseee41722016-05-03 15:13:13 -07001505 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
1506 dev_err(&pf->pdev->dev,
1507 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1508 vf->vf_id);
1509 /* Lie to the VF on purpose. */
1510 aq_ret = 0;
1511 goto error_param;
1512 }
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001513 /* Multicast promiscuous handling*/
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001514 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1515 allmulti = true;
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001516
1517 if (vf->port_vlan_id) {
1518 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
1519 allmulti,
1520 vf->port_vlan_id,
1521 NULL);
1522 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1523 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -07001524 if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1525 continue;
1526 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
1527 vsi->seid,
1528 allmulti,
1529 f->vlan,
1530 NULL);
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001531 aq_err = pf->hw.aq.asq_last_status;
1532 if (aq_ret) {
1533 dev_err(&pf->pdev->dev,
1534 "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1535 f->vlan,
1536 i40e_stat_str(&pf->hw, aq_ret),
1537 i40e_aq_str(&pf->hw, aq_err));
1538 break;
1539 }
1540 }
1541 } else {
1542 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1543 allmulti, NULL);
1544 aq_err = pf->hw.aq.asq_last_status;
1545 if (aq_ret) {
1546 dev_err(&pf->pdev->dev,
1547 "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1548 vf->vf_id,
1549 i40e_stat_str(&pf->hw, aq_ret),
1550 i40e_aq_str(&pf->hw, aq_err));
1551 goto error_param_int;
1552 }
1553 }
1554
1555 if (!aq_ret) {
1556 dev_info(&pf->pdev->dev,
1557 "VF %d successfully set multicast promiscuous mode\n",
1558 vf->vf_id);
1559 if (allmulti)
1560 set_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
1561 else
1562 clear_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
1563 }
1564
1565 if (info->flags & I40E_FLAG_VF_UNICAST_PROMISC)
1566 alluni = true;
1567 if (vf->port_vlan_id) {
1568 aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
1569 alluni,
1570 vf->port_vlan_id,
1571 NULL);
1572 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1573 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1574 aq_ret = 0;
Arnd Bergmannce927db2016-04-29 19:44:05 +02001575 if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID) {
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001576 aq_ret =
1577 i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
1578 vsi->seid,
1579 alluni,
1580 f->vlan,
1581 NULL);
1582 aq_err = pf->hw.aq.asq_last_status;
Arnd Bergmannce927db2016-04-29 19:44:05 +02001583 }
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001584 if (aq_ret)
1585 dev_err(&pf->pdev->dev,
1586 "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1587 f->vlan,
1588 i40e_stat_str(&pf->hw, aq_ret),
1589 i40e_aq_str(&pf->hw, aq_err));
1590 }
1591 } else {
1592 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001593 allmulti, NULL,
1594 true);
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07001595 aq_err = pf->hw.aq.asq_last_status;
1596 if (aq_ret)
1597 dev_err(&pf->pdev->dev,
1598 "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1599 vf->vf_id, info->flags,
1600 i40e_stat_str(&pf->hw, aq_ret),
1601 i40e_aq_str(&pf->hw, aq_err));
1602 }
1603
1604error_param_int:
1605 if (!aq_ret) {
1606 dev_info(&pf->pdev->dev,
1607 "VF %d successfully set unicast promiscuous mode\n",
1608 vf->vf_id);
1609 if (alluni)
1610 set_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
1611 else
1612 clear_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
1613 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001614
1615error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001616 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001617 return i40e_vc_send_resp_to_vf(vf,
1618 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1619 aq_ret);
1620}
1621
1622/**
1623 * i40e_vc_config_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001624 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001625 * @msg: pointer to the msg buffer
1626 * @msglen: msg length
1627 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001628 * called from the VF to configure the rx/tx
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001629 * queues
1630 **/
1631static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1632{
1633 struct i40e_virtchnl_vsi_queue_config_info *qci =
1634 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1635 struct i40e_virtchnl_queue_pair_info *qpi;
Ashish Shah5f5e33b2014-07-10 07:58:15 +00001636 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001637 u16 vsi_id, vsi_queue_id;
1638 i40e_status aq_ret = 0;
1639 int i;
1640
1641 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1642 aq_ret = I40E_ERR_PARAM;
1643 goto error_param;
1644 }
1645
1646 vsi_id = qci->vsi_id;
1647 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1648 aq_ret = I40E_ERR_PARAM;
1649 goto error_param;
1650 }
1651 for (i = 0; i < qci->num_queue_pairs; i++) {
1652 qpi = &qci->qpair[i];
1653 vsi_queue_id = qpi->txq.queue_id;
1654 if ((qpi->txq.vsi_id != vsi_id) ||
1655 (qpi->rxq.vsi_id != vsi_id) ||
1656 (qpi->rxq.queue_id != vsi_queue_id) ||
1657 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1658 aq_ret = I40E_ERR_PARAM;
1659 goto error_param;
1660 }
1661
1662 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1663 &qpi->rxq) ||
1664 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1665 &qpi->txq)) {
1666 aq_ret = I40E_ERR_PARAM;
1667 goto error_param;
1668 }
1669 }
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001670 /* set vsi num_queue_pairs in use to num configured by VF */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001671 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001672
1673error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001674 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001675 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1676 aq_ret);
1677}
1678
1679/**
1680 * i40e_vc_config_irq_map_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001681 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001682 * @msg: pointer to the msg buffer
1683 * @msglen: msg length
1684 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001685 * called from the VF to configure the irq to
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001686 * queue map
1687 **/
1688static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1689{
1690 struct i40e_virtchnl_irq_map_info *irqmap_info =
1691 (struct i40e_virtchnl_irq_map_info *)msg;
1692 struct i40e_virtchnl_vector_map *map;
1693 u16 vsi_id, vsi_queue_id, vector_id;
1694 i40e_status aq_ret = 0;
1695 unsigned long tempmap;
1696 int i;
1697
1698 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1699 aq_ret = I40E_ERR_PARAM;
1700 goto error_param;
1701 }
1702
1703 for (i = 0; i < irqmap_info->num_vectors; i++) {
1704 map = &irqmap_info->vecmap[i];
1705
1706 vector_id = map->vector_id;
1707 vsi_id = map->vsi_id;
1708 /* validate msg params */
1709 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1710 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1711 aq_ret = I40E_ERR_PARAM;
1712 goto error_param;
1713 }
1714
1715 /* lookout for the invalid queue index */
1716 tempmap = map->rxq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001717 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001718 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1719 vsi_queue_id)) {
1720 aq_ret = I40E_ERR_PARAM;
1721 goto error_param;
1722 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001723 }
1724
1725 tempmap = map->txq_map;
Wei Yongjun48366502013-09-24 05:17:36 +00001726 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001727 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1728 vsi_queue_id)) {
1729 aq_ret = I40E_ERR_PARAM;
1730 goto error_param;
1731 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001732 }
1733
1734 i40e_config_irq_link_list(vf, vsi_id, map);
1735 }
1736error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001737 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001738 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1739 aq_ret);
1740}
1741
1742/**
1743 * i40e_vc_enable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001744 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001745 * @msg: pointer to the msg buffer
1746 * @msglen: msg length
1747 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001748 * called from the VF to enable all or specific queue(s)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001749 **/
1750static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1751{
1752 struct i40e_virtchnl_queue_select *vqs =
1753 (struct i40e_virtchnl_queue_select *)msg;
1754 struct i40e_pf *pf = vf->pf;
1755 u16 vsi_id = vqs->vsi_id;
1756 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001757
1758 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1759 aq_ret = I40E_ERR_PARAM;
1760 goto error_param;
1761 }
1762
1763 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1764 aq_ret = I40E_ERR_PARAM;
1765 goto error_param;
1766 }
1767
1768 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1769 aq_ret = I40E_ERR_PARAM;
1770 goto error_param;
1771 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001772
1773 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
Mitch Williams88f65632013-11-28 06:39:28 +00001774 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001775error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001776 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001777 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1778 aq_ret);
1779}
1780
1781/**
1782 * i40e_vc_disable_queues_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001783 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001784 * @msg: pointer to the msg buffer
1785 * @msglen: msg length
1786 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001787 * called from the VF to disable all or specific
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001788 * queue(s)
1789 **/
1790static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1791{
1792 struct i40e_virtchnl_queue_select *vqs =
1793 (struct i40e_virtchnl_queue_select *)msg;
1794 struct i40e_pf *pf = vf->pf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001795 i40e_status aq_ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001796
1797 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1798 aq_ret = I40E_ERR_PARAM;
1799 goto error_param;
1800 }
1801
1802 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1803 aq_ret = I40E_ERR_PARAM;
1804 goto error_param;
1805 }
1806
1807 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1808 aq_ret = I40E_ERR_PARAM;
1809 goto error_param;
1810 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001811
1812 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
Mitch Williams88f65632013-11-28 06:39:28 +00001813 aq_ret = I40E_ERR_TIMEOUT;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001814
1815error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001816 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001817 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1818 aq_ret);
1819}
1820
1821/**
1822 * i40e_vc_get_stats_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001823 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001824 * @msg: pointer to the msg buffer
1825 * @msglen: msg length
1826 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001827 * called from the VF to get vsi stats
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001828 **/
1829static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1830{
1831 struct i40e_virtchnl_queue_select *vqs =
1832 (struct i40e_virtchnl_queue_select *)msg;
1833 struct i40e_pf *pf = vf->pf;
1834 struct i40e_eth_stats stats;
1835 i40e_status aq_ret = 0;
1836 struct i40e_vsi *vsi;
1837
1838 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1839
1840 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1841 aq_ret = I40E_ERR_PARAM;
1842 goto error_param;
1843 }
1844
1845 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1846 aq_ret = I40E_ERR_PARAM;
1847 goto error_param;
1848 }
1849
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001850 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001851 if (!vsi) {
1852 aq_ret = I40E_ERR_PARAM;
1853 goto error_param;
1854 }
1855 i40e_update_eth_stats(vsi);
Mitch Williams5a9769c2013-11-28 06:39:38 +00001856 stats = vsi->eth_stats;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001857
1858error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001859 /* send the response back to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001860 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1861 (u8 *)&stats, sizeof(stats));
1862}
1863
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07001864/* If the VF is not trusted restrict the number of MAC/VLAN it can program */
1865#define I40E_VC_MAX_MAC_ADDR_PER_VF 8
1866#define I40E_VC_MAX_VLAN_PER_VF 8
1867
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001868/**
Greg Rosef657a6e2013-11-28 06:39:42 +00001869 * i40e_check_vf_permission
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001870 * @vf: pointer to the VF info
Greg Rosef657a6e2013-11-28 06:39:42 +00001871 * @macaddr: pointer to the MAC Address being checked
1872 *
1873 * Check if the VF has permission to add or delete unicast MAC address
1874 * filters and return error code -EPERM if not. Then check if the
1875 * address filter requested is broadcast or zero and if so return
1876 * an invalid MAC address error code.
1877 **/
1878static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1879{
1880 struct i40e_pf *pf = vf->pf;
1881 int ret = 0;
1882
1883 if (is_broadcast_ether_addr(macaddr) ||
1884 is_zero_ether_addr(macaddr)) {
1885 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1886 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rose5017c2a2013-12-07 10:36:54 +00001887 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -07001888 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
Greg Rose5017c2a2013-12-07 10:36:54 +00001889 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001890 /* If the host VMM administrator has set the VF MAC address
1891 * administratively via the ndo_set_vf_mac command then deny
1892 * permission to the VF to add or delete unicast MAC addresses.
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -07001893 * Unless the VF is privileged and then it can do whatever.
Greg Rose5017c2a2013-12-07 10:36:54 +00001894 * The VF may request to set the MAC address filter already
1895 * assigned to it so do not return an error in that case.
Greg Rosef657a6e2013-11-28 06:39:42 +00001896 */
1897 dev_err(&pf->pdev->dev,
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -07001898 "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
Greg Rosef657a6e2013-11-28 06:39:42 +00001899 ret = -EPERM;
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07001900 } else if ((vf->num_mac >= I40E_VC_MAX_MAC_ADDR_PER_VF) &&
1901 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
1902 dev_err(&pf->pdev->dev,
1903 "VF is not trusted, switch the VF to trusted to add more functionality\n");
1904 ret = -EPERM;
Greg Rosef657a6e2013-11-28 06:39:42 +00001905 }
1906 return ret;
1907}
1908
1909/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001910 * i40e_vc_add_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001911 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001912 * @msg: pointer to the msg buffer
1913 * @msglen: msg length
1914 *
1915 * add guest mac address filter
1916 **/
1917static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1918{
1919 struct i40e_virtchnl_ether_addr_list *al =
1920 (struct i40e_virtchnl_ether_addr_list *)msg;
1921 struct i40e_pf *pf = vf->pf;
1922 struct i40e_vsi *vsi = NULL;
1923 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001924 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001925 int i;
1926
1927 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001928 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001929 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001930 goto error_param;
1931 }
1932
1933 for (i = 0; i < al->num_elements; i++) {
Greg Rosef657a6e2013-11-28 06:39:42 +00001934 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1935 if (ret)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001936 goto error_param;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001937 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07001938 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001939
Kiran Patil21659032015-09-30 14:09:03 -04001940 /* Lock once, because all function inside for loop accesses VSI's
1941 * MAC filter list which needs to be protected using same lock.
1942 */
1943 spin_lock_bh(&vsi->mac_filter_list_lock);
1944
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001945 /* add new addresses to the list */
1946 for (i = 0; i < al->num_elements; i++) {
1947 struct i40e_mac_filter *f;
1948
1949 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
Mitch Williams7e68edf92013-11-16 10:00:41 +00001950 if (!f) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001951 if (i40e_is_vsi_in_vlan(vsi))
1952 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1953 true, false);
1954 else
1955 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1956 true, false);
1957 }
1958
1959 if (!f) {
1960 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04001961 "Unable to add MAC filter %pM for VF %d\n",
1962 al->list[i].addr, vf->vf_id);
Greg Rosef657a6e2013-11-28 06:39:42 +00001963 ret = I40E_ERR_PARAM;
Kiran Patil21659032015-09-30 14:09:03 -04001964 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001965 goto error_param;
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07001966 } else {
1967 vf->num_mac++;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001968 }
1969 }
Kiran Patil21659032015-09-30 14:09:03 -04001970 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001971
1972 /* program the updated filter list */
Mitch Williamsea02e902015-11-09 15:35:50 -08001973 ret = i40e_sync_vsi_filters(vsi);
1974 if (ret)
1975 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
1976 vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001977
1978error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001979 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001980 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00001981 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001982}
1983
1984/**
1985 * i40e_vc_del_mac_addr_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001986 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00001987 * @msg: pointer to the msg buffer
1988 * @msglen: msg length
1989 *
1990 * remove guest mac address filter
1991 **/
1992static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1993{
1994 struct i40e_virtchnl_ether_addr_list *al =
1995 (struct i40e_virtchnl_ether_addr_list *)msg;
1996 struct i40e_pf *pf = vf->pf;
1997 struct i40e_vsi *vsi = NULL;
1998 u16 vsi_id = al->vsi_id;
Greg Rosef657a6e2013-11-28 06:39:42 +00001999 i40e_status ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002000 int i;
2001
2002 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002003 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
Greg Rosef657a6e2013-11-28 06:39:42 +00002004 ret = I40E_ERR_PARAM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002005 goto error_param;
2006 }
Greg Rosef657a6e2013-11-28 06:39:42 +00002007
2008 for (i = 0; i < al->num_elements; i++) {
Mitch Williams700bbf62013-12-21 05:44:45 +00002009 if (is_broadcast_ether_addr(al->list[i].addr) ||
2010 is_zero_ether_addr(al->list[i].addr)) {
Mitch Williams8d8f2292015-10-21 19:47:11 -04002011 dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
2012 al->list[i].addr, vf->vf_id);
Mitch Williams700bbf62013-12-21 05:44:45 +00002013 ret = I40E_ERR_INVALID_MAC_ADDR;
Greg Rosef657a6e2013-11-28 06:39:42 +00002014 goto error_param;
Mitch Williams700bbf62013-12-21 05:44:45 +00002015 }
Patryk Małek23580e82018-08-28 10:16:09 -07002016
2017 if (vf->pf_set_mac &&
2018 ether_addr_equal(al->list[i].addr,
2019 vf->default_lan_addr.addr)) {
2020 dev_err(&pf->pdev->dev,
2021 "MAC addr %pM has been set by PF, cannot delete it for VF %d, reset VF to change MAC addr\n",
2022 vf->default_lan_addr.addr, vf->vf_id);
2023 ret = I40E_ERR_PARAM;
2024 goto error_param;
2025 }
Greg Rosef657a6e2013-11-28 06:39:42 +00002026 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002027 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002028
Kiran Patil21659032015-09-30 14:09:03 -04002029 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002030 /* delete addresses from the list */
2031 for (i = 0; i < al->num_elements; i++)
Mitch Williamsb36e9ab2015-11-19 11:34:16 -08002032 if (i40e_del_mac_all_vlan(vsi, al->list[i].addr, true, false)) {
2033 ret = I40E_ERR_INVALID_MAC_ADDR;
2034 spin_unlock_bh(&vsi->mac_filter_list_lock);
2035 goto error_param;
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07002036 } else {
2037 vf->num_mac--;
Mitch Williamsb36e9ab2015-11-19 11:34:16 -08002038 }
2039
Kiran Patil21659032015-09-30 14:09:03 -04002040 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002041
2042 /* program the updated filter list */
Mitch Williamsea02e902015-11-09 15:35:50 -08002043 ret = i40e_sync_vsi_filters(vsi);
2044 if (ret)
2045 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
2046 vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002047
2048error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002049 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002050 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
Greg Rosef657a6e2013-11-28 06:39:42 +00002051 ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002052}
2053
2054/**
2055 * i40e_vc_add_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002056 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002057 * @msg: pointer to the msg buffer
2058 * @msglen: msg length
2059 *
2060 * program guest vlan id
2061 **/
2062static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2063{
2064 struct i40e_virtchnl_vlan_filter_list *vfl =
2065 (struct i40e_virtchnl_vlan_filter_list *)msg;
2066 struct i40e_pf *pf = vf->pf;
2067 struct i40e_vsi *vsi = NULL;
2068 u16 vsi_id = vfl->vsi_id;
2069 i40e_status aq_ret = 0;
2070 int i;
2071
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07002072 if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
2073 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2074 dev_err(&pf->pdev->dev,
2075 "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
2076 goto error_param;
2077 }
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002078 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002079 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2080 aq_ret = I40E_ERR_PARAM;
2081 goto error_param;
2082 }
2083
2084 for (i = 0; i < vfl->num_elements; i++) {
2085 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2086 aq_ret = I40E_ERR_PARAM;
2087 dev_err(&pf->pdev->dev,
2088 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
2089 goto error_param;
2090 }
2091 }
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002092 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002093 if (vsi->info.pvid) {
2094 aq_ret = I40E_ERR_PARAM;
2095 goto error_param;
2096 }
2097
2098 i40e_vlan_stripping_enable(vsi);
2099 for (i = 0; i < vfl->num_elements; i++) {
2100 /* add new VLAN filter */
2101 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07002102 if (!ret)
2103 vf->num_vlan++;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002104
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07002105 if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
2106 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2107 true,
2108 vfl->vlan_id[i],
2109 NULL);
2110 if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
2111 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2112 true,
2113 vfl->vlan_id[i],
2114 NULL);
2115
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002116 if (ret)
2117 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04002118 "Unable to add VLAN filter %d for VF %d, error %d\n",
2119 vfl->vlan_id[i], vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002120 }
2121
2122error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002123 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002124 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
2125}
2126
2127/**
2128 * i40e_vc_remove_vlan_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002129 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002130 * @msg: pointer to the msg buffer
2131 * @msglen: msg length
2132 *
2133 * remove programmed guest vlan id
2134 **/
2135static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2136{
2137 struct i40e_virtchnl_vlan_filter_list *vfl =
2138 (struct i40e_virtchnl_vlan_filter_list *)msg;
2139 struct i40e_pf *pf = vf->pf;
2140 struct i40e_vsi *vsi = NULL;
2141 u16 vsi_id = vfl->vsi_id;
2142 i40e_status aq_ret = 0;
2143 int i;
2144
2145 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002146 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2147 aq_ret = I40E_ERR_PARAM;
2148 goto error_param;
2149 }
2150
2151 for (i = 0; i < vfl->num_elements; i++) {
2152 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2153 aq_ret = I40E_ERR_PARAM;
2154 goto error_param;
2155 }
2156 }
2157
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002158 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002159 if (vsi->info.pvid) {
2160 aq_ret = I40E_ERR_PARAM;
2161 goto error_param;
2162 }
2163
2164 for (i = 0; i < vfl->num_elements; i++) {
2165 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
Anjali Singhai Jain5f527ba2016-04-13 03:08:22 -07002166 if (!ret)
2167 vf->num_vlan--;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002168
Anjali Singhai Jain5676a8b2016-04-12 08:30:51 -07002169 if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
2170 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2171 false,
2172 vfl->vlan_id[i],
2173 NULL);
2174 if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
2175 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2176 false,
2177 vfl->vlan_id[i],
2178 NULL);
2179
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002180 if (ret)
2181 dev_err(&pf->pdev->dev,
Mitch Williams8d8f2292015-10-21 19:47:11 -04002182 "Unable to delete VLAN filter %d for VF %d, error %d\n",
2183 vfl->vlan_id[i], vf->vf_id, ret);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002184 }
2185
2186error_param:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002187 /* send the response to the VF */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002188 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
2189}
2190
2191/**
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002192 * i40e_vc_iwarp_msg
2193 * @vf: pointer to the VF info
2194 * @msg: pointer to the msg buffer
2195 * @msglen: msg length
2196 *
2197 * called from the VF for the iwarp msgs
2198 **/
2199static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2200{
2201 struct i40e_pf *pf = vf->pf;
2202 int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
2203 i40e_status aq_ret = 0;
2204
2205 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2206 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
2207 aq_ret = I40E_ERR_PARAM;
2208 goto error_param;
2209 }
2210
2211 i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
2212 msg, msglen);
2213
2214error_param:
2215 /* send the response to the VF */
2216 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_IWARP,
2217 aq_ret);
2218}
2219
2220/**
2221 * i40e_vc_iwarp_qvmap_msg
2222 * @vf: pointer to the VF info
2223 * @msg: pointer to the msg buffer
2224 * @msglen: msg length
2225 * @config: config qvmap or release it
2226 *
2227 * called from the VF for the iwarp msgs
2228 **/
2229static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
2230 bool config)
2231{
2232 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info =
2233 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2234 i40e_status aq_ret = 0;
2235
2236 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2237 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
2238 aq_ret = I40E_ERR_PARAM;
2239 goto error_param;
2240 }
2241
2242 if (config) {
2243 if (i40e_config_iwarp_qvlist(vf, qvlist_info))
2244 aq_ret = I40E_ERR_PARAM;
2245 } else {
2246 i40e_release_iwarp_qvlist(vf);
2247 }
2248
2249error_param:
2250 /* send the response to the VF */
2251 return i40e_vc_send_resp_to_vf(vf,
Mitch Williams8d9d9272016-08-24 11:33:49 -07002252 config ? I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP :
2253 I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002254 aq_ret);
2255}
2256
2257/**
Mitch Williamsc4e18682016-04-12 08:30:40 -07002258 * i40e_vc_config_rss_key
2259 * @vf: pointer to the VF info
2260 * @msg: pointer to the msg buffer
2261 * @msglen: msg length
2262 *
2263 * Configure the VF's RSS key
2264 **/
2265static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
2266{
2267 struct i40e_virtchnl_rss_key *vrk =
2268 (struct i40e_virtchnl_rss_key *)msg;
2269 struct i40e_pf *pf = vf->pf;
2270 struct i40e_vsi *vsi = NULL;
2271 u16 vsi_id = vrk->vsi_id;
2272 i40e_status aq_ret = 0;
2273
2274 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Mitch Williamsc4e18682016-04-12 08:30:40 -07002275 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2276 (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
2277 aq_ret = I40E_ERR_PARAM;
2278 goto err;
2279 }
2280
2281 vsi = pf->vsi[vf->lan_vsi_idx];
2282 aq_ret = i40e_config_rss(vsi, vrk->key, NULL, 0);
2283err:
2284 /* send the response to the VF */
2285 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
2286 aq_ret);
2287}
2288
2289/**
2290 * i40e_vc_config_rss_lut
2291 * @vf: pointer to the VF info
2292 * @msg: pointer to the msg buffer
2293 * @msglen: msg length
2294 *
2295 * Configure the VF's RSS LUT
2296 **/
2297static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
2298{
2299 struct i40e_virtchnl_rss_lut *vrl =
2300 (struct i40e_virtchnl_rss_lut *)msg;
2301 struct i40e_pf *pf = vf->pf;
2302 struct i40e_vsi *vsi = NULL;
2303 u16 vsi_id = vrl->vsi_id;
2304 i40e_status aq_ret = 0;
2305
2306 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
Mitch Williamsc4e18682016-04-12 08:30:40 -07002307 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2308 (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
2309 aq_ret = I40E_ERR_PARAM;
2310 goto err;
2311 }
2312
2313 vsi = pf->vsi[vf->lan_vsi_idx];
2314 aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
2315 /* send the response to the VF */
2316err:
2317 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
2318 aq_ret);
2319}
2320
2321/**
2322 * i40e_vc_get_rss_hena
2323 * @vf: pointer to the VF info
2324 * @msg: pointer to the msg buffer
2325 * @msglen: msg length
2326 *
2327 * Return the RSS HENA bits allowed by the hardware
2328 **/
2329static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2330{
2331 struct i40e_virtchnl_rss_hena *vrh = NULL;
2332 struct i40e_pf *pf = vf->pf;
2333 i40e_status aq_ret = 0;
2334 int len = 0;
2335
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -07002336 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
Mitch Williamsc4e18682016-04-12 08:30:40 -07002337 aq_ret = I40E_ERR_PARAM;
2338 goto err;
2339 }
2340 len = sizeof(struct i40e_virtchnl_rss_hena);
2341
2342 vrh = kzalloc(len, GFP_KERNEL);
2343 if (!vrh) {
2344 aq_ret = I40E_ERR_NO_MEMORY;
2345 len = 0;
2346 goto err;
2347 }
2348 vrh->hena = i40e_pf_get_default_rss_hena(pf);
2349err:
2350 /* send the response back to the VF */
2351 aq_ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
2352 aq_ret, (u8 *)vrh, len);
Mitch Williamsb7d2cd92016-07-27 12:02:39 -07002353 kfree(vrh);
Mitch Williamsc4e18682016-04-12 08:30:40 -07002354 return aq_ret;
2355}
2356
2357/**
2358 * i40e_vc_set_rss_hena
2359 * @vf: pointer to the VF info
2360 * @msg: pointer to the msg buffer
2361 * @msglen: msg length
2362 *
2363 * Set the RSS HENA bits for the VF
2364 **/
2365static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2366{
2367 struct i40e_virtchnl_rss_hena *vrh =
2368 (struct i40e_virtchnl_rss_hena *)msg;
2369 struct i40e_pf *pf = vf->pf;
2370 struct i40e_hw *hw = &pf->hw;
2371 i40e_status aq_ret = 0;
2372
Anjali Singhai Jain692fb0a2016-04-13 03:08:21 -07002373 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
Mitch Williamsc4e18682016-04-12 08:30:40 -07002374 aq_ret = I40E_ERR_PARAM;
2375 goto err;
2376 }
2377 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)vrh->hena);
2378 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_id),
2379 (u32)(vrh->hena >> 32));
2380
2381 /* send the response to the VF */
2382err:
2383 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_SET_RSS_HENA,
2384 aq_ret);
2385}
2386
2387/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002388 * i40e_vc_validate_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002389 * @vf: pointer to the VF info
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002390 * @msg: pointer to the msg buffer
2391 * @msglen: msg length
2392 * @msghndl: msg handle
2393 *
2394 * validate msg
2395 **/
2396static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
2397 u32 v_retval, u8 *msg, u16 msglen)
2398{
2399 bool err_msg_format = false;
Catherine Sullivan3ed439c2016-04-13 03:08:27 -07002400 int valid_len = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002401
2402 /* Check if VF is disabled. */
2403 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
2404 return I40E_ERR_PARAM;
2405
2406 /* Validate message length. */
2407 switch (v_opcode) {
2408 case I40E_VIRTCHNL_OP_VERSION:
2409 valid_len = sizeof(struct i40e_virtchnl_version_info);
2410 break;
2411 case I40E_VIRTCHNL_OP_RESET_VF:
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002412 break;
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04002413 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
2414 if (VF_IS_V11(vf))
2415 valid_len = sizeof(u32);
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04002416 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002417 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
2418 valid_len = sizeof(struct i40e_virtchnl_txq_info);
2419 break;
2420 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
2421 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
2422 break;
2423 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
2424 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
2425 if (msglen >= valid_len) {
2426 struct i40e_virtchnl_vsi_queue_config_info *vqc =
2427 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
2428 valid_len += (vqc->num_queue_pairs *
2429 sizeof(struct
2430 i40e_virtchnl_queue_pair_info));
2431 if (vqc->num_queue_pairs == 0)
2432 err_msg_format = true;
2433 }
2434 break;
2435 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
2436 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
2437 if (msglen >= valid_len) {
2438 struct i40e_virtchnl_irq_map_info *vimi =
2439 (struct i40e_virtchnl_irq_map_info *)msg;
2440 valid_len += (vimi->num_vectors *
2441 sizeof(struct i40e_virtchnl_vector_map));
2442 if (vimi->num_vectors == 0)
2443 err_msg_format = true;
2444 }
2445 break;
2446 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
2447 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
2448 valid_len = sizeof(struct i40e_virtchnl_queue_select);
2449 break;
2450 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
2451 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
2452 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
2453 if (msglen >= valid_len) {
2454 struct i40e_virtchnl_ether_addr_list *veal =
2455 (struct i40e_virtchnl_ether_addr_list *)msg;
2456 valid_len += veal->num_elements *
2457 sizeof(struct i40e_virtchnl_ether_addr);
2458 if (veal->num_elements == 0)
2459 err_msg_format = true;
2460 }
2461 break;
2462 case I40E_VIRTCHNL_OP_ADD_VLAN:
2463 case I40E_VIRTCHNL_OP_DEL_VLAN:
2464 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
2465 if (msglen >= valid_len) {
2466 struct i40e_virtchnl_vlan_filter_list *vfl =
2467 (struct i40e_virtchnl_vlan_filter_list *)msg;
2468 valid_len += vfl->num_elements * sizeof(u16);
2469 if (vfl->num_elements == 0)
2470 err_msg_format = true;
2471 }
2472 break;
2473 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
2474 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
2475 break;
2476 case I40E_VIRTCHNL_OP_GET_STATS:
2477 valid_len = sizeof(struct i40e_virtchnl_queue_select);
2478 break;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002479 case I40E_VIRTCHNL_OP_IWARP:
2480 /* These messages are opaque to us and will be validated in
2481 * the RDMA client code. We just need to check for nonzero
2482 * length. The firmware will enforce max length restrictions.
2483 */
2484 if (msglen)
2485 valid_len = msglen;
2486 else
2487 err_msg_format = true;
2488 break;
2489 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2490 valid_len = 0;
2491 break;
2492 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2493 valid_len = sizeof(struct i40e_virtchnl_iwarp_qvlist_info);
2494 if (msglen >= valid_len) {
2495 struct i40e_virtchnl_iwarp_qvlist_info *qv =
2496 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2497 if (qv->num_vectors == 0) {
2498 err_msg_format = true;
2499 break;
2500 }
2501 valid_len += ((qv->num_vectors - 1) *
2502 sizeof(struct i40e_virtchnl_iwarp_qv_info));
2503 }
2504 break;
Mitch Williamsc4e18682016-04-12 08:30:40 -07002505 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
2506 valid_len = sizeof(struct i40e_virtchnl_rss_key);
2507 if (msglen >= valid_len) {
2508 struct i40e_virtchnl_rss_key *vrk =
2509 (struct i40e_virtchnl_rss_key *)msg;
2510 if (vrk->key_len != I40E_HKEY_ARRAY_SIZE) {
2511 err_msg_format = true;
2512 break;
2513 }
2514 valid_len += vrk->key_len - 1;
2515 }
2516 break;
2517 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
2518 valid_len = sizeof(struct i40e_virtchnl_rss_lut);
2519 if (msglen >= valid_len) {
2520 struct i40e_virtchnl_rss_lut *vrl =
2521 (struct i40e_virtchnl_rss_lut *)msg;
2522 if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE) {
2523 err_msg_format = true;
2524 break;
2525 }
2526 valid_len += vrl->lut_entries - 1;
2527 }
2528 break;
2529 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
Mitch Williamsc4e18682016-04-12 08:30:40 -07002530 break;
2531 case I40E_VIRTCHNL_OP_SET_RSS_HENA:
2532 valid_len = sizeof(struct i40e_virtchnl_rss_hena);
2533 break;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002534 /* These are always errors coming from the VF. */
2535 case I40E_VIRTCHNL_OP_EVENT:
2536 case I40E_VIRTCHNL_OP_UNKNOWN:
2537 default:
2538 return -EPERM;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002539 }
2540 /* few more checks */
2541 if ((valid_len != msglen) || (err_msg_format)) {
2542 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
2543 return -EINVAL;
2544 } else {
2545 return 0;
2546 }
2547}
2548
2549/**
2550 * i40e_vc_process_vf_msg
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002551 * @pf: pointer to the PF structure
2552 * @vf_id: source VF id
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002553 * @msg: pointer to the msg buffer
2554 * @msglen: msg length
2555 * @msghndl: msg handle
2556 *
2557 * called from the common aeq/arq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002558 * process request from VF
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002559 **/
Jesse Brandeburga1b5a242016-04-13 03:08:29 -07002560int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002561 u32 v_retval, u8 *msg, u16 msglen)
2562{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002563 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburga1b5a242016-04-13 03:08:29 -07002564 int local_vf_id = vf_id - (s16)hw->func_caps.vf_base_id;
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00002565 struct i40e_vf *vf;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002566 int ret;
2567
2568 pf->vf_aq_requests++;
Mitch Williams7efa84b2013-11-28 06:39:41 +00002569 if (local_vf_id >= pf->num_alloc_vfs)
Mitch Williams6c1b5bf2013-11-28 06:39:30 +00002570 return -EINVAL;
Mitch Williams7efa84b2013-11-28 06:39:41 +00002571 vf = &(pf->vf[local_vf_id]);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002572 /* perform basic checks on the msg */
2573 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
2574
2575 if (ret) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002576 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00002577 local_vf_id, v_opcode, msglen);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002578 return ret;
2579 }
Mitch Williamsbae3cae2014-01-14 00:49:49 -08002580
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002581 switch (v_opcode) {
2582 case I40E_VIRTCHNL_OP_VERSION:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04002583 ret = i40e_vc_get_version_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002584 break;
2585 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
Mitch Williamsf4ca1a22015-06-04 16:23:57 -04002586 ret = i40e_vc_get_vf_resources_msg(vf, msg);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002587 break;
2588 case I40E_VIRTCHNL_OP_RESET_VF:
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00002589 i40e_vc_reset_vf_msg(vf);
2590 ret = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002591 break;
2592 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
2593 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
2594 break;
2595 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
2596 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
2597 break;
2598 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
2599 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
2600 break;
2601 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
2602 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
Mitch Williams055b2952015-04-07 19:45:33 -04002603 i40e_vc_notify_vf_link_state(vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002604 break;
2605 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
2606 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
2607 break;
2608 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
2609 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
2610 break;
2611 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
2612 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
2613 break;
2614 case I40E_VIRTCHNL_OP_ADD_VLAN:
2615 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
2616 break;
2617 case I40E_VIRTCHNL_OP_DEL_VLAN:
2618 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
2619 break;
2620 case I40E_VIRTCHNL_OP_GET_STATS:
2621 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
2622 break;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002623 case I40E_VIRTCHNL_OP_IWARP:
2624 ret = i40e_vc_iwarp_msg(vf, msg, msglen);
2625 break;
2626 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2627 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
2628 break;
2629 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2630 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
2631 break;
Mitch Williamsc4e18682016-04-12 08:30:40 -07002632 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
2633 ret = i40e_vc_config_rss_key(vf, msg, msglen);
2634 break;
2635 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
2636 ret = i40e_vc_config_rss_lut(vf, msg, msglen);
2637 break;
2638 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
2639 ret = i40e_vc_get_rss_hena(vf, msg, msglen);
2640 break;
2641 case I40E_VIRTCHNL_OP_SET_RSS_HENA:
2642 ret = i40e_vc_set_rss_hena(vf, msg, msglen);
2643 break;
2644
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002645 case I40E_VIRTCHNL_OP_UNKNOWN:
2646 default:
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002647 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
Mitch Williams7efa84b2013-11-28 06:39:41 +00002648 v_opcode, local_vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002649 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
2650 I40E_ERR_NOT_IMPLEMENTED);
2651 break;
2652 }
2653
2654 return ret;
2655}
2656
2657/**
2658 * i40e_vc_process_vflr_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002659 * @pf: pointer to the PF structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002660 *
2661 * called from the vlfr irq handler to
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002662 * free up VF resources and state variables
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002663 **/
2664int i40e_vc_process_vflr_event(struct i40e_pf *pf)
2665{
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002666 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburga1b5a242016-04-13 03:08:29 -07002667 u32 reg, reg_idx, bit_idx;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002668 struct i40e_vf *vf;
Jesse Brandeburga1b5a242016-04-13 03:08:29 -07002669 int vf_id;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002670
2671 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2672 return 0;
2673
Mitch Williams0d790322016-01-15 14:33:17 -08002674 /* Re-enable the VFLR interrupt cause here, before looking for which
2675 * VF got reset. Otherwise, if another VF gets a reset while the
2676 * first one is being processed, that interrupt will be lost, and
2677 * that VF will be stuck in reset forever.
2678 */
Mitch Williamsc5c2f7c2014-11-11 03:15:04 +00002679 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2680 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2681 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2682 i40e_flush(hw);
2683
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002684 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2685 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2686 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2687 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002688 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002689 vf = &pf->vf[vf_id];
2690 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
Mitch Williams7369ca82016-03-18 12:18:09 -07002691 if (reg & BIT(bit_idx))
Mitch Williams7e5a3132016-03-10 14:59:47 -08002692 /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
Mitch Williams7369ca82016-03-18 12:18:09 -07002693 i40e_reset_vf(vf, true);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002694 }
2695
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002696 return 0;
2697}
2698
2699/**
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002700 * i40e_ndo_set_vf_mac
2701 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002702 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002703 * @mac: mac address
2704 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002705 * program VF mac address
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002706 **/
2707int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2708{
2709 struct i40e_netdev_priv *np = netdev_priv(netdev);
2710 struct i40e_vsi *vsi = np->vsi;
2711 struct i40e_pf *pf = vsi->back;
2712 struct i40e_mac_filter *f;
2713 struct i40e_vf *vf;
2714 int ret = 0;
2715
2716 /* validate the request */
2717 if (vf_id >= pf->num_alloc_vfs) {
2718 dev_err(&pf->pdev->dev,
2719 "Invalid VF Identifier %d\n", vf_id);
2720 ret = -EINVAL;
2721 goto error_param;
2722 }
2723
2724 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002725 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002726 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002727 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2728 vf_id);
2729 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002730 goto error_param;
2731 }
2732
Mitch Williamsefd8e392015-12-22 15:34:43 -08002733 if (is_multicast_ether_addr(mac)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002734 dev_err(&pf->pdev->dev,
Mitch Williamsefd8e392015-12-22 15:34:43 -08002735 "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002736 ret = -EINVAL;
2737 goto error_param;
2738 }
2739
Kiran Patil21659032015-09-30 14:09:03 -04002740 /* Lock once because below invoked function add/del_filter requires
2741 * mac_filter_list_lock to be held
2742 */
2743 spin_lock_bh(&vsi->mac_filter_list_lock);
2744
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002745 /* delete the temporary mac address */
Mitch Williamsefd8e392015-12-22 15:34:43 -08002746 if (!is_zero_ether_addr(vf->default_lan_addr.addr))
2747 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2748 vf->port_vlan_id ? vf->port_vlan_id : -1,
2749 true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002750
Greg Rose29f71bb2014-05-20 08:01:45 +00002751 /* Delete all the filters for this VSI - we're going to kill it
2752 * anyway.
2753 */
2754 list_for_each_entry(f, &vsi->mac_filter_list, list)
2755 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002756
Kiran Patil21659032015-09-30 14:09:03 -04002757 spin_unlock_bh(&vsi->mac_filter_list_lock);
2758
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002759 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2760 /* program mac filter */
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002761 if (i40e_sync_vsi_filters(vsi)) {
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002762 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2763 ret = -EIO;
2764 goto error_param;
2765 }
Greg Rose9a173902014-05-22 06:32:02 +00002766 ether_addr_copy(vf->default_lan_addr.addr, mac);
Greg Rosef657a6e2013-11-28 06:39:42 +00002767 vf->pf_set_mac = true;
Greg Rose17413a82014-06-04 01:23:13 +00002768 /* Force the VF driver stop so it has to reload with new MAC address */
2769 i40e_vc_disable_vf(pf, vf);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002770 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002771
2772error_param:
2773 return ret;
2774}
2775
2776/**
2777 * i40e_ndo_set_vf_port_vlan
2778 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002779 * @vf_id: VF identifier
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002780 * @vlan_id: mac address
2781 * @qos: priority setting
Moshe Shemesh79aab092016-09-22 12:11:15 +03002782 * @vlan_proto: vlan protocol
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002783 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002784 * program VF vlan id and/or qos
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002785 **/
Moshe Shemesh79aab092016-09-22 12:11:15 +03002786int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
2787 u16 vlan_id, u8 qos, __be16 vlan_proto)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002788{
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002789 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002790 struct i40e_netdev_priv *np = netdev_priv(netdev);
2791 struct i40e_pf *pf = np->vsi->back;
Kiran Patil21659032015-09-30 14:09:03 -04002792 bool is_vsi_in_vlan = false;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002793 struct i40e_vsi *vsi;
2794 struct i40e_vf *vf;
2795 int ret = 0;
2796
2797 /* validate the request */
2798 if (vf_id >= pf->num_alloc_vfs) {
2799 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2800 ret = -EINVAL;
2801 goto error_pvid;
2802 }
2803
2804 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2805 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2806 ret = -EINVAL;
2807 goto error_pvid;
2808 }
2809
Moshe Shemesh79aab092016-09-22 12:11:15 +03002810 if (vlan_proto != htons(ETH_P_8021Q)) {
2811 dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
2812 ret = -EPROTONOSUPPORT;
2813 goto error_pvid;
2814 }
2815
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002816 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002817 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002818 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002819 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2820 vf_id);
2821 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002822 goto error_pvid;
2823 }
2824
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002825 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
Mitch Williams85927ec2015-04-27 14:57:10 -04002826 /* duplicate request, so just return success */
2827 goto error_pvid;
2828
Kiran Patil21659032015-09-30 14:09:03 -04002829 spin_lock_bh(&vsi->mac_filter_list_lock);
2830 is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
2831 spin_unlock_bh(&vsi->mac_filter_list_lock);
2832
2833 if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
Greg Rose99a49732014-01-13 16:13:03 -08002834 dev_err(&pf->pdev->dev,
2835 "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",
2836 vf_id);
Greg Rosef9b4b622014-03-06 09:02:28 +00002837 /* Administrator Error - knock the VF offline until he does
2838 * the right thing by reconfiguring his network correctly
2839 * and then reloading the VF driver.
2840 */
2841 i40e_vc_disable_vf(pf, vf);
Mitch Williams35f34722016-02-17 16:12:23 -08002842 /* During reset the VF got a new VSI, so refresh the pointer. */
2843 vsi = pf->vsi[vf->lan_vsi_idx];
Greg Rosef9b4b622014-03-06 09:02:28 +00002844 }
Greg Rose99a49732014-01-13 16:13:03 -08002845
Greg Rose8d82a7c2014-01-13 16:13:04 -08002846 /* Check for condition where there was already a port VLAN ID
2847 * filter set and now it is being deleted by setting it to zero.
Greg Rose1315f7c2014-03-14 07:32:20 +00002848 * Additionally check for the condition where there was a port
2849 * VLAN but now there is a new and different port VLAN being set.
Greg Rose8d82a7c2014-01-13 16:13:04 -08002850 * Before deleting all the old VLAN filters we must add new ones
2851 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2852 * MAC addresses deleted.
2853 */
Greg Rose1315f7c2014-03-14 07:32:20 +00002854 if ((!(vlan_id || qos) ||
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002855 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
Greg Rose1315f7c2014-03-14 07:32:20 +00002856 vsi->info.pvid)
Greg Rose8d82a7c2014-01-13 16:13:04 -08002857 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2858
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002859 if (vsi->info.pvid) {
2860 /* kill old VLAN */
2861 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2862 VLAN_VID_MASK));
2863 if (ret) {
2864 dev_info(&vsi->back->pdev->dev,
2865 "remove VLAN failed, ret=%d, aq_err=%d\n",
2866 ret, pf->hw.aq.asq_last_status);
2867 }
2868 }
2869 if (vlan_id || qos)
Mitch Williamsf7fc2f22015-07-23 16:54:36 -04002870 ret = i40e_vsi_add_pvid(vsi, vlanprio);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002871 else
Greg Rose6c12fcb2013-11-28 06:39:34 +00002872 i40e_vsi_remove_pvid(vsi);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002873
2874 if (vlan_id) {
2875 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2876 vlan_id, qos, vf_id);
2877
2878 /* add new VLAN filter */
2879 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2880 if (ret) {
2881 dev_info(&vsi->back->pdev->dev,
2882 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2883 vsi->back->hw.aq.asq_last_status);
2884 goto error_pvid;
2885 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002886 /* Kill non-vlan MAC filters - ignore error return since
2887 * there might not be any non-vlan MAC filters.
2888 */
2889 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002890 }
2891
2892 if (ret) {
2893 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2894 goto error_pvid;
2895 }
Greg Rose6c12fcb2013-11-28 06:39:34 +00002896 /* The Port VLAN needs to be saved across resets the same as the
2897 * default LAN MAC address.
2898 */
2899 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002900 ret = 0;
2901
2902error_pvid:
2903 return ret;
2904}
2905
Mitch Williams84590fd2014-04-09 05:58:57 +00002906#define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2907#define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002908/**
2909 * i40e_ndo_set_vf_bw
2910 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002911 * @vf_id: VF identifier
2912 * @tx_rate: Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002913 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002914 * configure VF Tx rate
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002915 **/
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002916int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2917 int max_tx_rate)
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002918{
Mitch Williams6b192892014-03-06 09:02:29 +00002919 struct i40e_netdev_priv *np = netdev_priv(netdev);
2920 struct i40e_pf *pf = np->vsi->back;
2921 struct i40e_vsi *vsi;
2922 struct i40e_vf *vf;
2923 int speed = 0;
2924 int ret = 0;
2925
2926 /* validate the request */
2927 if (vf_id >= pf->num_alloc_vfs) {
2928 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2929 ret = -EINVAL;
2930 goto error;
2931 }
2932
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002933 if (min_tx_rate) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002934 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 -04002935 min_tx_rate, vf_id);
2936 return -EINVAL;
2937 }
2938
Mitch Williams6b192892014-03-06 09:02:29 +00002939 vf = &(pf->vf[vf_id]);
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07002940 vsi = pf->vsi[vf->lan_vsi_idx];
Mitch Williams6b192892014-03-06 09:02:29 +00002941 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08002942 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2943 vf_id);
2944 ret = -EAGAIN;
Mitch Williams6b192892014-03-06 09:02:29 +00002945 goto error;
2946 }
2947
2948 switch (pf->hw.phy.link_info.link_speed) {
2949 case I40E_LINK_SPEED_40GB:
2950 speed = 40000;
2951 break;
Mitch Williams07f169c2015-12-23 12:05:49 -08002952 case I40E_LINK_SPEED_20GB:
2953 speed = 20000;
2954 break;
Mitch Williams6b192892014-03-06 09:02:29 +00002955 case I40E_LINK_SPEED_10GB:
2956 speed = 10000;
2957 break;
2958 case I40E_LINK_SPEED_1GB:
2959 speed = 1000;
2960 break;
2961 default:
2962 break;
2963 }
2964
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002965 if (max_tx_rate > speed) {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002966 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002967 max_tx_rate, vf->vf_id);
Mitch Williams6b192892014-03-06 09:02:29 +00002968 ret = -EINVAL;
2969 goto error;
2970 }
2971
Mitch Williamsdac9b312014-04-09 05:58:56 +00002972 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2973 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2974 max_tx_rate = 50;
2975 }
2976
Mitch Williams6b192892014-03-06 09:02:29 +00002977 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
Mitch Williams84590fd2014-04-09 05:58:57 +00002978 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2979 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2980 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
Mitch Williams6b192892014-03-06 09:02:29 +00002981 if (ret) {
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002982 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
Mitch Williams6b192892014-03-06 09:02:29 +00002983 ret);
2984 ret = -EIO;
2985 goto error;
2986 }
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04002987 vf->tx_rate = max_tx_rate;
Mitch Williams6b192892014-03-06 09:02:29 +00002988error:
2989 return ret;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002990}
2991
2992/**
2993 * i40e_ndo_get_vf_config
2994 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002995 * @vf_id: VF identifier
2996 * @ivi: VF configuration structure
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002997 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002998 * return VF configuration
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00002999 **/
3000int i40e_ndo_get_vf_config(struct net_device *netdev,
3001 int vf_id, struct ifla_vf_info *ivi)
3002{
3003 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003004 struct i40e_vsi *vsi = np->vsi;
3005 struct i40e_pf *pf = vsi->back;
3006 struct i40e_vf *vf;
3007 int ret = 0;
3008
3009 /* validate the request */
3010 if (vf_id >= pf->num_alloc_vfs) {
3011 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3012 ret = -EINVAL;
3013 goto error_param;
3014 }
3015
3016 vf = &(pf->vf[vf_id]);
3017 /* first vsi is always the LAN vsi */
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07003018 vsi = pf->vsi[vf->lan_vsi_idx];
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003019 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
Mitch Williams2d166c32015-12-22 15:34:42 -08003020 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3021 vf_id);
3022 ret = -EAGAIN;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003023 goto error_param;
3024 }
3025
3026 ivi->vf = vf_id;
3027
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003028 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003029
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04003030 ivi->max_tx_rate = vf->tx_rate;
3031 ivi->min_tx_rate = 0;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003032 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
3033 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
3034 I40E_VLAN_PRIORITY_SHIFT;
Mitch Williams84ca55a2014-03-14 07:32:24 +00003035 if (vf->link_forced == false)
3036 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
3037 else if (vf->link_up == true)
3038 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
3039 else
3040 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
Mitch Williamsc674d122014-05-20 08:01:40 +00003041 ivi->spoofchk = vf->spoofchk;
Sridhar Samudralad40062f2016-08-04 18:45:47 +02003042 ivi->trusted = vf->trusted;
Jesse Brandeburg5c3c48a2013-09-11 08:40:07 +00003043 ret = 0;
3044
3045error_param:
3046 return ret;
3047}
Mitch Williams588aefa2014-02-11 08:27:49 +00003048
3049/**
3050 * i40e_ndo_set_vf_link_state
3051 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00003052 * @vf_id: VF identifier
Mitch Williams588aefa2014-02-11 08:27:49 +00003053 * @link: required link state
3054 *
3055 * Set the link state of a specified VF, regardless of physical link state
3056 **/
3057int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
3058{
3059 struct i40e_netdev_priv *np = netdev_priv(netdev);
3060 struct i40e_pf *pf = np->vsi->back;
3061 struct i40e_virtchnl_pf_event pfe;
3062 struct i40e_hw *hw = &pf->hw;
3063 struct i40e_vf *vf;
Ashish Shahf19efbb2014-08-01 13:27:06 -07003064 int abs_vf_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00003065 int ret = 0;
3066
3067 /* validate the request */
3068 if (vf_id >= pf->num_alloc_vfs) {
3069 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3070 ret = -EINVAL;
3071 goto error_out;
3072 }
3073
3074 vf = &pf->vf[vf_id];
Ashish Shahf19efbb2014-08-01 13:27:06 -07003075 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
Mitch Williams588aefa2014-02-11 08:27:49 +00003076
3077 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
3078 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
3079
3080 switch (link) {
3081 case IFLA_VF_LINK_STATE_AUTO:
3082 vf->link_forced = false;
3083 pfe.event_data.link_event.link_status =
3084 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
3085 pfe.event_data.link_event.link_speed =
3086 pf->hw.phy.link_info.link_speed;
3087 break;
3088 case IFLA_VF_LINK_STATE_ENABLE:
3089 vf->link_forced = true;
3090 vf->link_up = true;
3091 pfe.event_data.link_event.link_status = true;
3092 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
3093 break;
3094 case IFLA_VF_LINK_STATE_DISABLE:
3095 vf->link_forced = true;
3096 vf->link_up = false;
3097 pfe.event_data.link_event.link_status = false;
3098 pfe.event_data.link_event.link_speed = 0;
3099 break;
3100 default:
3101 ret = -EINVAL;
3102 goto error_out;
3103 }
3104 /* Notify the VF of its new link state */
Ashish Shahf19efbb2014-08-01 13:27:06 -07003105 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
Mitch Williams588aefa2014-02-11 08:27:49 +00003106 0, (u8 *)&pfe, sizeof(pfe), NULL);
3107
3108error_out:
3109 return ret;
3110}
Mitch Williamsc674d122014-05-20 08:01:40 +00003111
3112/**
3113 * i40e_ndo_set_vf_spoofchk
3114 * @netdev: network interface device structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00003115 * @vf_id: VF identifier
Mitch Williamsc674d122014-05-20 08:01:40 +00003116 * @enable: flag to enable or disable feature
3117 *
3118 * Enable or disable VF spoof checking
3119 **/
Serey Konge6d90042014-07-12 07:28:14 +00003120int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
Mitch Williamsc674d122014-05-20 08:01:40 +00003121{
3122 struct i40e_netdev_priv *np = netdev_priv(netdev);
3123 struct i40e_vsi *vsi = np->vsi;
3124 struct i40e_pf *pf = vsi->back;
3125 struct i40e_vsi_context ctxt;
3126 struct i40e_hw *hw = &pf->hw;
3127 struct i40e_vf *vf;
3128 int ret = 0;
3129
3130 /* validate the request */
3131 if (vf_id >= pf->num_alloc_vfs) {
3132 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3133 ret = -EINVAL;
3134 goto out;
3135 }
3136
3137 vf = &(pf->vf[vf_id]);
Mitch Williams2d166c32015-12-22 15:34:42 -08003138 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
3139 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3140 vf_id);
3141 ret = -EAGAIN;
3142 goto out;
3143 }
Mitch Williamsc674d122014-05-20 08:01:40 +00003144
3145 if (enable == vf->spoofchk)
3146 goto out;
3147
3148 vf->spoofchk = enable;
3149 memset(&ctxt, 0, sizeof(ctxt));
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -07003150 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
Mitch Williamsc674d122014-05-20 08:01:40 +00003151 ctxt.pf_num = pf->hw.pf_id;
3152 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
3153 if (enable)
Greg Rose30d71af2015-01-29 07:17:17 +00003154 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
3155 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
Mitch Williamsc674d122014-05-20 08:01:40 +00003156 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3157 if (ret) {
3158 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
3159 ret);
3160 ret = -EIO;
3161 }
3162out:
3163 return ret;
3164}
Anjali Singhai Jainc3bbbd22016-04-01 03:56:07 -07003165
3166/**
3167 * i40e_ndo_set_vf_trust
3168 * @netdev: network interface device structure of the pf
3169 * @vf_id: VF identifier
3170 * @setting: trust setting
3171 *
3172 * Enable or disable VF trust setting
3173 **/
3174int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
3175{
3176 struct i40e_netdev_priv *np = netdev_priv(netdev);
3177 struct i40e_pf *pf = np->vsi->back;
3178 struct i40e_vf *vf;
3179 int ret = 0;
3180
3181 /* validate the request */
3182 if (vf_id >= pf->num_alloc_vfs) {
3183 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3184 return -EINVAL;
3185 }
3186
3187 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3188 dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
3189 return -EINVAL;
3190 }
3191
3192 vf = &pf->vf[vf_id];
3193
3194 if (!vf)
3195 return -EINVAL;
3196 if (setting == vf->trusted)
3197 goto out;
3198
3199 vf->trusted = setting;
3200 i40e_vc_notify_vf_reset(vf);
3201 i40e_reset_vf(vf, false);
3202 dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
3203 vf_id, setting ? "" : "un");
3204out:
3205 return ret;
3206}