net/octeontx: support allmulticast
[dpdk.git] / drivers / net / octeontx / octeontx_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <unistd.h>
11
12 #include <eventdev_pmd.h>
13 #include <rte_alarm.h>
14 #include <rte_branch_prediction.h>
15 #include <rte_bus_vdev.h>
16 #include <rte_cycles.h>
17 #include <rte_debug.h>
18 #include <rte_dev.h>
19 #include <rte_devargs.h>
20 #include <rte_kvargs.h>
21 #include <rte_malloc.h>
22 #include <rte_mbuf_pool_ops.h>
23 #include <rte_prefetch.h>
24
25 #include "octeontx_ethdev.h"
26 #include "octeontx_rxtx.h"
27 #include "octeontx_logs.h"
28 #include "octeontx_stats.h"
29
30 /* Useful in stopping/closing event device if no of
31  * eth ports are using it.
32  */
33 uint16_t evdev_refcnt;
34
35 #define OCTEONTX_QLM_MODE_SGMII  7
36 #define OCTEONTX_QLM_MODE_XFI   12
37
38 struct evdev_priv_data {
39         OFFLOAD_FLAGS; /*Sequence should not be changed */
40 } __rte_cache_aligned;
41
42 struct octeontx_vdev_init_params {
43         uint8_t nr_port;
44 };
45
46 uint16_t
47 rte_octeontx_pchan_map[OCTEONTX_MAX_BGX_PORTS][OCTEONTX_MAX_LMAC_PER_BGX];
48
49 enum octeontx_link_speed {
50         OCTEONTX_LINK_SPEED_SGMII,
51         OCTEONTX_LINK_SPEED_XAUI,
52         OCTEONTX_LINK_SPEED_RXAUI,
53         OCTEONTX_LINK_SPEED_10G_R,
54         OCTEONTX_LINK_SPEED_40G_R,
55         OCTEONTX_LINK_SPEED_RESERVE1,
56         OCTEONTX_LINK_SPEED_QSGMII,
57         OCTEONTX_LINK_SPEED_RESERVE2,
58         OCTEONTX_LINK_SPEED_UNKNOWN = 255
59 };
60
61 RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_mbox, mbox, NOTICE);
62 RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_init, init, NOTICE);
63 RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_driver, driver, NOTICE);
64
65 /* Parse integer from integer argument */
66 static int
67 parse_integer_arg(const char *key __rte_unused,
68                 const char *value, void *extra_args)
69 {
70         int *i = (int *)extra_args;
71
72         *i = atoi(value);
73         if (*i < 0) {
74                 octeontx_log_err("argument has to be positive.");
75                 return -1;
76         }
77
78         return 0;
79 }
80
81 static int
82 octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
83                                 struct rte_vdev_device *dev)
84 {
85         struct rte_kvargs *kvlist = NULL;
86         int ret = 0;
87
88         static const char * const octeontx_vdev_valid_params[] = {
89                 OCTEONTX_VDEV_NR_PORT_ARG,
90                 NULL
91         };
92
93         const char *input_args = rte_vdev_device_args(dev);
94         if (params == NULL)
95                 return -EINVAL;
96
97
98         if (input_args) {
99                 kvlist = rte_kvargs_parse(input_args,
100                                 octeontx_vdev_valid_params);
101                 if (kvlist == NULL)
102                         return -1;
103
104                 ret = rte_kvargs_process(kvlist,
105                                         OCTEONTX_VDEV_NR_PORT_ARG,
106                                         &parse_integer_arg,
107                                         &params->nr_port);
108                 if (ret < 0)
109                         goto free_kvlist;
110         }
111
112 free_kvlist:
113         rte_kvargs_free(kvlist);
114         return ret;
115 }
116
117 static int
118 octeontx_port_open(struct octeontx_nic *nic)
119 {
120         octeontx_mbox_bgx_port_conf_t bgx_port_conf;
121         octeontx_mbox_bgx_port_fifo_cfg_t fifo_cfg;
122         int res;
123
124         res = 0;
125         memset(&bgx_port_conf, 0x0, sizeof(bgx_port_conf));
126         PMD_INIT_FUNC_TRACE();
127
128         res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
129         if (res < 0) {
130                 octeontx_log_err("failed to open port %d", res);
131                 return res;
132         }
133
134         nic->node = bgx_port_conf.node;
135         nic->port_ena = bgx_port_conf.enable;
136         nic->base_ichan = bgx_port_conf.base_chan;
137         nic->base_ochan = bgx_port_conf.base_chan;
138         nic->num_ichans = bgx_port_conf.num_chans;
139         nic->num_ochans = bgx_port_conf.num_chans;
140         nic->bgx_mtu = bgx_port_conf.mtu;
141         nic->bpen = bgx_port_conf.bpen;
142         nic->fcs_strip = bgx_port_conf.fcs_strip;
143         nic->bcast_mode = bgx_port_conf.bcast_mode;
144         nic->mcast_mode = bgx_port_conf.mcast_mode;
145         nic->speed      = bgx_port_conf.mode;
146
147         nic->duplex = RTE_ETH_LINK_FULL_DUPLEX;
148         memset(&fifo_cfg, 0x0, sizeof(fifo_cfg));
149
150         res = octeontx_bgx_port_get_fifo_cfg(nic->port_id, &fifo_cfg);
151         if (res < 0) {
152                 octeontx_log_err("failed to get port %d fifo cfg", res);
153                 return res;
154         }
155
156         nic->fc.rx_fifosz = fifo_cfg.rx_fifosz;
157
158         memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0],
159                 RTE_ETHER_ADDR_LEN);
160
161         octeontx_log_dbg("port opened %d", nic->port_id);
162         return res;
163 }
164
165 static void
166 octeontx_link_status_print(struct rte_eth_dev *eth_dev,
167                            struct rte_eth_link *link)
168 {
169         if (link && link->link_status)
170                 octeontx_log_info("Port %u: Link Up - speed %u Mbps - %s",
171                           (eth_dev->data->port_id),
172                           link->link_speed,
173                           link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
174                           "full-duplex" : "half-duplex");
175         else
176                 octeontx_log_info("Port %d: Link Down",
177                                   (int)(eth_dev->data->port_id));
178 }
179
180 static inline uint32_t
181 octeontx_parse_link_speeds(uint32_t link_speeds)
182 {
183         uint32_t link_speed = OCTEONTX_LINK_SPEED_UNKNOWN;
184
185         if (link_speeds & RTE_ETH_LINK_SPEED_40G)
186                 link_speed = OCTEONTX_LINK_SPEED_40G_R;
187
188         if (link_speeds & RTE_ETH_LINK_SPEED_10G) {
189                 link_speed  = OCTEONTX_LINK_SPEED_XAUI;
190                 link_speed |= OCTEONTX_LINK_SPEED_RXAUI;
191                 link_speed |= OCTEONTX_LINK_SPEED_10G_R;
192         }
193
194         if (link_speeds & RTE_ETH_LINK_SPEED_5G)
195                 link_speed = OCTEONTX_LINK_SPEED_QSGMII;
196
197         if (link_speeds & RTE_ETH_LINK_SPEED_1G)
198                 link_speed = OCTEONTX_LINK_SPEED_SGMII;
199
200         return link_speed;
201 }
202
203 static inline uint8_t
204 octeontx_parse_eth_link_duplex(uint32_t link_speeds)
205 {
206         if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) ||
207                         (link_speeds & RTE_ETH_LINK_SPEED_100M_HD))
208                 return RTE_ETH_LINK_HALF_DUPLEX;
209         else
210                 return RTE_ETH_LINK_FULL_DUPLEX;
211 }
212
213 static int
214 octeontx_apply_link_speed(struct rte_eth_dev *dev)
215 {
216         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
217         struct rte_eth_conf *conf = &dev->data->dev_conf;
218         octeontx_mbox_bgx_port_change_mode_t cfg;
219
220         if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
221                 return 0;
222
223         cfg.speed = octeontx_parse_link_speeds(conf->link_speeds);
224         cfg.autoneg = (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) ? 1 : 0;
225         cfg.duplex = octeontx_parse_eth_link_duplex(conf->link_speeds);
226         cfg.qlm_mode = ((conf->link_speeds & RTE_ETH_LINK_SPEED_1G) ?
227                         OCTEONTX_QLM_MODE_SGMII :
228                         (conf->link_speeds & RTE_ETH_LINK_SPEED_10G) ?
229                         OCTEONTX_QLM_MODE_XFI : 0);
230
231         if (cfg.speed != OCTEONTX_LINK_SPEED_UNKNOWN &&
232             (cfg.speed != nic->speed || cfg.duplex != nic->duplex)) {
233                 nic->speed = cfg.speed;
234                 nic->duplex = cfg.duplex;
235                 return octeontx_bgx_port_change_mode(nic->port_id, &cfg);
236         } else {
237                 return 0;
238         }
239 }
240
241 static void
242 octeontx_link_status_update(struct octeontx_nic *nic,
243                          struct rte_eth_link *link)
244 {
245         memset(link, 0, sizeof(*link));
246
247         link->link_status = nic->link_up ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
248
249         switch (nic->speed) {
250         case OCTEONTX_LINK_SPEED_SGMII:
251                 link->link_speed = RTE_ETH_SPEED_NUM_1G;
252                 break;
253
254         case OCTEONTX_LINK_SPEED_XAUI:
255                 link->link_speed = RTE_ETH_SPEED_NUM_10G;
256                 break;
257
258         case OCTEONTX_LINK_SPEED_RXAUI:
259         case OCTEONTX_LINK_SPEED_10G_R:
260                 link->link_speed = RTE_ETH_SPEED_NUM_10G;
261                 break;
262         case OCTEONTX_LINK_SPEED_QSGMII:
263                 link->link_speed = RTE_ETH_SPEED_NUM_5G;
264                 break;
265         case OCTEONTX_LINK_SPEED_40G_R:
266                 link->link_speed = RTE_ETH_SPEED_NUM_40G;
267                 break;
268
269         case OCTEONTX_LINK_SPEED_RESERVE1:
270         case OCTEONTX_LINK_SPEED_RESERVE2:
271         default:
272                 link->link_speed = RTE_ETH_SPEED_NUM_NONE;
273                 octeontx_log_err("incorrect link speed %d", nic->speed);
274                 break;
275         }
276
277         link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
278         link->link_autoneg = RTE_ETH_LINK_AUTONEG;
279 }
280
281 static void
282 octeontx_link_status_poll(void *arg)
283 {
284         struct octeontx_nic *nic = arg;
285         struct rte_eth_link link;
286         struct rte_eth_dev *dev;
287         int res;
288
289         PMD_INIT_FUNC_TRACE();
290
291         dev = nic->dev;
292
293         res = octeontx_bgx_port_link_status(nic->port_id);
294         if (res < 0) {
295                 octeontx_log_err("Failed to get port %d link status",
296                                 nic->port_id);
297         } else {
298                 if (nic->link_up != (uint8_t)res) {
299                         nic->link_up = (uint8_t)res;
300                         octeontx_link_status_update(nic, &link);
301                         octeontx_link_status_print(dev, &link);
302                         rte_eth_linkstatus_set(dev, &link);
303                         rte_eth_dev_callback_process(dev,
304                                                      RTE_ETH_EVENT_INTR_LSC,
305                                                      NULL);
306                 }
307         }
308
309         res = rte_eal_alarm_set(OCCTX_INTR_POLL_INTERVAL_MS * 1000,
310                                 octeontx_link_status_poll, nic);
311         if (res < 0)
312                 octeontx_log_err("Failed to restart alarm for port %d, err: %d",
313                                 nic->port_id, res);
314 }
315
316 static void
317 octeontx_port_close(struct octeontx_nic *nic)
318 {
319         PMD_INIT_FUNC_TRACE();
320
321         rte_eal_alarm_cancel(octeontx_link_status_poll, nic);
322         octeontx_bgx_port_close(nic->port_id);
323         octeontx_log_dbg("port closed %d", nic->port_id);
324 }
325
326 static int
327 octeontx_port_start(struct octeontx_nic *nic)
328 {
329         PMD_INIT_FUNC_TRACE();
330
331         return octeontx_bgx_port_start(nic->port_id);
332 }
333
334 static int
335 octeontx_port_stop(struct octeontx_nic *nic)
336 {
337         PMD_INIT_FUNC_TRACE();
338
339         return octeontx_bgx_port_stop(nic->port_id);
340 }
341
342 static int
343 octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
344 {
345         struct rte_eth_dev *dev;
346         int res;
347
348         res = 0;
349         PMD_INIT_FUNC_TRACE();
350         dev = nic->dev;
351
352         res = octeontx_bgx_port_promisc_set(nic->port_id, en);
353         if (res < 0) {
354                 octeontx_log_err("failed to set promiscuous mode %d",
355                                 nic->port_id);
356                 return res;
357         }
358
359         /* Set proper flag for the mode */
360         dev->data->promiscuous = (en != 0) ? 1 : 0;
361
362         octeontx_log_dbg("port %d : promiscuous mode %s",
363                         nic->port_id, en ? "set" : "unset");
364
365         return 0;
366 }
367
368 static int
369 octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats)
370 {
371         octeontx_mbox_bgx_port_stats_t bgx_stats;
372         int res;
373
374         PMD_INIT_FUNC_TRACE();
375
376         res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats);
377         if (res < 0) {
378                 octeontx_log_err("failed to get port stats %d", nic->port_id);
379                 return res;
380         }
381
382         stats->ipackets = bgx_stats.rx_packets;
383         stats->ibytes = bgx_stats.rx_bytes;
384         stats->imissed = bgx_stats.rx_dropped;
385         stats->ierrors = bgx_stats.rx_errors;
386         stats->opackets = bgx_stats.tx_packets;
387         stats->obytes = bgx_stats.tx_bytes;
388         stats->oerrors = bgx_stats.tx_errors;
389
390         octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "",
391                         nic->port_id, stats->ipackets, stats->opackets);
392
393         return 0;
394 }
395
396 static int
397 octeontx_port_stats_clr(struct octeontx_nic *nic)
398 {
399         PMD_INIT_FUNC_TRACE();
400
401         return octeontx_bgx_port_stats_clr(nic->port_id);
402 }
403
404 static inline void
405 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
406                                 struct rte_event_dev_info *info)
407 {
408         memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
409         dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
410
411         dev_conf->nb_event_ports = info->max_event_ports;
412         dev_conf->nb_event_queues = info->max_event_queues;
413
414         dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
415         dev_conf->nb_event_port_dequeue_depth =
416                         info->max_event_port_dequeue_depth;
417         dev_conf->nb_event_port_enqueue_depth =
418                         info->max_event_port_enqueue_depth;
419         dev_conf->nb_event_port_enqueue_depth =
420                         info->max_event_port_enqueue_depth;
421         dev_conf->nb_events_limit =
422                         info->max_num_events;
423 }
424
425 static uint16_t
426 octeontx_tx_offload_flags(struct rte_eth_dev *eth_dev)
427 {
428         struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
429         uint16_t flags = 0;
430
431         if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
432             nic->tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
433                 flags |= OCCTX_TX_OFFLOAD_OL3_OL4_CSUM_F;
434
435         if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM ||
436             nic->tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM ||
437             nic->tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM ||
438             nic->tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)
439                 flags |= OCCTX_TX_OFFLOAD_L3_L4_CSUM_F;
440
441         if (!(nic->tx_offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE))
442                 flags |= OCCTX_TX_OFFLOAD_MBUF_NOFF_F;
443
444         if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
445                 flags |= OCCTX_TX_MULTI_SEG_F;
446
447         return flags;
448 }
449
450 static uint16_t
451 octeontx_rx_offload_flags(struct rte_eth_dev *eth_dev)
452 {
453         struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
454         uint16_t flags = 0;
455
456         if (nic->rx_offloads & (RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
457                          RTE_ETH_RX_OFFLOAD_UDP_CKSUM))
458                 flags |= OCCTX_RX_OFFLOAD_CSUM_F;
459
460         if (nic->rx_offloads & (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
461                                 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM))
462                 flags |= OCCTX_RX_OFFLOAD_CSUM_F;
463
464         if (nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
465                 flags |= OCCTX_RX_MULTI_SEG_F;
466                 eth_dev->data->scattered_rx = 1;
467                 /* If scatter mode is enabled, TX should also be in multi
468                  * seg mode, else memory leak will occur
469                  */
470                 nic->tx_offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
471         }
472
473         return flags;
474 }
475
476 static int
477 octeontx_dev_configure(struct rte_eth_dev *dev)
478 {
479         struct rte_eth_dev_data *data = dev->data;
480         struct rte_eth_conf *conf = &data->dev_conf;
481         struct rte_eth_rxmode *rxmode = &conf->rxmode;
482         struct rte_eth_txmode *txmode = &conf->txmode;
483         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
484         int ret;
485
486         PMD_INIT_FUNC_TRACE();
487         RTE_SET_USED(conf);
488
489         if (!rte_eal_has_hugepages()) {
490                 octeontx_log_err("huge page is not configured");
491                 return -EINVAL;
492         }
493
494         if (txmode->mq_mode) {
495                 octeontx_log_err("tx mq_mode DCB or VMDq not supported");
496                 return -EINVAL;
497         }
498
499         if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
500                 rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
501                 octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
502                 return -EINVAL;
503         }
504
505         if (!(txmode->offloads & RTE_ETH_TX_OFFLOAD_MT_LOCKFREE)) {
506                 PMD_INIT_LOG(NOTICE, "cant disable lockfree tx");
507                 txmode->offloads |= RTE_ETH_TX_OFFLOAD_MT_LOCKFREE;
508         }
509
510         if (conf->dcb_capability_en) {
511                 octeontx_log_err("DCB enable not supported");
512                 return -EINVAL;
513         }
514
515         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
516                 octeontx_log_err("flow director not supported");
517                 return -EINVAL;
518         }
519
520         nic->num_tx_queues = dev->data->nb_tx_queues;
521
522         if (!nic->reconfigure) {
523                 ret = octeontx_pko_channel_open(nic->pko_vfid * PKO_VF_NUM_DQ,
524                                                 nic->num_tx_queues,
525                                                 nic->base_ochan);
526                 if (ret) {
527                         octeontx_log_err("failed to open channel %d no-of-txq %d",
528                                          nic->base_ochan, nic->num_tx_queues);
529                         return -EFAULT;
530                 }
531
532                 ret = octeontx_dev_vlan_offload_init(dev);
533                 if (ret) {
534                         octeontx_log_err("failed to initialize vlan offload");
535                         return -EFAULT;
536                 }
537
538                 nic->pki.classifier_enable = false;
539                 nic->pki.hash_enable = true;
540                 nic->pki.initialized = false;
541         }
542
543         nic->rx_offloads |= rxmode->offloads;
544         nic->tx_offloads |= txmode->offloads;
545         nic->rx_offload_flags |= octeontx_rx_offload_flags(dev);
546         nic->tx_offload_flags |= octeontx_tx_offload_flags(dev);
547
548         nic->reconfigure = true;
549
550         return 0;
551 }
552
553 static int
554 octeontx_dev_close(struct rte_eth_dev *dev)
555 {
556         struct octeontx_txq *txq = NULL;
557         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
558         unsigned int i;
559         int ret;
560
561         PMD_INIT_FUNC_TRACE();
562         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
563                 return 0;
564
565         /* Stopping/closing event device once all eth ports are closed. */
566         if (__atomic_sub_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE) == 0) {
567                 rte_event_dev_stop(nic->evdev);
568                 rte_event_dev_close(nic->evdev);
569         }
570
571         octeontx_dev_flow_ctrl_fini(dev);
572
573         octeontx_dev_vlan_offload_fini(dev);
574
575         ret = octeontx_pko_channel_close(nic->base_ochan);
576         if (ret < 0) {
577                 octeontx_log_err("failed to close channel %d VF%d %d %d",
578                              nic->base_ochan, nic->port_id, nic->num_tx_queues,
579                              ret);
580         }
581         /* Free txq resources for this port */
582         for (i = 0; i < nic->num_tx_queues; i++) {
583                 txq = dev->data->tx_queues[i];
584                 if (!txq)
585                         continue;
586
587                 rte_free(txq);
588         }
589
590         octeontx_port_close(nic);
591         nic->reconfigure = false;
592
593         return 0;
594 }
595
596 static int
597 octeontx_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
598 {
599         uint32_t buffsz, frame_size = mtu + OCCTX_L2_OVERHEAD;
600         struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
601         struct rte_eth_dev_data *data = eth_dev->data;
602         int rc = 0;
603
604         buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
605
606         /* Refuse MTU that requires the support of scattered packets
607          * when this feature has not been enabled before.
608          */
609         if (data->dev_started && frame_size > buffsz &&
610             !(nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
611                 octeontx_log_err("Scatter mode is disabled");
612                 return -EINVAL;
613         }
614
615         /* Check <seg size> * <max_seg>  >= max_frame */
616         if ((nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER)     &&
617             (frame_size > buffsz * OCCTX_RX_NB_SEG_MAX))
618                 return -EINVAL;
619
620         rc = octeontx_pko_send_mtu(nic->port_id, frame_size);
621         if (rc)
622                 return rc;
623
624         rc = octeontx_bgx_port_mtu_set(nic->port_id, frame_size);
625         if (rc)
626                 return rc;
627
628         octeontx_log_info("Received pkt beyond  maxlen %d will be dropped",
629                           frame_size);
630
631         return rc;
632 }
633
634 static int
635 octeontx_recheck_rx_offloads(struct octeontx_rxq *rxq)
636 {
637         struct rte_eth_dev *eth_dev = rxq->eth_dev;
638         struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
639         struct rte_eth_dev_data *data = eth_dev->data;
640         struct rte_pktmbuf_pool_private *mbp_priv;
641         struct evdev_priv_data *evdev_priv;
642         struct rte_eventdev *dev;
643         uint32_t buffsz;
644
645         /* Get rx buffer size */
646         mbp_priv = rte_mempool_get_priv(rxq->pool);
647         buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
648
649         /* Setup scatter mode if needed by jumbo */
650         if (data->mtu > buffsz) {
651                 nic->rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
652                 nic->rx_offload_flags |= octeontx_rx_offload_flags(eth_dev);
653                 nic->tx_offload_flags |= octeontx_tx_offload_flags(eth_dev);
654         }
655
656         /* Sharing offload flags via eventdev priv region */
657         dev = &rte_eventdevs[rxq->evdev];
658         evdev_priv = dev->data->dev_private;
659         evdev_priv->rx_offload_flags = nic->rx_offload_flags;
660         evdev_priv->tx_offload_flags = nic->tx_offload_flags;
661
662         /* Setup MTU */
663         nic->mtu = data->mtu;
664
665         return 0;
666 }
667
668 static int
669 octeontx_dev_start(struct rte_eth_dev *dev)
670 {
671         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
672         struct octeontx_rxq *rxq;
673         int ret, i;
674
675         PMD_INIT_FUNC_TRACE();
676         /* Rechecking if any new offload set to update
677          * rx/tx burst function pointer accordingly.
678          */
679         for (i = 0; i < dev->data->nb_rx_queues; i++) {
680                 rxq = dev->data->rx_queues[i];
681                 octeontx_recheck_rx_offloads(rxq);
682         }
683
684         /* Setting up the mtu */
685         ret = octeontx_dev_mtu_set(dev, nic->mtu);
686         if (ret) {
687                 octeontx_log_err("Failed to set default MTU size %d", ret);
688                 goto error;
689         }
690
691         /* Apply new link configurations if changed */
692         ret = octeontx_apply_link_speed(dev);
693         if (ret) {
694                 octeontx_log_err("Failed to set link configuration: %d", ret);
695                 goto error;
696         }
697
698         /*
699          * Tx start
700          */
701         octeontx_set_tx_function(dev);
702         ret = octeontx_pko_channel_start(nic->base_ochan);
703         if (ret < 0) {
704                 octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d",
705                            nic->port_id, nic->num_tx_queues, nic->base_ochan,
706                            ret);
707                 goto error;
708         }
709
710         /*
711          * Rx start
712          */
713         dev->rx_pkt_burst = octeontx_recv_pkts;
714         ret = octeontx_pki_port_start(nic->port_id);
715         if (ret < 0) {
716                 octeontx_log_err("fail to start Rx on port %d", nic->port_id);
717                 goto channel_stop_error;
718         }
719
720         /*
721          * Start port
722          */
723         ret = octeontx_port_start(nic);
724         if (ret < 0) {
725                 octeontx_log_err("failed start port %d", ret);
726                 goto pki_port_stop_error;
727         }
728
729         PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d",
730                         nic->base_ochan, nic->num_tx_queues, nic->port_id);
731
732         ret = rte_event_dev_start(nic->evdev);
733         if (ret < 0) {
734                 octeontx_log_err("failed to start evdev: ret (%d)", ret);
735                 goto pki_port_stop_error;
736         }
737
738         /* Success */
739         return ret;
740
741 pki_port_stop_error:
742         octeontx_pki_port_stop(nic->port_id);
743 channel_stop_error:
744         octeontx_pko_channel_stop(nic->base_ochan);
745 error:
746         return ret;
747 }
748
749 static int
750 octeontx_dev_stop(struct rte_eth_dev *dev)
751 {
752         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
753         int ret;
754
755         PMD_INIT_FUNC_TRACE();
756
757         ret = octeontx_port_stop(nic);
758         if (ret < 0) {
759                 octeontx_log_err("failed to req stop port %d res=%d",
760                                         nic->port_id, ret);
761                 return ret;
762         }
763
764         ret = octeontx_pki_port_stop(nic->port_id);
765         if (ret < 0) {
766                 octeontx_log_err("failed to stop pki port %d res=%d",
767                                         nic->port_id, ret);
768                 return ret;
769         }
770
771         ret = octeontx_pko_channel_stop(nic->base_ochan);
772         if (ret < 0) {
773                 octeontx_log_err("failed to stop channel %d VF%d %d %d",
774                              nic->base_ochan, nic->port_id, nic->num_tx_queues,
775                              ret);
776                 return ret;
777         }
778
779         return 0;
780 }
781
782 static int
783 octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
784 {
785         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
786
787         PMD_INIT_FUNC_TRACE();
788         return octeontx_port_promisc_set(nic, 1);
789 }
790
791 static int
792 octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
793 {
794         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
795
796         PMD_INIT_FUNC_TRACE();
797         return octeontx_port_promisc_set(nic, 0);
798 }
799
800 static int
801 octeontx_port_link_status(struct octeontx_nic *nic)
802 {
803         int res;
804
805         PMD_INIT_FUNC_TRACE();
806         res = octeontx_bgx_port_link_status(nic->port_id);
807         if (res < 0) {
808                 octeontx_log_err("failed to get port %d link status",
809                                 nic->port_id);
810                 return res;
811         }
812
813         if (nic->link_up != (uint8_t)res || nic->print_flag == -1) {
814                 nic->link_up = (uint8_t)res;
815                 nic->print_flag = 1;
816         }
817         octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
818
819         return res;
820 }
821
822 /*
823  * Return 0 means link status changed, -1 means not changed
824  */
825 static int
826 octeontx_dev_link_update(struct rte_eth_dev *dev,
827                          int wait_to_complete __rte_unused)
828 {
829         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
830         struct rte_eth_link link;
831         int res;
832
833         PMD_INIT_FUNC_TRACE();
834
835         res = octeontx_port_link_status(nic);
836         if (res < 0) {
837                 octeontx_log_err("failed to request link status %d", res);
838                 return res;
839         }
840
841         octeontx_link_status_update(nic, &link);
842         if (nic->print_flag) {
843                 octeontx_link_status_print(nic->dev, &link);
844                 nic->print_flag = 0;
845         }
846
847         return rte_eth_linkstatus_set(dev, &link);
848 }
849
850 static int
851 octeontx_port_mcast_set(struct octeontx_nic *nic, int en)
852 {
853         struct rte_eth_dev *dev;
854         int res;
855
856         res = 0;
857         PMD_INIT_FUNC_TRACE();
858         dev = nic->dev;
859
860         res = octeontx_bgx_port_multicast_set(nic->port_id, en);
861         if (res < 0) {
862                 octeontx_log_err("failed to set multicast mode %d",
863                                 nic->port_id);
864                 return res;
865         }
866
867         /* Set proper flag for the mode */
868         dev->data->all_multicast = (en != 0) ? 1 : 0;
869
870         octeontx_log_dbg("port %d : multicast mode %s",
871                         nic->port_id, en ? "set" : "unset");
872
873         return 0;
874 }
875
876 static int
877 octeontx_allmulticast_enable(struct rte_eth_dev *dev)
878 {
879         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
880
881         PMD_INIT_FUNC_TRACE();
882         return octeontx_port_mcast_set(nic, 1);
883 }
884
885 static int
886 octeontx_allmulticast_disable(struct rte_eth_dev *dev)
887 {
888         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
889
890         PMD_INIT_FUNC_TRACE();
891         return octeontx_port_mcast_set(nic, 0);
892 }
893
894 static inline int octeontx_dev_total_xstat(void)
895 {
896         return NUM_BGX_XSTAT;
897 }
898
899 static int
900 octeontx_port_xstats(struct octeontx_nic *nic, struct rte_eth_xstat *xstats,
901                      unsigned int n)
902 {
903         octeontx_mbox_bgx_port_stats_t bgx_stats;
904         int stat_cnt, res, si, i;
905
906         res = octeontx_bgx_port_xstats(nic->port_id, &bgx_stats);
907         if (res < 0) {
908                 octeontx_log_err("failed to get port stats %d", nic->port_id);
909                 return res;
910         }
911
912         si = 0;
913         /* Fill BGX stats */
914         stat_cnt = (n > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : n;
915         n = n - stat_cnt;
916         for (i = 0; i < stat_cnt; i++) {
917                 xstats[si].id = si;
918                 xstats[si].value = *(uint64_t *)(((char *)&bgx_stats) +
919                                 octeontx_bgx_xstats[i].soffset);
920                 si++;
921         }
922         /*TODO: Similarly fill rest of HW stats */
923
924         return si;
925 }
926
927 static int
928 octeontx_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
929                               uint64_t *stat_val, unsigned int n)
930 {
931         unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
932         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
933         struct rte_eth_xstat xstats[xstat_cnt];
934
935         octeontx_port_xstats(nic, xstats, xstat_cnt);
936         for (i = 0; i < n; i++) {
937                 if (ids[i] >= xstat_cnt) {
938                         PMD_INIT_LOG(ERR, "out of range id value");
939                         return -1;
940                 }
941                 stat_val[i] = xstats[ids[i]].value;
942         }
943         return n;
944 }
945
946 static int
947 octeontx_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
948                               struct rte_eth_xstat_name *xstats_names,
949                               unsigned int size)
950 {
951         int stat_cnt, si, i;
952
953         if (xstats_names) {
954                 si = 0;
955                 /* Fill BGX stats */
956                 stat_cnt = (size > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : size;
957                 size = size - stat_cnt;
958                 for (i = 0; i < stat_cnt; i++) {
959                         strlcpy(xstats_names[si].name,
960                                 octeontx_bgx_xstats[i].sname,
961                                 sizeof(xstats_names[si].name));
962                         si++;
963                 }
964                 /*TODO: Similarly fill rest of HW stats */
965                 return si;
966         } else {
967                 return octeontx_dev_total_xstat();
968         }
969 }
970
971 static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
972 {
973         unsigned int i;
974
975         for (i = 0; i < NUM_BGX_XSTAT; i++) {
976                 strlcpy(xstat_names[i].name, octeontx_bgx_xstats[i].sname,
977                         RTE_ETH_XSTATS_NAME_SIZE);
978         }
979 }
980
981 static int
982 octeontx_dev_xstats_get_names_by_id(struct rte_eth_dev *dev __rte_unused,
983                                     const uint64_t *ids,
984                                     struct rte_eth_xstat_name *stat_names,
985                                     unsigned int n)
986 {
987         unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
988         struct rte_eth_xstat_name xstat_names[xstat_cnt];
989
990         build_xstat_names(xstat_names);
991         for (i = 0; i < n; i++) {
992                 if (ids[i] >= xstat_cnt) {
993                         PMD_INIT_LOG(ERR, "out of range id value");
994                         return -1;
995                 }
996                 strlcpy(stat_names[i].name, xstat_names[ids[i]].name,
997                         sizeof(stat_names[i].name));
998         }
999         /*TODO: Similarly fill rest of HW stats */
1000
1001         return n;
1002 }
1003
1004 static int
1005 octeontx_dev_xstats_get(struct rte_eth_dev *dev,
1006                         struct rte_eth_xstat *xstats,
1007                         unsigned int n)
1008 {
1009         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1010
1011         PMD_INIT_FUNC_TRACE();
1012         return octeontx_port_xstats(nic, xstats, n);
1013 }
1014
1015 static int
1016 octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1017 {
1018         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1019
1020         PMD_INIT_FUNC_TRACE();
1021         return octeontx_port_stats(nic, stats);
1022 }
1023
1024 static int
1025 octeontx_dev_stats_reset(struct rte_eth_dev *dev)
1026 {
1027         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1028
1029         PMD_INIT_FUNC_TRACE();
1030         return octeontx_port_stats_clr(nic);
1031 }
1032
1033 static void
1034 octeontx_dev_mac_addr_del(struct rte_eth_dev *dev, uint32_t index)
1035 {
1036         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1037         int ret;
1038
1039         ret = octeontx_bgx_port_mac_del(nic->port_id, index);
1040         if (ret != 0)
1041                 octeontx_log_err("failed to del MAC address filter on port %d",
1042                                  nic->port_id);
1043 }
1044
1045 static int
1046 octeontx_dev_mac_addr_add(struct rte_eth_dev *dev,
1047                           struct rte_ether_addr *mac_addr,
1048                           uint32_t index,
1049                           __rte_unused uint32_t vmdq)
1050 {
1051         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1052         int ret;
1053
1054         ret = octeontx_bgx_port_mac_add(nic->port_id, mac_addr->addr_bytes,
1055                                         index);
1056         if (ret < 0) {
1057                 octeontx_log_err("failed to add MAC address filter on port %d",
1058                                  nic->port_id);
1059                 return ret;
1060         }
1061
1062         return 0;
1063 }
1064
1065 static int
1066 octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
1067                                         struct rte_ether_addr *addr)
1068 {
1069         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1070         int ret;
1071
1072         ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
1073         if (ret == 0) {
1074                 /* Update same mac address to BGX CAM table */
1075                 ret = octeontx_bgx_port_mac_add(nic->port_id, addr->addr_bytes,
1076                                                 0);
1077         }
1078         if (ret < 0) {
1079                 octeontx_log_err("failed to set MAC address on port %d",
1080                                  nic->port_id);
1081         }
1082
1083         return ret;
1084 }
1085
1086 static int
1087 octeontx_dev_info(struct rte_eth_dev *dev,
1088                 struct rte_eth_dev_info *dev_info)
1089 {
1090         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1091
1092         /* Autonegotiation may be disabled */
1093         dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
1094         dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10M | RTE_ETH_LINK_SPEED_100M |
1095                         RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G |
1096                         RTE_ETH_LINK_SPEED_40G;
1097
1098         /* Min/Max MTU supported */
1099         dev_info->min_rx_bufsize = OCCTX_MIN_FRS;
1100         dev_info->max_rx_pktlen = OCCTX_MAX_FRS;
1101         dev_info->max_mtu = dev_info->max_rx_pktlen - OCCTX_L2_OVERHEAD;
1102         dev_info->min_mtu = dev_info->min_rx_bufsize - OCCTX_L2_OVERHEAD;
1103
1104         dev_info->max_mac_addrs =
1105                                 octeontx_bgx_port_mac_entries_get(nic->port_id);
1106         dev_info->max_rx_queues = 1;
1107         dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
1108         dev_info->min_rx_bufsize = 0;
1109
1110         dev_info->default_rxconf = (struct rte_eth_rxconf) {
1111                 .rx_free_thresh = 0,
1112                 .rx_drop_en = 0,
1113                 .offloads = OCTEONTX_RX_OFFLOADS,
1114         };
1115
1116         dev_info->default_txconf = (struct rte_eth_txconf) {
1117                 .tx_free_thresh = 0,
1118                 .offloads = OCTEONTX_TX_OFFLOADS,
1119         };
1120
1121         dev_info->rx_offload_capa = OCTEONTX_RX_OFFLOADS;
1122         dev_info->tx_offload_capa = OCTEONTX_TX_OFFLOADS;
1123         dev_info->rx_queue_offload_capa = OCTEONTX_RX_OFFLOADS;
1124         dev_info->tx_queue_offload_capa = OCTEONTX_TX_OFFLOADS;
1125
1126         return 0;
1127 }
1128
1129 static void
1130 octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
1131 {
1132         ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
1133         ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
1134         ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
1135 }
1136
1137 static int
1138 octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1139                                 uint16_t qidx)
1140 {
1141         struct octeontx_txq *txq;
1142         int res;
1143
1144         PMD_INIT_FUNC_TRACE();
1145
1146         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
1147                 return 0;
1148
1149         txq = dev->data->tx_queues[qidx];
1150
1151         res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1152                                                 &txq->dq,
1153                                                 sizeof(octeontx_dq_t),
1154                                                 txq->queue_id,
1155                                                 octeontx_dq_info_getter);
1156         if (res < 0) {
1157                 res = -EFAULT;
1158                 goto close_port;
1159         }
1160
1161         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
1162         return res;
1163
1164 close_port:
1165         (void)octeontx_port_stop(nic);
1166         octeontx_pko_channel_stop(nic->base_ochan);
1167         octeontx_pko_channel_close(nic->base_ochan);
1168         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1169         return res;
1170 }
1171
1172 int
1173 octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1174 {
1175         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1176
1177         PMD_INIT_FUNC_TRACE();
1178         qidx = qidx % PKO_VF_NUM_DQ;
1179         return octeontx_vf_start_tx_queue(dev, nic, qidx);
1180 }
1181
1182 static inline int
1183 octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1184                           uint16_t qidx)
1185 {
1186         int ret = 0;
1187
1188         RTE_SET_USED(nic);
1189         PMD_INIT_FUNC_TRACE();
1190
1191         if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
1192                 return 0;
1193
1194         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1195         return ret;
1196 }
1197
1198 int
1199 octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1200 {
1201         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1202
1203         PMD_INIT_FUNC_TRACE();
1204         qidx = qidx % PKO_VF_NUM_DQ;
1205
1206         return octeontx_vf_stop_tx_queue(dev, nic, qidx);
1207 }
1208
1209 static void
1210 octeontx_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1211 {
1212         int res;
1213
1214         PMD_INIT_FUNC_TRACE();
1215
1216         if (dev->data->tx_queues[qid]) {
1217                 res = octeontx_dev_tx_queue_stop(dev, qid);
1218                 if (res < 0)
1219                         octeontx_log_err("failed stop tx_queue(%d)\n", qid);
1220
1221                 rte_free(dev->data->tx_queues[qid]);
1222         }
1223 }
1224
1225 static int
1226 octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1227                             uint16_t nb_desc, unsigned int socket_id,
1228                             const struct rte_eth_txconf *tx_conf __rte_unused)
1229 {
1230         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1231         struct octeontx_txq *txq = NULL;
1232         uint16_t dq_num;
1233         int res = 0;
1234
1235         RTE_SET_USED(nb_desc);
1236         RTE_SET_USED(socket_id);
1237
1238         dq_num = (nic->pko_vfid * PKO_VF_NUM_DQ) + qidx;
1239
1240         /* Socket id check */
1241         if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1242                         socket_id != (unsigned int)nic->node)
1243                 PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
1244                                                 socket_id, nic->node);
1245
1246         /* Free memory prior to re-allocation if needed. */
1247         if (dev->data->tx_queues[qidx] != NULL) {
1248                 PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
1249                                 qidx);
1250                 octeontx_dev_tx_queue_release(dev, qidx);
1251                 dev->data->tx_queues[qidx] = NULL;
1252         }
1253
1254         /* Allocating tx queue data structure */
1255         txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
1256                                  RTE_CACHE_LINE_SIZE, nic->node);
1257         if (txq == NULL) {
1258                 octeontx_log_err("failed to allocate txq=%d", qidx);
1259                 res = -ENOMEM;
1260                 goto err;
1261         }
1262
1263         txq->eth_dev = dev;
1264         txq->queue_id = dq_num;
1265         dev->data->tx_queues[qidx] = txq;
1266         dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1267
1268         res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1269                                                 &txq->dq,
1270                                                 sizeof(octeontx_dq_t),
1271                                                 txq->queue_id,
1272                                                 octeontx_dq_info_getter);
1273         if (res < 0) {
1274                 res = -EFAULT;
1275                 goto err;
1276         }
1277
1278         PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
1279                         qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
1280                         txq->dq.ioreg_va,
1281                         txq->dq.fc_status_va);
1282
1283         return res;
1284
1285 err:
1286         rte_free(txq);
1287
1288         return res;
1289 }
1290
1291 static int
1292 octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1293                                 uint16_t nb_desc, unsigned int socket_id,
1294                                 const struct rte_eth_rxconf *rx_conf,
1295                                 struct rte_mempool *mb_pool)
1296 {
1297         struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1298         struct rte_mempool_ops *mp_ops = NULL;
1299         struct octeontx_rxq *rxq = NULL;
1300         pki_pktbuf_cfg_t pktbuf_conf;
1301         pki_hash_cfg_t pki_hash;
1302         pki_qos_cfg_t pki_qos;
1303         uintptr_t pool;
1304         int ret, port;
1305         uint16_t gaura;
1306         unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
1307         unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
1308
1309         RTE_SET_USED(nb_desc);
1310
1311         memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
1312         memset(&pki_hash, 0, sizeof(pki_hash));
1313         memset(&pki_qos, 0, sizeof(pki_qos));
1314
1315         mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
1316         if (strcmp(mp_ops->name, "octeontx_fpavf")) {
1317                 octeontx_log_err("failed to find octeontx_fpavf mempool");
1318                 return -ENOTSUP;
1319         }
1320
1321         /* Handle forbidden configurations */
1322         if (nic->pki.classifier_enable) {
1323                 octeontx_log_err("cannot setup queue %d. "
1324                                         "Classifier option unsupported", qidx);
1325                 return -EINVAL;
1326         }
1327
1328         port = nic->port_id;
1329
1330         /* Rx deferred start is not supported */
1331         if (rx_conf->rx_deferred_start) {
1332                 octeontx_log_err("rx deferred start not supported");
1333                 return -EINVAL;
1334         }
1335
1336         /* Verify queue index */
1337         if (qidx >= dev->data->nb_rx_queues) {
1338                 octeontx_log_err("QID %d not supported (0 - %d available)\n",
1339                                 qidx, (dev->data->nb_rx_queues - 1));
1340                 return -ENOTSUP;
1341         }
1342
1343         /* Socket id check */
1344         if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1345                         socket_id != (unsigned int)nic->node)
1346                 PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
1347                                                 socket_id, nic->node);
1348
1349         /* Allocating rx queue data structure */
1350         rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
1351                                  RTE_CACHE_LINE_SIZE, nic->node);
1352         if (rxq == NULL) {
1353                 octeontx_log_err("failed to allocate rxq=%d", qidx);
1354                 return -ENOMEM;
1355         }
1356
1357         if (!nic->pki.initialized) {
1358                 pktbuf_conf.port_type = 0;
1359                 pki_hash.port_type = 0;
1360                 pki_qos.port_type = 0;
1361
1362                 pktbuf_conf.mmask.f_wqe_skip = 1;
1363                 pktbuf_conf.mmask.f_first_skip = 1;
1364                 pktbuf_conf.mmask.f_later_skip = 1;
1365                 pktbuf_conf.mmask.f_mbuff_size = 1;
1366                 pktbuf_conf.mmask.f_cache_mode = 1;
1367
1368                 pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
1369                 pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP(mb_pool);
1370                 pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
1371                 pktbuf_conf.mbuff_size = (mb_pool->elt_size -
1372                                         RTE_PKTMBUF_HEADROOM -
1373                                         rte_pktmbuf_priv_size(mb_pool) -
1374                                         sizeof(struct rte_mbuf));
1375
1376                 pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
1377
1378                 ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
1379                 if (ret != 0) {
1380                         octeontx_log_err("fail to configure pktbuf for port %d",
1381                                         port);
1382                         rte_free(rxq);
1383                         return ret;
1384                 }
1385                 PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n"
1386                                 "\tmbuf_size:\t0x%0x\n"
1387                                 "\twqe_skip:\t0x%0x\n"
1388                                 "\tfirst_skip:\t0x%0x\n"
1389                                 "\tlater_skip:\t0x%0x\n"
1390                                 "\tcache_mode:\t%s\n",
1391                                 port,
1392                                 pktbuf_conf.mbuff_size,
1393                                 pktbuf_conf.wqe_skip,
1394                                 pktbuf_conf.first_skip,
1395                                 pktbuf_conf.later_skip,
1396                                 (pktbuf_conf.cache_mode ==
1397                                                 PKI_OPC_MODE_STT) ?
1398                                 "STT" :
1399                                 (pktbuf_conf.cache_mode ==
1400                                                 PKI_OPC_MODE_STF) ?
1401                                 "STF" :
1402                                 (pktbuf_conf.cache_mode ==
1403                                                 PKI_OPC_MODE_STF1_STT) ?
1404                                 "STF1_STT" : "STF2_STT");
1405
1406                 if (nic->pki.hash_enable) {
1407                         pki_hash.tag_dlc = 1;
1408                         pki_hash.tag_slc = 1;
1409                         pki_hash.tag_dlf = 1;
1410                         pki_hash.tag_slf = 1;
1411                         pki_hash.tag_prt = 1;
1412                         octeontx_pki_port_hash_config(port, &pki_hash);
1413                 }
1414
1415                 pool = (uintptr_t)mb_pool->pool_id;
1416
1417                 /* Get the gaura Id */
1418                 gaura = octeontx_fpa_bufpool_gaura(pool);
1419
1420                 pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
1421                 pki_qos.num_entry = 1;
1422                 pki_qos.drop_policy = 0;
1423                 pki_qos.tag_type = 0L;
1424                 pki_qos.qos_entry[0].port_add = 0;
1425                 pki_qos.qos_entry[0].gaura = gaura;
1426                 pki_qos.qos_entry[0].ggrp_ok = ev_queues;
1427                 pki_qos.qos_entry[0].ggrp_bad = ev_queues;
1428                 pki_qos.qos_entry[0].grptag_bad = 0;
1429                 pki_qos.qos_entry[0].grptag_ok = 0;
1430
1431                 ret = octeontx_pki_port_create_qos(port, &pki_qos);
1432                 if (ret < 0) {
1433                         octeontx_log_err("failed to create QOS port=%d, q=%d",
1434                                         port, qidx);
1435                         rte_free(rxq);
1436                         return ret;
1437                 }
1438                 nic->pki.initialized = true;
1439         }
1440
1441         rxq->port_id = nic->port_id;
1442         rxq->eth_dev = dev;
1443         rxq->queue_id = qidx;
1444         rxq->evdev = nic->evdev;
1445         rxq->ev_queues = ev_queues;
1446         rxq->ev_ports = ev_ports;
1447         rxq->pool = mb_pool;
1448
1449         octeontx_recheck_rx_offloads(rxq);
1450         dev->data->rx_queues[qidx] = rxq;
1451         dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1452
1453         return 0;
1454 }
1455
1456 static void
1457 octeontx_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1458 {
1459         rte_free(dev->data->rx_queues[qid]);
1460 }
1461
1462 static const uint32_t *
1463 octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1464 {
1465         static const uint32_t ptypes[] = {
1466                 RTE_PTYPE_L3_IPV4,
1467                 RTE_PTYPE_L3_IPV4_EXT,
1468                 RTE_PTYPE_L3_IPV6,
1469                 RTE_PTYPE_L3_IPV6_EXT,
1470                 RTE_PTYPE_L4_TCP,
1471                 RTE_PTYPE_L4_UDP,
1472                 RTE_PTYPE_L4_FRAG,
1473                 RTE_PTYPE_UNKNOWN
1474         };
1475
1476         if (dev->rx_pkt_burst == octeontx_recv_pkts)
1477                 return ptypes;
1478
1479         return NULL;
1480 }
1481
1482 static int
1483 octeontx_pool_ops(struct rte_eth_dev *dev, const char *pool)
1484 {
1485         RTE_SET_USED(dev);
1486
1487         if (!strcmp(pool, "octeontx_fpavf"))
1488                 return 0;
1489
1490         return -ENOTSUP;
1491 }
1492
1493 /* Initialize and register driver with DPDK Application */
1494 static const struct eth_dev_ops octeontx_dev_ops = {
1495         .dev_configure           = octeontx_dev_configure,
1496         .dev_infos_get           = octeontx_dev_info,
1497         .dev_close               = octeontx_dev_close,
1498         .dev_start               = octeontx_dev_start,
1499         .dev_stop                = octeontx_dev_stop,
1500         .promiscuous_enable      = octeontx_dev_promisc_enable,
1501         .promiscuous_disable     = octeontx_dev_promisc_disable,
1502         .link_update             = octeontx_dev_link_update,
1503         .stats_get               = octeontx_dev_stats_get,
1504         .stats_reset             = octeontx_dev_stats_reset,
1505         .mac_addr_remove         = octeontx_dev_mac_addr_del,
1506         .mac_addr_add            = octeontx_dev_mac_addr_add,
1507         .mac_addr_set            = octeontx_dev_default_mac_addr_set,
1508         .vlan_offload_set        = octeontx_dev_vlan_offload_set,
1509         .vlan_filter_set         = octeontx_dev_vlan_filter_set,
1510         .tx_queue_start          = octeontx_dev_tx_queue_start,
1511         .tx_queue_stop           = octeontx_dev_tx_queue_stop,
1512         .tx_queue_setup          = octeontx_dev_tx_queue_setup,
1513         .tx_queue_release        = octeontx_dev_tx_queue_release,
1514         .rx_queue_setup          = octeontx_dev_rx_queue_setup,
1515         .rx_queue_release        = octeontx_dev_rx_queue_release,
1516         .dev_set_link_up          = octeontx_dev_set_link_up,
1517         .dev_set_link_down        = octeontx_dev_set_link_down,
1518         .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
1519         .mtu_set                 = octeontx_dev_mtu_set,
1520         .pool_ops_supported      = octeontx_pool_ops,
1521         .flow_ctrl_get           = octeontx_dev_flow_ctrl_get,
1522         .flow_ctrl_set           = octeontx_dev_flow_ctrl_set,
1523         .xstats_get              = octeontx_dev_xstats_get,
1524         .xstats_get_by_id        = octeontx_dev_xstats_get_by_id,
1525         .xstats_get_names        = octeontx_dev_xstats_get_names,
1526         .xstats_get_names_by_id  = octeontx_dev_xstats_get_names_by_id,
1527         .allmulticast_enable      = octeontx_allmulticast_enable,
1528         .allmulticast_disable     = octeontx_allmulticast_disable,
1529 };
1530
1531 /* Create Ethdev interface per BGX LMAC ports */
1532 static int
1533 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
1534                         int socket_id)
1535 {
1536         int res;
1537         size_t pko_vfid;
1538         char octtx_name[OCTEONTX_MAX_NAME_LEN];
1539         struct octeontx_nic *nic = NULL;
1540         struct rte_eth_dev *eth_dev = NULL;
1541         struct rte_eth_dev_data *data;
1542         const char *name = rte_vdev_device_name(dev);
1543         int max_entries;
1544
1545         PMD_INIT_FUNC_TRACE();
1546
1547         sprintf(octtx_name, "%s_%d", name, port);
1548         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1549                 eth_dev = rte_eth_dev_attach_secondary(octtx_name);
1550                 if (eth_dev == NULL)
1551                         return -ENODEV;
1552
1553                 eth_dev->dev_ops = &octeontx_dev_ops;
1554                 eth_dev->device = &dev->device;
1555                 octeontx_set_tx_function(eth_dev);
1556                 eth_dev->rx_pkt_burst = octeontx_recv_pkts;
1557                 rte_eth_dev_probing_finish(eth_dev);
1558                 return 0;
1559         }
1560
1561         /* Reserve an ethdev entry */
1562         eth_dev = rte_eth_dev_allocate(octtx_name);
1563         if (eth_dev == NULL) {
1564                 octeontx_log_err("failed to allocate rte_eth_dev");
1565                 res = -ENOMEM;
1566                 goto err;
1567         }
1568         data = eth_dev->data;
1569
1570         nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
1571         if (nic == NULL) {
1572                 octeontx_log_err("failed to allocate nic structure");
1573                 res = -ENOMEM;
1574                 goto err;
1575         }
1576         data->dev_private = nic;
1577         pko_vfid = octeontx_pko_get_vfid();
1578
1579         if (pko_vfid == SIZE_MAX) {
1580                 octeontx_log_err("failed to get pko vfid");
1581                 res = -ENODEV;
1582                 goto err;
1583         }
1584
1585         nic->pko_vfid = pko_vfid;
1586         nic->port_id = port;
1587         nic->evdev = evdev;
1588         __atomic_add_fetch(&evdev_refcnt, 1, __ATOMIC_ACQUIRE);
1589
1590         res = octeontx_port_open(nic);
1591         if (res < 0)
1592                 goto err;
1593
1594         /* Rx side port configuration */
1595         res = octeontx_pki_port_open(port);
1596         if (res != 0) {
1597                 octeontx_log_err("failed to open PKI port %d", port);
1598                 res = -ENODEV;
1599                 goto err;
1600         }
1601
1602         eth_dev->device = &dev->device;
1603         eth_dev->intr_handle = NULL;
1604         eth_dev->data->numa_node = dev->device.numa_node;
1605
1606         data->port_id = eth_dev->data->port_id;
1607
1608         nic->ev_queues = 1;
1609         nic->ev_ports = 1;
1610         nic->print_flag = -1;
1611         nic->reconfigure = false;
1612
1613         data->dev_link.link_status = RTE_ETH_LINK_DOWN;
1614         data->dev_started = 0;
1615         data->promiscuous = 0;
1616         data->all_multicast = 0;
1617         data->scattered_rx = 0;
1618
1619         /* Get maximum number of supported MAC entries */
1620         max_entries = octeontx_bgx_port_mac_entries_get(nic->port_id);
1621         if (max_entries < 0) {
1622                 octeontx_log_err("Failed to get max entries for mac addr");
1623                 res = -ENOTSUP;
1624                 goto err;
1625         }
1626
1627         data->mac_addrs = rte_zmalloc_socket(octtx_name, max_entries *
1628                                              RTE_ETHER_ADDR_LEN, 0,
1629                                                         socket_id);
1630         if (data->mac_addrs == NULL) {
1631                 octeontx_log_err("failed to allocate memory for mac_addrs");
1632                 res = -ENOMEM;
1633                 goto err;
1634         }
1635
1636         eth_dev->dev_ops = &octeontx_dev_ops;
1637
1638         /* Finally save ethdev pointer to the NIC structure */
1639         nic->dev = eth_dev;
1640
1641         if (nic->port_id != data->port_id) {
1642                 octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
1643                                 data->port_id, nic->port_id);
1644                 res = -EINVAL;
1645                 goto free_mac_addrs;
1646         }
1647
1648         res = rte_eal_alarm_set(OCCTX_INTR_POLL_INTERVAL_MS * 1000,
1649                                 octeontx_link_status_poll, nic);
1650         if (res) {
1651                 octeontx_log_err("Failed to start link polling alarm");
1652                 goto err;
1653         }
1654
1655         /* Update port_id mac to eth_dev */
1656         memcpy(data->mac_addrs, nic->mac_addr, RTE_ETHER_ADDR_LEN);
1657
1658         /* Update same mac address to BGX CAM table at index 0 */
1659         octeontx_bgx_port_mac_add(nic->port_id, nic->mac_addr, 0);
1660
1661         res = octeontx_dev_flow_ctrl_init(eth_dev);
1662         if (res < 0)
1663                 goto err;
1664
1665         PMD_INIT_LOG(DEBUG, "ethdev info: ");
1666         PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
1667                                 nic->port_id, nic->port_ena,
1668                                 nic->base_ochan, nic->num_ochans,
1669                                 nic->num_tx_queues);
1670         PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->bgx_mtu);
1671
1672         rte_octeontx_pchan_map[(nic->base_ochan >> 8) & 0x7]
1673                 [(nic->base_ochan >> 4) & 0xF] = data->port_id;
1674
1675         rte_eth_dev_probing_finish(eth_dev);
1676         return data->port_id;
1677
1678 free_mac_addrs:
1679         rte_free(data->mac_addrs);
1680         data->mac_addrs = NULL;
1681 err:
1682         if (nic)
1683                 octeontx_port_close(nic);
1684
1685         rte_eth_dev_release_port(eth_dev);
1686
1687         return res;
1688 }
1689
1690 /* Un initialize octeontx device */
1691 static int
1692 octeontx_remove(struct rte_vdev_device *dev)
1693 {
1694         char octtx_name[OCTEONTX_MAX_NAME_LEN];
1695         struct rte_eth_dev *eth_dev = NULL;
1696         struct octeontx_nic *nic = NULL;
1697         int i;
1698
1699         if (dev == NULL)
1700                 return -EINVAL;
1701
1702         for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1703                 sprintf(octtx_name, "eth_octeontx_%d", i);
1704
1705                 eth_dev = rte_eth_dev_allocated(octtx_name);
1706                 if (eth_dev == NULL)
1707                         continue; /* port already released */
1708
1709                 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1710                         rte_eth_dev_release_port(eth_dev);
1711                         continue;
1712                 }
1713
1714                 nic = octeontx_pmd_priv(eth_dev);
1715                 rte_event_dev_stop(nic->evdev);
1716                 PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1717                 octeontx_dev_close(eth_dev);
1718                 rte_eth_dev_release_port(eth_dev);
1719         }
1720
1721         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1722                 return 0;
1723
1724         /* Free FC resource */
1725         octeontx_pko_fc_free();
1726
1727         return 0;
1728 }
1729
1730 /* Initialize octeontx device */
1731 static int
1732 octeontx_probe(struct rte_vdev_device *dev)
1733 {
1734         const char *dev_name;
1735         static int probe_once;
1736         uint8_t socket_id, qlist;
1737         int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1738         struct rte_event_dev_config dev_conf;
1739         const char *eventdev_name = "event_octeontx";
1740         struct rte_event_dev_info info;
1741         struct rte_eth_dev *eth_dev;
1742
1743         struct octeontx_vdev_init_params init_params = {
1744                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1745         };
1746
1747         dev_name = rte_vdev_device_name(dev);
1748
1749         if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
1750             strlen(rte_vdev_device_args(dev)) == 0) {
1751                 eth_dev = rte_eth_dev_attach_secondary(dev_name);
1752                 if (!eth_dev) {
1753                         PMD_INIT_LOG(ERR, "Failed to probe %s", dev_name);
1754                         return -1;
1755                 }
1756                 /* TODO: request info from primary to set up Rx and Tx */
1757                 eth_dev->dev_ops = &octeontx_dev_ops;
1758                 eth_dev->device = &dev->device;
1759                 rte_eth_dev_probing_finish(eth_dev);
1760                 return 0;
1761         }
1762
1763         res = octeontx_parse_vdev_init_params(&init_params, dev);
1764         if (res < 0)
1765                 return -EINVAL;
1766
1767         if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1768                 octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1769                                 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1770                 return -ENOTSUP;
1771         }
1772
1773         PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1774
1775         socket_id = rte_socket_id();
1776
1777         tx_vfcnt = octeontx_pko_vf_count();
1778
1779         if (tx_vfcnt < init_params.nr_port) {
1780                 octeontx_log_err("not enough PKO (%d) for port number (%d)",
1781                                 tx_vfcnt, init_params.nr_port);
1782                 return -EINVAL;
1783         }
1784         evdev = rte_event_dev_get_dev_id(eventdev_name);
1785         if (evdev < 0) {
1786                 octeontx_log_err("eventdev %s not found", eventdev_name);
1787                 return -ENODEV;
1788         }
1789
1790         res = rte_event_dev_info_get(evdev, &info);
1791         if (res < 0) {
1792                 octeontx_log_err("failed to eventdev info %d", res);
1793                 return -EINVAL;
1794         }
1795
1796         PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1797                         info.max_event_queues, info.max_event_ports);
1798
1799         if (octeontx_pko_init_fc(tx_vfcnt))
1800                 return -ENOMEM;
1801
1802         devconf_set_default_sane_values(&dev_conf, &info);
1803         res = rte_event_dev_configure(evdev, &dev_conf);
1804         if (res < 0)
1805                 goto parse_error;
1806
1807         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1808                         (uint32_t *)&pnum);
1809         rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1810                         (uint32_t *)&qnum);
1811         if (pnum < qnum) {
1812                 octeontx_log_err("too few event ports (%d) for event_q(%d)",
1813                                 pnum, qnum);
1814                 res = -EINVAL;
1815                 goto parse_error;
1816         }
1817
1818         /* Enable all queues available */
1819         for (i = 0; i < qnum; i++) {
1820                 res = rte_event_queue_setup(evdev, i, NULL);
1821                 if (res < 0) {
1822                         octeontx_log_err("failed to setup event_q(%d): res %d",
1823                                         i, res);
1824                         goto parse_error;
1825                 }
1826         }
1827
1828         /* Enable all ports available */
1829         for (i = 0; i < pnum; i++) {
1830                 res = rte_event_port_setup(evdev, i, NULL);
1831                 if (res < 0) {
1832                         res = -ENODEV;
1833                         octeontx_log_err("failed to setup ev port(%d) res=%d",
1834                                                 i, res);
1835                         goto parse_error;
1836                 }
1837         }
1838
1839         __atomic_store_n(&evdev_refcnt, 0, __ATOMIC_RELEASE);
1840         /*
1841          * Do 1:1 links for ports & queues. All queues would be mapped to
1842          * one port. If there are more ports than queues, then some ports
1843          * won't be linked to any queue.
1844          */
1845         for (i = 0; i < qnum; i++) {
1846                 /* Link one queue to one event port */
1847                 qlist = i;
1848                 res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1849                 if (res < 0) {
1850                         res = -ENODEV;
1851                         octeontx_log_err("failed to link port (%d): res=%d",
1852                                         i, res);
1853                         goto parse_error;
1854                 }
1855         }
1856
1857         /* Create ethdev interface */
1858         for (i = 0; i < init_params.nr_port; i++) {
1859                 port_id = octeontx_create(dev, i, evdev, socket_id);
1860                 if (port_id < 0) {
1861                         octeontx_log_err("failed to create device %s",
1862                                         dev_name);
1863                         res = -ENODEV;
1864                         goto parse_error;
1865                 }
1866
1867                 PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1868                                         port_id);
1869         }
1870
1871         if (probe_once) {
1872                 octeontx_log_err("interface %s not supported", dev_name);
1873                 octeontx_remove(dev);
1874                 res = -ENOTSUP;
1875                 goto parse_error;
1876         }
1877         rte_mbuf_set_platform_mempool_ops("octeontx_fpavf");
1878         probe_once = 1;
1879
1880         return 0;
1881
1882 parse_error:
1883         octeontx_pko_fc_free();
1884         return res;
1885 }
1886
1887 static struct rte_vdev_driver octeontx_pmd_drv = {
1888         .probe = octeontx_probe,
1889         .remove = octeontx_remove,
1890 };
1891
1892 RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1893 RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1894 RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");