Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 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 | |
Hariprasad Shenai | 49aa284 | 2015-01-07 08:48:00 +0530 | [diff] [blame^] | 46 | /* Firmware Device Log dump. |
| 47 | */ |
| 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" |
| 55 | }; |
| 56 | |
| 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" |
| 81 | }; |
| 82 | |
| 83 | /* Information gathered by Device Log Open routine for the display routine. |
| 84 | */ |
| 85 | struct devlog_info { |
| 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 */ |
| 89 | }; |
| 90 | |
| 91 | /* Dump a Firmaware Device Log entry. |
| 92 | */ |
| 93 | static int devlog_show(struct seq_file *seq, void *v) |
| 94 | { |
| 95 | if (v == SEQ_START_TOKEN) |
| 96 | seq_printf(seq, "%10s %15s %8s %8s %s\n", |
| 97 | "Seq#", "Tstamp", "Level", "Facility", "Message"); |
| 98 | else { |
| 99 | struct devlog_info *dinfo = seq->private; |
| 100 | int fidx = (uintptr_t)v - 2; |
| 101 | unsigned long index; |
| 102 | struct fw_devlog_e *e; |
| 103 | |
| 104 | /* Get a pointer to the log entry to display. Skip unused log |
| 105 | * entries. |
| 106 | */ |
| 107 | index = dinfo->first + fidx; |
| 108 | if (index >= dinfo->nentries) |
| 109 | index -= dinfo->nentries; |
| 110 | e = &dinfo->log[index]; |
| 111 | if (e->timestamp == 0) |
| 112 | return 0; |
| 113 | |
| 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 ... |
| 117 | */ |
| 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] |
| 122 | : "UNKNOWN"), |
| 123 | (e->facility < ARRAY_SIZE(devlog_facility_strings) |
| 124 | ? devlog_facility_strings[e->facility] |
| 125 | : "UNKNOWN")); |
| 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]); |
| 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | /* Sequential File Operations for Device Log. |
| 134 | */ |
| 135 | static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos) |
| 136 | { |
| 137 | if (pos > dinfo->nentries) |
| 138 | return NULL; |
| 139 | |
| 140 | return (void *)(uintptr_t)(pos + 1); |
| 141 | } |
| 142 | |
| 143 | static void *devlog_start(struct seq_file *seq, loff_t *pos) |
| 144 | { |
| 145 | struct devlog_info *dinfo = seq->private; |
| 146 | |
| 147 | return (*pos |
| 148 | ? devlog_get_idx(dinfo, *pos) |
| 149 | : SEQ_START_TOKEN); |
| 150 | } |
| 151 | |
| 152 | static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos) |
| 153 | { |
| 154 | struct devlog_info *dinfo = seq->private; |
| 155 | |
| 156 | (*pos)++; |
| 157 | return devlog_get_idx(dinfo, *pos); |
| 158 | } |
| 159 | |
| 160 | static void devlog_stop(struct seq_file *seq, void *v) |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | static const struct seq_operations devlog_seq_ops = { |
| 165 | .start = devlog_start, |
| 166 | .next = devlog_next, |
| 167 | .stop = devlog_stop, |
| 168 | .show = devlog_show |
| 169 | }; |
| 170 | |
| 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(). |
| 173 | */ |
| 174 | static int devlog_open(struct inode *inode, struct file *file) |
| 175 | { |
| 176 | struct adapter *adap = inode->i_private; |
| 177 | struct devlog_params *dparams = &adap->params.devlog; |
| 178 | struct devlog_info *dinfo; |
| 179 | unsigned int index; |
| 180 | u32 fseqno; |
| 181 | int ret; |
| 182 | |
| 183 | /* If we don't know where the log is we can't do anything. |
| 184 | */ |
| 185 | if (dparams->start == 0) |
| 186 | return -ENXIO; |
| 187 | |
| 188 | /* Allocate the space to read in the firmware's device log and set up |
| 189 | * for the iterated call to our display function. |
| 190 | */ |
| 191 | dinfo = __seq_open_private(file, &devlog_seq_ops, |
| 192 | sizeof(*dinfo) + dparams->size); |
| 193 | if (!dinfo) |
| 194 | return -ENOMEM; |
| 195 | |
| 196 | /* Record the basic log buffer information and read in the raw log. |
| 197 | */ |
| 198 | dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e)); |
| 199 | dinfo->first = 0; |
| 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, |
| 203 | T4_MEMORY_READ); |
| 204 | spin_unlock(&adap->win0_lock); |
| 205 | if (ret) { |
| 206 | seq_release_private(inode, file); |
| 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | /* Translate log multi-byte integral elements into host native format |
| 211 | * and determine where the first entry in the log is. |
| 212 | */ |
| 213 | for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) { |
| 214 | struct fw_devlog_e *e = &dinfo->log[index]; |
| 215 | int i; |
| 216 | __u32 seqno; |
| 217 | |
| 218 | if (e->timestamp == 0) |
| 219 | continue; |
| 220 | |
| 221 | e->timestamp = (__force __be64)be64_to_cpu(e->timestamp); |
| 222 | seqno = be32_to_cpu(e->seqno); |
| 223 | for (i = 0; i < 8; i++) |
| 224 | e->params[i] = |
| 225 | (__force __be32)be32_to_cpu(e->params[i]); |
| 226 | |
| 227 | if (seqno < fseqno) { |
| 228 | fseqno = seqno; |
| 229 | dinfo->first = index; |
| 230 | } |
| 231 | } |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static const struct file_operations devlog_fops = { |
| 236 | .owner = THIS_MODULE, |
| 237 | .open = devlog_open, |
| 238 | .read = seq_read, |
| 239 | .llseek = seq_lseek, |
| 240 | .release = seq_release_private |
| 241 | }; |
| 242 | |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 243 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, |
| 244 | loff_t *ppos) |
| 245 | { |
| 246 | loff_t pos = *ppos; |
| 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; |
| 250 | __be32 *data; |
| 251 | int ret; |
| 252 | |
| 253 | if (pos < 0) |
| 254 | return -EINVAL; |
| 255 | if (pos >= avail) |
| 256 | return 0; |
| 257 | if (count > avail - pos) |
| 258 | count = avail - pos; |
| 259 | |
| 260 | data = t4_alloc_mem(count); |
| 261 | if (!data) |
| 262 | return -ENOMEM; |
| 263 | |
| 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); |
| 267 | if (ret) { |
| 268 | t4_free_mem(data); |
| 269 | return ret; |
| 270 | } |
| 271 | ret = copy_to_user(buf, data, count); |
| 272 | |
| 273 | t4_free_mem(data); |
| 274 | if (ret) |
| 275 | return -EFAULT; |
| 276 | |
| 277 | *ppos = pos + count; |
| 278 | return count; |
| 279 | } |
| 280 | |
| 281 | static const struct file_operations mem_debugfs_fops = { |
| 282 | .owner = THIS_MODULE, |
| 283 | .open = simple_open, |
| 284 | .read = mem_read, |
| 285 | .llseek = default_llseek, |
| 286 | }; |
| 287 | |
| 288 | static void add_debugfs_mem(struct adapter *adap, const char *name, |
| 289 | unsigned int idx, unsigned int size_mb) |
| 290 | { |
| 291 | struct dentry *de; |
| 292 | |
| 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; |
| 297 | } |
| 298 | |
| 299 | /* Add an array of Debug FS files. |
| 300 | */ |
| 301 | void add_debugfs_files(struct adapter *adap, |
| 302 | struct t4_debugfs_entry *files, |
| 303 | unsigned int nfiles) |
| 304 | { |
| 305 | int i; |
| 306 | |
| 307 | /* debugfs support is best effort */ |
| 308 | for (i = 0; i < nfiles; i++) |
| 309 | debugfs_create_file(files[i].name, files[i].mode, |
| 310 | adap->debugfs_root, |
| 311 | (void *)adap + files[i].data, |
| 312 | files[i].ops); |
| 313 | } |
| 314 | |
| 315 | int t4_setup_debugfs(struct adapter *adap) |
| 316 | { |
| 317 | int i; |
| 318 | u32 size; |
| 319 | |
| 320 | static struct t4_debugfs_entry t4_debugfs_files[] = { |
Hariprasad Shenai | 49aa284 | 2015-01-07 08:48:00 +0530 | [diff] [blame^] | 321 | { "devlog", &devlog_fops, S_IRUSR, 0 }, |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 322 | { "l2t", &t4_l2t_fops, S_IRUSR, 0}, |
| 323 | }; |
| 324 | |
| 325 | add_debugfs_files(adap, |
| 326 | t4_debugfs_files, |
| 327 | ARRAY_SIZE(t4_debugfs_files)); |
| 328 | |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 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)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 333 | } |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 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)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 337 | } |
| 338 | if (is_t4(adap->params.chip)) { |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 339 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A); |
| 340 | if (i & EXT_MEM_ENABLE_F) |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 341 | add_debugfs_mem(adap, "mc", MEM_MC, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 342 | EXT_MEM_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 343 | } else { |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 344 | if (i & EXT_MEM0_ENABLE_F) { |
| 345 | size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 346 | add_debugfs_mem(adap, "mc0", MEM_MC0, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 347 | EXT_MEM0_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 348 | } |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 349 | if (i & EXT_MEM1_ENABLE_F) { |
| 350 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 351 | add_debugfs_mem(adap, "mc1", MEM_MC1, |
Hariprasad Shenai | 6559a7e | 2014-11-07 09:35:24 +0530 | [diff] [blame] | 352 | EXT_MEM1_SIZE_G(size)); |
Hariprasad Shenai | fd88b31 | 2014-11-07 09:35:23 +0530 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | return 0; |
| 356 | } |