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