debugfs.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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("dynamic_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. struct wl12xx_vif *wlvif;
  358. #define DRIVER_STATE_BUF_LEN 1024
  359. buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
  360. if (!buf)
  361. return -ENOMEM;
  362. mutex_lock(&wl->mutex);
  363. #define DRIVER_STATE_PRINT(x, fmt) \
  364. (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
  365. #x " = " fmt "\n", wl->x))
  366. #define DRIVER_STATE_PRINT_GENERIC(x, fmt, args...) \
  367. (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
  368. #x " = " fmt "\n", args))
  369. #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
  370. #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
  371. #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
  372. #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
  373. #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
  374. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  375. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  376. continue;
  377. DRIVER_STATE_PRINT_GENERIC(channel, "%d (%s)", wlvif->channel,
  378. wlvif->p2p ? "P2P-CL" : "STA");
  379. }
  380. wl12xx_for_each_wlvif_ap(wl, wlvif)
  381. DRIVER_STATE_PRINT_GENERIC(channel, "%d (%s)", wlvif->channel,
  382. wlvif->p2p ? "P2P-GO" : "AP");
  383. DRIVER_STATE_PRINT_INT(tx_blocks_available);
  384. DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
  385. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
  386. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
  387. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
  388. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
  389. DRIVER_STATE_PRINT_INT(tx_frames_cnt);
  390. DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
  391. DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
  392. DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
  393. DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
  394. DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
  395. DRIVER_STATE_PRINT_INT(tx_packets_count);
  396. DRIVER_STATE_PRINT_INT(tx_results_count);
  397. DRIVER_STATE_PRINT_LHEX(flags);
  398. DRIVER_STATE_PRINT_INT(tx_blocks_freed);
  399. DRIVER_STATE_PRINT_INT(rx_counter);
  400. DRIVER_STATE_PRINT_INT(state);
  401. DRIVER_STATE_PRINT_INT(band);
  402. DRIVER_STATE_PRINT_INT(power_level);
  403. DRIVER_STATE_PRINT_INT(sg_enabled);
  404. DRIVER_STATE_PRINT_INT(enable_11a);
  405. DRIVER_STATE_PRINT_INT(noise);
  406. DRIVER_STATE_PRINT_LHEX(ap_fw_ps_map);
  407. DRIVER_STATE_PRINT_LHEX(ap_ps_map);
  408. DRIVER_STATE_PRINT_HEX(quirks);
  409. DRIVER_STATE_PRINT_HEX(irq);
  410. /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
  411. DRIVER_STATE_PRINT_HEX(hw_pg_ver);
  412. DRIVER_STATE_PRINT_HEX(irq_flags);
  413. DRIVER_STATE_PRINT_HEX(chip.id);
  414. DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
  415. DRIVER_STATE_PRINT_STR(chip.phy_fw_ver_str);
  416. DRIVER_STATE_PRINT_INT(recovery_count);
  417. #undef DRIVER_STATE_PRINT_INT
  418. #undef DRIVER_STATE_PRINT_LONG
  419. #undef DRIVER_STATE_PRINT_HEX
  420. #undef DRIVER_STATE_PRINT_LHEX
  421. #undef DRIVER_STATE_PRINT_STR
  422. #undef DRIVER_STATE_PRINT
  423. #undef DRIVER_STATE_BUF_LEN
  424. mutex_unlock(&wl->mutex);
  425. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  426. kfree(buf);
  427. return ret;
  428. }
  429. static const struct file_operations driver_state_ops = {
  430. .read = driver_state_read,
  431. .open = simple_open,
  432. .llseek = default_llseek,
  433. };
  434. static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
  435. size_t count, loff_t *ppos)
  436. {
  437. struct wl1271 *wl = file->private_data;
  438. struct wl12xx_vif *wlvif;
  439. int ret, res = 0;
  440. const int buf_size = 4096;
  441. char *buf;
  442. char tmp_buf[64];
  443. buf = kzalloc(buf_size, GFP_KERNEL);
  444. if (!buf)
  445. return -ENOMEM;
  446. mutex_lock(&wl->mutex);
  447. #define VIF_STATE_PRINT(x, fmt) \
  448. (res += scnprintf(buf + res, buf_size - res, \
  449. #x " = " fmt "\n", wlvif->x))
  450. #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
  451. #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
  452. #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
  453. #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
  454. #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
  455. #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
  456. #define VIF_STATE_PRINT_NSTR(x, len) \
  457. do { \
  458. memset(tmp_buf, 0, sizeof(tmp_buf)); \
  459. memcpy(tmp_buf, wlvif->x, \
  460. min_t(u8, len, sizeof(tmp_buf) - 1)); \
  461. res += scnprintf(buf + res, buf_size - res, \
  462. #x " = %s\n", tmp_buf); \
  463. } while (0)
  464. wl12xx_for_each_wlvif(wl, wlvif) {
  465. VIF_STATE_PRINT_INT(role_id);
  466. VIF_STATE_PRINT_INT(bss_type);
  467. VIF_STATE_PRINT_LHEX(flags);
  468. VIF_STATE_PRINT_INT(p2p);
  469. VIF_STATE_PRINT_INT(dev_role_id);
  470. VIF_STATE_PRINT_INT(dev_hlid);
  471. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  472. wlvif->bss_type == BSS_TYPE_IBSS) {
  473. VIF_STATE_PRINT_INT(sta.hlid);
  474. VIF_STATE_PRINT_INT(sta.basic_rate_idx);
  475. VIF_STATE_PRINT_INT(sta.ap_rate_idx);
  476. VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
  477. VIF_STATE_PRINT_INT(sta.qos);
  478. } else {
  479. VIF_STATE_PRINT_INT(ap.global_hlid);
  480. VIF_STATE_PRINT_INT(ap.bcast_hlid);
  481. VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
  482. VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
  483. VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
  484. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
  485. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
  486. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
  487. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
  488. }
  489. VIF_STATE_PRINT_INT(last_tx_hlid);
  490. VIF_STATE_PRINT_INT(tx_queue_count[0]);
  491. VIF_STATE_PRINT_INT(tx_queue_count[1]);
  492. VIF_STATE_PRINT_INT(tx_queue_count[2]);
  493. VIF_STATE_PRINT_INT(tx_queue_count[3]);
  494. VIF_STATE_PRINT_LHEX(links_map[0]);
  495. VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
  496. VIF_STATE_PRINT_INT(band);
  497. VIF_STATE_PRINT_INT(channel);
  498. VIF_STATE_PRINT_HEX(bitrate_masks[0]);
  499. VIF_STATE_PRINT_HEX(bitrate_masks[1]);
  500. VIF_STATE_PRINT_HEX(basic_rate_set);
  501. VIF_STATE_PRINT_HEX(basic_rate);
  502. VIF_STATE_PRINT_HEX(rate_set);
  503. VIF_STATE_PRINT_INT(beacon_int);
  504. VIF_STATE_PRINT_INT(default_key);
  505. VIF_STATE_PRINT_INT(aid);
  506. VIF_STATE_PRINT_INT(psm_entry_retry);
  507. VIF_STATE_PRINT_INT(power_level);
  508. VIF_STATE_PRINT_INT(rssi_thold);
  509. VIF_STATE_PRINT_INT(last_rssi_event);
  510. VIF_STATE_PRINT_INT(ba_support);
  511. VIF_STATE_PRINT_INT(ba_allowed);
  512. VIF_STATE_PRINT_LLHEX(total_freed_pkts);
  513. }
  514. #undef VIF_STATE_PRINT_INT
  515. #undef VIF_STATE_PRINT_LONG
  516. #undef VIF_STATE_PRINT_HEX
  517. #undef VIF_STATE_PRINT_LHEX
  518. #undef VIF_STATE_PRINT_LLHEX
  519. #undef VIF_STATE_PRINT_STR
  520. #undef VIF_STATE_PRINT_NSTR
  521. #undef VIF_STATE_PRINT
  522. mutex_unlock(&wl->mutex);
  523. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  524. kfree(buf);
  525. return ret;
  526. }
  527. static const struct file_operations vifs_state_ops = {
  528. .read = vifs_state_read,
  529. .open = simple_open,
  530. .llseek = default_llseek,
  531. };
  532. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  533. size_t count, loff_t *ppos)
  534. {
  535. struct wl1271 *wl = file->private_data;
  536. u8 value;
  537. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  538. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  539. value = wl->conf.conn.listen_interval;
  540. else
  541. value = 0;
  542. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  543. }
  544. static ssize_t dtim_interval_write(struct file *file,
  545. const char __user *user_buf,
  546. size_t count, loff_t *ppos)
  547. {
  548. struct wl1271 *wl = file->private_data;
  549. unsigned long value;
  550. int ret;
  551. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  552. if (ret < 0) {
  553. wl1271_warning("illegal value for dtim_interval");
  554. return -EINVAL;
  555. }
  556. if (value < 1 || value > 10) {
  557. wl1271_warning("dtim value is not in valid range");
  558. return -ERANGE;
  559. }
  560. mutex_lock(&wl->mutex);
  561. wl->conf.conn.listen_interval = value;
  562. /* for some reason there are different event types for 1 and >1 */
  563. if (value == 1)
  564. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  565. else
  566. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  567. /*
  568. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  569. * take effect on the next time we enter psm.
  570. */
  571. mutex_unlock(&wl->mutex);
  572. return count;
  573. }
  574. static const struct file_operations dtim_interval_ops = {
  575. .read = dtim_interval_read,
  576. .write = dtim_interval_write,
  577. .open = simple_open,
  578. .llseek = default_llseek,
  579. };
  580. static ssize_t suspend_dtim_interval_read(struct file *file,
  581. char __user *user_buf,
  582. size_t count, loff_t *ppos)
  583. {
  584. struct wl1271 *wl = file->private_data;
  585. u8 value;
  586. if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  587. wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  588. value = wl->conf.conn.suspend_listen_interval;
  589. else
  590. value = 0;
  591. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  592. }
  593. static ssize_t suspend_dtim_interval_write(struct file *file,
  594. const char __user *user_buf,
  595. size_t count, loff_t *ppos)
  596. {
  597. struct wl1271 *wl = file->private_data;
  598. unsigned long value;
  599. int ret;
  600. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  601. if (ret < 0) {
  602. wl1271_warning("illegal value for suspend_dtim_interval");
  603. return -EINVAL;
  604. }
  605. if (value < 1 || value > 10) {
  606. wl1271_warning("suspend_dtim value is not in valid range");
  607. return -ERANGE;
  608. }
  609. mutex_lock(&wl->mutex);
  610. wl->conf.conn.suspend_listen_interval = value;
  611. /* for some reason there are different event types for 1 and >1 */
  612. if (value == 1)
  613. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  614. else
  615. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  616. mutex_unlock(&wl->mutex);
  617. return count;
  618. }
  619. static const struct file_operations suspend_dtim_interval_ops = {
  620. .read = suspend_dtim_interval_read,
  621. .write = suspend_dtim_interval_write,
  622. .open = simple_open,
  623. .llseek = default_llseek,
  624. };
  625. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  626. size_t count, loff_t *ppos)
  627. {
  628. struct wl1271 *wl = file->private_data;
  629. u8 value;
  630. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  631. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  632. value = wl->conf.conn.listen_interval;
  633. else
  634. value = 0;
  635. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  636. }
  637. static ssize_t beacon_interval_write(struct file *file,
  638. const char __user *user_buf,
  639. size_t count, loff_t *ppos)
  640. {
  641. struct wl1271 *wl = file->private_data;
  642. unsigned long value;
  643. int ret;
  644. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  645. if (ret < 0) {
  646. wl1271_warning("illegal value for beacon_interval");
  647. return -EINVAL;
  648. }
  649. if (value < 1 || value > 255) {
  650. wl1271_warning("beacon interval value is not in valid range");
  651. return -ERANGE;
  652. }
  653. mutex_lock(&wl->mutex);
  654. wl->conf.conn.listen_interval = value;
  655. /* for some reason there are different event types for 1 and >1 */
  656. if (value == 1)
  657. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  658. else
  659. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  660. /*
  661. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  662. * take effect on the next time we enter psm.
  663. */
  664. mutex_unlock(&wl->mutex);
  665. return count;
  666. }
  667. static const struct file_operations beacon_interval_ops = {
  668. .read = beacon_interval_read,
  669. .write = beacon_interval_write,
  670. .open = simple_open,
  671. .llseek = default_llseek,
  672. };
  673. static ssize_t rx_streaming_interval_write(struct file *file,
  674. const char __user *user_buf,
  675. size_t count, loff_t *ppos)
  676. {
  677. struct wl1271 *wl = file->private_data;
  678. struct wl12xx_vif *wlvif;
  679. unsigned long value;
  680. int ret;
  681. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  682. if (ret < 0) {
  683. wl1271_warning("illegal value in rx_streaming_interval!");
  684. return -EINVAL;
  685. }
  686. /* valid values: 0, 10-100 */
  687. if (value && (value < 10 || value > 100)) {
  688. wl1271_warning("value is not in range!");
  689. return -ERANGE;
  690. }
  691. mutex_lock(&wl->mutex);
  692. wl->conf.rx_streaming.interval = value;
  693. ret = wl1271_ps_elp_wakeup(wl);
  694. if (ret < 0)
  695. goto out;
  696. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  697. wl1271_recalc_rx_streaming(wl, wlvif);
  698. }
  699. wl1271_ps_elp_sleep(wl);
  700. out:
  701. mutex_unlock(&wl->mutex);
  702. return count;
  703. }
  704. static ssize_t rx_streaming_interval_read(struct file *file,
  705. char __user *userbuf,
  706. size_t count, loff_t *ppos)
  707. {
  708. struct wl1271 *wl = file->private_data;
  709. return wl1271_format_buffer(userbuf, count, ppos,
  710. "%d\n", wl->conf.rx_streaming.interval);
  711. }
  712. static const struct file_operations rx_streaming_interval_ops = {
  713. .read = rx_streaming_interval_read,
  714. .write = rx_streaming_interval_write,
  715. .open = simple_open,
  716. .llseek = default_llseek,
  717. };
  718. static ssize_t rx_streaming_always_write(struct file *file,
  719. const char __user *user_buf,
  720. size_t count, loff_t *ppos)
  721. {
  722. struct wl1271 *wl = file->private_data;
  723. struct wl12xx_vif *wlvif;
  724. unsigned long value;
  725. int ret;
  726. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  727. if (ret < 0) {
  728. wl1271_warning("illegal value in rx_streaming_write!");
  729. return -EINVAL;
  730. }
  731. /* valid values: 0, 10-100 */
  732. if (!(value == 0 || value == 1)) {
  733. wl1271_warning("value is not in valid!");
  734. return -EINVAL;
  735. }
  736. mutex_lock(&wl->mutex);
  737. wl->conf.rx_streaming.always = value;
  738. ret = wl1271_ps_elp_wakeup(wl);
  739. if (ret < 0)
  740. goto out;
  741. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  742. wl1271_recalc_rx_streaming(wl, wlvif);
  743. }
  744. wl1271_ps_elp_sleep(wl);
  745. out:
  746. mutex_unlock(&wl->mutex);
  747. return count;
  748. }
  749. static ssize_t rx_streaming_always_read(struct file *file,
  750. char __user *userbuf,
  751. size_t count, loff_t *ppos)
  752. {
  753. struct wl1271 *wl = file->private_data;
  754. return wl1271_format_buffer(userbuf, count, ppos,
  755. "%d\n", wl->conf.rx_streaming.always);
  756. }
  757. static const struct file_operations rx_streaming_always_ops = {
  758. .read = rx_streaming_always_read,
  759. .write = rx_streaming_always_write,
  760. .open = simple_open,
  761. .llseek = default_llseek,
  762. };
  763. static ssize_t beacon_filtering_write(struct file *file,
  764. const char __user *user_buf,
  765. size_t count, loff_t *ppos)
  766. {
  767. struct wl1271 *wl = file->private_data;
  768. struct wl12xx_vif *wlvif;
  769. unsigned long value;
  770. int ret;
  771. ret = kstrtoul_from_user(user_buf, count, 0, &value);
  772. if (ret < 0) {
  773. wl1271_warning("illegal value for beacon_filtering!");
  774. return -EINVAL;
  775. }
  776. mutex_lock(&wl->mutex);
  777. ret = wl1271_ps_elp_wakeup(wl);
  778. if (ret < 0)
  779. goto out;
  780. wl12xx_for_each_wlvif(wl, wlvif) {
  781. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
  782. }
  783. wl1271_ps_elp_sleep(wl);
  784. out:
  785. mutex_unlock(&wl->mutex);
  786. return count;
  787. }
  788. static const struct file_operations beacon_filtering_ops = {
  789. .write = beacon_filtering_write,
  790. .open = simple_open,
  791. .llseek = default_llseek,
  792. };
  793. static ssize_t fw_stats_raw_read(struct file *file,
  794. char __user *userbuf,
  795. size_t count, loff_t *ppos)
  796. {
  797. struct wl1271 *wl = file->private_data;
  798. wl1271_debugfs_update_stats(wl);
  799. return simple_read_from_buffer(userbuf, count, ppos,
  800. wl->stats.fw_stats,
  801. wl->stats.fw_stats_len);
  802. }
  803. static const struct file_operations fw_stats_raw_ops = {
  804. .read = fw_stats_raw_read,
  805. .open = simple_open,
  806. .llseek = default_llseek,
  807. };
  808. static ssize_t sleep_auth_read(struct file *file, char __user *user_buf,
  809. size_t count, loff_t *ppos)
  810. {
  811. struct wl1271 *wl = file->private_data;
  812. return wl1271_format_buffer(user_buf, count,
  813. ppos, "%d\n",
  814. wl->sleep_auth);
  815. }
  816. static ssize_t sleep_auth_write(struct file *file,
  817. const char __user *user_buf,
  818. size_t count, loff_t *ppos)
  819. {
  820. struct wl1271 *wl = file->private_data;
  821. unsigned long value;
  822. int ret;
  823. ret = kstrtoul_from_user(user_buf, count, 0, &value);
  824. if (ret < 0) {
  825. wl1271_warning("illegal value in sleep_auth");
  826. return -EINVAL;
  827. }
  828. if (value > WL1271_PSM_MAX) {
  829. wl1271_warning("sleep_auth must be between 0 and %d",
  830. WL1271_PSM_MAX);
  831. return -ERANGE;
  832. }
  833. mutex_lock(&wl->mutex);
  834. wl->conf.conn.sta_sleep_auth = value;
  835. if (unlikely(wl->state != WLCORE_STATE_ON)) {
  836. /* this will show up on "read" in case we are off */
  837. wl->sleep_auth = value;
  838. goto out;
  839. }
  840. ret = wl1271_ps_elp_wakeup(wl);
  841. if (ret < 0)
  842. goto out;
  843. ret = wl1271_acx_sleep_auth(wl, value);
  844. if (ret < 0)
  845. goto out_sleep;
  846. out_sleep:
  847. wl1271_ps_elp_sleep(wl);
  848. out:
  849. mutex_unlock(&wl->mutex);
  850. return count;
  851. }
  852. static const struct file_operations sleep_auth_ops = {
  853. .read = sleep_auth_read,
  854. .write = sleep_auth_write,
  855. .open = simple_open,
  856. .llseek = default_llseek,
  857. };
  858. static ssize_t dev_mem_read(struct file *file,
  859. char __user *user_buf, size_t count,
  860. loff_t *ppos)
  861. {
  862. struct wl1271 *wl = file->private_data;
  863. struct wlcore_partition_set part, old_part;
  864. size_t bytes = count;
  865. int ret;
  866. char *buf;
  867. /* only requests of dword-aligned size and offset are supported */
  868. if (bytes % 4)
  869. return -EINVAL;
  870. if (*ppos % 4)
  871. return -EINVAL;
  872. /* function should return in reasonable time */
  873. bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
  874. if (bytes == 0)
  875. return -EINVAL;
  876. memset(&part, 0, sizeof(part));
  877. part.mem.start = *ppos;
  878. part.mem.size = bytes;
  879. buf = kmalloc(bytes, GFP_KERNEL);
  880. if (!buf)
  881. return -ENOMEM;
  882. mutex_lock(&wl->mutex);
  883. if (unlikely(wl->state == WLCORE_STATE_OFF)) {
  884. ret = -EFAULT;
  885. goto skip_read;
  886. }
  887. /*
  888. * Don't fail if elp_wakeup returns an error, so the device's memory
  889. * could be read even if the FW crashed
  890. */
  891. wl1271_ps_elp_wakeup(wl);
  892. /* store current partition and switch partition */
  893. memcpy(&old_part, &wl->curr_part, sizeof(old_part));
  894. ret = wlcore_set_partition(wl, &part);
  895. if (ret < 0)
  896. goto part_err;
  897. ret = wlcore_raw_read(wl, 0, buf, bytes, false);
  898. if (ret < 0)
  899. goto read_err;
  900. read_err:
  901. /* recover partition */
  902. ret = wlcore_set_partition(wl, &old_part);
  903. if (ret < 0)
  904. goto part_err;
  905. part_err:
  906. wl1271_ps_elp_sleep(wl);
  907. skip_read:
  908. mutex_unlock(&wl->mutex);
  909. if (ret == 0) {
  910. ret = copy_to_user(user_buf, buf, bytes);
  911. if (ret < bytes) {
  912. bytes -= ret;
  913. *ppos += bytes;
  914. ret = 0;
  915. } else {
  916. ret = -EFAULT;
  917. }
  918. }
  919. kfree(buf);
  920. return ((ret == 0) ? bytes : ret);
  921. }
  922. static ssize_t dev_mem_write(struct file *file, const char __user *user_buf,
  923. size_t count, loff_t *ppos)
  924. {
  925. struct wl1271 *wl = file->private_data;
  926. struct wlcore_partition_set part, old_part;
  927. size_t bytes = count;
  928. int ret;
  929. char *buf;
  930. /* only requests of dword-aligned size and offset are supported */
  931. if (bytes % 4)
  932. return -EINVAL;
  933. if (*ppos % 4)
  934. return -EINVAL;
  935. /* function should return in reasonable time */
  936. bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
  937. if (bytes == 0)
  938. return -EINVAL;
  939. memset(&part, 0, sizeof(part));
  940. part.mem.start = *ppos;
  941. part.mem.size = bytes;
  942. buf = memdup_user(user_buf, bytes);
  943. if (IS_ERR(buf))
  944. return PTR_ERR(buf);
  945. mutex_lock(&wl->mutex);
  946. if (unlikely(wl->state == WLCORE_STATE_OFF)) {
  947. ret = -EFAULT;
  948. goto skip_write;
  949. }
  950. /*
  951. * Don't fail if elp_wakeup returns an error, so the device's memory
  952. * could be read even if the FW crashed
  953. */
  954. wl1271_ps_elp_wakeup(wl);
  955. /* store current partition and switch partition */
  956. memcpy(&old_part, &wl->curr_part, sizeof(old_part));
  957. ret = wlcore_set_partition(wl, &part);
  958. if (ret < 0)
  959. goto part_err;
  960. ret = wlcore_raw_write(wl, 0, buf, bytes, false);
  961. if (ret < 0)
  962. goto write_err;
  963. write_err:
  964. /* recover partition */
  965. ret = wlcore_set_partition(wl, &old_part);
  966. if (ret < 0)
  967. goto part_err;
  968. part_err:
  969. wl1271_ps_elp_sleep(wl);
  970. skip_write:
  971. mutex_unlock(&wl->mutex);
  972. if (ret == 0)
  973. *ppos += bytes;
  974. kfree(buf);
  975. return ((ret == 0) ? bytes : ret);
  976. }
  977. static loff_t dev_mem_seek(struct file *file, loff_t offset, int orig)
  978. {
  979. /* only requests of dword-aligned size and offset are supported */
  980. if (offset % 4)
  981. return -EINVAL;
  982. return no_seek_end_llseek(file, offset, orig);
  983. }
  984. static const struct file_operations dev_mem_ops = {
  985. .open = simple_open,
  986. .read = dev_mem_read,
  987. .write = dev_mem_write,
  988. .llseek = dev_mem_seek,
  989. };
  990. static ssize_t fw_logger_read(struct file *file, char __user *user_buf,
  991. size_t count, loff_t *ppos)
  992. {
  993. struct wl1271 *wl = file->private_data;
  994. return wl1271_format_buffer(user_buf, count,
  995. ppos, "%d\n",
  996. wl->conf.fwlog.output);
  997. }
  998. static ssize_t fw_logger_write(struct file *file,
  999. const char __user *user_buf,
  1000. size_t count, loff_t *ppos)
  1001. {
  1002. struct wl1271 *wl = file->private_data;
  1003. unsigned long value;
  1004. int ret;
  1005. ret = kstrtoul_from_user(user_buf, count, 0, &value);
  1006. if (ret < 0) {
  1007. wl1271_warning("illegal value in fw_logger");
  1008. return -EINVAL;
  1009. }
  1010. if ((value > 2) || (value == 0)) {
  1011. wl1271_warning("fw_logger value must be 1-UART 2-SDIO");
  1012. return -ERANGE;
  1013. }
  1014. if (wl->conf.fwlog.output == 0) {
  1015. wl1271_warning("invalid operation - fw logger disabled by default, please change mode via wlconf");
  1016. return -EINVAL;
  1017. }
  1018. mutex_lock(&wl->mutex);
  1019. ret = wl1271_ps_elp_wakeup(wl);
  1020. if (ret < 0) {
  1021. count = ret;
  1022. goto out;
  1023. }
  1024. wl->conf.fwlog.output = value;
  1025. ret = wl12xx_cmd_config_fwlog(wl);
  1026. wl1271_ps_elp_sleep(wl);
  1027. out:
  1028. mutex_unlock(&wl->mutex);
  1029. return count;
  1030. }
  1031. static const struct file_operations fw_logger_ops = {
  1032. .open = simple_open,
  1033. .read = fw_logger_read,
  1034. .write = fw_logger_write,
  1035. .llseek = default_llseek,
  1036. };
  1037. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  1038. struct dentry *rootdir)
  1039. {
  1040. int ret = 0;
  1041. struct dentry *entry, *streaming;
  1042. DEBUGFS_ADD(tx_queue_len, rootdir);
  1043. DEBUGFS_ADD(retry_count, rootdir);
  1044. DEBUGFS_ADD(excessive_retries, rootdir);
  1045. DEBUGFS_ADD(gpio_power, rootdir);
  1046. DEBUGFS_ADD(start_recovery, rootdir);
  1047. DEBUGFS_ADD(driver_state, rootdir);
  1048. DEBUGFS_ADD(vifs_state, rootdir);
  1049. DEBUGFS_ADD(dtim_interval, rootdir);
  1050. DEBUGFS_ADD(suspend_dtim_interval, rootdir);
  1051. DEBUGFS_ADD(beacon_interval, rootdir);
  1052. DEBUGFS_ADD(beacon_filtering, rootdir);
  1053. DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
  1054. DEBUGFS_ADD(forced_ps, rootdir);
  1055. DEBUGFS_ADD(split_scan_timeout, rootdir);
  1056. DEBUGFS_ADD(irq_pkt_threshold, rootdir);
  1057. DEBUGFS_ADD(irq_blk_threshold, rootdir);
  1058. DEBUGFS_ADD(irq_timeout, rootdir);
  1059. DEBUGFS_ADD(fw_stats_raw, rootdir);
  1060. DEBUGFS_ADD(sleep_auth, rootdir);
  1061. DEBUGFS_ADD(fw_logger, rootdir);
  1062. streaming = debugfs_create_dir("rx_streaming", rootdir);
  1063. if (!streaming || IS_ERR(streaming))
  1064. goto err;
  1065. DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
  1066. DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
  1067. DEBUGFS_ADD_PREFIX(dev, mem, rootdir);
  1068. return 0;
  1069. err:
  1070. if (IS_ERR(entry))
  1071. ret = PTR_ERR(entry);
  1072. else
  1073. ret = -ENOMEM;
  1074. return ret;
  1075. }
  1076. void wl1271_debugfs_reset(struct wl1271 *wl)
  1077. {
  1078. if (!wl->stats.fw_stats)
  1079. return;
  1080. memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
  1081. wl->stats.retry_count = 0;
  1082. wl->stats.excessive_retries = 0;
  1083. }
  1084. int wl1271_debugfs_init(struct wl1271 *wl)
  1085. {
  1086. int ret;
  1087. struct dentry *rootdir;
  1088. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  1089. wl->hw->wiphy->debugfsdir);
  1090. if (IS_ERR(rootdir)) {
  1091. ret = PTR_ERR(rootdir);
  1092. goto out;
  1093. }
  1094. wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
  1095. if (!wl->stats.fw_stats) {
  1096. ret = -ENOMEM;
  1097. goto out_remove;
  1098. }
  1099. wl->stats.fw_stats_update = jiffies;
  1100. ret = wl1271_debugfs_add_files(wl, rootdir);
  1101. if (ret < 0)
  1102. goto out_exit;
  1103. ret = wlcore_debugfs_init(wl, rootdir);
  1104. if (ret < 0)
  1105. goto out_exit;
  1106. goto out;
  1107. out_exit:
  1108. wl1271_debugfs_exit(wl);
  1109. out_remove:
  1110. debugfs_remove_recursive(rootdir);
  1111. out:
  1112. return ret;
  1113. }
  1114. void wl1271_debugfs_exit(struct wl1271 *wl)
  1115. {
  1116. kfree(wl->stats.fw_stats);
  1117. wl->stats.fw_stats = NULL;
  1118. }