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