2 * Copyright(c) 2015-2018 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include <linux/debugfs.h>
48 #include <linux/seq_file.h>
49 #include <linux/kernel.h>
50 #include <linux/export.h>
51 #include <linux/module.h>
52 #include <linux/string.h>
53 #include <linux/types.h>
54 #include <linux/ratelimit.h>
55 #include <linux/fault-inject.h>
64 static struct dentry
*hfi1_dbg_root
;
66 /* wrappers to enforce srcu in seq file */
67 static ssize_t
hfi1_seq_read(
73 struct dentry
*d
= file
->f_path
.dentry
;
76 r
= debugfs_file_get(d
);
79 r
= seq_read(file
, buf
, size
, ppos
);
84 static loff_t
hfi1_seq_lseek(
89 struct dentry
*d
= file
->f_path
.dentry
;
92 r
= debugfs_file_get(d
);
95 r
= seq_lseek(file
, offset
, whence
);
100 #define private2dd(file) (file_inode(file)->i_private)
101 #define private2ppd(file) (file_inode(file)->i_private)
103 #define DEBUGFS_SEQ_FILE_OPS(name) \
104 static const struct seq_operations _##name##_seq_ops = { \
105 .start = _##name##_seq_start, \
106 .next = _##name##_seq_next, \
107 .stop = _##name##_seq_stop, \
108 .show = _##name##_seq_show \
111 #define DEBUGFS_SEQ_FILE_OPEN(name) \
112 static int _##name##_open(struct inode *inode, struct file *s) \
114 struct seq_file *seq; \
116 ret = seq_open(s, &_##name##_seq_ops); \
119 seq = s->private_data; \
120 seq->private = inode->i_private; \
124 #define DEBUGFS_FILE_OPS(name) \
125 static const struct file_operations _##name##_file_ops = { \
126 .owner = THIS_MODULE, \
127 .open = _##name##_open, \
128 .read = hfi1_seq_read, \
129 .llseek = hfi1_seq_lseek, \
130 .release = seq_release \
133 #define DEBUGFS_FILE_CREATE(name, parent, data, ops, mode) \
135 struct dentry *ent; \
136 ent = debugfs_create_file(name, mode, parent, \
139 pr_warn("create of %s failed\n", name); \
142 #define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \
143 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
145 static void *_opcode_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
147 struct hfi1_opcode_stats_perctx
*opstats
;
149 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
154 static void *_opcode_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
156 struct hfi1_opcode_stats_perctx
*opstats
;
159 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
164 static void _opcode_stats_seq_stop(struct seq_file
*s
, void *v
)
168 static int opcode_stats_show(struct seq_file
*s
, u8 i
, u64 packets
, u64 bytes
)
170 if (!packets
&& !bytes
)
172 seq_printf(s
, "%02x %llu/%llu\n", i
,
173 (unsigned long long)packets
,
174 (unsigned long long)bytes
);
179 static int _opcode_stats_seq_show(struct seq_file
*s
, void *v
)
183 u64 n_packets
= 0, n_bytes
= 0;
184 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
185 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
186 struct hfi1_ctxtdata
*rcd
;
188 for (j
= 0; j
< dd
->first_dyn_alloc_ctxt
; j
++) {
189 rcd
= hfi1_rcd_get_by_index(dd
, j
);
191 n_packets
+= rcd
->opstats
->stats
[i
].n_packets
;
192 n_bytes
+= rcd
->opstats
->stats
[i
].n_bytes
;
196 return opcode_stats_show(s
, i
, n_packets
, n_bytes
);
199 DEBUGFS_SEQ_FILE_OPS(opcode_stats
);
200 DEBUGFS_SEQ_FILE_OPEN(opcode_stats
)
201 DEBUGFS_FILE_OPS(opcode_stats
);
203 static void *_tx_opcode_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
205 return _opcode_stats_seq_start(s
, pos
);
208 static void *_tx_opcode_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
210 return _opcode_stats_seq_next(s
, v
, pos
);
213 static void _tx_opcode_stats_seq_stop(struct seq_file
*s
, void *v
)
217 static int _tx_opcode_stats_seq_show(struct seq_file
*s
, void *v
)
222 u64 n_packets
= 0, n_bytes
= 0;
223 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
224 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
226 for_each_possible_cpu(j
) {
227 struct hfi1_opcode_stats_perctx
*s
=
228 per_cpu_ptr(dd
->tx_opstats
, j
);
229 n_packets
+= s
->stats
[i
].n_packets
;
230 n_bytes
+= s
->stats
[i
].n_bytes
;
232 return opcode_stats_show(s
, i
, n_packets
, n_bytes
);
235 DEBUGFS_SEQ_FILE_OPS(tx_opcode_stats
);
236 DEBUGFS_SEQ_FILE_OPEN(tx_opcode_stats
)
237 DEBUGFS_FILE_OPS(tx_opcode_stats
);
239 static void *_ctx_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
241 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
242 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
245 return SEQ_START_TOKEN
;
246 if (*pos
>= dd
->first_dyn_alloc_ctxt
)
251 static void *_ctx_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
253 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
254 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
256 if (v
== SEQ_START_TOKEN
)
260 if (*pos
>= dd
->first_dyn_alloc_ctxt
)
265 static void _ctx_stats_seq_stop(struct seq_file
*s
, void *v
)
267 /* nothing allocated */
270 static int _ctx_stats_seq_show(struct seq_file
*s
, void *v
)
275 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
276 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
277 struct hfi1_ctxtdata
*rcd
;
279 if (v
== SEQ_START_TOKEN
) {
280 seq_puts(s
, "Ctx:npkts\n");
287 rcd
= hfi1_rcd_get_by_index_safe(dd
, i
);
291 for (j
= 0; j
< ARRAY_SIZE(rcd
->opstats
->stats
); j
++)
292 n_packets
+= rcd
->opstats
->stats
[j
].n_packets
;
299 seq_printf(s
, " %llu:%llu\n", i
, n_packets
);
303 DEBUGFS_SEQ_FILE_OPS(ctx_stats
);
304 DEBUGFS_SEQ_FILE_OPEN(ctx_stats
)
305 DEBUGFS_FILE_OPS(ctx_stats
);
307 static void *_qp_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
310 struct rvt_qp_iter
*iter
;
313 iter
= rvt_qp_iter_init(s
->private, 0, NULL
);
315 /* stop calls rcu_read_unlock */
322 if (rvt_qp_iter_next(iter
)) {
331 static void *_qp_stats_seq_next(struct seq_file
*s
, void *iter_ptr
,
335 struct rvt_qp_iter
*iter
= iter_ptr
;
339 if (rvt_qp_iter_next(iter
)) {
347 static void _qp_stats_seq_stop(struct seq_file
*s
, void *iter_ptr
)
353 static int _qp_stats_seq_show(struct seq_file
*s
, void *iter_ptr
)
355 struct rvt_qp_iter
*iter
= iter_ptr
;
360 qp_iter_print(s
, iter
);
365 DEBUGFS_SEQ_FILE_OPS(qp_stats
);
366 DEBUGFS_SEQ_FILE_OPEN(qp_stats
)
367 DEBUGFS_FILE_OPS(qp_stats
);
369 static void *_sdes_seq_start(struct seq_file
*s
, loff_t
*pos
)
371 struct hfi1_ibdev
*ibd
;
372 struct hfi1_devdata
*dd
;
374 ibd
= (struct hfi1_ibdev
*)s
->private;
375 dd
= dd_from_dev(ibd
);
376 if (!dd
->per_sdma
|| *pos
>= dd
->num_sdma
)
381 static void *_sdes_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
383 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
384 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
387 if (!dd
->per_sdma
|| *pos
>= dd
->num_sdma
)
392 static void _sdes_seq_stop(struct seq_file
*s
, void *v
)
396 static int _sdes_seq_show(struct seq_file
*s
, void *v
)
398 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
399 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
403 sdma_seqfile_dump_sde(s
, &dd
->per_sdma
[i
]);
407 DEBUGFS_SEQ_FILE_OPS(sdes
);
408 DEBUGFS_SEQ_FILE_OPEN(sdes
)
409 DEBUGFS_FILE_OPS(sdes
);
411 static void *_rcds_seq_start(struct seq_file
*s
, loff_t
*pos
)
413 struct hfi1_ibdev
*ibd
;
414 struct hfi1_devdata
*dd
;
416 ibd
= (struct hfi1_ibdev
*)s
->private;
417 dd
= dd_from_dev(ibd
);
418 if (!dd
->rcd
|| *pos
>= dd
->n_krcv_queues
)
423 static void *_rcds_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
425 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
426 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
429 if (!dd
->rcd
|| *pos
>= dd
->n_krcv_queues
)
434 static void _rcds_seq_stop(struct seq_file
*s
, void *v
)
438 static int _rcds_seq_show(struct seq_file
*s
, void *v
)
440 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
441 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
442 struct hfi1_ctxtdata
*rcd
;
446 rcd
= hfi1_rcd_get_by_index_safe(dd
, i
);
448 seqfile_dump_rcd(s
, rcd
);
453 DEBUGFS_SEQ_FILE_OPS(rcds
);
454 DEBUGFS_SEQ_FILE_OPEN(rcds
)
455 DEBUGFS_FILE_OPS(rcds
);
457 /* read the per-device counters */
458 static ssize_t
dev_counters_read(struct file
*file
, char __user
*buf
,
459 size_t count
, loff_t
*ppos
)
463 struct hfi1_devdata
*dd
;
466 dd
= private2dd(file
);
467 avail
= hfi1_read_cntrs(dd
, NULL
, &counters
);
468 rval
= simple_read_from_buffer(buf
, count
, ppos
, counters
, avail
);
472 /* read the per-device counters */
473 static ssize_t
dev_names_read(struct file
*file
, char __user
*buf
,
474 size_t count
, loff_t
*ppos
)
478 struct hfi1_devdata
*dd
;
481 dd
= private2dd(file
);
482 avail
= hfi1_read_cntrs(dd
, &names
, NULL
);
483 rval
= simple_read_from_buffer(buf
, count
, ppos
, names
, avail
);
487 struct counter_info
{
489 const struct file_operations ops
;
493 * Could use file_inode(file)->i_ino to figure out which file,
494 * instead of separate routine for each, but for now, this works...
497 /* read the per-port names (same for each port) */
498 static ssize_t
portnames_read(struct file
*file
, char __user
*buf
,
499 size_t count
, loff_t
*ppos
)
503 struct hfi1_devdata
*dd
;
506 dd
= private2dd(file
);
507 avail
= hfi1_read_portcntrs(dd
->pport
, &names
, NULL
);
508 rval
= simple_read_from_buffer(buf
, count
, ppos
, names
, avail
);
512 /* read the per-port counters */
513 static ssize_t
portcntrs_debugfs_read(struct file
*file
, char __user
*buf
,
514 size_t count
, loff_t
*ppos
)
518 struct hfi1_pportdata
*ppd
;
521 ppd
= private2ppd(file
);
522 avail
= hfi1_read_portcntrs(ppd
, NULL
, &counters
);
523 rval
= simple_read_from_buffer(buf
, count
, ppos
, counters
, avail
);
527 static void check_dyn_flag(u64 scratch0
, char *p
, int size
, int *used
,
528 int this_hfi
, int hfi
, u32 flag
, const char *what
)
532 mask
= flag
<< (hfi
? CR_DYN_SHIFT
: 0);
533 if (scratch0
& mask
) {
534 *used
+= scnprintf(p
+ *used
, size
- *used
,
535 " 0x%08x - HFI%d %s in use, %s device\n",
537 this_hfi
== hfi
? "this" : "other");
541 static ssize_t
asic_flags_read(struct file
*file
, char __user
*buf
,
542 size_t count
, loff_t
*ppos
)
544 struct hfi1_pportdata
*ppd
;
545 struct hfi1_devdata
*dd
;
553 ppd
= private2ppd(file
);
557 tmp
= kmalloc(size
, GFP_KERNEL
);
561 scratch0
= read_csr(dd
, ASIC_CFG_SCRATCH
);
562 used
+= scnprintf(tmp
+ used
, size
- used
,
563 "Resource flags: 0x%016llx\n", scratch0
);
565 /* check permanent flag */
566 if (scratch0
& CR_THERM_INIT
) {
567 used
+= scnprintf(tmp
+ used
, size
- used
,
568 " 0x%08x - thermal monitoring initialized\n",
572 /* check each dynamic flag on each HFI */
573 for (i
= 0; i
< 2; i
++) {
574 check_dyn_flag(scratch0
, tmp
, size
, &used
, dd
->hfi1_id
, i
,
576 check_dyn_flag(scratch0
, tmp
, size
, &used
, dd
->hfi1_id
, i
,
578 check_dyn_flag(scratch0
, tmp
, size
, &used
, dd
->hfi1_id
, i
,
579 CR_I2C1
, "i2c chain 1");
580 check_dyn_flag(scratch0
, tmp
, size
, &used
, dd
->hfi1_id
, i
,
581 CR_I2C2
, "i2c chain 2");
583 used
+= scnprintf(tmp
+ used
, size
- used
, "Write bits to clear\n");
585 ret
= simple_read_from_buffer(buf
, count
, ppos
, tmp
, used
);
590 static ssize_t
asic_flags_write(struct file
*file
, const char __user
*buf
,
591 size_t count
, loff_t
*ppos
)
593 struct hfi1_pportdata
*ppd
;
594 struct hfi1_devdata
*dd
;
597 unsigned long long value
;
601 ppd
= private2ppd(file
);
604 /* zero terminate and read the expected integer */
605 buff
= memdup_user_nul(buf
, count
);
607 return PTR_ERR(buff
);
609 ret
= kstrtoull(buff
, 0, &value
);
614 /* obtain exclusive access */
615 mutex_lock(&dd
->asic_data
->asic_resource_mutex
);
616 acquire_hw_mutex(dd
);
618 scratch0
= read_csr(dd
, ASIC_CFG_SCRATCH
);
620 write_csr(dd
, ASIC_CFG_SCRATCH
, scratch0
);
621 /* force write to be visible to other HFI on another OS */
622 (void)read_csr(dd
, ASIC_CFG_SCRATCH
);
624 release_hw_mutex(dd
);
625 mutex_unlock(&dd
->asic_data
->asic_resource_mutex
);
627 /* return the number of bytes written */
635 /* read the dc8051 memory */
636 static ssize_t
dc8051_memory_read(struct file
*file
, char __user
*buf
,
637 size_t count
, loff_t
*ppos
)
639 struct hfi1_pportdata
*ppd
= private2ppd(file
);
644 /* the checks below expect the position to be positive */
648 tmp
= kzalloc(DC8051_DATA_MEM_SIZE
, GFP_KERNEL
);
653 * Fill in the requested portion of the temporary buffer from the
654 * 8051 memory. The 8051 memory read is done in terms of 8 bytes.
655 * Adjust start and end to fit. Skip reading anything if out of
658 start
= *ppos
& ~0x7; /* round down */
659 if (start
< DC8051_DATA_MEM_SIZE
) {
660 end
= (*ppos
+ count
+ 7) & ~0x7; /* round up */
661 if (end
> DC8051_DATA_MEM_SIZE
)
662 end
= DC8051_DATA_MEM_SIZE
;
663 rval
= read_8051_data(ppd
->dd
, start
, end
- start
,
664 (u64
*)(tmp
+ start
));
669 rval
= simple_read_from_buffer(buf
, count
, ppos
, tmp
,
670 DC8051_DATA_MEM_SIZE
);
676 static ssize_t
debugfs_lcb_read(struct file
*file
, char __user
*buf
,
677 size_t count
, loff_t
*ppos
)
679 struct hfi1_pportdata
*ppd
= private2ppd(file
);
680 struct hfi1_devdata
*dd
= ppd
->dd
;
681 unsigned long total
, csr_off
;
686 /* only read 8 byte quantities */
687 if ((count
% 8) != 0)
689 /* offset must be 8-byte aligned */
690 if ((*ppos
% 8) != 0)
692 /* do nothing if out of range or zero count */
693 if (*ppos
>= (LCB_END
- LCB_START
) || !count
)
695 /* reduce count if needed */
696 if (*ppos
+ count
> LCB_END
- LCB_START
)
697 count
= (LCB_END
- LCB_START
) - *ppos
;
699 csr_off
= LCB_START
+ *ppos
;
700 for (total
= 0; total
< count
; total
+= 8, csr_off
+= 8) {
701 if (read_lcb_csr(dd
, csr_off
, (u64
*)&data
))
703 if (put_user(data
, (unsigned long __user
*)(buf
+ total
)))
710 static ssize_t
debugfs_lcb_write(struct file
*file
, const char __user
*buf
,
711 size_t count
, loff_t
*ppos
)
713 struct hfi1_pportdata
*ppd
= private2ppd(file
);
714 struct hfi1_devdata
*dd
= ppd
->dd
;
715 unsigned long total
, csr_off
, data
;
719 /* only write 8 byte quantities */
720 if ((count
% 8) != 0)
722 /* offset must be 8-byte aligned */
723 if ((*ppos
% 8) != 0)
725 /* do nothing if out of range or zero count */
726 if (*ppos
>= (LCB_END
- LCB_START
) || !count
)
728 /* reduce count if needed */
729 if (*ppos
+ count
> LCB_END
- LCB_START
)
730 count
= (LCB_END
- LCB_START
) - *ppos
;
732 csr_off
= LCB_START
+ *ppos
;
733 for (total
= 0; total
< count
; total
+= 8, csr_off
+= 8) {
734 if (get_user(data
, (unsigned long __user
*)(buf
+ total
)))
736 if (write_lcb_csr(dd
, csr_off
, data
))
744 * read the per-port QSFP data for ppd
746 static ssize_t
qsfp_debugfs_dump(struct file
*file
, char __user
*buf
,
747 size_t count
, loff_t
*ppos
)
749 struct hfi1_pportdata
*ppd
;
753 ppd
= private2ppd(file
);
754 tmp
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
758 ret
= qsfp_dump(ppd
, tmp
, PAGE_SIZE
);
760 ret
= simple_read_from_buffer(buf
, count
, ppos
, tmp
, ret
);
765 /* Do an i2c write operation on the chain for the given HFI. */
766 static ssize_t
__i2c_debugfs_write(struct file
*file
, const char __user
*buf
,
767 size_t count
, loff_t
*ppos
, u32 target
)
769 struct hfi1_pportdata
*ppd
;
776 ppd
= private2ppd(file
);
778 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
779 i2c_addr
= (*ppos
>> 16) & 0xffff;
780 offset
= *ppos
& 0xffff;
782 /* explicitly reject invalid address 0 to catch cp and cat */
786 buff
= memdup_user(buf
, count
);
788 return PTR_ERR(buff
);
790 total_written
= i2c_write(ppd
, target
, i2c_addr
, offset
, buff
, count
);
791 if (total_written
< 0) {
796 *ppos
+= total_written
;
805 /* Do an i2c write operation on chain for HFI 0. */
806 static ssize_t
i2c1_debugfs_write(struct file
*file
, const char __user
*buf
,
807 size_t count
, loff_t
*ppos
)
809 return __i2c_debugfs_write(file
, buf
, count
, ppos
, 0);
812 /* Do an i2c write operation on chain for HFI 1. */
813 static ssize_t
i2c2_debugfs_write(struct file
*file
, const char __user
*buf
,
814 size_t count
, loff_t
*ppos
)
816 return __i2c_debugfs_write(file
, buf
, count
, ppos
, 1);
819 /* Do an i2c read operation on the chain for the given HFI. */
820 static ssize_t
__i2c_debugfs_read(struct file
*file
, char __user
*buf
,
821 size_t count
, loff_t
*ppos
, u32 target
)
823 struct hfi1_pportdata
*ppd
;
830 ppd
= private2ppd(file
);
832 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
833 i2c_addr
= (*ppos
>> 16) & 0xffff;
834 offset
= *ppos
& 0xffff;
836 /* explicitly reject invalid address 0 to catch cp and cat */
840 buff
= kmalloc(count
, GFP_KERNEL
);
844 total_read
= i2c_read(ppd
, target
, i2c_addr
, offset
, buff
, count
);
845 if (total_read
< 0) {
852 ret
= copy_to_user(buf
, buff
, total_read
);
865 /* Do an i2c read operation on chain for HFI 0. */
866 static ssize_t
i2c1_debugfs_read(struct file
*file
, char __user
*buf
,
867 size_t count
, loff_t
*ppos
)
869 return __i2c_debugfs_read(file
, buf
, count
, ppos
, 0);
872 /* Do an i2c read operation on chain for HFI 1. */
873 static ssize_t
i2c2_debugfs_read(struct file
*file
, char __user
*buf
,
874 size_t count
, loff_t
*ppos
)
876 return __i2c_debugfs_read(file
, buf
, count
, ppos
, 1);
879 /* Do a QSFP write operation on the i2c chain for the given HFI. */
880 static ssize_t
__qsfp_debugfs_write(struct file
*file
, const char __user
*buf
,
881 size_t count
, loff_t
*ppos
, u32 target
)
883 struct hfi1_pportdata
*ppd
;
888 if (*ppos
+ count
> QSFP_PAGESIZE
* 4) /* base page + page00-page03 */
891 ppd
= private2ppd(file
);
893 buff
= memdup_user(buf
, count
);
895 return PTR_ERR(buff
);
897 total_written
= qsfp_write(ppd
, target
, *ppos
, buff
, count
);
898 if (total_written
< 0) {
903 *ppos
+= total_written
;
912 /* Do a QSFP write operation on i2c chain for HFI 0. */
913 static ssize_t
qsfp1_debugfs_write(struct file
*file
, const char __user
*buf
,
914 size_t count
, loff_t
*ppos
)
916 return __qsfp_debugfs_write(file
, buf
, count
, ppos
, 0);
919 /* Do a QSFP write operation on i2c chain for HFI 1. */
920 static ssize_t
qsfp2_debugfs_write(struct file
*file
, const char __user
*buf
,
921 size_t count
, loff_t
*ppos
)
923 return __qsfp_debugfs_write(file
, buf
, count
, ppos
, 1);
926 /* Do a QSFP read operation on the i2c chain for the given HFI. */
927 static ssize_t
__qsfp_debugfs_read(struct file
*file
, char __user
*buf
,
928 size_t count
, loff_t
*ppos
, u32 target
)
930 struct hfi1_pportdata
*ppd
;
935 if (*ppos
+ count
> QSFP_PAGESIZE
* 4) { /* base page + page00-page03 */
940 ppd
= private2ppd(file
);
942 buff
= kmalloc(count
, GFP_KERNEL
);
948 total_read
= qsfp_read(ppd
, target
, *ppos
, buff
, count
);
949 if (total_read
< 0) {
956 ret
= copy_to_user(buf
, buff
, total_read
);
970 /* Do a QSFP read operation on i2c chain for HFI 0. */
971 static ssize_t
qsfp1_debugfs_read(struct file
*file
, char __user
*buf
,
972 size_t count
, loff_t
*ppos
)
974 return __qsfp_debugfs_read(file
, buf
, count
, ppos
, 0);
977 /* Do a QSFP read operation on i2c chain for HFI 1. */
978 static ssize_t
qsfp2_debugfs_read(struct file
*file
, char __user
*buf
,
979 size_t count
, loff_t
*ppos
)
981 return __qsfp_debugfs_read(file
, buf
, count
, ppos
, 1);
984 static int __i2c_debugfs_open(struct inode
*in
, struct file
*fp
, u32 target
)
986 struct hfi1_pportdata
*ppd
;
989 if (!try_module_get(THIS_MODULE
))
992 ppd
= private2ppd(fp
);
994 ret
= acquire_chip_resource(ppd
->dd
, i2c_target(target
), 0);
995 if (ret
) /* failed - release the module */
996 module_put(THIS_MODULE
);
1001 static int i2c1_debugfs_open(struct inode
*in
, struct file
*fp
)
1003 return __i2c_debugfs_open(in
, fp
, 0);
1006 static int i2c2_debugfs_open(struct inode
*in
, struct file
*fp
)
1008 return __i2c_debugfs_open(in
, fp
, 1);
1011 static int __i2c_debugfs_release(struct inode
*in
, struct file
*fp
, u32 target
)
1013 struct hfi1_pportdata
*ppd
;
1015 ppd
= private2ppd(fp
);
1017 release_chip_resource(ppd
->dd
, i2c_target(target
));
1018 module_put(THIS_MODULE
);
1023 static int i2c1_debugfs_release(struct inode
*in
, struct file
*fp
)
1025 return __i2c_debugfs_release(in
, fp
, 0);
1028 static int i2c2_debugfs_release(struct inode
*in
, struct file
*fp
)
1030 return __i2c_debugfs_release(in
, fp
, 1);
1033 static int __qsfp_debugfs_open(struct inode
*in
, struct file
*fp
, u32 target
)
1035 struct hfi1_pportdata
*ppd
;
1038 if (!try_module_get(THIS_MODULE
))
1041 ppd
= private2ppd(fp
);
1043 ret
= acquire_chip_resource(ppd
->dd
, i2c_target(target
), 0);
1044 if (ret
) /* failed - release the module */
1045 module_put(THIS_MODULE
);
1050 static int qsfp1_debugfs_open(struct inode
*in
, struct file
*fp
)
1052 return __qsfp_debugfs_open(in
, fp
, 0);
1055 static int qsfp2_debugfs_open(struct inode
*in
, struct file
*fp
)
1057 return __qsfp_debugfs_open(in
, fp
, 1);
1060 static int __qsfp_debugfs_release(struct inode
*in
, struct file
*fp
, u32 target
)
1062 struct hfi1_pportdata
*ppd
;
1064 ppd
= private2ppd(fp
);
1066 release_chip_resource(ppd
->dd
, i2c_target(target
));
1067 module_put(THIS_MODULE
);
1072 static int qsfp1_debugfs_release(struct inode
*in
, struct file
*fp
)
1074 return __qsfp_debugfs_release(in
, fp
, 0);
1077 static int qsfp2_debugfs_release(struct inode
*in
, struct file
*fp
)
1079 return __qsfp_debugfs_release(in
, fp
, 1);
1082 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
1086 .read = readroutine, \
1087 .write = writeroutine, \
1088 .llseek = generic_file_llseek, \
1092 #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
1098 .llseek = generic_file_llseek, \
1100 .release = releasef \
1104 static const struct counter_info cntr_ops
[] = {
1105 DEBUGFS_OPS("counter_names", dev_names_read
, NULL
),
1106 DEBUGFS_OPS("counters", dev_counters_read
, NULL
),
1107 DEBUGFS_OPS("portcounter_names", portnames_read
, NULL
),
1110 static const struct counter_info port_cntr_ops
[] = {
1111 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read
, NULL
),
1112 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read
, i2c1_debugfs_write
,
1113 i2c1_debugfs_open
, i2c1_debugfs_release
),
1114 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read
, i2c2_debugfs_write
,
1115 i2c2_debugfs_open
, i2c2_debugfs_release
),
1116 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump
, NULL
),
1117 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read
, qsfp1_debugfs_write
,
1118 qsfp1_debugfs_open
, qsfp1_debugfs_release
),
1119 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read
, qsfp2_debugfs_write
,
1120 qsfp2_debugfs_open
, qsfp2_debugfs_release
),
1121 DEBUGFS_OPS("asic_flags", asic_flags_read
, asic_flags_write
),
1122 DEBUGFS_OPS("dc8051_memory", dc8051_memory_read
, NULL
),
1123 DEBUGFS_OPS("lcb", debugfs_lcb_read
, debugfs_lcb_write
),
1126 static void *_sdma_cpu_list_seq_start(struct seq_file
*s
, loff_t
*pos
)
1128 if (*pos
>= num_online_cpus())
1134 static void *_sdma_cpu_list_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
1137 if (*pos
>= num_online_cpus())
1143 static void _sdma_cpu_list_seq_stop(struct seq_file
*s
, void *v
)
1145 /* nothing allocated */
1148 static int _sdma_cpu_list_seq_show(struct seq_file
*s
, void *v
)
1150 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
1151 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
1155 sdma_seqfile_dump_cpu_list(s
, dd
, (unsigned long)i
);
1159 DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list
);
1160 DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list
)
1161 DEBUGFS_FILE_OPS(sdma_cpu_list
);
1163 #ifdef CONFIG_FAULT_INJECTION
1164 static void *_fault_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
1166 struct hfi1_opcode_stats_perctx
*opstats
;
1168 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
1173 static void *_fault_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
1175 struct hfi1_opcode_stats_perctx
*opstats
;
1178 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
1183 static void _fault_stats_seq_stop(struct seq_file
*s
, void *v
)
1187 static int _fault_stats_seq_show(struct seq_file
*s
, void *v
)
1190 loff_t i
= *spos
, j
;
1191 u64 n_packets
= 0, n_bytes
= 0;
1192 struct hfi1_ibdev
*ibd
= (struct hfi1_ibdev
*)s
->private;
1193 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
1194 struct hfi1_ctxtdata
*rcd
;
1196 for (j
= 0; j
< dd
->first_dyn_alloc_ctxt
; j
++) {
1197 rcd
= hfi1_rcd_get_by_index(dd
, j
);
1199 n_packets
+= rcd
->opstats
->stats
[i
].n_packets
;
1200 n_bytes
+= rcd
->opstats
->stats
[i
].n_bytes
;
1204 for_each_possible_cpu(j
) {
1205 struct hfi1_opcode_stats_perctx
*sp
=
1206 per_cpu_ptr(dd
->tx_opstats
, j
);
1208 n_packets
+= sp
->stats
[i
].n_packets
;
1209 n_bytes
+= sp
->stats
[i
].n_bytes
;
1211 if (!n_packets
&& !n_bytes
)
1213 if (!ibd
->fault_opcode
->n_rxfaults
[i
] &&
1214 !ibd
->fault_opcode
->n_txfaults
[i
])
1216 seq_printf(s
, "%02llx %llu/%llu (faults rx:%llu faults: tx:%llu)\n", i
,
1217 (unsigned long long)n_packets
,
1218 (unsigned long long)n_bytes
,
1219 (unsigned long long)ibd
->fault_opcode
->n_rxfaults
[i
],
1220 (unsigned long long)ibd
->fault_opcode
->n_txfaults
[i
]);
1224 DEBUGFS_SEQ_FILE_OPS(fault_stats
);
1225 DEBUGFS_SEQ_FILE_OPEN(fault_stats
);
1226 DEBUGFS_FILE_OPS(fault_stats
);
1228 static void fault_exit_opcode_debugfs(struct hfi1_ibdev
*ibd
)
1230 debugfs_remove_recursive(ibd
->fault_opcode
->dir
);
1231 kfree(ibd
->fault_opcode
);
1232 ibd
->fault_opcode
= NULL
;
1235 static int fault_init_opcode_debugfs(struct hfi1_ibdev
*ibd
)
1237 struct dentry
*parent
= ibd
->hfi1_ibdev_dbg
;
1239 ibd
->fault_opcode
= kzalloc(sizeof(*ibd
->fault_opcode
), GFP_KERNEL
);
1240 if (!ibd
->fault_opcode
)
1243 ibd
->fault_opcode
->attr
.interval
= 1;
1244 ibd
->fault_opcode
->attr
.require_end
= ULONG_MAX
;
1245 ibd
->fault_opcode
->attr
.stacktrace_depth
= 32;
1246 ibd
->fault_opcode
->attr
.dname
= NULL
;
1247 ibd
->fault_opcode
->attr
.verbose
= 0;
1248 ibd
->fault_opcode
->fault_by_opcode
= false;
1249 ibd
->fault_opcode
->opcode
= 0;
1250 ibd
->fault_opcode
->mask
= 0xff;
1252 ibd
->fault_opcode
->dir
=
1253 fault_create_debugfs_attr("fault_opcode",
1255 &ibd
->fault_opcode
->attr
);
1256 if (IS_ERR(ibd
->fault_opcode
->dir
)) {
1257 kfree(ibd
->fault_opcode
);
1261 DEBUGFS_SEQ_FILE_CREATE(fault_stats
, ibd
->fault_opcode
->dir
, ibd
);
1262 if (!debugfs_create_bool("fault_by_opcode", 0600,
1263 ibd
->fault_opcode
->dir
,
1264 &ibd
->fault_opcode
->fault_by_opcode
))
1266 if (!debugfs_create_x8("opcode", 0600, ibd
->fault_opcode
->dir
,
1267 &ibd
->fault_opcode
->opcode
))
1269 if (!debugfs_create_x8("mask", 0600, ibd
->fault_opcode
->dir
,
1270 &ibd
->fault_opcode
->mask
))
1275 fault_exit_opcode_debugfs(ibd
);
1279 static void fault_exit_packet_debugfs(struct hfi1_ibdev
*ibd
)
1281 debugfs_remove_recursive(ibd
->fault_packet
->dir
);
1282 kfree(ibd
->fault_packet
);
1283 ibd
->fault_packet
= NULL
;
1286 static int fault_init_packet_debugfs(struct hfi1_ibdev
*ibd
)
1288 struct dentry
*parent
= ibd
->hfi1_ibdev_dbg
;
1290 ibd
->fault_packet
= kzalloc(sizeof(*ibd
->fault_packet
), GFP_KERNEL
);
1291 if (!ibd
->fault_packet
)
1294 ibd
->fault_packet
->attr
.interval
= 1;
1295 ibd
->fault_packet
->attr
.require_end
= ULONG_MAX
;
1296 ibd
->fault_packet
->attr
.stacktrace_depth
= 32;
1297 ibd
->fault_packet
->attr
.dname
= NULL
;
1298 ibd
->fault_packet
->attr
.verbose
= 0;
1299 ibd
->fault_packet
->fault_by_packet
= false;
1301 ibd
->fault_packet
->dir
=
1302 fault_create_debugfs_attr("fault_packet",
1304 &ibd
->fault_opcode
->attr
);
1305 if (IS_ERR(ibd
->fault_packet
->dir
)) {
1306 kfree(ibd
->fault_packet
);
1310 if (!debugfs_create_bool("fault_by_packet", 0600,
1311 ibd
->fault_packet
->dir
,
1312 &ibd
->fault_packet
->fault_by_packet
))
1314 if (!debugfs_create_u64("fault_stats", 0400,
1315 ibd
->fault_packet
->dir
,
1316 &ibd
->fault_packet
->n_faults
))
1321 fault_exit_packet_debugfs(ibd
);
1325 static void fault_exit_debugfs(struct hfi1_ibdev
*ibd
)
1327 fault_exit_opcode_debugfs(ibd
);
1328 fault_exit_packet_debugfs(ibd
);
1331 static int fault_init_debugfs(struct hfi1_ibdev
*ibd
)
1335 ret
= fault_init_opcode_debugfs(ibd
);
1339 ret
= fault_init_packet_debugfs(ibd
);
1341 fault_exit_opcode_debugfs(ibd
);
1346 bool hfi1_dbg_fault_suppress_err(struct hfi1_ibdev
*ibd
)
1348 return ibd
->fault_suppress_err
;
1351 bool hfi1_dbg_fault_opcode(struct rvt_qp
*qp
, u32 opcode
, bool rx
)
1354 struct hfi1_ibdev
*ibd
= to_idev(qp
->ibqp
.device
);
1356 if (!ibd
->fault_opcode
|| !ibd
->fault_opcode
->fault_by_opcode
)
1358 if (ibd
->fault_opcode
->opcode
!= (opcode
& ibd
->fault_opcode
->mask
))
1360 ret
= should_fail(&ibd
->fault_opcode
->attr
, 1);
1362 trace_hfi1_fault_opcode(qp
, opcode
);
1364 ibd
->fault_opcode
->n_rxfaults
[opcode
]++;
1366 ibd
->fault_opcode
->n_txfaults
[opcode
]++;
1371 bool hfi1_dbg_fault_packet(struct hfi1_packet
*packet
)
1373 struct rvt_dev_info
*rdi
= &packet
->rcd
->ppd
->dd
->verbs_dev
.rdi
;
1374 struct hfi1_ibdev
*ibd
= dev_from_rdi(rdi
);
1377 if (!ibd
->fault_packet
|| !ibd
->fault_packet
->fault_by_packet
)
1380 ret
= should_fail(&ibd
->fault_packet
->attr
, 1);
1382 ++ibd
->fault_packet
->n_faults
;
1383 trace_hfi1_fault_packet(packet
);
1389 void hfi1_dbg_ibdev_init(struct hfi1_ibdev
*ibd
)
1391 char name
[sizeof("port0counters") + 1];
1393 struct hfi1_devdata
*dd
= dd_from_dev(ibd
);
1394 struct hfi1_pportdata
*ppd
;
1395 int unit
= dd
->unit
;
1400 snprintf(name
, sizeof(name
), "%s_%d", class_name(), unit
);
1401 snprintf(link
, sizeof(link
), "%d", unit
);
1402 ibd
->hfi1_ibdev_dbg
= debugfs_create_dir(name
, hfi1_dbg_root
);
1403 if (!ibd
->hfi1_ibdev_dbg
) {
1404 pr_warn("create of %s failed\n", name
);
1407 ibd
->hfi1_ibdev_link
=
1408 debugfs_create_symlink(link
, hfi1_dbg_root
, name
);
1409 if (!ibd
->hfi1_ibdev_link
) {
1410 pr_warn("create of %s symlink failed\n", name
);
1413 DEBUGFS_SEQ_FILE_CREATE(opcode_stats
, ibd
->hfi1_ibdev_dbg
, ibd
);
1414 DEBUGFS_SEQ_FILE_CREATE(tx_opcode_stats
, ibd
->hfi1_ibdev_dbg
, ibd
);
1415 DEBUGFS_SEQ_FILE_CREATE(ctx_stats
, ibd
->hfi1_ibdev_dbg
, ibd
);
1416 DEBUGFS_SEQ_FILE_CREATE(qp_stats
, ibd
->hfi1_ibdev_dbg
, ibd
);
1417 DEBUGFS_SEQ_FILE_CREATE(sdes
, ibd
->hfi1_ibdev_dbg
, ibd
);
1418 DEBUGFS_SEQ_FILE_CREATE(rcds
, ibd
->hfi1_ibdev_dbg
, ibd
);
1419 DEBUGFS_SEQ_FILE_CREATE(sdma_cpu_list
, ibd
->hfi1_ibdev_dbg
, ibd
);
1420 /* dev counter files */
1421 for (i
= 0; i
< ARRAY_SIZE(cntr_ops
); i
++)
1422 DEBUGFS_FILE_CREATE(cntr_ops
[i
].name
,
1423 ibd
->hfi1_ibdev_dbg
,
1425 &cntr_ops
[i
].ops
, S_IRUGO
);
1426 /* per port files */
1427 for (ppd
= dd
->pport
, j
= 0; j
< dd
->num_pports
; j
++, ppd
++)
1428 for (i
= 0; i
< ARRAY_SIZE(port_cntr_ops
); i
++) {
1431 port_cntr_ops
[i
].name
,
1433 DEBUGFS_FILE_CREATE(name
,
1434 ibd
->hfi1_ibdev_dbg
,
1436 &port_cntr_ops
[i
].ops
,
1437 !port_cntr_ops
[i
].ops
.write
?
1438 S_IRUGO
: S_IRUGO
| S_IWUSR
);
1441 #ifdef CONFIG_FAULT_INJECTION
1442 debugfs_create_bool("fault_suppress_err", 0600,
1443 ibd
->hfi1_ibdev_dbg
,
1444 &ibd
->fault_suppress_err
);
1445 fault_init_debugfs(ibd
);
1449 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev
*ibd
)
1453 #ifdef CONFIG_FAULT_INJECTION
1454 fault_exit_debugfs(ibd
);
1456 debugfs_remove(ibd
->hfi1_ibdev_link
);
1457 debugfs_remove_recursive(ibd
->hfi1_ibdev_dbg
);
1459 ibd
->hfi1_ibdev_dbg
= NULL
;
1463 * driver stats field names, one line per stat, single string. Used by
1464 * programs like hfistats to print the stats in a way which works for
1465 * different versions of drivers, without changing program source.
1466 * if hfi1_ib_stats changes, this needs to change. Names need to be
1467 * 12 chars or less (w/o newline), for proper display by hfistats utility.
1469 static const char * const hfi1_statnames
[] = {
1470 /* must be element 0*/
1483 static void *_driver_stats_names_seq_start(struct seq_file
*s
, loff_t
*pos
)
1485 if (*pos
>= ARRAY_SIZE(hfi1_statnames
))
1490 static void *_driver_stats_names_seq_next(
1496 if (*pos
>= ARRAY_SIZE(hfi1_statnames
))
1501 static void _driver_stats_names_seq_stop(struct seq_file
*s
, void *v
)
1505 static int _driver_stats_names_seq_show(struct seq_file
*s
, void *v
)
1509 seq_printf(s
, "%s\n", hfi1_statnames
[*spos
]);
1513 DEBUGFS_SEQ_FILE_OPS(driver_stats_names
);
1514 DEBUGFS_SEQ_FILE_OPEN(driver_stats_names
)
1515 DEBUGFS_FILE_OPS(driver_stats_names
);
1517 static void *_driver_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
1519 if (*pos
>= ARRAY_SIZE(hfi1_statnames
))
1524 static void *_driver_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
1527 if (*pos
>= ARRAY_SIZE(hfi1_statnames
))
1532 static void _driver_stats_seq_stop(struct seq_file
*s
, void *v
)
1536 static u64
hfi1_sps_ints(void)
1538 unsigned long flags
;
1539 struct hfi1_devdata
*dd
;
1542 spin_lock_irqsave(&hfi1_devs_lock
, flags
);
1543 list_for_each_entry(dd
, &hfi1_dev_list
, list
) {
1544 sps_ints
+= get_all_cpu_total(dd
->int_counter
);
1546 spin_unlock_irqrestore(&hfi1_devs_lock
, flags
);
1550 static int _driver_stats_seq_show(struct seq_file
*s
, void *v
)
1554 u64
*stats
= (u64
*)&hfi1_stats
;
1555 size_t sz
= seq_get_buf(s
, &buffer
);
1557 if (sz
< sizeof(u64
))
1559 /* special case for interrupts */
1561 *(u64
*)buffer
= hfi1_sps_ints();
1563 *(u64
*)buffer
= stats
[*spos
];
1564 seq_commit(s
, sizeof(u64
));
1568 DEBUGFS_SEQ_FILE_OPS(driver_stats
);
1569 DEBUGFS_SEQ_FILE_OPEN(driver_stats
)
1570 DEBUGFS_FILE_OPS(driver_stats
);
1572 void hfi1_dbg_init(void)
1574 hfi1_dbg_root
= debugfs_create_dir(DRIVER_NAME
, NULL
);
1576 pr_warn("init of debugfs failed\n");
1577 DEBUGFS_SEQ_FILE_CREATE(driver_stats_names
, hfi1_dbg_root
, NULL
);
1578 DEBUGFS_SEQ_FILE_CREATE(driver_stats
, hfi1_dbg_root
, NULL
);
1581 void hfi1_dbg_exit(void)
1583 debugfs_remove_recursive(hfi1_dbg_root
);
1584 hfi1_dbg_root
= NULL
;