1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
6 /*********************notification routines***********************/
10 * @pf: pointer to the PF structure
11 * @opcode: operation code
12 * @retval: return value
13 * @msg: pointer to the msg buffer
16 * send a message to all VFs on a given PF
18 static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
19 enum virtchnl_ops v_opcode,
20 i40e_status v_retval, u8 *msg,
23 struct i40e_hw *hw = &pf->hw;
24 struct i40e_vf *vf = pf->vf;
27 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
28 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
29 /* Not all vfs are enabled so skip the ones that are not */
30 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
31 !test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
34 /* Ignore return value on purpose - a given VF may fail, but
35 * we need to keep going and send to all of them
37 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
43 * i40e_vc_notify_vf_link_state
44 * @vf: pointer to the VF structure
46 * send a link status message to a single VF
48 static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
50 struct virtchnl_pf_event pfe;
51 struct i40e_pf *pf = vf->pf;
52 struct i40e_hw *hw = &pf->hw;
53 struct i40e_link_status *ls = &pf->hw.phy.link_info;
54 int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
56 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
57 pfe.severity = PF_EVENT_SEVERITY_INFO;
58 if (vf->link_forced) {
59 pfe.event_data.link_event.link_status = vf->link_up;
60 pfe.event_data.link_event.link_speed =
61 (vf->link_up ? VIRTCHNL_LINK_SPEED_40GB : 0);
63 pfe.event_data.link_event.link_status =
64 ls->link_info & I40E_AQ_LINK_UP;
65 pfe.event_data.link_event.link_speed =
66 i40e_virtchnl_link_speed(ls->link_speed);
68 i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT,
69 0, (u8 *)&pfe, sizeof(pfe), NULL);
73 * i40e_vc_notify_link_state
74 * @pf: pointer to the PF structure
76 * send a link status message to all VFs on a given PF
78 void i40e_vc_notify_link_state(struct i40e_pf *pf)
82 for (i = 0; i < pf->num_alloc_vfs; i++)
83 i40e_vc_notify_vf_link_state(&pf->vf[i]);
87 * i40e_vc_notify_reset
88 * @pf: pointer to the PF structure
90 * indicate a pending reset to all VFs on a given PF
92 void i40e_vc_notify_reset(struct i40e_pf *pf)
94 struct virtchnl_pf_event pfe;
96 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
97 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
98 i40e_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, 0,
99 (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
103 * i40e_vc_notify_vf_reset
104 * @vf: pointer to the VF structure
106 * indicate a pending reset to the given VF
108 void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
110 struct virtchnl_pf_event pfe;
113 /* validate the request */
114 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
117 /* verify if the VF is in either init or active before proceeding */
118 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
119 !test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
122 abs_vf_id = vf->vf_id + (int)vf->pf->hw.func_caps.vf_base_id;
124 pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
125 pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
126 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, VIRTCHNL_OP_EVENT,
128 sizeof(struct virtchnl_pf_event), NULL);
130 /***********************misc routines*****************************/
134 * @vf: pointer to the VF info
136 * Disable the VF through a SW reset.
138 static inline void i40e_vc_disable_vf(struct i40e_vf *vf)
142 i40e_vc_notify_vf_reset(vf);
144 /* We want to ensure that an actual reset occurs initiated after this
145 * function was called. However, we do not want to wait forever, so
146 * we'll give a reasonable time and print a message if we failed to
149 for (i = 0; i < 20; i++) {
150 if (i40e_reset_vf(vf, false))
152 usleep_range(10000, 20000);
155 dev_warn(&vf->pf->pdev->dev,
156 "Failed to initiate reset for VF %d after 200 milliseconds\n",
161 * i40e_vc_isvalid_vsi_id
162 * @vf: pointer to the VF info
163 * @vsi_id: VF relative VSI id
165 * check for the valid VSI id
167 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
169 struct i40e_pf *pf = vf->pf;
170 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
172 return (vsi && (vsi->vf_id == vf->vf_id));
176 * i40e_vc_isvalid_queue_id
177 * @vf: pointer to the VF info
179 * @qid: vsi relative queue id
181 * check for the valid queue id
183 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
186 struct i40e_pf *pf = vf->pf;
187 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
189 return (vsi && (qid < vsi->alloc_queue_pairs));
193 * i40e_vc_isvalid_vector_id
194 * @vf: pointer to the VF info
195 * @vector_id: VF relative vector id
197 * check for the valid vector id
199 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
201 struct i40e_pf *pf = vf->pf;
203 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
206 /***********************vf resource mgmt routines*****************/
209 * i40e_vc_get_pf_queue_id
210 * @vf: pointer to the VF info
211 * @vsi_id: id of VSI as provided by the FW
212 * @vsi_queue_id: vsi relative queue id
214 * return PF relative queue id
216 static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
219 struct i40e_pf *pf = vf->pf;
220 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
221 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
226 if (le16_to_cpu(vsi->info.mapping_flags) &
227 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
229 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
231 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
238 * i40e_get_real_pf_qid
239 * @vf: pointer to the VF info
241 * @queue_id: queue number
243 * wrapper function to get pf_queue_id handling ADq code as well
245 static u16 i40e_get_real_pf_qid(struct i40e_vf *vf, u16 vsi_id, u16 queue_id)
249 if (vf->adq_enabled) {
250 /* Although VF considers all the queues(can be 1 to 16) as its
251 * own but they may actually belong to different VSIs(up to 4).
252 * We need to find which queues belongs to which VSI.
254 for (i = 0; i < vf->num_tc; i++) {
255 if (queue_id < vf->ch[i].num_qps) {
256 vsi_id = vf->ch[i].vsi_id;
259 /* find right queue id which is relative to a
262 queue_id -= vf->ch[i].num_qps;
266 return i40e_vc_get_pf_queue_id(vf, vsi_id, queue_id);
270 * i40e_config_irq_link_list
271 * @vf: pointer to the VF info
272 * @vsi_id: id of VSI as given by the FW
273 * @vecmap: irq map info
275 * configure irq link list from the map
277 static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
278 struct virtchnl_vector_map *vecmap)
280 unsigned long linklistmap = 0, tempmap;
281 struct i40e_pf *pf = vf->pf;
282 struct i40e_hw *hw = &pf->hw;
283 u16 vsi_queue_id, pf_queue_id;
284 enum i40e_queue_type qtype;
285 u16 next_q, vector_id, size;
289 vector_id = vecmap->vector_id;
292 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
294 reg_idx = I40E_VPINT_LNKLSTN(
295 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
298 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
299 /* Special case - No queues mapped on this vector */
300 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
303 tempmap = vecmap->rxq_map;
304 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
305 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
309 tempmap = vecmap->txq_map;
310 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
311 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
315 size = I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES;
316 next_q = find_first_bit(&linklistmap, size);
317 if (unlikely(next_q == size))
320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
322 pf_queue_id = i40e_get_real_pf_qid(vf, vsi_id, vsi_queue_id);
323 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
325 wr32(hw, reg_idx, reg);
327 while (next_q < size) {
329 case I40E_QUEUE_TYPE_RX:
330 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
331 itr_idx = vecmap->rxitr_idx;
333 case I40E_QUEUE_TYPE_TX:
334 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
335 itr_idx = vecmap->txitr_idx;
341 next_q = find_next_bit(&linklistmap, size, next_q + 1);
343 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
344 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
345 pf_queue_id = i40e_get_real_pf_qid(vf,
349 pf_queue_id = I40E_QUEUE_END_OF_LIST;
353 /* format for the RQCTL & TQCTL regs is same */
355 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
356 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
357 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
358 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
359 wr32(hw, reg_idx, reg);
362 /* if the vf is running in polling mode and using interrupt zero,
363 * need to disable auto-mask on enabling zero interrupt for VFs.
365 if ((vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
367 reg = rd32(hw, I40E_GLINT_CTL);
368 if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
369 reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
370 wr32(hw, I40E_GLINT_CTL, reg);
379 * i40e_release_iwarp_qvlist
380 * @vf: pointer to the VF.
383 static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
385 struct i40e_pf *pf = vf->pf;
386 struct virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
390 if (!vf->qvlist_info)
393 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
394 for (i = 0; i < qvlist_info->num_vectors; i++) {
395 struct virtchnl_iwarp_qv_info *qv_info;
396 u32 next_q_index, next_q_type;
397 struct i40e_hw *hw = &pf->hw;
398 u32 v_idx, reg_idx, reg;
400 qv_info = &qvlist_info->qv_info[i];
403 v_idx = qv_info->v_idx;
404 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
405 /* Figure out the queue after CEQ and make that the
408 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
409 reg = rd32(hw, I40E_VPINT_CEQCTL(reg_idx));
410 next_q_index = (reg & I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK)
411 >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT;
412 next_q_type = (reg & I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK)
413 >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT;
415 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
416 reg = (next_q_index &
417 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
419 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
421 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
424 kfree(vf->qvlist_info);
425 vf->qvlist_info = NULL;
429 * i40e_config_iwarp_qvlist
430 * @vf: pointer to the VF info
431 * @qvlist_info: queue and vector list
433 * Return 0 on success or < 0 on error
435 static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
436 struct virtchnl_iwarp_qvlist_info *qvlist_info)
438 struct i40e_pf *pf = vf->pf;
439 struct i40e_hw *hw = &pf->hw;
440 struct virtchnl_iwarp_qv_info *qv_info;
441 u32 v_idx, i, reg_idx, reg;
442 u32 next_q_idx, next_q_type;
445 size = sizeof(struct virtchnl_iwarp_qvlist_info) +
446 (sizeof(struct virtchnl_iwarp_qv_info) *
447 (qvlist_info->num_vectors - 1));
448 vf->qvlist_info = kzalloc(size, GFP_KERNEL);
449 if (!vf->qvlist_info)
452 vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
454 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
455 for (i = 0; i < qvlist_info->num_vectors; i++) {
456 qv_info = &qvlist_info->qv_info[i];
459 v_idx = qv_info->v_idx;
461 /* Validate vector id belongs to this vf */
462 if (!i40e_vc_isvalid_vector_id(vf, v_idx))
465 vf->qvlist_info->qv_info[i] = *qv_info;
467 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
468 /* We might be sharing the interrupt, so get the first queue
469 * index and type, push it down the list by adding the new
470 * queue on top. Also link it with the new queue in CEQCTL.
472 reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
473 next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
474 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
475 next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
476 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
478 if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
479 reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
480 reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
481 (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
482 (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
483 (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
484 (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
485 wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
487 reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
488 reg = (qv_info->ceq_idx &
489 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
490 (I40E_QUEUE_TYPE_PE_CEQ <<
491 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
492 wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
495 if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
496 reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
497 (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
498 (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
500 wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
506 kfree(vf->qvlist_info);
507 vf->qvlist_info = NULL;
512 * i40e_config_vsi_tx_queue
513 * @vf: pointer to the VF info
514 * @vsi_id: id of VSI as provided by the FW
515 * @vsi_queue_id: vsi relative queue index
516 * @info: config. info
520 static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
522 struct virtchnl_txq_info *info)
524 struct i40e_pf *pf = vf->pf;
525 struct i40e_hw *hw = &pf->hw;
526 struct i40e_hmc_obj_txq tx_ctx;
527 struct i40e_vsi *vsi;
532 if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
536 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
537 vsi = i40e_find_vsi_from_id(pf, vsi_id);
543 /* clear the context structure first */
544 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
546 /* only set the required fields */
547 tx_ctx.base = info->dma_ring_addr / 128;
548 tx_ctx.qlen = info->ring_len;
549 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
550 tx_ctx.rdylist_act = 0;
551 tx_ctx.head_wb_ena = info->headwb_enabled;
552 tx_ctx.head_wb_addr = info->dma_headwb_addr;
554 /* clear the context in the HMC */
555 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
557 dev_err(&pf->pdev->dev,
558 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
564 /* set the context in the HMC */
565 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
567 dev_err(&pf->pdev->dev,
568 "Failed to set VF LAN Tx queue context %d error: %d\n",
574 /* associate this queue with the PCI VF function */
575 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
576 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
577 & I40E_QTX_CTL_PF_INDX_MASK);
578 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
579 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
580 & I40E_QTX_CTL_VFVM_INDX_MASK);
581 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
589 * i40e_config_vsi_rx_queue
590 * @vf: pointer to the VF info
591 * @vsi_id: id of VSI as provided by the FW
592 * @vsi_queue_id: vsi relative queue index
593 * @info: config. info
597 static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
599 struct virtchnl_rxq_info *info)
601 struct i40e_pf *pf = vf->pf;
602 struct i40e_hw *hw = &pf->hw;
603 struct i40e_hmc_obj_rxq rx_ctx;
607 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
609 /* clear the context structure first */
610 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
612 /* only set the required fields */
613 rx_ctx.base = info->dma_ring_addr / 128;
614 rx_ctx.qlen = info->ring_len;
616 if (info->splithdr_enabled) {
617 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
619 I40E_RX_SPLIT_TCP_UDP |
621 /* header length validation */
622 if (info->hdr_size > ((2 * 1024) - 64)) {
626 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
628 /* set split mode 10b */
629 rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
632 /* databuffer length validation */
633 if (info->databuffer_size > ((16 * 1024) - 128)) {
637 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
639 /* max pkt. length validation */
640 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
644 rx_ctx.rxmax = info->max_pkt_size;
646 /* enable 32bytes desc always */
650 rx_ctx.lrxqthresh = 1;
655 /* clear the context in the HMC */
656 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
658 dev_err(&pf->pdev->dev,
659 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
665 /* set the context in the HMC */
666 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
668 dev_err(&pf->pdev->dev,
669 "Failed to set VF LAN Rx queue context %d error: %d\n",
681 * @vf: pointer to the VF info
682 * @idx: VSI index, applies only for ADq mode, zero otherwise
684 * alloc VF vsi context & resources
686 static int i40e_alloc_vsi_res(struct i40e_vf *vf, u8 idx)
688 struct i40e_mac_filter *f = NULL;
689 struct i40e_pf *pf = vf->pf;
690 struct i40e_vsi *vsi;
694 vsi = i40e_vsi_setup(pf, I40E_VSI_SRIOV, pf->vsi[pf->lan_vsi]->seid,
698 dev_err(&pf->pdev->dev,
699 "add vsi failed for VF %d, aq_err %d\n",
700 vf->vf_id, pf->hw.aq.asq_last_status);
702 goto error_alloc_vsi_res;
706 u64 hena = i40e_pf_get_default_rss_hena(pf);
707 u8 broadcast[ETH_ALEN];
709 vf->lan_vsi_idx = vsi->idx;
710 vf->lan_vsi_id = vsi->id;
711 /* If the port VLAN has been configured and then the
712 * VF driver was removed then the VSI port VLAN
713 * configuration was destroyed. Check if there is
714 * a port VLAN and restore the VSI configuration if
717 if (vf->port_vlan_id)
718 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
720 spin_lock_bh(&vsi->mac_filter_hash_lock);
721 if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
722 f = i40e_add_mac_filter(vsi,
723 vf->default_lan_addr.addr);
725 dev_info(&pf->pdev->dev,
726 "Could not add MAC filter %pM for VF %d\n",
727 vf->default_lan_addr.addr, vf->vf_id);
729 eth_broadcast_addr(broadcast);
730 f = i40e_add_mac_filter(vsi, broadcast);
732 dev_info(&pf->pdev->dev,
733 "Could not allocate VF broadcast filter\n");
734 spin_unlock_bh(&vsi->mac_filter_hash_lock);
735 wr32(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)hena);
736 wr32(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id), (u32)(hena >> 32));
737 /* program mac filter only for VF VSI */
738 ret = i40e_sync_vsi_filters(vsi);
740 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
743 /* storing VSI index and id for ADq and don't apply the mac filter */
744 if (vf->adq_enabled) {
745 vf->ch[idx].vsi_idx = vsi->idx;
746 vf->ch[idx].vsi_id = vsi->id;
749 /* Set VF bandwidth if specified */
751 max_tx_rate = vf->tx_rate;
752 } else if (vf->ch[idx].max_tx_rate) {
753 max_tx_rate = vf->ch[idx].max_tx_rate;
757 max_tx_rate = div_u64(max_tx_rate, I40E_BW_CREDIT_DIVISOR);
758 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
759 max_tx_rate, 0, NULL);
761 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
770 * i40e_map_pf_queues_to_vsi
771 * @vf: pointer to the VF info
773 * PF maps LQPs to a VF by programming VSILAN_QTABLE & VPLAN_QTABLE. This
774 * function takes care of first part VSILAN_QTABLE, mapping pf queues to VSI.
776 static void i40e_map_pf_queues_to_vsi(struct i40e_vf *vf)
778 struct i40e_pf *pf = vf->pf;
779 struct i40e_hw *hw = &pf->hw;
780 u32 reg, num_tc = 1; /* VF has at least one traffic class */
787 for (i = 0; i < num_tc; i++) {
788 if (vf->adq_enabled) {
789 qps = vf->ch[i].num_qps;
790 vsi_id = vf->ch[i].vsi_id;
792 qps = pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
793 vsi_id = vf->lan_vsi_id;
796 for (j = 0; j < 7; j++) {
801 u16 qid = i40e_vc_get_pf_queue_id(vf,
805 qid = i40e_vc_get_pf_queue_id(vf, vsi_id,
809 i40e_write_rx_ctl(hw,
810 I40E_VSILAN_QTABLE(j, vsi_id),
817 * i40e_map_pf_to_vf_queues
818 * @vf: pointer to the VF info
820 * PF maps LQPs to a VF by programming VSILAN_QTABLE & VPLAN_QTABLE. This
821 * function takes care of the second part VPLAN_QTABLE & completes VF mappings.
823 static void i40e_map_pf_to_vf_queues(struct i40e_vf *vf)
825 struct i40e_pf *pf = vf->pf;
826 struct i40e_hw *hw = &pf->hw;
827 u32 reg, total_qps = 0;
828 u32 qps, num_tc = 1; /* VF has at least one traffic class */
835 for (i = 0; i < num_tc; i++) {
836 if (vf->adq_enabled) {
837 qps = vf->ch[i].num_qps;
838 vsi_id = vf->ch[i].vsi_id;
840 qps = pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
841 vsi_id = vf->lan_vsi_id;
844 for (j = 0; j < qps; j++) {
845 qid = i40e_vc_get_pf_queue_id(vf, vsi_id, j);
847 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
848 wr32(hw, I40E_VPLAN_QTABLE(total_qps, vf->vf_id),
856 * i40e_enable_vf_mappings
857 * @vf: pointer to the VF info
861 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
863 struct i40e_pf *pf = vf->pf;
864 struct i40e_hw *hw = &pf->hw;
867 /* Tell the hardware we're using noncontiguous mapping. HW requires
868 * that VF queues be mapped using this method, even when they are
869 * contiguous in real life
871 i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
872 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
874 /* enable VF vplan_qtable mappings */
875 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
876 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
878 i40e_map_pf_to_vf_queues(vf);
879 i40e_map_pf_queues_to_vsi(vf);
885 * i40e_disable_vf_mappings
886 * @vf: pointer to the VF info
888 * disable VF mappings
890 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
892 struct i40e_pf *pf = vf->pf;
893 struct i40e_hw *hw = &pf->hw;
896 /* disable qp mappings */
897 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
898 for (i = 0; i < I40E_MAX_VSI_QP; i++)
899 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
900 I40E_QUEUE_END_OF_LIST);
906 * @vf: pointer to the VF info
910 static void i40e_free_vf_res(struct i40e_vf *vf)
912 struct i40e_pf *pf = vf->pf;
913 struct i40e_hw *hw = &pf->hw;
917 /* Start by disabling VF's configuration API to prevent the OS from
918 * accessing the VF's VSI after it's freed / invalidated.
920 clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
922 /* It's possible the VF had requeuested more queues than the default so
923 * do the accounting here when we're about to free them.
925 if (vf->num_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF) {
926 pf->queues_left += vf->num_queue_pairs -
927 I40E_DEFAULT_QUEUES_PER_VF;
930 /* free vsi & disconnect it from the parent uplink */
931 if (vf->lan_vsi_idx) {
932 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
938 /* do the accounting and remove additional ADq VSI's */
939 if (vf->adq_enabled && vf->ch[0].vsi_idx) {
940 for (j = 0; j < vf->num_tc; j++) {
941 /* At this point VSI0 is already released so don't
942 * release it again and only clear their values in
943 * structure variables
946 i40e_vsi_release(pf->vsi[vf->ch[j].vsi_idx]);
947 vf->ch[j].vsi_idx = 0;
948 vf->ch[j].vsi_id = 0;
951 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
953 /* disable interrupts so the VF starts in a known state */
954 for (i = 0; i < msix_vf; i++) {
955 /* format is same for both registers */
957 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
959 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
962 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
966 /* clear the irq settings */
967 for (i = 0; i < msix_vf; i++) {
968 /* format is same for both registers */
970 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
972 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
975 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
976 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
977 wr32(hw, reg_idx, reg);
980 /* reset some of the state variables keeping track of the resources */
981 vf->num_queue_pairs = 0;
982 clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
983 clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
988 * @vf: pointer to the VF info
990 * allocate VF resources
992 static int i40e_alloc_vf_res(struct i40e_vf *vf)
994 struct i40e_pf *pf = vf->pf;
995 int total_queue_pairs = 0;
998 if (vf->num_req_queues &&
999 vf->num_req_queues <= pf->queues_left + I40E_DEFAULT_QUEUES_PER_VF)
1000 pf->num_vf_qps = vf->num_req_queues;
1002 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
1004 /* allocate hw vsi context & associated resources */
1005 ret = i40e_alloc_vsi_res(vf, 0);
1008 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
1010 /* allocate additional VSIs based on tc information for ADq */
1011 if (vf->adq_enabled) {
1012 if (pf->queues_left >=
1013 (I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF)) {
1014 /* TC 0 always belongs to VF VSI */
1015 for (idx = 1; idx < vf->num_tc; idx++) {
1016 ret = i40e_alloc_vsi_res(vf, idx);
1020 /* send correct number of queues */
1021 total_queue_pairs = I40E_MAX_VF_QUEUES;
1023 dev_info(&pf->pdev->dev, "VF %d: Not enough queues to allocate, disabling ADq\n",
1025 vf->adq_enabled = false;
1029 /* We account for each VF to get a default number of queue pairs. If
1030 * the VF has now requested more, we need to account for that to make
1031 * certain we never request more queues than we actually have left in
1034 if (total_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF)
1036 total_queue_pairs - I40E_DEFAULT_QUEUES_PER_VF;
1039 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
1041 clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
1043 /* store the total qps number for the runtime
1046 vf->num_queue_pairs = total_queue_pairs;
1048 /* VF is now completely initialized */
1049 set_bit(I40E_VF_STATE_INIT, &vf->vf_states);
1053 i40e_free_vf_res(vf);
1058 #define VF_DEVICE_STATUS 0xAA
1059 #define VF_TRANS_PENDING_MASK 0x20
1061 * i40e_quiesce_vf_pci
1062 * @vf: pointer to the VF structure
1064 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
1065 * if the transactions never clear.
1067 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
1069 struct i40e_pf *pf = vf->pf;
1070 struct i40e_hw *hw = &pf->hw;
1074 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
1076 wr32(hw, I40E_PF_PCI_CIAA,
1077 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
1078 for (i = 0; i < 100; i++) {
1079 reg = rd32(hw, I40E_PF_PCI_CIAD);
1080 if ((reg & VF_TRANS_PENDING_MASK) == 0)
1088 * i40e_trigger_vf_reset
1089 * @vf: pointer to the VF structure
1090 * @flr: VFLR was issued or not
1092 * Trigger hardware to start a reset for a particular VF. Expects the caller
1093 * to wait the proper amount of time to allow hardware to reset the VF before
1094 * it cleans up and restores VF functionality.
1096 static void i40e_trigger_vf_reset(struct i40e_vf *vf, bool flr)
1098 struct i40e_pf *pf = vf->pf;
1099 struct i40e_hw *hw = &pf->hw;
1100 u32 reg, reg_idx, bit_idx;
1103 clear_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
1105 /* Disable VF's configuration API during reset. The flag is re-enabled
1106 * in i40e_alloc_vf_res(), when it's safe again to access VF's VSI.
1107 * It's normally disabled in i40e_free_vf_res(), but it's safer
1108 * to do it earlier to give some time to finish to any VF config
1109 * functions that may still be running at this point.
1111 clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
1113 /* In the case of a VFLR, the HW has already reset the VF and we
1114 * just need to clean up, so don't hit the VFRTRIG register.
1117 /* reset VF using VPGEN_VFRTRIG reg */
1118 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
1119 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
1120 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
1123 /* clear the VFLR bit in GLGEN_VFLRSTAT */
1124 reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
1125 bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
1126 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
1129 if (i40e_quiesce_vf_pci(vf))
1130 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
1135 * i40e_cleanup_reset_vf
1136 * @vf: pointer to the VF structure
1138 * Cleanup a VF after the hardware reset is finished. Expects the caller to
1139 * have verified whether the reset is finished properly, and ensure the
1140 * minimum amount of wait time has passed.
1142 static void i40e_cleanup_reset_vf(struct i40e_vf *vf)
1144 struct i40e_pf *pf = vf->pf;
1145 struct i40e_hw *hw = &pf->hw;
1148 /* free VF resources to begin resetting the VSI state */
1149 i40e_free_vf_res(vf);
1151 /* Enable hardware by clearing the reset bit in the VPGEN_VFRTRIG reg.
1152 * By doing this we allow HW to access VF memory at any point. If we
1153 * did it any sooner, HW could access memory while it was being freed
1154 * in i40e_free_vf_res(), causing an IOMMU fault.
1156 * On the other hand, this needs to be done ASAP, because the VF driver
1157 * is waiting for this to happen and may report a timeout. It's
1158 * harmless, but it gets logged into Guest OS kernel log, so best avoid
1161 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
1162 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
1163 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
1165 /* reallocate VF resources to finish resetting the VSI state */
1166 if (!i40e_alloc_vf_res(vf)) {
1167 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1168 i40e_enable_vf_mappings(vf);
1169 set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
1170 clear_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
1171 /* Do not notify the client during VF init */
1172 if (!test_and_clear_bit(I40E_VF_STATE_PRE_ENABLE,
1174 i40e_notify_client_of_vf_reset(pf, abs_vf_id);
1178 /* Tell the VF driver the reset is done. This needs to be done only
1179 * after VF has been fully initialized, because the VF driver may
1180 * request resources immediately after setting this flag.
1182 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
1187 * @vf: pointer to the VF structure
1188 * @flr: VFLR was issued or not
1190 * Returns true if the VF is reset, false otherwise.
1192 bool i40e_reset_vf(struct i40e_vf *vf, bool flr)
1194 struct i40e_pf *pf = vf->pf;
1195 struct i40e_hw *hw = &pf->hw;
1200 /* If the VFs have been disabled, this means something else is
1201 * resetting the VF, so we shouldn't continue.
1203 if (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
1206 i40e_trigger_vf_reset(vf, flr);
1208 /* poll VPGEN_VFRSTAT reg to make sure
1209 * that reset is complete
1211 for (i = 0; i < 10; i++) {
1212 /* VF reset requires driver to first reset the VF and then
1213 * poll the status register to make sure that the reset
1214 * completed successfully. Due to internal HW FIFO flushes,
1215 * we must wait 10ms before the register will be valid.
1217 usleep_range(10000, 20000);
1218 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
1219 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
1226 usleep_range(10000, 20000);
1229 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
1231 usleep_range(10000, 20000);
1233 /* On initial reset, we don't have any queues to disable */
1234 if (vf->lan_vsi_idx != 0)
1235 i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
1237 i40e_cleanup_reset_vf(vf);
1240 clear_bit(__I40E_VF_DISABLE, pf->state);
1246 * i40e_reset_all_vfs
1247 * @pf: pointer to the PF structure
1248 * @flr: VFLR was issued or not
1250 * Reset all allocated VFs in one go. First, tell the hardware to reset each
1251 * VF, then do all the waiting in one chunk, and finally finish restoring each
1252 * VF after the wait. This is useful during PF routines which need to reset
1253 * all VFs, as otherwise it must perform these resets in a serialized fashion.
1255 * Returns true if any VFs were reset, and false otherwise.
1257 bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
1259 struct i40e_hw *hw = &pf->hw;
1264 /* If we don't have any VFs, then there is nothing to reset */
1265 if (!pf->num_alloc_vfs)
1268 /* If VFs have been disabled, there is no need to reset */
1269 if (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
1272 /* Begin reset on all VFs at once */
1273 for (v = 0; v < pf->num_alloc_vfs; v++)
1274 i40e_trigger_vf_reset(&pf->vf[v], flr);
1276 /* HW requires some time to make sure it can flush the FIFO for a VF
1277 * when it resets it. Poll the VPGEN_VFRSTAT register for each VF in
1278 * sequence to make sure that it has completed. We'll keep track of
1279 * the VFs using a simple iterator that increments once that VF has
1280 * finished resetting.
1282 for (i = 0, v = 0; i < 10 && v < pf->num_alloc_vfs; i++) {
1283 usleep_range(10000, 20000);
1285 /* Check each VF in sequence, beginning with the VF to fail
1286 * the previous check.
1288 while (v < pf->num_alloc_vfs) {
1290 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
1291 if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK))
1294 /* If the current VF has finished resetting, move on
1295 * to the next VF in sequence.
1302 usleep_range(10000, 20000);
1304 /* Display a warning if at least one VF didn't manage to reset in
1305 * time, but continue on with the operation.
1307 if (v < pf->num_alloc_vfs)
1308 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
1310 usleep_range(10000, 20000);
1312 /* Begin disabling all the rings associated with VFs, but do not wait
1315 for (v = 0; v < pf->num_alloc_vfs; v++) {
1316 /* On initial reset, we don't have any queues to disable */
1317 if (pf->vf[v].lan_vsi_idx == 0)
1320 i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[v].lan_vsi_idx]);
1323 /* Now that we've notified HW to disable all of the VF rings, wait
1324 * until they finish.
1326 for (v = 0; v < pf->num_alloc_vfs; v++) {
1327 /* On initial reset, we don't have any queues to disable */
1328 if (pf->vf[v].lan_vsi_idx == 0)
1331 i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[v].lan_vsi_idx]);
1334 /* Hw may need up to 50ms to finish disabling the RX queues. We
1335 * minimize the wait by delaying only once for all VFs.
1339 /* Finish the reset on each VF */
1340 for (v = 0; v < pf->num_alloc_vfs; v++)
1341 i40e_cleanup_reset_vf(&pf->vf[v]);
1344 clear_bit(__I40E_VF_DISABLE, pf->state);
1351 * @pf: pointer to the PF structure
1355 void i40e_free_vfs(struct i40e_pf *pf)
1357 struct i40e_hw *hw = &pf->hw;
1358 u32 reg_idx, bit_idx;
1363 while (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
1364 usleep_range(1000, 2000);
1366 i40e_notify_client_of_vf_enable(pf, 0);
1368 /* Amortize wait time by stopping all VFs at the same time */
1369 for (i = 0; i < pf->num_alloc_vfs; i++) {
1370 if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
1373 i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[i].lan_vsi_idx]);
1376 for (i = 0; i < pf->num_alloc_vfs; i++) {
1377 if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
1380 i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[i].lan_vsi_idx]);
1383 /* Disable IOV before freeing resources. This lets any VF drivers
1384 * running in the host get themselves cleaned up before we yank
1385 * the carpet out from underneath their feet.
1387 if (!pci_vfs_assigned(pf->pdev))
1388 pci_disable_sriov(pf->pdev);
1390 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
1392 /* free up VF resources */
1393 tmp = pf->num_alloc_vfs;
1394 pf->num_alloc_vfs = 0;
1395 for (i = 0; i < tmp; i++) {
1396 if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
1397 i40e_free_vf_res(&pf->vf[i]);
1398 /* disable qp mappings */
1399 i40e_disable_vf_mappings(&pf->vf[i]);
1405 /* This check is for when the driver is unloaded while VFs are
1406 * assigned. Setting the number of VFs to 0 through sysfs is caught
1407 * before this function ever gets called.
1409 if (!pci_vfs_assigned(pf->pdev)) {
1410 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
1411 * work correctly when SR-IOV gets re-enabled.
1413 for (vf_id = 0; vf_id < tmp; vf_id++) {
1414 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1415 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1416 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
1419 clear_bit(__I40E_VF_DISABLE, pf->state);
1422 #ifdef CONFIG_PCI_IOV
1425 * @pf: pointer to the PF structure
1426 * @num_alloc_vfs: number of VFs to allocate
1428 * allocate VF resources
1430 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
1432 struct i40e_vf *vfs;
1435 /* Disable interrupt 0 so we don't try to handle the VFLR. */
1436 i40e_irq_dynamic_disable_icr0(pf);
1438 /* Check to see if we're just allocating resources for extant VFs */
1439 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
1440 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
1442 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1443 pf->num_alloc_vfs = 0;
1447 /* allocate memory */
1448 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
1455 /* apply default profile */
1456 for (i = 0; i < num_alloc_vfs; i++) {
1458 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
1461 /* assign default capabilities */
1462 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
1463 vfs[i].spoofchk = true;
1465 set_bit(I40E_VF_STATE_PRE_ENABLE, &vfs[i].vf_states);
1468 pf->num_alloc_vfs = num_alloc_vfs;
1470 /* VF resources get allocated during reset */
1471 i40e_reset_all_vfs(pf, false);
1473 i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
1479 /* Re-enable interrupt 0. */
1480 i40e_irq_dynamic_enable_icr0(pf);
1486 * i40e_pci_sriov_enable
1487 * @pdev: pointer to a pci_dev structure
1488 * @num_vfs: number of VFs to allocate
1490 * Enable or change the number of VFs
1492 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
1494 #ifdef CONFIG_PCI_IOV
1495 struct i40e_pf *pf = pci_get_drvdata(pdev);
1496 int pre_existing_vfs = pci_num_vf(pdev);
1499 if (test_bit(__I40E_TESTING, pf->state)) {
1500 dev_warn(&pdev->dev,
1501 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1506 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1508 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1511 if (num_vfs > pf->num_req_vfs) {
1512 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1513 num_vfs, pf->num_req_vfs);
1518 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
1519 err = i40e_alloc_vfs(pf, num_vfs);
1521 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1535 * i40e_pci_sriov_configure
1536 * @pdev: pointer to a pci_dev structure
1537 * @num_vfs: number of VFs to allocate
1539 * Enable or change the number of VFs. Called when the user updates the number
1542 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1544 struct i40e_pf *pf = pci_get_drvdata(pdev);
1547 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1548 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1549 i40e_do_reset_safe(pf, I40E_PF_RESET_FLAG);
1551 return i40e_pci_sriov_enable(pdev, num_vfs);
1554 if (!pci_vfs_assigned(pf->pdev)) {
1556 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1557 i40e_do_reset_safe(pf, I40E_PF_RESET_FLAG);
1559 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1565 /***********************virtual channel routines******************/
1568 * i40e_vc_send_msg_to_vf
1569 * @vf: pointer to the VF info
1570 * @v_opcode: virtual channel opcode
1571 * @v_retval: virtual channel return value
1572 * @msg: pointer to the msg buffer
1573 * @msglen: msg length
1577 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1578 u32 v_retval, u8 *msg, u16 msglen)
1585 /* validate the request */
1586 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1591 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1593 /* single place to detect unsuccessful return values */
1595 vf->num_invalid_msgs++;
1596 dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
1597 vf->vf_id, v_opcode, v_retval);
1598 if (vf->num_invalid_msgs >
1599 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1600 dev_err(&pf->pdev->dev,
1601 "Number of invalid messages exceeded for VF %d\n",
1603 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1604 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
1607 vf->num_valid_msgs++;
1608 /* reset the invalid counter, if a valid message is received. */
1609 vf->num_invalid_msgs = 0;
1612 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1615 dev_info(&pf->pdev->dev,
1616 "Unable to send the message to VF %d aq_err %d\n",
1617 vf->vf_id, pf->hw.aq.asq_last_status);
1625 * i40e_vc_send_resp_to_vf
1626 * @vf: pointer to the VF info
1627 * @opcode: operation code
1628 * @retval: return value
1630 * send resp msg to VF
1632 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1633 enum virtchnl_ops opcode,
1636 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1640 * i40e_vc_get_version_msg
1641 * @vf: pointer to the VF info
1643 * called from the VF to request the API version used by the PF
1645 static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
1647 struct virtchnl_version_info info = {
1648 VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
1651 vf->vf_ver = *(struct virtchnl_version_info *)msg;
1652 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1653 if (VF_IS_V10(&vf->vf_ver))
1654 info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
1655 return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
1656 I40E_SUCCESS, (u8 *)&info,
1657 sizeof(struct virtchnl_version_info));
1661 * i40e_del_qch - delete all the additional VSIs created as a part of ADq
1662 * @vf: pointer to VF structure
1664 static void i40e_del_qch(struct i40e_vf *vf)
1666 struct i40e_pf *pf = vf->pf;
1669 /* first element in the array belongs to primary VF VSI and we shouldn't
1670 * delete it. We should however delete the rest of the VSIs created
1672 for (i = 1; i < vf->num_tc; i++) {
1673 if (vf->ch[i].vsi_idx) {
1674 i40e_vsi_release(pf->vsi[vf->ch[i].vsi_idx]);
1675 vf->ch[i].vsi_idx = 0;
1676 vf->ch[i].vsi_id = 0;
1682 * i40e_vc_get_vf_resources_msg
1683 * @vf: pointer to the VF info
1684 * @msg: pointer to the msg buffer
1685 * @msglen: msg length
1687 * called from the VF to request its resources
1689 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1691 struct virtchnl_vf_resource *vfres = NULL;
1692 struct i40e_pf *pf = vf->pf;
1693 i40e_status aq_ret = 0;
1694 struct i40e_vsi *vsi;
1699 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
1700 aq_ret = I40E_ERR_PARAM;
1704 len = (sizeof(struct virtchnl_vf_resource) +
1705 sizeof(struct virtchnl_vsi_resource) * num_vsis);
1707 vfres = kzalloc(len, GFP_KERNEL);
1709 aq_ret = I40E_ERR_NO_MEMORY;
1713 if (VF_IS_V11(&vf->vf_ver))
1714 vf->driver_caps = *(u32 *)msg;
1716 vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
1717 VIRTCHNL_VF_OFFLOAD_RSS_REG |
1718 VIRTCHNL_VF_OFFLOAD_VLAN;
1720 vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
1721 vsi = pf->vsi[vf->lan_vsi_idx];
1722 if (!vsi->info.pvid)
1723 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
1725 if (i40e_vf_client_capable(pf, vf->vf_id) &&
1726 (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_IWARP)) {
1727 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_IWARP;
1728 set_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states);
1730 clear_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states);
1733 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1734 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
1736 if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
1737 (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ))
1738 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1740 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
1743 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
1744 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1745 vfres->vf_cap_flags |=
1746 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
1749 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
1750 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
1752 if ((pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE) &&
1753 (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM))
1754 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
1756 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) {
1757 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
1758 dev_err(&pf->pdev->dev,
1759 "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
1761 aq_ret = I40E_ERR_PARAM;
1764 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1767 if (pf->hw_features & I40E_HW_WB_ON_ITR_CAPABLE) {
1768 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1769 vfres->vf_cap_flags |=
1770 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
1773 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
1774 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
1776 if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)
1777 vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADQ;
1779 vfres->num_vsis = num_vsis;
1780 vfres->num_queue_pairs = vf->num_queue_pairs;
1781 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1782 vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
1783 vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
1785 if (vf->lan_vsi_idx) {
1786 vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
1787 vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
1788 vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
1789 /* VFs only use TC 0 */
1790 vfres->vsi_res[0].qset_handle
1791 = le16_to_cpu(vsi->info.qs_handle[0]);
1792 ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
1793 vf->default_lan_addr.addr);
1795 set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
1798 /* send the response back to the VF */
1799 ret = i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES,
1800 aq_ret, (u8 *)vfres, len);
1807 * i40e_vc_reset_vf_msg
1808 * @vf: pointer to the VF info
1809 * @msg: pointer to the msg buffer
1810 * @msglen: msg length
1812 * called from the VF to reset itself,
1813 * unlike other virtchnl messages, PF driver
1814 * doesn't send the response back to the VF
1816 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1818 if (test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
1819 i40e_reset_vf(vf, false);
1823 * i40e_getnum_vf_vsi_vlan_filters
1824 * @vsi: pointer to the vsi
1826 * called to get the number of VLANs offloaded on this VF
1828 static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
1830 struct i40e_mac_filter *f;
1831 int num_vlans = 0, bkt;
1833 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1834 if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
1842 * i40e_vc_config_promiscuous_mode_msg
1843 * @vf: pointer to the VF info
1844 * @msg: pointer to the msg buffer
1845 * @msglen: msg length
1847 * called from the VF to configure the promiscuous mode of
1850 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1851 u8 *msg, u16 msglen)
1853 struct virtchnl_promisc_info *info =
1854 (struct virtchnl_promisc_info *)msg;
1855 struct i40e_pf *pf = vf->pf;
1856 struct i40e_hw *hw = &pf->hw;
1857 struct i40e_mac_filter *f;
1858 i40e_status aq_ret = 0;
1859 bool allmulti = false;
1860 struct i40e_vsi *vsi;
1861 bool alluni = false;
1865 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1866 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
1867 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1869 aq_ret = I40E_ERR_PARAM;
1872 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
1873 dev_err(&pf->pdev->dev,
1874 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1876 /* Lie to the VF on purpose. */
1880 /* Multicast promiscuous handling*/
1881 if (info->flags & FLAG_VF_MULTICAST_PROMISC)
1884 if (vf->port_vlan_id) {
1885 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
1889 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1890 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1891 if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1893 aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
1898 aq_err = pf->hw.aq.asq_last_status;
1900 dev_err(&pf->pdev->dev,
1901 "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1903 i40e_stat_str(&pf->hw, aq_ret),
1904 i40e_aq_str(&pf->hw, aq_err));
1909 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1911 aq_err = pf->hw.aq.asq_last_status;
1913 dev_err(&pf->pdev->dev,
1914 "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1916 i40e_stat_str(&pf->hw, aq_ret),
1917 i40e_aq_str(&pf->hw, aq_err));
1923 dev_info(&pf->pdev->dev,
1924 "VF %d successfully set multicast promiscuous mode\n",
1927 set_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
1929 clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
1932 if (info->flags & FLAG_VF_UNICAST_PROMISC)
1934 if (vf->port_vlan_id) {
1935 aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
1939 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
1940 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
1941 if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
1943 aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
1948 aq_err = pf->hw.aq.asq_last_status;
1950 dev_err(&pf->pdev->dev,
1951 "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1953 i40e_stat_str(&pf->hw, aq_ret),
1954 i40e_aq_str(&pf->hw, aq_err));
1957 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1960 aq_err = pf->hw.aq.asq_last_status;
1962 dev_err(&pf->pdev->dev,
1963 "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1964 vf->vf_id, info->flags,
1965 i40e_stat_str(&pf->hw, aq_ret),
1966 i40e_aq_str(&pf->hw, aq_err));
1972 dev_info(&pf->pdev->dev,
1973 "VF %d successfully set unicast promiscuous mode\n",
1976 set_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
1978 clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
1982 /* send the response to the VF */
1983 return i40e_vc_send_resp_to_vf(vf,
1984 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1989 * i40e_vc_config_queues_msg
1990 * @vf: pointer to the VF info
1991 * @msg: pointer to the msg buffer
1992 * @msglen: msg length
1994 * called from the VF to configure the rx/tx
1997 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1999 struct virtchnl_vsi_queue_config_info *qci =
2000 (struct virtchnl_vsi_queue_config_info *)msg;
2001 struct virtchnl_queue_pair_info *qpi;
2002 struct i40e_pf *pf = vf->pf;
2003 u16 vsi_id, vsi_queue_id = 0;
2004 i40e_status aq_ret = 0;
2005 int i, j = 0, idx = 0;
2007 vsi_id = qci->vsi_id;
2009 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2010 aq_ret = I40E_ERR_PARAM;
2014 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2015 aq_ret = I40E_ERR_PARAM;
2019 for (i = 0; i < qci->num_queue_pairs; i++) {
2020 qpi = &qci->qpair[i];
2022 if (!vf->adq_enabled) {
2023 vsi_queue_id = qpi->txq.queue_id;
2025 if (qpi->txq.vsi_id != qci->vsi_id ||
2026 qpi->rxq.vsi_id != qci->vsi_id ||
2027 qpi->rxq.queue_id != vsi_queue_id) {
2028 aq_ret = I40E_ERR_PARAM;
2033 if (!i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
2034 aq_ret = I40E_ERR_PARAM;
2038 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
2040 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
2042 aq_ret = I40E_ERR_PARAM;
2046 /* For ADq there can be up to 4 VSIs with max 4 queues each.
2047 * VF does not know about these additional VSIs and all
2048 * it cares is about its own queues. PF configures these queues
2049 * to its appropriate VSIs based on TC mapping
2051 if (vf->adq_enabled) {
2052 if (j == (vf->ch[idx].num_qps - 1)) {
2054 j = 0; /* resetting the queue count */
2060 vsi_id = vf->ch[idx].vsi_id;
2063 /* set vsi num_queue_pairs in use to num configured by VF */
2064 if (!vf->adq_enabled) {
2065 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs =
2066 qci->num_queue_pairs;
2068 for (i = 0; i < vf->num_tc; i++)
2069 pf->vsi[vf->ch[i].vsi_idx]->num_queue_pairs =
2074 /* send the response to the VF */
2075 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
2080 * i40e_validate_queue_map
2082 * @queuemap: Tx or Rx queue map
2084 * check if Tx or Rx queue map is valid
2086 static int i40e_validate_queue_map(struct i40e_vf *vf, u16 vsi_id,
2087 unsigned long queuemap)
2089 u16 vsi_queue_id, queue_id;
2091 for_each_set_bit(vsi_queue_id, &queuemap, I40E_MAX_VSI_QP) {
2092 if (vf->adq_enabled) {
2093 vsi_id = vf->ch[vsi_queue_id / I40E_MAX_VF_VSI].vsi_id;
2094 queue_id = (vsi_queue_id % I40E_DEFAULT_QUEUES_PER_VF);
2096 queue_id = vsi_queue_id;
2099 if (!i40e_vc_isvalid_queue_id(vf, vsi_id, queue_id))
2107 * i40e_vc_config_irq_map_msg
2108 * @vf: pointer to the VF info
2109 * @msg: pointer to the msg buffer
2110 * @msglen: msg length
2112 * called from the VF to configure the irq to
2115 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2117 struct virtchnl_irq_map_info *irqmap_info =
2118 (struct virtchnl_irq_map_info *)msg;
2119 struct virtchnl_vector_map *map;
2120 u16 vsi_id, vector_id;
2121 i40e_status aq_ret = 0;
2124 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2125 aq_ret = I40E_ERR_PARAM;
2129 for (i = 0; i < irqmap_info->num_vectors; i++) {
2130 map = &irqmap_info->vecmap[i];
2131 vector_id = map->vector_id;
2132 vsi_id = map->vsi_id;
2133 /* validate msg params */
2134 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
2135 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2136 aq_ret = I40E_ERR_PARAM;
2140 if (i40e_validate_queue_map(vf, vsi_id, map->rxq_map)) {
2141 aq_ret = I40E_ERR_PARAM;
2145 if (i40e_validate_queue_map(vf, vsi_id, map->txq_map)) {
2146 aq_ret = I40E_ERR_PARAM;
2150 i40e_config_irq_link_list(vf, vsi_id, map);
2153 /* send the response to the VF */
2154 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP,
2159 * i40e_vc_enable_queues_msg
2160 * @vf: pointer to the VF info
2161 * @msg: pointer to the msg buffer
2162 * @msglen: msg length
2164 * called from the VF to enable all or specific queue(s)
2166 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2168 struct virtchnl_queue_select *vqs =
2169 (struct virtchnl_queue_select *)msg;
2170 struct i40e_pf *pf = vf->pf;
2171 u16 vsi_id = vqs->vsi_id;
2172 i40e_status aq_ret = 0;
2175 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2176 aq_ret = I40E_ERR_PARAM;
2180 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2181 aq_ret = I40E_ERR_PARAM;
2185 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
2186 aq_ret = I40E_ERR_PARAM;
2190 if (i40e_vsi_start_rings(pf->vsi[vf->lan_vsi_idx]))
2191 aq_ret = I40E_ERR_TIMEOUT;
2193 /* need to start the rings for additional ADq VSI's as well */
2194 if (vf->adq_enabled) {
2195 /* zero belongs to LAN VSI */
2196 for (i = 1; i < vf->num_tc; i++) {
2197 if (i40e_vsi_start_rings(pf->vsi[vf->ch[i].vsi_idx]))
2198 aq_ret = I40E_ERR_TIMEOUT;
2203 /* send the response to the VF */
2204 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES,
2209 * i40e_vc_disable_queues_msg
2210 * @vf: pointer to the VF info
2211 * @msg: pointer to the msg buffer
2212 * @msglen: msg length
2214 * called from the VF to disable all or specific
2217 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2219 struct virtchnl_queue_select *vqs =
2220 (struct virtchnl_queue_select *)msg;
2221 struct i40e_pf *pf = vf->pf;
2222 i40e_status aq_ret = 0;
2224 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2225 aq_ret = I40E_ERR_PARAM;
2229 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
2230 aq_ret = I40E_ERR_PARAM;
2234 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
2235 aq_ret = I40E_ERR_PARAM;
2239 i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
2242 /* send the response to the VF */
2243 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES,
2248 * i40e_vc_request_queues_msg
2249 * @vf: pointer to the VF info
2250 * @msg: pointer to the msg buffer
2251 * @msglen: msg length
2253 * VFs get a default number of queues but can use this message to request a
2254 * different number. If the request is successful, PF will reset the VF and
2255 * return 0. If unsuccessful, PF will send message informing VF of number of
2256 * available queues and return result of sending VF a message.
2258 static int i40e_vc_request_queues_msg(struct i40e_vf *vf, u8 *msg, int msglen)
2260 struct virtchnl_vf_res_request *vfres =
2261 (struct virtchnl_vf_res_request *)msg;
2262 int req_pairs = vfres->num_queue_pairs;
2263 int cur_pairs = vf->num_queue_pairs;
2264 struct i40e_pf *pf = vf->pf;
2266 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
2269 if (req_pairs <= 0) {
2270 dev_err(&pf->pdev->dev,
2271 "VF %d tried to request %d queues. Ignoring.\n",
2272 vf->vf_id, req_pairs);
2273 } else if (req_pairs > I40E_MAX_VF_QUEUES) {
2274 dev_err(&pf->pdev->dev,
2275 "VF %d tried to request more than %d queues.\n",
2277 I40E_MAX_VF_QUEUES);
2278 vfres->num_queue_pairs = I40E_MAX_VF_QUEUES;
2279 } else if (req_pairs - cur_pairs > pf->queues_left) {
2280 dev_warn(&pf->pdev->dev,
2281 "VF %d requested %d more queues, but only %d left.\n",
2283 req_pairs - cur_pairs,
2285 vfres->num_queue_pairs = pf->queues_left + cur_pairs;
2287 /* successful request */
2288 vf->num_req_queues = req_pairs;
2289 i40e_vc_notify_vf_reset(vf);
2290 i40e_reset_vf(vf, false);
2294 return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES, 0,
2295 (u8 *)vfres, sizeof(*vfres));
2299 * i40e_vc_get_stats_msg
2300 * @vf: pointer to the VF info
2301 * @msg: pointer to the msg buffer
2302 * @msglen: msg length
2304 * called from the VF to get vsi stats
2306 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2308 struct virtchnl_queue_select *vqs =
2309 (struct virtchnl_queue_select *)msg;
2310 struct i40e_pf *pf = vf->pf;
2311 struct i40e_eth_stats stats;
2312 i40e_status aq_ret = 0;
2313 struct i40e_vsi *vsi;
2315 memset(&stats, 0, sizeof(struct i40e_eth_stats));
2317 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2318 aq_ret = I40E_ERR_PARAM;
2322 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
2323 aq_ret = I40E_ERR_PARAM;
2327 vsi = pf->vsi[vf->lan_vsi_idx];
2329 aq_ret = I40E_ERR_PARAM;
2332 i40e_update_eth_stats(vsi);
2333 stats = vsi->eth_stats;
2336 /* send the response back to the VF */
2337 return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, aq_ret,
2338 (u8 *)&stats, sizeof(stats));
2341 /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
2342 #define I40E_VC_MAX_MAC_ADDR_PER_VF 12
2343 #define I40E_VC_MAX_VLAN_PER_VF 8
2346 * i40e_check_vf_permission
2347 * @vf: pointer to the VF info
2348 * @al: MAC address list from virtchnl
2350 * Check that the given list of MAC addresses is allowed. Will return -EPERM
2351 * if any address in the list is not valid. Checks the following conditions:
2353 * 1) broadcast and zero addresses are never valid
2354 * 2) unicast addresses are not allowed if the VMM has administratively set
2355 * the VF MAC address, unless the VF is marked as privileged.
2356 * 3) There is enough space to add all the addresses.
2358 * Note that to guarantee consistency, it is expected this function be called
2359 * while holding the mac_filter_hash_lock, as otherwise the current number of
2360 * addresses might not be accurate.
2362 static inline int i40e_check_vf_permission(struct i40e_vf *vf,
2363 struct virtchnl_ether_addr_list *al)
2365 struct i40e_pf *pf = vf->pf;
2368 /* If this VF is not privileged, then we can't add more than a limited
2369 * number of addresses. Check to make sure that the additions do not
2370 * push us over the limit.
2372 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
2373 (vf->num_mac + al->num_elements) > I40E_VC_MAX_MAC_ADDR_PER_VF) {
2374 dev_err(&pf->pdev->dev,
2375 "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2379 for (i = 0; i < al->num_elements; i++) {
2380 u8 *addr = al->list[i].addr;
2382 if (is_broadcast_ether_addr(addr) ||
2383 is_zero_ether_addr(addr)) {
2384 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
2386 return I40E_ERR_INVALID_MAC_ADDR;
2389 /* If the host VMM administrator has set the VF MAC address
2390 * administratively via the ndo_set_vf_mac command then deny
2391 * permission to the VF to add or delete unicast MAC addresses.
2392 * Unless the VF is privileged and then it can do whatever.
2393 * The VF may request to set the MAC address filter already
2394 * assigned to it so do not return an error in that case.
2396 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
2397 !is_multicast_ether_addr(addr) && vf->pf_set_mac &&
2398 !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
2399 dev_err(&pf->pdev->dev,
2400 "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
2409 * i40e_vc_add_mac_addr_msg
2410 * @vf: pointer to the VF info
2411 * @msg: pointer to the msg buffer
2412 * @msglen: msg length
2414 * add guest mac address filter
2416 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2418 struct virtchnl_ether_addr_list *al =
2419 (struct virtchnl_ether_addr_list *)msg;
2420 struct i40e_pf *pf = vf->pf;
2421 struct i40e_vsi *vsi = NULL;
2422 u16 vsi_id = al->vsi_id;
2423 i40e_status ret = 0;
2426 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2427 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2428 ret = I40E_ERR_PARAM;
2432 vsi = pf->vsi[vf->lan_vsi_idx];
2434 /* Lock once, because all function inside for loop accesses VSI's
2435 * MAC filter list which needs to be protected using same lock.
2437 spin_lock_bh(&vsi->mac_filter_hash_lock);
2439 ret = i40e_check_vf_permission(vf, al);
2441 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2445 /* add new addresses to the list */
2446 for (i = 0; i < al->num_elements; i++) {
2447 struct i40e_mac_filter *f;
2449 f = i40e_find_mac(vsi, al->list[i].addr);
2451 f = i40e_add_mac_filter(vsi, al->list[i].addr);
2454 dev_err(&pf->pdev->dev,
2455 "Unable to add MAC filter %pM for VF %d\n",
2456 al->list[i].addr, vf->vf_id);
2457 ret = I40E_ERR_PARAM;
2458 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2465 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2467 /* program the updated filter list */
2468 ret = i40e_sync_vsi_filters(vsi);
2470 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
2474 /* send the response to the VF */
2475 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
2480 * i40e_vc_del_mac_addr_msg
2481 * @vf: pointer to the VF info
2482 * @msg: pointer to the msg buffer
2483 * @msglen: msg length
2485 * remove guest mac address filter
2487 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2489 struct virtchnl_ether_addr_list *al =
2490 (struct virtchnl_ether_addr_list *)msg;
2491 struct i40e_pf *pf = vf->pf;
2492 struct i40e_vsi *vsi = NULL;
2493 u16 vsi_id = al->vsi_id;
2494 i40e_status ret = 0;
2497 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2498 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2499 ret = I40E_ERR_PARAM;
2503 for (i = 0; i < al->num_elements; i++) {
2504 if (is_broadcast_ether_addr(al->list[i].addr) ||
2505 is_zero_ether_addr(al->list[i].addr)) {
2506 dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
2507 al->list[i].addr, vf->vf_id);
2508 ret = I40E_ERR_INVALID_MAC_ADDR;
2512 vsi = pf->vsi[vf->lan_vsi_idx];
2514 spin_lock_bh(&vsi->mac_filter_hash_lock);
2515 /* delete addresses from the list */
2516 for (i = 0; i < al->num_elements; i++)
2517 if (i40e_del_mac_filter(vsi, al->list[i].addr)) {
2518 ret = I40E_ERR_INVALID_MAC_ADDR;
2519 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2525 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2527 /* program the updated filter list */
2528 ret = i40e_sync_vsi_filters(vsi);
2530 dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
2534 /* send the response to the VF */
2535 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
2540 * i40e_vc_add_vlan_msg
2541 * @vf: pointer to the VF info
2542 * @msg: pointer to the msg buffer
2543 * @msglen: msg length
2545 * program guest vlan id
2547 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2549 struct virtchnl_vlan_filter_list *vfl =
2550 (struct virtchnl_vlan_filter_list *)msg;
2551 struct i40e_pf *pf = vf->pf;
2552 struct i40e_vsi *vsi = NULL;
2553 u16 vsi_id = vfl->vsi_id;
2554 i40e_status aq_ret = 0;
2557 if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
2558 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2559 dev_err(&pf->pdev->dev,
2560 "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
2563 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2564 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2565 aq_ret = I40E_ERR_PARAM;
2569 for (i = 0; i < vfl->num_elements; i++) {
2570 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2571 aq_ret = I40E_ERR_PARAM;
2572 dev_err(&pf->pdev->dev,
2573 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
2577 vsi = pf->vsi[vf->lan_vsi_idx];
2578 if (vsi->info.pvid) {
2579 aq_ret = I40E_ERR_PARAM;
2583 i40e_vlan_stripping_enable(vsi);
2584 for (i = 0; i < vfl->num_elements; i++) {
2585 /* add new VLAN filter */
2586 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
2590 if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
2591 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2595 if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
2596 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2602 dev_err(&pf->pdev->dev,
2603 "Unable to add VLAN filter %d for VF %d, error %d\n",
2604 vfl->vlan_id[i], vf->vf_id, ret);
2608 /* send the response to the VF */
2609 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, aq_ret);
2613 * i40e_vc_remove_vlan_msg
2614 * @vf: pointer to the VF info
2615 * @msg: pointer to the msg buffer
2616 * @msglen: msg length
2618 * remove programmed guest vlan id
2620 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2622 struct virtchnl_vlan_filter_list *vfl =
2623 (struct virtchnl_vlan_filter_list *)msg;
2624 struct i40e_pf *pf = vf->pf;
2625 struct i40e_vsi *vsi = NULL;
2626 u16 vsi_id = vfl->vsi_id;
2627 i40e_status aq_ret = 0;
2630 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2631 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
2632 aq_ret = I40E_ERR_PARAM;
2636 for (i = 0; i < vfl->num_elements; i++) {
2637 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
2638 aq_ret = I40E_ERR_PARAM;
2643 vsi = pf->vsi[vf->lan_vsi_idx];
2644 if (vsi->info.pvid) {
2645 aq_ret = I40E_ERR_PARAM;
2649 for (i = 0; i < vfl->num_elements; i++) {
2650 i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
2653 if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
2654 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
2658 if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
2659 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
2666 /* send the response to the VF */
2667 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, aq_ret);
2672 * @vf: pointer to the VF info
2673 * @msg: pointer to the msg buffer
2674 * @msglen: msg length
2676 * called from the VF for the iwarp msgs
2678 static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
2680 struct i40e_pf *pf = vf->pf;
2681 int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
2682 i40e_status aq_ret = 0;
2684 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2685 !test_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states)) {
2686 aq_ret = I40E_ERR_PARAM;
2690 i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
2694 /* send the response to the VF */
2695 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_IWARP,
2700 * i40e_vc_iwarp_qvmap_msg
2701 * @vf: pointer to the VF info
2702 * @msg: pointer to the msg buffer
2703 * @msglen: msg length
2704 * @config: config qvmap or release it
2706 * called from the VF for the iwarp msgs
2708 static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
2711 struct virtchnl_iwarp_qvlist_info *qvlist_info =
2712 (struct virtchnl_iwarp_qvlist_info *)msg;
2713 i40e_status aq_ret = 0;
2715 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2716 !test_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states)) {
2717 aq_ret = I40E_ERR_PARAM;
2722 if (i40e_config_iwarp_qvlist(vf, qvlist_info))
2723 aq_ret = I40E_ERR_PARAM;
2725 i40e_release_iwarp_qvlist(vf);
2729 /* send the response to the VF */
2730 return i40e_vc_send_resp_to_vf(vf,
2731 config ? VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP :
2732 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
2737 * i40e_vc_config_rss_key
2738 * @vf: pointer to the VF info
2739 * @msg: pointer to the msg buffer
2740 * @msglen: msg length
2742 * Configure the VF's RSS key
2744 static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
2746 struct virtchnl_rss_key *vrk =
2747 (struct virtchnl_rss_key *)msg;
2748 struct i40e_pf *pf = vf->pf;
2749 struct i40e_vsi *vsi = NULL;
2750 u16 vsi_id = vrk->vsi_id;
2751 i40e_status aq_ret = 0;
2753 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2754 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2755 (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
2756 aq_ret = I40E_ERR_PARAM;
2760 vsi = pf->vsi[vf->lan_vsi_idx];
2761 aq_ret = i40e_config_rss(vsi, vrk->key, NULL, 0);
2763 /* send the response to the VF */
2764 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY,
2769 * i40e_vc_config_rss_lut
2770 * @vf: pointer to the VF info
2771 * @msg: pointer to the msg buffer
2772 * @msglen: msg length
2774 * Configure the VF's RSS LUT
2776 static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
2778 struct virtchnl_rss_lut *vrl =
2779 (struct virtchnl_rss_lut *)msg;
2780 struct i40e_pf *pf = vf->pf;
2781 struct i40e_vsi *vsi = NULL;
2782 u16 vsi_id = vrl->vsi_id;
2783 i40e_status aq_ret = 0;
2785 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
2786 !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
2787 (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
2788 aq_ret = I40E_ERR_PARAM;
2792 vsi = pf->vsi[vf->lan_vsi_idx];
2793 aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
2794 /* send the response to the VF */
2796 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT,
2801 * i40e_vc_get_rss_hena
2802 * @vf: pointer to the VF info
2803 * @msg: pointer to the msg buffer
2804 * @msglen: msg length
2806 * Return the RSS HENA bits allowed by the hardware
2808 static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2810 struct virtchnl_rss_hena *vrh = NULL;
2811 struct i40e_pf *pf = vf->pf;
2812 i40e_status aq_ret = 0;
2815 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2816 aq_ret = I40E_ERR_PARAM;
2819 len = sizeof(struct virtchnl_rss_hena);
2821 vrh = kzalloc(len, GFP_KERNEL);
2823 aq_ret = I40E_ERR_NO_MEMORY;
2827 vrh->hena = i40e_pf_get_default_rss_hena(pf);
2829 /* send the response back to the VF */
2830 aq_ret = i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
2831 aq_ret, (u8 *)vrh, len);
2837 * i40e_vc_set_rss_hena
2838 * @vf: pointer to the VF info
2839 * @msg: pointer to the msg buffer
2840 * @msglen: msg length
2842 * Set the RSS HENA bits for the VF
2844 static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
2846 struct virtchnl_rss_hena *vrh =
2847 (struct virtchnl_rss_hena *)msg;
2848 struct i40e_pf *pf = vf->pf;
2849 struct i40e_hw *hw = &pf->hw;
2850 i40e_status aq_ret = 0;
2852 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2853 aq_ret = I40E_ERR_PARAM;
2856 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)vrh->hena);
2857 i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_id),
2858 (u32)(vrh->hena >> 32));
2860 /* send the response to the VF */
2862 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, aq_ret);
2866 * i40e_vc_enable_vlan_stripping
2867 * @vf: pointer to the VF info
2868 * @msg: pointer to the msg buffer
2869 * @msglen: msg length
2871 * Enable vlan header stripping for the VF
2873 static int i40e_vc_enable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
2876 struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
2877 i40e_status aq_ret = 0;
2879 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2880 aq_ret = I40E_ERR_PARAM;
2884 i40e_vlan_stripping_enable(vsi);
2886 /* send the response to the VF */
2888 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
2893 * i40e_vc_disable_vlan_stripping
2894 * @vf: pointer to the VF info
2895 * @msg: pointer to the msg buffer
2896 * @msglen: msg length
2898 * Disable vlan header stripping for the VF
2900 static int i40e_vc_disable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
2903 struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
2904 i40e_status aq_ret = 0;
2906 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
2907 aq_ret = I40E_ERR_PARAM;
2911 i40e_vlan_stripping_disable(vsi);
2913 /* send the response to the VF */
2915 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
2920 * i40e_validate_cloud_filter
2921 * @mask: mask for TC filter
2922 * @data: data for TC filter
2924 * This function validates cloud filter programmed as TC filter for ADq
2926 static int i40e_validate_cloud_filter(struct i40e_vf *vf,
2927 struct virtchnl_filter *tc_filter)
2929 struct virtchnl_l4_spec mask = tc_filter->mask.tcp_spec;
2930 struct virtchnl_l4_spec data = tc_filter->data.tcp_spec;
2931 struct i40e_pf *pf = vf->pf;
2932 struct i40e_vsi *vsi = NULL;
2933 struct i40e_mac_filter *f;
2934 struct hlist_node *h;
2938 if (!tc_filter->action) {
2939 dev_info(&pf->pdev->dev,
2940 "VF %d: Currently ADq doesn't support Drop Action\n",
2945 /* action_meta is TC number here to which the filter is applied */
2946 if (!tc_filter->action_meta ||
2947 tc_filter->action_meta > I40E_MAX_VF_VSI) {
2948 dev_info(&pf->pdev->dev, "VF %d: Invalid TC number %u\n",
2949 vf->vf_id, tc_filter->action_meta);
2953 /* Check filter if it's programmed for advanced mode or basic mode.
2954 * There are two ADq modes (for VF only),
2955 * 1. Basic mode: intended to allow as many filter options as possible
2956 * to be added to a VF in Non-trusted mode. Main goal is
2957 * to add filters to its own MAC and VLAN id.
2958 * 2. Advanced mode: is for allowing filters to be applied other than
2959 * its own MAC or VLAN. This mode requires the VF to be
2962 if (mask.dst_mac[0] && !mask.dst_ip[0]) {
2963 vsi = pf->vsi[vf->lan_vsi_idx];
2964 f = i40e_find_mac(vsi, data.dst_mac);
2967 dev_info(&pf->pdev->dev,
2968 "Destination MAC %pM doesn't belong to VF %d\n",
2969 data.dst_mac, vf->vf_id);
2974 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f,
2976 if (f->vlan == ntohs(data.vlan_id)) {
2982 dev_info(&pf->pdev->dev,
2983 "VF %d doesn't have any VLAN id %u\n",
2984 vf->vf_id, ntohs(data.vlan_id));
2989 /* Check if VF is trusted */
2990 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2991 dev_err(&pf->pdev->dev,
2992 "VF %d not trusted, make VF trusted to add advanced mode ADq cloud filters\n",
2994 return I40E_ERR_CONFIG;
2998 if (mask.dst_mac[0] & data.dst_mac[0]) {
2999 if (is_broadcast_ether_addr(data.dst_mac) ||
3000 is_zero_ether_addr(data.dst_mac)) {
3001 dev_info(&pf->pdev->dev, "VF %d: Invalid Dest MAC addr %pM\n",
3002 vf->vf_id, data.dst_mac);
3007 if (mask.src_mac[0] & data.src_mac[0]) {
3008 if (is_broadcast_ether_addr(data.src_mac) ||
3009 is_zero_ether_addr(data.src_mac)) {
3010 dev_info(&pf->pdev->dev, "VF %d: Invalid Source MAC addr %pM\n",
3011 vf->vf_id, data.src_mac);
3016 if (mask.dst_port & data.dst_port) {
3017 if (!data.dst_port || be16_to_cpu(data.dst_port) > 0xFFFF) {
3018 dev_info(&pf->pdev->dev, "VF %d: Invalid Dest port\n",
3024 if (mask.src_port & data.src_port) {
3025 if (!data.src_port || be16_to_cpu(data.src_port) > 0xFFFF) {
3026 dev_info(&pf->pdev->dev, "VF %d: Invalid Source port\n",
3032 if (tc_filter->flow_type != VIRTCHNL_TCP_V6_FLOW &&
3033 tc_filter->flow_type != VIRTCHNL_TCP_V4_FLOW) {
3034 dev_info(&pf->pdev->dev, "VF %d: Invalid Flow type\n",
3039 if (mask.vlan_id & data.vlan_id) {
3040 if (ntohs(data.vlan_id) > I40E_MAX_VLANID) {
3041 dev_info(&pf->pdev->dev, "VF %d: invalid VLAN ID\n",
3047 return I40E_SUCCESS;
3049 return I40E_ERR_CONFIG;
3053 * i40e_find_vsi_from_seid - searches for the vsi with the given seid
3054 * @vf: pointer to the VF info
3055 * @seid - seid of the vsi it is searching for
3057 static struct i40e_vsi *i40e_find_vsi_from_seid(struct i40e_vf *vf, u16 seid)
3059 struct i40e_pf *pf = vf->pf;
3060 struct i40e_vsi *vsi = NULL;
3063 for (i = 0; i < vf->num_tc ; i++) {
3064 vsi = i40e_find_vsi_from_id(pf, vf->ch[i].vsi_id);
3065 if (vsi && vsi->seid == seid)
3072 * i40e_del_all_cloud_filters
3073 * @vf: pointer to the VF info
3075 * This function deletes all cloud filters
3077 static void i40e_del_all_cloud_filters(struct i40e_vf *vf)
3079 struct i40e_cloud_filter *cfilter = NULL;
3080 struct i40e_pf *pf = vf->pf;
3081 struct i40e_vsi *vsi = NULL;
3082 struct hlist_node *node;
3085 hlist_for_each_entry_safe(cfilter, node,
3086 &vf->cloud_filter_list, cloud_node) {
3087 vsi = i40e_find_vsi_from_seid(vf, cfilter->seid);
3090 dev_err(&pf->pdev->dev, "VF %d: no VSI found for matching %u seid, can't delete cloud filter\n",
3091 vf->vf_id, cfilter->seid);
3095 if (cfilter->dst_port)
3096 ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
3099 ret = i40e_add_del_cloud_filter(vsi, cfilter, false);
3101 dev_err(&pf->pdev->dev,
3102 "VF %d: Failed to delete cloud filter, err %s aq_err %s\n",
3103 vf->vf_id, i40e_stat_str(&pf->hw, ret),
3104 i40e_aq_str(&pf->hw,
3105 pf->hw.aq.asq_last_status));
3107 hlist_del(&cfilter->cloud_node);
3109 vf->num_cloud_filters--;
3114 * i40e_vc_del_cloud_filter
3115 * @vf: pointer to the VF info
3116 * @msg: pointer to the msg buffer
3118 * This function deletes a cloud filter programmed as TC filter for ADq
3120 static int i40e_vc_del_cloud_filter(struct i40e_vf *vf, u8 *msg)
3122 struct virtchnl_filter *vcf = (struct virtchnl_filter *)msg;
3123 struct virtchnl_l4_spec mask = vcf->mask.tcp_spec;
3124 struct virtchnl_l4_spec tcf = vcf->data.tcp_spec;
3125 struct i40e_cloud_filter cfilter, *cf = NULL;
3126 struct i40e_pf *pf = vf->pf;
3127 struct i40e_vsi *vsi = NULL;
3128 struct hlist_node *node;
3129 i40e_status aq_ret = 0;
3132 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3133 aq_ret = I40E_ERR_PARAM;
3137 if (!vf->adq_enabled) {
3138 dev_info(&pf->pdev->dev,
3139 "VF %d: ADq not enabled, can't apply cloud filter\n",
3141 aq_ret = I40E_ERR_PARAM;
3145 if (i40e_validate_cloud_filter(vf, vcf)) {
3146 dev_info(&pf->pdev->dev,
3147 "VF %d: Invalid input, can't apply cloud filter\n",
3149 aq_ret = I40E_ERR_PARAM;
3153 memset(&cfilter, 0, sizeof(cfilter));
3154 /* parse destination mac address */
3155 for (i = 0; i < ETH_ALEN; i++)
3156 cfilter.dst_mac[i] = mask.dst_mac[i] & tcf.dst_mac[i];
3158 /* parse source mac address */
3159 for (i = 0; i < ETH_ALEN; i++)
3160 cfilter.src_mac[i] = mask.src_mac[i] & tcf.src_mac[i];
3162 cfilter.vlan_id = mask.vlan_id & tcf.vlan_id;
3163 cfilter.dst_port = mask.dst_port & tcf.dst_port;
3164 cfilter.src_port = mask.src_port & tcf.src_port;
3166 switch (vcf->flow_type) {
3167 case VIRTCHNL_TCP_V4_FLOW:
3168 cfilter.n_proto = ETH_P_IP;
3169 if (mask.dst_ip[0] & tcf.dst_ip[0])
3170 memcpy(&cfilter.ip.v4.dst_ip, tcf.dst_ip,
3171 ARRAY_SIZE(tcf.dst_ip));
3172 else if (mask.src_ip[0] & tcf.dst_ip[0])
3173 memcpy(&cfilter.ip.v4.src_ip, tcf.src_ip,
3174 ARRAY_SIZE(tcf.dst_ip));
3176 case VIRTCHNL_TCP_V6_FLOW:
3177 cfilter.n_proto = ETH_P_IPV6;
3178 if (mask.dst_ip[3] & tcf.dst_ip[3])
3179 memcpy(&cfilter.ip.v6.dst_ip6, tcf.dst_ip,
3180 sizeof(cfilter.ip.v6.dst_ip6));
3181 if (mask.src_ip[3] & tcf.src_ip[3])
3182 memcpy(&cfilter.ip.v6.src_ip6, tcf.src_ip,
3183 sizeof(cfilter.ip.v6.src_ip6));
3186 /* TC filter can be configured based on different combinations
3187 * and in this case IP is not a part of filter config
3189 dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
3193 /* get the vsi to which the tc belongs to */
3194 vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
3195 cfilter.seid = vsi->seid;
3196 cfilter.flags = vcf->field_flags;
3198 /* Deleting TC filter */
3200 ret = i40e_add_del_cloud_filter_big_buf(vsi, &cfilter, false);
3202 ret = i40e_add_del_cloud_filter(vsi, &cfilter, false);
3204 dev_err(&pf->pdev->dev,
3205 "VF %d: Failed to delete cloud filter, err %s aq_err %s\n",
3206 vf->vf_id, i40e_stat_str(&pf->hw, ret),
3207 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
3211 hlist_for_each_entry_safe(cf, node,
3212 &vf->cloud_filter_list, cloud_node) {
3213 if (cf->seid != cfilter.seid)
3216 if (cfilter.dst_port != cf->dst_port)
3218 if (mask.dst_mac[0])
3219 if (!ether_addr_equal(cf->src_mac, cfilter.src_mac))
3221 /* for ipv4 data to be valid, only first byte of mask is set */
3222 if (cfilter.n_proto == ETH_P_IP && mask.dst_ip[0])
3223 if (memcmp(&cfilter.ip.v4.dst_ip, &cf->ip.v4.dst_ip,
3224 ARRAY_SIZE(tcf.dst_ip)))
3226 /* for ipv6, mask is set for all sixteen bytes (4 words) */
3227 if (cfilter.n_proto == ETH_P_IPV6 && mask.dst_ip[3])
3228 if (memcmp(&cfilter.ip.v6.dst_ip6, &cf->ip.v6.dst_ip6,
3229 sizeof(cfilter.ip.v6.src_ip6)))
3232 if (cfilter.vlan_id != cf->vlan_id)
3235 hlist_del(&cf->cloud_node);
3237 vf->num_cloud_filters--;
3241 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_CLOUD_FILTER,
3246 * i40e_vc_add_cloud_filter
3247 * @vf: pointer to the VF info
3248 * @msg: pointer to the msg buffer
3250 * This function adds a cloud filter programmed as TC filter for ADq
3252 static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
3254 struct virtchnl_filter *vcf = (struct virtchnl_filter *)msg;
3255 struct virtchnl_l4_spec mask = vcf->mask.tcp_spec;
3256 struct virtchnl_l4_spec tcf = vcf->data.tcp_spec;
3257 struct i40e_cloud_filter *cfilter = NULL;
3258 struct i40e_pf *pf = vf->pf;
3259 struct i40e_vsi *vsi = NULL;
3260 i40e_status aq_ret = 0;
3263 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3264 aq_ret = I40E_ERR_PARAM;
3268 if (!vf->adq_enabled) {
3269 dev_info(&pf->pdev->dev,
3270 "VF %d: ADq is not enabled, can't apply cloud filter\n",
3272 aq_ret = I40E_ERR_PARAM;
3276 if (i40e_validate_cloud_filter(vf, vcf)) {
3277 dev_info(&pf->pdev->dev,
3278 "VF %d: Invalid input/s, can't apply cloud filter\n",
3280 aq_ret = I40E_ERR_PARAM;
3284 cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL);
3288 /* parse destination mac address */
3289 for (i = 0; i < ETH_ALEN; i++)
3290 cfilter->dst_mac[i] = mask.dst_mac[i] & tcf.dst_mac[i];
3292 /* parse source mac address */
3293 for (i = 0; i < ETH_ALEN; i++)
3294 cfilter->src_mac[i] = mask.src_mac[i] & tcf.src_mac[i];
3296 cfilter->vlan_id = mask.vlan_id & tcf.vlan_id;
3297 cfilter->dst_port = mask.dst_port & tcf.dst_port;
3298 cfilter->src_port = mask.src_port & tcf.src_port;
3300 switch (vcf->flow_type) {
3301 case VIRTCHNL_TCP_V4_FLOW:
3302 cfilter->n_proto = ETH_P_IP;
3303 if (mask.dst_ip[0] & tcf.dst_ip[0])
3304 memcpy(&cfilter->ip.v4.dst_ip, tcf.dst_ip,
3305 ARRAY_SIZE(tcf.dst_ip));
3306 else if (mask.src_ip[0] & tcf.dst_ip[0])
3307 memcpy(&cfilter->ip.v4.src_ip, tcf.src_ip,
3308 ARRAY_SIZE(tcf.dst_ip));
3310 case VIRTCHNL_TCP_V6_FLOW:
3311 cfilter->n_proto = ETH_P_IPV6;
3312 if (mask.dst_ip[3] & tcf.dst_ip[3])
3313 memcpy(&cfilter->ip.v6.dst_ip6, tcf.dst_ip,
3314 sizeof(cfilter->ip.v6.dst_ip6));
3315 if (mask.src_ip[3] & tcf.src_ip[3])
3316 memcpy(&cfilter->ip.v6.src_ip6, tcf.src_ip,
3317 sizeof(cfilter->ip.v6.src_ip6));
3320 /* TC filter can be configured based on different combinations
3321 * and in this case IP is not a part of filter config
3323 dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
3327 /* get the VSI to which the TC belongs to */
3328 vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
3329 cfilter->seid = vsi->seid;
3330 cfilter->flags = vcf->field_flags;
3332 /* Adding cloud filter programmed as TC filter */
3334 ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter, true);
3336 ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
3338 dev_err(&pf->pdev->dev,
3339 "VF %d: Failed to add cloud filter, err %s aq_err %s\n",
3340 vf->vf_id, i40e_stat_str(&pf->hw, ret),
3341 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
3345 INIT_HLIST_NODE(&cfilter->cloud_node);
3346 hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list);
3347 vf->num_cloud_filters++;
3349 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER,
3354 * i40e_vc_add_qch_msg: Add queue channel and enable ADq
3355 * @vf: pointer to the VF info
3356 * @msg: pointer to the msg buffer
3358 static int i40e_vc_add_qch_msg(struct i40e_vf *vf, u8 *msg)
3360 struct virtchnl_tc_info *tci =
3361 (struct virtchnl_tc_info *)msg;
3362 struct i40e_pf *pf = vf->pf;
3363 struct i40e_link_status *ls = &pf->hw.phy.link_info;
3364 int i, adq_request_qps = 0, speed = 0;
3365 i40e_status aq_ret = 0;
3367 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3368 aq_ret = I40E_ERR_PARAM;
3372 /* ADq cannot be applied if spoof check is ON */
3374 dev_err(&pf->pdev->dev,
3375 "Spoof check is ON, turn it OFF to enable ADq\n");
3376 aq_ret = I40E_ERR_PARAM;
3380 if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)) {
3381 dev_err(&pf->pdev->dev,
3382 "VF %d attempting to enable ADq, but hasn't properly negotiated that capability\n",
3384 aq_ret = I40E_ERR_PARAM;
3388 /* max number of traffic classes for VF currently capped at 4 */
3389 if (!tci->num_tc || tci->num_tc > I40E_MAX_VF_VSI) {
3390 dev_err(&pf->pdev->dev,
3391 "VF %d trying to set %u TCs, valid range 1-4 TCs per VF\n",
3392 vf->vf_id, tci->num_tc);
3393 aq_ret = I40E_ERR_PARAM;
3397 /* validate queues for each TC */
3398 for (i = 0; i < tci->num_tc; i++)
3399 if (!tci->list[i].count ||
3400 tci->list[i].count > I40E_DEFAULT_QUEUES_PER_VF) {
3401 dev_err(&pf->pdev->dev,
3402 "VF %d: TC %d trying to set %u queues, valid range 1-4 queues per TC\n",
3403 vf->vf_id, i, tci->list[i].count);
3404 aq_ret = I40E_ERR_PARAM;
3408 /* need Max VF queues but already have default number of queues */
3409 adq_request_qps = I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF;
3411 if (pf->queues_left < adq_request_qps) {
3412 dev_err(&pf->pdev->dev,
3413 "No queues left to allocate to VF %d\n",
3415 aq_ret = I40E_ERR_PARAM;
3418 /* we need to allocate max VF queues to enable ADq so as to
3419 * make sure ADq enabled VF always gets back queues when it
3420 * goes through a reset.
3422 vf->num_queue_pairs = I40E_MAX_VF_QUEUES;
3425 /* get link speed in MB to validate rate limit */
3426 switch (ls->link_speed) {
3427 case VIRTCHNL_LINK_SPEED_100MB:
3430 case VIRTCHNL_LINK_SPEED_1GB:
3433 case VIRTCHNL_LINK_SPEED_10GB:
3434 speed = SPEED_10000;
3436 case VIRTCHNL_LINK_SPEED_20GB:
3437 speed = SPEED_20000;
3439 case VIRTCHNL_LINK_SPEED_25GB:
3440 speed = SPEED_25000;
3442 case VIRTCHNL_LINK_SPEED_40GB:
3443 speed = SPEED_40000;
3446 dev_err(&pf->pdev->dev,
3447 "Cannot detect link speed\n");
3448 aq_ret = I40E_ERR_PARAM;
3452 /* parse data from the queue channel info */
3453 vf->num_tc = tci->num_tc;
3454 for (i = 0; i < vf->num_tc; i++) {
3455 if (tci->list[i].max_tx_rate) {
3456 if (tci->list[i].max_tx_rate > speed) {
3457 dev_err(&pf->pdev->dev,
3458 "Invalid max tx rate %llu specified for VF %d.",
3459 tci->list[i].max_tx_rate,
3461 aq_ret = I40E_ERR_PARAM;
3464 vf->ch[i].max_tx_rate =
3465 tci->list[i].max_tx_rate;
3468 vf->ch[i].num_qps = tci->list[i].count;
3471 /* set this flag only after making sure all inputs are sane */
3472 vf->adq_enabled = true;
3473 /* num_req_queues is set when user changes number of queues via ethtool
3474 * and this causes issue for default VSI(which depends on this variable)
3475 * when ADq is enabled, hence reset it.
3477 vf->num_req_queues = 0;
3479 /* reset the VF in order to allocate resources */
3480 i40e_vc_notify_vf_reset(vf);
3481 i40e_reset_vf(vf, false);
3483 return I40E_SUCCESS;
3485 /* send the response to the VF */
3487 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_CHANNELS,
3492 * i40e_vc_del_qch_msg
3493 * @vf: pointer to the VF info
3494 * @msg: pointer to the msg buffer
3496 static int i40e_vc_del_qch_msg(struct i40e_vf *vf, u8 *msg)
3498 struct i40e_pf *pf = vf->pf;
3499 i40e_status aq_ret = 0;
3501 if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
3502 aq_ret = I40E_ERR_PARAM;
3506 if (vf->adq_enabled) {
3507 i40e_del_all_cloud_filters(vf);
3509 vf->adq_enabled = false;
3511 dev_info(&pf->pdev->dev,
3512 "Deleting Queue Channels and cloud filters for ADq on VF %d\n",
3515 dev_info(&pf->pdev->dev, "VF %d trying to delete queue channels but ADq isn't enabled\n",
3517 aq_ret = I40E_ERR_PARAM;
3520 /* reset the VF in order to allocate resources */
3521 i40e_vc_notify_vf_reset(vf);
3522 i40e_reset_vf(vf, false);
3524 return I40E_SUCCESS;
3527 return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_CHANNELS,
3532 * i40e_vc_process_vf_msg
3533 * @pf: pointer to the PF structure
3534 * @vf_id: source VF id
3535 * @msg: pointer to the msg buffer
3536 * @msglen: msg length
3537 * @msghndl: msg handle
3539 * called from the common aeq/arq handler to
3540 * process request from VF
3542 int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
3543 u32 v_retval, u8 *msg, u16 msglen)
3545 struct i40e_hw *hw = &pf->hw;
3546 int local_vf_id = vf_id - (s16)hw->func_caps.vf_base_id;
3550 pf->vf_aq_requests++;
3551 if (local_vf_id >= pf->num_alloc_vfs)
3553 vf = &(pf->vf[local_vf_id]);
3555 /* Check if VF is disabled. */
3556 if (test_bit(I40E_VF_STATE_DISABLED, &vf->vf_states))
3557 return I40E_ERR_PARAM;
3559 /* perform basic checks on the msg */
3560 ret = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
3562 /* perform additional checks specific to this driver */
3563 if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_KEY) {
3564 struct virtchnl_rss_key *vrk = (struct virtchnl_rss_key *)msg;
3566 if (vrk->key_len != I40E_HKEY_ARRAY_SIZE)
3568 } else if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_LUT) {
3569 struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
3571 if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)
3576 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
3577 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
3578 local_vf_id, v_opcode, msglen);
3580 case VIRTCHNL_ERR_PARAM:
3588 case VIRTCHNL_OP_VERSION:
3589 ret = i40e_vc_get_version_msg(vf, msg);
3591 case VIRTCHNL_OP_GET_VF_RESOURCES:
3592 ret = i40e_vc_get_vf_resources_msg(vf, msg);
3593 i40e_vc_notify_vf_link_state(vf);
3595 case VIRTCHNL_OP_RESET_VF:
3596 i40e_vc_reset_vf_msg(vf);
3599 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
3600 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
3602 case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
3603 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
3605 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
3606 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
3608 case VIRTCHNL_OP_ENABLE_QUEUES:
3609 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
3610 i40e_vc_notify_vf_link_state(vf);
3612 case VIRTCHNL_OP_DISABLE_QUEUES:
3613 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
3615 case VIRTCHNL_OP_ADD_ETH_ADDR:
3616 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
3618 case VIRTCHNL_OP_DEL_ETH_ADDR:
3619 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
3621 case VIRTCHNL_OP_ADD_VLAN:
3622 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
3624 case VIRTCHNL_OP_DEL_VLAN:
3625 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
3627 case VIRTCHNL_OP_GET_STATS:
3628 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
3630 case VIRTCHNL_OP_IWARP:
3631 ret = i40e_vc_iwarp_msg(vf, msg, msglen);
3633 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
3634 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
3636 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
3637 ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
3639 case VIRTCHNL_OP_CONFIG_RSS_KEY:
3640 ret = i40e_vc_config_rss_key(vf, msg, msglen);
3642 case VIRTCHNL_OP_CONFIG_RSS_LUT:
3643 ret = i40e_vc_config_rss_lut(vf, msg, msglen);
3645 case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
3646 ret = i40e_vc_get_rss_hena(vf, msg, msglen);
3648 case VIRTCHNL_OP_SET_RSS_HENA:
3649 ret = i40e_vc_set_rss_hena(vf, msg, msglen);
3651 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
3652 ret = i40e_vc_enable_vlan_stripping(vf, msg, msglen);
3654 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
3655 ret = i40e_vc_disable_vlan_stripping(vf, msg, msglen);
3657 case VIRTCHNL_OP_REQUEST_QUEUES:
3658 ret = i40e_vc_request_queues_msg(vf, msg, msglen);
3660 case VIRTCHNL_OP_ENABLE_CHANNELS:
3661 ret = i40e_vc_add_qch_msg(vf, msg);
3663 case VIRTCHNL_OP_DISABLE_CHANNELS:
3664 ret = i40e_vc_del_qch_msg(vf, msg);
3666 case VIRTCHNL_OP_ADD_CLOUD_FILTER:
3667 ret = i40e_vc_add_cloud_filter(vf, msg);
3669 case VIRTCHNL_OP_DEL_CLOUD_FILTER:
3670 ret = i40e_vc_del_cloud_filter(vf, msg);
3672 case VIRTCHNL_OP_UNKNOWN:
3674 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
3675 v_opcode, local_vf_id);
3676 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
3677 I40E_ERR_NOT_IMPLEMENTED);
3685 * i40e_vc_process_vflr_event
3686 * @pf: pointer to the PF structure
3688 * called from the vlfr irq handler to
3689 * free up VF resources and state variables
3691 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
3693 struct i40e_hw *hw = &pf->hw;
3694 u32 reg, reg_idx, bit_idx;
3698 if (!test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
3701 /* Re-enable the VFLR interrupt cause here, before looking for which
3702 * VF got reset. Otherwise, if another VF gets a reset while the
3703 * first one is being processed, that interrupt will be lost, and
3704 * that VF will be stuck in reset forever.
3706 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
3707 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
3708 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
3711 clear_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
3712 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
3713 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
3714 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
3715 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
3716 vf = &pf->vf[vf_id];
3717 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
3718 if (reg & BIT(bit_idx))
3719 /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
3720 i40e_reset_vf(vf, true);
3727 * i40e_ndo_set_vf_mac
3728 * @netdev: network interface device structure
3729 * @vf_id: VF identifier
3732 * program VF mac address
3734 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
3736 struct i40e_netdev_priv *np = netdev_priv(netdev);
3737 struct i40e_vsi *vsi = np->vsi;
3738 struct i40e_pf *pf = vsi->back;
3739 struct i40e_mac_filter *f;
3742 struct hlist_node *h;
3746 /* validate the request */
3747 if (vf_id >= pf->num_alloc_vfs) {
3748 dev_err(&pf->pdev->dev,
3749 "Invalid VF Identifier %d\n", vf_id);
3754 vf = &(pf->vf[vf_id]);
3755 vsi = pf->vsi[vf->lan_vsi_idx];
3757 /* When the VF is resetting wait until it is done.
3758 * It can take up to 200 milliseconds,
3759 * but wait for up to 300 milliseconds to be safe.
3761 for (i = 0; i < 15; i++) {
3762 if (test_bit(I40E_VF_STATE_INIT, &vf->vf_states))
3766 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
3767 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3773 if (is_multicast_ether_addr(mac)) {
3774 dev_err(&pf->pdev->dev,
3775 "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
3780 /* Lock once because below invoked function add/del_filter requires
3781 * mac_filter_hash_lock to be held
3783 spin_lock_bh(&vsi->mac_filter_hash_lock);
3785 /* delete the temporary mac address */
3786 if (!is_zero_ether_addr(vf->default_lan_addr.addr))
3787 i40e_del_mac_filter(vsi, vf->default_lan_addr.addr);
3789 /* Delete all the filters for this VSI - we're going to kill it
3792 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
3793 __i40e_del_filter(vsi, f);
3795 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3797 /* program mac filter */
3798 if (i40e_sync_vsi_filters(vsi)) {
3799 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
3803 ether_addr_copy(vf->default_lan_addr.addr, mac);
3805 if (is_zero_ether_addr(mac)) {
3806 vf->pf_set_mac = false;
3807 dev_info(&pf->pdev->dev, "Removing MAC on VF %d\n", vf_id);
3809 vf->pf_set_mac = true;
3810 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n",
3814 /* Force the VF driver stop so it has to reload with new MAC address */
3815 i40e_vc_disable_vf(vf);
3816 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
3823 * i40e_vsi_has_vlans - True if VSI has configured VLANs
3824 * @vsi: pointer to the vsi
3826 * Check if a VSI has configured any VLANs. False if we have a port VLAN or if
3827 * we have no configured VLANs. Do not call while holding the
3828 * mac_filter_hash_lock.
3830 static bool i40e_vsi_has_vlans(struct i40e_vsi *vsi)
3834 /* If we have a port VLAN, then the VSI cannot have any VLANs
3835 * configured, as all MAC/VLAN filters will be assigned to the PVID.
3840 /* Since we don't have a PVID, we know that if the device is in VLAN
3841 * mode it must be because of a VLAN filter configured on this VSI.
3843 spin_lock_bh(&vsi->mac_filter_hash_lock);
3844 have_vlans = i40e_is_vsi_in_vlan(vsi);
3845 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3851 * i40e_ndo_set_vf_port_vlan
3852 * @netdev: network interface device structure
3853 * @vf_id: VF identifier
3854 * @vlan_id: mac address
3855 * @qos: priority setting
3856 * @vlan_proto: vlan protocol
3858 * program VF vlan id and/or qos
3860 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
3861 u16 vlan_id, u8 qos, __be16 vlan_proto)
3863 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
3864 struct i40e_netdev_priv *np = netdev_priv(netdev);
3865 struct i40e_pf *pf = np->vsi->back;
3866 struct i40e_vsi *vsi;
3870 /* validate the request */
3871 if (vf_id >= pf->num_alloc_vfs) {
3872 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
3877 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
3878 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
3883 if (vlan_proto != htons(ETH_P_8021Q)) {
3884 dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
3885 ret = -EPROTONOSUPPORT;
3889 vf = &(pf->vf[vf_id]);
3890 vsi = pf->vsi[vf->lan_vsi_idx];
3891 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
3892 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3898 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
3899 /* duplicate request, so just return success */
3902 if (i40e_vsi_has_vlans(vsi)) {
3903 dev_err(&pf->pdev->dev,
3904 "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",
3906 /* Administrator Error - knock the VF offline until he does
3907 * the right thing by reconfiguring his network correctly
3908 * and then reloading the VF driver.
3910 i40e_vc_disable_vf(vf);
3911 /* During reset the VF got a new VSI, so refresh the pointer. */
3912 vsi = pf->vsi[vf->lan_vsi_idx];
3915 /* Locked once because multiple functions below iterate list */
3916 spin_lock_bh(&vsi->mac_filter_hash_lock);
3918 /* Check for condition where there was already a port VLAN ID
3919 * filter set and now it is being deleted by setting it to zero.
3920 * Additionally check for the condition where there was a port
3921 * VLAN but now there is a new and different port VLAN being set.
3922 * Before deleting all the old VLAN filters we must add new ones
3923 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
3924 * MAC addresses deleted.
3926 if ((!(vlan_id || qos) ||
3927 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
3929 ret = i40e_add_vlan_all_mac(vsi, I40E_VLAN_ANY);
3931 dev_info(&vsi->back->pdev->dev,
3932 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
3933 vsi->back->hw.aq.asq_last_status);
3934 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3939 if (vsi->info.pvid) {
3940 /* remove all filters on the old VLAN */
3941 i40e_rm_vlan_all_mac(vsi, (le16_to_cpu(vsi->info.pvid) &
3945 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3947 ret = i40e_vsi_add_pvid(vsi, vlanprio);
3949 i40e_vsi_remove_pvid(vsi);
3950 spin_lock_bh(&vsi->mac_filter_hash_lock);
3953 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
3954 vlan_id, qos, vf_id);
3956 /* add new VLAN filter for each MAC */
3957 ret = i40e_add_vlan_all_mac(vsi, vlan_id);
3959 dev_info(&vsi->back->pdev->dev,
3960 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
3961 vsi->back->hw.aq.asq_last_status);
3962 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3966 /* remove the previously added non-VLAN MAC filters */
3967 i40e_rm_vlan_all_mac(vsi, I40E_VLAN_ANY);
3970 spin_unlock_bh(&vsi->mac_filter_hash_lock);
3972 /* Schedule the worker thread to take care of applying changes */
3973 i40e_service_event_schedule(vsi->back);
3976 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
3980 /* The Port VLAN needs to be saved across resets the same as the
3981 * default LAN MAC address.
3983 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
3991 * i40e_ndo_set_vf_bw
3992 * @netdev: network interface device structure
3993 * @vf_id: VF identifier
3996 * configure VF Tx rate
3998 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
4001 struct i40e_netdev_priv *np = netdev_priv(netdev);
4002 struct i40e_pf *pf = np->vsi->back;
4003 struct i40e_vsi *vsi;
4007 /* validate the request */
4008 if (vf_id >= pf->num_alloc_vfs) {
4009 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
4015 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
4016 min_tx_rate, vf_id);
4020 vf = &(pf->vf[vf_id]);
4021 vsi = pf->vsi[vf->lan_vsi_idx];
4022 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4023 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
4029 ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
4033 vf->tx_rate = max_tx_rate;
4039 * i40e_ndo_get_vf_config
4040 * @netdev: network interface device structure
4041 * @vf_id: VF identifier
4042 * @ivi: VF configuration structure
4044 * return VF configuration
4046 int i40e_ndo_get_vf_config(struct net_device *netdev,
4047 int vf_id, struct ifla_vf_info *ivi)
4049 struct i40e_netdev_priv *np = netdev_priv(netdev);
4050 struct i40e_vsi *vsi = np->vsi;
4051 struct i40e_pf *pf = vsi->back;
4055 /* validate the request */
4056 if (vf_id >= pf->num_alloc_vfs) {
4057 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4062 vf = &(pf->vf[vf_id]);
4063 /* first vsi is always the LAN vsi */
4064 vsi = pf->vsi[vf->lan_vsi_idx];
4065 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4066 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
4074 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
4076 ivi->max_tx_rate = vf->tx_rate;
4077 ivi->min_tx_rate = 0;
4078 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
4079 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
4080 I40E_VLAN_PRIORITY_SHIFT;
4081 if (vf->link_forced == false)
4082 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
4083 else if (vf->link_up == true)
4084 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
4086 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
4087 ivi->spoofchk = vf->spoofchk;
4088 ivi->trusted = vf->trusted;
4096 * i40e_ndo_set_vf_link_state
4097 * @netdev: network interface device structure
4098 * @vf_id: VF identifier
4099 * @link: required link state
4101 * Set the link state of a specified VF, regardless of physical link state
4103 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
4105 struct i40e_netdev_priv *np = netdev_priv(netdev);
4106 struct i40e_pf *pf = np->vsi->back;
4107 struct virtchnl_pf_event pfe;
4108 struct i40e_hw *hw = &pf->hw;
4113 /* validate the request */
4114 if (vf_id >= pf->num_alloc_vfs) {
4115 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4120 vf = &pf->vf[vf_id];
4121 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
4123 pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
4124 pfe.severity = PF_EVENT_SEVERITY_INFO;
4127 case IFLA_VF_LINK_STATE_AUTO:
4128 vf->link_forced = false;
4129 pfe.event_data.link_event.link_status =
4130 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
4131 pfe.event_data.link_event.link_speed =
4132 (enum virtchnl_link_speed)
4133 pf->hw.phy.link_info.link_speed;
4135 case IFLA_VF_LINK_STATE_ENABLE:
4136 vf->link_forced = true;
4138 pfe.event_data.link_event.link_status = true;
4139 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
4141 case IFLA_VF_LINK_STATE_DISABLE:
4142 vf->link_forced = true;
4143 vf->link_up = false;
4144 pfe.event_data.link_event.link_status = false;
4145 pfe.event_data.link_event.link_speed = 0;
4151 /* Notify the VF of its new link state */
4152 i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT,
4153 0, (u8 *)&pfe, sizeof(pfe), NULL);
4160 * i40e_ndo_set_vf_spoofchk
4161 * @netdev: network interface device structure
4162 * @vf_id: VF identifier
4163 * @enable: flag to enable or disable feature
4165 * Enable or disable VF spoof checking
4167 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
4169 struct i40e_netdev_priv *np = netdev_priv(netdev);
4170 struct i40e_vsi *vsi = np->vsi;
4171 struct i40e_pf *pf = vsi->back;
4172 struct i40e_vsi_context ctxt;
4173 struct i40e_hw *hw = &pf->hw;
4177 /* validate the request */
4178 if (vf_id >= pf->num_alloc_vfs) {
4179 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4184 vf = &(pf->vf[vf_id]);
4185 if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4186 dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
4192 if (enable == vf->spoofchk)
4195 vf->spoofchk = enable;
4196 memset(&ctxt, 0, sizeof(ctxt));
4197 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
4198 ctxt.pf_num = pf->hw.pf_id;
4199 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
4201 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
4202 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
4203 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4205 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
4214 * i40e_ndo_set_vf_trust
4215 * @netdev: network interface device structure of the pf
4216 * @vf_id: VF identifier
4217 * @setting: trust setting
4219 * Enable or disable VF trust setting
4221 int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
4223 struct i40e_netdev_priv *np = netdev_priv(netdev);
4224 struct i40e_pf *pf = np->vsi->back;
4228 /* validate the request */
4229 if (vf_id >= pf->num_alloc_vfs) {
4230 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
4234 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
4235 dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
4239 vf = &pf->vf[vf_id];
4241 if (setting == vf->trusted)
4244 vf->trusted = setting;
4245 i40e_vc_disable_vf(vf);
4246 dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
4247 vf_id, setting ? "" : "un");
4249 if (vf->adq_enabled) {
4251 dev_info(&pf->pdev->dev,
4252 "VF %u no longer Trusted, deleting all cloud filters\n",
4254 i40e_del_all_cloud_filters(vf);