xref: /titanic_41/usr/src/uts/common/io/hxge/hpi.c (revision 450396635f70344c58b6b1e4db38cf17ff34445c)
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 2008 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 <hpi.h>
29 #include <hxge_impl.h>
30 
31 static hxge_os_mutex_t hpidebuglock;
32 static int hpi_debug_init = 0;
33 uint64_t hpi_debug_level = 0x0;
34 
35 void
36 hpi_debug_msg(hpi_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 & hpi_debug_level) ||
44 	    (level & HPI_REG_CTL) || (level & HPI_ERR_CTL)) {
45 
46 		if (hpi_debug_init == 0) {
47 			MUTEX_INIT(&hpidebuglock, NULL, MUTEX_DRIVER, NULL);
48 			hpi_debug_init = 1;
49 		}
50 
51 		MUTEX_ENTER(&hpidebuglock);
52 
53 		if (level & HPI_ERR_CTL) {
54 			cmn_level = CE_WARN;
55 		}
56 
57 		va_start(ap, fmt);
58 		(void) vsprintf(msg_buffer, fmt, ap);
59 		va_end(ap);
60 
61 		(void) sprintf(prefix_buffer, "%s%d(%d):", "hpi",
62 		    function.instance, function.function);
63 
64 		cmn_err(cmn_level, "%s %s\n", prefix_buffer, msg_buffer);
65 		MUTEX_EXIT(&hpidebuglock);
66 	}
67 }
68 
69 void
70 hpi_rtrace_buf_init(rtrace_t *rt)
71 {
72 	int i;
73 
74 	rt->next_idx = 0;
75 	rt->last_idx = MAX_RTRACE_ENTRIES - 1;
76 	rt->wrapped = B_FALSE;
77 	for (i = 0; i < MAX_RTRACE_ENTRIES; i++) {
78 		rt->buf[i].ctl_addr = TRACE_CTL_INVALID;
79 		rt->buf[i].val_l32 = 0;
80 		rt->buf[i].val_h32 = 0;
81 	}
82 }
83 
84 void
85 hpi_rtrace_update(hpi_handle_t handle, boolean_t wr, rtrace_t *rt,
86     uint32_t addr, uint64_t val)
87 {
88 	int idx;
89 	idx = rt->next_idx;
90 	if (wr == B_TRUE)
91 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK) | TRACE_CTL_WR;
92 	else
93 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK);
94 	rt->buf[idx].ctl_addr |= (((handle.function.function
95 	    << TRACE_FUNC_SHIFT) & TRACE_FUNC_MASK) |
96 	    ((handle.function.instance << TRACE_INST_SHIFT) & TRACE_INST_MASK));
97 	rt->buf[idx].val_l32 = val & 0xFFFFFFFF;
98 	rt->buf[idx].val_h32 = (val >> 32) & 0xFFFFFFFF;
99 	rt->next_idx++;
100 	if (rt->next_idx > rt->last_idx) {
101 		rt->next_idx = 0;
102 		rt->wrapped = B_TRUE;
103 	}
104 }
105