cxgb4: Add support for ULP RX logic analyzer output in debugfs
[deliverable/linux.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
2d277b3b
HS
318struct field_desc {
319 const char *name;
320 unsigned int start;
321 unsigned int width;
322};
323
324static void field_desc_show(struct seq_file *seq, u64 v,
325 const struct field_desc *p)
326{
327 char buf[32];
328 int line_size = 0;
329
330 while (p->name) {
331 u64 mask = (1ULL << p->width) - 1;
332 int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
333 ((unsigned long long)v >> p->start) & mask);
334
335 if (line_size + len >= 79) {
336 line_size = 8;
337 seq_puts(seq, "\n ");
338 }
339 seq_printf(seq, "%s ", buf);
340 line_size += len + 1;
341 p++;
342 }
343 seq_putc(seq, '\n');
344}
345
346static struct field_desc tp_la0[] = {
347 { "RcfOpCodeOut", 60, 4 },
348 { "State", 56, 4 },
349 { "WcfState", 52, 4 },
350 { "RcfOpcSrcOut", 50, 2 },
351 { "CRxError", 49, 1 },
352 { "ERxError", 48, 1 },
353 { "SanityFailed", 47, 1 },
354 { "SpuriousMsg", 46, 1 },
355 { "FlushInputMsg", 45, 1 },
356 { "FlushInputCpl", 44, 1 },
357 { "RssUpBit", 43, 1 },
358 { "RssFilterHit", 42, 1 },
359 { "Tid", 32, 10 },
360 { "InitTcb", 31, 1 },
361 { "LineNumber", 24, 7 },
362 { "Emsg", 23, 1 },
363 { "EdataOut", 22, 1 },
364 { "Cmsg", 21, 1 },
365 { "CdataOut", 20, 1 },
366 { "EreadPdu", 19, 1 },
367 { "CreadPdu", 18, 1 },
368 { "TunnelPkt", 17, 1 },
369 { "RcfPeerFin", 16, 1 },
370 { "RcfReasonOut", 12, 4 },
371 { "TxCchannel", 10, 2 },
372 { "RcfTxChannel", 8, 2 },
373 { "RxEchannel", 6, 2 },
374 { "RcfRxChannel", 5, 1 },
375 { "RcfDataOutSrdy", 4, 1 },
376 { "RxDvld", 3, 1 },
377 { "RxOoDvld", 2, 1 },
378 { "RxCongestion", 1, 1 },
379 { "TxCongestion", 0, 1 },
380 { NULL }
381};
382
383static int tp_la_show(struct seq_file *seq, void *v, int idx)
384{
385 const u64 *p = v;
386
387 field_desc_show(seq, *p, tp_la0);
388 return 0;
389}
390
391static int tp_la_show2(struct seq_file *seq, void *v, int idx)
392{
393 const u64 *p = v;
394
395 if (idx)
396 seq_putc(seq, '\n');
397 field_desc_show(seq, p[0], tp_la0);
398 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
399 field_desc_show(seq, p[1], tp_la0);
400 return 0;
401}
402
403static int tp_la_show3(struct seq_file *seq, void *v, int idx)
404{
405 static struct field_desc tp_la1[] = {
406 { "CplCmdIn", 56, 8 },
407 { "CplCmdOut", 48, 8 },
408 { "ESynOut", 47, 1 },
409 { "EAckOut", 46, 1 },
410 { "EFinOut", 45, 1 },
411 { "ERstOut", 44, 1 },
412 { "SynIn", 43, 1 },
413 { "AckIn", 42, 1 },
414 { "FinIn", 41, 1 },
415 { "RstIn", 40, 1 },
416 { "DataIn", 39, 1 },
417 { "DataInVld", 38, 1 },
418 { "PadIn", 37, 1 },
419 { "RxBufEmpty", 36, 1 },
420 { "RxDdp", 35, 1 },
421 { "RxFbCongestion", 34, 1 },
422 { "TxFbCongestion", 33, 1 },
423 { "TxPktSumSrdy", 32, 1 },
424 { "RcfUlpType", 28, 4 },
425 { "Eread", 27, 1 },
426 { "Ebypass", 26, 1 },
427 { "Esave", 25, 1 },
428 { "Static0", 24, 1 },
429 { "Cread", 23, 1 },
430 { "Cbypass", 22, 1 },
431 { "Csave", 21, 1 },
432 { "CPktOut", 20, 1 },
433 { "RxPagePoolFull", 18, 2 },
434 { "RxLpbkPkt", 17, 1 },
435 { "TxLpbkPkt", 16, 1 },
436 { "RxVfValid", 15, 1 },
437 { "SynLearned", 14, 1 },
438 { "SetDelEntry", 13, 1 },
439 { "SetInvEntry", 12, 1 },
440 { "CpcmdDvld", 11, 1 },
441 { "CpcmdSave", 10, 1 },
442 { "RxPstructsFull", 8, 2 },
443 { "EpcmdDvld", 7, 1 },
444 { "EpcmdFlush", 6, 1 },
445 { "EpcmdTrimPrefix", 5, 1 },
446 { "EpcmdTrimPostfix", 4, 1 },
447 { "ERssIp4Pkt", 3, 1 },
448 { "ERssIp6Pkt", 2, 1 },
449 { "ERssTcpUdpPkt", 1, 1 },
450 { "ERssFceFipPkt", 0, 1 },
451 { NULL }
452 };
453 static struct field_desc tp_la2[] = {
454 { "CplCmdIn", 56, 8 },
455 { "MpsVfVld", 55, 1 },
456 { "MpsPf", 52, 3 },
457 { "MpsVf", 44, 8 },
458 { "SynIn", 43, 1 },
459 { "AckIn", 42, 1 },
460 { "FinIn", 41, 1 },
461 { "RstIn", 40, 1 },
462 { "DataIn", 39, 1 },
463 { "DataInVld", 38, 1 },
464 { "PadIn", 37, 1 },
465 { "RxBufEmpty", 36, 1 },
466 { "RxDdp", 35, 1 },
467 { "RxFbCongestion", 34, 1 },
468 { "TxFbCongestion", 33, 1 },
469 { "TxPktSumSrdy", 32, 1 },
470 { "RcfUlpType", 28, 4 },
471 { "Eread", 27, 1 },
472 { "Ebypass", 26, 1 },
473 { "Esave", 25, 1 },
474 { "Static0", 24, 1 },
475 { "Cread", 23, 1 },
476 { "Cbypass", 22, 1 },
477 { "Csave", 21, 1 },
478 { "CPktOut", 20, 1 },
479 { "RxPagePoolFull", 18, 2 },
480 { "RxLpbkPkt", 17, 1 },
481 { "TxLpbkPkt", 16, 1 },
482 { "RxVfValid", 15, 1 },
483 { "SynLearned", 14, 1 },
484 { "SetDelEntry", 13, 1 },
485 { "SetInvEntry", 12, 1 },
486 { "CpcmdDvld", 11, 1 },
487 { "CpcmdSave", 10, 1 },
488 { "RxPstructsFull", 8, 2 },
489 { "EpcmdDvld", 7, 1 },
490 { "EpcmdFlush", 6, 1 },
491 { "EpcmdTrimPrefix", 5, 1 },
492 { "EpcmdTrimPostfix", 4, 1 },
493 { "ERssIp4Pkt", 3, 1 },
494 { "ERssIp6Pkt", 2, 1 },
495 { "ERssTcpUdpPkt", 1, 1 },
496 { "ERssFceFipPkt", 0, 1 },
497 { NULL }
498 };
499 const u64 *p = v;
500
501 if (idx)
502 seq_putc(seq, '\n');
503 field_desc_show(seq, p[0], tp_la0);
504 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
505 field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
506 return 0;
507}
508
509static int tp_la_open(struct inode *inode, struct file *file)
510{
511 struct seq_tab *p;
512 struct adapter *adap = inode->i_private;
513
514 switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
515 case 2:
516 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
517 tp_la_show2);
518 break;
519 case 3:
520 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
521 tp_la_show3);
522 break;
523 default:
524 p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
525 }
526 if (!p)
527 return -ENOMEM;
528
529 t4_tp_read_la(adap, (u64 *)p->data, NULL);
530 return 0;
531}
532
533static ssize_t tp_la_write(struct file *file, const char __user *buf,
534 size_t count, loff_t *pos)
535{
536 int err;
537 char s[32];
538 unsigned long val;
539 size_t size = min(sizeof(s) - 1, count);
540 struct adapter *adap = FILE_DATA(file)->i_private;
541
542 if (copy_from_user(s, buf, size))
543 return -EFAULT;
544 s[size] = '\0';
545 err = kstrtoul(s, 0, &val);
546 if (err)
547 return err;
548 if (val > 0xffff)
549 return -EINVAL;
550 adap->params.tp.la_mask = val << 16;
551 t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
552 adap->params.tp.la_mask);
553 return count;
554}
555
556static const struct file_operations tp_la_fops = {
557 .owner = THIS_MODULE,
558 .open = tp_la_open,
559 .read = seq_read,
560 .llseek = seq_lseek,
561 .release = seq_release_private,
562 .write = tp_la_write
563};
564
797ff0f5
HS
565static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
566{
567 const u32 *p = v;
568
569 if (v == SEQ_START_TOKEN)
570 seq_puts(seq, " Pcmd Type Message"
571 " Data\n");
572 else
573 seq_printf(seq, "%08x%08x %4x %08x %08x%08x%08x%08x\n",
574 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
575 return 0;
576}
577
578static int ulprx_la_open(struct inode *inode, struct file *file)
579{
580 struct seq_tab *p;
581 struct adapter *adap = inode->i_private;
582
583 p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
584 ulprx_la_show);
585 if (!p)
586 return -ENOMEM;
587
588 t4_ulprx_read_la(adap, (u32 *)p->data);
589 return 0;
590}
591
592static const struct file_operations ulprx_la_fops = {
593 .owner = THIS_MODULE,
594 .open = ulprx_la_open,
595 .read = seq_read,
596 .llseek = seq_lseek,
597 .release = seq_release_private
598};
599
b3bbe36a
HS
600/* Show the PM memory stats. These stats include:
601 *
602 * TX:
603 * Read: memory read operation
604 * Write Bypass: cut-through
605 * Bypass + mem: cut-through and save copy
606 *
607 * RX:
608 * Read: memory read
609 * Write Bypass: cut-through
610 * Flush: payload trim or drop
611 */
612static int pm_stats_show(struct seq_file *seq, void *v)
613{
614 static const char * const tx_pm_stats[] = {
615 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
616 };
617 static const char * const rx_pm_stats[] = {
618 "Read:", "Write bypass:", "Write mem:", "Flush:"
619 };
620
621 int i;
622 u32 tx_cnt[PM_NSTATS], rx_cnt[PM_NSTATS];
623 u64 tx_cyc[PM_NSTATS], rx_cyc[PM_NSTATS];
624 struct adapter *adap = seq->private;
625
626 t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
627 t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
628
629 seq_printf(seq, "%13s %10s %20s\n", " ", "Tx pcmds", "Tx bytes");
630 for (i = 0; i < PM_NSTATS - 1; i++)
631 seq_printf(seq, "%-13s %10u %20llu\n",
632 tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
633
634 seq_printf(seq, "%13s %10s %20s\n", " ", "Rx pcmds", "Rx bytes");
635 for (i = 0; i < PM_NSTATS - 1; i++)
636 seq_printf(seq, "%-13s %10u %20llu\n",
637 rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
638 return 0;
639}
640
641static int pm_stats_open(struct inode *inode, struct file *file)
642{
643 return single_open(file, pm_stats_show, inode->i_private);
644}
645
646static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
647 size_t count, loff_t *pos)
648{
649 struct adapter *adap = FILE_DATA(file)->i_private;
650
651 t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
652 t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
653 return count;
654}
655
656static const struct file_operations pm_stats_debugfs_fops = {
657 .owner = THIS_MODULE,
658 .open = pm_stats_open,
659 .read = seq_read,
660 .llseek = seq_lseek,
661 .release = single_release,
662 .write = pm_stats_clear
663};
664
b58b6676
HS
665/* Format a value in a unit that differs from the value's native unit by the
666 * given factor.
667 */
668static char *unit_conv(char *buf, size_t len, unsigned int val,
669 unsigned int factor)
670{
671 unsigned int rem = val % factor;
672
673 if (rem == 0) {
674 snprintf(buf, len, "%u", val / factor);
675 } else {
676 while (rem % 10 == 0)
677 rem /= 10;
678 snprintf(buf, len, "%u.%u", val / factor, rem);
679 }
680 return buf;
681}
682
683static int clk_show(struct seq_file *seq, void *v)
684{
685 char buf[32];
686 struct adapter *adap = seq->private;
687 unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk; /* in ps */
688 u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
689 unsigned int tre = TIMERRESOLUTION_G(res);
690 unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
691 unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
692
693 seq_printf(seq, "Core clock period: %s ns\n",
694 unit_conv(buf, sizeof(buf), cclk_ps, 1000));
695 seq_printf(seq, "TP timer tick: %s us\n",
696 unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
697 seq_printf(seq, "TCP timestamp tick: %s us\n",
698 unit_conv(buf, sizeof(buf),
699 (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
700 seq_printf(seq, "DACK tick: %s us\n",
701 unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
702 seq_printf(seq, "DACK timer: %u us\n",
703 ((cclk_ps << dack_re) / 1000000) *
704 t4_read_reg(adap, TP_DACK_TIMER_A));
705 seq_printf(seq, "Retransmit min: %llu us\n",
706 tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
707 seq_printf(seq, "Retransmit max: %llu us\n",
708 tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
709 seq_printf(seq, "Persist timer min: %llu us\n",
710 tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
711 seq_printf(seq, "Persist timer max: %llu us\n",
712 tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
713 seq_printf(seq, "Keepalive idle timer: %llu us\n",
714 tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
715 seq_printf(seq, "Keepalive interval: %llu us\n",
716 tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
717 seq_printf(seq, "Initial SRTT: %llu us\n",
718 tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
719 seq_printf(seq, "FINWAIT2 timer: %llu us\n",
720 tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
721
722 return 0;
723}
724
725DEFINE_SIMPLE_DEBUGFS_FILE(clk);
726
f1ff24aa 727/* Firmware Device Log dump. */
49aa284f
HS
728static const char * const devlog_level_strings[] = {
729 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
730 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
731 [FW_DEVLOG_LEVEL_ERR] = "ERR",
732 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
733 [FW_DEVLOG_LEVEL_INFO] = "INFO",
734 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
735};
736
737static const char * const devlog_facility_strings[] = {
738 [FW_DEVLOG_FACILITY_CORE] = "CORE",
739 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
740 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
741 [FW_DEVLOG_FACILITY_RES] = "RES",
742 [FW_DEVLOG_FACILITY_HW] = "HW",
743 [FW_DEVLOG_FACILITY_FLR] = "FLR",
744 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
745 [FW_DEVLOG_FACILITY_PHY] = "PHY",
746 [FW_DEVLOG_FACILITY_MAC] = "MAC",
747 [FW_DEVLOG_FACILITY_PORT] = "PORT",
748 [FW_DEVLOG_FACILITY_VI] = "VI",
749 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
750 [FW_DEVLOG_FACILITY_ACL] = "ACL",
751 [FW_DEVLOG_FACILITY_TM] = "TM",
752 [FW_DEVLOG_FACILITY_QFC] = "QFC",
753 [FW_DEVLOG_FACILITY_DCB] = "DCB",
754 [FW_DEVLOG_FACILITY_ETH] = "ETH",
755 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
756 [FW_DEVLOG_FACILITY_RI] = "RI",
757 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
758 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
759 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
760 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
761};
762
763/* Information gathered by Device Log Open routine for the display routine.
764 */
765struct devlog_info {
766 unsigned int nentries; /* number of entries in log[] */
767 unsigned int first; /* first [temporal] entry in log[] */
768 struct fw_devlog_e log[0]; /* Firmware Device Log */
769};
770
771/* Dump a Firmaware Device Log entry.
772 */
773static int devlog_show(struct seq_file *seq, void *v)
774{
775 if (v == SEQ_START_TOKEN)
776 seq_printf(seq, "%10s %15s %8s %8s %s\n",
777 "Seq#", "Tstamp", "Level", "Facility", "Message");
778 else {
779 struct devlog_info *dinfo = seq->private;
780 int fidx = (uintptr_t)v - 2;
781 unsigned long index;
782 struct fw_devlog_e *e;
783
784 /* Get a pointer to the log entry to display. Skip unused log
785 * entries.
786 */
787 index = dinfo->first + fidx;
788 if (index >= dinfo->nentries)
789 index -= dinfo->nentries;
790 e = &dinfo->log[index];
791 if (e->timestamp == 0)
792 return 0;
793
794 /* Print the message. This depends on the firmware using
795 * exactly the same formating strings as the kernel so we may
796 * eventually have to put a format interpreter in here ...
797 */
798 seq_printf(seq, "%10d %15llu %8s %8s ",
799 e->seqno, e->timestamp,
800 (e->level < ARRAY_SIZE(devlog_level_strings)
801 ? devlog_level_strings[e->level]
802 : "UNKNOWN"),
803 (e->facility < ARRAY_SIZE(devlog_facility_strings)
804 ? devlog_facility_strings[e->facility]
805 : "UNKNOWN"));
806 seq_printf(seq, e->fmt, e->params[0], e->params[1],
807 e->params[2], e->params[3], e->params[4],
808 e->params[5], e->params[6], e->params[7]);
809 }
810 return 0;
811}
812
813/* Sequential File Operations for Device Log.
814 */
815static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
816{
817 if (pos > dinfo->nentries)
818 return NULL;
819
820 return (void *)(uintptr_t)(pos + 1);
821}
822
823static void *devlog_start(struct seq_file *seq, loff_t *pos)
824{
825 struct devlog_info *dinfo = seq->private;
826
827 return (*pos
828 ? devlog_get_idx(dinfo, *pos)
829 : SEQ_START_TOKEN);
830}
831
832static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
833{
834 struct devlog_info *dinfo = seq->private;
835
836 (*pos)++;
837 return devlog_get_idx(dinfo, *pos);
838}
839
840static void devlog_stop(struct seq_file *seq, void *v)
841{
842}
843
844static const struct seq_operations devlog_seq_ops = {
845 .start = devlog_start,
846 .next = devlog_next,
847 .stop = devlog_stop,
848 .show = devlog_show
849};
850
851/* Set up for reading the firmware's device log. We read the entire log here
852 * and then display it incrementally in devlog_show().
853 */
854static int devlog_open(struct inode *inode, struct file *file)
855{
856 struct adapter *adap = inode->i_private;
857 struct devlog_params *dparams = &adap->params.devlog;
858 struct devlog_info *dinfo;
859 unsigned int index;
860 u32 fseqno;
861 int ret;
862
863 /* If we don't know where the log is we can't do anything.
864 */
865 if (dparams->start == 0)
866 return -ENXIO;
867
868 /* Allocate the space to read in the firmware's device log and set up
869 * for the iterated call to our display function.
870 */
871 dinfo = __seq_open_private(file, &devlog_seq_ops,
872 sizeof(*dinfo) + dparams->size);
873 if (!dinfo)
874 return -ENOMEM;
875
876 /* Record the basic log buffer information and read in the raw log.
877 */
878 dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
879 dinfo->first = 0;
880 spin_lock(&adap->win0_lock);
881 ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
882 dparams->start, dparams->size, (__be32 *)dinfo->log,
883 T4_MEMORY_READ);
884 spin_unlock(&adap->win0_lock);
885 if (ret) {
886 seq_release_private(inode, file);
887 return ret;
888 }
889
890 /* Translate log multi-byte integral elements into host native format
891 * and determine where the first entry in the log is.
892 */
893 for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
894 struct fw_devlog_e *e = &dinfo->log[index];
895 int i;
896 __u32 seqno;
897
898 if (e->timestamp == 0)
899 continue;
900
901 e->timestamp = (__force __be64)be64_to_cpu(e->timestamp);
902 seqno = be32_to_cpu(e->seqno);
903 for (i = 0; i < 8; i++)
904 e->params[i] =
905 (__force __be32)be32_to_cpu(e->params[i]);
906
907 if (seqno < fseqno) {
908 fseqno = seqno;
909 dinfo->first = index;
910 }
911 }
912 return 0;
913}
914
915static const struct file_operations devlog_fops = {
916 .owner = THIS_MODULE,
917 .open = devlog_open,
918 .read = seq_read,
919 .llseek = seq_lseek,
920 .release = seq_release_private
921};
922
49216c1c
HS
923static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
924 loff_t *ppos)
925{
926 loff_t pos = *ppos;
927 loff_t avail = FILE_DATA(file)->i_size;
928 struct adapter *adap = file->private_data;
929
930 if (pos < 0)
931 return -EINVAL;
932 if (pos >= avail)
933 return 0;
934 if (count > avail - pos)
935 count = avail - pos;
936
937 while (count) {
938 size_t len;
939 int ret, ofst;
940 u8 data[256];
941
942 ofst = pos & 3;
943 len = min(count + ofst, sizeof(data));
944 ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
945 (u32 *)data, 1);
946 if (ret)
947 return ret;
948
949 len -= ofst;
950 if (copy_to_user(buf, data + ofst, len))
951 return -EFAULT;
952
953 buf += len;
954 pos += len;
955 count -= len;
956 }
957 count = pos - *ppos;
958 *ppos = pos;
959 return count;
960}
961
962static const struct file_operations flash_debugfs_fops = {
963 .owner = THIS_MODULE,
964 .open = mem_open,
965 .read = flash_read,
966};
967
ef82f662
HS
968static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
969{
970 *mask = x | y;
971 y = (__force u64)cpu_to_be64(y);
972 memcpy(addr, (char *)&y + 2, ETH_ALEN);
973}
974
975static int mps_tcam_show(struct seq_file *seq, void *v)
976{
977 if (v == SEQ_START_TOKEN)
978 seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF"
979 " VF Replication "
980 "P0 P1 P2 P3 ML\n");
981 else {
982 u64 mask;
983 u8 addr[ETH_ALEN];
984 struct adapter *adap = seq->private;
985 unsigned int idx = (uintptr_t)v - 2;
986 u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
987 u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
988 u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
989 u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
990 u32 rplc[4] = {0, 0, 0, 0};
991
992 if (tcamx & tcamy) {
993 seq_printf(seq, "%3u -\n", idx);
994 goto out;
995 }
996
997 if (cls_lo & REPLICATE_F) {
998 struct fw_ldst_cmd ldst_cmd;
999 int ret;
1000
1001 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
1002 ldst_cmd.op_to_addrspace =
1003 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1004 FW_CMD_REQUEST_F |
1005 FW_CMD_READ_F |
1006 FW_LDST_CMD_ADDRSPACE_V(
1007 FW_LDST_ADDRSPC_MPS));
1008 ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
1009 ldst_cmd.u.mps.fid_ctl =
1010 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
1011 FW_LDST_CMD_CTL_V(idx));
1012 ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1013 sizeof(ldst_cmd), &ldst_cmd);
1014 if (ret)
1015 dev_warn(adap->pdev_dev, "Can't read MPS "
1016 "replication map for idx %d: %d\n",
1017 idx, -ret);
1018 else {
1019 rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0);
1020 rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32);
1021 rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64);
1022 rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96);
1023 }
1024 }
1025
1026 tcamxy2valmask(tcamx, tcamy, addr, &mask);
1027 seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx"
1028 "%3c %#x%4u%4d",
1029 idx, addr[0], addr[1], addr[2], addr[3], addr[4],
1030 addr[5], (unsigned long long)mask,
1031 (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi),
1032 PF_G(cls_lo),
1033 (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
1034 if (cls_lo & REPLICATE_F)
1035 seq_printf(seq, " %08x %08x %08x %08x",
1036 rplc[3], rplc[2], rplc[1], rplc[0]);
1037 else
1038 seq_printf(seq, "%36c", ' ');
1039 seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1040 SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1041 SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1042 (cls_lo >> MULTILISTEN0_S) & 0xf);
1043 }
1044out: return 0;
1045}
1046
1047static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1048{
1049 struct adapter *adap = seq->private;
1050 int max_mac_addr = is_t4(adap->params.chip) ?
1051 NUM_MPS_CLS_SRAM_L_INSTANCES :
1052 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1053 return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1054}
1055
1056static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1057{
1058 return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1059}
1060
1061static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1062{
1063 ++*pos;
1064 return mps_tcam_get_idx(seq, *pos);
1065}
1066
1067static void mps_tcam_stop(struct seq_file *seq, void *v)
1068{
1069}
1070
1071static const struct seq_operations mps_tcam_seq_ops = {
1072 .start = mps_tcam_start,
1073 .next = mps_tcam_next,
1074 .stop = mps_tcam_stop,
1075 .show = mps_tcam_show
1076};
1077
1078static int mps_tcam_open(struct inode *inode, struct file *file)
1079{
1080 int res = seq_open(file, &mps_tcam_seq_ops);
1081
1082 if (!res) {
1083 struct seq_file *seq = file->private_data;
1084
1085 seq->private = inode->i_private;
1086 }
1087 return res;
1088}
1089
1090static const struct file_operations mps_tcam_debugfs_fops = {
1091 .owner = THIS_MODULE,
1092 .open = mps_tcam_open,
1093 .read = seq_read,
1094 .llseek = seq_lseek,
1095 .release = seq_release,
1096};
1097
70a5f3bb
HS
1098/* Display various sensor information.
1099 */
1100static int sensors_show(struct seq_file *seq, void *v)
1101{
1102 struct adapter *adap = seq->private;
1103 u32 param[7], val[7];
1104 int ret;
1105
1106 /* Note that if the sensors haven't been initialized and turned on
1107 * we'll get values of 0, so treat those as "<unknown>" ...
1108 */
1109 param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1110 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1111 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
1112 param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1113 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1114 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1115 ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 2,
1116 param, val);
1117
1118 if (ret < 0 || val[0] == 0)
1119 seq_puts(seq, "Temperature: <unknown>\n");
1120 else
1121 seq_printf(seq, "Temperature: %dC\n", val[0]);
1122
1123 if (ret < 0 || val[1] == 0)
1124 seq_puts(seq, "Core VDD: <unknown>\n");
1125 else
1126 seq_printf(seq, "Core VDD: %dmV\n", val[1]);
1127
1128 return 0;
1129}
1130
1131DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
1132
b5a02f50
AB
1133#if IS_ENABLED(CONFIG_IPV6)
1134static int clip_tbl_open(struct inode *inode, struct file *file)
1135{
1136 return single_open(file, clip_tbl_show, PDE_DATA(inode));
1137}
1138
1139static const struct file_operations clip_tbl_debugfs_fops = {
1140 .owner = THIS_MODULE,
1141 .open = clip_tbl_open,
1142 .read = seq_read,
1143 .llseek = seq_lseek,
1144 .release = single_release
1145};
1146#endif
1147
688ea5fe
HS
1148/*RSS Table.
1149 */
1150
1151static int rss_show(struct seq_file *seq, void *v, int idx)
1152{
1153 u16 *entry = v;
1154
1155 seq_printf(seq, "%4d: %4u %4u %4u %4u %4u %4u %4u %4u\n",
1156 idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
1157 entry[5], entry[6], entry[7]);
1158 return 0;
1159}
1160
1161static int rss_open(struct inode *inode, struct file *file)
1162{
1163 int ret;
1164 struct seq_tab *p;
1165 struct adapter *adap = inode->i_private;
1166
1167 p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
1168 if (!p)
1169 return -ENOMEM;
1170
1171 ret = t4_read_rss(adap, (u16 *)p->data);
1172 if (ret)
1173 seq_release_private(inode, file);
1174
1175 return ret;
1176}
1177
1178static const struct file_operations rss_debugfs_fops = {
1179 .owner = THIS_MODULE,
1180 .open = rss_open,
1181 .read = seq_read,
1182 .llseek = seq_lseek,
1183 .release = seq_release_private
1184};
1185
1186/* RSS Configuration.
1187 */
1188
1189/* Small utility function to return the strings "yes" or "no" if the supplied
1190 * argument is non-zero.
1191 */
1192static const char *yesno(int x)
1193{
1194 static const char *yes = "yes";
1195 static const char *no = "no";
1196
1197 return x ? yes : no;
1198}
1199
1200static int rss_config_show(struct seq_file *seq, void *v)
1201{
1202 struct adapter *adapter = seq->private;
1203 static const char * const keymode[] = {
1204 "global",
1205 "global and per-VF scramble",
1206 "per-PF and per-VF scramble",
1207 "per-VF and per-VF scramble",
1208 };
1209 u32 rssconf;
1210
1211 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
1212 seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
1213 seq_printf(seq, " Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
1214 TNL4TUPENIPV6_F));
1215 seq_printf(seq, " Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
1216 TNL2TUPENIPV6_F));
1217 seq_printf(seq, " Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
1218 TNL4TUPENIPV4_F));
1219 seq_printf(seq, " Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
1220 TNL2TUPENIPV4_F));
1221 seq_printf(seq, " TnlTcpSel: %3s\n", yesno(rssconf & TNLTCPSEL_F));
1222 seq_printf(seq, " TnlIp6Sel: %3s\n", yesno(rssconf & TNLIP6SEL_F));
1223 seq_printf(seq, " TnlVrtSel: %3s\n", yesno(rssconf & TNLVRTSEL_F));
1224 seq_printf(seq, " TnlMapEn: %3s\n", yesno(rssconf & TNLMAPEN_F));
1225 seq_printf(seq, " OfdHashSave: %3s\n", yesno(rssconf &
1226 OFDHASHSAVE_F));
1227 seq_printf(seq, " OfdVrtSel: %3s\n", yesno(rssconf & OFDVRTSEL_F));
1228 seq_printf(seq, " OfdMapEn: %3s\n", yesno(rssconf & OFDMAPEN_F));
1229 seq_printf(seq, " OfdLkpEn: %3s\n", yesno(rssconf & OFDLKPEN_F));
1230 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1231 SYN4TUPENIPV6_F));
1232 seq_printf(seq, " Syn2TupEnIpv6: %3s\n", yesno(rssconf &
1233 SYN2TUPENIPV6_F));
1234 seq_printf(seq, " Syn4TupEnIpv4: %3s\n", yesno(rssconf &
1235 SYN4TUPENIPV4_F));
1236 seq_printf(seq, " Syn2TupEnIpv4: %3s\n", yesno(rssconf &
1237 SYN2TUPENIPV4_F));
1238 seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1239 SYN4TUPENIPV6_F));
1240 seq_printf(seq, " SynIp6Sel: %3s\n", yesno(rssconf & SYNIP6SEL_F));
1241 seq_printf(seq, " SynVrt6Sel: %3s\n", yesno(rssconf & SYNVRTSEL_F));
1242 seq_printf(seq, " SynMapEn: %3s\n", yesno(rssconf & SYNMAPEN_F));
1243 seq_printf(seq, " SynLkpEn: %3s\n", yesno(rssconf & SYNLKPEN_F));
1244 seq_printf(seq, " ChnEn: %3s\n", yesno(rssconf &
1245 CHANNELENABLE_F));
1246 seq_printf(seq, " PrtEn: %3s\n", yesno(rssconf &
1247 PORTENABLE_F));
1248 seq_printf(seq, " TnlAllLkp: %3s\n", yesno(rssconf &
1249 TNLALLLOOKUP_F));
1250 seq_printf(seq, " VrtEn: %3s\n", yesno(rssconf &
1251 VIRTENABLE_F));
1252 seq_printf(seq, " CngEn: %3s\n", yesno(rssconf &
1253 CONGESTIONENABLE_F));
1254 seq_printf(seq, " HashToeplitz: %3s\n", yesno(rssconf &
1255 HASHTOEPLITZ_F));
1256 seq_printf(seq, " Udp4En: %3s\n", yesno(rssconf & UDPENABLE_F));
1257 seq_printf(seq, " Disable: %3s\n", yesno(rssconf & DISABLE_F));
1258
1259 seq_puts(seq, "\n");
1260
1261 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
1262 seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
1263 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
1264 seq_printf(seq, " MaskFilter: %3d\n", MASKFILTER_G(rssconf));
1265 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
1266 seq_printf(seq, " HashAll: %3s\n",
1267 yesno(rssconf & HASHALL_F));
1268 seq_printf(seq, " HashEth: %3s\n",
1269 yesno(rssconf & HASHETH_F));
1270 }
1271 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
1272
1273 seq_puts(seq, "\n");
1274
1275 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
1276 seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
1277 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
1278 seq_printf(seq, " RRCplMapEn: %3s\n", yesno(rssconf &
1279 RRCPLMAPEN_F));
1280 seq_printf(seq, " RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
1281
1282 seq_puts(seq, "\n");
1283
1284 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
1285 seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
1286 seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
1287 seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
1288
1289 seq_puts(seq, "\n");
1290
1291 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
1292 seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
1293 if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
1294 seq_printf(seq, " KeyWrAddrX: %3d\n",
1295 KEYWRADDRX_G(rssconf));
1296 seq_printf(seq, " KeyExtend: %3s\n",
1297 yesno(rssconf & KEYEXTEND_F));
1298 }
1299 seq_printf(seq, " VfRdRg: %3s\n", yesno(rssconf & VFRDRG_F));
1300 seq_printf(seq, " VfRdEn: %3s\n", yesno(rssconf & VFRDEN_F));
1301 seq_printf(seq, " VfPerrEn: %3s\n", yesno(rssconf & VFPERREN_F));
1302 seq_printf(seq, " KeyPerrEn: %3s\n", yesno(rssconf & KEYPERREN_F));
1303 seq_printf(seq, " DisVfVlan: %3s\n", yesno(rssconf &
1304 DISABLEVLAN_F));
1305 seq_printf(seq, " EnUpSwt: %3s\n", yesno(rssconf & ENABLEUP0_F));
1306 seq_printf(seq, " HashDelay: %3d\n", HASHDELAY_G(rssconf));
1307 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
1308 seq_printf(seq, " VfWrAddr: %3d\n", VFWRADDR_G(rssconf));
1309 seq_printf(seq, " KeyMode: %s\n", keymode[KEYMODE_G(rssconf)]);
1310 seq_printf(seq, " VfWrEn: %3s\n", yesno(rssconf & VFWREN_F));
1311 seq_printf(seq, " KeyWrEn: %3s\n", yesno(rssconf & KEYWREN_F));
1312 seq_printf(seq, " KeyWrAddr: %3d\n", KEYWRADDR_G(rssconf));
1313
1314 seq_puts(seq, "\n");
1315
1316 rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
1317 seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
1318 seq_printf(seq, " ChnCount3: %3s\n", yesno(rssconf & CHNCOUNT3_F));
1319 seq_printf(seq, " ChnCount2: %3s\n", yesno(rssconf & CHNCOUNT2_F));
1320 seq_printf(seq, " ChnCount1: %3s\n", yesno(rssconf & CHNCOUNT1_F));
1321 seq_printf(seq, " ChnCount0: %3s\n", yesno(rssconf & CHNCOUNT0_F));
1322 seq_printf(seq, " ChnUndFlow3: %3s\n", yesno(rssconf &
1323 CHNUNDFLOW3_F));
1324 seq_printf(seq, " ChnUndFlow2: %3s\n", yesno(rssconf &
1325 CHNUNDFLOW2_F));
1326 seq_printf(seq, " ChnUndFlow1: %3s\n", yesno(rssconf &
1327 CHNUNDFLOW1_F));
1328 seq_printf(seq, " ChnUndFlow0: %3s\n", yesno(rssconf &
1329 CHNUNDFLOW0_F));
1330 seq_printf(seq, " RstChn3: %3s\n", yesno(rssconf & RSTCHN3_F));
1331 seq_printf(seq, " RstChn2: %3s\n", yesno(rssconf & RSTCHN2_F));
1332 seq_printf(seq, " RstChn1: %3s\n", yesno(rssconf & RSTCHN1_F));
1333 seq_printf(seq, " RstChn0: %3s\n", yesno(rssconf & RSTCHN0_F));
1334 seq_printf(seq, " UpdVld: %3s\n", yesno(rssconf & UPDVLD_F));
1335 seq_printf(seq, " Xoff: %3s\n", yesno(rssconf & XOFF_F));
1336 seq_printf(seq, " UpdChn3: %3s\n", yesno(rssconf & UPDCHN3_F));
1337 seq_printf(seq, " UpdChn2: %3s\n", yesno(rssconf & UPDCHN2_F));
1338 seq_printf(seq, " UpdChn1: %3s\n", yesno(rssconf & UPDCHN1_F));
1339 seq_printf(seq, " UpdChn0: %3s\n", yesno(rssconf & UPDCHN0_F));
1340 seq_printf(seq, " Queue: %3d\n", QUEUE_G(rssconf));
1341
1342 return 0;
1343}
1344
1345DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
1346
1347/* RSS Secret Key.
1348 */
1349
1350static int rss_key_show(struct seq_file *seq, void *v)
1351{
1352 u32 key[10];
1353
1354 t4_read_rss_key(seq->private, key);
1355 seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1356 key[9], key[8], key[7], key[6], key[5], key[4], key[3],
1357 key[2], key[1], key[0]);
1358 return 0;
1359}
1360
1361static int rss_key_open(struct inode *inode, struct file *file)
1362{
1363 return single_open(file, rss_key_show, inode->i_private);
1364}
1365
1366static ssize_t rss_key_write(struct file *file, const char __user *buf,
1367 size_t count, loff_t *pos)
1368{
1369 int i, j;
1370 u32 key[10];
1371 char s[100], *p;
1372 struct adapter *adap = FILE_DATA(file)->i_private;
1373
1374 if (count > sizeof(s) - 1)
1375 return -EINVAL;
1376 if (copy_from_user(s, buf, count))
1377 return -EFAULT;
1378 for (i = count; i > 0 && isspace(s[i - 1]); i--)
1379 ;
1380 s[i] = '\0';
1381
1382 for (p = s, i = 9; i >= 0; i--) {
1383 key[i] = 0;
1384 for (j = 0; j < 8; j++, p++) {
1385 if (!isxdigit(*p))
1386 return -EINVAL;
1387 key[i] = (key[i] << 4) | hex2val(*p);
1388 }
1389 }
1390
1391 t4_write_rss_key(adap, key, -1);
1392 return count;
1393}
1394
1395static const struct file_operations rss_key_debugfs_fops = {
1396 .owner = THIS_MODULE,
1397 .open = rss_key_open,
1398 .read = seq_read,
1399 .llseek = seq_lseek,
1400 .release = single_release,
1401 .write = rss_key_write
1402};
1403
1404/* PF RSS Configuration.
1405 */
1406
1407struct rss_pf_conf {
1408 u32 rss_pf_map;
1409 u32 rss_pf_mask;
1410 u32 rss_pf_config;
1411};
1412
1413static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
1414{
1415 struct rss_pf_conf *pfconf;
1416
1417 if (v == SEQ_START_TOKEN) {
1418 /* use the 0th entry to dump the PF Map Index Size */
1419 pfconf = seq->private + offsetof(struct seq_tab, data);
1420 seq_printf(seq, "PF Map Index Size = %d\n\n",
1421 LKPIDXSIZE_G(pfconf->rss_pf_map));
1422
1423 seq_puts(seq, " RSS PF VF Hash Tuple Enable Default\n");
1424 seq_puts(seq, " Enable IPF Mask Mask IPv6 IPv4 UDP Queue\n");
1425 seq_puts(seq, " PF Map Chn Prt Map Size Size Four Two Four Two Four Ch1 Ch0\n");
1426 } else {
1427 #define G_PFnLKPIDX(map, n) \
1428 (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
1429 #define G_PFnMSKSIZE(mask, n) \
1430 (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
1431
1432 pfconf = v;
1433 seq_printf(seq, "%3d %3s %3s %3s %3d %3d %3d %3s %3s %3s %3s %3s %3d %3d\n",
1434 idx,
1435 yesno(pfconf->rss_pf_config & MAPENABLE_F),
1436 yesno(pfconf->rss_pf_config & CHNENABLE_F),
1437 yesno(pfconf->rss_pf_config & PRTENABLE_F),
1438 G_PFnLKPIDX(pfconf->rss_pf_map, idx),
1439 G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
1440 IVFWIDTH_G(pfconf->rss_pf_config),
1441 yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
1442 yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
1443 yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
1444 yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
1445 yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
1446 CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
1447 CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
1448
1449 #undef G_PFnLKPIDX
1450 #undef G_PFnMSKSIZE
1451 }
1452 return 0;
1453}
1454
1455static int rss_pf_config_open(struct inode *inode, struct file *file)
1456{
1457 struct adapter *adapter = inode->i_private;
1458 struct seq_tab *p;
1459 u32 rss_pf_map, rss_pf_mask;
1460 struct rss_pf_conf *pfconf;
1461 int pf;
1462
1463 p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
1464 if (!p)
1465 return -ENOMEM;
1466
1467 pfconf = (struct rss_pf_conf *)p->data;
1468 rss_pf_map = t4_read_rss_pf_map(adapter);
1469 rss_pf_mask = t4_read_rss_pf_mask(adapter);
1470 for (pf = 0; pf < 8; pf++) {
1471 pfconf[pf].rss_pf_map = rss_pf_map;
1472 pfconf[pf].rss_pf_mask = rss_pf_mask;
1473 t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
1474 }
1475 return 0;
1476}
1477
1478static const struct file_operations rss_pf_config_debugfs_fops = {
1479 .owner = THIS_MODULE,
1480 .open = rss_pf_config_open,
1481 .read = seq_read,
1482 .llseek = seq_lseek,
1483 .release = seq_release_private
1484};
1485
1486/* VF RSS Configuration.
1487 */
1488
1489struct rss_vf_conf {
1490 u32 rss_vf_vfl;
1491 u32 rss_vf_vfh;
1492};
1493
1494static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
1495{
1496 if (v == SEQ_START_TOKEN) {
1497 seq_puts(seq, " RSS Hash Tuple Enable\n");
1498 seq_puts(seq, " Enable IVF Dis Enb IPv6 IPv4 UDP Def Secret Key\n");
1499 seq_puts(seq, " VF Chn Prt Map VLAN uP Four Two Four Two Four Que Idx Hash\n");
1500 } else {
1501 struct rss_vf_conf *vfconf = v;
1502
1503 seq_printf(seq, "%3d %3s %3s %3d %3s %3s %3s %3s %3s %3s %3s %4d %3d %#10x\n",
1504 idx,
1505 yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
1506 yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
1507 VFLKPIDX_G(vfconf->rss_vf_vfh),
1508 yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
1509 yesno(vfconf->rss_vf_vfh & VFUPEN_F),
1510 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1511 yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
1512 yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1513 yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
1514 yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
1515 DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
1516 KEYINDEX_G(vfconf->rss_vf_vfh),
1517 vfconf->rss_vf_vfl);
1518 }
1519 return 0;
1520}
1521
1522static int rss_vf_config_open(struct inode *inode, struct file *file)
1523{
1524 struct adapter *adapter = inode->i_private;
1525 struct seq_tab *p;
1526 struct rss_vf_conf *vfconf;
1527 int vf;
1528
1529 p = seq_open_tab(file, 128, sizeof(*vfconf), 1, rss_vf_config_show);
1530 if (!p)
1531 return -ENOMEM;
1532
1533 vfconf = (struct rss_vf_conf *)p->data;
1534 for (vf = 0; vf < 128; vf++) {
1535 t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
1536 &vfconf[vf].rss_vf_vfh);
1537 }
1538 return 0;
1539}
1540
1541static const struct file_operations rss_vf_config_debugfs_fops = {
1542 .owner = THIS_MODULE,
1543 .open = rss_vf_config_open,
1544 .read = seq_read,
1545 .llseek = seq_lseek,
1546 .release = seq_release_private
1547};
1548
3051fa61
HS
1549/**
1550 * ethqset2pinfo - return port_info of an Ethernet Queue Set
1551 * @adap: the adapter
1552 * @qset: Ethernet Queue Set
1553 */
1554static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
1555{
1556 int pidx;
1557
1558 for_each_port(adap, pidx) {
1559 struct port_info *pi = adap2pinfo(adap, pidx);
1560
1561 if (qset >= pi->first_qset &&
1562 qset < pi->first_qset + pi->nqsets)
1563 return pi;
1564 }
1565
1566 /* should never happen! */
1567 BUG_ON(1);
1568 return NULL;
1569}
1570
dc9daab2
HS
1571static int sge_qinfo_show(struct seq_file *seq, void *v)
1572{
1573 struct adapter *adap = seq->private;
1574 int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
1575 int toe_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
1576 int rdma_entries = DIV_ROUND_UP(adap->sge.rdmaqs, 4);
1577 int ciq_entries = DIV_ROUND_UP(adap->sge.rdmaciqs, 4);
1578 int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
1579 int i, r = (uintptr_t)v - 1;
1580 int toe_idx = r - eth_entries;
1581 int rdma_idx = toe_idx - toe_entries;
1582 int ciq_idx = rdma_idx - rdma_entries;
1583 int ctrl_idx = ciq_idx - ciq_entries;
1584 int fq_idx = ctrl_idx - ctrl_entries;
1585
1586 if (r)
1587 seq_putc(seq, '\n');
1588
1589#define S3(fmt_spec, s, v) \
1590do { \
1591 seq_printf(seq, "%-12s", s); \
1592 for (i = 0; i < n; ++i) \
1593 seq_printf(seq, " %16" fmt_spec, v); \
1594 seq_putc(seq, '\n'); \
1595} while (0)
1596#define S(s, v) S3("s", s, v)
1597#define T(s, v) S3("u", s, tx[i].v)
1598#define R(s, v) S3("u", s, rx[i].v)
1599
1600 if (r < eth_entries) {
1601 int base_qset = r * 4;
1602 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
1603 const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
1604 int n = min(4, adap->sge.ethqsets - 4 * r);
1605
1606 S("QType:", "Ethernet");
1607 S("Interface:",
1608 rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1609 T("TxQ ID:", q.cntxt_id);
1610 T("TxQ size:", q.size);
1611 T("TxQ inuse:", q.in_use);
1612 T("TxQ CIDX:", q.cidx);
1613 T("TxQ PIDX:", q.pidx);
3051fa61 1614#ifdef CONFIG_CHELSIO_T4_DCB
dc9daab2
HS
1615 T("DCB Prio:", dcb_prio);
1616 S3("u", "DCB PGID:",
1617 (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
1618 4*(7-tx[i].dcb_prio)) & 0xf);
1619 S3("u", "DCB PFC:",
1620 (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
1621 1*(7-tx[i].dcb_prio)) & 0x1);
1622#endif
1623 R("RspQ ID:", rspq.abs_id);
1624 R("RspQ size:", rspq.size);
1625 R("RspQE size:", rspq.iqe_len);
1626 R("RspQ CIDX:", rspq.cidx);
1627 R("RspQ Gen:", rspq.gen);
1628 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1629 S3("u", "Intr pktcnt:",
1630 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1631 R("FL ID:", fl.cntxt_id);
1632 R("FL size:", fl.size - 8);
1633 R("FL pend:", fl.pend_cred);
1634 R("FL avail:", fl.avail);
1635 R("FL PIDX:", fl.pidx);
1636 R("FL CIDX:", fl.cidx);
1637 } else if (toe_idx < toe_entries) {
1638 const struct sge_ofld_rxq *rx = &adap->sge.ofldrxq[toe_idx * 4];
1639 const struct sge_ofld_txq *tx = &adap->sge.ofldtxq[toe_idx * 4];
1640 int n = min(4, adap->sge.ofldqsets - 4 * toe_idx);
1641
1642 S("QType:", "TOE");
1643 T("TxQ ID:", q.cntxt_id);
1644 T("TxQ size:", q.size);
1645 T("TxQ inuse:", q.in_use);
1646 T("TxQ CIDX:", q.cidx);
1647 T("TxQ PIDX:", q.pidx);
1648 R("RspQ ID:", rspq.abs_id);
1649 R("RspQ size:", rspq.size);
1650 R("RspQE size:", rspq.iqe_len);
1651 R("RspQ CIDX:", rspq.cidx);
1652 R("RspQ Gen:", rspq.gen);
1653 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1654 S3("u", "Intr pktcnt:",
1655 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1656 R("FL ID:", fl.cntxt_id);
1657 R("FL size:", fl.size - 8);
1658 R("FL pend:", fl.pend_cred);
1659 R("FL avail:", fl.avail);
1660 R("FL PIDX:", fl.pidx);
1661 R("FL CIDX:", fl.cidx);
1662 } else if (rdma_idx < rdma_entries) {
1663 const struct sge_ofld_rxq *rx =
1664 &adap->sge.rdmarxq[rdma_idx * 4];
1665 int n = min(4, adap->sge.rdmaqs - 4 * rdma_idx);
1666
1667 S("QType:", "RDMA-CPL");
1668 R("RspQ ID:", rspq.abs_id);
1669 R("RspQ size:", rspq.size);
1670 R("RspQE size:", rspq.iqe_len);
1671 R("RspQ CIDX:", rspq.cidx);
1672 R("RspQ Gen:", rspq.gen);
1673 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1674 S3("u", "Intr pktcnt:",
1675 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1676 R("FL ID:", fl.cntxt_id);
1677 R("FL size:", fl.size - 8);
1678 R("FL pend:", fl.pend_cred);
1679 R("FL avail:", fl.avail);
1680 R("FL PIDX:", fl.pidx);
1681 R("FL CIDX:", fl.cidx);
1682 } else if (ciq_idx < ciq_entries) {
1683 const struct sge_ofld_rxq *rx = &adap->sge.rdmaciq[ciq_idx * 4];
1684 int n = min(4, adap->sge.rdmaciqs - 4 * ciq_idx);
1685
1686 S("QType:", "RDMA-CIQ");
1687 R("RspQ ID:", rspq.abs_id);
1688 R("RspQ size:", rspq.size);
1689 R("RspQE size:", rspq.iqe_len);
1690 R("RspQ CIDX:", rspq.cidx);
1691 R("RspQ Gen:", rspq.gen);
1692 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1693 S3("u", "Intr pktcnt:",
1694 adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1695 } else if (ctrl_idx < ctrl_entries) {
1696 const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
1697 int n = min(4, adap->params.nports - 4 * ctrl_idx);
1698
1699 S("QType:", "Control");
1700 T("TxQ ID:", q.cntxt_id);
1701 T("TxQ size:", q.size);
1702 T("TxQ inuse:", q.in_use);
1703 T("TxQ CIDX:", q.cidx);
1704 T("TxQ PIDX:", q.pidx);
1705 } else if (fq_idx == 0) {
1706 const struct sge_rspq *evtq = &adap->sge.fw_evtq;
1707
1708 seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
1709 seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
1710 seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
1711 seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
1712 seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
1713 seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
1714 seq_printf(seq, "%-12s %16u\n", "Intr delay:",
1715 qtimer_val(adap, evtq));
1716 seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
1717 adap->sge.counter_val[evtq->pktcnt_idx]);
1718 }
1719#undef R
1720#undef T
1721#undef S
1722#undef S3
1723return 0;
1724}
1725
1726static int sge_queue_entries(const struct adapter *adap)
1727{
1728 return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
1729 DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
1730 DIV_ROUND_UP(adap->sge.rdmaqs, 4) +
1731 DIV_ROUND_UP(adap->sge.rdmaciqs, 4) +
1732 DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
1733}
1734
1735static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
1736{
1737 int entries = sge_queue_entries(seq->private);
1738
1739 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1740}
1741
1742static void sge_queue_stop(struct seq_file *seq, void *v)
1743{
1744}
1745
1746static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
1747{
1748 int entries = sge_queue_entries(seq->private);
1749
1750 ++*pos;
1751 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1752}
1753
1754static const struct seq_operations sge_qinfo_seq_ops = {
1755 .start = sge_queue_start,
1756 .next = sge_queue_next,
1757 .stop = sge_queue_stop,
1758 .show = sge_qinfo_show
1759};
1760
1761static int sge_qinfo_open(struct inode *inode, struct file *file)
1762{
1763 int res = seq_open(file, &sge_qinfo_seq_ops);
1764
1765 if (!res) {
1766 struct seq_file *seq = file->private_data;
1767
1768 seq->private = inode->i_private;
1769 }
1770 return res;
1771}
1772
1773static const struct file_operations sge_qinfo_debugfs_fops = {
1774 .owner = THIS_MODULE,
1775 .open = sge_qinfo_open,
1776 .read = seq_read,
1777 .llseek = seq_lseek,
1778 .release = seq_release,
1779};
1780
49216c1c
HS
1781int mem_open(struct inode *inode, struct file *file)
1782{
1783 unsigned int mem;
1784 struct adapter *adap;
1785
1786 file->private_data = inode->i_private;
1787
1788 mem = (uintptr_t)file->private_data & 0x3;
1789 adap = file->private_data - mem;
1790
1791 (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
1792
1793 return 0;
1794}
1795
fd88b31a
HS
1796static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
1797 loff_t *ppos)
1798{
1799 loff_t pos = *ppos;
1800 loff_t avail = file_inode(file)->i_size;
1801 unsigned int mem = (uintptr_t)file->private_data & 3;
1802 struct adapter *adap = file->private_data - mem;
1803 __be32 *data;
1804 int ret;
1805
1806 if (pos < 0)
1807 return -EINVAL;
1808 if (pos >= avail)
1809 return 0;
1810 if (count > avail - pos)
1811 count = avail - pos;
1812
1813 data = t4_alloc_mem(count);
1814 if (!data)
1815 return -ENOMEM;
1816
1817 spin_lock(&adap->win0_lock);
1818 ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
1819 spin_unlock(&adap->win0_lock);
1820 if (ret) {
1821 t4_free_mem(data);
1822 return ret;
1823 }
1824 ret = copy_to_user(buf, data, count);
1825
1826 t4_free_mem(data);
1827 if (ret)
1828 return -EFAULT;
1829
1830 *ppos = pos + count;
1831 return count;
1832}
fd88b31a
HS
1833static const struct file_operations mem_debugfs_fops = {
1834 .owner = THIS_MODULE,
1835 .open = simple_open,
1836 .read = mem_read,
1837 .llseek = default_llseek,
1838};
1839
49216c1c
HS
1840static void set_debugfs_file_size(struct dentry *de, loff_t size)
1841{
1842 if (!IS_ERR(de) && de->d_inode)
1843 de->d_inode->i_size = size;
1844}
1845
fd88b31a
HS
1846static void add_debugfs_mem(struct adapter *adap, const char *name,
1847 unsigned int idx, unsigned int size_mb)
1848{
1849 struct dentry *de;
1850
1851 de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root,
1852 (void *)adap + idx, &mem_debugfs_fops);
1853 if (de && de->d_inode)
1854 de->d_inode->i_size = size_mb << 20;
1855}
1856
1857/* Add an array of Debug FS files.
1858 */
1859void add_debugfs_files(struct adapter *adap,
1860 struct t4_debugfs_entry *files,
1861 unsigned int nfiles)
1862{
1863 int i;
1864
1865 /* debugfs support is best effort */
1866 for (i = 0; i < nfiles; i++)
1867 debugfs_create_file(files[i].name, files[i].mode,
1868 adap->debugfs_root,
1869 (void *)adap + files[i].data,
1870 files[i].ops);
1871}
1872
1873int t4_setup_debugfs(struct adapter *adap)
1874{
1875 int i;
1876 u32 size;
49216c1c 1877 struct dentry *de;
fd88b31a
HS
1878
1879 static struct t4_debugfs_entry t4_debugfs_files[] = {
f1ff24aa 1880 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
74b3092c 1881 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
b58b6676 1882 { "clk", &clk_debugfs_fops, S_IRUSR, 0 },
49aa284f 1883 { "devlog", &devlog_fops, S_IRUSR, 0 },
fd88b31a 1884 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
ef82f662 1885 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
688ea5fe
HS
1886 { "rss", &rss_debugfs_fops, S_IRUSR, 0 },
1887 { "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
1888 { "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
1889 { "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
1890 { "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
dc9daab2 1891 { "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
e5f0e43b
HS
1892 { "ibq_tp0", &cim_ibq_fops, S_IRUSR, 0 },
1893 { "ibq_tp1", &cim_ibq_fops, S_IRUSR, 1 },
1894 { "ibq_ulp", &cim_ibq_fops, S_IRUSR, 2 },
1895 { "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
1896 { "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
1897 { "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
c778af7d
HS
1898 { "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
1899 { "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
1900 { "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
1901 { "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
1902 { "obq_sge", &cim_obq_fops, S_IRUSR, 4 },
1903 { "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
2d277b3b 1904 { "tp_la", &tp_la_fops, S_IRUSR, 0 },
797ff0f5 1905 { "ulprx_la", &ulprx_la_fops, S_IRUSR, 0 },
70a5f3bb 1906 { "sensors", &sensors_debugfs_fops, S_IRUSR, 0 },
b3bbe36a 1907 { "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
b5a02f50
AB
1908#if IS_ENABLED(CONFIG_IPV6)
1909 { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
1910#endif
fd88b31a
HS
1911 };
1912
c778af7d
HS
1913 /* Debug FS nodes common to all T5 and later adapters.
1914 */
1915 static struct t4_debugfs_entry t5_debugfs_files[] = {
1916 { "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
1917 { "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
1918 };
1919
fd88b31a
HS
1920 add_debugfs_files(adap,
1921 t4_debugfs_files,
1922 ARRAY_SIZE(t4_debugfs_files));
c778af7d
HS
1923 if (!is_t4(adap->params.chip))
1924 add_debugfs_files(adap,
1925 t5_debugfs_files,
1926 ARRAY_SIZE(t5_debugfs_files));
fd88b31a 1927
6559a7e8
HS
1928 i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
1929 if (i & EDRAM0_ENABLE_F) {
1930 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
1931 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
fd88b31a 1932 }
6559a7e8
HS
1933 if (i & EDRAM1_ENABLE_F) {
1934 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
1935 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
fd88b31a
HS
1936 }
1937 if (is_t4(adap->params.chip)) {
6559a7e8
HS
1938 size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
1939 if (i & EXT_MEM_ENABLE_F)
fd88b31a 1940 add_debugfs_mem(adap, "mc", MEM_MC,
6559a7e8 1941 EXT_MEM_SIZE_G(size));
fd88b31a 1942 } else {
6559a7e8
HS
1943 if (i & EXT_MEM0_ENABLE_F) {
1944 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
fd88b31a 1945 add_debugfs_mem(adap, "mc0", MEM_MC0,
6559a7e8 1946 EXT_MEM0_SIZE_G(size));
fd88b31a 1947 }
6559a7e8
HS
1948 if (i & EXT_MEM1_ENABLE_F) {
1949 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
fd88b31a 1950 add_debugfs_mem(adap, "mc1", MEM_MC1,
6559a7e8 1951 EXT_MEM1_SIZE_G(size));
fd88b31a
HS
1952 }
1953 }
49216c1c
HS
1954
1955 de = debugfs_create_file("flash", S_IRUSR, adap->debugfs_root, adap,
1956 &flash_debugfs_fops);
1957 set_debugfs_file_size(de, adap->params.sf_size);
1958
fd88b31a
HS
1959 return 0;
1960}
This page took 0.251279 seconds and 5 git commands to generate.