]>
Commit | Line | Data |
---|---|---|
fd88b31a HS |
1 | /* |
2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. | |
3 | * | |
4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. | |
5 | * | |
6 | * This software is available to you under a choice of one of two | |
7 | * licenses. You may choose to be licensed under the terms of the GNU | |
8 | * General Public License (GPL) Version 2, available from the file | |
9 | * COPYING in the main directory of this source tree, or the | |
10 | * OpenIB.org BSD license below: | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or | |
13 | * without modification, are permitted provided that the following | |
14 | * conditions are met: | |
15 | * | |
16 | * - Redistributions of source code must retain the above | |
17 | * copyright notice, this list of conditions and the following | |
18 | * disclaimer. | |
19 | * | |
20 | * - Redistributions in binary form must reproduce the above | |
21 | * copyright notice, this list of conditions and the following | |
22 | * disclaimer in the documentation and/or other materials | |
23 | * provided with the distribution. | |
24 | * | |
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
32 | * SOFTWARE. | |
33 | */ | |
34 | ||
35 | #include <linux/seq_file.h> | |
36 | #include <linux/debugfs.h> | |
37 | #include <linux/string_helpers.h> | |
38 | #include <linux/sort.h> | |
39 | ||
40 | #include "cxgb4.h" | |
41 | #include "t4_regs.h" | |
42 | #include "t4fw_api.h" | |
43 | #include "cxgb4_debugfs.h" | |
b5a02f50 | 44 | #include "clip_tbl.h" |
fd88b31a HS |
45 | #include "l2t.h" |
46 | ||
f1ff24aa HS |
47 | /* generic seq_file support for showing a table of size rows x width. */ |
48 | static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos) | |
49 | { | |
50 | pos -= tb->skip_first; | |
51 | return pos >= tb->rows ? NULL : &tb->data[pos * tb->width]; | |
52 | } | |
53 | ||
54 | static void *seq_tab_start(struct seq_file *seq, loff_t *pos) | |
55 | { | |
56 | struct seq_tab *tb = seq->private; | |
57 | ||
58 | if (tb->skip_first && *pos == 0) | |
59 | return SEQ_START_TOKEN; | |
60 | ||
61 | return seq_tab_get_idx(tb, *pos); | |
62 | } | |
63 | ||
64 | static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos) | |
65 | { | |
66 | v = seq_tab_get_idx(seq->private, *pos + 1); | |
67 | if (v) | |
68 | ++*pos; | |
69 | return v; | |
70 | } | |
71 | ||
72 | static void seq_tab_stop(struct seq_file *seq, void *v) | |
73 | { | |
74 | } | |
75 | ||
76 | static int seq_tab_show(struct seq_file *seq, void *v) | |
77 | { | |
78 | const struct seq_tab *tb = seq->private; | |
79 | ||
80 | return tb->show(seq, v, ((char *)v - tb->data) / tb->width); | |
81 | } | |
82 | ||
83 | static const struct seq_operations seq_tab_ops = { | |
84 | .start = seq_tab_start, | |
85 | .next = seq_tab_next, | |
86 | .stop = seq_tab_stop, | |
87 | .show = seq_tab_show | |
88 | }; | |
89 | ||
90 | struct seq_tab *seq_open_tab(struct file *f, unsigned int rows, | |
91 | unsigned int width, unsigned int have_header, | |
92 | int (*show)(struct seq_file *seq, void *v, int i)) | |
93 | { | |
94 | struct seq_tab *p; | |
95 | ||
96 | p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width); | |
97 | if (p) { | |
98 | p->show = show; | |
99 | p->rows = rows; | |
100 | p->width = width; | |
101 | p->skip_first = have_header != 0; | |
102 | } | |
103 | return p; | |
104 | } | |
105 | ||
106 | static int cim_la_show(struct seq_file *seq, void *v, int idx) | |
107 | { | |
108 | if (v == SEQ_START_TOKEN) | |
109 | seq_puts(seq, "Status Data PC LS0Stat LS0Addr " | |
110 | " LS0Data\n"); | |
111 | else { | |
112 | const u32 *p = v; | |
113 | ||
114 | seq_printf(seq, | |
115 | " %02x %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n", | |
116 | (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4, | |
117 | p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5], | |
118 | p[6], p[7]); | |
119 | } | |
120 | return 0; | |
121 | } | |
122 | ||
123 | static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx) | |
124 | { | |
125 | if (v == SEQ_START_TOKEN) { | |
126 | seq_puts(seq, "Status Data PC\n"); | |
127 | } else { | |
128 | const u32 *p = v; | |
129 | ||
130 | seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6], | |
131 | p[7]); | |
132 | seq_printf(seq, " %02x %02x%06x %02x%06x\n", | |
133 | (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8, | |
134 | p[4] & 0xff, p[5] >> 8); | |
135 | seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff, | |
136 | p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4); | |
137 | } | |
138 | return 0; | |
139 | } | |
140 | ||
141 | static int cim_la_open(struct inode *inode, struct file *file) | |
142 | { | |
143 | int ret; | |
144 | unsigned int cfg; | |
145 | struct seq_tab *p; | |
146 | struct adapter *adap = inode->i_private; | |
147 | ||
148 | ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg); | |
149 | if (ret) | |
150 | return ret; | |
151 | ||
152 | p = seq_open_tab(file, adap->params.cim_la_size / 8, 8 * sizeof(u32), 1, | |
153 | cfg & UPDBGLACAPTPCONLY_F ? | |
154 | cim_la_show_3in1 : cim_la_show); | |
155 | if (!p) | |
156 | return -ENOMEM; | |
157 | ||
158 | ret = t4_cim_read_la(adap, (u32 *)p->data, NULL); | |
159 | if (ret) | |
160 | seq_release_private(inode, file); | |
161 | return ret; | |
162 | } | |
163 | ||
164 | static const struct file_operations cim_la_fops = { | |
165 | .owner = THIS_MODULE, | |
166 | .open = cim_la_open, | |
167 | .read = seq_read, | |
168 | .llseek = seq_lseek, | |
169 | .release = seq_release_private | |
170 | }; | |
171 | ||
74b3092c HS |
172 | static int cim_qcfg_show(struct seq_file *seq, void *v) |
173 | { | |
174 | static const char * const qname[] = { | |
175 | "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", | |
176 | "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", | |
177 | "SGE0-RX", "SGE1-RX" | |
178 | }; | |
179 | ||
180 | int i; | |
181 | struct adapter *adap = seq->private; | |
182 | u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; | |
183 | u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; | |
184 | u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))]; | |
185 | u16 thres[CIM_NUM_IBQ]; | |
186 | u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr; | |
187 | u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5]; | |
188 | u32 *p = stat; | |
189 | int cim_num_obq = is_t4(adap->params.chip) ? | |
190 | CIM_NUM_OBQ : CIM_NUM_OBQ_T5; | |
191 | ||
192 | i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A : | |
193 | UP_IBQ_0_SHADOW_RDADDR_A, | |
194 | ARRAY_SIZE(stat), stat); | |
195 | if (!i) { | |
196 | if (is_t4(adap->params.chip)) { | |
197 | i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A, | |
198 | ARRAY_SIZE(obq_wr_t4), obq_wr_t4); | |
199 | wr = obq_wr_t4; | |
200 | } else { | |
201 | i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A, | |
202 | ARRAY_SIZE(obq_wr_t5), obq_wr_t5); | |
203 | wr = obq_wr_t5; | |
204 | } | |
205 | } | |
206 | if (i) | |
207 | return i; | |
208 | ||
209 | t4_read_cimq_cfg(adap, base, size, thres); | |
210 | ||
211 | seq_printf(seq, | |
212 | " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n"); | |
213 | for (i = 0; i < CIM_NUM_IBQ; i++, p += 4) | |
214 | seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n", | |
215 | qname[i], base[i], size[i], thres[i], | |
216 | IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]), | |
217 | QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]), | |
218 | QUEREMFLITS_G(p[2]) * 16); | |
219 | for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2) | |
220 | seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n", | |
221 | qname[i], base[i], size[i], | |
222 | QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i], | |
223 | QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]), | |
224 | QUEREMFLITS_G(p[2]) * 16); | |
225 | return 0; | |
226 | } | |
227 | ||
228 | static int cim_qcfg_open(struct inode *inode, struct file *file) | |
229 | { | |
230 | return single_open(file, cim_qcfg_show, inode->i_private); | |
231 | } | |
232 | ||
233 | static const struct file_operations cim_qcfg_fops = { | |
234 | .owner = THIS_MODULE, | |
235 | .open = cim_qcfg_open, | |
236 | .read = seq_read, | |
237 | .llseek = seq_lseek, | |
238 | .release = single_release, | |
239 | }; | |
240 | ||
f1ff24aa | 241 | /* Firmware Device Log dump. */ |
49aa284f HS |
242 | static const char * const devlog_level_strings[] = { |
243 | [FW_DEVLOG_LEVEL_EMERG] = "EMERG", | |
244 | [FW_DEVLOG_LEVEL_CRIT] = "CRIT", | |
245 | [FW_DEVLOG_LEVEL_ERR] = "ERR", | |
246 | [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE", | |
247 | [FW_DEVLOG_LEVEL_INFO] = "INFO", | |
248 | [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG" | |
249 | }; | |
250 | ||
251 | static const char * const devlog_facility_strings[] = { | |
252 | [FW_DEVLOG_FACILITY_CORE] = "CORE", | |
253 | [FW_DEVLOG_FACILITY_SCHED] = "SCHED", | |
254 | [FW_DEVLOG_FACILITY_TIMER] = "TIMER", | |
255 | [FW_DEVLOG_FACILITY_RES] = "RES", | |
256 | [FW_DEVLOG_FACILITY_HW] = "HW", | |
257 | [FW_DEVLOG_FACILITY_FLR] = "FLR", | |
258 | [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ", | |
259 | [FW_DEVLOG_FACILITY_PHY] = "PHY", | |
260 | [FW_DEVLOG_FACILITY_MAC] = "MAC", | |
261 | [FW_DEVLOG_FACILITY_PORT] = "PORT", | |
262 | [FW_DEVLOG_FACILITY_VI] = "VI", | |
263 | [FW_DEVLOG_FACILITY_FILTER] = "FILTER", | |
264 | [FW_DEVLOG_FACILITY_ACL] = "ACL", | |
265 | [FW_DEVLOG_FACILITY_TM] = "TM", | |
266 | [FW_DEVLOG_FACILITY_QFC] = "QFC", | |
267 | [FW_DEVLOG_FACILITY_DCB] = "DCB", | |
268 | [FW_DEVLOG_FACILITY_ETH] = "ETH", | |
269 | [FW_DEVLOG_FACILITY_OFLD] = "OFLD", | |
270 | [FW_DEVLOG_FACILITY_RI] = "RI", | |
271 | [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI", | |
272 | [FW_DEVLOG_FACILITY_FCOE] = "FCOE", | |
273 | [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI", | |
274 | [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE" | |
275 | }; | |
276 | ||
277 | /* Information gathered by Device Log Open routine for the display routine. | |
278 | */ | |
279 | struct devlog_info { | |
280 | unsigned int nentries; /* number of entries in log[] */ | |
281 | unsigned int first; /* first [temporal] entry in log[] */ | |
282 | struct fw_devlog_e log[0]; /* Firmware Device Log */ | |
283 | }; | |
284 | ||
285 | /* Dump a Firmaware Device Log entry. | |
286 | */ | |
287 | static int devlog_show(struct seq_file *seq, void *v) | |
288 | { | |
289 | if (v == SEQ_START_TOKEN) | |
290 | seq_printf(seq, "%10s %15s %8s %8s %s\n", | |
291 | "Seq#", "Tstamp", "Level", "Facility", "Message"); | |
292 | else { | |
293 | struct devlog_info *dinfo = seq->private; | |
294 | int fidx = (uintptr_t)v - 2; | |
295 | unsigned long index; | |
296 | struct fw_devlog_e *e; | |
297 | ||
298 | /* Get a pointer to the log entry to display. Skip unused log | |
299 | * entries. | |
300 | */ | |
301 | index = dinfo->first + fidx; | |
302 | if (index >= dinfo->nentries) | |
303 | index -= dinfo->nentries; | |
304 | e = &dinfo->log[index]; | |
305 | if (e->timestamp == 0) | |
306 | return 0; | |
307 | ||
308 | /* Print the message. This depends on the firmware using | |
309 | * exactly the same formating strings as the kernel so we may | |
310 | * eventually have to put a format interpreter in here ... | |
311 | */ | |
312 | seq_printf(seq, "%10d %15llu %8s %8s ", | |
313 | e->seqno, e->timestamp, | |
314 | (e->level < ARRAY_SIZE(devlog_level_strings) | |
315 | ? devlog_level_strings[e->level] | |
316 | : "UNKNOWN"), | |
317 | (e->facility < ARRAY_SIZE(devlog_facility_strings) | |
318 | ? devlog_facility_strings[e->facility] | |
319 | : "UNKNOWN")); | |
320 | seq_printf(seq, e->fmt, e->params[0], e->params[1], | |
321 | e->params[2], e->params[3], e->params[4], | |
322 | e->params[5], e->params[6], e->params[7]); | |
323 | } | |
324 | return 0; | |
325 | } | |
326 | ||
327 | /* Sequential File Operations for Device Log. | |
328 | */ | |
329 | static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos) | |
330 | { | |
331 | if (pos > dinfo->nentries) | |
332 | return NULL; | |
333 | ||
334 | return (void *)(uintptr_t)(pos + 1); | |
335 | } | |
336 | ||
337 | static void *devlog_start(struct seq_file *seq, loff_t *pos) | |
338 | { | |
339 | struct devlog_info *dinfo = seq->private; | |
340 | ||
341 | return (*pos | |
342 | ? devlog_get_idx(dinfo, *pos) | |
343 | : SEQ_START_TOKEN); | |
344 | } | |
345 | ||
346 | static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos) | |
347 | { | |
348 | struct devlog_info *dinfo = seq->private; | |
349 | ||
350 | (*pos)++; | |
351 | return devlog_get_idx(dinfo, *pos); | |
352 | } | |
353 | ||
354 | static void devlog_stop(struct seq_file *seq, void *v) | |
355 | { | |
356 | } | |
357 | ||
358 | static const struct seq_operations devlog_seq_ops = { | |
359 | .start = devlog_start, | |
360 | .next = devlog_next, | |
361 | .stop = devlog_stop, | |
362 | .show = devlog_show | |
363 | }; | |
364 | ||
365 | /* Set up for reading the firmware's device log. We read the entire log here | |
366 | * and then display it incrementally in devlog_show(). | |
367 | */ | |
368 | static int devlog_open(struct inode *inode, struct file *file) | |
369 | { | |
370 | struct adapter *adap = inode->i_private; | |
371 | struct devlog_params *dparams = &adap->params.devlog; | |
372 | struct devlog_info *dinfo; | |
373 | unsigned int index; | |
374 | u32 fseqno; | |
375 | int ret; | |
376 | ||
377 | /* If we don't know where the log is we can't do anything. | |
378 | */ | |
379 | if (dparams->start == 0) | |
380 | return -ENXIO; | |
381 | ||
382 | /* Allocate the space to read in the firmware's device log and set up | |
383 | * for the iterated call to our display function. | |
384 | */ | |
385 | dinfo = __seq_open_private(file, &devlog_seq_ops, | |
386 | sizeof(*dinfo) + dparams->size); | |
387 | if (!dinfo) | |
388 | return -ENOMEM; | |
389 | ||
390 | /* Record the basic log buffer information and read in the raw log. | |
391 | */ | |
392 | dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e)); | |
393 | dinfo->first = 0; | |
394 | spin_lock(&adap->win0_lock); | |
395 | ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype, | |
396 | dparams->start, dparams->size, (__be32 *)dinfo->log, | |
397 | T4_MEMORY_READ); | |
398 | spin_unlock(&adap->win0_lock); | |
399 | if (ret) { | |
400 | seq_release_private(inode, file); | |
401 | return ret; | |
402 | } | |
403 | ||
404 | /* Translate log multi-byte integral elements into host native format | |
405 | * and determine where the first entry in the log is. | |
406 | */ | |
407 | for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) { | |
408 | struct fw_devlog_e *e = &dinfo->log[index]; | |
409 | int i; | |
410 | __u32 seqno; | |
411 | ||
412 | if (e->timestamp == 0) | |
413 | continue; | |
414 | ||
415 | e->timestamp = (__force __be64)be64_to_cpu(e->timestamp); | |
416 | seqno = be32_to_cpu(e->seqno); | |
417 | for (i = 0; i < 8; i++) | |
418 | e->params[i] = | |
419 | (__force __be32)be32_to_cpu(e->params[i]); | |
420 | ||
421 | if (seqno < fseqno) { | |
422 | fseqno = seqno; | |
423 | dinfo->first = index; | |
424 | } | |
425 | } | |
426 | return 0; | |
427 | } | |
428 | ||
429 | static const struct file_operations devlog_fops = { | |
430 | .owner = THIS_MODULE, | |
431 | .open = devlog_open, | |
432 | .read = seq_read, | |
433 | .llseek = seq_lseek, | |
434 | .release = seq_release_private | |
435 | }; | |
436 | ||
49216c1c HS |
437 | static ssize_t flash_read(struct file *file, char __user *buf, size_t count, |
438 | loff_t *ppos) | |
439 | { | |
440 | loff_t pos = *ppos; | |
441 | loff_t avail = FILE_DATA(file)->i_size; | |
442 | struct adapter *adap = file->private_data; | |
443 | ||
444 | if (pos < 0) | |
445 | return -EINVAL; | |
446 | if (pos >= avail) | |
447 | return 0; | |
448 | if (count > avail - pos) | |
449 | count = avail - pos; | |
450 | ||
451 | while (count) { | |
452 | size_t len; | |
453 | int ret, ofst; | |
454 | u8 data[256]; | |
455 | ||
456 | ofst = pos & 3; | |
457 | len = min(count + ofst, sizeof(data)); | |
458 | ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4, | |
459 | (u32 *)data, 1); | |
460 | if (ret) | |
461 | return ret; | |
462 | ||
463 | len -= ofst; | |
464 | if (copy_to_user(buf, data + ofst, len)) | |
465 | return -EFAULT; | |
466 | ||
467 | buf += len; | |
468 | pos += len; | |
469 | count -= len; | |
470 | } | |
471 | count = pos - *ppos; | |
472 | *ppos = pos; | |
473 | return count; | |
474 | } | |
475 | ||
476 | static const struct file_operations flash_debugfs_fops = { | |
477 | .owner = THIS_MODULE, | |
478 | .open = mem_open, | |
479 | .read = flash_read, | |
480 | }; | |
481 | ||
ef82f662 HS |
482 | static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask) |
483 | { | |
484 | *mask = x | y; | |
485 | y = (__force u64)cpu_to_be64(y); | |
486 | memcpy(addr, (char *)&y + 2, ETH_ALEN); | |
487 | } | |
488 | ||
489 | static int mps_tcam_show(struct seq_file *seq, void *v) | |
490 | { | |
491 | if (v == SEQ_START_TOKEN) | |
492 | seq_puts(seq, "Idx Ethernet address Mask Vld Ports PF" | |
493 | " VF Replication " | |
494 | "P0 P1 P2 P3 ML\n"); | |
495 | else { | |
496 | u64 mask; | |
497 | u8 addr[ETH_ALEN]; | |
498 | struct adapter *adap = seq->private; | |
499 | unsigned int idx = (uintptr_t)v - 2; | |
500 | u64 tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx)); | |
501 | u64 tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx)); | |
502 | u32 cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx)); | |
503 | u32 cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx)); | |
504 | u32 rplc[4] = {0, 0, 0, 0}; | |
505 | ||
506 | if (tcamx & tcamy) { | |
507 | seq_printf(seq, "%3u -\n", idx); | |
508 | goto out; | |
509 | } | |
510 | ||
511 | if (cls_lo & REPLICATE_F) { | |
512 | struct fw_ldst_cmd ldst_cmd; | |
513 | int ret; | |
514 | ||
515 | memset(&ldst_cmd, 0, sizeof(ldst_cmd)); | |
516 | ldst_cmd.op_to_addrspace = | |
517 | htonl(FW_CMD_OP_V(FW_LDST_CMD) | | |
518 | FW_CMD_REQUEST_F | | |
519 | FW_CMD_READ_F | | |
520 | FW_LDST_CMD_ADDRSPACE_V( | |
521 | FW_LDST_ADDRSPC_MPS)); | |
522 | ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd)); | |
523 | ldst_cmd.u.mps.fid_ctl = | |
524 | htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) | | |
525 | FW_LDST_CMD_CTL_V(idx)); | |
526 | ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, | |
527 | sizeof(ldst_cmd), &ldst_cmd); | |
528 | if (ret) | |
529 | dev_warn(adap->pdev_dev, "Can't read MPS " | |
530 | "replication map for idx %d: %d\n", | |
531 | idx, -ret); | |
532 | else { | |
533 | rplc[0] = ntohl(ldst_cmd.u.mps.rplc31_0); | |
534 | rplc[1] = ntohl(ldst_cmd.u.mps.rplc63_32); | |
535 | rplc[2] = ntohl(ldst_cmd.u.mps.rplc95_64); | |
536 | rplc[3] = ntohl(ldst_cmd.u.mps.rplc127_96); | |
537 | } | |
538 | } | |
539 | ||
540 | tcamxy2valmask(tcamx, tcamy, addr, &mask); | |
541 | seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x %012llx" | |
542 | "%3c %#x%4u%4d", | |
543 | idx, addr[0], addr[1], addr[2], addr[3], addr[4], | |
544 | addr[5], (unsigned long long)mask, | |
545 | (cls_lo & SRAM_VLD_F) ? 'Y' : 'N', PORTMAP_G(cls_hi), | |
546 | PF_G(cls_lo), | |
547 | (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1); | |
548 | if (cls_lo & REPLICATE_F) | |
549 | seq_printf(seq, " %08x %08x %08x %08x", | |
550 | rplc[3], rplc[2], rplc[1], rplc[0]); | |
551 | else | |
552 | seq_printf(seq, "%36c", ' '); | |
553 | seq_printf(seq, "%4u%3u%3u%3u %#x\n", | |
554 | SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo), | |
555 | SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo), | |
556 | (cls_lo >> MULTILISTEN0_S) & 0xf); | |
557 | } | |
558 | out: return 0; | |
559 | } | |
560 | ||
561 | static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos) | |
562 | { | |
563 | struct adapter *adap = seq->private; | |
564 | int max_mac_addr = is_t4(adap->params.chip) ? | |
565 | NUM_MPS_CLS_SRAM_L_INSTANCES : | |
566 | NUM_MPS_T5_CLS_SRAM_L_INSTANCES; | |
567 | return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL); | |
568 | } | |
569 | ||
570 | static void *mps_tcam_start(struct seq_file *seq, loff_t *pos) | |
571 | { | |
572 | return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN; | |
573 | } | |
574 | ||
575 | static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos) | |
576 | { | |
577 | ++*pos; | |
578 | return mps_tcam_get_idx(seq, *pos); | |
579 | } | |
580 | ||
581 | static void mps_tcam_stop(struct seq_file *seq, void *v) | |
582 | { | |
583 | } | |
584 | ||
585 | static const struct seq_operations mps_tcam_seq_ops = { | |
586 | .start = mps_tcam_start, | |
587 | .next = mps_tcam_next, | |
588 | .stop = mps_tcam_stop, | |
589 | .show = mps_tcam_show | |
590 | }; | |
591 | ||
592 | static int mps_tcam_open(struct inode *inode, struct file *file) | |
593 | { | |
594 | int res = seq_open(file, &mps_tcam_seq_ops); | |
595 | ||
596 | if (!res) { | |
597 | struct seq_file *seq = file->private_data; | |
598 | ||
599 | seq->private = inode->i_private; | |
600 | } | |
601 | return res; | |
602 | } | |
603 | ||
604 | static const struct file_operations mps_tcam_debugfs_fops = { | |
605 | .owner = THIS_MODULE, | |
606 | .open = mps_tcam_open, | |
607 | .read = seq_read, | |
608 | .llseek = seq_lseek, | |
609 | .release = seq_release, | |
610 | }; | |
611 | ||
b5a02f50 AB |
612 | #if IS_ENABLED(CONFIG_IPV6) |
613 | static int clip_tbl_open(struct inode *inode, struct file *file) | |
614 | { | |
615 | return single_open(file, clip_tbl_show, PDE_DATA(inode)); | |
616 | } | |
617 | ||
618 | static const struct file_operations clip_tbl_debugfs_fops = { | |
619 | .owner = THIS_MODULE, | |
620 | .open = clip_tbl_open, | |
621 | .read = seq_read, | |
622 | .llseek = seq_lseek, | |
623 | .release = single_release | |
624 | }; | |
625 | #endif | |
626 | ||
49216c1c HS |
627 | int mem_open(struct inode *inode, struct file *file) |
628 | { | |
629 | unsigned int mem; | |
630 | struct adapter *adap; | |
631 | ||
632 | file->private_data = inode->i_private; | |
633 | ||
634 | mem = (uintptr_t)file->private_data & 0x3; | |
635 | adap = file->private_data - mem; | |
636 | ||
637 | (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH); | |
638 | ||
639 | return 0; | |
640 | } | |
641 | ||
fd88b31a HS |
642 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, |
643 | loff_t *ppos) | |
644 | { | |
645 | loff_t pos = *ppos; | |
646 | loff_t avail = file_inode(file)->i_size; | |
647 | unsigned int mem = (uintptr_t)file->private_data & 3; | |
648 | struct adapter *adap = file->private_data - mem; | |
649 | __be32 *data; | |
650 | int ret; | |
651 | ||
652 | if (pos < 0) | |
653 | return -EINVAL; | |
654 | if (pos >= avail) | |
655 | return 0; | |
656 | if (count > avail - pos) | |
657 | count = avail - pos; | |
658 | ||
659 | data = t4_alloc_mem(count); | |
660 | if (!data) | |
661 | return -ENOMEM; | |
662 | ||
663 | spin_lock(&adap->win0_lock); | |
664 | ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ); | |
665 | spin_unlock(&adap->win0_lock); | |
666 | if (ret) { | |
667 | t4_free_mem(data); | |
668 | return ret; | |
669 | } | |
670 | ret = copy_to_user(buf, data, count); | |
671 | ||
672 | t4_free_mem(data); | |
673 | if (ret) | |
674 | return -EFAULT; | |
675 | ||
676 | *ppos = pos + count; | |
677 | return count; | |
678 | } | |
fd88b31a HS |
679 | static const struct file_operations mem_debugfs_fops = { |
680 | .owner = THIS_MODULE, | |
681 | .open = simple_open, | |
682 | .read = mem_read, | |
683 | .llseek = default_llseek, | |
684 | }; | |
685 | ||
49216c1c HS |
686 | static void set_debugfs_file_size(struct dentry *de, loff_t size) |
687 | { | |
688 | if (!IS_ERR(de) && de->d_inode) | |
689 | de->d_inode->i_size = size; | |
690 | } | |
691 | ||
fd88b31a HS |
692 | static void add_debugfs_mem(struct adapter *adap, const char *name, |
693 | unsigned int idx, unsigned int size_mb) | |
694 | { | |
695 | struct dentry *de; | |
696 | ||
697 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, | |
698 | (void *)adap + idx, &mem_debugfs_fops); | |
699 | if (de && de->d_inode) | |
700 | de->d_inode->i_size = size_mb << 20; | |
701 | } | |
702 | ||
703 | /* Add an array of Debug FS files. | |
704 | */ | |
705 | void add_debugfs_files(struct adapter *adap, | |
706 | struct t4_debugfs_entry *files, | |
707 | unsigned int nfiles) | |
708 | { | |
709 | int i; | |
710 | ||
711 | /* debugfs support is best effort */ | |
712 | for (i = 0; i < nfiles; i++) | |
713 | debugfs_create_file(files[i].name, files[i].mode, | |
714 | adap->debugfs_root, | |
715 | (void *)adap + files[i].data, | |
716 | files[i].ops); | |
717 | } | |
718 | ||
719 | int t4_setup_debugfs(struct adapter *adap) | |
720 | { | |
721 | int i; | |
722 | u32 size; | |
49216c1c | 723 | struct dentry *de; |
fd88b31a HS |
724 | |
725 | static struct t4_debugfs_entry t4_debugfs_files[] = { | |
f1ff24aa | 726 | { "cim_la", &cim_la_fops, S_IRUSR, 0 }, |
74b3092c | 727 | { "cim_qcfg", &cim_qcfg_fops, S_IRUSR, 0 }, |
49aa284f | 728 | { "devlog", &devlog_fops, S_IRUSR, 0 }, |
fd88b31a | 729 | { "l2t", &t4_l2t_fops, S_IRUSR, 0}, |
ef82f662 | 730 | { "mps_tcam", &mps_tcam_debugfs_fops, S_IRUSR, 0 }, |
b5a02f50 AB |
731 | #if IS_ENABLED(CONFIG_IPV6) |
732 | { "clip_tbl", &clip_tbl_debugfs_fops, S_IRUSR, 0 }, | |
733 | #endif | |
fd88b31a HS |
734 | }; |
735 | ||
736 | add_debugfs_files(adap, | |
737 | t4_debugfs_files, | |
738 | ARRAY_SIZE(t4_debugfs_files)); | |
739 | ||
6559a7e8 HS |
740 | i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A); |
741 | if (i & EDRAM0_ENABLE_F) { | |
742 | size = t4_read_reg(adap, MA_EDRAM0_BAR_A); | |
743 | add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size)); | |
fd88b31a | 744 | } |
6559a7e8 HS |
745 | if (i & EDRAM1_ENABLE_F) { |
746 | size = t4_read_reg(adap, MA_EDRAM1_BAR_A); | |
747 | add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size)); | |
fd88b31a HS |
748 | } |
749 | if (is_t4(adap->params.chip)) { | |
6559a7e8 HS |
750 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A); |
751 | if (i & EXT_MEM_ENABLE_F) | |
fd88b31a | 752 | add_debugfs_mem(adap, "mc", MEM_MC, |
6559a7e8 | 753 | EXT_MEM_SIZE_G(size)); |
fd88b31a | 754 | } else { |
6559a7e8 HS |
755 | if (i & EXT_MEM0_ENABLE_F) { |
756 | size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A); | |
fd88b31a | 757 | add_debugfs_mem(adap, "mc0", MEM_MC0, |
6559a7e8 | 758 | EXT_MEM0_SIZE_G(size)); |
fd88b31a | 759 | } |
6559a7e8 HS |
760 | if (i & EXT_MEM1_ENABLE_F) { |
761 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A); | |
fd88b31a | 762 | add_debugfs_mem(adap, "mc1", MEM_MC1, |
6559a7e8 | 763 | EXT_MEM1_SIZE_G(size)); |
fd88b31a HS |
764 | } |
765 | } | |
49216c1c HS |
766 | |
767 | de = debugfs_create_file("flash", S_IRUSR, adap->debugfs_root, adap, | |
768 | &flash_debugfs_fops); | |
769 | set_debugfs_file_size(de, adap->params.sf_size); | |
770 | ||
fd88b31a HS |
771 | return 0; |
772 | } |