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"
48fd88b31aSHariprasad Shenai 
49f1ff24aaSHariprasad Shenai /* generic seq_file support for showing a table of size rows x width. */
50f1ff24aaSHariprasad Shenai static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
51f1ff24aaSHariprasad Shenai {
52f1ff24aaSHariprasad Shenai 	pos -= tb->skip_first;
53f1ff24aaSHariprasad Shenai 	return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
54f1ff24aaSHariprasad Shenai }
55f1ff24aaSHariprasad Shenai 
56f1ff24aaSHariprasad Shenai static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
57f1ff24aaSHariprasad Shenai {
58f1ff24aaSHariprasad Shenai 	struct seq_tab *tb = seq->private;
59f1ff24aaSHariprasad Shenai 
60f1ff24aaSHariprasad Shenai 	if (tb->skip_first && *pos == 0)
61f1ff24aaSHariprasad Shenai 		return SEQ_START_TOKEN;
62f1ff24aaSHariprasad Shenai 
63f1ff24aaSHariprasad Shenai 	return seq_tab_get_idx(tb, *pos);
64f1ff24aaSHariprasad Shenai }
65f1ff24aaSHariprasad Shenai 
66f1ff24aaSHariprasad Shenai static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
67f1ff24aaSHariprasad Shenai {
68f1ff24aaSHariprasad Shenai 	v = seq_tab_get_idx(seq->private, *pos + 1);
69f1ff24aaSHariprasad Shenai 	if (v)
70f1ff24aaSHariprasad Shenai 		++*pos;
71f1ff24aaSHariprasad Shenai 	return v;
72f1ff24aaSHariprasad Shenai }
73f1ff24aaSHariprasad Shenai 
74f1ff24aaSHariprasad Shenai static void seq_tab_stop(struct seq_file *seq, void *v)
75f1ff24aaSHariprasad Shenai {
76f1ff24aaSHariprasad Shenai }
77f1ff24aaSHariprasad Shenai 
78f1ff24aaSHariprasad Shenai static int seq_tab_show(struct seq_file *seq, void *v)
79f1ff24aaSHariprasad Shenai {
80f1ff24aaSHariprasad Shenai 	const struct seq_tab *tb = seq->private;
81f1ff24aaSHariprasad Shenai 
82f1ff24aaSHariprasad Shenai 	return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
83f1ff24aaSHariprasad Shenai }
84f1ff24aaSHariprasad Shenai 
85f1ff24aaSHariprasad Shenai static const struct seq_operations seq_tab_ops = {
86f1ff24aaSHariprasad Shenai 	.start = seq_tab_start,
87f1ff24aaSHariprasad Shenai 	.next  = seq_tab_next,
88f1ff24aaSHariprasad Shenai 	.stop  = seq_tab_stop,
89f1ff24aaSHariprasad Shenai 	.show  = seq_tab_show
90f1ff24aaSHariprasad Shenai };
91f1ff24aaSHariprasad Shenai 
92f1ff24aaSHariprasad Shenai struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
93f1ff24aaSHariprasad Shenai 			     unsigned int width, unsigned int have_header,
94f1ff24aaSHariprasad Shenai 			     int (*show)(struct seq_file *seq, void *v, int i))
95f1ff24aaSHariprasad Shenai {
96f1ff24aaSHariprasad Shenai 	struct seq_tab *p;
97f1ff24aaSHariprasad Shenai 
98f1ff24aaSHariprasad Shenai 	p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
99f1ff24aaSHariprasad Shenai 	if (p) {
100f1ff24aaSHariprasad Shenai 		p->show = show;
101f1ff24aaSHariprasad Shenai 		p->rows = rows;
102f1ff24aaSHariprasad Shenai 		p->width = width;
103f1ff24aaSHariprasad Shenai 		p->skip_first = have_header != 0;
104f1ff24aaSHariprasad Shenai 	}
105f1ff24aaSHariprasad Shenai 	return p;
106f1ff24aaSHariprasad Shenai }
107f1ff24aaSHariprasad Shenai 
108c778af7dSHariprasad Shenai /* Trim the size of a seq_tab to the supplied number of rows.  The operation is
109c778af7dSHariprasad Shenai  * irreversible.
110c778af7dSHariprasad Shenai  */
111c778af7dSHariprasad Shenai static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
112c778af7dSHariprasad Shenai {
113c778af7dSHariprasad Shenai 	if (new_rows > p->rows)
114c778af7dSHariprasad Shenai 		return -EINVAL;
115c778af7dSHariprasad Shenai 	p->rows = new_rows;
116c778af7dSHariprasad Shenai 	return 0;
117c778af7dSHariprasad Shenai }
118c778af7dSHariprasad Shenai 
119f1ff24aaSHariprasad Shenai static int cim_la_show(struct seq_file *seq, void *v, int idx)
120f1ff24aaSHariprasad Shenai {
121f1ff24aaSHariprasad Shenai 	if (v == SEQ_START_TOKEN)
122f1ff24aaSHariprasad Shenai 		seq_puts(seq, "Status   Data      PC     LS0Stat  LS0Addr "
123f1ff24aaSHariprasad Shenai 			 "            LS0Data\n");
124f1ff24aaSHariprasad Shenai 	else {
125f1ff24aaSHariprasad Shenai 		const u32 *p = v;
126f1ff24aaSHariprasad Shenai 
127f1ff24aaSHariprasad Shenai 		seq_printf(seq,
128f1ff24aaSHariprasad Shenai 			   "  %02x  %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
129f1ff24aaSHariprasad Shenai 			   (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
130f1ff24aaSHariprasad Shenai 			   p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
131f1ff24aaSHariprasad Shenai 			   p[6], p[7]);
132f1ff24aaSHariprasad Shenai 	}
133f1ff24aaSHariprasad Shenai 	return 0;
134f1ff24aaSHariprasad Shenai }
135f1ff24aaSHariprasad Shenai 
136f1ff24aaSHariprasad Shenai static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
137f1ff24aaSHariprasad Shenai {
138f1ff24aaSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
139f1ff24aaSHariprasad Shenai 		seq_puts(seq, "Status   Data      PC\n");
140f1ff24aaSHariprasad Shenai 	} else {
141f1ff24aaSHariprasad Shenai 		const u32 *p = v;
142f1ff24aaSHariprasad Shenai 
143f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %08x %08x\n", p[5] & 0xff, p[6],
144f1ff24aaSHariprasad Shenai 			   p[7]);
145f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %02x%06x %02x%06x\n",
146f1ff24aaSHariprasad Shenai 			   (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
147f1ff24aaSHariprasad Shenai 			   p[4] & 0xff, p[5] >> 8);
148f1ff24aaSHariprasad Shenai 		seq_printf(seq, "  %02x   %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
149f1ff24aaSHariprasad Shenai 			   p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
150f1ff24aaSHariprasad Shenai 	}
151f1ff24aaSHariprasad Shenai 	return 0;
152f1ff24aaSHariprasad Shenai }
153f1ff24aaSHariprasad Shenai 
154b7660642SHariprasad Shenai static int cim_la_show_t6(struct seq_file *seq, void *v, int idx)
155b7660642SHariprasad Shenai {
156b7660642SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
157b7660642SHariprasad Shenai 		seq_puts(seq, "Status   Inst    Data      PC     LS0Stat  "
158b7660642SHariprasad Shenai 			 "LS0Addr  LS0Data  LS1Stat  LS1Addr  LS1Data\n");
159b7660642SHariprasad Shenai 	} else {
160b7660642SHariprasad Shenai 		const u32 *p = v;
161b7660642SHariprasad Shenai 
162b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x %08x %08x %08x %08x %08x %08x\n",
163b7660642SHariprasad Shenai 			   (p[9] >> 16) & 0xff,       /* Status */
164b7660642SHariprasad Shenai 			   p[9] & 0xffff, p[8] >> 16, /* Inst */
165b7660642SHariprasad Shenai 			   p[8] & 0xffff, p[7] >> 16, /* Data */
166b7660642SHariprasad Shenai 			   p[7] & 0xffff, p[6] >> 16, /* PC */
167b7660642SHariprasad Shenai 			   p[2], p[1], p[0],      /* LS0 Stat, Addr and Data */
168b7660642SHariprasad Shenai 			   p[5], p[4], p[3]);     /* LS1 Stat, Addr and Data */
169b7660642SHariprasad Shenai 	}
170b7660642SHariprasad Shenai 	return 0;
171b7660642SHariprasad Shenai }
172b7660642SHariprasad Shenai 
173b7660642SHariprasad Shenai static int cim_la_show_pc_t6(struct seq_file *seq, void *v, int idx)
174b7660642SHariprasad Shenai {
175b7660642SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
176b7660642SHariprasad Shenai 		seq_puts(seq, "Status   Inst    Data      PC\n");
177b7660642SHariprasad Shenai 	} else {
178b7660642SHariprasad Shenai 		const u32 *p = v;
179b7660642SHariprasad Shenai 
180b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %08x %08x %08x\n",
181b7660642SHariprasad Shenai 			   p[3] & 0xff, p[2], p[1], p[0]);
182b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %02x%06x %02x%06x %02x%06x\n",
183b7660642SHariprasad Shenai 			   (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
184b7660642SHariprasad Shenai 			   p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
185b7660642SHariprasad Shenai 		seq_printf(seq, "  %02x   %04x%04x %04x%04x %04x%04x\n",
186b7660642SHariprasad Shenai 			   (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
187b7660642SHariprasad Shenai 			   p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
188b7660642SHariprasad Shenai 			   p[6] >> 16);
189b7660642SHariprasad Shenai 	}
190b7660642SHariprasad Shenai 	return 0;
191b7660642SHariprasad Shenai }
192b7660642SHariprasad Shenai 
193f1ff24aaSHariprasad Shenai static int cim_la_open(struct inode *inode, struct file *file)
194f1ff24aaSHariprasad Shenai {
195f1ff24aaSHariprasad Shenai 	int ret;
196f1ff24aaSHariprasad Shenai 	unsigned int cfg;
197f1ff24aaSHariprasad Shenai 	struct seq_tab *p;
198f1ff24aaSHariprasad Shenai 	struct adapter *adap = inode->i_private;
199f1ff24aaSHariprasad Shenai 
200f1ff24aaSHariprasad Shenai 	ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
201f1ff24aaSHariprasad Shenai 	if (ret)
202f1ff24aaSHariprasad Shenai 		return ret;
203f1ff24aaSHariprasad Shenai 
204b7660642SHariprasad Shenai 	if (is_t6(adap->params.chip)) {
205b7660642SHariprasad Shenai 		/* +1 to account for integer division of CIMLA_SIZE/10 */
206b7660642SHariprasad Shenai 		p = seq_open_tab(file, (adap->params.cim_la_size / 10) + 1,
207b7660642SHariprasad Shenai 				 10 * sizeof(u32), 1,
208f1ff24aaSHariprasad Shenai 				 cfg & UPDBGLACAPTPCONLY_F ?
209b7660642SHariprasad Shenai 					cim_la_show_pc_t6 : cim_la_show_t6);
210b7660642SHariprasad Shenai 	} else {
211b7660642SHariprasad Shenai 		p = seq_open_tab(file, adap->params.cim_la_size / 8,
212b7660642SHariprasad Shenai 				 8 * sizeof(u32), 1,
213b7660642SHariprasad Shenai 				 cfg & UPDBGLACAPTPCONLY_F ? cim_la_show_3in1 :
214b7660642SHariprasad Shenai 							     cim_la_show);
215b7660642SHariprasad Shenai 	}
216f1ff24aaSHariprasad Shenai 	if (!p)
217f1ff24aaSHariprasad Shenai 		return -ENOMEM;
218f1ff24aaSHariprasad Shenai 
219f1ff24aaSHariprasad Shenai 	ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
220f1ff24aaSHariprasad Shenai 	if (ret)
221f1ff24aaSHariprasad Shenai 		seq_release_private(inode, file);
222f1ff24aaSHariprasad Shenai 	return ret;
223f1ff24aaSHariprasad Shenai }
224f1ff24aaSHariprasad Shenai 
225f1ff24aaSHariprasad Shenai static const struct file_operations cim_la_fops = {
226f1ff24aaSHariprasad Shenai 	.owner   = THIS_MODULE,
227f1ff24aaSHariprasad Shenai 	.open    = cim_la_open,
228f1ff24aaSHariprasad Shenai 	.read    = seq_read,
229f1ff24aaSHariprasad Shenai 	.llseek  = seq_lseek,
230f1ff24aaSHariprasad Shenai 	.release = seq_release_private
231f1ff24aaSHariprasad Shenai };
232f1ff24aaSHariprasad Shenai 
23319689609SHariprasad Shenai static int cim_pif_la_show(struct seq_file *seq, void *v, int idx)
23419689609SHariprasad Shenai {
23519689609SHariprasad Shenai 	const u32 *p = v;
23619689609SHariprasad Shenai 
23719689609SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
23819689609SHariprasad Shenai 		seq_puts(seq, "Cntl ID DataBE   Addr                 Data\n");
23919689609SHariprasad Shenai 	} else if (idx < CIM_PIFLA_SIZE) {
24019689609SHariprasad Shenai 		seq_printf(seq, " %02x  %02x  %04x  %08x %08x%08x%08x%08x\n",
24119689609SHariprasad Shenai 			   (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f,
24219689609SHariprasad Shenai 			   p[5] & 0xffff, p[4], p[3], p[2], p[1], p[0]);
24319689609SHariprasad Shenai 	} else {
24419689609SHariprasad Shenai 		if (idx == CIM_PIFLA_SIZE)
24519689609SHariprasad Shenai 			seq_puts(seq, "\nCntl ID               Data\n");
24619689609SHariprasad Shenai 		seq_printf(seq, " %02x  %02x %08x%08x%08x%08x\n",
24719689609SHariprasad Shenai 			   (p[4] >> 6) & 0xff, p[4] & 0x3f,
24819689609SHariprasad Shenai 			   p[3], p[2], p[1], p[0]);
24919689609SHariprasad Shenai 	}
25019689609SHariprasad Shenai 	return 0;
25119689609SHariprasad Shenai }
25219689609SHariprasad Shenai 
25319689609SHariprasad Shenai static int cim_pif_la_open(struct inode *inode, struct file *file)
25419689609SHariprasad Shenai {
25519689609SHariprasad Shenai 	struct seq_tab *p;
25619689609SHariprasad Shenai 	struct adapter *adap = inode->i_private;
25719689609SHariprasad Shenai 
25819689609SHariprasad Shenai 	p = seq_open_tab(file, 2 * CIM_PIFLA_SIZE, 6 * sizeof(u32), 1,
25919689609SHariprasad Shenai 			 cim_pif_la_show);
26019689609SHariprasad Shenai 	if (!p)
26119689609SHariprasad Shenai 		return -ENOMEM;
26219689609SHariprasad Shenai 
26319689609SHariprasad Shenai 	t4_cim_read_pif_la(adap, (u32 *)p->data,
26419689609SHariprasad Shenai 			   (u32 *)p->data + 6 * CIM_PIFLA_SIZE, NULL, NULL);
26519689609SHariprasad Shenai 	return 0;
26619689609SHariprasad Shenai }
26719689609SHariprasad Shenai 
26819689609SHariprasad Shenai static const struct file_operations cim_pif_la_fops = {
26919689609SHariprasad Shenai 	.owner   = THIS_MODULE,
27019689609SHariprasad Shenai 	.open    = cim_pif_la_open,
27119689609SHariprasad Shenai 	.read    = seq_read,
27219689609SHariprasad Shenai 	.llseek  = seq_lseek,
27319689609SHariprasad Shenai 	.release = seq_release_private
27419689609SHariprasad Shenai };
27519689609SHariprasad Shenai 
27626fae93fSHariprasad Shenai static int cim_ma_la_show(struct seq_file *seq, void *v, int idx)
27726fae93fSHariprasad Shenai {
27826fae93fSHariprasad Shenai 	const u32 *p = v;
27926fae93fSHariprasad Shenai 
28026fae93fSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
28126fae93fSHariprasad Shenai 		seq_puts(seq, "\n");
28226fae93fSHariprasad Shenai 	} else if (idx < CIM_MALA_SIZE) {
28326fae93fSHariprasad Shenai 		seq_printf(seq, "%02x%08x%08x%08x%08x\n",
28426fae93fSHariprasad Shenai 			   p[4], p[3], p[2], p[1], p[0]);
28526fae93fSHariprasad Shenai 	} else {
28626fae93fSHariprasad Shenai 		if (idx == CIM_MALA_SIZE)
28726fae93fSHariprasad Shenai 			seq_puts(seq,
28826fae93fSHariprasad Shenai 				 "\nCnt ID Tag UE       Data       RDY VLD\n");
28926fae93fSHariprasad Shenai 		seq_printf(seq, "%3u %2u  %x   %u %08x%08x  %u   %u\n",
29026fae93fSHariprasad Shenai 			   (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
29126fae93fSHariprasad Shenai 			   (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
29226fae93fSHariprasad Shenai 			   (p[1] >> 2) | ((p[2] & 3) << 30),
29326fae93fSHariprasad Shenai 			   (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
29426fae93fSHariprasad Shenai 			   p[0] & 1);
29526fae93fSHariprasad Shenai 	}
29626fae93fSHariprasad Shenai 	return 0;
29726fae93fSHariprasad Shenai }
29826fae93fSHariprasad Shenai 
29926fae93fSHariprasad Shenai static int cim_ma_la_open(struct inode *inode, struct file *file)
30026fae93fSHariprasad Shenai {
30126fae93fSHariprasad Shenai 	struct seq_tab *p;
30226fae93fSHariprasad Shenai 	struct adapter *adap = inode->i_private;
30326fae93fSHariprasad Shenai 
30426fae93fSHariprasad Shenai 	p = seq_open_tab(file, 2 * CIM_MALA_SIZE, 5 * sizeof(u32), 1,
30526fae93fSHariprasad Shenai 			 cim_ma_la_show);
30626fae93fSHariprasad Shenai 	if (!p)
30726fae93fSHariprasad Shenai 		return -ENOMEM;
30826fae93fSHariprasad Shenai 
30926fae93fSHariprasad Shenai 	t4_cim_read_ma_la(adap, (u32 *)p->data,
31026fae93fSHariprasad Shenai 			  (u32 *)p->data + 5 * CIM_MALA_SIZE);
31126fae93fSHariprasad Shenai 	return 0;
31226fae93fSHariprasad Shenai }
31326fae93fSHariprasad Shenai 
31426fae93fSHariprasad Shenai static const struct file_operations cim_ma_la_fops = {
31526fae93fSHariprasad Shenai 	.owner   = THIS_MODULE,
31626fae93fSHariprasad Shenai 	.open    = cim_ma_la_open,
31726fae93fSHariprasad Shenai 	.read    = seq_read,
31826fae93fSHariprasad Shenai 	.llseek  = seq_lseek,
31926fae93fSHariprasad Shenai 	.release = seq_release_private
32026fae93fSHariprasad Shenai };
32126fae93fSHariprasad Shenai 
32274b3092cSHariprasad Shenai static int cim_qcfg_show(struct seq_file *seq, void *v)
32374b3092cSHariprasad Shenai {
32474b3092cSHariprasad Shenai 	static const char * const qname[] = {
32574b3092cSHariprasad Shenai 		"TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
32674b3092cSHariprasad Shenai 		"ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
32774b3092cSHariprasad Shenai 		"SGE0-RX", "SGE1-RX"
32874b3092cSHariprasad Shenai 	};
32974b3092cSHariprasad Shenai 
33074b3092cSHariprasad Shenai 	int i;
33174b3092cSHariprasad Shenai 	struct adapter *adap = seq->private;
33274b3092cSHariprasad Shenai 	u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
33374b3092cSHariprasad Shenai 	u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
33474b3092cSHariprasad Shenai 	u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
33574b3092cSHariprasad Shenai 	u16 thres[CIM_NUM_IBQ];
33674b3092cSHariprasad Shenai 	u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
33774b3092cSHariprasad Shenai 	u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
33874b3092cSHariprasad Shenai 	u32 *p = stat;
33974b3092cSHariprasad Shenai 	int cim_num_obq = is_t4(adap->params.chip) ?
34074b3092cSHariprasad Shenai 				CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
34174b3092cSHariprasad Shenai 
34274b3092cSHariprasad Shenai 	i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
34374b3092cSHariprasad Shenai 			UP_IBQ_0_SHADOW_RDADDR_A,
34474b3092cSHariprasad Shenai 			ARRAY_SIZE(stat), stat);
34574b3092cSHariprasad Shenai 	if (!i) {
34674b3092cSHariprasad Shenai 		if (is_t4(adap->params.chip)) {
34774b3092cSHariprasad Shenai 			i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
34874b3092cSHariprasad Shenai 					ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
34974b3092cSHariprasad Shenai 			wr = obq_wr_t4;
35074b3092cSHariprasad Shenai 		} else {
35174b3092cSHariprasad Shenai 			i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
35274b3092cSHariprasad Shenai 					ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
35374b3092cSHariprasad Shenai 			wr = obq_wr_t5;
35474b3092cSHariprasad Shenai 		}
35574b3092cSHariprasad Shenai 	}
35674b3092cSHariprasad Shenai 	if (i)
35774b3092cSHariprasad Shenai 		return i;
35874b3092cSHariprasad Shenai 
35974b3092cSHariprasad Shenai 	t4_read_cimq_cfg(adap, base, size, thres);
36074b3092cSHariprasad Shenai 
36174b3092cSHariprasad Shenai 	seq_printf(seq,
36274b3092cSHariprasad Shenai 		   "  Queue  Base  Size Thres  RdPtr WrPtr  SOP  EOP Avail\n");
36374b3092cSHariprasad Shenai 	for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
36474b3092cSHariprasad Shenai 		seq_printf(seq, "%7s %5x %5u %5u %6x  %4x %4u %4u %5u\n",
36574b3092cSHariprasad Shenai 			   qname[i], base[i], size[i], thres[i],
36674b3092cSHariprasad Shenai 			   IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
36774b3092cSHariprasad Shenai 			   QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
36874b3092cSHariprasad Shenai 			   QUEREMFLITS_G(p[2]) * 16);
36974b3092cSHariprasad Shenai 	for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
37074b3092cSHariprasad Shenai 		seq_printf(seq, "%7s %5x %5u %12x  %4x %4u %4u %5u\n",
37174b3092cSHariprasad Shenai 			   qname[i], base[i], size[i],
37274b3092cSHariprasad Shenai 			   QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
37374b3092cSHariprasad Shenai 			   QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
37474b3092cSHariprasad Shenai 			   QUEREMFLITS_G(p[2]) * 16);
37574b3092cSHariprasad Shenai 	return 0;
37674b3092cSHariprasad Shenai }
37774b3092cSHariprasad Shenai 
37874b3092cSHariprasad Shenai static int cim_qcfg_open(struct inode *inode, struct file *file)
37974b3092cSHariprasad Shenai {
38074b3092cSHariprasad Shenai 	return single_open(file, cim_qcfg_show, inode->i_private);
38174b3092cSHariprasad Shenai }
38274b3092cSHariprasad Shenai 
38374b3092cSHariprasad Shenai static const struct file_operations cim_qcfg_fops = {
38474b3092cSHariprasad Shenai 	.owner   = THIS_MODULE,
38574b3092cSHariprasad Shenai 	.open    = cim_qcfg_open,
38674b3092cSHariprasad Shenai 	.read    = seq_read,
38774b3092cSHariprasad Shenai 	.llseek  = seq_lseek,
38874b3092cSHariprasad Shenai 	.release = single_release,
38974b3092cSHariprasad Shenai };
39074b3092cSHariprasad Shenai 
391e5f0e43bSHariprasad Shenai static int cimq_show(struct seq_file *seq, void *v, int idx)
392e5f0e43bSHariprasad Shenai {
393e5f0e43bSHariprasad Shenai 	const u32 *p = v;
394e5f0e43bSHariprasad Shenai 
395e5f0e43bSHariprasad Shenai 	seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
396e5f0e43bSHariprasad Shenai 		   p[2], p[3]);
397e5f0e43bSHariprasad Shenai 	return 0;
398e5f0e43bSHariprasad Shenai }
399e5f0e43bSHariprasad Shenai 
400e5f0e43bSHariprasad Shenai static int cim_ibq_open(struct inode *inode, struct file *file)
401e5f0e43bSHariprasad Shenai {
402e5f0e43bSHariprasad Shenai 	int ret;
403e5f0e43bSHariprasad Shenai 	struct seq_tab *p;
404e5f0e43bSHariprasad Shenai 	unsigned int qid = (uintptr_t)inode->i_private & 7;
405e5f0e43bSHariprasad Shenai 	struct adapter *adap = inode->i_private - qid;
406e5f0e43bSHariprasad Shenai 
407e5f0e43bSHariprasad Shenai 	p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
408e5f0e43bSHariprasad Shenai 	if (!p)
409e5f0e43bSHariprasad Shenai 		return -ENOMEM;
410e5f0e43bSHariprasad Shenai 
411e5f0e43bSHariprasad Shenai 	ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
412e5f0e43bSHariprasad Shenai 	if (ret < 0)
413e5f0e43bSHariprasad Shenai 		seq_release_private(inode, file);
414e5f0e43bSHariprasad Shenai 	else
415e5f0e43bSHariprasad Shenai 		ret = 0;
416e5f0e43bSHariprasad Shenai 	return ret;
417e5f0e43bSHariprasad Shenai }
418e5f0e43bSHariprasad Shenai 
419e5f0e43bSHariprasad Shenai static const struct file_operations cim_ibq_fops = {
420e5f0e43bSHariprasad Shenai 	.owner   = THIS_MODULE,
421e5f0e43bSHariprasad Shenai 	.open    = cim_ibq_open,
422e5f0e43bSHariprasad Shenai 	.read    = seq_read,
423e5f0e43bSHariprasad Shenai 	.llseek  = seq_lseek,
424e5f0e43bSHariprasad Shenai 	.release = seq_release_private
425e5f0e43bSHariprasad Shenai };
426e5f0e43bSHariprasad Shenai 
427c778af7dSHariprasad Shenai static int cim_obq_open(struct inode *inode, struct file *file)
428c778af7dSHariprasad Shenai {
429c778af7dSHariprasad Shenai 	int ret;
430c778af7dSHariprasad Shenai 	struct seq_tab *p;
431c778af7dSHariprasad Shenai 	unsigned int qid = (uintptr_t)inode->i_private & 7;
432c778af7dSHariprasad Shenai 	struct adapter *adap = inode->i_private - qid;
433c778af7dSHariprasad Shenai 
434c778af7dSHariprasad Shenai 	p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
435c778af7dSHariprasad Shenai 	if (!p)
436c778af7dSHariprasad Shenai 		return -ENOMEM;
437c778af7dSHariprasad Shenai 
438c778af7dSHariprasad Shenai 	ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
439c778af7dSHariprasad Shenai 	if (ret < 0) {
440c778af7dSHariprasad Shenai 		seq_release_private(inode, file);
441c778af7dSHariprasad Shenai 	} else {
442c778af7dSHariprasad Shenai 		seq_tab_trim(p, ret / 4);
443c778af7dSHariprasad Shenai 		ret = 0;
444c778af7dSHariprasad Shenai 	}
445c778af7dSHariprasad Shenai 	return ret;
446c778af7dSHariprasad Shenai }
447c778af7dSHariprasad Shenai 
448c778af7dSHariprasad Shenai static const struct file_operations cim_obq_fops = {
449c778af7dSHariprasad Shenai 	.owner   = THIS_MODULE,
450c778af7dSHariprasad Shenai 	.open    = cim_obq_open,
451c778af7dSHariprasad Shenai 	.read    = seq_read,
452c778af7dSHariprasad Shenai 	.llseek  = seq_lseek,
453c778af7dSHariprasad Shenai 	.release = seq_release_private
454c778af7dSHariprasad Shenai };
455c778af7dSHariprasad Shenai 
4562d277b3bSHariprasad Shenai struct field_desc {
4572d277b3bSHariprasad Shenai 	const char *name;
4582d277b3bSHariprasad Shenai 	unsigned int start;
4592d277b3bSHariprasad Shenai 	unsigned int width;
4602d277b3bSHariprasad Shenai };
4612d277b3bSHariprasad Shenai 
4622d277b3bSHariprasad Shenai static void field_desc_show(struct seq_file *seq, u64 v,
4632d277b3bSHariprasad Shenai 			    const struct field_desc *p)
4642d277b3bSHariprasad Shenai {
4652d277b3bSHariprasad Shenai 	char buf[32];
4662d277b3bSHariprasad Shenai 	int line_size = 0;
4672d277b3bSHariprasad Shenai 
4682d277b3bSHariprasad Shenai 	while (p->name) {
4692d277b3bSHariprasad Shenai 		u64 mask = (1ULL << p->width) - 1;
4702d277b3bSHariprasad Shenai 		int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
4712d277b3bSHariprasad Shenai 				    ((unsigned long long)v >> p->start) & mask);
4722d277b3bSHariprasad Shenai 
4732d277b3bSHariprasad Shenai 		if (line_size + len >= 79) {
4742d277b3bSHariprasad Shenai 			line_size = 8;
4752d277b3bSHariprasad Shenai 			seq_puts(seq, "\n        ");
4762d277b3bSHariprasad Shenai 		}
4772d277b3bSHariprasad Shenai 		seq_printf(seq, "%s ", buf);
4782d277b3bSHariprasad Shenai 		line_size += len + 1;
4792d277b3bSHariprasad Shenai 		p++;
4802d277b3bSHariprasad Shenai 	}
4812d277b3bSHariprasad Shenai 	seq_putc(seq, '\n');
4822d277b3bSHariprasad Shenai }
4832d277b3bSHariprasad Shenai 
4842d277b3bSHariprasad Shenai static struct field_desc tp_la0[] = {
4852d277b3bSHariprasad Shenai 	{ "RcfOpCodeOut", 60, 4 },
4862d277b3bSHariprasad Shenai 	{ "State", 56, 4 },
4872d277b3bSHariprasad Shenai 	{ "WcfState", 52, 4 },
4882d277b3bSHariprasad Shenai 	{ "RcfOpcSrcOut", 50, 2 },
4892d277b3bSHariprasad Shenai 	{ "CRxError", 49, 1 },
4902d277b3bSHariprasad Shenai 	{ "ERxError", 48, 1 },
4912d277b3bSHariprasad Shenai 	{ "SanityFailed", 47, 1 },
4922d277b3bSHariprasad Shenai 	{ "SpuriousMsg", 46, 1 },
4932d277b3bSHariprasad Shenai 	{ "FlushInputMsg", 45, 1 },
4942d277b3bSHariprasad Shenai 	{ "FlushInputCpl", 44, 1 },
4952d277b3bSHariprasad Shenai 	{ "RssUpBit", 43, 1 },
4962d277b3bSHariprasad Shenai 	{ "RssFilterHit", 42, 1 },
4972d277b3bSHariprasad Shenai 	{ "Tid", 32, 10 },
4982d277b3bSHariprasad Shenai 	{ "InitTcb", 31, 1 },
4992d277b3bSHariprasad Shenai 	{ "LineNumber", 24, 7 },
5002d277b3bSHariprasad Shenai 	{ "Emsg", 23, 1 },
5012d277b3bSHariprasad Shenai 	{ "EdataOut", 22, 1 },
5022d277b3bSHariprasad Shenai 	{ "Cmsg", 21, 1 },
5032d277b3bSHariprasad Shenai 	{ "CdataOut", 20, 1 },
5042d277b3bSHariprasad Shenai 	{ "EreadPdu", 19, 1 },
5052d277b3bSHariprasad Shenai 	{ "CreadPdu", 18, 1 },
5062d277b3bSHariprasad Shenai 	{ "TunnelPkt", 17, 1 },
5072d277b3bSHariprasad Shenai 	{ "RcfPeerFin", 16, 1 },
5082d277b3bSHariprasad Shenai 	{ "RcfReasonOut", 12, 4 },
5092d277b3bSHariprasad Shenai 	{ "TxCchannel", 10, 2 },
5102d277b3bSHariprasad Shenai 	{ "RcfTxChannel", 8, 2 },
5112d277b3bSHariprasad Shenai 	{ "RxEchannel", 6, 2 },
5122d277b3bSHariprasad Shenai 	{ "RcfRxChannel", 5, 1 },
5132d277b3bSHariprasad Shenai 	{ "RcfDataOutSrdy", 4, 1 },
5142d277b3bSHariprasad Shenai 	{ "RxDvld", 3, 1 },
5152d277b3bSHariprasad Shenai 	{ "RxOoDvld", 2, 1 },
5162d277b3bSHariprasad Shenai 	{ "RxCongestion", 1, 1 },
5172d277b3bSHariprasad Shenai 	{ "TxCongestion", 0, 1 },
5182d277b3bSHariprasad Shenai 	{ NULL }
5192d277b3bSHariprasad Shenai };
5202d277b3bSHariprasad Shenai 
5212d277b3bSHariprasad Shenai static int tp_la_show(struct seq_file *seq, void *v, int idx)
5222d277b3bSHariprasad Shenai {
5232d277b3bSHariprasad Shenai 	const u64 *p = v;
5242d277b3bSHariprasad Shenai 
5252d277b3bSHariprasad Shenai 	field_desc_show(seq, *p, tp_la0);
5262d277b3bSHariprasad Shenai 	return 0;
5272d277b3bSHariprasad Shenai }
5282d277b3bSHariprasad Shenai 
5292d277b3bSHariprasad Shenai static int tp_la_show2(struct seq_file *seq, void *v, int idx)
5302d277b3bSHariprasad Shenai {
5312d277b3bSHariprasad Shenai 	const u64 *p = v;
5322d277b3bSHariprasad Shenai 
5332d277b3bSHariprasad Shenai 	if (idx)
5342d277b3bSHariprasad Shenai 		seq_putc(seq, '\n');
5352d277b3bSHariprasad Shenai 	field_desc_show(seq, p[0], tp_la0);
5362d277b3bSHariprasad Shenai 	if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
5372d277b3bSHariprasad Shenai 		field_desc_show(seq, p[1], tp_la0);
5382d277b3bSHariprasad Shenai 	return 0;
5392d277b3bSHariprasad Shenai }
5402d277b3bSHariprasad Shenai 
5412d277b3bSHariprasad Shenai static int tp_la_show3(struct seq_file *seq, void *v, int idx)
5422d277b3bSHariprasad Shenai {
5432d277b3bSHariprasad Shenai 	static struct field_desc tp_la1[] = {
5442d277b3bSHariprasad Shenai 		{ "CplCmdIn", 56, 8 },
5452d277b3bSHariprasad Shenai 		{ "CplCmdOut", 48, 8 },
5462d277b3bSHariprasad Shenai 		{ "ESynOut", 47, 1 },
5472d277b3bSHariprasad Shenai 		{ "EAckOut", 46, 1 },
5482d277b3bSHariprasad Shenai 		{ "EFinOut", 45, 1 },
5492d277b3bSHariprasad Shenai 		{ "ERstOut", 44, 1 },
5502d277b3bSHariprasad Shenai 		{ "SynIn", 43, 1 },
5512d277b3bSHariprasad Shenai 		{ "AckIn", 42, 1 },
5522d277b3bSHariprasad Shenai 		{ "FinIn", 41, 1 },
5532d277b3bSHariprasad Shenai 		{ "RstIn", 40, 1 },
5542d277b3bSHariprasad Shenai 		{ "DataIn", 39, 1 },
5552d277b3bSHariprasad Shenai 		{ "DataInVld", 38, 1 },
5562d277b3bSHariprasad Shenai 		{ "PadIn", 37, 1 },
5572d277b3bSHariprasad Shenai 		{ "RxBufEmpty", 36, 1 },
5582d277b3bSHariprasad Shenai 		{ "RxDdp", 35, 1 },
5592d277b3bSHariprasad Shenai 		{ "RxFbCongestion", 34, 1 },
5602d277b3bSHariprasad Shenai 		{ "TxFbCongestion", 33, 1 },
5612d277b3bSHariprasad Shenai 		{ "TxPktSumSrdy", 32, 1 },
5622d277b3bSHariprasad Shenai 		{ "RcfUlpType", 28, 4 },
5632d277b3bSHariprasad Shenai 		{ "Eread", 27, 1 },
5642d277b3bSHariprasad Shenai 		{ "Ebypass", 26, 1 },
5652d277b3bSHariprasad Shenai 		{ "Esave", 25, 1 },
5662d277b3bSHariprasad Shenai 		{ "Static0", 24, 1 },
5672d277b3bSHariprasad Shenai 		{ "Cread", 23, 1 },
5682d277b3bSHariprasad Shenai 		{ "Cbypass", 22, 1 },
5692d277b3bSHariprasad Shenai 		{ "Csave", 21, 1 },
5702d277b3bSHariprasad Shenai 		{ "CPktOut", 20, 1 },
5712d277b3bSHariprasad Shenai 		{ "RxPagePoolFull", 18, 2 },
5722d277b3bSHariprasad Shenai 		{ "RxLpbkPkt", 17, 1 },
5732d277b3bSHariprasad Shenai 		{ "TxLpbkPkt", 16, 1 },
5742d277b3bSHariprasad Shenai 		{ "RxVfValid", 15, 1 },
5752d277b3bSHariprasad Shenai 		{ "SynLearned", 14, 1 },
5762d277b3bSHariprasad Shenai 		{ "SetDelEntry", 13, 1 },
5772d277b3bSHariprasad Shenai 		{ "SetInvEntry", 12, 1 },
5782d277b3bSHariprasad Shenai 		{ "CpcmdDvld", 11, 1 },
5792d277b3bSHariprasad Shenai 		{ "CpcmdSave", 10, 1 },
5802d277b3bSHariprasad Shenai 		{ "RxPstructsFull", 8, 2 },
5812d277b3bSHariprasad Shenai 		{ "EpcmdDvld", 7, 1 },
5822d277b3bSHariprasad Shenai 		{ "EpcmdFlush", 6, 1 },
5832d277b3bSHariprasad Shenai 		{ "EpcmdTrimPrefix", 5, 1 },
5842d277b3bSHariprasad Shenai 		{ "EpcmdTrimPostfix", 4, 1 },
5852d277b3bSHariprasad Shenai 		{ "ERssIp4Pkt", 3, 1 },
5862d277b3bSHariprasad Shenai 		{ "ERssIp6Pkt", 2, 1 },
5872d277b3bSHariprasad Shenai 		{ "ERssTcpUdpPkt", 1, 1 },
5882d277b3bSHariprasad Shenai 		{ "ERssFceFipPkt", 0, 1 },
5892d277b3bSHariprasad Shenai 		{ NULL }
5902d277b3bSHariprasad Shenai 	};
5912d277b3bSHariprasad Shenai 	static struct field_desc tp_la2[] = {
5922d277b3bSHariprasad Shenai 		{ "CplCmdIn", 56, 8 },
5932d277b3bSHariprasad Shenai 		{ "MpsVfVld", 55, 1 },
5942d277b3bSHariprasad Shenai 		{ "MpsPf", 52, 3 },
5952d277b3bSHariprasad Shenai 		{ "MpsVf", 44, 8 },
5962d277b3bSHariprasad Shenai 		{ "SynIn", 43, 1 },
5972d277b3bSHariprasad Shenai 		{ "AckIn", 42, 1 },
5982d277b3bSHariprasad Shenai 		{ "FinIn", 41, 1 },
5992d277b3bSHariprasad Shenai 		{ "RstIn", 40, 1 },
6002d277b3bSHariprasad Shenai 		{ "DataIn", 39, 1 },
6012d277b3bSHariprasad Shenai 		{ "DataInVld", 38, 1 },
6022d277b3bSHariprasad Shenai 		{ "PadIn", 37, 1 },
6032d277b3bSHariprasad Shenai 		{ "RxBufEmpty", 36, 1 },
6042d277b3bSHariprasad Shenai 		{ "RxDdp", 35, 1 },
6052d277b3bSHariprasad Shenai 		{ "RxFbCongestion", 34, 1 },
6062d277b3bSHariprasad Shenai 		{ "TxFbCongestion", 33, 1 },
6072d277b3bSHariprasad Shenai 		{ "TxPktSumSrdy", 32, 1 },
6082d277b3bSHariprasad Shenai 		{ "RcfUlpType", 28, 4 },
6092d277b3bSHariprasad Shenai 		{ "Eread", 27, 1 },
6102d277b3bSHariprasad Shenai 		{ "Ebypass", 26, 1 },
6112d277b3bSHariprasad Shenai 		{ "Esave", 25, 1 },
6122d277b3bSHariprasad Shenai 		{ "Static0", 24, 1 },
6132d277b3bSHariprasad Shenai 		{ "Cread", 23, 1 },
6142d277b3bSHariprasad Shenai 		{ "Cbypass", 22, 1 },
6152d277b3bSHariprasad Shenai 		{ "Csave", 21, 1 },
6162d277b3bSHariprasad Shenai 		{ "CPktOut", 20, 1 },
6172d277b3bSHariprasad Shenai 		{ "RxPagePoolFull", 18, 2 },
6182d277b3bSHariprasad Shenai 		{ "RxLpbkPkt", 17, 1 },
6192d277b3bSHariprasad Shenai 		{ "TxLpbkPkt", 16, 1 },
6202d277b3bSHariprasad Shenai 		{ "RxVfValid", 15, 1 },
6212d277b3bSHariprasad Shenai 		{ "SynLearned", 14, 1 },
6222d277b3bSHariprasad Shenai 		{ "SetDelEntry", 13, 1 },
6232d277b3bSHariprasad Shenai 		{ "SetInvEntry", 12, 1 },
6242d277b3bSHariprasad Shenai 		{ "CpcmdDvld", 11, 1 },
6252d277b3bSHariprasad Shenai 		{ "CpcmdSave", 10, 1 },
6262d277b3bSHariprasad Shenai 		{ "RxPstructsFull", 8, 2 },
6272d277b3bSHariprasad Shenai 		{ "EpcmdDvld", 7, 1 },
6282d277b3bSHariprasad Shenai 		{ "EpcmdFlush", 6, 1 },
6292d277b3bSHariprasad Shenai 		{ "EpcmdTrimPrefix", 5, 1 },
6302d277b3bSHariprasad Shenai 		{ "EpcmdTrimPostfix", 4, 1 },
6312d277b3bSHariprasad Shenai 		{ "ERssIp4Pkt", 3, 1 },
6322d277b3bSHariprasad Shenai 		{ "ERssIp6Pkt", 2, 1 },
6332d277b3bSHariprasad Shenai 		{ "ERssTcpUdpPkt", 1, 1 },
6342d277b3bSHariprasad Shenai 		{ "ERssFceFipPkt", 0, 1 },
6352d277b3bSHariprasad Shenai 		{ NULL }
6362d277b3bSHariprasad Shenai 	};
6372d277b3bSHariprasad Shenai 	const u64 *p = v;
6382d277b3bSHariprasad Shenai 
6392d277b3bSHariprasad Shenai 	if (idx)
6402d277b3bSHariprasad Shenai 		seq_putc(seq, '\n');
6412d277b3bSHariprasad Shenai 	field_desc_show(seq, p[0], tp_la0);
6422d277b3bSHariprasad Shenai 	if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6432d277b3bSHariprasad Shenai 		field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
6442d277b3bSHariprasad Shenai 	return 0;
6452d277b3bSHariprasad Shenai }
6462d277b3bSHariprasad Shenai 
6472d277b3bSHariprasad Shenai static int tp_la_open(struct inode *inode, struct file *file)
6482d277b3bSHariprasad Shenai {
6492d277b3bSHariprasad Shenai 	struct seq_tab *p;
6502d277b3bSHariprasad Shenai 	struct adapter *adap = inode->i_private;
6512d277b3bSHariprasad Shenai 
6522d277b3bSHariprasad Shenai 	switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
6532d277b3bSHariprasad Shenai 	case 2:
6542d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
6552d277b3bSHariprasad Shenai 				 tp_la_show2);
6562d277b3bSHariprasad Shenai 		break;
6572d277b3bSHariprasad Shenai 	case 3:
6582d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
6592d277b3bSHariprasad Shenai 				 tp_la_show3);
6602d277b3bSHariprasad Shenai 		break;
6612d277b3bSHariprasad Shenai 	default:
6622d277b3bSHariprasad Shenai 		p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
6632d277b3bSHariprasad Shenai 	}
6642d277b3bSHariprasad Shenai 	if (!p)
6652d277b3bSHariprasad Shenai 		return -ENOMEM;
6662d277b3bSHariprasad Shenai 
6672d277b3bSHariprasad Shenai 	t4_tp_read_la(adap, (u64 *)p->data, NULL);
6682d277b3bSHariprasad Shenai 	return 0;
6692d277b3bSHariprasad Shenai }
6702d277b3bSHariprasad Shenai 
6712d277b3bSHariprasad Shenai static ssize_t tp_la_write(struct file *file, const char __user *buf,
6722d277b3bSHariprasad Shenai 			   size_t count, loff_t *pos)
6732d277b3bSHariprasad Shenai {
6742d277b3bSHariprasad Shenai 	int err;
6752d277b3bSHariprasad Shenai 	char s[32];
6762d277b3bSHariprasad Shenai 	unsigned long val;
6772d277b3bSHariprasad Shenai 	size_t size = min(sizeof(s) - 1, count);
678c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
6792d277b3bSHariprasad Shenai 
6802d277b3bSHariprasad Shenai 	if (copy_from_user(s, buf, size))
6812d277b3bSHariprasad Shenai 		return -EFAULT;
6822d277b3bSHariprasad Shenai 	s[size] = '\0';
6832d277b3bSHariprasad Shenai 	err = kstrtoul(s, 0, &val);
6842d277b3bSHariprasad Shenai 	if (err)
6852d277b3bSHariprasad Shenai 		return err;
6862d277b3bSHariprasad Shenai 	if (val > 0xffff)
6872d277b3bSHariprasad Shenai 		return -EINVAL;
6882d277b3bSHariprasad Shenai 	adap->params.tp.la_mask = val << 16;
6892d277b3bSHariprasad Shenai 	t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
6902d277b3bSHariprasad Shenai 			 adap->params.tp.la_mask);
6912d277b3bSHariprasad Shenai 	return count;
6922d277b3bSHariprasad Shenai }
6932d277b3bSHariprasad Shenai 
6942d277b3bSHariprasad Shenai static const struct file_operations tp_la_fops = {
6952d277b3bSHariprasad Shenai 	.owner   = THIS_MODULE,
6962d277b3bSHariprasad Shenai 	.open    = tp_la_open,
6972d277b3bSHariprasad Shenai 	.read    = seq_read,
6982d277b3bSHariprasad Shenai 	.llseek  = seq_lseek,
6992d277b3bSHariprasad Shenai 	.release = seq_release_private,
7002d277b3bSHariprasad Shenai 	.write   = tp_la_write
7012d277b3bSHariprasad Shenai };
7022d277b3bSHariprasad Shenai 
703797ff0f5SHariprasad Shenai static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
704797ff0f5SHariprasad Shenai {
705797ff0f5SHariprasad Shenai 	const u32 *p = v;
706797ff0f5SHariprasad Shenai 
707797ff0f5SHariprasad Shenai 	if (v == SEQ_START_TOKEN)
708797ff0f5SHariprasad Shenai 		seq_puts(seq, "      Pcmd        Type   Message"
709797ff0f5SHariprasad Shenai 			 "                Data\n");
710797ff0f5SHariprasad Shenai 	else
711797ff0f5SHariprasad Shenai 		seq_printf(seq, "%08x%08x  %4x  %08x  %08x%08x%08x%08x\n",
712797ff0f5SHariprasad Shenai 			   p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
713797ff0f5SHariprasad Shenai 	return 0;
714797ff0f5SHariprasad Shenai }
715797ff0f5SHariprasad Shenai 
716797ff0f5SHariprasad Shenai static int ulprx_la_open(struct inode *inode, struct file *file)
717797ff0f5SHariprasad Shenai {
718797ff0f5SHariprasad Shenai 	struct seq_tab *p;
719797ff0f5SHariprasad Shenai 	struct adapter *adap = inode->i_private;
720797ff0f5SHariprasad Shenai 
721797ff0f5SHariprasad Shenai 	p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
722797ff0f5SHariprasad Shenai 			 ulprx_la_show);
723797ff0f5SHariprasad Shenai 	if (!p)
724797ff0f5SHariprasad Shenai 		return -ENOMEM;
725797ff0f5SHariprasad Shenai 
726797ff0f5SHariprasad Shenai 	t4_ulprx_read_la(adap, (u32 *)p->data);
727797ff0f5SHariprasad Shenai 	return 0;
728797ff0f5SHariprasad Shenai }
729797ff0f5SHariprasad Shenai 
730797ff0f5SHariprasad Shenai static const struct file_operations ulprx_la_fops = {
731797ff0f5SHariprasad Shenai 	.owner   = THIS_MODULE,
732797ff0f5SHariprasad Shenai 	.open    = ulprx_la_open,
733797ff0f5SHariprasad Shenai 	.read    = seq_read,
734797ff0f5SHariprasad Shenai 	.llseek  = seq_lseek,
735797ff0f5SHariprasad Shenai 	.release = seq_release_private
736797ff0f5SHariprasad Shenai };
737797ff0f5SHariprasad Shenai 
738b3bbe36aSHariprasad Shenai /* Show the PM memory stats.  These stats include:
739b3bbe36aSHariprasad Shenai  *
740b3bbe36aSHariprasad Shenai  * TX:
741b3bbe36aSHariprasad Shenai  *   Read: memory read operation
742b3bbe36aSHariprasad Shenai  *   Write Bypass: cut-through
743b3bbe36aSHariprasad Shenai  *   Bypass + mem: cut-through and save copy
744b3bbe36aSHariprasad Shenai  *
745b3bbe36aSHariprasad Shenai  * RX:
746b3bbe36aSHariprasad Shenai  *   Read: memory read
747b3bbe36aSHariprasad Shenai  *   Write Bypass: cut-through
748b3bbe36aSHariprasad Shenai  *   Flush: payload trim or drop
749b3bbe36aSHariprasad Shenai  */
750b3bbe36aSHariprasad Shenai static int pm_stats_show(struct seq_file *seq, void *v)
751b3bbe36aSHariprasad Shenai {
752b3bbe36aSHariprasad Shenai 	static const char * const tx_pm_stats[] = {
753b3bbe36aSHariprasad Shenai 		"Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
754b3bbe36aSHariprasad Shenai 	};
755b3bbe36aSHariprasad Shenai 	static const char * const rx_pm_stats[] = {
756b3bbe36aSHariprasad Shenai 		"Read:", "Write bypass:", "Write mem:", "Flush:"
757b3bbe36aSHariprasad Shenai 	};
758b3bbe36aSHariprasad Shenai 
759b3bbe36aSHariprasad Shenai 	int i;
76044588560SHariprasad Shenai 	u32 tx_cnt[T6_PM_NSTATS], rx_cnt[T6_PM_NSTATS];
76144588560SHariprasad Shenai 	u64 tx_cyc[T6_PM_NSTATS], rx_cyc[T6_PM_NSTATS];
762b3bbe36aSHariprasad Shenai 	struct adapter *adap = seq->private;
763b3bbe36aSHariprasad Shenai 
764b3bbe36aSHariprasad Shenai 	t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
765b3bbe36aSHariprasad Shenai 	t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
766b3bbe36aSHariprasad Shenai 
767b3bbe36aSHariprasad Shenai 	seq_printf(seq, "%13s %10s  %20s\n", " ", "Tx pcmds", "Tx bytes");
768b3bbe36aSHariprasad Shenai 	for (i = 0; i < PM_NSTATS - 1; i++)
769b3bbe36aSHariprasad Shenai 		seq_printf(seq, "%-13s %10u  %20llu\n",
770b3bbe36aSHariprasad Shenai 			   tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
771b3bbe36aSHariprasad Shenai 
772b3bbe36aSHariprasad Shenai 	seq_printf(seq, "%13s %10s  %20s\n", " ", "Rx pcmds", "Rx bytes");
773b3bbe36aSHariprasad Shenai 	for (i = 0; i < PM_NSTATS - 1; i++)
774b3bbe36aSHariprasad Shenai 		seq_printf(seq, "%-13s %10u  %20llu\n",
775b3bbe36aSHariprasad Shenai 			   rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
77644588560SHariprasad Shenai 
77744588560SHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
77844588560SHariprasad Shenai 		/* In T5 the granularity of the total wait is too fine.
77944588560SHariprasad Shenai 		 * It is not useful as it reaches the max value too fast.
78044588560SHariprasad Shenai 		 * Hence display this Input FIFO wait for T6 onwards.
78144588560SHariprasad Shenai 		 */
78244588560SHariprasad Shenai 		seq_printf(seq, "%13s %10s  %20s\n",
78344588560SHariprasad Shenai 			   " ", "Total wait", "Total Occupancy");
78444588560SHariprasad Shenai 		seq_printf(seq, "Tx FIFO wait  %10u  %20llu\n",
78544588560SHariprasad Shenai 			   tx_cnt[i], tx_cyc[i]);
78644588560SHariprasad Shenai 		seq_printf(seq, "Rx FIFO wait  %10u  %20llu\n",
78744588560SHariprasad Shenai 			   rx_cnt[i], rx_cyc[i]);
78844588560SHariprasad Shenai 
78944588560SHariprasad Shenai 		/* Skip index 6 as there is nothing useful ihere */
79044588560SHariprasad Shenai 		i += 2;
79144588560SHariprasad Shenai 
79244588560SHariprasad Shenai 		/* At index 7, a new stat for read latency (count, total wait)
79344588560SHariprasad Shenai 		 * is added.
79444588560SHariprasad Shenai 		 */
79544588560SHariprasad Shenai 		seq_printf(seq, "%13s %10s  %20s\n",
79644588560SHariprasad Shenai 			   " ", "Reads", "Total wait");
79744588560SHariprasad Shenai 		seq_printf(seq, "Tx latency    %10u  %20llu\n",
79844588560SHariprasad Shenai 			   tx_cnt[i], tx_cyc[i]);
79944588560SHariprasad Shenai 		seq_printf(seq, "Rx latency    %10u  %20llu\n",
80044588560SHariprasad Shenai 			   rx_cnt[i], rx_cyc[i]);
80144588560SHariprasad Shenai 	}
802b3bbe36aSHariprasad Shenai 	return 0;
803b3bbe36aSHariprasad Shenai }
804b3bbe36aSHariprasad Shenai 
805b3bbe36aSHariprasad Shenai static int pm_stats_open(struct inode *inode, struct file *file)
806b3bbe36aSHariprasad Shenai {
807b3bbe36aSHariprasad Shenai 	return single_open(file, pm_stats_show, inode->i_private);
808b3bbe36aSHariprasad Shenai }
809b3bbe36aSHariprasad Shenai 
810b3bbe36aSHariprasad Shenai static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
811b3bbe36aSHariprasad Shenai 			      size_t count, loff_t *pos)
812b3bbe36aSHariprasad Shenai {
813c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
814b3bbe36aSHariprasad Shenai 
815b3bbe36aSHariprasad Shenai 	t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
816b3bbe36aSHariprasad Shenai 	t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
817b3bbe36aSHariprasad Shenai 	return count;
818b3bbe36aSHariprasad Shenai }
819b3bbe36aSHariprasad Shenai 
820b3bbe36aSHariprasad Shenai static const struct file_operations pm_stats_debugfs_fops = {
821b3bbe36aSHariprasad Shenai 	.owner   = THIS_MODULE,
822b3bbe36aSHariprasad Shenai 	.open    = pm_stats_open,
823b3bbe36aSHariprasad Shenai 	.read    = seq_read,
824b3bbe36aSHariprasad Shenai 	.llseek  = seq_lseek,
825b3bbe36aSHariprasad Shenai 	.release = single_release,
826b3bbe36aSHariprasad Shenai 	.write   = pm_stats_clear
827b3bbe36aSHariprasad Shenai };
828b3bbe36aSHariprasad Shenai 
8297864026bSHariprasad Shenai static int tx_rate_show(struct seq_file *seq, void *v)
8307864026bSHariprasad Shenai {
8317864026bSHariprasad Shenai 	u64 nrate[NCHAN], orate[NCHAN];
8327864026bSHariprasad Shenai 	struct adapter *adap = seq->private;
8337864026bSHariprasad Shenai 
8347864026bSHariprasad Shenai 	t4_get_chan_txrate(adap, nrate, orate);
8357864026bSHariprasad Shenai 	if (adap->params.arch.nchan == NCHAN) {
8367864026bSHariprasad Shenai 		seq_puts(seq, "              channel 0   channel 1   "
8377864026bSHariprasad Shenai 			 "channel 2   channel 3\n");
8387864026bSHariprasad Shenai 		seq_printf(seq, "NIC B/s:     %10llu  %10llu  %10llu  %10llu\n",
8397864026bSHariprasad Shenai 			   (unsigned long long)nrate[0],
8407864026bSHariprasad Shenai 			   (unsigned long long)nrate[1],
8417864026bSHariprasad Shenai 			   (unsigned long long)nrate[2],
8427864026bSHariprasad Shenai 			   (unsigned long long)nrate[3]);
8437864026bSHariprasad Shenai 		seq_printf(seq, "Offload B/s: %10llu  %10llu  %10llu  %10llu\n",
8447864026bSHariprasad Shenai 			   (unsigned long long)orate[0],
8457864026bSHariprasad Shenai 			   (unsigned long long)orate[1],
8467864026bSHariprasad Shenai 			   (unsigned long long)orate[2],
8477864026bSHariprasad Shenai 			   (unsigned long long)orate[3]);
8487864026bSHariprasad Shenai 	} else {
8497864026bSHariprasad Shenai 		seq_puts(seq, "              channel 0   channel 1\n");
8507864026bSHariprasad Shenai 		seq_printf(seq, "NIC B/s:     %10llu  %10llu\n",
8517864026bSHariprasad Shenai 			   (unsigned long long)nrate[0],
8527864026bSHariprasad Shenai 			   (unsigned long long)nrate[1]);
8537864026bSHariprasad Shenai 		seq_printf(seq, "Offload B/s: %10llu  %10llu\n",
8547864026bSHariprasad Shenai 			   (unsigned long long)orate[0],
8557864026bSHariprasad Shenai 			   (unsigned long long)orate[1]);
8567864026bSHariprasad Shenai 	}
8577864026bSHariprasad Shenai 	return 0;
8587864026bSHariprasad Shenai }
8597864026bSHariprasad Shenai 
8607864026bSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(tx_rate);
8617864026bSHariprasad Shenai 
862bad43792SHariprasad Shenai static int cctrl_tbl_show(struct seq_file *seq, void *v)
863bad43792SHariprasad Shenai {
864bad43792SHariprasad Shenai 	static const char * const dec_fac[] = {
865bad43792SHariprasad Shenai 		"0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
866bad43792SHariprasad Shenai 		"0.9375" };
867bad43792SHariprasad Shenai 
868bad43792SHariprasad Shenai 	int i;
869dde93dfeSHariprasad Shenai 	u16 (*incr)[NCCTRL_WIN];
870bad43792SHariprasad Shenai 	struct adapter *adap = seq->private;
871bad43792SHariprasad Shenai 
872dde93dfeSHariprasad Shenai 	incr = kmalloc(sizeof(*incr) * NMTUS, GFP_KERNEL);
873dde93dfeSHariprasad Shenai 	if (!incr)
874dde93dfeSHariprasad Shenai 		return -ENOMEM;
875dde93dfeSHariprasad Shenai 
876bad43792SHariprasad Shenai 	t4_read_cong_tbl(adap, incr);
877bad43792SHariprasad Shenai 
878bad43792SHariprasad Shenai 	for (i = 0; i < NCCTRL_WIN; ++i) {
879bad43792SHariprasad Shenai 		seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
880bad43792SHariprasad Shenai 			   incr[0][i], incr[1][i], incr[2][i], incr[3][i],
881bad43792SHariprasad Shenai 			   incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
882bad43792SHariprasad Shenai 		seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
883bad43792SHariprasad Shenai 			   incr[8][i], incr[9][i], incr[10][i], incr[11][i],
884bad43792SHariprasad Shenai 			   incr[12][i], incr[13][i], incr[14][i], incr[15][i],
885bad43792SHariprasad Shenai 			   adap->params.a_wnd[i],
886bad43792SHariprasad Shenai 			   dec_fac[adap->params.b_wnd[i]]);
887bad43792SHariprasad Shenai 	}
888dde93dfeSHariprasad Shenai 
889dde93dfeSHariprasad Shenai 	kfree(incr);
890bad43792SHariprasad Shenai 	return 0;
891bad43792SHariprasad Shenai }
892bad43792SHariprasad Shenai 
893bad43792SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(cctrl_tbl);
894bad43792SHariprasad Shenai 
895b58b6676SHariprasad Shenai /* Format a value in a unit that differs from the value's native unit by the
896b58b6676SHariprasad Shenai  * given factor.
897b58b6676SHariprasad Shenai  */
898b58b6676SHariprasad Shenai static char *unit_conv(char *buf, size_t len, unsigned int val,
899b58b6676SHariprasad Shenai 		       unsigned int factor)
900b58b6676SHariprasad Shenai {
901b58b6676SHariprasad Shenai 	unsigned int rem = val % factor;
902b58b6676SHariprasad Shenai 
903b58b6676SHariprasad Shenai 	if (rem == 0) {
904b58b6676SHariprasad Shenai 		snprintf(buf, len, "%u", val / factor);
905b58b6676SHariprasad Shenai 	} else {
906b58b6676SHariprasad Shenai 		while (rem % 10 == 0)
907b58b6676SHariprasad Shenai 			rem /= 10;
908b58b6676SHariprasad Shenai 		snprintf(buf, len, "%u.%u", val / factor, rem);
909b58b6676SHariprasad Shenai 	}
910b58b6676SHariprasad Shenai 	return buf;
911b58b6676SHariprasad Shenai }
912b58b6676SHariprasad Shenai 
913b58b6676SHariprasad Shenai static int clk_show(struct seq_file *seq, void *v)
914b58b6676SHariprasad Shenai {
915b58b6676SHariprasad Shenai 	char buf[32];
916b58b6676SHariprasad Shenai 	struct adapter *adap = seq->private;
917b58b6676SHariprasad Shenai 	unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk;  /* in ps */
918b58b6676SHariprasad Shenai 	u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
919b58b6676SHariprasad Shenai 	unsigned int tre = TIMERRESOLUTION_G(res);
920b58b6676SHariprasad Shenai 	unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
921b58b6676SHariprasad Shenai 	unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
922b58b6676SHariprasad Shenai 
923b58b6676SHariprasad Shenai 	seq_printf(seq, "Core clock period: %s ns\n",
924b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), cclk_ps, 1000));
925b58b6676SHariprasad Shenai 	seq_printf(seq, "TP timer tick: %s us\n",
926b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
927b58b6676SHariprasad Shenai 	seq_printf(seq, "TCP timestamp tick: %s us\n",
928b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf),
929b58b6676SHariprasad Shenai 			     (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
930b58b6676SHariprasad Shenai 	seq_printf(seq, "DACK tick: %s us\n",
931b58b6676SHariprasad Shenai 		   unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
932b58b6676SHariprasad Shenai 	seq_printf(seq, "DACK timer: %u us\n",
933b58b6676SHariprasad Shenai 		   ((cclk_ps << dack_re) / 1000000) *
934b58b6676SHariprasad Shenai 		   t4_read_reg(adap, TP_DACK_TIMER_A));
935b58b6676SHariprasad Shenai 	seq_printf(seq, "Retransmit min: %llu us\n",
936b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
937b58b6676SHariprasad Shenai 	seq_printf(seq, "Retransmit max: %llu us\n",
938b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
939b58b6676SHariprasad Shenai 	seq_printf(seq, "Persist timer min: %llu us\n",
940b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
941b58b6676SHariprasad Shenai 	seq_printf(seq, "Persist timer max: %llu us\n",
942b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
943b58b6676SHariprasad Shenai 	seq_printf(seq, "Keepalive idle timer: %llu us\n",
944b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
945b58b6676SHariprasad Shenai 	seq_printf(seq, "Keepalive interval: %llu us\n",
946b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
947b58b6676SHariprasad Shenai 	seq_printf(seq, "Initial SRTT: %llu us\n",
948b58b6676SHariprasad Shenai 		   tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
949b58b6676SHariprasad Shenai 	seq_printf(seq, "FINWAIT2 timer: %llu us\n",
950b58b6676SHariprasad Shenai 		   tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
951b58b6676SHariprasad Shenai 
952b58b6676SHariprasad Shenai 	return 0;
953b58b6676SHariprasad Shenai }
954b58b6676SHariprasad Shenai 
955b58b6676SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(clk);
956b58b6676SHariprasad Shenai 
957f1ff24aaSHariprasad Shenai /* Firmware Device Log dump. */
95849aa284fSHariprasad Shenai static const char * const devlog_level_strings[] = {
95949aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_EMERG]		= "EMERG",
96049aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_CRIT]		= "CRIT",
96149aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_ERR]		= "ERR",
96249aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_NOTICE]	= "NOTICE",
96349aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_INFO]		= "INFO",
96449aa284fSHariprasad Shenai 	[FW_DEVLOG_LEVEL_DEBUG]		= "DEBUG"
96549aa284fSHariprasad Shenai };
96649aa284fSHariprasad Shenai 
96749aa284fSHariprasad Shenai static const char * const devlog_facility_strings[] = {
96849aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_CORE]	= "CORE",
969da4976e1SHariprasad Shenai 	[FW_DEVLOG_FACILITY_CF]         = "CF",
97049aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_SCHED]	= "SCHED",
97149aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_TIMER]	= "TIMER",
97249aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_RES]	= "RES",
97349aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_HW]		= "HW",
97449aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FLR]	= "FLR",
97549aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_DMAQ]	= "DMAQ",
97649aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_PHY]	= "PHY",
97749aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_MAC]	= "MAC",
97849aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_PORT]	= "PORT",
97949aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_VI]		= "VI",
98049aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FILTER]	= "FILTER",
98149aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ACL]	= "ACL",
98249aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_TM]		= "TM",
98349aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_QFC]	= "QFC",
98449aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_DCB]	= "DCB",
98549aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ETH]	= "ETH",
98649aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_OFLD]	= "OFLD",
98749aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_RI]		= "RI",
98849aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_ISCSI]	= "ISCSI",
98949aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FCOE]	= "FCOE",
99049aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FOISCSI]	= "FOISCSI",
99149aa284fSHariprasad Shenai 	[FW_DEVLOG_FACILITY_FOFCOE]	= "FOFCOE"
99249aa284fSHariprasad Shenai };
99349aa284fSHariprasad Shenai 
99449aa284fSHariprasad Shenai /* Information gathered by Device Log Open routine for the display routine.
99549aa284fSHariprasad Shenai  */
99649aa284fSHariprasad Shenai struct devlog_info {
99749aa284fSHariprasad Shenai 	unsigned int nentries;		/* number of entries in log[] */
99849aa284fSHariprasad Shenai 	unsigned int first;		/* first [temporal] entry in log[] */
99949aa284fSHariprasad Shenai 	struct fw_devlog_e log[0];	/* Firmware Device Log */
100049aa284fSHariprasad Shenai };
100149aa284fSHariprasad Shenai 
100249aa284fSHariprasad Shenai /* Dump a Firmaware Device Log entry.
100349aa284fSHariprasad Shenai  */
100449aa284fSHariprasad Shenai static int devlog_show(struct seq_file *seq, void *v)
100549aa284fSHariprasad Shenai {
100649aa284fSHariprasad Shenai 	if (v == SEQ_START_TOKEN)
100749aa284fSHariprasad Shenai 		seq_printf(seq, "%10s  %15s  %8s  %8s  %s\n",
100849aa284fSHariprasad Shenai 			   "Seq#", "Tstamp", "Level", "Facility", "Message");
100949aa284fSHariprasad Shenai 	else {
101049aa284fSHariprasad Shenai 		struct devlog_info *dinfo = seq->private;
101149aa284fSHariprasad Shenai 		int fidx = (uintptr_t)v - 2;
101249aa284fSHariprasad Shenai 		unsigned long index;
101349aa284fSHariprasad Shenai 		struct fw_devlog_e *e;
101449aa284fSHariprasad Shenai 
101549aa284fSHariprasad Shenai 		/* Get a pointer to the log entry to display.  Skip unused log
101649aa284fSHariprasad Shenai 		 * entries.
101749aa284fSHariprasad Shenai 		 */
101849aa284fSHariprasad Shenai 		index = dinfo->first + fidx;
101949aa284fSHariprasad Shenai 		if (index >= dinfo->nentries)
102049aa284fSHariprasad Shenai 			index -= dinfo->nentries;
102149aa284fSHariprasad Shenai 		e = &dinfo->log[index];
102249aa284fSHariprasad Shenai 		if (e->timestamp == 0)
102349aa284fSHariprasad Shenai 			return 0;
102449aa284fSHariprasad Shenai 
102549aa284fSHariprasad Shenai 		/* Print the message.  This depends on the firmware using
102649aa284fSHariprasad Shenai 		 * exactly the same formating strings as the kernel so we may
102749aa284fSHariprasad Shenai 		 * eventually have to put a format interpreter in here ...
102849aa284fSHariprasad Shenai 		 */
102949aa284fSHariprasad Shenai 		seq_printf(seq, "%10d  %15llu  %8s  %8s  ",
1030fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->seqno),
1031fda8b18cSHariprasad Shenai 			   be64_to_cpu(e->timestamp),
103249aa284fSHariprasad Shenai 			   (e->level < ARRAY_SIZE(devlog_level_strings)
103349aa284fSHariprasad Shenai 			    ? devlog_level_strings[e->level]
103449aa284fSHariprasad Shenai 			    : "UNKNOWN"),
103549aa284fSHariprasad Shenai 			   (e->facility < ARRAY_SIZE(devlog_facility_strings)
103649aa284fSHariprasad Shenai 			    ? devlog_facility_strings[e->facility]
103749aa284fSHariprasad Shenai 			    : "UNKNOWN"));
1038fda8b18cSHariprasad Shenai 		seq_printf(seq, e->fmt,
1039fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[0]),
1040fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[1]),
1041fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[2]),
1042fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[3]),
1043fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[4]),
1044fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[5]),
1045fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[6]),
1046fda8b18cSHariprasad Shenai 			   be32_to_cpu(e->params[7]));
104749aa284fSHariprasad Shenai 	}
104849aa284fSHariprasad Shenai 	return 0;
104949aa284fSHariprasad Shenai }
105049aa284fSHariprasad Shenai 
105149aa284fSHariprasad Shenai /* Sequential File Operations for Device Log.
105249aa284fSHariprasad Shenai  */
105349aa284fSHariprasad Shenai static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
105449aa284fSHariprasad Shenai {
105549aa284fSHariprasad Shenai 	if (pos > dinfo->nentries)
105649aa284fSHariprasad Shenai 		return NULL;
105749aa284fSHariprasad Shenai 
105849aa284fSHariprasad Shenai 	return (void *)(uintptr_t)(pos + 1);
105949aa284fSHariprasad Shenai }
106049aa284fSHariprasad Shenai 
106149aa284fSHariprasad Shenai static void *devlog_start(struct seq_file *seq, loff_t *pos)
106249aa284fSHariprasad Shenai {
106349aa284fSHariprasad Shenai 	struct devlog_info *dinfo = seq->private;
106449aa284fSHariprasad Shenai 
106549aa284fSHariprasad Shenai 	return (*pos
106649aa284fSHariprasad Shenai 		? devlog_get_idx(dinfo, *pos)
106749aa284fSHariprasad Shenai 		: SEQ_START_TOKEN);
106849aa284fSHariprasad Shenai }
106949aa284fSHariprasad Shenai 
107049aa284fSHariprasad Shenai static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
107149aa284fSHariprasad Shenai {
107249aa284fSHariprasad Shenai 	struct devlog_info *dinfo = seq->private;
107349aa284fSHariprasad Shenai 
107449aa284fSHariprasad Shenai 	(*pos)++;
107549aa284fSHariprasad Shenai 	return devlog_get_idx(dinfo, *pos);
107649aa284fSHariprasad Shenai }
107749aa284fSHariprasad Shenai 
107849aa284fSHariprasad Shenai static void devlog_stop(struct seq_file *seq, void *v)
107949aa284fSHariprasad Shenai {
108049aa284fSHariprasad Shenai }
108149aa284fSHariprasad Shenai 
108249aa284fSHariprasad Shenai static const struct seq_operations devlog_seq_ops = {
108349aa284fSHariprasad Shenai 	.start = devlog_start,
108449aa284fSHariprasad Shenai 	.next  = devlog_next,
108549aa284fSHariprasad Shenai 	.stop  = devlog_stop,
108649aa284fSHariprasad Shenai 	.show  = devlog_show
108749aa284fSHariprasad Shenai };
108849aa284fSHariprasad Shenai 
108949aa284fSHariprasad Shenai /* Set up for reading the firmware's device log.  We read the entire log here
109049aa284fSHariprasad Shenai  * and then display it incrementally in devlog_show().
109149aa284fSHariprasad Shenai  */
109249aa284fSHariprasad Shenai static int devlog_open(struct inode *inode, struct file *file)
109349aa284fSHariprasad Shenai {
109449aa284fSHariprasad Shenai 	struct adapter *adap = inode->i_private;
109549aa284fSHariprasad Shenai 	struct devlog_params *dparams = &adap->params.devlog;
109649aa284fSHariprasad Shenai 	struct devlog_info *dinfo;
109749aa284fSHariprasad Shenai 	unsigned int index;
109849aa284fSHariprasad Shenai 	u32 fseqno;
109949aa284fSHariprasad Shenai 	int ret;
110049aa284fSHariprasad Shenai 
110149aa284fSHariprasad Shenai 	/* If we don't know where the log is we can't do anything.
110249aa284fSHariprasad Shenai 	 */
110349aa284fSHariprasad Shenai 	if (dparams->start == 0)
110449aa284fSHariprasad Shenai 		return -ENXIO;
110549aa284fSHariprasad Shenai 
110649aa284fSHariprasad Shenai 	/* Allocate the space to read in the firmware's device log and set up
110749aa284fSHariprasad Shenai 	 * for the iterated call to our display function.
110849aa284fSHariprasad Shenai 	 */
110949aa284fSHariprasad Shenai 	dinfo = __seq_open_private(file, &devlog_seq_ops,
111049aa284fSHariprasad Shenai 				   sizeof(*dinfo) + dparams->size);
111149aa284fSHariprasad Shenai 	if (!dinfo)
111249aa284fSHariprasad Shenai 		return -ENOMEM;
111349aa284fSHariprasad Shenai 
111449aa284fSHariprasad Shenai 	/* Record the basic log buffer information and read in the raw log.
111549aa284fSHariprasad Shenai 	 */
111649aa284fSHariprasad Shenai 	dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
111749aa284fSHariprasad Shenai 	dinfo->first = 0;
111849aa284fSHariprasad Shenai 	spin_lock(&adap->win0_lock);
111949aa284fSHariprasad Shenai 	ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
112049aa284fSHariprasad Shenai 			   dparams->start, dparams->size, (__be32 *)dinfo->log,
112149aa284fSHariprasad Shenai 			   T4_MEMORY_READ);
112249aa284fSHariprasad Shenai 	spin_unlock(&adap->win0_lock);
112349aa284fSHariprasad Shenai 	if (ret) {
112449aa284fSHariprasad Shenai 		seq_release_private(inode, file);
112549aa284fSHariprasad Shenai 		return ret;
112649aa284fSHariprasad Shenai 	}
112749aa284fSHariprasad Shenai 
1128fda8b18cSHariprasad Shenai 	/* Find the earliest (lowest Sequence Number) log entry in the
1129fda8b18cSHariprasad Shenai 	 * circular Device Log.
113049aa284fSHariprasad Shenai 	 */
113149aa284fSHariprasad Shenai 	for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
113249aa284fSHariprasad Shenai 		struct fw_devlog_e *e = &dinfo->log[index];
113349aa284fSHariprasad Shenai 		__u32 seqno;
113449aa284fSHariprasad Shenai 
113549aa284fSHariprasad Shenai 		if (e->timestamp == 0)
113649aa284fSHariprasad Shenai 			continue;
113749aa284fSHariprasad Shenai 
113849aa284fSHariprasad Shenai 		seqno = be32_to_cpu(e->seqno);
113949aa284fSHariprasad Shenai 		if (seqno < fseqno) {
114049aa284fSHariprasad Shenai 			fseqno = seqno;
114149aa284fSHariprasad Shenai 			dinfo->first = index;
114249aa284fSHariprasad Shenai 		}
114349aa284fSHariprasad Shenai 	}
114449aa284fSHariprasad Shenai 	return 0;
114549aa284fSHariprasad Shenai }
114649aa284fSHariprasad Shenai 
114749aa284fSHariprasad Shenai static const struct file_operations devlog_fops = {
114849aa284fSHariprasad Shenai 	.owner   = THIS_MODULE,
114949aa284fSHariprasad Shenai 	.open    = devlog_open,
115049aa284fSHariprasad Shenai 	.read    = seq_read,
115149aa284fSHariprasad Shenai 	.llseek  = seq_lseek,
115249aa284fSHariprasad Shenai 	.release = seq_release_private
115349aa284fSHariprasad Shenai };
115449aa284fSHariprasad Shenai 
11557f080c3fSHariprasad Shenai /* Show Firmware Mailbox Command/Reply Log
11567f080c3fSHariprasad Shenai  *
11577f080c3fSHariprasad Shenai  * Note that we don't do any locking when dumping the Firmware Mailbox Log so
11587f080c3fSHariprasad Shenai  * it's possible that we can catch things during a log update and therefore
11597f080c3fSHariprasad Shenai  * see partially corrupted log entries.  But it's probably Good Enough(tm).
11607f080c3fSHariprasad Shenai  * If we ever decide that we want to make sure that we're dumping a coherent
11617f080c3fSHariprasad Shenai  * log, we'd need to perform locking in the mailbox logging and in
11627f080c3fSHariprasad Shenai  * mboxlog_open() where we'd need to grab the entire mailbox log in one go
11637f080c3fSHariprasad Shenai  * like we do for the Firmware Device Log.
11647f080c3fSHariprasad Shenai  */
11657f080c3fSHariprasad Shenai static int mboxlog_show(struct seq_file *seq, void *v)
11667f080c3fSHariprasad Shenai {
11677f080c3fSHariprasad Shenai 	struct adapter *adapter = seq->private;
11687f080c3fSHariprasad Shenai 	struct mbox_cmd_log *log = adapter->mbox_log;
11697f080c3fSHariprasad Shenai 	struct mbox_cmd *entry;
11707f080c3fSHariprasad Shenai 	int entry_idx, i;
11717f080c3fSHariprasad Shenai 
11727f080c3fSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
11737f080c3fSHariprasad Shenai 		seq_printf(seq,
11747f080c3fSHariprasad Shenai 			   "%10s  %15s  %5s  %5s  %s\n",
11757f080c3fSHariprasad Shenai 			   "Seq#", "Tstamp", "Atime", "Etime",
11767f080c3fSHariprasad Shenai 			   "Command/Reply");
11777f080c3fSHariprasad Shenai 		return 0;
11787f080c3fSHariprasad Shenai 	}
11797f080c3fSHariprasad Shenai 
11807f080c3fSHariprasad Shenai 	entry_idx = log->cursor + ((uintptr_t)v - 2);
11817f080c3fSHariprasad Shenai 	if (entry_idx >= log->size)
11827f080c3fSHariprasad Shenai 		entry_idx -= log->size;
11837f080c3fSHariprasad Shenai 	entry = mbox_cmd_log_entry(log, entry_idx);
11847f080c3fSHariprasad Shenai 
11857f080c3fSHariprasad Shenai 	/* skip over unused entries */
11867f080c3fSHariprasad Shenai 	if (entry->timestamp == 0)
11877f080c3fSHariprasad Shenai 		return 0;
11887f080c3fSHariprasad Shenai 
11897f080c3fSHariprasad Shenai 	seq_printf(seq, "%10u  %15llu  %5d  %5d",
11907f080c3fSHariprasad Shenai 		   entry->seqno, entry->timestamp,
11917f080c3fSHariprasad Shenai 		   entry->access, entry->execute);
11927f080c3fSHariprasad Shenai 	for (i = 0; i < MBOX_LEN / 8; i++) {
11937f080c3fSHariprasad Shenai 		u64 flit = entry->cmd[i];
11947f080c3fSHariprasad Shenai 		u32 hi = (u32)(flit >> 32);
11957f080c3fSHariprasad Shenai 		u32 lo = (u32)flit;
11967f080c3fSHariprasad Shenai 
11977f080c3fSHariprasad Shenai 		seq_printf(seq, "  %08x %08x", hi, lo);
11987f080c3fSHariprasad Shenai 	}
11997f080c3fSHariprasad Shenai 	seq_puts(seq, "\n");
12007f080c3fSHariprasad Shenai 	return 0;
12017f080c3fSHariprasad Shenai }
12027f080c3fSHariprasad Shenai 
12037f080c3fSHariprasad Shenai static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
12047f080c3fSHariprasad Shenai {
12057f080c3fSHariprasad Shenai 	struct adapter *adapter = seq->private;
12067f080c3fSHariprasad Shenai 	struct mbox_cmd_log *log = adapter->mbox_log;
12077f080c3fSHariprasad Shenai 
12087f080c3fSHariprasad Shenai 	return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
12097f080c3fSHariprasad Shenai }
12107f080c3fSHariprasad Shenai 
12117f080c3fSHariprasad Shenai static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
12127f080c3fSHariprasad Shenai {
12137f080c3fSHariprasad Shenai 	return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
12147f080c3fSHariprasad Shenai }
12157f080c3fSHariprasad Shenai 
12167f080c3fSHariprasad Shenai static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
12177f080c3fSHariprasad Shenai {
12187f080c3fSHariprasad Shenai 	++*pos;
12197f080c3fSHariprasad Shenai 	return mboxlog_get_idx(seq, *pos);
12207f080c3fSHariprasad Shenai }
12217f080c3fSHariprasad Shenai 
12227f080c3fSHariprasad Shenai static void mboxlog_stop(struct seq_file *seq, void *v)
12237f080c3fSHariprasad Shenai {
12247f080c3fSHariprasad Shenai }
12257f080c3fSHariprasad Shenai 
12267f080c3fSHariprasad Shenai static const struct seq_operations mboxlog_seq_ops = {
12277f080c3fSHariprasad Shenai 	.start = mboxlog_start,
12287f080c3fSHariprasad Shenai 	.next  = mboxlog_next,
12297f080c3fSHariprasad Shenai 	.stop  = mboxlog_stop,
12307f080c3fSHariprasad Shenai 	.show  = mboxlog_show
12317f080c3fSHariprasad Shenai };
12327f080c3fSHariprasad Shenai 
12337f080c3fSHariprasad Shenai static int mboxlog_open(struct inode *inode, struct file *file)
12347f080c3fSHariprasad Shenai {
12357f080c3fSHariprasad Shenai 	int res = seq_open(file, &mboxlog_seq_ops);
12367f080c3fSHariprasad Shenai 
12377f080c3fSHariprasad Shenai 	if (!res) {
12387f080c3fSHariprasad Shenai 		struct seq_file *seq = file->private_data;
12397f080c3fSHariprasad Shenai 
12407f080c3fSHariprasad Shenai 		seq->private = inode->i_private;
12417f080c3fSHariprasad Shenai 	}
12427f080c3fSHariprasad Shenai 	return res;
12437f080c3fSHariprasad Shenai }
12447f080c3fSHariprasad Shenai 
12457f080c3fSHariprasad Shenai static const struct file_operations mboxlog_fops = {
12467f080c3fSHariprasad Shenai 	.owner   = THIS_MODULE,
12477f080c3fSHariprasad Shenai 	.open    = mboxlog_open,
12487f080c3fSHariprasad Shenai 	.read    = seq_read,
12497f080c3fSHariprasad Shenai 	.llseek  = seq_lseek,
12507f080c3fSHariprasad Shenai 	.release = seq_release,
12517f080c3fSHariprasad Shenai };
12527f080c3fSHariprasad Shenai 
1253bf7c781dSHariprasad Shenai static int mbox_show(struct seq_file *seq, void *v)
1254bf7c781dSHariprasad Shenai {
1255bf7c781dSHariprasad Shenai 	static const char * const owner[] = { "none", "FW", "driver",
1256b3695540SHariprasad Shenai 					      "unknown", "<unread>" };
1257bf7c781dSHariprasad Shenai 
1258bf7c781dSHariprasad Shenai 	int i;
1259bf7c781dSHariprasad Shenai 	unsigned int mbox = (uintptr_t)seq->private & 7;
1260bf7c781dSHariprasad Shenai 	struct adapter *adap = seq->private - mbox;
1261bf7c781dSHariprasad Shenai 	void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1262b3695540SHariprasad Shenai 
1263b3695540SHariprasad Shenai 	/* For T4 we don't have a shadow copy of the Mailbox Control register.
1264b3695540SHariprasad Shenai 	 * And since reading that real register causes a side effect of
1265b3695540SHariprasad Shenai 	 * granting ownership, we're best of simply not reading it at all.
1266b3695540SHariprasad Shenai 	 */
1267b3695540SHariprasad Shenai 	if (is_t4(adap->params.chip)) {
1268b3695540SHariprasad Shenai 		i = 4; /* index of "<unread>" */
1269b3695540SHariprasad Shenai 	} else {
1270b3695540SHariprasad Shenai 		unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
1271bf7c781dSHariprasad Shenai 		void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
1272bf7c781dSHariprasad Shenai 
1273bf7c781dSHariprasad Shenai 		i = MBOWNER_G(readl(ctrl));
1274b3695540SHariprasad Shenai 	}
1275b3695540SHariprasad Shenai 
1276bf7c781dSHariprasad Shenai 	seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
1277bf7c781dSHariprasad Shenai 
1278bf7c781dSHariprasad Shenai 	for (i = 0; i < MBOX_LEN; i += 8)
1279bf7c781dSHariprasad Shenai 		seq_printf(seq, "%016llx\n",
1280bf7c781dSHariprasad Shenai 			   (unsigned long long)readq(addr + i));
1281bf7c781dSHariprasad Shenai 	return 0;
1282bf7c781dSHariprasad Shenai }
1283bf7c781dSHariprasad Shenai 
1284bf7c781dSHariprasad Shenai static int mbox_open(struct inode *inode, struct file *file)
1285bf7c781dSHariprasad Shenai {
1286bf7c781dSHariprasad Shenai 	return single_open(file, mbox_show, inode->i_private);
1287bf7c781dSHariprasad Shenai }
1288bf7c781dSHariprasad Shenai 
1289bf7c781dSHariprasad Shenai static ssize_t mbox_write(struct file *file, const char __user *buf,
1290bf7c781dSHariprasad Shenai 			  size_t count, loff_t *pos)
1291bf7c781dSHariprasad Shenai {
1292bf7c781dSHariprasad Shenai 	int i;
1293bf7c781dSHariprasad Shenai 	char c = '\n', s[256];
1294bf7c781dSHariprasad Shenai 	unsigned long long data[8];
1295bf7c781dSHariprasad Shenai 	const struct inode *ino;
1296bf7c781dSHariprasad Shenai 	unsigned int mbox;
1297bf7c781dSHariprasad Shenai 	struct adapter *adap;
1298bf7c781dSHariprasad Shenai 	void __iomem *addr;
1299bf7c781dSHariprasad Shenai 	void __iomem *ctrl;
1300bf7c781dSHariprasad Shenai 
1301bf7c781dSHariprasad Shenai 	if (count > sizeof(s) - 1 || !count)
1302bf7c781dSHariprasad Shenai 		return -EINVAL;
1303bf7c781dSHariprasad Shenai 	if (copy_from_user(s, buf, count))
1304bf7c781dSHariprasad Shenai 		return -EFAULT;
1305bf7c781dSHariprasad Shenai 	s[count] = '\0';
1306bf7c781dSHariprasad Shenai 
1307bf7c781dSHariprasad Shenai 	if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
1308bf7c781dSHariprasad Shenai 		   &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
1309bf7c781dSHariprasad Shenai 		   &data[7], &c) < 8 || c != '\n')
1310bf7c781dSHariprasad Shenai 		return -EINVAL;
1311bf7c781dSHariprasad Shenai 
1312c1d81b1cSDavid Howells 	ino = file_inode(file);
1313bf7c781dSHariprasad Shenai 	mbox = (uintptr_t)ino->i_private & 7;
1314bf7c781dSHariprasad Shenai 	adap = ino->i_private - mbox;
1315bf7c781dSHariprasad Shenai 	addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1316bf7c781dSHariprasad Shenai 	ctrl = addr + MBOX_LEN;
1317bf7c781dSHariprasad Shenai 
1318bf7c781dSHariprasad Shenai 	if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
1319bf7c781dSHariprasad Shenai 		return -EBUSY;
1320bf7c781dSHariprasad Shenai 
1321bf7c781dSHariprasad Shenai 	for (i = 0; i < 8; i++)
1322bf7c781dSHariprasad Shenai 		writeq(data[i], addr + 8 * i);
1323bf7c781dSHariprasad Shenai 
1324bf7c781dSHariprasad Shenai 	writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
1325bf7c781dSHariprasad Shenai 	return count;
1326bf7c781dSHariprasad Shenai }
1327bf7c781dSHariprasad Shenai 
1328bf7c781dSHariprasad Shenai static const struct file_operations mbox_debugfs_fops = {
1329bf7c781dSHariprasad Shenai 	.owner   = THIS_MODULE,
1330bf7c781dSHariprasad Shenai 	.open    = mbox_open,
1331bf7c781dSHariprasad Shenai 	.read    = seq_read,
1332bf7c781dSHariprasad Shenai 	.llseek  = seq_lseek,
1333bf7c781dSHariprasad Shenai 	.release = single_release,
1334bf7c781dSHariprasad Shenai 	.write   = mbox_write
1335bf7c781dSHariprasad Shenai };
1336bf7c781dSHariprasad Shenai 
13378e3d04fdSHariprasad Shenai static int mps_trc_show(struct seq_file *seq, void *v)
13388e3d04fdSHariprasad Shenai {
13398e3d04fdSHariprasad Shenai 	int enabled, i;
13408e3d04fdSHariprasad Shenai 	struct trace_params tp;
13418e3d04fdSHariprasad Shenai 	unsigned int trcidx = (uintptr_t)seq->private & 3;
13428e3d04fdSHariprasad Shenai 	struct adapter *adap = seq->private - trcidx;
13438e3d04fdSHariprasad Shenai 
13448e3d04fdSHariprasad Shenai 	t4_get_trace_filter(adap, &tp, trcidx, &enabled);
13458e3d04fdSHariprasad Shenai 	if (!enabled) {
13468e3d04fdSHariprasad Shenai 		seq_puts(seq, "tracer is disabled\n");
13478e3d04fdSHariprasad Shenai 		return 0;
13488e3d04fdSHariprasad Shenai 	}
13498e3d04fdSHariprasad Shenai 
13508e3d04fdSHariprasad Shenai 	if (tp.skip_ofst * 8 >= TRACE_LEN) {
13518e3d04fdSHariprasad Shenai 		dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
13528e3d04fdSHariprasad Shenai 		return -EINVAL;
13538e3d04fdSHariprasad Shenai 	}
13548e3d04fdSHariprasad Shenai 	if (tp.port < 8) {
13558e3d04fdSHariprasad Shenai 		i = adap->chan_map[tp.port & 3];
13568e3d04fdSHariprasad Shenai 		if (i >= MAX_NPORTS) {
13578e3d04fdSHariprasad Shenai 			dev_err(adap->pdev_dev, "tracer %u is assigned "
13588e3d04fdSHariprasad Shenai 				"to non-existing port\n", trcidx);
13598e3d04fdSHariprasad Shenai 			return -EINVAL;
13608e3d04fdSHariprasad Shenai 		}
13618e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing %s %s, ",
13628e3d04fdSHariprasad Shenai 			   adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
13638e3d04fdSHariprasad Shenai 	} else
13648e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing loopback %d, ",
13658e3d04fdSHariprasad Shenai 			   tp.port - 8);
13668e3d04fdSHariprasad Shenai 	seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
13678e3d04fdSHariprasad Shenai 		   tp.min_len);
13688e3d04fdSHariprasad Shenai 	seq_printf(seq, "packets captured %smatch filter\n",
13698e3d04fdSHariprasad Shenai 		   tp.invert ? "do not " : "");
13708e3d04fdSHariprasad Shenai 
13718e3d04fdSHariprasad Shenai 	if (tp.skip_ofst) {
13728e3d04fdSHariprasad Shenai 		seq_puts(seq, "filter pattern: ");
13738e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
13748e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
13758e3d04fdSHariprasad Shenai 		seq_putc(seq, '/');
13768e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
13778e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
13788e3d04fdSHariprasad Shenai 		seq_puts(seq, "@0\n");
13798e3d04fdSHariprasad Shenai 	}
13808e3d04fdSHariprasad Shenai 
13818e3d04fdSHariprasad Shenai 	seq_puts(seq, "filter pattern: ");
13828e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
13838e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
13848e3d04fdSHariprasad Shenai 	seq_putc(seq, '/');
13858e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
13868e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
13878e3d04fdSHariprasad Shenai 	seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
13888e3d04fdSHariprasad Shenai 	return 0;
13898e3d04fdSHariprasad Shenai }
13908e3d04fdSHariprasad Shenai 
13918e3d04fdSHariprasad Shenai static int mps_trc_open(struct inode *inode, struct file *file)
13928e3d04fdSHariprasad Shenai {
13938e3d04fdSHariprasad Shenai 	return single_open(file, mps_trc_show, inode->i_private);
13948e3d04fdSHariprasad Shenai }
13958e3d04fdSHariprasad Shenai 
13968e3d04fdSHariprasad Shenai static unsigned int xdigit2int(unsigned char c)
13978e3d04fdSHariprasad Shenai {
13988e3d04fdSHariprasad Shenai 	return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
13998e3d04fdSHariprasad Shenai }
14008e3d04fdSHariprasad Shenai 
14018e3d04fdSHariprasad Shenai #define TRC_PORT_NONE 0xff
14028e3d04fdSHariprasad Shenai #define TRC_RSS_ENABLE 0x33
14038e3d04fdSHariprasad Shenai #define TRC_RSS_DISABLE 0x13
14048e3d04fdSHariprasad Shenai 
14058e3d04fdSHariprasad Shenai /* Set an MPS trace filter.  Syntax is:
14068e3d04fdSHariprasad Shenai  *
14078e3d04fdSHariprasad Shenai  * disable
14088e3d04fdSHariprasad Shenai  *
14098e3d04fdSHariprasad Shenai  * to disable tracing, or
14108e3d04fdSHariprasad Shenai  *
14118e3d04fdSHariprasad Shenai  * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
14128e3d04fdSHariprasad Shenai  *
14138e3d04fdSHariprasad Shenai  * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
14148e3d04fdSHariprasad Shenai  * of the NIC's response qid obtained from sge_qinfo and pattern has the form
14158e3d04fdSHariprasad Shenai  *
14168e3d04fdSHariprasad Shenai  * <pattern data>[/<pattern mask>][@<anchor>]
14178e3d04fdSHariprasad Shenai  *
14188e3d04fdSHariprasad Shenai  * Up to 2 filter patterns can be specified.  If 2 are supplied the first one
14190cf2a848SMasahiro Yamada  * must be anchored at 0.  An omitted mask is taken as a mask of 1s, an omitted
14208e3d04fdSHariprasad Shenai  * anchor is taken as 0.
14218e3d04fdSHariprasad Shenai  */
14228e3d04fdSHariprasad Shenai static ssize_t mps_trc_write(struct file *file, const char __user *buf,
14238e3d04fdSHariprasad Shenai 			     size_t count, loff_t *pos)
14248e3d04fdSHariprasad Shenai {
1425c938a003SDan Carpenter 	int i, enable, ret;
14268e3d04fdSHariprasad Shenai 	u32 *data, *mask;
14278e3d04fdSHariprasad Shenai 	struct trace_params tp;
14288e3d04fdSHariprasad Shenai 	const struct inode *ino;
14298e3d04fdSHariprasad Shenai 	unsigned int trcidx;
14308e3d04fdSHariprasad Shenai 	char *s, *p, *word, *end;
14318e3d04fdSHariprasad Shenai 	struct adapter *adap;
1432c938a003SDan Carpenter 	u32 j;
14338e3d04fdSHariprasad Shenai 
14348e3d04fdSHariprasad Shenai 	ino = file_inode(file);
14358e3d04fdSHariprasad Shenai 	trcidx = (uintptr_t)ino->i_private & 3;
14368e3d04fdSHariprasad Shenai 	adap = ino->i_private - trcidx;
14378e3d04fdSHariprasad Shenai 
14388e3d04fdSHariprasad Shenai 	/* Don't accept input more than 1K, can't be anything valid except lots
14398e3d04fdSHariprasad Shenai 	 * of whitespace.  Well, use less.
14408e3d04fdSHariprasad Shenai 	 */
14418e3d04fdSHariprasad Shenai 	if (count > 1024)
14428e3d04fdSHariprasad Shenai 		return -EFBIG;
14438e3d04fdSHariprasad Shenai 	p = s = kzalloc(count + 1, GFP_USER);
14448e3d04fdSHariprasad Shenai 	if (!s)
14458e3d04fdSHariprasad Shenai 		return -ENOMEM;
14468e3d04fdSHariprasad Shenai 	if (copy_from_user(s, buf, count)) {
14478e3d04fdSHariprasad Shenai 		count = -EFAULT;
14488e3d04fdSHariprasad Shenai 		goto out;
14498e3d04fdSHariprasad Shenai 	}
14508e3d04fdSHariprasad Shenai 
14518e3d04fdSHariprasad Shenai 	if (s[count - 1] == '\n')
14528e3d04fdSHariprasad Shenai 		s[count - 1] = '\0';
14538e3d04fdSHariprasad Shenai 
14548e3d04fdSHariprasad Shenai 	enable = strcmp("disable", s) != 0;
14558e3d04fdSHariprasad Shenai 	if (!enable)
14568e3d04fdSHariprasad Shenai 		goto apply;
14578e3d04fdSHariprasad Shenai 
14588e3d04fdSHariprasad Shenai 	/* enable or disable trace multi rss filter */
14598e3d04fdSHariprasad Shenai 	if (adap->trace_rss)
14608e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
14618e3d04fdSHariprasad Shenai 	else
14628e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
14638e3d04fdSHariprasad Shenai 
14648e3d04fdSHariprasad Shenai 	memset(&tp, 0, sizeof(tp));
14658e3d04fdSHariprasad Shenai 	tp.port = TRC_PORT_NONE;
14668e3d04fdSHariprasad Shenai 	i = 0;	/* counts pattern nibbles */
14678e3d04fdSHariprasad Shenai 
14688e3d04fdSHariprasad Shenai 	while (p) {
14698e3d04fdSHariprasad Shenai 		while (isspace(*p))
14708e3d04fdSHariprasad Shenai 			p++;
14718e3d04fdSHariprasad Shenai 		word = strsep(&p, " ");
14728e3d04fdSHariprasad Shenai 		if (!*word)
14738e3d04fdSHariprasad Shenai 			break;
14748e3d04fdSHariprasad Shenai 
14758e3d04fdSHariprasad Shenai 		if (!strncmp(word, "qid=", 4)) {
14768e3d04fdSHariprasad Shenai 			end = (char *)word + 4;
1477c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
14788e3d04fdSHariprasad Shenai 			if (ret)
14798e3d04fdSHariprasad Shenai 				goto out;
14808e3d04fdSHariprasad Shenai 			if (!adap->trace_rss) {
14818e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
14828e3d04fdSHariprasad Shenai 				continue;
14838e3d04fdSHariprasad Shenai 			}
14848e3d04fdSHariprasad Shenai 
14858e3d04fdSHariprasad Shenai 			switch (trcidx) {
14868e3d04fdSHariprasad Shenai 			case 0:
14878e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
14888e3d04fdSHariprasad Shenai 				break;
14898e3d04fdSHariprasad Shenai 			case 1:
14908e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14918e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER1_RSS_CONTROL_A, j);
14928e3d04fdSHariprasad Shenai 				break;
14938e3d04fdSHariprasad Shenai 			case 2:
14948e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14958e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER2_RSS_CONTROL_A, j);
14968e3d04fdSHariprasad Shenai 				break;
14978e3d04fdSHariprasad Shenai 			case 3:
14988e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14998e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER3_RSS_CONTROL_A, j);
15008e3d04fdSHariprasad Shenai 				break;
15018e3d04fdSHariprasad Shenai 			}
15028e3d04fdSHariprasad Shenai 			continue;
15038e3d04fdSHariprasad Shenai 		}
15048e3d04fdSHariprasad Shenai 		if (!strncmp(word, "snaplen=", 8)) {
15058e3d04fdSHariprasad Shenai 			end = (char *)word + 8;
1506c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15078e3d04fdSHariprasad Shenai 			if (ret || j > 9600) {
15088e3d04fdSHariprasad Shenai inval:				count = -EINVAL;
15098e3d04fdSHariprasad Shenai 				goto out;
15108e3d04fdSHariprasad Shenai 			}
15118e3d04fdSHariprasad Shenai 			tp.snap_len = j;
15128e3d04fdSHariprasad Shenai 			continue;
15138e3d04fdSHariprasad Shenai 		}
15148e3d04fdSHariprasad Shenai 		if (!strncmp(word, "minlen=", 7)) {
15158e3d04fdSHariprasad Shenai 			end = (char *)word + 7;
1516c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15178e3d04fdSHariprasad Shenai 			if (ret || j > TFMINPKTSIZE_M)
15188e3d04fdSHariprasad Shenai 				goto inval;
15198e3d04fdSHariprasad Shenai 			tp.min_len = j;
15208e3d04fdSHariprasad Shenai 			continue;
15218e3d04fdSHariprasad Shenai 		}
15228e3d04fdSHariprasad Shenai 		if (!strcmp(word, "not")) {
15238e3d04fdSHariprasad Shenai 			tp.invert = !tp.invert;
15248e3d04fdSHariprasad Shenai 			continue;
15258e3d04fdSHariprasad Shenai 		}
15268e3d04fdSHariprasad Shenai 		if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
15278e3d04fdSHariprasad Shenai 			if (word[8] < '0' || word[8] > '3' || word[9])
15288e3d04fdSHariprasad Shenai 				goto inval;
15298e3d04fdSHariprasad Shenai 			tp.port = word[8] - '0' + 8;
15308e3d04fdSHariprasad Shenai 			continue;
15318e3d04fdSHariprasad Shenai 		}
15328e3d04fdSHariprasad Shenai 		if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
15338e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
15348e3d04fdSHariprasad Shenai 				goto inval;
15358e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0' + 4;
15368e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
15378e3d04fdSHariprasad Shenai 				goto inval;
15388e3d04fdSHariprasad Shenai 			continue;
15398e3d04fdSHariprasad Shenai 		}
15408e3d04fdSHariprasad Shenai 		if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
15418e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
15428e3d04fdSHariprasad Shenai 				goto inval;
15438e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0';
15448e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port] >= MAX_NPORTS)
15458e3d04fdSHariprasad Shenai 				goto inval;
15468e3d04fdSHariprasad Shenai 			continue;
15478e3d04fdSHariprasad Shenai 		}
15488e3d04fdSHariprasad Shenai 		if (!isxdigit(*word))
15498e3d04fdSHariprasad Shenai 			goto inval;
15508e3d04fdSHariprasad Shenai 
15518e3d04fdSHariprasad Shenai 		/* we have found a trace pattern */
15528e3d04fdSHariprasad Shenai 		if (i) {                            /* split pattern */
15538e3d04fdSHariprasad Shenai 			if (tp.skip_len)            /* too many splits */
15548e3d04fdSHariprasad Shenai 				goto inval;
15558e3d04fdSHariprasad Shenai 			tp.skip_ofst = i / 16;
15568e3d04fdSHariprasad Shenai 		}
15578e3d04fdSHariprasad Shenai 
15588e3d04fdSHariprasad Shenai 		data = &tp.data[i / 8];
15598e3d04fdSHariprasad Shenai 		mask = &tp.mask[i / 8];
15608e3d04fdSHariprasad Shenai 		j = i;
15618e3d04fdSHariprasad Shenai 
15628e3d04fdSHariprasad Shenai 		while (isxdigit(*word)) {
15638e3d04fdSHariprasad Shenai 			if (i >= TRACE_LEN * 2) {
15648e3d04fdSHariprasad Shenai 				count = -EFBIG;
15658e3d04fdSHariprasad Shenai 				goto out;
15668e3d04fdSHariprasad Shenai 			}
15678e3d04fdSHariprasad Shenai 			*data = (*data << 4) + xdigit2int(*word++);
15688e3d04fdSHariprasad Shenai 			if (++i % 8 == 0)
15698e3d04fdSHariprasad Shenai 				data++;
15708e3d04fdSHariprasad Shenai 		}
15718e3d04fdSHariprasad Shenai 		if (*word == '/') {
15728e3d04fdSHariprasad Shenai 			word++;
15738e3d04fdSHariprasad Shenai 			while (isxdigit(*word)) {
15748e3d04fdSHariprasad Shenai 				if (j >= i)         /* mask longer than data */
15758e3d04fdSHariprasad Shenai 					goto inval;
15768e3d04fdSHariprasad Shenai 				*mask = (*mask << 4) + xdigit2int(*word++);
15778e3d04fdSHariprasad Shenai 				if (++j % 8 == 0)
15788e3d04fdSHariprasad Shenai 					mask++;
15798e3d04fdSHariprasad Shenai 			}
15808e3d04fdSHariprasad Shenai 			if (i != j)                 /* mask shorter than data */
15818e3d04fdSHariprasad Shenai 				goto inval;
15828e3d04fdSHariprasad Shenai 		} else {                            /* no mask, use all 1s */
15838e3d04fdSHariprasad Shenai 			for ( ; i - j >= 8; j += 8)
15848e3d04fdSHariprasad Shenai 				*mask++ = 0xffffffff;
15858e3d04fdSHariprasad Shenai 			if (i % 8)
15868e3d04fdSHariprasad Shenai 				*mask = (1 << (i % 8) * 4) - 1;
15878e3d04fdSHariprasad Shenai 		}
15888e3d04fdSHariprasad Shenai 		if (*word == '@') {
15898e3d04fdSHariprasad Shenai 			end = (char *)word + 1;
1590c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
15918e3d04fdSHariprasad Shenai 			if (*end && *end != '\n')
15928e3d04fdSHariprasad Shenai 				goto inval;
15938e3d04fdSHariprasad Shenai 			if (j & 7)          /* doesn't start at multiple of 8 */
15948e3d04fdSHariprasad Shenai 				goto inval;
15958e3d04fdSHariprasad Shenai 			j /= 8;
15968e3d04fdSHariprasad Shenai 			if (j < tp.skip_ofst)     /* overlaps earlier pattern */
15978e3d04fdSHariprasad Shenai 				goto inval;
15988e3d04fdSHariprasad Shenai 			if (j - tp.skip_ofst > 31)            /* skip too big */
15998e3d04fdSHariprasad Shenai 				goto inval;
16008e3d04fdSHariprasad Shenai 			tp.skip_len = j - tp.skip_ofst;
16018e3d04fdSHariprasad Shenai 		}
16028e3d04fdSHariprasad Shenai 		if (i % 8) {
16038e3d04fdSHariprasad Shenai 			*data <<= (8 - i % 8) * 4;
16048e3d04fdSHariprasad Shenai 			*mask <<= (8 - i % 8) * 4;
16058e3d04fdSHariprasad Shenai 			i = (i + 15) & ~15;         /* 8-byte align */
16068e3d04fdSHariprasad Shenai 		}
16078e3d04fdSHariprasad Shenai 	}
16088e3d04fdSHariprasad Shenai 
16098e3d04fdSHariprasad Shenai 	if (tp.port == TRC_PORT_NONE)
16108e3d04fdSHariprasad Shenai 		goto inval;
16118e3d04fdSHariprasad Shenai 
16128e3d04fdSHariprasad Shenai apply:
16138e3d04fdSHariprasad Shenai 	i = t4_set_trace_filter(adap, &tp, trcidx, enable);
16148e3d04fdSHariprasad Shenai 	if (i)
16158e3d04fdSHariprasad Shenai 		count = i;
16168e3d04fdSHariprasad Shenai out:
16178e3d04fdSHariprasad Shenai 	kfree(s);
16188e3d04fdSHariprasad Shenai 	return count;
16198e3d04fdSHariprasad Shenai }
16208e3d04fdSHariprasad Shenai 
16218e3d04fdSHariprasad Shenai static const struct file_operations mps_trc_debugfs_fops = {
16228e3d04fdSHariprasad Shenai 	.owner   = THIS_MODULE,
16238e3d04fdSHariprasad Shenai 	.open    = mps_trc_open,
16248e3d04fdSHariprasad Shenai 	.read    = seq_read,
16258e3d04fdSHariprasad Shenai 	.llseek  = seq_lseek,
16268e3d04fdSHariprasad Shenai 	.release = single_release,
16278e3d04fdSHariprasad Shenai 	.write   = mps_trc_write
16288e3d04fdSHariprasad Shenai };
16298e3d04fdSHariprasad Shenai 
163049216c1cSHariprasad Shenai static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
163149216c1cSHariprasad Shenai 			  loff_t *ppos)
163249216c1cSHariprasad Shenai {
163349216c1cSHariprasad Shenai 	loff_t pos = *ppos;
1634c1d81b1cSDavid Howells 	loff_t avail = file_inode(file)->i_size;
163549216c1cSHariprasad Shenai 	struct adapter *adap = file->private_data;
163649216c1cSHariprasad Shenai 
163749216c1cSHariprasad Shenai 	if (pos < 0)
163849216c1cSHariprasad Shenai 		return -EINVAL;
163949216c1cSHariprasad Shenai 	if (pos >= avail)
164049216c1cSHariprasad Shenai 		return 0;
164149216c1cSHariprasad Shenai 	if (count > avail - pos)
164249216c1cSHariprasad Shenai 		count = avail - pos;
164349216c1cSHariprasad Shenai 
164449216c1cSHariprasad Shenai 	while (count) {
164549216c1cSHariprasad Shenai 		size_t len;
164649216c1cSHariprasad Shenai 		int ret, ofst;
164749216c1cSHariprasad Shenai 		u8 data[256];
164849216c1cSHariprasad Shenai 
164949216c1cSHariprasad Shenai 		ofst = pos & 3;
165049216c1cSHariprasad Shenai 		len = min(count + ofst, sizeof(data));
165149216c1cSHariprasad Shenai 		ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
165249216c1cSHariprasad Shenai 				    (u32 *)data, 1);
165349216c1cSHariprasad Shenai 		if (ret)
165449216c1cSHariprasad Shenai 			return ret;
165549216c1cSHariprasad Shenai 
165649216c1cSHariprasad Shenai 		len -= ofst;
165749216c1cSHariprasad Shenai 		if (copy_to_user(buf, data + ofst, len))
165849216c1cSHariprasad Shenai 			return -EFAULT;
165949216c1cSHariprasad Shenai 
166049216c1cSHariprasad Shenai 		buf += len;
166149216c1cSHariprasad Shenai 		pos += len;
166249216c1cSHariprasad Shenai 		count -= len;
166349216c1cSHariprasad Shenai 	}
166449216c1cSHariprasad Shenai 	count = pos - *ppos;
166549216c1cSHariprasad Shenai 	*ppos = pos;
166649216c1cSHariprasad Shenai 	return count;
166749216c1cSHariprasad Shenai }
166849216c1cSHariprasad Shenai 
166949216c1cSHariprasad Shenai static const struct file_operations flash_debugfs_fops = {
167049216c1cSHariprasad Shenai 	.owner   = THIS_MODULE,
167149216c1cSHariprasad Shenai 	.open    = mem_open,
167249216c1cSHariprasad Shenai 	.read    = flash_read,
1673ed98c85eSHariprasad Shenai 	.llseek  = default_llseek,
167449216c1cSHariprasad Shenai };
167549216c1cSHariprasad Shenai 
1676ef82f662SHariprasad Shenai static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1677ef82f662SHariprasad Shenai {
1678ef82f662SHariprasad Shenai 	*mask = x | y;
1679ef82f662SHariprasad Shenai 	y = (__force u64)cpu_to_be64(y);
1680ef82f662SHariprasad Shenai 	memcpy(addr, (char *)&y + 2, ETH_ALEN);
1681ef82f662SHariprasad Shenai }
1682ef82f662SHariprasad Shenai 
1683ef82f662SHariprasad Shenai static int mps_tcam_show(struct seq_file *seq, void *v)
1684ef82f662SHariprasad Shenai {
16853ccc6cf7SHariprasad Shenai 	struct adapter *adap = seq->private;
16863ccc6cf7SHariprasad Shenai 	unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
16873ccc6cf7SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
1688115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1689115b56afSHariprasad Shenai 			seq_puts(seq, "Idx  Ethernet address     Mask     "
1690115b56afSHariprasad Shenai 				 "  VNI   Mask   IVLAN Vld "
1691115b56afSHariprasad Shenai 				 "DIP_Hit   Lookup  Port "
1692115b56afSHariprasad Shenai 				 "Vld Ports PF  VF                           "
1693115b56afSHariprasad Shenai 				 "Replication                                "
1694115b56afSHariprasad Shenai 				 "    P0 P1 P2 P3  ML\n");
1695115b56afSHariprasad Shenai 		} else {
16963ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
16973ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
16983ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF                           "
16993ccc6cf7SHariprasad Shenai 					 "Replication                                "
1700ef82f662SHariprasad Shenai 					 "    P0 P1 P2 P3  ML\n");
17013ccc6cf7SHariprasad Shenai 			else
17023ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
17033ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF              Replication"
17043ccc6cf7SHariprasad Shenai 					 "	         P0 P1 P2 P3  ML\n");
1705115b56afSHariprasad Shenai 		}
17063ccc6cf7SHariprasad Shenai 	} else {
1707ef82f662SHariprasad Shenai 		u64 mask;
1708ef82f662SHariprasad Shenai 		u8 addr[ETH_ALEN];
1709115b56afSHariprasad Shenai 		bool replicate, dip_hit = false, vlan_vld = false;
1710ef82f662SHariprasad Shenai 		unsigned int idx = (uintptr_t)v - 2;
17113ccc6cf7SHariprasad Shenai 		u64 tcamy, tcamx, val;
1712115b56afSHariprasad Shenai 		u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
17133ccc6cf7SHariprasad Shenai 		u32 rplc[8] = {0};
1714115b56afSHariprasad Shenai 		u8 lookup_type = 0, port_num = 0;
1715115b56afSHariprasad Shenai 		u16 ivlan = 0;
17163ccc6cf7SHariprasad Shenai 
17173ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
17183ccc6cf7SHariprasad Shenai 			/* CtlCmdType - 0: Read, 1: Write
17193ccc6cf7SHariprasad Shenai 			 * CtlTcamSel - 0: TCAM0, 1: TCAM1
17203ccc6cf7SHariprasad Shenai 			 * CtlXYBitSel- 0: Y bit, 1: X bit
17213ccc6cf7SHariprasad Shenai 			 */
17223ccc6cf7SHariprasad Shenai 
17233ccc6cf7SHariprasad Shenai 			/* Read tcamy */
17243ccc6cf7SHariprasad Shenai 			ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
17253ccc6cf7SHariprasad Shenai 			if (idx < 256)
17263ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
17273ccc6cf7SHariprasad Shenai 			else
17283ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx - 256) |
17293ccc6cf7SHariprasad Shenai 				       CTLTCAMSEL_V(1);
17303ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
17313ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
17323ccc6cf7SHariprasad Shenai 			tcamy = DMACH_G(val) << 32;
17333ccc6cf7SHariprasad Shenai 			tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1734115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1735115b56afSHariprasad Shenai 			lookup_type = DATALKPTYPE_G(data2);
1736115b56afSHariprasad Shenai 			/* 0 - Outer header, 1 - Inner header
1737115b56afSHariprasad Shenai 			 * [71:48] bit locations are overloaded for
1738115b56afSHariprasad Shenai 			 * outer vs. inner lookup types.
1739115b56afSHariprasad Shenai 			 */
1740115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1741115b56afSHariprasad Shenai 				/* Inner header VNI */
1742115b56afSHariprasad Shenai 				vniy = ((data2 & DATAVIDH2_F) << 23) |
1743115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1744115b56afSHariprasad Shenai 				dip_hit = data2 & DATADIPHIT_F;
1745115b56afSHariprasad Shenai 			} else {
1746115b56afSHariprasad Shenai 				vlan_vld = data2 & DATAVIDH2_F;
1747115b56afSHariprasad Shenai 				ivlan = VIDL_G(val);
1748115b56afSHariprasad Shenai 			}
1749115b56afSHariprasad Shenai 			port_num = DATAPORTNUM_G(data2);
17503ccc6cf7SHariprasad Shenai 
17513ccc6cf7SHariprasad Shenai 			/* Read tcamx. Change the control param */
17523ccc6cf7SHariprasad Shenai 			ctl |= CTLXYBITSEL_V(1);
17533ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
17543ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
17553ccc6cf7SHariprasad Shenai 			tcamx = DMACH_G(val) << 32;
17563ccc6cf7SHariprasad Shenai 			tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1757115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1758115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1759115b56afSHariprasad Shenai 				/* Inner header VNI mask */
1760115b56afSHariprasad Shenai 				vnix = ((data2 & DATAVIDH2_F) << 23) |
1761115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1762115b56afSHariprasad Shenai 			}
17633ccc6cf7SHariprasad Shenai 		} else {
17643ccc6cf7SHariprasad Shenai 			tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
17653ccc6cf7SHariprasad Shenai 			tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
17663ccc6cf7SHariprasad Shenai 		}
17673ccc6cf7SHariprasad Shenai 
17683ccc6cf7SHariprasad Shenai 		cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
17693ccc6cf7SHariprasad Shenai 		cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
1770ef82f662SHariprasad Shenai 
1771ef82f662SHariprasad Shenai 		if (tcamx & tcamy) {
1772ef82f662SHariprasad Shenai 			seq_printf(seq, "%3u         -\n", idx);
1773ef82f662SHariprasad Shenai 			goto out;
1774ef82f662SHariprasad Shenai 		}
1775ef82f662SHariprasad Shenai 
17763ccc6cf7SHariprasad Shenai 		rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
17773ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
17783ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & T6_REPLICATE_F);
17793ccc6cf7SHariprasad Shenai 		else
17803ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & REPLICATE_F);
17813ccc6cf7SHariprasad Shenai 
17823ccc6cf7SHariprasad Shenai 		if (replicate) {
1783ef82f662SHariprasad Shenai 			struct fw_ldst_cmd ldst_cmd;
1784ef82f662SHariprasad Shenai 			int ret;
17853ccc6cf7SHariprasad Shenai 			struct fw_ldst_mps_rplc mps_rplc;
17863ccc6cf7SHariprasad Shenai 			u32 ldst_addrspc;
1787ef82f662SHariprasad Shenai 
1788ef82f662SHariprasad Shenai 			memset(&ldst_cmd, 0, sizeof(ldst_cmd));
17893ccc6cf7SHariprasad Shenai 			ldst_addrspc =
17903ccc6cf7SHariprasad Shenai 				FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
1791ef82f662SHariprasad Shenai 			ldst_cmd.op_to_addrspace =
1792ef82f662SHariprasad Shenai 				htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1793ef82f662SHariprasad Shenai 				      FW_CMD_REQUEST_F |
1794ef82f662SHariprasad Shenai 				      FW_CMD_READ_F |
17953ccc6cf7SHariprasad Shenai 				      ldst_addrspc);
1796ef82f662SHariprasad Shenai 			ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
17973ccc6cf7SHariprasad Shenai 			ldst_cmd.u.mps.rplc.fid_idx =
1798ef82f662SHariprasad Shenai 				htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
17993ccc6cf7SHariprasad Shenai 				      FW_LDST_CMD_IDX_V(idx));
1800ef82f662SHariprasad Shenai 			ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1801ef82f662SHariprasad Shenai 					 sizeof(ldst_cmd), &ldst_cmd);
1802ef82f662SHariprasad Shenai 			if (ret)
1803ef82f662SHariprasad Shenai 				dev_warn(adap->pdev_dev, "Can't read MPS "
1804ef82f662SHariprasad Shenai 					 "replication map for idx %d: %d\n",
1805ef82f662SHariprasad Shenai 					 idx, -ret);
1806ef82f662SHariprasad Shenai 			else {
18073ccc6cf7SHariprasad Shenai 				mps_rplc = ldst_cmd.u.mps.rplc;
18083ccc6cf7SHariprasad Shenai 				rplc[0] = ntohl(mps_rplc.rplc31_0);
18093ccc6cf7SHariprasad Shenai 				rplc[1] = ntohl(mps_rplc.rplc63_32);
18103ccc6cf7SHariprasad Shenai 				rplc[2] = ntohl(mps_rplc.rplc95_64);
18113ccc6cf7SHariprasad Shenai 				rplc[3] = ntohl(mps_rplc.rplc127_96);
18123ccc6cf7SHariprasad Shenai 				if (adap->params.arch.mps_rplc_size > 128) {
18133ccc6cf7SHariprasad Shenai 					rplc[4] = ntohl(mps_rplc.rplc159_128);
18143ccc6cf7SHariprasad Shenai 					rplc[5] = ntohl(mps_rplc.rplc191_160);
18153ccc6cf7SHariprasad Shenai 					rplc[6] = ntohl(mps_rplc.rplc223_192);
18163ccc6cf7SHariprasad Shenai 					rplc[7] = ntohl(mps_rplc.rplc255_224);
18173ccc6cf7SHariprasad Shenai 				}
1818ef82f662SHariprasad Shenai 			}
1819ef82f662SHariprasad Shenai 		}
1820ef82f662SHariprasad Shenai 
1821ef82f662SHariprasad Shenai 		tcamxy2valmask(tcamx, tcamy, addr, &mask);
1822115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1823115b56afSHariprasad Shenai 			/* Inner header lookup */
1824115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1825115b56afSHariprasad Shenai 				seq_printf(seq,
1826115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1827115b56afSHariprasad Shenai 					   "%012llx %06x %06x    -    -   %3c"
182889e7a154SHariprasad Shenai 					   "      'I'  %4x   "
1829115b56afSHariprasad Shenai 					   "%3c   %#x%4u%4d", idx, addr[0],
1830115b56afSHariprasad Shenai 					   addr[1], addr[2], addr[3],
1831115b56afSHariprasad Shenai 					   addr[4], addr[5],
1832115b56afSHariprasad Shenai 					   (unsigned long long)mask,
1833115b56afSHariprasad Shenai 					   vniy, vnix, dip_hit ? 'Y' : 'N',
183489e7a154SHariprasad Shenai 					   port_num,
18353ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
18363ccc6cf7SHariprasad Shenai 					   PORTMAP_G(cls_hi),
18373ccc6cf7SHariprasad Shenai 					   T6_PF_G(cls_lo),
18383ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
18393ccc6cf7SHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1840115b56afSHariprasad Shenai 			} else {
1841115b56afSHariprasad Shenai 				seq_printf(seq,
1842115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1843115b56afSHariprasad Shenai 					   "%012llx    -       -   ",
1844115b56afSHariprasad Shenai 					   idx, addr[0], addr[1], addr[2],
1845115b56afSHariprasad Shenai 					   addr[3], addr[4], addr[5],
1846115b56afSHariprasad Shenai 					   (unsigned long long)mask);
1847115b56afSHariprasad Shenai 
1848115b56afSHariprasad Shenai 				if (vlan_vld)
1849115b56afSHariprasad Shenai 					seq_printf(seq, "%4u   Y     ", ivlan);
18503ccc6cf7SHariprasad Shenai 				else
1851115b56afSHariprasad Shenai 					seq_puts(seq, "  -    N     ");
1852115b56afSHariprasad Shenai 
1853115b56afSHariprasad Shenai 				seq_printf(seq,
1854115b56afSHariprasad Shenai 					   "-      %3c  %4x   %3c   %#x%4u%4d",
1855115b56afSHariprasad Shenai 					   lookup_type ? 'I' : 'O', port_num,
1856115b56afSHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1857115b56afSHariprasad Shenai 					   PORTMAP_G(cls_hi),
1858115b56afSHariprasad Shenai 					   T6_PF_G(cls_lo),
1859115b56afSHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
1860115b56afSHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1861115b56afSHariprasad Shenai 			}
1862115b56afSHariprasad Shenai 		} else
18633ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
18643ccc6cf7SHariprasad Shenai 				   "%012llx%3c   %#x%4u%4d",
18653ccc6cf7SHariprasad Shenai 				   idx, addr[0], addr[1], addr[2], addr[3],
18663ccc6cf7SHariprasad Shenai 				   addr[4], addr[5], (unsigned long long)mask,
18673ccc6cf7SHariprasad Shenai 				   (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
18683ccc6cf7SHariprasad Shenai 				   PORTMAP_G(cls_hi),
1869ef82f662SHariprasad Shenai 				   PF_G(cls_lo),
1870ef82f662SHariprasad Shenai 				   (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
18713ccc6cf7SHariprasad Shenai 
18723ccc6cf7SHariprasad Shenai 		if (replicate) {
18733ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
18743ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x "
18753ccc6cf7SHariprasad Shenai 					   "%08x %08x %08x %08x",
18763ccc6cf7SHariprasad Shenai 					   rplc[7], rplc[6], rplc[5], rplc[4],
1877ef82f662SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
1878ef82f662SHariprasad Shenai 			else
18793ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x",
18803ccc6cf7SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
18813ccc6cf7SHariprasad Shenai 		} else {
18823ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
18833ccc6cf7SHariprasad Shenai 				seq_printf(seq, "%72c", ' ');
18843ccc6cf7SHariprasad Shenai 			else
1885ef82f662SHariprasad Shenai 				seq_printf(seq, "%36c", ' ');
18863ccc6cf7SHariprasad Shenai 		}
18873ccc6cf7SHariprasad Shenai 
18883ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
18893ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
18903ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO0_G(cls_lo),
18913ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO1_G(cls_lo),
18923ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO2_G(cls_lo),
18933ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO3_G(cls_lo),
18943ccc6cf7SHariprasad Shenai 				   (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
18953ccc6cf7SHariprasad Shenai 		else
1896ef82f662SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1897ef82f662SHariprasad Shenai 				   SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1898ef82f662SHariprasad Shenai 				   SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1899ef82f662SHariprasad Shenai 				   (cls_lo >> MULTILISTEN0_S) & 0xf);
1900ef82f662SHariprasad Shenai 	}
1901ef82f662SHariprasad Shenai out:	return 0;
1902ef82f662SHariprasad Shenai }
1903ef82f662SHariprasad Shenai 
1904ef82f662SHariprasad Shenai static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1905ef82f662SHariprasad Shenai {
1906ef82f662SHariprasad Shenai 	struct adapter *adap = seq->private;
1907ef82f662SHariprasad Shenai 	int max_mac_addr = is_t4(adap->params.chip) ?
1908ef82f662SHariprasad Shenai 				NUM_MPS_CLS_SRAM_L_INSTANCES :
1909ef82f662SHariprasad Shenai 				NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1910ef82f662SHariprasad Shenai 	return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1911ef82f662SHariprasad Shenai }
1912ef82f662SHariprasad Shenai 
1913ef82f662SHariprasad Shenai static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1914ef82f662SHariprasad Shenai {
1915ef82f662SHariprasad Shenai 	return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1916ef82f662SHariprasad Shenai }
1917ef82f662SHariprasad Shenai 
1918ef82f662SHariprasad Shenai static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1919ef82f662SHariprasad Shenai {
1920ef82f662SHariprasad Shenai 	++*pos;
1921ef82f662SHariprasad Shenai 	return mps_tcam_get_idx(seq, *pos);
1922ef82f662SHariprasad Shenai }
1923ef82f662SHariprasad Shenai 
1924ef82f662SHariprasad Shenai static void mps_tcam_stop(struct seq_file *seq, void *v)
1925ef82f662SHariprasad Shenai {
1926ef82f662SHariprasad Shenai }
1927ef82f662SHariprasad Shenai 
1928ef82f662SHariprasad Shenai static const struct seq_operations mps_tcam_seq_ops = {
1929ef82f662SHariprasad Shenai 	.start = mps_tcam_start,
1930ef82f662SHariprasad Shenai 	.next  = mps_tcam_next,
1931ef82f662SHariprasad Shenai 	.stop  = mps_tcam_stop,
1932ef82f662SHariprasad Shenai 	.show  = mps_tcam_show
1933ef82f662SHariprasad Shenai };
1934ef82f662SHariprasad Shenai 
1935ef82f662SHariprasad Shenai static int mps_tcam_open(struct inode *inode, struct file *file)
1936ef82f662SHariprasad Shenai {
1937ef82f662SHariprasad Shenai 	int res = seq_open(file, &mps_tcam_seq_ops);
1938ef82f662SHariprasad Shenai 
1939ef82f662SHariprasad Shenai 	if (!res) {
1940ef82f662SHariprasad Shenai 		struct seq_file *seq = file->private_data;
1941ef82f662SHariprasad Shenai 
1942ef82f662SHariprasad Shenai 		seq->private = inode->i_private;
1943ef82f662SHariprasad Shenai 	}
1944ef82f662SHariprasad Shenai 	return res;
1945ef82f662SHariprasad Shenai }
1946ef82f662SHariprasad Shenai 
1947ef82f662SHariprasad Shenai static const struct file_operations mps_tcam_debugfs_fops = {
1948ef82f662SHariprasad Shenai 	.owner   = THIS_MODULE,
1949ef82f662SHariprasad Shenai 	.open    = mps_tcam_open,
1950ef82f662SHariprasad Shenai 	.read    = seq_read,
1951ef82f662SHariprasad Shenai 	.llseek  = seq_lseek,
1952ef82f662SHariprasad Shenai 	.release = seq_release,
1953ef82f662SHariprasad Shenai };
1954ef82f662SHariprasad Shenai 
195570a5f3bbSHariprasad Shenai /* Display various sensor information.
195670a5f3bbSHariprasad Shenai  */
195770a5f3bbSHariprasad Shenai static int sensors_show(struct seq_file *seq, void *v)
195870a5f3bbSHariprasad Shenai {
195970a5f3bbSHariprasad Shenai 	struct adapter *adap = seq->private;
196070a5f3bbSHariprasad Shenai 	u32 param[7], val[7];
196170a5f3bbSHariprasad Shenai 	int ret;
196270a5f3bbSHariprasad Shenai 
196370a5f3bbSHariprasad Shenai 	/* Note that if the sensors haven't been initialized and turned on
196470a5f3bbSHariprasad Shenai 	 * we'll get values of 0, so treat those as "<unknown>" ...
196570a5f3bbSHariprasad Shenai 	 */
196670a5f3bbSHariprasad Shenai 	param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
196770a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
196870a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
196970a5f3bbSHariprasad Shenai 	param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
197070a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
197170a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1972b2612722SHariprasad Shenai 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
197370a5f3bbSHariprasad Shenai 			      param, val);
197470a5f3bbSHariprasad Shenai 
197570a5f3bbSHariprasad Shenai 	if (ret < 0 || val[0] == 0)
197670a5f3bbSHariprasad Shenai 		seq_puts(seq, "Temperature: <unknown>\n");
197770a5f3bbSHariprasad Shenai 	else
197870a5f3bbSHariprasad Shenai 		seq_printf(seq, "Temperature: %dC\n", val[0]);
197970a5f3bbSHariprasad Shenai 
198070a5f3bbSHariprasad Shenai 	if (ret < 0 || val[1] == 0)
198170a5f3bbSHariprasad Shenai 		seq_puts(seq, "Core VDD:    <unknown>\n");
198270a5f3bbSHariprasad Shenai 	else
198370a5f3bbSHariprasad Shenai 		seq_printf(seq, "Core VDD:    %dmV\n", val[1]);
198470a5f3bbSHariprasad Shenai 
198570a5f3bbSHariprasad Shenai 	return 0;
198670a5f3bbSHariprasad Shenai }
198770a5f3bbSHariprasad Shenai 
198870a5f3bbSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
198970a5f3bbSHariprasad Shenai 
1990b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1991b5a02f50SAnish Bhatt static int clip_tbl_open(struct inode *inode, struct file *file)
1992b5a02f50SAnish Bhatt {
1993acde2c2dSHariprasad Shenai 	return single_open(file, clip_tbl_show, inode->i_private);
1994b5a02f50SAnish Bhatt }
1995b5a02f50SAnish Bhatt 
1996b5a02f50SAnish Bhatt static const struct file_operations clip_tbl_debugfs_fops = {
1997b5a02f50SAnish Bhatt 	.owner   = THIS_MODULE,
1998b5a02f50SAnish Bhatt 	.open    = clip_tbl_open,
1999b5a02f50SAnish Bhatt 	.read    = seq_read,
2000b5a02f50SAnish Bhatt 	.llseek  = seq_lseek,
2001b5a02f50SAnish Bhatt 	.release = single_release
2002b5a02f50SAnish Bhatt };
2003b5a02f50SAnish Bhatt #endif
2004b5a02f50SAnish Bhatt 
2005688ea5feSHariprasad Shenai /*RSS Table.
2006688ea5feSHariprasad Shenai  */
2007688ea5feSHariprasad Shenai 
2008688ea5feSHariprasad Shenai static int rss_show(struct seq_file *seq, void *v, int idx)
2009688ea5feSHariprasad Shenai {
2010688ea5feSHariprasad Shenai 	u16 *entry = v;
2011688ea5feSHariprasad Shenai 
2012688ea5feSHariprasad Shenai 	seq_printf(seq, "%4d:  %4u  %4u  %4u  %4u  %4u  %4u  %4u  %4u\n",
2013688ea5feSHariprasad Shenai 		   idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
2014688ea5feSHariprasad Shenai 		   entry[5], entry[6], entry[7]);
2015688ea5feSHariprasad Shenai 	return 0;
2016688ea5feSHariprasad Shenai }
2017688ea5feSHariprasad Shenai 
2018688ea5feSHariprasad Shenai static int rss_open(struct inode *inode, struct file *file)
2019688ea5feSHariprasad Shenai {
2020688ea5feSHariprasad Shenai 	int ret;
2021688ea5feSHariprasad Shenai 	struct seq_tab *p;
2022688ea5feSHariprasad Shenai 	struct adapter *adap = inode->i_private;
2023688ea5feSHariprasad Shenai 
2024688ea5feSHariprasad Shenai 	p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
2025688ea5feSHariprasad Shenai 	if (!p)
2026688ea5feSHariprasad Shenai 		return -ENOMEM;
2027688ea5feSHariprasad Shenai 
2028688ea5feSHariprasad Shenai 	ret = t4_read_rss(adap, (u16 *)p->data);
2029688ea5feSHariprasad Shenai 	if (ret)
2030688ea5feSHariprasad Shenai 		seq_release_private(inode, file);
2031688ea5feSHariprasad Shenai 
2032688ea5feSHariprasad Shenai 	return ret;
2033688ea5feSHariprasad Shenai }
2034688ea5feSHariprasad Shenai 
2035688ea5feSHariprasad Shenai static const struct file_operations rss_debugfs_fops = {
2036688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2037688ea5feSHariprasad Shenai 	.open    = rss_open,
2038688ea5feSHariprasad Shenai 	.read    = seq_read,
2039688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2040688ea5feSHariprasad Shenai 	.release = seq_release_private
2041688ea5feSHariprasad Shenai };
2042688ea5feSHariprasad Shenai 
2043688ea5feSHariprasad Shenai /* RSS Configuration.
2044688ea5feSHariprasad Shenai  */
2045688ea5feSHariprasad Shenai 
2046688ea5feSHariprasad Shenai /* Small utility function to return the strings "yes" or "no" if the supplied
2047688ea5feSHariprasad Shenai  * argument is non-zero.
2048688ea5feSHariprasad Shenai  */
2049688ea5feSHariprasad Shenai static const char *yesno(int x)
2050688ea5feSHariprasad Shenai {
2051688ea5feSHariprasad Shenai 	static const char *yes = "yes";
2052688ea5feSHariprasad Shenai 	static const char *no = "no";
2053688ea5feSHariprasad Shenai 
2054688ea5feSHariprasad Shenai 	return x ? yes : no;
2055688ea5feSHariprasad Shenai }
2056688ea5feSHariprasad Shenai 
2057688ea5feSHariprasad Shenai static int rss_config_show(struct seq_file *seq, void *v)
2058688ea5feSHariprasad Shenai {
2059688ea5feSHariprasad Shenai 	struct adapter *adapter = seq->private;
2060688ea5feSHariprasad Shenai 	static const char * const keymode[] = {
2061688ea5feSHariprasad Shenai 		"global",
2062688ea5feSHariprasad Shenai 		"global and per-VF scramble",
2063688ea5feSHariprasad Shenai 		"per-PF and per-VF scramble",
2064688ea5feSHariprasad Shenai 		"per-VF and per-VF scramble",
2065688ea5feSHariprasad Shenai 	};
2066688ea5feSHariprasad Shenai 	u32 rssconf;
2067688ea5feSHariprasad Shenai 
2068688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
2069688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
2070688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
2071688ea5feSHariprasad Shenai 							TNL4TUPENIPV6_F));
2072688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
2073688ea5feSHariprasad Shenai 							TNL2TUPENIPV6_F));
2074688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
2075688ea5feSHariprasad Shenai 							TNL4TUPENIPV4_F));
2076688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
2077688ea5feSHariprasad Shenai 							TNL2TUPENIPV4_F));
2078688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlTcpSel:     %3s\n", yesno(rssconf & TNLTCPSEL_F));
2079688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlIp6Sel:     %3s\n", yesno(rssconf & TNLIP6SEL_F));
2080688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlVrtSel:     %3s\n", yesno(rssconf & TNLVRTSEL_F));
2081688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlMapEn:      %3s\n", yesno(rssconf & TNLMAPEN_F));
2082688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdHashSave:   %3s\n", yesno(rssconf &
2083688ea5feSHariprasad Shenai 							OFDHASHSAVE_F));
2084688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdVrtSel:     %3s\n", yesno(rssconf & OFDVRTSEL_F));
2085688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdMapEn:      %3s\n", yesno(rssconf & OFDMAPEN_F));
2086688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdLkpEn:      %3s\n", yesno(rssconf & OFDLKPEN_F));
2087688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2088688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
2089688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv6: %3s\n", yesno(rssconf &
2090688ea5feSHariprasad Shenai 							SYN2TUPENIPV6_F));
2091688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv4: %3s\n", yesno(rssconf &
2092688ea5feSHariprasad Shenai 							SYN4TUPENIPV4_F));
2093688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv4: %3s\n", yesno(rssconf &
2094688ea5feSHariprasad Shenai 							SYN2TUPENIPV4_F));
2095688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
2096688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
2097688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynIp6Sel:     %3s\n", yesno(rssconf & SYNIP6SEL_F));
2098688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynVrt6Sel:    %3s\n", yesno(rssconf & SYNVRTSEL_F));
2099688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynMapEn:      %3s\n", yesno(rssconf & SYNMAPEN_F));
2100688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynLkpEn:      %3s\n", yesno(rssconf & SYNLKPEN_F));
2101688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnEn:         %3s\n", yesno(rssconf &
2102688ea5feSHariprasad Shenai 							CHANNELENABLE_F));
2103688ea5feSHariprasad Shenai 	seq_printf(seq, "  PrtEn:         %3s\n", yesno(rssconf &
2104688ea5feSHariprasad Shenai 							PORTENABLE_F));
2105688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlAllLkp:     %3s\n", yesno(rssconf &
2106688ea5feSHariprasad Shenai 							TNLALLLOOKUP_F));
2107688ea5feSHariprasad Shenai 	seq_printf(seq, "  VrtEn:         %3s\n", yesno(rssconf &
2108688ea5feSHariprasad Shenai 							VIRTENABLE_F));
2109688ea5feSHariprasad Shenai 	seq_printf(seq, "  CngEn:         %3s\n", yesno(rssconf &
2110688ea5feSHariprasad Shenai 							CONGESTIONENABLE_F));
2111688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashToeplitz:  %3s\n", yesno(rssconf &
2112688ea5feSHariprasad Shenai 							HASHTOEPLITZ_F));
2113688ea5feSHariprasad Shenai 	seq_printf(seq, "  Udp4En:        %3s\n", yesno(rssconf & UDPENABLE_F));
2114688ea5feSHariprasad Shenai 	seq_printf(seq, "  Disable:       %3s\n", yesno(rssconf & DISABLE_F));
2115688ea5feSHariprasad Shenai 
2116688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2117688ea5feSHariprasad Shenai 
2118688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
2119688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
2120688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2121688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskFilter:    %3d\n", MASKFILTER_G(rssconf));
2122688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2123688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashAll:     %3s\n",
2124688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHALL_F));
2125688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashEth:     %3s\n",
2126688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHETH_F));
2127688ea5feSHariprasad Shenai 	}
2128688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2129688ea5feSHariprasad Shenai 
2130688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2131688ea5feSHariprasad Shenai 
2132688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
2133688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
2134688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2135688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplMapEn:    %3s\n", yesno(rssconf &
2136688ea5feSHariprasad Shenai 							RRCPLMAPEN_F));
2137688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
2138688ea5feSHariprasad Shenai 
2139688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2140688ea5feSHariprasad Shenai 
2141688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
2142688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
2143688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2144688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2145688ea5feSHariprasad Shenai 
2146688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2147688ea5feSHariprasad Shenai 
2148688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
2149688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
2150688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2151688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyWrAddrX:     %3d\n",
2152688ea5feSHariprasad Shenai 			   KEYWRADDRX_G(rssconf));
2153688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyExtend:      %3s\n",
2154688ea5feSHariprasad Shenai 			   yesno(rssconf & KEYEXTEND_F));
2155688ea5feSHariprasad Shenai 	}
2156688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdRg:        %3s\n", yesno(rssconf & VFRDRG_F));
2157688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdEn:        %3s\n", yesno(rssconf & VFRDEN_F));
2158688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfPerrEn:      %3s\n", yesno(rssconf & VFPERREN_F));
2159688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyPerrEn:     %3s\n", yesno(rssconf & KEYPERREN_F));
2160688ea5feSHariprasad Shenai 	seq_printf(seq, "  DisVfVlan:     %3s\n", yesno(rssconf &
2161688ea5feSHariprasad Shenai 							DISABLEVLAN_F));
2162688ea5feSHariprasad Shenai 	seq_printf(seq, "  EnUpSwt:       %3s\n", yesno(rssconf & ENABLEUP0_F));
2163688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashDelay:     %3d\n", HASHDELAY_G(rssconf));
2164688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
2165688ea5feSHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n", VFWRADDR_G(rssconf));
21663ccc6cf7SHariprasad Shenai 	else
21673ccc6cf7SHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n",
21683ccc6cf7SHariprasad Shenai 			   T6_VFWRADDR_G(rssconf));
2169688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyMode:       %s\n", keymode[KEYMODE_G(rssconf)]);
2170688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfWrEn:        %3s\n", yesno(rssconf & VFWREN_F));
2171688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrEn:       %3s\n", yesno(rssconf & KEYWREN_F));
2172688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrAddr:     %3d\n", KEYWRADDR_G(rssconf));
2173688ea5feSHariprasad Shenai 
2174688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2175688ea5feSHariprasad Shenai 
2176688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
2177688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
2178688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount3:     %3s\n", yesno(rssconf & CHNCOUNT3_F));
2179688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount2:     %3s\n", yesno(rssconf & CHNCOUNT2_F));
2180688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount1:     %3s\n", yesno(rssconf & CHNCOUNT1_F));
2181688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount0:     %3s\n", yesno(rssconf & CHNCOUNT0_F));
2182688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow3:   %3s\n", yesno(rssconf &
2183688ea5feSHariprasad Shenai 							CHNUNDFLOW3_F));
2184688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow2:   %3s\n", yesno(rssconf &
2185688ea5feSHariprasad Shenai 							CHNUNDFLOW2_F));
2186688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow1:   %3s\n", yesno(rssconf &
2187688ea5feSHariprasad Shenai 							CHNUNDFLOW1_F));
2188688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow0:   %3s\n", yesno(rssconf &
2189688ea5feSHariprasad Shenai 							CHNUNDFLOW0_F));
2190688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn3:       %3s\n", yesno(rssconf & RSTCHN3_F));
2191688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn2:       %3s\n", yesno(rssconf & RSTCHN2_F));
2192688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn1:       %3s\n", yesno(rssconf & RSTCHN1_F));
2193688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn0:       %3s\n", yesno(rssconf & RSTCHN0_F));
2194688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdVld:        %3s\n", yesno(rssconf & UPDVLD_F));
2195688ea5feSHariprasad Shenai 	seq_printf(seq, "  Xoff:          %3s\n", yesno(rssconf & XOFF_F));
2196688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn3:       %3s\n", yesno(rssconf & UPDCHN3_F));
2197688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn2:       %3s\n", yesno(rssconf & UPDCHN2_F));
2198688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn1:       %3s\n", yesno(rssconf & UPDCHN1_F));
2199688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn0:       %3s\n", yesno(rssconf & UPDCHN0_F));
2200688ea5feSHariprasad Shenai 	seq_printf(seq, "  Queue:         %3d\n", QUEUE_G(rssconf));
2201688ea5feSHariprasad Shenai 
2202688ea5feSHariprasad Shenai 	return 0;
2203688ea5feSHariprasad Shenai }
2204688ea5feSHariprasad Shenai 
2205688ea5feSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
2206688ea5feSHariprasad Shenai 
2207688ea5feSHariprasad Shenai /* RSS Secret Key.
2208688ea5feSHariprasad Shenai  */
2209688ea5feSHariprasad Shenai 
2210688ea5feSHariprasad Shenai static int rss_key_show(struct seq_file *seq, void *v)
2211688ea5feSHariprasad Shenai {
2212688ea5feSHariprasad Shenai 	u32 key[10];
2213688ea5feSHariprasad Shenai 
2214688ea5feSHariprasad Shenai 	t4_read_rss_key(seq->private, key);
2215688ea5feSHariprasad Shenai 	seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
2216688ea5feSHariprasad Shenai 		   key[9], key[8], key[7], key[6], key[5], key[4], key[3],
2217688ea5feSHariprasad Shenai 		   key[2], key[1], key[0]);
2218688ea5feSHariprasad Shenai 	return 0;
2219688ea5feSHariprasad Shenai }
2220688ea5feSHariprasad Shenai 
2221688ea5feSHariprasad Shenai static int rss_key_open(struct inode *inode, struct file *file)
2222688ea5feSHariprasad Shenai {
2223688ea5feSHariprasad Shenai 	return single_open(file, rss_key_show, inode->i_private);
2224688ea5feSHariprasad Shenai }
2225688ea5feSHariprasad Shenai 
2226688ea5feSHariprasad Shenai static ssize_t rss_key_write(struct file *file, const char __user *buf,
2227688ea5feSHariprasad Shenai 			     size_t count, loff_t *pos)
2228688ea5feSHariprasad Shenai {
2229688ea5feSHariprasad Shenai 	int i, j;
2230688ea5feSHariprasad Shenai 	u32 key[10];
2231688ea5feSHariprasad Shenai 	char s[100], *p;
2232c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
2233688ea5feSHariprasad Shenai 
2234688ea5feSHariprasad Shenai 	if (count > sizeof(s) - 1)
2235688ea5feSHariprasad Shenai 		return -EINVAL;
2236688ea5feSHariprasad Shenai 	if (copy_from_user(s, buf, count))
2237688ea5feSHariprasad Shenai 		return -EFAULT;
2238688ea5feSHariprasad Shenai 	for (i = count; i > 0 && isspace(s[i - 1]); i--)
2239688ea5feSHariprasad Shenai 		;
2240688ea5feSHariprasad Shenai 	s[i] = '\0';
2241688ea5feSHariprasad Shenai 
2242688ea5feSHariprasad Shenai 	for (p = s, i = 9; i >= 0; i--) {
2243688ea5feSHariprasad Shenai 		key[i] = 0;
2244688ea5feSHariprasad Shenai 		for (j = 0; j < 8; j++, p++) {
2245688ea5feSHariprasad Shenai 			if (!isxdigit(*p))
2246688ea5feSHariprasad Shenai 				return -EINVAL;
2247688ea5feSHariprasad Shenai 			key[i] = (key[i] << 4) | hex2val(*p);
2248688ea5feSHariprasad Shenai 		}
2249688ea5feSHariprasad Shenai 	}
2250688ea5feSHariprasad Shenai 
2251688ea5feSHariprasad Shenai 	t4_write_rss_key(adap, key, -1);
2252688ea5feSHariprasad Shenai 	return count;
2253688ea5feSHariprasad Shenai }
2254688ea5feSHariprasad Shenai 
2255688ea5feSHariprasad Shenai static const struct file_operations rss_key_debugfs_fops = {
2256688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2257688ea5feSHariprasad Shenai 	.open    = rss_key_open,
2258688ea5feSHariprasad Shenai 	.read    = seq_read,
2259688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2260688ea5feSHariprasad Shenai 	.release = single_release,
2261688ea5feSHariprasad Shenai 	.write   = rss_key_write
2262688ea5feSHariprasad Shenai };
2263688ea5feSHariprasad Shenai 
2264688ea5feSHariprasad Shenai /* PF RSS Configuration.
2265688ea5feSHariprasad Shenai  */
2266688ea5feSHariprasad Shenai 
2267688ea5feSHariprasad Shenai struct rss_pf_conf {
2268688ea5feSHariprasad Shenai 	u32 rss_pf_map;
2269688ea5feSHariprasad Shenai 	u32 rss_pf_mask;
2270688ea5feSHariprasad Shenai 	u32 rss_pf_config;
2271688ea5feSHariprasad Shenai };
2272688ea5feSHariprasad Shenai 
2273688ea5feSHariprasad Shenai static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
2274688ea5feSHariprasad Shenai {
2275688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2276688ea5feSHariprasad Shenai 
2277688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2278688ea5feSHariprasad Shenai 		/* use the 0th entry to dump the PF Map Index Size */
2279688ea5feSHariprasad Shenai 		pfconf = seq->private + offsetof(struct seq_tab, data);
2280688ea5feSHariprasad Shenai 		seq_printf(seq, "PF Map Index Size = %d\n\n",
2281688ea5feSHariprasad Shenai 			   LKPIDXSIZE_G(pfconf->rss_pf_map));
2282688ea5feSHariprasad Shenai 
2283688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS              PF   VF    Hash Tuple Enable         Default\n");
2284688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable       IPF Mask Mask  IPv6      IPv4      UDP   Queue\n");
2285688ea5feSHariprasad Shenai 		seq_puts(seq, " PF  Map Chn Prt  Map Size Size  Four Two  Four Two  Four  Ch1  Ch0\n");
2286688ea5feSHariprasad Shenai 	} else {
2287688ea5feSHariprasad Shenai 		#define G_PFnLKPIDX(map, n) \
2288688ea5feSHariprasad Shenai 			(((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
2289688ea5feSHariprasad Shenai 		#define G_PFnMSKSIZE(mask, n) \
2290688ea5feSHariprasad Shenai 			(((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
2291688ea5feSHariprasad Shenai 
2292688ea5feSHariprasad Shenai 		pfconf = v;
2293688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s %3s  %3d  %3d  %3d   %3s %3s   %3s %3s   %3s  %3d  %3d\n",
2294688ea5feSHariprasad Shenai 			   idx,
2295688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & MAPENABLE_F),
2296688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & CHNENABLE_F),
2297688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & PRTENABLE_F),
2298688ea5feSHariprasad Shenai 			   G_PFnLKPIDX(pfconf->rss_pf_map, idx),
2299688ea5feSHariprasad Shenai 			   G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
2300688ea5feSHariprasad Shenai 			   IVFWIDTH_G(pfconf->rss_pf_config),
2301688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
2302688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
2303688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
2304688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
2305688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
2306688ea5feSHariprasad Shenai 			   CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
2307688ea5feSHariprasad Shenai 			   CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
2308688ea5feSHariprasad Shenai 
2309688ea5feSHariprasad Shenai 		#undef G_PFnLKPIDX
2310688ea5feSHariprasad Shenai 		#undef G_PFnMSKSIZE
2311688ea5feSHariprasad Shenai 	}
2312688ea5feSHariprasad Shenai 	return 0;
2313688ea5feSHariprasad Shenai }
2314688ea5feSHariprasad Shenai 
2315688ea5feSHariprasad Shenai static int rss_pf_config_open(struct inode *inode, struct file *file)
2316688ea5feSHariprasad Shenai {
2317688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2318688ea5feSHariprasad Shenai 	struct seq_tab *p;
2319688ea5feSHariprasad Shenai 	u32 rss_pf_map, rss_pf_mask;
2320688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2321688ea5feSHariprasad Shenai 	int pf;
2322688ea5feSHariprasad Shenai 
2323688ea5feSHariprasad Shenai 	p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
2324688ea5feSHariprasad Shenai 	if (!p)
2325688ea5feSHariprasad Shenai 		return -ENOMEM;
2326688ea5feSHariprasad Shenai 
2327688ea5feSHariprasad Shenai 	pfconf = (struct rss_pf_conf *)p->data;
2328688ea5feSHariprasad Shenai 	rss_pf_map = t4_read_rss_pf_map(adapter);
2329688ea5feSHariprasad Shenai 	rss_pf_mask = t4_read_rss_pf_mask(adapter);
2330688ea5feSHariprasad Shenai 	for (pf = 0; pf < 8; pf++) {
2331688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_map = rss_pf_map;
2332688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_mask = rss_pf_mask;
2333688ea5feSHariprasad Shenai 		t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
2334688ea5feSHariprasad Shenai 	}
2335688ea5feSHariprasad Shenai 	return 0;
2336688ea5feSHariprasad Shenai }
2337688ea5feSHariprasad Shenai 
2338688ea5feSHariprasad Shenai static const struct file_operations rss_pf_config_debugfs_fops = {
2339688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2340688ea5feSHariprasad Shenai 	.open    = rss_pf_config_open,
2341688ea5feSHariprasad Shenai 	.read    = seq_read,
2342688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2343688ea5feSHariprasad Shenai 	.release = seq_release_private
2344688ea5feSHariprasad Shenai };
2345688ea5feSHariprasad Shenai 
2346688ea5feSHariprasad Shenai /* VF RSS Configuration.
2347688ea5feSHariprasad Shenai  */
2348688ea5feSHariprasad Shenai 
2349688ea5feSHariprasad Shenai struct rss_vf_conf {
2350688ea5feSHariprasad Shenai 	u32 rss_vf_vfl;
2351688ea5feSHariprasad Shenai 	u32 rss_vf_vfh;
2352688ea5feSHariprasad Shenai };
2353688ea5feSHariprasad Shenai 
2354688ea5feSHariprasad Shenai static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
2355688ea5feSHariprasad Shenai {
2356688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2357688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS                     Hash Tuple Enable\n");
2358688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable   IVF  Dis  Enb  IPv6      IPv4      UDP    Def  Secret Key\n");
2359688ea5feSHariprasad Shenai 		seq_puts(seq, " VF  Chn Prt  Map  VLAN  uP  Four Two  Four Two  Four   Que  Idx       Hash\n");
2360688ea5feSHariprasad Shenai 	} else {
2361688ea5feSHariprasad Shenai 		struct rss_vf_conf *vfconf = v;
2362688ea5feSHariprasad Shenai 
2363688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s  %3d   %3s %3s   %3s %3s   %3s  %3s   %3s  %4d  %3d %#10x\n",
2364688ea5feSHariprasad Shenai 			   idx,
2365688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
2366688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
2367688ea5feSHariprasad Shenai 			   VFLKPIDX_G(vfconf->rss_vf_vfh),
2368688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
2369688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFUPEN_F),
2370688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2371688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
2372688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2373688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
2374688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
2375688ea5feSHariprasad Shenai 			   DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
2376688ea5feSHariprasad Shenai 			   KEYINDEX_G(vfconf->rss_vf_vfh),
2377688ea5feSHariprasad Shenai 			   vfconf->rss_vf_vfl);
2378688ea5feSHariprasad Shenai 	}
2379688ea5feSHariprasad Shenai 	return 0;
2380688ea5feSHariprasad Shenai }
2381688ea5feSHariprasad Shenai 
2382688ea5feSHariprasad Shenai static int rss_vf_config_open(struct inode *inode, struct file *file)
2383688ea5feSHariprasad Shenai {
2384688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2385688ea5feSHariprasad Shenai 	struct seq_tab *p;
2386688ea5feSHariprasad Shenai 	struct rss_vf_conf *vfconf;
23873ccc6cf7SHariprasad Shenai 	int vf, vfcount = adapter->params.arch.vfcount;
2388688ea5feSHariprasad Shenai 
23893ccc6cf7SHariprasad Shenai 	p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
2390688ea5feSHariprasad Shenai 	if (!p)
2391688ea5feSHariprasad Shenai 		return -ENOMEM;
2392688ea5feSHariprasad Shenai 
2393688ea5feSHariprasad Shenai 	vfconf = (struct rss_vf_conf *)p->data;
23943ccc6cf7SHariprasad Shenai 	for (vf = 0; vf < vfcount; vf++) {
2395688ea5feSHariprasad Shenai 		t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
2396688ea5feSHariprasad Shenai 				      &vfconf[vf].rss_vf_vfh);
2397688ea5feSHariprasad Shenai 	}
2398688ea5feSHariprasad Shenai 	return 0;
2399688ea5feSHariprasad Shenai }
2400688ea5feSHariprasad Shenai 
2401688ea5feSHariprasad Shenai static const struct file_operations rss_vf_config_debugfs_fops = {
2402688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2403688ea5feSHariprasad Shenai 	.open    = rss_vf_config_open,
2404688ea5feSHariprasad Shenai 	.read    = seq_read,
2405688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2406688ea5feSHariprasad Shenai 	.release = seq_release_private
2407688ea5feSHariprasad Shenai };
2408688ea5feSHariprasad Shenai 
24093051fa61SHariprasad Shenai /**
24103051fa61SHariprasad Shenai  * ethqset2pinfo - return port_info of an Ethernet Queue Set
24113051fa61SHariprasad Shenai  * @adap: the adapter
24123051fa61SHariprasad Shenai  * @qset: Ethernet Queue Set
24133051fa61SHariprasad Shenai  */
24143051fa61SHariprasad Shenai static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
24153051fa61SHariprasad Shenai {
24163051fa61SHariprasad Shenai 	int pidx;
24173051fa61SHariprasad Shenai 
24183051fa61SHariprasad Shenai 	for_each_port(adap, pidx) {
24193051fa61SHariprasad Shenai 		struct port_info *pi = adap2pinfo(adap, pidx);
24203051fa61SHariprasad Shenai 
24213051fa61SHariprasad Shenai 		if (qset >= pi->first_qset &&
24223051fa61SHariprasad Shenai 		    qset < pi->first_qset + pi->nqsets)
24233051fa61SHariprasad Shenai 			return pi;
24243051fa61SHariprasad Shenai 	}
24253051fa61SHariprasad Shenai 
24263051fa61SHariprasad Shenai 	/* should never happen! */
24273051fa61SHariprasad Shenai 	BUG_ON(1);
24283051fa61SHariprasad Shenai 	return NULL;
24293051fa61SHariprasad Shenai }
24303051fa61SHariprasad Shenai 
2431dc9daab2SHariprasad Shenai static int sge_qinfo_show(struct seq_file *seq, void *v)
2432dc9daab2SHariprasad Shenai {
2433dc9daab2SHariprasad Shenai 	struct adapter *adap = seq->private;
2434dc9daab2SHariprasad Shenai 	int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
24350fbc81b3SHariprasad Shenai 	int ofld_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
2436dc9daab2SHariprasad Shenai 	int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
2437dc9daab2SHariprasad Shenai 	int i, r = (uintptr_t)v - 1;
24380fbc81b3SHariprasad Shenai 	int ofld_idx = r - eth_entries;
24390fbc81b3SHariprasad Shenai 	int ctrl_idx =  ofld_idx - ofld_entries;
2440dc9daab2SHariprasad Shenai 	int fq_idx =  ctrl_idx - ctrl_entries;
2441dc9daab2SHariprasad Shenai 
2442dc9daab2SHariprasad Shenai 	if (r)
2443dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n');
2444dc9daab2SHariprasad Shenai 
2445dc9daab2SHariprasad Shenai #define S3(fmt_spec, s, v) \
2446dc9daab2SHariprasad Shenai do { \
2447dc9daab2SHariprasad Shenai 	seq_printf(seq, "%-12s", s); \
2448dc9daab2SHariprasad Shenai 	for (i = 0; i < n; ++i) \
2449dc9daab2SHariprasad Shenai 		seq_printf(seq, " %16" fmt_spec, v); \
2450dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n'); \
2451dc9daab2SHariprasad Shenai } while (0)
2452dc9daab2SHariprasad Shenai #define S(s, v) S3("s", s, v)
2453e106a4d9SHariprasad Shenai #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
2454dc9daab2SHariprasad Shenai #define T(s, v) S3("u", s, tx[i].v)
2455e106a4d9SHariprasad Shenai #define TL(s, v) T3("lu", s, v)
2456e106a4d9SHariprasad Shenai #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
2457dc9daab2SHariprasad Shenai #define R(s, v) S3("u", s, rx[i].v)
2458e106a4d9SHariprasad Shenai #define RL(s, v) R3("lu", s, v)
2459dc9daab2SHariprasad Shenai 
2460dc9daab2SHariprasad Shenai 	if (r < eth_entries) {
2461dc9daab2SHariprasad Shenai 		int base_qset = r * 4;
2462dc9daab2SHariprasad Shenai 		const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
2463dc9daab2SHariprasad Shenai 		const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
2464dc9daab2SHariprasad Shenai 		int n = min(4, adap->sge.ethqsets - 4 * r);
2465dc9daab2SHariprasad Shenai 
2466dc9daab2SHariprasad Shenai 		S("QType:", "Ethernet");
2467dc9daab2SHariprasad Shenai 		S("Interface:",
2468dc9daab2SHariprasad Shenai 		  rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2469dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2470dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2471dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2472dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2473dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
24743051fa61SHariprasad Shenai #ifdef CONFIG_CHELSIO_T4_DCB
2475dc9daab2SHariprasad Shenai 		T("DCB Prio:", dcb_prio);
2476dc9daab2SHariprasad Shenai 		S3("u", "DCB PGID:",
2477dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
2478dc9daab2SHariprasad Shenai 		    4*(7-tx[i].dcb_prio)) & 0xf);
2479dc9daab2SHariprasad Shenai 		S3("u", "DCB PFC:",
2480dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
2481dc9daab2SHariprasad Shenai 		    1*(7-tx[i].dcb_prio)) & 0x1);
2482dc9daab2SHariprasad Shenai #endif
2483dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2484dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2485dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2486dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2487dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2488dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2489dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2490dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2491dc9daab2SHariprasad Shenai 		R("FL ID:", fl.cntxt_id);
2492dc9daab2SHariprasad Shenai 		R("FL size:", fl.size - 8);
2493dc9daab2SHariprasad Shenai 		R("FL pend:", fl.pend_cred);
2494dc9daab2SHariprasad Shenai 		R("FL avail:", fl.avail);
2495dc9daab2SHariprasad Shenai 		R("FL PIDX:", fl.pidx);
2496dc9daab2SHariprasad Shenai 		R("FL CIDX:", fl.cidx);
2497e106a4d9SHariprasad Shenai 		RL("RxPackets:", stats.pkts);
2498e106a4d9SHariprasad Shenai 		RL("RxCSO:", stats.rx_cso);
2499e106a4d9SHariprasad Shenai 		RL("VLANxtract:", stats.vlan_ex);
2500e106a4d9SHariprasad Shenai 		RL("LROmerged:", stats.lro_merged);
2501e106a4d9SHariprasad Shenai 		RL("LROpackets:", stats.lro_pkts);
2502e106a4d9SHariprasad Shenai 		RL("RxDrops:", stats.rx_drops);
2503e106a4d9SHariprasad Shenai 		TL("TSO:", tso);
2504e106a4d9SHariprasad Shenai 		TL("TxCSO:", tx_cso);
2505e106a4d9SHariprasad Shenai 		TL("VLANins:", vlan_ins);
2506e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2507e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2508e106a4d9SHariprasad Shenai 		TL("TxMapErr:", mapping_err);
2509e106a4d9SHariprasad Shenai 		RL("FLAllocErr:", fl.alloc_failed);
2510e106a4d9SHariprasad Shenai 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
251170055dd0SHariprasad Shenai 		RL("FLMapErr:", fl.mapping_err);
251270055dd0SHariprasad Shenai 		RL("FLLow:", fl.low);
2513e106a4d9SHariprasad Shenai 		RL("FLStarving:", fl.starving);
2514dc9daab2SHariprasad Shenai 
2515dc9daab2SHariprasad Shenai 	} else if (ctrl_idx < ctrl_entries) {
2516dc9daab2SHariprasad Shenai 		const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
2517dc9daab2SHariprasad Shenai 		int n = min(4, adap->params.nports - 4 * ctrl_idx);
2518dc9daab2SHariprasad Shenai 
2519dc9daab2SHariprasad Shenai 		S("QType:", "Control");
2520dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2521dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2522dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2523dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2524dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
2525e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2526e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2527dc9daab2SHariprasad Shenai 	} else if (fq_idx == 0) {
2528dc9daab2SHariprasad Shenai 		const struct sge_rspq *evtq = &adap->sge.fw_evtq;
2529dc9daab2SHariprasad Shenai 
2530dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
2531dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
2532dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
2533dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
2534dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
2535dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
2536dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr delay:",
2537dc9daab2SHariprasad Shenai 			   qtimer_val(adap, evtq));
2538dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
2539dc9daab2SHariprasad Shenai 			   adap->sge.counter_val[evtq->pktcnt_idx]);
2540dc9daab2SHariprasad Shenai 	}
2541dc9daab2SHariprasad Shenai #undef R
2542e106a4d9SHariprasad Shenai #undef RL
2543dc9daab2SHariprasad Shenai #undef T
2544e106a4d9SHariprasad Shenai #undef TL
2545dc9daab2SHariprasad Shenai #undef S
2546e106a4d9SHariprasad Shenai #undef R3
2547e106a4d9SHariprasad Shenai #undef T3
2548dc9daab2SHariprasad Shenai #undef S3
2549dc9daab2SHariprasad Shenai 	return 0;
2550dc9daab2SHariprasad Shenai }
2551dc9daab2SHariprasad Shenai 
2552dc9daab2SHariprasad Shenai static int sge_queue_entries(const struct adapter *adap)
2553dc9daab2SHariprasad Shenai {
2554dc9daab2SHariprasad Shenai 	return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
25550fbc81b3SHariprasad Shenai 	       DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
2556dc9daab2SHariprasad Shenai 	       DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
2557dc9daab2SHariprasad Shenai }
2558dc9daab2SHariprasad Shenai 
2559dc9daab2SHariprasad Shenai static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
2560dc9daab2SHariprasad Shenai {
2561dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2562dc9daab2SHariprasad Shenai 
2563dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2564dc9daab2SHariprasad Shenai }
2565dc9daab2SHariprasad Shenai 
2566dc9daab2SHariprasad Shenai static void sge_queue_stop(struct seq_file *seq, void *v)
2567dc9daab2SHariprasad Shenai {
2568dc9daab2SHariprasad Shenai }
2569dc9daab2SHariprasad Shenai 
2570dc9daab2SHariprasad Shenai static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
2571dc9daab2SHariprasad Shenai {
2572dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2573dc9daab2SHariprasad Shenai 
2574dc9daab2SHariprasad Shenai 	++*pos;
2575dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2576dc9daab2SHariprasad Shenai }
2577dc9daab2SHariprasad Shenai 
2578dc9daab2SHariprasad Shenai static const struct seq_operations sge_qinfo_seq_ops = {
2579dc9daab2SHariprasad Shenai 	.start = sge_queue_start,
2580dc9daab2SHariprasad Shenai 	.next  = sge_queue_next,
2581dc9daab2SHariprasad Shenai 	.stop  = sge_queue_stop,
2582dc9daab2SHariprasad Shenai 	.show  = sge_qinfo_show
2583dc9daab2SHariprasad Shenai };
2584dc9daab2SHariprasad Shenai 
2585dc9daab2SHariprasad Shenai static int sge_qinfo_open(struct inode *inode, struct file *file)
2586dc9daab2SHariprasad Shenai {
2587dc9daab2SHariprasad Shenai 	int res = seq_open(file, &sge_qinfo_seq_ops);
2588dc9daab2SHariprasad Shenai 
2589dc9daab2SHariprasad Shenai 	if (!res) {
2590dc9daab2SHariprasad Shenai 		struct seq_file *seq = file->private_data;
2591dc9daab2SHariprasad Shenai 
2592dc9daab2SHariprasad Shenai 		seq->private = inode->i_private;
2593dc9daab2SHariprasad Shenai 	}
2594dc9daab2SHariprasad Shenai 	return res;
2595dc9daab2SHariprasad Shenai }
2596dc9daab2SHariprasad Shenai 
2597dc9daab2SHariprasad Shenai static const struct file_operations sge_qinfo_debugfs_fops = {
2598dc9daab2SHariprasad Shenai 	.owner   = THIS_MODULE,
2599dc9daab2SHariprasad Shenai 	.open    = sge_qinfo_open,
2600dc9daab2SHariprasad Shenai 	.read    = seq_read,
2601dc9daab2SHariprasad Shenai 	.llseek  = seq_lseek,
2602dc9daab2SHariprasad Shenai 	.release = seq_release,
2603dc9daab2SHariprasad Shenai };
2604dc9daab2SHariprasad Shenai 
260549216c1cSHariprasad Shenai int mem_open(struct inode *inode, struct file *file)
260649216c1cSHariprasad Shenai {
260749216c1cSHariprasad Shenai 	unsigned int mem;
260849216c1cSHariprasad Shenai 	struct adapter *adap;
260949216c1cSHariprasad Shenai 
261049216c1cSHariprasad Shenai 	file->private_data = inode->i_private;
261149216c1cSHariprasad Shenai 
261249216c1cSHariprasad Shenai 	mem = (uintptr_t)file->private_data & 0x3;
261349216c1cSHariprasad Shenai 	adap = file->private_data - mem;
261449216c1cSHariprasad Shenai 
261549216c1cSHariprasad Shenai 	(void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
261649216c1cSHariprasad Shenai 
261749216c1cSHariprasad Shenai 	return 0;
261849216c1cSHariprasad Shenai }
261949216c1cSHariprasad Shenai 
2620fd88b31aSHariprasad Shenai static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2621fd88b31aSHariprasad Shenai 			loff_t *ppos)
2622fd88b31aSHariprasad Shenai {
2623fd88b31aSHariprasad Shenai 	loff_t pos = *ppos;
2624fd88b31aSHariprasad Shenai 	loff_t avail = file_inode(file)->i_size;
2625fd88b31aSHariprasad Shenai 	unsigned int mem = (uintptr_t)file->private_data & 3;
2626fd88b31aSHariprasad Shenai 	struct adapter *adap = file->private_data - mem;
2627fd88b31aSHariprasad Shenai 	__be32 *data;
2628fd88b31aSHariprasad Shenai 	int ret;
2629fd88b31aSHariprasad Shenai 
2630fd88b31aSHariprasad Shenai 	if (pos < 0)
2631fd88b31aSHariprasad Shenai 		return -EINVAL;
2632fd88b31aSHariprasad Shenai 	if (pos >= avail)
2633fd88b31aSHariprasad Shenai 		return 0;
2634fd88b31aSHariprasad Shenai 	if (count > avail - pos)
2635fd88b31aSHariprasad Shenai 		count = avail - pos;
2636fd88b31aSHariprasad Shenai 
2637752ade68SMichal Hocko 	data = kvzalloc(count, GFP_KERNEL);
2638fd88b31aSHariprasad Shenai 	if (!data)
2639fd88b31aSHariprasad Shenai 		return -ENOMEM;
2640fd88b31aSHariprasad Shenai 
2641fd88b31aSHariprasad Shenai 	spin_lock(&adap->win0_lock);
2642fd88b31aSHariprasad Shenai 	ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
2643fd88b31aSHariprasad Shenai 	spin_unlock(&adap->win0_lock);
2644fd88b31aSHariprasad Shenai 	if (ret) {
2645752ade68SMichal Hocko 		kvfree(data);
2646fd88b31aSHariprasad Shenai 		return ret;
2647fd88b31aSHariprasad Shenai 	}
2648fd88b31aSHariprasad Shenai 	ret = copy_to_user(buf, data, count);
2649fd88b31aSHariprasad Shenai 
2650752ade68SMichal Hocko 	kvfree(data);
2651fd88b31aSHariprasad Shenai 	if (ret)
2652fd88b31aSHariprasad Shenai 		return -EFAULT;
2653fd88b31aSHariprasad Shenai 
2654fd88b31aSHariprasad Shenai 	*ppos = pos + count;
2655fd88b31aSHariprasad Shenai 	return count;
2656fd88b31aSHariprasad Shenai }
2657fd88b31aSHariprasad Shenai static const struct file_operations mem_debugfs_fops = {
2658fd88b31aSHariprasad Shenai 	.owner   = THIS_MODULE,
2659fd88b31aSHariprasad Shenai 	.open    = simple_open,
2660fd88b31aSHariprasad Shenai 	.read    = mem_read,
2661fd88b31aSHariprasad Shenai 	.llseek  = default_llseek,
2662fd88b31aSHariprasad Shenai };
2663fd88b31aSHariprasad Shenai 
2664a4011fd4SHariprasad Shenai static int tid_info_show(struct seq_file *seq, void *v)
2665a4011fd4SHariprasad Shenai {
2666a4011fd4SHariprasad Shenai 	struct adapter *adap = seq->private;
2667a4011fd4SHariprasad Shenai 	const struct tid_info *t = &adap->tids;
2668a4011fd4SHariprasad Shenai 	enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
2669a4011fd4SHariprasad Shenai 
2670a4011fd4SHariprasad Shenai 	if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
2671a4011fd4SHariprasad Shenai 		unsigned int sb;
2672a4011fd4SHariprasad Shenai 
2673a4011fd4SHariprasad Shenai 		if (chip <= CHELSIO_T5)
2674a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
2675a4011fd4SHariprasad Shenai 		else
2676a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
2677a4011fd4SHariprasad Shenai 
2678a4011fd4SHariprasad Shenai 		if (sb) {
2679a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: 0..%u/%u..%u", sb - 1,
2680a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2681a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2682a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2683a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2684a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2685a4011fd4SHariprasad Shenai 		} else if (adap->flags & FW_OFLD_CONN) {
2686a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u/%u..%u",
2687a4011fd4SHariprasad Shenai 				   t->aftid_base,
2688a4011fd4SHariprasad Shenai 				   t->aftid_end,
2689a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2690a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2691a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2692a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2693a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2694a4011fd4SHariprasad Shenai 		} else {
2695a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u",
2696a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2697a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2698a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u\n",
2699a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2700a4011fd4SHariprasad Shenai 		}
2701a4011fd4SHariprasad Shenai 	} else if (t->ntids) {
2702a4011fd4SHariprasad Shenai 		seq_printf(seq, "TID range: 0..%u", t->ntids - 1);
2703a4011fd4SHariprasad Shenai 		seq_printf(seq, ", in use: %u\n",
2704a4011fd4SHariprasad Shenai 			   atomic_read(&t->tids_in_use));
2705a4011fd4SHariprasad Shenai 	}
2706a4011fd4SHariprasad Shenai 
2707a4011fd4SHariprasad Shenai 	if (t->nstids)
2708a4011fd4SHariprasad Shenai 		seq_printf(seq, "STID range: %u..%u, in use: %u\n",
2709a4011fd4SHariprasad Shenai 			   (!t->stid_base &&
2710a4011fd4SHariprasad Shenai 			   (chip <= CHELSIO_T5)) ?
2711a4011fd4SHariprasad Shenai 			   t->stid_base + 1 : t->stid_base,
2712a4011fd4SHariprasad Shenai 			   t->stid_base + t->nstids - 1, t->stids_in_use);
2713a4011fd4SHariprasad Shenai 	if (t->natids)
2714a4011fd4SHariprasad Shenai 		seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
2715a4011fd4SHariprasad Shenai 			   t->natids - 1, t->atids_in_use);
2716a4011fd4SHariprasad Shenai 	seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
2717a4011fd4SHariprasad Shenai 		   t->ftid_base + t->nftids - 1);
2718a4011fd4SHariprasad Shenai 	if (t->nsftids)
2719a4011fd4SHariprasad Shenai 		seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
2720a4011fd4SHariprasad Shenai 			   t->sftid_base, t->sftid_base + t->nsftids - 2,
2721a4011fd4SHariprasad Shenai 			   t->sftids_in_use);
2722a4011fd4SHariprasad Shenai 	if (t->ntids)
2723a4011fd4SHariprasad Shenai 		seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
2724a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
2725a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
2726a4011fd4SHariprasad Shenai 	return 0;
2727a4011fd4SHariprasad Shenai }
2728a4011fd4SHariprasad Shenai 
2729a4011fd4SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(tid_info);
2730a4011fd4SHariprasad Shenai 
2731fd88b31aSHariprasad Shenai static void add_debugfs_mem(struct adapter *adap, const char *name,
2732fd88b31aSHariprasad Shenai 			    unsigned int idx, unsigned int size_mb)
2733fd88b31aSHariprasad Shenai {
2734e59b4e91SDavid Howells 	debugfs_create_file_size(name, S_IRUSR, adap->debugfs_root,
2735e59b4e91SDavid Howells 				 (void *)adap + idx, &mem_debugfs_fops,
2736e59b4e91SDavid Howells 				 size_mb << 20);
2737fd88b31aSHariprasad Shenai }
2738fd88b31aSHariprasad Shenai 
27395b377d11SHariprasad Shenai static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
27405b377d11SHariprasad Shenai 			       size_t count, loff_t *ppos)
27415b377d11SHariprasad Shenai {
27425b377d11SHariprasad Shenai 	int len;
27435b377d11SHariprasad Shenai 	const struct adapter *adap = filp->private_data;
27445b377d11SHariprasad Shenai 	char *buf;
27455b377d11SHariprasad Shenai 	ssize_t size = (adap->sge.egr_sz + 3) / 4 +
27465b377d11SHariprasad Shenai 			adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
27475b377d11SHariprasad Shenai 
27485b377d11SHariprasad Shenai 	buf = kzalloc(size, GFP_KERNEL);
27495b377d11SHariprasad Shenai 	if (!buf)
27505b377d11SHariprasad Shenai 		return -ENOMEM;
27515b377d11SHariprasad Shenai 
27525b377d11SHariprasad Shenai 	len = snprintf(buf, size - 1, "%*pb\n",
27535b377d11SHariprasad Shenai 		       adap->sge.egr_sz, adap->sge.blocked_fl);
27545b377d11SHariprasad Shenai 	len += sprintf(buf + len, "\n");
27555b377d11SHariprasad Shenai 	size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
2756752ade68SMichal Hocko 	kvfree(buf);
27575b377d11SHariprasad Shenai 	return size;
27585b377d11SHariprasad Shenai }
27595b377d11SHariprasad Shenai 
27605b377d11SHariprasad Shenai static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
27615b377d11SHariprasad Shenai 				size_t count, loff_t *ppos)
27625b377d11SHariprasad Shenai {
27635b377d11SHariprasad Shenai 	int err;
27645b377d11SHariprasad Shenai 	unsigned long *t;
27655b377d11SHariprasad Shenai 	struct adapter *adap = filp->private_data;
27665b377d11SHariprasad Shenai 
27675b377d11SHariprasad Shenai 	t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
27685b377d11SHariprasad Shenai 	if (!t)
27695b377d11SHariprasad Shenai 		return -ENOMEM;
27705b377d11SHariprasad Shenai 
27715b377d11SHariprasad Shenai 	err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
27725b377d11SHariprasad Shenai 	if (err)
27735b377d11SHariprasad Shenai 		return err;
27745b377d11SHariprasad Shenai 
27755b377d11SHariprasad Shenai 	bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
2776752ade68SMichal Hocko 	kvfree(t);
27775b377d11SHariprasad Shenai 	return count;
27785b377d11SHariprasad Shenai }
27795b377d11SHariprasad Shenai 
27805b377d11SHariprasad Shenai static const struct file_operations blocked_fl_fops = {
27815b377d11SHariprasad Shenai 	.owner   = THIS_MODULE,
2782524605e5SWei Yongjun 	.open    = simple_open,
27835b377d11SHariprasad Shenai 	.read    = blocked_fl_read,
27845b377d11SHariprasad Shenai 	.write   = blocked_fl_write,
27855b377d11SHariprasad Shenai 	.llseek  = generic_file_llseek,
27865b377d11SHariprasad Shenai };
27875b377d11SHariprasad Shenai 
27885888111cSHariprasad Shenai struct mem_desc {
27895888111cSHariprasad Shenai 	unsigned int base;
27905888111cSHariprasad Shenai 	unsigned int limit;
27915888111cSHariprasad Shenai 	unsigned int idx;
27925888111cSHariprasad Shenai };
27935888111cSHariprasad Shenai 
27945888111cSHariprasad Shenai static int mem_desc_cmp(const void *a, const void *b)
27955888111cSHariprasad Shenai {
27965888111cSHariprasad Shenai 	return ((const struct mem_desc *)a)->base -
27975888111cSHariprasad Shenai 	       ((const struct mem_desc *)b)->base;
27985888111cSHariprasad Shenai }
27995888111cSHariprasad Shenai 
28005888111cSHariprasad Shenai static void mem_region_show(struct seq_file *seq, const char *name,
28015888111cSHariprasad Shenai 			    unsigned int from, unsigned int to)
28025888111cSHariprasad Shenai {
28035888111cSHariprasad Shenai 	char buf[40];
28045888111cSHariprasad Shenai 
28055888111cSHariprasad Shenai 	string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
28065888111cSHariprasad Shenai 			sizeof(buf));
28075888111cSHariprasad Shenai 	seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
28085888111cSHariprasad Shenai }
28095888111cSHariprasad Shenai 
28105888111cSHariprasad Shenai static int meminfo_show(struct seq_file *seq, void *v)
28115888111cSHariprasad Shenai {
28125888111cSHariprasad Shenai 	static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
28135888111cSHariprasad Shenai 					"MC0:", "MC1:"};
28145888111cSHariprasad Shenai 	static const char * const region[] = {
28155888111cSHariprasad Shenai 		"DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
28165888111cSHariprasad Shenai 		"Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
28175888111cSHariprasad Shenai 		"Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
28185888111cSHariprasad Shenai 		"TDDP region:", "TPT region:", "STAG region:", "RQ region:",
28195888111cSHariprasad Shenai 		"RQUDP region:", "PBL region:", "TXPBL region:",
28205888111cSHariprasad Shenai 		"DBVFIFO region:", "ULPRX state:", "ULPTX state:",
28215888111cSHariprasad Shenai 		"On-chip queues:"
28225888111cSHariprasad Shenai 	};
28235888111cSHariprasad Shenai 
28245888111cSHariprasad Shenai 	int i, n;
28255888111cSHariprasad Shenai 	u32 lo, hi, used, alloc;
28265888111cSHariprasad Shenai 	struct mem_desc avail[4];
28275888111cSHariprasad Shenai 	struct mem_desc mem[ARRAY_SIZE(region) + 3];      /* up to 3 holes */
28285888111cSHariprasad Shenai 	struct mem_desc *md = mem;
28295888111cSHariprasad Shenai 	struct adapter *adap = seq->private;
28305888111cSHariprasad Shenai 
28315888111cSHariprasad Shenai 	for (i = 0; i < ARRAY_SIZE(mem); i++) {
28325888111cSHariprasad Shenai 		mem[i].limit = 0;
28335888111cSHariprasad Shenai 		mem[i].idx = i;
28345888111cSHariprasad Shenai 	}
28355888111cSHariprasad Shenai 
28365888111cSHariprasad Shenai 	/* Find and sort the populated memory ranges */
28375888111cSHariprasad Shenai 	i = 0;
28385888111cSHariprasad Shenai 	lo = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
28395888111cSHariprasad Shenai 	if (lo & EDRAM0_ENABLE_F) {
28405888111cSHariprasad Shenai 		hi = t4_read_reg(adap, MA_EDRAM0_BAR_A);
28415888111cSHariprasad Shenai 		avail[i].base = EDRAM0_BASE_G(hi) << 20;
28425888111cSHariprasad Shenai 		avail[i].limit = avail[i].base + (EDRAM0_SIZE_G(hi) << 20);
28435888111cSHariprasad Shenai 		avail[i].idx = 0;
28445888111cSHariprasad Shenai 		i++;
28455888111cSHariprasad Shenai 	}
28465888111cSHariprasad Shenai 	if (lo & EDRAM1_ENABLE_F) {
28475888111cSHariprasad Shenai 		hi = t4_read_reg(adap, MA_EDRAM1_BAR_A);
28485888111cSHariprasad Shenai 		avail[i].base = EDRAM1_BASE_G(hi) << 20;
28495888111cSHariprasad Shenai 		avail[i].limit = avail[i].base + (EDRAM1_SIZE_G(hi) << 20);
28505888111cSHariprasad Shenai 		avail[i].idx = 1;
28515888111cSHariprasad Shenai 		i++;
28525888111cSHariprasad Shenai 	}
28535888111cSHariprasad Shenai 
28545888111cSHariprasad Shenai 	if (is_t5(adap->params.chip)) {
28555888111cSHariprasad Shenai 		if (lo & EXT_MEM0_ENABLE_F) {
28565888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
28575888111cSHariprasad Shenai 			avail[i].base = EXT_MEM0_BASE_G(hi) << 20;
28585888111cSHariprasad Shenai 			avail[i].limit =
28595888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM0_SIZE_G(hi) << 20);
28605888111cSHariprasad Shenai 			avail[i].idx = 3;
28615888111cSHariprasad Shenai 			i++;
28625888111cSHariprasad Shenai 		}
28635888111cSHariprasad Shenai 		if (lo & EXT_MEM1_ENABLE_F) {
28645888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
28655888111cSHariprasad Shenai 			avail[i].base = EXT_MEM1_BASE_G(hi) << 20;
28665888111cSHariprasad Shenai 			avail[i].limit =
28675888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM1_SIZE_G(hi) << 20);
28685888111cSHariprasad Shenai 			avail[i].idx = 4;
28695888111cSHariprasad Shenai 			i++;
28705888111cSHariprasad Shenai 		}
28715888111cSHariprasad Shenai 	} else {
28725888111cSHariprasad Shenai 		if (lo & EXT_MEM_ENABLE_F) {
28735888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
28745888111cSHariprasad Shenai 			avail[i].base = EXT_MEM_BASE_G(hi) << 20;
28755888111cSHariprasad Shenai 			avail[i].limit =
28765888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM_SIZE_G(hi) << 20);
28775888111cSHariprasad Shenai 			avail[i].idx = 2;
28785888111cSHariprasad Shenai 			i++;
28795888111cSHariprasad Shenai 		}
28805888111cSHariprasad Shenai 	}
28815888111cSHariprasad Shenai 	if (!i)                                    /* no memory available */
28825888111cSHariprasad Shenai 		return 0;
28835888111cSHariprasad Shenai 	sort(avail, i, sizeof(struct mem_desc), mem_desc_cmp, NULL);
28845888111cSHariprasad Shenai 
28855888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A);
28865888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_IMSG_CTXT_BADDR_A);
28875888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_FLM_CACHE_BADDR_A);
28885888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_TCB_BASE_A);
28895888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_BASE_A);
28905888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_TIMER_BASE_A);
28915888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_RX_FLST_BASE_A);
28925888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_TX_FLST_BASE_A);
28935888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_PS_FLST_BASE_A);
28945888111cSHariprasad Shenai 
28955888111cSHariprasad Shenai 	/* the next few have explicit upper bounds */
28965888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, TP_PMM_TX_BASE_A);
28975888111cSHariprasad Shenai 	md->limit = md->base - 1 +
28985888111cSHariprasad Shenai 		    t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A) *
28995888111cSHariprasad Shenai 		    PMTXMAXPAGE_G(t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A));
29005888111cSHariprasad Shenai 	md++;
29015888111cSHariprasad Shenai 
29025888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, TP_PMM_RX_BASE_A);
29035888111cSHariprasad Shenai 	md->limit = md->base - 1 +
29045888111cSHariprasad Shenai 		    t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) *
29055888111cSHariprasad Shenai 		    PMRXMAXPAGE_G(t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A));
29065888111cSHariprasad Shenai 	md++;
29075888111cSHariprasad Shenai 
29085888111cSHariprasad Shenai 	if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
29095888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5) {
29105888111cSHariprasad Shenai 			hi = t4_read_reg(adap, LE_DB_TID_HASHBASE_A) / 4;
29115888111cSHariprasad Shenai 			md->base = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
29125888111cSHariprasad Shenai 		 } else {
29135888111cSHariprasad Shenai 			hi = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
29145888111cSHariprasad Shenai 			md->base = t4_read_reg(adap,
29155888111cSHariprasad Shenai 					       LE_DB_HASH_TBL_BASE_ADDR_A);
29165888111cSHariprasad Shenai 		}
29175888111cSHariprasad Shenai 		md->limit = 0;
29185888111cSHariprasad Shenai 	} else {
29195888111cSHariprasad Shenai 		md->base = 0;
29205888111cSHariprasad Shenai 		md->idx = ARRAY_SIZE(region);  /* hide it */
29215888111cSHariprasad Shenai 	}
29225888111cSHariprasad Shenai 	md++;
29235888111cSHariprasad Shenai 
29245888111cSHariprasad Shenai #define ulp_region(reg) do { \
29255888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_ ## reg ## _LLIMIT_A);\
29265888111cSHariprasad Shenai 	(md++)->limit = t4_read_reg(adap, ULP_ ## reg ## _ULIMIT_A); \
29275888111cSHariprasad Shenai } while (0)
29285888111cSHariprasad Shenai 
29295888111cSHariprasad Shenai 	ulp_region(RX_ISCSI);
29305888111cSHariprasad Shenai 	ulp_region(RX_TDDP);
29315888111cSHariprasad Shenai 	ulp_region(TX_TPT);
29325888111cSHariprasad Shenai 	ulp_region(RX_STAG);
29335888111cSHariprasad Shenai 	ulp_region(RX_RQ);
29345888111cSHariprasad Shenai 	ulp_region(RX_RQUDP);
29355888111cSHariprasad Shenai 	ulp_region(RX_PBL);
29365888111cSHariprasad Shenai 	ulp_region(TX_PBL);
29375888111cSHariprasad Shenai #undef ulp_region
29385888111cSHariprasad Shenai 	md->base = 0;
29395888111cSHariprasad Shenai 	md->idx = ARRAY_SIZE(region);
29405888111cSHariprasad Shenai 	if (!is_t4(adap->params.chip)) {
29415888111cSHariprasad Shenai 		u32 size = 0;
29425888111cSHariprasad Shenai 		u32 sge_ctrl = t4_read_reg(adap, SGE_CONTROL2_A);
29435888111cSHariprasad Shenai 		u32 fifo_size = t4_read_reg(adap, SGE_DBVFIFO_SIZE_A);
29445888111cSHariprasad Shenai 
29455888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
29465888111cSHariprasad Shenai 			if (sge_ctrl & VFIFO_ENABLE_F)
29475888111cSHariprasad Shenai 				size = DBVFIFO_SIZE_G(fifo_size);
29485888111cSHariprasad Shenai 		} else {
29495888111cSHariprasad Shenai 			size = T6_DBVFIFO_SIZE_G(fifo_size);
29505888111cSHariprasad Shenai 		}
29515888111cSHariprasad Shenai 
29525888111cSHariprasad Shenai 		if (size) {
29535888111cSHariprasad Shenai 			md->base = BASEADDR_G(t4_read_reg(adap,
29545888111cSHariprasad Shenai 					SGE_DBVFIFO_BADDR_A));
29555888111cSHariprasad Shenai 			md->limit = md->base + (size << 2) - 1;
29565888111cSHariprasad Shenai 		}
29575888111cSHariprasad Shenai 	}
29585888111cSHariprasad Shenai 
29595888111cSHariprasad Shenai 	md++;
29605888111cSHariprasad Shenai 
29615888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_RX_CTX_BASE_A);
29625888111cSHariprasad Shenai 	md->limit = 0;
29635888111cSHariprasad Shenai 	md++;
29645888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_TX_ERR_TABLE_BASE_A);
29655888111cSHariprasad Shenai 	md->limit = 0;
29665888111cSHariprasad Shenai 	md++;
29675888111cSHariprasad Shenai 
29685888111cSHariprasad Shenai 	md->base = adap->vres.ocq.start;
29695888111cSHariprasad Shenai 	if (adap->vres.ocq.size)
29705888111cSHariprasad Shenai 		md->limit = md->base + adap->vres.ocq.size - 1;
29715888111cSHariprasad Shenai 	else
29725888111cSHariprasad Shenai 		md->idx = ARRAY_SIZE(region);  /* hide it */
29735888111cSHariprasad Shenai 	md++;
29745888111cSHariprasad Shenai 
29755888111cSHariprasad Shenai 	/* add any address-space holes, there can be up to 3 */
29765888111cSHariprasad Shenai 	for (n = 0; n < i - 1; n++)
29775888111cSHariprasad Shenai 		if (avail[n].limit < avail[n + 1].base)
29785888111cSHariprasad Shenai 			(md++)->base = avail[n].limit;
29795888111cSHariprasad Shenai 	if (avail[n].limit)
29805888111cSHariprasad Shenai 		(md++)->base = avail[n].limit;
29815888111cSHariprasad Shenai 
29825888111cSHariprasad Shenai 	n = md - mem;
29835888111cSHariprasad Shenai 	sort(mem, n, sizeof(struct mem_desc), mem_desc_cmp, NULL);
29845888111cSHariprasad Shenai 
29855888111cSHariprasad Shenai 	for (lo = 0; lo < i; lo++)
29865888111cSHariprasad Shenai 		mem_region_show(seq, memory[avail[lo].idx], avail[lo].base,
29875888111cSHariprasad Shenai 				avail[lo].limit - 1);
29885888111cSHariprasad Shenai 
29895888111cSHariprasad Shenai 	seq_putc(seq, '\n');
29905888111cSHariprasad Shenai 	for (i = 0; i < n; i++) {
29915888111cSHariprasad Shenai 		if (mem[i].idx >= ARRAY_SIZE(region))
29925888111cSHariprasad Shenai 			continue;                        /* skip holes */
29935888111cSHariprasad Shenai 		if (!mem[i].limit)
29945888111cSHariprasad Shenai 			mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
29955888111cSHariprasad Shenai 		mem_region_show(seq, region[mem[i].idx], mem[i].base,
29965888111cSHariprasad Shenai 				mem[i].limit);
29975888111cSHariprasad Shenai 	}
29985888111cSHariprasad Shenai 
29995888111cSHariprasad Shenai 	seq_putc(seq, '\n');
30005888111cSHariprasad Shenai 	lo = t4_read_reg(adap, CIM_SDRAM_BASE_ADDR_A);
30015888111cSHariprasad Shenai 	hi = t4_read_reg(adap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
30025888111cSHariprasad Shenai 	mem_region_show(seq, "uP RAM:", lo, hi);
30035888111cSHariprasad Shenai 
30045888111cSHariprasad Shenai 	lo = t4_read_reg(adap, CIM_EXTMEM2_BASE_ADDR_A);
30055888111cSHariprasad Shenai 	hi = t4_read_reg(adap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
30065888111cSHariprasad Shenai 	mem_region_show(seq, "uP Extmem2:", lo, hi);
30075888111cSHariprasad Shenai 
30085888111cSHariprasad Shenai 	lo = t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A);
30095888111cSHariprasad Shenai 	seq_printf(seq, "\n%u Rx pages of size %uKiB for %u channels\n",
30105888111cSHariprasad Shenai 		   PMRXMAXPAGE_G(lo),
30115888111cSHariprasad Shenai 		   t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) >> 10,
30125888111cSHariprasad Shenai 		   (lo & PMRXNUMCHN_F) ? 2 : 1);
30135888111cSHariprasad Shenai 
30145888111cSHariprasad Shenai 	lo = t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A);
30155888111cSHariprasad Shenai 	hi = t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A);
30165888111cSHariprasad Shenai 	seq_printf(seq, "%u Tx pages of size %u%ciB for %u channels\n",
30175888111cSHariprasad Shenai 		   PMTXMAXPAGE_G(lo),
30185888111cSHariprasad Shenai 		   hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
30195888111cSHariprasad Shenai 		   hi >= (1 << 20) ? 'M' : 'K', 1 << PMTXNUMCHN_G(lo));
30205888111cSHariprasad Shenai 	seq_printf(seq, "%u p-structs\n\n",
30215888111cSHariprasad Shenai 		   t4_read_reg(adap, TP_CMM_MM_MAX_PSTRUCT_A));
30225888111cSHariprasad Shenai 
30235888111cSHariprasad Shenai 	for (i = 0; i < 4; i++) {
30245888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
30255888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
30265888111cSHariprasad Shenai 		else
30275888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_PG_RSV0_A + i * 4);
30285888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
30295888111cSHariprasad Shenai 			used = T5_USED_G(lo);
30305888111cSHariprasad Shenai 			alloc = T5_ALLOC_G(lo);
30315888111cSHariprasad Shenai 		} else {
30325888111cSHariprasad Shenai 			used = USED_G(lo);
30335888111cSHariprasad Shenai 			alloc = ALLOC_G(lo);
30345888111cSHariprasad Shenai 		}
30355888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
30365888111cSHariprasad Shenai 		seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
30375888111cSHariprasad Shenai 			   i, used, alloc);
30385888111cSHariprasad Shenai 	}
30395888111cSHariprasad Shenai 	for (i = 0; i < adap->params.arch.nchan; i++) {
30405888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
30415888111cSHariprasad Shenai 			lo = t4_read_reg(adap,
30425888111cSHariprasad Shenai 					 MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
30435888111cSHariprasad Shenai 		else
30445888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_PG_RSV4_A + i * 4);
30455888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
30465888111cSHariprasad Shenai 			used = T5_USED_G(lo);
30475888111cSHariprasad Shenai 			alloc = T5_ALLOC_G(lo);
30485888111cSHariprasad Shenai 		} else {
30495888111cSHariprasad Shenai 			used = USED_G(lo);
30505888111cSHariprasad Shenai 			alloc = ALLOC_G(lo);
30515888111cSHariprasad Shenai 		}
30525888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
30535888111cSHariprasad Shenai 		seq_printf(seq,
30545888111cSHariprasad Shenai 			   "Loopback %d using %u pages out of %u allocated\n",
30555888111cSHariprasad Shenai 			   i, used, alloc);
30565888111cSHariprasad Shenai 	}
30575888111cSHariprasad Shenai 	return 0;
30585888111cSHariprasad Shenai }
30595888111cSHariprasad Shenai 
30605888111cSHariprasad Shenai static int meminfo_open(struct inode *inode, struct file *file)
30615888111cSHariprasad Shenai {
30625888111cSHariprasad Shenai 	return single_open(file, meminfo_show, inode->i_private);
30635888111cSHariprasad Shenai }
30645888111cSHariprasad Shenai 
30655888111cSHariprasad Shenai static const struct file_operations meminfo_fops = {
30665888111cSHariprasad Shenai 	.owner   = THIS_MODULE,
30675888111cSHariprasad Shenai 	.open    = meminfo_open,
30685888111cSHariprasad Shenai 	.read    = seq_read,
30695888111cSHariprasad Shenai 	.llseek  = seq_lseek,
30705888111cSHariprasad Shenai 	.release = single_release,
30715888111cSHariprasad Shenai };
3072ee0863baSHarsh Jain 
3073ee0863baSHarsh Jain static int chcr_show(struct seq_file *seq, void *v)
3074ee0863baSHarsh Jain {
3075ee0863baSHarsh Jain 	struct adapter *adap = seq->private;
3076ee0863baSHarsh Jain 
3077ee0863baSHarsh Jain 	seq_puts(seq, "Chelsio Crypto Accelerator Stats \n");
3078ee0863baSHarsh Jain 	seq_printf(seq, "Cipher Ops: %10u \n",
3079ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.cipher_rqst));
3080ee0863baSHarsh Jain 	seq_printf(seq, "Digest Ops: %10u \n",
3081ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.digest_rqst));
3082ee0863baSHarsh Jain 	seq_printf(seq, "Aead Ops: %10u \n",
3083ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.aead_rqst));
3084ee0863baSHarsh Jain 	seq_printf(seq, "Completion: %10u \n",
3085ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.complete));
3086ee0863baSHarsh Jain 	seq_printf(seq, "Error: %10u \n",
3087ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.error));
3088ee0863baSHarsh Jain 	seq_printf(seq, "Fallback: %10u \n",
3089ee0863baSHarsh Jain 		   atomic_read(&adap->chcr_stats.fallback));
3090ee0863baSHarsh Jain 	return 0;
3091ee0863baSHarsh Jain }
3092ee0863baSHarsh Jain 
3093ee0863baSHarsh Jain 
3094ee0863baSHarsh Jain static int chcr_stats_open(struct inode *inode, struct file *file)
3095ee0863baSHarsh Jain {
3096ee0863baSHarsh Jain         return single_open(file, chcr_show, inode->i_private);
3097ee0863baSHarsh Jain }
3098ee0863baSHarsh Jain 
3099ee0863baSHarsh Jain static const struct file_operations chcr_stats_debugfs_fops = {
3100ee0863baSHarsh Jain         .owner   = THIS_MODULE,
3101ee0863baSHarsh Jain         .open    = chcr_stats_open,
3102ee0863baSHarsh Jain         .read    = seq_read,
3103ee0863baSHarsh Jain         .llseek  = seq_lseek,
3104ee0863baSHarsh Jain         .release = single_release,
3105ee0863baSHarsh Jain };
3106fd88b31aSHariprasad Shenai /* Add an array of Debug FS files.
3107fd88b31aSHariprasad Shenai  */
3108fd88b31aSHariprasad Shenai void add_debugfs_files(struct adapter *adap,
3109fd88b31aSHariprasad Shenai 		       struct t4_debugfs_entry *files,
3110fd88b31aSHariprasad Shenai 		       unsigned int nfiles)
3111fd88b31aSHariprasad Shenai {
3112fd88b31aSHariprasad Shenai 	int i;
3113fd88b31aSHariprasad Shenai 
3114fd88b31aSHariprasad Shenai 	/* debugfs support is best effort */
3115fd88b31aSHariprasad Shenai 	for (i = 0; i < nfiles; i++)
3116fd88b31aSHariprasad Shenai 		debugfs_create_file(files[i].name, files[i].mode,
3117fd88b31aSHariprasad Shenai 				    adap->debugfs_root,
3118fd88b31aSHariprasad Shenai 				    (void *)adap + files[i].data,
3119fd88b31aSHariprasad Shenai 				    files[i].ops);
3120fd88b31aSHariprasad Shenai }
3121fd88b31aSHariprasad Shenai 
3122fd88b31aSHariprasad Shenai int t4_setup_debugfs(struct adapter *adap)
3123fd88b31aSHariprasad Shenai {
3124fd88b31aSHariprasad Shenai 	int i;
31253ccc6cf7SHariprasad Shenai 	u32 size = 0;
312649216c1cSHariprasad Shenai 	struct dentry *de;
3127fd88b31aSHariprasad Shenai 
3128fd88b31aSHariprasad Shenai 	static struct t4_debugfs_entry t4_debugfs_files[] = {
3129f1ff24aaSHariprasad Shenai 		{ "cim_la", &cim_la_fops, S_IRUSR, 0 },
313019689609SHariprasad Shenai 		{ "cim_pif_la", &cim_pif_la_fops, S_IRUSR, 0 },
313126fae93fSHariprasad Shenai 		{ "cim_ma_la", &cim_ma_la_fops, S_IRUSR, 0 },
313274b3092cSHariprasad Shenai 		{ "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
3133b58b6676SHariprasad Shenai 		{ "clk", &clk_debugfs_fops, S_IRUSR, 0 },
313449aa284fSHariprasad Shenai 		{ "devlog", &devlog_fops, S_IRUSR, 0 },
31357f080c3fSHariprasad Shenai 		{ "mboxlog", &mboxlog_fops, S_IRUSR, 0 },
3136bf7c781dSHariprasad Shenai 		{ "mbox0", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
3137bf7c781dSHariprasad Shenai 		{ "mbox1", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
3138bf7c781dSHariprasad Shenai 		{ "mbox2", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
3139bf7c781dSHariprasad Shenai 		{ "mbox3", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3140bf7c781dSHariprasad Shenai 		{ "mbox4", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 4 },
3141bf7c781dSHariprasad Shenai 		{ "mbox5", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 5 },
3142bf7c781dSHariprasad Shenai 		{ "mbox6", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 6 },
3143bf7c781dSHariprasad Shenai 		{ "mbox7", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 7 },
31448e3d04fdSHariprasad Shenai 		{ "trace0", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
31458e3d04fdSHariprasad Shenai 		{ "trace1", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
31468e3d04fdSHariprasad Shenai 		{ "trace2", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
31478e3d04fdSHariprasad Shenai 		{ "trace3", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3148fd88b31aSHariprasad Shenai 		{ "l2t", &t4_l2t_fops, S_IRUSR, 0},
3149ef82f662SHariprasad Shenai 		{ "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
3150688ea5feSHariprasad Shenai 		{ "rss", &rss_debugfs_fops, S_IRUSR, 0 },
3151688ea5feSHariprasad Shenai 		{ "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
3152688ea5feSHariprasad Shenai 		{ "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
3153688ea5feSHariprasad Shenai 		{ "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
3154688ea5feSHariprasad Shenai 		{ "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
3155dc9daab2SHariprasad Shenai 		{ "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
3156e5f0e43bSHariprasad Shenai 		{ "ibq_tp0",  &cim_ibq_fops, S_IRUSR, 0 },
3157e5f0e43bSHariprasad Shenai 		{ "ibq_tp1",  &cim_ibq_fops, S_IRUSR, 1 },
3158e5f0e43bSHariprasad Shenai 		{ "ibq_ulp",  &cim_ibq_fops, S_IRUSR, 2 },
3159e5f0e43bSHariprasad Shenai 		{ "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
3160e5f0e43bSHariprasad Shenai 		{ "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
3161e5f0e43bSHariprasad Shenai 		{ "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
3162c778af7dSHariprasad Shenai 		{ "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
3163c778af7dSHariprasad Shenai 		{ "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
3164c778af7dSHariprasad Shenai 		{ "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
3165c778af7dSHariprasad Shenai 		{ "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
3166c778af7dSHariprasad Shenai 		{ "obq_sge",  &cim_obq_fops, S_IRUSR, 4 },
3167c778af7dSHariprasad Shenai 		{ "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
31682d277b3bSHariprasad Shenai 		{ "tp_la", &tp_la_fops, S_IRUSR, 0 },
3169797ff0f5SHariprasad Shenai 		{ "ulprx_la", &ulprx_la_fops, S_IRUSR, 0 },
317070a5f3bbSHariprasad Shenai 		{ "sensors", &sensors_debugfs_fops, S_IRUSR, 0 },
3171b3bbe36aSHariprasad Shenai 		{ "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
31727864026bSHariprasad Shenai 		{ "tx_rate", &tx_rate_debugfs_fops, S_IRUSR, 0 },
3173bad43792SHariprasad Shenai 		{ "cctrl", &cctrl_tbl_debugfs_fops, S_IRUSR, 0 },
3174b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
3175b5a02f50SAnish Bhatt 		{ "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
3176b5a02f50SAnish Bhatt #endif
3177a4011fd4SHariprasad Shenai 		{ "tids", &tid_info_debugfs_fops, S_IRUSR, 0},
31785b377d11SHariprasad Shenai 		{ "blocked_fl", &blocked_fl_fops, S_IRUSR | S_IWUSR, 0 },
31795888111cSHariprasad Shenai 		{ "meminfo", &meminfo_fops, S_IRUSR, 0 },
3180ee0863baSHarsh Jain 		{ "crypto", &chcr_stats_debugfs_fops, S_IRUSR, 0 },
3181fd88b31aSHariprasad Shenai 	};
3182fd88b31aSHariprasad Shenai 
3183c778af7dSHariprasad Shenai 	/* Debug FS nodes common to all T5 and later adapters.
3184c778af7dSHariprasad Shenai 	 */
3185c778af7dSHariprasad Shenai 	static struct t4_debugfs_entry t5_debugfs_files[] = {
3186c778af7dSHariprasad Shenai 		{ "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
3187c778af7dSHariprasad Shenai 		{ "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
3188c778af7dSHariprasad Shenai 	};
3189c778af7dSHariprasad Shenai 
3190fd88b31aSHariprasad Shenai 	add_debugfs_files(adap,
3191fd88b31aSHariprasad Shenai 			  t4_debugfs_files,
3192fd88b31aSHariprasad Shenai 			  ARRAY_SIZE(t4_debugfs_files));
3193c778af7dSHariprasad Shenai 	if (!is_t4(adap->params.chip))
3194c778af7dSHariprasad Shenai 		add_debugfs_files(adap,
3195c778af7dSHariprasad Shenai 				  t5_debugfs_files,
3196c778af7dSHariprasad Shenai 				  ARRAY_SIZE(t5_debugfs_files));
3197fd88b31aSHariprasad Shenai 
31986559a7e8SHariprasad Shenai 	i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
31996559a7e8SHariprasad Shenai 	if (i & EDRAM0_ENABLE_F) {
32006559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
32016559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
3202fd88b31aSHariprasad Shenai 	}
32036559a7e8SHariprasad Shenai 	if (i & EDRAM1_ENABLE_F) {
32046559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
32056559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
3206fd88b31aSHariprasad Shenai 	}
32073ccc6cf7SHariprasad Shenai 	if (is_t5(adap->params.chip)) {
32086559a7e8SHariprasad Shenai 		if (i & EXT_MEM0_ENABLE_F) {
32096559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
3210fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc0", MEM_MC0,
32116559a7e8SHariprasad Shenai 					EXT_MEM0_SIZE_G(size));
3212fd88b31aSHariprasad Shenai 		}
32136559a7e8SHariprasad Shenai 		if (i & EXT_MEM1_ENABLE_F) {
32146559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
3215fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc1", MEM_MC1,
32166559a7e8SHariprasad Shenai 					EXT_MEM1_SIZE_G(size));
3217fd88b31aSHariprasad Shenai 		}
32183ccc6cf7SHariprasad Shenai 	} else {
321921a44763SDan Carpenter 		if (i & EXT_MEM_ENABLE_F) {
32203ccc6cf7SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
32213ccc6cf7SHariprasad Shenai 			add_debugfs_mem(adap, "mc", MEM_MC,
32223ccc6cf7SHariprasad Shenai 					EXT_MEM_SIZE_G(size));
3223fd88b31aSHariprasad Shenai 		}
322421a44763SDan Carpenter 	}
322549216c1cSHariprasad Shenai 
3226c1d81b1cSDavid Howells 	de = debugfs_create_file_size("flash", S_IRUSR, adap->debugfs_root, adap,
3227c1d81b1cSDavid Howells 				      &flash_debugfs_fops, adap->params.sf_size);
32280b2c2a93SHariprasad Shenai 	debugfs_create_bool("use_backdoor", S_IWUSR | S_IRUSR,
32290b2c2a93SHariprasad Shenai 			    adap->debugfs_root, &adap->use_bd);
32308e3d04fdSHariprasad Shenai 	debugfs_create_bool("trace_rss", S_IWUSR | S_IRUSR,
32318e3d04fdSHariprasad Shenai 			    adap->debugfs_root, &adap->trace_rss);
323249216c1cSHariprasad Shenai 
3233fd88b31aSHariprasad Shenai 	return 0;
3234fd88b31aSHariprasad Shenai }
3235