1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Driver for Broadcom MPI3 Storage Controllers
4  *
5  * Copyright (C) 2017-2022 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_IOCTL_ERROR		0x00008000
27 #define MPI3_DEBUG_IOCTL_INFO		0x00010000
28 #define MPI3_DEBUG_SCSI_INFO		0x00020000
29 #define MPI3_DEBUG			0x01000000
30 #define MPI3_DEBUG_SG			0x02000000
31 
32 
33 /*
34  * debug macros
35  */
36 
37 #define ioc_err(ioc, fmt, ...) \
38 	pr_err("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
39 #define ioc_notice(ioc, fmt, ...) \
40 	pr_notice("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
41 #define ioc_warn(ioc, fmt, ...) \
42 	pr_warn("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
43 #define ioc_info(ioc, fmt, ...) \
44 	pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__)
45 
46 #define dprint(ioc, fmt, ...) \
47 	do { \
48 		if (ioc->logging_level & MPI3_DEBUG) \
49 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
50 	} while (0)
51 
52 #define dprint_event_th(ioc, fmt, ...) \
53 	do { \
54 		if (ioc->logging_level & MPI3_DEBUG_EVENT) \
55 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
56 	} while (0)
57 
58 #define dprint_event_bh(ioc, fmt, ...) \
59 	do { \
60 		if (ioc->logging_level & MPI3_DEBUG_EVENT_WORK_TASK) \
61 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
62 	} while (0)
63 
64 #define dprint_init(ioc, fmt, ...) \
65 	do { \
66 		if (ioc->logging_level & MPI3_DEBUG_INIT) \
67 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
68 	} while (0)
69 
70 #define dprint_exit(ioc, fmt, ...) \
71 	do { \
72 		if (ioc->logging_level & MPI3_DEBUG_EXIT) \
73 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
74 	} while (0)
75 
76 #define dprint_tm(ioc, fmt, ...) \
77 	do { \
78 		if (ioc->logging_level & MPI3_DEBUG_TM) \
79 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
80 	} while (0)
81 
82 #define dprint_reply(ioc, fmt, ...) \
83 	do { \
84 		if (ioc->logging_level & MPI3_DEBUG_REPLY) \
85 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
86 	} while (0)
87 
88 #define dprint_reset(ioc, fmt, ...) \
89 	do { \
90 		if (ioc->logging_level & MPI3_DEBUG_RESET) \
91 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
92 	} while (0)
93 
94 #define dprint_scsi_info(ioc, fmt, ...) \
95 	do { \
96 		if (ioc->logging_level & MPI3_DEBUG_SCSI_INFO) \
97 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
98 	} while (0)
99 
100 #define dprint_scsi_err(ioc, fmt, ...) \
101 	do { \
102 		if (ioc->logging_level & MPI3_DEBUG_SCSI_ERROR) \
103 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
104 	} while (0)
105 
106 #define dprint_scsi_command(ioc, SCMD, LOG_LEVEL) \
107 	do { \
108 		if (ioc->logging_level & LOG_LEVEL) \
109 			scsi_print_command(SCMD); \
110 	} while (0)
111 
112 
113 #define dprint_ioctl_info(ioc, fmt, ...) \
114 	do { \
115 		if (ioc->logging_level & MPI3_DEBUG_IOCTL_INFO) \
116 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
117 	} while (0)
118 
119 #define dprint_ioctl_err(ioc, fmt, ...) \
120 	do { \
121 		if (ioc->logging_level & MPI3_DEBUG_IOCTL_ERROR) \
122 			pr_info("%s: " fmt, (ioc)->name, ##__VA_ARGS__); \
123 	} while (0)
124 
125 #endif /* MPT3SAS_DEBUG_H_INCLUDED */
126 
127 /**
128  * dprint_dump_req - print message frame contents
129  * @req: pointer to message frame
130  * @sz: number of dwords
131  */
132 static inline void
133 dprint_dump_req(void *req, int sz)
134 {
135 	int i;
136 	__le32 *mfp = (__le32 *)req;
137 
138 	pr_info("request:\n\t");
139 	for (i = 0; i < sz; i++) {
140 		if (i && ((i % 8) == 0))
141 			pr_info("\n\t");
142 		pr_info("%08x ", le32_to_cpu(mfp[i]));
143 	}
144 	pr_info("\n");
145 }
146