17e6ad46Vishal Kulkarni/*
27e6ad46Vishal Kulkarni * This file and its contents are supplied under the terms of the
37e6ad46Vishal Kulkarni * Common Development and Distribution License ("CDDL"), version 1.0.
47e6ad46Vishal Kulkarni * You may only use this file in accordance with the terms of version
57e6ad46Vishal Kulkarni * 1.0 of the CDDL.
67e6ad46Vishal Kulkarni *
77e6ad46Vishal Kulkarni * A full copy of the text of the CDDL should have accompanied this
87e6ad46Vishal Kulkarni * source. A copy of the CDDL is also available via the Internet at
97e6ad46Vishal Kulkarni * http://www.illumos.org/license/CDDL.
107e6ad46Vishal Kulkarni */
117e6ad46Vishal Kulkarni
127e6ad46Vishal Kulkarni/*-
137e6ad46Vishal Kulkarni * Copyright (c) 2019 Chelsio Communications, Inc.
147e6ad46Vishal Kulkarni * All rights reserved.
157e6ad46Vishal Kulkarni * * Redistribution and use in source and binary forms, with or without
167e6ad46Vishal Kulkarni * modification, are permitted provided that the following conditions * are met:
177e6ad46Vishal Kulkarni * 1. Redistributions of source code must retain the above copyright
187e6ad46Vishal Kulkarni *    notice, this list of conditions and the following disclaimer.
197e6ad46Vishal Kulkarni * 2. Redistributions in binary form must reproduce the above copyright
207e6ad46Vishal Kulkarni *    notice, this list of conditions and the following disclaimer in the
217e6ad46Vishal Kulkarni *    documentation and/or other materials provided with the distribution.
227e6ad46Vishal Kulkarni *
237e6ad46Vishal Kulkarni * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
247e6ad46Vishal Kulkarni * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
257e6ad46Vishal Kulkarni * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
267e6ad46Vishal Kulkarni * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
277e6ad46Vishal Kulkarni * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
287e6ad46Vishal Kulkarni * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
297e6ad46Vishal Kulkarni * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
307e6ad46Vishal Kulkarni * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
317e6ad46Vishal Kulkarni * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
327e6ad46Vishal Kulkarni * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
337e6ad46Vishal Kulkarni * SUCH DAMAGE.
347e6ad46Vishal Kulkarni */
357e6ad46Vishal Kulkarni
367e6ad46Vishal Kulkarni/*
377e6ad46Vishal Kulkarni * Chelsio Unified Debug Interface header file.
387e6ad46Vishal Kulkarni * Version 1.1
397e6ad46Vishal Kulkarni */
407e6ad46Vishal Kulkarni#ifndef _CUDBG_IF_H_
417e6ad46Vishal Kulkarni#define _CUDBG_IF_H_
427e6ad46Vishal Kulkarni
437e6ad46Vishal Kulkarni#ifndef _KERNEL
447e6ad46Vishal Kulkarni#include <stdlib.h>
457e6ad46Vishal Kulkarni#endif
467e6ad46Vishal Kulkarni
477e6ad46Vishal Kulkarni#include "cudbg_lib_common.h"
487e6ad46Vishal Kulkarni
497e6ad46Vishal Kulkarni#ifdef __GNUC__
507e6ad46Vishal Kulkarni#define ATTRIBUTE_UNUSED __attribute__ ((unused))
517e6ad46Vishal Kulkarni#else
527e6ad46Vishal Kulkarni#define ATTRIBUTE_UNUSED
537e6ad46Vishal Kulkarni#endif
547e6ad46Vishal Kulkarni
557e6ad46Vishal Kulkarni#if defined(CONFIG_CUDBG_DEBUG)
567e6ad46Vishal Kulkarni#define cudbg_debug(pdbg_init, format,  ...) do {\
577e6ad46Vishal Kulkarni	pdbg_init->print(format, ##__VA_ARGS__); \
587e6ad46Vishal Kulkarni} while (0)
597e6ad46Vishal Kulkarni#else
607e6ad46Vishal Kulkarni#define cudbg_debug(pdbg_init, format,  ...) do { } while (0)
617e6ad46Vishal Kulkarni#endif
627e6ad46Vishal Kulkarni
637e6ad46Vishal Kulkarni#define OUT
647e6ad46Vishal Kulkarni#define IN
657e6ad46Vishal Kulkarni#define INOUT
667e6ad46Vishal Kulkarni
677e6ad46Vishal Kulkarni/* Error codes */
687e6ad46Vishal Kulkarni
697e6ad46Vishal Kulkarni#define CUDBG_STATUS_SUCCESS		     0
707e6ad46Vishal Kulkarni#define CUDBG_STATUS_NOSPACE		    -2
717e6ad46Vishal Kulkarni#define CUDBG_STATUS_FLASH_WRITE_FAIL	    -3
727e6ad46Vishal Kulkarni#define CUDBG_STATUS_FLASH_READ_FAIL	    -4
737e6ad46Vishal Kulkarni#define CUDBG_STATUS_UNDEFINED_OUT_BUF	    -5
747e6ad46Vishal Kulkarni#define CUDBG_STATUS_UNDEFINED_CBFN	    -6
757e6ad46Vishal Kulkarni#define CUDBG_STATUS_UNDEFINED_PRINTF_CBFN  -7
767e6ad46Vishal Kulkarni#define CUDBG_STATUS_ADAP_INVALID	    -8
777e6ad46Vishal Kulkarni#define CUDBG_STATUS_FLASH_EMPTY	    -9
787e6ad46Vishal Kulkarni#define CUDBG_STATUS_NO_ADAPTER		    -10
797e6ad46Vishal Kulkarni#define CUDBG_STATUS_NO_SIGNATURE	    -11
807e6ad46Vishal Kulkarni#define CUDBG_STATUS_MULTIPLE_REG	    -12
817e6ad46Vishal Kulkarni#define CUDBG_STATUS_UNREGISTERED	    -13
827e6ad46Vishal Kulkarni#define CUDBG_STATUS_UNDEFINED_ENTITY	    -14
837e6ad46Vishal Kulkarni#define CUDBG_STATUS_REG_FAIlED		    -15
847e6ad46Vishal Kulkarni#define CUDBG_STATUS_DEVLOG_FAILED	    -16
857e6ad46Vishal Kulkarni#define CUDBG_STATUS_SMALL_BUFF		    -17
867e6ad46Vishal Kulkarni#define CUDBG_STATUS_CHKSUM_MISSMATCH	    -18
877e6ad46Vishal Kulkarni#define CUDBG_STATUS_NO_SCRATCH_MEM	    -19
887e6ad46Vishal Kulkarni#define CUDBG_STATUS_OUTBUFF_OVERFLOW	    -20
897e6ad46Vishal Kulkarni#define CUDBG_STATUS_INVALID_BUFF	    -21  /* Invalid magic */
907e6ad46Vishal Kulkarni#define CUDBG_STATUS_FILE_OPEN_FAIL	    -22
917e6ad46Vishal Kulkarni#define CUDBG_STATUS_DEVLOG_INT_FAIL	    -23
927e6ad46Vishal Kulkarni#define CUDBG_STATUS_ENTITY_NOT_FOUND	    -24
937e6ad46Vishal Kulkarni#define CUDBG_STATUS_DECOMPRESS_FAIL	    -25
947e6ad46Vishal Kulkarni#define CUDBG_STATUS_BUFFER_SHORT	    -26
957e6ad46Vishal Kulkarni#define CUDBG_METADATA_VERSION_MISMATCH     -27
967e6ad46Vishal Kulkarni#define CUDBG_STATUS_NOT_IMPLEMENTED	    -28
977e6ad46Vishal Kulkarni#define CUDBG_SYSTEM_ERROR		    -29
987e6ad46Vishal Kulkarni#define CUDBG_STATUS_MMAP_FAILED	    -30
997e6ad46Vishal Kulkarni#define CUDBG_STATUS_FILE_WRITE_FAILED	    -31
1007e6ad46Vishal Kulkarni#define CUDBG_STATUS_CCLK_NOT_DEFINED	    -32
1017e6ad46Vishal Kulkarni#define CUDBG_STATUS_FLASH_FULL            -33
1027e6ad46Vishal Kulkarni#define CUDBG_STATUS_SECTOR_EMPTY          -34
1037e6ad46Vishal Kulkarni#define CUDBG_STATUS_ENTITY_NOT_REQUESTED  -35
1047e6ad46Vishal Kulkarni#define CUDBG_STATUS_NOT_SUPPORTED         -36
1057e6ad46Vishal Kulkarni#define CUDBG_STATUS_FILE_READ_FAILED      -37
1067e6ad46Vishal Kulkarni#define CUDBG_STATUS_CORRUPTED             -38
1077e6ad46Vishal Kulkarni#define CUDBG_STATUS_INVALID_INDEX         -39
1087e6ad46Vishal Kulkarni
1097e6ad46Vishal Kulkarni#define CUDBG_MAJOR_VERSION		    1
1107e6ad46Vishal Kulkarni#define CUDBG_MINOR_VERSION		    14
1117e6ad46Vishal Kulkarni#define CUDBG_BUILD_VERSION		    0
1127e6ad46Vishal Kulkarni
1137e6ad46Vishal Kulkarni#define CUDBG_FILE_NAME_LEN 256
1147e6ad46Vishal Kulkarni#define CUDBG_DIR_NAME_LEN  256
1157e6ad46Vishal Kulkarni#define CUDBG_MAX_BITMAP_LEN 16
1167e6ad46Vishal Kulkarni
1177e6ad46Vishal Kulkarnistatic char ATTRIBUTE_UNUSED * err_msg[] = {
1187e6ad46Vishal Kulkarni	"Success",
1197e6ad46Vishal Kulkarni	"Unknown",
1207e6ad46Vishal Kulkarni	"No space",
1217e6ad46Vishal Kulkarni	"Flash write fail",
1227e6ad46Vishal Kulkarni	"Flash read fail",
1237e6ad46Vishal Kulkarni	"Undefined out buf",
1247e6ad46Vishal Kulkarni	"Callback function undefined",
1257e6ad46Vishal Kulkarni	"Print callback function undefined",
1267e6ad46Vishal Kulkarni	"ADAP invalid",
1277e6ad46Vishal Kulkarni	"Flash empty",
1287e6ad46Vishal Kulkarni	"No adapter",
1297e6ad46Vishal Kulkarni	"No signature",
1307e6ad46Vishal Kulkarni	"Multiple registration",
1317e6ad46Vishal Kulkarni	"Unregistered",
1327e6ad46Vishal Kulkarni	"Undefined entity",
1337e6ad46Vishal Kulkarni	"Reg failed",
1347e6ad46Vishal Kulkarni	"Devlog failed",
1357e6ad46Vishal Kulkarni	"Small buff",
1367e6ad46Vishal Kulkarni	"Checksum mismatch",
1377e6ad46Vishal Kulkarni	"No scratch memory",
1387e6ad46Vishal Kulkarni	"Outbuff overflow",
1397e6ad46Vishal Kulkarni	"Invalid buffer",
1407e6ad46Vishal Kulkarni	"File open fail",
1417e6ad46Vishal Kulkarni	"Devlog int fail",
1427e6ad46Vishal Kulkarni	"Entity not found",
1437e6ad46Vishal Kulkarni	"Decompress fail",
1447e6ad46Vishal Kulkarni	"Buffer short",
1457e6ad46Vishal Kulkarni	"Version mismatch",
1467e6ad46Vishal Kulkarni	"Not implemented",
1477e6ad46Vishal Kulkarni	"System error",
1487e6ad46Vishal Kulkarni	"Mmap failed",
1497e6ad46Vishal Kulkarni	"File write failed",
1507e6ad46Vishal Kulkarni	"cclk not defined",
1517e6ad46Vishal Kulkarni	"Flash full",
1527e6ad46Vishal Kulkarni	"Sector empty",
1537e6ad46Vishal Kulkarni	"Entity not requested",
1547e6ad46Vishal Kulkarni	"Not supported",
1557e6ad46Vishal Kulkarni	"File read fail",
1567e6ad46Vishal Kulkarni	"Corrupted",
1577e6ad46Vishal Kulkarni	"Invalid Index"
1587e6ad46Vishal Kulkarni};
1597e6ad46Vishal Kulkarni
1607e6ad46Vishal Kulkarnienum CUDBG_DBG_ENTITY_TYPE {
1617e6ad46Vishal Kulkarni	CUDBG_ALL	   = 0,
1627e6ad46Vishal Kulkarni	CUDBG_REG_DUMP	   = 1,
1637e6ad46Vishal Kulkarni	CUDBG_DEV_LOG	   = 2,
1647e6ad46Vishal Kulkarni	CUDBG_CIM_LA	   = 3,
1657e6ad46Vishal Kulkarni	CUDBG_CIM_MA_LA    = 4,
1667e6ad46Vishal Kulkarni	CUDBG_CIM_QCFG	   = 5,
1677e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_TP0  = 6,
1687e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_TP1  = 7,
1697e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_ULP  = 8,
1707e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_SGE0 = 9,
1717e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_SGE1 = 10,
1727e6ad46Vishal Kulkarni	CUDBG_CIM_IBQ_NCSI = 11,
1737e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_ULP0 = 12,
1747e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_ULP1 = 13,
1757e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_ULP2 = 14,
1767e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_ULP3 = 15,
1777e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_SGE  = 16,
1787e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_NCSI = 17,
1797e6ad46Vishal Kulkarni	CUDBG_EDC0	   = 18,
1807e6ad46Vishal Kulkarni	CUDBG_EDC1	   = 19,
1817e6ad46Vishal Kulkarni	CUDBG_MC0	   = 20,
1827e6ad46Vishal Kulkarni	CUDBG_MC1	   = 21,
1837e6ad46Vishal Kulkarni	CUDBG_RSS	   = 22,
1847e6ad46Vishal Kulkarni	CUDBG_RSS_PF_CONF  = 23,
1857e6ad46Vishal Kulkarni	CUDBG_RSS_KEY	   = 24,
1867e6ad46Vishal Kulkarni	CUDBG_RSS_VF_CONF  = 25,
1877e6ad46Vishal Kulkarni	CUDBG_RSS_CONF	   = 26,
1887e6ad46Vishal Kulkarni	CUDBG_PATH_MTU	   = 27,
1897e6ad46Vishal Kulkarni	CUDBG_SW_STATE	   = 28,
1907e6ad46Vishal Kulkarni	CUDBG_WTP	   = 29,
1917e6ad46Vishal Kulkarni	CUDBG_PM_STATS	   = 30,
1927e6ad46Vishal Kulkarni	CUDBG_HW_SCHED	   = 31,
1937e6ad46Vishal Kulkarni	CUDBG_TCP_STATS    = 32,
1947e6ad46Vishal Kulkarni	CUDBG_TP_ERR_STATS = 33,
1957e6ad46Vishal Kulkarni	CUDBG_FCOE_STATS   = 34,
1967e6ad46Vishal Kulkarni	CUDBG_RDMA_STATS   = 35,
1977e6ad46Vishal Kulkarni	CUDBG_TP_INDIRECT  = 36,
1987e6ad46Vishal Kulkarni	CUDBG_SGE_INDIRECT = 37,
1997e6ad46Vishal Kulkarni	CUDBG_CPL_STATS    = 38,
2007e6ad46Vishal Kulkarni	CUDBG_DDP_STATS    = 39,
2017e6ad46Vishal Kulkarni	CUDBG_WC_STATS	   = 40,
2027e6ad46Vishal Kulkarni	CUDBG_ULPRX_LA	   = 41,
2037e6ad46Vishal Kulkarni	CUDBG_LB_STATS	   = 42,
2047e6ad46Vishal Kulkarni	CUDBG_TP_LA	   = 43,
2057e6ad46Vishal Kulkarni	CUDBG_MEMINFO	   = 44,
2067e6ad46Vishal Kulkarni	CUDBG_CIM_PIF_LA   = 45,
2077e6ad46Vishal Kulkarni	CUDBG_CLK	   = 46,
2087e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_RXQ0 = 47,
2097e6ad46Vishal Kulkarni	CUDBG_CIM_OBQ_RXQ1 = 48,
2107e6ad46Vishal Kulkarni	CUDBG_MAC_STATS    = 49,
2117e6ad46Vishal Kulkarni	CUDBG_PCIE_INDIRECT = 50,
2127e6ad46Vishal Kulkarni	CUDBG_PM_INDIRECT  = 51,
2137e6ad46Vishal Kulkarni	CUDBG_FULL	   = 52,
2147e6ad46Vishal Kulkarni	CUDBG_TX_RATE	   = 53,
2157e6ad46Vishal Kulkarni	CUDBG_TID_INFO	   = 54,
2167e6ad46Vishal Kulkarni	CUDBG_PCIE_CONFIG  = 55,
2177e6ad46Vishal Kulkarni	CUDBG_DUMP_CONTEXT = 56,
2187e6ad46Vishal Kulkarni	CUDBG_MPS_TCAM	   = 57,
2197e6ad46Vishal Kulkarni	CUDBG_VPD_DATA	   = 58,
2207e6ad46Vishal Kulkarni	CUDBG_LE_TCAM	   = 59,
2217e6ad46Vishal Kulkarni	CUDBG_CCTRL	   = 60,
2227e6ad46Vishal Kulkarni	CUDBG_MA_INDIRECT  = 61,
2237e6ad46Vishal Kulkarni	CUDBG_ULPTX_LA	   = 62,
2247e6ad46Vishal Kulkarni	CUDBG_EXT_ENTITY   = 63,
2257e6ad46Vishal Kulkarni	CUDBG_UP_CIM_INDIRECT = 64,
2267e6ad46Vishal Kulkarni	CUDBG_PBT_TABLE    = 65,
2277e6ad46Vishal Kulkarni	CUDBG_MBOX_LOG     = 66,
2287e6ad46Vishal Kulkarni	CUDBG_HMA_INDIRECT = 67,
2297e6ad46Vishal Kulkarni	CUDBG_MAX_ENTITY   = 68,
2307e6ad46Vishal Kulkarni};
2317e6ad46Vishal Kulkarni
2327e6ad46Vishal Kulkarni#define ENTITY_FLAG_NULL 0
2337e6ad46Vishal Kulkarni#define ENTITY_FLAG_REGISTER 1
2347e6ad46Vishal Kulkarni#define ENTITY_FLAG_BINARY 2
2357e6ad46Vishal Kulkarni#define ENTITY_FLAG_FW_NO_ATTACH    3
2367e6ad46Vishal Kulkarni
2377e6ad46Vishal Kulkarni/* file_name matches Linux cxgb4 debugfs entry names. */
2387e6ad46Vishal Kulkarnistruct el {char *name; char *file_name; int bit; u32 flag; };
2397e6ad46Vishal Kulkarnistatic struct el ATTRIBUTE_UNUSED entity_list[] = {
2407e6ad46Vishal Kulkarni	{"all", "all", CUDBG_ALL, ENTITY_FLAG_NULL},
2417e6ad46Vishal Kulkarni	{"regdump", "regdump", CUDBG_REG_DUMP, 1 << ENTITY_FLAG_REGISTER},
2427e6ad46Vishal Kulkarni	{"devlog", "devlog", CUDBG_DEV_LOG, ENTITY_FLAG_NULL},
2437e6ad46Vishal Kulkarni	{"cimla", "cim_la", CUDBG_CIM_LA, ENTITY_FLAG_NULL},
2447e6ad46Vishal Kulkarni	{"cimmala", "cim_ma_la", CUDBG_CIM_MA_LA, ENTITY_FLAG_NULL},
2457e6ad46Vishal Kulkarni	{"cimqcfg", "cim_qcfg", CUDBG_CIM_QCFG, ENTITY_FLAG_NULL},
2467e6ad46Vishal Kulkarni	{"ibqtp0", "ibq_tp0", CUDBG_CIM_IBQ_TP0, ENTITY_FLAG_NULL},
2477e6ad46Vishal Kulkarni	{"ibqtp1", "ibq_tp1", CUDBG_CIM_IBQ_TP1, ENTITY_FLAG_NULL},
2487e6ad46Vishal Kulkarni	{"ibqulp", "ibq_ulp", CUDBG_CIM_IBQ_ULP, ENTITY_FLAG_NULL},
2497e6ad46Vishal Kulkarni	{"ibqsge0", "ibq_sge0", CUDBG_CIM_IBQ_SGE0, ENTITY_FLAG_NULL},
2507e6ad46Vishal Kulkarni	{"ibqsge1", "ibq_sge1", CUDBG_CIM_IBQ_SGE1, ENTITY_FLAG_NULL},
2517e6ad46Vishal Kulkarni	{"ibqncsi", "ibq_ncsi", CUDBG_CIM_IBQ_NCSI, ENTITY_FLAG_NULL},
2527e6ad46Vishal Kulkarni	{"obqulp0", "obq_ulp0", CUDBG_CIM_OBQ_ULP0, ENTITY_FLAG_NULL},
2537e6ad46Vishal Kulkarni	{"obqulp1", "obq_ulp1", CUDBG_CIM_OBQ_ULP1, ENTITY_FLAG_NULL},
2547e6ad46Vishal Kulkarni	{"obqulp2", "obq_ulp2", CUDBG_CIM_OBQ_ULP2, ENTITY_FLAG_NULL},
2557e6ad46Vishal Kulkarni	{"obqulp3", "obq_ulp3", CUDBG_CIM_OBQ_ULP3, ENTITY_FLAG_NULL},
2567e6ad46Vishal Kulkarni	{"obqsge", "obq_sge", CUDBG_CIM_OBQ_SGE, ENTITY_FLAG_NULL},
2577e6ad46Vishal Kulkarni	{"obqncsi", "obq_ncsi", CUDBG_CIM_OBQ_NCSI, ENTITY_FLAG_NULL},
2587e6ad46Vishal Kulkarni	{"edc0", "edc0", CUDBG_EDC0, (1 << ENTITY_FLAG_BINARY)},
2597e6ad46Vishal Kulkarni	{"edc1", "edc1", CUDBG_EDC1, (1 << ENTITY_FLAG_BINARY)},
2607e6ad46Vishal Kulkarni	{"mc0", "mc0", CUDBG_MC0, (1 << ENTITY_FLAG_BINARY)},
2617e6ad46Vishal Kulkarni	{"mc1", "mc1", CUDBG_MC1, (1 << ENTITY_FLAG_BINARY)},
2627e6ad46Vishal Kulkarni	{"rss", "rss", CUDBG_RSS, ENTITY_FLAG_NULL},
2637e6ad46Vishal Kulkarni	{"rss_pf_config", "rss_pf_config", CUDBG_RSS_PF_CONF, ENTITY_FLAG_NULL},
2647e6ad46Vishal Kulkarni	{"rss_key", "rss_key", CUDBG_RSS_KEY, ENTITY_FLAG_NULL},
2657e6ad46Vishal Kulkarni	{"rss_vf_config", "rss_vf_config", CUDBG_RSS_VF_CONF, ENTITY_FLAG_NULL},
2667e6ad46Vishal Kulkarni	{"rss_config", "rss_config", CUDBG_RSS_CONF, ENTITY_FLAG_NULL},
2677e6ad46Vishal Kulkarni	{"pathmtu", "path_mtus", CUDBG_PATH_MTU, ENTITY_FLAG_NULL},
2687e6ad46Vishal Kulkarni	{"swstate", "sw_state", CUDBG_SW_STATE, ENTITY_FLAG_NULL},
2697e6ad46Vishal Kulkarni	{"wtp", "wtp", CUDBG_WTP, ENTITY_FLAG_NULL},
2707e6ad46Vishal Kulkarni	{"pmstats", "pm_stats", CUDBG_PM_STATS, ENTITY_FLAG_NULL},
2717e6ad46Vishal Kulkarni	{"hwsched", "hw_sched", CUDBG_HW_SCHED, ENTITY_FLAG_NULL},
2727e6ad46Vishal Kulkarni	{"tcpstats", "tcp_stats", CUDBG_TCP_STATS, ENTITY_FLAG_NULL},
2737e6ad46Vishal Kulkarni	{"tperrstats", "tp_err_stats", CUDBG_TP_ERR_STATS, ENTITY_FLAG_NULL},
2747e6ad46Vishal Kulkarni	{"fcoestats", "fcoe_stats", CUDBG_FCOE_STATS, ENTITY_FLAG_NULL},
2757e6ad46Vishal Kulkarni	{"rdmastats", "rdma_stats", CUDBG_RDMA_STATS, ENTITY_FLAG_NULL},
2767e6ad46Vishal Kulkarni	{"tpindirect", "tp_indirect", CUDBG_TP_INDIRECT,
2777e6ad46Vishal Kulkarni					1 << ENTITY_FLAG_REGISTER},
2787e6ad46Vishal Kulkarni	{"sgeindirect", "sge_indirect", CUDBG_SGE_INDIRECT,
2797e6ad46Vishal Kulkarni					1 << ENTITY_FLAG_REGISTER},
2807e6ad46Vishal Kulkarni	{"cplstats", "cpl_stats", CUDBG_CPL_STATS, ENTITY_FLAG_NULL},
2817e6ad46Vishal Kulkarni	{"ddpstats", "ddp_stats", CUDBG_DDP_STATS, ENTITY_FLAG_NULL},
2827e6ad46Vishal Kulkarni	{"wcstats", "wc_stats", CUDBG_WC_STATS, ENTITY_FLAG_NULL},
2837e6ad46Vishal Kulkarni	{"ulprxla", "ulprx_la", CUDBG_ULPRX_LA, ENTITY_FLAG_NULL},
2847e6ad46Vishal Kulkarni	{"lbstats", "lb_stats", CUDBG_LB_STATS, ENTITY_FLAG_NULL},
2857e6ad46Vishal Kulkarni	{"tpla", "tp_la", CUDBG_TP_LA, ENTITY_FLAG_NULL},
2867e6ad46Vishal Kulkarni	{"meminfo", "meminfo", CUDBG_MEMINFO, ENTITY_FLAG_NULL},
2877e6ad46Vishal Kulkarni	{"cimpifla", "cim_pif_la", CUDBG_CIM_PIF_LA, ENTITY_FLAG_NULL},
2887e6ad46Vishal Kulkarni	{"clk", "clk", CUDBG_CLK, ENTITY_FLAG_NULL},
2897e6ad46Vishal Kulkarni	{"obq_sge_rx_q0", "obq_sge_rx_q0", CUDBG_CIM_OBQ_RXQ0,
2907e6ad46Vishal Kulkarni					ENTITY_FLAG_NULL},
2917e6ad46Vishal Kulkarni	{"obq_sge_rx_q1", "obq_sge_rx_q1", CUDBG_CIM_OBQ_RXQ1,
2927e6ad46Vishal Kulkarni					ENTITY_FLAG_NULL},
2937e6ad46Vishal Kulkarni	{"macstats", "mac_stats", CUDBG_MAC_STATS, ENTITY_FLAG_NULL},
2947e6ad46Vishal Kulkarni	{"pcieindirect", "pcie_indirect", CUDBG_PCIE_INDIRECT,
2957e6ad46Vishal Kulkarni					1 << ENTITY_FLAG_REGISTER},
2967e6ad46Vishal Kulkarni	{"pmindirect", "pm_indirect", CUDBG_PM_INDIRECT,
2977e6ad46Vishal Kulkarni				1 << ENTITY_FLAG_REGISTER},
2987e6ad46Vishal Kulkarni	{"full", "full", CUDBG_FULL, ENTITY_FLAG_NULL},
2997e6ad46Vishal Kulkarni	{"txrate", "tx_rate", CUDBG_TX_RATE, ENTITY_FLAG_NULL},
3007e6ad46Vishal Kulkarni	{"tidinfo", "tids", CUDBG_TID_INFO, ENTITY_FLAG_NULL |
3017e6ad46Vishal Kulkarni				(1 << ENTITY_FLAG_FW_NO_ATTACH)},
3027e6ad46Vishal Kulkarni	{"pcieconfig", "pcie_config", CUDBG_PCIE_CONFIG, ENTITY_FLAG_NULL},
3037e6ad46Vishal Kulkarni	{"dumpcontext", "dump_context", CUDBG_DUMP_CONTEXT, ENTITY_FLAG_NULL},
3047e6ad46Vishal Kulkarni	{"mpstcam", "mps_tcam", CUDBG_MPS_TCAM, ENTITY_FLAG_NULL},
3057e6ad46Vishal Kulkarni	{"vpddata", "vpd_data", CUDBG_VPD_DATA, ENTITY_FLAG_NULL},
3067e6ad46Vishal Kulkarni	{"letcam", "le_tcam", CUDBG_LE_TCAM, ENTITY_FLAG_NULL},
3077e6ad46Vishal Kulkarni	{"cctrl", "cctrl", CUDBG_CCTRL, ENTITY_FLAG_NULL},
3087e6ad46Vishal Kulkarni	{"maindirect", "ma_indirect", CUDBG_MA_INDIRECT,
3097e6ad46Vishal Kulkarni				1 << ENTITY_FLAG_REGISTER},
3107e6ad46Vishal Kulkarni	{"ulptxla", "ulptx_la", CUDBG_ULPTX_LA, ENTITY_FLAG_NULL},
3117e6ad46Vishal Kulkarni	{"extentity", "ext_entity", CUDBG_EXT_ENTITY, ENTITY_FLAG_NULL},
3127e6ad46Vishal Kulkarni	{"upcimindirect", "up_cim_indirect", CUDBG_UP_CIM_INDIRECT,
3137e6ad46Vishal Kulkarni					1 << ENTITY_FLAG_REGISTER},
3147e6ad46Vishal Kulkarni	{"pbttables", "pbt_tables", CUDBG_PBT_TABLE, ENTITY_FLAG_NULL},
3157e6ad46Vishal Kulkarni	{"mboxlog", "mboxlog", CUDBG_MBOX_LOG, ENTITY_FLAG_NULL},
3167e6ad46Vishal Kulkarni	{"hmaindirect", "hma_indirect", CUDBG_HMA_INDIRECT,
3177e6ad46Vishal Kulkarni				1 << ENTITY_FLAG_REGISTER},
3187e6ad46Vishal Kulkarni};
3197e6ad46Vishal Kulkarni
3207e6ad46Vishal Kulkarni#ifdef _KERNEL
32141378e7Toomas Soometypedef int (*cudbg_print_cb) (dev_info_t *dip, int, char *, ...);
3227e6ad46Vishal Kulkarni#else
3237e6ad46Vishal Kulkarnitypedef int (*cudbg_print_cb) (char *, ...);
3247e6ad46Vishal Kulkarni#endif
3257e6ad46Vishal Kulkarni
3267e6ad46Vishal Kulkarnistruct cudbg_init_hdr {
3277e6ad46Vishal Kulkarni	u8   major_ver;
3287e6ad46Vishal Kulkarni	u8   minor_ver;
3297e6ad46Vishal Kulkarni	u8   build_ver;
3307e6ad46Vishal Kulkarni	u8   res;
3317e6ad46Vishal Kulkarni	u16  init_struct_size;
3327e6ad46Vishal Kulkarni};
3337e6ad46Vishal Kulkarni
3347e6ad46Vishal Kulkarnistruct cudbg_flash_hdr {
3357e6ad46Vishal Kulkarni	u32 signature;
3367e6ad46Vishal Kulkarni	u8 major_ver;
3377e6ad46Vishal Kulkarni	u8 minor_ver;
3387e6ad46Vishal Kulkarni	u8 build_ver;
3397e6ad46Vishal Kulkarni	u8 res;
3407e6ad46Vishal Kulkarni	u64 timestamp;
3417e6ad46Vishal Kulkarni	u64 time_res;
3427e6ad46Vishal Kulkarni	u32 hdr_len;
3437e6ad46Vishal Kulkarni	u32 data_len;
3447e6ad46Vishal Kulkarni	u32 hdr_flags;
3457e6ad46Vishal Kulkarni	u32 sec_seq_no;
3467e6ad46Vishal Kulkarni	u32 reserved[22];
3477e6ad46Vishal Kulkarni};
3487e6ad46Vishal Kulkarni
3497e6ad46Vishal Kulkarnistruct cudbg_param {
3507e6ad46Vishal Kulkarni	u16			 param_type;
3517e6ad46Vishal Kulkarni	u16			 reserved;
3527e6ad46Vishal Kulkarni	union {
3537e6ad46Vishal Kulkarni		struct {
3547e6ad46Vishal Kulkarni			u32 memtype;	/* which memory (EDC0, EDC1, MC) */
3557e6ad46Vishal Kulkarni			u32 start;	/* start of log in firmware memory */
3567e6ad46Vishal Kulkarni			u32 size;	/* size of log */
3577e6ad46Vishal Kulkarni		} devlog_param;
3587e6ad46Vishal Kulkarni		struct {
3597e6ad46Vishal Kulkarni			struct mbox_cmd_log *log;
3607e6ad46Vishal Kulkarni			u16 mbox_cmds;
3617e6ad46Vishal Kulkarni		} mboxlog_param;
3627e6ad46Vishal Kulkarni		struct {
3637e6ad46Vishal Kulkarni			u8 caller_string[100];
3647e6ad46Vishal Kulkarni			u8 os_type;
3657e6ad46Vishal Kulkarni		} sw_state_param;
3667e6ad46Vishal Kulkarni		u64 time;
3677e6ad46Vishal Kulkarni		u8 tcb_bit_param;
3687e6ad46Vishal Kulkarni		void *adap;
3697e6ad46Vishal Kulkarni		void *access_lock;
3707e6ad46Vishal Kulkarni	} u;
3717e6ad46Vishal Kulkarni};
3727e6ad46Vishal Kulkarni
3737e6ad46Vishal Kulkarni/* params for tcb_bit_param */
3747e6ad46Vishal Kulkarni#define CUDBG_TCB_BRIEF_PARAM      0x1
3757e6ad46Vishal Kulkarni#define CUDBG_TCB_FROM_CARD_PARAM  0x2
3767e6ad46Vishal Kulkarni#define CUDBG_TCB_AS_SCB_PARAM     0x4
3777e6ad46Vishal Kulkarni
3787e6ad46Vishal Kulkarnienum {
3797e6ad46Vishal Kulkarni        /* params for os_type */
3807e6ad46Vishal Kulkarni        CUDBG_OS_TYPE_WINDOWS = 1,
3817e6ad46Vishal Kulkarni        CUDBG_OS_TYPE_LINUX = 2,
3827e6ad46Vishal Kulkarni        CUDBG_OS_TYPE_ESX = 3,
3837e6ad46Vishal Kulkarni        CUDBG_OS_TYPE_UNKNOWN = 4,
3847e6ad46Vishal Kulkarni};
3857e6ad46Vishal Kulkarni
3867e6ad46Vishal Kulkarni/*
3877e6ad46Vishal Kulkarni * * What is OFFLINE_VIEW_ONLY mode?
3887e6ad46Vishal Kulkarni *
3897e6ad46Vishal Kulkarni * cudbg frame work will be used only to interpret previously collected
3907e6ad46Vishal Kulkarni * data store in a file (i.e NOT hw flash)
3917e6ad46Vishal Kulkarni */
3927e6ad46Vishal Kulkarni
3937e6ad46Vishal Kulkarnistruct cudbg_init {
3947e6ad46Vishal Kulkarni	struct cudbg_init_hdr	 header;
3957e6ad46Vishal Kulkarni	struct adapter		 *adap;		 /* Pointer to adapter structure
3967e6ad46Vishal Kulkarni						    with filled fields */
3977e6ad46Vishal Kulkarni	cudbg_print_cb		 print;		 /* Platform dependent print
3987e6ad46Vishal Kulkarni						    function */
3997e6ad46Vishal Kulkarni	u32			 verbose:1;	 /* Turn on verbose print */
4007e6ad46Vishal Kulkarni	u32			 use_flash:1;	 /* Use flash to collect or view
4017e6ad46Vishal Kulkarni						    debug */
4027e6ad46Vishal Kulkarni	u32			 full_mode:1;	 /* If set, cudbg will pull in
4037e6ad46Vishal Kulkarni						    common code */
4047e6ad46Vishal Kulkarni	u32			 no_compress:1;  /* Dont compress will storing
4057e6ad46Vishal Kulkarni						    the collected debug */
4067e6ad46Vishal Kulkarni	u32			 info:1;	 /* Show just the info, Dont
4077e6ad46Vishal Kulkarni						    interpret */
4087e6ad46Vishal Kulkarni	u32			 reserved:27;
4097e6ad46Vishal Kulkarni	u8			 dbg_bitmap[CUDBG_MAX_BITMAP_LEN];
4107e6ad46Vishal Kulkarni						/* Bit map to select the dbg
4117e6ad46Vishal Kulkarni						    data type to be collected
4127e6ad46Vishal Kulkarni						    or viewed */
4137e6ad46Vishal Kulkarni};
4147e6ad46Vishal Kulkarni
4157e6ad46Vishal Kulkarnistruct cudbg_private {
4167e6ad46Vishal Kulkarni	struct cudbg_init  dbg_init;
4177e6ad46Vishal Kulkarni#ifdef _KERNEL
4187e6ad46Vishal Kulkarni	struct cudbg_flash_sec_info  sec_info;
4197e6ad46Vishal Kulkarni#endif
4207e6ad46Vishal Kulkarni};
4217e6ad46Vishal Kulkarni
4227e6ad46Vishal Kulkarni/********************************* Helper functions *************************/
4237e6ad46Vishal Kulkarnivoid set_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type);
4247e6ad46Vishal Kulkarnivoid reset_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type);
4257e6ad46Vishal Kulkarnistruct cudbg_init * cudbg_get_init(void *handle);
4267e6ad46Vishal Kulkarni
4277e6ad46Vishal Kulkarni/**
4287e6ad46Vishal Kulkarni *  cudbg_collect - Collect and store debug information.
4297e6ad46Vishal Kulkarni *  ## Parameters ##
4307e6ad46Vishal Kulkarni *  @handle : A pointer returned by cudbg_alloc_handle.
4317e6ad46Vishal Kulkarni *  @outbuf : pointer to output buffer, to store the collected information
4327e6ad46Vishal Kulkarni *	      or to use it as a scratch buffer in case HW flash is used to
4337e6ad46Vishal Kulkarni *	      store the debug information.
4347e6ad46Vishal Kulkarni *  @outbuf_size : Size of output buffer.
4357e6ad46Vishal Kulkarni *  ##	Return ##
4367e6ad46Vishal Kulkarni *  If the function succeeds, the return value will be size of debug information
4377e6ad46Vishal Kulkarni *  collected and stored.
4387e6ad46Vishal Kulkarni *  -ve value represent error.
4397e6ad46Vishal Kulkarni */
4407e6ad46Vishal Kulkarniint cudbg_collect(void *handle, void *outbuf, u32 *outbuf_size);
4417e6ad46Vishal Kulkarni
4427e6ad46Vishal Kulkarniint cudbg_view(void *handle, void *pinbuf, u32 inbuf_size,
4437e6ad46Vishal Kulkarni               void *poutbuf, s64 *poutbuf_size);
4447e6ad46Vishal Kulkarnivoid init_cudbg_hdr(struct cudbg_init_hdr *hdr);
4457e6ad46Vishal Kulkarnivoid * cudbg_alloc_handle(void);
4467e6ad46Vishal Kulkarnivoid cudbg_free_handle(void *handle);
4477e6ad46Vishal Kulkarni#endif /* _CUDBG_IF_H_ */
448