rsi_91x_debugfs.c 10 KB

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