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 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
553 vf->port_vlan_id ? vf->port_vlan_id : -1,
556 dev_info(&pf->pdev->dev,
557 "Could not allocate VF MAC addr\n");
558 f = i40e_add_filter(vsi, brdcast,
559 vf->port_vlan_id ? vf->port_vlan_id : -1,
562 dev_info(&pf->pdev->dev,
563 "Could not allocate VF broadcast filter\n");
564 spin_unlock_bh(&vsi->mac_filter_list_lock);
567 /* program mac filter */
568 ret = i40e_sync_vsi_filters(vsi, false);
570 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
572 /* Set VF bandwidth if specified */
574 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
575 vf->tx_rate / 50, 0, NULL);
577 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
586 * i40e_enable_vf_mappings
587 * @vf: pointer to the VF info
591 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
593 struct i40e_pf *pf = vf->pf;
594 struct i40e_hw *hw = &pf->hw;
595 u32 reg, total_queue_pairs = 0;
598 /* Tell the hardware we're using noncontiguous mapping. HW requires
599 * that VF queues be mapped using this method, even when they are
600 * contiguous in real life
602 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
603 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
605 /* enable VF vplan_qtable mappings */
606 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
607 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
609 /* map PF queues to VF queues */
610 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
611 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
613 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
614 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
618 /* map PF queues to VSI */
619 for (j = 0; j < 7; j++) {
620 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
621 reg = 0x07FF07FF; /* unused */
623 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
626 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
630 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
637 * i40e_disable_vf_mappings
638 * @vf: pointer to the VF info
640 * disable VF mappings
642 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
644 struct i40e_pf *pf = vf->pf;
645 struct i40e_hw *hw = &pf->hw;
648 /* disable qp mappings */
649 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
650 for (i = 0; i < I40E_MAX_VSI_QP; i++)
651 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
652 I40E_QUEUE_END_OF_LIST);
658 * @vf: pointer to the VF info
662 static void i40e_free_vf_res(struct i40e_vf *vf)
664 struct i40e_pf *pf = vf->pf;
665 struct i40e_hw *hw = &pf->hw;
669 /* free vsi & disconnect it from the parent uplink */
670 if (vf->lan_vsi_idx) {
671 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
675 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
677 /* disable interrupts so the VF starts in a known state */
678 for (i = 0; i < msix_vf; i++) {
679 /* format is same for both registers */
681 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
683 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
686 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
690 /* clear the irq settings */
691 for (i = 0; i < msix_vf; i++) {
692 /* format is same for both registers */
694 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
696 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
699 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
700 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
701 wr32(hw, reg_idx, reg);
704 /* reset some of the state varibles keeping
705 * track of the resources
707 vf->num_queue_pairs = 0;
709 clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
714 * @vf: pointer to the VF info
716 * allocate VF resources
718 static int i40e_alloc_vf_res(struct i40e_vf *vf)
720 struct i40e_pf *pf = vf->pf;
721 int total_queue_pairs = 0;
724 /* allocate hw vsi context & associated resources */
725 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
728 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
729 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
731 /* store the total qps number for the runtime
734 vf->num_queue_pairs = total_queue_pairs;
736 /* VF is now completely initialized */
737 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
741 i40e_free_vf_res(vf);
746 #define VF_DEVICE_STATUS 0xAA
747 #define VF_TRANS_PENDING_MASK 0x20
749 * i40e_quiesce_vf_pci
750 * @vf: pointer to the VF structure
752 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
753 * if the transactions never clear.
755 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
757 struct i40e_pf *pf = vf->pf;
758 struct i40e_hw *hw = &pf->hw;
762 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
764 wr32(hw, I40E_PF_PCI_CIAA,
765 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
766 for (i = 0; i < 100; i++) {
767 reg = rd32(hw, I40E_PF_PCI_CIAD);
768 if ((reg & VF_TRANS_PENDING_MASK) == 0)
777 * @vf: pointer to the VF structure
778 * @flr: VFLR was issued or not
782 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
784 struct i40e_pf *pf = vf->pf;
785 struct i40e_hw *hw = &pf->hw;
790 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
794 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
796 /* In the case of a VFLR, the HW has already reset the VF and we
797 * just need to clean up, so don't hit the VFRTRIG register.
800 /* reset VF using VPGEN_VFRTRIG reg */
801 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
802 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
803 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
807 if (i40e_quiesce_vf_pci(vf))
808 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
811 /* poll VPGEN_VFRSTAT reg to make sure
812 * that reset is complete
814 for (i = 0; i < 10; i++) {
815 /* VF reset requires driver to first reset the VF and then
816 * poll the status register to make sure that the reset
817 * completed successfully. Due to internal HW FIFO flushes,
818 * we must wait 10ms before the register will be valid.
820 usleep_range(10000, 20000);
821 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
822 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
829 usleep_range(10000, 20000);
832 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
834 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
835 /* clear the reset bit in the VPGEN_VFRTRIG reg */
836 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
837 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
838 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
840 /* On initial reset, we won't have any queues */
841 if (vf->lan_vsi_idx == 0)
844 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
846 /* reallocate VF resources to reset the VSI state */
847 i40e_free_vf_res(vf);
848 if (!i40e_alloc_vf_res(vf)) {
849 i40e_enable_vf_mappings(vf);
850 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
851 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
853 /* tell the VF the reset is done */
854 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
856 clear_bit(__I40E_VF_DISABLE, &pf->state);
861 * @pf: pointer to the PF structure
865 void i40e_free_vfs(struct i40e_pf *pf)
867 struct i40e_hw *hw = &pf->hw;
868 u32 reg_idx, bit_idx;
873 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
874 usleep_range(1000, 2000);
876 for (i = 0; i < pf->num_alloc_vfs; i++)
877 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
878 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
881 for (i = 0; i < pf->num_alloc_vfs; i++)
882 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
883 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
886 /* Disable IOV before freeing resources. This lets any VF drivers
887 * running in the host get themselves cleaned up before we yank
888 * the carpet out from underneath their feet.
890 if (!pci_vfs_assigned(pf->pdev))
891 pci_disable_sriov(pf->pdev);
893 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
895 msleep(20); /* let any messages in transit get finished up */
897 /* free up VF resources */
898 tmp = pf->num_alloc_vfs;
899 pf->num_alloc_vfs = 0;
900 for (i = 0; i < tmp; i++) {
901 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
902 i40e_free_vf_res(&pf->vf[i]);
903 /* disable qp mappings */
904 i40e_disable_vf_mappings(&pf->vf[i]);
910 /* This check is for when the driver is unloaded while VFs are
911 * assigned. Setting the number of VFs to 0 through sysfs is caught
912 * before this function ever gets called.
914 if (!pci_vfs_assigned(pf->pdev)) {
915 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
916 * work correctly when SR-IOV gets re-enabled.
918 for (vf_id = 0; vf_id < tmp; vf_id++) {
919 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
920 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
921 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
924 clear_bit(__I40E_VF_DISABLE, &pf->state);
927 #ifdef CONFIG_PCI_IOV
930 * @pf: pointer to the PF structure
931 * @num_alloc_vfs: number of VFs to allocate
933 * allocate VF resources
935 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
940 /* Disable interrupt 0 so we don't try to handle the VFLR. */
941 i40e_irq_dynamic_disable_icr0(pf);
943 /* Check to see if we're just allocating resources for extant VFs */
944 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
945 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
947 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
948 pf->num_alloc_vfs = 0;
952 /* allocate memory */
953 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
960 /* apply default profile */
961 for (i = 0; i < num_alloc_vfs; i++) {
963 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
966 /* assign default capabilities */
967 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
968 vfs[i].spoofchk = true;
969 /* VF resources get allocated during reset */
970 i40e_reset_vf(&vfs[i], false);
973 pf->num_alloc_vfs = num_alloc_vfs;
979 /* Re-enable interrupt 0. */
980 i40e_irq_dynamic_enable_icr0(pf);
986 * i40e_pci_sriov_enable
987 * @pdev: pointer to a pci_dev structure
988 * @num_vfs: number of VFs to allocate
990 * Enable or change the number of VFs
992 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
994 #ifdef CONFIG_PCI_IOV
995 struct i40e_pf *pf = pci_get_drvdata(pdev);
996 int pre_existing_vfs = pci_num_vf(pdev);
999 if (test_bit(__I40E_TESTING, &pf->state)) {
1000 dev_warn(&pdev->dev,
1001 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
1006 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
1008 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1011 if (num_vfs > pf->num_req_vfs) {
1012 dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
1013 num_vfs, pf->num_req_vfs);
1018 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
1019 err = i40e_alloc_vfs(pf, num_vfs);
1021 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1035 * i40e_pci_sriov_configure
1036 * @pdev: pointer to a pci_dev structure
1037 * @num_vfs: number of VFs to allocate
1039 * Enable or change the number of VFs. Called when the user updates the number
1042 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1044 struct i40e_pf *pf = pci_get_drvdata(pdev);
1047 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1048 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1049 i40e_do_reset_safe(pf,
1050 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1052 return i40e_pci_sriov_enable(pdev, num_vfs);
1055 if (!pci_vfs_assigned(pf->pdev)) {
1057 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1058 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
1060 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1066 /***********************virtual channel routines******************/
1069 * i40e_vc_send_msg_to_vf
1070 * @vf: pointer to the VF info
1071 * @v_opcode: virtual channel opcode
1072 * @v_retval: virtual channel return value
1073 * @msg: pointer to the msg buffer
1074 * @msglen: msg length
1078 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1079 u32 v_retval, u8 *msg, u16 msglen)
1086 /* validate the request */
1087 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1092 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1094 /* single place to detect unsuccessful return values */
1096 vf->num_invalid_msgs++;
1097 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1098 v_opcode, v_retval);
1099 if (vf->num_invalid_msgs >
1100 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1101 dev_err(&pf->pdev->dev,
1102 "Number of invalid messages exceeded for VF %d\n",
1104 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1105 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1108 vf->num_valid_msgs++;
1109 /* reset the invalid counter, if a valid message is received. */
1110 vf->num_invalid_msgs = 0;
1113 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1116 dev_err(&pf->pdev->dev,
1117 "Unable to send the message to VF %d aq_err %d\n",
1118 vf->vf_id, pf->hw.aq.asq_last_status);
1126 * i40e_vc_send_resp_to_vf
1127 * @vf: pointer to the VF info
1128 * @opcode: operation code
1129 * @retval: return value
1131 * send resp msg to VF
1133 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1134 enum i40e_virtchnl_ops opcode,
1137 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1141 * i40e_vc_get_version_msg
1142 * @vf: pointer to the VF info
1144 * called from the VF to request the API version used by the PF
1146 static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
1148 struct i40e_virtchnl_version_info info = {
1149 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1152 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
1153 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1155 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
1156 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1157 I40E_SUCCESS, (u8 *)&info,
1159 i40e_virtchnl_version_info));
1163 * i40e_vc_get_vf_resources_msg
1164 * @vf: pointer to the VF info
1165 * @msg: pointer to the msg buffer
1166 * @msglen: msg length
1168 * called from the VF to request its resources
1170 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1172 struct i40e_virtchnl_vf_resource *vfres = NULL;
1173 struct i40e_pf *pf = vf->pf;
1174 i40e_status aq_ret = 0;
1175 struct i40e_vsi *vsi;
1180 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1181 aq_ret = I40E_ERR_PARAM;
1185 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1186 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1188 vfres = kzalloc(len, GFP_KERNEL);
1190 aq_ret = I40E_ERR_NO_MEMORY;
1195 vf->driver_caps = *(u32 *)msg;
1197 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1198 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1199 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1201 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1202 vsi = pf->vsi[vf->lan_vsi_idx];
1203 if (!vsi->info.pvid)
1204 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1205 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1206 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1207 vfres->vf_offload_flags |=
1208 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1210 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1213 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING)
1214 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
1216 vfres->num_vsis = num_vsis;
1217 vfres->num_queue_pairs = vf->num_queue_pairs;
1218 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1219 if (vf->lan_vsi_idx) {
1220 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
1221 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1222 vfres->vsi_res[i].num_queue_pairs = vsi->alloc_queue_pairs;
1223 /* VFs only use TC 0 */
1224 vfres->vsi_res[i].qset_handle
1225 = le16_to_cpu(vsi->info.qs_handle[0]);
1226 ether_addr_copy(vfres->vsi_res[i].default_mac_addr,
1227 vf->default_lan_addr.addr);
1230 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1233 /* send the response back to the VF */
1234 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1235 aq_ret, (u8 *)vfres, len);
1242 * i40e_vc_reset_vf_msg
1243 * @vf: pointer to the VF info
1244 * @msg: pointer to the msg buffer
1245 * @msglen: msg length
1247 * called from the VF to reset itself,
1248 * unlike other virtchnl messages, PF driver
1249 * doesn't send the response back to the VF
1251 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1253 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1254 i40e_reset_vf(vf, false);
1258 * i40e_vc_config_promiscuous_mode_msg
1259 * @vf: pointer to the VF info
1260 * @msg: pointer to the msg buffer
1261 * @msglen: msg length
1263 * called from the VF to configure the promiscuous mode of
1266 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1267 u8 *msg, u16 msglen)
1269 struct i40e_virtchnl_promisc_info *info =
1270 (struct i40e_virtchnl_promisc_info *)msg;
1271 struct i40e_pf *pf = vf->pf;
1272 struct i40e_hw *hw = &pf->hw;
1273 struct i40e_vsi *vsi;
1274 bool allmulti = false;
1277 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1278 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1279 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1280 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1281 (vsi->type != I40E_VSI_FCOE)) {
1282 aq_ret = I40E_ERR_PARAM;
1285 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1287 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1291 /* send the response to the VF */
1292 return i40e_vc_send_resp_to_vf(vf,
1293 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1298 * i40e_vc_config_queues_msg
1299 * @vf: pointer to the VF info
1300 * @msg: pointer to the msg buffer
1301 * @msglen: msg length
1303 * called from the VF to configure the rx/tx
1306 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1308 struct i40e_virtchnl_vsi_queue_config_info *qci =
1309 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1310 struct i40e_virtchnl_queue_pair_info *qpi;
1311 struct i40e_pf *pf = vf->pf;
1312 u16 vsi_id, vsi_queue_id;
1313 i40e_status aq_ret = 0;
1316 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1317 aq_ret = I40E_ERR_PARAM;
1321 vsi_id = qci->vsi_id;
1322 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1323 aq_ret = I40E_ERR_PARAM;
1326 for (i = 0; i < qci->num_queue_pairs; i++) {
1327 qpi = &qci->qpair[i];
1328 vsi_queue_id = qpi->txq.queue_id;
1329 if ((qpi->txq.vsi_id != vsi_id) ||
1330 (qpi->rxq.vsi_id != vsi_id) ||
1331 (qpi->rxq.queue_id != vsi_queue_id) ||
1332 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1333 aq_ret = I40E_ERR_PARAM;
1337 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1339 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1341 aq_ret = I40E_ERR_PARAM;
1345 /* set vsi num_queue_pairs in use to num configured by VF */
1346 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
1349 /* send the response to the VF */
1350 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1355 * i40e_vc_config_irq_map_msg
1356 * @vf: pointer to the VF info
1357 * @msg: pointer to the msg buffer
1358 * @msglen: msg length
1360 * called from the VF to configure the irq to
1363 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1365 struct i40e_virtchnl_irq_map_info *irqmap_info =
1366 (struct i40e_virtchnl_irq_map_info *)msg;
1367 struct i40e_virtchnl_vector_map *map;
1368 u16 vsi_id, vsi_queue_id, vector_id;
1369 i40e_status aq_ret = 0;
1370 unsigned long tempmap;
1373 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1374 aq_ret = I40E_ERR_PARAM;
1378 for (i = 0; i < irqmap_info->num_vectors; i++) {
1379 map = &irqmap_info->vecmap[i];
1381 vector_id = map->vector_id;
1382 vsi_id = map->vsi_id;
1383 /* validate msg params */
1384 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1385 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1386 aq_ret = I40E_ERR_PARAM;
1390 /* lookout for the invalid queue index */
1391 tempmap = map->rxq_map;
1392 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1393 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1395 aq_ret = I40E_ERR_PARAM;
1400 tempmap = map->txq_map;
1401 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1402 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1404 aq_ret = I40E_ERR_PARAM;
1409 i40e_config_irq_link_list(vf, vsi_id, map);
1412 /* send the response to the VF */
1413 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1418 * i40e_vc_enable_queues_msg
1419 * @vf: pointer to the VF info
1420 * @msg: pointer to the msg buffer
1421 * @msglen: msg length
1423 * called from the VF to enable all or specific queue(s)
1425 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1427 struct i40e_virtchnl_queue_select *vqs =
1428 (struct i40e_virtchnl_queue_select *)msg;
1429 struct i40e_pf *pf = vf->pf;
1430 u16 vsi_id = vqs->vsi_id;
1431 i40e_status aq_ret = 0;
1433 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1434 aq_ret = I40E_ERR_PARAM;
1438 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1439 aq_ret = I40E_ERR_PARAM;
1443 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1444 aq_ret = I40E_ERR_PARAM;
1448 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
1449 aq_ret = I40E_ERR_TIMEOUT;
1451 /* send the response to the VF */
1452 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1457 * i40e_vc_disable_queues_msg
1458 * @vf: pointer to the VF info
1459 * @msg: pointer to the msg buffer
1460 * @msglen: msg length
1462 * called from the VF to disable all or specific
1465 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1467 struct i40e_virtchnl_queue_select *vqs =
1468 (struct i40e_virtchnl_queue_select *)msg;
1469 struct i40e_pf *pf = vf->pf;
1470 i40e_status aq_ret = 0;
1472 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1473 aq_ret = I40E_ERR_PARAM;
1477 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1478 aq_ret = I40E_ERR_PARAM;
1482 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1483 aq_ret = I40E_ERR_PARAM;
1487 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
1488 aq_ret = I40E_ERR_TIMEOUT;
1491 /* send the response to the VF */
1492 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1497 * i40e_vc_get_stats_msg
1498 * @vf: pointer to the VF info
1499 * @msg: pointer to the msg buffer
1500 * @msglen: msg length
1502 * called from the VF to get vsi stats
1504 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1506 struct i40e_virtchnl_queue_select *vqs =
1507 (struct i40e_virtchnl_queue_select *)msg;
1508 struct i40e_pf *pf = vf->pf;
1509 struct i40e_eth_stats stats;
1510 i40e_status aq_ret = 0;
1511 struct i40e_vsi *vsi;
1513 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1515 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1516 aq_ret = I40E_ERR_PARAM;
1520 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1521 aq_ret = I40E_ERR_PARAM;
1525 vsi = pf->vsi[vf->lan_vsi_idx];
1527 aq_ret = I40E_ERR_PARAM;
1530 i40e_update_eth_stats(vsi);
1531 stats = vsi->eth_stats;
1534 /* send the response back to the VF */
1535 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1536 (u8 *)&stats, sizeof(stats));
1540 * i40e_check_vf_permission
1541 * @vf: pointer to the VF info
1542 * @macaddr: pointer to the MAC Address being checked
1544 * Check if the VF has permission to add or delete unicast MAC address
1545 * filters and return error code -EPERM if not. Then check if the
1546 * address filter requested is broadcast or zero and if so return
1547 * an invalid MAC address error code.
1549 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1551 struct i40e_pf *pf = vf->pf;
1554 if (is_broadcast_ether_addr(macaddr) ||
1555 is_zero_ether_addr(macaddr)) {
1556 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1557 ret = I40E_ERR_INVALID_MAC_ADDR;
1558 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1559 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1560 /* If the host VMM administrator has set the VF MAC address
1561 * administratively via the ndo_set_vf_mac command then deny
1562 * permission to the VF to add or delete unicast MAC addresses.
1563 * The VF may request to set the MAC address filter already
1564 * assigned to it so do not return an error in that case.
1566 dev_err(&pf->pdev->dev,
1567 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1574 * i40e_vc_add_mac_addr_msg
1575 * @vf: pointer to the VF info
1576 * @msg: pointer to the msg buffer
1577 * @msglen: msg length
1579 * add guest mac address filter
1581 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1583 struct i40e_virtchnl_ether_addr_list *al =
1584 (struct i40e_virtchnl_ether_addr_list *)msg;
1585 struct i40e_pf *pf = vf->pf;
1586 struct i40e_vsi *vsi = NULL;
1587 u16 vsi_id = al->vsi_id;
1588 i40e_status ret = 0;
1591 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1592 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1593 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1594 ret = I40E_ERR_PARAM;
1598 for (i = 0; i < al->num_elements; i++) {
1599 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1603 vsi = pf->vsi[vf->lan_vsi_idx];
1605 /* Lock once, because all function inside for loop accesses VSI's
1606 * MAC filter list which needs to be protected using same lock.
1608 spin_lock_bh(&vsi->mac_filter_list_lock);
1610 /* add new addresses to the list */
1611 for (i = 0; i < al->num_elements; i++) {
1612 struct i40e_mac_filter *f;
1614 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1616 if (i40e_is_vsi_in_vlan(vsi))
1617 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1620 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1625 dev_err(&pf->pdev->dev,
1626 "Unable to add VF MAC filter\n");
1627 ret = I40E_ERR_PARAM;
1628 spin_unlock_bh(&vsi->mac_filter_list_lock);
1632 spin_unlock_bh(&vsi->mac_filter_list_lock);
1634 /* program the updated filter list */
1635 if (i40e_sync_vsi_filters(vsi, false))
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_ADD_ETHER_ADDRESS,
1645 * i40e_vc_del_mac_addr_msg
1646 * @vf: pointer to the VF info
1647 * @msg: pointer to the msg buffer
1648 * @msglen: msg length
1650 * remove guest mac address filter
1652 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1654 struct i40e_virtchnl_ether_addr_list *al =
1655 (struct i40e_virtchnl_ether_addr_list *)msg;
1656 struct i40e_pf *pf = vf->pf;
1657 struct i40e_vsi *vsi = NULL;
1658 u16 vsi_id = al->vsi_id;
1659 i40e_status 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 ret = I40E_ERR_PARAM;
1669 for (i = 0; i < al->num_elements; i++) {
1670 if (is_broadcast_ether_addr(al->list[i].addr) ||
1671 is_zero_ether_addr(al->list[i].addr)) {
1672 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1674 ret = I40E_ERR_INVALID_MAC_ADDR;
1678 vsi = pf->vsi[vf->lan_vsi_idx];
1680 spin_lock_bh(&vsi->mac_filter_list_lock);
1681 /* delete addresses from the list */
1682 for (i = 0; i < al->num_elements; i++)
1683 i40e_del_filter(vsi, al->list[i].addr,
1684 I40E_VLAN_ANY, true, false);
1685 spin_unlock_bh(&vsi->mac_filter_list_lock);
1687 /* program the updated filter list */
1688 if (i40e_sync_vsi_filters(vsi, false))
1689 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1692 /* send the response to the VF */
1693 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
1698 * i40e_vc_add_vlan_msg
1699 * @vf: pointer to the VF info
1700 * @msg: pointer to the msg buffer
1701 * @msglen: msg length
1703 * program guest vlan id
1705 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1707 struct i40e_virtchnl_vlan_filter_list *vfl =
1708 (struct i40e_virtchnl_vlan_filter_list *)msg;
1709 struct i40e_pf *pf = vf->pf;
1710 struct i40e_vsi *vsi = NULL;
1711 u16 vsi_id = vfl->vsi_id;
1712 i40e_status aq_ret = 0;
1715 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1716 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1717 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1718 aq_ret = I40E_ERR_PARAM;
1722 for (i = 0; i < vfl->num_elements; i++) {
1723 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1724 aq_ret = I40E_ERR_PARAM;
1725 dev_err(&pf->pdev->dev,
1726 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1730 vsi = pf->vsi[vf->lan_vsi_idx];
1731 if (vsi->info.pvid) {
1732 aq_ret = I40E_ERR_PARAM;
1736 i40e_vlan_stripping_enable(vsi);
1737 for (i = 0; i < vfl->num_elements; i++) {
1738 /* add new VLAN filter */
1739 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1742 dev_err(&pf->pdev->dev,
1743 "Unable to add VF vlan filter %d, error %d\n",
1744 vfl->vlan_id[i], ret);
1748 /* send the response to the VF */
1749 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1753 * i40e_vc_remove_vlan_msg
1754 * @vf: pointer to the VF info
1755 * @msg: pointer to the msg buffer
1756 * @msglen: msg length
1758 * remove programmed guest vlan id
1760 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1762 struct i40e_virtchnl_vlan_filter_list *vfl =
1763 (struct i40e_virtchnl_vlan_filter_list *)msg;
1764 struct i40e_pf *pf = vf->pf;
1765 struct i40e_vsi *vsi = NULL;
1766 u16 vsi_id = vfl->vsi_id;
1767 i40e_status aq_ret = 0;
1770 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1771 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1772 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1773 aq_ret = I40E_ERR_PARAM;
1777 for (i = 0; i < vfl->num_elements; i++) {
1778 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1779 aq_ret = I40E_ERR_PARAM;
1784 vsi = pf->vsi[vf->lan_vsi_idx];
1785 if (vsi->info.pvid) {
1786 aq_ret = I40E_ERR_PARAM;
1790 for (i = 0; i < vfl->num_elements; i++) {
1791 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1794 dev_err(&pf->pdev->dev,
1795 "Unable to delete VF vlan filter %d, error %d\n",
1796 vfl->vlan_id[i], ret);
1800 /* send the response to the VF */
1801 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1805 * i40e_vc_validate_vf_msg
1806 * @vf: pointer to the VF info
1807 * @msg: pointer to the msg buffer
1808 * @msglen: msg length
1809 * @msghndl: msg handle
1813 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1814 u32 v_retval, u8 *msg, u16 msglen)
1816 bool err_msg_format = false;
1819 /* Check if VF is disabled. */
1820 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1821 return I40E_ERR_PARAM;
1823 /* Validate message length. */
1825 case I40E_VIRTCHNL_OP_VERSION:
1826 valid_len = sizeof(struct i40e_virtchnl_version_info);
1828 case I40E_VIRTCHNL_OP_RESET_VF:
1831 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1833 valid_len = sizeof(u32);
1837 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1838 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1840 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1841 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1843 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1844 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1845 if (msglen >= valid_len) {
1846 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1847 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1848 valid_len += (vqc->num_queue_pairs *
1850 i40e_virtchnl_queue_pair_info));
1851 if (vqc->num_queue_pairs == 0)
1852 err_msg_format = true;
1855 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1856 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1857 if (msglen >= valid_len) {
1858 struct i40e_virtchnl_irq_map_info *vimi =
1859 (struct i40e_virtchnl_irq_map_info *)msg;
1860 valid_len += (vimi->num_vectors *
1861 sizeof(struct i40e_virtchnl_vector_map));
1862 if (vimi->num_vectors == 0)
1863 err_msg_format = true;
1866 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1867 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1868 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1870 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1871 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1872 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1873 if (msglen >= valid_len) {
1874 struct i40e_virtchnl_ether_addr_list *veal =
1875 (struct i40e_virtchnl_ether_addr_list *)msg;
1876 valid_len += veal->num_elements *
1877 sizeof(struct i40e_virtchnl_ether_addr);
1878 if (veal->num_elements == 0)
1879 err_msg_format = true;
1882 case I40E_VIRTCHNL_OP_ADD_VLAN:
1883 case I40E_VIRTCHNL_OP_DEL_VLAN:
1884 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1885 if (msglen >= valid_len) {
1886 struct i40e_virtchnl_vlan_filter_list *vfl =
1887 (struct i40e_virtchnl_vlan_filter_list *)msg;
1888 valid_len += vfl->num_elements * sizeof(u16);
1889 if (vfl->num_elements == 0)
1890 err_msg_format = true;
1893 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1894 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1896 case I40E_VIRTCHNL_OP_GET_STATS:
1897 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1899 /* These are always errors coming from the VF. */
1900 case I40E_VIRTCHNL_OP_EVENT:
1901 case I40E_VIRTCHNL_OP_UNKNOWN:
1905 /* few more checks */
1906 if ((valid_len != msglen) || (err_msg_format)) {
1907 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1915 * i40e_vc_process_vf_msg
1916 * @pf: pointer to the PF structure
1917 * @vf_id: source VF id
1918 * @msg: pointer to the msg buffer
1919 * @msglen: msg length
1920 * @msghndl: msg handle
1922 * called from the common aeq/arq handler to
1923 * process request from VF
1925 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1926 u32 v_retval, u8 *msg, u16 msglen)
1928 struct i40e_hw *hw = &pf->hw;
1929 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
1933 pf->vf_aq_requests++;
1934 if (local_vf_id >= pf->num_alloc_vfs)
1936 vf = &(pf->vf[local_vf_id]);
1937 /* perform basic checks on the msg */
1938 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1941 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
1942 local_vf_id, v_opcode, msglen);
1947 case I40E_VIRTCHNL_OP_VERSION:
1948 ret = i40e_vc_get_version_msg(vf, msg);
1950 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1951 ret = i40e_vc_get_vf_resources_msg(vf, msg);
1953 case I40E_VIRTCHNL_OP_RESET_VF:
1954 i40e_vc_reset_vf_msg(vf);
1957 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1958 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1960 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1961 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1963 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1964 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1966 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1967 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1968 i40e_vc_notify_vf_link_state(vf);
1970 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1971 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1973 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1974 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1976 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1977 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1979 case I40E_VIRTCHNL_OP_ADD_VLAN:
1980 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1982 case I40E_VIRTCHNL_OP_DEL_VLAN:
1983 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1985 case I40E_VIRTCHNL_OP_GET_STATS:
1986 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1988 case I40E_VIRTCHNL_OP_UNKNOWN:
1990 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
1991 v_opcode, local_vf_id);
1992 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1993 I40E_ERR_NOT_IMPLEMENTED);
2001 * i40e_vc_process_vflr_event
2002 * @pf: pointer to the PF structure
2004 * called from the vlfr irq handler to
2005 * free up VF resources and state variables
2007 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
2009 u32 reg, reg_idx, bit_idx, vf_id;
2010 struct i40e_hw *hw = &pf->hw;
2013 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
2016 /* re-enable vflr interrupt cause */
2017 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
2018 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
2019 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
2022 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2023 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
2024 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
2025 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
2026 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
2027 vf = &pf->vf[vf_id];
2028 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
2029 if (reg & BIT(bit_idx)) {
2030 /* clear the bit in GLGEN_VFLRSTAT */
2031 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
2033 if (!test_bit(__I40E_DOWN, &pf->state))
2034 i40e_reset_vf(vf, true);
2042 * i40e_ndo_set_vf_mac
2043 * @netdev: network interface device structure
2044 * @vf_id: VF identifier
2047 * program VF mac address
2049 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2051 struct i40e_netdev_priv *np = netdev_priv(netdev);
2052 struct i40e_vsi *vsi = np->vsi;
2053 struct i40e_pf *pf = vsi->back;
2054 struct i40e_mac_filter *f;
2058 /* validate the request */
2059 if (vf_id >= pf->num_alloc_vfs) {
2060 dev_err(&pf->pdev->dev,
2061 "Invalid VF Identifier %d\n", vf_id);
2066 vf = &(pf->vf[vf_id]);
2067 vsi = pf->vsi[vf->lan_vsi_idx];
2068 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2069 dev_err(&pf->pdev->dev,
2070 "Uninitialized VF %d\n", vf_id);
2075 if (!is_valid_ether_addr(mac)) {
2076 dev_err(&pf->pdev->dev,
2077 "Invalid VF ethernet address\n");
2082 /* Lock once because below invoked function add/del_filter requires
2083 * mac_filter_list_lock to be held
2085 spin_lock_bh(&vsi->mac_filter_list_lock);
2087 /* delete the temporary mac address */
2088 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2089 vf->port_vlan_id ? vf->port_vlan_id : -1,
2092 /* Delete all the filters for this VSI - we're going to kill it
2095 list_for_each_entry(f, &vsi->mac_filter_list, list)
2096 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2098 spin_unlock_bh(&vsi->mac_filter_list_lock);
2100 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2101 /* program mac filter */
2102 if (i40e_sync_vsi_filters(vsi, false)) {
2103 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2107 ether_addr_copy(vf->default_lan_addr.addr, mac);
2108 vf->pf_set_mac = true;
2109 /* Force the VF driver stop so it has to reload with new MAC address */
2110 i40e_vc_disable_vf(pf, vf);
2111 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2118 * i40e_ndo_set_vf_port_vlan
2119 * @netdev: network interface device structure
2120 * @vf_id: VF identifier
2121 * @vlan_id: mac address
2122 * @qos: priority setting
2124 * program VF vlan id and/or qos
2126 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2127 int vf_id, u16 vlan_id, u8 qos)
2129 u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
2130 struct i40e_netdev_priv *np = netdev_priv(netdev);
2131 struct i40e_pf *pf = np->vsi->back;
2132 bool is_vsi_in_vlan = false;
2133 struct i40e_vsi *vsi;
2137 /* validate the request */
2138 if (vf_id >= pf->num_alloc_vfs) {
2139 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2144 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2145 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2150 vf = &(pf->vf[vf_id]);
2151 vsi = pf->vsi[vf->lan_vsi_idx];
2152 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2153 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2158 if (le16_to_cpu(vsi->info.pvid) == vlanprio)
2159 /* duplicate request, so just return success */
2162 spin_lock_bh(&vsi->mac_filter_list_lock);
2163 is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
2164 spin_unlock_bh(&vsi->mac_filter_list_lock);
2166 if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
2167 dev_err(&pf->pdev->dev,
2168 "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",
2170 /* Administrator Error - knock the VF offline until he does
2171 * the right thing by reconfiguring his network correctly
2172 * and then reloading the VF driver.
2174 i40e_vc_disable_vf(pf, vf);
2177 /* Check for condition where there was already a port VLAN ID
2178 * filter set and now it is being deleted by setting it to zero.
2179 * Additionally check for the condition where there was a port
2180 * VLAN but now there is a new and different port VLAN being set.
2181 * Before deleting all the old VLAN filters we must add new ones
2182 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2183 * MAC addresses deleted.
2185 if ((!(vlan_id || qos) ||
2186 vlanprio != le16_to_cpu(vsi->info.pvid)) &&
2188 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2190 if (vsi->info.pvid) {
2192 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2195 dev_info(&vsi->back->pdev->dev,
2196 "remove VLAN failed, ret=%d, aq_err=%d\n",
2197 ret, pf->hw.aq.asq_last_status);
2201 ret = i40e_vsi_add_pvid(vsi, vlanprio);
2203 i40e_vsi_remove_pvid(vsi);
2206 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2207 vlan_id, qos, vf_id);
2209 /* add new VLAN filter */
2210 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2212 dev_info(&vsi->back->pdev->dev,
2213 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2214 vsi->back->hw.aq.asq_last_status);
2217 /* Kill non-vlan MAC filters - ignore error return since
2218 * there might not be any non-vlan MAC filters.
2220 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2224 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2227 /* The Port VLAN needs to be saved across resets the same as the
2228 * default LAN MAC address.
2230 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2237 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2238 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2240 * i40e_ndo_set_vf_bw
2241 * @netdev: network interface device structure
2242 * @vf_id: VF identifier
2245 * configure VF Tx rate
2247 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2250 struct i40e_netdev_priv *np = netdev_priv(netdev);
2251 struct i40e_pf *pf = np->vsi->back;
2252 struct i40e_vsi *vsi;
2257 /* validate the request */
2258 if (vf_id >= pf->num_alloc_vfs) {
2259 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2265 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2266 min_tx_rate, vf_id);
2270 vf = &(pf->vf[vf_id]);
2271 vsi = pf->vsi[vf->lan_vsi_idx];
2272 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2273 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2278 switch (pf->hw.phy.link_info.link_speed) {
2279 case I40E_LINK_SPEED_40GB:
2282 case I40E_LINK_SPEED_10GB:
2285 case I40E_LINK_SPEED_1GB:
2292 if (max_tx_rate > speed) {
2293 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
2294 max_tx_rate, vf->vf_id);
2299 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2300 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2304 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2305 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2306 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2307 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2309 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2314 vf->tx_rate = max_tx_rate;
2320 * i40e_ndo_get_vf_config
2321 * @netdev: network interface device structure
2322 * @vf_id: VF identifier
2323 * @ivi: VF configuration structure
2325 * return VF configuration
2327 int i40e_ndo_get_vf_config(struct net_device *netdev,
2328 int vf_id, struct ifla_vf_info *ivi)
2330 struct i40e_netdev_priv *np = netdev_priv(netdev);
2331 struct i40e_vsi *vsi = np->vsi;
2332 struct i40e_pf *pf = vsi->back;
2336 /* validate the request */
2337 if (vf_id >= pf->num_alloc_vfs) {
2338 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2343 vf = &(pf->vf[vf_id]);
2344 /* first vsi is always the LAN vsi */
2345 vsi = pf->vsi[vf->lan_vsi_idx];
2346 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2347 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2354 ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
2356 ivi->max_tx_rate = vf->tx_rate;
2357 ivi->min_tx_rate = 0;
2358 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2359 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2360 I40E_VLAN_PRIORITY_SHIFT;
2361 if (vf->link_forced == false)
2362 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2363 else if (vf->link_up == true)
2364 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2366 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
2367 ivi->spoofchk = vf->spoofchk;
2375 * i40e_ndo_set_vf_link_state
2376 * @netdev: network interface device structure
2377 * @vf_id: VF identifier
2378 * @link: required link state
2380 * Set the link state of a specified VF, regardless of physical link state
2382 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2384 struct i40e_netdev_priv *np = netdev_priv(netdev);
2385 struct i40e_pf *pf = np->vsi->back;
2386 struct i40e_virtchnl_pf_event pfe;
2387 struct i40e_hw *hw = &pf->hw;
2392 /* validate the request */
2393 if (vf_id >= pf->num_alloc_vfs) {
2394 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2399 vf = &pf->vf[vf_id];
2400 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
2402 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2403 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2406 case IFLA_VF_LINK_STATE_AUTO:
2407 vf->link_forced = false;
2408 pfe.event_data.link_event.link_status =
2409 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2410 pfe.event_data.link_event.link_speed =
2411 pf->hw.phy.link_info.link_speed;
2413 case IFLA_VF_LINK_STATE_ENABLE:
2414 vf->link_forced = true;
2416 pfe.event_data.link_event.link_status = true;
2417 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2419 case IFLA_VF_LINK_STATE_DISABLE:
2420 vf->link_forced = true;
2421 vf->link_up = false;
2422 pfe.event_data.link_event.link_status = false;
2423 pfe.event_data.link_event.link_speed = 0;
2429 /* Notify the VF of its new link state */
2430 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2431 0, (u8 *)&pfe, sizeof(pfe), NULL);
2438 * i40e_ndo_set_vf_spoofchk
2439 * @netdev: network interface device structure
2440 * @vf_id: VF identifier
2441 * @enable: flag to enable or disable feature
2443 * Enable or disable VF spoof checking
2445 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
2447 struct i40e_netdev_priv *np = netdev_priv(netdev);
2448 struct i40e_vsi *vsi = np->vsi;
2449 struct i40e_pf *pf = vsi->back;
2450 struct i40e_vsi_context ctxt;
2451 struct i40e_hw *hw = &pf->hw;
2455 /* validate the request */
2456 if (vf_id >= pf->num_alloc_vfs) {
2457 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2462 vf = &(pf->vf[vf_id]);
2464 if (enable == vf->spoofchk)
2467 vf->spoofchk = enable;
2468 memset(&ctxt, 0, sizeof(ctxt));
2469 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
2470 ctxt.pf_num = pf->hw.pf_id;
2471 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2473 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2474 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
2475 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2477 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",