debugfs.c 23 KB

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