DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 14/14] net/sfc: move MCDI helpers to common driver
Date: Tue, 8 Sep 2020 10:14:35 +0100	[thread overview]
Message-ID: <1599556475-27820-16-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1599556475-27820-1-git-send-email-arybchenko@solarflare.com>

These helper will be reused by other libefx consumers, e.g. vDPA
driver.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/common/sfc_efx/Makefile               |   1 +
 drivers/common/sfc_efx/meson.build            |   1 +
 .../sfc_efx/rte_common_sfc_efx_version.map    |   9 +-
 drivers/common/sfc_efx/sfc_efx_mcdi.c         | 343 ++++++++++++++++++
 .../sfc_efx/sfc_efx_mcdi.h}                   |  12 +-
 drivers/net/sfc/sfc.h                         |   3 +-
 drivers/net/sfc/sfc_mcdi.c                    | 333 +----------------
 7 files changed, 360 insertions(+), 342 deletions(-)
 create mode 100644 drivers/common/sfc_efx/sfc_efx_mcdi.c
 rename drivers/{net/sfc/sfc_mcdi.h => common/sfc_efx/sfc_efx_mcdi.h} (81%)

diff --git a/drivers/common/sfc_efx/Makefile b/drivers/common/sfc_efx/Makefile
index 0bd6a593e9..bcbb15e789 100644
--- a/drivers/common/sfc_efx/Makefile
+++ b/drivers/common/sfc_efx/Makefile
@@ -58,6 +58,7 @@ EXPORT_MAP := rte_common_sfc_efx_version.map
 #
 
 SRCS-y += sfc_efx.c
+SRCS-y += sfc_efx_mcdi.c
 
 VPATH += $(SRCDIR)/base
 
diff --git a/drivers/common/sfc_efx/meson.build b/drivers/common/sfc_efx/meson.build
index 8fab4df792..b7a0763a34 100644
--- a/drivers/common/sfc_efx/meson.build
+++ b/drivers/common/sfc_efx/meson.build
@@ -34,6 +34,7 @@ objs = [base_objs]
 
 sources = files(
 	'sfc_efx.c',
+	'sfc_efx_mcdi.c',
 )
 
 includes += include_directories('base')
diff --git a/drivers/common/sfc_efx/rte_common_sfc_efx_version.map b/drivers/common/sfc_efx/rte_common_sfc_efx_version.map
index 0c719e8250..8c010c90ac 100644
--- a/drivers/common/sfc_efx/rte_common_sfc_efx_version.map
+++ b/drivers/common/sfc_efx/rte_common_sfc_efx_version.map
@@ -47,13 +47,7 @@ DPDK_21 {
 	efx_mac_stats_update;
 	efx_mac_stats_upload;
 
-	efx_mcdi_fini;
-	efx_mcdi_get_proxy_handle;
-	efx_mcdi_init;
 	efx_mcdi_new_epoch;
-	efx_mcdi_request_abort;
-	efx_mcdi_request_poll;
-	efx_mcdi_request_start;
 
 	efx_nic_cfg_get;
 	efx_nic_create;
@@ -118,5 +112,8 @@ DPDK_21 {
 	efx_tx_qpush;
 	efx_txq_size;
 
+	sfc_efx_mcdi_init;
+	sfc_efx_mcdi_fini;
+
 	local: *;
 };
diff --git a/drivers/common/sfc_efx/sfc_efx_mcdi.c b/drivers/common/sfc_efx/sfc_efx_mcdi.c
new file mode 100644
index 0000000000..7eb565bbd6
--- /dev/null
+++ b/drivers/common/sfc_efx/sfc_efx_mcdi.c
@@ -0,0 +1,343 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2019-2020 Xilinx, Inc.
+ * Copyright(c) 2016-2019 Solarflare Communications Inc.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ */
+
+#include <rte_cycles.h>
+
+#include "efx.h"
+#include "efx_mcdi.h"
+#include "efx_regs_mcdi.h"
+
+#include "sfc_efx_mcdi.h"
+#include "sfc_efx_debug.h"
+
+#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 */
+
+#define sfc_efx_mcdi_log(mcdi, level, ...) \
+	do {								\
+		const struct sfc_efx_mcdi *_mcdi = (mcdi);		\
+									\
+		rte_log(level, _mcdi->logtype,				\
+			RTE_FMT("%s" RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
+				_mcdi->log_prefix,			\
+				RTE_FMT_TAIL(__VA_ARGS__,)));		\
+	} while (0)
+
+#define sfc_efx_mcdi_crit(mcdi, ...) \
+	sfc_efx_mcdi_log(mcdi, RTE_LOG_CRIT, __VA_ARGS__)
+
+#define sfc_efx_mcdi_err(mcdi, ...) \
+	sfc_efx_mcdi_log(mcdi, RTE_LOG_ERR, __VA_ARGS__)
+
+#define sfc_efx_mcdi_warn(mcdi, ...) \
+	sfc_efx_mcdi_log(mcdi, RTE_LOG_WARNING, __VA_ARGS__)
+
+#define sfc_efx_mcdi_info(mcdi, ...) \
+	sfc_efx_mcdi_log(mcdi, RTE_LOG_INFO, __VA_ARGS__)
+
+/** Level value used by MCDI log statements */
+#define SFC_EFX_LOG_LEVEL_MCDI	RTE_LOG_INFO
+
+#define sfc_efx_log_mcdi(mcdi, ...) \
+	sfc_efx_mcdi_log(mcdi, SFC_EFX_LOG_LEVEL_MCDI, __VA_ARGS__)
+
+static void
+sfc_efx_mcdi_timeout(struct sfc_efx_mcdi *mcdi)
+{
+	sfc_efx_mcdi_warn(mcdi, "MC TIMEOUT");
+
+	sfc_efx_mcdi_crit(mcdi, "MCDI timeout handling is not implemented");
+	sfc_efx_mcdi_crit(mcdi, "NIC is unusable");
+	mcdi->state = SFC_EFX_MCDI_DEAD;
+}
+
+static inline boolean_t
+sfc_efx_mcdi_proxy_event_available(struct sfc_efx_mcdi *mcdi)
+{
+	mcdi->proxy_handle = 0;
+	mcdi->proxy_result = ETIMEDOUT;
+	mcdi->ops->mgmt_evq_poll(mcdi->ops_cookie);
+	if (mcdi->proxy_result != ETIMEDOUT)
+		return B_TRUE;
+
+	return B_FALSE;
+}
+
+static void
+sfc_efx_mcdi_poll(struct sfc_efx_mcdi *mcdi, boolean_t proxy)
+{
+	efx_nic_t *enp;
+	unsigned int delay_total;
+	unsigned int delay_us;
+	boolean_t aborted __rte_unused;
+
+	delay_total = 0;
+	delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MIN_US;
+	enp = mcdi->nic;
+
+	do {
+		boolean_t poll_completed;
+
+		poll_completed = (proxy) ?
+				sfc_efx_mcdi_proxy_event_available(mcdi) :
+				efx_mcdi_request_poll(enp);
+		if (poll_completed)
+			return;
+
+		if (delay_total > SFC_EFX_MCDI_WATCHDOG_INTERVAL_US) {
+			if (!proxy) {
+				aborted = efx_mcdi_request_abort(enp);
+				SFC_EFX_ASSERT(aborted);
+				sfc_efx_mcdi_timeout(mcdi);
+			}
+
+			return;
+		}
+
+		rte_delay_us(delay_us);
+
+		delay_total += delay_us;
+
+		/* Exponentially back off the poll frequency */
+		RTE_BUILD_BUG_ON(SFC_EFX_MCDI_POLL_INTERVAL_MAX_US >
+				 UINT_MAX / 2);
+		delay_us *= 2;
+		if (delay_us > SFC_EFX_MCDI_POLL_INTERVAL_MAX_US)
+			delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MAX_US;
+
+	} while (1);
+}
+
+static void
+sfc_efx_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
+{
+	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
+	uint32_t proxy_handle;
+
+	if (mcdi->state == SFC_EFX_MCDI_DEAD) {
+		emrp->emr_rc = ENOEXEC;
+		return;
+	}
+
+	rte_spinlock_lock(&mcdi->lock);
+
+	SFC_EFX_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
+
+	efx_mcdi_request_start(mcdi->nic, emrp, B_FALSE);
+	sfc_efx_mcdi_poll(mcdi, B_FALSE);
+
+	if (efx_mcdi_get_proxy_handle(mcdi->nic, emrp, &proxy_handle) == 0) {
+		/*
+		 * Authorization is required for the MCDI request;
+		 * wait for an MCDI proxy response event to bring
+		 * a non-zero proxy handle (should be the same as
+		 * the value obtained above) and operation status
+		 */
+		sfc_efx_mcdi_poll(mcdi, B_TRUE);
+
+		if ((mcdi->proxy_handle != 0) &&
+		    (mcdi->proxy_handle != proxy_handle)) {
+			sfc_efx_mcdi_err(mcdi, "Unexpected MCDI proxy event");
+			emrp->emr_rc = EFAULT;
+		} else if (mcdi->proxy_result == 0) {
+			/*
+			 * Authorization succeeded; re-issue the original
+			 * request and poll for an ordinary MCDI response
+			 */
+			efx_mcdi_request_start(mcdi->nic, emrp, B_FALSE);
+			sfc_efx_mcdi_poll(mcdi, B_FALSE);
+		} else {
+			emrp->emr_rc = mcdi->proxy_result;
+			sfc_efx_mcdi_err(mcdi,
+				"MCDI proxy authorization failed (handle=%08x, result=%d)",
+				proxy_handle, mcdi->proxy_result);
+		}
+	}
+
+	rte_spinlock_unlock(&mcdi->lock);
+}
+
+static void
+sfc_efx_mcdi_ev_cpl(void *arg)
+{
+	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
+
+	RTE_SET_USED(mcdi);
+	SFC_EFX_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
+
+	/* MCDI is polled, completions are not expected */
+	SFC_EFX_ASSERT(0);
+}
+
+static void
+sfc_efx_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
+{
+	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
+
+	sfc_efx_mcdi_warn(mcdi, "MC %s",
+	    (eme == EFX_MCDI_EXCEPTION_MC_REBOOT) ? "REBOOT" :
+	    (eme == EFX_MCDI_EXCEPTION_MC_BADASSERT) ? "BADASSERT" : "UNKNOWN");
+
+	mcdi->ops->sched_restart(mcdi->ops_cookie);
+}
+
+#define SFC_MCDI_LOG_BUF_SIZE	128
+
+static size_t
+sfc_efx_mcdi_do_log(const struct sfc_efx_mcdi *mcdi,
+		char *buffer, void *data, size_t data_size,
+		size_t pfxsize, size_t position)
+{
+	uint32_t *words = data;
+	/* Space separator plus 2 characters per byte */
+	const size_t word_str_space = 1 + 2 * sizeof(*words);
+	size_t i;
+
+	for (i = 0; i < data_size; i += sizeof(*words)) {
+		if (position + word_str_space >=
+		    SFC_MCDI_LOG_BUF_SIZE) {
+			/* Flush at SFC_MCDI_LOG_BUF_SIZE with backslash
+			 * at the end which is required by netlogdecode.
+			 */
+			buffer[position] = '\0';
+			sfc_efx_log_mcdi(mcdi, "%s \\", buffer);
+			/* Preserve prefix for the next log message */
+			position = pfxsize;
+		}
+		position += snprintf(buffer + position,
+				     SFC_MCDI_LOG_BUF_SIZE - position,
+				     " %08x", *words);
+		words++;
+	}
+	return position;
+}
+
+static void
+sfc_efx_mcdi_logger(void *arg, efx_log_msg_t type,
+		void *header, size_t header_size,
+		void *data, size_t data_size)
+{
+	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
+	char buffer[SFC_MCDI_LOG_BUF_SIZE];
+	size_t pfxsize;
+	size_t start;
+
+	/*
+	 * Unlike the other cases, MCDI logging implies more onerous work
+	 * needed to produce a message. If the dynamic log level prevents
+	 * the end result from being printed, the CPU time will be wasted.
+	 *
+	 * To avoid wasting time, the actual level is examined in advance.
+	 */
+	if (rte_log_get_level(mcdi->logtype) < (int)SFC_EFX_LOG_LEVEL_MCDI)
+		return;
+
+	/* The format including prefix added by sfc_efx_log_mcdi() is the
+	 * format consumed by the Solarflare netlogdecode tool.
+	 */
+	pfxsize = snprintf(buffer, sizeof(buffer), "MCDI RPC %s:",
+			   type == EFX_LOG_MCDI_REQUEST ? "REQ" :
+			   type == EFX_LOG_MCDI_RESPONSE ? "RESP" : "???");
+	start = sfc_efx_mcdi_do_log(mcdi, buffer, header, header_size,
+				    pfxsize, pfxsize);
+	start = sfc_efx_mcdi_do_log(mcdi, buffer, data, data_size,
+				    pfxsize, start);
+	if (start != pfxsize) {
+		buffer[start] = '\0';
+		sfc_efx_log_mcdi(mcdi, "%s", buffer);
+	}
+}
+
+static void
+sfc_efx_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
+{
+	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
+
+	mcdi->proxy_handle = handle;
+	mcdi->proxy_result = result;
+}
+
+int
+sfc_efx_mcdi_init(struct sfc_efx_mcdi *mcdi,
+		  uint32_t logtype, const char *log_prefix, efx_nic_t *nic,
+		  const struct sfc_efx_mcdi_ops *ops, void *ops_cookie)
+{
+	size_t max_msg_size;
+	efx_mcdi_transport_t *emtp;
+	int rc;
+
+	if (ops->dma_alloc == NULL || ops->dma_free == NULL ||
+	    ops->sched_restart == NULL || ops->mgmt_evq_poll == NULL)
+		return EINVAL;
+
+	SFC_EFX_ASSERT(mcdi->state == SFC_EFX_MCDI_UNINITIALIZED);
+
+	rte_spinlock_init(&mcdi->lock);
+
+	mcdi->ops = ops;
+	mcdi->ops_cookie = ops_cookie;
+	mcdi->nic = nic;
+
+	mcdi->state = SFC_EFX_MCDI_INITIALIZED;
+
+	mcdi->logtype = logtype;
+	mcdi->log_prefix = log_prefix;
+
+	max_msg_size = sizeof(uint32_t) + MCDI_CTL_SDU_LEN_MAX_V2;
+	rc = ops->dma_alloc(ops_cookie, "mcdi", max_msg_size, &mcdi->mem);
+	if (rc != 0)
+		goto fail_dma_alloc;
+
+	emtp = &mcdi->transport;
+	emtp->emt_context = mcdi;
+	emtp->emt_dma_mem = &mcdi->mem;
+	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_efx_mcdi_info(mcdi, "init MCDI");
+	rc = efx_mcdi_init(mcdi->nic, emtp);
+	if (rc != 0)
+		goto fail_mcdi_init;
+
+	return 0;
+
+fail_mcdi_init:
+	memset(emtp, 0, sizeof(*emtp));
+	ops->dma_free(ops_cookie, &mcdi->mem);
+
+fail_dma_alloc:
+	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
+	return rc;
+}
+
+void
+sfc_efx_mcdi_fini(struct sfc_efx_mcdi *mcdi)
+{
+	efx_mcdi_transport_t *emtp;
+
+	emtp = &mcdi->transport;
+
+	rte_spinlock_lock(&mcdi->lock);
+
+	SFC_EFX_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED ||
+		       mcdi->state == SFC_EFX_MCDI_DEAD);
+	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
+
+	sfc_efx_mcdi_info(mcdi, "fini MCDI");
+	efx_mcdi_fini(mcdi->nic);
+	memset(emtp, 0, sizeof(*emtp));
+
+	rte_spinlock_unlock(&mcdi->lock);
+
+	mcdi->ops->dma_free(mcdi->ops_cookie, &mcdi->mem);
+}
diff --git a/drivers/net/sfc/sfc_mcdi.h b/drivers/common/sfc_efx/sfc_efx_mcdi.h
similarity index 81%
rename from drivers/net/sfc/sfc_mcdi.h
rename to drivers/common/sfc_efx/sfc_efx_mcdi.h
index e3a637aeb7..836afacddc 100644
--- a/drivers/net/sfc/sfc_mcdi.h
+++ b/drivers/common/sfc_efx/sfc_efx_mcdi.h
@@ -7,8 +7,8 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
-#ifndef _SFC_MCDI_H
-#define _SFC_MCDI_H
+#ifndef _SFC_EFX_MCDI_H
+#define _SFC_EFX_MCDI_H
 
 #include <stdint.h>
 
@@ -62,8 +62,14 @@ struct sfc_efx_mcdi {
 	const char			*log_prefix;
 };
 
+int sfc_efx_mcdi_init(struct sfc_efx_mcdi *mcdi,
+		      uint32_t logtype, const char *log_prefix,
+		      efx_nic_t *nic,
+		      const struct sfc_efx_mcdi_ops *ops, void *ops_cookie);
+void sfc_efx_mcdi_fini(struct sfc_efx_mcdi *mcdi);
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif  /* _SFC_MCDI_H */
+#endif  /* _SFC_EFX_MCDI_H */
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index b20fecb4f8..fa7c79b80b 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -21,10 +21,11 @@
 
 #include "efx.h"
 
+#include "sfc_efx_mcdi.h"
+
 #include "sfc_debug.h"
 #include "sfc_log.h"
 #include "sfc_filter.h"
-#include "sfc_mcdi.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/drivers/net/sfc/sfc_mcdi.c b/drivers/net/sfc/sfc_mcdi.c
index ff2bc14c5d..644dd9c980 100644
--- a/drivers/net/sfc/sfc_mcdi.c
+++ b/drivers/net/sfc/sfc_mcdi.c
@@ -7,344 +7,13 @@
  * for Solarflare) and Solarflare Communications, Inc.
  */
 
-#include <rte_cycles.h>
+#include "sfc_efx_mcdi.h"
 
-#include "efx.h"
-#include "efx_mcdi.h"
-#include "efx_regs_mcdi.h"
-
-#include "sfc_mcdi.h"
 #include "sfc.h"
 #include "sfc_debug.h"
 #include "sfc_log.h"
 #include "sfc_ev.h"
 
-#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 */
-
-#define sfc_efx_mcdi_log(mcdi, level, ...) \
-	do {								\
-		const struct sfc_efx_mcdi *_mcdi = (mcdi);		\
-									\
-		rte_log(level, _mcdi->logtype,				\
-			RTE_FMT("%s" RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
-				_mcdi->log_prefix,			\
-				RTE_FMT_TAIL(__VA_ARGS__,)));		\
-	} while (0)
-
-#define sfc_efx_mcdi_crit(mcdi, ...) \
-	sfc_efx_mcdi_log(mcdi, RTE_LOG_CRIT, __VA_ARGS__)
-
-#define sfc_efx_mcdi_err(mcdi, ...) \
-	sfc_efx_mcdi_log(mcdi, RTE_LOG_ERR, __VA_ARGS__)
-
-#define sfc_efx_mcdi_warn(mcdi, ...) \
-	sfc_efx_mcdi_log(mcdi, RTE_LOG_WARNING, __VA_ARGS__)
-
-#define sfc_efx_mcdi_info(mcdi, ...) \
-	sfc_efx_mcdi_log(mcdi, RTE_LOG_INFO, __VA_ARGS__)
-
-/** Level value used by MCDI log statements */
-#define SFC_EFX_LOG_LEVEL_MCDI	RTE_LOG_INFO
-
-#define sfc_efx_log_mcdi(mcdi, ...) \
-	sfc_efx_mcdi_log(mcdi, SFC_EFX_LOG_LEVEL_MCDI, __VA_ARGS__)
-
-static void
-sfc_efx_mcdi_timeout(struct sfc_efx_mcdi *mcdi)
-{
-	sfc_efx_mcdi_warn(mcdi, "MC TIMEOUT");
-
-	mcdi->state = SFC_EFX_MCDI_DEAD;
-	sfc_efx_mcdi_crit(mcdi,
-		"MCDI timeout handling is not implemented - NIC is unusable");
-}
-
-static inline boolean_t
-sfc_efx_mcdi_proxy_event_available(struct sfc_efx_mcdi *mcdi)
-{
-	mcdi->proxy_handle = 0;
-	mcdi->proxy_result = ETIMEDOUT;
-	mcdi->ops->mgmt_evq_poll(mcdi->ops_cookie);
-	if (mcdi->proxy_result != ETIMEDOUT)
-		return B_TRUE;
-
-	return B_FALSE;
-}
-
-static void
-sfc_efx_mcdi_poll(struct sfc_efx_mcdi *mcdi, boolean_t proxy)
-{
-	efx_nic_t *enp;
-	unsigned int delay_total;
-	unsigned int delay_us;
-	boolean_t aborted __rte_unused;
-
-	delay_total = 0;
-	delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MIN_US;
-	enp = mcdi->nic;
-
-	do {
-		boolean_t poll_completed;
-
-		poll_completed = (proxy) ?
-				sfc_efx_mcdi_proxy_event_available(mcdi) :
-				efx_mcdi_request_poll(enp);
-		if (poll_completed)
-			return;
-
-		if (delay_total > SFC_EFX_MCDI_WATCHDOG_INTERVAL_US) {
-			if (!proxy) {
-				aborted = efx_mcdi_request_abort(enp);
-				SFC_ASSERT(aborted);
-				sfc_efx_mcdi_timeout(mcdi);
-			}
-
-			return;
-		}
-
-		rte_delay_us(delay_us);
-
-		delay_total += delay_us;
-
-		/* Exponentially back off the poll frequency */
-		RTE_BUILD_BUG_ON(SFC_EFX_MCDI_POLL_INTERVAL_MAX_US >
-				 UINT_MAX / 2);
-		delay_us *= 2;
-		if (delay_us > SFC_EFX_MCDI_POLL_INTERVAL_MAX_US)
-			delay_us = SFC_EFX_MCDI_POLL_INTERVAL_MAX_US;
-
-	} while (1);
-}
-
-static void
-sfc_efx_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
-{
-	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
-	uint32_t proxy_handle;
-
-	if (mcdi->state == SFC_EFX_MCDI_DEAD) {
-		emrp->emr_rc = ENOEXEC;
-		return;
-	}
-
-	rte_spinlock_lock(&mcdi->lock);
-
-	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
-
-	efx_mcdi_request_start(mcdi->nic, emrp, B_FALSE);
-	sfc_efx_mcdi_poll(mcdi, B_FALSE);
-
-	if (efx_mcdi_get_proxy_handle(mcdi->nic, emrp, &proxy_handle) == 0) {
-		/*
-		 * Authorization is required for the MCDI request;
-		 * wait for an MCDI proxy response event to bring
-		 * a non-zero proxy handle (should be the same as
-		 * the value obtained above) and operation status
-		 */
-		sfc_efx_mcdi_poll(mcdi, B_TRUE);
-
-		if ((mcdi->proxy_handle != 0) &&
-		    (mcdi->proxy_handle != proxy_handle)) {
-			sfc_efx_mcdi_err(mcdi, "Unexpected MCDI proxy event");
-			emrp->emr_rc = EFAULT;
-		} else if (mcdi->proxy_result == 0) {
-			/*
-			 * Authorization succeeded; re-issue the original
-			 * request and poll for an ordinary MCDI response
-			 */
-			efx_mcdi_request_start(mcdi->nic, emrp, B_FALSE);
-			sfc_efx_mcdi_poll(mcdi, B_FALSE);
-		} else {
-			emrp->emr_rc = mcdi->proxy_result;
-			sfc_efx_mcdi_err(mcdi,
-				"MCDI proxy authorization failed (handle=%08x, result=%d)",
-				proxy_handle, mcdi->proxy_result);
-		}
-	}
-
-	rte_spinlock_unlock(&mcdi->lock);
-}
-
-static void
-sfc_efx_mcdi_ev_cpl(void *arg)
-{
-	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
-
-	RTE_SET_USED(mcdi);
-	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
-
-	/* MCDI is polled, completions are not expected */
-	SFC_ASSERT(0);
-}
-
-static void
-sfc_efx_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
-{
-	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
-
-	sfc_efx_mcdi_warn(mcdi, "MC %s",
-	    (eme == EFX_MCDI_EXCEPTION_MC_REBOOT) ? "REBOOT" :
-	    (eme == EFX_MCDI_EXCEPTION_MC_BADASSERT) ? "BADASSERT" : "UNKNOWN");
-
-	mcdi->ops->sched_restart(mcdi->ops_cookie);
-}
-
-#define SFC_MCDI_LOG_BUF_SIZE	128
-
-static size_t
-sfc_efx_mcdi_do_log(const struct sfc_efx_mcdi *mcdi,
-		char *buffer, void *data, size_t data_size,
-		size_t pfxsize, size_t position)
-{
-	uint32_t *words = data;
-	/* Space separator plus 2 characters per byte */
-	const size_t word_str_space = 1 + 2 * sizeof(*words);
-	size_t i;
-
-	for (i = 0; i < data_size; i += sizeof(*words)) {
-		if (position + word_str_space >=
-		    SFC_MCDI_LOG_BUF_SIZE) {
-			/* Flush at SFC_MCDI_LOG_BUF_SIZE with backslash
-			 * at the end which is required by netlogdecode.
-			 */
-			buffer[position] = '\0';
-			sfc_efx_log_mcdi(mcdi, "%s \\", buffer);
-			/* Preserve prefix for the next log message */
-			position = pfxsize;
-		}
-		position += snprintf(buffer + position,
-				     SFC_MCDI_LOG_BUF_SIZE - position,
-				     " %08x", *words);
-		words++;
-	}
-	return position;
-}
-
-static void
-sfc_efx_mcdi_logger(void *arg, efx_log_msg_t type,
-		void *header, size_t header_size,
-		void *data, size_t data_size)
-{
-	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
-	char buffer[SFC_MCDI_LOG_BUF_SIZE];
-	size_t pfxsize;
-	size_t start;
-
-	/*
-	 * Unlike the other cases, MCDI logging implies more onerous work
-	 * needed to produce a message. If the dynamic log level prevents
-	 * the end result from being printed, the CPU time will be wasted.
-	 *
-	 * To avoid wasting time, the actual level is examined in advance.
-	 */
-	if (rte_log_get_level(mcdi->logtype) < (int)SFC_EFX_LOG_LEVEL_MCDI)
-		return;
-
-	/* The format including prefix added by sfc_efx_log_mcdi() is the
-	 * format consumed by the Solarflare netlogdecode tool.
-	 */
-	pfxsize = snprintf(buffer, sizeof(buffer), "MCDI RPC %s:",
-			   type == EFX_LOG_MCDI_REQUEST ? "REQ" :
-			   type == EFX_LOG_MCDI_RESPONSE ? "RESP" : "???");
-	start = sfc_efx_mcdi_do_log(mcdi, buffer, header, header_size,
-				    pfxsize, pfxsize);
-	start = sfc_efx_mcdi_do_log(mcdi, buffer, data, data_size,
-				    pfxsize, start);
-	if (start != pfxsize) {
-		buffer[start] = '\0';
-		sfc_efx_log_mcdi(mcdi, "%s", buffer);
-	}
-}
-
-static void
-sfc_efx_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
-{
-	struct sfc_efx_mcdi *mcdi = (struct sfc_efx_mcdi *)arg;
-
-	mcdi->proxy_handle = handle;
-	mcdi->proxy_result = result;
-}
-
-static int
-sfc_efx_mcdi_init(struct sfc_efx_mcdi *mcdi,
-		  uint32_t logtype, const char *log_prefix, efx_nic_t *nic,
-		  const struct sfc_efx_mcdi_ops *ops, void *ops_cookie)
-{
-	size_t max_msg_size;
-	efx_mcdi_transport_t *emtp;
-	int rc;
-
-	if (ops->dma_alloc == NULL || ops->dma_free == NULL ||
-	    ops->sched_restart == NULL || ops->mgmt_evq_poll == NULL)
-		return EINVAL;
-
-	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_UNINITIALIZED);
-
-	rte_spinlock_init(&mcdi->lock);
-
-	mcdi->ops = ops;
-	mcdi->ops_cookie = ops_cookie;
-	mcdi->nic = nic;
-
-	mcdi->state = SFC_EFX_MCDI_INITIALIZED;
-
-	mcdi->logtype = logtype;
-	mcdi->log_prefix = log_prefix;
-
-	max_msg_size = sizeof(uint32_t) + MCDI_CTL_SDU_LEN_MAX_V2;
-	rc = ops->dma_alloc(ops_cookie, "mcdi", max_msg_size, &mcdi->mem);
-	if (rc != 0)
-		goto fail_dma_alloc;
-
-	emtp = &mcdi->transport;
-	emtp->emt_context = mcdi;
-	emtp->emt_dma_mem = &mcdi->mem;
-	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_efx_mcdi_info(mcdi, "init MCDI");
-	rc = efx_mcdi_init(mcdi->nic, emtp);
-	if (rc != 0)
-		goto fail_mcdi_init;
-
-	return 0;
-
-fail_mcdi_init:
-	memset(emtp, 0, sizeof(*emtp));
-	ops->dma_free(ops_cookie, &mcdi->mem);
-
-fail_dma_alloc:
-	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
-	return rc;
-}
-
-static void
-sfc_efx_mcdi_fini(struct sfc_efx_mcdi *mcdi)
-{
-	efx_mcdi_transport_t *emtp;
-
-	emtp = &mcdi->transport;
-
-	rte_spinlock_lock(&mcdi->lock);
-
-	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED ||
-		   mcdi->state == SFC_EFX_MCDI_DEAD);
-	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
-
-	sfc_efx_mcdi_info(mcdi, "fini MCDI");
-	efx_mcdi_fini(mcdi->nic);
-	memset(emtp, 0, sizeof(*emtp));
-
-	rte_spinlock_unlock(&mcdi->lock);
-
-	mcdi->ops->dma_free(mcdi->ops_cookie, &mcdi->mem);
-}
-
 static sfc_efx_mcdi_dma_alloc_cb sfc_mcdi_dma_alloc;
 static int
 sfc_mcdi_dma_alloc(void *cookie, const char *name, size_t len,
-- 
2.17.1


  parent reply	other threads:[~2020-09-08  9:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08  9:14 [dpdk-dev] [PATCH 00/14] net/sfc: factor out common driver library Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 01/14] net/iavf: downgrade error log Andrew Rybchenko
2020-09-08  9:26   ` Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 01/14] net/sfc: include header with debug helpers directly Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 02/14] net/sfc: introduce common driver library Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 03/14] net/sfc: add dedicated header file with MCDI interface Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 04/14] net/sfc: move MCDI helper interface to dedicated namespace Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 05/14] net/sfc: make MCDI logging helper macros local Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 06/14] net/sfc: start to make MCDI helpers interface shareable Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 07/14] net/sfc: use own logging helper macros Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 08/14] net/sfc: avoid usage of NIC pointer from adapter context Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 09/14] net/sfc: avoid panic in the case of MCDI timeout Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 10/14] net/sfc: add MCDI callbacks to allocate/free DMA memory Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 11/14] net/sfc: add MCDI callback to schedule restart Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 12/14] net/sfc: add MCDI callback to poll management event queue Andrew Rybchenko
2020-09-08  9:14 ` [dpdk-dev] [PATCH 13/14] net/sfc: use MCDI control structure as libefx ops context Andrew Rybchenko
2020-09-08  9:14 ` Andrew Rybchenko [this message]
2020-09-09 14:32 ` [dpdk-dev] [PATCH 00/14] net/sfc: factor out common driver library Ferruh Yigit
2020-09-17  6:21   ` Andrew Rybchenko
2020-09-17  6:34 ` [dpdk-dev] [PATCH v2 00/17] " Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 01/17] net/sfc/base: add missing extern storage-class specifiers Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 02/17] net/sfc/base: decorate libefx API functions Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 03/17] net/sfc/base: decorate libefx internal extern functions Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 04/17] net/sfc: include header with debug helpers directly Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 05/17] net/sfc: introduce common driver library Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 06/17] net/sfc: add dedicated header file with MCDI interface Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 07/17] net/sfc: move MCDI helper interface to dedicated namespace Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 08/17] net/sfc: make MCDI logging helper macros local Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 09/17] net/sfc: start to make MCDI helpers interface shareable Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 10/17] net/sfc: use own logging helper macros Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 11/17] net/sfc: avoid usage of NIC pointer from adapter context Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 12/17] net/sfc: avoid panic in the case of MCDI timeout Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 13/17] net/sfc: add MCDI callbacks to allocate/free DMA memory Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 14/17] net/sfc: add MCDI callback to schedule restart Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 15/17] net/sfc: add MCDI callback to poll management event queue Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 16/17] net/sfc: use MCDI control structure as libefx ops context Andrew Rybchenko
2020-09-17  6:34   ` [dpdk-dev] [PATCH v2 17/17] net/sfc: move MCDI helpers to common driver Andrew Rybchenko
2020-09-21 22:38   ` [dpdk-dev] [PATCH v2 00/17] net/sfc: factor out common driver library Ferruh Yigit

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=1599556475-27820-16-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    /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).