net/cnxk: add multi-segment Tx for CN10K
[dpdk.git] / drivers / net / cnxk / cnxk_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 #include <cnxk_ethdev.h>
5
6 static inline uint64_t
7 nix_get_rx_offload_capa(struct cnxk_eth_dev *dev)
8 {
9         uint64_t capa = CNXK_NIX_RX_OFFLOAD_CAPA;
10
11         if (roc_nix_is_vf_or_sdp(&dev->nix))
12                 capa &= ~DEV_RX_OFFLOAD_TIMESTAMP;
13
14         return capa;
15 }
16
17 static inline uint64_t
18 nix_get_tx_offload_capa(struct cnxk_eth_dev *dev)
19 {
20         RTE_SET_USED(dev);
21         return CNXK_NIX_TX_OFFLOAD_CAPA;
22 }
23
24 static inline uint32_t
25 nix_get_speed_capa(struct cnxk_eth_dev *dev)
26 {
27         uint32_t speed_capa;
28
29         /* Auto negotiation disabled */
30         speed_capa = ETH_LINK_SPEED_FIXED;
31         if (!roc_nix_is_vf_or_sdp(&dev->nix) && !roc_nix_is_lbk(&dev->nix)) {
32                 speed_capa |= ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
33                               ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
34                               ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
35         }
36
37         return speed_capa;
38 }
39
40 uint64_t
41 cnxk_nix_rxq_mbuf_setup(struct cnxk_eth_dev *dev)
42 {
43         uint16_t port_id = dev->eth_dev->data->port_id;
44         struct rte_mbuf mb_def;
45         uint64_t *tmp;
46
47         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
48         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
49                                  offsetof(struct rte_mbuf, data_off) !=
50                          2);
51         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
52                                  offsetof(struct rte_mbuf, data_off) !=
53                          4);
54         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
55                                  offsetof(struct rte_mbuf, data_off) !=
56                          6);
57         mb_def.nb_segs = 1;
58         mb_def.data_off = RTE_PKTMBUF_HEADROOM;
59         mb_def.port = port_id;
60         rte_mbuf_refcnt_set(&mb_def, 1);
61
62         /* Prevent compiler reordering: rearm_data covers previous fields */
63         rte_compiler_barrier();
64         tmp = (uint64_t *)&mb_def.rearm_data;
65
66         return *tmp;
67 }
68
69 static inline uint8_t
70 nix_sq_max_sqe_sz(struct cnxk_eth_dev *dev)
71 {
72         /*
73          * Maximum three segments can be supported with W8, Choose
74          * NIX_MAXSQESZ_W16 for multi segment offload.
75          */
76         if (dev->tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
77                 return NIX_MAXSQESZ_W16;
78         else
79                 return NIX_MAXSQESZ_W8;
80 }
81
82 int
83 cnxk_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
84                         uint16_t nb_desc, uint16_t fp_tx_q_sz,
85                         const struct rte_eth_txconf *tx_conf)
86 {
87         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
88         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
89         struct cnxk_eth_txq_sp *txq_sp;
90         struct roc_nix_sq *sq;
91         size_t txq_sz;
92         int rc;
93
94         /* Free memory prior to re-allocation if needed. */
95         if (eth_dev->data->tx_queues[qid] != NULL) {
96                 plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
97                 dev_ops->tx_queue_release(eth_dev->data->tx_queues[qid]);
98                 eth_dev->data->tx_queues[qid] = NULL;
99         }
100
101         /* Setup ROC SQ */
102         sq = &dev->sqs[qid];
103         sq->qid = qid;
104         sq->nb_desc = nb_desc;
105         sq->max_sqe_sz = nix_sq_max_sqe_sz(dev);
106
107         rc = roc_nix_sq_init(&dev->nix, sq);
108         if (rc) {
109                 plt_err("Failed to init sq=%d, rc=%d", qid, rc);
110                 return rc;
111         }
112
113         rc = -ENOMEM;
114         txq_sz = sizeof(struct cnxk_eth_txq_sp) + fp_tx_q_sz;
115         txq_sp = plt_zmalloc(txq_sz, PLT_CACHE_LINE_SIZE);
116         if (!txq_sp) {
117                 plt_err("Failed to alloc tx queue mem");
118                 rc |= roc_nix_sq_fini(sq);
119                 return rc;
120         }
121
122         txq_sp->dev = dev;
123         txq_sp->qid = qid;
124         txq_sp->qconf.conf.tx = *tx_conf;
125         txq_sp->qconf.nb_desc = nb_desc;
126
127         plt_nix_dbg("sq=%d fc=%p offload=0x%" PRIx64 " lmt_addr=%p"
128                     " nb_sqb_bufs=%d sqes_per_sqb_log2=%d",
129                     qid, sq->fc, dev->tx_offloads, sq->lmt_addr,
130                     sq->nb_sqb_bufs, sq->sqes_per_sqb_log2);
131
132         /* Store start of fast path area */
133         eth_dev->data->tx_queues[qid] = txq_sp + 1;
134         eth_dev->data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
135         return 0;
136 }
137
138 static void
139 cnxk_nix_tx_queue_release(void *txq)
140 {
141         struct cnxk_eth_txq_sp *txq_sp;
142         struct cnxk_eth_dev *dev;
143         struct roc_nix_sq *sq;
144         uint16_t qid;
145         int rc;
146
147         if (!txq)
148                 return;
149
150         txq_sp = cnxk_eth_txq_to_sp(txq);
151         dev = txq_sp->dev;
152         qid = txq_sp->qid;
153
154         plt_nix_dbg("Releasing txq %u", qid);
155
156         /* Cleanup ROC SQ */
157         sq = &dev->sqs[qid];
158         rc = roc_nix_sq_fini(sq);
159         if (rc)
160                 plt_err("Failed to cleanup sq, rc=%d", rc);
161
162         /* Finally free */
163         plt_free(txq_sp);
164 }
165
166 int
167 cnxk_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
168                         uint16_t nb_desc, uint16_t fp_rx_q_sz,
169                         const struct rte_eth_rxconf *rx_conf,
170                         struct rte_mempool *mp)
171 {
172         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
173         struct cnxk_eth_rxq_sp *rxq_sp;
174         struct rte_mempool_ops *ops;
175         const char *platform_ops;
176         struct roc_nix_rq *rq;
177         struct roc_nix_cq *cq;
178         uint16_t first_skip;
179         int rc = -EINVAL;
180         size_t rxq_sz;
181
182         /* Sanity checks */
183         if (rx_conf->rx_deferred_start == 1) {
184                 plt_err("Deferred Rx start is not supported");
185                 goto fail;
186         }
187
188         platform_ops = rte_mbuf_platform_mempool_ops();
189         /* This driver needs cnxk_npa mempool ops to work */
190         ops = rte_mempool_get_ops(mp->ops_index);
191         if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
192                 plt_err("mempool ops should be of cnxk_npa type");
193                 goto fail;
194         }
195
196         if (mp->pool_id == 0) {
197                 plt_err("Invalid pool_id");
198                 goto fail;
199         }
200
201         /* Free memory prior to re-allocation if needed */
202         if (eth_dev->data->rx_queues[qid] != NULL) {
203                 const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
204
205                 plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
206                 dev_ops->rx_queue_release(eth_dev->data->rx_queues[qid]);
207                 eth_dev->data->rx_queues[qid] = NULL;
208         }
209
210         /* Setup ROC CQ */
211         cq = &dev->cqs[qid];
212         cq->qid = qid;
213         cq->nb_desc = nb_desc;
214         rc = roc_nix_cq_init(&dev->nix, cq);
215         if (rc) {
216                 plt_err("Failed to init roc cq for rq=%d, rc=%d", qid, rc);
217                 goto fail;
218         }
219
220         /* Setup ROC RQ */
221         rq = &dev->rqs[qid];
222         rq->qid = qid;
223         rq->aura_handle = mp->pool_id;
224         rq->flow_tag_width = 32;
225         rq->sso_ena = false;
226
227         /* Calculate first mbuf skip */
228         first_skip = (sizeof(struct rte_mbuf));
229         first_skip += RTE_PKTMBUF_HEADROOM;
230         first_skip += rte_pktmbuf_priv_size(mp);
231         rq->first_skip = first_skip;
232         rq->later_skip = sizeof(struct rte_mbuf);
233         rq->lpb_size = mp->elt_size;
234
235         rc = roc_nix_rq_init(&dev->nix, rq, !!eth_dev->data->dev_started);
236         if (rc) {
237                 plt_err("Failed to init roc rq for rq=%d, rc=%d", qid, rc);
238                 goto cq_fini;
239         }
240
241         /* Allocate and setup fast path rx queue */
242         rc = -ENOMEM;
243         rxq_sz = sizeof(struct cnxk_eth_rxq_sp) + fp_rx_q_sz;
244         rxq_sp = plt_zmalloc(rxq_sz, PLT_CACHE_LINE_SIZE);
245         if (!rxq_sp) {
246                 plt_err("Failed to alloc rx queue for rq=%d", qid);
247                 goto rq_fini;
248         }
249
250         /* Setup slow path fields */
251         rxq_sp->dev = dev;
252         rxq_sp->qid = qid;
253         rxq_sp->qconf.conf.rx = *rx_conf;
254         rxq_sp->qconf.nb_desc = nb_desc;
255         rxq_sp->qconf.mp = mp;
256
257         plt_nix_dbg("rq=%d pool=%s nb_desc=%d->%d", qid, mp->name, nb_desc,
258                     cq->nb_desc);
259
260         /* Store start of fast path area */
261         eth_dev->data->rx_queues[qid] = rxq_sp + 1;
262         eth_dev->data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
263
264         return 0;
265 rq_fini:
266         rc |= roc_nix_rq_fini(rq);
267 cq_fini:
268         rc |= roc_nix_cq_fini(cq);
269 fail:
270         return rc;
271 }
272
273 static void
274 cnxk_nix_rx_queue_release(void *rxq)
275 {
276         struct cnxk_eth_rxq_sp *rxq_sp;
277         struct cnxk_eth_dev *dev;
278         struct roc_nix_rq *rq;
279         struct roc_nix_cq *cq;
280         uint16_t qid;
281         int rc;
282
283         if (!rxq)
284                 return;
285
286         rxq_sp = cnxk_eth_rxq_to_sp(rxq);
287         dev = rxq_sp->dev;
288         qid = rxq_sp->qid;
289
290         plt_nix_dbg("Releasing rxq %u", qid);
291
292         /* Cleanup ROC RQ */
293         rq = &dev->rqs[qid];
294         rc = roc_nix_rq_fini(rq);
295         if (rc)
296                 plt_err("Failed to cleanup rq, rc=%d", rc);
297
298         /* Cleanup ROC CQ */
299         cq = &dev->cqs[qid];
300         rc = roc_nix_cq_fini(cq);
301         if (rc)
302                 plt_err("Failed to cleanup cq, rc=%d", rc);
303
304         /* Finally free fast path area */
305         plt_free(rxq_sp);
306 }
307
308 uint32_t
309 cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
310                        uint8_t rss_level)
311 {
312         uint32_t flow_key_type[RSS_MAX_LEVELS][6] = {
313                 {FLOW_KEY_TYPE_IPV4, FLOW_KEY_TYPE_IPV6, FLOW_KEY_TYPE_TCP,
314                  FLOW_KEY_TYPE_UDP, FLOW_KEY_TYPE_SCTP, FLOW_KEY_TYPE_ETH_DMAC},
315                 {FLOW_KEY_TYPE_INNR_IPV4, FLOW_KEY_TYPE_INNR_IPV6,
316                  FLOW_KEY_TYPE_INNR_TCP, FLOW_KEY_TYPE_INNR_UDP,
317                  FLOW_KEY_TYPE_INNR_SCTP, FLOW_KEY_TYPE_INNR_ETH_DMAC},
318                 {FLOW_KEY_TYPE_IPV4 | FLOW_KEY_TYPE_INNR_IPV4,
319                  FLOW_KEY_TYPE_IPV6 | FLOW_KEY_TYPE_INNR_IPV6,
320                  FLOW_KEY_TYPE_TCP | FLOW_KEY_TYPE_INNR_TCP,
321                  FLOW_KEY_TYPE_UDP | FLOW_KEY_TYPE_INNR_UDP,
322                  FLOW_KEY_TYPE_SCTP | FLOW_KEY_TYPE_INNR_SCTP,
323                  FLOW_KEY_TYPE_ETH_DMAC | FLOW_KEY_TYPE_INNR_ETH_DMAC}
324         };
325         uint32_t flowkey_cfg = 0;
326
327         dev->ethdev_rss_hf = ethdev_rss;
328
329         if (ethdev_rss & ETH_RSS_L2_PAYLOAD)
330                 flowkey_cfg |= FLOW_KEY_TYPE_CH_LEN_90B;
331
332         if (ethdev_rss & ETH_RSS_C_VLAN)
333                 flowkey_cfg |= FLOW_KEY_TYPE_VLAN;
334
335         if (ethdev_rss & ETH_RSS_L3_SRC_ONLY)
336                 flowkey_cfg |= FLOW_KEY_TYPE_L3_SRC;
337
338         if (ethdev_rss & ETH_RSS_L3_DST_ONLY)
339                 flowkey_cfg |= FLOW_KEY_TYPE_L3_DST;
340
341         if (ethdev_rss & ETH_RSS_L4_SRC_ONLY)
342                 flowkey_cfg |= FLOW_KEY_TYPE_L4_SRC;
343
344         if (ethdev_rss & ETH_RSS_L4_DST_ONLY)
345                 flowkey_cfg |= FLOW_KEY_TYPE_L4_DST;
346
347         if (ethdev_rss & RSS_IPV4_ENABLE)
348                 flowkey_cfg |= flow_key_type[rss_level][RSS_IPV4_INDEX];
349
350         if (ethdev_rss & RSS_IPV6_ENABLE)
351                 flowkey_cfg |= flow_key_type[rss_level][RSS_IPV6_INDEX];
352
353         if (ethdev_rss & ETH_RSS_TCP)
354                 flowkey_cfg |= flow_key_type[rss_level][RSS_TCP_INDEX];
355
356         if (ethdev_rss & ETH_RSS_UDP)
357                 flowkey_cfg |= flow_key_type[rss_level][RSS_UDP_INDEX];
358
359         if (ethdev_rss & ETH_RSS_SCTP)
360                 flowkey_cfg |= flow_key_type[rss_level][RSS_SCTP_INDEX];
361
362         if (ethdev_rss & ETH_RSS_L2_PAYLOAD)
363                 flowkey_cfg |= flow_key_type[rss_level][RSS_DMAC_INDEX];
364
365         if (ethdev_rss & RSS_IPV6_EX_ENABLE)
366                 flowkey_cfg |= FLOW_KEY_TYPE_IPV6_EXT;
367
368         if (ethdev_rss & ETH_RSS_PORT)
369                 flowkey_cfg |= FLOW_KEY_TYPE_PORT;
370
371         if (ethdev_rss & ETH_RSS_NVGRE)
372                 flowkey_cfg |= FLOW_KEY_TYPE_NVGRE;
373
374         if (ethdev_rss & ETH_RSS_VXLAN)
375                 flowkey_cfg |= FLOW_KEY_TYPE_VXLAN;
376
377         if (ethdev_rss & ETH_RSS_GENEVE)
378                 flowkey_cfg |= FLOW_KEY_TYPE_GENEVE;
379
380         if (ethdev_rss & ETH_RSS_GTPU)
381                 flowkey_cfg |= FLOW_KEY_TYPE_GTPU;
382
383         return flowkey_cfg;
384 }
385
386 static void
387 nix_free_queue_mem(struct cnxk_eth_dev *dev)
388 {
389         plt_free(dev->rqs);
390         plt_free(dev->cqs);
391         plt_free(dev->sqs);
392         dev->rqs = NULL;
393         dev->cqs = NULL;
394         dev->sqs = NULL;
395 }
396
397 static int
398 nix_rss_default_setup(struct cnxk_eth_dev *dev)
399 {
400         struct rte_eth_dev *eth_dev = dev->eth_dev;
401         uint8_t rss_hash_level;
402         uint32_t flowkey_cfg;
403         uint64_t rss_hf;
404
405         rss_hf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
406         rss_hash_level = ETH_RSS_LEVEL(rss_hf);
407         if (rss_hash_level)
408                 rss_hash_level -= 1;
409
410         flowkey_cfg = cnxk_rss_ethdev_to_nix(dev, rss_hf, rss_hash_level);
411         return roc_nix_rss_default_setup(&dev->nix, flowkey_cfg);
412 }
413
414 static int
415 nix_store_queue_cfg_and_then_release(struct rte_eth_dev *eth_dev)
416 {
417         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
418         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
419         struct cnxk_eth_qconf *tx_qconf = NULL;
420         struct cnxk_eth_qconf *rx_qconf = NULL;
421         struct cnxk_eth_rxq_sp *rxq_sp;
422         struct cnxk_eth_txq_sp *txq_sp;
423         int i, nb_rxq, nb_txq;
424         void **txq, **rxq;
425
426         nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
427         nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
428
429         tx_qconf = malloc(nb_txq * sizeof(*tx_qconf));
430         if (tx_qconf == NULL) {
431                 plt_err("Failed to allocate memory for tx_qconf");
432                 goto fail;
433         }
434
435         rx_qconf = malloc(nb_rxq * sizeof(*rx_qconf));
436         if (rx_qconf == NULL) {
437                 plt_err("Failed to allocate memory for rx_qconf");
438                 goto fail;
439         }
440
441         txq = eth_dev->data->tx_queues;
442         for (i = 0; i < nb_txq; i++) {
443                 if (txq[i] == NULL) {
444                         tx_qconf[i].valid = false;
445                         plt_info("txq[%d] is already released", i);
446                         continue;
447                 }
448                 txq_sp = cnxk_eth_txq_to_sp(txq[i]);
449                 memcpy(&tx_qconf[i], &txq_sp->qconf, sizeof(*tx_qconf));
450                 tx_qconf[i].valid = true;
451                 dev_ops->tx_queue_release(txq[i]);
452                 eth_dev->data->tx_queues[i] = NULL;
453         }
454
455         rxq = eth_dev->data->rx_queues;
456         for (i = 0; i < nb_rxq; i++) {
457                 if (rxq[i] == NULL) {
458                         rx_qconf[i].valid = false;
459                         plt_info("rxq[%d] is already released", i);
460                         continue;
461                 }
462                 rxq_sp = cnxk_eth_rxq_to_sp(rxq[i]);
463                 memcpy(&rx_qconf[i], &rxq_sp->qconf, sizeof(*rx_qconf));
464                 rx_qconf[i].valid = true;
465                 dev_ops->rx_queue_release(rxq[i]);
466                 eth_dev->data->rx_queues[i] = NULL;
467         }
468
469         dev->tx_qconf = tx_qconf;
470         dev->rx_qconf = rx_qconf;
471         return 0;
472
473 fail:
474         free(tx_qconf);
475         free(rx_qconf);
476         return -ENOMEM;
477 }
478
479 static int
480 nix_restore_queue_cfg(struct rte_eth_dev *eth_dev)
481 {
482         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
483         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
484         struct cnxk_eth_qconf *tx_qconf = dev->tx_qconf;
485         struct cnxk_eth_qconf *rx_qconf = dev->rx_qconf;
486         int rc, i, nb_rxq, nb_txq;
487         void **txq, **rxq;
488
489         nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
490         nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
491
492         rc = -ENOMEM;
493         /* Setup tx & rx queues with previous configuration so
494          * that the queues can be functional in cases like ports
495          * are started without re configuring queues.
496          *
497          * Usual re config sequence is like below:
498          * port_configure() {
499          *      if(reconfigure) {
500          *              queue_release()
501          *              queue_setup()
502          *      }
503          *      queue_configure() {
504          *              queue_release()
505          *              queue_setup()
506          *      }
507          * }
508          * port_start()
509          *
510          * In some application's control path, queue_configure() would
511          * NOT be invoked for TXQs/RXQs in port_configure().
512          * In such cases, queues can be functional after start as the
513          * queues are already setup in port_configure().
514          */
515         for (i = 0; i < nb_txq; i++) {
516                 if (!tx_qconf[i].valid)
517                         continue;
518                 rc = dev_ops->tx_queue_setup(eth_dev, i, tx_qconf[i].nb_desc, 0,
519                                              &tx_qconf[i].conf.tx);
520                 if (rc) {
521                         plt_err("Failed to setup tx queue rc=%d", rc);
522                         txq = eth_dev->data->tx_queues;
523                         for (i -= 1; i >= 0; i--)
524                                 dev_ops->tx_queue_release(txq[i]);
525                         goto fail;
526                 }
527         }
528
529         free(tx_qconf);
530         tx_qconf = NULL;
531
532         for (i = 0; i < nb_rxq; i++) {
533                 if (!rx_qconf[i].valid)
534                         continue;
535                 rc = dev_ops->rx_queue_setup(eth_dev, i, rx_qconf[i].nb_desc, 0,
536                                              &rx_qconf[i].conf.rx,
537                                              rx_qconf[i].mp);
538                 if (rc) {
539                         plt_err("Failed to setup rx queue rc=%d", rc);
540                         rxq = eth_dev->data->rx_queues;
541                         for (i -= 1; i >= 0; i--)
542                                 dev_ops->rx_queue_release(rxq[i]);
543                         goto tx_queue_release;
544                 }
545         }
546
547         free(rx_qconf);
548         rx_qconf = NULL;
549
550         return 0;
551
552 tx_queue_release:
553         txq = eth_dev->data->tx_queues;
554         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
555                 dev_ops->tx_queue_release(txq[i]);
556 fail:
557         if (tx_qconf)
558                 free(tx_qconf);
559         if (rx_qconf)
560                 free(rx_qconf);
561
562         return rc;
563 }
564
565 static uint16_t
566 nix_eth_nop_burst(void *queue, struct rte_mbuf **mbufs, uint16_t pkts)
567 {
568         RTE_SET_USED(queue);
569         RTE_SET_USED(mbufs);
570         RTE_SET_USED(pkts);
571
572         return 0;
573 }
574
575 static void
576 nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev)
577 {
578         /* These dummy functions are required for supporting
579          * some applications which reconfigure queues without
580          * stopping tx burst and rx burst threads(eg kni app)
581          * When the queues context is saved, txq/rxqs are released
582          * which caused app crash since rx/tx burst is still
583          * on different lcores
584          */
585         eth_dev->tx_pkt_burst = nix_eth_nop_burst;
586         eth_dev->rx_pkt_burst = nix_eth_nop_burst;
587         rte_mb();
588 }
589
590 static int
591 nix_lso_tun_fmt_update(struct cnxk_eth_dev *dev)
592 {
593         uint8_t udp_tun[ROC_NIX_LSO_TUN_MAX];
594         uint8_t tun[ROC_NIX_LSO_TUN_MAX];
595         struct roc_nix *nix = &dev->nix;
596         int rc;
597
598         rc = roc_nix_lso_fmt_get(nix, udp_tun, tun);
599         if (rc)
600                 return rc;
601
602         dev->lso_tun_fmt = ((uint64_t)tun[ROC_NIX_LSO_TUN_V4V4] |
603                             (uint64_t)tun[ROC_NIX_LSO_TUN_V4V6] << 8 |
604                             (uint64_t)tun[ROC_NIX_LSO_TUN_V6V4] << 16 |
605                             (uint64_t)tun[ROC_NIX_LSO_TUN_V6V6] << 24);
606
607         dev->lso_tun_fmt |= ((uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V4] << 32 |
608                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V6] << 40 |
609                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V4] << 48 |
610                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V6] << 56);
611         return 0;
612 }
613
614 static int
615 nix_lso_fmt_setup(struct cnxk_eth_dev *dev)
616 {
617         struct roc_nix *nix = &dev->nix;
618         int rc;
619
620         /* Nothing much to do if offload is not enabled */
621         if (!(dev->tx_offloads &
622               (DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
623                DEV_TX_OFFLOAD_GENEVE_TNL_TSO | DEV_TX_OFFLOAD_GRE_TNL_TSO)))
624                 return 0;
625
626         /* Setup LSO formats in AF. Its a no-op if other ethdev has
627          * already set it up
628          */
629         rc = roc_nix_lso_fmt_setup(nix);
630         if (rc)
631                 return rc;
632
633         return nix_lso_tun_fmt_update(dev);
634 }
635
636 int
637 cnxk_nix_configure(struct rte_eth_dev *eth_dev)
638 {
639         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
640         struct rte_eth_dev_data *data = eth_dev->data;
641         struct rte_eth_conf *conf = &data->dev_conf;
642         struct rte_eth_rxmode *rxmode = &conf->rxmode;
643         struct rte_eth_txmode *txmode = &conf->txmode;
644         char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
645         struct roc_nix *nix = &dev->nix;
646         struct rte_ether_addr *ea;
647         uint8_t nb_rxq, nb_txq;
648         uint64_t rx_cfg;
649         void *qs;
650         int rc;
651
652         rc = -EINVAL;
653
654         /* Sanity checks */
655         if (rte_eal_has_hugepages() == 0) {
656                 plt_err("Huge page is not configured");
657                 goto fail_configure;
658         }
659
660         if (conf->dcb_capability_en == 1) {
661                 plt_err("dcb enable is not supported");
662                 goto fail_configure;
663         }
664
665         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
666                 plt_err("Flow director is not supported");
667                 goto fail_configure;
668         }
669
670         if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
671             rxmode->mq_mode != ETH_MQ_RX_RSS) {
672                 plt_err("Unsupported mq rx mode %d", rxmode->mq_mode);
673                 goto fail_configure;
674         }
675
676         if (txmode->mq_mode != ETH_MQ_TX_NONE) {
677                 plt_err("Unsupported mq tx mode %d", txmode->mq_mode);
678                 goto fail_configure;
679         }
680
681         /* Free the resources allocated from the previous configure */
682         if (dev->configured == 1) {
683                 /* Unregister queue irq's */
684                 roc_nix_unregister_queue_irqs(nix);
685
686                 /* Unregister CQ irqs if present */
687                 if (eth_dev->data->dev_conf.intr_conf.rxq)
688                         roc_nix_unregister_cq_irqs(nix);
689
690                 /* Set no-op functions */
691                 nix_set_nop_rxtx_function(eth_dev);
692                 /* Store queue config for later */
693                 rc = nix_store_queue_cfg_and_then_release(eth_dev);
694                 if (rc)
695                         goto fail_configure;
696                 roc_nix_tm_fini(nix);
697                 roc_nix_lf_free(nix);
698         }
699
700         dev->rx_offloads = rxmode->offloads;
701         dev->tx_offloads = txmode->offloads;
702
703         /* Prepare rx cfg */
704         rx_cfg = ROC_NIX_LF_RX_CFG_DIS_APAD;
705         if (dev->rx_offloads &
706             (DEV_RX_OFFLOAD_TCP_CKSUM | DEV_RX_OFFLOAD_UDP_CKSUM)) {
707                 rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_OL4;
708                 rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_IL4;
709         }
710         rx_cfg |= (ROC_NIX_LF_RX_CFG_DROP_RE | ROC_NIX_LF_RX_CFG_L2_LEN_ERR |
711                    ROC_NIX_LF_RX_CFG_LEN_IL4 | ROC_NIX_LF_RX_CFG_LEN_IL3 |
712                    ROC_NIX_LF_RX_CFG_LEN_OL4 | ROC_NIX_LF_RX_CFG_LEN_OL3);
713
714         nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
715         nb_txq = RTE_MAX(data->nb_tx_queues, 1);
716
717         /* Alloc a nix lf */
718         rc = roc_nix_lf_alloc(nix, nb_rxq, nb_txq, rx_cfg);
719         if (rc) {
720                 plt_err("Failed to init nix_lf rc=%d", rc);
721                 goto fail_configure;
722         }
723
724         nb_rxq = data->nb_rx_queues;
725         nb_txq = data->nb_tx_queues;
726         rc = -ENOMEM;
727         if (nb_rxq) {
728                 /* Allocate memory for roc rq's and cq's */
729                 qs = plt_zmalloc(sizeof(struct roc_nix_rq) * nb_rxq, 0);
730                 if (!qs) {
731                         plt_err("Failed to alloc rqs");
732                         goto free_nix_lf;
733                 }
734                 dev->rqs = qs;
735
736                 qs = plt_zmalloc(sizeof(struct roc_nix_cq) * nb_rxq, 0);
737                 if (!qs) {
738                         plt_err("Failed to alloc cqs");
739                         goto free_nix_lf;
740                 }
741                 dev->cqs = qs;
742         }
743
744         if (nb_txq) {
745                 /* Allocate memory for roc sq's */
746                 qs = plt_zmalloc(sizeof(struct roc_nix_sq) * nb_txq, 0);
747                 if (!qs) {
748                         plt_err("Failed to alloc sqs");
749                         goto free_nix_lf;
750                 }
751                 dev->sqs = qs;
752         }
753
754         /* Re-enable NIX LF error interrupts */
755         roc_nix_err_intr_ena_dis(nix, true);
756         roc_nix_ras_intr_ena_dis(nix, true);
757
758         if (nix->rx_ptp_ena) {
759                 plt_err("Both PTP and switch header enabled");
760                 goto free_nix_lf;
761         }
762
763         /* Setup LSO if needed */
764         rc = nix_lso_fmt_setup(dev);
765         if (rc) {
766                 plt_err("Failed to setup nix lso format fields, rc=%d", rc);
767                 goto free_nix_lf;
768         }
769
770         /* Configure RSS */
771         rc = nix_rss_default_setup(dev);
772         if (rc) {
773                 plt_err("Failed to configure rss rc=%d", rc);
774                 goto free_nix_lf;
775         }
776
777         /* Init the default TM scheduler hierarchy */
778         rc = roc_nix_tm_init(nix);
779         if (rc) {
780                 plt_err("Failed to init traffic manager, rc=%d", rc);
781                 goto free_nix_lf;
782         }
783
784         rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
785         if (rc) {
786                 plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
787                 goto tm_fini;
788         }
789
790         /* Register queue IRQs */
791         rc = roc_nix_register_queue_irqs(nix);
792         if (rc) {
793                 plt_err("Failed to register queue interrupts rc=%d", rc);
794                 goto tm_fini;
795         }
796
797         /* Register cq IRQs */
798         if (eth_dev->data->dev_conf.intr_conf.rxq) {
799                 if (eth_dev->data->nb_rx_queues > dev->nix.cints) {
800                         plt_err("Rx interrupt cannot be enabled, rxq > %d",
801                                 dev->nix.cints);
802                         goto q_irq_fini;
803                 }
804                 /* Rx interrupt feature cannot work with vector mode because,
805                  * vector mode does not process packets unless min 4 pkts are
806                  * received, while cq interrupts are generated even for 1 pkt
807                  * in the CQ.
808                  */
809                 dev->scalar_ena = true;
810
811                 rc = roc_nix_register_cq_irqs(nix);
812                 if (rc) {
813                         plt_err("Failed to register CQ interrupts rc=%d", rc);
814                         goto q_irq_fini;
815                 }
816         }
817
818         /* Configure loop back mode */
819         rc = roc_nix_mac_loopback_enable(nix,
820                                          eth_dev->data->dev_conf.lpbk_mode);
821         if (rc) {
822                 plt_err("Failed to configure cgx loop back mode rc=%d", rc);
823                 goto cq_fini;
824         }
825
826         /*
827          * Restore queue config when reconfigure followed by
828          * reconfigure and no queue configure invoked from application case.
829          */
830         if (dev->configured == 1) {
831                 rc = nix_restore_queue_cfg(eth_dev);
832                 if (rc)
833                         goto cq_fini;
834         }
835
836         /* Update the mac address */
837         ea = eth_dev->data->mac_addrs;
838         memcpy(ea, dev->mac_addr, RTE_ETHER_ADDR_LEN);
839         if (rte_is_zero_ether_addr(ea))
840                 rte_eth_random_addr((uint8_t *)ea);
841
842         rte_ether_format_addr(ea_fmt, RTE_ETHER_ADDR_FMT_SIZE, ea);
843
844         plt_nix_dbg("Configured port%d mac=%s nb_rxq=%d nb_txq=%d"
845                     " rx_offloads=0x%" PRIx64 " tx_offloads=0x%" PRIx64 "",
846                     eth_dev->data->port_id, ea_fmt, nb_rxq, nb_txq,
847                     dev->rx_offloads, dev->tx_offloads);
848
849         /* All good */
850         dev->configured = 1;
851         dev->nb_rxq = data->nb_rx_queues;
852         dev->nb_txq = data->nb_tx_queues;
853         return 0;
854
855 cq_fini:
856         roc_nix_unregister_cq_irqs(nix);
857 q_irq_fini:
858         roc_nix_unregister_queue_irqs(nix);
859 tm_fini:
860         roc_nix_tm_fini(nix);
861 free_nix_lf:
862         nix_free_queue_mem(dev);
863         rc |= roc_nix_lf_free(nix);
864 fail_configure:
865         dev->configured = 0;
866         return rc;
867 }
868
869 static int
870 cnxk_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
871 {
872         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
873         struct rte_eth_dev_data *data = eth_dev->data;
874         struct roc_nix_sq *sq = &dev->sqs[qid];
875         int rc = -EINVAL;
876
877         if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
878                 return 0;
879
880         rc = roc_nix_tm_sq_aura_fc(sq, true);
881         if (rc) {
882                 plt_err("Failed to enable sq aura fc, txq=%u, rc=%d", qid, rc);
883                 goto done;
884         }
885
886         data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
887 done:
888         return rc;
889 }
890
891 int
892 cnxk_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
893 {
894         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
895         struct rte_eth_dev_data *data = eth_dev->data;
896         struct roc_nix_sq *sq = &dev->sqs[qid];
897         int rc;
898
899         if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
900                 return 0;
901
902         rc = roc_nix_tm_sq_aura_fc(sq, false);
903         if (rc) {
904                 plt_err("Failed to disable sqb aura fc, txq=%u, rc=%d", qid,
905                         rc);
906                 goto done;
907         }
908
909         data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
910 done:
911         return rc;
912 }
913
914 static int
915 cnxk_nix_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
916 {
917         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
918         struct rte_eth_dev_data *data = eth_dev->data;
919         struct roc_nix_rq *rq = &dev->rqs[qid];
920         int rc;
921
922         if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
923                 return 0;
924
925         rc = roc_nix_rq_ena_dis(rq, true);
926         if (rc) {
927                 plt_err("Failed to enable rxq=%u, rc=%d", qid, rc);
928                 goto done;
929         }
930
931         data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
932 done:
933         return rc;
934 }
935
936 static int
937 cnxk_nix_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
938 {
939         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
940         struct rte_eth_dev_data *data = eth_dev->data;
941         struct roc_nix_rq *rq = &dev->rqs[qid];
942         int rc;
943
944         if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
945                 return 0;
946
947         rc = roc_nix_rq_ena_dis(rq, false);
948         if (rc) {
949                 plt_err("Failed to disable rxq=%u, rc=%d", qid, rc);
950                 goto done;
951         }
952
953         data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
954 done:
955         return rc;
956 }
957
958 /* CNXK platform independent eth dev ops */
959 struct eth_dev_ops cnxk_eth_dev_ops = {
960         .dev_infos_get = cnxk_nix_info_get,
961         .link_update = cnxk_nix_link_update,
962         .tx_queue_release = cnxk_nix_tx_queue_release,
963         .rx_queue_release = cnxk_nix_rx_queue_release,
964         .tx_queue_start = cnxk_nix_tx_queue_start,
965         .rx_queue_start = cnxk_nix_rx_queue_start,
966         .rx_queue_stop = cnxk_nix_rx_queue_stop,
967         .dev_supported_ptypes_get = cnxk_nix_supported_ptypes_get,
968 };
969
970 static int
971 cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
972 {
973         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
974         struct roc_nix *nix = &dev->nix;
975         struct rte_pci_device *pci_dev;
976         int rc, max_entries;
977
978         eth_dev->dev_ops = &cnxk_eth_dev_ops;
979
980         /* For secondary processes, the primary has done all the work */
981         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
982                 return 0;
983
984         pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
985         rte_eth_copy_pci_info(eth_dev, pci_dev);
986
987         /* Parse devargs string */
988         rc = cnxk_ethdev_parse_devargs(eth_dev->device->devargs, dev);
989         if (rc) {
990                 plt_err("Failed to parse devargs rc=%d", rc);
991                 goto error;
992         }
993
994         /* Initialize base roc nix */
995         nix->pci_dev = pci_dev;
996         rc = roc_nix_dev_init(nix);
997         if (rc) {
998                 plt_err("Failed to initialize roc nix rc=%d", rc);
999                 goto error;
1000         }
1001
1002         /* Register up msg callbacks */
1003         roc_nix_mac_link_cb_register(nix, cnxk_eth_dev_link_status_cb);
1004
1005         dev->eth_dev = eth_dev;
1006         dev->configured = 0;
1007         dev->ptype_disable = 0;
1008
1009         /* For vfs, returned max_entries will be 0. but to keep default mac
1010          * address, one entry must be allocated. so setting up to 1.
1011          */
1012         if (roc_nix_is_vf_or_sdp(nix))
1013                 max_entries = 1;
1014         else
1015                 max_entries = roc_nix_mac_max_entries_get(nix);
1016
1017         if (max_entries <= 0) {
1018                 plt_err("Failed to get max entries for mac addr");
1019                 rc = -ENOTSUP;
1020                 goto dev_fini;
1021         }
1022
1023         eth_dev->data->mac_addrs =
1024                 rte_zmalloc("mac_addr", max_entries * RTE_ETHER_ADDR_LEN, 0);
1025         if (eth_dev->data->mac_addrs == NULL) {
1026                 plt_err("Failed to allocate memory for mac addr");
1027                 rc = -ENOMEM;
1028                 goto dev_fini;
1029         }
1030
1031         dev->max_mac_entries = max_entries;
1032
1033         /* Get mac address */
1034         rc = roc_nix_npc_mac_addr_get(nix, dev->mac_addr);
1035         if (rc) {
1036                 plt_err("Failed to get mac addr, rc=%d", rc);
1037                 goto free_mac_addrs;
1038         }
1039
1040         /* Update the mac address */
1041         memcpy(eth_dev->data->mac_addrs, dev->mac_addr, RTE_ETHER_ADDR_LEN);
1042
1043         if (!roc_nix_is_vf_or_sdp(nix)) {
1044                 /* Sync same MAC address to CGX/RPM table */
1045                 rc = roc_nix_mac_addr_set(nix, dev->mac_addr);
1046                 if (rc) {
1047                         plt_err("Failed to set mac addr, rc=%d", rc);
1048                         goto free_mac_addrs;
1049                 }
1050         }
1051
1052         /* Union of all capabilities supported by CNXK.
1053          * Platform specific capabilities will be
1054          * updated later.
1055          */
1056         dev->rx_offload_capa = nix_get_rx_offload_capa(dev);
1057         dev->tx_offload_capa = nix_get_tx_offload_capa(dev);
1058         dev->speed_capa = nix_get_speed_capa(dev);
1059
1060         /* Initialize roc npc */
1061         plt_nix_dbg("Port=%d pf=%d vf=%d ver=%s hwcap=0x%" PRIx64
1062                     " rxoffload_capa=0x%" PRIx64 " txoffload_capa=0x%" PRIx64,
1063                     eth_dev->data->port_id, roc_nix_get_pf(nix),
1064                     roc_nix_get_vf(nix), CNXK_ETH_DEV_PMD_VERSION, dev->hwcap,
1065                     dev->rx_offload_capa, dev->tx_offload_capa);
1066         return 0;
1067
1068 free_mac_addrs:
1069         rte_free(eth_dev->data->mac_addrs);
1070 dev_fini:
1071         roc_nix_dev_fini(nix);
1072 error:
1073         plt_err("Failed to init nix eth_dev rc=%d", rc);
1074         return rc;
1075 }
1076
1077 static int
1078 cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool mbox_close)
1079 {
1080         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1081         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
1082         struct roc_nix *nix = &dev->nix;
1083         int rc, i;
1084
1085         /* Nothing to be done for secondary processes */
1086         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1087                 return 0;
1088
1089         /* Clear the flag since we are closing down */
1090         dev->configured = 0;
1091
1092         roc_nix_npc_rx_ena_dis(nix, false);
1093
1094         /* Disable link status events */
1095         roc_nix_mac_link_event_start_stop(nix, false);
1096
1097         /* Free up SQs */
1098         for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
1099                 dev_ops->tx_queue_release(eth_dev->data->tx_queues[i]);
1100                 eth_dev->data->tx_queues[i] = NULL;
1101         }
1102         eth_dev->data->nb_tx_queues = 0;
1103
1104         /* Free up RQ's and CQ's */
1105         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1106                 dev_ops->rx_queue_release(eth_dev->data->rx_queues[i]);
1107                 eth_dev->data->rx_queues[i] = NULL;
1108         }
1109         eth_dev->data->nb_rx_queues = 0;
1110
1111         /* Free tm resources */
1112         roc_nix_tm_fini(nix);
1113
1114         /* Unregister queue irqs */
1115         roc_nix_unregister_queue_irqs(nix);
1116
1117         /* Unregister cq irqs */
1118         if (eth_dev->data->dev_conf.intr_conf.rxq)
1119                 roc_nix_unregister_cq_irqs(nix);
1120
1121         /* Free ROC RQ's, SQ's and CQ's memory */
1122         nix_free_queue_mem(dev);
1123
1124         /* Free nix lf resources */
1125         rc = roc_nix_lf_free(nix);
1126         if (rc)
1127                 plt_err("Failed to free nix lf, rc=%d", rc);
1128
1129         rte_free(eth_dev->data->mac_addrs);
1130         eth_dev->data->mac_addrs = NULL;
1131
1132         /* Check if mbox close is needed */
1133         if (!mbox_close)
1134                 return 0;
1135
1136         rc = roc_nix_dev_fini(nix);
1137         /* Can be freed later by PMD if NPA LF is in use */
1138         if (rc == -EAGAIN) {
1139                 eth_dev->data->dev_private = NULL;
1140                 return 0;
1141         } else if (rc) {
1142                 plt_err("Failed in nix dev fini, rc=%d", rc);
1143         }
1144
1145         return rc;
1146 }
1147
1148 int
1149 cnxk_nix_remove(struct rte_pci_device *pci_dev)
1150 {
1151         struct rte_eth_dev *eth_dev;
1152         struct roc_nix *nix;
1153         int rc = -EINVAL;
1154
1155         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
1156         if (eth_dev) {
1157                 /* Cleanup eth dev */
1158                 rc = cnxk_eth_dev_uninit(eth_dev, true);
1159                 if (rc)
1160                         return rc;
1161
1162                 rte_eth_dev_release_port(eth_dev);
1163         }
1164
1165         /* Nothing to be done for secondary processes */
1166         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1167                 return 0;
1168
1169         /* Check if this device is hosting common resource */
1170         nix = roc_idev_npa_nix_get();
1171         if (nix->pci_dev != pci_dev)
1172                 return 0;
1173
1174         /* Try nix fini now */
1175         rc = roc_nix_dev_fini(nix);
1176         if (rc == -EAGAIN) {
1177                 plt_info("%s: common resource in use by other devices",
1178                          pci_dev->name);
1179                 goto exit;
1180         } else if (rc) {
1181                 plt_err("Failed in nix dev fini, rc=%d", rc);
1182                 goto exit;
1183         }
1184
1185         /* Free device pointer as rte_ethdev does not have it anymore */
1186         rte_free(nix);
1187 exit:
1188         return rc;
1189 }
1190
1191 int
1192 cnxk_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
1193 {
1194         int rc;
1195
1196         RTE_SET_USED(pci_drv);
1197
1198         rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct cnxk_eth_dev),
1199                                            cnxk_eth_dev_init);
1200
1201         /* On error on secondary, recheck if port exists in primary or
1202          * in mid of detach state.
1203          */
1204         if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
1205                 if (!rte_eth_dev_allocated(pci_dev->device.name))
1206                         return 0;
1207         return rc;
1208 }