1 /* 2 * This file is part of wl1271 3 * 4 * Copyright (C) 2009 Nokia Corporation 5 * 6 * Contact: Luciano Coelho <luciano.coelho@nokia.com> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * version 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA 21 * 22 */ 23 24 #ifndef __DEBUGFS_H__ 25 #define __DEBUGFS_H__ 26 27 #include "wlcore.h" 28 29 __printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count, 30 loff_t *ppos, char *fmt, ...); 31 32 int wl1271_debugfs_init(struct wl1271 *wl); 33 void wl1271_debugfs_exit(struct wl1271 *wl); 34 void wl1271_debugfs_reset(struct wl1271 *wl); 35 void wl1271_debugfs_update_stats(struct wl1271 *wl); 36 37 #define DEBUGFS_FORMAT_BUFFER_SIZE 256 38 39 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ 40 static ssize_t name## _read(struct file *file, char __user *userbuf, \ 41 size_t count, loff_t *ppos) \ 42 { \ 43 struct wl1271 *wl = file->private_data; \ 44 return wl1271_format_buffer(userbuf, count, ppos, \ 45 fmt "\n", ##value); \ 46 } \ 47 \ 48 static const struct file_operations name## _ops = { \ 49 .read = name## _read, \ 50 .open = simple_open, \ 51 .llseek = generic_file_llseek, \ 52 }; 53 54 #define DEBUGFS_ADD(name, parent) \ 55 do { \ 56 entry = debugfs_create_file(#name, 0400, parent, \ 57 wl, &name## _ops); \ 58 if (!entry || IS_ERR(entry)) \ 59 goto err; \ 60 } while (0) 61 62 63 #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \ 64 do { \ 65 entry = debugfs_create_file(#name, 0400, parent, \ 66 wl, &prefix## _## name## _ops); \ 67 if (!entry || IS_ERR(entry)) \ 68 goto err; \ 69 } while (0) 70 71 #define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \ 72 static ssize_t sub## _ ##name## _read(struct file *file, \ 73 char __user *userbuf, \ 74 size_t count, loff_t *ppos) \ 75 { \ 76 struct wl1271 *wl = file->private_data; \ 77 struct struct_type *stats = wl->stats.fw_stats; \ 78 \ 79 wl1271_debugfs_update_stats(wl); \ 80 \ 81 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \ 82 stats->sub.name); \ 83 } \ 84 \ 85 static const struct file_operations sub## _ ##name## _ops = { \ 86 .read = sub## _ ##name## _read, \ 87 .open = simple_open, \ 88 .llseek = generic_file_llseek, \ 89 }; 90 91 #define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \ 92 static ssize_t sub## _ ##name## _read(struct file *file, \ 93 char __user *userbuf, \ 94 size_t count, loff_t *ppos) \ 95 { \ 96 struct wl1271 *wl = file->private_data; \ 97 struct struct_type *stats = wl->stats.fw_stats; \ 98 char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \ 99 int res, i; \ 100 \ 101 wl1271_debugfs_update_stats(wl); \ 102 \ 103 for (i = 0; i < len; i++) \ 104 res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \ 105 buf, i, stats->sub.name[i]); \ 106 \ 107 return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \ 108 } \ 109 \ 110 static const struct file_operations sub## _ ##name## _ops = { \ 111 .read = sub## _ ##name## _read, \ 112 .open = simple_open, \ 113 .llseek = generic_file_llseek, \ 114 }; 115 116 #define DEBUGFS_FWSTATS_ADD(sub, name) \ 117 DEBUGFS_ADD(sub## _ ##name, stats) 118 119 120 #endif /* WL1271_DEBUGFS_H */ 121