DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 07/14] net/sfc: use own logging helper macros
Date: Tue, 8 Sep 2020 10:14:28 +0100
Message-ID: <1599556475-27820-9-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1599556475-27820-1-git-send-email-arybchenko@solarflare.com>

Network driver logging macros depends on sfc_adapter which is
specific to the driver and cannot be used in common code.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc.h        |  2 +
 drivers/net/sfc/sfc_ethdev.c | 13 ++++++
 drivers/net/sfc/sfc_log.h    | 12 ++---
 drivers/net/sfc/sfc_mcdi.c   | 86 +++++++++++++++++++++++-------------
 drivers/net/sfc/sfc_mcdi.h   |  1 +
 5 files changed, 75 insertions(+), 39 deletions(-)

diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index b3ac752334..b20fecb4f8 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -22,6 +22,7 @@
 #include "efx.h"
 
 #include "sfc_debug.h"
+#include "sfc_log.h"
 #include "sfc_filter.h"
 #include "sfc_mcdi.h"
 
@@ -170,6 +171,7 @@ struct sfc_adapter_shared {
 	boolean_t			isolated;
 	uint32_t			tunnel_encaps;
 
+	char				log_prefix[SFC_LOG_PREFIX_MAX];
 	struct rte_pci_addr		pci_addr;
 	uint16_t			port_id;
 
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index acee3e48e4..085f020a4c 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -2136,6 +2136,7 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 	int rc;
 	const efx_nic_cfg_t *encp;
 	const struct rte_ether_addr *from;
+	int ret;
 
 	sfc_register_dp();
 
@@ -2147,6 +2148,18 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
 		return -sfc_eth_dev_secondary_init(dev, logtype_main);
 
 	/* Required for logging */
+	ret = snprintf(sas->log_prefix, sizeof(sas->log_prefix),
+			"PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu16 ": ",
+			pci_dev->addr.domain, pci_dev->addr.bus,
+			pci_dev->addr.devid, pci_dev->addr.function,
+			dev->data->port_id);
+	if (ret < 0 || ret >= (int)sizeof(sas->log_prefix)) {
+		SFC_GENERIC_LOG(ERR,
+			"reserved log prefix is too short for " PCI_PRI_FMT,
+			pci_dev->addr.domain, pci_dev->addr.bus,
+			pci_dev->addr.devid, pci_dev->addr.function);
+		return -EINVAL;
+	}
 	sas->pci_addr = pci_dev->addr;
 	sas->port_id = dev->data->port_id;
 
diff --git a/drivers/net/sfc/sfc_log.h b/drivers/net/sfc/sfc_log.h
index 4bf44b1f15..a2d714afb7 100644
--- a/drivers/net/sfc/sfc_log.h
+++ b/drivers/net/sfc/sfc_log.h
@@ -28,20 +28,16 @@ extern uint32_t sfc_logtype_driver;
 /** Device MCDI log type name prefix */
 #define SFC_LOGTYPE_MCDI_STR	SFC_LOGTYPE_PREFIX "mcdi"
 
+#define SFC_LOG_PREFIX_MAX	32
+
 /* Log PMD message, automatically add prefix and \n */
 #define SFC_LOG(sas, level, type, ...) \
 	do {								\
 		const struct sfc_adapter_shared *_sas = (sas);		\
 									\
 		rte_log(level, type,					\
-			RTE_FMT("PMD: sfc_efx "				\
-				PCI_PRI_FMT " #%" PRIu16		\
-				": " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
-				_sas->pci_addr.domain,			\
-				_sas->pci_addr.bus,			\
-				_sas->pci_addr.devid,			\
-				_sas->pci_addr.function,		\
-				_sas->port_id,				\
+			RTE_FMT("%s" RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",	\
+				_sas->log_prefix,			\
 				RTE_FMT_TAIL(__VA_ARGS__,)));		\
 	} while (0)
 
diff --git a/drivers/net/sfc/sfc_mcdi.c b/drivers/net/sfc/sfc_mcdi.c
index 35e1f3940d..5f6ad0a4aa 100644
--- a/drivers/net/sfc/sfc_mcdi.c
+++ b/drivers/net/sfc/sfc_mcdi.c
@@ -23,21 +23,37 @@
 #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 */
 
-/** Level value used by MCDI log statements */
-#define SFC_EFX_LOG_LEVEL_MCDI	RTE_LOG_INFO
-
-#define sfc_efx_log_mcdi(sa, ...) \
+#define sfc_efx_mcdi_log(mcdi, level, ...) \
 	do {								\
-		const struct sfc_adapter *_sa = (sa);			\
+		const struct sfc_efx_mcdi *_mcdi = (mcdi);		\
 									\
-		SFC_LOG(_sa->priv.shared, SFC_EFX_LOG_LEVEL_MCDI,	\
-			_sa->mcdi.logtype, __VA_ARGS__);		\
+		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_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_adapter *sa)
 {
-	sfc_warn(sa, "MC TIMEOUT");
+	struct sfc_efx_mcdi *mcdi = &sa->mcdi;
+
+	sfc_efx_mcdi_warn(mcdi, "MC TIMEOUT");
 
 	sfc_panic(sa, "MCDI timeout handling is not implemented\n");
 }
@@ -125,7 +141,7 @@ sfc_efx_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 
 		if ((mcdi->proxy_handle != 0) &&
 		    (mcdi->proxy_handle != proxy_handle)) {
-			sfc_err(sa, "Unexpected MCDI proxy event");
+			sfc_efx_mcdi_err(mcdi, "Unexpected MCDI proxy event");
 			emrp->emr_rc = EFAULT;
 		} else if (mcdi->proxy_result == 0) {
 			/*
@@ -136,9 +152,9 @@ sfc_efx_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
 			sfc_efx_mcdi_poll(sa, B_FALSE);
 		} else {
 			emrp->emr_rc = mcdi->proxy_result;
-			sfc_err(sa, "MCDI proxy authorization failed "
-				    "(handle=%08x, result=%d)",
-				    proxy_handle, mcdi->proxy_result);
+			sfc_efx_mcdi_err(mcdi,
+				"MCDI proxy authorization failed (handle=%08x, result=%d)",
+				proxy_handle, mcdi->proxy_result);
 		}
 	}
 
@@ -162,8 +178,9 @@ static void
 sfc_efx_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
+	struct sfc_efx_mcdi *mcdi  = &sa->mcdi;
 
-	sfc_warn(sa, "MC %s",
+	sfc_efx_mcdi_warn(mcdi, "MC %s",
 	    (eme == EFX_MCDI_EXCEPTION_MC_REBOOT) ? "REBOOT" :
 	    (eme == EFX_MCDI_EXCEPTION_MC_BADASSERT) ? "BADASSERT" : "UNKNOWN");
 
@@ -173,7 +190,7 @@ sfc_efx_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
 #define SFC_MCDI_LOG_BUF_SIZE	128
 
 static size_t
-sfc_efx_mcdi_do_log(const struct sfc_adapter *sa,
+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)
 {
@@ -189,7 +206,7 @@ sfc_efx_mcdi_do_log(const struct sfc_adapter *sa,
 			 * at the end which is required by netlogdecode.
 			 */
 			buffer[position] = '\0';
-			sfc_efx_log_mcdi(sa, "%s \\", buffer);
+			sfc_efx_log_mcdi(mcdi, "%s \\", buffer);
 			/* Preserve prefix for the next log message */
 			position = pfxsize;
 		}
@@ -207,6 +224,7 @@ sfc_efx_mcdi_logger(void *arg, efx_log_msg_t type,
 		void *data, size_t data_size)
 {
 	struct sfc_adapter *sa = (struct sfc_adapter *)arg;
+	struct sfc_efx_mcdi *mcdi = &sa->mcdi;
 	char buffer[SFC_MCDI_LOG_BUF_SIZE];
 	size_t pfxsize;
 	size_t start;
@@ -218,7 +236,7 @@ sfc_efx_mcdi_logger(void *arg, efx_log_msg_t type,
 	 *
 	 * To avoid wasting time, the actual level is examined in advance.
 	 */
-	if (rte_log_get_level(sa->mcdi.logtype) < (int)SFC_EFX_LOG_LEVEL_MCDI)
+	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
@@ -227,13 +245,13 @@ sfc_efx_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_efx_mcdi_do_log(sa, buffer, header, header_size,
+	start = sfc_efx_mcdi_do_log(mcdi, buffer, header, header_size,
 				    pfxsize, pfxsize);
-	start = sfc_efx_mcdi_do_log(sa, buffer, data, data_size,
+	start = sfc_efx_mcdi_do_log(mcdi, buffer, data, data_size,
 				    pfxsize, start);
 	if (start != pfxsize) {
 		buffer[start] = '\0';
-		sfc_efx_log_mcdi(sa, "%s", buffer);
+		sfc_efx_log_mcdi(mcdi, "%s", buffer);
 	}
 }
 
@@ -248,30 +266,28 @@ sfc_efx_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
 }
 
 static int
-sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
+sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi,
+		  uint32_t logtype, const char *log_prefix)
 {
 	size_t max_msg_size;
 	efx_mcdi_transport_t *emtp;
 	int rc;
 
-	sfc_log_init(sa, "entry");
-
 	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_UNINITIALIZED);
 
 	rte_spinlock_init(&mcdi->lock);
 
 	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 = sfc_dma_alloc(sa, "mcdi", 0, max_msg_size, sa->socket_id,
 			   &mcdi->mem);
 	if (rc != 0)
 		goto fail_dma_alloc;
 
-	mcdi->logtype = sfc_register_logtype(&sa->priv.shared->pci_addr,
-					     SFC_LOGTYPE_MCDI_STR,
-					     RTE_LOG_NOTICE);
-
 	emtp = &mcdi->transport;
 	emtp->emt_context = sa;
 	emtp->emt_dma_mem = &mcdi->mem;
@@ -281,7 +297,7 @@ sfc_efx_mcdi_init(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
 	emtp->emt_logger = sfc_efx_mcdi_logger;
 	emtp->emt_ev_proxy_response = sfc_efx_mcdi_ev_proxy_response;
 
-	sfc_log_init(sa, "init MCDI");
+	sfc_efx_mcdi_info(mcdi, "init MCDI");
 	rc = efx_mcdi_init(sa->nic, emtp);
 	if (rc != 0)
 		goto fail_mcdi_init;
@@ -302,8 +318,6 @@ sfc_efx_mcdi_fini(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
 {
 	efx_mcdi_transport_t *emtp;
 
-	sfc_log_init(sa, "entry");
-
 	emtp = &mcdi->transport;
 
 	rte_spinlock_lock(&mcdi->lock);
@@ -311,7 +325,7 @@ sfc_efx_mcdi_fini(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
 	SFC_ASSERT(mcdi->state == SFC_EFX_MCDI_INITIALIZED);
 	mcdi->state = SFC_EFX_MCDI_UNINITIALIZED;
 
-	sfc_log_init(sa, "fini MCDI");
+	sfc_efx_mcdi_info(mcdi, "fini MCDI");
 	efx_mcdi_fini(sa->nic);
 	memset(emtp, 0, sizeof(*emtp));
 
@@ -323,11 +337,21 @@ sfc_efx_mcdi_fini(struct sfc_adapter *sa, struct sfc_efx_mcdi *mcdi)
 int
 sfc_mcdi_init(struct sfc_adapter *sa)
 {
-	return sfc_efx_mcdi_init(sa, &sa->mcdi);
+	uint32_t logtype;
+
+	sfc_log_init(sa, "entry");
+
+	logtype = sfc_register_logtype(&sa->priv.shared->pci_addr,
+				       SFC_LOGTYPE_MCDI_STR,
+				       RTE_LOG_NOTICE);
+
+	return sfc_efx_mcdi_init(sa, &sa->mcdi, logtype,
+				 sa->priv.shared->log_prefix);
 }
 
 void
 sfc_mcdi_fini(struct sfc_adapter *sa)
 {
+	sfc_log_init(sa, "entry");
 	sfc_efx_mcdi_fini(sa, &sa->mcdi);
 }
diff --git a/drivers/net/sfc/sfc_mcdi.h b/drivers/net/sfc/sfc_mcdi.h
index 10f5bab666..0194825bfa 100644
--- a/drivers/net/sfc/sfc_mcdi.h
+++ b/drivers/net/sfc/sfc_mcdi.h
@@ -39,6 +39,7 @@ struct sfc_efx_mcdi {
 	uint32_t			logtype;
 	uint32_t			proxy_handle;
 	efx_rc_t			proxy_result;
+	const char			*log_prefix;
 };
 
 #ifdef __cplusplus
-- 
2.17.1


  parent reply	other threads:[~2020-09-08  9:16 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 ` Andrew Rybchenko [this message]
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 ` [dpdk-dev] [PATCH 14/14] net/sfc: move MCDI helpers to common driver Andrew Rybchenko
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-9-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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git