1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2014 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 /***********************misc routines*****************************/
33 * @pf: pointer to the pf info
34 * @vf: pointer to the vf info
36 * Disable the VF through a SW reset
38 static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
40 struct i40e_hw *hw = &pf->hw;
43 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
44 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
45 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
50 * i40e_vc_isvalid_vsi_id
51 * @vf: pointer to the vf info
52 * @vsi_id: vf relative vsi id
54 * check for the valid vsi id
56 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u8 vsi_id)
58 struct i40e_pf *pf = vf->pf;
60 return pf->vsi[vsi_id]->vf_id == vf->vf_id;
64 * i40e_vc_isvalid_queue_id
65 * @vf: pointer to the vf info
67 * @qid: vsi relative queue id
69 * check for the valid queue id
71 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u8 vsi_id,
74 struct i40e_pf *pf = vf->pf;
76 return qid < pf->vsi[vsi_id]->alloc_queue_pairs;
80 * i40e_vc_isvalid_vector_id
81 * @vf: pointer to the vf info
82 * @vector_id: vf relative vector id
84 * check for the valid vector id
86 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
88 struct i40e_pf *pf = vf->pf;
90 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
93 /***********************vf resource mgmt routines*****************/
96 * i40e_vc_get_pf_queue_id
97 * @vf: pointer to the vf info
98 * @vsi_idx: index of VSI in PF struct
99 * @vsi_queue_id: vsi relative queue id
101 * return pf relative queue id
103 static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u8 vsi_idx,
106 struct i40e_pf *pf = vf->pf;
107 struct i40e_vsi *vsi = pf->vsi[vsi_idx];
108 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
110 if (le16_to_cpu(vsi->info.mapping_flags) &
111 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
113 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
115 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
122 * i40e_config_irq_link_list
123 * @vf: pointer to the vf info
124 * @vsi_idx: index of VSI in PF struct
125 * @vecmap: irq map info
127 * configure irq link list from the map
129 static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_idx,
130 struct i40e_virtchnl_vector_map *vecmap)
132 unsigned long linklistmap = 0, tempmap;
133 struct i40e_pf *pf = vf->pf;
134 struct i40e_hw *hw = &pf->hw;
135 u16 vsi_queue_id, pf_queue_id;
136 enum i40e_queue_type qtype;
137 u16 next_q, vector_id;
141 vector_id = vecmap->vector_id;
144 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
146 reg_idx = I40E_VPINT_LNKLSTN(
147 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
150 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
151 /* Special case - No queues mapped on this vector */
152 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
155 tempmap = vecmap->rxq_map;
156 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
158 (I40E_VIRTCHNL_SUPPORTED_QTYPES *
162 tempmap = vecmap->txq_map;
163 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
165 (I40E_VIRTCHNL_SUPPORTED_QTYPES * vsi_queue_id
169 next_q = find_first_bit(&linklistmap,
171 I40E_VIRTCHNL_SUPPORTED_QTYPES));
172 vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES;
173 qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES;
174 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
175 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
177 wr32(hw, reg_idx, reg);
179 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
181 case I40E_QUEUE_TYPE_RX:
182 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
183 itr_idx = vecmap->rxitr_idx;
185 case I40E_QUEUE_TYPE_TX:
186 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
187 itr_idx = vecmap->txitr_idx;
193 next_q = find_next_bit(&linklistmap,
195 I40E_VIRTCHNL_SUPPORTED_QTYPES),
198 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
199 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
200 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
201 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx,
204 pf_queue_id = I40E_QUEUE_END_OF_LIST;
208 /* format for the RQCTL & TQCTL regs is same */
210 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
211 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
212 (1 << I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
213 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
214 wr32(hw, reg_idx, reg);
222 * i40e_config_vsi_tx_queue
223 * @vf: pointer to the vf info
224 * @vsi_idx: index of VSI in PF struct
225 * @vsi_queue_id: vsi relative queue index
226 * @info: config. info
230 static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_idx,
232 struct i40e_virtchnl_txq_info *info)
234 struct i40e_pf *pf = vf->pf;
235 struct i40e_hw *hw = &pf->hw;
236 struct i40e_hmc_obj_txq tx_ctx;
241 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
243 /* clear the context structure first */
244 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
246 /* only set the required fields */
247 tx_ctx.base = info->dma_ring_addr / 128;
248 tx_ctx.qlen = info->ring_len;
249 tx_ctx.rdylist = le16_to_cpu(pf->vsi[vsi_idx]->info.qs_handle[0]);
250 tx_ctx.rdylist_act = 0;
251 tx_ctx.head_wb_ena = info->headwb_enabled;
252 tx_ctx.head_wb_addr = info->dma_headwb_addr;
254 /* clear the context in the HMC */
255 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
257 dev_err(&pf->pdev->dev,
258 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
264 /* set the context in the HMC */
265 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
267 dev_err(&pf->pdev->dev,
268 "Failed to set VF LAN Tx queue context %d error: %d\n",
274 /* associate this queue with the PCI VF function */
275 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
276 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
277 & I40E_QTX_CTL_PF_INDX_MASK);
278 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
279 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
280 & I40E_QTX_CTL_VFVM_INDX_MASK);
281 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
289 * i40e_config_vsi_rx_queue
290 * @vf: pointer to the vf info
291 * @vsi_idx: index of VSI in PF struct
292 * @vsi_queue_id: vsi relative queue index
293 * @info: config. info
297 static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_idx,
299 struct i40e_virtchnl_rxq_info *info)
301 struct i40e_pf *pf = vf->pf;
302 struct i40e_hw *hw = &pf->hw;
303 struct i40e_hmc_obj_rxq rx_ctx;
307 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_idx, vsi_queue_id);
309 /* clear the context structure first */
310 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
312 /* only set the required fields */
313 rx_ctx.base = info->dma_ring_addr / 128;
314 rx_ctx.qlen = info->ring_len;
316 if (info->splithdr_enabled) {
317 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
319 I40E_RX_SPLIT_TCP_UDP |
321 /* header length validation */
322 if (info->hdr_size > ((2 * 1024) - 64)) {
326 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
328 /* set splitalways mode 10b */
332 /* databuffer length validation */
333 if (info->databuffer_size > ((16 * 1024) - 128)) {
337 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
339 /* max pkt. length validation */
340 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
344 rx_ctx.rxmax = info->max_pkt_size;
346 /* enable 32bytes desc always */
350 rx_ctx.lrxqthresh = 2;
355 /* clear the context in the HMC */
356 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
358 dev_err(&pf->pdev->dev,
359 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
365 /* set the context in the HMC */
366 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
368 dev_err(&pf->pdev->dev,
369 "Failed to set VF LAN Rx queue context %d error: %d\n",
381 * @vf: pointer to the vf info
382 * @type: type of VSI to allocate
384 * alloc vf vsi context & resources
386 static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
388 struct i40e_mac_filter *f = NULL;
389 struct i40e_pf *pf = vf->pf;
390 struct i40e_vsi *vsi;
393 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
396 dev_err(&pf->pdev->dev,
397 "add vsi failed for vf %d, aq_err %d\n",
398 vf->vf_id, pf->hw.aq.asq_last_status);
400 goto error_alloc_vsi_res;
402 if (type == I40E_VSI_SRIOV) {
403 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
404 vf->lan_vsi_index = vsi->idx;
405 vf->lan_vsi_id = vsi->id;
406 dev_info(&pf->pdev->dev,
407 "VF %d assigned LAN VSI index %d, VSI id %d\n",
408 vf->vf_id, vsi->idx, vsi->id);
409 /* If the port VLAN has been configured and then the
410 * VF driver was removed then the VSI port VLAN
411 * configuration was destroyed. Check if there is
412 * a port VLAN and restore the VSI configuration if
415 if (vf->port_vlan_id)
416 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
417 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
418 vf->port_vlan_id, true, false);
420 dev_info(&pf->pdev->dev,
421 "Could not allocate VF MAC addr\n");
422 f = i40e_add_filter(vsi, brdcast, vf->port_vlan_id,
425 dev_info(&pf->pdev->dev,
426 "Could not allocate VF broadcast filter\n");
429 /* program mac filter */
430 ret = i40e_sync_vsi_filters(vsi);
432 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
434 /* Set VF bandwidth if specified */
436 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
437 vf->tx_rate / 50, 0, NULL);
439 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
448 * i40e_enable_vf_mappings
449 * @vf: pointer to the vf info
453 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
455 struct i40e_pf *pf = vf->pf;
456 struct i40e_hw *hw = &pf->hw;
457 u32 reg, total_queue_pairs = 0;
460 /* Tell the hardware we're using noncontiguous mapping. HW requires
461 * that VF queues be mapped using this method, even when they are
462 * contiguous in real life
464 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
465 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
467 /* enable VF vplan_qtable mappings */
468 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
469 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
471 /* map PF queues to VF queues */
472 for (j = 0; j < pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs; j++) {
473 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index, j);
474 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
475 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
479 /* map PF queues to VSI */
480 for (j = 0; j < 7; j++) {
481 if (j * 2 >= pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs) {
482 reg = 0x07FF07FF; /* unused */
484 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
487 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
491 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
498 * i40e_disable_vf_mappings
499 * @vf: pointer to the vf info
501 * disable vf mappings
503 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
505 struct i40e_pf *pf = vf->pf;
506 struct i40e_hw *hw = &pf->hw;
509 /* disable qp mappings */
510 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
511 for (i = 0; i < I40E_MAX_VSI_QP; i++)
512 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
513 I40E_QUEUE_END_OF_LIST);
519 * @vf: pointer to the vf info
523 static void i40e_free_vf_res(struct i40e_vf *vf)
525 struct i40e_pf *pf = vf->pf;
526 struct i40e_hw *hw = &pf->hw;
530 /* free vsi & disconnect it from the parent uplink */
531 if (vf->lan_vsi_index) {
532 i40e_vsi_release(pf->vsi[vf->lan_vsi_index]);
533 vf->lan_vsi_index = 0;
536 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
538 /* disable interrupts so the VF starts in a known state */
539 for (i = 0; i < msix_vf; i++) {
540 /* format is same for both registers */
542 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
544 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
547 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
551 /* clear the irq settings */
552 for (i = 0; i < msix_vf; i++) {
553 /* format is same for both registers */
555 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
557 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
560 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
561 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
562 wr32(hw, reg_idx, reg);
565 /* reset some of the state varibles keeping
566 * track of the resources
568 vf->num_queue_pairs = 0;
574 * @vf: pointer to the vf info
576 * allocate vf resources
578 static int i40e_alloc_vf_res(struct i40e_vf *vf)
580 struct i40e_pf *pf = vf->pf;
581 int total_queue_pairs = 0;
584 /* allocate hw vsi context & associated resources */
585 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
588 total_queue_pairs += pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs;
589 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
591 /* store the total qps number for the runtime
594 vf->num_queue_pairs = total_queue_pairs;
596 /* vf is now completely initialized */
597 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
601 i40e_free_vf_res(vf);
606 #define VF_DEVICE_STATUS 0xAA
607 #define VF_TRANS_PENDING_MASK 0x20
609 * i40e_quiesce_vf_pci
610 * @vf: pointer to the vf structure
612 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
613 * if the transactions never clear.
615 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
617 struct i40e_pf *pf = vf->pf;
618 struct i40e_hw *hw = &pf->hw;
622 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
624 wr32(hw, I40E_PF_PCI_CIAA,
625 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
626 for (i = 0; i < 100; i++) {
627 reg = rd32(hw, I40E_PF_PCI_CIAD);
628 if ((reg & VF_TRANS_PENDING_MASK) == 0)
637 * @vf: pointer to the vf structure
638 * @flr: VFLR was issued or not
642 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
644 struct i40e_pf *pf = vf->pf;
645 struct i40e_hw *hw = &pf->hw;
651 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
653 /* In the case of a VFLR, the HW has already reset the VF and we
654 * just need to clean up, so don't hit the VFRTRIG register.
657 /* reset vf using VPGEN_VFRTRIG reg */
658 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
659 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
660 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
664 if (i40e_quiesce_vf_pci(vf))
665 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
668 /* poll VPGEN_VFRSTAT reg to make sure
669 * that reset is complete
671 for (i = 0; i < 100; i++) {
672 /* vf reset requires driver to first reset the
673 * vf and then poll the status register to make sure
674 * that the requested op was completed
677 usleep_range(10, 20);
678 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
679 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
686 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
688 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
689 /* clear the reset bit in the VPGEN_VFRTRIG reg */
690 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
691 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
692 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
694 /* On initial reset, we won't have any queues */
695 if (vf->lan_vsi_index == 0)
698 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_index], false);
700 /* reallocate vf resources to reset the VSI state */
701 i40e_free_vf_res(vf);
702 i40e_alloc_vf_res(vf);
703 i40e_enable_vf_mappings(vf);
704 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
706 /* tell the VF the reset is done */
707 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
712 * i40e_enable_pf_switch_lb
713 * @pf: pointer to the pf structure
715 * enable switch loop back or die - no point in a return value
717 void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
719 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
720 struct i40e_vsi_context ctxt;
723 ctxt.seid = pf->main_vsi_seid;
724 ctxt.pf_num = pf->hw.pf_id;
726 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
728 dev_info(&pf->pdev->dev,
729 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
730 __func__, aq_ret, pf->hw.aq.asq_last_status);
733 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
734 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
735 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
737 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
739 dev_info(&pf->pdev->dev,
740 "%s: update vsi switch failed, aq_err=%d\n",
741 __func__, vsi->back->hw.aq.asq_last_status);
746 * i40e_disable_pf_switch_lb
747 * @pf: pointer to the pf structure
749 * disable switch loop back or die - no point in a return value
751 static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
753 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
754 struct i40e_vsi_context ctxt;
757 ctxt.seid = pf->main_vsi_seid;
758 ctxt.pf_num = pf->hw.pf_id;
760 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
762 dev_info(&pf->pdev->dev,
763 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
764 __func__, aq_ret, pf->hw.aq.asq_last_status);
767 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
768 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
769 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
771 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
773 dev_info(&pf->pdev->dev,
774 "%s: update vsi switch failed, aq_err=%d\n",
775 __func__, vsi->back->hw.aq.asq_last_status);
781 * @pf: pointer to the pf structure
785 void i40e_free_vfs(struct i40e_pf *pf)
787 struct i40e_hw *hw = &pf->hw;
788 u32 reg_idx, bit_idx;
794 /* Disable interrupt 0 so we don't try to handle the VFLR. */
795 i40e_irq_dynamic_disable_icr0(pf);
797 mdelay(10); /* let any messages in transit get finished up */
798 /* free up vf resources */
799 tmp = pf->num_alloc_vfs;
800 pf->num_alloc_vfs = 0;
801 for (i = 0; i < tmp; i++) {
802 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
803 i40e_free_vf_res(&pf->vf[i]);
804 /* disable qp mappings */
805 i40e_disable_vf_mappings(&pf->vf[i]);
811 /* This check is for when the driver is unloaded while VFs are
812 * assigned. Setting the number of VFs to 0 through sysfs is caught
813 * before this function ever gets called.
815 if (!pci_vfs_assigned(pf->pdev)) {
816 pci_disable_sriov(pf->pdev);
817 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
818 * work correctly when SR-IOV gets re-enabled.
820 for (vf_id = 0; vf_id < tmp; vf_id++) {
821 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
822 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
823 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
825 i40e_disable_pf_switch_lb(pf);
827 dev_warn(&pf->pdev->dev,
828 "unable to disable SR-IOV because VFs are assigned.\n");
831 /* Re-enable interrupt 0. */
832 i40e_irq_dynamic_enable_icr0(pf);
835 #ifdef CONFIG_PCI_IOV
838 * @pf: pointer to the pf structure
839 * @num_alloc_vfs: number of vfs to allocate
841 * allocate vf resources
843 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
848 /* Disable interrupt 0 so we don't try to handle the VFLR. */
849 i40e_irq_dynamic_disable_icr0(pf);
851 /* Check to see if we're just allocating resources for extant VFs */
852 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
853 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
855 dev_err(&pf->pdev->dev,
856 "Failed to enable SR-IOV, error %d.\n", ret);
857 pf->num_alloc_vfs = 0;
861 /* allocate memory */
862 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
869 /* apply default profile */
870 for (i = 0; i < num_alloc_vfs; i++) {
872 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
875 /* assign default capabilities */
876 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
877 vfs[i].spoofchk = true;
878 /* vf resources get allocated during reset */
879 i40e_reset_vf(&vfs[i], false);
881 /* enable vf vplan_qtable mappings */
882 i40e_enable_vf_mappings(&vfs[i]);
884 pf->num_alloc_vfs = num_alloc_vfs;
886 i40e_enable_pf_switch_lb(pf);
891 /* Re-enable interrupt 0. */
892 i40e_irq_dynamic_enable_icr0(pf);
898 * i40e_pci_sriov_enable
899 * @pdev: pointer to a pci_dev structure
900 * @num_vfs: number of vfs to allocate
902 * Enable or change the number of VFs
904 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
906 #ifdef CONFIG_PCI_IOV
907 struct i40e_pf *pf = pci_get_drvdata(pdev);
908 int pre_existing_vfs = pci_num_vf(pdev);
911 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
912 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
914 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
917 if (num_vfs > pf->num_req_vfs) {
922 err = i40e_alloc_vfs(pf, num_vfs);
924 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
938 * i40e_pci_sriov_configure
939 * @pdev: pointer to a pci_dev structure
940 * @num_vfs: number of vfs to allocate
942 * Enable or change the number of VFs. Called when the user updates the number
945 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
947 struct i40e_pf *pf = pci_get_drvdata(pdev);
950 return i40e_pci_sriov_enable(pdev, num_vfs);
952 if (!pci_vfs_assigned(pf->pdev)) {
955 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
961 /***********************virtual channel routines******************/
964 * i40e_vc_send_msg_to_vf
965 * @vf: pointer to the vf info
966 * @v_opcode: virtual channel opcode
967 * @v_retval: virtual channel return value
968 * @msg: pointer to the msg buffer
969 * @msglen: msg length
973 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
974 u32 v_retval, u8 *msg, u16 msglen)
981 /* validate the request */
982 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
987 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
989 /* single place to detect unsuccessful return values */
991 vf->num_invalid_msgs++;
992 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
994 if (vf->num_invalid_msgs >
995 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
996 dev_err(&pf->pdev->dev,
997 "Number of invalid messages exceeded for VF %d\n",
999 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1000 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1003 vf->num_valid_msgs++;
1006 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1009 dev_err(&pf->pdev->dev,
1010 "Unable to send the message to VF %d aq_err %d\n",
1011 vf->vf_id, pf->hw.aq.asq_last_status);
1019 * i40e_vc_send_resp_to_vf
1020 * @vf: pointer to the vf info
1021 * @opcode: operation code
1022 * @retval: return value
1024 * send resp msg to vf
1026 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1027 enum i40e_virtchnl_ops opcode,
1030 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1034 * i40e_vc_get_version_msg
1035 * @vf: pointer to the vf info
1037 * called from the vf to request the API version used by the PF
1039 static int i40e_vc_get_version_msg(struct i40e_vf *vf)
1041 struct i40e_virtchnl_version_info info = {
1042 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1045 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1046 I40E_SUCCESS, (u8 *)&info,
1048 i40e_virtchnl_version_info));
1052 * i40e_vc_get_vf_resources_msg
1053 * @vf: pointer to the vf info
1054 * @msg: pointer to the msg buffer
1055 * @msglen: msg length
1057 * called from the vf to request its resources
1059 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf)
1061 struct i40e_virtchnl_vf_resource *vfres = NULL;
1062 struct i40e_pf *pf = vf->pf;
1063 i40e_status aq_ret = 0;
1064 struct i40e_vsi *vsi;
1069 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1070 aq_ret = I40E_ERR_PARAM;
1074 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1075 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1077 vfres = kzalloc(len, GFP_KERNEL);
1079 aq_ret = I40E_ERR_NO_MEMORY;
1084 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1085 vsi = pf->vsi[vf->lan_vsi_index];
1086 if (!vsi->info.pvid)
1087 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1089 vfres->num_vsis = num_vsis;
1090 vfres->num_queue_pairs = vf->num_queue_pairs;
1091 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1092 if (vf->lan_vsi_index) {
1093 vfres->vsi_res[i].vsi_id = vf->lan_vsi_index;
1094 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1095 vfres->vsi_res[i].num_queue_pairs =
1096 pf->vsi[vf->lan_vsi_index]->alloc_queue_pairs;
1097 memcpy(vfres->vsi_res[i].default_mac_addr,
1098 vf->default_lan_addr.addr, ETH_ALEN);
1101 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1104 /* send the response back to the vf */
1105 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1106 aq_ret, (u8 *)vfres, len);
1113 * i40e_vc_reset_vf_msg
1114 * @vf: pointer to the vf info
1115 * @msg: pointer to the msg buffer
1116 * @msglen: msg length
1118 * called from the vf to reset itself,
1119 * unlike other virtchnl messages, pf driver
1120 * doesn't send the response back to the vf
1122 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1124 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1125 i40e_reset_vf(vf, false);
1129 * i40e_vc_config_promiscuous_mode_msg
1130 * @vf: pointer to the vf info
1131 * @msg: pointer to the msg buffer
1132 * @msglen: msg length
1134 * called from the vf to configure the promiscuous mode of
1137 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1138 u8 *msg, u16 msglen)
1140 struct i40e_virtchnl_promisc_info *info =
1141 (struct i40e_virtchnl_promisc_info *)msg;
1142 struct i40e_pf *pf = vf->pf;
1143 struct i40e_hw *hw = &pf->hw;
1144 struct i40e_vsi *vsi;
1145 bool allmulti = false;
1148 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1149 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1150 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1151 (pf->vsi[info->vsi_id]->type != I40E_VSI_FCOE)) {
1152 aq_ret = I40E_ERR_PARAM;
1155 vsi = pf->vsi[info->vsi_id];
1156 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1158 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1162 /* send the response to the vf */
1163 return i40e_vc_send_resp_to_vf(vf,
1164 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1169 * i40e_vc_config_queues_msg
1170 * @vf: pointer to the vf info
1171 * @msg: pointer to the msg buffer
1172 * @msglen: msg length
1174 * called from the vf to configure the rx/tx
1177 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1179 struct i40e_virtchnl_vsi_queue_config_info *qci =
1180 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1181 struct i40e_virtchnl_queue_pair_info *qpi;
1182 struct i40e_pf *pf = vf->pf;
1183 u16 vsi_id, vsi_queue_id;
1184 i40e_status aq_ret = 0;
1187 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1188 aq_ret = I40E_ERR_PARAM;
1192 vsi_id = qci->vsi_id;
1193 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1194 aq_ret = I40E_ERR_PARAM;
1197 for (i = 0; i < qci->num_queue_pairs; i++) {
1198 qpi = &qci->qpair[i];
1199 vsi_queue_id = qpi->txq.queue_id;
1200 if ((qpi->txq.vsi_id != vsi_id) ||
1201 (qpi->rxq.vsi_id != vsi_id) ||
1202 (qpi->rxq.queue_id != vsi_queue_id) ||
1203 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1204 aq_ret = I40E_ERR_PARAM;
1208 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1210 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1212 aq_ret = I40E_ERR_PARAM;
1216 /* set vsi num_queue_pairs in use to num configured by vf */
1217 pf->vsi[vf->lan_vsi_index]->num_queue_pairs = qci->num_queue_pairs;
1220 /* send the response to the vf */
1221 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1226 * i40e_vc_config_irq_map_msg
1227 * @vf: pointer to the vf info
1228 * @msg: pointer to the msg buffer
1229 * @msglen: msg length
1231 * called from the vf to configure the irq to
1234 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1236 struct i40e_virtchnl_irq_map_info *irqmap_info =
1237 (struct i40e_virtchnl_irq_map_info *)msg;
1238 struct i40e_virtchnl_vector_map *map;
1239 u16 vsi_id, vsi_queue_id, vector_id;
1240 i40e_status aq_ret = 0;
1241 unsigned long tempmap;
1244 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1245 aq_ret = I40E_ERR_PARAM;
1249 for (i = 0; i < irqmap_info->num_vectors; i++) {
1250 map = &irqmap_info->vecmap[i];
1252 vector_id = map->vector_id;
1253 vsi_id = map->vsi_id;
1254 /* validate msg params */
1255 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1256 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1257 aq_ret = I40E_ERR_PARAM;
1261 /* lookout for the invalid queue index */
1262 tempmap = map->rxq_map;
1263 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1264 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1266 aq_ret = I40E_ERR_PARAM;
1271 tempmap = map->txq_map;
1272 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1273 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1275 aq_ret = I40E_ERR_PARAM;
1280 i40e_config_irq_link_list(vf, vsi_id, map);
1283 /* send the response to the vf */
1284 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1289 * i40e_vc_enable_queues_msg
1290 * @vf: pointer to the vf info
1291 * @msg: pointer to the msg buffer
1292 * @msglen: msg length
1294 * called from the vf to enable all or specific queue(s)
1296 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1298 struct i40e_virtchnl_queue_select *vqs =
1299 (struct i40e_virtchnl_queue_select *)msg;
1300 struct i40e_pf *pf = vf->pf;
1301 u16 vsi_id = vqs->vsi_id;
1302 i40e_status aq_ret = 0;
1304 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1305 aq_ret = I40E_ERR_PARAM;
1309 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1310 aq_ret = I40E_ERR_PARAM;
1314 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1315 aq_ret = I40E_ERR_PARAM;
1318 if (i40e_vsi_control_rings(pf->vsi[vsi_id], true))
1319 aq_ret = I40E_ERR_TIMEOUT;
1321 /* send the response to the vf */
1322 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1327 * i40e_vc_disable_queues_msg
1328 * @vf: pointer to the vf info
1329 * @msg: pointer to the msg buffer
1330 * @msglen: msg length
1332 * called from the vf to disable all or specific
1335 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1337 struct i40e_virtchnl_queue_select *vqs =
1338 (struct i40e_virtchnl_queue_select *)msg;
1339 struct i40e_pf *pf = vf->pf;
1340 u16 vsi_id = vqs->vsi_id;
1341 i40e_status aq_ret = 0;
1343 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1344 aq_ret = I40E_ERR_PARAM;
1348 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1349 aq_ret = I40E_ERR_PARAM;
1353 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1354 aq_ret = I40E_ERR_PARAM;
1357 if (i40e_vsi_control_rings(pf->vsi[vsi_id], false))
1358 aq_ret = I40E_ERR_TIMEOUT;
1361 /* send the response to the vf */
1362 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1367 * i40e_vc_get_stats_msg
1368 * @vf: pointer to the vf info
1369 * @msg: pointer to the msg buffer
1370 * @msglen: msg length
1372 * called from the vf to get vsi stats
1374 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1376 struct i40e_virtchnl_queue_select *vqs =
1377 (struct i40e_virtchnl_queue_select *)msg;
1378 struct i40e_pf *pf = vf->pf;
1379 struct i40e_eth_stats stats;
1380 i40e_status aq_ret = 0;
1381 struct i40e_vsi *vsi;
1383 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1385 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1386 aq_ret = I40E_ERR_PARAM;
1390 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1391 aq_ret = I40E_ERR_PARAM;
1395 vsi = pf->vsi[vqs->vsi_id];
1397 aq_ret = I40E_ERR_PARAM;
1400 i40e_update_eth_stats(vsi);
1401 stats = vsi->eth_stats;
1404 /* send the response back to the vf */
1405 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1406 (u8 *)&stats, sizeof(stats));
1410 * i40e_check_vf_permission
1411 * @vf: pointer to the vf info
1412 * @macaddr: pointer to the MAC Address being checked
1414 * Check if the VF has permission to add or delete unicast MAC address
1415 * filters and return error code -EPERM if not. Then check if the
1416 * address filter requested is broadcast or zero and if so return
1417 * an invalid MAC address error code.
1419 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1421 struct i40e_pf *pf = vf->pf;
1424 if (is_broadcast_ether_addr(macaddr) ||
1425 is_zero_ether_addr(macaddr)) {
1426 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1427 ret = I40E_ERR_INVALID_MAC_ADDR;
1428 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1429 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1430 /* If the host VMM administrator has set the VF MAC address
1431 * administratively via the ndo_set_vf_mac command then deny
1432 * permission to the VF to add or delete unicast MAC addresses.
1433 * The VF may request to set the MAC address filter already
1434 * assigned to it so do not return an error in that case.
1436 dev_err(&pf->pdev->dev,
1437 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1444 * i40e_vc_add_mac_addr_msg
1445 * @vf: pointer to the vf info
1446 * @msg: pointer to the msg buffer
1447 * @msglen: msg length
1449 * add guest mac address filter
1451 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1453 struct i40e_virtchnl_ether_addr_list *al =
1454 (struct i40e_virtchnl_ether_addr_list *)msg;
1455 struct i40e_pf *pf = vf->pf;
1456 struct i40e_vsi *vsi = NULL;
1457 u16 vsi_id = al->vsi_id;
1458 i40e_status ret = 0;
1461 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1462 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1463 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1464 ret = I40E_ERR_PARAM;
1468 for (i = 0; i < al->num_elements; i++) {
1469 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1473 vsi = pf->vsi[vsi_id];
1475 /* add new addresses to the list */
1476 for (i = 0; i < al->num_elements; i++) {
1477 struct i40e_mac_filter *f;
1479 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1481 if (i40e_is_vsi_in_vlan(vsi))
1482 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1485 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1490 dev_err(&pf->pdev->dev,
1491 "Unable to add VF MAC filter\n");
1492 ret = I40E_ERR_PARAM;
1497 /* program the updated filter list */
1498 if (i40e_sync_vsi_filters(vsi))
1499 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1502 /* send the response to the vf */
1503 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
1508 * i40e_vc_del_mac_addr_msg
1509 * @vf: pointer to the vf info
1510 * @msg: pointer to the msg buffer
1511 * @msglen: msg length
1513 * remove guest mac address filter
1515 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1517 struct i40e_virtchnl_ether_addr_list *al =
1518 (struct i40e_virtchnl_ether_addr_list *)msg;
1519 struct i40e_pf *pf = vf->pf;
1520 struct i40e_vsi *vsi = NULL;
1521 u16 vsi_id = al->vsi_id;
1522 i40e_status ret = 0;
1525 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1526 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1527 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1528 ret = I40E_ERR_PARAM;
1532 for (i = 0; i < al->num_elements; i++) {
1533 if (is_broadcast_ether_addr(al->list[i].addr) ||
1534 is_zero_ether_addr(al->list[i].addr)) {
1535 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1537 ret = I40E_ERR_INVALID_MAC_ADDR;
1541 vsi = pf->vsi[vsi_id];
1543 /* delete addresses from the list */
1544 for (i = 0; i < al->num_elements; i++)
1545 i40e_del_filter(vsi, al->list[i].addr,
1546 I40E_VLAN_ANY, true, false);
1548 /* program the updated filter list */
1549 if (i40e_sync_vsi_filters(vsi))
1550 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1553 /* send the response to the vf */
1554 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
1559 * i40e_vc_add_vlan_msg
1560 * @vf: pointer to the vf info
1561 * @msg: pointer to the msg buffer
1562 * @msglen: msg length
1564 * program guest vlan id
1566 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1568 struct i40e_virtchnl_vlan_filter_list *vfl =
1569 (struct i40e_virtchnl_vlan_filter_list *)msg;
1570 struct i40e_pf *pf = vf->pf;
1571 struct i40e_vsi *vsi = NULL;
1572 u16 vsi_id = vfl->vsi_id;
1573 i40e_status aq_ret = 0;
1576 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1577 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1578 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1579 aq_ret = I40E_ERR_PARAM;
1583 for (i = 0; i < vfl->num_elements; i++) {
1584 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1585 aq_ret = I40E_ERR_PARAM;
1586 dev_err(&pf->pdev->dev,
1587 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1591 vsi = pf->vsi[vsi_id];
1592 if (vsi->info.pvid) {
1593 aq_ret = I40E_ERR_PARAM;
1597 i40e_vlan_stripping_enable(vsi);
1598 for (i = 0; i < vfl->num_elements; i++) {
1599 /* add new VLAN filter */
1600 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1602 dev_err(&pf->pdev->dev,
1603 "Unable to add VF vlan filter %d, error %d\n",
1604 vfl->vlan_id[i], ret);
1608 /* send the response to the vf */
1609 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1613 * i40e_vc_remove_vlan_msg
1614 * @vf: pointer to the vf info
1615 * @msg: pointer to the msg buffer
1616 * @msglen: msg length
1618 * remove programmed guest vlan id
1620 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1622 struct i40e_virtchnl_vlan_filter_list *vfl =
1623 (struct i40e_virtchnl_vlan_filter_list *)msg;
1624 struct i40e_pf *pf = vf->pf;
1625 struct i40e_vsi *vsi = NULL;
1626 u16 vsi_id = vfl->vsi_id;
1627 i40e_status aq_ret = 0;
1630 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1631 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1632 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1633 aq_ret = I40E_ERR_PARAM;
1637 for (i = 0; i < vfl->num_elements; i++) {
1638 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1639 aq_ret = I40E_ERR_PARAM;
1644 vsi = pf->vsi[vsi_id];
1645 if (vsi->info.pvid) {
1646 aq_ret = I40E_ERR_PARAM;
1650 for (i = 0; i < vfl->num_elements; i++) {
1651 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1653 dev_err(&pf->pdev->dev,
1654 "Unable to delete VF vlan filter %d, error %d\n",
1655 vfl->vlan_id[i], ret);
1659 /* send the response to the vf */
1660 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1664 * i40e_vc_validate_vf_msg
1665 * @vf: pointer to the vf info
1666 * @msg: pointer to the msg buffer
1667 * @msglen: msg length
1668 * @msghndl: msg handle
1672 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1673 u32 v_retval, u8 *msg, u16 msglen)
1675 bool err_msg_format = false;
1678 /* Check if VF is disabled. */
1679 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1680 return I40E_ERR_PARAM;
1682 /* Validate message length. */
1684 case I40E_VIRTCHNL_OP_VERSION:
1685 valid_len = sizeof(struct i40e_virtchnl_version_info);
1687 case I40E_VIRTCHNL_OP_RESET_VF:
1688 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1691 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1692 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1694 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1695 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1697 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1698 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1699 if (msglen >= valid_len) {
1700 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1701 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1702 valid_len += (vqc->num_queue_pairs *
1704 i40e_virtchnl_queue_pair_info));
1705 if (vqc->num_queue_pairs == 0)
1706 err_msg_format = true;
1709 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1710 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1711 if (msglen >= valid_len) {
1712 struct i40e_virtchnl_irq_map_info *vimi =
1713 (struct i40e_virtchnl_irq_map_info *)msg;
1714 valid_len += (vimi->num_vectors *
1715 sizeof(struct i40e_virtchnl_vector_map));
1716 if (vimi->num_vectors == 0)
1717 err_msg_format = true;
1720 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1721 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1722 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1724 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1725 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1726 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1727 if (msglen >= valid_len) {
1728 struct i40e_virtchnl_ether_addr_list *veal =
1729 (struct i40e_virtchnl_ether_addr_list *)msg;
1730 valid_len += veal->num_elements *
1731 sizeof(struct i40e_virtchnl_ether_addr);
1732 if (veal->num_elements == 0)
1733 err_msg_format = true;
1736 case I40E_VIRTCHNL_OP_ADD_VLAN:
1737 case I40E_VIRTCHNL_OP_DEL_VLAN:
1738 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1739 if (msglen >= valid_len) {
1740 struct i40e_virtchnl_vlan_filter_list *vfl =
1741 (struct i40e_virtchnl_vlan_filter_list *)msg;
1742 valid_len += vfl->num_elements * sizeof(u16);
1743 if (vfl->num_elements == 0)
1744 err_msg_format = true;
1747 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1748 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1750 case I40E_VIRTCHNL_OP_GET_STATS:
1751 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1753 /* These are always errors coming from the VF. */
1754 case I40E_VIRTCHNL_OP_EVENT:
1755 case I40E_VIRTCHNL_OP_UNKNOWN:
1760 /* few more checks */
1761 if ((valid_len != msglen) || (err_msg_format)) {
1762 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1770 * i40e_vc_process_vf_msg
1771 * @pf: pointer to the pf structure
1772 * @vf_id: source vf id
1773 * @msg: pointer to the msg buffer
1774 * @msglen: msg length
1775 * @msghndl: msg handle
1777 * called from the common aeq/arq handler to
1778 * process request from vf
1780 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1781 u32 v_retval, u8 *msg, u16 msglen)
1783 struct i40e_hw *hw = &pf->hw;
1784 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
1788 pf->vf_aq_requests++;
1789 if (local_vf_id >= pf->num_alloc_vfs)
1791 vf = &(pf->vf[local_vf_id]);
1792 /* perform basic checks on the msg */
1793 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1796 dev_err(&pf->pdev->dev, "Invalid message from vf %d, opcode %d, len %d\n",
1797 local_vf_id, v_opcode, msglen);
1802 case I40E_VIRTCHNL_OP_VERSION:
1803 ret = i40e_vc_get_version_msg(vf);
1805 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1806 ret = i40e_vc_get_vf_resources_msg(vf);
1808 case I40E_VIRTCHNL_OP_RESET_VF:
1809 i40e_vc_reset_vf_msg(vf);
1812 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1813 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1815 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1816 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1818 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1819 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1821 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1822 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1824 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1825 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1827 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1828 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1830 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1831 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1833 case I40E_VIRTCHNL_OP_ADD_VLAN:
1834 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1836 case I40E_VIRTCHNL_OP_DEL_VLAN:
1837 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1839 case I40E_VIRTCHNL_OP_GET_STATS:
1840 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1842 case I40E_VIRTCHNL_OP_UNKNOWN:
1844 dev_err(&pf->pdev->dev, "Unsupported opcode %d from vf %d\n",
1845 v_opcode, local_vf_id);
1846 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1847 I40E_ERR_NOT_IMPLEMENTED);
1855 * i40e_vc_process_vflr_event
1856 * @pf: pointer to the pf structure
1858 * called from the vlfr irq handler to
1859 * free up vf resources and state variables
1861 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1863 u32 reg, reg_idx, bit_idx, vf_id;
1864 struct i40e_hw *hw = &pf->hw;
1867 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1870 /* re-enable vflr interrupt cause */
1871 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1872 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1873 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1876 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1877 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1878 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1879 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1880 /* read GLGEN_VFLRSTAT register to find out the flr vfs */
1881 vf = &pf->vf[vf_id];
1882 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1883 if (reg & (1 << bit_idx)) {
1884 /* clear the bit in GLGEN_VFLRSTAT */
1885 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
1887 if (!test_bit(__I40E_DOWN, &pf->state))
1888 i40e_reset_vf(vf, true);
1896 * i40e_vc_vf_broadcast
1897 * @pf: pointer to the pf structure
1898 * @opcode: operation code
1899 * @retval: return value
1900 * @msg: pointer to the msg buffer
1901 * @msglen: msg length
1903 * send a message to all VFs on a given PF
1905 static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1906 enum i40e_virtchnl_ops v_opcode,
1907 i40e_status v_retval, u8 *msg,
1910 struct i40e_hw *hw = &pf->hw;
1911 struct i40e_vf *vf = pf->vf;
1914 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1915 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1916 /* Not all vfs are enabled so skip the ones that are not */
1917 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
1918 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1921 /* Ignore return value on purpose - a given VF may fail, but
1922 * we need to keep going and send to all of them
1924 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1930 * i40e_vc_notify_link_state
1931 * @pf: pointer to the pf structure
1933 * send a link status message to all VFs on a given PF
1935 void i40e_vc_notify_link_state(struct i40e_pf *pf)
1937 struct i40e_virtchnl_pf_event pfe;
1938 struct i40e_hw *hw = &pf->hw;
1939 struct i40e_vf *vf = pf->vf;
1940 struct i40e_link_status *ls = &pf->hw.phy.link_info;
1943 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1944 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
1945 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
1946 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1947 if (vf->link_forced) {
1948 pfe.event_data.link_event.link_status = vf->link_up;
1949 pfe.event_data.link_event.link_speed =
1950 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
1952 pfe.event_data.link_event.link_status =
1953 ls->link_info & I40E_AQ_LINK_UP;
1954 pfe.event_data.link_event.link_speed = ls->link_speed;
1956 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
1957 0, (u8 *)&pfe, sizeof(pfe),
1963 * i40e_vc_notify_reset
1964 * @pf: pointer to the pf structure
1966 * indicate a pending reset to all VFs on a given PF
1968 void i40e_vc_notify_reset(struct i40e_pf *pf)
1970 struct i40e_virtchnl_pf_event pfe;
1972 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
1973 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
1974 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, I40E_SUCCESS,
1975 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
1979 * i40e_vc_notify_vf_reset
1980 * @vf: pointer to the vf structure
1982 * indicate a pending reset to the given VF
1984 void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
1986 struct i40e_virtchnl_pf_event pfe;
1989 /* validate the request */
1990 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1993 /* verify if the VF is in either init or active before proceeding */
1994 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
1995 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1998 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
2000 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
2001 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
2002 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2003 I40E_SUCCESS, (u8 *)&pfe,
2004 sizeof(struct i40e_virtchnl_pf_event), NULL);
2008 * i40e_ndo_set_vf_mac
2009 * @netdev: network interface device structure
2010 * @vf_id: vf identifier
2013 * program vf mac address
2015 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2017 struct i40e_netdev_priv *np = netdev_priv(netdev);
2018 struct i40e_vsi *vsi = np->vsi;
2019 struct i40e_pf *pf = vsi->back;
2020 struct i40e_mac_filter *f;
2024 /* validate the request */
2025 if (vf_id >= pf->num_alloc_vfs) {
2026 dev_err(&pf->pdev->dev,
2027 "Invalid VF Identifier %d\n", vf_id);
2032 vf = &(pf->vf[vf_id]);
2033 vsi = pf->vsi[vf->lan_vsi_index];
2034 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2035 dev_err(&pf->pdev->dev,
2036 "Uninitialized VF %d\n", vf_id);
2041 if (!is_valid_ether_addr(mac)) {
2042 dev_err(&pf->pdev->dev,
2043 "Invalid VF ethernet address\n");
2048 /* delete the temporary mac address */
2049 i40e_del_filter(vsi, vf->default_lan_addr.addr, vf->port_vlan_id,
2052 /* Delete all the filters for this VSI - we're going to kill it
2055 list_for_each_entry(f, &vsi->mac_filter_list, list)
2056 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2058 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2059 /* program mac filter */
2060 if (i40e_sync_vsi_filters(vsi)) {
2061 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2065 ether_addr_copy(vf->default_lan_addr.addr, mac);
2066 vf->pf_set_mac = true;
2067 /* Force the VF driver stop so it has to reload with new MAC address */
2068 i40e_vc_disable_vf(pf, vf);
2069 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2076 * i40e_ndo_set_vf_port_vlan
2077 * @netdev: network interface device structure
2078 * @vf_id: vf identifier
2079 * @vlan_id: mac address
2080 * @qos: priority setting
2082 * program vf vlan id and/or qos
2084 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2085 int vf_id, u16 vlan_id, u8 qos)
2087 struct i40e_netdev_priv *np = netdev_priv(netdev);
2088 struct i40e_pf *pf = np->vsi->back;
2089 struct i40e_vsi *vsi;
2093 /* validate the request */
2094 if (vf_id >= pf->num_alloc_vfs) {
2095 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2100 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2101 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2106 vf = &(pf->vf[vf_id]);
2107 vsi = pf->vsi[vf->lan_vsi_index];
2108 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2109 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2114 if (vsi->info.pvid == 0 && i40e_is_vsi_in_vlan(vsi)) {
2115 dev_err(&pf->pdev->dev,
2116 "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",
2118 /* Administrator Error - knock the VF offline until he does
2119 * the right thing by reconfiguring his network correctly
2120 * and then reloading the VF driver.
2122 i40e_vc_disable_vf(pf, vf);
2125 /* Check for condition where there was already a port VLAN ID
2126 * filter set and now it is being deleted by setting it to zero.
2127 * Additionally check for the condition where there was a port
2128 * VLAN but now there is a new and different port VLAN being set.
2129 * Before deleting all the old VLAN filters we must add new ones
2130 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2131 * MAC addresses deleted.
2133 if ((!(vlan_id || qos) ||
2134 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2136 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2138 if (vsi->info.pvid) {
2140 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2143 dev_info(&vsi->back->pdev->dev,
2144 "remove VLAN failed, ret=%d, aq_err=%d\n",
2145 ret, pf->hw.aq.asq_last_status);
2149 ret = i40e_vsi_add_pvid(vsi,
2150 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2152 i40e_vsi_remove_pvid(vsi);
2155 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2156 vlan_id, qos, vf_id);
2158 /* add new VLAN filter */
2159 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2161 dev_info(&vsi->back->pdev->dev,
2162 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2163 vsi->back->hw.aq.asq_last_status);
2166 /* Kill non-vlan MAC filters - ignore error return since
2167 * there might not be any non-vlan MAC filters.
2169 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2173 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2176 /* The Port VLAN needs to be saved across resets the same as the
2177 * default LAN MAC address.
2179 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2186 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2187 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2189 * i40e_ndo_set_vf_bw
2190 * @netdev: network interface device structure
2191 * @vf_id: vf identifier
2194 * configure vf tx rate
2196 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2199 struct i40e_netdev_priv *np = netdev_priv(netdev);
2200 struct i40e_pf *pf = np->vsi->back;
2201 struct i40e_vsi *vsi;
2206 /* validate the request */
2207 if (vf_id >= pf->num_alloc_vfs) {
2208 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2214 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for vf %d.\n",
2215 min_tx_rate, vf_id);
2219 vf = &(pf->vf[vf_id]);
2220 vsi = pf->vsi[vf->lan_vsi_index];
2221 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2222 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2227 switch (pf->hw.phy.link_info.link_speed) {
2228 case I40E_LINK_SPEED_40GB:
2231 case I40E_LINK_SPEED_10GB:
2234 case I40E_LINK_SPEED_1GB:
2241 if (max_tx_rate > speed) {
2242 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for vf %d.",
2243 max_tx_rate, vf->vf_id);
2248 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2249 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2253 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2254 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2255 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2256 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2258 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2263 vf->tx_rate = max_tx_rate;
2269 * i40e_ndo_get_vf_config
2270 * @netdev: network interface device structure
2271 * @vf_id: vf identifier
2272 * @ivi: vf configuration structure
2274 * return vf configuration
2276 int i40e_ndo_get_vf_config(struct net_device *netdev,
2277 int vf_id, struct ifla_vf_info *ivi)
2279 struct i40e_netdev_priv *np = netdev_priv(netdev);
2280 struct i40e_vsi *vsi = np->vsi;
2281 struct i40e_pf *pf = vsi->back;
2285 /* validate the request */
2286 if (vf_id >= pf->num_alloc_vfs) {
2287 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2292 vf = &(pf->vf[vf_id]);
2293 /* first vsi is always the LAN vsi */
2294 vsi = pf->vsi[vf->lan_vsi_index];
2295 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2296 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2303 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
2305 ivi->max_tx_rate = vf->tx_rate;
2306 ivi->min_tx_rate = 0;
2307 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2308 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2309 I40E_VLAN_PRIORITY_SHIFT;
2310 if (vf->link_forced == false)
2311 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2312 else if (vf->link_up == true)
2313 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2315 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
2316 ivi->spoofchk = vf->spoofchk;
2324 * i40e_ndo_set_vf_link_state
2325 * @netdev: network interface device structure
2326 * @vf_id: vf identifier
2327 * @link: required link state
2329 * Set the link state of a specified VF, regardless of physical link state
2331 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2333 struct i40e_netdev_priv *np = netdev_priv(netdev);
2334 struct i40e_pf *pf = np->vsi->back;
2335 struct i40e_virtchnl_pf_event pfe;
2336 struct i40e_hw *hw = &pf->hw;
2341 /* validate the request */
2342 if (vf_id >= pf->num_alloc_vfs) {
2343 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2348 vf = &pf->vf[vf_id];
2349 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
2351 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2352 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2355 case IFLA_VF_LINK_STATE_AUTO:
2356 vf->link_forced = false;
2357 pfe.event_data.link_event.link_status =
2358 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2359 pfe.event_data.link_event.link_speed =
2360 pf->hw.phy.link_info.link_speed;
2362 case IFLA_VF_LINK_STATE_ENABLE:
2363 vf->link_forced = true;
2365 pfe.event_data.link_event.link_status = true;
2366 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2368 case IFLA_VF_LINK_STATE_DISABLE:
2369 vf->link_forced = true;
2370 vf->link_up = false;
2371 pfe.event_data.link_event.link_status = false;
2372 pfe.event_data.link_event.link_speed = 0;
2378 /* Notify the VF of its new link state */
2379 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2380 0, (u8 *)&pfe, sizeof(pfe), NULL);
2387 * i40e_ndo_set_vf_spoofchk
2388 * @netdev: network interface device structure
2389 * @vf_id: vf identifier
2390 * @enable: flag to enable or disable feature
2392 * Enable or disable VF spoof checking
2394 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
2396 struct i40e_netdev_priv *np = netdev_priv(netdev);
2397 struct i40e_vsi *vsi = np->vsi;
2398 struct i40e_pf *pf = vsi->back;
2399 struct i40e_vsi_context ctxt;
2400 struct i40e_hw *hw = &pf->hw;
2404 /* validate the request */
2405 if (vf_id >= pf->num_alloc_vfs) {
2406 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2411 vf = &(pf->vf[vf_id]);
2413 if (enable == vf->spoofchk)
2416 vf->spoofchk = enable;
2417 memset(&ctxt, 0, sizeof(ctxt));
2418 ctxt.seid = pf->vsi[vf->lan_vsi_index]->seid;
2419 ctxt.pf_num = pf->hw.pf_id;
2420 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2422 ctxt.info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
2423 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2425 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",