^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Marvell Bluetooth driver: debugfs related functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2009, Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This software file (the "File") is distributed by Marvell International
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Ltd. under the terms of the GNU General Public License Version 2, June 1991
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (the "License"). You may use, redistribute and/or modify this File in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * accordance with the terms and conditions of the License, a copy of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * is available by writing to the Free Software Foundation, Inc.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * this warranty disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "btmrvl_drv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct btmrvl_debugfs_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct dentry *config_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct dentry *status_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static ssize_t btmrvl_hscfgcmd_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const char __user *ubuf, size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) long result, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ret = kstrtol_from_user(ubuf, count, 10, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) priv->btmrvl_dev.hscfgcmd = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (priv->btmrvl_dev.hscfgcmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) btmrvl_prepare_command(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) wake_up_interruptible(&priv->main_thread.wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) priv->btmrvl_dev.hscfgcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static const struct file_operations btmrvl_hscfgcmd_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .read = btmrvl_hscfgcmd_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .write = btmrvl_hscfgcmd_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) long result, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = kstrtol_from_user(ubuf, count, 10, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) priv->btmrvl_dev.pscmd = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (priv->btmrvl_dev.pscmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) btmrvl_prepare_command(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) wake_up_interruptible(&priv->main_thread.wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static const struct file_operations btmrvl_pscmd_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .read = btmrvl_pscmd_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .write = btmrvl_pscmd_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) long result, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = kstrtol_from_user(ubuf, count, 10, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) priv->btmrvl_dev.hscmd = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (priv->btmrvl_dev.hscmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) btmrvl_prepare_command(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) wake_up_interruptible(&priv->main_thread.wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct btmrvl_private *priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static const struct file_operations btmrvl_hscmd_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .read = btmrvl_hscmd_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .write = btmrvl_hscmd_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void btmrvl_debugfs_init(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct btmrvl_private *priv = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct btmrvl_debugfs_data *dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!hdev->debugfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) priv->debugfs_data = dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!dbg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) debugfs_create_u8("psmode", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) &priv->btmrvl_dev.psmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) debugfs_create_file("pscmd", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) priv, &btmrvl_pscmd_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) &priv->btmrvl_dev.gpio_gap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) debugfs_create_u8("hsmode", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) &priv->btmrvl_dev.hsmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) debugfs_create_file("hscmd", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) priv, &btmrvl_hscmd_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) priv, &btmrvl_hscfgcmd_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) &priv->adapter->psmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) debugfs_create_u8("psstate", 0444, dbg->status_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) &priv->adapter->ps_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) debugfs_create_u8("hsstate", 0444, dbg->status_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) &priv->adapter->hs_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) &priv->btmrvl_dev.tx_dnld_rdy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void btmrvl_debugfs_remove(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct btmrvl_private *priv = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!dbg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) debugfs_remove_recursive(dbg->config_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) debugfs_remove_recursive(dbg->status_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) kfree(dbg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }