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