debugfs.c 27 KB

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