net/enic: remove VLAN filter handler
[dpdk.git] / drivers / net / enic / enic_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5
6 #include <stdio.h>
7 #include <stdint.h>
8
9 #include <rte_dev.h>
10 #include <rte_pci.h>
11 #include <rte_bus_pci.h>
12 #include <rte_ethdev_driver.h>
13 #include <rte_ethdev_pci.h>
14 #include <rte_string_fns.h>
15
16 #include "vnic_intr.h"
17 #include "vnic_cq.h"
18 #include "vnic_wq.h"
19 #include "vnic_rq.h"
20 #include "vnic_enet.h"
21 #include "enic.h"
22
23 int enicpmd_logtype_init;
24 int enicpmd_logtype_flow;
25
26 #define PMD_INIT_LOG(level, fmt, args...) \
27         rte_log(RTE_LOG_ ## level, enicpmd_logtype_init, \
28                 "%s" fmt "\n", __func__, ##args)
29
30 #define ENICPMD_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
31
32 /*
33  * The set of PCI devices this driver supports
34  */
35 #define CISCO_PCI_VENDOR_ID 0x1137
36 static const struct rte_pci_id pci_id_enic_map[] = {
37         { RTE_PCI_DEVICE(CISCO_PCI_VENDOR_ID, PCI_DEVICE_ID_CISCO_VIC_ENET) },
38         { RTE_PCI_DEVICE(CISCO_PCI_VENDOR_ID, PCI_DEVICE_ID_CISCO_VIC_ENET_VF) },
39         {.vendor_id = 0, /* sentinel */},
40 };
41
42 RTE_INIT(enicpmd_init_log);
43 static void
44 enicpmd_init_log(void)
45 {
46         enicpmd_logtype_init = rte_log_register("pmd.net.enic.init");
47         if (enicpmd_logtype_init >= 0)
48                 rte_log_set_level(enicpmd_logtype_init, RTE_LOG_NOTICE);
49         enicpmd_logtype_flow = rte_log_register("pmd.net.enic.flow");
50         if (enicpmd_logtype_flow >= 0)
51                 rte_log_set_level(enicpmd_logtype_flow, RTE_LOG_NOTICE);
52 }
53
54 static int
55 enicpmd_fdir_ctrl_func(struct rte_eth_dev *eth_dev,
56                         enum rte_filter_op filter_op, void *arg)
57 {
58         struct enic *enic = pmd_priv(eth_dev);
59         int ret = 0;
60
61         ENICPMD_FUNC_TRACE();
62         if (filter_op == RTE_ETH_FILTER_NOP)
63                 return 0;
64
65         if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
66                 return -EINVAL;
67
68         switch (filter_op) {
69         case RTE_ETH_FILTER_ADD:
70         case RTE_ETH_FILTER_UPDATE:
71                 ret = enic_fdir_add_fltr(enic,
72                         (struct rte_eth_fdir_filter *)arg);
73                 break;
74
75         case RTE_ETH_FILTER_DELETE:
76                 ret = enic_fdir_del_fltr(enic,
77                         (struct rte_eth_fdir_filter *)arg);
78                 break;
79
80         case RTE_ETH_FILTER_STATS:
81                 enic_fdir_stats_get(enic, (struct rte_eth_fdir_stats *)arg);
82                 break;
83
84         case RTE_ETH_FILTER_FLUSH:
85                 dev_warning(enic, "unsupported operation %u", filter_op);
86                 ret = -ENOTSUP;
87                 break;
88         case RTE_ETH_FILTER_INFO:
89                 enic_fdir_info_get(enic, (struct rte_eth_fdir_info *)arg);
90                 break;
91         default:
92                 dev_err(enic, "unknown operation %u", filter_op);
93                 ret = -EINVAL;
94                 break;
95         }
96         return ret;
97 }
98
99 static int
100 enicpmd_dev_filter_ctrl(struct rte_eth_dev *dev,
101                      enum rte_filter_type filter_type,
102                      enum rte_filter_op filter_op,
103                      void *arg)
104 {
105         int ret = 0;
106
107         ENICPMD_FUNC_TRACE();
108
109         switch (filter_type) {
110         case RTE_ETH_FILTER_GENERIC:
111                 if (filter_op != RTE_ETH_FILTER_GET)
112                         return -EINVAL;
113                 *(const void **)arg = &enic_flow_ops;
114                 break;
115         case RTE_ETH_FILTER_FDIR:
116                 ret = enicpmd_fdir_ctrl_func(dev, filter_op, arg);
117                 break;
118         default:
119                 dev_warning(enic, "Filter type (%d) not supported",
120                         filter_type);
121                 ret = -EINVAL;
122                 break;
123         }
124
125         return ret;
126 }
127
128 static void enicpmd_dev_tx_queue_release(void *txq)
129 {
130         ENICPMD_FUNC_TRACE();
131
132         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
133                 return;
134
135         enic_free_wq(txq);
136 }
137
138 static int enicpmd_dev_setup_intr(struct enic *enic)
139 {
140         int ret;
141         unsigned int index;
142
143         ENICPMD_FUNC_TRACE();
144
145         /* Are we done with the init of all the queues? */
146         for (index = 0; index < enic->cq_count; index++) {
147                 if (!enic->cq[index].ctrl)
148                         break;
149         }
150         if (enic->cq_count != index)
151                 return 0;
152         for (index = 0; index < enic->wq_count; index++) {
153                 if (!enic->wq[index].ctrl)
154                         break;
155         }
156         if (enic->wq_count != index)
157                 return 0;
158         /* check start of packet (SOP) RQs only in case scatter is disabled. */
159         for (index = 0; index < enic->rq_count; index++) {
160                 if (!enic->rq[enic_rte_rq_idx_to_sop_idx(index)].ctrl)
161                         break;
162         }
163         if (enic->rq_count != index)
164                 return 0;
165
166         ret = enic_alloc_intr_resources(enic);
167         if (ret) {
168                 dev_err(enic, "alloc intr failed\n");
169                 return ret;
170         }
171         enic_init_vnic_resources(enic);
172
173         ret = enic_setup_finish(enic);
174         if (ret)
175                 dev_err(enic, "setup could not be finished\n");
176
177         return ret;
178 }
179
180 static int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
181         uint16_t queue_idx,
182         uint16_t nb_desc,
183         unsigned int socket_id,
184         __rte_unused const struct rte_eth_txconf *tx_conf)
185 {
186         int ret;
187         struct enic *enic = pmd_priv(eth_dev);
188
189         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
190                 return -E_RTE_SECONDARY;
191
192         ENICPMD_FUNC_TRACE();
193         RTE_ASSERT(queue_idx < enic->conf_wq_count);
194         eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
195
196         ret = enic_alloc_wq(enic, queue_idx, socket_id, nb_desc);
197         if (ret) {
198                 dev_err(enic, "error in allocating wq\n");
199                 return ret;
200         }
201
202         return enicpmd_dev_setup_intr(enic);
203 }
204
205 static int enicpmd_dev_tx_queue_start(struct rte_eth_dev *eth_dev,
206         uint16_t queue_idx)
207 {
208         struct enic *enic = pmd_priv(eth_dev);
209
210         ENICPMD_FUNC_TRACE();
211
212         enic_start_wq(enic, queue_idx);
213
214         return 0;
215 }
216
217 static int enicpmd_dev_tx_queue_stop(struct rte_eth_dev *eth_dev,
218         uint16_t queue_idx)
219 {
220         int ret;
221         struct enic *enic = pmd_priv(eth_dev);
222
223         ENICPMD_FUNC_TRACE();
224
225         ret = enic_stop_wq(enic, queue_idx);
226         if (ret)
227                 dev_err(enic, "error in stopping wq %d\n", queue_idx);
228
229         return ret;
230 }
231
232 static int enicpmd_dev_rx_queue_start(struct rte_eth_dev *eth_dev,
233         uint16_t queue_idx)
234 {
235         struct enic *enic = pmd_priv(eth_dev);
236
237         ENICPMD_FUNC_TRACE();
238
239         enic_start_rq(enic, queue_idx);
240
241         return 0;
242 }
243
244 static int enicpmd_dev_rx_queue_stop(struct rte_eth_dev *eth_dev,
245         uint16_t queue_idx)
246 {
247         int ret;
248         struct enic *enic = pmd_priv(eth_dev);
249
250         ENICPMD_FUNC_TRACE();
251
252         ret = enic_stop_rq(enic, queue_idx);
253         if (ret)
254                 dev_err(enic, "error in stopping rq %d\n", queue_idx);
255
256         return ret;
257 }
258
259 static void enicpmd_dev_rx_queue_release(void *rxq)
260 {
261         ENICPMD_FUNC_TRACE();
262
263         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
264                 return;
265
266         enic_free_rq(rxq);
267 }
268
269 static uint32_t enicpmd_dev_rx_queue_count(struct rte_eth_dev *dev,
270                                            uint16_t rx_queue_id)
271 {
272         struct enic *enic = pmd_priv(dev);
273         uint32_t queue_count = 0;
274         struct vnic_cq *cq;
275         uint32_t cq_tail;
276         uint16_t cq_idx;
277         int rq_num;
278
279         rq_num = enic_rte_rq_idx_to_sop_idx(rx_queue_id);
280         cq = &enic->cq[enic_cq_rq(enic, rq_num)];
281         cq_idx = cq->to_clean;
282
283         cq_tail = ioread32(&cq->ctrl->cq_tail);
284
285         if (cq_tail < cq_idx)
286                 cq_tail += cq->ring.desc_count;
287
288         queue_count = cq_tail - cq_idx;
289
290         return queue_count;
291 }
292
293 static int enicpmd_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
294         uint16_t queue_idx,
295         uint16_t nb_desc,
296         unsigned int socket_id,
297         const struct rte_eth_rxconf *rx_conf,
298         struct rte_mempool *mp)
299 {
300         int ret;
301         struct enic *enic = pmd_priv(eth_dev);
302
303         ENICPMD_FUNC_TRACE();
304
305         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
306                 return -E_RTE_SECONDARY;
307         RTE_ASSERT(enic_rte_rq_idx_to_sop_idx(queue_idx) < enic->conf_rq_count);
308         eth_dev->data->rx_queues[queue_idx] =
309                 (void *)&enic->rq[enic_rte_rq_idx_to_sop_idx(queue_idx)];
310
311         ret = enic_alloc_rq(enic, queue_idx, socket_id, mp, nb_desc,
312                             rx_conf->rx_free_thresh);
313         if (ret) {
314                 dev_err(enic, "error in allocating rq\n");
315                 return ret;
316         }
317
318         return enicpmd_dev_setup_intr(enic);
319 }
320
321 static int enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
322 {
323         struct enic *enic = pmd_priv(eth_dev);
324         uint64_t offloads;
325
326         ENICPMD_FUNC_TRACE();
327
328         offloads = eth_dev->data->dev_conf.rxmode.offloads;
329         if (mask & ETH_VLAN_STRIP_MASK) {
330                 if (offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
331                         enic->ig_vlan_strip_en = 1;
332                 else
333                         enic->ig_vlan_strip_en = 0;
334         }
335
336         if ((mask & ETH_VLAN_FILTER_MASK) &&
337             (offloads & DEV_RX_OFFLOAD_VLAN_FILTER)) {
338                 dev_warning(enic,
339                         "Configuration of VLAN filter is not supported\n");
340         }
341
342         if ((mask & ETH_VLAN_EXTEND_MASK) &&
343             (offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)) {
344                 dev_warning(enic,
345                         "Configuration of extended VLAN is not supported\n");
346         }
347
348         return enic_set_vlan_strip(enic);
349 }
350
351 static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
352 {
353         int ret;
354         int mask;
355         struct enic *enic = pmd_priv(eth_dev);
356
357         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
358                 return -E_RTE_SECONDARY;
359
360         ENICPMD_FUNC_TRACE();
361         ret = enic_set_vnic_res(enic);
362         if (ret) {
363                 dev_err(enic, "Set vNIC resource num  failed, aborting\n");
364                 return ret;
365         }
366
367         enic->hw_ip_checksum = !!(eth_dev->data->dev_conf.rxmode.offloads &
368                                   DEV_RX_OFFLOAD_CHECKSUM);
369         /* All vlan offload masks to apply the current settings */
370         mask = ETH_VLAN_STRIP_MASK |
371                 ETH_VLAN_FILTER_MASK |
372                 ETH_VLAN_EXTEND_MASK;
373         ret = enicpmd_vlan_offload_set(eth_dev, mask);
374         if (ret) {
375                 dev_err(enic, "Failed to configure VLAN offloads\n");
376                 return ret;
377         }
378         /*
379          * Initialize RSS with the default reta and key. If the user key is
380          * given (rx_adv_conf.rss_conf.rss_key), will use that instead of the
381          * default key.
382          */
383         return enic_init_rss_nic_cfg(enic);
384 }
385
386 /* Start the device.
387  * It returns 0 on success.
388  */
389 static int enicpmd_dev_start(struct rte_eth_dev *eth_dev)
390 {
391         struct enic *enic = pmd_priv(eth_dev);
392
393         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
394                 return -E_RTE_SECONDARY;
395
396         ENICPMD_FUNC_TRACE();
397         return enic_enable(enic);
398 }
399
400 /*
401  * Stop device: disable rx and tx functions to allow for reconfiguring.
402  */
403 static void enicpmd_dev_stop(struct rte_eth_dev *eth_dev)
404 {
405         struct rte_eth_link link;
406         struct enic *enic = pmd_priv(eth_dev);
407
408         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
409                 return;
410
411         ENICPMD_FUNC_TRACE();
412         enic_disable(enic);
413         memset(&link, 0, sizeof(link));
414         rte_atomic64_cmpset((uint64_t *)&eth_dev->data->dev_link,
415                 *(uint64_t *)&eth_dev->data->dev_link,
416                 *(uint64_t *)&link);
417 }
418
419 /*
420  * Stop device.
421  */
422 static void enicpmd_dev_close(struct rte_eth_dev *eth_dev)
423 {
424         struct enic *enic = pmd_priv(eth_dev);
425
426         ENICPMD_FUNC_TRACE();
427         enic_remove(enic);
428 }
429
430 static int enicpmd_dev_link_update(struct rte_eth_dev *eth_dev,
431         __rte_unused int wait_to_complete)
432 {
433         struct enic *enic = pmd_priv(eth_dev);
434
435         ENICPMD_FUNC_TRACE();
436         return enic_link_update(enic);
437 }
438
439 static int enicpmd_dev_stats_get(struct rte_eth_dev *eth_dev,
440         struct rte_eth_stats *stats)
441 {
442         struct enic *enic = pmd_priv(eth_dev);
443
444         ENICPMD_FUNC_TRACE();
445         return enic_dev_stats_get(enic, stats);
446 }
447
448 static void enicpmd_dev_stats_reset(struct rte_eth_dev *eth_dev)
449 {
450         struct enic *enic = pmd_priv(eth_dev);
451
452         ENICPMD_FUNC_TRACE();
453         enic_dev_stats_clear(enic);
454 }
455
456 static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
457         struct rte_eth_dev_info *device_info)
458 {
459         struct enic *enic = pmd_priv(eth_dev);
460
461         ENICPMD_FUNC_TRACE();
462         device_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
463         /* Scattered Rx uses two receive queues per rx queue exposed to dpdk */
464         device_info->max_rx_queues = enic->conf_rq_count / 2;
465         device_info->max_tx_queues = enic->conf_wq_count;
466         device_info->min_rx_bufsize = ENIC_MIN_MTU;
467         /* "Max" mtu is not a typo. HW receives packet sizes up to the
468          * max mtu regardless of the current mtu (vNIC's mtu). vNIC mtu is
469          * a hint to the driver to size receive buffers accordingly so that
470          * larger-than-vnic-mtu packets get truncated.. For DPDK, we let
471          * the user decide the buffer size via rxmode.max_rx_pkt_len, basically
472          * ignoring vNIC mtu.
473          */
474         device_info->max_rx_pktlen = enic_mtu_to_max_rx_pktlen(enic->max_mtu);
475         device_info->max_mac_addrs = ENIC_MAX_MAC_ADDR;
476         device_info->rx_offload_capa =
477                 DEV_RX_OFFLOAD_VLAN_STRIP |
478                 DEV_RX_OFFLOAD_IPV4_CKSUM |
479                 DEV_RX_OFFLOAD_UDP_CKSUM  |
480                 DEV_RX_OFFLOAD_TCP_CKSUM;
481         device_info->tx_offload_capa =
482                 DEV_TX_OFFLOAD_VLAN_INSERT |
483                 DEV_TX_OFFLOAD_IPV4_CKSUM  |
484                 DEV_TX_OFFLOAD_UDP_CKSUM   |
485                 DEV_TX_OFFLOAD_TCP_CKSUM   |
486                 DEV_TX_OFFLOAD_TCP_TSO;
487         device_info->default_rxconf = (struct rte_eth_rxconf) {
488                 .rx_free_thresh = ENIC_DEFAULT_RX_FREE_THRESH
489         };
490         device_info->reta_size = enic->reta_size;
491         device_info->hash_key_size = enic->hash_key_size;
492         device_info->flow_type_rss_offloads = enic->flow_type_rss_offloads;
493 }
494
495 static const uint32_t *enicpmd_dev_supported_ptypes_get(struct rte_eth_dev *dev)
496 {
497         static const uint32_t ptypes[] = {
498                 RTE_PTYPE_L2_ETHER,
499                 RTE_PTYPE_L2_ETHER_VLAN,
500                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
501                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
502                 RTE_PTYPE_L4_TCP,
503                 RTE_PTYPE_L4_UDP,
504                 RTE_PTYPE_L4_FRAG,
505                 RTE_PTYPE_L4_NONFRAG,
506                 RTE_PTYPE_UNKNOWN
507         };
508
509         if (dev->rx_pkt_burst == enic_recv_pkts)
510                 return ptypes;
511         return NULL;
512 }
513
514 static void enicpmd_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
515 {
516         struct enic *enic = pmd_priv(eth_dev);
517
518         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
519                 return;
520
521         ENICPMD_FUNC_TRACE();
522
523         enic->promisc = 1;
524         enic_add_packet_filter(enic);
525 }
526
527 static void enicpmd_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
528 {
529         struct enic *enic = pmd_priv(eth_dev);
530
531         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
532                 return;
533
534         ENICPMD_FUNC_TRACE();
535         enic->promisc = 0;
536         enic_add_packet_filter(enic);
537 }
538
539 static void enicpmd_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
540 {
541         struct enic *enic = pmd_priv(eth_dev);
542
543         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
544                 return;
545
546         ENICPMD_FUNC_TRACE();
547         enic->allmulti = 1;
548         enic_add_packet_filter(enic);
549 }
550
551 static void enicpmd_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
552 {
553         struct enic *enic = pmd_priv(eth_dev);
554
555         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
556                 return;
557
558         ENICPMD_FUNC_TRACE();
559         enic->allmulti = 0;
560         enic_add_packet_filter(enic);
561 }
562
563 static int enicpmd_add_mac_addr(struct rte_eth_dev *eth_dev,
564         struct ether_addr *mac_addr,
565         __rte_unused uint32_t index, __rte_unused uint32_t pool)
566 {
567         struct enic *enic = pmd_priv(eth_dev);
568
569         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
570                 return -E_RTE_SECONDARY;
571
572         ENICPMD_FUNC_TRACE();
573         return enic_set_mac_address(enic, mac_addr->addr_bytes);
574 }
575
576 static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, uint32_t index)
577 {
578         struct enic *enic = pmd_priv(eth_dev);
579
580         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
581                 return;
582
583         ENICPMD_FUNC_TRACE();
584         enic_del_mac_address(enic, index);
585 }
586
587 static int enicpmd_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
588 {
589         struct enic *enic = pmd_priv(eth_dev);
590
591         ENICPMD_FUNC_TRACE();
592         return enic_set_mtu(enic, mtu);
593 }
594
595 static int enicpmd_dev_rss_reta_query(struct rte_eth_dev *dev,
596                                       struct rte_eth_rss_reta_entry64
597                                       *reta_conf,
598                                       uint16_t reta_size)
599 {
600         struct enic *enic = pmd_priv(dev);
601         uint16_t i, idx, shift;
602
603         ENICPMD_FUNC_TRACE();
604         if (reta_size != ENIC_RSS_RETA_SIZE) {
605                 dev_err(enic, "reta_query: wrong reta_size. given=%u expected=%u\n",
606                         reta_size, ENIC_RSS_RETA_SIZE);
607                 return -EINVAL;
608         }
609
610         for (i = 0; i < reta_size; i++) {
611                 idx = i / RTE_RETA_GROUP_SIZE;
612                 shift = i % RTE_RETA_GROUP_SIZE;
613                 if (reta_conf[idx].mask & (1ULL << shift))
614                         reta_conf[idx].reta[shift] = enic_sop_rq_idx_to_rte_idx(
615                                 enic->rss_cpu.cpu[i / 4].b[i % 4]);
616         }
617
618         return 0;
619 }
620
621 static int enicpmd_dev_rss_reta_update(struct rte_eth_dev *dev,
622                                        struct rte_eth_rss_reta_entry64
623                                        *reta_conf,
624                                        uint16_t reta_size)
625 {
626         struct enic *enic = pmd_priv(dev);
627         union vnic_rss_cpu rss_cpu;
628         uint16_t i, idx, shift;
629
630         ENICPMD_FUNC_TRACE();
631         if (reta_size != ENIC_RSS_RETA_SIZE) {
632                 dev_err(enic, "reta_update: wrong reta_size. given=%u"
633                         " expected=%u\n",
634                         reta_size, ENIC_RSS_RETA_SIZE);
635                 return -EINVAL;
636         }
637         /*
638          * Start with the current reta and modify it per reta_conf, as we
639          * need to push the entire reta even if we only modify one entry.
640          */
641         rss_cpu = enic->rss_cpu;
642         for (i = 0; i < reta_size; i++) {
643                 idx = i / RTE_RETA_GROUP_SIZE;
644                 shift = i % RTE_RETA_GROUP_SIZE;
645                 if (reta_conf[idx].mask & (1ULL << shift))
646                         rss_cpu.cpu[i / 4].b[i % 4] =
647                                 enic_rte_rq_idx_to_sop_idx(
648                                         reta_conf[idx].reta[shift]);
649         }
650         return enic_set_rss_reta(enic, &rss_cpu);
651 }
652
653 static int enicpmd_dev_rss_hash_update(struct rte_eth_dev *dev,
654                                        struct rte_eth_rss_conf *rss_conf)
655 {
656         struct enic *enic = pmd_priv(dev);
657
658         ENICPMD_FUNC_TRACE();
659         return enic_set_rss_conf(enic, rss_conf);
660 }
661
662 static int enicpmd_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
663                                          struct rte_eth_rss_conf *rss_conf)
664 {
665         struct enic *enic = pmd_priv(dev);
666
667         ENICPMD_FUNC_TRACE();
668         if (rss_conf == NULL)
669                 return -EINVAL;
670         if (rss_conf->rss_key != NULL &&
671             rss_conf->rss_key_len < ENIC_RSS_HASH_KEY_SIZE) {
672                 dev_err(enic, "rss_hash_conf_get: wrong rss_key_len. given=%u"
673                         " expected=%u+\n",
674                         rss_conf->rss_key_len, ENIC_RSS_HASH_KEY_SIZE);
675                 return -EINVAL;
676         }
677         rss_conf->rss_hf = enic->rss_hf;
678         if (rss_conf->rss_key != NULL) {
679                 int i;
680                 for (i = 0; i < ENIC_RSS_HASH_KEY_SIZE; i++) {
681                         rss_conf->rss_key[i] =
682                                 enic->rss_key.key[i / 10].b[i % 10];
683                 }
684                 rss_conf->rss_key_len = ENIC_RSS_HASH_KEY_SIZE;
685         }
686         return 0;
687 }
688
689 static const struct eth_dev_ops enicpmd_eth_dev_ops = {
690         .dev_configure        = enicpmd_dev_configure,
691         .dev_start            = enicpmd_dev_start,
692         .dev_stop             = enicpmd_dev_stop,
693         .dev_set_link_up      = NULL,
694         .dev_set_link_down    = NULL,
695         .dev_close            = enicpmd_dev_close,
696         .promiscuous_enable   = enicpmd_dev_promiscuous_enable,
697         .promiscuous_disable  = enicpmd_dev_promiscuous_disable,
698         .allmulticast_enable  = enicpmd_dev_allmulticast_enable,
699         .allmulticast_disable = enicpmd_dev_allmulticast_disable,
700         .link_update          = enicpmd_dev_link_update,
701         .stats_get            = enicpmd_dev_stats_get,
702         .stats_reset          = enicpmd_dev_stats_reset,
703         .queue_stats_mapping_set = NULL,
704         .dev_infos_get        = enicpmd_dev_info_get,
705         .dev_supported_ptypes_get = enicpmd_dev_supported_ptypes_get,
706         .mtu_set              = enicpmd_mtu_set,
707         .vlan_filter_set      = NULL,
708         .vlan_tpid_set        = NULL,
709         .vlan_offload_set     = enicpmd_vlan_offload_set,
710         .vlan_strip_queue_set = NULL,
711         .rx_queue_start       = enicpmd_dev_rx_queue_start,
712         .rx_queue_stop        = enicpmd_dev_rx_queue_stop,
713         .tx_queue_start       = enicpmd_dev_tx_queue_start,
714         .tx_queue_stop        = enicpmd_dev_tx_queue_stop,
715         .rx_queue_setup       = enicpmd_dev_rx_queue_setup,
716         .rx_queue_release     = enicpmd_dev_rx_queue_release,
717         .rx_queue_count       = enicpmd_dev_rx_queue_count,
718         .rx_descriptor_done   = NULL,
719         .tx_queue_setup       = enicpmd_dev_tx_queue_setup,
720         .tx_queue_release     = enicpmd_dev_tx_queue_release,
721         .dev_led_on           = NULL,
722         .dev_led_off          = NULL,
723         .flow_ctrl_get        = NULL,
724         .flow_ctrl_set        = NULL,
725         .priority_flow_ctrl_set = NULL,
726         .mac_addr_add         = enicpmd_add_mac_addr,
727         .mac_addr_remove      = enicpmd_remove_mac_addr,
728         .filter_ctrl          = enicpmd_dev_filter_ctrl,
729         .reta_query           = enicpmd_dev_rss_reta_query,
730         .reta_update          = enicpmd_dev_rss_reta_update,
731         .rss_hash_conf_get    = enicpmd_dev_rss_hash_conf_get,
732         .rss_hash_update      = enicpmd_dev_rss_hash_update,
733 };
734
735 struct enic *enicpmd_list_head = NULL;
736 /* Initialize the driver
737  * It returns 0 on success.
738  */
739 static int eth_enicpmd_dev_init(struct rte_eth_dev *eth_dev)
740 {
741         struct rte_pci_device *pdev;
742         struct rte_pci_addr *addr;
743         struct enic *enic = pmd_priv(eth_dev);
744
745         ENICPMD_FUNC_TRACE();
746
747         enic->port_id = eth_dev->data->port_id;
748         enic->rte_dev = eth_dev;
749         eth_dev->dev_ops = &enicpmd_eth_dev_ops;
750         eth_dev->rx_pkt_burst = &enic_recv_pkts;
751         eth_dev->tx_pkt_burst = &enic_xmit_pkts;
752         eth_dev->tx_pkt_prepare = &enic_prep_pkts;
753
754         pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
755         rte_eth_copy_pci_info(eth_dev, pdev);
756         enic->pdev = pdev;
757         addr = &pdev->addr;
758
759         snprintf(enic->bdf_name, ENICPMD_BDF_LENGTH, "%04x:%02x:%02x.%x",
760                 addr->domain, addr->bus, addr->devid, addr->function);
761
762         return enic_probe(enic);
763 }
764
765 static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
766         struct rte_pci_device *pci_dev)
767 {
768         return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct enic),
769                 eth_enicpmd_dev_init);
770 }
771
772 static int eth_enic_pci_remove(struct rte_pci_device *pci_dev)
773 {
774         return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
775 }
776
777 static struct rte_pci_driver rte_enic_pmd = {
778         .id_table = pci_id_enic_map,
779         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
780         .probe = eth_enic_pci_probe,
781         .remove = eth_enic_pci_remove,
782 };
783
784 RTE_PMD_REGISTER_PCI(net_enic, rte_enic_pmd);
785 RTE_PMD_REGISTER_PCI_TABLE(net_enic, pci_id_enic_map);
786 RTE_PMD_REGISTER_KMOD_DEP(net_enic, "* igb_uio | uio_pci_generic | vfio-pci");