2 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
20 #include "cxgb4_cudbg.h"
21 #include "cudbg_entity.h"
23 static const struct cxgb4_collect_entity cxgb4_collect_mem_dump[] = {
24 { CUDBG_EDC0, cudbg_collect_edc0_meminfo },
25 { CUDBG_EDC1, cudbg_collect_edc1_meminfo },
28 static const struct cxgb4_collect_entity cxgb4_collect_hw_dump[] = {
29 { CUDBG_MBOX_LOG, cudbg_collect_mbox_log },
30 { CUDBG_DEV_LOG, cudbg_collect_fw_devlog },
31 { CUDBG_REG_DUMP, cudbg_collect_reg_dump },
32 { CUDBG_TP_INDIRECT, cudbg_collect_tp_indirect },
35 static u32 cxgb4_get_entity_length(struct adapter *adap, u32 entity)
37 u32 value, n = 0, len = 0;
41 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
54 len = adap->params.devlog.size;
57 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
58 if (value & EDRAM0_ENABLE_F) {
59 value = t4_read_reg(adap, MA_EDRAM0_BAR_A);
60 len = EDRAM0_SIZE_G(value);
62 len = cudbg_mbytes_to_bytes(len);
65 value = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
66 if (value & EDRAM1_ENABLE_F) {
67 value = t4_read_reg(adap, MA_EDRAM1_BAR_A);
68 len = EDRAM1_SIZE_G(value);
70 len = cudbg_mbytes_to_bytes(len);
72 case CUDBG_TP_INDIRECT:
73 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
75 n = sizeof(t5_tp_pio_array) +
76 sizeof(t5_tp_tm_pio_array) +
77 sizeof(t5_tp_mib_index_array);
80 n = sizeof(t6_tp_pio_array) +
81 sizeof(t6_tp_tm_pio_array) +
82 sizeof(t6_tp_mib_index_array);
87 n = n / (IREG_NUM_ELEM * sizeof(u32));
88 len = sizeof(struct ireg_buf) * n;
91 len = sizeof(struct cudbg_mbox_log) * adap->mbox_log->size;
100 u32 cxgb4_get_dump_length(struct adapter *adap, u32 flag)
105 if (flag & CXGB4_ETH_DUMP_HW) {
106 for (i = 0; i < ARRAY_SIZE(cxgb4_collect_hw_dump); i++) {
107 entity = cxgb4_collect_hw_dump[i].entity;
108 len += cxgb4_get_entity_length(adap, entity);
112 if (flag & CXGB4_ETH_DUMP_MEM) {
113 for (i = 0; i < ARRAY_SIZE(cxgb4_collect_mem_dump); i++) {
114 entity = cxgb4_collect_mem_dump[i].entity;
115 len += cxgb4_get_entity_length(adap, entity);
122 static void cxgb4_cudbg_collect_entity(struct cudbg_init *pdbg_init,
123 struct cudbg_buffer *dbg_buff,
124 const struct cxgb4_collect_entity *e_arr,
125 u32 arr_size, void *buf, u32 *tot_size)
127 struct adapter *adap = pdbg_init->adap;
128 struct cudbg_error cudbg_err = { 0 };
129 struct cudbg_entity_hdr *entity_hdr;
134 for (i = 0; i < arr_size; i++) {
135 const struct cxgb4_collect_entity *e = &e_arr[i];
137 /* Skip entities that won't fit in output buffer */
138 entity_size = cxgb4_get_entity_length(adap, e->entity);
140 pdbg_init->outbuf_size - *tot_size - total_size)
143 entity_hdr = cudbg_get_entity_hdr(buf, e->entity);
144 entity_hdr->entity_type = e->entity;
145 entity_hdr->start_offset = dbg_buff->offset;
146 memset(&cudbg_err, 0, sizeof(struct cudbg_error));
147 ret = e->collect_cb(pdbg_init, dbg_buff, &cudbg_err);
149 entity_hdr->size = 0;
150 dbg_buff->offset = entity_hdr->start_offset;
152 cudbg_align_debug_buffer(dbg_buff, entity_hdr);
155 /* Log error and continue with next entity */
156 if (cudbg_err.sys_err)
157 ret = CUDBG_SYSTEM_ERROR;
159 entity_hdr->hdr_flags = ret;
160 entity_hdr->sys_err = cudbg_err.sys_err;
161 entity_hdr->sys_warn = cudbg_err.sys_warn;
162 total_size += entity_hdr->size;
165 *tot_size += total_size;
168 int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size,
171 struct cudbg_init cudbg_init = { 0 };
172 struct cudbg_buffer dbg_buff = { 0 };
173 u32 size, min_size, total_size = 0;
174 struct cudbg_hdr *cudbg_hdr;
178 cudbg_init.adap = adap;
179 cudbg_init.outbuf = buf;
180 cudbg_init.outbuf_size = size;
183 dbg_buff.size = size;
186 cudbg_hdr = (struct cudbg_hdr *)buf;
187 cudbg_hdr->signature = CUDBG_SIGNATURE;
188 cudbg_hdr->hdr_len = sizeof(struct cudbg_hdr);
189 cudbg_hdr->major_ver = CUDBG_MAJOR_VERSION;
190 cudbg_hdr->minor_ver = CUDBG_MINOR_VERSION;
191 cudbg_hdr->max_entities = CUDBG_MAX_ENTITY;
192 cudbg_hdr->chip_ver = adap->params.chip;
193 cudbg_hdr->dump_type = CUDBG_DUMP_TYPE_MINI;
194 cudbg_hdr->compress_type = CUDBG_COMPRESSION_NONE;
196 min_size = sizeof(struct cudbg_hdr) +
197 sizeof(struct cudbg_entity_hdr) *
198 cudbg_hdr->max_entities;
202 dbg_buff.offset += min_size;
203 total_size = dbg_buff.offset;
205 if (flag & CXGB4_ETH_DUMP_HW)
206 cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff,
207 cxgb4_collect_hw_dump,
208 ARRAY_SIZE(cxgb4_collect_hw_dump),
212 if (flag & CXGB4_ETH_DUMP_MEM)
213 cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff,
214 cxgb4_collect_mem_dump,
215 ARRAY_SIZE(cxgb4_collect_mem_dump),
219 cudbg_hdr->data_len = total_size;
220 *buf_size = total_size;
224 void cxgb4_init_ethtool_dump(struct adapter *adapter)
226 adapter->eth_dump.flag = CXGB4_ETH_DUMP_NONE;
227 adapter->eth_dump.version = adapter->params.fw_vers;
228 adapter->eth_dump.len = 0;