From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 7BD3E5F1A for ; Wed, 21 Mar 2018 12:28:41 +0100 (CET) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 64FE514005A; Wed, 21 Mar 2018 11:28:39 +0000 (UTC) Received: from sfocexch01r.SolarFlarecom.com (10.20.40.34) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Wed, 21 Mar 2018 04:28:36 -0700 Received: from ocex03.SolarFlarecom.com (10.20.40.36) by sfocexch01r.SolarFlarecom.com (10.20.40.34) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Wed, 21 Mar 2018 04:28:33 -0700 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Wed, 21 Mar 2018 04:28:32 -0700 Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com [10.17.10.10]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w2LBSVAf007210; Wed, 21 Mar 2018 11:28:31 GMT Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1]) by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w2LBSVut011323; Wed, 21 Mar 2018 11:28:31 GMT From: Andrew Rybchenko To: CC: Ferruh Yigit , Ivan Malov Date: Wed, 21 Mar 2018 11:28:18 +0000 Message-ID: <1521631701-11282-4-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1521631701-11282-1-git-send-email-arybchenko@solarflare.com> References: <1516899647-8541-1-git-send-email-arybchenko@solarflare.com> <1521631701-11282-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-MDID: 1521631720-CGD9KbVhVSK2 Subject: [dpdk-dev] [PATCH v3 3/6] net/sfc: add support for per-port dynamic logging X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Mar 2018 11:28:41 -0000 From: Ivan Malov Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- doc/guides/nics/sfc_efx.rst | 6 ++++++ drivers/net/sfc/Makefile | 2 +- drivers/net/sfc/sfc.c | 32 ++++++++++++++++++++++++++++++++ drivers/net/sfc/sfc.h | 5 +++++ drivers/net/sfc/sfc_ethdev.c | 3 +++ drivers/net/sfc/sfc_log.h | 41 ++++++++++++++++++++++++++++++++--------- 6 files changed, 79 insertions(+), 10 deletions(-) diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst index 7162ffd..a580d94 100644 --- a/doc/guides/nics/sfc_efx.rst +++ b/doc/guides/nics/sfc_efx.rst @@ -358,3 +358,9 @@ SFC EFX PMD provides the following log types available for control: - ``pmd.net.sfc.driver`` (default level is **6** - ``RTE_LOG_NOTICE``) Affects driver-wide messages unrelated to any particular devices. + +- ``pmd.net.sfc.main`` (default level is **6** - ``RTE_LOG_NOTICE``) + + Matches a subset of per-port log types registered during runtime. + A full name for a particular type may be obtained by appending a + dot and a PCI device identifier (``XXXX:XX:XX.X``) to the prefix. diff --git a/drivers/net/sfc/Makefile b/drivers/net/sfc/Makefile index d2decd0..d3361d1 100644 --- a/drivers/net/sfc/Makefile +++ b/drivers/net/sfc/Makefile @@ -50,7 +50,7 @@ CFLAGS_sfc_ef10_tx.o += -wd3656 endif LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -LDLIBS += -lrte_bus_pci +LDLIBS += -lrte_bus_pci -lrte_pci # # List of base driver object files for which diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index 7eb9305..cb3a581 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -835,3 +835,35 @@ sfc_unprobe(struct sfc_adapter *sa) sfc_flow_fini(sa); sa->state = SFC_ADAPTER_UNINITIALIZED; } + +uint32_t +sfc_register_logtype(struct sfc_adapter *sa, const char *lt_prefix_str, + uint32_t ll_default) +{ + size_t lt_prefix_str_size = strlen(lt_prefix_str); + size_t lt_str_size_max; + char *lt_str = NULL; + int ret; + + if (SIZE_MAX - PCI_PRI_STR_SIZE - 1 > lt_prefix_str_size) { + ++lt_prefix_str_size; /* Reserve space for prefix separator */ + lt_str_size_max = lt_prefix_str_size + PCI_PRI_STR_SIZE + 1; + } else { + return RTE_LOGTYPE_PMD; + } + + lt_str = rte_zmalloc("logtype_str", lt_str_size_max, 0); + if (lt_str == NULL) + return RTE_LOGTYPE_PMD; + + strncpy(lt_str, lt_prefix_str, lt_prefix_str_size); + lt_str[lt_prefix_str_size - 1] = '.'; + rte_pci_device_name(&sa->pci_addr, lt_str + lt_prefix_str_size, + lt_str_size_max - lt_prefix_str_size); + lt_str[lt_str_size_max - 1] = '\0'; + + ret = rte_log_register_type_and_pick_level(lt_str, ll_default); + rte_free(lt_str); + + return (ret < 0) ? RTE_LOGTYPE_PMD : ret; +} diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 7557534..768578e 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -170,6 +170,7 @@ struct sfc_adapter { uint16_t port_id; struct rte_eth_dev *eth_dev; struct rte_kvargs *kvargs; + uint32_t logtype_main; bool debug_init; int socket_id; efsys_bar_t mem_bar; @@ -302,6 +303,10 @@ int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id, size_t len, int socket_id, efsys_mem_t *esmp); void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp); +uint32_t sfc_register_logtype(struct sfc_adapter *sa, + const char *lt_prefix_str, + uint32_t ll_default); + int sfc_probe(struct sfc_adapter *sa); void sfc_unprobe(struct sfc_adapter *sa); int sfc_attach(struct sfc_adapter *sa); diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 341fa46..15aee22 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -1923,6 +1923,9 @@ sfc_eth_dev_init(struct rte_eth_dev *dev) /* Copy PCI device info to the dev->data */ rte_eth_copy_pci_info(dev, pci_dev); + sa->logtype_main = sfc_register_logtype(sa, SFC_LOGTYPE_MAIN_STR, + RTE_LOG_NOTICE); + rc = sfc_kvargs_parse(sa); if (rc != 0) goto fail_kvargs_parse; diff --git a/drivers/net/sfc/sfc_log.h b/drivers/net/sfc/sfc_log.h index ecafffc..ec903db 100644 --- a/drivers/net/sfc/sfc_log.h +++ b/drivers/net/sfc/sfc_log.h @@ -22,14 +22,17 @@ extern uint32_t sfc_logtype_driver; RTE_FMT("PMD: " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ RTE_FMT_TAIL(__VA_ARGS__ ,))) +/** Name prefix for the per-device log type used to report basic information */ +#define SFC_LOGTYPE_MAIN_STR SFC_LOGTYPE_PREFIX "main" + /* Log PMD message, automatically add prefix and \n */ -#define SFC_LOG(sa, level, ...) \ +#define SFC_LOG(sa, level, type, ...) \ do { \ const struct sfc_adapter *__sa = (sa); \ \ - RTE_LOG(level, PMD, \ - RTE_FMT("sfc_efx " PCI_PRI_FMT " #%" PRIu8 ": " \ - RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ + rte_log(level, type, \ + RTE_FMT("PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu8 \ + ": " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ __sa->pci_addr.domain, \ __sa->pci_addr.bus, \ __sa->pci_addr.devid, \ @@ -39,23 +42,43 @@ extern uint32_t sfc_logtype_driver; } while (0) #define sfc_err(sa, ...) \ - SFC_LOG(sa, ERR, __VA_ARGS__) + do { \ + const struct sfc_adapter *_sa = (sa); \ + \ + SFC_LOG(_sa, RTE_LOG_ERR, _sa->logtype_main, \ + __VA_ARGS__); \ + } while (0) #define sfc_warn(sa, ...) \ - SFC_LOG(sa, WARNING, __VA_ARGS__) + do { \ + const struct sfc_adapter *_sa = (sa); \ + \ + SFC_LOG(_sa, RTE_LOG_WARNING, _sa->logtype_main, \ + __VA_ARGS__); \ + } while (0) #define sfc_notice(sa, ...) \ - SFC_LOG(sa, NOTICE, __VA_ARGS__) + do { \ + const struct sfc_adapter *_sa = (sa); \ + \ + SFC_LOG(_sa, RTE_LOG_NOTICE, _sa->logtype_main, \ + __VA_ARGS__); \ + } while (0) #define sfc_info(sa, ...) \ - SFC_LOG(sa, INFO, __VA_ARGS__) + do { \ + const struct sfc_adapter *_sa = (sa); \ + \ + SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main, \ + __VA_ARGS__); \ + } while (0) #define sfc_log_init(sa, ...) \ do { \ const struct sfc_adapter *_sa = (sa); \ \ if (_sa->debug_init) \ - SFC_LOG(_sa, INFO, \ + SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main, \ RTE_FMT("%s(): " \ RTE_FMT_HEAD(__VA_ARGS__,), \ __func__, \ -- 2.7.4