i40e: support Rx interrupt
[dpdk.git] / drivers / net / i40e / i40e_pf.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <sys/queue.h>
35 #include <stdio.h>
36 #include <errno.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include <stdarg.h>
41 #include <inttypes.h>
42
43 #include <rte_string_fns.h>
44 #include <rte_pci.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>
50
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"
57 #include "i40e_pf.h"
58
59 #define I40E_CFG_CRCSTRIP_DEFAULT 1
60
61 static int
62 i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
63                            struct i40e_virtchnl_queue_select *qsel,
64                            bool on);
65
66 /**
67  * Bind PF queues with VSI and VF.
68  **/
69 static int
70 i40e_pf_vf_queues_mapping(struct i40e_pf_vf *vf)
71 {
72         int i;
73         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
74         uint16_t vsi_id = vf->vsi->vsi_id;
75         uint16_t vf_id  = vf->vf_idx;
76         uint16_t nb_qps = vf->vsi->nb_qps;
77         uint16_t qbase  = vf->vsi->base_queue;
78         uint16_t q1, q2;
79         uint32_t val;
80
81         /*
82          * VF should use scatter range queues. So, it needn't
83          * to set QBASE in this register.
84          */
85         I40E_WRITE_REG(hw, I40E_VSILAN_QBASE(vsi_id),
86              I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
87
88         /* Set to enable VFLAN_QTABLE[] registers valid */
89         I40E_WRITE_REG(hw, I40E_VPLAN_MAPENA(vf_id),
90                 I40E_VPLAN_MAPENA_TXRX_ENA_MASK);
91
92         /* map PF queues to VF */
93         for (i = 0; i < nb_qps; i++) {
94                 val = ((qbase + i) & I40E_VPLAN_QTABLE_QINDEX_MASK);
95                 I40E_WRITE_REG(hw, I40E_VPLAN_QTABLE(i, vf_id), val);
96         }
97
98         /* map PF queues to VSI */
99         for (i = 0; i < I40E_MAX_QP_NUM_PER_VF / 2; i++) {
100                 if (2 * i > nb_qps - 1)
101                         q1 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
102                 else
103                         q1 = qbase + 2 * i;
104
105                 if (2 * i + 1 > nb_qps - 1)
106                         q2 = I40E_VSILAN_QTABLE_QINDEX_0_MASK;
107                 else
108                         q2 = qbase + 2 * i + 1;
109
110                 val = (q2 << I40E_VSILAN_QTABLE_QINDEX_1_SHIFT) + q1;
111                 I40E_WRITE_REG(hw, I40E_VSILAN_QTABLE(i, vsi_id), val);
112         }
113         I40E_WRITE_FLUSH(hw);
114
115         return I40E_SUCCESS;
116 }
117
118
119 /**
120  * Proceed VF reset operation.
121  */
122 int
123 i40e_pf_host_vf_reset(struct i40e_pf_vf *vf, bool do_hw_reset)
124 {
125         uint32_t val, i;
126         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
127         uint16_t vf_id, abs_vf_id, vf_msix_num;
128         int ret;
129         struct i40e_virtchnl_queue_select qsel;
130
131         if (vf == NULL)
132                 return -EINVAL;
133
134         vf_id = vf->vf_idx;
135         abs_vf_id = vf_id + hw->func_caps.vf_base_id;
136
137         /* Notify VF that we are in VFR progress */
138         I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), I40E_PF_VFR_INPROGRESS);
139
140         /*
141          * If require a SW VF reset, a VFLR interrupt will be generated,
142          * this function will be called again. To avoid it,
143          * disable interrupt first.
144          */
145         if (do_hw_reset) {
146                 vf->state = I40E_VF_INRESET;
147                 val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
148                 val |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
149                 I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
150                 I40E_WRITE_FLUSH(hw);
151         }
152
153 #define VFRESET_MAX_WAIT_CNT 100
154         /* Wait until VF reset is done */
155         for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
156                 rte_delay_us(10);
157                 val = I40E_READ_REG(hw, I40E_VPGEN_VFRSTAT(vf_id));
158                 if (val & I40E_VPGEN_VFRSTAT_VFRD_MASK)
159                         break;
160         }
161
162         if (i >= VFRESET_MAX_WAIT_CNT) {
163                 PMD_DRV_LOG(ERR, "VF reset timeout");
164                 return -ETIMEDOUT;
165         }
166
167         /* This is not first time to do reset, do cleanup job first */
168         if (vf->vsi) {
169                 /* Disable queues */
170                 memset(&qsel, 0, sizeof(qsel));
171                 for (i = 0; i < vf->vsi->nb_qps; i++)
172                         qsel.rx_queues |= 1 << i;
173                 qsel.tx_queues = qsel.rx_queues;
174                 ret = i40e_pf_host_switch_queues(vf, &qsel, false);
175                 if (ret != I40E_SUCCESS) {
176                         PMD_DRV_LOG(ERR, "Disable VF queues failed");
177                         return -EFAULT;
178                 }
179
180                 /* Disable VF interrupt setting */
181                 vf_msix_num = hw->func_caps.num_msix_vectors_vf;
182                 for (i = 0; i < vf_msix_num; i++) {
183                         if (!i)
184                                 val = I40E_VFINT_DYN_CTL0(vf_id);
185                         else
186                                 val = I40E_VFINT_DYN_CTLN(((vf_msix_num - 1) *
187                                                         (vf_id)) + (i - 1));
188                         I40E_WRITE_REG(hw, val, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
189                 }
190                 I40E_WRITE_FLUSH(hw);
191
192                 /* remove VSI */
193                 ret = i40e_vsi_release(vf->vsi);
194                 if (ret != I40E_SUCCESS) {
195                         PMD_DRV_LOG(ERR, "Release VSI failed");
196                         return -EFAULT;
197                 }
198         }
199
200 #define I40E_VF_PCI_ADDR  0xAA
201 #define I40E_VF_PEND_MASK 0x20
202         /* Check the pending transactions of this VF */
203         /* Use absolute VF id, refer to datasheet for details */
204         I40E_WRITE_REG(hw, I40E_PF_PCI_CIAA, I40E_VF_PCI_ADDR |
205                 (abs_vf_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
206         for (i = 0; i < VFRESET_MAX_WAIT_CNT; i++) {
207                 rte_delay_us(1);
208                 val = I40E_READ_REG(hw, I40E_PF_PCI_CIAD);
209                 if ((val & I40E_VF_PEND_MASK) == 0)
210                         break;
211         }
212
213         if (i >= VFRESET_MAX_WAIT_CNT) {
214                 PMD_DRV_LOG(ERR, "Wait VF PCI transaction end timeout");
215                 return -ETIMEDOUT;
216         }
217
218         /* Reset done, Set COMPLETE flag and clear reset bit */
219         I40E_WRITE_REG(hw, I40E_VFGEN_RSTAT1(vf_id), I40E_PF_VFR_COMPLETED);
220         val = I40E_READ_REG(hw, I40E_VPGEN_VFRTRIG(vf_id));
221         val &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
222         I40E_WRITE_REG(hw, I40E_VPGEN_VFRTRIG(vf_id), val);
223         vf->reset_cnt++;
224         I40E_WRITE_FLUSH(hw);
225
226         /* Allocate resource again */
227         vf->vsi = i40e_vsi_setup(vf->pf, I40E_VSI_SRIOV,
228                         vf->pf->main_vsi, vf->vf_idx);
229         if (vf->vsi == NULL) {
230                 PMD_DRV_LOG(ERR, "Add vsi failed");
231                 return -EFAULT;
232         }
233
234         ret = i40e_pf_vf_queues_mapping(vf);
235         if (ret != I40E_SUCCESS) {
236                 PMD_DRV_LOG(ERR, "queue mapping error");
237                 i40e_vsi_release(vf->vsi);
238                 return -EFAULT;
239         }
240
241         return ret;
242 }
243
244 static int
245 i40e_pf_host_send_msg_to_vf(struct i40e_pf_vf *vf,
246                             uint32_t opcode,
247                             uint32_t retval,
248                             uint8_t *msg,
249                             uint16_t msglen)
250 {
251         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
252         uint16_t abs_vf_id = hw->func_caps.vf_base_id + vf->vf_idx;
253         int ret;
254
255         ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, opcode, retval,
256                                                 msg, msglen, NULL);
257         if (ret) {
258                 PMD_INIT_LOG(ERR, "Fail to send message to VF, err %u",
259                              hw->aq.asq_last_status);
260         }
261
262         return ret;
263 }
264
265 static void
266 i40e_pf_host_process_cmd_version(struct i40e_pf_vf *vf)
267 {
268         struct i40e_virtchnl_version_info info;
269
270         info.major = I40E_DPDK_VERSION_MAJOR;
271         info.minor = I40E_DPDK_VERSION_MINOR;
272         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
273                 I40E_SUCCESS, (uint8_t *)&info, sizeof(info));
274 }
275
276 static int
277 i40e_pf_host_process_cmd_reset_vf(struct i40e_pf_vf *vf)
278 {
279         i40e_pf_host_vf_reset(vf, 1);
280
281         /* No feedback will be sent to VF for VFLR */
282         return I40E_SUCCESS;
283 }
284
285 static int
286 i40e_pf_host_process_cmd_get_vf_resource(struct i40e_pf_vf *vf)
287 {
288         struct i40e_virtchnl_vf_resource *vf_res = NULL;
289         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
290         uint32_t len = 0;
291         int ret = I40E_SUCCESS;
292
293         /* only have 1 VSI by default */
294         len =  sizeof(struct i40e_virtchnl_vf_resource) +
295                                 I40E_DEFAULT_VF_VSI_NUM *
296                 sizeof(struct i40e_virtchnl_vsi_resource);
297
298         vf_res = rte_zmalloc("i40e_vf_res", len, 0);
299         if (vf_res == NULL) {
300                 PMD_DRV_LOG(ERR, "failed to allocate mem");
301                 ret = I40E_ERR_NO_MEMORY;
302                 vf_res = NULL;
303                 len = 0;
304                 goto send_msg;
305         }
306
307         vf_res->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
308                                 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
309         vf_res->max_vectors = hw->func_caps.num_msix_vectors_vf;
310         vf_res->num_queue_pairs = vf->vsi->nb_qps;
311         vf_res->num_vsis = I40E_DEFAULT_VF_VSI_NUM;
312
313         /* Change below setting if PF host can support more VSIs for VF */
314         vf_res->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
315         /* As assume Vf only has single VSI now, always return 0 */
316         vf_res->vsi_res[0].vsi_id = 0;
317         vf_res->vsi_res[0].num_queue_pairs = vf->vsi->nb_qps;
318
319 send_msg:
320         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
321                                         ret, (uint8_t *)vf_res, len);
322         rte_free(vf_res);
323
324         return ret;
325 }
326
327 static int
328 i40e_pf_host_hmc_config_rxq(struct i40e_hw *hw,
329                             struct i40e_pf_vf *vf,
330                             struct i40e_virtchnl_rxq_info *rxq,
331                             uint8_t crcstrip)
332 {
333         int err = I40E_SUCCESS;
334         struct i40e_hmc_obj_rxq rx_ctx;
335         uint16_t abs_queue_id = vf->vsi->base_queue + rxq->queue_id;
336
337         /* Clear the context structure first */
338         memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
339         rx_ctx.dbuff = rxq->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
340         rx_ctx.hbuff = rxq->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
341         rx_ctx.base = rxq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
342         rx_ctx.qlen = rxq->ring_len;
343 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
344         rx_ctx.dsize = 1;
345 #endif
346
347         if (rxq->splithdr_enabled) {
348                 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
349                 rx_ctx.dtype = i40e_header_split_enabled;
350         } else {
351                 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
352                 rx_ctx.dtype = i40e_header_split_none;
353         }
354         rx_ctx.rxmax = rxq->max_pkt_size;
355         rx_ctx.tphrdesc_ena = 1;
356         rx_ctx.tphwdesc_ena = 1;
357         rx_ctx.tphdata_ena = 1;
358         rx_ctx.tphhead_ena = 1;
359         rx_ctx.lrxqthresh = 2;
360         rx_ctx.crcstrip = crcstrip;
361         rx_ctx.l2tsel = 1;
362         rx_ctx.prefena = 1;
363
364         err = i40e_clear_lan_rx_queue_context(hw, abs_queue_id);
365         if (err != I40E_SUCCESS)
366                 return err;
367         err = i40e_set_lan_rx_queue_context(hw, abs_queue_id, &rx_ctx);
368
369         return err;
370 }
371
372 static int
373 i40e_pf_host_hmc_config_txq(struct i40e_hw *hw,
374                             struct i40e_pf_vf *vf,
375                             struct i40e_virtchnl_txq_info *txq)
376 {
377         int err = I40E_SUCCESS;
378         struct i40e_hmc_obj_txq tx_ctx;
379         uint32_t qtx_ctl;
380         uint16_t abs_queue_id = vf->vsi->base_queue + txq->queue_id;
381
382
383         /* clear the context structure first */
384         memset(&tx_ctx, 0, sizeof(tx_ctx));
385         tx_ctx.new_context = 1;
386         tx_ctx.base = txq->dma_ring_addr / I40E_QUEUE_BASE_ADDR_UNIT;
387         tx_ctx.qlen = txq->ring_len;
388         tx_ctx.rdylist = rte_le_to_cpu_16(vf->vsi->info.qs_handle[0]);
389         err = i40e_clear_lan_tx_queue_context(hw, abs_queue_id);
390         if (err != I40E_SUCCESS)
391                 return err;
392
393         err = i40e_set_lan_tx_queue_context(hw, abs_queue_id, &tx_ctx);
394         if (err != I40E_SUCCESS)
395                 return err;
396
397         /* bind queue with VF function, since TX/QX will appear in pair,
398          * so only has QTX_CTL to set.
399          */
400         qtx_ctl = (I40E_QTX_CTL_VF_QUEUE << I40E_QTX_CTL_PFVF_Q_SHIFT) |
401                                 ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
402                                 I40E_QTX_CTL_PF_INDX_MASK) |
403                                 (((vf->vf_idx + hw->func_caps.vf_base_id) <<
404                                 I40E_QTX_CTL_VFVM_INDX_SHIFT) &
405                                 I40E_QTX_CTL_VFVM_INDX_MASK);
406         I40E_WRITE_REG(hw, I40E_QTX_CTL(abs_queue_id), qtx_ctl);
407         I40E_WRITE_FLUSH(hw);
408
409         return I40E_SUCCESS;
410 }
411
412 static int
413 i40e_pf_host_process_cmd_config_vsi_queues(struct i40e_pf_vf *vf,
414                                            uint8_t *msg,
415                                            uint16_t msglen)
416 {
417         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
418         struct i40e_vsi *vsi = vf->vsi;
419         struct i40e_virtchnl_vsi_queue_config_info *vc_vqci =
420                 (struct i40e_virtchnl_vsi_queue_config_info *)msg;
421         struct i40e_virtchnl_queue_pair_info *vc_qpi;
422         int i, ret = I40E_SUCCESS;
423
424         if (!msg || vc_vqci->num_queue_pairs > vsi->nb_qps ||
425                 vc_vqci->num_queue_pairs > I40E_MAX_VSI_QP ||
426                 msglen < I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqci,
427                                         vc_vqci->num_queue_pairs)) {
428                 PMD_DRV_LOG(ERR, "vsi_queue_config_info argument wrong\n");
429                 ret = I40E_ERR_PARAM;
430                 goto send_msg;
431         }
432
433         vc_qpi = vc_vqci->qpair;
434         for (i = 0; i < vc_vqci->num_queue_pairs; i++) {
435                 if (vc_qpi[i].rxq.queue_id > vsi->nb_qps - 1 ||
436                         vc_qpi[i].txq.queue_id > vsi->nb_qps - 1) {
437                         ret = I40E_ERR_PARAM;
438                         goto send_msg;
439                 }
440
441                 /*
442                  * Apply VF RX queue setting to HMC.
443                  * If the opcode is I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
444                  * then the extra information of
445                  * 'struct i40e_virtchnl_queue_pair_extra_info' is needed,
446                  * otherwise set the last parameter to NULL.
447                  */
448                 if (i40e_pf_host_hmc_config_rxq(hw, vf, &vc_qpi[i].rxq,
449                         I40E_CFG_CRCSTRIP_DEFAULT) != I40E_SUCCESS) {
450                         PMD_DRV_LOG(ERR, "Configure RX queue HMC failed");
451                         ret = I40E_ERR_PARAM;
452                         goto send_msg;
453                 }
454
455                 /* Apply VF TX queue setting to HMC */
456                 if (i40e_pf_host_hmc_config_txq(hw, vf,
457                         &vc_qpi[i].txq) != I40E_SUCCESS) {
458                         PMD_DRV_LOG(ERR, "Configure TX queue HMC failed");
459                         ret = I40E_ERR_PARAM;
460                         goto send_msg;
461                 }
462         }
463
464 send_msg:
465         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
466                                                         ret, NULL, 0);
467
468         return ret;
469 }
470
471 static int
472 i40e_pf_host_process_cmd_config_vsi_queues_ext(struct i40e_pf_vf *vf,
473                                                uint8_t *msg,
474                                                uint16_t msglen)
475 {
476         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
477         struct i40e_vsi *vsi = vf->vsi;
478         struct i40e_virtchnl_vsi_queue_config_ext_info *vc_vqcei =
479                 (struct i40e_virtchnl_vsi_queue_config_ext_info *)msg;
480         struct i40e_virtchnl_queue_pair_ext_info *vc_qpei;
481         int i, ret = I40E_SUCCESS;
482
483         if (!msg || vc_vqcei->num_queue_pairs > vsi->nb_qps ||
484                 vc_vqcei->num_queue_pairs > I40E_MAX_VSI_QP ||
485                 msglen < I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqcei,
486                                         vc_vqcei->num_queue_pairs)) {
487                 PMD_DRV_LOG(ERR, "vsi_queue_config_ext_info argument wrong\n");
488                 ret = I40E_ERR_PARAM;
489                 goto send_msg;
490         }
491
492         vc_qpei = vc_vqcei->qpair;
493         for (i = 0; i < vc_vqcei->num_queue_pairs; i++) {
494                 if (vc_qpei[i].rxq.queue_id > vsi->nb_qps - 1 ||
495                         vc_qpei[i].txq.queue_id > vsi->nb_qps - 1) {
496                         ret = I40E_ERR_PARAM;
497                         goto send_msg;
498                 }
499                 /*
500                  * Apply VF RX queue setting to HMC.
501                  * If the opcode is I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
502                  * then the extra information of
503                  * 'struct i40e_virtchnl_queue_pair_ext_info' is needed,
504                  * otherwise set the last parameter to NULL.
505                  */
506                 if (i40e_pf_host_hmc_config_rxq(hw, vf, &vc_qpei[i].rxq,
507                         vc_qpei[i].rxq_ext.crcstrip) != I40E_SUCCESS) {
508                         PMD_DRV_LOG(ERR, "Configure RX queue HMC failed");
509                         ret = I40E_ERR_PARAM;
510                         goto send_msg;
511                 }
512
513                 /* Apply VF TX queue setting to HMC */
514                 if (i40e_pf_host_hmc_config_txq(hw, vf, &vc_qpei[i].txq) !=
515                                                         I40E_SUCCESS) {
516                         PMD_DRV_LOG(ERR, "Configure TX queue HMC failed");
517                         ret = I40E_ERR_PARAM;
518                         goto send_msg;
519                 }
520         }
521
522 send_msg:
523         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT,
524                                                                 ret, NULL, 0);
525
526         return ret;
527 }
528
529 static int
530 i40e_pf_host_process_cmd_config_irq_map(struct i40e_pf_vf *vf,
531                                         uint8_t *msg, uint16_t msglen)
532 {
533         int ret = I40E_SUCCESS;
534         struct i40e_virtchnl_irq_map_info *irqmap =
535             (struct i40e_virtchnl_irq_map_info *)msg;
536
537         if (msg == NULL || msglen < sizeof(struct i40e_virtchnl_irq_map_info)) {
538                 PMD_DRV_LOG(ERR, "buffer too short");
539                 ret = I40E_ERR_PARAM;
540                 goto send_msg;
541         }
542
543         /* Assume VF only have 1 vector to bind all queues */
544         if (irqmap->num_vectors != 1) {
545                 PMD_DRV_LOG(ERR, "DKDK host only support 1 vector");
546                 ret = I40E_ERR_PARAM;
547                 goto send_msg;
548         }
549
550         if (irqmap->vecmap[0].vector_id == 0) {
551                 PMD_DRV_LOG(ERR, "DPDK host don't support use IRQ0");
552                 ret = I40E_ERR_PARAM;
553                 goto send_msg;
554         }
555         /* This MSIX intr store the intr in VF range */
556         vf->vsi->msix_intr = irqmap->vecmap[0].vector_id;
557         vf->vsi->nb_msix = irqmap->num_vectors;
558         vf->vsi->nb_used_qps = vf->vsi->nb_qps;
559
560         /* Don't care how the TX/RX queue mapping with this vector.
561          * Link all VF RX queues together. Only did mapping work.
562          * VF can disable/enable the intr by itself.
563          */
564         i40e_vsi_queues_bind_intr(vf->vsi);
565 send_msg:
566         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
567                                                         ret, NULL, 0);
568
569         return ret;
570 }
571
572 static int
573 i40e_pf_host_switch_queues(struct i40e_pf_vf *vf,
574                            struct i40e_virtchnl_queue_select *qsel,
575                            bool on)
576 {
577         int ret = I40E_SUCCESS;
578         int i;
579         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
580         uint16_t baseq = vf->vsi->base_queue;
581
582         if (qsel->rx_queues + qsel->tx_queues == 0)
583                 return I40E_ERR_PARAM;
584
585         /* always enable RX first and disable last */
586         /* Enable RX if it's enable */
587         if (on) {
588                 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
589                         if (qsel->rx_queues & (1 << i)) {
590                                 ret = i40e_switch_rx_queue(hw, baseq + i, on);
591                                 if (ret != I40E_SUCCESS)
592                                         return ret;
593                         }
594         }
595
596         /* Enable/Disable TX */
597         for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
598                 if (qsel->tx_queues & (1 << i)) {
599                         ret = i40e_switch_tx_queue(hw, baseq + i, on);
600                         if (ret != I40E_SUCCESS)
601                                 return ret;
602                 }
603
604         /* disable RX last if it's disable */
605         if (!on) {
606                 /* disable RX */
607                 for (i = 0; i < I40E_MAX_QP_NUM_PER_VF; i++)
608                         if (qsel->rx_queues & (1 << i)) {
609                                 ret = i40e_switch_rx_queue(hw, baseq + i, on);
610                                 if (ret != I40E_SUCCESS)
611                                         return ret;
612                         }
613         }
614
615         return ret;
616 }
617
618 static int
619 i40e_pf_host_process_cmd_enable_queues(struct i40e_pf_vf *vf,
620                                        uint8_t *msg,
621                                        uint16_t msglen)
622 {
623         int ret = I40E_SUCCESS;
624         struct i40e_virtchnl_queue_select *q_sel =
625                 (struct i40e_virtchnl_queue_select *)msg;
626
627         if (msg == NULL || msglen != sizeof(*q_sel)) {
628                 ret = I40E_ERR_PARAM;
629                 goto send_msg;
630         }
631         ret = i40e_pf_host_switch_queues(vf, q_sel, true);
632
633 send_msg:
634         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
635                                                         ret, NULL, 0);
636
637         return ret;
638 }
639
640 static int
641 i40e_pf_host_process_cmd_disable_queues(struct i40e_pf_vf *vf,
642                                         uint8_t *msg,
643                                         uint16_t msglen)
644 {
645         int ret = I40E_SUCCESS;
646         struct i40e_virtchnl_queue_select *q_sel =
647                 (struct i40e_virtchnl_queue_select *)msg;
648
649         if (msg == NULL || msglen != sizeof(*q_sel)) {
650                 ret = I40E_ERR_PARAM;
651                 goto send_msg;
652         }
653         ret = i40e_pf_host_switch_queues(vf, q_sel, false);
654
655 send_msg:
656         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
657                                                         ret, NULL, 0);
658
659         return ret;
660 }
661
662
663 static int
664 i40e_pf_host_process_cmd_add_ether_address(struct i40e_pf_vf *vf,
665                                            uint8_t *msg,
666                                            uint16_t msglen)
667 {
668         int ret = I40E_SUCCESS;
669         struct i40e_virtchnl_ether_addr_list *addr_list =
670                         (struct i40e_virtchnl_ether_addr_list *)msg;
671         struct i40e_mac_filter_info filter;
672         int i;
673         struct ether_addr *mac;
674
675         memset(&filter, 0 , sizeof(struct i40e_mac_filter_info));
676
677         if (msg == NULL || msglen <= sizeof(*addr_list)) {
678                 PMD_DRV_LOG(ERR, "add_ether_address argument too short");
679                 ret = I40E_ERR_PARAM;
680                 goto send_msg;
681         }
682
683         for (i = 0; i < addr_list->num_elements; i++) {
684                 mac = (struct ether_addr *)(addr_list->list[i].addr);
685                 (void)rte_memcpy(&filter.mac_addr, mac, ETHER_ADDR_LEN);
686                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
687                 if(!is_valid_assigned_ether_addr(mac) ||
688                         i40e_vsi_add_mac(vf->vsi, &filter)) {
689                         ret = I40E_ERR_INVALID_MAC_ADDR;
690                         goto send_msg;
691                 }
692         }
693
694 send_msg:
695         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
696                                                         ret, NULL, 0);
697
698         return ret;
699 }
700
701 static int
702 i40e_pf_host_process_cmd_del_ether_address(struct i40e_pf_vf *vf,
703                                            uint8_t *msg,
704                                            uint16_t msglen)
705 {
706         int ret = I40E_SUCCESS;
707         struct i40e_virtchnl_ether_addr_list *addr_list =
708                 (struct i40e_virtchnl_ether_addr_list *)msg;
709         int i;
710         struct ether_addr *mac;
711
712         if (msg == NULL || msglen <= sizeof(*addr_list)) {
713                 PMD_DRV_LOG(ERR, "delete_ether_address argument too short");
714                 ret = I40E_ERR_PARAM;
715                 goto send_msg;
716         }
717
718         for (i = 0; i < addr_list->num_elements; i++) {
719                 mac = (struct ether_addr *)(addr_list->list[i].addr);
720                 if(!is_valid_assigned_ether_addr(mac) ||
721                         i40e_vsi_delete_mac(vf->vsi, mac)) {
722                         ret = I40E_ERR_INVALID_MAC_ADDR;
723                         goto send_msg;
724                 }
725         }
726
727 send_msg:
728         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
729                                                         ret, NULL, 0);
730
731         return ret;
732 }
733
734 static int
735 i40e_pf_host_process_cmd_add_vlan(struct i40e_pf_vf *vf,
736                                 uint8_t *msg, uint16_t msglen)
737 {
738         int ret = I40E_SUCCESS;
739         struct i40e_virtchnl_vlan_filter_list *vlan_filter_list =
740                 (struct i40e_virtchnl_vlan_filter_list *)msg;
741         int i;
742         uint16_t *vid;
743
744         if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
745                 PMD_DRV_LOG(ERR, "add_vlan argument too short");
746                 ret = I40E_ERR_PARAM;
747                 goto send_msg;
748         }
749
750         vid = vlan_filter_list->vlan_id;
751
752         for (i = 0; i < vlan_filter_list->num_elements; i++) {
753                 ret = i40e_vsi_add_vlan(vf->vsi, vid[i]);
754                 if(ret != I40E_SUCCESS)
755                         goto send_msg;
756         }
757
758 send_msg:
759         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN,
760                                                 ret, NULL, 0);
761
762         return ret;
763 }
764
765 static int
766 i40e_pf_host_process_cmd_del_vlan(struct i40e_pf_vf *vf,
767                                   uint8_t *msg,
768                                   uint16_t msglen)
769 {
770         int ret = I40E_SUCCESS;
771         struct i40e_virtchnl_vlan_filter_list *vlan_filter_list =
772                         (struct i40e_virtchnl_vlan_filter_list *)msg;
773         int i;
774         uint16_t *vid;
775
776         if (msg == NULL || msglen <= sizeof(*vlan_filter_list)) {
777                 PMD_DRV_LOG(ERR, "delete_vlan argument too short");
778                 ret = I40E_ERR_PARAM;
779                 goto send_msg;
780         }
781
782         vid = vlan_filter_list->vlan_id;
783         for (i = 0; i < vlan_filter_list->num_elements; i++) {
784                 ret = i40e_vsi_delete_vlan(vf->vsi, vid[i]);
785                 if(ret != I40E_SUCCESS)
786                         goto send_msg;
787         }
788
789 send_msg:
790         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN,
791                                                 ret, NULL, 0);
792
793         return ret;
794 }
795
796 static int
797 i40e_pf_host_process_cmd_config_promisc_mode(
798                                         struct i40e_pf_vf *vf,
799                                         uint8_t *msg,
800                                         uint16_t msglen)
801 {
802         int ret = I40E_SUCCESS;
803         struct i40e_virtchnl_promisc_info *promisc =
804                                 (struct i40e_virtchnl_promisc_info *)msg;
805         struct i40e_hw *hw = I40E_PF_TO_HW(vf->pf);
806         bool unicast = FALSE, multicast = FALSE;
807
808         if (msg == NULL || msglen != sizeof(*promisc)) {
809                 ret = I40E_ERR_PARAM;
810                 goto send_msg;
811         }
812
813         if (promisc->flags & I40E_FLAG_VF_UNICAST_PROMISC)
814                 unicast = TRUE;
815         ret = i40e_aq_set_vsi_unicast_promiscuous(hw,
816                         vf->vsi->seid, unicast, NULL);
817         if (ret != I40E_SUCCESS)
818                 goto send_msg;
819
820         if (promisc->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
821                 multicast = TRUE;
822         ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vf->vsi->seid,
823                                                 multicast, NULL);
824
825 send_msg:
826         i40e_pf_host_send_msg_to_vf(vf,
827                 I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, ret, NULL, 0);
828
829         return ret;
830 }
831
832 static int
833 i40e_pf_host_process_cmd_get_stats(struct i40e_pf_vf *vf)
834 {
835         i40e_update_vsi_stats(vf->vsi);
836
837         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS,
838                 I40E_SUCCESS, (uint8_t *)&vf->vsi->eth_stats,
839                                 sizeof(vf->vsi->eth_stats));
840
841         return I40E_SUCCESS;
842 }
843
844 static void
845 i40e_pf_host_process_cmd_get_link_status(struct i40e_pf_vf *vf)
846 {
847         struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vf->pf->main_vsi);
848
849         /* Update link status first to acquire latest link change */
850         i40e_dev_link_update(dev, 1);
851         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_LINK_STAT,
852                 I40E_SUCCESS, (uint8_t *)&dev->data->dev_link,
853                                 sizeof(struct rte_eth_link));
854 }
855
856 static int
857 i40e_pf_host_process_cmd_cfg_vlan_offload(
858                                         struct i40e_pf_vf *vf,
859                                         uint8_t *msg,
860                                         uint16_t msglen)
861 {
862         int ret = I40E_SUCCESS;
863         struct i40e_virtchnl_vlan_offload_info *offload =
864                         (struct i40e_virtchnl_vlan_offload_info *)msg;
865
866         if (msg == NULL || msglen != sizeof(*offload)) {
867                 ret = I40E_ERR_PARAM;
868                 goto send_msg;
869         }
870
871         ret = i40e_vsi_config_vlan_stripping(vf->vsi,
872                                                 !!offload->enable_vlan_strip);
873         if (ret != 0)
874                 PMD_DRV_LOG(ERR, "Failed to configure vlan stripping");
875
876 send_msg:
877         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD,
878                                         ret, NULL, 0);
879
880         return ret;
881 }
882
883 static int
884 i40e_pf_host_process_cmd_cfg_pvid(struct i40e_pf_vf *vf,
885                                         uint8_t *msg,
886                                         uint16_t msglen)
887 {
888         int ret = I40E_SUCCESS;
889         struct i40e_virtchnl_pvid_info  *tpid_info =
890                         (struct i40e_virtchnl_pvid_info *)msg;
891
892         if (msg == NULL || msglen != sizeof(*tpid_info)) {
893                 ret = I40E_ERR_PARAM;
894                 goto send_msg;
895         }
896
897         ret = i40e_vsi_vlan_pvid_set(vf->vsi, &tpid_info->info);
898
899 send_msg:
900         i40e_pf_host_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_CFG_VLAN_PVID,
901                                         ret, NULL, 0);
902
903         return ret;
904 }
905
906 void
907 i40e_pf_host_handle_vf_msg(struct rte_eth_dev *dev,
908                            uint16_t abs_vf_id, uint32_t opcode,
909                            __rte_unused uint32_t retval,
910                            uint8_t *msg,
911                            uint16_t msglen)
912 {
913         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
914         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
915         struct i40e_pf_vf *vf;
916         /* AdminQ will pass absolute VF id, transfer to internal vf id */
917         uint16_t vf_id = abs_vf_id - hw->func_caps.vf_base_id;
918
919         if (!dev || vf_id > pf->vf_num - 1 || !pf->vfs) {
920                 PMD_DRV_LOG(ERR, "invalid argument");
921                 return;
922         }
923
924         vf = &pf->vfs[vf_id];
925         if (!vf->vsi) {
926                 PMD_DRV_LOG(ERR, "NO VSI associated with VF found");
927                 i40e_pf_host_send_msg_to_vf(vf, opcode,
928                         I40E_ERR_NO_AVAILABLE_VSI, NULL, 0);
929                 return;
930         }
931
932         switch (opcode) {
933         case I40E_VIRTCHNL_OP_VERSION :
934                 PMD_DRV_LOG(INFO, "OP_VERSION received");
935                 i40e_pf_host_process_cmd_version(vf);
936                 break;
937         case I40E_VIRTCHNL_OP_RESET_VF :
938                 PMD_DRV_LOG(INFO, "OP_RESET_VF received");
939                 i40e_pf_host_process_cmd_reset_vf(vf);
940                 break;
941         case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
942                 PMD_DRV_LOG(INFO, "OP_GET_VF_RESOURCES received");
943                 i40e_pf_host_process_cmd_get_vf_resource(vf);
944                 break;
945         case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
946                 PMD_DRV_LOG(INFO, "OP_CONFIG_VSI_QUEUES received");
947                 i40e_pf_host_process_cmd_config_vsi_queues(vf, msg, msglen);
948                 break;
949         case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT:
950                 PMD_DRV_LOG(INFO, "OP_CONFIG_VSI_QUEUES_EXT received");
951                 i40e_pf_host_process_cmd_config_vsi_queues_ext(vf, msg,
952                                                                 msglen);
953                 break;
954         case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
955                 PMD_DRV_LOG(INFO, "OP_CONFIG_IRQ_MAP received");
956                 i40e_pf_host_process_cmd_config_irq_map(vf, msg, msglen);
957                 break;
958         case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
959                 PMD_DRV_LOG(INFO, "OP_ENABLE_QUEUES received");
960                 i40e_pf_host_process_cmd_enable_queues(vf, msg, msglen);
961                 break;
962         case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
963                 PMD_DRV_LOG(INFO, "OP_DISABLE_QUEUE received");
964                 i40e_pf_host_process_cmd_disable_queues(vf, msg, msglen);
965                 break;
966         case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
967                 PMD_DRV_LOG(INFO, "OP_ADD_ETHER_ADDRESS received");
968                 i40e_pf_host_process_cmd_add_ether_address(vf, msg, msglen);
969                 break;
970         case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
971                 PMD_DRV_LOG(INFO, "OP_DEL_ETHER_ADDRESS received");
972                 i40e_pf_host_process_cmd_del_ether_address(vf, msg, msglen);
973                 break;
974         case I40E_VIRTCHNL_OP_ADD_VLAN:
975                 PMD_DRV_LOG(INFO, "OP_ADD_VLAN received");
976                 i40e_pf_host_process_cmd_add_vlan(vf, msg, msglen);
977                 break;
978         case I40E_VIRTCHNL_OP_DEL_VLAN:
979                 PMD_DRV_LOG(INFO, "OP_DEL_VLAN received");
980                 i40e_pf_host_process_cmd_del_vlan(vf, msg, msglen);
981                 break;
982         case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
983                 PMD_DRV_LOG(INFO, "OP_CONFIG_PROMISCUOUS_MODE received");
984                 i40e_pf_host_process_cmd_config_promisc_mode(vf, msg, msglen);
985                 break;
986         case I40E_VIRTCHNL_OP_GET_STATS:
987                 PMD_DRV_LOG(INFO, "OP_GET_STATS received");
988                 i40e_pf_host_process_cmd_get_stats(vf);
989                 break;
990         case I40E_VIRTCHNL_OP_GET_LINK_STAT:
991                 PMD_DRV_LOG(INFO, "OP_GET_LINK_STAT received");
992                 i40e_pf_host_process_cmd_get_link_status(vf);
993                 break;
994         case I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD:
995                 PMD_DRV_LOG(INFO, "OP_CFG_VLAN_OFFLOAD received");
996                 i40e_pf_host_process_cmd_cfg_vlan_offload(vf, msg, msglen);
997                 break;
998         case I40E_VIRTCHNL_OP_CFG_VLAN_PVID:
999                 PMD_DRV_LOG(INFO, "OP_CFG_VLAN_PVID received");
1000                 i40e_pf_host_process_cmd_cfg_pvid(vf, msg, msglen);
1001                 break;
1002          /* Don't add command supported below, which will
1003          *  return an error code.
1004          */
1005         case I40E_VIRTCHNL_OP_FCOE:
1006                 PMD_DRV_LOG(ERR, "OP_FCOE received, not supported");
1007         default:
1008                 PMD_DRV_LOG(ERR, "%u received, not supported", opcode);
1009                 i40e_pf_host_send_msg_to_vf(vf, opcode, I40E_ERR_PARAM,
1010                                                                 NULL, 0);
1011                 break;
1012         }
1013 }
1014
1015 int
1016 i40e_pf_host_init(struct rte_eth_dev *dev)
1017 {
1018         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1019         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1020         int ret, i;
1021         uint32_t val;
1022
1023         PMD_INIT_FUNC_TRACE();
1024
1025         /**
1026          * return if SRIOV not enabled, VF number not configured or
1027          * no queue assigned.
1028          */
1029         if(!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 || pf->vf_nb_qps == 0)
1030                 return I40E_SUCCESS;
1031
1032         /* Allocate memory to store VF structure */
1033         pf->vfs = rte_zmalloc("i40e_pf_vf",sizeof(*pf->vfs) * pf->vf_num, 0);
1034         if(pf->vfs == NULL)
1035                 return -ENOMEM;
1036
1037         /* Disable irq0 for VFR event */
1038         i40e_pf_disable_irq0(hw);
1039
1040         /* Disable VF link status interrupt */
1041         val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1042         val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1043         I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1044         I40E_WRITE_FLUSH(hw);
1045
1046         for (i = 0; i < pf->vf_num; i++) {
1047                 pf->vfs[i].pf = pf;
1048                 pf->vfs[i].state = I40E_VF_INACTIVE;
1049                 pf->vfs[i].vf_idx = i;
1050                 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
1051                 if (ret != I40E_SUCCESS)
1052                         goto fail;
1053         }
1054
1055         /* restore irq0 */
1056         i40e_pf_enable_irq0(hw);
1057
1058         return I40E_SUCCESS;
1059
1060 fail:
1061         rte_free(pf->vfs);
1062         i40e_pf_enable_irq0(hw);
1063
1064         return ret;
1065 }
1066
1067 int
1068 i40e_pf_host_uninit(struct rte_eth_dev *dev)
1069 {
1070         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1071         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1072         uint32_t val;
1073
1074         PMD_INIT_FUNC_TRACE();
1075
1076         /**
1077          * return if SRIOV not enabled, VF number not configured or
1078          * no queue assigned.
1079          */
1080         if ((!hw->func_caps.sr_iov_1_1) ||
1081                 (pf->vf_num == 0) ||
1082                 (pf->vf_nb_qps == 0))
1083                 return I40E_SUCCESS;
1084
1085         /* free memory to store VF structure */
1086         rte_free(pf->vfs);
1087         pf->vfs = NULL;
1088
1089         /* Disable irq0 for VFR event */
1090         i40e_pf_disable_irq0(hw);
1091
1092         /* Disable VF link status interrupt */
1093         val = I40E_READ_REG(hw, I40E_PFGEN_PORTMDIO_NUM);
1094         val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
1095         I40E_WRITE_REG(hw, I40E_PFGEN_PORTMDIO_NUM, val);
1096         I40E_WRITE_FLUSH(hw);
1097
1098         return I40E_SUCCESS;
1099 }