New upstream version 17.11.4
[deb_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_bus_vdev.h>
48
49 #include "octeontx_ethdev.h"
50 #include "octeontx_rxtx.h"
51 #include "octeontx_logs.h"
52
53 struct octeontx_vdev_init_params {
54         uint8_t nr_port;
55 };
56
57 uint16_t
58 rte_octeontx_pchan_map[OCTEONTX_MAX_BGX_PORTS][OCTEONTX_MAX_LMAC_PER_BGX];
59
60 enum octeontx_link_speed {
61         OCTEONTX_LINK_SPEED_SGMII,
62         OCTEONTX_LINK_SPEED_XAUI,
63         OCTEONTX_LINK_SPEED_RXAUI,
64         OCTEONTX_LINK_SPEED_10G_R,
65         OCTEONTX_LINK_SPEED_40G_R,
66         OCTEONTX_LINK_SPEED_RESERVE1,
67         OCTEONTX_LINK_SPEED_QSGMII,
68         OCTEONTX_LINK_SPEED_RESERVE2
69 };
70
71 /* Parse integer from integer argument */
72 static int
73 parse_integer_arg(const char *key __rte_unused,
74                 const char *value, void *extra_args)
75 {
76         int *i = (int *)extra_args;
77
78         *i = atoi(value);
79         if (*i < 0) {
80                 octeontx_log_err("argument has to be positive.");
81                 return -1;
82         }
83
84         return 0;
85 }
86
87 static int
88 octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
89                                 struct rte_vdev_device *dev)
90 {
91         struct rte_kvargs *kvlist = NULL;
92         int ret = 0;
93
94         static const char * const octeontx_vdev_valid_params[] = {
95                 OCTEONTX_VDEV_NR_PORT_ARG,
96                 NULL
97         };
98
99         const char *input_args = rte_vdev_device_args(dev);
100         if (params == NULL)
101                 return -EINVAL;
102
103
104         if (input_args) {
105                 kvlist = rte_kvargs_parse(input_args,
106                                 octeontx_vdev_valid_params);
107                 if (kvlist == NULL)
108                         return -1;
109
110                 ret = rte_kvargs_process(kvlist,
111                                         OCTEONTX_VDEV_NR_PORT_ARG,
112                                         &parse_integer_arg,
113                                         &params->nr_port);
114                 if (ret < 0)
115                         goto free_kvlist;
116         }
117
118 free_kvlist:
119         rte_kvargs_free(kvlist);
120         return ret;
121 }
122
123 static int
124 octeontx_port_open(struct octeontx_nic *nic)
125 {
126         octeontx_mbox_bgx_port_conf_t bgx_port_conf;
127         int res;
128
129         res = 0;
130         memset(&bgx_port_conf, 0x0, sizeof(bgx_port_conf));
131         PMD_INIT_FUNC_TRACE();
132
133         res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
134         if (res < 0) {
135                 octeontx_log_err("failed to open port %d", res);
136                 return res;
137         }
138
139         nic->node = bgx_port_conf.node;
140         nic->port_ena = bgx_port_conf.enable;
141         nic->base_ichan = bgx_port_conf.base_chan;
142         nic->base_ochan = bgx_port_conf.base_chan;
143         nic->num_ichans = bgx_port_conf.num_chans;
144         nic->num_ochans = bgx_port_conf.num_chans;
145         nic->mtu = bgx_port_conf.mtu;
146         nic->bpen = bgx_port_conf.bpen;
147         nic->fcs_strip = bgx_port_conf.fcs_strip;
148         nic->bcast_mode = bgx_port_conf.bcast_mode;
149         nic->mcast_mode = bgx_port_conf.mcast_mode;
150         nic->speed      = bgx_port_conf.mode;
151
152         memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
153
154         octeontx_log_dbg("port opened %d", nic->port_id);
155         return res;
156 }
157
158 static void
159 octeontx_port_close(struct octeontx_nic *nic)
160 {
161         PMD_INIT_FUNC_TRACE();
162
163         octeontx_bgx_port_close(nic->port_id);
164         octeontx_log_dbg("port closed %d", nic->port_id);
165 }
166
167 static int
168 octeontx_port_start(struct octeontx_nic *nic)
169 {
170         PMD_INIT_FUNC_TRACE();
171
172         return octeontx_bgx_port_start(nic->port_id);
173 }
174
175 static int
176 octeontx_port_stop(struct octeontx_nic *nic)
177 {
178         PMD_INIT_FUNC_TRACE();
179
180         return octeontx_bgx_port_stop(nic->port_id);
181 }
182
183 static void
184 octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
185 {
186         struct rte_eth_dev *dev;
187         int res;
188
189         res = 0;
190         PMD_INIT_FUNC_TRACE();
191         dev = nic->dev;
192
193         res = octeontx_bgx_port_promisc_set(nic->port_id, en);
194         if (res < 0)
195                 octeontx_log_err("failed to set promiscuous mode %d",
196                                 nic->port_id);
197
198         /* Set proper flag for the mode */
199         dev->data->promiscuous = (en != 0) ? 1 : 0;
200
201         octeontx_log_dbg("port %d : promiscuous mode %s",
202                         nic->port_id, en ? "set" : "unset");
203 }
204
205 static int
206 octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats)
207 {
208         octeontx_mbox_bgx_port_stats_t bgx_stats;
209         int res;
210
211         PMD_INIT_FUNC_TRACE();
212
213         res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats);
214         if (res < 0) {
215                 octeontx_log_err("failed to get port stats %d", nic->port_id);
216                 return res;
217         }
218
219         stats->ipackets = bgx_stats.rx_packets;
220         stats->ibytes = bgx_stats.rx_bytes;
221         stats->imissed = bgx_stats.rx_dropped;
222         stats->ierrors = bgx_stats.rx_errors;
223         stats->opackets = bgx_stats.tx_packets;
224         stats->obytes = bgx_stats.tx_bytes;
225         stats->oerrors = bgx_stats.tx_errors;
226
227         octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "",
228                         nic->port_id, stats->ipackets, stats->opackets);
229
230         return 0;
231 }
232
233 static void
234 octeontx_port_stats_clr(struct octeontx_nic *nic)
235 {
236         PMD_INIT_FUNC_TRACE();
237
238         octeontx_bgx_port_stats_clr(nic->port_id);
239 }
240
241 static inline void
242 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
243                                 struct rte_event_dev_info *info)
244 {
245         memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
246         dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
247
248         dev_conf->nb_event_ports = info->max_event_ports;
249         dev_conf->nb_event_queues = info->max_event_queues;
250
251         dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
252         dev_conf->nb_event_port_dequeue_depth =
253                         info->max_event_port_dequeue_depth;
254         dev_conf->nb_event_port_enqueue_depth =
255                         info->max_event_port_enqueue_depth;
256         dev_conf->nb_event_port_enqueue_depth =
257                         info->max_event_port_enqueue_depth;
258         dev_conf->nb_events_limit =
259                         info->max_num_events;
260 }
261
262 static int
263 octeontx_dev_configure(struct rte_eth_dev *dev)
264 {
265         struct rte_eth_dev_data *data = dev->data;
266         struct rte_eth_conf *conf = &data->dev_conf;
267         struct rte_eth_rxmode *rxmode = &conf->rxmode;
268         struct rte_eth_txmode *txmode = &conf->txmode;
269         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
270         int ret;
271
272         PMD_INIT_FUNC_TRACE();
273         RTE_SET_USED(conf);
274
275         if (!rte_eal_has_hugepages()) {
276                 octeontx_log_err("huge page is not configured");
277                 return -EINVAL;
278         }
279
280         if (txmode->mq_mode) {
281                 octeontx_log_err("tx mq_mode DCB or VMDq not supported");
282                 return -EINVAL;
283         }
284
285         if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
286                 rxmode->mq_mode != ETH_MQ_RX_RSS) {
287                 octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
288                 return -EINVAL;
289         }
290
291         if (!rxmode->hw_strip_crc) {
292                 PMD_INIT_LOG(NOTICE, "can't disable hw crc strip");
293                 rxmode->hw_strip_crc = 1;
294         }
295
296         if (rxmode->hw_ip_checksum) {
297                 PMD_INIT_LOG(NOTICE, "rxcksum not supported");
298                 rxmode->hw_ip_checksum = 0;
299         }
300
301         if (rxmode->split_hdr_size) {
302                 octeontx_log_err("rxmode does not support split header");
303                 return -EINVAL;
304         }
305
306         if (rxmode->hw_vlan_filter) {
307                 octeontx_log_err("VLAN filter not supported");
308                 return -EINVAL;
309         }
310
311         if (rxmode->hw_vlan_extend) {
312                 octeontx_log_err("VLAN extended not supported");
313                 return -EINVAL;
314         }
315
316         if (rxmode->enable_lro) {
317                 octeontx_log_err("LRO not supported");
318                 return -EINVAL;
319         }
320
321         if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
322                 octeontx_log_err("setting link speed/duplex not supported");
323                 return -EINVAL;
324         }
325
326         if (conf->dcb_capability_en) {
327                 octeontx_log_err("DCB enable not supported");
328                 return -EINVAL;
329         }
330
331         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
332                 octeontx_log_err("flow director not supported");
333                 return -EINVAL;
334         }
335
336         nic->num_tx_queues = dev->data->nb_tx_queues;
337
338         ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ,
339                                         nic->num_tx_queues,
340                                         nic->base_ochan);
341         if (ret) {
342                 octeontx_log_err("failed to open channel %d no-of-txq %d",
343                            nic->base_ochan, nic->num_tx_queues);
344                 return -EFAULT;
345         }
346
347         nic->pki.classifier_enable = false;
348         nic->pki.hash_enable = true;
349         nic->pki.initialized = false;
350
351         return 0;
352 }
353
354 static void
355 octeontx_dev_close(struct rte_eth_dev *dev)
356 {
357         struct octeontx_txq *txq = NULL;
358         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
359         unsigned int i;
360         int ret;
361
362         PMD_INIT_FUNC_TRACE();
363
364         rte_event_dev_close(nic->evdev);
365
366         ret = octeontx_pko_channel_close(nic->base_ochan);
367         if (ret < 0) {
368                 octeontx_log_err("failed to close channel %d VF%d %d %d",
369                              nic->base_ochan, nic->port_id, nic->num_tx_queues,
370                              ret);
371         }
372         /* Free txq resources for this port */
373         for (i = 0; i < nic->num_tx_queues; i++) {
374                 txq = dev->data->tx_queues[i];
375                 if (!txq)
376                         continue;
377
378                 rte_free(txq);
379         }
380
381         dev->tx_pkt_burst = NULL;
382         dev->rx_pkt_burst = NULL;
383 }
384
385 static int
386 octeontx_dev_start(struct rte_eth_dev *dev)
387 {
388         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
389         int ret;
390
391         ret = 0;
392
393         PMD_INIT_FUNC_TRACE();
394         /*
395          * Tx start
396          */
397         dev->tx_pkt_burst = octeontx_xmit_pkts;
398         ret = octeontx_pko_channel_start(nic->base_ochan);
399         if (ret < 0) {
400                 octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d",
401                            nic->port_id, nic->num_tx_queues, nic->base_ochan,
402                            ret);
403                 goto error;
404         }
405
406         /*
407          * Rx start
408          */
409         dev->rx_pkt_burst = octeontx_recv_pkts;
410         ret = octeontx_pki_port_start(nic->port_id);
411         if (ret < 0) {
412                 octeontx_log_err("fail to start Rx on port %d", nic->port_id);
413                 goto channel_stop_error;
414         }
415
416         /*
417          * Start port
418          */
419         ret = octeontx_port_start(nic);
420         if (ret < 0) {
421                 octeontx_log_err("failed start port %d", ret);
422                 goto pki_port_stop_error;
423         }
424
425         PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d",
426                         nic->base_ochan, nic->num_tx_queues, nic->port_id);
427
428         ret = rte_event_dev_start(nic->evdev);
429         if (ret < 0) {
430                 octeontx_log_err("failed to start evdev: ret (%d)", ret);
431                 goto pki_port_stop_error;
432         }
433
434         /* Success */
435         return ret;
436
437 pki_port_stop_error:
438         octeontx_pki_port_stop(nic->port_id);
439 channel_stop_error:
440         octeontx_pko_channel_stop(nic->base_ochan);
441 error:
442         return ret;
443 }
444
445 static void
446 octeontx_dev_stop(struct rte_eth_dev *dev)
447 {
448         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
449         int ret;
450
451         PMD_INIT_FUNC_TRACE();
452
453         rte_event_dev_stop(nic->evdev);
454
455         ret = octeontx_port_stop(nic);
456         if (ret < 0) {
457                 octeontx_log_err("failed to req stop port %d res=%d",
458                                         nic->port_id, ret);
459                 return;
460         }
461
462         ret = octeontx_pki_port_stop(nic->port_id);
463         if (ret < 0) {
464                 octeontx_log_err("failed to stop pki port %d res=%d",
465                                         nic->port_id, ret);
466                 return;
467         }
468
469         ret = octeontx_pko_channel_stop(nic->base_ochan);
470         if (ret < 0) {
471                 octeontx_log_err("failed to stop channel %d VF%d %d %d",
472                              nic->base_ochan, nic->port_id, nic->num_tx_queues,
473                              ret);
474                 return;
475         }
476 }
477
478 static void
479 octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
480 {
481         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
482
483         PMD_INIT_FUNC_TRACE();
484         octeontx_port_promisc_set(nic, 1);
485 }
486
487 static void
488 octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
489 {
490         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
491
492         PMD_INIT_FUNC_TRACE();
493         octeontx_port_promisc_set(nic, 0);
494 }
495
496 static inline int
497 octeontx_atomic_write_link_status(struct rte_eth_dev *dev,
498                                   struct rte_eth_link *link)
499 {
500         struct rte_eth_link *dst = &dev->data->dev_link;
501         struct rte_eth_link *src = link;
502
503         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
504                 *(uint64_t *)src) == 0)
505                 return -1;
506
507         return 0;
508 }
509
510 static int
511 octeontx_port_link_status(struct octeontx_nic *nic)
512 {
513         int res;
514
515         PMD_INIT_FUNC_TRACE();
516         res = octeontx_bgx_port_link_status(nic->port_id);
517         if (res < 0) {
518                 octeontx_log_err("failed to get port %d link status",
519                                 nic->port_id);
520                 return res;
521         }
522
523         nic->link_up = (uint8_t)res;
524         octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
525
526         return res;
527 }
528
529 /*
530  * Return 0 means link status changed, -1 means not changed
531  */
532 static int
533 octeontx_dev_link_update(struct rte_eth_dev *dev,
534                          int wait_to_complete __rte_unused)
535 {
536         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
537         struct rte_eth_link link;
538         int res;
539
540         PMD_INIT_FUNC_TRACE();
541
542         res = octeontx_port_link_status(nic);
543         if (res < 0) {
544                 octeontx_log_err("failed to request link status %d", res);
545                 return res;
546         }
547
548         link.link_status = nic->link_up;
549
550         switch (nic->speed) {
551         case OCTEONTX_LINK_SPEED_SGMII:
552                 link.link_speed = ETH_SPEED_NUM_1G;
553                 break;
554
555         case OCTEONTX_LINK_SPEED_XAUI:
556                 link.link_speed = ETH_SPEED_NUM_10G;
557                 break;
558
559         case OCTEONTX_LINK_SPEED_RXAUI:
560         case OCTEONTX_LINK_SPEED_10G_R:
561                 link.link_speed = ETH_SPEED_NUM_10G;
562                 break;
563         case OCTEONTX_LINK_SPEED_QSGMII:
564                 link.link_speed = ETH_SPEED_NUM_5G;
565                 break;
566         case OCTEONTX_LINK_SPEED_40G_R:
567                 link.link_speed = ETH_SPEED_NUM_40G;
568                 break;
569
570         case OCTEONTX_LINK_SPEED_RESERVE1:
571         case OCTEONTX_LINK_SPEED_RESERVE2:
572         default:
573                 link.link_speed = ETH_SPEED_NUM_NONE;
574                 octeontx_log_err("incorrect link speed %d", nic->speed);
575                 break;
576         }
577
578         link.link_duplex = ETH_LINK_FULL_DUPLEX;
579         link.link_autoneg = ETH_LINK_AUTONEG;
580
581         return octeontx_atomic_write_link_status(dev, &link);
582 }
583
584 static int
585 octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
586 {
587         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
588
589         PMD_INIT_FUNC_TRACE();
590         return octeontx_port_stats(nic, stats);
591 }
592
593 static void
594 octeontx_dev_stats_reset(struct rte_eth_dev *dev)
595 {
596         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
597
598         PMD_INIT_FUNC_TRACE();
599         octeontx_port_stats_clr(nic);
600 }
601
602 static void
603 octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
604                                         struct ether_addr *addr)
605 {
606         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
607         int ret;
608
609         ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
610         if (ret != 0)
611                 octeontx_log_err("failed to set MAC address on port %d",
612                                 nic->port_id);
613 }
614
615 static void
616 octeontx_dev_info(struct rte_eth_dev *dev,
617                 struct rte_eth_dev_info *dev_info)
618 {
619         RTE_SET_USED(dev);
620
621         /* Autonegotiation may be disabled */
622         dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
623         dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
624                         ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
625                         ETH_LINK_SPEED_40G;
626
627         dev_info->driver_name = RTE_STR(rte_octeontx_pmd);
628         dev_info->max_mac_addrs = 1;
629         dev_info->max_rx_pktlen = PKI_MAX_PKTLEN;
630         dev_info->max_rx_queues = 1;
631         dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
632         dev_info->min_rx_bufsize = 0;
633         dev_info->pci_dev = NULL;
634
635         dev_info->default_rxconf = (struct rte_eth_rxconf) {
636                 .rx_free_thresh = 0,
637                 .rx_drop_en = 0,
638         };
639
640         dev_info->default_txconf = (struct rte_eth_txconf) {
641                 .tx_free_thresh = 0,
642                 .txq_flags =
643                         ETH_TXQ_FLAGS_NOMULTSEGS |
644                         ETH_TXQ_FLAGS_NOOFFLOADS |
645                         ETH_TXQ_FLAGS_NOXSUMS,
646         };
647
648         dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE;
649 }
650
651 static void
652 octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
653 {
654         ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
655         ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
656         ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
657 }
658
659 static int
660 octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
661                                 uint16_t qidx)
662 {
663         struct octeontx_txq *txq;
664         int res;
665
666         PMD_INIT_FUNC_TRACE();
667
668         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
669                 return 0;
670
671         txq = dev->data->tx_queues[qidx];
672
673         res = octeontx_pko_channel_query_dqs(nic->base_ochan,
674                                                 &txq->dq,
675                                                 sizeof(octeontx_dq_t),
676                                                 txq->queue_id,
677                                                 octeontx_dq_info_getter);
678         if (res < 0) {
679                 res = -EFAULT;
680                 goto close_port;
681         }
682
683         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
684         return res;
685
686 close_port:
687         (void)octeontx_port_stop(nic);
688         octeontx_pko_channel_stop(nic->base_ochan);
689         octeontx_pko_channel_close(nic->base_ochan);
690         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
691         return res;
692 }
693
694 static int
695 octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
696 {
697         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
698
699         PMD_INIT_FUNC_TRACE();
700         qidx = qidx % PKO_VF_NUM_DQ;
701         return octeontx_vf_start_tx_queue(dev, nic, qidx);
702 }
703
704 static inline int
705 octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
706                           uint16_t qidx)
707 {
708         int ret = 0;
709
710         RTE_SET_USED(nic);
711         PMD_INIT_FUNC_TRACE();
712
713         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
714                 return 0;
715
716         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
717         return ret;
718 }
719
720 static int
721 octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
722 {
723         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
724
725         PMD_INIT_FUNC_TRACE();
726         qidx = qidx % PKO_VF_NUM_DQ;
727
728         return octeontx_vf_stop_tx_queue(dev, nic, qidx);
729 }
730
731 static void
732 octeontx_dev_tx_queue_release(void *tx_queue)
733 {
734         struct octeontx_txq *txq = tx_queue;
735         int res;
736
737         PMD_INIT_FUNC_TRACE();
738
739         if (txq) {
740                 res = octeontx_dev_tx_queue_stop(txq->eth_dev, txq->queue_id);
741                 if (res < 0)
742                         octeontx_log_err("failed stop tx_queue(%d)\n",
743                                    txq->queue_id);
744
745                 rte_free(txq);
746         }
747 }
748
749 static int
750 octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
751                             uint16_t nb_desc, unsigned int socket_id,
752                             const struct rte_eth_txconf *tx_conf)
753 {
754         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
755         struct octeontx_txq *txq = NULL;
756         uint16_t dq_num;
757         int res = 0;
758
759         RTE_SET_USED(nb_desc);
760         RTE_SET_USED(socket_id);
761         RTE_SET_USED(tx_conf);
762
763         dq_num = (nic->port_id * PKO_VF_NUM_DQ) + qidx;
764
765         /* Socket id check */
766         if (socket_id != (unsigned int)SOCKET_ID_ANY &&
767                         socket_id != (unsigned int)nic->node)
768                 PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
769                                                 socket_id, nic->node);
770
771         /* Free memory prior to re-allocation if needed. */
772         if (dev->data->tx_queues[qidx] != NULL) {
773                 PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
774                                 qidx);
775                 octeontx_dev_tx_queue_release(dev->data->tx_queues[qidx]);
776                 dev->data->tx_queues[qidx] = NULL;
777         }
778
779         /* Allocating tx queue data structure */
780         txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
781                                  RTE_CACHE_LINE_SIZE, nic->node);
782         if (txq == NULL) {
783                 octeontx_log_err("failed to allocate txq=%d", qidx);
784                 res = -ENOMEM;
785                 goto err;
786         }
787
788         txq->eth_dev = dev;
789         txq->queue_id = dq_num;
790         dev->data->tx_queues[qidx] = txq;
791         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
792
793         res = octeontx_pko_channel_query_dqs(nic->base_ochan,
794                                                 &txq->dq,
795                                                 sizeof(octeontx_dq_t),
796                                                 txq->queue_id,
797                                                 octeontx_dq_info_getter);
798         if (res < 0) {
799                 res = -EFAULT;
800                 goto err;
801         }
802
803         PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
804                         qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
805                         txq->dq.ioreg_va,
806                         txq->dq.fc_status_va);
807
808         return res;
809
810 err:
811         if (txq)
812                 rte_free(txq);
813
814         return res;
815 }
816
817 static int
818 octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
819                                 uint16_t nb_desc, unsigned int socket_id,
820                                 const struct rte_eth_rxconf *rx_conf,
821                                 struct rte_mempool *mb_pool)
822 {
823         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
824         struct rte_mempool_ops *mp_ops = NULL;
825         struct octeontx_rxq *rxq = NULL;
826         pki_pktbuf_cfg_t pktbuf_conf;
827         pki_hash_cfg_t pki_hash;
828         pki_qos_cfg_t pki_qos;
829         uintptr_t pool;
830         int ret, port;
831         uint8_t gaura;
832         unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
833         unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
834
835         RTE_SET_USED(nb_desc);
836
837         memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
838         memset(&pki_hash, 0, sizeof(pki_hash));
839         memset(&pki_qos, 0, sizeof(pki_qos));
840
841         mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
842         if (strcmp(mp_ops->name, "octeontx_fpavf")) {
843                 octeontx_log_err("failed to find octeontx_fpavf mempool");
844                 return -ENOTSUP;
845         }
846
847         /* Handle forbidden configurations */
848         if (nic->pki.classifier_enable) {
849                 octeontx_log_err("cannot setup queue %d. "
850                                         "Classifier option unsupported", qidx);
851                 return -EINVAL;
852         }
853
854         port = nic->port_id;
855
856         /* Rx deferred start is not supported */
857         if (rx_conf->rx_deferred_start) {
858                 octeontx_log_err("rx deferred start not supported");
859                 return -EINVAL;
860         }
861
862         /* Verify queue index */
863         if (qidx >= dev->data->nb_rx_queues) {
864                 octeontx_log_err("QID %d not supporteded (0 - %d available)\n",
865                                 qidx, (dev->data->nb_rx_queues - 1));
866                 return -ENOTSUP;
867         }
868
869         /* Socket id check */
870         if (socket_id != (unsigned int)SOCKET_ID_ANY &&
871                         socket_id != (unsigned int)nic->node)
872                 PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
873                                                 socket_id, nic->node);
874
875         /* Allocating rx queue data structure */
876         rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
877                                  RTE_CACHE_LINE_SIZE, nic->node);
878         if (rxq == NULL) {
879                 octeontx_log_err("failed to allocate rxq=%d", qidx);
880                 return -ENOMEM;
881         }
882
883         if (!nic->pki.initialized) {
884                 pktbuf_conf.port_type = 0;
885                 pki_hash.port_type = 0;
886                 pki_qos.port_type = 0;
887
888                 pktbuf_conf.mmask.f_wqe_skip = 1;
889                 pktbuf_conf.mmask.f_first_skip = 1;
890                 pktbuf_conf.mmask.f_later_skip = 1;
891                 pktbuf_conf.mmask.f_mbuff_size = 1;
892                 pktbuf_conf.mmask.f_cache_mode = 1;
893
894                 pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
895                 pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP;
896                 pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
897                 pktbuf_conf.mbuff_size = (mb_pool->elt_size -
898                                         RTE_PKTMBUF_HEADROOM -
899                                         sizeof(struct rte_mbuf));
900
901                 pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
902
903                 ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
904                 if (ret != 0) {
905                         octeontx_log_err("fail to configure pktbuf for port %d",
906                                         port);
907                         rte_free(rxq);
908                         return ret;
909                 }
910                 PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n"
911                                 "\tmbuf_size:\t0x%0x\n"
912                                 "\twqe_skip:\t0x%0x\n"
913                                 "\tfirst_skip:\t0x%0x\n"
914                                 "\tlater_skip:\t0x%0x\n"
915                                 "\tcache_mode:\t%s\n",
916                                 port,
917                                 pktbuf_conf.mbuff_size,
918                                 pktbuf_conf.wqe_skip,
919                                 pktbuf_conf.first_skip,
920                                 pktbuf_conf.later_skip,
921                                 (pktbuf_conf.cache_mode ==
922                                                 PKI_OPC_MODE_STT) ?
923                                 "STT" :
924                                 (pktbuf_conf.cache_mode ==
925                                                 PKI_OPC_MODE_STF) ?
926                                 "STF" :
927                                 (pktbuf_conf.cache_mode ==
928                                                 PKI_OPC_MODE_STF1_STT) ?
929                                 "STF1_STT" : "STF2_STT");
930
931                 if (nic->pki.hash_enable) {
932                         pki_hash.tag_dlc = 1;
933                         pki_hash.tag_slc = 1;
934                         pki_hash.tag_dlf = 1;
935                         pki_hash.tag_slf = 1;
936                         pki_hash.tag_prt = 1;
937                         octeontx_pki_port_hash_config(port, &pki_hash);
938                 }
939
940                 pool = (uintptr_t)mb_pool->pool_id;
941
942                 /* Get the gpool Id */
943                 gaura = octeontx_fpa_bufpool_gpool(pool);
944
945                 pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
946                 pki_qos.num_entry = 1;
947                 pki_qos.drop_policy = 0;
948                 pki_qos.tag_type = 0L;
949                 pki_qos.qos_entry[0].port_add = 0;
950                 pki_qos.qos_entry[0].gaura = gaura;
951                 pki_qos.qos_entry[0].ggrp_ok = ev_queues;
952                 pki_qos.qos_entry[0].ggrp_bad = ev_queues;
953                 pki_qos.qos_entry[0].grptag_bad = 0;
954                 pki_qos.qos_entry[0].grptag_ok = 0;
955
956                 ret = octeontx_pki_port_create_qos(port, &pki_qos);
957                 if (ret < 0) {
958                         octeontx_log_err("failed to create QOS port=%d, q=%d",
959                                         port, qidx);
960                         rte_free(rxq);
961                         return ret;
962                 }
963                 nic->pki.initialized = true;
964         }
965
966         rxq->port_id = nic->port_id;
967         rxq->eth_dev = dev;
968         rxq->queue_id = qidx;
969         rxq->evdev = nic->evdev;
970         rxq->ev_queues = ev_queues;
971         rxq->ev_ports = ev_ports;
972
973         dev->data->rx_queues[qidx] = rxq;
974         dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
975         return 0;
976 }
977
978 static void
979 octeontx_dev_rx_queue_release(void *rxq)
980 {
981         rte_free(rxq);
982 }
983
984 static const uint32_t *
985 octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev)
986 {
987         static const uint32_t ptypes[] = {
988                 RTE_PTYPE_L3_IPV4,
989                 RTE_PTYPE_L3_IPV4_EXT,
990                 RTE_PTYPE_L3_IPV6,
991                 RTE_PTYPE_L3_IPV6_EXT,
992                 RTE_PTYPE_L4_TCP,
993                 RTE_PTYPE_L4_UDP,
994                 RTE_PTYPE_L4_FRAG,
995                 RTE_PTYPE_UNKNOWN
996         };
997
998         if (dev->rx_pkt_burst == octeontx_recv_pkts)
999                 return ptypes;
1000
1001         return NULL;
1002 }
1003
1004 /* Initialize and register driver with DPDK Application */
1005 static const struct eth_dev_ops octeontx_dev_ops = {
1006         .dev_configure           = octeontx_dev_configure,
1007         .dev_infos_get           = octeontx_dev_info,
1008         .dev_close               = octeontx_dev_close,
1009         .dev_start               = octeontx_dev_start,
1010         .dev_stop                = octeontx_dev_stop,
1011         .promiscuous_enable      = octeontx_dev_promisc_enable,
1012         .promiscuous_disable     = octeontx_dev_promisc_disable,
1013         .link_update             = octeontx_dev_link_update,
1014         .stats_get               = octeontx_dev_stats_get,
1015         .stats_reset             = octeontx_dev_stats_reset,
1016         .mac_addr_set            = octeontx_dev_default_mac_addr_set,
1017         .tx_queue_start          = octeontx_dev_tx_queue_start,
1018         .tx_queue_stop           = octeontx_dev_tx_queue_stop,
1019         .tx_queue_setup          = octeontx_dev_tx_queue_setup,
1020         .tx_queue_release        = octeontx_dev_tx_queue_release,
1021         .rx_queue_setup          = octeontx_dev_rx_queue_setup,
1022         .rx_queue_release        = octeontx_dev_rx_queue_release,
1023         .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
1024 };
1025
1026 /* Create Ethdev interface per BGX LMAC ports */
1027 static int
1028 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
1029                         int socket_id)
1030 {
1031         int res;
1032         char octtx_name[OCTEONTX_MAX_NAME_LEN];
1033         struct octeontx_nic *nic = NULL;
1034         struct rte_eth_dev *eth_dev = NULL;
1035         struct rte_eth_dev_data *data = NULL;
1036         const char *name = rte_vdev_device_name(dev);
1037
1038         PMD_INIT_FUNC_TRACE();
1039
1040         sprintf(octtx_name, "%s_%d", name, port);
1041         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1042                 eth_dev = rte_eth_dev_attach_secondary(octtx_name);
1043                 if (eth_dev == NULL)
1044                         return -ENODEV;
1045
1046                 eth_dev->tx_pkt_burst = octeontx_xmit_pkts;
1047                 eth_dev->rx_pkt_burst = octeontx_recv_pkts;
1048                 return 0;
1049         }
1050
1051         data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
1052         if (data == NULL) {
1053                 octeontx_log_err("failed to allocate devdata");
1054                 res = -ENOMEM;
1055                 goto err;
1056         }
1057
1058         nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
1059         if (nic == NULL) {
1060                 octeontx_log_err("failed to allocate nic structure");
1061                 res = -ENOMEM;
1062                 goto err;
1063         }
1064
1065         nic->port_id = port;
1066         nic->evdev = evdev;
1067
1068         res = octeontx_port_open(nic);
1069         if (res < 0)
1070                 goto err;
1071
1072         /* Rx side port configuration */
1073         res = octeontx_pki_port_open(port);
1074         if (res != 0) {
1075                 octeontx_log_err("failed to open PKI port %d", port);
1076                 res = -ENODEV;
1077                 goto err;
1078         }
1079
1080         /* Reserve an ethdev entry */
1081         eth_dev = rte_eth_dev_allocate(octtx_name);
1082         if (eth_dev == NULL) {
1083                 octeontx_log_err("failed to allocate rte_eth_dev");
1084                 res = -ENOMEM;
1085                 goto err;
1086         }
1087
1088         eth_dev->device = &dev->device;
1089         eth_dev->intr_handle = NULL;
1090         eth_dev->data->kdrv = RTE_KDRV_NONE;
1091         eth_dev->data->numa_node = dev->device.numa_node;
1092
1093         rte_memcpy(data, (eth_dev)->data, sizeof(*data));
1094         data->dev_private = nic;
1095
1096         data->port_id = eth_dev->data->port_id;
1097         snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
1098
1099         nic->ev_queues = 1;
1100         nic->ev_ports = 1;
1101
1102         data->dev_link.link_status = ETH_LINK_DOWN;
1103         data->dev_started = 0;
1104         data->promiscuous = 0;
1105         data->all_multicast = 0;
1106         data->scattered_rx = 0;
1107
1108         data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
1109                                                         socket_id);
1110         if (data->mac_addrs == NULL) {
1111                 octeontx_log_err("failed to allocate memory for mac_addrs");
1112                 res = -ENOMEM;
1113                 goto err;
1114         }
1115
1116         eth_dev->data = data;
1117         eth_dev->dev_ops = &octeontx_dev_ops;
1118
1119         /* Finally save ethdev pointer to the NIC structure */
1120         nic->dev = eth_dev;
1121
1122         if (nic->port_id != data->port_id) {
1123                 octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
1124                                 data->port_id, nic->port_id);
1125                 res = -EINVAL;
1126                 goto err;
1127         }
1128
1129         /* Update port_id mac to eth_dev */
1130         memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
1131
1132         PMD_INIT_LOG(DEBUG, "ethdev info: ");
1133         PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
1134                                 nic->port_id, nic->port_ena,
1135                                 nic->base_ochan, nic->num_ochans,
1136                                 nic->num_tx_queues);
1137         PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
1138
1139         rte_octeontx_pchan_map[(nic->base_ochan >> 8) & 0x7]
1140                 [(nic->base_ochan >> 4) & 0xF] = data->port_id;
1141
1142         return data->port_id;
1143
1144 err:
1145         if (nic)
1146                 octeontx_port_close(nic);
1147
1148         if (eth_dev != NULL) {
1149                 rte_free(eth_dev->data->mac_addrs);
1150                 rte_free(data);
1151                 rte_free(nic);
1152                 rte_eth_dev_release_port(eth_dev);
1153         }
1154
1155         return res;
1156 }
1157
1158 /* Un initialize octeontx device */
1159 static int
1160 octeontx_remove(struct rte_vdev_device *dev)
1161 {
1162         char octtx_name[OCTEONTX_MAX_NAME_LEN];
1163         struct rte_eth_dev *eth_dev = NULL;
1164         struct octeontx_nic *nic = NULL;
1165         int i;
1166
1167         if (dev == NULL)
1168                 return -EINVAL;
1169
1170         for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1171                 sprintf(octtx_name, "eth_octeontx_%d", i);
1172
1173                 /* reserve an ethdev entry */
1174                 eth_dev = rte_eth_dev_allocated(octtx_name);
1175                 if (eth_dev == NULL)
1176                         return -ENODEV;
1177
1178                 nic = octeontx_pmd_priv(eth_dev);
1179                 rte_event_dev_stop(nic->evdev);
1180                 PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1181
1182                 rte_free(eth_dev->data->mac_addrs);
1183                 rte_free(eth_dev->data->dev_private);
1184                 rte_free(eth_dev->data);
1185                 rte_eth_dev_release_port(eth_dev);
1186                 rte_event_dev_close(nic->evdev);
1187         }
1188
1189         /* Free FC resource */
1190         octeontx_pko_fc_free();
1191
1192         return 0;
1193 }
1194
1195 /* Initialize octeontx device */
1196 static int
1197 octeontx_probe(struct rte_vdev_device *dev)
1198 {
1199         const char *dev_name;
1200         static int probe_once;
1201         uint8_t socket_id, qlist;
1202         int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1203         struct rte_event_dev_config dev_conf;
1204         const char *eventdev_name = "event_octeontx";
1205         struct rte_event_dev_info info;
1206
1207         struct octeontx_vdev_init_params init_params = {
1208                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1209         };
1210
1211         dev_name = rte_vdev_device_name(dev);
1212         res = octeontx_parse_vdev_init_params(&init_params, dev);
1213         if (res < 0)
1214                 return -EINVAL;
1215
1216         if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1217                 octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1218                                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1219                 return -ENOTSUP;
1220         }
1221
1222         PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1223
1224         socket_id = rte_socket_id();
1225
1226         tx_vfcnt = octeontx_pko_vf_count();
1227
1228         if (tx_vfcnt < init_params.nr_port) {
1229                 octeontx_log_err("not enough PKO (%d) for port number (%d)",
1230                                 tx_vfcnt, init_params.nr_port);
1231                 return -EINVAL;
1232         }
1233         evdev = rte_event_dev_get_dev_id(eventdev_name);
1234         if (evdev < 0) {
1235                 octeontx_log_err("eventdev %s not found", eventdev_name);
1236                 return -ENODEV;
1237         }
1238
1239         res = rte_event_dev_info_get(evdev, &info);
1240         if (res < 0) {
1241                 octeontx_log_err("failed to eventdev info %d", res);
1242                 return -EINVAL;
1243         }
1244
1245         PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1246                         info.max_event_queues, info.max_event_ports);
1247
1248         if (octeontx_pko_init_fc(tx_vfcnt))
1249                 return -ENOMEM;
1250
1251         devconf_set_default_sane_values(&dev_conf, &info);
1252         res = rte_event_dev_configure(evdev, &dev_conf);
1253         if (res < 0)
1254                 goto parse_error;
1255
1256         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1257                         (uint32_t *)&pnum);
1258         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1259                         (uint32_t *)&qnum);
1260         if (pnum < qnum) {
1261                 octeontx_log_err("too few event ports (%d) for event_q(%d)",
1262                                 pnum, qnum);
1263                 res = -EINVAL;
1264                 goto parse_error;
1265         }
1266         if (pnum > qnum) {
1267                 /*
1268                  * We don't poll on event ports
1269                  * that do not have any queues assigned.
1270                  */
1271                 pnum = qnum;
1272                 PMD_INIT_LOG(INFO,
1273                         "reducing number of active event ports to %d", pnum);
1274         }
1275         for (i = 0; i < qnum; i++) {
1276                 res = rte_event_queue_setup(evdev, i, NULL);
1277                 if (res < 0) {
1278                         octeontx_log_err("failed to setup event_q(%d): res %d",
1279                                         i, res);
1280                         goto parse_error;
1281                 }
1282         }
1283
1284         for (i = 0; i < pnum; i++) {
1285                 res = rte_event_port_setup(evdev, i, NULL);
1286                 if (res < 0) {
1287                         res = -ENODEV;
1288                         octeontx_log_err("failed to setup ev port(%d) res=%d",
1289                                                 i, res);
1290                         goto parse_error;
1291                 }
1292                 /* Link one queue to one event port */
1293                 qlist = i;
1294                 res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1295                 if (res < 0) {
1296                         res = -ENODEV;
1297                         octeontx_log_err("failed to link port (%d): res=%d",
1298                                         i, res);
1299                         goto parse_error;
1300                 }
1301         }
1302
1303         /* Create ethdev interface */
1304         for (i = 0; i < init_params.nr_port; i++) {
1305                 port_id = octeontx_create(dev, i, evdev, socket_id);
1306                 if (port_id < 0) {
1307                         octeontx_log_err("failed to create device %s",
1308                                         dev_name);
1309                         res = -ENODEV;
1310                         goto parse_error;
1311                 }
1312
1313                 PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1314                                         port_id);
1315         }
1316
1317         if (probe_once) {
1318                 octeontx_log_err("interface %s not supported", dev_name);
1319                 octeontx_remove(dev);
1320                 res = -ENOTSUP;
1321                 goto parse_error;
1322         }
1323         probe_once = 1;
1324
1325         return 0;
1326
1327 parse_error:
1328         octeontx_pko_fc_free();
1329         return res;
1330 }
1331
1332 static struct rte_vdev_driver octeontx_pmd_drv = {
1333         .probe = octeontx_probe,
1334         .remove = octeontx_remove,
1335 };
1336
1337 RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1338 RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1339 RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");