]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
cxgb4: Adds support for T6 adapter
[karo-tx-linux.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         if (v)
70                 ++*pos;
71         return v;
72 }
73
74 static void seq_tab_stop(struct seq_file *seq, void *v)
75 {
76 }
77
78 static int seq_tab_show(struct seq_file *seq, void *v)
79 {
80         const struct seq_tab *tb = seq->private;
81
82         return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
83 }
84
85 static const struct seq_operations seq_tab_ops = {
86         .start = seq_tab_start,
87         .next  = seq_tab_next,
88         .stop  = seq_tab_stop,
89         .show  = seq_tab_show
90 };
91
92 struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
93                              unsigned int width, unsigned int have_header,
94                              int (*show)(struct seq_file *seq, void *v, int i))
95 {
96         struct seq_tab *p;
97
98         p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
99         if (p) {
100                 p->show = show;
101                 p->rows = rows;
102                 p->width = width;
103                 p->skip_first = have_header != 0;
104         }
105         return p;
106 }
107
108 /* Trim the size of a seq_tab to the supplied number of rows.  The operation is
109  * irreversible.
110  */
111 static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
112 {
113         if (new_rows > p->rows)
114                 return -EINVAL;
115         p->rows = new_rows;
116         return 0;
117 }
118
119 static int cim_la_show(struct seq_file *seq, void *v, int idx)
120 {
121         if (v == SEQ_START_TOKEN)
122                 seq_puts(seq, "Status   Data      PC     LS0Stat  LS0Addr "
123                          "            LS0Data\n");
124         else {
125                 const u32 *p = v;
126
127                 seq_printf(seq,
128                            "  %02x  %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
129                            (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
130                            p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
131                            p[6], p[7]);
132         }
133         return 0;
134 }
135
136 static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
137 {
138         if (v == SEQ_START_TOKEN) {
139                 seq_puts(seq, "Status   Data      PC\n");
140         } else {
141                 const u32 *p = v;
142
143                 seq_printf(seq, "  %02x   %08x %08x\n", p[5] & 0xff, p[6],
144                            p[7]);
145                 seq_printf(seq, "  %02x   %02x%06x %02x%06x\n",
146                            (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
147                            p[4] & 0xff, p[5] >> 8);
148                 seq_printf(seq, "  %02x   %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
149                            p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
150         }
151         return 0;
152 }
153
154 static int cim_la_open(struct inode *inode, struct file *file)
155 {
156         int ret;
157         unsigned int cfg;
158         struct seq_tab *p;
159         struct adapter *adap = inode->i_private;
160
161         ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
162         if (ret)
163                 return ret;
164
165         p = seq_open_tab(file, adap->params.cim_la_size / 8, 8 * sizeof(u32), 1,
166                          cfg & UPDBGLACAPTPCONLY_F ?
167                          cim_la_show_3in1 : cim_la_show);
168         if (!p)
169                 return -ENOMEM;
170
171         ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
172         if (ret)
173                 seq_release_private(inode, file);
174         return ret;
175 }
176
177 static const struct file_operations cim_la_fops = {
178         .owner   = THIS_MODULE,
179         .open    = cim_la_open,
180         .read    = seq_read,
181         .llseek  = seq_lseek,
182         .release = seq_release_private
183 };
184
185 static int cim_qcfg_show(struct seq_file *seq, void *v)
186 {
187         static const char * const qname[] = {
188                 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
189                 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
190                 "SGE0-RX", "SGE1-RX"
191         };
192
193         int i;
194         struct adapter *adap = seq->private;
195         u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
196         u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
197         u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
198         u16 thres[CIM_NUM_IBQ];
199         u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
200         u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
201         u32 *p = stat;
202         int cim_num_obq = is_t4(adap->params.chip) ?
203                                 CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
204
205         i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
206                         UP_IBQ_0_SHADOW_RDADDR_A,
207                         ARRAY_SIZE(stat), stat);
208         if (!i) {
209                 if (is_t4(adap->params.chip)) {
210                         i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
211                                         ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
212                                 wr = obq_wr_t4;
213                 } else {
214                         i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
215                                         ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
216                                 wr = obq_wr_t5;
217                 }
218         }
219         if (i)
220                 return i;
221
222         t4_read_cimq_cfg(adap, base, size, thres);
223
224         seq_printf(seq,
225                    "  Queue  Base  Size Thres  RdPtr WrPtr  SOP  EOP Avail\n");
226         for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
227                 seq_printf(seq, "%7s %5x %5u %5u %6x  %4x %4u %4u %5u\n",
228                            qname[i], base[i], size[i], thres[i],
229                            IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
230                            QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
231                            QUEREMFLITS_G(p[2]) * 16);
232         for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
233                 seq_printf(seq, "%7s %5x %5u %12x  %4x %4u %4u %5u\n",
234                            qname[i], base[i], size[i],
235                            QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
236                            QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
237                            QUEREMFLITS_G(p[2]) * 16);
238         return 0;
239 }
240
241 static int cim_qcfg_open(struct inode *inode, struct file *file)
242 {
243         return single_open(file, cim_qcfg_show, inode->i_private);
244 }
245
246 static const struct file_operations cim_qcfg_fops = {
247         .owner   = THIS_MODULE,
248         .open    = cim_qcfg_open,
249         .read    = seq_read,
250         .llseek  = seq_lseek,
251         .release = single_release,
252 };
253
254 static int cimq_show(struct seq_file *seq, void *v, int idx)
255 {
256         const u32 *p = v;
257
258         seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
259                    p[2], p[3]);
260         return 0;
261 }
262
263 static int cim_ibq_open(struct inode *inode, struct file *file)
264 {
265         int ret;
266         struct seq_tab *p;
267         unsigned int qid = (uintptr_t)inode->i_private & 7;
268         struct adapter *adap = inode->i_private - qid;
269
270         p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
271         if (!p)
272                 return -ENOMEM;
273
274         ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
275         if (ret < 0)
276                 seq_release_private(inode, file);
277         else
278                 ret = 0;
279         return ret;
280 }
281
282 static const struct file_operations cim_ibq_fops = {
283         .owner   = THIS_MODULE,
284         .open    = cim_ibq_open,
285         .read    = seq_read,
286         .llseek  = seq_lseek,
287         .release = seq_release_private
288 };
289
290 static int cim_obq_open(struct inode *inode, struct file *file)
291 {
292         int ret;
293         struct seq_tab *p;
294         unsigned int qid = (uintptr_t)inode->i_private & 7;
295         struct adapter *adap = inode->i_private - qid;
296
297         p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
298         if (!p)
299                 return -ENOMEM;
300
301         ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
302         if (ret < 0) {
303                 seq_release_private(inode, file);
304         } else {
305                 seq_tab_trim(p, ret / 4);
306                 ret = 0;
307         }
308         return ret;
309 }
310
311 static const struct file_operations cim_obq_fops = {
312         .owner   = THIS_MODULE,
313         .open    = cim_obq_open,
314         .read    = seq_read,
315         .llseek  = seq_lseek,
316         .release = seq_release_private
317 };
318
319 struct field_desc {
320         const char *name;
321         unsigned int start;
322         unsigned int width;
323 };
324
325 static void field_desc_show(struct seq_file *seq, u64 v,
326                             const struct field_desc *p)
327 {
328         char buf[32];
329         int line_size = 0;
330
331         while (p->name) {
332                 u64 mask = (1ULL << p->width) - 1;
333                 int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
334                                     ((unsigned long long)v >> p->start) & mask);
335
336                 if (line_size + len >= 79) {
337                         line_size = 8;
338                         seq_puts(seq, "\n        ");
339                 }
340                 seq_printf(seq, "%s ", buf);
341                 line_size += len + 1;
342                 p++;
343         }
344         seq_putc(seq, '\n');
345 }
346
347 static struct field_desc tp_la0[] = {
348         { "RcfOpCodeOut", 60, 4 },
349         { "State", 56, 4 },
350         { "WcfState", 52, 4 },
351         { "RcfOpcSrcOut", 50, 2 },
352         { "CRxError", 49, 1 },
353         { "ERxError", 48, 1 },
354         { "SanityFailed", 47, 1 },
355         { "SpuriousMsg", 46, 1 },
356         { "FlushInputMsg", 45, 1 },
357         { "FlushInputCpl", 44, 1 },
358         { "RssUpBit", 43, 1 },
359         { "RssFilterHit", 42, 1 },
360         { "Tid", 32, 10 },
361         { "InitTcb", 31, 1 },
362         { "LineNumber", 24, 7 },
363         { "Emsg", 23, 1 },
364         { "EdataOut", 22, 1 },
365         { "Cmsg", 21, 1 },
366         { "CdataOut", 20, 1 },
367         { "EreadPdu", 19, 1 },
368         { "CreadPdu", 18, 1 },
369         { "TunnelPkt", 17, 1 },
370         { "RcfPeerFin", 16, 1 },
371         { "RcfReasonOut", 12, 4 },
372         { "TxCchannel", 10, 2 },
373         { "RcfTxChannel", 8, 2 },
374         { "RxEchannel", 6, 2 },
375         { "RcfRxChannel", 5, 1 },
376         { "RcfDataOutSrdy", 4, 1 },
377         { "RxDvld", 3, 1 },
378         { "RxOoDvld", 2, 1 },
379         { "RxCongestion", 1, 1 },
380         { "TxCongestion", 0, 1 },
381         { NULL }
382 };
383
384 static int tp_la_show(struct seq_file *seq, void *v, int idx)
385 {
386         const u64 *p = v;
387
388         field_desc_show(seq, *p, tp_la0);
389         return 0;
390 }
391
392 static int tp_la_show2(struct seq_file *seq, void *v, int idx)
393 {
394         const u64 *p = v;
395
396         if (idx)
397                 seq_putc(seq, '\n');
398         field_desc_show(seq, p[0], tp_la0);
399         if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
400                 field_desc_show(seq, p[1], tp_la0);
401         return 0;
402 }
403
404 static int tp_la_show3(struct seq_file *seq, void *v, int idx)
405 {
406         static struct field_desc tp_la1[] = {
407                 { "CplCmdIn", 56, 8 },
408                 { "CplCmdOut", 48, 8 },
409                 { "ESynOut", 47, 1 },
410                 { "EAckOut", 46, 1 },
411                 { "EFinOut", 45, 1 },
412                 { "ERstOut", 44, 1 },
413                 { "SynIn", 43, 1 },
414                 { "AckIn", 42, 1 },
415                 { "FinIn", 41, 1 },
416                 { "RstIn", 40, 1 },
417                 { "DataIn", 39, 1 },
418                 { "DataInVld", 38, 1 },
419                 { "PadIn", 37, 1 },
420                 { "RxBufEmpty", 36, 1 },
421                 { "RxDdp", 35, 1 },
422                 { "RxFbCongestion", 34, 1 },
423                 { "TxFbCongestion", 33, 1 },
424                 { "TxPktSumSrdy", 32, 1 },
425                 { "RcfUlpType", 28, 4 },
426                 { "Eread", 27, 1 },
427                 { "Ebypass", 26, 1 },
428                 { "Esave", 25, 1 },
429                 { "Static0", 24, 1 },
430                 { "Cread", 23, 1 },
431                 { "Cbypass", 22, 1 },
432                 { "Csave", 21, 1 },
433                 { "CPktOut", 20, 1 },
434                 { "RxPagePoolFull", 18, 2 },
435                 { "RxLpbkPkt", 17, 1 },
436                 { "TxLpbkPkt", 16, 1 },
437                 { "RxVfValid", 15, 1 },
438                 { "SynLearned", 14, 1 },
439                 { "SetDelEntry", 13, 1 },
440                 { "SetInvEntry", 12, 1 },
441                 { "CpcmdDvld", 11, 1 },
442                 { "CpcmdSave", 10, 1 },
443                 { "RxPstructsFull", 8, 2 },
444                 { "EpcmdDvld", 7, 1 },
445                 { "EpcmdFlush", 6, 1 },
446                 { "EpcmdTrimPrefix", 5, 1 },
447                 { "EpcmdTrimPostfix", 4, 1 },
448                 { "ERssIp4Pkt", 3, 1 },
449                 { "ERssIp6Pkt", 2, 1 },
450                 { "ERssTcpUdpPkt", 1, 1 },
451                 { "ERssFceFipPkt", 0, 1 },
452                 { NULL }
453         };
454         static struct field_desc tp_la2[] = {
455                 { "CplCmdIn", 56, 8 },
456                 { "MpsVfVld", 55, 1 },
457                 { "MpsPf", 52, 3 },
458                 { "MpsVf", 44, 8 },
459                 { "SynIn", 43, 1 },
460                 { "AckIn", 42, 1 },
461                 { "FinIn", 41, 1 },
462                 { "RstIn", 40, 1 },
463                 { "DataIn", 39, 1 },
464                 { "DataInVld", 38, 1 },
465                 { "PadIn", 37, 1 },
466                 { "RxBufEmpty", 36, 1 },
467                 { "RxDdp", 35, 1 },
468                 { "RxFbCongestion", 34, 1 },
469                 { "TxFbCongestion", 33, 1 },
470                 { "TxPktSumSrdy", 32, 1 },
471                 { "RcfUlpType", 28, 4 },
472                 { "Eread", 27, 1 },
473                 { "Ebypass", 26, 1 },
474                 { "Esave", 25, 1 },
475                 { "Static0", 24, 1 },
476                 { "Cread", 23, 1 },
477                 { "Cbypass", 22, 1 },
478                 { "Csave", 21, 1 },
479                 { "CPktOut", 20, 1 },
480                 { "RxPagePoolFull", 18, 2 },
481                 { "RxLpbkPkt", 17, 1 },
482                 { "TxLpbkPkt", 16, 1 },
483                 { "RxVfValid", 15, 1 },
484                 { "SynLearned", 14, 1 },
485                 { "SetDelEntry", 13, 1 },
486                 { "SetInvEntry", 12, 1 },
487                 { "CpcmdDvld", 11, 1 },
488                 { "CpcmdSave", 10, 1 },
489                 { "RxPstructsFull", 8, 2 },
490                 { "EpcmdDvld", 7, 1 },
491                 { "EpcmdFlush", 6, 1 },
492                 { "EpcmdTrimPrefix", 5, 1 },
493                 { "EpcmdTrimPostfix", 4, 1 },
494                 { "ERssIp4Pkt", 3, 1 },
495                 { "ERssIp6Pkt", 2, 1 },
496                 { "ERssTcpUdpPkt", 1, 1 },
497                 { "ERssFceFipPkt", 0, 1 },
498                 { NULL }
499         };
500         const u64 *p = v;
501
502         if (idx)
503                 seq_putc(seq, '\n');
504         field_desc_show(seq, p[0], tp_la0);
505         if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
506                 field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
507         return 0;
508 }
509
510 static int tp_la_open(struct inode *inode, struct file *file)
511 {
512         struct seq_tab *p;
513         struct adapter *adap = inode->i_private;
514
515         switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
516         case 2:
517                 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
518                                  tp_la_show2);
519                 break;
520         case 3:
521                 p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
522                                  tp_la_show3);
523                 break;
524         default:
525                 p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
526         }
527         if (!p)
528                 return -ENOMEM;
529
530         t4_tp_read_la(adap, (u64 *)p->data, NULL);
531         return 0;
532 }
533
534 static ssize_t tp_la_write(struct file *file, const char __user *buf,
535                            size_t count, loff_t *pos)
536 {
537         int err;
538         char s[32];
539         unsigned long val;
540         size_t size = min(sizeof(s) - 1, count);
541         struct adapter *adap = file_inode(file)->i_private;
542
543         if (copy_from_user(s, buf, size))
544                 return -EFAULT;
545         s[size] = '\0';
546         err = kstrtoul(s, 0, &val);
547         if (err)
548                 return err;
549         if (val > 0xffff)
550                 return -EINVAL;
551         adap->params.tp.la_mask = val << 16;
552         t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
553                          adap->params.tp.la_mask);
554         return count;
555 }
556
557 static const struct file_operations tp_la_fops = {
558         .owner   = THIS_MODULE,
559         .open    = tp_la_open,
560         .read    = seq_read,
561         .llseek  = seq_lseek,
562         .release = seq_release_private,
563         .write   = tp_la_write
564 };
565
566 static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
567 {
568         const u32 *p = v;
569
570         if (v == SEQ_START_TOKEN)
571                 seq_puts(seq, "      Pcmd        Type   Message"
572                          "                Data\n");
573         else
574                 seq_printf(seq, "%08x%08x  %4x  %08x  %08x%08x%08x%08x\n",
575                            p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
576         return 0;
577 }
578
579 static int ulprx_la_open(struct inode *inode, struct file *file)
580 {
581         struct seq_tab *p;
582         struct adapter *adap = inode->i_private;
583
584         p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
585                          ulprx_la_show);
586         if (!p)
587                 return -ENOMEM;
588
589         t4_ulprx_read_la(adap, (u32 *)p->data);
590         return 0;
591 }
592
593 static const struct file_operations ulprx_la_fops = {
594         .owner   = THIS_MODULE,
595         .open    = ulprx_la_open,
596         .read    = seq_read,
597         .llseek  = seq_lseek,
598         .release = seq_release_private
599 };
600
601 /* Show the PM memory stats.  These stats include:
602  *
603  * TX:
604  *   Read: memory read operation
605  *   Write Bypass: cut-through
606  *   Bypass + mem: cut-through and save copy
607  *
608  * RX:
609  *   Read: memory read
610  *   Write Bypass: cut-through
611  *   Flush: payload trim or drop
612  */
613 static int pm_stats_show(struct seq_file *seq, void *v)
614 {
615         static const char * const tx_pm_stats[] = {
616                 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
617         };
618         static const char * const rx_pm_stats[] = {
619                 "Read:", "Write bypass:", "Write mem:", "Flush:"
620         };
621
622         int i;
623         u32 tx_cnt[PM_NSTATS], rx_cnt[PM_NSTATS];
624         u64 tx_cyc[PM_NSTATS], rx_cyc[PM_NSTATS];
625         struct adapter *adap = seq->private;
626
627         t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
628         t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
629
630         seq_printf(seq, "%13s %10s  %20s\n", " ", "Tx pcmds", "Tx bytes");
631         for (i = 0; i < PM_NSTATS - 1; i++)
632                 seq_printf(seq, "%-13s %10u  %20llu\n",
633                            tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
634
635         seq_printf(seq, "%13s %10s  %20s\n", " ", "Rx pcmds", "Rx bytes");
636         for (i = 0; i < PM_NSTATS - 1; i++)
637                 seq_printf(seq, "%-13s %10u  %20llu\n",
638                            rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
639         return 0;
640 }
641
642 static int pm_stats_open(struct inode *inode, struct file *file)
643 {
644         return single_open(file, pm_stats_show, inode->i_private);
645 }
646
647 static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
648                               size_t count, loff_t *pos)
649 {
650         struct adapter *adap = file_inode(file)->i_private;
651
652         t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
653         t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
654         return count;
655 }
656
657 static const struct file_operations pm_stats_debugfs_fops = {
658         .owner   = THIS_MODULE,
659         .open    = pm_stats_open,
660         .read    = seq_read,
661         .llseek  = seq_lseek,
662         .release = single_release,
663         .write   = pm_stats_clear
664 };
665
666 static int cctrl_tbl_show(struct seq_file *seq, void *v)
667 {
668         static const char * const dec_fac[] = {
669                 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
670                 "0.9375" };
671
672         int i;
673         u16 (*incr)[NCCTRL_WIN];
674         struct adapter *adap = seq->private;
675
676         incr = kmalloc(sizeof(*incr) * NMTUS, GFP_KERNEL);
677         if (!incr)
678                 return -ENOMEM;
679
680         t4_read_cong_tbl(adap, incr);
681
682         for (i = 0; i < NCCTRL_WIN; ++i) {
683                 seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
684                            incr[0][i], incr[1][i], incr[2][i], incr[3][i],
685                            incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
686                 seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
687                            incr[8][i], incr[9][i], incr[10][i], incr[11][i],
688                            incr[12][i], incr[13][i], incr[14][i], incr[15][i],
689                            adap->params.a_wnd[i],
690                            dec_fac[adap->params.b_wnd[i]]);
691         }
692
693         kfree(incr);
694         return 0;
695 }
696
697 DEFINE_SIMPLE_DEBUGFS_FILE(cctrl_tbl);
698
699 /* Format a value in a unit that differs from the value's native unit by the
700  * given factor.
701  */
702 static char *unit_conv(char *buf, size_t len, unsigned int val,
703                        unsigned int factor)
704 {
705         unsigned int rem = val % factor;
706
707         if (rem == 0) {
708                 snprintf(buf, len, "%u", val / factor);
709         } else {
710                 while (rem % 10 == 0)
711                         rem /= 10;
712                 snprintf(buf, len, "%u.%u", val / factor, rem);
713         }
714         return buf;
715 }
716
717 static int clk_show(struct seq_file *seq, void *v)
718 {
719         char buf[32];
720         struct adapter *adap = seq->private;
721         unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk;  /* in ps */
722         u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
723         unsigned int tre = TIMERRESOLUTION_G(res);
724         unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
725         unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
726
727         seq_printf(seq, "Core clock period: %s ns\n",
728                    unit_conv(buf, sizeof(buf), cclk_ps, 1000));
729         seq_printf(seq, "TP timer tick: %s us\n",
730                    unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
731         seq_printf(seq, "TCP timestamp tick: %s us\n",
732                    unit_conv(buf, sizeof(buf),
733                              (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
734         seq_printf(seq, "DACK tick: %s us\n",
735                    unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
736         seq_printf(seq, "DACK timer: %u us\n",
737                    ((cclk_ps << dack_re) / 1000000) *
738                    t4_read_reg(adap, TP_DACK_TIMER_A));
739         seq_printf(seq, "Retransmit min: %llu us\n",
740                    tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
741         seq_printf(seq, "Retransmit max: %llu us\n",
742                    tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
743         seq_printf(seq, "Persist timer min: %llu us\n",
744                    tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
745         seq_printf(seq, "Persist timer max: %llu us\n",
746                    tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
747         seq_printf(seq, "Keepalive idle timer: %llu us\n",
748                    tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
749         seq_printf(seq, "Keepalive interval: %llu us\n",
750                    tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
751         seq_printf(seq, "Initial SRTT: %llu us\n",
752                    tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
753         seq_printf(seq, "FINWAIT2 timer: %llu us\n",
754                    tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
755
756         return 0;
757 }
758
759 DEFINE_SIMPLE_DEBUGFS_FILE(clk);
760
761 /* Firmware Device Log dump. */
762 static const char * const devlog_level_strings[] = {
763         [FW_DEVLOG_LEVEL_EMERG]         = "EMERG",
764         [FW_DEVLOG_LEVEL_CRIT]          = "CRIT",
765         [FW_DEVLOG_LEVEL_ERR]           = "ERR",
766         [FW_DEVLOG_LEVEL_NOTICE]        = "NOTICE",
767         [FW_DEVLOG_LEVEL_INFO]          = "INFO",
768         [FW_DEVLOG_LEVEL_DEBUG]         = "DEBUG"
769 };
770
771 static const char * const devlog_facility_strings[] = {
772         [FW_DEVLOG_FACILITY_CORE]       = "CORE",
773         [FW_DEVLOG_FACILITY_SCHED]      = "SCHED",
774         [FW_DEVLOG_FACILITY_TIMER]      = "TIMER",
775         [FW_DEVLOG_FACILITY_RES]        = "RES",
776         [FW_DEVLOG_FACILITY_HW]         = "HW",
777         [FW_DEVLOG_FACILITY_FLR]        = "FLR",
778         [FW_DEVLOG_FACILITY_DMAQ]       = "DMAQ",
779         [FW_DEVLOG_FACILITY_PHY]        = "PHY",
780         [FW_DEVLOG_FACILITY_MAC]        = "MAC",
781         [FW_DEVLOG_FACILITY_PORT]       = "PORT",
782         [FW_DEVLOG_FACILITY_VI]         = "VI",
783         [FW_DEVLOG_FACILITY_FILTER]     = "FILTER",
784         [FW_DEVLOG_FACILITY_ACL]        = "ACL",
785         [FW_DEVLOG_FACILITY_TM]         = "TM",
786         [FW_DEVLOG_FACILITY_QFC]        = "QFC",
787         [FW_DEVLOG_FACILITY_DCB]        = "DCB",
788         [FW_DEVLOG_FACILITY_ETH]        = "ETH",
789         [FW_DEVLOG_FACILITY_OFLD]       = "OFLD",
790         [FW_DEVLOG_FACILITY_RI]         = "RI",
791         [FW_DEVLOG_FACILITY_ISCSI]      = "ISCSI",
792         [FW_DEVLOG_FACILITY_FCOE]       = "FCOE",
793         [FW_DEVLOG_FACILITY_FOISCSI]    = "FOISCSI",
794         [FW_DEVLOG_FACILITY_FOFCOE]     = "FOFCOE"
795 };
796
797 /* Information gathered by Device Log Open routine for the display routine.
798  */
799 struct devlog_info {
800         unsigned int nentries;          /* number of entries in log[] */
801         unsigned int first;             /* first [temporal] entry in log[] */
802         struct fw_devlog_e log[0];      /* Firmware Device Log */
803 };
804
805 /* Dump a Firmaware Device Log entry.
806  */
807 static int devlog_show(struct seq_file *seq, void *v)
808 {
809         if (v == SEQ_START_TOKEN)
810                 seq_printf(seq, "%10s  %15s  %8s  %8s  %s\n",
811                            "Seq#", "Tstamp", "Level", "Facility", "Message");
812         else {
813                 struct devlog_info *dinfo = seq->private;
814                 int fidx = (uintptr_t)v - 2;
815                 unsigned long index;
816                 struct fw_devlog_e *e;
817
818                 /* Get a pointer to the log entry to display.  Skip unused log
819                  * entries.
820                  */
821                 index = dinfo->first + fidx;
822                 if (index >= dinfo->nentries)
823                         index -= dinfo->nentries;
824                 e = &dinfo->log[index];
825                 if (e->timestamp == 0)
826                         return 0;
827
828                 /* Print the message.  This depends on the firmware using
829                  * exactly the same formating strings as the kernel so we may
830                  * eventually have to put a format interpreter in here ...
831                  */
832                 seq_printf(seq, "%10d  %15llu  %8s  %8s  ",
833                            e->seqno, e->timestamp,
834                            (e->level < ARRAY_SIZE(devlog_level_strings)
835                             ? devlog_level_strings[e->level]
836                             : "UNKNOWN"),
837                            (e->facility < ARRAY_SIZE(devlog_facility_strings)
838                             ? devlog_facility_strings[e->facility]
839                             : "UNKNOWN"));
840                 seq_printf(seq, e->fmt, e->params[0], e->params[1],
841                            e->params[2], e->params[3], e->params[4],
842                            e->params[5], e->params[6], e->params[7]);
843         }
844         return 0;
845 }
846
847 /* Sequential File Operations for Device Log.
848  */
849 static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
850 {
851         if (pos > dinfo->nentries)
852                 return NULL;
853
854         return (void *)(uintptr_t)(pos + 1);
855 }
856
857 static void *devlog_start(struct seq_file *seq, loff_t *pos)
858 {
859         struct devlog_info *dinfo = seq->private;
860
861         return (*pos
862                 ? devlog_get_idx(dinfo, *pos)
863                 : SEQ_START_TOKEN);
864 }
865
866 static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
867 {
868         struct devlog_info *dinfo = seq->private;
869
870         (*pos)++;
871         return devlog_get_idx(dinfo, *pos);
872 }
873
874 static void devlog_stop(struct seq_file *seq, void *v)
875 {
876 }
877
878 static const struct seq_operations devlog_seq_ops = {
879         .start = devlog_start,
880         .next  = devlog_next,
881         .stop  = devlog_stop,
882         .show  = devlog_show
883 };
884
885 /* Set up for reading the firmware's device log.  We read the entire log here
886  * and then display it incrementally in devlog_show().
887  */
888 static int devlog_open(struct inode *inode, struct file *file)
889 {
890         struct adapter *adap = inode->i_private;
891         struct devlog_params *dparams = &adap->params.devlog;
892         struct devlog_info *dinfo;
893         unsigned int index;
894         u32 fseqno;
895         int ret;
896
897         /* If we don't know where the log is we can't do anything.
898          */
899         if (dparams->start == 0)
900                 return -ENXIO;
901
902         /* Allocate the space to read in the firmware's device log and set up
903          * for the iterated call to our display function.
904          */
905         dinfo = __seq_open_private(file, &devlog_seq_ops,
906                                    sizeof(*dinfo) + dparams->size);
907         if (!dinfo)
908                 return -ENOMEM;
909
910         /* Record the basic log buffer information and read in the raw log.
911          */
912         dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
913         dinfo->first = 0;
914         spin_lock(&adap->win0_lock);
915         ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
916                            dparams->start, dparams->size, (__be32 *)dinfo->log,
917                            T4_MEMORY_READ);
918         spin_unlock(&adap->win0_lock);
919         if (ret) {
920                 seq_release_private(inode, file);
921                 return ret;
922         }
923
924         /* Translate log multi-byte integral elements into host native format
925          * and determine where the first entry in the log is.
926          */
927         for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
928                 struct fw_devlog_e *e = &dinfo->log[index];
929                 int i;
930                 __u32 seqno;
931
932                 if (e->timestamp == 0)
933                         continue;
934
935                 e->timestamp = (__force __be64)be64_to_cpu(e->timestamp);
936                 seqno = be32_to_cpu(e->seqno);
937                 for (i = 0; i < 8; i++)
938                         e->params[i] =
939                                 (__force __be32)be32_to_cpu(e->params[i]);
940
941                 if (seqno < fseqno) {
942                         fseqno = seqno;
943                         dinfo->first = index;
944                 }
945         }
946         return 0;
947 }
948
949 static const struct file_operations devlog_fops = {
950         .owner   = THIS_MODULE,
951         .open    = devlog_open,
952         .read    = seq_read,
953         .llseek  = seq_lseek,
954         .release = seq_release_private
955 };
956
957 static int mbox_show(struct seq_file *seq, void *v)
958 {
959         static const char * const owner[] = { "none", "FW", "driver",
960                                               "unknown" };
961
962         int i;
963         unsigned int mbox = (uintptr_t)seq->private & 7;
964         struct adapter *adap = seq->private - mbox;
965         void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
966         unsigned int ctrl_reg = (is_t4(adap->params.chip)
967                                  ? CIM_PF_MAILBOX_CTRL_A
968                                  : CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A);
969         void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
970
971         i = MBOWNER_G(readl(ctrl));
972         seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
973
974         for (i = 0; i < MBOX_LEN; i += 8)
975                 seq_printf(seq, "%016llx\n",
976                            (unsigned long long)readq(addr + i));
977         return 0;
978 }
979
980 static int mbox_open(struct inode *inode, struct file *file)
981 {
982         return single_open(file, mbox_show, inode->i_private);
983 }
984
985 static ssize_t mbox_write(struct file *file, const char __user *buf,
986                           size_t count, loff_t *pos)
987 {
988         int i;
989         char c = '\n', s[256];
990         unsigned long long data[8];
991         const struct inode *ino;
992         unsigned int mbox;
993         struct adapter *adap;
994         void __iomem *addr;
995         void __iomem *ctrl;
996
997         if (count > sizeof(s) - 1 || !count)
998                 return -EINVAL;
999         if (copy_from_user(s, buf, count))
1000                 return -EFAULT;
1001         s[count] = '\0';
1002
1003         if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
1004                    &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
1005                    &data[7], &c) < 8 || c != '\n')
1006                 return -EINVAL;
1007
1008         ino = file_inode(file);
1009         mbox = (uintptr_t)ino->i_private & 7;
1010         adap = ino->i_private - mbox;
1011         addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1012         ctrl = addr + MBOX_LEN;
1013
1014         if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
1015                 return -EBUSY;
1016
1017         for (i = 0; i < 8; i++)
1018                 writeq(data[i], addr + 8 * i);
1019
1020         writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
1021         return count;
1022 }
1023
1024 static const struct file_operations mbox_debugfs_fops = {
1025         .owner   = THIS_MODULE,
1026         .open    = mbox_open,
1027         .read    = seq_read,
1028         .llseek  = seq_lseek,
1029         .release = single_release,
1030         .write   = mbox_write
1031 };
1032
1033 static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
1034                           loff_t *ppos)
1035 {
1036         loff_t pos = *ppos;
1037         loff_t avail = file_inode(file)->i_size;
1038         struct adapter *adap = file->private_data;
1039
1040         if (pos < 0)
1041                 return -EINVAL;
1042         if (pos >= avail)
1043                 return 0;
1044         if (count > avail - pos)
1045                 count = avail - pos;
1046
1047         while (count) {
1048                 size_t len;
1049                 int ret, ofst;
1050                 u8 data[256];
1051
1052                 ofst = pos & 3;
1053                 len = min(count + ofst, sizeof(data));
1054                 ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
1055                                     (u32 *)data, 1);
1056                 if (ret)
1057                         return ret;
1058
1059                 len -= ofst;
1060                 if (copy_to_user(buf, data + ofst, len))
1061                         return -EFAULT;
1062
1063                 buf += len;
1064                 pos += len;
1065                 count -= len;
1066         }
1067         count = pos - *ppos;
1068         *ppos = pos;
1069         return count;
1070 }
1071
1072 static const struct file_operations flash_debugfs_fops = {
1073         .owner   = THIS_MODULE,
1074         .open    = mem_open,
1075         .read    = flash_read,
1076 };
1077
1078 static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1079 {
1080         *mask = x | y;
1081         y = (__force u64)cpu_to_be64(y);
1082         memcpy(addr, (char *)&y + 2, ETH_ALEN);
1083 }
1084
1085 static int mps_tcam_show(struct seq_file *seq, void *v)
1086 {
1087         struct adapter *adap = seq->private;
1088         unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
1089
1090         if (v == SEQ_START_TOKEN) {
1091                 if (adap->params.arch.mps_rplc_size > 128)
1092                         seq_puts(seq, "Idx  Ethernet address     Mask     "
1093                                  "Vld Ports PF  VF                           "
1094                                  "Replication                                "
1095                                  "    P0 P1 P2 P3  ML\n");
1096                 else
1097                         seq_puts(seq, "Idx  Ethernet address     Mask     "
1098                                  "Vld Ports PF  VF              Replication"
1099                                  "               P0 P1 P2 P3  ML\n");
1100         } else {
1101                 u64 mask;
1102                 u8 addr[ETH_ALEN];
1103                 bool replicate;
1104                 unsigned int idx = (uintptr_t)v - 2;
1105                 u64 tcamy, tcamx, val;
1106                 u32 cls_lo, cls_hi, ctl;
1107                 u32 rplc[8] = {0};
1108
1109                 if (chip_ver > CHELSIO_T5) {
1110                         /* CtlCmdType - 0: Read, 1: Write
1111                          * CtlTcamSel - 0: TCAM0, 1: TCAM1
1112                          * CtlXYBitSel- 0: Y bit, 1: X bit
1113                          */
1114
1115                         /* Read tcamy */
1116                         ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
1117                         if (idx < 256)
1118                                 ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
1119                         else
1120                                 ctl |= CTLTCAMINDEX_V(idx - 256) |
1121                                        CTLTCAMSEL_V(1);
1122                         t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1123                         val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
1124                         tcamy = DMACH_G(val) << 32;
1125                         tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1126
1127                         /* Read tcamx. Change the control param */
1128                         ctl |= CTLXYBITSEL_V(1);
1129                         t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
1130                         val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
1131                         tcamx = DMACH_G(val) << 32;
1132                         tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1133                 } else {
1134                         tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
1135                         tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
1136                 }
1137
1138                 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
1139                 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
1140
1141                 if (tcamx & tcamy) {
1142                         seq_printf(seq, "%3u         -\n", idx);
1143                         goto out;
1144                 }
1145
1146                 rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
1147                 if (chip_ver > CHELSIO_T5)
1148                         replicate = (cls_lo & T6_REPLICATE_F);
1149                 else
1150                         replicate = (cls_lo & REPLICATE_F);
1151
1152                 if (replicate) {
1153                         struct fw_ldst_cmd ldst_cmd;
1154                         int ret;
1155                         struct fw_ldst_mps_rplc mps_rplc;
1156                         u32 ldst_addrspc;
1157
1158                         memset(&ldst_cmd, 0, sizeof(ldst_cmd));
1159                         ldst_addrspc =
1160                                 FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
1161                         ldst_cmd.op_to_addrspace =
1162                                 htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1163                                       FW_CMD_REQUEST_F |
1164                                       FW_CMD_READ_F |
1165                                       ldst_addrspc);
1166                         ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
1167                         ldst_cmd.u.mps.rplc.fid_idx =
1168                                 htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
1169                                       FW_LDST_CMD_IDX_V(idx));
1170                         ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1171                                          sizeof(ldst_cmd), &ldst_cmd);
1172                         if (ret)
1173                                 dev_warn(adap->pdev_dev, "Can't read MPS "
1174                                          "replication map for idx %d: %d\n",
1175                                          idx, -ret);
1176                         else {
1177                                 mps_rplc = ldst_cmd.u.mps.rplc;
1178                                 rplc[0] = ntohl(mps_rplc.rplc31_0);
1179                                 rplc[1] = ntohl(mps_rplc.rplc63_32);
1180                                 rplc[2] = ntohl(mps_rplc.rplc95_64);
1181                                 rplc[3] = ntohl(mps_rplc.rplc127_96);
1182                                 if (adap->params.arch.mps_rplc_size > 128) {
1183                                         rplc[4] = ntohl(mps_rplc.rplc159_128);
1184                                         rplc[5] = ntohl(mps_rplc.rplc191_160);
1185                                         rplc[6] = ntohl(mps_rplc.rplc223_192);
1186                                         rplc[7] = ntohl(mps_rplc.rplc255_224);
1187                                 }
1188                         }
1189                 }
1190
1191                 tcamxy2valmask(tcamx, tcamy, addr, &mask);
1192                 if (chip_ver > CHELSIO_T5)
1193                         seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1194                                    "%012llx%3c   %#x%4u%4d",
1195                                    idx, addr[0], addr[1], addr[2], addr[3],
1196                                    addr[4], addr[5], (unsigned long long)mask,
1197                                    (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1198                                    PORTMAP_G(cls_hi),
1199                                    T6_PF_G(cls_lo),
1200                                    (cls_lo & T6_VF_VALID_F) ?
1201                                    T6_VF_G(cls_lo) : -1);
1202                 else
1203                         seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1204                                    "%012llx%3c   %#x%4u%4d",
1205                                    idx, addr[0], addr[1], addr[2], addr[3],
1206                                    addr[4], addr[5], (unsigned long long)mask,
1207                                    (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
1208                                    PORTMAP_G(cls_hi),
1209                                    PF_G(cls_lo),
1210                                    (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
1211
1212                 if (replicate) {
1213                         if (adap->params.arch.mps_rplc_size > 128)
1214                                 seq_printf(seq, " %08x %08x %08x %08x "
1215                                            "%08x %08x %08x %08x",
1216                                            rplc[7], rplc[6], rplc[5], rplc[4],
1217                                            rplc[3], rplc[2], rplc[1], rplc[0]);
1218                         else
1219                                 seq_printf(seq, " %08x %08x %08x %08x",
1220                                            rplc[3], rplc[2], rplc[1], rplc[0]);
1221                 } else {
1222                         if (adap->params.arch.mps_rplc_size > 128)
1223                                 seq_printf(seq, "%72c", ' ');
1224                         else
1225                                 seq_printf(seq, "%36c", ' ');
1226                 }
1227
1228                 if (chip_ver > CHELSIO_T5)
1229                         seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1230                                    T6_SRAM_PRIO0_G(cls_lo),
1231                                    T6_SRAM_PRIO1_G(cls_lo),
1232                                    T6_SRAM_PRIO2_G(cls_lo),
1233                                    T6_SRAM_PRIO3_G(cls_lo),
1234                                    (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
1235                 else
1236                         seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1237                                    SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1238                                    SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1239                                    (cls_lo >> MULTILISTEN0_S) & 0xf);
1240         }
1241 out:    return 0;
1242 }
1243
1244 static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1245 {
1246         struct adapter *adap = seq->private;
1247         int max_mac_addr = is_t4(adap->params.chip) ?
1248                                 NUM_MPS_CLS_SRAM_L_INSTANCES :
1249                                 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1250         return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1251 }
1252
1253 static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1254 {
1255         return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1256 }
1257
1258 static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1259 {
1260         ++*pos;
1261         return mps_tcam_get_idx(seq, *pos);
1262 }
1263
1264 static void mps_tcam_stop(struct seq_file *seq, void *v)
1265 {
1266 }
1267
1268 static const struct seq_operations mps_tcam_seq_ops = {
1269         .start = mps_tcam_start,
1270         .next  = mps_tcam_next,
1271         .stop  = mps_tcam_stop,
1272         .show  = mps_tcam_show
1273 };
1274
1275 static int mps_tcam_open(struct inode *inode, struct file *file)
1276 {
1277         int res = seq_open(file, &mps_tcam_seq_ops);
1278
1279         if (!res) {
1280                 struct seq_file *seq = file->private_data;
1281
1282                 seq->private = inode->i_private;
1283         }
1284         return res;
1285 }
1286
1287 static const struct file_operations mps_tcam_debugfs_fops = {
1288         .owner   = THIS_MODULE,
1289         .open    = mps_tcam_open,
1290         .read    = seq_read,
1291         .llseek  = seq_lseek,
1292         .release = seq_release,
1293 };
1294
1295 /* Display various sensor information.
1296  */
1297 static int sensors_show(struct seq_file *seq, void *v)
1298 {
1299         struct adapter *adap = seq->private;
1300         u32 param[7], val[7];
1301         int ret;
1302
1303         /* Note that if the sensors haven't been initialized and turned on
1304          * we'll get values of 0, so treat those as "<unknown>" ...
1305          */
1306         param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1307                     FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1308                     FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
1309         param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
1310                     FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
1311                     FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1312         ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
1313                               param, val);
1314
1315         if (ret < 0 || val[0] == 0)
1316                 seq_puts(seq, "Temperature: <unknown>\n");
1317         else
1318                 seq_printf(seq, "Temperature: %dC\n", val[0]);
1319
1320         if (ret < 0 || val[1] == 0)
1321                 seq_puts(seq, "Core VDD:    <unknown>\n");
1322         else
1323                 seq_printf(seq, "Core VDD:    %dmV\n", val[1]);
1324
1325         return 0;
1326 }
1327
1328 DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
1329
1330 #if IS_ENABLED(CONFIG_IPV6)
1331 static int clip_tbl_open(struct inode *inode, struct file *file)
1332 {
1333         return single_open(file, clip_tbl_show, inode->i_private);
1334 }
1335
1336 static const struct file_operations clip_tbl_debugfs_fops = {
1337         .owner   = THIS_MODULE,
1338         .open    = clip_tbl_open,
1339         .read    = seq_read,
1340         .llseek  = seq_lseek,
1341         .release = single_release
1342 };
1343 #endif
1344
1345 /*RSS Table.
1346  */
1347
1348 static int rss_show(struct seq_file *seq, void *v, int idx)
1349 {
1350         u16 *entry = v;
1351
1352         seq_printf(seq, "%4d:  %4u  %4u  %4u  %4u  %4u  %4u  %4u  %4u\n",
1353                    idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
1354                    entry[5], entry[6], entry[7]);
1355         return 0;
1356 }
1357
1358 static int rss_open(struct inode *inode, struct file *file)
1359 {
1360         int ret;
1361         struct seq_tab *p;
1362         struct adapter *adap = inode->i_private;
1363
1364         p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
1365         if (!p)
1366                 return -ENOMEM;
1367
1368         ret = t4_read_rss(adap, (u16 *)p->data);
1369         if (ret)
1370                 seq_release_private(inode, file);
1371
1372         return ret;
1373 }
1374
1375 static const struct file_operations rss_debugfs_fops = {
1376         .owner   = THIS_MODULE,
1377         .open    = rss_open,
1378         .read    = seq_read,
1379         .llseek  = seq_lseek,
1380         .release = seq_release_private
1381 };
1382
1383 /* RSS Configuration.
1384  */
1385
1386 /* Small utility function to return the strings "yes" or "no" if the supplied
1387  * argument is non-zero.
1388  */
1389 static const char *yesno(int x)
1390 {
1391         static const char *yes = "yes";
1392         static const char *no = "no";
1393
1394         return x ? yes : no;
1395 }
1396
1397 static int rss_config_show(struct seq_file *seq, void *v)
1398 {
1399         struct adapter *adapter = seq->private;
1400         static const char * const keymode[] = {
1401                 "global",
1402                 "global and per-VF scramble",
1403                 "per-PF and per-VF scramble",
1404                 "per-VF and per-VF scramble",
1405         };
1406         u32 rssconf;
1407
1408         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
1409         seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
1410         seq_printf(seq, "  Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
1411                                                         TNL4TUPENIPV6_F));
1412         seq_printf(seq, "  Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
1413                                                         TNL2TUPENIPV6_F));
1414         seq_printf(seq, "  Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
1415                                                         TNL4TUPENIPV4_F));
1416         seq_printf(seq, "  Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
1417                                                         TNL2TUPENIPV4_F));
1418         seq_printf(seq, "  TnlTcpSel:     %3s\n", yesno(rssconf & TNLTCPSEL_F));
1419         seq_printf(seq, "  TnlIp6Sel:     %3s\n", yesno(rssconf & TNLIP6SEL_F));
1420         seq_printf(seq, "  TnlVrtSel:     %3s\n", yesno(rssconf & TNLVRTSEL_F));
1421         seq_printf(seq, "  TnlMapEn:      %3s\n", yesno(rssconf & TNLMAPEN_F));
1422         seq_printf(seq, "  OfdHashSave:   %3s\n", yesno(rssconf &
1423                                                         OFDHASHSAVE_F));
1424         seq_printf(seq, "  OfdVrtSel:     %3s\n", yesno(rssconf & OFDVRTSEL_F));
1425         seq_printf(seq, "  OfdMapEn:      %3s\n", yesno(rssconf & OFDMAPEN_F));
1426         seq_printf(seq, "  OfdLkpEn:      %3s\n", yesno(rssconf & OFDLKPEN_F));
1427         seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1428                                                         SYN4TUPENIPV6_F));
1429         seq_printf(seq, "  Syn2TupEnIpv6: %3s\n", yesno(rssconf &
1430                                                         SYN2TUPENIPV6_F));
1431         seq_printf(seq, "  Syn4TupEnIpv4: %3s\n", yesno(rssconf &
1432                                                         SYN4TUPENIPV4_F));
1433         seq_printf(seq, "  Syn2TupEnIpv4: %3s\n", yesno(rssconf &
1434                                                         SYN2TUPENIPV4_F));
1435         seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1436                                                         SYN4TUPENIPV6_F));
1437         seq_printf(seq, "  SynIp6Sel:     %3s\n", yesno(rssconf & SYNIP6SEL_F));
1438         seq_printf(seq, "  SynVrt6Sel:    %3s\n", yesno(rssconf & SYNVRTSEL_F));
1439         seq_printf(seq, "  SynMapEn:      %3s\n", yesno(rssconf & SYNMAPEN_F));
1440         seq_printf(seq, "  SynLkpEn:      %3s\n", yesno(rssconf & SYNLKPEN_F));
1441         seq_printf(seq, "  ChnEn:         %3s\n", yesno(rssconf &
1442                                                         CHANNELENABLE_F));
1443         seq_printf(seq, "  PrtEn:         %3s\n", yesno(rssconf &
1444                                                         PORTENABLE_F));
1445         seq_printf(seq, "  TnlAllLkp:     %3s\n", yesno(rssconf &
1446                                                         TNLALLLOOKUP_F));
1447         seq_printf(seq, "  VrtEn:         %3s\n", yesno(rssconf &
1448                                                         VIRTENABLE_F));
1449         seq_printf(seq, "  CngEn:         %3s\n", yesno(rssconf &
1450                                                         CONGESTIONENABLE_F));
1451         seq_printf(seq, "  HashToeplitz:  %3s\n", yesno(rssconf &
1452                                                         HASHTOEPLITZ_F));
1453         seq_printf(seq, "  Udp4En:        %3s\n", yesno(rssconf & UDPENABLE_F));
1454         seq_printf(seq, "  Disable:       %3s\n", yesno(rssconf & DISABLE_F));
1455
1456         seq_puts(seq, "\n");
1457
1458         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
1459         seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
1460         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
1461         seq_printf(seq, "  MaskFilter:    %3d\n", MASKFILTER_G(rssconf));
1462         if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
1463                 seq_printf(seq, "  HashAll:     %3s\n",
1464                            yesno(rssconf & HASHALL_F));
1465                 seq_printf(seq, "  HashEth:     %3s\n",
1466                            yesno(rssconf & HASHETH_F));
1467         }
1468         seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
1469
1470         seq_puts(seq, "\n");
1471
1472         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
1473         seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
1474         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
1475         seq_printf(seq, "  RRCplMapEn:    %3s\n", yesno(rssconf &
1476                                                         RRCPLMAPEN_F));
1477         seq_printf(seq, "  RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
1478
1479         seq_puts(seq, "\n");
1480
1481         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
1482         seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
1483         seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
1484         seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
1485
1486         seq_puts(seq, "\n");
1487
1488         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
1489         seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
1490         if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
1491                 seq_printf(seq, "  KeyWrAddrX:     %3d\n",
1492                            KEYWRADDRX_G(rssconf));
1493                 seq_printf(seq, "  KeyExtend:      %3s\n",
1494                            yesno(rssconf & KEYEXTEND_F));
1495         }
1496         seq_printf(seq, "  VfRdRg:        %3s\n", yesno(rssconf & VFRDRG_F));
1497         seq_printf(seq, "  VfRdEn:        %3s\n", yesno(rssconf & VFRDEN_F));
1498         seq_printf(seq, "  VfPerrEn:      %3s\n", yesno(rssconf & VFPERREN_F));
1499         seq_printf(seq, "  KeyPerrEn:     %3s\n", yesno(rssconf & KEYPERREN_F));
1500         seq_printf(seq, "  DisVfVlan:     %3s\n", yesno(rssconf &
1501                                                         DISABLEVLAN_F));
1502         seq_printf(seq, "  EnUpSwt:       %3s\n", yesno(rssconf & ENABLEUP0_F));
1503         seq_printf(seq, "  HashDelay:     %3d\n", HASHDELAY_G(rssconf));
1504         if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
1505                 seq_printf(seq, "  VfWrAddr:      %3d\n", VFWRADDR_G(rssconf));
1506         else
1507                 seq_printf(seq, "  VfWrAddr:      %3d\n",
1508                            T6_VFWRADDR_G(rssconf));
1509         seq_printf(seq, "  KeyMode:       %s\n", keymode[KEYMODE_G(rssconf)]);
1510         seq_printf(seq, "  VfWrEn:        %3s\n", yesno(rssconf & VFWREN_F));
1511         seq_printf(seq, "  KeyWrEn:       %3s\n", yesno(rssconf & KEYWREN_F));
1512         seq_printf(seq, "  KeyWrAddr:     %3d\n", KEYWRADDR_G(rssconf));
1513
1514         seq_puts(seq, "\n");
1515
1516         rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
1517         seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
1518         seq_printf(seq, "  ChnCount3:     %3s\n", yesno(rssconf & CHNCOUNT3_F));
1519         seq_printf(seq, "  ChnCount2:     %3s\n", yesno(rssconf & CHNCOUNT2_F));
1520         seq_printf(seq, "  ChnCount1:     %3s\n", yesno(rssconf & CHNCOUNT1_F));
1521         seq_printf(seq, "  ChnCount0:     %3s\n", yesno(rssconf & CHNCOUNT0_F));
1522         seq_printf(seq, "  ChnUndFlow3:   %3s\n", yesno(rssconf &
1523                                                         CHNUNDFLOW3_F));
1524         seq_printf(seq, "  ChnUndFlow2:   %3s\n", yesno(rssconf &
1525                                                         CHNUNDFLOW2_F));
1526         seq_printf(seq, "  ChnUndFlow1:   %3s\n", yesno(rssconf &
1527                                                         CHNUNDFLOW1_F));
1528         seq_printf(seq, "  ChnUndFlow0:   %3s\n", yesno(rssconf &
1529                                                         CHNUNDFLOW0_F));
1530         seq_printf(seq, "  RstChn3:       %3s\n", yesno(rssconf & RSTCHN3_F));
1531         seq_printf(seq, "  RstChn2:       %3s\n", yesno(rssconf & RSTCHN2_F));
1532         seq_printf(seq, "  RstChn1:       %3s\n", yesno(rssconf & RSTCHN1_F));
1533         seq_printf(seq, "  RstChn0:       %3s\n", yesno(rssconf & RSTCHN0_F));
1534         seq_printf(seq, "  UpdVld:        %3s\n", yesno(rssconf & UPDVLD_F));
1535         seq_printf(seq, "  Xoff:          %3s\n", yesno(rssconf & XOFF_F));
1536         seq_printf(seq, "  UpdChn3:       %3s\n", yesno(rssconf & UPDCHN3_F));
1537         seq_printf(seq, "  UpdChn2:       %3s\n", yesno(rssconf & UPDCHN2_F));
1538         seq_printf(seq, "  UpdChn1:       %3s\n", yesno(rssconf & UPDCHN1_F));
1539         seq_printf(seq, "  UpdChn0:       %3s\n", yesno(rssconf & UPDCHN0_F));
1540         seq_printf(seq, "  Queue:         %3d\n", QUEUE_G(rssconf));
1541
1542         return 0;
1543 }
1544
1545 DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
1546
1547 /* RSS Secret Key.
1548  */
1549
1550 static int rss_key_show(struct seq_file *seq, void *v)
1551 {
1552         u32 key[10];
1553
1554         t4_read_rss_key(seq->private, key);
1555         seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1556                    key[9], key[8], key[7], key[6], key[5], key[4], key[3],
1557                    key[2], key[1], key[0]);
1558         return 0;
1559 }
1560
1561 static int rss_key_open(struct inode *inode, struct file *file)
1562 {
1563         return single_open(file, rss_key_show, inode->i_private);
1564 }
1565
1566 static ssize_t rss_key_write(struct file *file, const char __user *buf,
1567                              size_t count, loff_t *pos)
1568 {
1569         int i, j;
1570         u32 key[10];
1571         char s[100], *p;
1572         struct adapter *adap = file_inode(file)->i_private;
1573
1574         if (count > sizeof(s) - 1)
1575                 return -EINVAL;
1576         if (copy_from_user(s, buf, count))
1577                 return -EFAULT;
1578         for (i = count; i > 0 && isspace(s[i - 1]); i--)
1579                 ;
1580         s[i] = '\0';
1581
1582         for (p = s, i = 9; i >= 0; i--) {
1583                 key[i] = 0;
1584                 for (j = 0; j < 8; j++, p++) {
1585                         if (!isxdigit(*p))
1586                                 return -EINVAL;
1587                         key[i] = (key[i] << 4) | hex2val(*p);
1588                 }
1589         }
1590
1591         t4_write_rss_key(adap, key, -1);
1592         return count;
1593 }
1594
1595 static const struct file_operations rss_key_debugfs_fops = {
1596         .owner   = THIS_MODULE,
1597         .open    = rss_key_open,
1598         .read    = seq_read,
1599         .llseek  = seq_lseek,
1600         .release = single_release,
1601         .write   = rss_key_write
1602 };
1603
1604 /* PF RSS Configuration.
1605  */
1606
1607 struct rss_pf_conf {
1608         u32 rss_pf_map;
1609         u32 rss_pf_mask;
1610         u32 rss_pf_config;
1611 };
1612
1613 static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
1614 {
1615         struct rss_pf_conf *pfconf;
1616
1617         if (v == SEQ_START_TOKEN) {
1618                 /* use the 0th entry to dump the PF Map Index Size */
1619                 pfconf = seq->private + offsetof(struct seq_tab, data);
1620                 seq_printf(seq, "PF Map Index Size = %d\n\n",
1621                            LKPIDXSIZE_G(pfconf->rss_pf_map));
1622
1623                 seq_puts(seq, "     RSS              PF   VF    Hash Tuple Enable         Default\n");
1624                 seq_puts(seq, "     Enable       IPF Mask Mask  IPv6      IPv4      UDP   Queue\n");
1625                 seq_puts(seq, " PF  Map Chn Prt  Map Size Size  Four Two  Four Two  Four  Ch1  Ch0\n");
1626         } else {
1627                 #define G_PFnLKPIDX(map, n) \
1628                         (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
1629                 #define G_PFnMSKSIZE(mask, n) \
1630                         (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
1631
1632                 pfconf = v;
1633                 seq_printf(seq, "%3d  %3s %3s %3s  %3d  %3d  %3d   %3s %3s   %3s %3s   %3s  %3d  %3d\n",
1634                            idx,
1635                            yesno(pfconf->rss_pf_config & MAPENABLE_F),
1636                            yesno(pfconf->rss_pf_config & CHNENABLE_F),
1637                            yesno(pfconf->rss_pf_config & PRTENABLE_F),
1638                            G_PFnLKPIDX(pfconf->rss_pf_map, idx),
1639                            G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
1640                            IVFWIDTH_G(pfconf->rss_pf_config),
1641                            yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
1642                            yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
1643                            yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
1644                            yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
1645                            yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
1646                            CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
1647                            CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
1648
1649                 #undef G_PFnLKPIDX
1650                 #undef G_PFnMSKSIZE
1651         }
1652         return 0;
1653 }
1654
1655 static int rss_pf_config_open(struct inode *inode, struct file *file)
1656 {
1657         struct adapter *adapter = inode->i_private;
1658         struct seq_tab *p;
1659         u32 rss_pf_map, rss_pf_mask;
1660         struct rss_pf_conf *pfconf;
1661         int pf;
1662
1663         p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
1664         if (!p)
1665                 return -ENOMEM;
1666
1667         pfconf = (struct rss_pf_conf *)p->data;
1668         rss_pf_map = t4_read_rss_pf_map(adapter);
1669         rss_pf_mask = t4_read_rss_pf_mask(adapter);
1670         for (pf = 0; pf < 8; pf++) {
1671                 pfconf[pf].rss_pf_map = rss_pf_map;
1672                 pfconf[pf].rss_pf_mask = rss_pf_mask;
1673                 t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
1674         }
1675         return 0;
1676 }
1677
1678 static const struct file_operations rss_pf_config_debugfs_fops = {
1679         .owner   = THIS_MODULE,
1680         .open    = rss_pf_config_open,
1681         .read    = seq_read,
1682         .llseek  = seq_lseek,
1683         .release = seq_release_private
1684 };
1685
1686 /* VF RSS Configuration.
1687  */
1688
1689 struct rss_vf_conf {
1690         u32 rss_vf_vfl;
1691         u32 rss_vf_vfh;
1692 };
1693
1694 static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
1695 {
1696         if (v == SEQ_START_TOKEN) {
1697                 seq_puts(seq, "     RSS                     Hash Tuple Enable\n");
1698                 seq_puts(seq, "     Enable   IVF  Dis  Enb  IPv6      IPv4      UDP    Def  Secret Key\n");
1699                 seq_puts(seq, " VF  Chn Prt  Map  VLAN  uP  Four Two  Four Two  Four   Que  Idx       Hash\n");
1700         } else {
1701                 struct rss_vf_conf *vfconf = v;
1702
1703                 seq_printf(seq, "%3d  %3s %3s  %3d   %3s %3s   %3s %3s   %3s  %3s   %3s  %4d  %3d %#10x\n",
1704                            idx,
1705                            yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
1706                            yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
1707                            VFLKPIDX_G(vfconf->rss_vf_vfh),
1708                            yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
1709                            yesno(vfconf->rss_vf_vfh & VFUPEN_F),
1710                            yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1711                            yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
1712                            yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
1713                            yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
1714                            yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
1715                            DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
1716                            KEYINDEX_G(vfconf->rss_vf_vfh),
1717                            vfconf->rss_vf_vfl);
1718         }
1719         return 0;
1720 }
1721
1722 static int rss_vf_config_open(struct inode *inode, struct file *file)
1723 {
1724         struct adapter *adapter = inode->i_private;
1725         struct seq_tab *p;
1726         struct rss_vf_conf *vfconf;
1727         int vf, vfcount = adapter->params.arch.vfcount;
1728
1729         p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
1730         if (!p)
1731                 return -ENOMEM;
1732
1733         vfconf = (struct rss_vf_conf *)p->data;
1734         for (vf = 0; vf < vfcount; vf++) {
1735                 t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
1736                                       &vfconf[vf].rss_vf_vfh);
1737         }
1738         return 0;
1739 }
1740
1741 static const struct file_operations rss_vf_config_debugfs_fops = {
1742         .owner   = THIS_MODULE,
1743         .open    = rss_vf_config_open,
1744         .read    = seq_read,
1745         .llseek  = seq_lseek,
1746         .release = seq_release_private
1747 };
1748
1749 /**
1750  * ethqset2pinfo - return port_info of an Ethernet Queue Set
1751  * @adap: the adapter
1752  * @qset: Ethernet Queue Set
1753  */
1754 static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
1755 {
1756         int pidx;
1757
1758         for_each_port(adap, pidx) {
1759                 struct port_info *pi = adap2pinfo(adap, pidx);
1760
1761                 if (qset >= pi->first_qset &&
1762                     qset < pi->first_qset + pi->nqsets)
1763                         return pi;
1764         }
1765
1766         /* should never happen! */
1767         BUG_ON(1);
1768         return NULL;
1769 }
1770
1771 static int sge_qinfo_show(struct seq_file *seq, void *v)
1772 {
1773         struct adapter *adap = seq->private;
1774         int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
1775         int toe_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
1776         int rdma_entries = DIV_ROUND_UP(adap->sge.rdmaqs, 4);
1777         int ciq_entries = DIV_ROUND_UP(adap->sge.rdmaciqs, 4);
1778         int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
1779         int i, r = (uintptr_t)v - 1;
1780         int toe_idx = r - eth_entries;
1781         int rdma_idx = toe_idx - toe_entries;
1782         int ciq_idx = rdma_idx - rdma_entries;
1783         int ctrl_idx =  ciq_idx - ciq_entries;
1784         int fq_idx =  ctrl_idx - ctrl_entries;
1785
1786         if (r)
1787                 seq_putc(seq, '\n');
1788
1789 #define S3(fmt_spec, s, v) \
1790 do { \
1791         seq_printf(seq, "%-12s", s); \
1792         for (i = 0; i < n; ++i) \
1793                 seq_printf(seq, " %16" fmt_spec, v); \
1794                 seq_putc(seq, '\n'); \
1795 } while (0)
1796 #define S(s, v) S3("s", s, v)
1797 #define T(s, v) S3("u", s, tx[i].v)
1798 #define R(s, v) S3("u", s, rx[i].v)
1799
1800         if (r < eth_entries) {
1801                 int base_qset = r * 4;
1802                 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
1803                 const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
1804                 int n = min(4, adap->sge.ethqsets - 4 * r);
1805
1806                 S("QType:", "Ethernet");
1807                 S("Interface:",
1808                   rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1809                 T("TxQ ID:", q.cntxt_id);
1810                 T("TxQ size:", q.size);
1811                 T("TxQ inuse:", q.in_use);
1812                 T("TxQ CIDX:", q.cidx);
1813                 T("TxQ PIDX:", q.pidx);
1814 #ifdef CONFIG_CHELSIO_T4_DCB
1815                 T("DCB Prio:", dcb_prio);
1816                 S3("u", "DCB PGID:",
1817                    (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
1818                     4*(7-tx[i].dcb_prio)) & 0xf);
1819                 S3("u", "DCB PFC:",
1820                    (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
1821                     1*(7-tx[i].dcb_prio)) & 0x1);
1822 #endif
1823                 R("RspQ ID:", rspq.abs_id);
1824                 R("RspQ size:", rspq.size);
1825                 R("RspQE size:", rspq.iqe_len);
1826                 R("RspQ CIDX:", rspq.cidx);
1827                 R("RspQ Gen:", rspq.gen);
1828                 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1829                 S3("u", "Intr pktcnt:",
1830                    adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1831                 R("FL ID:", fl.cntxt_id);
1832                 R("FL size:", fl.size - 8);
1833                 R("FL pend:", fl.pend_cred);
1834                 R("FL avail:", fl.avail);
1835                 R("FL PIDX:", fl.pidx);
1836                 R("FL CIDX:", fl.cidx);
1837         } else if (toe_idx < toe_entries) {
1838                 const struct sge_ofld_rxq *rx = &adap->sge.ofldrxq[toe_idx * 4];
1839                 const struct sge_ofld_txq *tx = &adap->sge.ofldtxq[toe_idx * 4];
1840                 int n = min(4, adap->sge.ofldqsets - 4 * toe_idx);
1841
1842                 S("QType:", "TOE");
1843                 T("TxQ ID:", q.cntxt_id);
1844                 T("TxQ size:", q.size);
1845                 T("TxQ inuse:", q.in_use);
1846                 T("TxQ CIDX:", q.cidx);
1847                 T("TxQ PIDX:", q.pidx);
1848                 R("RspQ ID:", rspq.abs_id);
1849                 R("RspQ size:", rspq.size);
1850                 R("RspQE size:", rspq.iqe_len);
1851                 R("RspQ CIDX:", rspq.cidx);
1852                 R("RspQ Gen:", rspq.gen);
1853                 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1854                 S3("u", "Intr pktcnt:",
1855                    adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1856                 R("FL ID:", fl.cntxt_id);
1857                 R("FL size:", fl.size - 8);
1858                 R("FL pend:", fl.pend_cred);
1859                 R("FL avail:", fl.avail);
1860                 R("FL PIDX:", fl.pidx);
1861                 R("FL CIDX:", fl.cidx);
1862         } else if (rdma_idx < rdma_entries) {
1863                 const struct sge_ofld_rxq *rx =
1864                                 &adap->sge.rdmarxq[rdma_idx * 4];
1865                 int n = min(4, adap->sge.rdmaqs - 4 * rdma_idx);
1866
1867                 S("QType:", "RDMA-CPL");
1868                 S("Interface:",
1869                   rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1870                 R("RspQ ID:", rspq.abs_id);
1871                 R("RspQ size:", rspq.size);
1872                 R("RspQE size:", rspq.iqe_len);
1873                 R("RspQ CIDX:", rspq.cidx);
1874                 R("RspQ Gen:", rspq.gen);
1875                 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1876                 S3("u", "Intr pktcnt:",
1877                    adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1878                 R("FL ID:", fl.cntxt_id);
1879                 R("FL size:", fl.size - 8);
1880                 R("FL pend:", fl.pend_cred);
1881                 R("FL avail:", fl.avail);
1882                 R("FL PIDX:", fl.pidx);
1883                 R("FL CIDX:", fl.cidx);
1884         } else if (ciq_idx < ciq_entries) {
1885                 const struct sge_ofld_rxq *rx = &adap->sge.rdmaciq[ciq_idx * 4];
1886                 int n = min(4, adap->sge.rdmaciqs - 4 * ciq_idx);
1887
1888                 S("QType:", "RDMA-CIQ");
1889                 S("Interface:",
1890                   rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
1891                 R("RspQ ID:", rspq.abs_id);
1892                 R("RspQ size:", rspq.size);
1893                 R("RspQE size:", rspq.iqe_len);
1894                 R("RspQ CIDX:", rspq.cidx);
1895                 R("RspQ Gen:", rspq.gen);
1896                 S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
1897                 S3("u", "Intr pktcnt:",
1898                    adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
1899         } else if (ctrl_idx < ctrl_entries) {
1900                 const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
1901                 int n = min(4, adap->params.nports - 4 * ctrl_idx);
1902
1903                 S("QType:", "Control");
1904                 T("TxQ ID:", q.cntxt_id);
1905                 T("TxQ size:", q.size);
1906                 T("TxQ inuse:", q.in_use);
1907                 T("TxQ CIDX:", q.cidx);
1908                 T("TxQ PIDX:", q.pidx);
1909         } else if (fq_idx == 0) {
1910                 const struct sge_rspq *evtq = &adap->sge.fw_evtq;
1911
1912                 seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
1913                 seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
1914                 seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
1915                 seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
1916                 seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
1917                 seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
1918                 seq_printf(seq, "%-12s %16u\n", "Intr delay:",
1919                            qtimer_val(adap, evtq));
1920                 seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
1921                            adap->sge.counter_val[evtq->pktcnt_idx]);
1922         }
1923 #undef R
1924 #undef T
1925 #undef S
1926 #undef S3
1927 return 0;
1928 }
1929
1930 static int sge_queue_entries(const struct adapter *adap)
1931 {
1932         return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
1933                DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
1934                DIV_ROUND_UP(adap->sge.rdmaqs, 4) +
1935                DIV_ROUND_UP(adap->sge.rdmaciqs, 4) +
1936                DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
1937 }
1938
1939 static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
1940 {
1941         int entries = sge_queue_entries(seq->private);
1942
1943         return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1944 }
1945
1946 static void sge_queue_stop(struct seq_file *seq, void *v)
1947 {
1948 }
1949
1950 static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
1951 {
1952         int entries = sge_queue_entries(seq->private);
1953
1954         ++*pos;
1955         return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
1956 }
1957
1958 static const struct seq_operations sge_qinfo_seq_ops = {
1959         .start = sge_queue_start,
1960         .next  = sge_queue_next,
1961         .stop  = sge_queue_stop,
1962         .show  = sge_qinfo_show
1963 };
1964
1965 static int sge_qinfo_open(struct inode *inode, struct file *file)
1966 {
1967         int res = seq_open(file, &sge_qinfo_seq_ops);
1968
1969         if (!res) {
1970                 struct seq_file *seq = file->private_data;
1971
1972                 seq->private = inode->i_private;
1973         }
1974         return res;
1975 }
1976
1977 static const struct file_operations sge_qinfo_debugfs_fops = {
1978         .owner   = THIS_MODULE,
1979         .open    = sge_qinfo_open,
1980         .read    = seq_read,
1981         .llseek  = seq_lseek,
1982         .release = seq_release,
1983 };
1984
1985 int mem_open(struct inode *inode, struct file *file)
1986 {
1987         unsigned int mem;
1988         struct adapter *adap;
1989
1990         file->private_data = inode->i_private;
1991
1992         mem = (uintptr_t)file->private_data & 0x3;
1993         adap = file->private_data - mem;
1994
1995         (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
1996
1997         return 0;
1998 }
1999
2000 static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2001                         loff_t *ppos)
2002 {
2003         loff_t pos = *ppos;
2004         loff_t avail = file_inode(file)->i_size;
2005         unsigned int mem = (uintptr_t)file->private_data & 3;
2006         struct adapter *adap = file->private_data - mem;
2007         __be32 *data;
2008         int ret;
2009
2010         if (pos < 0)
2011                 return -EINVAL;
2012         if (pos >= avail)
2013                 return 0;
2014         if (count > avail - pos)
2015                 count = avail - pos;
2016
2017         data = t4_alloc_mem(count);
2018         if (!data)
2019                 return -ENOMEM;
2020
2021         spin_lock(&adap->win0_lock);
2022         ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
2023         spin_unlock(&adap->win0_lock);
2024         if (ret) {
2025                 t4_free_mem(data);
2026                 return ret;
2027         }
2028         ret = copy_to_user(buf, data, count);
2029
2030         t4_free_mem(data);
2031         if (ret)
2032                 return -EFAULT;
2033
2034         *ppos = pos + count;
2035         return count;
2036 }
2037 static const struct file_operations mem_debugfs_fops = {
2038         .owner   = THIS_MODULE,
2039         .open    = simple_open,
2040         .read    = mem_read,
2041         .llseek  = default_llseek,
2042 };
2043
2044 static void add_debugfs_mem(struct adapter *adap, const char *name,
2045                             unsigned int idx, unsigned int size_mb)
2046 {
2047         debugfs_create_file_size(name, S_IRUSR, adap->debugfs_root,
2048                                  (void *)adap + idx, &mem_debugfs_fops,
2049                                  size_mb << 20);
2050 }
2051
2052 static int blocked_fl_open(struct inode *inode, struct file *file)
2053 {
2054         file->private_data = inode->i_private;
2055         return 0;
2056 }
2057
2058 static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
2059                                size_t count, loff_t *ppos)
2060 {
2061         int len;
2062         const struct adapter *adap = filp->private_data;
2063         char *buf;
2064         ssize_t size = (adap->sge.egr_sz + 3) / 4 +
2065                         adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
2066
2067         buf = kzalloc(size, GFP_KERNEL);
2068         if (!buf)
2069                 return -ENOMEM;
2070
2071         len = snprintf(buf, size - 1, "%*pb\n",
2072                        adap->sge.egr_sz, adap->sge.blocked_fl);
2073         len += sprintf(buf + len, "\n");
2074         size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
2075         t4_free_mem(buf);
2076         return size;
2077 }
2078
2079 static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
2080                                 size_t count, loff_t *ppos)
2081 {
2082         int err;
2083         unsigned long *t;
2084         struct adapter *adap = filp->private_data;
2085
2086         t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
2087         if (!t)
2088                 return -ENOMEM;
2089
2090         err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
2091         if (err)
2092                 return err;
2093
2094         bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
2095         t4_free_mem(t);
2096         return count;
2097 }
2098
2099 static const struct file_operations blocked_fl_fops = {
2100         .owner   = THIS_MODULE,
2101         .open    = blocked_fl_open,
2102         .read    = blocked_fl_read,
2103         .write   = blocked_fl_write,
2104         .llseek  = generic_file_llseek,
2105 };
2106
2107 /* Add an array of Debug FS files.
2108  */
2109 void add_debugfs_files(struct adapter *adap,
2110                        struct t4_debugfs_entry *files,
2111                        unsigned int nfiles)
2112 {
2113         int i;
2114
2115         /* debugfs support is best effort */
2116         for (i = 0; i < nfiles; i++)
2117                 debugfs_create_file(files[i].name, files[i].mode,
2118                                     adap->debugfs_root,
2119                                     (void *)adap + files[i].data,
2120                                     files[i].ops);
2121 }
2122
2123 int t4_setup_debugfs(struct adapter *adap)
2124 {
2125         int i;
2126         u32 size = 0;
2127         struct dentry *de;
2128
2129         static struct t4_debugfs_entry t4_debugfs_files[] = {
2130                 { "cim_la", &cim_la_fops, S_IRUSR, 0 },
2131                 { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
2132                 { "clk", &clk_debugfs_fops, S_IRUSR, 0 },
2133                 { "devlog", &devlog_fops, S_IRUSR, 0 },
2134                 { "mbox0", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
2135                 { "mbox1", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
2136                 { "mbox2", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
2137                 { "mbox3", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
2138                 { "mbox4", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 4 },
2139                 { "mbox5", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 5 },
2140                 { "mbox6", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 6 },
2141                 { "mbox7", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 7 },
2142                 { "l2t", &t4_l2t_fops, S_IRUSR, 0},
2143                 { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
2144                 { "rss", &rss_debugfs_fops, S_IRUSR, 0 },
2145                 { "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
2146                 { "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
2147                 { "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
2148                 { "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
2149                 { "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
2150                 { "ibq_tp0",  &cim_ibq_fops, S_IRUSR, 0 },
2151                 { "ibq_tp1",  &cim_ibq_fops, S_IRUSR, 1 },
2152                 { "ibq_ulp",  &cim_ibq_fops, S_IRUSR, 2 },
2153                 { "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
2154                 { "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
2155                 { "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
2156                 { "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
2157                 { "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
2158                 { "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
2159                 { "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
2160                 { "obq_sge",  &cim_obq_fops, S_IRUSR, 4 },
2161                 { "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
2162                 { "tp_la", &tp_la_fops, S_IRUSR, 0 },
2163                 { "ulprx_la", &ulprx_la_fops, S_IRUSR, 0 },
2164                 { "sensors", &sensors_debugfs_fops, S_IRUSR, 0 },
2165                 { "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
2166                 { "cctrl", &cctrl_tbl_debugfs_fops, S_IRUSR, 0 },
2167 #if IS_ENABLED(CONFIG_IPV6)
2168                 { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
2169 #endif
2170                 { "blocked_fl", &blocked_fl_fops, S_IRUSR | S_IWUSR, 0 },
2171         };
2172
2173         /* Debug FS nodes common to all T5 and later adapters.
2174          */
2175         static struct t4_debugfs_entry t5_debugfs_files[] = {
2176                 { "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
2177                 { "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
2178         };
2179
2180         add_debugfs_files(adap,
2181                           t4_debugfs_files,
2182                           ARRAY_SIZE(t4_debugfs_files));
2183         if (!is_t4(adap->params.chip))
2184                 add_debugfs_files(adap,
2185                                   t5_debugfs_files,
2186                                   ARRAY_SIZE(t5_debugfs_files));
2187
2188         i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
2189         if (i & EDRAM0_ENABLE_F) {
2190                 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
2191                 add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
2192         }
2193         if (i & EDRAM1_ENABLE_F) {
2194                 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
2195                 add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
2196         }
2197         if (is_t5(adap->params.chip)) {
2198                 if (i & EXT_MEM0_ENABLE_F) {
2199                         size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
2200                         add_debugfs_mem(adap, "mc0", MEM_MC0,
2201                                         EXT_MEM0_SIZE_G(size));
2202                 }
2203                 if (i & EXT_MEM1_ENABLE_F) {
2204                         size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
2205                         add_debugfs_mem(adap, "mc1", MEM_MC1,
2206                                         EXT_MEM1_SIZE_G(size));
2207                 }
2208         } else {
2209                 if (i & EXT_MEM_ENABLE_F)
2210                         size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
2211                         add_debugfs_mem(adap, "mc", MEM_MC,
2212                                         EXT_MEM_SIZE_G(size));
2213         }
2214
2215         de = debugfs_create_file_size("flash", S_IRUSR, adap->debugfs_root, adap,
2216                                       &flash_debugfs_fops, adap->params.sf_size);
2217
2218         return 0;
2219 }