net/sfc: support per-port dynamic logging
[dpdk.git] / drivers / net / sfc / sfc_log.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2016-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_LOG_H_
11 #define _SFC_LOG_H_
12
13 /** Generic driver log type */
14 extern uint32_t sfc_logtype_driver;
15
16 /** Common log type name prefix */
17 #define SFC_LOGTYPE_PREFIX      "pmd.net.sfc."
18
19 /** Log PMD generic message, add a prefix and a line break */
20 #define SFC_GENERIC_LOG(level, ...) \
21         rte_log(RTE_LOG_ ## level, sfc_logtype_driver,                  \
22                 RTE_FMT("PMD: " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",       \
23                         RTE_FMT_TAIL(__VA_ARGS__ ,)))
24
25 /** Name prefix for the per-device log type used to report basic information */
26 #define SFC_LOGTYPE_MAIN_STR    SFC_LOGTYPE_PREFIX "main"
27
28 /* Log PMD message, automatically add prefix and \n */
29 #define SFC_LOG(sa, level, type, ...) \
30         do {                                                            \
31                 const struct sfc_adapter *__sa = (sa);                  \
32                                                                         \
33                 rte_log(level, type,                                    \
34                         RTE_FMT("PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu8 \
35                                 ": " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",  \
36                                 __sa->pci_addr.domain,                  \
37                                 __sa->pci_addr.bus,                     \
38                                 __sa->pci_addr.devid,                   \
39                                 __sa->pci_addr.function,                \
40                                 __sa->port_id,                          \
41                                 RTE_FMT_TAIL(__VA_ARGS__,)));           \
42         } while (0)
43
44 #define sfc_err(sa, ...) \
45         do {                                                            \
46                 const struct sfc_adapter *_sa = (sa);                   \
47                                                                         \
48                 SFC_LOG(_sa, RTE_LOG_ERR, _sa->logtype_main,            \
49                         __VA_ARGS__);                                   \
50         } while (0)
51
52 #define sfc_warn(sa, ...) \
53         do {                                                            \
54                 const struct sfc_adapter *_sa = (sa);                   \
55                                                                         \
56                 SFC_LOG(_sa, RTE_LOG_WARNING, _sa->logtype_main,        \
57                         __VA_ARGS__);                                   \
58         } while (0)
59
60 #define sfc_notice(sa, ...) \
61         do {                                                            \
62                 const struct sfc_adapter *_sa = (sa);                   \
63                                                                         \
64                 SFC_LOG(_sa, RTE_LOG_NOTICE, _sa->logtype_main,         \
65                         __VA_ARGS__);                                   \
66         } while (0)
67
68 #define sfc_info(sa, ...) \
69         do {                                                            \
70                 const struct sfc_adapter *_sa = (sa);                   \
71                                                                         \
72                 SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main,           \
73                         __VA_ARGS__);                                   \
74         } while (0)
75
76 #define sfc_log_init(sa, ...) \
77         do {                                                            \
78                 const struct sfc_adapter *_sa = (sa);                   \
79                                                                         \
80                 if (_sa->debug_init)                                    \
81                         SFC_LOG(_sa, RTE_LOG_INFO, _sa->logtype_main,   \
82                                 RTE_FMT("%s(): "                        \
83                                         RTE_FMT_HEAD(__VA_ARGS__,),     \
84                                         __func__,                       \
85                                         RTE_FMT_TAIL(__VA_ARGS__,)));   \
86         } while (0)
87
88 #endif /* _SFC_LOG_H_ */