1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
29 /*********************notification routines***********************/
32 * i40e_vc_vf_broadcast
33 * @pf: pointer to the PF structure
34 * @opcode: operation code
35 * @retval: return value
36 * @msg: pointer to the msg buffer
39 * send a message to all VFs on a given PF
41 static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
42 enum i40e_virtchnl_ops v_opcode,
43 i40e_status v_retval, u8 *msg,
46 struct i40e_hw *hw = &pf->hw;
47 struct i40e_vf *vf = pf->vf;
50 for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
51 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
52 /* Not all vfs are enabled so skip the ones that are not */
53 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
54 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
57 /* Ignore return value on purpose - a given VF may fail, but
58 * we need to keep going and send to all of them
60 i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
66 * i40e_vc_notify_link_state
67 * @vf: pointer to the VF structure
69 * send a link status message to a single VF
71 static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
73 struct i40e_virtchnl_pf_event pfe;
74 struct i40e_pf *pf = vf->pf;
75 struct i40e_hw *hw = &pf->hw;
76 struct i40e_link_status *ls = &pf->hw.phy.link_info;
77 int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
79 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
80 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
81 if (vf->link_forced) {
82 pfe.event_data.link_event.link_status = vf->link_up;
83 pfe.event_data.link_event.link_speed =
84 (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
86 pfe.event_data.link_event.link_status =
87 ls->link_info & I40E_AQ_LINK_UP;
88 pfe.event_data.link_event.link_speed = ls->link_speed;
90 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
91 0, (u8 *)&pfe, sizeof(pfe), NULL);
95 * i40e_vc_notify_link_state
96 * @pf: pointer to the PF structure
98 * send a link status message to all VFs on a given PF
100 void i40e_vc_notify_link_state(struct i40e_pf *pf)
104 for (i = 0; i < pf->num_alloc_vfs; i++)
105 i40e_vc_notify_vf_link_state(&pf->vf[i]);
109 * i40e_vc_notify_reset
110 * @pf: pointer to the PF structure
112 * indicate a pending reset to all VFs on a given PF
114 void i40e_vc_notify_reset(struct i40e_pf *pf)
116 struct i40e_virtchnl_pf_event pfe;
118 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
119 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
120 i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0,
121 (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
125 * i40e_vc_notify_vf_reset
126 * @vf: pointer to the VF structure
128 * indicate a pending reset to the given VF
130 void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
132 struct i40e_virtchnl_pf_event pfe;
135 /* validate the request */
136 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
139 /* verify if the VF is in either init or active before proceeding */
140 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
141 !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
144 abs_vf_id = vf->vf_id + vf->pf->hw.func_caps.vf_base_id;
146 pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
147 pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
148 i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
150 sizeof(struct i40e_virtchnl_pf_event), NULL);
152 /***********************misc routines*****************************/
156 * @pf: pointer to the PF info
157 * @vf: pointer to the VF info
159 * Disable the VF through a SW reset
161 static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
163 i40e_vc_notify_vf_reset(vf);
164 i40e_reset_vf(vf, false);
168 * i40e_vc_isvalid_vsi_id
169 * @vf: pointer to the VF info
170 * @vsi_id: VF relative VSI id
172 * check for the valid VSI id
174 static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
176 struct i40e_pf *pf = vf->pf;
177 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
179 return (vsi && (vsi->vf_id == vf->vf_id));
183 * i40e_vc_isvalid_queue_id
184 * @vf: pointer to the VF info
186 * @qid: vsi relative queue id
188 * check for the valid queue id
190 static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
193 struct i40e_pf *pf = vf->pf;
194 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
196 return (vsi && (qid < vsi->alloc_queue_pairs));
200 * i40e_vc_isvalid_vector_id
201 * @vf: pointer to the VF info
202 * @vector_id: VF relative vector id
204 * check for the valid vector id
206 static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
208 struct i40e_pf *pf = vf->pf;
210 return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
213 /***********************vf resource mgmt routines*****************/
216 * i40e_vc_get_pf_queue_id
217 * @vf: pointer to the VF info
218 * @vsi_id: id of VSI as provided by the FW
219 * @vsi_queue_id: vsi relative queue id
221 * return PF relative queue id
223 static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
226 struct i40e_pf *pf = vf->pf;
227 struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
228 u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
233 if (le16_to_cpu(vsi->info.mapping_flags) &
234 I40E_AQ_VSI_QUE_MAP_NONCONTIG)
236 le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
238 pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
245 * i40e_config_irq_link_list
246 * @vf: pointer to the VF info
247 * @vsi_id: id of VSI as given by the FW
248 * @vecmap: irq map info
250 * configure irq link list from the map
252 static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
253 struct i40e_virtchnl_vector_map *vecmap)
255 unsigned long linklistmap = 0, tempmap;
256 struct i40e_pf *pf = vf->pf;
257 struct i40e_hw *hw = &pf->hw;
258 u16 vsi_queue_id, pf_queue_id;
259 enum i40e_queue_type qtype;
260 u16 next_q, vector_id;
264 vector_id = vecmap->vector_id;
267 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
269 reg_idx = I40E_VPINT_LNKLSTN(
270 ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
273 if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
274 /* Special case - No queues mapped on this vector */
275 wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
278 tempmap = vecmap->rxq_map;
279 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
280 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
284 tempmap = vecmap->txq_map;
285 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
286 linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
290 next_q = find_first_bit(&linklistmap,
292 I40E_VIRTCHNL_SUPPORTED_QTYPES));
293 vsi_queue_id = next_q/I40E_VIRTCHNL_SUPPORTED_QTYPES;
294 qtype = next_q%I40E_VIRTCHNL_SUPPORTED_QTYPES;
295 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
296 reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
298 wr32(hw, reg_idx, reg);
300 while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
302 case I40E_QUEUE_TYPE_RX:
303 reg_idx = I40E_QINT_RQCTL(pf_queue_id);
304 itr_idx = vecmap->rxitr_idx;
306 case I40E_QUEUE_TYPE_TX:
307 reg_idx = I40E_QINT_TQCTL(pf_queue_id);
308 itr_idx = vecmap->txitr_idx;
314 next_q = find_next_bit(&linklistmap,
316 I40E_VIRTCHNL_SUPPORTED_QTYPES),
319 (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
320 vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
321 qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
322 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
325 pf_queue_id = I40E_QUEUE_END_OF_LIST;
329 /* format for the RQCTL & TQCTL regs is same */
331 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
332 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
333 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
334 (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
335 wr32(hw, reg_idx, reg);
338 /* if the vf is running in polling mode and using interrupt zero,
339 * need to disable auto-mask on enabling zero interrupt for VFs.
341 if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
343 reg = rd32(hw, I40E_GLINT_CTL);
344 if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
345 reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
346 wr32(hw, I40E_GLINT_CTL, reg);
355 * i40e_config_vsi_tx_queue
356 * @vf: pointer to the VF info
357 * @vsi_id: id of VSI as provided by the FW
358 * @vsi_queue_id: vsi relative queue index
359 * @info: config. info
363 static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
365 struct i40e_virtchnl_txq_info *info)
367 struct i40e_pf *pf = vf->pf;
368 struct i40e_hw *hw = &pf->hw;
369 struct i40e_hmc_obj_txq tx_ctx;
370 struct i40e_vsi *vsi;
375 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
376 vsi = i40e_find_vsi_from_id(pf, vsi_id);
378 /* clear the context structure first */
379 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
381 /* only set the required fields */
382 tx_ctx.base = info->dma_ring_addr / 128;
383 tx_ctx.qlen = info->ring_len;
384 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
385 tx_ctx.rdylist_act = 0;
386 tx_ctx.head_wb_ena = info->headwb_enabled;
387 tx_ctx.head_wb_addr = info->dma_headwb_addr;
389 /* clear the context in the HMC */
390 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
392 dev_err(&pf->pdev->dev,
393 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
399 /* set the context in the HMC */
400 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
402 dev_err(&pf->pdev->dev,
403 "Failed to set VF LAN Tx queue context %d error: %d\n",
409 /* associate this queue with the PCI VF function */
410 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
411 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
412 & I40E_QTX_CTL_PF_INDX_MASK);
413 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
414 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
415 & I40E_QTX_CTL_VFVM_INDX_MASK);
416 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
424 * i40e_config_vsi_rx_queue
425 * @vf: pointer to the VF info
426 * @vsi_id: id of VSI as provided by the FW
427 * @vsi_queue_id: vsi relative queue index
428 * @info: config. info
432 static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
434 struct i40e_virtchnl_rxq_info *info)
436 struct i40e_pf *pf = vf->pf;
437 struct i40e_hw *hw = &pf->hw;
438 struct i40e_hmc_obj_rxq rx_ctx;
442 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
444 /* clear the context structure first */
445 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
447 /* only set the required fields */
448 rx_ctx.base = info->dma_ring_addr / 128;
449 rx_ctx.qlen = info->ring_len;
451 if (info->splithdr_enabled) {
452 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
454 I40E_RX_SPLIT_TCP_UDP |
456 /* header length validation */
457 if (info->hdr_size > ((2 * 1024) - 64)) {
461 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
463 /* set splitalways mode 10b */
467 /* databuffer length validation */
468 if (info->databuffer_size > ((16 * 1024) - 128)) {
472 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
474 /* max pkt. length validation */
475 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
479 rx_ctx.rxmax = info->max_pkt_size;
481 /* enable 32bytes desc always */
485 rx_ctx.lrxqthresh = 2;
490 /* clear the context in the HMC */
491 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
493 dev_err(&pf->pdev->dev,
494 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
500 /* set the context in the HMC */
501 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
503 dev_err(&pf->pdev->dev,
504 "Failed to set VF LAN Rx queue context %d error: %d\n",
516 * @vf: pointer to the VF info
517 * @type: type of VSI to allocate
519 * alloc VF vsi context & resources
521 static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
523 struct i40e_mac_filter *f = NULL;
524 struct i40e_pf *pf = vf->pf;
525 struct i40e_vsi *vsi;
528 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
531 dev_err(&pf->pdev->dev,
532 "add vsi failed for VF %d, aq_err %d\n",
533 vf->vf_id, pf->hw.aq.asq_last_status);
535 goto error_alloc_vsi_res;
537 if (type == I40E_VSI_SRIOV) {
538 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
539 vf->lan_vsi_idx = vsi->idx;
540 vf->lan_vsi_id = vsi->id;
541 /* If the port VLAN has been configured and then the
542 * VF driver was removed then the VSI port VLAN
543 * configuration was destroyed. Check if there is
544 * a port VLAN and restore the VSI configuration if
547 if (vf->port_vlan_id)
548 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
549 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
550 vf->port_vlan_id ? vf->port_vlan_id : -1,
553 dev_info(&pf->pdev->dev,
554 "Could not allocate VF MAC addr\n");
555 f = i40e_add_filter(vsi, brdcast,
556 vf->port_vlan_id ? vf->port_vlan_id : -1,
559 dev_info(&pf->pdev->dev,
560 "Could not allocate VF broadcast filter\n");
563 /* program mac filter */
564 ret = i40e_sync_vsi_filters(vsi);
566 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
568 /* Set VF bandwidth if specified */
570 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
571 vf->tx_rate / 50, 0, NULL);
573 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
582 * i40e_enable_vf_mappings
583 * @vf: pointer to the VF info
587 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
589 struct i40e_pf *pf = vf->pf;
590 struct i40e_hw *hw = &pf->hw;
591 u32 reg, total_queue_pairs = 0;
594 /* Tell the hardware we're using noncontiguous mapping. HW requires
595 * that VF queues be mapped using this method, even when they are
596 * contiguous in real life
598 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
599 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
601 /* enable VF vplan_qtable mappings */
602 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
603 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
605 /* map PF queues to VF queues */
606 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
607 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
608 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
609 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
613 /* map PF queues to VSI */
614 for (j = 0; j < 7; j++) {
615 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
616 reg = 0x07FF07FF; /* unused */
618 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
621 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
625 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
632 * i40e_disable_vf_mappings
633 * @vf: pointer to the VF info
635 * disable VF mappings
637 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
639 struct i40e_pf *pf = vf->pf;
640 struct i40e_hw *hw = &pf->hw;
643 /* disable qp mappings */
644 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
645 for (i = 0; i < I40E_MAX_VSI_QP; i++)
646 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
647 I40E_QUEUE_END_OF_LIST);
653 * @vf: pointer to the VF info
657 static void i40e_free_vf_res(struct i40e_vf *vf)
659 struct i40e_pf *pf = vf->pf;
660 struct i40e_hw *hw = &pf->hw;
664 /* free vsi & disconnect it from the parent uplink */
665 if (vf->lan_vsi_idx) {
666 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
670 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
672 /* disable interrupts so the VF starts in a known state */
673 for (i = 0; i < msix_vf; i++) {
674 /* format is same for both registers */
676 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
678 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
681 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
685 /* clear the irq settings */
686 for (i = 0; i < msix_vf; i++) {
687 /* format is same for both registers */
689 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
691 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
694 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
695 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
696 wr32(hw, reg_idx, reg);
699 /* reset some of the state varibles keeping
700 * track of the resources
702 vf->num_queue_pairs = 0;
708 * @vf: pointer to the VF info
710 * allocate VF resources
712 static int i40e_alloc_vf_res(struct i40e_vf *vf)
714 struct i40e_pf *pf = vf->pf;
715 int total_queue_pairs = 0;
718 /* allocate hw vsi context & associated resources */
719 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
722 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
723 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
725 /* store the total qps number for the runtime
728 vf->num_queue_pairs = total_queue_pairs;
730 /* VF is now completely initialized */
731 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
735 i40e_free_vf_res(vf);
740 #define VF_DEVICE_STATUS 0xAA
741 #define VF_TRANS_PENDING_MASK 0x20
743 * i40e_quiesce_vf_pci
744 * @vf: pointer to the VF structure
746 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
747 * if the transactions never clear.
749 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
751 struct i40e_pf *pf = vf->pf;
752 struct i40e_hw *hw = &pf->hw;
756 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
758 wr32(hw, I40E_PF_PCI_CIAA,
759 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
760 for (i = 0; i < 100; i++) {
761 reg = rd32(hw, I40E_PF_PCI_CIAD);
762 if ((reg & VF_TRANS_PENDING_MASK) == 0)
771 * @vf: pointer to the VF structure
772 * @flr: VFLR was issued or not
776 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
778 struct i40e_pf *pf = vf->pf;
779 struct i40e_hw *hw = &pf->hw;
784 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
788 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
790 /* In the case of a VFLR, the HW has already reset the VF and we
791 * just need to clean up, so don't hit the VFRTRIG register.
794 /* reset VF using VPGEN_VFRTRIG reg */
795 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
796 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
797 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
801 if (i40e_quiesce_vf_pci(vf))
802 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
805 /* poll VPGEN_VFRSTAT reg to make sure
806 * that reset is complete
808 for (i = 0; i < 10; i++) {
809 /* VF reset requires driver to first reset the VF and then
810 * poll the status register to make sure that the reset
811 * completed successfully. Due to internal HW FIFO flushes,
812 * we must wait 10ms before the register will be valid.
814 usleep_range(10000, 20000);
815 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
816 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
823 usleep_range(10000, 20000);
826 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
828 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
829 /* clear the reset bit in the VPGEN_VFRTRIG reg */
830 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
831 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
832 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
834 /* On initial reset, we won't have any queues */
835 if (vf->lan_vsi_idx == 0)
838 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
840 /* reallocate VF resources to reset the VSI state */
841 i40e_free_vf_res(vf);
842 i40e_alloc_vf_res(vf);
843 i40e_enable_vf_mappings(vf);
844 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
845 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
847 /* tell the VF the reset is done */
848 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
850 clear_bit(__I40E_VF_DISABLE, &pf->state);
855 * @pf: pointer to the PF structure
859 void i40e_free_vfs(struct i40e_pf *pf)
861 struct i40e_hw *hw = &pf->hw;
862 u32 reg_idx, bit_idx;
867 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
868 usleep_range(1000, 2000);
870 for (i = 0; i < pf->num_alloc_vfs; i++)
871 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
872 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
875 /* Disable IOV before freeing resources. This lets any VF drivers
876 * running in the host get themselves cleaned up before we yank
877 * the carpet out from underneath their feet.
879 if (!pci_vfs_assigned(pf->pdev))
880 pci_disable_sriov(pf->pdev);
882 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
884 msleep(20); /* let any messages in transit get finished up */
886 /* free up VF resources */
887 tmp = pf->num_alloc_vfs;
888 pf->num_alloc_vfs = 0;
889 for (i = 0; i < tmp; i++) {
890 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
891 i40e_free_vf_res(&pf->vf[i]);
892 /* disable qp mappings */
893 i40e_disable_vf_mappings(&pf->vf[i]);
899 /* This check is for when the driver is unloaded while VFs are
900 * assigned. Setting the number of VFs to 0 through sysfs is caught
901 * before this function ever gets called.
903 if (!pci_vfs_assigned(pf->pdev)) {
904 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
905 * work correctly when SR-IOV gets re-enabled.
907 for (vf_id = 0; vf_id < tmp; vf_id++) {
908 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
909 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
910 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
913 clear_bit(__I40E_VF_DISABLE, &pf->state);
916 #ifdef CONFIG_PCI_IOV
919 * @pf: pointer to the PF structure
920 * @num_alloc_vfs: number of VFs to allocate
922 * allocate VF resources
924 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
929 /* Disable interrupt 0 so we don't try to handle the VFLR. */
930 i40e_irq_dynamic_disable_icr0(pf);
932 /* Check to see if we're just allocating resources for extant VFs */
933 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
934 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
936 pf->num_alloc_vfs = 0;
940 /* allocate memory */
941 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
948 /* apply default profile */
949 for (i = 0; i < num_alloc_vfs; i++) {
951 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
954 /* assign default capabilities */
955 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
956 vfs[i].spoofchk = true;
957 /* VF resources get allocated during reset */
958 i40e_reset_vf(&vfs[i], false);
960 /* enable VF vplan_qtable mappings */
961 i40e_enable_vf_mappings(&vfs[i]);
963 pf->num_alloc_vfs = num_alloc_vfs;
969 /* Re-enable interrupt 0. */
970 i40e_irq_dynamic_enable_icr0(pf);
976 * i40e_pci_sriov_enable
977 * @pdev: pointer to a pci_dev structure
978 * @num_vfs: number of VFs to allocate
980 * Enable or change the number of VFs
982 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
984 #ifdef CONFIG_PCI_IOV
985 struct i40e_pf *pf = pci_get_drvdata(pdev);
986 int pre_existing_vfs = pci_num_vf(pdev);
989 if (pf->state & __I40E_TESTING) {
991 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
996 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
997 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
999 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1002 if (num_vfs > pf->num_req_vfs) {
1007 err = i40e_alloc_vfs(pf, num_vfs);
1009 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1023 * i40e_pci_sriov_configure
1024 * @pdev: pointer to a pci_dev structure
1025 * @num_vfs: number of VFs to allocate
1027 * Enable or change the number of VFs. Called when the user updates the number
1030 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1032 struct i40e_pf *pf = pci_get_drvdata(pdev);
1035 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1036 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1037 i40e_do_reset_safe(pf,
1038 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1040 return i40e_pci_sriov_enable(pdev, num_vfs);
1043 if (!pci_vfs_assigned(pf->pdev)) {
1045 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1046 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
1048 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1054 /***********************virtual channel routines******************/
1057 * i40e_vc_send_msg_to_vf
1058 * @vf: pointer to the VF info
1059 * @v_opcode: virtual channel opcode
1060 * @v_retval: virtual channel return value
1061 * @msg: pointer to the msg buffer
1062 * @msglen: msg length
1066 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1067 u32 v_retval, u8 *msg, u16 msglen)
1074 /* validate the request */
1075 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1080 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1082 /* single place to detect unsuccessful return values */
1084 vf->num_invalid_msgs++;
1085 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1086 v_opcode, v_retval);
1087 if (vf->num_invalid_msgs >
1088 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1089 dev_err(&pf->pdev->dev,
1090 "Number of invalid messages exceeded for VF %d\n",
1092 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1093 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1096 vf->num_valid_msgs++;
1099 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1102 dev_err(&pf->pdev->dev,
1103 "Unable to send the message to VF %d aq_err %d\n",
1104 vf->vf_id, pf->hw.aq.asq_last_status);
1112 * i40e_vc_send_resp_to_vf
1113 * @vf: pointer to the VF info
1114 * @opcode: operation code
1115 * @retval: return value
1117 * send resp msg to VF
1119 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1120 enum i40e_virtchnl_ops opcode,
1123 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1127 * i40e_vc_get_version_msg
1128 * @vf: pointer to the VF info
1130 * called from the VF to request the API version used by the PF
1132 static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
1134 struct i40e_virtchnl_version_info info = {
1135 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1138 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
1139 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1141 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
1142 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1143 I40E_SUCCESS, (u8 *)&info,
1145 i40e_virtchnl_version_info));
1149 * i40e_vc_get_vf_resources_msg
1150 * @vf: pointer to the VF info
1151 * @msg: pointer to the msg buffer
1152 * @msglen: msg length
1154 * called from the VF to request its resources
1156 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1158 struct i40e_virtchnl_vf_resource *vfres = NULL;
1159 struct i40e_pf *pf = vf->pf;
1160 i40e_status aq_ret = 0;
1161 struct i40e_vsi *vsi;
1166 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1167 aq_ret = I40E_ERR_PARAM;
1171 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1172 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1174 vfres = kzalloc(len, GFP_KERNEL);
1176 aq_ret = I40E_ERR_NO_MEMORY;
1181 vf->driver_caps = *(u32 *)msg;
1183 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1184 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1185 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1187 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1188 vsi = pf->vsi[vf->lan_vsi_idx];
1189 if (!vsi->info.pvid)
1190 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1191 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1192 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1193 vfres->vf_offload_flags |=
1194 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1196 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1198 vfres->num_vsis = num_vsis;
1199 vfres->num_queue_pairs = vf->num_queue_pairs;
1200 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1201 if (vf->lan_vsi_idx) {
1202 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
1203 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1204 vfres->vsi_res[i].num_queue_pairs =
1205 pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
1206 memcpy(vfres->vsi_res[i].default_mac_addr,
1207 vf->default_lan_addr.addr, ETH_ALEN);
1210 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1213 /* send the response back to the VF */
1214 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1215 aq_ret, (u8 *)vfres, len);
1222 * i40e_vc_reset_vf_msg
1223 * @vf: pointer to the VF info
1224 * @msg: pointer to the msg buffer
1225 * @msglen: msg length
1227 * called from the VF to reset itself,
1228 * unlike other virtchnl messages, PF driver
1229 * doesn't send the response back to the VF
1231 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1233 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1234 i40e_reset_vf(vf, false);
1238 * i40e_vc_config_promiscuous_mode_msg
1239 * @vf: pointer to the VF info
1240 * @msg: pointer to the msg buffer
1241 * @msglen: msg length
1243 * called from the VF to configure the promiscuous mode of
1246 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1247 u8 *msg, u16 msglen)
1249 struct i40e_virtchnl_promisc_info *info =
1250 (struct i40e_virtchnl_promisc_info *)msg;
1251 struct i40e_pf *pf = vf->pf;
1252 struct i40e_hw *hw = &pf->hw;
1253 struct i40e_vsi *vsi;
1254 bool allmulti = false;
1257 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1258 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1259 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1260 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1261 (vsi->type != I40E_VSI_FCOE)) {
1262 aq_ret = I40E_ERR_PARAM;
1265 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1267 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1271 /* send the response to the VF */
1272 return i40e_vc_send_resp_to_vf(vf,
1273 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1278 * i40e_vc_config_queues_msg
1279 * @vf: pointer to the VF info
1280 * @msg: pointer to the msg buffer
1281 * @msglen: msg length
1283 * called from the VF to configure the rx/tx
1286 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1288 struct i40e_virtchnl_vsi_queue_config_info *qci =
1289 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1290 struct i40e_virtchnl_queue_pair_info *qpi;
1291 struct i40e_pf *pf = vf->pf;
1292 u16 vsi_id, vsi_queue_id;
1293 i40e_status aq_ret = 0;
1296 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1297 aq_ret = I40E_ERR_PARAM;
1301 vsi_id = qci->vsi_id;
1302 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1303 aq_ret = I40E_ERR_PARAM;
1306 for (i = 0; i < qci->num_queue_pairs; i++) {
1307 qpi = &qci->qpair[i];
1308 vsi_queue_id = qpi->txq.queue_id;
1309 if ((qpi->txq.vsi_id != vsi_id) ||
1310 (qpi->rxq.vsi_id != vsi_id) ||
1311 (qpi->rxq.queue_id != vsi_queue_id) ||
1312 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1313 aq_ret = I40E_ERR_PARAM;
1317 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1319 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1321 aq_ret = I40E_ERR_PARAM;
1325 /* set vsi num_queue_pairs in use to num configured by VF */
1326 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
1329 /* send the response to the VF */
1330 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1335 * i40e_vc_config_irq_map_msg
1336 * @vf: pointer to the VF info
1337 * @msg: pointer to the msg buffer
1338 * @msglen: msg length
1340 * called from the VF to configure the irq to
1343 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1345 struct i40e_virtchnl_irq_map_info *irqmap_info =
1346 (struct i40e_virtchnl_irq_map_info *)msg;
1347 struct i40e_virtchnl_vector_map *map;
1348 u16 vsi_id, vsi_queue_id, vector_id;
1349 i40e_status aq_ret = 0;
1350 unsigned long tempmap;
1353 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1354 aq_ret = I40E_ERR_PARAM;
1358 for (i = 0; i < irqmap_info->num_vectors; i++) {
1359 map = &irqmap_info->vecmap[i];
1361 vector_id = map->vector_id;
1362 vsi_id = map->vsi_id;
1363 /* validate msg params */
1364 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1365 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1366 aq_ret = I40E_ERR_PARAM;
1370 /* lookout for the invalid queue index */
1371 tempmap = map->rxq_map;
1372 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1373 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1375 aq_ret = I40E_ERR_PARAM;
1380 tempmap = map->txq_map;
1381 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1382 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1384 aq_ret = I40E_ERR_PARAM;
1389 i40e_config_irq_link_list(vf, vsi_id, map);
1392 /* send the response to the VF */
1393 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1398 * i40e_vc_enable_queues_msg
1399 * @vf: pointer to the VF info
1400 * @msg: pointer to the msg buffer
1401 * @msglen: msg length
1403 * called from the VF to enable all or specific queue(s)
1405 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1407 struct i40e_virtchnl_queue_select *vqs =
1408 (struct i40e_virtchnl_queue_select *)msg;
1409 struct i40e_pf *pf = vf->pf;
1410 u16 vsi_id = vqs->vsi_id;
1411 i40e_status aq_ret = 0;
1413 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1414 aq_ret = I40E_ERR_PARAM;
1418 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1419 aq_ret = I40E_ERR_PARAM;
1423 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1424 aq_ret = I40E_ERR_PARAM;
1428 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
1429 aq_ret = I40E_ERR_TIMEOUT;
1431 /* send the response to the VF */
1432 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1437 * i40e_vc_disable_queues_msg
1438 * @vf: pointer to the VF info
1439 * @msg: pointer to the msg buffer
1440 * @msglen: msg length
1442 * called from the VF to disable all or specific
1445 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1447 struct i40e_virtchnl_queue_select *vqs =
1448 (struct i40e_virtchnl_queue_select *)msg;
1449 struct i40e_pf *pf = vf->pf;
1450 i40e_status aq_ret = 0;
1452 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1453 aq_ret = I40E_ERR_PARAM;
1457 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1458 aq_ret = I40E_ERR_PARAM;
1462 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1463 aq_ret = I40E_ERR_PARAM;
1467 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
1468 aq_ret = I40E_ERR_TIMEOUT;
1471 /* send the response to the VF */
1472 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1477 * i40e_vc_get_stats_msg
1478 * @vf: pointer to the VF info
1479 * @msg: pointer to the msg buffer
1480 * @msglen: msg length
1482 * called from the VF to get vsi stats
1484 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1486 struct i40e_virtchnl_queue_select *vqs =
1487 (struct i40e_virtchnl_queue_select *)msg;
1488 struct i40e_pf *pf = vf->pf;
1489 struct i40e_eth_stats stats;
1490 i40e_status aq_ret = 0;
1491 struct i40e_vsi *vsi;
1493 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1495 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1496 aq_ret = I40E_ERR_PARAM;
1500 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1501 aq_ret = I40E_ERR_PARAM;
1505 vsi = pf->vsi[vf->lan_vsi_idx];
1507 aq_ret = I40E_ERR_PARAM;
1510 i40e_update_eth_stats(vsi);
1511 stats = vsi->eth_stats;
1514 /* send the response back to the VF */
1515 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1516 (u8 *)&stats, sizeof(stats));
1520 * i40e_check_vf_permission
1521 * @vf: pointer to the VF info
1522 * @macaddr: pointer to the MAC Address being checked
1524 * Check if the VF has permission to add or delete unicast MAC address
1525 * filters and return error code -EPERM if not. Then check if the
1526 * address filter requested is broadcast or zero and if so return
1527 * an invalid MAC address error code.
1529 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1531 struct i40e_pf *pf = vf->pf;
1534 if (is_broadcast_ether_addr(macaddr) ||
1535 is_zero_ether_addr(macaddr)) {
1536 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1537 ret = I40E_ERR_INVALID_MAC_ADDR;
1538 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1539 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1540 /* If the host VMM administrator has set the VF MAC address
1541 * administratively via the ndo_set_vf_mac command then deny
1542 * permission to the VF to add or delete unicast MAC addresses.
1543 * The VF may request to set the MAC address filter already
1544 * assigned to it so do not return an error in that case.
1546 dev_err(&pf->pdev->dev,
1547 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1554 * i40e_vc_add_mac_addr_msg
1555 * @vf: pointer to the VF info
1556 * @msg: pointer to the msg buffer
1557 * @msglen: msg length
1559 * add guest mac address filter
1561 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1563 struct i40e_virtchnl_ether_addr_list *al =
1564 (struct i40e_virtchnl_ether_addr_list *)msg;
1565 struct i40e_pf *pf = vf->pf;
1566 struct i40e_vsi *vsi = NULL;
1567 u16 vsi_id = al->vsi_id;
1568 i40e_status ret = 0;
1571 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1572 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1573 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1574 ret = I40E_ERR_PARAM;
1578 for (i = 0; i < al->num_elements; i++) {
1579 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1583 vsi = pf->vsi[vf->lan_vsi_idx];
1585 /* add new addresses to the list */
1586 for (i = 0; i < al->num_elements; i++) {
1587 struct i40e_mac_filter *f;
1589 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1591 if (i40e_is_vsi_in_vlan(vsi))
1592 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1595 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1600 dev_err(&pf->pdev->dev,
1601 "Unable to add VF MAC filter\n");
1602 ret = I40E_ERR_PARAM;
1607 /* program the updated filter list */
1608 if (i40e_sync_vsi_filters(vsi))
1609 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1612 /* send the response to the VF */
1613 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
1618 * i40e_vc_del_mac_addr_msg
1619 * @vf: pointer to the VF info
1620 * @msg: pointer to the msg buffer
1621 * @msglen: msg length
1623 * remove guest mac address filter
1625 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1627 struct i40e_virtchnl_ether_addr_list *al =
1628 (struct i40e_virtchnl_ether_addr_list *)msg;
1629 struct i40e_pf *pf = vf->pf;
1630 struct i40e_vsi *vsi = NULL;
1631 u16 vsi_id = al->vsi_id;
1632 i40e_status ret = 0;
1635 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1636 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1637 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1638 ret = I40E_ERR_PARAM;
1642 for (i = 0; i < al->num_elements; i++) {
1643 if (is_broadcast_ether_addr(al->list[i].addr) ||
1644 is_zero_ether_addr(al->list[i].addr)) {
1645 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1647 ret = I40E_ERR_INVALID_MAC_ADDR;
1651 vsi = pf->vsi[vf->lan_vsi_idx];
1653 /* delete addresses from the list */
1654 for (i = 0; i < al->num_elements; i++)
1655 i40e_del_filter(vsi, al->list[i].addr,
1656 I40E_VLAN_ANY, true, false);
1658 /* program the updated filter list */
1659 if (i40e_sync_vsi_filters(vsi))
1660 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1663 /* send the response to the VF */
1664 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
1669 * i40e_vc_add_vlan_msg
1670 * @vf: pointer to the VF info
1671 * @msg: pointer to the msg buffer
1672 * @msglen: msg length
1674 * program guest vlan id
1676 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1678 struct i40e_virtchnl_vlan_filter_list *vfl =
1679 (struct i40e_virtchnl_vlan_filter_list *)msg;
1680 struct i40e_pf *pf = vf->pf;
1681 struct i40e_vsi *vsi = NULL;
1682 u16 vsi_id = vfl->vsi_id;
1683 i40e_status aq_ret = 0;
1686 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1687 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1688 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1689 aq_ret = I40E_ERR_PARAM;
1693 for (i = 0; i < vfl->num_elements; i++) {
1694 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1695 aq_ret = I40E_ERR_PARAM;
1696 dev_err(&pf->pdev->dev,
1697 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1701 vsi = pf->vsi[vf->lan_vsi_idx];
1702 if (vsi->info.pvid) {
1703 aq_ret = I40E_ERR_PARAM;
1707 i40e_vlan_stripping_enable(vsi);
1708 for (i = 0; i < vfl->num_elements; i++) {
1709 /* add new VLAN filter */
1710 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1712 dev_err(&pf->pdev->dev,
1713 "Unable to add VF vlan filter %d, error %d\n",
1714 vfl->vlan_id[i], ret);
1718 /* send the response to the VF */
1719 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1723 * i40e_vc_remove_vlan_msg
1724 * @vf: pointer to the VF info
1725 * @msg: pointer to the msg buffer
1726 * @msglen: msg length
1728 * remove programmed guest vlan id
1730 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1732 struct i40e_virtchnl_vlan_filter_list *vfl =
1733 (struct i40e_virtchnl_vlan_filter_list *)msg;
1734 struct i40e_pf *pf = vf->pf;
1735 struct i40e_vsi *vsi = NULL;
1736 u16 vsi_id = vfl->vsi_id;
1737 i40e_status aq_ret = 0;
1740 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1741 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1742 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1743 aq_ret = I40E_ERR_PARAM;
1747 for (i = 0; i < vfl->num_elements; i++) {
1748 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1749 aq_ret = I40E_ERR_PARAM;
1754 vsi = pf->vsi[vf->lan_vsi_idx];
1755 if (vsi->info.pvid) {
1756 aq_ret = I40E_ERR_PARAM;
1760 for (i = 0; i < vfl->num_elements; i++) {
1761 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1763 dev_err(&pf->pdev->dev,
1764 "Unable to delete VF vlan filter %d, error %d\n",
1765 vfl->vlan_id[i], ret);
1769 /* send the response to the VF */
1770 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1774 * i40e_vc_validate_vf_msg
1775 * @vf: pointer to the VF info
1776 * @msg: pointer to the msg buffer
1777 * @msglen: msg length
1778 * @msghndl: msg handle
1782 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1783 u32 v_retval, u8 *msg, u16 msglen)
1785 bool err_msg_format = false;
1788 /* Check if VF is disabled. */
1789 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1790 return I40E_ERR_PARAM;
1792 /* Validate message length. */
1794 case I40E_VIRTCHNL_OP_VERSION:
1795 valid_len = sizeof(struct i40e_virtchnl_version_info);
1797 case I40E_VIRTCHNL_OP_RESET_VF:
1800 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1802 valid_len = sizeof(u32);
1806 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1807 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1809 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1810 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1812 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1813 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1814 if (msglen >= valid_len) {
1815 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1816 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1817 valid_len += (vqc->num_queue_pairs *
1819 i40e_virtchnl_queue_pair_info));
1820 if (vqc->num_queue_pairs == 0)
1821 err_msg_format = true;
1824 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1825 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1826 if (msglen >= valid_len) {
1827 struct i40e_virtchnl_irq_map_info *vimi =
1828 (struct i40e_virtchnl_irq_map_info *)msg;
1829 valid_len += (vimi->num_vectors *
1830 sizeof(struct i40e_virtchnl_vector_map));
1831 if (vimi->num_vectors == 0)
1832 err_msg_format = true;
1835 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1836 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1837 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1839 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1840 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1841 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1842 if (msglen >= valid_len) {
1843 struct i40e_virtchnl_ether_addr_list *veal =
1844 (struct i40e_virtchnl_ether_addr_list *)msg;
1845 valid_len += veal->num_elements *
1846 sizeof(struct i40e_virtchnl_ether_addr);
1847 if (veal->num_elements == 0)
1848 err_msg_format = true;
1851 case I40E_VIRTCHNL_OP_ADD_VLAN:
1852 case I40E_VIRTCHNL_OP_DEL_VLAN:
1853 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1854 if (msglen >= valid_len) {
1855 struct i40e_virtchnl_vlan_filter_list *vfl =
1856 (struct i40e_virtchnl_vlan_filter_list *)msg;
1857 valid_len += vfl->num_elements * sizeof(u16);
1858 if (vfl->num_elements == 0)
1859 err_msg_format = true;
1862 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1863 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1865 case I40E_VIRTCHNL_OP_GET_STATS:
1866 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1868 /* These are always errors coming from the VF. */
1869 case I40E_VIRTCHNL_OP_EVENT:
1870 case I40E_VIRTCHNL_OP_UNKNOWN:
1875 /* few more checks */
1876 if ((valid_len != msglen) || (err_msg_format)) {
1877 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1885 * i40e_vc_process_vf_msg
1886 * @pf: pointer to the PF structure
1887 * @vf_id: source VF id
1888 * @msg: pointer to the msg buffer
1889 * @msglen: msg length
1890 * @msghndl: msg handle
1892 * called from the common aeq/arq handler to
1893 * process request from VF
1895 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1896 u32 v_retval, u8 *msg, u16 msglen)
1898 struct i40e_hw *hw = &pf->hw;
1899 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
1903 pf->vf_aq_requests++;
1904 if (local_vf_id >= pf->num_alloc_vfs)
1906 vf = &(pf->vf[local_vf_id]);
1907 /* perform basic checks on the msg */
1908 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1911 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
1912 local_vf_id, v_opcode, msglen);
1917 case I40E_VIRTCHNL_OP_VERSION:
1918 ret = i40e_vc_get_version_msg(vf, msg);
1920 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1921 ret = i40e_vc_get_vf_resources_msg(vf, msg);
1923 case I40E_VIRTCHNL_OP_RESET_VF:
1924 i40e_vc_reset_vf_msg(vf);
1927 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1928 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1930 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1931 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1933 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1934 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1936 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1937 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1938 i40e_vc_notify_vf_link_state(vf);
1940 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1941 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1943 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1944 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1946 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1947 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1949 case I40E_VIRTCHNL_OP_ADD_VLAN:
1950 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1952 case I40E_VIRTCHNL_OP_DEL_VLAN:
1953 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1955 case I40E_VIRTCHNL_OP_GET_STATS:
1956 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1958 case I40E_VIRTCHNL_OP_UNKNOWN:
1960 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
1961 v_opcode, local_vf_id);
1962 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1963 I40E_ERR_NOT_IMPLEMENTED);
1971 * i40e_vc_process_vflr_event
1972 * @pf: pointer to the PF structure
1974 * called from the vlfr irq handler to
1975 * free up VF resources and state variables
1977 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1979 u32 reg, reg_idx, bit_idx, vf_id;
1980 struct i40e_hw *hw = &pf->hw;
1983 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1986 /* re-enable vflr interrupt cause */
1987 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1988 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1989 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1992 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1993 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1994 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1995 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1996 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
1997 vf = &pf->vf[vf_id];
1998 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1999 if (reg & BIT(bit_idx)) {
2000 /* clear the bit in GLGEN_VFLRSTAT */
2001 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
2003 if (!test_bit(__I40E_DOWN, &pf->state))
2004 i40e_reset_vf(vf, true);
2012 * i40e_ndo_set_vf_mac
2013 * @netdev: network interface device structure
2014 * @vf_id: VF identifier
2017 * program VF mac address
2019 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2021 struct i40e_netdev_priv *np = netdev_priv(netdev);
2022 struct i40e_vsi *vsi = np->vsi;
2023 struct i40e_pf *pf = vsi->back;
2024 struct i40e_mac_filter *f;
2028 /* validate the request */
2029 if (vf_id >= pf->num_alloc_vfs) {
2030 dev_err(&pf->pdev->dev,
2031 "Invalid VF Identifier %d\n", vf_id);
2036 vf = &(pf->vf[vf_id]);
2037 vsi = pf->vsi[vf->lan_vsi_idx];
2038 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2039 dev_err(&pf->pdev->dev,
2040 "Uninitialized VF %d\n", vf_id);
2045 if (!is_valid_ether_addr(mac)) {
2046 dev_err(&pf->pdev->dev,
2047 "Invalid VF ethernet address\n");
2052 /* delete the temporary mac address */
2053 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2054 vf->port_vlan_id ? vf->port_vlan_id : -1,
2057 /* Delete all the filters for this VSI - we're going to kill it
2060 list_for_each_entry(f, &vsi->mac_filter_list, list)
2061 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2063 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2064 /* program mac filter */
2065 if (i40e_sync_vsi_filters(vsi)) {
2066 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2070 ether_addr_copy(vf->default_lan_addr.addr, mac);
2071 vf->pf_set_mac = true;
2072 /* Force the VF driver stop so it has to reload with new MAC address */
2073 i40e_vc_disable_vf(pf, vf);
2074 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2081 * i40e_ndo_set_vf_port_vlan
2082 * @netdev: network interface device structure
2083 * @vf_id: VF identifier
2084 * @vlan_id: mac address
2085 * @qos: priority setting
2087 * program VF vlan id and/or qos
2089 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2090 int vf_id, u16 vlan_id, u8 qos)
2092 struct i40e_netdev_priv *np = netdev_priv(netdev);
2093 struct i40e_pf *pf = np->vsi->back;
2094 struct i40e_vsi *vsi;
2098 /* validate the request */
2099 if (vf_id >= pf->num_alloc_vfs) {
2100 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2105 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2106 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2111 vf = &(pf->vf[vf_id]);
2112 vsi = pf->vsi[vf->lan_vsi_idx];
2113 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2114 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2119 if (le16_to_cpu(vsi->info.pvid) ==
2120 (vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT)))
2121 /* duplicate request, so just return success */
2124 if (le16_to_cpu(vsi->info.pvid) == 0 && i40e_is_vsi_in_vlan(vsi)) {
2125 dev_err(&pf->pdev->dev,
2126 "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",
2128 /* Administrator Error - knock the VF offline until he does
2129 * the right thing by reconfiguring his network correctly
2130 * and then reloading the VF driver.
2132 i40e_vc_disable_vf(pf, vf);
2135 /* Check for condition where there was already a port VLAN ID
2136 * filter set and now it is being deleted by setting it to zero.
2137 * Additionally check for the condition where there was a port
2138 * VLAN but now there is a new and different port VLAN being set.
2139 * Before deleting all the old VLAN filters we must add new ones
2140 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2141 * MAC addresses deleted.
2143 if ((!(vlan_id || qos) ||
2144 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2146 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2148 if (vsi->info.pvid) {
2150 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2153 dev_info(&vsi->back->pdev->dev,
2154 "remove VLAN failed, ret=%d, aq_err=%d\n",
2155 ret, pf->hw.aq.asq_last_status);
2159 ret = i40e_vsi_add_pvid(vsi,
2160 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2162 i40e_vsi_remove_pvid(vsi);
2165 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2166 vlan_id, qos, vf_id);
2168 /* add new VLAN filter */
2169 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2171 dev_info(&vsi->back->pdev->dev,
2172 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2173 vsi->back->hw.aq.asq_last_status);
2176 /* Kill non-vlan MAC filters - ignore error return since
2177 * there might not be any non-vlan MAC filters.
2179 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2183 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2186 /* The Port VLAN needs to be saved across resets the same as the
2187 * default LAN MAC address.
2189 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2196 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2197 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2199 * i40e_ndo_set_vf_bw
2200 * @netdev: network interface device structure
2201 * @vf_id: VF identifier
2204 * configure VF Tx rate
2206 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2209 struct i40e_netdev_priv *np = netdev_priv(netdev);
2210 struct i40e_pf *pf = np->vsi->back;
2211 struct i40e_vsi *vsi;
2216 /* validate the request */
2217 if (vf_id >= pf->num_alloc_vfs) {
2218 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2224 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2225 min_tx_rate, vf_id);
2229 vf = &(pf->vf[vf_id]);
2230 vsi = pf->vsi[vf->lan_vsi_idx];
2231 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2232 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2237 switch (pf->hw.phy.link_info.link_speed) {
2238 case I40E_LINK_SPEED_40GB:
2241 case I40E_LINK_SPEED_10GB:
2244 case I40E_LINK_SPEED_1GB:
2251 if (max_tx_rate > speed) {
2252 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
2253 max_tx_rate, vf->vf_id);
2258 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2259 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2263 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2264 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2265 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2266 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2268 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2273 vf->tx_rate = max_tx_rate;
2279 * i40e_ndo_get_vf_config
2280 * @netdev: network interface device structure
2281 * @vf_id: VF identifier
2282 * @ivi: VF configuration structure
2284 * return VF configuration
2286 int i40e_ndo_get_vf_config(struct net_device *netdev,
2287 int vf_id, struct ifla_vf_info *ivi)
2289 struct i40e_netdev_priv *np = netdev_priv(netdev);
2290 struct i40e_vsi *vsi = np->vsi;
2291 struct i40e_pf *pf = vsi->back;
2295 /* validate the request */
2296 if (vf_id >= pf->num_alloc_vfs) {
2297 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2302 vf = &(pf->vf[vf_id]);
2303 /* first vsi is always the LAN vsi */
2304 vsi = pf->vsi[vf->lan_vsi_idx];
2305 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2306 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2313 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
2315 ivi->max_tx_rate = vf->tx_rate;
2316 ivi->min_tx_rate = 0;
2317 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2318 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2319 I40E_VLAN_PRIORITY_SHIFT;
2320 if (vf->link_forced == false)
2321 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2322 else if (vf->link_up == true)
2323 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2325 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
2326 ivi->spoofchk = vf->spoofchk;
2334 * i40e_ndo_set_vf_link_state
2335 * @netdev: network interface device structure
2336 * @vf_id: VF identifier
2337 * @link: required link state
2339 * Set the link state of a specified VF, regardless of physical link state
2341 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2343 struct i40e_netdev_priv *np = netdev_priv(netdev);
2344 struct i40e_pf *pf = np->vsi->back;
2345 struct i40e_virtchnl_pf_event pfe;
2346 struct i40e_hw *hw = &pf->hw;
2351 /* validate the request */
2352 if (vf_id >= pf->num_alloc_vfs) {
2353 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2358 vf = &pf->vf[vf_id];
2359 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
2361 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2362 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2365 case IFLA_VF_LINK_STATE_AUTO:
2366 vf->link_forced = false;
2367 pfe.event_data.link_event.link_status =
2368 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2369 pfe.event_data.link_event.link_speed =
2370 pf->hw.phy.link_info.link_speed;
2372 case IFLA_VF_LINK_STATE_ENABLE:
2373 vf->link_forced = true;
2375 pfe.event_data.link_event.link_status = true;
2376 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2378 case IFLA_VF_LINK_STATE_DISABLE:
2379 vf->link_forced = true;
2380 vf->link_up = false;
2381 pfe.event_data.link_event.link_status = false;
2382 pfe.event_data.link_event.link_speed = 0;
2388 /* Notify the VF of its new link state */
2389 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2390 0, (u8 *)&pfe, sizeof(pfe), NULL);
2397 * i40e_ndo_set_vf_spoofchk
2398 * @netdev: network interface device structure
2399 * @vf_id: VF identifier
2400 * @enable: flag to enable or disable feature
2402 * Enable or disable VF spoof checking
2404 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
2406 struct i40e_netdev_priv *np = netdev_priv(netdev);
2407 struct i40e_vsi *vsi = np->vsi;
2408 struct i40e_pf *pf = vsi->back;
2409 struct i40e_vsi_context ctxt;
2410 struct i40e_hw *hw = &pf->hw;
2414 /* validate the request */
2415 if (vf_id >= pf->num_alloc_vfs) {
2416 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2421 vf = &(pf->vf[vf_id]);
2423 if (enable == vf->spoofchk)
2426 vf->spoofchk = enable;
2427 memset(&ctxt, 0, sizeof(ctxt));
2428 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
2429 ctxt.pf_num = pf->hw.pf_id;
2430 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2432 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2433 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
2434 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2436 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",