1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
8 #include <rte_mempool.h>
10 #include <ethdev_pci.h>
12 #include "otx_ep_common.h"
13 #include "otx_ep_vf.h"
14 #include "otx2_ep_vf.h"
15 #include "otx_ep_rxtx.h"
18 otx_ep_dmazone_free(const struct rte_memzone *mz)
20 const struct rte_memzone *mz_tmp;
24 otx_ep_err("Memzone %s : NULL\n", mz->name);
28 mz_tmp = rte_memzone_lookup(mz->name);
30 otx_ep_err("Memzone %s Not Found\n", mz->name);
34 ret = rte_memzone_free(mz);
36 otx_ep_err("Memzone free failed : ret = %d\n", ret);
40 otx_ep_droq_reset_indices(struct otx_ep_droq *droq)
45 droq->refill_count = 0;
46 droq->last_pkt_count = 0;
47 droq->pkts_pending = 0;
51 otx_ep_droq_destroy_ring_buffers(struct otx_ep_droq *droq)
55 for (idx = 0; idx < droq->nb_desc; idx++) {
56 if (droq->recv_buf_list[idx]) {
57 rte_pktmbuf_free(droq->recv_buf_list[idx]);
58 droq->recv_buf_list[idx] = NULL;
62 otx_ep_droq_reset_indices(droq);
65 /* Free OQs resources */
67 otx_ep_delete_oqs(struct otx_ep_device *otx_ep, uint32_t oq_no)
69 struct otx_ep_droq *droq;
71 droq = otx_ep->droq[oq_no];
73 otx_ep_err("Invalid droq[%d]\n", oq_no);
77 otx_ep_droq_destroy_ring_buffers(droq);
78 rte_free(droq->recv_buf_list);
79 droq->recv_buf_list = NULL;
81 if (droq->desc_ring_mz) {
82 otx_ep_dmazone_free(droq->desc_ring_mz);
83 droq->desc_ring_mz = NULL;
86 memset(droq, 0, OTX_EP_DROQ_SIZE);
88 rte_free(otx_ep->droq[oq_no]);
89 otx_ep->droq[oq_no] = NULL;
91 otx_ep->nb_rx_queues--;
93 otx_ep_info("OQ[%d] is deleted\n", oq_no);
98 otx_ep_droq_setup_ring_buffers(struct otx_ep_droq *droq)
100 struct otx_ep_droq_desc *desc_ring = droq->desc_ring;
101 struct otx_ep_droq_info *info;
102 struct rte_mbuf *buf;
105 for (idx = 0; idx < droq->nb_desc; idx++) {
106 buf = rte_pktmbuf_alloc(droq->mpool);
108 otx_ep_err("OQ buffer alloc failed\n");
109 droq->stats.rx_alloc_failure++;
113 droq->recv_buf_list[idx] = buf;
114 info = rte_pktmbuf_mtod(buf, struct otx_ep_droq_info *);
115 memset(info, 0, sizeof(*info));
116 desc_ring[idx].buffer_ptr = rte_mbuf_data_iova_default(buf);
119 otx_ep_droq_reset_indices(droq);
124 /* OQ initialization */
126 otx_ep_init_droq(struct otx_ep_device *otx_ep, uint32_t q_no,
127 uint32_t num_descs, uint32_t desc_size,
128 struct rte_mempool *mpool, unsigned int socket_id)
130 const struct otx_ep_config *conf = otx_ep->conf;
131 uint32_t c_refill_threshold;
132 struct otx_ep_droq *droq;
133 uint32_t desc_ring_size;
135 otx_ep_info("OQ[%d] Init start\n", q_no);
137 droq = otx_ep->droq[q_no];
138 droq->otx_ep_dev = otx_ep;
142 droq->nb_desc = num_descs;
143 droq->buffer_size = desc_size;
144 c_refill_threshold = RTE_MAX(conf->oq.refill_threshold,
147 /* OQ desc_ring set up */
148 desc_ring_size = droq->nb_desc * OTX_EP_DROQ_DESC_SIZE;
149 droq->desc_ring_mz = rte_eth_dma_zone_reserve(otx_ep->eth_dev, "droq",
150 q_no, desc_ring_size,
151 OTX_EP_PCI_RING_ALIGN,
154 if (droq->desc_ring_mz == NULL) {
155 otx_ep_err("OQ:%d desc_ring allocation failed\n", q_no);
159 droq->desc_ring_dma = droq->desc_ring_mz->iova;
160 droq->desc_ring = (struct otx_ep_droq_desc *)droq->desc_ring_mz->addr;
162 otx_ep_dbg("OQ[%d]: desc_ring: virt: 0x%p, dma: %lx\n",
163 q_no, droq->desc_ring, (unsigned long)droq->desc_ring_dma);
164 otx_ep_dbg("OQ[%d]: num_desc: %d\n", q_no, droq->nb_desc);
166 /* OQ buf_list set up */
167 droq->recv_buf_list = rte_zmalloc_socket("recv_buf_list",
168 (droq->nb_desc * sizeof(struct rte_mbuf *)),
169 RTE_CACHE_LINE_SIZE, socket_id);
170 if (droq->recv_buf_list == NULL) {
171 otx_ep_err("OQ recv_buf_list alloc failed\n");
175 if (otx_ep_droq_setup_ring_buffers(droq))
178 droq->refill_threshold = c_refill_threshold;
180 /* Set up OQ registers */
181 otx_ep->fn_list.setup_oq_regs(otx_ep, q_no);
183 otx_ep->io_qmask.oq |= (1ull << q_no);
191 /* OQ configuration and setup */
193 otx_ep_setup_oqs(struct otx_ep_device *otx_ep, int oq_no, int num_descs,
194 int desc_size, struct rte_mempool *mpool,
195 unsigned int socket_id)
197 struct otx_ep_droq *droq;
199 /* Allocate new droq. */
200 droq = (struct otx_ep_droq *)rte_zmalloc("otx_ep_OQ",
201 sizeof(*droq), RTE_CACHE_LINE_SIZE);
203 otx_ep_err("Droq[%d] Creation Failed\n", oq_no);
206 otx_ep->droq[oq_no] = droq;
208 if (otx_ep_init_droq(otx_ep, oq_no, num_descs, desc_size, mpool,
210 otx_ep_err("Droq[%d] Initialization failed\n", oq_no);
213 otx_ep_info("OQ[%d] is created.\n", oq_no);
215 otx_ep->nb_rx_queues++;
220 otx_ep_delete_oqs(otx_ep, oq_no);