Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /* |
| 2 | * NewportMedia WiFi chipset driver test tools - wilc-debug |
| 3 | * Copyright (c) 2012 NewportMedia Inc. |
| 4 | * Author: SSW <sswd@wilcsemic.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #if defined(WILC_DEBUGFS) |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/poll.h> |
| 16 | #include <linux/sched.h> |
| 17 | |
| 18 | #include "wilc_wlan_if.h" |
| 19 | |
| 20 | |
| 21 | static struct dentry *wilc_dir; |
| 22 | |
| 23 | /* |
| 24 | * -------------------------------------------------------------------------------- |
| 25 | */ |
Chris Park | b331f15 | 2016-02-22 13:12:08 +0900 | [diff] [blame] | 26 | #define DEBUG BIT(0) |
| 27 | #define INFO BIT(1) |
| 28 | #define WRN BIT(2) |
| 29 | #define ERR BIT(3) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 30 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 31 | #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR) |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 32 | atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR); |
Arnd Bergmann | 750ffe9 | 2015-11-16 15:05:08 +0100 | [diff] [blame] | 33 | EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * -------------------------------------------------------------------------------- |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) |
| 41 | { |
| 42 | char buf[128]; |
| 43 | int res = 0; |
| 44 | |
| 45 | /* only allow read from start */ |
| 46 | if (*ppos > 0) |
| 47 | return 0; |
| 48 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 49 | res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&WILC_DEBUG_LEVEL)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 50 | |
| 51 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
| 52 | } |
| 53 | |
Chandra S Gorentla | 6e3f05b | 2015-08-15 12:23:31 +0530 | [diff] [blame] | 54 | static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf, |
| 55 | size_t count, loff_t *ppos) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 56 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 57 | int flag = 0; |
Chandra S Gorentla | 6e3f05b | 2015-08-15 12:23:31 +0530 | [diff] [blame] | 58 | int ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 59 | |
Chandra S Gorentla | 6e3f05b | 2015-08-15 12:23:31 +0530 | [diff] [blame] | 60 | ret = kstrtouint_from_user(buf, count, 16, &flag); |
| 61 | if (ret) |
| 62 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 63 | |
| 64 | if (flag > DBG_LEVEL_ALL) { |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 65 | printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_DEBUG_LEVEL)); |
Chandra S Gorentla | 6e3f05b | 2015-08-15 12:23:31 +0530 | [diff] [blame] | 66 | return -EINVAL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 67 | } |
| 68 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 69 | atomic_set(&WILC_DEBUG_LEVEL, (int)flag); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 70 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 71 | if (flag == 0) |
Janani Ravichandran | f7b7f87 | 2016-02-13 23:19:10 -0500 | [diff] [blame] | 72 | printk(KERN_INFO "Debug-level disabled\n"); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 73 | else |
Janani Ravichandran | f7b7f87 | 2016-02-13 23:19:10 -0500 | [diff] [blame] | 74 | printk(KERN_INFO "Debug-level enabled\n"); |
Chandra S Gorentla | 6e3f05b | 2015-08-15 12:23:31 +0530 | [diff] [blame] | 75 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 76 | return count; |
| 77 | } |
| 78 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 79 | /* |
| 80 | * -------------------------------------------------------------------------------- |
| 81 | */ |
| 82 | |
| 83 | #define FOPS(_open, _read, _write, _poll) { \ |
| 84 | .owner = THIS_MODULE, \ |
| 85 | .open = (_open), \ |
| 86 | .read = (_read), \ |
| 87 | .write = (_write), \ |
| 88 | .poll = (_poll), \ |
| 89 | } |
| 90 | |
| 91 | struct wilc_debugfs_info_t { |
| 92 | const char *name; |
| 93 | int perm; |
| 94 | unsigned int data; |
Eva Rachel Retuya | 8a7b2b1 | 2016-02-15 13:52:15 +0800 | [diff] [blame] | 95 | const struct file_operations fops; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static struct wilc_debugfs_info_t debugfs_info[] = { |
| 99 | { "wilc_debug_level", 0666, (DEBUG | ERR), FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL), }, |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 100 | }; |
| 101 | |
Arnd Bergmann | c94f05e | 2015-11-16 15:05:09 +0100 | [diff] [blame] | 102 | static int __init wilc_debugfs_init(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 103 | { |
| 104 | int i; |
| 105 | |
| 106 | struct dentry *debugfs_files; |
| 107 | struct wilc_debugfs_info_t *info; |
| 108 | |
| 109 | wilc_dir = debugfs_create_dir("wilc_wifi", NULL); |
| 110 | if (wilc_dir == ERR_PTR(-ENODEV)) { |
| 111 | /* it's not error. the debugfs is just not being enabled. */ |
| 112 | printk("ERR, kernel has built without debugfs support\n"); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | if (!wilc_dir) { |
| 117 | printk("ERR, debugfs create dir\n"); |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) { |
| 122 | info = &debugfs_info[i]; |
| 123 | debugfs_files = debugfs_create_file(info->name, |
| 124 | info->perm, |
| 125 | wilc_dir, |
| 126 | &info->data, |
| 127 | &info->fops); |
| 128 | |
| 129 | if (!debugfs_files) { |
| 130 | printk("ERR fail to create the debugfs file, %s\n", info->name); |
| 131 | debugfs_remove_recursive(wilc_dir); |
| 132 | return -1; |
| 133 | } |
| 134 | } |
| 135 | return 0; |
| 136 | } |
Arnd Bergmann | c94f05e | 2015-11-16 15:05:09 +0100 | [diff] [blame] | 137 | module_init(wilc_debugfs_init); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 138 | |
Arnd Bergmann | c94f05e | 2015-11-16 15:05:09 +0100 | [diff] [blame] | 139 | static void __exit wilc_debugfs_remove(void) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 140 | { |
| 141 | debugfs_remove_recursive(wilc_dir); |
| 142 | } |
Arnd Bergmann | c94f05e | 2015-11-16 15:05:09 +0100 | [diff] [blame] | 143 | module_exit(wilc_debugfs_remove); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 144 | |
| 145 | #endif |
| 146 | |