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++) {
25 rte_pktmbuf_free(sw_ring[i]);
33 void axgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx)
35 axgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
38 int axgbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
39 uint16_t nb_desc, unsigned int socket_id,
40 const struct rte_eth_rxconf *rx_conf,
41 struct rte_mempool *mp)
43 PMD_INIT_FUNC_TRACE();
45 const struct rte_memzone *dma;
46 struct axgbe_rx_queue *rxq;
47 uint32_t rx_desc = nb_desc;
48 struct axgbe_port *pdata = dev->data->dev_private;
51 * validate Rx descriptors count
52 * should be power of 2 and less than h/w supported
54 if ((!rte_is_power_of_2(rx_desc)) ||
55 rx_desc > pdata->rx_desc_count)
57 /* First allocate the rx queue data structure */
58 rxq = rte_zmalloc_socket("ethdev RX queue",
59 sizeof(struct axgbe_rx_queue),
60 RTE_CACHE_LINE_SIZE, socket_id);
62 PMD_INIT_LOG(ERR, "rte_zmalloc for rxq failed!");
70 rxq->queue_id = queue_idx;
71 rxq->port_id = dev->data->port_id;
72 rxq->nb_desc = rx_desc;
73 rxq->dma_regs = (void *)((uint8_t *)pdata->xgmac_regs + DMA_CH_BASE +
74 (DMA_CH_INC * rxq->queue_id));
75 rxq->dma_tail_reg = (volatile uint32_t *)((uint8_t *)rxq->dma_regs +
77 if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
78 rxq->crc_len = RTE_ETHER_CRC_LEN;
82 /* CRC strip in AXGBE supports per port not per queue */
83 pdata->crc_strip_enable = (rxq->crc_len == 0) ? 1 : 0;
84 rxq->free_thresh = rx_conf->rx_free_thresh ?
85 rx_conf->rx_free_thresh : AXGBE_RX_FREE_THRESH;
86 if (rxq->free_thresh > rxq->nb_desc)
87 rxq->free_thresh = rxq->nb_desc >> 3;
89 /* Allocate RX ring hardware descriptors */
90 size = rxq->nb_desc * sizeof(union axgbe_rx_desc);
91 dma = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size, 128,
94 PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for rx_ring failed\n");
95 axgbe_rx_queue_release(rxq);
98 rxq->ring_phys_addr = (uint64_t)dma->iova;
99 rxq->desc = (volatile union axgbe_rx_desc *)dma->addr;
100 memset((void *)rxq->desc, 0, size);
101 /* Allocate software ring */
102 size = rxq->nb_desc * sizeof(struct rte_mbuf *);
103 rxq->sw_ring = rte_zmalloc_socket("sw_ring", size,
107 PMD_DRV_LOG(ERR, "rte_zmalloc for sw_ring failed\n");
108 axgbe_rx_queue_release(rxq);
111 dev->data->rx_queues[queue_idx] = rxq;
112 if (!pdata->rx_queues)
113 pdata->rx_queues = dev->data->rx_queues;
118 static void axgbe_prepare_rx_stop(struct axgbe_port *pdata,
121 unsigned int rx_status;
122 unsigned long rx_timeout;
124 /* The Rx engine cannot be stopped if it is actively processing
125 * packets. Wait for the Rx queue to empty the Rx fifo. Don't
126 * wait forever though...
128 rx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
131 while (time_before(rte_get_timer_cycles(), rx_timeout)) {
132 rx_status = AXGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
133 if ((AXGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
134 (AXGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
140 if (!time_before(rte_get_timer_cycles(), rx_timeout))
142 "timed out waiting for Rx queue %u to empty\n",
146 void axgbe_dev_disable_rx(struct rte_eth_dev *dev)
148 struct axgbe_rx_queue *rxq;
149 struct axgbe_port *pdata = dev->data->dev_private;
153 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
154 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
155 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
156 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
158 /* Prepare for Rx DMA channel stop */
159 for (i = 0; i < dev->data->nb_rx_queues; i++) {
160 rxq = dev->data->rx_queues[i];
161 axgbe_prepare_rx_stop(pdata, i);
163 /* Disable each Rx queue */
164 AXGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
165 for (i = 0; i < dev->data->nb_rx_queues; i++) {
166 rxq = dev->data->rx_queues[i];
167 /* Disable Rx DMA channel */
168 AXGMAC_DMA_IOWRITE_BITS(rxq, DMA_CH_RCR, SR, 0);
172 void axgbe_dev_enable_rx(struct rte_eth_dev *dev)
174 struct axgbe_rx_queue *rxq;
175 struct axgbe_port *pdata = dev->data->dev_private;
177 unsigned int reg_val = 0;
179 for (i = 0; i < dev->data->nb_rx_queues; i++) {
180 rxq = dev->data->rx_queues[i];
181 /* Enable Rx DMA channel */
182 AXGMAC_DMA_IOWRITE_BITS(rxq, DMA_CH_RCR, SR, 1);
186 for (i = 0; i < pdata->rx_q_count; i++)
187 reg_val |= (0x02 << (i << 1));
188 AXGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
191 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
192 /* Frame is forwarded after stripping CRC to application*/
193 if (pdata->crc_strip_enable) {
194 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
195 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
197 AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
200 /* Rx function one to one refresh */
202 axgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
205 PMD_INIT_FUNC_TRACE();
207 struct axgbe_rx_queue *rxq = rx_queue;
208 volatile union axgbe_rx_desc *desc;
209 uint64_t old_dirty = rxq->dirty;
210 struct rte_mbuf *mbuf, *tmbuf;
211 unsigned int err, etlt;
212 uint32_t error_status;
213 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 |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
263 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
264 if (unlikely(error_status == AXGBE_L3_CSUM_ERR)) {
265 mbuf->ol_flags &= ~RTE_MBUF_F_RX_IP_CKSUM_GOOD;
266 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
267 mbuf->ol_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_GOOD;
268 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN;
270 unlikely(error_status == AXGBE_L4_CSUM_ERR)) {
271 mbuf->ol_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_GOOD;
272 mbuf->ol_flags |= RTE_MBUF_F_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 etlt = AXGMAC_GET_BITS_LE(desc->write.desc3,
280 RX_NORMAL_DESC3, ETLT);
281 offloads = rxq->pdata->eth_dev->data->dev_conf.rxmode.offloads;
283 if (etlt == RX_CVLAN_TAG_PRESENT) {
284 mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN;
286 AXGMAC_GET_BITS_LE(desc->write.desc0,
287 RX_NORMAL_DESC0, OVT);
288 if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
289 mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
291 mbuf->ol_flags &= ~RTE_MBUF_F_RX_VLAN_STRIPPED;
294 ~(RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED);
298 /* Indicate if a Context Descriptor is next */
299 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CDA))
300 mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP
301 | RTE_MBUF_F_RX_IEEE1588_TMST;
302 pkt_len = AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3,
306 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
308 mbuf->port = rxq->port_id;
309 mbuf->pkt_len = pkt_len;
310 mbuf->data_len = pkt_len;
311 rxq->bytes += pkt_len;
312 rx_pkts[nb_rx++] = mbuf;
315 rxq->sw_ring[idx++] = tmbuf;
317 rte_cpu_to_le_64(rte_mbuf_data_iova_default(tmbuf));
318 memset((void *)(&desc->read.desc2), 0, 8);
319 AXGMAC_SET_BITS_LE(desc->read.desc3, RX_NORMAL_DESC3, OWN, 1);
323 if (rxq->dirty != old_dirty) {
325 idx = AXGBE_GET_DESC_IDX(rxq, rxq->dirty - 1);
326 AXGMAC_DMA_IOWRITE(rxq, DMA_CH_RDTR_LO,
327 low32_value(rxq->ring_phys_addr +
328 (idx * sizeof(union axgbe_rx_desc))));
335 uint16_t eth_axgbe_recv_scattered_pkts(void *rx_queue,
336 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
338 PMD_INIT_FUNC_TRACE();
340 struct axgbe_rx_queue *rxq = rx_queue;
341 volatile union axgbe_rx_desc *desc;
343 uint64_t old_dirty = rxq->dirty;
344 struct rte_mbuf *first_seg = NULL;
345 struct rte_mbuf *mbuf, *tmbuf;
346 unsigned int err, etlt;
347 uint32_t error_status;
348 uint16_t idx, pidx, data_len = 0, pkt_len = 0;
351 idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
352 while (nb_rx < nb_pkts) {
355 if (unlikely(idx == rxq->nb_desc))
358 desc = &rxq->desc[idx];
360 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
363 tmbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
364 if (unlikely(!tmbuf)) {
365 PMD_DRV_LOG(ERR, "RX mbuf alloc failed port_id = %u"
367 (unsigned int)rxq->port_id,
368 (unsigned int)rxq->queue_id);
369 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
374 if (unlikely(pidx == rxq->nb_desc))
377 rte_prefetch0(rxq->sw_ring[pidx]);
378 if ((pidx & 0x3) == 0) {
379 rte_prefetch0(&rxq->desc[pidx]);
380 rte_prefetch0(&rxq->sw_ring[pidx]);
383 mbuf = rxq->sw_ring[idx];
384 /* Check for any errors and free mbuf*/
385 err = AXGMAC_GET_BITS_LE(desc->write.desc3,
386 RX_NORMAL_DESC3, ES);
389 error_status = desc->write.desc3 & AXGBE_ERR_STATUS;
390 if ((error_status != AXGBE_L3_CSUM_ERR)
391 && (error_status != AXGBE_L4_CSUM_ERR)) {
393 rte_pktmbuf_free(mbuf);
397 rte_prefetch1(rte_pktmbuf_mtod(mbuf, void *));
399 if (!AXGMAC_GET_BITS_LE(desc->write.desc3,
400 RX_NORMAL_DESC3, LD)) {
402 pkt_len = rxq->buf_size;
406 pkt_len = AXGMAC_GET_BITS_LE(desc->write.desc3,
407 RX_NORMAL_DESC3, PL);
408 data_len = pkt_len - rxq->crc_len;
411 if (first_seg != NULL) {
412 if (rte_pktmbuf_chain(first_seg, mbuf) != 0)
413 rte_mempool_put(rxq->mb_pool,
419 /* Get the RSS hash */
420 if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, RSV))
421 mbuf->hash.rss = rte_le_to_cpu_32(desc->write.desc1);
422 etlt = AXGMAC_GET_BITS_LE(desc->write.desc3,
423 RX_NORMAL_DESC3, ETLT);
424 offloads = rxq->pdata->eth_dev->data->dev_conf.rxmode.offloads;
426 if (etlt == RX_CVLAN_TAG_PRESENT) {
427 mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN;
429 AXGMAC_GET_BITS_LE(desc->write.desc0,
430 RX_NORMAL_DESC0, OVT);
431 if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
432 mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
434 mbuf->ol_flags &= ~RTE_MBUF_F_RX_VLAN_STRIPPED;
437 ~(RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED);
442 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
443 mbuf->data_len = data_len;
447 rxq->sw_ring[idx++] = tmbuf;
449 rte_cpu_to_le_64(rte_mbuf_data_iova_default(tmbuf));
450 memset((void *)(&desc->read.desc2), 0, 8);
451 AXGMAC_SET_BITS_LE(desc->read.desc3, RX_NORMAL_DESC3, OWN, 1);
455 rte_pktmbuf_free(mbuf);
459 first_seg->pkt_len = pkt_len;
460 rxq->bytes += pkt_len;
463 first_seg->port = rxq->port_id;
464 if (rxq->pdata->rx_csum_enable) {
466 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
467 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
468 if (unlikely(error_status == AXGBE_L3_CSUM_ERR)) {
469 mbuf->ol_flags &= ~RTE_MBUF_F_RX_IP_CKSUM_GOOD;
470 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
471 mbuf->ol_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_GOOD;
472 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN;
473 } else if (unlikely(error_status
474 == AXGBE_L4_CSUM_ERR)) {
475 mbuf->ol_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_GOOD;
476 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
480 rx_pkts[nb_rx++] = first_seg;
482 /* Setup receipt context for a new packet.*/
486 /* Save receive context.*/
489 if (rxq->dirty != old_dirty) {
491 idx = AXGBE_GET_DESC_IDX(rxq, rxq->dirty - 1);
492 AXGMAC_DMA_IOWRITE(rxq, DMA_CH_RDTR_LO,
493 low32_value(rxq->ring_phys_addr +
494 (idx * sizeof(union axgbe_rx_desc))));
500 static void axgbe_tx_queue_release(struct axgbe_tx_queue *tx_queue)
503 struct rte_mbuf **sw_ring;
506 sw_ring = tx_queue->sw_ring;
508 for (i = 0; i < tx_queue->nb_desc; i++) {
509 rte_pktmbuf_free(sw_ring[i]);
517 void axgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx)
519 axgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
522 int axgbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
523 uint16_t nb_desc, unsigned int socket_id,
524 const struct rte_eth_txconf *tx_conf)
526 PMD_INIT_FUNC_TRACE();
528 struct axgbe_port *pdata;
529 struct axgbe_tx_queue *txq;
531 const struct rte_memzone *tz;
535 pdata = dev->data->dev_private;
538 * validate tx descriptors count
539 * should be power of 2 and less than h/w supported
541 if ((!rte_is_power_of_2(tx_desc)) ||
542 tx_desc > pdata->tx_desc_count ||
543 tx_desc < AXGBE_MIN_RING_DESC)
546 /* First allocate the tx queue data structure */
547 txq = rte_zmalloc("ethdev TX queue", sizeof(struct axgbe_tx_queue),
548 RTE_CACHE_LINE_SIZE);
552 offloads = tx_conf->offloads |
553 txq->pdata->eth_dev->data->dev_conf.txmode.offloads;
554 txq->nb_desc = tx_desc;
555 txq->free_thresh = tx_conf->tx_free_thresh ?
556 tx_conf->tx_free_thresh : AXGBE_TX_FREE_THRESH;
557 if (txq->free_thresh > txq->nb_desc)
558 txq->free_thresh = (txq->nb_desc >> 1);
559 txq->free_batch_cnt = txq->free_thresh;
561 /* In vector_tx path threshold should be multiple of queue_size*/
562 if (txq->nb_desc % txq->free_thresh != 0)
563 txq->vector_disable = 1;
566 txq->vector_disable = 1;
568 /* Allocate TX ring hardware descriptors */
569 tsize = txq->nb_desc * sizeof(struct axgbe_tx_desc);
570 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
571 tsize, AXGBE_DESC_ALIGN, socket_id);
573 axgbe_tx_queue_release(txq);
576 memset(tz->addr, 0, tsize);
577 txq->ring_phys_addr = (uint64_t)tz->iova;
578 txq->desc = tz->addr;
579 txq->queue_id = queue_idx;
580 txq->port_id = dev->data->port_id;
581 txq->dma_regs = (void *)((uint8_t *)pdata->xgmac_regs + DMA_CH_BASE +
582 (DMA_CH_INC * txq->queue_id));
583 txq->dma_tail_reg = (volatile uint32_t *)((uint8_t *)txq->dma_regs +
587 txq->nb_desc_free = txq->nb_desc;
588 /* Allocate software ring */
589 tsize = txq->nb_desc * sizeof(struct rte_mbuf *);
590 txq->sw_ring = rte_zmalloc("tx_sw_ring", tsize,
591 RTE_CACHE_LINE_SIZE);
593 axgbe_tx_queue_release(txq);
596 dev->data->tx_queues[queue_idx] = txq;
597 if (!pdata->tx_queues)
598 pdata->tx_queues = dev->data->tx_queues;
600 if (txq->vector_disable ||
601 rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
602 dev->tx_pkt_burst = &axgbe_xmit_pkts;
605 dev->tx_pkt_burst = &axgbe_xmit_pkts_vec;
607 dev->tx_pkt_burst = &axgbe_xmit_pkts;
613 int axgbe_dev_fw_version_get(struct rte_eth_dev *eth_dev,
614 char *fw_version, size_t fw_size)
616 struct axgbe_port *pdata;
617 struct axgbe_hw_features *hw_feat;
620 pdata = (struct axgbe_port *)eth_dev->data->dev_private;
621 hw_feat = &pdata->hw_feat;
623 ret = snprintf(fw_version, fw_size, "%d.%d.%d",
624 AXGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
625 AXGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
626 AXGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
630 ret += 1; /* add the size of '\0' */
631 if (fw_size < (size_t)ret)
637 static void axgbe_txq_prepare_tx_stop(struct axgbe_port *pdata,
640 unsigned int tx_status;
641 unsigned long tx_timeout;
643 /* The Tx engine cannot be stopped if it is actively processing
644 * packets. Wait for the Tx queue to empty the Tx fifo. Don't
645 * wait forever though...
647 tx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
649 while (time_before(rte_get_timer_cycles(), tx_timeout)) {
650 tx_status = AXGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
651 if ((AXGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
652 (AXGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
658 if (!time_before(rte_get_timer_cycles(), tx_timeout))
660 "timed out waiting for Tx queue %u to empty\n",
664 static void axgbe_prepare_tx_stop(struct axgbe_port *pdata,
667 unsigned int tx_dsr, tx_pos, tx_qidx;
668 unsigned int tx_status;
669 unsigned long tx_timeout;
671 if (AXGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
672 return axgbe_txq_prepare_tx_stop(pdata, queue);
674 /* Calculate the status register to read and the position within */
675 if (queue < DMA_DSRX_FIRST_QUEUE) {
677 tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
679 tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
681 tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
682 tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
686 /* The Tx engine cannot be stopped if it is actively processing
687 * descriptors. Wait for the Tx engine to enter the stopped or
688 * suspended state. Don't wait forever though...
690 tx_timeout = rte_get_timer_cycles() + (AXGBE_DMA_STOP_TIMEOUT *
692 while (time_before(rte_get_timer_cycles(), tx_timeout)) {
693 tx_status = AXGMAC_IOREAD(pdata, tx_dsr);
694 tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
695 if ((tx_status == DMA_TPS_STOPPED) ||
696 (tx_status == DMA_TPS_SUSPENDED))
702 if (!time_before(rte_get_timer_cycles(), tx_timeout))
704 "timed out waiting for Tx DMA channel %u to stop\n",
708 void axgbe_dev_disable_tx(struct rte_eth_dev *dev)
710 struct axgbe_tx_queue *txq;
711 struct axgbe_port *pdata = dev->data->dev_private;
714 /* Prepare for stopping DMA channel */
715 for (i = 0; i < pdata->tx_q_count; i++) {
716 txq = dev->data->tx_queues[i];
717 axgbe_prepare_tx_stop(pdata, i);
720 AXGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
721 /* Disable each Tx queue*/
722 for (i = 0; i < pdata->tx_q_count; i++)
723 AXGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
725 /* Disable each Tx DMA channel */
726 for (i = 0; i < dev->data->nb_tx_queues; i++) {
727 txq = dev->data->tx_queues[i];
728 AXGMAC_DMA_IOWRITE_BITS(txq, DMA_CH_TCR, ST, 0);
732 void axgbe_dev_enable_tx(struct rte_eth_dev *dev)
734 struct axgbe_tx_queue *txq;
735 struct axgbe_port *pdata = dev->data->dev_private;
738 for (i = 0; i < dev->data->nb_tx_queues; i++) {
739 txq = dev->data->tx_queues[i];
740 /* Enable Tx DMA channel */
741 AXGMAC_DMA_IOWRITE_BITS(txq, DMA_CH_TCR, ST, 1);
744 for (i = 0; i < pdata->tx_q_count; i++)
745 AXGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
748 AXGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
751 /* Free Tx conformed mbufs */
752 static void axgbe_xmit_cleanup(struct axgbe_tx_queue *txq)
754 volatile struct axgbe_tx_desc *desc;
757 idx = AXGBE_GET_DESC_IDX(txq, txq->dirty);
758 while (txq->cur != txq->dirty) {
759 if (unlikely(idx == txq->nb_desc))
761 desc = &txq->desc[idx];
762 /* Check for ownership */
763 if (AXGMAC_GET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN))
765 memset((void *)&desc->desc2, 0, 8);
767 rte_pktmbuf_free(txq->sw_ring[idx]);
768 txq->sw_ring[idx++] = NULL;
773 /* Tx Descriptor formation
774 * Considering each mbuf requires one desc
777 static int axgbe_xmit_hw(struct axgbe_tx_queue *txq,
778 struct rte_mbuf *mbuf)
780 volatile struct axgbe_tx_desc *desc;
784 idx = AXGBE_GET_DESC_IDX(txq, txq->cur);
785 desc = &txq->desc[idx];
787 /* Update buffer address and length */
788 desc->baddr = rte_mbuf_data_iova(mbuf);
789 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, HL_B1L,
791 /* Total msg length to transmit */
792 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, FL,
794 /* Timestamp enablement check */
795 if (mbuf->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
796 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, TTSE, 1);
798 /* Mark it as First and Last Descriptor */
799 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, FD, 1);
800 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, LD, 1);
801 /* Mark it as a NORMAL descriptor */
802 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CTXT, 0);
803 /* configure h/w Offload */
804 mask = mbuf->ol_flags & RTE_MBUF_F_TX_L4_MASK;
805 if (mask == RTE_MBUF_F_TX_TCP_CKSUM || mask == RTE_MBUF_F_TX_UDP_CKSUM)
806 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CIC, 0x3);
807 else if (mbuf->ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
808 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, CIC, 0x1);
811 if (mbuf->ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
812 /* Mark it as a CONTEXT descriptor */
813 AXGMAC_SET_BITS_LE(desc->desc3, TX_CONTEXT_DESC3,
815 /* Set the VLAN tag */
816 AXGMAC_SET_BITS_LE(desc->desc3, TX_CONTEXT_DESC3,
818 /* Indicate this descriptor contains the VLAN tag */
819 AXGMAC_SET_BITS_LE(desc->desc3, TX_CONTEXT_DESC3,
821 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, VTIR,
822 TX_NORMAL_DESC2_VLAN_INSERT);
824 AXGMAC_SET_BITS_LE(desc->desc2, TX_NORMAL_DESC2, VTIR, 0x0);
829 AXGMAC_SET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN, 1);
834 txq->sw_ring[idx] = mbuf;
835 /* Update current index*/
838 txq->bytes += mbuf->pkt_len;
843 /* Eal supported tx wrapper*/
845 axgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
848 PMD_INIT_FUNC_TRACE();
850 if (unlikely(nb_pkts == 0))
853 struct axgbe_tx_queue *txq;
854 uint16_t nb_desc_free;
855 uint16_t nb_pkt_sent = 0;
858 struct rte_mbuf *mbuf;
860 txq = (struct axgbe_tx_queue *)tx_queue;
861 nb_desc_free = txq->nb_desc - (txq->cur - txq->dirty);
863 if (unlikely(nb_desc_free <= txq->free_thresh)) {
864 axgbe_xmit_cleanup(txq);
865 nb_desc_free = txq->nb_desc - (txq->cur - txq->dirty);
866 if (unlikely(nb_desc_free == 0))
869 nb_pkts = RTE_MIN(nb_desc_free, nb_pkts);
872 if (axgbe_xmit_hw(txq, mbuf))
877 /* Sync read and write */
879 idx = AXGBE_GET_DESC_IDX(txq, txq->cur);
880 tail_addr = low32_value(txq->ring_phys_addr +
881 idx * sizeof(struct axgbe_tx_desc));
882 /* Update tail reg with next immediate address to kick Tx DMA channel*/
883 AXGMAC_DMA_IOWRITE(txq, DMA_CH_TDTR_LO, tail_addr);
884 txq->pkts += nb_pkt_sent;
888 void axgbe_dev_clear_queues(struct rte_eth_dev *dev)
890 PMD_INIT_FUNC_TRACE();
892 struct axgbe_rx_queue *rxq;
893 struct axgbe_tx_queue *txq;
895 for (i = 0; i < dev->data->nb_rx_queues; i++) {
896 rxq = dev->data->rx_queues[i];
899 axgbe_rx_queue_release(rxq);
900 dev->data->rx_queues[i] = NULL;
904 for (i = 0; i < dev->data->nb_tx_queues; i++) {
905 txq = dev->data->tx_queues[i];
908 axgbe_tx_queue_release(txq);
909 dev->data->tx_queues[i] = NULL;
915 axgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
917 struct axgbe_rx_queue *rxq = rx_queue;
918 volatile union axgbe_rx_desc *desc;
922 if (unlikely(offset >= rxq->nb_desc))
925 if (offset >= rxq->nb_desc - rxq->dirty)
926 return RTE_ETH_RX_DESC_UNAVAIL;
928 idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
929 desc = &rxq->desc[idx + offset];
931 if (!AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
932 return RTE_ETH_RX_DESC_DONE;
934 return RTE_ETH_RX_DESC_AVAIL;
938 axgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
940 struct axgbe_tx_queue *txq = tx_queue;
941 volatile struct axgbe_tx_desc *desc;
945 if (unlikely(offset >= txq->nb_desc))
948 if (offset >= txq->nb_desc - txq->dirty)
949 return RTE_ETH_TX_DESC_UNAVAIL;
951 idx = AXGBE_GET_DESC_IDX(txq, txq->dirty + txq->free_batch_cnt - 1);
952 desc = &txq->desc[idx + offset];
954 if (!AXGMAC_GET_BITS_LE(desc->desc3, TX_NORMAL_DESC3, OWN))
955 return RTE_ETH_TX_DESC_DONE;
957 return RTE_ETH_TX_DESC_FULL;