blob: e9f348942eb0f7a71311b319be326669ddddf065 [file] [log] [blame]
Hariprasad Shenaifd88b312014-11-07 09:35:23 +05301/*
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 Shenaif1ff24a2015-01-07 08:48:01 +053046/* generic seq_file support for showing a table of size rows x width. */
47static 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
53static 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
63static 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
71static void seq_tab_stop(struct seq_file *seq, void *v)
72{
73}
74
75static 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
82static 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
89struct 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
105static 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
122static 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
140static 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
163static 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
Hariprasad Shenai74b30922015-01-07 08:48:02 +0530171static int cim_qcfg_show(struct seq_file *seq, void *v)
172{
173 static const char * const qname[] = {
174 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
175 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
176 "SGE0-RX", "SGE1-RX"
177 };
178
179 int i;
180 struct adapter *adap = seq->private;
181 u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
182 u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
183 u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
184 u16 thres[CIM_NUM_IBQ];
185 u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
186 u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
187 u32 *p = stat;
188 int cim_num_obq = is_t4(adap->params.chip) ?
189 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
190
191 i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
192 UP_IBQ_0_SHADOW_RDADDR_A,
193 ARRAY_SIZE(stat), stat);
194 if (!i) {
195 if (is_t4(adap->params.chip)) {
196 i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
197 ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
198 wr = obq_wr_t4;
199 } else {
200 i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
201 ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
202 wr = obq_wr_t5;
203 }
204 }
205 if (i)
206 return i;
207
208 t4_read_cimq_cfg(adap, base, size, thres);
209
210 seq_printf(seq,
211 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n");
212 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
213 seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n",
214 qname[i], base[i], size[i], thres[i],
215 IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
216 QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
217 QUEREMFLITS_G(p[2]) * 16);
218 for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
219 seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n",
220 qname[i], base[i], size[i],
221 QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
222 QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
223 QUEREMFLITS_G(p[2]) * 16);
224 return 0;
225}
226
227static int cim_qcfg_open(struct inode *inode, struct file *file)
228{
229 return single_open(file, cim_qcfg_show, inode->i_private);
230}
231
232static const struct file_operations cim_qcfg_fops = {
233 .owner = THIS_MODULE,
234 .open = cim_qcfg_open,
235 .read = seq_read,
236 .llseek = seq_lseek,
237 .release = single_release,
238};
239
Hariprasad Shenaif1ff24a2015-01-07 08:48:01 +0530240/* Firmware Device Log dump. */
Hariprasad Shenai49aa2842015-01-07 08:48:00 +0530241static const char * const devlog_level_strings[] = {
242 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
243 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
244 [FW_DEVLOG_LEVEL_ERR] = "ERR",
245 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
246 [FW_DEVLOG_LEVEL_INFO] = "INFO",
247 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
248};
249
250static const char * const devlog_facility_strings[] = {
251 [FW_DEVLOG_FACILITY_CORE] = "CORE",
252 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
253 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
254 [FW_DEVLOG_FACILITY_RES] = "RES",
255 [FW_DEVLOG_FACILITY_HW] = "HW",
256 [FW_DEVLOG_FACILITY_FLR] = "FLR",
257 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
258 [FW_DEVLOG_FACILITY_PHY] = "PHY",
259 [FW_DEVLOG_FACILITY_MAC] = "MAC",
260 [FW_DEVLOG_FACILITY_PORT] = "PORT",
261 [FW_DEVLOG_FACILITY_VI] = "VI",
262 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
263 [FW_DEVLOG_FACILITY_ACL] = "ACL",
264 [FW_DEVLOG_FACILITY_TM] = "TM",
265 [FW_DEVLOG_FACILITY_QFC] = "QFC",
266 [FW_DEVLOG_FACILITY_DCB] = "DCB",
267 [FW_DEVLOG_FACILITY_ETH] = "ETH",
268 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
269 [FW_DEVLOG_FACILITY_RI] = "RI",
270 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
271 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
272 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
273 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
274};
275
276/* Information gathered by Device Log Open routine for the display routine.
277 */
278struct devlog_info {
279 unsigned int nentries; /* number of entries in log[] */
280 unsigned int first; /* first [temporal] entry in log[] */
281 struct fw_devlog_e log[0]; /* Firmware Device Log */
282};
283
284/* Dump a Firmaware Device Log entry.
285 */
286static int devlog_show(struct seq_file *seq, void *v)
287{
288 if (v == SEQ_START_TOKEN)
289 seq_printf(seq, "%10s %15s %8s %8s %s\n",
290 "Seq#", "Tstamp", "Level", "Facility", "Message");
291 else {
292 struct devlog_info *dinfo = seq->private;
293 int fidx = (uintptr_t)v - 2;
294 unsigned long index;
295 struct fw_devlog_e *e;
296
297 /* Get a pointer to the log entry to display. Skip unused log
298 * entries.
299 */
300 index = dinfo->first + fidx;
301 if (index >= dinfo->nentries)
302 index -= dinfo->nentries;
303 e = &dinfo->log[index];
304 if (e->timestamp == 0)
305 return 0;
306
307 /* Print the message. This depends on the firmware using
308 * exactly the same formating strings as the kernel so we may
309 * eventually have to put a format interpreter in here ...
310 */
311 seq_printf(seq, "%10d %15llu %8s %8s ",
312 e->seqno, e->timestamp,
313 (e->level < ARRAY_SIZE(devlog_level_strings)
314 ? devlog_level_strings[e->level]
315 : "UNKNOWN"),
316 (e->facility < ARRAY_SIZE(devlog_facility_strings)
317 ? devlog_facility_strings[e->facility]
318 : "UNKNOWN"));
319 seq_printf(seq, e->fmt, e->params[0], e->params[1],
320 e->params[2], e->params[3], e->params[4],
321 e->params[5], e->params[6], e->params[7]);
322 }
323 return 0;
324}
325
326/* Sequential File Operations for Device Log.
327 */
328static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
329{
330 if (pos > dinfo->nentries)
331 return NULL;
332
333 return (void *)(uintptr_t)(pos + 1);
334}
335
336static void *devlog_start(struct seq_file *seq, loff_t *pos)
337{
338 struct devlog_info *dinfo = seq->private;
339
340 return (*pos
341 ? devlog_get_idx(dinfo, *pos)
342 : SEQ_START_TOKEN);
343}
344
345static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
346{
347 struct devlog_info *dinfo = seq->private;
348
349 (*pos)++;
350 return devlog_get_idx(dinfo, *pos);
351}
352
353static void devlog_stop(struct seq_file *seq, void *v)
354{
355}
356
357static const struct seq_operations devlog_seq_ops = {
358 .start = devlog_start,
359 .next = devlog_next,
360 .stop = devlog_stop,
361 .show = devlog_show
362};
363
364/* Set up for reading the firmware's device log. We read the entire log here
365 * and then display it incrementally in devlog_show().
366 */
367static int devlog_open(struct inode *inode, struct file *file)
368{
369 struct adapter *adap = inode->i_private;
370 struct devlog_params *dparams = &adap->params.devlog;
371 struct devlog_info *dinfo;
372 unsigned int index;
373 u32 fseqno;
374 int ret;
375
376 /* If we don't know where the log is we can't do anything.
377 */
378 if (dparams->start == 0)
379 return -ENXIO;
380
381 /* Allocate the space to read in the firmware's device log and set up
382 * for the iterated call to our display function.
383 */
384 dinfo = __seq_open_private(file, &devlog_seq_ops,
385 sizeof(*dinfo) + dparams->size);
386 if (!dinfo)
387 return -ENOMEM;
388
389 /* Record the basic log buffer information and read in the raw log.
390 */
391 dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
392 dinfo->first = 0;
393 spin_lock(&adap->win0_lock);
394 ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
395 dparams->start, dparams->size, (__be32 *)dinfo->log,
396 T4_MEMORY_READ);
397 spin_unlock(&adap->win0_lock);
398 if (ret) {
399 seq_release_private(inode, file);
400 return ret;
401 }
402
403 /* Translate log multi-byte integral elements into host native format
404 * and determine where the first entry in the log is.
405 */
406 for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
407 struct fw_devlog_e *e = &dinfo->log[index];
408 int i;
409 __u32 seqno;
410
411 if (e->timestamp == 0)
412 continue;
413
414 e->timestamp = (__force __be64)be64_to_cpu(e->timestamp);
415 seqno = be32_to_cpu(e->seqno);
416 for (i = 0; i < 8; i++)
417 e->params[i] =
418 (__force __be32)be32_to_cpu(e->params[i]);
419
420 if (seqno < fseqno) {
421 fseqno = seqno;
422 dinfo->first = index;
423 }
424 }
425 return 0;
426}
427
428static const struct file_operations devlog_fops = {
429 .owner = THIS_MODULE,
430 .open = devlog_open,
431 .read = seq_read,
432 .llseek = seq_lseek,
433 .release = seq_release_private
434};
435
Hariprasad Shenaief82f662015-01-07 08:48:03 +0530436static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
437{
438 *mask = x | y;
439 y = (__force u64)cpu_to_be64(y);
440 memcpy(addr, (char *)&y + 2, ETH_ALEN);
441}
442
443static int mps_tcam_show(struct seq_file *seq, void *v)
444{
445 if (v == SEQ_START_TOKEN)
446 seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF"
447 " VF Replication "
448 "P0 P1 P2 P3 ML\n");
449 else {
450 u64 mask;
451 u8 addr[ETH_ALEN];
452 struct adapter *adap = seq->private;
453 unsigned int idx = (uintptr_t)v - 2;
454 u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
455 u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
456 u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
457 u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
458 u32 rplc[4] = {0, 0, 0, 0};
459
460 if (tcamx & tcamy) {
461 seq_printf(seq, "%3u -\n", idx);
462 goto out;
463 }
464
465 if (cls_lo & REPLICATE_F) {
466 struct fw_ldst_cmd ldst_cmd;
467 int ret;
468
469 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
470 ldst_cmd.op_to_addrspace =
471 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
472 FW_CMD_REQUEST_F |
473 FW_CMD_READ_F |
474 FW_LDST_CMD_ADDRSPACE_V(
475 FW_LDST_ADDRSPC_MPS));
476 ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
477 ldst_cmd.u.mps.fid_ctl =
478 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
479 FW_LDST_CMD_CTL_V(idx));
480 ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
481 sizeof(ldst_cmd), &ldst_cmd);
482 if (ret)
483 dev_warn(adap->pdev_dev, "Can't read MPS "
484 "replication map for idx %d: %d\n",
485 idx, -ret);
486 else {
487 rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0);
488 rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32);
489 rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64);
490 rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96);
491 }
492 }
493
494 tcamxy2valmask(tcamx, tcamy, addr, &mask);
495 seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx"
496 "%3c %#x%4u%4d",
497 idx, addr[0], addr[1], addr[2], addr[3], addr[4],
498 addr[5], (unsigned long long)mask,
499 (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi),
500 PF_G(cls_lo),
501 (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
502 if (cls_lo & REPLICATE_F)
503 seq_printf(seq, " %08x %08x %08x %08x",
504 rplc[3], rplc[2], rplc[1], rplc[0]);
505 else
506 seq_printf(seq, "%36c", ' ');
507 seq_printf(seq, "%4u%3u%3u%3u %#x\n",
508 SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
509 SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
510 (cls_lo >> MULTILISTEN0_S) & 0xf);
511 }
512out: return 0;
513}
514
515static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
516{
517 struct adapter *adap = seq->private;
518 int max_mac_addr = is_t4(adap->params.chip) ?
519 NUM_MPS_CLS_SRAM_L_INSTANCES :
520 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
521 return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
522}
523
524static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
525{
526 return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
527}
528
529static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
530{
531 ++*pos;
532 return mps_tcam_get_idx(seq, *pos);
533}
534
535static void mps_tcam_stop(struct seq_file *seq, void *v)
536{
537}
538
539static const struct seq_operations mps_tcam_seq_ops = {
540 .start = mps_tcam_start,
541 .next = mps_tcam_next,
542 .stop = mps_tcam_stop,
543 .show = mps_tcam_show
544};
545
546static int mps_tcam_open(struct inode *inode, struct file *file)
547{
548 int res = seq_open(file, &mps_tcam_seq_ops);
549
550 if (!res) {
551 struct seq_file *seq = file->private_data;
552
553 seq->private = inode->i_private;
554 }
555 return res;
556}
557
558static const struct file_operations mps_tcam_debugfs_fops = {
559 .owner = THIS_MODULE,
560 .open = mps_tcam_open,
561 .read = seq_read,
562 .llseek = seq_lseek,
563 .release = seq_release,
564};
565
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530566static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
567 loff_t *ppos)
568{
569 loff_t pos = *ppos;
570 loff_t avail = file_inode(file)->i_size;
571 unsigned int mem = (uintptr_t)file->private_data & 3;
572 struct adapter *adap = file->private_data - mem;
573 __be32 *data;
574 int ret;
575
576 if (pos < 0)
577 return -EINVAL;
578 if (pos >= avail)
579 return 0;
580 if (count > avail - pos)
581 count = avail - pos;
582
583 data = t4_alloc_mem(count);
584 if (!data)
585 return -ENOMEM;
586
587 spin_lock(&adap->win0_lock);
588 ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
589 spin_unlock(&adap->win0_lock);
590 if (ret) {
591 t4_free_mem(data);
592 return ret;
593 }
594 ret = copy_to_user(buf, data, count);
595
596 t4_free_mem(data);
597 if (ret)
598 return -EFAULT;
599
600 *ppos = pos + count;
601 return count;
602}
603
604static const struct file_operations mem_debugfs_fops = {
605 .owner = THIS_MODULE,
606 .open = simple_open,
607 .read = mem_read,
608 .llseek = default_llseek,
609};
610
611static void add_debugfs_mem(struct adapter *adap, const char *name,
612 unsigned int idx, unsigned int size_mb)
613{
614 struct dentry *de;
615
616 de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root,
617 (void *)adap + idx, &mem_debugfs_fops);
618 if (de && de->d_inode)
619 de->d_inode->i_size = size_mb << 20;
620}
621
622/* Add an array of Debug FS files.
623 */
624void add_debugfs_files(struct adapter *adap,
625 struct t4_debugfs_entry *files,
626 unsigned int nfiles)
627{
628 int i;
629
630 /* debugfs support is best effort */
631 for (i = 0; i < nfiles; i++)
632 debugfs_create_file(files[i].name, files[i].mode,
633 adap->debugfs_root,
634 (void *)adap + files[i].data,
635 files[i].ops);
636}
637
638int t4_setup_debugfs(struct adapter *adap)
639{
640 int i;
641 u32 size;
642
643 static struct t4_debugfs_entry t4_debugfs_files[] = {
Hariprasad Shenaif1ff24a2015-01-07 08:48:01 +0530644 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
Hariprasad Shenai74b30922015-01-07 08:48:02 +0530645 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
Hariprasad Shenai49aa2842015-01-07 08:48:00 +0530646 { "devlog", &devlog_fops, S_IRUSR, 0 },
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530647 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
Hariprasad Shenaief82f662015-01-07 08:48:03 +0530648 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530649 };
650
651 add_debugfs_files(adap,
652 t4_debugfs_files,
653 ARRAY_SIZE(t4_debugfs_files));
654
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530655 i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
656 if (i & EDRAM0_ENABLE_F) {
657 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
658 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530659 }
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530660 if (i & EDRAM1_ENABLE_F) {
661 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
662 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530663 }
664 if (is_t4(adap->params.chip)) {
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530665 size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
666 if (i & EXT_MEM_ENABLE_F)
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530667 add_debugfs_mem(adap, "mc", MEM_MC,
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530668 EXT_MEM_SIZE_G(size));
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530669 } else {
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530670 if (i & EXT_MEM0_ENABLE_F) {
671 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530672 add_debugfs_mem(adap, "mc0", MEM_MC0,
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530673 EXT_MEM0_SIZE_G(size));
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530674 }
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530675 if (i & EXT_MEM1_ENABLE_F) {
676 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530677 add_debugfs_mem(adap, "mc1", MEM_MC1,
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +0530678 EXT_MEM1_SIZE_G(size));
Hariprasad Shenaifd88b312014-11-07 09:35:23 +0530679 }
680 }
681 return 0;
682}