debug.c 12 KB

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