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);
343 * i40e_config_vsi_tx_queue
344 * @vf: pointer to the VF info
345 * @vsi_id: id of VSI as provided by the FW
346 * @vsi_queue_id: vsi relative queue index
347 * @info: config. info
351 static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
353 struct i40e_virtchnl_txq_info *info)
355 struct i40e_pf *pf = vf->pf;
356 struct i40e_hw *hw = &pf->hw;
357 struct i40e_hmc_obj_txq tx_ctx;
358 struct i40e_vsi *vsi;
363 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
364 vsi = i40e_find_vsi_from_id(pf, vsi_id);
366 /* clear the context structure first */
367 memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
369 /* only set the required fields */
370 tx_ctx.base = info->dma_ring_addr / 128;
371 tx_ctx.qlen = info->ring_len;
372 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
373 tx_ctx.rdylist_act = 0;
374 tx_ctx.head_wb_ena = info->headwb_enabled;
375 tx_ctx.head_wb_addr = info->dma_headwb_addr;
377 /* clear the context in the HMC */
378 ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
380 dev_err(&pf->pdev->dev,
381 "Failed to clear VF LAN Tx queue context %d, error: %d\n",
387 /* set the context in the HMC */
388 ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
390 dev_err(&pf->pdev->dev,
391 "Failed to set VF LAN Tx queue context %d error: %d\n",
397 /* associate this queue with the PCI VF function */
398 qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
399 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
400 & I40E_QTX_CTL_PF_INDX_MASK);
401 qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
402 << I40E_QTX_CTL_VFVM_INDX_SHIFT)
403 & I40E_QTX_CTL_VFVM_INDX_MASK);
404 wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
412 * i40e_config_vsi_rx_queue
413 * @vf: pointer to the VF info
414 * @vsi_id: id of VSI as provided by the FW
415 * @vsi_queue_id: vsi relative queue index
416 * @info: config. info
420 static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
422 struct i40e_virtchnl_rxq_info *info)
424 struct i40e_pf *pf = vf->pf;
425 struct i40e_hw *hw = &pf->hw;
426 struct i40e_hmc_obj_rxq rx_ctx;
430 pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
432 /* clear the context structure first */
433 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
435 /* only set the required fields */
436 rx_ctx.base = info->dma_ring_addr / 128;
437 rx_ctx.qlen = info->ring_len;
439 if (info->splithdr_enabled) {
440 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
442 I40E_RX_SPLIT_TCP_UDP |
444 /* header length validation */
445 if (info->hdr_size > ((2 * 1024) - 64)) {
449 rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
451 /* set splitalways mode 10b */
455 /* databuffer length validation */
456 if (info->databuffer_size > ((16 * 1024) - 128)) {
460 rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
462 /* max pkt. length validation */
463 if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
467 rx_ctx.rxmax = info->max_pkt_size;
469 /* enable 32bytes desc always */
473 rx_ctx.lrxqthresh = 2;
478 /* clear the context in the HMC */
479 ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
481 dev_err(&pf->pdev->dev,
482 "Failed to clear VF LAN Rx queue context %d, error: %d\n",
488 /* set the context in the HMC */
489 ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
491 dev_err(&pf->pdev->dev,
492 "Failed to set VF LAN Rx queue context %d error: %d\n",
504 * @vf: pointer to the VF info
505 * @type: type of VSI to allocate
507 * alloc VF vsi context & resources
509 static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
511 struct i40e_mac_filter *f = NULL;
512 struct i40e_pf *pf = vf->pf;
513 struct i40e_vsi *vsi;
516 vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
519 dev_err(&pf->pdev->dev,
520 "add vsi failed for VF %d, aq_err %d\n",
521 vf->vf_id, pf->hw.aq.asq_last_status);
523 goto error_alloc_vsi_res;
525 if (type == I40E_VSI_SRIOV) {
526 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
527 vf->lan_vsi_idx = vsi->idx;
528 vf->lan_vsi_id = vsi->id;
529 /* If the port VLAN has been configured and then the
530 * VF driver was removed then the VSI port VLAN
531 * configuration was destroyed. Check if there is
532 * a port VLAN and restore the VSI configuration if
535 if (vf->port_vlan_id)
536 i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
537 f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
538 vf->port_vlan_id ? vf->port_vlan_id : -1,
541 dev_info(&pf->pdev->dev,
542 "Could not allocate VF MAC addr\n");
543 f = i40e_add_filter(vsi, brdcast,
544 vf->port_vlan_id ? vf->port_vlan_id : -1,
547 dev_info(&pf->pdev->dev,
548 "Could not allocate VF broadcast filter\n");
551 /* program mac filter */
552 ret = i40e_sync_vsi_filters(vsi);
554 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
556 /* Set VF bandwidth if specified */
558 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
559 vf->tx_rate / 50, 0, NULL);
561 dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
570 * i40e_enable_vf_mappings
571 * @vf: pointer to the VF info
575 static void i40e_enable_vf_mappings(struct i40e_vf *vf)
577 struct i40e_pf *pf = vf->pf;
578 struct i40e_hw *hw = &pf->hw;
579 u32 reg, total_queue_pairs = 0;
582 /* Tell the hardware we're using noncontiguous mapping. HW requires
583 * that VF queues be mapped using this method, even when they are
584 * contiguous in real life
586 wr32(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
587 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
589 /* enable VF vplan_qtable mappings */
590 reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
591 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
593 /* map PF queues to VF queues */
594 for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
595 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
596 reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
597 wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
601 /* map PF queues to VSI */
602 for (j = 0; j < 7; j++) {
603 if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
604 reg = 0x07FF07FF; /* unused */
606 u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
609 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
613 wr32(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id), reg);
620 * i40e_disable_vf_mappings
621 * @vf: pointer to the VF info
623 * disable VF mappings
625 static void i40e_disable_vf_mappings(struct i40e_vf *vf)
627 struct i40e_pf *pf = vf->pf;
628 struct i40e_hw *hw = &pf->hw;
631 /* disable qp mappings */
632 wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
633 for (i = 0; i < I40E_MAX_VSI_QP; i++)
634 wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
635 I40E_QUEUE_END_OF_LIST);
641 * @vf: pointer to the VF info
645 static void i40e_free_vf_res(struct i40e_vf *vf)
647 struct i40e_pf *pf = vf->pf;
648 struct i40e_hw *hw = &pf->hw;
652 /* free vsi & disconnect it from the parent uplink */
653 if (vf->lan_vsi_idx) {
654 i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
658 msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
660 /* disable interrupts so the VF starts in a known state */
661 for (i = 0; i < msix_vf; i++) {
662 /* format is same for both registers */
664 reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
666 reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
669 wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
673 /* clear the irq settings */
674 for (i = 0; i < msix_vf; i++) {
675 /* format is same for both registers */
677 reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
679 reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
682 reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
683 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
684 wr32(hw, reg_idx, reg);
687 /* reset some of the state varibles keeping
688 * track of the resources
690 vf->num_queue_pairs = 0;
696 * @vf: pointer to the VF info
698 * allocate VF resources
700 static int i40e_alloc_vf_res(struct i40e_vf *vf)
702 struct i40e_pf *pf = vf->pf;
703 int total_queue_pairs = 0;
706 /* allocate hw vsi context & associated resources */
707 ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
710 total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
711 set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
713 /* store the total qps number for the runtime
716 vf->num_queue_pairs = total_queue_pairs;
718 /* VF is now completely initialized */
719 set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
723 i40e_free_vf_res(vf);
728 #define VF_DEVICE_STATUS 0xAA
729 #define VF_TRANS_PENDING_MASK 0x20
731 * i40e_quiesce_vf_pci
732 * @vf: pointer to the VF structure
734 * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
735 * if the transactions never clear.
737 static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
739 struct i40e_pf *pf = vf->pf;
740 struct i40e_hw *hw = &pf->hw;
744 vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
746 wr32(hw, I40E_PF_PCI_CIAA,
747 VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
748 for (i = 0; i < 100; i++) {
749 reg = rd32(hw, I40E_PF_PCI_CIAD);
750 if ((reg & VF_TRANS_PENDING_MASK) == 0)
759 * @vf: pointer to the VF structure
760 * @flr: VFLR was issued or not
764 void i40e_reset_vf(struct i40e_vf *vf, bool flr)
766 struct i40e_pf *pf = vf->pf;
767 struct i40e_hw *hw = &pf->hw;
772 if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
776 clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
778 /* In the case of a VFLR, the HW has already reset the VF and we
779 * just need to clean up, so don't hit the VFRTRIG register.
782 /* reset VF using VPGEN_VFRTRIG reg */
783 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
784 reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
785 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
789 if (i40e_quiesce_vf_pci(vf))
790 dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
793 /* poll VPGEN_VFRSTAT reg to make sure
794 * that reset is complete
796 for (i = 0; i < 10; i++) {
797 /* VF reset requires driver to first reset the VF and then
798 * poll the status register to make sure that the reset
799 * completed successfully. Due to internal HW FIFO flushes,
800 * we must wait 10ms before the register will be valid.
802 usleep_range(10000, 20000);
803 reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
804 if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
811 usleep_range(10000, 20000);
814 dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
816 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
817 /* clear the reset bit in the VPGEN_VFRTRIG reg */
818 reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
819 reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
820 wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
822 /* On initial reset, we won't have any queues */
823 if (vf->lan_vsi_idx == 0)
826 i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
828 /* reallocate VF resources to reset the VSI state */
829 i40e_free_vf_res(vf);
830 i40e_alloc_vf_res(vf);
831 i40e_enable_vf_mappings(vf);
832 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
833 clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
835 /* tell the VF the reset is done */
836 wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
838 clear_bit(__I40E_VF_DISABLE, &pf->state);
843 * @pf: pointer to the PF structure
847 void i40e_free_vfs(struct i40e_pf *pf)
849 struct i40e_hw *hw = &pf->hw;
850 u32 reg_idx, bit_idx;
855 while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
856 usleep_range(1000, 2000);
858 for (i = 0; i < pf->num_alloc_vfs; i++)
859 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
860 i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
863 /* Disable IOV before freeing resources. This lets any VF drivers
864 * running in the host get themselves cleaned up before we yank
865 * the carpet out from underneath their feet.
867 if (!pci_vfs_assigned(pf->pdev))
868 pci_disable_sriov(pf->pdev);
870 dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
872 msleep(20); /* let any messages in transit get finished up */
874 /* free up VF resources */
875 tmp = pf->num_alloc_vfs;
876 pf->num_alloc_vfs = 0;
877 for (i = 0; i < tmp; i++) {
878 if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
879 i40e_free_vf_res(&pf->vf[i]);
880 /* disable qp mappings */
881 i40e_disable_vf_mappings(&pf->vf[i]);
887 /* This check is for when the driver is unloaded while VFs are
888 * assigned. Setting the number of VFs to 0 through sysfs is caught
889 * before this function ever gets called.
891 if (!pci_vfs_assigned(pf->pdev)) {
892 /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
893 * work correctly when SR-IOV gets re-enabled.
895 for (vf_id = 0; vf_id < tmp; vf_id++) {
896 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
897 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
898 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
901 clear_bit(__I40E_VF_DISABLE, &pf->state);
904 #ifdef CONFIG_PCI_IOV
907 * @pf: pointer to the PF structure
908 * @num_alloc_vfs: number of VFs to allocate
910 * allocate VF resources
912 int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
917 /* Disable interrupt 0 so we don't try to handle the VFLR. */
918 i40e_irq_dynamic_disable_icr0(pf);
920 /* Check to see if we're just allocating resources for extant VFs */
921 if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
922 ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
924 dev_err(&pf->pdev->dev,
925 "Failed to enable SR-IOV, error %d.\n", ret);
926 pf->num_alloc_vfs = 0;
930 /* allocate memory */
931 vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
938 /* apply default profile */
939 for (i = 0; i < num_alloc_vfs; i++) {
941 vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
944 /* assign default capabilities */
945 set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
946 vfs[i].spoofchk = true;
947 /* VF resources get allocated during reset */
948 i40e_reset_vf(&vfs[i], false);
950 /* enable VF vplan_qtable mappings */
951 i40e_enable_vf_mappings(&vfs[i]);
953 pf->num_alloc_vfs = num_alloc_vfs;
959 /* Re-enable interrupt 0. */
960 i40e_irq_dynamic_enable_icr0(pf);
966 * i40e_pci_sriov_enable
967 * @pdev: pointer to a pci_dev structure
968 * @num_vfs: number of VFs to allocate
970 * Enable or change the number of VFs
972 static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
974 #ifdef CONFIG_PCI_IOV
975 struct i40e_pf *pf = pci_get_drvdata(pdev);
976 int pre_existing_vfs = pci_num_vf(pdev);
979 if (pf->state & __I40E_TESTING) {
981 "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
986 dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
987 if (pre_existing_vfs && pre_existing_vfs != num_vfs)
989 else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
992 if (num_vfs > pf->num_req_vfs) {
997 err = i40e_alloc_vfs(pf, num_vfs);
999 dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
1013 * i40e_pci_sriov_configure
1014 * @pdev: pointer to a pci_dev structure
1015 * @num_vfs: number of VFs to allocate
1017 * Enable or change the number of VFs. Called when the user updates the number
1020 int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
1022 struct i40e_pf *pf = pci_get_drvdata(pdev);
1025 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
1026 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
1027 i40e_do_reset_safe(pf,
1028 BIT_ULL(__I40E_PF_RESET_REQUESTED));
1030 return i40e_pci_sriov_enable(pdev, num_vfs);
1033 if (!pci_vfs_assigned(pf->pdev)) {
1035 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
1036 i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
1038 dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
1044 /***********************virtual channel routines******************/
1047 * i40e_vc_send_msg_to_vf
1048 * @vf: pointer to the VF info
1049 * @v_opcode: virtual channel opcode
1050 * @v_retval: virtual channel return value
1051 * @msg: pointer to the msg buffer
1052 * @msglen: msg length
1056 static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
1057 u32 v_retval, u8 *msg, u16 msglen)
1064 /* validate the request */
1065 if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
1070 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
1072 /* single place to detect unsuccessful return values */
1074 vf->num_invalid_msgs++;
1075 dev_err(&pf->pdev->dev, "Failed opcode %d Error: %d\n",
1076 v_opcode, v_retval);
1077 if (vf->num_invalid_msgs >
1078 I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
1079 dev_err(&pf->pdev->dev,
1080 "Number of invalid messages exceeded for VF %d\n",
1082 dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
1083 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
1086 vf->num_valid_msgs++;
1089 aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
1092 dev_err(&pf->pdev->dev,
1093 "Unable to send the message to VF %d aq_err %d\n",
1094 vf->vf_id, pf->hw.aq.asq_last_status);
1102 * i40e_vc_send_resp_to_vf
1103 * @vf: pointer to the VF info
1104 * @opcode: operation code
1105 * @retval: return value
1107 * send resp msg to VF
1109 static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
1110 enum i40e_virtchnl_ops opcode,
1113 return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
1117 * i40e_vc_get_version_msg
1118 * @vf: pointer to the VF info
1120 * called from the VF to request the API version used by the PF
1122 static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
1124 struct i40e_virtchnl_version_info info = {
1125 I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
1128 vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
1129 /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
1131 info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
1132 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
1133 I40E_SUCCESS, (u8 *)&info,
1135 i40e_virtchnl_version_info));
1139 * i40e_vc_get_vf_resources_msg
1140 * @vf: pointer to the VF info
1141 * @msg: pointer to the msg buffer
1142 * @msglen: msg length
1144 * called from the VF to request its resources
1146 static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
1148 struct i40e_virtchnl_vf_resource *vfres = NULL;
1149 struct i40e_pf *pf = vf->pf;
1150 i40e_status aq_ret = 0;
1151 struct i40e_vsi *vsi;
1156 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
1157 aq_ret = I40E_ERR_PARAM;
1161 len = (sizeof(struct i40e_virtchnl_vf_resource) +
1162 sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
1164 vfres = kzalloc(len, GFP_KERNEL);
1166 aq_ret = I40E_ERR_NO_MEMORY;
1171 vf->driver_caps = *(u32 *)msg;
1173 vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
1174 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1175 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1177 vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
1178 vsi = pf->vsi[vf->lan_vsi_idx];
1179 if (!vsi->info.pvid)
1180 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
1181 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
1182 if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
1183 vfres->vf_offload_flags |=
1184 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
1186 vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
1188 vfres->num_vsis = num_vsis;
1189 vfres->num_queue_pairs = vf->num_queue_pairs;
1190 vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
1191 if (vf->lan_vsi_idx) {
1192 vfres->vsi_res[i].vsi_id = vf->lan_vsi_id;
1193 vfres->vsi_res[i].vsi_type = I40E_VSI_SRIOV;
1194 vfres->vsi_res[i].num_queue_pairs =
1195 pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
1196 memcpy(vfres->vsi_res[i].default_mac_addr,
1197 vf->default_lan_addr.addr, ETH_ALEN);
1200 set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
1203 /* send the response back to the VF */
1204 ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
1205 aq_ret, (u8 *)vfres, len);
1212 * i40e_vc_reset_vf_msg
1213 * @vf: pointer to the VF info
1214 * @msg: pointer to the msg buffer
1215 * @msglen: msg length
1217 * called from the VF to reset itself,
1218 * unlike other virtchnl messages, PF driver
1219 * doesn't send the response back to the VF
1221 static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
1223 if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
1224 i40e_reset_vf(vf, false);
1228 * i40e_vc_config_promiscuous_mode_msg
1229 * @vf: pointer to the VF info
1230 * @msg: pointer to the msg buffer
1231 * @msglen: msg length
1233 * called from the VF to configure the promiscuous mode of
1236 static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
1237 u8 *msg, u16 msglen)
1239 struct i40e_virtchnl_promisc_info *info =
1240 (struct i40e_virtchnl_promisc_info *)msg;
1241 struct i40e_pf *pf = vf->pf;
1242 struct i40e_hw *hw = &pf->hw;
1243 struct i40e_vsi *vsi;
1244 bool allmulti = false;
1247 vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
1248 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1249 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1250 !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
1251 (vsi->type != I40E_VSI_FCOE)) {
1252 aq_ret = I40E_ERR_PARAM;
1255 if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
1257 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1261 /* send the response to the VF */
1262 return i40e_vc_send_resp_to_vf(vf,
1263 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1268 * i40e_vc_config_queues_msg
1269 * @vf: pointer to the VF info
1270 * @msg: pointer to the msg buffer
1271 * @msglen: msg length
1273 * called from the VF to configure the rx/tx
1276 static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1278 struct i40e_virtchnl_vsi_queue_config_info *qci =
1279 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1280 struct i40e_virtchnl_queue_pair_info *qpi;
1281 struct i40e_pf *pf = vf->pf;
1282 u16 vsi_id, vsi_queue_id;
1283 i40e_status aq_ret = 0;
1286 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1287 aq_ret = I40E_ERR_PARAM;
1291 vsi_id = qci->vsi_id;
1292 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1293 aq_ret = I40E_ERR_PARAM;
1296 for (i = 0; i < qci->num_queue_pairs; i++) {
1297 qpi = &qci->qpair[i];
1298 vsi_queue_id = qpi->txq.queue_id;
1299 if ((qpi->txq.vsi_id != vsi_id) ||
1300 (qpi->rxq.vsi_id != vsi_id) ||
1301 (qpi->rxq.queue_id != vsi_queue_id) ||
1302 !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
1303 aq_ret = I40E_ERR_PARAM;
1307 if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
1309 i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
1311 aq_ret = I40E_ERR_PARAM;
1315 /* set vsi num_queue_pairs in use to num configured by VF */
1316 pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
1319 /* send the response to the VF */
1320 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
1325 * i40e_vc_config_irq_map_msg
1326 * @vf: pointer to the VF info
1327 * @msg: pointer to the msg buffer
1328 * @msglen: msg length
1330 * called from the VF to configure the irq to
1333 static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1335 struct i40e_virtchnl_irq_map_info *irqmap_info =
1336 (struct i40e_virtchnl_irq_map_info *)msg;
1337 struct i40e_virtchnl_vector_map *map;
1338 u16 vsi_id, vsi_queue_id, vector_id;
1339 i40e_status aq_ret = 0;
1340 unsigned long tempmap;
1343 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1344 aq_ret = I40E_ERR_PARAM;
1348 for (i = 0; i < irqmap_info->num_vectors; i++) {
1349 map = &irqmap_info->vecmap[i];
1351 vector_id = map->vector_id;
1352 vsi_id = map->vsi_id;
1353 /* validate msg params */
1354 if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
1355 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1356 aq_ret = I40E_ERR_PARAM;
1360 /* lookout for the invalid queue index */
1361 tempmap = map->rxq_map;
1362 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1363 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1365 aq_ret = I40E_ERR_PARAM;
1370 tempmap = map->txq_map;
1371 for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
1372 if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
1374 aq_ret = I40E_ERR_PARAM;
1379 i40e_config_irq_link_list(vf, vsi_id, map);
1382 /* send the response to the VF */
1383 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
1388 * i40e_vc_enable_queues_msg
1389 * @vf: pointer to the VF info
1390 * @msg: pointer to the msg buffer
1391 * @msglen: msg length
1393 * called from the VF to enable all or specific queue(s)
1395 static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1397 struct i40e_virtchnl_queue_select *vqs =
1398 (struct i40e_virtchnl_queue_select *)msg;
1399 struct i40e_pf *pf = vf->pf;
1400 u16 vsi_id = vqs->vsi_id;
1401 i40e_status aq_ret = 0;
1403 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1404 aq_ret = I40E_ERR_PARAM;
1408 if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1409 aq_ret = I40E_ERR_PARAM;
1413 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1414 aq_ret = I40E_ERR_PARAM;
1418 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
1419 aq_ret = I40E_ERR_TIMEOUT;
1421 /* send the response to the VF */
1422 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1427 * i40e_vc_disable_queues_msg
1428 * @vf: pointer to the VF info
1429 * @msg: pointer to the msg buffer
1430 * @msglen: msg length
1432 * called from the VF to disable all or specific
1435 static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1437 struct i40e_virtchnl_queue_select *vqs =
1438 (struct i40e_virtchnl_queue_select *)msg;
1439 struct i40e_pf *pf = vf->pf;
1440 i40e_status aq_ret = 0;
1442 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1443 aq_ret = I40E_ERR_PARAM;
1447 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1448 aq_ret = I40E_ERR_PARAM;
1452 if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
1453 aq_ret = I40E_ERR_PARAM;
1457 if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
1458 aq_ret = I40E_ERR_TIMEOUT;
1461 /* send the response to the VF */
1462 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
1467 * i40e_vc_get_stats_msg
1468 * @vf: pointer to the VF info
1469 * @msg: pointer to the msg buffer
1470 * @msglen: msg length
1472 * called from the VF to get vsi stats
1474 static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1476 struct i40e_virtchnl_queue_select *vqs =
1477 (struct i40e_virtchnl_queue_select *)msg;
1478 struct i40e_pf *pf = vf->pf;
1479 struct i40e_eth_stats stats;
1480 i40e_status aq_ret = 0;
1481 struct i40e_vsi *vsi;
1483 memset(&stats, 0, sizeof(struct i40e_eth_stats));
1485 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
1486 aq_ret = I40E_ERR_PARAM;
1490 if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
1491 aq_ret = I40E_ERR_PARAM;
1495 vsi = pf->vsi[vf->lan_vsi_idx];
1497 aq_ret = I40E_ERR_PARAM;
1500 i40e_update_eth_stats(vsi);
1501 stats = vsi->eth_stats;
1504 /* send the response back to the VF */
1505 return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
1506 (u8 *)&stats, sizeof(stats));
1510 * i40e_check_vf_permission
1511 * @vf: pointer to the VF info
1512 * @macaddr: pointer to the MAC Address being checked
1514 * Check if the VF has permission to add or delete unicast MAC address
1515 * filters and return error code -EPERM if not. Then check if the
1516 * address filter requested is broadcast or zero and if so return
1517 * an invalid MAC address error code.
1519 static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
1521 struct i40e_pf *pf = vf->pf;
1524 if (is_broadcast_ether_addr(macaddr) ||
1525 is_zero_ether_addr(macaddr)) {
1526 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
1527 ret = I40E_ERR_INVALID_MAC_ADDR;
1528 } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
1529 !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
1530 /* If the host VMM administrator has set the VF MAC address
1531 * administratively via the ndo_set_vf_mac command then deny
1532 * permission to the VF to add or delete unicast MAC addresses.
1533 * The VF may request to set the MAC address filter already
1534 * assigned to it so do not return an error in that case.
1536 dev_err(&pf->pdev->dev,
1537 "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
1544 * i40e_vc_add_mac_addr_msg
1545 * @vf: pointer to the VF info
1546 * @msg: pointer to the msg buffer
1547 * @msglen: msg length
1549 * add guest mac address filter
1551 static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1553 struct i40e_virtchnl_ether_addr_list *al =
1554 (struct i40e_virtchnl_ether_addr_list *)msg;
1555 struct i40e_pf *pf = vf->pf;
1556 struct i40e_vsi *vsi = NULL;
1557 u16 vsi_id = al->vsi_id;
1558 i40e_status ret = 0;
1561 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1562 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1563 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1564 ret = I40E_ERR_PARAM;
1568 for (i = 0; i < al->num_elements; i++) {
1569 ret = i40e_check_vf_permission(vf, al->list[i].addr);
1573 vsi = pf->vsi[vf->lan_vsi_idx];
1575 /* add new addresses to the list */
1576 for (i = 0; i < al->num_elements; i++) {
1577 struct i40e_mac_filter *f;
1579 f = i40e_find_mac(vsi, al->list[i].addr, true, false);
1581 if (i40e_is_vsi_in_vlan(vsi))
1582 f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
1585 f = i40e_add_filter(vsi, al->list[i].addr, -1,
1590 dev_err(&pf->pdev->dev,
1591 "Unable to add VF MAC filter\n");
1592 ret = I40E_ERR_PARAM;
1597 /* program the updated filter list */
1598 if (i40e_sync_vsi_filters(vsi))
1599 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1602 /* send the response to the VF */
1603 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
1608 * i40e_vc_del_mac_addr_msg
1609 * @vf: pointer to the VF info
1610 * @msg: pointer to the msg buffer
1611 * @msglen: msg length
1613 * remove guest mac address filter
1615 static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1617 struct i40e_virtchnl_ether_addr_list *al =
1618 (struct i40e_virtchnl_ether_addr_list *)msg;
1619 struct i40e_pf *pf = vf->pf;
1620 struct i40e_vsi *vsi = NULL;
1621 u16 vsi_id = al->vsi_id;
1622 i40e_status ret = 0;
1625 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1626 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1627 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1628 ret = I40E_ERR_PARAM;
1632 for (i = 0; i < al->num_elements; i++) {
1633 if (is_broadcast_ether_addr(al->list[i].addr) ||
1634 is_zero_ether_addr(al->list[i].addr)) {
1635 dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
1637 ret = I40E_ERR_INVALID_MAC_ADDR;
1641 vsi = pf->vsi[vf->lan_vsi_idx];
1643 /* delete addresses from the list */
1644 for (i = 0; i < al->num_elements; i++)
1645 i40e_del_filter(vsi, al->list[i].addr,
1646 I40E_VLAN_ANY, true, false);
1648 /* program the updated filter list */
1649 if (i40e_sync_vsi_filters(vsi))
1650 dev_err(&pf->pdev->dev, "Unable to program VF MAC filters\n");
1653 /* send the response to the VF */
1654 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
1659 * i40e_vc_add_vlan_msg
1660 * @vf: pointer to the VF info
1661 * @msg: pointer to the msg buffer
1662 * @msglen: msg length
1664 * program guest vlan id
1666 static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1668 struct i40e_virtchnl_vlan_filter_list *vfl =
1669 (struct i40e_virtchnl_vlan_filter_list *)msg;
1670 struct i40e_pf *pf = vf->pf;
1671 struct i40e_vsi *vsi = NULL;
1672 u16 vsi_id = vfl->vsi_id;
1673 i40e_status aq_ret = 0;
1676 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1677 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1678 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1679 aq_ret = I40E_ERR_PARAM;
1683 for (i = 0; i < vfl->num_elements; i++) {
1684 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1685 aq_ret = I40E_ERR_PARAM;
1686 dev_err(&pf->pdev->dev,
1687 "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
1691 vsi = pf->vsi[vf->lan_vsi_idx];
1692 if (vsi->info.pvid) {
1693 aq_ret = I40E_ERR_PARAM;
1697 i40e_vlan_stripping_enable(vsi);
1698 for (i = 0; i < vfl->num_elements; i++) {
1699 /* add new VLAN filter */
1700 int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
1702 dev_err(&pf->pdev->dev,
1703 "Unable to add VF vlan filter %d, error %d\n",
1704 vfl->vlan_id[i], ret);
1708 /* send the response to the VF */
1709 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
1713 * i40e_vc_remove_vlan_msg
1714 * @vf: pointer to the VF info
1715 * @msg: pointer to the msg buffer
1716 * @msglen: msg length
1718 * remove programmed guest vlan id
1720 static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
1722 struct i40e_virtchnl_vlan_filter_list *vfl =
1723 (struct i40e_virtchnl_vlan_filter_list *)msg;
1724 struct i40e_pf *pf = vf->pf;
1725 struct i40e_vsi *vsi = NULL;
1726 u16 vsi_id = vfl->vsi_id;
1727 i40e_status aq_ret = 0;
1730 if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
1731 !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
1732 !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
1733 aq_ret = I40E_ERR_PARAM;
1737 for (i = 0; i < vfl->num_elements; i++) {
1738 if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
1739 aq_ret = I40E_ERR_PARAM;
1744 vsi = pf->vsi[vf->lan_vsi_idx];
1745 if (vsi->info.pvid) {
1746 aq_ret = I40E_ERR_PARAM;
1750 for (i = 0; i < vfl->num_elements; i++) {
1751 int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
1753 dev_err(&pf->pdev->dev,
1754 "Unable to delete VF vlan filter %d, error %d\n",
1755 vfl->vlan_id[i], ret);
1759 /* send the response to the VF */
1760 return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
1764 * i40e_vc_validate_vf_msg
1765 * @vf: pointer to the VF info
1766 * @msg: pointer to the msg buffer
1767 * @msglen: msg length
1768 * @msghndl: msg handle
1772 static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
1773 u32 v_retval, u8 *msg, u16 msglen)
1775 bool err_msg_format = false;
1778 /* Check if VF is disabled. */
1779 if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
1780 return I40E_ERR_PARAM;
1782 /* Validate message length. */
1784 case I40E_VIRTCHNL_OP_VERSION:
1785 valid_len = sizeof(struct i40e_virtchnl_version_info);
1787 case I40E_VIRTCHNL_OP_RESET_VF:
1790 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1792 valid_len = sizeof(u32);
1796 case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
1797 valid_len = sizeof(struct i40e_virtchnl_txq_info);
1799 case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
1800 valid_len = sizeof(struct i40e_virtchnl_rxq_info);
1802 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1803 valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
1804 if (msglen >= valid_len) {
1805 struct i40e_virtchnl_vsi_queue_config_info *vqc =
1806 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
1807 valid_len += (vqc->num_queue_pairs *
1809 i40e_virtchnl_queue_pair_info));
1810 if (vqc->num_queue_pairs == 0)
1811 err_msg_format = true;
1814 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1815 valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
1816 if (msglen >= valid_len) {
1817 struct i40e_virtchnl_irq_map_info *vimi =
1818 (struct i40e_virtchnl_irq_map_info *)msg;
1819 valid_len += (vimi->num_vectors *
1820 sizeof(struct i40e_virtchnl_vector_map));
1821 if (vimi->num_vectors == 0)
1822 err_msg_format = true;
1825 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1826 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1827 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1829 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1830 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1831 valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
1832 if (msglen >= valid_len) {
1833 struct i40e_virtchnl_ether_addr_list *veal =
1834 (struct i40e_virtchnl_ether_addr_list *)msg;
1835 valid_len += veal->num_elements *
1836 sizeof(struct i40e_virtchnl_ether_addr);
1837 if (veal->num_elements == 0)
1838 err_msg_format = true;
1841 case I40E_VIRTCHNL_OP_ADD_VLAN:
1842 case I40E_VIRTCHNL_OP_DEL_VLAN:
1843 valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
1844 if (msglen >= valid_len) {
1845 struct i40e_virtchnl_vlan_filter_list *vfl =
1846 (struct i40e_virtchnl_vlan_filter_list *)msg;
1847 valid_len += vfl->num_elements * sizeof(u16);
1848 if (vfl->num_elements == 0)
1849 err_msg_format = true;
1852 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1853 valid_len = sizeof(struct i40e_virtchnl_promisc_info);
1855 case I40E_VIRTCHNL_OP_GET_STATS:
1856 valid_len = sizeof(struct i40e_virtchnl_queue_select);
1858 /* These are always errors coming from the VF. */
1859 case I40E_VIRTCHNL_OP_EVENT:
1860 case I40E_VIRTCHNL_OP_UNKNOWN:
1865 /* few more checks */
1866 if ((valid_len != msglen) || (err_msg_format)) {
1867 i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
1875 * i40e_vc_process_vf_msg
1876 * @pf: pointer to the PF structure
1877 * @vf_id: source VF id
1878 * @msg: pointer to the msg buffer
1879 * @msglen: msg length
1880 * @msghndl: msg handle
1882 * called from the common aeq/arq handler to
1883 * process request from VF
1885 int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
1886 u32 v_retval, u8 *msg, u16 msglen)
1888 struct i40e_hw *hw = &pf->hw;
1889 unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
1893 pf->vf_aq_requests++;
1894 if (local_vf_id >= pf->num_alloc_vfs)
1896 vf = &(pf->vf[local_vf_id]);
1897 /* perform basic checks on the msg */
1898 ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
1901 dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
1902 local_vf_id, v_opcode, msglen);
1907 case I40E_VIRTCHNL_OP_VERSION:
1908 ret = i40e_vc_get_version_msg(vf, msg);
1910 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1911 ret = i40e_vc_get_vf_resources_msg(vf, msg);
1913 case I40E_VIRTCHNL_OP_RESET_VF:
1914 i40e_vc_reset_vf_msg(vf);
1917 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1918 ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
1920 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1921 ret = i40e_vc_config_queues_msg(vf, msg, msglen);
1923 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1924 ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
1926 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1927 ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
1928 i40e_vc_notify_vf_link_state(vf);
1930 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1931 ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
1933 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1934 ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
1936 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1937 ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
1939 case I40E_VIRTCHNL_OP_ADD_VLAN:
1940 ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
1942 case I40E_VIRTCHNL_OP_DEL_VLAN:
1943 ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
1945 case I40E_VIRTCHNL_OP_GET_STATS:
1946 ret = i40e_vc_get_stats_msg(vf, msg, msglen);
1948 case I40E_VIRTCHNL_OP_UNKNOWN:
1950 dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
1951 v_opcode, local_vf_id);
1952 ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
1953 I40E_ERR_NOT_IMPLEMENTED);
1961 * i40e_vc_process_vflr_event
1962 * @pf: pointer to the PF structure
1964 * called from the vlfr irq handler to
1965 * free up VF resources and state variables
1967 int i40e_vc_process_vflr_event(struct i40e_pf *pf)
1969 u32 reg, reg_idx, bit_idx, vf_id;
1970 struct i40e_hw *hw = &pf->hw;
1973 if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
1976 /* re-enable vflr interrupt cause */
1977 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
1978 reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
1979 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
1982 clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
1983 for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
1984 reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
1985 bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
1986 /* read GLGEN_VFLRSTAT register to find out the flr VFs */
1987 vf = &pf->vf[vf_id];
1988 reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
1989 if (reg & BIT(bit_idx)) {
1990 /* clear the bit in GLGEN_VFLRSTAT */
1991 wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
1993 if (!test_bit(__I40E_DOWN, &pf->state))
1994 i40e_reset_vf(vf, true);
2002 * i40e_ndo_set_vf_mac
2003 * @netdev: network interface device structure
2004 * @vf_id: VF identifier
2007 * program VF mac address
2009 int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
2011 struct i40e_netdev_priv *np = netdev_priv(netdev);
2012 struct i40e_vsi *vsi = np->vsi;
2013 struct i40e_pf *pf = vsi->back;
2014 struct i40e_mac_filter *f;
2018 /* validate the request */
2019 if (vf_id >= pf->num_alloc_vfs) {
2020 dev_err(&pf->pdev->dev,
2021 "Invalid VF Identifier %d\n", vf_id);
2026 vf = &(pf->vf[vf_id]);
2027 vsi = pf->vsi[vf->lan_vsi_idx];
2028 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2029 dev_err(&pf->pdev->dev,
2030 "Uninitialized VF %d\n", vf_id);
2035 if (!is_valid_ether_addr(mac)) {
2036 dev_err(&pf->pdev->dev,
2037 "Invalid VF ethernet address\n");
2042 /* delete the temporary mac address */
2043 i40e_del_filter(vsi, vf->default_lan_addr.addr,
2044 vf->port_vlan_id ? vf->port_vlan_id : -1,
2047 /* Delete all the filters for this VSI - we're going to kill it
2050 list_for_each_entry(f, &vsi->mac_filter_list, list)
2051 i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
2053 dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
2054 /* program mac filter */
2055 if (i40e_sync_vsi_filters(vsi)) {
2056 dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
2060 ether_addr_copy(vf->default_lan_addr.addr, mac);
2061 vf->pf_set_mac = true;
2062 /* Force the VF driver stop so it has to reload with new MAC address */
2063 i40e_vc_disable_vf(pf, vf);
2064 dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
2071 * i40e_ndo_set_vf_port_vlan
2072 * @netdev: network interface device structure
2073 * @vf_id: VF identifier
2074 * @vlan_id: mac address
2075 * @qos: priority setting
2077 * program VF vlan id and/or qos
2079 int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
2080 int vf_id, u16 vlan_id, u8 qos)
2082 struct i40e_netdev_priv *np = netdev_priv(netdev);
2083 struct i40e_pf *pf = np->vsi->back;
2084 struct i40e_vsi *vsi;
2088 /* validate the request */
2089 if (vf_id >= pf->num_alloc_vfs) {
2090 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2095 if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
2096 dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
2101 vf = &(pf->vf[vf_id]);
2102 vsi = pf->vsi[vf->lan_vsi_idx];
2103 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2104 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2109 if (le16_to_cpu(vsi->info.pvid) ==
2110 (vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT)))
2111 /* duplicate request, so just return success */
2114 if (le16_to_cpu(vsi->info.pvid) == 0 && i40e_is_vsi_in_vlan(vsi)) {
2115 dev_err(&pf->pdev->dev,
2116 "VF %d has already configured VLAN filters and the administrator is requesting a port VLAN override.\nPlease unload and reload the VF driver for this change to take effect.\n",
2118 /* Administrator Error - knock the VF offline until he does
2119 * the right thing by reconfiguring his network correctly
2120 * and then reloading the VF driver.
2122 i40e_vc_disable_vf(pf, vf);
2125 /* Check for condition where there was already a port VLAN ID
2126 * filter set and now it is being deleted by setting it to zero.
2127 * Additionally check for the condition where there was a port
2128 * VLAN but now there is a new and different port VLAN being set.
2129 * Before deleting all the old VLAN filters we must add new ones
2130 * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
2131 * MAC addresses deleted.
2133 if ((!(vlan_id || qos) ||
2134 (vlan_id | qos) != le16_to_cpu(vsi->info.pvid)) &&
2136 ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
2138 if (vsi->info.pvid) {
2140 ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
2143 dev_info(&vsi->back->pdev->dev,
2144 "remove VLAN failed, ret=%d, aq_err=%d\n",
2145 ret, pf->hw.aq.asq_last_status);
2149 ret = i40e_vsi_add_pvid(vsi,
2150 vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT));
2152 i40e_vsi_remove_pvid(vsi);
2155 dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
2156 vlan_id, qos, vf_id);
2158 /* add new VLAN filter */
2159 ret = i40e_vsi_add_vlan(vsi, vlan_id);
2161 dev_info(&vsi->back->pdev->dev,
2162 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
2163 vsi->back->hw.aq.asq_last_status);
2166 /* Kill non-vlan MAC filters - ignore error return since
2167 * there might not be any non-vlan MAC filters.
2169 i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
2173 dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
2176 /* The Port VLAN needs to be saved across resets the same as the
2177 * default LAN MAC address.
2179 vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
2186 #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
2187 #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
2189 * i40e_ndo_set_vf_bw
2190 * @netdev: network interface device structure
2191 * @vf_id: VF identifier
2194 * configure VF Tx rate
2196 int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
2199 struct i40e_netdev_priv *np = netdev_priv(netdev);
2200 struct i40e_pf *pf = np->vsi->back;
2201 struct i40e_vsi *vsi;
2206 /* validate the request */
2207 if (vf_id >= pf->num_alloc_vfs) {
2208 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
2214 dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
2215 min_tx_rate, vf_id);
2219 vf = &(pf->vf[vf_id]);
2220 vsi = pf->vsi[vf->lan_vsi_idx];
2221 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2222 dev_err(&pf->pdev->dev, "Uninitialized VF %d.\n", vf_id);
2227 switch (pf->hw.phy.link_info.link_speed) {
2228 case I40E_LINK_SPEED_40GB:
2231 case I40E_LINK_SPEED_10GB:
2234 case I40E_LINK_SPEED_1GB:
2241 if (max_tx_rate > speed) {
2242 dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
2243 max_tx_rate, vf->vf_id);
2248 if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
2249 dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
2253 /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
2254 ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
2255 max_tx_rate / I40E_BW_CREDIT_DIVISOR,
2256 I40E_MAX_BW_INACTIVE_ACCUM, NULL);
2258 dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
2263 vf->tx_rate = max_tx_rate;
2269 * i40e_ndo_get_vf_config
2270 * @netdev: network interface device structure
2271 * @vf_id: VF identifier
2272 * @ivi: VF configuration structure
2274 * return VF configuration
2276 int i40e_ndo_get_vf_config(struct net_device *netdev,
2277 int vf_id, struct ifla_vf_info *ivi)
2279 struct i40e_netdev_priv *np = netdev_priv(netdev);
2280 struct i40e_vsi *vsi = np->vsi;
2281 struct i40e_pf *pf = vsi->back;
2285 /* validate the request */
2286 if (vf_id >= pf->num_alloc_vfs) {
2287 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2292 vf = &(pf->vf[vf_id]);
2293 /* first vsi is always the LAN vsi */
2294 vsi = pf->vsi[vf->lan_vsi_idx];
2295 if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
2296 dev_err(&pf->pdev->dev, "Uninitialized VF %d\n", vf_id);
2303 memcpy(&ivi->mac, vf->default_lan_addr.addr, ETH_ALEN);
2305 ivi->max_tx_rate = vf->tx_rate;
2306 ivi->min_tx_rate = 0;
2307 ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
2308 ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
2309 I40E_VLAN_PRIORITY_SHIFT;
2310 if (vf->link_forced == false)
2311 ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
2312 else if (vf->link_up == true)
2313 ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
2315 ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
2316 ivi->spoofchk = vf->spoofchk;
2324 * i40e_ndo_set_vf_link_state
2325 * @netdev: network interface device structure
2326 * @vf_id: VF identifier
2327 * @link: required link state
2329 * Set the link state of a specified VF, regardless of physical link state
2331 int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
2333 struct i40e_netdev_priv *np = netdev_priv(netdev);
2334 struct i40e_pf *pf = np->vsi->back;
2335 struct i40e_virtchnl_pf_event pfe;
2336 struct i40e_hw *hw = &pf->hw;
2341 /* validate the request */
2342 if (vf_id >= pf->num_alloc_vfs) {
2343 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2348 vf = &pf->vf[vf_id];
2349 abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
2351 pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
2352 pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
2355 case IFLA_VF_LINK_STATE_AUTO:
2356 vf->link_forced = false;
2357 pfe.event_data.link_event.link_status =
2358 pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
2359 pfe.event_data.link_event.link_speed =
2360 pf->hw.phy.link_info.link_speed;
2362 case IFLA_VF_LINK_STATE_ENABLE:
2363 vf->link_forced = true;
2365 pfe.event_data.link_event.link_status = true;
2366 pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
2368 case IFLA_VF_LINK_STATE_DISABLE:
2369 vf->link_forced = true;
2370 vf->link_up = false;
2371 pfe.event_data.link_event.link_status = false;
2372 pfe.event_data.link_event.link_speed = 0;
2378 /* Notify the VF of its new link state */
2379 i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
2380 0, (u8 *)&pfe, sizeof(pfe), NULL);
2387 * i40e_ndo_set_vf_spoofchk
2388 * @netdev: network interface device structure
2389 * @vf_id: VF identifier
2390 * @enable: flag to enable or disable feature
2392 * Enable or disable VF spoof checking
2394 int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
2396 struct i40e_netdev_priv *np = netdev_priv(netdev);
2397 struct i40e_vsi *vsi = np->vsi;
2398 struct i40e_pf *pf = vsi->back;
2399 struct i40e_vsi_context ctxt;
2400 struct i40e_hw *hw = &pf->hw;
2404 /* validate the request */
2405 if (vf_id >= pf->num_alloc_vfs) {
2406 dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
2411 vf = &(pf->vf[vf_id]);
2413 if (enable == vf->spoofchk)
2416 vf->spoofchk = enable;
2417 memset(&ctxt, 0, sizeof(ctxt));
2418 ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
2419 ctxt.pf_num = pf->hw.pf_id;
2420 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
2422 ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
2423 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
2424 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2426 dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",