rsi_91x_debugfs.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 function 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. seq_printf(seq, "LMAC : %d.%d.%d.%d\n",
  80. common->lmac_ver.major,
  81. common->lmac_ver.minor,
  82. common->lmac_ver.release_num,
  83. common->lmac_ver.patch_num);
  84. return 0;
  85. }
  86. /**
  87. * rsi_version_open() - This function calls single open function of seq_file to
  88. * open file and read contents from it.
  89. * @inode: Pointer to the inode structure.
  90. * @file: Pointer to the file structure.
  91. *
  92. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  93. */
  94. static int rsi_version_open(struct inode *inode,
  95. struct file *file)
  96. {
  97. return single_open(file, rsi_version_read, inode->i_private);
  98. }
  99. /**
  100. * rsi_stats_read() - This function return the status of the driver.
  101. * @seq: Pointer to the sequence file structure.
  102. * @data: Pointer to the data.
  103. *
  104. * Return: 0 on success, -1 on failure.
  105. */
  106. static int rsi_stats_read(struct seq_file *seq, void *data)
  107. {
  108. struct rsi_common *common = seq->private;
  109. unsigned char fsm_state[][32] = {
  110. "FSM_FW_NOT_LOADED",
  111. "FSM_CARD_NOT_READY",
  112. "FSM_COMMON_DEV_PARAMS_SENT",
  113. "FSM_BOOT_PARAMS_SENT",
  114. "FSM_EEPROM_READ_MAC_ADDR",
  115. "FSM_EEPROM_READ_RF_TYPE",
  116. "FSM_RESET_MAC_SENT",
  117. "FSM_RADIO_CAPS_SENT",
  118. "FSM_BB_RF_PROG_SENT",
  119. "FSM_MAC_INIT_DONE"
  120. };
  121. seq_puts(seq, "==> RSI STA DRIVER STATUS <==\n");
  122. seq_puts(seq, "DRIVER_FSM_STATE: ");
  123. BUILD_BUG_ON(ARRAY_SIZE(fsm_state) != NUM_FSM_STATES);
  124. if (common->fsm_state <= FSM_MAC_INIT_DONE)
  125. seq_printf(seq, "%s", fsm_state[common->fsm_state]);
  126. seq_printf(seq, "(%d)\n\n", common->fsm_state);
  127. /* Mgmt TX Path Stats */
  128. seq_printf(seq, "total_mgmt_pkt_send : %d\n",
  129. common->tx_stats.total_tx_pkt_send[MGMT_SOFT_Q]);
  130. seq_printf(seq, "total_mgmt_pkt_queued : %d\n",
  131. skb_queue_len(&common->tx_queue[MGMT_SOFT_Q]));
  132. seq_printf(seq, "total_mgmt_pkt_freed : %d\n",
  133. common->tx_stats.total_tx_pkt_freed[MGMT_SOFT_Q]);
  134. /* Data TX Path Stats */
  135. seq_printf(seq, "total_data_vo_pkt_send: %8d\t",
  136. common->tx_stats.total_tx_pkt_send[VO_Q]);
  137. seq_printf(seq, "total_data_vo_pkt_queued: %8d\t",
  138. skb_queue_len(&common->tx_queue[VO_Q]));
  139. seq_printf(seq, "total_vo_pkt_freed: %8d\n",
  140. common->tx_stats.total_tx_pkt_freed[VO_Q]);
  141. seq_printf(seq, "total_data_vi_pkt_send: %8d\t",
  142. common->tx_stats.total_tx_pkt_send[VI_Q]);
  143. seq_printf(seq, "total_data_vi_pkt_queued: %8d\t",
  144. skb_queue_len(&common->tx_queue[VI_Q]));
  145. seq_printf(seq, "total_vi_pkt_freed: %8d\n",
  146. common->tx_stats.total_tx_pkt_freed[VI_Q]);
  147. seq_printf(seq, "total_data_be_pkt_send: %8d\t",
  148. common->tx_stats.total_tx_pkt_send[BE_Q]);
  149. seq_printf(seq, "total_data_be_pkt_queued: %8d\t",
  150. skb_queue_len(&common->tx_queue[BE_Q]));
  151. seq_printf(seq, "total_be_pkt_freed: %8d\n",
  152. common->tx_stats.total_tx_pkt_freed[BE_Q]);
  153. seq_printf(seq, "total_data_bk_pkt_send: %8d\t",
  154. common->tx_stats.total_tx_pkt_send[BK_Q]);
  155. seq_printf(seq, "total_data_bk_pkt_queued: %8d\t",
  156. skb_queue_len(&common->tx_queue[BK_Q]));
  157. seq_printf(seq, "total_bk_pkt_freed: %8d\n",
  158. common->tx_stats.total_tx_pkt_freed[BK_Q]);
  159. seq_puts(seq, "\n");
  160. return 0;
  161. }
  162. /**
  163. * rsi_stats_open() - This function calls single open function of seq_file to
  164. * open file and read contents from it.
  165. * @inode: Pointer to the inode structure.
  166. * @file: Pointer to the file structure.
  167. *
  168. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  169. */
  170. static int rsi_stats_open(struct inode *inode,
  171. struct file *file)
  172. {
  173. return single_open(file, rsi_stats_read, inode->i_private);
  174. }
  175. /**
  176. * rsi_debug_zone_read() - This function display the currently enabled debug zones.
  177. * @seq: Pointer to the sequence file structure.
  178. * @data: Pointer to the data.
  179. *
  180. * Return: 0 on success, -1 on failure.
  181. */
  182. static int rsi_debug_zone_read(struct seq_file *seq, void *data)
  183. {
  184. rsi_dbg(FSM_ZONE, "%x: rsi_enabled zone", rsi_zone_enabled);
  185. seq_printf(seq, "The zones available are %#x\n",
  186. rsi_zone_enabled);
  187. return 0;
  188. }
  189. /**
  190. * rsi_debug_read() - This function calls single open function of seq_file to
  191. * open file and read contents from it.
  192. * @inode: Pointer to the inode structure.
  193. * @file: Pointer to the file structure.
  194. *
  195. * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
  196. */
  197. static int rsi_debug_read(struct inode *inode,
  198. struct file *file)
  199. {
  200. return single_open(file, rsi_debug_zone_read, inode->i_private);
  201. }
  202. /**
  203. * rsi_debug_zone_write() - This function writes into hal queues as per user
  204. * requirement.
  205. * @filp: Pointer to the file structure.
  206. * @buff: Pointer to the character buffer.
  207. * @len: Length of the data to be written into buffer.
  208. * @data: Pointer to the data.
  209. *
  210. * Return: len: Number of bytes read.
  211. */
  212. static ssize_t rsi_debug_zone_write(struct file *filp,
  213. const char __user *buff,
  214. size_t len,
  215. loff_t *data)
  216. {
  217. unsigned long dbg_zone;
  218. int ret;
  219. if (!len)
  220. return 0;
  221. ret = kstrtoul_from_user(buff, len, 16, &dbg_zone);
  222. if (ret)
  223. return ret;
  224. rsi_zone_enabled = dbg_zone;
  225. return len;
  226. }
  227. #define FOPS(fopen) { \
  228. .owner = THIS_MODULE, \
  229. .open = (fopen), \
  230. .read = seq_read, \
  231. .llseek = seq_lseek, \
  232. }
  233. #define FOPS_RW(fopen, fwrite) { \
  234. .owner = THIS_MODULE, \
  235. .open = (fopen), \
  236. .read = seq_read, \
  237. .llseek = seq_lseek, \
  238. .write = (fwrite), \
  239. }
  240. static const struct rsi_dbg_files dev_debugfs_files[] = {
  241. {"version", 0644, FOPS(rsi_version_open),},
  242. {"stats", 0644, FOPS(rsi_stats_open),},
  243. {"debug_zone", 0666, FOPS_RW(rsi_debug_read, rsi_debug_zone_write),},
  244. {"sdio_stats", 0644, FOPS(rsi_sdio_stats_open),},
  245. };
  246. /**
  247. * rsi_init_dbgfs() - This function initializes the dbgfs entry.
  248. * @adapter: Pointer to the adapter structure.
  249. *
  250. * Return: 0 on success, -1 on failure.
  251. */
  252. int rsi_init_dbgfs(struct rsi_hw *adapter)
  253. {
  254. struct rsi_common *common = adapter->priv;
  255. struct rsi_debugfs *dev_dbgfs;
  256. char devdir[6];
  257. int ii;
  258. const struct rsi_dbg_files *files;
  259. dev_dbgfs = kzalloc(sizeof(*dev_dbgfs), GFP_KERNEL);
  260. if (!dev_dbgfs)
  261. return -ENOMEM;
  262. adapter->dfsentry = dev_dbgfs;
  263. snprintf(devdir, sizeof(devdir), "%s",
  264. wiphy_name(adapter->hw->wiphy));
  265. dev_dbgfs->subdir = debugfs_create_dir(devdir, NULL);
  266. for (ii = 0; ii < adapter->num_debugfs_entries; ii++) {
  267. files = &dev_debugfs_files[ii];
  268. dev_dbgfs->rsi_files[ii] =
  269. debugfs_create_file(files->name,
  270. files->perms,
  271. dev_dbgfs->subdir,
  272. common,
  273. &files->fops);
  274. }
  275. return 0;
  276. }
  277. EXPORT_SYMBOL_GPL(rsi_init_dbgfs);
  278. /**
  279. * rsi_remove_dbgfs() - Removes the previously created dbgfs file entries
  280. * in the reverse order of creation.
  281. * @adapter: Pointer to the adapter structure.
  282. *
  283. * Return: None.
  284. */
  285. void rsi_remove_dbgfs(struct rsi_hw *adapter)
  286. {
  287. struct rsi_debugfs *dev_dbgfs = adapter->dfsentry;
  288. if (!dev_dbgfs)
  289. return;
  290. debugfs_remove_recursive(dev_dbgfs->subdir);
  291. }
  292. EXPORT_SYMBOL_GPL(rsi_remove_dbgfs);