xref: /titanic_41/usr/src/uts/common/io/nxge/npi/npi.c (revision 4aac33d31b41cc7e3ac6fb66747ff2cae63d08cf)
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 2006 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 <npi.h>
29 #include <sys/nxge/nxge_impl.h>
30 
31 nxge_os_mutex_t npidebuglock;
32 int npi_debug_init = 0;
33 uint64_t npi_debug_level = 0;
34 
35 void
36 npi_debug_msg(npi_handle_function_t function, uint64_t level, char *fmt, ...)
37 {
38 	char msg_buffer[1024];
39 	char prefix_buffer[32];
40 	int cmn_level = CE_CONT;
41 	va_list ap;
42 
43 	if ((level & npi_debug_level) ||
44 		(level & NPI_REG_CTL) ||
45 		(level & NPI_ERR_CTL)) {
46 
47 		if (npi_debug_init == 0) {
48 			MUTEX_INIT(&npidebuglock, NULL, MUTEX_DRIVER, NULL);
49 			npi_debug_init = 1;
50 		}
51 
52 		MUTEX_ENTER(&npidebuglock);
53 
54 		if (level & NPI_ERR_CTL) {
55 			cmn_level = CE_WARN;
56 		}
57 
58 		va_start(ap, fmt);
59 		(void) vsprintf(msg_buffer, fmt, ap);
60 		va_end(ap);
61 
62 		(void) sprintf(prefix_buffer, "%s%d(%d):", "npi",
63 				function.instance, function.function);
64 
65 		MUTEX_EXIT(&npidebuglock);
66 		cmn_err(cmn_level, "!%s %s\n", prefix_buffer, msg_buffer);
67 	}
68 }
69 
70 void
71 npi_rtrace_buf_init(rtrace_t *rt)
72 {
73 	int i;
74 
75 	rt->next_idx = 0;
76 	rt->last_idx = MAX_RTRACE_ENTRIES - 1;
77 	rt->wrapped = B_FALSE;
78 	for (i = 0; i < MAX_RTRACE_ENTRIES; i++) {
79 		rt->buf[i].ctl_addr = TRACE_CTL_INVALID;
80 		rt->buf[i].val_l32 = 0;
81 		rt->buf[i].val_h32 = 0;
82 	}
83 }
84 
85 void
86 npi_rtrace_update(npi_handle_t handle, boolean_t wr, rtrace_t *rt,
87 		    uint32_t addr, uint64_t val)
88 {
89 	int idx;
90 	idx = rt->next_idx;
91 	if (wr == B_TRUE)
92 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK)
93 						| TRACE_CTL_WR;
94 	else
95 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK);
96 	rt->buf[idx].ctl_addr |= (((handle.function.function
97 				<< TRACE_FUNC_SHIFT) & TRACE_FUNC_MASK) |
98 				((handle.function.instance
99 				<< TRACE_INST_SHIFT) & TRACE_INST_MASK));
100 	rt->buf[idx].val_l32 = val & 0xFFFFFFFF;
101 	rt->buf[idx].val_h32 = (val >> 32) & 0xFFFFFFFF;
102 	rt->next_idx++;
103 	if (rt->next_idx > rt->last_idx) {
104 		rt->next_idx = 0;
105 		rt->wrapped = B_TRUE;
106 	}
107 }
108