Print this page
8368 remove warlock leftovers from usr/src/uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/ibtl/ibtl_util.c
+++ new/usr/src/uts/common/io/ib/ibtl/ibtl_util.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * ibtf_util.c
28 28 *
29 29 * This file contains the IBTF module's helper/utility functions.
30 30 * - IBTF logging support
31 31 */
32 32
33 33 #include <sys/ib/ibtl/impl/ibtl.h>
34 34
35 35 static char ibtf_util[] = "ibtl_util";
36 36
37 37 /* Function Prototypes */
38 38 static void ibtf_clear_print_buf();
39 39
40 40 /*
41 41 * Print Buffer protected by mutex for debug stuff. The mutex also
42 42 * ensures serializing debug messages.
43 43 */
44 44 static kmutex_t ibtf_print_mutex;
45 45 static char ibtf_print_buf[IBTL_PRINT_BUF_LEN];
46 46
47 47 /*
48 48 * Debug Stuff.
49 49 */
50 50 uint_t ibtf_errlevel = IBTF_LOG_L5;
51 51 uint_t ibgen_errlevel = IBTF_LOG_L2;
52 52 uint_t ibtl_errlevel = IBTF_LOG_L2;
53 53 uint_t ibcm_errlevel = IBTF_LOG_L2;
54 54 uint_t ibdm_errlevel = IBTF_LOG_L2;
55 55 uint_t ibnex_errlevel = IBTF_LOG_L2;
56 56
57 57 #define IBTF_DEBUG_SIZE_EXTRA_ALLOC 8
58 58 #define IBTF_MIN_DEBUG_BUF_SIZE 0x1000
59 59 #ifdef DEBUG
60 60 #define IBTF_DEBUG_BUF_SIZE 0x10000
61 61 #else
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
62 62 #define IBTF_DEBUG_BUF_SIZE 0x2000
63 63 #endif /* DEBUG */
64 64
65 65 int ibtf_suppress_dprintf; /* Suppress debug printing */
66 66 int ibtf_buffer_dprintf = 1; /* Use a debug print buffer */
67 67 int ibtf_debug_buf_size = IBTF_DEBUG_BUF_SIZE; /* Sz of Debug buf */
68 68 int ibtf_allow_intr_msgs = 0; /* log "intr" messages */
69 69 char *ibtf_debug_buf = NULL; /* The Debug Buf */
70 70 char *ibtf_buf_sptr, *ibtf_buf_eptr; /* debug buffer temp pointer */
71 71 int ibtf_clear_debug_buf_flag = 0; /* Clear debug buffer */
72 -_NOTE(SCHEME_PROTECTS_DATA("inconsistency OK", ibtf_debug_buf_size))
73 72
74 73 longlong_t ibtl_ib2usec_tbl[64]; /* time conversion table */
75 -_NOTE(SCHEME_PROTECTS_DATA("inconsistency OK", ibtl_ib2usec_tbl))
76 74
77 -_NOTE(MUTEX_PROTECTS_DATA(ibtf_print_mutex, ibtf_buf_sptr ibtf_buf_eptr))
78 -
79 75 /*
80 76 * Function:
81 77 * ibtl_ib2usec_init
82 78 * Input:
83 79 * none
84 80 * Output:
85 81 * none
86 82 * Returns:
87 83 * none
88 84 * Description:
89 85 * Initialize ibtl_ib2usec_tbl[64] for use by ibt_usec2ib and ibt_ib2usec.
90 86 */
91 87 void
92 88 ibtl_ib2usec_init(void)
93 89 {
94 90 int i;
95 91
96 92 for (i = 0; i < 64; i++) {
97 93 if (i < 51) { /* shift first to avoid underflow */
98 94 ibtl_ib2usec_tbl[i] = ((1LL << i) << 12LL) / 1000LL;
99 95 } else if (i < 61) { /* divide first to avoid overflow */
100 96 ibtl_ib2usec_tbl[i] = ((1LL << i) / 1000LL) << 12LL;
101 97 } else { /* max'ed out, so use MAX LONGLONG */
102 98 ibtl_ib2usec_tbl[i] = 0x7FFFFFFFFFFFFFFFLL;
103 99 }
104 100 #if !defined(_LP64)
105 101 if (ibtl_ib2usec_tbl[i] > LONG_MAX)
106 102 ibtl_ib2usec_tbl[i] = LONG_MAX;
107 103 #endif
108 104 }
109 105 }
110 106
111 107 /*
112 108 * Function:
113 109 * ibt_usec2ib
114 110 * Input:
115 111 * time_val - Time in microsecs.
116 112 * Output:
117 113 * none
118 114 * Returns:
119 115 * Nearest IB Timeout Exponent value.
120 116 * Description:
121 117 * This function converts the standard input time in microseconds to
122 118 * IB's 6 bits of timeout exponent, calculated based on
123 119 * time = 4.096us * 2 ^ exp. This is done by searching through
124 120 * the ibtl_ib2usec_tbl for the closest value >= time_val.
125 121 */
126 122 ib_time_t
127 123 ibt_usec2ib(clock_t time_val)
128 124 {
129 125 int i;
130 126
131 127 IBTF_DPRINTF_L3(ibtf_util, "ibt_usec2ib(%ld)", time_val);
132 128
133 129 /* First, leap through the table by 4 entries at a time */
134 130 for (i = 0; (i + 4) < 64 && ibtl_ib2usec_tbl[i + 4] < time_val; i += 4)
135 131 ;
136 132 /* Find the return value; it's now between i and i + 4, inclusive */
137 133 while (ibtl_ib2usec_tbl[i] < time_val)
138 134 i++;
139 135 return (i);
140 136 }
141 137
142 138
143 139 /*
144 140 * Function:
145 141 * ibt_ib2usec
146 142 * Input:
147 143 * ib_time - IB Timeout Exponent value.
148 144 * Output:
149 145 * none
150 146 * Returns:
151 147 * Standard Time is microseconds.
152 148 * Description:
153 149 * This function converts the input IB timeout exponent (6 bits) to
154 150 * standard time in microseconds, calculated based on
155 151 * time = 4.096us * 2 ^ exp.
156 152 * This is implemented as a simple index into ibtl_ib2usec_tbl[].
157 153 */
158 154 clock_t
159 155 ibt_ib2usec(ib_time_t ib_time)
160 156 {
161 157 IBTF_DPRINTF_L3(ibtf_util, "ibt_ib2usec(%d)", ib_time);
162 158
163 159 return ((clock_t)ibtl_ib2usec_tbl[ib_time & IB_TIME_EXP_MASK]);
164 160 }
165 161
166 162
167 163 /* IBTF logging init */
168 164 void
169 165 ibtl_logging_initialization()
170 166 {
171 167 boolean_t flag = B_FALSE;
172 168
173 169 IBTF_DPRINTF_L3(ibtf_util, "ibtl_logging_initialization:");
174 170
175 171 mutex_init(&ibtf_print_mutex, NULL, MUTEX_DRIVER, NULL);
176 172 mutex_enter(&ibtf_print_mutex);
177 173
178 174 if (ibtf_debug_buf_size <= IBTF_DEBUG_SIZE_EXTRA_ALLOC) {
179 175 ibtf_debug_buf_size = IBTF_MIN_DEBUG_BUF_SIZE;
180 176 flag = B_TRUE;
181 177 }
182 178
183 179 /* if it is less that IBTF_MIN_DEBUG_BUF_SIZE, adjust it */
184 180 ibtf_debug_buf_size = max(IBTF_MIN_DEBUG_BUF_SIZE,
185 181 ibtf_debug_buf_size);
186 182
187 183 ibtf_debug_buf = (char *)kmem_alloc(ibtf_debug_buf_size, KM_SLEEP);
188 184 ibtf_clear_print_buf();
189 185 mutex_exit(&ibtf_print_mutex);
190 186
191 187 if (flag == B_TRUE) {
192 188 IBTF_DPRINTF_L2(ibtf_util, "ibtf_debug_buf_size was too small "
193 189 "%x, adjusted to %x", ibtf_debug_buf_size,
194 190 IBTF_MIN_DEBUG_BUF_SIZE);
195 191 }
196 192 }
197 193
198 194
199 195 /* IBTF logging destroy */
200 196 void
201 197 ibtl_logging_destroy()
202 198 {
203 199 IBTF_DPRINTF_L3(ibtf_util, "ibtl_logging_destroy");
204 200
205 201 mutex_enter(&ibtf_print_mutex);
206 202 if (ibtf_debug_buf) {
207 203 kmem_free(ibtf_debug_buf, ibtf_debug_buf_size);
208 204 ibtf_debug_buf = NULL;
209 205 }
210 206 mutex_exit(&ibtf_print_mutex);
211 207 mutex_destroy(&ibtf_print_mutex);
212 208 }
213 209
214 210
215 211 /*
216 212 * debug, log, and console message handling
217 213 */
218 214
219 215 /*
220 216 * clear the IBTF trace buffer
221 217 */
222 218 static void
223 219 ibtf_clear_print_buf()
224 220 {
225 221 ASSERT(MUTEX_HELD(&ibtf_print_mutex));
226 222 if (ibtf_debug_buf) {
227 223 ibtf_buf_sptr = ibtf_debug_buf;
228 224 ibtf_buf_eptr = ibtf_debug_buf + ibtf_debug_buf_size -
229 225 IBTF_DEBUG_SIZE_EXTRA_ALLOC;
230 226
231 227 bzero(ibtf_debug_buf, ibtf_debug_buf_size);
232 228 }
233 229 }
234 230
235 231
236 232 static void
237 233 ibtf_vlog(char *name, uint_t level, char *fmt, va_list ap)
238 234 {
239 235 char *label = (name == NULL) ? "ibtl" : name;
240 236 char *msg_ptr;
241 237 size_t len;
242 238
243 239 mutex_enter(&ibtf_print_mutex);
244 240
245 241 /* if not using logging scheme; quit */
246 242 if (ibtf_suppress_dprintf || (ibtf_debug_buf == NULL)) {
247 243 mutex_exit(&ibtf_print_mutex);
248 244 return;
249 245 }
250 246
251 247 /* if level doesn't match, we are done */
252 248 if ((level < IBTF_LOG_L0) || (level > IBTF_LOG_LINTR)) {
253 249 mutex_exit(&ibtf_print_mutex);
254 250 return;
255 251 }
256 252
257 253 /* If user requests to clear debug buffer, go ahead */
258 254 if (ibtf_clear_debug_buf_flag != 0) {
259 255 ibtf_clear_print_buf();
260 256 ibtf_clear_debug_buf_flag = 0;
261 257 }
262 258
263 259 /*
264 260 * Check if we have a valid buf size?
265 261 * Suppress logging to ibtf_buffer if so.
266 262 */
267 263 if (ibtf_debug_buf_size <= 0) {
268 264 ibtf_buffer_dprintf = 0;
269 265 }
270 266
271 267 /*
272 268 * put "label" into the buffer
273 269 */
274 270 len = snprintf(ibtf_print_buf, IBTL_DRVNAME_LEN, "%s:\t", label);
275 271
276 272 msg_ptr = ibtf_print_buf + len;
277 273 len += vsnprintf(msg_ptr, IBTL_PRINT_BUF_LEN - len - 2, fmt, ap);
278 274
279 275 len = min(len, IBTL_PRINT_BUF_LEN - 2);
280 276 ASSERT(len == strlen(ibtf_print_buf));
281 277 ibtf_print_buf[len++] = '\n';
282 278 ibtf_print_buf[len] = '\0';
283 279
284 280 /*
285 281 * stuff the message in the debug buf
286 282 */
287 283 if (ibtf_buffer_dprintf) {
288 284
289 285 /*
290 286 * overwrite >>>> that might be over the end of the
291 287 * the buffer
292 288 */
293 289 *ibtf_buf_sptr = '\0';
294 290
295 291 if (ibtf_buf_sptr + len > ibtf_buf_eptr) {
296 292 size_t left = ibtf_buf_eptr - ibtf_buf_sptr;
297 293
298 294 bcopy((caddr_t)ibtf_print_buf,
299 295 (caddr_t)ibtf_buf_sptr, left);
300 296 bcopy((caddr_t)ibtf_print_buf + left,
301 297 (caddr_t)ibtf_debug_buf, len - left);
302 298 ibtf_buf_sptr = ibtf_debug_buf + len - left;
303 299 } else {
304 300 bcopy((caddr_t)ibtf_print_buf, ibtf_buf_sptr, len);
305 301 ibtf_buf_sptr += len;
306 302 }
307 303
308 304 /* add marker */
309 305 (void) sprintf(ibtf_buf_sptr, ">>>>");
310 306 }
311 307
312 308 /*
313 309 * LINTR, L5-L2 message may go to the ibtf_debug_buf
314 310 * L1 messages will go to the log buf in non-debug kernels and
315 311 * to console and log buf in debug kernels
316 312 * L0 messages are warnings and will go to console and log buf
317 313 */
318 314 switch (level) {
319 315 case IBTF_LOG_LINTR:
320 316 case IBTF_LOG_L5:
321 317 case IBTF_LOG_L4:
322 318 case IBTF_LOG_L3:
323 319 case IBTF_LOG_L2:
324 320 if (!ibtf_buffer_dprintf) {
325 321 cmn_err(CE_CONT, "^%s", ibtf_print_buf);
326 322 }
327 323 break;
328 324 case IBTF_LOG_L1:
329 325 #ifdef DEBUG
330 326 cmn_err(CE_CONT, "%s", ibtf_print_buf);
331 327 #else
332 328 if (!ibtf_buffer_dprintf) {
333 329 cmn_err(CE_CONT, "^%s", ibtf_print_buf);
334 330 }
335 331 #endif
336 332 break;
337 333 case IBTF_LOG_L0:
338 334 /* Strip the "\n" added earlier */
339 335 if (ibtf_print_buf[len - 1] == '\n') {
340 336 ibtf_print_buf[len - 1] = '\0';
341 337 }
342 338 if (msg_ptr[len - 1] == '\n') {
343 339 msg_ptr[len - 1] = '\0';
344 340 }
345 341 cmn_err(CE_WARN, ibtf_print_buf);
346 342 break;
347 343 }
348 344
349 345 mutex_exit(&ibtf_print_mutex);
350 346 }
351 347
352 348
353 349 void
354 350 ibtl_dprintf_intr(char *name, char *fmt, ...)
355 351 {
356 352 va_list ap;
357 353
358 354 /* only log messages if "ibtf_allow_intr_msgs" is set */
359 355 if (!ibtf_allow_intr_msgs)
360 356 return;
361 357
362 358 va_start(ap, fmt);
363 359 ibtf_vlog(name, IBTF_LOG_LINTR, fmt, ap);
364 360 va_end(ap);
365 361 }
366 362
367 363
368 364 /*
369 365 * Check individual subsystem err levels
370 366 */
371 367 #define IBTL_CHECK_ERR_LEVEL(level) \
372 368 if (strncmp(name, "ibgen", 5) == 0) { \
373 369 if (ibgen_errlevel < level) \
374 370 return; \
375 371 } else if (strncmp(name, "ibtl", 4) == 0) { \
376 372 if (ibtl_errlevel < level) \
377 373 return; \
378 374 } else if (strncmp(name, "ibcm", 4) == 0) { \
379 375 if (ibcm_errlevel < level) \
380 376 return; \
381 377 } else if (strncmp(name, "ibdm", 4) == 0) { \
382 378 if (ibdm_errlevel < level) \
383 379 return; \
384 380 } else if (strncmp(name, "ibnex", 5) == 0) { \
385 381 if (ibnex_errlevel < level) \
386 382 return; \
387 383 }
388 384
389 385 void
390 386 ibtl_dprintf5(char *name, char *fmt, ...)
391 387 {
392 388 va_list ap;
393 389
394 390 /* check if global errlevel matches or not */
395 391 if (ibtf_errlevel < IBTF_LOG_L5)
396 392 return;
397 393
398 394 IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L5);
399 395
400 396 va_start(ap, fmt);
401 397 ibtf_vlog(name, IBTF_LOG_L5, fmt, ap);
402 398 va_end(ap);
403 399 }
404 400
405 401 void
406 402 ibtl_dprintf4(char *name, char *fmt, ...)
407 403 {
408 404 va_list ap;
409 405
410 406 /* check if global errlevel matches or not */
411 407 if (ibtf_errlevel < IBTF_LOG_L4)
412 408 return;
413 409
414 410 IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L4);
415 411
416 412 va_start(ap, fmt);
417 413 ibtf_vlog(name, IBTF_LOG_L4, fmt, ap);
418 414 va_end(ap);
419 415 }
420 416
421 417
422 418 void
423 419 ibtl_dprintf3(char *name, char *fmt, ...)
424 420 {
425 421 va_list ap;
426 422
427 423 /* check if global errlevel matches or not */
428 424 if (ibtf_errlevel < IBTF_LOG_L3)
429 425 return;
430 426
431 427 IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L3);
432 428
433 429 va_start(ap, fmt);
434 430 ibtf_vlog(name, IBTF_LOG_L3, fmt, ap);
435 431 va_end(ap);
436 432 }
437 433
438 434
439 435 void
440 436 ibtl_dprintf2(char *name, char *fmt, ...)
441 437 {
442 438 va_list ap;
443 439
444 440 /* check if global errlevel matches or not */
445 441 if (ibtf_errlevel < IBTF_LOG_L2)
446 442 return;
447 443
448 444 IBTL_CHECK_ERR_LEVEL(IBTF_LOG_L2);
449 445
450 446 va_start(ap, fmt);
451 447 ibtf_vlog(name, IBTF_LOG_L2, fmt, ap);
452 448 va_end(ap);
453 449 }
454 450
455 451
456 452 void
457 453 ibtl_dprintf1(char *name, char *fmt, ...)
458 454 {
459 455 va_list ap;
460 456
461 457 /* check if global errlevel matches or not */
462 458 if (ibtf_errlevel < IBTF_LOG_L1)
463 459 return;
464 460
465 461 va_start(ap, fmt);
466 462 ibtf_vlog(name, IBTF_LOG_L1, fmt, ap);
467 463 va_end(ap);
468 464 }
469 465
470 466
471 467 /*
472 468 * Function:
473 469 * ibtf_dprintf0
474 470 * Input:
475 471 * name - Name of the subsystem generating the debug message
476 472 * fmt - The message to be displayed.
477 473 * Output:
478 474 * none
479 475 * Returns:
480 476 * none
481 477 * Description:
482 478 * A generic log function to display IBTF debug messages.
483 479 */
484 480 void
485 481 ibtl_dprintf0(char *name, char *fmt, ...)
486 482 {
487 483 va_list ap;
488 484
489 485 /* check if global errlevel matches or not */
490 486 if (ibtf_errlevel < IBTF_LOG_L0)
491 487 return;
492 488
493 489 va_start(ap, fmt);
494 490 ibtf_vlog(name, IBTF_LOG_L0, fmt, ap);
495 491 va_end(ap);
496 492 }
↓ open down ↓ |
408 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX