Skip to content

Commit 20572ee

Browse files
lsgunthjonmason
authored andcommitted
ntb_pingpong: Add a debugfs file to get the ping count
This commit adds a debugfs 'count' file to ntb_pingpong. This is so testing with ntb_pingpong can be automated beyond just checking the logs for pong messages. The count file returns a number which increments every pong. The counter can be cleared by writing a zero. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Allen Hubbe <Allen.Hubbe@emc.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent bfcaa39 commit 20572ee

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

drivers/ntb/test/ntb_pingpong.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <linux/pci.h>
6262
#include <linux/slab.h>
6363
#include <linux/spinlock.h>
64+
#include <linux/debugfs.h>
6465

6566
#include <linux/ntb.h>
6667

@@ -96,8 +97,13 @@ struct pp_ctx {
9697
spinlock_t db_lock;
9798
struct timer_list db_timer;
9899
unsigned long db_delay;
100+
struct dentry *debugfs_node_dir;
101+
struct dentry *debugfs_count;
102+
atomic_t count;
99103
};
100104

105+
static struct dentry *pp_debugfs_dir;
106+
101107
static void pp_ping(unsigned long ctx)
102108
{
103109
struct pp_ctx *pp = (void *)ctx;
@@ -171,10 +177,32 @@ static void pp_db_event(void *ctx, int vec)
171177
dev_dbg(&pp->ntb->dev,
172178
"Pong vec %d bits %#llx\n",
173179
vec, db_bits);
180+
atomic_inc(&pp->count);
174181
}
175182
spin_unlock_irqrestore(&pp->db_lock, irqflags);
176183
}
177184

185+
static int pp_debugfs_setup(struct pp_ctx *pp)
186+
{
187+
struct pci_dev *pdev = pp->ntb->pdev;
188+
189+
if (!pp_debugfs_dir)
190+
return -ENODEV;
191+
192+
pp->debugfs_node_dir = debugfs_create_dir(pci_name(pdev),
193+
pp_debugfs_dir);
194+
if (!pp->debugfs_node_dir)
195+
return -ENODEV;
196+
197+
pp->debugfs_count = debugfs_create_atomic_t("count", S_IRUSR | S_IWUSR,
198+
pp->debugfs_node_dir,
199+
&pp->count);
200+
if (!pp->debugfs_count)
201+
return -ENODEV;
202+
203+
return 0;
204+
}
205+
178206
static const struct ntb_ctx_ops pp_ops = {
179207
.link_event = pp_link_event,
180208
.db_event = pp_db_event,
@@ -210,6 +238,7 @@ static int pp_probe(struct ntb_client *client,
210238

211239
pp->ntb = ntb;
212240
pp->db_bits = 0;
241+
atomic_set(&pp->count, 0);
213242
spin_lock_init(&pp->db_lock);
214243
setup_timer(&pp->db_timer, pp_ping, (unsigned long)pp);
215244
pp->db_delay = msecs_to_jiffies(delay_ms);
@@ -218,6 +247,10 @@ static int pp_probe(struct ntb_client *client,
218247
if (rc)
219248
goto err_ctx;
220249

250+
rc = pp_debugfs_setup(pp);
251+
if (rc)
252+
goto err_ctx;
253+
221254
ntb_link_enable(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
222255
ntb_link_event(ntb);
223256

@@ -234,6 +267,8 @@ static void pp_remove(struct ntb_client *client,
234267
{
235268
struct pp_ctx *pp = ntb->ctx;
236269

270+
debugfs_remove_recursive(pp->debugfs_node_dir);
271+
237272
ntb_clear_ctx(ntb);
238273
del_timer_sync(&pp->db_timer);
239274
ntb_link_disable(ntb);
@@ -247,4 +282,29 @@ static struct ntb_client pp_client = {
247282
.remove = pp_remove,
248283
},
249284
};
250-
module_ntb_client(pp_client);
285+
286+
static int __init pp_init(void)
287+
{
288+
int rc;
289+
290+
if (debugfs_initialized())
291+
pp_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
292+
293+
rc = ntb_register_client(&pp_client);
294+
if (rc)
295+
goto err_client;
296+
297+
return 0;
298+
299+
err_client:
300+
debugfs_remove_recursive(pp_debugfs_dir);
301+
return rc;
302+
}
303+
module_init(pp_init);
304+
305+
static void __exit pp_exit(void)
306+
{
307+
ntb_unregister_client(&pp_client);
308+
debugfs_remove_recursive(pp_debugfs_dir);
309+
}
310+
module_exit(pp_exit);

0 commit comments

Comments
 (0)