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>
39 #include <linux/ctype.h>
44 #include "cxgb4_debugfs.h"
48 /* generic seq_file support for showing a table of size rows x width. */
49 static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
51 pos -= tb->skip_first;
52 return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
55 static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
57 struct seq_tab *tb = seq->private;
59 if (tb->skip_first && *pos == 0)
60 return SEQ_START_TOKEN;
62 return seq_tab_get_idx(tb, *pos);
65 static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
67 v = seq_tab_get_idx(seq->private, *pos + 1);
73 static void seq_tab_stop(struct seq_file *seq, void *v)
77 static int seq_tab_show(struct seq_file *seq, void *v)
79 const struct seq_tab *tb = seq->private;
81 return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
84 static const struct seq_operations seq_tab_ops = {
85 .start = seq_tab_start,
91 struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
92 unsigned int width, unsigned int have_header,
93 int (*show)(struct seq_file *seq, void *v, int i))
97 p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
102 p->skip_first = have_header != 0;
107 /* Trim the size of a seq_tab to the supplied number of rows. The operation is
110 static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
112 if (new_rows > p->rows)
118 static int cim_la_show(struct seq_file *seq, void *v, int idx)
120 if (v == SEQ_START_TOKEN)
121 seq_puts(seq, "Status Data PC LS0Stat LS0Addr "
127 " %02x %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
128 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
129 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
135 static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
137 if (v == SEQ_START_TOKEN) {
138 seq_puts(seq, "Status Data PC\n");
142 seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6],
144 seq_printf(seq, " %02x %02x%06x %02x%06x\n",
145 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
146 p[4] & 0xff, p[5] >> 8);
147 seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
148 p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
153 static int cim_la_open(struct inode *inode, struct file *file)
158 struct adapter *adap = inode->i_private;
160 ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
164 p = seq_open_tab(file, adap->params.cim_la_size / 8, 8 * sizeof(u32), 1,
165 cfg & UPDBGLACAPTPCONLY_F ?
166 cim_la_show_3in1 : cim_la_show);
170 ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
172 seq_release_private(inode, file);
176 static const struct file_operations cim_la_fops = {
177 .owner = THIS_MODULE,
181 .release = seq_release_private
184 static int cim_qcfg_show(struct seq_file *seq, void *v)
186 static const char * const qname[] = {
187 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
188 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
193 struct adapter *adap = seq->private;
194 u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
195 u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
196 u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
197 u16 thres[CIM_NUM_IBQ];
198 u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
199 u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
201 int cim_num_obq = is_t4(adap->params.chip) ?
202 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
204 i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
205 UP_IBQ_0_SHADOW_RDADDR_A,
206 ARRAY_SIZE(stat), stat);
208 if (is_t4(adap->params.chip)) {
209 i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
210 ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
213 i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
214 ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
221 t4_read_cimq_cfg(adap, base, size, thres);
224 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n");
225 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
226 seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n",
227 qname[i], base[i], size[i], thres[i],
228 IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
229 QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
230 QUEREMFLITS_G(p[2]) * 16);
231 for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
232 seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n",
233 qname[i], base[i], size[i],
234 QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
235 QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
236 QUEREMFLITS_G(p[2]) * 16);
240 static int cim_qcfg_open(struct inode *inode, struct file *file)
242 return single_open(file, cim_qcfg_show, inode->i_private);
245 static const struct file_operations cim_qcfg_fops = {
246 .owner = THIS_MODULE,
247 .open = cim_qcfg_open,
250 .release = single_release,
253 static int cimq_show(struct seq_file *seq, void *v, int idx)
257 seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
262 static int cim_ibq_open(struct inode *inode, struct file *file)
266 unsigned int qid = (uintptr_t)inode->i_private & 7;
267 struct adapter *adap = inode->i_private - qid;
269 p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
273 ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
275 seq_release_private(inode, file);
281 static const struct file_operations cim_ibq_fops = {
282 .owner = THIS_MODULE,
283 .open = cim_ibq_open,
286 .release = seq_release_private
289 static int cim_obq_open(struct inode *inode, struct file *file)
293 unsigned int qid = (uintptr_t)inode->i_private & 7;
294 struct adapter *adap = inode->i_private - qid;
296 p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
300 ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
302 seq_release_private(inode, file);
304 seq_tab_trim(p, ret / 4);
310 static const struct file_operations cim_obq_fops = {
311 .owner = THIS_MODULE,
312 .open = cim_obq_open,
315 .release = seq_release_private
318 /* Show the PM memory stats. These stats include:
321 * Read: memory read operation
322 * Write Bypass: cut-through
323 * Bypass + mem: cut-through and save copy
327 * Write Bypass: cut-through
328 * Flush: payload trim or drop
330 static int pm_stats_show(struct seq_file *seq, void *v)
332 static const char * const tx_pm_stats[] = {
333 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
335 static const char * const rx_pm_stats[] = {
336 "Read:", "Write bypass:", "Write mem:", "Flush:"
340 u32 tx_cnt[PM_NSTATS], rx_cnt[PM_NSTATS];
341 u64 tx_cyc[PM_NSTATS], rx_cyc[PM_NSTATS];
342 struct adapter *adap = seq->private;
344 t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
345 t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
347 seq_printf(seq, "%13s %10s %20s\n", " ", "Tx pcmds", "Tx bytes");
348 for (i = 0; i < PM_NSTATS - 1; i++)
349 seq_printf(seq, "%-13s %10u %20llu\n",
350 tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
352 seq_printf(seq, "%13s %10s %20s\n", " ", "Rx pcmds", "Rx bytes");
353 for (i = 0; i < PM_NSTATS - 1; i++)
354 seq_printf(seq, "%-13s %10u %20llu\n",
355 rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
359 static int pm_stats_open(struct inode *inode, struct file *file)
361 return single_open(file, pm_stats_show, inode->i_private);
364 static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
365 size_t count, loff_t *pos)
367 struct adapter *adap = FILE_DATA(file)->i_private;
369 t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
370 t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
374 static const struct file_operations pm_stats_debugfs_fops = {
375 .owner = THIS_MODULE,
376 .open = pm_stats_open,
379 .release = single_release,
380 .write = pm_stats_clear
383 /* Format a value in a unit that differs from the value's native unit by the
386 static char *unit_conv(char *buf, size_t len, unsigned int val,
389 unsigned int rem = val % factor;
392 snprintf(buf, len, "%u", val / factor);
394 while (rem % 10 == 0)
396 snprintf(buf, len, "%u.%u", val / factor, rem);
401 static int clk_show(struct seq_file *seq, void *v)
404 struct adapter *adap = seq->private;
405 unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk; /* in ps */
406 u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
407 unsigned int tre = TIMERRESOLUTION_G(res);
408 unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
409 unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
411 seq_printf(seq, "Core clock period: %s ns\n",
412 unit_conv(buf, sizeof(buf), cclk_ps, 1000));
413 seq_printf(seq, "TP timer tick: %s us\n",
414 unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
415 seq_printf(seq, "TCP timestamp tick: %s us\n",
416 unit_conv(buf, sizeof(buf),
417 (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
418 seq_printf(seq, "DACK tick: %s us\n",
419 unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
420 seq_printf(seq, "DACK timer: %u us\n",
421 ((cclk_ps << dack_re) / 1000000) *
422 t4_read_reg(adap, TP_DACK_TIMER_A));
423 seq_printf(seq, "Retransmit min: %llu us\n",
424 tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
425 seq_printf(seq, "Retransmit max: %llu us\n",
426 tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
427 seq_printf(seq, "Persist timer min: %llu us\n",
428 tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
429 seq_printf(seq, "Persist timer max: %llu us\n",
430 tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
431 seq_printf(seq, "Keepalive idle timer: %llu us\n",
432 tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
433 seq_printf(seq, "Keepalive interval: %llu us\n",
434 tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
435 seq_printf(seq, "Initial SRTT: %llu us\n",
436 tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
437 seq_printf(seq, "FINWAIT2 timer: %llu us\n",
438 tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
443 DEFINE_SIMPLE_DEBUGFS_FILE(clk);
445 /* Firmware Device Log dump. */
446 static const char * const devlog_level_strings[] = {
447 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
448 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
449 [FW_DEVLOG_LEVEL_ERR] = "ERR",
450 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
451 [FW_DEVLOG_LEVEL_INFO] = "INFO",
452 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
455 static const char * const devlog_facility_strings[] = {
456 [FW_DEVLOG_FACILITY_CORE] = "CORE",
457 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
458 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
459 [FW_DEVLOG_FACILITY_RES] = "RES",
460 [FW_DEVLOG_FACILITY_HW] = "HW",
461 [FW_DEVLOG_FACILITY_FLR] = "FLR",
462 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
463 [FW_DEVLOG_FACILITY_PHY] = "PHY",
464 [FW_DEVLOG_FACILITY_MAC] = "MAC",
465 [FW_DEVLOG_FACILITY_PORT] = "PORT",
466 [FW_DEVLOG_FACILITY_VI] = "VI",
467 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
468 [FW_DEVLOG_FACILITY_ACL] = "ACL",
469 [FW_DEVLOG_FACILITY_TM] = "TM",
470 [FW_DEVLOG_FACILITY_QFC] = "QFC",
471 [FW_DEVLOG_FACILITY_DCB] = "DCB",
472 [FW_DEVLOG_FACILITY_ETH] = "ETH",
473 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
474 [FW_DEVLOG_FACILITY_RI] = "RI",
475 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
476 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
477 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
478 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
481 /* Information gathered by Device Log Open routine for the display routine.
484 unsigned int nentries; /* number of entries in log[] */
485 unsigned int first; /* first [temporal] entry in log[] */
486 struct fw_devlog_e log[0]; /* Firmware Device Log */
489 /* Dump a Firmaware Device Log entry.
491 static int devlog_show(struct seq_file *seq, void *v)
493 if (v == SEQ_START_TOKEN)
494 seq_printf(seq, "%10s %15s %8s %8s %s\n",
495 "Seq#", "Tstamp", "Level", "Facility", "Message");
497 struct devlog_info *dinfo = seq->private;
498 int fidx = (uintptr_t)v - 2;
500 struct fw_devlog_e *e;
502 /* Get a pointer to the log entry to display. Skip unused log
505 index = dinfo->first + fidx;
506 if (index >= dinfo->nentries)
507 index -= dinfo->nentries;
508 e = &dinfo->log[index];
509 if (e->timestamp == 0)
512 /* Print the message. This depends on the firmware using
513 * exactly the same formating strings as the kernel so we may
514 * eventually have to put a format interpreter in here ...
516 seq_printf(seq, "%10d %15llu %8s %8s ",
517 e->seqno, e->timestamp,
518 (e->level < ARRAY_SIZE(devlog_level_strings)
519 ? devlog_level_strings[e->level]
521 (e->facility < ARRAY_SIZE(devlog_facility_strings)
522 ? devlog_facility_strings[e->facility]
524 seq_printf(seq, e->fmt, e->params[0], e->params[1],
525 e->params[2], e->params[3], e->params[4],
526 e->params[5], e->params[6], e->params[7]);
531 /* Sequential File Operations for Device Log.
533 static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
535 if (pos > dinfo->nentries)
538 return (void *)(uintptr_t)(pos + 1);
541 static void *devlog_start(struct seq_file *seq, loff_t *pos)
543 struct devlog_info *dinfo = seq->private;
546 ? devlog_get_idx(dinfo, *pos)
550 static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
552 struct devlog_info *dinfo = seq->private;
555 return devlog_get_idx(dinfo, *pos);
558 static void devlog_stop(struct seq_file *seq, void *v)
562 static const struct seq_operations devlog_seq_ops = {
563 .start = devlog_start,
569 /* Set up for reading the firmware's device log. We read the entire log here
570 * and then display it incrementally in devlog_show().
572 static int devlog_open(struct inode *inode, struct file *file)
574 struct adapter *adap = inode->i_private;
575 struct devlog_params *dparams = &adap->params.devlog;
576 struct devlog_info *dinfo;
581 /* If we don't know where the log is we can't do anything.
583 if (dparams->start == 0)
586 /* Allocate the space to read in the firmware's device log and set up
587 * for the iterated call to our display function.
589 dinfo = __seq_open_private(file, &devlog_seq_ops,
590 sizeof(*dinfo) + dparams->size);
594 /* Record the basic log buffer information and read in the raw log.
596 dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
598 spin_lock(&adap->win0_lock);
599 ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
600 dparams->start, dparams->size, (__be32 *)dinfo->log,
602 spin_unlock(&adap->win0_lock);
604 seq_release_private(inode, file);
608 /* Translate log multi-byte integral elements into host native format
609 * and determine where the first entry in the log is.
611 for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
612 struct fw_devlog_e *e = &dinfo->log[index];
616 if (e->timestamp == 0)
619 e->timestamp = (__force __be64)be64_to_cpu(e->timestamp);
620 seqno = be32_to_cpu(e->seqno);
621 for (i = 0; i < 8; i++)
623 (__force __be32)be32_to_cpu(e->params[i]);
625 if (seqno < fseqno) {
627 dinfo->first = index;
633 static const struct file_operations devlog_fops = {
634 .owner = THIS_MODULE,
638 .release = seq_release_private
641 static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
645 loff_t avail = FILE_DATA(file)->i_size;
646 struct adapter *adap = file->private_data;
652 if (count > avail - pos)
661 len = min(count + ofst, sizeof(data));
662 ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
668 if (copy_to_user(buf, data + ofst, len))
680 static const struct file_operations flash_debugfs_fops = {
681 .owner = THIS_MODULE,
686 static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
689 y = (__force u64)cpu_to_be64(y);
690 memcpy(addr, (char *)&y + 2, ETH_ALEN);
693 static int mps_tcam_show(struct seq_file *seq, void *v)
695 if (v == SEQ_START_TOKEN)
696 seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF"
702 struct adapter *adap = seq->private;
703 unsigned int idx = (uintptr_t)v - 2;
704 u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
705 u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
706 u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
707 u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
708 u32 rplc[4] = {0, 0, 0, 0};
711 seq_printf(seq, "%3u -\n", idx);
715 if (cls_lo & REPLICATE_F) {
716 struct fw_ldst_cmd ldst_cmd;
719 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
720 ldst_cmd.op_to_addrspace =
721 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
724 FW_LDST_CMD_ADDRSPACE_V(
725 FW_LDST_ADDRSPC_MPS));
726 ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
727 ldst_cmd.u.mps.fid_ctl =
728 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
729 FW_LDST_CMD_CTL_V(idx));
730 ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
731 sizeof(ldst_cmd), &ldst_cmd);
733 dev_warn(adap->pdev_dev, "Can't read MPS "
734 "replication map for idx %d: %d\n",
737 rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0);
738 rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32);
739 rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64);
740 rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96);
744 tcamxy2valmask(tcamx, tcamy, addr, &mask);
745 seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx"
747 idx, addr[0], addr[1], addr[2], addr[3], addr[4],
748 addr[5], (unsigned long long)mask,
749 (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi),
751 (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
752 if (cls_lo & REPLICATE_F)
753 seq_printf(seq, " %08x %08x %08x %08x",
754 rplc[3], rplc[2], rplc[1], rplc[0]);
756 seq_printf(seq, "%36c", ' ');
757 seq_printf(seq, "%4u%3u%3u%3u %#x\n",
758 SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
759 SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
760 (cls_lo >> MULTILISTEN0_S) & 0xf);
765 static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
767 struct adapter *adap = seq->private;
768 int max_mac_addr = is_t4(adap->params.chip) ?
769 NUM_MPS_CLS_SRAM_L_INSTANCES :
770 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
771 return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
774 static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
776 return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
779 static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
782 return mps_tcam_get_idx(seq, *pos);
785 static void mps_tcam_stop(struct seq_file *seq, void *v)
789 static const struct seq_operations mps_tcam_seq_ops = {
790 .start = mps_tcam_start,
791 .next = mps_tcam_next,
792 .stop = mps_tcam_stop,
793 .show = mps_tcam_show
796 static int mps_tcam_open(struct inode *inode, struct file *file)
798 int res = seq_open(file, &mps_tcam_seq_ops);
801 struct seq_file *seq = file->private_data;
803 seq->private = inode->i_private;
808 static const struct file_operations mps_tcam_debugfs_fops = {
809 .owner = THIS_MODULE,
810 .open = mps_tcam_open,
813 .release = seq_release,
816 #if IS_ENABLED(CONFIG_IPV6)
817 static int clip_tbl_open(struct inode *inode, struct file *file)
819 return single_open(file, clip_tbl_show, PDE_DATA(inode));
822 static const struct file_operations clip_tbl_debugfs_fops = {
823 .owner = THIS_MODULE,
824 .open = clip_tbl_open,
827 .release = single_release
834 static int rss_show(struct seq_file *seq, void *v, int idx)
838 seq_printf(seq, "%4d: %4u %4u %4u %4u %4u %4u %4u %4u\n",
839 idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
840 entry[5], entry[6], entry[7]);
844 static int rss_open(struct inode *inode, struct file *file)
848 struct adapter *adap = inode->i_private;
850 p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
854 ret = t4_read_rss(adap, (u16 *)p->data);
856 seq_release_private(inode, file);
861 static const struct file_operations rss_debugfs_fops = {
862 .owner = THIS_MODULE,
866 .release = seq_release_private
869 /* RSS Configuration.
872 /* Small utility function to return the strings "yes" or "no" if the supplied
873 * argument is non-zero.
875 static const char *yesno(int x)
877 static const char *yes = "yes";
878 static const char *no = "no";
883 static int rss_config_show(struct seq_file *seq, void *v)
885 struct adapter *adapter = seq->private;
886 static const char * const keymode[] = {
888 "global and per-VF scramble",
889 "per-PF and per-VF scramble",
890 "per-VF and per-VF scramble",
894 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
895 seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
896 seq_printf(seq, " Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
898 seq_printf(seq, " Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
900 seq_printf(seq, " Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
902 seq_printf(seq, " Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
904 seq_printf(seq, " TnlTcpSel: %3s\n", yesno(rssconf & TNLTCPSEL_F));
905 seq_printf(seq, " TnlIp6Sel: %3s\n", yesno(rssconf & TNLIP6SEL_F));
906 seq_printf(seq, " TnlVrtSel: %3s\n", yesno(rssconf & TNLVRTSEL_F));
907 seq_printf(seq, " TnlMapEn: %3s\n", yesno(rssconf & TNLMAPEN_F));
908 seq_printf(seq, " OfdHashSave: %3s\n", yesno(rssconf &
910 seq_printf(seq, " OfdVrtSel: %3s\n", yesno(rssconf & OFDVRTSEL_F));
911 seq_printf(seq, " OfdMapEn: %3s\n", yesno(rssconf & OFDMAPEN_F));
912 seq_printf(seq, " OfdLkpEn: %3s\n", yesno(rssconf & OFDLKPEN_F));
913 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
915 seq_printf(seq, " Syn2TupEnIpv6: %3s\n", yesno(rssconf &
917 seq_printf(seq, " Syn4TupEnIpv4: %3s\n", yesno(rssconf &
919 seq_printf(seq, " Syn2TupEnIpv4: %3s\n", yesno(rssconf &
921 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
923 seq_printf(seq, " SynIp6Sel: %3s\n", yesno(rssconf & SYNIP6SEL_F));
924 seq_printf(seq, " SynVrt6Sel: %3s\n", yesno(rssconf & SYNVRTSEL_F));
925 seq_printf(seq, " SynMapEn: %3s\n", yesno(rssconf & SYNMAPEN_F));
926 seq_printf(seq, " SynLkpEn: %3s\n", yesno(rssconf & SYNLKPEN_F));
927 seq_printf(seq, " ChnEn: %3s\n", yesno(rssconf &
929 seq_printf(seq, " PrtEn: %3s\n", yesno(rssconf &
931 seq_printf(seq, " TnlAllLkp: %3s\n", yesno(rssconf &
933 seq_printf(seq, " VrtEn: %3s\n", yesno(rssconf &
935 seq_printf(seq, " CngEn: %3s\n", yesno(rssconf &
936 CONGESTIONENABLE_F));
937 seq_printf(seq, " HashToeplitz: %3s\n", yesno(rssconf &
939 seq_printf(seq, " Udp4En: %3s\n", yesno(rssconf & UDPENABLE_F));
940 seq_printf(seq, " Disable: %3s\n", yesno(rssconf & DISABLE_F));
944 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
945 seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
946 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
947 seq_printf(seq, " MaskFilter: %3d\n", MASKFILTER_G(rssconf));
948 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
949 seq_printf(seq, " HashAll: %3s\n",
950 yesno(rssconf & HASHALL_F));
951 seq_printf(seq, " HashEth: %3s\n",
952 yesno(rssconf & HASHETH_F));
954 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
958 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
959 seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
960 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
961 seq_printf(seq, " RRCplMapEn: %3s\n", yesno(rssconf &
963 seq_printf(seq, " RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
967 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
968 seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
969 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
970 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
974 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
975 seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
976 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
977 seq_printf(seq, " KeyWrAddrX: %3d\n",
978 KEYWRADDRX_G(rssconf));
979 seq_printf(seq, " KeyExtend: %3s\n",
980 yesno(rssconf & KEYEXTEND_F));
982 seq_printf(seq, " VfRdRg: %3s\n", yesno(rssconf & VFRDRG_F));
983 seq_printf(seq, " VfRdEn: %3s\n", yesno(rssconf & VFRDEN_F));
984 seq_printf(seq, " VfPerrEn: %3s\n", yesno(rssconf & VFPERREN_F));
985 seq_printf(seq, " KeyPerrEn: %3s\n", yesno(rssconf & KEYPERREN_F));
986 seq_printf(seq, " DisVfVlan: %3s\n", yesno(rssconf &
988 seq_printf(seq, " EnUpSwt: %3s\n", yesno(rssconf & ENABLEUP0_F));
989 seq_printf(seq, " HashDelay: %3d\n", HASHDELAY_G(rssconf));
990 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
991 seq_printf(seq, " VfWrAddr: %3d\n", VFWRADDR_G(rssconf));
992 seq_printf(seq, " KeyMode: %s\n", keymode[KEYMODE_G(rssconf)]);
993 seq_printf(seq, " VfWrEn: %3s\n", yesno(rssconf & VFWREN_F));
994 seq_printf(seq, " KeyWrEn: %3s\n", yesno(rssconf & KEYWREN_F));
995 seq_printf(seq, " KeyWrAddr: %3d\n", KEYWRADDR_G(rssconf));
999 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
1000 seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
1001 seq_printf(seq, " ChnCount3: %3s\n", yesno(rssconf & CHNCOUNT3_F));
1002 seq_printf(seq, " ChnCount2: %3s\n", yesno(rssconf & CHNCOUNT2_F));
1003 seq_printf(seq, " ChnCount1: %3s\n", yesno(rssconf & CHNCOUNT1_F));
1004 seq_printf(seq, " ChnCount0: %3s\n", yesno(rssconf & CHNCOUNT0_F));
1005 seq_printf(seq, " ChnUndFlow3: %3s\n", yesno(rssconf &
1007 seq_printf(seq, " ChnUndFlow2: %3s\n", yesno(rssconf &
1009 seq_printf(seq, " ChnUndFlow1: %3s\n", yesno(rssconf &
1011 seq_printf(seq, " ChnUndFlow0: %3s\n", yesno(rssconf &
1013 seq_printf(seq, " RstChn3: %3s\n", yesno(rssconf & RSTCHN3_F));
1014 seq_printf(seq, " RstChn2: %3s\n", yesno(rssconf & RSTCHN2_F));
1015 seq_printf(seq, " RstChn1: %3s\n", yesno(rssconf & RSTCHN1_F));
1016 seq_printf(seq, " RstChn0: %3s\n", yesno(rssconf & RSTCHN0_F));
1017 seq_printf(seq, " UpdVld: %3s\n", yesno(rssconf & UPDVLD_F));
1018 seq_printf(seq, " Xoff: %3s\n", yesno(rssconf & XOFF_F));
1019 seq_printf(seq, " UpdChn3: %3s\n", yesno(rssconf & UPDCHN3_F));
1020 seq_printf(seq, " UpdChn2: %3s\n", yesno(rssconf & UPDCHN2_F));
1021 seq_printf(seq, " UpdChn1: %3s\n", yesno(rssconf & UPDCHN1_F));
1022 seq_printf(seq, " UpdChn0: %3s\n", yesno(rssconf & UPDCHN0_F));
1023 seq_printf(seq, " Queue: %3d\n", QUEUE_G(rssconf));
1028 DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
1033 static int rss_key_show(struct seq_file *seq, void *v)
1037 t4_read_rss_key(seq->private, key);
1038 seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1039 key[9], key[8], key[7], key[6], key[5], key[4], key[3],
1040 key[2], key[1], key[0]);
1044 static int rss_key_open(struct inode *inode, struct file *file)
1046 return single_open(file, rss_key_show, inode->i_private);
1049 static ssize_t rss_key_write(struct file *file, const char __user *buf,
1050 size_t count, loff_t *pos)
1055 struct adapter *adap = FILE_DATA(file)->i_private;
1057 if (count > sizeof(s) - 1)
1059 if (copy_from_user(s, buf, count))
1061 for (i = count; i > 0 && isspace(s[i - 1]); i--)
1065 for (p = s, i = 9; i >= 0; i--) {
1067 for (j = 0; j < 8; j++, p++) {
1070 key[i] = (key[i] << 4) | hex2val(*p);
1074 t4_write_rss_key(adap, key, -1);
1078 static const struct file_operations rss_key_debugfs_fops = {
1079 .owner = THIS_MODULE,
1080 .open = rss_key_open,
1082 .llseek = seq_lseek,
1083 .release = single_release,
1084 .write = rss_key_write
1087 /* PF RSS Configuration.
1090 struct rss_pf_conf {
1096 static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
1098 struct rss_pf_conf *pfconf;
1100 if (v == SEQ_START_TOKEN) {
1101 /* use the 0th entry to dump the PF Map Index Size */
1102 pfconf = seq->private + offsetof(struct seq_tab, data);
1103 seq_printf(seq, "PF Map Index Size = %d\n\n",
1104 LKPIDXSIZE_G(pfconf->rss_pf_map));
1106 seq_puts(seq, " RSS PF VF Hash Tuple Enable Default\n");
1107 seq_puts(seq, " Enable IPF Mask Mask IPv6 IPv4 UDP Queue\n");
1108 seq_puts(seq, " PF Map Chn Prt Map Size Size Four Two Four Two Four Ch1 Ch0\n");
1110 #define G_PFnLKPIDX(map, n) \
1111 (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
1112 #define G_PFnMSKSIZE(mask, n) \
1113 (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
1116 seq_printf(seq, "%3d %3s %3s %3s %3d %3d %3d %3s %3s %3s %3s %3s %3d %3d\n",
1118 yesno(pfconf->rss_pf_config & MAPENABLE_F),
1119 yesno(pfconf->rss_pf_config & CHNENABLE_F),
1120 yesno(pfconf->rss_pf_config & PRTENABLE_F),
1121 G_PFnLKPIDX(pfconf->rss_pf_map, idx),
1122 G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
1123 IVFWIDTH_G(pfconf->rss_pf_config),
1124 yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
1125 yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
1126 yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
1127 yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
1128 yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
1129 CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
1130 CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
1138 static int rss_pf_config_open(struct inode *inode, struct file *file)
1140 struct adapter *adapter = inode->i_private;
1142 u32 rss_pf_map, rss_pf_mask;
1143 struct rss_pf_conf *pfconf;
1146 p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
1150 pfconf = (struct rss_pf_conf *)p->data;
1151 rss_pf_map = t4_read_rss_pf_map(adapter);
1152 rss_pf_mask = t4_read_rss_pf_mask(adapter);
1153 for (pf = 0; pf < 8; pf++) {
1154 pfconf[pf].rss_pf_map = rss_pf_map;
1155 pfconf[pf].rss_pf_mask = rss_pf_mask;
1156 t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
1161 static const struct file_operations rss_pf_config_debugfs_fops = {
1162 .owner = THIS_MODULE,
1163 .open = rss_pf_config_open,
1165 .llseek = seq_lseek,
1166 .release = seq_release_private
1169 /* VF RSS Configuration.
1172 struct rss_vf_conf {
1177 static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
1179 if (v == SEQ_START_TOKEN) {
1180 seq_puts(seq, " RSS Hash Tuple Enable\n");
1181 seq_puts(seq, " Enable IVF Dis Enb IPv6 IPv4 UDP Def Secret Key\n");
1182 seq_puts(seq, " VF Chn Prt Map VLAN uP Four Two Four Two Four Que Idx Hash\n");
1184 struct rss_vf_conf *vfconf = v;
1186 seq_printf(seq, "%3d %3s %3s %3d %3s %3s %3s %3s %3s %3s %3s %4d %3d %#10x\n",
1188 yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
1189 yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
1190 VFLKPIDX_G(vfconf->rss_vf_vfh),
1191 yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
1192 yesno(vfconf->rss_vf_vfh & VFUPEN_F),
1193 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1194 yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
1195 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1196 yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
1197 yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
1198 DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
1199 KEYINDEX_G(vfconf->rss_vf_vfh),
1200 vfconf->rss_vf_vfl);
1205 static int rss_vf_config_open(struct inode *inode, struct file *file)
1207 struct adapter *adapter = inode->i_private;
1209 struct rss_vf_conf *vfconf;
1212 p = seq_open_tab(file, 128, sizeof(*vfconf), 1, rss_vf_config_show);
1216 vfconf = (struct rss_vf_conf *)p->data;
1217 for (vf = 0; vf < 128; vf++) {
1218 t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
1219 &vfconf[vf].rss_vf_vfh);
1224 static const struct file_operations rss_vf_config_debugfs_fops = {
1225 .owner = THIS_MODULE,
1226 .open = rss_vf_config_open,
1228 .llseek = seq_lseek,
1229 .release = seq_release_private
1233 * ethqset2pinfo - return port_info of an Ethernet Queue Set
1234 * @adap: the adapter
1235 * @qset: Ethernet Queue Set
1237 static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
1241 for_each_port(adap, pidx) {
1242 struct port_info *pi = adap2pinfo(adap, pidx);
1244 if (qset >= pi->first_qset &&
1245 qset < pi->first_qset + pi->nqsets)
1249 /* should never happen! */
1254 static int sge_qinfo_show(struct seq_file *seq, void *v)
1256 struct adapter *adap = seq->private;
1257 int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
1258 int toe_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
1259 int rdma_entries = DIV_ROUND_UP(adap->sge.rdmaqs, 4);
1260 int ciq_entries = DIV_ROUND_UP(adap->sge.rdmaciqs, 4);
1261 int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
1262 int i, r = (uintptr_t)v - 1;
1263 int toe_idx = r - eth_entries;
1264 int rdma_idx = toe_idx - toe_entries;
1265 int ciq_idx = rdma_idx - rdma_entries;
1266 int ctrl_idx = ciq_idx - ciq_entries;
1267 int fq_idx = ctrl_idx - ctrl_entries;
1270 seq_putc(seq, '\n');
1272 #define S3(fmt_spec, s, v) \
1274 seq_printf(seq, "%-12s", s); \
1275 for (i = 0; i < n; ++i) \
1276 seq_printf(seq, " %16" fmt_spec, v); \
1277 seq_putc(seq, '\n'); \
1279 #define S(s, v) S3("s", s, v)
1280 #define T(s, v) S3("u", s, tx[i].v)
1281 #define R(s, v) S3("u", s, rx[i].v)
1283 if (r < eth_entries) {
1284 int base_qset = r * 4;
1285 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
1286 const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
1287 int n = min(4, adap->sge.ethqsets - 4 * r);
1289 S("QType:", "Ethernet");
1291 rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1292 T("TxQ ID:", q.cntxt_id);
1293 T("TxQ size:", q.size);
1294 T("TxQ inuse:", q.in_use);
1295 T("TxQ CIDX:", q.cidx);
1296 T("TxQ PIDX:", q.pidx);
1297 #ifdef CONFIG_CHELSIO_T4_DCB
1298 T("DCB Prio:", dcb_prio);
1299 S3("u", "DCB PGID:",
1300 (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
1301 4*(7-tx[i].dcb_prio)) & 0xf);
1303 (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
1304 1*(7-tx[i].dcb_prio)) & 0x1);
1306 R("RspQ ID:", rspq.abs_id);
1307 R("RspQ size:", rspq.size);
1308 R("RspQE size:", rspq.iqe_len);
1309 R("RspQ CIDX:", rspq.cidx);
1310 R("RspQ Gen:", rspq.gen);
1311 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1312 S3("u", "Intr pktcnt:",
1313 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1314 R("FL ID:", fl.cntxt_id);
1315 R("FL size:", fl.size - 8);
1316 R("FL pend:", fl.pend_cred);
1317 R("FL avail:", fl.avail);
1318 R("FL PIDX:", fl.pidx);
1319 R("FL CIDX:", fl.cidx);
1320 } else if (toe_idx < toe_entries) {
1321 const struct sge_ofld_rxq *rx = &adap->sge.ofldrxq[toe_idx * 4];
1322 const struct sge_ofld_txq *tx = &adap->sge.ofldtxq[toe_idx * 4];
1323 int n = min(4, adap->sge.ofldqsets - 4 * toe_idx);
1326 T("TxQ ID:", q.cntxt_id);
1327 T("TxQ size:", q.size);
1328 T("TxQ inuse:", q.in_use);
1329 T("TxQ CIDX:", q.cidx);
1330 T("TxQ PIDX:", q.pidx);
1331 R("RspQ ID:", rspq.abs_id);
1332 R("RspQ size:", rspq.size);
1333 R("RspQE size:", rspq.iqe_len);
1334 R("RspQ CIDX:", rspq.cidx);
1335 R("RspQ Gen:", rspq.gen);
1336 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1337 S3("u", "Intr pktcnt:",
1338 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1339 R("FL ID:", fl.cntxt_id);
1340 R("FL size:", fl.size - 8);
1341 R("FL pend:", fl.pend_cred);
1342 R("FL avail:", fl.avail);
1343 R("FL PIDX:", fl.pidx);
1344 R("FL CIDX:", fl.cidx);
1345 } else if (rdma_idx < rdma_entries) {
1346 const struct sge_ofld_rxq *rx =
1347 &adap->sge.rdmarxq[rdma_idx * 4];
1348 int n = min(4, adap->sge.rdmaqs - 4 * rdma_idx);
1350 S("QType:", "RDMA-CPL");
1351 R("RspQ ID:", rspq.abs_id);
1352 R("RspQ size:", rspq.size);
1353 R("RspQE size:", rspq.iqe_len);
1354 R("RspQ CIDX:", rspq.cidx);
1355 R("RspQ Gen:", rspq.gen);
1356 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1357 S3("u", "Intr pktcnt:",
1358 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1359 R("FL ID:", fl.cntxt_id);
1360 R("FL size:", fl.size - 8);
1361 R("FL pend:", fl.pend_cred);
1362 R("FL avail:", fl.avail);
1363 R("FL PIDX:", fl.pidx);
1364 R("FL CIDX:", fl.cidx);
1365 } else if (ciq_idx < ciq_entries) {
1366 const struct sge_ofld_rxq *rx = &adap->sge.rdmaciq[ciq_idx * 4];
1367 int n = min(4, adap->sge.rdmaciqs - 4 * ciq_idx);
1369 S("QType:", "RDMA-CIQ");
1370 R("RspQ ID:", rspq.abs_id);
1371 R("RspQ size:", rspq.size);
1372 R("RspQE size:", rspq.iqe_len);
1373 R("RspQ CIDX:", rspq.cidx);
1374 R("RspQ Gen:", rspq.gen);
1375 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1376 S3("u", "Intr pktcnt:",
1377 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1378 } else if (ctrl_idx < ctrl_entries) {
1379 const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
1380 int n = min(4, adap->params.nports - 4 * ctrl_idx);
1382 S("QType:", "Control");
1383 T("TxQ ID:", q.cntxt_id);
1384 T("TxQ size:", q.size);
1385 T("TxQ inuse:", q.in_use);
1386 T("TxQ CIDX:", q.cidx);
1387 T("TxQ PIDX:", q.pidx);
1388 } else if (fq_idx == 0) {
1389 const struct sge_rspq *evtq = &adap->sge.fw_evtq;
1391 seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
1392 seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
1393 seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
1394 seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
1395 seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
1396 seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
1397 seq_printf(seq, "%-12s %16u\n", "Intr delay:",
1398 qtimer_val(adap, evtq));
1399 seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
1400 adap->sge.counter_val[evtq->pktcnt_idx]);
1409 static int sge_queue_entries(const struct adapter *adap)
1411 return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
1412 DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
1413 DIV_ROUND_UP(adap->sge.rdmaqs, 4) +
1414 DIV_ROUND_UP(adap->sge.rdmaciqs, 4) +
1415 DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
1418 static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
1420 int entries = sge_queue_entries(seq->private);
1422 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1425 static void sge_queue_stop(struct seq_file *seq, void *v)
1429 static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
1431 int entries = sge_queue_entries(seq->private);
1434 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1437 static const struct seq_operations sge_qinfo_seq_ops = {
1438 .start = sge_queue_start,
1439 .next = sge_queue_next,
1440 .stop = sge_queue_stop,
1441 .show = sge_qinfo_show
1444 static int sge_qinfo_open(struct inode *inode, struct file *file)
1446 int res = seq_open(file, &sge_qinfo_seq_ops);
1449 struct seq_file *seq = file->private_data;
1451 seq->private = inode->i_private;
1456 static const struct file_operations sge_qinfo_debugfs_fops = {
1457 .owner = THIS_MODULE,
1458 .open = sge_qinfo_open,
1460 .llseek = seq_lseek,
1461 .release = seq_release,
1464 int mem_open(struct inode *inode, struct file *file)
1467 struct adapter *adap;
1469 file->private_data = inode->i_private;
1471 mem = (uintptr_t)file->private_data & 0x3;
1472 adap = file->private_data - mem;
1474 (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
1479 static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
1483 loff_t avail = file_inode(file)->i_size;
1484 unsigned int mem = (uintptr_t)file->private_data & 3;
1485 struct adapter *adap = file->private_data - mem;
1493 if (count > avail - pos)
1494 count = avail - pos;
1496 data = t4_alloc_mem(count);
1500 spin_lock(&adap->win0_lock);
1501 ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
1502 spin_unlock(&adap->win0_lock);
1507 ret = copy_to_user(buf, data, count);
1513 *ppos = pos + count;
1516 static const struct file_operations mem_debugfs_fops = {
1517 .owner = THIS_MODULE,
1518 .open = simple_open,
1520 .llseek = default_llseek,
1523 static void set_debugfs_file_size(struct dentry *de, loff_t size)
1525 if (!IS_ERR(de) && de->d_inode)
1526 de->d_inode->i_size = size;
1529 static void add_debugfs_mem(struct adapter *adap, const char *name,
1530 unsigned int idx, unsigned int size_mb)
1534 de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root,
1535 (void *)adap + idx, &mem_debugfs_fops);
1536 if (de && de->d_inode)
1537 de->d_inode->i_size = size_mb << 20;
1540 /* Add an array of Debug FS files.
1542 void add_debugfs_files(struct adapter *adap,
1543 struct t4_debugfs_entry *files,
1544 unsigned int nfiles)
1548 /* debugfs support is best effort */
1549 for (i = 0; i < nfiles; i++)
1550 debugfs_create_file(files[i].name, files[i].mode,
1552 (void *)adap + files[i].data,
1556 int t4_setup_debugfs(struct adapter *adap)
1562 static struct t4_debugfs_entry t4_debugfs_files[] = {
1563 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
1564 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
1565 { "clk", &clk_debugfs_fops, S_IRUSR, 0 },
1566 { "devlog", &devlog_fops, S_IRUSR, 0 },
1567 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
1568 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
1569 { "rss", &rss_debugfs_fops, S_IRUSR, 0 },
1570 { "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
1571 { "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
1572 { "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
1573 { "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
1574 { "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
1575 { "ibq_tp0", &cim_ibq_fops, S_IRUSR, 0 },
1576 { "ibq_tp1", &cim_ibq_fops, S_IRUSR, 1 },
1577 { "ibq_ulp", &cim_ibq_fops, S_IRUSR, 2 },
1578 { "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
1579 { "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
1580 { "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
1581 { "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
1582 { "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
1583 { "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
1584 { "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
1585 { "obq_sge", &cim_obq_fops, S_IRUSR, 4 },
1586 { "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
1587 { "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
1588 #if IS_ENABLED(CONFIG_IPV6)
1589 { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
1593 /* Debug FS nodes common to all T5 and later adapters.
1595 static struct t4_debugfs_entry t5_debugfs_files[] = {
1596 { "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
1597 { "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
1600 add_debugfs_files(adap,
1602 ARRAY_SIZE(t4_debugfs_files));
1603 if (!is_t4(adap->params.chip))
1604 add_debugfs_files(adap,
1606 ARRAY_SIZE(t5_debugfs_files));
1608 i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
1609 if (i & EDRAM0_ENABLE_F) {
1610 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
1611 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
1613 if (i & EDRAM1_ENABLE_F) {
1614 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
1615 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
1617 if (is_t4(adap->params.chip)) {
1618 size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
1619 if (i & EXT_MEM_ENABLE_F)
1620 add_debugfs_mem(adap, "mc", MEM_MC,
1621 EXT_MEM_SIZE_G(size));
1623 if (i & EXT_MEM0_ENABLE_F) {
1624 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
1625 add_debugfs_mem(adap, "mc0", MEM_MC0,
1626 EXT_MEM0_SIZE_G(size));
1628 if (i & EXT_MEM1_ENABLE_F) {
1629 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
1630 add_debugfs_mem(adap, "mc1", MEM_MC1,
1631 EXT_MEM1_SIZE_G(size));
1635 de = debugfs_create_file("flash", S_IRUSR, adap->debugfs_root, adap,
1636 &flash_debugfs_fops);
1637 set_debugfs_file_size(de, adap->params.sf_size);