xref: /dpdk/drivers/net/ark/ark_ethdev_tx.c (revision 540914bc7ad88bae5ac5a4ea4acf4ddc5f4799e5)
1*540914bcSEd Czeck /* SPDX-License-Identifier: BSD-3-Clause
2*540914bcSEd Czeck  * Copyright (c) 2015-2018 Atomic Rules LLC
3c33d45afSEd Czeck  */
4c33d45afSEd Czeck 
5c33d45afSEd Czeck #include <unistd.h>
6c33d45afSEd Czeck 
7c33d45afSEd Czeck #include "ark_ethdev_tx.h"
8c33d45afSEd Czeck #include "ark_global.h"
9c33d45afSEd Czeck #include "ark_mpu.h"
10c33d45afSEd Czeck #include "ark_ddm.h"
11c33d45afSEd Czeck #include "ark_logs.h"
12c33d45afSEd Czeck 
13c33d45afSEd Czeck #define ARK_TX_META_SIZE   32
14c33d45afSEd Czeck #define ARK_TX_META_OFFSET (RTE_PKTMBUF_HEADROOM - ARK_TX_META_SIZE)
15c33d45afSEd Czeck #define ARK_TX_MAX_NOCHAIN (RTE_MBUF_DEFAULT_DATAROOM)
16c33d45afSEd Czeck 
17c33d45afSEd Czeck 
18c33d45afSEd Czeck /* ************************************************************************* */
19c33d45afSEd Czeck struct ark_tx_queue {
20c33d45afSEd Czeck 	struct ark_tx_meta *meta_q;
21c33d45afSEd Czeck 	struct rte_mbuf **bufs;
22c33d45afSEd Czeck 
23c33d45afSEd Czeck 	/* handles for hw objects */
24c33d45afSEd Czeck 	struct ark_mpu_t *mpu;
25c33d45afSEd Czeck 	struct ark_ddm_t *ddm;
26c33d45afSEd Czeck 
27c33d45afSEd Czeck 	/* Stats HW tracks bytes and packets, need to count send errors */
28c33d45afSEd Czeck 	uint64_t tx_errors;
29c33d45afSEd Czeck 
30c33d45afSEd Czeck 	uint32_t queue_size;
31c33d45afSEd Czeck 	uint32_t queue_mask;
32c33d45afSEd Czeck 
33c33d45afSEd Czeck 	/* 3 indexes to the paired data rings. */
34c33d45afSEd Czeck 	uint32_t prod_index;		/* where to put the next one */
35c33d45afSEd Czeck 	uint32_t free_index;		/* mbuf has been freed */
36c33d45afSEd Czeck 
37c33d45afSEd Czeck 	/* The queue Id is used to identify the HW Q */
38c33d45afSEd Czeck 	uint16_t phys_qid;
39c33d45afSEd Czeck 	/* The queue Index within the dpdk device structures */
40c33d45afSEd Czeck 	uint16_t queue_index;
41c33d45afSEd Czeck 
42c33d45afSEd Czeck 	uint32_t pad[1];
43c33d45afSEd Czeck 
44c33d45afSEd Czeck 	/* second cache line - fields only used in slow path */
45c33d45afSEd Czeck 	MARKER cacheline1 __rte_cache_min_aligned;
46c33d45afSEd Czeck 	uint32_t cons_index;		/* hw is done, can be freed */
47c33d45afSEd Czeck } __rte_cache_aligned;
48c33d45afSEd Czeck 
49c33d45afSEd Czeck /* Forward declarations */
50c33d45afSEd Czeck static uint32_t eth_ark_tx_jumbo(struct ark_tx_queue *queue,
51c33d45afSEd Czeck 				 struct rte_mbuf *mbuf);
52c33d45afSEd Czeck static int eth_ark_tx_hw_queue_config(struct ark_tx_queue *queue);
53c33d45afSEd Czeck static void free_completed_tx(struct ark_tx_queue *queue);
54c33d45afSEd Czeck 
55c33d45afSEd Czeck static inline void
56c33d45afSEd Czeck ark_tx_hw_queue_stop(struct ark_tx_queue *queue)
57c33d45afSEd Czeck {
58c33d45afSEd Czeck 	ark_mpu_stop(queue->mpu);
59c33d45afSEd Czeck }
60c33d45afSEd Czeck 
61c33d45afSEd Czeck /* ************************************************************************* */
62c33d45afSEd Czeck static inline void
63c33d45afSEd Czeck eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
64c33d45afSEd Czeck 			  const struct rte_mbuf *mbuf,
65c33d45afSEd Czeck 			  uint8_t flags)
66c33d45afSEd Czeck {
67bfa9a8a4SThomas Monjalon 	meta->physaddr = rte_mbuf_data_iova(mbuf);
68c33d45afSEd Czeck 	meta->delta_ns = 0;
69c33d45afSEd Czeck 	meta->data_len = rte_pktmbuf_data_len(mbuf);
70c33d45afSEd Czeck 	meta->flags = flags;
71c33d45afSEd Czeck }
72c33d45afSEd Czeck 
73c33d45afSEd Czeck /* ************************************************************************* */
74c33d45afSEd Czeck uint16_t
75c33d45afSEd Czeck eth_ark_xmit_pkts_noop(void *vtxq __rte_unused,
76c33d45afSEd Czeck 		       struct rte_mbuf **tx_pkts __rte_unused,
77c33d45afSEd Czeck 		       uint16_t nb_pkts __rte_unused)
78c33d45afSEd Czeck {
79c33d45afSEd Czeck 	return 0;
80c33d45afSEd Czeck }
81c33d45afSEd Czeck 
82c33d45afSEd Czeck /* ************************************************************************* */
83c33d45afSEd Czeck uint16_t
84c33d45afSEd Czeck eth_ark_xmit_pkts(void *vtxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
85c33d45afSEd Czeck {
86c33d45afSEd Czeck 	struct ark_tx_queue *queue;
87c33d45afSEd Czeck 	struct rte_mbuf *mbuf;
88c33d45afSEd Czeck 	struct ark_tx_meta *meta;
89c33d45afSEd Czeck 
90c33d45afSEd Czeck 	uint32_t idx;
91c33d45afSEd Czeck 	uint32_t prod_index_limit;
92c33d45afSEd Czeck 	int stat;
93c33d45afSEd Czeck 	uint16_t nb;
94c33d45afSEd Czeck 
95c33d45afSEd Czeck 	queue = (struct ark_tx_queue *)vtxq;
96c33d45afSEd Czeck 
97c33d45afSEd Czeck 	/* free any packets after the HW is done with them */
98c33d45afSEd Czeck 	free_completed_tx(queue);
99c33d45afSEd Czeck 
100c33d45afSEd Czeck 	prod_index_limit = queue->queue_size + queue->free_index;
101c33d45afSEd Czeck 
102c33d45afSEd Czeck 	for (nb = 0;
103c33d45afSEd Czeck 	     (nb < nb_pkts) && (queue->prod_index != prod_index_limit);
104c33d45afSEd Czeck 	     ++nb) {
105c33d45afSEd Czeck 		mbuf = tx_pkts[nb];
106c33d45afSEd Czeck 
107c33d45afSEd Czeck 		if (ARK_TX_PAD_TO_60) {
108c33d45afSEd Czeck 			if (unlikely(rte_pktmbuf_pkt_len(mbuf) < 60)) {
109c33d45afSEd Czeck 				/* this packet even if it is small can be split,
110c33d45afSEd Czeck 				 * be sure to add to the end mbuf
111c33d45afSEd Czeck 				 */
112c33d45afSEd Czeck 				uint16_t to_add =
113c33d45afSEd Czeck 					60 - rte_pktmbuf_pkt_len(mbuf);
114c33d45afSEd Czeck 				char *appended =
115c33d45afSEd Czeck 					rte_pktmbuf_append(mbuf, to_add);
116c33d45afSEd Czeck 
117c33d45afSEd Czeck 				if (appended == 0) {
118c33d45afSEd Czeck 					/* This packet is in error,
119c33d45afSEd Czeck 					 * we cannot send it so just
120c33d45afSEd Czeck 					 * count it and delete it.
121c33d45afSEd Czeck 					 */
122c33d45afSEd Czeck 					queue->tx_errors += 1;
123c33d45afSEd Czeck 					rte_pktmbuf_free(mbuf);
124c33d45afSEd Czeck 					continue;
125c33d45afSEd Czeck 				}
126c33d45afSEd Czeck 				memset(appended, 0, to_add);
127c33d45afSEd Czeck 			}
128c33d45afSEd Czeck 		}
129c33d45afSEd Czeck 
130c33d45afSEd Czeck 		if (unlikely(mbuf->nb_segs != 1)) {
131c33d45afSEd Czeck 			stat = eth_ark_tx_jumbo(queue, mbuf);
132c33d45afSEd Czeck 			if (unlikely(stat != 0))
133c33d45afSEd Czeck 				break;		/* Queue is full */
134c33d45afSEd Czeck 		} else {
135c33d45afSEd Czeck 			idx = queue->prod_index & queue->queue_mask;
136c33d45afSEd Czeck 			queue->bufs[idx] = mbuf;
137c33d45afSEd Czeck 			meta = &queue->meta_q[idx];
138c33d45afSEd Czeck 			eth_ark_tx_meta_from_mbuf(meta,
139c33d45afSEd Czeck 						  mbuf,
140c33d45afSEd Czeck 						  ARK_DDM_SOP |
141c33d45afSEd Czeck 						  ARK_DDM_EOP);
142c33d45afSEd Czeck 			queue->prod_index++;
143c33d45afSEd Czeck 		}
144c33d45afSEd Czeck 	}
145c33d45afSEd Czeck 
146c33d45afSEd Czeck 	if (ARK_TX_DEBUG && (nb != nb_pkts)) {
147c33d45afSEd Czeck 		PMD_TX_LOG(DEBUG, "TX: Failure to send:"
148c33d45afSEd Czeck 			   " req: %" PRIU32
149c33d45afSEd Czeck 			   " sent: %" PRIU32
150c33d45afSEd Czeck 			   " prod: %" PRIU32
151c33d45afSEd Czeck 			   " cons: %" PRIU32
152c33d45afSEd Czeck 			   " free: %" PRIU32 "\n",
153c33d45afSEd Czeck 			   nb_pkts, nb,
154c33d45afSEd Czeck 			   queue->prod_index,
155c33d45afSEd Czeck 			   queue->cons_index,
156c33d45afSEd Czeck 			   queue->free_index);
157c33d45afSEd Czeck 		ark_mpu_dump(queue->mpu,
158c33d45afSEd Czeck 			     "TX Failure MPU: ",
159c33d45afSEd Czeck 			     queue->phys_qid);
160c33d45afSEd Czeck 	}
161c33d45afSEd Czeck 
162c33d45afSEd Czeck 	/* let FPGA know producer index.  */
163c33d45afSEd Czeck 	if (likely(nb != 0))
164c33d45afSEd Czeck 		ark_mpu_set_producer(queue->mpu, queue->prod_index);
165c33d45afSEd Czeck 
166c33d45afSEd Czeck 	return nb;
167c33d45afSEd Czeck }
168c33d45afSEd Czeck 
169c33d45afSEd Czeck /* ************************************************************************* */
170c33d45afSEd Czeck static uint32_t
171c33d45afSEd Czeck eth_ark_tx_jumbo(struct ark_tx_queue *queue, struct rte_mbuf *mbuf)
172c33d45afSEd Czeck {
173c33d45afSEd Czeck 	struct rte_mbuf *next;
174c33d45afSEd Czeck 	struct ark_tx_meta *meta;
175c33d45afSEd Czeck 	uint32_t free_queue_space;
176c33d45afSEd Czeck 	uint32_t idx;
177c33d45afSEd Czeck 	uint8_t flags = ARK_DDM_SOP;
178c33d45afSEd Czeck 
179c33d45afSEd Czeck 	free_queue_space = queue->queue_mask -
180c33d45afSEd Czeck 		(queue->prod_index - queue->free_index);
181c33d45afSEd Czeck 	if (unlikely(free_queue_space < mbuf->nb_segs))
182c33d45afSEd Czeck 		return -1;
183c33d45afSEd Czeck 
184c33d45afSEd Czeck 	while (mbuf != NULL) {
185c33d45afSEd Czeck 		next = mbuf->next;
186c33d45afSEd Czeck 
187c33d45afSEd Czeck 		idx = queue->prod_index & queue->queue_mask;
188c33d45afSEd Czeck 		queue->bufs[idx] = mbuf;
189c33d45afSEd Czeck 		meta = &queue->meta_q[idx];
190c33d45afSEd Czeck 
191c33d45afSEd Czeck 		flags |= (next == NULL) ? ARK_DDM_EOP : 0;
192c33d45afSEd Czeck 		eth_ark_tx_meta_from_mbuf(meta, mbuf, flags);
193c33d45afSEd Czeck 		queue->prod_index++;
194c33d45afSEd Czeck 
195c33d45afSEd Czeck 		flags &= ~ARK_DDM_SOP;	/* drop SOP flags */
196c33d45afSEd Czeck 		mbuf = next;
197c33d45afSEd Czeck 	}
198c33d45afSEd Czeck 
199c33d45afSEd Czeck 	return 0;
200c33d45afSEd Czeck }
201c33d45afSEd Czeck 
202c33d45afSEd Czeck /* ************************************************************************* */
203c33d45afSEd Czeck int
204c33d45afSEd Czeck eth_ark_tx_queue_setup(struct rte_eth_dev *dev,
205c33d45afSEd Czeck 		       uint16_t queue_idx,
206c33d45afSEd Czeck 		       uint16_t nb_desc,
207c33d45afSEd Czeck 		       unsigned int socket_id,
208c33d45afSEd Czeck 		       const struct rte_eth_txconf *tx_conf __rte_unused)
209c33d45afSEd Czeck {
210c33d45afSEd Czeck 	struct ark_adapter *ark = (struct ark_adapter *)dev->data->dev_private;
211c33d45afSEd Czeck 	struct ark_tx_queue *queue;
212c33d45afSEd Czeck 	int status;
213c33d45afSEd Czeck 
214c33d45afSEd Czeck 	/* Future: divide the Q's evenly with multi-ports */
215c33d45afSEd Czeck 	int port = dev->data->port_id;
216c33d45afSEd Czeck 	int qidx = port + queue_idx;
217c33d45afSEd Czeck 
218c33d45afSEd Czeck 	if (!rte_is_power_of_2(nb_desc)) {
219c33d45afSEd Czeck 		PMD_DRV_LOG(ERR,
220c33d45afSEd Czeck 			    "DPDK Arkville configuration queue size"
221c33d45afSEd Czeck 			    " must be power of two %u (%s)\n",
222c33d45afSEd Czeck 			    nb_desc, __func__);
223c33d45afSEd Czeck 		return -1;
224c33d45afSEd Czeck 	}
225c33d45afSEd Czeck 
226c33d45afSEd Czeck 	/* Allocate queue struct */
227c33d45afSEd Czeck 	queue =	rte_zmalloc_socket("Ark_txqueue",
228c33d45afSEd Czeck 				   sizeof(struct ark_tx_queue),
229c33d45afSEd Czeck 				   64,
230c33d45afSEd Czeck 				   socket_id);
231c33d45afSEd Czeck 	if (queue == 0) {
232c33d45afSEd Czeck 		PMD_DRV_LOG(ERR, "Failed to allocate tx "
233c33d45afSEd Czeck 			    "queue memory in %s\n",
234c33d45afSEd Czeck 			    __func__);
235c33d45afSEd Czeck 		return -ENOMEM;
236c33d45afSEd Czeck 	}
237c33d45afSEd Czeck 
238c33d45afSEd Czeck 	/* we use zmalloc no need to initialize fields */
239c33d45afSEd Czeck 	queue->queue_size = nb_desc;
240c33d45afSEd Czeck 	queue->queue_mask = nb_desc - 1;
241c33d45afSEd Czeck 	queue->phys_qid = qidx;
242c33d45afSEd Czeck 	queue->queue_index = queue_idx;
243c33d45afSEd Czeck 	dev->data->tx_queues[queue_idx] = queue;
244c33d45afSEd Czeck 
245c33d45afSEd Czeck 	queue->meta_q =
246c33d45afSEd Czeck 		rte_zmalloc_socket("Ark_txqueue meta",
247c33d45afSEd Czeck 				   nb_desc * sizeof(struct ark_tx_meta),
248c33d45afSEd Czeck 				   64,
249c33d45afSEd Czeck 				   socket_id);
250c33d45afSEd Czeck 	queue->bufs =
251c33d45afSEd Czeck 		rte_zmalloc_socket("Ark_txqueue bufs",
252c33d45afSEd Czeck 				   nb_desc * sizeof(struct rte_mbuf *),
253c33d45afSEd Czeck 				   64,
254c33d45afSEd Czeck 				   socket_id);
255c33d45afSEd Czeck 
256c33d45afSEd Czeck 	if (queue->meta_q == 0 || queue->bufs == 0) {
257c33d45afSEd Czeck 		PMD_DRV_LOG(ERR, "Failed to allocate "
258c33d45afSEd Czeck 			    "queue memory in %s\n", __func__);
259c33d45afSEd Czeck 		rte_free(queue->meta_q);
260c33d45afSEd Czeck 		rte_free(queue->bufs);
261c33d45afSEd Czeck 		rte_free(queue);
262c33d45afSEd Czeck 		return -ENOMEM;
263c33d45afSEd Czeck 	}
264c33d45afSEd Czeck 
265c33d45afSEd Czeck 	queue->ddm = RTE_PTR_ADD(ark->ddm.v, qidx * ARK_DDM_QOFFSET);
266c33d45afSEd Czeck 	queue->mpu = RTE_PTR_ADD(ark->mputx.v, qidx * ARK_MPU_QOFFSET);
267c33d45afSEd Czeck 
268c33d45afSEd Czeck 	status = eth_ark_tx_hw_queue_config(queue);
269c33d45afSEd Czeck 
270c33d45afSEd Czeck 	if (unlikely(status != 0)) {
271c33d45afSEd Czeck 		rte_free(queue->meta_q);
272c33d45afSEd Czeck 		rte_free(queue->bufs);
273c33d45afSEd Czeck 		rte_free(queue);
274c33d45afSEd Czeck 		return -1;		/* ERROR CODE */
275c33d45afSEd Czeck 	}
276c33d45afSEd Czeck 
277c33d45afSEd Czeck 	return 0;
278c33d45afSEd Czeck }
279c33d45afSEd Czeck 
280c33d45afSEd Czeck /* ************************************************************************* */
281c33d45afSEd Czeck static int
282c33d45afSEd Czeck eth_ark_tx_hw_queue_config(struct ark_tx_queue *queue)
283c33d45afSEd Czeck {
284df6e0a06SSantosh Shukla 	rte_iova_t queue_base, ring_base, cons_index_addr;
285c33d45afSEd Czeck 	uint32_t write_interval_ns;
286c33d45afSEd Czeck 
287c33d45afSEd Czeck 	/* Verify HW -- MPU */
288c33d45afSEd Czeck 	if (ark_mpu_verify(queue->mpu, sizeof(struct ark_tx_meta)))
289c33d45afSEd Czeck 		return -1;
290c33d45afSEd Czeck 
29187cf4c6cSThomas Monjalon 	queue_base = rte_malloc_virt2iova(queue);
29287cf4c6cSThomas Monjalon 	ring_base = rte_malloc_virt2iova(queue->meta_q);
293c33d45afSEd Czeck 	cons_index_addr =
294c33d45afSEd Czeck 		queue_base + offsetof(struct ark_tx_queue, cons_index);
295c33d45afSEd Czeck 
296c33d45afSEd Czeck 	ark_mpu_stop(queue->mpu);
297c33d45afSEd Czeck 	ark_mpu_reset(queue->mpu);
298c33d45afSEd Czeck 
299c33d45afSEd Czeck 	/* Stop and Reset and configure MPU */
300c33d45afSEd Czeck 	ark_mpu_configure(queue->mpu, ring_base, queue->queue_size, 1);
301c33d45afSEd Czeck 
302c33d45afSEd Czeck 	/*
303c33d45afSEd Czeck 	 * Adjust the write interval based on queue size --
304c33d45afSEd Czeck 	 * increase pcie traffic  when low mbuf count
305c33d45afSEd Czeck 	 * Queue sizes less than 128 are not allowed
306c33d45afSEd Czeck 	 */
307c33d45afSEd Czeck 	switch (queue->queue_size) {
308c33d45afSEd Czeck 	case 128:
309c33d45afSEd Czeck 		write_interval_ns = 500;
310c33d45afSEd Czeck 		break;
311c33d45afSEd Czeck 	case 256:
312c33d45afSEd Czeck 		write_interval_ns = 500;
313c33d45afSEd Czeck 		break;
314c33d45afSEd Czeck 	case 512:
315c33d45afSEd Czeck 		write_interval_ns = 1000;
316c33d45afSEd Czeck 		break;
317c33d45afSEd Czeck 	default:
318c33d45afSEd Czeck 		write_interval_ns = 2000;
319c33d45afSEd Czeck 		break;
320c33d45afSEd Czeck 	}
321c33d45afSEd Czeck 
322c33d45afSEd Czeck 	/* Completion address in UDM */
323c33d45afSEd Czeck 	ark_ddm_setup(queue->ddm, cons_index_addr, write_interval_ns);
324c33d45afSEd Czeck 
325c33d45afSEd Czeck 	return 0;
326c33d45afSEd Czeck }
327c33d45afSEd Czeck 
328c33d45afSEd Czeck /* ************************************************************************* */
329c33d45afSEd Czeck void
330c33d45afSEd Czeck eth_ark_tx_queue_release(void *vtx_queue)
331c33d45afSEd Czeck {
332c33d45afSEd Czeck 	struct ark_tx_queue *queue;
333c33d45afSEd Czeck 
334c33d45afSEd Czeck 	queue = (struct ark_tx_queue *)vtx_queue;
335c33d45afSEd Czeck 
336c33d45afSEd Czeck 	ark_tx_hw_queue_stop(queue);
337c33d45afSEd Czeck 
338c33d45afSEd Czeck 	queue->cons_index = queue->prod_index;
339c33d45afSEd Czeck 	free_completed_tx(queue);
340c33d45afSEd Czeck 
341c33d45afSEd Czeck 	rte_free(queue->meta_q);
342c33d45afSEd Czeck 	rte_free(queue->bufs);
343c33d45afSEd Czeck 	rte_free(queue);
344c33d45afSEd Czeck }
345c33d45afSEd Czeck 
346c33d45afSEd Czeck /* ************************************************************************* */
347c33d45afSEd Czeck int
348c33d45afSEd Czeck eth_ark_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id)
349c33d45afSEd Czeck {
350c33d45afSEd Czeck 	struct ark_tx_queue *queue;
351c33d45afSEd Czeck 	int cnt = 0;
352c33d45afSEd Czeck 
353c33d45afSEd Czeck 	queue = dev->data->tx_queues[queue_id];
354c33d45afSEd Czeck 
355c33d45afSEd Czeck 	/* Wait for DDM to send out all packets. */
356c33d45afSEd Czeck 	while (queue->cons_index != queue->prod_index) {
357c33d45afSEd Czeck 		usleep(100);
358c33d45afSEd Czeck 		if (cnt++ > 10000)
359c33d45afSEd Czeck 			return -1;
360c33d45afSEd Czeck 	}
361c33d45afSEd Czeck 
362c33d45afSEd Czeck 	ark_mpu_stop(queue->mpu);
363c33d45afSEd Czeck 	free_completed_tx(queue);
364c33d45afSEd Czeck 
365c33d45afSEd Czeck 	dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
366c33d45afSEd Czeck 
367c33d45afSEd Czeck 	return 0;
368c33d45afSEd Czeck }
369c33d45afSEd Czeck 
370c33d45afSEd Czeck int
371c33d45afSEd Czeck eth_ark_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id)
372c33d45afSEd Czeck {
373c33d45afSEd Czeck 	struct ark_tx_queue *queue;
374c33d45afSEd Czeck 
375c33d45afSEd Czeck 	queue = dev->data->tx_queues[queue_id];
376c33d45afSEd Czeck 	if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_STARTED)
377c33d45afSEd Czeck 		return 0;
378c33d45afSEd Czeck 
379c33d45afSEd Czeck 	ark_mpu_start(queue->mpu);
380c33d45afSEd Czeck 	dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
381c33d45afSEd Czeck 
382c33d45afSEd Czeck 	return 0;
383c33d45afSEd Czeck }
384c33d45afSEd Czeck 
385c33d45afSEd Czeck /* ************************************************************************* */
386c33d45afSEd Czeck static void
387c33d45afSEd Czeck free_completed_tx(struct ark_tx_queue *queue)
388c33d45afSEd Czeck {
389c33d45afSEd Czeck 	struct rte_mbuf *mbuf;
390c33d45afSEd Czeck 	struct ark_tx_meta *meta;
391c33d45afSEd Czeck 	uint32_t top_index;
392c33d45afSEd Czeck 
393c33d45afSEd Czeck 	top_index = queue->cons_index;	/* read once */
394c33d45afSEd Czeck 	while (queue->free_index != top_index) {
395c33d45afSEd Czeck 		meta = &queue->meta_q[queue->free_index & queue->queue_mask];
396c33d45afSEd Czeck 		mbuf = queue->bufs[queue->free_index & queue->queue_mask];
397c33d45afSEd Czeck 
398c33d45afSEd Czeck 		if (likely((meta->flags & ARK_DDM_SOP) != 0)) {
399c33d45afSEd Czeck 			/* ref count of the mbuf is checked in this call. */
400c33d45afSEd Czeck 			rte_pktmbuf_free(mbuf);
401c33d45afSEd Czeck 		}
402c33d45afSEd Czeck 		queue->free_index++;
403c33d45afSEd Czeck 	}
404c33d45afSEd Czeck }
405c33d45afSEd Czeck 
406c33d45afSEd Czeck /* ************************************************************************* */
407c33d45afSEd Czeck void
408c33d45afSEd Czeck eth_tx_queue_stats_get(void *vqueue, struct rte_eth_stats *stats)
409c33d45afSEd Czeck {
410c33d45afSEd Czeck 	struct ark_tx_queue *queue;
411c33d45afSEd Czeck 	struct ark_ddm_t *ddm;
412c33d45afSEd Czeck 	uint64_t bytes, pkts;
413c33d45afSEd Czeck 
414c33d45afSEd Czeck 	queue = vqueue;
415c33d45afSEd Czeck 	ddm = queue->ddm;
416c33d45afSEd Czeck 
417c33d45afSEd Czeck 	bytes = ark_ddm_queue_byte_count(ddm);
418c33d45afSEd Czeck 	pkts = ark_ddm_queue_pkt_count(ddm);
419c33d45afSEd Czeck 
420c33d45afSEd Czeck 	stats->q_opackets[queue->queue_index] = pkts;
421c33d45afSEd Czeck 	stats->q_obytes[queue->queue_index] = bytes;
422c33d45afSEd Czeck 	stats->opackets += pkts;
423c33d45afSEd Czeck 	stats->obytes += bytes;
424c33d45afSEd Czeck 	stats->oerrors += queue->tx_errors;
425c33d45afSEd Czeck }
426c33d45afSEd Czeck 
427c33d45afSEd Czeck void
428c33d45afSEd Czeck eth_tx_queue_stats_reset(void *vqueue)
429c33d45afSEd Czeck {
430c33d45afSEd Czeck 	struct ark_tx_queue *queue;
431c33d45afSEd Czeck 	struct ark_ddm_t *ddm;
432c33d45afSEd Czeck 
433c33d45afSEd Czeck 	queue = vqueue;
434c33d45afSEd Czeck 	ddm = queue->ddm;
435c33d45afSEd Czeck 
436c33d45afSEd Czeck 	ark_ddm_queue_reset_stats(ddm);
437c33d45afSEd Czeck 	queue->tx_errors = 0;
438c33d45afSEd Czeck }
439