debug.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*
  2. * mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers
  3. * DebugFS code
  4. *
  5. * Copyright (c) 2010, ST-Ericsson
  6. * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/debugfs.h>
  14. #include <linux/seq_file.h>
  15. #include "cw1200.h"
  16. #include "debug.h"
  17. #include "fwio.h"
  18. /* join_status */
  19. static const char * const cw1200_debug_join_status[] = {
  20. "passive",
  21. "monitor",
  22. "station (joining)",
  23. "station (not authenticated yet)",
  24. "station",
  25. "adhoc",
  26. "access point",
  27. };
  28. /* WSM_JOIN_PREAMBLE_... */
  29. static const char * const cw1200_debug_preamble[] = {
  30. "long",
  31. "short",
  32. "long on 1 and 2 Mbps",
  33. };
  34. static const char * const cw1200_debug_link_id[] = {
  35. "OFF",
  36. "REQ",
  37. "SOFT",
  38. "HARD",
  39. "RESET",
  40. "RESET_REMAP",
  41. };
  42. static const char *cw1200_debug_mode(int mode)
  43. {
  44. switch (mode) {
  45. case NL80211_IFTYPE_UNSPECIFIED:
  46. return "unspecified";
  47. case NL80211_IFTYPE_MONITOR:
  48. return "monitor";
  49. case NL80211_IFTYPE_STATION:
  50. return "station";
  51. case NL80211_IFTYPE_ADHOC:
  52. return "adhoc";
  53. case NL80211_IFTYPE_MESH_POINT:
  54. return "mesh point";
  55. case NL80211_IFTYPE_AP:
  56. return "access point";
  57. case NL80211_IFTYPE_P2P_CLIENT:
  58. return "p2p client";
  59. case NL80211_IFTYPE_P2P_GO:
  60. return "p2p go";
  61. default:
  62. return "unsupported";
  63. }
  64. }
  65. static void cw1200_queue_status_show(struct seq_file *seq,
  66. struct cw1200_queue *q)
  67. {
  68. int i;
  69. seq_printf(seq, "Queue %d:\n", q->queue_id);
  70. seq_printf(seq, " capacity: %zu\n", q->capacity);
  71. seq_printf(seq, " queued: %zu\n", q->num_queued);
  72. seq_printf(seq, " pending: %zu\n", q->num_pending);
  73. seq_printf(seq, " sent: %zu\n", q->num_sent);
  74. seq_printf(seq, " locked: %s\n", q->tx_locked_cnt ? "yes" : "no");
  75. seq_printf(seq, " overfull: %s\n", q->overfull ? "yes" : "no");
  76. seq_puts(seq, " link map: 0-> ");
  77. for (i = 0; i < q->stats->map_capacity; ++i)
  78. seq_printf(seq, "%.2d ", q->link_map_cache[i]);
  79. seq_printf(seq, "<-%zu\n", q->stats->map_capacity);
  80. }
  81. static void cw1200_debug_print_map(struct seq_file *seq,
  82. struct cw1200_common *priv,
  83. const char *label,
  84. u32 map)
  85. {
  86. int i;
  87. seq_printf(seq, "%s0-> ", label);
  88. for (i = 0; i < priv->tx_queue_stats.map_capacity; ++i)
  89. seq_printf(seq, "%s ", (map & BIT(i)) ? "**" : "..");
  90. seq_printf(seq, "<-%zu\n", priv->tx_queue_stats.map_capacity - 1);
  91. }
  92. static int cw1200_status_show(struct seq_file *seq, void *v)
  93. {
  94. int i;
  95. struct list_head *item;
  96. struct cw1200_common *priv = seq->private;
  97. struct cw1200_debug_priv *d = priv->debug;
  98. seq_puts(seq, "CW1200 Wireless LAN driver status\n");
  99. seq_printf(seq, "Hardware: %d.%d\n",
  100. priv->wsm_caps.hw_id,
  101. priv->wsm_caps.hw_subid);
  102. seq_printf(seq, "Firmware: %s %d.%d\n",
  103. cw1200_fw_types[priv->wsm_caps.fw_type],
  104. priv->wsm_caps.fw_ver,
  105. priv->wsm_caps.fw_build);
  106. seq_printf(seq, "FW API: %d\n",
  107. priv->wsm_caps.fw_api);
  108. seq_printf(seq, "FW caps: 0x%.4X\n",
  109. priv->wsm_caps.fw_cap);
  110. seq_printf(seq, "FW label: '%s'\n",
  111. priv->wsm_caps.fw_label);
  112. seq_printf(seq, "Mode: %s%s\n",
  113. cw1200_debug_mode(priv->mode),
  114. priv->listening ? " (listening)" : "");
  115. seq_printf(seq, "Join state: %s\n",
  116. cw1200_debug_join_status[priv->join_status]);
  117. if (priv->channel)
  118. seq_printf(seq, "Channel: %d%s\n",
  119. priv->channel->hw_value,
  120. priv->channel_switch_in_progress ?
  121. " (switching)" : "");
  122. if (priv->rx_filter.promiscuous)
  123. seq_puts(seq, "Filter: promisc\n");
  124. else if (priv->rx_filter.fcs)
  125. seq_puts(seq, "Filter: fcs\n");
  126. if (priv->rx_filter.bssid)
  127. seq_puts(seq, "Filter: bssid\n");
  128. if (!priv->disable_beacon_filter)
  129. seq_puts(seq, "Filter: beacons\n");
  130. if (priv->enable_beacon ||
  131. priv->mode == NL80211_IFTYPE_AP ||
  132. priv->mode == NL80211_IFTYPE_ADHOC ||
  133. priv->mode == NL80211_IFTYPE_MESH_POINT ||
  134. priv->mode == NL80211_IFTYPE_P2P_GO)
  135. seq_printf(seq, "Beaconing: %s\n",
  136. priv->enable_beacon ?
  137. "enabled" : "disabled");
  138. for (i = 0; i < 4; ++i)
  139. seq_printf(seq, "EDCA(%d): %d, %d, %d, %d, %d\n", i,
  140. priv->edca.params[i].cwmin,
  141. priv->edca.params[i].cwmax,
  142. priv->edca.params[i].aifns,
  143. priv->edca.params[i].txop_limit,
  144. priv->edca.params[i].max_rx_lifetime);
  145. if (priv->join_status == CW1200_JOIN_STATUS_STA) {
  146. static const char *pm_mode = "unknown";
  147. switch (priv->powersave_mode.mode) {
  148. case WSM_PSM_ACTIVE:
  149. pm_mode = "off";
  150. break;
  151. case WSM_PSM_PS:
  152. pm_mode = "on";
  153. break;
  154. case WSM_PSM_FAST_PS:
  155. pm_mode = "dynamic";
  156. break;
  157. }
  158. seq_printf(seq, "Preamble: %s\n",
  159. cw1200_debug_preamble[priv->association_mode.preamble]);
  160. seq_printf(seq, "AMPDU spcn: %d\n",
  161. priv->association_mode.mpdu_start_spacing);
  162. seq_printf(seq, "Basic rate: 0x%.8X\n",
  163. le32_to_cpu(priv->association_mode.basic_rate_set));
  164. seq_printf(seq, "Bss lost: %d beacons\n",
  165. priv->bss_params.beacon_lost_count);
  166. seq_printf(seq, "AID: %d\n",
  167. priv->bss_params.aid);
  168. seq_printf(seq, "Rates: 0x%.8X\n",
  169. priv->bss_params.operational_rate_set);
  170. seq_printf(seq, "Powersave: %s\n", pm_mode);
  171. }
  172. seq_printf(seq, "HT: %s\n",
  173. cw1200_is_ht(&priv->ht_info) ? "on" : "off");
  174. if (cw1200_is_ht(&priv->ht_info)) {
  175. seq_printf(seq, "Greenfield: %s\n",
  176. cw1200_ht_greenfield(&priv->ht_info) ? "yes" : "no");
  177. seq_printf(seq, "AMPDU dens: %d\n",
  178. cw1200_ht_ampdu_density(&priv->ht_info));
  179. }
  180. seq_printf(seq, "RSSI thold: %d\n",
  181. priv->cqm_rssi_thold);
  182. seq_printf(seq, "RSSI hyst: %d\n",
  183. priv->cqm_rssi_hyst);
  184. seq_printf(seq, "Long retr: %d\n",
  185. priv->long_frame_max_tx_count);
  186. seq_printf(seq, "Short retr: %d\n",
  187. priv->short_frame_max_tx_count);
  188. spin_lock_bh(&priv->tx_policy_cache.lock);
  189. i = 0;
  190. list_for_each(item, &priv->tx_policy_cache.used)
  191. ++i;
  192. spin_unlock_bh(&priv->tx_policy_cache.lock);
  193. seq_printf(seq, "RC in use: %d\n", i);
  194. seq_puts(seq, "\n");
  195. for (i = 0; i < 4; ++i) {
  196. cw1200_queue_status_show(seq, &priv->tx_queue[i]);
  197. seq_puts(seq, "\n");
  198. }
  199. cw1200_debug_print_map(seq, priv, "Link map: ",
  200. priv->link_id_map);
  201. cw1200_debug_print_map(seq, priv, "Asleep map: ",
  202. priv->sta_asleep_mask);
  203. cw1200_debug_print_map(seq, priv, "PSPOLL map: ",
  204. priv->pspoll_mask);
  205. seq_puts(seq, "\n");
  206. for (i = 0; i < CW1200_MAX_STA_IN_AP_MODE; ++i) {
  207. if (priv->link_id_db[i].status) {
  208. seq_printf(seq, "Link %d: %s, %pM\n",
  209. i + 1,
  210. cw1200_debug_link_id[priv->link_id_db[i].status],
  211. priv->link_id_db[i].mac);
  212. }
  213. }
  214. seq_puts(seq, "\n");
  215. seq_printf(seq, "BH status: %s\n",
  216. atomic_read(&priv->bh_term) ? "terminated" : "alive");
  217. seq_printf(seq, "Pending RX: %d\n",
  218. atomic_read(&priv->bh_rx));
  219. seq_printf(seq, "Pending TX: %d\n",
  220. atomic_read(&priv->bh_tx));
  221. if (priv->bh_error)
  222. seq_printf(seq, "BH errcode: %d\n",
  223. priv->bh_error);
  224. seq_printf(seq, "TX bufs: %d x %d bytes\n",
  225. priv->wsm_caps.input_buffers,
  226. priv->wsm_caps.input_buffer_size);
  227. seq_printf(seq, "Used bufs: %d\n",
  228. priv->hw_bufs_used);
  229. seq_printf(seq, "Powermgmt: %s\n",
  230. priv->powersave_enabled ? "on" : "off");
  231. seq_printf(seq, "Device: %s\n",
  232. priv->device_can_sleep ? "asleep" : "awake");
  233. spin_lock(&priv->wsm_cmd.lock);
  234. seq_printf(seq, "WSM status: %s\n",
  235. priv->wsm_cmd.done ? "idle" : "active");
  236. seq_printf(seq, "WSM cmd: 0x%.4X (%td bytes)\n",
  237. priv->wsm_cmd.cmd, priv->wsm_cmd.len);
  238. seq_printf(seq, "WSM retval: %d\n",
  239. priv->wsm_cmd.ret);
  240. spin_unlock(&priv->wsm_cmd.lock);
  241. seq_printf(seq, "Datapath: %s\n",
  242. atomic_read(&priv->tx_lock) ? "locked" : "unlocked");
  243. if (atomic_read(&priv->tx_lock))
  244. seq_printf(seq, "TXlock cnt: %d\n",
  245. atomic_read(&priv->tx_lock));
  246. seq_printf(seq, "TXed: %d\n",
  247. d->tx);
  248. seq_printf(seq, "AGG TXed: %d\n",
  249. d->tx_agg);
  250. seq_printf(seq, "MULTI TXed: %d (%d)\n",
  251. d->tx_multi, d->tx_multi_frames);
  252. seq_printf(seq, "RXed: %d\n",
  253. d->rx);
  254. seq_printf(seq, "AGG RXed: %d\n",
  255. d->rx_agg);
  256. seq_printf(seq, "TX miss: %d\n",
  257. d->tx_cache_miss);
  258. seq_printf(seq, "TX align: %d\n",
  259. d->tx_align);
  260. seq_printf(seq, "TX burst: %d\n",
  261. d->tx_burst);
  262. seq_printf(seq, "TX TTL: %d\n",
  263. d->tx_ttl);
  264. seq_printf(seq, "Scan: %s\n",
  265. atomic_read(&priv->scan.in_progress) ? "active" : "idle");
  266. return 0;
  267. }
  268. static int cw1200_status_open(struct inode *inode, struct file *file)
  269. {
  270. return single_open(file, &cw1200_status_show,
  271. inode->i_private);
  272. }
  273. static const struct file_operations fops_status = {
  274. .open = cw1200_status_open,
  275. .read = seq_read,
  276. .llseek = seq_lseek,
  277. .release = single_release,
  278. .owner = THIS_MODULE,
  279. };
  280. static int cw1200_counters_show(struct seq_file *seq, void *v)
  281. {
  282. int ret;
  283. struct cw1200_common *priv = seq->private;
  284. struct wsm_mib_counters_table counters;
  285. ret = wsm_get_counters_table(priv, &counters);
  286. if (ret)
  287. return ret;
  288. #define PUT_COUNTER(tab, name) \
  289. seq_printf(seq, "%s:" tab "%d\n", #name, \
  290. __le32_to_cpu(counters.name))
  291. PUT_COUNTER("\t\t", plcp_errors);
  292. PUT_COUNTER("\t\t", fcs_errors);
  293. PUT_COUNTER("\t\t", tx_packets);
  294. PUT_COUNTER("\t\t", rx_packets);
  295. PUT_COUNTER("\t\t", rx_packet_errors);
  296. PUT_COUNTER("\t", rx_decryption_failures);
  297. PUT_COUNTER("\t\t", rx_mic_failures);
  298. PUT_COUNTER("\t", rx_no_key_failures);
  299. PUT_COUNTER("\t", tx_multicast_frames);
  300. PUT_COUNTER("\t", tx_frames_success);
  301. PUT_COUNTER("\t", tx_frame_failures);
  302. PUT_COUNTER("\t", tx_frames_retried);
  303. PUT_COUNTER("\t", tx_frames_multi_retried);
  304. PUT_COUNTER("\t", rx_frame_duplicates);
  305. PUT_COUNTER("\t\t", rts_success);
  306. PUT_COUNTER("\t\t", rts_failures);
  307. PUT_COUNTER("\t\t", ack_failures);
  308. PUT_COUNTER("\t", rx_multicast_frames);
  309. PUT_COUNTER("\t", rx_frames_success);
  310. PUT_COUNTER("\t", rx_cmac_icv_errors);
  311. PUT_COUNTER("\t\t", rx_cmac_replays);
  312. PUT_COUNTER("\t", rx_mgmt_ccmp_replays);
  313. #undef PUT_COUNTER
  314. return 0;
  315. }
  316. static int cw1200_counters_open(struct inode *inode, struct file *file)
  317. {
  318. return single_open(file, &cw1200_counters_show,
  319. inode->i_private);
  320. }
  321. static const struct file_operations fops_counters = {
  322. .open = cw1200_counters_open,
  323. .read = seq_read,
  324. .llseek = seq_lseek,
  325. .release = single_release,
  326. .owner = THIS_MODULE,
  327. };
  328. static ssize_t cw1200_wsm_dumps(struct file *file,
  329. const char __user *user_buf, size_t count, loff_t *ppos)
  330. {
  331. struct cw1200_common *priv = file->private_data;
  332. char buf[1];
  333. if (!count)
  334. return -EINVAL;
  335. if (copy_from_user(buf, user_buf, 1))
  336. return -EFAULT;
  337. if (buf[0] == '1')
  338. priv->wsm_enable_wsm_dumps = 1;
  339. else
  340. priv->wsm_enable_wsm_dumps = 0;
  341. return count;
  342. }
  343. static const struct file_operations fops_wsm_dumps = {
  344. .open = simple_open,
  345. .write = cw1200_wsm_dumps,
  346. .llseek = default_llseek,
  347. };
  348. int cw1200_debug_init(struct cw1200_common *priv)
  349. {
  350. int ret = -ENOMEM;
  351. struct cw1200_debug_priv *d = kzalloc(sizeof(struct cw1200_debug_priv),
  352. GFP_KERNEL);
  353. priv->debug = d;
  354. if (!d)
  355. return ret;
  356. d->debugfs_phy = debugfs_create_dir("cw1200",
  357. priv->hw->wiphy->debugfsdir);
  358. if (!d->debugfs_phy)
  359. goto err;
  360. if (!debugfs_create_file("status", S_IRUSR, d->debugfs_phy,
  361. priv, &fops_status))
  362. goto err;
  363. if (!debugfs_create_file("counters", S_IRUSR, d->debugfs_phy,
  364. priv, &fops_counters))
  365. goto err;
  366. if (!debugfs_create_file("wsm_dumps", S_IWUSR, d->debugfs_phy,
  367. priv, &fops_wsm_dumps))
  368. goto err;
  369. return 0;
  370. err:
  371. priv->debug = NULL;
  372. debugfs_remove_recursive(d->debugfs_phy);
  373. kfree(d);
  374. return ret;
  375. }
  376. void cw1200_debug_release(struct cw1200_common *priv)
  377. {
  378. struct cw1200_debug_priv *d = priv->debug;
  379. if (d) {
  380. debugfs_remove_recursive(d->debugfs_phy);
  381. priv->debug = NULL;
  382. kfree(d);
  383. }
  384. }