1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
3 * Copyright(c) 2018 Synopsys, Inc. All rights reserved.
6 #include "axgbe_ethdev.h"
7 #include "axgbe_rxtx.h"
11 #include <rte_mempool.h>
16 axgbe_rx_queue_release(struct axgbe_rx_queue *rx_queue)
19 struct rte_mbuf **sw_ring;
22 sw_ring = rx_queue->sw_ring;
24 for (i = 0; i < rx_queue->nb_desc; i++) {
26 rte_pktmbuf_free(sw_ring[i]);
34 void axgbe_dev_rx_queue_release(void *rxq)
36 axgbe_rx_queue_release(rxq);
39 int axgbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
40 uint16_t nb_desc, unsigned int socket_id,
41 const struct rte_eth_rxconf *rx_conf,
42 struct rte_mempool *mp)
44 PMD_INIT_FUNC_TRACE();
46 const struct rte_memzone *dma;
47 struct axgbe_rx_queue *rxq;
48 uint32_t rx_desc = nb_desc;
49 struct axgbe_port *pdata = dev->data->dev_private;
52 * validate Rx descriptors count
53 * should be power of 2 and less than h/w supported
55 if ((!rte_is_power_of_2(rx_desc)) ||
56 rx_desc > pdata->rx_desc_count)
58 /* First allocate the rx queue data structure */
59 rxq = rte_zmalloc_socket("ethdev RX queue",
60 sizeof(struct axgbe_rx_queue),
61 RTE_CACHE_LINE_SIZE, socket_id);
63 PMD_INIT_LOG(ERR, "rte_zmalloc for rxq failed!");
71 rxq->queue_id = queue_idx;
72 rxq->port_id = dev->data->port_id;
73 rxq->nb_desc = rx_desc;
74 rxq->dma_regs = (void *)((uint8_t *)pdata->xgmac_regs + DMA_CH_BASE +
75 (DMA_CH_INC * rxq->queue_id));
76 rxq->dma_tail_reg = (volatile uint32_t *)((uint8_t *)rxq->dma_regs +
78 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
79 rxq->crc_len = RTE_ETHER_CRC_LEN;
83 /* CRC strip in AXGBE supports per port not per queue */
84 pdata->crc_strip_enable = (rxq->crc_len == 0) ? 1 : 0;
85 rxq->free_thresh = rx_conf->rx_free_thresh ?
86 rx_conf->rx_free_thresh : AXGBE_RX_FREE_THRESH;
87 if (rxq->free_thresh > rxq->nb_desc)
88 rxq->free_thresh = rxq->nb_desc >> 3;
90 /* Allocate RX ring hardware descriptors */
91 size = rxq->nb_desc * sizeof(union axgbe_rx_desc);
92 dma = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size, 128,
95 PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for rx_ring failed\n");
96 axgbe_rx_queue_release(rxq);
99 rxq->ring_phys_addr = (uint64_t)dma->iova;
100 rxq->desc = (volatile union axgbe_rx_desc *)dma->addr;
101 memset((void *)rxq->desc, 0, size);
102 /* Allocate software ring */
103 size = rxq->nb_desc * sizeof(struct rte_mbuf *);
104 rxq->sw_ring = rte_zmalloc_socket("sw_ring", size,
108 PMD_DRV_LOG(ERR, "rte_zmalloc for sw_ring failed\n");
109 axgbe_rx_queue_release(rxq);
112 dev->data->rx_queues[queue_idx] = rxq;
113 if (!pdata->rx_queues)
114 pdata->rx_queues = dev->data->rx_queues;
119 static void axgbe_prepare_rx_stop(struct axgbe_port *pdata,
122 unsigned int rx_status;
123 unsigned long rx_timeout;
125 /* The Rx engine cannot be stopped if it is actively processing
126 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
127 * wait forever though...
129 rx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
132 while (time_before(rte_get_timer_cycles(), rx_timeout)) {
133 rx_status = AXGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
134 if ((AXGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
135 (AXGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
141 if (!time_before(rte_get_timer_cycles(), rx_timeout))
143 "timed out waiting for Rx queue %u to empty\n",
147 void axgbe_dev_disable_rx(struct rte_eth_dev *dev)
149 struct axgbe_rx_queue *rxq;
150 struct axgbe_port *pdata = dev->data->dev_private;
154 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
155 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
156 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
157 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
159 /* Prepare for Rx DMA channel stop */
160 for (i = 0; i < dev->data->nb_rx_queues; i++) {
161 rxq = dev->data->rx_queues[i];
162 axgbe_prepare_rx_stop(pdata, i);
164 /* Disable each Rx queue */
165 AXGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
166 for (i = 0; i < dev->data->nb_rx_queues; i++) {
167 rxq = dev->data->rx_queues[i];
168 /* Disable Rx DMA channel */
169 AXGMAC_DMA_IOWRITE_BITS(rxq, DMA_CH_RCR, SR, 0);
173 void axgbe_dev_enable_rx(struct rte_eth_dev *dev)
175 struct axgbe_rx_queue *rxq;
176 struct axgbe_port *pdata = dev->data->dev_private;
178 unsigned int reg_val = 0;
180 for (i = 0; i < dev->data->nb_rx_queues; i++) {
181 rxq = dev->data->rx_queues[i];
182 /* Enable Rx DMA channel */
183 AXGMAC_DMA_IOWRITE_BITS(rxq, DMA_CH_RCR, SR, 1);
187 for (i = 0; i < pdata->rx_q_count; i++)
188 reg_val |= (0x02 << (i << 1));
189 AXGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
192 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
193 /* Frame is forwarded after stripping CRC to application*/
194 if (pdata->crc_strip_enable) {
195 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
196 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
198 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
201 /* Rx function one to one refresh */
203 axgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
206 PMD_INIT_FUNC_TRACE();
208 struct axgbe_rx_queue *rxq = rx_queue;
209 volatile union axgbe_rx_desc *desc;
210 uint64_t old_dirty = rxq->dirty;
211 struct rte_mbuf *mbuf, *tmbuf;
213 uint32_t error_status;
214 uint16_t idx, pidx, pkt_len;
216 idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
217 while (nb_rx < nb_pkts) {
218 if (unlikely(idx == rxq->nb_desc))
221 desc = &rxq->desc[idx];
223 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
225 tmbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
226 if (unlikely(!tmbuf)) {
227 PMD_DRV_LOG(ERR, "RX mbuf alloc failed port_id = %u"
229 (unsigned int)rxq->port_id,
230 (unsigned int)rxq->queue_id);
232 rxq->port_id].data->rx_mbuf_alloc_failed++;
233 rxq->rx_mbuf_alloc_failed++;
237 if (unlikely(pidx == rxq->nb_desc))
240 rte_prefetch0(rxq->sw_ring[pidx]);
241 if ((pidx & 0x3) == 0) {
242 rte_prefetch0(&rxq->desc[pidx]);
243 rte_prefetch0(&rxq->sw_ring[pidx]);
246 mbuf = rxq->sw_ring[idx];
247 /* Check for any errors and free mbuf*/
248 err = AXGMAC_GET_BITS_LE(desc->write.desc3,
249 RX_NORMAL_DESC3, ES);
252 error_status = desc->write.desc3 & AXGBE_ERR_STATUS;
253 if ((error_status != AXGBE_L3_CSUM_ERR) &&
254 (error_status != AXGBE_L4_CSUM_ERR)) {
256 rte_pktmbuf_free(mbuf);
260 if (rxq->pdata->rx_csum_enable) {
262 mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
263 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
264 if (unlikely(error_status == AXGBE_L3_CSUM_ERR)) {
265 mbuf->ol_flags &= ~PKT_RX_IP_CKSUM_GOOD;
266 mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD;
267 mbuf->ol_flags &= ~PKT_RX_L4_CKSUM_GOOD;
268 mbuf->ol_flags |= PKT_RX_L4_CKSUM_UNKNOWN;
270 unlikely(error_status == AXGBE_L4_CSUM_ERR)) {
271 mbuf->ol_flags &= ~PKT_RX_L4_CKSUM_GOOD;
272 mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD;
275 rte_prefetch1(rte_pktmbuf_mtod(mbuf, void *));
276 /* Get the RSS hash */
277 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, RSV))
278 mbuf->hash.rss = rte_le_to_cpu_32(desc->write.desc1);
279 /* Indicate if a Context Descriptor is next */
280 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CDA))
281 mbuf->ol_flags |= PKT_RX_IEEE1588_PTP
282 | PKT_RX_IEEE1588_TMST;
283 pkt_len = AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3,
287 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
289 mbuf->port = rxq->port_id;
290 mbuf->pkt_len = pkt_len;
291 mbuf->data_len = pkt_len;
292 rxq->bytes += pkt_len;
293 rx_pkts[nb_rx++] = mbuf;
296 rxq->sw_ring[idx++] = tmbuf;
298 rte_cpu_to_le_64(rte_mbuf_data_iova_default(tmbuf));
299 memset((void *)(&desc->read.desc2), 0, 8);
300 AXGMAC_SET_BITS_LE(desc->read.desc3, RX_NORMAL_DESC3, OWN, 1);
304 if (rxq->dirty != old_dirty) {
306 idx = AXGBE_GET_DESC_IDX(rxq, rxq->dirty - 1);
307 AXGMAC_DMA_IOWRITE(rxq, DMA_CH_RDTR_LO,
308 low32_value(rxq->ring_phys_addr +
309 (idx * sizeof(union axgbe_rx_desc))));
316 uint16_t eth_axgbe_recv_scattered_pkts(void *rx_queue,
317 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
319 PMD_INIT_FUNC_TRACE();
321 struct axgbe_rx_queue *rxq = rx_queue;
322 volatile union axgbe_rx_desc *desc;
324 uint64_t old_dirty = rxq->dirty;
325 struct rte_mbuf *first_seg = NULL;
326 struct rte_mbuf *mbuf, *tmbuf;
328 uint32_t error_status;
329 uint16_t idx, pidx, data_len = 0, pkt_len = 0;
331 idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
332 while (nb_rx < nb_pkts) {
335 if (unlikely(idx == rxq->nb_desc))
338 desc = &rxq->desc[idx];
340 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
343 tmbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
344 if (unlikely(!tmbuf)) {
345 PMD_DRV_LOG(ERR, "RX mbuf alloc failed port_id = %u"
347 (unsigned int)rxq->port_id,
348 (unsigned int)rxq->queue_id);
349 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
354 if (unlikely(pidx == rxq->nb_desc))
357 rte_prefetch0(rxq->sw_ring[pidx]);
358 if ((pidx & 0x3) == 0) {
359 rte_prefetch0(&rxq->desc[pidx]);
360 rte_prefetch0(&rxq->sw_ring[pidx]);
363 mbuf = rxq->sw_ring[idx];
364 /* Check for any errors and free mbuf*/
365 err = AXGMAC_GET_BITS_LE(desc->write.desc3,
366 RX_NORMAL_DESC3, ES);
369 error_status = desc->write.desc3 & AXGBE_ERR_STATUS;
370 if ((error_status != AXGBE_L3_CSUM_ERR)
371 && (error_status != AXGBE_L4_CSUM_ERR)) {
373 rte_pktmbuf_free(mbuf);
377 rte_prefetch1(rte_pktmbuf_mtod(mbuf, void *));
379 if (!AXGMAC_GET_BITS_LE(desc->write.desc3,
380 RX_NORMAL_DESC3, LD)) {
382 pkt_len = rxq->buf_size;
386 pkt_len = AXGMAC_GET_BITS_LE(desc->write.desc3,
387 RX_NORMAL_DESC3, PL);
388 data_len = pkt_len - rxq->crc_len;
391 if (first_seg != NULL) {
392 if (rte_pktmbuf_chain(first_seg, mbuf) != 0)
393 rte_mempool_put(rxq->mb_pool,
399 /* Get the RSS hash */
400 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, RSV))
401 mbuf->hash.rss = rte_le_to_cpu_32(desc->write.desc1);
404 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
405 mbuf->data_len = data_len;
409 rxq->sw_ring[idx++] = tmbuf;
411 rte_cpu_to_le_64(rte_mbuf_data_iova_default(tmbuf));
412 memset((void *)(&desc->read.desc2), 0, 8);
413 AXGMAC_SET_BITS_LE(desc->read.desc3, RX_NORMAL_DESC3, OWN, 1);
417 rte_pktmbuf_free(mbuf);
421 first_seg->pkt_len = pkt_len;
422 rxq->bytes += pkt_len;
425 first_seg->port = rxq->port_id;
426 if (rxq->pdata->rx_csum_enable) {
428 mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
429 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
430 if (unlikely(error_status == AXGBE_L3_CSUM_ERR)) {
431 mbuf->ol_flags &= ~PKT_RX_IP_CKSUM_GOOD;
432 mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD;
433 mbuf->ol_flags &= ~PKT_RX_L4_CKSUM_GOOD;
434 mbuf->ol_flags |= PKT_RX_L4_CKSUM_UNKNOWN;
435 } else if (unlikely(error_status
436 == AXGBE_L4_CSUM_ERR)) {
437 mbuf->ol_flags &= ~PKT_RX_L4_CKSUM_GOOD;
438 mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD;
442 rx_pkts[nb_rx++] = first_seg;
444 /* Setup receipt context for a new packet.*/
448 /* Save receive context.*/
451 if (rxq->dirty != old_dirty) {
453 idx = AXGBE_GET_DESC_IDX(rxq, rxq->dirty - 1);
454 AXGMAC_DMA_IOWRITE(rxq, DMA_CH_RDTR_LO,
455 low32_value(rxq->ring_phys_addr +
456 (idx * sizeof(union axgbe_rx_desc))));
462 static void axgbe_tx_queue_release(struct axgbe_tx_queue *tx_queue)
465 struct rte_mbuf **sw_ring;
468 sw_ring = tx_queue->sw_ring;
470 for (i = 0; i < tx_queue->nb_desc; i++) {
472 rte_pktmbuf_free(sw_ring[i]);
480 void axgbe_dev_tx_queue_release(void *txq)
482 axgbe_tx_queue_release(txq);
485 int axgbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
486 uint16_t nb_desc, unsigned int socket_id,
487 const struct rte_eth_txconf *tx_conf)
489 PMD_INIT_FUNC_TRACE();
491 struct axgbe_port *pdata;
492 struct axgbe_tx_queue *txq;
494 const struct rte_memzone *tz;
497 pdata = dev->data->dev_private;
500 * validate tx descriptors count
501 * should be power of 2 and less than h/w supported
503 if ((!rte_is_power_of_2(tx_desc)) ||
504 tx_desc > pdata->tx_desc_count ||
505 tx_desc < AXGBE_MIN_RING_DESC)
508 /* First allocate the tx queue data structure */
509 txq = rte_zmalloc("ethdev TX queue", sizeof(struct axgbe_tx_queue),
510 RTE_CACHE_LINE_SIZE);
515 txq->nb_desc = tx_desc;
516 txq->free_thresh = tx_conf->tx_free_thresh ?
517 tx_conf->tx_free_thresh : AXGBE_TX_FREE_THRESH;
518 if (txq->free_thresh > txq->nb_desc)
519 txq->free_thresh = (txq->nb_desc >> 1);
520 txq->free_batch_cnt = txq->free_thresh;
522 /* In vector_tx path threshold should be multiple of queue_size*/
523 if (txq->nb_desc % txq->free_thresh != 0)
524 txq->vector_disable = 1;
526 if (tx_conf->offloads != 0)
527 txq->vector_disable = 1;
529 /* Allocate TX ring hardware descriptors */
530 tsize = txq->nb_desc * sizeof(struct axgbe_tx_desc);
531 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
532 tsize, AXGBE_DESC_ALIGN, socket_id);
534 axgbe_tx_queue_release(txq);
537 memset(tz->addr, 0, tsize);
538 txq->ring_phys_addr = (uint64_t)tz->iova;
539 txq->desc = tz->addr;
540 txq->queue_id = queue_idx;
541 txq->port_id = dev->data->port_id;
542 txq->dma_regs = (void *)((uint8_t *)pdata->xgmac_regs + DMA_CH_BASE +
543 (DMA_CH_INC * txq->queue_id));
544 txq->dma_tail_reg = (volatile uint32_t *)((uint8_t *)txq->dma_regs +
548 txq->nb_desc_free = txq->nb_desc;
549 /* Allocate software ring */
550 tsize = txq->nb_desc * sizeof(struct rte_mbuf *);
551 txq->sw_ring = rte_zmalloc("tx_sw_ring", tsize,
552 RTE_CACHE_LINE_SIZE);
554 axgbe_tx_queue_release(txq);
557 dev->data->tx_queues[queue_idx] = txq;
558 if (!pdata->tx_queues)
559 pdata->tx_queues = dev->data->tx_queues;
561 if (txq->vector_disable ||
562 rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
563 dev->tx_pkt_burst = &axgbe_xmit_pkts;
566 dev->tx_pkt_burst = &axgbe_xmit_pkts_vec;
568 dev->tx_pkt_burst = &axgbe_xmit_pkts;
574 static void axgbe_txq_prepare_tx_stop(struct axgbe_port *pdata,
577 unsigned int tx_status;
578 unsigned long tx_timeout;
580 /* The Tx engine cannot be stopped if it is actively processing
581 * packets. Wait for the Tx queue to empty the Tx fifo. Don't
582 * wait forever though...
584 tx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
586 while (time_before(rte_get_timer_cycles(), tx_timeout)) {
587 tx_status = AXGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
588 if ((AXGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
589 (AXGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
595 if (!time_before(rte_get_timer_cycles(), tx_timeout))
597 "timed out waiting for Tx queue %u to empty\n",
601 static void axgbe_prepare_tx_stop(struct axgbe_port *pdata,
604 unsigned int tx_dsr, tx_pos, tx_qidx;
605 unsigned int tx_status;
606 unsigned long tx_timeout;
608 if (AXGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
609 return axgbe_txq_prepare_tx_stop(pdata, queue);
611 /* Calculate the status register to read and the position within */
612 if (queue < DMA_DSRX_FIRST_QUEUE) {
614 tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
616 tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
618 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
619 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
623 /* The Tx engine cannot be stopped if it is actively processing
624 * descriptors. Wait for the Tx engine to enter the stopped or
625 * suspended state. Don't wait forever though...
627 tx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
629 while (time_before(rte_get_timer_cycles(), tx_timeout)) {
630 tx_status = AXGMAC_IOREAD(pdata, tx_dsr);
631 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
632 if ((tx_status == DMA_TPS_STOPPED) ||
633 (tx_status == DMA_TPS_SUSPENDED))
639 if (!time_before(rte_get_timer_cycles(), tx_timeout))
641 "timed out waiting for Tx DMA channel %u to stop\n",
645 void axgbe_dev_disable_tx(struct rte_eth_dev *dev)
647 struct axgbe_tx_queue *txq;
648 struct axgbe_port *pdata = dev->data->dev_private;
651 /* Prepare for stopping DMA channel */
652 for (i = 0; i < pdata->tx_q_count; i++) {
653 txq = dev->data->tx_queues[i];
654 axgbe_prepare_tx_stop(pdata, i);
657 AXGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
658 /* Disable each Tx queue*/
659 for (i = 0; i < pdata->tx_q_count; i++)
660 AXGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
662 /* Disable each Tx DMA channel */
663 for (i = 0; i < dev->data->nb_tx_queues; i++) {
664 txq = dev->data->tx_queues[i];
665 AXGMAC_DMA_IOWRITE_BITS(txq, DMA_CH_TCR, ST, 0);
669 void axgbe_dev_enable_tx(struct rte_eth_dev *dev)
671 struct axgbe_tx_queue *txq;
672 struct axgbe_port *pdata = dev->data->dev_private;
675 for (i = 0; i < dev->data->nb_tx_queues; i++) {
676 txq = dev->data->tx_queues[i];
677 /* Enable Tx DMA channel */
678 AXGMAC_DMA_IOWRITE_BITS(txq, DMA_CH_TCR, ST, 1);
681 for (i = 0; i < pdata->tx_q_count; i++)
682 AXGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
685 AXGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
688 /* Free Tx conformed mbufs */
689 static void axgbe_xmit_cleanup(struct axgbe_tx_queue *txq)
691 volatile struct axgbe_tx_desc *desc;
694 idx = AXGBE_GET_DESC_IDX(txq, txq->dirty);
695 while (txq->cur != txq->dirty) {
696 if (unlikely(idx == txq->nb_desc))
698 desc = &txq->desc[idx];
699 /* Check for ownership */
700 if (AXGMAC_GET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN))
702 memset((void *)&desc->desc2, 0, 8);
704 rte_pktmbuf_free(txq->sw_ring[idx]);
705 txq->sw_ring[idx++] = NULL;
710 /* Tx Descriptor formation
711 * Considering each mbuf requires one desc
714 static int axgbe_xmit_hw(struct axgbe_tx_queue *txq,
715 struct rte_mbuf *mbuf)
717 volatile struct axgbe_tx_desc *desc;
721 idx = AXGBE_GET_DESC_IDX(txq, txq->cur);
722 desc = &txq->desc[idx];
724 /* Update buffer address and length */
725 desc->baddr = rte_mbuf_data_iova(mbuf);
726 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, HL_B1L,
728 /* Total msg length to transmit */
729 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, FL,
731 /* Timestamp enablement check */
732 if (mbuf->ol_flags & PKT_TX_IEEE1588_TMST)
733 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, TTSE, 1);
735 /* Mark it as First and Last Descriptor */
736 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, FD, 1);
737 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, LD, 1);
738 /* Mark it as a NORMAL descriptor */
739 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CTXT, 0);
740 /* configure h/w Offload */
741 mask = mbuf->ol_flags & PKT_TX_L4_MASK;
742 if ((mask == PKT_TX_TCP_CKSUM) || (mask == PKT_TX_UDP_CKSUM))
743 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CIC, 0x3);
744 else if (mbuf->ol_flags & PKT_TX_IP_CKSUM)
745 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CIC, 0x1);
749 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN, 1);
753 txq->sw_ring[idx] = mbuf;
754 /* Update current index*/
757 txq->bytes += mbuf->pkt_len;
762 /* Eal supported tx wrapper*/
764 axgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
767 PMD_INIT_FUNC_TRACE();
769 if (unlikely(nb_pkts == 0))
772 struct axgbe_tx_queue *txq;
773 uint16_t nb_desc_free;
774 uint16_t nb_pkt_sent = 0;
777 struct rte_mbuf *mbuf;
779 txq = (struct axgbe_tx_queue *)tx_queue;
780 nb_desc_free = txq->nb_desc - (txq->cur - txq->dirty);
782 if (unlikely(nb_desc_free <= txq->free_thresh)) {
783 axgbe_xmit_cleanup(txq);
784 nb_desc_free = txq->nb_desc - (txq->cur - txq->dirty);
785 if (unlikely(nb_desc_free == 0))
788 nb_pkts = RTE_MIN(nb_desc_free, nb_pkts);
791 if (axgbe_xmit_hw(txq, mbuf))
796 /* Sync read and write */
798 idx = AXGBE_GET_DESC_IDX(txq, txq->cur);
799 tail_addr = low32_value(txq->ring_phys_addr +
800 idx * sizeof(struct axgbe_tx_desc));
801 /* Update tail reg with next immediate address to kick Tx DMA channel*/
802 AXGMAC_DMA_IOWRITE(txq, DMA_CH_TDTR_LO, tail_addr);
803 txq->pkts += nb_pkt_sent;
807 void axgbe_dev_clear_queues(struct rte_eth_dev *dev)
809 PMD_INIT_FUNC_TRACE();
811 struct axgbe_rx_queue *rxq;
812 struct axgbe_tx_queue *txq;
814 for (i = 0; i < dev->data->nb_rx_queues; i++) {
815 rxq = dev->data->rx_queues[i];
818 axgbe_rx_queue_release(rxq);
819 dev->data->rx_queues[i] = NULL;
823 for (i = 0; i < dev->data->nb_tx_queues; i++) {
824 txq = dev->data->tx_queues[i];
827 axgbe_tx_queue_release(txq);
828 dev->data->tx_queues[i] = NULL;
834 axgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
836 struct axgbe_rx_queue *rxq = rx_queue;
837 volatile union axgbe_rx_desc *desc;
841 if (unlikely(offset >= rxq->nb_desc))
844 if (offset >= rxq->nb_desc - rxq->dirty)
845 return RTE_ETH_RX_DESC_UNAVAIL;
847 idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
848 desc = &rxq->desc[idx + offset];
850 if (!AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
851 return RTE_ETH_RX_DESC_DONE;
853 return RTE_ETH_RX_DESC_AVAIL;
857 axgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
859 struct axgbe_tx_queue *txq = tx_queue;
860 volatile struct axgbe_tx_desc *desc;
864 if (unlikely(offset >= txq->nb_desc))
867 if (offset >= txq->nb_desc - txq->dirty)
868 return RTE_ETH_TX_DESC_UNAVAIL;
870 idx = AXGBE_GET_DESC_IDX(txq, txq->dirty + txq->free_batch_cnt - 1);
871 desc = &txq->desc[idx + offset];
873 if (!AXGMAC_GET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN))
874 return RTE_ETH_TX_DESC_DONE;
876 return RTE_ETH_TX_DESC_FULL;