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