3 * Copyright(c) 2015, 2016 Intel Corporation.
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
25 * - Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * - Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in
29 * the documentation and/or other materials provided with the
31 * - Neither the name of Intel Corporation nor the names of its
32 * contributors may be used to endorse or promote products derived
33 * from this software without specific prior written permission.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <linux/debugfs.h>
49 #include <linux/seq_file.h>
50 #include <linux/kernel.h>
51 #include <linux/export.h>
52 #include <linux/module.h>
60 static struct dentry *hfi1_dbg_root;
62 /* wrappers to enforce srcu in seq file */
63 static ssize_t hfi1_seq_read(
69 struct dentry *d = file->f_path.dentry;
73 r = debugfs_use_file_start(d, &srcu_idx);
75 r = seq_read(file, buf, size, ppos);
76 debugfs_use_file_finish(srcu_idx);
80 static loff_t hfi1_seq_lseek(
85 struct dentry *d = file->f_path.dentry;
89 r = debugfs_use_file_start(d, &srcu_idx);
91 r = seq_lseek(file, offset, whence);
92 debugfs_use_file_finish(srcu_idx);
96 #define private2dd(file) (file_inode(file)->i_private)
97 #define private2ppd(file) (file_inode(file)->i_private)
99 #define DEBUGFS_SEQ_FILE_OPS(name) \
100 static const struct seq_operations _##name##_seq_ops = { \
101 .start = _##name##_seq_start, \
102 .next = _##name##_seq_next, \
103 .stop = _##name##_seq_stop, \
104 .show = _##name##_seq_show \
107 #define DEBUGFS_SEQ_FILE_OPEN(name) \
108 static int _##name##_open(struct inode *inode, struct file *s) \
110 struct seq_file *seq; \
112 ret = seq_open(s, &_##name##_seq_ops); \
115 seq = s->private_data; \
116 seq->private = inode->i_private; \
120 #define DEBUGFS_FILE_OPS(name) \
121 static const struct file_operations _##name##_file_ops = { \
122 .owner = THIS_MODULE, \
123 .open = _##name##_open, \
124 .read = hfi1_seq_read, \
125 .llseek = hfi1_seq_lseek, \
126 .release = seq_release \
129 #define DEBUGFS_FILE_CREATE(name, parent, data, ops, mode) \
131 struct dentry *ent; \
132 ent = debugfs_create_file(name, mode, parent, \
135 pr_warn("create of %s failed\n", name); \
138 #define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \
139 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
141 static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
143 struct hfi1_opcode_stats_perctx *opstats;
145 if (*pos >= ARRAY_SIZE(opstats->stats))
150 static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
152 struct hfi1_opcode_stats_perctx *opstats;
155 if (*pos >= ARRAY_SIZE(opstats->stats))
160 static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
164 static int _opcode_stats_seq_show(struct seq_file *s, void *v)
168 u64 n_packets = 0, n_bytes = 0;
169 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
170 struct hfi1_devdata *dd = dd_from_dev(ibd);
172 for (j = 0; j < dd->first_user_ctxt; j++) {
175 n_packets += dd->rcd[j]->opstats->stats[i].n_packets;
176 n_bytes += dd->rcd[j]->opstats->stats[i].n_bytes;
178 if (!n_packets && !n_bytes)
180 seq_printf(s, "%02llx %llu/%llu\n", i,
181 (unsigned long long)n_packets,
182 (unsigned long long)n_bytes);
187 DEBUGFS_SEQ_FILE_OPS(opcode_stats);
188 DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
189 DEBUGFS_FILE_OPS(opcode_stats);
191 static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
193 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
194 struct hfi1_devdata *dd = dd_from_dev(ibd);
197 return SEQ_START_TOKEN;
198 if (*pos >= dd->first_user_ctxt)
203 static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
205 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
206 struct hfi1_devdata *dd = dd_from_dev(ibd);
208 if (v == SEQ_START_TOKEN)
212 if (*pos >= dd->first_user_ctxt)
217 static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
219 /* nothing allocated */
222 static int _ctx_stats_seq_show(struct seq_file *s, void *v)
227 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
228 struct hfi1_devdata *dd = dd_from_dev(ibd);
230 if (v == SEQ_START_TOKEN) {
231 seq_puts(s, "Ctx:npkts\n");
241 for (j = 0; j < ARRAY_SIZE(dd->rcd[i]->opstats->stats); j++)
242 n_packets += dd->rcd[i]->opstats->stats[j].n_packets;
247 seq_printf(s, " %llu:%llu\n", i, n_packets);
251 DEBUGFS_SEQ_FILE_OPS(ctx_stats);
252 DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
253 DEBUGFS_FILE_OPS(ctx_stats);
255 static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
258 struct qp_iter *iter;
261 iter = qp_iter_init(s->private);
263 /* stop calls rcu_read_unlock */
270 if (qp_iter_next(iter)) {
279 static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
283 struct qp_iter *iter = iter_ptr;
287 if (qp_iter_next(iter)) {
295 static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
301 static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
303 struct qp_iter *iter = iter_ptr;
308 qp_iter_print(s, iter);
313 DEBUGFS_SEQ_FILE_OPS(qp_stats);
314 DEBUGFS_SEQ_FILE_OPEN(qp_stats)
315 DEBUGFS_FILE_OPS(qp_stats);
317 static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
319 struct hfi1_ibdev *ibd;
320 struct hfi1_devdata *dd;
322 ibd = (struct hfi1_ibdev *)s->private;
323 dd = dd_from_dev(ibd);
324 if (!dd->per_sdma || *pos >= dd->num_sdma)
329 static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
331 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
332 struct hfi1_devdata *dd = dd_from_dev(ibd);
335 if (!dd->per_sdma || *pos >= dd->num_sdma)
340 static void _sdes_seq_stop(struct seq_file *s, void *v)
344 static int _sdes_seq_show(struct seq_file *s, void *v)
346 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
347 struct hfi1_devdata *dd = dd_from_dev(ibd);
351 sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
355 DEBUGFS_SEQ_FILE_OPS(sdes);
356 DEBUGFS_SEQ_FILE_OPEN(sdes)
357 DEBUGFS_FILE_OPS(sdes);
359 /* read the per-device counters */
360 static ssize_t dev_counters_read(struct file *file, char __user *buf,
361 size_t count, loff_t *ppos)
365 struct hfi1_devdata *dd;
368 dd = private2dd(file);
369 avail = hfi1_read_cntrs(dd, NULL, &counters);
370 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
374 /* read the per-device counters */
375 static ssize_t dev_names_read(struct file *file, char __user *buf,
376 size_t count, loff_t *ppos)
380 struct hfi1_devdata *dd;
383 dd = private2dd(file);
384 avail = hfi1_read_cntrs(dd, &names, NULL);
385 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
389 struct counter_info {
391 const struct file_operations ops;
395 * Could use file_inode(file)->i_ino to figure out which file,
396 * instead of separate routine for each, but for now, this works...
399 /* read the per-port names (same for each port) */
400 static ssize_t portnames_read(struct file *file, char __user *buf,
401 size_t count, loff_t *ppos)
405 struct hfi1_devdata *dd;
408 dd = private2dd(file);
409 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
410 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
414 /* read the per-port counters */
415 static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
416 size_t count, loff_t *ppos)
420 struct hfi1_pportdata *ppd;
423 ppd = private2ppd(file);
424 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
425 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
429 static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
430 int this_hfi, int hfi, u32 flag, const char *what)
434 mask = flag << (hfi ? CR_DYN_SHIFT : 0);
435 if (scratch0 & mask) {
436 *used += scnprintf(p + *used, size - *used,
437 " 0x%08x - HFI%d %s in use, %s device\n",
439 this_hfi == hfi ? "this" : "other");
443 static ssize_t asic_flags_read(struct file *file, char __user *buf,
444 size_t count, loff_t *ppos)
446 struct hfi1_pportdata *ppd;
447 struct hfi1_devdata *dd;
455 ppd = private2ppd(file);
459 tmp = kmalloc(size, GFP_KERNEL);
463 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
464 used += scnprintf(tmp + used, size - used,
465 "Resource flags: 0x%016llx\n", scratch0);
467 /* check permanent flag */
468 if (scratch0 & CR_THERM_INIT) {
469 used += scnprintf(tmp + used, size - used,
470 " 0x%08x - thermal monitoring initialized\n",
474 /* check each dynamic flag on each HFI */
475 for (i = 0; i < 2; i++) {
476 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
478 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
480 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
481 CR_I2C1, "i2c chain 1");
482 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
483 CR_I2C2, "i2c chain 2");
485 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
487 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
492 static ssize_t asic_flags_write(struct file *file, const char __user *buf,
493 size_t count, loff_t *ppos)
495 struct hfi1_pportdata *ppd;
496 struct hfi1_devdata *dd;
499 unsigned long long value;
503 ppd = private2ppd(file);
506 buff = kmalloc(count + 1, GFP_KERNEL);
510 ret = copy_from_user(buff, buf, count);
516 /* zero terminate and read the expected integer */
518 ret = kstrtoull(buff, 0, &value);
523 /* obtain exclusive access */
524 mutex_lock(&dd->asic_data->asic_resource_mutex);
525 acquire_hw_mutex(dd);
527 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
529 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
530 /* force write to be visible to other HFI on another OS */
531 (void)read_csr(dd, ASIC_CFG_SCRATCH);
533 release_hw_mutex(dd);
534 mutex_unlock(&dd->asic_data->asic_resource_mutex);
536 /* return the number of bytes written */
545 * read the per-port QSFP data for ppd
547 static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
548 size_t count, loff_t *ppos)
550 struct hfi1_pportdata *ppd;
554 ppd = private2ppd(file);
555 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
559 ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
561 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
566 /* Do an i2c write operation on the chain for the given HFI. */
567 static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
568 size_t count, loff_t *ppos, u32 target)
570 struct hfi1_pportdata *ppd;
577 ppd = private2ppd(file);
579 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
580 i2c_addr = (*ppos >> 16) & 0xffff;
581 offset = *ppos & 0xffff;
583 /* explicitly reject invalid address 0 to catch cp and cat */
587 buff = kmalloc(count, GFP_KERNEL);
591 ret = copy_from_user(buff, buf, count);
597 total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
598 if (total_written < 0) {
603 *ppos += total_written;
612 /* Do an i2c write operation on chain for HFI 0. */
613 static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
614 size_t count, loff_t *ppos)
616 return __i2c_debugfs_write(file, buf, count, ppos, 0);
619 /* Do an i2c write operation on chain for HFI 1. */
620 static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
621 size_t count, loff_t *ppos)
623 return __i2c_debugfs_write(file, buf, count, ppos, 1);
626 /* Do an i2c read operation on the chain for the given HFI. */
627 static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
628 size_t count, loff_t *ppos, u32 target)
630 struct hfi1_pportdata *ppd;
637 ppd = private2ppd(file);
639 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
640 i2c_addr = (*ppos >> 16) & 0xffff;
641 offset = *ppos & 0xffff;
643 /* explicitly reject invalid address 0 to catch cp and cat */
647 buff = kmalloc(count, GFP_KERNEL);
651 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
652 if (total_read < 0) {
659 ret = copy_to_user(buf, buff, total_read);
672 /* Do an i2c read operation on chain for HFI 0. */
673 static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
674 size_t count, loff_t *ppos)
676 return __i2c_debugfs_read(file, buf, count, ppos, 0);
679 /* Do an i2c read operation on chain for HFI 1. */
680 static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
681 size_t count, loff_t *ppos)
683 return __i2c_debugfs_read(file, buf, count, ppos, 1);
686 /* Do a QSFP write operation on the i2c chain for the given HFI. */
687 static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
688 size_t count, loff_t *ppos, u32 target)
690 struct hfi1_pportdata *ppd;
695 if (*ppos + count > QSFP_PAGESIZE * 4) /* base page + page00-page03 */
698 ppd = private2ppd(file);
700 buff = kmalloc(count, GFP_KERNEL);
704 ret = copy_from_user(buff, buf, count);
709 total_written = qsfp_write(ppd, target, *ppos, buff, count);
710 if (total_written < 0) {
715 *ppos += total_written;
724 /* Do a QSFP write operation on i2c chain for HFI 0. */
725 static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
726 size_t count, loff_t *ppos)
728 return __qsfp_debugfs_write(file, buf, count, ppos, 0);
731 /* Do a QSFP write operation on i2c chain for HFI 1. */
732 static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
733 size_t count, loff_t *ppos)
735 return __qsfp_debugfs_write(file, buf, count, ppos, 1);
738 /* Do a QSFP read operation on the i2c chain for the given HFI. */
739 static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
740 size_t count, loff_t *ppos, u32 target)
742 struct hfi1_pportdata *ppd;
747 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
752 ppd = private2ppd(file);
754 buff = kmalloc(count, GFP_KERNEL);
760 total_read = qsfp_read(ppd, target, *ppos, buff, count);
761 if (total_read < 0) {
768 ret = copy_to_user(buf, buff, total_read);
782 /* Do a QSFP read operation on i2c chain for HFI 0. */
783 static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
784 size_t count, loff_t *ppos)
786 return __qsfp_debugfs_read(file, buf, count, ppos, 0);
789 /* Do a QSFP read operation on i2c chain for HFI 1. */
790 static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
791 size_t count, loff_t *ppos)
793 return __qsfp_debugfs_read(file, buf, count, ppos, 1);
796 static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
798 struct hfi1_pportdata *ppd;
801 if (!try_module_get(THIS_MODULE))
804 ppd = private2ppd(fp);
806 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
807 if (ret) /* failed - release the module */
808 module_put(THIS_MODULE);
813 static int i2c1_debugfs_open(struct inode *in, struct file *fp)
815 return __i2c_debugfs_open(in, fp, 0);
818 static int i2c2_debugfs_open(struct inode *in, struct file *fp)
820 return __i2c_debugfs_open(in, fp, 1);
823 static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
825 struct hfi1_pportdata *ppd;
827 ppd = private2ppd(fp);
829 release_chip_resource(ppd->dd, i2c_target(target));
830 module_put(THIS_MODULE);
835 static int i2c1_debugfs_release(struct inode *in, struct file *fp)
837 return __i2c_debugfs_release(in, fp, 0);
840 static int i2c2_debugfs_release(struct inode *in, struct file *fp)
842 return __i2c_debugfs_release(in, fp, 1);
845 static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
847 struct hfi1_pportdata *ppd;
850 if (!try_module_get(THIS_MODULE))
853 ppd = private2ppd(fp);
855 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
856 if (ret) /* failed - release the module */
857 module_put(THIS_MODULE);
862 static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
864 return __qsfp_debugfs_open(in, fp, 0);
867 static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
869 return __qsfp_debugfs_open(in, fp, 1);
872 static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
874 struct hfi1_pportdata *ppd;
876 ppd = private2ppd(fp);
878 release_chip_resource(ppd->dd, i2c_target(target));
879 module_put(THIS_MODULE);
884 static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
886 return __qsfp_debugfs_release(in, fp, 0);
889 static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
891 return __qsfp_debugfs_release(in, fp, 1);
894 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
898 .read = readroutine, \
899 .write = writeroutine, \
900 .llseek = generic_file_llseek, \
904 #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
910 .llseek = generic_file_llseek, \
912 .release = releasef \
916 static const struct counter_info cntr_ops[] = {
917 DEBUGFS_OPS("counter_names", dev_names_read, NULL),
918 DEBUGFS_OPS("counters", dev_counters_read, NULL),
919 DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
922 static const struct counter_info port_cntr_ops[] = {
923 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
924 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
925 i2c1_debugfs_open, i2c1_debugfs_release),
926 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
927 i2c2_debugfs_open, i2c2_debugfs_release),
928 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
929 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
930 qsfp1_debugfs_open, qsfp1_debugfs_release),
931 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
932 qsfp2_debugfs_open, qsfp2_debugfs_release),
933 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
936 static void *_sdma_cpu_list_seq_start(struct seq_file *s, loff_t *pos)
938 if (*pos >= num_online_cpus())
944 static void *_sdma_cpu_list_seq_next(struct seq_file *s, void *v, loff_t *pos)
947 if (*pos >= num_online_cpus())
953 static void _sdma_cpu_list_seq_stop(struct seq_file *s, void *v)
955 /* nothing allocated */
958 static int _sdma_cpu_list_seq_show(struct seq_file *s, void *v)
960 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
961 struct hfi1_devdata *dd = dd_from_dev(ibd);
965 sdma_seqfile_dump_cpu_list(s, dd, (unsigned long)i);
969 DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list);
970 DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list)
971 DEBUGFS_FILE_OPS(sdma_cpu_list);
973 void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
975 char name[sizeof("port0counters") + 1];
977 struct hfi1_devdata *dd = dd_from_dev(ibd);
978 struct hfi1_pportdata *ppd;
984 snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
985 snprintf(link, sizeof(link), "%d", unit);
986 ibd->hfi1_ibdev_dbg = debugfs_create_dir(name, hfi1_dbg_root);
987 if (!ibd->hfi1_ibdev_dbg) {
988 pr_warn("create of %s failed\n", name);
991 ibd->hfi1_ibdev_link =
992 debugfs_create_symlink(link, hfi1_dbg_root, name);
993 if (!ibd->hfi1_ibdev_link) {
994 pr_warn("create of %s symlink failed\n", name);
997 DEBUGFS_SEQ_FILE_CREATE(opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
998 DEBUGFS_SEQ_FILE_CREATE(ctx_stats, ibd->hfi1_ibdev_dbg, ibd);
999 DEBUGFS_SEQ_FILE_CREATE(qp_stats, ibd->hfi1_ibdev_dbg, ibd);
1000 DEBUGFS_SEQ_FILE_CREATE(sdes, ibd->hfi1_ibdev_dbg, ibd);
1001 DEBUGFS_SEQ_FILE_CREATE(sdma_cpu_list, ibd->hfi1_ibdev_dbg, ibd);
1002 /* dev counter files */
1003 for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
1004 DEBUGFS_FILE_CREATE(cntr_ops[i].name,
1005 ibd->hfi1_ibdev_dbg,
1007 &cntr_ops[i].ops, S_IRUGO);
1008 /* per port files */
1009 for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
1010 for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
1013 port_cntr_ops[i].name,
1015 DEBUGFS_FILE_CREATE(name,
1016 ibd->hfi1_ibdev_dbg,
1018 &port_cntr_ops[i].ops,
1019 !port_cntr_ops[i].ops.write ?
1020 S_IRUGO : S_IRUGO | S_IWUSR);
1024 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
1028 debugfs_remove(ibd->hfi1_ibdev_link);
1029 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
1031 ibd->hfi1_ibdev_dbg = NULL;
1035 * driver stats field names, one line per stat, single string. Used by
1036 * programs like hfistats to print the stats in a way which works for
1037 * different versions of drivers, without changing program source.
1038 * if hfi1_ib_stats changes, this needs to change. Names need to be
1039 * 12 chars or less (w/o newline), for proper display by hfistats utility.
1041 static const char * const hfi1_statnames[] = {
1042 /* must be element 0*/
1055 static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
1057 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1062 static void *_driver_stats_names_seq_next(
1068 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1073 static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
1077 static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
1081 seq_printf(s, "%s\n", hfi1_statnames[*spos]);
1085 DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
1086 DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
1087 DEBUGFS_FILE_OPS(driver_stats_names);
1089 static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
1091 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1096 static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
1099 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1104 static void _driver_stats_seq_stop(struct seq_file *s, void *v)
1108 static u64 hfi1_sps_ints(void)
1110 unsigned long flags;
1111 struct hfi1_devdata *dd;
1114 spin_lock_irqsave(&hfi1_devs_lock, flags);
1115 list_for_each_entry(dd, &hfi1_dev_list, list) {
1116 sps_ints += get_all_cpu_total(dd->int_counter);
1118 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1122 static int _driver_stats_seq_show(struct seq_file *s, void *v)
1126 u64 *stats = (u64 *)&hfi1_stats;
1127 size_t sz = seq_get_buf(s, &buffer);
1129 if (sz < sizeof(u64))
1131 /* special case for interrupts */
1133 *(u64 *)buffer = hfi1_sps_ints();
1135 *(u64 *)buffer = stats[*spos];
1136 seq_commit(s, sizeof(u64));
1140 DEBUGFS_SEQ_FILE_OPS(driver_stats);
1141 DEBUGFS_SEQ_FILE_OPEN(driver_stats)
1142 DEBUGFS_FILE_OPS(driver_stats);
1144 void hfi1_dbg_init(void)
1146 hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
1148 pr_warn("init of debugfs failed\n");
1149 DEBUGFS_SEQ_FILE_CREATE(driver_stats_names, hfi1_dbg_root, NULL);
1150 DEBUGFS_SEQ_FILE_CREATE(driver_stats, hfi1_dbg_root, NULL);
1153 void hfi1_dbg_exit(void)
1155 debugfs_remove_recursive(hfi1_dbg_root);
1156 hfi1_dbg_root = NULL;