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