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 iscsi_general_purpose_overview General Purpose APIs
40  * - @ref debug
41  *
42  * <div class="overview">
43  *
44  * <h2>Debug Support Functions</h2>
45  *
46  * These functions provide general purpose debug facilities.
47  * <br><br>
48  * </div><!-- overview -->
49  */
50 
51 #ifndef _OCS_DEBUG_H
52 #define _OCS_DEBUG_H
53 
54 /* Uncomment this line to enable logging extended queue history
55  */
56 //#define OCS_DEBUG_QUEUE_HISTORY
57 
58 
59 /* Allocate maximum allowed (4M) */
60 #if defined(OCS_DEBUG_QUEUE_HISTORY)
61 #define OCS_Q_HIST_SIZE (1000000UL) /* Size in words */
62 #endif
63 
64 extern void ocs_dump32(uint32_t, ocs_os_handle_t, const char *, void *, uint32_t);
65 extern void ocs_swap_and_dump32(uint32_t, ocs_os_handle_t, const char *, void *, uint32_t);
66 extern void ocs_debug_enable(uint32_t mask);
67 extern void ocs_debug_disable(uint32_t mask);
68 extern int ocs_debug_is_enabled(uint32_t mask);
69 extern void ocs_debug_attach(void *);
70 extern void ocs_debug_detach(void *);
71 
72 #define OCS_LOG_ENABLE_SCSI_TGT_TRACE(ocs) ocs_debug_is_enabled(OCS_DEBUG_ENABLE_SCSI_TGT_TRACE)
73 
74 #define OCS_LOG_ENABLE_Q_FULL_BUSY_MSG(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 5)) != 0) : 0)
75 #define OCS_LOG_ENABLE_IO_ERRORS(ocs) (((ocs) != NULL) ? (((ocs)->logmask & (1U << 6)) != 0) : 0)
76 
77 #if defined(OCS_DEBUG_QUEUE_HISTORY)
78 /**
79  * @brief Queue history footer
80  */
81 typedef union ocs_q_hist_ftr_u {
82  uint32_t word;
83  struct {
84 #define Q_HIST_TYPE_LEN 4
85 #define Q_HIST_MASK_LEN 28
86  uint32_t mask:Q_HIST_MASK_LEN,
87  type:Q_HIST_TYPE_LEN;
88  } s;
89 } ocs_q_hist_ftr_t;
90 
91 /**
92  * @brief Queue history type
93  */
94 typedef enum {
95  /* changes need to be made to ocs_queue_history_type_name() as well */
96  OCS_Q_HIST_TYPE_WQE = 0,
97  OCS_Q_HIST_TYPE_CQE_RQ,
98  OCS_Q_HIST_TYPE_CQE_TCP_ACK,
99  OCS_Q_HIST_TYPE_CQE_INI_IO,
100  OCS_Q_HIST_TYPE_CQE_TGT_IO,
101  OCS_Q_HIST_TYPE_CQE_CMDINV,
102  OCS_Q_HIST_TYPE_CQE_ASYNC,
103  OCS_Q_HIST_TYPE_CQE_MQ,
104  OCS_Q_HIST_TYPE_CQE_CNXINV,
105  OCS_Q_HIST_TYPE_CQE_T_DDIGEST,
106  OCS_Q_HIST_TYPE_CQE_TX_DIF,
107  OCS_Q_HIST_TYPE_MISC,
108 } ocs_q_hist_type_t;
109 
110 static __inline const char *
111 ocs_queue_history_type_name(ocs_q_hist_type_t type)
112 {
113  switch (type) {
114  case OCS_Q_HIST_TYPE_WQE: return "wqe"; break;
115  case OCS_Q_HIST_TYPE_CQE_RQ: return "cqe rq"; break;
116  case OCS_Q_HIST_TYPE_CQE_TCP_ACK: return "cqe TCP_ACK"; break;
117  case OCS_Q_HIST_TYPE_CQE_INI_IO: return "cqe Ini IO"; break;
118  case OCS_Q_HIST_TYPE_CQE_TGT_IO: return "cqe Tgt IO"; break;
119  case OCS_Q_HIST_TYPE_CQE_CMDINV: return "cqe Cmd Inv"; break;
120  case OCS_Q_HIST_TYPE_CQE_ASYNC: return "cqe Async"; break;
121  case OCS_Q_HIST_TYPE_CQE_MQ: return "cqe MQ"; break;
122  case OCS_Q_HIST_TYPE_CQE_CNXINV: return "cqe Cnx Inv"; break;
123  case OCS_Q_HIST_TYPE_CQE_T_DDIGEST: return "cqe Tgt Data Digest"; break;
124  case OCS_Q_HIST_TYPE_CQE_TX_DIF: return "cqe TX DIF"; break;
125  case OCS_Q_HIST_TYPE_MISC: return "misc"; break;
126  default: return "unknown"; break;
127  }
128 }
129 
130 typedef struct {
131  ocs_t *ocs;
132  uint32_t *q_hist;
133  uint32_t q_hist_index;
134  ocs_lock_t q_hist_lock;
135 } ocs_hal_q_hist_t;
136 
137 extern void ocs_queue_history_cqe(ocs_hal_q_hist_t*, uint8_t, uint32_t *, uint32_t, uint32_t);
138 extern void ocs_queue_history_wq(ocs_hal_q_hist_t*, uint32_t *, uint32_t, uint32_t);
139 extern void ocs_queue_history_misc(ocs_hal_q_hist_t*, uint32_t *, uint32_t);
140 extern void ocs_queue_history_init(ocs_t *, ocs_hal_q_hist_t*);
141 extern void ocs_queue_history_free(ocs_hal_q_hist_t*);
142 extern uint32_t ocs_queue_history_prev_index(uint32_t);
143 extern uint8_t ocs_queue_history_q_info_enabled(void);
144 extern uint8_t ocs_queue_history_timestamp_enabled(void);
145 #else
146 #define ocs_queue_history_wq(...)
147 #define ocs_queue_history_cqe(...)
148 #define ocs_queue_history_misc(...)
149 #define ocs_queue_history_init(...)
150 #define ocs_queue_history_free(...)
151 #endif
152 
153 
154 #define OCS_DEBUG_ALWAYS (1U << 0)
155 #define OCS_DEBUG_ENABLE_MQ_DUMP (1U << 1)
156 #define OCS_DEBUG_ENABLE_CQ_DUMP (1U << 2)
157 #define OCS_DEBUG_ENABLE_WQ_DUMP (1U << 3)
158 #define OCS_DEBUG_ENABLE_IO_TRACE (1U << 4)
159 #define OCS_DEBUG_ENABLE_SM_TRACE (1U << 5)
160 #define OCS_DEBUG_ENABLE_SCSI_TGT_TRACE (1U << 6)
161 #define OCS_DEBUG_ENABLE_ISNS_LOG (1U << 7)
162 
163 #define ocs_assert(cond, ...) \
164  do { \
165  if (!(cond)) { \
166  const char *fn = strrchr(__FILE__, '/'); \
167  ocs_log_err(NULL, "%s(%d) assertion (%s) failed\n", (fn ? fn + 1 : __FILE__), __LINE__, #cond); \
168  ocs_print_stack(); \
169  ocs_save_ddump_all(OCS_DDUMP_FLAGS_WQES|OCS_DDUMP_FLAGS_CQES|OCS_DDUMP_FLAGS_MQES, -1, \
170  TRUE); \
171  return __VA_ARGS__; \
172  } \
173  } while (0)
174 
175 extern void ocs_dump_service_params(const char *label, void *sparms);
176 
177 #if defined(OCS_INCLUDE_DEBUG)
178 #define io_trace(io, fmt, ...) \
179  do { \
180  /* ocs_iscsi_t *iscsi = io->node->iscsi; */ \
181  if (ocs_debug_is_enabled(OCS_DEBUG_ENABLE_IO_TRACE)) \
182  ocs_log_info(iscsi->os, "[%06x][%04x] %s: " fmt, \
183  (io->hio != NULL ? io->hio->icd : -1), \
184  io->init_task_tag, __func__, ##__VA_ARGS__); \
185  } while (0)
186 #else
187 #define io_trace(io, fmt, ...)
188 #endif
189 
190 #endif /* !_OCS_DEBUG_H */
#define ocs_queue_history_misc(...)
Definition: ocs_debug.h:148
void ocs_debug_attach(void *)
#define ocs_queue_history_wq(...)
Definition: ocs_debug.h:146
#define ocs_queue_history_init(...)
Definition: ocs_debug.h:149
void ocs_debug_detach(void *)
#define ocs_queue_history_cqe(...)
Definition: ocs_debug.h:147
void ocs_dump_service_params(const char *label, void *sparms)
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
void ocs_swap_and_dump32(uint32_t mask, ocs_os_handle_t os, const char *label, void *buf, uint32_t buf_length)
Definition: ocs_debug.c:196
#define ocs_queue_history_free(...)
Definition: ocs_debug.h:150
void ocs_debug_enable(uint32_t mask)
enable debug options
Definition: ocs_debug.c:91
int ocs_debug_is_enabled(uint32_t mask)
return true if debug bits are enabled
Definition: ocs_debug.c:122
void ocs_debug_disable(uint32_t mask)
disable debug options
Definition: ocs_debug.c:106