debugfs.c 25 KB

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