1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /*- 13 * Copyright (c) 2019 Chelsio Communications, Inc. 14 * All rights reserved. 15 * * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 /* 37 * Chelsio Unified Debug Interface header file. 38 * Version 1.1 39 */ 40 #ifndef _CUDBG_IF_H_ 41 #define _CUDBG_IF_H_ 42 43 #ifndef _KERNEL 44 #include <stdlib.h> 45 #endif 46 47 #include "cudbg_lib_common.h" 48 49 #ifdef __GNUC__ 50 #define ATTRIBUTE_UNUSED __attribute__ ((unused)) 51 #else 52 #define ATTRIBUTE_UNUSED 53 #endif 54 55 #if defined(CONFIG_CUDBG_DEBUG) 56 #define cudbg_debug(pdbg_init, format, ...) do {\ 57 pdbg_init->print(format, ##__VA_ARGS__); \ 58 } while (0) 59 #else 60 #define cudbg_debug(pdbg_init, format, ...) do { } while (0) 61 #endif 62 63 #define OUT 64 #define IN 65 #define INOUT 66 67 /* Error codes */ 68 69 #define CUDBG_STATUS_SUCCESS 0 70 #define CUDBG_STATUS_NOSPACE -2 71 #define CUDBG_STATUS_FLASH_WRITE_FAIL -3 72 #define CUDBG_STATUS_FLASH_READ_FAIL -4 73 #define CUDBG_STATUS_UNDEFINED_OUT_BUF -5 74 #define CUDBG_STATUS_UNDEFINED_CBFN -6 75 #define CUDBG_STATUS_UNDEFINED_PRINTF_CBFN -7 76 #define CUDBG_STATUS_ADAP_INVALID -8 77 #define CUDBG_STATUS_FLASH_EMPTY -9 78 #define CUDBG_STATUS_NO_ADAPTER -10 79 #define CUDBG_STATUS_NO_SIGNATURE -11 80 #define CUDBG_STATUS_MULTIPLE_REG -12 81 #define CUDBG_STATUS_UNREGISTERED -13 82 #define CUDBG_STATUS_UNDEFINED_ENTITY -14 83 #define CUDBG_STATUS_REG_FAIlED -15 84 #define CUDBG_STATUS_DEVLOG_FAILED -16 85 #define CUDBG_STATUS_SMALL_BUFF -17 86 #define CUDBG_STATUS_CHKSUM_MISSMATCH -18 87 #define CUDBG_STATUS_NO_SCRATCH_MEM -19 88 #define CUDBG_STATUS_OUTBUFF_OVERFLOW -20 89 #define CUDBG_STATUS_INVALID_BUFF -21 /* Invalid magic */ 90 #define CUDBG_STATUS_FILE_OPEN_FAIL -22 91 #define CUDBG_STATUS_DEVLOG_INT_FAIL -23 92 #define CUDBG_STATUS_ENTITY_NOT_FOUND -24 93 #define CUDBG_STATUS_DECOMPRESS_FAIL -25 94 #define CUDBG_STATUS_BUFFER_SHORT -26 95 #define CUDBG_METADATA_VERSION_MISMATCH -27 96 #define CUDBG_STATUS_NOT_IMPLEMENTED -28 97 #define CUDBG_SYSTEM_ERROR -29 98 #define CUDBG_STATUS_MMAP_FAILED -30 99 #define CUDBG_STATUS_FILE_WRITE_FAILED -31 100 #define CUDBG_STATUS_CCLK_NOT_DEFINED -32 101 #define CUDBG_STATUS_FLASH_FULL -33 102 #define CUDBG_STATUS_SECTOR_EMPTY -34 103 #define CUDBG_STATUS_ENTITY_NOT_REQUESTED -35 104 #define CUDBG_STATUS_NOT_SUPPORTED -36 105 #define CUDBG_STATUS_FILE_READ_FAILED -37 106 #define CUDBG_STATUS_CORRUPTED -38 107 #define CUDBG_STATUS_INVALID_INDEX -39 108 109 #define CUDBG_MAJOR_VERSION 1 110 #define CUDBG_MINOR_VERSION 14 111 #define CUDBG_BUILD_VERSION 0 112 113 #define CUDBG_FILE_NAME_LEN 256 114 #define CUDBG_DIR_NAME_LEN 256 115 #define CUDBG_MAX_BITMAP_LEN 16 116 117 static char ATTRIBUTE_UNUSED * err_msg[] = { 118 "Success", 119 "Unknown", 120 "No space", 121 "Flash write fail", 122 "Flash read fail", 123 "Undefined out buf", 124 "Callback function undefined", 125 "Print callback function undefined", 126 "ADAP invalid", 127 "Flash empty", 128 "No adapter", 129 "No signature", 130 "Multiple registration", 131 "Unregistered", 132 "Undefined entity", 133 "Reg failed", 134 "Devlog failed", 135 "Small buff", 136 "Checksum mismatch", 137 "No scratch memory", 138 "Outbuff overflow", 139 "Invalid buffer", 140 "File open fail", 141 "Devlog int fail", 142 "Entity not found", 143 "Decompress fail", 144 "Buffer short", 145 "Version mismatch", 146 "Not implemented", 147 "System error", 148 "Mmap failed", 149 "File write failed", 150 "cclk not defined", 151 "Flash full", 152 "Sector empty", 153 "Entity not requested", 154 "Not supported", 155 "File read fail", 156 "Corrupted", 157 "Invalid Index" 158 }; 159 160 enum CUDBG_DBG_ENTITY_TYPE { 161 CUDBG_ALL = 0, 162 CUDBG_REG_DUMP = 1, 163 CUDBG_DEV_LOG = 2, 164 CUDBG_CIM_LA = 3, 165 CUDBG_CIM_MA_LA = 4, 166 CUDBG_CIM_QCFG = 5, 167 CUDBG_CIM_IBQ_TP0 = 6, 168 CUDBG_CIM_IBQ_TP1 = 7, 169 CUDBG_CIM_IBQ_ULP = 8, 170 CUDBG_CIM_IBQ_SGE0 = 9, 171 CUDBG_CIM_IBQ_SGE1 = 10, 172 CUDBG_CIM_IBQ_NCSI = 11, 173 CUDBG_CIM_OBQ_ULP0 = 12, 174 CUDBG_CIM_OBQ_ULP1 = 13, 175 CUDBG_CIM_OBQ_ULP2 = 14, 176 CUDBG_CIM_OBQ_ULP3 = 15, 177 CUDBG_CIM_OBQ_SGE = 16, 178 CUDBG_CIM_OBQ_NCSI = 17, 179 CUDBG_EDC0 = 18, 180 CUDBG_EDC1 = 19, 181 CUDBG_MC0 = 20, 182 CUDBG_MC1 = 21, 183 CUDBG_RSS = 22, 184 CUDBG_RSS_PF_CONF = 23, 185 CUDBG_RSS_KEY = 24, 186 CUDBG_RSS_VF_CONF = 25, 187 CUDBG_RSS_CONF = 26, 188 CUDBG_PATH_MTU = 27, 189 CUDBG_SW_STATE = 28, 190 CUDBG_WTP = 29, 191 CUDBG_PM_STATS = 30, 192 CUDBG_HW_SCHED = 31, 193 CUDBG_TCP_STATS = 32, 194 CUDBG_TP_ERR_STATS = 33, 195 CUDBG_FCOE_STATS = 34, 196 CUDBG_RDMA_STATS = 35, 197 CUDBG_TP_INDIRECT = 36, 198 CUDBG_SGE_INDIRECT = 37, 199 CUDBG_CPL_STATS = 38, 200 CUDBG_DDP_STATS = 39, 201 CUDBG_WC_STATS = 40, 202 CUDBG_ULPRX_LA = 41, 203 CUDBG_LB_STATS = 42, 204 CUDBG_TP_LA = 43, 205 CUDBG_MEMINFO = 44, 206 CUDBG_CIM_PIF_LA = 45, 207 CUDBG_CLK = 46, 208 CUDBG_CIM_OBQ_RXQ0 = 47, 209 CUDBG_CIM_OBQ_RXQ1 = 48, 210 CUDBG_MAC_STATS = 49, 211 CUDBG_PCIE_INDIRECT = 50, 212 CUDBG_PM_INDIRECT = 51, 213 CUDBG_FULL = 52, 214 CUDBG_TX_RATE = 53, 215 CUDBG_TID_INFO = 54, 216 CUDBG_PCIE_CONFIG = 55, 217 CUDBG_DUMP_CONTEXT = 56, 218 CUDBG_MPS_TCAM = 57, 219 CUDBG_VPD_DATA = 58, 220 CUDBG_LE_TCAM = 59, 221 CUDBG_CCTRL = 60, 222 CUDBG_MA_INDIRECT = 61, 223 CUDBG_ULPTX_LA = 62, 224 CUDBG_EXT_ENTITY = 63, 225 CUDBG_UP_CIM_INDIRECT = 64, 226 CUDBG_PBT_TABLE = 65, 227 CUDBG_MBOX_LOG = 66, 228 CUDBG_HMA_INDIRECT = 67, 229 CUDBG_MAX_ENTITY = 68, 230 }; 231 232 #define ENTITY_FLAG_NULL 0 233 #define ENTITY_FLAG_REGISTER 1 234 #define ENTITY_FLAG_BINARY 2 235 #define ENTITY_FLAG_FW_NO_ATTACH 3 236 237 /* file_name matches Linux cxgb4 debugfs entry names. */ 238 struct el {char *name; char *file_name; int bit; u32 flag; }; 239 static struct el ATTRIBUTE_UNUSED entity_list[] = { 240 {"all", "all", CUDBG_ALL, ENTITY_FLAG_NULL}, 241 {"regdump", "regdump", CUDBG_REG_DUMP, 1 << ENTITY_FLAG_REGISTER}, 242 {"devlog", "devlog", CUDBG_DEV_LOG, ENTITY_FLAG_NULL}, 243 {"cimla", "cim_la", CUDBG_CIM_LA, ENTITY_FLAG_NULL}, 244 {"cimmala", "cim_ma_la", CUDBG_CIM_MA_LA, ENTITY_FLAG_NULL}, 245 {"cimqcfg", "cim_qcfg", CUDBG_CIM_QCFG, ENTITY_FLAG_NULL}, 246 {"ibqtp0", "ibq_tp0", CUDBG_CIM_IBQ_TP0, ENTITY_FLAG_NULL}, 247 {"ibqtp1", "ibq_tp1", CUDBG_CIM_IBQ_TP1, ENTITY_FLAG_NULL}, 248 {"ibqulp", "ibq_ulp", CUDBG_CIM_IBQ_ULP, ENTITY_FLAG_NULL}, 249 {"ibqsge0", "ibq_sge0", CUDBG_CIM_IBQ_SGE0, ENTITY_FLAG_NULL}, 250 {"ibqsge1", "ibq_sge1", CUDBG_CIM_IBQ_SGE1, ENTITY_FLAG_NULL}, 251 {"ibqncsi", "ibq_ncsi", CUDBG_CIM_IBQ_NCSI, ENTITY_FLAG_NULL}, 252 {"obqulp0", "obq_ulp0", CUDBG_CIM_OBQ_ULP0, ENTITY_FLAG_NULL}, 253 {"obqulp1", "obq_ulp1", CUDBG_CIM_OBQ_ULP1, ENTITY_FLAG_NULL}, 254 {"obqulp2", "obq_ulp2", CUDBG_CIM_OBQ_ULP2, ENTITY_FLAG_NULL}, 255 {"obqulp3", "obq_ulp3", CUDBG_CIM_OBQ_ULP3, ENTITY_FLAG_NULL}, 256 {"obqsge", "obq_sge", CUDBG_CIM_OBQ_SGE, ENTITY_FLAG_NULL}, 257 {"obqncsi", "obq_ncsi", CUDBG_CIM_OBQ_NCSI, ENTITY_FLAG_NULL}, 258 {"edc0", "edc0", CUDBG_EDC0, (1 << ENTITY_FLAG_BINARY)}, 259 {"edc1", "edc1", CUDBG_EDC1, (1 << ENTITY_FLAG_BINARY)}, 260 {"mc0", "mc0", CUDBG_MC0, (1 << ENTITY_FLAG_BINARY)}, 261 {"mc1", "mc1", CUDBG_MC1, (1 << ENTITY_FLAG_BINARY)}, 262 {"rss", "rss", CUDBG_RSS, ENTITY_FLAG_NULL}, 263 {"rss_pf_config", "rss_pf_config", CUDBG_RSS_PF_CONF, ENTITY_FLAG_NULL}, 264 {"rss_key", "rss_key", CUDBG_RSS_KEY, ENTITY_FLAG_NULL}, 265 {"rss_vf_config", "rss_vf_config", CUDBG_RSS_VF_CONF, ENTITY_FLAG_NULL}, 266 {"rss_config", "rss_config", CUDBG_RSS_CONF, ENTITY_FLAG_NULL}, 267 {"pathmtu", "path_mtus", CUDBG_PATH_MTU, ENTITY_FLAG_NULL}, 268 {"swstate", "sw_state", CUDBG_SW_STATE, ENTITY_FLAG_NULL}, 269 {"wtp", "wtp", CUDBG_WTP, ENTITY_FLAG_NULL}, 270 {"pmstats", "pm_stats", CUDBG_PM_STATS, ENTITY_FLAG_NULL}, 271 {"hwsched", "hw_sched", CUDBG_HW_SCHED, ENTITY_FLAG_NULL}, 272 {"tcpstats", "tcp_stats", CUDBG_TCP_STATS, ENTITY_FLAG_NULL}, 273 {"tperrstats", "tp_err_stats", CUDBG_TP_ERR_STATS, ENTITY_FLAG_NULL}, 274 {"fcoestats", "fcoe_stats", CUDBG_FCOE_STATS, ENTITY_FLAG_NULL}, 275 {"rdmastats", "rdma_stats", CUDBG_RDMA_STATS, ENTITY_FLAG_NULL}, 276 {"tpindirect", "tp_indirect", CUDBG_TP_INDIRECT, 277 1 << ENTITY_FLAG_REGISTER}, 278 {"sgeindirect", "sge_indirect", CUDBG_SGE_INDIRECT, 279 1 << ENTITY_FLAG_REGISTER}, 280 {"cplstats", "cpl_stats", CUDBG_CPL_STATS, ENTITY_FLAG_NULL}, 281 {"ddpstats", "ddp_stats", CUDBG_DDP_STATS, ENTITY_FLAG_NULL}, 282 {"wcstats", "wc_stats", CUDBG_WC_STATS, ENTITY_FLAG_NULL}, 283 {"ulprxla", "ulprx_la", CUDBG_ULPRX_LA, ENTITY_FLAG_NULL}, 284 {"lbstats", "lb_stats", CUDBG_LB_STATS, ENTITY_FLAG_NULL}, 285 {"tpla", "tp_la", CUDBG_TP_LA, ENTITY_FLAG_NULL}, 286 {"meminfo", "meminfo", CUDBG_MEMINFO, ENTITY_FLAG_NULL}, 287 {"cimpifla", "cim_pif_la", CUDBG_CIM_PIF_LA, ENTITY_FLAG_NULL}, 288 {"clk", "clk", CUDBG_CLK, ENTITY_FLAG_NULL}, 289 {"obq_sge_rx_q0", "obq_sge_rx_q0", CUDBG_CIM_OBQ_RXQ0, 290 ENTITY_FLAG_NULL}, 291 {"obq_sge_rx_q1", "obq_sge_rx_q1", CUDBG_CIM_OBQ_RXQ1, 292 ENTITY_FLAG_NULL}, 293 {"macstats", "mac_stats", CUDBG_MAC_STATS, ENTITY_FLAG_NULL}, 294 {"pcieindirect", "pcie_indirect", CUDBG_PCIE_INDIRECT, 295 1 << ENTITY_FLAG_REGISTER}, 296 {"pmindirect", "pm_indirect", CUDBG_PM_INDIRECT, 297 1 << ENTITY_FLAG_REGISTER}, 298 {"full", "full", CUDBG_FULL, ENTITY_FLAG_NULL}, 299 {"txrate", "tx_rate", CUDBG_TX_RATE, ENTITY_FLAG_NULL}, 300 {"tidinfo", "tids", CUDBG_TID_INFO, ENTITY_FLAG_NULL | 301 (1 << ENTITY_FLAG_FW_NO_ATTACH)}, 302 {"pcieconfig", "pcie_config", CUDBG_PCIE_CONFIG, ENTITY_FLAG_NULL}, 303 {"dumpcontext", "dump_context", CUDBG_DUMP_CONTEXT, ENTITY_FLAG_NULL}, 304 {"mpstcam", "mps_tcam", CUDBG_MPS_TCAM, ENTITY_FLAG_NULL}, 305 {"vpddata", "vpd_data", CUDBG_VPD_DATA, ENTITY_FLAG_NULL}, 306 {"letcam", "le_tcam", CUDBG_LE_TCAM, ENTITY_FLAG_NULL}, 307 {"cctrl", "cctrl", CUDBG_CCTRL, ENTITY_FLAG_NULL}, 308 {"maindirect", "ma_indirect", CUDBG_MA_INDIRECT, 309 1 << ENTITY_FLAG_REGISTER}, 310 {"ulptxla", "ulptx_la", CUDBG_ULPTX_LA, ENTITY_FLAG_NULL}, 311 {"extentity", "ext_entity", CUDBG_EXT_ENTITY, ENTITY_FLAG_NULL}, 312 {"upcimindirect", "up_cim_indirect", CUDBG_UP_CIM_INDIRECT, 313 1 << ENTITY_FLAG_REGISTER}, 314 {"pbttables", "pbt_tables", CUDBG_PBT_TABLE, ENTITY_FLAG_NULL}, 315 {"mboxlog", "mboxlog", CUDBG_MBOX_LOG, ENTITY_FLAG_NULL}, 316 {"hmaindirect", "hma_indirect", CUDBG_HMA_INDIRECT, 317 1 << ENTITY_FLAG_REGISTER}, 318 }; 319 320 #ifdef _KERNEL 321 typedef int (*cudbg_print_cb) (dev_info_t *dip, int, char *, ...); 322 #else 323 typedef int (*cudbg_print_cb) (char *, ...); 324 #endif 325 326 struct cudbg_init_hdr { 327 u8 major_ver; 328 u8 minor_ver; 329 u8 build_ver; 330 u8 res; 331 u16 init_struct_size; 332 }; 333 334 struct cudbg_flash_hdr { 335 u32 signature; 336 u8 major_ver; 337 u8 minor_ver; 338 u8 build_ver; 339 u8 res; 340 u64 timestamp; 341 u64 time_res; 342 u32 hdr_len; 343 u32 data_len; 344 u32 hdr_flags; 345 u32 sec_seq_no; 346 u32 reserved[22]; 347 }; 348 349 struct cudbg_param { 350 u16 param_type; 351 u16 reserved; 352 union { 353 struct { 354 u32 memtype; /* which memory (EDC0, EDC1, MC) */ 355 u32 start; /* start of log in firmware memory */ 356 u32 size; /* size of log */ 357 } devlog_param; 358 struct { 359 struct mbox_cmd_log *log; 360 u16 mbox_cmds; 361 } mboxlog_param; 362 struct { 363 u8 caller_string[100]; 364 u8 os_type; 365 } sw_state_param; 366 u64 time; 367 u8 tcb_bit_param; 368 void *adap; 369 void *access_lock; 370 } u; 371 }; 372 373 /* params for tcb_bit_param */ 374 #define CUDBG_TCB_BRIEF_PARAM 0x1 375 #define CUDBG_TCB_FROM_CARD_PARAM 0x2 376 #define CUDBG_TCB_AS_SCB_PARAM 0x4 377 378 enum { 379 /* params for os_type */ 380 CUDBG_OS_TYPE_WINDOWS = 1, 381 CUDBG_OS_TYPE_LINUX = 2, 382 CUDBG_OS_TYPE_ESX = 3, 383 CUDBG_OS_TYPE_UNKNOWN = 4, 384 }; 385 386 /* 387 * * What is OFFLINE_VIEW_ONLY mode? 388 * 389 * cudbg frame work will be used only to interpret previously collected 390 * data store in a file (i.e NOT hw flash) 391 */ 392 393 struct cudbg_init { 394 struct cudbg_init_hdr header; 395 struct adapter *adap; /* Pointer to adapter structure 396 with filled fields */ 397 cudbg_print_cb print; /* Platform dependent print 398 function */ 399 u32 verbose:1; /* Turn on verbose print */ 400 u32 use_flash:1; /* Use flash to collect or view 401 debug */ 402 u32 full_mode:1; /* If set, cudbg will pull in 403 common code */ 404 u32 no_compress:1; /* Dont compress will storing 405 the collected debug */ 406 u32 info:1; /* Show just the info, Dont 407 interpret */ 408 u32 reserved:27; 409 u8 dbg_bitmap[CUDBG_MAX_BITMAP_LEN]; 410 /* Bit map to select the dbg 411 data type to be collected 412 or viewed */ 413 }; 414 415 struct cudbg_private { 416 struct cudbg_init dbg_init; 417 #ifdef _KERNEL 418 struct cudbg_flash_sec_info sec_info; 419 #endif 420 }; 421 422 /********************************* Helper functions *************************/ 423 void set_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type); 424 void reset_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type); 425 struct cudbg_init * cudbg_get_init(void *handle); 426 427 /** 428 * cudbg_collect - Collect and store debug information. 429 * ## Parameters ## 430 * @handle : A pointer returned by cudbg_alloc_handle. 431 * @outbuf : pointer to output buffer, to store the collected information 432 * or to use it as a scratch buffer in case HW flash is used to 433 * store the debug information. 434 * @outbuf_size : Size of output buffer. 435 * ## Return ## 436 * If the function succeeds, the return value will be size of debug information 437 * collected and stored. 438 * -ve value represent error. 439 */ 440 int cudbg_collect(void *handle, void *outbuf, u32 *outbuf_size); 441 442 int cudbg_view(void *handle, void *pinbuf, u32 inbuf_size, 443 void *poutbuf, s64 *poutbuf_size); 444 void init_cudbg_hdr(struct cudbg_init_hdr *hdr); 445 void * cudbg_alloc_handle(void); 446 void cudbg_free_handle(void *handle); 447 #endif /* _CUDBG_IF_H_ */ 448