debugfs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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 "wl12xx.h"
  27. #include "acx.h"
  28. #include "ps.h"
  29. #include "io.h"
  30. /* ms */
  31. #define WL1271_DEBUGFS_STATS_LIFETIME 1000
  32. /* debugfs macros idea from mac80211 */
  33. #define DEBUGFS_FORMAT_BUFFER_SIZE 100
  34. static int wl1271_format_buffer(char __user *userbuf, size_t count,
  35. loff_t *ppos, char *fmt, ...)
  36. {
  37. va_list args;
  38. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  39. int res;
  40. va_start(args, fmt);
  41. res = vscnprintf(buf, sizeof(buf), fmt, args);
  42. va_end(args);
  43. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  44. }
  45. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  46. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  47. size_t count, loff_t *ppos) \
  48. { \
  49. struct wl1271 *wl = file->private_data; \
  50. return wl1271_format_buffer(userbuf, count, ppos, \
  51. fmt "\n", ##value); \
  52. } \
  53. \
  54. static const struct file_operations name## _ops = { \
  55. .read = name## _read, \
  56. .open = wl1271_open_file_generic, \
  57. .llseek = generic_file_llseek, \
  58. };
  59. #define DEBUGFS_ADD(name, parent) \
  60. entry = debugfs_create_file(#name, 0400, parent, \
  61. wl, &name## _ops); \
  62. if (!entry || IS_ERR(entry)) \
  63. goto err; \
  64. #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
  65. do { \
  66. entry = debugfs_create_file(#name, 0400, parent, \
  67. wl, &prefix## _## name## _ops); \
  68. if (!entry || IS_ERR(entry)) \
  69. goto err; \
  70. } while (0);
  71. #define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
  72. static ssize_t sub## _ ##name## _read(struct file *file, \
  73. char __user *userbuf, \
  74. size_t count, loff_t *ppos) \
  75. { \
  76. struct wl1271 *wl = file->private_data; \
  77. \
  78. wl1271_debugfs_update_stats(wl); \
  79. \
  80. return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
  81. wl->stats.fw_stats->sub.name); \
  82. } \
  83. \
  84. static const struct file_operations sub## _ ##name## _ops = { \
  85. .read = sub## _ ##name## _read, \
  86. .open = wl1271_open_file_generic, \
  87. .llseek = generic_file_llseek, \
  88. };
  89. #define DEBUGFS_FWSTATS_ADD(sub, name) \
  90. DEBUGFS_ADD(sub## _ ##name, stats)
  91. static void wl1271_debugfs_update_stats(struct wl1271 *wl)
  92. {
  93. int ret;
  94. mutex_lock(&wl->mutex);
  95. ret = wl1271_ps_elp_wakeup(wl);
  96. if (ret < 0)
  97. goto out;
  98. if (wl->state == WL1271_STATE_ON &&
  99. time_after(jiffies, wl->stats.fw_stats_update +
  100. msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
  101. wl1271_acx_statistics(wl, wl->stats.fw_stats);
  102. wl->stats.fw_stats_update = jiffies;
  103. }
  104. wl1271_ps_elp_sleep(wl);
  105. out:
  106. mutex_unlock(&wl->mutex);
  107. }
  108. static int wl1271_open_file_generic(struct inode *inode, struct file *file)
  109. {
  110. file->private_data = inode->i_private;
  111. return 0;
  112. }
  113. DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
  114. DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
  115. DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
  116. DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
  117. DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
  118. DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
  119. DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
  120. DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
  121. DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
  122. DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
  123. DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
  124. DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
  125. DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
  126. DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
  127. DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
  128. DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
  129. DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
  130. DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
  131. DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
  132. DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
  133. DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
  134. DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
  135. DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
  136. DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
  137. DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
  138. DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
  139. DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
  140. DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
  141. DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
  142. DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
  143. DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
  144. DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
  145. DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
  146. /* skipping wep.reserved */
  147. DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
  148. DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
  149. DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
  150. DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
  151. DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
  152. DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
  153. DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
  154. DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
  155. DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
  156. DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
  157. DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
  158. DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
  159. DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
  160. DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
  161. DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
  162. DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
  163. /* skipping cont_miss_bcns_spread for now */
  164. DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
  165. DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
  166. DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
  167. DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
  168. DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
  169. DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
  170. DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
  171. DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
  172. DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
  173. DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
  174. DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
  175. DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
  176. DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
  177. DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
  178. DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
  179. DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
  180. DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
  181. DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
  182. DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
  183. DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
  184. DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
  185. DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
  186. DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
  187. DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
  188. DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
  189. DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
  190. DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
  191. DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
  192. DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
  193. DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
  194. DEBUGFS_READONLY_FILE(excessive_retries, "%u",
  195. wl->stats.excessive_retries);
  196. static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
  197. size_t count, loff_t *ppos)
  198. {
  199. struct wl1271 *wl = file->private_data;
  200. u32 queue_len;
  201. char buf[20];
  202. int res;
  203. queue_len = wl->tx_queue_count;
  204. res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
  205. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  206. }
  207. static const struct file_operations tx_queue_len_ops = {
  208. .read = tx_queue_len_read,
  209. .open = wl1271_open_file_generic,
  210. .llseek = default_llseek,
  211. };
  212. static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
  213. size_t count, loff_t *ppos)
  214. {
  215. struct wl1271 *wl = file->private_data;
  216. bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  217. int res;
  218. char buf[10];
  219. res = scnprintf(buf, sizeof(buf), "%d\n", state);
  220. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  221. }
  222. static ssize_t gpio_power_write(struct file *file,
  223. const char __user *user_buf,
  224. size_t count, loff_t *ppos)
  225. {
  226. struct wl1271 *wl = file->private_data;
  227. char buf[10];
  228. size_t len;
  229. unsigned long value;
  230. int ret;
  231. len = min(count, sizeof(buf) - 1);
  232. if (copy_from_user(buf, user_buf, len)) {
  233. return -EFAULT;
  234. }
  235. buf[len] = '\0';
  236. ret = kstrtoul(buf, 0, &value);
  237. if (ret < 0) {
  238. wl1271_warning("illegal value in gpio_power");
  239. return -EINVAL;
  240. }
  241. mutex_lock(&wl->mutex);
  242. if (value)
  243. wl1271_power_on(wl);
  244. else
  245. wl1271_power_off(wl);
  246. mutex_unlock(&wl->mutex);
  247. return count;
  248. }
  249. static const struct file_operations gpio_power_ops = {
  250. .read = gpio_power_read,
  251. .write = gpio_power_write,
  252. .open = wl1271_open_file_generic,
  253. .llseek = default_llseek,
  254. };
  255. static ssize_t start_recovery_write(struct file *file,
  256. const char __user *user_buf,
  257. size_t count, loff_t *ppos)
  258. {
  259. struct wl1271 *wl = file->private_data;
  260. mutex_lock(&wl->mutex);
  261. ieee80211_queue_work(wl->hw, &wl->recovery_work);
  262. mutex_unlock(&wl->mutex);
  263. return count;
  264. }
  265. static const struct file_operations start_recovery_ops = {
  266. .write = start_recovery_write,
  267. .open = wl1271_open_file_generic,
  268. .llseek = default_llseek,
  269. };
  270. static ssize_t driver_state_read(struct file *file, char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct wl1271 *wl = file->private_data;
  274. int res = 0;
  275. char buf[1024];
  276. mutex_lock(&wl->mutex);
  277. #define DRIVER_STATE_PRINT(x, fmt) \
  278. (res += scnprintf(buf + res, sizeof(buf) - res,\
  279. #x " = " fmt "\n", wl->x))
  280. #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
  281. #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
  282. #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
  283. #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
  284. #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
  285. DRIVER_STATE_PRINT_INT(tx_blocks_available);
  286. DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
  287. DRIVER_STATE_PRINT_INT(tx_frames_cnt);
  288. DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
  289. DRIVER_STATE_PRINT_INT(tx_queue_count);
  290. DRIVER_STATE_PRINT_INT(tx_packets_count);
  291. DRIVER_STATE_PRINT_INT(tx_results_count);
  292. DRIVER_STATE_PRINT_LHEX(flags);
  293. DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]);
  294. DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]);
  295. DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]);
  296. DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]);
  297. DRIVER_STATE_PRINT_INT(tx_security_last_seq);
  298. DRIVER_STATE_PRINT_INT(rx_counter);
  299. DRIVER_STATE_PRINT_INT(session_counter);
  300. DRIVER_STATE_PRINT_INT(state);
  301. DRIVER_STATE_PRINT_INT(bss_type);
  302. DRIVER_STATE_PRINT_INT(channel);
  303. DRIVER_STATE_PRINT_HEX(rate_set);
  304. DRIVER_STATE_PRINT_HEX(basic_rate_set);
  305. DRIVER_STATE_PRINT_HEX(basic_rate);
  306. DRIVER_STATE_PRINT_INT(band);
  307. DRIVER_STATE_PRINT_INT(beacon_int);
  308. DRIVER_STATE_PRINT_INT(psm_entry_retry);
  309. DRIVER_STATE_PRINT_INT(ps_poll_failures);
  310. DRIVER_STATE_PRINT_HEX(filters);
  311. DRIVER_STATE_PRINT_HEX(rx_config);
  312. DRIVER_STATE_PRINT_HEX(rx_filter);
  313. DRIVER_STATE_PRINT_INT(power_level);
  314. DRIVER_STATE_PRINT_INT(rssi_thold);
  315. DRIVER_STATE_PRINT_INT(last_rssi_event);
  316. DRIVER_STATE_PRINT_INT(sg_enabled);
  317. DRIVER_STATE_PRINT_INT(enable_11a);
  318. DRIVER_STATE_PRINT_INT(noise);
  319. DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
  320. DRIVER_STATE_PRINT_INT(last_tx_hlid);
  321. DRIVER_STATE_PRINT_INT(ba_support);
  322. DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
  323. DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
  324. DRIVER_STATE_PRINT_LHEX(ap_ps_map);
  325. DRIVER_STATE_PRINT_HEX(quirks);
  326. DRIVER_STATE_PRINT_HEX(irq);
  327. DRIVER_STATE_PRINT_HEX(ref_clock);
  328. DRIVER_STATE_PRINT_HEX(tcxo_clock);
  329. DRIVER_STATE_PRINT_HEX(hw_pg_ver);
  330. DRIVER_STATE_PRINT_HEX(platform_quirks);
  331. DRIVER_STATE_PRINT_HEX(chip.id);
  332. DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
  333. DRIVER_STATE_PRINT_INT(sched_scanning);
  334. #undef DRIVER_STATE_PRINT_INT
  335. #undef DRIVER_STATE_PRINT_LONG
  336. #undef DRIVER_STATE_PRINT_HEX
  337. #undef DRIVER_STATE_PRINT_LHEX
  338. #undef DRIVER_STATE_PRINT_STR
  339. #undef DRIVER_STATE_PRINT
  340. mutex_unlock(&wl->mutex);
  341. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  342. }
  343. static const struct file_operations driver_state_ops = {
  344. .read = driver_state_read,
  345. .open = wl1271_open_file_generic,
  346. .llseek = default_llseek,
  347. };
  348. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  349. size_t count, loff_t *ppos)
  350. {
  351. struct wl1271 *wl = file->private_data;
  352. u8 value;
  353. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  354. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  355. value = wl->conf.conn.listen_interval;
  356. else
  357. value = 0;
  358. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  359. }
  360. static ssize_t dtim_interval_write(struct file *file,
  361. const char __user *user_buf,
  362. size_t count, loff_t *ppos)
  363. {
  364. struct wl1271 *wl = file->private_data;
  365. char buf[10];
  366. size_t len;
  367. unsigned long value;
  368. int ret;
  369. len = min(count, sizeof(buf) - 1);
  370. if (copy_from_user(buf, user_buf, len))
  371. return -EFAULT;
  372. buf[len] = '\0';
  373. ret = kstrtoul(buf, 0, &value);
  374. if (ret < 0) {
  375. wl1271_warning("illegal value for dtim_interval");
  376. return -EINVAL;
  377. }
  378. if (value < 1 || value > 10) {
  379. wl1271_warning("dtim value is not in valid range");
  380. return -ERANGE;
  381. }
  382. mutex_lock(&wl->mutex);
  383. wl->conf.conn.listen_interval = value;
  384. /* for some reason there are different event types for 1 and >1 */
  385. if (value == 1)
  386. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  387. else
  388. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  389. /*
  390. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  391. * take effect on the next time we enter psm.
  392. */
  393. mutex_unlock(&wl->mutex);
  394. return count;
  395. }
  396. static const struct file_operations dtim_interval_ops = {
  397. .read = dtim_interval_read,
  398. .write = dtim_interval_write,
  399. .open = wl1271_open_file_generic,
  400. .llseek = default_llseek,
  401. };
  402. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  403. size_t count, loff_t *ppos)
  404. {
  405. struct wl1271 *wl = file->private_data;
  406. u8 value;
  407. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  408. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  409. value = wl->conf.conn.listen_interval;
  410. else
  411. value = 0;
  412. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  413. }
  414. static ssize_t beacon_interval_write(struct file *file,
  415. const char __user *user_buf,
  416. size_t count, loff_t *ppos)
  417. {
  418. struct wl1271 *wl = file->private_data;
  419. char buf[10];
  420. size_t len;
  421. unsigned long value;
  422. int ret;
  423. len = min(count, sizeof(buf) - 1);
  424. if (copy_from_user(buf, user_buf, len))
  425. return -EFAULT;
  426. buf[len] = '\0';
  427. ret = kstrtoul(buf, 0, &value);
  428. if (ret < 0) {
  429. wl1271_warning("illegal value for beacon_interval");
  430. return -EINVAL;
  431. }
  432. if (value < 1 || value > 255) {
  433. wl1271_warning("beacon interval value is not in valid range");
  434. return -ERANGE;
  435. }
  436. mutex_lock(&wl->mutex);
  437. wl->conf.conn.listen_interval = value;
  438. /* for some reason there are different event types for 1 and >1 */
  439. if (value == 1)
  440. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  441. else
  442. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  443. /*
  444. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  445. * take effect on the next time we enter psm.
  446. */
  447. mutex_unlock(&wl->mutex);
  448. return count;
  449. }
  450. static const struct file_operations beacon_interval_ops = {
  451. .read = beacon_interval_read,
  452. .write = beacon_interval_write,
  453. .open = wl1271_open_file_generic,
  454. .llseek = default_llseek,
  455. };
  456. static ssize_t rx_streaming_interval_write(struct file *file,
  457. const char __user *user_buf,
  458. size_t count, loff_t *ppos)
  459. {
  460. struct wl1271 *wl = file->private_data;
  461. char buf[10];
  462. size_t len;
  463. unsigned long value;
  464. int ret;
  465. len = min(count, sizeof(buf) - 1);
  466. if (copy_from_user(buf, user_buf, len))
  467. return -EFAULT;
  468. buf[len] = '\0';
  469. ret = kstrtoul(buf, 0, &value);
  470. if (ret < 0) {
  471. wl1271_warning("illegal value in rx_streaming_interval!");
  472. return -EINVAL;
  473. }
  474. /* valid values: 0, 10-100 */
  475. if (value && (value < 10 || value > 100)) {
  476. wl1271_warning("value is not in range!");
  477. return -ERANGE;
  478. }
  479. mutex_lock(&wl->mutex);
  480. wl->conf.rx_streaming.interval = value;
  481. ret = wl1271_ps_elp_wakeup(wl);
  482. if (ret < 0)
  483. goto out;
  484. wl1271_recalc_rx_streaming(wl);
  485. wl1271_ps_elp_sleep(wl);
  486. out:
  487. mutex_unlock(&wl->mutex);
  488. return count;
  489. }
  490. static ssize_t rx_streaming_interval_read(struct file *file,
  491. char __user *userbuf,
  492. size_t count, loff_t *ppos)
  493. {
  494. struct wl1271 *wl = file->private_data;
  495. return wl1271_format_buffer(userbuf, count, ppos,
  496. "%d\n", wl->conf.rx_streaming.interval);
  497. }
  498. static const struct file_operations rx_streaming_interval_ops = {
  499. .read = rx_streaming_interval_read,
  500. .write = rx_streaming_interval_write,
  501. .open = wl1271_open_file_generic,
  502. .llseek = default_llseek,
  503. };
  504. static ssize_t rx_streaming_always_write(struct file *file,
  505. const char __user *user_buf,
  506. size_t count, loff_t *ppos)
  507. {
  508. struct wl1271 *wl = file->private_data;
  509. char buf[10];
  510. size_t len;
  511. unsigned long value;
  512. int ret;
  513. len = min(count, sizeof(buf) - 1);
  514. if (copy_from_user(buf, user_buf, len))
  515. return -EFAULT;
  516. buf[len] = '\0';
  517. ret = kstrtoul(buf, 0, &value);
  518. if (ret < 0) {
  519. wl1271_warning("illegal value in rx_streaming_write!");
  520. return -EINVAL;
  521. }
  522. /* valid values: 0, 10-100 */
  523. if (!(value == 0 || value == 1)) {
  524. wl1271_warning("value is not in valid!");
  525. return -EINVAL;
  526. }
  527. mutex_lock(&wl->mutex);
  528. wl->conf.rx_streaming.always = value;
  529. ret = wl1271_ps_elp_wakeup(wl);
  530. if (ret < 0)
  531. goto out;
  532. wl1271_recalc_rx_streaming(wl);
  533. wl1271_ps_elp_sleep(wl);
  534. out:
  535. mutex_unlock(&wl->mutex);
  536. return count;
  537. }
  538. static ssize_t rx_streaming_always_read(struct file *file,
  539. char __user *userbuf,
  540. size_t count, loff_t *ppos)
  541. {
  542. struct wl1271 *wl = file->private_data;
  543. return wl1271_format_buffer(userbuf, count, ppos,
  544. "%d\n", wl->conf.rx_streaming.always);
  545. }
  546. static const struct file_operations rx_streaming_always_ops = {
  547. .read = rx_streaming_always_read,
  548. .write = rx_streaming_always_write,
  549. .open = wl1271_open_file_generic,
  550. .llseek = default_llseek,
  551. };
  552. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  553. struct dentry *rootdir)
  554. {
  555. int ret = 0;
  556. struct dentry *entry, *stats, *streaming;
  557. stats = debugfs_create_dir("fw-statistics", rootdir);
  558. if (!stats || IS_ERR(stats)) {
  559. entry = stats;
  560. goto err;
  561. }
  562. DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
  563. DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
  564. DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
  565. DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
  566. DEBUGFS_FWSTATS_ADD(rx, dropped);
  567. DEBUGFS_FWSTATS_ADD(rx, fcs_err);
  568. DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
  569. DEBUGFS_FWSTATS_ADD(rx, path_reset);
  570. DEBUGFS_FWSTATS_ADD(rx, reset_counter);
  571. DEBUGFS_FWSTATS_ADD(dma, rx_requested);
  572. DEBUGFS_FWSTATS_ADD(dma, rx_errors);
  573. DEBUGFS_FWSTATS_ADD(dma, tx_requested);
  574. DEBUGFS_FWSTATS_ADD(dma, tx_errors);
  575. DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
  576. DEBUGFS_FWSTATS_ADD(isr, fiqs);
  577. DEBUGFS_FWSTATS_ADD(isr, rx_headers);
  578. DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
  579. DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
  580. DEBUGFS_FWSTATS_ADD(isr, irqs);
  581. DEBUGFS_FWSTATS_ADD(isr, tx_procs);
  582. DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
  583. DEBUGFS_FWSTATS_ADD(isr, dma0_done);
  584. DEBUGFS_FWSTATS_ADD(isr, dma1_done);
  585. DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
  586. DEBUGFS_FWSTATS_ADD(isr, commands);
  587. DEBUGFS_FWSTATS_ADD(isr, rx_procs);
  588. DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
  589. DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
  590. DEBUGFS_FWSTATS_ADD(isr, pci_pm);
  591. DEBUGFS_FWSTATS_ADD(isr, wakeups);
  592. DEBUGFS_FWSTATS_ADD(isr, low_rssi);
  593. DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
  594. DEBUGFS_FWSTATS_ADD(wep, default_key_count);
  595. /* skipping wep.reserved */
  596. DEBUGFS_FWSTATS_ADD(wep, key_not_found);
  597. DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
  598. DEBUGFS_FWSTATS_ADD(wep, packets);
  599. DEBUGFS_FWSTATS_ADD(wep, interrupt);
  600. DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
  601. DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
  602. DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
  603. DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
  604. DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
  605. DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
  606. DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
  607. DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
  608. DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
  609. DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
  610. DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
  611. DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
  612. /* skipping cont_miss_bcns_spread for now */
  613. DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
  614. DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
  615. DEBUGFS_FWSTATS_ADD(mic, calc_failure);
  616. DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
  617. DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
  618. DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
  619. DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
  620. DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
  621. DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
  622. DEBUGFS_FWSTATS_ADD(event, heart_beat);
  623. DEBUGFS_FWSTATS_ADD(event, calibration);
  624. DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
  625. DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
  626. DEBUGFS_FWSTATS_ADD(event, rx_pool);
  627. DEBUGFS_FWSTATS_ADD(event, oom_late);
  628. DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
  629. DEBUGFS_FWSTATS_ADD(event, tx_stuck);
  630. DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
  631. DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
  632. DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
  633. DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
  634. DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
  635. DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
  636. DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
  637. DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
  638. DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
  639. DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
  640. DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
  641. DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
  642. DEBUGFS_ADD(tx_queue_len, rootdir);
  643. DEBUGFS_ADD(retry_count, rootdir);
  644. DEBUGFS_ADD(excessive_retries, rootdir);
  645. DEBUGFS_ADD(gpio_power, rootdir);
  646. DEBUGFS_ADD(start_recovery, rootdir);
  647. DEBUGFS_ADD(driver_state, rootdir);
  648. DEBUGFS_ADD(dtim_interval, rootdir);
  649. DEBUGFS_ADD(beacon_interval, rootdir);
  650. streaming = debugfs_create_dir("rx_streaming", rootdir);
  651. if (!streaming || IS_ERR(streaming))
  652. goto err;
  653. DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
  654. DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
  655. return 0;
  656. err:
  657. if (IS_ERR(entry))
  658. ret = PTR_ERR(entry);
  659. else
  660. ret = -ENOMEM;
  661. return ret;
  662. }
  663. void wl1271_debugfs_reset(struct wl1271 *wl)
  664. {
  665. if (!wl->stats.fw_stats)
  666. return;
  667. memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
  668. wl->stats.retry_count = 0;
  669. wl->stats.excessive_retries = 0;
  670. }
  671. int wl1271_debugfs_init(struct wl1271 *wl)
  672. {
  673. int ret;
  674. struct dentry *rootdir;
  675. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  676. wl->hw->wiphy->debugfsdir);
  677. if (IS_ERR(rootdir)) {
  678. ret = PTR_ERR(rootdir);
  679. goto err;
  680. }
  681. wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
  682. GFP_KERNEL);
  683. if (!wl->stats.fw_stats) {
  684. ret = -ENOMEM;
  685. goto err_fw;
  686. }
  687. wl->stats.fw_stats_update = jiffies;
  688. ret = wl1271_debugfs_add_files(wl, rootdir);
  689. if (ret < 0)
  690. goto err_file;
  691. return 0;
  692. err_file:
  693. kfree(wl->stats.fw_stats);
  694. wl->stats.fw_stats = NULL;
  695. err_fw:
  696. debugfs_remove_recursive(rootdir);
  697. err:
  698. return ret;
  699. }
  700. void wl1271_debugfs_exit(struct wl1271 *wl)
  701. {
  702. kfree(wl->stats.fw_stats);
  703. wl->stats.fw_stats = NULL;
  704. }