[18/38] net/sfc: implement representor TxQ start/stop

Message ID 20210827065717.1838258-19-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/sfc: support port representors |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko Aug. 27, 2021, 6:56 a.m. UTC
  From: Igor Romanov <igor.romanov@oktetlabs.ru>

Implement Tx queue start and stop in port representor proxy.

Signed-off-by: Igor Romanov <igor.romanov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 drivers/net/sfc/sfc_ev.h         |   8 ++
 drivers/net/sfc/sfc_repr_proxy.c | 166 +++++++++++++++++++++++++++++++
 drivers/net/sfc/sfc_repr_proxy.h |  11 ++
 drivers/net/sfc/sfc_tx.c         |  15 ++-
 drivers/net/sfc/sfc_tx.h         |   1 +
 5 files changed, 199 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/sfc/sfc_ev.h b/drivers/net/sfc/sfc_ev.h
index bcb7fbe466..a4ababc2bc 100644
--- a/drivers/net/sfc/sfc_ev.h
+++ b/drivers/net/sfc/sfc_ev.h
@@ -118,6 +118,14 @@  sfc_repr_rxq_sw_index(const struct sfc_adapter_shared *sas,
 		repr_queue_id;
 }
 
+static inline sfc_sw_index_t
+sfc_repr_txq_sw_index(const struct sfc_adapter_shared *sas,
+		      unsigned int repr_queue_id)
+{
+	/* Reserved TxQ for representors is the first reserved TxQ */
+	return sfc_repr_available(sas) ? repr_queue_id : SFC_SW_INDEX_INVALID;
+}
+
 /*
  * Functions below define event queue to transmit/receive queue and vice
  * versa mapping.
diff --git a/drivers/net/sfc/sfc_repr_proxy.c b/drivers/net/sfc/sfc_repr_proxy.c
index 03b6421b04..a5be8fa270 100644
--- a/drivers/net/sfc/sfc_repr_proxy.c
+++ b/drivers/net/sfc/sfc_repr_proxy.c
@@ -17,6 +17,7 @@ 
 #include "sfc.h"
 #include "sfc_ev.h"
 #include "sfc_rx.h"
+#include "sfc_tx.h"
 
 /**
  * Amount of time to wait for the representor proxy routine (which is
@@ -138,6 +139,155 @@  sfc_repr_proxy_routine(void *arg)
 	return 0;
 }
 
+static int
+sfc_repr_proxy_txq_attach(struct sfc_adapter *sa)
+{
+	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
+	struct sfc_repr_proxy *rp = &sa->repr_proxy;
+	unsigned int i;
+
+	sfc_log_init(sa, "entry");
+
+	for (i = 0; i < sfc_repr_nb_txq(sas); i++) {
+		sfc_sw_index_t sw_index = sfc_repr_txq_sw_index(sas, i);
+
+		rp->dp_txq[i].sw_index = sw_index;
+	}
+
+	sfc_log_init(sa, "done");
+
+	return 0;
+}
+
+static void
+sfc_repr_proxy_txq_detach(struct sfc_adapter *sa)
+{
+	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
+	struct sfc_repr_proxy *rp = &sa->repr_proxy;
+	unsigned int i;
+
+	sfc_log_init(sa, "entry");
+
+	for (i = 0; i < sfc_repr_nb_txq(sas); i++)
+		rp->dp_txq[i].sw_index = 0;
+
+	sfc_log_init(sa, "done");
+}
+
+int
+sfc_repr_proxy_txq_init(struct sfc_adapter *sa)
+{
+	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
+	struct sfc_repr_proxy *rp = &sa->repr_proxy;
+	const struct rte_eth_txconf tx_conf = {
+		.tx_free_thresh = SFC_REPR_PROXY_TXQ_FREE_THRESH,
+	};
+	struct sfc_txq_info *txq_info;
+	unsigned int init_i;
+	unsigned int i;
+	int rc;
+
+	sfc_log_init(sa, "entry");
+
+	if (!sfc_repr_available(sas)) {
+		sfc_log_init(sa, "representors not supported - skip");
+		return 0;
+	}
+
+	for (init_i = 0; init_i < sfc_repr_nb_txq(sas); init_i++) {
+		struct sfc_repr_proxy_dp_txq *txq = &rp->dp_txq[init_i];
+
+		txq_info = &sfc_sa2shared(sa)->txq_info[txq->sw_index];
+		if (txq_info->state == SFC_TXQ_INITIALIZED) {
+			sfc_log_init(sa,
+				"representor proxy TxQ %u is already initialized - skip",
+				init_i);
+			continue;
+		}
+
+		sfc_tx_qinit_info(sa, txq->sw_index);
+
+		rc = sfc_tx_qinit(sa, txq->sw_index,
+				  SFC_REPR_PROXY_TX_DESC_COUNT, sa->socket_id,
+				  &tx_conf);
+
+		if (rc != 0) {
+			sfc_err(sa, "failed to init representor proxy TxQ %u",
+				init_i);
+			goto fail_init;
+		}
+	}
+
+	sfc_log_init(sa, "done");
+
+	return 0;
+
+fail_init:
+	for (i = 0; i < init_i; i++) {
+		struct sfc_repr_proxy_dp_txq *txq = &rp->dp_txq[i];
+
+		txq_info = &sfc_sa2shared(sa)->txq_info[txq->sw_index];
+		if (txq_info->state == SFC_TXQ_INITIALIZED)
+			sfc_tx_qfini(sa, txq->sw_index);
+	}
+	sfc_log_init(sa, "failed: %s", rte_strerror(rc));
+
+	return rc;
+}
+
+void
+sfc_repr_proxy_txq_fini(struct sfc_adapter *sa)
+{
+	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
+	struct sfc_repr_proxy *rp = &sa->repr_proxy;
+	struct sfc_txq_info *txq_info;
+	unsigned int i;
+
+	sfc_log_init(sa, "entry");
+
+	if (!sfc_repr_available(sas)) {
+		sfc_log_init(sa, "representors not supported - skip");
+		return;
+	}
+
+	for (i = 0; i < sfc_repr_nb_txq(sas); i++) {
+		struct sfc_repr_proxy_dp_txq *txq = &rp->dp_txq[i];
+
+		txq_info = &sfc_sa2shared(sa)->txq_info[txq->sw_index];
+		if (txq_info->state != SFC_TXQ_INITIALIZED) {
+			sfc_log_init(sa,
+				"representor proxy TxQ %u is already finalized - skip",
+				i);
+			continue;
+		}
+
+		sfc_tx_qfini(sa, txq->sw_index);
+	}
+
+	sfc_log_init(sa, "done");
+}
+
+static int
+sfc_repr_proxy_txq_start(struct sfc_adapter *sa)
+{
+	struct sfc_repr_proxy *rp = &sa->repr_proxy;
+
+	sfc_log_init(sa, "entry");
+
+	RTE_SET_USED(rp);
+
+	sfc_log_init(sa, "done");
+
+	return 0;
+}
+
+static void
+sfc_repr_proxy_txq_stop(struct sfc_adapter *sa)
+{
+	sfc_log_init(sa, "entry");
+	sfc_log_init(sa, "done");
+}
+
 static int
 sfc_repr_proxy_rxq_attach(struct sfc_adapter *sa)
 {
@@ -398,6 +548,10 @@  sfc_repr_proxy_attach(struct sfc_adapter *sa)
 	if (rc != 0)
 		goto fail_rxq_attach;
 
+	rc = sfc_repr_proxy_txq_attach(sa);
+	if (rc != 0)
+		goto fail_txq_attach;
+
 	rc = sfc_repr_proxy_ports_init(sa);
 	if (rc != 0)
 		goto fail_ports_init;
@@ -458,6 +612,9 @@  sfc_repr_proxy_attach(struct sfc_adapter *sa)
 	sfc_repr_proxy_ports_fini(sa);
 
 fail_ports_init:
+	sfc_repr_proxy_txq_detach(sa);
+
+fail_txq_attach:
 	sfc_repr_proxy_rxq_detach(sa);
 
 fail_rxq_attach:
@@ -482,6 +639,7 @@  sfc_repr_proxy_detach(struct sfc_adapter *sa)
 	rte_service_component_unregister(rp->service_id);
 	sfc_repr_proxy_ports_fini(sa);
 	sfc_repr_proxy_rxq_detach(sa);
+	sfc_repr_proxy_txq_detach(sa);
 
 	sfc_log_init(sa, "done");
 }
@@ -508,6 +666,10 @@  sfc_repr_proxy_start(struct sfc_adapter *sa)
 	if (rc != 0)
 		goto fail_rxq_start;
 
+	rc = sfc_repr_proxy_txq_start(sa);
+	if (rc != 0)
+		goto fail_txq_start;
+
 	/* Service core may be in "stopped" state, start it */
 	rc = rte_service_lcore_start(rp->service_core_id);
 	if (rc != 0 && rc != -EALREADY) {
@@ -549,6 +711,9 @@  sfc_repr_proxy_start(struct sfc_adapter *sa)
 	/* Service lcore may be shared and we never stop it */
 
 fail_start_core:
+	sfc_repr_proxy_txq_stop(sa);
+
+fail_txq_start:
 	sfc_repr_proxy_rxq_stop(sa);
 
 fail_rxq_start:
@@ -587,6 +752,7 @@  sfc_repr_proxy_stop(struct sfc_adapter *sa)
 	/* Service lcore may be shared and we never stop it */
 
 	sfc_repr_proxy_rxq_stop(sa);
+	sfc_repr_proxy_txq_stop(sa);
 
 	rp->started = false;
 
diff --git a/drivers/net/sfc/sfc_repr_proxy.h b/drivers/net/sfc/sfc_repr_proxy.h
index dca3fca2b9..1fe7ff3695 100644
--- a/drivers/net/sfc/sfc_repr_proxy.h
+++ b/drivers/net/sfc/sfc_repr_proxy.h
@@ -36,6 +36,10 @@  extern "C" {
 #define SFC_REPR_PROXY_RXQ_REFILL_LEVEL	(SFC_REPR_PROXY_RX_DESC_COUNT / 4)
 #define SFC_REPR_PROXY_RX_BURST		32
 
+#define SFC_REPR_PROXY_TX_DESC_COUNT	256
+#define SFC_REPR_PROXY_TXQ_FREE_THRESH	(SFC_REPR_PROXY_TX_DESC_COUNT / 4)
+#define SFC_REPR_PROXY_TX_BURST		32
+
 struct sfc_repr_proxy_rxq {
 	struct rte_ring			*ring;
 	struct rte_mempool		*mb_pool;
@@ -61,6 +65,10 @@  struct sfc_repr_proxy_dp_rxq {
 	sfc_sw_index_t			sw_index;
 };
 
+struct sfc_repr_proxy_dp_txq {
+	sfc_sw_index_t			sw_index;
+};
+
 enum sfc_repr_proxy_mbox_op {
 	SFC_REPR_PROXY_MBOX_ADD_PORT,
 	SFC_REPR_PROXY_MBOX_DEL_PORT,
@@ -83,6 +91,7 @@  struct sfc_repr_proxy {
 	struct sfc_repr_proxy_ports	ports;
 	bool				started;
 	struct sfc_repr_proxy_dp_rxq	dp_rxq[SFC_REPR_PROXY_NB_RXQ_MAX];
+	struct sfc_repr_proxy_dp_txq	dp_txq[SFC_REPR_PROXY_NB_TXQ_MAX];
 
 	struct sfc_repr_proxy_mbox	mbox;
 };
@@ -92,6 +101,8 @@  struct sfc_adapter;
 int sfc_repr_proxy_attach(struct sfc_adapter *sa);
 void sfc_repr_proxy_pre_detach(struct sfc_adapter *sa);
 void sfc_repr_proxy_detach(struct sfc_adapter *sa);
+int sfc_repr_proxy_txq_init(struct sfc_adapter *sa);
+void sfc_repr_proxy_txq_fini(struct sfc_adapter *sa);
 int sfc_repr_proxy_start(struct sfc_adapter *sa);
 void sfc_repr_proxy_stop(struct sfc_adapter *sa);
 
diff --git a/drivers/net/sfc/sfc_tx.c b/drivers/net/sfc/sfc_tx.c
index c1b2e964f8..13392cdd5a 100644
--- a/drivers/net/sfc/sfc_tx.c
+++ b/drivers/net/sfc/sfc_tx.c
@@ -290,7 +290,7 @@  sfc_tx_qfini(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
 	txq->evq = NULL;
 }
 
-static int
+int
 sfc_tx_qinit_info(struct sfc_adapter *sa, sfc_sw_index_t sw_index)
 {
 	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
@@ -378,6 +378,7 @@  sfc_tx_configure(struct sfc_adapter *sa)
 	const unsigned int nb_tx_queues = sa->eth_dev->data->nb_tx_queues;
 	const unsigned int nb_rsvd_tx_queues = sfc_nb_txq_reserved(sas);
 	const unsigned int nb_txq_total = nb_tx_queues + nb_rsvd_tx_queues;
+	bool reconfigure;
 	int rc = 0;
 
 	sfc_log_init(sa, "nb_tx_queues=%u (old %u)",
@@ -401,6 +402,7 @@  sfc_tx_configure(struct sfc_adapter *sa)
 		goto done;
 
 	if (sas->txq_info == NULL) {
+		reconfigure = false;
 		sas->txq_info = rte_calloc_socket("sfc-txqs", nb_txq_total,
 						  sizeof(sas->txq_info[0]), 0,
 						  sa->socket_id);
@@ -419,6 +421,8 @@  sfc_tx_configure(struct sfc_adapter *sa)
 		struct sfc_txq_info *new_txq_info;
 		struct sfc_txq *new_txq_ctrl;
 
+		reconfigure = true;
+
 		if (nb_tx_queues < sas->ethdev_txq_count)
 			sfc_tx_fini_queues(sa, nb_tx_queues);
 
@@ -457,12 +461,18 @@  sfc_tx_configure(struct sfc_adapter *sa)
 		sas->ethdev_txq_count++;
 	}
 
-	/* TODO: initialize reserved queues when supported. */
 	sas->txq_count = sas->ethdev_txq_count + nb_rsvd_tx_queues;
 
+	if (!reconfigure) {
+		rc = sfc_repr_proxy_txq_init(sa);
+		if (rc != 0)
+			goto fail_repr_proxy_txq_init;
+	}
+
 done:
 	return 0;
 
+fail_repr_proxy_txq_init:
 fail_tx_qinit_info:
 fail_txqs_ctrl_realloc:
 fail_txqs_realloc:
@@ -480,6 +490,7 @@  void
 sfc_tx_close(struct sfc_adapter *sa)
 {
 	sfc_tx_fini_queues(sa, 0);
+	sfc_repr_proxy_txq_fini(sa);
 
 	free(sa->txq_ctrl);
 	sa->txq_ctrl = NULL;
diff --git a/drivers/net/sfc/sfc_tx.h b/drivers/net/sfc/sfc_tx.h
index f1700b13ca..1a33199fdc 100644
--- a/drivers/net/sfc/sfc_tx.h
+++ b/drivers/net/sfc/sfc_tx.h
@@ -108,6 +108,7 @@  struct sfc_txq_info *sfc_txq_info_by_dp_txq(const struct sfc_dp_txq *dp_txq);
 int sfc_tx_configure(struct sfc_adapter *sa);
 void sfc_tx_close(struct sfc_adapter *sa);
 
+int sfc_tx_qinit_info(struct sfc_adapter *sa, sfc_sw_index_t sw_index);
 int sfc_tx_qinit(struct sfc_adapter *sa, sfc_sw_index_t sw_index,
 		 uint16_t nb_tx_desc, unsigned int socket_id,
 		 const struct rte_eth_txconf *tx_conf);