1fd88b31aSHariprasad Shenai /*
2fd88b31aSHariprasad Shenai  * This file is part of the Chelsio T4 Ethernet driver for Linux.
3fd88b31aSHariprasad Shenai  *
4fd88b31aSHariprasad Shenai  * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
5fd88b31aSHariprasad Shenai  *
6fd88b31aSHariprasad Shenai  * This software is available to you under a choice of one of two
7fd88b31aSHariprasad Shenai  * licenses.  You may choose to be licensed under the terms of the GNU
8fd88b31aSHariprasad Shenai  * General Public License (GPL) Version 2, available from the file
9fd88b31aSHariprasad Shenai  * COPYING in the main directory of this source tree, or the
10fd88b31aSHariprasad Shenai  * OpenIB.org BSD license below:
11fd88b31aSHariprasad Shenai  *
12fd88b31aSHariprasad Shenai  *     Redistribution and use in source and binary forms, with or
13fd88b31aSHariprasad Shenai  *     without modification, are permitted provided that the following
14fd88b31aSHariprasad Shenai  *     conditions are met:
15fd88b31aSHariprasad Shenai  *
16fd88b31aSHariprasad Shenai  *      - Redistributions of source code must retain the above
17fd88b31aSHariprasad Shenai  *        copyright notice, this list of conditions and the following
18fd88b31aSHariprasad Shenai  *        disclaimer.
19fd88b31aSHariprasad Shenai  *
20fd88b31aSHariprasad Shenai  *      - Redistributions in binary form must reproduce the above
21fd88b31aSHariprasad Shenai  *        copyright notice, this list of conditions and the following
22fd88b31aSHariprasad Shenai  *        disclaimer in the documentation and/or other materials
23fd88b31aSHariprasad Shenai  *        provided with the distribution.
24fd88b31aSHariprasad Shenai  *
25fd88b31aSHariprasad Shenai  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26fd88b31aSHariprasad Shenai  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27fd88b31aSHariprasad Shenai  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28fd88b31aSHariprasad Shenai  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29fd88b31aSHariprasad Shenai  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30fd88b31aSHariprasad Shenai  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31fd88b31aSHariprasad Shenai  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32fd88b31aSHariprasad Shenai  * SOFTWARE.
33fd88b31aSHariprasad Shenai  */
34fd88b31aSHariprasad Shenai 
35fd88b31aSHariprasad Shenai #include <linux/seq_file.h>
36fd88b31aSHariprasad Shenai #include <linux/debugfs.h>
37fd88b31aSHariprasad Shenai #include <linux/string_helpers.h>
38fd88b31aSHariprasad Shenai #include <linux/sort.h>
39688ea5feSHariprasad Shenai #include <linux/ctype.h>
40fd88b31aSHariprasad Shenai 
41fd88b31aSHariprasad Shenai #include "cxgb4.h"
42fd88b31aSHariprasad Shenai #include "t4_regs.h"
43bf7c781dSHariprasad Shenai #include "t4_values.h"
44fd88b31aSHariprasad Shenai #include "t4fw_api.h"
45fd88b31aSHariprasad Shenai #include "cxgb4_debugfs.h"
46b5a02f50SAnish Bhatt #include "clip_tbl.h"
47fd88b31aSHariprasad Shenai #include "l2t.h"
48123e25c4SRahul Lakkireddy #include "cudbg_if.h"
49123e25c4SRahul Lakkireddy #include "cudbg_lib_common.h"
50123e25c4SRahul Lakkireddy #include "cudbg_entity.h"
51123e25c4SRahul Lakkireddy #include "cudbg_lib.h"
52fd88b31aSHariprasad Shenai 
53f1ff24aaSHariprasad Shenai /* generic seq_file support for showing a table of size rows x width. */
54f1ff24aaSHariprasad Shenai static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
55f1ff24aaSHariprasad Shenai {
56f1ff24aaSHariprasad Shenai 	pos -= tb->skip_first;
57f1ff24aaSHariprasad Shenai 	return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
58f1ff24aaSHariprasad Shenai }
59f1ff24aaSHariprasad Shenai 
60f1ff24aaSHariprasad Shenai static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
61f1ff24aaSHariprasad Shenai {
62f1ff24aaSHariprasad Shenai 	struct seq_tab *tb = seq->private;
63f1ff24aaSHariprasad Shenai 
64f1ff24aaSHariprasad Shenai 	if (tb->skip_first && *pos == 0)
65f1ff24aaSHariprasad Shenai 		return SEQ_START_TOKEN;
66f1ff24aaSHariprasad Shenai 
67f1ff24aaSHariprasad Shenai 	return seq_tab_get_idx(tb, *pos);
68f1ff24aaSHariprasad Shenai }
69f1ff24aaSHariprasad Shenai 
70f1ff24aaSHariprasad Shenai static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
71f1ff24aaSHariprasad Shenai {
72f1ff24aaSHariprasad Shenai 	v = seq_tab_get_idx(seq->private, *pos + 1);
73f1ff24aaSHariprasad Shenai 	if (v)
74f1ff24aaSHariprasad Shenai 		++*pos;
75f1ff24aaSHariprasad Shenai 	return v;
76f1ff24aaSHariprasad Shenai }
77f1ff24aaSHariprasad Shenai 
78f1ff24aaSHariprasad Shenai static void seq_tab_stop(struct seq_file *seq, void *v)
79f1ff24aaSHariprasad Shenai {
80f1ff24aaSHariprasad Shenai }
81f1ff24aaSHariprasad Shenai 
82f1ff24aaSHariprasad Shenai static int seq_tab_show(struct seq_file *seq, void *v)
83f1ff24aaSHariprasad Shenai {
84f1ff24aaSHariprasad Shenai 	const struct seq_tab *tb = seq->private;
85f1ff24aaSHariprasad Shenai 
86f1ff24aaSHariprasad Shenai 	return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
87f1ff24aaSHariprasad Shenai }
88f1ff24aaSHariprasad Shenai 
89f1ff24aaSHariprasad Shenai static const struct seq_operations seq_tab_ops = {
90f1ff24aaSHariprasad Shenai 	.start = seq_tab_start,
91f1ff24aaSHariprasad Shenai 	.next  = seq_tab_next,
92f1ff24aaSHariprasad Shenai 	.stop  = seq_tab_stop,
93f1ff24aaSHariprasad Shenai 	.show  = seq_tab_show
94f1ff24aaSHariprasad Shenai };
95f1ff24aaSHariprasad Shenai 
96f1ff24aaSHariprasad Shenai struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
97f1ff24aaSHariprasad Shenai 			     unsigned int width, unsigned int have_header,
98f1ff24aaSHariprasad Shenai 			     int (*show)(struct seq_file *seq, void *v, int i))
99f1ff24aaSHariprasad Shenai {
100f1ff24aaSHariprasad Shenai 	struct seq_tab *p;
101f1ff24aaSHariprasad Shenai 
102f1ff24aaSHariprasad Shenai 	p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
103f1ff24aaSHariprasad Shenai 	if (p) {
104f1ff24aaSHariprasad Shenai 		p->show = show;
105f1ff24aaSHariprasad Shenai 		p->rows = rows;
106f1ff24aaSHariprasad Shenai 		p->width = width;
107f1ff24aaSHariprasad Shenai 		p->skip_first = have_header != 0;
108f1ff24aaSHariprasad Shenai 	}
109f1ff24aaSHariprasad Shenai 	return p;
110f1ff24aaSHariprasad Shenai }
111f1ff24aaSHariprasad Shenai 
112c778af7dSHariprasad Shenai /* Trim the size of a seq_tab to the supplied number of rows.  The operation is
113c778af7dSHariprasad Shenai  * irreversible.
114c778af7dSHariprasad Shenai  */
115c778af7dSHariprasad Shenai static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
116c778af7dSHariprasad Shenai {
117c778af7dSHariprasad Shenai 	if (new_rows > p->rows)
118c778af7dSHariprasad Shenai 		return -EINVAL;
119c778af7dSHariprasad Shenai 	p->rows = new_rows;
120c778af7dSHariprasad Shenai 	return 0;
121c778af7dSHariprasad Shenai }
122c778af7dSHariprasad Shenai 
123f1ff24aaSHariprasad Shenai static int cim_la_show(struct seq_file *seq, void *v, int idx)
124f1ff24aaSHariprasad Shenai {
125f1ff24aaSHariprasad Shenai 	if (v == SEQ_START_TOKEN)
126f1ff24aaSHariprasad Shenai 		seq_puts(seq, "Status   Data      PC     LS0Stat  LS0Addr "
127f1ff24aaSHariprasad Shenai 			 "            LS0Data\n");
128f1ff24aaSHariprasad Shenai 	else {
129f1ff24aaSHariprasad Shenai 		const u32 *p = v;
130f1ff24aaSHariprasad Shenai 
131f1ff24aaSHariprasad Shenai 		seq_printf(seq,
132f1ff24aaSHariprasad Shenai 			   "  %02x  %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
133f1ff24aaSHariprasad Shenai 			   (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
134f1ff24aaSHariprasad Shenai 			   p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
135f1ff24aaSHariprasad Shenai 			   p[6], p[7]);
136f1ff24aaSHariprasad Shenai 	}
137f1ff24aaSHariprasad Shenai 	return 0;
138f1ff24aaSHariprasad Shenai }
139f1ff24aaSHariprasad Shenai 
140f1ff24aaSHariprasad Shenai static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
141f1ff24aaSHariprasad Shenai {
142f1ff24aaSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
143f1ff24aaSHariprasad Shenai 		seq_puts(seq, "Status   Data      PC\n");
144f1ff24aaSHariprasad Shenai 	} else {
145f1ff24aaSHariprasad Shenai 		const u32 *p = v;
146f1ff24aaSHariprasad Shenai 
147f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %08x %08x\n", p[5] & 0xff, p[6],
148f1ff24aaSHariprasad Shenai 			   p[7]);
149f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %02x%06x %02x%06x\n",
150f1ff24aaSHariprasad Shenai 			   (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
151f1ff24aaSHariprasad Shenai 			   p[4] & 0xff, p[5] >> 8);
152f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
153f1ff24aaSHariprasad Shenai 			   p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
154f1ff24aaSHariprasad Shenai 	}
155f1ff24aaSHariprasad Shenai 	return 0;
156f1ff24aaSHariprasad Shenai }
157f1ff24aaSHariprasad Shenai 
158b7660642SHariprasad Shenai static int cim_la_show_t6(struct seq_file *seq, void *v, int idx)
159b7660642SHariprasad Shenai {
160b7660642SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
161b7660642SHariprasad Shenai 		seq_puts(seq, "Status   Inst    Data      PC     LS0Stat  "
162b7660642SHariprasad Shenai 			 "LS0Addr  LS0Data  LS1Stat  LS1Addr  LS1Data\n");
163b7660642SHariprasad Shenai 	} else {
164b7660642SHariprasad Shenai 		const u32 *p = v;
165b7660642SHariprasad Shenai 
166b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x %08x %08x %08x %08x %08x %08x\n",
167b7660642SHariprasad Shenai 			   (p[9] >> 16) & 0xff,       /* Status */
168b7660642SHariprasad Shenai 			   p[9] & 0xffff, p[8] >> 16, /* Inst */
169b7660642SHariprasad Shenai 			   p[8] & 0xffff, p[7] >> 16, /* Data */
170b7660642SHariprasad Shenai 			   p[7] & 0xffff, p[6] >> 16, /* PC */
171b7660642SHariprasad Shenai 			   p[2], p[1], p[0],      /* LS0 Stat, Addr and Data */
172b7660642SHariprasad Shenai 			   p[5], p[4], p[3]);     /* LS1 Stat, Addr and Data */
173b7660642SHariprasad Shenai 	}
174b7660642SHariprasad Shenai 	return 0;
175b7660642SHariprasad Shenai }
176b7660642SHariprasad Shenai 
177b7660642SHariprasad Shenai static int cim_la_show_pc_t6(struct seq_file *seq, void *v, int idx)
178b7660642SHariprasad Shenai {
179b7660642SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
180b7660642SHariprasad Shenai 		seq_puts(seq, "Status   Inst    Data      PC\n");
181b7660642SHariprasad Shenai 	} else {
182b7660642SHariprasad Shenai 		const u32 *p = v;
183b7660642SHariprasad Shenai 
184b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %08x %08x %08x\n",
185b7660642SHariprasad Shenai 			   p[3] & 0xff, p[2], p[1], p[0]);
186b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %02x%06x %02x%06x %02x%06x\n",
187b7660642SHariprasad Shenai 			   (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
188b7660642SHariprasad Shenai 			   p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
189b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x\n",
190b7660642SHariprasad Shenai 			   (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
191b7660642SHariprasad Shenai 			   p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
192b7660642SHariprasad Shenai 			   p[6] >> 16);
193b7660642SHariprasad Shenai 	}
194b7660642SHariprasad Shenai 	return 0;
195b7660642SHariprasad Shenai }
196b7660642SHariprasad Shenai 
197f1ff24aaSHariprasad Shenai static int cim_la_open(struct inode *inode, struct file *file)
198f1ff24aaSHariprasad Shenai {
199f1ff24aaSHariprasad Shenai 	int ret;
200f1ff24aaSHariprasad Shenai 	unsigned int cfg;
201f1ff24aaSHariprasad Shenai 	struct seq_tab *p;
202f1ff24aaSHariprasad Shenai 	struct adapter *adap = inode->i_private;
203f1ff24aaSHariprasad Shenai 
204f1ff24aaSHariprasad Shenai 	ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
205f1ff24aaSHariprasad Shenai 	if (ret)
206f1ff24aaSHariprasad Shenai 		return ret;
207f1ff24aaSHariprasad Shenai 
208b7660642SHariprasad Shenai 	if (is_t6(adap->params.chip)) {
209b7660642SHariprasad Shenai 		/* +1 to account for integer division of CIMLA_SIZE/10 */
210b7660642SHariprasad Shenai 		p = seq_open_tab(file, (adap->params.cim_la_size / 10) + 1,
211b7660642SHariprasad Shenai 				 10 * sizeof(u32), 1,
212f1ff24aaSHariprasad Shenai 				 cfg & UPDBGLACAPTPCONLY_F ?
213b7660642SHariprasad Shenai 					cim_la_show_pc_t6 : cim_la_show_t6);
214b7660642SHariprasad Shenai 	} else {
215b7660642SHariprasad Shenai 		p = seq_open_tab(file, adap->params.cim_la_size / 8,
216b7660642SHariprasad Shenai 				 8 * sizeof(u32), 1,
217b7660642SHariprasad Shenai 				 cfg & UPDBGLACAPTPCONLY_F ? cim_la_show_3in1 :
218b7660642SHariprasad Shenai 							     cim_la_show);
219b7660642SHariprasad Shenai 	}
220f1ff24aaSHariprasad Shenai 	if (!p)
221f1ff24aaSHariprasad Shenai 		return -ENOMEM;
222f1ff24aaSHariprasad Shenai 
223f1ff24aaSHariprasad Shenai 	ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
224f1ff24aaSHariprasad Shenai 	if (ret)
225f1ff24aaSHariprasad Shenai 		seq_release_private(inode, file);
226f1ff24aaSHariprasad Shenai 	return ret;
227f1ff24aaSHariprasad Shenai }
228f1ff24aaSHariprasad Shenai 
229f1ff24aaSHariprasad Shenai static const struct file_operations cim_la_fops = {
230f1ff24aaSHariprasad Shenai 	.owner   = THIS_MODULE,
231f1ff24aaSHariprasad Shenai 	.open    = cim_la_open,
232f1ff24aaSHariprasad Shenai 	.read    = seq_read,
233f1ff24aaSHariprasad Shenai 	.llseek  = seq_lseek,
234f1ff24aaSHariprasad Shenai 	.release = seq_release_private
235f1ff24aaSHariprasad Shenai };
236f1ff24aaSHariprasad Shenai 
23719689609SHariprasad Shenai static int cim_pif_la_show(struct seq_file *seq, void *v, int idx)
23819689609SHariprasad Shenai {
23919689609SHariprasad Shenai 	const u32 *p = v;
24019689609SHariprasad Shenai 
24119689609SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
24219689609SHariprasad Shenai 		seq_puts(seq, "Cntl ID DataBE   Addr                 Data\n");
24319689609SHariprasad Shenai 	} else if (idx < CIM_PIFLA_SIZE) {
24419689609SHariprasad Shenai 		seq_printf(seq, " %02x  %02x  %04x  %08x %08x%08x%08x%08x\n",
24519689609SHariprasad Shenai 			   (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f,
24619689609SHariprasad Shenai 			   p[5] & 0xffff, p[4], p[3], p[2], p[1], p[0]);
24719689609SHariprasad Shenai 	} else {
24819689609SHariprasad Shenai 		if (idx == CIM_PIFLA_SIZE)
24919689609SHariprasad Shenai 			seq_puts(seq, "\nCntl ID               Data\n");
25019689609SHariprasad Shenai 		seq_printf(seq, " %02x  %02x %08x%08x%08x%08x\n",
25119689609SHariprasad Shenai 			   (p[4] >> 6) & 0xff, p[4] & 0x3f,
25219689609SHariprasad Shenai 			   p[3], p[2], p[1], p[0]);
25319689609SHariprasad Shenai 	}
25419689609SHariprasad Shenai 	return 0;
25519689609SHariprasad Shenai }
25619689609SHariprasad Shenai 
25719689609SHariprasad Shenai static int cim_pif_la_open(struct inode *inode, struct file *file)
25819689609SHariprasad Shenai {
25919689609SHariprasad Shenai 	struct seq_tab *p;
26019689609SHariprasad Shenai 	struct adapter *adap = inode->i_private;
26119689609SHariprasad Shenai 
26219689609SHariprasad Shenai 	p = seq_open_tab(file, 2 * CIM_PIFLA_SIZE, 6 * sizeof(u32), 1,
26319689609SHariprasad Shenai 			 cim_pif_la_show);
26419689609SHariprasad Shenai 	if (!p)
26519689609SHariprasad Shenai 		return -ENOMEM;
26619689609SHariprasad Shenai 
26719689609SHariprasad Shenai 	t4_cim_read_pif_la(adap, (u32 *)p->data,
26819689609SHariprasad Shenai 			   (u32 *)p->data + 6 * CIM_PIFLA_SIZE, NULL, NULL);
26919689609SHariprasad Shenai 	return 0;
27019689609SHariprasad Shenai }
27119689609SHariprasad Shenai 
27219689609SHariprasad Shenai static const struct file_operations cim_pif_la_fops = {
27319689609SHariprasad Shenai 	.owner   = THIS_MODULE,
27419689609SHariprasad Shenai 	.open    = cim_pif_la_open,
27519689609SHariprasad Shenai 	.read    = seq_read,
27619689609SHariprasad Shenai 	.llseek  = seq_lseek,
27719689609SHariprasad Shenai 	.release = seq_release_private
27819689609SHariprasad Shenai };
27919689609SHariprasad Shenai 
28026fae93fSHariprasad Shenai static int cim_ma_la_show(struct seq_file *seq, void *v, int idx)
28126fae93fSHariprasad Shenai {
28226fae93fSHariprasad Shenai 	const u32 *p = v;
28326fae93fSHariprasad Shenai 
28426fae93fSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
28526fae93fSHariprasad Shenai 		seq_puts(seq, "\n");
28626fae93fSHariprasad Shenai 	} else if (idx < CIM_MALA_SIZE) {
28726fae93fSHariprasad Shenai 		seq_printf(seq, "%02x%08x%08x%08x%08x\n",
28826fae93fSHariprasad Shenai 			   p[4], p[3], p[2], p[1], p[0]);
28926fae93fSHariprasad Shenai 	} else {
29026fae93fSHariprasad Shenai 		if (idx == CIM_MALA_SIZE)
29126fae93fSHariprasad Shenai 			seq_puts(seq,
29226fae93fSHariprasad Shenai 				 "\nCnt ID Tag UE       Data       RDY VLD\n");
29326fae93fSHariprasad Shenai 		seq_printf(seq, "%3u %2u  %x   %u %08x%08x  %u   %u\n",
29426fae93fSHariprasad Shenai 			   (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
29526fae93fSHariprasad Shenai 			   (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
29626fae93fSHariprasad Shenai 			   (p[1] >> 2) | ((p[2] & 3) << 30),
29726fae93fSHariprasad Shenai 			   (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
29826fae93fSHariprasad Shenai 			   p[0] & 1);
29926fae93fSHariprasad Shenai 	}
30026fae93fSHariprasad Shenai 	return 0;
30126fae93fSHariprasad Shenai }
30226fae93fSHariprasad Shenai 
30326fae93fSHariprasad Shenai static int cim_ma_la_open(struct inode *inode, struct file *file)
30426fae93fSHariprasad Shenai {
30526fae93fSHariprasad Shenai 	struct seq_tab *p;
30626fae93fSHariprasad Shenai 	struct adapter *adap = inode->i_private;
30726fae93fSHariprasad Shenai 
30826fae93fSHariprasad Shenai 	p = seq_open_tab(file, 2 * CIM_MALA_SIZE, 5 * sizeof(u32), 1,
30926fae93fSHariprasad Shenai 			 cim_ma_la_show);
31026fae93fSHariprasad Shenai 	if (!p)
31126fae93fSHariprasad Shenai 		return -ENOMEM;
31226fae93fSHariprasad Shenai 
31326fae93fSHariprasad Shenai 	t4_cim_read_ma_la(adap, (u32 *)p->data,
31426fae93fSHariprasad Shenai 			  (u32 *)p->data + 5 * CIM_MALA_SIZE);
31526fae93fSHariprasad Shenai 	return 0;
31626fae93fSHariprasad Shenai }
31726fae93fSHariprasad Shenai 
31826fae93fSHariprasad Shenai static const struct file_operations cim_ma_la_fops = {
31926fae93fSHariprasad Shenai 	.owner   = THIS_MODULE,
32026fae93fSHariprasad Shenai 	.open    = cim_ma_la_open,
32126fae93fSHariprasad Shenai 	.read    = seq_read,
32226fae93fSHariprasad Shenai 	.llseek  = seq_lseek,
32326fae93fSHariprasad Shenai 	.release = seq_release_private
32426fae93fSHariprasad Shenai };
32526fae93fSHariprasad Shenai 
32674b3092cSHariprasad Shenai static int cim_qcfg_show(struct seq_file *seq, void *v)
32774b3092cSHariprasad Shenai {
32874b3092cSHariprasad Shenai 	static const char * const qname[] = {
32974b3092cSHariprasad Shenai 		"TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
33074b3092cSHariprasad Shenai 		"ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
33174b3092cSHariprasad Shenai 		"SGE0-RX", "SGE1-RX"
33274b3092cSHariprasad Shenai 	};
33374b3092cSHariprasad Shenai 
33474b3092cSHariprasad Shenai 	int i;
33574b3092cSHariprasad Shenai 	struct adapter *adap = seq->private;
33674b3092cSHariprasad Shenai 	u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
33774b3092cSHariprasad Shenai 	u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
33874b3092cSHariprasad Shenai 	u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
33974b3092cSHariprasad Shenai 	u16 thres[CIM_NUM_IBQ];
34074b3092cSHariprasad Shenai 	u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
34174b3092cSHariprasad Shenai 	u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
34274b3092cSHariprasad Shenai 	u32 *p = stat;
34374b3092cSHariprasad Shenai 	int cim_num_obq = is_t4(adap->params.chip) ?
34474b3092cSHariprasad Shenai 				CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
34574b3092cSHariprasad Shenai 
34674b3092cSHariprasad Shenai 	i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
34774b3092cSHariprasad Shenai 			UP_IBQ_0_SHADOW_RDADDR_A,
34874b3092cSHariprasad Shenai 			ARRAY_SIZE(stat), stat);
34974b3092cSHariprasad Shenai 	if (!i) {
35074b3092cSHariprasad Shenai 		if (is_t4(adap->params.chip)) {
35174b3092cSHariprasad Shenai 			i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
35274b3092cSHariprasad Shenai 					ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
35374b3092cSHariprasad Shenai 			wr = obq_wr_t4;
35474b3092cSHariprasad Shenai 		} else {
35574b3092cSHariprasad Shenai 			i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
35674b3092cSHariprasad Shenai 					ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
35774b3092cSHariprasad Shenai 			wr = obq_wr_t5;
35874b3092cSHariprasad Shenai 		}
35974b3092cSHariprasad Shenai 	}
36074b3092cSHariprasad Shenai 	if (i)
36174b3092cSHariprasad Shenai 		return i;
36274b3092cSHariprasad Shenai 
36374b3092cSHariprasad Shenai 	t4_read_cimq_cfg(adap, base, size, thres);
36474b3092cSHariprasad Shenai 
36574b3092cSHariprasad Shenai 	seq_printf(seq,
36674b3092cSHariprasad Shenai 		   "  Queue  Base  Size Thres  RdPtr WrPtr  SOP  EOP Avail\n");
36774b3092cSHariprasad Shenai 	for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
36874b3092cSHariprasad Shenai 		seq_printf(seq, "%7s %5x %5u %5u %6x  %4x %4u %4u %5u\n",
36974b3092cSHariprasad Shenai 			   qname[i], base[i], size[i], thres[i],
37074b3092cSHariprasad Shenai 			   IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
37174b3092cSHariprasad Shenai 			   QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
37274b3092cSHariprasad Shenai 			   QUEREMFLITS_G(p[2]) * 16);
37374b3092cSHariprasad Shenai 	for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
37474b3092cSHariprasad Shenai 		seq_printf(seq, "%7s %5x %5u %12x  %4x %4u %4u %5u\n",
37574b3092cSHariprasad Shenai 			   qname[i], base[i], size[i],
37674b3092cSHariprasad Shenai 			   QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
37774b3092cSHariprasad Shenai 			   QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
37874b3092cSHariprasad Shenai 			   QUEREMFLITS_G(p[2]) * 16);
37974b3092cSHariprasad Shenai 	return 0;
38074b3092cSHariprasad Shenai }
38174b3092cSHariprasad Shenai 
38274b3092cSHariprasad Shenai static int cim_qcfg_open(struct inode *inode, struct file *file)
38374b3092cSHariprasad Shenai {
38474b3092cSHariprasad Shenai 	return single_open(file, cim_qcfg_show, inode->i_private);
38574b3092cSHariprasad Shenai }
38674b3092cSHariprasad Shenai 
38774b3092cSHariprasad Shenai static const struct file_operations cim_qcfg_fops = {
38874b3092cSHariprasad Shenai 	.owner   = THIS_MODULE,
38974b3092cSHariprasad Shenai 	.open    = cim_qcfg_open,
39074b3092cSHariprasad Shenai 	.read    = seq_read,
39174b3092cSHariprasad Shenai 	.llseek  = seq_lseek,
39274b3092cSHariprasad Shenai 	.release = single_release,
39374b3092cSHariprasad Shenai };
39474b3092cSHariprasad Shenai 
395e5f0e43bSHariprasad Shenai static int cimq_show(struct seq_file *seq, void *v, int idx)
396e5f0e43bSHariprasad Shenai {
397e5f0e43bSHariprasad Shenai 	const u32 *p = v;
398e5f0e43bSHariprasad Shenai 
399e5f0e43bSHariprasad Shenai 	seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
400e5f0e43bSHariprasad Shenai 		   p[2], p[3]);
401e5f0e43bSHariprasad Shenai 	return 0;
402e5f0e43bSHariprasad Shenai }
403e5f0e43bSHariprasad Shenai 
404e5f0e43bSHariprasad Shenai static int cim_ibq_open(struct inode *inode, struct file *file)
405e5f0e43bSHariprasad Shenai {
406e5f0e43bSHariprasad Shenai 	int ret;
407e5f0e43bSHariprasad Shenai 	struct seq_tab *p;
408e5f0e43bSHariprasad Shenai 	unsigned int qid = (uintptr_t)inode->i_private & 7;
409e5f0e43bSHariprasad Shenai 	struct adapter *adap = inode->i_private - qid;
410e5f0e43bSHariprasad Shenai 
411e5f0e43bSHariprasad Shenai 	p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
412e5f0e43bSHariprasad Shenai 	if (!p)
413e5f0e43bSHariprasad Shenai 		return -ENOMEM;
414e5f0e43bSHariprasad Shenai 
415e5f0e43bSHariprasad Shenai 	ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
416e5f0e43bSHariprasad Shenai 	if (ret < 0)
417e5f0e43bSHariprasad Shenai 		seq_release_private(inode, file);
418e5f0e43bSHariprasad Shenai 	else
419e5f0e43bSHariprasad Shenai 		ret = 0;
420e5f0e43bSHariprasad Shenai 	return ret;
421e5f0e43bSHariprasad Shenai }
422e5f0e43bSHariprasad Shenai 
423e5f0e43bSHariprasad Shenai static const struct file_operations cim_ibq_fops = {
424e5f0e43bSHariprasad Shenai 	.owner   = THIS_MODULE,
425e5f0e43bSHariprasad Shenai 	.open    = cim_ibq_open,
426e5f0e43bSHariprasad Shenai 	.read    = seq_read,
427e5f0e43bSHariprasad Shenai 	.llseek  = seq_lseek,
428e5f0e43bSHariprasad Shenai 	.release = seq_release_private
429e5f0e43bSHariprasad Shenai };
430e5f0e43bSHariprasad Shenai 
431c778af7dSHariprasad Shenai static int cim_obq_open(struct inode *inode, struct file *file)
432c778af7dSHariprasad Shenai {
433c778af7dSHariprasad Shenai 	int ret;
434c778af7dSHariprasad Shenai 	struct seq_tab *p;
435c778af7dSHariprasad Shenai 	unsigned int qid = (uintptr_t)inode->i_private & 7;
436c778af7dSHariprasad Shenai 	struct adapter *adap = inode->i_private - qid;
437c778af7dSHariprasad Shenai 
438c778af7dSHariprasad Shenai 	p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
439c778af7dSHariprasad Shenai 	if (!p)
440c778af7dSHariprasad Shenai 		return -ENOMEM;
441c778af7dSHariprasad Shenai 
442c778af7dSHariprasad Shenai 	ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
443c778af7dSHariprasad Shenai 	if (ret < 0) {
444c778af7dSHariprasad Shenai 		seq_release_private(inode, file);
445c778af7dSHariprasad Shenai 	} else {
446c778af7dSHariprasad Shenai 		seq_tab_trim(p, ret / 4);
447c778af7dSHariprasad Shenai 		ret = 0;
448c778af7dSHariprasad Shenai 	}
449c778af7dSHariprasad Shenai 	return ret;
450c778af7dSHariprasad Shenai }
451c778af7dSHariprasad Shenai 
452c778af7dSHariprasad Shenai static const struct file_operations cim_obq_fops = {
453c778af7dSHariprasad Shenai 	.owner   = THIS_MODULE,
454c778af7dSHariprasad Shenai 	.open    = cim_obq_open,
455c778af7dSHariprasad Shenai 	.read    = seq_read,
456c778af7dSHariprasad Shenai 	.llseek  = seq_lseek,
457c778af7dSHariprasad Shenai 	.release = seq_release_private
458c778af7dSHariprasad Shenai };
459c778af7dSHariprasad Shenai 
4602d277b3bSHariprasad Shenai struct field_desc {
4612d277b3bSHariprasad Shenai 	const char *name;
4622d277b3bSHariprasad Shenai 	unsigned int start;
4632d277b3bSHariprasad Shenai 	unsigned int width;
4642d277b3bSHariprasad Shenai };
4652d277b3bSHariprasad Shenai 
4662d277b3bSHariprasad Shenai static void field_desc_show(struct seq_file *seq, u64 v,
4672d277b3bSHariprasad Shenai 			    const struct field_desc *p)
4682d277b3bSHariprasad Shenai {
4692d277b3bSHariprasad Shenai 	char buf[32];
4702d277b3bSHariprasad Shenai 	int line_size = 0;
4712d277b3bSHariprasad Shenai 
4722d277b3bSHariprasad Shenai 	while (p->name) {
4732d277b3bSHariprasad Shenai 		u64 mask = (1ULL << p->width) - 1;
4742d277b3bSHariprasad Shenai 		int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
4752d277b3bSHariprasad Shenai 				    ((unsigned long long)v >> p->start) & mask);
4762d277b3bSHariprasad Shenai 
4772d277b3bSHariprasad Shenai 		if (line_size + len >= 79) {
4782d277b3bSHariprasad Shenai 			line_size = 8;
4792d277b3bSHariprasad Shenai 			seq_puts(seq, "\n        ");
4802d277b3bSHariprasad Shenai 		}
4812d277b3bSHariprasad Shenai 		seq_printf(seq, "%s ", buf);
4822d277b3bSHariprasad Shenai 		line_size += len + 1;
4832d277b3bSHariprasad Shenai 		p++;
4842d277b3bSHariprasad Shenai 	}
4852d277b3bSHariprasad Shenai 	seq_putc(seq, '\n');
4862d277b3bSHariprasad Shenai }
4872d277b3bSHariprasad Shenai 
4882d277b3bSHariprasad Shenai static struct field_desc tp_la0[] = {
4892d277b3bSHariprasad Shenai 	{ "RcfOpCodeOut", 60, 4 },
4902d277b3bSHariprasad Shenai 	{ "State", 56, 4 },
4912d277b3bSHariprasad Shenai 	{ "WcfState", 52, 4 },
4922d277b3bSHariprasad Shenai 	{ "RcfOpcSrcOut", 50, 2 },
4932d277b3bSHariprasad Shenai 	{ "CRxError", 49, 1 },
4942d277b3bSHariprasad Shenai 	{ "ERxError", 48, 1 },
4952d277b3bSHariprasad Shenai 	{ "SanityFailed", 47, 1 },
4962d277b3bSHariprasad Shenai 	{ "SpuriousMsg", 46, 1 },
4972d277b3bSHariprasad Shenai 	{ "FlushInputMsg", 45, 1 },
4982d277b3bSHariprasad Shenai 	{ "FlushInputCpl", 44, 1 },
4992d277b3bSHariprasad Shenai 	{ "RssUpBit", 43, 1 },
5002d277b3bSHariprasad Shenai 	{ "RssFilterHit", 42, 1 },
5012d277b3bSHariprasad Shenai 	{ "Tid", 32, 10 },
5022d277b3bSHariprasad Shenai 	{ "InitTcb", 31, 1 },
5032d277b3bSHariprasad Shenai 	{ "LineNumber", 24, 7 },
5042d277b3bSHariprasad Shenai 	{ "Emsg", 23, 1 },
5052d277b3bSHariprasad Shenai 	{ "EdataOut", 22, 1 },
5062d277b3bSHariprasad Shenai 	{ "Cmsg", 21, 1 },
5072d277b3bSHariprasad Shenai 	{ "CdataOut", 20, 1 },
5082d277b3bSHariprasad Shenai 	{ "EreadPdu", 19, 1 },
5092d277b3bSHariprasad Shenai 	{ "CreadPdu", 18, 1 },
5102d277b3bSHariprasad Shenai 	{ "TunnelPkt", 17, 1 },
5112d277b3bSHariprasad Shenai 	{ "RcfPeerFin", 16, 1 },
5122d277b3bSHariprasad Shenai 	{ "RcfReasonOut", 12, 4 },
5132d277b3bSHariprasad Shenai 	{ "TxCchannel", 10, 2 },
5142d277b3bSHariprasad Shenai 	{ "RcfTxChannel", 8, 2 },
5152d277b3bSHariprasad Shenai 	{ "RxEchannel", 6, 2 },
5162d277b3bSHariprasad Shenai 	{ "RcfRxChannel", 5, 1 },
5172d277b3bSHariprasad Shenai 	{ "RcfDataOutSrdy", 4, 1 },
5182d277b3bSHariprasad Shenai 	{ "RxDvld", 3, 1 },
5192d277b3bSHariprasad Shenai 	{ "RxOoDvld", 2, 1 },
5202d277b3bSHariprasad Shenai 	{ "RxCongestion", 1, 1 },
5212d277b3bSHariprasad Shenai 	{ "TxCongestion", 0, 1 },
5222d277b3bSHariprasad Shenai 	{ NULL }
5232d277b3bSHariprasad Shenai };
5242d277b3bSHariprasad Shenai 
5252d277b3bSHariprasad Shenai static int tp_la_show(struct seq_file *seq, void *v, int idx)
5262d277b3bSHariprasad Shenai {
5272d277b3bSHariprasad Shenai 	const u64 *p = v;
5282d277b3bSHariprasad Shenai 
5292d277b3bSHariprasad Shenai 	field_desc_show(seq, *p, tp_la0);
5302d277b3bSHariprasad Shenai 	return 0;
5312d277b3bSHariprasad Shenai }
5322d277b3bSHariprasad Shenai 
5332d277b3bSHariprasad Shenai static int tp_la_show2(struct seq_file *seq, void *v, int idx)
5342d277b3bSHariprasad Shenai {
5352d277b3bSHariprasad Shenai 	const u64 *p = v;
5362d277b3bSHariprasad Shenai 
5372d277b3bSHariprasad Shenai 	if (idx)
5382d277b3bSHariprasad Shenai 		seq_putc(seq, '\n');
5392d277b3bSHariprasad Shenai 	field_desc_show(seq, p[0], tp_la0);
5402d277b3bSHariprasad Shenai 	if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
5412d277b3bSHariprasad Shenai 		field_desc_show(seq, p[1], tp_la0);
5422d277b3bSHariprasad Shenai 	return 0;
5432d277b3bSHariprasad Shenai }
5442d277b3bSHariprasad Shenai 
5452d277b3bSHariprasad Shenai static int tp_la_show3(struct seq_file *seq, void *v, int idx)
5462d277b3bSHariprasad Shenai {
5472d277b3bSHariprasad Shenai 	static struct field_desc tp_la1[] = {
5482d277b3bSHariprasad Shenai 		{ "CplCmdIn", 56, 8 },
5492d277b3bSHariprasad Shenai 		{ "CplCmdOut", 48, 8 },
5502d277b3bSHariprasad Shenai 		{ "ESynOut", 47, 1 },
5512d277b3bSHariprasad Shenai 		{ "EAckOut", 46, 1 },
5522d277b3bSHariprasad Shenai 		{ "EFinOut", 45, 1 },
5532d277b3bSHariprasad Shenai 		{ "ERstOut", 44, 1 },
5542d277b3bSHariprasad Shenai 		{ "SynIn", 43, 1 },
5552d277b3bSHariprasad Shenai 		{ "AckIn", 42, 1 },
5562d277b3bSHariprasad Shenai 		{ "FinIn", 41, 1 },
5572d277b3bSHariprasad Shenai 		{ "RstIn", 40, 1 },
5582d277b3bSHariprasad Shenai 		{ "DataIn", 39, 1 },
5592d277b3bSHariprasad Shenai 		{ "DataInVld", 38, 1 },
5602d277b3bSHariprasad Shenai 		{ "PadIn", 37, 1 },
5612d277b3bSHariprasad Shenai 		{ "RxBufEmpty", 36, 1 },
5622d277b3bSHariprasad Shenai 		{ "RxDdp", 35, 1 },
5632d277b3bSHariprasad Shenai 		{ "RxFbCongestion", 34, 1 },
5642d277b3bSHariprasad Shenai 		{ "TxFbCongestion", 33, 1 },
5652d277b3bSHariprasad Shenai 		{ "TxPktSumSrdy", 32, 1 },
5662d277b3bSHariprasad Shenai 		{ "RcfUlpType", 28, 4 },
5672d277b3bSHariprasad Shenai 		{ "Eread", 27, 1 },
5682d277b3bSHariprasad Shenai 		{ "Ebypass", 26, 1 },
5692d277b3bSHariprasad Shenai 		{ "Esave", 25, 1 },
5702d277b3bSHariprasad Shenai 		{ "Static0", 24, 1 },
5712d277b3bSHariprasad Shenai 		{ "Cread", 23, 1 },
5722d277b3bSHariprasad Shenai 		{ "Cbypass", 22, 1 },
5732d277b3bSHariprasad Shenai 		{ "Csave", 21, 1 },
5742d277b3bSHariprasad Shenai 		{ "CPktOut", 20, 1 },
5752d277b3bSHariprasad Shenai 		{ "RxPagePoolFull", 18, 2 },
5762d277b3bSHariprasad Shenai 		{ "RxLpbkPkt", 17, 1 },
5772d277b3bSHariprasad Shenai 		{ "TxLpbkPkt", 16, 1 },
5782d277b3bSHariprasad Shenai 		{ "RxVfValid", 15, 1 },
5792d277b3bSHariprasad Shenai 		{ "SynLearned", 14, 1 },
5802d277b3bSHariprasad Shenai 		{ "SetDelEntry", 13, 1 },
5812d277b3bSHariprasad Shenai 		{ "SetInvEntry", 12, 1 },
5822d277b3bSHariprasad Shenai 		{ "CpcmdDvld", 11, 1 },
5832d277b3bSHariprasad Shenai 		{ "CpcmdSave", 10, 1 },
5842d277b3bSHariprasad Shenai 		{ "RxPstructsFull", 8, 2 },
5852d277b3bSHariprasad Shenai 		{ "EpcmdDvld", 7, 1 },
5862d277b3bSHariprasad Shenai 		{ "EpcmdFlush", 6, 1 },
5872d277b3bSHariprasad Shenai 		{ "EpcmdTrimPrefix", 5, 1 },
5882d277b3bSHariprasad Shenai 		{ "EpcmdTrimPostfix", 4, 1 },
5892d277b3bSHariprasad Shenai 		{ "ERssIp4Pkt", 3, 1 },
5902d277b3bSHariprasad Shenai 		{ "ERssIp6Pkt", 2, 1 },
5912d277b3bSHariprasad Shenai 		{ "ERssTcpUdpPkt", 1, 1 },
5922d277b3bSHariprasad Shenai 		{ "ERssFceFipPkt", 0, 1 },
5932d277b3bSHariprasad Shenai 		{ NULL }
5942d277b3bSHariprasad Shenai 	};
5952d277b3bSHariprasad Shenai 	static struct field_desc tp_la2[] = {
5962d277b3bSHariprasad Shenai 		{ "CplCmdIn", 56, 8 },
5972d277b3bSHariprasad Shenai 		{ "MpsVfVld", 55, 1 },
5982d277b3bSHariprasad Shenai 		{ "MpsPf", 52, 3 },
5992d277b3bSHariprasad Shenai 		{ "MpsVf", 44, 8 },
6002d277b3bSHariprasad Shenai 		{ "SynIn", 43, 1 },
6012d277b3bSHariprasad Shenai 		{ "AckIn", 42, 1 },
6022d277b3bSHariprasad Shenai 		{ "FinIn", 41, 1 },
6032d277b3bSHariprasad Shenai 		{ "RstIn", 40, 1 },
6042d277b3bSHariprasad Shenai 		{ "DataIn", 39, 1 },
6052d277b3bSHariprasad Shenai 		{ "DataInVld", 38, 1 },
6062d277b3bSHariprasad Shenai 		{ "PadIn", 37, 1 },
6072d277b3bSHariprasad Shenai 		{ "RxBufEmpty", 36, 1 },
6082d277b3bSHariprasad Shenai 		{ "RxDdp", 35, 1 },
6092d277b3bSHariprasad Shenai 		{ "RxFbCongestion", 34, 1 },
6102d277b3bSHariprasad Shenai 		{ "TxFbCongestion", 33, 1 },
6112d277b3bSHariprasad Shenai 		{ "TxPktSumSrdy", 32, 1 },
6122d277b3bSHariprasad Shenai 		{ "RcfUlpType", 28, 4 },
6132d277b3bSHariprasad Shenai 		{ "Eread", 27, 1 },
6142d277b3bSHariprasad Shenai 		{ "Ebypass", 26, 1 },
6152d277b3bSHariprasad Shenai 		{ "Esave", 25, 1 },
6162d277b3bSHariprasad Shenai 		{ "Static0", 24, 1 },
6172d277b3bSHariprasad Shenai 		{ "Cread", 23, 1 },
6182d277b3bSHariprasad Shenai 		{ "Cbypass", 22, 1 },
6192d277b3bSHariprasad Shenai 		{ "Csave", 21, 1 },
6202d277b3bSHariprasad Shenai 		{ "CPktOut", 20, 1 },
6212d277b3bSHariprasad Shenai 		{ "RxPagePoolFull", 18, 2 },
6222d277b3bSHariprasad Shenai 		{ "RxLpbkPkt", 17, 1 },
6232d277b3bSHariprasad Shenai 		{ "TxLpbkPkt", 16, 1 },
6242d277b3bSHariprasad Shenai 		{ "RxVfValid", 15, 1 },
6252d277b3bSHariprasad Shenai 		{ "SynLearned", 14, 1 },
6262d277b3bSHariprasad Shenai 		{ "SetDelEntry", 13, 1 },
6272d277b3bSHariprasad Shenai 		{ "SetInvEntry", 12, 1 },
6282d277b3bSHariprasad Shenai 		{ "CpcmdDvld", 11, 1 },
6292d277b3bSHariprasad Shenai 		{ "CpcmdSave", 10, 1 },
6302d277b3bSHariprasad Shenai 		{ "RxPstructsFull", 8, 2 },
6312d277b3bSHariprasad Shenai 		{ "EpcmdDvld", 7, 1 },
6322d277b3bSHariprasad Shenai 		{ "EpcmdFlush", 6, 1 },
6332d277b3bSHariprasad Shenai 		{ "EpcmdTrimPrefix", 5, 1 },
6342d277b3bSHariprasad Shenai 		{ "EpcmdTrimPostfix", 4, 1 },
6352d277b3bSHariprasad Shenai 		{ "ERssIp4Pkt", 3, 1 },
6362d277b3bSHariprasad Shenai 		{ "ERssIp6Pkt", 2, 1 },
6372d277b3bSHariprasad Shenai 		{ "ERssTcpUdpPkt", 1, 1 },
6382d277b3bSHariprasad Shenai 		{ "ERssFceFipPkt", 0, 1 },
6392d277b3bSHariprasad Shenai 		{ NULL }
6402d277b3bSHariprasad Shenai 	};
6412d277b3bSHariprasad Shenai 	const u64 *p = v;
6422d277b3bSHariprasad Shenai 
6432d277b3bSHariprasad Shenai 	if (idx)
6442d277b3bSHariprasad Shenai 		seq_putc(seq, '\n');
6452d277b3bSHariprasad Shenai 	field_desc_show(seq, p[0], tp_la0);
6462d277b3bSHariprasad Shenai 	if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6472d277b3bSHariprasad Shenai 		field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
6482d277b3bSHariprasad Shenai 	return 0;
6492d277b3bSHariprasad Shenai }
6502d277b3bSHariprasad Shenai 
6512d277b3bSHariprasad Shenai static int tp_la_open(struct inode *inode, struct file *file)
6522d277b3bSHariprasad Shenai {
6532d277b3bSHariprasad Shenai 	struct seq_tab *p;
6542d277b3bSHariprasad Shenai 	struct adapter *adap = inode->i_private;
6552d277b3bSHariprasad Shenai 
6562d277b3bSHariprasad Shenai 	switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
6572d277b3bSHariprasad Shenai 	case 2:
6582d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
6592d277b3bSHariprasad Shenai 				 tp_la_show2);
6602d277b3bSHariprasad Shenai 		break;
6612d277b3bSHariprasad Shenai 	case 3:
6622d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
6632d277b3bSHariprasad Shenai 				 tp_la_show3);
6642d277b3bSHariprasad Shenai 		break;
6652d277b3bSHariprasad Shenai 	default:
6662d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
6672d277b3bSHariprasad Shenai 	}
6682d277b3bSHariprasad Shenai 	if (!p)
6692d277b3bSHariprasad Shenai 		return -ENOMEM;
6702d277b3bSHariprasad Shenai 
6712d277b3bSHariprasad Shenai 	t4_tp_read_la(adap, (u64 *)p->data, NULL);
6722d277b3bSHariprasad Shenai 	return 0;
6732d277b3bSHariprasad Shenai }
6742d277b3bSHariprasad Shenai 
6752d277b3bSHariprasad Shenai static ssize_t tp_la_write(struct file *file, const char __user *buf,
6762d277b3bSHariprasad Shenai 			   size_t count, loff_t *pos)
6772d277b3bSHariprasad Shenai {
6782d277b3bSHariprasad Shenai 	int err;
6792d277b3bSHariprasad Shenai 	char s[32];
6802d277b3bSHariprasad Shenai 	unsigned long val;
6812d277b3bSHariprasad Shenai 	size_t size = min(sizeof(s) - 1, count);
682c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
6832d277b3bSHariprasad Shenai 
6842d277b3bSHariprasad Shenai 	if (copy_from_user(s, buf, size))
6852d277b3bSHariprasad Shenai 		return -EFAULT;
6862d277b3bSHariprasad Shenai 	s[size] = '\0';
6872d277b3bSHariprasad Shenai 	err = kstrtoul(s, 0, &val);
6882d277b3bSHariprasad Shenai 	if (err)
6892d277b3bSHariprasad Shenai 		return err;
6902d277b3bSHariprasad Shenai 	if (val > 0xffff)
6912d277b3bSHariprasad Shenai 		return -EINVAL;
6922d277b3bSHariprasad Shenai 	adap->params.tp.la_mask = val << 16;
6932d277b3bSHariprasad Shenai 	t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
6942d277b3bSHariprasad Shenai 			 adap->params.tp.la_mask);
6952d277b3bSHariprasad Shenai 	return count;
6962d277b3bSHariprasad Shenai }
6972d277b3bSHariprasad Shenai 
6982d277b3bSHariprasad Shenai static const struct file_operations tp_la_fops = {
6992d277b3bSHariprasad Shenai 	.owner   = THIS_MODULE,
7002d277b3bSHariprasad Shenai 	.open    = tp_la_open,
7012d277b3bSHariprasad Shenai 	.read    = seq_read,
7022d277b3bSHariprasad Shenai 	.llseek  = seq_lseek,
7032d277b3bSHariprasad Shenai 	.release = seq_release_private,
7042d277b3bSHariprasad Shenai 	.write   = tp_la_write
7052d277b3bSHariprasad Shenai };
7062d277b3bSHariprasad Shenai 
707797ff0f5SHariprasad Shenai static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
708797ff0f5SHariprasad Shenai {
709797ff0f5SHariprasad Shenai 	const u32 *p = v;
710797ff0f5SHariprasad Shenai 
711797ff0f5SHariprasad Shenai 	if (v == SEQ_START_TOKEN)
712797ff0f5SHariprasad Shenai 		seq_puts(seq, "      Pcmd        Type   Message"
713797ff0f5SHariprasad Shenai 			 "                Data\n");
714797ff0f5SHariprasad Shenai 	else
715797ff0f5SHariprasad Shenai 		seq_printf(seq, "%08x%08x  %4x  %08x  %08x%08x%08x%08x\n",
716797ff0f5SHariprasad Shenai 			   p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
717797ff0f5SHariprasad Shenai 	return 0;
718797ff0f5SHariprasad Shenai }
719797ff0f5SHariprasad Shenai 
720797ff0f5SHariprasad Shenai static int ulprx_la_open(struct inode *inode, struct file *file)
721797ff0f5SHariprasad Shenai {
722797ff0f5SHariprasad Shenai 	struct seq_tab *p;
723797ff0f5SHariprasad Shenai 	struct adapter *adap = inode->i_private;
724797ff0f5SHariprasad Shenai 
725797ff0f5SHariprasad Shenai 	p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
726797ff0f5SHariprasad Shenai 			 ulprx_la_show);
727797ff0f5SHariprasad Shenai 	if (!p)
728797ff0f5SHariprasad Shenai 		return -ENOMEM;
729797ff0f5SHariprasad Shenai 
730797ff0f5SHariprasad Shenai 	t4_ulprx_read_la(adap, (u32 *)p->data);
731797ff0f5SHariprasad Shenai 	return 0;
732797ff0f5SHariprasad Shenai }
733797ff0f5SHariprasad Shenai 
734797ff0f5SHariprasad Shenai static const struct file_operations ulprx_la_fops = {
735797ff0f5SHariprasad Shenai 	.owner   = THIS_MODULE,
736797ff0f5SHariprasad Shenai 	.open    = ulprx_la_open,
737797ff0f5SHariprasad Shenai 	.read    = seq_read,
738797ff0f5SHariprasad Shenai 	.llseek  = seq_lseek,
739797ff0f5SHariprasad Shenai 	.release = seq_release_private
740797ff0f5SHariprasad Shenai };
741797ff0f5SHariprasad Shenai 
742b3bbe36aSHariprasad Shenai /* Show the PM memory stats.  These stats include:
743b3bbe36aSHariprasad Shenai  *
744b3bbe36aSHariprasad Shenai  * TX:
745b3bbe36aSHariprasad Shenai  *   Read: memory read operation
746b3bbe36aSHariprasad Shenai  *   Write Bypass: cut-through
747b3bbe36aSHariprasad Shenai  *   Bypass + mem: cut-through and save copy
748b3bbe36aSHariprasad Shenai  *
749b3bbe36aSHariprasad Shenai  * RX:
750b3bbe36aSHariprasad Shenai  *   Read: memory read
751b3bbe36aSHariprasad Shenai  *   Write Bypass: cut-through
752b3bbe36aSHariprasad Shenai  *   Flush: payload trim or drop
753b3bbe36aSHariprasad Shenai  */
754b3bbe36aSHariprasad Shenai static int pm_stats_show(struct seq_file *seq, void *v)
755b3bbe36aSHariprasad Shenai {
756b3bbe36aSHariprasad Shenai 	static const char * const tx_pm_stats[] = {
757b3bbe36aSHariprasad Shenai 		"Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
758b3bbe36aSHariprasad Shenai 	};
759b3bbe36aSHariprasad Shenai 	static const char * const rx_pm_stats[] = {
760b3bbe36aSHariprasad Shenai 		"Read:", "Write bypass:", "Write mem:", "Flush:"
761b3bbe36aSHariprasad Shenai 	};
762b3bbe36aSHariprasad Shenai 
763b3bbe36aSHariprasad Shenai 	int i;
76444588560SHariprasad Shenai 	u32 tx_cnt[T6_PM_NSTATS], rx_cnt[T6_PM_NSTATS];
76544588560SHariprasad Shenai 	u64 tx_cyc[T6_PM_NSTATS], rx_cyc[T6_PM_NSTATS];
766b3bbe36aSHariprasad Shenai 	struct adapter *adap = seq->private;
767b3bbe36aSHariprasad Shenai 
768b3bbe36aSHariprasad Shenai 	t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
769b3bbe36aSHariprasad Shenai 	t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
770b3bbe36aSHariprasad Shenai 
771b3bbe36aSHariprasad Shenai 	seq_printf(seq, "%13s %10s  %20s\n", " ", "Tx pcmds", "Tx bytes");
772b3bbe36aSHariprasad Shenai 	for (i = 0; i < PM_NSTATS - 1; i++)
773b3bbe36aSHariprasad Shenai 		seq_printf(seq, "%-13s %10u  %20llu\n",
774b3bbe36aSHariprasad Shenai 			   tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
775b3bbe36aSHariprasad Shenai 
776b3bbe36aSHariprasad Shenai 	seq_printf(seq, "%13s %10s  %20s\n", " ", "Rx pcmds", "Rx bytes");
777b3bbe36aSHariprasad Shenai 	for (i = 0; i < PM_NSTATS - 1; i++)
778b3bbe36aSHariprasad Shenai 		seq_printf(seq, "%-13s %10u  %20llu\n",
779b3bbe36aSHariprasad Shenai 			   rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
78044588560SHariprasad Shenai 
78144588560SHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
78244588560SHariprasad Shenai 		/* In T5 the granularity of the total wait is too fine.
78344588560SHariprasad Shenai 		 * It is not useful as it reaches the max value too fast.
78444588560SHariprasad Shenai 		 * Hence display this Input FIFO wait for T6 onwards.
78544588560SHariprasad Shenai 		 */
78644588560SHariprasad Shenai 		seq_printf(seq, "%13s %10s  %20s\n",
78744588560SHariprasad Shenai 			   " ", "Total wait", "Total Occupancy");
78844588560SHariprasad Shenai 		seq_printf(seq, "Tx FIFO wait  %10u  %20llu\n",
78944588560SHariprasad Shenai 			   tx_cnt[i], tx_cyc[i]);
79044588560SHariprasad Shenai 		seq_printf(seq, "Rx FIFO wait  %10u  %20llu\n",
79144588560SHariprasad Shenai 			   rx_cnt[i], rx_cyc[i]);
79244588560SHariprasad Shenai 
79344588560SHariprasad Shenai 		/* Skip index 6 as there is nothing useful ihere */
79444588560SHariprasad Shenai 		i += 2;
79544588560SHariprasad Shenai 
79644588560SHariprasad Shenai 		/* At index 7, a new stat for read latency (count, total wait)
79744588560SHariprasad Shenai 		 * is added.
79844588560SHariprasad Shenai 		 */
79944588560SHariprasad Shenai 		seq_printf(seq, "%13s %10s  %20s\n",
80044588560SHariprasad Shenai 			   " ", "Reads", "Total wait");
80144588560SHariprasad Shenai 		seq_printf(seq, "Tx latency    %10u  %20llu\n",
80244588560SHariprasad Shenai 			   tx_cnt[i], tx_cyc[i]);
80344588560SHariprasad Shenai 		seq_printf(seq, "Rx latency    %10u  %20llu\n",
80444588560SHariprasad Shenai 			   rx_cnt[i], rx_cyc[i]);
80544588560SHariprasad Shenai 	}
806b3bbe36aSHariprasad Shenai 	return 0;
807b3bbe36aSHariprasad Shenai }
808b3bbe36aSHariprasad Shenai 
809b3bbe36aSHariprasad Shenai static int pm_stats_open(struct inode *inode, struct file *file)
810b3bbe36aSHariprasad Shenai {
811b3bbe36aSHariprasad Shenai 	return single_open(file, pm_stats_show, inode->i_private);
812b3bbe36aSHariprasad Shenai }
813b3bbe36aSHariprasad Shenai 
814b3bbe36aSHariprasad Shenai static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
815b3bbe36aSHariprasad Shenai 			      size_t count, loff_t *pos)
816b3bbe36aSHariprasad Shenai {
817c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
818b3bbe36aSHariprasad Shenai 
819b3bbe36aSHariprasad Shenai 	t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
820b3bbe36aSHariprasad Shenai 	t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
821b3bbe36aSHariprasad Shenai 	return count;
822b3bbe36aSHariprasad Shenai }
823b3bbe36aSHariprasad Shenai 
824b3bbe36aSHariprasad Shenai static const struct file_operations pm_stats_debugfs_fops = {
825b3bbe36aSHariprasad Shenai 	.owner   = THIS_MODULE,
826b3bbe36aSHariprasad Shenai 	.open    = pm_stats_open,
827b3bbe36aSHariprasad Shenai 	.read    = seq_read,
828b3bbe36aSHariprasad Shenai 	.llseek  = seq_lseek,
829b3bbe36aSHariprasad Shenai 	.release = single_release,
830b3bbe36aSHariprasad Shenai 	.write   = pm_stats_clear
831b3bbe36aSHariprasad Shenai };
832b3bbe36aSHariprasad Shenai 
8337864026bSHariprasad Shenai static int tx_rate_show(struct seq_file *seq, void *v)
8347864026bSHariprasad Shenai {
8357864026bSHariprasad Shenai 	u64 nrate[NCHAN], orate[NCHAN];
8367864026bSHariprasad Shenai 	struct adapter *adap = seq->private;
8377864026bSHariprasad Shenai 
8387864026bSHariprasad Shenai 	t4_get_chan_txrate(adap, nrate, orate);
8397864026bSHariprasad Shenai 	if (adap->params.arch.nchan == NCHAN) {
8407864026bSHariprasad Shenai 		seq_puts(seq, "              channel 0   channel 1   "
8417864026bSHariprasad Shenai 			 "channel 2   channel 3\n");
8427864026bSHariprasad Shenai 		seq_printf(seq, "NIC B/s:     %10llu  %10llu  %10llu  %10llu\n",
8437864026bSHariprasad Shenai 			   (unsigned long long)nrate[0],
8447864026bSHariprasad Shenai 			   (unsigned long long)nrate[1],
8457864026bSHariprasad Shenai 			   (unsigned long long)nrate[2],
8467864026bSHariprasad Shenai 			   (unsigned long long)nrate[3]);
8477864026bSHariprasad Shenai 		seq_printf(seq, "Offload B/s: %10llu  %10llu  %10llu  %10llu\n",
8487864026bSHariprasad Shenai 			   (unsigned long long)orate[0],
8497864026bSHariprasad Shenai 			   (unsigned long long)orate[1],
8507864026bSHariprasad Shenai 			   (unsigned long long)orate[2],
8517864026bSHariprasad Shenai 			   (unsigned long long)orate[3]);
8527864026bSHariprasad Shenai 	} else {
8537864026bSHariprasad Shenai 		seq_puts(seq, "              channel 0   channel 1\n");
8547864026bSHariprasad Shenai 		seq_printf(seq, "NIC B/s:     %10llu  %10llu\n",
8557864026bSHariprasad Shenai 			   (unsigned long long)nrate[0],
8567864026bSHariprasad Shenai 			   (unsigned long long)nrate[1]);
8577864026bSHariprasad Shenai 		seq_printf(seq, "Offload B/s: %10llu  %10llu\n",
8587864026bSHariprasad Shenai 			   (unsigned long long)orate[0],
8597864026bSHariprasad Shenai 			   (unsigned long long)orate[1]);
8607864026bSHariprasad Shenai 	}
8617864026bSHariprasad Shenai 	return 0;
8627864026bSHariprasad Shenai }
8637864026bSHariprasad Shenai 
8647864026bSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(tx_rate);
8657864026bSHariprasad Shenai 
866bad43792SHariprasad Shenai static int cctrl_tbl_show(struct seq_file *seq, void *v)
867bad43792SHariprasad Shenai {
868bad43792SHariprasad Shenai 	static const char * const dec_fac[] = {
869bad43792SHariprasad Shenai 		"0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
870bad43792SHariprasad Shenai 		"0.9375" };
871bad43792SHariprasad Shenai 
872bad43792SHariprasad Shenai 	int i;
873dde93dfeSHariprasad Shenai 	u16 (*incr)[NCCTRL_WIN];
874bad43792SHariprasad Shenai 	struct adapter *adap = seq->private;
875bad43792SHariprasad Shenai 
8766da2ec56SKees Cook 	incr = kmalloc_array(NMTUS, sizeof(*incr), GFP_KERNEL);
877dde93dfeSHariprasad Shenai 	if (!incr)
878dde93dfeSHariprasad Shenai 		return -ENOMEM;
879dde93dfeSHariprasad Shenai 
880bad43792SHariprasad Shenai 	t4_read_cong_tbl(adap, incr);
881bad43792SHariprasad Shenai 
882bad43792SHariprasad Shenai 	for (i = 0; i < NCCTRL_WIN; ++i) {
883bad43792SHariprasad Shenai 		seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
884bad43792SHariprasad Shenai 			   incr[0][i], incr[1][i], incr[2][i], incr[3][i],
885bad43792SHariprasad Shenai 			   incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
886bad43792SHariprasad Shenai 		seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
887bad43792SHariprasad Shenai 			   incr[8][i], incr[9][i], incr[10][i], incr[11][i],
888bad43792SHariprasad Shenai 			   incr[12][i], incr[13][i], incr[14][i], incr[15][i],
889bad43792SHariprasad Shenai 			   adap->params.a_wnd[i],
890bad43792SHariprasad Shenai 			   dec_fac[adap->params.b_wnd[i]]);
891bad43792SHariprasad Shenai 	}
892dde93dfeSHariprasad Shenai 
893dde93dfeSHariprasad Shenai 	kfree(incr);
894bad43792SHariprasad Shenai 	return 0;
895bad43792SHariprasad Shenai }
896bad43792SHariprasad Shenai 
897bad43792SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(cctrl_tbl);
898bad43792SHariprasad Shenai 
899b58b6676SHariprasad Shenai /* Format a value in a unit that differs from the value's native unit by the
900b58b6676SHariprasad Shenai  * given factor.
901b58b6676SHariprasad Shenai  */
902b58b6676SHariprasad Shenai static char *unit_conv(char *buf, size_t len, unsigned int val,
903b58b6676SHariprasad Shenai 		       unsigned int factor)
904b58b6676SHariprasad Shenai {
905b58b6676SHariprasad Shenai 	unsigned int rem = val % factor;
906b58b6676SHariprasad Shenai 
907b58b6676SHariprasad Shenai 	if (rem == 0) {
908b58b6676SHariprasad Shenai 		snprintf(buf, len, "%u", val / factor);
909b58b6676SHariprasad Shenai 	} else {
910b58b6676SHariprasad Shenai 		while (rem % 10 == 0)
911b58b6676SHariprasad Shenai 			rem /= 10;
912b58b6676SHariprasad Shenai 		snprintf(buf, len, "%u.%u", val / factor, rem);
913b58b6676SHariprasad Shenai 	}
914b58b6676SHariprasad Shenai 	return buf;
915b58b6676SHariprasad Shenai }
916b58b6676SHariprasad Shenai 
917b58b6676SHariprasad Shenai static int clk_show(struct seq_file *seq, void *v)
918b58b6676SHariprasad Shenai {
919b58b6676SHariprasad Shenai 	char buf[32];
920b58b6676SHariprasad Shenai 	struct adapter *adap = seq->private;
921b58b6676SHariprasad Shenai 	unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk;  /* in ps */
922b58b6676SHariprasad Shenai 	u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
923b58b6676SHariprasad Shenai 	unsigned int tre = TIMERRESOLUTION_G(res);
924b58b6676SHariprasad Shenai 	unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
925b58b6676SHariprasad Shenai 	unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
926b58b6676SHariprasad Shenai 
927b58b6676SHariprasad Shenai 	seq_printf(seq, "Core clock period: %s ns\n",
928b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), cclk_ps, 1000));
929b58b6676SHariprasad Shenai 	seq_printf(seq, "TP timer tick: %s us\n",
930b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
931b58b6676SHariprasad Shenai 	seq_printf(seq, "TCP timestamp tick: %s us\n",
932b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf),
933b58b6676SHariprasad Shenai 			     (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
934b58b6676SHariprasad Shenai 	seq_printf(seq, "DACK tick: %s us\n",
935b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
936b58b6676SHariprasad Shenai 	seq_printf(seq, "DACK timer: %u us\n",
937b58b6676SHariprasad Shenai 		   ((cclk_ps << dack_re) / 1000000) *
938b58b6676SHariprasad Shenai 		   t4_read_reg(adap, TP_DACK_TIMER_A));
939b58b6676SHariprasad Shenai 	seq_printf(seq, "Retransmit min: %llu us\n",
940b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
941b58b6676SHariprasad Shenai 	seq_printf(seq, "Retransmit max: %llu us\n",
942b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
943b58b6676SHariprasad Shenai 	seq_printf(seq, "Persist timer min: %llu us\n",
944b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
945b58b6676SHariprasad Shenai 	seq_printf(seq, "Persist timer max: %llu us\n",
946b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
947b58b6676SHariprasad Shenai 	seq_printf(seq, "Keepalive idle timer: %llu us\n",
948b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
949b58b6676SHariprasad Shenai 	seq_printf(seq, "Keepalive interval: %llu us\n",
950b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
951b58b6676SHariprasad Shenai 	seq_printf(seq, "Initial SRTT: %llu us\n",
952b58b6676SHariprasad Shenai 		   tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
953b58b6676SHariprasad Shenai 	seq_printf(seq, "FINWAIT2 timer: %llu us\n",
954b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
955b58b6676SHariprasad Shenai 
956b58b6676SHariprasad Shenai 	return 0;
957b58b6676SHariprasad Shenai }
958b58b6676SHariprasad Shenai 
959b58b6676SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(clk);
960b58b6676SHariprasad Shenai 
961f1ff24aaSHariprasad Shenai /* Firmware Device Log dump. */
96249aa284fSHariprasad Shenai static const char * const devlog_level_strings[] = {
96349aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_EMERG]		= "EMERG",
96449aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_CRIT]		= "CRIT",
96549aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_ERR]		= "ERR",
96649aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_NOTICE]	= "NOTICE",
96749aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_INFO]		= "INFO",
96849aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_DEBUG]		= "DEBUG"
96949aa284fSHariprasad Shenai };
97049aa284fSHariprasad Shenai 
97149aa284fSHariprasad Shenai static const char * const devlog_facility_strings[] = {
97249aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_CORE]	= "CORE",
973da4976e1SHariprasad Shenai 	[FW_DEVLOG_FACILITY_CF]         = "CF",
97449aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_SCHED]	= "SCHED",
97549aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_TIMER]	= "TIMER",
97649aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_RES]	= "RES",
97749aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_HW]		= "HW",
97849aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FLR]	= "FLR",
97949aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_DMAQ]	= "DMAQ",
98049aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_PHY]	= "PHY",
98149aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_MAC]	= "MAC",
98249aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_PORT]	= "PORT",
98349aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_VI]		= "VI",
98449aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FILTER]	= "FILTER",
98549aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ACL]	= "ACL",
98649aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_TM]		= "TM",
98749aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_QFC]	= "QFC",
98849aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_DCB]	= "DCB",
98949aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ETH]	= "ETH",
99049aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_OFLD]	= "OFLD",
99149aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_RI]		= "RI",
99249aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ISCSI]	= "ISCSI",
99349aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FCOE]	= "FCOE",
99449aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FOISCSI]	= "FOISCSI",
99549aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FOFCOE]	= "FOFCOE"
99649aa284fSHariprasad Shenai };
99749aa284fSHariprasad Shenai 
99849aa284fSHariprasad Shenai /* Information gathered by Device Log Open routine for the display routine.
99949aa284fSHariprasad Shenai  */
100049aa284fSHariprasad Shenai struct devlog_info {
100149aa284fSHariprasad Shenai 	unsigned int nentries;		/* number of entries in log[] */
100249aa284fSHariprasad Shenai 	unsigned int first;		/* first [temporal] entry in log[] */
100349aa284fSHariprasad Shenai 	struct fw_devlog_e log[0];	/* Firmware Device Log */
100449aa284fSHariprasad Shenai };
100549aa284fSHariprasad Shenai 
100649aa284fSHariprasad Shenai /* Dump a Firmaware Device Log entry.
100749aa284fSHariprasad Shenai  */
100849aa284fSHariprasad Shenai static int devlog_show(struct seq_file *seq, void *v)
100949aa284fSHariprasad Shenai {
101049aa284fSHariprasad Shenai 	if (v == SEQ_START_TOKEN)
101149aa284fSHariprasad Shenai 		seq_printf(seq, "%10s  %15s  %8s  %8s  %s\n",
101249aa284fSHariprasad Shenai 			   "Seq#", "Tstamp", "Level", "Facility", "Message");
101349aa284fSHariprasad Shenai 	else {
101449aa284fSHariprasad Shenai 		struct devlog_info *dinfo = seq->private;
101549aa284fSHariprasad Shenai 		int fidx = (uintptr_t)v - 2;
101649aa284fSHariprasad Shenai 		unsigned long index;
101749aa284fSHariprasad Shenai 		struct fw_devlog_e *e;
101849aa284fSHariprasad Shenai 
101949aa284fSHariprasad Shenai 		/* Get a pointer to the log entry to display.  Skip unused log
102049aa284fSHariprasad Shenai 		 * entries.
102149aa284fSHariprasad Shenai 		 */
102249aa284fSHariprasad Shenai 		index = dinfo->first + fidx;
102349aa284fSHariprasad Shenai 		if (index >= dinfo->nentries)
102449aa284fSHariprasad Shenai 			index -= dinfo->nentries;
102549aa284fSHariprasad Shenai 		e = &dinfo->log[index];
102649aa284fSHariprasad Shenai 		if (e->timestamp == 0)
102749aa284fSHariprasad Shenai 			return 0;
102849aa284fSHariprasad Shenai 
102949aa284fSHariprasad Shenai 		/* Print the message.  This depends on the firmware using
103049aa284fSHariprasad Shenai 		 * exactly the same formating strings as the kernel so we may
103149aa284fSHariprasad Shenai 		 * eventually have to put a format interpreter in here ...
103249aa284fSHariprasad Shenai 		 */
103349aa284fSHariprasad Shenai 		seq_printf(seq, "%10d  %15llu  %8s  %8s  ",
1034fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->seqno),
1035fda8b18cSHariprasad Shenai 			   be64_to_cpu(e->timestamp),
103649aa284fSHariprasad Shenai 			   (e->level < ARRAY_SIZE(devlog_level_strings)
103749aa284fSHariprasad Shenai 			    ? devlog_level_strings[e->level]
103849aa284fSHariprasad Shenai 			    : "UNKNOWN"),
103949aa284fSHariprasad Shenai 			   (e->facility < ARRAY_SIZE(devlog_facility_strings)
104049aa284fSHariprasad Shenai 			    ? devlog_facility_strings[e->facility]
104149aa284fSHariprasad Shenai 			    : "UNKNOWN"));
1042fda8b18cSHariprasad Shenai 		seq_printf(seq, e->fmt,
1043fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[0]),
1044fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[1]),
1045fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[2]),
1046fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[3]),
1047fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[4]),
1048fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[5]),
1049fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[6]),
1050fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[7]));
105149aa284fSHariprasad Shenai 	}
105249aa284fSHariprasad Shenai 	return 0;
105349aa284fSHariprasad Shenai }
105449aa284fSHariprasad Shenai 
105549aa284fSHariprasad Shenai /* Sequential File Operations for Device Log.
105649aa284fSHariprasad Shenai  */
105749aa284fSHariprasad Shenai static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
105849aa284fSHariprasad Shenai {
105949aa284fSHariprasad Shenai 	if (pos > dinfo->nentries)
106049aa284fSHariprasad Shenai 		return NULL;
106149aa284fSHariprasad Shenai 
106249aa284fSHariprasad Shenai 	return (void *)(uintptr_t)(pos + 1);
106349aa284fSHariprasad Shenai }
106449aa284fSHariprasad Shenai 
106549aa284fSHariprasad Shenai static void *devlog_start(struct seq_file *seq, loff_t *pos)
106649aa284fSHariprasad Shenai {
106749aa284fSHariprasad Shenai 	struct devlog_info *dinfo = seq->private;
106849aa284fSHariprasad Shenai 
106949aa284fSHariprasad Shenai 	return (*pos
107049aa284fSHariprasad Shenai 		? devlog_get_idx(dinfo, *pos)
107149aa284fSHariprasad Shenai 		: SEQ_START_TOKEN);
107249aa284fSHariprasad Shenai }
107349aa284fSHariprasad Shenai 
107449aa284fSHariprasad Shenai static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
107549aa284fSHariprasad Shenai {
107649aa284fSHariprasad Shenai 	struct devlog_info *dinfo = seq->private;
107749aa284fSHariprasad Shenai 
107849aa284fSHariprasad Shenai 	(*pos)++;
107949aa284fSHariprasad Shenai 	return devlog_get_idx(dinfo, *pos);
108049aa284fSHariprasad Shenai }
108149aa284fSHariprasad Shenai 
108249aa284fSHariprasad Shenai static void devlog_stop(struct seq_file *seq, void *v)
108349aa284fSHariprasad Shenai {
108449aa284fSHariprasad Shenai }
108549aa284fSHariprasad Shenai 
108649aa284fSHariprasad Shenai static const struct seq_operations devlog_seq_ops = {
108749aa284fSHariprasad Shenai 	.start = devlog_start,
108849aa284fSHariprasad Shenai 	.next  = devlog_next,
108949aa284fSHariprasad Shenai 	.stop  = devlog_stop,
109049aa284fSHariprasad Shenai 	.show  = devlog_show
109149aa284fSHariprasad Shenai };
109249aa284fSHariprasad Shenai 
109349aa284fSHariprasad Shenai /* Set up for reading the firmware's device log.  We read the entire log here
109449aa284fSHariprasad Shenai  * and then display it incrementally in devlog_show().
109549aa284fSHariprasad Shenai  */
109649aa284fSHariprasad Shenai static int devlog_open(struct inode *inode, struct file *file)
109749aa284fSHariprasad Shenai {
109849aa284fSHariprasad Shenai 	struct adapter *adap = inode->i_private;
109949aa284fSHariprasad Shenai 	struct devlog_params *dparams = &adap->params.devlog;
110049aa284fSHariprasad Shenai 	struct devlog_info *dinfo;
110149aa284fSHariprasad Shenai 	unsigned int index;
110249aa284fSHariprasad Shenai 	u32 fseqno;
110349aa284fSHariprasad Shenai 	int ret;
110449aa284fSHariprasad Shenai 
110549aa284fSHariprasad Shenai 	/* If we don't know where the log is we can't do anything.
110649aa284fSHariprasad Shenai 	 */
110749aa284fSHariprasad Shenai 	if (dparams->start == 0)
110849aa284fSHariprasad Shenai 		return -ENXIO;
110949aa284fSHariprasad Shenai 
111049aa284fSHariprasad Shenai 	/* Allocate the space to read in the firmware's device log and set up
111149aa284fSHariprasad Shenai 	 * for the iterated call to our display function.
111249aa284fSHariprasad Shenai 	 */
111349aa284fSHariprasad Shenai 	dinfo = __seq_open_private(file, &devlog_seq_ops,
111449aa284fSHariprasad Shenai 				   sizeof(*dinfo) + dparams->size);
111549aa284fSHariprasad Shenai 	if (!dinfo)
111649aa284fSHariprasad Shenai 		return -ENOMEM;
111749aa284fSHariprasad Shenai 
111849aa284fSHariprasad Shenai 	/* Record the basic log buffer information and read in the raw log.
111949aa284fSHariprasad Shenai 	 */
112049aa284fSHariprasad Shenai 	dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
112149aa284fSHariprasad Shenai 	dinfo->first = 0;
112249aa284fSHariprasad Shenai 	spin_lock(&adap->win0_lock);
112349aa284fSHariprasad Shenai 	ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
112449aa284fSHariprasad Shenai 			   dparams->start, dparams->size, (__be32 *)dinfo->log,
112549aa284fSHariprasad Shenai 			   T4_MEMORY_READ);
112649aa284fSHariprasad Shenai 	spin_unlock(&adap->win0_lock);
112749aa284fSHariprasad Shenai 	if (ret) {
112849aa284fSHariprasad Shenai 		seq_release_private(inode, file);
112949aa284fSHariprasad Shenai 		return ret;
113049aa284fSHariprasad Shenai 	}
113149aa284fSHariprasad Shenai 
1132fda8b18cSHariprasad Shenai 	/* Find the earliest (lowest Sequence Number) log entry in the
1133fda8b18cSHariprasad Shenai 	 * circular Device Log.
113449aa284fSHariprasad Shenai 	 */
113549aa284fSHariprasad Shenai 	for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
113649aa284fSHariprasad Shenai 		struct fw_devlog_e *e = &dinfo->log[index];
113749aa284fSHariprasad Shenai 		__u32 seqno;
113849aa284fSHariprasad Shenai 
113949aa284fSHariprasad Shenai 		if (e->timestamp == 0)
114049aa284fSHariprasad Shenai 			continue;
114149aa284fSHariprasad Shenai 
114249aa284fSHariprasad Shenai 		seqno = be32_to_cpu(e->seqno);
114349aa284fSHariprasad Shenai 		if (seqno < fseqno) {
114449aa284fSHariprasad Shenai 			fseqno = seqno;
114549aa284fSHariprasad Shenai 			dinfo->first = index;
114649aa284fSHariprasad Shenai 		}
114749aa284fSHariprasad Shenai 	}
114849aa284fSHariprasad Shenai 	return 0;
114949aa284fSHariprasad Shenai }
115049aa284fSHariprasad Shenai 
115149aa284fSHariprasad Shenai static const struct file_operations devlog_fops = {
115249aa284fSHariprasad Shenai 	.owner   = THIS_MODULE,
115349aa284fSHariprasad Shenai 	.open    = devlog_open,
115449aa284fSHariprasad Shenai 	.read    = seq_read,
115549aa284fSHariprasad Shenai 	.llseek  = seq_lseek,
115649aa284fSHariprasad Shenai 	.release = seq_release_private
115749aa284fSHariprasad Shenai };
115849aa284fSHariprasad Shenai 
11597f080c3fSHariprasad Shenai /* Show Firmware Mailbox Command/Reply Log
11607f080c3fSHariprasad Shenai  *
11617f080c3fSHariprasad Shenai  * Note that we don't do any locking when dumping the Firmware Mailbox Log so
11627f080c3fSHariprasad Shenai  * it's possible that we can catch things during a log update and therefore
11637f080c3fSHariprasad Shenai  * see partially corrupted log entries.  But it's probably Good Enough(tm).
11647f080c3fSHariprasad Shenai  * If we ever decide that we want to make sure that we're dumping a coherent
11657f080c3fSHariprasad Shenai  * log, we'd need to perform locking in the mailbox logging and in
11667f080c3fSHariprasad Shenai  * mboxlog_open() where we'd need to grab the entire mailbox log in one go
11677f080c3fSHariprasad Shenai  * like we do for the Firmware Device Log.
11687f080c3fSHariprasad Shenai  */
11697f080c3fSHariprasad Shenai static int mboxlog_show(struct seq_file *seq, void *v)
11707f080c3fSHariprasad Shenai {
11717f080c3fSHariprasad Shenai 	struct adapter *adapter = seq->private;
11727f080c3fSHariprasad Shenai 	struct mbox_cmd_log *log = adapter->mbox_log;
11737f080c3fSHariprasad Shenai 	struct mbox_cmd *entry;
11747f080c3fSHariprasad Shenai 	int entry_idx, i;
11757f080c3fSHariprasad Shenai 
11767f080c3fSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
11777f080c3fSHariprasad Shenai 		seq_printf(seq,
11787f080c3fSHariprasad Shenai 			   "%10s  %15s  %5s  %5s  %s\n",
11797f080c3fSHariprasad Shenai 			   "Seq#", "Tstamp", "Atime", "Etime",
11807f080c3fSHariprasad Shenai 			   "Command/Reply");
11817f080c3fSHariprasad Shenai 		return 0;
11827f080c3fSHariprasad Shenai 	}
11837f080c3fSHariprasad Shenai 
11847f080c3fSHariprasad Shenai 	entry_idx = log->cursor + ((uintptr_t)v - 2);
11857f080c3fSHariprasad Shenai 	if (entry_idx >= log->size)
11867f080c3fSHariprasad Shenai 		entry_idx -= log->size;
11877f080c3fSHariprasad Shenai 	entry = mbox_cmd_log_entry(log, entry_idx);
11887f080c3fSHariprasad Shenai 
11897f080c3fSHariprasad Shenai 	/* skip over unused entries */
11907f080c3fSHariprasad Shenai 	if (entry->timestamp == 0)
11917f080c3fSHariprasad Shenai 		return 0;
11927f080c3fSHariprasad Shenai 
11937f080c3fSHariprasad Shenai 	seq_printf(seq, "%10u  %15llu  %5d  %5d",
11947f080c3fSHariprasad Shenai 		   entry->seqno, entry->timestamp,
11957f080c3fSHariprasad Shenai 		   entry->access, entry->execute);
11967f080c3fSHariprasad Shenai 	for (i = 0; i < MBOX_LEN / 8; i++) {
11977f080c3fSHariprasad Shenai 		u64 flit = entry->cmd[i];
11987f080c3fSHariprasad Shenai 		u32 hi = (u32)(flit >> 32);
11997f080c3fSHariprasad Shenai 		u32 lo = (u32)flit;
12007f080c3fSHariprasad Shenai 
12017f080c3fSHariprasad Shenai 		seq_printf(seq, "  %08x %08x", hi, lo);
12027f080c3fSHariprasad Shenai 	}
12037f080c3fSHariprasad Shenai 	seq_puts(seq, "\n");
12047f080c3fSHariprasad Shenai 	return 0;
12057f080c3fSHariprasad Shenai }
12067f080c3fSHariprasad Shenai 
12077f080c3fSHariprasad Shenai static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
12087f080c3fSHariprasad Shenai {
12097f080c3fSHariprasad Shenai 	struct adapter *adapter = seq->private;
12107f080c3fSHariprasad Shenai 	struct mbox_cmd_log *log = adapter->mbox_log;
12117f080c3fSHariprasad Shenai 
12127f080c3fSHariprasad Shenai 	return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
12137f080c3fSHariprasad Shenai }
12147f080c3fSHariprasad Shenai 
12157f080c3fSHariprasad Shenai static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
12167f080c3fSHariprasad Shenai {
12177f080c3fSHariprasad Shenai 	return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
12187f080c3fSHariprasad Shenai }
12197f080c3fSHariprasad Shenai 
12207f080c3fSHariprasad Shenai static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
12217f080c3fSHariprasad Shenai {
12227f080c3fSHariprasad Shenai 	++*pos;
12237f080c3fSHariprasad Shenai 	return mboxlog_get_idx(seq, *pos);
12247f080c3fSHariprasad Shenai }
12257f080c3fSHariprasad Shenai 
12267f080c3fSHariprasad Shenai static void mboxlog_stop(struct seq_file *seq, void *v)
12277f080c3fSHariprasad Shenai {
12287f080c3fSHariprasad Shenai }
12297f080c3fSHariprasad Shenai 
12307f080c3fSHariprasad Shenai static const struct seq_operations mboxlog_seq_ops = {
12317f080c3fSHariprasad Shenai 	.start = mboxlog_start,
12327f080c3fSHariprasad Shenai 	.next  = mboxlog_next,
12337f080c3fSHariprasad Shenai 	.stop  = mboxlog_stop,
12347f080c3fSHariprasad Shenai 	.show  = mboxlog_show
12357f080c3fSHariprasad Shenai };
12367f080c3fSHariprasad Shenai 
12377f080c3fSHariprasad Shenai static int mboxlog_open(struct inode *inode, struct file *file)
12387f080c3fSHariprasad Shenai {
12397f080c3fSHariprasad Shenai 	int res = seq_open(file, &mboxlog_seq_ops);
12407f080c3fSHariprasad Shenai 
12417f080c3fSHariprasad Shenai 	if (!res) {
12427f080c3fSHariprasad Shenai 		struct seq_file *seq = file->private_data;
12437f080c3fSHariprasad Shenai 
12447f080c3fSHariprasad Shenai 		seq->private = inode->i_private;
12457f080c3fSHariprasad Shenai 	}
12467f080c3fSHariprasad Shenai 	return res;
12477f080c3fSHariprasad Shenai }
12487f080c3fSHariprasad Shenai 
12497f080c3fSHariprasad Shenai static const struct file_operations mboxlog_fops = {
12507f080c3fSHariprasad Shenai 	.owner   = THIS_MODULE,
12517f080c3fSHariprasad Shenai 	.open    = mboxlog_open,
12527f080c3fSHariprasad Shenai 	.read    = seq_read,
12537f080c3fSHariprasad Shenai 	.llseek  = seq_lseek,
12547f080c3fSHariprasad Shenai 	.release = seq_release,
12557f080c3fSHariprasad Shenai };
12567f080c3fSHariprasad Shenai 
1257bf7c781dSHariprasad Shenai static int mbox_show(struct seq_file *seq, void *v)
1258bf7c781dSHariprasad Shenai {
1259bf7c781dSHariprasad Shenai 	static const char * const owner[] = { "none", "FW", "driver",
1260b3695540SHariprasad Shenai 					      "unknown", "<unread>" };
1261bf7c781dSHariprasad Shenai 
1262bf7c781dSHariprasad Shenai 	int i;
1263bf7c781dSHariprasad Shenai 	unsigned int mbox = (uintptr_t)seq->private & 7;
1264bf7c781dSHariprasad Shenai 	struct adapter *adap = seq->private - mbox;
1265bf7c781dSHariprasad Shenai 	void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1266b3695540SHariprasad Shenai 
1267b3695540SHariprasad Shenai 	/* For T4 we don't have a shadow copy of the Mailbox Control register.
1268b3695540SHariprasad Shenai 	 * And since reading that real register causes a side effect of
1269b3695540SHariprasad Shenai 	 * granting ownership, we're best of simply not reading it at all.
1270b3695540SHariprasad Shenai 	 */
1271b3695540SHariprasad Shenai 	if (is_t4(adap->params.chip)) {
1272b3695540SHariprasad Shenai 		i = 4; /* index of "<unread>" */
1273b3695540SHariprasad Shenai 	} else {
1274b3695540SHariprasad Shenai 		unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
1275bf7c781dSHariprasad Shenai 		void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
1276bf7c781dSHariprasad Shenai 
1277bf7c781dSHariprasad Shenai 		i = MBOWNER_G(readl(ctrl));
1278b3695540SHariprasad Shenai 	}
1279b3695540SHariprasad Shenai 
1280bf7c781dSHariprasad Shenai 	seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
1281bf7c781dSHariprasad Shenai 
1282bf7c781dSHariprasad Shenai 	for (i = 0; i < MBOX_LEN; i += 8)
1283bf7c781dSHariprasad Shenai 		seq_printf(seq, "%016llx\n",
1284bf7c781dSHariprasad Shenai 			   (unsigned long long)readq(addr + i));
1285bf7c781dSHariprasad Shenai 	return 0;
1286bf7c781dSHariprasad Shenai }
1287bf7c781dSHariprasad Shenai 
1288bf7c781dSHariprasad Shenai static int mbox_open(struct inode *inode, struct file *file)
1289bf7c781dSHariprasad Shenai {
1290bf7c781dSHariprasad Shenai 	return single_open(file, mbox_show, inode->i_private);
1291bf7c781dSHariprasad Shenai }
1292bf7c781dSHariprasad Shenai 
1293bf7c781dSHariprasad Shenai static ssize_t mbox_write(struct file *file, const char __user *buf,
1294bf7c781dSHariprasad Shenai 			  size_t count, loff_t *pos)
1295bf7c781dSHariprasad Shenai {
1296bf7c781dSHariprasad Shenai 	int i;
1297bf7c781dSHariprasad Shenai 	char c = '\n', s[256];
1298bf7c781dSHariprasad Shenai 	unsigned long long data[8];
1299bf7c781dSHariprasad Shenai 	const struct inode *ino;
1300bf7c781dSHariprasad Shenai 	unsigned int mbox;
1301bf7c781dSHariprasad Shenai 	struct adapter *adap;
1302bf7c781dSHariprasad Shenai 	void __iomem *addr;
1303bf7c781dSHariprasad Shenai 	void __iomem *ctrl;
1304bf7c781dSHariprasad Shenai 
1305bf7c781dSHariprasad Shenai 	if (count > sizeof(s) - 1 || !count)
1306bf7c781dSHariprasad Shenai 		return -EINVAL;
1307bf7c781dSHariprasad Shenai 	if (copy_from_user(s, buf, count))
1308bf7c781dSHariprasad Shenai 		return -EFAULT;
1309bf7c781dSHariprasad Shenai 	s[count] = '\0';
1310bf7c781dSHariprasad Shenai 
1311bf7c781dSHariprasad Shenai 	if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
1312bf7c781dSHariprasad Shenai 		   &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
1313bf7c781dSHariprasad Shenai 		   &data[7], &c) < 8 || c != '\n')
1314bf7c781dSHariprasad Shenai 		return -EINVAL;
1315bf7c781dSHariprasad Shenai 
1316c1d81b1cSDavid Howells 	ino = file_inode(file);
1317bf7c781dSHariprasad Shenai 	mbox = (uintptr_t)ino->i_private & 7;
1318bf7c781dSHariprasad Shenai 	adap = ino->i_private - mbox;
1319bf7c781dSHariprasad Shenai 	addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1320bf7c781dSHariprasad Shenai 	ctrl = addr + MBOX_LEN;
1321bf7c781dSHariprasad Shenai 
1322bf7c781dSHariprasad Shenai 	if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
1323bf7c781dSHariprasad Shenai 		return -EBUSY;
1324bf7c781dSHariprasad Shenai 
1325bf7c781dSHariprasad Shenai 	for (i = 0; i < 8; i++)
1326bf7c781dSHariprasad Shenai 		writeq(data[i], addr + 8 * i);
1327bf7c781dSHariprasad Shenai 
1328bf7c781dSHariprasad Shenai 	writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
1329bf7c781dSHariprasad Shenai 	return count;
1330bf7c781dSHariprasad Shenai }
1331bf7c781dSHariprasad Shenai 
1332bf7c781dSHariprasad Shenai static const struct file_operations mbox_debugfs_fops = {
1333bf7c781dSHariprasad Shenai 	.owner   = THIS_MODULE,
1334bf7c781dSHariprasad Shenai 	.open    = mbox_open,
1335bf7c781dSHariprasad Shenai 	.read    = seq_read,
1336bf7c781dSHariprasad Shenai 	.llseek  = seq_lseek,
1337bf7c781dSHariprasad Shenai 	.release = single_release,
1338bf7c781dSHariprasad Shenai 	.write   = mbox_write
1339bf7c781dSHariprasad Shenai };
1340bf7c781dSHariprasad Shenai 
13418e3d04fdSHariprasad Shenai static int mps_trc_show(struct seq_file *seq, void *v)
13428e3d04fdSHariprasad Shenai {
13438e3d04fdSHariprasad Shenai 	int enabled, i;
13448e3d04fdSHariprasad Shenai 	struct trace_params tp;
13458e3d04fdSHariprasad Shenai 	unsigned int trcidx = (uintptr_t)seq->private & 3;
13468e3d04fdSHariprasad Shenai 	struct adapter *adap = seq->private - trcidx;
13478e3d04fdSHariprasad Shenai 
13488e3d04fdSHariprasad Shenai 	t4_get_trace_filter(adap, &tp, trcidx, &enabled);
13498e3d04fdSHariprasad Shenai 	if (!enabled) {
13508e3d04fdSHariprasad Shenai 		seq_puts(seq, "tracer is disabled\n");
13518e3d04fdSHariprasad Shenai 		return 0;
13528e3d04fdSHariprasad Shenai 	}
13538e3d04fdSHariprasad Shenai 
13548e3d04fdSHariprasad Shenai 	if (tp.skip_ofst * 8 >= TRACE_LEN) {
13558e3d04fdSHariprasad Shenai 		dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
13568e3d04fdSHariprasad Shenai 		return -EINVAL;
13578e3d04fdSHariprasad Shenai 	}
13588e3d04fdSHariprasad Shenai 	if (tp.port < 8) {
13598e3d04fdSHariprasad Shenai 		i = adap->chan_map[tp.port & 3];
13608e3d04fdSHariprasad Shenai 		if (i >= MAX_NPORTS) {
13618e3d04fdSHariprasad Shenai 			dev_err(adap->pdev_dev, "tracer %u is assigned "
13628e3d04fdSHariprasad Shenai 				"to non-existing port\n", trcidx);
13638e3d04fdSHariprasad Shenai 			return -EINVAL;
13648e3d04fdSHariprasad Shenai 		}
13658e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing %s %s, ",
13668e3d04fdSHariprasad Shenai 			   adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
13678e3d04fdSHariprasad Shenai 	} else
13688e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing loopback %d, ",
13698e3d04fdSHariprasad Shenai 			   tp.port - 8);
13708e3d04fdSHariprasad Shenai 	seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
13718e3d04fdSHariprasad Shenai 		   tp.min_len);
13728e3d04fdSHariprasad Shenai 	seq_printf(seq, "packets captured %smatch filter\n",
13738e3d04fdSHariprasad Shenai 		   tp.invert ? "do not " : "");
13748e3d04fdSHariprasad Shenai 
13758e3d04fdSHariprasad Shenai 	if (tp.skip_ofst) {
13768e3d04fdSHariprasad Shenai 		seq_puts(seq, "filter pattern: ");
13778e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
13788e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
13798e3d04fdSHariprasad Shenai 		seq_putc(seq, '/');
13808e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
13818e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
13828e3d04fdSHariprasad Shenai 		seq_puts(seq, "@0\n");
13838e3d04fdSHariprasad Shenai 	}
13848e3d04fdSHariprasad Shenai 
13858e3d04fdSHariprasad Shenai 	seq_puts(seq, "filter pattern: ");
13868e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
13878e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
13888e3d04fdSHariprasad Shenai 	seq_putc(seq, '/');
13898e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
13908e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
13918e3d04fdSHariprasad Shenai 	seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
13928e3d04fdSHariprasad Shenai 	return 0;
13938e3d04fdSHariprasad Shenai }
13948e3d04fdSHariprasad Shenai 
13958e3d04fdSHariprasad Shenai static int mps_trc_open(struct inode *inode, struct file *file)
13968e3d04fdSHariprasad Shenai {
13978e3d04fdSHariprasad Shenai 	return single_open(file, mps_trc_show, inode->i_private);
13988e3d04fdSHariprasad Shenai }
13998e3d04fdSHariprasad Shenai 
14008e3d04fdSHariprasad Shenai static unsigned int xdigit2int(unsigned char c)
14018e3d04fdSHariprasad Shenai {
14028e3d04fdSHariprasad Shenai 	return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
14038e3d04fdSHariprasad Shenai }
14048e3d04fdSHariprasad Shenai 
14058e3d04fdSHariprasad Shenai #define TRC_PORT_NONE 0xff
14068e3d04fdSHariprasad Shenai #define TRC_RSS_ENABLE 0x33
14078e3d04fdSHariprasad Shenai #define TRC_RSS_DISABLE 0x13
14088e3d04fdSHariprasad Shenai 
14098e3d04fdSHariprasad Shenai /* Set an MPS trace filter.  Syntax is:
14108e3d04fdSHariprasad Shenai  *
14118e3d04fdSHariprasad Shenai  * disable
14128e3d04fdSHariprasad Shenai  *
14138e3d04fdSHariprasad Shenai  * to disable tracing, or
14148e3d04fdSHariprasad Shenai  *
14158e3d04fdSHariprasad Shenai  * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
14168e3d04fdSHariprasad Shenai  *
14178e3d04fdSHariprasad Shenai  * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
14188e3d04fdSHariprasad Shenai  * of the NIC's response qid obtained from sge_qinfo and pattern has the form
14198e3d04fdSHariprasad Shenai  *
14208e3d04fdSHariprasad Shenai  * <pattern data>[/<pattern mask>][@<anchor>]
14218e3d04fdSHariprasad Shenai  *
14228e3d04fdSHariprasad Shenai  * Up to 2 filter patterns can be specified.  If 2 are supplied the first one
14230cf2a848SMasahiro Yamada  * must be anchored at 0.  An omitted mask is taken as a mask of 1s, an omitted
14248e3d04fdSHariprasad Shenai  * anchor is taken as 0.
14258e3d04fdSHariprasad Shenai  */
14268e3d04fdSHariprasad Shenai static ssize_t mps_trc_write(struct file *file, const char __user *buf,
14278e3d04fdSHariprasad Shenai 			     size_t count, loff_t *pos)
14288e3d04fdSHariprasad Shenai {
1429c938a003SDan Carpenter 	int i, enable, ret;
14308e3d04fdSHariprasad Shenai 	u32 *data, *mask;
14318e3d04fdSHariprasad Shenai 	struct trace_params tp;
14328e3d04fdSHariprasad Shenai 	const struct inode *ino;
14338e3d04fdSHariprasad Shenai 	unsigned int trcidx;
14348e3d04fdSHariprasad Shenai 	char *s, *p, *word, *end;
14358e3d04fdSHariprasad Shenai 	struct adapter *adap;
1436c938a003SDan Carpenter 	u32 j;
14378e3d04fdSHariprasad Shenai 
14388e3d04fdSHariprasad Shenai 	ino = file_inode(file);
14398e3d04fdSHariprasad Shenai 	trcidx = (uintptr_t)ino->i_private & 3;
14408e3d04fdSHariprasad Shenai 	adap = ino->i_private - trcidx;
14418e3d04fdSHariprasad Shenai 
14428e3d04fdSHariprasad Shenai 	/* Don't accept input more than 1K, can't be anything valid except lots
14438e3d04fdSHariprasad Shenai 	 * of whitespace.  Well, use less.
14448e3d04fdSHariprasad Shenai 	 */
14458e3d04fdSHariprasad Shenai 	if (count > 1024)
14468e3d04fdSHariprasad Shenai 		return -EFBIG;
14478e3d04fdSHariprasad Shenai 	p = s = kzalloc(count + 1, GFP_USER);
14488e3d04fdSHariprasad Shenai 	if (!s)
14498e3d04fdSHariprasad Shenai 		return -ENOMEM;
14508e3d04fdSHariprasad Shenai 	if (copy_from_user(s, buf, count)) {
14518e3d04fdSHariprasad Shenai 		count = -EFAULT;
14528e3d04fdSHariprasad Shenai 		goto out;
14538e3d04fdSHariprasad Shenai 	}
14548e3d04fdSHariprasad Shenai 
14558e3d04fdSHariprasad Shenai 	if (s[count - 1] == '\n')
14568e3d04fdSHariprasad Shenai 		s[count - 1] = '\0';
14578e3d04fdSHariprasad Shenai 
14588e3d04fdSHariprasad Shenai 	enable = strcmp("disable", s) != 0;
14598e3d04fdSHariprasad Shenai 	if (!enable)
14608e3d04fdSHariprasad Shenai 		goto apply;
14618e3d04fdSHariprasad Shenai 
14628e3d04fdSHariprasad Shenai 	/* enable or disable trace multi rss filter */
14638e3d04fdSHariprasad Shenai 	if (adap->trace_rss)
14648e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
14658e3d04fdSHariprasad Shenai 	else
14668e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
14678e3d04fdSHariprasad Shenai 
14688e3d04fdSHariprasad Shenai 	memset(&tp, 0, sizeof(tp));
14698e3d04fdSHariprasad Shenai 	tp.port = TRC_PORT_NONE;
14708e3d04fdSHariprasad Shenai 	i = 0;	/* counts pattern nibbles */
14718e3d04fdSHariprasad Shenai 
14728e3d04fdSHariprasad Shenai 	while (p) {
14738e3d04fdSHariprasad Shenai 		while (isspace(*p))
14748e3d04fdSHariprasad Shenai 			p++;
14758e3d04fdSHariprasad Shenai 		word = strsep(&p, " ");
14768e3d04fdSHariprasad Shenai 		if (!*word)
14778e3d04fdSHariprasad Shenai 			break;
14788e3d04fdSHariprasad Shenai 
14798e3d04fdSHariprasad Shenai 		if (!strncmp(word, "qid=", 4)) {
14808e3d04fdSHariprasad Shenai 			end = (char *)word + 4;
1481c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
14828e3d04fdSHariprasad Shenai 			if (ret)
14838e3d04fdSHariprasad Shenai 				goto out;
14848e3d04fdSHariprasad Shenai 			if (!adap->trace_rss) {
14858e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
14868e3d04fdSHariprasad Shenai 				continue;
14878e3d04fdSHariprasad Shenai 			}
14888e3d04fdSHariprasad Shenai 
14898e3d04fdSHariprasad Shenai 			switch (trcidx) {
14908e3d04fdSHariprasad Shenai 			case 0:
14918e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
14928e3d04fdSHariprasad Shenai 				break;
14938e3d04fdSHariprasad Shenai 			case 1:
14948e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14958e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER1_RSS_CONTROL_A, j);
14968e3d04fdSHariprasad Shenai 				break;
14978e3d04fdSHariprasad Shenai 			case 2:
14988e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14998e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER2_RSS_CONTROL_A, j);
15008e3d04fdSHariprasad Shenai 				break;
15018e3d04fdSHariprasad Shenai 			case 3:
15028e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
15038e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER3_RSS_CONTROL_A, j);
15048e3d04fdSHariprasad Shenai 				break;
15058e3d04fdSHariprasad Shenai 			}
15068e3d04fdSHariprasad Shenai 			continue;
15078e3d04fdSHariprasad Shenai 		}
15088e3d04fdSHariprasad Shenai 		if (!strncmp(word, "snaplen=", 8)) {
15098e3d04fdSHariprasad Shenai 			end = (char *)word + 8;
1510c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15118e3d04fdSHariprasad Shenai 			if (ret || j > 9600) {
15128e3d04fdSHariprasad Shenai inval:				count = -EINVAL;
15138e3d04fdSHariprasad Shenai 				goto out;
15148e3d04fdSHariprasad Shenai 			}
15158e3d04fdSHariprasad Shenai 			tp.snap_len = j;
15168e3d04fdSHariprasad Shenai 			continue;
15178e3d04fdSHariprasad Shenai 		}
15188e3d04fdSHariprasad Shenai 		if (!strncmp(word, "minlen=", 7)) {
15198e3d04fdSHariprasad Shenai 			end = (char *)word + 7;
1520c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15218e3d04fdSHariprasad Shenai 			if (ret || j > TFMINPKTSIZE_M)
15228e3d04fdSHariprasad Shenai 				goto inval;
15238e3d04fdSHariprasad Shenai 			tp.min_len = j;
15248e3d04fdSHariprasad Shenai 			continue;
15258e3d04fdSHariprasad Shenai 		}
15268e3d04fdSHariprasad Shenai 		if (!strcmp(word, "not")) {
15278e3d04fdSHariprasad Shenai 			tp.invert = !tp.invert;
15288e3d04fdSHariprasad Shenai 			continue;
15298e3d04fdSHariprasad Shenai 		}
15308e3d04fdSHariprasad Shenai 		if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
15318e3d04fdSHariprasad Shenai 			if (word[8] < '0' || word[8] > '3' || word[9])
15328e3d04fdSHariprasad Shenai 				goto inval;
15338e3d04fdSHariprasad Shenai 			tp.port = word[8] - '0' + 8;
15348e3d04fdSHariprasad Shenai 			continue;
15358e3d04fdSHariprasad Shenai 		}
15368e3d04fdSHariprasad Shenai 		if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
15378e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
15388e3d04fdSHariprasad Shenai 				goto inval;
15398e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0' + 4;
15408e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
15418e3d04fdSHariprasad Shenai 				goto inval;
15428e3d04fdSHariprasad Shenai 			continue;
15438e3d04fdSHariprasad Shenai 		}
15448e3d04fdSHariprasad Shenai 		if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
15458e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
15468e3d04fdSHariprasad Shenai 				goto inval;
15478e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0';
15488e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port] >= MAX_NPORTS)
15498e3d04fdSHariprasad Shenai 				goto inval;
15508e3d04fdSHariprasad Shenai 			continue;
15518e3d04fdSHariprasad Shenai 		}
15528e3d04fdSHariprasad Shenai 		if (!isxdigit(*word))
15538e3d04fdSHariprasad Shenai 			goto inval;
15548e3d04fdSHariprasad Shenai 
15558e3d04fdSHariprasad Shenai 		/* we have found a trace pattern */
15568e3d04fdSHariprasad Shenai 		if (i) {                            /* split pattern */
15578e3d04fdSHariprasad Shenai 			if (tp.skip_len)            /* too many splits */
15588e3d04fdSHariprasad Shenai 				goto inval;
15598e3d04fdSHariprasad Shenai 			tp.skip_ofst = i / 16;
15608e3d04fdSHariprasad Shenai 		}
15618e3d04fdSHariprasad Shenai 
15628e3d04fdSHariprasad Shenai 		data = &tp.data[i / 8];
15638e3d04fdSHariprasad Shenai 		mask = &tp.mask[i / 8];
15648e3d04fdSHariprasad Shenai 		j = i;
15658e3d04fdSHariprasad Shenai 
15668e3d04fdSHariprasad Shenai 		while (isxdigit(*word)) {
15678e3d04fdSHariprasad Shenai 			if (i >= TRACE_LEN * 2) {
15688e3d04fdSHariprasad Shenai 				count = -EFBIG;
15698e3d04fdSHariprasad Shenai 				goto out;
15708e3d04fdSHariprasad Shenai 			}
15718e3d04fdSHariprasad Shenai 			*data = (*data << 4) + xdigit2int(*word++);
15728e3d04fdSHariprasad Shenai 			if (++i % 8 == 0)
15738e3d04fdSHariprasad Shenai 				data++;
15748e3d04fdSHariprasad Shenai 		}
15758e3d04fdSHariprasad Shenai 		if (*word == '/') {
15768e3d04fdSHariprasad Shenai 			word++;
15778e3d04fdSHariprasad Shenai 			while (isxdigit(*word)) {
15788e3d04fdSHariprasad Shenai 				if (j >= i)         /* mask longer than data */
15798e3d04fdSHariprasad Shenai 					goto inval;
15808e3d04fdSHariprasad Shenai 				*mask = (*mask << 4) + xdigit2int(*word++);
15818e3d04fdSHariprasad Shenai 				if (++j % 8 == 0)
15828e3d04fdSHariprasad Shenai 					mask++;
15838e3d04fdSHariprasad Shenai 			}
15848e3d04fdSHariprasad Shenai 			if (i != j)                 /* mask shorter than data */
15858e3d04fdSHariprasad Shenai 				goto inval;
15868e3d04fdSHariprasad Shenai 		} else {                            /* no mask, use all 1s */
15878e3d04fdSHariprasad Shenai 			for ( ; i - j >= 8; j += 8)
15888e3d04fdSHariprasad Shenai 				*mask++ = 0xffffffff;
15898e3d04fdSHariprasad Shenai 			if (i % 8)
15908e3d04fdSHariprasad Shenai 				*mask = (1 << (i % 8) * 4) - 1;
15918e3d04fdSHariprasad Shenai 		}
15928e3d04fdSHariprasad Shenai 		if (*word == '@') {
15938e3d04fdSHariprasad Shenai 			end = (char *)word + 1;
1594c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15958e3d04fdSHariprasad Shenai 			if (*end && *end != '\n')
15968e3d04fdSHariprasad Shenai 				goto inval;
15978e3d04fdSHariprasad Shenai 			if (j & 7)          /* doesn't start at multiple of 8 */
15988e3d04fdSHariprasad Shenai 				goto inval;
15998e3d04fdSHariprasad Shenai 			j /= 8;
16008e3d04fdSHariprasad Shenai 			if (j < tp.skip_ofst)     /* overlaps earlier pattern */
16018e3d04fdSHariprasad Shenai 				goto inval;
16028e3d04fdSHariprasad Shenai 			if (j - tp.skip_ofst > 31)            /* skip too big */
16038e3d04fdSHariprasad Shenai 				goto inval;
16048e3d04fdSHariprasad Shenai 			tp.skip_len = j - tp.skip_ofst;
16058e3d04fdSHariprasad Shenai 		}
16068e3d04fdSHariprasad Shenai 		if (i % 8) {
16078e3d04fdSHariprasad Shenai 			*data <<= (8 - i % 8) * 4;
16088e3d04fdSHariprasad Shenai 			*mask <<= (8 - i % 8) * 4;
16098e3d04fdSHariprasad Shenai 			i = (i + 15) & ~15;         /* 8-byte align */
16108e3d04fdSHariprasad Shenai 		}
16118e3d04fdSHariprasad Shenai 	}
16128e3d04fdSHariprasad Shenai 
16138e3d04fdSHariprasad Shenai 	if (tp.port == TRC_PORT_NONE)
16148e3d04fdSHariprasad Shenai 		goto inval;
16158e3d04fdSHariprasad Shenai 
16168e3d04fdSHariprasad Shenai apply:
16178e3d04fdSHariprasad Shenai 	i = t4_set_trace_filter(adap, &tp, trcidx, enable);
16188e3d04fdSHariprasad Shenai 	if (i)
16198e3d04fdSHariprasad Shenai 		count = i;
16208e3d04fdSHariprasad Shenai out:
16218e3d04fdSHariprasad Shenai 	kfree(s);
16228e3d04fdSHariprasad Shenai 	return count;
16238e3d04fdSHariprasad Shenai }
16248e3d04fdSHariprasad Shenai 
16258e3d04fdSHariprasad Shenai static const struct file_operations mps_trc_debugfs_fops = {
16268e3d04fdSHariprasad Shenai 	.owner   = THIS_MODULE,
16278e3d04fdSHariprasad Shenai 	.open    = mps_trc_open,
16288e3d04fdSHariprasad Shenai 	.read    = seq_read,
16298e3d04fdSHariprasad Shenai 	.llseek  = seq_lseek,
16308e3d04fdSHariprasad Shenai 	.release = single_release,
16318e3d04fdSHariprasad Shenai 	.write   = mps_trc_write
16328e3d04fdSHariprasad Shenai };
16338e3d04fdSHariprasad Shenai 
163449216c1cSHariprasad Shenai static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
163549216c1cSHariprasad Shenai 			  loff_t *ppos)
163649216c1cSHariprasad Shenai {
163749216c1cSHariprasad Shenai 	loff_t pos = *ppos;
1638c1d81b1cSDavid Howells 	loff_t avail = file_inode(file)->i_size;
163949216c1cSHariprasad Shenai 	struct adapter *adap = file->private_data;
164049216c1cSHariprasad Shenai 
164149216c1cSHariprasad Shenai 	if (pos < 0)
164249216c1cSHariprasad Shenai 		return -EINVAL;
164349216c1cSHariprasad Shenai 	if (pos >= avail)
164449216c1cSHariprasad Shenai 		return 0;
164549216c1cSHariprasad Shenai 	if (count > avail - pos)
164649216c1cSHariprasad Shenai 		count = avail - pos;
164749216c1cSHariprasad Shenai 
164849216c1cSHariprasad Shenai 	while (count) {
164949216c1cSHariprasad Shenai 		size_t len;
165049216c1cSHariprasad Shenai 		int ret, ofst;
165149216c1cSHariprasad Shenai 		u8 data[256];
165249216c1cSHariprasad Shenai 
165349216c1cSHariprasad Shenai 		ofst = pos & 3;
165449216c1cSHariprasad Shenai 		len = min(count + ofst, sizeof(data));
165549216c1cSHariprasad Shenai 		ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
165649216c1cSHariprasad Shenai 				    (u32 *)data, 1);
165749216c1cSHariprasad Shenai 		if (ret)
165849216c1cSHariprasad Shenai 			return ret;
165949216c1cSHariprasad Shenai 
166049216c1cSHariprasad Shenai 		len -= ofst;
166149216c1cSHariprasad Shenai 		if (copy_to_user(buf, data + ofst, len))
166249216c1cSHariprasad Shenai 			return -EFAULT;
166349216c1cSHariprasad Shenai 
166449216c1cSHariprasad Shenai 		buf += len;
166549216c1cSHariprasad Shenai 		pos += len;
166649216c1cSHariprasad Shenai 		count -= len;
166749216c1cSHariprasad Shenai 	}
166849216c1cSHariprasad Shenai 	count = pos - *ppos;
166949216c1cSHariprasad Shenai 	*ppos = pos;
167049216c1cSHariprasad Shenai 	return count;
167149216c1cSHariprasad Shenai }
167249216c1cSHariprasad Shenai 
167349216c1cSHariprasad Shenai static const struct file_operations flash_debugfs_fops = {
167449216c1cSHariprasad Shenai 	.owner   = THIS_MODULE,
167549216c1cSHariprasad Shenai 	.open    = mem_open,
167649216c1cSHariprasad Shenai 	.read    = flash_read,
1677ed98c85eSHariprasad Shenai 	.llseek  = default_llseek,
167849216c1cSHariprasad Shenai };
167949216c1cSHariprasad Shenai 
1680ef82f662SHariprasad Shenai static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1681ef82f662SHariprasad Shenai {
1682ef82f662SHariprasad Shenai 	*mask = x | y;
1683ef82f662SHariprasad Shenai 	y = (__force u64)cpu_to_be64(y);
1684ef82f662SHariprasad Shenai 	memcpy(addr, (char *)&y + 2, ETH_ALEN);
1685ef82f662SHariprasad Shenai }
1686ef82f662SHariprasad Shenai 
1687ef82f662SHariprasad Shenai static int mps_tcam_show(struct seq_file *seq, void *v)
1688ef82f662SHariprasad Shenai {
16893ccc6cf7SHariprasad Shenai 	struct adapter *adap = seq->private;
16903ccc6cf7SHariprasad Shenai 	unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
16913ccc6cf7SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
1692115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1693115b56afSHariprasad Shenai 			seq_puts(seq, "Idx  Ethernet address     Mask     "
1694115b56afSHariprasad Shenai 				 "  VNI   Mask   IVLAN Vld "
1695115b56afSHariprasad Shenai 				 "DIP_Hit   Lookup  Port "
1696115b56afSHariprasad Shenai 				 "Vld Ports PF  VF                           "
1697115b56afSHariprasad Shenai 				 "Replication                                "
1698115b56afSHariprasad Shenai 				 "    P0 P1 P2 P3  ML\n");
1699115b56afSHariprasad Shenai 		} else {
17003ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
17013ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
17023ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF                           "
17033ccc6cf7SHariprasad Shenai 					 "Replication                                "
1704ef82f662SHariprasad Shenai 					 "    P0 P1 P2 P3  ML\n");
17053ccc6cf7SHariprasad Shenai 			else
17063ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
17073ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF              Replication"
17083ccc6cf7SHariprasad Shenai 					 "	         P0 P1 P2 P3  ML\n");
1709115b56afSHariprasad Shenai 		}
17103ccc6cf7SHariprasad Shenai 	} else {
1711ef82f662SHariprasad Shenai 		u64 mask;
1712ef82f662SHariprasad Shenai 		u8 addr[ETH_ALEN];
1713115b56afSHariprasad Shenai 		bool replicate, dip_hit = false, vlan_vld = false;
1714ef82f662SHariprasad Shenai 		unsigned int idx = (uintptr_t)v - 2;
17153ccc6cf7SHariprasad Shenai 		u64 tcamy, tcamx, val;
1716115b56afSHariprasad Shenai 		u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
17173ccc6cf7SHariprasad Shenai 		u32 rplc[8] = {0};
1718115b56afSHariprasad Shenai 		u8 lookup_type = 0, port_num = 0;
1719115b56afSHariprasad Shenai 		u16 ivlan = 0;
17203ccc6cf7SHariprasad Shenai 
17213ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
17223ccc6cf7SHariprasad Shenai 			/* CtlCmdType - 0: Read, 1: Write
17233ccc6cf7SHariprasad Shenai 			 * CtlTcamSel - 0: TCAM0, 1: TCAM1
17243ccc6cf7SHariprasad Shenai 			 * CtlXYBitSel- 0: Y bit, 1: X bit
17253ccc6cf7SHariprasad Shenai 			 */
17263ccc6cf7SHariprasad Shenai 
17273ccc6cf7SHariprasad Shenai 			/* Read tcamy */
17283ccc6cf7SHariprasad Shenai 			ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
17293ccc6cf7SHariprasad Shenai 			if (idx < 256)
17303ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
17313ccc6cf7SHariprasad Shenai 			else
17323ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx - 256) |
17333ccc6cf7SHariprasad Shenai 				       CTLTCAMSEL_V(1);
17343ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
17353ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
17363ccc6cf7SHariprasad Shenai 			tcamy = DMACH_G(val) << 32;
17373ccc6cf7SHariprasad Shenai 			tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1738115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1739115b56afSHariprasad Shenai 			lookup_type = DATALKPTYPE_G(data2);
1740115b56afSHariprasad Shenai 			/* 0 - Outer header, 1 - Inner header
1741115b56afSHariprasad Shenai 			 * [71:48] bit locations are overloaded for
1742115b56afSHariprasad Shenai 			 * outer vs. inner lookup types.
1743115b56afSHariprasad Shenai 			 */
1744115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1745115b56afSHariprasad Shenai 				/* Inner header VNI */
1746b9525301SGanesh Goudar 				vniy = (data2 & DATAVIDH2_F) |
1747115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1748115b56afSHariprasad Shenai 				dip_hit = data2 & DATADIPHIT_F;
1749115b56afSHariprasad Shenai 			} else {
1750115b56afSHariprasad Shenai 				vlan_vld = data2 & DATAVIDH2_F;
1751115b56afSHariprasad Shenai 				ivlan = VIDL_G(val);
1752115b56afSHariprasad Shenai 			}
1753115b56afSHariprasad Shenai 			port_num = DATAPORTNUM_G(data2);
17543ccc6cf7SHariprasad Shenai 
17553ccc6cf7SHariprasad Shenai 			/* Read tcamx. Change the control param */
1756b9525301SGanesh Goudar 			vnix = 0;
17573ccc6cf7SHariprasad Shenai 			ctl |= CTLXYBITSEL_V(1);
17583ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
17593ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
17603ccc6cf7SHariprasad Shenai 			tcamx = DMACH_G(val) << 32;
17613ccc6cf7SHariprasad Shenai 			tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1762115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1763115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1764115b56afSHariprasad Shenai 				/* Inner header VNI mask */
1765b9525301SGanesh Goudar 				vnix = (data2 & DATAVIDH2_F) |
1766115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1767115b56afSHariprasad Shenai 			}
17683ccc6cf7SHariprasad Shenai 		} else {
17693ccc6cf7SHariprasad Shenai 			tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
17703ccc6cf7SHariprasad Shenai 			tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
17713ccc6cf7SHariprasad Shenai 		}
17723ccc6cf7SHariprasad Shenai 
17733ccc6cf7SHariprasad Shenai 		cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
17743ccc6cf7SHariprasad Shenai 		cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
1775ef82f662SHariprasad Shenai 
1776ef82f662SHariprasad Shenai 		if (tcamx & tcamy) {
1777ef82f662SHariprasad Shenai 			seq_printf(seq, "%3u         -\n", idx);
1778ef82f662SHariprasad Shenai 			goto out;
1779ef82f662SHariprasad Shenai 		}
1780ef82f662SHariprasad Shenai 
17813ccc6cf7SHariprasad Shenai 		rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
17823ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
17833ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & T6_REPLICATE_F);
17843ccc6cf7SHariprasad Shenai 		else
17853ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & REPLICATE_F);
17863ccc6cf7SHariprasad Shenai 
17873ccc6cf7SHariprasad Shenai 		if (replicate) {
1788ef82f662SHariprasad Shenai 			struct fw_ldst_cmd ldst_cmd;
1789ef82f662SHariprasad Shenai 			int ret;
17903ccc6cf7SHariprasad Shenai 			struct fw_ldst_mps_rplc mps_rplc;
17913ccc6cf7SHariprasad Shenai 			u32 ldst_addrspc;
1792ef82f662SHariprasad Shenai 
1793ef82f662SHariprasad Shenai 			memset(&ldst_cmd, 0, sizeof(ldst_cmd));
17943ccc6cf7SHariprasad Shenai 			ldst_addrspc =
17953ccc6cf7SHariprasad Shenai 				FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
1796ef82f662SHariprasad Shenai 			ldst_cmd.op_to_addrspace =
1797ef82f662SHariprasad Shenai 				htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1798ef82f662SHariprasad Shenai 				      FW_CMD_REQUEST_F |
1799ef82f662SHariprasad Shenai 				      FW_CMD_READ_F |
18003ccc6cf7SHariprasad Shenai 				      ldst_addrspc);
1801ef82f662SHariprasad Shenai 			ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
18023ccc6cf7SHariprasad Shenai 			ldst_cmd.u.mps.rplc.fid_idx =
1803ef82f662SHariprasad Shenai 				htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
18043ccc6cf7SHariprasad Shenai 				      FW_LDST_CMD_IDX_V(idx));
1805ef82f662SHariprasad Shenai 			ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1806ef82f662SHariprasad Shenai 					 sizeof(ldst_cmd), &ldst_cmd);
1807ef82f662SHariprasad Shenai 			if (ret)
1808ef82f662SHariprasad Shenai 				dev_warn(adap->pdev_dev, "Can't read MPS "
1809ef82f662SHariprasad Shenai 					 "replication map for idx %d: %d\n",
1810ef82f662SHariprasad Shenai 					 idx, -ret);
1811ef82f662SHariprasad Shenai 			else {
18123ccc6cf7SHariprasad Shenai 				mps_rplc = ldst_cmd.u.mps.rplc;
18133ccc6cf7SHariprasad Shenai 				rplc[0] = ntohl(mps_rplc.rplc31_0);
18143ccc6cf7SHariprasad Shenai 				rplc[1] = ntohl(mps_rplc.rplc63_32);
18153ccc6cf7SHariprasad Shenai 				rplc[2] = ntohl(mps_rplc.rplc95_64);
18163ccc6cf7SHariprasad Shenai 				rplc[3] = ntohl(mps_rplc.rplc127_96);
18173ccc6cf7SHariprasad Shenai 				if (adap->params.arch.mps_rplc_size > 128) {
18183ccc6cf7SHariprasad Shenai 					rplc[4] = ntohl(mps_rplc.rplc159_128);
18193ccc6cf7SHariprasad Shenai 					rplc[5] = ntohl(mps_rplc.rplc191_160);
18203ccc6cf7SHariprasad Shenai 					rplc[6] = ntohl(mps_rplc.rplc223_192);
18213ccc6cf7SHariprasad Shenai 					rplc[7] = ntohl(mps_rplc.rplc255_224);
18223ccc6cf7SHariprasad Shenai 				}
1823ef82f662SHariprasad Shenai 			}
1824ef82f662SHariprasad Shenai 		}
1825ef82f662SHariprasad Shenai 
1826ef82f662SHariprasad Shenai 		tcamxy2valmask(tcamx, tcamy, addr, &mask);
1827115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1828115b56afSHariprasad Shenai 			/* Inner header lookup */
1829115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1830115b56afSHariprasad Shenai 				seq_printf(seq,
1831115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1832115b56afSHariprasad Shenai 					   "%012llx %06x %06x    -    -   %3c"
183389e7a154SHariprasad Shenai 					   "      'I'  %4x   "
1834115b56afSHariprasad Shenai 					   "%3c   %#x%4u%4d", idx, addr[0],
1835115b56afSHariprasad Shenai 					   addr[1], addr[2], addr[3],
1836115b56afSHariprasad Shenai 					   addr[4], addr[5],
1837115b56afSHariprasad Shenai 					   (unsigned long long)mask,
1838b9525301SGanesh Goudar 					   vniy, (vnix | vniy),
1839b9525301SGanesh Goudar 					   dip_hit ? 'Y' : 'N',
184089e7a154SHariprasad Shenai 					   port_num,
18413ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
18423ccc6cf7SHariprasad Shenai 					   PORTMAP_G(cls_hi),
18433ccc6cf7SHariprasad Shenai 					   T6_PF_G(cls_lo),
18443ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
18453ccc6cf7SHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1846115b56afSHariprasad Shenai 			} else {
1847115b56afSHariprasad Shenai 				seq_printf(seq,
1848115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1849115b56afSHariprasad Shenai 					   "%012llx    -       -   ",
1850115b56afSHariprasad Shenai 					   idx, addr[0], addr[1], addr[2],
1851115b56afSHariprasad Shenai 					   addr[3], addr[4], addr[5],
1852115b56afSHariprasad Shenai 					   (unsigned long long)mask);
1853115b56afSHariprasad Shenai 
1854115b56afSHariprasad Shenai 				if (vlan_vld)
1855115b56afSHariprasad Shenai 					seq_printf(seq, "%4u   Y     ", ivlan);
18563ccc6cf7SHariprasad Shenai 				else
1857115b56afSHariprasad Shenai 					seq_puts(seq, "  -    N     ");
1858115b56afSHariprasad Shenai 
1859115b56afSHariprasad Shenai 				seq_printf(seq,
1860115b56afSHariprasad Shenai 					   "-      %3c  %4x   %3c   %#x%4u%4d",
1861115b56afSHariprasad Shenai 					   lookup_type ? 'I' : 'O', port_num,
1862115b56afSHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1863115b56afSHariprasad Shenai 					   PORTMAP_G(cls_hi),
1864115b56afSHariprasad Shenai 					   T6_PF_G(cls_lo),
1865115b56afSHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
1866115b56afSHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1867115b56afSHariprasad Shenai 			}
1868115b56afSHariprasad Shenai 		} else
18693ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
18703ccc6cf7SHariprasad Shenai 				   "%012llx%3c   %#x%4u%4d",
18713ccc6cf7SHariprasad Shenai 				   idx, addr[0], addr[1], addr[2], addr[3],
18723ccc6cf7SHariprasad Shenai 				   addr[4], addr[5], (unsigned long long)mask,
18733ccc6cf7SHariprasad Shenai 				   (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
18743ccc6cf7SHariprasad Shenai 				   PORTMAP_G(cls_hi),
1875ef82f662SHariprasad Shenai 				   PF_G(cls_lo),
1876ef82f662SHariprasad Shenai 				   (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
18773ccc6cf7SHariprasad Shenai 
18783ccc6cf7SHariprasad Shenai 		if (replicate) {
18793ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
18803ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x "
18813ccc6cf7SHariprasad Shenai 					   "%08x %08x %08x %08x",
18823ccc6cf7SHariprasad Shenai 					   rplc[7], rplc[6], rplc[5], rplc[4],
1883ef82f662SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
1884ef82f662SHariprasad Shenai 			else
18853ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x",
18863ccc6cf7SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
18873ccc6cf7SHariprasad Shenai 		} else {
18883ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
18893ccc6cf7SHariprasad Shenai 				seq_printf(seq, "%72c", ' ');
18903ccc6cf7SHariprasad Shenai 			else
1891ef82f662SHariprasad Shenai 				seq_printf(seq, "%36c", ' ');
18923ccc6cf7SHariprasad Shenai 		}
18933ccc6cf7SHariprasad Shenai 
18943ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
18953ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
18963ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO0_G(cls_lo),
18973ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO1_G(cls_lo),
18983ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO2_G(cls_lo),
18993ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO3_G(cls_lo),
19003ccc6cf7SHariprasad Shenai 				   (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
19013ccc6cf7SHariprasad Shenai 		else
1902ef82f662SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1903ef82f662SHariprasad Shenai 				   SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1904ef82f662SHariprasad Shenai 				   SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1905ef82f662SHariprasad Shenai 				   (cls_lo >> MULTILISTEN0_S) & 0xf);
1906ef82f662SHariprasad Shenai 	}
1907ef82f662SHariprasad Shenai out:	return 0;
1908ef82f662SHariprasad Shenai }
1909ef82f662SHariprasad Shenai 
1910ef82f662SHariprasad Shenai static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1911ef82f662SHariprasad Shenai {
1912ef82f662SHariprasad Shenai 	struct adapter *adap = seq->private;
1913ef82f662SHariprasad Shenai 	int max_mac_addr = is_t4(adap->params.chip) ?
1914ef82f662SHariprasad Shenai 				NUM_MPS_CLS_SRAM_L_INSTANCES :
1915ef82f662SHariprasad Shenai 				NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1916ef82f662SHariprasad Shenai 	return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1917ef82f662SHariprasad Shenai }
1918ef82f662SHariprasad Shenai 
1919ef82f662SHariprasad Shenai static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1920ef82f662SHariprasad Shenai {
1921ef82f662SHariprasad Shenai 	return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1922ef82f662SHariprasad Shenai }
1923ef82f662SHariprasad Shenai 
1924ef82f662SHariprasad Shenai static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1925ef82f662SHariprasad Shenai {
1926ef82f662SHariprasad Shenai 	++*pos;
1927ef82f662SHariprasad Shenai 	return mps_tcam_get_idx(seq, *pos);
1928ef82f662SHariprasad Shenai }
1929ef82f662SHariprasad Shenai 
1930ef82f662SHariprasad Shenai static void mps_tcam_stop(struct seq_file *seq, void *v)
1931ef82f662SHariprasad Shenai {
1932ef82f662SHariprasad Shenai }
1933ef82f662SHariprasad Shenai 
1934ef82f662SHariprasad Shenai static const struct seq_operations mps_tcam_seq_ops = {
1935ef82f662SHariprasad Shenai 	.start = mps_tcam_start,
1936ef82f662SHariprasad Shenai 	.next  = mps_tcam_next,
1937ef82f662SHariprasad Shenai 	.stop  = mps_tcam_stop,
1938ef82f662SHariprasad Shenai 	.show  = mps_tcam_show
1939ef82f662SHariprasad Shenai };
1940ef82f662SHariprasad Shenai 
1941ef82f662SHariprasad Shenai static int mps_tcam_open(struct inode *inode, struct file *file)
1942ef82f662SHariprasad Shenai {
1943ef82f662SHariprasad Shenai 	int res = seq_open(file, &mps_tcam_seq_ops);
1944ef82f662SHariprasad Shenai 
1945ef82f662SHariprasad Shenai 	if (!res) {
1946ef82f662SHariprasad Shenai 		struct seq_file *seq = file->private_data;
1947ef82f662SHariprasad Shenai 
1948ef82f662SHariprasad Shenai 		seq->private = inode->i_private;
1949ef82f662SHariprasad Shenai 	}
1950ef82f662SHariprasad Shenai 	return res;
1951ef82f662SHariprasad Shenai }
1952ef82f662SHariprasad Shenai 
1953ef82f662SHariprasad Shenai static const struct file_operations mps_tcam_debugfs_fops = {
1954ef82f662SHariprasad Shenai 	.owner   = THIS_MODULE,
1955ef82f662SHariprasad Shenai 	.open    = mps_tcam_open,
1956ef82f662SHariprasad Shenai 	.read    = seq_read,
1957ef82f662SHariprasad Shenai 	.llseek  = seq_lseek,
1958ef82f662SHariprasad Shenai 	.release = seq_release,
1959ef82f662SHariprasad Shenai };
1960ef82f662SHariprasad Shenai 
196170a5f3bbSHariprasad Shenai /* Display various sensor information.
196270a5f3bbSHariprasad Shenai  */
196370a5f3bbSHariprasad Shenai static int sensors_show(struct seq_file *seq, void *v)
196470a5f3bbSHariprasad Shenai {
196570a5f3bbSHariprasad Shenai 	struct adapter *adap = seq->private;
196670a5f3bbSHariprasad Shenai 	u32 param[7], val[7];
196770a5f3bbSHariprasad Shenai 	int ret;
196870a5f3bbSHariprasad Shenai 
196970a5f3bbSHariprasad Shenai 	/* Note that if the sensors haven't been initialized and turned on
197070a5f3bbSHariprasad Shenai 	 * we'll get values of 0, so treat those as "<unknown>" ...
197170a5f3bbSHariprasad Shenai 	 */
197270a5f3bbSHariprasad Shenai 	param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
197370a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
197470a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
197570a5f3bbSHariprasad Shenai 	param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
197670a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
197770a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1978b2612722SHariprasad Shenai 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
197970a5f3bbSHariprasad Shenai 			      param, val);
198070a5f3bbSHariprasad Shenai 
198170a5f3bbSHariprasad Shenai 	if (ret < 0 || val[0] == 0)
198270a5f3bbSHariprasad Shenai 		seq_puts(seq, "Temperature: <unknown>\n");
198370a5f3bbSHariprasad Shenai 	else
198470a5f3bbSHariprasad Shenai 		seq_printf(seq, "Temperature: %dC\n", val[0]);
198570a5f3bbSHariprasad Shenai 
198670a5f3bbSHariprasad Shenai 	if (ret < 0 || val[1] == 0)
198770a5f3bbSHariprasad Shenai 		seq_puts(seq, "Core VDD:    <unknown>\n");
198870a5f3bbSHariprasad Shenai 	else
198970a5f3bbSHariprasad Shenai 		seq_printf(seq, "Core VDD:    %dmV\n", val[1]);
199070a5f3bbSHariprasad Shenai 
199170a5f3bbSHariprasad Shenai 	return 0;
199270a5f3bbSHariprasad Shenai }
199370a5f3bbSHariprasad Shenai 
199470a5f3bbSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
199570a5f3bbSHariprasad Shenai 
1996b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1997b5a02f50SAnish Bhatt static int clip_tbl_open(struct inode *inode, struct file *file)
1998b5a02f50SAnish Bhatt {
1999acde2c2dSHariprasad Shenai 	return single_open(file, clip_tbl_show, inode->i_private);
2000b5a02f50SAnish Bhatt }
2001b5a02f50SAnish Bhatt 
2002b5a02f50SAnish Bhatt static const struct file_operations clip_tbl_debugfs_fops = {
2003b5a02f50SAnish Bhatt 	.owner   = THIS_MODULE,
2004b5a02f50SAnish Bhatt 	.open    = clip_tbl_open,
2005b5a02f50SAnish Bhatt 	.read    = seq_read,
2006b5a02f50SAnish Bhatt 	.llseek  = seq_lseek,
2007b5a02f50SAnish Bhatt 	.release = single_release
2008b5a02f50SAnish Bhatt };
2009b5a02f50SAnish Bhatt #endif
2010b5a02f50SAnish Bhatt 
2011688ea5feSHariprasad Shenai /*RSS Table.
2012688ea5feSHariprasad Shenai  */
2013688ea5feSHariprasad Shenai 
2014688ea5feSHariprasad Shenai static int rss_show(struct seq_file *seq, void *v, int idx)
2015688ea5feSHariprasad Shenai {
2016688ea5feSHariprasad Shenai 	u16 *entry = v;
2017688ea5feSHariprasad Shenai 
2018688ea5feSHariprasad Shenai 	seq_printf(seq, "%4d:  %4u  %4u  %4u  %4u  %4u  %4u  %4u  %4u\n",
2019688ea5feSHariprasad Shenai 		   idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
2020688ea5feSHariprasad Shenai 		   entry[5], entry[6], entry[7]);
2021688ea5feSHariprasad Shenai 	return 0;
2022688ea5feSHariprasad Shenai }
2023688ea5feSHariprasad Shenai 
2024688ea5feSHariprasad Shenai static int rss_open(struct inode *inode, struct file *file)
2025688ea5feSHariprasad Shenai {
2026688ea5feSHariprasad Shenai 	struct adapter *adap = inode->i_private;
2027f988008aSGanesh Goudar 	int ret, nentries;
2028f988008aSGanesh Goudar 	struct seq_tab *p;
2029688ea5feSHariprasad Shenai 
2030f988008aSGanesh Goudar 	nentries = t4_chip_rss_size(adap);
2031f988008aSGanesh Goudar 	p = seq_open_tab(file, nentries / 8, 8 * sizeof(u16), 0, rss_show);
2032688ea5feSHariprasad Shenai 	if (!p)
2033688ea5feSHariprasad Shenai 		return -ENOMEM;
2034688ea5feSHariprasad Shenai 
2035688ea5feSHariprasad Shenai 	ret = t4_read_rss(adap, (u16 *)p->data);
2036688ea5feSHariprasad Shenai 	if (ret)
2037688ea5feSHariprasad Shenai 		seq_release_private(inode, file);
2038688ea5feSHariprasad Shenai 
2039688ea5feSHariprasad Shenai 	return ret;
2040688ea5feSHariprasad Shenai }
2041688ea5feSHariprasad Shenai 
2042688ea5feSHariprasad Shenai static const struct file_operations rss_debugfs_fops = {
2043688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2044688ea5feSHariprasad Shenai 	.open    = rss_open,
2045688ea5feSHariprasad Shenai 	.read    = seq_read,
2046688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2047688ea5feSHariprasad Shenai 	.release = seq_release_private
2048688ea5feSHariprasad Shenai };
2049688ea5feSHariprasad Shenai 
2050688ea5feSHariprasad Shenai /* RSS Configuration.
2051688ea5feSHariprasad Shenai  */
2052688ea5feSHariprasad Shenai 
2053688ea5feSHariprasad Shenai /* Small utility function to return the strings "yes" or "no" if the supplied
2054688ea5feSHariprasad Shenai  * argument is non-zero.
2055688ea5feSHariprasad Shenai  */
2056688ea5feSHariprasad Shenai static const char *yesno(int x)
2057688ea5feSHariprasad Shenai {
2058688ea5feSHariprasad Shenai 	static const char *yes = "yes";
2059688ea5feSHariprasad Shenai 	static const char *no = "no";
2060688ea5feSHariprasad Shenai 
2061688ea5feSHariprasad Shenai 	return x ? yes : no;
2062688ea5feSHariprasad Shenai }
2063688ea5feSHariprasad Shenai 
2064688ea5feSHariprasad Shenai static int rss_config_show(struct seq_file *seq, void *v)
2065688ea5feSHariprasad Shenai {
2066688ea5feSHariprasad Shenai 	struct adapter *adapter = seq->private;
2067688ea5feSHariprasad Shenai 	static const char * const keymode[] = {
2068688ea5feSHariprasad Shenai 		"global",
2069688ea5feSHariprasad Shenai 		"global and per-VF scramble",
2070688ea5feSHariprasad Shenai 		"per-PF and per-VF scramble",
2071688ea5feSHariprasad Shenai 		"per-VF and per-VF scramble",
2072688ea5feSHariprasad Shenai 	};
2073688ea5feSHariprasad Shenai 	u32 rssconf;
2074688ea5feSHariprasad Shenai 
2075688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
2076688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
2077688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
2078688ea5feSHariprasad Shenai 							TNL4TUPENIPV6_F));
2079688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
2080688ea5feSHariprasad Shenai 							TNL2TUPENIPV6_F));
2081688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
2082688ea5feSHariprasad Shenai 							TNL4TUPENIPV4_F));
2083688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
2084688ea5feSHariprasad Shenai 							TNL2TUPENIPV4_F));
2085688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlTcpSel:     %3s\n", yesno(rssconf & TNLTCPSEL_F));
2086688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlIp6Sel:     %3s\n", yesno(rssconf & TNLIP6SEL_F));
2087688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlVrtSel:     %3s\n", yesno(rssconf & TNLVRTSEL_F));
2088688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlMapEn:      %3s\n", yesno(rssconf & TNLMAPEN_F));
2089688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdHashSave:   %3s\n", yesno(rssconf &
2090688ea5feSHariprasad Shenai 							OFDHASHSAVE_F));
2091688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdVrtSel:     %3s\n", yesno(rssconf & OFDVRTSEL_F));
2092688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdMapEn:      %3s\n", yesno(rssconf & OFDMAPEN_F));
2093688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdLkpEn:      %3s\n", yesno(rssconf & OFDLKPEN_F));
2094688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2095688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
2096688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv6: %3s\n", yesno(rssconf &
2097688ea5feSHariprasad Shenai 							SYN2TUPENIPV6_F));
2098688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv4: %3s\n", yesno(rssconf &
2099688ea5feSHariprasad Shenai 							SYN4TUPENIPV4_F));
2100688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv4: %3s\n", yesno(rssconf &
2101688ea5feSHariprasad Shenai 							SYN2TUPENIPV4_F));
2102688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2103688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
2104688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynIp6Sel:     %3s\n", yesno(rssconf & SYNIP6SEL_F));
2105688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynVrt6Sel:    %3s\n", yesno(rssconf & SYNVRTSEL_F));
2106688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynMapEn:      %3s\n", yesno(rssconf & SYNMAPEN_F));
2107688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynLkpEn:      %3s\n", yesno(rssconf & SYNLKPEN_F));
2108688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnEn:         %3s\n", yesno(rssconf &
2109688ea5feSHariprasad Shenai 							CHANNELENABLE_F));
2110688ea5feSHariprasad Shenai 	seq_printf(seq, "  PrtEn:         %3s\n", yesno(rssconf &
2111688ea5feSHariprasad Shenai 							PORTENABLE_F));
2112688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlAllLkp:     %3s\n", yesno(rssconf &
2113688ea5feSHariprasad Shenai 							TNLALLLOOKUP_F));
2114688ea5feSHariprasad Shenai 	seq_printf(seq, "  VrtEn:         %3s\n", yesno(rssconf &
2115688ea5feSHariprasad Shenai 							VIRTENABLE_F));
2116688ea5feSHariprasad Shenai 	seq_printf(seq, "  CngEn:         %3s\n", yesno(rssconf &
2117688ea5feSHariprasad Shenai 							CONGESTIONENABLE_F));
2118688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashToeplitz:  %3s\n", yesno(rssconf &
2119688ea5feSHariprasad Shenai 							HASHTOEPLITZ_F));
2120688ea5feSHariprasad Shenai 	seq_printf(seq, "  Udp4En:        %3s\n", yesno(rssconf & UDPENABLE_F));
2121688ea5feSHariprasad Shenai 	seq_printf(seq, "  Disable:       %3s\n", yesno(rssconf & DISABLE_F));
2122688ea5feSHariprasad Shenai 
2123688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2124688ea5feSHariprasad Shenai 
2125688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
2126688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
2127688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2128688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskFilter:    %3d\n", MASKFILTER_G(rssconf));
2129688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2130688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashAll:     %3s\n",
2131688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHALL_F));
2132688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashEth:     %3s\n",
2133688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHETH_F));
2134688ea5feSHariprasad Shenai 	}
2135688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2136688ea5feSHariprasad Shenai 
2137688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2138688ea5feSHariprasad Shenai 
2139688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
2140688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
2141688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2142688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplMapEn:    %3s\n", yesno(rssconf &
2143688ea5feSHariprasad Shenai 							RRCPLMAPEN_F));
2144688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
2145688ea5feSHariprasad Shenai 
2146688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2147688ea5feSHariprasad Shenai 
2148688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
2149688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
2150688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2151688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2152688ea5feSHariprasad Shenai 
2153688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2154688ea5feSHariprasad Shenai 
2155688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
2156688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
2157688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2158688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyWrAddrX:     %3d\n",
2159688ea5feSHariprasad Shenai 			   KEYWRADDRX_G(rssconf));
2160688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyExtend:      %3s\n",
2161688ea5feSHariprasad Shenai 			   yesno(rssconf & KEYEXTEND_F));
2162688ea5feSHariprasad Shenai 	}
2163688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdRg:        %3s\n", yesno(rssconf & VFRDRG_F));
2164688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdEn:        %3s\n", yesno(rssconf & VFRDEN_F));
2165688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfPerrEn:      %3s\n", yesno(rssconf & VFPERREN_F));
2166688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyPerrEn:     %3s\n", yesno(rssconf & KEYPERREN_F));
2167688ea5feSHariprasad Shenai 	seq_printf(seq, "  DisVfVlan:     %3s\n", yesno(rssconf &
2168688ea5feSHariprasad Shenai 							DISABLEVLAN_F));
2169688ea5feSHariprasad Shenai 	seq_printf(seq, "  EnUpSwt:       %3s\n", yesno(rssconf & ENABLEUP0_F));
2170688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashDelay:     %3d\n", HASHDELAY_G(rssconf));
2171688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
2172688ea5feSHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n", VFWRADDR_G(rssconf));
21733ccc6cf7SHariprasad Shenai 	else
21743ccc6cf7SHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n",
21753ccc6cf7SHariprasad Shenai 			   T6_VFWRADDR_G(rssconf));
2176688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyMode:       %s\n", keymode[KEYMODE_G(rssconf)]);
2177688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfWrEn:        %3s\n", yesno(rssconf & VFWREN_F));
2178688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrEn:       %3s\n", yesno(rssconf & KEYWREN_F));
2179688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrAddr:     %3d\n", KEYWRADDR_G(rssconf));
2180688ea5feSHariprasad Shenai 
2181688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2182688ea5feSHariprasad Shenai 
2183688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
2184688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
2185688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount3:     %3s\n", yesno(rssconf & CHNCOUNT3_F));
2186688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount2:     %3s\n", yesno(rssconf & CHNCOUNT2_F));
2187688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount1:     %3s\n", yesno(rssconf & CHNCOUNT1_F));
2188688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount0:     %3s\n", yesno(rssconf & CHNCOUNT0_F));
2189688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow3:   %3s\n", yesno(rssconf &
2190688ea5feSHariprasad Shenai 							CHNUNDFLOW3_F));
2191688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow2:   %3s\n", yesno(rssconf &
2192688ea5feSHariprasad Shenai 							CHNUNDFLOW2_F));
2193688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow1:   %3s\n", yesno(rssconf &
2194688ea5feSHariprasad Shenai 							CHNUNDFLOW1_F));
2195688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow0:   %3s\n", yesno(rssconf &
2196688ea5feSHariprasad Shenai 							CHNUNDFLOW0_F));
2197688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn3:       %3s\n", yesno(rssconf & RSTCHN3_F));
2198688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn2:       %3s\n", yesno(rssconf & RSTCHN2_F));
2199688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn1:       %3s\n", yesno(rssconf & RSTCHN1_F));
2200688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn0:       %3s\n", yesno(rssconf & RSTCHN0_F));
2201688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdVld:        %3s\n", yesno(rssconf & UPDVLD_F));
2202688ea5feSHariprasad Shenai 	seq_printf(seq, "  Xoff:          %3s\n", yesno(rssconf & XOFF_F));
2203688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn3:       %3s\n", yesno(rssconf & UPDCHN3_F));
2204688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn2:       %3s\n", yesno(rssconf & UPDCHN2_F));
2205688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn1:       %3s\n", yesno(rssconf & UPDCHN1_F));
2206688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn0:       %3s\n", yesno(rssconf & UPDCHN0_F));
2207688ea5feSHariprasad Shenai 	seq_printf(seq, "  Queue:         %3d\n", QUEUE_G(rssconf));
2208688ea5feSHariprasad Shenai 
2209688ea5feSHariprasad Shenai 	return 0;
2210688ea5feSHariprasad Shenai }
2211688ea5feSHariprasad Shenai 
2212688ea5feSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
2213688ea5feSHariprasad Shenai 
2214688ea5feSHariprasad Shenai /* RSS Secret Key.
2215688ea5feSHariprasad Shenai  */
2216688ea5feSHariprasad Shenai 
2217688ea5feSHariprasad Shenai static int rss_key_show(struct seq_file *seq, void *v)
2218688ea5feSHariprasad Shenai {
2219688ea5feSHariprasad Shenai 	u32 key[10];
2220688ea5feSHariprasad Shenai 
22215ccf9d04SRahul Lakkireddy 	t4_read_rss_key(seq->private, key, true);
2222688ea5feSHariprasad Shenai 	seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
2223688ea5feSHariprasad Shenai 		   key[9], key[8], key[7], key[6], key[5], key[4], key[3],
2224688ea5feSHariprasad Shenai 		   key[2], key[1], key[0]);
2225688ea5feSHariprasad Shenai 	return 0;
2226688ea5feSHariprasad Shenai }
2227688ea5feSHariprasad Shenai 
2228688ea5feSHariprasad Shenai static int rss_key_open(struct inode *inode, struct file *file)
2229688ea5feSHariprasad Shenai {
2230688ea5feSHariprasad Shenai 	return single_open(file, rss_key_show, inode->i_private);
2231688ea5feSHariprasad Shenai }
2232688ea5feSHariprasad Shenai 
2233688ea5feSHariprasad Shenai static ssize_t rss_key_write(struct file *file, const char __user *buf,
2234688ea5feSHariprasad Shenai 			     size_t count, loff_t *pos)
2235688ea5feSHariprasad Shenai {
2236688ea5feSHariprasad Shenai 	int i, j;
2237688ea5feSHariprasad Shenai 	u32 key[10];
2238688ea5feSHariprasad Shenai 	char s[100], *p;
2239c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
2240688ea5feSHariprasad Shenai 
2241688ea5feSHariprasad Shenai 	if (count > sizeof(s) - 1)
2242688ea5feSHariprasad Shenai 		return -EINVAL;
2243688ea5feSHariprasad Shenai 	if (copy_from_user(s, buf, count))
2244688ea5feSHariprasad Shenai 		return -EFAULT;
2245688ea5feSHariprasad Shenai 	for (i = count; i > 0 && isspace(s[i - 1]); i--)
2246688ea5feSHariprasad Shenai 		;
2247688ea5feSHariprasad Shenai 	s[i] = '\0';
2248688ea5feSHariprasad Shenai 
2249688ea5feSHariprasad Shenai 	for (p = s, i = 9; i >= 0; i--) {
2250688ea5feSHariprasad Shenai 		key[i] = 0;
2251688ea5feSHariprasad Shenai 		for (j = 0; j < 8; j++, p++) {
2252688ea5feSHariprasad Shenai 			if (!isxdigit(*p))
2253688ea5feSHariprasad Shenai 				return -EINVAL;
2254688ea5feSHariprasad Shenai 			key[i] = (key[i] << 4) | hex2val(*p);
2255688ea5feSHariprasad Shenai 		}
2256688ea5feSHariprasad Shenai 	}
2257688ea5feSHariprasad Shenai 
22585ccf9d04SRahul Lakkireddy 	t4_write_rss_key(adap, key, -1, true);
2259688ea5feSHariprasad Shenai 	return count;
2260688ea5feSHariprasad Shenai }
2261688ea5feSHariprasad Shenai 
2262688ea5feSHariprasad Shenai static const struct file_operations rss_key_debugfs_fops = {
2263688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2264688ea5feSHariprasad Shenai 	.open    = rss_key_open,
2265688ea5feSHariprasad Shenai 	.read    = seq_read,
2266688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2267688ea5feSHariprasad Shenai 	.release = single_release,
2268688ea5feSHariprasad Shenai 	.write   = rss_key_write
2269688ea5feSHariprasad Shenai };
2270688ea5feSHariprasad Shenai 
2271688ea5feSHariprasad Shenai /* PF RSS Configuration.
2272688ea5feSHariprasad Shenai  */
2273688ea5feSHariprasad Shenai 
2274688ea5feSHariprasad Shenai struct rss_pf_conf {
2275688ea5feSHariprasad Shenai 	u32 rss_pf_map;
2276688ea5feSHariprasad Shenai 	u32 rss_pf_mask;
2277688ea5feSHariprasad Shenai 	u32 rss_pf_config;
2278688ea5feSHariprasad Shenai };
2279688ea5feSHariprasad Shenai 
2280688ea5feSHariprasad Shenai static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
2281688ea5feSHariprasad Shenai {
2282688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2283688ea5feSHariprasad Shenai 
2284688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2285688ea5feSHariprasad Shenai 		/* use the 0th entry to dump the PF Map Index Size */
2286688ea5feSHariprasad Shenai 		pfconf = seq->private + offsetof(struct seq_tab, data);
2287688ea5feSHariprasad Shenai 		seq_printf(seq, "PF Map Index Size = %d\n\n",
2288688ea5feSHariprasad Shenai 			   LKPIDXSIZE_G(pfconf->rss_pf_map));
2289688ea5feSHariprasad Shenai 
2290688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS              PF   VF    Hash Tuple Enable         Default\n");
2291688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable       IPF Mask Mask  IPv6      IPv4      UDP   Queue\n");
2292688ea5feSHariprasad Shenai 		seq_puts(seq, " PF  Map Chn Prt  Map Size Size  Four Two  Four Two  Four  Ch1  Ch0\n");
2293688ea5feSHariprasad Shenai 	} else {
2294688ea5feSHariprasad Shenai 		#define G_PFnLKPIDX(map, n) \
2295688ea5feSHariprasad Shenai 			(((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
2296688ea5feSHariprasad Shenai 		#define G_PFnMSKSIZE(mask, n) \
2297688ea5feSHariprasad Shenai 			(((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
2298688ea5feSHariprasad Shenai 
2299688ea5feSHariprasad Shenai 		pfconf = v;
2300688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s %3s  %3d  %3d  %3d   %3s %3s   %3s %3s   %3s  %3d  %3d\n",
2301688ea5feSHariprasad Shenai 			   idx,
2302688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & MAPENABLE_F),
2303688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & CHNENABLE_F),
2304688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & PRTENABLE_F),
2305688ea5feSHariprasad Shenai 			   G_PFnLKPIDX(pfconf->rss_pf_map, idx),
2306688ea5feSHariprasad Shenai 			   G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
2307688ea5feSHariprasad Shenai 			   IVFWIDTH_G(pfconf->rss_pf_config),
2308688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
2309688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
2310688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
2311688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
2312688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
2313688ea5feSHariprasad Shenai 			   CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
2314688ea5feSHariprasad Shenai 			   CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
2315688ea5feSHariprasad Shenai 
2316688ea5feSHariprasad Shenai 		#undef G_PFnLKPIDX
2317688ea5feSHariprasad Shenai 		#undef G_PFnMSKSIZE
2318688ea5feSHariprasad Shenai 	}
2319688ea5feSHariprasad Shenai 	return 0;
2320688ea5feSHariprasad Shenai }
2321688ea5feSHariprasad Shenai 
2322688ea5feSHariprasad Shenai static int rss_pf_config_open(struct inode *inode, struct file *file)
2323688ea5feSHariprasad Shenai {
2324688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2325688ea5feSHariprasad Shenai 	struct seq_tab *p;
2326688ea5feSHariprasad Shenai 	u32 rss_pf_map, rss_pf_mask;
2327688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2328688ea5feSHariprasad Shenai 	int pf;
2329688ea5feSHariprasad Shenai 
2330688ea5feSHariprasad Shenai 	p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
2331688ea5feSHariprasad Shenai 	if (!p)
2332688ea5feSHariprasad Shenai 		return -ENOMEM;
2333688ea5feSHariprasad Shenai 
2334688ea5feSHariprasad Shenai 	pfconf = (struct rss_pf_conf *)p->data;
23355ccf9d04SRahul Lakkireddy 	rss_pf_map = t4_read_rss_pf_map(adapter, true);
23365ccf9d04SRahul Lakkireddy 	rss_pf_mask = t4_read_rss_pf_mask(adapter, true);
2337688ea5feSHariprasad Shenai 	for (pf = 0; pf < 8; pf++) {
2338688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_map = rss_pf_map;
2339688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_mask = rss_pf_mask;
23405ccf9d04SRahul Lakkireddy 		t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config,
23415ccf9d04SRahul Lakkireddy 				      true);
2342688ea5feSHariprasad Shenai 	}
2343688ea5feSHariprasad Shenai 	return 0;
2344688ea5feSHariprasad Shenai }
2345688ea5feSHariprasad Shenai 
2346688ea5feSHariprasad Shenai static const struct file_operations rss_pf_config_debugfs_fops = {
2347688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2348688ea5feSHariprasad Shenai 	.open    = rss_pf_config_open,
2349688ea5feSHariprasad Shenai 	.read    = seq_read,
2350688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2351688ea5feSHariprasad Shenai 	.release = seq_release_private
2352688ea5feSHariprasad Shenai };
2353688ea5feSHariprasad Shenai 
2354688ea5feSHariprasad Shenai /* VF RSS Configuration.
2355688ea5feSHariprasad Shenai  */
2356688ea5feSHariprasad Shenai 
2357688ea5feSHariprasad Shenai struct rss_vf_conf {
2358688ea5feSHariprasad Shenai 	u32 rss_vf_vfl;
2359688ea5feSHariprasad Shenai 	u32 rss_vf_vfh;
2360688ea5feSHariprasad Shenai };
2361688ea5feSHariprasad Shenai 
2362688ea5feSHariprasad Shenai static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
2363688ea5feSHariprasad Shenai {
2364688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2365688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS                     Hash Tuple Enable\n");
2366688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable   IVF  Dis  Enb  IPv6      IPv4      UDP    Def  Secret Key\n");
2367688ea5feSHariprasad Shenai 		seq_puts(seq, " VF  Chn Prt  Map  VLAN  uP  Four Two  Four Two  Four   Que  Idx       Hash\n");
2368688ea5feSHariprasad Shenai 	} else {
2369688ea5feSHariprasad Shenai 		struct rss_vf_conf *vfconf = v;
2370688ea5feSHariprasad Shenai 
2371688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s  %3d   %3s %3s   %3s %3s   %3s  %3s   %3s  %4d  %3d %#10x\n",
2372688ea5feSHariprasad Shenai 			   idx,
2373688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
2374688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
2375688ea5feSHariprasad Shenai 			   VFLKPIDX_G(vfconf->rss_vf_vfh),
2376688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
2377688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFUPEN_F),
2378688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2379688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
2380688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2381688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
2382688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
2383688ea5feSHariprasad Shenai 			   DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
2384688ea5feSHariprasad Shenai 			   KEYINDEX_G(vfconf->rss_vf_vfh),
2385688ea5feSHariprasad Shenai 			   vfconf->rss_vf_vfl);
2386688ea5feSHariprasad Shenai 	}
2387688ea5feSHariprasad Shenai 	return 0;
2388688ea5feSHariprasad Shenai }
2389688ea5feSHariprasad Shenai 
2390688ea5feSHariprasad Shenai static int rss_vf_config_open(struct inode *inode, struct file *file)
2391688ea5feSHariprasad Shenai {
2392688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2393688ea5feSHariprasad Shenai 	struct seq_tab *p;
2394688ea5feSHariprasad Shenai 	struct rss_vf_conf *vfconf;
23953ccc6cf7SHariprasad Shenai 	int vf, vfcount = adapter->params.arch.vfcount;
2396688ea5feSHariprasad Shenai 
23973ccc6cf7SHariprasad Shenai 	p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
2398688ea5feSHariprasad Shenai 	if (!p)
2399688ea5feSHariprasad Shenai 		return -ENOMEM;
2400688ea5feSHariprasad Shenai 
2401688ea5feSHariprasad Shenai 	vfconf = (struct rss_vf_conf *)p->data;
24023ccc6cf7SHariprasad Shenai 	for (vf = 0; vf < vfcount; vf++) {
2403688ea5feSHariprasad Shenai 		t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
24045ccf9d04SRahul Lakkireddy 				      &vfconf[vf].rss_vf_vfh, true);
2405688ea5feSHariprasad Shenai 	}
2406688ea5feSHariprasad Shenai 	return 0;
2407688ea5feSHariprasad Shenai }
2408688ea5feSHariprasad Shenai 
2409688ea5feSHariprasad Shenai static const struct file_operations rss_vf_config_debugfs_fops = {
2410688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2411688ea5feSHariprasad Shenai 	.open    = rss_vf_config_open,
2412688ea5feSHariprasad Shenai 	.read    = seq_read,
2413688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2414688ea5feSHariprasad Shenai 	.release = seq_release_private
2415688ea5feSHariprasad Shenai };
2416688ea5feSHariprasad Shenai 
24170eaec62aSCasey Leedom static int resources_show(struct seq_file *seq, void *v)
24180eaec62aSCasey Leedom {
24190eaec62aSCasey Leedom 	struct adapter *adapter = seq->private;
24200eaec62aSCasey Leedom 	struct pf_resources *pfres = &adapter->params.pfres;
24210eaec62aSCasey Leedom 
24220eaec62aSCasey Leedom 	#define S(desc, fmt, var) \
24230eaec62aSCasey Leedom 		seq_printf(seq, "%-60s " fmt "\n", \
24240eaec62aSCasey Leedom 			   desc " (" #var "):", pfres->var)
24250eaec62aSCasey Leedom 
24260eaec62aSCasey Leedom 	S("Virtual Interfaces", "%d", nvi);
24270eaec62aSCasey Leedom 	S("Egress Queues", "%d", neq);
24280eaec62aSCasey Leedom 	S("Ethernet Control", "%d", nethctrl);
24290eaec62aSCasey Leedom 	S("Ingress Queues/w Free Lists/Interrupts", "%d", niqflint);
24300eaec62aSCasey Leedom 	S("Ingress Queues", "%d", niq);
24310eaec62aSCasey Leedom 	S("Traffic Class", "%d", tc);
24320eaec62aSCasey Leedom 	S("Port Access Rights Mask", "%#x", pmask);
24330eaec62aSCasey Leedom 	S("MAC Address Filters", "%d", nexactf);
24340eaec62aSCasey Leedom 	S("Firmware Command Read Capabilities", "%#x", r_caps);
24350eaec62aSCasey Leedom 	S("Firmware Command Write/Execute Capabilities", "%#x", wx_caps);
24360eaec62aSCasey Leedom 
24370eaec62aSCasey Leedom 	#undef S
24380eaec62aSCasey Leedom 
24390eaec62aSCasey Leedom 	return 0;
24400eaec62aSCasey Leedom }
24410eaec62aSCasey Leedom 
24420eaec62aSCasey Leedom static int resources_open(struct inode *inode, struct file *file)
24430eaec62aSCasey Leedom {
24440eaec62aSCasey Leedom 	return single_open(file, resources_show, inode->i_private);
24450eaec62aSCasey Leedom }
24460eaec62aSCasey Leedom 
24470eaec62aSCasey Leedom static const struct file_operations resources_debugfs_fops = {
24480eaec62aSCasey Leedom 	.owner   = THIS_MODULE,
24490eaec62aSCasey Leedom 	.open    = resources_open,
24500eaec62aSCasey Leedom 	.read    = seq_read,
24510eaec62aSCasey Leedom 	.llseek  = seq_lseek,
24520eaec62aSCasey Leedom 	.release = seq_release,
24530eaec62aSCasey Leedom };
24540eaec62aSCasey Leedom 
24553051fa61SHariprasad Shenai /**
24563051fa61SHariprasad Shenai  * ethqset2pinfo - return port_info of an Ethernet Queue Set
24573051fa61SHariprasad Shenai  * @adap: the adapter
24583051fa61SHariprasad Shenai  * @qset: Ethernet Queue Set
24593051fa61SHariprasad Shenai  */
24603051fa61SHariprasad Shenai static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
24613051fa61SHariprasad Shenai {
24623051fa61SHariprasad Shenai 	int pidx;
24633051fa61SHariprasad Shenai 
24643051fa61SHariprasad Shenai 	for_each_port(adap, pidx) {
24653051fa61SHariprasad Shenai 		struct port_info *pi = adap2pinfo(adap, pidx);
24663051fa61SHariprasad Shenai 
24673051fa61SHariprasad Shenai 		if (qset >= pi->first_qset &&
24683051fa61SHariprasad Shenai 		    qset < pi->first_qset + pi->nqsets)
24693051fa61SHariprasad Shenai 			return pi;
24703051fa61SHariprasad Shenai 	}
24713051fa61SHariprasad Shenai 
24723051fa61SHariprasad Shenai 	/* should never happen! */
24733051fa61SHariprasad Shenai 	BUG_ON(1);
24743051fa61SHariprasad Shenai 	return NULL;
24753051fa61SHariprasad Shenai }
24763051fa61SHariprasad Shenai 
2477dc9daab2SHariprasad Shenai static int sge_qinfo_show(struct seq_file *seq, void *v)
2478dc9daab2SHariprasad Shenai {
2479dc9daab2SHariprasad Shenai 	struct adapter *adap = seq->private;
2480dc9daab2SHariprasad Shenai 	int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
24810fbc81b3SHariprasad Shenai 	int ofld_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
2482dc9daab2SHariprasad Shenai 	int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
2483dc9daab2SHariprasad Shenai 	int i, r = (uintptr_t)v - 1;
24840fbc81b3SHariprasad Shenai 	int ofld_idx = r - eth_entries;
24850fbc81b3SHariprasad Shenai 	int ctrl_idx =  ofld_idx - ofld_entries;
2486dc9daab2SHariprasad Shenai 	int fq_idx =  ctrl_idx - ctrl_entries;
2487dc9daab2SHariprasad Shenai 
2488dc9daab2SHariprasad Shenai 	if (r)
2489dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n');
2490dc9daab2SHariprasad Shenai 
2491dc9daab2SHariprasad Shenai #define S3(fmt_spec, s, v) \
2492dc9daab2SHariprasad Shenai do { \
2493dc9daab2SHariprasad Shenai 	seq_printf(seq, "%-12s", s); \
2494dc9daab2SHariprasad Shenai 	for (i = 0; i < n; ++i) \
2495dc9daab2SHariprasad Shenai 		seq_printf(seq, " %16" fmt_spec, v); \
2496dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n'); \
2497dc9daab2SHariprasad Shenai } while (0)
2498dc9daab2SHariprasad Shenai #define S(s, v) S3("s", s, v)
2499e106a4d9SHariprasad Shenai #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
2500dc9daab2SHariprasad Shenai #define T(s, v) S3("u", s, tx[i].v)
2501e106a4d9SHariprasad Shenai #define TL(s, v) T3("lu", s, v)
2502e106a4d9SHariprasad Shenai #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
2503dc9daab2SHariprasad Shenai #define R(s, v) S3("u", s, rx[i].v)
2504e106a4d9SHariprasad Shenai #define RL(s, v) R3("lu", s, v)
2505dc9daab2SHariprasad Shenai 
2506dc9daab2SHariprasad Shenai 	if (r < eth_entries) {
2507dc9daab2SHariprasad Shenai 		int base_qset = r * 4;
2508dc9daab2SHariprasad Shenai 		const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
2509dc9daab2SHariprasad Shenai 		const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
2510dc9daab2SHariprasad Shenai 		int n = min(4, adap->sge.ethqsets - 4 * r);
2511dc9daab2SHariprasad Shenai 
2512dc9daab2SHariprasad Shenai 		S("QType:", "Ethernet");
2513dc9daab2SHariprasad Shenai 		S("Interface:",
2514dc9daab2SHariprasad Shenai 		  rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2515dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2516dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2517dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2518dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2519dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
25203051fa61SHariprasad Shenai #ifdef CONFIG_CHELSIO_T4_DCB
2521dc9daab2SHariprasad Shenai 		T("DCB Prio:", dcb_prio);
2522dc9daab2SHariprasad Shenai 		S3("u", "DCB PGID:",
2523dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
2524dc9daab2SHariprasad Shenai 		    4*(7-tx[i].dcb_prio)) & 0xf);
2525dc9daab2SHariprasad Shenai 		S3("u", "DCB PFC:",
2526dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
2527dc9daab2SHariprasad Shenai 		    1*(7-tx[i].dcb_prio)) & 0x1);
2528dc9daab2SHariprasad Shenai #endif
2529dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2530dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2531dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2532dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2533dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2534dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2535dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2536dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2537dc9daab2SHariprasad Shenai 		R("FL ID:", fl.cntxt_id);
2538dc9daab2SHariprasad Shenai 		R("FL size:", fl.size - 8);
2539dc9daab2SHariprasad Shenai 		R("FL pend:", fl.pend_cred);
2540dc9daab2SHariprasad Shenai 		R("FL avail:", fl.avail);
2541dc9daab2SHariprasad Shenai 		R("FL PIDX:", fl.pidx);
2542dc9daab2SHariprasad Shenai 		R("FL CIDX:", fl.cidx);
2543e106a4d9SHariprasad Shenai 		RL("RxPackets:", stats.pkts);
2544e106a4d9SHariprasad Shenai 		RL("RxCSO:", stats.rx_cso);
2545e106a4d9SHariprasad Shenai 		RL("VLANxtract:", stats.vlan_ex);
2546e106a4d9SHariprasad Shenai 		RL("LROmerged:", stats.lro_merged);
2547e106a4d9SHariprasad Shenai 		RL("LROpackets:", stats.lro_pkts);
2548e106a4d9SHariprasad Shenai 		RL("RxDrops:", stats.rx_drops);
2549e106a4d9SHariprasad Shenai 		TL("TSO:", tso);
2550e106a4d9SHariprasad Shenai 		TL("TxCSO:", tx_cso);
2551e106a4d9SHariprasad Shenai 		TL("VLANins:", vlan_ins);
2552e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2553e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2554e106a4d9SHariprasad Shenai 		TL("TxMapErr:", mapping_err);
2555e106a4d9SHariprasad Shenai 		RL("FLAllocErr:", fl.alloc_failed);
2556e106a4d9SHariprasad Shenai 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
255770055dd0SHariprasad Shenai 		RL("FLMapErr:", fl.mapping_err);
255870055dd0SHariprasad Shenai 		RL("FLLow:", fl.low);
2559e106a4d9SHariprasad Shenai 		RL("FLStarving:", fl.starving);
2560dc9daab2SHariprasad Shenai 
2561dc9daab2SHariprasad Shenai 	} else if (ctrl_idx < ctrl_entries) {
2562dc9daab2SHariprasad Shenai 		const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
2563dc9daab2SHariprasad Shenai 		int n = min(4, adap->params.nports - 4 * ctrl_idx);
2564dc9daab2SHariprasad Shenai 
2565dc9daab2SHariprasad Shenai 		S("QType:", "Control");
2566dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2567dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2568dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2569dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2570dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
2571e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2572e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2573dc9daab2SHariprasad Shenai 	} else if (fq_idx == 0) {
2574dc9daab2SHariprasad Shenai 		const struct sge_rspq *evtq = &adap->sge.fw_evtq;
2575dc9daab2SHariprasad Shenai 
2576dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
2577dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
2578dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
2579dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
2580dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
2581dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
2582dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr delay:",
2583dc9daab2SHariprasad Shenai 			   qtimer_val(adap, evtq));
2584dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
2585dc9daab2SHariprasad Shenai 			   adap->sge.counter_val[evtq->pktcnt_idx]);
2586dc9daab2SHariprasad Shenai 	}
2587dc9daab2SHariprasad Shenai #undef R
2588e106a4d9SHariprasad Shenai #undef RL
2589dc9daab2SHariprasad Shenai #undef T
2590e106a4d9SHariprasad Shenai #undef TL
2591dc9daab2SHariprasad Shenai #undef S
2592e106a4d9SHariprasad Shenai #undef R3
2593e106a4d9SHariprasad Shenai #undef T3
2594dc9daab2SHariprasad Shenai #undef S3
2595dc9daab2SHariprasad Shenai 	return 0;
2596dc9daab2SHariprasad Shenai }
2597dc9daab2SHariprasad Shenai 
2598dc9daab2SHariprasad Shenai static int sge_queue_entries(const struct adapter *adap)
2599dc9daab2SHariprasad Shenai {
2600dc9daab2SHariprasad Shenai 	return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
26010fbc81b3SHariprasad Shenai 	       DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
2602dc9daab2SHariprasad Shenai 	       DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
2603dc9daab2SHariprasad Shenai }
2604dc9daab2SHariprasad Shenai 
2605dc9daab2SHariprasad Shenai static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
2606dc9daab2SHariprasad Shenai {
2607dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2608dc9daab2SHariprasad Shenai 
2609dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2610dc9daab2SHariprasad Shenai }
2611dc9daab2SHariprasad Shenai 
2612dc9daab2SHariprasad Shenai static void sge_queue_stop(struct seq_file *seq, void *v)
2613dc9daab2SHariprasad Shenai {
2614dc9daab2SHariprasad Shenai }
2615dc9daab2SHariprasad Shenai 
2616dc9daab2SHariprasad Shenai static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
2617dc9daab2SHariprasad Shenai {
2618dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2619dc9daab2SHariprasad Shenai 
2620dc9daab2SHariprasad Shenai 	++*pos;
2621dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2622dc9daab2SHariprasad Shenai }
2623dc9daab2SHariprasad Shenai 
2624dc9daab2SHariprasad Shenai static const struct seq_operations sge_qinfo_seq_ops = {
2625dc9daab2SHariprasad Shenai 	.start = sge_queue_start,
2626dc9daab2SHariprasad Shenai 	.next  = sge_queue_next,
2627dc9daab2SHariprasad Shenai 	.stop  = sge_queue_stop,
2628dc9daab2SHariprasad Shenai 	.show  = sge_qinfo_show
2629dc9daab2SHariprasad Shenai };
2630dc9daab2SHariprasad Shenai 
2631dc9daab2SHariprasad Shenai static int sge_qinfo_open(struct inode *inode, struct file *file)
2632dc9daab2SHariprasad Shenai {
2633dc9daab2SHariprasad Shenai 	int res = seq_open(file, &sge_qinfo_seq_ops);
2634dc9daab2SHariprasad Shenai 
2635dc9daab2SHariprasad Shenai 	if (!res) {
2636dc9daab2SHariprasad Shenai 		struct seq_file *seq = file->private_data;
2637dc9daab2SHariprasad Shenai 
2638dc9daab2SHariprasad Shenai 		seq->private = inode->i_private;
2639dc9daab2SHariprasad Shenai 	}
2640dc9daab2SHariprasad Shenai 	return res;
2641dc9daab2SHariprasad Shenai }
2642dc9daab2SHariprasad Shenai 
2643dc9daab2SHariprasad Shenai static const struct file_operations sge_qinfo_debugfs_fops = {
2644dc9daab2SHariprasad Shenai 	.owner   = THIS_MODULE,
2645dc9daab2SHariprasad Shenai 	.open    = sge_qinfo_open,
2646dc9daab2SHariprasad Shenai 	.read    = seq_read,
2647dc9daab2SHariprasad Shenai 	.llseek  = seq_lseek,
2648dc9daab2SHariprasad Shenai 	.release = seq_release,
2649dc9daab2SHariprasad Shenai };
2650dc9daab2SHariprasad Shenai 
265149216c1cSHariprasad Shenai int mem_open(struct inode *inode, struct file *file)
265249216c1cSHariprasad Shenai {
265349216c1cSHariprasad Shenai 	unsigned int mem;
265449216c1cSHariprasad Shenai 	struct adapter *adap;
265549216c1cSHariprasad Shenai 
265649216c1cSHariprasad Shenai 	file->private_data = inode->i_private;
265749216c1cSHariprasad Shenai 
26588b4e6b3cSArjun Vynipadath 	mem = (uintptr_t)file->private_data & 0x7;
265949216c1cSHariprasad Shenai 	adap = file->private_data - mem;
266049216c1cSHariprasad Shenai 
266149216c1cSHariprasad Shenai 	(void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
266249216c1cSHariprasad Shenai 
266349216c1cSHariprasad Shenai 	return 0;
266449216c1cSHariprasad Shenai }
266549216c1cSHariprasad Shenai 
2666fd88b31aSHariprasad Shenai static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2667fd88b31aSHariprasad Shenai 			loff_t *ppos)
2668fd88b31aSHariprasad Shenai {
2669fd88b31aSHariprasad Shenai 	loff_t pos = *ppos;
2670fd88b31aSHariprasad Shenai 	loff_t avail = file_inode(file)->i_size;
26718b4e6b3cSArjun Vynipadath 	unsigned int mem = (uintptr_t)file->private_data & 0x7;
2672fd88b31aSHariprasad Shenai 	struct adapter *adap = file->private_data - mem;
2673fd88b31aSHariprasad Shenai 	__be32 *data;
2674fd88b31aSHariprasad Shenai 	int ret;
2675fd88b31aSHariprasad Shenai 
2676fd88b31aSHariprasad Shenai 	if (pos < 0)
2677fd88b31aSHariprasad Shenai 		return -EINVAL;
2678fd88b31aSHariprasad Shenai 	if (pos >= avail)
2679fd88b31aSHariprasad Shenai 		return 0;
2680fd88b31aSHariprasad Shenai 	if (count > avail - pos)
2681fd88b31aSHariprasad Shenai 		count = avail - pos;
2682fd88b31aSHariprasad Shenai 
2683752ade68SMichal Hocko 	data = kvzalloc(count, GFP_KERNEL);
2684fd88b31aSHariprasad Shenai 	if (!data)
2685fd88b31aSHariprasad Shenai 		return -ENOMEM;
2686fd88b31aSHariprasad Shenai 
2687fd88b31aSHariprasad Shenai 	spin_lock(&adap->win0_lock);
2688fd88b31aSHariprasad Shenai 	ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
2689fd88b31aSHariprasad Shenai 	spin_unlock(&adap->win0_lock);
2690fd88b31aSHariprasad Shenai 	if (ret) {
2691752ade68SMichal Hocko 		kvfree(data);
2692fd88b31aSHariprasad Shenai 		return ret;
2693fd88b31aSHariprasad Shenai 	}
2694fd88b31aSHariprasad Shenai 	ret = copy_to_user(buf, data, count);
2695fd88b31aSHariprasad Shenai 
2696752ade68SMichal Hocko 	kvfree(data);
2697fd88b31aSHariprasad Shenai 	if (ret)
2698fd88b31aSHariprasad Shenai 		return -EFAULT;
2699fd88b31aSHariprasad Shenai 
2700fd88b31aSHariprasad Shenai 	*ppos = pos + count;
2701fd88b31aSHariprasad Shenai 	return count;
2702fd88b31aSHariprasad Shenai }
2703fd88b31aSHariprasad Shenai static const struct file_operations mem_debugfs_fops = {
2704fd88b31aSHariprasad Shenai 	.owner   = THIS_MODULE,
2705fd88b31aSHariprasad Shenai 	.open    = simple_open,
2706fd88b31aSHariprasad Shenai 	.read    = mem_read,
2707fd88b31aSHariprasad Shenai 	.llseek  = default_llseek,
2708fd88b31aSHariprasad Shenai };
2709fd88b31aSHariprasad Shenai 
2710a4011fd4SHariprasad Shenai static int tid_info_show(struct seq_file *seq, void *v)
2711a4011fd4SHariprasad Shenai {
2712918341e0SGanesh Goudar 	unsigned int tid_start = 0;
2713a4011fd4SHariprasad Shenai 	struct adapter *adap = seq->private;
2714a4011fd4SHariprasad Shenai 	const struct tid_info *t = &adap->tids;
2715a4011fd4SHariprasad Shenai 	enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
2716a4011fd4SHariprasad Shenai 
2717918341e0SGanesh Goudar 	if (chip > CHELSIO_T5)
2718918341e0SGanesh Goudar 		tid_start = t4_read_reg(adap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
2719918341e0SGanesh Goudar 
2720a4011fd4SHariprasad Shenai 	if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
2721a4011fd4SHariprasad Shenai 		unsigned int sb;
27221dec4cecSGanesh Goudar 		seq_printf(seq, "Connections in use: %u\n",
27231dec4cecSGanesh Goudar 			   atomic_read(&t->conns_in_use));
2724a4011fd4SHariprasad Shenai 
2725a4011fd4SHariprasad Shenai 		if (chip <= CHELSIO_T5)
2726a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
2727a4011fd4SHariprasad Shenai 		else
2728a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
2729a4011fd4SHariprasad Shenai 
2730a4011fd4SHariprasad Shenai 		if (sb) {
2731918341e0SGanesh Goudar 			seq_printf(seq, "TID range: %u..%u/%u..%u", tid_start,
2732918341e0SGanesh Goudar 				   sb - 1, adap->tids.hash_base,
2733a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2734a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2735a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2736a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2737a4011fd4SHariprasad Shenai 		} else if (adap->flags & FW_OFLD_CONN) {
2738a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u/%u..%u",
2739a4011fd4SHariprasad Shenai 				   t->aftid_base,
2740a4011fd4SHariprasad Shenai 				   t->aftid_end,
2741a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2742a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2743a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2744a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2745a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2746a4011fd4SHariprasad Shenai 		} else {
2747a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u",
2748a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2749a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2750a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u\n",
2751a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2752a4011fd4SHariprasad Shenai 		}
2753a4011fd4SHariprasad Shenai 	} else if (t->ntids) {
27541dec4cecSGanesh Goudar 		seq_printf(seq, "Connections in use: %u\n",
27551dec4cecSGanesh Goudar 			   atomic_read(&t->conns_in_use));
27561dec4cecSGanesh Goudar 
2757918341e0SGanesh Goudar 		seq_printf(seq, "TID range: %u..%u", tid_start,
2758918341e0SGanesh Goudar 			   tid_start + t->ntids - 1);
2759a4011fd4SHariprasad Shenai 		seq_printf(seq, ", in use: %u\n",
2760a4011fd4SHariprasad Shenai 			   atomic_read(&t->tids_in_use));
2761a4011fd4SHariprasad Shenai 	}
2762a4011fd4SHariprasad Shenai 
2763a4011fd4SHariprasad Shenai 	if (t->nstids)
27641dec4cecSGanesh Goudar 		seq_printf(seq, "STID range: %u..%u, in use-IPv4/IPv6: %u/%u\n",
2765a4011fd4SHariprasad Shenai 			   (!t->stid_base &&
2766a4011fd4SHariprasad Shenai 			   (chip <= CHELSIO_T5)) ?
2767a4011fd4SHariprasad Shenai 			   t->stid_base + 1 : t->stid_base,
27681dec4cecSGanesh Goudar 			   t->stid_base + t->nstids - 1,
27691dec4cecSGanesh Goudar 			   t->stids_in_use - t->v6_stids_in_use,
27701dec4cecSGanesh Goudar 			   t->v6_stids_in_use);
27711dec4cecSGanesh Goudar 
2772a4011fd4SHariprasad Shenai 	if (t->natids)
2773a4011fd4SHariprasad Shenai 		seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
2774a4011fd4SHariprasad Shenai 			   t->natids - 1, t->atids_in_use);
2775a4011fd4SHariprasad Shenai 	seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
2776a4011fd4SHariprasad Shenai 		   t->ftid_base + t->nftids - 1);
2777a4011fd4SHariprasad Shenai 	if (t->nsftids)
2778a4011fd4SHariprasad Shenai 		seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
2779a4011fd4SHariprasad Shenai 			   t->sftid_base, t->sftid_base + t->nsftids - 2,
2780a4011fd4SHariprasad Shenai 			   t->sftids_in_use);
2781a4011fd4SHariprasad Shenai 	if (t->ntids)
2782a4011fd4SHariprasad Shenai 		seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
2783a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
2784a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
2785a4011fd4SHariprasad Shenai 	return 0;
2786a4011fd4SHariprasad Shenai }
2787a4011fd4SHariprasad Shenai 
2788a4011fd4SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(tid_info);
2789a4011fd4SHariprasad Shenai 
2790fd88b31aSHariprasad Shenai static void add_debugfs_mem(struct adapter *adap, const char *name,
2791fd88b31aSHariprasad Shenai 			    unsigned int idx, unsigned int size_mb)
2792fd88b31aSHariprasad Shenai {
2793d3757ba4SJoe Perches 	debugfs_create_file_size(name, 0400, adap->debugfs_root,
2794e59b4e91SDavid Howells 				 (void *)adap + idx, &mem_debugfs_fops,
2795e59b4e91SDavid Howells 				 size_mb << 20);
2796fd88b31aSHariprasad Shenai }
2797fd88b31aSHariprasad Shenai 
27985b377d11SHariprasad Shenai static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
27995b377d11SHariprasad Shenai 			       size_t count, loff_t *ppos)
28005b377d11SHariprasad Shenai {
28015b377d11SHariprasad Shenai 	int len;
28025b377d11SHariprasad Shenai 	const struct adapter *adap = filp->private_data;
28035b377d11SHariprasad Shenai 	char *buf;
28045b377d11SHariprasad Shenai 	ssize_t size = (adap->sge.egr_sz + 3) / 4 +
28055b377d11SHariprasad Shenai 			adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
28065b377d11SHariprasad Shenai 
28075b377d11SHariprasad Shenai 	buf = kzalloc(size, GFP_KERNEL);
28085b377d11SHariprasad Shenai 	if (!buf)
28095b377d11SHariprasad Shenai 		return -ENOMEM;
28105b377d11SHariprasad Shenai 
28115b377d11SHariprasad Shenai 	len = snprintf(buf, size - 1, "%*pb\n",
28125b377d11SHariprasad Shenai 		       adap->sge.egr_sz, adap->sge.blocked_fl);
28135b377d11SHariprasad Shenai 	len += sprintf(buf + len, "\n");
28145b377d11SHariprasad Shenai 	size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
2815752ade68SMichal Hocko 	kvfree(buf);
28165b377d11SHariprasad Shenai 	return size;
28175b377d11SHariprasad Shenai }
28185b377d11SHariprasad Shenai 
28195b377d11SHariprasad Shenai static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
28205b377d11SHariprasad Shenai 				size_t count, loff_t *ppos)
28215b377d11SHariprasad Shenai {
28225b377d11SHariprasad Shenai 	int err;
28235b377d11SHariprasad Shenai 	unsigned long *t;
28245b377d11SHariprasad Shenai 	struct adapter *adap = filp->private_data;
28255b377d11SHariprasad Shenai 
28265b377d11SHariprasad Shenai 	t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
28275b377d11SHariprasad Shenai 	if (!t)
28285b377d11SHariprasad Shenai 		return -ENOMEM;
28295b377d11SHariprasad Shenai 
28305b377d11SHariprasad Shenai 	err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
28315b377d11SHariprasad Shenai 	if (err)
28325b377d11SHariprasad Shenai 		return err;
28335b377d11SHariprasad Shenai 
28345b377d11SHariprasad Shenai 	bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
2835752ade68SMichal Hocko 	kvfree(t);
28365b377d11SHariprasad Shenai 	return count;
28375b377d11SHariprasad Shenai }
28385b377d11SHariprasad Shenai 
28395b377d11SHariprasad Shenai static const struct file_operations blocked_fl_fops = {
28405b377d11SHariprasad Shenai 	.owner   = THIS_MODULE,
2841524605e5SWei Yongjun 	.open    = simple_open,
28425b377d11SHariprasad Shenai 	.read    = blocked_fl_read,
28435b377d11SHariprasad Shenai 	.write   = blocked_fl_write,
28445b377d11SHariprasad Shenai 	.llseek  = generic_file_llseek,
28455b377d11SHariprasad Shenai };
28465b377d11SHariprasad Shenai 
28475888111cSHariprasad Shenai static void mem_region_show(struct seq_file *seq, const char *name,
28485888111cSHariprasad Shenai 			    unsigned int from, unsigned int to)
28495888111cSHariprasad Shenai {
28505888111cSHariprasad Shenai 	char buf[40];
28515888111cSHariprasad Shenai 
28525888111cSHariprasad Shenai 	string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
28535888111cSHariprasad Shenai 			sizeof(buf));
28545888111cSHariprasad Shenai 	seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
28555888111cSHariprasad Shenai }
28565888111cSHariprasad Shenai 
28575888111cSHariprasad Shenai static int meminfo_show(struct seq_file *seq, void *v)
28585888111cSHariprasad Shenai {
28595888111cSHariprasad Shenai 	static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
28604db0401fSRahul Lakkireddy 					       "MC0:", "MC1:", "HMA:"};
28615888111cSHariprasad Shenai 	struct adapter *adap = seq->private;
2862123e25c4SRahul Lakkireddy 	struct cudbg_meminfo meminfo;
2863123e25c4SRahul Lakkireddy 	int i, rc;
28645888111cSHariprasad Shenai 
2865123e25c4SRahul Lakkireddy 	memset(&meminfo, 0, sizeof(struct cudbg_meminfo));
2866123e25c4SRahul Lakkireddy 	rc = cudbg_fill_meminfo(adap, &meminfo);
2867123e25c4SRahul Lakkireddy 	if (rc)
2868123e25c4SRahul Lakkireddy 		return -ENXIO;
28695888111cSHariprasad Shenai 
2870123e25c4SRahul Lakkireddy 	for (i = 0; i < meminfo.avail_c; i++)
2871123e25c4SRahul Lakkireddy 		mem_region_show(seq, memory[meminfo.avail[i].idx],
2872123e25c4SRahul Lakkireddy 				meminfo.avail[i].base,
2873123e25c4SRahul Lakkireddy 				meminfo.avail[i].limit - 1);
28745888111cSHariprasad Shenai 
28755888111cSHariprasad Shenai 	seq_putc(seq, '\n');
2876123e25c4SRahul Lakkireddy 	for (i = 0; i < meminfo.mem_c; i++) {
2877123e25c4SRahul Lakkireddy 		if (meminfo.mem[i].idx >= ARRAY_SIZE(cudbg_region))
28785888111cSHariprasad Shenai 			continue;                        /* skip holes */
2879123e25c4SRahul Lakkireddy 		if (!meminfo.mem[i].limit)
2880123e25c4SRahul Lakkireddy 			meminfo.mem[i].limit =
2881123e25c4SRahul Lakkireddy 				i < meminfo.mem_c - 1 ?
2882123e25c4SRahul Lakkireddy 				meminfo.mem[i + 1].base - 1 : ~0;
2883123e25c4SRahul Lakkireddy 		mem_region_show(seq, cudbg_region[meminfo.mem[i].idx],
2884123e25c4SRahul Lakkireddy 				meminfo.mem[i].base, meminfo.mem[i].limit);
28855888111cSHariprasad Shenai 	}
28865888111cSHariprasad Shenai 
28875888111cSHariprasad Shenai 	seq_putc(seq, '\n');
2888123e25c4SRahul Lakkireddy 	mem_region_show(seq, "uP RAM:", meminfo.up_ram_lo, meminfo.up_ram_hi);
2889123e25c4SRahul Lakkireddy 	mem_region_show(seq, "uP Extmem2:", meminfo.up_extmem2_lo,
2890123e25c4SRahul Lakkireddy 			meminfo.up_extmem2_hi);
28915888111cSHariprasad Shenai 
28925888111cSHariprasad Shenai 	seq_printf(seq, "\n%u Rx pages of size %uKiB for %u channels\n",
2893123e25c4SRahul Lakkireddy 		   meminfo.rx_pages_data[0], meminfo.rx_pages_data[1],
2894123e25c4SRahul Lakkireddy 		   meminfo.rx_pages_data[2]);
28955888111cSHariprasad Shenai 
28965888111cSHariprasad Shenai 	seq_printf(seq, "%u Tx pages of size %u%ciB for %u channels\n",
2897123e25c4SRahul Lakkireddy 		   meminfo.tx_pages_data[0], meminfo.tx_pages_data[1],
2898123e25c4SRahul Lakkireddy 		   meminfo.tx_pages_data[2], meminfo.tx_pages_data[3]);
28995888111cSHariprasad Shenai 
2900123e25c4SRahul Lakkireddy 	seq_printf(seq, "%u p-structs\n\n", meminfo.p_structs);
2901123e25c4SRahul Lakkireddy 
2902123e25c4SRahul Lakkireddy 	for (i = 0; i < 4; i++)
29035888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
29045888111cSHariprasad Shenai 		seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
2905123e25c4SRahul Lakkireddy 			   i, meminfo.port_used[i], meminfo.port_alloc[i]);
2906123e25c4SRahul Lakkireddy 
2907123e25c4SRahul Lakkireddy 	for (i = 0; i < adap->params.arch.nchan; i++)
29085888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
29095888111cSHariprasad Shenai 		seq_printf(seq,
29105888111cSHariprasad Shenai 			   "Loopback %d using %u pages out of %u allocated\n",
2911123e25c4SRahul Lakkireddy 			   i, meminfo.loopback_used[i],
2912123e25c4SRahul Lakkireddy 			   meminfo.loopback_alloc[i]);
2913123e25c4SRahul Lakkireddy 
29145888111cSHariprasad Shenai 	return 0;
29155888111cSHariprasad Shenai }
29165888111cSHariprasad Shenai 
29175888111cSHariprasad Shenai static int meminfo_open(struct inode *inode, struct file *file)
29185888111cSHariprasad Shenai {
29195888111cSHariprasad Shenai 	return single_open(file, meminfo_show, inode->i_private);
29205888111cSHariprasad Shenai }
29215888111cSHariprasad Shenai 
29225888111cSHariprasad Shenai static const struct file_operations meminfo_fops = {
29235888111cSHariprasad Shenai 	.owner   = THIS_MODULE,
29245888111cSHariprasad Shenai 	.open    = meminfo_open,
29255888111cSHariprasad Shenai 	.read    = seq_read,
29265888111cSHariprasad Shenai 	.llseek  = seq_lseek,
29275888111cSHariprasad Shenai 	.release = single_release,
29285888111cSHariprasad Shenai };
2929ee0863baSHarsh Jain 
2930ee0863baSHarsh Jain static int chcr_show(struct seq_file *seq, void *v)
2931ee0863baSHarsh Jain {
2932ee0863baSHarsh Jain 	struct adapter *adap = seq->private;
2933ee0863baSHarsh Jain 
2934ee0863baSHarsh Jain 	seq_puts(seq, "Chelsio Crypto Accelerator Stats \n");
2935ee0863baSHarsh Jain 	seq_printf(seq, "Cipher Ops: %10u \n",
2936ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.cipher_rqst));
2937ee0863baSHarsh Jain 	seq_printf(seq, "Digest Ops: %10u \n",
2938ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.digest_rqst));
2939ee0863baSHarsh Jain 	seq_printf(seq, "Aead Ops: %10u \n",
2940ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.aead_rqst));
2941ee0863baSHarsh Jain 	seq_printf(seq, "Completion: %10u \n",
2942ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.complete));
2943ee0863baSHarsh Jain 	seq_printf(seq, "Error: %10u \n",
2944ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.error));
2945ee0863baSHarsh Jain 	seq_printf(seq, "Fallback: %10u \n",
2946ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.fallback));
2947a6ec572bSAtul Gupta 	seq_printf(seq, "IPSec PDU: %10u\n",
2948a6ec572bSAtul Gupta 		   atomic_read(&adap->chcr_stats.ipsec_cnt));
2949ee0863baSHarsh Jain 	return 0;
2950ee0863baSHarsh Jain }
2951ee0863baSHarsh Jain 
2952ee0863baSHarsh Jain 
2953ee0863baSHarsh Jain static int chcr_stats_open(struct inode *inode, struct file *file)
2954ee0863baSHarsh Jain {
2955ee0863baSHarsh Jain         return single_open(file, chcr_show, inode->i_private);
2956ee0863baSHarsh Jain }
2957ee0863baSHarsh Jain 
2958ee0863baSHarsh Jain static const struct file_operations chcr_stats_debugfs_fops = {
2959ee0863baSHarsh Jain         .owner   = THIS_MODULE,
2960ee0863baSHarsh Jain         .open    = chcr_stats_open,
2961ee0863baSHarsh Jain         .read    = seq_read,
2962ee0863baSHarsh Jain         .llseek  = seq_lseek,
2963ee0863baSHarsh Jain         .release = single_release,
2964ee0863baSHarsh Jain };
296531e5f5c3SRahul Lakkireddy 
296631e5f5c3SRahul Lakkireddy #define PRINT_ADAP_STATS(string, value) \
296731e5f5c3SRahul Lakkireddy 	seq_printf(seq, "%-25s %-20llu\n", (string), \
296831e5f5c3SRahul Lakkireddy 		   (unsigned long long)(value))
296931e5f5c3SRahul Lakkireddy 
297031e5f5c3SRahul Lakkireddy #define PRINT_CH_STATS(string, value) \
297131e5f5c3SRahul Lakkireddy do { \
297231e5f5c3SRahul Lakkireddy 	seq_printf(seq, "%-25s ", (string)); \
297331e5f5c3SRahul Lakkireddy 	for (i = 0; i < adap->params.arch.nchan; i++) \
297431e5f5c3SRahul Lakkireddy 		seq_printf(seq, "%-20llu ", \
297531e5f5c3SRahul Lakkireddy 			   (unsigned long long)stats.value[i]); \
297631e5f5c3SRahul Lakkireddy 	seq_printf(seq, "\n"); \
297731e5f5c3SRahul Lakkireddy } while (0)
297831e5f5c3SRahul Lakkireddy 
297931e5f5c3SRahul Lakkireddy #define PRINT_CH_STATS2(string, value) \
298031e5f5c3SRahul Lakkireddy do { \
298131e5f5c3SRahul Lakkireddy 	seq_printf(seq, "%-25s ", (string)); \
298231e5f5c3SRahul Lakkireddy 	for (i = 0; i < adap->params.arch.nchan; i++) \
298331e5f5c3SRahul Lakkireddy 		seq_printf(seq, "%-20llu ", \
298431e5f5c3SRahul Lakkireddy 			   (unsigned long long)stats[i].value); \
298531e5f5c3SRahul Lakkireddy 	seq_printf(seq, "\n"); \
298631e5f5c3SRahul Lakkireddy } while (0)
298731e5f5c3SRahul Lakkireddy 
298831e5f5c3SRahul Lakkireddy static void show_tcp_stats(struct seq_file *seq)
298931e5f5c3SRahul Lakkireddy {
299031e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
299131e5f5c3SRahul Lakkireddy 	struct tp_tcp_stats v4, v6;
299231e5f5c3SRahul Lakkireddy 
299331e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
299431e5f5c3SRahul Lakkireddy 	t4_tp_get_tcp_stats(adap, &v4, &v6, false);
299531e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
299631e5f5c3SRahul Lakkireddy 
299731e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv4_out_rsts:", v4.tcp_out_rsts);
299831e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv4_in_segs:", v4.tcp_in_segs);
299931e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv4_out_segs:", v4.tcp_out_segs);
300031e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv4_retrans_segs:", v4.tcp_retrans_segs);
300131e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv6_out_rsts:", v6.tcp_out_rsts);
300231e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv6_in_segs:", v6.tcp_in_segs);
300331e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv6_out_segs:", v6.tcp_out_segs);
300431e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tcp_ipv6_retrans_segs:", v6.tcp_retrans_segs);
300531e5f5c3SRahul Lakkireddy }
300631e5f5c3SRahul Lakkireddy 
300731e5f5c3SRahul Lakkireddy static void show_ddp_stats(struct seq_file *seq)
300831e5f5c3SRahul Lakkireddy {
300931e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
301031e5f5c3SRahul Lakkireddy 	struct tp_usm_stats stats;
301131e5f5c3SRahul Lakkireddy 
301231e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
301331e5f5c3SRahul Lakkireddy 	t4_get_usm_stats(adap, &stats, false);
301431e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
301531e5f5c3SRahul Lakkireddy 
301631e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("usm_ddp_frames:", stats.frames);
301731e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("usm_ddp_octets:", stats.octets);
301831e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("usm_ddp_drops:", stats.drops);
301931e5f5c3SRahul Lakkireddy }
302031e5f5c3SRahul Lakkireddy 
302131e5f5c3SRahul Lakkireddy static void show_rdma_stats(struct seq_file *seq)
302231e5f5c3SRahul Lakkireddy {
302331e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
302431e5f5c3SRahul Lakkireddy 	struct tp_rdma_stats stats;
302531e5f5c3SRahul Lakkireddy 
302631e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
302731e5f5c3SRahul Lakkireddy 	t4_tp_get_rdma_stats(adap, &stats, false);
302831e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
302931e5f5c3SRahul Lakkireddy 
303031e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("rdma_no_rqe_mod_defer:", stats.rqe_dfr_mod);
303131e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("rdma_no_rqe_pkt_defer:", stats.rqe_dfr_pkt);
303231e5f5c3SRahul Lakkireddy }
303331e5f5c3SRahul Lakkireddy 
303431e5f5c3SRahul Lakkireddy static void show_tp_err_adapter_stats(struct seq_file *seq)
303531e5f5c3SRahul Lakkireddy {
303631e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
303731e5f5c3SRahul Lakkireddy 	struct tp_err_stats stats;
303831e5f5c3SRahul Lakkireddy 
303931e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
304031e5f5c3SRahul Lakkireddy 	t4_tp_get_err_stats(adap, &stats, false);
304131e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
304231e5f5c3SRahul Lakkireddy 
304331e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tp_err_ofld_no_neigh:", stats.ofld_no_neigh);
304431e5f5c3SRahul Lakkireddy 	PRINT_ADAP_STATS("tp_err_ofld_cong_defer:", stats.ofld_cong_defer);
304531e5f5c3SRahul Lakkireddy }
304631e5f5c3SRahul Lakkireddy 
304731e5f5c3SRahul Lakkireddy static void show_cpl_stats(struct seq_file *seq)
304831e5f5c3SRahul Lakkireddy {
304931e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
305031e5f5c3SRahul Lakkireddy 	struct tp_cpl_stats stats;
305131e5f5c3SRahul Lakkireddy 	u8 i;
305231e5f5c3SRahul Lakkireddy 
305331e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
305431e5f5c3SRahul Lakkireddy 	t4_tp_get_cpl_stats(adap, &stats, false);
305531e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
305631e5f5c3SRahul Lakkireddy 
305731e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_cpl_requests:", req);
305831e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_cpl_responses:", rsp);
305931e5f5c3SRahul Lakkireddy }
306031e5f5c3SRahul Lakkireddy 
306131e5f5c3SRahul Lakkireddy static void show_tp_err_channel_stats(struct seq_file *seq)
306231e5f5c3SRahul Lakkireddy {
306331e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
306431e5f5c3SRahul Lakkireddy 	struct tp_err_stats stats;
306531e5f5c3SRahul Lakkireddy 	u8 i;
306631e5f5c3SRahul Lakkireddy 
306731e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
306831e5f5c3SRahul Lakkireddy 	t4_tp_get_err_stats(adap, &stats, false);
306931e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
307031e5f5c3SRahul Lakkireddy 
307131e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_mac_in_errs:", mac_in_errs);
307231e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_hdr_in_errs:", hdr_in_errs);
307331e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_tcp_in_errs:", tcp_in_errs);
307431e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_tcp6_in_errs:", tcp6_in_errs);
307531e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_tnl_cong_drops:", tnl_cong_drops);
307631e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_tnl_tx_drops:", tnl_tx_drops);
307731e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_ofld_vlan_drops:", ofld_vlan_drops);
307831e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS("tp_ofld_chan_drops:", ofld_chan_drops);
307931e5f5c3SRahul Lakkireddy }
308031e5f5c3SRahul Lakkireddy 
308131e5f5c3SRahul Lakkireddy static void show_fcoe_stats(struct seq_file *seq)
308231e5f5c3SRahul Lakkireddy {
308331e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
308431e5f5c3SRahul Lakkireddy 	struct tp_fcoe_stats stats[NCHAN];
308531e5f5c3SRahul Lakkireddy 	u8 i;
308631e5f5c3SRahul Lakkireddy 
308731e5f5c3SRahul Lakkireddy 	spin_lock(&adap->stats_lock);
308831e5f5c3SRahul Lakkireddy 	for (i = 0; i < adap->params.arch.nchan; i++)
308931e5f5c3SRahul Lakkireddy 		t4_get_fcoe_stats(adap, i, &stats[i], false);
309031e5f5c3SRahul Lakkireddy 	spin_unlock(&adap->stats_lock);
309131e5f5c3SRahul Lakkireddy 
309231e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS2("fcoe_octets_ddp", octets_ddp);
309331e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS2("fcoe_frames_ddp", frames_ddp);
309431e5f5c3SRahul Lakkireddy 	PRINT_CH_STATS2("fcoe_frames_drop", frames_drop);
309531e5f5c3SRahul Lakkireddy }
309631e5f5c3SRahul Lakkireddy 
309731e5f5c3SRahul Lakkireddy #undef PRINT_CH_STATS2
309831e5f5c3SRahul Lakkireddy #undef PRINT_CH_STATS
309931e5f5c3SRahul Lakkireddy #undef PRINT_ADAP_STATS
310031e5f5c3SRahul Lakkireddy 
310131e5f5c3SRahul Lakkireddy static int tp_stats_show(struct seq_file *seq, void *v)
310231e5f5c3SRahul Lakkireddy {
310331e5f5c3SRahul Lakkireddy 	struct adapter *adap = seq->private;
310431e5f5c3SRahul Lakkireddy 
310531e5f5c3SRahul Lakkireddy 	seq_puts(seq, "\n--------Adapter Stats--------\n");
310631e5f5c3SRahul Lakkireddy 	show_tcp_stats(seq);
310731e5f5c3SRahul Lakkireddy 	show_ddp_stats(seq);
310831e5f5c3SRahul Lakkireddy 	show_rdma_stats(seq);
310931e5f5c3SRahul Lakkireddy 	show_tp_err_adapter_stats(seq);
311031e5f5c3SRahul Lakkireddy 
311131e5f5c3SRahul Lakkireddy 	seq_puts(seq, "\n-------- Channel Stats --------\n");
311231e5f5c3SRahul Lakkireddy 	if (adap->params.arch.nchan == NCHAN)
311331e5f5c3SRahul Lakkireddy 		seq_printf(seq, "%-25s %-20s %-20s %-20s %-20s\n",
311431e5f5c3SRahul Lakkireddy 			   " ", "channel 0", "channel 1",
311531e5f5c3SRahul Lakkireddy 			   "channel 2", "channel 3");
311631e5f5c3SRahul Lakkireddy 	else
311731e5f5c3SRahul Lakkireddy 		seq_printf(seq, "%-25s %-20s %-20s\n",
311831e5f5c3SRahul Lakkireddy 			   " ", "channel 0", "channel 1");
311931e5f5c3SRahul Lakkireddy 	show_cpl_stats(seq);
312031e5f5c3SRahul Lakkireddy 	show_tp_err_channel_stats(seq);
312131e5f5c3SRahul Lakkireddy 	show_fcoe_stats(seq);
312231e5f5c3SRahul Lakkireddy 
312331e5f5c3SRahul Lakkireddy 	return 0;
312431e5f5c3SRahul Lakkireddy }
312531e5f5c3SRahul Lakkireddy 
312631e5f5c3SRahul Lakkireddy DEFINE_SIMPLE_DEBUGFS_FILE(tp_stats);
312731e5f5c3SRahul Lakkireddy 
3128fd88b31aSHariprasad Shenai /* Add an array of Debug FS files.
3129fd88b31aSHariprasad Shenai  */
3130fd88b31aSHariprasad Shenai void add_debugfs_files(struct adapter *adap,
3131fd88b31aSHariprasad Shenai 		       struct t4_debugfs_entry *files,
3132fd88b31aSHariprasad Shenai 		       unsigned int nfiles)
3133fd88b31aSHariprasad Shenai {
3134fd88b31aSHariprasad Shenai 	int i;
3135fd88b31aSHariprasad Shenai 
3136fd88b31aSHariprasad Shenai 	/* debugfs support is best effort */
3137fd88b31aSHariprasad Shenai 	for (i = 0; i < nfiles; i++)
3138fd88b31aSHariprasad Shenai 		debugfs_create_file(files[i].name, files[i].mode,
3139fd88b31aSHariprasad Shenai 				    adap->debugfs_root,
3140fd88b31aSHariprasad Shenai 				    (void *)adap + files[i].data,
3141fd88b31aSHariprasad Shenai 				    files[i].ops);
3142fd88b31aSHariprasad Shenai }
3143fd88b31aSHariprasad Shenai 
3144fd88b31aSHariprasad Shenai int t4_setup_debugfs(struct adapter *adap)
3145fd88b31aSHariprasad Shenai {
3146fd88b31aSHariprasad Shenai 	int i;
31473ccc6cf7SHariprasad Shenai 	u32 size = 0;
314849216c1cSHariprasad Shenai 	struct dentry *de;
3149fd88b31aSHariprasad Shenai 
3150fd88b31aSHariprasad Shenai 	static struct t4_debugfs_entry t4_debugfs_files[] = {
3151d3757ba4SJoe Perches 		{ "cim_la", &cim_la_fops, 0400, 0 },
3152d3757ba4SJoe Perches 		{ "cim_pif_la", &cim_pif_la_fops, 0400, 0 },
3153d3757ba4SJoe Perches 		{ "cim_ma_la", &cim_ma_la_fops, 0400, 0 },
3154d3757ba4SJoe Perches 		{ "cim_qcfg", &cim_qcfg_fops, 0400, 0 },
3155d3757ba4SJoe Perches 		{ "clk", &clk_debugfs_fops, 0400, 0 },
3156d3757ba4SJoe Perches 		{ "devlog", &devlog_fops, 0400, 0 },
3157d3757ba4SJoe Perches 		{ "mboxlog", &mboxlog_fops, 0400, 0 },
3158d3757ba4SJoe Perches 		{ "mbox0", &mbox_debugfs_fops, 0600, 0 },
3159d3757ba4SJoe Perches 		{ "mbox1", &mbox_debugfs_fops, 0600, 1 },
3160d3757ba4SJoe Perches 		{ "mbox2", &mbox_debugfs_fops, 0600, 2 },
3161d3757ba4SJoe Perches 		{ "mbox3", &mbox_debugfs_fops, 0600, 3 },
3162d3757ba4SJoe Perches 		{ "mbox4", &mbox_debugfs_fops, 0600, 4 },
3163d3757ba4SJoe Perches 		{ "mbox5", &mbox_debugfs_fops, 0600, 5 },
3164d3757ba4SJoe Perches 		{ "mbox6", &mbox_debugfs_fops, 0600, 6 },
3165d3757ba4SJoe Perches 		{ "mbox7", &mbox_debugfs_fops, 0600, 7 },
3166d3757ba4SJoe Perches 		{ "trace0", &mps_trc_debugfs_fops, 0600, 0 },
3167d3757ba4SJoe Perches 		{ "trace1", &mps_trc_debugfs_fops, 0600, 1 },
3168d3757ba4SJoe Perches 		{ "trace2", &mps_trc_debugfs_fops, 0600, 2 },
3169d3757ba4SJoe Perches 		{ "trace3", &mps_trc_debugfs_fops, 0600, 3 },
3170d3757ba4SJoe Perches 		{ "l2t", &t4_l2t_fops, 0400, 0},
3171d3757ba4SJoe Perches 		{ "mps_tcam", &mps_tcam_debugfs_fops, 0400, 0 },
3172d3757ba4SJoe Perches 		{ "rss", &rss_debugfs_fops, 0400, 0 },
3173d3757ba4SJoe Perches 		{ "rss_config", &rss_config_debugfs_fops, 0400, 0 },
3174d3757ba4SJoe Perches 		{ "rss_key", &rss_key_debugfs_fops, 0400, 0 },
3175d3757ba4SJoe Perches 		{ "rss_pf_config", &rss_pf_config_debugfs_fops, 0400, 0 },
3176d3757ba4SJoe Perches 		{ "rss_vf_config", &rss_vf_config_debugfs_fops, 0400, 0 },
31770eaec62aSCasey Leedom 		{ "resources", &resources_debugfs_fops, 0400, 0 },
3178d3757ba4SJoe Perches 		{ "sge_qinfo", &sge_qinfo_debugfs_fops, 0400, 0 },
3179d3757ba4SJoe Perches 		{ "ibq_tp0",  &cim_ibq_fops, 0400, 0 },
3180d3757ba4SJoe Perches 		{ "ibq_tp1",  &cim_ibq_fops, 0400, 1 },
3181d3757ba4SJoe Perches 		{ "ibq_ulp",  &cim_ibq_fops, 0400, 2 },
3182d3757ba4SJoe Perches 		{ "ibq_sge0", &cim_ibq_fops, 0400, 3 },
3183d3757ba4SJoe Perches 		{ "ibq_sge1", &cim_ibq_fops, 0400, 4 },
3184d3757ba4SJoe Perches 		{ "ibq_ncsi", &cim_ibq_fops, 0400, 5 },
3185d3757ba4SJoe Perches 		{ "obq_ulp0", &cim_obq_fops, 0400, 0 },
3186d3757ba4SJoe Perches 		{ "obq_ulp1", &cim_obq_fops, 0400, 1 },
3187d3757ba4SJoe Perches 		{ "obq_ulp2", &cim_obq_fops, 0400, 2 },
3188d3757ba4SJoe Perches 		{ "obq_ulp3", &cim_obq_fops, 0400, 3 },
3189d3757ba4SJoe Perches 		{ "obq_sge",  &cim_obq_fops, 0400, 4 },
3190d3757ba4SJoe Perches 		{ "obq_ncsi", &cim_obq_fops, 0400, 5 },
3191d3757ba4SJoe Perches 		{ "tp_la", &tp_la_fops, 0400, 0 },
3192d3757ba4SJoe Perches 		{ "ulprx_la", &ulprx_la_fops, 0400, 0 },
3193d3757ba4SJoe Perches 		{ "sensors", &sensors_debugfs_fops, 0400, 0 },
3194d3757ba4SJoe Perches 		{ "pm_stats", &pm_stats_debugfs_fops, 0400, 0 },
3195d3757ba4SJoe Perches 		{ "tx_rate", &tx_rate_debugfs_fops, 0400, 0 },
3196d3757ba4SJoe Perches 		{ "cctrl", &cctrl_tbl_debugfs_fops, 0400, 0 },
3197b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
3198d3757ba4SJoe Perches 		{ "clip_tbl", &clip_tbl_debugfs_fops, 0400, 0 },
3199b5a02f50SAnish Bhatt #endif
3200d3757ba4SJoe Perches 		{ "tids", &tid_info_debugfs_fops, 0400, 0},
3201d3757ba4SJoe Perches 		{ "blocked_fl", &blocked_fl_fops, 0600, 0 },
3202d3757ba4SJoe Perches 		{ "meminfo", &meminfo_fops, 0400, 0 },
3203d3757ba4SJoe Perches 		{ "crypto", &chcr_stats_debugfs_fops, 0400, 0 },
320431e5f5c3SRahul Lakkireddy 		{ "tp_stats", &tp_stats_debugfs_fops, 0400, 0 },
3205fd88b31aSHariprasad Shenai 	};
3206fd88b31aSHariprasad Shenai 
3207c778af7dSHariprasad Shenai 	/* Debug FS nodes common to all T5 and later adapters.
3208c778af7dSHariprasad Shenai 	 */
3209c778af7dSHariprasad Shenai 	static struct t4_debugfs_entry t5_debugfs_files[] = {
3210d3757ba4SJoe Perches 		{ "obq_sge_rx_q0", &cim_obq_fops, 0400, 6 },
3211d3757ba4SJoe Perches 		{ "obq_sge_rx_q1", &cim_obq_fops, 0400, 7 },
3212c778af7dSHariprasad Shenai 	};
3213c778af7dSHariprasad Shenai 
3214fd88b31aSHariprasad Shenai 	add_debugfs_files(adap,
3215fd88b31aSHariprasad Shenai 			  t4_debugfs_files,
3216fd88b31aSHariprasad Shenai 			  ARRAY_SIZE(t4_debugfs_files));
3217c778af7dSHariprasad Shenai 	if (!is_t4(adap->params.chip))
3218c778af7dSHariprasad Shenai 		add_debugfs_files(adap,
3219c778af7dSHariprasad Shenai 				  t5_debugfs_files,
3220c778af7dSHariprasad Shenai 				  ARRAY_SIZE(t5_debugfs_files));
3221fd88b31aSHariprasad Shenai 
32226559a7e8SHariprasad Shenai 	i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
32236559a7e8SHariprasad Shenai 	if (i & EDRAM0_ENABLE_F) {
32246559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
32256559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
3226fd88b31aSHariprasad Shenai 	}
32276559a7e8SHariprasad Shenai 	if (i & EDRAM1_ENABLE_F) {
32286559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
32296559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
3230fd88b31aSHariprasad Shenai 	}
32313ccc6cf7SHariprasad Shenai 	if (is_t5(adap->params.chip)) {
32326559a7e8SHariprasad Shenai 		if (i & EXT_MEM0_ENABLE_F) {
32336559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
3234fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc0", MEM_MC0,
32356559a7e8SHariprasad Shenai 					EXT_MEM0_SIZE_G(size));
3236fd88b31aSHariprasad Shenai 		}
32376559a7e8SHariprasad Shenai 		if (i & EXT_MEM1_ENABLE_F) {
32386559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
3239fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc1", MEM_MC1,
32406559a7e8SHariprasad Shenai 					EXT_MEM1_SIZE_G(size));
3241fd88b31aSHariprasad Shenai 		}
32423ccc6cf7SHariprasad Shenai 	} else {
324321a44763SDan Carpenter 		if (i & EXT_MEM_ENABLE_F) {
32443ccc6cf7SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
32453ccc6cf7SHariprasad Shenai 			add_debugfs_mem(adap, "mc", MEM_MC,
32463ccc6cf7SHariprasad Shenai 					EXT_MEM_SIZE_G(size));
3247fd88b31aSHariprasad Shenai 		}
32488b4e6b3cSArjun Vynipadath 
32498b4e6b3cSArjun Vynipadath 		if (i & HMA_MUX_F) {
32508b4e6b3cSArjun Vynipadath 			size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
32518b4e6b3cSArjun Vynipadath 			add_debugfs_mem(adap, "hma", MEM_HMA,
32528b4e6b3cSArjun Vynipadath 					EXT_MEM1_SIZE_G(size));
32538b4e6b3cSArjun Vynipadath 		}
325421a44763SDan Carpenter 	}
325549216c1cSHariprasad Shenai 
3256d3757ba4SJoe Perches 	de = debugfs_create_file_size("flash", 0400, adap->debugfs_root, adap,
3257c1d81b1cSDavid Howells 				      &flash_debugfs_fops, adap->params.sf_size);
3258d3757ba4SJoe Perches 	debugfs_create_bool("use_backdoor", 0600,
32590b2c2a93SHariprasad Shenai 			    adap->debugfs_root, &adap->use_bd);
3260d3757ba4SJoe Perches 	debugfs_create_bool("trace_rss", 0600,
32618e3d04fdSHariprasad Shenai 			    adap->debugfs_root, &adap->trace_rss);
326249216c1cSHariprasad Shenai 
3263fd88b31aSHariprasad Shenai 	return 0;
3264fd88b31aSHariprasad Shenai }
3265