xref: /titanic_51/usr/src/uts/sun4v/io/n2rng/n2rng_debug.c (revision b453864f3587ccc3324d7a3b0438a1e542dcfde7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/ddi.h>
30 #include <sys/sunddi.h>
31 #include <sys/cmn_err.h>
32 #include <sys/varargs.h>
33 #include <sys/n2rng.h>
34 
35 /*
36  * Debugging and messaging.
37  */
38 #if DEBUG
39 static unsigned int n2rng_debug = DWARN;
40 
41 int
42 n2rng_dflagset(int flag)
43 {
44 	return (flag & n2rng_debug);
45 }
46 
47 void
48 n2rng_dprintf(n2rng_t *n2rng, int level, const char *fmt, ...)
49 {
50 	va_list ap;
51 	char	buf[256];
52 
53 	if (n2rng_debug & level) {
54 		va_start(ap, fmt);
55 		if (n2rng == NULL) {
56 			(void) sprintf(buf, "%s\n", fmt);
57 		} else {
58 			(void) sprintf(buf, "%s/%d: %s\n",
59 			    ddi_driver_name(n2rng->n_dip),
60 			    ddi_get_instance(n2rng->n_dip), fmt);
61 		}
62 		vprintf(buf, ap);
63 		va_end(ap);
64 	}
65 }
66 #endif
67 
68 void
69 n2rng_error(n2rng_t *n2rng, const char *fmt, ...)
70 {
71 	va_list ap;
72 	va_start(ap, fmt);
73 	n2rng_dipverror(n2rng->n_dip, fmt, ap);
74 	va_end(ap);
75 }
76 
77 void
78 n2rng_diperror(dev_info_t *dip, const char *fmt, ...)
79 {
80 	va_list ap;
81 	va_start(ap, fmt);
82 	n2rng_dipverror(dip, fmt, ap);
83 	va_end(ap);
84 }
85 
86 void
87 n2rng_dipverror(dev_info_t *dip, const char *fmt, va_list ap)
88 {
89 	char	buf[256];
90 
91 	(void) sprintf(buf, "%s%d: %s", ddi_driver_name(dip),
92 	    ddi_get_instance(dip), fmt);
93 	vcmn_err(CE_WARN, buf, ap);
94 }
95