2 * Copyright (c) 2017 Chelsio Communications, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Chelsio Unified Debug Interface header file.
38 #define ATTRIBUTE_UNUSED __attribute__ ((unused))
40 #define ATTRIBUTE_UNUSED
43 #if defined(CONFIG_CUDBG_DEBUG)
44 #define cudbg_debug(pdbg_init, format, ...) do {\
45 pdbg_init->print(format, ##__VA_ARGS__); \
48 #define cudbg_debug(pdbg_init, format, ...) do { } while (0)
57 #define CUDBG_STATUS_SUCCESS 0
58 #define CUDBG_STATUS_NOSPACE -2
59 #define CUDBG_STATUS_FLASH_WRITE_FAIL -3
60 #define CUDBG_STATUS_FLASH_READ_FAIL -4
61 #define CUDBG_STATUS_UNDEFINED_OUT_BUF -5
62 #define CUDBG_STATUS_UNDEFINED_CBFN -6
63 #define CUDBG_STATUS_UNDEFINED_PRINTF_CBFN -7
64 #define CUDBG_STATUS_ADAP_INVALID -8
65 #define CUDBG_STATUS_FLASH_EMPTY -9
66 #define CUDBG_STATUS_NO_ADAPTER -10
67 #define CUDBG_STATUS_NO_SIGNATURE -11
68 #define CUDBG_STATUS_MULTIPLE_REG -12
69 #define CUDBG_STATUS_UNREGISTERED -13
70 #define CUDBG_STATUS_UNDEFINED_ENTITY -14
71 #define CUDBG_STATUS_REG_FAIlED -15
72 #define CUDBG_STATUS_DEVLOG_FAILED -16
73 #define CUDBG_STATUS_SMALL_BUFF -17
74 #define CUDBG_STATUS_CHKSUM_MISSMATCH -18
75 #define CUDBG_STATUS_NO_SCRATCH_MEM -19
76 #define CUDBG_STATUS_OUTBUFF_OVERFLOW -20
77 #define CUDBG_STATUS_INVALID_BUFF -21 /* Invalid magic */
78 #define CUDBG_STATUS_FILE_OPEN_FAIL -22
79 #define CUDBG_STATUS_DEVLOG_INT_FAIL -23
80 #define CUDBG_STATUS_ENTITY_NOT_FOUND -24
81 #define CUDBG_STATUS_DECOMPRESS_FAIL -25
82 #define CUDBG_STATUS_BUFFER_SHORT -26
83 #define CUDBG_METADATA_VERSION_MISMATCH -27
84 #define CUDBG_STATUS_NOT_IMPLEMENTED -28
85 #define CUDBG_SYSTEM_ERROR -29
86 #define CUDBG_STATUS_MMAP_FAILED -30
87 #define CUDBG_STATUS_FILE_WRITE_FAILED -31
88 #define CUDBG_STATUS_CCLK_NOT_DEFINED -32
89 #define CUDBG_STATUS_FLASH_FULL -33
90 #define CUDBG_STATUS_SECTOR_EMPTY -34
91 #define CUDBG_STATUS_ENTITY_NOT_REQUESTED -35
92 #define CUDBG_STATUS_NOT_SUPPORTED -36
93 #define CUDBG_STATUS_FILE_READ_FAILED -37
94 #define CUDBG_STATUS_CORRUPTED -38
95 #define CUDBG_STATUS_INVALID_INDEX -39
97 #define CUDBG_MAJOR_VERSION 1
98 #define CUDBG_MINOR_VERSION 14
99 #define CUDBG_BUILD_VERSION 0
101 #define CUDBG_FILE_NAME_LEN 256
102 #define CUDBG_DIR_NAME_LEN 256
103 #define CUDBG_MAX_BITMAP_LEN 16
105 static char ATTRIBUTE_UNUSED * err_msg[] = {
112 "Callback function undefined",
113 "Print callback function undefined",
118 "Multiple registration",
141 "Entity not requested",
148 enum CUDBG_DBG_ENTITY_TYPE {
155 CUDBG_CIM_IBQ_TP0 = 6,
156 CUDBG_CIM_IBQ_TP1 = 7,
157 CUDBG_CIM_IBQ_ULP = 8,
158 CUDBG_CIM_IBQ_SGE0 = 9,
159 CUDBG_CIM_IBQ_SGE1 = 10,
160 CUDBG_CIM_IBQ_NCSI = 11,
161 CUDBG_CIM_OBQ_ULP0 = 12,
162 CUDBG_CIM_OBQ_ULP1 = 13,
163 CUDBG_CIM_OBQ_ULP2 = 14,
164 CUDBG_CIM_OBQ_ULP3 = 15,
165 CUDBG_CIM_OBQ_SGE = 16,
166 CUDBG_CIM_OBQ_NCSI = 17,
172 CUDBG_RSS_PF_CONF = 23,
174 CUDBG_RSS_VF_CONF = 25,
181 CUDBG_TCP_STATS = 32,
182 CUDBG_TP_ERR_STATS = 33,
183 CUDBG_FCOE_STATS = 34,
184 CUDBG_RDMA_STATS = 35,
185 CUDBG_TP_INDIRECT = 36,
186 CUDBG_SGE_INDIRECT = 37,
187 CUDBG_CPL_STATS = 38,
188 CUDBG_DDP_STATS = 39,
194 CUDBG_CIM_PIF_LA = 45,
196 CUDBG_CIM_OBQ_RXQ0 = 47,
197 CUDBG_CIM_OBQ_RXQ1 = 48,
198 CUDBG_MAC_STATS = 49,
199 CUDBG_PCIE_INDIRECT = 50,
200 CUDBG_PM_INDIRECT = 51,
204 CUDBG_PCIE_CONFIG = 55,
205 CUDBG_DUMP_CONTEXT = 56,
210 CUDBG_MA_INDIRECT = 61,
212 CUDBG_EXT_ENTITY = 63,
213 CUDBG_UP_CIM_INDIRECT = 64,
214 CUDBG_PBT_TABLE = 65,
216 CUDBG_HMA_INDIRECT = 67,
217 CUDBG_MAX_ENTITY = 68,
220 #define ENTITY_FLAG_NULL 0
221 #define ENTITY_FLAG_REGISTER 1
222 #define ENTITY_FLAG_BINARY 2
223 #define ENTITY_FLAG_FW_NO_ATTACH 3
225 /* file_name matches Linux cxgb4 debugfs entry names. */
226 struct el {char *name; char *file_name; int bit; u32 flag; };
227 static struct el ATTRIBUTE_UNUSED entity_list[] = {
228 {"all", "all", CUDBG_ALL, ENTITY_FLAG_NULL},
229 {"regdump", "regdump", CUDBG_REG_DUMP, 1 << ENTITY_FLAG_REGISTER},
230 /* {"reg", CUDBG_REG_DUMP},*/
231 {"devlog", "devlog", CUDBG_DEV_LOG, ENTITY_FLAG_NULL},
232 {"cimla", "cim_la", CUDBG_CIM_LA, ENTITY_FLAG_NULL},
233 {"cimmala", "cim_ma_la", CUDBG_CIM_MA_LA, ENTITY_FLAG_NULL},
234 {"cimqcfg", "cim_qcfg", CUDBG_CIM_QCFG, ENTITY_FLAG_NULL},
235 {"ibqtp0", "ibq_tp0", CUDBG_CIM_IBQ_TP0, ENTITY_FLAG_NULL},
236 {"ibqtp1", "ibq_tp1", CUDBG_CIM_IBQ_TP1, ENTITY_FLAG_NULL},
237 {"ibqulp", "ibq_ulp", CUDBG_CIM_IBQ_ULP, ENTITY_FLAG_NULL},
238 {"ibqsge0", "ibq_sge0", CUDBG_CIM_IBQ_SGE0, ENTITY_FLAG_NULL},
239 {"ibqsge1", "ibq_sge1", CUDBG_CIM_IBQ_SGE1, ENTITY_FLAG_NULL},
240 {"ibqncsi", "ibq_ncsi", CUDBG_CIM_IBQ_NCSI, ENTITY_FLAG_NULL},
241 {"obqulp0", "obq_ulp0", CUDBG_CIM_OBQ_ULP0, ENTITY_FLAG_NULL},
242 /* {"cimobqulp1", CUDBG_CIM_OBQ_ULP1},*/
243 {"obqulp1", "obq_ulp1", CUDBG_CIM_OBQ_ULP1, ENTITY_FLAG_NULL},
244 {"obqulp2", "obq_ulp2", CUDBG_CIM_OBQ_ULP2, ENTITY_FLAG_NULL},
245 {"obqulp3", "obq_ulp3", CUDBG_CIM_OBQ_ULP3, ENTITY_FLAG_NULL},
246 {"obqsge", "obq_sge", CUDBG_CIM_OBQ_SGE, ENTITY_FLAG_NULL},
247 {"obqncsi", "obq_ncsi", CUDBG_CIM_OBQ_NCSI, ENTITY_FLAG_NULL},
248 {"edc0", "edc0", CUDBG_EDC0, (1 << ENTITY_FLAG_BINARY)},
249 {"edc1", "edc1", CUDBG_EDC1, (1 << ENTITY_FLAG_BINARY)},
250 {"mc0", "mc0", CUDBG_MC0, (1 << ENTITY_FLAG_BINARY)},
251 {"mc1", "mc1", CUDBG_MC1, (1 << ENTITY_FLAG_BINARY)},
252 {"rss", "rss", CUDBG_RSS, ENTITY_FLAG_NULL},
253 {"rss_pf_config", "rss_pf_config", CUDBG_RSS_PF_CONF, ENTITY_FLAG_NULL},
254 {"rss_key", "rss_key", CUDBG_RSS_KEY, ENTITY_FLAG_NULL},
255 {"rss_vf_config", "rss_vf_config", CUDBG_RSS_VF_CONF, ENTITY_FLAG_NULL},
256 {"rss_config", "rss_config", CUDBG_RSS_CONF, ENTITY_FLAG_NULL},
257 {"pathmtu", "path_mtus", CUDBG_PATH_MTU, ENTITY_FLAG_NULL},
258 {"swstate", "sw_state", CUDBG_SW_STATE, ENTITY_FLAG_NULL},
259 {"wtp", "wtp", CUDBG_WTP, ENTITY_FLAG_NULL},
260 {"pmstats", "pm_stats", CUDBG_PM_STATS, ENTITY_FLAG_NULL},
261 {"hwsched", "hw_sched", CUDBG_HW_SCHED, ENTITY_FLAG_NULL},
262 {"tcpstats", "tcp_stats", CUDBG_TCP_STATS, ENTITY_FLAG_NULL},
263 {"tperrstats", "tp_err_stats", CUDBG_TP_ERR_STATS, ENTITY_FLAG_NULL},
264 {"fcoestats", "fcoe_stats", CUDBG_FCOE_STATS, ENTITY_FLAG_NULL},
265 {"rdmastats", "rdma_stats", CUDBG_RDMA_STATS, ENTITY_FLAG_NULL},
266 {"tpindirect", "tp_indirect", CUDBG_TP_INDIRECT,
267 1 << ENTITY_FLAG_REGISTER},
268 {"sgeindirect", "sge_indirect", CUDBG_SGE_INDIRECT,
269 1 << ENTITY_FLAG_REGISTER},
270 {"cplstats", "cpl_stats", CUDBG_CPL_STATS, ENTITY_FLAG_NULL},
271 {"ddpstats", "ddp_stats", CUDBG_DDP_STATS, ENTITY_FLAG_NULL},
272 {"wcstats", "wc_stats", CUDBG_WC_STATS, ENTITY_FLAG_NULL},
273 {"ulprxla", "ulprx_la", CUDBG_ULPRX_LA, ENTITY_FLAG_NULL},
274 {"lbstats", "lb_stats", CUDBG_LB_STATS, ENTITY_FLAG_NULL},
275 {"tpla", "tp_la", CUDBG_TP_LA, ENTITY_FLAG_NULL},
276 {"meminfo", "meminfo", CUDBG_MEMINFO, ENTITY_FLAG_NULL},
277 {"cimpifla", "cim_pif_la", CUDBG_CIM_PIF_LA, ENTITY_FLAG_NULL},
278 {"clk", "clk", CUDBG_CLK, ENTITY_FLAG_NULL},
279 {"obq_sge_rx_q0", "obq_sge_rx_q0", CUDBG_CIM_OBQ_RXQ0,
281 {"obq_sge_rx_q1", "obq_sge_rx_q1", CUDBG_CIM_OBQ_RXQ1,
283 {"macstats", "mac_stats", CUDBG_MAC_STATS, ENTITY_FLAG_NULL},
284 {"pcieindirect", "pcie_indirect", CUDBG_PCIE_INDIRECT,
285 1 << ENTITY_FLAG_REGISTER},
286 {"pmindirect", "pm_indirect", CUDBG_PM_INDIRECT,
287 1 << ENTITY_FLAG_REGISTER},
288 {"full", "full", CUDBG_FULL, ENTITY_FLAG_NULL},
289 {"txrate", "tx_rate", CUDBG_TX_RATE, ENTITY_FLAG_NULL},
290 {"tidinfo", "tids", CUDBG_TID_INFO, ENTITY_FLAG_NULL |
291 (1 << ENTITY_FLAG_FW_NO_ATTACH)},
292 {"pcieconfig", "pcie_config", CUDBG_PCIE_CONFIG, ENTITY_FLAG_NULL},
293 {"dumpcontext", "dump_context", CUDBG_DUMP_CONTEXT, ENTITY_FLAG_NULL},
294 {"mpstcam", "mps_tcam", CUDBG_MPS_TCAM, ENTITY_FLAG_NULL},
295 {"vpddata", "vpd_data", CUDBG_VPD_DATA, ENTITY_FLAG_NULL},
296 {"letcam", "le_tcam", CUDBG_LE_TCAM, ENTITY_FLAG_NULL},
297 {"cctrl", "cctrl", CUDBG_CCTRL, ENTITY_FLAG_NULL},
298 {"maindirect", "ma_indirect", CUDBG_MA_INDIRECT,
299 1 << ENTITY_FLAG_REGISTER},
300 {"ulptxla", "ulptx_la", CUDBG_ULPTX_LA, ENTITY_FLAG_NULL},
301 {"extentity", "ext_entity", CUDBG_EXT_ENTITY, ENTITY_FLAG_NULL},
302 {"upcimindirect", "up_cim_indirect", CUDBG_UP_CIM_INDIRECT,
303 1 << ENTITY_FLAG_REGISTER},
304 {"pbttables", "pbt_tables", CUDBG_PBT_TABLE, ENTITY_FLAG_NULL},
305 {"mboxlog", "mboxlog", CUDBG_MBOX_LOG, ENTITY_FLAG_NULL},
306 {"hmaindirect", "hma_indirect", CUDBG_HMA_INDIRECT,
307 1 << ENTITY_FLAG_REGISTER},
310 typedef int (*cudbg_print_cb) (char *str, ...);
312 struct cudbg_init_hdr {
317 u16 init_struct_size;
320 struct cudbg_flash_hdr {
340 u32 memtype; /* which memory (EDC0, EDC1, MC) */
341 u32 start; /* start of log in firmware memory */
342 u32 size; /* size of log */
345 struct mbox_cmd_log *log;
349 u8 caller_string[100];
359 /* params for tcb_bit_param */
360 #define CUDBG_TCB_BRIEF_PARAM 0x1
361 #define CUDBG_TCB_FROM_CARD_PARAM 0x2
362 #define CUDBG_TCB_AS_SCB_PARAM 0x4
365 * * What is OFFLINE_VIEW_ONLY mode?
367 * cudbg frame work will be used only to interpret previously collected
368 * data store in a file (i.e NOT hw flash)
372 struct cudbg_init_hdr header;
373 struct adapter *adap; /* Pointer to adapter structure
374 with filled fields */
375 cudbg_print_cb print; /* Platform dependent print
377 u32 verbose:1; /* Turn on verbose print */
378 u32 use_flash:1; /* Use flash to collect or view
380 u32 full_mode:1; /* If set, cudbg will pull in
382 u32 no_compress:1; /* Dont compress will storing
383 the collected debug */
384 u32 info:1; /* Show just the info, Dont
387 u8 dbg_bitmap[CUDBG_MAX_BITMAP_LEN];
388 /* Bit map to select the dbg
389 data type to be collected
394 /********************************* Helper functions *************************/
395 static inline void set_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type)
397 int index = type / 8;
400 bitmap[index] |= (1 << bit);
403 static inline void reset_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type)
405 int index = type / 8;
408 bitmap[index] &= ~(1 << bit);
411 /********************************* End of Helper functions
412 * *************************/
417 * cudbg_alloc_handle - Allocates and initializes a handle that represents
418 * cudbg state. Needs to called first before calling any other function.
420 * returns a pointer to memory that has a cudbg_init structure at the begining
421 * and enough space after that for internal book keeping.
424 void *cudbg_alloc_handle(void);
425 static inline struct cudbg_init *cudbg_get_init(void *handle)
431 * cudbg_collect - Collect and store debug information.
433 * @handle : A pointer returned by cudbg_alloc_handle.
434 * @outbuf : pointer to output buffer, to store the collected information
435 * or to use it as a scratch buffer in case HW flash is used to
436 * store the debug information.
437 * @outbuf_size : Size of output buffer.
439 * If the function succeeds, the return value will be size of debug information
440 * collected and stored.
441 * -ve value represent error.
443 int cudbg_collect(void *handle, void *outbuf, u32 *outbuf_size);
446 * cudbg_free_handle - Release cudbg resources.
448 * @handle : A pointer returned by cudbg_alloc_handle.
451 void cudbg_free_handle(IN void *handle);
454 * cudbg_read_flash_data - Read cudbg “flash” header from adapter flash.
455 * This will be used by the consumer mainly to
456 * know the size of the data in flash.
458 * @handle : A pointer returned by cudbg_hello.
459 * @data : A pointer to data/header buffer
462 int cudbg_read_flash_details(void *handle, struct cudbg_flash_hdr *data);
465 * cudbg_read_flash_data - Read cudbg dump contents stored in flash.
467 * @handle : A pointer returned by cudbg_hello.
468 * @data_buf : A pointer to data buffer.
469 * @data_buf_size : Data buffer size.
472 int cudbg_read_flash_data(void *handle, void *data_buf, u32 data_buf_size);
474 #endif /* _CUDBG_IF_H_ */