i40evf: support RSS
[dpdk.git] / lib / librte_pmd_i40e / i40e_ethdev_vf.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 #include <rte_byteorder.h>
43 #include <rte_common.h>
44 #include <rte_cycles.h>
45
46 #include <rte_interrupts.h>
47 #include <rte_log.h>
48 #include <rte_debug.h>
49 #include <rte_pci.h>
50 #include <rte_atomic.h>
51 #include <rte_branch_prediction.h>
52 #include <rte_memory.h>
53 #include <rte_memzone.h>
54 #include <rte_tailq.h>
55 #include <rte_eal.h>
56 #include <rte_alarm.h>
57 #include <rte_ether.h>
58 #include <rte_ethdev.h>
59 #include <rte_atomic.h>
60 #include <rte_malloc.h>
61 #include <rte_dev.h>
62
63 #include "i40e_logs.h"
64 #include "i40e/i40e_prototype.h"
65 #include "i40e/i40e_adminq_cmd.h"
66 #include "i40e/i40e_type.h"
67
68 #include "i40e_rxtx.h"
69 #include "i40e_ethdev.h"
70 #include "i40e_pf.h"
71 #define I40EVF_VSI_DEFAULT_MSIX_INTR 1
72
73 /* busy wait delay in msec */
74 #define I40EVF_BUSY_WAIT_DELAY 10
75 #define I40EVF_BUSY_WAIT_COUNT 50
76 #define MAX_RESET_WAIT_CNT     20
77
78 struct i40evf_arq_msg_info {
79         enum i40e_virtchnl_ops ops;
80         enum i40e_status_code result;
81         uint16_t buf_len;
82         uint16_t msg_len;
83         uint8_t *msg;
84 };
85
86 struct vf_cmd_info {
87         enum i40e_virtchnl_ops ops;
88         uint8_t *in_args;
89         uint32_t in_args_size;
90         uint8_t *out_buffer;
91         /* Input & output type. pass in buffer size and pass out
92          * actual return result
93          */
94         uint32_t out_size;
95 };
96
97 enum i40evf_aq_result {
98         I40EVF_MSG_ERR = -1, /* Meet error when accessing admin queue */
99         I40EVF_MSG_NON,      /* Read nothing from admin queue */
100         I40EVF_MSG_SYS,      /* Read system msg from admin queue */
101         I40EVF_MSG_CMD,      /* Read async command result */
102 };
103
104 /* A share buffer to store the command result from PF driver */
105 static uint8_t cmd_result_buffer[I40E_AQ_BUF_SZ];
106
107 static int i40evf_dev_configure(struct rte_eth_dev *dev);
108 static int i40evf_dev_start(struct rte_eth_dev *dev);
109 static void i40evf_dev_stop(struct rte_eth_dev *dev);
110 static void i40evf_dev_info_get(struct rte_eth_dev *dev,
111                                 struct rte_eth_dev_info *dev_info);
112 static int i40evf_dev_link_update(struct rte_eth_dev *dev,
113                                   __rte_unused int wait_to_complete);
114 static void i40evf_dev_stats_get(struct rte_eth_dev *dev,
115                                 struct rte_eth_stats *stats);
116 static int i40evf_vlan_filter_set(struct rte_eth_dev *dev,
117                                   uint16_t vlan_id, int on);
118 static void i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
119 static int i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid,
120                                 int on);
121 static void i40evf_dev_close(struct rte_eth_dev *dev);
122 static void i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev);
123 static void i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev);
124 static void i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev);
125 static void i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev);
126 static int i40evf_get_link_status(struct rte_eth_dev *dev,
127                                   struct rte_eth_link *link);
128 static int i40evf_init_vlan(struct rte_eth_dev *dev);
129 static int i40evf_config_rss(struct i40e_vf *vf);
130 static int i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
131                                       struct rte_eth_rss_conf *rss_conf);
132 static int i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
133                                         struct rte_eth_rss_conf *rss_conf);
134 static int i40evf_dev_rx_queue_start(struct rte_eth_dev *, uint16_t);
135 static int i40evf_dev_rx_queue_stop(struct rte_eth_dev *, uint16_t);
136 static int i40evf_dev_tx_queue_start(struct rte_eth_dev *, uint16_t);
137 static int i40evf_dev_tx_queue_stop(struct rte_eth_dev *, uint16_t);
138
139 /* Default hash key buffer for RSS */
140 static uint32_t rss_key_default[I40E_VFQF_HKEY_MAX_INDEX + 1];
141
142 static struct eth_dev_ops i40evf_eth_dev_ops = {
143         .dev_configure        = i40evf_dev_configure,
144         .dev_start            = i40evf_dev_start,
145         .dev_stop             = i40evf_dev_stop,
146         .promiscuous_enable   = i40evf_dev_promiscuous_enable,
147         .promiscuous_disable  = i40evf_dev_promiscuous_disable,
148         .allmulticast_enable  = i40evf_dev_allmulticast_enable,
149         .allmulticast_disable = i40evf_dev_allmulticast_disable,
150         .link_update          = i40evf_dev_link_update,
151         .stats_get            = i40evf_dev_stats_get,
152         .dev_close            = i40evf_dev_close,
153         .dev_infos_get        = i40evf_dev_info_get,
154         .vlan_filter_set      = i40evf_vlan_filter_set,
155         .vlan_offload_set     = i40evf_vlan_offload_set,
156         .vlan_pvid_set        = i40evf_vlan_pvid_set,
157         .rx_queue_start       = i40evf_dev_rx_queue_start,
158         .rx_queue_stop        = i40evf_dev_rx_queue_stop,
159         .tx_queue_start       = i40evf_dev_tx_queue_start,
160         .tx_queue_stop        = i40evf_dev_tx_queue_stop,
161         .rx_queue_setup       = i40e_dev_rx_queue_setup,
162         .rx_queue_release     = i40e_dev_rx_queue_release,
163         .tx_queue_setup       = i40e_dev_tx_queue_setup,
164         .tx_queue_release     = i40e_dev_tx_queue_release,
165         .rss_hash_update      = i40evf_dev_rss_hash_update,
166         .rss_hash_conf_get    = i40evf_dev_rss_hash_conf_get,
167 };
168
169 static int
170 i40evf_set_mac_type(struct i40e_hw *hw)
171 {
172         int status = I40E_ERR_DEVICE_NOT_SUPPORTED;
173
174         if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
175                 switch (hw->device_id) {
176                 case I40E_DEV_ID_VF:
177                 case I40E_DEV_ID_VF_HV:
178                         hw->mac.type = I40E_MAC_VF;
179                         status = I40E_SUCCESS;
180                         break;
181                 default:
182                         ;
183                 }
184         }
185
186         return status;
187 }
188
189 /*
190  * Parse admin queue message.
191  *
192  * return value:
193  *  < 0: meet error
194  *  0: read sys msg
195  *  > 0: read cmd result
196  */
197 static enum i40evf_aq_result
198 i40evf_parse_pfmsg(struct i40e_vf *vf,
199                    struct i40e_arq_event_info *event,
200                    struct i40evf_arq_msg_info *data)
201 {
202         enum i40e_virtchnl_ops opcode = (enum i40e_virtchnl_ops)\
203                         rte_le_to_cpu_32(event->desc.cookie_high);
204         enum i40e_status_code retval = (enum i40e_status_code)\
205                         rte_le_to_cpu_32(event->desc.cookie_low);
206         enum i40evf_aq_result ret = I40EVF_MSG_CMD;
207
208         /* pf sys event */
209         if (opcode == I40E_VIRTCHNL_OP_EVENT) {
210                 struct i40e_virtchnl_pf_event *vpe =
211                         (struct i40e_virtchnl_pf_event *)event->msg_buf;
212
213                 /* Initialize ret to sys event */
214                 ret = I40EVF_MSG_SYS;
215                 switch (vpe->event) {
216                 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
217                         vf->link_up =
218                                 vpe->event_data.link_event.link_status;
219                         vf->pend_msg |= PFMSG_LINK_CHANGE;
220                         PMD_DRV_LOG(INFO, "Link status update:%s",
221                                     vf->link_up ? "up" : "down");
222                         break;
223                 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
224                         vf->vf_reset = true;
225                         vf->pend_msg |= PFMSG_RESET_IMPENDING;
226                         PMD_DRV_LOG(INFO, "vf is reseting");
227                         break;
228                 case I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
229                         vf->dev_closed = true;
230                         vf->pend_msg |= PFMSG_DRIVER_CLOSE;
231                         PMD_DRV_LOG(INFO, "PF driver closed");
232                         break;
233                 default:
234                         PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
235                                     __func__, vpe->event);
236                 }
237         } else {
238                 /* async reply msg on command issued by vf previously */
239                 ret = I40EVF_MSG_CMD;
240                 /* Actual data length read from PF */
241                 data->msg_len = event->msg_len;
242         }
243         /* fill the ops and result to notify VF */
244         data->result = retval;
245         data->ops = opcode;
246
247         return ret;
248 }
249
250 /*
251  * Read data in admin queue to get msg from pf driver
252  */
253 static enum i40evf_aq_result
254 i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
255 {
256         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
257         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
258         struct i40e_arq_event_info event;
259         int ret;
260         enum i40evf_aq_result result = I40EVF_MSG_NON;
261
262         event.buf_len = data->buf_len;
263         event.msg_buf = data->msg;
264         ret = i40e_clean_arq_element(hw, &event, NULL);
265         /* Can't read any msg from adminQ */
266         if (ret) {
267                 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
268                         result = I40EVF_MSG_NON;
269                 else
270                         result = I40EVF_MSG_ERR;
271                 return result;
272         }
273
274         /* Parse the event */
275         result = i40evf_parse_pfmsg(vf, &event, data);
276
277         return result;
278 }
279
280 /*
281  * Polling read until command result return from pf driver or meet error.
282  */
283 static int
284 i40evf_wait_cmd_done(struct rte_eth_dev *dev,
285                      struct i40evf_arq_msg_info *data)
286 {
287         int i = 0;
288         enum i40evf_aq_result ret;
289
290 #define MAX_TRY_TIMES 10
291 #define ASQ_DELAY_MS  50
292         do {
293                 /* Delay some time first */
294                 rte_delay_ms(ASQ_DELAY_MS);
295                 ret = i40evf_read_pfmsg(dev, data);
296                 if (ret == I40EVF_MSG_CMD)
297                         return 0;
298                 else if (ret == I40EVF_MSG_ERR)
299                         return -1;
300
301                 /* If don't read msg or read sys event, continue */
302         } while(i++ < MAX_TRY_TIMES);
303
304         return -1;
305 }
306
307 /**
308  * clear current command. Only call in case execute
309  * _atomic_set_cmd successfully.
310  */
311 static inline void
312 _clear_cmd(struct i40e_vf *vf)
313 {
314         rte_wmb();
315         vf->pend_cmd = I40E_VIRTCHNL_OP_UNKNOWN;
316 }
317
318 /*
319  * Check there is pending cmd in execution. If none, set new command.
320  */
321 static inline int
322 _atomic_set_cmd(struct i40e_vf *vf, enum i40e_virtchnl_ops ops)
323 {
324         int ret = rte_atomic32_cmpset(&vf->pend_cmd,
325                         I40E_VIRTCHNL_OP_UNKNOWN, ops);
326
327         if (!ret)
328                 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
329
330         return !ret;
331 }
332
333 static int
334 i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
335 {
336         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
337         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
338         int err = -1;
339         struct i40evf_arq_msg_info info;
340
341         if (_atomic_set_cmd(vf, args->ops))
342                 return -1;
343
344         info.msg = args->out_buffer;
345         info.buf_len = args->out_size;
346         info.ops = I40E_VIRTCHNL_OP_UNKNOWN;
347         info.result = I40E_SUCCESS;
348
349         err = i40e_aq_send_msg_to_pf(hw, args->ops, I40E_SUCCESS,
350                      args->in_args, args->in_args_size, NULL);
351         if (err) {
352                 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
353                 return err;
354         }
355
356         err = i40evf_wait_cmd_done(dev, &info);
357         /* read message and it's expected one */
358         if (!err && args->ops == info.ops)
359                 _clear_cmd(vf);
360         else if (err)
361                 PMD_DRV_LOG(ERR, "Failed to read message from AdminQ");
362         else if (args->ops != info.ops)
363                 PMD_DRV_LOG(ERR, "command mismatch, expect %u, get %u",
364                             args->ops, info.ops);
365
366         return (err | info.result);
367 }
368
369 /*
370  * Check API version with sync wait until version read or fail from admin queue
371  */
372 static int
373 i40evf_check_api_version(struct rte_eth_dev *dev)
374 {
375         struct i40e_virtchnl_version_info version, *pver;
376         int err;
377         struct vf_cmd_info args;
378         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
379
380         version.major = I40E_VIRTCHNL_VERSION_MAJOR;
381         version.minor = I40E_VIRTCHNL_VERSION_MINOR;
382
383         args.ops = I40E_VIRTCHNL_OP_VERSION;
384         args.in_args = (uint8_t *)&version;
385         args.in_args_size = sizeof(version);
386         args.out_buffer = cmd_result_buffer;
387         args.out_size = I40E_AQ_BUF_SZ;
388
389         err = i40evf_execute_vf_cmd(dev, &args);
390         if (err) {
391                 PMD_INIT_LOG(ERR, "fail to execute command OP_VERSION");
392                 return err;
393         }
394
395         pver = (struct i40e_virtchnl_version_info *)args.out_buffer;
396         /* We are talking with DPDK host */
397         if (pver->major == I40E_DPDK_VERSION_MAJOR) {
398                 vf->host_is_dpdk = TRUE;
399                 PMD_DRV_LOG(INFO, "Detect PF host is DPDK app");
400         }
401         /* It's linux host driver */
402         else if ((pver->major != version.major) ||
403             (pver->minor != version.minor)) {
404                 PMD_INIT_LOG(ERR, "pf/vf API version mismatch. "
405                              "(%u.%u)-(%u.%u)", pver->major, pver->minor,
406                              version.major, version.minor);
407                 return -1;
408         }
409
410         return 0;
411 }
412
413 static int
414 i40evf_get_vf_resource(struct rte_eth_dev *dev)
415 {
416         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
417         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
418         int err;
419         struct vf_cmd_info args;
420         uint32_t len;
421
422         args.ops = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
423         args.in_args = NULL;
424         args.in_args_size = 0;
425         args.out_buffer = cmd_result_buffer;
426         args.out_size = I40E_AQ_BUF_SZ;
427
428         err = i40evf_execute_vf_cmd(dev, &args);
429
430         if (err) {
431                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_VF_RESOURCE");
432                 return err;
433         }
434
435         len =  sizeof(struct i40e_virtchnl_vf_resource) +
436                 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
437
438         (void)rte_memcpy(vf->vf_res, args.out_buffer,
439                         RTE_MIN(args.out_size, len));
440         i40e_vf_parse_hw_config(hw, vf->vf_res);
441
442         return 0;
443 }
444
445 static int
446 i40evf_config_promisc(struct rte_eth_dev *dev,
447                       bool enable_unicast,
448                       bool enable_multicast)
449 {
450         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
451         int err;
452         struct vf_cmd_info args;
453         struct i40e_virtchnl_promisc_info promisc;
454
455         promisc.flags = 0;
456         promisc.vsi_id = vf->vsi_res->vsi_id;
457
458         if (enable_unicast)
459                 promisc.flags |= I40E_FLAG_VF_UNICAST_PROMISC;
460
461         if (enable_multicast)
462                 promisc.flags |= I40E_FLAG_VF_MULTICAST_PROMISC;
463
464         args.ops = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
465         args.in_args = (uint8_t *)&promisc;
466         args.in_args_size = sizeof(promisc);
467         args.out_buffer = cmd_result_buffer;
468         args.out_size = I40E_AQ_BUF_SZ;
469
470         err = i40evf_execute_vf_cmd(dev, &args);
471
472         if (err)
473                 PMD_DRV_LOG(ERR, "fail to execute command "
474                             "CONFIG_PROMISCUOUS_MODE");
475         return err;
476 }
477
478 /* Configure vlan and double vlan offload. Use flag to specify which part to configure */
479 static int
480 i40evf_config_vlan_offload(struct rte_eth_dev *dev,
481                                 bool enable_vlan_strip)
482 {
483         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
484         int err;
485         struct vf_cmd_info args;
486         struct i40e_virtchnl_vlan_offload_info offload;
487
488         offload.vsi_id = vf->vsi_res->vsi_id;
489         offload.enable_vlan_strip = enable_vlan_strip;
490
491         args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD;
492         args.in_args = (uint8_t *)&offload;
493         args.in_args_size = sizeof(offload);
494         args.out_buffer = cmd_result_buffer;
495         args.out_size = I40E_AQ_BUF_SZ;
496
497         err = i40evf_execute_vf_cmd(dev, &args);
498         if (err)
499                 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_OFFLOAD");
500
501         return err;
502 }
503
504 static int
505 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
506                                 struct i40e_vsi_vlan_pvid_info *info)
507 {
508         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
509         int err;
510         struct vf_cmd_info args;
511         struct i40e_virtchnl_pvid_info tpid_info;
512
513         if (dev == NULL || info == NULL) {
514                 PMD_DRV_LOG(ERR, "invalid parameters");
515                 return I40E_ERR_PARAM;
516         }
517
518         memset(&tpid_info, 0, sizeof(tpid_info));
519         tpid_info.vsi_id = vf->vsi_res->vsi_id;
520         (void)rte_memcpy(&tpid_info.info, info, sizeof(*info));
521
522         args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_PVID;
523         args.in_args = (uint8_t *)&tpid_info;
524         args.in_args_size = sizeof(tpid_info);
525         args.out_buffer = cmd_result_buffer;
526         args.out_size = I40E_AQ_BUF_SZ;
527
528         err = i40evf_execute_vf_cmd(dev, &args);
529         if (err)
530                 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_PVID");
531
532         return err;
533 }
534
535 static int
536 i40evf_configure_queues(struct rte_eth_dev *dev)
537 {
538         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
539         struct i40e_virtchnl_vsi_queue_config_info *queue_info;
540         struct i40e_virtchnl_queue_pair_info *queue_cfg;
541         struct i40e_rx_queue **rxq =
542                 (struct i40e_rx_queue **)dev->data->rx_queues;
543         struct i40e_tx_queue **txq =
544                 (struct i40e_tx_queue **)dev->data->tx_queues;
545         int i, len, nb_qpairs, num_rxq, num_txq;
546         int err;
547         struct vf_cmd_info args;
548         struct rte_pktmbuf_pool_private *mbp_priv;
549
550         nb_qpairs = vf->num_queue_pairs;
551         len = sizeof(*queue_info) + sizeof(*queue_cfg) * nb_qpairs;
552         queue_info = rte_zmalloc("queue_info", len, 0);
553         if (queue_info == NULL) {
554                 PMD_INIT_LOG(ERR, "failed alloc memory for queue_info");
555                 return -1;
556         }
557         queue_info->vsi_id = vf->vsi_res->vsi_id;
558         queue_info->num_queue_pairs = nb_qpairs;
559         queue_cfg = queue_info->qpair;
560
561         num_rxq = dev->data->nb_rx_queues;
562         num_txq = dev->data->nb_tx_queues;
563         /*
564          * PF host driver required to configure queues in pairs, which means
565          * rxq_num should equals to txq_num. The actual usage won't always
566          * work that way. The solution is fills 0 with HW ring option in case
567          * they are not equal.
568          */
569         for (i = 0; i < nb_qpairs; i++) {
570                 /*Fill TX info */
571                 queue_cfg->txq.vsi_id = queue_info->vsi_id;
572                 queue_cfg->txq.queue_id = i;
573                 if (i < num_txq) {
574                         queue_cfg->txq.ring_len = txq[i]->nb_tx_desc;
575                         queue_cfg->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
576                 } else {
577                         queue_cfg->txq.ring_len = 0;
578                         queue_cfg->txq.dma_ring_addr = 0;
579                 }
580
581                 /* Fill RX info */
582                 queue_cfg->rxq.vsi_id = queue_info->vsi_id;
583                 queue_cfg->rxq.queue_id = i;
584                 queue_cfg->rxq.max_pkt_size = vf->max_pkt_len;
585                 if (i < num_rxq) {
586                         mbp_priv = rte_mempool_get_priv(rxq[i]->mp);
587                         queue_cfg->rxq.databuffer_size = mbp_priv->mbuf_data_room_size -
588                                                    RTE_PKTMBUF_HEADROOM;;
589                         queue_cfg->rxq.ring_len = rxq[i]->nb_rx_desc;
590                         queue_cfg->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;;
591                 } else {
592                         queue_cfg->rxq.ring_len = 0;
593                         queue_cfg->rxq.dma_ring_addr = 0;
594                         queue_cfg->rxq.databuffer_size = 0;
595                 }
596                 queue_cfg++;
597         }
598
599         args.ops = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
600         args.in_args = (u8 *)queue_info;
601         args.in_args_size = len;
602         args.out_buffer = cmd_result_buffer;
603         args.out_size = I40E_AQ_BUF_SZ;
604         err = i40evf_execute_vf_cmd(dev, &args);
605         if (err)
606                 PMD_DRV_LOG(ERR, "fail to execute command "
607                             "OP_CONFIG_VSI_QUEUES");
608         rte_free(queue_info);
609
610         return err;
611 }
612
613 static int
614 i40evf_config_irq_map(struct rte_eth_dev *dev)
615 {
616         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
617         struct vf_cmd_info args;
618         uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
619                 sizeof(struct i40e_virtchnl_vector_map)];
620         struct i40e_virtchnl_irq_map_info *map_info;
621         int i, err;
622         map_info = (struct i40e_virtchnl_irq_map_info *)cmd_buffer;
623         map_info->num_vectors = 1;
624         map_info->vecmap[0].rxitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
625         map_info->vecmap[0].txitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
626         map_info->vecmap[0].vsi_id = vf->vsi_res->vsi_id;
627         /* Alway use default dynamic MSIX interrupt */
628         map_info->vecmap[0].vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR;
629         /* Don't map any tx queue */
630         map_info->vecmap[0].txq_map = 0;
631         map_info->vecmap[0].rxq_map = 0;
632         for (i = 0; i < dev->data->nb_rx_queues; i++)
633                 map_info->vecmap[0].rxq_map |= 1 << i;
634
635         args.ops = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
636         args.in_args = (u8 *)cmd_buffer;
637         args.in_args_size = sizeof(cmd_buffer);
638         args.out_buffer = cmd_result_buffer;
639         args.out_size = I40E_AQ_BUF_SZ;
640         err = i40evf_execute_vf_cmd(dev, &args);
641         if (err)
642                 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES");
643
644         return err;
645 }
646
647 static int
648 i40evf_switch_queue(struct rte_eth_dev *dev, bool isrx, uint16_t qid,
649                                 bool on)
650 {
651         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
652         struct i40e_virtchnl_queue_select queue_select;
653         int err;
654         struct vf_cmd_info args;
655         memset(&queue_select, 0, sizeof(queue_select));
656         queue_select.vsi_id = vf->vsi_res->vsi_id;
657
658         if (isrx)
659                 queue_select.rx_queues |= 1 << qid;
660         else
661                 queue_select.tx_queues |= 1 << qid;
662
663         if (on)
664                 args.ops = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
665         else
666                 args.ops = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
667         args.in_args = (u8 *)&queue_select;
668         args.in_args_size = sizeof(queue_select);
669         args.out_buffer = cmd_result_buffer;
670         args.out_size = I40E_AQ_BUF_SZ;
671         err = i40evf_execute_vf_cmd(dev, &args);
672         if (err)
673                 PMD_DRV_LOG(ERR, "fail to switch %s %u %s",
674                             isrx ? "RX" : "TX", qid, on ? "on" : "off");
675
676         return err;
677 }
678
679 static int
680 i40evf_start_queues(struct rte_eth_dev *dev)
681 {
682         struct rte_eth_dev_data *dev_data = dev->data;
683         int i;
684         struct i40e_rx_queue *rxq;
685         struct i40e_tx_queue *txq;
686
687         for (i = 0; i < dev->data->nb_rx_queues; i++) {
688                 rxq = dev_data->rx_queues[i];
689                 if (rxq->rx_deferred_start)
690                         continue;
691                 if (i40evf_dev_rx_queue_start(dev, i) != 0) {
692                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
693                         return -1;
694                 }
695         }
696
697         for (i = 0; i < dev->data->nb_tx_queues; i++) {
698                 txq = dev_data->tx_queues[i];
699                 if (txq->tx_deferred_start)
700                         continue;
701                 if (i40evf_dev_tx_queue_start(dev, i) != 0) {
702                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
703                         return -1;
704                 }
705         }
706
707         return 0;
708 }
709
710 static int
711 i40evf_stop_queues(struct rte_eth_dev *dev)
712 {
713         int i;
714
715         /* Stop TX queues first */
716         for (i = 0; i < dev->data->nb_tx_queues; i++) {
717                 if (i40evf_dev_tx_queue_stop(dev, i) != 0) {
718                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
719                         return -1;
720                 }
721         }
722
723         /* Then stop RX queues */
724         for (i = 0; i < dev->data->nb_rx_queues; i++) {
725                 if (i40evf_dev_rx_queue_stop(dev, i) != 0) {
726                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
727                         return -1;
728                 }
729         }
730
731         return 0;
732 }
733
734 static int
735 i40evf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
736 {
737         struct i40e_virtchnl_ether_addr_list *list;
738         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
739         uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
740                         sizeof(struct i40e_virtchnl_ether_addr)];
741         int err;
742         struct vf_cmd_info args;
743
744         if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
745                 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
746                             addr->addr_bytes[0], addr->addr_bytes[1],
747                             addr->addr_bytes[2], addr->addr_bytes[3],
748                             addr->addr_bytes[4], addr->addr_bytes[5]);
749                 return -1;
750         }
751
752         list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
753         list->vsi_id = vf->vsi_res->vsi_id;
754         list->num_elements = 1;
755         (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
756                                         sizeof(addr->addr_bytes));
757
758         args.ops = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
759         args.in_args = cmd_buffer;
760         args.in_args_size = sizeof(cmd_buffer);
761         args.out_buffer = cmd_result_buffer;
762         args.out_size = I40E_AQ_BUF_SZ;
763         err = i40evf_execute_vf_cmd(dev, &args);
764         if (err)
765                 PMD_DRV_LOG(ERR, "fail to execute command "
766                             "OP_ADD_ETHER_ADDRESS");
767
768         return err;
769 }
770
771 static int
772 i40evf_del_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
773 {
774         struct i40e_virtchnl_ether_addr_list *list;
775         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
776         uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
777                         sizeof(struct i40e_virtchnl_ether_addr)];
778         int err;
779         struct vf_cmd_info args;
780
781         if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
782                 PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x",
783                             addr->addr_bytes[0], addr->addr_bytes[1],
784                             addr->addr_bytes[2], addr->addr_bytes[3],
785                             addr->addr_bytes[4], addr->addr_bytes[5]);
786                 return -1;
787         }
788
789         list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
790         list->vsi_id = vf->vsi_res->vsi_id;
791         list->num_elements = 1;
792         (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
793                         sizeof(addr->addr_bytes));
794
795         args.ops = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
796         args.in_args = cmd_buffer;
797         args.in_args_size = sizeof(cmd_buffer);
798         args.out_buffer = cmd_result_buffer;
799         args.out_size = I40E_AQ_BUF_SZ;
800         err = i40evf_execute_vf_cmd(dev, &args);
801         if (err)
802                 PMD_DRV_LOG(ERR, "fail to execute command "
803                             "OP_DEL_ETHER_ADDRESS");
804
805         return err;
806 }
807
808 static int
809 i40evf_get_statics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
810 {
811         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
812         struct i40e_virtchnl_queue_select q_stats;
813         struct i40e_eth_stats *pstats;
814         int err;
815         struct vf_cmd_info args;
816
817         memset(&q_stats, 0, sizeof(q_stats));
818         q_stats.vsi_id = vf->vsi_res->vsi_id;
819         args.ops = I40E_VIRTCHNL_OP_GET_STATS;
820         args.in_args = (u8 *)&q_stats;
821         args.in_args_size = sizeof(q_stats);
822         args.out_buffer = cmd_result_buffer;
823         args.out_size = I40E_AQ_BUF_SZ;
824
825         err = i40evf_execute_vf_cmd(dev, &args);
826         if (err) {
827                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
828                 return err;
829         }
830         pstats = (struct i40e_eth_stats *)args.out_buffer;
831         stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
832                                                 pstats->rx_broadcast;
833         stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
834                                                 pstats->tx_unicast;
835         stats->ierrors = pstats->rx_discards;
836         stats->oerrors = pstats->tx_errors + pstats->tx_discards;
837         stats->ibytes = pstats->rx_bytes;
838         stats->obytes = pstats->tx_bytes;
839
840         return 0;
841 }
842
843 static int
844 i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
845 {
846         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
847         struct i40e_virtchnl_vlan_filter_list *vlan_list;
848         uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
849                                                         sizeof(uint16_t)];
850         int err;
851         struct vf_cmd_info args;
852
853         vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
854         vlan_list->vsi_id = vf->vsi_res->vsi_id;
855         vlan_list->num_elements = 1;
856         vlan_list->vlan_id[0] = vlanid;
857
858         args.ops = I40E_VIRTCHNL_OP_ADD_VLAN;
859         args.in_args = (u8 *)&cmd_buffer;
860         args.in_args_size = sizeof(cmd_buffer);
861         args.out_buffer = cmd_result_buffer;
862         args.out_size = I40E_AQ_BUF_SZ;
863         err = i40evf_execute_vf_cmd(dev, &args);
864         if (err)
865                 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN");
866
867         return err;
868 }
869
870 static int
871 i40evf_del_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
872 {
873         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
874         struct i40e_virtchnl_vlan_filter_list *vlan_list;
875         uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
876                                                         sizeof(uint16_t)];
877         int err;
878         struct vf_cmd_info args;
879
880         vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
881         vlan_list->vsi_id = vf->vsi_res->vsi_id;
882         vlan_list->num_elements = 1;
883         vlan_list->vlan_id[0] = vlanid;
884
885         args.ops = I40E_VIRTCHNL_OP_DEL_VLAN;
886         args.in_args = (u8 *)&cmd_buffer;
887         args.in_args_size = sizeof(cmd_buffer);
888         args.out_buffer = cmd_result_buffer;
889         args.out_size = I40E_AQ_BUF_SZ;
890         err = i40evf_execute_vf_cmd(dev, &args);
891         if (err)
892                 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_VLAN");
893
894         return err;
895 }
896
897 static int
898 i40evf_get_link_status(struct rte_eth_dev *dev, struct rte_eth_link *link)
899 {
900         int err;
901         struct vf_cmd_info args;
902         struct rte_eth_link *new_link;
903
904         args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_GET_LINK_STAT;
905         args.in_args = NULL;
906         args.in_args_size = 0;
907         args.out_buffer = cmd_result_buffer;
908         args.out_size = I40E_AQ_BUF_SZ;
909         err = i40evf_execute_vf_cmd(dev, &args);
910         if (err) {
911                 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_LINK_STAT");
912                 return err;
913         }
914
915         new_link = (struct rte_eth_link *)args.out_buffer;
916         (void)rte_memcpy(link, new_link, sizeof(*link));
917
918         return 0;
919 }
920
921 static struct rte_pci_id pci_id_i40evf_map[] = {
922 #define RTE_PCI_DEV_ID_DECL_I40EVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
923 #include "rte_pci_dev_ids.h"
924 { .vendor_id = 0, /* sentinel */ },
925 };
926
927 static inline int
928 i40evf_dev_atomic_write_link_status(struct rte_eth_dev *dev,
929                                     struct rte_eth_link *link)
930 {
931         struct rte_eth_link *dst = &(dev->data->dev_link);
932         struct rte_eth_link *src = link;
933
934         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
935                                         *(uint64_t *)src) == 0)
936                 return -1;
937
938         return 0;
939 }
940
941 static int
942 i40evf_reset_vf(struct i40e_hw *hw)
943 {
944         int i, reset;
945
946         if (i40e_vf_reset(hw) != I40E_SUCCESS) {
947                 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
948                 return -1;
949         }
950         /**
951           * After issuing vf reset command to pf, pf won't necessarily
952           * reset vf, it depends on what state it exactly is. If it's not
953           * initialized yet, it won't have vf reset since it's in a certain
954           * state. If not, it will try to reset. Even vf is reset, pf will
955           * set I40E_VFGEN_RSTAT to COMPLETE first, then wait 10ms and set
956           * it to ACTIVE. In this duration, vf may not catch the moment that
957           * COMPLETE is set. So, for vf, we'll try to wait a long time.
958           */
959         rte_delay_ms(200);
960
961         for (i = 0; i < MAX_RESET_WAIT_CNT; i++) {
962                 reset = rd32(hw, I40E_VFGEN_RSTAT) &
963                         I40E_VFGEN_RSTAT_VFR_STATE_MASK;
964                 reset = reset >> I40E_VFGEN_RSTAT_VFR_STATE_SHIFT;
965                 if (I40E_VFR_COMPLETED == reset || I40E_VFR_VFACTIVE == reset)
966                         break;
967                 else
968                         rte_delay_ms(50);
969         }
970
971         if (i >= MAX_RESET_WAIT_CNT) {
972                 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
973                 return -1;
974         }
975
976         return 0;
977 }
978
979 static int
980 i40evf_init_vf(struct rte_eth_dev *dev)
981 {
982         int i, err, bufsz;
983         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
984         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
985
986         vf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
987         vf->dev_data = dev->data;
988         err = i40evf_set_mac_type(hw);
989         if (err) {
990                 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
991                 goto err;
992         }
993
994         i40e_init_adminq_parameter(hw);
995         err = i40e_init_adminq(hw);
996         if (err) {
997                 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
998                 goto err;
999         }
1000
1001
1002         /* Reset VF and wait until it's complete */
1003         if (i40evf_reset_vf(hw)) {
1004                 PMD_INIT_LOG(ERR, "reset NIC failed");
1005                 goto err_aq;
1006         }
1007
1008         /* VF reset, shutdown admin queue and initialize again */
1009         if (i40e_shutdown_adminq(hw) != I40E_SUCCESS) {
1010                 PMD_INIT_LOG(ERR, "i40e_shutdown_adminq failed");
1011                 return -1;
1012         }
1013
1014         i40e_init_adminq_parameter(hw);
1015         if (i40e_init_adminq(hw) != I40E_SUCCESS) {
1016                 PMD_INIT_LOG(ERR, "init_adminq failed");
1017                 return -1;
1018         }
1019         if (i40evf_check_api_version(dev) != 0) {
1020                 PMD_INIT_LOG(ERR, "check_api version failed");
1021                 goto err_aq;
1022         }
1023         bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
1024                 (I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource));
1025         vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1026         if (!vf->vf_res) {
1027                 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1028                         goto err_aq;
1029         }
1030
1031         if (i40evf_get_vf_resource(dev) != 0) {
1032                 PMD_INIT_LOG(ERR, "i40evf_get_vf_config failed");
1033                 goto err_alloc;
1034         }
1035
1036         /* got VF config message back from PF, now we can parse it */
1037         for (i = 0; i < vf->vf_res->num_vsis; i++) {
1038                 if (vf->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
1039                         vf->vsi_res = &vf->vf_res->vsi_res[i];
1040         }
1041
1042         if (!vf->vsi_res) {
1043                 PMD_INIT_LOG(ERR, "no LAN VSI found");
1044                 goto err_alloc;
1045         }
1046
1047         vf->vsi.vsi_id = vf->vsi_res->vsi_id;
1048         vf->vsi.type = vf->vsi_res->vsi_type;
1049         vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
1050
1051         /* check mac addr, if it's not valid, genrate one */
1052         if (I40E_SUCCESS != i40e_validate_mac_addr(\
1053                         vf->vsi_res->default_mac_addr))
1054                 eth_random_addr(vf->vsi_res->default_mac_addr);
1055
1056         ether_addr_copy((struct ether_addr *)vf->vsi_res->default_mac_addr,
1057                                         (struct ether_addr *)hw->mac.addr);
1058
1059         return 0;
1060
1061 err_alloc:
1062         rte_free(vf->vf_res);
1063 err_aq:
1064         i40e_shutdown_adminq(hw); /* ignore error */
1065 err:
1066         return -1;
1067 }
1068
1069 static int
1070 i40evf_dev_init(__rte_unused struct eth_driver *eth_drv,
1071                 struct rte_eth_dev *eth_dev)
1072 {
1073         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
1074                         eth_dev->data->dev_private);
1075
1076         PMD_INIT_FUNC_TRACE();
1077
1078         /* assign ops func pointer */
1079         eth_dev->dev_ops = &i40evf_eth_dev_ops;
1080         eth_dev->rx_pkt_burst = &i40e_recv_pkts;
1081         eth_dev->tx_pkt_burst = &i40e_xmit_pkts;
1082
1083         /*
1084          * For secondary processes, we don't initialise any further as primary
1085          * has already done this work.
1086          */
1087         if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1088                 if (eth_dev->data->scattered_rx)
1089                         eth_dev->rx_pkt_burst = i40e_recv_scattered_pkts;
1090                 return 0;
1091         }
1092
1093         hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
1094         hw->device_id = eth_dev->pci_dev->id.device_id;
1095         hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
1096         hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
1097         hw->bus.device = eth_dev->pci_dev->addr.devid;
1098         hw->bus.func = eth_dev->pci_dev->addr.function;
1099         hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
1100
1101         if(i40evf_init_vf(eth_dev) != 0) {
1102                 PMD_INIT_LOG(ERR, "Init vf failed");
1103                 return -1;
1104         }
1105
1106         /* copy mac addr */
1107         eth_dev->data->mac_addrs = rte_zmalloc("i40evf_mac",
1108                                         ETHER_ADDR_LEN, 0);
1109         if (eth_dev->data->mac_addrs == NULL) {
1110                 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
1111                                 "store MAC addresses", ETHER_ADDR_LEN);
1112                 return -ENOMEM;
1113         }
1114         ether_addr_copy((struct ether_addr *)hw->mac.addr,
1115                 (struct ether_addr *)eth_dev->data->mac_addrs);
1116
1117         return 0;
1118 }
1119
1120 /*
1121  * virtual function driver struct
1122  */
1123 static struct eth_driver rte_i40evf_pmd = {
1124         {
1125                 .name = "rte_i40evf_pmd",
1126                 .id_table = pci_id_i40evf_map,
1127                 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1128         },
1129         .eth_dev_init = i40evf_dev_init,
1130         .dev_private_size = sizeof(struct i40e_vf),
1131 };
1132
1133 /*
1134  * VF Driver initialization routine.
1135  * Invoked one at EAL init time.
1136  * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
1137  */
1138 static int
1139 rte_i40evf_pmd_init(const char *name __rte_unused,
1140                     const char *params __rte_unused)
1141 {
1142         PMD_INIT_FUNC_TRACE();
1143
1144         rte_eth_driver_register(&rte_i40evf_pmd);
1145
1146         return 0;
1147 }
1148
1149 static struct rte_driver rte_i40evf_driver = {
1150         .type = PMD_PDEV,
1151         .init = rte_i40evf_pmd_init,
1152 };
1153
1154 PMD_REGISTER_DRIVER(rte_i40evf_driver);
1155
1156 static int
1157 i40evf_dev_configure(struct rte_eth_dev *dev)
1158 {
1159         return i40evf_init_vlan(dev);
1160 }
1161
1162 static int
1163 i40evf_init_vlan(struct rte_eth_dev *dev)
1164 {
1165         struct rte_eth_dev_data *data = dev->data;
1166         int ret;
1167
1168         /* Apply vlan offload setting */
1169         i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
1170
1171         /* Apply pvid setting */
1172         ret = i40evf_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
1173                                 data->dev_conf.txmode.hw_vlan_insert_pvid);
1174         return ret;
1175 }
1176
1177 static void
1178 i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1179 {
1180         bool enable_vlan_strip = 0;
1181         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1182         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1183
1184         /* Linux pf host doesn't support vlan offload yet */
1185         if (vf->host_is_dpdk) {
1186                 /* Vlan stripping setting */
1187                 if (mask & ETH_VLAN_STRIP_MASK) {
1188                         /* Enable or disable VLAN stripping */
1189                         if (dev_conf->rxmode.hw_vlan_strip)
1190                                 enable_vlan_strip = 1;
1191                         else
1192                                 enable_vlan_strip = 0;
1193
1194                         i40evf_config_vlan_offload(dev, enable_vlan_strip);
1195                 }
1196         }
1197 }
1198
1199 static int
1200 i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1201 {
1202         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1203         struct i40e_vsi_vlan_pvid_info info;
1204         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1205
1206         memset(&info, 0, sizeof(info));
1207         info.on = on;
1208
1209         /* Linux pf host don't support vlan offload yet */
1210         if (vf->host_is_dpdk) {
1211                 if (info.on)
1212                         info.config.pvid = pvid;
1213                 else {
1214                         info.config.reject.tagged =
1215                                 dev_conf->txmode.hw_vlan_reject_tagged;
1216                         info.config.reject.untagged =
1217                                 dev_conf->txmode.hw_vlan_reject_untagged;
1218                 }
1219                 return i40evf_config_vlan_pvid(dev, &info);
1220         }
1221
1222         return 0;
1223 }
1224
1225 static int
1226 i40evf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1227 {
1228         struct i40e_rx_queue *rxq;
1229         int err = 0;
1230         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1231
1232         PMD_INIT_FUNC_TRACE();
1233
1234         if (rx_queue_id < dev->data->nb_rx_queues) {
1235                 rxq = dev->data->rx_queues[rx_queue_id];
1236
1237                 err = i40e_alloc_rx_queue_mbufs(rxq);
1238                 if (err) {
1239                         PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1240                         return err;
1241                 }
1242
1243                 rte_wmb();
1244
1245                 /* Init the RX tail register. */
1246                 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1247                 I40EVF_WRITE_FLUSH(hw);
1248
1249                 /* Ready to switch the queue on */
1250                 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, TRUE);
1251
1252                 if (err)
1253                         PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1254                                     rx_queue_id);
1255         }
1256
1257         return err;
1258 }
1259
1260 static int
1261 i40evf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1262 {
1263         struct i40e_rx_queue *rxq;
1264         int err;
1265
1266         if (rx_queue_id < dev->data->nb_rx_queues) {
1267                 rxq = dev->data->rx_queues[rx_queue_id];
1268
1269                 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, FALSE);
1270
1271                 if (err) {
1272                         PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1273                                     rx_queue_id);
1274                         return err;
1275                 }
1276
1277                 i40e_rx_queue_release_mbufs(rxq);
1278                 i40e_reset_rx_queue(rxq);
1279         }
1280
1281         return 0;
1282 }
1283
1284 static int
1285 i40evf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1286 {
1287         int err = 0;
1288
1289         PMD_INIT_FUNC_TRACE();
1290
1291         if (tx_queue_id < dev->data->nb_tx_queues) {
1292
1293                 /* Ready to switch the queue on */
1294                 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, TRUE);
1295
1296                 if (err)
1297                         PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1298                                     tx_queue_id);
1299         }
1300
1301         return err;
1302 }
1303
1304 static int
1305 i40evf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1306 {
1307         struct i40e_tx_queue *txq;
1308         int err;
1309
1310         if (tx_queue_id < dev->data->nb_tx_queues) {
1311                 txq = dev->data->tx_queues[tx_queue_id];
1312
1313                 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, FALSE);
1314
1315                 if (err) {
1316                         PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1317                                     tx_queue_id);
1318                         return err;
1319                 }
1320
1321                 i40e_tx_queue_release_mbufs(txq);
1322                 i40e_reset_tx_queue(txq);
1323         }
1324
1325         return 0;
1326 }
1327
1328 static int
1329 i40evf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1330 {
1331         int ret;
1332
1333         if (on)
1334                 ret = i40evf_add_vlan(dev, vlan_id);
1335         else
1336                 ret = i40evf_del_vlan(dev,vlan_id);
1337
1338         return ret;
1339 }
1340
1341 static int
1342 i40evf_rx_init(struct rte_eth_dev *dev)
1343 {
1344         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1345         uint16_t i;
1346         struct i40e_rx_queue **rxq =
1347                 (struct i40e_rx_queue **)dev->data->rx_queues;
1348         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1349
1350         i40evf_config_rss(vf);
1351         for (i = 0; i < dev->data->nb_rx_queues; i++) {
1352                 rxq[i]->qrx_tail = hw->hw_addr + I40E_QRX_TAIL1(i);
1353                 I40E_PCI_REG_WRITE(rxq[i]->qrx_tail, rxq[i]->nb_rx_desc - 1);
1354         }
1355
1356         /* Flush the operation to write registers */
1357         I40EVF_WRITE_FLUSH(hw);
1358
1359         return 0;
1360 }
1361
1362 static void
1363 i40evf_tx_init(struct rte_eth_dev *dev)
1364 {
1365         uint16_t i;
1366         struct i40e_tx_queue **txq =
1367                 (struct i40e_tx_queue **)dev->data->tx_queues;
1368         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1369
1370         for (i = 0; i < dev->data->nb_tx_queues; i++)
1371                 txq[i]->qtx_tail = hw->hw_addr + I40E_QTX_TAIL1(i);
1372 }
1373
1374 static inline void
1375 i40evf_enable_queues_intr(struct i40e_hw *hw)
1376 {
1377         I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1378                         I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1379                         I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
1380 }
1381
1382 static inline void
1383 i40evf_disable_queues_intr(struct i40e_hw *hw)
1384 {
1385         I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1386                         0);
1387 }
1388
1389 static int
1390 i40evf_dev_start(struct rte_eth_dev *dev)
1391 {
1392         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1393         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1394         struct ether_addr mac_addr;
1395
1396         PMD_INIT_FUNC_TRACE();
1397
1398         vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1399         if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
1400                 if (vf->max_pkt_len <= ETHER_MAX_LEN ||
1401                         vf->max_pkt_len > I40E_FRAME_SIZE_MAX) {
1402                         PMD_DRV_LOG(ERR, "maximum packet length must "
1403                                     "be larger than %u and smaller than %u,"
1404                                     "as jumbo frame is enabled",
1405                                     (uint32_t)ETHER_MAX_LEN,
1406                                     (uint32_t)I40E_FRAME_SIZE_MAX);
1407                         return I40E_ERR_CONFIG;
1408                 }
1409         } else {
1410                 if (vf->max_pkt_len < ETHER_MIN_LEN ||
1411                         vf->max_pkt_len > ETHER_MAX_LEN) {
1412                         PMD_DRV_LOG(ERR, "maximum packet length must be "
1413                                     "larger than %u and smaller than %u, "
1414                                     "as jumbo frame is disabled",
1415                                     (uint32_t)ETHER_MIN_LEN,
1416                                     (uint32_t)ETHER_MAX_LEN);
1417                         return I40E_ERR_CONFIG;
1418                 }
1419         }
1420
1421         vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
1422                                         dev->data->nb_tx_queues);
1423
1424         if (i40evf_rx_init(dev) != 0){
1425                 PMD_DRV_LOG(ERR, "failed to do RX init");
1426                 return -1;
1427         }
1428
1429         i40evf_tx_init(dev);
1430
1431         if (i40evf_configure_queues(dev) != 0) {
1432                 PMD_DRV_LOG(ERR, "configure queues failed");
1433                 goto err_queue;
1434         }
1435         if (i40evf_config_irq_map(dev)) {
1436                 PMD_DRV_LOG(ERR, "config_irq_map failed");
1437                 goto err_queue;
1438         }
1439
1440         /* Set mac addr */
1441         (void)rte_memcpy(mac_addr.addr_bytes, hw->mac.addr,
1442                                 sizeof(mac_addr.addr_bytes));
1443         if (i40evf_add_mac_addr(dev, &mac_addr)) {
1444                 PMD_DRV_LOG(ERR, "Failed to add mac addr");
1445                 goto err_queue;
1446         }
1447
1448         if (i40evf_start_queues(dev) != 0) {
1449                 PMD_DRV_LOG(ERR, "enable queues failed");
1450                 goto err_mac;
1451         }
1452
1453         i40evf_enable_queues_intr(hw);
1454         return 0;
1455
1456 err_mac:
1457         i40evf_del_mac_addr(dev, &mac_addr);
1458 err_queue:
1459         return -1;
1460 }
1461
1462 static void
1463 i40evf_dev_stop(struct rte_eth_dev *dev)
1464 {
1465         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1466
1467         PMD_INIT_FUNC_TRACE();
1468
1469         i40evf_disable_queues_intr(hw);
1470         i40evf_stop_queues(dev);
1471 }
1472
1473 static int
1474 i40evf_dev_link_update(struct rte_eth_dev *dev,
1475                        __rte_unused int wait_to_complete)
1476 {
1477         struct rte_eth_link new_link;
1478         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1479         /*
1480          * DPDK pf host provide interfacet to acquire link status
1481          * while Linux driver does not
1482          */
1483         if (vf->host_is_dpdk)
1484                 i40evf_get_link_status(dev, &new_link);
1485         else {
1486                 /* Always assume it's up, for Linux driver PF host */
1487                 new_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1488                 new_link.link_speed  = ETH_LINK_SPEED_10000;
1489                 new_link.link_status = 1;
1490         }
1491         i40evf_dev_atomic_write_link_status(dev, &new_link);
1492
1493         return 0;
1494 }
1495
1496 static void
1497 i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1498 {
1499         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1500         int ret;
1501
1502         /* If enabled, just return */
1503         if (vf->promisc_unicast_enabled)
1504                 return;
1505
1506         ret = i40evf_config_promisc(dev, 1, vf->promisc_multicast_enabled);
1507         if (ret == 0)
1508                 vf->promisc_unicast_enabled = TRUE;
1509 }
1510
1511 static void
1512 i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1513 {
1514         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1515         int ret;
1516
1517         /* If disabled, just return */
1518         if (!vf->promisc_unicast_enabled)
1519                 return;
1520
1521         ret = i40evf_config_promisc(dev, 0, vf->promisc_multicast_enabled);
1522         if (ret == 0)
1523                 vf->promisc_unicast_enabled = FALSE;
1524 }
1525
1526 static void
1527 i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1528 {
1529         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1530         int ret;
1531
1532         /* If enabled, just return */
1533         if (vf->promisc_multicast_enabled)
1534                 return;
1535
1536         ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 1);
1537         if (ret == 0)
1538                 vf->promisc_multicast_enabled = TRUE;
1539 }
1540
1541 static void
1542 i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1543 {
1544         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1545         int ret;
1546
1547         /* If enabled, just return */
1548         if (!vf->promisc_multicast_enabled)
1549                 return;
1550
1551         ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 0);
1552         if (ret == 0)
1553                 vf->promisc_multicast_enabled = FALSE;
1554 }
1555
1556 static void
1557 i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1558 {
1559         struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1560
1561         memset(dev_info, 0, sizeof(*dev_info));
1562         dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
1563         dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
1564         dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
1565         dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
1566 }
1567
1568 static void
1569 i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1570 {
1571         memset(stats, 0, sizeof(*stats));
1572         if (i40evf_get_statics(dev, stats))
1573                 PMD_DRV_LOG(ERR, "Get statics failed");
1574 }
1575
1576 static void
1577 i40evf_dev_close(struct rte_eth_dev *dev)
1578 {
1579         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1580
1581         i40evf_dev_stop(dev);
1582         i40evf_reset_vf(hw);
1583         i40e_shutdown_adminq(hw);
1584 }
1585
1586 static int
1587 i40evf_hw_rss_hash_set(struct i40e_hw *hw, struct rte_eth_rss_conf *rss_conf)
1588 {
1589         uint32_t *hash_key;
1590         uint8_t hash_key_len;
1591         uint64_t rss_hf, hena;
1592
1593         hash_key = (uint32_t *)(rss_conf->rss_key);
1594         hash_key_len = rss_conf->rss_key_len;
1595         if (hash_key != NULL && hash_key_len >=
1596                 (I40E_VFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
1597                 uint16_t i;
1598
1599                 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1600                         I40E_WRITE_REG(hw, I40E_VFQF_HKEY(i), hash_key[i]);
1601         }
1602
1603         rss_hf = rss_conf->rss_hf;
1604         hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1605         hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1606         hena &= ~I40E_RSS_HENA_ALL;
1607         hena |= i40e_config_hena(rss_hf);
1608         I40E_WRITE_REG(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
1609         I40E_WRITE_REG(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
1610         I40EVF_WRITE_FLUSH(hw);
1611
1612         return 0;
1613 }
1614
1615 static void
1616 i40evf_disable_rss(struct i40e_vf *vf)
1617 {
1618         struct i40e_hw *hw = I40E_VF_TO_HW(vf);
1619         uint64_t hena;
1620
1621         hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1622         hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1623         hena &= ~I40E_RSS_HENA_ALL;
1624         I40E_WRITE_REG(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
1625         I40E_WRITE_REG(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
1626         I40EVF_WRITE_FLUSH(hw);
1627 }
1628
1629 static int
1630 i40evf_config_rss(struct i40e_vf *vf)
1631 {
1632         struct i40e_hw *hw = I40E_VF_TO_HW(vf);
1633         struct rte_eth_rss_conf rss_conf;
1634         uint32_t i, j, lut = 0, nb_q = (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
1635
1636         if (vf->dev_data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
1637                 i40evf_disable_rss(vf);
1638                 PMD_DRV_LOG(DEBUG, "RSS not configured\n");
1639                 return 0;
1640         }
1641
1642         /* Fill out the look up table */
1643         for (i = 0, j = 0; i < nb_q; i++, j++) {
1644                 if (j >= vf->num_queue_pairs)
1645                         j = 0;
1646                 lut = (lut << 8) | j;
1647                 if ((i & 3) == 3)
1648                         I40E_WRITE_REG(hw, I40E_VFQF_HLUT(i >> 2), lut);
1649         }
1650
1651         rss_conf = vf->dev_data->dev_conf.rx_adv_conf.rss_conf;
1652         if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
1653                 i40evf_disable_rss(vf);
1654                 PMD_DRV_LOG(DEBUG, "No hash flag is set\n");
1655                 return 0;
1656         }
1657
1658         if (rss_conf.rss_key == NULL || rss_conf.rss_key_len < nb_q) {
1659                 /* Calculate the default hash key */
1660                 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1661                         rss_key_default[i] = (uint32_t)rte_rand();
1662                 rss_conf.rss_key = (uint8_t *)rss_key_default;
1663                 rss_conf.rss_key_len = nb_q;
1664         }
1665
1666         return i40evf_hw_rss_hash_set(hw, &rss_conf);
1667 }
1668
1669 static int
1670 i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
1671                            struct rte_eth_rss_conf *rss_conf)
1672 {
1673         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1674         uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
1675         uint64_t hena;
1676
1677         hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1678         hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1679         if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
1680                 if (rss_hf != 0) /* Enable RSS */
1681                         return -EINVAL;
1682                 return 0;
1683         }
1684
1685         /* RSS enabled */
1686         if (rss_hf == 0) /* Disable RSS */
1687                 return -EINVAL;
1688
1689         return i40evf_hw_rss_hash_set(hw, rss_conf);
1690 }
1691
1692 static int
1693 i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1694                              struct rte_eth_rss_conf *rss_conf)
1695 {
1696         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1697         uint32_t *hash_key = (uint32_t *)(rss_conf->rss_key);
1698         uint64_t hena;
1699         uint16_t i;
1700
1701         if (hash_key) {
1702                 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1703                         hash_key[i] = I40E_READ_REG(hw, I40E_VFQF_HKEY(i));
1704                 rss_conf->rss_key_len = i * sizeof(uint32_t);
1705         }
1706         hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1707         hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1708         rss_conf->rss_hf = i40e_parse_hena(hena);
1709
1710         return 0;
1711 }