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]->num_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;
354 /* clear the context in the HMC */
355 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
357 dev_err(&pf->pdev->dev,
358 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
364 /* set the context in the HMC */
365 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
367 dev_err(&pf->pdev->dev,
368 "Failed to set VF LAN Rx queue context %d error: %d\n",
380 * @vf: pointer to the vf info
381 * @type: type of VSI to allocate
383 * alloc vf vsi context & resources
385 static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
387 struct i40e_mac_filter *f = NULL;
388 struct i40e_pf *pf = vf->pf;
389 struct i40e_vsi *vsi;
392 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
395 dev_err(&pf->pdev->dev,
396 "add vsi failed for vf %d, aq_err %d\n",
397 vf->vf_id, pf->hw.aq.asq_last_status);
399 goto error_alloc_vsi_res;
401 if (type == I40E_VSI_SRIOV) {
402 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
403 vf->lan_vsi_index = vsi->idx;
404 vf->lan_vsi_id = vsi->id;
405 dev_info(&pf->pdev->dev,
406 "VF %d assigned LAN VSI index %d, VSI id %d\n",
407 vf->vf_id, vsi->idx, vsi->id);
408 /* If the port VLAN has been configured and then the
409 * VF driver was removed then the VSI port VLAN
410 * configuration was destroyed. Check if there is
411 * a port VLAN and restore the VSI configuration if
414 if (vf->port_vlan_id)
415 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
416 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
417 vf->port_vlan_id, true, false);
419 dev_info(&pf->pdev->dev,
420 "Could not allocate VF MAC addr\n");
421 f = i40e_add_filter(vsi, brdcast, vf->port_vlan_id,
424 dev_info(&pf->pdev->dev,
425 "Could not allocate VF broadcast filter\n");
428 /* program mac filter */
429 ret = i40e_sync_vsi_filters(vsi);
431 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
433 /* Set VF bandwidth if specified */
435 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
436 vf->tx_rate / 50, 0, NULL);
438 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
447 * i40e_enable_vf_mappings
448 * @vf: pointer to the vf info
452 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
454 struct i40e_pf *pf = vf->pf;
455 struct i40e_hw *hw = &pf->hw;
456 u32 reg, total_queue_pairs = 0;
459 /* Tell the hardware we're using noncontiguous mapping. HW requires
460 * that VF queues be mapped using this method, even when they are
461 * contiguous in real life
463 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
464 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
466 /* enable VF vplan_qtable mappings */
467 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
468 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
470 /* map PF queues to VF queues */
471 for (j = 0; j < pf->vsi[vf->lan_vsi_index]->num_queue_pairs; j++) {
472 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index, j);
473 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
474 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
478 /* map PF queues to VSI */
479 for (j = 0; j < 7; j++) {
480 if (j * 2 >= pf->vsi[vf->lan_vsi_index]->num_queue_pairs) {
481 reg = 0x07FF07FF; /* unused */
483 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
486 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_index,
490 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
497 * i40e_disable_vf_mappings
498 * @vf: pointer to the vf info
500 * disable vf mappings
502 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
504 struct i40e_pf *pf = vf->pf;
505 struct i40e_hw *hw = &pf->hw;
508 /* disable qp mappings */
509 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
510 for (i = 0; i < I40E_MAX_VSI_QP; i++)
511 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
512 I40E_QUEUE_END_OF_LIST);
518 * @vf: pointer to the vf info
522 static void i40e_free_vf_res(struct i40e_vf *vf)
524 struct i40e_pf *pf = vf->pf;
525 struct i40e_hw *hw = &pf->hw;
529 /* free vsi & disconnect it from the parent uplink */
530 if (vf->lan_vsi_index) {
531 i40e_vsi_release(pf->vsi[vf->lan_vsi_index]);
532 vf->lan_vsi_index = 0;
535 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
537 /* disable interrupts so the VF starts in a known state */
538 for (i = 0; i < msix_vf; i++) {
539 /* format is same for both registers */
541 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
543 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
546 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
550 /* clear the irq settings */
551 for (i = 0; i < msix_vf; i++) {
552 /* format is same for both registers */
554 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
556 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
559 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
560 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
561 wr32(hw, reg_idx, reg);
564 /* reset some of the state varibles keeping
565 * track of the resources
567 vf->num_queue_pairs = 0;
573 * @vf: pointer to the vf info
575 * allocate vf resources
577 static int i40e_alloc_vf_res(struct i40e_vf *vf)
579 struct i40e_pf *pf = vf->pf;
580 int total_queue_pairs = 0;
583 /* allocate hw vsi context & associated resources */
584 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
587 total_queue_pairs += pf->vsi[vf->lan_vsi_index]->num_queue_pairs;
588 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
590 /* store the total qps number for the runtime
593 vf->num_queue_pairs = total_queue_pairs;
595 /* vf is now completely initialized */
596 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
600 i40e_free_vf_res(vf);
605 #define VF_DEVICE_STATUS 0xAA
606 #define VF_TRANS_PENDING_MASK 0x20
608 * i40e_quiesce_vf_pci
609 * @vf: pointer to the vf structure
611 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
612 * if the transactions never clear.
614 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
616 struct i40e_pf *pf = vf->pf;
617 struct i40e_hw *hw = &pf->hw;
621 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
623 wr32(hw, I40E_PF_PCI_CIAA,
624 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
625 for (i = 0; i < 100; i++) {
626 reg = rd32(hw, I40E_PF_PCI_CIAD);
627 if ((reg & VF_TRANS_PENDING_MASK) == 0)
636 * @vf: pointer to the vf structure
637 * @flr: VFLR was issued or not
641 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
643 struct i40e_pf *pf = vf->pf;
644 struct i40e_hw *hw = &pf->hw;
650 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
652 /* In the case of a VFLR, the HW has already reset the VF and we
653 * just need to clean up, so don't hit the VFRTRIG register.
656 /* reset vf using VPGEN_VFRTRIG reg */
657 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
658 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
659 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
663 if (i40e_quiesce_vf_pci(vf))
664 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
667 /* poll VPGEN_VFRSTAT reg to make sure
668 * that reset is complete
670 for (i = 0; i < 100; i++) {
671 /* vf reset requires driver to first reset the
672 * vf and then poll the status register to make sure
673 * that the requested op was completed
677 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
678 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
685 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
687 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
688 /* clear the reset bit in the VPGEN_VFRTRIG reg */
689 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
690 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
691 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
693 /* On initial reset, we won't have any queues */
694 if (vf->lan_vsi_index == 0)
697 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_index], false);
699 /* reallocate vf resources to reset the VSI state */
700 i40e_free_vf_res(vf);
701 i40e_alloc_vf_res(vf);
702 i40e_enable_vf_mappings(vf);
703 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
705 /* tell the VF the reset is done */
706 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
711 * i40e_vfs_are_assigned
712 * @pf: pointer to the pf structure
714 * Determine if any VFs are assigned to VMs
716 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
718 struct pci_dev *pdev = pf->pdev;
719 struct pci_dev *vfdev;
721 /* loop through all the VFs to see if we own any that are assigned */
722 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
724 /* if we don't own it we don't care */
725 if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
726 /* if it is assigned we cannot release it */
727 if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
731 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
738 #ifdef CONFIG_PCI_IOV
741 * i40e_enable_pf_switch_lb
742 * @pf: pointer to the pf structure
744 * enable switch loop back or die - no point in a return value
746 static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
748 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
749 struct i40e_vsi_context ctxt;
752 ctxt.seid = pf->main_vsi_seid;
753 ctxt.pf_num = pf->hw.pf_id;
755 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
757 dev_info(&pf->pdev->dev,
758 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
759 __func__, aq_ret, pf->hw.aq.asq_last_status);
762 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
763 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
764 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
766 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
768 dev_info(&pf->pdev->dev,
769 "%s: update vsi switch failed, aq_err=%d\n",
770 __func__, vsi->back->hw.aq.asq_last_status);
776 * i40e_disable_pf_switch_lb
777 * @pf: pointer to the pf structure
779 * disable switch loop back or die - no point in a return value
781 static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
783 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
784 struct i40e_vsi_context ctxt;
787 ctxt.seid = pf->main_vsi_seid;
788 ctxt.pf_num = pf->hw.pf_id;
790 aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
792 dev_info(&pf->pdev->dev,
793 "%s couldn't get pf vsi config, err %d, aq_err %d\n",
794 __func__, aq_ret, pf->hw.aq.asq_last_status);
797 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
798 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
799 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
801 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
803 dev_info(&pf->pdev->dev,
804 "%s: update vsi switch failed, aq_err=%d\n",
805 __func__, vsi->back->hw.aq.asq_last_status);
811 * @pf: pointer to the pf structure
815 void i40e_free_vfs(struct i40e_pf *pf)
817 struct i40e_hw *hw = &pf->hw;
818 u32 reg_idx, bit_idx;
824 /* Disable interrupt 0 so we don't try to handle the VFLR. */
825 i40e_irq_dynamic_disable_icr0(pf);
827 mdelay(10); /* let any messages in transit get finished up */
828 /* free up vf resources */
829 tmp = pf->num_alloc_vfs;
830 pf->num_alloc_vfs = 0;
831 for (i = 0; i < tmp; i++) {
832 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
833 i40e_free_vf_res(&pf->vf[i]);
834 /* disable qp mappings */
835 i40e_disable_vf_mappings(&pf->vf[i]);
841 /* This check is for when the driver is unloaded while VFs are
842 * assigned. Setting the number of VFs to 0 through sysfs is caught
843 * before this function ever gets called.
845 if (!i40e_vfs_are_assigned(pf)) {
846 pci_disable_sriov(pf->pdev);
847 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
848 * work correctly when SR-IOV gets re-enabled.
850 for (vf_id = 0; vf_id < tmp; vf_id++) {
851 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
852 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
853 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
855 i40e_disable_pf_switch_lb(pf);
857 dev_warn(&pf->pdev->dev,
858 "unable to disable SR-IOV because VFs are assigned.\n");
861 /* Re-enable interrupt 0. */
862 i40e_irq_dynamic_enable_icr0(pf);
865 #ifdef CONFIG_PCI_IOV
868 * @pf: pointer to the pf structure
869 * @num_alloc_vfs: number of vfs to allocate
871 * allocate vf resources
873 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
878 /* Disable interrupt 0 so we don't try to handle the VFLR. */
879 i40e_irq_dynamic_disable_icr0(pf);
881 /* Check to see if we're just allocating resources for extant VFs */
882 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
883 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
885 dev_err(&pf->pdev->dev,
886 "Failed to enable SR-IOV, error %d.\n", ret);
887 pf->num_alloc_vfs = 0;
891 /* allocate memory */
892 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
899 /* apply default profile */
900 for (i = 0; i < num_alloc_vfs; i++) {
902 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
905 /* assign default capabilities */
906 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
907 vfs[i].spoofchk = true;
908 /* vf resources get allocated during reset */
909 i40e_reset_vf(&vfs[i], false);
911 /* enable vf vplan_qtable mappings */
912 i40e_enable_vf_mappings(&vfs[i]);
914 pf->num_alloc_vfs = num_alloc_vfs;
916 i40e_enable_pf_switch_lb(pf);
921 /* Re-enable interrupt 0. */
922 i40e_irq_dynamic_enable_icr0(pf);
928 * i40e_pci_sriov_enable
929 * @pdev: pointer to a pci_dev structure
930 * @num_vfs: number of vfs to allocate
932 * Enable or change the number of VFs
934 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
936 #ifdef CONFIG_PCI_IOV
937 struct i40e_pf *pf = pci_get_drvdata(pdev);
938 int pre_existing_vfs = pci_num_vf(pdev);
941 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
942 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
944 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
947 if (num_vfs > pf->num_req_vfs) {
952 err = i40e_alloc_vfs(pf, num_vfs);
954 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
968 * i40e_pci_sriov_configure
969 * @pdev: pointer to a pci_dev structure
970 * @num_vfs: number of vfs to allocate
972 * Enable or change the number of VFs. Called when the user updates the number
975 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
977 struct i40e_pf *pf = pci_get_drvdata(pdev);
980 return i40e_pci_sriov_enable(pdev, num_vfs);
982 if (!i40e_vfs_are_assigned(pf)) {
985 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
991 /***********************virtual channel routines******************/
994 * i40e_vc_send_msg_to_vf
995 * @vf: pointer to the vf info
996 * @v_opcode: virtual channel opcode
997 * @v_retval: virtual channel return value
998 * @msg: pointer to the msg buffer
999 * @msglen: msg length
1003 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1004 u32 v_retval, u8 *msg, u16 msglen)
1006 struct i40e_pf *pf = vf->pf;
1007 struct i40e_hw *hw = &pf->hw;
1008 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1011 /* single place to detect unsuccessful return values */
1013 vf->num_invalid_msgs++;
1014 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1015 v_opcode, v_retval);
1016 if (vf->num_invalid_msgs >
1017 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1018 dev_err(&pf->pdev->dev,
1019 "Number of invalid messages exceeded for VF %d\n",
1021 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1022 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1025 vf->num_valid_msgs++;
1028 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1031 dev_err(&pf->pdev->dev,
1032 "Unable to send the message to VF %d aq_err %d\n",
1033 vf->vf_id, pf->hw.aq.asq_last_status);
1041 * i40e_vc_send_resp_to_vf
1042 * @vf: pointer to the vf info
1043 * @opcode: operation code
1044 * @retval: return value
1046 * send resp msg to vf
1048 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1049 enum i40e_virtchnl_ops opcode,
1052 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1056 * i40e_vc_get_version_msg
1057 * @vf: pointer to the vf info
1059 * called from the vf to request the API version used by the PF
1061 static int i40e_vc_get_version_msg(struct i40e_vf *vf)
1063 struct i40e_virtchnl_version_info info = {
1064 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1067 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1068 I40E_SUCCESS, (u8 *)&info,
1070 i40e_virtchnl_version_info));
1074 * i40e_vc_get_vf_resources_msg
1075 * @vf: pointer to the vf info
1076 * @msg: pointer to the msg buffer
1077 * @msglen: msg length
1079 * called from the vf to request its resources
1081 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf)
1083 struct i40e_virtchnl_vf_resource *vfres = NULL;
1084 struct i40e_pf *pf = vf->pf;
1085 i40e_status aq_ret = 0;
1086 struct i40e_vsi *vsi;
1091 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1092 aq_ret = I40E_ERR_PARAM;
1096 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1097 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1099 vfres = kzalloc(len, GFP_KERNEL);
1101 aq_ret = I40E_ERR_NO_MEMORY;
1106 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1107 vsi = pf->vsi[vf->lan_vsi_index];
1108 if (!vsi->info.pvid)
1109 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1111 vfres->num_vsis = num_vsis;
1112 vfres->num_queue_pairs = vf->num_queue_pairs;
1113 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1114 if (vf->lan_vsi_index) {
1115 vfres->vsi_res[i].vsi_id = vf->lan_vsi_index;
1116 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1117 vfres->vsi_res[i].num_queue_pairs =
1118 pf->vsi[vf->lan_vsi_index]->num_queue_pairs;
1119 memcpy(vfres->vsi_res[i].default_mac_addr,
1120 vf->default_lan_addr.addr, ETH_ALEN);
1123 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1126 /* send the response back to the vf */
1127 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1128 aq_ret, (u8 *)vfres, len);
1135 * i40e_vc_reset_vf_msg
1136 * @vf: pointer to the vf info
1137 * @msg: pointer to the msg buffer
1138 * @msglen: msg length
1140 * called from the vf to reset itself,
1141 * unlike other virtchnl messages, pf driver
1142 * doesn't send the response back to the vf
1144 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1146 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1147 i40e_reset_vf(vf, false);
1151 * i40e_vc_config_promiscuous_mode_msg
1152 * @vf: pointer to the vf info
1153 * @msg: pointer to the msg buffer
1154 * @msglen: msg length
1156 * called from the vf to configure the promiscuous mode of
1159 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1160 u8 *msg, u16 msglen)
1162 struct i40e_virtchnl_promisc_info *info =
1163 (struct i40e_virtchnl_promisc_info *)msg;
1164 struct i40e_pf *pf = vf->pf;
1165 struct i40e_hw *hw = &pf->hw;
1166 struct i40e_vsi *vsi;
1167 bool allmulti = false;
1170 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1171 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1172 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1173 (pf->vsi[info->vsi_id]->type != I40E_VSI_FCOE)) {
1174 aq_ret = I40E_ERR_PARAM;
1177 vsi = pf->vsi[info->vsi_id];
1178 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1180 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1184 /* send the response to the vf */
1185 return i40e_vc_send_resp_to_vf(vf,
1186 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1191 * i40e_vc_config_queues_msg
1192 * @vf: pointer to the vf info
1193 * @msg: pointer to the msg buffer
1194 * @msglen: msg length
1196 * called from the vf to configure the rx/tx
1199 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1201 struct i40e_virtchnl_vsi_queue_config_info *qci =
1202 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1203 struct i40e_virtchnl_queue_pair_info *qpi;
1204 u16 vsi_id, vsi_queue_id;
1205 i40e_status aq_ret = 0;
1208 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1209 aq_ret = I40E_ERR_PARAM;
1213 vsi_id = qci->vsi_id;
1214 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1215 aq_ret = I40E_ERR_PARAM;
1218 for (i = 0; i < qci->num_queue_pairs; i++) {
1219 qpi = &qci->qpair[i];
1220 vsi_queue_id = qpi->txq.queue_id;
1221 if ((qpi->txq.vsi_id != vsi_id) ||
1222 (qpi->rxq.vsi_id != vsi_id) ||
1223 (qpi->rxq.queue_id != vsi_queue_id) ||
1224 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1225 aq_ret = I40E_ERR_PARAM;
1229 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1231 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1233 aq_ret = I40E_ERR_PARAM;
1239 /* send the response to the vf */
1240 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1245 * i40e_vc_config_irq_map_msg
1246 * @vf: pointer to the vf info
1247 * @msg: pointer to the msg buffer
1248 * @msglen: msg length
1250 * called from the vf to configure the irq to
1253 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1255 struct i40e_virtchnl_irq_map_info *irqmap_info =
1256 (struct i40e_virtchnl_irq_map_info *)msg;
1257 struct i40e_virtchnl_vector_map *map;
1258 u16 vsi_id, vsi_queue_id, vector_id;
1259 i40e_status aq_ret = 0;
1260 unsigned long tempmap;
1263 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1264 aq_ret = I40E_ERR_PARAM;
1268 for (i = 0; i < irqmap_info->num_vectors; i++) {
1269 map = &irqmap_info->vecmap[i];
1271 vector_id = map->vector_id;
1272 vsi_id = map->vsi_id;
1273 /* validate msg params */
1274 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1275 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1276 aq_ret = I40E_ERR_PARAM;
1280 /* lookout for the invalid queue index */
1281 tempmap = map->rxq_map;
1282 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1283 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1285 aq_ret = I40E_ERR_PARAM;
1290 tempmap = map->txq_map;
1291 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1292 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1294 aq_ret = I40E_ERR_PARAM;
1299 i40e_config_irq_link_list(vf, vsi_id, map);
1302 /* send the response to the vf */
1303 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1308 * i40e_vc_enable_queues_msg
1309 * @vf: pointer to the vf info
1310 * @msg: pointer to the msg buffer
1311 * @msglen: msg length
1313 * called from the vf to enable all or specific queue(s)
1315 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1317 struct i40e_virtchnl_queue_select *vqs =
1318 (struct i40e_virtchnl_queue_select *)msg;
1319 struct i40e_pf *pf = vf->pf;
1320 u16 vsi_id = vqs->vsi_id;
1321 i40e_status aq_ret = 0;
1323 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1324 aq_ret = I40E_ERR_PARAM;
1328 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1329 aq_ret = I40E_ERR_PARAM;
1333 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1334 aq_ret = I40E_ERR_PARAM;
1337 if (i40e_vsi_control_rings(pf->vsi[vsi_id], true))
1338 aq_ret = I40E_ERR_TIMEOUT;
1340 /* send the response to the vf */
1341 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1346 * i40e_vc_disable_queues_msg
1347 * @vf: pointer to the vf info
1348 * @msg: pointer to the msg buffer
1349 * @msglen: msg length
1351 * called from the vf to disable all or specific
1354 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1356 struct i40e_virtchnl_queue_select *vqs =
1357 (struct i40e_virtchnl_queue_select *)msg;
1358 struct i40e_pf *pf = vf->pf;
1359 u16 vsi_id = vqs->vsi_id;
1360 i40e_status aq_ret = 0;
1362 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1363 aq_ret = I40E_ERR_PARAM;
1367 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1368 aq_ret = I40E_ERR_PARAM;
1372 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1373 aq_ret = I40E_ERR_PARAM;
1376 if (i40e_vsi_control_rings(pf->vsi[vsi_id], false))
1377 aq_ret = I40E_ERR_TIMEOUT;
1380 /* send the response to the vf */
1381 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1386 * i40e_vc_get_stats_msg
1387 * @vf: pointer to the vf info
1388 * @msg: pointer to the msg buffer
1389 * @msglen: msg length
1391 * called from the vf to get vsi stats
1393 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1395 struct i40e_virtchnl_queue_select *vqs =
1396 (struct i40e_virtchnl_queue_select *)msg;
1397 struct i40e_pf *pf = vf->pf;
1398 struct i40e_eth_stats stats;
1399 i40e_status aq_ret = 0;
1400 struct i40e_vsi *vsi;
1402 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1404 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1405 aq_ret = I40E_ERR_PARAM;
1409 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1410 aq_ret = I40E_ERR_PARAM;
1414 vsi = pf->vsi[vqs->vsi_id];
1416 aq_ret = I40E_ERR_PARAM;
1419 i40e_update_eth_stats(vsi);
1420 stats = vsi->eth_stats;
1423 /* send the response back to the vf */
1424 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1425 (u8 *)&stats, sizeof(stats));
1429 * i40e_check_vf_permission
1430 * @vf: pointer to the vf info
1431 * @macaddr: pointer to the MAC Address being checked
1433 * Check if the VF has permission to add or delete unicast MAC address
1434 * filters and return error code -EPERM if not. Then check if the
1435 * address filter requested is broadcast or zero and if so return
1436 * an invalid MAC address error code.
1438 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1440 struct i40e_pf *pf = vf->pf;
1443 if (is_broadcast_ether_addr(macaddr) ||
1444 is_zero_ether_addr(macaddr)) {
1445 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1446 ret = I40E_ERR_INVALID_MAC_ADDR;
1447 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1448 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1449 /* If the host VMM administrator has set the VF MAC address
1450 * administratively via the ndo_set_vf_mac command then deny
1451 * permission to the VF to add or delete unicast MAC addresses.
1452 * The VF may request to set the MAC address filter already
1453 * assigned to it so do not return an error in that case.
1455 dev_err(&pf->pdev->dev,
1456 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1463 * i40e_vc_add_mac_addr_msg
1464 * @vf: pointer to the vf info
1465 * @msg: pointer to the msg buffer
1466 * @msglen: msg length
1468 * add guest mac address filter
1470 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1472 struct i40e_virtchnl_ether_addr_list *al =
1473 (struct i40e_virtchnl_ether_addr_list *)msg;
1474 struct i40e_pf *pf = vf->pf;
1475 struct i40e_vsi *vsi = NULL;
1476 u16 vsi_id = al->vsi_id;
1477 i40e_status ret = 0;
1480 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1481 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1482 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1483 ret = I40E_ERR_PARAM;
1487 for (i = 0; i < al->num_elements; i++) {
1488 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1492 vsi = pf->vsi[vsi_id];
1494 /* add new addresses to the list */
1495 for (i = 0; i < al->num_elements; i++) {
1496 struct i40e_mac_filter *f;
1498 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1500 if (i40e_is_vsi_in_vlan(vsi))
1501 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1504 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1509 dev_err(&pf->pdev->dev,
1510 "Unable to add VF MAC filter\n");
1511 ret = I40E_ERR_PARAM;
1516 /* program the updated filter list */
1517 if (i40e_sync_vsi_filters(vsi))
1518 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1521 /* send the response to the vf */
1522 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
1527 * i40e_vc_del_mac_addr_msg
1528 * @vf: pointer to the vf info
1529 * @msg: pointer to the msg buffer
1530 * @msglen: msg length
1532 * remove guest mac address filter
1534 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1536 struct i40e_virtchnl_ether_addr_list *al =
1537 (struct i40e_virtchnl_ether_addr_list *)msg;
1538 struct i40e_pf *pf = vf->pf;
1539 struct i40e_vsi *vsi = NULL;
1540 u16 vsi_id = al->vsi_id;
1541 i40e_status ret = 0;
1544 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1545 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1546 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1547 ret = I40E_ERR_PARAM;
1551 for (i = 0; i < al->num_elements; i++) {
1552 if (is_broadcast_ether_addr(al->list[i].addr) ||
1553 is_zero_ether_addr(al->list[i].addr)) {
1554 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1556 ret = I40E_ERR_INVALID_MAC_ADDR;
1560 vsi = pf->vsi[vsi_id];
1562 /* delete addresses from the list */
1563 for (i = 0; i < al->num_elements; i++)
1564 i40e_del_filter(vsi, al->list[i].addr,
1565 I40E_VLAN_ANY, true, false);
1567 /* program the updated filter list */
1568 if (i40e_sync_vsi_filters(vsi))
1569 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1572 /* send the response to the vf */
1573 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
1578 * i40e_vc_add_vlan_msg
1579 * @vf: pointer to the vf info
1580 * @msg: pointer to the msg buffer
1581 * @msglen: msg length
1583 * program guest vlan id
1585 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1587 struct i40e_virtchnl_vlan_filter_list *vfl =
1588 (struct i40e_virtchnl_vlan_filter_list *)msg;
1589 struct i40e_pf *pf = vf->pf;
1590 struct i40e_vsi *vsi = NULL;
1591 u16 vsi_id = vfl->vsi_id;
1592 i40e_status aq_ret = 0;
1595 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1596 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1597 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1598 aq_ret = I40E_ERR_PARAM;
1602 for (i = 0; i < vfl->num_elements; i++) {
1603 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1604 aq_ret = I40E_ERR_PARAM;
1605 dev_err(&pf->pdev->dev,
1606 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1610 vsi = pf->vsi[vsi_id];
1611 if (vsi->info.pvid) {
1612 aq_ret = I40E_ERR_PARAM;
1616 i40e_vlan_stripping_enable(vsi);
1617 for (i = 0; i < vfl->num_elements; i++) {
1618 /* add new VLAN filter */
1619 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1621 dev_err(&pf->pdev->dev,
1622 "Unable to add VF vlan filter %d, error %d\n",
1623 vfl->vlan_id[i], ret);
1627 /* send the response to the vf */
1628 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1632 * i40e_vc_remove_vlan_msg
1633 * @vf: pointer to the vf info
1634 * @msg: pointer to the msg buffer
1635 * @msglen: msg length
1637 * remove programmed guest vlan id
1639 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1641 struct i40e_virtchnl_vlan_filter_list *vfl =
1642 (struct i40e_virtchnl_vlan_filter_list *)msg;
1643 struct i40e_pf *pf = vf->pf;
1644 struct i40e_vsi *vsi = NULL;
1645 u16 vsi_id = vfl->vsi_id;
1646 i40e_status aq_ret = 0;
1649 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1650 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1651 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1652 aq_ret = I40E_ERR_PARAM;
1656 for (i = 0; i < vfl->num_elements; i++) {
1657 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1658 aq_ret = I40E_ERR_PARAM;
1663 vsi = pf->vsi[vsi_id];
1664 if (vsi->info.pvid) {
1665 aq_ret = I40E_ERR_PARAM;
1669 for (i = 0; i < vfl->num_elements; i++) {
1670 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1672 dev_err(&pf->pdev->dev,
1673 "Unable to delete VF vlan filter %d, error %d\n",
1674 vfl->vlan_id[i], ret);
1678 /* send the response to the vf */
1679 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1683 * i40e_vc_validate_vf_msg
1684 * @vf: pointer to the vf info
1685 * @msg: pointer to the msg buffer
1686 * @msglen: msg length
1687 * @msghndl: msg handle
1691 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1692 u32 v_retval, u8 *msg, u16 msglen)
1694 bool err_msg_format = false;
1697 /* Check if VF is disabled. */
1698 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1699 return I40E_ERR_PARAM;
1701 /* Validate message length. */
1703 case I40E_VIRTCHNL_OP_VERSION:
1704 valid_len = sizeof(struct i40e_virtchnl_version_info);
1706 case I40E_VIRTCHNL_OP_RESET_VF:
1707 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1710 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1711 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1713 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1714 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1716 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1717 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1718 if (msglen >= valid_len) {
1719 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1720 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1721 valid_len += (vqc->num_queue_pairs *
1723 i40e_virtchnl_queue_pair_info));
1724 if (vqc->num_queue_pairs == 0)
1725 err_msg_format = true;
1728 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1729 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1730 if (msglen >= valid_len) {
1731 struct i40e_virtchnl_irq_map_info *vimi =
1732 (struct i40e_virtchnl_irq_map_info *)msg;
1733 valid_len += (vimi->num_vectors *
1734 sizeof(struct i40e_virtchnl_vector_map));
1735 if (vimi->num_vectors == 0)
1736 err_msg_format = true;
1739 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1740 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1741 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1743 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1744 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1745 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1746 if (msglen >= valid_len) {
1747 struct i40e_virtchnl_ether_addr_list *veal =
1748 (struct i40e_virtchnl_ether_addr_list *)msg;
1749 valid_len += veal->num_elements *
1750 sizeof(struct i40e_virtchnl_ether_addr);
1751 if (veal->num_elements == 0)
1752 err_msg_format = true;
1755 case I40E_VIRTCHNL_OP_ADD_VLAN:
1756 case I40E_VIRTCHNL_OP_DEL_VLAN:
1757 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1758 if (msglen >= valid_len) {
1759 struct i40e_virtchnl_vlan_filter_list *vfl =
1760 (struct i40e_virtchnl_vlan_filter_list *)msg;
1761 valid_len += vfl->num_elements * sizeof(u16);
1762 if (vfl->num_elements == 0)
1763 err_msg_format = true;
1766 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1767 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1769 case I40E_VIRTCHNL_OP_GET_STATS:
1770 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1772 /* These are always errors coming from the VF. */
1773 case I40E_VIRTCHNL_OP_EVENT:
1774 case I40E_VIRTCHNL_OP_UNKNOWN:
1779 /* few more checks */
1780 if ((valid_len != msglen) || (err_msg_format)) {
1781 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1789 * i40e_vc_process_vf_msg
1790 * @pf: pointer to the pf structure
1791 * @vf_id: source vf id
1792 * @msg: pointer to the msg buffer
1793 * @msglen: msg length
1794 * @msghndl: msg handle
1796 * called from the common aeq/arq handler to
1797 * process request from vf
1799 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1800 u32 v_retval, u8 *msg, u16 msglen)
1802 struct i40e_hw *hw = &pf->hw;
1803 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
1807 pf->vf_aq_requests++;
1808 if (local_vf_id >= pf->num_alloc_vfs)
1810 vf = &(pf->vf[local_vf_id]);
1811 /* perform basic checks on the msg */
1812 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1815 dev_err(&pf->pdev->dev, "Invalid message from vf %d, opcode %d, len %d\n",
1816 local_vf_id, v_opcode, msglen);
1821 case I40E_VIRTCHNL_OP_VERSION:
1822 ret = i40e_vc_get_version_msg(vf);
1824 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1825 ret = i40e_vc_get_vf_resources_msg(vf);
1827 case I40E_VIRTCHNL_OP_RESET_VF:
1828 i40e_vc_reset_vf_msg(vf);
1831 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1832 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1834 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1835 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1837 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1838 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1840 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1841 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1843 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1844 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1846 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1847 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1849 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1850 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1852 case I40E_VIRTCHNL_OP_ADD_VLAN:
1853 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1855 case I40E_VIRTCHNL_OP_DEL_VLAN:
1856 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1858 case I40E_VIRTCHNL_OP_GET_STATS:
1859 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1861 case I40E_VIRTCHNL_OP_UNKNOWN:
1863 dev_err(&pf->pdev->dev, "Unsupported opcode %d from vf %d\n",
1864 v_opcode, local_vf_id);
1865 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1866 I40E_ERR_NOT_IMPLEMENTED);
1874 * i40e_vc_process_vflr_event
1875 * @pf: pointer to the pf structure
1877 * called from the vlfr irq handler to
1878 * free up vf resources and state variables
1880 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1882 u32 reg, reg_idx, bit_idx, vf_id;
1883 struct i40e_hw *hw = &pf->hw;
1886 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1889 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1890 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1891 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1892 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1893 /* read GLGEN_VFLRSTAT register to find out the flr vfs */
1894 vf = &pf->vf[vf_id];
1895 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1896 if (reg & (1 << bit_idx)) {
1897 /* clear the bit in GLGEN_VFLRSTAT */
1898 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), (1 << bit_idx));
1900 if (!test_bit(__I40E_DOWN, &pf->state))
1901 i40e_reset_vf(vf, true);
1905 /* re-enable vflr interrupt cause */
1906 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1907 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1908 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1915 * i40e_vc_vf_broadcast
1916 * @pf: pointer to the pf structure
1917 * @opcode: operation code
1918 * @retval: return value
1919 * @msg: pointer to the msg buffer
1920 * @msglen: msg length
1922 * send a message to all VFs on a given PF
1924 static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
1925 enum i40e_virtchnl_ops v_opcode,
1926 i40e_status v_retval, u8 *msg,
1929 struct i40e_hw *hw = &pf->hw;
1930 struct i40e_vf *vf = pf->vf;
1931 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1934 for (i = 0; i < pf->num_alloc_vfs; i++) {
1935 /* Ignore return value on purpose - a given VF may fail, but
1936 * we need to keep going and send to all of them
1938 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1941 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1946 * i40e_vc_notify_link_state
1947 * @pf: pointer to the pf structure
1949 * send a link status message to all VFs on a given PF
1951 void i40e_vc_notify_link_state(struct i40e_pf *pf)
1953 struct i40e_virtchnl_pf_event pfe;
1954 struct i40e_hw *hw = &pf->hw;
1955 struct i40e_vf *vf = pf->vf;
1956 struct i40e_link_status *ls = &pf->hw.phy.link_info;
1957 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1960 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1961 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
1962 for (i = 0; i < pf->num_alloc_vfs; i++) {
1963 if (vf->link_forced) {
1964 pfe.event_data.link_event.link_status = vf->link_up;
1965 pfe.event_data.link_event.link_speed =
1966 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
1968 pfe.event_data.link_event.link_status =
1969 ls->link_info & I40E_AQ_LINK_UP;
1970 pfe.event_data.link_event.link_speed = ls->link_speed;
1972 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
1973 0, (u8 *)&pfe, sizeof(pfe),
1976 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1981 * i40e_vc_notify_reset
1982 * @pf: pointer to the pf structure
1984 * indicate a pending reset to all VFs on a given PF
1986 void i40e_vc_notify_reset(struct i40e_pf *pf)
1988 struct i40e_virtchnl_pf_event pfe;
1990 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
1991 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
1992 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, I40E_SUCCESS,
1993 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
1997 * i40e_vc_notify_vf_reset
1998 * @vf: pointer to the vf structure
2000 * indicate a pending reset to the given VF
2002 void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
2004 struct i40e_virtchnl_pf_event pfe;
2005 int abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
2007 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
2008 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
2009 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2010 I40E_SUCCESS, (u8 *)&pfe,
2011 sizeof(struct i40e_virtchnl_pf_event), NULL);
2015 * i40e_ndo_set_vf_mac
2016 * @netdev: network interface device structure
2017 * @vf_id: vf identifier
2020 * program vf mac address
2022 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2024 struct i40e_netdev_priv *np = netdev_priv(netdev);
2025 struct i40e_vsi *vsi = np->vsi;
2026 struct i40e_pf *pf = vsi->back;
2027 struct i40e_mac_filter *f;
2031 /* validate the request */
2032 if (vf_id >= pf->num_alloc_vfs) {
2033 dev_err(&pf->pdev->dev,
2034 "Invalid VF Identifier %d\n", vf_id);
2039 vf = &(pf->vf[vf_id]);
2040 vsi = pf->vsi[vf->lan_vsi_index];
2041 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2042 dev_err(&pf->pdev->dev,
2043 "Uninitialized VF %d\n", vf_id);
2048 if (!is_valid_ether_addr(mac)) {
2049 dev_err(&pf->pdev->dev,
2050 "Invalid VF ethernet address\n");
2055 /* delete the temporary mac address */
2056 i40e_del_filter(vsi, vf->default_lan_addr.addr, vf->port_vlan_id,
2059 /* Delete all the filters for this VSI - we're going to kill it
2062 list_for_each_entry(f, &vsi->mac_filter_list, list)
2063 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2065 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2066 /* program mac filter */
2067 if (i40e_sync_vsi_filters(vsi)) {
2068 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2072 ether_addr_copy(vf->default_lan_addr.addr, mac);
2073 vf->pf_set_mac = true;
2074 /* Force the VF driver stop so it has to reload with new MAC address */
2075 i40e_vc_disable_vf(pf, vf);
2076 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2084 * i40e_ndo_set_vf_port_vlan
2085 * @netdev: network interface device structure
2086 * @vf_id: vf identifier
2087 * @vlan_id: mac address
2088 * @qos: priority setting
2090 * program vf vlan id and/or qos
2092 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2093 int vf_id, u16 vlan_id, u8 qos)
2095 struct i40e_netdev_priv *np = netdev_priv(netdev);
2096 struct i40e_pf *pf = np->vsi->back;
2097 struct i40e_vsi *vsi;
2101 /* validate the request */
2102 if (vf_id >= pf->num_alloc_vfs) {
2103 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2108 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2109 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2114 vf = &(pf->vf[vf_id]);
2115 vsi = pf->vsi[vf->lan_vsi_index];
2116 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2117 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2122 if (vsi->info.pvid == 0 && i40e_is_vsi_in_vlan(vsi)) {
2123 dev_err(&pf->pdev->dev,
2124 "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",
2126 /* Administrator Error - knock the VF offline until he does
2127 * the right thing by reconfiguring his network correctly
2128 * and then reloading the VF driver.
2130 i40e_vc_disable_vf(pf, vf);
2133 /* Check for condition where there was already a port VLAN ID
2134 * filter set and now it is being deleted by setting it to zero.
2135 * Additionally check for the condition where there was a port
2136 * VLAN but now there is a new and different port VLAN being set.
2137 * Before deleting all the old VLAN filters we must add new ones
2138 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2139 * MAC addresses deleted.
2141 if ((!(vlan_id || qos) ||
2142 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2144 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2146 if (vsi->info.pvid) {
2148 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2151 dev_info(&vsi->back->pdev->dev,
2152 "remove VLAN failed, ret=%d, aq_err=%d\n",
2153 ret, pf->hw.aq.asq_last_status);
2157 ret = i40e_vsi_add_pvid(vsi,
2158 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2160 i40e_vsi_remove_pvid(vsi);
2163 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2164 vlan_id, qos, vf_id);
2166 /* add new VLAN filter */
2167 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2169 dev_info(&vsi->back->pdev->dev,
2170 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2171 vsi->back->hw.aq.asq_last_status);
2174 /* Kill non-vlan MAC filters - ignore error return since
2175 * there might not be any non-vlan MAC filters.
2177 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2181 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2184 /* The Port VLAN needs to be saved across resets the same as the
2185 * default LAN MAC address.
2187 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2194 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2195 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2197 * i40e_ndo_set_vf_bw
2198 * @netdev: network interface device structure
2199 * @vf_id: vf identifier
2202 * configure vf tx rate
2204 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2207 struct i40e_netdev_priv *np = netdev_priv(netdev);
2208 struct i40e_pf *pf = np->vsi->back;
2209 struct i40e_vsi *vsi;
2214 /* validate the request */
2215 if (vf_id >= pf->num_alloc_vfs) {
2216 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2222 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for vf %d.\n",
2223 min_tx_rate, vf_id);
2227 vf = &(pf->vf[vf_id]);
2228 vsi = pf->vsi[vf->lan_vsi_index];
2229 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2230 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2235 switch (pf->hw.phy.link_info.link_speed) {
2236 case I40E_LINK_SPEED_40GB:
2239 case I40E_LINK_SPEED_10GB:
2242 case I40E_LINK_SPEED_1GB:
2249 if (max_tx_rate > speed) {
2250 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for vf %d.",
2251 max_tx_rate, vf->vf_id);
2256 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2257 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2261 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2262 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2263 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2264 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2266 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2271 vf->tx_rate = max_tx_rate;
2277 * i40e_ndo_get_vf_config
2278 * @netdev: network interface device structure
2279 * @vf_id: vf identifier
2280 * @ivi: vf configuration structure
2282 * return vf configuration
2284 int i40e_ndo_get_vf_config(struct net_device *netdev,
2285 int vf_id, struct ifla_vf_info *ivi)
2287 struct i40e_netdev_priv *np = netdev_priv(netdev);
2288 struct i40e_vsi *vsi = np->vsi;
2289 struct i40e_pf *pf = vsi->back;
2293 /* validate the request */
2294 if (vf_id >= pf->num_alloc_vfs) {
2295 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2300 vf = &(pf->vf[vf_id]);
2301 /* first vsi is always the LAN vsi */
2302 vsi = pf->vsi[vf->lan_vsi_index];
2303 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2304 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2311 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
2313 ivi->max_tx_rate = vf->tx_rate;
2314 ivi->min_tx_rate = 0;
2315 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2316 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2317 I40E_VLAN_PRIORITY_SHIFT;
2318 if (vf->link_forced == false)
2319 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2320 else if (vf->link_up == true)
2321 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2323 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
2324 ivi->spoofchk = vf->spoofchk;
2332 * i40e_ndo_set_vf_link_state
2333 * @netdev: network interface device structure
2334 * @vf_id: vf identifier
2335 * @link: required link state
2337 * Set the link state of a specified VF, regardless of physical link state
2339 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2341 struct i40e_netdev_priv *np = netdev_priv(netdev);
2342 struct i40e_pf *pf = np->vsi->back;
2343 struct i40e_virtchnl_pf_event pfe;
2344 struct i40e_hw *hw = &pf->hw;
2349 /* validate the request */
2350 if (vf_id >= pf->num_alloc_vfs) {
2351 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2356 vf = &pf->vf[vf_id];
2357 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
2359 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2360 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2363 case IFLA_VF_LINK_STATE_AUTO:
2364 vf->link_forced = false;
2365 pfe.event_data.link_event.link_status =
2366 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2367 pfe.event_data.link_event.link_speed =
2368 pf->hw.phy.link_info.link_speed;
2370 case IFLA_VF_LINK_STATE_ENABLE:
2371 vf->link_forced = true;
2373 pfe.event_data.link_event.link_status = true;
2374 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2376 case IFLA_VF_LINK_STATE_DISABLE:
2377 vf->link_forced = true;
2378 vf->link_up = false;
2379 pfe.event_data.link_event.link_status = false;
2380 pfe.event_data.link_event.link_speed = 0;
2386 /* Notify the VF of its new link state */
2387 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2388 0, (u8 *)&pfe, sizeof(pfe), NULL);
2395 * i40e_ndo_set_vf_spoofchk
2396 * @netdev: network interface device structure
2397 * @vf_id: vf identifier
2398 * @enable: flag to enable or disable feature
2400 * Enable or disable VF spoof checking
2402 int i40e_ndo_set_vf_spoofck(struct net_device *netdev, int vf_id, bool enable)
2404 struct i40e_netdev_priv *np = netdev_priv(netdev);
2405 struct i40e_vsi *vsi = np->vsi;
2406 struct i40e_pf *pf = vsi->back;
2407 struct i40e_vsi_context ctxt;
2408 struct i40e_hw *hw = &pf->hw;
2412 /* validate the request */
2413 if (vf_id >= pf->num_alloc_vfs) {
2414 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2419 vf = &(pf->vf[vf_id]);
2421 if (enable == vf->spoofchk)
2424 vf->spoofchk = enable;
2425 memset(&ctxt, 0, sizeof(ctxt));
2426 ctxt.seid = pf->vsi[vf->lan_vsi_index]->seid;
2427 ctxt.pf_num = pf->hw.pf_id;
2428 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2430 ctxt.info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
2431 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2433 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",