diff options
author | Logan Gunthorpe <logang@deltatee.com> | 2016-06-20 15:15:11 -0400 |
---|---|---|
committer | Jon Mason <jdmason@kudzu.us> | 2016-08-05 10:21:07 -0400 |
commit | 20572ee1c577609f38b56b81c760dcb4151f1dbf (patch) | |
tree | 4e572da3619bc301724e53b90816a2f96082d58b | |
parent | bfcaa39652bf64294261415e5fa18ef0445a4d74 (diff) |
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>
-rw-r--r-- | drivers/ntb/test/ntb_pingpong.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/drivers/ntb/test/ntb_pingpong.c b/drivers/ntb/test/ntb_pingpong.c index fe1600566981..7d311799fca1 100644 --- a/drivers/ntb/test/ntb_pingpong.c +++ b/drivers/ntb/test/ntb_pingpong.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #include <linux/pci.h> | 61 | #include <linux/pci.h> |
62 | #include <linux/slab.h> | 62 | #include <linux/slab.h> |
63 | #include <linux/spinlock.h> | 63 | #include <linux/spinlock.h> |
64 | #include <linux/debugfs.h> | ||
64 | 65 | ||
65 | #include <linux/ntb.h> | 66 | #include <linux/ntb.h> |
66 | 67 | ||
@@ -96,8 +97,13 @@ struct pp_ctx { | |||
96 | spinlock_t db_lock; | 97 | spinlock_t db_lock; |
97 | struct timer_list db_timer; | 98 | struct timer_list db_timer; |
98 | unsigned long db_delay; | 99 | unsigned long db_delay; |
100 | struct dentry *debugfs_node_dir; | ||
101 | struct dentry *debugfs_count; | ||
102 | atomic_t count; | ||
99 | }; | 103 | }; |
100 | 104 | ||
105 | static struct dentry *pp_debugfs_dir; | ||
106 | |||
101 | static void pp_ping(unsigned long ctx) | 107 | static void pp_ping(unsigned long ctx) |
102 | { | 108 | { |
103 | struct pp_ctx *pp = (void *)ctx; | 109 | struct pp_ctx *pp = (void *)ctx; |
@@ -171,10 +177,32 @@ static void pp_db_event(void *ctx, int vec) | |||
171 | dev_dbg(&pp->ntb->dev, | 177 | dev_dbg(&pp->ntb->dev, |
172 | "Pong vec %d bits %#llx\n", | 178 | "Pong vec %d bits %#llx\n", |
173 | vec, db_bits); | 179 | vec, db_bits); |
180 | atomic_inc(&pp->count); | ||
174 | } | 181 | } |
175 | spin_unlock_irqrestore(&pp->db_lock, irqflags); | 182 | spin_unlock_irqrestore(&pp->db_lock, irqflags); |
176 | } | 183 | } |
177 | 184 | ||
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 | |||
178 | static const struct ntb_ctx_ops pp_ops = { | 206 | static const struct ntb_ctx_ops pp_ops = { |
179 | .link_event = pp_link_event, | 207 | .link_event = pp_link_event, |
180 | .db_event = pp_db_event, | 208 | .db_event = pp_db_event, |
@@ -210,6 +238,7 @@ static int pp_probe(struct ntb_client *client, | |||
210 | 238 | ||
211 | pp->ntb = ntb; | 239 | pp->ntb = ntb; |
212 | pp->db_bits = 0; | 240 | pp->db_bits = 0; |
241 | atomic_set(&pp->count, 0); | ||
213 | spin_lock_init(&pp->db_lock); | 242 | spin_lock_init(&pp->db_lock); |
214 | setup_timer(&pp->db_timer, pp_ping, (unsigned long)pp); | 243 | setup_timer(&pp->db_timer, pp_ping, (unsigned long)pp); |
215 | pp->db_delay = msecs_to_jiffies(delay_ms); | 244 | pp->db_delay = msecs_to_jiffies(delay_ms); |
@@ -218,6 +247,10 @@ static int pp_probe(struct ntb_client *client, | |||
218 | if (rc) | 247 | if (rc) |
219 | goto err_ctx; | 248 | goto err_ctx; |
220 | 249 | ||
250 | rc = pp_debugfs_setup(pp); | ||
251 | if (rc) | ||
252 | goto err_ctx; | ||
253 | |||
221 | ntb_link_enable(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO); | 254 | ntb_link_enable(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO); |
222 | ntb_link_event(ntb); | 255 | ntb_link_event(ntb); |
223 | 256 | ||
@@ -234,6 +267,8 @@ static void pp_remove(struct ntb_client *client, | |||
234 | { | 267 | { |
235 | struct pp_ctx *pp = ntb->ctx; | 268 | struct pp_ctx *pp = ntb->ctx; |
236 | 269 | ||
270 | debugfs_remove_recursive(pp->debugfs_node_dir); | ||
271 | |||
237 | ntb_clear_ctx(ntb); | 272 | ntb_clear_ctx(ntb); |
238 | del_timer_sync(&pp->db_timer); | 273 | del_timer_sync(&pp->db_timer); |
239 | ntb_link_disable(ntb); | 274 | ntb_link_disable(ntb); |
@@ -247,4 +282,29 @@ static struct ntb_client pp_client = { | |||
247 | .remove = pp_remove, | 282 | .remove = pp_remove, |
248 | }, | 283 | }, |
249 | }; | 284 | }; |
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); | ||