18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Chelsio Communications. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "t4_regs.h" 78c2ecf20Sopenharmony_ci#include "cxgb4.h" 88c2ecf20Sopenharmony_ci#include "cxgb4_cudbg.h" 98c2ecf20Sopenharmony_ci#include "cudbg_zlib.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistatic const struct cxgb4_collect_entity cxgb4_collect_mem_dump[] = { 128c2ecf20Sopenharmony_ci { CUDBG_EDC0, cudbg_collect_edc0_meminfo }, 138c2ecf20Sopenharmony_ci { CUDBG_EDC1, cudbg_collect_edc1_meminfo }, 148c2ecf20Sopenharmony_ci { CUDBG_MC0, cudbg_collect_mc0_meminfo }, 158c2ecf20Sopenharmony_ci { CUDBG_MC1, cudbg_collect_mc1_meminfo }, 168c2ecf20Sopenharmony_ci { CUDBG_HMA, cudbg_collect_hma_meminfo }, 178c2ecf20Sopenharmony_ci}; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic const struct cxgb4_collect_entity cxgb4_collect_hw_dump[] = { 208c2ecf20Sopenharmony_ci { CUDBG_MBOX_LOG, cudbg_collect_mbox_log }, 218c2ecf20Sopenharmony_ci { CUDBG_QDESC, cudbg_collect_qdesc }, 228c2ecf20Sopenharmony_ci { CUDBG_DEV_LOG, cudbg_collect_fw_devlog }, 238c2ecf20Sopenharmony_ci { CUDBG_REG_DUMP, cudbg_collect_reg_dump }, 248c2ecf20Sopenharmony_ci { CUDBG_CIM_LA, cudbg_collect_cim_la }, 258c2ecf20Sopenharmony_ci { CUDBG_CIM_MA_LA, cudbg_collect_cim_ma_la }, 268c2ecf20Sopenharmony_ci { CUDBG_CIM_QCFG, cudbg_collect_cim_qcfg }, 278c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_TP0, cudbg_collect_cim_ibq_tp0 }, 288c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_TP1, cudbg_collect_cim_ibq_tp1 }, 298c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_ULP, cudbg_collect_cim_ibq_ulp }, 308c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_SGE0, cudbg_collect_cim_ibq_sge0 }, 318c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_SGE1, cudbg_collect_cim_ibq_sge1 }, 328c2ecf20Sopenharmony_ci { CUDBG_CIM_IBQ_NCSI, cudbg_collect_cim_ibq_ncsi }, 338c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_ULP0, cudbg_collect_cim_obq_ulp0 }, 348c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_ULP1, cudbg_collect_cim_obq_ulp1 }, 358c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_ULP2, cudbg_collect_cim_obq_ulp2 }, 368c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_ULP3, cudbg_collect_cim_obq_ulp3 }, 378c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_SGE, cudbg_collect_cim_obq_sge }, 388c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_NCSI, cudbg_collect_cim_obq_ncsi }, 398c2ecf20Sopenharmony_ci { CUDBG_RSS, cudbg_collect_rss }, 408c2ecf20Sopenharmony_ci { CUDBG_RSS_VF_CONF, cudbg_collect_rss_vf_config }, 418c2ecf20Sopenharmony_ci { CUDBG_PATH_MTU, cudbg_collect_path_mtu }, 428c2ecf20Sopenharmony_ci { CUDBG_PM_STATS, cudbg_collect_pm_stats }, 438c2ecf20Sopenharmony_ci { CUDBG_HW_SCHED, cudbg_collect_hw_sched }, 448c2ecf20Sopenharmony_ci { CUDBG_TP_INDIRECT, cudbg_collect_tp_indirect }, 458c2ecf20Sopenharmony_ci { CUDBG_SGE_INDIRECT, cudbg_collect_sge_indirect }, 468c2ecf20Sopenharmony_ci { CUDBG_ULPRX_LA, cudbg_collect_ulprx_la }, 478c2ecf20Sopenharmony_ci { CUDBG_TP_LA, cudbg_collect_tp_la }, 488c2ecf20Sopenharmony_ci { CUDBG_MEMINFO, cudbg_collect_meminfo }, 498c2ecf20Sopenharmony_ci { CUDBG_CIM_PIF_LA, cudbg_collect_cim_pif_la }, 508c2ecf20Sopenharmony_ci { CUDBG_CLK, cudbg_collect_clk_info }, 518c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_RXQ0, cudbg_collect_obq_sge_rx_q0 }, 528c2ecf20Sopenharmony_ci { CUDBG_CIM_OBQ_RXQ1, cudbg_collect_obq_sge_rx_q1 }, 538c2ecf20Sopenharmony_ci { CUDBG_PCIE_INDIRECT, cudbg_collect_pcie_indirect }, 548c2ecf20Sopenharmony_ci { CUDBG_PM_INDIRECT, cudbg_collect_pm_indirect }, 558c2ecf20Sopenharmony_ci { CUDBG_TID_INFO, cudbg_collect_tid }, 568c2ecf20Sopenharmony_ci { CUDBG_PCIE_CONFIG, cudbg_collect_pcie_config }, 578c2ecf20Sopenharmony_ci { CUDBG_DUMP_CONTEXT, cudbg_collect_dump_context }, 588c2ecf20Sopenharmony_ci { CUDBG_MPS_TCAM, cudbg_collect_mps_tcam }, 598c2ecf20Sopenharmony_ci { CUDBG_VPD_DATA, cudbg_collect_vpd_data }, 608c2ecf20Sopenharmony_ci { CUDBG_LE_TCAM, cudbg_collect_le_tcam }, 618c2ecf20Sopenharmony_ci { CUDBG_CCTRL, cudbg_collect_cctrl }, 628c2ecf20Sopenharmony_ci { CUDBG_MA_INDIRECT, cudbg_collect_ma_indirect }, 638c2ecf20Sopenharmony_ci { CUDBG_ULPTX_LA, cudbg_collect_ulptx_la }, 648c2ecf20Sopenharmony_ci { CUDBG_UP_CIM_INDIRECT, cudbg_collect_up_cim_indirect }, 658c2ecf20Sopenharmony_ci { CUDBG_PBT_TABLE, cudbg_collect_pbt_tables }, 668c2ecf20Sopenharmony_ci { CUDBG_HMA_INDIRECT, cudbg_collect_hma_indirect }, 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic const struct cxgb4_collect_entity cxgb4_collect_flash_dump[] = { 708c2ecf20Sopenharmony_ci { CUDBG_FLASH, cudbg_collect_flash }, 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciu32 cxgb4_get_dump_length(struct adapter *adap, u32 flag) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci u32 i, entity; 768c2ecf20Sopenharmony_ci u32 len = 0; 778c2ecf20Sopenharmony_ci u32 wsize; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_HW) { 808c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(cxgb4_collect_hw_dump); i++) { 818c2ecf20Sopenharmony_ci entity = cxgb4_collect_hw_dump[i].entity; 828c2ecf20Sopenharmony_ci len += cudbg_get_entity_length(adap, entity); 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci } 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_MEM) { 878c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(cxgb4_collect_mem_dump); i++) { 888c2ecf20Sopenharmony_ci entity = cxgb4_collect_mem_dump[i].entity; 898c2ecf20Sopenharmony_ci len += cudbg_get_entity_length(adap, entity); 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci } 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_FLASH) 948c2ecf20Sopenharmony_ci len += adap->params.sf_size; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci /* If compression is enabled, a smaller destination buffer is enough */ 978c2ecf20Sopenharmony_ci wsize = cudbg_get_workspace_size(); 988c2ecf20Sopenharmony_ci if (wsize && len > CUDBG_DUMP_BUFF_SIZE) 998c2ecf20Sopenharmony_ci len = CUDBG_DUMP_BUFF_SIZE; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci return len; 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic void cxgb4_cudbg_collect_entity(struct cudbg_init *pdbg_init, 1058c2ecf20Sopenharmony_ci struct cudbg_buffer *dbg_buff, 1068c2ecf20Sopenharmony_ci const struct cxgb4_collect_entity *e_arr, 1078c2ecf20Sopenharmony_ci u32 arr_size, void *buf, u32 *tot_size) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci struct cudbg_error cudbg_err = { 0 }; 1108c2ecf20Sopenharmony_ci struct cudbg_entity_hdr *entity_hdr; 1118c2ecf20Sopenharmony_ci u32 i, total_size = 0; 1128c2ecf20Sopenharmony_ci int ret; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci for (i = 0; i < arr_size; i++) { 1158c2ecf20Sopenharmony_ci const struct cxgb4_collect_entity *e = &e_arr[i]; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci entity_hdr = cudbg_get_entity_hdr(buf, e->entity); 1188c2ecf20Sopenharmony_ci entity_hdr->entity_type = e->entity; 1198c2ecf20Sopenharmony_ci entity_hdr->start_offset = dbg_buff->offset; 1208c2ecf20Sopenharmony_ci memset(&cudbg_err, 0, sizeof(struct cudbg_error)); 1218c2ecf20Sopenharmony_ci ret = e->collect_cb(pdbg_init, dbg_buff, &cudbg_err); 1228c2ecf20Sopenharmony_ci if (ret) { 1238c2ecf20Sopenharmony_ci entity_hdr->size = 0; 1248c2ecf20Sopenharmony_ci dbg_buff->offset = entity_hdr->start_offset; 1258c2ecf20Sopenharmony_ci } else { 1268c2ecf20Sopenharmony_ci cudbg_align_debug_buffer(dbg_buff, entity_hdr); 1278c2ecf20Sopenharmony_ci } 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci /* Log error and continue with next entity */ 1308c2ecf20Sopenharmony_ci if (cudbg_err.sys_err) 1318c2ecf20Sopenharmony_ci ret = CUDBG_SYSTEM_ERROR; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci entity_hdr->hdr_flags = ret; 1348c2ecf20Sopenharmony_ci entity_hdr->sys_err = cudbg_err.sys_err; 1358c2ecf20Sopenharmony_ci entity_hdr->sys_warn = cudbg_err.sys_warn; 1368c2ecf20Sopenharmony_ci total_size += entity_hdr->size; 1378c2ecf20Sopenharmony_ci } 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci *tot_size += total_size; 1408c2ecf20Sopenharmony_ci} 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistatic int cudbg_alloc_compress_buff(struct cudbg_init *pdbg_init) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci u32 workspace_size; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci workspace_size = cudbg_get_workspace_size(); 1478c2ecf20Sopenharmony_ci pdbg_init->compress_buff = vzalloc(CUDBG_COMPRESS_BUFF_SIZE + 1488c2ecf20Sopenharmony_ci workspace_size); 1498c2ecf20Sopenharmony_ci if (!pdbg_init->compress_buff) 1508c2ecf20Sopenharmony_ci return -ENOMEM; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci pdbg_init->compress_buff_size = CUDBG_COMPRESS_BUFF_SIZE; 1538c2ecf20Sopenharmony_ci pdbg_init->workspace = (u8 *)pdbg_init->compress_buff + 1548c2ecf20Sopenharmony_ci CUDBG_COMPRESS_BUFF_SIZE - workspace_size; 1558c2ecf20Sopenharmony_ci return 0; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic void cudbg_free_compress_buff(struct cudbg_init *pdbg_init) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci if (pdbg_init->compress_buff) 1618c2ecf20Sopenharmony_ci vfree(pdbg_init->compress_buff); 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ciint cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size, 1658c2ecf20Sopenharmony_ci u32 flag) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci struct cudbg_buffer dbg_buff = { 0 }; 1688c2ecf20Sopenharmony_ci u32 size, min_size, total_size = 0; 1698c2ecf20Sopenharmony_ci struct cudbg_init cudbg_init; 1708c2ecf20Sopenharmony_ci struct cudbg_hdr *cudbg_hdr; 1718c2ecf20Sopenharmony_ci int rc; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci size = *buf_size; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci memset(&cudbg_init, 0, sizeof(struct cudbg_init)); 1768c2ecf20Sopenharmony_ci cudbg_init.adap = adap; 1778c2ecf20Sopenharmony_ci cudbg_init.outbuf = buf; 1788c2ecf20Sopenharmony_ci cudbg_init.outbuf_size = size; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci dbg_buff.data = buf; 1818c2ecf20Sopenharmony_ci dbg_buff.size = size; 1828c2ecf20Sopenharmony_ci dbg_buff.offset = 0; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci cudbg_hdr = (struct cudbg_hdr *)buf; 1858c2ecf20Sopenharmony_ci cudbg_hdr->signature = CUDBG_SIGNATURE; 1868c2ecf20Sopenharmony_ci cudbg_hdr->hdr_len = sizeof(struct cudbg_hdr); 1878c2ecf20Sopenharmony_ci cudbg_hdr->major_ver = CUDBG_MAJOR_VERSION; 1888c2ecf20Sopenharmony_ci cudbg_hdr->minor_ver = CUDBG_MINOR_VERSION; 1898c2ecf20Sopenharmony_ci cudbg_hdr->max_entities = CUDBG_MAX_ENTITY; 1908c2ecf20Sopenharmony_ci cudbg_hdr->chip_ver = adap->params.chip; 1918c2ecf20Sopenharmony_ci cudbg_hdr->dump_type = CUDBG_DUMP_TYPE_MINI; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci min_size = sizeof(struct cudbg_hdr) + 1948c2ecf20Sopenharmony_ci sizeof(struct cudbg_entity_hdr) * 1958c2ecf20Sopenharmony_ci cudbg_hdr->max_entities; 1968c2ecf20Sopenharmony_ci if (size < min_size) 1978c2ecf20Sopenharmony_ci return -ENOMEM; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci rc = cudbg_get_workspace_size(); 2008c2ecf20Sopenharmony_ci if (rc) { 2018c2ecf20Sopenharmony_ci /* Zlib available. So, use zlib deflate */ 2028c2ecf20Sopenharmony_ci cudbg_init.compress_type = CUDBG_COMPRESSION_ZLIB; 2038c2ecf20Sopenharmony_ci rc = cudbg_alloc_compress_buff(&cudbg_init); 2048c2ecf20Sopenharmony_ci if (rc) { 2058c2ecf20Sopenharmony_ci /* Ignore error and continue without compression. */ 2068c2ecf20Sopenharmony_ci dev_warn(adap->pdev_dev, 2078c2ecf20Sopenharmony_ci "Fail allocating compression buffer ret: %d. Continuing without compression.\n", 2088c2ecf20Sopenharmony_ci rc); 2098c2ecf20Sopenharmony_ci cudbg_init.compress_type = CUDBG_COMPRESSION_NONE; 2108c2ecf20Sopenharmony_ci rc = 0; 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci } else { 2138c2ecf20Sopenharmony_ci cudbg_init.compress_type = CUDBG_COMPRESSION_NONE; 2148c2ecf20Sopenharmony_ci } 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci cudbg_hdr->compress_type = cudbg_init.compress_type; 2178c2ecf20Sopenharmony_ci dbg_buff.offset += min_size; 2188c2ecf20Sopenharmony_ci total_size = dbg_buff.offset; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_HW) 2218c2ecf20Sopenharmony_ci cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff, 2228c2ecf20Sopenharmony_ci cxgb4_collect_hw_dump, 2238c2ecf20Sopenharmony_ci ARRAY_SIZE(cxgb4_collect_hw_dump), 2248c2ecf20Sopenharmony_ci buf, 2258c2ecf20Sopenharmony_ci &total_size); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_MEM) 2288c2ecf20Sopenharmony_ci cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff, 2298c2ecf20Sopenharmony_ci cxgb4_collect_mem_dump, 2308c2ecf20Sopenharmony_ci ARRAY_SIZE(cxgb4_collect_mem_dump), 2318c2ecf20Sopenharmony_ci buf, 2328c2ecf20Sopenharmony_ci &total_size); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci if (flag & CXGB4_ETH_DUMP_FLASH) 2358c2ecf20Sopenharmony_ci cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff, 2368c2ecf20Sopenharmony_ci cxgb4_collect_flash_dump, 2378c2ecf20Sopenharmony_ci ARRAY_SIZE(cxgb4_collect_flash_dump), 2388c2ecf20Sopenharmony_ci buf, 2398c2ecf20Sopenharmony_ci &total_size); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci cudbg_free_compress_buff(&cudbg_init); 2428c2ecf20Sopenharmony_ci cudbg_hdr->data_len = total_size; 2438c2ecf20Sopenharmony_ci if (cudbg_init.compress_type != CUDBG_COMPRESSION_NONE) 2448c2ecf20Sopenharmony_ci *buf_size = size; 2458c2ecf20Sopenharmony_ci else 2468c2ecf20Sopenharmony_ci *buf_size = total_size; 2478c2ecf20Sopenharmony_ci return 0; 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_civoid cxgb4_init_ethtool_dump(struct adapter *adapter) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci adapter->eth_dump.flag = CXGB4_ETH_DUMP_NONE; 2538c2ecf20Sopenharmony_ci adapter->eth_dump.version = adapter->params.fw_vers; 2548c2ecf20Sopenharmony_ci adapter->eth_dump.len = 0; 2558c2ecf20Sopenharmony_ci} 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic int cxgb4_cudbg_vmcoredd_collect(struct vmcoredd_data *data, void *buf) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci struct adapter *adap = container_of(data, struct adapter, vmcoredd); 2608c2ecf20Sopenharmony_ci u32 len = data->size; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci return cxgb4_cudbg_collect(adap, buf, &len, CXGB4_ETH_DUMP_ALL); 2638c2ecf20Sopenharmony_ci} 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ciint cxgb4_cudbg_vmcore_add_dump(struct adapter *adap) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct vmcoredd_data *data = &adap->vmcoredd; 2688c2ecf20Sopenharmony_ci u32 len; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci len = sizeof(struct cudbg_hdr) + 2718c2ecf20Sopenharmony_ci sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY; 2728c2ecf20Sopenharmony_ci len += CUDBG_DUMP_BUFF_SIZE; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci data->size = len; 2758c2ecf20Sopenharmony_ci snprintf(data->dump_name, sizeof(data->dump_name), "%s_%s", 2768c2ecf20Sopenharmony_ci cxgb4_driver_name, adap->name); 2778c2ecf20Sopenharmony_ci data->vmcoredd_callback = cxgb4_cudbg_vmcoredd_collect; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci return vmcore_add_device_dump(data); 2808c2ecf20Sopenharmony_ci} 281