[v2,07/17] net/sfc: move MCDI helper interface to dedicated namespace
diff mbox series

Message ID 1600324483-23153-8-git-send-email-arybchenko@solarflare.com
State Accepted
Delegated to: Ferruh Yigit
Headers show
Series
  • net/sfc: factor out common driver library
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko Sept. 17, 2020, 6:34 a.m. UTC
MCDI helpers will be moved to common/sfc_efx and it is better
to do dummy renamings first before non-trivial changes.

Existing functionality should be split into common and network
driver specific parts. Prepare to do it.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc.h      |   5 +-
 drivers/net/sfc/sfc_mcdi.c | 108 +++++++++++++++++++++----------------
 drivers/net/sfc/sfc_mcdi.h |  22 +++-----
 3 files changed, 73 insertions(+), 62 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index a530b12a8e..b3ac752334 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -220,7 +220,7 @@  struct sfc_adapter {
 	rte_spinlock_t			nic_lock;
 	rte_atomic32_t			restart_required;
 
-	struct sfc_mcdi			mcdi;
+	struct sfc_efx_mcdi		mcdi;
 	struct sfc_intr			intr;
 	struct sfc_port			port;
 	struct sfc_filter		filter;
@@ -366,6 +366,9 @@  void sfc_stop(struct sfc_adapter *sa);
 
 void sfc_schedule_restart(struct sfc_adapter *sa);
 
+int sfc_mcdi_init(struct sfc_adapter *sa);
+void sfc_mcdi_fini(struct sfc_adapter *sa);
+
 int sfc_configure(struct sfc_adapter *sa);
 void sfc_close(struct sfc_adapter *sa);
 
diff --git a/drivers/net/sfc/sfc_mcdi.c b/drivers/net/sfc/sfc_mcdi.c
index 9a51b3e030..c97a33d558 100644
--- a/drivers/net/sfc/sfc_mcdi.c
+++ b/drivers/net/sfc/sfc_mcdi.c
@@ -19,12 +19,12 @@ 
 #include "sfc_log.h"
 #include "sfc_ev.h"
 
-#define SFC_MCDI_POLL_INTERVAL_MIN_US	10		/* 10us in 1us units */
-#define SFC_MCDI_POLL_INTERVAL_MAX_US	(US_PER_S / 10)	/* 100ms in 1us units */
-#define SFC_MCDI_WATCHDOG_INTERVAL_US	(10 * US_PER_S)	/* 10s in 1us units */
+#define SFC_EFX_MCDI_POLL_INTERVAL_MIN_US	10		/* 10us */
+#define SFC_EFX_MCDI_POLL_INTERVAL_MAX_US	(US_PER_S / 10)	/* 100ms */
+#define SFC_EFX_MCDI_WATCHDOG_INTERVAL_US	(10 * US_PER_S)	/* 10s */
 
 static void
-sfc_mcdi_timeout(struct sfc_adapter *sa)
+sfc_efx_mcdi_timeout(struct sfc_adapter *sa)
 {
 	sfc_warn(sa, "MC TIMEOUT");
 
@@ -32,9 +32,9 @@  sfc_mcdi_timeout(struct sfc_adapter *sa)
 }
 
 static inline boolean_t
-sfc_mcdi_proxy_event_available(struct sfc_adapter *sa)
+sfc_efx_mcdi_proxy_event_available(struct sfc_adapter *sa)
 {
-	struct sfc_mcdi *mcdi = &sa->mcdi;
+	struct sfc_efx_mcdi *mcdi = &sa->mcdi;
 
 	mcdi->proxy_handle = 0;
 	mcdi->proxy_result = ETIMEDOUT;
@@ -46,7 +46,7 @@  sfc_mcdi_proxy_event_available(struct sfc_adapter *sa)
 }
 
 static void
-sfc_mcdi_poll(struct sfc_adapter *sa, boolean_t proxy)
+sfc_efx_mcdi_poll(struct sfc_adapter *sa, boolean_t proxy)
 {
 	efx_nic_t *enp;
 	unsigned int delay_total;
@@ -54,22 +54,22 @@  sfc_mcdi_poll(struct sfc_adapter *sa, boolean_t proxy)
 	boolean_t aborted __rte_unused;
 
 	delay_total = 0;
-	delay_us = SFC_MCDI_POLL_INTERVAL_MIN_US;
+	delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MIN_US;
 	enp = sa->nic;
 
 	do {
 		boolean_t poll_completed;
 
-		poll_completed = (proxy) ? sfc_mcdi_proxy_event_available(sa) :
+		poll_completed = (proxy) ? sfc_efx_mcdi_proxy_event_available(sa) :
 					   efx_mcdi_request_poll(enp);
 		if (poll_completed)
 			return;
 
-		if (delay_total > SFC_MCDI_WATCHDOG_INTERVAL_US) {
+		if (delay_total > SFC_EFX_MCDI_WATCHDOG_INTERVAL_US) {
 			if (!proxy) {
 				aborted = efx_mcdi_request_abort(enp);
 				SFC_ASSERT(aborted);
-				sfc_mcdi_timeout(sa);
+				sfc_efx_mcdi_timeout(sa);
 			}
 
 			return;
@@ -80,27 +80,28 @@  sfc_mcdi_poll(struct sfc_adapter *sa, boolean_t proxy)
 		delay_total += delay_us;
 
 		/* Exponentially back off the poll frequency */
-		RTE_BUILD_BUG_ON(SFC_MCDI_POLL_INTERVAL_MAX_US > UINT_MAX / 2);
+		RTE_BUILD_BUG_ON(SFC_EFX_MCDI_POLL_INTERVAL_MAX_US >
+				 UINT_MAX / 2);
 		delay_us *= 2;
-		if (delay_us > SFC_MCDI_POLL_INTERVAL_MAX_US)
-			delay_us = SFC_MCDI_POLL_INTERVAL_MAX_US;
+		if (delay_us > SFC_EFX_MCDI_POLL_INTERVAL_MAX_US)
+			delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MAX_US;
 
 	} while (1);
 }
 
 static void
-sfc_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
+sfc_efx_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
-	struct sfc_mcdi *mcdi = &sa->mcdi;
+	struct sfc_efx_mcdi *mcdi = &sa->mcdi;
 	uint32_t proxy_handle;
 
 	rte_spinlock_lock(&mcdi->lock);
 
-	SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
+	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
 
 	efx_mcdi_request_start(sa->nic, emrp, B_FALSE);
-	sfc_mcdi_poll(sa, B_FALSE);
+	sfc_efx_mcdi_poll(sa, B_FALSE);
 
 	if (efx_mcdi_get_proxy_handle(sa->nic, emrp, &proxy_handle) == 0) {
 		/*
@@ -109,7 +110,7 @@  sfc_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 		 * a non-zero proxy handle (should be the same as
 		 * the value obtained above) and operation status
 		 */
-		sfc_mcdi_poll(sa, B_TRUE);
+		sfc_efx_mcdi_poll(sa, B_TRUE);
 
 		if ((mcdi->proxy_handle != 0) &&
 		    (mcdi->proxy_handle != proxy_handle)) {
@@ -121,7 +122,7 @@  sfc_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 			 * request and poll for an ordinary MCDI response
 			 */
 			efx_mcdi_request_start(sa->nic, emrp, B_FALSE);
-			sfc_mcdi_poll(sa, B_FALSE);
+			sfc_efx_mcdi_poll(sa, B_FALSE);
 		} else {
 			emrp->emr_rc = mcdi->proxy_result;
 			sfc_err(sa, "MCDI proxy authorization failed "
@@ -134,20 +135,20 @@  sfc_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 }
 
 static void
-sfc_mcdi_ev_cpl(void *arg)
+sfc_efx_mcdi_ev_cpl(void *arg)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
-	struct sfc_mcdi *mcdi __rte_unused;
+	struct sfc_efx_mcdi *mcdi __rte_unused;
 
 	mcdi = &sa->mcdi;
-	SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
+	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
 
 	/* MCDI is polled, completions are not expected */
 	SFC_ASSERT(0);
 }
 
 static void
-sfc_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
+sfc_efx_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
 
@@ -161,7 +162,7 @@  sfc_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
 #define SFC_MCDI_LOG_BUF_SIZE	128
 
 static size_t
-sfc_mcdi_do_log(const struct sfc_adapter *sa,
+sfc_efx_mcdi_do_log(const struct sfc_adapter *sa,
 		char *buffer, void *data, size_t data_size,
 		size_t pfxsize, size_t position)
 {
@@ -190,7 +191,7 @@  sfc_mcdi_do_log(const struct sfc_adapter *sa,
 }
 
 static void
-sfc_mcdi_logger(void *arg, efx_log_msg_t type,
+sfc_efx_mcdi_logger(void *arg, efx_log_msg_t type,
 		void *header, size_t header_size,
 		void *data, size_t data_size)
 {
@@ -215,9 +216,10 @@  sfc_mcdi_logger(void *arg, efx_log_msg_t type,
 	pfxsize = snprintf(buffer, sizeof(buffer), "MCDI RPC %s:",
 			   type == EFX_LOG_MCDI_REQUEST ? "REQ" :
 			   type == EFX_LOG_MCDI_RESPONSE ? "RESP" : "???");
-	start = sfc_mcdi_do_log(sa, buffer, header, header_size,
-				pfxsize, pfxsize);
-	start = sfc_mcdi_do_log(sa, buffer, data, data_size, pfxsize, start);
+	start = sfc_efx_mcdi_do_log(sa, buffer, header, header_size,
+				    pfxsize, pfxsize);
+	start = sfc_efx_mcdi_do_log(sa, buffer, data, data_size,
+				    pfxsize, start);
 	if (start != pfxsize) {
 		buffer[start] = '\0';
 		sfc_log_mcdi(sa, "%s", buffer);
@@ -225,19 +227,19 @@  sfc_mcdi_logger(void *arg, efx_log_msg_t type,
 }
 
 static void
-sfc_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
+sfc_efx_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
-	struct sfc_mcdi *mcdi = &sa->mcdi;
+	struct sfc_efx_mcdi *mcdi = &sa->mcdi;
 
 	mcdi->proxy_handle = handle;
 	mcdi->proxy_result = result;
 }
 
-int
-sfc_mcdi_init(struct sfc_adapter *sa)
+static int
+sfc_efx_mcdi_init(struct sfc_adapter *sa)
 {
-	struct sfc_mcdi *mcdi;
+	struct sfc_efx_mcdi *mcdi;
 	size_t max_msg_size;
 	efx_mcdi_transport_t *emtp;
 	int rc;
@@ -246,11 +248,11 @@  sfc_mcdi_init(struct sfc_adapter *sa)
 
 	mcdi = &sa->mcdi;
 
-	SFC_ASSERT(mcdi->state == SFC_MCDI_UNINITIALIZED);
+	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_UNINITIALIZED);
 
 	rte_spinlock_init(&mcdi->lock);
 
-	mcdi->state = SFC_MCDI_INITIALIZED;
+	mcdi->state = SFC_EFX_MCDI_INITIALIZED;
 
 	max_msg_size = sizeof(uint32_t) + MCDI_CTL_SDU_LEN_MAX_V2;
 	rc = sfc_dma_alloc(sa, "mcdi", 0, max_msg_size, sa->socket_id,
@@ -265,11 +267,11 @@  sfc_mcdi_init(struct sfc_adapter *sa)
 	emtp = &mcdi->transport;
 	emtp->emt_context = sa;
 	emtp->emt_dma_mem = &mcdi->mem;
-	emtp->emt_execute = sfc_mcdi_execute;
-	emtp->emt_ev_cpl = sfc_mcdi_ev_cpl;
-	emtp->emt_exception = sfc_mcdi_exception;
-	emtp->emt_logger = sfc_mcdi_logger;
-	emtp->emt_ev_proxy_response = sfc_mcdi_ev_proxy_response;
+	emtp->emt_execute = sfc_efx_mcdi_execute;
+	emtp->emt_ev_cpl = sfc_efx_mcdi_ev_cpl;
+	emtp->emt_exception = sfc_efx_mcdi_exception;
+	emtp->emt_logger = sfc_efx_mcdi_logger;
+	emtp->emt_ev_proxy_response = sfc_efx_mcdi_ev_proxy_response;
 
 	sfc_log_init(sa, "init MCDI");
 	rc = efx_mcdi_init(sa->nic, emtp);
@@ -283,14 +285,14 @@  sfc_mcdi_init(struct sfc_adapter *sa)
 	sfc_dma_free(sa, &mcdi->mem);
 
 fail_dma_alloc:
-	mcdi->state = SFC_MCDI_UNINITIALIZED;
+	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
 	return rc;
 }
 
-void
-sfc_mcdi_fini(struct sfc_adapter *sa)
+static void
+sfc_efx_mcdi_fini(struct sfc_adapter *sa)
 {
-	struct sfc_mcdi *mcdi;
+	struct sfc_efx_mcdi *mcdi;
 	efx_mcdi_transport_t *emtp;
 
 	sfc_log_init(sa, "entry");
@@ -300,8 +302,8 @@  sfc_mcdi_fini(struct sfc_adapter *sa)
 
 	rte_spinlock_lock(&mcdi->lock);
 
-	SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
-	mcdi->state = SFC_MCDI_UNINITIALIZED;
+	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
+	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
 
 	sfc_log_init(sa, "fini MCDI");
 	efx_mcdi_fini(sa->nic);
@@ -311,3 +313,15 @@  sfc_mcdi_fini(struct sfc_adapter *sa)
 
 	sfc_dma_free(sa, &mcdi->mem);
 }
+
+int
+sfc_mcdi_init(struct sfc_adapter *sa)
+{
+	return sfc_efx_mcdi_init(sa);
+}
+
+void
+sfc_mcdi_fini(struct sfc_adapter *sa)
+{
+	sfc_efx_mcdi_fini(sa);
+}
diff --git a/drivers/net/sfc/sfc_mcdi.h b/drivers/net/sfc/sfc_mcdi.h
index 789a16d8bb..10f5bab666 100644
--- a/drivers/net/sfc/sfc_mcdi.h
+++ b/drivers/net/sfc/sfc_mcdi.h
@@ -22,31 +22,25 @@ 
 extern "C" {
 #endif
 
-enum sfc_mcdi_state {
-	SFC_MCDI_UNINITIALIZED = 0,
-	SFC_MCDI_INITIALIZED,
-	SFC_MCDI_BUSY,
-	SFC_MCDI_COMPLETED,
+enum sfc_efx_mcdi_state {
+	SFC_EFX_MCDI_UNINITIALIZED = 0,
+	SFC_EFX_MCDI_INITIALIZED,
+	SFC_EFX_MCDI_BUSY,
+	SFC_EFX_MCDI_COMPLETED,
 
-	SFC_MCDI_NSTATES
+	SFC_EFX_MCDI_NSTATES
 };
 
-struct sfc_mcdi {
+struct sfc_efx_mcdi {
 	rte_spinlock_t			lock;
 	efsys_mem_t			mem;
-	enum sfc_mcdi_state		state;
+	enum sfc_efx_mcdi_state		state;
 	efx_mcdi_transport_t		transport;
 	uint32_t			logtype;
 	uint32_t			proxy_handle;
 	efx_rc_t			proxy_result;
 };
 
-
-struct sfc_adapter;
-
-int sfc_mcdi_init(struct sfc_adapter *sa);
-void sfc_mcdi_fini(struct sfc_adapter *sa);
-
 #ifdef __cplusplus
 }
 #endif