1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2022 Scott Long 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * Thunderbolt 3 driver debug strings 29 * 30 * $FreeBSD$ 31 */ 32 33 #ifndef _TB_DEBUG_H 34 #define _TB_DEBUG_H 35 36 typedef struct { 37 uintmax_t key; 38 const char * value; 39 } tb_string_t; 40 41 const char * tb_get_string(uintmax_t, tb_string_t *); 42 int tb_debug_sysctl(SYSCTL_HANDLER_ARGS); 43 void tb_parse_debug(u_int *, char *); 44 45 extern tb_string_t nhi_outmailcmd_opmode[]; 46 extern tb_string_t nhi_frame_pdf[]; 47 extern tb_string_t tb_security_level[]; 48 extern tb_string_t tb_rdy_connmode[]; 49 extern tb_string_t tb_mbox_connmode[]; 50 extern tb_string_t tb_device_power[]; 51 extern tb_string_t tb_notify_code[]; 52 extern tb_string_t tb_adapter_type[]; 53 extern tb_string_t tb_adapter_state[]; 54 extern tb_string_t tb_notify_event[]; 55 56 enum { 57 /* Debug subsystems */ 58 DBG_NONE = 0, 59 DBG_INIT = (1 << 0), 60 DBG_INFO = (1 << 1), 61 DBG_RXQ = (1 << 2), 62 DBG_TXQ = (1 << 3), 63 DBG_INTR = (1 << 4), 64 DBG_TB = (1 << 5), 65 DBG_MBOX = (1 << 6), 66 DBG_BRIDGE = (1 << 7), 67 DBG_CFG = (1 << 8), 68 DBG_ROUTER = (1 << 9), 69 DBG_PORT = (1 << 10), 70 DBG_HCM = (1 << 11), 71 /* Debug levels */ 72 DBG_EXTRA = (1 << 30), 73 DBG_NOISY = (1 << 31), 74 DBG_FULL = DBG_EXTRA | DBG_NOISY 75 }; 76 77 /* 78 * Macros to wrap printing. 79 * Each softc type needs a `dev` and `debug` field. Do tbdbg_printf as a 80 * function to make format errors more clear during compile. 81 */ 82 void tbdbg_dprintf(device_t dev, u_int debug, u_int val, const char *fmt, ...) __printflike(4, 5); 83 84 #if defined(THUNDERBOLT_DEBUG) && (THUNDERBOLT_DEBUG > 0) 85 #define tb_debug(sc, level, fmt...) \ 86 tbdbg_dprintf((sc)->dev, (sc)->debug, level, ##fmt) 87 #else 88 #define tb_debug(sc, level, fmt...) 89 #endif 90 #define tb_printf(sc, fmt...) \ 91 device_printf((sc)->dev, ##fmt) 92 93 #endif /* _TB_DEBUG_H */ 94