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