debugfs.c 31 KB

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