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 #define private2dd(file) (file_inode(file)->i_private)
63 #define private2ppd(file) (file_inode(file)->i_private)
65 #define DEBUGFS_SEQ_FILE_OPS(name) \
66 static const struct seq_operations _##name##_seq_ops = { \
67 .start = _##name##_seq_start, \
68 .next = _##name##_seq_next, \
69 .stop = _##name##_seq_stop, \
70 .show = _##name##_seq_show \
73 #define DEBUGFS_SEQ_FILE_OPEN(name) \
74 static int _##name##_open(struct inode *inode, struct file *s) \
76 struct seq_file *seq; \
78 ret = seq_open(s, &_##name##_seq_ops); \
81 seq = s->private_data; \
82 seq->private = inode->i_private; \
86 #define DEBUGFS_FILE_OPS(name) \
87 static const struct file_operations _##name##_file_ops = { \
88 .owner = THIS_MODULE, \
89 .open = _##name##_open, \
91 .llseek = seq_lseek, \
92 .release = seq_release \
95 #define DEBUGFS_FILE_CREATE(name, parent, data, ops, mode) \
98 ent = debugfs_create_file(name, mode, parent, \
101 pr_warn("create of %s failed\n", name); \
104 #define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \
105 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
107 static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
110 struct hfi1_opcode_stats_perctx *opstats;
113 if (*pos >= ARRAY_SIZE(opstats->stats))
118 static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
120 struct hfi1_opcode_stats_perctx *opstats;
123 if (*pos >= ARRAY_SIZE(opstats->stats))
128 static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
134 static int _opcode_stats_seq_show(struct seq_file *s, void *v)
138 u64 n_packets = 0, n_bytes = 0;
139 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
140 struct hfi1_devdata *dd = dd_from_dev(ibd);
142 for (j = 0; j < dd->first_user_ctxt; j++) {
145 n_packets += dd->rcd[j]->opstats->stats[i].n_packets;
146 n_bytes += dd->rcd[j]->opstats->stats[i].n_bytes;
148 if (!n_packets && !n_bytes)
150 seq_printf(s, "%02llx %llu/%llu\n", i,
151 (unsigned long long)n_packets,
152 (unsigned long long)n_bytes);
157 DEBUGFS_SEQ_FILE_OPS(opcode_stats);
158 DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
159 DEBUGFS_FILE_OPS(opcode_stats);
161 static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
163 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
164 struct hfi1_devdata *dd = dd_from_dev(ibd);
167 return SEQ_START_TOKEN;
168 if (*pos >= dd->first_user_ctxt)
173 static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
175 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
176 struct hfi1_devdata *dd = dd_from_dev(ibd);
178 if (v == SEQ_START_TOKEN)
182 if (*pos >= dd->first_user_ctxt)
187 static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
189 /* nothing allocated */
192 static int _ctx_stats_seq_show(struct seq_file *s, void *v)
197 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
198 struct hfi1_devdata *dd = dd_from_dev(ibd);
200 if (v == SEQ_START_TOKEN) {
201 seq_puts(s, "Ctx:npkts\n");
211 for (j = 0; j < ARRAY_SIZE(dd->rcd[i]->opstats->stats); j++)
212 n_packets += dd->rcd[i]->opstats->stats[j].n_packets;
217 seq_printf(s, " %llu:%llu\n", i, n_packets);
221 DEBUGFS_SEQ_FILE_OPS(ctx_stats);
222 DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
223 DEBUGFS_FILE_OPS(ctx_stats);
225 static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
228 struct qp_iter *iter;
231 iter = qp_iter_init(s->private);
233 /* stop calls rcu_read_unlock */
240 if (qp_iter_next(iter)) {
249 static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
253 struct qp_iter *iter = iter_ptr;
257 if (qp_iter_next(iter)) {
265 static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
271 static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
273 struct qp_iter *iter = iter_ptr;
278 qp_iter_print(s, iter);
283 DEBUGFS_SEQ_FILE_OPS(qp_stats);
284 DEBUGFS_SEQ_FILE_OPEN(qp_stats)
285 DEBUGFS_FILE_OPS(qp_stats);
287 static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
290 struct hfi1_ibdev *ibd;
291 struct hfi1_devdata *dd;
294 ibd = (struct hfi1_ibdev *)s->private;
295 dd = dd_from_dev(ibd);
296 if (!dd->per_sdma || *pos >= dd->num_sdma)
301 static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
303 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
304 struct hfi1_devdata *dd = dd_from_dev(ibd);
307 if (!dd->per_sdma || *pos >= dd->num_sdma)
312 static void _sdes_seq_stop(struct seq_file *s, void *v)
318 static int _sdes_seq_show(struct seq_file *s, void *v)
320 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
321 struct hfi1_devdata *dd = dd_from_dev(ibd);
325 sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
329 DEBUGFS_SEQ_FILE_OPS(sdes);
330 DEBUGFS_SEQ_FILE_OPEN(sdes)
331 DEBUGFS_FILE_OPS(sdes);
333 /* read the per-device counters */
334 static ssize_t dev_counters_read(struct file *file, char __user *buf,
335 size_t count, loff_t *ppos)
339 struct hfi1_devdata *dd;
343 dd = private2dd(file);
344 avail = hfi1_read_cntrs(dd, NULL, &counters);
345 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
350 /* read the per-device counters */
351 static ssize_t dev_names_read(struct file *file, char __user *buf,
352 size_t count, loff_t *ppos)
356 struct hfi1_devdata *dd;
360 dd = private2dd(file);
361 avail = hfi1_read_cntrs(dd, &names, NULL);
362 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
367 struct counter_info {
369 const struct file_operations ops;
373 * Could use file_inode(file)->i_ino to figure out which file,
374 * instead of separate routine for each, but for now, this works...
377 /* read the per-port names (same for each port) */
378 static ssize_t portnames_read(struct file *file, char __user *buf,
379 size_t count, loff_t *ppos)
383 struct hfi1_devdata *dd;
387 dd = private2dd(file);
388 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
389 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
394 /* read the per-port counters */
395 static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
396 size_t count, loff_t *ppos)
400 struct hfi1_pportdata *ppd;
404 ppd = private2ppd(file);
405 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
406 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
411 static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
412 int this_hfi, int hfi, u32 flag, const char *what)
416 mask = flag << (hfi ? CR_DYN_SHIFT : 0);
417 if (scratch0 & mask) {
418 *used += scnprintf(p + *used, size - *used,
419 " 0x%08x - HFI%d %s in use, %s device\n",
421 this_hfi == hfi ? "this" : "other");
425 static ssize_t asic_flags_read(struct file *file, char __user *buf,
426 size_t count, loff_t *ppos)
428 struct hfi1_pportdata *ppd;
429 struct hfi1_devdata *dd;
438 ppd = private2ppd(file);
442 tmp = kmalloc(size, GFP_KERNEL);
448 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
449 used += scnprintf(tmp + used, size - used,
450 "Resource flags: 0x%016llx\n", scratch0);
452 /* check permanent flag */
453 if (scratch0 & CR_THERM_INIT) {
454 used += scnprintf(tmp + used, size - used,
455 " 0x%08x - thermal monitoring initialized\n",
459 /* check each dynamic flag on each HFI */
460 for (i = 0; i < 2; i++) {
461 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
463 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
465 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
466 CR_I2C1, "i2c chain 1");
467 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
468 CR_I2C2, "i2c chain 2");
470 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
472 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
478 static ssize_t asic_flags_write(struct file *file, const char __user *buf,
479 size_t count, loff_t *ppos)
481 struct hfi1_pportdata *ppd;
482 struct hfi1_devdata *dd;
485 unsigned long long value;
490 ppd = private2ppd(file);
493 buff = kmalloc(count + 1, GFP_KERNEL);
499 ret = copy_from_user(buff, buf, count);
505 /* zero terminate and read the expected integer */
507 ret = kstrtoull(buff, 0, &value);
512 /* obtain exclusive access */
513 mutex_lock(&dd->asic_data->asic_resource_mutex);
514 acquire_hw_mutex(dd);
516 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
518 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
519 /* force write to be visible to other HFI on another OS */
520 (void)read_csr(dd, ASIC_CFG_SCRATCH);
522 release_hw_mutex(dd);
523 mutex_unlock(&dd->asic_data->asic_resource_mutex);
525 /* return the number of bytes written */
536 * read the per-port QSFP data for ppd
538 static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
539 size_t count, loff_t *ppos)
541 struct hfi1_pportdata *ppd;
546 ppd = private2ppd(file);
547 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
553 ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
555 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
561 /* Do an i2c write operation on the chain for the given HFI. */
562 static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
563 size_t count, loff_t *ppos, u32 target)
565 struct hfi1_pportdata *ppd;
573 ppd = private2ppd(file);
575 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
576 i2c_addr = (*ppos >> 16) & 0xffff;
577 offset = *ppos & 0xffff;
579 /* explicitly reject invalid address 0 to catch cp and cat */
585 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;
614 /* Do an i2c write operation on chain for HFI 0. */
615 static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
616 size_t count, loff_t *ppos)
618 return __i2c_debugfs_write(file, buf, count, ppos, 0);
621 /* Do an i2c write operation on chain for HFI 1. */
622 static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
623 size_t count, loff_t *ppos)
625 return __i2c_debugfs_write(file, buf, count, ppos, 1);
628 /* Do an i2c read operation on the chain for the given HFI. */
629 static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
630 size_t count, loff_t *ppos, u32 target)
632 struct hfi1_pportdata *ppd;
640 ppd = private2ppd(file);
642 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
643 i2c_addr = (*ppos >> 16) & 0xffff;
644 offset = *ppos & 0xffff;
646 /* explicitly reject invalid address 0 to catch cp and cat */
652 buff = kmalloc(count, GFP_KERNEL);
658 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
659 if (total_read < 0) {
666 ret = copy_to_user(buf, buff, total_read);
681 /* Do an i2c read operation on chain for HFI 0. */
682 static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
683 size_t count, loff_t *ppos)
685 return __i2c_debugfs_read(file, buf, count, ppos, 0);
688 /* Do an i2c read operation on chain for HFI 1. */
689 static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
690 size_t count, loff_t *ppos)
692 return __i2c_debugfs_read(file, buf, count, ppos, 1);
695 /* Do a QSFP write operation on the i2c chain for the given HFI. */
696 static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
697 size_t count, loff_t *ppos, u32 target)
699 struct hfi1_pportdata *ppd;
705 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
710 ppd = private2ppd(file);
712 buff = kmalloc(count, GFP_KERNEL);
718 ret = copy_from_user(buff, buf, count);
724 total_written = qsfp_write(ppd, target, *ppos, buff, count);
725 if (total_written < 0) {
730 *ppos += total_written;
741 /* Do a QSFP write operation on i2c chain for HFI 0. */
742 static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
743 size_t count, loff_t *ppos)
745 return __qsfp_debugfs_write(file, buf, count, ppos, 0);
748 /* Do a QSFP write operation on i2c chain for HFI 1. */
749 static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
750 size_t count, loff_t *ppos)
752 return __qsfp_debugfs_write(file, buf, count, ppos, 1);
755 /* Do a QSFP read operation on the i2c chain for the given HFI. */
756 static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
757 size_t count, loff_t *ppos, u32 target)
759 struct hfi1_pportdata *ppd;
765 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
770 ppd = private2ppd(file);
772 buff = kmalloc(count, GFP_KERNEL);
778 total_read = qsfp_read(ppd, target, *ppos, buff, count);
779 if (total_read < 0) {
786 ret = copy_to_user(buf, buff, total_read);
801 /* Do a QSFP read operation on i2c chain for HFI 0. */
802 static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
803 size_t count, loff_t *ppos)
805 return __qsfp_debugfs_read(file, buf, count, ppos, 0);
808 /* Do a QSFP read operation on i2c chain for HFI 1. */
809 static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
810 size_t count, loff_t *ppos)
812 return __qsfp_debugfs_read(file, buf, count, ppos, 1);
815 static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
817 struct hfi1_pportdata *ppd;
820 if (!try_module_get(THIS_MODULE))
823 ppd = private2ppd(fp);
825 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
826 if (ret) /* failed - release the module */
827 module_put(THIS_MODULE);
832 static int i2c1_debugfs_open(struct inode *in, struct file *fp)
834 return __i2c_debugfs_open(in, fp, 0);
837 static int i2c2_debugfs_open(struct inode *in, struct file *fp)
839 return __i2c_debugfs_open(in, fp, 1);
842 static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
844 struct hfi1_pportdata *ppd;
846 ppd = private2ppd(fp);
848 release_chip_resource(ppd->dd, i2c_target(target));
849 module_put(THIS_MODULE);
854 static int i2c1_debugfs_release(struct inode *in, struct file *fp)
856 return __i2c_debugfs_release(in, fp, 0);
859 static int i2c2_debugfs_release(struct inode *in, struct file *fp)
861 return __i2c_debugfs_release(in, fp, 1);
864 static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
866 struct hfi1_pportdata *ppd;
869 if (!try_module_get(THIS_MODULE))
872 ppd = private2ppd(fp);
874 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
875 if (ret) /* failed - release the module */
876 module_put(THIS_MODULE);
881 static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
883 return __qsfp_debugfs_open(in, fp, 0);
886 static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
888 return __qsfp_debugfs_open(in, fp, 1);
891 static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
893 struct hfi1_pportdata *ppd;
895 ppd = private2ppd(fp);
897 release_chip_resource(ppd->dd, i2c_target(target));
898 module_put(THIS_MODULE);
903 static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
905 return __qsfp_debugfs_release(in, fp, 0);
908 static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
910 return __qsfp_debugfs_release(in, fp, 1);
913 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
917 .read = readroutine, \
918 .write = writeroutine, \
919 .llseek = generic_file_llseek, \
923 #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
929 .llseek = generic_file_llseek, \
931 .release = releasef \
935 static const struct counter_info cntr_ops[] = {
936 DEBUGFS_OPS("counter_names", dev_names_read, NULL),
937 DEBUGFS_OPS("counters", dev_counters_read, NULL),
938 DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
941 static const struct counter_info port_cntr_ops[] = {
942 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
943 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
944 i2c1_debugfs_open, i2c1_debugfs_release),
945 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
946 i2c2_debugfs_open, i2c2_debugfs_release),
947 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
948 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
949 qsfp1_debugfs_open, qsfp1_debugfs_release),
950 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
951 qsfp2_debugfs_open, qsfp2_debugfs_release),
952 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
955 void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
957 char name[sizeof("port0counters") + 1];
959 struct hfi1_devdata *dd = dd_from_dev(ibd);
960 struct hfi1_pportdata *ppd;
966 snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
967 snprintf(link, sizeof(link), "%d", unit);
968 ibd->hfi1_ibdev_dbg = debugfs_create_dir(name, hfi1_dbg_root);
969 if (!ibd->hfi1_ibdev_dbg) {
970 pr_warn("create of %s failed\n", name);
973 ibd->hfi1_ibdev_link =
974 debugfs_create_symlink(link, hfi1_dbg_root, name);
975 if (!ibd->hfi1_ibdev_link) {
976 pr_warn("create of %s symlink failed\n", name);
979 DEBUGFS_SEQ_FILE_CREATE(opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
980 DEBUGFS_SEQ_FILE_CREATE(ctx_stats, ibd->hfi1_ibdev_dbg, ibd);
981 DEBUGFS_SEQ_FILE_CREATE(qp_stats, ibd->hfi1_ibdev_dbg, ibd);
982 DEBUGFS_SEQ_FILE_CREATE(sdes, ibd->hfi1_ibdev_dbg, ibd);
983 /* dev counter files */
984 for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
985 DEBUGFS_FILE_CREATE(cntr_ops[i].name,
988 &cntr_ops[i].ops, S_IRUGO);
990 for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
991 for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
994 port_cntr_ops[i].name,
996 DEBUGFS_FILE_CREATE(name,
999 &port_cntr_ops[i].ops,
1000 !port_cntr_ops[i].ops.write ?
1001 S_IRUGO : S_IRUGO | S_IWUSR);
1005 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
1009 debugfs_remove(ibd->hfi1_ibdev_link);
1010 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
1012 ibd->hfi1_ibdev_dbg = NULL;
1017 * driver stats field names, one line per stat, single string. Used by
1018 * programs like hfistats to print the stats in a way which works for
1019 * different versions of drivers, without changing program source.
1020 * if hfi1_ib_stats changes, this needs to change. Names need to be
1021 * 12 chars or less (w/o newline), for proper display by hfistats utility.
1023 static const char * const hfi1_statnames[] = {
1024 /* must be element 0*/
1037 static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
1041 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1046 static void *_driver_stats_names_seq_next(
1052 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1057 static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
1063 static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
1067 seq_printf(s, "%s\n", hfi1_statnames[*spos]);
1071 DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
1072 DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
1073 DEBUGFS_FILE_OPS(driver_stats_names);
1075 static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
1079 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1084 static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
1087 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1092 static void _driver_stats_seq_stop(struct seq_file *s, void *v)
1098 static u64 hfi1_sps_ints(void)
1100 unsigned long flags;
1101 struct hfi1_devdata *dd;
1104 spin_lock_irqsave(&hfi1_devs_lock, flags);
1105 list_for_each_entry(dd, &hfi1_dev_list, list) {
1106 sps_ints += get_all_cpu_total(dd->int_counter);
1108 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1112 static int _driver_stats_seq_show(struct seq_file *s, void *v)
1116 u64 *stats = (u64 *)&hfi1_stats;
1117 size_t sz = seq_get_buf(s, &buffer);
1119 if (sz < sizeof(u64))
1121 /* special case for interrupts */
1123 *(u64 *)buffer = hfi1_sps_ints();
1125 *(u64 *)buffer = stats[*spos];
1126 seq_commit(s, sizeof(u64));
1130 DEBUGFS_SEQ_FILE_OPS(driver_stats);
1131 DEBUGFS_SEQ_FILE_OPEN(driver_stats)
1132 DEBUGFS_FILE_OPS(driver_stats);
1134 void hfi1_dbg_init(void)
1136 hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
1138 pr_warn("init of debugfs failed\n");
1139 DEBUGFS_SEQ_FILE_CREATE(driver_stats_names, hfi1_dbg_root, NULL);
1140 DEBUGFS_SEQ_FILE_CREATE(driver_stats, hfi1_dbg_root, NULL);
1143 void hfi1_dbg_exit(void)
1145 debugfs_remove_recursive(hfi1_dbg_root);
1146 hfi1_dbg_root = NULL;