2 * Copyright (c) 2013 - 2017 Intel Corporation. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/debugfs.h>
33 #include <linux/seq_file.h>
34 #include <linux/kernel.h>
35 #include <linux/export.h>
38 #include "qib_verbs.h"
39 #include "qib_debugfs.h"
41 static struct dentry
*qib_dbg_root
;
43 #define DEBUGFS_FILE(name) \
44 static const struct seq_operations _##name##_seq_ops = { \
45 .start = _##name##_seq_start, \
46 .next = _##name##_seq_next, \
47 .stop = _##name##_seq_stop, \
48 .show = _##name##_seq_show \
50 static int _##name##_open(struct inode *inode, struct file *s) \
52 struct seq_file *seq; \
54 ret = seq_open(s, &_##name##_seq_ops); \
57 seq = s->private_data; \
58 seq->private = inode->i_private; \
61 static const struct file_operations _##name##_file_ops = { \
62 .owner = THIS_MODULE, \
63 .open = _##name##_open, \
65 .llseek = seq_lseek, \
66 .release = seq_release \
69 static void *_opcode_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
71 struct qib_opcode_stats_perctx
*opstats
;
73 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
78 static void *_opcode_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
80 struct qib_opcode_stats_perctx
*opstats
;
83 if (*pos
>= ARRAY_SIZE(opstats
->stats
))
89 static void _opcode_stats_seq_stop(struct seq_file
*s
, void *v
)
91 /* nothing allocated */
94 static int _opcode_stats_seq_show(struct seq_file
*s
, void *v
)
98 u64 n_packets
= 0, n_bytes
= 0;
99 struct qib_ibdev
*ibd
= (struct qib_ibdev
*)s
->private;
100 struct qib_devdata
*dd
= dd_from_dev(ibd
);
102 for (j
= 0; j
< dd
->first_user_ctxt
; j
++) {
105 n_packets
+= dd
->rcd
[j
]->opstats
->stats
[i
].n_packets
;
106 n_bytes
+= dd
->rcd
[j
]->opstats
->stats
[i
].n_bytes
;
108 if (!n_packets
&& !n_bytes
)
110 seq_printf(s
, "%02llx %llu/%llu\n", i
,
111 (unsigned long long) n_packets
,
112 (unsigned long long) n_bytes
);
117 DEBUGFS_FILE(opcode_stats
)
119 static void *_ctx_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
121 struct qib_ibdev
*ibd
= (struct qib_ibdev
*)s
->private;
122 struct qib_devdata
*dd
= dd_from_dev(ibd
);
125 return SEQ_START_TOKEN
;
126 if (*pos
>= dd
->first_user_ctxt
)
131 static void *_ctx_stats_seq_next(struct seq_file
*s
, void *v
, loff_t
*pos
)
133 struct qib_ibdev
*ibd
= (struct qib_ibdev
*)s
->private;
134 struct qib_devdata
*dd
= dd_from_dev(ibd
);
136 if (v
== SEQ_START_TOKEN
)
140 if (*pos
>= dd
->first_user_ctxt
)
145 static void _ctx_stats_seq_stop(struct seq_file
*s
, void *v
)
147 /* nothing allocated */
150 static int _ctx_stats_seq_show(struct seq_file
*s
, void *v
)
155 struct qib_ibdev
*ibd
= (struct qib_ibdev
*)s
->private;
156 struct qib_devdata
*dd
= dd_from_dev(ibd
);
158 if (v
== SEQ_START_TOKEN
) {
159 seq_puts(s
, "Ctx:npkts\n");
169 for (j
= 0; j
< ARRAY_SIZE(dd
->rcd
[i
]->opstats
->stats
); j
++)
170 n_packets
+= dd
->rcd
[i
]->opstats
->stats
[j
].n_packets
;
175 seq_printf(s
, " %llu:%llu\n", i
, n_packets
);
179 DEBUGFS_FILE(ctx_stats
)
181 static void *_qp_stats_seq_start(struct seq_file
*s
, loff_t
*pos
)
184 struct rvt_qp_iter
*iter
;
187 iter
= rvt_qp_iter_init(s
->private, 0, NULL
);
189 /* stop calls rcu_read_unlock */
196 if (rvt_qp_iter_next(iter
)) {
205 static void *_qp_stats_seq_next(struct seq_file
*s
, void *iter_ptr
,
209 struct rvt_qp_iter
*iter
= iter_ptr
;
213 if (rvt_qp_iter_next(iter
)) {
221 static void _qp_stats_seq_stop(struct seq_file
*s
, void *iter_ptr
)
227 static int _qp_stats_seq_show(struct seq_file
*s
, void *iter_ptr
)
229 struct rvt_qp_iter
*iter
= iter_ptr
;
234 qib_qp_iter_print(s
, iter
);
239 DEBUGFS_FILE(qp_stats
)
241 void qib_dbg_ibdev_init(struct qib_ibdev
*ibd
)
246 snprintf(name
, sizeof(name
), "qib%d", dd_from_dev(ibd
)->unit
);
247 root
= debugfs_create_dir(name
, qib_dbg_root
);
248 ibd
->qib_ibdev_dbg
= root
;
250 debugfs_create_file("opcode_stats", 0400, root
, ibd
,
251 &_opcode_stats_file_ops
);
252 debugfs_create_file("ctx_stats", 0400, root
, ibd
, &_ctx_stats_file_ops
);
253 debugfs_create_file("qp_stats", 0400, root
, ibd
, &_qp_stats_file_ops
);
256 void qib_dbg_ibdev_exit(struct qib_ibdev
*ibd
)
260 debugfs_remove_recursive(ibd
->qib_ibdev_dbg
);
262 ibd
->qib_ibdev_dbg
= NULL
;
265 void qib_dbg_init(void)
267 qib_dbg_root
= debugfs_create_dir(QIB_DRV_NAME
, NULL
);
270 void qib_dbg_exit(void)
272 debugfs_remove_recursive(qib_dbg_root
);