common-debug.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications 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 "common.h"
  17. static ssize_t read_file_modal_eeprom(struct file *file, char __user *user_buf,
  18. size_t count, loff_t *ppos)
  19. {
  20. struct ath_hw *ah = file->private_data;
  21. u32 len = 0, size = 6000;
  22. char *buf;
  23. size_t retval;
  24. buf = kzalloc(size, GFP_KERNEL);
  25. if (buf == NULL)
  26. return -ENOMEM;
  27. len = ah->eep_ops->dump_eeprom(ah, false, buf, len, size);
  28. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  29. kfree(buf);
  30. return retval;
  31. }
  32. static const struct file_operations fops_modal_eeprom = {
  33. .read = read_file_modal_eeprom,
  34. .open = simple_open,
  35. .owner = THIS_MODULE,
  36. .llseek = default_llseek,
  37. };
  38. void ath9k_cmn_debug_modal_eeprom(struct dentry *debugfs_phy,
  39. struct ath_hw *ah)
  40. {
  41. debugfs_create_file("modal_eeprom", S_IRUSR, debugfs_phy, ah,
  42. &fops_modal_eeprom);
  43. }
  44. EXPORT_SYMBOL(ath9k_cmn_debug_modal_eeprom);
  45. static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
  46. size_t count, loff_t *ppos)
  47. {
  48. struct ath_hw *ah = file->private_data;
  49. u32 len = 0, size = 1500;
  50. ssize_t retval = 0;
  51. char *buf;
  52. buf = kzalloc(size, GFP_KERNEL);
  53. if (!buf)
  54. return -ENOMEM;
  55. len = ah->eep_ops->dump_eeprom(ah, true, buf, len, size);
  56. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  57. kfree(buf);
  58. return retval;
  59. }
  60. static const struct file_operations fops_base_eeprom = {
  61. .read = read_file_base_eeprom,
  62. .open = simple_open,
  63. .owner = THIS_MODULE,
  64. .llseek = default_llseek,
  65. };
  66. void ath9k_cmn_debug_base_eeprom(struct dentry *debugfs_phy,
  67. struct ath_hw *ah)
  68. {
  69. debugfs_create_file("base_eeprom", S_IRUSR, debugfs_phy, ah,
  70. &fops_base_eeprom);
  71. }
  72. EXPORT_SYMBOL(ath9k_cmn_debug_base_eeprom);
  73. void ath9k_cmn_debug_stat_rx(struct ath_rx_stats *rxstats,
  74. struct ath_rx_status *rs)
  75. {
  76. #define RX_PHY_ERR_INC(c) rxstats->phy_err_stats[c]++
  77. #define RX_CMN_STAT_INC(c) (rxstats->c++)
  78. RX_CMN_STAT_INC(rx_pkts_all);
  79. rxstats->rx_bytes_all += rs->rs_datalen;
  80. if (rs->rs_status & ATH9K_RXERR_CRC)
  81. RX_CMN_STAT_INC(crc_err);
  82. if (rs->rs_status & ATH9K_RXERR_DECRYPT)
  83. RX_CMN_STAT_INC(decrypt_crc_err);
  84. if (rs->rs_status & ATH9K_RXERR_MIC)
  85. RX_CMN_STAT_INC(mic_err);
  86. if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
  87. RX_CMN_STAT_INC(pre_delim_crc_err);
  88. if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
  89. RX_CMN_STAT_INC(post_delim_crc_err);
  90. if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
  91. RX_CMN_STAT_INC(decrypt_busy_err);
  92. if (rs->rs_status & ATH9K_RXERR_PHY) {
  93. RX_CMN_STAT_INC(phy_err);
  94. if (rs->rs_phyerr < ATH9K_PHYERR_MAX)
  95. RX_PHY_ERR_INC(rs->rs_phyerr);
  96. }
  97. #undef RX_CMN_STAT_INC
  98. #undef RX_PHY_ERR_INC
  99. }
  100. EXPORT_SYMBOL(ath9k_cmn_debug_stat_rx);
  101. static ssize_t read_file_recv(struct file *file, char __user *user_buf,
  102. size_t count, loff_t *ppos)
  103. {
  104. #define RXS_ERR(s, e) \
  105. do { \
  106. len += scnprintf(buf + len, size - len, \
  107. "%18s : %10u\n", s, \
  108. rxstats->e); \
  109. } while (0)
  110. struct ath_rx_stats *rxstats = file->private_data;
  111. char *buf;
  112. unsigned int len = 0, size = 1600;
  113. ssize_t retval = 0;
  114. buf = kzalloc(size, GFP_KERNEL);
  115. if (buf == NULL)
  116. return -ENOMEM;
  117. RXS_ERR("PKTS-ALL", rx_pkts_all);
  118. RXS_ERR("BYTES-ALL", rx_bytes_all);
  119. RXS_ERR("BEACONS", rx_beacons);
  120. RXS_ERR("FRAGS", rx_frags);
  121. RXS_ERR("SPECTRAL", rx_spectral);
  122. RXS_ERR("CRC ERR", crc_err);
  123. RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
  124. RXS_ERR("PHY ERR", phy_err);
  125. RXS_ERR("MIC ERR", mic_err);
  126. RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
  127. RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
  128. RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
  129. RXS_ERR("LENGTH-ERR", rx_len_err);
  130. RXS_ERR("OOM-ERR", rx_oom_err);
  131. RXS_ERR("RATE-ERR", rx_rate_err);
  132. RXS_ERR("TOO-MANY-FRAGS", rx_too_many_frags_err);
  133. if (len > size)
  134. len = size;
  135. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  136. kfree(buf);
  137. return retval;
  138. #undef RXS_ERR
  139. }
  140. static const struct file_operations fops_recv = {
  141. .read = read_file_recv,
  142. .open = simple_open,
  143. .owner = THIS_MODULE,
  144. .llseek = default_llseek,
  145. };
  146. void ath9k_cmn_debug_recv(struct dentry *debugfs_phy,
  147. struct ath_rx_stats *rxstats)
  148. {
  149. debugfs_create_file("recv", S_IRUSR, debugfs_phy, rxstats,
  150. &fops_recv);
  151. }
  152. EXPORT_SYMBOL(ath9k_cmn_debug_recv);
  153. static ssize_t read_file_phy_err(struct file *file, char __user *user_buf,
  154. size_t count, loff_t *ppos)
  155. {
  156. #define PHY_ERR(s, p) \
  157. len += scnprintf(buf + len, size - len, "%22s : %10u\n", s, \
  158. rxstats->phy_err_stats[p]);
  159. struct ath_rx_stats *rxstats = file->private_data;
  160. char *buf;
  161. unsigned int len = 0, size = 1600;
  162. ssize_t retval = 0;
  163. buf = kzalloc(size, GFP_KERNEL);
  164. if (buf == NULL)
  165. return -ENOMEM;
  166. PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
  167. PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
  168. PHY_ERR("PARITY ERR", ATH9K_PHYERR_PARITY);
  169. PHY_ERR("RATE ERR", ATH9K_PHYERR_RATE);
  170. PHY_ERR("LENGTH ERR", ATH9K_PHYERR_LENGTH);
  171. PHY_ERR("RADAR ERR", ATH9K_PHYERR_RADAR);
  172. PHY_ERR("SERVICE ERR", ATH9K_PHYERR_SERVICE);
  173. PHY_ERR("TOR ERR", ATH9K_PHYERR_TOR);
  174. PHY_ERR("OFDM-TIMING ERR", ATH9K_PHYERR_OFDM_TIMING);
  175. PHY_ERR("OFDM-SIGNAL-PARITY ERR", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
  176. PHY_ERR("OFDM-RATE ERR", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
  177. PHY_ERR("OFDM-LENGTH ERR", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
  178. PHY_ERR("OFDM-POWER-DROP ERR", ATH9K_PHYERR_OFDM_POWER_DROP);
  179. PHY_ERR("OFDM-SERVICE ERR", ATH9K_PHYERR_OFDM_SERVICE);
  180. PHY_ERR("OFDM-RESTART ERR", ATH9K_PHYERR_OFDM_RESTART);
  181. PHY_ERR("CCK-BLOCKER ERR", ATH9K_PHYERR_CCK_BLOCKER);
  182. PHY_ERR("CCK-TIMING ERR", ATH9K_PHYERR_CCK_TIMING);
  183. PHY_ERR("CCK-HEADER-CRC ERR", ATH9K_PHYERR_CCK_HEADER_CRC);
  184. PHY_ERR("CCK-RATE ERR", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
  185. PHY_ERR("CCK-LENGTH ERR", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
  186. PHY_ERR("CCK-POWER-DROP ERR", ATH9K_PHYERR_CCK_POWER_DROP);
  187. PHY_ERR("CCK-SERVICE ERR", ATH9K_PHYERR_CCK_SERVICE);
  188. PHY_ERR("CCK-RESTART ERR", ATH9K_PHYERR_CCK_RESTART);
  189. PHY_ERR("HT-CRC ERR", ATH9K_PHYERR_HT_CRC_ERROR);
  190. PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
  191. PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
  192. PHY_ERR("HT-ZLF ERR", ATH9K_PHYERR_HT_ZLF);
  193. PHY_ERR("FALSE-RADAR-EXT ERR", ATH9K_PHYERR_FALSE_RADAR_EXT);
  194. PHY_ERR("GREEN-FIELD ERR", ATH9K_PHYERR_GREEN_FIELD);
  195. PHY_ERR("SPECTRAL ERR", ATH9K_PHYERR_SPECTRAL);
  196. if (len > size)
  197. len = size;
  198. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  199. kfree(buf);
  200. return retval;
  201. #undef PHY_ERR
  202. }
  203. static const struct file_operations fops_phy_err = {
  204. .read = read_file_phy_err,
  205. .open = simple_open,
  206. .owner = THIS_MODULE,
  207. .llseek = default_llseek,
  208. };
  209. void ath9k_cmn_debug_phy_err(struct dentry *debugfs_phy,
  210. struct ath_rx_stats *rxstats)
  211. {
  212. debugfs_create_file("phy_err", S_IRUSR, debugfs_phy, rxstats,
  213. &fops_phy_err);
  214. }
  215. EXPORT_SYMBOL(ath9k_cmn_debug_phy_err);