debugfs.c 31 KB

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