debugfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include "debugfs.h"
  24. #include <linux/skbuff.h>
  25. #include <linux/slab.h>
  26. #include "wl12xx.h"
  27. #include "acx.h"
  28. #include "ps.h"
  29. #include "io.h"
  30. /* ms */
  31. #define WL1271_DEBUGFS_STATS_LIFETIME 1000
  32. /* debugfs macros idea from mac80211 */
  33. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  34. static int wl1271_format_buffer(char __user *userbuf, size_t count,
  35. loff_t *ppos, char *fmt, ...)
  36. {
  37. va_list args;
  38. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  39. int res;
  40. va_start(args, fmt);
  41. res = vscnprintf(buf, sizeof(buf), fmt, args);
  42. va_end(args);
  43. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  44. }
  45. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  46. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  47. size_t count, loff_t *ppos) \
  48. { \
  49. struct wl1271 *wl = file->private_data; \
  50. return wl1271_format_buffer(userbuf, count, ppos, \
  51. fmt "\n", ##value); \
  52. } \
  53. \
  54. static const struct file_operations name## _ops = { \
  55. .read = name## _read, \
  56. .open = wl1271_open_file_generic, \
  57. .llseek = generic_file_llseek, \
  58. };
  59. #define DEBUGFS_ADD(name, parent) \
  60. entry = debugfs_create_file(#name, 0400, parent, \
  61. wl, &name## _ops); \
  62. if (!entry || IS_ERR(entry)) \
  63. goto err; \
  64. #define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
  65. static ssize_t sub## _ ##name## _read(struct file *file, \
  66. char __user *userbuf, \
  67. size_t count, loff_t *ppos) \
  68. { \
  69. struct wl1271 *wl = file->private_data; \
  70. \
  71. wl1271_debugfs_update_stats(wl); \
  72. \
  73. return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
  74. wl->stats.fw_stats->sub.name); \
  75. } \
  76. \
  77. static const struct file_operations sub## _ ##name## _ops = { \
  78. .read = sub## _ ##name## _read, \
  79. .open = wl1271_open_file_generic, \
  80. .llseek = generic_file_llseek, \
  81. };
  82. #define DEBUGFS_FWSTATS_ADD(sub, name) \
  83. DEBUGFS_ADD(sub## _ ##name, stats)
  84. static void wl1271_debugfs_update_stats(struct wl1271 *wl)
  85. {
  86. int ret;
  87. mutex_lock(&wl->mutex);
  88. ret = wl1271_ps_elp_wakeup(wl);
  89. if (ret < 0)
  90. goto out;
  91. if (wl->state == WL1271_STATE_ON &&
  92. time_after(jiffies, wl->stats.fw_stats_update +
  93. msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
  94. wl1271_acx_statistics(wl, wl->stats.fw_stats);
  95. wl->stats.fw_stats_update = jiffies;
  96. }
  97. wl1271_ps_elp_sleep(wl);
  98. out:
  99. mutex_unlock(&wl->mutex);
  100. }
  101. static int wl1271_open_file_generic(struct inode *inode, struct file *file)
  102. {
  103. file->private_data = inode->i_private;
  104. return 0;
  105. }
  106. DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
  107. DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
  108. DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
  109. DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
  110. DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
  111. DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
  112. DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
  113. DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
  114. DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
  115. DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
  116. DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
  117. DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
  118. DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
  119. DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
  120. DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
  121. DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
  122. DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
  123. DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
  124. DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
  125. DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
  126. DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
  127. DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
  128. DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
  129. DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
  130. DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
  131. DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
  132. DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
  133. DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
  134. DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
  135. DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
  136. DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
  137. DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
  138. DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
  139. /* skipping wep.reserved */
  140. DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
  141. DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
  142. DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
  143. DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
  144. DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
  145. DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
  146. DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
  147. DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
  148. DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
  149. DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
  150. DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
  151. DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
  152. DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
  153. DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
  154. DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
  155. DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
  156. /* skipping cont_miss_bcns_spread for now */
  157. DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
  158. DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
  159. DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
  160. DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
  161. DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
  162. DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
  163. DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
  164. DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
  165. DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
  166. DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
  167. DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
  168. DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
  169. DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
  170. DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
  171. DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
  172. DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
  173. DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
  174. DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
  175. DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
  176. DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
  177. DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
  178. DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
  179. DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
  180. DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
  181. DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
  182. DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
  183. DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
  184. DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
  185. DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
  186. DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
  187. DEBUGFS_READONLY_FILE(excessive_retries, "%u",
  188. wl->stats.excessive_retries);
  189. static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
  190. size_t count, loff_t *ppos)
  191. {
  192. struct wl1271 *wl = file->private_data;
  193. u32 queue_len;
  194. char buf[20];
  195. int res;
  196. queue_len = wl->tx_queue_count;
  197. res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
  198. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  199. }
  200. static const struct file_operations tx_queue_len_ops = {
  201. .read = tx_queue_len_read,
  202. .open = wl1271_open_file_generic,
  203. .llseek = default_llseek,
  204. };
  205. static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
  206. size_t count, loff_t *ppos)
  207. {
  208. struct wl1271 *wl = file->private_data;
  209. bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  210. int res;
  211. char buf[10];
  212. res = scnprintf(buf, sizeof(buf), "%d\n", state);
  213. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  214. }
  215. static ssize_t gpio_power_write(struct file *file,
  216. const char __user *user_buf,
  217. size_t count, loff_t *ppos)
  218. {
  219. struct wl1271 *wl = file->private_data;
  220. char buf[10];
  221. size_t len;
  222. unsigned long value;
  223. int ret;
  224. len = min(count, sizeof(buf) - 1);
  225. if (copy_from_user(buf, user_buf, len)) {
  226. return -EFAULT;
  227. }
  228. buf[len] = '\0';
  229. ret = kstrtoul(buf, 0, &value);
  230. if (ret < 0) {
  231. wl1271_warning("illegal value in gpio_power");
  232. return -EINVAL;
  233. }
  234. mutex_lock(&wl->mutex);
  235. if (value)
  236. wl1271_power_on(wl);
  237. else
  238. wl1271_power_off(wl);
  239. mutex_unlock(&wl->mutex);
  240. return count;
  241. }
  242. static const struct file_operations gpio_power_ops = {
  243. .read = gpio_power_read,
  244. .write = gpio_power_write,
  245. .open = wl1271_open_file_generic,
  246. .llseek = default_llseek,
  247. };
  248. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  249. size_t count, loff_t *ppos)
  250. {
  251. struct wl1271 *wl = file->private_data;
  252. u8 value;
  253. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  254. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  255. value = wl->conf.conn.listen_interval;
  256. else
  257. value = 0;
  258. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  259. }
  260. static ssize_t dtim_interval_write(struct file *file,
  261. const char __user *user_buf,
  262. size_t count, loff_t *ppos)
  263. {
  264. struct wl1271 *wl = file->private_data;
  265. char buf[10];
  266. size_t len;
  267. unsigned long value;
  268. int ret;
  269. len = min(count, sizeof(buf) - 1);
  270. if (copy_from_user(buf, user_buf, len))
  271. return -EFAULT;
  272. buf[len] = '\0';
  273. ret = strict_strtoul(buf, 0, &value);
  274. if (ret < 0) {
  275. wl1271_warning("illegal value for dtim_interval");
  276. return -EINVAL;
  277. }
  278. if (value < 1 || value > 10) {
  279. wl1271_warning("dtim value is not in valid range");
  280. return -ERANGE;
  281. }
  282. mutex_lock(&wl->mutex);
  283. wl->conf.conn.listen_interval = value;
  284. /* for some reason there are different event types for 1 and >1 */
  285. if (value == 1)
  286. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  287. else
  288. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  289. /*
  290. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  291. * take effect on the next time we enter psm.
  292. */
  293. mutex_unlock(&wl->mutex);
  294. return count;
  295. }
  296. static const struct file_operations dtim_interval_ops = {
  297. .read = dtim_interval_read,
  298. .write = dtim_interval_write,
  299. .open = wl1271_open_file_generic,
  300. .llseek = default_llseek,
  301. };
  302. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  303. size_t count, loff_t *ppos)
  304. {
  305. struct wl1271 *wl = file->private_data;
  306. u8 value;
  307. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  308. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  309. value = wl->conf.conn.listen_interval;
  310. else
  311. value = 0;
  312. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  313. }
  314. static ssize_t beacon_interval_write(struct file *file,
  315. const char __user *user_buf,
  316. size_t count, loff_t *ppos)
  317. {
  318. struct wl1271 *wl = file->private_data;
  319. char buf[10];
  320. size_t len;
  321. unsigned long value;
  322. int ret;
  323. len = min(count, sizeof(buf) - 1);
  324. if (copy_from_user(buf, user_buf, len))
  325. return -EFAULT;
  326. buf[len] = '\0';
  327. ret = strict_strtoul(buf, 0, &value);
  328. if (ret < 0) {
  329. wl1271_warning("illegal value for beacon_interval");
  330. return -EINVAL;
  331. }
  332. if (value < 1 || value > 255) {
  333. wl1271_warning("beacon interval value is not in valid range");
  334. return -ERANGE;
  335. }
  336. mutex_lock(&wl->mutex);
  337. wl->conf.conn.listen_interval = value;
  338. /* for some reason there are different event types for 1 and >1 */
  339. if (value == 1)
  340. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  341. else
  342. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  343. /*
  344. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  345. * take effect on the next time we enter psm.
  346. */
  347. mutex_unlock(&wl->mutex);
  348. return count;
  349. }
  350. static const struct file_operations beacon_interval_ops = {
  351. .read = beacon_interval_read,
  352. .write = beacon_interval_write,
  353. .open = wl1271_open_file_generic,
  354. .llseek = default_llseek,
  355. };
  356. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  357. struct dentry *rootdir)
  358. {
  359. int ret = 0;
  360. struct dentry *entry, *stats;
  361. stats = debugfs_create_dir("fw-statistics", rootdir);
  362. if (!stats || IS_ERR(stats)) {
  363. entry = stats;
  364. goto err;
  365. }
  366. DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
  367. DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
  368. DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
  369. DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
  370. DEBUGFS_FWSTATS_ADD(rx, dropped);
  371. DEBUGFS_FWSTATS_ADD(rx, fcs_err);
  372. DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
  373. DEBUGFS_FWSTATS_ADD(rx, path_reset);
  374. DEBUGFS_FWSTATS_ADD(rx, reset_counter);
  375. DEBUGFS_FWSTATS_ADD(dma, rx_requested);
  376. DEBUGFS_FWSTATS_ADD(dma, rx_errors);
  377. DEBUGFS_FWSTATS_ADD(dma, tx_requested);
  378. DEBUGFS_FWSTATS_ADD(dma, tx_errors);
  379. DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
  380. DEBUGFS_FWSTATS_ADD(isr, fiqs);
  381. DEBUGFS_FWSTATS_ADD(isr, rx_headers);
  382. DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
  383. DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
  384. DEBUGFS_FWSTATS_ADD(isr, irqs);
  385. DEBUGFS_FWSTATS_ADD(isr, tx_procs);
  386. DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
  387. DEBUGFS_FWSTATS_ADD(isr, dma0_done);
  388. DEBUGFS_FWSTATS_ADD(isr, dma1_done);
  389. DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
  390. DEBUGFS_FWSTATS_ADD(isr, commands);
  391. DEBUGFS_FWSTATS_ADD(isr, rx_procs);
  392. DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
  393. DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
  394. DEBUGFS_FWSTATS_ADD(isr, pci_pm);
  395. DEBUGFS_FWSTATS_ADD(isr, wakeups);
  396. DEBUGFS_FWSTATS_ADD(isr, low_rssi);
  397. DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
  398. DEBUGFS_FWSTATS_ADD(wep, default_key_count);
  399. /* skipping wep.reserved */
  400. DEBUGFS_FWSTATS_ADD(wep, key_not_found);
  401. DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
  402. DEBUGFS_FWSTATS_ADD(wep, packets);
  403. DEBUGFS_FWSTATS_ADD(wep, interrupt);
  404. DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
  405. DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
  406. DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
  407. DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
  408. DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
  409. DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
  410. DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
  411. DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
  412. DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
  413. DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
  414. DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
  415. DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
  416. /* skipping cont_miss_bcns_spread for now */
  417. DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
  418. DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
  419. DEBUGFS_FWSTATS_ADD(mic, calc_failure);
  420. DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
  421. DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
  422. DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
  423. DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
  424. DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
  425. DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
  426. DEBUGFS_FWSTATS_ADD(event, heart_beat);
  427. DEBUGFS_FWSTATS_ADD(event, calibration);
  428. DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
  429. DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
  430. DEBUGFS_FWSTATS_ADD(event, rx_pool);
  431. DEBUGFS_FWSTATS_ADD(event, oom_late);
  432. DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
  433. DEBUGFS_FWSTATS_ADD(event, tx_stuck);
  434. DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
  435. DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
  436. DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
  437. DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
  438. DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
  439. DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
  440. DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
  441. DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
  442. DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
  443. DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
  444. DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
  445. DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
  446. DEBUGFS_ADD(tx_queue_len, rootdir);
  447. DEBUGFS_ADD(retry_count, rootdir);
  448. DEBUGFS_ADD(excessive_retries, rootdir);
  449. DEBUGFS_ADD(gpio_power, rootdir);
  450. DEBUGFS_ADD(dtim_interval, rootdir);
  451. DEBUGFS_ADD(beacon_interval, rootdir);
  452. return 0;
  453. err:
  454. if (IS_ERR(entry))
  455. ret = PTR_ERR(entry);
  456. else
  457. ret = -ENOMEM;
  458. return ret;
  459. }
  460. void wl1271_debugfs_reset(struct wl1271 *wl)
  461. {
  462. if (!wl->stats.fw_stats)
  463. return;
  464. memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
  465. wl->stats.retry_count = 0;
  466. wl->stats.excessive_retries = 0;
  467. }
  468. int wl1271_debugfs_init(struct wl1271 *wl)
  469. {
  470. int ret;
  471. struct dentry *rootdir;
  472. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  473. wl->hw->wiphy->debugfsdir);
  474. if (IS_ERR(rootdir)) {
  475. ret = PTR_ERR(rootdir);
  476. goto err;
  477. }
  478. wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
  479. GFP_KERNEL);
  480. if (!wl->stats.fw_stats) {
  481. ret = -ENOMEM;
  482. goto err_fw;
  483. }
  484. wl->stats.fw_stats_update = jiffies;
  485. ret = wl1271_debugfs_add_files(wl, rootdir);
  486. if (ret < 0)
  487. goto err_file;
  488. return 0;
  489. err_file:
  490. kfree(wl->stats.fw_stats);
  491. wl->stats.fw_stats = NULL;
  492. err_fw:
  493. debugfs_remove_recursive(rootdir);
  494. err:
  495. return ret;
  496. }
  497. void wl1271_debugfs_exit(struct wl1271 *wl)
  498. {
  499. kfree(wl->stats.fw_stats);
  500. wl->stats.fw_stats = NULL;
  501. }