btmrvl_debugfs.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #include <linux/debugfs.h>
  21. #include <linux/slab.h>
  22. #include <net/bluetooth/bluetooth.h>
  23. #include <net/bluetooth/hci_core.h>
  24. #include "btmrvl_drv.h"
  25. struct btmrvl_debugfs_data {
  26. struct dentry *config_dir;
  27. struct dentry *status_dir;
  28. };
  29. static ssize_t btmrvl_hscfgcmd_write(struct file *file,
  30. const char __user *ubuf, size_t count, loff_t *ppos)
  31. {
  32. struct btmrvl_private *priv = file->private_data;
  33. char buf[16];
  34. long result, ret;
  35. memset(buf, 0, sizeof(buf));
  36. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  37. return -EFAULT;
  38. ret = kstrtol(buf, 10, &result);
  39. if (ret)
  40. return ret;
  41. priv->btmrvl_dev.hscfgcmd = result;
  42. if (priv->btmrvl_dev.hscfgcmd) {
  43. btmrvl_prepare_command(priv);
  44. wake_up_interruptible(&priv->main_thread.wait_q);
  45. }
  46. return count;
  47. }
  48. static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
  49. size_t count, loff_t *ppos)
  50. {
  51. struct btmrvl_private *priv = file->private_data;
  52. char buf[16];
  53. int ret;
  54. ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
  55. priv->btmrvl_dev.hscfgcmd);
  56. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  57. }
  58. static const struct file_operations btmrvl_hscfgcmd_fops = {
  59. .read = btmrvl_hscfgcmd_read,
  60. .write = btmrvl_hscfgcmd_write,
  61. .open = simple_open,
  62. .llseek = default_llseek,
  63. };
  64. static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
  65. size_t count, loff_t *ppos)
  66. {
  67. struct btmrvl_private *priv = file->private_data;
  68. char buf[16];
  69. long result, ret;
  70. memset(buf, 0, sizeof(buf));
  71. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  72. return -EFAULT;
  73. ret = kstrtol(buf, 10, &result);
  74. if (ret)
  75. return ret;
  76. priv->btmrvl_dev.pscmd = result;
  77. if (priv->btmrvl_dev.pscmd) {
  78. btmrvl_prepare_command(priv);
  79. wake_up_interruptible(&priv->main_thread.wait_q);
  80. }
  81. return count;
  82. }
  83. static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
  84. size_t count, loff_t *ppos)
  85. {
  86. struct btmrvl_private *priv = file->private_data;
  87. char buf[16];
  88. int ret;
  89. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
  90. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  91. }
  92. static const struct file_operations btmrvl_pscmd_fops = {
  93. .read = btmrvl_pscmd_read,
  94. .write = btmrvl_pscmd_write,
  95. .open = simple_open,
  96. .llseek = default_llseek,
  97. };
  98. static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
  99. size_t count, loff_t *ppos)
  100. {
  101. struct btmrvl_private *priv = file->private_data;
  102. char buf[16];
  103. long result, ret;
  104. memset(buf, 0, sizeof(buf));
  105. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  106. return -EFAULT;
  107. ret = kstrtol(buf, 10, &result);
  108. if (ret)
  109. return ret;
  110. priv->btmrvl_dev.hscmd = result;
  111. if (priv->btmrvl_dev.hscmd) {
  112. btmrvl_prepare_command(priv);
  113. wake_up_interruptible(&priv->main_thread.wait_q);
  114. }
  115. return count;
  116. }
  117. static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
  118. size_t count, loff_t *ppos)
  119. {
  120. struct btmrvl_private *priv = file->private_data;
  121. char buf[16];
  122. int ret;
  123. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
  124. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  125. }
  126. static const struct file_operations btmrvl_hscmd_fops = {
  127. .read = btmrvl_hscmd_read,
  128. .write = btmrvl_hscmd_write,
  129. .open = simple_open,
  130. .llseek = default_llseek,
  131. };
  132. static ssize_t btmrvl_fwdump_write(struct file *file, const char __user *ubuf,
  133. size_t count, loff_t *ppos)
  134. {
  135. struct btmrvl_private *priv = file->private_data;
  136. char buf[16];
  137. bool result;
  138. memset(buf, 0, sizeof(buf));
  139. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  140. return -EFAULT;
  141. if (strtobool(buf, &result))
  142. return -EINVAL;
  143. if (!result)
  144. return -EINVAL;
  145. btmrvl_firmware_dump(priv);
  146. return count;
  147. }
  148. static const struct file_operations btmrvl_fwdump_fops = {
  149. .write = btmrvl_fwdump_write,
  150. .open = simple_open,
  151. .llseek = default_llseek,
  152. };
  153. void btmrvl_debugfs_init(struct hci_dev *hdev)
  154. {
  155. struct btmrvl_private *priv = hci_get_drvdata(hdev);
  156. struct btmrvl_debugfs_data *dbg;
  157. if (!hdev->debugfs)
  158. return;
  159. dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
  160. priv->debugfs_data = dbg;
  161. if (!dbg) {
  162. BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
  163. return;
  164. }
  165. dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
  166. debugfs_create_u8("psmode", 0644, dbg->config_dir,
  167. &priv->btmrvl_dev.psmode);
  168. debugfs_create_file("pscmd", 0644, dbg->config_dir,
  169. priv, &btmrvl_pscmd_fops);
  170. debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
  171. &priv->btmrvl_dev.gpio_gap);
  172. debugfs_create_u8("hsmode", 0644, dbg->config_dir,
  173. &priv->btmrvl_dev.hsmode);
  174. debugfs_create_file("hscmd", 0644, dbg->config_dir,
  175. priv, &btmrvl_hscmd_fops);
  176. debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
  177. priv, &btmrvl_hscfgcmd_fops);
  178. debugfs_create_file("fw_dump", 0200, dbg->config_dir,
  179. priv, &btmrvl_fwdump_fops);
  180. dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
  181. debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
  182. &priv->adapter->psmode);
  183. debugfs_create_u8("psstate", 0444, dbg->status_dir,
  184. &priv->adapter->ps_state);
  185. debugfs_create_u8("hsstate", 0444, dbg->status_dir,
  186. &priv->adapter->hs_state);
  187. debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
  188. &priv->btmrvl_dev.tx_dnld_rdy);
  189. }
  190. void btmrvl_debugfs_remove(struct hci_dev *hdev)
  191. {
  192. struct btmrvl_private *priv = hci_get_drvdata(hdev);
  193. struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
  194. if (!dbg)
  195. return;
  196. debugfs_remove_recursive(dbg->config_dir);
  197. debugfs_remove_recursive(dbg->status_dir);
  198. kfree(dbg);
  199. }