1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 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
+ 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_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
+ 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
+ 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 struct i40e_hw
*hw
= &pf
->hw
;
166 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
167 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
168 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
173 * i40e_vc_isvalid_vsi_id
174 * @vf: pointer to the VF info
175 * @vsi_id: VF relative VSI id
177 * check for the valid VSI id
179 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf
*vf
, u16 vsi_id
)
181 struct i40e_pf
*pf
= vf
->pf
;
182 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
184 return (vsi
&& (vsi
->vf_id
== vf
->vf_id
));
188 * i40e_vc_isvalid_queue_id
189 * @vf: pointer to the VF info
191 * @qid: vsi relative queue id
193 * check for the valid queue id
195 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
198 struct i40e_pf
*pf
= vf
->pf
;
199 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
201 return (vsi
&& (qid
< vsi
->alloc_queue_pairs
));
205 * i40e_vc_isvalid_vector_id
206 * @vf: pointer to the VF info
207 * @vector_id: VF relative vector id
209 * check for the valid vector id
211 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf
*vf
, u8 vector_id
)
213 struct i40e_pf
*pf
= vf
->pf
;
215 return vector_id
< pf
->hw
.func_caps
.num_msix_vectors_vf
;
218 /***********************vf resource mgmt routines*****************/
221 * i40e_vc_get_pf_queue_id
222 * @vf: pointer to the VF info
223 * @vsi_id: id of VSI as provided by the FW
224 * @vsi_queue_id: vsi relative queue id
226 * return PF relative queue id
228 static u16
i40e_vc_get_pf_queue_id(struct i40e_vf
*vf
, u16 vsi_id
,
231 struct i40e_pf
*pf
= vf
->pf
;
232 struct i40e_vsi
*vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
233 u16 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
238 if (le16_to_cpu(vsi
->info
.mapping_flags
) &
239 I40E_AQ_VSI_QUE_MAP_NONCONTIG
)
241 le16_to_cpu(vsi
->info
.queue_mapping
[vsi_queue_id
]);
243 pf_queue_id
= le16_to_cpu(vsi
->info
.queue_mapping
[0]) +
250 * i40e_config_irq_link_list
251 * @vf: pointer to the VF info
252 * @vsi_id: id of VSI as given by the FW
253 * @vecmap: irq map info
255 * configure irq link list from the map
257 static void i40e_config_irq_link_list(struct i40e_vf
*vf
, u16 vsi_id
,
258 struct i40e_virtchnl_vector_map
*vecmap
)
260 unsigned long linklistmap
= 0, tempmap
;
261 struct i40e_pf
*pf
= vf
->pf
;
262 struct i40e_hw
*hw
= &pf
->hw
;
263 u16 vsi_queue_id
, pf_queue_id
;
264 enum i40e_queue_type qtype
;
265 u16 next_q
, vector_id
;
269 vector_id
= vecmap
->vector_id
;
272 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
274 reg_idx
= I40E_VPINT_LNKLSTN(
275 ((pf
->hw
.func_caps
.num_msix_vectors_vf
- 1) * vf
->vf_id
) +
278 if (vecmap
->rxq_map
== 0 && vecmap
->txq_map
== 0) {
279 /* Special case - No queues mapped on this vector */
280 wr32(hw
, reg_idx
, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK
);
283 tempmap
= vecmap
->rxq_map
;
284 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
286 (I40E_VIRTCHNL_SUPPORTED_QTYPES
*
290 tempmap
= vecmap
->txq_map
;
291 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
293 (I40E_VIRTCHNL_SUPPORTED_QTYPES
* vsi_queue_id
297 next_q
= find_first_bit(&linklistmap
,
299 I40E_VIRTCHNL_SUPPORTED_QTYPES
));
300 vsi_queue_id
= next_q
/I40E_VIRTCHNL_SUPPORTED_QTYPES
;
301 qtype
= next_q
%I40E_VIRTCHNL_SUPPORTED_QTYPES
;
302 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
303 reg
= ((qtype
<< I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
) | pf_queue_id
);
305 wr32(hw
, reg_idx
, reg
);
307 while (next_q
< (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
309 case I40E_QUEUE_TYPE_RX
:
310 reg_idx
= I40E_QINT_RQCTL(pf_queue_id
);
311 itr_idx
= vecmap
->rxitr_idx
;
313 case I40E_QUEUE_TYPE_TX
:
314 reg_idx
= I40E_QINT_TQCTL(pf_queue_id
);
315 itr_idx
= vecmap
->txitr_idx
;
321 next_q
= find_next_bit(&linklistmap
,
323 I40E_VIRTCHNL_SUPPORTED_QTYPES
),
326 (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
327 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
328 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
329 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
,
332 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
336 /* format for the RQCTL & TQCTL regs is same */
338 (qtype
<< I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
) |
339 (pf_queue_id
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
340 (1 << I40E_QINT_RQCTL_CAUSE_ENA_SHIFT
) |
341 (itr_idx
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
);
342 wr32(hw
, reg_idx
, reg
);
350 * i40e_config_vsi_tx_queue
351 * @vf: pointer to the VF info
352 * @vsi_id: id of VSI as provided by the FW
353 * @vsi_queue_id: vsi relative queue index
354 * @info: config. info
358 static int i40e_config_vsi_tx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
360 struct i40e_virtchnl_txq_info
*info
)
362 struct i40e_pf
*pf
= vf
->pf
;
363 struct i40e_hw
*hw
= &pf
->hw
;
364 struct i40e_hmc_obj_txq tx_ctx
;
365 struct i40e_vsi
*vsi
;
370 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
371 vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
373 /* clear the context structure first */
374 memset(&tx_ctx
, 0, sizeof(struct i40e_hmc_obj_txq
));
376 /* only set the required fields */
377 tx_ctx
.base
= info
->dma_ring_addr
/ 128;
378 tx_ctx
.qlen
= info
->ring_len
;
379 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[0]);
380 tx_ctx
.rdylist_act
= 0;
381 tx_ctx
.head_wb_ena
= info
->headwb_enabled
;
382 tx_ctx
.head_wb_addr
= info
->dma_headwb_addr
;
384 /* clear the context in the HMC */
385 ret
= i40e_clear_lan_tx_queue_context(hw
, pf_queue_id
);
387 dev_err(&pf
->pdev
->dev
,
388 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
394 /* set the context in the HMC */
395 ret
= i40e_set_lan_tx_queue_context(hw
, pf_queue_id
, &tx_ctx
);
397 dev_err(&pf
->pdev
->dev
,
398 "Failed to set VF LAN Tx queue context %d error: %d\n",
404 /* associate this queue with the PCI VF function */
405 qtx_ctl
= I40E_QTX_CTL_VF_QUEUE
;
406 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
)
407 & I40E_QTX_CTL_PF_INDX_MASK
);
408 qtx_ctl
|= (((vf
->vf_id
+ hw
->func_caps
.vf_base_id
)
409 << I40E_QTX_CTL_VFVM_INDX_SHIFT
)
410 & I40E_QTX_CTL_VFVM_INDX_MASK
);
411 wr32(hw
, I40E_QTX_CTL(pf_queue_id
), qtx_ctl
);
419 * i40e_config_vsi_rx_queue
420 * @vf: pointer to the VF info
421 * @vsi_id: id of VSI as provided by the FW
422 * @vsi_queue_id: vsi relative queue index
423 * @info: config. info
427 static int i40e_config_vsi_rx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
429 struct i40e_virtchnl_rxq_info
*info
)
431 struct i40e_pf
*pf
= vf
->pf
;
432 struct i40e_hw
*hw
= &pf
->hw
;
433 struct i40e_hmc_obj_rxq rx_ctx
;
437 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
439 /* clear the context structure first */
440 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
442 /* only set the required fields */
443 rx_ctx
.base
= info
->dma_ring_addr
/ 128;
444 rx_ctx
.qlen
= info
->ring_len
;
446 if (info
->splithdr_enabled
) {
447 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
449 I40E_RX_SPLIT_TCP_UDP
|
451 /* header length validation */
452 if (info
->hdr_size
> ((2 * 1024) - 64)) {
456 rx_ctx
.hbuff
= info
->hdr_size
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
458 /* set splitalways mode 10b */
462 /* databuffer length validation */
463 if (info
->databuffer_size
> ((16 * 1024) - 128)) {
467 rx_ctx
.dbuff
= info
->databuffer_size
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
469 /* max pkt. length validation */
470 if (info
->max_pkt_size
>= (16 * 1024) || info
->max_pkt_size
< 64) {
474 rx_ctx
.rxmax
= info
->max_pkt_size
;
476 /* enable 32bytes desc always */
480 rx_ctx
.lrxqthresh
= 2;
485 /* clear the context in the HMC */
486 ret
= i40e_clear_lan_rx_queue_context(hw
, pf_queue_id
);
488 dev_err(&pf
->pdev
->dev
,
489 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
495 /* set the context in the HMC */
496 ret
= i40e_set_lan_rx_queue_context(hw
, pf_queue_id
, &rx_ctx
);
498 dev_err(&pf
->pdev
->dev
,
499 "Failed to set VF LAN Rx queue context %d error: %d\n",
511 * @vf: pointer to the VF info
512 * @type: type of VSI to allocate
514 * alloc VF vsi context & resources
516 static int i40e_alloc_vsi_res(struct i40e_vf
*vf
, enum i40e_vsi_type type
)
518 struct i40e_mac_filter
*f
= NULL
;
519 struct i40e_pf
*pf
= vf
->pf
;
520 struct i40e_vsi
*vsi
;
523 vsi
= i40e_vsi_setup(pf
, type
, pf
->vsi
[pf
->lan_vsi
]->seid
, vf
->vf_id
);
526 dev_err(&pf
->pdev
->dev
,
527 "add vsi failed for VF %d, aq_err %d\n",
528 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
530 goto error_alloc_vsi_res
;
532 if (type
== I40E_VSI_SRIOV
) {
533 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
534 vf
->lan_vsi_idx
= vsi
->idx
;
535 vf
->lan_vsi_id
= vsi
->id
;
536 /* If the port VLAN has been configured and then the
537 * VF driver was removed then the VSI port VLAN
538 * configuration was destroyed. Check if there is
539 * a port VLAN and restore the VSI configuration if
542 if (vf
->port_vlan_id
)
543 i40e_vsi_add_pvid(vsi
, vf
->port_vlan_id
);
544 f
= i40e_add_filter(vsi
, vf
->default_lan_addr
.addr
,
545 vf
->port_vlan_id
, true, false);
547 dev_info(&pf
->pdev
->dev
,
548 "Could not allocate VF MAC addr\n");
549 f
= i40e_add_filter(vsi
, brdcast
, vf
->port_vlan_id
,
552 dev_info(&pf
->pdev
->dev
,
553 "Could not allocate VF broadcast filter\n");
556 /* program mac filter */
557 ret
= i40e_sync_vsi_filters(vsi
);
559 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
561 /* Set VF bandwidth if specified */
563 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
564 vf
->tx_rate
/ 50, 0, NULL
);
566 dev_err(&pf
->pdev
->dev
, "Unable to set tx rate, VF %d, error code %d.\n",
575 * i40e_enable_vf_mappings
576 * @vf: pointer to the VF info
580 static void i40e_enable_vf_mappings(struct i40e_vf
*vf
)
582 struct i40e_pf
*pf
= vf
->pf
;
583 struct i40e_hw
*hw
= &pf
->hw
;
584 u32 reg
, total_queue_pairs
= 0;
587 /* Tell the hardware we're using noncontiguous mapping. HW requires
588 * that VF queues be mapped using this method, even when they are
589 * contiguous in real life
591 wr32(hw
, I40E_VSILAN_QBASE(vf
->lan_vsi_id
),
592 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK
);
594 /* enable VF vplan_qtable mappings */
595 reg
= I40E_VPLAN_MAPENA_TXRX_ENA_MASK
;
596 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), reg
);
598 /* map PF queues to VF queues */
599 for (j
= 0; j
< pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
; j
++) {
600 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
, j
);
601 reg
= (qid
& I40E_VPLAN_QTABLE_QINDEX_MASK
);
602 wr32(hw
, I40E_VPLAN_QTABLE(total_queue_pairs
, vf
->vf_id
), reg
);
606 /* map PF queues to VSI */
607 for (j
= 0; j
< 7; j
++) {
608 if (j
* 2 >= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
) {
609 reg
= 0x07FF07FF; /* unused */
611 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
614 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
618 wr32(hw
, I40E_VSILAN_QTABLE(j
, vf
->lan_vsi_id
), reg
);
625 * i40e_disable_vf_mappings
626 * @vf: pointer to the VF info
628 * disable VF mappings
630 static void i40e_disable_vf_mappings(struct i40e_vf
*vf
)
632 struct i40e_pf
*pf
= vf
->pf
;
633 struct i40e_hw
*hw
= &pf
->hw
;
636 /* disable qp mappings */
637 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), 0);
638 for (i
= 0; i
< I40E_MAX_VSI_QP
; i
++)
639 wr32(hw
, I40E_VPLAN_QTABLE(i
, vf
->vf_id
),
640 I40E_QUEUE_END_OF_LIST
);
646 * @vf: pointer to the VF info
650 static void i40e_free_vf_res(struct i40e_vf
*vf
)
652 struct i40e_pf
*pf
= vf
->pf
;
653 struct i40e_hw
*hw
= &pf
->hw
;
657 /* free vsi & disconnect it from the parent uplink */
658 if (vf
->lan_vsi_idx
) {
659 i40e_vsi_release(pf
->vsi
[vf
->lan_vsi_idx
]);
663 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
665 /* disable interrupts so the VF starts in a known state */
666 for (i
= 0; i
< msix_vf
; i
++) {
667 /* format is same for both registers */
669 reg_idx
= I40E_VFINT_DYN_CTL0(vf
->vf_id
);
671 reg_idx
= I40E_VFINT_DYN_CTLN(((msix_vf
- 1) *
674 wr32(hw
, reg_idx
, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
678 /* clear the irq settings */
679 for (i
= 0; i
< msix_vf
; i
++) {
680 /* format is same for both registers */
682 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
684 reg_idx
= I40E_VPINT_LNKLSTN(((msix_vf
- 1) *
687 reg
= (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
|
688 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
);
689 wr32(hw
, reg_idx
, reg
);
692 /* reset some of the state varibles keeping
693 * track of the resources
695 vf
->num_queue_pairs
= 0;
701 * @vf: pointer to the VF info
703 * allocate VF resources
705 static int i40e_alloc_vf_res(struct i40e_vf
*vf
)
707 struct i40e_pf
*pf
= vf
->pf
;
708 int total_queue_pairs
= 0;
711 /* allocate hw vsi context & associated resources */
712 ret
= i40e_alloc_vsi_res(vf
, I40E_VSI_SRIOV
);
715 total_queue_pairs
+= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
716 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
718 /* store the total qps number for the runtime
721 vf
->num_queue_pairs
= total_queue_pairs
;
723 /* VF is now completely initialized */
724 set_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
728 i40e_free_vf_res(vf
);
733 #define VF_DEVICE_STATUS 0xAA
734 #define VF_TRANS_PENDING_MASK 0x20
736 * i40e_quiesce_vf_pci
737 * @vf: pointer to the VF structure
739 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
740 * if the transactions never clear.
742 static int i40e_quiesce_vf_pci(struct i40e_vf
*vf
)
744 struct i40e_pf
*pf
= vf
->pf
;
745 struct i40e_hw
*hw
= &pf
->hw
;
749 vf_abs_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
751 wr32(hw
, I40E_PF_PCI_CIAA
,
752 VF_DEVICE_STATUS
| (vf_abs_id
<< I40E_PF_PCI_CIAA_VF_NUM_SHIFT
));
753 for (i
= 0; i
< 100; i
++) {
754 reg
= rd32(hw
, I40E_PF_PCI_CIAD
);
755 if ((reg
& VF_TRANS_PENDING_MASK
) == 0)
764 * @vf: pointer to the VF structure
765 * @flr: VFLR was issued or not
769 void i40e_reset_vf(struct i40e_vf
*vf
, bool flr
)
771 struct i40e_pf
*pf
= vf
->pf
;
772 struct i40e_hw
*hw
= &pf
->hw
;
777 if (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
781 clear_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
783 /* In the case of a VFLR, the HW has already reset the VF and we
784 * just need to clean up, so don't hit the VFRTRIG register.
787 /* reset VF using VPGEN_VFRTRIG reg */
788 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
789 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
790 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
794 if (i40e_quiesce_vf_pci(vf
))
795 dev_err(&pf
->pdev
->dev
, "VF %d PCI transactions stuck\n",
798 /* poll VPGEN_VFRSTAT reg to make sure
799 * that reset is complete
801 for (i
= 0; i
< 10; i
++) {
802 /* VF reset requires driver to first reset the VF and then
803 * poll the status register to make sure that the reset
804 * completed successfully. Due to internal HW FIFO flushes,
805 * we must wait 10ms before the register will be valid.
807 usleep_range(10000, 20000);
808 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
809 if (reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
) {
816 usleep_range(10000, 20000);
819 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
821 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_COMPLETED
);
822 /* clear the reset bit in the VPGEN_VFRTRIG reg */
823 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
824 reg
&= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
825 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
827 /* On initial reset, we won't have any queues */
828 if (vf
->lan_vsi_idx
== 0)
831 i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false);
833 /* reallocate VF resources to reset the VSI state */
834 i40e_free_vf_res(vf
);
835 i40e_alloc_vf_res(vf
);
836 i40e_enable_vf_mappings(vf
);
837 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
839 /* tell the VF the reset is done */
840 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_VFACTIVE
);
842 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
847 * @pf: pointer to the PF structure
851 void i40e_free_vfs(struct i40e_pf
*pf
)
853 struct i40e_hw
*hw
= &pf
->hw
;
854 u32 reg_idx
, bit_idx
;
859 while (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
860 usleep_range(1000, 2000);
862 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
863 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
864 i40e_vsi_control_rings(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
],
867 /* Disable IOV before freeing resources. This lets any VF drivers
868 * running in the host get themselves cleaned up before we yank
869 * the carpet out from underneath their feet.
871 if (!pci_vfs_assigned(pf
->pdev
))
872 pci_disable_sriov(pf
->pdev
);
874 dev_warn(&pf
->pdev
->dev
, "VFs are assigned - not disabling SR-IOV\n");
876 msleep(20); /* let any messages in transit get finished up */
878 /* free up VF resources */
879 tmp
= pf
->num_alloc_vfs
;
880 pf
->num_alloc_vfs
= 0;
881 for (i
= 0; i
< tmp
; i
++) {
882 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
883 i40e_free_vf_res(&pf
->vf
[i
]);
884 /* disable qp mappings */
885 i40e_disable_vf_mappings(&pf
->vf
[i
]);
891 /* This check is for when the driver is unloaded while VFs are
892 * assigned. Setting the number of VFs to 0 through sysfs is caught
893 * before this function ever gets called.
895 if (!pci_vfs_assigned(pf
->pdev
)) {
896 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
897 * work correctly when SR-IOV gets re-enabled.
899 for (vf_id
= 0; vf_id
< tmp
; vf_id
++) {
900 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
901 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
902 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), (1 << bit_idx
));
905 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
908 #ifdef CONFIG_PCI_IOV
911 * @pf: pointer to the PF structure
912 * @num_alloc_vfs: number of VFs to allocate
914 * allocate VF resources
916 int i40e_alloc_vfs(struct i40e_pf
*pf
, u16 num_alloc_vfs
)
921 /* Disable interrupt 0 so we don't try to handle the VFLR. */
922 i40e_irq_dynamic_disable_icr0(pf
);
924 /* Check to see if we're just allocating resources for extant VFs */
925 if (pci_num_vf(pf
->pdev
) != num_alloc_vfs
) {
926 ret
= pci_enable_sriov(pf
->pdev
, num_alloc_vfs
);
928 dev_err(&pf
->pdev
->dev
,
929 "Failed to enable SR-IOV, error %d.\n", ret
);
930 pf
->num_alloc_vfs
= 0;
934 /* allocate memory */
935 vfs
= kcalloc(num_alloc_vfs
, sizeof(struct i40e_vf
), GFP_KERNEL
);
942 /* apply default profile */
943 for (i
= 0; i
< num_alloc_vfs
; i
++) {
945 vfs
[i
].parent_type
= I40E_SWITCH_ELEMENT_TYPE_VEB
;
948 /* assign default capabilities */
949 set_bit(I40E_VIRTCHNL_VF_CAP_L2
, &vfs
[i
].vf_caps
);
950 vfs
[i
].spoofchk
= true;
951 /* VF resources get allocated during reset */
952 i40e_reset_vf(&vfs
[i
], false);
954 /* enable VF vplan_qtable mappings */
955 i40e_enable_vf_mappings(&vfs
[i
]);
957 pf
->num_alloc_vfs
= num_alloc_vfs
;
963 /* Re-enable interrupt 0. */
964 i40e_irq_dynamic_enable_icr0(pf
);
970 * i40e_pci_sriov_enable
971 * @pdev: pointer to a pci_dev structure
972 * @num_vfs: number of VFs to allocate
974 * Enable or change the number of VFs
976 static int i40e_pci_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
978 #ifdef CONFIG_PCI_IOV
979 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
980 int pre_existing_vfs
= pci_num_vf(pdev
);
983 dev_info(&pdev
->dev
, "Allocating %d VFs.\n", num_vfs
);
984 if (pre_existing_vfs
&& pre_existing_vfs
!= num_vfs
)
986 else if (pre_existing_vfs
&& pre_existing_vfs
== num_vfs
)
989 if (num_vfs
> pf
->num_req_vfs
) {
994 err
= i40e_alloc_vfs(pf
, num_vfs
);
996 dev_warn(&pdev
->dev
, "Failed to enable SR-IOV: %d\n", err
);
1010 * i40e_pci_sriov_configure
1011 * @pdev: pointer to a pci_dev structure
1012 * @num_vfs: number of VFs to allocate
1014 * Enable or change the number of VFs. Called when the user updates the number
1017 int i40e_pci_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
1019 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1022 return i40e_pci_sriov_enable(pdev
, num_vfs
);
1024 if (!pci_vfs_assigned(pf
->pdev
)) {
1027 dev_warn(&pdev
->dev
, "Unable to free VFs because some are assigned to VMs.\n");
1033 /***********************virtual channel routines******************/
1036 * i40e_vc_send_msg_to_vf
1037 * @vf: pointer to the VF info
1038 * @v_opcode: virtual channel opcode
1039 * @v_retval: virtual channel return value
1040 * @msg: pointer to the msg buffer
1041 * @msglen: msg length
1045 static int i40e_vc_send_msg_to_vf(struct i40e_vf
*vf
, u32 v_opcode
,
1046 u32 v_retval
, u8
*msg
, u16 msglen
)
1053 /* validate the request */
1054 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
1059 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1061 /* single place to detect unsuccessful return values */
1063 vf
->num_invalid_msgs
++;
1064 dev_err(&pf
->pdev
->dev
, "Failed opcode %d Error: %d\n",
1065 v_opcode
, v_retval
);
1066 if (vf
->num_invalid_msgs
>
1067 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED
) {
1068 dev_err(&pf
->pdev
->dev
,
1069 "Number of invalid messages exceeded for VF %d\n",
1071 dev_err(&pf
->pdev
->dev
, "Use PF Control I/F to enable the VF\n");
1072 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
1075 vf
->num_valid_msgs
++;
1078 aq_ret
= i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
1081 dev_err(&pf
->pdev
->dev
,
1082 "Unable to send the message to VF %d aq_err %d\n",
1083 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
1091 * i40e_vc_send_resp_to_vf
1092 * @vf: pointer to the VF info
1093 * @opcode: operation code
1094 * @retval: return value
1096 * send resp msg to VF
1098 static int i40e_vc_send_resp_to_vf(struct i40e_vf
*vf
,
1099 enum i40e_virtchnl_ops opcode
,
1102 return i40e_vc_send_msg_to_vf(vf
, opcode
, retval
, NULL
, 0);
1106 * i40e_vc_get_version_msg
1107 * @vf: pointer to the VF info
1109 * called from the VF to request the API version used by the PF
1111 static int i40e_vc_get_version_msg(struct i40e_vf
*vf
)
1113 struct i40e_virtchnl_version_info info
= {
1114 I40E_VIRTCHNL_VERSION_MAJOR
, I40E_VIRTCHNL_VERSION_MINOR
1117 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_VERSION
,
1118 I40E_SUCCESS
, (u8
*)&info
,
1120 i40e_virtchnl_version_info
));
1124 * i40e_vc_get_vf_resources_msg
1125 * @vf: pointer to the VF info
1126 * @msg: pointer to the msg buffer
1127 * @msglen: msg length
1129 * called from the VF to request its resources
1131 static int i40e_vc_get_vf_resources_msg(struct i40e_vf
*vf
)
1133 struct i40e_virtchnl_vf_resource
*vfres
= NULL
;
1134 struct i40e_pf
*pf
= vf
->pf
;
1135 i40e_status aq_ret
= 0;
1136 struct i40e_vsi
*vsi
;
1141 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
1142 aq_ret
= I40E_ERR_PARAM
;
1146 len
= (sizeof(struct i40e_virtchnl_vf_resource
) +
1147 sizeof(struct i40e_virtchnl_vsi_resource
) * num_vsis
);
1149 vfres
= kzalloc(len
, GFP_KERNEL
);
1151 aq_ret
= I40E_ERR_NO_MEMORY
;
1156 vfres
->vf_offload_flags
= I40E_VIRTCHNL_VF_OFFLOAD_L2
;
1157 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1158 if (!vsi
->info
.pvid
)
1159 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1161 vfres
->num_vsis
= num_vsis
;
1162 vfres
->num_queue_pairs
= vf
->num_queue_pairs
;
1163 vfres
->max_vectors
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
1164 if (vf
->lan_vsi_idx
) {
1165 vfres
->vsi_res
[i
].vsi_id
= vf
->lan_vsi_id
;
1166 vfres
->vsi_res
[i
].vsi_type
= I40E_VSI_SRIOV
;
1167 vfres
->vsi_res
[i
].num_queue_pairs
=
1168 pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
1169 memcpy(vfres
->vsi_res
[i
].default_mac_addr
,
1170 vf
->default_lan_addr
.addr
, ETH_ALEN
);
1173 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
1176 /* send the response back to the VF */
1177 ret
= i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
1178 aq_ret
, (u8
*)vfres
, len
);
1185 * i40e_vc_reset_vf_msg
1186 * @vf: pointer to the VF info
1187 * @msg: pointer to the msg buffer
1188 * @msglen: msg length
1190 * called from the VF to reset itself,
1191 * unlike other virtchnl messages, PF driver
1192 * doesn't send the response back to the VF
1194 static void i40e_vc_reset_vf_msg(struct i40e_vf
*vf
)
1196 if (test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
1197 i40e_reset_vf(vf
, false);
1201 * i40e_vc_config_promiscuous_mode_msg
1202 * @vf: pointer to the VF info
1203 * @msg: pointer to the msg buffer
1204 * @msglen: msg length
1206 * called from the VF to configure the promiscuous mode of
1209 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf
*vf
,
1210 u8
*msg
, u16 msglen
)
1212 struct i40e_virtchnl_promisc_info
*info
=
1213 (struct i40e_virtchnl_promisc_info
*)msg
;
1214 struct i40e_pf
*pf
= vf
->pf
;
1215 struct i40e_hw
*hw
= &pf
->hw
;
1216 struct i40e_vsi
*vsi
;
1217 bool allmulti
= false;
1220 vsi
= i40e_find_vsi_from_id(pf
, info
->vsi_id
);
1221 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1222 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1223 !i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
) ||
1224 (vsi
->type
!= I40E_VSI_FCOE
)) {
1225 aq_ret
= I40E_ERR_PARAM
;
1228 if (info
->flags
& I40E_FLAG_VF_MULTICAST_PROMISC
)
1230 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(hw
, vsi
->seid
,
1234 /* send the response to the VF */
1235 return i40e_vc_send_resp_to_vf(vf
,
1236 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
1241 * i40e_vc_config_queues_msg
1242 * @vf: pointer to the VF info
1243 * @msg: pointer to the msg buffer
1244 * @msglen: msg length
1246 * called from the VF to configure the rx/tx
1249 static int i40e_vc_config_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1251 struct i40e_virtchnl_vsi_queue_config_info
*qci
=
1252 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1253 struct i40e_virtchnl_queue_pair_info
*qpi
;
1254 struct i40e_pf
*pf
= vf
->pf
;
1255 u16 vsi_id
, vsi_queue_id
;
1256 i40e_status aq_ret
= 0;
1259 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1260 aq_ret
= I40E_ERR_PARAM
;
1264 vsi_id
= qci
->vsi_id
;
1265 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1266 aq_ret
= I40E_ERR_PARAM
;
1269 for (i
= 0; i
< qci
->num_queue_pairs
; i
++) {
1270 qpi
= &qci
->qpair
[i
];
1271 vsi_queue_id
= qpi
->txq
.queue_id
;
1272 if ((qpi
->txq
.vsi_id
!= vsi_id
) ||
1273 (qpi
->rxq
.vsi_id
!= vsi_id
) ||
1274 (qpi
->rxq
.queue_id
!= vsi_queue_id
) ||
1275 !i40e_vc_isvalid_queue_id(vf
, vsi_id
, vsi_queue_id
)) {
1276 aq_ret
= I40E_ERR_PARAM
;
1280 if (i40e_config_vsi_rx_queue(vf
, vsi_id
, vsi_queue_id
,
1282 i40e_config_vsi_tx_queue(vf
, vsi_id
, vsi_queue_id
,
1284 aq_ret
= I40E_ERR_PARAM
;
1288 /* set vsi num_queue_pairs in use to num configured by VF */
1289 pf
->vsi
[vf
->lan_vsi_idx
]->num_queue_pairs
= qci
->num_queue_pairs
;
1292 /* send the response to the VF */
1293 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
1298 * i40e_vc_config_irq_map_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 configure the irq to
1306 static int i40e_vc_config_irq_map_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1308 struct i40e_virtchnl_irq_map_info
*irqmap_info
=
1309 (struct i40e_virtchnl_irq_map_info
*)msg
;
1310 struct i40e_virtchnl_vector_map
*map
;
1311 u16 vsi_id
, vsi_queue_id
, vector_id
;
1312 i40e_status aq_ret
= 0;
1313 unsigned long tempmap
;
1316 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1317 aq_ret
= I40E_ERR_PARAM
;
1321 for (i
= 0; i
< irqmap_info
->num_vectors
; i
++) {
1322 map
= &irqmap_info
->vecmap
[i
];
1324 vector_id
= map
->vector_id
;
1325 vsi_id
= map
->vsi_id
;
1326 /* validate msg params */
1327 if (!i40e_vc_isvalid_vector_id(vf
, vector_id
) ||
1328 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1329 aq_ret
= I40E_ERR_PARAM
;
1333 /* lookout for the invalid queue index */
1334 tempmap
= map
->rxq_map
;
1335 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1336 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1338 aq_ret
= I40E_ERR_PARAM
;
1343 tempmap
= map
->txq_map
;
1344 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1345 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1347 aq_ret
= I40E_ERR_PARAM
;
1352 i40e_config_irq_link_list(vf
, vsi_id
, map
);
1355 /* send the response to the VF */
1356 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
1361 * i40e_vc_enable_queues_msg
1362 * @vf: pointer to the VF info
1363 * @msg: pointer to the msg buffer
1364 * @msglen: msg length
1366 * called from the VF to enable all or specific queue(s)
1368 static int i40e_vc_enable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1370 struct i40e_virtchnl_queue_select
*vqs
=
1371 (struct i40e_virtchnl_queue_select
*)msg
;
1372 struct i40e_pf
*pf
= vf
->pf
;
1373 u16 vsi_id
= vqs
->vsi_id
;
1374 i40e_status aq_ret
= 0;
1376 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1377 aq_ret
= I40E_ERR_PARAM
;
1381 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1382 aq_ret
= I40E_ERR_PARAM
;
1386 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1387 aq_ret
= I40E_ERR_PARAM
;
1391 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], true))
1392 aq_ret
= I40E_ERR_TIMEOUT
;
1394 /* send the response to the VF */
1395 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
1400 * i40e_vc_disable_queues_msg
1401 * @vf: pointer to the VF info
1402 * @msg: pointer to the msg buffer
1403 * @msglen: msg length
1405 * called from the VF to disable all or specific
1408 static int i40e_vc_disable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1410 struct i40e_virtchnl_queue_select
*vqs
=
1411 (struct i40e_virtchnl_queue_select
*)msg
;
1412 struct i40e_pf
*pf
= vf
->pf
;
1413 i40e_status aq_ret
= 0;
1415 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1416 aq_ret
= I40E_ERR_PARAM
;
1420 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1421 aq_ret
= I40E_ERR_PARAM
;
1425 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1426 aq_ret
= I40E_ERR_PARAM
;
1430 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false))
1431 aq_ret
= I40E_ERR_TIMEOUT
;
1434 /* send the response to the VF */
1435 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
1440 * i40e_vc_get_stats_msg
1441 * @vf: pointer to the VF info
1442 * @msg: pointer to the msg buffer
1443 * @msglen: msg length
1445 * called from the VF to get vsi stats
1447 static int i40e_vc_get_stats_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1449 struct i40e_virtchnl_queue_select
*vqs
=
1450 (struct i40e_virtchnl_queue_select
*)msg
;
1451 struct i40e_pf
*pf
= vf
->pf
;
1452 struct i40e_eth_stats stats
;
1453 i40e_status aq_ret
= 0;
1454 struct i40e_vsi
*vsi
;
1456 memset(&stats
, 0, sizeof(struct i40e_eth_stats
));
1458 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1459 aq_ret
= I40E_ERR_PARAM
;
1463 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1464 aq_ret
= I40E_ERR_PARAM
;
1468 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1470 aq_ret
= I40E_ERR_PARAM
;
1473 i40e_update_eth_stats(vsi
);
1474 stats
= vsi
->eth_stats
;
1477 /* send the response back to the VF */
1478 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_STATS
, aq_ret
,
1479 (u8
*)&stats
, sizeof(stats
));
1483 * i40e_check_vf_permission
1484 * @vf: pointer to the VF info
1485 * @macaddr: pointer to the MAC Address being checked
1487 * Check if the VF has permission to add or delete unicast MAC address
1488 * filters and return error code -EPERM if not. Then check if the
1489 * address filter requested is broadcast or zero and if so return
1490 * an invalid MAC address error code.
1492 static inline int i40e_check_vf_permission(struct i40e_vf
*vf
, u8
*macaddr
)
1494 struct i40e_pf
*pf
= vf
->pf
;
1497 if (is_broadcast_ether_addr(macaddr
) ||
1498 is_zero_ether_addr(macaddr
)) {
1499 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n", macaddr
);
1500 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1501 } else if (vf
->pf_set_mac
&& !is_multicast_ether_addr(macaddr
) &&
1502 !ether_addr_equal(macaddr
, vf
->default_lan_addr
.addr
)) {
1503 /* If the host VMM administrator has set the VF MAC address
1504 * administratively via the ndo_set_vf_mac command then deny
1505 * permission to the VF to add or delete unicast MAC addresses.
1506 * The VF may request to set the MAC address filter already
1507 * assigned to it so do not return an error in that case.
1509 dev_err(&pf
->pdev
->dev
,
1510 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1517 * i40e_vc_add_mac_addr_msg
1518 * @vf: pointer to the VF info
1519 * @msg: pointer to the msg buffer
1520 * @msglen: msg length
1522 * add guest mac address filter
1524 static int i40e_vc_add_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1526 struct i40e_virtchnl_ether_addr_list
*al
=
1527 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1528 struct i40e_pf
*pf
= vf
->pf
;
1529 struct i40e_vsi
*vsi
= NULL
;
1530 u16 vsi_id
= al
->vsi_id
;
1531 i40e_status ret
= 0;
1534 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1535 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1536 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1537 ret
= I40E_ERR_PARAM
;
1541 for (i
= 0; i
< al
->num_elements
; i
++) {
1542 ret
= i40e_check_vf_permission(vf
, al
->list
[i
].addr
);
1546 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1548 /* add new addresses to the list */
1549 for (i
= 0; i
< al
->num_elements
; i
++) {
1550 struct i40e_mac_filter
*f
;
1552 f
= i40e_find_mac(vsi
, al
->list
[i
].addr
, true, false);
1554 if (i40e_is_vsi_in_vlan(vsi
))
1555 f
= i40e_put_mac_in_vlan(vsi
, al
->list
[i
].addr
,
1558 f
= i40e_add_filter(vsi
, al
->list
[i
].addr
, -1,
1563 dev_err(&pf
->pdev
->dev
,
1564 "Unable to add VF MAC filter\n");
1565 ret
= I40E_ERR_PARAM
;
1570 /* program the updated filter list */
1571 if (i40e_sync_vsi_filters(vsi
))
1572 dev_err(&pf
->pdev
->dev
, "Unable to program VF MAC filters\n");
1575 /* send the response to the VF */
1576 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
1581 * i40e_vc_del_mac_addr_msg
1582 * @vf: pointer to the VF info
1583 * @msg: pointer to the msg buffer
1584 * @msglen: msg length
1586 * remove guest mac address filter
1588 static int i40e_vc_del_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1590 struct i40e_virtchnl_ether_addr_list
*al
=
1591 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1592 struct i40e_pf
*pf
= vf
->pf
;
1593 struct i40e_vsi
*vsi
= NULL
;
1594 u16 vsi_id
= al
->vsi_id
;
1595 i40e_status ret
= 0;
1598 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1599 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1600 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1601 ret
= I40E_ERR_PARAM
;
1605 for (i
= 0; i
< al
->num_elements
; i
++) {
1606 if (is_broadcast_ether_addr(al
->list
[i
].addr
) ||
1607 is_zero_ether_addr(al
->list
[i
].addr
)) {
1608 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n",
1610 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1614 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1616 /* delete addresses from the list */
1617 for (i
= 0; i
< al
->num_elements
; i
++)
1618 i40e_del_filter(vsi
, al
->list
[i
].addr
,
1619 I40E_VLAN_ANY
, true, false);
1621 /* program the updated filter list */
1622 if (i40e_sync_vsi_filters(vsi
))
1623 dev_err(&pf
->pdev
->dev
, "Unable to program VF MAC filters\n");
1626 /* send the response to the VF */
1627 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
1632 * i40e_vc_add_vlan_msg
1633 * @vf: pointer to the VF info
1634 * @msg: pointer to the msg buffer
1635 * @msglen: msg length
1637 * program guest vlan id
1639 static int i40e_vc_add_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1641 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1642 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1643 struct i40e_pf
*pf
= vf
->pf
;
1644 struct i40e_vsi
*vsi
= NULL
;
1645 u16 vsi_id
= vfl
->vsi_id
;
1646 i40e_status aq_ret
= 0;
1649 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1650 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1651 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1652 aq_ret
= I40E_ERR_PARAM
;
1656 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1657 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1658 aq_ret
= I40E_ERR_PARAM
;
1659 dev_err(&pf
->pdev
->dev
,
1660 "invalid VF VLAN id %d\n", vfl
->vlan_id
[i
]);
1664 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1665 if (vsi
->info
.pvid
) {
1666 aq_ret
= I40E_ERR_PARAM
;
1670 i40e_vlan_stripping_enable(vsi
);
1671 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1672 /* add new VLAN filter */
1673 int ret
= i40e_vsi_add_vlan(vsi
, vfl
->vlan_id
[i
]);
1675 dev_err(&pf
->pdev
->dev
,
1676 "Unable to add VF vlan filter %d, error %d\n",
1677 vfl
->vlan_id
[i
], ret
);
1681 /* send the response to the VF */
1682 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_VLAN
, aq_ret
);
1686 * i40e_vc_remove_vlan_msg
1687 * @vf: pointer to the VF info
1688 * @msg: pointer to the msg buffer
1689 * @msglen: msg length
1691 * remove programmed guest vlan id
1693 static int i40e_vc_remove_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1695 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1696 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1697 struct i40e_pf
*pf
= vf
->pf
;
1698 struct i40e_vsi
*vsi
= NULL
;
1699 u16 vsi_id
= vfl
->vsi_id
;
1700 i40e_status aq_ret
= 0;
1703 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1704 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1705 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1706 aq_ret
= I40E_ERR_PARAM
;
1710 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1711 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1712 aq_ret
= I40E_ERR_PARAM
;
1717 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1718 if (vsi
->info
.pvid
) {
1719 aq_ret
= I40E_ERR_PARAM
;
1723 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1724 int ret
= i40e_vsi_kill_vlan(vsi
, vfl
->vlan_id
[i
]);
1726 dev_err(&pf
->pdev
->dev
,
1727 "Unable to delete VF vlan filter %d, error %d\n",
1728 vfl
->vlan_id
[i
], ret
);
1732 /* send the response to the VF */
1733 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_VLAN
, aq_ret
);
1737 * i40e_vc_validate_vf_msg
1738 * @vf: pointer to the VF info
1739 * @msg: pointer to the msg buffer
1740 * @msglen: msg length
1741 * @msghndl: msg handle
1745 static int i40e_vc_validate_vf_msg(struct i40e_vf
*vf
, u32 v_opcode
,
1746 u32 v_retval
, u8
*msg
, u16 msglen
)
1748 bool err_msg_format
= false;
1751 /* Check if VF is disabled. */
1752 if (test_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
))
1753 return I40E_ERR_PARAM
;
1755 /* Validate message length. */
1757 case I40E_VIRTCHNL_OP_VERSION
:
1758 valid_len
= sizeof(struct i40e_virtchnl_version_info
);
1760 case I40E_VIRTCHNL_OP_RESET_VF
:
1761 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1764 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE
:
1765 valid_len
= sizeof(struct i40e_virtchnl_txq_info
);
1767 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE
:
1768 valid_len
= sizeof(struct i40e_virtchnl_rxq_info
);
1770 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1771 valid_len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
);
1772 if (msglen
>= valid_len
) {
1773 struct i40e_virtchnl_vsi_queue_config_info
*vqc
=
1774 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1775 valid_len
+= (vqc
->num_queue_pairs
*
1777 i40e_virtchnl_queue_pair_info
));
1778 if (vqc
->num_queue_pairs
== 0)
1779 err_msg_format
= true;
1782 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1783 valid_len
= sizeof(struct i40e_virtchnl_irq_map_info
);
1784 if (msglen
>= valid_len
) {
1785 struct i40e_virtchnl_irq_map_info
*vimi
=
1786 (struct i40e_virtchnl_irq_map_info
*)msg
;
1787 valid_len
+= (vimi
->num_vectors
*
1788 sizeof(struct i40e_virtchnl_vector_map
));
1789 if (vimi
->num_vectors
== 0)
1790 err_msg_format
= true;
1793 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1794 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1795 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1797 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1798 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1799 valid_len
= sizeof(struct i40e_virtchnl_ether_addr_list
);
1800 if (msglen
>= valid_len
) {
1801 struct i40e_virtchnl_ether_addr_list
*veal
=
1802 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1803 valid_len
+= veal
->num_elements
*
1804 sizeof(struct i40e_virtchnl_ether_addr
);
1805 if (veal
->num_elements
== 0)
1806 err_msg_format
= true;
1809 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1810 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1811 valid_len
= sizeof(struct i40e_virtchnl_vlan_filter_list
);
1812 if (msglen
>= valid_len
) {
1813 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1814 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1815 valid_len
+= vfl
->num_elements
* sizeof(u16
);
1816 if (vfl
->num_elements
== 0)
1817 err_msg_format
= true;
1820 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1821 valid_len
= sizeof(struct i40e_virtchnl_promisc_info
);
1823 case I40E_VIRTCHNL_OP_GET_STATS
:
1824 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1826 /* These are always errors coming from the VF. */
1827 case I40E_VIRTCHNL_OP_EVENT
:
1828 case I40E_VIRTCHNL_OP_UNKNOWN
:
1833 /* few more checks */
1834 if ((valid_len
!= msglen
) || (err_msg_format
)) {
1835 i40e_vc_send_resp_to_vf(vf
, v_opcode
, I40E_ERR_PARAM
);
1843 * i40e_vc_process_vf_msg
1844 * @pf: pointer to the PF structure
1845 * @vf_id: source VF id
1846 * @msg: pointer to the msg buffer
1847 * @msglen: msg length
1848 * @msghndl: msg handle
1850 * called from the common aeq/arq handler to
1851 * process request from VF
1853 int i40e_vc_process_vf_msg(struct i40e_pf
*pf
, u16 vf_id
, u32 v_opcode
,
1854 u32 v_retval
, u8
*msg
, u16 msglen
)
1856 struct i40e_hw
*hw
= &pf
->hw
;
1857 unsigned int local_vf_id
= vf_id
- hw
->func_caps
.vf_base_id
;
1861 pf
->vf_aq_requests
++;
1862 if (local_vf_id
>= pf
->num_alloc_vfs
)
1864 vf
= &(pf
->vf
[local_vf_id
]);
1865 /* perform basic checks on the msg */
1866 ret
= i40e_vc_validate_vf_msg(vf
, v_opcode
, v_retval
, msg
, msglen
);
1869 dev_err(&pf
->pdev
->dev
, "Invalid message from VF %d, opcode %d, len %d\n",
1870 local_vf_id
, v_opcode
, msglen
);
1875 case I40E_VIRTCHNL_OP_VERSION
:
1876 ret
= i40e_vc_get_version_msg(vf
);
1878 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1879 ret
= i40e_vc_get_vf_resources_msg(vf
);
1881 case I40E_VIRTCHNL_OP_RESET_VF
:
1882 i40e_vc_reset_vf_msg(vf
);
1885 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1886 ret
= i40e_vc_config_promiscuous_mode_msg(vf
, msg
, msglen
);
1888 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1889 ret
= i40e_vc_config_queues_msg(vf
, msg
, msglen
);
1891 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1892 ret
= i40e_vc_config_irq_map_msg(vf
, msg
, msglen
);
1894 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1895 ret
= i40e_vc_enable_queues_msg(vf
, msg
, msglen
);
1896 i40e_vc_notify_vf_link_state(vf
);
1898 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1899 ret
= i40e_vc_disable_queues_msg(vf
, msg
, msglen
);
1901 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1902 ret
= i40e_vc_add_mac_addr_msg(vf
, msg
, msglen
);
1904 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1905 ret
= i40e_vc_del_mac_addr_msg(vf
, msg
, msglen
);
1907 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1908 ret
= i40e_vc_add_vlan_msg(vf
, msg
, msglen
);
1910 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1911 ret
= i40e_vc_remove_vlan_msg(vf
, msg
, msglen
);
1913 case I40E_VIRTCHNL_OP_GET_STATS
:
1914 ret
= i40e_vc_get_stats_msg(vf
, msg
, msglen
);
1916 case I40E_VIRTCHNL_OP_UNKNOWN
:
1918 dev_err(&pf
->pdev
->dev
, "Unsupported opcode %d from VF %d\n",
1919 v_opcode
, local_vf_id
);
1920 ret
= i40e_vc_send_resp_to_vf(vf
, v_opcode
,
1921 I40E_ERR_NOT_IMPLEMENTED
);
1929 * i40e_vc_process_vflr_event
1930 * @pf: pointer to the PF structure
1932 * called from the vlfr irq handler to
1933 * free up VF resources and state variables
1935 int i40e_vc_process_vflr_event(struct i40e_pf
*pf
)
1937 u32 reg
, reg_idx
, bit_idx
, vf_id
;
1938 struct i40e_hw
*hw
= &pf
->hw
;
1941 if (!test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
1944 /* re-enable vflr interrupt cause */
1945 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
1946 reg
|= I40E_PFINT_ICR0_ENA_VFLR_MASK
;
1947 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
1950 clear_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
1951 for (vf_id
= 0; vf_id
< pf
->num_alloc_vfs
; vf_id
++) {
1952 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
1953 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
1954 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
1955 vf
= &pf
->vf
[vf_id
];
1956 reg
= rd32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
));
1957 if (reg
& (1 << bit_idx
)) {
1958 /* clear the bit in GLGEN_VFLRSTAT */
1959 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), (1 << bit_idx
));
1961 if (!test_bit(__I40E_DOWN
, &pf
->state
))
1962 i40e_reset_vf(vf
, true);
1970 * i40e_ndo_set_vf_mac
1971 * @netdev: network interface device structure
1972 * @vf_id: VF identifier
1975 * program VF mac address
1977 int i40e_ndo_set_vf_mac(struct net_device
*netdev
, int vf_id
, u8
*mac
)
1979 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1980 struct i40e_vsi
*vsi
= np
->vsi
;
1981 struct i40e_pf
*pf
= vsi
->back
;
1982 struct i40e_mac_filter
*f
;
1986 /* validate the request */
1987 if (vf_id
>= pf
->num_alloc_vfs
) {
1988 dev_err(&pf
->pdev
->dev
,
1989 "Invalid VF Identifier %d\n", vf_id
);
1994 vf
= &(pf
->vf
[vf_id
]);
1995 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1996 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
1997 dev_err(&pf
->pdev
->dev
,
1998 "Uninitialized VF %d\n", vf_id
);
2003 if (!is_valid_ether_addr(mac
)) {
2004 dev_err(&pf
->pdev
->dev
,
2005 "Invalid VF ethernet address\n");
2010 /* delete the temporary mac address */
2011 i40e_del_filter(vsi
, vf
->default_lan_addr
.addr
, vf
->port_vlan_id
,
2014 /* Delete all the filters for this VSI - we're going to kill it
2017 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2018 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
, true, false);
2020 dev_info(&pf
->pdev
->dev
, "Setting MAC %pM on VF %d\n", mac
, vf_id
);
2021 /* program mac filter */
2022 if (i40e_sync_vsi_filters(vsi
)) {
2023 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
2027 ether_addr_copy(vf
->default_lan_addr
.addr
, mac
);
2028 vf
->pf_set_mac
= true;
2029 /* Force the VF driver stop so it has to reload with new MAC address */
2030 i40e_vc_disable_vf(pf
, vf
);
2031 dev_info(&pf
->pdev
->dev
, "Reload the VF driver to make this change effective.\n");
2038 * i40e_ndo_set_vf_port_vlan
2039 * @netdev: network interface device structure
2040 * @vf_id: VF identifier
2041 * @vlan_id: mac address
2042 * @qos: priority setting
2044 * program VF vlan id and/or qos
2046 int i40e_ndo_set_vf_port_vlan(struct net_device
*netdev
,
2047 int vf_id
, u16 vlan_id
, u8 qos
)
2049 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2050 struct i40e_pf
*pf
= np
->vsi
->back
;
2051 struct i40e_vsi
*vsi
;
2055 /* validate the request */
2056 if (vf_id
>= pf
->num_alloc_vfs
) {
2057 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2062 if ((vlan_id
> I40E_MAX_VLANID
) || (qos
> 7)) {
2063 dev_err(&pf
->pdev
->dev
, "Invalid VF Parameters\n");
2068 vf
= &(pf
->vf
[vf_id
]);
2069 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2070 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2071 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d\n", vf_id
);
2076 if (vsi
->info
.pvid
== 0 && i40e_is_vsi_in_vlan(vsi
)) {
2077 dev_err(&pf
->pdev
->dev
,
2078 "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",
2080 /* Administrator Error - knock the VF offline until he does
2081 * the right thing by reconfiguring his network correctly
2082 * and then reloading the VF driver.
2084 i40e_vc_disable_vf(pf
, vf
);
2087 /* Check for condition where there was already a port VLAN ID
2088 * filter set and now it is being deleted by setting it to zero.
2089 * Additionally check for the condition where there was a port
2090 * VLAN but now there is a new and different port VLAN being set.
2091 * Before deleting all the old VLAN filters we must add new ones
2092 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2093 * MAC addresses deleted.
2095 if ((!(vlan_id
|| qos
) ||
2096 (vlan_id
| qos
) != le16_to_cpu(vsi
->info
.pvid
)) &&
2098 ret
= i40e_vsi_add_vlan(vsi
, I40E_VLAN_ANY
);
2100 if (vsi
->info
.pvid
) {
2102 ret
= i40e_vsi_kill_vlan(vsi
, (le16_to_cpu(vsi
->info
.pvid
) &
2105 dev_info(&vsi
->back
->pdev
->dev
,
2106 "remove VLAN failed, ret=%d, aq_err=%d\n",
2107 ret
, pf
->hw
.aq
.asq_last_status
);
2111 ret
= i40e_vsi_add_pvid(vsi
,
2112 vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
));
2114 i40e_vsi_remove_pvid(vsi
);
2117 dev_info(&pf
->pdev
->dev
, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2118 vlan_id
, qos
, vf_id
);
2120 /* add new VLAN filter */
2121 ret
= i40e_vsi_add_vlan(vsi
, vlan_id
);
2123 dev_info(&vsi
->back
->pdev
->dev
,
2124 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
2125 vsi
->back
->hw
.aq
.asq_last_status
);
2128 /* Kill non-vlan MAC filters - ignore error return since
2129 * there might not be any non-vlan MAC filters.
2131 i40e_vsi_kill_vlan(vsi
, I40E_VLAN_ANY
);
2135 dev_err(&pf
->pdev
->dev
, "Unable to update VF vsi context\n");
2138 /* The Port VLAN needs to be saved across resets the same as the
2139 * default LAN MAC address.
2141 vf
->port_vlan_id
= le16_to_cpu(vsi
->info
.pvid
);
2148 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2149 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2151 * i40e_ndo_set_vf_bw
2152 * @netdev: network interface device structure
2153 * @vf_id: VF identifier
2156 * configure VF Tx rate
2158 int i40e_ndo_set_vf_bw(struct net_device
*netdev
, int vf_id
, int min_tx_rate
,
2161 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2162 struct i40e_pf
*pf
= np
->vsi
->back
;
2163 struct i40e_vsi
*vsi
;
2168 /* validate the request */
2169 if (vf_id
>= pf
->num_alloc_vfs
) {
2170 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d.\n", vf_id
);
2176 dev_err(&pf
->pdev
->dev
, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2177 min_tx_rate
, vf_id
);
2181 vf
= &(pf
->vf
[vf_id
]);
2182 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2183 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2184 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d.\n", vf_id
);
2189 switch (pf
->hw
.phy
.link_info
.link_speed
) {
2190 case I40E_LINK_SPEED_40GB
:
2193 case I40E_LINK_SPEED_10GB
:
2196 case I40E_LINK_SPEED_1GB
:
2203 if (max_tx_rate
> speed
) {
2204 dev_err(&pf
->pdev
->dev
, "Invalid max tx rate %d specified for VF %d.",
2205 max_tx_rate
, vf
->vf_id
);
2210 if ((max_tx_rate
< 50) && (max_tx_rate
> 0)) {
2211 dev_warn(&pf
->pdev
->dev
, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2215 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2216 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
2217 max_tx_rate
/ I40E_BW_CREDIT_DIVISOR
,
2218 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
2220 dev_err(&pf
->pdev
->dev
, "Unable to set max tx rate, error code %d.\n",
2225 vf
->tx_rate
= max_tx_rate
;
2231 * i40e_ndo_get_vf_config
2232 * @netdev: network interface device structure
2233 * @vf_id: VF identifier
2234 * @ivi: VF configuration structure
2236 * return VF configuration
2238 int i40e_ndo_get_vf_config(struct net_device
*netdev
,
2239 int vf_id
, struct ifla_vf_info
*ivi
)
2241 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2242 struct i40e_vsi
*vsi
= np
->vsi
;
2243 struct i40e_pf
*pf
= vsi
->back
;
2247 /* validate the request */
2248 if (vf_id
>= pf
->num_alloc_vfs
) {
2249 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2254 vf
= &(pf
->vf
[vf_id
]);
2255 /* first vsi is always the LAN vsi */
2256 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2257 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2258 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d\n", vf_id
);
2265 memcpy(&ivi
->mac
, vf
->default_lan_addr
.addr
, ETH_ALEN
);
2267 ivi
->max_tx_rate
= vf
->tx_rate
;
2268 ivi
->min_tx_rate
= 0;
2269 ivi
->vlan
= le16_to_cpu(vsi
->info
.pvid
) & I40E_VLAN_MASK
;
2270 ivi
->qos
= (le16_to_cpu(vsi
->info
.pvid
) & I40E_PRIORITY_MASK
) >>
2271 I40E_VLAN_PRIORITY_SHIFT
;
2272 if (vf
->link_forced
== false)
2273 ivi
->linkstate
= IFLA_VF_LINK_STATE_AUTO
;
2274 else if (vf
->link_up
== true)
2275 ivi
->linkstate
= IFLA_VF_LINK_STATE_ENABLE
;
2277 ivi
->linkstate
= IFLA_VF_LINK_STATE_DISABLE
;
2278 ivi
->spoofchk
= vf
->spoofchk
;
2286 * i40e_ndo_set_vf_link_state
2287 * @netdev: network interface device structure
2288 * @vf_id: VF identifier
2289 * @link: required link state
2291 * Set the link state of a specified VF, regardless of physical link state
2293 int i40e_ndo_set_vf_link_state(struct net_device
*netdev
, int vf_id
, int link
)
2295 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2296 struct i40e_pf
*pf
= np
->vsi
->back
;
2297 struct i40e_virtchnl_pf_event pfe
;
2298 struct i40e_hw
*hw
= &pf
->hw
;
2303 /* validate the request */
2304 if (vf_id
>= pf
->num_alloc_vfs
) {
2305 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2310 vf
= &pf
->vf
[vf_id
];
2311 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
2313 pfe
.event
= I40E_VIRTCHNL_EVENT_LINK_CHANGE
;
2314 pfe
.severity
= I40E_PF_EVENT_SEVERITY_INFO
;
2317 case IFLA_VF_LINK_STATE_AUTO
:
2318 vf
->link_forced
= false;
2319 pfe
.event_data
.link_event
.link_status
=
2320 pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
2321 pfe
.event_data
.link_event
.link_speed
=
2322 pf
->hw
.phy
.link_info
.link_speed
;
2324 case IFLA_VF_LINK_STATE_ENABLE
:
2325 vf
->link_forced
= true;
2327 pfe
.event_data
.link_event
.link_status
= true;
2328 pfe
.event_data
.link_event
.link_speed
= I40E_LINK_SPEED_40GB
;
2330 case IFLA_VF_LINK_STATE_DISABLE
:
2331 vf
->link_forced
= true;
2332 vf
->link_up
= false;
2333 pfe
.event_data
.link_event
.link_status
= false;
2334 pfe
.event_data
.link_event
.link_speed
= 0;
2340 /* Notify the VF of its new link state */
2341 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
2342 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
2349 * i40e_ndo_set_vf_spoofchk
2350 * @netdev: network interface device structure
2351 * @vf_id: VF identifier
2352 * @enable: flag to enable or disable feature
2354 * Enable or disable VF spoof checking
2356 int i40e_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf_id
, bool enable
)
2358 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2359 struct i40e_vsi
*vsi
= np
->vsi
;
2360 struct i40e_pf
*pf
= vsi
->back
;
2361 struct i40e_vsi_context ctxt
;
2362 struct i40e_hw
*hw
= &pf
->hw
;
2366 /* validate the request */
2367 if (vf_id
>= pf
->num_alloc_vfs
) {
2368 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2373 vf
= &(pf
->vf
[vf_id
]);
2375 if (enable
== vf
->spoofchk
)
2378 vf
->spoofchk
= enable
;
2379 memset(&ctxt
, 0, sizeof(ctxt
));
2380 ctxt
.seid
= pf
->vsi
[vf
->lan_vsi_idx
]->seid
;
2381 ctxt
.pf_num
= pf
->hw
.pf_id
;
2382 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
2384 ctxt
.info
.sec_flags
|= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
2385 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
2386 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
2388 dev_err(&pf
->pdev
->dev
, "Error %d updating VSI parameters\n",