4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
43 #include <rte_string_fns.h>
45 #include <rte_ether.h>
46 #include <rte_ethdev.h>
47 #include <rte_memzone.h>
48 #include <rte_malloc.h>
49 #include <rte_memcpy.h>
51 #include "i40e_logs.h"
52 #include "base/i40e_prototype.h"
53 #include "base/i40e_adminq_cmd.h"
54 #include "base/i40e_type.h"
55 #include "i40e_ethdev.h"
56 #include "i40e_rxtx.h"
58 #include "rte_pmd_i40e.h"
60 #define I40E_CFG_CRCSTRIP_DEFAULT 1
63 i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
64 struct i40e_virtchnl_queue_select *qsel,
68 * Bind PF queues with VSI and VF.
71 i40e_pf_vf_queues_mapping(struct i40e_pf_vf *vf)
74 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
75 uint16_t vsi_id = vf->vsi->vsi_id;
76 uint16_t vf_id = vf->vf_idx;
77 uint16_t nb_qps = vf->vsi->nb_qps;
78 uint16_t qbase = vf->vsi->base_queue;
83 * VF should use scatter range queues. So, it needn't
84 * to set QBASE in this register.
86 i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vsi_id),
87 I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
89 /* Set to enable VFLAN_QTABLE[] registers valid */
90 I40E_WRITE_REG(hw, I40E_VPLAN_MAPENA(vf_id),
91 I40E_VPLAN_MAPENA_TXRX_ENA_MASK);
93 /* map PF queues to VF */
94 for (i = 0; i < nb_qps; i++) {
95 val = ((qbase + i) & I40E_VPLAN_QTABLE_QINDEX_MASK);
96 I40E_WRITE_REG(hw, I40E_VPLAN_QTABLE(i, vf_id), val);
99 /* map PF queues to VSI */
100 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF / 2; i++) {
101 if (2 * i > nb_qps - 1)
102 q1 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
106 if (2 * i + 1 > nb_qps - 1)
107 q2 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
109 q2 = qbase + 2 * i + 1;
111 val = (q2 << I40E_VSILAN_QTABLE_QINDEX_1_SHIFT) + q1;
112 i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(i, vsi_id), val);
114 I40E_WRITE_FLUSH(hw);
121 * Proceed VF reset operation.
124 i40e_pf_host_vf_reset(struct i40e_pf_vf *vf, bool do_hw_reset)
129 uint16_t vf_id, abs_vf_id, vf_msix_num;
131 struct i40e_virtchnl_queue_select qsel;
137 hw = I40E_PF_TO_HW(vf->pf);
139 abs_vf_id = vf_id + hw->func_caps.vf_base_id;
141 /* Notify VF that we are in VFR progress */
142 I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), I40E_PF_VFR_INPROGRESS);
145 * If require a SW VF reset, a VFLR interrupt will be generated,
146 * this function will be called again. To avoid it,
147 * disable interrupt first.
150 vf->state = I40E_VF_INRESET;
151 val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
152 val |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
153 I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
154 I40E_WRITE_FLUSH(hw);
157 #define VFRESET_MAX_WAIT_CNT 100
158 /* Wait until VF reset is done */
159 for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
161 val = I40E_READ_REG(hw, I40E_VPGEN_VFRSTAT(vf_id));
162 if (val & I40E_VPGEN_VFRSTAT_VFRD_MASK)
166 if (i >= VFRESET_MAX_WAIT_CNT) {
167 PMD_DRV_LOG(ERR, "VF reset timeout");
171 /* This is not first time to do reset, do cleanup job first */
174 memset(&qsel, 0, sizeof(qsel));
175 for (i = 0; i < vf->vsi->nb_qps; i++)
176 qsel.rx_queues |= 1 << i;
177 qsel.tx_queues = qsel.rx_queues;
178 ret = i40e_pf_host_switch_queues(vf, &qsel, false);
179 if (ret != I40E_SUCCESS) {
180 PMD_DRV_LOG(ERR, "Disable VF queues failed");
184 /* Disable VF interrupt setting */
185 vf_msix_num = hw->func_caps.num_msix_vectors_vf;
186 for (i = 0; i < vf_msix_num; i++) {
188 val = I40E_VFINT_DYN_CTL0(vf_id);
190 val = I40E_VFINT_DYN_CTLN(((vf_msix_num - 1) *
192 I40E_WRITE_REG(hw, val, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
194 I40E_WRITE_FLUSH(hw);
197 ret = i40e_vsi_release(vf->vsi);
198 if (ret != I40E_SUCCESS) {
199 PMD_DRV_LOG(ERR, "Release VSI failed");
204 #define I40E_VF_PCI_ADDR 0xAA
205 #define I40E_VF_PEND_MASK 0x20
206 /* Check the pending transactions of this VF */
207 /* Use absolute VF id, refer to datasheet for details */
208 I40E_WRITE_REG(hw, I40E_PF_PCI_CIAA, I40E_VF_PCI_ADDR |
209 (abs_vf_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
210 for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
212 val = I40E_READ_REG(hw, I40E_PF_PCI_CIAD);
213 if ((val & I40E_VF_PEND_MASK) == 0)
217 if (i >= VFRESET_MAX_WAIT_CNT) {
218 PMD_DRV_LOG(ERR, "Wait VF PCI transaction end timeout");
222 /* Reset done, Set COMPLETE flag and clear reset bit */
223 I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), I40E_PF_VFR_COMPLETED);
224 val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
225 val &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
226 I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
228 I40E_WRITE_FLUSH(hw);
230 /* Allocate resource again */
231 if (pf->floating_veb && pf->floating_veb_list[vf_id]) {
232 vf->vsi = i40e_vsi_setup(vf->pf, I40E_VSI_SRIOV,
235 vf->vsi = i40e_vsi_setup(vf->pf, I40E_VSI_SRIOV,
236 vf->pf->main_vsi, vf->vf_idx);
239 if (vf->vsi == NULL) {
240 PMD_DRV_LOG(ERR, "Add vsi failed");
244 ret = i40e_pf_vf_queues_mapping(vf);
245 if (ret != I40E_SUCCESS) {
246 PMD_DRV_LOG(ERR, "queue mapping error");
247 i40e_vsi_release(vf->vsi);
255 i40e_pf_host_send_msg_to_vf(struct i40e_pf_vf *vf,
261 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
262 uint16_t abs_vf_id = hw->func_caps.vf_base_id + vf->vf_idx;
265 ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, opcode, retval,
268 PMD_INIT_LOG(ERR, "Fail to send message to VF, err %u",
269 hw->aq.asq_last_status);
276 i40e_pf_host_process_cmd_version(struct i40e_pf_vf *vf, bool b_op)
278 struct i40e_virtchnl_version_info info;
280 info.major = I40E_DPDK_VERSION_MAJOR;
281 info.minor = I40E_DPDK_VERSION_MINOR;
284 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
289 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
296 i40e_pf_host_process_cmd_reset_vf(struct i40e_pf_vf *vf)
298 i40e_pf_host_vf_reset(vf, 1);
300 /* No feedback will be sent to VF for VFLR */
305 i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf, bool b_op)
307 struct i40e_virtchnl_vf_resource *vf_res = NULL;
308 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
310 int ret = I40E_SUCCESS;
313 i40e_pf_host_send_msg_to_vf(vf,
314 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
315 I40E_NOT_SUPPORTED, NULL, 0);
319 /* only have 1 VSI by default */
320 len = sizeof(struct i40e_virtchnl_vf_resource) +
321 I40E_DEFAULT_VF_VSI_NUM *
322 sizeof(struct i40e_virtchnl_vsi_resource);
324 vf_res = rte_zmalloc("i40e_vf_res", len, 0);
325 if (vf_res == NULL) {
326 PMD_DRV_LOG(ERR, "failed to allocate mem");
327 ret = I40E_ERR_NO_MEMORY;
333 vf_res->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
334 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
335 vf_res->max_vectors = hw->func_caps.num_msix_vectors_vf;
336 vf_res->num_queue_pairs = vf->vsi->nb_qps;
337 vf_res->num_vsis = I40E_DEFAULT_VF_VSI_NUM;
339 /* Change below setting if PF host can support more VSIs for VF */
340 vf_res->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
341 /* As assume Vf only has single VSI now, always return 0 */
342 vf_res->vsi_res[0].vsi_id = 0;
343 vf_res->vsi_res[0].num_queue_pairs = vf->vsi->nb_qps;
344 ether_addr_copy(&vf->mac_addr,
345 (struct ether_addr *)vf_res->vsi_res[0].default_mac_addr);
348 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
349 ret, (uint8_t *)vf_res, len);
356 i40e_pf_host_hmc_config_rxq(struct i40e_hw *hw,
357 struct i40e_pf_vf *vf,
358 struct i40e_virtchnl_rxq_info *rxq,
361 int err = I40E_SUCCESS;
362 struct i40e_hmc_obj_rxq rx_ctx;
363 uint16_t abs_queue_id = vf->vsi->base_queue + rxq->queue_id;
365 /* Clear the context structure first */
366 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
367 rx_ctx.dbuff = rxq->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
368 rx_ctx.hbuff = rxq->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
369 rx_ctx.base = rxq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
370 rx_ctx.qlen = rxq->ring_len;
371 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
375 if (rxq->splithdr_enabled) {
376 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
377 rx_ctx.dtype = i40e_header_split_enabled;
379 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
380 rx_ctx.dtype = i40e_header_split_none;
382 rx_ctx.rxmax = rxq->max_pkt_size;
383 rx_ctx.tphrdesc_ena = 1;
384 rx_ctx.tphwdesc_ena = 1;
385 rx_ctx.tphdata_ena = 1;
386 rx_ctx.tphhead_ena = 1;
387 rx_ctx.lrxqthresh = 2;
388 rx_ctx.crcstrip = crcstrip;
392 err = i40e_clear_lan_rx_queue_context(hw, abs_queue_id);
393 if (err != I40E_SUCCESS)
395 err = i40e_set_lan_rx_queue_context(hw, abs_queue_id, &rx_ctx);
401 i40e_pf_host_hmc_config_txq(struct i40e_hw *hw,
402 struct i40e_pf_vf *vf,
403 struct i40e_virtchnl_txq_info *txq)
405 int err = I40E_SUCCESS;
406 struct i40e_hmc_obj_txq tx_ctx;
408 uint16_t abs_queue_id = vf->vsi->base_queue + txq->queue_id;
411 /* clear the context structure first */
412 memset(&tx_ctx, 0, sizeof(tx_ctx));
413 tx_ctx.new_context = 1;
414 tx_ctx.base = txq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
415 tx_ctx.qlen = txq->ring_len;
416 tx_ctx.rdylist = rte_le_to_cpu_16(vf->vsi->info.qs_handle[0]);
417 err = i40e_clear_lan_tx_queue_context(hw, abs_queue_id);
418 if (err != I40E_SUCCESS)
421 err = i40e_set_lan_tx_queue_context(hw, abs_queue_id, &tx_ctx);
422 if (err != I40E_SUCCESS)
425 /* bind queue with VF function, since TX/QX will appear in pair,
426 * so only has QTX_CTL to set.
428 qtx_ctl = (I40E_QTX_CTL_VF_QUEUE << I40E_QTX_CTL_PFVF_Q_SHIFT) |
429 ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
430 I40E_QTX_CTL_PF_INDX_MASK) |
431 (((vf->vf_idx + hw->func_caps.vf_base_id) <<
432 I40E_QTX_CTL_VFVM_INDX_SHIFT) &
433 I40E_QTX_CTL_VFVM_INDX_MASK);
434 I40E_WRITE_REG(hw, I40E_QTX_CTL(abs_queue_id), qtx_ctl);
435 I40E_WRITE_FLUSH(hw);
441 i40e_pf_host_process_cmd_config_vsi_queues(struct i40e_pf_vf *vf,
446 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
447 struct i40e_vsi *vsi = vf->vsi;
448 struct i40e_virtchnl_vsi_queue_config_info *vc_vqci =
449 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
450 struct i40e_virtchnl_queue_pair_info *vc_qpi;
451 int i, ret = I40E_SUCCESS;
454 i40e_pf_host_send_msg_to_vf(vf,
455 I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
456 I40E_NOT_SUPPORTED, NULL, 0);
460 if (!msg || vc_vqci->num_queue_pairs > vsi->nb_qps ||
461 vc_vqci->num_queue_pairs > I40E_MAX_VSI_QP ||
462 msglen < I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqci,
463 vc_vqci->num_queue_pairs)) {
464 PMD_DRV_LOG(ERR, "vsi_queue_config_info argument wrong\n");
465 ret = I40E_ERR_PARAM;
469 vc_qpi = vc_vqci->qpair;
470 for (i = 0; i < vc_vqci->num_queue_pairs; i++) {
471 if (vc_qpi[i].rxq.queue_id > vsi->nb_qps - 1 ||
472 vc_qpi[i].txq.queue_id > vsi->nb_qps - 1) {
473 ret = I40E_ERR_PARAM;
478 * Apply VF RX queue setting to HMC.
479 * If the opcode is I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
480 * then the extra information of
481 * 'struct i40e_virtchnl_queue_pair_extra_info' is needed,
482 * otherwise set the last parameter to NULL.
484 if (i40e_pf_host_hmc_config_rxq(hw, vf, &vc_qpi[i].rxq,
485 I40E_CFG_CRCSTRIP_DEFAULT) != I40E_SUCCESS) {
486 PMD_DRV_LOG(ERR, "Configure RX queue HMC failed");
487 ret = I40E_ERR_PARAM;
491 /* Apply VF TX queue setting to HMC */
492 if (i40e_pf_host_hmc_config_txq(hw, vf,
493 &vc_qpi[i].txq) != I40E_SUCCESS) {
494 PMD_DRV_LOG(ERR, "Configure TX queue HMC failed");
495 ret = I40E_ERR_PARAM;
501 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
508 i40e_pf_host_process_cmd_config_vsi_queues_ext(struct i40e_pf_vf *vf,
513 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
514 struct i40e_vsi *vsi = vf->vsi;
515 struct i40e_virtchnl_vsi_queue_config_ext_info *vc_vqcei =
516 (struct i40e_virtchnl_vsi_queue_config_ext_info *)msg;
517 struct i40e_virtchnl_queue_pair_ext_info *vc_qpei;
518 int i, ret = I40E_SUCCESS;
521 i40e_pf_host_send_msg_to_vf(
523 I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
524 I40E_NOT_SUPPORTED, NULL, 0);
528 if (!msg || vc_vqcei->num_queue_pairs > vsi->nb_qps ||
529 vc_vqcei->num_queue_pairs > I40E_MAX_VSI_QP ||
530 msglen < I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqcei,
531 vc_vqcei->num_queue_pairs)) {
532 PMD_DRV_LOG(ERR, "vsi_queue_config_ext_info argument wrong\n");
533 ret = I40E_ERR_PARAM;
537 vc_qpei = vc_vqcei->qpair;
538 for (i = 0; i < vc_vqcei->num_queue_pairs; i++) {
539 if (vc_qpei[i].rxq.queue_id > vsi->nb_qps - 1 ||
540 vc_qpei[i].txq.queue_id > vsi->nb_qps - 1) {
541 ret = I40E_ERR_PARAM;
545 * Apply VF RX queue setting to HMC.
546 * If the opcode is I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
547 * then the extra information of
548 * 'struct i40e_virtchnl_queue_pair_ext_info' is needed,
549 * otherwise set the last parameter to NULL.
551 if (i40e_pf_host_hmc_config_rxq(hw, vf, &vc_qpei[i].rxq,
552 vc_qpei[i].rxq_ext.crcstrip) != I40E_SUCCESS) {
553 PMD_DRV_LOG(ERR, "Configure RX queue HMC failed");
554 ret = I40E_ERR_PARAM;
558 /* Apply VF TX queue setting to HMC */
559 if (i40e_pf_host_hmc_config_txq(hw, vf, &vc_qpei[i].txq) !=
561 PMD_DRV_LOG(ERR, "Configure TX queue HMC failed");
562 ret = I40E_ERR_PARAM;
568 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
575 i40e_pf_host_process_cmd_config_irq_map(struct i40e_pf_vf *vf,
576 uint8_t *msg, uint16_t msglen,
579 int ret = I40E_SUCCESS;
580 struct i40e_virtchnl_irq_map_info *irqmap =
581 (struct i40e_virtchnl_irq_map_info *)msg;
584 i40e_pf_host_send_msg_to_vf(
586 I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
587 I40E_NOT_SUPPORTED, NULL, 0);
591 if (msg == NULL || msglen < sizeof(struct i40e_virtchnl_irq_map_info)) {
592 PMD_DRV_LOG(ERR, "buffer too short");
593 ret = I40E_ERR_PARAM;
597 /* Assume VF only have 1 vector to bind all queues */
598 if (irqmap->num_vectors != 1) {
599 PMD_DRV_LOG(ERR, "DKDK host only support 1 vector");
600 ret = I40E_ERR_PARAM;
604 /* This MSIX intr store the intr in VF range */
605 vf->vsi->msix_intr = irqmap->vecmap[0].vector_id;
606 vf->vsi->nb_msix = irqmap->num_vectors;
607 vf->vsi->nb_used_qps = vf->vsi->nb_qps;
609 /* Don't care how the TX/RX queue mapping with this vector.
610 * Link all VF RX queues together. Only did mapping work.
611 * VF can disable/enable the intr by itself.
613 i40e_vsi_queues_bind_intr(vf->vsi);
615 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
622 i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
623 struct i40e_virtchnl_queue_select *qsel,
626 int ret = I40E_SUCCESS;
628 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
629 uint16_t baseq = vf->vsi->base_queue;
631 if (qsel->rx_queues + qsel->tx_queues == 0)
632 return I40E_ERR_PARAM;
634 /* always enable RX first and disable last */
635 /* Enable RX if it's enable */
637 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
638 if (qsel->rx_queues & (1 << i)) {
639 ret = i40e_switch_rx_queue(hw, baseq + i, on);
640 if (ret != I40E_SUCCESS)
645 /* Enable/Disable TX */
646 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
647 if (qsel->tx_queues & (1 << i)) {
648 ret = i40e_switch_tx_queue(hw, baseq + i, on);
649 if (ret != I40E_SUCCESS)
653 /* disable RX last if it's disable */
656 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
657 if (qsel->rx_queues & (1 << i)) {
658 ret = i40e_switch_rx_queue(hw, baseq + i, on);
659 if (ret != I40E_SUCCESS)
668 i40e_pf_host_process_cmd_enable_queues(struct i40e_pf_vf *vf,
672 int ret = I40E_SUCCESS;
673 struct i40e_virtchnl_queue_select *q_sel =
674 (struct i40e_virtchnl_queue_select *)msg;
676 if (msg == NULL || msglen != sizeof(*q_sel)) {
677 ret = I40E_ERR_PARAM;
680 ret = i40e_pf_host_switch_queues(vf, q_sel, true);
683 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
690 i40e_pf_host_process_cmd_disable_queues(struct i40e_pf_vf *vf,
695 int ret = I40E_SUCCESS;
696 struct i40e_virtchnl_queue_select *q_sel =
697 (struct i40e_virtchnl_queue_select *)msg;
700 i40e_pf_host_send_msg_to_vf(
702 I40E_VIRTCHNL_OP_DISABLE_QUEUES,
703 I40E_NOT_SUPPORTED, NULL, 0);
707 if (msg == NULL || msglen != sizeof(*q_sel)) {
708 ret = I40E_ERR_PARAM;
711 ret = i40e_pf_host_switch_queues(vf, q_sel, false);
714 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
722 i40e_pf_host_process_cmd_add_ether_address(struct i40e_pf_vf *vf,
727 int ret = I40E_SUCCESS;
728 struct i40e_virtchnl_ether_addr_list *addr_list =
729 (struct i40e_virtchnl_ether_addr_list *)msg;
730 struct i40e_mac_filter_info filter;
732 struct ether_addr *mac;
735 i40e_pf_host_send_msg_to_vf(
737 I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
738 I40E_NOT_SUPPORTED, NULL, 0);
742 memset(&filter, 0 , sizeof(struct i40e_mac_filter_info));
744 if (msg == NULL || msglen <= sizeof(*addr_list)) {
745 PMD_DRV_LOG(ERR, "add_ether_address argument too short");
746 ret = I40E_ERR_PARAM;
750 for (i = 0; i < addr_list->num_elements; i++) {
751 mac = (struct ether_addr *)(addr_list->list[i].addr);
752 (void)rte_memcpy(&filter.mac_addr, mac, ETHER_ADDR_LEN);
753 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
754 if(!is_valid_assigned_ether_addr(mac) ||
755 i40e_vsi_add_mac(vf->vsi, &filter)) {
756 ret = I40E_ERR_INVALID_MAC_ADDR;
762 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
769 i40e_pf_host_process_cmd_del_ether_address(struct i40e_pf_vf *vf,
774 int ret = I40E_SUCCESS;
775 struct i40e_virtchnl_ether_addr_list *addr_list =
776 (struct i40e_virtchnl_ether_addr_list *)msg;
778 struct ether_addr *mac;
781 i40e_pf_host_send_msg_to_vf(
783 I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
784 I40E_NOT_SUPPORTED, NULL, 0);
788 if (msg == NULL || msglen <= sizeof(*addr_list)) {
789 PMD_DRV_LOG(ERR, "delete_ether_address argument too short");
790 ret = I40E_ERR_PARAM;
794 for (i = 0; i < addr_list->num_elements; i++) {
795 mac = (struct ether_addr *)(addr_list->list[i].addr);
796 if(!is_valid_assigned_ether_addr(mac) ||
797 i40e_vsi_delete_mac(vf->vsi, mac)) {
798 ret = I40E_ERR_INVALID_MAC_ADDR;
804 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
811 i40e_pf_host_process_cmd_add_vlan(struct i40e_pf_vf *vf,
812 uint8_t *msg, uint16_t msglen,
815 int ret = I40E_SUCCESS;
816 struct i40e_virtchnl_vlan_filter_list *vlan_filter_list =
817 (struct i40e_virtchnl_vlan_filter_list *)msg;
822 i40e_pf_host_send_msg_to_vf(
824 I40E_VIRTCHNL_OP_ADD_VLAN,
825 I40E_NOT_SUPPORTED, NULL, 0);
829 if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
830 PMD_DRV_LOG(ERR, "add_vlan argument too short");
831 ret = I40E_ERR_PARAM;
835 vid = vlan_filter_list->vlan_id;
837 for (i = 0; i < vlan_filter_list->num_elements; i++) {
838 ret = i40e_vsi_add_vlan(vf->vsi, vid[i]);
839 if(ret != I40E_SUCCESS)
844 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN,
851 i40e_pf_host_process_cmd_del_vlan(struct i40e_pf_vf *vf,
856 int ret = I40E_SUCCESS;
857 struct i40e_virtchnl_vlan_filter_list *vlan_filter_list =
858 (struct i40e_virtchnl_vlan_filter_list *)msg;
863 i40e_pf_host_send_msg_to_vf(
865 I40E_VIRTCHNL_OP_DEL_VLAN,
866 I40E_NOT_SUPPORTED, NULL, 0);
870 if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
871 PMD_DRV_LOG(ERR, "delete_vlan argument too short");
872 ret = I40E_ERR_PARAM;
876 vid = vlan_filter_list->vlan_id;
877 for (i = 0; i < vlan_filter_list->num_elements; i++) {
878 ret = i40e_vsi_delete_vlan(vf->vsi, vid[i]);
879 if(ret != I40E_SUCCESS)
884 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN,
891 i40e_pf_host_process_cmd_config_promisc_mode(
892 struct i40e_pf_vf *vf,
897 int ret = I40E_SUCCESS;
898 struct i40e_virtchnl_promisc_info *promisc =
899 (struct i40e_virtchnl_promisc_info *)msg;
900 struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
901 bool unicast = FALSE, multicast = FALSE;
904 i40e_pf_host_send_msg_to_vf(
906 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
907 I40E_NOT_SUPPORTED, NULL, 0);
911 if (msg == NULL || msglen != sizeof(*promisc)) {
912 ret = I40E_ERR_PARAM;
916 if (promisc->flags & I40E_FLAG_VF_UNICAST_PROMISC)
918 ret = i40e_aq_set_vsi_unicast_promiscuous(hw,
919 vf->vsi->seid, unicast, NULL, true);
920 if (ret != I40E_SUCCESS)
923 if (promisc->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
925 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vf->vsi->seid,
929 i40e_pf_host_send_msg_to_vf(vf,
930 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, ret, NULL, 0);
936 i40e_pf_host_process_cmd_get_stats(struct i40e_pf_vf *vf, bool b_op)
938 i40e_update_vsi_stats(vf->vsi);
941 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS,
943 (uint8_t *)&vf->vsi->eth_stats,
944 sizeof(vf->vsi->eth_stats));
946 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS,
948 (uint8_t *)&vf->vsi->eth_stats,
949 sizeof(vf->vsi->eth_stats));
955 i40e_pf_host_process_cmd_cfg_vlan_offload(
956 struct i40e_pf_vf *vf,
961 int ret = I40E_SUCCESS;
962 struct i40e_virtchnl_vlan_offload_info *offload =
963 (struct i40e_virtchnl_vlan_offload_info *)msg;
966 i40e_pf_host_send_msg_to_vf(
968 I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD,
969 I40E_NOT_SUPPORTED, NULL, 0);
973 if (msg == NULL || msglen != sizeof(*offload)) {
974 ret = I40E_ERR_PARAM;
978 ret = i40e_vsi_config_vlan_stripping(vf->vsi,
979 !!offload->enable_vlan_strip);
981 PMD_DRV_LOG(ERR, "Failed to configure vlan stripping");
984 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD,
991 i40e_pf_host_process_cmd_cfg_pvid(struct i40e_pf_vf *vf,
996 int ret = I40E_SUCCESS;
997 struct i40e_virtchnl_pvid_info *tpid_info =
998 (struct i40e_virtchnl_pvid_info *)msg;
1001 i40e_pf_host_send_msg_to_vf(
1003 I40E_VIRTCHNL_OP_CFG_VLAN_PVID,
1004 I40E_NOT_SUPPORTED, NULL, 0);
1008 if (msg == NULL || msglen != sizeof(*tpid_info)) {
1009 ret = I40E_ERR_PARAM;
1013 ret = i40e_vsi_vlan_pvid_set(vf->vsi, &tpid_info->info);
1016 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CFG_VLAN_PVID,
1023 i40e_notify_vf_link_status(struct rte_eth_dev *dev, struct i40e_pf_vf *vf)
1025 struct i40e_virtchnl_pf_event event;
1027 event.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
1028 event.event_data.link_event.link_status =
1029 dev->data->dev_link.link_status;
1030 event.event_data.link_event.link_speed =
1031 (enum i40e_aq_link_speed)dev->data->dev_link.link_speed;
1032 i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_EVENT,
1033 I40E_SUCCESS, (uint8_t *)&event, sizeof(event));
1037 i40e_pf_host_handle_vf_msg(struct rte_eth_dev *dev,
1038 uint16_t abs_vf_id, uint32_t opcode,
1039 __rte_unused uint32_t retval,
1043 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1044 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1045 struct i40e_pf_vf *vf;
1046 /* AdminQ will pass absolute VF id, transfer to internal vf id */
1047 uint16_t vf_id = abs_vf_id - hw->func_caps.vf_base_id;
1048 struct rte_pmd_i40e_mb_event_param cb_param;
1051 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
1052 PMD_DRV_LOG(ERR, "invalid argument");
1056 vf = &pf->vfs[vf_id];
1058 PMD_DRV_LOG(ERR, "NO VSI associated with VF found");
1059 i40e_pf_host_send_msg_to_vf(vf, opcode,
1060 I40E_ERR_NO_AVAILABLE_VSI, NULL, 0);
1065 * initialise structure to send to user application
1066 * will return response from user in retval field
1068 cb_param.retval = RTE_PMD_I40E_MB_EVENT_PROCEED;
1069 cb_param.vfid = vf_id;
1070 cb_param.msg_type = opcode;
1071 cb_param.msg = (void *)msg;
1072 cb_param.msglen = msglen;
1075 * Ask user application if we're allowed to perform those functions.
1076 * If we get cb_param.retval == RTE_PMD_I40E_MB_EVENT_PROCEED,
1077 * then business as usual.
1078 * If RTE_PMD_I40E_MB_EVENT_NOOP_ACK or RTE_PMD_I40E_MB_EVENT_NOOP_NACK,
1079 * do nothing and send not_supported to VF. As PF must send a response
1080 * to VF and ACK/NACK is not defined.
1082 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX, &cb_param);
1083 if (cb_param.retval != RTE_PMD_I40E_MB_EVENT_PROCEED) {
1084 PMD_DRV_LOG(WARNING, "VF to PF message(%d) is not permitted!",
1090 case I40E_VIRTCHNL_OP_VERSION :
1091 PMD_DRV_LOG(INFO, "OP_VERSION received");
1092 i40e_pf_host_process_cmd_version(vf, b_op);
1094 case I40E_VIRTCHNL_OP_RESET_VF :
1095 PMD_DRV_LOG(INFO, "OP_RESET_VF received");
1096 i40e_pf_host_process_cmd_reset_vf(vf);
1098 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
1099 PMD_DRV_LOG(INFO, "OP_GET_VF_RESOURCES received");
1100 i40e_pf_host_process_cmd_get_vf_resource(vf, b_op);
1102 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
1103 PMD_DRV_LOG(INFO, "OP_CONFIG_VSI_QUEUES received");
1104 i40e_pf_host_process_cmd_config_vsi_queues(vf, msg,
1107 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT:
1108 PMD_DRV_LOG(INFO, "OP_CONFIG_VSI_QUEUES_EXT received");
1109 i40e_pf_host_process_cmd_config_vsi_queues_ext(vf, msg,
1112 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
1113 PMD_DRV_LOG(INFO, "OP_CONFIG_IRQ_MAP received");
1114 i40e_pf_host_process_cmd_config_irq_map(vf, msg, msglen, b_op);
1116 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
1117 PMD_DRV_LOG(INFO, "OP_ENABLE_QUEUES received");
1119 i40e_pf_host_process_cmd_enable_queues(vf, msg, msglen);
1120 i40e_notify_vf_link_status(dev, vf);
1122 i40e_pf_host_send_msg_to_vf(
1123 vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
1124 I40E_NOT_SUPPORTED, NULL, 0);
1127 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
1128 PMD_DRV_LOG(INFO, "OP_DISABLE_QUEUE received");
1129 i40e_pf_host_process_cmd_disable_queues(vf, msg, msglen, b_op);
1131 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
1132 PMD_DRV_LOG(INFO, "OP_ADD_ETHER_ADDRESS received");
1133 i40e_pf_host_process_cmd_add_ether_address(vf, msg,
1136 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
1137 PMD_DRV_LOG(INFO, "OP_DEL_ETHER_ADDRESS received");
1138 i40e_pf_host_process_cmd_del_ether_address(vf, msg,
1141 case I40E_VIRTCHNL_OP_ADD_VLAN:
1142 PMD_DRV_LOG(INFO, "OP_ADD_VLAN received");
1143 i40e_pf_host_process_cmd_add_vlan(vf, msg, msglen, b_op);
1145 case I40E_VIRTCHNL_OP_DEL_VLAN:
1146 PMD_DRV_LOG(INFO, "OP_DEL_VLAN received");
1147 i40e_pf_host_process_cmd_del_vlan(vf, msg, msglen, b_op);
1149 case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
1150 PMD_DRV_LOG(INFO, "OP_CONFIG_PROMISCUOUS_MODE received");
1151 i40e_pf_host_process_cmd_config_promisc_mode(vf, msg,
1154 case I40E_VIRTCHNL_OP_GET_STATS:
1155 PMD_DRV_LOG(INFO, "OP_GET_STATS received");
1156 i40e_pf_host_process_cmd_get_stats(vf, b_op);
1158 case I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD:
1159 PMD_DRV_LOG(INFO, "OP_CFG_VLAN_OFFLOAD received");
1160 i40e_pf_host_process_cmd_cfg_vlan_offload(vf, msg,
1163 case I40E_VIRTCHNL_OP_CFG_VLAN_PVID:
1164 PMD_DRV_LOG(INFO, "OP_CFG_VLAN_PVID received");
1165 i40e_pf_host_process_cmd_cfg_pvid(vf, msg, msglen, b_op);
1167 /* Don't add command supported below, which will
1168 * return an error code.
1171 PMD_DRV_LOG(ERR, "%u received, not supported", opcode);
1172 i40e_pf_host_send_msg_to_vf(vf, opcode, I40E_ERR_PARAM,
1179 i40e_pf_host_init(struct rte_eth_dev *dev)
1181 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1182 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1186 PMD_INIT_FUNC_TRACE();
1189 * return if SRIOV not enabled, VF number not configured or
1190 * no queue assigned.
1192 if(!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 || pf->vf_nb_qps == 0)
1193 return I40E_SUCCESS;
1195 /* Allocate memory to store VF structure */
1196 pf->vfs = rte_zmalloc("i40e_pf_vf",sizeof(*pf->vfs) * pf->vf_num, 0);
1200 /* Disable irq0 for VFR event */
1201 i40e_pf_disable_irq0(hw);
1203 /* Disable VF link status interrupt */
1204 val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1205 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1206 I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1207 I40E_WRITE_FLUSH(hw);
1209 for (i = 0; i < pf->vf_num; i++) {
1211 pf->vfs[i].state = I40E_VF_INACTIVE;
1212 pf->vfs[i].vf_idx = i;
1213 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
1214 if (ret != I40E_SUCCESS)
1216 eth_random_addr(pf->vfs[i].mac_addr.addr_bytes);
1220 i40e_pf_enable_irq0(hw);
1222 return I40E_SUCCESS;
1226 i40e_pf_enable_irq0(hw);
1232 i40e_pf_host_uninit(struct rte_eth_dev *dev)
1234 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1235 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1238 PMD_INIT_FUNC_TRACE();
1241 * return if SRIOV not enabled, VF number not configured or
1242 * no queue assigned.
1244 if ((!hw->func_caps.sr_iov_1_1) ||
1245 (pf->vf_num == 0) ||
1246 (pf->vf_nb_qps == 0))
1247 return I40E_SUCCESS;
1249 /* free memory to store VF structure */
1253 /* Disable irq0 for VFR event */
1254 i40e_pf_disable_irq0(hw);
1256 /* Disable VF link status interrupt */
1257 val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1258 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1259 I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1260 I40E_WRITE_FLUSH(hw);
1262 return I40E_SUCCESS;