net/sfc: support per-port dynamic logging
authorIvan Malov <ivan.malov@oktetlabs.ru>
Wed, 21 Mar 2018 11:28:18 +0000 (11:28 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 30 Mar 2018 12:08:44 +0000 (14:08 +0200)
Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
doc/guides/nics/sfc_efx.rst
drivers/net/sfc/Makefile
drivers/net/sfc/sfc.c
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_log.h

index 7162ffd..a580d94 100644 (file)
@@ -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.
index d2decd0..d3361d1 100644 (file)
@@ -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
index 7eb9305..cb3a581 100644 (file)
@@ -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;
+}
index 7557534..768578e 100644 (file)
@@ -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);
index 341fa46..15aee22 100644 (file)
@@ -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;
index ecafffc..ec903db 100644 (file)
@@ -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__,                       \