1*493d26c5SEd Maste /** 2*493d26c5SEd Maste * aQuantia Corporation Network Driver 3*493d26c5SEd Maste * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved 4*493d26c5SEd Maste * 5*493d26c5SEd Maste * Redistribution and use in source and binary forms, with or without 6*493d26c5SEd Maste * modification, are permitted provided that the following conditions 7*493d26c5SEd Maste * are met: 8*493d26c5SEd Maste * 9*493d26c5SEd Maste * (1) Redistributions of source code must retain the above 10*493d26c5SEd Maste * copyright notice, this list of conditions and the following 11*493d26c5SEd Maste * disclaimer. 12*493d26c5SEd Maste * 13*493d26c5SEd Maste * (2) Redistributions in binary form must reproduce the above 14*493d26c5SEd Maste * copyright notice, this list of conditions and the following 15*493d26c5SEd Maste * disclaimer in the documentation and/or other materials provided 16*493d26c5SEd Maste * with the distribution. 17*493d26c5SEd Maste * 18*493d26c5SEd Maste * (3) The name of the author may not be used to endorse or promote 19*493d26c5SEd Maste * products derived from this software without specific prior 20*493d26c5SEd Maste * written permission. 21*493d26c5SEd Maste * 22*493d26c5SEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 23*493d26c5SEd Maste * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24*493d26c5SEd Maste * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*493d26c5SEd Maste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 26*493d26c5SEd Maste * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*493d26c5SEd Maste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 28*493d26c5SEd Maste * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29*493d26c5SEd Maste * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30*493d26c5SEd Maste * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31*493d26c5SEd Maste * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32*493d26c5SEd Maste * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33*493d26c5SEd Maste * 34*493d26c5SEd Maste * @file aq_dbg.h 35*493d26c5SEd Maste * Debug print macros & definitions. 36*493d26c5SEd Maste * @date 2017.12.07 @author roman.agafonov@aquantia.com 37*493d26c5SEd Maste */ 38*493d26c5SEd Maste #ifndef AQ_DBG_H 39*493d26c5SEd Maste #define AQ_DBG_H 40*493d26c5SEd Maste 41*493d26c5SEd Maste #include <syslog.h> 42*493d26c5SEd Maste #include <sys/systm.h> 43*493d26c5SEd Maste /* 44*493d26c5SEd Maste Debug levels: 45*493d26c5SEd Maste 0 - no debug 46*493d26c5SEd Maste 1 - important warnings 47*493d26c5SEd Maste 2 - debug prints 48*493d26c5SEd Maste 3 - trace function calls 49*493d26c5SEd Maste 4 - dump descriptor 50*493d26c5SEd Maste */ 51*493d26c5SEd Maste 52*493d26c5SEd Maste #define AQ_CFG_DEBUG_LVL 0x0 53*493d26c5SEd Maste 54*493d26c5SEd Maste #define AQ_DBG_ERROR(string, args...) printf( "atlantic: " string "\n", ##args) 55*493d26c5SEd Maste 56*493d26c5SEd Maste /* Debug stuff */ 57*493d26c5SEd Maste #if AQ_CFG_DEBUG_LVL > 0 58*493d26c5SEd Maste #define AQ_DBG_WARNING(string, args...) printf( "atlantic: " string "\n", ##args) 59*493d26c5SEd Maste #else 60*493d26c5SEd Maste #define AQ_DBG_WARNING(string, ...) 61*493d26c5SEd Maste #endif 62*493d26c5SEd Maste 63*493d26c5SEd Maste #if AQ_CFG_DEBUG_LVL > 1 64*493d26c5SEd Maste #define AQ_DBG_PRINT(string, args...) printf( "atlantic: " string "\n", ##args) 65*493d26c5SEd Maste #else 66*493d26c5SEd Maste #define AQ_DBG_PRINT(string, ...) 67*493d26c5SEd Maste #endif 68*493d26c5SEd Maste 69*493d26c5SEd Maste #if AQ_CFG_DEBUG_LVL > 2 70*493d26c5SEd Maste #define AQ_DBG_ENTER() printf( "atlantic: %s() {\n", __func__) 71*493d26c5SEd Maste #define AQ_DBG_ENTERA(s, args...) printf( "atlantic: %s(" s ") {\n", __func__, ##args) 72*493d26c5SEd Maste #define AQ_DBG_EXIT(err) printf( "atlantic: } %s(), err=%d\n", __func__, err) 73*493d26c5SEd Maste #else 74*493d26c5SEd Maste #define AQ_DBG_ENTER() 75*493d26c5SEd Maste #define AQ_DBG_ENTERA(s, args...) 76*493d26c5SEd Maste #define AQ_DBG_EXIT(err) 77*493d26c5SEd Maste #endif 78*493d26c5SEd Maste 79*493d26c5SEd Maste #if AQ_CFG_DEBUG_LVL > 2 80*493d26c5SEd Maste #define AQ_DBG_DUMP_DESC(desc) { \ 81*493d26c5SEd Maste volatile u8 *raw = (volatile u8*)(desc); \ 82*493d26c5SEd Maste printf( "07-00 %02X%02X%02X%02X %02X%02X%02X%02X 15-08 %02X%02X%02X%02X %02X%02X%02X%02X\n", \ 83*493d26c5SEd Maste raw[7], raw[6], raw[5], raw[4], raw[3], raw[2], raw[1], raw[0], \ 84*493d26c5SEd Maste raw[15], raw[14], raw[13], raw[12], raw[11], raw[10], raw[9], raw[8]); \ 85*493d26c5SEd Maste }\ 86*493d26c5SEd Maste 87*493d26c5SEd Maste #else 88*493d26c5SEd Maste #define AQ_DBG_DUMP_DESC(desc) 89*493d26c5SEd Maste #endif 90*493d26c5SEd Maste 91*493d26c5SEd Maste typedef enum aq_debug_level 92*493d26c5SEd Maste { 93*493d26c5SEd Maste lvl_error = LOG_ERR, 94*493d26c5SEd Maste lvl_warn = LOG_WARNING, 95*493d26c5SEd Maste lvl_trace = LOG_NOTICE, 96*493d26c5SEd Maste lvl_detail = LOG_INFO, 97*493d26c5SEd Maste } aq_debug_level; 98*493d26c5SEd Maste 99*493d26c5SEd Maste typedef enum aq_debug_category 100*493d26c5SEd Maste { 101*493d26c5SEd Maste dbg_init = 1, 102*493d26c5SEd Maste dbg_config = 1 << 1, 103*493d26c5SEd Maste dbg_tx = 1 << 2, 104*493d26c5SEd Maste dbg_rx = 1 << 3, 105*493d26c5SEd Maste dbg_intr = 1 << 4, 106*493d26c5SEd Maste dbg_fw = 1 << 5, 107*493d26c5SEd Maste } aq_debug_category; 108*493d26c5SEd Maste 109*493d26c5SEd Maste 110*493d26c5SEd Maste #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 111*493d26c5SEd Maste 112*493d26c5SEd Maste extern const aq_debug_level dbg_level_; 113*493d26c5SEd Maste extern const u32 dbg_categories_; 114*493d26c5SEd Maste 115*493d26c5SEd Maste #define log_base_(_lvl, _fmt, args...) printf( "atlantic: " _fmt "\n", ##args) 116*493d26c5SEd Maste 117*493d26c5SEd Maste #if AQ_CFG_DEBUG_LVL > 0 118*493d26c5SEd Maste #define trace_base_(_lvl, _cat, _fmt, args...) do { if (dbg_level_ >= _lvl && (_cat & dbg_categories_)) { printf( "atlantic: " _fmt " @%s,%d\n", ##args, __FILENAME__, __LINE__); }} while (0) 119*493d26c5SEd Maste #else 120*493d26c5SEd Maste #define trace_base_(_lvl, _cat, _fmt, ...) do {} while (0) 121*493d26c5SEd Maste #endif // AQ_CFG_DEBUG_LVL > 0 122*493d26c5SEd Maste 123*493d26c5SEd Maste #define aq_log_error(_fmt, args...) log_base_(lvl_error, "[!] " _fmt, ##args) 124*493d26c5SEd Maste #define aq_log_warn(_fmt, args...) log_base_(lvl_warn, "/!\\ " _fmt, ##args) 125*493d26c5SEd Maste #define aq_log(_fmt, args...) log_base_(lvl_trace, _fmt, ##args) 126*493d26c5SEd Maste #define aq_log_detail(_fmt, args...) log_base_(lvl_detail, _fmt, ##args) 127*493d26c5SEd Maste 128*493d26c5SEd Maste #define trace_error(_cat,_fmt, args...) trace_base_(lvl_error, _cat, "[!] " _fmt, ##args) 129*493d26c5SEd Maste #define trace_warn(_cat, _fmt, args...) trace_base_(lvl_warn, _cat, "/!\\ " _fmt, ##args) 130*493d26c5SEd Maste #define trace(_cat, _fmt, args...) trace_base_(lvl_trace, _cat, _fmt, ##args) 131*493d26c5SEd Maste #define trace_detail(_cat, _fmt, args...) trace_base_(lvl_detail, _cat, _fmt, ##args) 132*493d26c5SEd Maste 133*493d26c5SEd Maste void trace_aq_tx_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2]); 134*493d26c5SEd Maste void trace_aq_rx_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2]); 135*493d26c5SEd Maste void trace_aq_tx_context_descr(int ring_idx, unsigned int pointer, volatile u64 descr[2]); 136*493d26c5SEd Maste void DumpHex(const void* data, size_t size); 137*493d26c5SEd Maste 138*493d26c5SEd Maste #endif // AQ_DBG_H 139