rsi_91x_debugfs.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "rsi_debugfs.h"
  17. #include "rsi_sdio.h"
  18. /**
  19. * rsi_sdio_stats_read() - This function returns the sdio status of the driver.
  20. * @seq: Pointer to the sequence file structure.
  21. * @data: Pointer to the data.
  22. *
  23. * Return: 0 on success, -1 on failure.
  24. */
  25. static int rsi_sdio_stats_read(struct seq_file *seq, void *data)
  26. {
  27. struct rsi_common *common = seq->private;
  28. struct rsi_hw *adapter = common->priv;
  29. struct rsi_91x_sdiodev *dev =
  30. (struct rsi_91x_sdiodev *)adapter->rsi_dev;
  31. seq_printf(seq, "total_sdio_interrupts: %d\n",
  32. dev->rx_info.sdio_int_counter);
  33. seq_printf(seq, "sdio_msdu_pending_intr_count: %d\n",
  34. dev->rx_info.total_sdio_msdu_pending_intr);
  35. seq_printf(seq, "sdio_buff_full_count : %d\n",
  36. dev->rx_info.buf_full_counter);
  37. seq_printf(seq, "sdio_buf_semi_full_count %d\n",
  38. dev->rx_info.buf_semi_full_counter);
  39. seq_printf(seq, "sdio_unknown_intr_count: %d\n",
  40. dev->rx_info.total_sdio_unknown_intr);
  41. /* RX Path Stats */
  42. seq_printf(seq, "BUFFER FULL STATUS : %d\n",
  43. dev->rx_info.buffer_full);
  44. seq_printf(seq, "SEMI BUFFER FULL STATUS : %d\n",
  45. dev->rx_info.semi_buffer_full);
  46. seq_printf(seq, "MGMT BUFFER FULL STATUS : %d\n",
  47. dev->rx_info.mgmt_buffer_full);
  48. seq_printf(seq, "BUFFER FULL COUNTER : %d\n",
  49. dev->rx_info.buf_full_counter);
  50. seq_printf(seq, "BUFFER SEMI FULL COUNTER : %d\n",
  51. dev->rx_info.buf_semi_full_counter);
  52. seq_printf(seq, "MGMT BUFFER FULL COUNTER : %d\n",
  53. dev->rx_info.mgmt_buf_full_counter);
  54. return 0;
  55. }
  56. /**
  57. * rsi_sdio_stats_open() - This funtion calls single open function of seq_file
  58. * to open file and read contents from it.
  59. * @inode: Pointer to the inode structure.
  60. * @file: Pointer to the file structure.
  61. *
  62. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  63. */
  64. static int rsi_sdio_stats_open(struct inode *inode,
  65. struct file *file)
  66. {
  67. return single_open(file, rsi_sdio_stats_read, inode->i_private);
  68. }
  69. /**
  70. * rsi_version_read() - This function gives driver and firmware version number.
  71. * @seq: Pointer to the sequence file structure.
  72. * @data: Pointer to the data.
  73. *
  74. * Return: 0 on success, -1 on failure.
  75. */
  76. static int rsi_version_read(struct seq_file *seq, void *data)
  77. {
  78. struct rsi_common *common = seq->private;
  79. common->driver_ver.major = 0;
  80. common->driver_ver.minor = 1;
  81. common->driver_ver.release_num = 0;
  82. common->driver_ver.patch_num = 0;
  83. seq_printf(seq, "Driver : %x.%d.%d.%d\nLMAC : %d.%d.%d.%d\n",
  84. common->driver_ver.major,
  85. common->driver_ver.minor,
  86. common->driver_ver.release_num,
  87. common->driver_ver.patch_num,
  88. common->fw_ver.major,
  89. common->fw_ver.minor,
  90. common->fw_ver.release_num,
  91. common->fw_ver.patch_num);
  92. return 0;
  93. }
  94. /**
  95. * rsi_version_open() - This funtion calls single open function of seq_file to
  96. * open file and read contents from it.
  97. * @inode: Pointer to the inode structure.
  98. * @file: Pointer to the file structure.
  99. *
  100. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  101. */
  102. static int rsi_version_open(struct inode *inode,
  103. struct file *file)
  104. {
  105. return single_open(file, rsi_version_read, inode->i_private);
  106. }
  107. /**
  108. * rsi_stats_read() - This function return the status of the driver.
  109. * @seq: Pointer to the sequence file structure.
  110. * @data: Pointer to the data.
  111. *
  112. * Return: 0 on success, -1 on failure.
  113. */
  114. static int rsi_stats_read(struct seq_file *seq, void *data)
  115. {
  116. struct rsi_common *common = seq->private;
  117. unsigned char fsm_state[][32] = {
  118. "FSM_CARD_NOT_READY",
  119. "FSM_BOOT_PARAMS_SENT",
  120. "FSM_EEPROM_READ_MAC_ADDR",
  121. "FSM_RESET_MAC_SENT",
  122. "FSM_RADIO_CAPS_SENT",
  123. "FSM_BB_RF_PROG_SENT",
  124. "FSM_MAC_INIT_DONE"
  125. };
  126. seq_puts(seq, "==> RSI STA DRIVER STATUS <==\n");
  127. seq_puts(seq, "DRIVER_FSM_STATE: ");
  128. if (common->fsm_state <= FSM_MAC_INIT_DONE)
  129. seq_printf(seq, "%s", fsm_state[common->fsm_state]);
  130. seq_printf(seq, "(%d)\n\n", common->fsm_state);
  131. /* Mgmt TX Path Stats */
  132. seq_printf(seq, "total_mgmt_pkt_send : %d\n",
  133. common->tx_stats.total_tx_pkt_send[MGMT_SOFT_Q]);
  134. seq_printf(seq, "total_mgmt_pkt_queued : %d\n",
  135. skb_queue_len(&common->tx_queue[MGMT_SOFT_Q]));
  136. seq_printf(seq, "total_mgmt_pkt_freed : %d\n",
  137. common->tx_stats.total_tx_pkt_freed[MGMT_SOFT_Q]);
  138. /* Data TX Path Stats */
  139. seq_printf(seq, "total_data_vo_pkt_send: %8d\t",
  140. common->tx_stats.total_tx_pkt_send[VO_Q]);
  141. seq_printf(seq, "total_data_vo_pkt_queued: %8d\t",
  142. skb_queue_len(&common->tx_queue[VO_Q]));
  143. seq_printf(seq, "total_vo_pkt_freed: %8d\n",
  144. common->tx_stats.total_tx_pkt_freed[VO_Q]);
  145. seq_printf(seq, "total_data_vi_pkt_send: %8d\t",
  146. common->tx_stats.total_tx_pkt_send[VI_Q]);
  147. seq_printf(seq, "total_data_vi_pkt_queued: %8d\t",
  148. skb_queue_len(&common->tx_queue[VI_Q]));
  149. seq_printf(seq, "total_vi_pkt_freed: %8d\n",
  150. common->tx_stats.total_tx_pkt_freed[VI_Q]);
  151. seq_printf(seq, "total_data_be_pkt_send: %8d\t",
  152. common->tx_stats.total_tx_pkt_send[BE_Q]);
  153. seq_printf(seq, "total_data_be_pkt_queued: %8d\t",
  154. skb_queue_len(&common->tx_queue[BE_Q]));
  155. seq_printf(seq, "total_be_pkt_freed: %8d\n",
  156. common->tx_stats.total_tx_pkt_freed[BE_Q]);
  157. seq_printf(seq, "total_data_bk_pkt_send: %8d\t",
  158. common->tx_stats.total_tx_pkt_send[BK_Q]);
  159. seq_printf(seq, "total_data_bk_pkt_queued: %8d\t",
  160. skb_queue_len(&common->tx_queue[BK_Q]));
  161. seq_printf(seq, "total_bk_pkt_freed: %8d\n",
  162. common->tx_stats.total_tx_pkt_freed[BK_Q]);
  163. seq_puts(seq, "\n");
  164. return 0;
  165. }
  166. /**
  167. * rsi_stats_open() - This funtion calls single open function of seq_file to
  168. * open file and read contents from it.
  169. * @inode: Pointer to the inode structure.
  170. * @file: Pointer to the file structure.
  171. *
  172. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  173. */
  174. static int rsi_stats_open(struct inode *inode,
  175. struct file *file)
  176. {
  177. return single_open(file, rsi_stats_read, inode->i_private);
  178. }
  179. /**
  180. * rsi_debug_zone_read() - This function display the currently enabled debug zones.
  181. * @seq: Pointer to the sequence file structure.
  182. * @data: Pointer to the data.
  183. *
  184. * Return: 0 on success, -1 on failure.
  185. */
  186. static int rsi_debug_zone_read(struct seq_file *seq, void *data)
  187. {
  188. rsi_dbg(FSM_ZONE, "%x: rsi_enabled zone", rsi_zone_enabled);
  189. seq_printf(seq, "The zones available are %#x\n",
  190. rsi_zone_enabled);
  191. return 0;
  192. }
  193. /**
  194. * rsi_debug_read() - This funtion calls single open function of seq_file to
  195. * open file and read contents from it.
  196. * @inode: Pointer to the inode structure.
  197. * @file: Pointer to the file structure.
  198. *
  199. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  200. */
  201. static int rsi_debug_read(struct inode *inode,
  202. struct file *file)
  203. {
  204. return single_open(file, rsi_debug_zone_read, inode->i_private);
  205. }
  206. /**
  207. * rsi_debug_zone_write() - This function writes into hal queues as per user
  208. * requirement.
  209. * @filp: Pointer to the file structure.
  210. * @buff: Pointer to the character buffer.
  211. * @len: Length of the data to be written into buffer.
  212. * @data: Pointer to the data.
  213. *
  214. * Return: len: Number of bytes read.
  215. */
  216. static ssize_t rsi_debug_zone_write(struct file *filp,
  217. const char __user *buff,
  218. size_t len,
  219. loff_t *data)
  220. {
  221. unsigned long dbg_zone;
  222. int ret;
  223. if (!len)
  224. return 0;
  225. ret = kstrtoul_from_user(buff, len, 16, &dbg_zone);
  226. if (ret)
  227. return ret;
  228. rsi_zone_enabled = dbg_zone;
  229. return len;
  230. }
  231. #define FOPS(fopen) { \
  232. .owner = THIS_MODULE, \
  233. .open = (fopen), \
  234. .read = seq_read, \
  235. .llseek = seq_lseek, \
  236. }
  237. #define FOPS_RW(fopen, fwrite) { \
  238. .owner = THIS_MODULE, \
  239. .open = (fopen), \
  240. .read = seq_read, \
  241. .llseek = seq_lseek, \
  242. .write = (fwrite), \
  243. }
  244. static const struct rsi_dbg_files dev_debugfs_files[] = {
  245. {"version", 0644, FOPS(rsi_version_open),},
  246. {"stats", 0644, FOPS(rsi_stats_open),},
  247. {"debug_zone", 0666, FOPS_RW(rsi_debug_read, rsi_debug_zone_write),},
  248. {"sdio_stats", 0644, FOPS(rsi_sdio_stats_open),},
  249. };
  250. /**
  251. * rsi_init_dbgfs() - This function initializes the dbgfs entry.
  252. * @adapter: Pointer to the adapter structure.
  253. *
  254. * Return: 0 on success, -1 on failure.
  255. */
  256. int rsi_init_dbgfs(struct rsi_hw *adapter)
  257. {
  258. struct rsi_common *common = adapter->priv;
  259. struct rsi_debugfs *dev_dbgfs;
  260. char devdir[6];
  261. int ii;
  262. const struct rsi_dbg_files *files;
  263. dev_dbgfs = kzalloc(sizeof(*dev_dbgfs), GFP_KERNEL);
  264. if (!dev_dbgfs)
  265. return -ENOMEM;
  266. adapter->dfsentry = dev_dbgfs;
  267. snprintf(devdir, sizeof(devdir), "%s",
  268. wiphy_name(adapter->hw->wiphy));
  269. dev_dbgfs->subdir = debugfs_create_dir(devdir, NULL);
  270. if (!dev_dbgfs->subdir) {
  271. kfree(dev_dbgfs);
  272. return -ENOMEM;
  273. }
  274. for (ii = 0; ii < adapter->num_debugfs_entries; ii++) {
  275. files = &dev_debugfs_files[ii];
  276. dev_dbgfs->rsi_files[ii] =
  277. debugfs_create_file(files->name,
  278. files->perms,
  279. dev_dbgfs->subdir,
  280. common,
  281. &files->fops);
  282. }
  283. return 0;
  284. }
  285. EXPORT_SYMBOL_GPL(rsi_init_dbgfs);
  286. /**
  287. * rsi_remove_dbgfs() - Removes the previously created dbgfs file entries
  288. * in the reverse order of creation.
  289. * @adapter: Pointer to the adapter structure.
  290. *
  291. * Return: None.
  292. */
  293. void rsi_remove_dbgfs(struct rsi_hw *adapter)
  294. {
  295. struct rsi_debugfs *dev_dbgfs = adapter->dfsentry;
  296. if (!dev_dbgfs)
  297. return;
  298. debugfs_remove_recursive(dev_dbgfs->subdir);
  299. }
  300. EXPORT_SYMBOL_GPL(rsi_remove_dbgfs);