net/octeontx: add promiscuous mode ops
[dpdk.git] / drivers / net / octeontx / octeontx_ethdev.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium Inc. 2017. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
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 FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <stdbool.h>
35 #include <stdint.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 #include <rte_alarm.h>
40 #include <rte_branch_prediction.h>
41 #include <rte_debug.h>
42 #include <rte_devargs.h>
43 #include <rte_dev.h>
44 #include <rte_kvargs.h>
45 #include <rte_malloc.h>
46 #include <rte_prefetch.h>
47 #include <rte_vdev.h>
48
49 #include "octeontx_ethdev.h"
50 #include "octeontx_logs.h"
51
52 struct octeontx_vdev_init_params {
53         uint8_t nr_port;
54 };
55
56 enum octeontx_link_speed {
57         OCTEONTX_LINK_SPEED_SGMII,
58         OCTEONTX_LINK_SPEED_XAUI,
59         OCTEONTX_LINK_SPEED_RXAUI,
60         OCTEONTX_LINK_SPEED_10G_R,
61         OCTEONTX_LINK_SPEED_40G_R,
62         OCTEONTX_LINK_SPEED_RESERVE1,
63         OCTEONTX_LINK_SPEED_QSGMII,
64         OCTEONTX_LINK_SPEED_RESERVE2
65 };
66
67 /* Parse integer from integer argument */
68 static int
69 parse_integer_arg(const char *key __rte_unused,
70                 const char *value, void *extra_args)
71 {
72         int *i = (int *)extra_args;
73
74         *i = atoi(value);
75         if (*i < 0) {
76                 octeontx_log_err("argument has to be positive.");
77                 return -1;
78         }
79
80         return 0;
81 }
82
83 static int
84 octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
85                                 struct rte_vdev_device *dev)
86 {
87         struct rte_kvargs *kvlist = NULL;
88         int ret = 0;
89
90         static const char * const octeontx_vdev_valid_params[] = {
91                 OCTEONTX_VDEV_NR_PORT_ARG,
92                 NULL
93         };
94
95         const char *input_args = rte_vdev_device_args(dev);
96         if (params == NULL)
97                 return -EINVAL;
98
99
100         if (input_args) {
101                 kvlist = rte_kvargs_parse(input_args,
102                                 octeontx_vdev_valid_params);
103                 if (kvlist == NULL)
104                         return -1;
105
106                 ret = rte_kvargs_process(kvlist,
107                                         OCTEONTX_VDEV_NR_PORT_ARG,
108                                         &parse_integer_arg,
109                                         &params->nr_port);
110                 if (ret < 0)
111                         goto free_kvlist;
112         }
113
114 free_kvlist:
115         rte_kvargs_free(kvlist);
116         return ret;
117 }
118
119 static int
120 octeontx_port_open(struct octeontx_nic *nic)
121 {
122         octeontx_mbox_bgx_port_conf_t bgx_port_conf;
123         int res;
124
125         res = 0;
126
127         PMD_INIT_FUNC_TRACE();
128
129         res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
130         if (res < 0) {
131                 octeontx_log_err("failed to open port %d", res);
132                 return res;
133         }
134
135         nic->node = bgx_port_conf.node;
136         nic->port_ena = bgx_port_conf.enable;
137         nic->base_ichan = bgx_port_conf.base_chan;
138         nic->base_ochan = bgx_port_conf.base_chan;
139         nic->num_ichans = bgx_port_conf.num_chans;
140         nic->num_ochans = bgx_port_conf.num_chans;
141         nic->mtu = bgx_port_conf.mtu;
142         nic->bpen = bgx_port_conf.bpen;
143         nic->fcs_strip = bgx_port_conf.fcs_strip;
144         nic->bcast_mode = bgx_port_conf.bcast_mode;
145         nic->mcast_mode = bgx_port_conf.mcast_mode;
146         nic->speed      = bgx_port_conf.mode;
147
148         memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
149
150         octeontx_log_dbg("port opened %d", nic->port_id);
151         return res;
152 }
153
154 static void
155 octeontx_port_close(struct octeontx_nic *nic)
156 {
157         PMD_INIT_FUNC_TRACE();
158
159         octeontx_bgx_port_close(nic->port_id);
160         octeontx_log_dbg("port closed %d", nic->port_id);
161 }
162
163 static void
164 octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
165 {
166         struct rte_eth_dev *dev;
167         int res;
168
169         res = 0;
170         PMD_INIT_FUNC_TRACE();
171         dev = nic->dev;
172
173         res = octeontx_bgx_port_promisc_set(nic->port_id, en);
174         if (res < 0)
175                 octeontx_log_err("failed to set promiscuous mode %d",
176                                 nic->port_id);
177
178         /* Set proper flag for the mode */
179         dev->data->promiscuous = (en != 0) ? 1 : 0;
180
181         octeontx_log_dbg("port %d : promiscuous mode %s",
182                         nic->port_id, en ? "set" : "unset");
183 }
184
185 static inline void
186 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
187                                 struct rte_event_dev_info *info)
188 {
189         memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
190         dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
191
192         dev_conf->nb_event_ports = info->max_event_ports;
193         dev_conf->nb_event_queues = info->max_event_queues;
194
195         dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
196         dev_conf->nb_event_port_dequeue_depth =
197                         info->max_event_port_dequeue_depth;
198         dev_conf->nb_event_port_enqueue_depth =
199                         info->max_event_port_enqueue_depth;
200         dev_conf->nb_event_port_enqueue_depth =
201                         info->max_event_port_enqueue_depth;
202         dev_conf->nb_events_limit =
203                         info->max_num_events;
204 }
205
206 static int
207 octeontx_dev_configure(struct rte_eth_dev *dev)
208 {
209         struct rte_eth_dev_data *data = dev->data;
210         struct rte_eth_conf *conf = &data->dev_conf;
211         struct rte_eth_rxmode *rxmode = &conf->rxmode;
212         struct rte_eth_txmode *txmode = &conf->txmode;
213         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
214         int ret;
215
216         PMD_INIT_FUNC_TRACE();
217         RTE_SET_USED(conf);
218
219         if (!rte_eal_has_hugepages()) {
220                 octeontx_log_err("huge page is not configured");
221                 return -EINVAL;
222         }
223
224         if (txmode->mq_mode) {
225                 octeontx_log_err("tx mq_mode DCB or VMDq not supported");
226                 return -EINVAL;
227         }
228
229         if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
230                 rxmode->mq_mode != ETH_MQ_RX_RSS) {
231                 octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
232                 return -EINVAL;
233         }
234
235         if (!rxmode->hw_strip_crc) {
236                 PMD_INIT_LOG(NOTICE, "can't disable hw crc strip");
237                 rxmode->hw_strip_crc = 1;
238         }
239
240         if (rxmode->hw_ip_checksum) {
241                 PMD_INIT_LOG(NOTICE, "rxcksum not supported");
242                 rxmode->hw_ip_checksum = 0;
243         }
244
245         if (rxmode->split_hdr_size) {
246                 octeontx_log_err("rxmode does not support split header");
247                 return -EINVAL;
248         }
249
250         if (rxmode->hw_vlan_filter) {
251                 octeontx_log_err("VLAN filter not supported");
252                 return -EINVAL;
253         }
254
255         if (rxmode->hw_vlan_extend) {
256                 octeontx_log_err("VLAN extended not supported");
257                 return -EINVAL;
258         }
259
260         if (rxmode->enable_lro) {
261                 octeontx_log_err("LRO not supported");
262                 return -EINVAL;
263         }
264
265         if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
266                 octeontx_log_err("setting link speed/duplex not supported");
267                 return -EINVAL;
268         }
269
270         if (conf->dcb_capability_en) {
271                 octeontx_log_err("DCB enable not supported");
272                 return -EINVAL;
273         }
274
275         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
276                 octeontx_log_err("flow director not supported");
277                 return -EINVAL;
278         }
279
280         nic->num_tx_queues = dev->data->nb_tx_queues;
281
282         ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ,
283                                         nic->num_tx_queues,
284                                         nic->base_ochan);
285         if (ret) {
286                 octeontx_log_err("failed to open channel %d no-of-txq %d",
287                            nic->base_ochan, nic->num_tx_queues);
288                 return -EFAULT;
289         }
290
291         nic->pki.classifier_enable = false;
292         nic->pki.hash_enable = true;
293         nic->pki.initialized = false;
294
295         return 0;
296 }
297
298 static void
299 octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
300 {
301         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
302
303         PMD_INIT_FUNC_TRACE();
304         octeontx_port_promisc_set(nic, 1);
305 }
306
307 static void
308 octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
309 {
310         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
311
312         PMD_INIT_FUNC_TRACE();
313         octeontx_port_promisc_set(nic, 0);
314 }
315
316 static inline int
317 octeontx_atomic_write_link_status(struct rte_eth_dev *dev,
318                                   struct rte_eth_link *link)
319 {
320         struct rte_eth_link *dst = &dev->data->dev_link;
321         struct rte_eth_link *src = link;
322
323         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
324                 *(uint64_t *)src) == 0)
325                 return -1;
326
327         return 0;
328 }
329
330 static int
331 octeontx_port_link_status(struct octeontx_nic *nic)
332 {
333         int res;
334
335         PMD_INIT_FUNC_TRACE();
336         res = octeontx_bgx_port_link_status(nic->port_id);
337         if (res < 0) {
338                 octeontx_log_err("failed to get port %d link status",
339                                 nic->port_id);
340                 return res;
341         }
342
343         nic->link_up = (uint8_t)res;
344         octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
345
346         return res;
347 }
348
349 /*
350  * Return 0 means link status changed, -1 means not changed
351  */
352 static int
353 octeontx_dev_link_update(struct rte_eth_dev *dev,
354                          int wait_to_complete __rte_unused)
355 {
356         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
357         struct rte_eth_link link;
358         int res;
359
360         res = 0;
361         PMD_INIT_FUNC_TRACE();
362
363         res = octeontx_port_link_status(nic);
364         if (res < 0) {
365                 octeontx_log_err("failed to request link status %d", res);
366                 return res;
367         }
368
369         link.link_status = nic->link_up;
370
371         switch (nic->speed) {
372         case OCTEONTX_LINK_SPEED_SGMII:
373                 link.link_speed = ETH_SPEED_NUM_1G;
374                 break;
375
376         case OCTEONTX_LINK_SPEED_XAUI:
377                 link.link_speed = ETH_SPEED_NUM_10G;
378                 break;
379
380         case OCTEONTX_LINK_SPEED_RXAUI:
381         case OCTEONTX_LINK_SPEED_10G_R:
382                 link.link_speed = ETH_SPEED_NUM_10G;
383                 break;
384         case OCTEONTX_LINK_SPEED_QSGMII:
385                 link.link_speed = ETH_SPEED_NUM_5G;
386                 break;
387         case OCTEONTX_LINK_SPEED_40G_R:
388                 link.link_speed = ETH_SPEED_NUM_40G;
389                 break;
390
391         case OCTEONTX_LINK_SPEED_RESERVE1:
392         case OCTEONTX_LINK_SPEED_RESERVE2:
393         default:
394                 octeontx_log_err("incorrect link speed %d", nic->speed);
395                 break;
396         }
397
398         link.link_duplex = ETH_LINK_AUTONEG;
399         link.link_autoneg = ETH_LINK_SPEED_AUTONEG;
400
401         return octeontx_atomic_write_link_status(dev, &link);
402 }
403
404 static void
405 octeontx_dev_info(struct rte_eth_dev *dev,
406                 struct rte_eth_dev_info *dev_info)
407 {
408         RTE_SET_USED(dev);
409
410         /* Autonegotiation may be disabled */
411         dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
412         dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
413                         ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
414                         ETH_LINK_SPEED_40G;
415
416         dev_info->driver_name = RTE_STR(rte_octeontx_pmd);
417         dev_info->max_mac_addrs = 1;
418         dev_info->max_rx_pktlen = PKI_MAX_PKTLEN;
419         dev_info->max_rx_queues = 1;
420         dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
421         dev_info->min_rx_bufsize = 0;
422         dev_info->pci_dev = NULL;
423
424         dev_info->default_rxconf = (struct rte_eth_rxconf) {
425                 .rx_free_thresh = 0,
426                 .rx_drop_en = 0,
427         };
428
429         dev_info->default_txconf = (struct rte_eth_txconf) {
430                 .tx_free_thresh = 0,
431                 .txq_flags =
432                         ETH_TXQ_FLAGS_NOMULTSEGS |
433                         ETH_TXQ_FLAGS_NOOFFLOADS |
434                         ETH_TXQ_FLAGS_NOXSUMS,
435         };
436
437         dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE;
438 }
439
440 /* Initialize and register driver with DPDK Application */
441 static const struct eth_dev_ops octeontx_dev_ops = {
442         .dev_configure           = octeontx_dev_configure,
443         .dev_infos_get           = octeontx_dev_info,
444         .promiscuous_enable      = octeontx_dev_promisc_enable,
445         .promiscuous_disable     = octeontx_dev_promisc_disable,
446         .link_update             = octeontx_dev_link_update,
447 };
448
449 /* Create Ethdev interface per BGX LMAC ports */
450 static int
451 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
452                         int socket_id)
453 {
454         int res;
455         char octtx_name[OCTEONTX_MAX_NAME_LEN];
456         struct octeontx_nic *nic = NULL;
457         struct rte_eth_dev *eth_dev = NULL;
458         struct rte_eth_dev_data *data = NULL;
459         const char *name = rte_vdev_device_name(dev);
460
461         PMD_INIT_FUNC_TRACE();
462
463         sprintf(octtx_name, "%s_%d", name, port);
464         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
465                 eth_dev = rte_eth_dev_attach_secondary(octtx_name);
466                 if (eth_dev == NULL)
467                         return -ENODEV;
468
469                 return 0;
470         }
471
472         data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
473         if (data == NULL) {
474                 octeontx_log_err("failed to allocate devdata");
475                 res = -ENOMEM;
476                 goto err;
477         }
478
479         nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
480         if (nic == NULL) {
481                 octeontx_log_err("failed to allocate nic structure");
482                 res = -ENOMEM;
483                 goto err;
484         }
485
486         nic->port_id = port;
487         nic->evdev = evdev;
488
489         res = octeontx_port_open(nic);
490         if (res < 0)
491                 goto err;
492
493         /* Rx side port configuration */
494         res = octeontx_pki_port_open(port);
495         if (res != 0) {
496                 octeontx_log_err("failed to open PKI port %d", port);
497                 res = -ENODEV;
498                 goto err;
499         }
500
501         /* Reserve an ethdev entry */
502         eth_dev = rte_eth_dev_allocate(octtx_name);
503         if (eth_dev == NULL) {
504                 octeontx_log_err("failed to allocate rte_eth_dev");
505                 res = -ENOMEM;
506                 goto err;
507         }
508
509         eth_dev->device = &dev->device;
510         eth_dev->intr_handle = NULL;
511         eth_dev->data->kdrv = RTE_KDRV_NONE;
512         eth_dev->data->numa_node = dev->device.numa_node;
513
514         rte_memcpy(data, (eth_dev)->data, sizeof(*data));
515         data->dev_private = nic;
516
517         data->port_id = eth_dev->data->port_id;
518         snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
519
520         nic->ev_queues = 1;
521         nic->ev_ports = 1;
522
523         data->dev_link.link_status = ETH_LINK_DOWN;
524         data->dev_started = 0;
525         data->promiscuous = 0;
526         data->all_multicast = 0;
527         data->scattered_rx = 0;
528
529         data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
530                                                         socket_id);
531         if (data->mac_addrs == NULL) {
532                 octeontx_log_err("failed to allocate memory for mac_addrs");
533                 res = -ENOMEM;
534                 goto err;
535         }
536
537         eth_dev->data = data;
538         eth_dev->dev_ops = &octeontx_dev_ops;
539
540         /* Finally save ethdev pointer to the NIC structure */
541         nic->dev = eth_dev;
542
543         if (nic->port_id != data->port_id) {
544                 octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
545                                 data->port_id, nic->port_id);
546                 res = -EINVAL;
547                 goto err;
548         }
549
550         /* Update port_id mac to eth_dev */
551         memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
552
553         PMD_INIT_LOG(DEBUG, "ethdev info: ");
554         PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
555                                 nic->port_id, nic->port_ena,
556                                 nic->base_ochan, nic->num_ochans,
557                                 nic->num_tx_queues);
558         PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
559
560         return data->port_id;
561
562 err:
563         if (port)
564                 octeontx_port_close(nic);
565
566         if (eth_dev != NULL) {
567                 rte_free(eth_dev->data->mac_addrs);
568                 rte_free(data);
569                 rte_free(nic);
570                 rte_eth_dev_release_port(eth_dev);
571         }
572
573         return res;
574 }
575
576 /* Un initialize octeontx device */
577 static int
578 octeontx_remove(struct rte_vdev_device *dev)
579 {
580         char octtx_name[OCTEONTX_MAX_NAME_LEN];
581         struct rte_eth_dev *eth_dev = NULL;
582         struct octeontx_nic *nic = NULL;
583         int i;
584
585         if (dev == NULL)
586                 return -EINVAL;
587
588         for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
589                 sprintf(octtx_name, "eth_octeontx_%d", i);
590
591                 /* reserve an ethdev entry */
592                 eth_dev = rte_eth_dev_allocated(octtx_name);
593                 if (eth_dev == NULL)
594                         return -ENODEV;
595
596                 nic = octeontx_pmd_priv(eth_dev);
597                 rte_event_dev_stop(nic->evdev);
598                 PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
599
600                 rte_free(eth_dev->data->mac_addrs);
601                 rte_free(eth_dev->data->dev_private);
602                 rte_free(eth_dev->data);
603                 rte_eth_dev_release_port(eth_dev);
604                 rte_event_dev_close(nic->evdev);
605         }
606
607         /* Free FC resource */
608         octeontx_pko_fc_free();
609
610         return 0;
611 }
612
613 /* Initialize octeontx device */
614 static int
615 octeontx_probe(struct rte_vdev_device *dev)
616 {
617         const char *dev_name;
618         static int probe_once;
619         uint8_t socket_id, qlist;
620         int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
621         struct rte_event_dev_config dev_conf;
622         const char *eventdev_name = "event_octeontx";
623         struct rte_event_dev_info info;
624
625         struct octeontx_vdev_init_params init_params = {
626                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
627         };
628
629         dev_name = rte_vdev_device_name(dev);
630         res = octeontx_parse_vdev_init_params(&init_params, dev);
631         if (res < 0)
632                 return -EINVAL;
633
634         if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
635                 octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
636                                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
637                 return -ENOTSUP;
638         }
639
640         PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
641
642         socket_id = rte_socket_id();
643
644         tx_vfcnt = octeontx_pko_vf_count();
645
646         if (tx_vfcnt < init_params.nr_port) {
647                 octeontx_log_err("not enough PKO (%d) for port number (%d)",
648                                 tx_vfcnt, init_params.nr_port);
649                 return -EINVAL;
650         }
651         evdev = rte_event_dev_get_dev_id(eventdev_name);
652         if (evdev < 0) {
653                 octeontx_log_err("eventdev %s not found", eventdev_name);
654                 return -ENODEV;
655         }
656
657         res = rte_event_dev_info_get(evdev, &info);
658         if (res < 0) {
659                 octeontx_log_err("failed to eventdev info %d", res);
660                 return -EINVAL;
661         }
662
663         PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
664                         info.max_event_queues, info.max_event_ports);
665
666         if (octeontx_pko_init_fc(tx_vfcnt))
667                 return -ENOMEM;
668
669         devconf_set_default_sane_values(&dev_conf, &info);
670         res = rte_event_dev_configure(evdev, &dev_conf);
671         if (res < 0)
672                 goto parse_error;
673
674         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
675                         (uint32_t *)&pnum);
676         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
677                         (uint32_t *)&qnum);
678         if (pnum < qnum) {
679                 octeontx_log_err("too few event ports (%d) for event_q(%d)",
680                                 pnum, qnum);
681                 res = -EINVAL;
682                 goto parse_error;
683         }
684         if (pnum > qnum) {
685                 /*
686                  * We don't poll on event ports
687                  * that do not have any queues assigned.
688                  */
689                 pnum = qnum;
690                 PMD_INIT_LOG(INFO,
691                         "reducing number of active event ports to %d", pnum);
692         }
693         for (i = 0; i < qnum; i++) {
694                 res = rte_event_queue_setup(evdev, i, NULL);
695                 if (res < 0) {
696                         octeontx_log_err("failed to setup event_q(%d): res %d",
697                                         i, res);
698                         goto parse_error;
699                 }
700         }
701
702         for (i = 0; i < pnum; i++) {
703                 res = rte_event_port_setup(evdev, i, NULL);
704                 if (res < 0) {
705                         res = -ENODEV;
706                         octeontx_log_err("failed to setup ev port(%d) res=%d",
707                                                 i, res);
708                         goto parse_error;
709                 }
710                 /* Link one queue to one event port */
711                 qlist = i;
712                 res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
713                 if (res < 0) {
714                         res = -ENODEV;
715                         octeontx_log_err("failed to link port (%d): res=%d",
716                                         i, res);
717                         goto parse_error;
718                 }
719         }
720
721         /* Create ethdev interface */
722         for (i = 0; i < init_params.nr_port; i++) {
723                 port_id = octeontx_create(dev, i, evdev, socket_id);
724                 if (port_id < 0) {
725                         octeontx_log_err("failed to create device %s",
726                                         dev_name);
727                         res = -ENODEV;
728                         goto parse_error;
729                 }
730
731                 PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
732                                         port_id);
733         }
734
735         if (probe_once) {
736                 octeontx_log_err("interface %s not supported", dev_name);
737                 octeontx_remove(dev);
738                 res = -ENOTSUP;
739                 goto parse_error;
740         }
741         probe_once = 1;
742
743         return 0;
744
745 parse_error:
746         octeontx_pko_fc_free();
747         return res;
748 }
749
750 static struct rte_vdev_driver octeontx_pmd_drv = {
751         .probe = octeontx_probe,
752         .remove = octeontx_remove,
753 };
754
755 RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
756 RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
757 RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");