2015-05-11 05:30:56 +00:00
|
|
|
/*
|
|
|
|
* NewportMedia WiFi chipset driver test tools - wilc-debug
|
|
|
|
* Copyright (c) 2012 NewportMedia Inc.
|
|
|
|
* Author: SSW <sswd@wilcsemic.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(WILC_DEBUGFS)
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
|
|
|
|
#include "wilc_wlan_if.h"
|
|
|
|
|
|
|
|
|
|
|
|
static struct dentry *wilc_dir;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2016-02-04 09:24:30 +00:00
|
|
|
#define DBG_REGION_ALL (HOSTAPD_DBG | CFG80211_DBG | INIT_DBG)
|
2015-05-11 05:30:56 +00:00
|
|
|
#define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
|
2016-02-04 09:24:30 +00:00
|
|
|
atomic_t WILC_REGION = ATOMIC_INIT(INIT_DBG | CFG80211_DBG |
|
2016-02-04 09:24:29 +00:00
|
|
|
HOSTAPD_DBG);
|
2015-11-16 14:05:08 +00:00
|
|
|
EXPORT_SYMBOL_GPL(WILC_REGION);
|
2015-11-16 14:04:54 +00:00
|
|
|
atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
|
2015-11-16 14:05:08 +00:00
|
|
|
EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* only allow read from start */
|
|
|
|
if (*ppos > 0)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-16 14:04:54 +00:00
|
|
|
res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&WILC_DEBUG_LEVEL));
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
|
|
|
}
|
|
|
|
|
2015-08-15 06:53:31 +00:00
|
|
|
static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
int flag = 0;
|
2015-08-15 06:53:31 +00:00
|
|
|
int ret;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-08-15 06:53:31 +00:00
|
|
|
ret = kstrtouint_from_user(buf, count, 16, &flag);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
if (flag > DBG_LEVEL_ALL) {
|
2015-11-16 14:04:54 +00:00
|
|
|
printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
|
2015-08-15 06:53:31 +00:00
|
|
|
return -EINVAL;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 14:04:54 +00:00
|
|
|
atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-08-08 12:11:36 +00:00
|
|
|
if (flag == 0)
|
2016-02-14 04:19:10 +00:00
|
|
|
printk(KERN_INFO "Debug-level disabled\n");
|
2015-08-08 12:11:36 +00:00
|
|
|
else
|
2016-02-14 04:19:10 +00:00
|
|
|
printk(KERN_INFO "Debug-level enabled\n");
|
2015-08-15 06:53:31 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t wilc_debug_region_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* only allow read from start */
|
|
|
|
if (*ppos > 0)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-16 14:04:54 +00:00
|
|
|
res = scnprintf(buf, sizeof(buf), "Debug region: %x\n", atomic_read(&WILC_REGION));
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
|
|
|
}
|
|
|
|
|
2016-01-04 20:33:50 +00:00
|
|
|
static ssize_t wilc_debug_region_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
char buffer[128] = {};
|
|
|
|
int flag;
|
|
|
|
|
2015-06-04 08:59:34 +00:00
|
|
|
if (count > sizeof(buffer))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-02-14 04:10:29 +00:00
|
|
|
if (copy_from_user(buffer, buf, count))
|
2015-05-11 05:30:56 +00:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
flag = buffer[0] - '0';
|
|
|
|
|
|
|
|
if (flag > DBG_REGION_ALL) {
|
2015-11-16 14:04:54 +00:00
|
|
|
printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_REGION));
|
2015-05-11 05:30:56 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:04:54 +00:00
|
|
|
atomic_set(&WILC_REGION, (int)flag);
|
|
|
|
printk("new debug-region is %x\n", atomic_read(&WILC_REGION));
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FOPS(_open, _read, _write, _poll) { \
|
|
|
|
.owner = THIS_MODULE, \
|
|
|
|
.open = (_open), \
|
|
|
|
.read = (_read), \
|
|
|
|
.write = (_write), \
|
|
|
|
.poll = (_poll), \
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wilc_debugfs_info_t {
|
|
|
|
const char *name;
|
|
|
|
int perm;
|
|
|
|
unsigned int data;
|
|
|
|
struct file_operations fops;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct wilc_debugfs_info_t debugfs_info[] = {
|
|
|
|
{ "wilc_debug_level", 0666, (DEBUG | ERR), FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL), },
|
2016-02-04 09:24:30 +00:00
|
|
|
{ "wilc_debug_region", 0666, (INIT_DBG | CFG80211_DBG), FOPS(NULL, wilc_debug_region_read, wilc_debug_region_write, NULL), },
|
2015-05-11 05:30:56 +00:00
|
|
|
};
|
|
|
|
|
2015-11-16 14:05:09 +00:00
|
|
|
static int __init wilc_debugfs_init(void)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct dentry *debugfs_files;
|
|
|
|
struct wilc_debugfs_info_t *info;
|
|
|
|
|
|
|
|
wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
|
|
|
|
if (wilc_dir == ERR_PTR(-ENODEV)) {
|
|
|
|
/* it's not error. the debugfs is just not being enabled. */
|
|
|
|
printk("ERR, kernel has built without debugfs support\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wilc_dir) {
|
|
|
|
printk("ERR, debugfs create dir\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
|
|
|
|
info = &debugfs_info[i];
|
|
|
|
debugfs_files = debugfs_create_file(info->name,
|
|
|
|
info->perm,
|
|
|
|
wilc_dir,
|
|
|
|
&info->data,
|
|
|
|
&info->fops);
|
|
|
|
|
|
|
|
if (!debugfs_files) {
|
|
|
|
printk("ERR fail to create the debugfs file, %s\n", info->name);
|
|
|
|
debugfs_remove_recursive(wilc_dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-16 14:05:09 +00:00
|
|
|
module_init(wilc_debugfs_init);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-16 14:05:09 +00:00
|
|
|
static void __exit wilc_debugfs_remove(void)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
debugfs_remove_recursive(wilc_dir);
|
|
|
|
}
|
2015-11-16 14:05:09 +00:00
|
|
|
module_exit(wilc_debugfs_remove);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|