debugfs.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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 "wlcore.h"
  27. #include "debug.h"
  28. #include "acx.h"
  29. #include "ps.h"
  30. #include "io.h"
  31. #include "tx.h"
  32. /* ms */
  33. #define WL1271_DEBUGFS_STATS_LIFETIME 1000
  34. /* debugfs macros idea from mac80211 */
  35. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  36. static int wl1271_format_buffer(char __user *userbuf, size_t count,
  37. loff_t *ppos, char *fmt, ...)
  38. {
  39. va_list args;
  40. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  41. int res;
  42. va_start(args, fmt);
  43. res = vscnprintf(buf, sizeof(buf), fmt, args);
  44. va_end(args);
  45. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  46. }
  47. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  48. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  49. size_t count, loff_t *ppos) \
  50. { \
  51. struct wl1271 *wl = file->private_data; \
  52. return wl1271_format_buffer(userbuf, count, ppos, \
  53. fmt "\n", ##value); \
  54. } \
  55. \
  56. static const struct file_operations name## _ops = { \
  57. .read = name## _read, \
  58. .open = wl1271_open_file_generic, \
  59. .llseek = generic_file_llseek, \
  60. };
  61. #define DEBUGFS_ADD(name, parent) \
  62. entry = debugfs_create_file(#name, 0400, parent, \
  63. wl, &name## _ops); \
  64. if (!entry || IS_ERR(entry)) \
  65. goto err; \
  66. #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
  67. do { \
  68. entry = debugfs_create_file(#name, 0400, parent, \
  69. wl, &prefix## _## name## _ops); \
  70. if (!entry || IS_ERR(entry)) \
  71. goto err; \
  72. } while (0);
  73. #define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
  74. static ssize_t sub## _ ##name## _read(struct file *file, \
  75. char __user *userbuf, \
  76. size_t count, loff_t *ppos) \
  77. { \
  78. struct wl1271 *wl = file->private_data; \
  79. \
  80. wl1271_debugfs_update_stats(wl); \
  81. \
  82. return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
  83. wl->stats.fw_stats->sub.name); \
  84. } \
  85. \
  86. static const struct file_operations sub## _ ##name## _ops = { \
  87. .read = sub## _ ##name## _read, \
  88. .open = wl1271_open_file_generic, \
  89. .llseek = generic_file_llseek, \
  90. };
  91. #define DEBUGFS_FWSTATS_ADD(sub, name) \
  92. DEBUGFS_ADD(sub## _ ##name, stats)
  93. static void wl1271_debugfs_update_stats(struct wl1271 *wl)
  94. {
  95. int ret;
  96. mutex_lock(&wl->mutex);
  97. ret = wl1271_ps_elp_wakeup(wl);
  98. if (ret < 0)
  99. goto out;
  100. if (wl->state == WL1271_STATE_ON && !wl->plt &&
  101. time_after(jiffies, wl->stats.fw_stats_update +
  102. msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
  103. wl1271_acx_statistics(wl, wl->stats.fw_stats);
  104. wl->stats.fw_stats_update = jiffies;
  105. }
  106. wl1271_ps_elp_sleep(wl);
  107. out:
  108. mutex_unlock(&wl->mutex);
  109. }
  110. static int wl1271_open_file_generic(struct inode *inode, struct file *file)
  111. {
  112. file->private_data = inode->i_private;
  113. return 0;
  114. }
  115. DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
  116. DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
  117. DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
  118. DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
  119. DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
  120. DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
  121. DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
  122. DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
  123. DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
  124. DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
  125. DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
  126. DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
  127. DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
  128. DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
  129. DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
  130. DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
  131. DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
  132. DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
  133. DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
  134. DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
  135. DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
  136. DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
  137. DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
  138. DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
  139. DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
  140. DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
  141. DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
  142. DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
  143. DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
  144. DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
  145. DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
  146. DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
  147. DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
  148. /* skipping wep.reserved */
  149. DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
  150. DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
  151. DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
  152. DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
  153. DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
  154. DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
  155. DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
  156. DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
  157. DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
  158. DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
  159. DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
  160. DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
  161. DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
  162. DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
  163. DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
  164. DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
  165. /* skipping cont_miss_bcns_spread for now */
  166. DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
  167. DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
  168. DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
  169. DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
  170. DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
  171. DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
  172. DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
  173. DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
  174. DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
  175. DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
  176. DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
  177. DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
  178. DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
  179. DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
  180. DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
  181. DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
  182. DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
  183. DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
  184. DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
  185. DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
  186. DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
  187. DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
  188. DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
  189. DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
  190. DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
  191. DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
  192. DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
  193. DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
  194. DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
  195. DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
  196. DEBUGFS_READONLY_FILE(excessive_retries, "%u",
  197. wl->stats.excessive_retries);
  198. static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
  199. size_t count, loff_t *ppos)
  200. {
  201. struct wl1271 *wl = file->private_data;
  202. u32 queue_len;
  203. char buf[20];
  204. int res;
  205. queue_len = wl1271_tx_total_queue_count(wl);
  206. res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
  207. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  208. }
  209. static const struct file_operations tx_queue_len_ops = {
  210. .read = tx_queue_len_read,
  211. .open = wl1271_open_file_generic,
  212. .llseek = default_llseek,
  213. };
  214. static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
  215. size_t count, loff_t *ppos)
  216. {
  217. struct wl1271 *wl = file->private_data;
  218. bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  219. int res;
  220. char buf[10];
  221. res = scnprintf(buf, sizeof(buf), "%d\n", state);
  222. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  223. }
  224. static ssize_t gpio_power_write(struct file *file,
  225. const char __user *user_buf,
  226. size_t count, loff_t *ppos)
  227. {
  228. struct wl1271 *wl = file->private_data;
  229. unsigned long value;
  230. int ret;
  231. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  232. if (ret < 0) {
  233. wl1271_warning("illegal value in gpio_power");
  234. return -EINVAL;
  235. }
  236. mutex_lock(&wl->mutex);
  237. if (value)
  238. wl1271_power_on(wl);
  239. else
  240. wl1271_power_off(wl);
  241. mutex_unlock(&wl->mutex);
  242. return count;
  243. }
  244. static const struct file_operations gpio_power_ops = {
  245. .read = gpio_power_read,
  246. .write = gpio_power_write,
  247. .open = wl1271_open_file_generic,
  248. .llseek = default_llseek,
  249. };
  250. static ssize_t start_recovery_write(struct file *file,
  251. const char __user *user_buf,
  252. size_t count, loff_t *ppos)
  253. {
  254. struct wl1271 *wl = file->private_data;
  255. mutex_lock(&wl->mutex);
  256. wl12xx_queue_recovery_work(wl);
  257. mutex_unlock(&wl->mutex);
  258. return count;
  259. }
  260. static const struct file_operations start_recovery_ops = {
  261. .write = start_recovery_write,
  262. .open = wl1271_open_file_generic,
  263. .llseek = default_llseek,
  264. };
  265. static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
  266. size_t count, loff_t *ppos)
  267. {
  268. struct wl1271 *wl = file->private_data;
  269. return wl1271_format_buffer(user_buf, count,
  270. ppos, "%d\n",
  271. wl->conf.conn.dynamic_ps_timeout);
  272. }
  273. static ssize_t dynamic_ps_timeout_write(struct file *file,
  274. const char __user *user_buf,
  275. size_t count, loff_t *ppos)
  276. {
  277. struct wl1271 *wl = file->private_data;
  278. struct wl12xx_vif *wlvif;
  279. unsigned long value;
  280. int ret;
  281. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  282. if (ret < 0) {
  283. wl1271_warning("illegal value in dynamic_ps");
  284. return -EINVAL;
  285. }
  286. if (value < 1 || value > 65535) {
  287. wl1271_warning("dyanmic_ps_timeout is not in valid range");
  288. return -ERANGE;
  289. }
  290. mutex_lock(&wl->mutex);
  291. wl->conf.conn.dynamic_ps_timeout = value;
  292. if (wl->state == WL1271_STATE_OFF)
  293. goto out;
  294. ret = wl1271_ps_elp_wakeup(wl);
  295. if (ret < 0)
  296. goto out;
  297. /* In case we're already in PSM, trigger it again to set new timeout
  298. * immediately without waiting for re-association
  299. */
  300. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  301. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  302. wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
  303. }
  304. wl1271_ps_elp_sleep(wl);
  305. out:
  306. mutex_unlock(&wl->mutex);
  307. return count;
  308. }
  309. static const struct file_operations dynamic_ps_timeout_ops = {
  310. .read = dynamic_ps_timeout_read,
  311. .write = dynamic_ps_timeout_write,
  312. .open = wl1271_open_file_generic,
  313. .llseek = default_llseek,
  314. };
  315. static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
  316. size_t count, loff_t *ppos)
  317. {
  318. struct wl1271 *wl = file->private_data;
  319. return wl1271_format_buffer(user_buf, count,
  320. ppos, "%d\n",
  321. wl->conf.conn.forced_ps);
  322. }
  323. static ssize_t forced_ps_write(struct file *file,
  324. const char __user *user_buf,
  325. size_t count, loff_t *ppos)
  326. {
  327. struct wl1271 *wl = file->private_data;
  328. struct wl12xx_vif *wlvif;
  329. unsigned long value;
  330. int ret, ps_mode;
  331. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  332. if (ret < 0) {
  333. wl1271_warning("illegal value in forced_ps");
  334. return -EINVAL;
  335. }
  336. if (value != 1 && value != 0) {
  337. wl1271_warning("forced_ps should be either 0 or 1");
  338. return -ERANGE;
  339. }
  340. mutex_lock(&wl->mutex);
  341. if (wl->conf.conn.forced_ps == value)
  342. goto out;
  343. wl->conf.conn.forced_ps = value;
  344. if (wl->state == WL1271_STATE_OFF)
  345. goto out;
  346. ret = wl1271_ps_elp_wakeup(wl);
  347. if (ret < 0)
  348. goto out;
  349. /* In case we're already in PSM, trigger it again to switch mode
  350. * immediately without waiting for re-association
  351. */
  352. ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
  353. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  354. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  355. wl1271_ps_set_mode(wl, wlvif, ps_mode);
  356. }
  357. wl1271_ps_elp_sleep(wl);
  358. out:
  359. mutex_unlock(&wl->mutex);
  360. return count;
  361. }
  362. static const struct file_operations forced_ps_ops = {
  363. .read = forced_ps_read,
  364. .write = forced_ps_write,
  365. .open = wl1271_open_file_generic,
  366. .llseek = default_llseek,
  367. };
  368. static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
  369. size_t count, loff_t *ppos)
  370. {
  371. struct wl1271 *wl = file->private_data;
  372. return wl1271_format_buffer(user_buf, count,
  373. ppos, "%d\n",
  374. wl->conf.scan.split_scan_timeout / 1000);
  375. }
  376. static ssize_t split_scan_timeout_write(struct file *file,
  377. const char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct wl1271 *wl = file->private_data;
  381. unsigned long value;
  382. int ret;
  383. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  384. if (ret < 0) {
  385. wl1271_warning("illegal value in split_scan_timeout");
  386. return -EINVAL;
  387. }
  388. if (value == 0)
  389. wl1271_info("split scan will be disabled");
  390. mutex_lock(&wl->mutex);
  391. wl->conf.scan.split_scan_timeout = value * 1000;
  392. mutex_unlock(&wl->mutex);
  393. return count;
  394. }
  395. static const struct file_operations split_scan_timeout_ops = {
  396. .read = split_scan_timeout_read,
  397. .write = split_scan_timeout_write,
  398. .open = wl1271_open_file_generic,
  399. .llseek = default_llseek,
  400. };
  401. static ssize_t driver_state_read(struct file *file, char __user *user_buf,
  402. size_t count, loff_t *ppos)
  403. {
  404. struct wl1271 *wl = file->private_data;
  405. int res = 0;
  406. ssize_t ret;
  407. char *buf;
  408. #define DRIVER_STATE_BUF_LEN 1024
  409. buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
  410. if (!buf)
  411. return -ENOMEM;
  412. mutex_lock(&wl->mutex);
  413. #define DRIVER_STATE_PRINT(x, fmt) \
  414. (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
  415. #x " = " fmt "\n", wl->x))
  416. #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
  417. #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
  418. #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
  419. #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
  420. #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
  421. DRIVER_STATE_PRINT_INT(tx_blocks_available);
  422. DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
  423. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
  424. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
  425. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
  426. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
  427. DRIVER_STATE_PRINT_INT(tx_frames_cnt);
  428. DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
  429. DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
  430. DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
  431. DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
  432. DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
  433. DRIVER_STATE_PRINT_INT(tx_packets_count);
  434. DRIVER_STATE_PRINT_INT(tx_results_count);
  435. DRIVER_STATE_PRINT_LHEX(flags);
  436. DRIVER_STATE_PRINT_INT(tx_blocks_freed);
  437. DRIVER_STATE_PRINT_INT(rx_counter);
  438. DRIVER_STATE_PRINT_INT(state);
  439. DRIVER_STATE_PRINT_INT(channel);
  440. DRIVER_STATE_PRINT_INT(band);
  441. DRIVER_STATE_PRINT_INT(power_level);
  442. DRIVER_STATE_PRINT_INT(sg_enabled);
  443. DRIVER_STATE_PRINT_INT(enable_11a);
  444. DRIVER_STATE_PRINT_INT(noise);
  445. DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
  446. DRIVER_STATE_PRINT_LHEX(ap_ps_map);
  447. DRIVER_STATE_PRINT_HEX(quirks);
  448. DRIVER_STATE_PRINT_HEX(irq);
  449. DRIVER_STATE_PRINT_HEX(ref_clock);
  450. DRIVER_STATE_PRINT_HEX(tcxo_clock);
  451. DRIVER_STATE_PRINT_HEX(hw_pg_ver);
  452. DRIVER_STATE_PRINT_HEX(platform_quirks);
  453. DRIVER_STATE_PRINT_HEX(chip.id);
  454. DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
  455. DRIVER_STATE_PRINT_INT(sched_scanning);
  456. #undef DRIVER_STATE_PRINT_INT
  457. #undef DRIVER_STATE_PRINT_LONG
  458. #undef DRIVER_STATE_PRINT_HEX
  459. #undef DRIVER_STATE_PRINT_LHEX
  460. #undef DRIVER_STATE_PRINT_STR
  461. #undef DRIVER_STATE_PRINT
  462. #undef DRIVER_STATE_BUF_LEN
  463. mutex_unlock(&wl->mutex);
  464. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  465. kfree(buf);
  466. return ret;
  467. }
  468. static const struct file_operations driver_state_ops = {
  469. .read = driver_state_read,
  470. .open = wl1271_open_file_generic,
  471. .llseek = default_llseek,
  472. };
  473. static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
  474. size_t count, loff_t *ppos)
  475. {
  476. struct wl1271 *wl = file->private_data;
  477. struct wl12xx_vif *wlvif;
  478. int ret, res = 0;
  479. const int buf_size = 4096;
  480. char *buf;
  481. char tmp_buf[64];
  482. buf = kzalloc(buf_size, GFP_KERNEL);
  483. if (!buf)
  484. return -ENOMEM;
  485. mutex_lock(&wl->mutex);
  486. #define VIF_STATE_PRINT(x, fmt) \
  487. (res += scnprintf(buf + res, buf_size - res, \
  488. #x " = " fmt "\n", wlvif->x))
  489. #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
  490. #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
  491. #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
  492. #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
  493. #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
  494. #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
  495. #define VIF_STATE_PRINT_NSTR(x, len) \
  496. do { \
  497. memset(tmp_buf, 0, sizeof(tmp_buf)); \
  498. memcpy(tmp_buf, wlvif->x, \
  499. min_t(u8, len, sizeof(tmp_buf) - 1)); \
  500. res += scnprintf(buf + res, buf_size - res, \
  501. #x " = %s\n", tmp_buf); \
  502. } while (0)
  503. wl12xx_for_each_wlvif(wl, wlvif) {
  504. VIF_STATE_PRINT_INT(role_id);
  505. VIF_STATE_PRINT_INT(bss_type);
  506. VIF_STATE_PRINT_LHEX(flags);
  507. VIF_STATE_PRINT_INT(p2p);
  508. VIF_STATE_PRINT_INT(dev_role_id);
  509. VIF_STATE_PRINT_INT(dev_hlid);
  510. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  511. wlvif->bss_type == BSS_TYPE_IBSS) {
  512. VIF_STATE_PRINT_INT(sta.hlid);
  513. VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
  514. VIF_STATE_PRINT_INT(sta.basic_rate_idx);
  515. VIF_STATE_PRINT_INT(sta.ap_rate_idx);
  516. VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
  517. VIF_STATE_PRINT_INT(sta.qos);
  518. } else {
  519. VIF_STATE_PRINT_INT(ap.global_hlid);
  520. VIF_STATE_PRINT_INT(ap.bcast_hlid);
  521. VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
  522. VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
  523. VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
  524. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
  525. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
  526. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
  527. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
  528. }
  529. VIF_STATE_PRINT_INT(last_tx_hlid);
  530. VIF_STATE_PRINT_LHEX(links_map[0]);
  531. VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
  532. VIF_STATE_PRINT_INT(band);
  533. VIF_STATE_PRINT_INT(channel);
  534. VIF_STATE_PRINT_HEX(bitrate_masks[0]);
  535. VIF_STATE_PRINT_HEX(bitrate_masks[1]);
  536. VIF_STATE_PRINT_HEX(basic_rate_set);
  537. VIF_STATE_PRINT_HEX(basic_rate);
  538. VIF_STATE_PRINT_HEX(rate_set);
  539. VIF_STATE_PRINT_INT(beacon_int);
  540. VIF_STATE_PRINT_INT(default_key);
  541. VIF_STATE_PRINT_INT(aid);
  542. VIF_STATE_PRINT_INT(session_counter);
  543. VIF_STATE_PRINT_INT(psm_entry_retry);
  544. VIF_STATE_PRINT_INT(power_level);
  545. VIF_STATE_PRINT_INT(rssi_thold);
  546. VIF_STATE_PRINT_INT(last_rssi_event);
  547. VIF_STATE_PRINT_INT(ba_support);
  548. VIF_STATE_PRINT_INT(ba_allowed);
  549. VIF_STATE_PRINT_INT(is_gem);
  550. VIF_STATE_PRINT_LLHEX(tx_security_seq);
  551. VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
  552. }
  553. #undef VIF_STATE_PRINT_INT
  554. #undef VIF_STATE_PRINT_LONG
  555. #undef VIF_STATE_PRINT_HEX
  556. #undef VIF_STATE_PRINT_LHEX
  557. #undef VIF_STATE_PRINT_LLHEX
  558. #undef VIF_STATE_PRINT_STR
  559. #undef VIF_STATE_PRINT_NSTR
  560. #undef VIF_STATE_PRINT
  561. mutex_unlock(&wl->mutex);
  562. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  563. kfree(buf);
  564. return ret;
  565. }
  566. static const struct file_operations vifs_state_ops = {
  567. .read = vifs_state_read,
  568. .open = wl1271_open_file_generic,
  569. .llseek = default_llseek,
  570. };
  571. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  572. size_t count, loff_t *ppos)
  573. {
  574. struct wl1271 *wl = file->private_data;
  575. u8 value;
  576. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  577. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  578. value = wl->conf.conn.listen_interval;
  579. else
  580. value = 0;
  581. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  582. }
  583. static ssize_t dtim_interval_write(struct file *file,
  584. const char __user *user_buf,
  585. size_t count, loff_t *ppos)
  586. {
  587. struct wl1271 *wl = file->private_data;
  588. unsigned long value;
  589. int ret;
  590. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  591. if (ret < 0) {
  592. wl1271_warning("illegal value for dtim_interval");
  593. return -EINVAL;
  594. }
  595. if (value < 1 || value > 10) {
  596. wl1271_warning("dtim value is not in valid range");
  597. return -ERANGE;
  598. }
  599. mutex_lock(&wl->mutex);
  600. wl->conf.conn.listen_interval = value;
  601. /* for some reason there are different event types for 1 and >1 */
  602. if (value == 1)
  603. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  604. else
  605. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  606. /*
  607. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  608. * take effect on the next time we enter psm.
  609. */
  610. mutex_unlock(&wl->mutex);
  611. return count;
  612. }
  613. static const struct file_operations dtim_interval_ops = {
  614. .read = dtim_interval_read,
  615. .write = dtim_interval_write,
  616. .open = wl1271_open_file_generic,
  617. .llseek = default_llseek,
  618. };
  619. static ssize_t suspend_dtim_interval_read(struct file *file,
  620. char __user *user_buf,
  621. size_t count, loff_t *ppos)
  622. {
  623. struct wl1271 *wl = file->private_data;
  624. u8 value;
  625. if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  626. wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  627. value = wl->conf.conn.suspend_listen_interval;
  628. else
  629. value = 0;
  630. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  631. }
  632. static ssize_t suspend_dtim_interval_write(struct file *file,
  633. const char __user *user_buf,
  634. size_t count, loff_t *ppos)
  635. {
  636. struct wl1271 *wl = file->private_data;
  637. unsigned long value;
  638. int ret;
  639. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  640. if (ret < 0) {
  641. wl1271_warning("illegal value for suspend_dtim_interval");
  642. return -EINVAL;
  643. }
  644. if (value < 1 || value > 10) {
  645. wl1271_warning("suspend_dtim value is not in valid range");
  646. return -ERANGE;
  647. }
  648. mutex_lock(&wl->mutex);
  649. wl->conf.conn.suspend_listen_interval = value;
  650. /* for some reason there are different event types for 1 and >1 */
  651. if (value == 1)
  652. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  653. else
  654. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  655. mutex_unlock(&wl->mutex);
  656. return count;
  657. }
  658. static const struct file_operations suspend_dtim_interval_ops = {
  659. .read = suspend_dtim_interval_read,
  660. .write = suspend_dtim_interval_write,
  661. .open = wl1271_open_file_generic,
  662. .llseek = default_llseek,
  663. };
  664. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  665. size_t count, loff_t *ppos)
  666. {
  667. struct wl1271 *wl = file->private_data;
  668. u8 value;
  669. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  670. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  671. value = wl->conf.conn.listen_interval;
  672. else
  673. value = 0;
  674. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  675. }
  676. static ssize_t beacon_interval_write(struct file *file,
  677. const char __user *user_buf,
  678. size_t count, loff_t *ppos)
  679. {
  680. struct wl1271 *wl = file->private_data;
  681. unsigned long value;
  682. int ret;
  683. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  684. if (ret < 0) {
  685. wl1271_warning("illegal value for beacon_interval");
  686. return -EINVAL;
  687. }
  688. if (value < 1 || value > 255) {
  689. wl1271_warning("beacon interval value is not in valid range");
  690. return -ERANGE;
  691. }
  692. mutex_lock(&wl->mutex);
  693. wl->conf.conn.listen_interval = value;
  694. /* for some reason there are different event types for 1 and >1 */
  695. if (value == 1)
  696. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  697. else
  698. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  699. /*
  700. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  701. * take effect on the next time we enter psm.
  702. */
  703. mutex_unlock(&wl->mutex);
  704. return count;
  705. }
  706. static const struct file_operations beacon_interval_ops = {
  707. .read = beacon_interval_read,
  708. .write = beacon_interval_write,
  709. .open = wl1271_open_file_generic,
  710. .llseek = default_llseek,
  711. };
  712. static ssize_t rx_streaming_interval_write(struct file *file,
  713. const char __user *user_buf,
  714. size_t count, loff_t *ppos)
  715. {
  716. struct wl1271 *wl = file->private_data;
  717. struct wl12xx_vif *wlvif;
  718. unsigned long value;
  719. int ret;
  720. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  721. if (ret < 0) {
  722. wl1271_warning("illegal value in rx_streaming_interval!");
  723. return -EINVAL;
  724. }
  725. /* valid values: 0, 10-100 */
  726. if (value && (value < 10 || value > 100)) {
  727. wl1271_warning("value is not in range!");
  728. return -ERANGE;
  729. }
  730. mutex_lock(&wl->mutex);
  731. wl->conf.rx_streaming.interval = value;
  732. ret = wl1271_ps_elp_wakeup(wl);
  733. if (ret < 0)
  734. goto out;
  735. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  736. wl1271_recalc_rx_streaming(wl, wlvif);
  737. }
  738. wl1271_ps_elp_sleep(wl);
  739. out:
  740. mutex_unlock(&wl->mutex);
  741. return count;
  742. }
  743. static ssize_t rx_streaming_interval_read(struct file *file,
  744. char __user *userbuf,
  745. size_t count, loff_t *ppos)
  746. {
  747. struct wl1271 *wl = file->private_data;
  748. return wl1271_format_buffer(userbuf, count, ppos,
  749. "%d\n", wl->conf.rx_streaming.interval);
  750. }
  751. static const struct file_operations rx_streaming_interval_ops = {
  752. .read = rx_streaming_interval_read,
  753. .write = rx_streaming_interval_write,
  754. .open = wl1271_open_file_generic,
  755. .llseek = default_llseek,
  756. };
  757. static ssize_t rx_streaming_always_write(struct file *file,
  758. const char __user *user_buf,
  759. size_t count, loff_t *ppos)
  760. {
  761. struct wl1271 *wl = file->private_data;
  762. struct wl12xx_vif *wlvif;
  763. unsigned long value;
  764. int ret;
  765. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  766. if (ret < 0) {
  767. wl1271_warning("illegal value in rx_streaming_write!");
  768. return -EINVAL;
  769. }
  770. /* valid values: 0, 10-100 */
  771. if (!(value == 0 || value == 1)) {
  772. wl1271_warning("value is not in valid!");
  773. return -EINVAL;
  774. }
  775. mutex_lock(&wl->mutex);
  776. wl->conf.rx_streaming.always = value;
  777. ret = wl1271_ps_elp_wakeup(wl);
  778. if (ret < 0)
  779. goto out;
  780. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  781. wl1271_recalc_rx_streaming(wl, wlvif);
  782. }
  783. wl1271_ps_elp_sleep(wl);
  784. out:
  785. mutex_unlock(&wl->mutex);
  786. return count;
  787. }
  788. static ssize_t rx_streaming_always_read(struct file *file,
  789. char __user *userbuf,
  790. size_t count, loff_t *ppos)
  791. {
  792. struct wl1271 *wl = file->private_data;
  793. return wl1271_format_buffer(userbuf, count, ppos,
  794. "%d\n", wl->conf.rx_streaming.always);
  795. }
  796. static const struct file_operations rx_streaming_always_ops = {
  797. .read = rx_streaming_always_read,
  798. .write = rx_streaming_always_write,
  799. .open = wl1271_open_file_generic,
  800. .llseek = default_llseek,
  801. };
  802. static ssize_t beacon_filtering_write(struct file *file,
  803. const char __user *user_buf,
  804. size_t count, loff_t *ppos)
  805. {
  806. struct wl1271 *wl = file->private_data;
  807. struct wl12xx_vif *wlvif;
  808. char buf[10];
  809. size_t len;
  810. unsigned long value;
  811. int ret;
  812. len = min(count, sizeof(buf) - 1);
  813. if (copy_from_user(buf, user_buf, len))
  814. return -EFAULT;
  815. buf[len] = '\0';
  816. ret = kstrtoul(buf, 0, &value);
  817. if (ret < 0) {
  818. wl1271_warning("illegal value for beacon_filtering!");
  819. return -EINVAL;
  820. }
  821. mutex_lock(&wl->mutex);
  822. ret = wl1271_ps_elp_wakeup(wl);
  823. if (ret < 0)
  824. goto out;
  825. wl12xx_for_each_wlvif(wl, wlvif) {
  826. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
  827. }
  828. wl1271_ps_elp_sleep(wl);
  829. out:
  830. mutex_unlock(&wl->mutex);
  831. return count;
  832. }
  833. static const struct file_operations beacon_filtering_ops = {
  834. .write = beacon_filtering_write,
  835. .open = wl1271_open_file_generic,
  836. .llseek = default_llseek,
  837. };
  838. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  839. struct dentry *rootdir)
  840. {
  841. int ret = 0;
  842. struct dentry *entry, *stats, *streaming;
  843. stats = debugfs_create_dir("fw-statistics", rootdir);
  844. if (!stats || IS_ERR(stats)) {
  845. entry = stats;
  846. goto err;
  847. }
  848. DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
  849. DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
  850. DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
  851. DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
  852. DEBUGFS_FWSTATS_ADD(rx, dropped);
  853. DEBUGFS_FWSTATS_ADD(rx, fcs_err);
  854. DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
  855. DEBUGFS_FWSTATS_ADD(rx, path_reset);
  856. DEBUGFS_FWSTATS_ADD(rx, reset_counter);
  857. DEBUGFS_FWSTATS_ADD(dma, rx_requested);
  858. DEBUGFS_FWSTATS_ADD(dma, rx_errors);
  859. DEBUGFS_FWSTATS_ADD(dma, tx_requested);
  860. DEBUGFS_FWSTATS_ADD(dma, tx_errors);
  861. DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
  862. DEBUGFS_FWSTATS_ADD(isr, fiqs);
  863. DEBUGFS_FWSTATS_ADD(isr, rx_headers);
  864. DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
  865. DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
  866. DEBUGFS_FWSTATS_ADD(isr, irqs);
  867. DEBUGFS_FWSTATS_ADD(isr, tx_procs);
  868. DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
  869. DEBUGFS_FWSTATS_ADD(isr, dma0_done);
  870. DEBUGFS_FWSTATS_ADD(isr, dma1_done);
  871. DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
  872. DEBUGFS_FWSTATS_ADD(isr, commands);
  873. DEBUGFS_FWSTATS_ADD(isr, rx_procs);
  874. DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
  875. DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
  876. DEBUGFS_FWSTATS_ADD(isr, pci_pm);
  877. DEBUGFS_FWSTATS_ADD(isr, wakeups);
  878. DEBUGFS_FWSTATS_ADD(isr, low_rssi);
  879. DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
  880. DEBUGFS_FWSTATS_ADD(wep, default_key_count);
  881. /* skipping wep.reserved */
  882. DEBUGFS_FWSTATS_ADD(wep, key_not_found);
  883. DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
  884. DEBUGFS_FWSTATS_ADD(wep, packets);
  885. DEBUGFS_FWSTATS_ADD(wep, interrupt);
  886. DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
  887. DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
  888. DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
  889. DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
  890. DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
  891. DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
  892. DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
  893. DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
  894. DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
  895. DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
  896. DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
  897. DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
  898. /* skipping cont_miss_bcns_spread for now */
  899. DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
  900. DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
  901. DEBUGFS_FWSTATS_ADD(mic, calc_failure);
  902. DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
  903. DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
  904. DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
  905. DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
  906. DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
  907. DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
  908. DEBUGFS_FWSTATS_ADD(event, heart_beat);
  909. DEBUGFS_FWSTATS_ADD(event, calibration);
  910. DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
  911. DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
  912. DEBUGFS_FWSTATS_ADD(event, rx_pool);
  913. DEBUGFS_FWSTATS_ADD(event, oom_late);
  914. DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
  915. DEBUGFS_FWSTATS_ADD(event, tx_stuck);
  916. DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
  917. DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
  918. DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
  919. DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
  920. DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
  921. DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
  922. DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
  923. DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
  924. DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
  925. DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
  926. DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
  927. DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
  928. DEBUGFS_ADD(tx_queue_len, rootdir);
  929. DEBUGFS_ADD(retry_count, rootdir);
  930. DEBUGFS_ADD(excessive_retries, rootdir);
  931. DEBUGFS_ADD(gpio_power, rootdir);
  932. DEBUGFS_ADD(start_recovery, rootdir);
  933. DEBUGFS_ADD(driver_state, rootdir);
  934. DEBUGFS_ADD(vifs_state, rootdir);
  935. DEBUGFS_ADD(dtim_interval, rootdir);
  936. DEBUGFS_ADD(suspend_dtim_interval, rootdir);
  937. DEBUGFS_ADD(beacon_interval, rootdir);
  938. DEBUGFS_ADD(beacon_filtering, rootdir);
  939. DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
  940. DEBUGFS_ADD(forced_ps, rootdir);
  941. DEBUGFS_ADD(split_scan_timeout, rootdir);
  942. streaming = debugfs_create_dir("rx_streaming", rootdir);
  943. if (!streaming || IS_ERR(streaming))
  944. goto err;
  945. DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
  946. DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
  947. return 0;
  948. err:
  949. if (IS_ERR(entry))
  950. ret = PTR_ERR(entry);
  951. else
  952. ret = -ENOMEM;
  953. return ret;
  954. }
  955. void wl1271_debugfs_reset(struct wl1271 *wl)
  956. {
  957. if (!wl->stats.fw_stats)
  958. return;
  959. memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
  960. wl->stats.retry_count = 0;
  961. wl->stats.excessive_retries = 0;
  962. }
  963. int wl1271_debugfs_init(struct wl1271 *wl)
  964. {
  965. int ret;
  966. struct dentry *rootdir;
  967. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  968. wl->hw->wiphy->debugfsdir);
  969. if (IS_ERR(rootdir)) {
  970. ret = PTR_ERR(rootdir);
  971. goto err;
  972. }
  973. wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
  974. GFP_KERNEL);
  975. if (!wl->stats.fw_stats) {
  976. ret = -ENOMEM;
  977. goto err_fw;
  978. }
  979. wl->stats.fw_stats_update = jiffies;
  980. ret = wl1271_debugfs_add_files(wl, rootdir);
  981. if (ret < 0)
  982. goto err_file;
  983. return 0;
  984. err_file:
  985. kfree(wl->stats.fw_stats);
  986. wl->stats.fw_stats = NULL;
  987. err_fw:
  988. debugfs_remove_recursive(rootdir);
  989. err:
  990. return ret;
  991. }
  992. void wl1271_debugfs_exit(struct wl1271 *wl)
  993. {
  994. kfree(wl->stats.fw_stats);
  995. wl->stats.fw_stats = NULL;
  996. }