Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_ddumplib.c
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  * General diagnostics dump API
36  *
37  */
38 
39 #include "ocs.h"
40 #include "ocs_ddump.h"
41 
42 /**
43  * @brief Generate driver dump start of file information
44  *
45  * The start of file information is added to 'textbuf'
46  *
47  * @param textbuf pointer to driver dump text buffer
48  *
49  * @return none
50  */
51 
52 void
54 {
55  if (!textbuf)
56  ocs_log_info(NULL, "Driver dump begin time %u",
57  ocs_ticks_to_ms(ocs_get_os_ticks()));
58 
59  ocs_textbuf_printf(textbuf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
60 }
61 
62 /**
63  * @brief Generate driver dump end of file information
64  *
65  * The end of file information is added to 'textbuf'
66  *
67  * @param textbuf pointer to driver dump text buffer
68  *
69  * @return none
70  */
71 
72 void
74 {
75 }
76 
77 /**
78  * @brief Generate driver dump section start data
79  *
80  * The driver section start information is added to textbuf
81  *
82  * @param textbuf pointer to text buffer
83  * @param name name of section
84  * @param instance instance number of this section
85  *
86  * @return none
87  */
88 
89 void
90 ocs_ddump_section(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
91 {
92  ocs_textbuf_printf(textbuf, "<%s type=\"section\" instance=\"%d\">\n", name, instance);
93 }
94 
95 /**
96  * @brief Generate driver dump section end data
97  *
98  * The driver section end information is added to textbuf
99  *
100  * @param textbuf pointer to text buffer
101  * @param name name of section
102  * @param instance instance number of this section
103  *
104  * @return none
105  */
106 
107 void
108 ocs_ddump_endsection(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
109 {
110  ocs_textbuf_printf(textbuf, "</%s>\n", name);
111 }
112 
113 /**
114  * @brief Generate driver dump data for a given value
115  *
116  * A value is added to textbuf
117  *
118  * @param textbuf pointer to text buffer
119  * @param name name of variable
120  * @param fmt snprintf format specifier
121  *
122  * @return none
123  */
124 
125 void
126 ocs_ddump_value(ocs_textbuf_t *textbuf, const char *name, const char *fmt, ...)
127 {
128  va_list ap;
129  char valuebuf[64];
130 
131  va_start(ap, fmt);
132  vsnprintf(valuebuf, sizeof(valuebuf), fmt, ap);
133  va_end(ap);
134 
135  ocs_textbuf_printf(textbuf, "<%s>%s</%s>\n", name, valuebuf, name);
136 }
137 
138 
139 /**
140  * @brief Generate driver dump data for an arbitrary buffer of DWORDS
141  *
142  * A status value is added to textbuf
143  *
144  * @param textbuf pointer to text buffer
145  * @param name name of status variable
146  * @param instance instance number of this section
147  * @param buffer buffer to print
148  * @param size size of buffer in bytes
149  *
150  * @return none
151  */
152 
153 void
154 ocs_ddump_buffer(ocs_textbuf_t *textbuf, const char *name, uint32_t instance, void *buffer, uint32_t size)
155 {
156  uint32_t *dword;
157  uint32_t i;
158  uint32_t count;
159 
160  count = size / sizeof(uint32_t);
161 
162  if (count == 0) {
163  return;
164  }
165 
166  ocs_textbuf_printf(textbuf, "<%s type=\"buffer\" instance=\"%d\">\n", name, instance);
167 
168  dword = buffer;
169  for (i = 0; i < count; i++) {
170 #define OCS_NEWLINE_MOD 8
171  ocs_textbuf_printf(textbuf, "%08x ", *dword++);
172  if ((i % OCS_NEWLINE_MOD) == (OCS_NEWLINE_MOD - 1)) {
173  ocs_textbuf_printf(textbuf, "\n");
174  }
175  }
176 
177  ocs_textbuf_printf(textbuf, "</%s>\n", name);
178 }
179 
180 /**
181  * @brief Generate driver dump for queue
182  *
183  * Add queue elements to text buffer
184  *
185  * @param textbuf pointer to driver dump text buffer
186  * @param q_addr address of start of queue
187  * @param size size of each queue entry
188  * @param length number of queue entries in the queue
189  * @param index current index of queue
190  * @param qentries number of most recent queue entries to dump
191  *
192  * @return none
193  */
194 
195 void
196 ocs_ddump_queue_entries(ocs_textbuf_t *textbuf, void *q_addr, uint32_t size,
197  uint32_t length, int32_t index, uint32_t qentries)
198 {
199  uint32_t i;
200  uint32_t j;
201  uint8_t *entry;
202  uint32_t *dword;
203  uint32_t entry_count = 0;
204  uint32_t entry_words = size / sizeof(uint32_t);
205 
206  if (!textbuf)
207  return;
208 
209  if ((qentries == (uint32_t)-1) || (qentries > length)) {
210  /* if qentries is -1 or larger than queue size, dump entire queue */
211  entry_count = length;
212  index = 0;
213  } else {
214  entry_count = qentries;
215 
216  index -= (qentries - 1);
217  if (index < 0) {
218  index += length;
219  }
220 
221  }
222 #define OCS_NEWLINE_MOD 8
223  ocs_textbuf_printf(textbuf, "<qentries>\n");
224  for (i = 0; i < entry_count; i++){
225  entry = q_addr;
226  entry += index * size;
227  dword = (uint32_t *)entry;
228 
229  ocs_textbuf_printf(textbuf, "[%04x] ", index);
230  for (j = 0; j < entry_words; j++) {
231  ocs_textbuf_printf(textbuf, "%08x ", *dword++);
232  if (((j+1) == entry_words) ||
233  ((j % OCS_NEWLINE_MOD) == (OCS_NEWLINE_MOD - 1))) {
234  ocs_textbuf_printf(textbuf, "\n");
235  if ((j+1) < entry_words) {
236  ocs_textbuf_printf(textbuf, " ");
237  }
238  }
239  }
240 
241  index++;
242  if ((uint32_t)index >= length) {
243  index = 0;
244  }
245  }
246  ocs_textbuf_printf(textbuf, "</qentries>\n");
247 }
248 
249 
void ocs_ddump_queue_entries(ocs_textbuf_t *textbuf, void *q_addr, uint32_t size, uint32_t length, int32_t index, uint32_t qentries)
Generate driver dump for queue.
Definition: ocs_ddumplib.c:196
void ocs_ddump_endfile(ocs_textbuf_t *textbuf)
Generate driver dump end of file information.
Definition: ocs_ddumplib.c:73
const char const char void ocs_ddump_buffer(ocs_textbuf_t *textbuf, const char *name, uint32_t instance, void *buffer, uint32_t size)
Generate driver dump data for an arbitrary buffer of DWORDS.
Definition: ocs_ddumplib.c:154
const char * name
Definition: ocs_ddump.h:54
void ocs_ddump_section(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
Generate driver dump section start data.
Definition: ocs_ddumplib.c:90
#define OCS_NEWLINE_MOD
const char const char va_list ap
Definition: ocs_ramlog.h:54
uint32_t entry_count
Definition: ocs_cbuf.c:44
void ocs_ddump_endsection(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
Generate driver dump section end data.
Definition: ocs_ddumplib.c:108
void ocs_ddump_startfile(ocs_textbuf_t *textbuf)
Generate driver dump start of file information.
Definition: ocs_ddumplib.c:53
void ocs_textbuf_printf(ocs_textbuf_t *textbuf, const char *fmt,...)
Helper function to dump message.
Definition: ocs_textbuf.c:238
const char const char * fmt
Definition: ocs_ddump.h:54
void ocs_ddump_value(ocs_textbuf_t *textbuf, const char *name, const char *fmt,...)
Generate driver dump data for a given value.
Definition: ocs_ddumplib.c:126