debugfs.c 26 KB

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