1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
7 #include <rte_ethdev_pci.h>
9 #include <rte_malloc.h>
11 #include <rte_mbuf_pool_ops.h>
12 #include <rte_mempool.h>
14 #include "otx2_ethdev.h"
16 static inline uint64_t
17 nix_get_rx_offload_capa(struct otx2_eth_dev *dev)
19 uint64_t capa = NIX_RX_OFFLOAD_CAPA;
21 if (otx2_dev_is_vf(dev) ||
22 dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG)
23 capa &= ~DEV_RX_OFFLOAD_TIMESTAMP;
28 static inline uint64_t
29 nix_get_tx_offload_capa(struct otx2_eth_dev *dev)
31 uint64_t capa = NIX_TX_OFFLOAD_CAPA;
33 /* TSO not supported for earlier chip revisions */
34 if (otx2_dev_is_96xx_A0(dev) || otx2_dev_is_95xx_Ax(dev))
35 capa &= ~(DEV_TX_OFFLOAD_TCP_TSO |
36 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
37 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
38 DEV_TX_OFFLOAD_GRE_TNL_TSO);
42 static const struct otx2_dev_ops otx2_dev_ops = {
43 .link_status_update = otx2_eth_dev_link_status_update,
44 .ptp_info_update = otx2_eth_dev_ptp_info_update
48 nix_lf_alloc(struct otx2_eth_dev *dev, uint32_t nb_rxq, uint32_t nb_txq)
50 struct otx2_mbox *mbox = dev->mbox;
51 struct nix_lf_alloc_req *req;
52 struct nix_lf_alloc_rsp *rsp;
55 req = otx2_mbox_alloc_msg_nix_lf_alloc(mbox);
59 /* XQE_SZ should be in Sync with NIX_CQ_ENTRY_SZ */
60 RTE_BUILD_BUG_ON(NIX_CQ_ENTRY_SZ != 128);
61 req->xqe_sz = NIX_XQESZ_W16;
62 req->rss_sz = dev->rss_info.rss_size;
63 req->rss_grps = NIX_RSS_GRPS;
64 req->npa_func = otx2_npa_pf_func_get();
65 req->sso_func = otx2_sso_pf_func_get();
66 req->rx_cfg = BIT_ULL(35 /* DIS_APAD */);
67 if (dev->rx_offloads & (DEV_RX_OFFLOAD_TCP_CKSUM |
68 DEV_RX_OFFLOAD_UDP_CKSUM)) {
69 req->rx_cfg |= BIT_ULL(37 /* CSUM_OL4 */);
70 req->rx_cfg |= BIT_ULL(36 /* CSUM_IL4 */);
72 req->rx_cfg |= BIT_ULL(32 /* DROP_RE */);
74 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
78 dev->sqb_size = rsp->sqb_size;
79 dev->tx_chan_base = rsp->tx_chan_base;
80 dev->rx_chan_base = rsp->rx_chan_base;
81 dev->rx_chan_cnt = rsp->rx_chan_cnt;
82 dev->tx_chan_cnt = rsp->tx_chan_cnt;
83 dev->lso_tsov4_idx = rsp->lso_tsov4_idx;
84 dev->lso_tsov6_idx = rsp->lso_tsov6_idx;
85 dev->lf_tx_stats = rsp->lf_tx_stats;
86 dev->lf_rx_stats = rsp->lf_rx_stats;
87 dev->cints = rsp->cints;
88 dev->qints = rsp->qints;
89 dev->npc_flow.channel = dev->rx_chan_base;
90 dev->ptp_en = rsp->hw_rx_tstamp_en;
96 nix_lf_switch_header_type_enable(struct otx2_eth_dev *dev, bool enable)
98 struct otx2_mbox *mbox = dev->mbox;
99 struct npc_set_pkind *req;
100 struct msg_resp *rsp;
103 if (dev->npc_flow.switch_header_type == 0)
106 /* Notify AF about higig2 config */
107 req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
108 req->mode = dev->npc_flow.switch_header_type;
110 req->mode = OTX2_PRIV_FLAGS_DEFAULT;
112 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
115 req = otx2_mbox_alloc_msg_npc_set_pkind(mbox);
116 req->mode = dev->npc_flow.switch_header_type;
118 req->mode = OTX2_PRIV_FLAGS_DEFAULT;
120 return otx2_mbox_process_msg(mbox, (void *)&rsp);
124 nix_lf_free(struct otx2_eth_dev *dev)
126 struct otx2_mbox *mbox = dev->mbox;
127 struct nix_lf_free_req *req;
128 struct ndc_sync_op *ndc_req;
131 /* Sync NDC-NIX for LF */
132 ndc_req = otx2_mbox_alloc_msg_ndc_sync_op(mbox);
133 ndc_req->nix_lf_tx_sync = 1;
134 ndc_req->nix_lf_rx_sync = 1;
135 rc = otx2_mbox_process(mbox);
137 otx2_err("Error on NDC-NIX-[TX, RX] LF sync, rc %d", rc);
139 req = otx2_mbox_alloc_msg_nix_lf_free(mbox);
140 /* Let AF driver free all this nix lf's
141 * NPC entries allocated using NPC MBOX.
145 return otx2_mbox_process(mbox);
149 otx2_cgx_rxtx_start(struct otx2_eth_dev *dev)
151 struct otx2_mbox *mbox = dev->mbox;
153 if (otx2_dev_is_vf_or_sdp(dev))
156 otx2_mbox_alloc_msg_cgx_start_rxtx(mbox);
158 return otx2_mbox_process(mbox);
162 otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev)
164 struct otx2_mbox *mbox = dev->mbox;
166 if (otx2_dev_is_vf_or_sdp(dev))
169 otx2_mbox_alloc_msg_cgx_stop_rxtx(mbox);
171 return otx2_mbox_process(mbox);
175 npc_rx_enable(struct otx2_eth_dev *dev)
177 struct otx2_mbox *mbox = dev->mbox;
179 otx2_mbox_alloc_msg_nix_lf_start_rx(mbox);
181 return otx2_mbox_process(mbox);
185 npc_rx_disable(struct otx2_eth_dev *dev)
187 struct otx2_mbox *mbox = dev->mbox;
189 otx2_mbox_alloc_msg_nix_lf_stop_rx(mbox);
191 return otx2_mbox_process(mbox);
195 nix_cgx_start_link_event(struct otx2_eth_dev *dev)
197 struct otx2_mbox *mbox = dev->mbox;
199 if (otx2_dev_is_vf_or_sdp(dev))
202 otx2_mbox_alloc_msg_cgx_start_linkevents(mbox);
204 return otx2_mbox_process(mbox);
208 cgx_intlbk_enable(struct otx2_eth_dev *dev, bool en)
210 struct otx2_mbox *mbox = dev->mbox;
212 if (en && otx2_dev_is_vf_or_sdp(dev))
216 otx2_mbox_alloc_msg_cgx_intlbk_enable(mbox);
218 otx2_mbox_alloc_msg_cgx_intlbk_disable(mbox);
220 return otx2_mbox_process(mbox);
224 nix_cgx_stop_link_event(struct otx2_eth_dev *dev)
226 struct otx2_mbox *mbox = dev->mbox;
228 if (otx2_dev_is_vf_or_sdp(dev))
231 otx2_mbox_alloc_msg_cgx_stop_linkevents(mbox);
233 return otx2_mbox_process(mbox);
237 nix_rx_queue_reset(struct otx2_eth_rxq *rxq)
243 static inline uint32_t
244 nix_qsize_to_val(enum nix_q_size_e qsize)
246 return (16UL << (qsize * 2));
249 static inline enum nix_q_size_e
250 nix_qsize_clampup_get(struct otx2_eth_dev *dev, uint32_t val)
254 if (otx2_ethdev_fixup_is_min_4k_q(dev))
259 for (; i < nix_q_size_max; i++)
260 if (val <= nix_qsize_to_val(i))
263 if (i >= nix_q_size_max)
264 i = nix_q_size_max - 1;
270 nix_cq_rq_init(struct rte_eth_dev *eth_dev, struct otx2_eth_dev *dev,
271 uint16_t qid, struct otx2_eth_rxq *rxq, struct rte_mempool *mp)
273 struct otx2_mbox *mbox = dev->mbox;
274 const struct rte_memzone *rz;
275 uint32_t ring_size, cq_size;
276 struct nix_aq_enq_req *aq;
281 ring_size = cq_size * NIX_CQ_ENTRY_SZ;
282 rz = rte_eth_dma_zone_reserve(eth_dev, "cq", qid, ring_size,
283 NIX_CQ_ALIGN, dev->node);
285 otx2_err("Failed to allocate mem for cq hw ring");
289 memset(rz->addr, 0, rz->len);
290 rxq->desc = (uintptr_t)rz->addr;
291 rxq->qmask = cq_size - 1;
293 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
295 aq->ctype = NIX_AQ_CTYPE_CQ;
296 aq->op = NIX_AQ_INSTOP_INIT;
300 aq->cq.qsize = rxq->qsize;
301 aq->cq.base = rz->iova;
302 aq->cq.avg_level = 0xff;
303 aq->cq.cq_err_int_ena = BIT(NIX_CQERRINT_CQE_FAULT);
304 aq->cq.cq_err_int_ena |= BIT(NIX_CQERRINT_DOOR_ERR);
306 /* Many to one reduction */
307 aq->cq.qint_idx = qid % dev->qints;
308 /* Map CQ0 [RQ0] to CINT0 and so on till max 64 irqs */
309 aq->cq.cint_idx = qid;
311 if (otx2_ethdev_fixup_is_limit_cq_full(dev)) {
312 const float rx_cq_skid = NIX_CQ_FULL_ERRATA_SKID;
313 uint16_t min_rx_drop;
315 min_rx_drop = ceil(rx_cq_skid / (float)cq_size);
316 aq->cq.drop = min_rx_drop;
318 rxq->cq_drop = min_rx_drop;
320 rxq->cq_drop = NIX_CQ_THRESH_LEVEL;
321 aq->cq.drop = rxq->cq_drop;
325 /* TX pause frames enable flowctrl on RX side */
326 if (dev->fc_info.tx_pause) {
327 /* Single bpid is allocated for all rx channels for now */
328 aq->cq.bpid = dev->fc_info.bpid[0];
329 aq->cq.bp = rxq->cq_drop;
333 rc = otx2_mbox_process(mbox);
335 otx2_err("Failed to init cq context");
339 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
341 aq->ctype = NIX_AQ_CTYPE_RQ;
342 aq->op = NIX_AQ_INSTOP_INIT;
345 aq->rq.cq = qid; /* RQ to CQ 1:1 mapped */
347 aq->rq.lpb_aura = npa_lf_aura_handle_to_aura(mp->pool_id);
348 first_skip = (sizeof(struct rte_mbuf));
349 first_skip += RTE_PKTMBUF_HEADROOM;
350 first_skip += rte_pktmbuf_priv_size(mp);
351 rxq->data_off = first_skip;
353 first_skip /= 8; /* Expressed in number of dwords */
354 aq->rq.first_skip = first_skip;
355 aq->rq.later_skip = (sizeof(struct rte_mbuf) / 8);
356 aq->rq.flow_tagw = 32; /* 32-bits */
357 aq->rq.lpb_sizem1 = rte_pktmbuf_data_room_size(mp);
358 aq->rq.lpb_sizem1 += rte_pktmbuf_priv_size(mp);
359 aq->rq.lpb_sizem1 += sizeof(struct rte_mbuf);
360 aq->rq.lpb_sizem1 /= 8;
361 aq->rq.lpb_sizem1 -= 1; /* Expressed in size minus one */
363 aq->rq.pb_caching = 0x2; /* First cache aligned block to LLC */
364 aq->rq.xqe_imm_size = 0; /* No pkt data copy to CQE */
365 aq->rq.rq_int_ena = 0;
366 /* Many to one reduction */
367 aq->rq.qint_idx = qid % dev->qints;
369 aq->rq.xqe_drop_ena = 1;
371 rc = otx2_mbox_process(mbox);
373 otx2_err("Failed to init rq context");
383 nix_rq_enb_dis(struct rte_eth_dev *eth_dev,
384 struct otx2_eth_rxq *rxq, const bool enb)
386 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
387 struct otx2_mbox *mbox = dev->mbox;
388 struct nix_aq_enq_req *aq;
390 /* Pkts will be dropped silently if RQ is disabled */
391 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
393 aq->ctype = NIX_AQ_CTYPE_RQ;
394 aq->op = NIX_AQ_INSTOP_WRITE;
397 aq->rq_mask.ena = ~(aq->rq_mask.ena);
399 return otx2_mbox_process(mbox);
403 nix_cq_rq_uninit(struct rte_eth_dev *eth_dev, struct otx2_eth_rxq *rxq)
405 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
406 struct otx2_mbox *mbox = dev->mbox;
407 struct nix_aq_enq_req *aq;
410 /* RQ is already disabled */
412 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
414 aq->ctype = NIX_AQ_CTYPE_CQ;
415 aq->op = NIX_AQ_INSTOP_WRITE;
418 aq->cq_mask.ena = ~(aq->cq_mask.ena);
420 rc = otx2_mbox_process(mbox);
422 otx2_err("Failed to disable cq context");
430 nix_get_data_off(struct otx2_eth_dev *dev)
432 return otx2_ethdev_is_ptp_en(dev) ? NIX_TIMESYNC_RX_OFFSET : 0;
436 otx2_nix_rxq_mbuf_setup(struct otx2_eth_dev *dev, uint16_t port_id)
438 struct rte_mbuf mb_def;
441 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
442 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
443 offsetof(struct rte_mbuf, data_off) != 2);
444 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
445 offsetof(struct rte_mbuf, data_off) != 4);
446 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
447 offsetof(struct rte_mbuf, data_off) != 6);
449 mb_def.data_off = RTE_PKTMBUF_HEADROOM + nix_get_data_off(dev);
450 mb_def.port = port_id;
451 rte_mbuf_refcnt_set(&mb_def, 1);
453 /* Prevent compiler reordering: rearm_data covers previous fields */
454 rte_compiler_barrier();
455 tmp = (uint64_t *)&mb_def.rearm_data;
461 otx2_nix_rx_queue_release(void *rx_queue)
463 struct otx2_eth_rxq *rxq = rx_queue;
468 otx2_nix_dbg("Releasing rxq %u", rxq->rq);
469 nix_cq_rq_uninit(rxq->eth_dev, rxq);
474 otx2_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t rq,
475 uint16_t nb_desc, unsigned int socket,
476 const struct rte_eth_rxconf *rx_conf,
477 struct rte_mempool *mp)
479 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
480 struct rte_mempool_ops *ops;
481 struct otx2_eth_rxq *rxq;
482 const char *platform_ops;
483 enum nix_q_size_e qsize;
489 /* Compile time check to make sure all fast path elements in a CL */
490 RTE_BUILD_BUG_ON(offsetof(struct otx2_eth_rxq, slow_path_start) >= 128);
493 if (rx_conf->rx_deferred_start == 1) {
494 otx2_err("Deferred Rx start is not supported");
498 platform_ops = rte_mbuf_platform_mempool_ops();
499 /* This driver needs octeontx2_npa mempool ops to work */
500 ops = rte_mempool_get_ops(mp->ops_index);
501 if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
502 otx2_err("mempool ops should be of octeontx2_npa type");
506 if (mp->pool_id == 0) {
507 otx2_err("Invalid pool_id");
511 /* Free memory prior to re-allocation if needed */
512 if (eth_dev->data->rx_queues[rq] != NULL) {
513 otx2_nix_dbg("Freeing memory prior to re-allocation %d", rq);
514 otx2_nix_rx_queue_release(eth_dev->data->rx_queues[rq]);
515 eth_dev->data->rx_queues[rq] = NULL;
518 offloads = rx_conf->offloads | eth_dev->data->dev_conf.rxmode.offloads;
519 dev->rx_offloads |= offloads;
521 /* Find the CQ queue size */
522 qsize = nix_qsize_clampup_get(dev, nb_desc);
523 /* Allocate rxq memory */
524 rxq = rte_zmalloc_socket("otx2 rxq", sizeof(*rxq), OTX2_ALIGN, socket);
526 otx2_err("Failed to allocate rq=%d", rq);
531 rxq->eth_dev = eth_dev;
533 rxq->cq_door = dev->base + NIX_LF_CQ_OP_DOOR;
534 rxq->cq_status = (int64_t *)(dev->base + NIX_LF_CQ_OP_STATUS);
535 rxq->wdata = (uint64_t)rq << 32;
536 rxq->aura = npa_lf_aura_handle_to_aura(mp->pool_id);
537 rxq->mbuf_initializer = otx2_nix_rxq_mbuf_setup(dev,
538 eth_dev->data->port_id);
539 rxq->offloads = offloads;
541 rxq->qlen = nix_qsize_to_val(qsize);
543 rxq->lookup_mem = otx2_nix_fastpath_lookup_mem_get();
544 rxq->tstamp = &dev->tstamp;
546 /* Alloc completion queue */
547 rc = nix_cq_rq_init(eth_dev, dev, rq, rxq, mp);
549 otx2_err("Failed to allocate rxq=%u", rq);
553 rxq->qconf.socket_id = socket;
554 rxq->qconf.nb_desc = nb_desc;
555 rxq->qconf.mempool = mp;
556 memcpy(&rxq->qconf.conf.rx, rx_conf, sizeof(struct rte_eth_rxconf));
558 nix_rx_queue_reset(rxq);
559 otx2_nix_dbg("rq=%d pool=%s qsize=%d nb_desc=%d->%d",
560 rq, mp->name, qsize, nb_desc, rxq->qlen);
562 eth_dev->data->rx_queues[rq] = rxq;
563 eth_dev->data->rx_queue_state[rq] = RTE_ETH_QUEUE_STATE_STOPPED;
565 /* Calculating delta and freq mult between PTP HI clock and tsc.
566 * These are needed in deriving raw clock value from tsc counter.
567 * read_clock eth op returns raw clock value.
569 if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) ||
570 otx2_ethdev_is_ptp_en(dev)) {
571 rc = otx2_nix_raw_clock_tsc_conv(dev);
573 otx2_err("Failed to calculate delta and freq mult");
581 otx2_nix_rx_queue_release(rxq);
586 static inline uint8_t
587 nix_sq_max_sqe_sz(struct otx2_eth_txq *txq)
590 * Maximum three segments can be supported with W8, Choose
591 * NIX_MAXSQESZ_W16 for multi segment offload.
593 if (txq->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
594 return NIX_MAXSQESZ_W16;
596 return NIX_MAXSQESZ_W8;
600 nix_rx_offload_flags(struct rte_eth_dev *eth_dev)
602 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
603 struct rte_eth_dev_data *data = eth_dev->data;
604 struct rte_eth_conf *conf = &data->dev_conf;
605 struct rte_eth_rxmode *rxmode = &conf->rxmode;
608 if (rxmode->mq_mode == ETH_MQ_RX_RSS &&
609 (dev->rx_offloads & DEV_RX_OFFLOAD_RSS_HASH))
610 flags |= NIX_RX_OFFLOAD_RSS_F;
612 if (dev->rx_offloads & (DEV_RX_OFFLOAD_TCP_CKSUM |
613 DEV_RX_OFFLOAD_UDP_CKSUM))
614 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
616 if (dev->rx_offloads & (DEV_RX_OFFLOAD_IPV4_CKSUM |
617 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM))
618 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
620 if (dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER)
621 flags |= NIX_RX_MULTI_SEG_F;
623 if (dev->rx_offloads & (DEV_RX_OFFLOAD_VLAN_STRIP |
624 DEV_RX_OFFLOAD_QINQ_STRIP))
625 flags |= NIX_RX_OFFLOAD_VLAN_STRIP_F;
627 if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP))
628 flags |= NIX_RX_OFFLOAD_TSTAMP_F;
630 if (!dev->ptype_disable)
631 flags |= NIX_RX_OFFLOAD_PTYPE_F;
637 nix_tx_offload_flags(struct rte_eth_dev *eth_dev)
639 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
640 uint64_t conf = dev->tx_offloads;
643 /* Fastpath is dependent on these enums */
644 RTE_BUILD_BUG_ON(PKT_TX_TCP_CKSUM != (1ULL << 52));
645 RTE_BUILD_BUG_ON(PKT_TX_SCTP_CKSUM != (2ULL << 52));
646 RTE_BUILD_BUG_ON(PKT_TX_UDP_CKSUM != (3ULL << 52));
647 RTE_BUILD_BUG_ON(PKT_TX_IP_CKSUM != (1ULL << 54));
648 RTE_BUILD_BUG_ON(PKT_TX_IPV4 != (1ULL << 55));
649 RTE_BUILD_BUG_ON(PKT_TX_OUTER_IP_CKSUM != (1ULL << 58));
650 RTE_BUILD_BUG_ON(PKT_TX_OUTER_IPV4 != (1ULL << 59));
651 RTE_BUILD_BUG_ON(PKT_TX_OUTER_IPV6 != (1ULL << 60));
652 RTE_BUILD_BUG_ON(PKT_TX_OUTER_UDP_CKSUM != (1ULL << 41));
653 RTE_BUILD_BUG_ON(RTE_MBUF_L2_LEN_BITS != 7);
654 RTE_BUILD_BUG_ON(RTE_MBUF_L3_LEN_BITS != 9);
655 RTE_BUILD_BUG_ON(RTE_MBUF_OUTL2_LEN_BITS != 7);
656 RTE_BUILD_BUG_ON(RTE_MBUF_OUTL3_LEN_BITS != 9);
657 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) !=
658 offsetof(struct rte_mbuf, buf_iova) + 8);
659 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
660 offsetof(struct rte_mbuf, buf_iova) + 16);
661 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
662 offsetof(struct rte_mbuf, ol_flags) + 12);
663 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, tx_offload) !=
664 offsetof(struct rte_mbuf, pool) + 2 * sizeof(void *));
666 if (conf & DEV_TX_OFFLOAD_VLAN_INSERT ||
667 conf & DEV_TX_OFFLOAD_QINQ_INSERT)
668 flags |= NIX_TX_OFFLOAD_VLAN_QINQ_F;
670 if (conf & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
671 conf & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
672 flags |= NIX_TX_OFFLOAD_OL3_OL4_CSUM_F;
674 if (conf & DEV_TX_OFFLOAD_IPV4_CKSUM ||
675 conf & DEV_TX_OFFLOAD_TCP_CKSUM ||
676 conf & DEV_TX_OFFLOAD_UDP_CKSUM ||
677 conf & DEV_TX_OFFLOAD_SCTP_CKSUM)
678 flags |= NIX_TX_OFFLOAD_L3_L4_CSUM_F;
680 if (!(conf & DEV_TX_OFFLOAD_MBUF_FAST_FREE))
681 flags |= NIX_TX_OFFLOAD_MBUF_NOFF_F;
683 if (conf & DEV_TX_OFFLOAD_MULTI_SEGS)
684 flags |= NIX_TX_MULTI_SEG_F;
686 /* Enable Inner checksum for TSO */
687 if (conf & DEV_TX_OFFLOAD_TCP_TSO)
688 flags |= (NIX_TX_OFFLOAD_TSO_F |
689 NIX_TX_OFFLOAD_L3_L4_CSUM_F);
691 /* Enable Inner and Outer checksum for Tunnel TSO */
692 if (conf & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
693 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
694 DEV_TX_OFFLOAD_GRE_TNL_TSO))
695 flags |= (NIX_TX_OFFLOAD_TSO_F |
696 NIX_TX_OFFLOAD_OL3_OL4_CSUM_F |
697 NIX_TX_OFFLOAD_L3_L4_CSUM_F);
699 if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP))
700 flags |= NIX_TX_OFFLOAD_TSTAMP_F;
706 nix_sq_init(struct otx2_eth_txq *txq)
708 struct otx2_eth_dev *dev = txq->dev;
709 struct otx2_mbox *mbox = dev->mbox;
710 struct nix_aq_enq_req *sq;
715 if (txq->sqb_pool->pool_id == 0)
718 rc = otx2_nix_tm_get_leaf_data(dev, txq->sq, &rr_quantum, &smq);
720 otx2_err("Failed to get sq->smq(leaf node), rc=%d", rc);
724 sq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
726 sq->ctype = NIX_AQ_CTYPE_SQ;
727 sq->op = NIX_AQ_INSTOP_INIT;
728 sq->sq.max_sqe_size = nix_sq_max_sqe_sz(txq);
731 sq->sq.smq_rr_quantum = rr_quantum;
732 sq->sq.default_chan = dev->tx_chan_base;
733 sq->sq.sqe_stype = NIX_STYPE_STF;
735 if (sq->sq.max_sqe_size == NIX_MAXSQESZ_W8)
736 sq->sq.sqe_stype = NIX_STYPE_STP;
738 npa_lf_aura_handle_to_aura(txq->sqb_pool->pool_id);
739 sq->sq.sq_int_ena = BIT(NIX_SQINT_LMT_ERR);
740 sq->sq.sq_int_ena |= BIT(NIX_SQINT_SQB_ALLOC_FAIL);
741 sq->sq.sq_int_ena |= BIT(NIX_SQINT_SEND_ERR);
742 sq->sq.sq_int_ena |= BIT(NIX_SQINT_MNQ_ERR);
744 /* Many to one reduction */
745 sq->sq.qint_idx = txq->sq % dev->qints;
747 return otx2_mbox_process(mbox);
751 nix_sq_uninit(struct otx2_eth_txq *txq)
753 struct otx2_eth_dev *dev = txq->dev;
754 struct otx2_mbox *mbox = dev->mbox;
755 struct ndc_sync_op *ndc_req;
756 struct nix_aq_enq_rsp *rsp;
757 struct nix_aq_enq_req *aq;
758 uint16_t sqes_per_sqb;
762 otx2_nix_dbg("Cleaning up sq %u", txq->sq);
764 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
766 aq->ctype = NIX_AQ_CTYPE_SQ;
767 aq->op = NIX_AQ_INSTOP_READ;
769 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
773 /* Check if sq is already cleaned up */
778 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
780 aq->ctype = NIX_AQ_CTYPE_SQ;
781 aq->op = NIX_AQ_INSTOP_WRITE;
783 aq->sq_mask.ena = ~aq->sq_mask.ena;
786 rc = otx2_mbox_process(mbox);
790 /* Read SQ and free sqb's */
791 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
793 aq->ctype = NIX_AQ_CTYPE_SQ;
794 aq->op = NIX_AQ_INSTOP_READ;
796 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
801 otx2_err("SQ has pending sqe's");
803 count = aq->sq.sqb_count;
804 sqes_per_sqb = 1 << txq->sqes_per_sqb_log2;
805 /* Free SQB's that are used */
806 sqb_buf = (void *)rsp->sq.head_sqb;
810 next_sqb = *(void **)((uintptr_t)sqb_buf + (uint32_t)
811 ((sqes_per_sqb - 1) *
812 nix_sq_max_sqe_sz(txq)));
813 npa_lf_aura_op_free(txq->sqb_pool->pool_id, 1,
819 /* Free next to use sqb */
820 if (rsp->sq.next_sqb)
821 npa_lf_aura_op_free(txq->sqb_pool->pool_id, 1,
824 /* Sync NDC-NIX-TX for LF */
825 ndc_req = otx2_mbox_alloc_msg_ndc_sync_op(mbox);
826 ndc_req->nix_lf_tx_sync = 1;
827 rc = otx2_mbox_process(mbox);
829 otx2_err("Error on NDC-NIX-TX LF sync, rc %d", rc);
835 nix_sqb_aura_limit_cfg(struct rte_mempool *mp, uint16_t nb_sqb_bufs)
837 struct otx2_npa_lf *npa_lf = otx2_intra_dev_get_cfg()->npa_lf;
838 struct npa_aq_enq_req *aura_req;
840 aura_req = otx2_mbox_alloc_msg_npa_aq_enq(npa_lf->mbox);
841 aura_req->aura_id = npa_lf_aura_handle_to_aura(mp->pool_id);
842 aura_req->ctype = NPA_AQ_CTYPE_AURA;
843 aura_req->op = NPA_AQ_INSTOP_WRITE;
845 aura_req->aura.limit = nb_sqb_bufs;
846 aura_req->aura_mask.limit = ~(aura_req->aura_mask.limit);
848 return otx2_mbox_process(npa_lf->mbox);
852 nix_alloc_sqb_pool(int port, struct otx2_eth_txq *txq, uint16_t nb_desc)
854 struct otx2_eth_dev *dev = txq->dev;
855 uint16_t sqes_per_sqb, nb_sqb_bufs;
856 char name[RTE_MEMPOOL_NAMESIZE];
857 struct rte_mempool_objsz sz;
858 struct npa_aura_s *aura;
859 uint32_t tmp, blk_sz;
861 aura = (struct npa_aura_s *)((uintptr_t)txq->fc_mem + OTX2_ALIGN);
862 snprintf(name, sizeof(name), "otx2_sqb_pool_%d_%d", port, txq->sq);
863 blk_sz = dev->sqb_size;
865 if (nix_sq_max_sqe_sz(txq) == NIX_MAXSQESZ_W16)
866 sqes_per_sqb = (dev->sqb_size / 8) / 16;
868 sqes_per_sqb = (dev->sqb_size / 8) / 8;
870 nb_sqb_bufs = nb_desc / sqes_per_sqb;
871 /* Clamp up to devarg passed SQB count */
872 nb_sqb_bufs = RTE_MIN(dev->max_sqb_count, RTE_MAX(NIX_DEF_SQB,
873 nb_sqb_bufs + NIX_SQB_LIST_SPACE));
875 txq->sqb_pool = rte_mempool_create_empty(name, NIX_MAX_SQB, blk_sz,
877 MEMPOOL_F_NO_SPREAD);
878 txq->nb_sqb_bufs = nb_sqb_bufs;
879 txq->sqes_per_sqb_log2 = (uint16_t)rte_log2_u32(sqes_per_sqb);
880 txq->nb_sqb_bufs_adj = nb_sqb_bufs -
881 RTE_ALIGN_MUL_CEIL(nb_sqb_bufs, sqes_per_sqb) / sqes_per_sqb;
882 txq->nb_sqb_bufs_adj =
883 (NIX_SQB_LOWER_THRESH * txq->nb_sqb_bufs_adj) / 100;
885 if (txq->sqb_pool == NULL) {
886 otx2_err("Failed to allocate sqe mempool");
890 memset(aura, 0, sizeof(*aura));
892 aura->fc_addr = txq->fc_iova;
893 aura->fc_hyst_bits = 0; /* Store count on all updates */
894 if (rte_mempool_set_ops_byname(txq->sqb_pool, "octeontx2_npa", aura)) {
895 otx2_err("Failed to set ops for sqe mempool");
898 if (rte_mempool_populate_default(txq->sqb_pool) < 0) {
899 otx2_err("Failed to populate sqe mempool");
903 tmp = rte_mempool_calc_obj_size(blk_sz, MEMPOOL_F_NO_SPREAD, &sz);
904 if (dev->sqb_size != sz.elt_size) {
905 otx2_err("sqe pool block size is not expected %d != %d",
910 nix_sqb_aura_limit_cfg(txq->sqb_pool, txq->nb_sqb_bufs);
918 otx2_nix_form_default_desc(struct otx2_eth_txq *txq)
920 struct nix_send_ext_s *send_hdr_ext;
921 struct nix_send_hdr_s *send_hdr;
922 struct nix_send_mem_s *send_mem;
923 union nix_send_sg_s *sg;
925 /* Initialize the fields based on basic single segment packet */
926 memset(&txq->cmd, 0, sizeof(txq->cmd));
928 if (txq->dev->tx_offload_flags & NIX_TX_NEED_EXT_HDR) {
929 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
930 /* 2(HDR) + 2(EXT_HDR) + 1(SG) + 1(IOVA) = 6/2 - 1 = 2 */
931 send_hdr->w0.sizem1 = 2;
933 send_hdr_ext = (struct nix_send_ext_s *)&txq->cmd[2];
934 send_hdr_ext->w0.subdc = NIX_SUBDC_EXT;
935 if (txq->dev->tx_offload_flags & NIX_TX_OFFLOAD_TSTAMP_F) {
936 /* Default: one seg packet would have:
937 * 2(HDR) + 2(EXT) + 1(SG) + 1(IOVA) + 2(MEM)
940 send_hdr->w0.sizem1 = 3;
941 send_hdr_ext->w0.tstmp = 1;
943 /* To calculate the offset for send_mem,
944 * send_hdr->w0.sizem1 * 2
946 send_mem = (struct nix_send_mem_s *)(txq->cmd +
947 (send_hdr->w0.sizem1 << 1));
948 send_mem->subdc = NIX_SUBDC_MEM;
949 send_mem->alg = NIX_SENDMEMALG_SETTSTMP;
950 send_mem->addr = txq->dev->tstamp.tx_tstamp_iova;
952 sg = (union nix_send_sg_s *)&txq->cmd[4];
954 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
955 /* 2(HDR) + 1(SG) + 1(IOVA) = 4/2 - 1 = 1 */
956 send_hdr->w0.sizem1 = 1;
957 sg = (union nix_send_sg_s *)&txq->cmd[2];
960 send_hdr->w0.sq = txq->sq;
961 sg->subdc = NIX_SUBDC_SG;
963 sg->ld_type = NIX_SENDLDTYPE_LDD;
969 otx2_nix_tx_queue_release(void *_txq)
971 struct otx2_eth_txq *txq = _txq;
972 struct rte_eth_dev *eth_dev;
977 eth_dev = txq->dev->eth_dev;
979 otx2_nix_dbg("Releasing txq %u", txq->sq);
981 /* Flush and disable tm */
982 otx2_nix_tm_sw_xoff(txq, eth_dev->data->dev_started);
984 /* Free sqb's and disable sq */
988 rte_mempool_free(txq->sqb_pool);
989 txq->sqb_pool = NULL;
996 otx2_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t sq,
997 uint16_t nb_desc, unsigned int socket_id,
998 const struct rte_eth_txconf *tx_conf)
1000 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1001 const struct rte_memzone *fc;
1002 struct otx2_eth_txq *txq;
1008 /* Compile time check to make sure all fast path elements in a CL */
1009 RTE_BUILD_BUG_ON(offsetof(struct otx2_eth_txq, slow_path_start) >= 128);
1011 if (tx_conf->tx_deferred_start) {
1012 otx2_err("Tx deferred start is not supported");
1016 /* Free memory prior to re-allocation if needed. */
1017 if (eth_dev->data->tx_queues[sq] != NULL) {
1018 otx2_nix_dbg("Freeing memory prior to re-allocation %d", sq);
1019 otx2_nix_tx_queue_release(eth_dev->data->tx_queues[sq]);
1020 eth_dev->data->tx_queues[sq] = NULL;
1023 /* Find the expected offloads for this queue */
1024 offloads = tx_conf->offloads | eth_dev->data->dev_conf.txmode.offloads;
1026 /* Allocating tx queue data structure */
1027 txq = rte_zmalloc_socket("otx2_ethdev TX queue", sizeof(*txq),
1028 OTX2_ALIGN, socket_id);
1030 otx2_err("Failed to alloc txq=%d", sq);
1036 txq->sqb_pool = NULL;
1037 txq->offloads = offloads;
1038 dev->tx_offloads |= offloads;
1041 * Allocate memory for flow control updates from HW.
1042 * Alloc one cache line, so that fits all FC_STYPE modes.
1044 fc = rte_eth_dma_zone_reserve(eth_dev, "fcmem", sq,
1045 OTX2_ALIGN + sizeof(struct npa_aura_s),
1046 OTX2_ALIGN, dev->node);
1048 otx2_err("Failed to allocate mem for fcmem");
1052 txq->fc_iova = fc->iova;
1053 txq->fc_mem = fc->addr;
1055 /* Initialize the aura sqb pool */
1056 rc = nix_alloc_sqb_pool(eth_dev->data->port_id, txq, nb_desc);
1058 otx2_err("Failed to alloc sqe pool rc=%d", rc);
1062 /* Initialize the SQ */
1063 rc = nix_sq_init(txq);
1065 otx2_err("Failed to init sq=%d context", sq);
1069 txq->fc_cache_pkts = 0;
1070 txq->io_addr = dev->base + NIX_LF_OP_SENDX(0);
1071 /* Evenly distribute LMT slot for each sq */
1072 txq->lmt_addr = (void *)(dev->lmt_addr + ((sq & LMT_SLOT_MASK) << 12));
1074 txq->qconf.socket_id = socket_id;
1075 txq->qconf.nb_desc = nb_desc;
1076 memcpy(&txq->qconf.conf.tx, tx_conf, sizeof(struct rte_eth_txconf));
1078 otx2_nix_form_default_desc(txq);
1080 otx2_nix_dbg("sq=%d fc=%p offload=0x%" PRIx64 " sqb=0x%" PRIx64 ""
1081 " lmt_addr=%p nb_sqb_bufs=%d sqes_per_sqb_log2=%d", sq,
1082 fc->addr, offloads, txq->sqb_pool->pool_id, txq->lmt_addr,
1083 txq->nb_sqb_bufs, txq->sqes_per_sqb_log2);
1084 eth_dev->data->tx_queues[sq] = txq;
1085 eth_dev->data->tx_queue_state[sq] = RTE_ETH_QUEUE_STATE_STOPPED;
1089 otx2_nix_tx_queue_release(txq);
1095 nix_store_queue_cfg_and_then_release(struct rte_eth_dev *eth_dev)
1097 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1098 struct otx2_eth_qconf *tx_qconf = NULL;
1099 struct otx2_eth_qconf *rx_qconf = NULL;
1100 struct otx2_eth_txq **txq;
1101 struct otx2_eth_rxq **rxq;
1102 int i, nb_rxq, nb_txq;
1104 nb_rxq = RTE_MIN(dev->configured_nb_rx_qs, eth_dev->data->nb_rx_queues);
1105 nb_txq = RTE_MIN(dev->configured_nb_tx_qs, eth_dev->data->nb_tx_queues);
1107 tx_qconf = malloc(nb_txq * sizeof(*tx_qconf));
1108 if (tx_qconf == NULL) {
1109 otx2_err("Failed to allocate memory for tx_qconf");
1113 rx_qconf = malloc(nb_rxq * sizeof(*rx_qconf));
1114 if (rx_qconf == NULL) {
1115 otx2_err("Failed to allocate memory for rx_qconf");
1119 txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1120 for (i = 0; i < nb_txq; i++) {
1121 if (txq[i] == NULL) {
1122 otx2_err("txq[%d] is already released", i);
1125 memcpy(&tx_qconf[i], &txq[i]->qconf, sizeof(*tx_qconf));
1126 otx2_nix_tx_queue_release(txq[i]);
1127 eth_dev->data->tx_queues[i] = NULL;
1130 rxq = (struct otx2_eth_rxq **)eth_dev->data->rx_queues;
1131 for (i = 0; i < nb_rxq; i++) {
1132 if (rxq[i] == NULL) {
1133 otx2_err("rxq[%d] is already released", i);
1136 memcpy(&rx_qconf[i], &rxq[i]->qconf, sizeof(*rx_qconf));
1137 otx2_nix_rx_queue_release(rxq[i]);
1138 eth_dev->data->rx_queues[i] = NULL;
1141 dev->tx_qconf = tx_qconf;
1142 dev->rx_qconf = rx_qconf;
1155 nix_restore_queue_cfg(struct rte_eth_dev *eth_dev)
1157 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1158 struct otx2_eth_qconf *tx_qconf = dev->tx_qconf;
1159 struct otx2_eth_qconf *rx_qconf = dev->rx_qconf;
1160 struct otx2_eth_txq **txq;
1161 struct otx2_eth_rxq **rxq;
1162 int rc, i, nb_rxq, nb_txq;
1164 nb_rxq = RTE_MIN(dev->configured_nb_rx_qs, eth_dev->data->nb_rx_queues);
1165 nb_txq = RTE_MIN(dev->configured_nb_tx_qs, eth_dev->data->nb_tx_queues);
1168 /* Setup tx & rx queues with previous configuration so
1169 * that the queues can be functional in cases like ports
1170 * are started without re configuring queues.
1172 * Usual re config sequence is like below:
1173 * port_configure() {
1178 * queue_configure() {
1185 * In some application's control path, queue_configure() would
1186 * NOT be invoked for TXQs/RXQs in port_configure().
1187 * In such cases, queues can be functional after start as the
1188 * queues are already setup in port_configure().
1190 for (i = 0; i < nb_txq; i++) {
1191 rc = otx2_nix_tx_queue_setup(eth_dev, i, tx_qconf[i].nb_desc,
1192 tx_qconf[i].socket_id,
1193 &tx_qconf[i].conf.tx);
1195 otx2_err("Failed to setup tx queue rc=%d", rc);
1196 txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1197 for (i -= 1; i >= 0; i--)
1198 otx2_nix_tx_queue_release(txq[i]);
1203 free(tx_qconf); tx_qconf = NULL;
1205 for (i = 0; i < nb_rxq; i++) {
1206 rc = otx2_nix_rx_queue_setup(eth_dev, i, rx_qconf[i].nb_desc,
1207 rx_qconf[i].socket_id,
1208 &rx_qconf[i].conf.rx,
1209 rx_qconf[i].mempool);
1211 otx2_err("Failed to setup rx queue rc=%d", rc);
1212 rxq = (struct otx2_eth_rxq **)eth_dev->data->rx_queues;
1213 for (i -= 1; i >= 0; i--)
1214 otx2_nix_rx_queue_release(rxq[i]);
1215 goto release_tx_queues;
1219 free(rx_qconf); rx_qconf = NULL;
1224 txq = (struct otx2_eth_txq **)eth_dev->data->tx_queues;
1225 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1226 otx2_nix_tx_queue_release(txq[i]);
1237 nix_eth_nop_burst(void *queue, struct rte_mbuf **mbufs, uint16_t pkts)
1239 RTE_SET_USED(queue);
1240 RTE_SET_USED(mbufs);
1247 nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev)
1249 /* These dummy functions are required for supporting
1250 * some applications which reconfigure queues without
1251 * stopping tx burst and rx burst threads(eg kni app)
1252 * When the queues context is saved, txq/rxqs are released
1253 * which caused app crash since rx/tx burst is still
1254 * on different lcores
1256 eth_dev->tx_pkt_burst = nix_eth_nop_burst;
1257 eth_dev->rx_pkt_burst = nix_eth_nop_burst;
1262 nix_lso_tcp(struct nix_lso_format_cfg *req, bool v4)
1264 volatile struct nix_lso_format *field;
1266 /* Format works only with TCP packet marked by OL3/OL4 */
1267 field = (volatile struct nix_lso_format *)&req->fields[0];
1268 req->field_mask = NIX_LSO_FIELD_MASK;
1269 /* Outer IPv4/IPv6 */
1270 field->layer = NIX_TXLAYER_OL3;
1271 field->offset = v4 ? 2 : 4;
1272 field->sizem1 = 1; /* 2B */
1273 field->alg = NIX_LSOALG_ADD_PAYLEN;
1277 field->layer = NIX_TXLAYER_OL3;
1280 /* Incremented linearly per segment */
1281 field->alg = NIX_LSOALG_ADD_SEGNUM;
1285 /* TCP sequence number update */
1286 field->layer = NIX_TXLAYER_OL4;
1288 field->sizem1 = 3; /* 4 bytes */
1289 field->alg = NIX_LSOALG_ADD_OFFSET;
1291 /* TCP flags field */
1292 field->layer = NIX_TXLAYER_OL4;
1295 field->alg = NIX_LSOALG_TCP_FLAGS;
1300 nix_lso_udp_tun_tcp(struct nix_lso_format_cfg *req,
1301 bool outer_v4, bool inner_v4)
1303 volatile struct nix_lso_format *field;
1305 field = (volatile struct nix_lso_format *)&req->fields[0];
1306 req->field_mask = NIX_LSO_FIELD_MASK;
1307 /* Outer IPv4/IPv6 len */
1308 field->layer = NIX_TXLAYER_OL3;
1309 field->offset = outer_v4 ? 2 : 4;
1310 field->sizem1 = 1; /* 2B */
1311 field->alg = NIX_LSOALG_ADD_PAYLEN;
1315 field->layer = NIX_TXLAYER_OL3;
1318 /* Incremented linearly per segment */
1319 field->alg = NIX_LSOALG_ADD_SEGNUM;
1323 /* Outer UDP length */
1324 field->layer = NIX_TXLAYER_OL4;
1327 field->alg = NIX_LSOALG_ADD_PAYLEN;
1330 /* Inner IPv4/IPv6 */
1331 field->layer = NIX_TXLAYER_IL3;
1332 field->offset = inner_v4 ? 2 : 4;
1333 field->sizem1 = 1; /* 2B */
1334 field->alg = NIX_LSOALG_ADD_PAYLEN;
1338 field->layer = NIX_TXLAYER_IL3;
1341 /* Incremented linearly per segment */
1342 field->alg = NIX_LSOALG_ADD_SEGNUM;
1346 /* TCP sequence number update */
1347 field->layer = NIX_TXLAYER_IL4;
1349 field->sizem1 = 3; /* 4 bytes */
1350 field->alg = NIX_LSOALG_ADD_OFFSET;
1353 /* TCP flags field */
1354 field->layer = NIX_TXLAYER_IL4;
1357 field->alg = NIX_LSOALG_TCP_FLAGS;
1362 nix_lso_tun_tcp(struct nix_lso_format_cfg *req,
1363 bool outer_v4, bool inner_v4)
1365 volatile struct nix_lso_format *field;
1367 field = (volatile struct nix_lso_format *)&req->fields[0];
1368 req->field_mask = NIX_LSO_FIELD_MASK;
1369 /* Outer IPv4/IPv6 len */
1370 field->layer = NIX_TXLAYER_OL3;
1371 field->offset = outer_v4 ? 2 : 4;
1372 field->sizem1 = 1; /* 2B */
1373 field->alg = NIX_LSOALG_ADD_PAYLEN;
1377 field->layer = NIX_TXLAYER_OL3;
1380 /* Incremented linearly per segment */
1381 field->alg = NIX_LSOALG_ADD_SEGNUM;
1385 /* Inner IPv4/IPv6 */
1386 field->layer = NIX_TXLAYER_IL3;
1387 field->offset = inner_v4 ? 2 : 4;
1388 field->sizem1 = 1; /* 2B */
1389 field->alg = NIX_LSOALG_ADD_PAYLEN;
1393 field->layer = NIX_TXLAYER_IL3;
1396 /* Incremented linearly per segment */
1397 field->alg = NIX_LSOALG_ADD_SEGNUM;
1401 /* TCP sequence number update */
1402 field->layer = NIX_TXLAYER_IL4;
1404 field->sizem1 = 3; /* 4 bytes */
1405 field->alg = NIX_LSOALG_ADD_OFFSET;
1408 /* TCP flags field */
1409 field->layer = NIX_TXLAYER_IL4;
1412 field->alg = NIX_LSOALG_TCP_FLAGS;
1417 nix_setup_lso_formats(struct otx2_eth_dev *dev)
1419 struct otx2_mbox *mbox = dev->mbox;
1420 struct nix_lso_format_cfg_rsp *rsp;
1421 struct nix_lso_format_cfg *req;
1425 /* Skip if TSO was not requested */
1426 if (!(dev->tx_offload_flags & NIX_TX_OFFLOAD_TSO_F))
1431 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1432 nix_lso_tcp(req, true);
1433 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1437 base = rsp->lso_format_idx;
1438 if (base != NIX_LSO_FORMAT_IDX_TSOV4)
1440 dev->lso_base_idx = base;
1441 otx2_nix_dbg("tcpv4 lso fmt=%u", base);
1447 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1448 nix_lso_tcp(req, false);
1449 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1453 if (rsp->lso_format_idx != base + 1)
1455 otx2_nix_dbg("tcpv6 lso fmt=%u\n", base + 1);
1458 * IPv4/UDP/TUN HDR/IPv4/TCP LSO
1460 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1461 nix_lso_udp_tun_tcp(req, true, true);
1462 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1466 if (rsp->lso_format_idx != base + 2)
1468 otx2_nix_dbg("udp tun v4v4 fmt=%u\n", base + 2);
1471 * IPv4/UDP/TUN HDR/IPv6/TCP LSO
1473 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1474 nix_lso_udp_tun_tcp(req, true, false);
1475 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1479 if (rsp->lso_format_idx != base + 3)
1481 otx2_nix_dbg("udp tun v4v6 fmt=%u\n", base + 3);
1484 * IPv6/UDP/TUN HDR/IPv4/TCP LSO
1486 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1487 nix_lso_udp_tun_tcp(req, false, true);
1488 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1492 if (rsp->lso_format_idx != base + 4)
1494 otx2_nix_dbg("udp tun v6v4 fmt=%u\n", base + 4);
1497 * IPv6/UDP/TUN HDR/IPv6/TCP LSO
1499 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1500 nix_lso_udp_tun_tcp(req, false, false);
1501 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1504 if (rsp->lso_format_idx != base + 5)
1506 otx2_nix_dbg("udp tun v6v6 fmt=%u\n", base + 5);
1509 * IPv4/TUN HDR/IPv4/TCP LSO
1511 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1512 nix_lso_tun_tcp(req, true, true);
1513 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1517 if (rsp->lso_format_idx != base + 6)
1519 otx2_nix_dbg("tun v4v4 fmt=%u\n", base + 6);
1522 * IPv4/TUN HDR/IPv6/TCP LSO
1524 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1525 nix_lso_tun_tcp(req, true, false);
1526 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1530 if (rsp->lso_format_idx != base + 7)
1532 otx2_nix_dbg("tun v4v6 fmt=%u\n", base + 7);
1535 * IPv6/TUN HDR/IPv4/TCP LSO
1537 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1538 nix_lso_tun_tcp(req, false, true);
1539 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1543 if (rsp->lso_format_idx != base + 8)
1545 otx2_nix_dbg("tun v6v4 fmt=%u\n", base + 8);
1548 * IPv6/TUN HDR/IPv6/TCP LSO
1550 req = otx2_mbox_alloc_msg_nix_lso_format_cfg(mbox);
1551 nix_lso_tun_tcp(req, false, false);
1552 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
1555 if (rsp->lso_format_idx != base + 9)
1557 otx2_nix_dbg("tun v6v6 fmt=%u\n", base + 9);
1562 otx2_nix_configure(struct rte_eth_dev *eth_dev)
1564 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1565 struct rte_eth_dev_data *data = eth_dev->data;
1566 struct rte_eth_conf *conf = &data->dev_conf;
1567 struct rte_eth_rxmode *rxmode = &conf->rxmode;
1568 struct rte_eth_txmode *txmode = &conf->txmode;
1569 char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
1570 struct rte_ether_addr *ea;
1571 uint8_t nb_rxq, nb_txq;
1577 if (rte_eal_has_hugepages() == 0) {
1578 otx2_err("Huge page is not configured");
1579 goto fail_configure;
1582 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
1583 otx2_err("Setting link speed/duplex not supported");
1584 goto fail_configure;
1587 if (conf->dcb_capability_en == 1) {
1588 otx2_err("dcb enable is not supported");
1589 goto fail_configure;
1592 if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1593 otx2_err("Flow director is not supported");
1594 goto fail_configure;
1597 if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
1598 rxmode->mq_mode != ETH_MQ_RX_RSS) {
1599 otx2_err("Unsupported mq rx mode %d", rxmode->mq_mode);
1600 goto fail_configure;
1603 if (txmode->mq_mode != ETH_MQ_TX_NONE) {
1604 otx2_err("Unsupported mq tx mode %d", txmode->mq_mode);
1605 goto fail_configure;
1608 if (otx2_dev_is_Ax(dev) &&
1609 (txmode->offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
1610 ((txmode->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
1611 (txmode->offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM))) {
1612 otx2_err("Outer IP and SCTP checksum unsupported");
1613 goto fail_configure;
1616 /* Free the resources allocated from the previous configure */
1617 if (dev->configured == 1) {
1618 otx2_nix_rxchan_bpid_cfg(eth_dev, false);
1619 otx2_nix_vlan_fini(eth_dev);
1620 otx2_nix_mc_addr_list_uninstall(eth_dev);
1621 otx2_flow_free_all_resources(dev);
1622 oxt2_nix_unregister_queue_irqs(eth_dev);
1623 if (eth_dev->data->dev_conf.intr_conf.rxq)
1624 oxt2_nix_unregister_cq_irqs(eth_dev);
1625 nix_set_nop_rxtx_function(eth_dev);
1626 rc = nix_store_queue_cfg_and_then_release(eth_dev);
1628 goto fail_configure;
1629 otx2_nix_tm_fini(eth_dev);
1633 dev->rx_offloads = rxmode->offloads;
1634 dev->tx_offloads = txmode->offloads;
1635 dev->rx_offload_flags |= nix_rx_offload_flags(eth_dev);
1636 dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
1637 dev->rss_info.rss_grps = NIX_RSS_GRPS;
1639 nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
1640 nb_txq = RTE_MAX(data->nb_tx_queues, 1);
1642 /* Alloc a nix lf */
1643 rc = nix_lf_alloc(dev, nb_rxq, nb_txq);
1645 otx2_err("Failed to init nix_lf rc=%d", rc);
1650 dev->npc_flow.switch_header_type == OTX2_PRIV_FLAGS_HIGIG) {
1651 otx2_err("Both PTP and switch header enabled");
1655 rc = nix_lf_switch_header_type_enable(dev, true);
1657 otx2_err("Failed to enable switch type nix_lf rc=%d", rc);
1661 rc = nix_setup_lso_formats(dev);
1663 otx2_err("failed to setup nix lso format fields, rc=%d", rc);
1668 rc = otx2_nix_rss_config(eth_dev);
1670 otx2_err("Failed to configure rss rc=%d", rc);
1674 /* Init the default TM scheduler hierarchy */
1675 rc = otx2_nix_tm_init_default(eth_dev);
1677 otx2_err("Failed to init traffic manager rc=%d", rc);
1681 rc = otx2_nix_vlan_offload_init(eth_dev);
1683 otx2_err("Failed to init vlan offload rc=%d", rc);
1687 /* Register queue IRQs */
1688 rc = oxt2_nix_register_queue_irqs(eth_dev);
1690 otx2_err("Failed to register queue interrupts rc=%d", rc);
1694 /* Register cq IRQs */
1695 if (eth_dev->data->dev_conf.intr_conf.rxq) {
1696 if (eth_dev->data->nb_rx_queues > dev->cints) {
1697 otx2_err("Rx interrupt cannot be enabled, rxq > %d",
1701 /* Rx interrupt feature cannot work with vector mode because,
1702 * vector mode doesn't process packets unless min 4 pkts are
1703 * received, while cq interrupts are generated even for 1 pkt
1706 dev->scalar_ena = true;
1708 rc = oxt2_nix_register_cq_irqs(eth_dev);
1710 otx2_err("Failed to register CQ interrupts rc=%d", rc);
1715 /* Configure loop back mode */
1716 rc = cgx_intlbk_enable(dev, eth_dev->data->dev_conf.lpbk_mode);
1718 otx2_err("Failed to configure cgx loop back mode rc=%d", rc);
1722 rc = otx2_nix_rxchan_bpid_cfg(eth_dev, true);
1724 otx2_err("Failed to configure nix rx chan bpid cfg rc=%d", rc);
1728 rc = otx2_nix_mc_addr_list_install(eth_dev);
1730 otx2_err("Failed to install mc address list rc=%d", rc);
1735 * Restore queue config when reconfigure followed by
1736 * reconfigure and no queue configure invoked from application case.
1738 if (dev->configured == 1) {
1739 rc = nix_restore_queue_cfg(eth_dev);
1741 goto uninstall_mc_list;
1744 /* Update the mac address */
1745 ea = eth_dev->data->mac_addrs;
1746 memcpy(ea, dev->mac_addr, RTE_ETHER_ADDR_LEN);
1747 if (rte_is_zero_ether_addr(ea))
1748 rte_eth_random_addr((uint8_t *)ea);
1750 rte_ether_format_addr(ea_fmt, RTE_ETHER_ADDR_FMT_SIZE, ea);
1752 otx2_nix_dbg("Configured port%d mac=%s nb_rxq=%d nb_txq=%d"
1753 " rx_offloads=0x%" PRIx64 " tx_offloads=0x%" PRIx64 ""
1754 " rx_flags=0x%x tx_flags=0x%x",
1755 eth_dev->data->port_id, ea_fmt, nb_rxq,
1756 nb_txq, dev->rx_offloads, dev->tx_offloads,
1757 dev->rx_offload_flags, dev->tx_offload_flags);
1760 dev->configured = 1;
1761 dev->configured_nb_rx_qs = data->nb_rx_queues;
1762 dev->configured_nb_tx_qs = data->nb_tx_queues;
1766 otx2_nix_mc_addr_list_uninstall(eth_dev);
1768 oxt2_nix_unregister_cq_irqs(eth_dev);
1770 oxt2_nix_unregister_queue_irqs(eth_dev);
1772 otx2_nix_vlan_fini(eth_dev);
1774 otx2_nix_tm_fini(eth_dev);
1778 dev->rx_offload_flags &= ~nix_rx_offload_flags(eth_dev);
1779 dev->tx_offload_flags &= ~nix_tx_offload_flags(eth_dev);
1781 dev->configured = 0;
1786 otx2_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx)
1788 struct rte_eth_dev_data *data = eth_dev->data;
1789 struct otx2_eth_txq *txq;
1792 txq = eth_dev->data->tx_queues[qidx];
1794 if (data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
1797 rc = otx2_nix_sq_sqb_aura_fc(txq, true);
1799 otx2_err("Failed to enable sqb aura fc, txq=%u, rc=%d",
1804 data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
1811 otx2_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx)
1813 struct rte_eth_dev_data *data = eth_dev->data;
1814 struct otx2_eth_txq *txq;
1817 txq = eth_dev->data->tx_queues[qidx];
1819 if (data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
1822 txq->fc_cache_pkts = 0;
1824 rc = otx2_nix_sq_sqb_aura_fc(txq, false);
1826 otx2_err("Failed to disable sqb aura fc, txq=%u, rc=%d",
1831 data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1838 otx2_nix_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx)
1840 struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[qidx];
1841 struct rte_eth_dev_data *data = eth_dev->data;
1844 if (data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
1847 rc = nix_rq_enb_dis(rxq->eth_dev, rxq, true);
1849 otx2_err("Failed to enable rxq=%u, rc=%d", qidx, rc);
1853 data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
1860 otx2_nix_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx)
1862 struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[qidx];
1863 struct rte_eth_dev_data *data = eth_dev->data;
1866 if (data->rx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
1869 rc = nix_rq_enb_dis(rxq->eth_dev, rxq, false);
1871 otx2_err("Failed to disable rxq=%u, rc=%d", qidx, rc);
1875 data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1882 otx2_nix_dev_stop(struct rte_eth_dev *eth_dev)
1884 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1885 struct rte_mbuf *rx_pkts[32];
1886 struct otx2_eth_rxq *rxq;
1887 int count, i, j, rc;
1889 nix_lf_switch_header_type_enable(dev, false);
1890 nix_cgx_stop_link_event(dev);
1891 npc_rx_disable(dev);
1893 /* Stop rx queues and free up pkts pending */
1894 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1895 rc = otx2_nix_rx_queue_stop(eth_dev, i);
1899 rxq = eth_dev->data->rx_queues[i];
1900 count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
1902 for (j = 0; j < count; j++)
1903 rte_pktmbuf_free(rx_pkts[j]);
1904 count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
1908 /* Stop tx queues */
1909 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1910 otx2_nix_tx_queue_stop(eth_dev, i);
1914 otx2_nix_dev_start(struct rte_eth_dev *eth_dev)
1916 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1919 /* MTU recalculate should be avoided here if PTP is enabled by PF, as
1920 * otx2_nix_recalc_mtu would be invoked during otx2_nix_ptp_enable_vf
1923 if (eth_dev->data->nb_rx_queues != 0 && !otx2_ethdev_is_ptp_en(dev)) {
1924 rc = otx2_nix_recalc_mtu(eth_dev);
1929 /* Start rx queues */
1930 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1931 rc = otx2_nix_rx_queue_start(eth_dev, i);
1936 /* Start tx queues */
1937 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
1938 rc = otx2_nix_tx_queue_start(eth_dev, i);
1943 rc = otx2_nix_update_flow_ctrl_mode(eth_dev);
1945 otx2_err("Failed to update flow ctrl mode %d", rc);
1949 /* Enable PTP if it was requested by the app or if it is already
1950 * enabled in PF owning this VF
1952 memset(&dev->tstamp, 0, sizeof(struct otx2_timesync_info));
1953 if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) ||
1954 otx2_ethdev_is_ptp_en(dev))
1955 otx2_nix_timesync_enable(eth_dev);
1957 otx2_nix_timesync_disable(eth_dev);
1959 /* Update VF about data off shifted by 8 bytes if PTP already
1960 * enabled in PF owning this VF
1962 if (otx2_ethdev_is_ptp_en(dev) && otx2_dev_is_vf(dev))
1963 otx2_nix_ptp_enable_vf(eth_dev);
1965 rc = npc_rx_enable(dev);
1967 otx2_err("Failed to enable NPC rx %d", rc);
1971 otx2_nix_toggle_flag_link_cfg(dev, true);
1973 rc = nix_cgx_start_link_event(dev);
1975 otx2_err("Failed to start cgx link event %d", rc);
1979 otx2_nix_toggle_flag_link_cfg(dev, false);
1980 otx2_eth_set_tx_function(eth_dev);
1981 otx2_eth_set_rx_function(eth_dev);
1986 npc_rx_disable(dev);
1987 otx2_nix_toggle_flag_link_cfg(dev, false);
1991 static int otx2_nix_dev_reset(struct rte_eth_dev *eth_dev);
1992 static void otx2_nix_dev_close(struct rte_eth_dev *eth_dev);
1994 /* Initialize and register driver with DPDK Application */
1995 static const struct eth_dev_ops otx2_eth_dev_ops = {
1996 .dev_infos_get = otx2_nix_info_get,
1997 .dev_configure = otx2_nix_configure,
1998 .link_update = otx2_nix_link_update,
1999 .tx_queue_setup = otx2_nix_tx_queue_setup,
2000 .tx_queue_release = otx2_nix_tx_queue_release,
2001 .rx_queue_setup = otx2_nix_rx_queue_setup,
2002 .rx_queue_release = otx2_nix_rx_queue_release,
2003 .dev_start = otx2_nix_dev_start,
2004 .dev_stop = otx2_nix_dev_stop,
2005 .dev_close = otx2_nix_dev_close,
2006 .tx_queue_start = otx2_nix_tx_queue_start,
2007 .tx_queue_stop = otx2_nix_tx_queue_stop,
2008 .rx_queue_start = otx2_nix_rx_queue_start,
2009 .rx_queue_stop = otx2_nix_rx_queue_stop,
2010 .dev_set_link_up = otx2_nix_dev_set_link_up,
2011 .dev_set_link_down = otx2_nix_dev_set_link_down,
2012 .dev_supported_ptypes_get = otx2_nix_supported_ptypes_get,
2013 .dev_ptypes_set = otx2_nix_ptypes_set,
2014 .dev_reset = otx2_nix_dev_reset,
2015 .stats_get = otx2_nix_dev_stats_get,
2016 .stats_reset = otx2_nix_dev_stats_reset,
2017 .get_reg = otx2_nix_dev_get_reg,
2018 .mtu_set = otx2_nix_mtu_set,
2019 .mac_addr_add = otx2_nix_mac_addr_add,
2020 .mac_addr_remove = otx2_nix_mac_addr_del,
2021 .mac_addr_set = otx2_nix_mac_addr_set,
2022 .set_mc_addr_list = otx2_nix_set_mc_addr_list,
2023 .promiscuous_enable = otx2_nix_promisc_enable,
2024 .promiscuous_disable = otx2_nix_promisc_disable,
2025 .allmulticast_enable = otx2_nix_allmulticast_enable,
2026 .allmulticast_disable = otx2_nix_allmulticast_disable,
2027 .queue_stats_mapping_set = otx2_nix_queue_stats_mapping,
2028 .reta_update = otx2_nix_dev_reta_update,
2029 .reta_query = otx2_nix_dev_reta_query,
2030 .rss_hash_update = otx2_nix_rss_hash_update,
2031 .rss_hash_conf_get = otx2_nix_rss_hash_conf_get,
2032 .xstats_get = otx2_nix_xstats_get,
2033 .xstats_get_names = otx2_nix_xstats_get_names,
2034 .xstats_reset = otx2_nix_xstats_reset,
2035 .xstats_get_by_id = otx2_nix_xstats_get_by_id,
2036 .xstats_get_names_by_id = otx2_nix_xstats_get_names_by_id,
2037 .rxq_info_get = otx2_nix_rxq_info_get,
2038 .txq_info_get = otx2_nix_txq_info_get,
2039 .rx_burst_mode_get = otx2_rx_burst_mode_get,
2040 .tx_burst_mode_get = otx2_tx_burst_mode_get,
2041 .rx_queue_count = otx2_nix_rx_queue_count,
2042 .rx_descriptor_done = otx2_nix_rx_descriptor_done,
2043 .rx_descriptor_status = otx2_nix_rx_descriptor_status,
2044 .tx_descriptor_status = otx2_nix_tx_descriptor_status,
2045 .tx_done_cleanup = otx2_nix_tx_done_cleanup,
2046 .pool_ops_supported = otx2_nix_pool_ops_supported,
2047 .filter_ctrl = otx2_nix_dev_filter_ctrl,
2048 .get_module_info = otx2_nix_get_module_info,
2049 .get_module_eeprom = otx2_nix_get_module_eeprom,
2050 .fw_version_get = otx2_nix_fw_version_get,
2051 .flow_ctrl_get = otx2_nix_flow_ctrl_get,
2052 .flow_ctrl_set = otx2_nix_flow_ctrl_set,
2053 .timesync_enable = otx2_nix_timesync_enable,
2054 .timesync_disable = otx2_nix_timesync_disable,
2055 .timesync_read_rx_timestamp = otx2_nix_timesync_read_rx_timestamp,
2056 .timesync_read_tx_timestamp = otx2_nix_timesync_read_tx_timestamp,
2057 .timesync_adjust_time = otx2_nix_timesync_adjust_time,
2058 .timesync_read_time = otx2_nix_timesync_read_time,
2059 .timesync_write_time = otx2_nix_timesync_write_time,
2060 .vlan_offload_set = otx2_nix_vlan_offload_set,
2061 .vlan_filter_set = otx2_nix_vlan_filter_set,
2062 .vlan_strip_queue_set = otx2_nix_vlan_strip_queue_set,
2063 .vlan_tpid_set = otx2_nix_vlan_tpid_set,
2064 .vlan_pvid_set = otx2_nix_vlan_pvid_set,
2065 .rx_queue_intr_enable = otx2_nix_rx_queue_intr_enable,
2066 .rx_queue_intr_disable = otx2_nix_rx_queue_intr_disable,
2067 .read_clock = otx2_nix_read_clock,
2071 nix_lf_attach(struct otx2_eth_dev *dev)
2073 struct otx2_mbox *mbox = dev->mbox;
2074 struct rsrc_attach_req *req;
2076 /* Attach NIX(lf) */
2077 req = otx2_mbox_alloc_msg_attach_resources(mbox);
2081 return otx2_mbox_process(mbox);
2085 nix_lf_get_msix_offset(struct otx2_eth_dev *dev)
2087 struct otx2_mbox *mbox = dev->mbox;
2088 struct msix_offset_rsp *msix_rsp;
2091 /* Get NPA and NIX MSIX vector offsets */
2092 otx2_mbox_alloc_msg_msix_offset(mbox);
2094 rc = otx2_mbox_process_msg(mbox, (void *)&msix_rsp);
2096 dev->nix_msixoff = msix_rsp->nix_msixoff;
2102 otx2_eth_dev_lf_detach(struct otx2_mbox *mbox)
2104 struct rsrc_detach_req *req;
2106 req = otx2_mbox_alloc_msg_detach_resources(mbox);
2108 /* Detach all except npa lf */
2109 req->partial = true;
2116 return otx2_mbox_process(mbox);
2120 otx2_eth_dev_is_sdp(struct rte_pci_device *pci_dev)
2122 if (pci_dev->id.device_id == PCI_DEVID_OCTEONTX2_RVU_SDP_PF ||
2123 pci_dev->id.device_id == PCI_DEVID_OCTEONTX2_RVU_SDP_VF)
2129 otx2_eth_dev_init(struct rte_eth_dev *eth_dev)
2131 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2132 struct rte_pci_device *pci_dev;
2133 int rc, max_entries;
2135 eth_dev->dev_ops = &otx2_eth_dev_ops;
2137 /* For secondary processes, the primary has done all the work */
2138 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2139 /* Setup callbacks for secondary process */
2140 otx2_eth_set_tx_function(eth_dev);
2141 otx2_eth_set_rx_function(eth_dev);
2145 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2147 rte_eth_copy_pci_info(eth_dev, pci_dev);
2148 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
2150 /* Zero out everything after OTX2_DEV to allow proper dev_reset() */
2151 memset(&dev->otx2_eth_dev_data_start, 0, sizeof(*dev) -
2152 offsetof(struct otx2_eth_dev, otx2_eth_dev_data_start));
2154 /* Parse devargs string */
2155 rc = otx2_ethdev_parse_devargs(eth_dev->device->devargs, dev);
2157 otx2_err("Failed to parse devargs rc=%d", rc);
2161 if (!dev->mbox_active) {
2162 /* Initialize the base otx2_dev object
2163 * only if already present
2165 rc = otx2_dev_init(pci_dev, dev);
2167 otx2_err("Failed to initialize otx2_dev rc=%d", rc);
2171 if (otx2_eth_dev_is_sdp(pci_dev))
2172 dev->sdp_link = true;
2174 dev->sdp_link = false;
2175 /* Device generic callbacks */
2176 dev->ops = &otx2_dev_ops;
2177 dev->eth_dev = eth_dev;
2179 /* Grab the NPA LF if required */
2180 rc = otx2_npa_lf_init(pci_dev, dev);
2182 goto otx2_dev_uninit;
2184 dev->configured = 0;
2185 dev->drv_inited = true;
2186 dev->ptype_disable = 0;
2187 dev->base = dev->bar2 + (RVU_BLOCK_ADDR_NIX0 << 20);
2188 dev->lmt_addr = dev->bar2 + (RVU_BLOCK_ADDR_LMT << 20);
2191 rc = nix_lf_attach(dev);
2193 goto otx2_npa_uninit;
2195 /* Get NIX MSIX offset */
2196 rc = nix_lf_get_msix_offset(dev);
2198 goto otx2_npa_uninit;
2200 /* Register LF irq handlers */
2201 rc = otx2_nix_register_irqs(eth_dev);
2205 /* Get maximum number of supported MAC entries */
2206 max_entries = otx2_cgx_mac_max_entries_get(dev);
2207 if (max_entries < 0) {
2208 otx2_err("Failed to get max entries for mac addr");
2210 goto unregister_irq;
2213 /* For VFs, returned max_entries will be 0. But to keep default MAC
2214 * address, one entry must be allocated. So setting up to 1.
2216 if (max_entries == 0)
2219 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", max_entries *
2220 RTE_ETHER_ADDR_LEN, 0);
2221 if (eth_dev->data->mac_addrs == NULL) {
2222 otx2_err("Failed to allocate memory for mac addr");
2224 goto unregister_irq;
2227 dev->max_mac_entries = max_entries;
2229 rc = otx2_nix_mac_addr_get(eth_dev, dev->mac_addr);
2231 goto free_mac_addrs;
2233 /* Update the mac address */
2234 memcpy(eth_dev->data->mac_addrs, dev->mac_addr, RTE_ETHER_ADDR_LEN);
2236 /* Also sync same MAC address to CGX table */
2237 otx2_cgx_mac_addr_set(eth_dev, ð_dev->data->mac_addrs[0]);
2239 /* Initialize the tm data structures */
2240 otx2_nix_tm_conf_init(eth_dev);
2242 dev->tx_offload_capa = nix_get_tx_offload_capa(dev);
2243 dev->rx_offload_capa = nix_get_rx_offload_capa(dev);
2245 if (otx2_dev_is_96xx_A0(dev) ||
2246 otx2_dev_is_95xx_Ax(dev)) {
2247 dev->hwcap |= OTX2_FIXUP_F_MIN_4K_Q;
2248 dev->hwcap |= OTX2_FIXUP_F_LIMIT_CQ_FULL;
2251 /* Initialize rte-flow */
2252 rc = otx2_flow_init(dev);
2254 goto free_mac_addrs;
2256 otx2_nix_mc_filter_init(dev);
2258 otx2_nix_dbg("Port=%d pf=%d vf=%d ver=%s msix_off=%d hwcap=0x%" PRIx64
2259 " rxoffload_capa=0x%" PRIx64 " txoffload_capa=0x%" PRIx64,
2260 eth_dev->data->port_id, dev->pf, dev->vf,
2261 OTX2_ETH_DEV_PMD_VERSION, dev->nix_msixoff, dev->hwcap,
2262 dev->rx_offload_capa, dev->tx_offload_capa);
2266 rte_free(eth_dev->data->mac_addrs);
2268 otx2_nix_unregister_irqs(eth_dev);
2270 otx2_eth_dev_lf_detach(dev->mbox);
2274 otx2_dev_fini(pci_dev, dev);
2276 otx2_err("Failed to init nix eth_dev rc=%d", rc);
2281 otx2_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool mbox_close)
2283 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
2284 struct rte_pci_device *pci_dev;
2287 /* Nothing to be done for secondary processes */
2288 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2291 /* Clear the flag since we are closing down */
2292 dev->configured = 0;
2294 /* Disable nix bpid config */
2295 otx2_nix_rxchan_bpid_cfg(eth_dev, false);
2297 npc_rx_disable(dev);
2299 /* Disable vlan offloads */
2300 otx2_nix_vlan_fini(eth_dev);
2302 /* Disable other rte_flow entries */
2303 otx2_flow_fini(dev);
2305 /* Free multicast filter list */
2306 otx2_nix_mc_filter_fini(dev);
2308 /* Disable PTP if already enabled */
2309 if (otx2_ethdev_is_ptp_en(dev))
2310 otx2_nix_timesync_disable(eth_dev);
2312 nix_cgx_stop_link_event(dev);
2315 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2316 otx2_nix_tx_queue_release(eth_dev->data->tx_queues[i]);
2317 eth_dev->data->tx_queues[i] = NULL;
2319 eth_dev->data->nb_tx_queues = 0;
2321 /* Free up RQ's and CQ's */
2322 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
2323 otx2_nix_rx_queue_release(eth_dev->data->rx_queues[i]);
2324 eth_dev->data->rx_queues[i] = NULL;
2326 eth_dev->data->nb_rx_queues = 0;
2328 /* Free tm resources */
2329 rc = otx2_nix_tm_fini(eth_dev);
2331 otx2_err("Failed to cleanup tm, rc=%d", rc);
2333 /* Unregister queue irqs */
2334 oxt2_nix_unregister_queue_irqs(eth_dev);
2336 /* Unregister cq irqs */
2337 if (eth_dev->data->dev_conf.intr_conf.rxq)
2338 oxt2_nix_unregister_cq_irqs(eth_dev);
2340 rc = nix_lf_free(dev);
2342 otx2_err("Failed to free nix lf, rc=%d", rc);
2344 rc = otx2_npa_lf_fini();
2346 otx2_err("Failed to cleanup npa lf, rc=%d", rc);
2348 rte_free(eth_dev->data->mac_addrs);
2349 eth_dev->data->mac_addrs = NULL;
2350 dev->drv_inited = false;
2352 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2353 otx2_nix_unregister_irqs(eth_dev);
2355 rc = otx2_eth_dev_lf_detach(dev->mbox);
2357 otx2_err("Failed to detach resources, rc=%d", rc);
2359 /* Check if mbox close is needed */
2363 if (otx2_npa_lf_active(dev) || otx2_dev_active_vfs(dev)) {
2364 /* Will be freed later by PMD */
2365 eth_dev->data->dev_private = NULL;
2369 otx2_dev_fini(pci_dev, dev);
2374 otx2_nix_dev_close(struct rte_eth_dev *eth_dev)
2376 otx2_eth_dev_uninit(eth_dev, true);
2380 otx2_nix_dev_reset(struct rte_eth_dev *eth_dev)
2384 rc = otx2_eth_dev_uninit(eth_dev, false);
2388 return otx2_eth_dev_init(eth_dev);
2392 nix_remove(struct rte_pci_device *pci_dev)
2394 struct rte_eth_dev *eth_dev;
2395 struct otx2_idev_cfg *idev;
2396 struct otx2_dev *otx2_dev;
2399 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
2401 /* Cleanup eth dev */
2402 rc = otx2_eth_dev_uninit(eth_dev, true);
2406 rte_eth_dev_pci_release(eth_dev);
2409 /* Nothing to be done for secondary processes */
2410 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2413 /* Check for common resources */
2414 idev = otx2_intra_dev_get_cfg();
2415 if (!idev || !idev->npa_lf || idev->npa_lf->pci_dev != pci_dev)
2418 otx2_dev = container_of(idev->npa_lf, struct otx2_dev, npalf);
2420 if (otx2_npa_lf_active(otx2_dev) || otx2_dev_active_vfs(otx2_dev))
2423 /* Safe to cleanup mbox as no more users */
2424 otx2_dev_fini(pci_dev, otx2_dev);
2429 otx2_info("%s: common resource in use by other devices", pci_dev->name);
2434 nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
2438 RTE_SET_USED(pci_drv);
2440 rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct otx2_eth_dev),
2443 /* On error on secondary, recheck if port exists in primary or
2444 * in mid of detach state.
2446 if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
2447 if (!rte_eth_dev_allocated(pci_dev->device.name))
2452 static const struct rte_pci_id pci_nix_map[] = {
2454 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_PF)
2457 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_OCTEONTX2_RVU_VF)
2460 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2461 PCI_DEVID_OCTEONTX2_RVU_AF_VF)
2464 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2465 PCI_DEVID_OCTEONTX2_RVU_SDP_PF)
2468 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
2469 PCI_DEVID_OCTEONTX2_RVU_SDP_VF)
2476 static struct rte_pci_driver pci_nix = {
2477 .id_table = pci_nix_map,
2478 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA |
2479 RTE_PCI_DRV_INTR_LSC,
2481 .remove = nix_remove,
2484 RTE_PMD_REGISTER_PCI(net_octeontx2, pci_nix);
2485 RTE_PMD_REGISTER_PCI_TABLE(net_octeontx2, pci_nix_map);
2486 RTE_PMD_REGISTER_KMOD_DEP(net_octeontx2, "vfio-pci");