debugfs.c 24 KB

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