2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 debugfs specific routines.
27 * Set enviroment defines for rt2x00.h
29 #define DRV_NAME "rt2x00lib"
31 #include <linux/debugfs.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/uaccess.h>
37 #include "rt2x00lib.h"
39 #define PRINT_LINE_LEN_MAX 32
41 struct rt2x00debug_intf
{
43 * Pointer to driver structure where
44 * this debugfs entry belongs to.
46 struct rt2x00_dev
*rt2x00dev
;
49 * Reference to the rt2x00debug structure
50 * which can be used to communicate with
53 const struct rt2x00debug
*debug
;
56 * Debugfs entries for:
61 * - register offset/value files
62 * - eeprom offset/value files
63 * - bbp offset/value files
64 * - rf offset/value files
66 struct dentry
*driver_folder
;
67 struct dentry
*driver_entry
;
68 struct dentry
*chipset_entry
;
69 struct dentry
*dev_flags
;
70 struct dentry
*csr_off_entry
;
71 struct dentry
*csr_val_entry
;
72 struct dentry
*eeprom_off_entry
;
73 struct dentry
*eeprom_val_entry
;
74 struct dentry
*bbp_off_entry
;
75 struct dentry
*bbp_val_entry
;
76 struct dentry
*rf_off_entry
;
77 struct dentry
*rf_val_entry
;
80 * Driver and chipset files will use a data buffer
81 * that has been created in advance. This will simplify
82 * the code since we can use the debugfs functions.
84 struct debugfs_blob_wrapper driver_blob
;
85 struct debugfs_blob_wrapper chipset_blob
;
88 * Requested offset for each register type.
90 unsigned int offset_csr
;
91 unsigned int offset_eeprom
;
92 unsigned int offset_bbp
;
93 unsigned int offset_rf
;
96 static int rt2x00debug_file_open(struct inode
*inode
, struct file
*file
)
98 struct rt2x00debug_intf
*intf
= inode
->i_private
;
100 file
->private_data
= inode
->i_private
;
102 if (!try_module_get(intf
->debug
->owner
))
108 static int rt2x00debug_file_release(struct inode
*inode
, struct file
*file
)
110 struct rt2x00debug_intf
*intf
= file
->private_data
;
112 module_put(intf
->debug
->owner
);
117 #define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \
118 static ssize_t rt2x00debug_read_##__name(struct file *file, \
123 struct rt2x00debug_intf *intf = file->private_data; \
124 const struct rt2x00debug *debug = intf->debug; \
132 if (intf->offset_##__name >= debug->__name.word_count) \
135 debug->__name.read(intf->rt2x00dev, \
136 intf->offset_##__name, &value); \
138 size = sprintf(line, __format, value); \
140 if (copy_to_user(buf, line, size)) \
147 #define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \
148 static ssize_t rt2x00debug_write_##__name(struct file *file, \
149 const char __user *buf,\
153 struct rt2x00debug_intf *intf = file->private_data; \
154 const struct rt2x00debug *debug = intf->debug; \
162 if (!capable(CAP_NET_ADMIN)) \
165 if (intf->offset_##__name >= debug->__name.word_count) \
168 if (copy_from_user(line, buf, length)) \
171 size = strlen(line); \
172 value = simple_strtoul(line, NULL, 0); \
174 debug->__name.write(intf->rt2x00dev, \
175 intf->offset_##__name, value); \
181 #define RT2X00DEBUGFS_OPS(__name, __format, __type) \
182 RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \
183 RT2X00DEBUGFS_OPS_WRITE(__name, __type); \
185 static const struct file_operations rt2x00debug_fop_##__name = {\
186 .owner = THIS_MODULE, \
187 .read = rt2x00debug_read_##__name, \
188 .write = rt2x00debug_write_##__name, \
189 .open = rt2x00debug_file_open, \
190 .release = rt2x00debug_file_release, \
193 RT2X00DEBUGFS_OPS(csr
, "0x%.8x\n", u32
);
194 RT2X00DEBUGFS_OPS(eeprom
, "0x%.4x\n", u16
);
195 RT2X00DEBUGFS_OPS(bbp
, "0x%.2x\n", u8
);
196 RT2X00DEBUGFS_OPS(rf
, "0x%.8x\n", u32
);
198 static ssize_t
rt2x00debug_read_dev_flags(struct file
*file
,
203 struct rt2x00debug_intf
*intf
= file
->private_data
;
210 size
= sprintf(line
, "0x%.8x\n", (unsigned int)intf
->rt2x00dev
->flags
);
212 if (copy_to_user(buf
, line
, size
))
219 static const struct file_operations rt2x00debug_fop_dev_flags
= {
220 .owner
= THIS_MODULE
,
221 .read
= rt2x00debug_read_dev_flags
,
222 .open
= rt2x00debug_file_open
,
223 .release
= rt2x00debug_file_release
,
226 static struct dentry
*rt2x00debug_create_file_driver(const char *name
,
227 struct rt2x00debug_intf
229 struct debugfs_blob_wrapper
234 data
= kzalloc(3 * PRINT_LINE_LEN_MAX
, GFP_KERNEL
);
239 data
+= sprintf(data
, "driver: %s\n", intf
->rt2x00dev
->ops
->name
);
240 data
+= sprintf(data
, "version: %s\n", DRV_VERSION
);
241 data
+= sprintf(data
, "compiled: %s %s\n", __DATE__
, __TIME__
);
242 blob
->size
= strlen(blob
->data
);
244 return debugfs_create_blob(name
, S_IRUGO
, intf
->driver_folder
, blob
);
247 static struct dentry
*rt2x00debug_create_file_chipset(const char *name
,
248 struct rt2x00debug_intf
254 const struct rt2x00debug
*debug
= intf
->debug
;
257 data
= kzalloc(4 * PRINT_LINE_LEN_MAX
, GFP_KERNEL
);
262 data
+= sprintf(data
, "csr length: %d\n", debug
->csr
.word_count
);
263 data
+= sprintf(data
, "eeprom length: %d\n", debug
->eeprom
.word_count
);
264 data
+= sprintf(data
, "bbp length: %d\n", debug
->bbp
.word_count
);
265 data
+= sprintf(data
, "rf length: %d\n", debug
->rf
.word_count
);
266 blob
->size
= strlen(blob
->data
);
268 return debugfs_create_blob(name
, S_IRUGO
, intf
->driver_folder
, blob
);
271 void rt2x00debug_register(struct rt2x00_dev
*rt2x00dev
)
273 const struct rt2x00debug
*debug
= rt2x00dev
->ops
->debugfs
;
274 struct rt2x00debug_intf
*intf
;
276 intf
= kzalloc(sizeof(struct rt2x00debug_intf
), GFP_KERNEL
);
278 ERROR(rt2x00dev
, "Failed to allocate debug handler.\n");
283 intf
->rt2x00dev
= rt2x00dev
;
284 rt2x00dev
->debugfs_intf
= intf
;
286 intf
->driver_folder
=
287 debugfs_create_dir(intf
->rt2x00dev
->ops
->name
,
288 rt2x00dev
->hw
->wiphy
->debugfsdir
);
289 if (IS_ERR(intf
->driver_folder
))
293 rt2x00debug_create_file_driver("driver", intf
, &intf
->driver_blob
);
294 if (IS_ERR(intf
->driver_entry
))
297 intf
->chipset_entry
=
298 rt2x00debug_create_file_chipset("chipset",
299 intf
, &intf
->chipset_blob
);
300 if (IS_ERR(intf
->chipset_entry
))
303 intf
->dev_flags
= debugfs_create_file("dev_flags", S_IRUGO
,
304 intf
->driver_folder
, intf
,
305 &rt2x00debug_fop_dev_flags
);
306 if (IS_ERR(intf
->dev_flags
))
309 #define RT2X00DEBUGFS_CREATE_ENTRY(__intf, __name) \
311 (__intf)->__name##_off_entry = \
312 debugfs_create_u32(__stringify(__name) "_offset", \
314 (__intf)->driver_folder, \
315 &(__intf)->offset_##__name); \
316 if (IS_ERR((__intf)->__name##_off_entry)) \
319 (__intf)->__name##_val_entry = \
320 debugfs_create_file(__stringify(__name) "_value", \
322 (__intf)->driver_folder, \
323 (__intf), &rt2x00debug_fop_##__name);\
324 if (IS_ERR((__intf)->__name##_val_entry)) \
328 RT2X00DEBUGFS_CREATE_ENTRY(intf
, csr
);
329 RT2X00DEBUGFS_CREATE_ENTRY(intf
, eeprom
);
330 RT2X00DEBUGFS_CREATE_ENTRY(intf
, bbp
);
331 RT2X00DEBUGFS_CREATE_ENTRY(intf
, rf
);
333 #undef RT2X00DEBUGFS_CREATE_ENTRY
338 rt2x00debug_deregister(rt2x00dev
);
339 ERROR(rt2x00dev
, "Failed to register debug handler.\n");
344 void rt2x00debug_deregister(struct rt2x00_dev
*rt2x00dev
)
346 const struct rt2x00debug_intf
*intf
= rt2x00dev
->debugfs_intf
;
351 debugfs_remove(intf
->rf_val_entry
);
352 debugfs_remove(intf
->rf_off_entry
);
353 debugfs_remove(intf
->bbp_val_entry
);
354 debugfs_remove(intf
->bbp_off_entry
);
355 debugfs_remove(intf
->eeprom_val_entry
);
356 debugfs_remove(intf
->eeprom_off_entry
);
357 debugfs_remove(intf
->csr_val_entry
);
358 debugfs_remove(intf
->csr_off_entry
);
359 debugfs_remove(intf
->dev_flags
);
360 debugfs_remove(intf
->chipset_entry
);
361 debugfs_remove(intf
->driver_entry
);
362 debugfs_remove(intf
->driver_folder
);
363 kfree(intf
->chipset_blob
.data
);
364 kfree(intf
->driver_blob
.data
);
367 rt2x00dev
->debugfs_intf
= NULL
;