Commit | Line | Data |
---|---|---|
fd88b31a HS |
1 | /* |
2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. | |
3 | * | |
4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. | |
5 | * | |
6 | * This software is available to you under a choice of one of two | |
7 | * licenses. You may choose to be licensed under the terms of the GNU | |
8 | * General Public License (GPL) Version 2, available from the file | |
9 | * COPYING in the main directory of this source tree, or the | |
10 | * OpenIB.org BSD license below: | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or | |
13 | * without modification, are permitted provided that the following | |
14 | * conditions are met: | |
15 | * | |
16 | * - Redistributions of source code must retain the above | |
17 | * copyright notice, this list of conditions and the following | |
18 | * disclaimer. | |
19 | * | |
20 | * - Redistributions in binary form must reproduce the above | |
21 | * copyright notice, this list of conditions and the following | |
22 | * disclaimer in the documentation and/or other materials | |
23 | * provided with the distribution. | |
24 | * | |
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
32 | * SOFTWARE. | |
33 | */ | |
34 | ||
35 | #include <linux/seq_file.h> | |
36 | #include <linux/debugfs.h> | |
37 | #include <linux/string_helpers.h> | |
38 | #include <linux/sort.h> | |
39 | ||
40 | #include "cxgb4.h" | |
41 | #include "t4_regs.h" | |
42 | #include "t4fw_api.h" | |
43 | #include "cxgb4_debugfs.h" | |
44 | #include "l2t.h" | |
45 | ||
f1ff24aa HS |
46 | /* generic seq_file support for showing a table of size rows x width. */ |
47 | static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos) | |
48 | { | |
49 | pos -= tb->skip_first; | |
50 | return pos >= tb->rows ? NULL : &tb->data[pos * tb->width]; | |
51 | } | |
52 | ||
53 | static void *seq_tab_start(struct seq_file *seq, loff_t *pos) | |
54 | { | |
55 | struct seq_tab *tb = seq->private; | |
56 | ||
57 | if (tb->skip_first && *pos == 0) | |
58 | return SEQ_START_TOKEN; | |
59 | ||
60 | return seq_tab_get_idx(tb, *pos); | |
61 | } | |
62 | ||
63 | static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos) | |
64 | { | |
65 | v = seq_tab_get_idx(seq->private, *pos + 1); | |
66 | if (v) | |
67 | ++*pos; | |
68 | return v; | |
69 | } | |
70 | ||
71 | static void seq_tab_stop(struct seq_file *seq, void *v) | |
72 | { | |
73 | } | |
74 | ||
75 | static int seq_tab_show(struct seq_file *seq, void *v) | |
76 | { | |
77 | const struct seq_tab *tb = seq->private; | |
78 | ||
79 | return tb->show(seq, v, ((char *)v - tb->data) / tb->width); | |
80 | } | |
81 | ||
82 | static const struct seq_operations seq_tab_ops = { | |
83 | .start = seq_tab_start, | |
84 | .next = seq_tab_next, | |
85 | .stop = seq_tab_stop, | |
86 | .show = seq_tab_show | |
87 | }; | |
88 | ||
89 | struct seq_tab *seq_open_tab(struct file *f, unsigned int rows, | |
90 | unsigned int width, unsigned int have_header, | |
91 | int (*show)(struct seq_file *seq, void *v, int i)) | |
92 | { | |
93 | struct seq_tab *p; | |
94 | ||
95 | p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width); | |
96 | if (p) { | |
97 | p->show = show; | |
98 | p->rows = rows; | |
99 | p->width = width; | |
100 | p->skip_first = have_header != 0; | |
101 | } | |
102 | return p; | |
103 | } | |
104 | ||
105 | static int cim_la_show(struct seq_file *seq, void *v, int idx) | |
106 | { | |
107 | if (v == SEQ_START_TOKEN) | |
108 | seq_puts(seq, "Status Data PC LS0Stat LS0Addr " | |
109 | " LS0Data\n"); | |
110 | else { | |
111 | const u32 *p = v; | |
112 | ||
113 | seq_printf(seq, | |
114 | " %02x %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n", | |
115 | (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4, | |
116 | p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5], | |
117 | p[6], p[7]); | |
118 | } | |
119 | return 0; | |
120 | } | |
121 | ||
122 | static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx) | |
123 | { | |
124 | if (v == SEQ_START_TOKEN) { | |
125 | seq_puts(seq, "Status Data PC\n"); | |
126 | } else { | |
127 | const u32 *p = v; | |
128 | ||
129 | seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6], | |
130 | p[7]); | |
131 | seq_printf(seq, " %02x %02x%06x %02x%06x\n", | |
132 | (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8, | |
133 | p[4] & 0xff, p[5] >> 8); | |
134 | seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff, | |
135 | p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4); | |
136 | } | |
137 | return 0; | |
138 | } | |
139 | ||
140 | static int cim_la_open(struct inode *inode, struct file *file) | |
141 | { | |
142 | int ret; | |
143 | unsigned int cfg; | |
144 | struct seq_tab *p; | |
145 | struct adapter *adap = inode->i_private; | |
146 | ||
147 | ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg); | |
148 | if (ret) | |
149 | return ret; | |
150 | ||
151 | p = seq_open_tab(file, adap->params.cim_la_size / 8, 8 * sizeof(u32), 1, | |
152 | cfg & UPDBGLACAPTPCONLY_F ? | |
153 | cim_la_show_3in1 : cim_la_show); | |
154 | if (!p) | |
155 | return -ENOMEM; | |
156 | ||
157 | ret = t4_cim_read_la(adap, (u32 *)p->data, NULL); | |
158 | if (ret) | |
159 | seq_release_private(inode, file); | |
160 | return ret; | |
161 | } | |
162 | ||
163 | static const struct file_operations cim_la_fops = { | |
164 | .owner = THIS_MODULE, | |
165 | .open = cim_la_open, | |
166 | .read = seq_read, | |
167 | .llseek = seq_lseek, | |
168 | .release = seq_release_private | |
169 | }; | |
170 | ||
171 | /* Firmware Device Log dump. */ | |
49aa284f HS |
172 | static const char * const devlog_level_strings[] = { |
173 | [FW_DEVLOG_LEVEL_EMERG] = "EMERG", | |
174 | [FW_DEVLOG_LEVEL_CRIT] = "CRIT", | |
175 | [FW_DEVLOG_LEVEL_ERR] = "ERR", | |
176 | [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE", | |
177 | [FW_DEVLOG_LEVEL_INFO] = "INFO", | |
178 | [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG" | |
179 | }; | |
180 | ||
181 | static const char * const devlog_facility_strings[] = { | |
182 | [FW_DEVLOG_FACILITY_CORE] = "CORE", | |
183 | [FW_DEVLOG_FACILITY_SCHED] = "SCHED", | |
184 | [FW_DEVLOG_FACILITY_TIMER] = "TIMER", | |
185 | [FW_DEVLOG_FACILITY_RES] = "RES", | |
186 | [FW_DEVLOG_FACILITY_HW] = "HW", | |
187 | [FW_DEVLOG_FACILITY_FLR] = "FLR", | |
188 | [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ", | |
189 | [FW_DEVLOG_FACILITY_PHY] = "PHY", | |
190 | [FW_DEVLOG_FACILITY_MAC] = "MAC", | |
191 | [FW_DEVLOG_FACILITY_PORT] = "PORT", | |
192 | [FW_DEVLOG_FACILITY_VI] = "VI", | |
193 | [FW_DEVLOG_FACILITY_FILTER] = "FILTER", | |
194 | [FW_DEVLOG_FACILITY_ACL] = "ACL", | |
195 | [FW_DEVLOG_FACILITY_TM] = "TM", | |
196 | [FW_DEVLOG_FACILITY_QFC] = "QFC", | |
197 | [FW_DEVLOG_FACILITY_DCB] = "DCB", | |
198 | [FW_DEVLOG_FACILITY_ETH] = "ETH", | |
199 | [FW_DEVLOG_FACILITY_OFLD] = "OFLD", | |
200 | [FW_DEVLOG_FACILITY_RI] = "RI", | |
201 | [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI", | |
202 | [FW_DEVLOG_FACILITY_FCOE] = "FCOE", | |
203 | [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI", | |
204 | [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE" | |
205 | }; | |
206 | ||
207 | /* Information gathered by Device Log Open routine for the display routine. | |
208 | */ | |
209 | struct devlog_info { | |
210 | unsigned int nentries; /* number of entries in log[] */ | |
211 | unsigned int first; /* first [temporal] entry in log[] */ | |
212 | struct fw_devlog_e log[0]; /* Firmware Device Log */ | |
213 | }; | |
214 | ||
215 | /* Dump a Firmaware Device Log entry. | |
216 | */ | |
217 | static int devlog_show(struct seq_file *seq, void *v) | |
218 | { | |
219 | if (v == SEQ_START_TOKEN) | |
220 | seq_printf(seq, "%10s %15s %8s %8s %s\n", | |
221 | "Seq#", "Tstamp", "Level", "Facility", "Message"); | |
222 | else { | |
223 | struct devlog_info *dinfo = seq->private; | |
224 | int fidx = (uintptr_t)v - 2; | |
225 | unsigned long index; | |
226 | struct fw_devlog_e *e; | |
227 | ||
228 | /* Get a pointer to the log entry to display. Skip unused log | |
229 | * entries. | |
230 | */ | |
231 | index = dinfo->first + fidx; | |
232 | if (index >= dinfo->nentries) | |
233 | index -= dinfo->nentries; | |
234 | e = &dinfo->log[index]; | |
235 | if (e->timestamp == 0) | |
236 | return 0; | |
237 | ||
238 | /* Print the message. This depends on the firmware using | |
239 | * exactly the same formating strings as the kernel so we may | |
240 | * eventually have to put a format interpreter in here ... | |
241 | */ | |
242 | seq_printf(seq, "%10d %15llu %8s %8s ", | |
243 | e->seqno, e->timestamp, | |
244 | (e->level < ARRAY_SIZE(devlog_level_strings) | |
245 | ? devlog_level_strings[e->level] | |
246 | : "UNKNOWN"), | |
247 | (e->facility < ARRAY_SIZE(devlog_facility_strings) | |
248 | ? devlog_facility_strings[e->facility] | |
249 | : "UNKNOWN")); | |
250 | seq_printf(seq, e->fmt, e->params[0], e->params[1], | |
251 | e->params[2], e->params[3], e->params[4], | |
252 | e->params[5], e->params[6], e->params[7]); | |
253 | } | |
254 | return 0; | |
255 | } | |
256 | ||
257 | /* Sequential File Operations for Device Log. | |
258 | */ | |
259 | static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos) | |
260 | { | |
261 | if (pos > dinfo->nentries) | |
262 | return NULL; | |
263 | ||
264 | return (void *)(uintptr_t)(pos + 1); | |
265 | } | |
266 | ||
267 | static void *devlog_start(struct seq_file *seq, loff_t *pos) | |
268 | { | |
269 | struct devlog_info *dinfo = seq->private; | |
270 | ||
271 | return (*pos | |
272 | ? devlog_get_idx(dinfo, *pos) | |
273 | : SEQ_START_TOKEN); | |
274 | } | |
275 | ||
276 | static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos) | |
277 | { | |
278 | struct devlog_info *dinfo = seq->private; | |
279 | ||
280 | (*pos)++; | |
281 | return devlog_get_idx(dinfo, *pos); | |
282 | } | |
283 | ||
284 | static void devlog_stop(struct seq_file *seq, void *v) | |
285 | { | |
286 | } | |
287 | ||
288 | static const struct seq_operations devlog_seq_ops = { | |
289 | .start = devlog_start, | |
290 | .next = devlog_next, | |
291 | .stop = devlog_stop, | |
292 | .show = devlog_show | |
293 | }; | |
294 | ||
295 | /* Set up for reading the firmware's device log. We read the entire log here | |
296 | * and then display it incrementally in devlog_show(). | |
297 | */ | |
298 | static int devlog_open(struct inode *inode, struct file *file) | |
299 | { | |
300 | struct adapter *adap = inode->i_private; | |
301 | struct devlog_params *dparams = &adap->params.devlog; | |
302 | struct devlog_info *dinfo; | |
303 | unsigned int index; | |
304 | u32 fseqno; | |
305 | int ret; | |
306 | ||
307 | /* If we don't know where the log is we can't do anything. | |
308 | */ | |
309 | if (dparams->start == 0) | |
310 | return -ENXIO; | |
311 | ||
312 | /* Allocate the space to read in the firmware's device log and set up | |
313 | * for the iterated call to our display function. | |
314 | */ | |
315 | dinfo = __seq_open_private(file, &devlog_seq_ops, | |
316 | sizeof(*dinfo) + dparams->size); | |
317 | if (!dinfo) | |
318 | return -ENOMEM; | |
319 | ||
320 | /* Record the basic log buffer information and read in the raw log. | |
321 | */ | |
322 | dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e)); | |
323 | dinfo->first = 0; | |
324 | spin_lock(&adap->win0_lock); | |
325 | ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype, | |
326 | dparams->start, dparams->size, (__be32 *)dinfo->log, | |
327 | T4_MEMORY_READ); | |
328 | spin_unlock(&adap->win0_lock); | |
329 | if (ret) { | |
330 | seq_release_private(inode, file); | |
331 | return ret; | |
332 | } | |
333 | ||
334 | /* Translate log multi-byte integral elements into host native format | |
335 | * and determine where the first entry in the log is. | |
336 | */ | |
337 | for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) { | |
338 | struct fw_devlog_e *e = &dinfo->log[index]; | |
339 | int i; | |
340 | __u32 seqno; | |
341 | ||
342 | if (e->timestamp == 0) | |
343 | continue; | |
344 | ||
345 | e->timestamp = (__force __be64)be64_to_cpu(e->timestamp); | |
346 | seqno = be32_to_cpu(e->seqno); | |
347 | for (i = 0; i < 8; i++) | |
348 | e->params[i] = | |
349 | (__force __be32)be32_to_cpu(e->params[i]); | |
350 | ||
351 | if (seqno < fseqno) { | |
352 | fseqno = seqno; | |
353 | dinfo->first = index; | |
354 | } | |
355 | } | |
356 | return 0; | |
357 | } | |
358 | ||
359 | static const struct file_operations devlog_fops = { | |
360 | .owner = THIS_MODULE, | |
361 | .open = devlog_open, | |
362 | .read = seq_read, | |
363 | .llseek = seq_lseek, | |
364 | .release = seq_release_private | |
365 | }; | |
366 | ||
fd88b31a HS |
367 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, |
368 | loff_t *ppos) | |
369 | { | |
370 | loff_t pos = *ppos; | |
371 | loff_t avail = file_inode(file)->i_size; | |
372 | unsigned int mem = (uintptr_t)file->private_data & 3; | |
373 | struct adapter *adap = file->private_data - mem; | |
374 | __be32 *data; | |
375 | int ret; | |
376 | ||
377 | if (pos < 0) | |
378 | return -EINVAL; | |
379 | if (pos >= avail) | |
380 | return 0; | |
381 | if (count > avail - pos) | |
382 | count = avail - pos; | |
383 | ||
384 | data = t4_alloc_mem(count); | |
385 | if (!data) | |
386 | return -ENOMEM; | |
387 | ||
388 | spin_lock(&adap->win0_lock); | |
389 | ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ); | |
390 | spin_unlock(&adap->win0_lock); | |
391 | if (ret) { | |
392 | t4_free_mem(data); | |
393 | return ret; | |
394 | } | |
395 | ret = copy_to_user(buf, data, count); | |
396 | ||
397 | t4_free_mem(data); | |
398 | if (ret) | |
399 | return -EFAULT; | |
400 | ||
401 | *ppos = pos + count; | |
402 | return count; | |
403 | } | |
404 | ||
405 | static const struct file_operations mem_debugfs_fops = { | |
406 | .owner = THIS_MODULE, | |
407 | .open = simple_open, | |
408 | .read = mem_read, | |
409 | .llseek = default_llseek, | |
410 | }; | |
411 | ||
412 | static void add_debugfs_mem(struct adapter *adap, const char *name, | |
413 | unsigned int idx, unsigned int size_mb) | |
414 | { | |
415 | struct dentry *de; | |
416 | ||
417 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, | |
418 | (void *)adap + idx, &mem_debugfs_fops); | |
419 | if (de && de->d_inode) | |
420 | de->d_inode->i_size = size_mb << 20; | |
421 | } | |
422 | ||
423 | /* Add an array of Debug FS files. | |
424 | */ | |
425 | void add_debugfs_files(struct adapter *adap, | |
426 | struct t4_debugfs_entry *files, | |
427 | unsigned int nfiles) | |
428 | { | |
429 | int i; | |
430 | ||
431 | /* debugfs support is best effort */ | |
432 | for (i = 0; i < nfiles; i++) | |
433 | debugfs_create_file(files[i].name, files[i].mode, | |
434 | adap->debugfs_root, | |
435 | (void *)adap + files[i].data, | |
436 | files[i].ops); | |
437 | } | |
438 | ||
439 | int t4_setup_debugfs(struct adapter *adap) | |
440 | { | |
441 | int i; | |
442 | u32 size; | |
443 | ||
444 | static struct t4_debugfs_entry t4_debugfs_files[] = { | |
f1ff24aa | 445 | { "cim_la", &cim_la_fops, S_IRUSR, 0 }, |
49aa284f | 446 | { "devlog", &devlog_fops, S_IRUSR, 0 }, |
fd88b31a HS |
447 | { "l2t", &t4_l2t_fops, S_IRUSR, 0}, |
448 | }; | |
449 | ||
450 | add_debugfs_files(adap, | |
451 | t4_debugfs_files, | |
452 | ARRAY_SIZE(t4_debugfs_files)); | |
453 | ||
6559a7e8 HS |
454 | i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A); |
455 | if (i & EDRAM0_ENABLE_F) { | |
456 | size = t4_read_reg(adap, MA_EDRAM0_BAR_A); | |
457 | add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size)); | |
fd88b31a | 458 | } |
6559a7e8 HS |
459 | if (i & EDRAM1_ENABLE_F) { |
460 | size = t4_read_reg(adap, MA_EDRAM1_BAR_A); | |
461 | add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size)); | |
fd88b31a HS |
462 | } |
463 | if (is_t4(adap->params.chip)) { | |
6559a7e8 HS |
464 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A); |
465 | if (i & EXT_MEM_ENABLE_F) | |
fd88b31a | 466 | add_debugfs_mem(adap, "mc", MEM_MC, |
6559a7e8 | 467 | EXT_MEM_SIZE_G(size)); |
fd88b31a | 468 | } else { |
6559a7e8 HS |
469 | if (i & EXT_MEM0_ENABLE_F) { |
470 | size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A); | |
fd88b31a | 471 | add_debugfs_mem(adap, "mc0", MEM_MC0, |
6559a7e8 | 472 | EXT_MEM0_SIZE_G(size)); |
fd88b31a | 473 | } |
6559a7e8 HS |
474 | if (i & EXT_MEM1_ENABLE_F) { |
475 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A); | |
fd88b31a | 476 | add_debugfs_mem(adap, "mc1", MEM_MC1, |
6559a7e8 | 477 | EXT_MEM1_SIZE_G(size)); |
fd88b31a HS |
478 | } |
479 | } | |
480 | return 0; | |
481 | } |