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 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_config_vsi_tx_queue
356 * @vf: pointer to the VF info
357 * @vsi_id: id of VSI as provided by the FW
358 * @vsi_queue_id: vsi relative queue index
359 * @info: config. info
363 static int i40e_config_vsi_tx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
365 struct i40e_virtchnl_txq_info
*info
)
367 struct i40e_pf
*pf
= vf
->pf
;
368 struct i40e_hw
*hw
= &pf
->hw
;
369 struct i40e_hmc_obj_txq tx_ctx
;
370 struct i40e_vsi
*vsi
;
375 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
376 vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
378 /* clear the context structure first */
379 memset(&tx_ctx
, 0, sizeof(struct i40e_hmc_obj_txq
));
381 /* only set the required fields */
382 tx_ctx
.base
= info
->dma_ring_addr
/ 128;
383 tx_ctx
.qlen
= info
->ring_len
;
384 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[0]);
385 tx_ctx
.rdylist_act
= 0;
386 tx_ctx
.head_wb_ena
= info
->headwb_enabled
;
387 tx_ctx
.head_wb_addr
= info
->dma_headwb_addr
;
389 /* clear the context in the HMC */
390 ret
= i40e_clear_lan_tx_queue_context(hw
, pf_queue_id
);
392 dev_err(&pf
->pdev
->dev
,
393 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
399 /* set the context in the HMC */
400 ret
= i40e_set_lan_tx_queue_context(hw
, pf_queue_id
, &tx_ctx
);
402 dev_err(&pf
->pdev
->dev
,
403 "Failed to set VF LAN Tx queue context %d error: %d\n",
409 /* associate this queue with the PCI VF function */
410 qtx_ctl
= I40E_QTX_CTL_VF_QUEUE
;
411 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
)
412 & I40E_QTX_CTL_PF_INDX_MASK
);
413 qtx_ctl
|= (((vf
->vf_id
+ hw
->func_caps
.vf_base_id
)
414 << I40E_QTX_CTL_VFVM_INDX_SHIFT
)
415 & I40E_QTX_CTL_VFVM_INDX_MASK
);
416 wr32(hw
, I40E_QTX_CTL(pf_queue_id
), qtx_ctl
);
424 * i40e_config_vsi_rx_queue
425 * @vf: pointer to the VF info
426 * @vsi_id: id of VSI as provided by the FW
427 * @vsi_queue_id: vsi relative queue index
428 * @info: config. info
432 static int i40e_config_vsi_rx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
434 struct i40e_virtchnl_rxq_info
*info
)
436 struct i40e_pf
*pf
= vf
->pf
;
437 struct i40e_hw
*hw
= &pf
->hw
;
438 struct i40e_hmc_obj_rxq rx_ctx
;
442 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
444 /* clear the context structure first */
445 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
447 /* only set the required fields */
448 rx_ctx
.base
= info
->dma_ring_addr
/ 128;
449 rx_ctx
.qlen
= info
->ring_len
;
451 if (info
->splithdr_enabled
) {
452 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
454 I40E_RX_SPLIT_TCP_UDP
|
456 /* header length validation */
457 if (info
->hdr_size
> ((2 * 1024) - 64)) {
461 rx_ctx
.hbuff
= info
->hdr_size
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
463 /* set splitalways mode 10b */
467 /* databuffer length validation */
468 if (info
->databuffer_size
> ((16 * 1024) - 128)) {
472 rx_ctx
.dbuff
= info
->databuffer_size
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
474 /* max pkt. length validation */
475 if (info
->max_pkt_size
>= (16 * 1024) || info
->max_pkt_size
< 64) {
479 rx_ctx
.rxmax
= info
->max_pkt_size
;
481 /* enable 32bytes desc always */
485 rx_ctx
.lrxqthresh
= 2;
490 /* clear the context in the HMC */
491 ret
= i40e_clear_lan_rx_queue_context(hw
, pf_queue_id
);
493 dev_err(&pf
->pdev
->dev
,
494 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
500 /* set the context in the HMC */
501 ret
= i40e_set_lan_rx_queue_context(hw
, pf_queue_id
, &rx_ctx
);
503 dev_err(&pf
->pdev
->dev
,
504 "Failed to set VF LAN Rx queue context %d error: %d\n",
516 * @vf: pointer to the VF info
517 * @type: type of VSI to allocate
519 * alloc VF vsi context & resources
521 static int i40e_alloc_vsi_res(struct i40e_vf
*vf
, enum i40e_vsi_type type
)
523 struct i40e_mac_filter
*f
= NULL
;
524 struct i40e_pf
*pf
= vf
->pf
;
525 struct i40e_vsi
*vsi
;
528 vsi
= i40e_vsi_setup(pf
, type
, pf
->vsi
[pf
->lan_vsi
]->seid
, vf
->vf_id
);
531 dev_err(&pf
->pdev
->dev
,
532 "add vsi failed for VF %d, aq_err %d\n",
533 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
535 goto error_alloc_vsi_res
;
537 if (type
== I40E_VSI_SRIOV
) {
538 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
540 vf
->lan_vsi_idx
= vsi
->idx
;
541 vf
->lan_vsi_id
= vsi
->id
;
542 /* If the port VLAN has been configured and then the
543 * VF driver was removed then the VSI port VLAN
544 * configuration was destroyed. Check if there is
545 * a port VLAN and restore the VSI configuration if
548 if (vf
->port_vlan_id
)
549 i40e_vsi_add_pvid(vsi
, vf
->port_vlan_id
);
551 spin_lock_bh(&vsi
->mac_filter_list_lock
);
552 if (is_valid_ether_addr(vf
->default_lan_addr
.addr
)) {
553 f
= i40e_add_filter(vsi
, vf
->default_lan_addr
.addr
,
554 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
557 dev_info(&pf
->pdev
->dev
,
558 "Could not add MAC filter %pM for VF %d\n",
559 vf
->default_lan_addr
.addr
, vf
->vf_id
);
561 f
= i40e_add_filter(vsi
, brdcast
,
562 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
565 dev_info(&pf
->pdev
->dev
,
566 "Could not allocate VF broadcast filter\n");
567 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
570 /* program mac filter */
571 ret
= i40e_sync_vsi_filters(vsi
);
573 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
575 /* Set VF bandwidth if specified */
577 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
578 vf
->tx_rate
/ 50, 0, NULL
);
580 dev_err(&pf
->pdev
->dev
, "Unable to set tx rate, VF %d, error code %d.\n",
589 * i40e_enable_vf_mappings
590 * @vf: pointer to the VF info
594 static void i40e_enable_vf_mappings(struct i40e_vf
*vf
)
596 struct i40e_pf
*pf
= vf
->pf
;
597 struct i40e_hw
*hw
= &pf
->hw
;
598 u32 reg
, total_queue_pairs
= 0;
601 /* Tell the hardware we're using noncontiguous mapping. HW requires
602 * that VF queues be mapped using this method, even when they are
603 * contiguous in real life
605 wr32(hw
, I40E_VSILAN_QBASE(vf
->lan_vsi_id
),
606 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK
);
608 /* enable VF vplan_qtable mappings */
609 reg
= I40E_VPLAN_MAPENA_TXRX_ENA_MASK
;
610 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), reg
);
612 /* map PF queues to VF queues */
613 for (j
= 0; j
< pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
; j
++) {
614 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
, j
);
616 reg
= (qid
& I40E_VPLAN_QTABLE_QINDEX_MASK
);
617 wr32(hw
, I40E_VPLAN_QTABLE(total_queue_pairs
, vf
->vf_id
), reg
);
621 /* map PF queues to VSI */
622 for (j
= 0; j
< 7; j
++) {
623 if (j
* 2 >= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
) {
624 reg
= 0x07FF07FF; /* unused */
626 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
629 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
633 wr32(hw
, I40E_VSILAN_QTABLE(j
, vf
->lan_vsi_id
), reg
);
640 * i40e_disable_vf_mappings
641 * @vf: pointer to the VF info
643 * disable VF mappings
645 static void i40e_disable_vf_mappings(struct i40e_vf
*vf
)
647 struct i40e_pf
*pf
= vf
->pf
;
648 struct i40e_hw
*hw
= &pf
->hw
;
651 /* disable qp mappings */
652 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), 0);
653 for (i
= 0; i
< I40E_MAX_VSI_QP
; i
++)
654 wr32(hw
, I40E_VPLAN_QTABLE(i
, vf
->vf_id
),
655 I40E_QUEUE_END_OF_LIST
);
661 * @vf: pointer to the VF info
665 static void i40e_free_vf_res(struct i40e_vf
*vf
)
667 struct i40e_pf
*pf
= vf
->pf
;
668 struct i40e_hw
*hw
= &pf
->hw
;
672 /* free vsi & disconnect it from the parent uplink */
673 if (vf
->lan_vsi_idx
) {
674 i40e_vsi_release(pf
->vsi
[vf
->lan_vsi_idx
]);
678 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
680 /* disable interrupts so the VF starts in a known state */
681 for (i
= 0; i
< msix_vf
; i
++) {
682 /* format is same for both registers */
684 reg_idx
= I40E_VFINT_DYN_CTL0(vf
->vf_id
);
686 reg_idx
= I40E_VFINT_DYN_CTLN(((msix_vf
- 1) *
689 wr32(hw
, reg_idx
, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
693 /* clear the irq settings */
694 for (i
= 0; i
< msix_vf
; i
++) {
695 /* format is same for both registers */
697 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
699 reg_idx
= I40E_VPINT_LNKLSTN(((msix_vf
- 1) *
702 reg
= (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
|
703 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
);
704 wr32(hw
, reg_idx
, reg
);
707 /* reset some of the state varibles keeping
708 * track of the resources
710 vf
->num_queue_pairs
= 0;
712 clear_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
717 * @vf: pointer to the VF info
719 * allocate VF resources
721 static int i40e_alloc_vf_res(struct i40e_vf
*vf
)
723 struct i40e_pf
*pf
= vf
->pf
;
724 int total_queue_pairs
= 0;
727 /* allocate hw vsi context & associated resources */
728 ret
= i40e_alloc_vsi_res(vf
, I40E_VSI_SRIOV
);
731 total_queue_pairs
+= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
732 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
734 /* store the total qps number for the runtime
737 vf
->num_queue_pairs
= total_queue_pairs
;
739 /* VF is now completely initialized */
740 set_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
744 i40e_free_vf_res(vf
);
749 #define VF_DEVICE_STATUS 0xAA
750 #define VF_TRANS_PENDING_MASK 0x20
752 * i40e_quiesce_vf_pci
753 * @vf: pointer to the VF structure
755 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
756 * if the transactions never clear.
758 static int i40e_quiesce_vf_pci(struct i40e_vf
*vf
)
760 struct i40e_pf
*pf
= vf
->pf
;
761 struct i40e_hw
*hw
= &pf
->hw
;
765 vf_abs_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
767 wr32(hw
, I40E_PF_PCI_CIAA
,
768 VF_DEVICE_STATUS
| (vf_abs_id
<< I40E_PF_PCI_CIAA_VF_NUM_SHIFT
));
769 for (i
= 0; i
< 100; i
++) {
770 reg
= rd32(hw
, I40E_PF_PCI_CIAD
);
771 if ((reg
& VF_TRANS_PENDING_MASK
) == 0)
780 * @vf: pointer to the VF structure
781 * @flr: VFLR was issued or not
785 void i40e_reset_vf(struct i40e_vf
*vf
, bool flr
)
787 struct i40e_pf
*pf
= vf
->pf
;
788 struct i40e_hw
*hw
= &pf
->hw
;
793 if (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
797 clear_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
799 /* In the case of a VFLR, the HW has already reset the VF and we
800 * just need to clean up, so don't hit the VFRTRIG register.
803 /* reset VF using VPGEN_VFRTRIG reg */
804 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
805 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
806 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
810 if (i40e_quiesce_vf_pci(vf
))
811 dev_err(&pf
->pdev
->dev
, "VF %d PCI transactions stuck\n",
814 /* poll VPGEN_VFRSTAT reg to make sure
815 * that reset is complete
817 for (i
= 0; i
< 10; i
++) {
818 /* VF reset requires driver to first reset the VF and then
819 * poll the status register to make sure that the reset
820 * completed successfully. Due to internal HW FIFO flushes,
821 * we must wait 10ms before the register will be valid.
823 usleep_range(10000, 20000);
824 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
825 if (reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
) {
832 usleep_range(10000, 20000);
835 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
837 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_COMPLETED
);
838 /* clear the reset bit in the VPGEN_VFRTRIG reg */
839 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
840 reg
&= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
841 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
843 /* On initial reset, we won't have any queues */
844 if (vf
->lan_vsi_idx
== 0)
847 i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false);
849 /* reallocate VF resources to reset the VSI state */
850 i40e_free_vf_res(vf
);
851 if (!i40e_alloc_vf_res(vf
)) {
852 i40e_enable_vf_mappings(vf
);
853 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
854 clear_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
856 /* tell the VF the reset is done */
857 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_VFACTIVE
);
859 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
864 * @pf: pointer to the PF structure
868 void i40e_free_vfs(struct i40e_pf
*pf
)
870 struct i40e_hw
*hw
= &pf
->hw
;
871 u32 reg_idx
, bit_idx
;
876 while (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
877 usleep_range(1000, 2000);
879 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
880 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
881 i40e_vsi_control_rings(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
],
884 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
885 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
886 i40e_vsi_control_rings(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
],
889 /* Disable IOV before freeing resources. This lets any VF drivers
890 * running in the host get themselves cleaned up before we yank
891 * the carpet out from underneath their feet.
893 if (!pci_vfs_assigned(pf
->pdev
))
894 pci_disable_sriov(pf
->pdev
);
896 dev_warn(&pf
->pdev
->dev
, "VFs are assigned - not disabling SR-IOV\n");
898 msleep(20); /* let any messages in transit get finished up */
900 /* free up VF resources */
901 tmp
= pf
->num_alloc_vfs
;
902 pf
->num_alloc_vfs
= 0;
903 for (i
= 0; i
< tmp
; i
++) {
904 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
905 i40e_free_vf_res(&pf
->vf
[i
]);
906 /* disable qp mappings */
907 i40e_disable_vf_mappings(&pf
->vf
[i
]);
913 /* This check is for when the driver is unloaded while VFs are
914 * assigned. Setting the number of VFs to 0 through sysfs is caught
915 * before this function ever gets called.
917 if (!pci_vfs_assigned(pf
->pdev
)) {
918 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
919 * work correctly when SR-IOV gets re-enabled.
921 for (vf_id
= 0; vf_id
< tmp
; vf_id
++) {
922 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
923 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
924 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
927 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
930 #ifdef CONFIG_PCI_IOV
933 * @pf: pointer to the PF structure
934 * @num_alloc_vfs: number of VFs to allocate
936 * allocate VF resources
938 int i40e_alloc_vfs(struct i40e_pf
*pf
, u16 num_alloc_vfs
)
943 /* Disable interrupt 0 so we don't try to handle the VFLR. */
944 i40e_irq_dynamic_disable_icr0(pf
);
946 /* Check to see if we're just allocating resources for extant VFs */
947 if (pci_num_vf(pf
->pdev
) != num_alloc_vfs
) {
948 ret
= pci_enable_sriov(pf
->pdev
, num_alloc_vfs
);
950 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
951 pf
->num_alloc_vfs
= 0;
955 /* allocate memory */
956 vfs
= kcalloc(num_alloc_vfs
, sizeof(struct i40e_vf
), GFP_KERNEL
);
963 /* apply default profile */
964 for (i
= 0; i
< num_alloc_vfs
; i
++) {
966 vfs
[i
].parent_type
= I40E_SWITCH_ELEMENT_TYPE_VEB
;
969 /* assign default capabilities */
970 set_bit(I40E_VIRTCHNL_VF_CAP_L2
, &vfs
[i
].vf_caps
);
971 vfs
[i
].spoofchk
= true;
972 /* VF resources get allocated during reset */
973 i40e_reset_vf(&vfs
[i
], false);
976 pf
->num_alloc_vfs
= num_alloc_vfs
;
982 /* Re-enable interrupt 0. */
983 i40e_irq_dynamic_enable_icr0(pf
);
989 * i40e_pci_sriov_enable
990 * @pdev: pointer to a pci_dev structure
991 * @num_vfs: number of VFs to allocate
993 * Enable or change the number of VFs
995 static int i40e_pci_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
997 #ifdef CONFIG_PCI_IOV
998 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
999 int pre_existing_vfs
= pci_num_vf(pdev
);
1002 if (test_bit(__I40E_TESTING
, &pf
->state
)) {
1003 dev_warn(&pdev
->dev
,
1004 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1009 if (pre_existing_vfs
&& pre_existing_vfs
!= num_vfs
)
1011 else if (pre_existing_vfs
&& pre_existing_vfs
== num_vfs
)
1014 if (num_vfs
> pf
->num_req_vfs
) {
1015 dev_warn(&pdev
->dev
, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1016 num_vfs
, pf
->num_req_vfs
);
1021 dev_info(&pdev
->dev
, "Allocating %d VFs.\n", num_vfs
);
1022 err
= i40e_alloc_vfs(pf
, num_vfs
);
1024 dev_warn(&pdev
->dev
, "Failed to enable SR-IOV: %d\n", err
);
1038 * i40e_pci_sriov_configure
1039 * @pdev: pointer to a pci_dev structure
1040 * @num_vfs: number of VFs to allocate
1042 * Enable or change the number of VFs. Called when the user updates the number
1045 int i40e_pci_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
1047 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1050 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
1051 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
1052 i40e_do_reset_safe(pf
,
1053 BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1055 return i40e_pci_sriov_enable(pdev
, num_vfs
);
1058 if (!pci_vfs_assigned(pf
->pdev
)) {
1060 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1061 i40e_do_reset_safe(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1063 dev_warn(&pdev
->dev
, "Unable to free VFs because some are assigned to VMs.\n");
1069 /***********************virtual channel routines******************/
1072 * i40e_vc_send_msg_to_vf
1073 * @vf: pointer to the VF info
1074 * @v_opcode: virtual channel opcode
1075 * @v_retval: virtual channel return value
1076 * @msg: pointer to the msg buffer
1077 * @msglen: msg length
1081 static int i40e_vc_send_msg_to_vf(struct i40e_vf
*vf
, u32 v_opcode
,
1082 u32 v_retval
, u8
*msg
, u16 msglen
)
1089 /* validate the request */
1090 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
1095 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1097 /* single place to detect unsuccessful return values */
1099 vf
->num_invalid_msgs
++;
1100 dev_err(&pf
->pdev
->dev
, "VF %d failed opcode %d, error: %d\n",
1101 vf
->vf_id
, v_opcode
, v_retval
);
1102 if (vf
->num_invalid_msgs
>
1103 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED
) {
1104 dev_err(&pf
->pdev
->dev
,
1105 "Number of invalid messages exceeded for VF %d\n",
1107 dev_err(&pf
->pdev
->dev
, "Use PF Control I/F to enable the VF\n");
1108 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
1111 vf
->num_valid_msgs
++;
1112 /* reset the invalid counter, if a valid message is received. */
1113 vf
->num_invalid_msgs
= 0;
1116 aq_ret
= i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
1119 dev_err(&pf
->pdev
->dev
,
1120 "Unable to send the message to VF %d aq_err %d\n",
1121 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
1129 * i40e_vc_send_resp_to_vf
1130 * @vf: pointer to the VF info
1131 * @opcode: operation code
1132 * @retval: return value
1134 * send resp msg to VF
1136 static int i40e_vc_send_resp_to_vf(struct i40e_vf
*vf
,
1137 enum i40e_virtchnl_ops opcode
,
1140 return i40e_vc_send_msg_to_vf(vf
, opcode
, retval
, NULL
, 0);
1144 * i40e_vc_get_version_msg
1145 * @vf: pointer to the VF info
1147 * called from the VF to request the API version used by the PF
1149 static int i40e_vc_get_version_msg(struct i40e_vf
*vf
, u8
*msg
)
1151 struct i40e_virtchnl_version_info info
= {
1152 I40E_VIRTCHNL_VERSION_MAJOR
, I40E_VIRTCHNL_VERSION_MINOR
1155 vf
->vf_ver
= *(struct i40e_virtchnl_version_info
*)msg
;
1156 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1158 info
.minor
= I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS
;
1159 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_VERSION
,
1160 I40E_SUCCESS
, (u8
*)&info
,
1162 i40e_virtchnl_version_info
));
1166 * i40e_vc_get_vf_resources_msg
1167 * @vf: pointer to the VF info
1168 * @msg: pointer to the msg buffer
1169 * @msglen: msg length
1171 * called from the VF to request its resources
1173 static int i40e_vc_get_vf_resources_msg(struct i40e_vf
*vf
, u8
*msg
)
1175 struct i40e_virtchnl_vf_resource
*vfres
= NULL
;
1176 struct i40e_pf
*pf
= vf
->pf
;
1177 i40e_status aq_ret
= 0;
1178 struct i40e_vsi
*vsi
;
1183 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
1184 aq_ret
= I40E_ERR_PARAM
;
1188 len
= (sizeof(struct i40e_virtchnl_vf_resource
) +
1189 sizeof(struct i40e_virtchnl_vsi_resource
) * num_vsis
);
1191 vfres
= kzalloc(len
, GFP_KERNEL
);
1193 aq_ret
= I40E_ERR_NO_MEMORY
;
1198 vf
->driver_caps
= *(u32
*)msg
;
1200 vf
->driver_caps
= I40E_VIRTCHNL_VF_OFFLOAD_L2
|
1201 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG
|
1202 I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1204 vfres
->vf_offload_flags
= I40E_VIRTCHNL_VF_OFFLOAD_L2
;
1205 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1206 if (!vsi
->info
.pvid
)
1207 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1208 if (pf
->flags
& I40E_FLAG_RSS_AQ_CAPABLE
) {
1209 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ
)
1210 vfres
->vf_offload_flags
|=
1211 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ
;
1213 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG
;
1216 if (vf
->driver_caps
& I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING
)
1217 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING
;
1219 vfres
->num_vsis
= num_vsis
;
1220 vfres
->num_queue_pairs
= vf
->num_queue_pairs
;
1221 vfres
->max_vectors
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
1222 if (vf
->lan_vsi_idx
) {
1223 vfres
->vsi_res
[i
].vsi_id
= vf
->lan_vsi_id
;
1224 vfres
->vsi_res
[i
].vsi_type
= I40E_VSI_SRIOV
;
1225 vfres
->vsi_res
[i
].num_queue_pairs
= vsi
->alloc_queue_pairs
;
1226 /* VFs only use TC 0 */
1227 vfres
->vsi_res
[i
].qset_handle
1228 = le16_to_cpu(vsi
->info
.qs_handle
[0]);
1229 ether_addr_copy(vfres
->vsi_res
[i
].default_mac_addr
,
1230 vf
->default_lan_addr
.addr
);
1233 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
1236 /* send the response back to the VF */
1237 ret
= i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
1238 aq_ret
, (u8
*)vfres
, len
);
1245 * i40e_vc_reset_vf_msg
1246 * @vf: pointer to the VF info
1247 * @msg: pointer to the msg buffer
1248 * @msglen: msg length
1250 * called from the VF to reset itself,
1251 * unlike other virtchnl messages, PF driver
1252 * doesn't send the response back to the VF
1254 static void i40e_vc_reset_vf_msg(struct i40e_vf
*vf
)
1256 if (test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
1257 i40e_reset_vf(vf
, false);
1261 * i40e_vc_config_promiscuous_mode_msg
1262 * @vf: pointer to the VF info
1263 * @msg: pointer to the msg buffer
1264 * @msglen: msg length
1266 * called from the VF to configure the promiscuous mode of
1269 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf
*vf
,
1270 u8
*msg
, u16 msglen
)
1272 struct i40e_virtchnl_promisc_info
*info
=
1273 (struct i40e_virtchnl_promisc_info
*)msg
;
1274 struct i40e_pf
*pf
= vf
->pf
;
1275 struct i40e_hw
*hw
= &pf
->hw
;
1276 struct i40e_vsi
*vsi
;
1277 bool allmulti
= false;
1280 vsi
= i40e_find_vsi_from_id(pf
, info
->vsi_id
);
1281 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1282 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1283 !i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
) ||
1284 (vsi
->type
!= I40E_VSI_FCOE
)) {
1285 aq_ret
= I40E_ERR_PARAM
;
1288 if (info
->flags
& I40E_FLAG_VF_MULTICAST_PROMISC
)
1290 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(hw
, vsi
->seid
,
1294 /* send the response to the VF */
1295 return i40e_vc_send_resp_to_vf(vf
,
1296 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
1301 * i40e_vc_config_queues_msg
1302 * @vf: pointer to the VF info
1303 * @msg: pointer to the msg buffer
1304 * @msglen: msg length
1306 * called from the VF to configure the rx/tx
1309 static int i40e_vc_config_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1311 struct i40e_virtchnl_vsi_queue_config_info
*qci
=
1312 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1313 struct i40e_virtchnl_queue_pair_info
*qpi
;
1314 struct i40e_pf
*pf
= vf
->pf
;
1315 u16 vsi_id
, vsi_queue_id
;
1316 i40e_status aq_ret
= 0;
1319 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1320 aq_ret
= I40E_ERR_PARAM
;
1324 vsi_id
= qci
->vsi_id
;
1325 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1326 aq_ret
= I40E_ERR_PARAM
;
1329 for (i
= 0; i
< qci
->num_queue_pairs
; i
++) {
1330 qpi
= &qci
->qpair
[i
];
1331 vsi_queue_id
= qpi
->txq
.queue_id
;
1332 if ((qpi
->txq
.vsi_id
!= vsi_id
) ||
1333 (qpi
->rxq
.vsi_id
!= vsi_id
) ||
1334 (qpi
->rxq
.queue_id
!= vsi_queue_id
) ||
1335 !i40e_vc_isvalid_queue_id(vf
, vsi_id
, vsi_queue_id
)) {
1336 aq_ret
= I40E_ERR_PARAM
;
1340 if (i40e_config_vsi_rx_queue(vf
, vsi_id
, vsi_queue_id
,
1342 i40e_config_vsi_tx_queue(vf
, vsi_id
, vsi_queue_id
,
1344 aq_ret
= I40E_ERR_PARAM
;
1348 /* set vsi num_queue_pairs in use to num configured by VF */
1349 pf
->vsi
[vf
->lan_vsi_idx
]->num_queue_pairs
= qci
->num_queue_pairs
;
1352 /* send the response to the VF */
1353 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
1358 * i40e_vc_config_irq_map_msg
1359 * @vf: pointer to the VF info
1360 * @msg: pointer to the msg buffer
1361 * @msglen: msg length
1363 * called from the VF to configure the irq to
1366 static int i40e_vc_config_irq_map_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1368 struct i40e_virtchnl_irq_map_info
*irqmap_info
=
1369 (struct i40e_virtchnl_irq_map_info
*)msg
;
1370 struct i40e_virtchnl_vector_map
*map
;
1371 u16 vsi_id
, vsi_queue_id
, vector_id
;
1372 i40e_status aq_ret
= 0;
1373 unsigned long tempmap
;
1376 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1377 aq_ret
= I40E_ERR_PARAM
;
1381 for (i
= 0; i
< irqmap_info
->num_vectors
; i
++) {
1382 map
= &irqmap_info
->vecmap
[i
];
1384 vector_id
= map
->vector_id
;
1385 vsi_id
= map
->vsi_id
;
1386 /* validate msg params */
1387 if (!i40e_vc_isvalid_vector_id(vf
, vector_id
) ||
1388 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1389 aq_ret
= I40E_ERR_PARAM
;
1393 /* lookout for the invalid queue index */
1394 tempmap
= map
->rxq_map
;
1395 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1396 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1398 aq_ret
= I40E_ERR_PARAM
;
1403 tempmap
= map
->txq_map
;
1404 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1405 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1407 aq_ret
= I40E_ERR_PARAM
;
1412 i40e_config_irq_link_list(vf
, vsi_id
, map
);
1415 /* send the response to the VF */
1416 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
1421 * i40e_vc_enable_queues_msg
1422 * @vf: pointer to the VF info
1423 * @msg: pointer to the msg buffer
1424 * @msglen: msg length
1426 * called from the VF to enable all or specific queue(s)
1428 static int i40e_vc_enable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1430 struct i40e_virtchnl_queue_select
*vqs
=
1431 (struct i40e_virtchnl_queue_select
*)msg
;
1432 struct i40e_pf
*pf
= vf
->pf
;
1433 u16 vsi_id
= vqs
->vsi_id
;
1434 i40e_status aq_ret
= 0;
1436 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1437 aq_ret
= I40E_ERR_PARAM
;
1441 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1442 aq_ret
= I40E_ERR_PARAM
;
1446 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1447 aq_ret
= I40E_ERR_PARAM
;
1451 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], true))
1452 aq_ret
= I40E_ERR_TIMEOUT
;
1454 /* send the response to the VF */
1455 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
1460 * i40e_vc_disable_queues_msg
1461 * @vf: pointer to the VF info
1462 * @msg: pointer to the msg buffer
1463 * @msglen: msg length
1465 * called from the VF to disable all or specific
1468 static int i40e_vc_disable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1470 struct i40e_virtchnl_queue_select
*vqs
=
1471 (struct i40e_virtchnl_queue_select
*)msg
;
1472 struct i40e_pf
*pf
= vf
->pf
;
1473 i40e_status aq_ret
= 0;
1475 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1476 aq_ret
= I40E_ERR_PARAM
;
1480 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1481 aq_ret
= I40E_ERR_PARAM
;
1485 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1486 aq_ret
= I40E_ERR_PARAM
;
1490 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false))
1491 aq_ret
= I40E_ERR_TIMEOUT
;
1494 /* send the response to the VF */
1495 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
1500 * i40e_vc_get_stats_msg
1501 * @vf: pointer to the VF info
1502 * @msg: pointer to the msg buffer
1503 * @msglen: msg length
1505 * called from the VF to get vsi stats
1507 static int i40e_vc_get_stats_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1509 struct i40e_virtchnl_queue_select
*vqs
=
1510 (struct i40e_virtchnl_queue_select
*)msg
;
1511 struct i40e_pf
*pf
= vf
->pf
;
1512 struct i40e_eth_stats stats
;
1513 i40e_status aq_ret
= 0;
1514 struct i40e_vsi
*vsi
;
1516 memset(&stats
, 0, sizeof(struct i40e_eth_stats
));
1518 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1519 aq_ret
= I40E_ERR_PARAM
;
1523 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1524 aq_ret
= I40E_ERR_PARAM
;
1528 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1530 aq_ret
= I40E_ERR_PARAM
;
1533 i40e_update_eth_stats(vsi
);
1534 stats
= vsi
->eth_stats
;
1537 /* send the response back to the VF */
1538 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_STATS
, aq_ret
,
1539 (u8
*)&stats
, sizeof(stats
));
1543 * i40e_check_vf_permission
1544 * @vf: pointer to the VF info
1545 * @macaddr: pointer to the MAC Address being checked
1547 * Check if the VF has permission to add or delete unicast MAC address
1548 * filters and return error code -EPERM if not. Then check if the
1549 * address filter requested is broadcast or zero and if so return
1550 * an invalid MAC address error code.
1552 static inline int i40e_check_vf_permission(struct i40e_vf
*vf
, u8
*macaddr
)
1554 struct i40e_pf
*pf
= vf
->pf
;
1557 if (is_broadcast_ether_addr(macaddr
) ||
1558 is_zero_ether_addr(macaddr
)) {
1559 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n", macaddr
);
1560 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1561 } else if (vf
->pf_set_mac
&& !is_multicast_ether_addr(macaddr
) &&
1562 !ether_addr_equal(macaddr
, vf
->default_lan_addr
.addr
)) {
1563 /* If the host VMM administrator has set the VF MAC address
1564 * administratively via the ndo_set_vf_mac command then deny
1565 * permission to the VF to add or delete unicast MAC addresses.
1566 * The VF may request to set the MAC address filter already
1567 * assigned to it so do not return an error in that case.
1569 dev_err(&pf
->pdev
->dev
,
1570 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1577 * i40e_vc_add_mac_addr_msg
1578 * @vf: pointer to the VF info
1579 * @msg: pointer to the msg buffer
1580 * @msglen: msg length
1582 * add guest mac address filter
1584 static int i40e_vc_add_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1586 struct i40e_virtchnl_ether_addr_list
*al
=
1587 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1588 struct i40e_pf
*pf
= vf
->pf
;
1589 struct i40e_vsi
*vsi
= NULL
;
1590 u16 vsi_id
= al
->vsi_id
;
1591 i40e_status ret
= 0;
1594 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1595 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1596 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1597 ret
= I40E_ERR_PARAM
;
1601 for (i
= 0; i
< al
->num_elements
; i
++) {
1602 ret
= i40e_check_vf_permission(vf
, al
->list
[i
].addr
);
1606 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1608 /* Lock once, because all function inside for loop accesses VSI's
1609 * MAC filter list which needs to be protected using same lock.
1611 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1613 /* add new addresses to the list */
1614 for (i
= 0; i
< al
->num_elements
; i
++) {
1615 struct i40e_mac_filter
*f
;
1617 f
= i40e_find_mac(vsi
, al
->list
[i
].addr
, true, false);
1619 if (i40e_is_vsi_in_vlan(vsi
))
1620 f
= i40e_put_mac_in_vlan(vsi
, al
->list
[i
].addr
,
1623 f
= i40e_add_filter(vsi
, al
->list
[i
].addr
, -1,
1628 dev_err(&pf
->pdev
->dev
,
1629 "Unable to add MAC filter %pM for VF %d\n",
1630 al
->list
[i
].addr
, vf
->vf_id
);
1631 ret
= I40E_ERR_PARAM
;
1632 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1636 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1638 /* program the updated filter list */
1639 ret
= i40e_sync_vsi_filters(vsi
);
1641 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
1645 /* send the response to the VF */
1646 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
1651 * i40e_vc_del_mac_addr_msg
1652 * @vf: pointer to the VF info
1653 * @msg: pointer to the msg buffer
1654 * @msglen: msg length
1656 * remove guest mac address filter
1658 static int i40e_vc_del_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1660 struct i40e_virtchnl_ether_addr_list
*al
=
1661 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1662 struct i40e_pf
*pf
= vf
->pf
;
1663 struct i40e_vsi
*vsi
= NULL
;
1664 u16 vsi_id
= al
->vsi_id
;
1665 i40e_status ret
= 0;
1668 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1669 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1670 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1671 ret
= I40E_ERR_PARAM
;
1675 for (i
= 0; i
< al
->num_elements
; i
++) {
1676 if (is_broadcast_ether_addr(al
->list
[i
].addr
) ||
1677 is_zero_ether_addr(al
->list
[i
].addr
)) {
1678 dev_err(&pf
->pdev
->dev
, "Invalid MAC addr %pM for VF %d\n",
1679 al
->list
[i
].addr
, vf
->vf_id
);
1680 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1684 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1686 spin_lock_bh(&vsi
->mac_filter_list_lock
);
1687 /* delete addresses from the list */
1688 for (i
= 0; i
< al
->num_elements
; i
++)
1689 if (i40e_del_mac_all_vlan(vsi
, al
->list
[i
].addr
, true, false)) {
1690 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1691 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1695 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
1697 /* program the updated filter list */
1698 ret
= i40e_sync_vsi_filters(vsi
);
1700 dev_err(&pf
->pdev
->dev
, "Unable to program VF %d MAC filters, error %d\n",
1704 /* send the response to the VF */
1705 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
1710 * i40e_vc_add_vlan_msg
1711 * @vf: pointer to the VF info
1712 * @msg: pointer to the msg buffer
1713 * @msglen: msg length
1715 * program guest vlan id
1717 static int i40e_vc_add_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1719 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1720 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1721 struct i40e_pf
*pf
= vf
->pf
;
1722 struct i40e_vsi
*vsi
= NULL
;
1723 u16 vsi_id
= vfl
->vsi_id
;
1724 i40e_status aq_ret
= 0;
1727 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1728 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1729 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1730 aq_ret
= I40E_ERR_PARAM
;
1734 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1735 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1736 aq_ret
= I40E_ERR_PARAM
;
1737 dev_err(&pf
->pdev
->dev
,
1738 "invalid VF VLAN id %d\n", vfl
->vlan_id
[i
]);
1742 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1743 if (vsi
->info
.pvid
) {
1744 aq_ret
= I40E_ERR_PARAM
;
1748 i40e_vlan_stripping_enable(vsi
);
1749 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1750 /* add new VLAN filter */
1751 int ret
= i40e_vsi_add_vlan(vsi
, vfl
->vlan_id
[i
]);
1754 dev_err(&pf
->pdev
->dev
,
1755 "Unable to add VLAN filter %d for VF %d, error %d\n",
1756 vfl
->vlan_id
[i
], vf
->vf_id
, ret
);
1760 /* send the response to the VF */
1761 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_VLAN
, aq_ret
);
1765 * i40e_vc_remove_vlan_msg
1766 * @vf: pointer to the VF info
1767 * @msg: pointer to the msg buffer
1768 * @msglen: msg length
1770 * remove programmed guest vlan id
1772 static int i40e_vc_remove_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1774 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1775 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1776 struct i40e_pf
*pf
= vf
->pf
;
1777 struct i40e_vsi
*vsi
= NULL
;
1778 u16 vsi_id
= vfl
->vsi_id
;
1779 i40e_status aq_ret
= 0;
1782 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1783 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1784 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1785 aq_ret
= I40E_ERR_PARAM
;
1789 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1790 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1791 aq_ret
= I40E_ERR_PARAM
;
1796 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1797 if (vsi
->info
.pvid
) {
1798 aq_ret
= I40E_ERR_PARAM
;
1802 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1803 int ret
= i40e_vsi_kill_vlan(vsi
, vfl
->vlan_id
[i
]);
1806 dev_err(&pf
->pdev
->dev
,
1807 "Unable to delete VLAN filter %d for VF %d, error %d\n",
1808 vfl
->vlan_id
[i
], vf
->vf_id
, ret
);
1812 /* send the response to the VF */
1813 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_VLAN
, aq_ret
);
1817 * i40e_vc_validate_vf_msg
1818 * @vf: pointer to the VF info
1819 * @msg: pointer to the msg buffer
1820 * @msglen: msg length
1821 * @msghndl: msg handle
1825 static int i40e_vc_validate_vf_msg(struct i40e_vf
*vf
, u32 v_opcode
,
1826 u32 v_retval
, u8
*msg
, u16 msglen
)
1828 bool err_msg_format
= false;
1831 /* Check if VF is disabled. */
1832 if (test_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
))
1833 return I40E_ERR_PARAM
;
1835 /* Validate message length. */
1837 case I40E_VIRTCHNL_OP_VERSION
:
1838 valid_len
= sizeof(struct i40e_virtchnl_version_info
);
1840 case I40E_VIRTCHNL_OP_RESET_VF
:
1843 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1845 valid_len
= sizeof(u32
);
1849 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE
:
1850 valid_len
= sizeof(struct i40e_virtchnl_txq_info
);
1852 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE
:
1853 valid_len
= sizeof(struct i40e_virtchnl_rxq_info
);
1855 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1856 valid_len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
);
1857 if (msglen
>= valid_len
) {
1858 struct i40e_virtchnl_vsi_queue_config_info
*vqc
=
1859 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1860 valid_len
+= (vqc
->num_queue_pairs
*
1862 i40e_virtchnl_queue_pair_info
));
1863 if (vqc
->num_queue_pairs
== 0)
1864 err_msg_format
= true;
1867 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1868 valid_len
= sizeof(struct i40e_virtchnl_irq_map_info
);
1869 if (msglen
>= valid_len
) {
1870 struct i40e_virtchnl_irq_map_info
*vimi
=
1871 (struct i40e_virtchnl_irq_map_info
*)msg
;
1872 valid_len
+= (vimi
->num_vectors
*
1873 sizeof(struct i40e_virtchnl_vector_map
));
1874 if (vimi
->num_vectors
== 0)
1875 err_msg_format
= true;
1878 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1879 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1880 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1882 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1883 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1884 valid_len
= sizeof(struct i40e_virtchnl_ether_addr_list
);
1885 if (msglen
>= valid_len
) {
1886 struct i40e_virtchnl_ether_addr_list
*veal
=
1887 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1888 valid_len
+= veal
->num_elements
*
1889 sizeof(struct i40e_virtchnl_ether_addr
);
1890 if (veal
->num_elements
== 0)
1891 err_msg_format
= true;
1894 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1895 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1896 valid_len
= sizeof(struct i40e_virtchnl_vlan_filter_list
);
1897 if (msglen
>= valid_len
) {
1898 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1899 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1900 valid_len
+= vfl
->num_elements
* sizeof(u16
);
1901 if (vfl
->num_elements
== 0)
1902 err_msg_format
= true;
1905 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1906 valid_len
= sizeof(struct i40e_virtchnl_promisc_info
);
1908 case I40E_VIRTCHNL_OP_GET_STATS
:
1909 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1911 /* These are always errors coming from the VF. */
1912 case I40E_VIRTCHNL_OP_EVENT
:
1913 case I40E_VIRTCHNL_OP_UNKNOWN
:
1917 /* few more checks */
1918 if ((valid_len
!= msglen
) || (err_msg_format
)) {
1919 i40e_vc_send_resp_to_vf(vf
, v_opcode
, I40E_ERR_PARAM
);
1927 * i40e_vc_process_vf_msg
1928 * @pf: pointer to the PF structure
1929 * @vf_id: source VF id
1930 * @msg: pointer to the msg buffer
1931 * @msglen: msg length
1932 * @msghndl: msg handle
1934 * called from the common aeq/arq handler to
1935 * process request from VF
1937 int i40e_vc_process_vf_msg(struct i40e_pf
*pf
, u16 vf_id
, u32 v_opcode
,
1938 u32 v_retval
, u8
*msg
, u16 msglen
)
1940 struct i40e_hw
*hw
= &pf
->hw
;
1941 unsigned int local_vf_id
= vf_id
- hw
->func_caps
.vf_base_id
;
1945 pf
->vf_aq_requests
++;
1946 if (local_vf_id
>= pf
->num_alloc_vfs
)
1948 vf
= &(pf
->vf
[local_vf_id
]);
1949 /* perform basic checks on the msg */
1950 ret
= i40e_vc_validate_vf_msg(vf
, v_opcode
, v_retval
, msg
, msglen
);
1953 dev_err(&pf
->pdev
->dev
, "Invalid message from VF %d, opcode %d, len %d\n",
1954 local_vf_id
, v_opcode
, msglen
);
1959 case I40E_VIRTCHNL_OP_VERSION
:
1960 ret
= i40e_vc_get_version_msg(vf
, msg
);
1962 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1963 ret
= i40e_vc_get_vf_resources_msg(vf
, msg
);
1965 case I40E_VIRTCHNL_OP_RESET_VF
:
1966 i40e_vc_reset_vf_msg(vf
);
1969 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1970 ret
= i40e_vc_config_promiscuous_mode_msg(vf
, msg
, msglen
);
1972 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1973 ret
= i40e_vc_config_queues_msg(vf
, msg
, msglen
);
1975 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1976 ret
= i40e_vc_config_irq_map_msg(vf
, msg
, msglen
);
1978 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1979 ret
= i40e_vc_enable_queues_msg(vf
, msg
, msglen
);
1980 i40e_vc_notify_vf_link_state(vf
);
1982 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1983 ret
= i40e_vc_disable_queues_msg(vf
, msg
, msglen
);
1985 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1986 ret
= i40e_vc_add_mac_addr_msg(vf
, msg
, msglen
);
1988 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1989 ret
= i40e_vc_del_mac_addr_msg(vf
, msg
, msglen
);
1991 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1992 ret
= i40e_vc_add_vlan_msg(vf
, msg
, msglen
);
1994 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1995 ret
= i40e_vc_remove_vlan_msg(vf
, msg
, msglen
);
1997 case I40E_VIRTCHNL_OP_GET_STATS
:
1998 ret
= i40e_vc_get_stats_msg(vf
, msg
, msglen
);
2000 case I40E_VIRTCHNL_OP_UNKNOWN
:
2002 dev_err(&pf
->pdev
->dev
, "Unsupported opcode %d from VF %d\n",
2003 v_opcode
, local_vf_id
);
2004 ret
= i40e_vc_send_resp_to_vf(vf
, v_opcode
,
2005 I40E_ERR_NOT_IMPLEMENTED
);
2013 * i40e_vc_process_vflr_event
2014 * @pf: pointer to the PF structure
2016 * called from the vlfr irq handler to
2017 * free up VF resources and state variables
2019 int i40e_vc_process_vflr_event(struct i40e_pf
*pf
)
2021 u32 reg
, reg_idx
, bit_idx
, vf_id
;
2022 struct i40e_hw
*hw
= &pf
->hw
;
2025 if (!test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
2028 /* re-enable vflr interrupt cause */
2029 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
2030 reg
|= I40E_PFINT_ICR0_ENA_VFLR_MASK
;
2031 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
2034 clear_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
2035 for (vf_id
= 0; vf_id
< pf
->num_alloc_vfs
; vf_id
++) {
2036 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
2037 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
2038 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
2039 vf
= &pf
->vf
[vf_id
];
2040 reg
= rd32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
));
2041 if (reg
& BIT(bit_idx
)) {
2042 /* clear the bit in GLGEN_VFLRSTAT */
2043 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), BIT(bit_idx
));
2045 if (!test_bit(__I40E_DOWN
, &pf
->state
))
2046 i40e_reset_vf(vf
, true);
2054 * i40e_ndo_set_vf_mac
2055 * @netdev: network interface device structure
2056 * @vf_id: VF identifier
2059 * program VF mac address
2061 int i40e_ndo_set_vf_mac(struct net_device
*netdev
, int vf_id
, u8
*mac
)
2063 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2064 struct i40e_vsi
*vsi
= np
->vsi
;
2065 struct i40e_pf
*pf
= vsi
->back
;
2066 struct i40e_mac_filter
*f
;
2070 /* validate the request */
2071 if (vf_id
>= pf
->num_alloc_vfs
) {
2072 dev_err(&pf
->pdev
->dev
,
2073 "Invalid VF Identifier %d\n", vf_id
);
2078 vf
= &(pf
->vf
[vf_id
]);
2079 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2080 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2081 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2087 if (is_multicast_ether_addr(mac
)) {
2088 dev_err(&pf
->pdev
->dev
,
2089 "Invalid Ethernet address %pM for VF %d\n", mac
, vf_id
);
2094 /* Lock once because below invoked function add/del_filter requires
2095 * mac_filter_list_lock to be held
2097 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2099 /* delete the temporary mac address */
2100 if (!is_zero_ether_addr(vf
->default_lan_addr
.addr
))
2101 i40e_del_filter(vsi
, vf
->default_lan_addr
.addr
,
2102 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
2105 /* Delete all the filters for this VSI - we're going to kill it
2108 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2109 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
, true, false);
2111 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2113 dev_info(&pf
->pdev
->dev
, "Setting MAC %pM on VF %d\n", mac
, vf_id
);
2114 /* program mac filter */
2115 if (i40e_sync_vsi_filters(vsi
)) {
2116 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
2120 ether_addr_copy(vf
->default_lan_addr
.addr
, mac
);
2121 vf
->pf_set_mac
= true;
2122 /* Force the VF driver stop so it has to reload with new MAC address */
2123 i40e_vc_disable_vf(pf
, vf
);
2124 dev_info(&pf
->pdev
->dev
, "Reload the VF driver to make this change effective.\n");
2131 * i40e_ndo_set_vf_port_vlan
2132 * @netdev: network interface device structure
2133 * @vf_id: VF identifier
2134 * @vlan_id: mac address
2135 * @qos: priority setting
2137 * program VF vlan id and/or qos
2139 int i40e_ndo_set_vf_port_vlan(struct net_device
*netdev
,
2140 int vf_id
, u16 vlan_id
, u8 qos
)
2142 u16 vlanprio
= vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
);
2143 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2144 struct i40e_pf
*pf
= np
->vsi
->back
;
2145 bool is_vsi_in_vlan
= false;
2146 struct i40e_vsi
*vsi
;
2150 /* validate the request */
2151 if (vf_id
>= pf
->num_alloc_vfs
) {
2152 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2157 if ((vlan_id
> I40E_MAX_VLANID
) || (qos
> 7)) {
2158 dev_err(&pf
->pdev
->dev
, "Invalid VF Parameters\n");
2163 vf
= &(pf
->vf
[vf_id
]);
2164 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2165 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2166 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2172 if (le16_to_cpu(vsi
->info
.pvid
) == vlanprio
)
2173 /* duplicate request, so just return success */
2176 spin_lock_bh(&vsi
->mac_filter_list_lock
);
2177 is_vsi_in_vlan
= i40e_is_vsi_in_vlan(vsi
);
2178 spin_unlock_bh(&vsi
->mac_filter_list_lock
);
2180 if (le16_to_cpu(vsi
->info
.pvid
) == 0 && is_vsi_in_vlan
) {
2181 dev_err(&pf
->pdev
->dev
,
2182 "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",
2184 /* Administrator Error - knock the VF offline until he does
2185 * the right thing by reconfiguring his network correctly
2186 * and then reloading the VF driver.
2188 i40e_vc_disable_vf(pf
, vf
);
2191 /* Check for condition where there was already a port VLAN ID
2192 * filter set and now it is being deleted by setting it to zero.
2193 * Additionally check for the condition where there was a port
2194 * VLAN but now there is a new and different port VLAN being set.
2195 * Before deleting all the old VLAN filters we must add new ones
2196 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2197 * MAC addresses deleted.
2199 if ((!(vlan_id
|| qos
) ||
2200 vlanprio
!= le16_to_cpu(vsi
->info
.pvid
)) &&
2202 ret
= i40e_vsi_add_vlan(vsi
, I40E_VLAN_ANY
);
2204 if (vsi
->info
.pvid
) {
2206 ret
= i40e_vsi_kill_vlan(vsi
, (le16_to_cpu(vsi
->info
.pvid
) &
2209 dev_info(&vsi
->back
->pdev
->dev
,
2210 "remove VLAN failed, ret=%d, aq_err=%d\n",
2211 ret
, pf
->hw
.aq
.asq_last_status
);
2215 ret
= i40e_vsi_add_pvid(vsi
, vlanprio
);
2217 i40e_vsi_remove_pvid(vsi
);
2220 dev_info(&pf
->pdev
->dev
, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2221 vlan_id
, qos
, vf_id
);
2223 /* add new VLAN filter */
2224 ret
= i40e_vsi_add_vlan(vsi
, vlan_id
);
2226 dev_info(&vsi
->back
->pdev
->dev
,
2227 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
2228 vsi
->back
->hw
.aq
.asq_last_status
);
2231 /* Kill non-vlan MAC filters - ignore error return since
2232 * there might not be any non-vlan MAC filters.
2234 i40e_vsi_kill_vlan(vsi
, I40E_VLAN_ANY
);
2238 dev_err(&pf
->pdev
->dev
, "Unable to update VF vsi context\n");
2241 /* The Port VLAN needs to be saved across resets the same as the
2242 * default LAN MAC address.
2244 vf
->port_vlan_id
= le16_to_cpu(vsi
->info
.pvid
);
2251 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2252 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2254 * i40e_ndo_set_vf_bw
2255 * @netdev: network interface device structure
2256 * @vf_id: VF identifier
2259 * configure VF Tx rate
2261 int i40e_ndo_set_vf_bw(struct net_device
*netdev
, int vf_id
, int min_tx_rate
,
2264 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2265 struct i40e_pf
*pf
= np
->vsi
->back
;
2266 struct i40e_vsi
*vsi
;
2271 /* validate the request */
2272 if (vf_id
>= pf
->num_alloc_vfs
) {
2273 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d.\n", vf_id
);
2279 dev_err(&pf
->pdev
->dev
, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2280 min_tx_rate
, vf_id
);
2284 vf
= &(pf
->vf
[vf_id
]);
2285 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2286 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2287 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2293 switch (pf
->hw
.phy
.link_info
.link_speed
) {
2294 case I40E_LINK_SPEED_40GB
:
2297 case I40E_LINK_SPEED_10GB
:
2300 case I40E_LINK_SPEED_1GB
:
2307 if (max_tx_rate
> speed
) {
2308 dev_err(&pf
->pdev
->dev
, "Invalid max tx rate %d specified for VF %d.",
2309 max_tx_rate
, vf
->vf_id
);
2314 if ((max_tx_rate
< 50) && (max_tx_rate
> 0)) {
2315 dev_warn(&pf
->pdev
->dev
, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2319 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2320 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
2321 max_tx_rate
/ I40E_BW_CREDIT_DIVISOR
,
2322 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
2324 dev_err(&pf
->pdev
->dev
, "Unable to set max tx rate, error code %d.\n",
2329 vf
->tx_rate
= max_tx_rate
;
2335 * i40e_ndo_get_vf_config
2336 * @netdev: network interface device structure
2337 * @vf_id: VF identifier
2338 * @ivi: VF configuration structure
2340 * return VF configuration
2342 int i40e_ndo_get_vf_config(struct net_device
*netdev
,
2343 int vf_id
, struct ifla_vf_info
*ivi
)
2345 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2346 struct i40e_vsi
*vsi
= np
->vsi
;
2347 struct i40e_pf
*pf
= vsi
->back
;
2351 /* validate the request */
2352 if (vf_id
>= pf
->num_alloc_vfs
) {
2353 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2358 vf
= &(pf
->vf
[vf_id
]);
2359 /* first vsi is always the LAN vsi */
2360 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2361 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2362 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2370 ether_addr_copy(ivi
->mac
, vf
->default_lan_addr
.addr
);
2372 ivi
->max_tx_rate
= vf
->tx_rate
;
2373 ivi
->min_tx_rate
= 0;
2374 ivi
->vlan
= le16_to_cpu(vsi
->info
.pvid
) & I40E_VLAN_MASK
;
2375 ivi
->qos
= (le16_to_cpu(vsi
->info
.pvid
) & I40E_PRIORITY_MASK
) >>
2376 I40E_VLAN_PRIORITY_SHIFT
;
2377 if (vf
->link_forced
== false)
2378 ivi
->linkstate
= IFLA_VF_LINK_STATE_AUTO
;
2379 else if (vf
->link_up
== true)
2380 ivi
->linkstate
= IFLA_VF_LINK_STATE_ENABLE
;
2382 ivi
->linkstate
= IFLA_VF_LINK_STATE_DISABLE
;
2383 ivi
->spoofchk
= vf
->spoofchk
;
2391 * i40e_ndo_set_vf_link_state
2392 * @netdev: network interface device structure
2393 * @vf_id: VF identifier
2394 * @link: required link state
2396 * Set the link state of a specified VF, regardless of physical link state
2398 int i40e_ndo_set_vf_link_state(struct net_device
*netdev
, int vf_id
, int link
)
2400 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2401 struct i40e_pf
*pf
= np
->vsi
->back
;
2402 struct i40e_virtchnl_pf_event pfe
;
2403 struct i40e_hw
*hw
= &pf
->hw
;
2408 /* validate the request */
2409 if (vf_id
>= pf
->num_alloc_vfs
) {
2410 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2415 vf
= &pf
->vf
[vf_id
];
2416 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
2418 pfe
.event
= I40E_VIRTCHNL_EVENT_LINK_CHANGE
;
2419 pfe
.severity
= I40E_PF_EVENT_SEVERITY_INFO
;
2422 case IFLA_VF_LINK_STATE_AUTO
:
2423 vf
->link_forced
= false;
2424 pfe
.event_data
.link_event
.link_status
=
2425 pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
2426 pfe
.event_data
.link_event
.link_speed
=
2427 pf
->hw
.phy
.link_info
.link_speed
;
2429 case IFLA_VF_LINK_STATE_ENABLE
:
2430 vf
->link_forced
= true;
2432 pfe
.event_data
.link_event
.link_status
= true;
2433 pfe
.event_data
.link_event
.link_speed
= I40E_LINK_SPEED_40GB
;
2435 case IFLA_VF_LINK_STATE_DISABLE
:
2436 vf
->link_forced
= true;
2437 vf
->link_up
= false;
2438 pfe
.event_data
.link_event
.link_status
= false;
2439 pfe
.event_data
.link_event
.link_speed
= 0;
2445 /* Notify the VF of its new link state */
2446 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
2447 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
2454 * i40e_ndo_set_vf_spoofchk
2455 * @netdev: network interface device structure
2456 * @vf_id: VF identifier
2457 * @enable: flag to enable or disable feature
2459 * Enable or disable VF spoof checking
2461 int i40e_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf_id
, bool enable
)
2463 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2464 struct i40e_vsi
*vsi
= np
->vsi
;
2465 struct i40e_pf
*pf
= vsi
->back
;
2466 struct i40e_vsi_context ctxt
;
2467 struct i40e_hw
*hw
= &pf
->hw
;
2471 /* validate the request */
2472 if (vf_id
>= pf
->num_alloc_vfs
) {
2473 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2478 vf
= &(pf
->vf
[vf_id
]);
2479 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2480 dev_err(&pf
->pdev
->dev
, "VF %d still in reset. Try again.\n",
2486 if (enable
== vf
->spoofchk
)
2489 vf
->spoofchk
= enable
;
2490 memset(&ctxt
, 0, sizeof(ctxt
));
2491 ctxt
.seid
= pf
->vsi
[vf
->lan_vsi_idx
]->seid
;
2492 ctxt
.pf_num
= pf
->hw
.pf_id
;
2493 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
2495 ctxt
.info
.sec_flags
|= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
2496 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
2497 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
2499 dev_err(&pf
->pdev
->dev
, "Error %d updating VSI parameters\n",