1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 /*********************notification routines***********************/
32 * i40e_vc_vf_broadcast
33 * @pf: pointer to the PF structure
34 * @opcode: operation code
35 * @retval: return value
36 * @msg: pointer to the msg buffer
39 * send a message to all VFs on a given PF
41 static void i40e_vc_vf_broadcast(struct i40e_pf
*pf
,
42 enum virtchnl_ops v_opcode
,
43 i40e_status v_retval
, u8
*msg
,
46 struct i40e_hw
*hw
= &pf
->hw
;
47 struct i40e_vf
*vf
= pf
->vf
;
50 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++, vf
++) {
51 int abs_vf_id
= vf
->vf_id
+ (int)hw
->func_caps
.vf_base_id
;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
) &&
54 !test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
))
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
60 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
66 * i40e_vc_notify_vf_link_state
67 * @vf: pointer to the VF structure
69 * send a link status message to a single VF
71 static void i40e_vc_notify_vf_link_state(struct i40e_vf
*vf
)
73 struct virtchnl_pf_event pfe
;
74 struct i40e_pf
*pf
= vf
->pf
;
75 struct i40e_hw
*hw
= &pf
->hw
;
76 struct i40e_link_status
*ls
= &pf
->hw
.phy
.link_info
;
77 int abs_vf_id
= vf
->vf_id
+ (int)hw
->func_caps
.vf_base_id
;
79 pfe
.event
= VIRTCHNL_EVENT_LINK_CHANGE
;
80 pfe
.severity
= PF_EVENT_SEVERITY_INFO
;
81 if (vf
->link_forced
) {
82 pfe
.event_data
.link_event
.link_status
= vf
->link_up
;
83 pfe
.event_data
.link_event
.link_speed
=
84 (vf
->link_up
? VIRTCHNL_LINK_SPEED_40GB
: 0);
86 pfe
.event_data
.link_event
.link_status
=
87 ls
->link_info
& I40E_AQ_LINK_UP
;
88 pfe
.event_data
.link_event
.link_speed
=
89 i40e_virtchnl_link_speed(ls
->link_speed
);
91 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, VIRTCHNL_OP_EVENT
,
92 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
96 * i40e_vc_notify_link_state
97 * @pf: pointer to the PF structure
99 * send a link status message to all VFs on a given PF
101 void i40e_vc_notify_link_state(struct i40e_pf
*pf
)
105 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
106 i40e_vc_notify_vf_link_state(&pf
->vf
[i
]);
110 * i40e_vc_notify_reset
111 * @pf: pointer to the PF structure
113 * indicate a pending reset to all VFs on a given PF
115 void i40e_vc_notify_reset(struct i40e_pf
*pf
)
117 struct virtchnl_pf_event pfe
;
119 pfe
.event
= VIRTCHNL_EVENT_RESET_IMPENDING
;
120 pfe
.severity
= PF_EVENT_SEVERITY_CERTAIN_DOOM
;
121 i40e_vc_vf_broadcast(pf
, VIRTCHNL_OP_EVENT
, 0,
122 (u8
*)&pfe
, sizeof(struct virtchnl_pf_event
));
126 * i40e_vc_notify_vf_reset
127 * @vf: pointer to the VF structure
129 * indicate a pending reset to the given VF
131 void i40e_vc_notify_vf_reset(struct i40e_vf
*vf
)
133 struct virtchnl_pf_event pfe
;
136 /* validate the request */
137 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
140 /* verify if the VF is in either init or active before proceeding */
141 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
) &&
142 !test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
))
145 abs_vf_id
= vf
->vf_id
+ (int)vf
->pf
->hw
.func_caps
.vf_base_id
;
147 pfe
.event
= VIRTCHNL_EVENT_RESET_IMPENDING
;
148 pfe
.severity
= PF_EVENT_SEVERITY_CERTAIN_DOOM
;
149 i40e_aq_send_msg_to_vf(&vf
->pf
->hw
, abs_vf_id
, VIRTCHNL_OP_EVENT
,
151 sizeof(struct virtchnl_pf_event
), NULL
);
153 /***********************misc routines*****************************/
157 * @vf: pointer to the VF info
159 * Disable the VF through a SW reset.
161 static inline void i40e_vc_disable_vf(struct i40e_vf
*vf
)
165 i40e_vc_notify_vf_reset(vf
);
167 /* We want to ensure that an actual reset occurs initiated after this
168 * function was called. However, we do not want to wait forever, so
169 * we'll give a reasonable time and print a message if we failed to
172 for (i
= 0; i
< 20; i
++) {
173 if (i40e_reset_vf(vf
, false))
175 usleep_range(10000, 20000);
178 dev_warn(&vf
->pf
->pdev
->dev
,
179 "Failed to initiate reset for VF %d after 200 milliseconds\n",
184 * i40e_vc_isvalid_vsi_id
185 * @vf: pointer to the VF info
186 * @vsi_id: VF relative VSI id
188 * check for the valid VSI id
190 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf
*vf
, u16 vsi_id
)
192 struct i40e_pf
*pf
= vf
->pf
;
193 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
195 return (vsi
&& (vsi
->vf_id
== vf
->vf_id
));
199 * i40e_vc_isvalid_queue_id
200 * @vf: pointer to the VF info
202 * @qid: vsi relative queue id
204 * check for the valid queue id
206 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
209 struct i40e_pf
*pf
= vf
->pf
;
210 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
212 return (vsi
&& (qid
< vsi
->alloc_queue_pairs
));
216 * i40e_vc_isvalid_vector_id
217 * @vf: pointer to the VF info
218 * @vector_id: VF relative vector id
220 * check for the valid vector id
222 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf
*vf
, u8 vector_id
)
224 struct i40e_pf
*pf
= vf
->pf
;
226 return vector_id
< pf
->hw
.func_caps
.num_msix_vectors_vf
;
229 /***********************vf resource mgmt routines*****************/
232 * i40e_vc_get_pf_queue_id
233 * @vf: pointer to the VF info
234 * @vsi_id: id of VSI as provided by the FW
235 * @vsi_queue_id: vsi relative queue id
237 * return PF relative queue id
239 static u16
i40e_vc_get_pf_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
242 struct i40e_pf
*pf
= vf
->pf
;
243 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
244 u16 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
249 if (le16_to_cpu(vsi
->info
.mapping_flags
) &
250 I40E_AQ_VSI_QUE_MAP_NONCONTIG
)
252 le16_to_cpu(vsi
->info
.queue_mapping
[vsi_queue_id
]);
254 pf_queue_id
= le16_to_cpu(vsi
->info
.queue_mapping
[0]) +
261 * i40e_config_irq_link_list
262 * @vf: pointer to the VF info
263 * @vsi_id: id of VSI as given by the FW
264 * @vecmap: irq map info
266 * configure irq link list from the map
268 static void i40e_config_irq_link_list(struct i40e_vf
*vf
, u16 vsi_id
,
269 struct virtchnl_vector_map
*vecmap
)
271 unsigned long linklistmap
= 0, tempmap
;
272 struct i40e_pf
*pf
= vf
->pf
;
273 struct i40e_hw
*hw
= &pf
->hw
;
274 u16 vsi_queue_id
, pf_queue_id
;
275 enum i40e_queue_type qtype
;
276 u16 next_q
, vector_id
, size
;
280 vector_id
= vecmap
->vector_id
;
283 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
285 reg_idx
= I40E_VPINT_LNKLSTN(
286 ((pf
->hw
.func_caps
.num_msix_vectors_vf
- 1) * vf
->vf_id
) +
289 if (vecmap
->rxq_map
== 0 && vecmap
->txq_map
== 0) {
290 /* Special case - No queues mapped on this vector */
291 wr32(hw
, reg_idx
, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK
);
294 tempmap
= vecmap
->rxq_map
;
295 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
296 linklistmap
|= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES
*
300 tempmap
= vecmap
->txq_map
;
301 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
302 linklistmap
|= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES
*
306 size
= I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
;
307 next_q
= find_first_bit(&linklistmap
, size
);
308 if (unlikely(next_q
== size
))
311 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
312 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
313 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
314 reg
= ((qtype
<< I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
) | pf_queue_id
);
316 wr32(hw
, reg_idx
, reg
);
318 while (next_q
< size
) {
320 case I40E_QUEUE_TYPE_RX
:
321 reg_idx
= I40E_QINT_RQCTL(pf_queue_id
);
322 itr_idx
= vecmap
->rxitr_idx
;
324 case I40E_QUEUE_TYPE_TX
:
325 reg_idx
= I40E_QINT_TQCTL(pf_queue_id
);
326 itr_idx
= vecmap
->txitr_idx
;
332 next_q
= find_next_bit(&linklistmap
, size
, next_q
+ 1);
334 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
335 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
336 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
,
339 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
343 /* format for the RQCTL & TQCTL regs is same */
345 (qtype
<< I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
) |
346 (pf_queue_id
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
347 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT
) |
348 (itr_idx
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
);
349 wr32(hw
, reg_idx
, reg
);
352 /* if the vf is running in polling mode and using interrupt zero,
353 * need to disable auto-mask on enabling zero interrupt for VFs.
355 if ((vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_RX_POLLING
) &&
357 reg
= rd32(hw
, I40E_GLINT_CTL
);
358 if (!(reg
& I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK
)) {
359 reg
|= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK
;
360 wr32(hw
, I40E_GLINT_CTL
, reg
);
369 * i40e_release_iwarp_qvlist
370 * @vf: pointer to the VF.
373 static void i40e_release_iwarp_qvlist(struct i40e_vf
*vf
)
375 struct i40e_pf
*pf
= vf
->pf
;
376 struct virtchnl_iwarp_qvlist_info
*qvlist_info
= vf
->qvlist_info
;
380 if (!vf
->qvlist_info
)
383 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
384 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
385 struct virtchnl_iwarp_qv_info
*qv_info
;
386 u32 next_q_index
, next_q_type
;
387 struct i40e_hw
*hw
= &pf
->hw
;
388 u32 v_idx
, reg_idx
, reg
;
390 qv_info
= &qvlist_info
->qv_info
[i
];
393 v_idx
= qv_info
->v_idx
;
394 if (qv_info
->ceq_idx
!= I40E_QUEUE_INVALID_IDX
) {
395 /* Figure out the queue after CEQ and make that the
398 reg_idx
= (msix_vf
- 1) * vf
->vf_id
+ qv_info
->ceq_idx
;
399 reg
= rd32(hw
, I40E_VPINT_CEQCTL(reg_idx
));
400 next_q_index
= (reg
& I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK
)
401 >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT
;
402 next_q_type
= (reg
& I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK
)
403 >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT
;
405 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
406 reg
= (next_q_index
&
407 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
409 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
411 wr32(hw
, I40E_VPINT_LNKLSTN(reg_idx
), reg
);
414 kfree(vf
->qvlist_info
);
415 vf
->qvlist_info
= NULL
;
419 * i40e_config_iwarp_qvlist
420 * @vf: pointer to the VF info
421 * @qvlist_info: queue and vector list
423 * Return 0 on success or < 0 on error
425 static int i40e_config_iwarp_qvlist(struct i40e_vf
*vf
,
426 struct virtchnl_iwarp_qvlist_info
*qvlist_info
)
428 struct i40e_pf
*pf
= vf
->pf
;
429 struct i40e_hw
*hw
= &pf
->hw
;
430 struct virtchnl_iwarp_qv_info
*qv_info
;
431 u32 v_idx
, i
, reg_idx
, reg
;
432 u32 next_q_idx
, next_q_type
;
435 size
= sizeof(struct virtchnl_iwarp_qvlist_info
) +
436 (sizeof(struct virtchnl_iwarp_qv_info
) *
437 (qvlist_info
->num_vectors
- 1));
438 vf
->qvlist_info
= kzalloc(size
, GFP_KERNEL
);
439 if (!vf
->qvlist_info
)
442 vf
->qvlist_info
->num_vectors
= qvlist_info
->num_vectors
;
444 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
445 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
446 qv_info
= &qvlist_info
->qv_info
[i
];
449 v_idx
= qv_info
->v_idx
;
451 /* Validate vector id belongs to this vf */
452 if (!i40e_vc_isvalid_vector_id(vf
, v_idx
))
455 vf
->qvlist_info
->qv_info
[i
] = *qv_info
;
457 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
458 /* We might be sharing the interrupt, so get the first queue
459 * index and type, push it down the list by adding the new
460 * queue on top. Also link it with the new queue in CEQCTL.
462 reg
= rd32(hw
, I40E_VPINT_LNKLSTN(reg_idx
));
463 next_q_idx
= ((reg
& I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) >>
464 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT
);
465 next_q_type
= ((reg
& I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
) >>
466 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
468 if (qv_info
->ceq_idx
!= I40E_QUEUE_INVALID_IDX
) {
469 reg_idx
= (msix_vf
- 1) * vf
->vf_id
+ qv_info
->ceq_idx
;
470 reg
= (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK
|
471 (v_idx
<< I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT
) |
472 (qv_info
->itr_idx
<< I40E_VPINT_CEQCTL_ITR_INDX_SHIFT
) |
473 (next_q_type
<< I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT
) |
474 (next_q_idx
<< I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT
));
475 wr32(hw
, I40E_VPINT_CEQCTL(reg_idx
), reg
);
477 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
478 reg
= (qv_info
->ceq_idx
&
479 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
480 (I40E_QUEUE_TYPE_PE_CEQ
<<
481 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
482 wr32(hw
, I40E_VPINT_LNKLSTN(reg_idx
), reg
);
485 if (qv_info
->aeq_idx
!= I40E_QUEUE_INVALID_IDX
) {
486 reg
= (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK
|
487 (v_idx
<< I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT
) |
488 (qv_info
->itr_idx
<< I40E_VPINT_AEQCTL_ITR_INDX_SHIFT
));
490 wr32(hw
, I40E_VPINT_AEQCTL(vf
->vf_id
), reg
);
496 kfree(vf
->qvlist_info
);
497 vf
->qvlist_info
= NULL
;
502 * i40e_config_vsi_tx_queue
503 * @vf: pointer to the VF info
504 * @vsi_id: id of VSI as provided by the FW
505 * @vsi_queue_id: vsi relative queue index
506 * @info: config. info
510 static int i40e_config_vsi_tx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
512 struct virtchnl_txq_info
*info
)
514 struct i40e_pf
*pf
= vf
->pf
;
515 struct i40e_hw
*hw
= &pf
->hw
;
516 struct i40e_hmc_obj_txq tx_ctx
;
517 struct i40e_vsi
*vsi
;
522 if (!i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
)) {
526 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
527 vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
533 /* clear the context structure first */
534 memset(&tx_ctx
, 0, sizeof(struct i40e_hmc_obj_txq
));
536 /* only set the required fields */
537 tx_ctx
.base
= info
->dma_ring_addr
/ 128;
538 tx_ctx
.qlen
= info
->ring_len
;
539 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[0]);
540 tx_ctx
.rdylist_act
= 0;
541 tx_ctx
.head_wb_ena
= info
->headwb_enabled
;
542 tx_ctx
.head_wb_addr
= info
->dma_headwb_addr
;
544 /* clear the context in the HMC */
545 ret
= i40e_clear_lan_tx_queue_context(hw
, pf_queue_id
);
547 dev_err(&pf
->pdev
->dev
,
548 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
554 /* set the context in the HMC */
555 ret
= i40e_set_lan_tx_queue_context(hw
, pf_queue_id
, &tx_ctx
);
557 dev_err(&pf
->pdev
->dev
,
558 "Failed to set VF LAN Tx queue context %d error: %d\n",
564 /* associate this queue with the PCI VF function */
565 qtx_ctl
= I40E_QTX_CTL_VF_QUEUE
;
566 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
)
567 & I40E_QTX_CTL_PF_INDX_MASK
);
568 qtx_ctl
|= (((vf
->vf_id
+ hw
->func_caps
.vf_base_id
)
569 << I40E_QTX_CTL_VFVM_INDX_SHIFT
)
570 & I40E_QTX_CTL_VFVM_INDX_MASK
);
571 wr32(hw
, I40E_QTX_CTL(pf_queue_id
), qtx_ctl
);
579 * i40e_config_vsi_rx_queue
580 * @vf: pointer to the VF info
581 * @vsi_id: id of VSI as provided by the FW
582 * @vsi_queue_id: vsi relative queue index
583 * @info: config. info
587 static int i40e_config_vsi_rx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
589 struct virtchnl_rxq_info
*info
)
591 struct i40e_pf
*pf
= vf
->pf
;
592 struct i40e_hw
*hw
= &pf
->hw
;
593 struct i40e_hmc_obj_rxq rx_ctx
;
597 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
599 /* clear the context structure first */
600 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
602 /* only set the required fields */
603 rx_ctx
.base
= info
->dma_ring_addr
/ 128;
604 rx_ctx
.qlen
= info
->ring_len
;
606 if (info
->splithdr_enabled
) {
607 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
609 I40E_RX_SPLIT_TCP_UDP
|
611 /* header length validation */
612 if (info
->hdr_size
> ((2 * 1024) - 64)) {
616 rx_ctx
.hbuff
= info
->hdr_size
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
618 /* set split mode 10b */
619 rx_ctx
.dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
622 /* databuffer length validation */
623 if (info
->databuffer_size
> ((16 * 1024) - 128)) {
627 rx_ctx
.dbuff
= info
->databuffer_size
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
629 /* max pkt. length validation */
630 if (info
->max_pkt_size
>= (16 * 1024) || info
->max_pkt_size
< 64) {
634 rx_ctx
.rxmax
= info
->max_pkt_size
;
636 /* enable 32bytes desc always */
640 rx_ctx
.lrxqthresh
= 1;
645 /* clear the context in the HMC */
646 ret
= i40e_clear_lan_rx_queue_context(hw
, pf_queue_id
);
648 dev_err(&pf
->pdev
->dev
,
649 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
655 /* set the context in the HMC */
656 ret
= i40e_set_lan_rx_queue_context(hw
, pf_queue_id
, &rx_ctx
);
658 dev_err(&pf
->pdev
->dev
,
659 "Failed to set VF LAN Rx queue context %d error: %d\n",
671 * @vf: pointer to the VF info
672 * @type: type of VSI to allocate
674 * alloc VF vsi context & resources
676 static int i40e_alloc_vsi_res(struct i40e_vf
*vf
, enum i40e_vsi_type type
)
678 struct i40e_mac_filter
*f
= NULL
;
679 struct i40e_pf
*pf
= vf
->pf
;
680 struct i40e_vsi
*vsi
;
683 vsi
= i40e_vsi_setup(pf
, type
, pf
->vsi
[pf
->lan_vsi
]->seid
, vf
->vf_id
);
686 dev_err(&pf
->pdev
->dev
,
687 "add vsi failed for VF %d, aq_err %d\n",
688 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
690 goto error_alloc_vsi_res
;
692 if (type
== I40E_VSI_SRIOV
) {
693 u64 hena
= i40e_pf_get_default_rss_hena(pf
);
694 u8 broadcast
[ETH_ALEN
];
696 vf
->lan_vsi_idx
= vsi
->idx
;
697 vf
->lan_vsi_id
= vsi
->id
;
698 /* If the port VLAN has been configured and then the
699 * VF driver was removed then the VSI port VLAN
700 * configuration was destroyed. Check if there is
701 * a port VLAN and restore the VSI configuration if
704 if (vf
->port_vlan_id
)
705 i40e_vsi_add_pvid(vsi
, vf
->port_vlan_id
);
707 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
708 if (is_valid_ether_addr(vf
->default_lan_addr
.addr
)) {
709 f
= i40e_add_mac_filter(vsi
,
710 vf
->default_lan_addr
.addr
);
712 dev_info(&pf
->pdev
->dev
,
713 "Could not add MAC filter %pM for VF %d\n",
714 vf
->default_lan_addr
.addr
, vf
->vf_id
);
716 eth_broadcast_addr(broadcast
);
717 f
= i40e_add_mac_filter(vsi
, broadcast
);
719 dev_info(&pf
->pdev
->dev
,
720 "Could not allocate VF broadcast filter\n");
721 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
722 wr32(&pf
->hw
, I40E_VFQF_HENA1(0, vf
->vf_id
), (u32
)hena
);
723 wr32(&pf
->hw
, I40E_VFQF_HENA1(1, vf
->vf_id
), (u32
)(hena
>> 32));
726 /* program mac filter */
727 ret
= i40e_sync_vsi_filters(vsi
);
729 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
731 /* Set VF bandwidth if specified */
733 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
734 vf
->tx_rate
/ 50, 0, NULL
);
736 dev_err(&pf
->pdev
->dev
, "Unable to set tx rate, VF %d, error code %d.\n",
745 * i40e_enable_vf_mappings
746 * @vf: pointer to the VF info
750 static void i40e_enable_vf_mappings(struct i40e_vf
*vf
)
752 struct i40e_pf
*pf
= vf
->pf
;
753 struct i40e_hw
*hw
= &pf
->hw
;
754 u32 reg
, total_queue_pairs
= 0;
757 /* Tell the hardware we're using noncontiguous mapping. HW requires
758 * that VF queues be mapped using this method, even when they are
759 * contiguous in real life
761 i40e_write_rx_ctl(hw
, I40E_VSILAN_QBASE(vf
->lan_vsi_id
),
762 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK
);
764 /* enable VF vplan_qtable mappings */
765 reg
= I40E_VPLAN_MAPENA_TXRX_ENA_MASK
;
766 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), reg
);
768 /* map PF queues to VF queues */
769 for (j
= 0; j
< pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
; j
++) {
770 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
, j
);
772 reg
= (qid
& I40E_VPLAN_QTABLE_QINDEX_MASK
);
773 wr32(hw
, I40E_VPLAN_QTABLE(total_queue_pairs
, vf
->vf_id
), reg
);
777 /* map PF queues to VSI */
778 for (j
= 0; j
< 7; j
++) {
779 if (j
* 2 >= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
) {
780 reg
= 0x07FF07FF; /* unused */
782 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
785 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
789 i40e_write_rx_ctl(hw
, I40E_VSILAN_QTABLE(j
, vf
->lan_vsi_id
),
797 * i40e_disable_vf_mappings
798 * @vf: pointer to the VF info
800 * disable VF mappings
802 static void i40e_disable_vf_mappings(struct i40e_vf
*vf
)
804 struct i40e_pf
*pf
= vf
->pf
;
805 struct i40e_hw
*hw
= &pf
->hw
;
808 /* disable qp mappings */
809 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), 0);
810 for (i
= 0; i
< I40E_MAX_VSI_QP
; i
++)
811 wr32(hw
, I40E_VPLAN_QTABLE(i
, vf
->vf_id
),
812 I40E_QUEUE_END_OF_LIST
);
818 * @vf: pointer to the VF info
822 static void i40e_free_vf_res(struct i40e_vf
*vf
)
824 struct i40e_pf
*pf
= vf
->pf
;
825 struct i40e_hw
*hw
= &pf
->hw
;
829 /* Start by disabling VF's configuration API to prevent the OS from
830 * accessing the VF's VSI after it's freed / invalidated.
832 clear_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
);
834 /* It's possible the VF had requeuested more queues than the default so
835 * do the accounting here when we're about to free them.
837 if (vf
->num_queue_pairs
> I40E_DEFAULT_QUEUES_PER_VF
) {
838 pf
->queues_left
+= vf
->num_queue_pairs
-
839 I40E_DEFAULT_QUEUES_PER_VF
;
842 /* free vsi & disconnect it from the parent uplink */
843 if (vf
->lan_vsi_idx
) {
844 i40e_vsi_release(pf
->vsi
[vf
->lan_vsi_idx
]);
849 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
851 /* disable interrupts so the VF starts in a known state */
852 for (i
= 0; i
< msix_vf
; i
++) {
853 /* format is same for both registers */
855 reg_idx
= I40E_VFINT_DYN_CTL0(vf
->vf_id
);
857 reg_idx
= I40E_VFINT_DYN_CTLN(((msix_vf
- 1) *
860 wr32(hw
, reg_idx
, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
864 /* clear the irq settings */
865 for (i
= 0; i
< msix_vf
; i
++) {
866 /* format is same for both registers */
868 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
870 reg_idx
= I40E_VPINT_LNKLSTN(((msix_vf
- 1) *
873 reg
= (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
|
874 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
);
875 wr32(hw
, reg_idx
, reg
);
878 /* reset some of the state variables keeping track of the resources */
879 vf
->num_queue_pairs
= 0;
880 clear_bit(I40E_VF_STATE_MC_PROMISC
, &vf
->vf_states
);
881 clear_bit(I40E_VF_STATE_UC_PROMISC
, &vf
->vf_states
);
886 * @vf: pointer to the VF info
888 * allocate VF resources
890 static int i40e_alloc_vf_res(struct i40e_vf
*vf
)
892 struct i40e_pf
*pf
= vf
->pf
;
893 int total_queue_pairs
= 0;
896 if (vf
->num_req_queues
&&
897 vf
->num_req_queues
<= pf
->queues_left
+ I40E_DEFAULT_QUEUES_PER_VF
)
898 pf
->num_vf_qps
= vf
->num_req_queues
;
900 pf
->num_vf_qps
= I40E_DEFAULT_QUEUES_PER_VF
;
902 /* allocate hw vsi context & associated resources */
903 ret
= i40e_alloc_vsi_res(vf
, I40E_VSI_SRIOV
);
906 total_queue_pairs
+= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
908 /* We account for each VF to get a default number of queue pairs. If
909 * the VF has now requested more, we need to account for that to make
910 * certain we never request more queues than we actually have left in
913 if (total_queue_pairs
> I40E_DEFAULT_QUEUES_PER_VF
)
915 total_queue_pairs
- I40E_DEFAULT_QUEUES_PER_VF
;
918 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
920 clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
922 /* store the total qps number for the runtime
925 vf
->num_queue_pairs
= total_queue_pairs
;
927 /* VF is now completely initialized */
928 set_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
);
932 i40e_free_vf_res(vf
);
937 #define VF_DEVICE_STATUS 0xAA
938 #define VF_TRANS_PENDING_MASK 0x20
940 * i40e_quiesce_vf_pci
941 * @vf: pointer to the VF structure
943 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
944 * if the transactions never clear.
946 static int i40e_quiesce_vf_pci(struct i40e_vf
*vf
)
948 struct i40e_pf
*pf
= vf
->pf
;
949 struct i40e_hw
*hw
= &pf
->hw
;
953 vf_abs_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
955 wr32(hw
, I40E_PF_PCI_CIAA
,
956 VF_DEVICE_STATUS
| (vf_abs_id
<< I40E_PF_PCI_CIAA_VF_NUM_SHIFT
));
957 for (i
= 0; i
< 100; i
++) {
958 reg
= rd32(hw
, I40E_PF_PCI_CIAD
);
959 if ((reg
& VF_TRANS_PENDING_MASK
) == 0)
967 * i40e_trigger_vf_reset
968 * @vf: pointer to the VF structure
969 * @flr: VFLR was issued or not
971 * Trigger hardware to start a reset for a particular VF. Expects the caller
972 * to wait the proper amount of time to allow hardware to reset the VF before
973 * it cleans up and restores VF functionality.
975 static void i40e_trigger_vf_reset(struct i40e_vf
*vf
, bool flr
)
977 struct i40e_pf
*pf
= vf
->pf
;
978 struct i40e_hw
*hw
= &pf
->hw
;
979 u32 reg
, reg_idx
, bit_idx
;
982 clear_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
);
984 /* Disable VF's configuration API during reset. The flag is re-enabled
985 * in i40e_alloc_vf_res(), when it's safe again to access VF's VSI.
986 * It's normally disabled in i40e_free_vf_res(), but it's safer
987 * to do it earlier to give some time to finish to any VF config
988 * functions that may still be running at this point.
990 clear_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
);
992 /* In the case of a VFLR, the HW has already reset the VF and we
993 * just need to clean up, so don't hit the VFRTRIG register.
996 /* reset VF using VPGEN_VFRTRIG reg */
997 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
998 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
999 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
1002 /* clear the VFLR bit in GLGEN_VFLRSTAT */
1003 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf
->vf_id
) / 32;
1004 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf
->vf_id
) % 32;
1005 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
1008 if (i40e_quiesce_vf_pci(vf
))
1009 dev_err(&pf
->pdev
->dev
, "VF %d PCI transactions stuck\n",
1014 * i40e_cleanup_reset_vf
1015 * @vf: pointer to the VF structure
1017 * Cleanup a VF after the hardware reset is finished. Expects the caller to
1018 * have verified whether the reset is finished properly, and ensure the
1019 * minimum amount of wait time has passed.
1021 static void i40e_cleanup_reset_vf(struct i40e_vf
*vf
)
1023 struct i40e_pf
*pf
= vf
->pf
;
1024 struct i40e_hw
*hw
= &pf
->hw
;
1027 /* free VF resources to begin resetting the VSI state */
1028 i40e_free_vf_res(vf
);
1030 /* Enable hardware by clearing the reset bit in the VPGEN_VFRTRIG reg.
1031 * By doing this we allow HW to access VF memory at any point. If we
1032 * did it any sooner, HW could access memory while it was being freed
1033 * in i40e_free_vf_res(), causing an IOMMU fault.
1035 * On the other hand, this needs to be done ASAP, because the VF driver
1036 * is waiting for this to happen and may report a timeout. It's
1037 * harmless, but it gets logged into Guest OS kernel log, so best avoid
1040 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
1041 reg
&= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
1042 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
1044 /* reallocate VF resources to finish resetting the VSI state */
1045 if (!i40e_alloc_vf_res(vf
)) {
1046 int abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1047 i40e_enable_vf_mappings(vf
);
1048 set_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
);
1049 clear_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
);
1050 /* Do not notify the client during VF init */
1051 if (!test_and_clear_bit(I40E_VF_STATE_PRE_ENABLE
,
1053 i40e_notify_client_of_vf_reset(pf
, abs_vf_id
);
1057 /* Tell the VF driver the reset is done. This needs to be done only
1058 * after VF has been fully initialized, because the VF driver may
1059 * request resources immediately after setting this flag.
1061 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), VIRTCHNL_VFR_VFACTIVE
);
1066 * @vf: pointer to the VF structure
1067 * @flr: VFLR was issued or not
1069 * Returns true if the VF is reset, false otherwise.
1071 bool i40e_reset_vf(struct i40e_vf
*vf
, bool flr
)
1073 struct i40e_pf
*pf
= vf
->pf
;
1074 struct i40e_hw
*hw
= &pf
->hw
;
1079 /* If the VFs have been disabled, this means something else is
1080 * resetting the VF, so we shouldn't continue.
1082 if (test_and_set_bit(__I40E_VF_DISABLE
, pf
->state
))
1085 i40e_trigger_vf_reset(vf
, flr
);
1087 /* poll VPGEN_VFRSTAT reg to make sure
1088 * that reset is complete
1090 for (i
= 0; i
< 10; i
++) {
1091 /* VF reset requires driver to first reset the VF and then
1092 * poll the status register to make sure that the reset
1093 * completed successfully. Due to internal HW FIFO flushes,
1094 * we must wait 10ms before the register will be valid.
1096 usleep_range(10000, 20000);
1097 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
1098 if (reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
) {
1105 usleep_range(10000, 20000);
1108 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
1110 usleep_range(10000, 20000);
1112 /* On initial reset, we don't have any queues to disable */
1113 if (vf
->lan_vsi_idx
!= 0)
1114 i40e_vsi_stop_rings(pf
->vsi
[vf
->lan_vsi_idx
]);
1116 i40e_cleanup_reset_vf(vf
);
1119 clear_bit(__I40E_VF_DISABLE
, pf
->state
);
1125 * i40e_reset_all_vfs
1126 * @pf: pointer to the PF structure
1127 * @flr: VFLR was issued or not
1129 * Reset all allocated VFs in one go. First, tell the hardware to reset each
1130 * VF, then do all the waiting in one chunk, and finally finish restoring each
1131 * VF after the wait. This is useful during PF routines which need to reset
1132 * all VFs, as otherwise it must perform these resets in a serialized fashion.
1134 * Returns true if any VFs were reset, and false otherwise.
1136 bool i40e_reset_all_vfs(struct i40e_pf
*pf
, bool flr
)
1138 struct i40e_hw
*hw
= &pf
->hw
;
1143 /* If we don't have any VFs, then there is nothing to reset */
1144 if (!pf
->num_alloc_vfs
)
1147 /* If VFs have been disabled, there is no need to reset */
1148 if (test_and_set_bit(__I40E_VF_DISABLE
, pf
->state
))
1151 /* Begin reset on all VFs at once */
1152 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
1153 i40e_trigger_vf_reset(&pf
->vf
[v
], flr
);
1155 /* HW requires some time to make sure it can flush the FIFO for a VF
1156 * when it resets it. Poll the VPGEN_VFRSTAT register for each VF in
1157 * sequence to make sure that it has completed. We'll keep track of
1158 * the VFs using a simple iterator that increments once that VF has
1159 * finished resetting.
1161 for (i
= 0, v
= 0; i
< 10 && v
< pf
->num_alloc_vfs
; i
++) {
1162 usleep_range(10000, 20000);
1164 /* Check each VF in sequence, beginning with the VF to fail
1165 * the previous check.
1167 while (v
< pf
->num_alloc_vfs
) {
1169 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
1170 if (!(reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
))
1173 /* If the current VF has finished resetting, move on
1174 * to the next VF in sequence.
1181 usleep_range(10000, 20000);
1183 /* Display a warning if at least one VF didn't manage to reset in
1184 * time, but continue on with the operation.
1186 if (v
< pf
->num_alloc_vfs
)
1187 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
1189 usleep_range(10000, 20000);
1191 /* Begin disabling all the rings associated with VFs, but do not wait
1194 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++) {
1195 /* On initial reset, we don't have any queues to disable */
1196 if (pf
->vf
[v
].lan_vsi_idx
== 0)
1199 i40e_vsi_stop_rings_no_wait(pf
->vsi
[pf
->vf
[v
].lan_vsi_idx
]);
1202 /* Now that we've notified HW to disable all of the VF rings, wait
1203 * until they finish.
1205 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++) {
1206 /* On initial reset, we don't have any queues to disable */
1207 if (pf
->vf
[v
].lan_vsi_idx
== 0)
1210 i40e_vsi_wait_queues_disabled(pf
->vsi
[pf
->vf
[v
].lan_vsi_idx
]);
1213 /* Hw may need up to 50ms to finish disabling the RX queues. We
1214 * minimize the wait by delaying only once for all VFs.
1218 /* Finish the reset on each VF */
1219 for (v
= 0; v
< pf
->num_alloc_vfs
; v
++)
1220 i40e_cleanup_reset_vf(&pf
->vf
[v
]);
1223 clear_bit(__I40E_VF_DISABLE
, pf
->state
);
1230 * @pf: pointer to the PF structure
1234 void i40e_free_vfs(struct i40e_pf
*pf
)
1236 struct i40e_hw
*hw
= &pf
->hw
;
1237 u32 reg_idx
, bit_idx
;
1242 while (test_and_set_bit(__I40E_VF_DISABLE
, pf
->state
))
1243 usleep_range(1000, 2000);
1245 i40e_notify_client_of_vf_enable(pf
, 0);
1247 /* Amortize wait time by stopping all VFs at the same time */
1248 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++) {
1249 if (test_bit(I40E_VF_STATE_INIT
, &pf
->vf
[i
].vf_states
))
1252 i40e_vsi_stop_rings_no_wait(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
]);
1255 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++) {
1256 if (test_bit(I40E_VF_STATE_INIT
, &pf
->vf
[i
].vf_states
))
1259 i40e_vsi_wait_queues_disabled(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
]);
1262 /* Disable IOV before freeing resources. This lets any VF drivers
1263 * running in the host get themselves cleaned up before we yank
1264 * the carpet out from underneath their feet.
1266 if (!pci_vfs_assigned(pf
->pdev
))
1267 pci_disable_sriov(pf
->pdev
);
1269 dev_warn(&pf
->pdev
->dev
, "VFs are assigned - not disabling SR-IOV\n");
1271 /* free up VF resources */
1272 tmp
= pf
->num_alloc_vfs
;
1273 pf
->num_alloc_vfs
= 0;
1274 for (i
= 0; i
< tmp
; i
++) {
1275 if (test_bit(I40E_VF_STATE_INIT
, &pf
->vf
[i
].vf_states
))
1276 i40e_free_vf_res(&pf
->vf
[i
]);
1277 /* disable qp mappings */
1278 i40e_disable_vf_mappings(&pf
->vf
[i
]);
1284 /* This check is for when the driver is unloaded while VFs are
1285 * assigned. Setting the number of VFs to 0 through sysfs is caught
1286 * before this function ever gets called.
1288 if (!pci_vfs_assigned(pf
->pdev
)) {
1289 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
1290 * work correctly when SR-IOV gets re-enabled.
1292 for (vf_id
= 0; vf_id
< tmp
; vf_id
++) {
1293 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
1294 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
1295 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
1298 clear_bit(__I40E_VF_DISABLE
, pf
->state
);
1301 #ifdef CONFIG_PCI_IOV
1304 * @pf: pointer to the PF structure
1305 * @num_alloc_vfs: number of VFs to allocate
1307 * allocate VF resources
1309 int i40e_alloc_vfs(struct i40e_pf
*pf
, u16 num_alloc_vfs
)
1311 struct i40e_vf
*vfs
;
1314 /* Disable interrupt 0 so we don't try to handle the VFLR. */
1315 i40e_irq_dynamic_disable_icr0(pf
);
1317 /* Check to see if we're just allocating resources for extant VFs */
1318 if (pci_num_vf(pf
->pdev
) != num_alloc_vfs
) {
1319 ret
= pci_enable_sriov(pf
->pdev
, num_alloc_vfs
);
1321 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1322 pf
->num_alloc_vfs
= 0;
1326 /* allocate memory */
1327 vfs
= kcalloc(num_alloc_vfs
, sizeof(struct i40e_vf
), GFP_KERNEL
);
1334 /* apply default profile */
1335 for (i
= 0; i
< num_alloc_vfs
; i
++) {
1337 vfs
[i
].parent_type
= I40E_SWITCH_ELEMENT_TYPE_VEB
;
1340 /* assign default capabilities */
1341 set_bit(I40E_VIRTCHNL_VF_CAP_L2
, &vfs
[i
].vf_caps
);
1342 vfs
[i
].spoofchk
= true;
1344 set_bit(I40E_VF_STATE_PRE_ENABLE
, &vfs
[i
].vf_states
);
1347 pf
->num_alloc_vfs
= num_alloc_vfs
;
1349 /* VF resources get allocated during reset */
1350 i40e_reset_all_vfs(pf
, false);
1352 i40e_notify_client_of_vf_enable(pf
, num_alloc_vfs
);
1358 /* Re-enable interrupt 0. */
1359 i40e_irq_dynamic_enable_icr0(pf
);
1365 * i40e_pci_sriov_enable
1366 * @pdev: pointer to a pci_dev structure
1367 * @num_vfs: number of VFs to allocate
1369 * Enable or change the number of VFs
1371 static int i40e_pci_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
1373 #ifdef CONFIG_PCI_IOV
1374 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1375 int pre_existing_vfs
= pci_num_vf(pdev
);
1378 if (test_bit(__I40E_TESTING
, pf
->state
)) {
1379 dev_warn(&pdev
->dev
,
1380 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1385 if (pre_existing_vfs
&& pre_existing_vfs
!= num_vfs
)
1387 else if (pre_existing_vfs
&& pre_existing_vfs
== num_vfs
)
1390 if (num_vfs
> pf
->num_req_vfs
) {
1391 dev_warn(&pdev
->dev
, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1392 num_vfs
, pf
->num_req_vfs
);
1397 dev_info(&pdev
->dev
, "Allocating %d VFs.\n", num_vfs
);
1398 err
= i40e_alloc_vfs(pf
, num_vfs
);
1400 dev_warn(&pdev
->dev
, "Failed to enable SR-IOV: %d\n", err
);
1414 * i40e_pci_sriov_configure
1415 * @pdev: pointer to a pci_dev structure
1416 * @num_vfs: number of VFs to allocate
1418 * Enable or change the number of VFs. Called when the user updates the number
1421 int i40e_pci_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
1423 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1426 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
1427 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
1428 i40e_do_reset_safe(pf
, I40E_PF_RESET_FLAG
);
1430 return i40e_pci_sriov_enable(pdev
, num_vfs
);
1433 if (!pci_vfs_assigned(pf
->pdev
)) {
1435 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1436 i40e_do_reset_safe(pf
, I40E_PF_RESET_FLAG
);
1438 dev_warn(&pdev
->dev
, "Unable to free VFs because some are assigned to VMs.\n");
1444 /***********************virtual channel routines******************/
1447 * i40e_vc_send_msg_to_vf
1448 * @vf: pointer to the VF info
1449 * @v_opcode: virtual channel opcode
1450 * @v_retval: virtual channel return value
1451 * @msg: pointer to the msg buffer
1452 * @msglen: msg length
1456 static int i40e_vc_send_msg_to_vf(struct i40e_vf
*vf
, u32 v_opcode
,
1457 u32 v_retval
, u8
*msg
, u16 msglen
)
1464 /* validate the request */
1465 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
1470 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1472 /* single place to detect unsuccessful return values */
1474 vf
->num_invalid_msgs
++;
1475 dev_info(&pf
->pdev
->dev
, "VF %d failed opcode %d, retval: %d\n",
1476 vf
->vf_id
, v_opcode
, v_retval
);
1477 if (vf
->num_invalid_msgs
>
1478 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED
) {
1479 dev_err(&pf
->pdev
->dev
,
1480 "Number of invalid messages exceeded for VF %d\n",
1482 dev_err(&pf
->pdev
->dev
, "Use PF Control I/F to enable the VF\n");
1483 set_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
);
1486 vf
->num_valid_msgs
++;
1487 /* reset the invalid counter, if a valid message is received. */
1488 vf
->num_invalid_msgs
= 0;
1491 aq_ret
= i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
1494 dev_info(&pf
->pdev
->dev
,
1495 "Unable to send the message to VF %d aq_err %d\n",
1496 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
1504 * i40e_vc_send_resp_to_vf
1505 * @vf: pointer to the VF info
1506 * @opcode: operation code
1507 * @retval: return value
1509 * send resp msg to VF
1511 static int i40e_vc_send_resp_to_vf(struct i40e_vf
*vf
,
1512 enum virtchnl_ops opcode
,
1515 return i40e_vc_send_msg_to_vf(vf
, opcode
, retval
, NULL
, 0);
1519 * i40e_vc_get_version_msg
1520 * @vf: pointer to the VF info
1522 * called from the VF to request the API version used by the PF
1524 static int i40e_vc_get_version_msg(struct i40e_vf
*vf
, u8
*msg
)
1526 struct virtchnl_version_info info
= {
1527 VIRTCHNL_VERSION_MAJOR
, VIRTCHNL_VERSION_MINOR
1530 vf
->vf_ver
= *(struct virtchnl_version_info
*)msg
;
1531 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1532 if (VF_IS_V10(&vf
->vf_ver
))
1533 info
.minor
= VIRTCHNL_VERSION_MINOR_NO_VF_CAPS
;
1534 return i40e_vc_send_msg_to_vf(vf
, VIRTCHNL_OP_VERSION
,
1535 I40E_SUCCESS
, (u8
*)&info
,
1536 sizeof(struct virtchnl_version_info
));
1540 * i40e_vc_get_vf_resources_msg
1541 * @vf: pointer to the VF info
1542 * @msg: pointer to the msg buffer
1543 * @msglen: msg length
1545 * called from the VF to request its resources
1547 static int i40e_vc_get_vf_resources_msg(struct i40e_vf
*vf
, u8
*msg
)
1549 struct virtchnl_vf_resource
*vfres
= NULL
;
1550 struct i40e_pf
*pf
= vf
->pf
;
1551 i40e_status aq_ret
= 0;
1552 struct i40e_vsi
*vsi
;
1557 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
1558 aq_ret
= I40E_ERR_PARAM
;
1562 len
= (sizeof(struct virtchnl_vf_resource
) +
1563 sizeof(struct virtchnl_vsi_resource
) * num_vsis
);
1565 vfres
= kzalloc(len
, GFP_KERNEL
);
1567 aq_ret
= I40E_ERR_NO_MEMORY
;
1571 if (VF_IS_V11(&vf
->vf_ver
))
1572 vf
->driver_caps
= *(u32
*)msg
;
1574 vf
->driver_caps
= VIRTCHNL_VF_OFFLOAD_L2
|
1575 VIRTCHNL_VF_OFFLOAD_RSS_REG
|
1576 VIRTCHNL_VF_OFFLOAD_VLAN
;
1578 vfres
->vf_cap_flags
= VIRTCHNL_VF_OFFLOAD_L2
;
1579 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1580 if (!vsi
->info
.pvid
)
1581 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_VLAN
;
1583 if (i40e_vf_client_capable(pf
, vf
->vf_id
) &&
1584 (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_IWARP
)) {
1585 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_IWARP
;
1586 set_bit(I40E_VF_STATE_IWARPENA
, &vf
->vf_states
);
1588 clear_bit(I40E_VF_STATE_IWARPENA
, &vf
->vf_states
);
1591 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
1592 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_RSS_PF
;
1594 if ((pf
->hw_features
& I40E_HW_RSS_AQ_CAPABLE
) &&
1595 (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_RSS_AQ
))
1596 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_RSS_AQ
;
1598 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_RSS_REG
;
1601 if (pf
->hw_features
& I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE
) {
1602 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1603 vfres
->vf_cap_flags
|=
1604 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
;
1607 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_ENCAP
)
1608 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_ENCAP
;
1610 if ((pf
->hw_features
& I40E_HW_OUTER_UDP_CSUM_CAPABLE
) &&
1611 (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
))
1612 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
;
1614 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_RX_POLLING
) {
1615 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
1616 dev_err(&pf
->pdev
->dev
,
1617 "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
1619 aq_ret
= I40E_ERR_PARAM
;
1622 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_RX_POLLING
;
1625 if (pf
->hw_features
& I40E_HW_WB_ON_ITR_CAPABLE
) {
1626 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
1627 vfres
->vf_cap_flags
|=
1628 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
;
1631 if (vf
->driver_caps
& VIRTCHNL_VF_OFFLOAD_REQ_QUEUES
)
1632 vfres
->vf_cap_flags
|= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES
;
1634 vfres
->num_vsis
= num_vsis
;
1635 vfres
->num_queue_pairs
= vf
->num_queue_pairs
;
1636 vfres
->max_vectors
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
1637 vfres
->rss_key_size
= I40E_HKEY_ARRAY_SIZE
;
1638 vfres
->rss_lut_size
= I40E_VF_HLUT_ARRAY_SIZE
;
1640 if (vf
->lan_vsi_idx
) {
1641 vfres
->vsi_res
[0].vsi_id
= vf
->lan_vsi_id
;
1642 vfres
->vsi_res
[0].vsi_type
= VIRTCHNL_VSI_SRIOV
;
1643 vfres
->vsi_res
[0].num_queue_pairs
= vsi
->alloc_queue_pairs
;
1644 /* VFs only use TC 0 */
1645 vfres
->vsi_res
[0].qset_handle
1646 = le16_to_cpu(vsi
->info
.qs_handle
[0]);
1647 ether_addr_copy(vfres
->vsi_res
[0].default_mac_addr
,
1648 vf
->default_lan_addr
.addr
);
1650 set_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
);
1653 /* send the response back to the VF */
1654 ret
= i40e_vc_send_msg_to_vf(vf
, VIRTCHNL_OP_GET_VF_RESOURCES
,
1655 aq_ret
, (u8
*)vfres
, len
);
1662 * i40e_vc_reset_vf_msg
1663 * @vf: pointer to the VF info
1664 * @msg: pointer to the msg buffer
1665 * @msglen: msg length
1667 * called from the VF to reset itself,
1668 * unlike other virtchnl messages, PF driver
1669 * doesn't send the response back to the VF
1671 static void i40e_vc_reset_vf_msg(struct i40e_vf
*vf
)
1673 if (test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
))
1674 i40e_reset_vf(vf
, false);
1678 * i40e_getnum_vf_vsi_vlan_filters
1679 * @vsi: pointer to the vsi
1681 * called to get the number of VLANs offloaded on this VF
1683 static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi
*vsi
)
1685 struct i40e_mac_filter
*f
;
1686 int num_vlans
= 0, bkt
;
1688 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
1689 if (f
->vlan
>= 0 && f
->vlan
<= I40E_MAX_VLANID
)
1697 * i40e_vc_config_promiscuous_mode_msg
1698 * @vf: pointer to the VF info
1699 * @msg: pointer to the msg buffer
1700 * @msglen: msg length
1702 * called from the VF to configure the promiscuous mode of
1705 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf
*vf
,
1706 u8
*msg
, u16 msglen
)
1708 struct virtchnl_promisc_info
*info
=
1709 (struct virtchnl_promisc_info
*)msg
;
1710 struct i40e_pf
*pf
= vf
->pf
;
1711 struct i40e_hw
*hw
= &pf
->hw
;
1712 struct i40e_mac_filter
*f
;
1713 i40e_status aq_ret
= 0;
1714 bool allmulti
= false;
1715 struct i40e_vsi
*vsi
;
1716 bool alluni
= false;
1720 vsi
= i40e_find_vsi_from_id(pf
, info
->vsi_id
);
1721 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
1722 !i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
) ||
1724 aq_ret
= I40E_ERR_PARAM
;
1727 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
1728 dev_err(&pf
->pdev
->dev
,
1729 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1731 /* Lie to the VF on purpose. */
1735 /* Multicast promiscuous handling*/
1736 if (info
->flags
& FLAG_VF_MULTICAST_PROMISC
)
1739 if (vf
->port_vlan_id
) {
1740 aq_ret
= i40e_aq_set_vsi_mc_promisc_on_vlan(hw
, vsi
->seid
,
1744 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi
)) {
1745 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
1746 if (f
->vlan
< 0 || f
->vlan
> I40E_MAX_VLANID
)
1748 aq_ret
= i40e_aq_set_vsi_mc_promisc_on_vlan(hw
,
1753 aq_err
= pf
->hw
.aq
.asq_last_status
;
1755 dev_err(&pf
->pdev
->dev
,
1756 "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1758 i40e_stat_str(&pf
->hw
, aq_ret
),
1759 i40e_aq_str(&pf
->hw
, aq_err
));
1764 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(hw
, vsi
->seid
,
1766 aq_err
= pf
->hw
.aq
.asq_last_status
;
1768 dev_err(&pf
->pdev
->dev
,
1769 "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1771 i40e_stat_str(&pf
->hw
, aq_ret
),
1772 i40e_aq_str(&pf
->hw
, aq_err
));
1778 dev_info(&pf
->pdev
->dev
,
1779 "VF %d successfully set multicast promiscuous mode\n",
1782 set_bit(I40E_VF_STATE_MC_PROMISC
, &vf
->vf_states
);
1784 clear_bit(I40E_VF_STATE_MC_PROMISC
, &vf
->vf_states
);
1787 if (info
->flags
& FLAG_VF_UNICAST_PROMISC
)
1789 if (vf
->port_vlan_id
) {
1790 aq_ret
= i40e_aq_set_vsi_uc_promisc_on_vlan(hw
, vsi
->seid
,
1794 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi
)) {
1795 hash_for_each(vsi
->mac_filter_hash
, bkt
, f
, hlist
) {
1796 if (f
->vlan
< 0 || f
->vlan
> I40E_MAX_VLANID
)
1798 aq_ret
= i40e_aq_set_vsi_uc_promisc_on_vlan(hw
,
1803 aq_err
= pf
->hw
.aq
.asq_last_status
;
1805 dev_err(&pf
->pdev
->dev
,
1806 "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1808 i40e_stat_str(&pf
->hw
, aq_ret
),
1809 i40e_aq_str(&pf
->hw
, aq_err
));
1812 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(hw
, vsi
->seid
,
1815 aq_err
= pf
->hw
.aq
.asq_last_status
;
1817 dev_err(&pf
->pdev
->dev
,
1818 "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1819 vf
->vf_id
, info
->flags
,
1820 i40e_stat_str(&pf
->hw
, aq_ret
),
1821 i40e_aq_str(&pf
->hw
, aq_err
));
1827 dev_info(&pf
->pdev
->dev
,
1828 "VF %d successfully set unicast promiscuous mode\n",
1831 set_bit(I40E_VF_STATE_UC_PROMISC
, &vf
->vf_states
);
1833 clear_bit(I40E_VF_STATE_UC_PROMISC
, &vf
->vf_states
);
1837 /* send the response to the VF */
1838 return i40e_vc_send_resp_to_vf(vf
,
1839 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
1844 * i40e_vc_config_queues_msg
1845 * @vf: pointer to the VF info
1846 * @msg: pointer to the msg buffer
1847 * @msglen: msg length
1849 * called from the VF to configure the rx/tx
1852 static int i40e_vc_config_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1854 struct virtchnl_vsi_queue_config_info
*qci
=
1855 (struct virtchnl_vsi_queue_config_info
*)msg
;
1856 struct virtchnl_queue_pair_info
*qpi
;
1857 struct i40e_pf
*pf
= vf
->pf
;
1858 u16 vsi_id
, vsi_queue_id
;
1859 i40e_status aq_ret
= 0;
1862 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
1863 aq_ret
= I40E_ERR_PARAM
;
1867 vsi_id
= qci
->vsi_id
;
1868 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1869 aq_ret
= I40E_ERR_PARAM
;
1872 for (i
= 0; i
< qci
->num_queue_pairs
; i
++) {
1873 qpi
= &qci
->qpair
[i
];
1874 vsi_queue_id
= qpi
->txq
.queue_id
;
1875 if ((qpi
->txq
.vsi_id
!= vsi_id
) ||
1876 (qpi
->rxq
.vsi_id
!= vsi_id
) ||
1877 (qpi
->rxq
.queue_id
!= vsi_queue_id
) ||
1878 !i40e_vc_isvalid_queue_id(vf
, vsi_id
, vsi_queue_id
)) {
1879 aq_ret
= I40E_ERR_PARAM
;
1883 if (i40e_config_vsi_rx_queue(vf
, vsi_id
, vsi_queue_id
,
1885 i40e_config_vsi_tx_queue(vf
, vsi_id
, vsi_queue_id
,
1887 aq_ret
= I40E_ERR_PARAM
;
1891 /* set vsi num_queue_pairs in use to num configured by VF */
1892 pf
->vsi
[vf
->lan_vsi_idx
]->num_queue_pairs
= qci
->num_queue_pairs
;
1895 /* send the response to the VF */
1896 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
1901 * i40e_vc_config_irq_map_msg
1902 * @vf: pointer to the VF info
1903 * @msg: pointer to the msg buffer
1904 * @msglen: msg length
1906 * called from the VF to configure the irq to
1909 static int i40e_vc_config_irq_map_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1911 struct virtchnl_irq_map_info
*irqmap_info
=
1912 (struct virtchnl_irq_map_info
*)msg
;
1913 struct virtchnl_vector_map
*map
;
1914 u16 vsi_id
, vsi_queue_id
, vector_id
;
1915 i40e_status aq_ret
= 0;
1916 unsigned long tempmap
;
1919 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
1920 aq_ret
= I40E_ERR_PARAM
;
1924 for (i
= 0; i
< irqmap_info
->num_vectors
; i
++) {
1925 map
= &irqmap_info
->vecmap
[i
];
1927 vector_id
= map
->vector_id
;
1928 vsi_id
= map
->vsi_id
;
1929 /* validate msg params */
1930 if (!i40e_vc_isvalid_vector_id(vf
, vector_id
) ||
1931 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1932 aq_ret
= I40E_ERR_PARAM
;
1936 /* lookout for the invalid queue index */
1937 tempmap
= map
->rxq_map
;
1938 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1939 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1941 aq_ret
= I40E_ERR_PARAM
;
1946 tempmap
= map
->txq_map
;
1947 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1948 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1950 aq_ret
= I40E_ERR_PARAM
;
1955 i40e_config_irq_link_list(vf
, vsi_id
, map
);
1958 /* send the response to the VF */
1959 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_CONFIG_IRQ_MAP
,
1964 * i40e_vc_enable_queues_msg
1965 * @vf: pointer to the VF info
1966 * @msg: pointer to the msg buffer
1967 * @msglen: msg length
1969 * called from the VF to enable all or specific queue(s)
1971 static int i40e_vc_enable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1973 struct virtchnl_queue_select
*vqs
=
1974 (struct virtchnl_queue_select
*)msg
;
1975 struct i40e_pf
*pf
= vf
->pf
;
1976 u16 vsi_id
= vqs
->vsi_id
;
1977 i40e_status aq_ret
= 0;
1979 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
1980 aq_ret
= I40E_ERR_PARAM
;
1984 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1985 aq_ret
= I40E_ERR_PARAM
;
1989 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1990 aq_ret
= I40E_ERR_PARAM
;
1994 if (i40e_vsi_start_rings(pf
->vsi
[vf
->lan_vsi_idx
]))
1995 aq_ret
= I40E_ERR_TIMEOUT
;
1997 /* send the response to the VF */
1998 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_ENABLE_QUEUES
,
2003 * i40e_vc_disable_queues_msg
2004 * @vf: pointer to the VF info
2005 * @msg: pointer to the msg buffer
2006 * @msglen: msg length
2008 * called from the VF to disable all or specific
2011 static int i40e_vc_disable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2013 struct virtchnl_queue_select
*vqs
=
2014 (struct virtchnl_queue_select
*)msg
;
2015 struct i40e_pf
*pf
= vf
->pf
;
2016 i40e_status aq_ret
= 0;
2018 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2019 aq_ret
= I40E_ERR_PARAM
;
2023 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
2024 aq_ret
= I40E_ERR_PARAM
;
2028 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
2029 aq_ret
= I40E_ERR_PARAM
;
2033 i40e_vsi_stop_rings(pf
->vsi
[vf
->lan_vsi_idx
]);
2036 /* send the response to the VF */
2037 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_DISABLE_QUEUES
,
2042 * i40e_vc_request_queues_msg
2043 * @vf: pointer to the VF info
2044 * @msg: pointer to the msg buffer
2045 * @msglen: msg length
2047 * VFs get a default number of queues but can use this message to request a
2048 * different number. If the request is successful, PF will reset the VF and
2049 * return 0. If unsuccessful, PF will send message informing VF of number of
2050 * available queues and return result of sending VF a message.
2052 static int i40e_vc_request_queues_msg(struct i40e_vf
*vf
, u8
*msg
, int msglen
)
2054 struct virtchnl_vf_res_request
*vfres
=
2055 (struct virtchnl_vf_res_request
*)msg
;
2056 int req_pairs
= vfres
->num_queue_pairs
;
2057 int cur_pairs
= vf
->num_queue_pairs
;
2058 struct i40e_pf
*pf
= vf
->pf
;
2060 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
))
2063 if (req_pairs
<= 0) {
2064 dev_err(&pf
->pdev
->dev
,
2065 "VF %d tried to request %d queues. Ignoring.\n",
2066 vf
->vf_id
, req_pairs
);
2067 } else if (req_pairs
> I40E_MAX_VF_QUEUES
) {
2068 dev_err(&pf
->pdev
->dev
,
2069 "VF %d tried to request more than %d queues.\n",
2071 I40E_MAX_VF_QUEUES
);
2072 vfres
->num_queue_pairs
= I40E_MAX_VF_QUEUES
;
2073 } else if (req_pairs
- cur_pairs
> pf
->queues_left
) {
2074 dev_warn(&pf
->pdev
->dev
,
2075 "VF %d requested %d more queues, but only %d left.\n",
2077 req_pairs
- cur_pairs
,
2079 vfres
->num_queue_pairs
= pf
->queues_left
+ cur_pairs
;
2081 /* successful request */
2082 vf
->num_req_queues
= req_pairs
;
2083 i40e_vc_notify_vf_reset(vf
);
2084 i40e_reset_vf(vf
, false);
2088 return i40e_vc_send_msg_to_vf(vf
, VIRTCHNL_OP_REQUEST_QUEUES
, 0,
2089 (u8
*)vfres
, sizeof(*vfres
));
2093 * i40e_vc_get_stats_msg
2094 * @vf: pointer to the VF info
2095 * @msg: pointer to the msg buffer
2096 * @msglen: msg length
2098 * called from the VF to get vsi stats
2100 static int i40e_vc_get_stats_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2102 struct virtchnl_queue_select
*vqs
=
2103 (struct virtchnl_queue_select
*)msg
;
2104 struct i40e_pf
*pf
= vf
->pf
;
2105 struct i40e_eth_stats stats
;
2106 i40e_status aq_ret
= 0;
2107 struct i40e_vsi
*vsi
;
2109 memset(&stats
, 0, sizeof(struct i40e_eth_stats
));
2111 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2112 aq_ret
= I40E_ERR_PARAM
;
2116 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
2117 aq_ret
= I40E_ERR_PARAM
;
2121 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2123 aq_ret
= I40E_ERR_PARAM
;
2126 i40e_update_eth_stats(vsi
);
2127 stats
= vsi
->eth_stats
;
2130 /* send the response back to the VF */
2131 return i40e_vc_send_msg_to_vf(vf
, VIRTCHNL_OP_GET_STATS
, aq_ret
,
2132 (u8
*)&stats
, sizeof(stats
));
2135 /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
2136 #define I40E_VC_MAX_MAC_ADDR_PER_VF 12
2137 #define I40E_VC_MAX_VLAN_PER_VF 8
2140 * i40e_check_vf_permission
2141 * @vf: pointer to the VF info
2142 * @macaddr: pointer to the MAC Address being checked
2144 * Check if the VF has permission to add or delete unicast MAC address
2145 * filters and return error code -EPERM if not. Then check if the
2146 * address filter requested is broadcast or zero and if so return
2147 * an invalid MAC address error code.
2149 static inline int i40e_check_vf_permission(struct i40e_vf
*vf
, u8
*macaddr
)
2151 struct i40e_pf
*pf
= vf
->pf
;
2154 if (is_broadcast_ether_addr(macaddr
) ||
2155 is_zero_ether_addr(macaddr
)) {
2156 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n", macaddr
);
2157 ret
= I40E_ERR_INVALID_MAC_ADDR
;
2158 } else if (vf
->pf_set_mac
&& !is_multicast_ether_addr(macaddr
) &&
2159 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) &&
2160 !ether_addr_equal(macaddr
, vf
->default_lan_addr
.addr
)) {
2161 /* If the host VMM administrator has set the VF MAC address
2162 * administratively via the ndo_set_vf_mac command then deny
2163 * permission to the VF to add or delete unicast MAC addresses.
2164 * Unless the VF is privileged and then it can do whatever.
2165 * The VF may request to set the MAC address filter already
2166 * assigned to it so do not return an error in that case.
2168 dev_err(&pf
->pdev
->dev
,
2169 "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
2171 } else if ((vf
->num_mac
>= I40E_VC_MAX_MAC_ADDR_PER_VF
) &&
2172 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
2173 dev_err(&pf
->pdev
->dev
,
2174 "VF is not trusted, switch the VF to trusted to add more functionality\n");
2181 * i40e_vc_add_mac_addr_msg
2182 * @vf: pointer to the VF info
2183 * @msg: pointer to the msg buffer
2184 * @msglen: msg length
2186 * add guest mac address filter
2188 static int i40e_vc_add_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2190 struct virtchnl_ether_addr_list
*al
=
2191 (struct virtchnl_ether_addr_list
*)msg
;
2192 struct i40e_pf
*pf
= vf
->pf
;
2193 struct i40e_vsi
*vsi
= NULL
;
2194 u16 vsi_id
= al
->vsi_id
;
2195 i40e_status ret
= 0;
2198 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2199 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2200 ret
= I40E_ERR_PARAM
;
2204 for (i
= 0; i
< al
->num_elements
; i
++) {
2205 ret
= i40e_check_vf_permission(vf
, al
->list
[i
].addr
);
2209 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2211 /* Lock once, because all function inside for loop accesses VSI's
2212 * MAC filter list which needs to be protected using same lock.
2214 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2216 /* add new addresses to the list */
2217 for (i
= 0; i
< al
->num_elements
; i
++) {
2218 struct i40e_mac_filter
*f
;
2220 f
= i40e_find_mac(vsi
, al
->list
[i
].addr
);
2222 f
= i40e_add_mac_filter(vsi
, al
->list
[i
].addr
);
2225 dev_err(&pf
->pdev
->dev
,
2226 "Unable to add MAC filter %pM for VF %d\n",
2227 al
->list
[i
].addr
, vf
->vf_id
);
2228 ret
= I40E_ERR_PARAM
;
2229 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2236 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2238 /* program the updated filter list */
2239 ret
= i40e_sync_vsi_filters(vsi
);
2241 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
2245 /* send the response to the VF */
2246 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_ADD_ETH_ADDR
,
2251 * i40e_vc_del_mac_addr_msg
2252 * @vf: pointer to the VF info
2253 * @msg: pointer to the msg buffer
2254 * @msglen: msg length
2256 * remove guest mac address filter
2258 static int i40e_vc_del_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2260 struct virtchnl_ether_addr_list
*al
=
2261 (struct virtchnl_ether_addr_list
*)msg
;
2262 struct i40e_pf
*pf
= vf
->pf
;
2263 struct i40e_vsi
*vsi
= NULL
;
2264 u16 vsi_id
= al
->vsi_id
;
2265 i40e_status ret
= 0;
2268 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2269 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2270 ret
= I40E_ERR_PARAM
;
2274 for (i
= 0; i
< al
->num_elements
; i
++) {
2275 if (is_broadcast_ether_addr(al
->list
[i
].addr
) ||
2276 is_zero_ether_addr(al
->list
[i
].addr
)) {
2277 dev_err(&pf
->pdev
->dev
, "Invalid MAC addr %pM for VF %d\n",
2278 al
->list
[i
].addr
, vf
->vf_id
);
2279 ret
= I40E_ERR_INVALID_MAC_ADDR
;
2283 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2285 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2286 /* delete addresses from the list */
2287 for (i
= 0; i
< al
->num_elements
; i
++)
2288 if (i40e_del_mac_filter(vsi
, al
->list
[i
].addr
)) {
2289 ret
= I40E_ERR_INVALID_MAC_ADDR
;
2290 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2296 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2298 /* program the updated filter list */
2299 ret
= i40e_sync_vsi_filters(vsi
);
2301 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
2305 /* send the response to the VF */
2306 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_DEL_ETH_ADDR
,
2311 * i40e_vc_add_vlan_msg
2312 * @vf: pointer to the VF info
2313 * @msg: pointer to the msg buffer
2314 * @msglen: msg length
2316 * program guest vlan id
2318 static int i40e_vc_add_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2320 struct virtchnl_vlan_filter_list
*vfl
=
2321 (struct virtchnl_vlan_filter_list
*)msg
;
2322 struct i40e_pf
*pf
= vf
->pf
;
2323 struct i40e_vsi
*vsi
= NULL
;
2324 u16 vsi_id
= vfl
->vsi_id
;
2325 i40e_status aq_ret
= 0;
2328 if ((vf
->num_vlan
>= I40E_VC_MAX_VLAN_PER_VF
) &&
2329 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
2330 dev_err(&pf
->pdev
->dev
,
2331 "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
2334 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2335 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2336 aq_ret
= I40E_ERR_PARAM
;
2340 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2341 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
2342 aq_ret
= I40E_ERR_PARAM
;
2343 dev_err(&pf
->pdev
->dev
,
2344 "invalid VF VLAN id %d\n", vfl
->vlan_id
[i
]);
2348 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2349 if (vsi
->info
.pvid
) {
2350 aq_ret
= I40E_ERR_PARAM
;
2354 i40e_vlan_stripping_enable(vsi
);
2355 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2356 /* add new VLAN filter */
2357 int ret
= i40e_vsi_add_vlan(vsi
, vfl
->vlan_id
[i
]);
2361 if (test_bit(I40E_VF_STATE_UC_PROMISC
, &vf
->vf_states
))
2362 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2366 if (test_bit(I40E_VF_STATE_MC_PROMISC
, &vf
->vf_states
))
2367 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2373 dev_err(&pf
->pdev
->dev
,
2374 "Unable to add VLAN filter %d for VF %d, error %d\n",
2375 vfl
->vlan_id
[i
], vf
->vf_id
, ret
);
2379 /* send the response to the VF */
2380 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_ADD_VLAN
, aq_ret
);
2384 * i40e_vc_remove_vlan_msg
2385 * @vf: pointer to the VF info
2386 * @msg: pointer to the msg buffer
2387 * @msglen: msg length
2389 * remove programmed guest vlan id
2391 static int i40e_vc_remove_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2393 struct virtchnl_vlan_filter_list
*vfl
=
2394 (struct virtchnl_vlan_filter_list
*)msg
;
2395 struct i40e_pf
*pf
= vf
->pf
;
2396 struct i40e_vsi
*vsi
= NULL
;
2397 u16 vsi_id
= vfl
->vsi_id
;
2398 i40e_status aq_ret
= 0;
2401 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2402 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2403 aq_ret
= I40E_ERR_PARAM
;
2407 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2408 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
2409 aq_ret
= I40E_ERR_PARAM
;
2414 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2415 if (vsi
->info
.pvid
) {
2416 aq_ret
= I40E_ERR_PARAM
;
2420 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2421 i40e_vsi_kill_vlan(vsi
, vfl
->vlan_id
[i
]);
2424 if (test_bit(I40E_VF_STATE_UC_PROMISC
, &vf
->vf_states
))
2425 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2429 if (test_bit(I40E_VF_STATE_MC_PROMISC
, &vf
->vf_states
))
2430 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2437 /* send the response to the VF */
2438 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_DEL_VLAN
, aq_ret
);
2443 * @vf: pointer to the VF info
2444 * @msg: pointer to the msg buffer
2445 * @msglen: msg length
2447 * called from the VF for the iwarp msgs
2449 static int i40e_vc_iwarp_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2451 struct i40e_pf
*pf
= vf
->pf
;
2452 int abs_vf_id
= vf
->vf_id
+ pf
->hw
.func_caps
.vf_base_id
;
2453 i40e_status aq_ret
= 0;
2455 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2456 !test_bit(I40E_VF_STATE_IWARPENA
, &vf
->vf_states
)) {
2457 aq_ret
= I40E_ERR_PARAM
;
2461 i40e_notify_client_of_vf_msg(pf
->vsi
[pf
->lan_vsi
], abs_vf_id
,
2465 /* send the response to the VF */
2466 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_IWARP
,
2471 * i40e_vc_iwarp_qvmap_msg
2472 * @vf: pointer to the VF info
2473 * @msg: pointer to the msg buffer
2474 * @msglen: msg length
2475 * @config: config qvmap or release it
2477 * called from the VF for the iwarp msgs
2479 static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
,
2482 struct virtchnl_iwarp_qvlist_info
*qvlist_info
=
2483 (struct virtchnl_iwarp_qvlist_info
*)msg
;
2484 i40e_status aq_ret
= 0;
2486 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2487 !test_bit(I40E_VF_STATE_IWARPENA
, &vf
->vf_states
)) {
2488 aq_ret
= I40E_ERR_PARAM
;
2493 if (i40e_config_iwarp_qvlist(vf
, qvlist_info
))
2494 aq_ret
= I40E_ERR_PARAM
;
2496 i40e_release_iwarp_qvlist(vf
);
2500 /* send the response to the VF */
2501 return i40e_vc_send_resp_to_vf(vf
,
2502 config
? VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
2503 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
,
2508 * i40e_vc_config_rss_key
2509 * @vf: pointer to the VF info
2510 * @msg: pointer to the msg buffer
2511 * @msglen: msg length
2513 * Configure the VF's RSS key
2515 static int i40e_vc_config_rss_key(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2517 struct virtchnl_rss_key
*vrk
=
2518 (struct virtchnl_rss_key
*)msg
;
2519 struct i40e_pf
*pf
= vf
->pf
;
2520 struct i40e_vsi
*vsi
= NULL
;
2521 u16 vsi_id
= vrk
->vsi_id
;
2522 i40e_status aq_ret
= 0;
2524 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2525 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
) ||
2526 (vrk
->key_len
!= I40E_HKEY_ARRAY_SIZE
)) {
2527 aq_ret
= I40E_ERR_PARAM
;
2531 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2532 aq_ret
= i40e_config_rss(vsi
, vrk
->key
, NULL
, 0);
2534 /* send the response to the VF */
2535 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_CONFIG_RSS_KEY
,
2540 * i40e_vc_config_rss_lut
2541 * @vf: pointer to the VF info
2542 * @msg: pointer to the msg buffer
2543 * @msglen: msg length
2545 * Configure the VF's RSS LUT
2547 static int i40e_vc_config_rss_lut(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2549 struct virtchnl_rss_lut
*vrl
=
2550 (struct virtchnl_rss_lut
*)msg
;
2551 struct i40e_pf
*pf
= vf
->pf
;
2552 struct i40e_vsi
*vsi
= NULL
;
2553 u16 vsi_id
= vrl
->vsi_id
;
2554 i40e_status aq_ret
= 0;
2556 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
) ||
2557 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
) ||
2558 (vrl
->lut_entries
!= I40E_VF_HLUT_ARRAY_SIZE
)) {
2559 aq_ret
= I40E_ERR_PARAM
;
2563 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2564 aq_ret
= i40e_config_rss(vsi
, NULL
, vrl
->lut
, I40E_VF_HLUT_ARRAY_SIZE
);
2565 /* send the response to the VF */
2567 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_CONFIG_RSS_LUT
,
2572 * i40e_vc_get_rss_hena
2573 * @vf: pointer to the VF info
2574 * @msg: pointer to the msg buffer
2575 * @msglen: msg length
2577 * Return the RSS HENA bits allowed by the hardware
2579 static int i40e_vc_get_rss_hena(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2581 struct virtchnl_rss_hena
*vrh
= NULL
;
2582 struct i40e_pf
*pf
= vf
->pf
;
2583 i40e_status aq_ret
= 0;
2586 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2587 aq_ret
= I40E_ERR_PARAM
;
2590 len
= sizeof(struct virtchnl_rss_hena
);
2592 vrh
= kzalloc(len
, GFP_KERNEL
);
2594 aq_ret
= I40E_ERR_NO_MEMORY
;
2598 vrh
->hena
= i40e_pf_get_default_rss_hena(pf
);
2600 /* send the response back to the VF */
2601 aq_ret
= i40e_vc_send_msg_to_vf(vf
, VIRTCHNL_OP_GET_RSS_HENA_CAPS
,
2602 aq_ret
, (u8
*)vrh
, len
);
2608 * i40e_vc_set_rss_hena
2609 * @vf: pointer to the VF info
2610 * @msg: pointer to the msg buffer
2611 * @msglen: msg length
2613 * Set the RSS HENA bits for the VF
2615 static int i40e_vc_set_rss_hena(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2617 struct virtchnl_rss_hena
*vrh
=
2618 (struct virtchnl_rss_hena
*)msg
;
2619 struct i40e_pf
*pf
= vf
->pf
;
2620 struct i40e_hw
*hw
= &pf
->hw
;
2621 i40e_status aq_ret
= 0;
2623 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2624 aq_ret
= I40E_ERR_PARAM
;
2627 i40e_write_rx_ctl(hw
, I40E_VFQF_HENA1(0, vf
->vf_id
), (u32
)vrh
->hena
);
2628 i40e_write_rx_ctl(hw
, I40E_VFQF_HENA1(1, vf
->vf_id
),
2629 (u32
)(vrh
->hena
>> 32));
2631 /* send the response to the VF */
2633 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_SET_RSS_HENA
, aq_ret
);
2637 * i40e_vc_enable_vlan_stripping
2638 * @vf: pointer to the VF info
2639 * @msg: pointer to the msg buffer
2640 * @msglen: msg length
2642 * Enable vlan header stripping for the VF
2644 static int i40e_vc_enable_vlan_stripping(struct i40e_vf
*vf
, u8
*msg
,
2647 struct i40e_vsi
*vsi
= vf
->pf
->vsi
[vf
->lan_vsi_idx
];
2648 i40e_status aq_ret
= 0;
2650 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2651 aq_ret
= I40E_ERR_PARAM
;
2655 i40e_vlan_stripping_enable(vsi
);
2657 /* send the response to the VF */
2659 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING
,
2664 * i40e_vc_disable_vlan_stripping
2665 * @vf: pointer to the VF info
2666 * @msg: pointer to the msg buffer
2667 * @msglen: msg length
2669 * Disable vlan header stripping for the VF
2671 static int i40e_vc_disable_vlan_stripping(struct i40e_vf
*vf
, u8
*msg
,
2674 struct i40e_vsi
*vsi
= vf
->pf
->vsi
[vf
->lan_vsi_idx
];
2675 i40e_status aq_ret
= 0;
2677 if (!test_bit(I40E_VF_STATE_ACTIVE
, &vf
->vf_states
)) {
2678 aq_ret
= I40E_ERR_PARAM
;
2682 i40e_vlan_stripping_disable(vsi
);
2684 /* send the response to the VF */
2686 return i40e_vc_send_resp_to_vf(vf
, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING
,
2691 * i40e_vc_process_vf_msg
2692 * @pf: pointer to the PF structure
2693 * @vf_id: source VF id
2694 * @msg: pointer to the msg buffer
2695 * @msglen: msg length
2696 * @msghndl: msg handle
2698 * called from the common aeq/arq handler to
2699 * process request from VF
2701 int i40e_vc_process_vf_msg(struct i40e_pf
*pf
, s16 vf_id
, u32 v_opcode
,
2702 u32 v_retval
, u8
*msg
, u16 msglen
)
2704 struct i40e_hw
*hw
= &pf
->hw
;
2705 int local_vf_id
= vf_id
- (s16
)hw
->func_caps
.vf_base_id
;
2709 pf
->vf_aq_requests
++;
2710 if (local_vf_id
>= pf
->num_alloc_vfs
)
2712 vf
= &(pf
->vf
[local_vf_id
]);
2714 /* Check if VF is disabled. */
2715 if (test_bit(I40E_VF_STATE_DISABLED
, &vf
->vf_states
))
2716 return I40E_ERR_PARAM
;
2718 /* perform basic checks on the msg */
2719 ret
= virtchnl_vc_validate_vf_msg(&vf
->vf_ver
, v_opcode
, msg
, msglen
);
2721 /* perform additional checks specific to this driver */
2722 if (v_opcode
== VIRTCHNL_OP_CONFIG_RSS_KEY
) {
2723 struct virtchnl_rss_key
*vrk
= (struct virtchnl_rss_key
*)msg
;
2725 if (vrk
->key_len
!= I40E_HKEY_ARRAY_SIZE
)
2727 } else if (v_opcode
== VIRTCHNL_OP_CONFIG_RSS_LUT
) {
2728 struct virtchnl_rss_lut
*vrl
= (struct virtchnl_rss_lut
*)msg
;
2730 if (vrl
->lut_entries
!= I40E_VF_HLUT_ARRAY_SIZE
)
2735 i40e_vc_send_resp_to_vf(vf
, v_opcode
, I40E_ERR_PARAM
);
2736 dev_err(&pf
->pdev
->dev
, "Invalid message from VF %d, opcode %d, len %d\n",
2737 local_vf_id
, v_opcode
, msglen
);
2739 case VIRTCHNL_ERR_PARAM
:
2747 case VIRTCHNL_OP_VERSION
:
2748 ret
= i40e_vc_get_version_msg(vf
, msg
);
2750 case VIRTCHNL_OP_GET_VF_RESOURCES
:
2751 ret
= i40e_vc_get_vf_resources_msg(vf
, msg
);
2752 i40e_vc_notify_vf_link_state(vf
);
2754 case VIRTCHNL_OP_RESET_VF
:
2755 i40e_vc_reset_vf_msg(vf
);
2758 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
2759 ret
= i40e_vc_config_promiscuous_mode_msg(vf
, msg
, msglen
);
2761 case VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
2762 ret
= i40e_vc_config_queues_msg(vf
, msg
, msglen
);
2764 case VIRTCHNL_OP_CONFIG_IRQ_MAP
:
2765 ret
= i40e_vc_config_irq_map_msg(vf
, msg
, msglen
);
2767 case VIRTCHNL_OP_ENABLE_QUEUES
:
2768 ret
= i40e_vc_enable_queues_msg(vf
, msg
, msglen
);
2769 i40e_vc_notify_vf_link_state(vf
);
2771 case VIRTCHNL_OP_DISABLE_QUEUES
:
2772 ret
= i40e_vc_disable_queues_msg(vf
, msg
, msglen
);
2774 case VIRTCHNL_OP_ADD_ETH_ADDR
:
2775 ret
= i40e_vc_add_mac_addr_msg(vf
, msg
, msglen
);
2777 case VIRTCHNL_OP_DEL_ETH_ADDR
:
2778 ret
= i40e_vc_del_mac_addr_msg(vf
, msg
, msglen
);
2780 case VIRTCHNL_OP_ADD_VLAN
:
2781 ret
= i40e_vc_add_vlan_msg(vf
, msg
, msglen
);
2783 case VIRTCHNL_OP_DEL_VLAN
:
2784 ret
= i40e_vc_remove_vlan_msg(vf
, msg
, msglen
);
2786 case VIRTCHNL_OP_GET_STATS
:
2787 ret
= i40e_vc_get_stats_msg(vf
, msg
, msglen
);
2789 case VIRTCHNL_OP_IWARP
:
2790 ret
= i40e_vc_iwarp_msg(vf
, msg
, msglen
);
2792 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
2793 ret
= i40e_vc_iwarp_qvmap_msg(vf
, msg
, msglen
, true);
2795 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
:
2796 ret
= i40e_vc_iwarp_qvmap_msg(vf
, msg
, msglen
, false);
2798 case VIRTCHNL_OP_CONFIG_RSS_KEY
:
2799 ret
= i40e_vc_config_rss_key(vf
, msg
, msglen
);
2801 case VIRTCHNL_OP_CONFIG_RSS_LUT
:
2802 ret
= i40e_vc_config_rss_lut(vf
, msg
, msglen
);
2804 case VIRTCHNL_OP_GET_RSS_HENA_CAPS
:
2805 ret
= i40e_vc_get_rss_hena(vf
, msg
, msglen
);
2807 case VIRTCHNL_OP_SET_RSS_HENA
:
2808 ret
= i40e_vc_set_rss_hena(vf
, msg
, msglen
);
2810 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING
:
2811 ret
= i40e_vc_enable_vlan_stripping(vf
, msg
, msglen
);
2813 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING
:
2814 ret
= i40e_vc_disable_vlan_stripping(vf
, msg
, msglen
);
2816 case VIRTCHNL_OP_REQUEST_QUEUES
:
2817 ret
= i40e_vc_request_queues_msg(vf
, msg
, msglen
);
2820 case VIRTCHNL_OP_UNKNOWN
:
2822 dev_err(&pf
->pdev
->dev
, "Unsupported opcode %d from VF %d\n",
2823 v_opcode
, local_vf_id
);
2824 ret
= i40e_vc_send_resp_to_vf(vf
, v_opcode
,
2825 I40E_ERR_NOT_IMPLEMENTED
);
2833 * i40e_vc_process_vflr_event
2834 * @pf: pointer to the PF structure
2836 * called from the vlfr irq handler to
2837 * free up VF resources and state variables
2839 int i40e_vc_process_vflr_event(struct i40e_pf
*pf
)
2841 struct i40e_hw
*hw
= &pf
->hw
;
2842 u32 reg
, reg_idx
, bit_idx
;
2846 if (!test_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
))
2849 /* Re-enable the VFLR interrupt cause here, before looking for which
2850 * VF got reset. Otherwise, if another VF gets a reset while the
2851 * first one is being processed, that interrupt will be lost, and
2852 * that VF will be stuck in reset forever.
2854 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
2855 reg
|= I40E_PFINT_ICR0_ENA_VFLR_MASK
;
2856 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
2859 clear_bit(__I40E_VFLR_EVENT_PENDING
, pf
->state
);
2860 for (vf_id
= 0; vf_id
< pf
->num_alloc_vfs
; vf_id
++) {
2861 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
2862 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
2863 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
2864 vf
= &pf
->vf
[vf_id
];
2865 reg
= rd32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
));
2866 if (reg
& BIT(bit_idx
))
2867 /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
2868 i40e_reset_vf(vf
, true);
2875 * i40e_ndo_set_vf_mac
2876 * @netdev: network interface device structure
2877 * @vf_id: VF identifier
2880 * program VF mac address
2882 int i40e_ndo_set_vf_mac(struct net_device
*netdev
, int vf_id
, u8
*mac
)
2884 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2885 struct i40e_vsi
*vsi
= np
->vsi
;
2886 struct i40e_pf
*pf
= vsi
->back
;
2887 struct i40e_mac_filter
*f
;
2890 struct hlist_node
*h
;
2893 /* validate the request */
2894 if (vf_id
>= pf
->num_alloc_vfs
) {
2895 dev_err(&pf
->pdev
->dev
,
2896 "Invalid VF Identifier %d\n", vf_id
);
2901 vf
= &(pf
->vf
[vf_id
]);
2902 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2903 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
2904 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2910 if (is_multicast_ether_addr(mac
)) {
2911 dev_err(&pf
->pdev
->dev
,
2912 "Invalid Ethernet address %pM for VF %d\n", mac
, vf_id
);
2917 /* Lock once because below invoked function add/del_filter requires
2918 * mac_filter_hash_lock to be held
2920 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2922 /* delete the temporary mac address */
2923 if (!is_zero_ether_addr(vf
->default_lan_addr
.addr
))
2924 i40e_del_mac_filter(vsi
, vf
->default_lan_addr
.addr
);
2926 /* Delete all the filters for this VSI - we're going to kill it
2929 hash_for_each_safe(vsi
->mac_filter_hash
, bkt
, h
, f
, hlist
)
2930 __i40e_del_filter(vsi
, f
);
2932 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2934 /* program mac filter */
2935 if (i40e_sync_vsi_filters(vsi
)) {
2936 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
2940 ether_addr_copy(vf
->default_lan_addr
.addr
, mac
);
2942 if (is_zero_ether_addr(mac
)) {
2943 vf
->pf_set_mac
= false;
2944 dev_info(&pf
->pdev
->dev
, "Removing MAC on VF %d\n", vf_id
);
2946 vf
->pf_set_mac
= true;
2947 dev_info(&pf
->pdev
->dev
, "Setting MAC %pM on VF %d\n",
2951 /* Force the VF driver stop so it has to reload with new MAC address */
2952 i40e_vc_disable_vf(vf
);
2953 dev_info(&pf
->pdev
->dev
, "Reload the VF driver to make this change effective.\n");
2960 * i40e_vsi_has_vlans - True if VSI has configured VLANs
2961 * @vsi: pointer to the vsi
2963 * Check if a VSI has configured any VLANs. False if we have a port VLAN or if
2964 * we have no configured VLANs. Do not call while holding the
2965 * mac_filter_hash_lock.
2967 static bool i40e_vsi_has_vlans(struct i40e_vsi
*vsi
)
2971 /* If we have a port VLAN, then the VSI cannot have any VLANs
2972 * configured, as all MAC/VLAN filters will be assigned to the PVID.
2977 /* Since we don't have a PVID, we know that if the device is in VLAN
2978 * mode it must be because of a VLAN filter configured on this VSI.
2980 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
2981 have_vlans
= i40e_is_vsi_in_vlan(vsi
);
2982 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
2988 * i40e_ndo_set_vf_port_vlan
2989 * @netdev: network interface device structure
2990 * @vf_id: VF identifier
2991 * @vlan_id: mac address
2992 * @qos: priority setting
2993 * @vlan_proto: vlan protocol
2995 * program VF vlan id and/or qos
2997 int i40e_ndo_set_vf_port_vlan(struct net_device
*netdev
, int vf_id
,
2998 u16 vlan_id
, u8 qos
, __be16 vlan_proto
)
3000 u16 vlanprio
= vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
);
3001 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3002 struct i40e_pf
*pf
= np
->vsi
->back
;
3003 struct i40e_vsi
*vsi
;
3007 /* validate the request */
3008 if (vf_id
>= pf
->num_alloc_vfs
) {
3009 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3014 if ((vlan_id
> I40E_MAX_VLANID
) || (qos
> 7)) {
3015 dev_err(&pf
->pdev
->dev
, "Invalid VF Parameters\n");
3020 if (vlan_proto
!= htons(ETH_P_8021Q
)) {
3021 dev_err(&pf
->pdev
->dev
, "VF VLAN protocol is not supported\n");
3022 ret
= -EPROTONOSUPPORT
;
3026 vf
= &(pf
->vf
[vf_id
]);
3027 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
3028 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
3029 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
3035 if (le16_to_cpu(vsi
->info
.pvid
) == vlanprio
)
3036 /* duplicate request, so just return success */
3039 if (i40e_vsi_has_vlans(vsi
)) {
3040 dev_err(&pf
->pdev
->dev
,
3041 "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",
3043 /* Administrator Error - knock the VF offline until he does
3044 * the right thing by reconfiguring his network correctly
3045 * and then reloading the VF driver.
3047 i40e_vc_disable_vf(vf
);
3048 /* During reset the VF got a new VSI, so refresh the pointer. */
3049 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
3052 /* Locked once because multiple functions below iterate list */
3053 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
3055 /* Check for condition where there was already a port VLAN ID
3056 * filter set and now it is being deleted by setting it to zero.
3057 * Additionally check for the condition where there was a port
3058 * VLAN but now there is a new and different port VLAN being set.
3059 * Before deleting all the old VLAN filters we must add new ones
3060 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
3061 * MAC addresses deleted.
3063 if ((!(vlan_id
|| qos
) ||
3064 vlanprio
!= le16_to_cpu(vsi
->info
.pvid
)) &&
3066 ret
= i40e_add_vlan_all_mac(vsi
, I40E_VLAN_ANY
);
3068 dev_info(&vsi
->back
->pdev
->dev
,
3069 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
3070 vsi
->back
->hw
.aq
.asq_last_status
);
3071 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
3076 if (vsi
->info
.pvid
) {
3077 /* remove all filters on the old VLAN */
3078 i40e_rm_vlan_all_mac(vsi
, (le16_to_cpu(vsi
->info
.pvid
) &
3082 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
3084 ret
= i40e_vsi_add_pvid(vsi
, vlanprio
);
3086 i40e_vsi_remove_pvid(vsi
);
3087 spin_lock_bh(&vsi
->mac_filter_hash_lock
);
3090 dev_info(&pf
->pdev
->dev
, "Setting VLAN %d, QOS 0x%x on VF %d\n",
3091 vlan_id
, qos
, vf_id
);
3093 /* add new VLAN filter for each MAC */
3094 ret
= i40e_add_vlan_all_mac(vsi
, vlan_id
);
3096 dev_info(&vsi
->back
->pdev
->dev
,
3097 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
3098 vsi
->back
->hw
.aq
.asq_last_status
);
3099 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
3103 /* remove the previously added non-VLAN MAC filters */
3104 i40e_rm_vlan_all_mac(vsi
, I40E_VLAN_ANY
);
3107 spin_unlock_bh(&vsi
->mac_filter_hash_lock
);
3109 /* Schedule the worker thread to take care of applying changes */
3110 i40e_service_event_schedule(vsi
->back
);
3113 dev_err(&pf
->pdev
->dev
, "Unable to update VF vsi context\n");
3117 /* The Port VLAN needs to be saved across resets the same as the
3118 * default LAN MAC address.
3120 vf
->port_vlan_id
= le16_to_cpu(vsi
->info
.pvid
);
3128 * i40e_ndo_set_vf_bw
3129 * @netdev: network interface device structure
3130 * @vf_id: VF identifier
3133 * configure VF Tx rate
3135 int i40e_ndo_set_vf_bw(struct net_device
*netdev
, int vf_id
, int min_tx_rate
,
3138 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3139 struct i40e_pf
*pf
= np
->vsi
->back
;
3140 struct i40e_vsi
*vsi
;
3144 /* validate the request */
3145 if (vf_id
>= pf
->num_alloc_vfs
) {
3146 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d.\n", vf_id
);
3152 dev_err(&pf
->pdev
->dev
, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
3153 min_tx_rate
, vf_id
);
3157 vf
= &(pf
->vf
[vf_id
]);
3158 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
3159 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
3160 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
3166 ret
= i40e_set_bw_limit(vsi
, vsi
->seid
, max_tx_rate
);
3170 vf
->tx_rate
= max_tx_rate
;
3176 * i40e_ndo_get_vf_config
3177 * @netdev: network interface device structure
3178 * @vf_id: VF identifier
3179 * @ivi: VF configuration structure
3181 * return VF configuration
3183 int i40e_ndo_get_vf_config(struct net_device
*netdev
,
3184 int vf_id
, struct ifla_vf_info
*ivi
)
3186 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3187 struct i40e_vsi
*vsi
= np
->vsi
;
3188 struct i40e_pf
*pf
= vsi
->back
;
3192 /* validate the request */
3193 if (vf_id
>= pf
->num_alloc_vfs
) {
3194 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3199 vf
= &(pf
->vf
[vf_id
]);
3200 /* first vsi is always the LAN vsi */
3201 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
3202 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
3203 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
3211 ether_addr_copy(ivi
->mac
, vf
->default_lan_addr
.addr
);
3213 ivi
->max_tx_rate
= vf
->tx_rate
;
3214 ivi
->min_tx_rate
= 0;
3215 ivi
->vlan
= le16_to_cpu(vsi
->info
.pvid
) & I40E_VLAN_MASK
;
3216 ivi
->qos
= (le16_to_cpu(vsi
->info
.pvid
) & I40E_PRIORITY_MASK
) >>
3217 I40E_VLAN_PRIORITY_SHIFT
;
3218 if (vf
->link_forced
== false)
3219 ivi
->linkstate
= IFLA_VF_LINK_STATE_AUTO
;
3220 else if (vf
->link_up
== true)
3221 ivi
->linkstate
= IFLA_VF_LINK_STATE_ENABLE
;
3223 ivi
->linkstate
= IFLA_VF_LINK_STATE_DISABLE
;
3224 ivi
->spoofchk
= vf
->spoofchk
;
3225 ivi
->trusted
= vf
->trusted
;
3233 * i40e_ndo_set_vf_link_state
3234 * @netdev: network interface device structure
3235 * @vf_id: VF identifier
3236 * @link: required link state
3238 * Set the link state of a specified VF, regardless of physical link state
3240 int i40e_ndo_set_vf_link_state(struct net_device
*netdev
, int vf_id
, int link
)
3242 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3243 struct i40e_pf
*pf
= np
->vsi
->back
;
3244 struct virtchnl_pf_event pfe
;
3245 struct i40e_hw
*hw
= &pf
->hw
;
3250 /* validate the request */
3251 if (vf_id
>= pf
->num_alloc_vfs
) {
3252 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3257 vf
= &pf
->vf
[vf_id
];
3258 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
3260 pfe
.event
= VIRTCHNL_EVENT_LINK_CHANGE
;
3261 pfe
.severity
= PF_EVENT_SEVERITY_INFO
;
3264 case IFLA_VF_LINK_STATE_AUTO
:
3265 vf
->link_forced
= false;
3266 pfe
.event_data
.link_event
.link_status
=
3267 pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
3268 pfe
.event_data
.link_event
.link_speed
=
3269 (enum virtchnl_link_speed
)
3270 pf
->hw
.phy
.link_info
.link_speed
;
3272 case IFLA_VF_LINK_STATE_ENABLE
:
3273 vf
->link_forced
= true;
3275 pfe
.event_data
.link_event
.link_status
= true;
3276 pfe
.event_data
.link_event
.link_speed
= I40E_LINK_SPEED_40GB
;
3278 case IFLA_VF_LINK_STATE_DISABLE
:
3279 vf
->link_forced
= true;
3280 vf
->link_up
= false;
3281 pfe
.event_data
.link_event
.link_status
= false;
3282 pfe
.event_data
.link_event
.link_speed
= 0;
3288 /* Notify the VF of its new link state */
3289 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, VIRTCHNL_OP_EVENT
,
3290 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
3297 * i40e_ndo_set_vf_spoofchk
3298 * @netdev: network interface device structure
3299 * @vf_id: VF identifier
3300 * @enable: flag to enable or disable feature
3302 * Enable or disable VF spoof checking
3304 int i40e_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf_id
, bool enable
)
3306 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3307 struct i40e_vsi
*vsi
= np
->vsi
;
3308 struct i40e_pf
*pf
= vsi
->back
;
3309 struct i40e_vsi_context ctxt
;
3310 struct i40e_hw
*hw
= &pf
->hw
;
3314 /* validate the request */
3315 if (vf_id
>= pf
->num_alloc_vfs
) {
3316 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3321 vf
= &(pf
->vf
[vf_id
]);
3322 if (!test_bit(I40E_VF_STATE_INIT
, &vf
->vf_states
)) {
3323 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
3329 if (enable
== vf
->spoofchk
)
3332 vf
->spoofchk
= enable
;
3333 memset(&ctxt
, 0, sizeof(ctxt
));
3334 ctxt
.seid
= pf
->vsi
[vf
->lan_vsi_idx
]->seid
;
3335 ctxt
.pf_num
= pf
->hw
.pf_id
;
3336 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
3338 ctxt
.info
.sec_flags
|= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
3339 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
3340 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
3342 dev_err(&pf
->pdev
->dev
, "Error %d updating VSI parameters\n",
3351 * i40e_ndo_set_vf_trust
3352 * @netdev: network interface device structure of the pf
3353 * @vf_id: VF identifier
3354 * @setting: trust setting
3356 * Enable or disable VF trust setting
3358 int i40e_ndo_set_vf_trust(struct net_device
*netdev
, int vf_id
, bool setting
)
3360 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3361 struct i40e_pf
*pf
= np
->vsi
->back
;
3365 /* validate the request */
3366 if (vf_id
>= pf
->num_alloc_vfs
) {
3367 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3371 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
3372 dev_err(&pf
->pdev
->dev
, "Trusted VF not supported in MFP mode.\n");
3376 vf
= &pf
->vf
[vf_id
];
3378 if (setting
== vf
->trusted
)
3381 vf
->trusted
= setting
;
3382 i40e_vc_disable_vf(vf
);
3383 dev_info(&pf
->pdev
->dev
, "VF %u is now %strusted\n",
3384 vf_id
, setting
? "" : "un");