1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Driver for Broadcom MPI3 Storage Controllers
4 *
5 * Copyright (C) 2017-2023 Broadcom Inc.
6 * (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
7 *
8 */
9
10 #ifndef MPI3SAS_DEBUG_H_INCLUDED
11
12 #define MPI3SAS_DEBUG_H_INCLUDED
13
14 /*
15 * debug levels
16 */
17
18 #define MPI3_DEBUG_EVENT 0x00000001
19 #define MPI3_DEBUG_EVENT_WORK_TASK 0x00000002
20 #define MPI3_DEBUG_INIT 0x00000004
21 #define MPI3_DEBUG_EXIT 0x00000008
22 #define MPI3_DEBUG_TM 0x00000010
23 #define MPI3_DEBUG_RESET 0x00000020
24 #define MPI3_DEBUG_SCSI_ERROR 0x00000040
25 #define MPI3_DEBUG_REPLY 0x00000080
26 #define MPI3_DEBUG_CFG_ERROR 0x00000100
27 #define MPI3_DEBUG_TRANSPORT_ERROR 0x00000200
28 #define MPI3_DEBUG_BSG_ERROR 0x00008000
29 #define MPI3_DEBUG_BSG_INFO 0x00010000
30 #define MPI3_DEBUG_SCSI_INFO 0x00020000
31 #define MPI3_DEBUG_CFG_INFO 0x00040000
32 #define MPI3_DEBUG_TRANSPORT_INFO 0x00080000
33 #define MPI3_DEBUG 0x01000000
34 #define MPI3_DEBUG_SG 0x02000000
35
36
37 /*
38 * debug macros
39 */
40
41 #define ioc_err(ioc, fmt, ...) \
42 pr_err("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
43 #define ioc_notice(ioc, fmt, ...) \
44 pr_notice("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
45 #define ioc_warn(ioc, fmt, ...) \
46 pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
47 #define ioc_info(ioc, fmt, ...) \
48 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
49
50 #define dprint(ioc, fmt, ...) \
51 do { \
52 if (ioc->logging_level & MPI3_DEBUG) \
53 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
54 } while (0)
55
56 #define dprint_event_th(ioc, fmt, ...) \
57 do { \
58 if (ioc->logging_level & MPI3_DEBUG_EVENT) \
59 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
60 } while (0)
61
62 #define dprint_event_bh(ioc, fmt, ...) \
63 do { \
64 if (ioc->logging_level & MPI3_DEBUG_EVENT_WORK_TASK) \
65 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
66 } while (0)
67
68 #define dprint_init(ioc, fmt, ...) \
69 do { \
70 if (ioc->logging_level & MPI3_DEBUG_INIT) \
71 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
72 } while (0)
73
74 #define dprint_exit(ioc, fmt, ...) \
75 do { \
76 if (ioc->logging_level & MPI3_DEBUG_EXIT) \
77 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
78 } while (0)
79
80 #define dprint_tm(ioc, fmt, ...) \
81 do { \
82 if (ioc->logging_level & MPI3_DEBUG_TM) \
83 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
84 } while (0)
85
86 #define dprint_reply(ioc, fmt, ...) \
87 do { \
88 if (ioc->logging_level & MPI3_DEBUG_REPLY) \
89 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
90 } while (0)
91
92 #define dprint_reset(ioc, fmt, ...) \
93 do { \
94 if (ioc->logging_level & MPI3_DEBUG_RESET) \
95 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
96 } while (0)
97
98 #define dprint_scsi_info(ioc, fmt, ...) \
99 do { \
100 if (ioc->logging_level & MPI3_DEBUG_SCSI_INFO) \
101 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
102 } while (0)
103
104 #define dprint_scsi_err(ioc, fmt, ...) \
105 do { \
106 if (ioc->logging_level & MPI3_DEBUG_SCSI_ERROR) \
107 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
108 } while (0)
109
110 #define dprint_scsi_command(ioc, SCMD, LOG_LEVEL) \
111 do { \
112 if (ioc->logging_level & LOG_LEVEL) \
113 scsi_print_command(SCMD); \
114 } while (0)
115
116
117 #define dprint_bsg_info(ioc, fmt, ...) \
118 do { \
119 if (ioc->logging_level & MPI3_DEBUG_BSG_INFO) \
120 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
121 } while (0)
122
123 #define dprint_bsg_err(ioc, fmt, ...) \
124 do { \
125 if (ioc->logging_level & MPI3_DEBUG_BSG_ERROR) \
126 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
127 } while (0)
128
129 #define dprint_cfg_info(ioc, fmt, ...) \
130 do { \
131 if (ioc->logging_level & MPI3_DEBUG_CFG_INFO) \
132 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
133 } while (0)
134
135 #define dprint_cfg_err(ioc, fmt, ...) \
136 do { \
137 if (ioc->logging_level & MPI3_DEBUG_CFG_ERROR) \
138 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
139 } while (0)
140 #define dprint_transport_info(ioc, fmt, ...) \
141 do { \
142 if (ioc->logging_level & MPI3_DEBUG_TRANSPORT_INFO) \
143 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
144 } while (0)
145
146 #define dprint_transport_err(ioc, fmt, ...) \
147 do { \
148 if (ioc->logging_level & MPI3_DEBUG_TRANSPORT_ERROR) \
149 pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
150 } while (0)
151
152 #endif /* MPT3SAS_DEBUG_H_INCLUDED */
153
154 /**
155 * dprint_dump - print contents of a memory buffer
156 * @req: Pointer to a memory buffer
157 * @sz: Memory buffer size
158 * @namestr: Name String to identify the buffer type
159 */
160 static inline void
dprint_dump(void * req,int sz,const char * name_string)161 dprint_dump(void *req, int sz, const char *name_string)
162 {
163 int i;
164 __le32 *mfp = (__le32 *)req;
165
166 sz = sz/4;
167 if (name_string)
168 pr_info("%s:\n\t", name_string);
169 else
170 pr_info("request:\n\t");
171 for (i = 0; i < sz; i++) {
172 if (i && ((i % 8) == 0))
173 pr_info("\n\t");
174 pr_info("%08x ", le32_to_cpu(mfp[i]));
175 }
176 pr_info("\n");
177 }
178
179 /**
180 * dprint_dump_req - print message frame contents
181 * @req: pointer to message frame
182 * @sz: number of dwords
183 */
184 static inline void
dprint_dump_req(void * req,int sz)185 dprint_dump_req(void *req, int sz)
186 {
187 int i;
188 __le32 *mfp = (__le32 *)req;
189
190 pr_info("request:\n\t");
191 for (i = 0; i < sz; i++) {
192 if (i && ((i % 8) == 0))
193 pr_info("\n\t");
194 pr_info("%08x ", le32_to_cpu(mfp[i]));
195 }
196 pr_info("\n");
197 }
198