DPDK patches and discussions
 help / color / mirror / Atom feed
From: <wanry@3snic.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@amd.com>, Renyong Wan <wanry@3snic.com>,
	Steven Song <steven.song@3snic.com>
Subject: [PATCH 17/32] net/sssnic: support Tx queue start and stop
Date: Tue, 29 Aug 2023 15:58:14 +0800	[thread overview]
Message-ID: <20230829075829.208413-18-wanry@3snic.com> (raw)
In-Reply-To: <20230829075829.208413-1-wanry@3snic.com>

From: Renyong Wan <wanry@3snic.com>

Signed-off-by: Steven Song <steven.song@3snic.com>
Signed-off-by: Renyong Wan <wanry@3snic.com>
---
 doc/guides/nics/features/sssnic.ini   |   1 +
 drivers/net/sssnic/sssnic_ethdev.c    |   2 +
 drivers/net/sssnic/sssnic_ethdev_tx.c | 155 ++++++++++++++++++++++++++
 drivers/net/sssnic/sssnic_ethdev_tx.h |   4 +
 4 files changed, 162 insertions(+)

diff --git a/doc/guides/nics/features/sssnic.ini b/doc/guides/nics/features/sssnic.ini
index 82b527ba26..b75c68cb33 100644
--- a/doc/guides/nics/features/sssnic.ini
+++ b/doc/guides/nics/features/sssnic.ini
@@ -6,6 +6,7 @@
 [Features]
 Link status          = Y
 Link status event    = Y
+Queue start/stop     = Y
 Unicast MAC filter   = Y
 Multicast MAC filter = Y
 Linux                = Y
diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c
index 8822e5a17b..f474aeadd8 100644
--- a/drivers/net/sssnic/sssnic_ethdev.c
+++ b/drivers/net/sssnic/sssnic_ethdev.c
@@ -361,6 +361,8 @@ static const struct eth_dev_ops sssnic_ethdev_ops = {
 	.tx_queue_release = sssnic_ethdev_tx_queue_release,
 	.rx_queue_start = sssnic_ethdev_rx_queue_start,
 	.rx_queue_stop = sssnic_ethdev_rx_queue_stop,
+	.tx_queue_start = sssnic_ethdev_tx_queue_start,
+	.tx_queue_stop = sssnic_ethdev_tx_queue_stop,
 };
 
 static int
diff --git a/drivers/net/sssnic/sssnic_ethdev_tx.c b/drivers/net/sssnic/sssnic_ethdev_tx.c
index 052bbaf777..8a2aa372c1 100644
--- a/drivers/net/sssnic/sssnic_ethdev_tx.c
+++ b/drivers/net/sssnic/sssnic_ethdev_tx.c
@@ -192,6 +192,18 @@ sssnic_ethdev_txq_ci_get(struct sssnic_ethdev_txq *txq)
 	return sssnic_workq_ci_get(txq->workq);
 }
 
+static inline int
+sssnic_ethdev_txq_pi_get(struct sssnic_ethdev_txq *txq)
+{
+	return sssnic_workq_pi_get(txq->workq);
+}
+
+static inline uint16_t
+sssnic_ethdev_txq_hw_ci_get(struct sssnic_ethdev_txq *txq)
+{
+	return *txq->hw_ci_addr & txq->idx_mask;
+}
+
 static inline void
 sssnic_ethdev_txq_consume(struct sssnic_ethdev_txq *txq, uint16_t num_entries)
 {
@@ -353,3 +365,146 @@ sssnic_ethdev_tx_queue_all_release(struct rte_eth_dev *ethdev)
 	for (qid = 0; qid < ethdev->data->nb_tx_queues; qid++)
 		sssnic_ethdev_tx_queue_release(ethdev, qid);
 }
+
+#define SSSNIC_ETHDEV_TX_FREE_BULK 64
+static inline int
+sssnic_ethdev_txq_pktmbufs_cleanup(struct sssnic_ethdev_txq *txq)
+{
+	struct sssnic_ethdev_tx_entry *txe;
+	struct rte_mbuf *free_pkts[SSSNIC_ETHDEV_TX_FREE_BULK];
+	uint16_t num_free_pkts = 0;
+	uint16_t hw_ci, ci, id_mask;
+	uint16_t count = 0;
+	int num_entries;
+
+	ci = sssnic_ethdev_txq_ci_get(txq);
+	hw_ci = sssnic_ethdev_txq_hw_ci_get(txq);
+	id_mask = txq->idx_mask;
+	num_entries = sssnic_ethdev_txq_num_used_entries(txq);
+
+	while (num_entries > 0) {
+		txe = &txq->txe[ci];
+
+		/* HW has not consumed enough entries of current packet */
+		if (((hw_ci - ci) & id_mask) < txe->num_workq_entries)
+			break;
+
+		num_entries -= txe->num_workq_entries;
+		count += txe->num_workq_entries;
+		ci = (ci + txe->num_workq_entries) & id_mask;
+
+		if (likely(txe->pktmbuf->nb_segs == 1)) {
+			struct rte_mbuf *pkt =
+				rte_pktmbuf_prefree_seg(txe->pktmbuf);
+			txe->pktmbuf = NULL;
+
+			if (unlikely(pkt == NULL))
+				continue;
+
+			free_pkts[num_free_pkts++] = pkt;
+			if (unlikely(pkt->pool != free_pkts[0]->pool ||
+				     num_free_pkts >=
+					     SSSNIC_ETHDEV_TX_FREE_BULK)) {
+				rte_mempool_put_bulk(free_pkts[0]->pool,
+					(void **)free_pkts, num_free_pkts - 1);
+				num_free_pkts = 0;
+				free_pkts[num_free_pkts++] = pkt;
+			}
+		} else {
+			rte_pktmbuf_free(txe->pktmbuf);
+			txe->pktmbuf = NULL;
+		}
+	}
+
+	if (num_free_pkts > 0)
+		rte_mempool_put_bulk(free_pkts[0]->pool, (void **)free_pkts,
+			num_free_pkts);
+
+	sssnic_ethdev_txq_consume(txq, count);
+
+	return count;
+}
+
+#define SSSNIC_ETHDEV_TXQ_FUSH_TIMEOUT 3000 /* 3 seconds */
+static int
+sssnic_ethdev_txq_flush(struct sssnic_ethdev_txq *txq)
+{
+	uint64_t timeout;
+	uint16_t used_entries;
+
+	timeout = rte_get_timer_cycles() +
+		  rte_get_timer_hz() * SSSNIC_ETHDEV_TXQ_FUSH_TIMEOUT / 1000;
+
+	do {
+		sssnic_ethdev_txq_pktmbufs_cleanup(txq);
+		used_entries = sssnic_ethdev_txq_num_used_entries(txq);
+		if (used_entries == 0)
+			return 0;
+
+		rte_delay_us_sleep(1000);
+	} while (((long)(rte_get_timer_cycles() - timeout)) < 0);
+
+	PMD_DRV_LOG(ERR, "Flush port:%u txq:%u timeout, used_txq_entries:%u",
+		txq->port, txq->qid, sssnic_ethdev_txq_num_used_entries(txq));
+
+	return -ETIMEDOUT;
+}
+
+int
+sssnic_ethdev_tx_queue_start(struct rte_eth_dev *ethdev, uint16_t queue_id)
+{
+	struct sssnic_netdev *netdev = SSSNIC_ETHDEV_PRIVATE(ethdev);
+
+	ethdev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
+	netdev->num_started_txqs++;
+
+	PMD_DRV_LOG(DEBUG, "port %u txq %u started", ethdev->data->port_id,
+		queue_id);
+
+	return 0;
+}
+
+int
+sssnic_ethdev_tx_queue_stop(struct rte_eth_dev *ethdev, uint16_t queue_id)
+{
+	int ret;
+	struct sssnic_netdev *netdev = SSSNIC_ETHDEV_PRIVATE(ethdev);
+	struct sssnic_ethdev_txq *txq = ethdev->data->tx_queues[queue_id];
+
+	ret = sssnic_ethdev_txq_flush(txq);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Failed to flush port %u txq %u",
+			ethdev->data->port_id, queue_id);
+		return ret;
+	}
+
+	ethdev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
+	netdev->num_started_txqs--;
+
+	PMD_DRV_LOG(DEBUG, "port %u txq %u stopped", ethdev->data->port_id,
+		queue_id);
+
+	return 0;
+}
+
+int
+sssnic_ethdev_tx_queue_all_start(struct rte_eth_dev *ethdev)
+{
+	uint16_t qid;
+	uint16_t numq = ethdev->data->nb_tx_queues;
+
+	for (qid = 0; qid < numq; qid++)
+		sssnic_ethdev_tx_queue_start(ethdev, qid);
+
+	return 0;
+}
+
+void
+sssnic_ethdev_tx_queue_all_stop(struct rte_eth_dev *ethdev)
+{
+	uint16_t qid;
+	uint16_t numq = ethdev->data->nb_tx_queues;
+
+	for (qid = 0; qid < numq; qid++)
+		sssnic_ethdev_tx_queue_stop(ethdev, qid);
+}
diff --git a/drivers/net/sssnic/sssnic_ethdev_tx.h b/drivers/net/sssnic/sssnic_ethdev_tx.h
index bd1d721e37..3de9e899a0 100644
--- a/drivers/net/sssnic/sssnic_ethdev_tx.h
+++ b/drivers/net/sssnic/sssnic_ethdev_tx.h
@@ -23,5 +23,9 @@ int sssnic_ethdev_tx_queue_setup(struct rte_eth_dev *ethdev,
 void sssnic_ethdev_tx_queue_release(struct rte_eth_dev *ethdev,
 	uint16_t queue_id);
 void sssnic_ethdev_tx_queue_all_release(struct rte_eth_dev *ethdev);
+int sssnic_ethdev_tx_queue_start(struct rte_eth_dev *ethdev, uint16_t queue_id);
+int sssnic_ethdev_tx_queue_stop(struct rte_eth_dev *ethdev, uint16_t queue_id);
+int sssnic_ethdev_tx_queue_all_start(struct rte_eth_dev *ethdev);
+void sssnic_ethdev_tx_queue_all_stop(struct rte_eth_dev *ethdev);
 
 #endif /* _SSSNIC_ETHDEV_TX_H_ */
-- 
2.27.0


  parent reply	other threads:[~2023-08-29  8:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29  7:57 [PATCH 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters wanry
2023-08-29  7:57 ` [PATCH 01/32] net/sssnic: add build and doc infrastructure wanry
2023-08-29  7:57 ` [PATCH 02/32] net/sssnic: add log type and log macros wanry
2023-08-29  7:58 ` [PATCH 03/32] net/sssnic: support probe and remove wanry
2023-08-29  7:58 ` [PATCH 04/32] net/sssnic: initialize hardware base wanry
2023-08-29  7:58 ` [PATCH 05/32] net/sssnic: add event queue wanry
2023-08-29  7:58 ` [PATCH 06/32] net/sssnic/base: add message definition and utility wanry
2023-08-29  7:58 ` [PATCH 07/32] net/sssnic/base: add mailbox support wanry
2023-08-29  7:58 ` [PATCH 08/32] net/sssnic/base: add work queue wanry
2023-09-06 15:09   ` Stephen Hemminger
2023-09-07  2:09     ` Renyong Wan
2023-08-29  7:58 ` [PATCH 09/32] net/sssnic/base: add control queue wanry
2023-08-29  7:58 ` [PATCH 10/32] net/sssnic: add dev configure and infos get wanry
2023-08-29  7:58 ` [PATCH 11/32] net/sssnic: add dev MAC ops wanry
2023-08-29  7:58 ` [PATCH 12/32] net/sssnic: support dev link status wanry
2023-08-29  7:58 ` [PATCH 13/32] net/sssnic: support link status event wanry
2023-08-29  7:58 ` [PATCH 14/32] net/sssnic: support Rx queue setup and release wanry
2023-08-29  7:58 ` [PATCH 15/32] net/sssnic: support Tx " wanry
2023-08-29  7:58 ` [PATCH 16/32] net/sssnic: support Rx queue start and stop wanry
2023-08-29  7:58 ` wanry [this message]
2023-08-29  7:58 ` [PATCH 18/32] net/sssnic: add Rx interrupt support wanry
2023-08-29  7:58 ` [PATCH 19/32] net/sssnic: support dev start and stop wanry
2023-08-29  7:58 ` [PATCH 20/32] net/sssnic: support dev close and reset wanry
2023-08-29  7:58 ` [PATCH 21/32] net/sssnic: add allmulticast and promiscuous ops wanry
2023-08-29  7:58 ` [PATCH 22/32] net/sssnic: add basic and extended stats ops wanry
2023-08-29  7:58 ` [PATCH 23/32] net/sssnic: support Rx packet burst wanry
2023-08-29  7:58 ` [PATCH 24/32] net/sssnic: support Tx " wanry
2023-08-29  7:58 ` [PATCH 25/32] net/sssnic: add RSS support wanry
2023-08-29  7:58 ` [PATCH 26/32] net/sssnic: support dev MTU set wanry
2023-08-29  7:58 ` [PATCH 27/32] net/sssnic: support dev queue info get wanry
2023-08-29  7:58 ` [PATCH 28/32] net/sssnic: support dev firmware version get wanry
2023-08-29  7:58 ` [PATCH 29/32] net/sssnic: add dev flow control ops wanry
2023-08-29  7:58 ` [PATCH 30/32] net/sssnic: support VLAN offload and filter wanry
2023-08-29  7:58 ` [PATCH 31/32] net/sssnic: add generic flow ops wanry
2023-08-29  7:58 ` [PATCH 32/32] net/sssnic: add VF dev support wanry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230829075829.208413-18-wanry@3snic.com \
    --to=wanry@3snic.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=steven.song@3snic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).