1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * This file is part of wl1271
5 * Copyright (C) 2009 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
15 __printf(4, 5) int wl1271_format_buffer(char __user
*userbuf
, size_t count
,
16 loff_t
*ppos
, char *fmt
, ...);
18 int wl1271_debugfs_init(struct wl1271
*wl
);
19 void wl1271_debugfs_exit(struct wl1271
*wl
);
20 void wl1271_debugfs_reset(struct wl1271
*wl
);
21 void wl1271_debugfs_update_stats(struct wl1271
*wl
);
23 #define DEBUGFS_FORMAT_BUFFER_SIZE 256
25 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
26 static ssize_t name## _read(struct file *file, char __user *userbuf, \
27 size_t count, loff_t *ppos) \
29 struct wl1271 *wl = file->private_data; \
30 return wl1271_format_buffer(userbuf, count, ppos, \
34 static const struct file_operations name## _ops = { \
35 .read = name## _read, \
36 .open = simple_open, \
37 .llseek = generic_file_llseek, \
40 #define DEBUGFS_ADD(name, parent) \
42 debugfs_create_file(#name, 0400, parent, \
47 #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
49 debugfs_create_file(#name, 0400, parent, \
50 wl, &prefix## _## name## _ops); \
53 #define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \
54 static ssize_t sub## _ ##name## _read(struct file *file, \
55 char __user *userbuf, \
56 size_t count, loff_t *ppos) \
58 struct wl1271 *wl = file->private_data; \
59 struct struct_type *stats = wl->stats.fw_stats; \
61 wl1271_debugfs_update_stats(wl); \
63 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
67 static const struct file_operations sub## _ ##name## _ops = { \
68 .read = sub## _ ##name## _read, \
69 .open = simple_open, \
70 .llseek = generic_file_llseek, \
73 #define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \
74 static ssize_t sub## _ ##name## _read(struct file *file, \
75 char __user *userbuf, \
76 size_t count, loff_t *ppos) \
78 struct wl1271 *wl = file->private_data; \
79 struct struct_type *stats = wl->stats.fw_stats; \
80 char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \
83 wl1271_debugfs_update_stats(wl); \
85 for (i = 0; i < len; i++) \
86 res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
87 buf, i, stats->sub.name[i]); \
89 return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \
92 static const struct file_operations sub## _ ##name## _ops = { \
93 .read = sub## _ ##name## _read, \
94 .open = simple_open, \
95 .llseek = generic_file_llseek, \
98 #define DEBUGFS_FWSTATS_ADD(sub, name) \
99 DEBUGFS_ADD(sub## _ ##name, stats)
102 #endif /* WL1271_DEBUGFS_H */