2 * This file is part of the Chelsio T4 Ethernet driver for Linux.
4 * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
35 #include <linux/seq_file.h>
36 #include <linux/debugfs.h>
37 #include <linux/string_helpers.h>
38 #include <linux/sort.h>
43 #include "cxgb4_debugfs.h"
46 /* Firmware Device Log dump.
48 static const char * const devlog_level_strings
[] = {
49 [FW_DEVLOG_LEVEL_EMERG
] = "EMERG",
50 [FW_DEVLOG_LEVEL_CRIT
] = "CRIT",
51 [FW_DEVLOG_LEVEL_ERR
] = "ERR",
52 [FW_DEVLOG_LEVEL_NOTICE
] = "NOTICE",
53 [FW_DEVLOG_LEVEL_INFO
] = "INFO",
54 [FW_DEVLOG_LEVEL_DEBUG
] = "DEBUG"
57 static const char * const devlog_facility_strings
[] = {
58 [FW_DEVLOG_FACILITY_CORE
] = "CORE",
59 [FW_DEVLOG_FACILITY_SCHED
] = "SCHED",
60 [FW_DEVLOG_FACILITY_TIMER
] = "TIMER",
61 [FW_DEVLOG_FACILITY_RES
] = "RES",
62 [FW_DEVLOG_FACILITY_HW
] = "HW",
63 [FW_DEVLOG_FACILITY_FLR
] = "FLR",
64 [FW_DEVLOG_FACILITY_DMAQ
] = "DMAQ",
65 [FW_DEVLOG_FACILITY_PHY
] = "PHY",
66 [FW_DEVLOG_FACILITY_MAC
] = "MAC",
67 [FW_DEVLOG_FACILITY_PORT
] = "PORT",
68 [FW_DEVLOG_FACILITY_VI
] = "VI",
69 [FW_DEVLOG_FACILITY_FILTER
] = "FILTER",
70 [FW_DEVLOG_FACILITY_ACL
] = "ACL",
71 [FW_DEVLOG_FACILITY_TM
] = "TM",
72 [FW_DEVLOG_FACILITY_QFC
] = "QFC",
73 [FW_DEVLOG_FACILITY_DCB
] = "DCB",
74 [FW_DEVLOG_FACILITY_ETH
] = "ETH",
75 [FW_DEVLOG_FACILITY_OFLD
] = "OFLD",
76 [FW_DEVLOG_FACILITY_RI
] = "RI",
77 [FW_DEVLOG_FACILITY_ISCSI
] = "ISCSI",
78 [FW_DEVLOG_FACILITY_FCOE
] = "FCOE",
79 [FW_DEVLOG_FACILITY_FOISCSI
] = "FOISCSI",
80 [FW_DEVLOG_FACILITY_FOFCOE
] = "FOFCOE"
83 /* Information gathered by Device Log Open routine for the display routine.
86 unsigned int nentries
; /* number of entries in log[] */
87 unsigned int first
; /* first [temporal] entry in log[] */
88 struct fw_devlog_e log
[0]; /* Firmware Device Log */
91 /* Dump a Firmaware Device Log entry.
93 static int devlog_show(struct seq_file
*seq
, void *v
)
95 if (v
== SEQ_START_TOKEN
)
96 seq_printf(seq
, "%10s %15s %8s %8s %s\n",
97 "Seq#", "Tstamp", "Level", "Facility", "Message");
99 struct devlog_info
*dinfo
= seq
->private;
100 int fidx
= (uintptr_t)v
- 2;
102 struct fw_devlog_e
*e
;
104 /* Get a pointer to the log entry to display. Skip unused log
107 index
= dinfo
->first
+ fidx
;
108 if (index
>= dinfo
->nentries
)
109 index
-= dinfo
->nentries
;
110 e
= &dinfo
->log
[index
];
111 if (e
->timestamp
== 0)
114 /* Print the message. This depends on the firmware using
115 * exactly the same formating strings as the kernel so we may
116 * eventually have to put a format interpreter in here ...
118 seq_printf(seq
, "%10d %15llu %8s %8s ",
119 e
->seqno
, e
->timestamp
,
120 (e
->level
< ARRAY_SIZE(devlog_level_strings
)
121 ? devlog_level_strings
[e
->level
]
123 (e
->facility
< ARRAY_SIZE(devlog_facility_strings
)
124 ? devlog_facility_strings
[e
->facility
]
126 seq_printf(seq
, e
->fmt
, e
->params
[0], e
->params
[1],
127 e
->params
[2], e
->params
[3], e
->params
[4],
128 e
->params
[5], e
->params
[6], e
->params
[7]);
133 /* Sequential File Operations for Device Log.
135 static inline void *devlog_get_idx(struct devlog_info
*dinfo
, loff_t pos
)
137 if (pos
> dinfo
->nentries
)
140 return (void *)(uintptr_t)(pos
+ 1);
143 static void *devlog_start(struct seq_file
*seq
, loff_t
*pos
)
145 struct devlog_info
*dinfo
= seq
->private;
148 ? devlog_get_idx(dinfo
, *pos
)
152 static void *devlog_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
154 struct devlog_info
*dinfo
= seq
->private;
157 return devlog_get_idx(dinfo
, *pos
);
160 static void devlog_stop(struct seq_file
*seq
, void *v
)
164 static const struct seq_operations devlog_seq_ops
= {
165 .start
= devlog_start
,
171 /* Set up for reading the firmware's device log. We read the entire log here
172 * and then display it incrementally in devlog_show().
174 static int devlog_open(struct inode
*inode
, struct file
*file
)
176 struct adapter
*adap
= inode
->i_private
;
177 struct devlog_params
*dparams
= &adap
->params
.devlog
;
178 struct devlog_info
*dinfo
;
183 /* If we don't know where the log is we can't do anything.
185 if (dparams
->start
== 0)
188 /* Allocate the space to read in the firmware's device log and set up
189 * for the iterated call to our display function.
191 dinfo
= __seq_open_private(file
, &devlog_seq_ops
,
192 sizeof(*dinfo
) + dparams
->size
);
196 /* Record the basic log buffer information and read in the raw log.
198 dinfo
->nentries
= (dparams
->size
/ sizeof(struct fw_devlog_e
));
200 spin_lock(&adap
->win0_lock
);
201 ret
= t4_memory_rw(adap
, adap
->params
.drv_memwin
, dparams
->memtype
,
202 dparams
->start
, dparams
->size
, (__be32
*)dinfo
->log
,
204 spin_unlock(&adap
->win0_lock
);
206 seq_release_private(inode
, file
);
210 /* Translate log multi-byte integral elements into host native format
211 * and determine where the first entry in the log is.
213 for (fseqno
= ~((u32
)0), index
= 0; index
< dinfo
->nentries
; index
++) {
214 struct fw_devlog_e
*e
= &dinfo
->log
[index
];
218 if (e
->timestamp
== 0)
221 e
->timestamp
= (__force __be64
)be64_to_cpu(e
->timestamp
);
222 seqno
= be32_to_cpu(e
->seqno
);
223 for (i
= 0; i
< 8; i
++)
225 (__force __be32
)be32_to_cpu(e
->params
[i
]);
227 if (seqno
< fseqno
) {
229 dinfo
->first
= index
;
235 static const struct file_operations devlog_fops
= {
236 .owner
= THIS_MODULE
,
240 .release
= seq_release_private
243 static ssize_t
mem_read(struct file
*file
, char __user
*buf
, size_t count
,
247 loff_t avail
= file_inode(file
)->i_size
;
248 unsigned int mem
= (uintptr_t)file
->private_data
& 3;
249 struct adapter
*adap
= file
->private_data
- mem
;
257 if (count
> avail
- pos
)
260 data
= t4_alloc_mem(count
);
264 spin_lock(&adap
->win0_lock
);
265 ret
= t4_memory_rw(adap
, 0, mem
, pos
, count
, data
, T4_MEMORY_READ
);
266 spin_unlock(&adap
->win0_lock
);
271 ret
= copy_to_user(buf
, data
, count
);
281 static const struct file_operations mem_debugfs_fops
= {
282 .owner
= THIS_MODULE
,
285 .llseek
= default_llseek
,
288 static void add_debugfs_mem(struct adapter
*adap
, const char *name
,
289 unsigned int idx
, unsigned int size_mb
)
293 de
= debugfs_create_file(name
, S_IRUSR
, adap
->debugfs_root
,
294 (void *)adap
+ idx
, &mem_debugfs_fops
);
295 if (de
&& de
->d_inode
)
296 de
->d_inode
->i_size
= size_mb
<< 20;
299 /* Add an array of Debug FS files.
301 void add_debugfs_files(struct adapter
*adap
,
302 struct t4_debugfs_entry
*files
,
307 /* debugfs support is best effort */
308 for (i
= 0; i
< nfiles
; i
++)
309 debugfs_create_file(files
[i
].name
, files
[i
].mode
,
311 (void *)adap
+ files
[i
].data
,
315 int t4_setup_debugfs(struct adapter
*adap
)
320 static struct t4_debugfs_entry t4_debugfs_files
[] = {
321 { "devlog", &devlog_fops
, S_IRUSR
, 0 },
322 { "l2t", &t4_l2t_fops
, S_IRUSR
, 0},
325 add_debugfs_files(adap
,
327 ARRAY_SIZE(t4_debugfs_files
));
329 i
= t4_read_reg(adap
, MA_TARGET_MEM_ENABLE_A
);
330 if (i
& EDRAM0_ENABLE_F
) {
331 size
= t4_read_reg(adap
, MA_EDRAM0_BAR_A
);
332 add_debugfs_mem(adap
, "edc0", MEM_EDC0
, EDRAM0_SIZE_G(size
));
334 if (i
& EDRAM1_ENABLE_F
) {
335 size
= t4_read_reg(adap
, MA_EDRAM1_BAR_A
);
336 add_debugfs_mem(adap
, "edc1", MEM_EDC1
, EDRAM1_SIZE_G(size
));
338 if (is_t4(adap
->params
.chip
)) {
339 size
= t4_read_reg(adap
, MA_EXT_MEMORY_BAR_A
);
340 if (i
& EXT_MEM_ENABLE_F
)
341 add_debugfs_mem(adap
, "mc", MEM_MC
,
342 EXT_MEM_SIZE_G(size
));
344 if (i
& EXT_MEM0_ENABLE_F
) {
345 size
= t4_read_reg(adap
, MA_EXT_MEMORY0_BAR_A
);
346 add_debugfs_mem(adap
, "mc0", MEM_MC0
,
347 EXT_MEM0_SIZE_G(size
));
349 if (i
& EXT_MEM1_ENABLE_F
) {
350 size
= t4_read_reg(adap
, MA_EXT_MEMORY1_BAR_A
);
351 add_debugfs_mem(adap
, "mc1", MEM_MC1
,
352 EXT_MEM1_SIZE_G(size
));