0a420c1fb142f3566f45ca8a07e35689714cf0e9
[dpdk.git] / drivers / net / octeontx2 / otx2_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #include <inttypes.h>
6
7 #include <ethdev_pci.h>
8 #include <rte_io.h>
9 #include <rte_malloc.h>
10 #include <rte_mbuf.h>
11 #include <rte_mbuf_pool_ops.h>
12 #include <rte_mempool.h>
13
14 #include "otx2_ethdev.h"
15 #include "otx2_ethdev_sec.h"
16
17 static inline uint64_t
18 nix_get_rx_offload_capa(struct otx2_eth_dev *dev)
19 {
20         uint64_t capa = NIX_RX_OFFLOAD_CAPA;
21
22         if (otx2_dev_is_vf(dev) ||
23             dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG)
24                 capa &= ~DEV_RX_OFFLOAD_TIMESTAMP;
25
26         return capa;
27 }
28
29 static inline uint64_t
30 nix_get_tx_offload_capa(struct otx2_eth_dev *dev)
31 {
32         uint64_t capa = NIX_TX_OFFLOAD_CAPA;
33
34         /* TSO not supported for earlier chip revisions */
35         if (otx2_dev_is_96xx_A0(dev) || otx2_dev_is_95xx_Ax(dev))
36                 capa &= ~(DEV_TX_OFFLOAD_TCP_TSO |
37                           DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
38                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
39                           DEV_TX_OFFLOAD_GRE_TNL_TSO);
40         return capa;
41 }
42
43 static const struct otx2_dev_ops otx2_dev_ops = {
44         .link_status_update = otx2_eth_dev_link_status_update,
45         .ptp_info_update = otx2_eth_dev_ptp_info_update
46 };
47
48 static int
49 nix_lf_alloc(struct otx2_eth_dev *dev, uint32_t nb_rxq, uint32_t nb_txq)
50 {
51         struct otx2_mbox *mbox = dev->mbox;
52         struct nix_lf_alloc_req *req;
53         struct nix_lf_alloc_rsp *rsp;
54         int rc;
55
56         req = otx2_mbox_alloc_msg_nix_lf_alloc(mbox);
57         req->rq_cnt = nb_rxq;
58         req->sq_cnt = nb_txq;
59         req->cq_cnt = nb_rxq;
60         /* XQE_SZ should be in Sync with NIX_CQ_ENTRY_SZ */
61         RTE_BUILD_BUG_ON(NIX_CQ_ENTRY_SZ != 128);
62         req->xqe_sz = NIX_XQESZ_W16;
63         req->rss_sz = dev->rss_info.rss_size;
64         req->rss_grps = NIX_RSS_GRPS;
65         req->npa_func = otx2_npa_pf_func_get();
66         req->sso_func = otx2_sso_pf_func_get();
67         req->rx_cfg = BIT_ULL(35 /* DIS_APAD */);
68         if (dev->rx_offloads & (DEV_RX_OFFLOAD_TCP_CKSUM |
69                          DEV_RX_OFFLOAD_UDP_CKSUM)) {
70                 req->rx_cfg |= BIT_ULL(37 /* CSUM_OL4 */);
71                 req->rx_cfg |= BIT_ULL(36 /* CSUM_IL4 */);
72         }
73         req->rx_cfg |= (BIT_ULL(32 /* DROP_RE */)             |
74                         BIT_ULL(33 /* Outer L2 Length */)     |
75                         BIT_ULL(38 /* Inner L4 UDP Length */) |
76                         BIT_ULL(39 /* Inner L3 Length */)     |
77                         BIT_ULL(40 /* Outer L4 UDP Length */) |
78                         BIT_ULL(41 /* Outer L3 Length */));
79
80         if (dev->rss_tag_as_xor == 0)
81                 req->flags = NIX_LF_RSS_TAG_LSB_AS_ADDER;
82
83         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
84         if (rc)
85                 return rc;
86
87         dev->sqb_size = rsp->sqb_size;
88         dev->tx_chan_base = rsp->tx_chan_base;
89         dev->rx_chan_base = rsp->rx_chan_base;
90         dev->rx_chan_cnt = rsp->rx_chan_cnt;
91         dev->tx_chan_cnt = rsp->tx_chan_cnt;
92         dev->lso_tsov4_idx = rsp->lso_tsov4_idx;
93         dev->lso_tsov6_idx = rsp->lso_tsov6_idx;
94         dev->lf_tx_stats = rsp->lf_tx_stats;
95         dev->lf_rx_stats = rsp->lf_rx_stats;
96         dev->cints = rsp->cints;
97         dev->qints = rsp->qints;
98         dev->npc_flow.channel = dev->rx_chan_base;
99         dev->ptp_en = rsp->hw_rx_tstamp_en;
100
101         return 0;
102 }
103
104 static int
105 nix_lf_switch_header_type_enable(struct otx2_eth_dev *dev, bool enable)
106 {
107         struct otx2_mbox *mbox = dev->mbox;
108         struct npc_set_pkind *req;
109         struct msg_resp *rsp;
110         int rc;
111
112         if (dev->npc_flow.switch_header_type == 0)
113                 return 0;
114
115         /* Notify AF about higig2 config */
116         req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
117         req->mode = dev->npc_flow.switch_header_type;
118         if (dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_CH_LEN_90B) {
119                 req->mode = OTX2_PRIV_FLAGS_CUSTOM;
120                 req->pkind = NPC_RX_CHLEN90B_PKIND;
121         } else if (dev->npc_flow.switch_header_type ==
122                    OTX2_PRIV_FLAGS_CH_LEN_24B) {
123                 req->mode = OTX2_PRIV_FLAGS_CUSTOM;
124                 req->pkind = NPC_RX_CHLEN24B_PKIND;
125         } else if (dev->npc_flow.switch_header_type ==
126                    OTX2_PRIV_FLAGS_EXDSA) {
127                 req->mode = OTX2_PRIV_FLAGS_CUSTOM;
128                 req->pkind = NPC_RX_EXDSA_PKIND;
129         } else if (dev->npc_flow.switch_header_type ==
130                    OTX2_PRIV_FLAGS_VLAN_EXDSA) {
131                 req->mode = OTX2_PRIV_FLAGS_CUSTOM;
132                 req->pkind = NPC_RX_VLAN_EXDSA_PKIND;
133         }
134
135         if (enable == 0)
136                 req->mode = OTX2_PRIV_FLAGS_DEFAULT;
137         req->dir = PKIND_RX;
138         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
139         if (rc)
140                 return rc;
141         req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
142         req->mode = dev->npc_flow.switch_header_type;
143         if (dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_CH_LEN_90B ||
144             dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_CH_LEN_24B)
145                 req->mode = OTX2_PRIV_FLAGS_DEFAULT;
146
147         if (enable == 0)
148                 req->mode = OTX2_PRIV_FLAGS_DEFAULT;
149         req->dir = PKIND_TX;
150         return otx2_mbox_process_msg(mbox, (void *)&rsp);
151 }
152
153 static int
154 nix_lf_free(struct otx2_eth_dev *dev)
155 {
156         struct otx2_mbox *mbox = dev->mbox;
157         struct nix_lf_free_req *req;
158         struct ndc_sync_op *ndc_req;
159         int rc;
160
161         /* Sync NDC-NIX for LF */
162         ndc_req = otx2_mbox_alloc_msg_ndc_sync_op(mbox);
163         ndc_req->nix_lf_tx_sync = 1;
164         ndc_req->nix_lf_rx_sync = 1;
165         rc = otx2_mbox_process(mbox);
166         if (rc)
167                 otx2_err("Error on NDC-NIX-[TX, RX] LF sync, rc %d", rc);
168
169         req = otx2_mbox_alloc_msg_nix_lf_free(mbox);
170         /* Let AF driver free all this nix lf's
171          * NPC entries allocated using NPC MBOX.
172          */
173         req->flags = 0;
174
175         return otx2_mbox_process(mbox);
176 }
177
178 int
179 otx2_cgx_rxtx_start(struct otx2_eth_dev *dev)
180 {
181         struct otx2_mbox *mbox = dev->mbox;
182
183         if (otx2_dev_is_vf_or_sdp(dev))
184                 return 0;
185
186         otx2_mbox_alloc_msg_cgx_start_rxtx(mbox);
187
188         return otx2_mbox_process(mbox);
189 }
190
191 int
192 otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev)
193 {
194         struct otx2_mbox *mbox = dev->mbox;
195
196         if (otx2_dev_is_vf_or_sdp(dev))
197                 return 0;
198
199         otx2_mbox_alloc_msg_cgx_stop_rxtx(mbox);
200
201         return otx2_mbox_process(mbox);
202 }
203
204 static int
205 npc_rx_enable(struct otx2_eth_dev *dev)
206 {
207         struct otx2_mbox *mbox = dev->mbox;
208
209         otx2_mbox_alloc_msg_nix_lf_start_rx(mbox);
210
211         return otx2_mbox_process(mbox);
212 }
213
214 static int
215 npc_rx_disable(struct otx2_eth_dev *dev)
216 {
217         struct otx2_mbox *mbox = dev->mbox;
218
219         otx2_mbox_alloc_msg_nix_lf_stop_rx(mbox);
220
221         return otx2_mbox_process(mbox);
222 }
223
224 static int
225 nix_cgx_start_link_event(struct otx2_eth_dev *dev)
226 {
227         struct otx2_mbox *mbox = dev->mbox;
228
229         if (otx2_dev_is_vf_or_sdp(dev))
230                 return 0;
231
232         otx2_mbox_alloc_msg_cgx_start_linkevents(mbox);
233
234         return otx2_mbox_process(mbox);
235 }
236
237 static int
238 cgx_intlbk_enable(struct otx2_eth_dev *dev, bool en)
239 {
240         struct otx2_mbox *mbox = dev->mbox;
241
242         if (en && otx2_dev_is_vf_or_sdp(dev))
243                 return -ENOTSUP;
244
245         if (en)
246                 otx2_mbox_alloc_msg_cgx_intlbk_enable(mbox);
247         else
248                 otx2_mbox_alloc_msg_cgx_intlbk_disable(mbox);
249
250         return otx2_mbox_process(mbox);
251 }
252
253 static int
254 nix_cgx_stop_link_event(struct otx2_eth_dev *dev)
255 {
256         struct otx2_mbox *mbox = dev->mbox;
257
258         if (otx2_dev_is_vf_or_sdp(dev))
259                 return 0;
260
261         otx2_mbox_alloc_msg_cgx_stop_linkevents(mbox);
262
263         return otx2_mbox_process(mbox);
264 }
265
266 static inline void
267 nix_rx_queue_reset(struct otx2_eth_rxq *rxq)
268 {
269         rxq->head = 0;
270         rxq->available = 0;
271 }
272
273 static inline uint32_t
274 nix_qsize_to_val(enum nix_q_size_e qsize)
275 {
276         return (16UL << (qsize * 2));
277 }
278
279 static inline enum nix_q_size_e
280 nix_qsize_clampup_get(struct otx2_eth_dev *dev, uint32_t val)
281 {
282         int i;
283
284         if (otx2_ethdev_fixup_is_min_4k_q(dev))
285                 i = nix_q_size_4K;
286         else
287                 i = nix_q_size_16;
288
289         for (; i < nix_q_size_max; i++)
290                 if (val <= nix_qsize_to_val(i))
291                         break;
292
293         if (i >= nix_q_size_max)
294                 i = nix_q_size_max - 1;
295
296         return i;
297 }
298
299 static int
300 nix_cq_rq_init(struct rte_eth_dev *eth_dev, struct otx2_eth_dev *dev,
301                uint16_t qid, struct otx2_eth_rxq *rxq, struct rte_mempool *mp)
302 {
303         struct otx2_mbox *mbox = dev->mbox;
304         const struct rte_memzone *rz;
305         uint32_t ring_size, cq_size;
306         struct nix_aq_enq_req *aq;
307         uint16_t first_skip;
308         int rc;
309
310         cq_size = rxq->qlen;
311         ring_size = cq_size * NIX_CQ_ENTRY_SZ;
312         rz = rte_eth_dma_zone_reserve(eth_dev, "cq", qid, ring_size,
313                                       NIX_CQ_ALIGN, dev->node);
314         if (rz == NULL) {
315                 otx2_err("Failed to allocate mem for cq hw ring");
316                 return -ENOMEM;
317         }
318         memset(rz->addr, 0, rz->len);
319         rxq->desc = (uintptr_t)rz->addr;
320         rxq->qmask = cq_size - 1;
321
322         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
323         aq->qidx = qid;
324         aq->ctype = NIX_AQ_CTYPE_CQ;
325         aq->op = NIX_AQ_INSTOP_INIT;
326
327         aq->cq.ena = 1;
328         aq->cq.caching = 1;
329         aq->cq.qsize = rxq->qsize;
330         aq->cq.base = rz->iova;
331         aq->cq.avg_level = 0xff;
332         aq->cq.cq_err_int_ena = BIT(NIX_CQERRINT_CQE_FAULT);
333         aq->cq.cq_err_int_ena |= BIT(NIX_CQERRINT_DOOR_ERR);
334
335         /* Many to one reduction */
336         aq->cq.qint_idx = qid % dev->qints;
337         /* Map CQ0 [RQ0] to CINT0 and so on till max 64 irqs */
338         aq->cq.cint_idx = qid;
339
340         if (otx2_ethdev_fixup_is_limit_cq_full(dev)) {
341                 const float rx_cq_skid = NIX_CQ_FULL_ERRATA_SKID;
342                 uint16_t min_rx_drop;
343
344                 min_rx_drop = ceil(rx_cq_skid / (float)cq_size);
345                 aq->cq.drop = min_rx_drop;
346                 aq->cq.drop_ena = 1;
347                 rxq->cq_drop = min_rx_drop;
348         } else {
349                 rxq->cq_drop = NIX_CQ_THRESH_LEVEL;
350                 aq->cq.drop = rxq->cq_drop;
351                 aq->cq.drop_ena = 1;
352         }
353
354         /* TX pause frames enable flowctrl on RX side */
355         if (dev->fc_info.tx_pause) {
356                 /* Single bpid is allocated for all rx channels for now */
357                 aq->cq.bpid = dev->fc_info.bpid[0];
358                 aq->cq.bp = rxq->cq_drop;
359                 aq->cq.bp_ena = 1;
360         }
361
362         rc = otx2_mbox_process(mbox);
363         if (rc) {
364                 otx2_err("Failed to init cq context");
365                 return rc;
366         }
367
368         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
369         aq->qidx = qid;
370         aq->ctype = NIX_AQ_CTYPE_RQ;
371         aq->op = NIX_AQ_INSTOP_INIT;
372
373         aq->rq.sso_ena = 0;
374
375         if (rxq->offloads & DEV_RX_OFFLOAD_SECURITY)
376                 aq->rq.ipsech_ena = 1;
377
378         aq->rq.cq = qid; /* RQ to CQ 1:1 mapped */
379         aq->rq.spb_ena = 0;
380         aq->rq.lpb_aura = npa_lf_aura_handle_to_aura(mp->pool_id);
381         first_skip = (sizeof(struct rte_mbuf));
382         first_skip += RTE_PKTMBUF_HEADROOM;
383         first_skip += rte_pktmbuf_priv_size(mp);
384         rxq->data_off = first_skip;
385
386         first_skip /= 8; /* Expressed in number of dwords */
387         aq->rq.first_skip = first_skip;
388         aq->rq.later_skip = (sizeof(struct rte_mbuf) / 8);
389         aq->rq.flow_tagw = 32; /* 32-bits */
390         aq->rq.lpb_sizem1 = mp->elt_size / 8;
391         aq->rq.lpb_sizem1 -= 1; /* Expressed in size minus one */
392         aq->rq.ena = 1;
393         aq->rq.pb_caching = 0x2; /* First cache aligned block to LLC */
394         aq->rq.xqe_imm_size = 0; /* No pkt data copy to CQE */
395         aq->rq.rq_int_ena = 0;
396         /* Many to one reduction */
397         aq->rq.qint_idx = qid % dev->qints;
398
399         aq->rq.xqe_drop_ena = 1;
400
401         rc = otx2_mbox_process(mbox);
402         if (rc) {
403                 otx2_err("Failed to init rq context");
404                 return rc;
405         }
406
407         if (dev->lock_rx_ctx) {
408                 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
409                 aq->qidx = qid;
410                 aq->ctype = NIX_AQ_CTYPE_CQ;
411                 aq->op = NIX_AQ_INSTOP_LOCK;
412
413                 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
414                 if (!aq) {
415                         /* The shared memory buffer can be full.
416                          * Flush it and retry
417                          */
418                         otx2_mbox_msg_send(mbox, 0);
419                         rc = otx2_mbox_wait_for_rsp(mbox, 0);
420                         if (rc < 0) {
421                                 otx2_err("Failed to LOCK cq context");
422                                 return rc;
423                         }
424
425                         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
426                         if (!aq) {
427                                 otx2_err("Failed to LOCK rq context");
428                                 return -ENOMEM;
429                         }
430                 }
431                 aq->qidx = qid;
432                 aq->ctype = NIX_AQ_CTYPE_RQ;
433                 aq->op = NIX_AQ_INSTOP_LOCK;
434                 rc = otx2_mbox_process(mbox);
435                 if (rc < 0) {
436                         otx2_err("Failed to LOCK rq context");
437                         return rc;
438                 }
439         }
440
441         return 0;
442 }
443
444 static int
445 nix_rq_enb_dis(struct rte_eth_dev *eth_dev,
446                struct otx2_eth_rxq *rxq, const bool enb)
447 {
448         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
449         struct otx2_mbox *mbox = dev->mbox;
450         struct nix_aq_enq_req *aq;
451
452         /* Pkts will be dropped silently if RQ is disabled */
453         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
454         aq->qidx = rxq->rq;
455         aq->ctype = NIX_AQ_CTYPE_RQ;
456         aq->op = NIX_AQ_INSTOP_WRITE;
457
458         aq->rq.ena = enb;
459         aq->rq_mask.ena = ~(aq->rq_mask.ena);
460
461         return otx2_mbox_process(mbox);
462 }
463
464 static int
465 nix_cq_rq_uninit(struct rte_eth_dev *eth_dev, struct otx2_eth_rxq *rxq)
466 {
467         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
468         struct otx2_mbox *mbox = dev->mbox;
469         struct nix_aq_enq_req *aq;
470         int rc;
471
472         /* RQ is already disabled */
473         /* Disable CQ */
474         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
475         aq->qidx = rxq->rq;
476         aq->ctype = NIX_AQ_CTYPE_CQ;
477         aq->op = NIX_AQ_INSTOP_WRITE;
478
479         aq->cq.ena = 0;
480         aq->cq_mask.ena = ~(aq->cq_mask.ena);
481
482         rc = otx2_mbox_process(mbox);
483         if (rc < 0) {
484                 otx2_err("Failed to disable cq context");
485                 return rc;
486         }
487
488         if (dev->lock_rx_ctx) {
489                 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
490                 aq->qidx = rxq->rq;
491                 aq->ctype = NIX_AQ_CTYPE_CQ;
492                 aq->op = NIX_AQ_INSTOP_UNLOCK;
493
494                 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
495                 if (!aq) {
496                         /* The shared memory buffer can be full.
497                          * Flush it and retry
498                          */
499                         otx2_mbox_msg_send(mbox, 0);
500                         rc = otx2_mbox_wait_for_rsp(mbox, 0);
501                         if (rc < 0) {
502                                 otx2_err("Failed to UNLOCK cq context");
503                                 return rc;
504                         }
505
506                         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
507                         if (!aq) {
508                                 otx2_err("Failed to UNLOCK rq context");
509                                 return -ENOMEM;
510                         }
511                 }
512                 aq->qidx = rxq->rq;
513                 aq->ctype = NIX_AQ_CTYPE_RQ;
514                 aq->op = NIX_AQ_INSTOP_UNLOCK;
515                 rc = otx2_mbox_process(mbox);
516                 if (rc < 0) {
517                         otx2_err("Failed to UNLOCK rq context");
518                         return rc;
519                 }
520         }
521
522         return 0;
523 }
524
525 static inline int
526 nix_get_data_off(struct otx2_eth_dev *dev)
527 {
528         return otx2_ethdev_is_ptp_en(dev) ? NIX_TIMESYNC_RX_OFFSET : 0;
529 }
530
531 uint64_t
532 otx2_nix_rxq_mbuf_setup(struct otx2_eth_dev *dev, uint16_t port_id)
533 {
534         struct rte_mbuf mb_def;
535         uint64_t *tmp;
536
537         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
538         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
539                                 offsetof(struct rte_mbuf, data_off) != 2);
540         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
541                                 offsetof(struct rte_mbuf, data_off) != 4);
542         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
543                                 offsetof(struct rte_mbuf, data_off) != 6);
544         mb_def.nb_segs = 1;
545         mb_def.data_off = RTE_PKTMBUF_HEADROOM + nix_get_data_off(dev);
546         mb_def.port = port_id;
547         rte_mbuf_refcnt_set(&mb_def, 1);
548
549         /* Prevent compiler reordering: rearm_data covers previous fields */
550         rte_compiler_barrier();
551         tmp = (uint64_t *)&mb_def.rearm_data;
552
553         return *tmp;
554 }
555
556 static void
557 otx2_nix_rx_queue_release(void *rx_queue)
558 {
559         struct otx2_eth_rxq *rxq = rx_queue;
560
561         if (!rxq)
562                 return;
563
564         otx2_nix_dbg("Releasing rxq %u", rxq->rq);
565         nix_cq_rq_uninit(rxq->eth_dev, rxq);
566         rte_free(rx_queue);
567 }
568
569 static int
570 otx2_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t rq,
571                         uint16_t nb_desc, unsigned int socket,
572                         const struct rte_eth_rxconf *rx_conf,
573                         struct rte_mempool *mp)
574 {
575         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
576         struct rte_mempool_ops *ops;
577         struct otx2_eth_rxq *rxq;
578         const char *platform_ops;
579         enum nix_q_size_e qsize;
580         uint64_t offloads;
581         int rc;
582
583         rc = -EINVAL;
584
585         /* Compile time check to make sure all fast path elements in a CL */
586         RTE_BUILD_BUG_ON(offsetof(struct otx2_eth_rxq, slow_path_start) >= 128);
587
588         /* Sanity checks */
589         if (rx_conf->rx_deferred_start == 1) {
590                 otx2_err("Deferred Rx start is not supported");
591                 goto fail;
592         }
593
594         platform_ops = rte_mbuf_platform_mempool_ops();
595         /* This driver needs octeontx2_npa mempool ops to work */
596         ops = rte_mempool_get_ops(mp->ops_index);
597         if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
598                 otx2_err("mempool ops should be of octeontx2_npa type");
599                 goto fail;
600         }
601
602         if (mp->pool_id == 0) {
603                 otx2_err("Invalid pool_id");
604                 goto fail;
605         }
606
607         /* Free memory prior to re-allocation if needed */
608         if (eth_dev->data->rx_queues[rq] != NULL) {
609                 otx2_nix_dbg("Freeing memory prior to re-allocation %d", rq);
610                 otx2_nix_rx_queue_release(eth_dev->data->rx_queues[rq]);
611                 rte_eth_dma_zone_free(eth_dev, "cq", rq);
612                 eth_dev->data->rx_queues[rq] = NULL;
613         }
614
615         offloads = rx_conf->offloads | eth_dev->data->dev_conf.rxmode.offloads;
616         dev->rx_offloads |= offloads;
617
618         /* Find the CQ queue size */
619         qsize = nix_qsize_clampup_get(dev, nb_desc);
620         /* Allocate rxq memory */
621         rxq = rte_zmalloc_socket("otx2 rxq", sizeof(*rxq), OTX2_ALIGN, socket);
622         if (rxq == NULL) {
623                 otx2_err("Failed to allocate rq=%d", rq);
624                 rc = -ENOMEM;
625                 goto fail;
626         }
627
628         rxq->eth_dev = eth_dev;
629         rxq->rq = rq;
630         rxq->cq_door = dev->base + NIX_LF_CQ_OP_DOOR;
631         rxq->cq_status = (int64_t *)(dev->base + NIX_LF_CQ_OP_STATUS);
632         rxq->wdata = (uint64_t)rq << 32;
633         rxq->aura = npa_lf_aura_handle_to_aura(mp->pool_id);
634         rxq->mbuf_initializer = otx2_nix_rxq_mbuf_setup(dev,
635                                                         eth_dev->data->port_id);
636         rxq->offloads = offloads;
637         rxq->pool = mp;
638         rxq->qlen = nix_qsize_to_val(qsize);
639         rxq->qsize = qsize;
640         rxq->lookup_mem = otx2_nix_fastpath_lookup_mem_get();
641         rxq->tstamp = &dev->tstamp;
642
643         /* Alloc completion queue */
644         rc = nix_cq_rq_init(eth_dev, dev, rq, rxq, mp);
645         if (rc) {
646                 otx2_err("Failed to allocate rxq=%u", rq);
647                 goto free_rxq;
648         }
649
650         rxq->qconf.socket_id = socket;
651         rxq->qconf.nb_desc = nb_desc;
652         rxq->qconf.mempool = mp;
653         memcpy(&rxq->qconf.conf.rx, rx_conf, sizeof(struct rte_eth_rxconf));
654
655         nix_rx_queue_reset(rxq);
656         otx2_nix_dbg("rq=%d pool=%s qsize=%d nb_desc=%d->%d",
657                      rq, mp->name, qsize, nb_desc, rxq->qlen);
658
659         eth_dev->data->rx_queues[rq] = rxq;
660         eth_dev->data->rx_queue_state[rq] = RTE_ETH_QUEUE_STATE_STOPPED;
661
662         /* Calculating delta and freq mult between PTP HI clock and tsc.
663          * These are needed in deriving raw clock value from tsc counter.
664          * read_clock eth op returns raw clock value.
665          */
666         if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) ||
667             otx2_ethdev_is_ptp_en(dev)) {
668                 rc = otx2_nix_raw_clock_tsc_conv(dev);
669                 if (rc) {
670                         otx2_err("Failed to calculate delta and freq mult");
671                         goto fail;
672                 }
673         }
674
675         /* Setup scatter mode if needed by jumbo */
676         otx2_nix_enable_mseg_on_jumbo(rxq);
677
678         return 0;
679
680 free_rxq:
681         otx2_nix_rx_queue_release(rxq);
682 fail:
683         return rc;
684 }
685
686 static inline uint8_t
687 nix_sq_max_sqe_sz(struct otx2_eth_txq *txq)
688 {
689         /*
690          * Maximum three segments can be supported with W8, Choose
691          * NIX_MAXSQESZ_W16 for multi segment offload.
692          */
693         if (txq->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
694                 return NIX_MAXSQESZ_W16;
695         else
696                 return NIX_MAXSQESZ_W8;
697 }
698
699 static uint16_t
700 nix_rx_offload_flags(struct rte_eth_dev *eth_dev)
701 {
702         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
703         struct rte_eth_dev_data *data = eth_dev->data;
704         struct rte_eth_conf *conf = &data->dev_conf;
705         struct rte_eth_rxmode *rxmode = &conf->rxmode;
706         uint16_t flags = 0;
707
708         if (rxmode->mq_mode == ETH_MQ_RX_RSS &&
709                         (dev->rx_offloads & DEV_RX_OFFLOAD_RSS_HASH))
710                 flags |= NIX_RX_OFFLOAD_RSS_F;
711
712         if (dev->rx_offloads & (DEV_RX_OFFLOAD_TCP_CKSUM |
713                          DEV_RX_OFFLOAD_UDP_CKSUM))
714                 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
715
716         if (dev->rx_offloads & (DEV_RX_OFFLOAD_IPV4_CKSUM |
717                                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM))
718                 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
719
720         if (dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER)
721                 flags |= NIX_RX_MULTI_SEG_F;
722
723         if (dev->rx_offloads & (DEV_RX_OFFLOAD_VLAN_STRIP |
724                                 DEV_RX_OFFLOAD_QINQ_STRIP))
725                 flags |= NIX_RX_OFFLOAD_VLAN_STRIP_F;
726
727         if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP))
728                 flags |= NIX_RX_OFFLOAD_TSTAMP_F;
729
730         if (dev->rx_offloads & DEV_RX_OFFLOAD_SECURITY)
731                 flags |= NIX_RX_OFFLOAD_SECURITY_F;
732
733         if (!dev->ptype_disable)
734                 flags |= NIX_RX_OFFLOAD_PTYPE_F;
735
736         return flags;
737 }
738
739 static uint16_t
740 nix_tx_offload_flags(struct rte_eth_dev *eth_dev)
741 {
742         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
743         uint64_t conf = dev->tx_offloads;
744         uint16_t flags = 0;
745
746         /* Fastpath is dependent on these enums */
747         RTE_BUILD_BUG_ON(PKT_TX_TCP_CKSUM != (1ULL << 52));
748         RTE_BUILD_BUG_ON(PKT_TX_SCTP_CKSUM != (2ULL << 52));
749         RTE_BUILD_BUG_ON(PKT_TX_UDP_CKSUM != (3ULL << 52));
750         RTE_BUILD_BUG_ON(PKT_TX_IP_CKSUM != (1ULL << 54));
751         RTE_BUILD_BUG_ON(PKT_TX_IPV4 != (1ULL << 55));
752         RTE_BUILD_BUG_ON(PKT_TX_OUTER_IP_CKSUM != (1ULL << 58));
753         RTE_BUILD_BUG_ON(PKT_TX_OUTER_IPV4 != (1ULL << 59));
754         RTE_BUILD_BUG_ON(PKT_TX_OUTER_IPV6 != (1ULL << 60));
755         RTE_BUILD_BUG_ON(PKT_TX_OUTER_UDP_CKSUM != (1ULL << 41));
756         RTE_BUILD_BUG_ON(RTE_MBUF_L2_LEN_BITS != 7);
757         RTE_BUILD_BUG_ON(RTE_MBUF_L3_LEN_BITS != 9);
758         RTE_BUILD_BUG_ON(RTE_MBUF_OUTL2_LEN_BITS != 7);
759         RTE_BUILD_BUG_ON(RTE_MBUF_OUTL3_LEN_BITS != 9);
760         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) !=
761                          offsetof(struct rte_mbuf, buf_iova) + 8);
762         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
763                          offsetof(struct rte_mbuf, buf_iova) + 16);
764         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
765                          offsetof(struct rte_mbuf, ol_flags) + 12);
766         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, tx_offload) !=
767                          offsetof(struct rte_mbuf, pool) + 2 * sizeof(void *));
768
769         if (conf & DEV_TX_OFFLOAD_VLAN_INSERT ||
770             conf & DEV_TX_OFFLOAD_QINQ_INSERT)
771                 flags |= NIX_TX_OFFLOAD_VLAN_QINQ_F;
772
773         if (conf & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
774             conf & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
775                 flags |= NIX_TX_OFFLOAD_OL3_OL4_CSUM_F;
776
777         if (conf & DEV_TX_OFFLOAD_IPV4_CKSUM ||
778             conf & DEV_TX_OFFLOAD_TCP_CKSUM ||
779             conf & DEV_TX_OFFLOAD_UDP_CKSUM ||
780             conf & DEV_TX_OFFLOAD_SCTP_CKSUM)
781                 flags |= NIX_TX_OFFLOAD_L3_L4_CSUM_F;
782
783         if (!(conf & DEV_TX_OFFLOAD_MBUF_FAST_FREE))
784                 flags |= NIX_TX_OFFLOAD_MBUF_NOFF_F;
785
786         if (conf & DEV_TX_OFFLOAD_MULTI_SEGS)
787                 flags |= NIX_TX_MULTI_SEG_F;
788
789         /* Enable Inner checksum for TSO */
790         if (conf & DEV_TX_OFFLOAD_TCP_TSO)
791                 flags |= (NIX_TX_OFFLOAD_TSO_F |
792                           NIX_TX_OFFLOAD_L3_L4_CSUM_F);
793
794         /* Enable Inner and Outer checksum for Tunnel TSO */
795         if (conf & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
796                     DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
797                     DEV_TX_OFFLOAD_GRE_TNL_TSO))
798                 flags |= (NIX_TX_OFFLOAD_TSO_F |
799                           NIX_TX_OFFLOAD_OL3_OL4_CSUM_F |
800                           NIX_TX_OFFLOAD_L3_L4_CSUM_F);
801
802         if (conf & DEV_TX_OFFLOAD_SECURITY)
803                 flags |= NIX_TX_OFFLOAD_SECURITY_F;
804
805         if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP))
806                 flags |= NIX_TX_OFFLOAD_TSTAMP_F;
807
808         return flags;
809 }
810
811 static int
812 nix_sqb_lock(struct rte_mempool *mp)
813 {
814         struct otx2_npa_lf *npa_lf = otx2_intra_dev_get_cfg()->npa_lf;
815         struct npa_aq_enq_req *req;
816         int rc;
817
818         req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
819         req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
820         req->ctype = NPA_AQ_CTYPE_AURA;
821         req->op = NPA_AQ_INSTOP_LOCK;
822
823         req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
824         if (!req) {
825                 /* The shared memory buffer can be full.
826                  * Flush it and retry
827                  */
828                 otx2_mbox_msg_send(npa_lf->mbox, 0);
829                 rc = otx2_mbox_wait_for_rsp(npa_lf->mbox, 0);
830                 if (rc < 0) {
831                         otx2_err("Failed to LOCK AURA context");
832                         return rc;
833                 }
834
835                 req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
836                 if (!req) {
837                         otx2_err("Failed to LOCK POOL context");
838                         return -ENOMEM;
839                 }
840         }
841
842         req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
843         req->ctype = NPA_AQ_CTYPE_POOL;
844         req->op = NPA_AQ_INSTOP_LOCK;
845
846         rc = otx2_mbox_process(npa_lf->mbox);
847         if (rc < 0) {
848                 otx2_err("Unable to lock POOL in NDC");
849                 return rc;
850         }
851
852         return 0;
853 }
854
855 static int
856 nix_sqb_unlock(struct rte_mempool *mp)
857 {
858         struct otx2_npa_lf *npa_lf = otx2_intra_dev_get_cfg()->npa_lf;
859         struct npa_aq_enq_req *req;
860         int rc;
861
862         req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
863         req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
864         req->ctype = NPA_AQ_CTYPE_AURA;
865         req->op = NPA_AQ_INSTOP_UNLOCK;
866
867         req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
868         if (!req) {
869                 /* The shared memory buffer can be full.
870                  * Flush it and retry
871                  */
872                 otx2_mbox_msg_send(npa_lf->mbox, 0);
873                 rc = otx2_mbox_wait_for_rsp(npa_lf->mbox, 0);
874                 if (rc < 0) {
875                         otx2_err("Failed to UNLOCK AURA context");
876                         return rc;
877                 }
878
879                 req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
880                 if (!req) {
881                         otx2_err("Failed to UNLOCK POOL context");
882                         return -ENOMEM;
883                 }
884         }
885         req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
886         req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
887         req->ctype = NPA_AQ_CTYPE_POOL;
888         req->op = NPA_AQ_INSTOP_UNLOCK;
889
890         rc = otx2_mbox_process(npa_lf->mbox);
891         if (rc < 0) {
892                 otx2_err("Unable to UNLOCK AURA in NDC");
893                 return rc;
894         }
895
896         return 0;
897 }
898
899 void
900 otx2_nix_enable_mseg_on_jumbo(struct otx2_eth_rxq *rxq)
901 {
902         struct rte_pktmbuf_pool_private *mbp_priv;
903         struct rte_eth_dev *eth_dev;
904         struct otx2_eth_dev *dev;
905         uint32_t buffsz;
906
907         eth_dev = rxq->eth_dev;
908         dev = otx2_eth_pmd_priv(eth_dev);
909
910         /* Get rx buffer size */
911         mbp_priv = rte_mempool_get_priv(rxq->pool);
912         buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
913
914         if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len > buffsz) {
915                 dev->rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
916                 dev->tx_offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
917
918                 /* Setting up the rx[tx]_offload_flags due to change
919                  * in rx[tx]_offloads.
920                  */
921                 dev->rx_offload_flags |= nix_rx_offload_flags(eth_dev);
922                 dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
923         }
924 }
925
926 static int
927 nix_sq_init(struct otx2_eth_txq *txq)
928 {
929         struct otx2_eth_dev *dev = txq->dev;
930         struct otx2_mbox *mbox = dev->mbox;
931         struct nix_aq_enq_req *sq;
932         uint32_t rr_quantum;
933         uint16_t smq;
934         int rc;
935
936         if (txq->sqb_pool->pool_id == 0)
937                 return -EINVAL;
938
939         rc = otx2_nix_tm_get_leaf_data(dev, txq->sq, &rr_quantum, &smq);
940         if (rc) {
941                 otx2_err("Failed to get sq->smq(leaf node), rc=%d", rc);
942                 return rc;
943         }
944
945         sq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
946         sq->qidx = txq->sq;
947         sq->ctype = NIX_AQ_CTYPE_SQ;
948         sq->op = NIX_AQ_INSTOP_INIT;
949         sq->sq.max_sqe_size = nix_sq_max_sqe_sz(txq);
950
951         sq->sq.smq = smq;
952         sq->sq.smq_rr_quantum = rr_quantum;
953         sq->sq.default_chan = dev->tx_chan_base;
954         sq->sq.sqe_stype = NIX_STYPE_STF;
955         sq->sq.ena = 1;
956         if (sq->sq.max_sqe_size == NIX_MAXSQESZ_W8)
957                 sq->sq.sqe_stype = NIX_STYPE_STP;
958         sq->sq.sqb_aura =
959                 npa_lf_aura_handle_to_aura(txq->sqb_pool->pool_id);
960         sq->sq.sq_int_ena = BIT(NIX_SQINT_LMT_ERR);
961         sq->sq.sq_int_ena |= BIT(NIX_SQINT_SQB_ALLOC_FAIL);
962         sq->sq.sq_int_ena |= BIT(NIX_SQINT_SEND_ERR);
963         sq->sq.sq_int_ena |= BIT(NIX_SQINT_MNQ_ERR);
964
965         /* Many to one reduction */
966         sq->sq.qint_idx = txq->sq % dev->qints;
967
968         rc = otx2_mbox_process(mbox);
969         if (rc < 0)
970                 return rc;
971
972         if (dev->lock_tx_ctx) {
973                 sq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
974                 sq->qidx = txq->sq;
975                 sq->ctype = NIX_AQ_CTYPE_SQ;
976                 sq->op = NIX_AQ_INSTOP_LOCK;
977
978                 rc = otx2_mbox_process(mbox);
979         }
980
981         return rc;
982 }
983
984 static int
985 nix_sq_uninit(struct otx2_eth_txq *txq)
986 {
987         struct otx2_eth_dev *dev = txq->dev;
988         struct otx2_mbox *mbox = dev->mbox;
989         struct ndc_sync_op *ndc_req;
990         struct nix_aq_enq_rsp *rsp;
991         struct nix_aq_enq_req *aq;
992         uint16_t sqes_per_sqb;
993         void *sqb_buf;
994         int rc, count;
995
996         otx2_nix_dbg("Cleaning up sq %u", txq->sq);
997
998         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
999         aq->qidx = txq->sq;
1000         aq->ctype = NIX_AQ_CTYPE_SQ;
1001         aq->op = NIX_AQ_INSTOP_READ;
1002
1003         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1004         if (rc)
1005                 return rc;
1006
1007         /* Check if sq is already cleaned up */
1008         if (!rsp->sq.ena)
1009                 return 0;
1010
1011         /* Disable sq */
1012         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
1013         aq->qidx = txq->sq;
1014         aq->ctype = NIX_AQ_CTYPE_SQ;
1015         aq->op = NIX_AQ_INSTOP_WRITE;
1016
1017         aq->sq_mask.ena = ~aq->sq_mask.ena;
1018         aq->sq.ena = 0;
1019
1020         rc = otx2_mbox_process(mbox);
1021         if (rc)
1022                 return rc;
1023
1024         if (dev->lock_tx_ctx) {
1025                 /* Unlock sq */
1026                 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
1027                 aq->qidx = txq->sq;
1028                 aq->ctype = NIX_AQ_CTYPE_SQ;
1029                 aq->op = NIX_AQ_INSTOP_UNLOCK;
1030
1031                 rc = otx2_mbox_process(mbox);
1032                 if (rc < 0)
1033                         return rc;
1034
1035                 nix_sqb_unlock(txq->sqb_pool);
1036         }
1037
1038         /* Read SQ and free sqb's */
1039         aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
1040         aq->qidx = txq->sq;
1041         aq->ctype = NIX_AQ_CTYPE_SQ;
1042         aq->op = NIX_AQ_INSTOP_READ;
1043
1044         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1045         if (rc)
1046                 return rc;
1047
1048         if (aq->sq.smq_pend)
1049                 otx2_err("SQ has pending sqe's");
1050
1051         count = aq->sq.sqb_count;
1052         sqes_per_sqb = 1 << txq->sqes_per_sqb_log2;
1053         /* Free SQB's that are used */
1054         sqb_buf = (void *)rsp->sq.head_sqb;
1055         while (count) {
1056                 void *next_sqb;
1057
1058                 next_sqb = *(void **)((uintptr_t)sqb_buf + (uint32_t)
1059                                       ((sqes_per_sqb - 1) *
1060                                       nix_sq_max_sqe_sz(txq)));
1061                 npa_lf_aura_op_free(txq->sqb_pool->pool_id, 1,
1062                                     (uint64_t)sqb_buf);
1063                 sqb_buf = next_sqb;
1064                 count--;
1065         }
1066
1067         /* Free next to use sqb */
1068         if (rsp->sq.next_sqb)
1069                 npa_lf_aura_op_free(txq->sqb_pool->pool_id, 1,
1070                                     rsp->sq.next_sqb);
1071
1072         /* Sync NDC-NIX-TX for LF */
1073         ndc_req = otx2_mbox_alloc_msg_ndc_sync_op(mbox);
1074         ndc_req->nix_lf_tx_sync = 1;
1075         rc = otx2_mbox_process(mbox);
1076         if (rc)
1077                 otx2_err("Error on NDC-NIX-TX LF sync, rc %d", rc);
1078
1079         return rc;
1080 }
1081
1082 static int
1083 nix_sqb_aura_limit_cfg(struct rte_mempool *mp, uint16_t nb_sqb_bufs)
1084 {
1085         struct otx2_npa_lf *npa_lf = otx2_intra_dev_get_cfg()->npa_lf;
1086         struct npa_aq_enq_req *aura_req;
1087
1088         aura_req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
1089         aura_req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
1090         aura_req->ctype = NPA_AQ_CTYPE_AURA;
1091         aura_req->op = NPA_AQ_INSTOP_WRITE;
1092
1093         aura_req->aura.limit = nb_sqb_bufs;
1094         aura_req->aura_mask.limit = ~(aura_req->aura_mask.limit);
1095
1096         return otx2_mbox_process(npa_lf->mbox);
1097 }
1098
1099 static int
1100 nix_alloc_sqb_pool(int port, struct otx2_eth_txq *txq, uint16_t nb_desc)
1101 {
1102         struct otx2_eth_dev *dev = txq->dev;
1103         uint16_t sqes_per_sqb, nb_sqb_bufs;
1104         char name[RTE_MEMPOOL_NAMESIZE];
1105         struct rte_mempool_objsz sz;
1106         struct npa_aura_s *aura;
1107         uint32_t tmp, blk_sz;
1108
1109         aura = (struct npa_aura_s *)((uintptr_t)txq->fc_mem + OTX2_ALIGN);
1110         snprintf(name, sizeof(name), "otx2_sqb_pool_%d_%d", port, txq->sq);
1111         blk_sz = dev->sqb_size;
1112
1113         if (nix_sq_max_sqe_sz(txq) == NIX_MAXSQESZ_W16)
1114                 sqes_per_sqb = (dev->sqb_size / 8) / 16;
1115         else
1116                 sqes_per_sqb = (dev->sqb_size / 8) / 8;
1117
1118         nb_sqb_bufs = nb_desc / sqes_per_sqb;
1119         /* Clamp up to devarg passed SQB count */
1120         nb_sqb_bufs =  RTE_MIN(dev->max_sqb_count, RTE_MAX(NIX_DEF_SQB,
1121                               nb_sqb_bufs + NIX_SQB_LIST_SPACE));
1122
1123         txq->sqb_pool = rte_mempool_create_empty(name, NIX_MAX_SQB, blk_sz,
1124                                                  0, 0, dev->node,
1125                                                  MEMPOOL_F_NO_SPREAD);
1126         txq->nb_sqb_bufs = nb_sqb_bufs;
1127         txq->sqes_per_sqb_log2 = (uint16_t)rte_log2_u32(sqes_per_sqb);
1128         txq->nb_sqb_bufs_adj = nb_sqb_bufs -
1129                 RTE_ALIGN_MUL_CEIL(nb_sqb_bufs, sqes_per_sqb) / sqes_per_sqb;
1130         txq->nb_sqb_bufs_adj =
1131                 (NIX_SQB_LOWER_THRESH * txq->nb_sqb_bufs_adj) / 100;
1132
1133         if (txq->sqb_pool == NULL) {
1134                 otx2_err("Failed to allocate sqe mempool");
1135                 goto fail;
1136         }
1137
1138         memset(aura, 0, sizeof(*aura));
1139         aura->fc_ena = 1;
1140         aura->fc_addr = txq->fc_iova;
1141         aura->fc_hyst_bits = 0; /* Store count on all updates */
1142         if (rte_mempool_set_ops_byname(txq->sqb_pool, "octeontx2_npa", aura)) {
1143                 otx2_err("Failed to set ops for sqe mempool");
1144                 goto fail;
1145         }
1146         if (rte_mempool_populate_default(txq->sqb_pool) < 0) {
1147                 otx2_err("Failed to populate sqe mempool");
1148                 goto fail;
1149         }
1150
1151         tmp = rte_mempool_calc_obj_size(blk_sz, MEMPOOL_F_NO_SPREAD, &sz);
1152         if (dev->sqb_size != sz.elt_size) {
1153                 otx2_err("sqe pool block size is not expected %d != %d",
1154                          dev->sqb_size, tmp);
1155                 goto fail;
1156         }
1157
1158         nix_sqb_aura_limit_cfg(txq->sqb_pool, txq->nb_sqb_bufs);
1159         if (dev->lock_tx_ctx)
1160                 nix_sqb_lock(txq->sqb_pool);
1161
1162         return 0;
1163 fail:
1164         return -ENOMEM;
1165 }
1166
1167 void
1168 otx2_nix_form_default_desc(struct otx2_eth_txq *txq)
1169 {
1170         struct nix_send_ext_s *send_hdr_ext;
1171         struct nix_send_hdr_s *send_hdr;
1172         struct nix_send_mem_s *send_mem;
1173         union nix_send_sg_s *sg;
1174
1175         /* Initialize the fields based on basic single segment packet */
1176         memset(&txq->cmd, 0, sizeof(txq->cmd));
1177
1178         if (txq->dev->tx_offload_flags & NIX_TX_NEED_EXT_HDR) {
1179                 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
1180                 /* 2(HDR) + 2(EXT_HDR) + 1(SG) + 1(IOVA) = 6/2 - 1 = 2 */
1181                 send_hdr->w0.sizem1 = 2;
1182
1183                 send_hdr_ext = (struct nix_send_ext_s *)&txq->cmd[2];
1184                 send_hdr_ext->w0.subdc = NIX_SUBDC_EXT;
1185                 if (txq->dev->tx_offload_flags & NIX_TX_OFFLOAD_TSTAMP_F) {
1186                         /* Default: one seg packet would have:
1187                          * 2(HDR) + 2(EXT) + 1(SG) + 1(IOVA) + 2(MEM)
1188                          * => 8/2 - 1 = 3
1189                          */
1190                         send_hdr->w0.sizem1 = 3;
1191                         send_hdr_ext->w0.tstmp = 1;
1192
1193                         /* To calculate the offset for send_mem,
1194                          * send_hdr->w0.sizem1 * 2
1195                          */
1196                         send_mem = (struct nix_send_mem_s *)(txq->cmd +
1197                                                 (send_hdr->w0.sizem1 << 1));
1198                         send_mem->subdc = NIX_SUBDC_MEM;
1199                         send_mem->alg = NIX_SENDMEMALG_SETTSTMP;
1200                         send_mem->addr = txq->dev->tstamp.tx_tstamp_iova;
1201                 }
1202                 sg = (union nix_send_sg_s *)&txq->cmd[4];
1203         } else {
1204                 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
1205                 /* 2(HDR) + 1(SG) + 1(IOVA) = 4/2 - 1 = 1 */
1206                 send_hdr->w0.sizem1 = 1;
1207                 sg = (union nix_send_sg_s *)&txq->cmd[2];
1208         }
1209
1210         send_hdr->w0.sq = txq->sq;
1211         sg->subdc = NIX_SUBDC_SG;
1212         sg->segs = 1;
1213         sg->ld_type = NIX_SENDLDTYPE_LDD;
1214
1215         rte_smp_wmb();
1216 }
1217
1218 static void
1219 otx2_nix_tx_queue_release(void *_txq)
1220 {
1221         struct otx2_eth_txq *txq = _txq;
1222         struct rte_eth_dev *eth_dev;
1223
1224         if (!txq)
1225                 return;
1226
1227         eth_dev = txq->dev->eth_dev;
1228
1229         otx2_nix_dbg("Releasing txq %u", txq->sq);
1230
1231         /* Flush and disable tm */
1232         otx2_nix_sq_flush_pre(txq, eth_dev->data->dev_started);
1233
1234         /* Free sqb's and disable sq */
1235         nix_sq_uninit(txq);
1236
1237         if (txq->sqb_pool) {
1238                 rte_mempool_free(txq->sqb_pool);
1239                 txq->sqb_pool = NULL;
1240         }
1241         otx2_nix_sq_flush_post(txq);
1242         rte_free(txq);
1243 }
1244
1245
1246 static int
1247 otx2_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t sq,
1248                         uint16_t nb_desc, unsigned int socket_id,
1249                         const struct rte_eth_txconf *tx_conf)
1250 {
1251         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1252         const struct rte_memzone *fc;
1253         struct otx2_eth_txq *txq;
1254         uint64_t offloads;
1255         int rc;
1256
1257         rc = -EINVAL;
1258
1259         /* Compile time check to make sure all fast path elements in a CL */
1260         RTE_BUILD_BUG_ON(offsetof(struct otx2_eth_txq, slow_path_start) >= 128);
1261
1262         if (tx_conf->tx_deferred_start) {
1263                 otx2_err("Tx deferred start is not supported");
1264                 goto fail;
1265         }
1266
1267         /* Free memory prior to re-allocation if needed. */
1268         if (eth_dev->data->tx_queues[sq] != NULL) {
1269                 otx2_nix_dbg("Freeing memory prior to re-allocation %d", sq);
1270                 otx2_nix_tx_queue_release(eth_dev->data->tx_queues[sq]);
1271                 eth_dev->data->tx_queues[sq] = NULL;
1272         }
1273
1274         /* Find the expected offloads for this queue */
1275         offloads = tx_conf->offloads | eth_dev->data->dev_conf.txmode.offloads;
1276
1277         /* Allocating tx queue data structure */
1278         txq = rte_zmalloc_socket("otx2_ethdev TX queue", sizeof(*txq),
1279                                  OTX2_ALIGN, socket_id);
1280         if (txq == NULL) {
1281                 otx2_err("Failed to alloc txq=%d", sq);
1282                 rc = -ENOMEM;
1283                 goto fail;
1284         }
1285         txq->sq = sq;
1286         txq->dev = dev;
1287         txq->sqb_pool = NULL;
1288         txq->offloads = offloads;
1289         dev->tx_offloads |= offloads;
1290
1291         /*
1292          * Allocate memory for flow control updates from HW.
1293          * Alloc one cache line, so that fits all FC_STYPE modes.
1294          */
1295         fc = rte_eth_dma_zone_reserve(eth_dev, "fcmem", sq,
1296                                       OTX2_ALIGN + sizeof(struct npa_aura_s),
1297                                       OTX2_ALIGN, dev->node);
1298         if (fc == NULL) {
1299                 otx2_err("Failed to allocate mem for fcmem");
1300                 rc = -ENOMEM;
1301                 goto free_txq;
1302         }
1303         txq->fc_iova = fc->iova;
1304         txq->fc_mem = fc->addr;
1305
1306         /* Initialize the aura sqb pool */
1307         rc = nix_alloc_sqb_pool(eth_dev->data->port_id, txq, nb_desc);
1308         if (rc) {
1309                 otx2_err("Failed to alloc sqe pool rc=%d", rc);
1310                 goto free_txq;
1311         }
1312
1313         /* Initialize the SQ */
1314         rc = nix_sq_init(txq);
1315         if (rc) {
1316                 otx2_err("Failed to init sq=%d context", sq);
1317                 goto free_txq;
1318         }
1319
1320         txq->fc_cache_pkts = 0;
1321         txq->io_addr = dev->base + NIX_LF_OP_SENDX(0);
1322         /* Evenly distribute LMT slot for each sq */
1323         txq->lmt_addr = (void *)(dev->lmt_addr + ((sq & LMT_SLOT_MASK) << 12));
1324
1325         txq->qconf.socket_id = socket_id;
1326         txq->qconf.nb_desc = nb_desc;
1327         memcpy(&txq->qconf.conf.tx, tx_conf, sizeof(struct rte_eth_txconf));
1328
1329         txq->lso_tun_fmt = dev->lso_tun_fmt;
1330         otx2_nix_form_default_desc(txq);
1331
1332         otx2_nix_dbg("sq=%d fc=%p offload=0x%" PRIx64 " sqb=0x%" PRIx64 ""
1333                      " lmt_addr=%p nb_sqb_bufs=%d sqes_per_sqb_log2=%d", sq,
1334                      fc->addr, offloads, txq->sqb_pool->pool_id, txq->lmt_addr,
1335                      txq->nb_sqb_bufs, txq->sqes_per_sqb_log2);
1336         eth_dev->data->tx_queues[sq] = txq;
1337         eth_dev->data->tx_queue_state[sq] = RTE_ETH_QUEUE_STATE_STOPPED;
1338         return 0;
1339
1340 free_txq:
1341         otx2_nix_tx_queue_release(txq);
1342 fail:
1343         return rc;
1344 }
1345
1346 static int
1347 nix_store_queue_cfg_and_then_release(struct rte_eth_dev *eth_dev)
1348 {
1349         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1350         struct otx2_eth_qconf *tx_qconf = NULL;
1351         struct otx2_eth_qconf *rx_qconf = NULL;
1352         struct otx2_eth_txq **txq;
1353         struct otx2_eth_rxq **rxq;
1354         int i, nb_rxq, nb_txq;
1355
1356         nb_rxq = RTE_MIN(dev->configured_nb_rx_qs, eth_dev->data->nb_rx_queues);
1357         nb_txq = RTE_MIN(dev->configured_nb_tx_qs, eth_dev->data->nb_tx_queues);
1358
1359         tx_qconf = malloc(nb_txq * sizeof(*tx_qconf));
1360         if (tx_qconf == NULL) {
1361                 otx2_err("Failed to allocate memory for tx_qconf");
1362                 goto fail;
1363         }
1364
1365         rx_qconf = malloc(nb_rxq * sizeof(*rx_qconf));
1366         if (rx_qconf == NULL) {
1367                 otx2_err("Failed to allocate memory for rx_qconf");
1368                 goto fail;
1369         }
1370
1371         txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1372         for (i = 0; i < nb_txq; i++) {
1373                 if (txq[i] == NULL) {
1374                         tx_qconf[i].valid = false;
1375                         otx2_info("txq[%d] is already released", i);
1376                         continue;
1377                 }
1378                 memcpy(&tx_qconf[i], &txq[i]->qconf, sizeof(*tx_qconf));
1379                 tx_qconf[i].valid = true;
1380                 otx2_nix_tx_queue_release(txq[i]);
1381                 eth_dev->data->tx_queues[i] = NULL;
1382         }
1383
1384         rxq = (struct otx2_eth_rxq **)eth_dev->data->rx_queues;
1385         for (i = 0; i < nb_rxq; i++) {
1386                 if (rxq[i] == NULL) {
1387                         rx_qconf[i].valid = false;
1388                         otx2_info("rxq[%d] is already released", i);
1389                         continue;
1390                 }
1391                 memcpy(&rx_qconf[i], &rxq[i]->qconf, sizeof(*rx_qconf));
1392                 rx_qconf[i].valid = true;
1393                 otx2_nix_rx_queue_release(rxq[i]);
1394                 eth_dev->data->rx_queues[i] = NULL;
1395         }
1396
1397         dev->tx_qconf = tx_qconf;
1398         dev->rx_qconf = rx_qconf;
1399         return 0;
1400
1401 fail:
1402         free(tx_qconf);
1403         free(rx_qconf);
1404
1405         return -ENOMEM;
1406 }
1407
1408 static int
1409 nix_restore_queue_cfg(struct rte_eth_dev *eth_dev)
1410 {
1411         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1412         struct otx2_eth_qconf *tx_qconf = dev->tx_qconf;
1413         struct otx2_eth_qconf *rx_qconf = dev->rx_qconf;
1414         struct otx2_eth_txq **txq;
1415         struct otx2_eth_rxq **rxq;
1416         int rc, i, nb_rxq, nb_txq;
1417
1418         nb_rxq = RTE_MIN(dev->configured_nb_rx_qs, eth_dev->data->nb_rx_queues);
1419         nb_txq = RTE_MIN(dev->configured_nb_tx_qs, eth_dev->data->nb_tx_queues);
1420
1421         rc = -ENOMEM;
1422         /* Setup tx & rx queues with previous configuration so
1423          * that the queues can be functional in cases like ports
1424          * are started without re configuring queues.
1425          *
1426          * Usual re config sequence is like below:
1427          * port_configure() {
1428          *      if(reconfigure) {
1429          *              queue_release()
1430          *              queue_setup()
1431          *      }
1432          *      queue_configure() {
1433          *              queue_release()
1434          *              queue_setup()
1435          *      }
1436          * }
1437          * port_start()
1438          *
1439          * In some application's control path, queue_configure() would
1440          * NOT be invoked for TXQs/RXQs in port_configure().
1441          * In such cases, queues can be functional after start as the
1442          * queues are already setup in port_configure().
1443          */
1444         for (i = 0; i < nb_txq; i++) {
1445                 if (!tx_qconf[i].valid)
1446                         continue;
1447                 rc = otx2_nix_tx_queue_setup(eth_dev, i, tx_qconf[i].nb_desc,
1448                                              tx_qconf[i].socket_id,
1449                                              &tx_qconf[i].conf.tx);
1450                 if (rc) {
1451                         otx2_err("Failed to setup tx queue rc=%d", rc);
1452                         txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1453                         for (i -= 1; i >= 0; i--)
1454                                 otx2_nix_tx_queue_release(txq[i]);
1455                         goto fail;
1456                 }
1457         }
1458
1459         free(tx_qconf); tx_qconf = NULL;
1460
1461         for (i = 0; i < nb_rxq; i++) {
1462                 if (!rx_qconf[i].valid)
1463                         continue;
1464                 rc = otx2_nix_rx_queue_setup(eth_dev, i, rx_qconf[i].nb_desc,
1465                                              rx_qconf[i].socket_id,
1466                                              &rx_qconf[i].conf.rx,
1467                                              rx_qconf[i].mempool);
1468                 if (rc) {
1469                         otx2_err("Failed to setup rx queue rc=%d", rc);
1470                         rxq = (struct otx2_eth_rxq **)eth_dev->data->rx_queues;
1471                         for (i -= 1; i >= 0; i--)
1472                                 otx2_nix_rx_queue_release(rxq[i]);
1473                         goto release_tx_queues;
1474                 }
1475         }
1476
1477         free(rx_qconf); rx_qconf = NULL;
1478
1479         return 0;
1480
1481 release_tx_queues:
1482         txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1483         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1484                 otx2_nix_tx_queue_release(txq[i]);
1485 fail:
1486         if (tx_qconf)
1487                 free(tx_qconf);
1488         if (rx_qconf)
1489                 free(rx_qconf);
1490
1491         return rc;
1492 }
1493
1494 static uint16_t
1495 nix_eth_nop_burst(void *queue, struct rte_mbuf **mbufs, uint16_t pkts)
1496 {
1497         RTE_SET_USED(queue);
1498         RTE_SET_USED(mbufs);
1499         RTE_SET_USED(pkts);
1500
1501         return 0;
1502 }
1503
1504 static void
1505 nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev)
1506 {
1507         /* These dummy functions are required for supporting
1508          * some applications which reconfigure queues without
1509          * stopping tx burst and rx burst threads(eg kni app)
1510          * When the queues context is saved, txq/rxqs are released
1511          * which caused app crash since rx/tx burst is still
1512          * on different lcores
1513          */
1514         eth_dev->tx_pkt_burst = nix_eth_nop_burst;
1515         eth_dev->rx_pkt_burst = nix_eth_nop_burst;
1516         rte_mb();
1517 }
1518
1519 static void
1520 nix_lso_tcp(struct nix_lso_format_cfg *req, bool v4)
1521 {
1522         volatile struct nix_lso_format *field;
1523
1524         /* Format works only with TCP packet marked by OL3/OL4 */
1525         field = (volatile struct nix_lso_format *)&req->fields[0];
1526         req->field_mask = NIX_LSO_FIELD_MASK;
1527         /* Outer IPv4/IPv6 */
1528         field->layer = NIX_TXLAYER_OL3;
1529         field->offset = v4 ? 2 : 4;
1530         field->sizem1 = 1; /* 2B */
1531         field->alg = NIX_LSOALG_ADD_PAYLEN;
1532         field++;
1533         if (v4) {
1534                 /* IPID field */
1535                 field->layer = NIX_TXLAYER_OL3;
1536                 field->offset = 4;
1537                 field->sizem1 = 1;
1538                 /* Incremented linearly per segment */
1539                 field->alg = NIX_LSOALG_ADD_SEGNUM;
1540                 field++;
1541         }
1542
1543         /* TCP sequence number update */
1544         field->layer = NIX_TXLAYER_OL4;
1545         field->offset = 4;
1546         field->sizem1 = 3; /* 4 bytes */
1547         field->alg = NIX_LSOALG_ADD_OFFSET;
1548         field++;
1549         /* TCP flags field */
1550         field->layer = NIX_TXLAYER_OL4;
1551         field->offset = 12;
1552         field->sizem1 = 1;
1553         field->alg = NIX_LSOALG_TCP_FLAGS;
1554         field++;
1555 }
1556
1557 static void
1558 nix_lso_udp_tun_tcp(struct nix_lso_format_cfg *req,
1559                     bool outer_v4, bool inner_v4)
1560 {
1561         volatile struct nix_lso_format *field;
1562
1563         field = (volatile struct nix_lso_format *)&req->fields[0];
1564         req->field_mask = NIX_LSO_FIELD_MASK;
1565         /* Outer IPv4/IPv6 len */
1566         field->layer = NIX_TXLAYER_OL3;
1567         field->offset = outer_v4 ? 2 : 4;
1568         field->sizem1 = 1; /* 2B */
1569         field->alg = NIX_LSOALG_ADD_PAYLEN;
1570         field++;
1571         if (outer_v4) {
1572                 /* IPID */
1573                 field->layer = NIX_TXLAYER_OL3;
1574                 field->offset = 4;
1575                 field->sizem1 = 1;
1576                 /* Incremented linearly per segment */
1577                 field->alg = NIX_LSOALG_ADD_SEGNUM;
1578                 field++;
1579         }
1580
1581         /* Outer UDP length */
1582         field->layer = NIX_TXLAYER_OL4;
1583         field->offset = 4;
1584         field->sizem1 = 1;
1585         field->alg = NIX_LSOALG_ADD_PAYLEN;
1586         field++;
1587
1588         /* Inner IPv4/IPv6 */
1589         field->layer = NIX_TXLAYER_IL3;
1590         field->offset = inner_v4 ? 2 : 4;
1591         field->sizem1 = 1; /* 2B */
1592         field->alg = NIX_LSOALG_ADD_PAYLEN;
1593         field++;
1594         if (inner_v4) {
1595                 /* IPID field */
1596                 field->layer = NIX_TXLAYER_IL3;
1597                 field->offset = 4;
1598                 field->sizem1 = 1;
1599                 /* Incremented linearly per segment */
1600                 field->alg = NIX_LSOALG_ADD_SEGNUM;
1601                 field++;
1602         }
1603
1604         /* TCP sequence number update */
1605         field->layer = NIX_TXLAYER_IL4;
1606         field->offset = 4;
1607         field->sizem1 = 3; /* 4 bytes */
1608         field->alg = NIX_LSOALG_ADD_OFFSET;
1609         field++;
1610
1611         /* TCP flags field */
1612         field->layer = NIX_TXLAYER_IL4;
1613         field->offset = 12;
1614         field->sizem1 = 1;
1615         field->alg = NIX_LSOALG_TCP_FLAGS;
1616         field++;
1617 }
1618
1619 static void
1620 nix_lso_tun_tcp(struct nix_lso_format_cfg *req,
1621                 bool outer_v4, bool inner_v4)
1622 {
1623         volatile struct nix_lso_format *field;
1624
1625         field = (volatile struct nix_lso_format *)&req->fields[0];
1626         req->field_mask = NIX_LSO_FIELD_MASK;
1627         /* Outer IPv4/IPv6 len */
1628         field->layer = NIX_TXLAYER_OL3;
1629         field->offset = outer_v4 ? 2 : 4;
1630         field->sizem1 = 1; /* 2B */
1631         field->alg = NIX_LSOALG_ADD_PAYLEN;
1632         field++;
1633         if (outer_v4) {
1634                 /* IPID */
1635                 field->layer = NIX_TXLAYER_OL3;
1636                 field->offset = 4;
1637                 field->sizem1 = 1;
1638                 /* Incremented linearly per segment */
1639                 field->alg = NIX_LSOALG_ADD_SEGNUM;
1640                 field++;
1641         }
1642
1643         /* Inner IPv4/IPv6 */
1644         field->layer = NIX_TXLAYER_IL3;
1645         field->offset = inner_v4 ? 2 : 4;
1646         field->sizem1 = 1; /* 2B */
1647         field->alg = NIX_LSOALG_ADD_PAYLEN;
1648         field++;
1649         if (inner_v4) {
1650                 /* IPID field */
1651                 field->layer = NIX_TXLAYER_IL3;
1652                 field->offset = 4;
1653                 field->sizem1 = 1;
1654                 /* Incremented linearly per segment */
1655                 field->alg = NIX_LSOALG_ADD_SEGNUM;
1656                 field++;
1657         }
1658
1659         /* TCP sequence number update */
1660         field->layer = NIX_TXLAYER_IL4;
1661         field->offset = 4;
1662         field->sizem1 = 3; /* 4 bytes */
1663         field->alg = NIX_LSOALG_ADD_OFFSET;
1664         field++;
1665
1666         /* TCP flags field */
1667         field->layer = NIX_TXLAYER_IL4;
1668         field->offset = 12;
1669         field->sizem1 = 1;
1670         field->alg = NIX_LSOALG_TCP_FLAGS;
1671         field++;
1672 }
1673
1674 static int
1675 nix_setup_lso_formats(struct otx2_eth_dev *dev)
1676 {
1677         struct otx2_mbox *mbox = dev->mbox;
1678         struct nix_lso_format_cfg_rsp *rsp;
1679         struct nix_lso_format_cfg *req;
1680         uint8_t *fmt;
1681         int rc;
1682
1683         /* Skip if TSO was not requested */
1684         if (!(dev->tx_offload_flags & NIX_TX_OFFLOAD_TSO_F))
1685                 return 0;
1686         /*
1687          * IPv4/TCP LSO
1688          */
1689         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1690         nix_lso_tcp(req, true);
1691         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1692         if (rc)
1693                 return rc;
1694
1695         if (rsp->lso_format_idx != NIX_LSO_FORMAT_IDX_TSOV4)
1696                 return -EFAULT;
1697         otx2_nix_dbg("tcpv4 lso fmt=%u", rsp->lso_format_idx);
1698
1699
1700         /*
1701          * IPv6/TCP LSO
1702          */
1703         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1704         nix_lso_tcp(req, false);
1705         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1706         if (rc)
1707                 return rc;
1708
1709         if (rsp->lso_format_idx != NIX_LSO_FORMAT_IDX_TSOV6)
1710                 return -EFAULT;
1711         otx2_nix_dbg("tcpv6 lso fmt=%u\n", rsp->lso_format_idx);
1712
1713         /*
1714          * IPv4/UDP/TUN HDR/IPv4/TCP LSO
1715          */
1716         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1717         nix_lso_udp_tun_tcp(req, true, true);
1718         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1719         if (rc)
1720                 return rc;
1721
1722         dev->lso_udp_tun_idx[NIX_LSO_TUN_V4V4] = rsp->lso_format_idx;
1723         otx2_nix_dbg("udp tun v4v4 fmt=%u\n", rsp->lso_format_idx);
1724
1725         /*
1726          * IPv4/UDP/TUN HDR/IPv6/TCP LSO
1727          */
1728         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1729         nix_lso_udp_tun_tcp(req, true, false);
1730         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1731         if (rc)
1732                 return rc;
1733
1734         dev->lso_udp_tun_idx[NIX_LSO_TUN_V4V6] = rsp->lso_format_idx;
1735         otx2_nix_dbg("udp tun v4v6 fmt=%u\n", rsp->lso_format_idx);
1736
1737         /*
1738          * IPv6/UDP/TUN HDR/IPv4/TCP LSO
1739          */
1740         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1741         nix_lso_udp_tun_tcp(req, false, true);
1742         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1743         if (rc)
1744                 return rc;
1745
1746         dev->lso_udp_tun_idx[NIX_LSO_TUN_V6V4] = rsp->lso_format_idx;
1747         otx2_nix_dbg("udp tun v6v4 fmt=%u\n", rsp->lso_format_idx);
1748
1749         /*
1750          * IPv6/UDP/TUN HDR/IPv6/TCP LSO
1751          */
1752         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1753         nix_lso_udp_tun_tcp(req, false, false);
1754         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1755         if (rc)
1756                 return rc;
1757
1758         dev->lso_udp_tun_idx[NIX_LSO_TUN_V6V6] = rsp->lso_format_idx;
1759         otx2_nix_dbg("udp tun v6v6 fmt=%u\n", rsp->lso_format_idx);
1760
1761         /*
1762          * IPv4/TUN HDR/IPv4/TCP LSO
1763          */
1764         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1765         nix_lso_tun_tcp(req, true, true);
1766         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1767         if (rc)
1768                 return rc;
1769
1770         dev->lso_tun_idx[NIX_LSO_TUN_V4V4] = rsp->lso_format_idx;
1771         otx2_nix_dbg("tun v4v4 fmt=%u\n", rsp->lso_format_idx);
1772
1773         /*
1774          * IPv4/TUN HDR/IPv6/TCP LSO
1775          */
1776         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1777         nix_lso_tun_tcp(req, true, false);
1778         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1779         if (rc)
1780                 return rc;
1781
1782         dev->lso_tun_idx[NIX_LSO_TUN_V4V6] = rsp->lso_format_idx;
1783         otx2_nix_dbg("tun v4v6 fmt=%u\n", rsp->lso_format_idx);
1784
1785         /*
1786          * IPv6/TUN HDR/IPv4/TCP LSO
1787          */
1788         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1789         nix_lso_tun_tcp(req, false, true);
1790         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1791         if (rc)
1792                 return rc;
1793
1794         dev->lso_tun_idx[NIX_LSO_TUN_V6V4] = rsp->lso_format_idx;
1795         otx2_nix_dbg("tun v6v4 fmt=%u\n", rsp->lso_format_idx);
1796
1797         /*
1798          * IPv6/TUN HDR/IPv6/TCP LSO
1799          */
1800         req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1801         nix_lso_tun_tcp(req, false, false);
1802         rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1803         if (rc)
1804                 return rc;
1805
1806         dev->lso_tun_idx[NIX_LSO_TUN_V6V6] = rsp->lso_format_idx;
1807         otx2_nix_dbg("tun v6v6 fmt=%u\n", rsp->lso_format_idx);
1808
1809         /* Save all tun formats into u64 for fast path.
1810          * Lower 32bit has non-udp tunnel formats.
1811          * Upper 32bit has udp tunnel formats.
1812          */
1813         fmt = dev->lso_tun_idx;
1814         dev->lso_tun_fmt = ((uint64_t)fmt[NIX_LSO_TUN_V4V4] |
1815                             (uint64_t)fmt[NIX_LSO_TUN_V4V6] << 8 |
1816                             (uint64_t)fmt[NIX_LSO_TUN_V6V4] << 16 |
1817                             (uint64_t)fmt[NIX_LSO_TUN_V6V6] << 24);
1818
1819         fmt = dev->lso_udp_tun_idx;
1820         dev->lso_tun_fmt |= ((uint64_t)fmt[NIX_LSO_TUN_V4V4] << 32 |
1821                              (uint64_t)fmt[NIX_LSO_TUN_V4V6] << 40 |
1822                              (uint64_t)fmt[NIX_LSO_TUN_V6V4] << 48 |
1823                              (uint64_t)fmt[NIX_LSO_TUN_V6V6] << 56);
1824
1825         return 0;
1826 }
1827
1828 static int
1829 otx2_nix_configure(struct rte_eth_dev *eth_dev)
1830 {
1831         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1832         struct rte_eth_dev_data *data = eth_dev->data;
1833         struct rte_eth_conf *conf = &data->dev_conf;
1834         struct rte_eth_rxmode *rxmode = &conf->rxmode;
1835         struct rte_eth_txmode *txmode = &conf->txmode;
1836         char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
1837         struct rte_ether_addr *ea;
1838         uint8_t nb_rxq, nb_txq;
1839         int rc;
1840
1841         rc = -EINVAL;
1842
1843         /* Sanity checks */
1844         if (rte_eal_has_hugepages() == 0) {
1845                 otx2_err("Huge page is not configured");
1846                 goto fail_configure;
1847         }
1848
1849         if (conf->dcb_capability_en == 1) {
1850                 otx2_err("dcb enable is not supported");
1851                 goto fail_configure;
1852         }
1853
1854         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1855                 otx2_err("Flow director is not supported");
1856                 goto fail_configure;
1857         }
1858
1859         if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
1860             rxmode->mq_mode != ETH_MQ_RX_RSS) {
1861                 otx2_err("Unsupported mq rx mode %d", rxmode->mq_mode);
1862                 goto fail_configure;
1863         }
1864
1865         if (txmode->mq_mode != ETH_MQ_TX_NONE) {
1866                 otx2_err("Unsupported mq tx mode %d", txmode->mq_mode);
1867                 goto fail_configure;
1868         }
1869
1870         if (otx2_dev_is_Ax(dev) &&
1871             (txmode->offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
1872             ((txmode->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
1873             (txmode->offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM))) {
1874                 otx2_err("Outer IP and SCTP checksum unsupported");
1875                 goto fail_configure;
1876         }
1877
1878         /* Free the resources allocated from the previous configure */
1879         if (dev->configured == 1) {
1880                 otx2_eth_sec_fini(eth_dev);
1881                 otx2_nix_rxchan_bpid_cfg(eth_dev, false);
1882                 otx2_nix_vlan_fini(eth_dev);
1883                 otx2_nix_mc_addr_list_uninstall(eth_dev);
1884                 otx2_flow_free_all_resources(dev);
1885                 oxt2_nix_unregister_queue_irqs(eth_dev);
1886                 if (eth_dev->data->dev_conf.intr_conf.rxq)
1887                         oxt2_nix_unregister_cq_irqs(eth_dev);
1888                 nix_set_nop_rxtx_function(eth_dev);
1889                 rc = nix_store_queue_cfg_and_then_release(eth_dev);
1890                 if (rc)
1891                         goto fail_configure;
1892                 otx2_nix_tm_fini(eth_dev);
1893                 nix_lf_free(dev);
1894         }
1895
1896         dev->rx_offloads = rxmode->offloads;
1897         dev->tx_offloads = txmode->offloads;
1898         dev->rx_offload_flags |= nix_rx_offload_flags(eth_dev);
1899         dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
1900         dev->rss_info.rss_grps = NIX_RSS_GRPS;
1901
1902         nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
1903         nb_txq = RTE_MAX(data->nb_tx_queues, 1);
1904
1905         /* Alloc a nix lf */
1906         rc = nix_lf_alloc(dev, nb_rxq, nb_txq);
1907         if (rc) {
1908                 otx2_err("Failed to init nix_lf rc=%d", rc);
1909                 goto fail_offloads;
1910         }
1911
1912         otx2_nix_err_intr_enb_dis(eth_dev, true);
1913         otx2_nix_ras_intr_enb_dis(eth_dev, true);
1914
1915         if (dev->ptp_en &&
1916             dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG) {
1917                 otx2_err("Both PTP and switch header enabled");
1918                 goto free_nix_lf;
1919         }
1920
1921         rc = nix_lf_switch_header_type_enable(dev, true);
1922         if (rc) {
1923                 otx2_err("Failed to enable switch type nix_lf rc=%d", rc);
1924                 goto free_nix_lf;
1925         }
1926
1927         rc = nix_setup_lso_formats(dev);
1928         if (rc) {
1929                 otx2_err("failed to setup nix lso format fields, rc=%d", rc);
1930                 goto free_nix_lf;
1931         }
1932
1933         /* Configure RSS */
1934         rc = otx2_nix_rss_config(eth_dev);
1935         if (rc) {
1936                 otx2_err("Failed to configure rss rc=%d", rc);
1937                 goto free_nix_lf;
1938         }
1939
1940         /* Init the default TM scheduler hierarchy */
1941         rc = otx2_nix_tm_init_default(eth_dev);
1942         if (rc) {
1943                 otx2_err("Failed to init traffic manager rc=%d", rc);
1944                 goto free_nix_lf;
1945         }
1946
1947         rc = otx2_nix_vlan_offload_init(eth_dev);
1948         if (rc) {
1949                 otx2_err("Failed to init vlan offload rc=%d", rc);
1950                 goto tm_fini;
1951         }
1952
1953         /* Register queue IRQs */
1954         rc = oxt2_nix_register_queue_irqs(eth_dev);
1955         if (rc) {
1956                 otx2_err("Failed to register queue interrupts rc=%d", rc);
1957                 goto vlan_fini;
1958         }
1959
1960         /* Register cq IRQs */
1961         if (eth_dev->data->dev_conf.intr_conf.rxq) {
1962                 if (eth_dev->data->nb_rx_queues > dev->cints) {
1963                         otx2_err("Rx interrupt cannot be enabled, rxq > %d",
1964                                  dev->cints);
1965                         goto q_irq_fini;
1966                 }
1967                 /* Rx interrupt feature cannot work with vector mode because,
1968                  * vector mode doesn't process packets unless min 4 pkts are
1969                  * received, while cq interrupts are generated even for 1 pkt
1970                  * in the CQ.
1971                  */
1972                 dev->scalar_ena = true;
1973
1974                 rc = oxt2_nix_register_cq_irqs(eth_dev);
1975                 if (rc) {
1976                         otx2_err("Failed to register CQ interrupts rc=%d", rc);
1977                         goto q_irq_fini;
1978                 }
1979         }
1980
1981         /* Configure loop back mode */
1982         rc = cgx_intlbk_enable(dev, eth_dev->data->dev_conf.lpbk_mode);
1983         if (rc) {
1984                 otx2_err("Failed to configure cgx loop back mode rc=%d", rc);
1985                 goto cq_fini;
1986         }
1987
1988         rc = otx2_nix_rxchan_bpid_cfg(eth_dev, true);
1989         if (rc) {
1990                 otx2_err("Failed to configure nix rx chan bpid cfg rc=%d", rc);
1991                 goto cq_fini;
1992         }
1993
1994         /* Enable security */
1995         rc = otx2_eth_sec_init(eth_dev);
1996         if (rc)
1997                 goto cq_fini;
1998
1999         rc = otx2_nix_flow_ctrl_init(eth_dev);
2000         if (rc) {
2001                 otx2_err("Failed to init flow ctrl mode %d", rc);
2002                 goto cq_fini;
2003         }
2004
2005         rc = otx2_nix_mc_addr_list_install(eth_dev);
2006         if (rc < 0) {
2007                 otx2_err("Failed to install mc address list rc=%d", rc);
2008                 goto sec_fini;
2009         }
2010
2011         /*
2012          * Restore queue config when reconfigure followed by
2013          * reconfigure and no queue configure invoked from application case.
2014          */
2015         if (dev->configured == 1) {
2016                 rc = nix_restore_queue_cfg(eth_dev);
2017                 if (rc)
2018                         goto uninstall_mc_list;
2019         }
2020
2021         /* Update the mac address */
2022         ea = eth_dev->data->mac_addrs;
2023         memcpy(ea, dev->mac_addr, RTE_ETHER_ADDR_LEN);
2024         if (rte_is_zero_ether_addr(ea))
2025                 rte_eth_random_addr((uint8_t *)ea);
2026
2027         rte_ether_format_addr(ea_fmt, RTE_ETHER_ADDR_FMT_SIZE, ea);
2028
2029         /* Apply new link configurations if changed */
2030         rc = otx2_apply_link_speed(eth_dev);
2031         if (rc) {
2032                 otx2_err("Failed to set link configuration");
2033                 goto uninstall_mc_list;
2034         }
2035
2036         otx2_nix_dbg("Configured port%d mac=%s nb_rxq=%d nb_txq=%d"
2037                 " rx_offloads=0x%" PRIx64 " tx_offloads=0x%" PRIx64 ""
2038                 " rx_flags=0x%x tx_flags=0x%x",
2039                 eth_dev->data->port_id, ea_fmt, nb_rxq,
2040                 nb_txq, dev->rx_offloads, dev->tx_offloads,
2041                 dev->rx_offload_flags, dev->tx_offload_flags);
2042
2043         /* All good */
2044         dev->configured = 1;
2045         dev->configured_nb_rx_qs = data->nb_rx_queues;
2046         dev->configured_nb_tx_qs = data->nb_tx_queues;
2047         return 0;
2048
2049 uninstall_mc_list:
2050         otx2_nix_mc_addr_list_uninstall(eth_dev);
2051 sec_fini:
2052         otx2_eth_sec_fini(eth_dev);
2053 cq_fini:
2054         oxt2_nix_unregister_cq_irqs(eth_dev);
2055 q_irq_fini:
2056         oxt2_nix_unregister_queue_irqs(eth_dev);
2057 vlan_fini:
2058         otx2_nix_vlan_fini(eth_dev);
2059 tm_fini:
2060         otx2_nix_tm_fini(eth_dev);
2061 free_nix_lf:
2062         nix_lf_free(dev);
2063 fail_offloads:
2064         dev->rx_offload_flags &= ~nix_rx_offload_flags(eth_dev);
2065         dev->tx_offload_flags &= ~nix_tx_offload_flags(eth_dev);
2066 fail_configure:
2067         dev->configured = 0;
2068         return rc;
2069 }
2070
2071 int
2072 otx2_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx)
2073 {
2074         struct rte_eth_dev_data *data = eth_dev->data;
2075         struct otx2_eth_txq *txq;
2076         int rc = -EINVAL;
2077
2078         txq = eth_dev->data->tx_queues[qidx];
2079
2080         if (data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
2081                 return 0;
2082
2083         rc = otx2_nix_sq_sqb_aura_fc(txq, true);
2084         if (rc) {
2085                 otx2_err("Failed to enable sqb aura fc, txq=%u, rc=%d",
2086                          qidx, rc);
2087                 goto done;
2088         }
2089
2090         data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
2091
2092 done:
2093         return rc;
2094 }
2095
2096 int
2097 otx2_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx)
2098 {
2099         struct rte_eth_dev_data *data = eth_dev->data;
2100         struct otx2_eth_txq *txq;
2101         int rc;
2102
2103         txq = eth_dev->data->tx_queues[qidx];
2104
2105         if (data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
2106                 return 0;
2107
2108         txq->fc_cache_pkts = 0;
2109
2110         rc = otx2_nix_sq_sqb_aura_fc(txq, false);
2111         if (rc) {
2112                 otx2_err("Failed to disable sqb aura fc, txq=%u, rc=%d",
2113                          qidx, rc);
2114                 goto done;
2115         }
2116
2117         data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
2118
2119 done:
2120         return rc;
2121 }
2122
2123 static int
2124 otx2_nix_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx)
2125 {
2126         struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[qidx];
2127         struct rte_eth_dev_data *data = eth_dev->data;
2128         int rc;
2129
2130         if (data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
2131                 return 0;
2132
2133         rc = nix_rq_enb_dis(rxq->eth_dev, rxq, true);
2134         if (rc) {
2135                 otx2_err("Failed to enable rxq=%u, rc=%d", qidx, rc);
2136                 goto done;
2137         }
2138
2139         data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
2140
2141 done:
2142         return rc;
2143 }
2144
2145 static int
2146 otx2_nix_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx)
2147 {
2148         struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[qidx];
2149         struct rte_eth_dev_data *data = eth_dev->data;
2150         int rc;
2151
2152         if (data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
2153                 return 0;
2154
2155         rc = nix_rq_enb_dis(rxq->eth_dev, rxq, false);
2156         if (rc) {
2157                 otx2_err("Failed to disable rxq=%u, rc=%d", qidx, rc);
2158                 goto done;
2159         }
2160
2161         data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
2162
2163 done:
2164         return rc;
2165 }
2166
2167 static int
2168 otx2_nix_dev_stop(struct rte_eth_dev *eth_dev)
2169 {
2170         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2171         struct rte_mbuf *rx_pkts[32];
2172         struct otx2_eth_rxq *rxq;
2173         int count, i, j, rc;
2174
2175         nix_lf_switch_header_type_enable(dev, false);
2176         nix_cgx_stop_link_event(dev);
2177         npc_rx_disable(dev);
2178
2179         /* Stop rx queues and free up pkts pending */
2180         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
2181                 rc = otx2_nix_rx_queue_stop(eth_dev, i);
2182                 if (rc)
2183                         continue;
2184
2185                 rxq = eth_dev->data->rx_queues[i];
2186                 count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
2187                 while (count) {
2188                         for (j = 0; j < count; j++)
2189                                 rte_pktmbuf_free(rx_pkts[j]);
2190                         count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
2191                 }
2192         }
2193
2194         /* Stop tx queues  */
2195         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
2196                 otx2_nix_tx_queue_stop(eth_dev, i);
2197
2198         return 0;
2199 }
2200
2201 static int
2202 otx2_nix_dev_start(struct rte_eth_dev *eth_dev)
2203 {
2204         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2205         int rc, i;
2206
2207         /* MTU recalculate should be avoided here if PTP is enabled by PF, as
2208          * otx2_nix_recalc_mtu would be invoked during otx2_nix_ptp_enable_vf
2209          * call below.
2210          */
2211         if (eth_dev->data->nb_rx_queues != 0 && !otx2_ethdev_is_ptp_en(dev)) {
2212                 rc = otx2_nix_recalc_mtu(eth_dev);
2213                 if (rc)
2214                         return rc;
2215         }
2216
2217         /* Start rx queues */
2218         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
2219                 rc = otx2_nix_rx_queue_start(eth_dev, i);
2220                 if (rc)
2221                         return rc;
2222         }
2223
2224         /* Start tx queues  */
2225         for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2226                 rc = otx2_nix_tx_queue_start(eth_dev, i);
2227                 if (rc)
2228                         return rc;
2229         }
2230
2231         rc = otx2_nix_update_flow_ctrl_mode(eth_dev);
2232         if (rc) {
2233                 otx2_err("Failed to update flow ctrl mode %d", rc);
2234                 return rc;
2235         }
2236
2237         /* Enable PTP if it was requested by the app or if it is already
2238          * enabled in PF owning this VF
2239          */
2240         memset(&dev->tstamp, 0, sizeof(struct otx2_timesync_info));
2241         if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) ||
2242             otx2_ethdev_is_ptp_en(dev))
2243                 otx2_nix_timesync_enable(eth_dev);
2244         else
2245                 otx2_nix_timesync_disable(eth_dev);
2246
2247         /* Update VF about data off shifted by 8 bytes if PTP already
2248          * enabled in PF owning this VF
2249          */
2250         if (otx2_ethdev_is_ptp_en(dev) && otx2_dev_is_vf(dev))
2251                 otx2_nix_ptp_enable_vf(eth_dev);
2252
2253         if (dev->rx_offload_flags & NIX_RX_OFFLOAD_TSTAMP_F) {
2254                 rc = rte_mbuf_dyn_rx_timestamp_register(
2255                                 &dev->tstamp.tstamp_dynfield_offset,
2256                                 &dev->tstamp.rx_tstamp_dynflag);
2257                 if (rc != 0) {
2258                         otx2_err("Failed to register Rx timestamp field/flag");
2259                         return -rte_errno;
2260                 }
2261         }
2262
2263         rc = npc_rx_enable(dev);
2264         if (rc) {
2265                 otx2_err("Failed to enable NPC rx %d", rc);
2266                 return rc;
2267         }
2268
2269         otx2_nix_toggle_flag_link_cfg(dev, true);
2270
2271         rc = nix_cgx_start_link_event(dev);
2272         if (rc) {
2273                 otx2_err("Failed to start cgx link event %d", rc);
2274                 goto rx_disable;
2275         }
2276
2277         otx2_nix_toggle_flag_link_cfg(dev, false);
2278         otx2_eth_set_tx_function(eth_dev);
2279         otx2_eth_set_rx_function(eth_dev);
2280
2281         return 0;
2282
2283 rx_disable:
2284         npc_rx_disable(dev);
2285         otx2_nix_toggle_flag_link_cfg(dev, false);
2286         return rc;
2287 }
2288
2289 static int otx2_nix_dev_reset(struct rte_eth_dev *eth_dev);
2290 static int otx2_nix_dev_close(struct rte_eth_dev *eth_dev);
2291
2292 /* Initialize and register driver with DPDK Application */
2293 static const struct eth_dev_ops otx2_eth_dev_ops = {
2294         .dev_infos_get            = otx2_nix_info_get,
2295         .dev_configure            = otx2_nix_configure,
2296         .link_update              = otx2_nix_link_update,
2297         .tx_queue_setup           = otx2_nix_tx_queue_setup,
2298         .tx_queue_release         = otx2_nix_tx_queue_release,
2299         .tm_ops_get               = otx2_nix_tm_ops_get,
2300         .rx_queue_setup           = otx2_nix_rx_queue_setup,
2301         .rx_queue_release         = otx2_nix_rx_queue_release,
2302         .dev_start                = otx2_nix_dev_start,
2303         .dev_stop                 = otx2_nix_dev_stop,
2304         .dev_close                = otx2_nix_dev_close,
2305         .tx_queue_start           = otx2_nix_tx_queue_start,
2306         .tx_queue_stop            = otx2_nix_tx_queue_stop,
2307         .rx_queue_start           = otx2_nix_rx_queue_start,
2308         .rx_queue_stop            = otx2_nix_rx_queue_stop,
2309         .dev_set_link_up          = otx2_nix_dev_set_link_up,
2310         .dev_set_link_down        = otx2_nix_dev_set_link_down,
2311         .dev_supported_ptypes_get = otx2_nix_supported_ptypes_get,
2312         .dev_ptypes_set           = otx2_nix_ptypes_set,
2313         .dev_reset                = otx2_nix_dev_reset,
2314         .stats_get                = otx2_nix_dev_stats_get,
2315         .stats_reset              = otx2_nix_dev_stats_reset,
2316         .get_reg                  = otx2_nix_dev_get_reg,
2317         .mtu_set                  = otx2_nix_mtu_set,
2318         .mac_addr_add             = otx2_nix_mac_addr_add,
2319         .mac_addr_remove          = otx2_nix_mac_addr_del,
2320         .mac_addr_set             = otx2_nix_mac_addr_set,
2321         .set_mc_addr_list         = otx2_nix_set_mc_addr_list,
2322         .promiscuous_enable       = otx2_nix_promisc_enable,
2323         .promiscuous_disable      = otx2_nix_promisc_disable,
2324         .allmulticast_enable      = otx2_nix_allmulticast_enable,
2325         .allmulticast_disable     = otx2_nix_allmulticast_disable,
2326         .queue_stats_mapping_set  = otx2_nix_queue_stats_mapping,
2327         .reta_update              = otx2_nix_dev_reta_update,
2328         .reta_query               = otx2_nix_dev_reta_query,
2329         .rss_hash_update          = otx2_nix_rss_hash_update,
2330         .rss_hash_conf_get        = otx2_nix_rss_hash_conf_get,
2331         .xstats_get               = otx2_nix_xstats_get,
2332         .xstats_get_names         = otx2_nix_xstats_get_names,
2333         .xstats_reset             = otx2_nix_xstats_reset,
2334         .xstats_get_by_id         = otx2_nix_xstats_get_by_id,
2335         .xstats_get_names_by_id   = otx2_nix_xstats_get_names_by_id,
2336         .rxq_info_get             = otx2_nix_rxq_info_get,
2337         .txq_info_get             = otx2_nix_txq_info_get,
2338         .rx_burst_mode_get        = otx2_rx_burst_mode_get,
2339         .tx_burst_mode_get        = otx2_tx_burst_mode_get,
2340         .tx_done_cleanup          = otx2_nix_tx_done_cleanup,
2341         .set_queue_rate_limit     = otx2_nix_tm_set_queue_rate_limit,
2342         .pool_ops_supported       = otx2_nix_pool_ops_supported,
2343         .flow_ops_get             = otx2_nix_dev_flow_ops_get,
2344         .get_module_info          = otx2_nix_get_module_info,
2345         .get_module_eeprom        = otx2_nix_get_module_eeprom,
2346         .fw_version_get           = otx2_nix_fw_version_get,
2347         .flow_ctrl_get            = otx2_nix_flow_ctrl_get,
2348         .flow_ctrl_set            = otx2_nix_flow_ctrl_set,
2349         .timesync_enable          = otx2_nix_timesync_enable,
2350         .timesync_disable         = otx2_nix_timesync_disable,
2351         .timesync_read_rx_timestamp = otx2_nix_timesync_read_rx_timestamp,
2352         .timesync_read_tx_timestamp = otx2_nix_timesync_read_tx_timestamp,
2353         .timesync_adjust_time     = otx2_nix_timesync_adjust_time,
2354         .timesync_read_time       = otx2_nix_timesync_read_time,
2355         .timesync_write_time      = otx2_nix_timesync_write_time,
2356         .vlan_offload_set         = otx2_nix_vlan_offload_set,
2357         .vlan_filter_set          = otx2_nix_vlan_filter_set,
2358         .vlan_strip_queue_set     = otx2_nix_vlan_strip_queue_set,
2359         .vlan_tpid_set            = otx2_nix_vlan_tpid_set,
2360         .vlan_pvid_set            = otx2_nix_vlan_pvid_set,
2361         .rx_queue_intr_enable     = otx2_nix_rx_queue_intr_enable,
2362         .rx_queue_intr_disable    = otx2_nix_rx_queue_intr_disable,
2363         .read_clock               = otx2_nix_read_clock,
2364 };
2365
2366 static inline int
2367 nix_lf_attach(struct otx2_eth_dev *dev)
2368 {
2369         struct otx2_mbox *mbox = dev->mbox;
2370         struct rsrc_attach_req *req;
2371
2372         /* Attach NIX(lf) */
2373         req = otx2_mbox_alloc_msg_attach_resources(mbox);
2374         req->modify = true;
2375         req->nixlf = true;
2376
2377         return otx2_mbox_process(mbox);
2378 }
2379
2380 static inline int
2381 nix_lf_get_msix_offset(struct otx2_eth_dev *dev)
2382 {
2383         struct otx2_mbox *mbox = dev->mbox;
2384         struct msix_offset_rsp *msix_rsp;
2385         int rc;
2386
2387         /* Get NPA and NIX MSIX vector offsets */
2388         otx2_mbox_alloc_msg_msix_offset(mbox);
2389
2390         rc = otx2_mbox_process_msg(mbox, (void *)&msix_rsp);
2391
2392         dev->nix_msixoff = msix_rsp->nix_msixoff;
2393
2394         return rc;
2395 }
2396
2397 static inline int
2398 otx2_eth_dev_lf_detach(struct otx2_mbox *mbox)
2399 {
2400         struct rsrc_detach_req *req;
2401
2402         req = otx2_mbox_alloc_msg_detach_resources(mbox);
2403
2404         /* Detach all except npa lf */
2405         req->partial = true;
2406         req->nixlf = true;
2407         req->sso = true;
2408         req->ssow = true;
2409         req->timlfs = true;
2410         req->cptlfs = true;
2411
2412         return otx2_mbox_process(mbox);
2413 }
2414
2415 static bool
2416 otx2_eth_dev_is_sdp(struct rte_pci_device *pci_dev)
2417 {
2418         if (pci_dev->id.device_id == PCI_DEVID_OCTEONTX2_RVU_SDP_PF ||
2419             pci_dev->id.device_id == PCI_DEVID_OCTEONTX2_RVU_SDP_VF)
2420                 return true;
2421         return false;
2422 }
2423
2424 static inline uint64_t
2425 nix_get_blkaddr(struct otx2_eth_dev *dev)
2426 {
2427         uint64_t reg;
2428
2429         /* Reading the discovery register to know which NIX is the LF
2430          * attached to.
2431          */
2432         reg = otx2_read64(dev->bar2 +
2433                           RVU_PF_BLOCK_ADDRX_DISC(RVU_BLOCK_ADDR_NIX0));
2434
2435         return reg & 0x1FFULL ? RVU_BLOCK_ADDR_NIX0 : RVU_BLOCK_ADDR_NIX1;
2436 }
2437
2438 static int
2439 otx2_eth_dev_init(struct rte_eth_dev *eth_dev)
2440 {
2441         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2442         struct rte_pci_device *pci_dev;
2443         int rc, max_entries;
2444
2445         eth_dev->dev_ops = &otx2_eth_dev_ops;
2446         eth_dev->rx_descriptor_done = otx2_nix_rx_descriptor_done;
2447         eth_dev->rx_queue_count = otx2_nix_rx_queue_count;
2448         eth_dev->rx_descriptor_status = otx2_nix_rx_descriptor_status;
2449         eth_dev->tx_descriptor_status = otx2_nix_tx_descriptor_status;
2450
2451         /* For secondary processes, the primary has done all the work */
2452         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2453                 /* Setup callbacks for secondary process */
2454                 otx2_eth_set_tx_function(eth_dev);
2455                 otx2_eth_set_rx_function(eth_dev);
2456                 return 0;
2457         }
2458
2459         pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2460
2461         rte_eth_copy_pci_info(eth_dev, pci_dev);
2462         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2463
2464         /* Zero out everything after OTX2_DEV to allow proper dev_reset() */
2465         memset(&dev->otx2_eth_dev_data_start, 0, sizeof(*dev) -
2466                 offsetof(struct otx2_eth_dev, otx2_eth_dev_data_start));
2467
2468         /* Parse devargs string */
2469         rc = otx2_ethdev_parse_devargs(eth_dev->device->devargs, dev);
2470         if (rc) {
2471                 otx2_err("Failed to parse devargs rc=%d", rc);
2472                 goto error;
2473         }
2474
2475         if (!dev->mbox_active) {
2476                 /* Initialize the base otx2_dev object
2477                  * only if already present
2478                  */
2479                 rc = otx2_dev_init(pci_dev, dev);
2480                 if (rc) {
2481                         otx2_err("Failed to initialize otx2_dev rc=%d", rc);
2482                         goto error;
2483                 }
2484         }
2485         if (otx2_eth_dev_is_sdp(pci_dev))
2486                 dev->sdp_link = true;
2487         else
2488                 dev->sdp_link = false;
2489         /* Device generic callbacks */
2490         dev->ops = &otx2_dev_ops;
2491         dev->eth_dev = eth_dev;
2492
2493         /* Grab the NPA LF if required */
2494         rc = otx2_npa_lf_init(pci_dev, dev);
2495         if (rc)
2496                 goto otx2_dev_uninit;
2497
2498         dev->configured = 0;
2499         dev->drv_inited = true;
2500         dev->ptype_disable = 0;
2501         dev->lmt_addr = dev->bar2 + (RVU_BLOCK_ADDR_LMT << 20);
2502
2503         /* Attach NIX LF */
2504         rc = nix_lf_attach(dev);
2505         if (rc)
2506                 goto otx2_npa_uninit;
2507
2508         dev->base = dev->bar2 + (nix_get_blkaddr(dev) << 20);
2509
2510         /* Get NIX MSIX offset */
2511         rc = nix_lf_get_msix_offset(dev);
2512         if (rc)
2513                 goto otx2_npa_uninit;
2514
2515         /* Register LF irq handlers */
2516         rc = otx2_nix_register_irqs(eth_dev);
2517         if (rc)
2518                 goto mbox_detach;
2519
2520         /* Get maximum number of supported MAC entries */
2521         max_entries = otx2_cgx_mac_max_entries_get(dev);
2522         if (max_entries < 0) {
2523                 otx2_err("Failed to get max entries for mac addr");
2524                 rc = -ENOTSUP;
2525                 goto unregister_irq;
2526         }
2527
2528         /* For VFs, returned max_entries will be 0. But to keep default MAC
2529          * address, one entry must be allocated. So setting up to 1.
2530          */
2531         if (max_entries == 0)
2532                 max_entries = 1;
2533
2534         eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", max_entries *
2535                                                RTE_ETHER_ADDR_LEN, 0);
2536         if (eth_dev->data->mac_addrs == NULL) {
2537                 otx2_err("Failed to allocate memory for mac addr");
2538                 rc = -ENOMEM;
2539                 goto unregister_irq;
2540         }
2541
2542         dev->max_mac_entries = max_entries;
2543
2544         rc = otx2_nix_mac_addr_get(eth_dev, dev->mac_addr);
2545         if (rc)
2546                 goto free_mac_addrs;
2547
2548         /* Update the mac address */
2549         memcpy(eth_dev->data->mac_addrs, dev->mac_addr, RTE_ETHER_ADDR_LEN);
2550
2551         /* Also sync same MAC address to CGX table */
2552         otx2_cgx_mac_addr_set(eth_dev, &eth_dev->data->mac_addrs[0]);
2553
2554         /* Initialize the tm data structures */
2555         otx2_nix_tm_conf_init(eth_dev);
2556
2557         dev->tx_offload_capa = nix_get_tx_offload_capa(dev);
2558         dev->rx_offload_capa = nix_get_rx_offload_capa(dev);
2559
2560         if (otx2_dev_is_96xx_A0(dev) ||
2561             otx2_dev_is_95xx_Ax(dev)) {
2562                 dev->hwcap |= OTX2_FIXUP_F_MIN_4K_Q;
2563                 dev->hwcap |= OTX2_FIXUP_F_LIMIT_CQ_FULL;
2564         }
2565
2566         /* Create security ctx */
2567         rc = otx2_eth_sec_ctx_create(eth_dev);
2568         if (rc)
2569                 goto free_mac_addrs;
2570         dev->tx_offload_capa |= DEV_TX_OFFLOAD_SECURITY;
2571         dev->rx_offload_capa |= DEV_RX_OFFLOAD_SECURITY;
2572
2573         /* Initialize rte-flow */
2574         rc = otx2_flow_init(dev);
2575         if (rc)
2576                 goto sec_ctx_destroy;
2577
2578         otx2_nix_mc_filter_init(dev);
2579
2580         otx2_nix_dbg("Port=%d pf=%d vf=%d ver=%s msix_off=%d hwcap=0x%" PRIx64
2581                      " rxoffload_capa=0x%" PRIx64 " txoffload_capa=0x%" PRIx64,
2582                      eth_dev->data->port_id, dev->pf, dev->vf,
2583                      OTX2_ETH_DEV_PMD_VERSION, dev->nix_msixoff, dev->hwcap,
2584                      dev->rx_offload_capa, dev->tx_offload_capa);
2585         return 0;
2586
2587 sec_ctx_destroy:
2588         otx2_eth_sec_ctx_destroy(eth_dev);
2589 free_mac_addrs:
2590         rte_free(eth_dev->data->mac_addrs);
2591 unregister_irq:
2592         otx2_nix_unregister_irqs(eth_dev);
2593 mbox_detach:
2594         otx2_eth_dev_lf_detach(dev->mbox);
2595 otx2_npa_uninit:
2596         otx2_npa_lf_fini();
2597 otx2_dev_uninit:
2598         otx2_dev_fini(pci_dev, dev);
2599 error:
2600         otx2_err("Failed to init nix eth_dev rc=%d", rc);
2601         return rc;
2602 }
2603
2604 static int
2605 otx2_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool mbox_close)
2606 {
2607         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2608         struct rte_pci_device *pci_dev;
2609         int rc, i;
2610
2611         /* Nothing to be done for secondary processes */
2612         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2613                 return 0;
2614
2615         /* Clear the flag since we are closing down */
2616         dev->configured = 0;
2617
2618         /* Disable nix bpid config */
2619         otx2_nix_rxchan_bpid_cfg(eth_dev, false);
2620
2621         npc_rx_disable(dev);
2622
2623         /* Disable vlan offloads */
2624         otx2_nix_vlan_fini(eth_dev);
2625
2626         /* Disable other rte_flow entries */
2627         otx2_flow_fini(dev);
2628
2629         /* Free multicast filter list */
2630         otx2_nix_mc_filter_fini(dev);
2631
2632         /* Disable PTP if already enabled */
2633         if (otx2_ethdev_is_ptp_en(dev))
2634                 otx2_nix_timesync_disable(eth_dev);
2635
2636         nix_cgx_stop_link_event(dev);
2637
2638         /* Free up SQs */
2639         for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2640                 otx2_nix_tx_queue_release(eth_dev->data->tx_queues[i]);
2641                 eth_dev->data->tx_queues[i] = NULL;
2642         }
2643         eth_dev->data->nb_tx_queues = 0;
2644
2645         /* Free up RQ's and CQ's */
2646         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
2647                 otx2_nix_rx_queue_release(eth_dev->data->rx_queues[i]);
2648                 eth_dev->data->rx_queues[i] = NULL;
2649         }
2650         eth_dev->data->nb_rx_queues = 0;
2651
2652         /* Free tm resources */
2653         rc = otx2_nix_tm_fini(eth_dev);
2654         if (rc)
2655                 otx2_err("Failed to cleanup tm, rc=%d", rc);
2656
2657         /* Unregister queue irqs */
2658         oxt2_nix_unregister_queue_irqs(eth_dev);
2659
2660         /* Unregister cq irqs */
2661         if (eth_dev->data->dev_conf.intr_conf.rxq)
2662                 oxt2_nix_unregister_cq_irqs(eth_dev);
2663
2664         rc = nix_lf_free(dev);
2665         if (rc)
2666                 otx2_err("Failed to free nix lf, rc=%d", rc);
2667
2668         rc = otx2_npa_lf_fini();
2669         if (rc)
2670                 otx2_err("Failed to cleanup npa lf, rc=%d", rc);
2671
2672         /* Disable security */
2673         otx2_eth_sec_fini(eth_dev);
2674
2675         /* Destroy security ctx */
2676         otx2_eth_sec_ctx_destroy(eth_dev);
2677
2678         rte_free(eth_dev->data->mac_addrs);
2679         eth_dev->data->mac_addrs = NULL;
2680         dev->drv_inited = false;
2681
2682         pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2683         otx2_nix_unregister_irqs(eth_dev);
2684
2685         rc = otx2_eth_dev_lf_detach(dev->mbox);
2686         if (rc)
2687                 otx2_err("Failed to detach resources, rc=%d", rc);
2688
2689         /* Check if mbox close is needed */
2690         if (!mbox_close)
2691                 return 0;
2692
2693         if (otx2_npa_lf_active(dev) || otx2_dev_active_vfs(dev)) {
2694                 /* Will be freed later by PMD */
2695                 eth_dev->data->dev_private = NULL;
2696                 return 0;
2697         }
2698
2699         otx2_dev_fini(pci_dev, dev);
2700         return 0;
2701 }
2702
2703 static int
2704 otx2_nix_dev_close(struct rte_eth_dev *eth_dev)
2705 {
2706         otx2_eth_dev_uninit(eth_dev, true);
2707         return 0;
2708 }
2709
2710 static int
2711 otx2_nix_dev_reset(struct rte_eth_dev *eth_dev)
2712 {
2713         int rc;
2714
2715         rc = otx2_eth_dev_uninit(eth_dev, false);
2716         if (rc)
2717                 return rc;
2718
2719         return otx2_eth_dev_init(eth_dev);
2720 }
2721
2722 static int
2723 nix_remove(struct rte_pci_device *pci_dev)
2724 {
2725         struct rte_eth_dev *eth_dev;
2726         struct otx2_idev_cfg *idev;
2727         struct otx2_dev *otx2_dev;
2728         int rc;
2729
2730         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
2731         if (eth_dev) {
2732                 /* Cleanup eth dev */
2733                 rc = otx2_eth_dev_uninit(eth_dev, true);
2734                 if (rc)
2735                         return rc;
2736
2737                 rte_eth_dev_release_port(eth_dev);
2738         }
2739
2740         /* Nothing to be done for secondary processes */
2741         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2742                 return 0;
2743
2744         /* Check for common resources */
2745         idev = otx2_intra_dev_get_cfg();
2746         if (!idev || !idev->npa_lf || idev->npa_lf->pci_dev != pci_dev)
2747                 return 0;
2748
2749         otx2_dev = container_of(idev->npa_lf, struct otx2_dev, npalf);
2750
2751         if (otx2_npa_lf_active(otx2_dev) || otx2_dev_active_vfs(otx2_dev))
2752                 goto exit;
2753
2754         /* Safe to cleanup mbox as no more users */
2755         otx2_dev_fini(pci_dev, otx2_dev);
2756         rte_free(otx2_dev);
2757         return 0;
2758
2759 exit:
2760         otx2_info("%s: common resource in use by other devices", pci_dev->name);
2761         return -EAGAIN;
2762 }
2763
2764 static int
2765 nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
2766 {
2767         int rc;
2768
2769         RTE_SET_USED(pci_drv);
2770
2771         rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct otx2_eth_dev),
2772                                            otx2_eth_dev_init);
2773
2774         /* On error on secondary, recheck if port exists in primary or
2775          * in mid of detach state.
2776          */
2777         if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
2778                 if (!rte_eth_dev_allocated(pci_dev->device.name))
2779                         return 0;
2780         return rc;
2781 }
2782
2783 static const struct rte_pci_id pci_nix_map[] = {
2784         {
2785                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_PF)
2786         },
2787         {
2788                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_VF)
2789         },
2790         {
2791                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2792                                PCI_DEVID_OCTEONTX2_RVU_AF_VF)
2793         },
2794         {
2795                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2796                                PCI_DEVID_OCTEONTX2_RVU_SDP_PF)
2797         },
2798         {
2799                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2800                                PCI_DEVID_OCTEONTX2_RVU_SDP_VF)
2801         },
2802         {
2803                 .vendor_id = 0,
2804         },
2805 };
2806
2807 static struct rte_pci_driver pci_nix = {
2808         .id_table = pci_nix_map,
2809         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA |
2810                         RTE_PCI_DRV_INTR_LSC,
2811         .probe = nix_probe,
2812         .remove = nix_remove,
2813 };
2814
2815 RTE_PMD_REGISTER_PCI(OCTEONTX2_PMD, pci_nix);
2816 RTE_PMD_REGISTER_PCI_TABLE(OCTEONTX2_PMD, pci_nix_map);
2817 RTE_PMD_REGISTER_KMOD_DEP(OCTEONTX2_PMD, "vfio-pci");