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