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 31 #ifndef _TB_DEBUG_H 32 #define _TB_DEBUG_H 33 34 typedef struct { 35 uintmax_t key; 36 const char * value; 37 } tb_string_t; 38 39 const char * tb_get_string(uintmax_t, tb_string_t *); 40 int tb_debug_sysctl(SYSCTL_HANDLER_ARGS); 41 void tb_parse_debug(u_int *, char *); 42 43 extern tb_string_t nhi_outmailcmd_opmode[]; 44 extern tb_string_t nhi_frame_pdf[]; 45 extern tb_string_t tb_security_level[]; 46 extern tb_string_t tb_rdy_connmode[]; 47 extern tb_string_t tb_mbox_connmode[]; 48 extern tb_string_t tb_device_power[]; 49 extern tb_string_t tb_notify_code[]; 50 extern tb_string_t tb_adapter_type[]; 51 extern tb_string_t tb_adapter_state[]; 52 extern tb_string_t tb_notify_event[]; 53 54 enum { 55 /* Debug subsystems */ 56 DBG_NONE = 0, 57 DBG_INIT = (1 << 0), 58 DBG_INFO = (1 << 1), 59 DBG_RXQ = (1 << 2), 60 DBG_TXQ = (1 << 3), 61 DBG_INTR = (1 << 4), 62 DBG_TB = (1 << 5), 63 DBG_MBOX = (1 << 6), 64 DBG_BRIDGE = (1 << 7), 65 DBG_CFG = (1 << 8), 66 DBG_ROUTER = (1 << 9), 67 DBG_PORT = (1 << 10), 68 DBG_HCM = (1 << 11), 69 /* Debug levels */ 70 DBG_EXTRA = (1 << 30), 71 DBG_NOISY = (1 << 31), 72 DBG_FULL = DBG_EXTRA | DBG_NOISY 73 }; 74 75 /* 76 * Macros to wrap printing. 77 * Each softc type needs a `dev` and `debug` field. Do tbdbg_printf as a 78 * function to make format errors more clear during compile. 79 */ 80 void tbdbg_dprintf(device_t dev, u_int debug, u_int val, const char *fmt, ...) __printflike(4, 5); 81 82 #ifdef THUNDERBOLT_DEBUG 83 #define tb_debug(sc, level, fmt...) \ 84 tbdbg_dprintf((sc)->dev, (sc)->debug, level, ##fmt) 85 #else 86 #define tb_debug(sc, level, fmt...) 87 #endif 88 #define tb_printf(sc, fmt...) \ 89 device_printf((sc)->dev, ##fmt) 90 91 #endif /* _TB_DEBUG_H */ 92