61
61
#include <linux/pci.h>
62
62
#include <linux/slab.h>
63
63
#include <linux/spinlock.h>
64
+ #include <linux/debugfs.h>
64
65
65
66
#include <linux/ntb.h>
66
67
@@ -96,8 +97,13 @@ struct pp_ctx {
96
97
spinlock_t db_lock ;
97
98
struct timer_list db_timer ;
98
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
107
static void pp_ping (unsigned long ctx )
102
108
{
103
109
struct pp_ctx * pp = (void * )ctx ;
@@ -171,10 +177,32 @@ static void pp_db_event(void *ctx, int vec)
171
177
dev_dbg (& pp -> ntb -> dev ,
172
178
"Pong vec %d bits %#llx\n" ,
173
179
vec , db_bits );
180
+ atomic_inc (& pp -> count );
174
181
}
175
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
206
static const struct ntb_ctx_ops pp_ops = {
179
207
.link_event = pp_link_event ,
180
208
.db_event = pp_db_event ,
@@ -210,6 +238,7 @@ static int pp_probe(struct ntb_client *client,
210
238
211
239
pp -> ntb = ntb ;
212
240
pp -> db_bits = 0 ;
241
+ atomic_set (& pp -> count , 0 );
213
242
spin_lock_init (& pp -> db_lock );
214
243
setup_timer (& pp -> db_timer , pp_ping , (unsigned long )pp );
215
244
pp -> db_delay = msecs_to_jiffies (delay_ms );
@@ -218,6 +247,10 @@ static int pp_probe(struct ntb_client *client,
218
247
if (rc )
219
248
goto err_ctx ;
220
249
250
+ rc = pp_debugfs_setup (pp );
251
+ if (rc )
252
+ goto err_ctx ;
253
+
221
254
ntb_link_enable (ntb , NTB_SPEED_AUTO , NTB_WIDTH_AUTO );
222
255
ntb_link_event (ntb );
223
256
@@ -234,6 +267,8 @@ static void pp_remove(struct ntb_client *client,
234
267
{
235
268
struct pp_ctx * pp = ntb -> ctx ;
236
269
270
+ debugfs_remove_recursive (pp -> debugfs_node_dir );
271
+
237
272
ntb_clear_ctx (ntb );
238
273
del_timer_sync (& pp -> db_timer );
239
274
ntb_link_disable (ntb );
@@ -247,4 +282,29 @@ static struct ntb_client pp_client = {
247
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 );
0 commit comments