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
) {
281 (I40E_VIRTCHNL_SUPPORTED_QTYPES
*
285 tempmap
= vecmap
->txq_map
;
286 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
288 (I40E_VIRTCHNL_SUPPORTED_QTYPES
* vsi_queue_id
292 next_q
= find_first_bit(&linklistmap
,
294 I40E_VIRTCHNL_SUPPORTED_QTYPES
));
295 vsi_queue_id
= next_q
/I40E_VIRTCHNL_SUPPORTED_QTYPES
;
296 qtype
= next_q
%I40E_VIRTCHNL_SUPPORTED_QTYPES
;
297 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
298 reg
= ((qtype
<< I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT
) | pf_queue_id
);
300 wr32(hw
, reg_idx
, reg
);
302 while (next_q
< (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
304 case I40E_QUEUE_TYPE_RX
:
305 reg_idx
= I40E_QINT_RQCTL(pf_queue_id
);
306 itr_idx
= vecmap
->rxitr_idx
;
308 case I40E_QUEUE_TYPE_TX
:
309 reg_idx
= I40E_QINT_TQCTL(pf_queue_id
);
310 itr_idx
= vecmap
->txitr_idx
;
316 next_q
= find_next_bit(&linklistmap
,
318 I40E_VIRTCHNL_SUPPORTED_QTYPES
),
321 (I40E_MAX_VSI_QP
* I40E_VIRTCHNL_SUPPORTED_QTYPES
)) {
322 vsi_queue_id
= next_q
/ I40E_VIRTCHNL_SUPPORTED_QTYPES
;
323 qtype
= next_q
% I40E_VIRTCHNL_SUPPORTED_QTYPES
;
324 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
,
327 pf_queue_id
= I40E_QUEUE_END_OF_LIST
;
331 /* format for the RQCTL & TQCTL regs is same */
333 (qtype
<< I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT
) |
334 (pf_queue_id
<< I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT
) |
335 (1 << I40E_QINT_RQCTL_CAUSE_ENA_SHIFT
) |
336 (itr_idx
<< I40E_QINT_RQCTL_ITR_INDX_SHIFT
);
337 wr32(hw
, reg_idx
, reg
);
345 * i40e_config_vsi_tx_queue
346 * @vf: pointer to the VF info
347 * @vsi_id: id of VSI as provided by the FW
348 * @vsi_queue_id: vsi relative queue index
349 * @info: config. info
353 static int i40e_config_vsi_tx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
355 struct i40e_virtchnl_txq_info
*info
)
357 struct i40e_pf
*pf
= vf
->pf
;
358 struct i40e_hw
*hw
= &pf
->hw
;
359 struct i40e_hmc_obj_txq tx_ctx
;
360 struct i40e_vsi
*vsi
;
365 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
366 vsi
= i40e_find_vsi_from_id(pf
, vsi_id
);
368 /* clear the context structure first */
369 memset(&tx_ctx
, 0, sizeof(struct i40e_hmc_obj_txq
));
371 /* only set the required fields */
372 tx_ctx
.base
= info
->dma_ring_addr
/ 128;
373 tx_ctx
.qlen
= info
->ring_len
;
374 tx_ctx
.rdylist
= le16_to_cpu(vsi
->info
.qs_handle
[0]);
375 tx_ctx
.rdylist_act
= 0;
376 tx_ctx
.head_wb_ena
= info
->headwb_enabled
;
377 tx_ctx
.head_wb_addr
= info
->dma_headwb_addr
;
379 /* clear the context in the HMC */
380 ret
= i40e_clear_lan_tx_queue_context(hw
, pf_queue_id
);
382 dev_err(&pf
->pdev
->dev
,
383 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
389 /* set the context in the HMC */
390 ret
= i40e_set_lan_tx_queue_context(hw
, pf_queue_id
, &tx_ctx
);
392 dev_err(&pf
->pdev
->dev
,
393 "Failed to set VF LAN Tx queue context %d error: %d\n",
399 /* associate this queue with the PCI VF function */
400 qtx_ctl
= I40E_QTX_CTL_VF_QUEUE
;
401 qtx_ctl
|= ((hw
->pf_id
<< I40E_QTX_CTL_PF_INDX_SHIFT
)
402 & I40E_QTX_CTL_PF_INDX_MASK
);
403 qtx_ctl
|= (((vf
->vf_id
+ hw
->func_caps
.vf_base_id
)
404 << I40E_QTX_CTL_VFVM_INDX_SHIFT
)
405 & I40E_QTX_CTL_VFVM_INDX_MASK
);
406 wr32(hw
, I40E_QTX_CTL(pf_queue_id
), qtx_ctl
);
414 * i40e_config_vsi_rx_queue
415 * @vf: pointer to the VF info
416 * @vsi_id: id of VSI as provided by the FW
417 * @vsi_queue_id: vsi relative queue index
418 * @info: config. info
422 static int i40e_config_vsi_rx_queue(struct i40e_vf
*vf
, u16 vsi_id
,
424 struct i40e_virtchnl_rxq_info
*info
)
426 struct i40e_pf
*pf
= vf
->pf
;
427 struct i40e_hw
*hw
= &pf
->hw
;
428 struct i40e_hmc_obj_rxq rx_ctx
;
432 pf_queue_id
= i40e_vc_get_pf_queue_id(vf
, vsi_id
, vsi_queue_id
);
434 /* clear the context structure first */
435 memset(&rx_ctx
, 0, sizeof(struct i40e_hmc_obj_rxq
));
437 /* only set the required fields */
438 rx_ctx
.base
= info
->dma_ring_addr
/ 128;
439 rx_ctx
.qlen
= info
->ring_len
;
441 if (info
->splithdr_enabled
) {
442 rx_ctx
.hsplit_0
= I40E_RX_SPLIT_L2
|
444 I40E_RX_SPLIT_TCP_UDP
|
446 /* header length validation */
447 if (info
->hdr_size
> ((2 * 1024) - 64)) {
451 rx_ctx
.hbuff
= info
->hdr_size
>> I40E_RXQ_CTX_HBUFF_SHIFT
;
453 /* set splitalways mode 10b */
457 /* databuffer length validation */
458 if (info
->databuffer_size
> ((16 * 1024) - 128)) {
462 rx_ctx
.dbuff
= info
->databuffer_size
>> I40E_RXQ_CTX_DBUFF_SHIFT
;
464 /* max pkt. length validation */
465 if (info
->max_pkt_size
>= (16 * 1024) || info
->max_pkt_size
< 64) {
469 rx_ctx
.rxmax
= info
->max_pkt_size
;
471 /* enable 32bytes desc always */
475 rx_ctx
.lrxqthresh
= 2;
480 /* clear the context in the HMC */
481 ret
= i40e_clear_lan_rx_queue_context(hw
, pf_queue_id
);
483 dev_err(&pf
->pdev
->dev
,
484 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
490 /* set the context in the HMC */
491 ret
= i40e_set_lan_rx_queue_context(hw
, pf_queue_id
, &rx_ctx
);
493 dev_err(&pf
->pdev
->dev
,
494 "Failed to set VF LAN Rx queue context %d error: %d\n",
506 * @vf: pointer to the VF info
507 * @type: type of VSI to allocate
509 * alloc VF vsi context & resources
511 static int i40e_alloc_vsi_res(struct i40e_vf
*vf
, enum i40e_vsi_type type
)
513 struct i40e_mac_filter
*f
= NULL
;
514 struct i40e_pf
*pf
= vf
->pf
;
515 struct i40e_vsi
*vsi
;
518 vsi
= i40e_vsi_setup(pf
, type
, pf
->vsi
[pf
->lan_vsi
]->seid
, vf
->vf_id
);
521 dev_err(&pf
->pdev
->dev
,
522 "add vsi failed for VF %d, aq_err %d\n",
523 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
525 goto error_alloc_vsi_res
;
527 if (type
== I40E_VSI_SRIOV
) {
528 u8 brdcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
529 vf
->lan_vsi_idx
= vsi
->idx
;
530 vf
->lan_vsi_id
= vsi
->id
;
531 /* If the port VLAN has been configured and then the
532 * VF driver was removed then the VSI port VLAN
533 * configuration was destroyed. Check if there is
534 * a port VLAN and restore the VSI configuration if
537 if (vf
->port_vlan_id
)
538 i40e_vsi_add_pvid(vsi
, vf
->port_vlan_id
);
539 f
= i40e_add_filter(vsi
, vf
->default_lan_addr
.addr
,
540 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
543 dev_info(&pf
->pdev
->dev
,
544 "Could not allocate VF MAC addr\n");
545 f
= i40e_add_filter(vsi
, brdcast
,
546 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
549 dev_info(&pf
->pdev
->dev
,
550 "Could not allocate VF broadcast filter\n");
553 /* program mac filter */
554 ret
= i40e_sync_vsi_filters(vsi
);
556 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
558 /* Set VF bandwidth if specified */
560 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
561 vf
->tx_rate
/ 50, 0, NULL
);
563 dev_err(&pf
->pdev
->dev
, "Unable to set tx rate, VF %d, error code %d.\n",
572 * i40e_enable_vf_mappings
573 * @vf: pointer to the VF info
577 static void i40e_enable_vf_mappings(struct i40e_vf
*vf
)
579 struct i40e_pf
*pf
= vf
->pf
;
580 struct i40e_hw
*hw
= &pf
->hw
;
581 u32 reg
, total_queue_pairs
= 0;
584 /* Tell the hardware we're using noncontiguous mapping. HW requires
585 * that VF queues be mapped using this method, even when they are
586 * contiguous in real life
588 wr32(hw
, I40E_VSILAN_QBASE(vf
->lan_vsi_id
),
589 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK
);
591 /* enable VF vplan_qtable mappings */
592 reg
= I40E_VPLAN_MAPENA_TXRX_ENA_MASK
;
593 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), reg
);
595 /* map PF queues to VF queues */
596 for (j
= 0; j
< pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
; j
++) {
597 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
, j
);
598 reg
= (qid
& I40E_VPLAN_QTABLE_QINDEX_MASK
);
599 wr32(hw
, I40E_VPLAN_QTABLE(total_queue_pairs
, vf
->vf_id
), reg
);
603 /* map PF queues to VSI */
604 for (j
= 0; j
< 7; j
++) {
605 if (j
* 2 >= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
) {
606 reg
= 0x07FF07FF; /* unused */
608 u16 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
611 qid
= i40e_vc_get_pf_queue_id(vf
, vf
->lan_vsi_id
,
615 wr32(hw
, I40E_VSILAN_QTABLE(j
, vf
->lan_vsi_id
), reg
);
622 * i40e_disable_vf_mappings
623 * @vf: pointer to the VF info
625 * disable VF mappings
627 static void i40e_disable_vf_mappings(struct i40e_vf
*vf
)
629 struct i40e_pf
*pf
= vf
->pf
;
630 struct i40e_hw
*hw
= &pf
->hw
;
633 /* disable qp mappings */
634 wr32(hw
, I40E_VPLAN_MAPENA(vf
->vf_id
), 0);
635 for (i
= 0; i
< I40E_MAX_VSI_QP
; i
++)
636 wr32(hw
, I40E_VPLAN_QTABLE(i
, vf
->vf_id
),
637 I40E_QUEUE_END_OF_LIST
);
643 * @vf: pointer to the VF info
647 static void i40e_free_vf_res(struct i40e_vf
*vf
)
649 struct i40e_pf
*pf
= vf
->pf
;
650 struct i40e_hw
*hw
= &pf
->hw
;
654 /* free vsi & disconnect it from the parent uplink */
655 if (vf
->lan_vsi_idx
) {
656 i40e_vsi_release(pf
->vsi
[vf
->lan_vsi_idx
]);
660 msix_vf
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
662 /* disable interrupts so the VF starts in a known state */
663 for (i
= 0; i
< msix_vf
; i
++) {
664 /* format is same for both registers */
666 reg_idx
= I40E_VFINT_DYN_CTL0(vf
->vf_id
);
668 reg_idx
= I40E_VFINT_DYN_CTLN(((msix_vf
- 1) *
671 wr32(hw
, reg_idx
, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK
);
675 /* clear the irq settings */
676 for (i
= 0; i
< msix_vf
; i
++) {
677 /* format is same for both registers */
679 reg_idx
= I40E_VPINT_LNKLST0(vf
->vf_id
);
681 reg_idx
= I40E_VPINT_LNKLSTN(((msix_vf
- 1) *
684 reg
= (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK
|
685 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK
);
686 wr32(hw
, reg_idx
, reg
);
689 /* reset some of the state varibles keeping
690 * track of the resources
692 vf
->num_queue_pairs
= 0;
698 * @vf: pointer to the VF info
700 * allocate VF resources
702 static int i40e_alloc_vf_res(struct i40e_vf
*vf
)
704 struct i40e_pf
*pf
= vf
->pf
;
705 int total_queue_pairs
= 0;
708 /* allocate hw vsi context & associated resources */
709 ret
= i40e_alloc_vsi_res(vf
, I40E_VSI_SRIOV
);
712 total_queue_pairs
+= pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
713 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
);
715 /* store the total qps number for the runtime
718 vf
->num_queue_pairs
= total_queue_pairs
;
720 /* VF is now completely initialized */
721 set_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
);
725 i40e_free_vf_res(vf
);
730 #define VF_DEVICE_STATUS 0xAA
731 #define VF_TRANS_PENDING_MASK 0x20
733 * i40e_quiesce_vf_pci
734 * @vf: pointer to the VF structure
736 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
737 * if the transactions never clear.
739 static int i40e_quiesce_vf_pci(struct i40e_vf
*vf
)
741 struct i40e_pf
*pf
= vf
->pf
;
742 struct i40e_hw
*hw
= &pf
->hw
;
746 vf_abs_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
748 wr32(hw
, I40E_PF_PCI_CIAA
,
749 VF_DEVICE_STATUS
| (vf_abs_id
<< I40E_PF_PCI_CIAA_VF_NUM_SHIFT
));
750 for (i
= 0; i
< 100; i
++) {
751 reg
= rd32(hw
, I40E_PF_PCI_CIAD
);
752 if ((reg
& VF_TRANS_PENDING_MASK
) == 0)
761 * @vf: pointer to the VF structure
762 * @flr: VFLR was issued or not
766 void i40e_reset_vf(struct i40e_vf
*vf
, bool flr
)
768 struct i40e_pf
*pf
= vf
->pf
;
769 struct i40e_hw
*hw
= &pf
->hw
;
774 if (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
778 clear_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
780 /* In the case of a VFLR, the HW has already reset the VF and we
781 * just need to clean up, so don't hit the VFRTRIG register.
784 /* reset VF using VPGEN_VFRTRIG reg */
785 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
786 reg
|= I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
787 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
791 if (i40e_quiesce_vf_pci(vf
))
792 dev_err(&pf
->pdev
->dev
, "VF %d PCI transactions stuck\n",
795 /* poll VPGEN_VFRSTAT reg to make sure
796 * that reset is complete
798 for (i
= 0; i
< 10; i
++) {
799 /* VF reset requires driver to first reset the VF and then
800 * poll the status register to make sure that the reset
801 * completed successfully. Due to internal HW FIFO flushes,
802 * we must wait 10ms before the register will be valid.
804 usleep_range(10000, 20000);
805 reg
= rd32(hw
, I40E_VPGEN_VFRSTAT(vf
->vf_id
));
806 if (reg
& I40E_VPGEN_VFRSTAT_VFRD_MASK
) {
813 usleep_range(10000, 20000);
816 dev_err(&pf
->pdev
->dev
, "VF reset check timeout on VF %d\n",
818 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_COMPLETED
);
819 /* clear the reset bit in the VPGEN_VFRTRIG reg */
820 reg
= rd32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
));
821 reg
&= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK
;
822 wr32(hw
, I40E_VPGEN_VFRTRIG(vf
->vf_id
), reg
);
824 /* On initial reset, we won't have any queues */
825 if (vf
->lan_vsi_idx
== 0)
828 i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false);
830 /* reallocate VF resources to reset the VSI state */
831 i40e_free_vf_res(vf
);
832 i40e_alloc_vf_res(vf
);
833 i40e_enable_vf_mappings(vf
);
834 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
835 clear_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
837 /* tell the VF the reset is done */
838 wr32(hw
, I40E_VFGEN_RSTAT1(vf
->vf_id
), I40E_VFR_VFACTIVE
);
840 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
845 * @pf: pointer to the PF structure
849 void i40e_free_vfs(struct i40e_pf
*pf
)
851 struct i40e_hw
*hw
= &pf
->hw
;
852 u32 reg_idx
, bit_idx
;
857 while (test_and_set_bit(__I40E_VF_DISABLE
, &pf
->state
))
858 usleep_range(1000, 2000);
860 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
861 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
862 i40e_vsi_control_rings(pf
->vsi
[pf
->vf
[i
].lan_vsi_idx
],
865 /* Disable IOV before freeing resources. This lets any VF drivers
866 * running in the host get themselves cleaned up before we yank
867 * the carpet out from underneath their feet.
869 if (!pci_vfs_assigned(pf
->pdev
))
870 pci_disable_sriov(pf
->pdev
);
872 dev_warn(&pf
->pdev
->dev
, "VFs are assigned - not disabling SR-IOV\n");
874 msleep(20); /* let any messages in transit get finished up */
876 /* free up VF resources */
877 tmp
= pf
->num_alloc_vfs
;
878 pf
->num_alloc_vfs
= 0;
879 for (i
= 0; i
< tmp
; i
++) {
880 if (test_bit(I40E_VF_STAT_INIT
, &pf
->vf
[i
].vf_states
))
881 i40e_free_vf_res(&pf
->vf
[i
]);
882 /* disable qp mappings */
883 i40e_disable_vf_mappings(&pf
->vf
[i
]);
889 /* This check is for when the driver is unloaded while VFs are
890 * assigned. Setting the number of VFs to 0 through sysfs is caught
891 * before this function ever gets called.
893 if (!pci_vfs_assigned(pf
->pdev
)) {
894 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
895 * work correctly when SR-IOV gets re-enabled.
897 for (vf_id
= 0; vf_id
< tmp
; vf_id
++) {
898 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
899 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
900 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), (1 << bit_idx
));
903 clear_bit(__I40E_VF_DISABLE
, &pf
->state
);
906 #ifdef CONFIG_PCI_IOV
909 * @pf: pointer to the PF structure
910 * @num_alloc_vfs: number of VFs to allocate
912 * allocate VF resources
914 int i40e_alloc_vfs(struct i40e_pf
*pf
, u16 num_alloc_vfs
)
919 /* Disable interrupt 0 so we don't try to handle the VFLR. */
920 i40e_irq_dynamic_disable_icr0(pf
);
922 /* Check to see if we're just allocating resources for extant VFs */
923 if (pci_num_vf(pf
->pdev
) != num_alloc_vfs
) {
924 ret
= pci_enable_sriov(pf
->pdev
, num_alloc_vfs
);
926 dev_err(&pf
->pdev
->dev
,
927 "Failed to enable SR-IOV, error %d.\n", ret
);
928 pf
->num_alloc_vfs
= 0;
932 /* allocate memory */
933 vfs
= kcalloc(num_alloc_vfs
, sizeof(struct i40e_vf
), GFP_KERNEL
);
940 /* apply default profile */
941 for (i
= 0; i
< num_alloc_vfs
; i
++) {
943 vfs
[i
].parent_type
= I40E_SWITCH_ELEMENT_TYPE_VEB
;
946 /* assign default capabilities */
947 set_bit(I40E_VIRTCHNL_VF_CAP_L2
, &vfs
[i
].vf_caps
);
948 vfs
[i
].spoofchk
= true;
949 /* VF resources get allocated during reset */
950 i40e_reset_vf(&vfs
[i
], false);
952 /* enable VF vplan_qtable mappings */
953 i40e_enable_vf_mappings(&vfs
[i
]);
955 pf
->num_alloc_vfs
= num_alloc_vfs
;
961 /* Re-enable interrupt 0. */
962 i40e_irq_dynamic_enable_icr0(pf
);
968 * i40e_pci_sriov_enable
969 * @pdev: pointer to a pci_dev structure
970 * @num_vfs: number of VFs to allocate
972 * Enable or change the number of VFs
974 static int i40e_pci_sriov_enable(struct pci_dev
*pdev
, int num_vfs
)
976 #ifdef CONFIG_PCI_IOV
977 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
978 int pre_existing_vfs
= pci_num_vf(pdev
);
981 if (pf
->state
& __I40E_TESTING
) {
983 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
988 dev_info(&pdev
->dev
, "Allocating %d VFs.\n", num_vfs
);
989 if (pre_existing_vfs
&& pre_existing_vfs
!= num_vfs
)
991 else if (pre_existing_vfs
&& pre_existing_vfs
== num_vfs
)
994 if (num_vfs
> pf
->num_req_vfs
) {
999 err
= i40e_alloc_vfs(pf
, num_vfs
);
1001 dev_warn(&pdev
->dev
, "Failed to enable SR-IOV: %d\n", err
);
1015 * i40e_pci_sriov_configure
1016 * @pdev: pointer to a pci_dev structure
1017 * @num_vfs: number of VFs to allocate
1019 * Enable or change the number of VFs. Called when the user updates the number
1022 int i40e_pci_sriov_configure(struct pci_dev
*pdev
, int num_vfs
)
1024 struct i40e_pf
*pf
= pci_get_drvdata(pdev
);
1027 if (!(pf
->flags
& I40E_FLAG_VEB_MODE_ENABLED
)) {
1028 pf
->flags
|= I40E_FLAG_VEB_MODE_ENABLED
;
1029 i40e_do_reset_safe(pf
,
1030 BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1032 return i40e_pci_sriov_enable(pdev
, num_vfs
);
1035 if (!pci_vfs_assigned(pf
->pdev
)) {
1037 pf
->flags
&= ~I40E_FLAG_VEB_MODE_ENABLED
;
1038 i40e_do_reset_safe(pf
, BIT_ULL(__I40E_PF_RESET_REQUESTED
));
1040 dev_warn(&pdev
->dev
, "Unable to free VFs because some are assigned to VMs.\n");
1046 /***********************virtual channel routines******************/
1049 * i40e_vc_send_msg_to_vf
1050 * @vf: pointer to the VF info
1051 * @v_opcode: virtual channel opcode
1052 * @v_retval: virtual channel return value
1053 * @msg: pointer to the msg buffer
1054 * @msglen: msg length
1058 static int i40e_vc_send_msg_to_vf(struct i40e_vf
*vf
, u32 v_opcode
,
1059 u32 v_retval
, u8
*msg
, u16 msglen
)
1066 /* validate the request */
1067 if (!vf
|| vf
->vf_id
>= vf
->pf
->num_alloc_vfs
)
1072 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
1074 /* single place to detect unsuccessful return values */
1076 vf
->num_invalid_msgs
++;
1077 dev_err(&pf
->pdev
->dev
, "Failed opcode %d Error: %d\n",
1078 v_opcode
, v_retval
);
1079 if (vf
->num_invalid_msgs
>
1080 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED
) {
1081 dev_err(&pf
->pdev
->dev
,
1082 "Number of invalid messages exceeded for VF %d\n",
1084 dev_err(&pf
->pdev
->dev
, "Use PF Control I/F to enable the VF\n");
1085 set_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
);
1088 vf
->num_valid_msgs
++;
1091 aq_ret
= i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, v_opcode
, v_retval
,
1094 dev_err(&pf
->pdev
->dev
,
1095 "Unable to send the message to VF %d aq_err %d\n",
1096 vf
->vf_id
, pf
->hw
.aq
.asq_last_status
);
1104 * i40e_vc_send_resp_to_vf
1105 * @vf: pointer to the VF info
1106 * @opcode: operation code
1107 * @retval: return value
1109 * send resp msg to VF
1111 static int i40e_vc_send_resp_to_vf(struct i40e_vf
*vf
,
1112 enum i40e_virtchnl_ops opcode
,
1115 return i40e_vc_send_msg_to_vf(vf
, opcode
, retval
, NULL
, 0);
1119 * i40e_vc_get_version_msg
1120 * @vf: pointer to the VF info
1122 * called from the VF to request the API version used by the PF
1124 static int i40e_vc_get_version_msg(struct i40e_vf
*vf
)
1126 struct i40e_virtchnl_version_info info
= {
1127 I40E_VIRTCHNL_VERSION_MAJOR
, I40E_VIRTCHNL_VERSION_MINOR
1130 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_VERSION
,
1131 I40E_SUCCESS
, (u8
*)&info
,
1133 i40e_virtchnl_version_info
));
1137 * i40e_vc_get_vf_resources_msg
1138 * @vf: pointer to the VF info
1139 * @msg: pointer to the msg buffer
1140 * @msglen: msg length
1142 * called from the VF to request its resources
1144 static int i40e_vc_get_vf_resources_msg(struct i40e_vf
*vf
)
1146 struct i40e_virtchnl_vf_resource
*vfres
= NULL
;
1147 struct i40e_pf
*pf
= vf
->pf
;
1148 i40e_status aq_ret
= 0;
1149 struct i40e_vsi
*vsi
;
1154 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
1155 aq_ret
= I40E_ERR_PARAM
;
1159 len
= (sizeof(struct i40e_virtchnl_vf_resource
) +
1160 sizeof(struct i40e_virtchnl_vsi_resource
) * num_vsis
);
1162 vfres
= kzalloc(len
, GFP_KERNEL
);
1164 aq_ret
= I40E_ERR_NO_MEMORY
;
1169 vfres
->vf_offload_flags
= I40E_VIRTCHNL_VF_OFFLOAD_L2
;
1170 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1171 if (!vsi
->info
.pvid
)
1172 vfres
->vf_offload_flags
|= I40E_VIRTCHNL_VF_OFFLOAD_VLAN
;
1174 vfres
->num_vsis
= num_vsis
;
1175 vfres
->num_queue_pairs
= vf
->num_queue_pairs
;
1176 vfres
->max_vectors
= pf
->hw
.func_caps
.num_msix_vectors_vf
;
1177 if (vf
->lan_vsi_idx
) {
1178 vfres
->vsi_res
[i
].vsi_id
= vf
->lan_vsi_id
;
1179 vfres
->vsi_res
[i
].vsi_type
= I40E_VSI_SRIOV
;
1180 vfres
->vsi_res
[i
].num_queue_pairs
=
1181 pf
->vsi
[vf
->lan_vsi_idx
]->alloc_queue_pairs
;
1182 memcpy(vfres
->vsi_res
[i
].default_mac_addr
,
1183 vf
->default_lan_addr
.addr
, ETH_ALEN
);
1186 set_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
);
1189 /* send the response back to the VF */
1190 ret
= i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
1191 aq_ret
, (u8
*)vfres
, len
);
1198 * i40e_vc_reset_vf_msg
1199 * @vf: pointer to the VF info
1200 * @msg: pointer to the msg buffer
1201 * @msglen: msg length
1203 * called from the VF to reset itself,
1204 * unlike other virtchnl messages, PF driver
1205 * doesn't send the response back to the VF
1207 static void i40e_vc_reset_vf_msg(struct i40e_vf
*vf
)
1209 if (test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
))
1210 i40e_reset_vf(vf
, false);
1214 * i40e_vc_config_promiscuous_mode_msg
1215 * @vf: pointer to the VF info
1216 * @msg: pointer to the msg buffer
1217 * @msglen: msg length
1219 * called from the VF to configure the promiscuous mode of
1222 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf
*vf
,
1223 u8
*msg
, u16 msglen
)
1225 struct i40e_virtchnl_promisc_info
*info
=
1226 (struct i40e_virtchnl_promisc_info
*)msg
;
1227 struct i40e_pf
*pf
= vf
->pf
;
1228 struct i40e_hw
*hw
= &pf
->hw
;
1229 struct i40e_vsi
*vsi
;
1230 bool allmulti
= false;
1233 vsi
= i40e_find_vsi_from_id(pf
, info
->vsi_id
);
1234 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1235 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1236 !i40e_vc_isvalid_vsi_id(vf
, info
->vsi_id
) ||
1237 (vsi
->type
!= I40E_VSI_FCOE
)) {
1238 aq_ret
= I40E_ERR_PARAM
;
1241 if (info
->flags
& I40E_FLAG_VF_MULTICAST_PROMISC
)
1243 aq_ret
= i40e_aq_set_vsi_multicast_promiscuous(hw
, vsi
->seid
,
1247 /* send the response to the VF */
1248 return i40e_vc_send_resp_to_vf(vf
,
1249 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
1254 * i40e_vc_config_queues_msg
1255 * @vf: pointer to the VF info
1256 * @msg: pointer to the msg buffer
1257 * @msglen: msg length
1259 * called from the VF to configure the rx/tx
1262 static int i40e_vc_config_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1264 struct i40e_virtchnl_vsi_queue_config_info
*qci
=
1265 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1266 struct i40e_virtchnl_queue_pair_info
*qpi
;
1267 struct i40e_pf
*pf
= vf
->pf
;
1268 u16 vsi_id
, vsi_queue_id
;
1269 i40e_status aq_ret
= 0;
1272 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1273 aq_ret
= I40E_ERR_PARAM
;
1277 vsi_id
= qci
->vsi_id
;
1278 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1279 aq_ret
= I40E_ERR_PARAM
;
1282 for (i
= 0; i
< qci
->num_queue_pairs
; i
++) {
1283 qpi
= &qci
->qpair
[i
];
1284 vsi_queue_id
= qpi
->txq
.queue_id
;
1285 if ((qpi
->txq
.vsi_id
!= vsi_id
) ||
1286 (qpi
->rxq
.vsi_id
!= vsi_id
) ||
1287 (qpi
->rxq
.queue_id
!= vsi_queue_id
) ||
1288 !i40e_vc_isvalid_queue_id(vf
, vsi_id
, vsi_queue_id
)) {
1289 aq_ret
= I40E_ERR_PARAM
;
1293 if (i40e_config_vsi_rx_queue(vf
, vsi_id
, vsi_queue_id
,
1295 i40e_config_vsi_tx_queue(vf
, vsi_id
, vsi_queue_id
,
1297 aq_ret
= I40E_ERR_PARAM
;
1301 /* set vsi num_queue_pairs in use to num configured by VF */
1302 pf
->vsi
[vf
->lan_vsi_idx
]->num_queue_pairs
= qci
->num_queue_pairs
;
1305 /* send the response to the VF */
1306 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
1311 * i40e_vc_config_irq_map_msg
1312 * @vf: pointer to the VF info
1313 * @msg: pointer to the msg buffer
1314 * @msglen: msg length
1316 * called from the VF to configure the irq to
1319 static int i40e_vc_config_irq_map_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1321 struct i40e_virtchnl_irq_map_info
*irqmap_info
=
1322 (struct i40e_virtchnl_irq_map_info
*)msg
;
1323 struct i40e_virtchnl_vector_map
*map
;
1324 u16 vsi_id
, vsi_queue_id
, vector_id
;
1325 i40e_status aq_ret
= 0;
1326 unsigned long tempmap
;
1329 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1330 aq_ret
= I40E_ERR_PARAM
;
1334 for (i
= 0; i
< irqmap_info
->num_vectors
; i
++) {
1335 map
= &irqmap_info
->vecmap
[i
];
1337 vector_id
= map
->vector_id
;
1338 vsi_id
= map
->vsi_id
;
1339 /* validate msg params */
1340 if (!i40e_vc_isvalid_vector_id(vf
, vector_id
) ||
1341 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1342 aq_ret
= I40E_ERR_PARAM
;
1346 /* lookout for the invalid queue index */
1347 tempmap
= map
->rxq_map
;
1348 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1349 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1351 aq_ret
= I40E_ERR_PARAM
;
1356 tempmap
= map
->txq_map
;
1357 for_each_set_bit(vsi_queue_id
, &tempmap
, I40E_MAX_VSI_QP
) {
1358 if (!i40e_vc_isvalid_queue_id(vf
, vsi_id
,
1360 aq_ret
= I40E_ERR_PARAM
;
1365 i40e_config_irq_link_list(vf
, vsi_id
, map
);
1368 /* send the response to the VF */
1369 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
1374 * i40e_vc_enable_queues_msg
1375 * @vf: pointer to the VF info
1376 * @msg: pointer to the msg buffer
1377 * @msglen: msg length
1379 * called from the VF to enable all or specific queue(s)
1381 static int i40e_vc_enable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1383 struct i40e_virtchnl_queue_select
*vqs
=
1384 (struct i40e_virtchnl_queue_select
*)msg
;
1385 struct i40e_pf
*pf
= vf
->pf
;
1386 u16 vsi_id
= vqs
->vsi_id
;
1387 i40e_status aq_ret
= 0;
1389 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1390 aq_ret
= I40E_ERR_PARAM
;
1394 if (!i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1395 aq_ret
= I40E_ERR_PARAM
;
1399 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1400 aq_ret
= I40E_ERR_PARAM
;
1404 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], true))
1405 aq_ret
= I40E_ERR_TIMEOUT
;
1407 /* send the response to the VF */
1408 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
1413 * i40e_vc_disable_queues_msg
1414 * @vf: pointer to the VF info
1415 * @msg: pointer to the msg buffer
1416 * @msglen: msg length
1418 * called from the VF to disable all or specific
1421 static int i40e_vc_disable_queues_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1423 struct i40e_virtchnl_queue_select
*vqs
=
1424 (struct i40e_virtchnl_queue_select
*)msg
;
1425 struct i40e_pf
*pf
= vf
->pf
;
1426 i40e_status aq_ret
= 0;
1428 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1429 aq_ret
= I40E_ERR_PARAM
;
1433 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1434 aq_ret
= I40E_ERR_PARAM
;
1438 if ((0 == vqs
->rx_queues
) && (0 == vqs
->tx_queues
)) {
1439 aq_ret
= I40E_ERR_PARAM
;
1443 if (i40e_vsi_control_rings(pf
->vsi
[vf
->lan_vsi_idx
], false))
1444 aq_ret
= I40E_ERR_TIMEOUT
;
1447 /* send the response to the VF */
1448 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
1453 * i40e_vc_get_stats_msg
1454 * @vf: pointer to the VF info
1455 * @msg: pointer to the msg buffer
1456 * @msglen: msg length
1458 * called from the VF to get vsi stats
1460 static int i40e_vc_get_stats_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1462 struct i40e_virtchnl_queue_select
*vqs
=
1463 (struct i40e_virtchnl_queue_select
*)msg
;
1464 struct i40e_pf
*pf
= vf
->pf
;
1465 struct i40e_eth_stats stats
;
1466 i40e_status aq_ret
= 0;
1467 struct i40e_vsi
*vsi
;
1469 memset(&stats
, 0, sizeof(struct i40e_eth_stats
));
1471 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
)) {
1472 aq_ret
= I40E_ERR_PARAM
;
1476 if (!i40e_vc_isvalid_vsi_id(vf
, vqs
->vsi_id
)) {
1477 aq_ret
= I40E_ERR_PARAM
;
1481 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1483 aq_ret
= I40E_ERR_PARAM
;
1486 i40e_update_eth_stats(vsi
);
1487 stats
= vsi
->eth_stats
;
1490 /* send the response back to the VF */
1491 return i40e_vc_send_msg_to_vf(vf
, I40E_VIRTCHNL_OP_GET_STATS
, aq_ret
,
1492 (u8
*)&stats
, sizeof(stats
));
1496 * i40e_check_vf_permission
1497 * @vf: pointer to the VF info
1498 * @macaddr: pointer to the MAC Address being checked
1500 * Check if the VF has permission to add or delete unicast MAC address
1501 * filters and return error code -EPERM if not. Then check if the
1502 * address filter requested is broadcast or zero and if so return
1503 * an invalid MAC address error code.
1505 static inline int i40e_check_vf_permission(struct i40e_vf
*vf
, u8
*macaddr
)
1507 struct i40e_pf
*pf
= vf
->pf
;
1510 if (is_broadcast_ether_addr(macaddr
) ||
1511 is_zero_ether_addr(macaddr
)) {
1512 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n", macaddr
);
1513 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1514 } else if (vf
->pf_set_mac
&& !is_multicast_ether_addr(macaddr
) &&
1515 !ether_addr_equal(macaddr
, vf
->default_lan_addr
.addr
)) {
1516 /* If the host VMM administrator has set the VF MAC address
1517 * administratively via the ndo_set_vf_mac command then deny
1518 * permission to the VF to add or delete unicast MAC addresses.
1519 * The VF may request to set the MAC address filter already
1520 * assigned to it so do not return an error in that case.
1522 dev_err(&pf
->pdev
->dev
,
1523 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1530 * i40e_vc_add_mac_addr_msg
1531 * @vf: pointer to the VF info
1532 * @msg: pointer to the msg buffer
1533 * @msglen: msg length
1535 * add guest mac address filter
1537 static int i40e_vc_add_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1539 struct i40e_virtchnl_ether_addr_list
*al
=
1540 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1541 struct i40e_pf
*pf
= vf
->pf
;
1542 struct i40e_vsi
*vsi
= NULL
;
1543 u16 vsi_id
= al
->vsi_id
;
1544 i40e_status ret
= 0;
1547 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1548 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1549 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1550 ret
= I40E_ERR_PARAM
;
1554 for (i
= 0; i
< al
->num_elements
; i
++) {
1555 ret
= i40e_check_vf_permission(vf
, al
->list
[i
].addr
);
1559 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1561 /* add new addresses to the list */
1562 for (i
= 0; i
< al
->num_elements
; i
++) {
1563 struct i40e_mac_filter
*f
;
1565 f
= i40e_find_mac(vsi
, al
->list
[i
].addr
, true, false);
1567 if (i40e_is_vsi_in_vlan(vsi
))
1568 f
= i40e_put_mac_in_vlan(vsi
, al
->list
[i
].addr
,
1571 f
= i40e_add_filter(vsi
, al
->list
[i
].addr
, -1,
1576 dev_err(&pf
->pdev
->dev
,
1577 "Unable to add VF MAC filter\n");
1578 ret
= I40E_ERR_PARAM
;
1583 /* program the updated filter list */
1584 if (i40e_sync_vsi_filters(vsi
))
1585 dev_err(&pf
->pdev
->dev
, "Unable to program VF MAC filters\n");
1588 /* send the response to the VF */
1589 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
1594 * i40e_vc_del_mac_addr_msg
1595 * @vf: pointer to the VF info
1596 * @msg: pointer to the msg buffer
1597 * @msglen: msg length
1599 * remove guest mac address filter
1601 static int i40e_vc_del_mac_addr_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1603 struct i40e_virtchnl_ether_addr_list
*al
=
1604 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1605 struct i40e_pf
*pf
= vf
->pf
;
1606 struct i40e_vsi
*vsi
= NULL
;
1607 u16 vsi_id
= al
->vsi_id
;
1608 i40e_status ret
= 0;
1611 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1612 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1613 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1614 ret
= I40E_ERR_PARAM
;
1618 for (i
= 0; i
< al
->num_elements
; i
++) {
1619 if (is_broadcast_ether_addr(al
->list
[i
].addr
) ||
1620 is_zero_ether_addr(al
->list
[i
].addr
)) {
1621 dev_err(&pf
->pdev
->dev
, "invalid VF MAC addr %pM\n",
1623 ret
= I40E_ERR_INVALID_MAC_ADDR
;
1627 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1629 /* delete addresses from the list */
1630 for (i
= 0; i
< al
->num_elements
; i
++)
1631 i40e_del_filter(vsi
, al
->list
[i
].addr
,
1632 I40E_VLAN_ANY
, true, false);
1634 /* program the updated filter list */
1635 if (i40e_sync_vsi_filters(vsi
))
1636 dev_err(&pf
->pdev
->dev
, "Unable to program VF MAC filters\n");
1639 /* send the response to the VF */
1640 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
1645 * i40e_vc_add_vlan_msg
1646 * @vf: pointer to the VF info
1647 * @msg: pointer to the msg buffer
1648 * @msglen: msg length
1650 * program guest vlan id
1652 static int i40e_vc_add_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1654 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1655 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1656 struct i40e_pf
*pf
= vf
->pf
;
1657 struct i40e_vsi
*vsi
= NULL
;
1658 u16 vsi_id
= vfl
->vsi_id
;
1659 i40e_status aq_ret
= 0;
1662 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1663 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1664 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1665 aq_ret
= I40E_ERR_PARAM
;
1669 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1670 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1671 aq_ret
= I40E_ERR_PARAM
;
1672 dev_err(&pf
->pdev
->dev
,
1673 "invalid VF VLAN id %d\n", vfl
->vlan_id
[i
]);
1677 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1678 if (vsi
->info
.pvid
) {
1679 aq_ret
= I40E_ERR_PARAM
;
1683 i40e_vlan_stripping_enable(vsi
);
1684 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1685 /* add new VLAN filter */
1686 int ret
= i40e_vsi_add_vlan(vsi
, vfl
->vlan_id
[i
]);
1688 dev_err(&pf
->pdev
->dev
,
1689 "Unable to add VF vlan filter %d, error %d\n",
1690 vfl
->vlan_id
[i
], ret
);
1694 /* send the response to the VF */
1695 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_ADD_VLAN
, aq_ret
);
1699 * i40e_vc_remove_vlan_msg
1700 * @vf: pointer to the VF info
1701 * @msg: pointer to the msg buffer
1702 * @msglen: msg length
1704 * remove programmed guest vlan id
1706 static int i40e_vc_remove_vlan_msg(struct i40e_vf
*vf
, u8
*msg
, u16 msglen
)
1708 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1709 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1710 struct i40e_pf
*pf
= vf
->pf
;
1711 struct i40e_vsi
*vsi
= NULL
;
1712 u16 vsi_id
= vfl
->vsi_id
;
1713 i40e_status aq_ret
= 0;
1716 if (!test_bit(I40E_VF_STAT_ACTIVE
, &vf
->vf_states
) ||
1717 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE
, &vf
->vf_caps
) ||
1718 !i40e_vc_isvalid_vsi_id(vf
, vsi_id
)) {
1719 aq_ret
= I40E_ERR_PARAM
;
1723 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1724 if (vfl
->vlan_id
[i
] > I40E_MAX_VLANID
) {
1725 aq_ret
= I40E_ERR_PARAM
;
1730 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
1731 if (vsi
->info
.pvid
) {
1732 aq_ret
= I40E_ERR_PARAM
;
1736 for (i
= 0; i
< vfl
->num_elements
; i
++) {
1737 int ret
= i40e_vsi_kill_vlan(vsi
, vfl
->vlan_id
[i
]);
1739 dev_err(&pf
->pdev
->dev
,
1740 "Unable to delete VF vlan filter %d, error %d\n",
1741 vfl
->vlan_id
[i
], ret
);
1745 /* send the response to the VF */
1746 return i40e_vc_send_resp_to_vf(vf
, I40E_VIRTCHNL_OP_DEL_VLAN
, aq_ret
);
1750 * i40e_vc_validate_vf_msg
1751 * @vf: pointer to the VF info
1752 * @msg: pointer to the msg buffer
1753 * @msglen: msg length
1754 * @msghndl: msg handle
1758 static int i40e_vc_validate_vf_msg(struct i40e_vf
*vf
, u32 v_opcode
,
1759 u32 v_retval
, u8
*msg
, u16 msglen
)
1761 bool err_msg_format
= false;
1764 /* Check if VF is disabled. */
1765 if (test_bit(I40E_VF_STAT_DISABLED
, &vf
->vf_states
))
1766 return I40E_ERR_PARAM
;
1768 /* Validate message length. */
1770 case I40E_VIRTCHNL_OP_VERSION
:
1771 valid_len
= sizeof(struct i40e_virtchnl_version_info
);
1773 case I40E_VIRTCHNL_OP_RESET_VF
:
1774 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1777 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE
:
1778 valid_len
= sizeof(struct i40e_virtchnl_txq_info
);
1780 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE
:
1781 valid_len
= sizeof(struct i40e_virtchnl_rxq_info
);
1783 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1784 valid_len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
);
1785 if (msglen
>= valid_len
) {
1786 struct i40e_virtchnl_vsi_queue_config_info
*vqc
=
1787 (struct i40e_virtchnl_vsi_queue_config_info
*)msg
;
1788 valid_len
+= (vqc
->num_queue_pairs
*
1790 i40e_virtchnl_queue_pair_info
));
1791 if (vqc
->num_queue_pairs
== 0)
1792 err_msg_format
= true;
1795 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1796 valid_len
= sizeof(struct i40e_virtchnl_irq_map_info
);
1797 if (msglen
>= valid_len
) {
1798 struct i40e_virtchnl_irq_map_info
*vimi
=
1799 (struct i40e_virtchnl_irq_map_info
*)msg
;
1800 valid_len
+= (vimi
->num_vectors
*
1801 sizeof(struct i40e_virtchnl_vector_map
));
1802 if (vimi
->num_vectors
== 0)
1803 err_msg_format
= true;
1806 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1807 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1808 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1810 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1811 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1812 valid_len
= sizeof(struct i40e_virtchnl_ether_addr_list
);
1813 if (msglen
>= valid_len
) {
1814 struct i40e_virtchnl_ether_addr_list
*veal
=
1815 (struct i40e_virtchnl_ether_addr_list
*)msg
;
1816 valid_len
+= veal
->num_elements
*
1817 sizeof(struct i40e_virtchnl_ether_addr
);
1818 if (veal
->num_elements
== 0)
1819 err_msg_format
= true;
1822 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1823 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1824 valid_len
= sizeof(struct i40e_virtchnl_vlan_filter_list
);
1825 if (msglen
>= valid_len
) {
1826 struct i40e_virtchnl_vlan_filter_list
*vfl
=
1827 (struct i40e_virtchnl_vlan_filter_list
*)msg
;
1828 valid_len
+= vfl
->num_elements
* sizeof(u16
);
1829 if (vfl
->num_elements
== 0)
1830 err_msg_format
= true;
1833 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1834 valid_len
= sizeof(struct i40e_virtchnl_promisc_info
);
1836 case I40E_VIRTCHNL_OP_GET_STATS
:
1837 valid_len
= sizeof(struct i40e_virtchnl_queue_select
);
1839 /* These are always errors coming from the VF. */
1840 case I40E_VIRTCHNL_OP_EVENT
:
1841 case I40E_VIRTCHNL_OP_UNKNOWN
:
1846 /* few more checks */
1847 if ((valid_len
!= msglen
) || (err_msg_format
)) {
1848 i40e_vc_send_resp_to_vf(vf
, v_opcode
, I40E_ERR_PARAM
);
1856 * i40e_vc_process_vf_msg
1857 * @pf: pointer to the PF structure
1858 * @vf_id: source VF id
1859 * @msg: pointer to the msg buffer
1860 * @msglen: msg length
1861 * @msghndl: msg handle
1863 * called from the common aeq/arq handler to
1864 * process request from VF
1866 int i40e_vc_process_vf_msg(struct i40e_pf
*pf
, u16 vf_id
, u32 v_opcode
,
1867 u32 v_retval
, u8
*msg
, u16 msglen
)
1869 struct i40e_hw
*hw
= &pf
->hw
;
1870 unsigned int local_vf_id
= vf_id
- hw
->func_caps
.vf_base_id
;
1874 pf
->vf_aq_requests
++;
1875 if (local_vf_id
>= pf
->num_alloc_vfs
)
1877 vf
= &(pf
->vf
[local_vf_id
]);
1878 /* perform basic checks on the msg */
1879 ret
= i40e_vc_validate_vf_msg(vf
, v_opcode
, v_retval
, msg
, msglen
);
1882 dev_err(&pf
->pdev
->dev
, "Invalid message from VF %d, opcode %d, len %d\n",
1883 local_vf_id
, v_opcode
, msglen
);
1888 case I40E_VIRTCHNL_OP_VERSION
:
1889 ret
= i40e_vc_get_version_msg(vf
);
1891 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
:
1892 ret
= i40e_vc_get_vf_resources_msg(vf
);
1894 case I40E_VIRTCHNL_OP_RESET_VF
:
1895 i40e_vc_reset_vf_msg(vf
);
1898 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
:
1899 ret
= i40e_vc_config_promiscuous_mode_msg(vf
, msg
, msglen
);
1901 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
1902 ret
= i40e_vc_config_queues_msg(vf
, msg
, msglen
);
1904 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1905 ret
= i40e_vc_config_irq_map_msg(vf
, msg
, msglen
);
1907 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
1908 ret
= i40e_vc_enable_queues_msg(vf
, msg
, msglen
);
1909 i40e_vc_notify_vf_link_state(vf
);
1911 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
1912 ret
= i40e_vc_disable_queues_msg(vf
, msg
, msglen
);
1914 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
1915 ret
= i40e_vc_add_mac_addr_msg(vf
, msg
, msglen
);
1917 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
1918 ret
= i40e_vc_del_mac_addr_msg(vf
, msg
, msglen
);
1920 case I40E_VIRTCHNL_OP_ADD_VLAN
:
1921 ret
= i40e_vc_add_vlan_msg(vf
, msg
, msglen
);
1923 case I40E_VIRTCHNL_OP_DEL_VLAN
:
1924 ret
= i40e_vc_remove_vlan_msg(vf
, msg
, msglen
);
1926 case I40E_VIRTCHNL_OP_GET_STATS
:
1927 ret
= i40e_vc_get_stats_msg(vf
, msg
, msglen
);
1929 case I40E_VIRTCHNL_OP_UNKNOWN
:
1931 dev_err(&pf
->pdev
->dev
, "Unsupported opcode %d from VF %d\n",
1932 v_opcode
, local_vf_id
);
1933 ret
= i40e_vc_send_resp_to_vf(vf
, v_opcode
,
1934 I40E_ERR_NOT_IMPLEMENTED
);
1942 * i40e_vc_process_vflr_event
1943 * @pf: pointer to the PF structure
1945 * called from the vlfr irq handler to
1946 * free up VF resources and state variables
1948 int i40e_vc_process_vflr_event(struct i40e_pf
*pf
)
1950 u32 reg
, reg_idx
, bit_idx
, vf_id
;
1951 struct i40e_hw
*hw
= &pf
->hw
;
1954 if (!test_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
))
1957 /* re-enable vflr interrupt cause */
1958 reg
= rd32(hw
, I40E_PFINT_ICR0_ENA
);
1959 reg
|= I40E_PFINT_ICR0_ENA_VFLR_MASK
;
1960 wr32(hw
, I40E_PFINT_ICR0_ENA
, reg
);
1963 clear_bit(__I40E_VFLR_EVENT_PENDING
, &pf
->state
);
1964 for (vf_id
= 0; vf_id
< pf
->num_alloc_vfs
; vf_id
++) {
1965 reg_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) / 32;
1966 bit_idx
= (hw
->func_caps
.vf_base_id
+ vf_id
) % 32;
1967 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
1968 vf
= &pf
->vf
[vf_id
];
1969 reg
= rd32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
));
1970 if (reg
& (1 << bit_idx
)) {
1971 /* clear the bit in GLGEN_VFLRSTAT */
1972 wr32(hw
, I40E_GLGEN_VFLRSTAT(reg_idx
), (1 << bit_idx
));
1974 if (!test_bit(__I40E_DOWN
, &pf
->state
))
1975 i40e_reset_vf(vf
, true);
1983 * i40e_ndo_set_vf_mac
1984 * @netdev: network interface device structure
1985 * @vf_id: VF identifier
1988 * program VF mac address
1990 int i40e_ndo_set_vf_mac(struct net_device
*netdev
, int vf_id
, u8
*mac
)
1992 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1993 struct i40e_vsi
*vsi
= np
->vsi
;
1994 struct i40e_pf
*pf
= vsi
->back
;
1995 struct i40e_mac_filter
*f
;
1999 /* validate the request */
2000 if (vf_id
>= pf
->num_alloc_vfs
) {
2001 dev_err(&pf
->pdev
->dev
,
2002 "Invalid VF Identifier %d\n", vf_id
);
2007 vf
= &(pf
->vf
[vf_id
]);
2008 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2009 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2010 dev_err(&pf
->pdev
->dev
,
2011 "Uninitialized VF %d\n", vf_id
);
2016 if (!is_valid_ether_addr(mac
)) {
2017 dev_err(&pf
->pdev
->dev
,
2018 "Invalid VF ethernet address\n");
2023 /* delete the temporary mac address */
2024 i40e_del_filter(vsi
, vf
->default_lan_addr
.addr
,
2025 vf
->port_vlan_id
? vf
->port_vlan_id
: -1,
2028 /* Delete all the filters for this VSI - we're going to kill it
2031 list_for_each_entry(f
, &vsi
->mac_filter_list
, list
)
2032 i40e_del_filter(vsi
, f
->macaddr
, f
->vlan
, true, false);
2034 dev_info(&pf
->pdev
->dev
, "Setting MAC %pM on VF %d\n", mac
, vf_id
);
2035 /* program mac filter */
2036 if (i40e_sync_vsi_filters(vsi
)) {
2037 dev_err(&pf
->pdev
->dev
, "Unable to program ucast filters\n");
2041 ether_addr_copy(vf
->default_lan_addr
.addr
, mac
);
2042 vf
->pf_set_mac
= true;
2043 /* Force the VF driver stop so it has to reload with new MAC address */
2044 i40e_vc_disable_vf(pf
, vf
);
2045 dev_info(&pf
->pdev
->dev
, "Reload the VF driver to make this change effective.\n");
2052 * i40e_ndo_set_vf_port_vlan
2053 * @netdev: network interface device structure
2054 * @vf_id: VF identifier
2055 * @vlan_id: mac address
2056 * @qos: priority setting
2058 * program VF vlan id and/or qos
2060 int i40e_ndo_set_vf_port_vlan(struct net_device
*netdev
,
2061 int vf_id
, u16 vlan_id
, u8 qos
)
2063 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2064 struct i40e_pf
*pf
= np
->vsi
->back
;
2065 struct i40e_vsi
*vsi
;
2069 /* validate the request */
2070 if (vf_id
>= pf
->num_alloc_vfs
) {
2071 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2076 if ((vlan_id
> I40E_MAX_VLANID
) || (qos
> 7)) {
2077 dev_err(&pf
->pdev
->dev
, "Invalid VF Parameters\n");
2082 vf
= &(pf
->vf
[vf_id
]);
2083 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2084 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2085 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d\n", vf_id
);
2090 if (vsi
->info
.pvid
== (vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
)))
2091 /* duplicate request, so just return success */
2094 if (vsi
->info
.pvid
== 0 && i40e_is_vsi_in_vlan(vsi
)) {
2095 dev_err(&pf
->pdev
->dev
,
2096 "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",
2098 /* Administrator Error - knock the VF offline until he does
2099 * the right thing by reconfiguring his network correctly
2100 * and then reloading the VF driver.
2102 i40e_vc_disable_vf(pf
, vf
);
2105 /* Check for condition where there was already a port VLAN ID
2106 * filter set and now it is being deleted by setting it to zero.
2107 * Additionally check for the condition where there was a port
2108 * VLAN but now there is a new and different port VLAN being set.
2109 * Before deleting all the old VLAN filters we must add new ones
2110 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2111 * MAC addresses deleted.
2113 if ((!(vlan_id
|| qos
) ||
2114 (vlan_id
| qos
) != le16_to_cpu(vsi
->info
.pvid
)) &&
2116 ret
= i40e_vsi_add_vlan(vsi
, I40E_VLAN_ANY
);
2118 if (vsi
->info
.pvid
) {
2120 ret
= i40e_vsi_kill_vlan(vsi
, (le16_to_cpu(vsi
->info
.pvid
) &
2123 dev_info(&vsi
->back
->pdev
->dev
,
2124 "remove VLAN failed, ret=%d, aq_err=%d\n",
2125 ret
, pf
->hw
.aq
.asq_last_status
);
2129 ret
= i40e_vsi_add_pvid(vsi
,
2130 vlan_id
| (qos
<< I40E_VLAN_PRIORITY_SHIFT
));
2132 i40e_vsi_remove_pvid(vsi
);
2135 dev_info(&pf
->pdev
->dev
, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2136 vlan_id
, qos
, vf_id
);
2138 /* add new VLAN filter */
2139 ret
= i40e_vsi_add_vlan(vsi
, vlan_id
);
2141 dev_info(&vsi
->back
->pdev
->dev
,
2142 "add VF VLAN failed, ret=%d aq_err=%d\n", ret
,
2143 vsi
->back
->hw
.aq
.asq_last_status
);
2146 /* Kill non-vlan MAC filters - ignore error return since
2147 * there might not be any non-vlan MAC filters.
2149 i40e_vsi_kill_vlan(vsi
, I40E_VLAN_ANY
);
2153 dev_err(&pf
->pdev
->dev
, "Unable to update VF vsi context\n");
2156 /* The Port VLAN needs to be saved across resets the same as the
2157 * default LAN MAC address.
2159 vf
->port_vlan_id
= le16_to_cpu(vsi
->info
.pvid
);
2166 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2167 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2169 * i40e_ndo_set_vf_bw
2170 * @netdev: network interface device structure
2171 * @vf_id: VF identifier
2174 * configure VF Tx rate
2176 int i40e_ndo_set_vf_bw(struct net_device
*netdev
, int vf_id
, int min_tx_rate
,
2179 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2180 struct i40e_pf
*pf
= np
->vsi
->back
;
2181 struct i40e_vsi
*vsi
;
2186 /* validate the request */
2187 if (vf_id
>= pf
->num_alloc_vfs
) {
2188 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d.\n", vf_id
);
2194 dev_err(&pf
->pdev
->dev
, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2195 min_tx_rate
, vf_id
);
2199 vf
= &(pf
->vf
[vf_id
]);
2200 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2201 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2202 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d.\n", vf_id
);
2207 switch (pf
->hw
.phy
.link_info
.link_speed
) {
2208 case I40E_LINK_SPEED_40GB
:
2211 case I40E_LINK_SPEED_10GB
:
2214 case I40E_LINK_SPEED_1GB
:
2221 if (max_tx_rate
> speed
) {
2222 dev_err(&pf
->pdev
->dev
, "Invalid max tx rate %d specified for VF %d.",
2223 max_tx_rate
, vf
->vf_id
);
2228 if ((max_tx_rate
< 50) && (max_tx_rate
> 0)) {
2229 dev_warn(&pf
->pdev
->dev
, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2233 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2234 ret
= i40e_aq_config_vsi_bw_limit(&pf
->hw
, vsi
->seid
,
2235 max_tx_rate
/ I40E_BW_CREDIT_DIVISOR
,
2236 I40E_MAX_BW_INACTIVE_ACCUM
, NULL
);
2238 dev_err(&pf
->pdev
->dev
, "Unable to set max tx rate, error code %d.\n",
2243 vf
->tx_rate
= max_tx_rate
;
2249 * i40e_ndo_get_vf_config
2250 * @netdev: network interface device structure
2251 * @vf_id: VF identifier
2252 * @ivi: VF configuration structure
2254 * return VF configuration
2256 int i40e_ndo_get_vf_config(struct net_device
*netdev
,
2257 int vf_id
, struct ifla_vf_info
*ivi
)
2259 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2260 struct i40e_vsi
*vsi
= np
->vsi
;
2261 struct i40e_pf
*pf
= vsi
->back
;
2265 /* validate the request */
2266 if (vf_id
>= pf
->num_alloc_vfs
) {
2267 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2272 vf
= &(pf
->vf
[vf_id
]);
2273 /* first vsi is always the LAN vsi */
2274 vsi
= pf
->vsi
[vf
->lan_vsi_idx
];
2275 if (!test_bit(I40E_VF_STAT_INIT
, &vf
->vf_states
)) {
2276 dev_err(&pf
->pdev
->dev
, "Uninitialized VF %d\n", vf_id
);
2283 memcpy(&ivi
->mac
, vf
->default_lan_addr
.addr
, ETH_ALEN
);
2285 ivi
->max_tx_rate
= vf
->tx_rate
;
2286 ivi
->min_tx_rate
= 0;
2287 ivi
->vlan
= le16_to_cpu(vsi
->info
.pvid
) & I40E_VLAN_MASK
;
2288 ivi
->qos
= (le16_to_cpu(vsi
->info
.pvid
) & I40E_PRIORITY_MASK
) >>
2289 I40E_VLAN_PRIORITY_SHIFT
;
2290 if (vf
->link_forced
== false)
2291 ivi
->linkstate
= IFLA_VF_LINK_STATE_AUTO
;
2292 else if (vf
->link_up
== true)
2293 ivi
->linkstate
= IFLA_VF_LINK_STATE_ENABLE
;
2295 ivi
->linkstate
= IFLA_VF_LINK_STATE_DISABLE
;
2296 ivi
->spoofchk
= vf
->spoofchk
;
2304 * i40e_ndo_set_vf_link_state
2305 * @netdev: network interface device structure
2306 * @vf_id: VF identifier
2307 * @link: required link state
2309 * Set the link state of a specified VF, regardless of physical link state
2311 int i40e_ndo_set_vf_link_state(struct net_device
*netdev
, int vf_id
, int link
)
2313 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2314 struct i40e_pf
*pf
= np
->vsi
->back
;
2315 struct i40e_virtchnl_pf_event pfe
;
2316 struct i40e_hw
*hw
= &pf
->hw
;
2321 /* validate the request */
2322 if (vf_id
>= pf
->num_alloc_vfs
) {
2323 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2328 vf
= &pf
->vf
[vf_id
];
2329 abs_vf_id
= vf
->vf_id
+ hw
->func_caps
.vf_base_id
;
2331 pfe
.event
= I40E_VIRTCHNL_EVENT_LINK_CHANGE
;
2332 pfe
.severity
= I40E_PF_EVENT_SEVERITY_INFO
;
2335 case IFLA_VF_LINK_STATE_AUTO
:
2336 vf
->link_forced
= false;
2337 pfe
.event_data
.link_event
.link_status
=
2338 pf
->hw
.phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
2339 pfe
.event_data
.link_event
.link_speed
=
2340 pf
->hw
.phy
.link_info
.link_speed
;
2342 case IFLA_VF_LINK_STATE_ENABLE
:
2343 vf
->link_forced
= true;
2345 pfe
.event_data
.link_event
.link_status
= true;
2346 pfe
.event_data
.link_event
.link_speed
= I40E_LINK_SPEED_40GB
;
2348 case IFLA_VF_LINK_STATE_DISABLE
:
2349 vf
->link_forced
= true;
2350 vf
->link_up
= false;
2351 pfe
.event_data
.link_event
.link_status
= false;
2352 pfe
.event_data
.link_event
.link_speed
= 0;
2358 /* Notify the VF of its new link state */
2359 i40e_aq_send_msg_to_vf(hw
, abs_vf_id
, I40E_VIRTCHNL_OP_EVENT
,
2360 0, (u8
*)&pfe
, sizeof(pfe
), NULL
);
2367 * i40e_ndo_set_vf_spoofchk
2368 * @netdev: network interface device structure
2369 * @vf_id: VF identifier
2370 * @enable: flag to enable or disable feature
2372 * Enable or disable VF spoof checking
2374 int i40e_ndo_set_vf_spoofchk(struct net_device
*netdev
, int vf_id
, bool enable
)
2376 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2377 struct i40e_vsi
*vsi
= np
->vsi
;
2378 struct i40e_pf
*pf
= vsi
->back
;
2379 struct i40e_vsi_context ctxt
;
2380 struct i40e_hw
*hw
= &pf
->hw
;
2384 /* validate the request */
2385 if (vf_id
>= pf
->num_alloc_vfs
) {
2386 dev_err(&pf
->pdev
->dev
, "Invalid VF Identifier %d\n", vf_id
);
2391 vf
= &(pf
->vf
[vf_id
]);
2393 if (enable
== vf
->spoofchk
)
2396 vf
->spoofchk
= enable
;
2397 memset(&ctxt
, 0, sizeof(ctxt
));
2398 ctxt
.seid
= pf
->vsi
[vf
->lan_vsi_idx
]->seid
;
2399 ctxt
.pf_num
= pf
->hw
.pf_id
;
2400 ctxt
.info
.valid_sections
= cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID
);
2402 ctxt
.info
.sec_flags
|= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK
|
2403 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK
);
2404 ret
= i40e_aq_update_vsi_params(hw
, &ctxt
, NULL
);
2406 dev_err(&pf
->pdev
->dev
, "Error %d updating VSI parameters\n",