1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
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.
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
15 * 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/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
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
25 ******************************************************************************/
29 /*********************notification routines***********************/
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
39 * send a message to all VFs on a given PF
41 static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
42 enum i40e_virtchnl_ops v_opcode,
43 i40e_status v_retval, u8 *msg,
46 struct i40e_hw *hw = &pf->hw;
47 struct i40e_vf *vf = pf->vf;
50 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
51 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
54 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
60 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
66 * i40e_vc_notify_vf_link_state
67 * @vf: pointer to the VF structure
69 * send a link status message to a single VF
71 static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
73 struct i40e_virtchnl_pf_event pfe;
74 struct i40e_pf *pf = vf->pf;
75 struct i40e_hw *hw = &pf->hw;
76 struct i40e_link_status *ls = &pf->hw.phy.link_info;
77 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
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);
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;
90 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
91 0, (u8 *)&pfe, sizeof(pfe), NULL);
95 * i40e_vc_notify_link_state
96 * @pf: pointer to the PF structure
98 * send a link status message to all VFs on a given PF
100 void i40e_vc_notify_link_state(struct i40e_pf *pf)
104 for (i = 0; i < pf->num_alloc_vfs; i++)
105 i40e_vc_notify_vf_link_state(&pf->vf[i]);
109 * i40e_vc_notify_reset
110 * @pf: pointer to the PF structure
112 * indicate a pending reset to all VFs on a given PF
114 void i40e_vc_notify_reset(struct i40e_pf *pf)
116 struct i40e_virtchnl_pf_event pfe;
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));
125 * i40e_vc_notify_vf_reset
126 * @vf: pointer to the VF structure
128 * indicate a pending reset to the given VF
130 void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
132 struct i40e_virtchnl_pf_event pfe;
135 /* validate the request */
136 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
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))
144 abs_vf_id = vf->vf_id + (int)vf->pf->hw.func_caps.vf_base_id;
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,
150 sizeof(struct i40e_virtchnl_pf_event), NULL);
152 /***********************misc routines*****************************/
156 * @pf: pointer to the PF info
157 * @vf: pointer to the VF info
159 * Disable the VF through a SW reset
161 static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
163 i40e_vc_notify_vf_reset(vf);
164 i40e_reset_vf(vf, false);
168 * i40e_vc_isvalid_vsi_id
169 * @vf: pointer to the VF info
170 * @vsi_id: VF relative VSI id
172 * check for the valid VSI id
174 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
176 struct i40e_pf *pf = vf->pf;
177 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
179 return (vsi && (vsi->vf_id == vf->vf_id));
183 * i40e_vc_isvalid_queue_id
184 * @vf: pointer to the VF info
186 * @qid: vsi relative queue id
188 * check for the valid queue id
190 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
193 struct i40e_pf *pf = vf->pf;
194 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
196 return (vsi && (qid < vsi->alloc_queue_pairs));
200 * i40e_vc_isvalid_vector_id
201 * @vf: pointer to the VF info
202 * @vector_id: VF relative vector id
204 * check for the valid vector id
206 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u32 vector_id)
208 struct i40e_pf *pf = vf->pf;
210 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
213 /***********************vf resource mgmt routines*****************/
216 * i40e_vc_get_pf_queue_id
217 * @vf: pointer to the VF info
218 * @vsi_id: id of VSI as provided by the FW
219 * @vsi_queue_id: vsi relative queue id
221 * return PF relative queue id
223 static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
226 struct i40e_pf *pf = vf->pf;
227 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
228 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
233 if (le16_to_cpu(vsi->info.mapping_flags) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
236 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
238 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
245 * i40e_config_irq_link_list
246 * @vf: pointer to the VF info
247 * @vsi_id: id of VSI as given by the FW
248 * @vecmap: irq map info
250 * configure irq link list from the map
252 static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
253 struct i40e_virtchnl_vector_map *vecmap)
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;
264 vector_id = vecmap->vector_id;
267 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
269 reg_idx = I40E_VPINT_LNKLSTN(
270 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
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);
278 tempmap = vecmap->rxq_map;
279 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
280 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
284 tempmap = vecmap->txq_map;
285 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
286 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
290 next_q = find_first_bit(&linklistmap,
292 I40E_VIRTCHNL_SUPPORTED_QTYPES));
293 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
294 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
295 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
296 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
298 wr32(hw, reg_idx, reg);
300 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
302 case I40E_QUEUE_TYPE_RX:
303 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
304 itr_idx = vecmap->rxitr_idx;
306 case I40E_QUEUE_TYPE_TX:
307 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
308 itr_idx = vecmap->txitr_idx;
314 next_q = find_next_bit(&linklistmap,
316 I40E_VIRTCHNL_SUPPORTED_QTYPES),
319 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
322 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
325 pf_queue_id = I40E_QUEUE_END_OF_LIST;
329 /* format for the RQCTL & TQCTL regs is same */
331 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
332 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
334 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
335 wr32(hw, reg_idx, reg);
338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
341 if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
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);
355 * i40e_release_iwarp_qvlist
356 * @vf: pointer to the VF.
359 static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
361 struct i40e_pf *pf = vf->pf;
362 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
366 if (!vf->qvlist_info)
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;
376 qv_info = &qvlist_info->qv_info[i];
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
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;
391 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
392 reg = (next_q_index &
393 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
395 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
397 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
400 kfree(vf->qvlist_info);
401 vf->qvlist_info = NULL;
405 * i40e_config_iwarp_qvlist
406 * @vf: pointer to the VF info
407 * @qvlist_info: queue and vector list
409 * Return 0 on success or < 0 on error
411 static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
412 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info)
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;
422 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
424 if (qvlist_info->num_vectors > msix_vf) {
425 dev_warn(&pf->pdev->dev,
426 "Incorrect number of iwarp vectors %u. Maximum %u allowed.\n",
427 qvlist_info->num_vectors,
433 size = sizeof(struct i40e_virtchnl_iwarp_qvlist_info) +
434 (sizeof(struct i40e_virtchnl_iwarp_qv_info) *
435 (qvlist_info->num_vectors - 1));
436 kfree(vf->qvlist_info);
437 vf->qvlist_info = kzalloc(size, GFP_KERNEL);
438 if (!vf->qvlist_info) {
442 vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
444 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
445 for (i = 0; i < qvlist_info->num_vectors; i++) {
446 qv_info = &qvlist_info->qv_info[i];
449 v_idx = qv_info->v_idx;
451 /* Validate vector id belongs to this vf */
452 if (!i40e_vc_isvalid_vector_id(vf, v_idx)) {
457 vf->qvlist_info->qv_info[i] = *qv_info;
459 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
460 /* We might be sharing the interrupt, so get the first queue
461 * index and type, push it down the list by adding the new
462 * queue on top. Also link it with the new queue in CEQCTL.
464 reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
465 next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
466 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
467 next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
468 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
470 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
471 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
472 reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
473 (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
474 (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
475 (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
476 (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
477 wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
479 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
480 reg = (qv_info->ceq_idx &
481 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
482 (I40E_QUEUE_TYPE_PE_CEQ <<
483 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
484 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
487 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
488 reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
489 (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
490 (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
492 wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
498 kfree(vf->qvlist_info);
499 vf->qvlist_info = NULL;
505 * i40e_config_vsi_tx_queue
506 * @vf: pointer to the VF info
507 * @vsi_id: id of VSI as provided by the FW
508 * @vsi_queue_id: vsi relative queue index
509 * @info: config. info
513 static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
515 struct i40e_virtchnl_txq_info *info)
517 struct i40e_pf *pf = vf->pf;
518 struct i40e_hw *hw = &pf->hw;
519 struct i40e_hmc_obj_txq tx_ctx;
520 struct i40e_vsi *vsi;
525 if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
529 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
530 vsi = i40e_find_vsi_from_id(pf, vsi_id);
536 /* clear the context structure first */
537 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
539 /* only set the required fields */
540 tx_ctx.base = info->dma_ring_addr / 128;
541 tx_ctx.qlen = info->ring_len;
542 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
543 tx_ctx.rdylist_act = 0;
544 tx_ctx.head_wb_ena = info->headwb_enabled;
545 tx_ctx.head_wb_addr = info->dma_headwb_addr;
547 /* clear the context in the HMC */
548 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
550 dev_err(&pf->pdev->dev,
551 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
557 /* set the context in the HMC */
558 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
560 dev_err(&pf->pdev->dev,
561 "Failed to set VF LAN Tx queue context %d error: %d\n",
567 /* associate this queue with the PCI VF function */
568 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
569 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
570 & I40E_QTX_CTL_PF_INDX_MASK);
571 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
572 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
573 & I40E_QTX_CTL_VFVM_INDX_MASK);
574 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
582 * i40e_config_vsi_rx_queue
583 * @vf: pointer to the VF info
584 * @vsi_id: id of VSI as provided by the FW
585 * @vsi_queue_id: vsi relative queue index
586 * @info: config. info
590 static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
592 struct i40e_virtchnl_rxq_info *info)
594 struct i40e_pf *pf = vf->pf;
595 struct i40e_hw *hw = &pf->hw;
596 struct i40e_hmc_obj_rxq rx_ctx;
600 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
602 /* clear the context structure first */
603 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
605 /* only set the required fields */
606 rx_ctx.base = info->dma_ring_addr / 128;
607 rx_ctx.qlen = info->ring_len;
609 if (info->splithdr_enabled) {
610 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
612 I40E_RX_SPLIT_TCP_UDP |
614 /* header length validation */
615 if (info->hdr_size > ((2 * 1024) - 64)) {
619 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
621 /* set split mode 10b */
622 rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
625 /* databuffer length validation */
626 if (info->databuffer_size > ((16 * 1024) - 128)) {
630 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
632 /* max pkt. length validation */
633 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
637 rx_ctx.rxmax = info->max_pkt_size;
639 /* enable 32bytes desc always */
643 rx_ctx.lrxqthresh = 2;
648 /* clear the context in the HMC */
649 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
651 dev_err(&pf->pdev->dev,
652 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
658 /* set the context in the HMC */
659 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
661 dev_err(&pf->pdev->dev,
662 "Failed to set VF LAN Rx queue context %d error: %d\n",
674 * @vf: pointer to the VF info
675 * @type: type of VSI to allocate
677 * alloc VF vsi context & resources
679 static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
681 struct i40e_mac_filter *f = NULL;
682 struct i40e_pf *pf = vf->pf;
683 struct i40e_vsi *vsi;
686 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
689 dev_err(&pf->pdev->dev,
690 "add vsi failed for VF %d, aq_err %d\n",
691 vf->vf_id, pf->hw.aq.asq_last_status);
693 goto error_alloc_vsi_res;
695 if (type == I40E_VSI_SRIOV) {
696 u64 hena = i40e_pf_get_default_rss_hena(pf);
698 vf->lan_vsi_idx = vsi->idx;
699 vf->lan_vsi_id = vsi->id;
700 /* If the port VLAN has been configured and then the
701 * VF driver was removed then the VSI port VLAN
702 * configuration was destroyed. Check if there is
703 * a port VLAN and restore the VSI configuration if
706 if (vf->port_vlan_id)
707 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
709 spin_lock_bh(&vsi->mac_filter_list_lock);
710 if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
711 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
712 vf->port_vlan_id ? vf->port_vlan_id : -1,
715 dev_info(&pf->pdev->dev,
716 "Could not add MAC filter %pM for VF %d\n",
717 vf->default_lan_addr.addr, vf->vf_id);
719 spin_unlock_bh(&vsi->mac_filter_list_lock);
720 i40e_write_rx_ctl(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id),
722 i40e_write_rx_ctl(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id),
726 /* program mac filter */
727 ret = i40e_sync_vsi_filters(vsi);
729 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
731 /* Set VF bandwidth if specified */
733 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
734 vf->tx_rate / 50, 0, NULL);
736 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
745 * i40e_enable_vf_mappings
746 * @vf: pointer to the VF info
750 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
752 struct i40e_pf *pf = vf->pf;
753 struct i40e_hw *hw = &pf->hw;
754 u32 reg, total_queue_pairs = 0;
757 /* Tell the hardware we're using noncontiguous mapping. HW requires
758 * that VF queues be mapped using this method, even when they are
759 * contiguous in real life
761 i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
762 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
764 /* enable VF vplan_qtable mappings */
765 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
766 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
768 /* map PF queues to VF queues */
769 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
770 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
772 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
773 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
777 /* map PF queues to VSI */
778 for (j = 0; j < 7; j++) {
779 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
780 reg = 0x07FF07FF; /* unused */
782 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
785 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
789 i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id),
797 * i40e_disable_vf_mappings
798 * @vf: pointer to the VF info
800 * disable VF mappings
802 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
804 struct i40e_pf *pf = vf->pf;
805 struct i40e_hw *hw = &pf->hw;
808 /* disable qp mappings */
809 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
810 for (i = 0; i < I40E_MAX_VSI_QP; i++)
811 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
812 I40E_QUEUE_END_OF_LIST);
818 * @vf: pointer to the VF info
822 static void i40e_free_vf_res(struct i40e_vf *vf)
824 struct i40e_pf *pf = vf->pf;
825 struct i40e_hw *hw = &pf->hw;
829 /* free vsi & disconnect it from the parent uplink */
830 if (vf->lan_vsi_idx) {
831 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
835 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
837 /* disable interrupts so the VF starts in a known state */
838 for (i = 0; i < msix_vf; i++) {
839 /* format is same for both registers */
841 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
843 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
846 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
850 /* clear the irq settings */
851 for (i = 0; i < msix_vf; i++) {
852 /* format is same for both registers */
854 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
856 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
859 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
860 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
861 wr32(hw, reg_idx, reg);
864 /* reset some of the state varibles keeping
865 * track of the resources
867 vf->num_queue_pairs = 0;
869 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
874 * @vf: pointer to the VF info
876 * allocate VF resources
878 static int i40e_alloc_vf_res(struct i40e_vf *vf)
880 struct i40e_pf *pf = vf->pf;
881 int total_queue_pairs = 0;
884 /* allocate hw vsi context & associated resources */
885 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
888 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
891 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
893 clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
895 /* store the total qps number for the runtime
898 vf->num_queue_pairs = total_queue_pairs;
900 /* VF is now completely initialized */
901 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
905 i40e_free_vf_res(vf);
910 #define VF_DEVICE_STATUS 0xAA
911 #define VF_TRANS_PENDING_MASK 0x20
913 * i40e_quiesce_vf_pci
914 * @vf: pointer to the VF structure
916 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
917 * if the transactions never clear.
919 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
921 struct i40e_pf *pf = vf->pf;
922 struct i40e_hw *hw = &pf->hw;
926 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
928 wr32(hw, I40E_PF_PCI_CIAA,
929 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
930 for (i = 0; i < 100; i++) {
931 reg = rd32(hw, I40E_PF_PCI_CIAD);
932 if ((reg & VF_TRANS_PENDING_MASK) == 0)
941 * @vf: pointer to the VF structure
942 * @flr: VFLR was issued or not
946 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
948 struct i40e_pf *pf = vf->pf;
949 struct i40e_hw *hw = &pf->hw;
950 u32 reg, reg_idx, bit_idx;
954 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
958 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
960 /* In the case of a VFLR, the HW has already reset the VF and we
961 * just need to clean up, so don't hit the VFRTRIG register.
964 /* reset VF using VPGEN_VFRTRIG reg */
965 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
966 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
967 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
970 /* clear the VFLR bit in GLGEN_VFLRSTAT */
971 reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
972 bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
973 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
976 if (i40e_quiesce_vf_pci(vf))
977 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
980 /* poll VPGEN_VFRSTAT reg to make sure
981 * that reset is complete
983 for (i = 0; i < 10; i++) {
984 /* VF reset requires driver to first reset the VF and then
985 * poll the status register to make sure that the reset
986 * completed successfully. Due to internal HW FIFO flushes,
987 * we must wait 10ms before the register will be valid.
989 usleep_range(10000, 20000);
990 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
991 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
998 usleep_range(10000, 20000);
1001 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
1003 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
1004 /* clear the reset bit in the VPGEN_VFRTRIG reg */
1005 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
1006 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
1007 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
1009 /* On initial reset, we won't have any queues */
1010 if (vf->lan_vsi_idx == 0)
1011 goto complete_reset;
1013 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
1015 /* reallocate VF resources to reset the VSI state */
1016 i40e_free_vf_res(vf);
1017 if (!i40e_alloc_vf_res(vf)) {
1018 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1019 i40e_enable_vf_mappings(vf);
1020 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1021 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1022 /* Do not notify the client during VF init */
1023 if (vf->pf->num_alloc_vfs)
1024 i40e_notify_client_of_vf_reset(pf, abs_vf_id);
1027 /* tell the VF the reset is done */
1028 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
1031 clear_bit(__I40E_VF_DISABLE, &pf->state);
1036 * @pf: pointer to the PF structure
1040 void i40e_free_vfs(struct i40e_pf *pf)
1042 struct i40e_hw *hw = &pf->hw;
1043 u32 reg_idx, bit_idx;
1048 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
1049 usleep_range(1000, 2000);
1051 i40e_notify_client_of_vf_enable(pf, 0);
1052 for (i = 0; i < pf->num_alloc_vfs; i++)
1053 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
1054 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
1057 /* Disable IOV before freeing resources. This lets any VF drivers
1058 * running in the host get themselves cleaned up before we yank
1059 * the carpet out from underneath their feet.
1061 if (!pci_vfs_assigned(pf->pdev))
1062 pci_disable_sriov(pf->pdev);
1064 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
1066 msleep(20); /* let any messages in transit get finished up */
1068 /* free up VF resources */
1069 tmp = pf->num_alloc_vfs;
1070 pf->num_alloc_vfs = 0;
1071 for (i = 0; i < tmp; i++) {
1072 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
1073 i40e_free_vf_res(&pf->vf[i]);
1074 /* disable qp mappings */
1075 i40e_disable_vf_mappings(&pf->vf[i]);
1081 /* This check is for when the driver is unloaded while VFs are
1082 * assigned. Setting the number of VFs to 0 through sysfs is caught
1083 * before this function ever gets called.
1085 if (!pci_vfs_assigned(pf->pdev)) {
1086 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
1087 * work correctly when SR-IOV gets re-enabled.
1089 for (vf_id = 0; vf_id < tmp; vf_id++) {
1090 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1091 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1092 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
1095 clear_bit(__I40E_VF_DISABLE, &pf->state);
1098 #ifdef CONFIG_PCI_IOV
1101 * @pf: pointer to the PF structure
1102 * @num_alloc_vfs: number of VFs to allocate
1104 * allocate VF resources
1106 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
1108 struct i40e_vf *vfs;
1111 /* Disable interrupt 0 so we don't try to handle the VFLR. */
1112 i40e_irq_dynamic_disable_icr0(pf);
1114 /* Check to see if we're just allocating resources for extant VFs */
1115 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
1116 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
1118 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1119 pf->num_alloc_vfs = 0;
1123 /* allocate memory */
1124 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
1131 /* apply default profile */
1132 for (i = 0; i < num_alloc_vfs; i++) {
1134 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
1137 /* assign default capabilities */
1138 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
1139 vfs[i].spoofchk = true;
1140 /* VF resources get allocated during reset */
1141 i40e_reset_vf(&vfs[i], false);
1144 pf->num_alloc_vfs = num_alloc_vfs;
1146 i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
1152 /* Re-enable interrupt 0. */
1153 i40e_irq_dynamic_enable_icr0(pf, false);
1159 * i40e_pci_sriov_enable
1160 * @pdev: pointer to a pci_dev structure
1161 * @num_vfs: number of VFs to allocate
1163 * Enable or change the number of VFs
1165 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
1167 #ifdef CONFIG_PCI_IOV
1168 struct i40e_pf *pf = pci_get_drvdata(pdev);
1169 int pre_existing_vfs = pci_num_vf(pdev);
1172 if (test_bit(__I40E_TESTING, &pf->state)) {
1173 dev_warn(&pdev->dev,
1174 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1179 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1181 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1184 if (num_vfs > pf->num_req_vfs) {
1185 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1186 num_vfs, pf->num_req_vfs);
1191 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
1192 err = i40e_alloc_vfs(pf, num_vfs);
1194 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1208 * i40e_pci_sriov_configure
1209 * @pdev: pointer to a pci_dev structure
1210 * @num_vfs: number of VFs to allocate
1212 * Enable or change the number of VFs. Called when the user updates the number
1215 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1217 struct i40e_pf *pf = pci_get_drvdata(pdev);
1220 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1221 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1222 i40e_do_reset_safe(pf,
1223 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1225 return i40e_pci_sriov_enable(pdev, num_vfs);
1228 if (!pci_vfs_assigned(pf->pdev)) {
1230 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1231 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
1233 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1239 /***********************virtual channel routines******************/
1242 * i40e_vc_send_msg_to_vf
1243 * @vf: pointer to the VF info
1244 * @v_opcode: virtual channel opcode
1245 * @v_retval: virtual channel return value
1246 * @msg: pointer to the msg buffer
1247 * @msglen: msg length
1251 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1252 u32 v_retval, u8 *msg, u16 msglen)
1259 /* validate the request */
1260 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1265 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1267 /* single place to detect unsuccessful return values */
1269 vf->num_invalid_msgs++;
1270 dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
1271 vf->vf_id, v_opcode, v_retval);
1272 if (vf->num_invalid_msgs >
1273 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1274 dev_err(&pf->pdev->dev,
1275 "Number of invalid messages exceeded for VF %d\n",
1277 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1278 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1281 vf->num_valid_msgs++;
1282 /* reset the invalid counter, if a valid message is received. */
1283 vf->num_invalid_msgs = 0;
1286 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1289 dev_info(&pf->pdev->dev,
1290 "Unable to send the message to VF %d aq_err %d\n",
1291 vf->vf_id, pf->hw.aq.asq_last_status);
1299 * i40e_vc_send_resp_to_vf
1300 * @vf: pointer to the VF info
1301 * @opcode: operation code
1302 * @retval: return value
1304 * send resp msg to VF
1306 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1307 enum i40e_virtchnl_ops opcode,
1310 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1314 * i40e_vc_get_version_msg
1315 * @vf: pointer to the VF info
1317 * called from the VF to request the API version used by the PF
1319 static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
1321 struct i40e_virtchnl_version_info info = {
1322 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1325 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
1326 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1328 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
1329 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1330 I40E_SUCCESS, (u8 *)&info,
1332 i40e_virtchnl_version_info));
1336 * i40e_vc_get_vf_resources_msg
1337 * @vf: pointer to the VF info
1338 * @msg: pointer to the msg buffer
1339 * @msglen: msg length
1341 * called from the VF to request its resources
1343 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1345 struct i40e_virtchnl_vf_resource *vfres = NULL;
1346 struct i40e_pf *pf = vf->pf;
1347 i40e_status aq_ret = 0;
1348 struct i40e_vsi *vsi;
1353 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1354 aq_ret = I40E_ERR_PARAM;
1358 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1359 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1361 vfres = kzalloc(len, GFP_KERNEL);
1363 aq_ret = I40E_ERR_NO_MEMORY;
1368 vf->driver_caps = *(u32 *)msg;
1370 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1371 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1372 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1374 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1375 vsi = pf->vsi[vf->lan_vsi_idx];
1376 if (!vsi->info.pvid)
1377 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1379 if (i40e_vf_client_capable(pf, vf->vf_id, I40E_CLIENT_IWARP) &&
1380 (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_IWARP)) {
1381 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_IWARP;
1382 set_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states);
1385 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1386 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF;
1388 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
1389 (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ))
1390 vfres->vf_offload_flags |=
1391 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1393 vfres->vf_offload_flags |=
1394 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1397 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
1398 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1399 vfres->vf_offload_flags |=
1400 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
1403 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) {
1404 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
1405 dev_err(&pf->pdev->dev,
1406 "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
1408 ret = I40E_ERR_PARAM;
1411 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1414 if (pf->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) {
1415 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1416 vfres->vf_offload_flags |=
1417 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
1420 vfres->num_vsis = num_vsis;
1421 vfres->num_queue_pairs = vf->num_queue_pairs;
1422 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1423 vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
1424 vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
1426 if (vf->lan_vsi_idx) {
1427 vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
1428 vfres->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
1429 vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
1430 /* VFs only use TC 0 */
1431 vfres->vsi_res[0].qset_handle
1432 = le16_to_cpu(vsi->info.qs_handle[0]);
1433 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
1434 vf->default_lan_addr.addr);
1436 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1439 /* send the response back to the VF */
1440 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1441 aq_ret, (u8 *)vfres, len);
1448 * i40e_vc_reset_vf_msg
1449 * @vf: pointer to the VF info
1450 * @msg: pointer to the msg buffer
1451 * @msglen: msg length
1453 * called from the VF to reset itself,
1454 * unlike other virtchnl messages, PF driver
1455 * doesn't send the response back to the VF
1457 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1459 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1460 i40e_reset_vf(vf, false);
1464 * i40e_getnum_vf_vsi_vlan_filters
1465 * @vsi: pointer to the vsi
1467 * called to get the number of VLANs offloaded on this VF
1469 static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1471 struct i40e_mac_filter *f;
1474 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1475 if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
1483 * i40e_vc_config_promiscuous_mode_msg
1484 * @vf: pointer to the VF info
1485 * @msg: pointer to the msg buffer
1486 * @msglen: msg length
1488 * called from the VF to configure the promiscuous mode of
1491 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1492 u8 *msg, u16 msglen)
1494 struct i40e_virtchnl_promisc_info *info =
1495 (struct i40e_virtchnl_promisc_info *)msg;
1496 struct i40e_pf *pf = vf->pf;
1497 struct i40e_hw *hw = &pf->hw;
1498 struct i40e_mac_filter *f;
1499 i40e_status aq_ret = 0;
1500 bool allmulti = false;
1501 struct i40e_vsi *vsi;
1502 bool alluni = false;
1505 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1506 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1507 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1509 aq_ret = I40E_ERR_PARAM;
1512 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
1513 dev_err(&pf->pdev->dev,
1514 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1516 /* Lie to the VF on purpose. */
1520 /* Multicast promiscuous handling*/
1521 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1524 if (vf->port_vlan_id) {
1525 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
1529 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1530 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1531 if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1533 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
1538 aq_err = pf->hw.aq.asq_last_status;
1540 dev_err(&pf->pdev->dev,
1541 "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1543 i40e_stat_str(&pf->hw, aq_ret),
1544 i40e_aq_str(&pf->hw, aq_err));
1549 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1551 aq_err = pf->hw.aq.asq_last_status;
1553 dev_err(&pf->pdev->dev,
1554 "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1556 i40e_stat_str(&pf->hw, aq_ret),
1557 i40e_aq_str(&pf->hw, aq_err));
1558 goto error_param_int;
1563 dev_info(&pf->pdev->dev,
1564 "VF %d successfully set multicast promiscuous mode\n",
1567 set_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
1569 clear_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
1572 if (info->flags & I40E_FLAG_VF_UNICAST_PROMISC)
1574 if (vf->port_vlan_id) {
1575 aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
1579 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1580 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1582 if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID) {
1584 i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
1589 aq_err = pf->hw.aq.asq_last_status;
1592 dev_err(&pf->pdev->dev,
1593 "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1595 i40e_stat_str(&pf->hw, aq_ret),
1596 i40e_aq_str(&pf->hw, aq_err));
1599 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1602 aq_err = pf->hw.aq.asq_last_status;
1604 dev_err(&pf->pdev->dev,
1605 "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1606 vf->vf_id, info->flags,
1607 i40e_stat_str(&pf->hw, aq_ret),
1608 i40e_aq_str(&pf->hw, aq_err));
1613 dev_info(&pf->pdev->dev,
1614 "VF %d successfully set unicast promiscuous mode\n",
1617 set_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
1619 clear_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
1623 /* send the response to the VF */
1624 return i40e_vc_send_resp_to_vf(vf,
1625 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1630 * i40e_vc_config_queues_msg
1631 * @vf: pointer to the VF info
1632 * @msg: pointer to the msg buffer
1633 * @msglen: msg length
1635 * called from the VF to configure the rx/tx
1638 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1640 struct i40e_virtchnl_vsi_queue_config_info *qci =
1641 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1642 struct i40e_virtchnl_queue_pair_info *qpi;
1643 struct i40e_pf *pf = vf->pf;
1644 u16 vsi_id, vsi_queue_id;
1645 i40e_status aq_ret = 0;
1648 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1649 aq_ret = I40E_ERR_PARAM;
1653 vsi_id = qci->vsi_id;
1654 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1655 aq_ret = I40E_ERR_PARAM;
1658 for (i = 0; i < qci->num_queue_pairs; i++) {
1659 qpi = &qci->qpair[i];
1660 vsi_queue_id = qpi->txq.queue_id;
1661 if ((qpi->txq.vsi_id != vsi_id) ||
1662 (qpi->rxq.vsi_id != vsi_id) ||
1663 (qpi->rxq.queue_id != vsi_queue_id) ||
1664 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1665 aq_ret = I40E_ERR_PARAM;
1669 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1671 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1673 aq_ret = I40E_ERR_PARAM;
1677 /* set vsi num_queue_pairs in use to num configured by VF */
1678 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
1681 /* send the response to the VF */
1682 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1687 * i40e_vc_config_irq_map_msg
1688 * @vf: pointer to the VF info
1689 * @msg: pointer to the msg buffer
1690 * @msglen: msg length
1692 * called from the VF to configure the irq to
1695 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1697 struct i40e_virtchnl_irq_map_info *irqmap_info =
1698 (struct i40e_virtchnl_irq_map_info *)msg;
1699 struct i40e_virtchnl_vector_map *map;
1700 u16 vsi_id, vsi_queue_id, vector_id;
1701 i40e_status aq_ret = 0;
1702 unsigned long tempmap;
1705 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1706 aq_ret = I40E_ERR_PARAM;
1710 for (i = 0; i < irqmap_info->num_vectors; i++) {
1711 map = &irqmap_info->vecmap[i];
1713 vector_id = map->vector_id;
1714 vsi_id = map->vsi_id;
1715 /* validate msg params */
1716 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1717 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1718 aq_ret = I40E_ERR_PARAM;
1722 /* lookout for the invalid queue index */
1723 tempmap = map->rxq_map;
1724 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1725 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1727 aq_ret = I40E_ERR_PARAM;
1732 tempmap = map->txq_map;
1733 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1734 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1736 aq_ret = I40E_ERR_PARAM;
1741 i40e_config_irq_link_list(vf, vsi_id, map);
1744 /* send the response to the VF */
1745 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1750 * i40e_vc_enable_queues_msg
1751 * @vf: pointer to the VF info
1752 * @msg: pointer to the msg buffer
1753 * @msglen: msg length
1755 * called from the VF to enable all or specific queue(s)
1757 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1759 struct i40e_virtchnl_queue_select *vqs =
1760 (struct i40e_virtchnl_queue_select *)msg;
1761 struct i40e_pf *pf = vf->pf;
1762 u16 vsi_id = vqs->vsi_id;
1763 i40e_status aq_ret = 0;
1765 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1766 aq_ret = I40E_ERR_PARAM;
1770 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1771 aq_ret = I40E_ERR_PARAM;
1775 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1776 aq_ret = I40E_ERR_PARAM;
1780 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
1781 aq_ret = I40E_ERR_TIMEOUT;
1783 /* send the response to the VF */
1784 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1789 * i40e_vc_disable_queues_msg
1790 * @vf: pointer to the VF info
1791 * @msg: pointer to the msg buffer
1792 * @msglen: msg length
1794 * called from the VF to disable all or specific
1797 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1799 struct i40e_virtchnl_queue_select *vqs =
1800 (struct i40e_virtchnl_queue_select *)msg;
1801 struct i40e_pf *pf = vf->pf;
1802 i40e_status aq_ret = 0;
1804 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1805 aq_ret = I40E_ERR_PARAM;
1809 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1810 aq_ret = I40E_ERR_PARAM;
1814 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1815 aq_ret = I40E_ERR_PARAM;
1819 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
1820 aq_ret = I40E_ERR_TIMEOUT;
1823 /* send the response to the VF */
1824 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1829 * i40e_vc_get_stats_msg
1830 * @vf: pointer to the VF info
1831 * @msg: pointer to the msg buffer
1832 * @msglen: msg length
1834 * called from the VF to get vsi stats
1836 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1838 struct i40e_virtchnl_queue_select *vqs =
1839 (struct i40e_virtchnl_queue_select *)msg;
1840 struct i40e_pf *pf = vf->pf;
1841 struct i40e_eth_stats stats;
1842 i40e_status aq_ret = 0;
1843 struct i40e_vsi *vsi;
1845 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1847 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1848 aq_ret = I40E_ERR_PARAM;
1852 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1853 aq_ret = I40E_ERR_PARAM;
1857 vsi = pf->vsi[vf->lan_vsi_idx];
1859 aq_ret = I40E_ERR_PARAM;
1862 i40e_update_eth_stats(vsi);
1863 stats = vsi->eth_stats;
1866 /* send the response back to the VF */
1867 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1868 (u8 *)&stats, sizeof(stats));
1871 /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
1872 #define I40E_VC_MAX_MAC_ADDR_PER_VF 8
1873 #define I40E_VC_MAX_VLAN_PER_VF 8
1876 * i40e_check_vf_permission
1877 * @vf: pointer to the VF info
1878 * @macaddr: pointer to the MAC Address being checked
1880 * Check if the VF has permission to add or delete unicast MAC address
1881 * filters and return error code -EPERM if not. Then check if the
1882 * address filter requested is broadcast or zero and if so return
1883 * an invalid MAC address error code.
1885 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1887 struct i40e_pf *pf = vf->pf;
1890 if (is_broadcast_ether_addr(macaddr) ||
1891 is_zero_ether_addr(macaddr)) {
1892 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1893 ret = I40E_ERR_INVALID_MAC_ADDR;
1894 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1895 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
1896 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1897 /* If the host VMM administrator has set the VF MAC address
1898 * administratively via the ndo_set_vf_mac command then deny
1899 * permission to the VF to add or delete unicast MAC addresses.
1900 * Unless the VF is privileged and then it can do whatever.
1901 * The VF may request to set the MAC address filter already
1902 * assigned to it so do not return an error in that case.
1904 dev_err(&pf->pdev->dev,
1905 "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
1907 } else if ((vf->num_mac >= I40E_VC_MAX_MAC_ADDR_PER_VF) &&
1908 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
1909 dev_err(&pf->pdev->dev,
1910 "VF is not trusted, switch the VF to trusted to add more functionality\n");
1917 * i40e_vc_add_mac_addr_msg
1918 * @vf: pointer to the VF info
1919 * @msg: pointer to the msg buffer
1920 * @msglen: msg length
1922 * add guest mac address filter
1924 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1926 struct i40e_virtchnl_ether_addr_list *al =
1927 (struct i40e_virtchnl_ether_addr_list *)msg;
1928 struct i40e_pf *pf = vf->pf;
1929 struct i40e_vsi *vsi = NULL;
1930 u16 vsi_id = al->vsi_id;
1931 i40e_status ret = 0;
1934 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1935 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1936 ret = I40E_ERR_PARAM;
1940 for (i = 0; i < al->num_elements; i++) {
1941 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1945 vsi = pf->vsi[vf->lan_vsi_idx];
1947 /* Lock once, because all function inside for loop accesses VSI's
1948 * MAC filter list which needs to be protected using same lock.
1950 spin_lock_bh(&vsi->mac_filter_list_lock);
1952 /* add new addresses to the list */
1953 for (i = 0; i < al->num_elements; i++) {
1954 struct i40e_mac_filter *f;
1956 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1958 if (i40e_is_vsi_in_vlan(vsi))
1959 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1962 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1967 dev_err(&pf->pdev->dev,
1968 "Unable to add MAC filter %pM for VF %d\n",
1969 al->list[i].addr, vf->vf_id);
1970 ret = I40E_ERR_PARAM;
1971 spin_unlock_bh(&vsi->mac_filter_list_lock);
1977 spin_unlock_bh(&vsi->mac_filter_list_lock);
1979 /* program the updated filter list */
1980 ret = i40e_sync_vsi_filters(vsi);
1982 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
1986 /* send the response to the VF */
1987 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
1992 * i40e_vc_del_mac_addr_msg
1993 * @vf: pointer to the VF info
1994 * @msg: pointer to the msg buffer
1995 * @msglen: msg length
1997 * remove guest mac address filter
1999 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2001 struct i40e_virtchnl_ether_addr_list *al =
2002 (struct i40e_virtchnl_ether_addr_list *)msg;
2003 struct i40e_pf *pf = vf->pf;
2004 struct i40e_vsi *vsi = NULL;
2005 u16 vsi_id = al->vsi_id;
2006 i40e_status ret = 0;
2009 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2010 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2011 ret = I40E_ERR_PARAM;
2015 for (i = 0; i < al->num_elements; i++) {
2016 if (is_broadcast_ether_addr(al->list[i].addr) ||
2017 is_zero_ether_addr(al->list[i].addr)) {
2018 dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
2019 al->list[i].addr, vf->vf_id);
2020 ret = I40E_ERR_INVALID_MAC_ADDR;
2024 if (vf->pf_set_mac &&
2025 ether_addr_equal(al->list[i].addr,
2026 vf->default_lan_addr.addr)) {
2027 dev_err(&pf->pdev->dev,
2028 "MAC addr %pM has been set by PF, cannot delete it for VF %d, reset VF to change MAC addr\n",
2029 vf->default_lan_addr.addr, vf->vf_id);
2030 ret = I40E_ERR_PARAM;
2034 vsi = pf->vsi[vf->lan_vsi_idx];
2036 spin_lock_bh(&vsi->mac_filter_list_lock);
2037 /* delete addresses from the list */
2038 for (i = 0; i < al->num_elements; i++)
2039 if (i40e_del_mac_all_vlan(vsi, al->list[i].addr, true, false)) {
2040 ret = I40E_ERR_INVALID_MAC_ADDR;
2041 spin_unlock_bh(&vsi->mac_filter_list_lock);
2047 spin_unlock_bh(&vsi->mac_filter_list_lock);
2049 /* program the updated filter list */
2050 ret = i40e_sync_vsi_filters(vsi);
2052 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
2056 /* send the response to the VF */
2057 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
2062 * i40e_vc_add_vlan_msg
2063 * @vf: pointer to the VF info
2064 * @msg: pointer to the msg buffer
2065 * @msglen: msg length
2067 * program guest vlan id
2069 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2071 struct i40e_virtchnl_vlan_filter_list *vfl =
2072 (struct i40e_virtchnl_vlan_filter_list *)msg;
2073 struct i40e_pf *pf = vf->pf;
2074 struct i40e_vsi *vsi = NULL;
2075 u16 vsi_id = vfl->vsi_id;
2076 i40e_status aq_ret = 0;
2079 if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
2080 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2081 dev_err(&pf->pdev->dev,
2082 "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
2085 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2086 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2087 aq_ret = I40E_ERR_PARAM;
2091 for (i = 0; i < vfl->num_elements; i++) {
2092 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2093 aq_ret = I40E_ERR_PARAM;
2094 dev_err(&pf->pdev->dev,
2095 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
2099 vsi = pf->vsi[vf->lan_vsi_idx];
2100 if (vsi->info.pvid) {
2101 aq_ret = I40E_ERR_PARAM;
2105 i40e_vlan_stripping_enable(vsi);
2106 for (i = 0; i < vfl->num_elements; i++) {
2107 /* add new VLAN filter */
2108 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
2112 if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
2113 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2117 if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
2118 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2124 dev_err(&pf->pdev->dev,
2125 "Unable to add VLAN filter %d for VF %d, error %d\n",
2126 vfl->vlan_id[i], vf->vf_id, ret);
2130 /* send the response to the VF */
2131 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
2135 * i40e_vc_remove_vlan_msg
2136 * @vf: pointer to the VF info
2137 * @msg: pointer to the msg buffer
2138 * @msglen: msg length
2140 * remove programmed guest vlan id
2142 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2144 struct i40e_virtchnl_vlan_filter_list *vfl =
2145 (struct i40e_virtchnl_vlan_filter_list *)msg;
2146 struct i40e_pf *pf = vf->pf;
2147 struct i40e_vsi *vsi = NULL;
2148 u16 vsi_id = vfl->vsi_id;
2149 i40e_status aq_ret = 0;
2152 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2153 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2154 aq_ret = I40E_ERR_PARAM;
2158 for (i = 0; i < vfl->num_elements; i++) {
2159 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2160 aq_ret = I40E_ERR_PARAM;
2165 vsi = pf->vsi[vf->lan_vsi_idx];
2166 if (vsi->info.pvid) {
2167 aq_ret = I40E_ERR_PARAM;
2171 for (i = 0; i < vfl->num_elements; i++) {
2172 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
2176 if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
2177 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2181 if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
2182 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2188 dev_err(&pf->pdev->dev,
2189 "Unable to delete VLAN filter %d for VF %d, error %d\n",
2190 vfl->vlan_id[i], vf->vf_id, ret);
2194 /* send the response to the VF */
2195 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
2200 * @vf: pointer to the VF info
2201 * @msg: pointer to the msg buffer
2202 * @msglen: msg length
2204 * called from the VF for the iwarp msgs
2206 static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2208 struct i40e_pf *pf = vf->pf;
2209 int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
2210 i40e_status aq_ret = 0;
2212 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2213 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
2214 aq_ret = I40E_ERR_PARAM;
2218 i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
2222 /* send the response to the VF */
2223 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_IWARP,
2228 * i40e_vc_iwarp_qvmap_msg
2229 * @vf: pointer to the VF info
2230 * @msg: pointer to the msg buffer
2231 * @msglen: msg length
2232 * @config: config qvmap or release it
2234 * called from the VF for the iwarp msgs
2236 static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
2239 struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info =
2240 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2241 i40e_status aq_ret = 0;
2243 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2244 !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
2245 aq_ret = I40E_ERR_PARAM;
2250 if (i40e_config_iwarp_qvlist(vf, qvlist_info))
2251 aq_ret = I40E_ERR_PARAM;
2253 i40e_release_iwarp_qvlist(vf);
2257 /* send the response to the VF */
2258 return i40e_vc_send_resp_to_vf(vf,
2259 config ? I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP :
2260 I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
2265 * i40e_vc_config_rss_key
2266 * @vf: pointer to the VF info
2267 * @msg: pointer to the msg buffer
2268 * @msglen: msg length
2270 * Configure the VF's RSS key
2272 static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
2274 struct i40e_virtchnl_rss_key *vrk =
2275 (struct i40e_virtchnl_rss_key *)msg;
2276 struct i40e_pf *pf = vf->pf;
2277 struct i40e_vsi *vsi = NULL;
2278 u16 vsi_id = vrk->vsi_id;
2279 i40e_status aq_ret = 0;
2281 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2282 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2283 (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
2284 aq_ret = I40E_ERR_PARAM;
2288 vsi = pf->vsi[vf->lan_vsi_idx];
2289 aq_ret = i40e_config_rss(vsi, vrk->key, NULL, 0);
2291 /* send the response to the VF */
2292 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
2297 * i40e_vc_config_rss_lut
2298 * @vf: pointer to the VF info
2299 * @msg: pointer to the msg buffer
2300 * @msglen: msg length
2302 * Configure the VF's RSS LUT
2304 static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
2306 struct i40e_virtchnl_rss_lut *vrl =
2307 (struct i40e_virtchnl_rss_lut *)msg;
2308 struct i40e_pf *pf = vf->pf;
2309 struct i40e_vsi *vsi = NULL;
2310 u16 vsi_id = vrl->vsi_id;
2311 i40e_status aq_ret = 0;
2313 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
2314 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2315 (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
2316 aq_ret = I40E_ERR_PARAM;
2320 vsi = pf->vsi[vf->lan_vsi_idx];
2321 aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
2322 /* send the response to the VF */
2324 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
2329 * i40e_vc_get_rss_hena
2330 * @vf: pointer to the VF info
2331 * @msg: pointer to the msg buffer
2332 * @msglen: msg length
2334 * Return the RSS HENA bits allowed by the hardware
2336 static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2338 struct i40e_virtchnl_rss_hena *vrh = NULL;
2339 struct i40e_pf *pf = vf->pf;
2340 i40e_status aq_ret = 0;
2343 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
2344 aq_ret = I40E_ERR_PARAM;
2347 len = sizeof(struct i40e_virtchnl_rss_hena);
2349 vrh = kzalloc(len, GFP_KERNEL);
2351 aq_ret = I40E_ERR_NO_MEMORY;
2355 vrh->hena = i40e_pf_get_default_rss_hena(pf);
2357 /* send the response back to the VF */
2358 aq_ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
2359 aq_ret, (u8 *)vrh, len);
2365 * i40e_vc_set_rss_hena
2366 * @vf: pointer to the VF info
2367 * @msg: pointer to the msg buffer
2368 * @msglen: msg length
2370 * Set the RSS HENA bits for the VF
2372 static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2374 struct i40e_virtchnl_rss_hena *vrh =
2375 (struct i40e_virtchnl_rss_hena *)msg;
2376 struct i40e_pf *pf = vf->pf;
2377 struct i40e_hw *hw = &pf->hw;
2378 i40e_status aq_ret = 0;
2380 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
2381 aq_ret = I40E_ERR_PARAM;
2384 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)vrh->hena);
2385 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_id),
2386 (u32)(vrh->hena >> 32));
2388 /* send the response to the VF */
2390 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_SET_RSS_HENA,
2395 * i40e_vc_validate_vf_msg
2396 * @vf: pointer to the VF info
2397 * @msg: pointer to the msg buffer
2398 * @msglen: msg length
2399 * @msghndl: msg handle
2403 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
2404 u32 v_retval, u8 *msg, u16 msglen)
2406 bool err_msg_format = false;
2409 /* Check if VF is disabled. */
2410 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
2411 return I40E_ERR_PARAM;
2413 /* Validate message length. */
2415 case I40E_VIRTCHNL_OP_VERSION:
2416 valid_len = sizeof(struct i40e_virtchnl_version_info);
2418 case I40E_VIRTCHNL_OP_RESET_VF:
2420 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
2422 valid_len = sizeof(u32);
2424 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
2425 valid_len = sizeof(struct i40e_virtchnl_txq_info);
2427 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
2428 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
2430 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
2431 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
2432 if (msglen >= valid_len) {
2433 struct i40e_virtchnl_vsi_queue_config_info *vqc =
2434 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
2435 valid_len += (vqc->num_queue_pairs *
2437 i40e_virtchnl_queue_pair_info));
2438 if (vqc->num_queue_pairs == 0)
2439 err_msg_format = true;
2442 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
2443 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
2444 if (msglen >= valid_len) {
2445 struct i40e_virtchnl_irq_map_info *vimi =
2446 (struct i40e_virtchnl_irq_map_info *)msg;
2447 valid_len += (vimi->num_vectors *
2448 sizeof(struct i40e_virtchnl_vector_map));
2449 if (vimi->num_vectors == 0)
2450 err_msg_format = true;
2453 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
2454 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
2455 valid_len = sizeof(struct i40e_virtchnl_queue_select);
2457 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
2458 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
2459 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
2460 if (msglen >= valid_len) {
2461 struct i40e_virtchnl_ether_addr_list *veal =
2462 (struct i40e_virtchnl_ether_addr_list *)msg;
2463 valid_len += veal->num_elements *
2464 sizeof(struct i40e_virtchnl_ether_addr);
2465 if (veal->num_elements == 0)
2466 err_msg_format = true;
2469 case I40E_VIRTCHNL_OP_ADD_VLAN:
2470 case I40E_VIRTCHNL_OP_DEL_VLAN:
2471 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
2472 if (msglen >= valid_len) {
2473 struct i40e_virtchnl_vlan_filter_list *vfl =
2474 (struct i40e_virtchnl_vlan_filter_list *)msg;
2475 valid_len += vfl->num_elements * sizeof(u16);
2476 if (vfl->num_elements == 0)
2477 err_msg_format = true;
2480 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
2481 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
2483 case I40E_VIRTCHNL_OP_GET_STATS:
2484 valid_len = sizeof(struct i40e_virtchnl_queue_select);
2486 case I40E_VIRTCHNL_OP_IWARP:
2487 /* These messages are opaque to us and will be validated in
2488 * the RDMA client code. We just need to check for nonzero
2489 * length. The firmware will enforce max length restrictions.
2494 err_msg_format = true;
2496 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2499 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2500 valid_len = sizeof(struct i40e_virtchnl_iwarp_qvlist_info);
2501 if (msglen >= valid_len) {
2502 struct i40e_virtchnl_iwarp_qvlist_info *qv =
2503 (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
2504 if (qv->num_vectors == 0) {
2505 err_msg_format = true;
2508 valid_len += ((qv->num_vectors - 1) *
2509 sizeof(struct i40e_virtchnl_iwarp_qv_info));
2512 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
2513 valid_len = sizeof(struct i40e_virtchnl_rss_key);
2514 if (msglen >= valid_len) {
2515 struct i40e_virtchnl_rss_key *vrk =
2516 (struct i40e_virtchnl_rss_key *)msg;
2517 if (vrk->key_len != I40E_HKEY_ARRAY_SIZE) {
2518 err_msg_format = true;
2521 valid_len += vrk->key_len - 1;
2524 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
2525 valid_len = sizeof(struct i40e_virtchnl_rss_lut);
2526 if (msglen >= valid_len) {
2527 struct i40e_virtchnl_rss_lut *vrl =
2528 (struct i40e_virtchnl_rss_lut *)msg;
2529 if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE) {
2530 err_msg_format = true;
2533 valid_len += vrl->lut_entries - 1;
2536 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
2538 case I40E_VIRTCHNL_OP_SET_RSS_HENA:
2539 valid_len = sizeof(struct i40e_virtchnl_rss_hena);
2541 /* These are always errors coming from the VF. */
2542 case I40E_VIRTCHNL_OP_EVENT:
2543 case I40E_VIRTCHNL_OP_UNKNOWN:
2547 /* few more checks */
2548 if ((valid_len != msglen) || (err_msg_format)) {
2549 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
2557 * i40e_vc_process_vf_msg
2558 * @pf: pointer to the PF structure
2559 * @vf_id: source VF id
2560 * @msg: pointer to the msg buffer
2561 * @msglen: msg length
2562 * @msghndl: msg handle
2564 * called from the common aeq/arq handler to
2565 * process request from VF
2567 int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
2568 u32 v_retval, u8 *msg, u16 msglen)
2570 struct i40e_hw *hw = &pf->hw;
2571 int local_vf_id = vf_id - (s16)hw->func_caps.vf_base_id;
2575 pf->vf_aq_requests++;
2576 if (local_vf_id >= pf->num_alloc_vfs)
2578 vf = &(pf->vf[local_vf_id]);
2579 /* perform basic checks on the msg */
2580 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
2583 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
2584 local_vf_id, v_opcode, msglen);
2589 case I40E_VIRTCHNL_OP_VERSION:
2590 ret = i40e_vc_get_version_msg(vf, msg);
2592 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
2593 ret = i40e_vc_get_vf_resources_msg(vf, msg);
2595 case I40E_VIRTCHNL_OP_RESET_VF:
2596 i40e_vc_reset_vf_msg(vf);
2599 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
2600 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
2602 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
2603 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
2605 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
2606 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
2608 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
2609 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
2610 i40e_vc_notify_vf_link_state(vf);
2612 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
2613 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
2615 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
2616 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
2618 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
2619 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
2621 case I40E_VIRTCHNL_OP_ADD_VLAN:
2622 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
2624 case I40E_VIRTCHNL_OP_DEL_VLAN:
2625 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
2627 case I40E_VIRTCHNL_OP_GET_STATS:
2628 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
2630 case I40E_VIRTCHNL_OP_IWARP:
2631 ret = i40e_vc_iwarp_msg(vf, msg, msglen);
2633 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2634 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
2636 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
2637 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
2639 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
2640 ret = i40e_vc_config_rss_key(vf, msg, msglen);
2642 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
2643 ret = i40e_vc_config_rss_lut(vf, msg, msglen);
2645 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
2646 ret = i40e_vc_get_rss_hena(vf, msg, msglen);
2648 case I40E_VIRTCHNL_OP_SET_RSS_HENA:
2649 ret = i40e_vc_set_rss_hena(vf, msg, msglen);
2652 case I40E_VIRTCHNL_OP_UNKNOWN:
2654 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
2655 v_opcode, local_vf_id);
2656 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
2657 I40E_ERR_NOT_IMPLEMENTED);
2665 * i40e_vc_process_vflr_event
2666 * @pf: pointer to the PF structure
2668 * called from the vlfr irq handler to
2669 * free up VF resources and state variables
2671 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
2673 struct i40e_hw *hw = &pf->hw;
2674 u32 reg, reg_idx, bit_idx;
2678 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2681 /* Re-enable the VFLR interrupt cause here, before looking for which
2682 * VF got reset. Otherwise, if another VF gets a reset while the
2683 * first one is being processed, that interrupt will be lost, and
2684 * that VF will be stuck in reset forever.
2686 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2687 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2688 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2691 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2692 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2693 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2694 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
2695 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
2696 vf = &pf->vf[vf_id];
2697 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
2698 if (reg & BIT(bit_idx))
2699 /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
2700 i40e_reset_vf(vf, true);
2707 * i40e_ndo_set_vf_mac
2708 * @netdev: network interface device structure
2709 * @vf_id: VF identifier
2712 * program VF mac address
2714 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2716 struct i40e_netdev_priv *np = netdev_priv(netdev);
2717 struct i40e_vsi *vsi = np->vsi;
2718 struct i40e_pf *pf = vsi->back;
2719 struct i40e_mac_filter *f;
2723 /* validate the request */
2724 if (vf_id >= pf->num_alloc_vfs) {
2725 dev_err(&pf->pdev->dev,
2726 "Invalid VF Identifier %d\n", vf_id);
2731 vf = &(pf->vf[vf_id]);
2732 vsi = pf->vsi[vf->lan_vsi_idx];
2733 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2734 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2740 if (is_multicast_ether_addr(mac)) {
2741 dev_err(&pf->pdev->dev,
2742 "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
2747 /* Lock once because below invoked function add/del_filter requires
2748 * mac_filter_list_lock to be held
2750 spin_lock_bh(&vsi->mac_filter_list_lock);
2752 /* delete the temporary mac address */
2753 if (!is_zero_ether_addr(vf->default_lan_addr.addr))
2754 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2755 vf->port_vlan_id ? vf->port_vlan_id : -1,
2758 /* Delete all the filters for this VSI - we're going to kill it
2761 list_for_each_entry(f, &vsi->mac_filter_list, list)
2762 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2764 spin_unlock_bh(&vsi->mac_filter_list_lock);
2766 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2767 /* program mac filter */
2768 if (i40e_sync_vsi_filters(vsi)) {
2769 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2773 ether_addr_copy(vf->default_lan_addr.addr, mac);
2774 vf->pf_set_mac = true;
2775 /* Force the VF driver stop so it has to reload with new MAC address */
2776 i40e_vc_disable_vf(pf, vf);
2777 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2784 * i40e_ndo_set_vf_port_vlan
2785 * @netdev: network interface device structure
2786 * @vf_id: VF identifier
2787 * @vlan_id: mac address
2788 * @qos: priority setting
2789 * @vlan_proto: vlan protocol
2791 * program VF vlan id and/or qos
2793 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
2794 u16 vlan_id, u8 qos, __be16 vlan_proto)
2796 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
2797 struct i40e_netdev_priv *np = netdev_priv(netdev);
2798 struct i40e_pf *pf = np->vsi->back;
2799 bool is_vsi_in_vlan = false;
2800 struct i40e_vsi *vsi;
2804 /* validate the request */
2805 if (vf_id >= pf->num_alloc_vfs) {
2806 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2811 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2812 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2817 if (vlan_proto != htons(ETH_P_8021Q)) {
2818 dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
2819 ret = -EPROTONOSUPPORT;
2823 vf = &(pf->vf[vf_id]);
2824 vsi = pf->vsi[vf->lan_vsi_idx];
2825 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2826 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2832 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
2833 /* duplicate request, so just return success */
2836 spin_lock_bh(&vsi->mac_filter_list_lock);
2837 is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
2838 spin_unlock_bh(&vsi->mac_filter_list_lock);
2840 if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
2841 dev_err(&pf->pdev->dev,
2842 "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",
2844 /* Administrator Error - knock the VF offline until he does
2845 * the right thing by reconfiguring his network correctly
2846 * and then reloading the VF driver.
2848 i40e_vc_disable_vf(pf, vf);
2849 /* During reset the VF got a new VSI, so refresh the pointer. */
2850 vsi = pf->vsi[vf->lan_vsi_idx];
2853 /* Check for condition where there was already a port VLAN ID
2854 * filter set and now it is being deleted by setting it to zero.
2855 * Additionally check for the condition where there was a port
2856 * VLAN but now there is a new and different port VLAN being set.
2857 * Before deleting all the old VLAN filters we must add new ones
2858 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2859 * MAC addresses deleted.
2861 if ((!(vlan_id || qos) ||
2862 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
2864 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2866 if (vsi->info.pvid) {
2868 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2871 dev_info(&vsi->back->pdev->dev,
2872 "remove VLAN failed, ret=%d, aq_err=%d\n",
2873 ret, pf->hw.aq.asq_last_status);
2877 ret = i40e_vsi_add_pvid(vsi, vlanprio);
2879 i40e_vsi_remove_pvid(vsi);
2882 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2883 vlan_id, qos, vf_id);
2885 /* add new VLAN filter */
2886 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2888 dev_info(&vsi->back->pdev->dev,
2889 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2890 vsi->back->hw.aq.asq_last_status);
2893 /* Kill non-vlan MAC filters - ignore error return since
2894 * there might not be any non-vlan MAC filters.
2896 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2900 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2903 /* The Port VLAN needs to be saved across resets the same as the
2904 * default LAN MAC address.
2906 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2913 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2914 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2916 * i40e_ndo_set_vf_bw
2917 * @netdev: network interface device structure
2918 * @vf_id: VF identifier
2921 * configure VF Tx rate
2923 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2926 struct i40e_netdev_priv *np = netdev_priv(netdev);
2927 struct i40e_pf *pf = np->vsi->back;
2928 struct i40e_vsi *vsi;
2933 /* validate the request */
2934 if (vf_id >= pf->num_alloc_vfs) {
2935 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2941 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2942 min_tx_rate, vf_id);
2946 vf = &(pf->vf[vf_id]);
2947 vsi = pf->vsi[vf->lan_vsi_idx];
2948 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2949 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
2955 switch (pf->hw.phy.link_info.link_speed) {
2956 case I40E_LINK_SPEED_40GB:
2959 case I40E_LINK_SPEED_20GB:
2962 case I40E_LINK_SPEED_10GB:
2965 case I40E_LINK_SPEED_1GB:
2972 if (max_tx_rate > speed) {
2973 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
2974 max_tx_rate, vf->vf_id);
2979 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2980 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2984 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2985 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2986 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2987 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2989 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2994 vf->tx_rate = max_tx_rate;
3000 * i40e_ndo_get_vf_config
3001 * @netdev: network interface device structure
3002 * @vf_id: VF identifier
3003 * @ivi: VF configuration structure
3005 * return VF configuration
3007 int i40e_ndo_get_vf_config(struct net_device *netdev,
3008 int vf_id, struct ifla_vf_info *ivi)
3010 struct i40e_netdev_priv *np = netdev_priv(netdev);
3011 struct i40e_vsi *vsi = np->vsi;
3012 struct i40e_pf *pf = vsi->back;
3016 /* validate the request */
3017 if (vf_id >= pf->num_alloc_vfs) {
3018 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3023 vf = &(pf->vf[vf_id]);
3024 /* first vsi is always the LAN vsi */
3025 vsi = pf->vsi[vf->lan_vsi_idx];
3026 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
3027 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3035 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
3037 ivi->max_tx_rate = vf->tx_rate;
3038 ivi->min_tx_rate = 0;
3039 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
3040 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
3041 I40E_VLAN_PRIORITY_SHIFT;
3042 if (vf->link_forced == false)
3043 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
3044 else if (vf->link_up == true)
3045 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
3047 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
3048 ivi->spoofchk = vf->spoofchk;
3049 ivi->trusted = vf->trusted;
3057 * i40e_ndo_set_vf_link_state
3058 * @netdev: network interface device structure
3059 * @vf_id: VF identifier
3060 * @link: required link state
3062 * Set the link state of a specified VF, regardless of physical link state
3064 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
3066 struct i40e_netdev_priv *np = netdev_priv(netdev);
3067 struct i40e_pf *pf = np->vsi->back;
3068 struct i40e_virtchnl_pf_event pfe;
3069 struct i40e_hw *hw = &pf->hw;
3074 /* validate the request */
3075 if (vf_id >= pf->num_alloc_vfs) {
3076 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3081 vf = &pf->vf[vf_id];
3082 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
3084 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
3085 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
3088 case IFLA_VF_LINK_STATE_AUTO:
3089 vf->link_forced = false;
3090 pfe.event_data.link_event.link_status =
3091 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
3092 pfe.event_data.link_event.link_speed =
3093 pf->hw.phy.link_info.link_speed;
3095 case IFLA_VF_LINK_STATE_ENABLE:
3096 vf->link_forced = true;
3098 pfe.event_data.link_event.link_status = true;
3099 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
3101 case IFLA_VF_LINK_STATE_DISABLE:
3102 vf->link_forced = true;
3103 vf->link_up = false;
3104 pfe.event_data.link_event.link_status = false;
3105 pfe.event_data.link_event.link_speed = 0;
3111 /* Notify the VF of its new link state */
3112 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
3113 0, (u8 *)&pfe, sizeof(pfe), NULL);
3120 * i40e_ndo_set_vf_spoofchk
3121 * @netdev: network interface device structure
3122 * @vf_id: VF identifier
3123 * @enable: flag to enable or disable feature
3125 * Enable or disable VF spoof checking
3127 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
3129 struct i40e_netdev_priv *np = netdev_priv(netdev);
3130 struct i40e_vsi *vsi = np->vsi;
3131 struct i40e_pf *pf = vsi->back;
3132 struct i40e_vsi_context ctxt;
3133 struct i40e_hw *hw = &pf->hw;
3137 /* validate the request */
3138 if (vf_id >= pf->num_alloc_vfs) {
3139 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3144 vf = &(pf->vf[vf_id]);
3145 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
3146 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3152 if (enable == vf->spoofchk)
3155 vf->spoofchk = enable;
3156 memset(&ctxt, 0, sizeof(ctxt));
3157 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
3158 ctxt.pf_num = pf->hw.pf_id;
3159 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
3161 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
3162 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
3163 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3165 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
3174 * i40e_ndo_set_vf_trust
3175 * @netdev: network interface device structure of the pf
3176 * @vf_id: VF identifier
3177 * @setting: trust setting
3179 * Enable or disable VF trust setting
3181 int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
3183 struct i40e_netdev_priv *np = netdev_priv(netdev);
3184 struct i40e_pf *pf = np->vsi->back;
3188 /* validate the request */
3189 if (vf_id >= pf->num_alloc_vfs) {
3190 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3194 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3195 dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
3199 vf = &pf->vf[vf_id];
3203 if (setting == vf->trusted)
3206 vf->trusted = setting;
3207 i40e_vc_notify_vf_reset(vf);
3208 i40e_reset_vf(vf, false);
3209 dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
3210 vf_id, setting ? "" : "un");