Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_debug.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * OCS debug declarations
36  */
37 
38 /**
39  * @page fc_general_purpose_overview General Purpose APIs
40  * - @ref debug
41  * - @ref spv
42  *
43  * <div class="overview">
44  *
45  * <h2>Debug Support Functions</h2>
46  *
47  * These functions provide general purpose debug facilities.
48  *
49  * <h2>Sparse Vector</h2>
50  *
51  * See @ref spv and the description in spv.h.
52  *
53  * <br><br>
54  * </div><!-- overview -->
55  */
56 
57 #ifndef _OCS_DEBUG_H
58 #define _OCS_DEBUG_H
59 
60 /* Uncomment this line to enable logging extended queue history
61  */
62 //#define OCS_DEBUG_QUEUE_HISTORY
63 
64 
65 /* Allocate maximum allowed (4M) */
66 #if defined(OCS_DEBUG_QUEUE_HISTORY)
67 #define OCS_Q_HIST_SIZE (1000000UL) /* Size in words */
68 #endif
69 
70 #define OCS_LOG_ENABLE_SM_TRACE(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 0)) != 0) : 0)
71 #define OCS_LOG_ENABLE_ELS_TRACE(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 1)) != 0) : 0)
72 #define OCS_LOG_ENABLE_SCSI_TRACE(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 2)) != 0) : 0)
73 #define OCS_LOG_ENABLE_SCSI_TGT_TRACE(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 3)) != 0) : 0)
74 #define OCS_LOG_ENABLE_DOMAIN_SM_TRACE(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 4)) != 0) : 0)
75 #define OCS_LOG_ENABLE_Q_FULL_BUSY_MSG(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 5)) != 0) : 0)
76 #define OCS_LOG_ENABLE_IO_ERRORS(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 6)) != 0) : 0)
77 
78 
79 extern void ocs_dump32(uint32_t, ocs_os_handle_t, const char *, void *, uint32_t);
80 extern void ocs_debug_enable(uint32_t mask);
81 extern void ocs_debug_disable(uint32_t mask);
82 extern int ocs_debug_is_enabled(uint32_t mask);
83 extern void ocs_debug_attach(void *);
84 extern void ocs_debug_detach(void *);
85 
86 #if defined(OCS_DEBUG_QUEUE_HISTORY)
87 
88 /**
89  * @brief Queue history footer
90  */
91 typedef union ocs_q_hist_ftr_u {
92  uint32_t word;
93  struct {
94 #define Q_HIST_TYPE_LEN 3
95 #define Q_HIST_MASK_LEN 29
96  uint32_t mask:Q_HIST_MASK_LEN,
97  type:Q_HIST_TYPE_LEN;
98  } s;
99 } ocs_q_hist_ftr_t;
100 
101 
102 /**
103  * @brief WQE command mask lookup
104  */
105 typedef struct ocs_q_hist_wqe_mask_s {
106  uint8_t command;
107  uint32_t mask;
108 } ocs_q_hist_wqe_mask_t;
109 
110 /**
111  * @brief CQE mask lookup
112  */
113 typedef struct ocs_q_hist_cqe_mask_s {
114  uint8_t ctype;
115  uint32_t :Q_HIST_MASK_LEN,
116  type:Q_HIST_TYPE_LEN;
117  uint32_t mask;
118  uint32_t mask_err;
119 } ocs_q_hist_cqe_mask_t;
120 
121 /**
122  * @brief Queue history type
123  */
124 typedef enum {
125  /* changes need to be made to ocs_queue_history_type_name() as well */
126  OCS_Q_HIST_TYPE_WQE = 0,
127  OCS_Q_HIST_TYPE_CWQE,
128  OCS_Q_HIST_TYPE_CXABT,
129  OCS_Q_HIST_TYPE_MISC,
130 } ocs_q_hist_type_t;
131 
132 static __inline const char *
133 ocs_queue_history_type_name(ocs_q_hist_type_t type)
134 {
135  switch (type) {
136  case OCS_Q_HIST_TYPE_WQE: return "wqe"; break;
137  case OCS_Q_HIST_TYPE_CWQE: return "wcqe"; break;
138  case OCS_Q_HIST_TYPE_CXABT: return "xacqe"; break;
139  case OCS_Q_HIST_TYPE_MISC: return "misc"; break;
140  default: return "unknown"; break;
141  }
142 }
143 
144 typedef struct {
145  ocs_t *ocs;
146  uint32_t *q_hist;
147  uint32_t q_hist_index;
148  ocs_lock_t q_hist_lock;
149 } ocs_hal_q_hist_t;
150 
151 extern void ocs_queue_history_cqe(ocs_hal_q_hist_t*, uint8_t, uint32_t *, uint8_t, uint32_t, uint32_t);
152 extern void ocs_queue_history_wq(ocs_hal_q_hist_t*, uint32_t *, uint32_t, uint32_t);
153 extern void ocs_queue_history_misc(ocs_hal_q_hist_t*, uint32_t *, uint32_t);
154 extern void ocs_queue_history_init(ocs_t *, ocs_hal_q_hist_t*);
155 extern void ocs_queue_history_free(ocs_hal_q_hist_t*);
156 extern uint32_t ocs_queue_history_prev_index(uint32_t);
157 extern uint8_t ocs_queue_history_q_info_enabled(void);
158 extern uint8_t ocs_queue_history_timestamp_enabled(void);
159 #else
160 #define ocs_queue_history_wq(...)
161 #define ocs_queue_history_cqe(...)
162 #define ocs_queue_history_misc(...)
163 #define ocs_queue_history_init(...)
164 #define ocs_queue_history_free(...)
165 #endif
166 
167 #define OCS_DEBUG_ALWAYS (1U << 0)
168 #define OCS_DEBUG_ENABLE_MQ_DUMP (1U << 1)
169 #define OCS_DEBUG_ENABLE_CQ_DUMP (1U << 2)
170 #define OCS_DEBUG_ENABLE_WQ_DUMP (1U << 3)
171 #define OCS_DEBUG_ENABLE_EQ_DUMP (1U << 4)
172 #define OCS_DEBUG_ENABLE_SPARAM_DUMP (1U << 5)
173 
174 extern void _ocs_assert(const char *cond, const char *filename, int linenum);
175 
176 #define ocs_assert(cond, ...) \
177  do { \
178  if (!(cond)) { \
179  _ocs_assert(#cond, __FILE__, __LINE__); \
180  return __VA_ARGS__; \
181  } \
182  } while (0)
183 
184 extern void ocs_dump_service_params(const char *label, void *sparms);
185 extern void ocs_display_sparams(const char *prelabel, const char *reqlabel, int dest, void *textbuf, void *sparams);
186 
187 #endif /* !_OCS_DEBUG_H */
#define ocs_queue_history_misc(...)
Definition: ocs_debug.h:162
void ocs_debug_attach(void *)
#define ocs_queue_history_wq(...)
Definition: ocs_debug.h:160
#define ocs_queue_history_init(...)
Definition: ocs_debug.h:163
void ocs_debug_detach(void *)
#define ocs_queue_history_cqe(...)
Definition: ocs_debug.h:161
void ocs_dump_service_params(const char *label, void *sparms)
void ocs_display_sparams(const char *prelabel, const char *reqlabel, int dest, void *textbuf, void *sparams)
Display service parameters.
Definition: ocs_debug.c:495
void _ocs_assert(const char *cond, const char *filename, int linenum)
void ocs_dump32(uint32_t mask, ocs_os_handle_t os, const char *label, void *buf, uint32_t buf_length)
Dump 32 bit hex/ascii data.
Definition: ocs_dump32.c:72
#define ocs_queue_history_free(...)
Definition: ocs_debug.h:164
void ocs_debug_enable(uint32_t mask)
enable debug options
Definition: ocs_debug.c:73
int ocs_debug_is_enabled(uint32_t mask)
return true if debug bits are enabled
Definition: ocs_debug.c:106
void ocs_debug_disable(uint32_t mask)
disable debug options
Definition: ocs_debug.c:89