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;
232 iter = qp_iter_init(s->private);
237 if (qp_iter_next(iter)) {
246 static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
249 struct qp_iter *iter = iter_ptr;
253 if (qp_iter_next(iter)) {
261 static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
267 static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
269 struct qp_iter *iter = iter_ptr;
274 qp_iter_print(s, iter);
279 DEBUGFS_SEQ_FILE_OPS(qp_stats);
280 DEBUGFS_SEQ_FILE_OPEN(qp_stats)
281 DEBUGFS_FILE_OPS(qp_stats);
283 static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
286 struct hfi1_ibdev *ibd;
287 struct hfi1_devdata *dd;
290 ibd = (struct hfi1_ibdev *)s->private;
291 dd = dd_from_dev(ibd);
292 if (!dd->per_sdma || *pos >= dd->num_sdma)
297 static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
299 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
300 struct hfi1_devdata *dd = dd_from_dev(ibd);
303 if (!dd->per_sdma || *pos >= dd->num_sdma)
308 static void _sdes_seq_stop(struct seq_file *s, void *v)
314 static int _sdes_seq_show(struct seq_file *s, void *v)
316 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
317 struct hfi1_devdata *dd = dd_from_dev(ibd);
321 sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
325 DEBUGFS_SEQ_FILE_OPS(sdes);
326 DEBUGFS_SEQ_FILE_OPEN(sdes)
327 DEBUGFS_FILE_OPS(sdes);
329 /* read the per-device counters */
330 static ssize_t dev_counters_read(struct file *file, char __user *buf,
331 size_t count, loff_t *ppos)
335 struct hfi1_devdata *dd;
339 dd = private2dd(file);
340 avail = hfi1_read_cntrs(dd, NULL, &counters);
341 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
346 /* read the per-device counters */
347 static ssize_t dev_names_read(struct file *file, char __user *buf,
348 size_t count, loff_t *ppos)
352 struct hfi1_devdata *dd;
356 dd = private2dd(file);
357 avail = hfi1_read_cntrs(dd, &names, NULL);
358 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
363 struct counter_info {
365 const struct file_operations ops;
369 * Could use file_inode(file)->i_ino to figure out which file,
370 * instead of separate routine for each, but for now, this works...
373 /* read the per-port names (same for each port) */
374 static ssize_t portnames_read(struct file *file, char __user *buf,
375 size_t count, loff_t *ppos)
379 struct hfi1_devdata *dd;
383 dd = private2dd(file);
384 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
385 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
390 /* read the per-port counters */
391 static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
392 size_t count, loff_t *ppos)
396 struct hfi1_pportdata *ppd;
400 ppd = private2ppd(file);
401 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
402 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
407 static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
408 int this_hfi, int hfi, u32 flag, const char *what)
412 mask = flag << (hfi ? CR_DYN_SHIFT : 0);
413 if (scratch0 & mask) {
414 *used += scnprintf(p + *used, size - *used,
415 " 0x%08x - HFI%d %s in use, %s device\n",
417 this_hfi == hfi ? "this" : "other");
421 static ssize_t asic_flags_read(struct file *file, char __user *buf,
422 size_t count, loff_t *ppos)
424 struct hfi1_pportdata *ppd;
425 struct hfi1_devdata *dd;
434 ppd = private2ppd(file);
438 tmp = kmalloc(size, GFP_KERNEL);
444 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
445 used += scnprintf(tmp + used, size - used,
446 "Resource flags: 0x%016llx\n", scratch0);
448 /* check permanent flag */
449 if (scratch0 & CR_THERM_INIT) {
450 used += scnprintf(tmp + used, size - used,
451 " 0x%08x - thermal monitoring initialized\n",
455 /* check each dynamic flag on each HFI */
456 for (i = 0; i < 2; i++) {
457 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
459 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
461 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
462 CR_I2C1, "i2c chain 1");
463 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
464 CR_I2C2, "i2c chain 2");
466 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
468 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
474 static ssize_t asic_flags_write(struct file *file, const char __user *buf,
475 size_t count, loff_t *ppos)
477 struct hfi1_pportdata *ppd;
478 struct hfi1_devdata *dd;
481 unsigned long long value;
486 ppd = private2ppd(file);
489 buff = kmalloc(count + 1, GFP_KERNEL);
495 ret = copy_from_user(buff, buf, count);
501 /* zero terminate and read the expected integer */
503 ret = kstrtoull(buff, 0, &value);
508 /* obtain exclusive access */
509 mutex_lock(&dd->asic_data->asic_resource_mutex);
510 acquire_hw_mutex(dd);
512 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
514 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
515 /* force write to be visible to other HFI on another OS */
516 (void)read_csr(dd, ASIC_CFG_SCRATCH);
518 release_hw_mutex(dd);
519 mutex_unlock(&dd->asic_data->asic_resource_mutex);
521 /* return the number of bytes written */
532 * read the per-port QSFP data for ppd
534 static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
535 size_t count, loff_t *ppos)
537 struct hfi1_pportdata *ppd;
542 ppd = private2ppd(file);
543 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
549 ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
551 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
557 /* Do an i2c write operation on the chain for the given HFI. */
558 static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
559 size_t count, loff_t *ppos, u32 target)
561 struct hfi1_pportdata *ppd;
569 ppd = private2ppd(file);
571 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
572 i2c_addr = (*ppos >> 16) & 0xffff;
573 offset = *ppos & 0xffff;
575 /* explicitly reject invalid address 0 to catch cp and cat */
581 buff = kmalloc(count, GFP_KERNEL);
587 ret = copy_from_user(buff, buf, count);
593 total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
594 if (total_written < 0) {
599 *ppos += total_written;
610 /* Do an i2c write operation on chain for HFI 0. */
611 static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
612 size_t count, loff_t *ppos)
614 return __i2c_debugfs_write(file, buf, count, ppos, 0);
617 /* Do an i2c write operation on chain for HFI 1. */
618 static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
619 size_t count, loff_t *ppos)
621 return __i2c_debugfs_write(file, buf, count, ppos, 1);
624 /* Do an i2c read operation on the chain for the given HFI. */
625 static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
626 size_t count, loff_t *ppos, u32 target)
628 struct hfi1_pportdata *ppd;
636 ppd = private2ppd(file);
638 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
639 i2c_addr = (*ppos >> 16) & 0xffff;
640 offset = *ppos & 0xffff;
642 /* explicitly reject invalid address 0 to catch cp and cat */
648 buff = kmalloc(count, GFP_KERNEL);
654 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
655 if (total_read < 0) {
662 ret = copy_to_user(buf, buff, total_read);
677 /* Do an i2c read operation on chain for HFI 0. */
678 static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
679 size_t count, loff_t *ppos)
681 return __i2c_debugfs_read(file, buf, count, ppos, 0);
684 /* Do an i2c read operation on chain for HFI 1. */
685 static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
686 size_t count, loff_t *ppos)
688 return __i2c_debugfs_read(file, buf, count, ppos, 1);
691 /* Do a QSFP write operation on the i2c chain for the given HFI. */
692 static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
693 size_t count, loff_t *ppos, u32 target)
695 struct hfi1_pportdata *ppd;
701 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
706 ppd = private2ppd(file);
708 buff = kmalloc(count, GFP_KERNEL);
714 ret = copy_from_user(buff, buf, count);
720 total_written = qsfp_write(ppd, target, *ppos, buff, count);
721 if (total_written < 0) {
726 *ppos += total_written;
737 /* Do a QSFP write operation on i2c chain for HFI 0. */
738 static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
739 size_t count, loff_t *ppos)
741 return __qsfp_debugfs_write(file, buf, count, ppos, 0);
744 /* Do a QSFP write operation on i2c chain for HFI 1. */
745 static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
746 size_t count, loff_t *ppos)
748 return __qsfp_debugfs_write(file, buf, count, ppos, 1);
751 /* Do a QSFP read operation on the i2c chain for the given HFI. */
752 static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
753 size_t count, loff_t *ppos, u32 target)
755 struct hfi1_pportdata *ppd;
761 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
766 ppd = private2ppd(file);
768 buff = kmalloc(count, GFP_KERNEL);
774 total_read = qsfp_read(ppd, target, *ppos, buff, count);
775 if (total_read < 0) {
782 ret = copy_to_user(buf, buff, total_read);
797 /* Do a QSFP read operation on i2c chain for HFI 0. */
798 static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
799 size_t count, loff_t *ppos)
801 return __qsfp_debugfs_read(file, buf, count, ppos, 0);
804 /* Do a QSFP read operation on i2c chain for HFI 1. */
805 static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
806 size_t count, loff_t *ppos)
808 return __qsfp_debugfs_read(file, buf, count, ppos, 1);
811 static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
813 struct hfi1_pportdata *ppd;
816 if (!try_module_get(THIS_MODULE))
819 ppd = private2ppd(fp);
821 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
822 if (ret) /* failed - release the module */
823 module_put(THIS_MODULE);
828 static int i2c1_debugfs_open(struct inode *in, struct file *fp)
830 return __i2c_debugfs_open(in, fp, 0);
833 static int i2c2_debugfs_open(struct inode *in, struct file *fp)
835 return __i2c_debugfs_open(in, fp, 1);
838 static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
840 struct hfi1_pportdata *ppd;
842 ppd = private2ppd(fp);
844 release_chip_resource(ppd->dd, i2c_target(target));
845 module_put(THIS_MODULE);
850 static int i2c1_debugfs_release(struct inode *in, struct file *fp)
852 return __i2c_debugfs_release(in, fp, 0);
855 static int i2c2_debugfs_release(struct inode *in, struct file *fp)
857 return __i2c_debugfs_release(in, fp, 1);
860 static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
862 struct hfi1_pportdata *ppd;
865 if (!try_module_get(THIS_MODULE))
868 ppd = private2ppd(fp);
870 ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
871 if (ret) /* failed - release the module */
872 module_put(THIS_MODULE);
877 static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
879 return __qsfp_debugfs_open(in, fp, 0);
882 static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
884 return __qsfp_debugfs_open(in, fp, 1);
887 static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
889 struct hfi1_pportdata *ppd;
891 ppd = private2ppd(fp);
893 release_chip_resource(ppd->dd, i2c_target(target));
894 module_put(THIS_MODULE);
899 static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
901 return __qsfp_debugfs_release(in, fp, 0);
904 static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
906 return __qsfp_debugfs_release(in, fp, 1);
909 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
913 .read = readroutine, \
914 .write = writeroutine, \
915 .llseek = generic_file_llseek, \
919 #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
925 .llseek = generic_file_llseek, \
927 .release = releasef \
931 static const struct counter_info cntr_ops[] = {
932 DEBUGFS_OPS("counter_names", dev_names_read, NULL),
933 DEBUGFS_OPS("counters", dev_counters_read, NULL),
934 DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
937 static const struct counter_info port_cntr_ops[] = {
938 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
939 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
940 i2c1_debugfs_open, i2c1_debugfs_release),
941 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
942 i2c2_debugfs_open, i2c2_debugfs_release),
943 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
944 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
945 qsfp1_debugfs_open, qsfp1_debugfs_release),
946 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
947 qsfp2_debugfs_open, qsfp2_debugfs_release),
948 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
951 void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
953 char name[sizeof("port0counters") + 1];
955 struct hfi1_devdata *dd = dd_from_dev(ibd);
956 struct hfi1_pportdata *ppd;
962 snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
963 snprintf(link, sizeof(link), "%d", unit);
964 ibd->hfi1_ibdev_dbg = debugfs_create_dir(name, hfi1_dbg_root);
965 if (!ibd->hfi1_ibdev_dbg) {
966 pr_warn("create of %s failed\n", name);
969 ibd->hfi1_ibdev_link =
970 debugfs_create_symlink(link, hfi1_dbg_root, name);
971 if (!ibd->hfi1_ibdev_link) {
972 pr_warn("create of %s symlink failed\n", name);
975 DEBUGFS_SEQ_FILE_CREATE(opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
976 DEBUGFS_SEQ_FILE_CREATE(ctx_stats, ibd->hfi1_ibdev_dbg, ibd);
977 DEBUGFS_SEQ_FILE_CREATE(qp_stats, ibd->hfi1_ibdev_dbg, ibd);
978 DEBUGFS_SEQ_FILE_CREATE(sdes, ibd->hfi1_ibdev_dbg, ibd);
979 /* dev counter files */
980 for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
981 DEBUGFS_FILE_CREATE(cntr_ops[i].name,
984 &cntr_ops[i].ops, S_IRUGO);
986 for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
987 for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
990 port_cntr_ops[i].name,
992 DEBUGFS_FILE_CREATE(name,
995 &port_cntr_ops[i].ops,
996 !port_cntr_ops[i].ops.write ?
997 S_IRUGO : S_IRUGO | S_IWUSR);
1001 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
1005 debugfs_remove(ibd->hfi1_ibdev_link);
1006 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
1008 ibd->hfi1_ibdev_dbg = NULL;
1013 * driver stats field names, one line per stat, single string. Used by
1014 * programs like hfistats to print the stats in a way which works for
1015 * different versions of drivers, without changing program source.
1016 * if hfi1_ib_stats changes, this needs to change. Names need to be
1017 * 12 chars or less (w/o newline), for proper display by hfistats utility.
1019 static const char * const hfi1_statnames[] = {
1020 /* must be element 0*/
1033 static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
1037 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1042 static void *_driver_stats_names_seq_next(
1048 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1053 static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
1059 static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
1063 seq_printf(s, "%s\n", hfi1_statnames[*spos]);
1067 DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
1068 DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
1069 DEBUGFS_FILE_OPS(driver_stats_names);
1071 static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
1075 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1080 static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
1083 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1088 static void _driver_stats_seq_stop(struct seq_file *s, void *v)
1094 static u64 hfi1_sps_ints(void)
1096 unsigned long flags;
1097 struct hfi1_devdata *dd;
1100 spin_lock_irqsave(&hfi1_devs_lock, flags);
1101 list_for_each_entry(dd, &hfi1_dev_list, list) {
1102 sps_ints += get_all_cpu_total(dd->int_counter);
1104 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1108 static int _driver_stats_seq_show(struct seq_file *s, void *v)
1112 u64 *stats = (u64 *)&hfi1_stats;
1113 size_t sz = seq_get_buf(s, &buffer);
1115 if (sz < sizeof(u64))
1117 /* special case for interrupts */
1119 *(u64 *)buffer = hfi1_sps_ints();
1121 *(u64 *)buffer = stats[*spos];
1122 seq_commit(s, sizeof(u64));
1126 DEBUGFS_SEQ_FILE_OPS(driver_stats);
1127 DEBUGFS_SEQ_FILE_OPEN(driver_stats)
1128 DEBUGFS_FILE_OPS(driver_stats);
1130 void hfi1_dbg_init(void)
1132 hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
1134 pr_warn("init of debugfs failed\n");
1135 DEBUGFS_SEQ_FILE_CREATE(driver_stats_names, hfi1_dbg_root, NULL);
1136 DEBUGFS_SEQ_FILE_CREATE(driver_stats, hfi1_dbg_root, NULL);
1139 void hfi1_dbg_exit(void)
1141 debugfs_remove_recursive(hfi1_dbg_root);
1142 hfi1_dbg_root = NULL;