]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
cxgb4: Addded support in debugfs to dump CIM outbound queue content
[thirdparty/kernel/stable.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_debugfs.c
CommitLineData
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>
688ea5fe 39#include <linux/ctype.h>
fd88b31a
HS
40
41#include "cxgb4.h"
42#include "t4_regs.h"
43#include "t4fw_api.h"
44#include "cxgb4_debugfs.h"
b5a02f50 45#include "clip_tbl.h"
fd88b31a
HS
46#include "l2t.h"
47
f1ff24aa
HS
48/* generic seq_file support for showing a table of size rows x width. */
49static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
50{
51 pos -= tb->skip_first;
52 return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
53}
54
55static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
56{
57 struct seq_tab *tb = seq->private;
58
59 if (tb->skip_first && *pos == 0)
60 return SEQ_START_TOKEN;
61
62 return seq_tab_get_idx(tb, *pos);
63}
64
65static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
66{
67 v = seq_tab_get_idx(seq->private, *pos + 1);
68 if (v)
69 ++*pos;
70 return v;
71}
72
73static void seq_tab_stop(struct seq_file *seq, void *v)
74{
75}
76
77static int seq_tab_show(struct seq_file *seq, void *v)
78{
79 const struct seq_tab *tb = seq->private;
80
81 return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
82}
83
84static const struct seq_operations seq_tab_ops = {
85 .start = seq_tab_start,
86 .next = seq_tab_next,
87 .stop = seq_tab_stop,
88 .show = seq_tab_show
89};
90
91struct 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))
94{
95 struct seq_tab *p;
96
97 p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
98 if (p) {
99 p->show = show;
100 p->rows = rows;
101 p->width = width;
102 p->skip_first = have_header != 0;
103 }
104 return p;
105}
106
c778af7d
HS
107/* Trim the size of a seq_tab to the supplied number of rows. The operation is
108 * irreversible.
109 */
110static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
111{
112 if (new_rows > p->rows)
113 return -EINVAL;
114 p->rows = new_rows;
115 return 0;
116}
117
f1ff24aa
HS
118static int cim_la_show(struct seq_file *seq, void *v, int idx)
119{
120 if (v == SEQ_START_TOKEN)
121 seq_puts(seq, "Status Data PC LS0Stat LS0Addr "
122 " LS0Data\n");
123 else {
124 const u32 *p = v;
125
126 seq_printf(seq,
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],
130 p[6], p[7]);
131 }
132 return 0;
133}
134
135static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
136{
137 if (v == SEQ_START_TOKEN) {
138 seq_puts(seq, "Status Data PC\n");
139 } else {
140 const u32 *p = v;
141
142 seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6],
143 p[7]);
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);
149 }
150 return 0;
151}
152
153static int cim_la_open(struct inode *inode, struct file *file)
154{
155 int ret;
156 unsigned int cfg;
157 struct seq_tab *p;
158 struct adapter *adap = inode->i_private;
159
160 ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
161 if (ret)
162 return ret;
163
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);
167 if (!p)
168 return -ENOMEM;
169
170 ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
171 if (ret)
172 seq_release_private(inode, file);
173 return ret;
174}
175
176static const struct file_operations cim_la_fops = {
177 .owner = THIS_MODULE,
178 .open = cim_la_open,
179 .read = seq_read,
180 .llseek = seq_lseek,
181 .release = seq_release_private
182};
183
74b3092c
HS
184static int cim_qcfg_show(struct seq_file *seq, void *v)
185{
186 static const char * const qname[] = {
187 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
188 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
189 "SGE0-RX", "SGE1-RX"
190 };
191
192 int i;
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];
200 u32 *p = stat;
201 int cim_num_obq = is_t4(adap->params.chip) ?
202 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
203
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);
207 if (!i) {
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);
211 wr = obq_wr_t4;
212 } else {
213 i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
214 ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
215 wr = obq_wr_t5;
216 }
217 }
218 if (i)
219 return i;
220
221 t4_read_cimq_cfg(adap, base, size, thres);
222
223 seq_printf(seq,
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);
237 return 0;
238}
239
240static int cim_qcfg_open(struct inode *inode, struct file *file)
241{
242 return single_open(file, cim_qcfg_show, inode->i_private);
243}
244
245static const struct file_operations cim_qcfg_fops = {
246 .owner = THIS_MODULE,
247 .open = cim_qcfg_open,
248 .read = seq_read,
249 .llseek = seq_lseek,
250 .release = single_release,
251};
252
e5f0e43b
HS
253static int cimq_show(struct seq_file *seq, void *v, int idx)
254{
255 const u32 *p = v;
256
257 seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
258 p[2], p[3]);
259 return 0;
260}
261
262static int cim_ibq_open(struct inode *inode, struct file *file)
263{
264 int ret;
265 struct seq_tab *p;
266 unsigned int qid = (uintptr_t)inode->i_private & 7;
267 struct adapter *adap = inode->i_private - qid;
268
269 p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
270 if (!p)
271 return -ENOMEM;
272
273 ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
274 if (ret < 0)
275 seq_release_private(inode, file);
276 else
277 ret = 0;
278 return ret;
279}
280
281static const struct file_operations cim_ibq_fops = {
282 .owner = THIS_MODULE,
283 .open = cim_ibq_open,
284 .read = seq_read,
285 .llseek = seq_lseek,
286 .release = seq_release_private
287};
288
c778af7d
HS
289static int cim_obq_open(struct inode *inode, struct file *file)
290{
291 int ret;
292 struct seq_tab *p;
293 unsigned int qid = (uintptr_t)inode->i_private & 7;
294 struct adapter *adap = inode->i_private - qid;
295
296 p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
297 if (!p)
298 return -ENOMEM;
299
300 ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
301 if (ret < 0) {
302 seq_release_private(inode, file);
303 } else {
304 seq_tab_trim(p, ret / 4);
305 ret = 0;
306 }
307 return ret;
308}
309
310static const struct file_operations cim_obq_fops = {
311 .owner = THIS_MODULE,
312 .open = cim_obq_open,
313 .read = seq_read,
314 .llseek = seq_lseek,
315 .release = seq_release_private
316};
317
f1ff24aa 318/* Firmware Device Log dump. */
49aa284f
HS
319static const char * const devlog_level_strings[] = {
320 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
321 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
322 [FW_DEVLOG_LEVEL_ERR] = "ERR",
323 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
324 [FW_DEVLOG_LEVEL_INFO] = "INFO",
325 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
326};
327
328static const char * const devlog_facility_strings[] = {
329 [FW_DEVLOG_FACILITY_CORE] = "CORE",
330 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
331 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
332 [FW_DEVLOG_FACILITY_RES] = "RES",
333 [FW_DEVLOG_FACILITY_HW] = "HW",
334 [FW_DEVLOG_FACILITY_FLR] = "FLR",
335 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
336 [FW_DEVLOG_FACILITY_PHY] = "PHY",
337 [FW_DEVLOG_FACILITY_MAC] = "MAC",
338 [FW_DEVLOG_FACILITY_PORT] = "PORT",
339 [FW_DEVLOG_FACILITY_VI] = "VI",
340 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
341 [FW_DEVLOG_FACILITY_ACL] = "ACL",
342 [FW_DEVLOG_FACILITY_TM] = "TM",
343 [FW_DEVLOG_FACILITY_QFC] = "QFC",
344 [FW_DEVLOG_FACILITY_DCB] = "DCB",
345 [FW_DEVLOG_FACILITY_ETH] = "ETH",
346 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
347 [FW_DEVLOG_FACILITY_RI] = "RI",
348 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
349 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
350 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
351 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
352};
353
354/* Information gathered by Device Log Open routine for the display routine.
355 */
356struct devlog_info {
357 unsigned int nentries; /* number of entries in log[] */
358 unsigned int first; /* first [temporal] entry in log[] */
359 struct fw_devlog_e log[0]; /* Firmware Device Log */
360};
361
362/* Dump a Firmaware Device Log entry.
363 */
364static int devlog_show(struct seq_file *seq, void *v)
365{
366 if (v == SEQ_START_TOKEN)
367 seq_printf(seq, "%10s %15s %8s %8s %s\n",
368 "Seq#", "Tstamp", "Level", "Facility", "Message");
369 else {
370 struct devlog_info *dinfo = seq->private;
371 int fidx = (uintptr_t)v - 2;
372 unsigned long index;
373 struct fw_devlog_e *e;
374
375 /* Get a pointer to the log entry to display. Skip unused log
376 * entries.
377 */
378 index = dinfo->first + fidx;
379 if (index >= dinfo->nentries)
380 index -= dinfo->nentries;
381 e = &dinfo->log[index];
382 if (e->timestamp == 0)
383 return 0;
384
385 /* Print the message. This depends on the firmware using
386 * exactly the same formating strings as the kernel so we may
387 * eventually have to put a format interpreter in here ...
388 */
389 seq_printf(seq, "%10d %15llu %8s %8s ",
390 e->seqno, e->timestamp,
391 (e->level < ARRAY_SIZE(devlog_level_strings)
392 ? devlog_level_strings[e->level]
393 : "UNKNOWN"),
394 (e->facility < ARRAY_SIZE(devlog_facility_strings)
395 ? devlog_facility_strings[e->facility]
396 : "UNKNOWN"));
397 seq_printf(seq, e->fmt, e->params[0], e->params[1],
398 e->params[2], e->params[3], e->params[4],
399 e->params[5], e->params[6], e->params[7]);
400 }
401 return 0;
402}
403
404/* Sequential File Operations for Device Log.
405 */
406static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
407{
408 if (pos > dinfo->nentries)
409 return NULL;
410
411 return (void *)(uintptr_t)(pos + 1);
412}
413
414static void *devlog_start(struct seq_file *seq, loff_t *pos)
415{
416 struct devlog_info *dinfo = seq->private;
417
418 return (*pos
419 ? devlog_get_idx(dinfo, *pos)
420 : SEQ_START_TOKEN);
421}
422
423static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
424{
425 struct devlog_info *dinfo = seq->private;
426
427 (*pos)++;
428 return devlog_get_idx(dinfo, *pos);
429}
430
431static void devlog_stop(struct seq_file *seq, void *v)
432{
433}
434
435static const struct seq_operations devlog_seq_ops = {
436 .start = devlog_start,
437 .next = devlog_next,
438 .stop = devlog_stop,
439 .show = devlog_show
440};
441
442/* Set up for reading the firmware's device log. We read the entire log here
443 * and then display it incrementally in devlog_show().
444 */
445static int devlog_open(struct inode *inode, struct file *file)
446{
447 struct adapter *adap = inode->i_private;
448 struct devlog_params *dparams = &adap->params.devlog;
449 struct devlog_info *dinfo;
450 unsigned int index;
451 u32 fseqno;
452 int ret;
453
454 /* If we don't know where the log is we can't do anything.
455 */
456 if (dparams->start == 0)
457 return -ENXIO;
458
459 /* Allocate the space to read in the firmware's device log and set up
460 * for the iterated call to our display function.
461 */
462 dinfo = __seq_open_private(file, &devlog_seq_ops,
463 sizeof(*dinfo) + dparams->size);
464 if (!dinfo)
465 return -ENOMEM;
466
467 /* Record the basic log buffer information and read in the raw log.
468 */
469 dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
470 dinfo->first = 0;
471 spin_lock(&adap->win0_lock);
472 ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
473 dparams->start, dparams->size, (__be32 *)dinfo->log,
474 T4_MEMORY_READ);
475 spin_unlock(&adap->win0_lock);
476 if (ret) {
477 seq_release_private(inode, file);
478 return ret;
479 }
480
481 /* Translate log multi-byte integral elements into host native format
482 * and determine where the first entry in the log is.
483 */
484 for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
485 struct fw_devlog_e *e = &dinfo->log[index];
486 int i;
487 __u32 seqno;
488
489 if (e->timestamp == 0)
490 continue;
491
492 e->timestamp = (__force __be64)be64_to_cpu(e->timestamp);
493 seqno = be32_to_cpu(e->seqno);
494 for (i = 0; i < 8; i++)
495 e->params[i] =
496 (__force __be32)be32_to_cpu(e->params[i]);
497
498 if (seqno < fseqno) {
499 fseqno = seqno;
500 dinfo->first = index;
501 }
502 }
503 return 0;
504}
505
506static const struct file_operations devlog_fops = {
507 .owner = THIS_MODULE,
508 .open = devlog_open,
509 .read = seq_read,
510 .llseek = seq_lseek,
511 .release = seq_release_private
512};
513
49216c1c
HS
514static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
515 loff_t *ppos)
516{
517 loff_t pos = *ppos;
518 loff_t avail = FILE_DATA(file)->i_size;
519 struct adapter *adap = file->private_data;
520
521 if (pos < 0)
522 return -EINVAL;
523 if (pos >= avail)
524 return 0;
525 if (count > avail - pos)
526 count = avail - pos;
527
528 while (count) {
529 size_t len;
530 int ret, ofst;
531 u8 data[256];
532
533 ofst = pos & 3;
534 len = min(count + ofst, sizeof(data));
535 ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
536 (u32 *)data, 1);
537 if (ret)
538 return ret;
539
540 len -= ofst;
541 if (copy_to_user(buf, data + ofst, len))
542 return -EFAULT;
543
544 buf += len;
545 pos += len;
546 count -= len;
547 }
548 count = pos - *ppos;
549 *ppos = pos;
550 return count;
551}
552
553static const struct file_operations flash_debugfs_fops = {
554 .owner = THIS_MODULE,
555 .open = mem_open,
556 .read = flash_read,
557};
558
ef82f662
HS
559static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
560{
561 *mask = x | y;
562 y = (__force u64)cpu_to_be64(y);
563 memcpy(addr, (char *)&y + 2, ETH_ALEN);
564}
565
566static int mps_tcam_show(struct seq_file *seq, void *v)
567{
568 if (v == SEQ_START_TOKEN)
569 seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF"
570 " VF Replication "
571 "P0 P1 P2 P3 ML\n");
572 else {
573 u64 mask;
574 u8 addr[ETH_ALEN];
575 struct adapter *adap = seq->private;
576 unsigned int idx = (uintptr_t)v - 2;
577 u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
578 u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
579 u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
580 u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
581 u32 rplc[4] = {0, 0, 0, 0};
582
583 if (tcamx & tcamy) {
584 seq_printf(seq, "%3u -\n", idx);
585 goto out;
586 }
587
588 if (cls_lo & REPLICATE_F) {
589 struct fw_ldst_cmd ldst_cmd;
590 int ret;
591
592 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
593 ldst_cmd.op_to_addrspace =
594 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
595 FW_CMD_REQUEST_F |
596 FW_CMD_READ_F |
597 FW_LDST_CMD_ADDRSPACE_V(
598 FW_LDST_ADDRSPC_MPS));
599 ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
600 ldst_cmd.u.mps.fid_ctl =
601 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
602 FW_LDST_CMD_CTL_V(idx));
603 ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
604 sizeof(ldst_cmd), &ldst_cmd);
605 if (ret)
606 dev_warn(adap->pdev_dev, "Can't read MPS "
607 "replication map for idx %d: %d\n",
608 idx, -ret);
609 else {
610 rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0);
611 rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32);
612 rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64);
613 rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96);
614 }
615 }
616
617 tcamxy2valmask(tcamx, tcamy, addr, &mask);
618 seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx"
619 "%3c %#x%4u%4d",
620 idx, addr[0], addr[1], addr[2], addr[3], addr[4],
621 addr[5], (unsigned long long)mask,
622 (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi),
623 PF_G(cls_lo),
624 (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
625 if (cls_lo & REPLICATE_F)
626 seq_printf(seq, " %08x %08x %08x %08x",
627 rplc[3], rplc[2], rplc[1], rplc[0]);
628 else
629 seq_printf(seq, "%36c", ' ');
630 seq_printf(seq, "%4u%3u%3u%3u %#x\n",
631 SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
632 SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
633 (cls_lo >> MULTILISTEN0_S) & 0xf);
634 }
635out: return 0;
636}
637
638static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
639{
640 struct adapter *adap = seq->private;
641 int max_mac_addr = is_t4(adap->params.chip) ?
642 NUM_MPS_CLS_SRAM_L_INSTANCES :
643 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
644 return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
645}
646
647static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
648{
649 return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
650}
651
652static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
653{
654 ++*pos;
655 return mps_tcam_get_idx(seq, *pos);
656}
657
658static void mps_tcam_stop(struct seq_file *seq, void *v)
659{
660}
661
662static const struct seq_operations mps_tcam_seq_ops = {
663 .start = mps_tcam_start,
664 .next = mps_tcam_next,
665 .stop = mps_tcam_stop,
666 .show = mps_tcam_show
667};
668
669static int mps_tcam_open(struct inode *inode, struct file *file)
670{
671 int res = seq_open(file, &mps_tcam_seq_ops);
672
673 if (!res) {
674 struct seq_file *seq = file->private_data;
675
676 seq->private = inode->i_private;
677 }
678 return res;
679}
680
681static const struct file_operations mps_tcam_debugfs_fops = {
682 .owner = THIS_MODULE,
683 .open = mps_tcam_open,
684 .read = seq_read,
685 .llseek = seq_lseek,
686 .release = seq_release,
687};
688
b5a02f50
AB
689#if IS_ENABLED(CONFIG_IPV6)
690static int clip_tbl_open(struct inode *inode, struct file *file)
691{
692 return single_open(file, clip_tbl_show, PDE_DATA(inode));
693}
694
695static const struct file_operations clip_tbl_debugfs_fops = {
696 .owner = THIS_MODULE,
697 .open = clip_tbl_open,
698 .read = seq_read,
699 .llseek = seq_lseek,
700 .release = single_release
701};
702#endif
703
688ea5fe
HS
704/*RSS Table.
705 */
706
707static int rss_show(struct seq_file *seq, void *v, int idx)
708{
709 u16 *entry = v;
710
711 seq_printf(seq, "%4d: %4u %4u %4u %4u %4u %4u %4u %4u\n",
712 idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
713 entry[5], entry[6], entry[7]);
714 return 0;
715}
716
717static int rss_open(struct inode *inode, struct file *file)
718{
719 int ret;
720 struct seq_tab *p;
721 struct adapter *adap = inode->i_private;
722
723 p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
724 if (!p)
725 return -ENOMEM;
726
727 ret = t4_read_rss(adap, (u16 *)p->data);
728 if (ret)
729 seq_release_private(inode, file);
730
731 return ret;
732}
733
734static const struct file_operations rss_debugfs_fops = {
735 .owner = THIS_MODULE,
736 .open = rss_open,
737 .read = seq_read,
738 .llseek = seq_lseek,
739 .release = seq_release_private
740};
741
742/* RSS Configuration.
743 */
744
745/* Small utility function to return the strings "yes" or "no" if the supplied
746 * argument is non-zero.
747 */
748static const char *yesno(int x)
749{
750 static const char *yes = "yes";
751 static const char *no = "no";
752
753 return x ? yes : no;
754}
755
756static int rss_config_show(struct seq_file *seq, void *v)
757{
758 struct adapter *adapter = seq->private;
759 static const char * const keymode[] = {
760 "global",
761 "global and per-VF scramble",
762 "per-PF and per-VF scramble",
763 "per-VF and per-VF scramble",
764 };
765 u32 rssconf;
766
767 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
768 seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
769 seq_printf(seq, " Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
770 TNL4TUPENIPV6_F));
771 seq_printf(seq, " Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
772 TNL2TUPENIPV6_F));
773 seq_printf(seq, " Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
774 TNL4TUPENIPV4_F));
775 seq_printf(seq, " Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
776 TNL2TUPENIPV4_F));
777 seq_printf(seq, " TnlTcpSel: %3s\n", yesno(rssconf & TNLTCPSEL_F));
778 seq_printf(seq, " TnlIp6Sel: %3s\n", yesno(rssconf & TNLIP6SEL_F));
779 seq_printf(seq, " TnlVrtSel: %3s\n", yesno(rssconf & TNLVRTSEL_F));
780 seq_printf(seq, " TnlMapEn: %3s\n", yesno(rssconf & TNLMAPEN_F));
781 seq_printf(seq, " OfdHashSave: %3s\n", yesno(rssconf &
782 OFDHASHSAVE_F));
783 seq_printf(seq, " OfdVrtSel: %3s\n", yesno(rssconf & OFDVRTSEL_F));
784 seq_printf(seq, " OfdMapEn: %3s\n", yesno(rssconf & OFDMAPEN_F));
785 seq_printf(seq, " OfdLkpEn: %3s\n", yesno(rssconf & OFDLKPEN_F));
786 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
787 SYN4TUPENIPV6_F));
788 seq_printf(seq, " Syn2TupEnIpv6: %3s\n", yesno(rssconf &
789 SYN2TUPENIPV6_F));
790 seq_printf(seq, " Syn4TupEnIpv4: %3s\n", yesno(rssconf &
791 SYN4TUPENIPV4_F));
792 seq_printf(seq, " Syn2TupEnIpv4: %3s\n", yesno(rssconf &
793 SYN2TUPENIPV4_F));
794 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
795 SYN4TUPENIPV6_F));
796 seq_printf(seq, " SynIp6Sel: %3s\n", yesno(rssconf & SYNIP6SEL_F));
797 seq_printf(seq, " SynVrt6Sel: %3s\n", yesno(rssconf & SYNVRTSEL_F));
798 seq_printf(seq, " SynMapEn: %3s\n", yesno(rssconf & SYNMAPEN_F));
799 seq_printf(seq, " SynLkpEn: %3s\n", yesno(rssconf & SYNLKPEN_F));
800 seq_printf(seq, " ChnEn: %3s\n", yesno(rssconf &
801 CHANNELENABLE_F));
802 seq_printf(seq, " PrtEn: %3s\n", yesno(rssconf &
803 PORTENABLE_F));
804 seq_printf(seq, " TnlAllLkp: %3s\n", yesno(rssconf &
805 TNLALLLOOKUP_F));
806 seq_printf(seq, " VrtEn: %3s\n", yesno(rssconf &
807 VIRTENABLE_F));
808 seq_printf(seq, " CngEn: %3s\n", yesno(rssconf &
809 CONGESTIONENABLE_F));
810 seq_printf(seq, " HashToeplitz: %3s\n", yesno(rssconf &
811 HASHTOEPLITZ_F));
812 seq_printf(seq, " Udp4En: %3s\n", yesno(rssconf & UDPENABLE_F));
813 seq_printf(seq, " Disable: %3s\n", yesno(rssconf & DISABLE_F));
814
815 seq_puts(seq, "\n");
816
817 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
818 seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
819 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
820 seq_printf(seq, " MaskFilter: %3d\n", MASKFILTER_G(rssconf));
821 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
822 seq_printf(seq, " HashAll: %3s\n",
823 yesno(rssconf & HASHALL_F));
824 seq_printf(seq, " HashEth: %3s\n",
825 yesno(rssconf & HASHETH_F));
826 }
827 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
828
829 seq_puts(seq, "\n");
830
831 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
832 seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
833 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
834 seq_printf(seq, " RRCplMapEn: %3s\n", yesno(rssconf &
835 RRCPLMAPEN_F));
836 seq_printf(seq, " RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
837
838 seq_puts(seq, "\n");
839
840 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
841 seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
842 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
843 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
844
845 seq_puts(seq, "\n");
846
847 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
848 seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
849 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
850 seq_printf(seq, " KeyWrAddrX: %3d\n",
851 KEYWRADDRX_G(rssconf));
852 seq_printf(seq, " KeyExtend: %3s\n",
853 yesno(rssconf & KEYEXTEND_F));
854 }
855 seq_printf(seq, " VfRdRg: %3s\n", yesno(rssconf & VFRDRG_F));
856 seq_printf(seq, " VfRdEn: %3s\n", yesno(rssconf & VFRDEN_F));
857 seq_printf(seq, " VfPerrEn: %3s\n", yesno(rssconf & VFPERREN_F));
858 seq_printf(seq, " KeyPerrEn: %3s\n", yesno(rssconf & KEYPERREN_F));
859 seq_printf(seq, " DisVfVlan: %3s\n", yesno(rssconf &
860 DISABLEVLAN_F));
861 seq_printf(seq, " EnUpSwt: %3s\n", yesno(rssconf & ENABLEUP0_F));
862 seq_printf(seq, " HashDelay: %3d\n", HASHDELAY_G(rssconf));
863 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
864 seq_printf(seq, " VfWrAddr: %3d\n", VFWRADDR_G(rssconf));
865 seq_printf(seq, " KeyMode: %s\n", keymode[KEYMODE_G(rssconf)]);
866 seq_printf(seq, " VfWrEn: %3s\n", yesno(rssconf & VFWREN_F));
867 seq_printf(seq, " KeyWrEn: %3s\n", yesno(rssconf & KEYWREN_F));
868 seq_printf(seq, " KeyWrAddr: %3d\n", KEYWRADDR_G(rssconf));
869
870 seq_puts(seq, "\n");
871
872 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
873 seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
874 seq_printf(seq, " ChnCount3: %3s\n", yesno(rssconf & CHNCOUNT3_F));
875 seq_printf(seq, " ChnCount2: %3s\n", yesno(rssconf & CHNCOUNT2_F));
876 seq_printf(seq, " ChnCount1: %3s\n", yesno(rssconf & CHNCOUNT1_F));
877 seq_printf(seq, " ChnCount0: %3s\n", yesno(rssconf & CHNCOUNT0_F));
878 seq_printf(seq, " ChnUndFlow3: %3s\n", yesno(rssconf &
879 CHNUNDFLOW3_F));
880 seq_printf(seq, " ChnUndFlow2: %3s\n", yesno(rssconf &
881 CHNUNDFLOW2_F));
882 seq_printf(seq, " ChnUndFlow1: %3s\n", yesno(rssconf &
883 CHNUNDFLOW1_F));
884 seq_printf(seq, " ChnUndFlow0: %3s\n", yesno(rssconf &
885 CHNUNDFLOW0_F));
886 seq_printf(seq, " RstChn3: %3s\n", yesno(rssconf & RSTCHN3_F));
887 seq_printf(seq, " RstChn2: %3s\n", yesno(rssconf & RSTCHN2_F));
888 seq_printf(seq, " RstChn1: %3s\n", yesno(rssconf & RSTCHN1_F));
889 seq_printf(seq, " RstChn0: %3s\n", yesno(rssconf & RSTCHN0_F));
890 seq_printf(seq, " UpdVld: %3s\n", yesno(rssconf & UPDVLD_F));
891 seq_printf(seq, " Xoff: %3s\n", yesno(rssconf & XOFF_F));
892 seq_printf(seq, " UpdChn3: %3s\n", yesno(rssconf & UPDCHN3_F));
893 seq_printf(seq, " UpdChn2: %3s\n", yesno(rssconf & UPDCHN2_F));
894 seq_printf(seq, " UpdChn1: %3s\n", yesno(rssconf & UPDCHN1_F));
895 seq_printf(seq, " UpdChn0: %3s\n", yesno(rssconf & UPDCHN0_F));
896 seq_printf(seq, " Queue: %3d\n", QUEUE_G(rssconf));
897
898 return 0;
899}
900
901DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
902
903/* RSS Secret Key.
904 */
905
906static int rss_key_show(struct seq_file *seq, void *v)
907{
908 u32 key[10];
909
910 t4_read_rss_key(seq->private, key);
911 seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
912 key[9], key[8], key[7], key[6], key[5], key[4], key[3],
913 key[2], key[1], key[0]);
914 return 0;
915}
916
917static int rss_key_open(struct inode *inode, struct file *file)
918{
919 return single_open(file, rss_key_show, inode->i_private);
920}
921
922static ssize_t rss_key_write(struct file *file, const char __user *buf,
923 size_t count, loff_t *pos)
924{
925 int i, j;
926 u32 key[10];
927 char s[100], *p;
928 struct adapter *adap = FILE_DATA(file)->i_private;
929
930 if (count > sizeof(s) - 1)
931 return -EINVAL;
932 if (copy_from_user(s, buf, count))
933 return -EFAULT;
934 for (i = count; i > 0 && isspace(s[i - 1]); i--)
935 ;
936 s[i] = '\0';
937
938 for (p = s, i = 9; i >= 0; i--) {
939 key[i] = 0;
940 for (j = 0; j < 8; j++, p++) {
941 if (!isxdigit(*p))
942 return -EINVAL;
943 key[i] = (key[i] << 4) | hex2val(*p);
944 }
945 }
946
947 t4_write_rss_key(adap, key, -1);
948 return count;
949}
950
951static const struct file_operations rss_key_debugfs_fops = {
952 .owner = THIS_MODULE,
953 .open = rss_key_open,
954 .read = seq_read,
955 .llseek = seq_lseek,
956 .release = single_release,
957 .write = rss_key_write
958};
959
960/* PF RSS Configuration.
961 */
962
963struct rss_pf_conf {
964 u32 rss_pf_map;
965 u32 rss_pf_mask;
966 u32 rss_pf_config;
967};
968
969static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
970{
971 struct rss_pf_conf *pfconf;
972
973 if (v == SEQ_START_TOKEN) {
974 /* use the 0th entry to dump the PF Map Index Size */
975 pfconf = seq->private + offsetof(struct seq_tab, data);
976 seq_printf(seq, "PF Map Index Size = %d\n\n",
977 LKPIDXSIZE_G(pfconf->rss_pf_map));
978
979 seq_puts(seq, " RSS PF VF Hash Tuple Enable Default\n");
980 seq_puts(seq, " Enable IPF Mask Mask IPv6 IPv4 UDP Queue\n");
981 seq_puts(seq, " PF Map Chn Prt Map Size Size Four Two Four Two Four Ch1 Ch0\n");
982 } else {
983 #define G_PFnLKPIDX(map, n) \
984 (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
985 #define G_PFnMSKSIZE(mask, n) \
986 (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
987
988 pfconf = v;
989 seq_printf(seq, "%3d %3s %3s %3s %3d %3d %3d %3s %3s %3s %3s %3s %3d %3d\n",
990 idx,
991 yesno(pfconf->rss_pf_config & MAPENABLE_F),
992 yesno(pfconf->rss_pf_config & CHNENABLE_F),
993 yesno(pfconf->rss_pf_config & PRTENABLE_F),
994 G_PFnLKPIDX(pfconf->rss_pf_map, idx),
995 G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
996 IVFWIDTH_G(pfconf->rss_pf_config),
997 yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
998 yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
999 yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
1000 yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
1001 yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
1002 CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
1003 CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
1004
1005 #undef G_PFnLKPIDX
1006 #undef G_PFnMSKSIZE
1007 }
1008 return 0;
1009}
1010
1011static int rss_pf_config_open(struct inode *inode, struct file *file)
1012{
1013 struct adapter *adapter = inode->i_private;
1014 struct seq_tab *p;
1015 u32 rss_pf_map, rss_pf_mask;
1016 struct rss_pf_conf *pfconf;
1017 int pf;
1018
1019 p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
1020 if (!p)
1021 return -ENOMEM;
1022
1023 pfconf = (struct rss_pf_conf *)p->data;
1024 rss_pf_map = t4_read_rss_pf_map(adapter);
1025 rss_pf_mask = t4_read_rss_pf_mask(adapter);
1026 for (pf = 0; pf < 8; pf++) {
1027 pfconf[pf].rss_pf_map = rss_pf_map;
1028 pfconf[pf].rss_pf_mask = rss_pf_mask;
1029 t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
1030 }
1031 return 0;
1032}
1033
1034static const struct file_operations rss_pf_config_debugfs_fops = {
1035 .owner = THIS_MODULE,
1036 .open = rss_pf_config_open,
1037 .read = seq_read,
1038 .llseek = seq_lseek,
1039 .release = seq_release_private
1040};
1041
1042/* VF RSS Configuration.
1043 */
1044
1045struct rss_vf_conf {
1046 u32 rss_vf_vfl;
1047 u32 rss_vf_vfh;
1048};
1049
1050static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
1051{
1052 if (v == SEQ_START_TOKEN) {
1053 seq_puts(seq, " RSS Hash Tuple Enable\n");
1054 seq_puts(seq, " Enable IVF Dis Enb IPv6 IPv4 UDP Def Secret Key\n");
1055 seq_puts(seq, " VF Chn Prt Map VLAN uP Four Two Four Two Four Que Idx Hash\n");
1056 } else {
1057 struct rss_vf_conf *vfconf = v;
1058
1059 seq_printf(seq, "%3d %3s %3s %3d %3s %3s %3s %3s %3s %3s %3s %4d %3d %#10x\n",
1060 idx,
1061 yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
1062 yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
1063 VFLKPIDX_G(vfconf->rss_vf_vfh),
1064 yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
1065 yesno(vfconf->rss_vf_vfh & VFUPEN_F),
1066 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1067 yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
1068 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1069 yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
1070 yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
1071 DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
1072 KEYINDEX_G(vfconf->rss_vf_vfh),
1073 vfconf->rss_vf_vfl);
1074 }
1075 return 0;
1076}
1077
1078static int rss_vf_config_open(struct inode *inode, struct file *file)
1079{
1080 struct adapter *adapter = inode->i_private;
1081 struct seq_tab *p;
1082 struct rss_vf_conf *vfconf;
1083 int vf;
1084
1085 p = seq_open_tab(file, 128, sizeof(*vfconf), 1, rss_vf_config_show);
1086 if (!p)
1087 return -ENOMEM;
1088
1089 vfconf = (struct rss_vf_conf *)p->data;
1090 for (vf = 0; vf < 128; vf++) {
1091 t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
1092 &vfconf[vf].rss_vf_vfh);
1093 }
1094 return 0;
1095}
1096
1097static const struct file_operations rss_vf_config_debugfs_fops = {
1098 .owner = THIS_MODULE,
1099 .open = rss_vf_config_open,
1100 .read = seq_read,
1101 .llseek = seq_lseek,
1102 .release = seq_release_private
1103};
1104
dc9daab2
HS
1105static int sge_qinfo_show(struct seq_file *seq, void *v)
1106{
1107 struct adapter *adap = seq->private;
1108 int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
1109 int toe_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
1110 int rdma_entries = DIV_ROUND_UP(adap->sge.rdmaqs, 4);
1111 int ciq_entries = DIV_ROUND_UP(adap->sge.rdmaciqs, 4);
1112 int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
1113 int i, r = (uintptr_t)v - 1;
1114 int toe_idx = r - eth_entries;
1115 int rdma_idx = toe_idx - toe_entries;
1116 int ciq_idx = rdma_idx - rdma_entries;
1117 int ctrl_idx = ciq_idx - ciq_entries;
1118 int fq_idx = ctrl_idx - ctrl_entries;
1119
1120 if (r)
1121 seq_putc(seq, '\n');
1122
1123#define S3(fmt_spec, s, v) \
1124do { \
1125 seq_printf(seq, "%-12s", s); \
1126 for (i = 0; i < n; ++i) \
1127 seq_printf(seq, " %16" fmt_spec, v); \
1128 seq_putc(seq, '\n'); \
1129} while (0)
1130#define S(s, v) S3("s", s, v)
1131#define T(s, v) S3("u", s, tx[i].v)
1132#define R(s, v) S3("u", s, rx[i].v)
1133
1134 if (r < eth_entries) {
1135 int base_qset = r * 4;
1136 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
1137 const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
1138 int n = min(4, adap->sge.ethqsets - 4 * r);
1139
1140 S("QType:", "Ethernet");
1141 S("Interface:",
1142 rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1143 T("TxQ ID:", q.cntxt_id);
1144 T("TxQ size:", q.size);
1145 T("TxQ inuse:", q.in_use);
1146 T("TxQ CIDX:", q.cidx);
1147 T("TxQ PIDX:", q.pidx);
1148#ifdef CONFIG_CXGB4_DCB
1149 T("DCB Prio:", dcb_prio);
1150 S3("u", "DCB PGID:",
1151 (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
1152 4*(7-tx[i].dcb_prio)) & 0xf);
1153 S3("u", "DCB PFC:",
1154 (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
1155 1*(7-tx[i].dcb_prio)) & 0x1);
1156#endif
1157 R("RspQ ID:", rspq.abs_id);
1158 R("RspQ size:", rspq.size);
1159 R("RspQE size:", rspq.iqe_len);
1160 R("RspQ CIDX:", rspq.cidx);
1161 R("RspQ Gen:", rspq.gen);
1162 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1163 S3("u", "Intr pktcnt:",
1164 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1165 R("FL ID:", fl.cntxt_id);
1166 R("FL size:", fl.size - 8);
1167 R("FL pend:", fl.pend_cred);
1168 R("FL avail:", fl.avail);
1169 R("FL PIDX:", fl.pidx);
1170 R("FL CIDX:", fl.cidx);
1171 } else if (toe_idx < toe_entries) {
1172 const struct sge_ofld_rxq *rx = &adap->sge.ofldrxq[toe_idx * 4];
1173 const struct sge_ofld_txq *tx = &adap->sge.ofldtxq[toe_idx * 4];
1174 int n = min(4, adap->sge.ofldqsets - 4 * toe_idx);
1175
1176 S("QType:", "TOE");
1177 T("TxQ ID:", q.cntxt_id);
1178 T("TxQ size:", q.size);
1179 T("TxQ inuse:", q.in_use);
1180 T("TxQ CIDX:", q.cidx);
1181 T("TxQ PIDX:", q.pidx);
1182 R("RspQ ID:", rspq.abs_id);
1183 R("RspQ size:", rspq.size);
1184 R("RspQE size:", rspq.iqe_len);
1185 R("RspQ CIDX:", rspq.cidx);
1186 R("RspQ Gen:", rspq.gen);
1187 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1188 S3("u", "Intr pktcnt:",
1189 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1190 R("FL ID:", fl.cntxt_id);
1191 R("FL size:", fl.size - 8);
1192 R("FL pend:", fl.pend_cred);
1193 R("FL avail:", fl.avail);
1194 R("FL PIDX:", fl.pidx);
1195 R("FL CIDX:", fl.cidx);
1196 } else if (rdma_idx < rdma_entries) {
1197 const struct sge_ofld_rxq *rx =
1198 &adap->sge.rdmarxq[rdma_idx * 4];
1199 int n = min(4, adap->sge.rdmaqs - 4 * rdma_idx);
1200
1201 S("QType:", "RDMA-CPL");
1202 R("RspQ ID:", rspq.abs_id);
1203 R("RspQ size:", rspq.size);
1204 R("RspQE size:", rspq.iqe_len);
1205 R("RspQ CIDX:", rspq.cidx);
1206 R("RspQ Gen:", rspq.gen);
1207 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1208 S3("u", "Intr pktcnt:",
1209 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1210 R("FL ID:", fl.cntxt_id);
1211 R("FL size:", fl.size - 8);
1212 R("FL pend:", fl.pend_cred);
1213 R("FL avail:", fl.avail);
1214 R("FL PIDX:", fl.pidx);
1215 R("FL CIDX:", fl.cidx);
1216 } else if (ciq_idx < ciq_entries) {
1217 const struct sge_ofld_rxq *rx = &adap->sge.rdmaciq[ciq_idx * 4];
1218 int n = min(4, adap->sge.rdmaciqs - 4 * ciq_idx);
1219
1220 S("QType:", "RDMA-CIQ");
1221 R("RspQ ID:", rspq.abs_id);
1222 R("RspQ size:", rspq.size);
1223 R("RspQE size:", rspq.iqe_len);
1224 R("RspQ CIDX:", rspq.cidx);
1225 R("RspQ Gen:", rspq.gen);
1226 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1227 S3("u", "Intr pktcnt:",
1228 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1229 } else if (ctrl_idx < ctrl_entries) {
1230 const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
1231 int n = min(4, adap->params.nports - 4 * ctrl_idx);
1232
1233 S("QType:", "Control");
1234 T("TxQ ID:", q.cntxt_id);
1235 T("TxQ size:", q.size);
1236 T("TxQ inuse:", q.in_use);
1237 T("TxQ CIDX:", q.cidx);
1238 T("TxQ PIDX:", q.pidx);
1239 } else if (fq_idx == 0) {
1240 const struct sge_rspq *evtq = &adap->sge.fw_evtq;
1241
1242 seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
1243 seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
1244 seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
1245 seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
1246 seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
1247 seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
1248 seq_printf(seq, "%-12s %16u\n", "Intr delay:",
1249 qtimer_val(adap, evtq));
1250 seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
1251 adap->sge.counter_val[evtq->pktcnt_idx]);
1252 }
1253#undef R
1254#undef T
1255#undef S
1256#undef S3
1257return 0;
1258}
1259
1260static int sge_queue_entries(const struct adapter *adap)
1261{
1262 return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
1263 DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
1264 DIV_ROUND_UP(adap->sge.rdmaqs, 4) +
1265 DIV_ROUND_UP(adap->sge.rdmaciqs, 4) +
1266 DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
1267}
1268
1269static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
1270{
1271 int entries = sge_queue_entries(seq->private);
1272
1273 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1274}
1275
1276static void sge_queue_stop(struct seq_file *seq, void *v)
1277{
1278}
1279
1280static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
1281{
1282 int entries = sge_queue_entries(seq->private);
1283
1284 ++*pos;
1285 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1286}
1287
1288static const struct seq_operations sge_qinfo_seq_ops = {
1289 .start = sge_queue_start,
1290 .next = sge_queue_next,
1291 .stop = sge_queue_stop,
1292 .show = sge_qinfo_show
1293};
1294
1295static int sge_qinfo_open(struct inode *inode, struct file *file)
1296{
1297 int res = seq_open(file, &sge_qinfo_seq_ops);
1298
1299 if (!res) {
1300 struct seq_file *seq = file->private_data;
1301
1302 seq->private = inode->i_private;
1303 }
1304 return res;
1305}
1306
1307static const struct file_operations sge_qinfo_debugfs_fops = {
1308 .owner = THIS_MODULE,
1309 .open = sge_qinfo_open,
1310 .read = seq_read,
1311 .llseek = seq_lseek,
1312 .release = seq_release,
1313};
1314
49216c1c
HS
1315int mem_open(struct inode *inode, struct file *file)
1316{
1317 unsigned int mem;
1318 struct adapter *adap;
1319
1320 file->private_data = inode->i_private;
1321
1322 mem = (uintptr_t)file->private_data & 0x3;
1323 adap = file->private_data - mem;
1324
1325 (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
1326
1327 return 0;
1328}
1329
fd88b31a
HS
1330static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
1331 loff_t *ppos)
1332{
1333 loff_t pos = *ppos;
1334 loff_t avail = file_inode(file)->i_size;
1335 unsigned int mem = (uintptr_t)file->private_data & 3;
1336 struct adapter *adap = file->private_data - mem;
1337 __be32 *data;
1338 int ret;
1339
1340 if (pos < 0)
1341 return -EINVAL;
1342 if (pos >= avail)
1343 return 0;
1344 if (count > avail - pos)
1345 count = avail - pos;
1346
1347 data = t4_alloc_mem(count);
1348 if (!data)
1349 return -ENOMEM;
1350
1351 spin_lock(&adap->win0_lock);
1352 ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
1353 spin_unlock(&adap->win0_lock);
1354 if (ret) {
1355 t4_free_mem(data);
1356 return ret;
1357 }
1358 ret = copy_to_user(buf, data, count);
1359
1360 t4_free_mem(data);
1361 if (ret)
1362 return -EFAULT;
1363
1364 *ppos = pos + count;
1365 return count;
1366}
fd88b31a
HS
1367static const struct file_operations mem_debugfs_fops = {
1368 .owner = THIS_MODULE,
1369 .open = simple_open,
1370 .read = mem_read,
1371 .llseek = default_llseek,
1372};
1373
49216c1c
HS
1374static void set_debugfs_file_size(struct dentry *de, loff_t size)
1375{
1376 if (!IS_ERR(de) && de->d_inode)
1377 de->d_inode->i_size = size;
1378}
1379
fd88b31a
HS
1380static void add_debugfs_mem(struct adapter *adap, const char *name,
1381 unsigned int idx, unsigned int size_mb)
1382{
1383 struct dentry *de;
1384
1385 de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root,
1386 (void *)adap + idx, &mem_debugfs_fops);
1387 if (de && de->d_inode)
1388 de->d_inode->i_size = size_mb << 20;
1389}
1390
1391/* Add an array of Debug FS files.
1392 */
1393void add_debugfs_files(struct adapter *adap,
1394 struct t4_debugfs_entry *files,
1395 unsigned int nfiles)
1396{
1397 int i;
1398
1399 /* debugfs support is best effort */
1400 for (i = 0; i < nfiles; i++)
1401 debugfs_create_file(files[i].name, files[i].mode,
1402 adap->debugfs_root,
1403 (void *)adap + files[i].data,
1404 files[i].ops);
1405}
1406
1407int t4_setup_debugfs(struct adapter *adap)
1408{
1409 int i;
1410 u32 size;
49216c1c 1411 struct dentry *de;
fd88b31a
HS
1412
1413 static struct t4_debugfs_entry t4_debugfs_files[] = {
f1ff24aa 1414 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
74b3092c 1415 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
49aa284f 1416 { "devlog", &devlog_fops, S_IRUSR, 0 },
fd88b31a 1417 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
ef82f662 1418 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
688ea5fe
HS
1419 { "rss", &rss_debugfs_fops, S_IRUSR, 0 },
1420 { "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
1421 { "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
1422 { "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
1423 { "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
dc9daab2 1424 { "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
e5f0e43b
HS
1425 { "ibq_tp0", &cim_ibq_fops, S_IRUSR, 0 },
1426 { "ibq_tp1", &cim_ibq_fops, S_IRUSR, 1 },
1427 { "ibq_ulp", &cim_ibq_fops, S_IRUSR, 2 },
1428 { "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
1429 { "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
1430 { "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
c778af7d
HS
1431 { "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
1432 { "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
1433 { "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
1434 { "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
1435 { "obq_sge", &cim_obq_fops, S_IRUSR, 4 },
1436 { "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
b5a02f50
AB
1437#if IS_ENABLED(CONFIG_IPV6)
1438 { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
1439#endif
fd88b31a
HS
1440 };
1441
c778af7d
HS
1442 /* Debug FS nodes common to all T5 and later adapters.
1443 */
1444 static struct t4_debugfs_entry t5_debugfs_files[] = {
1445 { "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
1446 { "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
1447 };
1448
fd88b31a
HS
1449 add_debugfs_files(adap,
1450 t4_debugfs_files,
1451 ARRAY_SIZE(t4_debugfs_files));
c778af7d
HS
1452 if (!is_t4(adap->params.chip))
1453 add_debugfs_files(adap,
1454 t5_debugfs_files,
1455 ARRAY_SIZE(t5_debugfs_files));
fd88b31a 1456
6559a7e8
HS
1457 i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
1458 if (i & EDRAM0_ENABLE_F) {
1459 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
1460 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
fd88b31a 1461 }
6559a7e8
HS
1462 if (i & EDRAM1_ENABLE_F) {
1463 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
1464 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
fd88b31a
HS
1465 }
1466 if (is_t4(adap->params.chip)) {
6559a7e8
HS
1467 size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
1468 if (i & EXT_MEM_ENABLE_F)
fd88b31a 1469 add_debugfs_mem(adap, "mc", MEM_MC,
6559a7e8 1470 EXT_MEM_SIZE_G(size));
fd88b31a 1471 } else {
6559a7e8
HS
1472 if (i & EXT_MEM0_ENABLE_F) {
1473 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
fd88b31a 1474 add_debugfs_mem(adap, "mc0", MEM_MC0,
6559a7e8 1475 EXT_MEM0_SIZE_G(size));
fd88b31a 1476 }
6559a7e8
HS
1477 if (i & EXT_MEM1_ENABLE_F) {
1478 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
fd88b31a 1479 add_debugfs_mem(adap, "mc1", MEM_MC1,
6559a7e8 1480 EXT_MEM1_SIZE_G(size));
fd88b31a
HS
1481 }
1482 }
49216c1c
HS
1483
1484 de = debugfs_create_file("flash", S_IRUSR, adap->debugfs_root, adap,
1485 &flash_debugfs_fops);
1486 set_debugfs_file_size(de, adap->params.sf_size);
1487
fd88b31a
HS
1488 return 0;
1489}