From dad99d926772c0c0e9d4ce792eba7787a0e601a3 Mon Sep 17 00:00:00 2001 From: Ivan Malov Date: Wed, 21 Mar 2018 11:28:18 +0000 Subject: [PATCH] net/sfc: support per-port dynamic logging 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 7162ffd1cc..a580d94067 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 d2decd09e9..d3361d1399 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 7eb9305b66..cb3a581ae1 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 75575349ba..768578e4cc 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 341fa46b28..15aee22299 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 ecafffc08b..ec903db36d 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.20.1