5132966d0023f8b398d3425b5973961ca6d5227f
[dpdk.git] / drivers / net / enic / enic_ethdev.c
1 /*
2  * Copyright 2008-2014 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #include <stdio.h>
36 #include <stdint.h>
37
38 #include <rte_dev.h>
39 #include <rte_pci.h>
40 #include <rte_bus_pci.h>
41 #include <rte_ethdev.h>
42 #include <rte_ethdev_pci.h>
43 #include <rte_string_fns.h>
44
45 #include "vnic_intr.h"
46 #include "vnic_cq.h"
47 #include "vnic_wq.h"
48 #include "vnic_rq.h"
49 #include "vnic_enet.h"
50 #include "enic.h"
51
52 int enicpmd_logtype_init;
53 int enicpmd_logtype_flow;
54
55 #define PMD_INIT_LOG(level, fmt, args...) \
56         rte_log(RTE_LOG_ ## level, enicpmd_logtype_init, \
57                 "%s" fmt "\n", __func__, ##args)
58
59 #define ENICPMD_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
60
61 /*
62  * The set of PCI devices this driver supports
63  */
64 #define CISCO_PCI_VENDOR_ID 0x1137
65 static const struct rte_pci_id pci_id_enic_map[] = {
66         { RTE_PCI_DEVICE(CISCO_PCI_VENDOR_ID, PCI_DEVICE_ID_CISCO_VIC_ENET) },
67         { RTE_PCI_DEVICE(CISCO_PCI_VENDOR_ID, PCI_DEVICE_ID_CISCO_VIC_ENET_VF) },
68         {.vendor_id = 0, /* sentinel */},
69 };
70
71 RTE_INIT(enicpmd_init_log);
72 static void
73 enicpmd_init_log(void)
74 {
75         enicpmd_logtype_init = rte_log_register("pmd.enic.init");
76         if (enicpmd_logtype_init >= 0)
77                 rte_log_set_level(enicpmd_logtype_init, RTE_LOG_NOTICE);
78         enicpmd_logtype_flow = rte_log_register("pmd.enic.flow");
79         if (enicpmd_logtype_flow >= 0)
80                 rte_log_set_level(enicpmd_logtype_flow, RTE_LOG_NOTICE);
81 }
82
83 static int
84 enicpmd_fdir_ctrl_func(struct rte_eth_dev *eth_dev,
85                         enum rte_filter_op filter_op, void *arg)
86 {
87         struct enic *enic = pmd_priv(eth_dev);
88         int ret = 0;
89
90         ENICPMD_FUNC_TRACE();
91         if (filter_op == RTE_ETH_FILTER_NOP)
92                 return 0;
93
94         if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
95                 return -EINVAL;
96
97         switch (filter_op) {
98         case RTE_ETH_FILTER_ADD:
99         case RTE_ETH_FILTER_UPDATE:
100                 ret = enic_fdir_add_fltr(enic,
101                         (struct rte_eth_fdir_filter *)arg);
102                 break;
103
104         case RTE_ETH_FILTER_DELETE:
105                 ret = enic_fdir_del_fltr(enic,
106                         (struct rte_eth_fdir_filter *)arg);
107                 break;
108
109         case RTE_ETH_FILTER_STATS:
110                 enic_fdir_stats_get(enic, (struct rte_eth_fdir_stats *)arg);
111                 break;
112
113         case RTE_ETH_FILTER_FLUSH:
114                 dev_warning(enic, "unsupported operation %u", filter_op);
115                 ret = -ENOTSUP;
116                 break;
117         case RTE_ETH_FILTER_INFO:
118                 enic_fdir_info_get(enic, (struct rte_eth_fdir_info *)arg);
119                 break;
120         default:
121                 dev_err(enic, "unknown operation %u", filter_op);
122                 ret = -EINVAL;
123                 break;
124         }
125         return ret;
126 }
127
128 static int
129 enicpmd_dev_filter_ctrl(struct rte_eth_dev *dev,
130                      enum rte_filter_type filter_type,
131                      enum rte_filter_op filter_op,
132                      void *arg)
133 {
134         int ret = 0;
135
136         ENICPMD_FUNC_TRACE();
137
138         switch (filter_type) {
139         case RTE_ETH_FILTER_GENERIC:
140                 if (filter_op != RTE_ETH_FILTER_GET)
141                         return -EINVAL;
142                 *(const void **)arg = &enic_flow_ops;
143                 break;
144         case RTE_ETH_FILTER_FDIR:
145                 ret = enicpmd_fdir_ctrl_func(dev, filter_op, arg);
146                 break;
147         default:
148                 dev_warning(enic, "Filter type (%d) not supported",
149                         filter_type);
150                 ret = -EINVAL;
151                 break;
152         }
153
154         return ret;
155 }
156
157 static void enicpmd_dev_tx_queue_release(void *txq)
158 {
159         ENICPMD_FUNC_TRACE();
160
161         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
162                 return;
163
164         enic_free_wq(txq);
165 }
166
167 static int enicpmd_dev_setup_intr(struct enic *enic)
168 {
169         int ret;
170         unsigned int index;
171
172         ENICPMD_FUNC_TRACE();
173
174         /* Are we done with the init of all the queues? */
175         for (index = 0; index < enic->cq_count; index++) {
176                 if (!enic->cq[index].ctrl)
177                         break;
178         }
179         if (enic->cq_count != index)
180                 return 0;
181         for (index = 0; index < enic->wq_count; index++) {
182                 if (!enic->wq[index].ctrl)
183                         break;
184         }
185         if (enic->wq_count != index)
186                 return 0;
187         /* check start of packet (SOP) RQs only in case scatter is disabled. */
188         for (index = 0; index < enic->rq_count; index++) {
189                 if (!enic->rq[enic_rte_rq_idx_to_sop_idx(index)].ctrl)
190                         break;
191         }
192         if (enic->rq_count != index)
193                 return 0;
194
195         ret = enic_alloc_intr_resources(enic);
196         if (ret) {
197                 dev_err(enic, "alloc intr failed\n");
198                 return ret;
199         }
200         enic_init_vnic_resources(enic);
201
202         ret = enic_setup_finish(enic);
203         if (ret)
204                 dev_err(enic, "setup could not be finished\n");
205
206         return ret;
207 }
208
209 static int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
210         uint16_t queue_idx,
211         uint16_t nb_desc,
212         unsigned int socket_id,
213         __rte_unused const struct rte_eth_txconf *tx_conf)
214 {
215         int ret;
216         struct enic *enic = pmd_priv(eth_dev);
217
218         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
219                 return -E_RTE_SECONDARY;
220
221         ENICPMD_FUNC_TRACE();
222         if (queue_idx >= ENIC_WQ_MAX) {
223                 dev_err(enic,
224                         "Max number of TX queues exceeded.  Max is %d\n",
225                         ENIC_WQ_MAX);
226                 return -EINVAL;
227         }
228
229         eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
230
231         ret = enic_alloc_wq(enic, queue_idx, socket_id, nb_desc);
232         if (ret) {
233                 dev_err(enic, "error in allocating wq\n");
234                 return ret;
235         }
236
237         return enicpmd_dev_setup_intr(enic);
238 }
239
240 static int enicpmd_dev_tx_queue_start(struct rte_eth_dev *eth_dev,
241         uint16_t queue_idx)
242 {
243         struct enic *enic = pmd_priv(eth_dev);
244
245         ENICPMD_FUNC_TRACE();
246
247         enic_start_wq(enic, queue_idx);
248
249         return 0;
250 }
251
252 static int enicpmd_dev_tx_queue_stop(struct rte_eth_dev *eth_dev,
253         uint16_t queue_idx)
254 {
255         int ret;
256         struct enic *enic = pmd_priv(eth_dev);
257
258         ENICPMD_FUNC_TRACE();
259
260         ret = enic_stop_wq(enic, queue_idx);
261         if (ret)
262                 dev_err(enic, "error in stopping wq %d\n", queue_idx);
263
264         return ret;
265 }
266
267 static int enicpmd_dev_rx_queue_start(struct rte_eth_dev *eth_dev,
268         uint16_t queue_idx)
269 {
270         struct enic *enic = pmd_priv(eth_dev);
271
272         ENICPMD_FUNC_TRACE();
273
274         enic_start_rq(enic, queue_idx);
275
276         return 0;
277 }
278
279 static int enicpmd_dev_rx_queue_stop(struct rte_eth_dev *eth_dev,
280         uint16_t queue_idx)
281 {
282         int ret;
283         struct enic *enic = pmd_priv(eth_dev);
284
285         ENICPMD_FUNC_TRACE();
286
287         ret = enic_stop_rq(enic, queue_idx);
288         if (ret)
289                 dev_err(enic, "error in stopping rq %d\n", queue_idx);
290
291         return ret;
292 }
293
294 static void enicpmd_dev_rx_queue_release(void *rxq)
295 {
296         ENICPMD_FUNC_TRACE();
297
298         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
299                 return;
300
301         enic_free_rq(rxq);
302 }
303
304 static uint32_t enicpmd_dev_rx_queue_count(struct rte_eth_dev *dev,
305                                            uint16_t rx_queue_id)
306 {
307         struct enic *enic = pmd_priv(dev);
308         uint32_t queue_count = 0;
309         struct vnic_cq *cq;
310         uint32_t cq_tail;
311         uint16_t cq_idx;
312         int rq_num;
313
314         rq_num = enic_rte_rq_idx_to_sop_idx(rx_queue_id);
315         cq = &enic->cq[enic_cq_rq(enic, rq_num)];
316         cq_idx = cq->to_clean;
317
318         cq_tail = ioread32(&cq->ctrl->cq_tail);
319
320         if (cq_tail < cq_idx)
321                 cq_tail += cq->ring.desc_count;
322
323         queue_count = cq_tail - cq_idx;
324
325         return queue_count;
326 }
327
328 static int enicpmd_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
329         uint16_t queue_idx,
330         uint16_t nb_desc,
331         unsigned int socket_id,
332         const struct rte_eth_rxconf *rx_conf,
333         struct rte_mempool *mp)
334 {
335         int ret;
336         struct enic *enic = pmd_priv(eth_dev);
337
338         ENICPMD_FUNC_TRACE();
339
340         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
341                 return -E_RTE_SECONDARY;
342
343         /* With Rx scatter support, two RQs are now used on VIC per RQ used
344          * by the application.
345          */
346         if (queue_idx * 2 >= ENIC_RQ_MAX) {
347                 dev_err(enic,
348                         "Max number of RX queues exceeded.  Max is %d. This PMD uses 2 RQs on VIC per RQ used by DPDK.\n",
349                         ENIC_RQ_MAX);
350                 return -EINVAL;
351         }
352
353         eth_dev->data->rx_queues[queue_idx] =
354                 (void *)&enic->rq[enic_rte_rq_idx_to_sop_idx(queue_idx)];
355
356         ret = enic_alloc_rq(enic, queue_idx, socket_id, mp, nb_desc,
357                             rx_conf->rx_free_thresh);
358         if (ret) {
359                 dev_err(enic, "error in allocating rq\n");
360                 return ret;
361         }
362
363         return enicpmd_dev_setup_intr(enic);
364 }
365
366 static int enicpmd_vlan_filter_set(struct rte_eth_dev *eth_dev,
367         uint16_t vlan_id, int on)
368 {
369         struct enic *enic = pmd_priv(eth_dev);
370         int err;
371
372         ENICPMD_FUNC_TRACE();
373         if (on)
374                 err = enic_add_vlan(enic, vlan_id);
375         else
376                 err = enic_del_vlan(enic, vlan_id);
377         return err;
378 }
379
380 static int enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
381 {
382         struct enic *enic = pmd_priv(eth_dev);
383
384         ENICPMD_FUNC_TRACE();
385
386         if (mask & ETH_VLAN_STRIP_MASK) {
387                 if (eth_dev->data->dev_conf.rxmode.offloads &
388                     DEV_RX_OFFLOAD_VLAN_STRIP)
389                         enic->ig_vlan_strip_en = 1;
390                 else
391                         enic->ig_vlan_strip_en = 0;
392         }
393         enic_set_rss_nic_cfg(enic);
394
395
396         if (mask & ETH_VLAN_FILTER_MASK) {
397                 dev_warning(enic,
398                         "Configuration of VLAN filter is not supported\n");
399         }
400
401         if (mask & ETH_VLAN_EXTEND_MASK) {
402                 dev_warning(enic,
403                         "Configuration of extended VLAN is not supported\n");
404         }
405
406         return 0;
407 }
408
409 static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
410 {
411         int ret;
412         struct enic *enic = pmd_priv(eth_dev);
413
414         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
415                 return -E_RTE_SECONDARY;
416
417         ENICPMD_FUNC_TRACE();
418         ret = enic_set_vnic_res(enic);
419         if (ret) {
420                 dev_err(enic, "Set vNIC resource num  failed, aborting\n");
421                 return ret;
422         }
423
424         enic->hw_ip_checksum = !!(eth_dev->data->dev_conf.rxmode.offloads &
425                                   DEV_RX_OFFLOAD_CHECKSUM);
426         ret = enicpmd_vlan_offload_set(eth_dev, ETH_VLAN_STRIP_MASK);
427
428         return ret;
429 }
430
431 /* Start the device.
432  * It returns 0 on success.
433  */
434 static int enicpmd_dev_start(struct rte_eth_dev *eth_dev)
435 {
436         struct enic *enic = pmd_priv(eth_dev);
437
438         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
439                 return -E_RTE_SECONDARY;
440
441         ENICPMD_FUNC_TRACE();
442         return enic_enable(enic);
443 }
444
445 /*
446  * Stop device: disable rx and tx functions to allow for reconfiguring.
447  */
448 static void enicpmd_dev_stop(struct rte_eth_dev *eth_dev)
449 {
450         struct rte_eth_link link;
451         struct enic *enic = pmd_priv(eth_dev);
452
453         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
454                 return;
455
456         ENICPMD_FUNC_TRACE();
457         enic_disable(enic);
458         memset(&link, 0, sizeof(link));
459         rte_atomic64_cmpset((uint64_t *)&eth_dev->data->dev_link,
460                 *(uint64_t *)&eth_dev->data->dev_link,
461                 *(uint64_t *)&link);
462 }
463
464 /*
465  * Stop device.
466  */
467 static void enicpmd_dev_close(struct rte_eth_dev *eth_dev)
468 {
469         struct enic *enic = pmd_priv(eth_dev);
470
471         ENICPMD_FUNC_TRACE();
472         enic_remove(enic);
473 }
474
475 static int enicpmd_dev_link_update(struct rte_eth_dev *eth_dev,
476         __rte_unused int wait_to_complete)
477 {
478         struct enic *enic = pmd_priv(eth_dev);
479
480         ENICPMD_FUNC_TRACE();
481         return enic_link_update(enic);
482 }
483
484 static int enicpmd_dev_stats_get(struct rte_eth_dev *eth_dev,
485         struct rte_eth_stats *stats)
486 {
487         struct enic *enic = pmd_priv(eth_dev);
488
489         ENICPMD_FUNC_TRACE();
490         return enic_dev_stats_get(enic, stats);
491 }
492
493 static void enicpmd_dev_stats_reset(struct rte_eth_dev *eth_dev)
494 {
495         struct enic *enic = pmd_priv(eth_dev);
496
497         ENICPMD_FUNC_TRACE();
498         enic_dev_stats_clear(enic);
499 }
500
501 static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
502         struct rte_eth_dev_info *device_info)
503 {
504         struct enic *enic = pmd_priv(eth_dev);
505
506         ENICPMD_FUNC_TRACE();
507         device_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
508         /* Scattered Rx uses two receive queues per rx queue exposed to dpdk */
509         device_info->max_rx_queues = enic->conf_rq_count / 2;
510         device_info->max_tx_queues = enic->conf_wq_count;
511         device_info->min_rx_bufsize = ENIC_MIN_MTU;
512         device_info->max_rx_pktlen = enic->max_mtu + ETHER_HDR_LEN + 4;
513         device_info->max_mac_addrs = ENIC_MAX_MAC_ADDR;
514         device_info->rx_offload_capa =
515                 DEV_RX_OFFLOAD_VLAN_STRIP |
516                 DEV_RX_OFFLOAD_IPV4_CKSUM |
517                 DEV_RX_OFFLOAD_UDP_CKSUM  |
518                 DEV_RX_OFFLOAD_TCP_CKSUM;
519         device_info->tx_offload_capa =
520                 DEV_TX_OFFLOAD_VLAN_INSERT |
521                 DEV_TX_OFFLOAD_IPV4_CKSUM  |
522                 DEV_TX_OFFLOAD_UDP_CKSUM   |
523                 DEV_TX_OFFLOAD_TCP_CKSUM   |
524                 DEV_TX_OFFLOAD_TCP_TSO;
525         device_info->default_rxconf = (struct rte_eth_rxconf) {
526                 .rx_free_thresh = ENIC_DEFAULT_RX_FREE_THRESH
527         };
528 }
529
530 static const uint32_t *enicpmd_dev_supported_ptypes_get(struct rte_eth_dev *dev)
531 {
532         static const uint32_t ptypes[] = {
533                 RTE_PTYPE_L2_ETHER,
534                 RTE_PTYPE_L2_ETHER_VLAN,
535                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
536                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
537                 RTE_PTYPE_L4_TCP,
538                 RTE_PTYPE_L4_UDP,
539                 RTE_PTYPE_L4_FRAG,
540                 RTE_PTYPE_L4_NONFRAG,
541                 RTE_PTYPE_UNKNOWN
542         };
543
544         if (dev->rx_pkt_burst == enic_recv_pkts)
545                 return ptypes;
546         return NULL;
547 }
548
549 static void enicpmd_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
550 {
551         struct enic *enic = pmd_priv(eth_dev);
552
553         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
554                 return;
555
556         ENICPMD_FUNC_TRACE();
557
558         enic->promisc = 1;
559         enic_add_packet_filter(enic);
560 }
561
562 static void enicpmd_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
563 {
564         struct enic *enic = pmd_priv(eth_dev);
565
566         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
567                 return;
568
569         ENICPMD_FUNC_TRACE();
570         enic->promisc = 0;
571         enic_add_packet_filter(enic);
572 }
573
574 static void enicpmd_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
575 {
576         struct enic *enic = pmd_priv(eth_dev);
577
578         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
579                 return;
580
581         ENICPMD_FUNC_TRACE();
582         enic->allmulti = 1;
583         enic_add_packet_filter(enic);
584 }
585
586 static void enicpmd_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
587 {
588         struct enic *enic = pmd_priv(eth_dev);
589
590         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
591                 return;
592
593         ENICPMD_FUNC_TRACE();
594         enic->allmulti = 0;
595         enic_add_packet_filter(enic);
596 }
597
598 static int enicpmd_add_mac_addr(struct rte_eth_dev *eth_dev,
599         struct ether_addr *mac_addr,
600         __rte_unused uint32_t index, __rte_unused uint32_t pool)
601 {
602         struct enic *enic = pmd_priv(eth_dev);
603
604         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
605                 return -E_RTE_SECONDARY;
606
607         ENICPMD_FUNC_TRACE();
608         return enic_set_mac_address(enic, mac_addr->addr_bytes);
609 }
610
611 static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, uint32_t index)
612 {
613         struct enic *enic = pmd_priv(eth_dev);
614
615         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
616                 return;
617
618         ENICPMD_FUNC_TRACE();
619         enic_del_mac_address(enic, index);
620 }
621
622 static int enicpmd_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
623 {
624         struct enic *enic = pmd_priv(eth_dev);
625
626         ENICPMD_FUNC_TRACE();
627         return enic_set_mtu(enic, mtu);
628 }
629
630 static const struct eth_dev_ops enicpmd_eth_dev_ops = {
631         .dev_configure        = enicpmd_dev_configure,
632         .dev_start            = enicpmd_dev_start,
633         .dev_stop             = enicpmd_dev_stop,
634         .dev_set_link_up      = NULL,
635         .dev_set_link_down    = NULL,
636         .dev_close            = enicpmd_dev_close,
637         .promiscuous_enable   = enicpmd_dev_promiscuous_enable,
638         .promiscuous_disable  = enicpmd_dev_promiscuous_disable,
639         .allmulticast_enable  = enicpmd_dev_allmulticast_enable,
640         .allmulticast_disable = enicpmd_dev_allmulticast_disable,
641         .link_update          = enicpmd_dev_link_update,
642         .stats_get            = enicpmd_dev_stats_get,
643         .stats_reset          = enicpmd_dev_stats_reset,
644         .queue_stats_mapping_set = NULL,
645         .dev_infos_get        = enicpmd_dev_info_get,
646         .dev_supported_ptypes_get = enicpmd_dev_supported_ptypes_get,
647         .mtu_set              = enicpmd_mtu_set,
648         .vlan_filter_set      = enicpmd_vlan_filter_set,
649         .vlan_tpid_set        = NULL,
650         .vlan_offload_set     = enicpmd_vlan_offload_set,
651         .vlan_strip_queue_set = NULL,
652         .rx_queue_start       = enicpmd_dev_rx_queue_start,
653         .rx_queue_stop        = enicpmd_dev_rx_queue_stop,
654         .tx_queue_start       = enicpmd_dev_tx_queue_start,
655         .tx_queue_stop        = enicpmd_dev_tx_queue_stop,
656         .rx_queue_setup       = enicpmd_dev_rx_queue_setup,
657         .rx_queue_release     = enicpmd_dev_rx_queue_release,
658         .rx_queue_count       = enicpmd_dev_rx_queue_count,
659         .rx_descriptor_done   = NULL,
660         .tx_queue_setup       = enicpmd_dev_tx_queue_setup,
661         .tx_queue_release     = enicpmd_dev_tx_queue_release,
662         .dev_led_on           = NULL,
663         .dev_led_off          = NULL,
664         .flow_ctrl_get        = NULL,
665         .flow_ctrl_set        = NULL,
666         .priority_flow_ctrl_set = NULL,
667         .mac_addr_add         = enicpmd_add_mac_addr,
668         .mac_addr_remove      = enicpmd_remove_mac_addr,
669         .filter_ctrl          = enicpmd_dev_filter_ctrl,
670 };
671
672 struct enic *enicpmd_list_head = NULL;
673 /* Initialize the driver
674  * It returns 0 on success.
675  */
676 static int eth_enicpmd_dev_init(struct rte_eth_dev *eth_dev)
677 {
678         struct rte_pci_device *pdev;
679         struct rte_pci_addr *addr;
680         struct enic *enic = pmd_priv(eth_dev);
681
682         ENICPMD_FUNC_TRACE();
683
684         enic->port_id = eth_dev->data->port_id;
685         enic->rte_dev = eth_dev;
686         eth_dev->dev_ops = &enicpmd_eth_dev_ops;
687         eth_dev->rx_pkt_burst = &enic_recv_pkts;
688         eth_dev->tx_pkt_burst = &enic_xmit_pkts;
689
690         pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
691         rte_eth_copy_pci_info(eth_dev, pdev);
692         enic->pdev = pdev;
693         addr = &pdev->addr;
694
695         snprintf(enic->bdf_name, ENICPMD_BDF_LENGTH, "%04x:%02x:%02x.%x",
696                 addr->domain, addr->bus, addr->devid, addr->function);
697
698         return enic_probe(enic);
699 }
700
701 static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
702         struct rte_pci_device *pci_dev)
703 {
704         return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct enic),
705                 eth_enicpmd_dev_init);
706 }
707
708 static int eth_enic_pci_remove(struct rte_pci_device *pci_dev)
709 {
710         return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
711 }
712
713 static struct rte_pci_driver rte_enic_pmd = {
714         .id_table = pci_id_enic_map,
715         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
716         .probe = eth_enic_pci_probe,
717         .remove = eth_enic_pci_remove,
718 };
719
720 RTE_PMD_REGISTER_PCI(net_enic, rte_enic_pmd);
721 RTE_PMD_REGISTER_PCI_TABLE(net_enic, pci_id_enic_map);
722 RTE_PMD_REGISTER_KMOD_DEP(net_enic, "* igb_uio | uio_pci_generic | vfio-pci");