GNU Linux-libre 4.14.254-gnu1
[releases.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_debugfs.c
1 /*
2  * This file is part of the Chelsio T4 Ethernet driver for Linux.
3  *
4  * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  */
34
35 #include <linux/seq_file.h>
36 #include <linux/debugfs.h>
37 #include <linux/string_helpers.h>
38 #include <linux/sort.h>
39 #include <linux/ctype.h>
40
41 #include "cxgb4.h"
42 #include "t4_regs.h"
43 #include "t4_values.h"
44 #include "t4fw_api.h"
45 #include "cxgb4_debugfs.h"
46 #include "clip_tbl.h"
47 #include "l2t.h"
48
49 /* generic seq_file support for showing a table of size rows x width. */
50 static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
51 {
52         pos -= tb->skip_first;
53         return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
54 }
55
56 static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
57 {
58         struct seq_tab *tb = seq->private;
59
60         if (tb->skip_first && *pos == 0)
61                 return SEQ_START_TOKEN;
62
63         return seq_tab_get_idx(tb, *pos);
64 }
65
66 static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
67 {
68         v = seq_tab_get_idx(seq->private, *pos + 1);
69         ++(*pos);
70         return v;
71 }
72
73 static void seq_tab_stop(struct seq_file *seq, void *v)
74 {
75 }
76
77 static 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
84 static 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
91 struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
92                              unsigned int width, unsigned int have_header,
93                              int (*show)(struct seq_file *seq, void *v, int i))
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
107 /* Trim the size of a seq_tab to the supplied number of rows.  The operation is
108  * irreversible.
109  */
110 static 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
118 static 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
135 static 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
153 static int cim_la_show_t6(struct seq_file *seq, void *v, int idx)
154 {
155         if (v == SEQ_START_TOKEN) {
156                 seq_puts(seq, "Status   Inst    Data      PC     LS0Stat  "
157                          "LS0Addr  LS0Data  LS1Stat  LS1Addr  LS1Data\n");
158         } else {
159                 const u32 *p = v;
160
161                 seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x %08x %08x %08x %08x %08x %08x\n",
162                            (p[9] >> 16) & 0xff,       /* Status */
163                            p[9] & 0xffff, p[8] >> 16, /* Inst */
164                            p[8] & 0xffff, p[7] >> 16, /* Data */
165                            p[7] & 0xffff, p[6] >> 16, /* PC */
166                            p[2], p[1], p[0],      /* LS0 Stat, Addr and Data */
167                            p[5], p[4], p[3]);     /* LS1 Stat, Addr and Data */
168         }
169         return 0;
170 }
171
172 static int cim_la_show_pc_t6(struct seq_file *seq, void *v, int idx)
173 {
174         if (v == SEQ_START_TOKEN) {
175                 seq_puts(seq, "Status   Inst    Data      PC\n");
176         } else {
177                 const u32 *p = v;
178
179                 seq_printf(seq, "  %02x   %08x %08x %08x\n",
180                            p[3] & 0xff, p[2], p[1], p[0]);
181                 seq_printf(seq, "  %02x   %02x%06x %02x%06x %02x%06x\n",
182                            (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
183                            p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
184                 seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x\n",
185                            (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
186                            p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
187                            p[6] >> 16);
188         }
189         return 0;
190 }
191
192 static int cim_la_open(struct inode *inode, struct file *file)
193 {
194         int ret;
195         unsigned int cfg;
196         struct seq_tab *p;
197         struct adapter *adap = inode->i_private;
198
199         ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
200         if (ret)
201                 return ret;
202
203         if (is_t6(adap->params.chip)) {
204                 /* +1 to account for integer division of CIMLA_SIZE/10 */
205                 p = seq_open_tab(file, (adap->params.cim_la_size / 10) + 1,
206                                  10 * sizeof(u32), 1,
207                                  cfg & UPDBGLACAPTPCONLY_F ?
208                                         cim_la_show_pc_t6 : cim_la_show_t6);
209         } else {
210                 p = seq_open_tab(file, adap->params.cim_la_size / 8,
211                                  8 * sizeof(u32), 1,
212                                  cfg & UPDBGLACAPTPCONLY_F ? cim_la_show_3in1 :
213                                                              cim_la_show);
214         }
215         if (!p)
216                 return -ENOMEM;
217
218         ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
219         if (ret)
220                 seq_release_private(inode, file);
221         return ret;
222 }
223
224 static const struct file_operations cim_la_fops = {
225         .owner   = THIS_MODULE,
226         .open    = cim_la_open,
227         .read    = seq_read,
228         .llseek  = seq_lseek,
229         .release = seq_release_private
230 };
231
232 static int cim_pif_la_show(struct seq_file *seq, void *v, int idx)
233 {
234         const u32 *p = v;
235
236         if (v == SEQ_START_TOKEN) {
237                 seq_puts(seq, "Cntl ID DataBE   Addr                 Data\n");
238         } else if (idx < CIM_PIFLA_SIZE) {
239                 seq_printf(seq, " %02x  %02x  %04x  %08x %08x%08x%08x%08x\n",
240                            (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f,
241                            p[5] & 0xffff, p[4], p[3], p[2], p[1], p[0]);
242         } else {
243                 if (idx == CIM_PIFLA_SIZE)
244                         seq_puts(seq, "\nCntl ID               Data\n");
245                 seq_printf(seq, " %02x  %02x %08x%08x%08x%08x\n",
246                            (p[4] >> 6) & 0xff, p[4] & 0x3f,
247                            p[3], p[2], p[1], p[0]);
248         }
249         return 0;
250 }
251
252 static int cim_pif_la_open(struct inode *inode, struct file *file)
253 {
254         struct seq_tab *p;
255         struct adapter *adap = inode->i_private;
256
257         p = seq_open_tab(file, 2 * CIM_PIFLA_SIZE, 6 * sizeof(u32), 1,
258                          cim_pif_la_show);
259         if (!p)
260                 return -ENOMEM;
261
262         t4_cim_read_pif_la(adap, (u32 *)p->data,
263                            (u32 *)p->data + 6 * CIM_PIFLA_SIZE, NULL, NULL);
264         return 0;
265 }
266
267 static const struct file_operations cim_pif_la_fops = {
268         .owner   = THIS_MODULE,
269         .open    = cim_pif_la_open,
270         .read    = seq_read,
271         .llseek  = seq_lseek,
272         .release = seq_release_private
273 };
274
275 static int cim_ma_la_show(struct seq_file *seq, void *v, int idx)
276 {
277         const u32 *p = v;
278
279         if (v == SEQ_START_TOKEN) {
280                 seq_puts(seq, "\n");
281         } else if (idx < CIM_MALA_SIZE) {
282                 seq_printf(seq, "%02x%08x%08x%08x%08x\n",
283                            p[4], p[3], p[2], p[1], p[0]);
284         } else {
285                 if (idx == CIM_MALA_SIZE)
286                         seq_puts(seq,
287                                  "\nCnt ID Tag UE       Data       RDY VLD\n");
288                 seq_printf(seq, "%3u %2u  %x   %u %08x%08x  %u   %u\n",
289                            (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
290                            (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
291                            (p[1] >> 2) | ((p[2] & 3) << 30),
292                            (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
293                            p[0] & 1);
294         }
295         return 0;
296 }
297
298 static int cim_ma_la_open(struct inode *inode, struct file *file)
299 {
300         struct seq_tab *p;
301         struct adapter *adap = inode->i_private;
302
303         p = seq_open_tab(file, 2 * CIM_MALA_SIZE, 5 * sizeof(u32), 1,
304                          cim_ma_la_show);
305         if (!p)
306                 return -ENOMEM;
307
308         t4_cim_read_ma_la(adap, (u32 *)p->data,
309                           (u32 *)p->data + 5 * CIM_MALA_SIZE);
310         return 0;
311 }
312
313 static const struct file_operations cim_ma_la_fops = {
314         .owner   = THIS_MODULE,
315         .open    = cim_ma_la_open,
316         .read    = seq_read,
317         .llseek  = seq_lseek,
318         .release = seq_release_private
319 };
320
321 static int cim_qcfg_show(struct seq_file *seq, void *v)
322 {
323         static const char * const qname[] = {
324                 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
325                 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
326                 "SGE0-RX", "SGE1-RX"
327         };
328
329         int i;
330         struct adapter *adap = seq->private;
331         u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
332         u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
333         u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
334         u16 thres[CIM_NUM_IBQ];
335         u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
336         u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
337         u32 *p = stat;
338         int cim_num_obq = is_t4(adap->params.chip) ?
339                                 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
340
341         i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
342                         UP_IBQ_0_SHADOW_RDADDR_A,
343                         ARRAY_SIZE(stat), stat);
344         if (!i) {
345                 if (is_t4(adap->params.chip)) {
346                         i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
347                                         ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
348                         wr = obq_wr_t4;
349                 } else {
350                         i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
351                                         ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
352                         wr = obq_wr_t5;
353                 }
354         }
355         if (i)
356                 return i;
357
358         t4_read_cimq_cfg(adap, base, size, thres);
359
360         seq_printf(seq,
361                    "  Queue  Base  Size Thres  RdPtr WrPtr  SOP  EOP Avail\n");
362         for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
363                 seq_printf(seq, "%7s %5x %5u %5u %6x  %4x %4u %4u %5u\n",
364                            qname[i], base[i], size[i], thres[i],
365                            IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
366                            QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
367                            QUEREMFLITS_G(p[2]) * 16);
368         for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
369                 seq_printf(seq, "%7s %5x %5u %12x  %4x %4u %4u %5u\n",
370                            qname[i], base[i], size[i],
371                            QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
372                            QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
373                            QUEREMFLITS_G(p[2]) * 16);
374         return 0;
375 }
376
377 static int cim_qcfg_open(struct inode *inode, struct file *file)
378 {
379         return single_open(file, cim_qcfg_show, inode->i_private);
380 }
381
382 static const struct file_operations cim_qcfg_fops = {
383         .owner   = THIS_MODULE,
384         .open    = cim_qcfg_open,
385         .read    = seq_read,
386         .llseek  = seq_lseek,
387         .release = single_release,
388 };
389
390 static int cimq_show(struct seq_file *seq, void *v, int idx)
391 {
392         const u32 *p = v;
393
394         seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
395                    p[2], p[3]);
396         return 0;
397 }
398
399 static int cim_ibq_open(struct inode *inode, struct file *file)
400 {
401         int ret;
402         struct seq_tab *p;
403         unsigned int qid = (uintptr_t)inode->i_private & 7;
404         struct adapter *adap = inode->i_private - qid;
405
406         p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
407         if (!p)
408                 return -ENOMEM;
409
410         ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
411         if (ret < 0)
412                 seq_release_private(inode, file);
413         else
414                 ret = 0;
415         return ret;
416 }
417
418 static const struct file_operations cim_ibq_fops = {
419         .owner   = THIS_MODULE,
420         .open    = cim_ibq_open,
421         .read    = seq_read,
422         .llseek  = seq_lseek,
423         .release = seq_release_private
424 };
425
426 static int cim_obq_open(struct inode *inode, struct file *file)
427 {
428         int ret;
429         struct seq_tab *p;
430         unsigned int qid = (uintptr_t)inode->i_private & 7;
431         struct adapter *adap = inode->i_private - qid;
432
433         p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
434         if (!p)
435                 return -ENOMEM;
436
437         ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
438         if (ret < 0) {
439                 seq_release_private(inode, file);
440         } else {
441                 seq_tab_trim(p, ret / 4);
442                 ret = 0;
443         }
444         return ret;
445 }
446
447 static const struct file_operations cim_obq_fops = {
448         .owner   = THIS_MODULE,
449         .open    = cim_obq_open,
450         .read    = seq_read,
451         .llseek  = seq_lseek,
452         .release = seq_release_private
453 };
454
455 struct field_desc {
456         const char *name;
457         unsigned int start;
458         unsigned int width;
459 };
460
461 static void field_desc_show(struct seq_file *seq, u64 v,
462                             const struct field_desc *p)
463 {
464         char buf[32];
465         int line_size = 0;
466
467         while (p->name) {
468                 u64 mask = (1ULL << p->width) - 1;
469                 int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
470                                     ((unsigned long long)v >> p->start) & mask);
471
472                 if (line_size + len >= 79) {
473                         line_size = 8;
474                         seq_puts(seq, "\n        ");
475                 }
476                 seq_printf(seq, "%s ", buf);
477                 line_size += len + 1;
478                 p++;
479         }
480         seq_putc(seq, '\n');
481 }
482
483 static struct field_desc tp_la0[] = {
484         { "RcfOpCodeOut", 60, 4 },
485         { "State", 56, 4 },
486         { "WcfState", 52, 4 },
487         { "RcfOpcSrcOut", 50, 2 },
488         { "CRxError", 49, 1 },
489         { "ERxError", 48, 1 },
490         { "SanityFailed", 47, 1 },
491         { "SpuriousMsg", 46, 1 },
492         { "FlushInputMsg", 45, 1 },
493         { "FlushInputCpl", 44, 1 },
494         { "RssUpBit", 43, 1 },
495         { "RssFilterHit", 42, 1 },
496         { "Tid", 32, 10 },
497         { "InitTcb", 31, 1 },
498         { "LineNumber", 24, 7 },
499         { "Emsg", 23, 1 },
500         { "EdataOut", 22, 1 },
501         { "Cmsg", 21, 1 },
502         { "CdataOut", 20, 1 },
503         { "EreadPdu", 19, 1 },
504         { "CreadPdu", 18, 1 },
505         { "TunnelPkt", 17, 1 },
506         { "RcfPeerFin", 16, 1 },
507         { "RcfReasonOut", 12, 4 },
508         { "TxCchannel", 10, 2 },
509         { "RcfTxChannel", 8, 2 },
510         { "RxEchannel", 6, 2 },
511         { "RcfRxChannel", 5, 1 },
512         { "RcfDataOutSrdy", 4, 1 },
513         { "RxDvld", 3, 1 },
514         { "RxOoDvld", 2, 1 },
515         { "RxCongestion", 1, 1 },
516         { "TxCongestion", 0, 1 },
517         { NULL }
518 };
519
520 static int tp_la_show(struct seq_file *seq, void *v, int idx)
521 {
522         const u64 *p = v;
523
524         field_desc_show(seq, *p, tp_la0);
525         return 0;
526 }
527
528 static int tp_la_show2(struct seq_file *seq, void *v, int idx)
529 {
530         const u64 *p = v;
531
532         if (idx)
533                 seq_putc(seq, '\n');
534         field_desc_show(seq, p[0], tp_la0);
535         if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
536                 field_desc_show(seq, p[1], tp_la0);
537         return 0;
538 }
539
540 static int tp_la_show3(struct seq_file *seq, void *v, int idx)
541 {
542         static struct field_desc tp_la1[] = {
543                 { "CplCmdIn", 56, 8 },
544                 { "CplCmdOut", 48, 8 },
545                 { "ESynOut", 47, 1 },
546                 { "EAckOut", 46, 1 },
547                 { "EFinOut", 45, 1 },
548                 { "ERstOut", 44, 1 },
549                 { "SynIn", 43, 1 },
550                 { "AckIn", 42, 1 },
551                 { "FinIn", 41, 1 },
552                 { "RstIn", 40, 1 },
553                 { "DataIn", 39, 1 },
554                 { "DataInVld", 38, 1 },
555                 { "PadIn", 37, 1 },
556                 { "RxBufEmpty", 36, 1 },
557                 { "RxDdp", 35, 1 },
558                 { "RxFbCongestion", 34, 1 },
559                 { "TxFbCongestion", 33, 1 },
560                 { "TxPktSumSrdy", 32, 1 },
561                 { "RcfUlpType", 28, 4 },
562                 { "Eread", 27, 1 },
563                 { "Ebypass", 26, 1 },
564                 { "Esave", 25, 1 },
565                 { "Static0", 24, 1 },
566                 { "Cread", 23, 1 },
567                 { "Cbypass", 22, 1 },
568                 { "Csave", 21, 1 },
569                 { "CPktOut", 20, 1 },
570                 { "RxPagePoolFull", 18, 2 },
571                 { "RxLpbkPkt", 17, 1 },
572                 { "TxLpbkPkt", 16, 1 },
573                 { "RxVfValid", 15, 1 },
574                 { "SynLearned", 14, 1 },
575                 { "SetDelEntry", 13, 1 },
576                 { "SetInvEntry", 12, 1 },
577                 { "CpcmdDvld", 11, 1 },
578                 { "CpcmdSave", 10, 1 },
579                 { "RxPstructsFull", 8, 2 },
580                 { "EpcmdDvld", 7, 1 },
581                 { "EpcmdFlush", 6, 1 },
582                 { "EpcmdTrimPrefix", 5, 1 },
583                 { "EpcmdTrimPostfix", 4, 1 },
584                 { "ERssIp4Pkt", 3, 1 },
585                 { "ERssIp6Pkt", 2, 1 },
586                 { "ERssTcpUdpPkt", 1, 1 },
587                 { "ERssFceFipPkt", 0, 1 },
588                 { NULL }
589         };
590         static struct field_desc tp_la2[] = {
591                 { "CplCmdIn", 56, 8 },
592                 { "MpsVfVld", 55, 1 },
593                 { "MpsPf", 52, 3 },
594                 { "MpsVf", 44, 8 },
595                 { "SynIn", 43, 1 },
596                 { "AckIn", 42, 1 },
597                 { "FinIn", 41, 1 },
598                 { "RstIn", 40, 1 },
599                 { "DataIn", 39, 1 },
600                 { "DataInVld", 38, 1 },
601                 { "PadIn", 37, 1 },
602                 { "RxBufEmpty", 36, 1 },
603                 { "RxDdp", 35, 1 },
604                 { "RxFbCongestion", 34, 1 },
605                 { "TxFbCongestion", 33, 1 },
606                 { "TxPktSumSrdy", 32, 1 },
607                 { "RcfUlpType", 28, 4 },
608                 { "Eread", 27, 1 },
609                 { "Ebypass", 26, 1 },
610                 { "Esave", 25, 1 },
611                 { "Static0", 24, 1 },
612                 { "Cread", 23, 1 },
613                 { "Cbypass", 22, 1 },
614                 { "Csave", 21, 1 },
615                 { "CPktOut", 20, 1 },
616                 { "RxPagePoolFull", 18, 2 },
617                 { "RxLpbkPkt", 17, 1 },
618                 { "TxLpbkPkt", 16, 1 },
619                 { "RxVfValid", 15, 1 },
620                 { "SynLearned", 14, 1 },
621                 { "SetDelEntry", 13, 1 },
622                 { "SetInvEntry", 12, 1 },
623                 { "CpcmdDvld", 11, 1 },
624                 { "CpcmdSave", 10, 1 },
625                 { "RxPstructsFull", 8, 2 },
626                 { "EpcmdDvld", 7, 1 },
627                 { "EpcmdFlush", 6, 1 },
628                 { "EpcmdTrimPrefix", 5, 1 },
629                 { "EpcmdTrimPostfix", 4, 1 },
630                 { "ERssIp4Pkt", 3, 1 },
631                 { "ERssIp6Pkt", 2, 1 },
632                 { "ERssTcpUdpPkt", 1, 1 },
633                 { "ERssFceFipPkt", 0, 1 },
634                 { NULL }
635         };
636         const u64 *p = v;
637
638         if (idx)
639                 seq_putc(seq, '\n');
640         field_desc_show(seq, p[0], tp_la0);
641         if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
642                 field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
643         return 0;
644 }
645
646 static int tp_la_open(struct inode *inode, struct file *file)
647 {
648         struct seq_tab *p;
649         struct adapter *adap = inode->i_private;
650
651         switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
652         case 2:
653                 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
654                                  tp_la_show2);
655                 break;
656         case 3:
657                 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
658                                  tp_la_show3);
659                 break;
660         default:
661                 p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
662         }
663         if (!p)
664                 return -ENOMEM;
665
666         t4_tp_read_la(adap, (u64 *)p->data, NULL);
667         return 0;
668 }
669
670 static ssize_t tp_la_write(struct file *file, const char __user *buf,
671                            size_t count, loff_t *pos)
672 {
673         int err;
674         char s[32];
675         unsigned long val;
676         size_t size = min(sizeof(s) - 1, count);
677         struct adapter *adap = file_inode(file)->i_private;
678
679         if (copy_from_user(s, buf, size))
680                 return -EFAULT;
681         s[size] = '\0';
682         err = kstrtoul(s, 0, &val);
683         if (err)
684                 return err;
685         if (val > 0xffff)
686                 return -EINVAL;
687         adap->params.tp.la_mask = val << 16;
688         t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
689                          adap->params.tp.la_mask);
690         return count;
691 }
692
693 static const struct file_operations tp_la_fops = {
694         .owner   = THIS_MODULE,
695         .open    = tp_la_open,
696         .read    = seq_read,
697         .llseek  = seq_lseek,
698         .release = seq_release_private,
699         .write   = tp_la_write
700 };
701
702 static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
703 {
704         const u32 *p = v;
705
706         if (v == SEQ_START_TOKEN)
707                 seq_puts(seq, "      Pcmd        Type   Message"
708                          "                Data\n");
709         else
710                 seq_printf(seq, "%08x%08x  %4x  %08x  %08x%08x%08x%08x\n",
711                            p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
712         return 0;
713 }
714
715 static int ulprx_la_open(struct inode *inode, struct file *file)
716 {
717         struct seq_tab *p;
718         struct adapter *adap = inode->i_private;
719
720         p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
721                          ulprx_la_show);
722         if (!p)
723                 return -ENOMEM;
724
725         t4_ulprx_read_la(adap, (u32 *)p->data);
726         return 0;
727 }
728
729 static const struct file_operations ulprx_la_fops = {
730         .owner   = THIS_MODULE,
731         .open    = ulprx_la_open,
732         .read    = seq_read,
733         .llseek  = seq_lseek,
734         .release = seq_release_private
735 };
736
737 /* Show the PM memory stats.  These stats include:
738  *
739  * TX:
740  *   Read: memory read operation
741  *   Write Bypass: cut-through
742  *   Bypass + mem: cut-through and save copy
743  *
744  * RX:
745  *   Read: memory read
746  *   Write Bypass: cut-through
747  *   Flush: payload trim or drop
748  */
749 static int pm_stats_show(struct seq_file *seq, void *v)
750 {
751         static const char * const tx_pm_stats[] = {
752                 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
753         };
754         static const char * const rx_pm_stats[] = {
755                 "Read:", "Write bypass:", "Write mem:", "Flush:"
756         };
757
758         int i;
759         u32 tx_cnt[T6_PM_NSTATS], rx_cnt[T6_PM_NSTATS];
760         u64 tx_cyc[T6_PM_NSTATS], rx_cyc[T6_PM_NSTATS];
761         struct adapter *adap = seq->private;
762
763         t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
764         t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
765
766         seq_printf(seq, "%13s %10s  %20s\n", " ", "Tx pcmds", "Tx bytes");
767         for (i = 0; i < PM_NSTATS - 1; i++)
768                 seq_printf(seq, "%-13s %10u  %20llu\n",
769                            tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
770
771         seq_printf(seq, "%13s %10s  %20s\n", " ", "Rx pcmds", "Rx bytes");
772         for (i = 0; i < PM_NSTATS - 1; i++)
773                 seq_printf(seq, "%-13s %10u  %20llu\n",
774                            rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
775
776         if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
777                 /* In T5 the granularity of the total wait is too fine.
778                  * It is not useful as it reaches the max value too fast.
779                  * Hence display this Input FIFO wait for T6 onwards.
780                  */
781                 seq_printf(seq, "%13s %10s  %20s\n",
782                            " ", "Total wait", "Total Occupancy");
783                 seq_printf(seq, "Tx FIFO wait  %10u  %20llu\n",
784                            tx_cnt[i], tx_cyc[i]);
785                 seq_printf(seq, "Rx FIFO wait  %10u  %20llu\n",
786                            rx_cnt[i], rx_cyc[i]);
787
788                 /* Skip index 6 as there is nothing useful ihere */
789                 i += 2;
790
791                 /* At index 7, a new stat for read latency (count, total wait)
792                  * is added.
793                  */
794                 seq_printf(seq, "%13s %10s  %20s\n",
795                            " ", "Reads", "Total wait");
796                 seq_printf(seq, "Tx latency    %10u  %20llu\n",
797                            tx_cnt[i], tx_cyc[i]);
798                 seq_printf(seq, "Rx latency    %10u  %20llu\n",
799                            rx_cnt[i], rx_cyc[i]);
800         }
801         return 0;
802 }
803
804 static int pm_stats_open(struct inode *inode, struct file *file)
805 {
806         return single_open(file, pm_stats_show, inode->i_private);
807 }
808
809 static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
810                               size_t count, loff_t *pos)
811 {
812         struct adapter *adap = file_inode(file)->i_private;
813
814         t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
815         t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
816         return count;
817 }
818
819 static const struct file_operations pm_stats_debugfs_fops = {
820         .owner   = THIS_MODULE,
821         .open    = pm_stats_open,
822         .read    = seq_read,
823         .llseek  = seq_lseek,
824         .release = single_release,
825         .write   = pm_stats_clear
826 };
827
828 static int tx_rate_show(struct seq_file *seq, void *v)
829 {
830         u64 nrate[NCHAN], orate[NCHAN];
831         struct adapter *adap = seq->private;
832
833         t4_get_chan_txrate(adap, nrate, orate);
834         if (adap->params.arch.nchan == NCHAN) {
835                 seq_puts(seq, "              channel 0   channel 1   "
836                          "channel 2   channel 3\n");
837                 seq_printf(seq, "NIC B/s:     %10llu  %10llu  %10llu  %10llu\n",
838                            (unsigned long long)nrate[0],
839                            (unsigned long long)nrate[1],
840                            (unsigned long long)nrate[2],
841                            (unsigned long long)nrate[3]);
842                 seq_printf(seq, "Offload B/s: %10llu  %10llu  %10llu  %10llu\n",
843                            (unsigned long long)orate[0],
844                            (unsigned long long)orate[1],
845                            (unsigned long long)orate[2],
846                            (unsigned long long)orate[3]);
847         } else {
848                 seq_puts(seq, "              channel 0   channel 1\n");
849                 seq_printf(seq, "NIC B/s:     %10llu  %10llu\n",
850                            (unsigned long long)nrate[0],
851                            (unsigned long long)nrate[1]);
852                 seq_printf(seq, "Offload B/s: %10llu  %10llu\n",
853                            (unsigned long long)orate[0],
854                            (unsigned long long)orate[1]);
855         }
856         return 0;
857 }
858
859 DEFINE_SIMPLE_DEBUGFS_FILE(tx_rate);
860
861 static int cctrl_tbl_show(struct seq_file *seq, void *v)
862 {
863         static const char * const dec_fac[] = {
864                 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
865                 "0.9375" };
866
867         int i;
868         u16 (*incr)[NCCTRL_WIN];
869         struct adapter *adap = seq->private;
870
871         incr = kmalloc(sizeof(*incr) * NMTUS, GFP_KERNEL);
872         if (!incr)
873                 return -ENOMEM;
874
875         t4_read_cong_tbl(adap, incr);
876
877         for (i = 0; i < NCCTRL_WIN; ++i) {
878                 seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
879                            incr[0][i], incr[1][i], incr[2][i], incr[3][i],
880                            incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
881                 seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
882                            incr[8][i], incr[9][i], incr[10][i], incr[11][i],
883                            incr[12][i], incr[13][i], incr[14][i], incr[15][i],
884                            adap->params.a_wnd[i],
885                            dec_fac[adap->params.b_wnd[i]]);
886         }
887
888         kfree(incr);
889         return 0;
890 }
891
892 DEFINE_SIMPLE_DEBUGFS_FILE(cctrl_tbl);
893
894 /* Format a value in a unit that differs from the value's native unit by the
895  * given factor.
896  */
897 static char *unit_conv(char *buf, size_t len, unsigned int val,
898                        unsigned int factor)
899 {
900         unsigned int rem = val % factor;
901
902         if (rem == 0) {
903                 snprintf(buf, len, "%u", val / factor);
904         } else {
905                 while (rem % 10 == 0)
906                         rem /= 10;
907                 snprintf(buf, len, "%u.%u", val / factor, rem);
908         }
909         return buf;
910 }
911
912 static int clk_show(struct seq_file *seq, void *v)
913 {
914         char buf[32];
915         struct adapter *adap = seq->private;
916         unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk;  /* in ps */
917         u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
918         unsigned int tre = TIMERRESOLUTION_G(res);
919         unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
920         unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
921
922         seq_printf(seq, "Core clock period: %s ns\n",
923                    unit_conv(buf, sizeof(buf), cclk_ps, 1000));
924         seq_printf(seq, "TP timer tick: %s us\n",
925                    unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
926         seq_printf(seq, "TCP timestamp tick: %s us\n",
927                    unit_conv(buf, sizeof(buf),
928                              (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
929         seq_printf(seq, "DACK tick: %s us\n",
930                    unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
931         seq_printf(seq, "DACK timer: %u us\n",
932                    ((cclk_ps << dack_re) / 1000000) *
933                    t4_read_reg(adap, TP_DACK_TIMER_A));
934         seq_printf(seq, "Retransmit min: %llu us\n",
935                    tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
936         seq_printf(seq, "Retransmit max: %llu us\n",
937                    tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
938         seq_printf(seq, "Persist timer min: %llu us\n",
939                    tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
940         seq_printf(seq, "Persist timer max: %llu us\n",
941                    tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
942         seq_printf(seq, "Keepalive idle timer: %llu us\n",
943                    tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
944         seq_printf(seq, "Keepalive interval: %llu us\n",
945                    tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
946         seq_printf(seq, "Initial SRTT: %llu us\n",
947                    tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
948         seq_printf(seq, "FINWAIT2 timer: %llu us\n",
949                    tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
950
951         return 0;
952 }
953
954 DEFINE_SIMPLE_DEBUGFS_FILE(clk);
955
956 /* Firmware Device Log dump. */
957 static const char * const devlog_level_strings[] = {
958         [FW_DEVLOG_LEVEL_EMERG]         = "EMERG",
959         [FW_DEVLOG_LEVEL_CRIT]          = "CRIT",
960         [FW_DEVLOG_LEVEL_ERR]           = "ERR",
961         [FW_DEVLOG_LEVEL_NOTICE]        = "NOTICE",
962         [FW_DEVLOG_LEVEL_INFO]          = "INFO",
963         [FW_DEVLOG_LEVEL_DEBUG]         = "DEBUG"
964 };
965
966 static const char * const devlog_facility_strings[] = {
967         [FW_DEVLOG_FACILITY_CORE]       = "CORE",
968         [FW_DEVLOG_FACILITY_CF]         = "CF",
969         [FW_DEVLOG_FACILITY_SCHED]      = "SCHED",
970         [FW_DEVLOG_FACILITY_TIMER]      = "TIMER",
971         [FW_DEVLOG_FACILITY_RES]        = "RES",
972         [FW_DEVLOG_FACILITY_HW]         = "HW",
973         [FW_DEVLOG_FACILITY_FLR]        = "FLR",
974         [FW_DEVLOG_FACILITY_DMAQ]       = "DMAQ",
975         [FW_DEVLOG_FACILITY_PHY]        = "PHY",
976         [FW_DEVLOG_FACILITY_MAC]        = "MAC",
977         [FW_DEVLOG_FACILITY_PORT]       = "PORT",
978         [FW_DEVLOG_FACILITY_VI]         = "VI",
979         [FW_DEVLOG_FACILITY_FILTER]     = "FILTER",
980         [FW_DEVLOG_FACILITY_ACL]        = "ACL",
981         [FW_DEVLOG_FACILITY_TM]         = "TM",
982         [FW_DEVLOG_FACILITY_QFC]        = "QFC",
983         [FW_DEVLOG_FACILITY_DCB]        = "DCB",
984         [FW_DEVLOG_FACILITY_ETH]        = "ETH",
985         [FW_DEVLOG_FACILITY_OFLD]       = "OFLD",
986         [FW_DEVLOG_FACILITY_RI]         = "RI",
987         [FW_DEVLOG_FACILITY_ISCSI]      = "ISCSI",
988         [FW_DEVLOG_FACILITY_FCOE]       = "FCOE",
989         [FW_DEVLOG_FACILITY_FOISCSI]    = "FOISCSI",
990         [FW_DEVLOG_FACILITY_FOFCOE]     = "FOFCOE"
991 };
992
993 /* Information gathered by Device Log Open routine for the display routine.
994  */
995 struct devlog_info {
996         unsigned int nentries;          /* number of entries in log[] */
997         unsigned int first;             /* first [temporal] entry in log[] */
998         struct fw_devlog_e log[0];      /* Firmware Device Log */
999 };
1000
1001 /* Dump a Firmaware Device Log entry.
1002  */
1003 static int devlog_show(struct seq_file *seq, void *v)
1004 {
1005         if (v == SEQ_START_TOKEN)
1006                 seq_printf(seq, "%10s  %15s  %8s  %8s  %s\n",
1007                            "Seq#", "Tstamp", "Level", "Facility", "Message");
1008         else {
1009                 struct devlog_info *dinfo = seq->private;
1010                 int fidx = (uintptr_t)v - 2;
1011                 unsigned long index;
1012                 struct fw_devlog_e *e;
1013
1014                 /* Get a pointer to the log entry to display.  Skip unused log
1015                  * entries.
1016                  */
1017                 index = dinfo->first + fidx;
1018                 if (index >= dinfo->nentries)
1019                         index -= dinfo->nentries;
1020                 e = &dinfo->log[index];
1021                 if (e->timestamp == 0)
1022                         return 0;
1023
1024                 /* Print the message.  This depends on the firmware using
1025                  * exactly the same formating strings as the kernel so we may
1026                  * eventually have to put a format interpreter in here ...
1027                  */
1028                 seq_printf(seq, "%10d  %15llu  %8s  %8s  ",
1029                            be32_to_cpu(e->seqno),
1030                            be64_to_cpu(e->timestamp),
1031                            (e->level < ARRAY_SIZE(devlog_level_strings)
1032                             ? devlog_level_strings[e->level]
1033                             : "UNKNOWN"),
1034                            (e->facility < ARRAY_SIZE(devlog_facility_strings)
1035                             ? devlog_facility_strings[e->facility]
1036                             : "UNKNOWN"));
1037                 seq_printf(seq, e->fmt,
1038                            be32_to_cpu(e->params[0]),
1039                            be32_to_cpu(e->params[1]),
1040                            be32_to_cpu(e->params[2]),
1041                            be32_to_cpu(e->params[3]),
1042                            be32_to_cpu(e->params[4]),
1043                            be32_to_cpu(e->params[5]),
1044                            be32_to_cpu(e->params[6]),
1045                            be32_to_cpu(e->params[7]));
1046         }
1047         return 0;
1048 }
1049
1050 /* Sequential File Operations for Device Log.
1051  */
1052 static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
1053 {
1054         if (pos > dinfo->nentries)
1055                 return NULL;
1056
1057         return (void *)(uintptr_t)(pos + 1);
1058 }
1059
1060 static void *devlog_start(struct seq_file *seq, loff_t *pos)
1061 {
1062         struct devlog_info *dinfo = seq->private;
1063
1064         return (*pos
1065                 ? devlog_get_idx(dinfo, *pos)
1066                 : SEQ_START_TOKEN);
1067 }
1068
1069 static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
1070 {
1071         struct devlog_info *dinfo = seq->private;
1072
1073         (*pos)++;
1074         return devlog_get_idx(dinfo, *pos);
1075 }
1076
1077 static void devlog_stop(struct seq_file *seq, void *v)
1078 {
1079 }
1080
1081 static const struct seq_operations devlog_seq_ops = {
1082         .start = devlog_start,
1083         .next  = devlog_next,
1084         .stop  = devlog_stop,
1085         .show  = devlog_show
1086 };
1087
1088 /* Set up for reading the firmware's device log.  We read the entire log here
1089  * and then display it incrementally in devlog_show().
1090  */
1091 static int devlog_open(struct inode *inode, struct file *file)
1092 {
1093         struct adapter *adap = inode->i_private;
1094         struct devlog_params *dparams = &adap->params.devlog;
1095         struct devlog_info *dinfo;
1096         unsigned int index;
1097         u32 fseqno;
1098         int ret;
1099
1100         /* If we don't know where the log is we can't do anything.
1101          */
1102         if (dparams->start == 0)
1103                 return -ENXIO;
1104
1105         /* Allocate the space to read in the firmware's device log and set up
1106          * for the iterated call to our display function.
1107          */
1108         dinfo = __seq_open_private(file, &devlog_seq_ops,
1109                                    sizeof(*dinfo) + dparams->size);
1110         if (!dinfo)
1111                 return -ENOMEM;
1112
1113         /* Record the basic log buffer information and read in the raw log.
1114          */
1115         dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
1116         dinfo->first = 0;
1117         spin_lock(&adap->win0_lock);
1118         ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
1119                            dparams->start, dparams->size, (__be32 *)dinfo->log,
1120                            T4_MEMORY_READ);
1121         spin_unlock(&adap->win0_lock);
1122         if (ret) {
1123                 seq_release_private(inode, file);
1124                 return ret;
1125         }
1126
1127         /* Find the earliest (lowest Sequence Number) log entry in the
1128          * circular Device Log.
1129          */
1130         for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
1131                 struct fw_devlog_e *e = &dinfo->log[index];
1132                 __u32 seqno;
1133
1134                 if (e->timestamp == 0)
1135                         continue;
1136
1137                 seqno = be32_to_cpu(e->seqno);
1138                 if (seqno < fseqno) {
1139                         fseqno = seqno;
1140                         dinfo->first = index;
1141                 }
1142         }
1143         return 0;
1144 }
1145
1146 static const struct file_operations devlog_fops = {
1147         .owner   = THIS_MODULE,
1148         .open    = devlog_open,
1149         .read    = seq_read,
1150         .llseek  = seq_lseek,
1151         .release = seq_release_private
1152 };
1153
1154 /* Show Firmware Mailbox Command/Reply Log
1155  *
1156  * Note that we don't do any locking when dumping the Firmware Mailbox Log so
1157  * it's possible that we can catch things during a log update and therefore
1158  * see partially corrupted log entries.  But it's probably Good Enough(tm).
1159  * If we ever decide that we want to make sure that we're dumping a coherent
1160  * log, we'd need to perform locking in the mailbox logging and in
1161  * mboxlog_open() where we'd need to grab the entire mailbox log in one go
1162  * like we do for the Firmware Device Log.
1163  */
1164 static int mboxlog_show(struct seq_file *seq, void *v)
1165 {
1166         struct adapter *adapter = seq->private;
1167         struct mbox_cmd_log *log = adapter->mbox_log;
1168         struct mbox_cmd *entry;
1169         int entry_idx, i;
1170
1171         if (v == SEQ_START_TOKEN) {
1172                 seq_printf(seq,
1173                            "%10s  %15s  %5s  %5s  %s\n",
1174                            "Seq#", "Tstamp", "Atime", "Etime",
1175                            "Command/Reply");
1176                 return 0;
1177         }
1178
1179         entry_idx = log->cursor + ((uintptr_t)v - 2);
1180         if (entry_idx >= log->size)
1181                 entry_idx -= log->size;
1182         entry = mbox_cmd_log_entry(log, entry_idx);
1183
1184         /* skip over unused entries */
1185         if (entry->timestamp == 0)
1186                 return 0;
1187
1188         seq_printf(seq, "%10u  %15llu  %5d  %5d",
1189                    entry->seqno, entry->timestamp,
1190                    entry->access, entry->execute);
1191         for (i = 0; i < MBOX_LEN / 8; i++) {
1192                 u64 flit = entry->cmd[i];
1193                 u32 hi = (u32)(flit >> 32);
1194                 u32 lo = (u32)flit;
1195
1196                 seq_printf(seq, "  %08x %08x", hi, lo);
1197         }
1198         seq_puts(seq, "\n");
1199         return 0;
1200 }
1201
1202 static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
1203 {
1204         struct adapter *adapter = seq->private;
1205         struct mbox_cmd_log *log = adapter->mbox_log;
1206
1207         return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
1208 }
1209
1210 static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
1211 {
1212         return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
1213 }
1214
1215 static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
1216 {
1217         ++*pos;
1218         return mboxlog_get_idx(seq, *pos);
1219 }
1220
1221 static void mboxlog_stop(struct seq_file *seq, void *v)
1222 {
1223 }
1224
1225 static const struct seq_operations mboxlog_seq_ops = {
1226         .start = mboxlog_start,
1227         .next  = mboxlog_next,
1228         .stop  = mboxlog_stop,
1229         .show  = mboxlog_show
1230 };
1231
1232 static int mboxlog_open(struct inode *inode, struct file *file)
1233 {
1234         int res = seq_open(file, &mboxlog_seq_ops);
1235
1236         if (!res) {
1237                 struct seq_file *seq = file->private_data;
1238
1239                 seq->private = inode->i_private;
1240         }
1241         return res;
1242 }
1243
1244 static const struct file_operations mboxlog_fops = {
1245         .owner   = THIS_MODULE,
1246         .open    = mboxlog_open,
1247         .read    = seq_read,
1248         .llseek  = seq_lseek,
1249         .release = seq_release,
1250 };
1251
1252 static int mbox_show(struct seq_file *seq, void *v)
1253 {
1254         static const char * const owner[] = { "none", "FW", "driver",
1255                                               "unknown", "<unread>" };
1256
1257         int i;
1258         unsigned int mbox = (uintptr_t)seq->private & 7;
1259         struct adapter *adap = seq->private - mbox;
1260         void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1261
1262         /* For T4 we don't have a shadow copy of the Mailbox Control register.
1263          * And since reading that real register causes a side effect of
1264          * granting ownership, we're best of simply not reading it at all.
1265          */
1266         if (is_t4(adap->params.chip)) {
1267                 i = 4; /* index of "<unread>" */
1268         } else {
1269                 unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
1270                 void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
1271
1272                 i = MBOWNER_G(readl(ctrl));
1273         }
1274
1275         seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
1276
1277         for (i = 0; i < MBOX_LEN; i += 8)
1278                 seq_printf(seq, "%016llx\n",
1279                            (unsigned long long)readq(addr + i));
1280         return 0;
1281 }
1282
1283 static int mbox_open(struct inode *inode, struct file *file)
1284 {
1285         return single_open(file, mbox_show, inode->i_private);
1286 }
1287
1288 static ssize_t mbox_write(struct file *file, const char __user *buf,
1289                           size_t count, loff_t *pos)
1290 {
1291         int i;
1292         char c = '\n', s[256];
1293         unsigned long long data[8];
1294         const struct inode *ino;
1295         unsigned int mbox;
1296         struct adapter *adap;
1297         void __iomem *addr;
1298         void __iomem *ctrl;
1299
1300         if (count > sizeof(s) - 1 || !count)
1301                 return -EINVAL;
1302         if (copy_from_user(s, buf, count))
1303                 return -EFAULT;
1304         s[count] = '\0';
1305
1306         if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
1307                    &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
1308                    &data[7], &c) < 8 || c != '\n')
1309                 return -EINVAL;
1310
1311         ino = file_inode(file);
1312         mbox = (uintptr_t)ino->i_private & 7;
1313         adap = ino->i_private - mbox;
1314         addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1315         ctrl = addr + MBOX_LEN;
1316
1317         if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
1318                 return -EBUSY;
1319
1320         for (i = 0; i < 8; i++)
1321                 writeq(data[i], addr + 8 * i);
1322
1323         writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
1324         return count;
1325 }
1326
1327 static const struct file_operations mbox_debugfs_fops = {
1328         .owner   = THIS_MODULE,
1329         .open    = mbox_open,
1330         .read    = seq_read,
1331         .llseek  = seq_lseek,
1332         .release = single_release,
1333         .write   = mbox_write
1334 };
1335
1336 static int mps_trc_show(struct seq_file *seq, void *v)
1337 {
1338         int enabled, i;
1339         struct trace_params tp;
1340         unsigned int trcidx = (uintptr_t)seq->private & 3;
1341         struct adapter *adap = seq->private - trcidx;
1342
1343         t4_get_trace_filter(adap, &tp, trcidx, &enabled);
1344         if (!enabled) {
1345                 seq_puts(seq, "tracer is disabled\n");
1346                 return 0;
1347         }
1348
1349         if (tp.skip_ofst * 8 >= TRACE_LEN) {
1350                 dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
1351                 return -EINVAL;
1352         }
1353         if (tp.port < 8) {
1354                 i = adap->chan_map[tp.port & 3];
1355                 if (i >= MAX_NPORTS) {
1356                         dev_err(adap->pdev_dev, "tracer %u is assigned "
1357                                 "to non-existing port\n", trcidx);
1358                         return -EINVAL;
1359                 }
1360                 seq_printf(seq, "tracer is capturing %s %s, ",
1361                            adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
1362         } else
1363                 seq_printf(seq, "tracer is capturing loopback %d, ",
1364                            tp.port - 8);
1365         seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
1366                    tp.min_len);
1367         seq_printf(seq, "packets captured %smatch filter\n",
1368                    tp.invert ? "do not " : "");
1369
1370         if (tp.skip_ofst) {
1371                 seq_puts(seq, "filter pattern: ");
1372                 for (i = 0; i < tp.skip_ofst * 2; i += 2)
1373                         seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
1374                 seq_putc(seq, '/');
1375                 for (i = 0; i < tp.skip_ofst * 2; i += 2)
1376                         seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
1377                 seq_puts(seq, "@0\n");
1378         }
1379
1380         seq_puts(seq, "filter pattern: ");
1381         for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
1382                 seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
1383         seq_putc(seq, '/');
1384         for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
1385                 seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
1386         seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
1387         return 0;
1388 }
1389
1390 static int mps_trc_open(struct inode *inode, struct file *file)
1391 {
1392         return single_open(file, mps_trc_show, inode->i_private);
1393 }
1394
1395 static unsigned int xdigit2int(unsigned char c)
1396 {
1397         return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
1398 }
1399
1400 #define TRC_PORT_NONE 0xff
1401 #define TRC_RSS_ENABLE 0x33
1402 #define TRC_RSS_DISABLE 0x13
1403
1404 /* Set an MPS trace filter.  Syntax is:
1405  *
1406  * disable
1407  *
1408  * to disable tracing, or
1409  *
1410  * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
1411  *
1412  * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
1413  * of the NIC's response qid obtained from sge_qinfo and pattern has the form
1414  *
1415  * <pattern data>[/<pattern mask>][@<anchor>]
1416  *
1417  * Up to 2 filter patterns can be specified.  If 2 are supplied the first one
1418  * must be anchored at 0.  An omitted mask is taken as a mask of 1s, an omitted
1419  * anchor is taken as 0.
1420  */
1421 static ssize_t mps_trc_write(struct file *file, const char __user *buf,
1422                              size_t count, loff_t *pos)
1423 {
1424         int i, enable, ret;
1425         u32 *data, *mask;
1426         struct trace_params tp;
1427         const struct inode *ino;
1428         unsigned int trcidx;
1429         char *s, *p, *word, *end;
1430         struct adapter *adap;
1431         u32 j;
1432
1433         ino = file_inode(file);
1434         trcidx = (uintptr_t)ino->i_private & 3;
1435         adap = ino->i_private - trcidx;
1436
1437         /* Don't accept input more than 1K, can't be anything valid except lots
1438          * of whitespace.  Well, use less.
1439          */
1440         if (count > 1024)
1441                 return -EFBIG;
1442         p = s = kzalloc(count + 1, GFP_USER);
1443         if (!s)
1444                 return -ENOMEM;
1445         if (copy_from_user(s, buf, count)) {
1446                 count = -EFAULT;
1447                 goto out;
1448         }
1449
1450         if (s[count - 1] == '\n')
1451                 s[count - 1] = '\0';
1452
1453         enable = strcmp("disable", s) != 0;
1454         if (!enable)
1455                 goto apply;
1456
1457         /* enable or disable trace multi rss filter */
1458         if (adap->trace_rss)
1459                 t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
1460         else
1461                 t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
1462
1463         memset(&tp, 0, sizeof(tp));
1464         tp.port = TRC_PORT_NONE;
1465         i = 0;  /* counts pattern nibbles */
1466
1467         while (p) {
1468                 while (isspace(*p))
1469                         p++;
1470                 word = strsep(&p, " ");
1471                 if (!*word)
1472                         break;
1473
1474                 if (!strncmp(word, "qid=", 4)) {
1475                         end = (char *)word + 4;
1476                         ret = kstrtouint(end, 10, &j);
1477                         if (ret)
1478                                 goto out;
1479                         if (!adap->trace_rss) {
1480                                 t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
1481                                 continue;
1482                         }
1483
1484                         switch (trcidx) {
1485                         case 0:
1486                                 t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
1487                                 break;
1488                         case 1:
1489                                 t4_write_reg(adap,
1490                                              MPS_TRC_FILTER1_RSS_CONTROL_A, j);
1491                                 break;
1492                         case 2:
1493                                 t4_write_reg(adap,
1494                                              MPS_TRC_FILTER2_RSS_CONTROL_A, j);
1495                                 break;
1496                         case 3:
1497                                 t4_write_reg(adap,
1498                                              MPS_TRC_FILTER3_RSS_CONTROL_A, j);
1499                                 break;
1500                         }
1501                         continue;
1502                 }
1503                 if (!strncmp(word, "snaplen=", 8)) {
1504                         end = (char *)word + 8;
1505                         ret = kstrtouint(end, 10, &j);
1506                         if (ret || j > 9600) {
1507 inval:                          count = -EINVAL;
1508                                 goto out;
1509                         }
1510                         tp.snap_len = j;
1511                         continue;
1512                 }
1513                 if (!strncmp(word, "minlen=", 7)) {
1514                         end = (char *)word + 7;
1515                         ret = kstrtouint(end, 10, &j);
1516                         if (ret || j > TFMINPKTSIZE_M)
1517                                 goto inval;
1518                         tp.min_len = j;
1519                         continue;
1520                 }
1521                 if (!strcmp(word, "not")) {
1522                         tp.invert = !tp.invert;
1523                         continue;
1524                 }
1525                 if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
1526                         if (word[8] < '0' || word[8] > '3' || word[9])
1527                                 goto inval;
1528                         tp.port = word[8] - '0' + 8;
1529                         continue;
1530                 }
1531                 if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
1532                         if (word[2] < '0' || word[2] > '3' || word[3])
1533                                 goto inval;
1534                         tp.port = word[2] - '0' + 4;
1535                         if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
1536                                 goto inval;
1537                         continue;
1538                 }
1539                 if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
1540                         if (word[2] < '0' || word[2] > '3' || word[3])
1541                                 goto inval;
1542                         tp.port = word[2] - '0';
1543                         if (adap->chan_map[tp.port] >= MAX_NPORTS)
1544                                 goto inval;
1545                         continue;
1546                 }
1547                 if (!isxdigit(*word))
1548                         goto inval;
1549
1550                 /* we have found a trace pattern */
1551                 if (i) {                            /* split pattern */
1552                         if (tp.skip_len)            /* too many splits */
1553                                 goto inval;
1554                         tp.skip_ofst = i / 16;
1555                 }
1556
1557                 data = &tp.data[i / 8];
1558                 mask = &tp.mask[i / 8];
1559                 j = i;
1560
1561                 while (isxdigit(*word)) {
1562                         if (i >= TRACE_LEN * 2) {
1563                                 count = -EFBIG;
1564                                 goto out;
1565                         }
1566                         *data = (*data << 4) + xdigit2int(*word++);
1567                         if (++i % 8 == 0)
1568                                 data++;
1569                 }
1570                 if (*word == '/') {
1571                         word++;
1572                         while (isxdigit(*word)) {
1573                                 if (j >= i)         /* mask longer than data */
1574                                         goto inval;
1575                                 *mask = (*mask << 4) + xdigit2int(*word++);
1576                                 if (++j % 8 == 0)
1577                                         mask++;
1578                         }
1579                         if (i != j)                 /* mask shorter than data */
1580                                 goto inval;
1581                 } else {                            /* no mask, use all 1s */
1582                         for ( ; i - j >= 8; j += 8)
1583                                 *mask++ = 0xffffffff;
1584                         if (i % 8)
1585                                 *mask = (1 << (i % 8) * 4) - 1;
1586                 }
1587                 if (*word == '@') {
1588                         end = (char *)word + 1;
1589                         ret = kstrtouint(end, 10, &j);
1590                         if (*end && *end != '\n')
1591                                 goto inval;
1592                         if (j & 7)          /* doesn't start at multiple of 8 */
1593                                 goto inval;
1594                         j /= 8;
1595                         if (j < tp.skip_ofst)     /* overlaps earlier pattern */
1596                                 goto inval;
1597                         if (j - tp.skip_ofst > 31)            /* skip too big */
1598                                 goto inval;
1599                         tp.skip_len = j - tp.skip_ofst;
1600                 }
1601                 if (i % 8) {
1602                         *data <<= (8 - i % 8) * 4;
1603                         *mask <<= (8 - i % 8) * 4;
1604                         i = (i + 15) & ~15;         /* 8-byte align */
1605                 }
1606         }
1607
1608         if (tp.port == TRC_PORT_NONE)
1609                 goto inval;
1610
1611 apply:
1612         i = t4_set_trace_filter(adap, &tp, trcidx, enable);
1613         if (i)
1614                 count = i;
1615 out:
1616         kfree(s);
1617         return count;
1618 }
1619
1620 static const struct file_operations mps_trc_debugfs_fops = {
1621         .owner   = THIS_MODULE,
1622         .open    = mps_trc_open,
1623         .read    = seq_read,
1624         .llseek  = seq_lseek,
1625         .release = single_release,
1626         .write   = mps_trc_write
1627 };
1628
1629 static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
1630                           loff_t *ppos)
1631 {
1632         loff_t pos = *ppos;
1633         loff_t avail = file_inode(file)->i_size;
1634         struct adapter *adap = file->private_data;
1635
1636         if (pos < 0)
1637                 return -EINVAL;
1638         if (pos >= avail)
1639                 return 0;
1640         if (count > avail - pos)
1641                 count = avail - pos;
1642
1643         while (count) {
1644                 size_t len;
1645                 int ret, ofst;
1646                 u8 data[256];
1647
1648                 ofst = pos & 3;
1649                 len = min(count + ofst, sizeof(data));
1650                 ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
1651                                     (u32 *)data, 1);
1652                 if (ret)
1653                         return ret;
1654
1655                 len -= ofst;
1656                 if (copy_to_user(buf, data + ofst, len))
1657                         return -EFAULT;
1658
1659                 buf += len;
1660                 pos += len;
1661                 count -= len;
1662         }
1663         count = pos - *ppos;
1664         *ppos = pos;
1665         return count;
1666 }
1667
1668 static const struct file_operations flash_debugfs_fops = {
1669         .owner   = THIS_MODULE,
1670         .open    = mem_open,
1671         .read    = flash_read,
1672         .llseek  = default_llseek,
1673 };
1674
1675 static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1676 {
1677         *mask = x | y;
1678         y = (__force u64)cpu_to_be64(y);
1679         memcpy(addr, (char *)&y + 2, ETH_ALEN);
1680 }
1681
1682 static int mps_tcam_show(struct seq_file *seq, void *v)
1683 {
1684         struct adapter *adap = seq->private;
1685         unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
1686         if (v == SEQ_START_TOKEN) {
1687                 if (chip_ver > CHELSIO_T5) {
1688                         seq_puts(seq, "Idx  Ethernet address     Mask     "
1689                                  "  VNI   Mask   IVLAN Vld "
1690                                  "DIP_Hit   Lookup  Port "
1691                                  "Vld Ports PF  VF                           "
1692                                  "Replication                                "
1693                                  "    P0 P1 P2 P3  ML\n");
1694                 } else {
1695                         if (adap->params.arch.mps_rplc_size > 128)
1696                                 seq_puts(seq, "Idx  Ethernet address     Mask     "
1697                                          "Vld Ports PF  VF                           "
1698                                          "Replication                                "
1699                                          "    P0 P1 P2 P3  ML\n");
1700                         else
1701                                 seq_puts(seq, "Idx  Ethernet address     Mask     "
1702                                          "Vld Ports PF  VF              Replication"
1703                                          "               P0 P1 P2 P3  ML\n");
1704                 }
1705         } else {
1706                 u64 mask;
1707                 u8 addr[ETH_ALEN];
1708                 bool replicate, dip_hit = false, vlan_vld = false;
1709                 unsigned int idx = (uintptr_t)v - 2;
1710                 u64 tcamy, tcamx, val;
1711                 u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
1712                 u32 rplc[8] = {0};
1713                 u8 lookup_type = 0, port_num = 0;
1714                 u16 ivlan = 0;
1715
1716                 if (chip_ver > CHELSIO_T5) {
1717                         /* CtlCmdType - 0: Read, 1: Write
1718                          * CtlTcamSel - 0: TCAM0, 1: TCAM1
1719                          * CtlXYBitSel- 0: Y bit, 1: X bit
1720                          */
1721
1722                         /* Read tcamy */
1723                         ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
1724                         if (idx < 256)
1725                                 ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
1726                         else
1727                                 ctl |= CTLTCAMINDEX_V(idx - 256) |
1728                                        CTLTCAMSEL_V(1);
1729                         t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1730                         val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
1731                         tcamy = DMACH_G(val) << 32;
1732                         tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1733                         data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1734                         lookup_type = DATALKPTYPE_G(data2);
1735                         /* 0 - Outer header, 1 - Inner header
1736                          * [71:48] bit locations are overloaded for
1737                          * outer vs. inner lookup types.
1738                          */
1739                         if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1740                                 /* Inner header VNI */
1741                                 vniy = ((data2 & DATAVIDH2_F) << 23) |
1742                                        (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1743                                 dip_hit = data2 & DATADIPHIT_F;
1744                         } else {
1745                                 vlan_vld = data2 & DATAVIDH2_F;
1746                                 ivlan = VIDL_G(val);
1747                         }
1748                         port_num = DATAPORTNUM_G(data2);
1749
1750                         /* Read tcamx. Change the control param */
1751                         ctl |= CTLXYBITSEL_V(1);
1752                         t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1753                         val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
1754                         tcamx = DMACH_G(val) << 32;
1755                         tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1756                         data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1757                         if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1758                                 /* Inner header VNI mask */
1759                                 vnix = ((data2 & DATAVIDH2_F) << 23) |
1760                                        (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1761                         }
1762                 } else {
1763                         tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
1764                         tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
1765                 }
1766
1767                 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
1768                 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
1769
1770                 if (tcamx & tcamy) {
1771                         seq_printf(seq, "%3u         -\n", idx);
1772                         goto out;
1773                 }
1774
1775                 rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
1776                 if (chip_ver > CHELSIO_T5)
1777                         replicate = (cls_lo & T6_REPLICATE_F);
1778                 else
1779                         replicate = (cls_lo & REPLICATE_F);
1780
1781                 if (replicate) {
1782                         struct fw_ldst_cmd ldst_cmd;
1783                         int ret;
1784                         struct fw_ldst_mps_rplc mps_rplc;
1785                         u32 ldst_addrspc;
1786
1787                         memset(&ldst_cmd, 0, sizeof(ldst_cmd));
1788                         ldst_addrspc =
1789                                 FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
1790                         ldst_cmd.op_to_addrspace =
1791                                 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1792                                       FW_CMD_REQUEST_F |
1793                                       FW_CMD_READ_F |
1794                                       ldst_addrspc);
1795                         ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
1796                         ldst_cmd.u.mps.rplc.fid_idx =
1797                                 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
1798                                       FW_LDST_CMD_IDX_V(idx));
1799                         ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1800                                          sizeof(ldst_cmd), &ldst_cmd);
1801                         if (ret)
1802                                 dev_warn(adap->pdev_dev, "Can't read MPS "
1803                                          "replication map for idx %d: %d\n",
1804                                          idx, -ret);
1805                         else {
1806                                 mps_rplc = ldst_cmd.u.mps.rplc;
1807                                 rplc[0] = ntohl(mps_rplc.rplc31_0);
1808                                 rplc[1] = ntohl(mps_rplc.rplc63_32);
1809                                 rplc[2] = ntohl(mps_rplc.rplc95_64);
1810                                 rplc[3] = ntohl(mps_rplc.rplc127_96);
1811                                 if (adap->params.arch.mps_rplc_size > 128) {
1812                                         rplc[4] = ntohl(mps_rplc.rplc159_128);
1813                                         rplc[5] = ntohl(mps_rplc.rplc191_160);
1814                                         rplc[6] = ntohl(mps_rplc.rplc223_192);
1815                                         rplc[7] = ntohl(mps_rplc.rplc255_224);
1816                                 }
1817                         }
1818                 }
1819
1820                 tcamxy2valmask(tcamx, tcamy, addr, &mask);
1821                 if (chip_ver > CHELSIO_T5) {
1822                         /* Inner header lookup */
1823                         if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1824                                 seq_printf(seq,
1825                                            "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1826                                            "%012llx %06x %06x    -    -   %3c"
1827                                            "      'I'  %4x   "
1828                                            "%3c   %#x%4u%4d", idx, addr[0],
1829                                            addr[1], addr[2], addr[3],
1830                                            addr[4], addr[5],
1831                                            (unsigned long long)mask,
1832                                            vniy, vnix, dip_hit ? 'Y' : 'N',
1833                                            port_num,
1834                                            (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1835                                            PORTMAP_G(cls_hi),
1836                                            T6_PF_G(cls_lo),
1837                                            (cls_lo & T6_VF_VALID_F) ?
1838                                            T6_VF_G(cls_lo) : -1);
1839                         } else {
1840                                 seq_printf(seq,
1841                                            "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1842                                            "%012llx    -       -   ",
1843                                            idx, addr[0], addr[1], addr[2],
1844                                            addr[3], addr[4], addr[5],
1845                                            (unsigned long long)mask);
1846
1847                                 if (vlan_vld)
1848                                         seq_printf(seq, "%4u   Y     ", ivlan);
1849                                 else
1850                                         seq_puts(seq, "  -    N     ");
1851
1852                                 seq_printf(seq,
1853                                            "-      %3c  %4x   %3c   %#x%4u%4d",
1854                                            lookup_type ? 'I' : 'O', port_num,
1855                                            (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1856                                            PORTMAP_G(cls_hi),
1857                                            T6_PF_G(cls_lo),
1858                                            (cls_lo & T6_VF_VALID_F) ?
1859                                            T6_VF_G(cls_lo) : -1);
1860                         }
1861                 } else
1862                         seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1863                                    "%012llx%3c   %#x%4u%4d",
1864                                    idx, addr[0], addr[1], addr[2], addr[3],
1865                                    addr[4], addr[5], (unsigned long long)mask,
1866                                    (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
1867                                    PORTMAP_G(cls_hi),
1868                                    PF_G(cls_lo),
1869                                    (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
1870
1871                 if (replicate) {
1872                         if (adap->params.arch.mps_rplc_size > 128)
1873                                 seq_printf(seq, " %08x %08x %08x %08x "
1874                                            "%08x %08x %08x %08x",
1875                                            rplc[7], rplc[6], rplc[5], rplc[4],
1876                                            rplc[3], rplc[2], rplc[1], rplc[0]);
1877                         else
1878                                 seq_printf(seq, " %08x %08x %08x %08x",
1879                                            rplc[3], rplc[2], rplc[1], rplc[0]);
1880                 } else {
1881                         if (adap->params.arch.mps_rplc_size > 128)
1882                                 seq_printf(seq, "%72c", ' ');
1883                         else
1884                                 seq_printf(seq, "%36c", ' ');
1885                 }
1886
1887                 if (chip_ver > CHELSIO_T5)
1888                         seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1889                                    T6_SRAM_PRIO0_G(cls_lo),
1890                                    T6_SRAM_PRIO1_G(cls_lo),
1891                                    T6_SRAM_PRIO2_G(cls_lo),
1892                                    T6_SRAM_PRIO3_G(cls_lo),
1893                                    (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
1894                 else
1895                         seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1896                                    SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1897                                    SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1898                                    (cls_lo >> MULTILISTEN0_S) & 0xf);
1899         }
1900 out:    return 0;
1901 }
1902
1903 static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1904 {
1905         struct adapter *adap = seq->private;
1906         int max_mac_addr = is_t4(adap->params.chip) ?
1907                                 NUM_MPS_CLS_SRAM_L_INSTANCES :
1908                                 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1909         return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1910 }
1911
1912 static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1913 {
1914         return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1915 }
1916
1917 static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1918 {
1919         ++*pos;
1920         return mps_tcam_get_idx(seq, *pos);
1921 }
1922
1923 static void mps_tcam_stop(struct seq_file *seq, void *v)
1924 {
1925 }
1926
1927 static const struct seq_operations mps_tcam_seq_ops = {
1928         .start = mps_tcam_start,
1929         .next  = mps_tcam_next,
1930         .stop  = mps_tcam_stop,
1931         .show  = mps_tcam_show
1932 };
1933
1934 static int mps_tcam_open(struct inode *inode, struct file *file)
1935 {
1936         int res = seq_open(file, &mps_tcam_seq_ops);
1937
1938         if (!res) {
1939                 struct seq_file *seq = file->private_data;
1940
1941                 seq->private = inode->i_private;
1942         }
1943         return res;
1944 }
1945
1946 static const struct file_operations mps_tcam_debugfs_fops = {
1947         .owner   = THIS_MODULE,
1948         .open    = mps_tcam_open,
1949         .read    = seq_read,
1950         .llseek  = seq_lseek,
1951         .release = seq_release,
1952 };
1953
1954 /* Display various sensor information.
1955  */
1956 static int sensors_show(struct seq_file *seq, void *v)
1957 {
1958         struct adapter *adap = seq->private;
1959         u32 param[7], val[7];
1960         int ret;
1961
1962         /* Note that if the sensors haven't been initialized and turned on
1963          * we'll get values of 0, so treat those as "<unknown>" ...
1964          */
1965         param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1966                     FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1967                     FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
1968         param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1969                     FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1970                     FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1971         ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
1972                               param, val);
1973
1974         if (ret < 0 || val[0] == 0)
1975                 seq_puts(seq, "Temperature: <unknown>\n");
1976         else
1977                 seq_printf(seq, "Temperature: %dC\n", val[0]);
1978
1979         if (ret < 0 || val[1] == 0)
1980                 seq_puts(seq, "Core VDD:    <unknown>\n");
1981         else
1982                 seq_printf(seq, "Core VDD:    %dmV\n", val[1]);
1983
1984         return 0;
1985 }
1986
1987 DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
1988
1989 #if IS_ENABLED(CONFIG_IPV6)
1990 static int clip_tbl_open(struct inode *inode, struct file *file)
1991 {
1992         return single_open(file, clip_tbl_show, inode->i_private);
1993 }
1994
1995 static const struct file_operations clip_tbl_debugfs_fops = {
1996         .owner   = THIS_MODULE,
1997         .open    = clip_tbl_open,
1998         .read    = seq_read,
1999         .llseek  = seq_lseek,
2000         .release = single_release
2001 };
2002 #endif
2003
2004 /*RSS Table.
2005  */
2006
2007 static int rss_show(struct seq_file *seq, void *v, int idx)
2008 {
2009         u16 *entry = v;
2010
2011         seq_printf(seq, "%4d:  %4u  %4u  %4u  %4u  %4u  %4u  %4u  %4u\n",
2012                    idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
2013                    entry[5], entry[6], entry[7]);
2014         return 0;
2015 }
2016
2017 static int rss_open(struct inode *inode, struct file *file)
2018 {
2019         int ret;
2020         struct seq_tab *p;
2021         struct adapter *adap = inode->i_private;
2022
2023         p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
2024         if (!p)
2025                 return -ENOMEM;
2026
2027         ret = t4_read_rss(adap, (u16 *)p->data);
2028         if (ret)
2029                 seq_release_private(inode, file);
2030
2031         return ret;
2032 }
2033
2034 static const struct file_operations rss_debugfs_fops = {
2035         .owner   = THIS_MODULE,
2036         .open    = rss_open,
2037         .read    = seq_read,
2038         .llseek  = seq_lseek,
2039         .release = seq_release_private
2040 };
2041
2042 /* RSS Configuration.
2043  */
2044
2045 /* Small utility function to return the strings "yes" or "no" if the supplied
2046  * argument is non-zero.
2047  */
2048 static const char *yesno(int x)
2049 {
2050         static const char *yes = "yes";
2051         static const char *no = "no";
2052
2053         return x ? yes : no;
2054 }
2055
2056 static int rss_config_show(struct seq_file *seq, void *v)
2057 {
2058         struct adapter *adapter = seq->private;
2059         static const char * const keymode[] = {
2060                 "global",
2061                 "global and per-VF scramble",
2062                 "per-PF and per-VF scramble",
2063                 "per-VF and per-VF scramble",
2064         };
2065         u32 rssconf;
2066
2067         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
2068         seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
2069         seq_printf(seq, "  Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
2070                                                         TNL4TUPENIPV6_F));
2071         seq_printf(seq, "  Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
2072                                                         TNL2TUPENIPV6_F));
2073         seq_printf(seq, "  Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
2074                                                         TNL4TUPENIPV4_F));
2075         seq_printf(seq, "  Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
2076                                                         TNL2TUPENIPV4_F));
2077         seq_printf(seq, "  TnlTcpSel:     %3s\n", yesno(rssconf & TNLTCPSEL_F));
2078         seq_printf(seq, "  TnlIp6Sel:     %3s\n", yesno(rssconf & TNLIP6SEL_F));
2079         seq_printf(seq, "  TnlVrtSel:     %3s\n", yesno(rssconf & TNLVRTSEL_F));
2080         seq_printf(seq, "  TnlMapEn:      %3s\n", yesno(rssconf & TNLMAPEN_F));
2081         seq_printf(seq, "  OfdHashSave:   %3s\n", yesno(rssconf &
2082                                                         OFDHASHSAVE_F));
2083         seq_printf(seq, "  OfdVrtSel:     %3s\n", yesno(rssconf & OFDVRTSEL_F));
2084         seq_printf(seq, "  OfdMapEn:      %3s\n", yesno(rssconf & OFDMAPEN_F));
2085         seq_printf(seq, "  OfdLkpEn:      %3s\n", yesno(rssconf & OFDLKPEN_F));
2086         seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2087                                                         SYN4TUPENIPV6_F));
2088         seq_printf(seq, "  Syn2TupEnIpv6: %3s\n", yesno(rssconf &
2089                                                         SYN2TUPENIPV6_F));
2090         seq_printf(seq, "  Syn4TupEnIpv4: %3s\n", yesno(rssconf &
2091                                                         SYN4TUPENIPV4_F));
2092         seq_printf(seq, "  Syn2TupEnIpv4: %3s\n", yesno(rssconf &
2093                                                         SYN2TUPENIPV4_F));
2094         seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2095                                                         SYN4TUPENIPV6_F));
2096         seq_printf(seq, "  SynIp6Sel:     %3s\n", yesno(rssconf & SYNIP6SEL_F));
2097         seq_printf(seq, "  SynVrt6Sel:    %3s\n", yesno(rssconf & SYNVRTSEL_F));
2098         seq_printf(seq, "  SynMapEn:      %3s\n", yesno(rssconf & SYNMAPEN_F));
2099         seq_printf(seq, "  SynLkpEn:      %3s\n", yesno(rssconf & SYNLKPEN_F));
2100         seq_printf(seq, "  ChnEn:         %3s\n", yesno(rssconf &
2101                                                         CHANNELENABLE_F));
2102         seq_printf(seq, "  PrtEn:         %3s\n", yesno(rssconf &
2103                                                         PORTENABLE_F));
2104         seq_printf(seq, "  TnlAllLkp:     %3s\n", yesno(rssconf &
2105                                                         TNLALLLOOKUP_F));
2106         seq_printf(seq, "  VrtEn:         %3s\n", yesno(rssconf &
2107                                                         VIRTENABLE_F));
2108         seq_printf(seq, "  CngEn:         %3s\n", yesno(rssconf &
2109                                                         CONGESTIONENABLE_F));
2110         seq_printf(seq, "  HashToeplitz:  %3s\n", yesno(rssconf &
2111                                                         HASHTOEPLITZ_F));
2112         seq_printf(seq, "  Udp4En:        %3s\n", yesno(rssconf & UDPENABLE_F));
2113         seq_printf(seq, "  Disable:       %3s\n", yesno(rssconf & DISABLE_F));
2114
2115         seq_puts(seq, "\n");
2116
2117         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
2118         seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
2119         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2120         seq_printf(seq, "  MaskFilter:    %3d\n", MASKFILTER_G(rssconf));
2121         if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2122                 seq_printf(seq, "  HashAll:     %3s\n",
2123                            yesno(rssconf & HASHALL_F));
2124                 seq_printf(seq, "  HashEth:     %3s\n",
2125                            yesno(rssconf & HASHETH_F));
2126         }
2127         seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2128
2129         seq_puts(seq, "\n");
2130
2131         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
2132         seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
2133         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2134         seq_printf(seq, "  RRCplMapEn:    %3s\n", yesno(rssconf &
2135                                                         RRCPLMAPEN_F));
2136         seq_printf(seq, "  RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
2137
2138         seq_puts(seq, "\n");
2139
2140         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
2141         seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
2142         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2143         seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2144
2145         seq_puts(seq, "\n");
2146
2147         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
2148         seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
2149         if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2150                 seq_printf(seq, "  KeyWrAddrX:     %3d\n",
2151                            KEYWRADDRX_G(rssconf));
2152                 seq_printf(seq, "  KeyExtend:      %3s\n",
2153                            yesno(rssconf & KEYEXTEND_F));
2154         }
2155         seq_printf(seq, "  VfRdRg:        %3s\n", yesno(rssconf & VFRDRG_F));
2156         seq_printf(seq, "  VfRdEn:        %3s\n", yesno(rssconf & VFRDEN_F));
2157         seq_printf(seq, "  VfPerrEn:      %3s\n", yesno(rssconf & VFPERREN_F));
2158         seq_printf(seq, "  KeyPerrEn:     %3s\n", yesno(rssconf & KEYPERREN_F));
2159         seq_printf(seq, "  DisVfVlan:     %3s\n", yesno(rssconf &
2160                                                         DISABLEVLAN_F));
2161         seq_printf(seq, "  EnUpSwt:       %3s\n", yesno(rssconf & ENABLEUP0_F));
2162         seq_printf(seq, "  HashDelay:     %3d\n", HASHDELAY_G(rssconf));
2163         if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
2164                 seq_printf(seq, "  VfWrAddr:      %3d\n", VFWRADDR_G(rssconf));
2165         else
2166                 seq_printf(seq, "  VfWrAddr:      %3d\n",
2167                            T6_VFWRADDR_G(rssconf));
2168         seq_printf(seq, "  KeyMode:       %s\n", keymode[KEYMODE_G(rssconf)]);
2169         seq_printf(seq, "  VfWrEn:        %3s\n", yesno(rssconf & VFWREN_F));
2170         seq_printf(seq, "  KeyWrEn:       %3s\n", yesno(rssconf & KEYWREN_F));
2171         seq_printf(seq, "  KeyWrAddr:     %3d\n", KEYWRADDR_G(rssconf));
2172
2173         seq_puts(seq, "\n");
2174
2175         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
2176         seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
2177         seq_printf(seq, "  ChnCount3:     %3s\n", yesno(rssconf & CHNCOUNT3_F));
2178         seq_printf(seq, "  ChnCount2:     %3s\n", yesno(rssconf & CHNCOUNT2_F));
2179         seq_printf(seq, "  ChnCount1:     %3s\n", yesno(rssconf & CHNCOUNT1_F));
2180         seq_printf(seq, "  ChnCount0:     %3s\n", yesno(rssconf & CHNCOUNT0_F));
2181         seq_printf(seq, "  ChnUndFlow3:   %3s\n", yesno(rssconf &
2182                                                         CHNUNDFLOW3_F));
2183         seq_printf(seq, "  ChnUndFlow2:   %3s\n", yesno(rssconf &
2184                                                         CHNUNDFLOW2_F));
2185         seq_printf(seq, "  ChnUndFlow1:   %3s\n", yesno(rssconf &
2186                                                         CHNUNDFLOW1_F));
2187         seq_printf(seq, "  ChnUndFlow0:   %3s\n", yesno(rssconf &
2188                                                         CHNUNDFLOW0_F));
2189         seq_printf(seq, "  RstChn3:       %3s\n", yesno(rssconf & RSTCHN3_F));
2190         seq_printf(seq, "  RstChn2:       %3s\n", yesno(rssconf & RSTCHN2_F));
2191         seq_printf(seq, "  RstChn1:       %3s\n", yesno(rssconf & RSTCHN1_F));
2192         seq_printf(seq, "  RstChn0:       %3s\n", yesno(rssconf & RSTCHN0_F));
2193         seq_printf(seq, "  UpdVld:        %3s\n", yesno(rssconf & UPDVLD_F));
2194         seq_printf(seq, "  Xoff:          %3s\n", yesno(rssconf & XOFF_F));
2195         seq_printf(seq, "  UpdChn3:       %3s\n", yesno(rssconf & UPDCHN3_F));
2196         seq_printf(seq, "  UpdChn2:       %3s\n", yesno(rssconf & UPDCHN2_F));
2197         seq_printf(seq, "  UpdChn1:       %3s\n", yesno(rssconf & UPDCHN1_F));
2198         seq_printf(seq, "  UpdChn0:       %3s\n", yesno(rssconf & UPDCHN0_F));
2199         seq_printf(seq, "  Queue:         %3d\n", QUEUE_G(rssconf));
2200
2201         return 0;
2202 }
2203
2204 DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
2205
2206 /* RSS Secret Key.
2207  */
2208
2209 static int rss_key_show(struct seq_file *seq, void *v)
2210 {
2211         u32 key[10];
2212
2213         t4_read_rss_key(seq->private, key);
2214         seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
2215                    key[9], key[8], key[7], key[6], key[5], key[4], key[3],
2216                    key[2], key[1], key[0]);
2217         return 0;
2218 }
2219
2220 static int rss_key_open(struct inode *inode, struct file *file)
2221 {
2222         return single_open(file, rss_key_show, inode->i_private);
2223 }
2224
2225 static ssize_t rss_key_write(struct file *file, const char __user *buf,
2226                              size_t count, loff_t *pos)
2227 {
2228         int i, j;
2229         u32 key[10];
2230         char s[100], *p;
2231         struct adapter *adap = file_inode(file)->i_private;
2232
2233         if (count > sizeof(s) - 1)
2234                 return -EINVAL;
2235         if (copy_from_user(s, buf, count))
2236                 return -EFAULT;
2237         for (i = count; i > 0 && isspace(s[i - 1]); i--)
2238                 ;
2239         s[i] = '\0';
2240
2241         for (p = s, i = 9; i >= 0; i--) {
2242                 key[i] = 0;
2243                 for (j = 0; j < 8; j++, p++) {
2244                         if (!isxdigit(*p))
2245                                 return -EINVAL;
2246                         key[i] = (key[i] << 4) | hex2val(*p);
2247                 }
2248         }
2249
2250         t4_write_rss_key(adap, key, -1);
2251         return count;
2252 }
2253
2254 static const struct file_operations rss_key_debugfs_fops = {
2255         .owner   = THIS_MODULE,
2256         .open    = rss_key_open,
2257         .read    = seq_read,
2258         .llseek  = seq_lseek,
2259         .release = single_release,
2260         .write   = rss_key_write
2261 };
2262
2263 /* PF RSS Configuration.
2264  */
2265
2266 struct rss_pf_conf {
2267         u32 rss_pf_map;
2268         u32 rss_pf_mask;
2269         u32 rss_pf_config;
2270 };
2271
2272 static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
2273 {
2274         struct rss_pf_conf *pfconf;
2275
2276         if (v == SEQ_START_TOKEN) {
2277                 /* use the 0th entry to dump the PF Map Index Size */
2278                 pfconf = seq->private + offsetof(struct seq_tab, data);
2279                 seq_printf(seq, "PF Map Index Size = %d\n\n",
2280                            LKPIDXSIZE_G(pfconf->rss_pf_map));
2281
2282                 seq_puts(seq, "     RSS              PF   VF    Hash Tuple Enable         Default\n");
2283                 seq_puts(seq, "     Enable       IPF Mask Mask  IPv6      IPv4      UDP   Queue\n");
2284                 seq_puts(seq, " PF  Map Chn Prt  Map Size Size  Four Two  Four Two  Four  Ch1  Ch0\n");
2285         } else {
2286                 #define G_PFnLKPIDX(map, n) \
2287                         (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
2288                 #define G_PFnMSKSIZE(mask, n) \
2289                         (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
2290
2291                 pfconf = v;
2292                 seq_printf(seq, "%3d  %3s %3s %3s  %3d  %3d  %3d   %3s %3s   %3s %3s   %3s  %3d  %3d\n",
2293                            idx,
2294                            yesno(pfconf->rss_pf_config & MAPENABLE_F),
2295                            yesno(pfconf->rss_pf_config & CHNENABLE_F),
2296                            yesno(pfconf->rss_pf_config & PRTENABLE_F),
2297                            G_PFnLKPIDX(pfconf->rss_pf_map, idx),
2298                            G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
2299                            IVFWIDTH_G(pfconf->rss_pf_config),
2300                            yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
2301                            yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
2302                            yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
2303                            yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
2304                            yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
2305                            CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
2306                            CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
2307
2308                 #undef G_PFnLKPIDX
2309                 #undef G_PFnMSKSIZE
2310         }
2311         return 0;
2312 }
2313
2314 static int rss_pf_config_open(struct inode *inode, struct file *file)
2315 {
2316         struct adapter *adapter = inode->i_private;
2317         struct seq_tab *p;
2318         u32 rss_pf_map, rss_pf_mask;
2319         struct rss_pf_conf *pfconf;
2320         int pf;
2321
2322         p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
2323         if (!p)
2324                 return -ENOMEM;
2325
2326         pfconf = (struct rss_pf_conf *)p->data;
2327         rss_pf_map = t4_read_rss_pf_map(adapter);
2328         rss_pf_mask = t4_read_rss_pf_mask(adapter);
2329         for (pf = 0; pf < 8; pf++) {
2330                 pfconf[pf].rss_pf_map = rss_pf_map;
2331                 pfconf[pf].rss_pf_mask = rss_pf_mask;
2332                 t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
2333         }
2334         return 0;
2335 }
2336
2337 static const struct file_operations rss_pf_config_debugfs_fops = {
2338         .owner   = THIS_MODULE,
2339         .open    = rss_pf_config_open,
2340         .read    = seq_read,
2341         .llseek  = seq_lseek,
2342         .release = seq_release_private
2343 };
2344
2345 /* VF RSS Configuration.
2346  */
2347
2348 struct rss_vf_conf {
2349         u32 rss_vf_vfl;
2350         u32 rss_vf_vfh;
2351 };
2352
2353 static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
2354 {
2355         if (v == SEQ_START_TOKEN) {
2356                 seq_puts(seq, "     RSS                     Hash Tuple Enable\n");
2357                 seq_puts(seq, "     Enable   IVF  Dis  Enb  IPv6      IPv4      UDP    Def  Secret Key\n");
2358                 seq_puts(seq, " VF  Chn Prt  Map  VLAN  uP  Four Two  Four Two  Four   Que  Idx       Hash\n");
2359         } else {
2360                 struct rss_vf_conf *vfconf = v;
2361
2362                 seq_printf(seq, "%3d  %3s %3s  %3d   %3s %3s   %3s %3s   %3s  %3s   %3s  %4d  %3d %#10x\n",
2363                            idx,
2364                            yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
2365                            yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
2366                            VFLKPIDX_G(vfconf->rss_vf_vfh),
2367                            yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
2368                            yesno(vfconf->rss_vf_vfh & VFUPEN_F),
2369                            yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2370                            yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
2371                            yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2372                            yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
2373                            yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
2374                            DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
2375                            KEYINDEX_G(vfconf->rss_vf_vfh),
2376                            vfconf->rss_vf_vfl);
2377         }
2378         return 0;
2379 }
2380
2381 static int rss_vf_config_open(struct inode *inode, struct file *file)
2382 {
2383         struct adapter *adapter = inode->i_private;
2384         struct seq_tab *p;
2385         struct rss_vf_conf *vfconf;
2386         int vf, vfcount = adapter->params.arch.vfcount;
2387
2388         p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
2389         if (!p)
2390                 return -ENOMEM;
2391
2392         vfconf = (struct rss_vf_conf *)p->data;
2393         for (vf = 0; vf < vfcount; vf++) {
2394                 t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
2395                                       &vfconf[vf].rss_vf_vfh);
2396         }
2397         return 0;
2398 }
2399
2400 static const struct file_operations rss_vf_config_debugfs_fops = {
2401         .owner   = THIS_MODULE,
2402         .open    = rss_vf_config_open,
2403         .read    = seq_read,
2404         .llseek  = seq_lseek,
2405         .release = seq_release_private
2406 };
2407
2408 /**
2409  * ethqset2pinfo - return port_info of an Ethernet Queue Set
2410  * @adap: the adapter
2411  * @qset: Ethernet Queue Set
2412  */
2413 static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
2414 {
2415         int pidx;
2416
2417         for_each_port(adap, pidx) {
2418                 struct port_info *pi = adap2pinfo(adap, pidx);
2419
2420                 if (qset >= pi->first_qset &&
2421                     qset < pi->first_qset + pi->nqsets)
2422                         return pi;
2423         }
2424
2425         /* should never happen! */
2426         BUG_ON(1);
2427         return NULL;
2428 }
2429
2430 static int sge_qinfo_show(struct seq_file *seq, void *v)
2431 {
2432         struct adapter *adap = seq->private;
2433         int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
2434         int ofld_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
2435         int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
2436         int i, r = (uintptr_t)v - 1;
2437         int ofld_idx = r - eth_entries;
2438         int ctrl_idx =  ofld_idx - ofld_entries;
2439         int fq_idx =  ctrl_idx - ctrl_entries;
2440
2441         if (r)
2442                 seq_putc(seq, '\n');
2443
2444 #define S3(fmt_spec, s, v) \
2445 do { \
2446         seq_printf(seq, "%-12s", s); \
2447         for (i = 0; i < n; ++i) \
2448                 seq_printf(seq, " %16" fmt_spec, v); \
2449         seq_putc(seq, '\n'); \
2450 } while (0)
2451 #define S(s, v) S3("s", s, v)
2452 #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
2453 #define T(s, v) S3("u", s, tx[i].v)
2454 #define TL(s, v) T3("lu", s, v)
2455 #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
2456 #define R(s, v) S3("u", s, rx[i].v)
2457 #define RL(s, v) R3("lu", s, v)
2458
2459         if (r < eth_entries) {
2460                 int base_qset = r * 4;
2461                 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
2462                 const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
2463                 int n = min(4, adap->sge.ethqsets - 4 * r);
2464
2465                 S("QType:", "Ethernet");
2466                 S("Interface:",
2467                   rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2468                 T("TxQ ID:", q.cntxt_id);
2469                 T("TxQ size:", q.size);
2470                 T("TxQ inuse:", q.in_use);
2471                 T("TxQ CIDX:", q.cidx);
2472                 T("TxQ PIDX:", q.pidx);
2473 #ifdef CONFIG_CHELSIO_T4_DCB
2474                 T("DCB Prio:", dcb_prio);
2475                 S3("u", "DCB PGID:",
2476                    (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
2477                     4*(7-tx[i].dcb_prio)) & 0xf);
2478                 S3("u", "DCB PFC:",
2479                    (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
2480                     1*(7-tx[i].dcb_prio)) & 0x1);
2481 #endif
2482                 R("RspQ ID:", rspq.abs_id);
2483                 R("RspQ size:", rspq.size);
2484                 R("RspQE size:", rspq.iqe_len);
2485                 R("RspQ CIDX:", rspq.cidx);
2486                 R("RspQ Gen:", rspq.gen);
2487                 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2488                 S3("u", "Intr pktcnt:",
2489                    adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2490                 R("FL ID:", fl.cntxt_id);
2491                 R("FL size:", fl.size - 8);
2492                 R("FL pend:", fl.pend_cred);
2493                 R("FL avail:", fl.avail);
2494                 R("FL PIDX:", fl.pidx);
2495                 R("FL CIDX:", fl.cidx);
2496                 RL("RxPackets:", stats.pkts);
2497                 RL("RxCSO:", stats.rx_cso);
2498                 RL("VLANxtract:", stats.vlan_ex);
2499                 RL("LROmerged:", stats.lro_merged);
2500                 RL("LROpackets:", stats.lro_pkts);
2501                 RL("RxDrops:", stats.rx_drops);
2502                 TL("TSO:", tso);
2503                 TL("TxCSO:", tx_cso);
2504                 TL("VLANins:", vlan_ins);
2505                 TL("TxQFull:", q.stops);
2506                 TL("TxQRestarts:", q.restarts);
2507                 TL("TxMapErr:", mapping_err);
2508                 RL("FLAllocErr:", fl.alloc_failed);
2509                 RL("FLLrgAlcErr:", fl.large_alloc_failed);
2510                 RL("FLMapErr:", fl.mapping_err);
2511                 RL("FLLow:", fl.low);
2512                 RL("FLStarving:", fl.starving);
2513
2514         } else if (ctrl_idx < ctrl_entries) {
2515                 const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
2516                 int n = min(4, adap->params.nports - 4 * ctrl_idx);
2517
2518                 S("QType:", "Control");
2519                 T("TxQ ID:", q.cntxt_id);
2520                 T("TxQ size:", q.size);
2521                 T("TxQ inuse:", q.in_use);
2522                 T("TxQ CIDX:", q.cidx);
2523                 T("TxQ PIDX:", q.pidx);
2524                 TL("TxQFull:", q.stops);
2525                 TL("TxQRestarts:", q.restarts);
2526         } else if (fq_idx == 0) {
2527                 const struct sge_rspq *evtq = &adap->sge.fw_evtq;
2528
2529                 seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
2530                 seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
2531                 seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
2532                 seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
2533                 seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
2534                 seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
2535                 seq_printf(seq, "%-12s %16u\n", "Intr delay:",
2536                            qtimer_val(adap, evtq));
2537                 seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
2538                            adap->sge.counter_val[evtq->pktcnt_idx]);
2539         }
2540 #undef R
2541 #undef RL
2542 #undef T
2543 #undef TL
2544 #undef S
2545 #undef R3
2546 #undef T3
2547 #undef S3
2548         return 0;
2549 }
2550
2551 static int sge_queue_entries(const struct adapter *adap)
2552 {
2553         return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
2554                DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
2555                DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
2556 }
2557
2558 static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
2559 {
2560         int entries = sge_queue_entries(seq->private);
2561
2562         return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2563 }
2564
2565 static void sge_queue_stop(struct seq_file *seq, void *v)
2566 {
2567 }
2568
2569 static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
2570 {
2571         int entries = sge_queue_entries(seq->private);
2572
2573         ++*pos;
2574         return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2575 }
2576
2577 static const struct seq_operations sge_qinfo_seq_ops = {
2578         .start = sge_queue_start,
2579         .next  = sge_queue_next,
2580         .stop  = sge_queue_stop,
2581         .show  = sge_qinfo_show
2582 };
2583
2584 static int sge_qinfo_open(struct inode *inode, struct file *file)
2585 {
2586         int res = seq_open(file, &sge_qinfo_seq_ops);
2587
2588         if (!res) {
2589                 struct seq_file *seq = file->private_data;
2590
2591                 seq->private = inode->i_private;
2592         }
2593         return res;
2594 }
2595
2596 static const struct file_operations sge_qinfo_debugfs_fops = {
2597         .owner   = THIS_MODULE,
2598         .open    = sge_qinfo_open,
2599         .read    = seq_read,
2600         .llseek  = seq_lseek,
2601         .release = seq_release,
2602 };
2603
2604 int mem_open(struct inode *inode, struct file *file)
2605 {
2606         unsigned int mem;
2607         struct adapter *adap;
2608
2609         file->private_data = inode->i_private;
2610
2611         mem = (uintptr_t)file->private_data & 0x3;
2612         adap = file->private_data - mem;
2613
2614         (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
2615
2616         return 0;
2617 }
2618
2619 static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2620                         loff_t *ppos)
2621 {
2622         loff_t pos = *ppos;
2623         loff_t avail = file_inode(file)->i_size;
2624         unsigned int mem = (uintptr_t)file->private_data & 3;
2625         struct adapter *adap = file->private_data - mem;
2626         __be32 *data;
2627         int ret;
2628
2629         if (pos < 0)
2630                 return -EINVAL;
2631         if (pos >= avail)
2632                 return 0;
2633         if (count > avail - pos)
2634                 count = avail - pos;
2635
2636         data = kvzalloc(count, GFP_KERNEL);
2637         if (!data)
2638                 return -ENOMEM;
2639
2640         spin_lock(&adap->win0_lock);
2641         ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
2642         spin_unlock(&adap->win0_lock);
2643         if (ret) {
2644                 kvfree(data);
2645                 return ret;
2646         }
2647         ret = copy_to_user(buf, data, count);
2648
2649         kvfree(data);
2650         if (ret)
2651                 return -EFAULT;
2652
2653         *ppos = pos + count;
2654         return count;
2655 }
2656 static const struct file_operations mem_debugfs_fops = {
2657         .owner   = THIS_MODULE,
2658         .open    = simple_open,
2659         .read    = mem_read,
2660         .llseek  = default_llseek,
2661 };
2662
2663 static int tid_info_show(struct seq_file *seq, void *v)
2664 {
2665         struct adapter *adap = seq->private;
2666         const struct tid_info *t = &adap->tids;
2667         enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
2668
2669         if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
2670                 unsigned int sb;
2671                 seq_printf(seq, "Connections in use: %u\n",
2672                            atomic_read(&t->conns_in_use));
2673
2674                 if (chip <= CHELSIO_T5)
2675                         sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
2676                 else
2677                         sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
2678
2679                 if (sb) {
2680                         seq_printf(seq, "TID range: 0..%u/%u..%u", sb - 1,
2681                                    adap->tids.hash_base,
2682                                    t->ntids - 1);
2683                         seq_printf(seq, ", in use: %u/%u\n",
2684                                    atomic_read(&t->tids_in_use),
2685                                    atomic_read(&t->hash_tids_in_use));
2686                 } else if (adap->flags & FW_OFLD_CONN) {
2687                         seq_printf(seq, "TID range: %u..%u/%u..%u",
2688                                    t->aftid_base,
2689                                    t->aftid_end,
2690                                    adap->tids.hash_base,
2691                                    t->ntids - 1);
2692                         seq_printf(seq, ", in use: %u/%u\n",
2693                                    atomic_read(&t->tids_in_use),
2694                                    atomic_read(&t->hash_tids_in_use));
2695                 } else {
2696                         seq_printf(seq, "TID range: %u..%u",
2697                                    adap->tids.hash_base,
2698                                    t->ntids - 1);
2699                         seq_printf(seq, ", in use: %u\n",
2700                                    atomic_read(&t->hash_tids_in_use));
2701                 }
2702         } else if (t->ntids) {
2703                 seq_printf(seq, "Connections in use: %u\n",
2704                            atomic_read(&t->conns_in_use));
2705
2706                 seq_printf(seq, "TID range: 0..%u", t->ntids - 1);
2707                 seq_printf(seq, ", in use: %u\n",
2708                            atomic_read(&t->tids_in_use));
2709         }
2710
2711         if (t->nstids)
2712                 seq_printf(seq, "STID range: %u..%u, in use-IPv4/IPv6: %u/%u\n",
2713                            (!t->stid_base &&
2714                            (chip <= CHELSIO_T5)) ?
2715                            t->stid_base + 1 : t->stid_base,
2716                            t->stid_base + t->nstids - 1,
2717                            t->stids_in_use - t->v6_stids_in_use,
2718                            t->v6_stids_in_use);
2719
2720         if (t->natids)
2721                 seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
2722                            t->natids - 1, t->atids_in_use);
2723         seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
2724                    t->ftid_base + t->nftids - 1);
2725         if (t->nsftids)
2726                 seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
2727                            t->sftid_base, t->sftid_base + t->nsftids - 2,
2728                            t->sftids_in_use);
2729         if (t->ntids)
2730                 seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
2731                            t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
2732                            t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
2733         return 0;
2734 }
2735
2736 DEFINE_SIMPLE_DEBUGFS_FILE(tid_info);
2737
2738 static void add_debugfs_mem(struct adapter *adap, const char *name,
2739                             unsigned int idx, unsigned int size_mb)
2740 {
2741         debugfs_create_file_size(name, S_IRUSR, adap->debugfs_root,
2742                                  (void *)adap + idx, &mem_debugfs_fops,
2743                                  size_mb << 20);
2744 }
2745
2746 static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
2747                                size_t count, loff_t *ppos)
2748 {
2749         int len;
2750         const struct adapter *adap = filp->private_data;
2751         char *buf;
2752         ssize_t size = (adap->sge.egr_sz + 3) / 4 +
2753                         adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
2754
2755         buf = kzalloc(size, GFP_KERNEL);
2756         if (!buf)
2757                 return -ENOMEM;
2758
2759         len = snprintf(buf, size - 1, "%*pb\n",
2760                        adap->sge.egr_sz, adap->sge.blocked_fl);
2761         len += sprintf(buf + len, "\n");
2762         size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
2763         kvfree(buf);
2764         return size;
2765 }
2766
2767 static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
2768                                 size_t count, loff_t *ppos)
2769 {
2770         int err;
2771         unsigned long *t;
2772         struct adapter *adap = filp->private_data;
2773
2774         t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
2775         if (!t)
2776                 return -ENOMEM;
2777
2778         err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
2779         if (err) {
2780                 kvfree(t);
2781                 return err;
2782         }
2783
2784         bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
2785         kvfree(t);
2786         return count;
2787 }
2788
2789 static const struct file_operations blocked_fl_fops = {
2790         .owner   = THIS_MODULE,
2791         .open    = simple_open,
2792         .read    = blocked_fl_read,
2793         .write   = blocked_fl_write,
2794         .llseek  = generic_file_llseek,
2795 };
2796
2797 struct mem_desc {
2798         unsigned int base;
2799         unsigned int limit;
2800         unsigned int idx;
2801 };
2802
2803 static int mem_desc_cmp(const void *a, const void *b)
2804 {
2805         return ((const struct mem_desc *)a)->base -
2806                ((const struct mem_desc *)b)->base;
2807 }
2808
2809 static void mem_region_show(struct seq_file *seq, const char *name,
2810                             unsigned int from, unsigned int to)
2811 {
2812         char buf[40];
2813
2814         string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
2815                         sizeof(buf));
2816         seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
2817 }
2818
2819 static int meminfo_show(struct seq_file *seq, void *v)
2820 {
2821         static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
2822                                         "MC0:", "MC1:"};
2823         static const char * const region[] = {
2824                 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
2825                 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
2826                 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
2827                 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
2828                 "RQUDP region:", "PBL region:", "TXPBL region:",
2829                 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
2830                 "On-chip queues:"
2831         };
2832
2833         int i, n;
2834         u32 lo, hi, used, alloc;
2835         struct mem_desc avail[4];
2836         struct mem_desc mem[ARRAY_SIZE(region) + 3];      /* up to 3 holes */
2837         struct mem_desc *md = mem;
2838         struct adapter *adap = seq->private;
2839
2840         for (i = 0; i < ARRAY_SIZE(mem); i++) {
2841                 mem[i].limit = 0;
2842                 mem[i].idx = i;
2843         }
2844
2845         /* Find and sort the populated memory ranges */
2846         i = 0;
2847         lo = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
2848         if (lo & EDRAM0_ENABLE_F) {
2849                 hi = t4_read_reg(adap, MA_EDRAM0_BAR_A);
2850                 avail[i].base = EDRAM0_BASE_G(hi) << 20;
2851                 avail[i].limit = avail[i].base + (EDRAM0_SIZE_G(hi) << 20);
2852                 avail[i].idx = 0;
2853                 i++;
2854         }
2855         if (lo & EDRAM1_ENABLE_F) {
2856                 hi = t4_read_reg(adap, MA_EDRAM1_BAR_A);
2857                 avail[i].base = EDRAM1_BASE_G(hi) << 20;
2858                 avail[i].limit = avail[i].base + (EDRAM1_SIZE_G(hi) << 20);
2859                 avail[i].idx = 1;
2860                 i++;
2861         }
2862
2863         if (is_t5(adap->params.chip)) {
2864                 if (lo & EXT_MEM0_ENABLE_F) {
2865                         hi = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
2866                         avail[i].base = EXT_MEM0_BASE_G(hi) << 20;
2867                         avail[i].limit =
2868                                 avail[i].base + (EXT_MEM0_SIZE_G(hi) << 20);
2869                         avail[i].idx = 3;
2870                         i++;
2871                 }
2872                 if (lo & EXT_MEM1_ENABLE_F) {
2873                         hi = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
2874                         avail[i].base = EXT_MEM1_BASE_G(hi) << 20;
2875                         avail[i].limit =
2876                                 avail[i].base + (EXT_MEM1_SIZE_G(hi) << 20);
2877                         avail[i].idx = 4;
2878                         i++;
2879                 }
2880         } else {
2881                 if (lo & EXT_MEM_ENABLE_F) {
2882                         hi = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
2883                         avail[i].base = EXT_MEM_BASE_G(hi) << 20;
2884                         avail[i].limit =
2885                                 avail[i].base + (EXT_MEM_SIZE_G(hi) << 20);
2886                         avail[i].idx = 2;
2887                         i++;
2888                 }
2889         }
2890         if (!i)                                    /* no memory available */
2891                 return 0;
2892         sort(avail, i, sizeof(struct mem_desc), mem_desc_cmp, NULL);
2893
2894         (md++)->base = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A);
2895         (md++)->base = t4_read_reg(adap, SGE_IMSG_CTXT_BADDR_A);
2896         (md++)->base = t4_read_reg(adap, SGE_FLM_CACHE_BADDR_A);
2897         (md++)->base = t4_read_reg(adap, TP_CMM_TCB_BASE_A);
2898         (md++)->base = t4_read_reg(adap, TP_CMM_MM_BASE_A);
2899         (md++)->base = t4_read_reg(adap, TP_CMM_TIMER_BASE_A);
2900         (md++)->base = t4_read_reg(adap, TP_CMM_MM_RX_FLST_BASE_A);
2901         (md++)->base = t4_read_reg(adap, TP_CMM_MM_TX_FLST_BASE_A);
2902         (md++)->base = t4_read_reg(adap, TP_CMM_MM_PS_FLST_BASE_A);
2903
2904         /* the next few have explicit upper bounds */
2905         md->base = t4_read_reg(adap, TP_PMM_TX_BASE_A);
2906         md->limit = md->base - 1 +
2907                     t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A) *
2908                     PMTXMAXPAGE_G(t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A));
2909         md++;
2910
2911         md->base = t4_read_reg(adap, TP_PMM_RX_BASE_A);
2912         md->limit = md->base - 1 +
2913                     t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) *
2914                     PMRXMAXPAGE_G(t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A));
2915         md++;
2916
2917         if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
2918                 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5) {
2919                         hi = t4_read_reg(adap, LE_DB_TID_HASHBASE_A) / 4;
2920                         md->base = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
2921                  } else {
2922                         hi = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
2923                         md->base = t4_read_reg(adap,
2924                                                LE_DB_HASH_TBL_BASE_ADDR_A);
2925                 }
2926                 md->limit = 0;
2927         } else {
2928                 md->base = 0;
2929                 md->idx = ARRAY_SIZE(region);  /* hide it */
2930         }
2931         md++;
2932
2933 #define ulp_region(reg) do { \
2934         md->base = t4_read_reg(adap, ULP_ ## reg ## _LLIMIT_A);\
2935         (md++)->limit = t4_read_reg(adap, ULP_ ## reg ## _ULIMIT_A); \
2936 } while (0)
2937
2938         ulp_region(RX_ISCSI);
2939         ulp_region(RX_TDDP);
2940         ulp_region(TX_TPT);
2941         ulp_region(RX_STAG);
2942         ulp_region(RX_RQ);
2943         ulp_region(RX_RQUDP);
2944         ulp_region(RX_PBL);
2945         ulp_region(TX_PBL);
2946 #undef ulp_region
2947         md->base = 0;
2948         md->idx = ARRAY_SIZE(region);
2949         if (!is_t4(adap->params.chip)) {
2950                 u32 size = 0;
2951                 u32 sge_ctrl = t4_read_reg(adap, SGE_CONTROL2_A);
2952                 u32 fifo_size = t4_read_reg(adap, SGE_DBVFIFO_SIZE_A);
2953
2954                 if (is_t5(adap->params.chip)) {
2955                         if (sge_ctrl & VFIFO_ENABLE_F)
2956                                 size = DBVFIFO_SIZE_G(fifo_size);
2957                 } else {
2958                         size = T6_DBVFIFO_SIZE_G(fifo_size);
2959                 }
2960
2961                 if (size) {
2962                         md->base = BASEADDR_G(t4_read_reg(adap,
2963                                         SGE_DBVFIFO_BADDR_A));
2964                         md->limit = md->base + (size << 2) - 1;
2965                 }
2966         }
2967
2968         md++;
2969
2970         md->base = t4_read_reg(adap, ULP_RX_CTX_BASE_A);
2971         md->limit = 0;
2972         md++;
2973         md->base = t4_read_reg(adap, ULP_TX_ERR_TABLE_BASE_A);
2974         md->limit = 0;
2975         md++;
2976
2977         md->base = adap->vres.ocq.start;
2978         if (adap->vres.ocq.size)
2979                 md->limit = md->base + adap->vres.ocq.size - 1;
2980         else
2981                 md->idx = ARRAY_SIZE(region);  /* hide it */
2982         md++;
2983
2984         /* add any address-space holes, there can be up to 3 */
2985         for (n = 0; n < i - 1; n++)
2986                 if (avail[n].limit < avail[n + 1].base)
2987                         (md++)->base = avail[n].limit;
2988         if (avail[n].limit)
2989                 (md++)->base = avail[n].limit;
2990
2991         n = md - mem;
2992         sort(mem, n, sizeof(struct mem_desc), mem_desc_cmp, NULL);
2993
2994         for (lo = 0; lo < i; lo++)
2995                 mem_region_show(seq, memory[avail[lo].idx], avail[lo].base,
2996                                 avail[lo].limit - 1);
2997
2998         seq_putc(seq, '\n');
2999         for (i = 0; i < n; i++) {
3000                 if (mem[i].idx >= ARRAY_SIZE(region))
3001                         continue;                        /* skip holes */
3002                 if (!mem[i].limit)
3003                         mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
3004                 mem_region_show(seq, region[mem[i].idx], mem[i].base,
3005                                 mem[i].limit);
3006         }
3007
3008         seq_putc(seq, '\n');
3009         lo = t4_read_reg(adap, CIM_SDRAM_BASE_ADDR_A);
3010         hi = t4_read_reg(adap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
3011         mem_region_show(seq, "uP RAM:", lo, hi);
3012
3013         lo = t4_read_reg(adap, CIM_EXTMEM2_BASE_ADDR_A);
3014         hi = t4_read_reg(adap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
3015         mem_region_show(seq, "uP Extmem2:", lo, hi);
3016
3017         lo = t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A);
3018         seq_printf(seq, "\n%u Rx pages of size %uKiB for %u channels\n",
3019                    PMRXMAXPAGE_G(lo),
3020                    t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) >> 10,
3021                    (lo & PMRXNUMCHN_F) ? 2 : 1);
3022
3023         lo = t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A);
3024         hi = t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A);
3025         seq_printf(seq, "%u Tx pages of size %u%ciB for %u channels\n",
3026                    PMTXMAXPAGE_G(lo),
3027                    hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
3028                    hi >= (1 << 20) ? 'M' : 'K', 1 << PMTXNUMCHN_G(lo));
3029         seq_printf(seq, "%u p-structs\n\n",
3030                    t4_read_reg(adap, TP_CMM_MM_MAX_PSTRUCT_A));
3031
3032         for (i = 0; i < 4; i++) {
3033                 if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
3034                         lo = t4_read_reg(adap, MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
3035                 else
3036                         lo = t4_read_reg(adap, MPS_RX_PG_RSV0_A + i * 4);
3037                 if (is_t5(adap->params.chip)) {
3038                         used = T5_USED_G(lo);
3039                         alloc = T5_ALLOC_G(lo);
3040                 } else {
3041                         used = USED_G(lo);
3042                         alloc = ALLOC_G(lo);
3043                 }
3044                 /* For T6 these are MAC buffer groups */
3045                 seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
3046                            i, used, alloc);
3047         }
3048         for (i = 0; i < adap->params.arch.nchan; i++) {
3049                 if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
3050                         lo = t4_read_reg(adap,
3051                                          MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
3052                 else
3053                         lo = t4_read_reg(adap, MPS_RX_PG_RSV4_A + i * 4);
3054                 if (is_t5(adap->params.chip)) {
3055                         used = T5_USED_G(lo);
3056                         alloc = T5_ALLOC_G(lo);
3057                 } else {
3058                         used = USED_G(lo);
3059                         alloc = ALLOC_G(lo);
3060                 }
3061                 /* For T6 these are MAC buffer groups */
3062                 seq_printf(seq,
3063                            "Loopback %d using %u pages out of %u allocated\n",
3064                            i, used, alloc);
3065         }
3066         return 0;
3067 }
3068
3069 static int meminfo_open(struct inode *inode, struct file *file)
3070 {
3071         return single_open(file, meminfo_show, inode->i_private);
3072 }
3073
3074 static const struct file_operations meminfo_fops = {
3075         .owner   = THIS_MODULE,
3076         .open    = meminfo_open,
3077         .read    = seq_read,
3078         .llseek  = seq_lseek,
3079         .release = single_release,
3080 };
3081
3082 static int chcr_show(struct seq_file *seq, void *v)
3083 {
3084         struct adapter *adap = seq->private;
3085
3086         seq_puts(seq, "Chelsio Crypto Accelerator Stats \n");
3087         seq_printf(seq, "Cipher Ops: %10u \n",
3088                    atomic_read(&adap->chcr_stats.cipher_rqst));
3089         seq_printf(seq, "Digest Ops: %10u \n",
3090                    atomic_read(&adap->chcr_stats.digest_rqst));
3091         seq_printf(seq, "Aead Ops: %10u \n",
3092                    atomic_read(&adap->chcr_stats.aead_rqst));
3093         seq_printf(seq, "Completion: %10u \n",
3094                    atomic_read(&adap->chcr_stats.complete));
3095         seq_printf(seq, "Error: %10u \n",
3096                    atomic_read(&adap->chcr_stats.error));
3097         seq_printf(seq, "Fallback: %10u \n",
3098                    atomic_read(&adap->chcr_stats.fallback));
3099         return 0;
3100 }
3101
3102
3103 static int chcr_stats_open(struct inode *inode, struct file *file)
3104 {
3105         return single_open(file, chcr_show, inode->i_private);
3106 }
3107
3108 static const struct file_operations chcr_stats_debugfs_fops = {
3109         .owner   = THIS_MODULE,
3110         .open    = chcr_stats_open,
3111         .read    = seq_read,
3112         .llseek  = seq_lseek,
3113         .release = single_release,
3114 };
3115 /* Add an array of Debug FS files.
3116  */
3117 void add_debugfs_files(struct adapter *adap,
3118                        struct t4_debugfs_entry *files,
3119                        unsigned int nfiles)
3120 {
3121         int i;
3122
3123         /* debugfs support is best effort */
3124         for (i = 0; i < nfiles; i++)
3125                 debugfs_create_file(files[i].name, files[i].mode,
3126                                     adap->debugfs_root,
3127                                     (void *)adap + files[i].data,
3128                                     files[i].ops);
3129 }
3130
3131 int t4_setup_debugfs(struct adapter *adap)
3132 {
3133         int i;
3134         u32 size = 0;
3135         struct dentry *de;
3136
3137         static struct t4_debugfs_entry t4_debugfs_files[] = {
3138                 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
3139                 { "cim_pif_la", &cim_pif_la_fops, S_IRUSR, 0 },
3140                 { "cim_ma_la", &cim_ma_la_fops, S_IRUSR, 0 },
3141                 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
3142                 { "clk", &clk_debugfs_fops, S_IRUSR, 0 },
3143                 { "devlog", &devlog_fops, S_IRUSR, 0 },
3144                 { "mboxlog", &mboxlog_fops, S_IRUSR, 0 },
3145                 { "mbox0", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
3146                 { "mbox1", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
3147                 { "mbox2", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
3148                 { "mbox3", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3149                 { "mbox4", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 4 },
3150                 { "mbox5", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 5 },
3151                 { "mbox6", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 6 },
3152                 { "mbox7", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 7 },
3153                 { "trace0", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
3154                 { "trace1", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
3155                 { "trace2", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
3156                 { "trace3", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3157                 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
3158                 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
3159                 { "rss", &rss_debugfs_fops, S_IRUSR, 0 },
3160                 { "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
3161                 { "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
3162                 { "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
3163                 { "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
3164                 { "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
3165                 { "ibq_tp0",  &cim_ibq_fops, S_IRUSR, 0 },
3166                 { "ibq_tp1",  &cim_ibq_fops, S_IRUSR, 1 },
3167                 { "ibq_ulp",  &cim_ibq_fops, S_IRUSR, 2 },
3168                 { "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
3169                 { "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
3170                 { "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
3171                 { "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
3172                 { "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
3173                 { "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
3174                 { "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
3175                 { "obq_sge",  &cim_obq_fops, S_IRUSR, 4 },
3176                 { "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
3177                 { "tp_la", &tp_la_fops, S_IRUSR, 0 },
3178                 { "ulprx_la", &ulprx_la_fops, S_IRUSR, 0 },
3179                 { "sensors", &sensors_debugfs_fops, S_IRUSR, 0 },
3180                 { "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
3181                 { "tx_rate", &tx_rate_debugfs_fops, S_IRUSR, 0 },
3182                 { "cctrl", &cctrl_tbl_debugfs_fops, S_IRUSR, 0 },
3183 #if IS_ENABLED(CONFIG_IPV6)
3184                 { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
3185 #endif
3186                 { "tids", &tid_info_debugfs_fops, S_IRUSR, 0},
3187                 { "blocked_fl", &blocked_fl_fops, S_IRUSR | S_IWUSR, 0 },
3188                 { "meminfo", &meminfo_fops, S_IRUSR, 0 },
3189                 { "crypto", &chcr_stats_debugfs_fops, S_IRUSR, 0 },
3190         };
3191
3192         /* Debug FS nodes common to all T5 and later adapters.
3193          */
3194         static struct t4_debugfs_entry t5_debugfs_files[] = {
3195                 { "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
3196                 { "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
3197         };
3198
3199         add_debugfs_files(adap,
3200                           t4_debugfs_files,
3201                           ARRAY_SIZE(t4_debugfs_files));
3202         if (!is_t4(adap->params.chip))
3203                 add_debugfs_files(adap,
3204                                   t5_debugfs_files,
3205                                   ARRAY_SIZE(t5_debugfs_files));
3206
3207         i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
3208         if (i & EDRAM0_ENABLE_F) {
3209                 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
3210                 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
3211         }
3212         if (i & EDRAM1_ENABLE_F) {
3213                 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
3214                 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
3215         }
3216         if (is_t5(adap->params.chip)) {
3217                 if (i & EXT_MEM0_ENABLE_F) {
3218                         size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
3219                         add_debugfs_mem(adap, "mc0", MEM_MC0,
3220                                         EXT_MEM0_SIZE_G(size));
3221                 }
3222                 if (i & EXT_MEM1_ENABLE_F) {
3223                         size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
3224                         add_debugfs_mem(adap, "mc1", MEM_MC1,
3225                                         EXT_MEM1_SIZE_G(size));
3226                 }
3227         } else {
3228                 if (i & EXT_MEM_ENABLE_F) {
3229                         size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
3230                         add_debugfs_mem(adap, "mc", MEM_MC,
3231                                         EXT_MEM_SIZE_G(size));
3232                 }
3233         }
3234
3235         de = debugfs_create_file_size("flash", S_IRUSR, adap->debugfs_root, adap,
3236                                       &flash_debugfs_fops, adap->params.sf_size);
3237         debugfs_create_bool("use_backdoor", S_IWUSR | S_IRUSR,
3238                             adap->debugfs_root, &adap->use_bd);
3239         debugfs_create_bool("trace_rss", S_IWUSR | S_IRUSR,
3240                             adap->debugfs_root, &adap->trace_rss);
3241
3242         return 0;
3243 }