net/iavf: fix adding multicast MAC address
[dpdk.git] / drivers / net / iavf / iavf_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include <sys/queue.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12 #include <inttypes.h>
13 #include <rte_byteorder.h>
14 #include <rte_common.h>
15
16 #include <rte_interrupts.h>
17 #include <rte_debug.h>
18 #include <rte_pci.h>
19 #include <rte_atomic.h>
20 #include <rte_eal.h>
21 #include <rte_ether.h>
22 #include <rte_ethdev_driver.h>
23 #include <rte_ethdev_pci.h>
24 #include <rte_malloc.h>
25 #include <rte_memzone.h>
26 #include <rte_dev.h>
27
28 #include "iavf.h"
29 #include "iavf_rxtx.h"
30 #include "iavf_generic_flow.h"
31
32 static int iavf_dev_configure(struct rte_eth_dev *dev);
33 static int iavf_dev_start(struct rte_eth_dev *dev);
34 static int iavf_dev_stop(struct rte_eth_dev *dev);
35 static int iavf_dev_close(struct rte_eth_dev *dev);
36 static int iavf_dev_reset(struct rte_eth_dev *dev);
37 static int iavf_dev_info_get(struct rte_eth_dev *dev,
38                              struct rte_eth_dev_info *dev_info);
39 static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev);
40 static int iavf_dev_stats_get(struct rte_eth_dev *dev,
41                              struct rte_eth_stats *stats);
42 static int iavf_dev_stats_reset(struct rte_eth_dev *dev);
43 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
44                                  struct rte_eth_xstat *xstats, unsigned int n);
45 static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev,
46                                        struct rte_eth_xstat_name *xstats_names,
47                                        unsigned int limit);
48 static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
49 static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
50 static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
51 static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
52 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
53                                 struct rte_ether_addr *addr,
54                                 uint32_t index,
55                                 uint32_t pool);
56 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
57 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
58                                    uint16_t vlan_id, int on);
59 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
60 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
61                                    struct rte_eth_rss_reta_entry64 *reta_conf,
62                                    uint16_t reta_size);
63 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
64                                   struct rte_eth_rss_reta_entry64 *reta_conf,
65                                   uint16_t reta_size);
66 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
67                                    struct rte_eth_rss_conf *rss_conf);
68 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
69                                      struct rte_eth_rss_conf *rss_conf);
70 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
71 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
72                                          struct rte_ether_addr *mac_addr);
73 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
74                                         uint16_t queue_id);
75 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
76                                          uint16_t queue_id);
77 static int iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
78                      enum rte_filter_type filter_type,
79                      enum rte_filter_op filter_op,
80                      void *arg);
81 static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
82                         struct rte_ether_addr *mc_addrs,
83                         uint32_t mc_addrs_num);
84
85 static const struct rte_pci_id pci_id_iavf_map[] = {
86         { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
87         { .vendor_id = 0, /* sentinel */ },
88 };
89
90 struct rte_iavf_xstats_name_off {
91         char name[RTE_ETH_XSTATS_NAME_SIZE];
92         unsigned int offset;
93 };
94
95 static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = {
96         {"rx_bytes", offsetof(struct iavf_eth_stats, rx_bytes)},
97         {"rx_unicast_packets", offsetof(struct iavf_eth_stats, rx_unicast)},
98         {"rx_multicast_packets", offsetof(struct iavf_eth_stats, rx_multicast)},
99         {"rx_broadcast_packets", offsetof(struct iavf_eth_stats, rx_broadcast)},
100         {"rx_dropped_packets", offsetof(struct iavf_eth_stats, rx_discards)},
101         {"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats,
102                 rx_unknown_protocol)},
103         {"tx_bytes", offsetof(struct iavf_eth_stats, tx_bytes)},
104         {"tx_unicast_packets", offsetof(struct iavf_eth_stats, tx_unicast)},
105         {"tx_multicast_packets", offsetof(struct iavf_eth_stats, tx_multicast)},
106         {"tx_broadcast_packets", offsetof(struct iavf_eth_stats, tx_broadcast)},
107         {"tx_dropped_packets", offsetof(struct iavf_eth_stats, tx_discards)},
108         {"tx_error_packets", offsetof(struct iavf_eth_stats, tx_errors)},
109 };
110
111 #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
112                 sizeof(rte_iavf_stats_strings[0]))
113
114 static const struct eth_dev_ops iavf_eth_dev_ops = {
115         .dev_configure              = iavf_dev_configure,
116         .dev_start                  = iavf_dev_start,
117         .dev_stop                   = iavf_dev_stop,
118         .dev_close                  = iavf_dev_close,
119         .dev_reset                  = iavf_dev_reset,
120         .dev_infos_get              = iavf_dev_info_get,
121         .dev_supported_ptypes_get   = iavf_dev_supported_ptypes_get,
122         .link_update                = iavf_dev_link_update,
123         .stats_get                  = iavf_dev_stats_get,
124         .stats_reset                = iavf_dev_stats_reset,
125         .xstats_get                 = iavf_dev_xstats_get,
126         .xstats_get_names           = iavf_dev_xstats_get_names,
127         .xstats_reset               = iavf_dev_stats_reset,
128         .promiscuous_enable         = iavf_dev_promiscuous_enable,
129         .promiscuous_disable        = iavf_dev_promiscuous_disable,
130         .allmulticast_enable        = iavf_dev_allmulticast_enable,
131         .allmulticast_disable       = iavf_dev_allmulticast_disable,
132         .mac_addr_add               = iavf_dev_add_mac_addr,
133         .mac_addr_remove            = iavf_dev_del_mac_addr,
134         .set_mc_addr_list                       = iavf_set_mc_addr_list,
135         .vlan_filter_set            = iavf_dev_vlan_filter_set,
136         .vlan_offload_set           = iavf_dev_vlan_offload_set,
137         .rx_queue_start             = iavf_dev_rx_queue_start,
138         .rx_queue_stop              = iavf_dev_rx_queue_stop,
139         .tx_queue_start             = iavf_dev_tx_queue_start,
140         .tx_queue_stop              = iavf_dev_tx_queue_stop,
141         .rx_queue_setup             = iavf_dev_rx_queue_setup,
142         .rx_queue_release           = iavf_dev_rx_queue_release,
143         .tx_queue_setup             = iavf_dev_tx_queue_setup,
144         .tx_queue_release           = iavf_dev_tx_queue_release,
145         .mac_addr_set               = iavf_dev_set_default_mac_addr,
146         .reta_update                = iavf_dev_rss_reta_update,
147         .reta_query                 = iavf_dev_rss_reta_query,
148         .rss_hash_update            = iavf_dev_rss_hash_update,
149         .rss_hash_conf_get          = iavf_dev_rss_hash_conf_get,
150         .rxq_info_get               = iavf_dev_rxq_info_get,
151         .txq_info_get               = iavf_dev_txq_info_get,
152         .mtu_set                    = iavf_dev_mtu_set,
153         .rx_queue_intr_enable       = iavf_dev_rx_queue_intr_enable,
154         .rx_queue_intr_disable      = iavf_dev_rx_queue_intr_disable,
155         .filter_ctrl                = iavf_dev_filter_ctrl,
156         .tx_done_cleanup            = iavf_dev_tx_done_cleanup,
157 };
158
159 static int
160 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
161                         struct rte_ether_addr *mc_addrs,
162                         uint32_t mc_addrs_num)
163 {
164         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
165         struct iavf_adapter *adapter =
166                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
167         int err, ret;
168
169         if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
170                 PMD_DRV_LOG(ERR,
171                             "can't add more than a limited number (%u) of addresses.",
172                             (uint32_t)IAVF_NUM_MACADDR_MAX);
173                 return -EINVAL;
174         }
175
176         /* flush previous addresses */
177         err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
178                                         false);
179         if (err)
180                 return err;
181
182         /* add new ones */
183         err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
184
185         if (err) {
186                 /* if adding mac address list fails, should add the previous
187                  * addresses back.
188                  */
189                 ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
190                                                 vf->mc_addrs_num, true);
191                 if (ret)
192                         return ret;
193         } else {
194                 vf->mc_addrs_num = mc_addrs_num;
195                 memcpy(vf->mc_addrs,
196                        mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
197         }
198
199         return err;
200 }
201
202 static int
203 iavf_init_rss(struct iavf_adapter *adapter)
204 {
205         struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(adapter);
206         struct rte_eth_rss_conf *rss_conf;
207         uint16_t i, j, nb_q;
208         int ret;
209
210         rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
211         nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
212                        IAVF_MAX_NUM_QUEUES);
213
214         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
215                 PMD_DRV_LOG(DEBUG, "RSS is not supported");
216                 return -ENOTSUP;
217         }
218         if (adapter->eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
219                 PMD_DRV_LOG(WARNING, "RSS is enabled by PF by default");
220                 /* set all lut items to default queue */
221                 for (i = 0; i < vf->vf_res->rss_lut_size; i++)
222                         vf->rss_lut[i] = 0;
223                 ret = iavf_configure_rss_lut(adapter);
224                 return ret;
225         }
226
227         /* In IAVF, RSS enablement is set by PF driver. It is not supported
228          * to set based on rss_conf->rss_hf.
229          */
230
231         /* configure RSS key */
232         if (!rss_conf->rss_key) {
233                 /* Calculate the default hash key */
234                 for (i = 0; i <= vf->vf_res->rss_key_size; i++)
235                         vf->rss_key[i] = (uint8_t)rte_rand();
236         } else
237                 rte_memcpy(vf->rss_key, rss_conf->rss_key,
238                            RTE_MIN(rss_conf->rss_key_len,
239                                    vf->vf_res->rss_key_size));
240
241         /* init RSS LUT table */
242         for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
243                 if (j >= nb_q)
244                         j = 0;
245                 vf->rss_lut[i] = j;
246         }
247         /* send virtchnnl ops to configure rss*/
248         ret = iavf_configure_rss_lut(adapter);
249         if (ret)
250                 return ret;
251         ret = iavf_configure_rss_key(adapter);
252         if (ret)
253                 return ret;
254
255         return 0;
256 }
257
258 static int
259 iavf_dev_configure(struct rte_eth_dev *dev)
260 {
261         struct iavf_adapter *ad =
262                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
263         struct iavf_info *vf =  IAVF_DEV_PRIVATE_TO_VF(ad);
264         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
265
266         ad->rx_bulk_alloc_allowed = true;
267         /* Initialize to TRUE. If any of Rx queues doesn't meet the
268          * vector Rx/Tx preconditions, it will be reset.
269          */
270         ad->rx_vec_allowed = true;
271         ad->tx_vec_allowed = true;
272
273         if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
274                 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
275
276         /* Vlan stripping setting */
277         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
278                 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
279                         iavf_enable_vlan_strip(ad);
280                 else
281                         iavf_disable_vlan_strip(ad);
282         }
283
284         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
285                 if (iavf_init_rss(ad) != 0) {
286                         PMD_DRV_LOG(ERR, "configure rss failed");
287                         return -1;
288                 }
289         }
290         return 0;
291 }
292
293 static int
294 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
295 {
296         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
297         struct rte_eth_dev_data *dev_data = dev->data;
298         uint16_t buf_size, max_pkt_len, len;
299
300         buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
301
302         /* Calculate the maximum packet length allowed */
303         len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
304         max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
305
306         /* Check if the jumbo frame and maximum packet length are set
307          * correctly.
308          */
309         if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
310                 if (max_pkt_len <= RTE_ETHER_MAX_LEN ||
311                     max_pkt_len > IAVF_FRAME_SIZE_MAX) {
312                         PMD_DRV_LOG(ERR, "maximum packet length must be "
313                                     "larger than %u and smaller than %u, "
314                                     "as jumbo frame is enabled",
315                                     (uint32_t)RTE_ETHER_MAX_LEN,
316                                     (uint32_t)IAVF_FRAME_SIZE_MAX);
317                         return -EINVAL;
318                 }
319         } else {
320                 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
321                     max_pkt_len > RTE_ETHER_MAX_LEN) {
322                         PMD_DRV_LOG(ERR, "maximum packet length must be "
323                                     "larger than %u and smaller than %u, "
324                                     "as jumbo frame is disabled",
325                                     (uint32_t)RTE_ETHER_MIN_LEN,
326                                     (uint32_t)RTE_ETHER_MAX_LEN);
327                         return -EINVAL;
328                 }
329         }
330
331         rxq->max_pkt_len = max_pkt_len;
332         if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
333             rxq->max_pkt_len > buf_size) {
334                 dev_data->scattered_rx = 1;
335         }
336         IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
337         IAVF_WRITE_FLUSH(hw);
338
339         return 0;
340 }
341
342 static int
343 iavf_init_queues(struct rte_eth_dev *dev)
344 {
345         struct iavf_rx_queue **rxq =
346                 (struct iavf_rx_queue **)dev->data->rx_queues;
347         int i, ret = IAVF_SUCCESS;
348
349         for (i = 0; i < dev->data->nb_rx_queues; i++) {
350                 if (!rxq[i] || !rxq[i]->q_set)
351                         continue;
352                 ret = iavf_init_rxq(dev, rxq[i]);
353                 if (ret != IAVF_SUCCESS)
354                         break;
355         }
356         /* set rx/tx function to vector/scatter/single-segment
357          * according to parameters
358          */
359         iavf_set_rx_function(dev);
360         iavf_set_tx_function(dev);
361
362         return ret;
363 }
364
365 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
366                                      struct rte_intr_handle *intr_handle)
367 {
368         struct iavf_adapter *adapter =
369                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
370         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
371         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
372         uint16_t interval, i;
373         int vec;
374
375         if (rte_intr_cap_multiple(intr_handle) &&
376             dev->data->dev_conf.intr_conf.rxq) {
377                 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
378                         return -1;
379         }
380
381         if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
382                 intr_handle->intr_vec =
383                         rte_zmalloc("intr_vec",
384                                     dev->data->nb_rx_queues * sizeof(int), 0);
385                 if (!intr_handle->intr_vec) {
386                         PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
387                                     dev->data->nb_rx_queues);
388                         return -1;
389                 }
390         }
391
392         if (!dev->data->dev_conf.intr_conf.rxq ||
393             !rte_intr_dp_is_en(intr_handle)) {
394                 /* Rx interrupt disabled, Map interrupt only for writeback */
395                 vf->nb_msix = 1;
396                 if (vf->vf_res->vf_cap_flags &
397                     VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
398                         /* If WB_ON_ITR supports, enable it */
399                         vf->msix_base = IAVF_RX_VEC_START;
400                         IAVF_WRITE_REG(hw,
401                                        IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
402                                        IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK |
403                                        IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK);
404                 } else {
405                         /* If no WB_ON_ITR offload flags, need to set
406                          * interrupt for descriptor write back.
407                          */
408                         vf->msix_base = IAVF_MISC_VEC_ID;
409
410                         /* set ITR to max */
411                         interval = iavf_calc_itr_interval(
412                                         IAVF_QUEUE_ITR_INTERVAL_MAX);
413                         IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
414                                        IAVF_VFINT_DYN_CTL01_INTENA_MASK |
415                                        (IAVF_ITR_INDEX_DEFAULT <<
416                                         IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
417                                        (interval <<
418                                         IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
419                 }
420                 IAVF_WRITE_FLUSH(hw);
421                 /* map all queues to the same interrupt */
422                 for (i = 0; i < dev->data->nb_rx_queues; i++)
423                         vf->rxq_map[vf->msix_base] |= 1 << i;
424         } else {
425                 if (!rte_intr_allow_others(intr_handle)) {
426                         vf->nb_msix = 1;
427                         vf->msix_base = IAVF_MISC_VEC_ID;
428                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
429                                 vf->rxq_map[vf->msix_base] |= 1 << i;
430                                 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
431                         }
432                         PMD_DRV_LOG(DEBUG,
433                                     "vector %u are mapping to all Rx queues",
434                                     vf->msix_base);
435                 } else {
436                         /* If Rx interrupt is reuquired, and we can use
437                          * multi interrupts, then the vec is from 1
438                          */
439                         vf->nb_msix = RTE_MIN(vf->vf_res->max_vectors,
440                                               intr_handle->nb_efd);
441                         vf->msix_base = IAVF_RX_VEC_START;
442                         vec = IAVF_RX_VEC_START;
443                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
444                                 vf->rxq_map[vec] |= 1 << i;
445                                 intr_handle->intr_vec[i] = vec++;
446                                 if (vec >= vf->nb_msix)
447                                         vec = IAVF_RX_VEC_START;
448                         }
449                         PMD_DRV_LOG(DEBUG,
450                                     "%u vectors are mapping to %u Rx queues",
451                                     vf->nb_msix, dev->data->nb_rx_queues);
452                 }
453         }
454
455         if (iavf_config_irq_map(adapter)) {
456                 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
457                 return -1;
458         }
459         return 0;
460 }
461
462 static int
463 iavf_start_queues(struct rte_eth_dev *dev)
464 {
465         struct iavf_rx_queue *rxq;
466         struct iavf_tx_queue *txq;
467         int i;
468
469         for (i = 0; i < dev->data->nb_tx_queues; i++) {
470                 txq = dev->data->tx_queues[i];
471                 if (txq->tx_deferred_start)
472                         continue;
473                 if (iavf_dev_tx_queue_start(dev, i) != 0) {
474                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
475                         return -1;
476                 }
477         }
478
479         for (i = 0; i < dev->data->nb_rx_queues; i++) {
480                 rxq = dev->data->rx_queues[i];
481                 if (rxq->rx_deferred_start)
482                         continue;
483                 if (iavf_dev_rx_queue_start(dev, i) != 0) {
484                         PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
485                         return -1;
486                 }
487         }
488
489         return 0;
490 }
491
492 static int
493 iavf_dev_start(struct rte_eth_dev *dev)
494 {
495         struct iavf_adapter *adapter =
496                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
497         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
498         struct rte_intr_handle *intr_handle = dev->intr_handle;
499
500         PMD_INIT_FUNC_TRACE();
501
502         adapter->stopped = 0;
503
504         vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
505         vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
506                                       dev->data->nb_tx_queues);
507
508         if (iavf_init_queues(dev) != 0) {
509                 PMD_DRV_LOG(ERR, "failed to do Queue init");
510                 return -1;
511         }
512
513         if (iavf_configure_queues(adapter) != 0) {
514                 PMD_DRV_LOG(ERR, "configure queues failed");
515                 goto err_queue;
516         }
517
518         if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
519                 PMD_DRV_LOG(ERR, "configure irq failed");
520                 goto err_queue;
521         }
522         /* re-enable intr again, because efd assign may change */
523         if (dev->data->dev_conf.intr_conf.rxq != 0) {
524                 rte_intr_disable(intr_handle);
525                 rte_intr_enable(intr_handle);
526         }
527
528         /* Set all mac addrs */
529         iavf_add_del_all_mac_addr(adapter, true);
530
531         /* Set all multicast addresses */
532         iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
533                                   true);
534
535         if (iavf_start_queues(dev) != 0) {
536                 PMD_DRV_LOG(ERR, "enable queues failed");
537                 goto err_mac;
538         }
539
540         return 0;
541
542 err_mac:
543         iavf_add_del_all_mac_addr(adapter, false);
544 err_queue:
545         return -1;
546 }
547
548 static int
549 iavf_dev_stop(struct rte_eth_dev *dev)
550 {
551         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
552         struct iavf_adapter *adapter =
553                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
554         struct rte_intr_handle *intr_handle = dev->intr_handle;
555
556         PMD_INIT_FUNC_TRACE();
557
558         if (adapter->stopped == 1)
559                 return 0;
560
561         iavf_stop_queues(dev);
562
563         /* Disable the interrupt for Rx */
564         rte_intr_efd_disable(intr_handle);
565         /* Rx interrupt vector mapping free */
566         if (intr_handle->intr_vec) {
567                 rte_free(intr_handle->intr_vec);
568                 intr_handle->intr_vec = NULL;
569         }
570
571         /* remove all mac addrs */
572         iavf_add_del_all_mac_addr(adapter, false);
573
574         /* remove all multicast addresses */
575         iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
576                                   false);
577
578         adapter->stopped = 1;
579         dev->data->dev_started = 0;
580
581         return 0;
582 }
583
584 static int
585 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
586 {
587         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
588
589         dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
590         dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
591         dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
592         dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
593         dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
594         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
595         dev_info->hash_key_size = vf->vf_res->rss_key_size;
596         dev_info->reta_size = vf->vf_res->rss_lut_size;
597         dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
598         dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
599         dev_info->rx_offload_capa =
600                 DEV_RX_OFFLOAD_VLAN_STRIP |
601                 DEV_RX_OFFLOAD_QINQ_STRIP |
602                 DEV_RX_OFFLOAD_IPV4_CKSUM |
603                 DEV_RX_OFFLOAD_UDP_CKSUM |
604                 DEV_RX_OFFLOAD_TCP_CKSUM |
605                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
606                 DEV_RX_OFFLOAD_SCATTER |
607                 DEV_RX_OFFLOAD_JUMBO_FRAME |
608                 DEV_RX_OFFLOAD_VLAN_FILTER |
609                 DEV_RX_OFFLOAD_RSS_HASH;
610         dev_info->tx_offload_capa =
611                 DEV_TX_OFFLOAD_VLAN_INSERT |
612                 DEV_TX_OFFLOAD_QINQ_INSERT |
613                 DEV_TX_OFFLOAD_IPV4_CKSUM |
614                 DEV_TX_OFFLOAD_UDP_CKSUM |
615                 DEV_TX_OFFLOAD_TCP_CKSUM |
616                 DEV_TX_OFFLOAD_SCTP_CKSUM |
617                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
618                 DEV_TX_OFFLOAD_TCP_TSO |
619                 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
620                 DEV_TX_OFFLOAD_GRE_TNL_TSO |
621                 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
622                 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
623                 DEV_TX_OFFLOAD_MULTI_SEGS;
624
625         dev_info->default_rxconf = (struct rte_eth_rxconf) {
626                 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
627                 .rx_drop_en = 0,
628                 .offloads = 0,
629         };
630
631         dev_info->default_txconf = (struct rte_eth_txconf) {
632                 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
633                 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
634                 .offloads = 0,
635         };
636
637         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
638                 .nb_max = IAVF_MAX_RING_DESC,
639                 .nb_min = IAVF_MIN_RING_DESC,
640                 .nb_align = IAVF_ALIGN_RING_DESC,
641         };
642
643         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
644                 .nb_max = IAVF_MAX_RING_DESC,
645                 .nb_min = IAVF_MIN_RING_DESC,
646                 .nb_align = IAVF_ALIGN_RING_DESC,
647         };
648
649         return 0;
650 }
651
652 static const uint32_t *
653 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
654 {
655         static const uint32_t ptypes[] = {
656                 RTE_PTYPE_L2_ETHER,
657                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
658                 RTE_PTYPE_L4_FRAG,
659                 RTE_PTYPE_L4_ICMP,
660                 RTE_PTYPE_L4_NONFRAG,
661                 RTE_PTYPE_L4_SCTP,
662                 RTE_PTYPE_L4_TCP,
663                 RTE_PTYPE_L4_UDP,
664                 RTE_PTYPE_UNKNOWN
665         };
666         return ptypes;
667 }
668
669 int
670 iavf_dev_link_update(struct rte_eth_dev *dev,
671                     __rte_unused int wait_to_complete)
672 {
673         struct rte_eth_link new_link;
674         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
675
676         memset(&new_link, 0, sizeof(new_link));
677
678         /* Only read status info stored in VF, and the info is updated
679          *  when receive LINK_CHANGE evnet from PF by Virtchnnl.
680          */
681         switch (vf->link_speed) {
682         case 10:
683                 new_link.link_speed = ETH_SPEED_NUM_10M;
684                 break;
685         case 100:
686                 new_link.link_speed = ETH_SPEED_NUM_100M;
687                 break;
688         case 1000:
689                 new_link.link_speed = ETH_SPEED_NUM_1G;
690                 break;
691         case 10000:
692                 new_link.link_speed = ETH_SPEED_NUM_10G;
693                 break;
694         case 20000:
695                 new_link.link_speed = ETH_SPEED_NUM_20G;
696                 break;
697         case 25000:
698                 new_link.link_speed = ETH_SPEED_NUM_25G;
699                 break;
700         case 40000:
701                 new_link.link_speed = ETH_SPEED_NUM_40G;
702                 break;
703         case 50000:
704                 new_link.link_speed = ETH_SPEED_NUM_50G;
705                 break;
706         case 100000:
707                 new_link.link_speed = ETH_SPEED_NUM_100G;
708                 break;
709         default:
710                 new_link.link_speed = ETH_SPEED_NUM_NONE;
711                 break;
712         }
713
714         new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
715         new_link.link_status = vf->link_up ? ETH_LINK_UP :
716                                              ETH_LINK_DOWN;
717         new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
718                                 ETH_LINK_SPEED_FIXED);
719
720         return rte_eth_linkstatus_set(dev, &new_link);
721 }
722
723 static int
724 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
725 {
726         struct iavf_adapter *adapter =
727                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
728         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
729
730         return iavf_config_promisc(adapter,
731                                   true, vf->promisc_multicast_enabled);
732 }
733
734 static int
735 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
736 {
737         struct iavf_adapter *adapter =
738                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
739         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
740
741         return iavf_config_promisc(adapter,
742                                   false, vf->promisc_multicast_enabled);
743 }
744
745 static int
746 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
747 {
748         struct iavf_adapter *adapter =
749                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
750         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
751
752         return iavf_config_promisc(adapter,
753                                   vf->promisc_unicast_enabled, true);
754 }
755
756 static int
757 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
758 {
759         struct iavf_adapter *adapter =
760                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
761         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
762
763         return iavf_config_promisc(adapter,
764                                   vf->promisc_unicast_enabled, false);
765 }
766
767 static int
768 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
769                      __rte_unused uint32_t index,
770                      __rte_unused uint32_t pool)
771 {
772         struct iavf_adapter *adapter =
773                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
774         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
775         int err;
776
777         if (rte_is_zero_ether_addr(addr)) {
778                 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
779                 return -EINVAL;
780         }
781
782         err = iavf_add_del_eth_addr(adapter, addr, true);
783         if (err) {
784                 PMD_DRV_LOG(ERR, "fail to add MAC address");
785                 return -EIO;
786         }
787
788         vf->mac_num++;
789
790         return 0;
791 }
792
793 static void
794 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
795 {
796         struct iavf_adapter *adapter =
797                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
798         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
799         struct rte_ether_addr *addr;
800         int err;
801
802         addr = &dev->data->mac_addrs[index];
803
804         err = iavf_add_del_eth_addr(adapter, addr, false);
805         if (err)
806                 PMD_DRV_LOG(ERR, "fail to delete MAC address");
807
808         vf->mac_num--;
809 }
810
811 static int
812 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
813 {
814         struct iavf_adapter *adapter =
815                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
816         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
817         int err;
818
819         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
820                 return -ENOTSUP;
821
822         err = iavf_add_del_vlan(adapter, vlan_id, on);
823         if (err)
824                 return -EIO;
825         return 0;
826 }
827
828 static int
829 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
830 {
831         struct iavf_adapter *adapter =
832                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
833         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
834         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
835         int err;
836
837         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
838                 return -ENOTSUP;
839
840         /* Vlan stripping setting */
841         if (mask & ETH_VLAN_STRIP_MASK) {
842                 /* Enable or disable VLAN stripping */
843                 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
844                         err = iavf_enable_vlan_strip(adapter);
845                 else
846                         err = iavf_disable_vlan_strip(adapter);
847
848                 if (err)
849                         return -EIO;
850         }
851         return 0;
852 }
853
854 static int
855 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
856                         struct rte_eth_rss_reta_entry64 *reta_conf,
857                         uint16_t reta_size)
858 {
859         struct iavf_adapter *adapter =
860                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
861         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
862         uint8_t *lut;
863         uint16_t i, idx, shift;
864         int ret;
865
866         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
867                 return -ENOTSUP;
868
869         if (reta_size != vf->vf_res->rss_lut_size) {
870                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
871                         "(%d) doesn't match the number of hardware can "
872                         "support (%d)", reta_size, vf->vf_res->rss_lut_size);
873                 return -EINVAL;
874         }
875
876         lut = rte_zmalloc("rss_lut", reta_size, 0);
877         if (!lut) {
878                 PMD_DRV_LOG(ERR, "No memory can be allocated");
879                 return -ENOMEM;
880         }
881         /* store the old lut table temporarily */
882         rte_memcpy(lut, vf->rss_lut, reta_size);
883
884         for (i = 0; i < reta_size; i++) {
885                 idx = i / RTE_RETA_GROUP_SIZE;
886                 shift = i % RTE_RETA_GROUP_SIZE;
887                 if (reta_conf[idx].mask & (1ULL << shift))
888                         lut[i] = reta_conf[idx].reta[shift];
889         }
890
891         rte_memcpy(vf->rss_lut, lut, reta_size);
892         /* send virtchnnl ops to configure rss*/
893         ret = iavf_configure_rss_lut(adapter);
894         if (ret) /* revert back */
895                 rte_memcpy(vf->rss_lut, lut, reta_size);
896         rte_free(lut);
897
898         return ret;
899 }
900
901 static int
902 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
903                        struct rte_eth_rss_reta_entry64 *reta_conf,
904                        uint16_t reta_size)
905 {
906         struct iavf_adapter *adapter =
907                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
908         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
909         uint16_t i, idx, shift;
910
911         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
912                 return -ENOTSUP;
913
914         if (reta_size != vf->vf_res->rss_lut_size) {
915                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
916                         "(%d) doesn't match the number of hardware can "
917                         "support (%d)", reta_size, vf->vf_res->rss_lut_size);
918                 return -EINVAL;
919         }
920
921         for (i = 0; i < reta_size; i++) {
922                 idx = i / RTE_RETA_GROUP_SIZE;
923                 shift = i % RTE_RETA_GROUP_SIZE;
924                 if (reta_conf[idx].mask & (1ULL << shift))
925                         reta_conf[idx].reta[shift] = vf->rss_lut[i];
926         }
927
928         return 0;
929 }
930
931 static int
932 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
933                         struct rte_eth_rss_conf *rss_conf)
934 {
935         struct iavf_adapter *adapter =
936                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
937         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
938
939         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
940                 return -ENOTSUP;
941
942         /* HENA setting, it is enabled by default, no change */
943         if (!rss_conf->rss_key || rss_conf->rss_key_len == 0) {
944                 PMD_DRV_LOG(DEBUG, "No key to be configured");
945                 return 0;
946         } else if (rss_conf->rss_key_len != vf->vf_res->rss_key_size) {
947                 PMD_DRV_LOG(ERR, "The size of hash key configured "
948                         "(%d) doesn't match the size of hardware can "
949                         "support (%d)", rss_conf->rss_key_len,
950                         vf->vf_res->rss_key_size);
951                 return -EINVAL;
952         }
953
954         rte_memcpy(vf->rss_key, rss_conf->rss_key, rss_conf->rss_key_len);
955
956         return iavf_configure_rss_key(adapter);
957 }
958
959 static int
960 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
961                           struct rte_eth_rss_conf *rss_conf)
962 {
963         struct iavf_adapter *adapter =
964                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
965         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
966
967         if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
968                 return -ENOTSUP;
969
970          /* Just set it to default value now. */
971         rss_conf->rss_hf = IAVF_RSS_OFFLOAD_ALL;
972
973         if (!rss_conf->rss_key)
974                 return 0;
975
976         rss_conf->rss_key_len = vf->vf_res->rss_key_size;
977         rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
978
979         return 0;
980 }
981
982 static int
983 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
984 {
985         uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
986         int ret = 0;
987
988         if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
989                 return -EINVAL;
990
991         /* mtu setting is forbidden if port is start */
992         if (dev->data->dev_started) {
993                 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
994                 return -EBUSY;
995         }
996
997         if (frame_size > RTE_ETHER_MAX_LEN)
998                 dev->data->dev_conf.rxmode.offloads |=
999                                 DEV_RX_OFFLOAD_JUMBO_FRAME;
1000         else
1001                 dev->data->dev_conf.rxmode.offloads &=
1002                                 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1003
1004         dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1005
1006         return ret;
1007 }
1008
1009 static int
1010 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1011                              struct rte_ether_addr *mac_addr)
1012 {
1013         struct iavf_adapter *adapter =
1014                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1015         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1016         struct rte_ether_addr *perm_addr, *old_addr;
1017         int ret;
1018
1019         old_addr = (struct rte_ether_addr *)hw->mac.addr;
1020         perm_addr = (struct rte_ether_addr *)hw->mac.perm_addr;
1021
1022         /* If the MAC address is configured by host, skip the setting */
1023         if (rte_is_valid_assigned_ether_addr(perm_addr))
1024                 return -EPERM;
1025
1026         ret = iavf_add_del_eth_addr(adapter, old_addr, false);
1027         if (ret)
1028                 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1029                             " %02X:%02X:%02X:%02X:%02X:%02X",
1030                             old_addr->addr_bytes[0],
1031                             old_addr->addr_bytes[1],
1032                             old_addr->addr_bytes[2],
1033                             old_addr->addr_bytes[3],
1034                             old_addr->addr_bytes[4],
1035                             old_addr->addr_bytes[5]);
1036
1037         ret = iavf_add_del_eth_addr(adapter, mac_addr, true);
1038         if (ret)
1039                 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1040                             " %02X:%02X:%02X:%02X:%02X:%02X",
1041                             mac_addr->addr_bytes[0],
1042                             mac_addr->addr_bytes[1],
1043                             mac_addr->addr_bytes[2],
1044                             mac_addr->addr_bytes[3],
1045                             mac_addr->addr_bytes[4],
1046                             mac_addr->addr_bytes[5]);
1047
1048         if (ret)
1049                 return -EIO;
1050
1051         rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1052         return 0;
1053 }
1054
1055 static void
1056 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1057 {
1058         if (*stat >= *offset)
1059                 *stat = *stat - *offset;
1060         else
1061                 *stat = (uint64_t)((*stat +
1062                         ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1063
1064         *stat &= IAVF_48_BIT_MASK;
1065 }
1066
1067 static void
1068 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1069 {
1070         if (*stat >= *offset)
1071                 *stat = (uint64_t)(*stat - *offset);
1072         else
1073                 *stat = (uint64_t)((*stat +
1074                         ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1075 }
1076
1077 static void
1078 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1079 {
1080         struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1081
1082         iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1083         iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1084         iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1085         iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1086         iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1087         iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1088         iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1089         iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1090         iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1091         iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1092         iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1093 }
1094
1095 static int
1096 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1097 {
1098         struct iavf_adapter *adapter =
1099                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1100         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1101         struct iavf_vsi *vsi = &vf->vsi;
1102         struct virtchnl_eth_stats *pstats = NULL;
1103         int ret;
1104
1105         ret = iavf_query_stats(adapter, &pstats);
1106         if (ret == 0) {
1107                 iavf_update_stats(vsi, pstats);
1108                 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1109                                 pstats->rx_broadcast - pstats->rx_discards;
1110                 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1111                                                 pstats->tx_unicast;
1112                 stats->imissed = pstats->rx_discards;
1113                 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1114                 stats->ibytes = pstats->rx_bytes;
1115                 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
1116                 stats->obytes = pstats->tx_bytes;
1117         } else {
1118                 PMD_DRV_LOG(ERR, "Get statistics failed");
1119         }
1120         return ret;
1121 }
1122
1123 static int
1124 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1125 {
1126         int ret;
1127         struct iavf_adapter *adapter =
1128                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1129         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1130         struct iavf_vsi *vsi = &vf->vsi;
1131         struct virtchnl_eth_stats *pstats = NULL;
1132
1133         /* read stat values to clear hardware registers */
1134         ret = iavf_query_stats(adapter, &pstats);
1135         if (ret != 0)
1136                 return ret;
1137
1138         /* set stats offset base on current values */
1139         vsi->eth_stats_offset = *pstats;
1140
1141         return 0;
1142 }
1143
1144 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1145                                       struct rte_eth_xstat_name *xstats_names,
1146                                       __rte_unused unsigned int limit)
1147 {
1148         unsigned int i;
1149
1150         if (xstats_names != NULL)
1151                 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1152                         snprintf(xstats_names[i].name,
1153                                 sizeof(xstats_names[i].name),
1154                                 "%s", rte_iavf_stats_strings[i].name);
1155                 }
1156         return IAVF_NB_XSTATS;
1157 }
1158
1159 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1160                                  struct rte_eth_xstat *xstats, unsigned int n)
1161 {
1162         int ret;
1163         unsigned int i;
1164         struct iavf_adapter *adapter =
1165                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1166         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1167         struct iavf_vsi *vsi = &vf->vsi;
1168         struct virtchnl_eth_stats *pstats = NULL;
1169
1170         if (n < IAVF_NB_XSTATS)
1171                 return IAVF_NB_XSTATS;
1172
1173         ret = iavf_query_stats(adapter, &pstats);
1174         if (ret != 0)
1175                 return 0;
1176
1177         if (!xstats)
1178                 return 0;
1179
1180         iavf_update_stats(vsi, pstats);
1181
1182         /* loop over xstats array and values from pstats */
1183         for (i = 0; i < IAVF_NB_XSTATS; i++) {
1184                 xstats[i].id = i;
1185                 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1186                         rte_iavf_stats_strings[i].offset);
1187         }
1188
1189         return IAVF_NB_XSTATS;
1190 }
1191
1192
1193 static int
1194 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1195 {
1196         struct iavf_adapter *adapter =
1197                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1198         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1199         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1200         uint16_t msix_intr;
1201
1202         msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1203         if (msix_intr == IAVF_MISC_VEC_ID) {
1204                 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1205                 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1206                                IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1207                                IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1208                                IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1209         } else {
1210                 IAVF_WRITE_REG(hw,
1211                                IAVF_VFINT_DYN_CTLN1
1212                                 (msix_intr - IAVF_RX_VEC_START),
1213                                IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1214                                IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1215                                IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1216         }
1217
1218         IAVF_WRITE_FLUSH(hw);
1219
1220         rte_intr_ack(&pci_dev->intr_handle);
1221
1222         return 0;
1223 }
1224
1225 static int
1226 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1227 {
1228         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1229         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1230         uint16_t msix_intr;
1231
1232         msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1233         if (msix_intr == IAVF_MISC_VEC_ID) {
1234                 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1235                 return -EIO;
1236         }
1237
1238         IAVF_WRITE_REG(hw,
1239                       IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1240                       0);
1241
1242         IAVF_WRITE_FLUSH(hw);
1243         return 0;
1244 }
1245
1246 static int
1247 iavf_check_vf_reset_done(struct iavf_hw *hw)
1248 {
1249         int i, reset;
1250
1251         for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1252                 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1253                         IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1254                 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1255                 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1256                     reset == VIRTCHNL_VFR_COMPLETED)
1257                         break;
1258                 rte_delay_ms(20);
1259         }
1260
1261         if (i >= IAVF_RESET_WAIT_CNT)
1262                 return -1;
1263
1264         return 0;
1265 }
1266
1267 static int
1268 iavf_init_vf(struct rte_eth_dev *dev)
1269 {
1270         int err, bufsz;
1271         struct iavf_adapter *adapter =
1272                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1273         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1274         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1275
1276         err = iavf_set_mac_type(hw);
1277         if (err) {
1278                 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1279                 goto err;
1280         }
1281
1282         err = iavf_check_vf_reset_done(hw);
1283         if (err) {
1284                 PMD_INIT_LOG(ERR, "VF is still resetting");
1285                 goto err;
1286         }
1287
1288         iavf_init_adminq_parameter(hw);
1289         err = iavf_init_adminq(hw);
1290         if (err) {
1291                 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1292                 goto err;
1293         }
1294
1295         vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
1296         if (!vf->aq_resp) {
1297                 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1298                 goto err_aq;
1299         }
1300         if (iavf_check_api_version(adapter) != 0) {
1301                 PMD_INIT_LOG(ERR, "check_api version failed");
1302                 goto err_api;
1303         }
1304
1305         bufsz = sizeof(struct virtchnl_vf_resource) +
1306                 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1307         vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1308         if (!vf->vf_res) {
1309                 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1310                 goto err_api;
1311         }
1312         if (iavf_get_vf_resource(adapter) != 0) {
1313                 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
1314                 goto err_alloc;
1315         }
1316         /* Allocate memort for RSS info */
1317         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1318                 vf->rss_key = rte_zmalloc("rss_key",
1319                                           vf->vf_res->rss_key_size, 0);
1320                 if (!vf->rss_key) {
1321                         PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
1322                         goto err_rss;
1323                 }
1324                 vf->rss_lut = rte_zmalloc("rss_lut",
1325                                           vf->vf_res->rss_lut_size, 0);
1326                 if (!vf->rss_lut) {
1327                         PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
1328                         goto err_rss;
1329                 }
1330         }
1331
1332         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
1333                 if (iavf_get_supported_rxdid(adapter) != 0) {
1334                         PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
1335                         goto err_rss;
1336                 }
1337         }
1338
1339         return 0;
1340 err_rss:
1341         rte_free(vf->rss_key);
1342         rte_free(vf->rss_lut);
1343 err_alloc:
1344         rte_free(vf->vf_res);
1345         vf->vsi_res = NULL;
1346 err_api:
1347         rte_free(vf->aq_resp);
1348 err_aq:
1349         iavf_shutdown_adminq(hw);
1350 err:
1351         return -1;
1352 }
1353
1354 /* Enable default admin queue interrupt setting */
1355 static inline void
1356 iavf_enable_irq0(struct iavf_hw *hw)
1357 {
1358         /* Enable admin queue interrupt trigger */
1359         IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
1360                        IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
1361
1362         IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1363                        IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1364                        IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1365                        IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1366
1367         IAVF_WRITE_FLUSH(hw);
1368 }
1369
1370 static inline void
1371 iavf_disable_irq0(struct iavf_hw *hw)
1372 {
1373         /* Disable all interrupt types */
1374         IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
1375         IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1376                        IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1377         IAVF_WRITE_FLUSH(hw);
1378 }
1379
1380 static void
1381 iavf_dev_interrupt_handler(void *param)
1382 {
1383         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1384         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1385
1386         iavf_disable_irq0(hw);
1387
1388         iavf_handle_virtchnl_msg(dev);
1389
1390         iavf_enable_irq0(hw);
1391 }
1392
1393 static int
1394 iavf_dev_filter_ctrl(struct rte_eth_dev *dev,
1395                      enum rte_filter_type filter_type,
1396                      enum rte_filter_op filter_op,
1397                      void *arg)
1398 {
1399         int ret = 0;
1400
1401         if (!dev)
1402                 return -EINVAL;
1403
1404         switch (filter_type) {
1405         case RTE_ETH_FILTER_GENERIC:
1406                 if (filter_op != RTE_ETH_FILTER_GET)
1407                         return -EINVAL;
1408                 *(const void **)arg = &iavf_flow_ops;
1409                 break;
1410         default:
1411                 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1412                             filter_type);
1413                 ret = -EINVAL;
1414                 break;
1415         }
1416
1417         return ret;
1418 }
1419
1420
1421 static int
1422 iavf_dev_init(struct rte_eth_dev *eth_dev)
1423 {
1424         struct iavf_adapter *adapter =
1425                 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1426         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1427         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1428         int ret = 0;
1429
1430         PMD_INIT_FUNC_TRACE();
1431
1432         /* assign ops func pointer */
1433         eth_dev->dev_ops = &iavf_eth_dev_ops;
1434         eth_dev->rx_queue_count = iavf_dev_rxq_count;
1435         eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
1436         eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
1437         eth_dev->rx_pkt_burst = &iavf_recv_pkts;
1438         eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
1439         eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
1440
1441         /* For secondary processes, we don't initialise any further as primary
1442          * has already done this work. Only check if we need a different RX
1443          * and TX function.
1444          */
1445         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1446                 iavf_set_rx_function(eth_dev);
1447                 iavf_set_tx_function(eth_dev);
1448                 return 0;
1449         }
1450         rte_eth_copy_pci_info(eth_dev, pci_dev);
1451         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1452
1453         hw->vendor_id = pci_dev->id.vendor_id;
1454         hw->device_id = pci_dev->id.device_id;
1455         hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1456         hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1457         hw->bus.bus_id = pci_dev->addr.bus;
1458         hw->bus.device = pci_dev->addr.devid;
1459         hw->bus.func = pci_dev->addr.function;
1460         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1461         hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
1462         adapter->eth_dev = eth_dev;
1463         adapter->stopped = 1;
1464
1465         if (iavf_init_vf(eth_dev) != 0) {
1466                 PMD_INIT_LOG(ERR, "Init vf failed");
1467                 return -1;
1468         }
1469
1470         /* set default ptype table */
1471         adapter->ptype_tbl = iavf_get_default_ptype_table();
1472
1473         /* copy mac addr */
1474         eth_dev->data->mac_addrs = rte_zmalloc(
1475                 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
1476         if (!eth_dev->data->mac_addrs) {
1477                 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1478                              " store MAC addresses",
1479                              RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
1480                 return -ENOMEM;
1481         }
1482         /* If the MAC address is not configured by host,
1483          * generate a random one.
1484          */
1485         if (!rte_is_valid_assigned_ether_addr(
1486                         (struct rte_ether_addr *)hw->mac.addr))
1487                 rte_eth_random_addr(hw->mac.addr);
1488         rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1489                         &eth_dev->data->mac_addrs[0]);
1490
1491         /* register callback func to eal lib */
1492         rte_intr_callback_register(&pci_dev->intr_handle,
1493                                    iavf_dev_interrupt_handler,
1494                                    (void *)eth_dev);
1495
1496         /* enable uio intr after callback register */
1497         rte_intr_enable(&pci_dev->intr_handle);
1498
1499         /* configure and enable device interrupt */
1500         iavf_enable_irq0(hw);
1501
1502         ret = iavf_flow_init(adapter);
1503         if (ret) {
1504                 PMD_INIT_LOG(ERR, "Failed to initialize flow");
1505                 return ret;
1506         }
1507
1508         return 0;
1509 }
1510
1511 static int
1512 iavf_dev_close(struct rte_eth_dev *dev)
1513 {
1514         struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1515         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1516         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1517         struct iavf_adapter *adapter =
1518                 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1519         struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1520         int ret;
1521
1522         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1523                 return 0;
1524
1525         ret = iavf_dev_stop(dev);
1526
1527         iavf_flow_flush(dev, NULL);
1528         iavf_flow_uninit(adapter);
1529
1530         /*
1531          * disable promiscuous mode before reset vf
1532          * it is a workaround solution when work with kernel driver
1533          * and it is not the normal way
1534          */
1535         if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
1536                 iavf_config_promisc(adapter, false, false);
1537
1538         iavf_shutdown_adminq(hw);
1539         /* disable uio intr before callback unregister */
1540         rte_intr_disable(intr_handle);
1541
1542         /* unregister callback func from eal lib */
1543         rte_intr_callback_unregister(intr_handle,
1544                                      iavf_dev_interrupt_handler, dev);
1545         iavf_disable_irq0(hw);
1546
1547         if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1548                 if (vf->rss_lut) {
1549                         rte_free(vf->rss_lut);
1550                         vf->rss_lut = NULL;
1551                 }
1552                 if (vf->rss_key) {
1553                         rte_free(vf->rss_key);
1554                         vf->rss_key = NULL;
1555                 }
1556         }
1557
1558         rte_free(vf->vf_res);
1559         vf->vsi_res = NULL;
1560         vf->vf_res = NULL;
1561
1562         rte_free(vf->aq_resp);
1563         vf->aq_resp = NULL;
1564
1565         vf->vf_reset = false;
1566
1567         return ret;
1568 }
1569
1570 static int
1571 iavf_dev_uninit(struct rte_eth_dev *dev)
1572 {
1573         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1574                 return -EPERM;
1575
1576         iavf_dev_close(dev);
1577
1578         return 0;
1579 }
1580
1581 /*
1582  * Reset VF device only to re-initialize resources in PMD layer
1583  */
1584 static int
1585 iavf_dev_reset(struct rte_eth_dev *dev)
1586 {
1587         int ret;
1588
1589         ret = iavf_dev_uninit(dev);
1590         if (ret)
1591                 return ret;
1592
1593         return iavf_dev_init(dev);
1594 }
1595
1596 static int
1597 iavf_dcf_cap_check_handler(__rte_unused const char *key,
1598                            const char *value, __rte_unused void *opaque)
1599 {
1600         if (strcmp(value, "dcf"))
1601                 return -1;
1602
1603         return 0;
1604 }
1605
1606 static int
1607 iavf_dcf_cap_selected(struct rte_devargs *devargs)
1608 {
1609         struct rte_kvargs *kvlist;
1610         const char *key = "cap";
1611         int ret = 0;
1612
1613         if (devargs == NULL)
1614                 return 0;
1615
1616         kvlist = rte_kvargs_parse(devargs->args, NULL);
1617         if (kvlist == NULL)
1618                 return 0;
1619
1620         if (!rte_kvargs_count(kvlist, key))
1621                 goto exit;
1622
1623         /* dcf capability selected when there's a key-value pair: cap=dcf */
1624         if (rte_kvargs_process(kvlist, key,
1625                                iavf_dcf_cap_check_handler, NULL) < 0)
1626                 goto exit;
1627
1628         ret = 1;
1629
1630 exit:
1631         rte_kvargs_free(kvlist);
1632         return ret;
1633 }
1634
1635 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1636                              struct rte_pci_device *pci_dev)
1637 {
1638         if (iavf_dcf_cap_selected(pci_dev->device.devargs))
1639                 return 1;
1640
1641         return rte_eth_dev_pci_generic_probe(pci_dev,
1642                 sizeof(struct iavf_adapter), iavf_dev_init);
1643 }
1644
1645 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
1646 {
1647         return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
1648 }
1649
1650 /* Adaptive virtual function driver struct */
1651 static struct rte_pci_driver rte_iavf_pmd = {
1652         .id_table = pci_id_iavf_map,
1653         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1654         .probe = eth_iavf_pci_probe,
1655         .remove = eth_iavf_pci_remove,
1656 };
1657
1658 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
1659 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
1660 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
1661 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
1662 RTE_LOG_REGISTER(iavf_logtype_init, pmd.net.iavf.init, NOTICE);
1663 RTE_LOG_REGISTER(iavf_logtype_driver, pmd.net.iavf.driver, NOTICE);
1664 #ifdef RTE_LIBRTE_IAVF_DEBUG_RX
1665 RTE_LOG_REGISTER(iavf_logtype_rx, pmd.net.iavf.rx, DEBUG);
1666 #endif
1667 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX
1668 RTE_LOG_REGISTER(iavf_logtype_tx, pmd.net.iavf.tx, DEBUG);
1669 #endif
1670 #ifdef RTE_LIBRTE_IAVF_DEBUG_TX_FREE
1671 RTE_LOG_REGISTER(iavf_logtype_tx_free, pmd.net.iavf.tx_free, DEBUG);
1672 #endif