xref: /illumos-gate/usr/src/uts/common/io/hxge/hpi.c (revision 2d6eb4a5)
1*3dec9fcdSqs /*
2*3dec9fcdSqs  * CDDL HEADER START
3*3dec9fcdSqs  *
4*3dec9fcdSqs  * The contents of this file are subject to the terms of the
5*3dec9fcdSqs  * Common Development and Distribution License (the "License").
6*3dec9fcdSqs  * You may not use this file except in compliance with the License.
7*3dec9fcdSqs  *
8*3dec9fcdSqs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3dec9fcdSqs  * or http://www.opensolaris.org/os/licensing.
10*3dec9fcdSqs  * See the License for the specific language governing permissions
11*3dec9fcdSqs  * and limitations under the License.
12*3dec9fcdSqs  *
13*3dec9fcdSqs  * When distributing Covered Code, include this CDDL HEADER in each
14*3dec9fcdSqs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3dec9fcdSqs  * If applicable, add the following below this CDDL HEADER, with the
16*3dec9fcdSqs  * fields enclosed by brackets "[]" replaced with your own identifying
17*3dec9fcdSqs  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3dec9fcdSqs  *
19*3dec9fcdSqs  * CDDL HEADER END
20*3dec9fcdSqs  */
21*3dec9fcdSqs /*
22*3dec9fcdSqs  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*3dec9fcdSqs  * Use is subject to license terms.
24*3dec9fcdSqs  */
25*3dec9fcdSqs 
26*3dec9fcdSqs #include <hpi.h>
27*3dec9fcdSqs #include <hxge_impl.h>
28*3dec9fcdSqs 
29*3dec9fcdSqs static hxge_os_mutex_t hpidebuglock;
30*3dec9fcdSqs static int hpi_debug_init = 0;
31*3dec9fcdSqs uint64_t hpi_debug_level = 0x0;
32*3dec9fcdSqs 
33*3dec9fcdSqs void
hpi_debug_msg(hpi_handle_function_t function,uint64_t level,char * fmt,...)34*3dec9fcdSqs hpi_debug_msg(hpi_handle_function_t function, uint64_t level, char *fmt, ...)
35*3dec9fcdSqs {
36*3dec9fcdSqs 	char		msg_buffer[1024];
37*3dec9fcdSqs 	char		prefix_buffer[32];
38*3dec9fcdSqs 	int		cmn_level = CE_CONT;
39*3dec9fcdSqs 	va_list		ap;
40*3dec9fcdSqs 
41*3dec9fcdSqs 	if ((level & hpi_debug_level) ||
42*3dec9fcdSqs 	    (level & HPI_REG_CTL) || (level & HPI_ERR_CTL)) {
43*3dec9fcdSqs 
44*3dec9fcdSqs 		if (hpi_debug_init == 0) {
45*3dec9fcdSqs 			MUTEX_INIT(&hpidebuglock, NULL, MUTEX_DRIVER, NULL);
46*3dec9fcdSqs 			hpi_debug_init = 1;
47*3dec9fcdSqs 		}
48*3dec9fcdSqs 
49*3dec9fcdSqs 		MUTEX_ENTER(&hpidebuglock);
50*3dec9fcdSqs 
51*3dec9fcdSqs 		if (level & HPI_ERR_CTL) {
52*3dec9fcdSqs 			cmn_level = CE_WARN;
53*3dec9fcdSqs 		}
54*3dec9fcdSqs 
55*3dec9fcdSqs 		va_start(ap, fmt);
56*3dec9fcdSqs 		(void) vsprintf(msg_buffer, fmt, ap);
57*3dec9fcdSqs 		va_end(ap);
58*3dec9fcdSqs 
59*3dec9fcdSqs 		(void) sprintf(prefix_buffer, "%s%d(%d):", "hpi",
60*3dec9fcdSqs 		    function.instance, function.function);
61*3dec9fcdSqs 
62*3dec9fcdSqs 		cmn_err(cmn_level, "%s %s\n", prefix_buffer, msg_buffer);
63*3dec9fcdSqs 		MUTEX_EXIT(&hpidebuglock);
64*3dec9fcdSqs 	}
65*3dec9fcdSqs }
66*3dec9fcdSqs 
67*3dec9fcdSqs void
hpi_rtrace_buf_init(rtrace_t * rt)68*3dec9fcdSqs hpi_rtrace_buf_init(rtrace_t *rt)
69*3dec9fcdSqs {
70*3dec9fcdSqs 	int i;
71*3dec9fcdSqs 
72*3dec9fcdSqs 	rt->next_idx = 0;
73*3dec9fcdSqs 	rt->last_idx = MAX_RTRACE_ENTRIES - 1;
74*3dec9fcdSqs 	rt->wrapped = B_FALSE;
75*3dec9fcdSqs 	for (i = 0; i < MAX_RTRACE_ENTRIES; i++) {
76*3dec9fcdSqs 		rt->buf[i].ctl_addr = TRACE_CTL_INVALID;
77*3dec9fcdSqs 		rt->buf[i].val_l32 = 0;
78*3dec9fcdSqs 		rt->buf[i].val_h32 = 0;
79*3dec9fcdSqs 	}
80*3dec9fcdSqs }
81*3dec9fcdSqs 
82*3dec9fcdSqs void
hpi_rtrace_update(hpi_handle_t handle,boolean_t wr,rtrace_t * rt,uint32_t addr,uint64_t val)83*3dec9fcdSqs hpi_rtrace_update(hpi_handle_t handle, boolean_t wr, rtrace_t *rt,
84*3dec9fcdSqs     uint32_t addr, uint64_t val)
85*3dec9fcdSqs {
86*3dec9fcdSqs 	int idx;
87*3dec9fcdSqs 	idx = rt->next_idx;
88*3dec9fcdSqs 	if (wr == B_TRUE)
89*3dec9fcdSqs 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK) | TRACE_CTL_WR;
90*3dec9fcdSqs 	else
91*3dec9fcdSqs 		rt->buf[idx].ctl_addr = (addr & TRACE_ADDR_MASK);
92*3dec9fcdSqs 	rt->buf[idx].ctl_addr |= (((handle.function.function
93*3dec9fcdSqs 	    << TRACE_FUNC_SHIFT) & TRACE_FUNC_MASK) |
94*3dec9fcdSqs 	    ((handle.function.instance << TRACE_INST_SHIFT) & TRACE_INST_MASK));
95*3dec9fcdSqs 	rt->buf[idx].val_l32 = val & 0xFFFFFFFF;
96*3dec9fcdSqs 	rt->buf[idx].val_h32 = (val >> 32) & 0xFFFFFFFF;
97*3dec9fcdSqs 	rt->next_idx++;
98*3dec9fcdSqs 	if (rt->next_idx > rt->last_idx) {
99*3dec9fcdSqs 		rt->next_idx = 0;
100*3dec9fcdSqs 		rt->wrapped = B_TRUE;
101*3dec9fcdSqs 	}
102*3dec9fcdSqs }
103