62c4f4dd16f620a1aaa42967151c0ac206ba01f8
[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 /** Device MCDI log type name prefix */
29 #define SFC_LOGTYPE_MCDI_STR    SFC_LOGTYPE_PREFIX "mcdi"
30
31 /** Level value used by MCDI log statements */
32 #define SFC_LOG_LEVEL_MCDI      RTE_LOG_INFO
33
34 /* Log PMD message, automatically add prefix and \n */
35 #define SFC_LOG(sas, level, type, ...) \
36         do {                                                            \
37                 const struct sfc_adapter_shared *_sas = (sas);          \
38                                                                         \
39                 rte_log(level, type,                                    \
40                         RTE_FMT("PMD: sfc_efx "                         \
41                                 PCI_PRI_FMT " #%" PRIu16                \
42                                 ": " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n",  \
43                                 _sas->pci_addr.domain,                  \
44                                 _sas->pci_addr.bus,                     \
45                                 _sas->pci_addr.devid,                   \
46                                 _sas->pci_addr.function,                \
47                                 _sas->port_id,                          \
48                                 RTE_FMT_TAIL(__VA_ARGS__,)));           \
49         } while (0)
50
51 #define sfc_err(sa, ...) \
52         do {                                                            \
53                 const struct sfc_adapter *_sa = (sa);                   \
54                                                                         \
55                 SFC_LOG(_sa->priv.shared, RTE_LOG_ERR,                  \
56                         _sa->priv.logtype_main, __VA_ARGS__);           \
57         } while (0)
58
59 #define sfc_warn(sa, ...) \
60         do {                                                            \
61                 const struct sfc_adapter *_sa = (sa);                   \
62                                                                         \
63                 SFC_LOG(_sa->priv.shared, RTE_LOG_WARNING,              \
64                         _sa->priv.logtype_main, __VA_ARGS__);           \
65         } while (0)
66
67 #define sfc_notice(sa, ...) \
68         do {                                                            \
69                 const struct sfc_adapter *_sa = (sa);                   \
70                                                                         \
71                 SFC_LOG(_sa->priv.shared, RTE_LOG_NOTICE,               \
72                         _sa->priv.logtype_main, __VA_ARGS__);           \
73         } while (0)
74
75 #define sfc_info(sa, ...) \
76         do {                                                            \
77                 const struct sfc_adapter *_sa = (sa);                   \
78                                                                         \
79                 SFC_LOG(_sa->priv.shared, RTE_LOG_INFO,                 \
80                         _sa->priv.logtype_main, __VA_ARGS__);           \
81         } while (0)
82
83 #define sfc_log_init(sa, ...) \
84         do {                                                            \
85                 const struct sfc_adapter *_sa = (sa);                   \
86                                                                         \
87                 SFC_LOG(_sa->priv.shared, RTE_LOG_INFO,                 \
88                         _sa->priv.logtype_main,                         \
89                         RTE_FMT("%s(): "                                \
90                                 RTE_FMT_HEAD(__VA_ARGS__ ,),            \
91                                 __func__,                               \
92                                 RTE_FMT_TAIL(__VA_ARGS__ ,)));          \
93         } while (0)
94
95 #define sfc_log_mcdi(sa, ...) \
96         do {                                                            \
97                 const struct sfc_adapter *_sa = (sa);                   \
98                                                                         \
99                 SFC_LOG(_sa->priv.shared, SFC_LOG_LEVEL_MCDI,           \
100                         _sa->mcdi.logtype, __VA_ARGS__);                \
101         } while (0)
102
103
104 #endif /* _SFC_LOG_H_ */