Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Marvell Bluetooth driver: debugfs related functions |
| 3 | * |
| 4 | * Copyright (C) 2009, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * |
| 15 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 18 | * this warranty disclaimer. |
| 19 | **/ |
| 20 | |
| 21 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 23 | |
| 24 | #include <net/bluetooth/bluetooth.h> |
| 25 | #include <net/bluetooth/hci_core.h> |
| 26 | |
| 27 | #include "btmrvl_drv.h" |
| 28 | |
| 29 | struct btmrvl_debugfs_data { |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 30 | struct dentry *config_dir; |
| 31 | struct dentry *status_dir; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 34 | static ssize_t btmrvl_hscfgcmd_write(struct file *file, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 35 | const char __user *ubuf, size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 36 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 37 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 38 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 39 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 40 | |
| 41 | memset(buf, 0, sizeof(buf)); |
| 42 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 43 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 44 | return -EFAULT; |
| 45 | |
Jingoo Han | 473c131 | 2013-07-19 16:09:38 +0900 | [diff] [blame] | 46 | ret = kstrtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 47 | if (ret) |
| 48 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 49 | |
| 50 | priv->btmrvl_dev.hscfgcmd = result; |
| 51 | |
| 52 | if (priv->btmrvl_dev.hscfgcmd) { |
| 53 | btmrvl_prepare_command(priv); |
| 54 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 55 | } |
| 56 | |
| 57 | return count; |
| 58 | } |
| 59 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 60 | static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf, |
| 61 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 62 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 63 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 64 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 65 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 66 | |
| 67 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 68 | priv->btmrvl_dev.hscfgcmd); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 69 | |
| 70 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 71 | } |
| 72 | |
| 73 | static const struct file_operations btmrvl_hscfgcmd_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 74 | .read = btmrvl_hscfgcmd_read, |
| 75 | .write = btmrvl_hscfgcmd_write, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 76 | .open = simple_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 77 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 80 | static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 81 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 82 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 83 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 84 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 85 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 86 | |
| 87 | memset(buf, 0, sizeof(buf)); |
| 88 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 89 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 90 | return -EFAULT; |
| 91 | |
Jingoo Han | 473c131 | 2013-07-19 16:09:38 +0900 | [diff] [blame] | 92 | ret = kstrtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 93 | if (ret) |
| 94 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 95 | |
| 96 | priv->btmrvl_dev.pscmd = result; |
| 97 | |
| 98 | if (priv->btmrvl_dev.pscmd) { |
| 99 | btmrvl_prepare_command(priv); |
| 100 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 101 | } |
| 102 | |
| 103 | return count; |
| 104 | |
| 105 | } |
| 106 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 107 | static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf, |
| 108 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 109 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 110 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 111 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 112 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 113 | |
| 114 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd); |
| 115 | |
| 116 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 117 | } |
| 118 | |
| 119 | static const struct file_operations btmrvl_pscmd_fops = { |
| 120 | .read = btmrvl_pscmd_read, |
| 121 | .write = btmrvl_pscmd_write, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 122 | .open = simple_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 123 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 126 | static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 127 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 128 | { |
Joe Perches | be60b94 | 2010-07-12 13:49:57 -0700 | [diff] [blame] | 129 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 130 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 131 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 132 | |
| 133 | memset(buf, 0, sizeof(buf)); |
| 134 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 135 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 136 | return -EFAULT; |
| 137 | |
Jingoo Han | 473c131 | 2013-07-19 16:09:38 +0900 | [diff] [blame] | 138 | ret = kstrtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 139 | if (ret) |
| 140 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 141 | |
| 142 | priv->btmrvl_dev.hscmd = result; |
| 143 | if (priv->btmrvl_dev.hscmd) { |
| 144 | btmrvl_prepare_command(priv); |
| 145 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 146 | } |
| 147 | |
| 148 | return count; |
| 149 | } |
| 150 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 151 | static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf, |
| 152 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 153 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 154 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 155 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 156 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 157 | |
| 158 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd); |
| 159 | |
| 160 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 161 | } |
| 162 | |
| 163 | static const struct file_operations btmrvl_hscmd_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 164 | .read = btmrvl_hscmd_read, |
| 165 | .write = btmrvl_hscmd_write, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 166 | .open = simple_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 167 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame^] | 170 | static ssize_t btmrvl_fwdump_write(struct file *file, const char __user *ubuf, |
| 171 | size_t count, loff_t *ppos) |
| 172 | { |
| 173 | struct btmrvl_private *priv = file->private_data; |
| 174 | char buf[16]; |
| 175 | bool result; |
| 176 | |
| 177 | memset(buf, 0, sizeof(buf)); |
| 178 | |
| 179 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 180 | return -EFAULT; |
| 181 | |
| 182 | if (strtobool(buf, &result)) |
| 183 | return -EINVAL; |
| 184 | |
| 185 | if (!result) |
| 186 | return -EINVAL; |
| 187 | |
| 188 | btmrvl_firmware_dump(priv); |
| 189 | |
| 190 | return count; |
| 191 | } |
| 192 | |
| 193 | static const struct file_operations btmrvl_fwdump_fops = { |
| 194 | .write = btmrvl_fwdump_write, |
| 195 | .open = simple_open, |
| 196 | .llseek = default_llseek, |
| 197 | }; |
| 198 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 199 | void btmrvl_debugfs_init(struct hci_dev *hdev) |
| 200 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 201 | struct btmrvl_private *priv = hci_get_drvdata(hdev); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 202 | struct btmrvl_debugfs_data *dbg; |
| 203 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 204 | if (!hdev->debugfs) |
| 205 | return; |
| 206 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 207 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 208 | priv->debugfs_data = dbg; |
| 209 | |
| 210 | if (!dbg) { |
| 211 | BT_ERR("Can not allocate memory for btmrvl_debugfs_data."); |
| 212 | return; |
| 213 | } |
| 214 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 215 | dbg->config_dir = debugfs_create_dir("config", hdev->debugfs); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 216 | |
Andy Shevchenko | 9da226c | 2013-04-23 12:53:46 +0300 | [diff] [blame] | 217 | debugfs_create_u8("psmode", 0644, dbg->config_dir, |
| 218 | &priv->btmrvl_dev.psmode); |
| 219 | debugfs_create_file("pscmd", 0644, dbg->config_dir, |
| 220 | priv, &btmrvl_pscmd_fops); |
| 221 | debugfs_create_x16("gpiogap", 0644, dbg->config_dir, |
| 222 | &priv->btmrvl_dev.gpio_gap); |
| 223 | debugfs_create_u8("hsmode", 0644, dbg->config_dir, |
| 224 | &priv->btmrvl_dev.hsmode); |
| 225 | debugfs_create_file("hscmd", 0644, dbg->config_dir, |
| 226 | priv, &btmrvl_hscmd_fops); |
| 227 | debugfs_create_file("hscfgcmd", 0644, dbg->config_dir, |
| 228 | priv, &btmrvl_hscfgcmd_fops); |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame^] | 229 | debugfs_create_file("fw_dump", 0200, dbg->config_dir, |
| 230 | priv, &btmrvl_fwdump_fops); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 231 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 232 | dbg->status_dir = debugfs_create_dir("status", hdev->debugfs); |
Andy Shevchenko | 9da226c | 2013-04-23 12:53:46 +0300 | [diff] [blame] | 233 | debugfs_create_u8("curpsmode", 0444, dbg->status_dir, |
| 234 | &priv->adapter->psmode); |
| 235 | debugfs_create_u8("psstate", 0444, dbg->status_dir, |
| 236 | &priv->adapter->ps_state); |
| 237 | debugfs_create_u8("hsstate", 0444, dbg->status_dir, |
| 238 | &priv->adapter->hs_state); |
| 239 | debugfs_create_u8("txdnldready", 0444, dbg->status_dir, |
| 240 | &priv->btmrvl_dev.tx_dnld_rdy); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void btmrvl_debugfs_remove(struct hci_dev *hdev) |
| 244 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 245 | struct btmrvl_private *priv = hci_get_drvdata(hdev); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 246 | struct btmrvl_debugfs_data *dbg = priv->debugfs_data; |
| 247 | |
| 248 | if (!dbg) |
| 249 | return; |
| 250 | |
Andy Shevchenko | 9da226c | 2013-04-23 12:53:46 +0300 | [diff] [blame] | 251 | debugfs_remove_recursive(dbg->config_dir); |
| 252 | debugfs_remove_recursive(dbg->status_dir); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 253 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 254 | kfree(dbg); |
| 255 | } |