net/sfc: support driver-wide 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 /* Log PMD message, automatically add prefix and \n */
26 #define SFC_LOG(sa, level, ...) \
27         do {                                                            \
28                 const struct sfc_adapter *__sa = (sa);                  \
29                                                                         \
30                 RTE_LOG(level, PMD,                                     \
31                         RTE_FMT("sfc_efx " PCI_PRI_FMT " #%" PRIu8 ": " \
32                                 RTE_FMT_HEAD(__VA_ARGS__,) "\n",        \
33                                 __sa->pci_addr.domain,                  \
34                                 __sa->pci_addr.bus,                     \
35                                 __sa->pci_addr.devid,                   \
36                                 __sa->pci_addr.function,                \
37                                 __sa->port_id,                          \
38                                 RTE_FMT_TAIL(__VA_ARGS__,)));           \
39         } while (0)
40
41 #define sfc_err(sa, ...) \
42         SFC_LOG(sa, ERR, __VA_ARGS__)
43
44 #define sfc_warn(sa, ...) \
45         SFC_LOG(sa, WARNING, __VA_ARGS__)
46
47 #define sfc_notice(sa, ...) \
48         SFC_LOG(sa, NOTICE, __VA_ARGS__)
49
50 #define sfc_info(sa, ...) \
51         SFC_LOG(sa, INFO, __VA_ARGS__)
52
53 #define sfc_log_init(sa, ...) \
54         do {                                                            \
55                 const struct sfc_adapter *_sa = (sa);                   \
56                                                                         \
57                 if (_sa->debug_init)                                    \
58                         SFC_LOG(_sa, INFO,                              \
59                                 RTE_FMT("%s(): "                        \
60                                         RTE_FMT_HEAD(__VA_ARGS__,),     \
61                                         __func__,                       \
62                                         RTE_FMT_TAIL(__VA_ARGS__,)));   \
63         } while (0)
64
65 #endif /* _SFC_LOG_H_ */