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 
1155bf7c781dSHariprasad Shenai static int mbox_show(struct seq_file *seq, void *v)
1156bf7c781dSHariprasad Shenai {
1157bf7c781dSHariprasad Shenai 	static const char * const owner[] = { "none", "FW", "driver",
1158b3695540SHariprasad Shenai 					      "unknown", "<unread>" };
1159bf7c781dSHariprasad Shenai 
1160bf7c781dSHariprasad Shenai 	int i;
1161bf7c781dSHariprasad Shenai 	unsigned int mbox = (uintptr_t)seq->private & 7;
1162bf7c781dSHariprasad Shenai 	struct adapter *adap = seq->private - mbox;
1163bf7c781dSHariprasad Shenai 	void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1164b3695540SHariprasad Shenai 
1165b3695540SHariprasad Shenai 	/* For T4 we don't have a shadow copy of the Mailbox Control register.
1166b3695540SHariprasad Shenai 	 * And since reading that real register causes a side effect of
1167b3695540SHariprasad Shenai 	 * granting ownership, we're best of simply not reading it at all.
1168b3695540SHariprasad Shenai 	 */
1169b3695540SHariprasad Shenai 	if (is_t4(adap->params.chip)) {
1170b3695540SHariprasad Shenai 		i = 4; /* index of "<unread>" */
1171b3695540SHariprasad Shenai 	} else {
1172b3695540SHariprasad Shenai 		unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
1173bf7c781dSHariprasad Shenai 		void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
1174bf7c781dSHariprasad Shenai 
1175bf7c781dSHariprasad Shenai 		i = MBOWNER_G(readl(ctrl));
1176b3695540SHariprasad Shenai 	}
1177b3695540SHariprasad Shenai 
1178bf7c781dSHariprasad Shenai 	seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
1179bf7c781dSHariprasad Shenai 
1180bf7c781dSHariprasad Shenai 	for (i = 0; i < MBOX_LEN; i += 8)
1181bf7c781dSHariprasad Shenai 		seq_printf(seq, "%016llx\n",
1182bf7c781dSHariprasad Shenai 			   (unsigned long long)readq(addr + i));
1183bf7c781dSHariprasad Shenai 	return 0;
1184bf7c781dSHariprasad Shenai }
1185bf7c781dSHariprasad Shenai 
1186bf7c781dSHariprasad Shenai static int mbox_open(struct inode *inode, struct file *file)
1187bf7c781dSHariprasad Shenai {
1188bf7c781dSHariprasad Shenai 	return single_open(file, mbox_show, inode->i_private);
1189bf7c781dSHariprasad Shenai }
1190bf7c781dSHariprasad Shenai 
1191bf7c781dSHariprasad Shenai static ssize_t mbox_write(struct file *file, const char __user *buf,
1192bf7c781dSHariprasad Shenai 			  size_t count, loff_t *pos)
1193bf7c781dSHariprasad Shenai {
1194bf7c781dSHariprasad Shenai 	int i;
1195bf7c781dSHariprasad Shenai 	char c = '\n', s[256];
1196bf7c781dSHariprasad Shenai 	unsigned long long data[8];
1197bf7c781dSHariprasad Shenai 	const struct inode *ino;
1198bf7c781dSHariprasad Shenai 	unsigned int mbox;
1199bf7c781dSHariprasad Shenai 	struct adapter *adap;
1200bf7c781dSHariprasad Shenai 	void __iomem *addr;
1201bf7c781dSHariprasad Shenai 	void __iomem *ctrl;
1202bf7c781dSHariprasad Shenai 
1203bf7c781dSHariprasad Shenai 	if (count > sizeof(s) - 1 || !count)
1204bf7c781dSHariprasad Shenai 		return -EINVAL;
1205bf7c781dSHariprasad Shenai 	if (copy_from_user(s, buf, count))
1206bf7c781dSHariprasad Shenai 		return -EFAULT;
1207bf7c781dSHariprasad Shenai 	s[count] = '\0';
1208bf7c781dSHariprasad Shenai 
1209bf7c781dSHariprasad Shenai 	if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
1210bf7c781dSHariprasad Shenai 		   &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
1211bf7c781dSHariprasad Shenai 		   &data[7], &c) < 8 || c != '\n')
1212bf7c781dSHariprasad Shenai 		return -EINVAL;
1213bf7c781dSHariprasad Shenai 
1214c1d81b1cSDavid Howells 	ino = file_inode(file);
1215bf7c781dSHariprasad Shenai 	mbox = (uintptr_t)ino->i_private & 7;
1216bf7c781dSHariprasad Shenai 	adap = ino->i_private - mbox;
1217bf7c781dSHariprasad Shenai 	addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
1218bf7c781dSHariprasad Shenai 	ctrl = addr + MBOX_LEN;
1219bf7c781dSHariprasad Shenai 
1220bf7c781dSHariprasad Shenai 	if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
1221bf7c781dSHariprasad Shenai 		return -EBUSY;
1222bf7c781dSHariprasad Shenai 
1223bf7c781dSHariprasad Shenai 	for (i = 0; i < 8; i++)
1224bf7c781dSHariprasad Shenai 		writeq(data[i], addr + 8 * i);
1225bf7c781dSHariprasad Shenai 
1226bf7c781dSHariprasad Shenai 	writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
1227bf7c781dSHariprasad Shenai 	return count;
1228bf7c781dSHariprasad Shenai }
1229bf7c781dSHariprasad Shenai 
1230bf7c781dSHariprasad Shenai static const struct file_operations mbox_debugfs_fops = {
1231bf7c781dSHariprasad Shenai 	.owner   = THIS_MODULE,
1232bf7c781dSHariprasad Shenai 	.open    = mbox_open,
1233bf7c781dSHariprasad Shenai 	.read    = seq_read,
1234bf7c781dSHariprasad Shenai 	.llseek  = seq_lseek,
1235bf7c781dSHariprasad Shenai 	.release = single_release,
1236bf7c781dSHariprasad Shenai 	.write   = mbox_write
1237bf7c781dSHariprasad Shenai };
1238bf7c781dSHariprasad Shenai 
12398e3d04fdSHariprasad Shenai static int mps_trc_show(struct seq_file *seq, void *v)
12408e3d04fdSHariprasad Shenai {
12418e3d04fdSHariprasad Shenai 	int enabled, i;
12428e3d04fdSHariprasad Shenai 	struct trace_params tp;
12438e3d04fdSHariprasad Shenai 	unsigned int trcidx = (uintptr_t)seq->private & 3;
12448e3d04fdSHariprasad Shenai 	struct adapter *adap = seq->private - trcidx;
12458e3d04fdSHariprasad Shenai 
12468e3d04fdSHariprasad Shenai 	t4_get_trace_filter(adap, &tp, trcidx, &enabled);
12478e3d04fdSHariprasad Shenai 	if (!enabled) {
12488e3d04fdSHariprasad Shenai 		seq_puts(seq, "tracer is disabled\n");
12498e3d04fdSHariprasad Shenai 		return 0;
12508e3d04fdSHariprasad Shenai 	}
12518e3d04fdSHariprasad Shenai 
12528e3d04fdSHariprasad Shenai 	if (tp.skip_ofst * 8 >= TRACE_LEN) {
12538e3d04fdSHariprasad Shenai 		dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
12548e3d04fdSHariprasad Shenai 		return -EINVAL;
12558e3d04fdSHariprasad Shenai 	}
12568e3d04fdSHariprasad Shenai 	if (tp.port < 8) {
12578e3d04fdSHariprasad Shenai 		i = adap->chan_map[tp.port & 3];
12588e3d04fdSHariprasad Shenai 		if (i >= MAX_NPORTS) {
12598e3d04fdSHariprasad Shenai 			dev_err(adap->pdev_dev, "tracer %u is assigned "
12608e3d04fdSHariprasad Shenai 				"to non-existing port\n", trcidx);
12618e3d04fdSHariprasad Shenai 			return -EINVAL;
12628e3d04fdSHariprasad Shenai 		}
12638e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing %s %s, ",
12648e3d04fdSHariprasad Shenai 			   adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
12658e3d04fdSHariprasad Shenai 	} else
12668e3d04fdSHariprasad Shenai 		seq_printf(seq, "tracer is capturing loopback %d, ",
12678e3d04fdSHariprasad Shenai 			   tp.port - 8);
12688e3d04fdSHariprasad Shenai 	seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
12698e3d04fdSHariprasad Shenai 		   tp.min_len);
12708e3d04fdSHariprasad Shenai 	seq_printf(seq, "packets captured %smatch filter\n",
12718e3d04fdSHariprasad Shenai 		   tp.invert ? "do not " : "");
12728e3d04fdSHariprasad Shenai 
12738e3d04fdSHariprasad Shenai 	if (tp.skip_ofst) {
12748e3d04fdSHariprasad Shenai 		seq_puts(seq, "filter pattern: ");
12758e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
12768e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
12778e3d04fdSHariprasad Shenai 		seq_putc(seq, '/');
12788e3d04fdSHariprasad Shenai 		for (i = 0; i < tp.skip_ofst * 2; i += 2)
12798e3d04fdSHariprasad Shenai 			seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
12808e3d04fdSHariprasad Shenai 		seq_puts(seq, "@0\n");
12818e3d04fdSHariprasad Shenai 	}
12828e3d04fdSHariprasad Shenai 
12838e3d04fdSHariprasad Shenai 	seq_puts(seq, "filter pattern: ");
12848e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
12858e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
12868e3d04fdSHariprasad Shenai 	seq_putc(seq, '/');
12878e3d04fdSHariprasad Shenai 	for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
12888e3d04fdSHariprasad Shenai 		seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
12898e3d04fdSHariprasad Shenai 	seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
12908e3d04fdSHariprasad Shenai 	return 0;
12918e3d04fdSHariprasad Shenai }
12928e3d04fdSHariprasad Shenai 
12938e3d04fdSHariprasad Shenai static int mps_trc_open(struct inode *inode, struct file *file)
12948e3d04fdSHariprasad Shenai {
12958e3d04fdSHariprasad Shenai 	return single_open(file, mps_trc_show, inode->i_private);
12968e3d04fdSHariprasad Shenai }
12978e3d04fdSHariprasad Shenai 
12988e3d04fdSHariprasad Shenai static unsigned int xdigit2int(unsigned char c)
12998e3d04fdSHariprasad Shenai {
13008e3d04fdSHariprasad Shenai 	return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
13018e3d04fdSHariprasad Shenai }
13028e3d04fdSHariprasad Shenai 
13038e3d04fdSHariprasad Shenai #define TRC_PORT_NONE 0xff
13048e3d04fdSHariprasad Shenai #define TRC_RSS_ENABLE 0x33
13058e3d04fdSHariprasad Shenai #define TRC_RSS_DISABLE 0x13
13068e3d04fdSHariprasad Shenai 
13078e3d04fdSHariprasad Shenai /* Set an MPS trace filter.  Syntax is:
13088e3d04fdSHariprasad Shenai  *
13098e3d04fdSHariprasad Shenai  * disable
13108e3d04fdSHariprasad Shenai  *
13118e3d04fdSHariprasad Shenai  * to disable tracing, or
13128e3d04fdSHariprasad Shenai  *
13138e3d04fdSHariprasad Shenai  * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
13148e3d04fdSHariprasad Shenai  *
13158e3d04fdSHariprasad Shenai  * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
13168e3d04fdSHariprasad Shenai  * of the NIC's response qid obtained from sge_qinfo and pattern has the form
13178e3d04fdSHariprasad Shenai  *
13188e3d04fdSHariprasad Shenai  * <pattern data>[/<pattern mask>][@<anchor>]
13198e3d04fdSHariprasad Shenai  *
13208e3d04fdSHariprasad Shenai  * Up to 2 filter patterns can be specified.  If 2 are supplied the first one
13218e3d04fdSHariprasad Shenai  * must be anchored at 0.  An omited mask is taken as a mask of 1s, an omitted
13228e3d04fdSHariprasad Shenai  * anchor is taken as 0.
13238e3d04fdSHariprasad Shenai  */
13248e3d04fdSHariprasad Shenai static ssize_t mps_trc_write(struct file *file, const char __user *buf,
13258e3d04fdSHariprasad Shenai 			     size_t count, loff_t *pos)
13268e3d04fdSHariprasad Shenai {
1327c938a003SDan Carpenter 	int i, enable, ret;
13288e3d04fdSHariprasad Shenai 	u32 *data, *mask;
13298e3d04fdSHariprasad Shenai 	struct trace_params tp;
13308e3d04fdSHariprasad Shenai 	const struct inode *ino;
13318e3d04fdSHariprasad Shenai 	unsigned int trcidx;
13328e3d04fdSHariprasad Shenai 	char *s, *p, *word, *end;
13338e3d04fdSHariprasad Shenai 	struct adapter *adap;
1334c938a003SDan Carpenter 	u32 j;
13358e3d04fdSHariprasad Shenai 
13368e3d04fdSHariprasad Shenai 	ino = file_inode(file);
13378e3d04fdSHariprasad Shenai 	trcidx = (uintptr_t)ino->i_private & 3;
13388e3d04fdSHariprasad Shenai 	adap = ino->i_private - trcidx;
13398e3d04fdSHariprasad Shenai 
13408e3d04fdSHariprasad Shenai 	/* Don't accept input more than 1K, can't be anything valid except lots
13418e3d04fdSHariprasad Shenai 	 * of whitespace.  Well, use less.
13428e3d04fdSHariprasad Shenai 	 */
13438e3d04fdSHariprasad Shenai 	if (count > 1024)
13448e3d04fdSHariprasad Shenai 		return -EFBIG;
13458e3d04fdSHariprasad Shenai 	p = s = kzalloc(count + 1, GFP_USER);
13468e3d04fdSHariprasad Shenai 	if (!s)
13478e3d04fdSHariprasad Shenai 		return -ENOMEM;
13488e3d04fdSHariprasad Shenai 	if (copy_from_user(s, buf, count)) {
13498e3d04fdSHariprasad Shenai 		count = -EFAULT;
13508e3d04fdSHariprasad Shenai 		goto out;
13518e3d04fdSHariprasad Shenai 	}
13528e3d04fdSHariprasad Shenai 
13538e3d04fdSHariprasad Shenai 	if (s[count - 1] == '\n')
13548e3d04fdSHariprasad Shenai 		s[count - 1] = '\0';
13558e3d04fdSHariprasad Shenai 
13568e3d04fdSHariprasad Shenai 	enable = strcmp("disable", s) != 0;
13578e3d04fdSHariprasad Shenai 	if (!enable)
13588e3d04fdSHariprasad Shenai 		goto apply;
13598e3d04fdSHariprasad Shenai 
13608e3d04fdSHariprasad Shenai 	/* enable or disable trace multi rss filter */
13618e3d04fdSHariprasad Shenai 	if (adap->trace_rss)
13628e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
13638e3d04fdSHariprasad Shenai 	else
13648e3d04fdSHariprasad Shenai 		t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
13658e3d04fdSHariprasad Shenai 
13668e3d04fdSHariprasad Shenai 	memset(&tp, 0, sizeof(tp));
13678e3d04fdSHariprasad Shenai 	tp.port = TRC_PORT_NONE;
13688e3d04fdSHariprasad Shenai 	i = 0;	/* counts pattern nibbles */
13698e3d04fdSHariprasad Shenai 
13708e3d04fdSHariprasad Shenai 	while (p) {
13718e3d04fdSHariprasad Shenai 		while (isspace(*p))
13728e3d04fdSHariprasad Shenai 			p++;
13738e3d04fdSHariprasad Shenai 		word = strsep(&p, " ");
13748e3d04fdSHariprasad Shenai 		if (!*word)
13758e3d04fdSHariprasad Shenai 			break;
13768e3d04fdSHariprasad Shenai 
13778e3d04fdSHariprasad Shenai 		if (!strncmp(word, "qid=", 4)) {
13788e3d04fdSHariprasad Shenai 			end = (char *)word + 4;
1379c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
13808e3d04fdSHariprasad Shenai 			if (ret)
13818e3d04fdSHariprasad Shenai 				goto out;
13828e3d04fdSHariprasad Shenai 			if (!adap->trace_rss) {
13838e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
13848e3d04fdSHariprasad Shenai 				continue;
13858e3d04fdSHariprasad Shenai 			}
13868e3d04fdSHariprasad Shenai 
13878e3d04fdSHariprasad Shenai 			switch (trcidx) {
13888e3d04fdSHariprasad Shenai 			case 0:
13898e3d04fdSHariprasad Shenai 				t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
13908e3d04fdSHariprasad Shenai 				break;
13918e3d04fdSHariprasad Shenai 			case 1:
13928e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
13938e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER1_RSS_CONTROL_A, j);
13948e3d04fdSHariprasad Shenai 				break;
13958e3d04fdSHariprasad Shenai 			case 2:
13968e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
13978e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER2_RSS_CONTROL_A, j);
13988e3d04fdSHariprasad Shenai 				break;
13998e3d04fdSHariprasad Shenai 			case 3:
14008e3d04fdSHariprasad Shenai 				t4_write_reg(adap,
14018e3d04fdSHariprasad Shenai 					     MPS_TRC_FILTER3_RSS_CONTROL_A, j);
14028e3d04fdSHariprasad Shenai 				break;
14038e3d04fdSHariprasad Shenai 			}
14048e3d04fdSHariprasad Shenai 			continue;
14058e3d04fdSHariprasad Shenai 		}
14068e3d04fdSHariprasad Shenai 		if (!strncmp(word, "snaplen=", 8)) {
14078e3d04fdSHariprasad Shenai 			end = (char *)word + 8;
1408c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
14098e3d04fdSHariprasad Shenai 			if (ret || j > 9600) {
14108e3d04fdSHariprasad Shenai inval:				count = -EINVAL;
14118e3d04fdSHariprasad Shenai 				goto out;
14128e3d04fdSHariprasad Shenai 			}
14138e3d04fdSHariprasad Shenai 			tp.snap_len = j;
14148e3d04fdSHariprasad Shenai 			continue;
14158e3d04fdSHariprasad Shenai 		}
14168e3d04fdSHariprasad Shenai 		if (!strncmp(word, "minlen=", 7)) {
14178e3d04fdSHariprasad Shenai 			end = (char *)word + 7;
1418c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
14198e3d04fdSHariprasad Shenai 			if (ret || j > TFMINPKTSIZE_M)
14208e3d04fdSHariprasad Shenai 				goto inval;
14218e3d04fdSHariprasad Shenai 			tp.min_len = j;
14228e3d04fdSHariprasad Shenai 			continue;
14238e3d04fdSHariprasad Shenai 		}
14248e3d04fdSHariprasad Shenai 		if (!strcmp(word, "not")) {
14258e3d04fdSHariprasad Shenai 			tp.invert = !tp.invert;
14268e3d04fdSHariprasad Shenai 			continue;
14278e3d04fdSHariprasad Shenai 		}
14288e3d04fdSHariprasad Shenai 		if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
14298e3d04fdSHariprasad Shenai 			if (word[8] < '0' || word[8] > '3' || word[9])
14308e3d04fdSHariprasad Shenai 				goto inval;
14318e3d04fdSHariprasad Shenai 			tp.port = word[8] - '0' + 8;
14328e3d04fdSHariprasad Shenai 			continue;
14338e3d04fdSHariprasad Shenai 		}
14348e3d04fdSHariprasad Shenai 		if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
14358e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
14368e3d04fdSHariprasad Shenai 				goto inval;
14378e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0' + 4;
14388e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
14398e3d04fdSHariprasad Shenai 				goto inval;
14408e3d04fdSHariprasad Shenai 			continue;
14418e3d04fdSHariprasad Shenai 		}
14428e3d04fdSHariprasad Shenai 		if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
14438e3d04fdSHariprasad Shenai 			if (word[2] < '0' || word[2] > '3' || word[3])
14448e3d04fdSHariprasad Shenai 				goto inval;
14458e3d04fdSHariprasad Shenai 			tp.port = word[2] - '0';
14468e3d04fdSHariprasad Shenai 			if (adap->chan_map[tp.port] >= MAX_NPORTS)
14478e3d04fdSHariprasad Shenai 				goto inval;
14488e3d04fdSHariprasad Shenai 			continue;
14498e3d04fdSHariprasad Shenai 		}
14508e3d04fdSHariprasad Shenai 		if (!isxdigit(*word))
14518e3d04fdSHariprasad Shenai 			goto inval;
14528e3d04fdSHariprasad Shenai 
14538e3d04fdSHariprasad Shenai 		/* we have found a trace pattern */
14548e3d04fdSHariprasad Shenai 		if (i) {                            /* split pattern */
14558e3d04fdSHariprasad Shenai 			if (tp.skip_len)            /* too many splits */
14568e3d04fdSHariprasad Shenai 				goto inval;
14578e3d04fdSHariprasad Shenai 			tp.skip_ofst = i / 16;
14588e3d04fdSHariprasad Shenai 		}
14598e3d04fdSHariprasad Shenai 
14608e3d04fdSHariprasad Shenai 		data = &tp.data[i / 8];
14618e3d04fdSHariprasad Shenai 		mask = &tp.mask[i / 8];
14628e3d04fdSHariprasad Shenai 		j = i;
14638e3d04fdSHariprasad Shenai 
14648e3d04fdSHariprasad Shenai 		while (isxdigit(*word)) {
14658e3d04fdSHariprasad Shenai 			if (i >= TRACE_LEN * 2) {
14668e3d04fdSHariprasad Shenai 				count = -EFBIG;
14678e3d04fdSHariprasad Shenai 				goto out;
14688e3d04fdSHariprasad Shenai 			}
14698e3d04fdSHariprasad Shenai 			*data = (*data << 4) + xdigit2int(*word++);
14708e3d04fdSHariprasad Shenai 			if (++i % 8 == 0)
14718e3d04fdSHariprasad Shenai 				data++;
14728e3d04fdSHariprasad Shenai 		}
14738e3d04fdSHariprasad Shenai 		if (*word == '/') {
14748e3d04fdSHariprasad Shenai 			word++;
14758e3d04fdSHariprasad Shenai 			while (isxdigit(*word)) {
14768e3d04fdSHariprasad Shenai 				if (j >= i)         /* mask longer than data */
14778e3d04fdSHariprasad Shenai 					goto inval;
14788e3d04fdSHariprasad Shenai 				*mask = (*mask << 4) + xdigit2int(*word++);
14798e3d04fdSHariprasad Shenai 				if (++j % 8 == 0)
14808e3d04fdSHariprasad Shenai 					mask++;
14818e3d04fdSHariprasad Shenai 			}
14828e3d04fdSHariprasad Shenai 			if (i != j)                 /* mask shorter than data */
14838e3d04fdSHariprasad Shenai 				goto inval;
14848e3d04fdSHariprasad Shenai 		} else {                            /* no mask, use all 1s */
14858e3d04fdSHariprasad Shenai 			for ( ; i - j >= 8; j += 8)
14868e3d04fdSHariprasad Shenai 				*mask++ = 0xffffffff;
14878e3d04fdSHariprasad Shenai 			if (i % 8)
14888e3d04fdSHariprasad Shenai 				*mask = (1 << (i % 8) * 4) - 1;
14898e3d04fdSHariprasad Shenai 		}
14908e3d04fdSHariprasad Shenai 		if (*word == '@') {
14918e3d04fdSHariprasad Shenai 			end = (char *)word + 1;
1492c938a003SDan Carpenter 			ret = kstrtouint(end, 10, &j);
14938e3d04fdSHariprasad Shenai 			if (*end && *end != '\n')
14948e3d04fdSHariprasad Shenai 				goto inval;
14958e3d04fdSHariprasad Shenai 			if (j & 7)          /* doesn't start at multiple of 8 */
14968e3d04fdSHariprasad Shenai 				goto inval;
14978e3d04fdSHariprasad Shenai 			j /= 8;
14988e3d04fdSHariprasad Shenai 			if (j < tp.skip_ofst)     /* overlaps earlier pattern */
14998e3d04fdSHariprasad Shenai 				goto inval;
15008e3d04fdSHariprasad Shenai 			if (j - tp.skip_ofst > 31)            /* skip too big */
15018e3d04fdSHariprasad Shenai 				goto inval;
15028e3d04fdSHariprasad Shenai 			tp.skip_len = j - tp.skip_ofst;
15038e3d04fdSHariprasad Shenai 		}
15048e3d04fdSHariprasad Shenai 		if (i % 8) {
15058e3d04fdSHariprasad Shenai 			*data <<= (8 - i % 8) * 4;
15068e3d04fdSHariprasad Shenai 			*mask <<= (8 - i % 8) * 4;
15078e3d04fdSHariprasad Shenai 			i = (i + 15) & ~15;         /* 8-byte align */
15088e3d04fdSHariprasad Shenai 		}
15098e3d04fdSHariprasad Shenai 	}
15108e3d04fdSHariprasad Shenai 
15118e3d04fdSHariprasad Shenai 	if (tp.port == TRC_PORT_NONE)
15128e3d04fdSHariprasad Shenai 		goto inval;
15138e3d04fdSHariprasad Shenai 
15148e3d04fdSHariprasad Shenai apply:
15158e3d04fdSHariprasad Shenai 	i = t4_set_trace_filter(adap, &tp, trcidx, enable);
15168e3d04fdSHariprasad Shenai 	if (i)
15178e3d04fdSHariprasad Shenai 		count = i;
15188e3d04fdSHariprasad Shenai out:
15198e3d04fdSHariprasad Shenai 	kfree(s);
15208e3d04fdSHariprasad Shenai 	return count;
15218e3d04fdSHariprasad Shenai }
15228e3d04fdSHariprasad Shenai 
15238e3d04fdSHariprasad Shenai static const struct file_operations mps_trc_debugfs_fops = {
15248e3d04fdSHariprasad Shenai 	.owner   = THIS_MODULE,
15258e3d04fdSHariprasad Shenai 	.open    = mps_trc_open,
15268e3d04fdSHariprasad Shenai 	.read    = seq_read,
15278e3d04fdSHariprasad Shenai 	.llseek  = seq_lseek,
15288e3d04fdSHariprasad Shenai 	.release = single_release,
15298e3d04fdSHariprasad Shenai 	.write   = mps_trc_write
15308e3d04fdSHariprasad Shenai };
15318e3d04fdSHariprasad Shenai 
153249216c1cSHariprasad Shenai static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
153349216c1cSHariprasad Shenai 			  loff_t *ppos)
153449216c1cSHariprasad Shenai {
153549216c1cSHariprasad Shenai 	loff_t pos = *ppos;
1536c1d81b1cSDavid Howells 	loff_t avail = file_inode(file)->i_size;
153749216c1cSHariprasad Shenai 	struct adapter *adap = file->private_data;
153849216c1cSHariprasad Shenai 
153949216c1cSHariprasad Shenai 	if (pos < 0)
154049216c1cSHariprasad Shenai 		return -EINVAL;
154149216c1cSHariprasad Shenai 	if (pos >= avail)
154249216c1cSHariprasad Shenai 		return 0;
154349216c1cSHariprasad Shenai 	if (count > avail - pos)
154449216c1cSHariprasad Shenai 		count = avail - pos;
154549216c1cSHariprasad Shenai 
154649216c1cSHariprasad Shenai 	while (count) {
154749216c1cSHariprasad Shenai 		size_t len;
154849216c1cSHariprasad Shenai 		int ret, ofst;
154949216c1cSHariprasad Shenai 		u8 data[256];
155049216c1cSHariprasad Shenai 
155149216c1cSHariprasad Shenai 		ofst = pos & 3;
155249216c1cSHariprasad Shenai 		len = min(count + ofst, sizeof(data));
155349216c1cSHariprasad Shenai 		ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
155449216c1cSHariprasad Shenai 				    (u32 *)data, 1);
155549216c1cSHariprasad Shenai 		if (ret)
155649216c1cSHariprasad Shenai 			return ret;
155749216c1cSHariprasad Shenai 
155849216c1cSHariprasad Shenai 		len -= ofst;
155949216c1cSHariprasad Shenai 		if (copy_to_user(buf, data + ofst, len))
156049216c1cSHariprasad Shenai 			return -EFAULT;
156149216c1cSHariprasad Shenai 
156249216c1cSHariprasad Shenai 		buf += len;
156349216c1cSHariprasad Shenai 		pos += len;
156449216c1cSHariprasad Shenai 		count -= len;
156549216c1cSHariprasad Shenai 	}
156649216c1cSHariprasad Shenai 	count = pos - *ppos;
156749216c1cSHariprasad Shenai 	*ppos = pos;
156849216c1cSHariprasad Shenai 	return count;
156949216c1cSHariprasad Shenai }
157049216c1cSHariprasad Shenai 
157149216c1cSHariprasad Shenai static const struct file_operations flash_debugfs_fops = {
157249216c1cSHariprasad Shenai 	.owner   = THIS_MODULE,
157349216c1cSHariprasad Shenai 	.open    = mem_open,
157449216c1cSHariprasad Shenai 	.read    = flash_read,
157549216c1cSHariprasad Shenai };
157649216c1cSHariprasad Shenai 
1577ef82f662SHariprasad Shenai static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
1578ef82f662SHariprasad Shenai {
1579ef82f662SHariprasad Shenai 	*mask = x | y;
1580ef82f662SHariprasad Shenai 	y = (__force u64)cpu_to_be64(y);
1581ef82f662SHariprasad Shenai 	memcpy(addr, (char *)&y + 2, ETH_ALEN);
1582ef82f662SHariprasad Shenai }
1583ef82f662SHariprasad Shenai 
1584ef82f662SHariprasad Shenai static int mps_tcam_show(struct seq_file *seq, void *v)
1585ef82f662SHariprasad Shenai {
15863ccc6cf7SHariprasad Shenai 	struct adapter *adap = seq->private;
15873ccc6cf7SHariprasad Shenai 	unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
15883ccc6cf7SHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
1589115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1590115b56afSHariprasad Shenai 			seq_puts(seq, "Idx  Ethernet address     Mask     "
1591115b56afSHariprasad Shenai 				 "  VNI   Mask   IVLAN Vld "
1592115b56afSHariprasad Shenai 				 "DIP_Hit   Lookup  Port "
1593115b56afSHariprasad Shenai 				 "Vld Ports PF  VF                           "
1594115b56afSHariprasad Shenai 				 "Replication                                "
1595115b56afSHariprasad Shenai 				 "    P0 P1 P2 P3  ML\n");
1596115b56afSHariprasad Shenai 		} else {
15973ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
15983ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
15993ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF                           "
16003ccc6cf7SHariprasad Shenai 					 "Replication                                "
1601ef82f662SHariprasad Shenai 					 "    P0 P1 P2 P3  ML\n");
16023ccc6cf7SHariprasad Shenai 			else
16033ccc6cf7SHariprasad Shenai 				seq_puts(seq, "Idx  Ethernet address     Mask     "
16043ccc6cf7SHariprasad Shenai 					 "Vld Ports PF  VF              Replication"
16053ccc6cf7SHariprasad Shenai 					 "	         P0 P1 P2 P3  ML\n");
1606115b56afSHariprasad Shenai 		}
16073ccc6cf7SHariprasad Shenai 	} else {
1608ef82f662SHariprasad Shenai 		u64 mask;
1609ef82f662SHariprasad Shenai 		u8 addr[ETH_ALEN];
1610115b56afSHariprasad Shenai 		bool replicate, dip_hit = false, vlan_vld = false;
1611ef82f662SHariprasad Shenai 		unsigned int idx = (uintptr_t)v - 2;
16123ccc6cf7SHariprasad Shenai 		u64 tcamy, tcamx, val;
1613115b56afSHariprasad Shenai 		u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
16143ccc6cf7SHariprasad Shenai 		u32 rplc[8] = {0};
1615115b56afSHariprasad Shenai 		u8 lookup_type = 0, port_num = 0;
1616115b56afSHariprasad Shenai 		u16 ivlan = 0;
16173ccc6cf7SHariprasad Shenai 
16183ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
16193ccc6cf7SHariprasad Shenai 			/* CtlCmdType - 0: Read, 1: Write
16203ccc6cf7SHariprasad Shenai 			 * CtlTcamSel - 0: TCAM0, 1: TCAM1
16213ccc6cf7SHariprasad Shenai 			 * CtlXYBitSel- 0: Y bit, 1: X bit
16223ccc6cf7SHariprasad Shenai 			 */
16233ccc6cf7SHariprasad Shenai 
16243ccc6cf7SHariprasad Shenai 			/* Read tcamy */
16253ccc6cf7SHariprasad Shenai 			ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
16263ccc6cf7SHariprasad Shenai 			if (idx < 256)
16273ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
16283ccc6cf7SHariprasad Shenai 			else
16293ccc6cf7SHariprasad Shenai 				ctl |= CTLTCAMINDEX_V(idx - 256) |
16303ccc6cf7SHariprasad Shenai 				       CTLTCAMSEL_V(1);
16313ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
16323ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
16333ccc6cf7SHariprasad Shenai 			tcamy = DMACH_G(val) << 32;
16343ccc6cf7SHariprasad Shenai 			tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1635115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1636115b56afSHariprasad Shenai 			lookup_type = DATALKPTYPE_G(data2);
1637115b56afSHariprasad Shenai 			/* 0 - Outer header, 1 - Inner header
1638115b56afSHariprasad Shenai 			 * [71:48] bit locations are overloaded for
1639115b56afSHariprasad Shenai 			 * outer vs. inner lookup types.
1640115b56afSHariprasad Shenai 			 */
1641115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1642115b56afSHariprasad Shenai 				/* Inner header VNI */
1643115b56afSHariprasad Shenai 				vniy = ((data2 & DATAVIDH2_F) << 23) |
1644115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1645115b56afSHariprasad Shenai 				dip_hit = data2 & DATADIPHIT_F;
1646115b56afSHariprasad Shenai 			} else {
1647115b56afSHariprasad Shenai 				vlan_vld = data2 & DATAVIDH2_F;
1648115b56afSHariprasad Shenai 				ivlan = VIDL_G(val);
1649115b56afSHariprasad Shenai 			}
1650115b56afSHariprasad Shenai 			port_num = DATAPORTNUM_G(data2);
16513ccc6cf7SHariprasad Shenai 
16523ccc6cf7SHariprasad Shenai 			/* Read tcamx. Change the control param */
16533ccc6cf7SHariprasad Shenai 			ctl |= CTLXYBITSEL_V(1);
16543ccc6cf7SHariprasad Shenai 			t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
16553ccc6cf7SHariprasad Shenai 			val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
16563ccc6cf7SHariprasad Shenai 			tcamx = DMACH_G(val) << 32;
16573ccc6cf7SHariprasad Shenai 			tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
1658115b56afSHariprasad Shenai 			data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
1659115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1660115b56afSHariprasad Shenai 				/* Inner header VNI mask */
1661115b56afSHariprasad Shenai 				vnix = ((data2 & DATAVIDH2_F) << 23) |
1662115b56afSHariprasad Shenai 				       (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
1663115b56afSHariprasad Shenai 			}
16643ccc6cf7SHariprasad Shenai 		} else {
16653ccc6cf7SHariprasad Shenai 			tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
16663ccc6cf7SHariprasad Shenai 			tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
16673ccc6cf7SHariprasad Shenai 		}
16683ccc6cf7SHariprasad Shenai 
16693ccc6cf7SHariprasad Shenai 		cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
16703ccc6cf7SHariprasad Shenai 		cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
1671ef82f662SHariprasad Shenai 
1672ef82f662SHariprasad Shenai 		if (tcamx & tcamy) {
1673ef82f662SHariprasad Shenai 			seq_printf(seq, "%3u         -\n", idx);
1674ef82f662SHariprasad Shenai 			goto out;
1675ef82f662SHariprasad Shenai 		}
1676ef82f662SHariprasad Shenai 
16773ccc6cf7SHariprasad Shenai 		rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
16783ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
16793ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & T6_REPLICATE_F);
16803ccc6cf7SHariprasad Shenai 		else
16813ccc6cf7SHariprasad Shenai 			replicate = (cls_lo & REPLICATE_F);
16823ccc6cf7SHariprasad Shenai 
16833ccc6cf7SHariprasad Shenai 		if (replicate) {
1684ef82f662SHariprasad Shenai 			struct fw_ldst_cmd ldst_cmd;
1685ef82f662SHariprasad Shenai 			int ret;
16863ccc6cf7SHariprasad Shenai 			struct fw_ldst_mps_rplc mps_rplc;
16873ccc6cf7SHariprasad Shenai 			u32 ldst_addrspc;
1688ef82f662SHariprasad Shenai 
1689ef82f662SHariprasad Shenai 			memset(&ldst_cmd, 0, sizeof(ldst_cmd));
16903ccc6cf7SHariprasad Shenai 			ldst_addrspc =
16913ccc6cf7SHariprasad Shenai 				FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
1692ef82f662SHariprasad Shenai 			ldst_cmd.op_to_addrspace =
1693ef82f662SHariprasad Shenai 				htonl(FW_CMD_OP_V(FW_LDST_CMD) |
1694ef82f662SHariprasad Shenai 				      FW_CMD_REQUEST_F |
1695ef82f662SHariprasad Shenai 				      FW_CMD_READ_F |
16963ccc6cf7SHariprasad Shenai 				      ldst_addrspc);
1697ef82f662SHariprasad Shenai 			ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
16983ccc6cf7SHariprasad Shenai 			ldst_cmd.u.mps.rplc.fid_idx =
1699ef82f662SHariprasad Shenai 				htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
17003ccc6cf7SHariprasad Shenai 				      FW_LDST_CMD_IDX_V(idx));
1701ef82f662SHariprasad Shenai 			ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
1702ef82f662SHariprasad Shenai 					 sizeof(ldst_cmd), &ldst_cmd);
1703ef82f662SHariprasad Shenai 			if (ret)
1704ef82f662SHariprasad Shenai 				dev_warn(adap->pdev_dev, "Can't read MPS "
1705ef82f662SHariprasad Shenai 					 "replication map for idx %d: %d\n",
1706ef82f662SHariprasad Shenai 					 idx, -ret);
1707ef82f662SHariprasad Shenai 			else {
17083ccc6cf7SHariprasad Shenai 				mps_rplc = ldst_cmd.u.mps.rplc;
17093ccc6cf7SHariprasad Shenai 				rplc[0] = ntohl(mps_rplc.rplc31_0);
17103ccc6cf7SHariprasad Shenai 				rplc[1] = ntohl(mps_rplc.rplc63_32);
17113ccc6cf7SHariprasad Shenai 				rplc[2] = ntohl(mps_rplc.rplc95_64);
17123ccc6cf7SHariprasad Shenai 				rplc[3] = ntohl(mps_rplc.rplc127_96);
17133ccc6cf7SHariprasad Shenai 				if (adap->params.arch.mps_rplc_size > 128) {
17143ccc6cf7SHariprasad Shenai 					rplc[4] = ntohl(mps_rplc.rplc159_128);
17153ccc6cf7SHariprasad Shenai 					rplc[5] = ntohl(mps_rplc.rplc191_160);
17163ccc6cf7SHariprasad Shenai 					rplc[6] = ntohl(mps_rplc.rplc223_192);
17173ccc6cf7SHariprasad Shenai 					rplc[7] = ntohl(mps_rplc.rplc255_224);
17183ccc6cf7SHariprasad Shenai 				}
1719ef82f662SHariprasad Shenai 			}
1720ef82f662SHariprasad Shenai 		}
1721ef82f662SHariprasad Shenai 
1722ef82f662SHariprasad Shenai 		tcamxy2valmask(tcamx, tcamy, addr, &mask);
1723115b56afSHariprasad Shenai 		if (chip_ver > CHELSIO_T5) {
1724115b56afSHariprasad Shenai 			/* Inner header lookup */
1725115b56afSHariprasad Shenai 			if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
1726115b56afSHariprasad Shenai 				seq_printf(seq,
1727115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1728115b56afSHariprasad Shenai 					   "%012llx %06x %06x    -    -   %3c"
172989e7a154SHariprasad Shenai 					   "      'I'  %4x   "
1730115b56afSHariprasad Shenai 					   "%3c   %#x%4u%4d", idx, addr[0],
1731115b56afSHariprasad Shenai 					   addr[1], addr[2], addr[3],
1732115b56afSHariprasad Shenai 					   addr[4], addr[5],
1733115b56afSHariprasad Shenai 					   (unsigned long long)mask,
1734115b56afSHariprasad Shenai 					   vniy, vnix, dip_hit ? 'Y' : 'N',
173589e7a154SHariprasad Shenai 					   port_num,
17363ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
17373ccc6cf7SHariprasad Shenai 					   PORTMAP_G(cls_hi),
17383ccc6cf7SHariprasad Shenai 					   T6_PF_G(cls_lo),
17393ccc6cf7SHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
17403ccc6cf7SHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1741115b56afSHariprasad Shenai 			} else {
1742115b56afSHariprasad Shenai 				seq_printf(seq,
1743115b56afSHariprasad Shenai 					   "%3u %02x:%02x:%02x:%02x:%02x:%02x "
1744115b56afSHariprasad Shenai 					   "%012llx    -       -   ",
1745115b56afSHariprasad Shenai 					   idx, addr[0], addr[1], addr[2],
1746115b56afSHariprasad Shenai 					   addr[3], addr[4], addr[5],
1747115b56afSHariprasad Shenai 					   (unsigned long long)mask);
1748115b56afSHariprasad Shenai 
1749115b56afSHariprasad Shenai 				if (vlan_vld)
1750115b56afSHariprasad Shenai 					seq_printf(seq, "%4u   Y     ", ivlan);
17513ccc6cf7SHariprasad Shenai 				else
1752115b56afSHariprasad Shenai 					seq_puts(seq, "  -    N     ");
1753115b56afSHariprasad Shenai 
1754115b56afSHariprasad Shenai 				seq_printf(seq,
1755115b56afSHariprasad Shenai 					   "-      %3c  %4x   %3c   %#x%4u%4d",
1756115b56afSHariprasad Shenai 					   lookup_type ? 'I' : 'O', port_num,
1757115b56afSHariprasad Shenai 					   (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
1758115b56afSHariprasad Shenai 					   PORTMAP_G(cls_hi),
1759115b56afSHariprasad Shenai 					   T6_PF_G(cls_lo),
1760115b56afSHariprasad Shenai 					   (cls_lo & T6_VF_VALID_F) ?
1761115b56afSHariprasad Shenai 					   T6_VF_G(cls_lo) : -1);
1762115b56afSHariprasad Shenai 			}
1763115b56afSHariprasad Shenai 		} else
17643ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
17653ccc6cf7SHariprasad Shenai 				   "%012llx%3c   %#x%4u%4d",
17663ccc6cf7SHariprasad Shenai 				   idx, addr[0], addr[1], addr[2], addr[3],
17673ccc6cf7SHariprasad Shenai 				   addr[4], addr[5], (unsigned long long)mask,
17683ccc6cf7SHariprasad Shenai 				   (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
17693ccc6cf7SHariprasad Shenai 				   PORTMAP_G(cls_hi),
1770ef82f662SHariprasad Shenai 				   PF_G(cls_lo),
1771ef82f662SHariprasad Shenai 				   (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
17723ccc6cf7SHariprasad Shenai 
17733ccc6cf7SHariprasad Shenai 		if (replicate) {
17743ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
17753ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x "
17763ccc6cf7SHariprasad Shenai 					   "%08x %08x %08x %08x",
17773ccc6cf7SHariprasad Shenai 					   rplc[7], rplc[6], rplc[5], rplc[4],
1778ef82f662SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
1779ef82f662SHariprasad Shenai 			else
17803ccc6cf7SHariprasad Shenai 				seq_printf(seq, " %08x %08x %08x %08x",
17813ccc6cf7SHariprasad Shenai 					   rplc[3], rplc[2], rplc[1], rplc[0]);
17823ccc6cf7SHariprasad Shenai 		} else {
17833ccc6cf7SHariprasad Shenai 			if (adap->params.arch.mps_rplc_size > 128)
17843ccc6cf7SHariprasad Shenai 				seq_printf(seq, "%72c", ' ');
17853ccc6cf7SHariprasad Shenai 			else
1786ef82f662SHariprasad Shenai 				seq_printf(seq, "%36c", ' ');
17873ccc6cf7SHariprasad Shenai 		}
17883ccc6cf7SHariprasad Shenai 
17893ccc6cf7SHariprasad Shenai 		if (chip_ver > CHELSIO_T5)
17903ccc6cf7SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
17913ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO0_G(cls_lo),
17923ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO1_G(cls_lo),
17933ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO2_G(cls_lo),
17943ccc6cf7SHariprasad Shenai 				   T6_SRAM_PRIO3_G(cls_lo),
17953ccc6cf7SHariprasad Shenai 				   (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
17963ccc6cf7SHariprasad Shenai 		else
1797ef82f662SHariprasad Shenai 			seq_printf(seq, "%4u%3u%3u%3u %#x\n",
1798ef82f662SHariprasad Shenai 				   SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
1799ef82f662SHariprasad Shenai 				   SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
1800ef82f662SHariprasad Shenai 				   (cls_lo >> MULTILISTEN0_S) & 0xf);
1801ef82f662SHariprasad Shenai 	}
1802ef82f662SHariprasad Shenai out:	return 0;
1803ef82f662SHariprasad Shenai }
1804ef82f662SHariprasad Shenai 
1805ef82f662SHariprasad Shenai static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
1806ef82f662SHariprasad Shenai {
1807ef82f662SHariprasad Shenai 	struct adapter *adap = seq->private;
1808ef82f662SHariprasad Shenai 	int max_mac_addr = is_t4(adap->params.chip) ?
1809ef82f662SHariprasad Shenai 				NUM_MPS_CLS_SRAM_L_INSTANCES :
1810ef82f662SHariprasad Shenai 				NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
1811ef82f662SHariprasad Shenai 	return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
1812ef82f662SHariprasad Shenai }
1813ef82f662SHariprasad Shenai 
1814ef82f662SHariprasad Shenai static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
1815ef82f662SHariprasad Shenai {
1816ef82f662SHariprasad Shenai 	return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
1817ef82f662SHariprasad Shenai }
1818ef82f662SHariprasad Shenai 
1819ef82f662SHariprasad Shenai static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
1820ef82f662SHariprasad Shenai {
1821ef82f662SHariprasad Shenai 	++*pos;
1822ef82f662SHariprasad Shenai 	return mps_tcam_get_idx(seq, *pos);
1823ef82f662SHariprasad Shenai }
1824ef82f662SHariprasad Shenai 
1825ef82f662SHariprasad Shenai static void mps_tcam_stop(struct seq_file *seq, void *v)
1826ef82f662SHariprasad Shenai {
1827ef82f662SHariprasad Shenai }
1828ef82f662SHariprasad Shenai 
1829ef82f662SHariprasad Shenai static const struct seq_operations mps_tcam_seq_ops = {
1830ef82f662SHariprasad Shenai 	.start = mps_tcam_start,
1831ef82f662SHariprasad Shenai 	.next  = mps_tcam_next,
1832ef82f662SHariprasad Shenai 	.stop  = mps_tcam_stop,
1833ef82f662SHariprasad Shenai 	.show  = mps_tcam_show
1834ef82f662SHariprasad Shenai };
1835ef82f662SHariprasad Shenai 
1836ef82f662SHariprasad Shenai static int mps_tcam_open(struct inode *inode, struct file *file)
1837ef82f662SHariprasad Shenai {
1838ef82f662SHariprasad Shenai 	int res = seq_open(file, &mps_tcam_seq_ops);
1839ef82f662SHariprasad Shenai 
1840ef82f662SHariprasad Shenai 	if (!res) {
1841ef82f662SHariprasad Shenai 		struct seq_file *seq = file->private_data;
1842ef82f662SHariprasad Shenai 
1843ef82f662SHariprasad Shenai 		seq->private = inode->i_private;
1844ef82f662SHariprasad Shenai 	}
1845ef82f662SHariprasad Shenai 	return res;
1846ef82f662SHariprasad Shenai }
1847ef82f662SHariprasad Shenai 
1848ef82f662SHariprasad Shenai static const struct file_operations mps_tcam_debugfs_fops = {
1849ef82f662SHariprasad Shenai 	.owner   = THIS_MODULE,
1850ef82f662SHariprasad Shenai 	.open    = mps_tcam_open,
1851ef82f662SHariprasad Shenai 	.read    = seq_read,
1852ef82f662SHariprasad Shenai 	.llseek  = seq_lseek,
1853ef82f662SHariprasad Shenai 	.release = seq_release,
1854ef82f662SHariprasad Shenai };
1855ef82f662SHariprasad Shenai 
185670a5f3bbSHariprasad Shenai /* Display various sensor information.
185770a5f3bbSHariprasad Shenai  */
185870a5f3bbSHariprasad Shenai static int sensors_show(struct seq_file *seq, void *v)
185970a5f3bbSHariprasad Shenai {
186070a5f3bbSHariprasad Shenai 	struct adapter *adap = seq->private;
186170a5f3bbSHariprasad Shenai 	u32 param[7], val[7];
186270a5f3bbSHariprasad Shenai 	int ret;
186370a5f3bbSHariprasad Shenai 
186470a5f3bbSHariprasad Shenai 	/* Note that if the sensors haven't been initialized and turned on
186570a5f3bbSHariprasad Shenai 	 * we'll get values of 0, so treat those as "<unknown>" ...
186670a5f3bbSHariprasad Shenai 	 */
186770a5f3bbSHariprasad Shenai 	param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
186870a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
186970a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
187070a5f3bbSHariprasad Shenai 	param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
187170a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
187270a5f3bbSHariprasad Shenai 		    FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
1873b2612722SHariprasad Shenai 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
187470a5f3bbSHariprasad Shenai 			      param, val);
187570a5f3bbSHariprasad Shenai 
187670a5f3bbSHariprasad Shenai 	if (ret < 0 || val[0] == 0)
187770a5f3bbSHariprasad Shenai 		seq_puts(seq, "Temperature: <unknown>\n");
187870a5f3bbSHariprasad Shenai 	else
187970a5f3bbSHariprasad Shenai 		seq_printf(seq, "Temperature: %dC\n", val[0]);
188070a5f3bbSHariprasad Shenai 
188170a5f3bbSHariprasad Shenai 	if (ret < 0 || val[1] == 0)
188270a5f3bbSHariprasad Shenai 		seq_puts(seq, "Core VDD:    <unknown>\n");
188370a5f3bbSHariprasad Shenai 	else
188470a5f3bbSHariprasad Shenai 		seq_printf(seq, "Core VDD:    %dmV\n", val[1]);
188570a5f3bbSHariprasad Shenai 
188670a5f3bbSHariprasad Shenai 	return 0;
188770a5f3bbSHariprasad Shenai }
188870a5f3bbSHariprasad Shenai 
188970a5f3bbSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
189070a5f3bbSHariprasad Shenai 
1891b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
1892b5a02f50SAnish Bhatt static int clip_tbl_open(struct inode *inode, struct file *file)
1893b5a02f50SAnish Bhatt {
1894acde2c2dSHariprasad Shenai 	return single_open(file, clip_tbl_show, inode->i_private);
1895b5a02f50SAnish Bhatt }
1896b5a02f50SAnish Bhatt 
1897b5a02f50SAnish Bhatt static const struct file_operations clip_tbl_debugfs_fops = {
1898b5a02f50SAnish Bhatt 	.owner   = THIS_MODULE,
1899b5a02f50SAnish Bhatt 	.open    = clip_tbl_open,
1900b5a02f50SAnish Bhatt 	.read    = seq_read,
1901b5a02f50SAnish Bhatt 	.llseek  = seq_lseek,
1902b5a02f50SAnish Bhatt 	.release = single_release
1903b5a02f50SAnish Bhatt };
1904b5a02f50SAnish Bhatt #endif
1905b5a02f50SAnish Bhatt 
1906688ea5feSHariprasad Shenai /*RSS Table.
1907688ea5feSHariprasad Shenai  */
1908688ea5feSHariprasad Shenai 
1909688ea5feSHariprasad Shenai static int rss_show(struct seq_file *seq, void *v, int idx)
1910688ea5feSHariprasad Shenai {
1911688ea5feSHariprasad Shenai 	u16 *entry = v;
1912688ea5feSHariprasad Shenai 
1913688ea5feSHariprasad Shenai 	seq_printf(seq, "%4d:  %4u  %4u  %4u  %4u  %4u  %4u  %4u  %4u\n",
1914688ea5feSHariprasad Shenai 		   idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
1915688ea5feSHariprasad Shenai 		   entry[5], entry[6], entry[7]);
1916688ea5feSHariprasad Shenai 	return 0;
1917688ea5feSHariprasad Shenai }
1918688ea5feSHariprasad Shenai 
1919688ea5feSHariprasad Shenai static int rss_open(struct inode *inode, struct file *file)
1920688ea5feSHariprasad Shenai {
1921688ea5feSHariprasad Shenai 	int ret;
1922688ea5feSHariprasad Shenai 	struct seq_tab *p;
1923688ea5feSHariprasad Shenai 	struct adapter *adap = inode->i_private;
1924688ea5feSHariprasad Shenai 
1925688ea5feSHariprasad Shenai 	p = seq_open_tab(file, RSS_NENTRIES / 8, 8 * sizeof(u16), 0, rss_show);
1926688ea5feSHariprasad Shenai 	if (!p)
1927688ea5feSHariprasad Shenai 		return -ENOMEM;
1928688ea5feSHariprasad Shenai 
1929688ea5feSHariprasad Shenai 	ret = t4_read_rss(adap, (u16 *)p->data);
1930688ea5feSHariprasad Shenai 	if (ret)
1931688ea5feSHariprasad Shenai 		seq_release_private(inode, file);
1932688ea5feSHariprasad Shenai 
1933688ea5feSHariprasad Shenai 	return ret;
1934688ea5feSHariprasad Shenai }
1935688ea5feSHariprasad Shenai 
1936688ea5feSHariprasad Shenai static const struct file_operations rss_debugfs_fops = {
1937688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
1938688ea5feSHariprasad Shenai 	.open    = rss_open,
1939688ea5feSHariprasad Shenai 	.read    = seq_read,
1940688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
1941688ea5feSHariprasad Shenai 	.release = seq_release_private
1942688ea5feSHariprasad Shenai };
1943688ea5feSHariprasad Shenai 
1944688ea5feSHariprasad Shenai /* RSS Configuration.
1945688ea5feSHariprasad Shenai  */
1946688ea5feSHariprasad Shenai 
1947688ea5feSHariprasad Shenai /* Small utility function to return the strings "yes" or "no" if the supplied
1948688ea5feSHariprasad Shenai  * argument is non-zero.
1949688ea5feSHariprasad Shenai  */
1950688ea5feSHariprasad Shenai static const char *yesno(int x)
1951688ea5feSHariprasad Shenai {
1952688ea5feSHariprasad Shenai 	static const char *yes = "yes";
1953688ea5feSHariprasad Shenai 	static const char *no = "no";
1954688ea5feSHariprasad Shenai 
1955688ea5feSHariprasad Shenai 	return x ? yes : no;
1956688ea5feSHariprasad Shenai }
1957688ea5feSHariprasad Shenai 
1958688ea5feSHariprasad Shenai static int rss_config_show(struct seq_file *seq, void *v)
1959688ea5feSHariprasad Shenai {
1960688ea5feSHariprasad Shenai 	struct adapter *adapter = seq->private;
1961688ea5feSHariprasad Shenai 	static const char * const keymode[] = {
1962688ea5feSHariprasad Shenai 		"global",
1963688ea5feSHariprasad Shenai 		"global and per-VF scramble",
1964688ea5feSHariprasad Shenai 		"per-PF and per-VF scramble",
1965688ea5feSHariprasad Shenai 		"per-VF and per-VF scramble",
1966688ea5feSHariprasad Shenai 	};
1967688ea5feSHariprasad Shenai 	u32 rssconf;
1968688ea5feSHariprasad Shenai 
1969688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
1970688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
1971688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
1972688ea5feSHariprasad Shenai 							TNL4TUPENIPV6_F));
1973688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
1974688ea5feSHariprasad Shenai 							TNL2TUPENIPV6_F));
1975688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
1976688ea5feSHariprasad Shenai 							TNL4TUPENIPV4_F));
1977688ea5feSHariprasad Shenai 	seq_printf(seq, "  Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
1978688ea5feSHariprasad Shenai 							TNL2TUPENIPV4_F));
1979688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlTcpSel:     %3s\n", yesno(rssconf & TNLTCPSEL_F));
1980688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlIp6Sel:     %3s\n", yesno(rssconf & TNLIP6SEL_F));
1981688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlVrtSel:     %3s\n", yesno(rssconf & TNLVRTSEL_F));
1982688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlMapEn:      %3s\n", yesno(rssconf & TNLMAPEN_F));
1983688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdHashSave:   %3s\n", yesno(rssconf &
1984688ea5feSHariprasad Shenai 							OFDHASHSAVE_F));
1985688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdVrtSel:     %3s\n", yesno(rssconf & OFDVRTSEL_F));
1986688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdMapEn:      %3s\n", yesno(rssconf & OFDMAPEN_F));
1987688ea5feSHariprasad Shenai 	seq_printf(seq, "  OfdLkpEn:      %3s\n", yesno(rssconf & OFDLKPEN_F));
1988688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1989688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
1990688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv6: %3s\n", yesno(rssconf &
1991688ea5feSHariprasad Shenai 							SYN2TUPENIPV6_F));
1992688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv4: %3s\n", yesno(rssconf &
1993688ea5feSHariprasad Shenai 							SYN4TUPENIPV4_F));
1994688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn2TupEnIpv4: %3s\n", yesno(rssconf &
1995688ea5feSHariprasad Shenai 							SYN2TUPENIPV4_F));
1996688ea5feSHariprasad Shenai 	seq_printf(seq, "  Syn4TupEnIpv6: %3s\n", yesno(rssconf &
1997688ea5feSHariprasad Shenai 							SYN4TUPENIPV6_F));
1998688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynIp6Sel:     %3s\n", yesno(rssconf & SYNIP6SEL_F));
1999688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynVrt6Sel:    %3s\n", yesno(rssconf & SYNVRTSEL_F));
2000688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynMapEn:      %3s\n", yesno(rssconf & SYNMAPEN_F));
2001688ea5feSHariprasad Shenai 	seq_printf(seq, "  SynLkpEn:      %3s\n", yesno(rssconf & SYNLKPEN_F));
2002688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnEn:         %3s\n", yesno(rssconf &
2003688ea5feSHariprasad Shenai 							CHANNELENABLE_F));
2004688ea5feSHariprasad Shenai 	seq_printf(seq, "  PrtEn:         %3s\n", yesno(rssconf &
2005688ea5feSHariprasad Shenai 							PORTENABLE_F));
2006688ea5feSHariprasad Shenai 	seq_printf(seq, "  TnlAllLkp:     %3s\n", yesno(rssconf &
2007688ea5feSHariprasad Shenai 							TNLALLLOOKUP_F));
2008688ea5feSHariprasad Shenai 	seq_printf(seq, "  VrtEn:         %3s\n", yesno(rssconf &
2009688ea5feSHariprasad Shenai 							VIRTENABLE_F));
2010688ea5feSHariprasad Shenai 	seq_printf(seq, "  CngEn:         %3s\n", yesno(rssconf &
2011688ea5feSHariprasad Shenai 							CONGESTIONENABLE_F));
2012688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashToeplitz:  %3s\n", yesno(rssconf &
2013688ea5feSHariprasad Shenai 							HASHTOEPLITZ_F));
2014688ea5feSHariprasad Shenai 	seq_printf(seq, "  Udp4En:        %3s\n", yesno(rssconf & UDPENABLE_F));
2015688ea5feSHariprasad Shenai 	seq_printf(seq, "  Disable:       %3s\n", yesno(rssconf & DISABLE_F));
2016688ea5feSHariprasad Shenai 
2017688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2018688ea5feSHariprasad Shenai 
2019688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
2020688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
2021688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2022688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskFilter:    %3d\n", MASKFILTER_G(rssconf));
2023688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2024688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashAll:     %3s\n",
2025688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHALL_F));
2026688ea5feSHariprasad Shenai 		seq_printf(seq, "  HashEth:     %3s\n",
2027688ea5feSHariprasad Shenai 			   yesno(rssconf & HASHETH_F));
2028688ea5feSHariprasad Shenai 	}
2029688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2030688ea5feSHariprasad Shenai 
2031688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2032688ea5feSHariprasad Shenai 
2033688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
2034688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
2035688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2036688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplMapEn:    %3s\n", yesno(rssconf &
2037688ea5feSHariprasad Shenai 							RRCPLMAPEN_F));
2038688ea5feSHariprasad Shenai 	seq_printf(seq, "  RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
2039688ea5feSHariprasad Shenai 
2040688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2041688ea5feSHariprasad Shenai 
2042688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
2043688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
2044688ea5feSHariprasad Shenai 	seq_printf(seq, "  MaskSize:      %3d\n", MASKSIZE_G(rssconf));
2045688ea5feSHariprasad Shenai 	seq_printf(seq, "  UseWireCh:     %3s\n", yesno(rssconf & USEWIRECH_F));
2046688ea5feSHariprasad Shenai 
2047688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2048688ea5feSHariprasad Shenai 
2049688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
2050688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
2051688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
2052688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyWrAddrX:     %3d\n",
2053688ea5feSHariprasad Shenai 			   KEYWRADDRX_G(rssconf));
2054688ea5feSHariprasad Shenai 		seq_printf(seq, "  KeyExtend:      %3s\n",
2055688ea5feSHariprasad Shenai 			   yesno(rssconf & KEYEXTEND_F));
2056688ea5feSHariprasad Shenai 	}
2057688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdRg:        %3s\n", yesno(rssconf & VFRDRG_F));
2058688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfRdEn:        %3s\n", yesno(rssconf & VFRDEN_F));
2059688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfPerrEn:      %3s\n", yesno(rssconf & VFPERREN_F));
2060688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyPerrEn:     %3s\n", yesno(rssconf & KEYPERREN_F));
2061688ea5feSHariprasad Shenai 	seq_printf(seq, "  DisVfVlan:     %3s\n", yesno(rssconf &
2062688ea5feSHariprasad Shenai 							DISABLEVLAN_F));
2063688ea5feSHariprasad Shenai 	seq_printf(seq, "  EnUpSwt:       %3s\n", yesno(rssconf & ENABLEUP0_F));
2064688ea5feSHariprasad Shenai 	seq_printf(seq, "  HashDelay:     %3d\n", HASHDELAY_G(rssconf));
2065688ea5feSHariprasad Shenai 	if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
2066688ea5feSHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n", VFWRADDR_G(rssconf));
20673ccc6cf7SHariprasad Shenai 	else
20683ccc6cf7SHariprasad Shenai 		seq_printf(seq, "  VfWrAddr:      %3d\n",
20693ccc6cf7SHariprasad Shenai 			   T6_VFWRADDR_G(rssconf));
2070688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyMode:       %s\n", keymode[KEYMODE_G(rssconf)]);
2071688ea5feSHariprasad Shenai 	seq_printf(seq, "  VfWrEn:        %3s\n", yesno(rssconf & VFWREN_F));
2072688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrEn:       %3s\n", yesno(rssconf & KEYWREN_F));
2073688ea5feSHariprasad Shenai 	seq_printf(seq, "  KeyWrAddr:     %3d\n", KEYWRADDR_G(rssconf));
2074688ea5feSHariprasad Shenai 
2075688ea5feSHariprasad Shenai 	seq_puts(seq, "\n");
2076688ea5feSHariprasad Shenai 
2077688ea5feSHariprasad Shenai 	rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
2078688ea5feSHariprasad Shenai 	seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
2079688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount3:     %3s\n", yesno(rssconf & CHNCOUNT3_F));
2080688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount2:     %3s\n", yesno(rssconf & CHNCOUNT2_F));
2081688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount1:     %3s\n", yesno(rssconf & CHNCOUNT1_F));
2082688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnCount0:     %3s\n", yesno(rssconf & CHNCOUNT0_F));
2083688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow3:   %3s\n", yesno(rssconf &
2084688ea5feSHariprasad Shenai 							CHNUNDFLOW3_F));
2085688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow2:   %3s\n", yesno(rssconf &
2086688ea5feSHariprasad Shenai 							CHNUNDFLOW2_F));
2087688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow1:   %3s\n", yesno(rssconf &
2088688ea5feSHariprasad Shenai 							CHNUNDFLOW1_F));
2089688ea5feSHariprasad Shenai 	seq_printf(seq, "  ChnUndFlow0:   %3s\n", yesno(rssconf &
2090688ea5feSHariprasad Shenai 							CHNUNDFLOW0_F));
2091688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn3:       %3s\n", yesno(rssconf & RSTCHN3_F));
2092688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn2:       %3s\n", yesno(rssconf & RSTCHN2_F));
2093688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn1:       %3s\n", yesno(rssconf & RSTCHN1_F));
2094688ea5feSHariprasad Shenai 	seq_printf(seq, "  RstChn0:       %3s\n", yesno(rssconf & RSTCHN0_F));
2095688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdVld:        %3s\n", yesno(rssconf & UPDVLD_F));
2096688ea5feSHariprasad Shenai 	seq_printf(seq, "  Xoff:          %3s\n", yesno(rssconf & XOFF_F));
2097688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn3:       %3s\n", yesno(rssconf & UPDCHN3_F));
2098688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn2:       %3s\n", yesno(rssconf & UPDCHN2_F));
2099688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn1:       %3s\n", yesno(rssconf & UPDCHN1_F));
2100688ea5feSHariprasad Shenai 	seq_printf(seq, "  UpdChn0:       %3s\n", yesno(rssconf & UPDCHN0_F));
2101688ea5feSHariprasad Shenai 	seq_printf(seq, "  Queue:         %3d\n", QUEUE_G(rssconf));
2102688ea5feSHariprasad Shenai 
2103688ea5feSHariprasad Shenai 	return 0;
2104688ea5feSHariprasad Shenai }
2105688ea5feSHariprasad Shenai 
2106688ea5feSHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
2107688ea5feSHariprasad Shenai 
2108688ea5feSHariprasad Shenai /* RSS Secret Key.
2109688ea5feSHariprasad Shenai  */
2110688ea5feSHariprasad Shenai 
2111688ea5feSHariprasad Shenai static int rss_key_show(struct seq_file *seq, void *v)
2112688ea5feSHariprasad Shenai {
2113688ea5feSHariprasad Shenai 	u32 key[10];
2114688ea5feSHariprasad Shenai 
2115688ea5feSHariprasad Shenai 	t4_read_rss_key(seq->private, key);
2116688ea5feSHariprasad Shenai 	seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
2117688ea5feSHariprasad Shenai 		   key[9], key[8], key[7], key[6], key[5], key[4], key[3],
2118688ea5feSHariprasad Shenai 		   key[2], key[1], key[0]);
2119688ea5feSHariprasad Shenai 	return 0;
2120688ea5feSHariprasad Shenai }
2121688ea5feSHariprasad Shenai 
2122688ea5feSHariprasad Shenai static int rss_key_open(struct inode *inode, struct file *file)
2123688ea5feSHariprasad Shenai {
2124688ea5feSHariprasad Shenai 	return single_open(file, rss_key_show, inode->i_private);
2125688ea5feSHariprasad Shenai }
2126688ea5feSHariprasad Shenai 
2127688ea5feSHariprasad Shenai static ssize_t rss_key_write(struct file *file, const char __user *buf,
2128688ea5feSHariprasad Shenai 			     size_t count, loff_t *pos)
2129688ea5feSHariprasad Shenai {
2130688ea5feSHariprasad Shenai 	int i, j;
2131688ea5feSHariprasad Shenai 	u32 key[10];
2132688ea5feSHariprasad Shenai 	char s[100], *p;
2133c1d81b1cSDavid Howells 	struct adapter *adap = file_inode(file)->i_private;
2134688ea5feSHariprasad Shenai 
2135688ea5feSHariprasad Shenai 	if (count > sizeof(s) - 1)
2136688ea5feSHariprasad Shenai 		return -EINVAL;
2137688ea5feSHariprasad Shenai 	if (copy_from_user(s, buf, count))
2138688ea5feSHariprasad Shenai 		return -EFAULT;
2139688ea5feSHariprasad Shenai 	for (i = count; i > 0 && isspace(s[i - 1]); i--)
2140688ea5feSHariprasad Shenai 		;
2141688ea5feSHariprasad Shenai 	s[i] = '\0';
2142688ea5feSHariprasad Shenai 
2143688ea5feSHariprasad Shenai 	for (p = s, i = 9; i >= 0; i--) {
2144688ea5feSHariprasad Shenai 		key[i] = 0;
2145688ea5feSHariprasad Shenai 		for (j = 0; j < 8; j++, p++) {
2146688ea5feSHariprasad Shenai 			if (!isxdigit(*p))
2147688ea5feSHariprasad Shenai 				return -EINVAL;
2148688ea5feSHariprasad Shenai 			key[i] = (key[i] << 4) | hex2val(*p);
2149688ea5feSHariprasad Shenai 		}
2150688ea5feSHariprasad Shenai 	}
2151688ea5feSHariprasad Shenai 
2152688ea5feSHariprasad Shenai 	t4_write_rss_key(adap, key, -1);
2153688ea5feSHariprasad Shenai 	return count;
2154688ea5feSHariprasad Shenai }
2155688ea5feSHariprasad Shenai 
2156688ea5feSHariprasad Shenai static const struct file_operations rss_key_debugfs_fops = {
2157688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2158688ea5feSHariprasad Shenai 	.open    = rss_key_open,
2159688ea5feSHariprasad Shenai 	.read    = seq_read,
2160688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2161688ea5feSHariprasad Shenai 	.release = single_release,
2162688ea5feSHariprasad Shenai 	.write   = rss_key_write
2163688ea5feSHariprasad Shenai };
2164688ea5feSHariprasad Shenai 
2165688ea5feSHariprasad Shenai /* PF RSS Configuration.
2166688ea5feSHariprasad Shenai  */
2167688ea5feSHariprasad Shenai 
2168688ea5feSHariprasad Shenai struct rss_pf_conf {
2169688ea5feSHariprasad Shenai 	u32 rss_pf_map;
2170688ea5feSHariprasad Shenai 	u32 rss_pf_mask;
2171688ea5feSHariprasad Shenai 	u32 rss_pf_config;
2172688ea5feSHariprasad Shenai };
2173688ea5feSHariprasad Shenai 
2174688ea5feSHariprasad Shenai static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
2175688ea5feSHariprasad Shenai {
2176688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2177688ea5feSHariprasad Shenai 
2178688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2179688ea5feSHariprasad Shenai 		/* use the 0th entry to dump the PF Map Index Size */
2180688ea5feSHariprasad Shenai 		pfconf = seq->private + offsetof(struct seq_tab, data);
2181688ea5feSHariprasad Shenai 		seq_printf(seq, "PF Map Index Size = %d\n\n",
2182688ea5feSHariprasad Shenai 			   LKPIDXSIZE_G(pfconf->rss_pf_map));
2183688ea5feSHariprasad Shenai 
2184688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS              PF   VF    Hash Tuple Enable         Default\n");
2185688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable       IPF Mask Mask  IPv6      IPv4      UDP   Queue\n");
2186688ea5feSHariprasad Shenai 		seq_puts(seq, " PF  Map Chn Prt  Map Size Size  Four Two  Four Two  Four  Ch1  Ch0\n");
2187688ea5feSHariprasad Shenai 	} else {
2188688ea5feSHariprasad Shenai 		#define G_PFnLKPIDX(map, n) \
2189688ea5feSHariprasad Shenai 			(((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
2190688ea5feSHariprasad Shenai 		#define G_PFnMSKSIZE(mask, n) \
2191688ea5feSHariprasad Shenai 			(((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
2192688ea5feSHariprasad Shenai 
2193688ea5feSHariprasad Shenai 		pfconf = v;
2194688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s %3s  %3d  %3d  %3d   %3s %3s   %3s %3s   %3s  %3d  %3d\n",
2195688ea5feSHariprasad Shenai 			   idx,
2196688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & MAPENABLE_F),
2197688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & CHNENABLE_F),
2198688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & PRTENABLE_F),
2199688ea5feSHariprasad Shenai 			   G_PFnLKPIDX(pfconf->rss_pf_map, idx),
2200688ea5feSHariprasad Shenai 			   G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
2201688ea5feSHariprasad Shenai 			   IVFWIDTH_G(pfconf->rss_pf_config),
2202688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
2203688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
2204688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
2205688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
2206688ea5feSHariprasad Shenai 			   yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
2207688ea5feSHariprasad Shenai 			   CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
2208688ea5feSHariprasad Shenai 			   CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
2209688ea5feSHariprasad Shenai 
2210688ea5feSHariprasad Shenai 		#undef G_PFnLKPIDX
2211688ea5feSHariprasad Shenai 		#undef G_PFnMSKSIZE
2212688ea5feSHariprasad Shenai 	}
2213688ea5feSHariprasad Shenai 	return 0;
2214688ea5feSHariprasad Shenai }
2215688ea5feSHariprasad Shenai 
2216688ea5feSHariprasad Shenai static int rss_pf_config_open(struct inode *inode, struct file *file)
2217688ea5feSHariprasad Shenai {
2218688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2219688ea5feSHariprasad Shenai 	struct seq_tab *p;
2220688ea5feSHariprasad Shenai 	u32 rss_pf_map, rss_pf_mask;
2221688ea5feSHariprasad Shenai 	struct rss_pf_conf *pfconf;
2222688ea5feSHariprasad Shenai 	int pf;
2223688ea5feSHariprasad Shenai 
2224688ea5feSHariprasad Shenai 	p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
2225688ea5feSHariprasad Shenai 	if (!p)
2226688ea5feSHariprasad Shenai 		return -ENOMEM;
2227688ea5feSHariprasad Shenai 
2228688ea5feSHariprasad Shenai 	pfconf = (struct rss_pf_conf *)p->data;
2229688ea5feSHariprasad Shenai 	rss_pf_map = t4_read_rss_pf_map(adapter);
2230688ea5feSHariprasad Shenai 	rss_pf_mask = t4_read_rss_pf_mask(adapter);
2231688ea5feSHariprasad Shenai 	for (pf = 0; pf < 8; pf++) {
2232688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_map = rss_pf_map;
2233688ea5feSHariprasad Shenai 		pfconf[pf].rss_pf_mask = rss_pf_mask;
2234688ea5feSHariprasad Shenai 		t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config);
2235688ea5feSHariprasad Shenai 	}
2236688ea5feSHariprasad Shenai 	return 0;
2237688ea5feSHariprasad Shenai }
2238688ea5feSHariprasad Shenai 
2239688ea5feSHariprasad Shenai static const struct file_operations rss_pf_config_debugfs_fops = {
2240688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2241688ea5feSHariprasad Shenai 	.open    = rss_pf_config_open,
2242688ea5feSHariprasad Shenai 	.read    = seq_read,
2243688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2244688ea5feSHariprasad Shenai 	.release = seq_release_private
2245688ea5feSHariprasad Shenai };
2246688ea5feSHariprasad Shenai 
2247688ea5feSHariprasad Shenai /* VF RSS Configuration.
2248688ea5feSHariprasad Shenai  */
2249688ea5feSHariprasad Shenai 
2250688ea5feSHariprasad Shenai struct rss_vf_conf {
2251688ea5feSHariprasad Shenai 	u32 rss_vf_vfl;
2252688ea5feSHariprasad Shenai 	u32 rss_vf_vfh;
2253688ea5feSHariprasad Shenai };
2254688ea5feSHariprasad Shenai 
2255688ea5feSHariprasad Shenai static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
2256688ea5feSHariprasad Shenai {
2257688ea5feSHariprasad Shenai 	if (v == SEQ_START_TOKEN) {
2258688ea5feSHariprasad Shenai 		seq_puts(seq, "     RSS                     Hash Tuple Enable\n");
2259688ea5feSHariprasad Shenai 		seq_puts(seq, "     Enable   IVF  Dis  Enb  IPv6      IPv4      UDP    Def  Secret Key\n");
2260688ea5feSHariprasad Shenai 		seq_puts(seq, " VF  Chn Prt  Map  VLAN  uP  Four Two  Four Two  Four   Que  Idx       Hash\n");
2261688ea5feSHariprasad Shenai 	} else {
2262688ea5feSHariprasad Shenai 		struct rss_vf_conf *vfconf = v;
2263688ea5feSHariprasad Shenai 
2264688ea5feSHariprasad Shenai 		seq_printf(seq, "%3d  %3s %3s  %3d   %3s %3s   %3s %3s   %3s  %3s   %3s  %4d  %3d %#10x\n",
2265688ea5feSHariprasad Shenai 			   idx,
2266688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
2267688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
2268688ea5feSHariprasad Shenai 			   VFLKPIDX_G(vfconf->rss_vf_vfh),
2269688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
2270688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFUPEN_F),
2271688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2272688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
2273688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
2274688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
2275688ea5feSHariprasad Shenai 			   yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
2276688ea5feSHariprasad Shenai 			   DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
2277688ea5feSHariprasad Shenai 			   KEYINDEX_G(vfconf->rss_vf_vfh),
2278688ea5feSHariprasad Shenai 			   vfconf->rss_vf_vfl);
2279688ea5feSHariprasad Shenai 	}
2280688ea5feSHariprasad Shenai 	return 0;
2281688ea5feSHariprasad Shenai }
2282688ea5feSHariprasad Shenai 
2283688ea5feSHariprasad Shenai static int rss_vf_config_open(struct inode *inode, struct file *file)
2284688ea5feSHariprasad Shenai {
2285688ea5feSHariprasad Shenai 	struct adapter *adapter = inode->i_private;
2286688ea5feSHariprasad Shenai 	struct seq_tab *p;
2287688ea5feSHariprasad Shenai 	struct rss_vf_conf *vfconf;
22883ccc6cf7SHariprasad Shenai 	int vf, vfcount = adapter->params.arch.vfcount;
2289688ea5feSHariprasad Shenai 
22903ccc6cf7SHariprasad Shenai 	p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
2291688ea5feSHariprasad Shenai 	if (!p)
2292688ea5feSHariprasad Shenai 		return -ENOMEM;
2293688ea5feSHariprasad Shenai 
2294688ea5feSHariprasad Shenai 	vfconf = (struct rss_vf_conf *)p->data;
22953ccc6cf7SHariprasad Shenai 	for (vf = 0; vf < vfcount; vf++) {
2296688ea5feSHariprasad Shenai 		t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
2297688ea5feSHariprasad Shenai 				      &vfconf[vf].rss_vf_vfh);
2298688ea5feSHariprasad Shenai 	}
2299688ea5feSHariprasad Shenai 	return 0;
2300688ea5feSHariprasad Shenai }
2301688ea5feSHariprasad Shenai 
2302688ea5feSHariprasad Shenai static const struct file_operations rss_vf_config_debugfs_fops = {
2303688ea5feSHariprasad Shenai 	.owner   = THIS_MODULE,
2304688ea5feSHariprasad Shenai 	.open    = rss_vf_config_open,
2305688ea5feSHariprasad Shenai 	.read    = seq_read,
2306688ea5feSHariprasad Shenai 	.llseek  = seq_lseek,
2307688ea5feSHariprasad Shenai 	.release = seq_release_private
2308688ea5feSHariprasad Shenai };
2309688ea5feSHariprasad Shenai 
23103051fa61SHariprasad Shenai /**
23113051fa61SHariprasad Shenai  * ethqset2pinfo - return port_info of an Ethernet Queue Set
23123051fa61SHariprasad Shenai  * @adap: the adapter
23133051fa61SHariprasad Shenai  * @qset: Ethernet Queue Set
23143051fa61SHariprasad Shenai  */
23153051fa61SHariprasad Shenai static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
23163051fa61SHariprasad Shenai {
23173051fa61SHariprasad Shenai 	int pidx;
23183051fa61SHariprasad Shenai 
23193051fa61SHariprasad Shenai 	for_each_port(adap, pidx) {
23203051fa61SHariprasad Shenai 		struct port_info *pi = adap2pinfo(adap, pidx);
23213051fa61SHariprasad Shenai 
23223051fa61SHariprasad Shenai 		if (qset >= pi->first_qset &&
23233051fa61SHariprasad Shenai 		    qset < pi->first_qset + pi->nqsets)
23243051fa61SHariprasad Shenai 			return pi;
23253051fa61SHariprasad Shenai 	}
23263051fa61SHariprasad Shenai 
23273051fa61SHariprasad Shenai 	/* should never happen! */
23283051fa61SHariprasad Shenai 	BUG_ON(1);
23293051fa61SHariprasad Shenai 	return NULL;
23303051fa61SHariprasad Shenai }
23313051fa61SHariprasad Shenai 
2332dc9daab2SHariprasad Shenai static int sge_qinfo_show(struct seq_file *seq, void *v)
2333dc9daab2SHariprasad Shenai {
2334dc9daab2SHariprasad Shenai 	struct adapter *adap = seq->private;
2335dc9daab2SHariprasad Shenai 	int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
2336f90ce561SHariprasad Shenai 	int iscsi_entries = DIV_ROUND_UP(adap->sge.iscsiqsets, 4);
2337f2692d16SVarun Prakash 	int iscsit_entries = DIV_ROUND_UP(adap->sge.niscsitq, 4);
2338dc9daab2SHariprasad Shenai 	int rdma_entries = DIV_ROUND_UP(adap->sge.rdmaqs, 4);
2339dc9daab2SHariprasad Shenai 	int ciq_entries = DIV_ROUND_UP(adap->sge.rdmaciqs, 4);
2340dc9daab2SHariprasad Shenai 	int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
2341dc9daab2SHariprasad Shenai 	int i, r = (uintptr_t)v - 1;
2342e106a4d9SHariprasad Shenai 	int iscsi_idx = r - eth_entries;
2343f2692d16SVarun Prakash 	int iscsit_idx = iscsi_idx - iscsi_entries;
2344f2692d16SVarun Prakash 	int rdma_idx = iscsit_idx - iscsit_entries;
2345dc9daab2SHariprasad Shenai 	int ciq_idx = rdma_idx - rdma_entries;
2346dc9daab2SHariprasad Shenai 	int ctrl_idx =  ciq_idx - ciq_entries;
2347dc9daab2SHariprasad Shenai 	int fq_idx =  ctrl_idx - ctrl_entries;
2348dc9daab2SHariprasad Shenai 
2349dc9daab2SHariprasad Shenai 	if (r)
2350dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n');
2351dc9daab2SHariprasad Shenai 
2352dc9daab2SHariprasad Shenai #define S3(fmt_spec, s, v) \
2353dc9daab2SHariprasad Shenai do { \
2354dc9daab2SHariprasad Shenai 	seq_printf(seq, "%-12s", s); \
2355dc9daab2SHariprasad Shenai 	for (i = 0; i < n; ++i) \
2356dc9daab2SHariprasad Shenai 		seq_printf(seq, " %16" fmt_spec, v); \
2357dc9daab2SHariprasad Shenai 		seq_putc(seq, '\n'); \
2358dc9daab2SHariprasad Shenai } while (0)
2359dc9daab2SHariprasad Shenai #define S(s, v) S3("s", s, v)
2360e106a4d9SHariprasad Shenai #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
2361dc9daab2SHariprasad Shenai #define T(s, v) S3("u", s, tx[i].v)
2362e106a4d9SHariprasad Shenai #define TL(s, v) T3("lu", s, v)
2363e106a4d9SHariprasad Shenai #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
2364dc9daab2SHariprasad Shenai #define R(s, v) S3("u", s, rx[i].v)
2365e106a4d9SHariprasad Shenai #define RL(s, v) R3("lu", s, v)
2366dc9daab2SHariprasad Shenai 
2367dc9daab2SHariprasad Shenai 	if (r < eth_entries) {
2368dc9daab2SHariprasad Shenai 		int base_qset = r * 4;
2369dc9daab2SHariprasad Shenai 		const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
2370dc9daab2SHariprasad Shenai 		const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
2371dc9daab2SHariprasad Shenai 		int n = min(4, adap->sge.ethqsets - 4 * r);
2372dc9daab2SHariprasad Shenai 
2373dc9daab2SHariprasad Shenai 		S("QType:", "Ethernet");
2374dc9daab2SHariprasad Shenai 		S("Interface:",
2375dc9daab2SHariprasad Shenai 		  rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2376dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2377dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2378dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2379dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2380dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
23813051fa61SHariprasad Shenai #ifdef CONFIG_CHELSIO_T4_DCB
2382dc9daab2SHariprasad Shenai 		T("DCB Prio:", dcb_prio);
2383dc9daab2SHariprasad Shenai 		S3("u", "DCB PGID:",
2384dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
2385dc9daab2SHariprasad Shenai 		    4*(7-tx[i].dcb_prio)) & 0xf);
2386dc9daab2SHariprasad Shenai 		S3("u", "DCB PFC:",
2387dc9daab2SHariprasad Shenai 		   (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
2388dc9daab2SHariprasad Shenai 		    1*(7-tx[i].dcb_prio)) & 0x1);
2389dc9daab2SHariprasad Shenai #endif
2390dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2391dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2392dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2393dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2394dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2395dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2396dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2397dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2398dc9daab2SHariprasad Shenai 		R("FL ID:", fl.cntxt_id);
2399dc9daab2SHariprasad Shenai 		R("FL size:", fl.size - 8);
2400dc9daab2SHariprasad Shenai 		R("FL pend:", fl.pend_cred);
2401dc9daab2SHariprasad Shenai 		R("FL avail:", fl.avail);
2402dc9daab2SHariprasad Shenai 		R("FL PIDX:", fl.pidx);
2403dc9daab2SHariprasad Shenai 		R("FL CIDX:", fl.cidx);
2404e106a4d9SHariprasad Shenai 		RL("RxPackets:", stats.pkts);
2405e106a4d9SHariprasad Shenai 		RL("RxCSO:", stats.rx_cso);
2406e106a4d9SHariprasad Shenai 		RL("VLANxtract:", stats.vlan_ex);
2407e106a4d9SHariprasad Shenai 		RL("LROmerged:", stats.lro_merged);
2408e106a4d9SHariprasad Shenai 		RL("LROpackets:", stats.lro_pkts);
2409e106a4d9SHariprasad Shenai 		RL("RxDrops:", stats.rx_drops);
2410e106a4d9SHariprasad Shenai 		TL("TSO:", tso);
2411e106a4d9SHariprasad Shenai 		TL("TxCSO:", tx_cso);
2412e106a4d9SHariprasad Shenai 		TL("VLANins:", vlan_ins);
2413e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2414e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2415e106a4d9SHariprasad Shenai 		TL("TxMapErr:", mapping_err);
2416e106a4d9SHariprasad Shenai 		RL("FLAllocErr:", fl.alloc_failed);
2417e106a4d9SHariprasad Shenai 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
241870055dd0SHariprasad Shenai 		RL("FLMapErr:", fl.mapping_err);
241970055dd0SHariprasad Shenai 		RL("FLLow:", fl.low);
2420e106a4d9SHariprasad Shenai 		RL("FLStarving:", fl.starving);
2421dc9daab2SHariprasad Shenai 
2422e106a4d9SHariprasad Shenai 	} else if (iscsi_idx < iscsi_entries) {
2423e106a4d9SHariprasad Shenai 		const struct sge_ofld_rxq *rx =
2424f90ce561SHariprasad Shenai 			&adap->sge.iscsirxq[iscsi_idx * 4];
2425e106a4d9SHariprasad Shenai 		const struct sge_ofld_txq *tx =
2426e106a4d9SHariprasad Shenai 			&adap->sge.ofldtxq[iscsi_idx * 4];
2427f90ce561SHariprasad Shenai 		int n = min(4, adap->sge.iscsiqsets - 4 * iscsi_idx);
2428e106a4d9SHariprasad Shenai 
2429e106a4d9SHariprasad Shenai 		S("QType:", "iSCSI");
2430dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2431dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2432dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2433dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2434dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
2435dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2436dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2437dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2438dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2439dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2440dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2441dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2442dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2443dc9daab2SHariprasad Shenai 		R("FL ID:", fl.cntxt_id);
2444dc9daab2SHariprasad Shenai 		R("FL size:", fl.size - 8);
2445dc9daab2SHariprasad Shenai 		R("FL pend:", fl.pend_cred);
2446dc9daab2SHariprasad Shenai 		R("FL avail:", fl.avail);
2447dc9daab2SHariprasad Shenai 		R("FL PIDX:", fl.pidx);
2448dc9daab2SHariprasad Shenai 		R("FL CIDX:", fl.cidx);
2449e106a4d9SHariprasad Shenai 		RL("RxPackets:", stats.pkts);
2450e106a4d9SHariprasad Shenai 		RL("RxImmPkts:", stats.imm);
2451e106a4d9SHariprasad Shenai 		RL("RxNoMem:", stats.nomem);
2452e106a4d9SHariprasad Shenai 		RL("FLAllocErr:", fl.alloc_failed);
2453e106a4d9SHariprasad Shenai 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
245470055dd0SHariprasad Shenai 		RL("FLMapErr:", fl.mapping_err);
245570055dd0SHariprasad Shenai 		RL("FLLow:", fl.low);
2456e106a4d9SHariprasad Shenai 		RL("FLStarving:", fl.starving);
2457e106a4d9SHariprasad Shenai 
2458f2692d16SVarun Prakash 	} else if (iscsit_idx < iscsit_entries) {
2459f2692d16SVarun Prakash 		const struct sge_ofld_rxq *rx =
2460f2692d16SVarun Prakash 			&adap->sge.iscsitrxq[iscsit_idx * 4];
2461f2692d16SVarun Prakash 		int n = min(4, adap->sge.niscsitq - 4 * iscsit_idx);
2462f2692d16SVarun Prakash 
2463f2692d16SVarun Prakash 		S("QType:", "iSCSIT");
2464f2692d16SVarun Prakash 		R("RspQ ID:", rspq.abs_id);
2465f2692d16SVarun Prakash 		R("RspQ size:", rspq.size);
2466f2692d16SVarun Prakash 		R("RspQE size:", rspq.iqe_len);
2467f2692d16SVarun Prakash 		R("RspQ CIDX:", rspq.cidx);
2468f2692d16SVarun Prakash 		R("RspQ Gen:", rspq.gen);
2469f2692d16SVarun Prakash 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2470f2692d16SVarun Prakash 		S3("u", "Intr pktcnt:",
2471f2692d16SVarun Prakash 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2472f2692d16SVarun Prakash 		R("FL ID:", fl.cntxt_id);
2473f2692d16SVarun Prakash 		R("FL size:", fl.size - 8);
2474f2692d16SVarun Prakash 		R("FL pend:", fl.pend_cred);
2475f2692d16SVarun Prakash 		R("FL avail:", fl.avail);
2476f2692d16SVarun Prakash 		R("FL PIDX:", fl.pidx);
2477f2692d16SVarun Prakash 		R("FL CIDX:", fl.cidx);
2478f2692d16SVarun Prakash 		RL("RxPackets:", stats.pkts);
2479f2692d16SVarun Prakash 		RL("RxImmPkts:", stats.imm);
2480f2692d16SVarun Prakash 		RL("RxNoMem:", stats.nomem);
2481f2692d16SVarun Prakash 		RL("FLAllocErr:", fl.alloc_failed);
2482f2692d16SVarun Prakash 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
2483f2692d16SVarun Prakash 		RL("FLMapErr:", fl.mapping_err);
2484f2692d16SVarun Prakash 		RL("FLLow:", fl.low);
2485f2692d16SVarun Prakash 		RL("FLStarving:", fl.starving);
2486f2692d16SVarun Prakash 
2487dc9daab2SHariprasad Shenai 	} else if (rdma_idx < rdma_entries) {
2488dc9daab2SHariprasad Shenai 		const struct sge_ofld_rxq *rx =
2489dc9daab2SHariprasad Shenai 				&adap->sge.rdmarxq[rdma_idx * 4];
2490dc9daab2SHariprasad Shenai 		int n = min(4, adap->sge.rdmaqs - 4 * rdma_idx);
2491dc9daab2SHariprasad Shenai 
2492dc9daab2SHariprasad Shenai 		S("QType:", "RDMA-CPL");
2493f36e58e5SHariprasad Shenai 		S("Interface:",
2494f36e58e5SHariprasad Shenai 		  rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2495dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2496dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2497dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2498dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2499dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2500dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2501dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2502dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2503dc9daab2SHariprasad Shenai 		R("FL ID:", fl.cntxt_id);
2504dc9daab2SHariprasad Shenai 		R("FL size:", fl.size - 8);
2505dc9daab2SHariprasad Shenai 		R("FL pend:", fl.pend_cred);
2506dc9daab2SHariprasad Shenai 		R("FL avail:", fl.avail);
2507dc9daab2SHariprasad Shenai 		R("FL PIDX:", fl.pidx);
2508dc9daab2SHariprasad Shenai 		R("FL CIDX:", fl.cidx);
2509e106a4d9SHariprasad Shenai 		RL("RxPackets:", stats.pkts);
2510e106a4d9SHariprasad Shenai 		RL("RxImmPkts:", stats.imm);
2511e106a4d9SHariprasad Shenai 		RL("RxNoMem:", stats.nomem);
2512e106a4d9SHariprasad Shenai 		RL("FLAllocErr:", fl.alloc_failed);
2513e106a4d9SHariprasad Shenai 		RL("FLLrgAlcErr:", fl.large_alloc_failed);
251470055dd0SHariprasad Shenai 		RL("FLMapErr:", fl.mapping_err);
251570055dd0SHariprasad Shenai 		RL("FLLow:", fl.low);
2516e106a4d9SHariprasad Shenai 		RL("FLStarving:", fl.starving);
2517e106a4d9SHariprasad Shenai 
2518dc9daab2SHariprasad Shenai 	} else if (ciq_idx < ciq_entries) {
2519dc9daab2SHariprasad Shenai 		const struct sge_ofld_rxq *rx = &adap->sge.rdmaciq[ciq_idx * 4];
2520dc9daab2SHariprasad Shenai 		int n = min(4, adap->sge.rdmaciqs - 4 * ciq_idx);
2521dc9daab2SHariprasad Shenai 
2522dc9daab2SHariprasad Shenai 		S("QType:", "RDMA-CIQ");
2523f36e58e5SHariprasad Shenai 		S("Interface:",
2524f36e58e5SHariprasad Shenai 		  rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
2525dc9daab2SHariprasad Shenai 		R("RspQ ID:", rspq.abs_id);
2526dc9daab2SHariprasad Shenai 		R("RspQ size:", rspq.size);
2527dc9daab2SHariprasad Shenai 		R("RspQE size:", rspq.iqe_len);
2528dc9daab2SHariprasad Shenai 		R("RspQ CIDX:", rspq.cidx);
2529dc9daab2SHariprasad Shenai 		R("RspQ Gen:", rspq.gen);
2530dc9daab2SHariprasad Shenai 		S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
2531dc9daab2SHariprasad Shenai 		S3("u", "Intr pktcnt:",
2532dc9daab2SHariprasad Shenai 		   adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
2533e106a4d9SHariprasad Shenai 		RL("RxAN:", stats.an);
2534e106a4d9SHariprasad Shenai 		RL("RxNoMem:", stats.nomem);
2535e106a4d9SHariprasad Shenai 
2536dc9daab2SHariprasad Shenai 	} else if (ctrl_idx < ctrl_entries) {
2537dc9daab2SHariprasad Shenai 		const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
2538dc9daab2SHariprasad Shenai 		int n = min(4, adap->params.nports - 4 * ctrl_idx);
2539dc9daab2SHariprasad Shenai 
2540dc9daab2SHariprasad Shenai 		S("QType:", "Control");
2541dc9daab2SHariprasad Shenai 		T("TxQ ID:", q.cntxt_id);
2542dc9daab2SHariprasad Shenai 		T("TxQ size:", q.size);
2543dc9daab2SHariprasad Shenai 		T("TxQ inuse:", q.in_use);
2544dc9daab2SHariprasad Shenai 		T("TxQ CIDX:", q.cidx);
2545dc9daab2SHariprasad Shenai 		T("TxQ PIDX:", q.pidx);
2546e106a4d9SHariprasad Shenai 		TL("TxQFull:", q.stops);
2547e106a4d9SHariprasad Shenai 		TL("TxQRestarts:", q.restarts);
2548dc9daab2SHariprasad Shenai 	} else if (fq_idx == 0) {
2549dc9daab2SHariprasad Shenai 		const struct sge_rspq *evtq = &adap->sge.fw_evtq;
2550dc9daab2SHariprasad Shenai 
2551dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
2552dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
2553dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
2554dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
2555dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
2556dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
2557dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr delay:",
2558dc9daab2SHariprasad Shenai 			   qtimer_val(adap, evtq));
2559dc9daab2SHariprasad Shenai 		seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
2560dc9daab2SHariprasad Shenai 			   adap->sge.counter_val[evtq->pktcnt_idx]);
2561dc9daab2SHariprasad Shenai 	}
2562dc9daab2SHariprasad Shenai #undef R
2563e106a4d9SHariprasad Shenai #undef RL
2564dc9daab2SHariprasad Shenai #undef T
2565e106a4d9SHariprasad Shenai #undef TL
2566dc9daab2SHariprasad Shenai #undef S
2567e106a4d9SHariprasad Shenai #undef R3
2568e106a4d9SHariprasad Shenai #undef T3
2569dc9daab2SHariprasad Shenai #undef S3
2570dc9daab2SHariprasad Shenai 	return 0;
2571dc9daab2SHariprasad Shenai }
2572dc9daab2SHariprasad Shenai 
2573dc9daab2SHariprasad Shenai static int sge_queue_entries(const struct adapter *adap)
2574dc9daab2SHariprasad Shenai {
2575dc9daab2SHariprasad Shenai 	return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
2576f90ce561SHariprasad Shenai 	       DIV_ROUND_UP(adap->sge.iscsiqsets, 4) +
2577f2692d16SVarun Prakash 	       DIV_ROUND_UP(adap->sge.niscsitq, 4) +
2578dc9daab2SHariprasad Shenai 	       DIV_ROUND_UP(adap->sge.rdmaqs, 4) +
2579dc9daab2SHariprasad Shenai 	       DIV_ROUND_UP(adap->sge.rdmaciqs, 4) +
2580dc9daab2SHariprasad Shenai 	       DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
2581dc9daab2SHariprasad Shenai }
2582dc9daab2SHariprasad Shenai 
2583dc9daab2SHariprasad Shenai static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
2584dc9daab2SHariprasad Shenai {
2585dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2586dc9daab2SHariprasad Shenai 
2587dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2588dc9daab2SHariprasad Shenai }
2589dc9daab2SHariprasad Shenai 
2590dc9daab2SHariprasad Shenai static void sge_queue_stop(struct seq_file *seq, void *v)
2591dc9daab2SHariprasad Shenai {
2592dc9daab2SHariprasad Shenai }
2593dc9daab2SHariprasad Shenai 
2594dc9daab2SHariprasad Shenai static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
2595dc9daab2SHariprasad Shenai {
2596dc9daab2SHariprasad Shenai 	int entries = sge_queue_entries(seq->private);
2597dc9daab2SHariprasad Shenai 
2598dc9daab2SHariprasad Shenai 	++*pos;
2599dc9daab2SHariprasad Shenai 	return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
2600dc9daab2SHariprasad Shenai }
2601dc9daab2SHariprasad Shenai 
2602dc9daab2SHariprasad Shenai static const struct seq_operations sge_qinfo_seq_ops = {
2603dc9daab2SHariprasad Shenai 	.start = sge_queue_start,
2604dc9daab2SHariprasad Shenai 	.next  = sge_queue_next,
2605dc9daab2SHariprasad Shenai 	.stop  = sge_queue_stop,
2606dc9daab2SHariprasad Shenai 	.show  = sge_qinfo_show
2607dc9daab2SHariprasad Shenai };
2608dc9daab2SHariprasad Shenai 
2609dc9daab2SHariprasad Shenai static int sge_qinfo_open(struct inode *inode, struct file *file)
2610dc9daab2SHariprasad Shenai {
2611dc9daab2SHariprasad Shenai 	int res = seq_open(file, &sge_qinfo_seq_ops);
2612dc9daab2SHariprasad Shenai 
2613dc9daab2SHariprasad Shenai 	if (!res) {
2614dc9daab2SHariprasad Shenai 		struct seq_file *seq = file->private_data;
2615dc9daab2SHariprasad Shenai 
2616dc9daab2SHariprasad Shenai 		seq->private = inode->i_private;
2617dc9daab2SHariprasad Shenai 	}
2618dc9daab2SHariprasad Shenai 	return res;
2619dc9daab2SHariprasad Shenai }
2620dc9daab2SHariprasad Shenai 
2621dc9daab2SHariprasad Shenai static const struct file_operations sge_qinfo_debugfs_fops = {
2622dc9daab2SHariprasad Shenai 	.owner   = THIS_MODULE,
2623dc9daab2SHariprasad Shenai 	.open    = sge_qinfo_open,
2624dc9daab2SHariprasad Shenai 	.read    = seq_read,
2625dc9daab2SHariprasad Shenai 	.llseek  = seq_lseek,
2626dc9daab2SHariprasad Shenai 	.release = seq_release,
2627dc9daab2SHariprasad Shenai };
2628dc9daab2SHariprasad Shenai 
262949216c1cSHariprasad Shenai int mem_open(struct inode *inode, struct file *file)
263049216c1cSHariprasad Shenai {
263149216c1cSHariprasad Shenai 	unsigned int mem;
263249216c1cSHariprasad Shenai 	struct adapter *adap;
263349216c1cSHariprasad Shenai 
263449216c1cSHariprasad Shenai 	file->private_data = inode->i_private;
263549216c1cSHariprasad Shenai 
263649216c1cSHariprasad Shenai 	mem = (uintptr_t)file->private_data & 0x3;
263749216c1cSHariprasad Shenai 	adap = file->private_data - mem;
263849216c1cSHariprasad Shenai 
263949216c1cSHariprasad Shenai 	(void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
264049216c1cSHariprasad Shenai 
264149216c1cSHariprasad Shenai 	return 0;
264249216c1cSHariprasad Shenai }
264349216c1cSHariprasad Shenai 
2644fd88b31aSHariprasad Shenai static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
2645fd88b31aSHariprasad Shenai 			loff_t *ppos)
2646fd88b31aSHariprasad Shenai {
2647fd88b31aSHariprasad Shenai 	loff_t pos = *ppos;
2648fd88b31aSHariprasad Shenai 	loff_t avail = file_inode(file)->i_size;
2649fd88b31aSHariprasad Shenai 	unsigned int mem = (uintptr_t)file->private_data & 3;
2650fd88b31aSHariprasad Shenai 	struct adapter *adap = file->private_data - mem;
2651fd88b31aSHariprasad Shenai 	__be32 *data;
2652fd88b31aSHariprasad Shenai 	int ret;
2653fd88b31aSHariprasad Shenai 
2654fd88b31aSHariprasad Shenai 	if (pos < 0)
2655fd88b31aSHariprasad Shenai 		return -EINVAL;
2656fd88b31aSHariprasad Shenai 	if (pos >= avail)
2657fd88b31aSHariprasad Shenai 		return 0;
2658fd88b31aSHariprasad Shenai 	if (count > avail - pos)
2659fd88b31aSHariprasad Shenai 		count = avail - pos;
2660fd88b31aSHariprasad Shenai 
2661fd88b31aSHariprasad Shenai 	data = t4_alloc_mem(count);
2662fd88b31aSHariprasad Shenai 	if (!data)
2663fd88b31aSHariprasad Shenai 		return -ENOMEM;
2664fd88b31aSHariprasad Shenai 
2665fd88b31aSHariprasad Shenai 	spin_lock(&adap->win0_lock);
2666fd88b31aSHariprasad Shenai 	ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
2667fd88b31aSHariprasad Shenai 	spin_unlock(&adap->win0_lock);
2668fd88b31aSHariprasad Shenai 	if (ret) {
2669fd88b31aSHariprasad Shenai 		t4_free_mem(data);
2670fd88b31aSHariprasad Shenai 		return ret;
2671fd88b31aSHariprasad Shenai 	}
2672fd88b31aSHariprasad Shenai 	ret = copy_to_user(buf, data, count);
2673fd88b31aSHariprasad Shenai 
2674fd88b31aSHariprasad Shenai 	t4_free_mem(data);
2675fd88b31aSHariprasad Shenai 	if (ret)
2676fd88b31aSHariprasad Shenai 		return -EFAULT;
2677fd88b31aSHariprasad Shenai 
2678fd88b31aSHariprasad Shenai 	*ppos = pos + count;
2679fd88b31aSHariprasad Shenai 	return count;
2680fd88b31aSHariprasad Shenai }
2681fd88b31aSHariprasad Shenai static const struct file_operations mem_debugfs_fops = {
2682fd88b31aSHariprasad Shenai 	.owner   = THIS_MODULE,
2683fd88b31aSHariprasad Shenai 	.open    = simple_open,
2684fd88b31aSHariprasad Shenai 	.read    = mem_read,
2685fd88b31aSHariprasad Shenai 	.llseek  = default_llseek,
2686fd88b31aSHariprasad Shenai };
2687fd88b31aSHariprasad Shenai 
2688a4011fd4SHariprasad Shenai static int tid_info_show(struct seq_file *seq, void *v)
2689a4011fd4SHariprasad Shenai {
2690a4011fd4SHariprasad Shenai 	struct adapter *adap = seq->private;
2691a4011fd4SHariprasad Shenai 	const struct tid_info *t = &adap->tids;
2692a4011fd4SHariprasad Shenai 	enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
2693a4011fd4SHariprasad Shenai 
2694a4011fd4SHariprasad Shenai 	if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
2695a4011fd4SHariprasad Shenai 		unsigned int sb;
2696a4011fd4SHariprasad Shenai 
2697a4011fd4SHariprasad Shenai 		if (chip <= CHELSIO_T5)
2698a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
2699a4011fd4SHariprasad Shenai 		else
2700a4011fd4SHariprasad Shenai 			sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
2701a4011fd4SHariprasad Shenai 
2702a4011fd4SHariprasad Shenai 		if (sb) {
2703a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: 0..%u/%u..%u", sb - 1,
2704a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2705a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2706a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2707a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2708a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2709a4011fd4SHariprasad Shenai 		} else if (adap->flags & FW_OFLD_CONN) {
2710a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u/%u..%u",
2711a4011fd4SHariprasad Shenai 				   t->aftid_base,
2712a4011fd4SHariprasad Shenai 				   t->aftid_end,
2713a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2714a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2715a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u/%u\n",
2716a4011fd4SHariprasad Shenai 				   atomic_read(&t->tids_in_use),
2717a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2718a4011fd4SHariprasad Shenai 		} else {
2719a4011fd4SHariprasad Shenai 			seq_printf(seq, "TID range: %u..%u",
2720a4011fd4SHariprasad Shenai 				   adap->tids.hash_base,
2721a4011fd4SHariprasad Shenai 				   t->ntids - 1);
2722a4011fd4SHariprasad Shenai 			seq_printf(seq, ", in use: %u\n",
2723a4011fd4SHariprasad Shenai 				   atomic_read(&t->hash_tids_in_use));
2724a4011fd4SHariprasad Shenai 		}
2725a4011fd4SHariprasad Shenai 	} else if (t->ntids) {
2726a4011fd4SHariprasad Shenai 		seq_printf(seq, "TID range: 0..%u", t->ntids - 1);
2727a4011fd4SHariprasad Shenai 		seq_printf(seq, ", in use: %u\n",
2728a4011fd4SHariprasad Shenai 			   atomic_read(&t->tids_in_use));
2729a4011fd4SHariprasad Shenai 	}
2730a4011fd4SHariprasad Shenai 
2731a4011fd4SHariprasad Shenai 	if (t->nstids)
2732a4011fd4SHariprasad Shenai 		seq_printf(seq, "STID range: %u..%u, in use: %u\n",
2733a4011fd4SHariprasad Shenai 			   (!t->stid_base &&
2734a4011fd4SHariprasad Shenai 			   (chip <= CHELSIO_T5)) ?
2735a4011fd4SHariprasad Shenai 			   t->stid_base + 1 : t->stid_base,
2736a4011fd4SHariprasad Shenai 			   t->stid_base + t->nstids - 1, t->stids_in_use);
2737a4011fd4SHariprasad Shenai 	if (t->natids)
2738a4011fd4SHariprasad Shenai 		seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
2739a4011fd4SHariprasad Shenai 			   t->natids - 1, t->atids_in_use);
2740a4011fd4SHariprasad Shenai 	seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
2741a4011fd4SHariprasad Shenai 		   t->ftid_base + t->nftids - 1);
2742a4011fd4SHariprasad Shenai 	if (t->nsftids)
2743a4011fd4SHariprasad Shenai 		seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
2744a4011fd4SHariprasad Shenai 			   t->sftid_base, t->sftid_base + t->nsftids - 2,
2745a4011fd4SHariprasad Shenai 			   t->sftids_in_use);
2746a4011fd4SHariprasad Shenai 	if (t->ntids)
2747a4011fd4SHariprasad Shenai 		seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
2748a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
2749a4011fd4SHariprasad Shenai 			   t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
2750a4011fd4SHariprasad Shenai 	return 0;
2751a4011fd4SHariprasad Shenai }
2752a4011fd4SHariprasad Shenai 
2753a4011fd4SHariprasad Shenai DEFINE_SIMPLE_DEBUGFS_FILE(tid_info);
2754a4011fd4SHariprasad Shenai 
2755fd88b31aSHariprasad Shenai static void add_debugfs_mem(struct adapter *adap, const char *name,
2756fd88b31aSHariprasad Shenai 			    unsigned int idx, unsigned int size_mb)
2757fd88b31aSHariprasad Shenai {
2758e59b4e91SDavid Howells 	debugfs_create_file_size(name, S_IRUSR, adap->debugfs_root,
2759e59b4e91SDavid Howells 				 (void *)adap + idx, &mem_debugfs_fops,
2760e59b4e91SDavid Howells 				 size_mb << 20);
2761fd88b31aSHariprasad Shenai }
2762fd88b31aSHariprasad Shenai 
27635b377d11SHariprasad Shenai static int blocked_fl_open(struct inode *inode, struct file *file)
27645b377d11SHariprasad Shenai {
27655b377d11SHariprasad Shenai 	file->private_data = inode->i_private;
27665b377d11SHariprasad Shenai 	return 0;
27675b377d11SHariprasad Shenai }
27685b377d11SHariprasad Shenai 
27695b377d11SHariprasad Shenai static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
27705b377d11SHariprasad Shenai 			       size_t count, loff_t *ppos)
27715b377d11SHariprasad Shenai {
27725b377d11SHariprasad Shenai 	int len;
27735b377d11SHariprasad Shenai 	const struct adapter *adap = filp->private_data;
27745b377d11SHariprasad Shenai 	char *buf;
27755b377d11SHariprasad Shenai 	ssize_t size = (adap->sge.egr_sz + 3) / 4 +
27765b377d11SHariprasad Shenai 			adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
27775b377d11SHariprasad Shenai 
27785b377d11SHariprasad Shenai 	buf = kzalloc(size, GFP_KERNEL);
27795b377d11SHariprasad Shenai 	if (!buf)
27805b377d11SHariprasad Shenai 		return -ENOMEM;
27815b377d11SHariprasad Shenai 
27825b377d11SHariprasad Shenai 	len = snprintf(buf, size - 1, "%*pb\n",
27835b377d11SHariprasad Shenai 		       adap->sge.egr_sz, adap->sge.blocked_fl);
27845b377d11SHariprasad Shenai 	len += sprintf(buf + len, "\n");
27855b377d11SHariprasad Shenai 	size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
27865b377d11SHariprasad Shenai 	t4_free_mem(buf);
27875b377d11SHariprasad Shenai 	return size;
27885b377d11SHariprasad Shenai }
27895b377d11SHariprasad Shenai 
27905b377d11SHariprasad Shenai static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
27915b377d11SHariprasad Shenai 				size_t count, loff_t *ppos)
27925b377d11SHariprasad Shenai {
27935b377d11SHariprasad Shenai 	int err;
27945b377d11SHariprasad Shenai 	unsigned long *t;
27955b377d11SHariprasad Shenai 	struct adapter *adap = filp->private_data;
27965b377d11SHariprasad Shenai 
27975b377d11SHariprasad Shenai 	t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
27985b377d11SHariprasad Shenai 	if (!t)
27995b377d11SHariprasad Shenai 		return -ENOMEM;
28005b377d11SHariprasad Shenai 
28015b377d11SHariprasad Shenai 	err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
28025b377d11SHariprasad Shenai 	if (err)
28035b377d11SHariprasad Shenai 		return err;
28045b377d11SHariprasad Shenai 
28055b377d11SHariprasad Shenai 	bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
28065b377d11SHariprasad Shenai 	t4_free_mem(t);
28075b377d11SHariprasad Shenai 	return count;
28085b377d11SHariprasad Shenai }
28095b377d11SHariprasad Shenai 
28105b377d11SHariprasad Shenai static const struct file_operations blocked_fl_fops = {
28115b377d11SHariprasad Shenai 	.owner   = THIS_MODULE,
28125b377d11SHariprasad Shenai 	.open    = blocked_fl_open,
28135b377d11SHariprasad Shenai 	.read    = blocked_fl_read,
28145b377d11SHariprasad Shenai 	.write   = blocked_fl_write,
28155b377d11SHariprasad Shenai 	.llseek  = generic_file_llseek,
28165b377d11SHariprasad Shenai };
28175b377d11SHariprasad Shenai 
28185888111cSHariprasad Shenai struct mem_desc {
28195888111cSHariprasad Shenai 	unsigned int base;
28205888111cSHariprasad Shenai 	unsigned int limit;
28215888111cSHariprasad Shenai 	unsigned int idx;
28225888111cSHariprasad Shenai };
28235888111cSHariprasad Shenai 
28245888111cSHariprasad Shenai static int mem_desc_cmp(const void *a, const void *b)
28255888111cSHariprasad Shenai {
28265888111cSHariprasad Shenai 	return ((const struct mem_desc *)a)->base -
28275888111cSHariprasad Shenai 	       ((const struct mem_desc *)b)->base;
28285888111cSHariprasad Shenai }
28295888111cSHariprasad Shenai 
28305888111cSHariprasad Shenai static void mem_region_show(struct seq_file *seq, const char *name,
28315888111cSHariprasad Shenai 			    unsigned int from, unsigned int to)
28325888111cSHariprasad Shenai {
28335888111cSHariprasad Shenai 	char buf[40];
28345888111cSHariprasad Shenai 
28355888111cSHariprasad Shenai 	string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
28365888111cSHariprasad Shenai 			sizeof(buf));
28375888111cSHariprasad Shenai 	seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
28385888111cSHariprasad Shenai }
28395888111cSHariprasad Shenai 
28405888111cSHariprasad Shenai static int meminfo_show(struct seq_file *seq, void *v)
28415888111cSHariprasad Shenai {
28425888111cSHariprasad Shenai 	static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
28435888111cSHariprasad Shenai 					"MC0:", "MC1:"};
28445888111cSHariprasad Shenai 	static const char * const region[] = {
28455888111cSHariprasad Shenai 		"DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
28465888111cSHariprasad Shenai 		"Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
28475888111cSHariprasad Shenai 		"Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
28485888111cSHariprasad Shenai 		"TDDP region:", "TPT region:", "STAG region:", "RQ region:",
28495888111cSHariprasad Shenai 		"RQUDP region:", "PBL region:", "TXPBL region:",
28505888111cSHariprasad Shenai 		"DBVFIFO region:", "ULPRX state:", "ULPTX state:",
28515888111cSHariprasad Shenai 		"On-chip queues:"
28525888111cSHariprasad Shenai 	};
28535888111cSHariprasad Shenai 
28545888111cSHariprasad Shenai 	int i, n;
28555888111cSHariprasad Shenai 	u32 lo, hi, used, alloc;
28565888111cSHariprasad Shenai 	struct mem_desc avail[4];
28575888111cSHariprasad Shenai 	struct mem_desc mem[ARRAY_SIZE(region) + 3];      /* up to 3 holes */
28585888111cSHariprasad Shenai 	struct mem_desc *md = mem;
28595888111cSHariprasad Shenai 	struct adapter *adap = seq->private;
28605888111cSHariprasad Shenai 
28615888111cSHariprasad Shenai 	for (i = 0; i < ARRAY_SIZE(mem); i++) {
28625888111cSHariprasad Shenai 		mem[i].limit = 0;
28635888111cSHariprasad Shenai 		mem[i].idx = i;
28645888111cSHariprasad Shenai 	}
28655888111cSHariprasad Shenai 
28665888111cSHariprasad Shenai 	/* Find and sort the populated memory ranges */
28675888111cSHariprasad Shenai 	i = 0;
28685888111cSHariprasad Shenai 	lo = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
28695888111cSHariprasad Shenai 	if (lo & EDRAM0_ENABLE_F) {
28705888111cSHariprasad Shenai 		hi = t4_read_reg(adap, MA_EDRAM0_BAR_A);
28715888111cSHariprasad Shenai 		avail[i].base = EDRAM0_BASE_G(hi) << 20;
28725888111cSHariprasad Shenai 		avail[i].limit = avail[i].base + (EDRAM0_SIZE_G(hi) << 20);
28735888111cSHariprasad Shenai 		avail[i].idx = 0;
28745888111cSHariprasad Shenai 		i++;
28755888111cSHariprasad Shenai 	}
28765888111cSHariprasad Shenai 	if (lo & EDRAM1_ENABLE_F) {
28775888111cSHariprasad Shenai 		hi = t4_read_reg(adap, MA_EDRAM1_BAR_A);
28785888111cSHariprasad Shenai 		avail[i].base = EDRAM1_BASE_G(hi) << 20;
28795888111cSHariprasad Shenai 		avail[i].limit = avail[i].base + (EDRAM1_SIZE_G(hi) << 20);
28805888111cSHariprasad Shenai 		avail[i].idx = 1;
28815888111cSHariprasad Shenai 		i++;
28825888111cSHariprasad Shenai 	}
28835888111cSHariprasad Shenai 
28845888111cSHariprasad Shenai 	if (is_t5(adap->params.chip)) {
28855888111cSHariprasad Shenai 		if (lo & EXT_MEM0_ENABLE_F) {
28865888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
28875888111cSHariprasad Shenai 			avail[i].base = EXT_MEM0_BASE_G(hi) << 20;
28885888111cSHariprasad Shenai 			avail[i].limit =
28895888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM0_SIZE_G(hi) << 20);
28905888111cSHariprasad Shenai 			avail[i].idx = 3;
28915888111cSHariprasad Shenai 			i++;
28925888111cSHariprasad Shenai 		}
28935888111cSHariprasad Shenai 		if (lo & EXT_MEM1_ENABLE_F) {
28945888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
28955888111cSHariprasad Shenai 			avail[i].base = EXT_MEM1_BASE_G(hi) << 20;
28965888111cSHariprasad Shenai 			avail[i].limit =
28975888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM1_SIZE_G(hi) << 20);
28985888111cSHariprasad Shenai 			avail[i].idx = 4;
28995888111cSHariprasad Shenai 			i++;
29005888111cSHariprasad Shenai 		}
29015888111cSHariprasad Shenai 	} else {
29025888111cSHariprasad Shenai 		if (lo & EXT_MEM_ENABLE_F) {
29035888111cSHariprasad Shenai 			hi = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
29045888111cSHariprasad Shenai 			avail[i].base = EXT_MEM_BASE_G(hi) << 20;
29055888111cSHariprasad Shenai 			avail[i].limit =
29065888111cSHariprasad Shenai 				avail[i].base + (EXT_MEM_SIZE_G(hi) << 20);
29075888111cSHariprasad Shenai 			avail[i].idx = 2;
29085888111cSHariprasad Shenai 			i++;
29095888111cSHariprasad Shenai 		}
29105888111cSHariprasad Shenai 	}
29115888111cSHariprasad Shenai 	if (!i)                                    /* no memory available */
29125888111cSHariprasad Shenai 		return 0;
29135888111cSHariprasad Shenai 	sort(avail, i, sizeof(struct mem_desc), mem_desc_cmp, NULL);
29145888111cSHariprasad Shenai 
29155888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A);
29165888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_IMSG_CTXT_BADDR_A);
29175888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, SGE_FLM_CACHE_BADDR_A);
29185888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_TCB_BASE_A);
29195888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_BASE_A);
29205888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_TIMER_BASE_A);
29215888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_RX_FLST_BASE_A);
29225888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_TX_FLST_BASE_A);
29235888111cSHariprasad Shenai 	(md++)->base = t4_read_reg(adap, TP_CMM_MM_PS_FLST_BASE_A);
29245888111cSHariprasad Shenai 
29255888111cSHariprasad Shenai 	/* the next few have explicit upper bounds */
29265888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, TP_PMM_TX_BASE_A);
29275888111cSHariprasad Shenai 	md->limit = md->base - 1 +
29285888111cSHariprasad Shenai 		    t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A) *
29295888111cSHariprasad Shenai 		    PMTXMAXPAGE_G(t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A));
29305888111cSHariprasad Shenai 	md++;
29315888111cSHariprasad Shenai 
29325888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, TP_PMM_RX_BASE_A);
29335888111cSHariprasad Shenai 	md->limit = md->base - 1 +
29345888111cSHariprasad Shenai 		    t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) *
29355888111cSHariprasad Shenai 		    PMRXMAXPAGE_G(t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A));
29365888111cSHariprasad Shenai 	md++;
29375888111cSHariprasad Shenai 
29385888111cSHariprasad Shenai 	if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
29395888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5) {
29405888111cSHariprasad Shenai 			hi = t4_read_reg(adap, LE_DB_TID_HASHBASE_A) / 4;
29415888111cSHariprasad Shenai 			md->base = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
29425888111cSHariprasad Shenai 		 } else {
29435888111cSHariprasad Shenai 			hi = t4_read_reg(adap, LE_DB_HASH_TID_BASE_A);
29445888111cSHariprasad Shenai 			md->base = t4_read_reg(adap,
29455888111cSHariprasad Shenai 					       LE_DB_HASH_TBL_BASE_ADDR_A);
29465888111cSHariprasad Shenai 		}
29475888111cSHariprasad Shenai 		md->limit = 0;
29485888111cSHariprasad Shenai 	} else {
29495888111cSHariprasad Shenai 		md->base = 0;
29505888111cSHariprasad Shenai 		md->idx = ARRAY_SIZE(region);  /* hide it */
29515888111cSHariprasad Shenai 	}
29525888111cSHariprasad Shenai 	md++;
29535888111cSHariprasad Shenai 
29545888111cSHariprasad Shenai #define ulp_region(reg) do { \
29555888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_ ## reg ## _LLIMIT_A);\
29565888111cSHariprasad Shenai 	(md++)->limit = t4_read_reg(adap, ULP_ ## reg ## _ULIMIT_A); \
29575888111cSHariprasad Shenai } while (0)
29585888111cSHariprasad Shenai 
29595888111cSHariprasad Shenai 	ulp_region(RX_ISCSI);
29605888111cSHariprasad Shenai 	ulp_region(RX_TDDP);
29615888111cSHariprasad Shenai 	ulp_region(TX_TPT);
29625888111cSHariprasad Shenai 	ulp_region(RX_STAG);
29635888111cSHariprasad Shenai 	ulp_region(RX_RQ);
29645888111cSHariprasad Shenai 	ulp_region(RX_RQUDP);
29655888111cSHariprasad Shenai 	ulp_region(RX_PBL);
29665888111cSHariprasad Shenai 	ulp_region(TX_PBL);
29675888111cSHariprasad Shenai #undef ulp_region
29685888111cSHariprasad Shenai 	md->base = 0;
29695888111cSHariprasad Shenai 	md->idx = ARRAY_SIZE(region);
29705888111cSHariprasad Shenai 	if (!is_t4(adap->params.chip)) {
29715888111cSHariprasad Shenai 		u32 size = 0;
29725888111cSHariprasad Shenai 		u32 sge_ctrl = t4_read_reg(adap, SGE_CONTROL2_A);
29735888111cSHariprasad Shenai 		u32 fifo_size = t4_read_reg(adap, SGE_DBVFIFO_SIZE_A);
29745888111cSHariprasad Shenai 
29755888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
29765888111cSHariprasad Shenai 			if (sge_ctrl & VFIFO_ENABLE_F)
29775888111cSHariprasad Shenai 				size = DBVFIFO_SIZE_G(fifo_size);
29785888111cSHariprasad Shenai 		} else {
29795888111cSHariprasad Shenai 			size = T6_DBVFIFO_SIZE_G(fifo_size);
29805888111cSHariprasad Shenai 		}
29815888111cSHariprasad Shenai 
29825888111cSHariprasad Shenai 		if (size) {
29835888111cSHariprasad Shenai 			md->base = BASEADDR_G(t4_read_reg(adap,
29845888111cSHariprasad Shenai 					SGE_DBVFIFO_BADDR_A));
29855888111cSHariprasad Shenai 			md->limit = md->base + (size << 2) - 1;
29865888111cSHariprasad Shenai 		}
29875888111cSHariprasad Shenai 	}
29885888111cSHariprasad Shenai 
29895888111cSHariprasad Shenai 	md++;
29905888111cSHariprasad Shenai 
29915888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_RX_CTX_BASE_A);
29925888111cSHariprasad Shenai 	md->limit = 0;
29935888111cSHariprasad Shenai 	md++;
29945888111cSHariprasad Shenai 	md->base = t4_read_reg(adap, ULP_TX_ERR_TABLE_BASE_A);
29955888111cSHariprasad Shenai 	md->limit = 0;
29965888111cSHariprasad Shenai 	md++;
29975888111cSHariprasad Shenai 
29985888111cSHariprasad Shenai 	md->base = adap->vres.ocq.start;
29995888111cSHariprasad Shenai 	if (adap->vres.ocq.size)
30005888111cSHariprasad Shenai 		md->limit = md->base + adap->vres.ocq.size - 1;
30015888111cSHariprasad Shenai 	else
30025888111cSHariprasad Shenai 		md->idx = ARRAY_SIZE(region);  /* hide it */
30035888111cSHariprasad Shenai 	md++;
30045888111cSHariprasad Shenai 
30055888111cSHariprasad Shenai 	/* add any address-space holes, there can be up to 3 */
30065888111cSHariprasad Shenai 	for (n = 0; n < i - 1; n++)
30075888111cSHariprasad Shenai 		if (avail[n].limit < avail[n + 1].base)
30085888111cSHariprasad Shenai 			(md++)->base = avail[n].limit;
30095888111cSHariprasad Shenai 	if (avail[n].limit)
30105888111cSHariprasad Shenai 		(md++)->base = avail[n].limit;
30115888111cSHariprasad Shenai 
30125888111cSHariprasad Shenai 	n = md - mem;
30135888111cSHariprasad Shenai 	sort(mem, n, sizeof(struct mem_desc), mem_desc_cmp, NULL);
30145888111cSHariprasad Shenai 
30155888111cSHariprasad Shenai 	for (lo = 0; lo < i; lo++)
30165888111cSHariprasad Shenai 		mem_region_show(seq, memory[avail[lo].idx], avail[lo].base,
30175888111cSHariprasad Shenai 				avail[lo].limit - 1);
30185888111cSHariprasad Shenai 
30195888111cSHariprasad Shenai 	seq_putc(seq, '\n');
30205888111cSHariprasad Shenai 	for (i = 0; i < n; i++) {
30215888111cSHariprasad Shenai 		if (mem[i].idx >= ARRAY_SIZE(region))
30225888111cSHariprasad Shenai 			continue;                        /* skip holes */
30235888111cSHariprasad Shenai 		if (!mem[i].limit)
30245888111cSHariprasad Shenai 			mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
30255888111cSHariprasad Shenai 		mem_region_show(seq, region[mem[i].idx], mem[i].base,
30265888111cSHariprasad Shenai 				mem[i].limit);
30275888111cSHariprasad Shenai 	}
30285888111cSHariprasad Shenai 
30295888111cSHariprasad Shenai 	seq_putc(seq, '\n');
30305888111cSHariprasad Shenai 	lo = t4_read_reg(adap, CIM_SDRAM_BASE_ADDR_A);
30315888111cSHariprasad Shenai 	hi = t4_read_reg(adap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
30325888111cSHariprasad Shenai 	mem_region_show(seq, "uP RAM:", lo, hi);
30335888111cSHariprasad Shenai 
30345888111cSHariprasad Shenai 	lo = t4_read_reg(adap, CIM_EXTMEM2_BASE_ADDR_A);
30355888111cSHariprasad Shenai 	hi = t4_read_reg(adap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
30365888111cSHariprasad Shenai 	mem_region_show(seq, "uP Extmem2:", lo, hi);
30375888111cSHariprasad Shenai 
30385888111cSHariprasad Shenai 	lo = t4_read_reg(adap, TP_PMM_RX_MAX_PAGE_A);
30395888111cSHariprasad Shenai 	seq_printf(seq, "\n%u Rx pages of size %uKiB for %u channels\n",
30405888111cSHariprasad Shenai 		   PMRXMAXPAGE_G(lo),
30415888111cSHariprasad Shenai 		   t4_read_reg(adap, TP_PMM_RX_PAGE_SIZE_A) >> 10,
30425888111cSHariprasad Shenai 		   (lo & PMRXNUMCHN_F) ? 2 : 1);
30435888111cSHariprasad Shenai 
30445888111cSHariprasad Shenai 	lo = t4_read_reg(adap, TP_PMM_TX_MAX_PAGE_A);
30455888111cSHariprasad Shenai 	hi = t4_read_reg(adap, TP_PMM_TX_PAGE_SIZE_A);
30465888111cSHariprasad Shenai 	seq_printf(seq, "%u Tx pages of size %u%ciB for %u channels\n",
30475888111cSHariprasad Shenai 		   PMTXMAXPAGE_G(lo),
30485888111cSHariprasad Shenai 		   hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
30495888111cSHariprasad Shenai 		   hi >= (1 << 20) ? 'M' : 'K', 1 << PMTXNUMCHN_G(lo));
30505888111cSHariprasad Shenai 	seq_printf(seq, "%u p-structs\n\n",
30515888111cSHariprasad Shenai 		   t4_read_reg(adap, TP_CMM_MM_MAX_PSTRUCT_A));
30525888111cSHariprasad Shenai 
30535888111cSHariprasad Shenai 	for (i = 0; i < 4; i++) {
30545888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
30555888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
30565888111cSHariprasad Shenai 		else
30575888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_PG_RSV0_A + i * 4);
30585888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
30595888111cSHariprasad Shenai 			used = T5_USED_G(lo);
30605888111cSHariprasad Shenai 			alloc = T5_ALLOC_G(lo);
30615888111cSHariprasad Shenai 		} else {
30625888111cSHariprasad Shenai 			used = USED_G(lo);
30635888111cSHariprasad Shenai 			alloc = ALLOC_G(lo);
30645888111cSHariprasad Shenai 		}
30655888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
30665888111cSHariprasad Shenai 		seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
30675888111cSHariprasad Shenai 			   i, used, alloc);
30685888111cSHariprasad Shenai 	}
30695888111cSHariprasad Shenai 	for (i = 0; i < adap->params.arch.nchan; i++) {
30705888111cSHariprasad Shenai 		if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5)
30715888111cSHariprasad Shenai 			lo = t4_read_reg(adap,
30725888111cSHariprasad Shenai 					 MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
30735888111cSHariprasad Shenai 		else
30745888111cSHariprasad Shenai 			lo = t4_read_reg(adap, MPS_RX_PG_RSV4_A + i * 4);
30755888111cSHariprasad Shenai 		if (is_t5(adap->params.chip)) {
30765888111cSHariprasad Shenai 			used = T5_USED_G(lo);
30775888111cSHariprasad Shenai 			alloc = T5_ALLOC_G(lo);
30785888111cSHariprasad Shenai 		} else {
30795888111cSHariprasad Shenai 			used = USED_G(lo);
30805888111cSHariprasad Shenai 			alloc = ALLOC_G(lo);
30815888111cSHariprasad Shenai 		}
30825888111cSHariprasad Shenai 		/* For T6 these are MAC buffer groups */
30835888111cSHariprasad Shenai 		seq_printf(seq,
30845888111cSHariprasad Shenai 			   "Loopback %d using %u pages out of %u allocated\n",
30855888111cSHariprasad Shenai 			   i, used, alloc);
30865888111cSHariprasad Shenai 	}
30875888111cSHariprasad Shenai 	return 0;
30885888111cSHariprasad Shenai }
30895888111cSHariprasad Shenai 
30905888111cSHariprasad Shenai static int meminfo_open(struct inode *inode, struct file *file)
30915888111cSHariprasad Shenai {
30925888111cSHariprasad Shenai 	return single_open(file, meminfo_show, inode->i_private);
30935888111cSHariprasad Shenai }
30945888111cSHariprasad Shenai 
30955888111cSHariprasad Shenai static const struct file_operations meminfo_fops = {
30965888111cSHariprasad Shenai 	.owner   = THIS_MODULE,
30975888111cSHariprasad Shenai 	.open    = meminfo_open,
30985888111cSHariprasad Shenai 	.read    = seq_read,
30995888111cSHariprasad Shenai 	.llseek  = seq_lseek,
31005888111cSHariprasad Shenai 	.release = single_release,
31015888111cSHariprasad Shenai };
3102fd88b31aSHariprasad Shenai /* Add an array of Debug FS files.
3103fd88b31aSHariprasad Shenai  */
3104fd88b31aSHariprasad Shenai void add_debugfs_files(struct adapter *adap,
3105fd88b31aSHariprasad Shenai 		       struct t4_debugfs_entry *files,
3106fd88b31aSHariprasad Shenai 		       unsigned int nfiles)
3107fd88b31aSHariprasad Shenai {
3108fd88b31aSHariprasad Shenai 	int i;
3109fd88b31aSHariprasad Shenai 
3110fd88b31aSHariprasad Shenai 	/* debugfs support is best effort */
3111fd88b31aSHariprasad Shenai 	for (i = 0; i < nfiles; i++)
3112fd88b31aSHariprasad Shenai 		debugfs_create_file(files[i].name, files[i].mode,
3113fd88b31aSHariprasad Shenai 				    adap->debugfs_root,
3114fd88b31aSHariprasad Shenai 				    (void *)adap + files[i].data,
3115fd88b31aSHariprasad Shenai 				    files[i].ops);
3116fd88b31aSHariprasad Shenai }
3117fd88b31aSHariprasad Shenai 
3118fd88b31aSHariprasad Shenai int t4_setup_debugfs(struct adapter *adap)
3119fd88b31aSHariprasad Shenai {
3120fd88b31aSHariprasad Shenai 	int i;
31213ccc6cf7SHariprasad Shenai 	u32 size = 0;
312249216c1cSHariprasad Shenai 	struct dentry *de;
3123fd88b31aSHariprasad Shenai 
3124fd88b31aSHariprasad Shenai 	static struct t4_debugfs_entry t4_debugfs_files[] = {
3125f1ff24aaSHariprasad Shenai 		{ "cim_la", &cim_la_fops, S_IRUSR, 0 },
312619689609SHariprasad Shenai 		{ "cim_pif_la", &cim_pif_la_fops, S_IRUSR, 0 },
312726fae93fSHariprasad Shenai 		{ "cim_ma_la", &cim_ma_la_fops, S_IRUSR, 0 },
312874b3092cSHariprasad Shenai 		{ "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 },
3129b58b6676SHariprasad Shenai 		{ "clk", &clk_debugfs_fops, S_IRUSR, 0 },
313049aa284fSHariprasad Shenai 		{ "devlog", &devlog_fops, S_IRUSR, 0 },
3131bf7c781dSHariprasad Shenai 		{ "mbox0", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
3132bf7c781dSHariprasad Shenai 		{ "mbox1", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
3133bf7c781dSHariprasad Shenai 		{ "mbox2", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
3134bf7c781dSHariprasad Shenai 		{ "mbox3", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3135bf7c781dSHariprasad Shenai 		{ "mbox4", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 4 },
3136bf7c781dSHariprasad Shenai 		{ "mbox5", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 5 },
3137bf7c781dSHariprasad Shenai 		{ "mbox6", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 6 },
3138bf7c781dSHariprasad Shenai 		{ "mbox7", &mbox_debugfs_fops, S_IRUSR | S_IWUSR, 7 },
31398e3d04fdSHariprasad Shenai 		{ "trace0", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 0 },
31408e3d04fdSHariprasad Shenai 		{ "trace1", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 1 },
31418e3d04fdSHariprasad Shenai 		{ "trace2", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 2 },
31428e3d04fdSHariprasad Shenai 		{ "trace3", &mps_trc_debugfs_fops, S_IRUSR | S_IWUSR, 3 },
3143fd88b31aSHariprasad Shenai 		{ "l2t", &t4_l2t_fops, S_IRUSR, 0},
3144ef82f662SHariprasad Shenai 		{ "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 },
3145688ea5feSHariprasad Shenai 		{ "rss", &rss_debugfs_fops, S_IRUSR, 0 },
3146688ea5feSHariprasad Shenai 		{ "rss_config", &rss_config_debugfs_fops, S_IRUSR, 0 },
3147688ea5feSHariprasad Shenai 		{ "rss_key", &rss_key_debugfs_fops, S_IRUSR, 0 },
3148688ea5feSHariprasad Shenai 		{ "rss_pf_config", &rss_pf_config_debugfs_fops, S_IRUSR, 0 },
3149688ea5feSHariprasad Shenai 		{ "rss_vf_config", &rss_vf_config_debugfs_fops, S_IRUSR, 0 },
3150dc9daab2SHariprasad Shenai 		{ "sge_qinfo", &sge_qinfo_debugfs_fops, S_IRUSR, 0 },
3151e5f0e43bSHariprasad Shenai 		{ "ibq_tp0",  &cim_ibq_fops, S_IRUSR, 0 },
3152e5f0e43bSHariprasad Shenai 		{ "ibq_tp1",  &cim_ibq_fops, S_IRUSR, 1 },
3153e5f0e43bSHariprasad Shenai 		{ "ibq_ulp",  &cim_ibq_fops, S_IRUSR, 2 },
3154e5f0e43bSHariprasad Shenai 		{ "ibq_sge0", &cim_ibq_fops, S_IRUSR, 3 },
3155e5f0e43bSHariprasad Shenai 		{ "ibq_sge1", &cim_ibq_fops, S_IRUSR, 4 },
3156e5f0e43bSHariprasad Shenai 		{ "ibq_ncsi", &cim_ibq_fops, S_IRUSR, 5 },
3157c778af7dSHariprasad Shenai 		{ "obq_ulp0", &cim_obq_fops, S_IRUSR, 0 },
3158c778af7dSHariprasad Shenai 		{ "obq_ulp1", &cim_obq_fops, S_IRUSR, 1 },
3159c778af7dSHariprasad Shenai 		{ "obq_ulp2", &cim_obq_fops, S_IRUSR, 2 },
3160c778af7dSHariprasad Shenai 		{ "obq_ulp3", &cim_obq_fops, S_IRUSR, 3 },
3161c778af7dSHariprasad Shenai 		{ "obq_sge",  &cim_obq_fops, S_IRUSR, 4 },
3162c778af7dSHariprasad Shenai 		{ "obq_ncsi", &cim_obq_fops, S_IRUSR, 5 },
31632d277b3bSHariprasad Shenai 		{ "tp_la", &tp_la_fops, S_IRUSR, 0 },
3164797ff0f5SHariprasad Shenai 		{ "ulprx_la", &ulprx_la_fops, S_IRUSR, 0 },
316570a5f3bbSHariprasad Shenai 		{ "sensors", &sensors_debugfs_fops, S_IRUSR, 0 },
3166b3bbe36aSHariprasad Shenai 		{ "pm_stats", &pm_stats_debugfs_fops, S_IRUSR, 0 },
31677864026bSHariprasad Shenai 		{ "tx_rate", &tx_rate_debugfs_fops, S_IRUSR, 0 },
3168bad43792SHariprasad Shenai 		{ "cctrl", &cctrl_tbl_debugfs_fops, S_IRUSR, 0 },
3169b5a02f50SAnish Bhatt #if IS_ENABLED(CONFIG_IPV6)
3170b5a02f50SAnish Bhatt 		{ "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 },
3171b5a02f50SAnish Bhatt #endif
3172a4011fd4SHariprasad Shenai 		{ "tids", &tid_info_debugfs_fops, S_IRUSR, 0},
31735b377d11SHariprasad Shenai 		{ "blocked_fl", &blocked_fl_fops, S_IRUSR | S_IWUSR, 0 },
31745888111cSHariprasad Shenai 		{ "meminfo", &meminfo_fops, S_IRUSR, 0 },
3175fd88b31aSHariprasad Shenai 	};
3176fd88b31aSHariprasad Shenai 
3177c778af7dSHariprasad Shenai 	/* Debug FS nodes common to all T5 and later adapters.
3178c778af7dSHariprasad Shenai 	 */
3179c778af7dSHariprasad Shenai 	static struct t4_debugfs_entry t5_debugfs_files[] = {
3180c778af7dSHariprasad Shenai 		{ "obq_sge_rx_q0", &cim_obq_fops, S_IRUSR, 6 },
3181c778af7dSHariprasad Shenai 		{ "obq_sge_rx_q1", &cim_obq_fops, S_IRUSR, 7 },
3182c778af7dSHariprasad Shenai 	};
3183c778af7dSHariprasad Shenai 
3184fd88b31aSHariprasad Shenai 	add_debugfs_files(adap,
3185fd88b31aSHariprasad Shenai 			  t4_debugfs_files,
3186fd88b31aSHariprasad Shenai 			  ARRAY_SIZE(t4_debugfs_files));
3187c778af7dSHariprasad Shenai 	if (!is_t4(adap->params.chip))
3188c778af7dSHariprasad Shenai 		add_debugfs_files(adap,
3189c778af7dSHariprasad Shenai 				  t5_debugfs_files,
3190c778af7dSHariprasad Shenai 				  ARRAY_SIZE(t5_debugfs_files));
3191fd88b31aSHariprasad Shenai 
31926559a7e8SHariprasad Shenai 	i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
31936559a7e8SHariprasad Shenai 	if (i & EDRAM0_ENABLE_F) {
31946559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
31956559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
3196fd88b31aSHariprasad Shenai 	}
31976559a7e8SHariprasad Shenai 	if (i & EDRAM1_ENABLE_F) {
31986559a7e8SHariprasad Shenai 		size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
31996559a7e8SHariprasad Shenai 		add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
3200fd88b31aSHariprasad Shenai 	}
32013ccc6cf7SHariprasad Shenai 	if (is_t5(adap->params.chip)) {
32026559a7e8SHariprasad Shenai 		if (i & EXT_MEM0_ENABLE_F) {
32036559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
3204fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc0", MEM_MC0,
32056559a7e8SHariprasad Shenai 					EXT_MEM0_SIZE_G(size));
3206fd88b31aSHariprasad Shenai 		}
32076559a7e8SHariprasad Shenai 		if (i & EXT_MEM1_ENABLE_F) {
32086559a7e8SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
3209fd88b31aSHariprasad Shenai 			add_debugfs_mem(adap, "mc1", MEM_MC1,
32106559a7e8SHariprasad Shenai 					EXT_MEM1_SIZE_G(size));
3211fd88b31aSHariprasad Shenai 		}
32123ccc6cf7SHariprasad Shenai 	} else {
321321a44763SDan Carpenter 		if (i & EXT_MEM_ENABLE_F) {
32143ccc6cf7SHariprasad Shenai 			size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
32153ccc6cf7SHariprasad Shenai 			add_debugfs_mem(adap, "mc", MEM_MC,
32163ccc6cf7SHariprasad Shenai 					EXT_MEM_SIZE_G(size));
3217fd88b31aSHariprasad Shenai 		}
321821a44763SDan Carpenter 	}
321949216c1cSHariprasad Shenai 
3220c1d81b1cSDavid Howells 	de = debugfs_create_file_size("flash", S_IRUSR, adap->debugfs_root, adap,
3221c1d81b1cSDavid Howells 				      &flash_debugfs_fops, adap->params.sf_size);
32220b2c2a93SHariprasad Shenai 	debugfs_create_bool("use_backdoor", S_IWUSR | S_IRUSR,
32230b2c2a93SHariprasad Shenai 			    adap->debugfs_root, &adap->use_bd);
32248e3d04fdSHariprasad Shenai 	debugfs_create_bool("trace_rss", S_IWUSR | S_IRUSR,
32258e3d04fdSHariprasad Shenai 			    adap->debugfs_root, &adap->trace_rss);
322649216c1cSHariprasad Shenai 
3227fd88b31aSHariprasad Shenai 	return 0;
3228fd88b31aSHariprasad Shenai }
3229