1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 /*********************notification routines***********************/
32 * i40e_vc_vf_broadcast
33 * @pf: pointer to the PF structure
34 * @opcode: operation code
35 * @retval: return value
36 * @msg: pointer to the msg buffer
39 * send a message to all VFs on a given PF
41 static void i40e_vc_vf_broadcast(struct i40e_pf
*pf
,
42 enum i40e_virtchnl_ops v_opcode
,
43 i40e_status v_retval
, u8
*msg
,
46 struct i40e_hw
*hw
= &pf
->hw
;
47 struct i40e_vf
*vf
= pf
->vf
;
50 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++, vf
++) {
51 int abs_vf_id
= vf
->vf_id
+ (int)hw
->func_caps
.vf_base_id
;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
) &&
54 !test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
60 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
66 * i40e_vc_notify_vf_link_state
67 * @vf: pointer to the VF structure
69 * send a link status message to a single VF
71 static void i40e_vc_notify_vf_link_state(struct i40e_vf
*vf
)
73 struct i40e_virtchnl_pf_event pfe
;
74 struct i40e_pf
*pf
= vf
->pf
;
75 struct i40e_hw
*hw
= &pf
->hw
;
76 struct i40e_link_status
*ls
= &pf
->hw
.phy
.link_info
;
77 int abs_vf_id
= vf
->vf_id
+ (int)hw
->func_caps
.vf_base_id
;
79 pfe
.event
= I40E_VIRTCHNL_EVENT_LINK_CHANGE
;
80 pfe
.severity
= I40E_PF_EVENT_SEVERITY_INFO
;
81 if (vf
->link_forced
) {
82 pfe
.event_data
.link_event
.link_status
= vf
->link_up
;
83 pfe
.event_data
.link_event
.link_speed
=
84 (vf
->link_up
? I40E_LINK_SPEED_40GB
: 0);
86 pfe
.event_data
.link_event
.link_status
=
87 ls
->link_info
& I40E_AQ_LINK_UP
;
88 pfe
.event_data
.link_event
.link_speed
= ls
->link_speed
;
90 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
91 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
95 * i40e_vc_notify_link_state
96 * @pf: pointer to the PF structure
98 * send a link status message to all VFs on a given PF
100 void i40e_vc_notify_link_state(struct i40e_pf
*pf
)
104 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
105 i40e_vc_notify_vf_link_state(&pf
->vf
[i
]);
109 * i40e_vc_notify_reset
110 * @pf: pointer to the PF structure
112 * indicate a pending reset to all VFs on a given PF
114 void i40e_vc_notify_reset(struct i40e_pf
*pf
)
116 struct i40e_virtchnl_pf_event pfe
;
118 pfe
.event
= I40E_VIRTCHNL_EVENT_RESET_IMPENDING
;
119 pfe
.severity
= I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM
;
120 i40e_vc_vf_broadcast(pf
, I40E_VIRTCHNL_OP_EVENT
, 0,
121 (u8
*)&pfe
, sizeof(struct i40e_virtchnl_pf_event
));
125 * i40e_vc_notify_vf_reset
126 * @vf: pointer to the VF structure
128 * indicate a pending reset to the given VF
130 void i40e_vc_notify_vf_reset(struct i40e_vf
*vf
)
132 struct i40e_virtchnl_pf_event pfe
;
135 /* validate the request */
136 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
139 /* verify if the VF is in either init or active before proceeding */
140 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
) &&
141 !test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
144 abs_vf_id
= vf
->vf_id
+ (int)vf
->pf
->hw
.func_caps
.vf_base_id
;
146 pfe
.event
= I40E_VIRTCHNL_EVENT_RESET_IMPENDING
;
147 pfe
.severity
= I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM
;
148 i40e_aq_send_msg_to_vf(&vf
->pf
->hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
150 sizeof(struct i40e_virtchnl_pf_event
), NULL
);
152 /***********************misc routines*****************************/
156 * @pf: pointer to the PF info
157 * @vf: pointer to the VF info
159 * Disable the VF through a SW reset
161 static inline void i40e_vc_disable_vf(struct i40e_pf
*pf
, struct i40e_vf
*vf
)
163 i40e_vc_notify_vf_reset(vf
);
164 i40e_reset_vf(vf
, false);
168 * i40e_vc_isvalid_vsi_id
169 * @vf: pointer to the VF info
170 * @vsi_id: VF relative VSI id
172 * check for the valid VSI id
174 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf
*vf
, u16 vsi_id
)
176 struct i40e_pf
*pf
= vf
->pf
;
177 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
179 return (vsi
&& (vsi
->vf_id
== vf
->vf_id
));
183 * i40e_vc_isvalid_queue_id
184 * @vf: pointer to the VF info
186 * @qid: vsi relative queue id
188 * check for the valid queue id
190 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
193 struct i40e_pf
*pf
= vf
->pf
;
194 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
196 return (vsi
&& (qid
< vsi
->alloc_queue_pairs
));
200 * i40e_vc_isvalid_vector_id
201 * @vf: pointer to the VF info
202 * @vector_id: VF relative vector id
204 * check for the valid vector id
206 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf
*vf
, u8 vector_id
)
208 struct i40e_pf
*pf
= vf
->pf
;
210 return vector_id
< pf
->hw
.func_caps
.num_msix_vectors_vf
;
213 /***********************vf resource mgmt routines*****************/
216 * i40e_vc_get_pf_queue_id
217 * @vf: pointer to the VF info
218 * @vsi_id: id of VSI as provided by the FW
219 * @vsi_queue_id: vsi relative queue id
221 * return PF relative queue id
223 static u16
i40e_vc_get_pf_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
226 struct i40e_pf
*pf
= vf
->pf
;
227 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
228 u16 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
233 if (le16_to_cpu(vsi
->info
.mapping_flags
) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG
)
236 le16_to_cpu(vsi
->info
.queue_mapping
[vsi_queue_id
]);
238 pf_queue_id
= le16_to_cpu(vsi
->info
.queue_mapping
[0]) +
245 * i40e_config_irq_link_list
246 * @vf: pointer to the VF info
247 * @vsi_id: id of VSI as given by the FW
248 * @vecmap: irq map info
250 * configure irq link list from the map
252 static void i40e_config_irq_link_list(struct i40e_vf
*vf
, u16 vsi_id
,
253 struct i40e_virtchnl_vector_map
*vecmap
)
255 unsigned long linklistmap
= 0, tempmap
;
256 struct i40e_pf
*pf
= vf
->pf
;
257 struct i40e_hw
*hw
= &pf
->hw
;
258 u16 vsi_queue_id
, pf_queue_id
;
259 enum i40e_queue_type qtype
;
260 u16 next_q
, vector_id
;
264 vector_id
= vecmap
->vector_id
;
267 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
269 reg_idx
= I40E_VPINT_LNKLSTN(
270 ((pf
->hw
.func_caps
.num_msix_vectors_vf
- 1) * vf
->vf_id
) +
273 if (vecmap
->rxq_map
== 0 && vecmap
->txq_map
== 0) {
274 /* Special case - No queues mapped on this vector */
275 wr32(hw
, reg_idx
, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK
);
278 tempmap
= vecmap
->rxq_map
;
279 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
280 linklistmap
|= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES
*
284 tempmap
= vecmap
->txq_map
;
285 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
286 linklistmap
|= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES
*
290 next_q
= find_first_bit(&linklistmap
,
292 I40E_VIRTCHNL_SUPPORTED_QTYPES
));
293 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
294 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
295 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
296 reg
= ((qtype
<< I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
) | pf_queue_id
);
298 wr32(hw
, reg_idx
, reg
);
300 while (next_q
< (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
302 case I40E_QUEUE_TYPE_RX
:
303 reg_idx
= I40E_QINT_RQCTL(pf_queue_id
);
304 itr_idx
= vecmap
->rxitr_idx
;
306 case I40E_QUEUE_TYPE_TX
:
307 reg_idx
= I40E_QINT_TQCTL(pf_queue_id
);
308 itr_idx
= vecmap
->txitr_idx
;
314 next_q
= find_next_bit(&linklistmap
,
316 I40E_VIRTCHNL_SUPPORTED_QTYPES
),
319 (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
320 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
321 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
322 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
,
325 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
329 /* format for the RQCTL & TQCTL regs is same */
331 (qtype
<< I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
) |
332 (pf_queue_id
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT
) |
334 (itr_idx
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
);
335 wr32(hw
, reg_idx
, reg
);
338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
341 if ((vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING
) &&
343 reg
= rd32(hw
, I40E_GLINT_CTL
);
344 if (!(reg
& I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK
)) {
345 reg
|= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK
;
346 wr32(hw
, I40E_GLINT_CTL
, reg
);
355 * i40e_release_iwarp_qvlist
356 * @vf: pointer to the VF.
359 static void i40e_release_iwarp_qvlist(struct i40e_vf
*vf
)
361 struct i40e_pf
*pf
= vf
->pf
;
362 struct i40e_virtchnl_iwarp_qvlist_info
*qvlist_info
= vf
->qvlist_info
;
366 if (!vf
->qvlist_info
)
369 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
370 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
371 struct i40e_virtchnl_iwarp_qv_info
*qv_info
;
372 u32 next_q_index
, next_q_type
;
373 struct i40e_hw
*hw
= &pf
->hw
;
374 u32 v_idx
, reg_idx
, reg
;
376 qv_info
= &qvlist_info
->qv_info
[i
];
379 v_idx
= qv_info
->v_idx
;
380 if (qv_info
->ceq_idx
!= I40E_QUEUE_INVALID_IDX
) {
381 /* Figure out the queue after CEQ and make that the
384 reg_idx
= (msix_vf
- 1) * vf
->vf_id
+ qv_info
->ceq_idx
;
385 reg
= rd32(hw
, I40E_VPINT_CEQCTL(reg_idx
));
386 next_q_index
= (reg
& I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK
)
387 >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT
;
388 next_q_type
= (reg
& I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK
)
389 >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT
;
391 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
392 reg
= (next_q_index
&
393 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
395 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
397 wr32(hw
, I40E_VPINT_LNKLSTN(reg_idx
), reg
);
400 kfree(vf
->qvlist_info
);
401 vf
->qvlist_info
= NULL
;
405 * i40e_config_iwarp_qvlist
406 * @vf: pointer to the VF info
407 * @qvlist_info: queue and vector list
409 * Return 0 on success or < 0 on error
411 static int i40e_config_iwarp_qvlist(struct i40e_vf
*vf
,
412 struct i40e_virtchnl_iwarp_qvlist_info
*qvlist_info
)
414 struct i40e_pf
*pf
= vf
->pf
;
415 struct i40e_hw
*hw
= &pf
->hw
;
416 struct i40e_virtchnl_iwarp_qv_info
*qv_info
;
417 u32 v_idx
, i
, reg_idx
, reg
;
418 u32 next_q_idx
, next_q_type
;
421 size
= sizeof(struct i40e_virtchnl_iwarp_qvlist_info
) +
422 (sizeof(struct i40e_virtchnl_iwarp_qv_info
) *
423 (qvlist_info
->num_vectors
- 1));
424 vf
->qvlist_info
= kzalloc(size
, GFP_KERNEL
);
425 vf
->qvlist_info
->num_vectors
= qvlist_info
->num_vectors
;
427 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
428 for (i
= 0; i
< qvlist_info
->num_vectors
; i
++) {
429 qv_info
= &qvlist_info
->qv_info
[i
];
432 v_idx
= qv_info
->v_idx
;
434 /* Validate vector id belongs to this vf */
435 if (!i40e_vc_isvalid_vector_id(vf
, v_idx
))
438 vf
->qvlist_info
->qv_info
[i
] = *qv_info
;
440 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
441 /* We might be sharing the interrupt, so get the first queue
442 * index and type, push it down the list by adding the new
443 * queue on top. Also link it with the new queue in CEQCTL.
445 reg
= rd32(hw
, I40E_VPINT_LNKLSTN(reg_idx
));
446 next_q_idx
= ((reg
& I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) >>
447 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT
);
448 next_q_type
= ((reg
& I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
) >>
449 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
451 if (qv_info
->ceq_idx
!= I40E_QUEUE_INVALID_IDX
) {
452 reg_idx
= (msix_vf
- 1) * vf
->vf_id
+ qv_info
->ceq_idx
;
453 reg
= (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK
|
454 (v_idx
<< I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT
) |
455 (qv_info
->itr_idx
<< I40E_VPINT_CEQCTL_ITR_INDX_SHIFT
) |
456 (next_q_type
<< I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT
) |
457 (next_q_idx
<< I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT
));
458 wr32(hw
, I40E_VPINT_CEQCTL(reg_idx
), reg
);
460 reg_idx
= ((msix_vf
- 1) * vf
->vf_id
) + (v_idx
- 1);
461 reg
= (qv_info
->ceq_idx
&
462 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
) |
463 (I40E_QUEUE_TYPE_PE_CEQ
<<
464 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
);
465 wr32(hw
, I40E_VPINT_LNKLSTN(reg_idx
), reg
);
468 if (qv_info
->aeq_idx
!= I40E_QUEUE_INVALID_IDX
) {
469 reg
= (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK
|
470 (v_idx
<< I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT
) |
471 (qv_info
->itr_idx
<< I40E_VPINT_AEQCTL_ITR_INDX_SHIFT
));
473 wr32(hw
, I40E_VPINT_AEQCTL(vf
->vf_id
), reg
);
479 kfree(vf
->qvlist_info
);
480 vf
->qvlist_info
= NULL
;
485 * i40e_config_vsi_tx_queue
486 * @vf: pointer to the VF info
487 * @vsi_id: id of VSI as provided by the FW
488 * @vsi_queue_id: vsi relative queue index
489 * @info: config. info
493 static int i40e_config_vsi_tx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
495 struct i40e_virtchnl_txq_info
*info
)
497 struct i40e_pf
*pf
= vf
->pf
;
498 struct i40e_hw
*hw
= &pf
->hw
;
499 struct i40e_hmc_obj_txq tx_ctx
;
500 struct i40e_vsi
*vsi
;
505 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
506 vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
508 /* clear the context structure first */
509 memset(&tx_ctx
, 0, sizeof(struct i40e_hmc_obj_txq
));
511 /* only set the required fields */
512 tx_ctx
.base
= info
->dma_ring_addr
/ 128;
513 tx_ctx
.qlen
= info
->ring_len
;
514 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[0]);
515 tx_ctx
.rdylist_act
= 0;
516 tx_ctx
.head_wb_ena
= info
->headwb_enabled
;
517 tx_ctx
.head_wb_addr
= info
->dma_headwb_addr
;
519 /* clear the context in the HMC */
520 ret
= i40e_clear_lan_tx_queue_context(hw
, pf_queue_id
);
522 dev_err(&pf
->pdev
->dev
,
523 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
529 /* set the context in the HMC */
530 ret
= i40e_set_lan_tx_queue_context(hw
, pf_queue_id
, &tx_ctx
);
532 dev_err(&pf
->pdev
->dev
,
533 "Failed to set VF LAN Tx queue context %d error: %d\n",
539 /* associate this queue with the PCI VF function */
540 qtx_ctl
= I40E_QTX_CTL_VF_QUEUE
;
541 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
)
542 & I40E_QTX_CTL_PF_INDX_MASK
);
543 qtx_ctl
|= (((vf
->vf_id
+ hw
->func_caps
.vf_base_id
)
544 << I40E_QTX_CTL_VFVM_INDX_SHIFT
)
545 & I40E_QTX_CTL_VFVM_INDX_MASK
);
546 wr32(hw
, I40E_QTX_CTL(pf_queue_id
), qtx_ctl
);
554 * i40e_config_vsi_rx_queue
555 * @vf: pointer to the VF info
556 * @vsi_id: id of VSI as provided by the FW
557 * @vsi_queue_id: vsi relative queue index
558 * @info: config. info
562 static int i40e_config_vsi_rx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
564 struct i40e_virtchnl_rxq_info
*info
)
566 struct i40e_pf
*pf
= vf
->pf
;
567 struct i40e_hw
*hw
= &pf
->hw
;
568 struct i40e_hmc_obj_rxq rx_ctx
;
572 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
574 /* clear the context structure first */
575 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
577 /* only set the required fields */
578 rx_ctx
.base
= info
->dma_ring_addr
/ 128;
579 rx_ctx
.qlen
= info
->ring_len
;
581 if (info
->splithdr_enabled
) {
582 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
584 I40E_RX_SPLIT_TCP_UDP
|
586 /* header length validation */
587 if (info
->hdr_size
> ((2 * 1024) - 64)) {
591 rx_ctx
.hbuff
= info
->hdr_size
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
593 /* set split mode 10b */
594 rx_ctx
.dtype
= I40E_RX_DTYPE_HEADER_SPLIT
;
597 /* databuffer length validation */
598 if (info
->databuffer_size
> ((16 * 1024) - 128)) {
602 rx_ctx
.dbuff
= info
->databuffer_size
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
604 /* max pkt. length validation */
605 if (info
->max_pkt_size
>= (16 * 1024) || info
->max_pkt_size
< 64) {
609 rx_ctx
.rxmax
= info
->max_pkt_size
;
611 /* enable 32bytes desc always */
615 rx_ctx
.lrxqthresh
= 2;
620 /* clear the context in the HMC */
621 ret
= i40e_clear_lan_rx_queue_context(hw
, pf_queue_id
);
623 dev_err(&pf
->pdev
->dev
,
624 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
630 /* set the context in the HMC */
631 ret
= i40e_set_lan_rx_queue_context(hw
, pf_queue_id
, &rx_ctx
);
633 dev_err(&pf
->pdev
->dev
,
634 "Failed to set VF LAN Rx queue context %d error: %d\n",
646 * @vf: pointer to the VF info
647 * @type: type of VSI to allocate
649 * alloc VF vsi context & resources
651 static int i40e_alloc_vsi_res(struct i40e_vf
*vf
, enum i40e_vsi_type type
)
653 struct i40e_mac_filter
*f
= NULL
;
654 struct i40e_pf
*pf
= vf
->pf
;
655 struct i40e_vsi
*vsi
;
658 vsi
= i40e_vsi_setup(pf
, type
, pf
->vsi
[pf
->lan_vsi
]->seid
, vf
->vf_id
);
661 dev_err(&pf
->pdev
->dev
,
662 "add vsi failed for VF %d, aq_err %d\n",
663 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
665 goto error_alloc_vsi_res
;
667 if (type
== I40E_VSI_SRIOV
) {
668 vf
->lan_vsi_idx
= vsi
->idx
;
669 vf
->lan_vsi_id
= vsi
->id
;
670 /* If the port VLAN has been configured and then the
671 * VF driver was removed then the VSI port VLAN
672 * configuration was destroyed. Check if there is
673 * a port VLAN and restore the VSI configuration if
676 if (vf
->port_vlan_id
)
677 i40e_vsi_add_pvid(vsi
, vf
->port_vlan_id
);
679 spin_lock_bh(&vsi
->mac_filter_list_lock
);
680 if (is_valid_ether_addr(vf
->default_lan_addr
.addr
)) {
681 f
= i40e_add_filter(vsi
, vf
->default_lan_addr
.addr
,
682 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
685 dev_info(&pf
->pdev
->dev
,
686 "Could not add MAC filter %pM for VF %d\n",
687 vf
->default_lan_addr
.addr
, vf
->vf_id
);
689 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
692 /* program mac filter */
693 ret
= i40e_sync_vsi_filters(vsi
);
695 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
697 /* Set VF bandwidth if specified */
699 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
700 vf
->tx_rate
/ 50, 0, NULL
);
702 dev_err(&pf
->pdev
->dev
, "Unable to set tx rate, VF %d, error code %d.\n",
711 * i40e_enable_vf_mappings
712 * @vf: pointer to the VF info
716 static void i40e_enable_vf_mappings(struct i40e_vf
*vf
)
718 struct i40e_pf
*pf
= vf
->pf
;
719 struct i40e_hw
*hw
= &pf
->hw
;
720 u32 reg
, total_queue_pairs
= 0;
723 /* Tell the hardware we're using noncontiguous mapping. HW requires
724 * that VF queues be mapped using this method, even when they are
725 * contiguous in real life
727 i40e_write_rx_ctl(hw
, I40E_VSILAN_QBASE(vf
->lan_vsi_id
),
728 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK
);
730 /* enable VF vplan_qtable mappings */
731 reg
= I40E_VPLAN_MAPENA_TXRX_ENA_MASK
;
732 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), reg
);
734 /* map PF queues to VF queues */
735 for (j
= 0; j
< pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
; j
++) {
736 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
, j
);
738 reg
= (qid
& I40E_VPLAN_QTABLE_QINDEX_MASK
);
739 wr32(hw
, I40E_VPLAN_QTABLE(total_queue_pairs
, vf
->vf_id
), reg
);
743 /* map PF queues to VSI */
744 for (j
= 0; j
< 7; j
++) {
745 if (j
* 2 >= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
) {
746 reg
= 0x07FF07FF; /* unused */
748 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
751 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
755 i40e_write_rx_ctl(hw
, I40E_VSILAN_QTABLE(j
, vf
->lan_vsi_id
),
763 * i40e_disable_vf_mappings
764 * @vf: pointer to the VF info
766 * disable VF mappings
768 static void i40e_disable_vf_mappings(struct i40e_vf
*vf
)
770 struct i40e_pf
*pf
= vf
->pf
;
771 struct i40e_hw
*hw
= &pf
->hw
;
774 /* disable qp mappings */
775 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), 0);
776 for (i
= 0; i
< I40E_MAX_VSI_QP
; i
++)
777 wr32(hw
, I40E_VPLAN_QTABLE(i
, vf
->vf_id
),
778 I40E_QUEUE_END_OF_LIST
);
784 * @vf: pointer to the VF info
788 static void i40e_free_vf_res(struct i40e_vf
*vf
)
790 struct i40e_pf
*pf
= vf
->pf
;
791 struct i40e_hw
*hw
= &pf
->hw
;
795 /* free vsi & disconnect it from the parent uplink */
796 if (vf
->lan_vsi_idx
) {
797 i40e_vsi_release(pf
->vsi
[vf
->lan_vsi_idx
]);
801 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
803 /* disable interrupts so the VF starts in a known state */
804 for (i
= 0; i
< msix_vf
; i
++) {
805 /* format is same for both registers */
807 reg_idx
= I40E_VFINT_DYN_CTL0(vf
->vf_id
);
809 reg_idx
= I40E_VFINT_DYN_CTLN(((msix_vf
- 1) *
812 wr32(hw
, reg_idx
, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
816 /* clear the irq settings */
817 for (i
= 0; i
< msix_vf
; i
++) {
818 /* format is same for both registers */
820 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
822 reg_idx
= I40E_VPINT_LNKLSTN(((msix_vf
- 1) *
825 reg
= (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
|
826 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
);
827 wr32(hw
, reg_idx
, reg
);
830 /* reset some of the state varibles keeping
831 * track of the resources
833 vf
->num_queue_pairs
= 0;
835 clear_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
840 * @vf: pointer to the VF info
842 * allocate VF resources
844 static int i40e_alloc_vf_res(struct i40e_vf
*vf
)
846 struct i40e_pf
*pf
= vf
->pf
;
847 int total_queue_pairs
= 0;
850 /* allocate hw vsi context & associated resources */
851 ret
= i40e_alloc_vsi_res(vf
, I40E_VSI_SRIOV
);
854 total_queue_pairs
+= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
857 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
859 clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
861 /* store the total qps number for the runtime
864 vf
->num_queue_pairs
= total_queue_pairs
;
866 /* VF is now completely initialized */
867 set_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
871 i40e_free_vf_res(vf
);
876 #define VF_DEVICE_STATUS 0xAA
877 #define VF_TRANS_PENDING_MASK 0x20
879 * i40e_quiesce_vf_pci
880 * @vf: pointer to the VF structure
882 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
883 * if the transactions never clear.
885 static int i40e_quiesce_vf_pci(struct i40e_vf
*vf
)
887 struct i40e_pf
*pf
= vf
->pf
;
888 struct i40e_hw
*hw
= &pf
->hw
;
892 vf_abs_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
894 wr32(hw
, I40E_PF_PCI_CIAA
,
895 VF_DEVICE_STATUS
| (vf_abs_id
<< I40E_PF_PCI_CIAA_VF_NUM_SHIFT
));
896 for (i
= 0; i
< 100; i
++) {
897 reg
= rd32(hw
, I40E_PF_PCI_CIAD
);
898 if ((reg
& VF_TRANS_PENDING_MASK
) == 0)
907 * @vf: pointer to the VF structure
908 * @flr: VFLR was issued or not
912 void i40e_reset_vf(struct i40e_vf
*vf
, bool flr
)
914 struct i40e_pf
*pf
= vf
->pf
;
915 struct i40e_hw
*hw
= &pf
->hw
;
916 u32 reg
, reg_idx
, bit_idx
;
920 if (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
924 clear_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
926 /* In the case of a VFLR, the HW has already reset the VF and we
927 * just need to clean up, so don't hit the VFRTRIG register.
930 /* reset VF using VPGEN_VFRTRIG reg */
931 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
932 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
933 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
936 /* clear the VFLR bit in GLGEN_VFLRSTAT */
937 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf
->vf_id
) / 32;
938 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf
->vf_id
) % 32;
939 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
942 if (i40e_quiesce_vf_pci(vf
))
943 dev_err(&pf
->pdev
->dev
, "VF %d PCI transactions stuck\n",
946 /* poll VPGEN_VFRSTAT reg to make sure
947 * that reset is complete
949 for (i
= 0; i
< 10; i
++) {
950 /* VF reset requires driver to first reset the VF and then
951 * poll the status register to make sure that the reset
952 * completed successfully. Due to internal HW FIFO flushes,
953 * we must wait 10ms before the register will be valid.
955 usleep_range(10000, 20000);
956 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
957 if (reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
) {
964 usleep_range(10000, 20000);
967 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
969 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_COMPLETED
);
970 /* clear the reset bit in the VPGEN_VFRTRIG reg */
971 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
972 reg
&= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
973 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
975 /* On initial reset, we won't have any queues */
976 if (vf
->lan_vsi_idx
== 0)
979 i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false);
981 /* reallocate VF resources to reset the VSI state */
982 i40e_free_vf_res(vf
);
983 if (!i40e_alloc_vf_res(vf
)) {
984 int abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
985 i40e_enable_vf_mappings(vf
);
986 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
987 clear_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
988 i40e_notify_client_of_vf_reset(pf
, abs_vf_id
);
990 /* tell the VF the reset is done */
991 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_VFACTIVE
);
994 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
999 * @pf: pointer to the PF structure
1003 void i40e_free_vfs(struct i40e_pf
*pf
)
1005 struct i40e_hw
*hw
= &pf
->hw
;
1006 u32 reg_idx
, bit_idx
;
1011 while (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
1012 usleep_range(1000, 2000);
1014 i40e_notify_client_of_vf_enable(pf
, 0);
1015 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
1016 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
1017 i40e_vsi_control_rings(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
],
1020 /* Disable IOV before freeing resources. This lets any VF drivers
1021 * running in the host get themselves cleaned up before we yank
1022 * the carpet out from underneath their feet.
1024 if (!pci_vfs_assigned(pf
->pdev
))
1025 pci_disable_sriov(pf
->pdev
);
1027 dev_warn(&pf
->pdev
->dev
, "VFs are assigned - not disabling SR-IOV\n");
1029 msleep(20); /* let any messages in transit get finished up */
1031 /* free up VF resources */
1032 tmp
= pf
->num_alloc_vfs
;
1033 pf
->num_alloc_vfs
= 0;
1034 for (i
= 0; i
< tmp
; i
++) {
1035 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
1036 i40e_free_vf_res(&pf
->vf
[i
]);
1037 /* disable qp mappings */
1038 i40e_disable_vf_mappings(&pf
->vf
[i
]);
1044 /* This check is for when the driver is unloaded while VFs are
1045 * assigned. Setting the number of VFs to 0 through sysfs is caught
1046 * before this function ever gets called.
1048 if (!pci_vfs_assigned(pf
->pdev
)) {
1049 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
1050 * work correctly when SR-IOV gets re-enabled.
1052 for (vf_id
= 0; vf_id
< tmp
; vf_id
++) {
1053 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
1054 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
1055 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
1058 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
1061 #ifdef CONFIG_PCI_IOV
1064 * @pf: pointer to the PF structure
1065 * @num_alloc_vfs: number of VFs to allocate
1067 * allocate VF resources
1069 int i40e_alloc_vfs(struct i40e_pf
*pf
, u16 num_alloc_vfs
)
1071 struct i40e_vf
*vfs
;
1074 /* Disable interrupt 0 so we don't try to handle the VFLR. */
1075 i40e_irq_dynamic_disable_icr0(pf
);
1077 /* Check to see if we're just allocating resources for extant VFs */
1078 if (pci_num_vf(pf
->pdev
) != num_alloc_vfs
) {
1079 ret
= pci_enable_sriov(pf
->pdev
, num_alloc_vfs
);
1081 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1082 pf
->num_alloc_vfs
= 0;
1086 i40e_notify_client_of_vf_enable(pf
, num_alloc_vfs
);
1087 /* allocate memory */
1088 vfs
= kcalloc(num_alloc_vfs
, sizeof(struct i40e_vf
), GFP_KERNEL
);
1095 /* apply default profile */
1096 for (i
= 0; i
< num_alloc_vfs
; i
++) {
1098 vfs
[i
].parent_type
= I40E_SWITCH_ELEMENT_TYPE_VEB
;
1101 /* assign default capabilities */
1102 set_bit(I40E_VIRTCHNL_VF_CAP_L2
, &vfs
[i
].vf_caps
);
1103 vfs
[i
].spoofchk
= true;
1104 /* VF resources get allocated during reset */
1105 i40e_reset_vf(&vfs
[i
], false);
1108 pf
->num_alloc_vfs
= num_alloc_vfs
;
1114 /* Re-enable interrupt 0. */
1115 i40e_irq_dynamic_enable_icr0(pf
, false);
1121 * i40e_pci_sriov_enable
1122 * @pdev: pointer to a pci_dev structure
1123 * @num_vfs: number of VFs to allocate
1125 * Enable or change the number of VFs
1127 static int i40e_pci_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
1129 #ifdef CONFIG_PCI_IOV
1130 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1131 int pre_existing_vfs
= pci_num_vf(pdev
);
1134 if (test_bit(__I40E_TESTING
, &pf
->state
)) {
1135 dev_warn(&pdev
->dev
,
1136 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1141 if (pre_existing_vfs
&& pre_existing_vfs
!= num_vfs
)
1143 else if (pre_existing_vfs
&& pre_existing_vfs
== num_vfs
)
1146 if (num_vfs
> pf
->num_req_vfs
) {
1147 dev_warn(&pdev
->dev
, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1148 num_vfs
, pf
->num_req_vfs
);
1153 dev_info(&pdev
->dev
, "Allocating %d VFs.\n", num_vfs
);
1154 err
= i40e_alloc_vfs(pf
, num_vfs
);
1156 dev_warn(&pdev
->dev
, "Failed to enable SR-IOV: %d\n", err
);
1170 * i40e_pci_sriov_configure
1171 * @pdev: pointer to a pci_dev structure
1172 * @num_vfs: number of VFs to allocate
1174 * Enable or change the number of VFs. Called when the user updates the number
1177 int i40e_pci_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
1179 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1182 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
1183 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
1184 i40e_do_reset_safe(pf
,
1185 BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1187 return i40e_pci_sriov_enable(pdev
, num_vfs
);
1190 if (!pci_vfs_assigned(pf
->pdev
)) {
1192 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1193 i40e_do_reset_safe(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1195 dev_warn(&pdev
->dev
, "Unable to free VFs because some are assigned to VMs.\n");
1201 /***********************virtual channel routines******************/
1204 * i40e_vc_send_msg_to_vf
1205 * @vf: pointer to the VF info
1206 * @v_opcode: virtual channel opcode
1207 * @v_retval: virtual channel return value
1208 * @msg: pointer to the msg buffer
1209 * @msglen: msg length
1213 static int i40e_vc_send_msg_to_vf(struct i40e_vf
*vf
, u32 v_opcode
,
1214 u32 v_retval
, u8
*msg
, u16 msglen
)
1221 /* validate the request */
1222 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
1227 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1229 /* single place to detect unsuccessful return values */
1231 vf
->num_invalid_msgs
++;
1232 dev_info(&pf
->pdev
->dev
, "VF %d failed opcode %d, retval: %d\n",
1233 vf
->vf_id
, v_opcode
, v_retval
);
1234 if (vf
->num_invalid_msgs
>
1235 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED
) {
1236 dev_err(&pf
->pdev
->dev
,
1237 "Number of invalid messages exceeded for VF %d\n",
1239 dev_err(&pf
->pdev
->dev
, "Use PF Control I/F to enable the VF\n");
1240 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
1243 vf
->num_valid_msgs
++;
1244 /* reset the invalid counter, if a valid message is received. */
1245 vf
->num_invalid_msgs
= 0;
1248 aq_ret
= i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
1251 dev_info(&pf
->pdev
->dev
,
1252 "Unable to send the message to VF %d aq_err %d\n",
1253 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
1261 * i40e_vc_send_resp_to_vf
1262 * @vf: pointer to the VF info
1263 * @opcode: operation code
1264 * @retval: return value
1266 * send resp msg to VF
1268 static int i40e_vc_send_resp_to_vf(struct i40e_vf
*vf
,
1269 enum i40e_virtchnl_ops opcode
,
1272 return i40e_vc_send_msg_to_vf(vf
, opcode
, retval
, NULL
, 0);
1276 * i40e_vc_get_version_msg
1277 * @vf: pointer to the VF info
1279 * called from the VF to request the API version used by the PF
1281 static int i40e_vc_get_version_msg(struct i40e_vf
*vf
, u8
*msg
)
1283 struct i40e_virtchnl_version_info info
= {
1284 I40E_VIRTCHNL_VERSION_MAJOR
, I40E_VIRTCHNL_VERSION_MINOR
1287 vf
->vf_ver
= *(struct i40e_virtchnl_version_info
*)msg
;
1288 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1290 info
.minor
= I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS
;
1291 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_VERSION
,
1292 I40E_SUCCESS
, (u8
*)&info
,
1294 i40e_virtchnl_version_info
));
1298 * i40e_vc_get_vf_resources_msg
1299 * @vf: pointer to the VF info
1300 * @msg: pointer to the msg buffer
1301 * @msglen: msg length
1303 * called from the VF to request its resources
1305 static int i40e_vc_get_vf_resources_msg(struct i40e_vf
*vf
, u8
*msg
)
1307 struct i40e_virtchnl_vf_resource
*vfres
= NULL
;
1308 struct i40e_pf
*pf
= vf
->pf
;
1309 i40e_status aq_ret
= 0;
1310 struct i40e_vsi
*vsi
;
1315 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
1316 aq_ret
= I40E_ERR_PARAM
;
1320 len
= (sizeof(struct i40e_virtchnl_vf_resource
) +
1321 sizeof(struct i40e_virtchnl_vsi_resource
) * num_vsis
);
1323 vfres
= kzalloc(len
, GFP_KERNEL
);
1325 aq_ret
= I40E_ERR_NO_MEMORY
;
1330 vf
->driver_caps
= *(u32
*)msg
;
1332 vf
->driver_caps
= I40E_VIRTCHNL_VF_OFFLOAD_L2
|
1333 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG
|
1334 I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1336 vfres
->vf_offload_flags
= I40E_VIRTCHNL_VF_OFFLOAD_L2
;
1337 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1338 if (!vsi
->info
.pvid
)
1339 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1341 if (i40e_vf_client_capable(pf
, vf
->vf_id
, I40E_CLIENT_IWARP
) &&
1342 (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_IWARP
)) {
1343 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_IWARP
;
1344 set_bit(I40E_VF_STAT_IWARPENA
, &vf
->vf_states
);
1347 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
1348 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF
;
1350 if ((pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) &&
1351 (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ
))
1352 vfres
->vf_offload_flags
|=
1353 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ
;
1355 vfres
->vf_offload_flags
|=
1356 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG
;
1359 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
) {
1360 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1361 vfres
->vf_offload_flags
|=
1362 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
;
1365 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING
) {
1366 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
1367 dev_err(&pf
->pdev
->dev
,
1368 "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
1370 ret
= I40E_ERR_PARAM
;
1373 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING
;
1376 if (pf
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
) {
1377 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
1378 vfres
->vf_offload_flags
|=
1379 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
;
1382 vfres
->num_vsis
= num_vsis
;
1383 vfres
->num_queue_pairs
= vf
->num_queue_pairs
;
1384 vfres
->max_vectors
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
1385 vfres
->rss_key_size
= I40E_HKEY_ARRAY_SIZE
;
1386 vfres
->rss_lut_size
= I40E_VF_HLUT_ARRAY_SIZE
;
1388 if (vf
->lan_vsi_idx
) {
1389 vfres
->vsi_res
[0].vsi_id
= vf
->lan_vsi_id
;
1390 vfres
->vsi_res
[0].vsi_type
= I40E_VSI_SRIOV
;
1391 vfres
->vsi_res
[0].num_queue_pairs
= vsi
->alloc_queue_pairs
;
1392 /* VFs only use TC 0 */
1393 vfres
->vsi_res
[0].qset_handle
1394 = le16_to_cpu(vsi
->info
.qs_handle
[0]);
1395 ether_addr_copy(vfres
->vsi_res
[0].default_mac_addr
,
1396 vf
->default_lan_addr
.addr
);
1398 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
1401 /* send the response back to the VF */
1402 ret
= i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
1403 aq_ret
, (u8
*)vfres
, len
);
1410 * i40e_vc_reset_vf_msg
1411 * @vf: pointer to the VF info
1412 * @msg: pointer to the msg buffer
1413 * @msglen: msg length
1415 * called from the VF to reset itself,
1416 * unlike other virtchnl messages, PF driver
1417 * doesn't send the response back to the VF
1419 static void i40e_vc_reset_vf_msg(struct i40e_vf
*vf
)
1421 if (test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
1422 i40e_reset_vf(vf
, false);
1426 * i40e_getnum_vf_vsi_vlan_filters
1427 * @vsi: pointer to the vsi
1429 * called to get the number of VLANs offloaded on this VF
1431 static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi
*vsi
)
1433 struct i40e_mac_filter
*f
;
1436 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1437 if (f
->vlan
>= 0 && f
->vlan
<= I40E_MAX_VLANID
)
1445 * i40e_vc_config_promiscuous_mode_msg
1446 * @vf: pointer to the VF info
1447 * @msg: pointer to the msg buffer
1448 * @msglen: msg length
1450 * called from the VF to configure the promiscuous mode of
1453 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf
*vf
,
1454 u8
*msg
, u16 msglen
)
1456 struct i40e_virtchnl_promisc_info
*info
=
1457 (struct i40e_virtchnl_promisc_info
*)msg
;
1458 struct i40e_pf
*pf
= vf
->pf
;
1459 struct i40e_hw
*hw
= &pf
->hw
;
1460 struct i40e_mac_filter
*f
;
1461 i40e_status aq_ret
= 0;
1462 bool allmulti
= false;
1463 struct i40e_vsi
*vsi
;
1464 bool alluni
= false;
1467 vsi
= i40e_find_vsi_from_id(pf
, info
->vsi_id
);
1468 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1469 !i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
)) {
1470 aq_ret
= I40E_ERR_PARAM
;
1473 if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
1474 dev_err(&pf
->pdev
->dev
,
1475 "Unprivileged VF %d is attempting to configure promiscuous mode\n",
1477 /* Lie to the VF on purpose. */
1481 /* Multicast promiscuous handling*/
1482 if (info
->flags
& I40E_FLAG_VF_MULTICAST_PROMISC
)
1485 if (vf
->port_vlan_id
) {
1486 aq_ret
= i40e_aq_set_vsi_mc_promisc_on_vlan(hw
, vsi
->seid
,
1490 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi
)) {
1491 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1492 if (f
->vlan
< 0 || f
->vlan
> I40E_MAX_VLANID
)
1494 aq_ret
= i40e_aq_set_vsi_mc_promisc_on_vlan(hw
,
1499 aq_err
= pf
->hw
.aq
.asq_last_status
;
1501 dev_err(&pf
->pdev
->dev
,
1502 "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
1504 i40e_stat_str(&pf
->hw
, aq_ret
),
1505 i40e_aq_str(&pf
->hw
, aq_err
));
1510 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(hw
, vsi
->seid
,
1512 aq_err
= pf
->hw
.aq
.asq_last_status
;
1514 dev_err(&pf
->pdev
->dev
,
1515 "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
1517 i40e_stat_str(&pf
->hw
, aq_ret
),
1518 i40e_aq_str(&pf
->hw
, aq_err
));
1519 goto error_param_int
;
1524 dev_info(&pf
->pdev
->dev
,
1525 "VF %d successfully set multicast promiscuous mode\n",
1528 set_bit(I40E_VF_STAT_MC_PROMISC
, &vf
->vf_states
);
1530 clear_bit(I40E_VF_STAT_MC_PROMISC
, &vf
->vf_states
);
1533 if (info
->flags
& I40E_FLAG_VF_UNICAST_PROMISC
)
1535 if (vf
->port_vlan_id
) {
1536 aq_ret
= i40e_aq_set_vsi_uc_promisc_on_vlan(hw
, vsi
->seid
,
1540 } else if (i40e_getnum_vf_vsi_vlan_filters(vsi
)) {
1541 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
) {
1543 if (f
->vlan
>= 0 && f
->vlan
<= I40E_MAX_VLANID
) {
1545 i40e_aq_set_vsi_uc_promisc_on_vlan(hw
,
1550 aq_err
= pf
->hw
.aq
.asq_last_status
;
1553 dev_err(&pf
->pdev
->dev
,
1554 "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
1556 i40e_stat_str(&pf
->hw
, aq_ret
),
1557 i40e_aq_str(&pf
->hw
, aq_err
));
1560 aq_ret
= i40e_aq_set_vsi_unicast_promiscuous(hw
, vsi
->seid
,
1563 aq_err
= pf
->hw
.aq
.asq_last_status
;
1565 dev_err(&pf
->pdev
->dev
,
1566 "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
1567 vf
->vf_id
, info
->flags
,
1568 i40e_stat_str(&pf
->hw
, aq_ret
),
1569 i40e_aq_str(&pf
->hw
, aq_err
));
1574 dev_info(&pf
->pdev
->dev
,
1575 "VF %d successfully set unicast promiscuous mode\n",
1578 set_bit(I40E_VF_STAT_UC_PROMISC
, &vf
->vf_states
);
1580 clear_bit(I40E_VF_STAT_UC_PROMISC
, &vf
->vf_states
);
1584 /* send the response to the VF */
1585 return i40e_vc_send_resp_to_vf(vf
,
1586 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
1591 * i40e_vc_config_queues_msg
1592 * @vf: pointer to the VF info
1593 * @msg: pointer to the msg buffer
1594 * @msglen: msg length
1596 * called from the VF to configure the rx/tx
1599 static int i40e_vc_config_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1601 struct i40e_virtchnl_vsi_queue_config_info
*qci
=
1602 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1603 struct i40e_virtchnl_queue_pair_info
*qpi
;
1604 struct i40e_pf
*pf
= vf
->pf
;
1605 u16 vsi_id
, vsi_queue_id
;
1606 i40e_status aq_ret
= 0;
1609 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1610 aq_ret
= I40E_ERR_PARAM
;
1614 vsi_id
= qci
->vsi_id
;
1615 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1616 aq_ret
= I40E_ERR_PARAM
;
1619 for (i
= 0; i
< qci
->num_queue_pairs
; i
++) {
1620 qpi
= &qci
->qpair
[i
];
1621 vsi_queue_id
= qpi
->txq
.queue_id
;
1622 if ((qpi
->txq
.vsi_id
!= vsi_id
) ||
1623 (qpi
->rxq
.vsi_id
!= vsi_id
) ||
1624 (qpi
->rxq
.queue_id
!= vsi_queue_id
) ||
1625 !i40e_vc_isvalid_queue_id(vf
, vsi_id
, vsi_queue_id
)) {
1626 aq_ret
= I40E_ERR_PARAM
;
1630 if (i40e_config_vsi_rx_queue(vf
, vsi_id
, vsi_queue_id
,
1632 i40e_config_vsi_tx_queue(vf
, vsi_id
, vsi_queue_id
,
1634 aq_ret
= I40E_ERR_PARAM
;
1638 /* set vsi num_queue_pairs in use to num configured by VF */
1639 pf
->vsi
[vf
->lan_vsi_idx
]->num_queue_pairs
= qci
->num_queue_pairs
;
1642 /* send the response to the VF */
1643 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
1648 * i40e_vc_config_irq_map_msg
1649 * @vf: pointer to the VF info
1650 * @msg: pointer to the msg buffer
1651 * @msglen: msg length
1653 * called from the VF to configure the irq to
1656 static int i40e_vc_config_irq_map_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1658 struct i40e_virtchnl_irq_map_info
*irqmap_info
=
1659 (struct i40e_virtchnl_irq_map_info
*)msg
;
1660 struct i40e_virtchnl_vector_map
*map
;
1661 u16 vsi_id
, vsi_queue_id
, vector_id
;
1662 i40e_status aq_ret
= 0;
1663 unsigned long tempmap
;
1666 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1667 aq_ret
= I40E_ERR_PARAM
;
1671 for (i
= 0; i
< irqmap_info
->num_vectors
; i
++) {
1672 map
= &irqmap_info
->vecmap
[i
];
1674 vector_id
= map
->vector_id
;
1675 vsi_id
= map
->vsi_id
;
1676 /* validate msg params */
1677 if (!i40e_vc_isvalid_vector_id(vf
, vector_id
) ||
1678 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1679 aq_ret
= I40E_ERR_PARAM
;
1683 /* lookout for the invalid queue index */
1684 tempmap
= map
->rxq_map
;
1685 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1686 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1688 aq_ret
= I40E_ERR_PARAM
;
1693 tempmap
= map
->txq_map
;
1694 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1695 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1697 aq_ret
= I40E_ERR_PARAM
;
1702 i40e_config_irq_link_list(vf
, vsi_id
, map
);
1705 /* send the response to the VF */
1706 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
1711 * i40e_vc_enable_queues_msg
1712 * @vf: pointer to the VF info
1713 * @msg: pointer to the msg buffer
1714 * @msglen: msg length
1716 * called from the VF to enable all or specific queue(s)
1718 static int i40e_vc_enable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1720 struct i40e_virtchnl_queue_select
*vqs
=
1721 (struct i40e_virtchnl_queue_select
*)msg
;
1722 struct i40e_pf
*pf
= vf
->pf
;
1723 u16 vsi_id
= vqs
->vsi_id
;
1724 i40e_status aq_ret
= 0;
1726 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1727 aq_ret
= I40E_ERR_PARAM
;
1731 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1732 aq_ret
= I40E_ERR_PARAM
;
1736 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1737 aq_ret
= I40E_ERR_PARAM
;
1741 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], true))
1742 aq_ret
= I40E_ERR_TIMEOUT
;
1744 /* send the response to the VF */
1745 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
1750 * i40e_vc_disable_queues_msg
1751 * @vf: pointer to the VF info
1752 * @msg: pointer to the msg buffer
1753 * @msglen: msg length
1755 * called from the VF to disable all or specific
1758 static int i40e_vc_disable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1760 struct i40e_virtchnl_queue_select
*vqs
=
1761 (struct i40e_virtchnl_queue_select
*)msg
;
1762 struct i40e_pf
*pf
= vf
->pf
;
1763 i40e_status aq_ret
= 0;
1765 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1766 aq_ret
= I40E_ERR_PARAM
;
1770 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1771 aq_ret
= I40E_ERR_PARAM
;
1775 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1776 aq_ret
= I40E_ERR_PARAM
;
1780 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false))
1781 aq_ret
= I40E_ERR_TIMEOUT
;
1784 /* send the response to the VF */
1785 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
1790 * i40e_vc_get_stats_msg
1791 * @vf: pointer to the VF info
1792 * @msg: pointer to the msg buffer
1793 * @msglen: msg length
1795 * called from the VF to get vsi stats
1797 static int i40e_vc_get_stats_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1799 struct i40e_virtchnl_queue_select
*vqs
=
1800 (struct i40e_virtchnl_queue_select
*)msg
;
1801 struct i40e_pf
*pf
= vf
->pf
;
1802 struct i40e_eth_stats stats
;
1803 i40e_status aq_ret
= 0;
1804 struct i40e_vsi
*vsi
;
1806 memset(&stats
, 0, sizeof(struct i40e_eth_stats
));
1808 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1809 aq_ret
= I40E_ERR_PARAM
;
1813 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1814 aq_ret
= I40E_ERR_PARAM
;
1818 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1820 aq_ret
= I40E_ERR_PARAM
;
1823 i40e_update_eth_stats(vsi
);
1824 stats
= vsi
->eth_stats
;
1827 /* send the response back to the VF */
1828 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_STATS
, aq_ret
,
1829 (u8
*)&stats
, sizeof(stats
));
1832 /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
1833 #define I40E_VC_MAX_MAC_ADDR_PER_VF 8
1834 #define I40E_VC_MAX_VLAN_PER_VF 8
1837 * i40e_check_vf_permission
1838 * @vf: pointer to the VF info
1839 * @macaddr: pointer to the MAC Address being checked
1841 * Check if the VF has permission to add or delete unicast MAC address
1842 * filters and return error code -EPERM if not. Then check if the
1843 * address filter requested is broadcast or zero and if so return
1844 * an invalid MAC address error code.
1846 static inline int i40e_check_vf_permission(struct i40e_vf
*vf
, u8
*macaddr
)
1848 struct i40e_pf
*pf
= vf
->pf
;
1851 if (is_broadcast_ether_addr(macaddr
) ||
1852 is_zero_ether_addr(macaddr
)) {
1853 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n", macaddr
);
1854 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1855 } else if (vf
->pf_set_mac
&& !is_multicast_ether_addr(macaddr
) &&
1856 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) &&
1857 !ether_addr_equal(macaddr
, vf
->default_lan_addr
.addr
)) {
1858 /* If the host VMM administrator has set the VF MAC address
1859 * administratively via the ndo_set_vf_mac command then deny
1860 * permission to the VF to add or delete unicast MAC addresses.
1861 * Unless the VF is privileged and then it can do whatever.
1862 * The VF may request to set the MAC address filter already
1863 * assigned to it so do not return an error in that case.
1865 dev_err(&pf
->pdev
->dev
,
1866 "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
1868 } else if ((vf
->num_mac
>= I40E_VC_MAX_MAC_ADDR_PER_VF
) &&
1869 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
1870 dev_err(&pf
->pdev
->dev
,
1871 "VF is not trusted, switch the VF to trusted to add more functionality\n");
1878 * i40e_vc_add_mac_addr_msg
1879 * @vf: pointer to the VF info
1880 * @msg: pointer to the msg buffer
1881 * @msglen: msg length
1883 * add guest mac address filter
1885 static int i40e_vc_add_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1887 struct i40e_virtchnl_ether_addr_list
*al
=
1888 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1889 struct i40e_pf
*pf
= vf
->pf
;
1890 struct i40e_vsi
*vsi
= NULL
;
1891 u16 vsi_id
= al
->vsi_id
;
1892 i40e_status ret
= 0;
1895 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1896 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1897 ret
= I40E_ERR_PARAM
;
1901 for (i
= 0; i
< al
->num_elements
; i
++) {
1902 ret
= i40e_check_vf_permission(vf
, al
->list
[i
].addr
);
1906 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1908 /* Lock once, because all function inside for loop accesses VSI's
1909 * MAC filter list which needs to be protected using same lock.
1911 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1913 /* add new addresses to the list */
1914 for (i
= 0; i
< al
->num_elements
; i
++) {
1915 struct i40e_mac_filter
*f
;
1917 f
= i40e_find_mac(vsi
, al
->list
[i
].addr
, true, false);
1919 if (i40e_is_vsi_in_vlan(vsi
))
1920 f
= i40e_put_mac_in_vlan(vsi
, al
->list
[i
].addr
,
1923 f
= i40e_add_filter(vsi
, al
->list
[i
].addr
, -1,
1928 dev_err(&pf
->pdev
->dev
,
1929 "Unable to add MAC filter %pM for VF %d\n",
1930 al
->list
[i
].addr
, vf
->vf_id
);
1931 ret
= I40E_ERR_PARAM
;
1932 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1938 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1940 /* program the updated filter list */
1941 ret
= i40e_sync_vsi_filters(vsi
);
1943 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
1947 /* send the response to the VF */
1948 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
1953 * i40e_vc_del_mac_addr_msg
1954 * @vf: pointer to the VF info
1955 * @msg: pointer to the msg buffer
1956 * @msglen: msg length
1958 * remove guest mac address filter
1960 static int i40e_vc_del_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1962 struct i40e_virtchnl_ether_addr_list
*al
=
1963 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1964 struct i40e_pf
*pf
= vf
->pf
;
1965 struct i40e_vsi
*vsi
= NULL
;
1966 u16 vsi_id
= al
->vsi_id
;
1967 i40e_status ret
= 0;
1970 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1971 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1972 ret
= I40E_ERR_PARAM
;
1976 for (i
= 0; i
< al
->num_elements
; i
++) {
1977 if (is_broadcast_ether_addr(al
->list
[i
].addr
) ||
1978 is_zero_ether_addr(al
->list
[i
].addr
)) {
1979 dev_err(&pf
->pdev
->dev
, "Invalid MAC addr %pM for VF %d\n",
1980 al
->list
[i
].addr
, vf
->vf_id
);
1981 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1985 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1987 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1988 /* delete addresses from the list */
1989 for (i
= 0; i
< al
->num_elements
; i
++)
1990 if (i40e_del_mac_all_vlan(vsi
, al
->list
[i
].addr
, true, false)) {
1991 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1992 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1998 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2000 /* program the updated filter list */
2001 ret
= i40e_sync_vsi_filters(vsi
);
2003 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
2007 /* send the response to the VF */
2008 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
2013 * i40e_vc_add_vlan_msg
2014 * @vf: pointer to the VF info
2015 * @msg: pointer to the msg buffer
2016 * @msglen: msg length
2018 * program guest vlan id
2020 static int i40e_vc_add_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2022 struct i40e_virtchnl_vlan_filter_list
*vfl
=
2023 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
2024 struct i40e_pf
*pf
= vf
->pf
;
2025 struct i40e_vsi
*vsi
= NULL
;
2026 u16 vsi_id
= vfl
->vsi_id
;
2027 i40e_status aq_ret
= 0;
2030 if ((vf
->num_vlan
>= I40E_VC_MAX_VLAN_PER_VF
) &&
2031 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
)) {
2032 dev_err(&pf
->pdev
->dev
,
2033 "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
2036 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2037 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2038 aq_ret
= I40E_ERR_PARAM
;
2042 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2043 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
2044 aq_ret
= I40E_ERR_PARAM
;
2045 dev_err(&pf
->pdev
->dev
,
2046 "invalid VF VLAN id %d\n", vfl
->vlan_id
[i
]);
2050 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2051 if (vsi
->info
.pvid
) {
2052 aq_ret
= I40E_ERR_PARAM
;
2056 i40e_vlan_stripping_enable(vsi
);
2057 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2058 /* add new VLAN filter */
2059 int ret
= i40e_vsi_add_vlan(vsi
, vfl
->vlan_id
[i
]);
2063 if (test_bit(I40E_VF_STAT_UC_PROMISC
, &vf
->vf_states
))
2064 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2068 if (test_bit(I40E_VF_STAT_MC_PROMISC
, &vf
->vf_states
))
2069 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2075 dev_err(&pf
->pdev
->dev
,
2076 "Unable to add VLAN filter %d for VF %d, error %d\n",
2077 vfl
->vlan_id
[i
], vf
->vf_id
, ret
);
2081 /* send the response to the VF */
2082 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_VLAN
, aq_ret
);
2086 * i40e_vc_remove_vlan_msg
2087 * @vf: pointer to the VF info
2088 * @msg: pointer to the msg buffer
2089 * @msglen: msg length
2091 * remove programmed guest vlan id
2093 static int i40e_vc_remove_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2095 struct i40e_virtchnl_vlan_filter_list
*vfl
=
2096 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
2097 struct i40e_pf
*pf
= vf
->pf
;
2098 struct i40e_vsi
*vsi
= NULL
;
2099 u16 vsi_id
= vfl
->vsi_id
;
2100 i40e_status aq_ret
= 0;
2103 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2104 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
2105 aq_ret
= I40E_ERR_PARAM
;
2109 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2110 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
2111 aq_ret
= I40E_ERR_PARAM
;
2116 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2117 if (vsi
->info
.pvid
) {
2118 aq_ret
= I40E_ERR_PARAM
;
2122 for (i
= 0; i
< vfl
->num_elements
; i
++) {
2123 int ret
= i40e_vsi_kill_vlan(vsi
, vfl
->vlan_id
[i
]);
2127 if (test_bit(I40E_VF_STAT_UC_PROMISC
, &vf
->vf_states
))
2128 i40e_aq_set_vsi_uc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2132 if (test_bit(I40E_VF_STAT_MC_PROMISC
, &vf
->vf_states
))
2133 i40e_aq_set_vsi_mc_promisc_on_vlan(&pf
->hw
, vsi
->seid
,
2139 dev_err(&pf
->pdev
->dev
,
2140 "Unable to delete VLAN filter %d for VF %d, error %d\n",
2141 vfl
->vlan_id
[i
], vf
->vf_id
, ret
);
2145 /* send the response to the VF */
2146 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_VLAN
, aq_ret
);
2151 * @vf: pointer to the VF info
2152 * @msg: pointer to the msg buffer
2153 * @msglen: msg length
2155 * called from the VF for the iwarp msgs
2157 static int i40e_vc_iwarp_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2159 struct i40e_pf
*pf
= vf
->pf
;
2160 int abs_vf_id
= vf
->vf_id
+ pf
->hw
.func_caps
.vf_base_id
;
2161 i40e_status aq_ret
= 0;
2163 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2164 !test_bit(I40E_VF_STAT_IWARPENA
, &vf
->vf_states
)) {
2165 aq_ret
= I40E_ERR_PARAM
;
2169 i40e_notify_client_of_vf_msg(pf
->vsi
[pf
->lan_vsi
], abs_vf_id
,
2173 /* send the response to the VF */
2174 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_IWARP
,
2179 * i40e_vc_iwarp_qvmap_msg
2180 * @vf: pointer to the VF info
2181 * @msg: pointer to the msg buffer
2182 * @msglen: msg length
2183 * @config: config qvmap or release it
2185 * called from the VF for the iwarp msgs
2187 static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
,
2190 struct i40e_virtchnl_iwarp_qvlist_info
*qvlist_info
=
2191 (struct i40e_virtchnl_iwarp_qvlist_info
*)msg
;
2192 i40e_status aq_ret
= 0;
2194 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2195 !test_bit(I40E_VF_STAT_IWARPENA
, &vf
->vf_states
)) {
2196 aq_ret
= I40E_ERR_PARAM
;
2201 if (i40e_config_iwarp_qvlist(vf
, qvlist_info
))
2202 aq_ret
= I40E_ERR_PARAM
;
2204 i40e_release_iwarp_qvlist(vf
);
2208 /* send the response to the VF */
2209 return i40e_vc_send_resp_to_vf(vf
,
2210 config
? I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
:
2211 I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
,
2216 * i40e_vc_config_rss_key
2217 * @vf: pointer to the VF info
2218 * @msg: pointer to the msg buffer
2219 * @msglen: msg length
2221 * Configure the VF's RSS key
2223 static int i40e_vc_config_rss_key(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2225 struct i40e_virtchnl_rss_key
*vrk
=
2226 (struct i40e_virtchnl_rss_key
*)msg
;
2227 struct i40e_pf
*pf
= vf
->pf
;
2228 struct i40e_vsi
*vsi
= NULL
;
2229 u16 vsi_id
= vrk
->vsi_id
;
2230 i40e_status aq_ret
= 0;
2232 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2233 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
) ||
2234 (vrk
->key_len
!= I40E_HKEY_ARRAY_SIZE
)) {
2235 aq_ret
= I40E_ERR_PARAM
;
2239 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2240 aq_ret
= i40e_config_rss(vsi
, vrk
->key
, NULL
, 0);
2242 /* send the response to the VF */
2243 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
,
2248 * i40e_vc_config_rss_lut
2249 * @vf: pointer to the VF info
2250 * @msg: pointer to the msg buffer
2251 * @msglen: msg length
2253 * Configure the VF's RSS LUT
2255 static int i40e_vc_config_rss_lut(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2257 struct i40e_virtchnl_rss_lut
*vrl
=
2258 (struct i40e_virtchnl_rss_lut
*)msg
;
2259 struct i40e_pf
*pf
= vf
->pf
;
2260 struct i40e_vsi
*vsi
= NULL
;
2261 u16 vsi_id
= vrl
->vsi_id
;
2262 i40e_status aq_ret
= 0;
2264 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
2265 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
) ||
2266 (vrl
->lut_entries
!= I40E_VF_HLUT_ARRAY_SIZE
)) {
2267 aq_ret
= I40E_ERR_PARAM
;
2271 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2272 aq_ret
= i40e_config_rss(vsi
, NULL
, vrl
->lut
, I40E_VF_HLUT_ARRAY_SIZE
);
2273 /* send the response to the VF */
2275 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
,
2280 * i40e_vc_get_rss_hena
2281 * @vf: pointer to the VF info
2282 * @msg: pointer to the msg buffer
2283 * @msglen: msg length
2285 * Return the RSS HENA bits allowed by the hardware
2287 static int i40e_vc_get_rss_hena(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2289 struct i40e_virtchnl_rss_hena
*vrh
= NULL
;
2290 struct i40e_pf
*pf
= vf
->pf
;
2291 i40e_status aq_ret
= 0;
2294 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
2295 aq_ret
= I40E_ERR_PARAM
;
2298 len
= sizeof(struct i40e_virtchnl_rss_hena
);
2300 vrh
= kzalloc(len
, GFP_KERNEL
);
2302 aq_ret
= I40E_ERR_NO_MEMORY
;
2306 vrh
->hena
= i40e_pf_get_default_rss_hena(pf
);
2308 /* send the response back to the VF */
2309 aq_ret
= i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
,
2310 aq_ret
, (u8
*)vrh
, len
);
2315 * i40e_vc_set_rss_hena
2316 * @vf: pointer to the VF info
2317 * @msg: pointer to the msg buffer
2318 * @msglen: msg length
2320 * Set the RSS HENA bits for the VF
2322 static int i40e_vc_set_rss_hena(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
2324 struct i40e_virtchnl_rss_hena
*vrh
=
2325 (struct i40e_virtchnl_rss_hena
*)msg
;
2326 struct i40e_pf
*pf
= vf
->pf
;
2327 struct i40e_hw
*hw
= &pf
->hw
;
2328 i40e_status aq_ret
= 0;
2330 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
2331 aq_ret
= I40E_ERR_PARAM
;
2334 i40e_write_rx_ctl(hw
, I40E_VFQF_HENA1(0, vf
->vf_id
), (u32
)vrh
->hena
);
2335 i40e_write_rx_ctl(hw
, I40E_VFQF_HENA1(1, vf
->vf_id
),
2336 (u32
)(vrh
->hena
>> 32));
2338 /* send the response to the VF */
2340 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_SET_RSS_HENA
,
2345 * i40e_vc_validate_vf_msg
2346 * @vf: pointer to the VF info
2347 * @msg: pointer to the msg buffer
2348 * @msglen: msg length
2349 * @msghndl: msg handle
2353 static int i40e_vc_validate_vf_msg(struct i40e_vf
*vf
, u32 v_opcode
,
2354 u32 v_retval
, u8
*msg
, u16 msglen
)
2356 bool err_msg_format
= false;
2359 /* Check if VF is disabled. */
2360 if (test_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
))
2361 return I40E_ERR_PARAM
;
2363 /* Validate message length. */
2365 case I40E_VIRTCHNL_OP_VERSION
:
2366 valid_len
= sizeof(struct i40e_virtchnl_version_info
);
2368 case I40E_VIRTCHNL_OP_RESET_VF
:
2370 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
2372 valid_len
= sizeof(u32
);
2374 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE
:
2375 valid_len
= sizeof(struct i40e_virtchnl_txq_info
);
2377 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE
:
2378 valid_len
= sizeof(struct i40e_virtchnl_rxq_info
);
2380 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
2381 valid_len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
);
2382 if (msglen
>= valid_len
) {
2383 struct i40e_virtchnl_vsi_queue_config_info
*vqc
=
2384 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
2385 valid_len
+= (vqc
->num_queue_pairs
*
2387 i40e_virtchnl_queue_pair_info
));
2388 if (vqc
->num_queue_pairs
== 0)
2389 err_msg_format
= true;
2392 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
2393 valid_len
= sizeof(struct i40e_virtchnl_irq_map_info
);
2394 if (msglen
>= valid_len
) {
2395 struct i40e_virtchnl_irq_map_info
*vimi
=
2396 (struct i40e_virtchnl_irq_map_info
*)msg
;
2397 valid_len
+= (vimi
->num_vectors
*
2398 sizeof(struct i40e_virtchnl_vector_map
));
2399 if (vimi
->num_vectors
== 0)
2400 err_msg_format
= true;
2403 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
2404 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
2405 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
2407 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
2408 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
2409 valid_len
= sizeof(struct i40e_virtchnl_ether_addr_list
);
2410 if (msglen
>= valid_len
) {
2411 struct i40e_virtchnl_ether_addr_list
*veal
=
2412 (struct i40e_virtchnl_ether_addr_list
*)msg
;
2413 valid_len
+= veal
->num_elements
*
2414 sizeof(struct i40e_virtchnl_ether_addr
);
2415 if (veal
->num_elements
== 0)
2416 err_msg_format
= true;
2419 case I40E_VIRTCHNL_OP_ADD_VLAN
:
2420 case I40E_VIRTCHNL_OP_DEL_VLAN
:
2421 valid_len
= sizeof(struct i40e_virtchnl_vlan_filter_list
);
2422 if (msglen
>= valid_len
) {
2423 struct i40e_virtchnl_vlan_filter_list
*vfl
=
2424 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
2425 valid_len
+= vfl
->num_elements
* sizeof(u16
);
2426 if (vfl
->num_elements
== 0)
2427 err_msg_format
= true;
2430 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
2431 valid_len
= sizeof(struct i40e_virtchnl_promisc_info
);
2433 case I40E_VIRTCHNL_OP_GET_STATS
:
2434 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
2436 case I40E_VIRTCHNL_OP_IWARP
:
2437 /* These messages are opaque to us and will be validated in
2438 * the RDMA client code. We just need to check for nonzero
2439 * length. The firmware will enforce max length restrictions.
2444 err_msg_format
= true;
2446 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
:
2449 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
2450 valid_len
= sizeof(struct i40e_virtchnl_iwarp_qvlist_info
);
2451 if (msglen
>= valid_len
) {
2452 struct i40e_virtchnl_iwarp_qvlist_info
*qv
=
2453 (struct i40e_virtchnl_iwarp_qvlist_info
*)msg
;
2454 if (qv
->num_vectors
== 0) {
2455 err_msg_format
= true;
2458 valid_len
+= ((qv
->num_vectors
- 1) *
2459 sizeof(struct i40e_virtchnl_iwarp_qv_info
));
2462 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
:
2463 valid_len
= sizeof(struct i40e_virtchnl_rss_key
);
2464 if (msglen
>= valid_len
) {
2465 struct i40e_virtchnl_rss_key
*vrk
=
2466 (struct i40e_virtchnl_rss_key
*)msg
;
2467 if (vrk
->key_len
!= I40E_HKEY_ARRAY_SIZE
) {
2468 err_msg_format
= true;
2471 valid_len
+= vrk
->key_len
- 1;
2474 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
:
2475 valid_len
= sizeof(struct i40e_virtchnl_rss_lut
);
2476 if (msglen
>= valid_len
) {
2477 struct i40e_virtchnl_rss_lut
*vrl
=
2478 (struct i40e_virtchnl_rss_lut
*)msg
;
2479 if (vrl
->lut_entries
!= I40E_VF_HLUT_ARRAY_SIZE
) {
2480 err_msg_format
= true;
2483 valid_len
+= vrl
->lut_entries
- 1;
2486 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
:
2488 case I40E_VIRTCHNL_OP_SET_RSS_HENA
:
2489 valid_len
= sizeof(struct i40e_virtchnl_rss_hena
);
2491 /* These are always errors coming from the VF. */
2492 case I40E_VIRTCHNL_OP_EVENT
:
2493 case I40E_VIRTCHNL_OP_UNKNOWN
:
2497 /* few more checks */
2498 if ((valid_len
!= msglen
) || (err_msg_format
)) {
2499 i40e_vc_send_resp_to_vf(vf
, v_opcode
, I40E_ERR_PARAM
);
2507 * i40e_vc_process_vf_msg
2508 * @pf: pointer to the PF structure
2509 * @vf_id: source VF id
2510 * @msg: pointer to the msg buffer
2511 * @msglen: msg length
2512 * @msghndl: msg handle
2514 * called from the common aeq/arq handler to
2515 * process request from VF
2517 int i40e_vc_process_vf_msg(struct i40e_pf
*pf
, s16 vf_id
, u32 v_opcode
,
2518 u32 v_retval
, u8
*msg
, u16 msglen
)
2520 struct i40e_hw
*hw
= &pf
->hw
;
2521 int local_vf_id
= vf_id
- (s16
)hw
->func_caps
.vf_base_id
;
2525 pf
->vf_aq_requests
++;
2526 if (local_vf_id
>= pf
->num_alloc_vfs
)
2528 vf
= &(pf
->vf
[local_vf_id
]);
2529 /* perform basic checks on the msg */
2530 ret
= i40e_vc_validate_vf_msg(vf
, v_opcode
, v_retval
, msg
, msglen
);
2533 dev_err(&pf
->pdev
->dev
, "Invalid message from VF %d, opcode %d, len %d\n",
2534 local_vf_id
, v_opcode
, msglen
);
2539 case I40E_VIRTCHNL_OP_VERSION
:
2540 ret
= i40e_vc_get_version_msg(vf
, msg
);
2542 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
2543 ret
= i40e_vc_get_vf_resources_msg(vf
, msg
);
2545 case I40E_VIRTCHNL_OP_RESET_VF
:
2546 i40e_vc_reset_vf_msg(vf
);
2549 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
2550 ret
= i40e_vc_config_promiscuous_mode_msg(vf
, msg
, msglen
);
2552 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
2553 ret
= i40e_vc_config_queues_msg(vf
, msg
, msglen
);
2555 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
2556 ret
= i40e_vc_config_irq_map_msg(vf
, msg
, msglen
);
2558 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
2559 ret
= i40e_vc_enable_queues_msg(vf
, msg
, msglen
);
2560 i40e_vc_notify_vf_link_state(vf
);
2562 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
2563 ret
= i40e_vc_disable_queues_msg(vf
, msg
, msglen
);
2565 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
2566 ret
= i40e_vc_add_mac_addr_msg(vf
, msg
, msglen
);
2568 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
2569 ret
= i40e_vc_del_mac_addr_msg(vf
, msg
, msglen
);
2571 case I40E_VIRTCHNL_OP_ADD_VLAN
:
2572 ret
= i40e_vc_add_vlan_msg(vf
, msg
, msglen
);
2574 case I40E_VIRTCHNL_OP_DEL_VLAN
:
2575 ret
= i40e_vc_remove_vlan_msg(vf
, msg
, msglen
);
2577 case I40E_VIRTCHNL_OP_GET_STATS
:
2578 ret
= i40e_vc_get_stats_msg(vf
, msg
, msglen
);
2580 case I40E_VIRTCHNL_OP_IWARP
:
2581 ret
= i40e_vc_iwarp_msg(vf
, msg
, msglen
);
2583 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
2584 ret
= i40e_vc_iwarp_qvmap_msg(vf
, msg
, msglen
, true);
2586 case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP
:
2587 ret
= i40e_vc_iwarp_qvmap_msg(vf
, msg
, msglen
, false);
2589 case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
:
2590 ret
= i40e_vc_config_rss_key(vf
, msg
, msglen
);
2592 case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
:
2593 ret
= i40e_vc_config_rss_lut(vf
, msg
, msglen
);
2595 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
:
2596 ret
= i40e_vc_get_rss_hena(vf
, msg
, msglen
);
2598 case I40E_VIRTCHNL_OP_SET_RSS_HENA
:
2599 ret
= i40e_vc_set_rss_hena(vf
, msg
, msglen
);
2602 case I40E_VIRTCHNL_OP_UNKNOWN
:
2604 dev_err(&pf
->pdev
->dev
, "Unsupported opcode %d from VF %d\n",
2605 v_opcode
, local_vf_id
);
2606 ret
= i40e_vc_send_resp_to_vf(vf
, v_opcode
,
2607 I40E_ERR_NOT_IMPLEMENTED
);
2615 * i40e_vc_process_vflr_event
2616 * @pf: pointer to the PF structure
2618 * called from the vlfr irq handler to
2619 * free up VF resources and state variables
2621 int i40e_vc_process_vflr_event(struct i40e_pf
*pf
)
2623 struct i40e_hw
*hw
= &pf
->hw
;
2624 u32 reg
, reg_idx
, bit_idx
;
2628 if (!test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
2631 /* Re-enable the VFLR interrupt cause here, before looking for which
2632 * VF got reset. Otherwise, if another VF gets a reset while the
2633 * first one is being processed, that interrupt will be lost, and
2634 * that VF will be stuck in reset forever.
2636 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
2637 reg
|= I40E_PFINT_ICR0_ENA_VFLR_MASK
;
2638 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
2641 clear_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
2642 for (vf_id
= 0; vf_id
< pf
->num_alloc_vfs
; vf_id
++) {
2643 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
2644 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
2645 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
2646 vf
= &pf
->vf
[vf_id
];
2647 reg
= rd32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
));
2648 if (reg
& BIT(bit_idx
))
2649 /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
2650 i40e_reset_vf(vf
, true);
2657 * i40e_ndo_set_vf_mac
2658 * @netdev: network interface device structure
2659 * @vf_id: VF identifier
2662 * program VF mac address
2664 int i40e_ndo_set_vf_mac(struct net_device
*netdev
, int vf_id
, u8
*mac
)
2666 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2667 struct i40e_vsi
*vsi
= np
->vsi
;
2668 struct i40e_pf
*pf
= vsi
->back
;
2669 struct i40e_mac_filter
*f
;
2673 /* validate the request */
2674 if (vf_id
>= pf
->num_alloc_vfs
) {
2675 dev_err(&pf
->pdev
->dev
,
2676 "Invalid VF Identifier %d\n", vf_id
);
2681 vf
= &(pf
->vf
[vf_id
]);
2682 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2683 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2684 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2690 if (is_multicast_ether_addr(mac
)) {
2691 dev_err(&pf
->pdev
->dev
,
2692 "Invalid Ethernet address %pM for VF %d\n", mac
, vf_id
);
2697 /* Lock once because below invoked function add/del_filter requires
2698 * mac_filter_list_lock to be held
2700 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2702 /* delete the temporary mac address */
2703 if (!is_zero_ether_addr(vf
->default_lan_addr
.addr
))
2704 i40e_del_filter(vsi
, vf
->default_lan_addr
.addr
,
2705 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
2708 /* Delete all the filters for this VSI - we're going to kill it
2711 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2712 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
, true, false);
2714 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2716 dev_info(&pf
->pdev
->dev
, "Setting MAC %pM on VF %d\n", mac
, vf_id
);
2717 /* program mac filter */
2718 if (i40e_sync_vsi_filters(vsi
)) {
2719 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
2723 ether_addr_copy(vf
->default_lan_addr
.addr
, mac
);
2724 vf
->pf_set_mac
= true;
2725 /* Force the VF driver stop so it has to reload with new MAC address */
2726 i40e_vc_disable_vf(pf
, vf
);
2727 dev_info(&pf
->pdev
->dev
, "Reload the VF driver to make this change effective.\n");
2734 * i40e_ndo_set_vf_port_vlan
2735 * @netdev: network interface device structure
2736 * @vf_id: VF identifier
2737 * @vlan_id: mac address
2738 * @qos: priority setting
2740 * program VF vlan id and/or qos
2742 int i40e_ndo_set_vf_port_vlan(struct net_device
*netdev
,
2743 int vf_id
, u16 vlan_id
, u8 qos
)
2745 u16 vlanprio
= vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
);
2746 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2747 struct i40e_pf
*pf
= np
->vsi
->back
;
2748 bool is_vsi_in_vlan
= false;
2749 struct i40e_vsi
*vsi
;
2753 /* validate the request */
2754 if (vf_id
>= pf
->num_alloc_vfs
) {
2755 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2760 if ((vlan_id
> I40E_MAX_VLANID
) || (qos
> 7)) {
2761 dev_err(&pf
->pdev
->dev
, "Invalid VF Parameters\n");
2766 vf
= &(pf
->vf
[vf_id
]);
2767 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2768 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2769 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2775 if (le16_to_cpu(vsi
->info
.pvid
) == vlanprio
)
2776 /* duplicate request, so just return success */
2779 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2780 is_vsi_in_vlan
= i40e_is_vsi_in_vlan(vsi
);
2781 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2783 if (le16_to_cpu(vsi
->info
.pvid
) == 0 && is_vsi_in_vlan
) {
2784 dev_err(&pf
->pdev
->dev
,
2785 "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",
2787 /* Administrator Error - knock the VF offline until he does
2788 * the right thing by reconfiguring his network correctly
2789 * and then reloading the VF driver.
2791 i40e_vc_disable_vf(pf
, vf
);
2792 /* During reset the VF got a new VSI, so refresh the pointer. */
2793 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2796 /* Check for condition where there was already a port VLAN ID
2797 * filter set and now it is being deleted by setting it to zero.
2798 * Additionally check for the condition where there was a port
2799 * VLAN but now there is a new and different port VLAN being set.
2800 * Before deleting all the old VLAN filters we must add new ones
2801 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2802 * MAC addresses deleted.
2804 if ((!(vlan_id
|| qos
) ||
2805 vlanprio
!= le16_to_cpu(vsi
->info
.pvid
)) &&
2807 ret
= i40e_vsi_add_vlan(vsi
, I40E_VLAN_ANY
);
2809 if (vsi
->info
.pvid
) {
2811 ret
= i40e_vsi_kill_vlan(vsi
, (le16_to_cpu(vsi
->info
.pvid
) &
2814 dev_info(&vsi
->back
->pdev
->dev
,
2815 "remove VLAN failed, ret=%d, aq_err=%d\n",
2816 ret
, pf
->hw
.aq
.asq_last_status
);
2820 ret
= i40e_vsi_add_pvid(vsi
, vlanprio
);
2822 i40e_vsi_remove_pvid(vsi
);
2825 dev_info(&pf
->pdev
->dev
, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2826 vlan_id
, qos
, vf_id
);
2828 /* add new VLAN filter */
2829 ret
= i40e_vsi_add_vlan(vsi
, vlan_id
);
2831 dev_info(&vsi
->back
->pdev
->dev
,
2832 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
2833 vsi
->back
->hw
.aq
.asq_last_status
);
2836 /* Kill non-vlan MAC filters - ignore error return since
2837 * there might not be any non-vlan MAC filters.
2839 i40e_vsi_kill_vlan(vsi
, I40E_VLAN_ANY
);
2843 dev_err(&pf
->pdev
->dev
, "Unable to update VF vsi context\n");
2846 /* The Port VLAN needs to be saved across resets the same as the
2847 * default LAN MAC address.
2849 vf
->port_vlan_id
= le16_to_cpu(vsi
->info
.pvid
);
2856 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2857 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2859 * i40e_ndo_set_vf_bw
2860 * @netdev: network interface device structure
2861 * @vf_id: VF identifier
2864 * configure VF Tx rate
2866 int i40e_ndo_set_vf_bw(struct net_device
*netdev
, int vf_id
, int min_tx_rate
,
2869 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2870 struct i40e_pf
*pf
= np
->vsi
->back
;
2871 struct i40e_vsi
*vsi
;
2876 /* validate the request */
2877 if (vf_id
>= pf
->num_alloc_vfs
) {
2878 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d.\n", vf_id
);
2884 dev_err(&pf
->pdev
->dev
, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2885 min_tx_rate
, vf_id
);
2889 vf
= &(pf
->vf
[vf_id
]);
2890 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2891 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2892 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2898 switch (pf
->hw
.phy
.link_info
.link_speed
) {
2899 case I40E_LINK_SPEED_40GB
:
2902 case I40E_LINK_SPEED_20GB
:
2905 case I40E_LINK_SPEED_10GB
:
2908 case I40E_LINK_SPEED_1GB
:
2915 if (max_tx_rate
> speed
) {
2916 dev_err(&pf
->pdev
->dev
, "Invalid max tx rate %d specified for VF %d.",
2917 max_tx_rate
, vf
->vf_id
);
2922 if ((max_tx_rate
< 50) && (max_tx_rate
> 0)) {
2923 dev_warn(&pf
->pdev
->dev
, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2927 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2928 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
2929 max_tx_rate
/ I40E_BW_CREDIT_DIVISOR
,
2930 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
2932 dev_err(&pf
->pdev
->dev
, "Unable to set max tx rate, error code %d.\n",
2937 vf
->tx_rate
= max_tx_rate
;
2943 * i40e_ndo_get_vf_config
2944 * @netdev: network interface device structure
2945 * @vf_id: VF identifier
2946 * @ivi: VF configuration structure
2948 * return VF configuration
2950 int i40e_ndo_get_vf_config(struct net_device
*netdev
,
2951 int vf_id
, struct ifla_vf_info
*ivi
)
2953 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2954 struct i40e_vsi
*vsi
= np
->vsi
;
2955 struct i40e_pf
*pf
= vsi
->back
;
2959 /* validate the request */
2960 if (vf_id
>= pf
->num_alloc_vfs
) {
2961 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2966 vf
= &(pf
->vf
[vf_id
]);
2967 /* first vsi is always the LAN vsi */
2968 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2969 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2970 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2978 ether_addr_copy(ivi
->mac
, vf
->default_lan_addr
.addr
);
2980 ivi
->max_tx_rate
= vf
->tx_rate
;
2981 ivi
->min_tx_rate
= 0;
2982 ivi
->vlan
= le16_to_cpu(vsi
->info
.pvid
) & I40E_VLAN_MASK
;
2983 ivi
->qos
= (le16_to_cpu(vsi
->info
.pvid
) & I40E_PRIORITY_MASK
) >>
2984 I40E_VLAN_PRIORITY_SHIFT
;
2985 if (vf
->link_forced
== false)
2986 ivi
->linkstate
= IFLA_VF_LINK_STATE_AUTO
;
2987 else if (vf
->link_up
== true)
2988 ivi
->linkstate
= IFLA_VF_LINK_STATE_ENABLE
;
2990 ivi
->linkstate
= IFLA_VF_LINK_STATE_DISABLE
;
2991 ivi
->spoofchk
= vf
->spoofchk
;
2999 * i40e_ndo_set_vf_link_state
3000 * @netdev: network interface device structure
3001 * @vf_id: VF identifier
3002 * @link: required link state
3004 * Set the link state of a specified VF, regardless of physical link state
3006 int i40e_ndo_set_vf_link_state(struct net_device
*netdev
, int vf_id
, int link
)
3008 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3009 struct i40e_pf
*pf
= np
->vsi
->back
;
3010 struct i40e_virtchnl_pf_event pfe
;
3011 struct i40e_hw
*hw
= &pf
->hw
;
3016 /* validate the request */
3017 if (vf_id
>= pf
->num_alloc_vfs
) {
3018 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3023 vf
= &pf
->vf
[vf_id
];
3024 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
3026 pfe
.event
= I40E_VIRTCHNL_EVENT_LINK_CHANGE
;
3027 pfe
.severity
= I40E_PF_EVENT_SEVERITY_INFO
;
3030 case IFLA_VF_LINK_STATE_AUTO
:
3031 vf
->link_forced
= false;
3032 pfe
.event_data
.link_event
.link_status
=
3033 pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
3034 pfe
.event_data
.link_event
.link_speed
=
3035 pf
->hw
.phy
.link_info
.link_speed
;
3037 case IFLA_VF_LINK_STATE_ENABLE
:
3038 vf
->link_forced
= true;
3040 pfe
.event_data
.link_event
.link_status
= true;
3041 pfe
.event_data
.link_event
.link_speed
= I40E_LINK_SPEED_40GB
;
3043 case IFLA_VF_LINK_STATE_DISABLE
:
3044 vf
->link_forced
= true;
3045 vf
->link_up
= false;
3046 pfe
.event_data
.link_event
.link_status
= false;
3047 pfe
.event_data
.link_event
.link_speed
= 0;
3053 /* Notify the VF of its new link state */
3054 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
3055 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
3062 * i40e_ndo_set_vf_spoofchk
3063 * @netdev: network interface device structure
3064 * @vf_id: VF identifier
3065 * @enable: flag to enable or disable feature
3067 * Enable or disable VF spoof checking
3069 int i40e_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf_id
, bool enable
)
3071 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3072 struct i40e_vsi
*vsi
= np
->vsi
;
3073 struct i40e_pf
*pf
= vsi
->back
;
3074 struct i40e_vsi_context ctxt
;
3075 struct i40e_hw
*hw
= &pf
->hw
;
3079 /* validate the request */
3080 if (vf_id
>= pf
->num_alloc_vfs
) {
3081 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3086 vf
= &(pf
->vf
[vf_id
]);
3087 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
3088 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
3094 if (enable
== vf
->spoofchk
)
3097 vf
->spoofchk
= enable
;
3098 memset(&ctxt
, 0, sizeof(ctxt
));
3099 ctxt
.seid
= pf
->vsi
[vf
->lan_vsi_idx
]->seid
;
3100 ctxt
.pf_num
= pf
->hw
.pf_id
;
3101 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
3103 ctxt
.info
.sec_flags
|= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
3104 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
3105 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
3107 dev_err(&pf
->pdev
->dev
, "Error %d updating VSI parameters\n",
3116 * i40e_ndo_set_vf_trust
3117 * @netdev: network interface device structure of the pf
3118 * @vf_id: VF identifier
3119 * @setting: trust setting
3121 * Enable or disable VF trust setting
3123 int i40e_ndo_set_vf_trust(struct net_device
*netdev
, int vf_id
, bool setting
)
3125 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3126 struct i40e_pf
*pf
= np
->vsi
->back
;
3130 /* validate the request */
3131 if (vf_id
>= pf
->num_alloc_vfs
) {
3132 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
3136 if (pf
->flags
& I40E_FLAG_MFP_ENABLED
) {
3137 dev_err(&pf
->pdev
->dev
, "Trusted VF not supported in MFP mode.\n");
3141 vf
= &pf
->vf
[vf_id
];
3145 if (setting
== vf
->trusted
)
3148 vf
->trusted
= setting
;
3149 i40e_vc_notify_vf_reset(vf
);
3150 i40e_reset_vf(vf
, false);
3151 dev_info(&pf
->pdev
->dev
, "VF %u is now %strusted\n",
3152 vf_id
, setting
? "" : "un");