debugfs.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include "debugfs.h"
  24. #include <linux/skbuff.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include "wlcore.h"
  28. #include "debug.h"
  29. #include "acx.h"
  30. #include "ps.h"
  31. #include "io.h"
  32. #include "tx.h"
  33. #include "hw_ops.h"
  34. /* ms */
  35. #define WL1271_DEBUGFS_STATS_LIFETIME 1000
  36. /* debugfs macros idea from mac80211 */
  37. int wl1271_format_buffer(char __user *userbuf, size_t count,
  38. loff_t *ppos, char *fmt, ...)
  39. {
  40. va_list args;
  41. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  42. int res;
  43. va_start(args, fmt);
  44. res = vscnprintf(buf, sizeof(buf), fmt, args);
  45. va_end(args);
  46. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  47. }
  48. EXPORT_SYMBOL_GPL(wl1271_format_buffer);
  49. void wl1271_debugfs_update_stats(struct wl1271 *wl)
  50. {
  51. int ret;
  52. mutex_lock(&wl->mutex);
  53. ret = wl1271_ps_elp_wakeup(wl);
  54. if (ret < 0)
  55. goto out;
  56. if (wl->state == WL1271_STATE_ON && !wl->plt &&
  57. time_after(jiffies, wl->stats.fw_stats_update +
  58. msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
  59. wl1271_acx_statistics(wl, wl->stats.fw_stats);
  60. wl->stats.fw_stats_update = jiffies;
  61. }
  62. wl1271_ps_elp_sleep(wl);
  63. out:
  64. mutex_unlock(&wl->mutex);
  65. }
  66. EXPORT_SYMBOL_GPL(wl1271_debugfs_update_stats);
  67. DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
  68. DEBUGFS_READONLY_FILE(excessive_retries, "%u",
  69. wl->stats.excessive_retries);
  70. static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
  71. size_t count, loff_t *ppos)
  72. {
  73. struct wl1271 *wl = file->private_data;
  74. u32 queue_len;
  75. char buf[20];
  76. int res;
  77. queue_len = wl1271_tx_total_queue_count(wl);
  78. res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
  79. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  80. }
  81. static const struct file_operations tx_queue_len_ops = {
  82. .read = tx_queue_len_read,
  83. .open = simple_open,
  84. .llseek = default_llseek,
  85. };
  86. static void chip_op_handler(struct wl1271 *wl, unsigned long value,
  87. void *arg)
  88. {
  89. int ret;
  90. int (*chip_op) (struct wl1271 *wl);
  91. if (!arg) {
  92. wl1271_warning("debugfs chip_op_handler with no callback");
  93. return;
  94. }
  95. ret = wl1271_ps_elp_wakeup(wl);
  96. if (ret < 0)
  97. return;
  98. chip_op = arg;
  99. chip_op(wl);
  100. wl1271_ps_elp_sleep(wl);
  101. }
  102. static inline void no_write_handler(struct wl1271 *wl,
  103. unsigned long value,
  104. unsigned long param)
  105. {
  106. }
  107. #define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
  108. min_val, max_val, write_handler_locked, \
  109. write_handler_arg) \
  110. static ssize_t param##_read(struct file *file, \
  111. char __user *user_buf, \
  112. size_t count, loff_t *ppos) \
  113. { \
  114. struct wl1271 *wl = file->private_data; \
  115. return wl1271_format_buffer(user_buf, count, \
  116. ppos, "%d\n", \
  117. wl->conf.conf_sub_struct.param); \
  118. } \
  119. \
  120. static ssize_t param##_write(struct file *file, \
  121. const char __user *user_buf, \
  122. size_t count, loff_t *ppos) \
  123. { \
  124. struct wl1271 *wl = file->private_data; \
  125. unsigned long value; \
  126. int ret; \
  127. \
  128. ret = kstrtoul_from_user(user_buf, count, 10, &value); \
  129. if (ret < 0) { \
  130. wl1271_warning("illegal value for " #param); \
  131. return -EINVAL; \
  132. } \
  133. \
  134. if (value < min_val || value > max_val) { \
  135. wl1271_warning(#param " is not in valid range"); \
  136. return -ERANGE; \
  137. } \
  138. \
  139. mutex_lock(&wl->mutex); \
  140. wl->conf.conf_sub_struct.param = value; \
  141. \
  142. write_handler_locked(wl, value, write_handler_arg); \
  143. \
  144. mutex_unlock(&wl->mutex); \
  145. return count; \
  146. } \
  147. \
  148. static const struct file_operations param##_ops = { \
  149. .read = param##_read, \
  150. .write = param##_write, \
  151. .open = simple_open, \
  152. .llseek = default_llseek, \
  153. };
  154. WL12XX_CONF_DEBUGFS(irq_pkt_threshold, rx, 0, 65535,
  155. chip_op_handler, wl1271_acx_init_rx_interrupt)
  156. WL12XX_CONF_DEBUGFS(irq_blk_threshold, rx, 0, 65535,
  157. chip_op_handler, wl1271_acx_init_rx_interrupt)
  158. WL12XX_CONF_DEBUGFS(irq_timeout, rx, 0, 100,
  159. chip_op_handler, wl1271_acx_init_rx_interrupt)
  160. static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
  161. size_t count, loff_t *ppos)
  162. {
  163. struct wl1271 *wl = file->private_data;
  164. bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  165. int res;
  166. char buf[10];
  167. res = scnprintf(buf, sizeof(buf), "%d\n", state);
  168. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  169. }
  170. static ssize_t gpio_power_write(struct file *file,
  171. const char __user *user_buf,
  172. size_t count, loff_t *ppos)
  173. {
  174. struct wl1271 *wl = file->private_data;
  175. unsigned long value;
  176. int ret;
  177. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  178. if (ret < 0) {
  179. wl1271_warning("illegal value in gpio_power");
  180. return -EINVAL;
  181. }
  182. mutex_lock(&wl->mutex);
  183. if (value)
  184. wl1271_power_on(wl);
  185. else
  186. wl1271_power_off(wl);
  187. mutex_unlock(&wl->mutex);
  188. return count;
  189. }
  190. static const struct file_operations gpio_power_ops = {
  191. .read = gpio_power_read,
  192. .write = gpio_power_write,
  193. .open = simple_open,
  194. .llseek = default_llseek,
  195. };
  196. static ssize_t start_recovery_write(struct file *file,
  197. const char __user *user_buf,
  198. size_t count, loff_t *ppos)
  199. {
  200. struct wl1271 *wl = file->private_data;
  201. mutex_lock(&wl->mutex);
  202. wl12xx_queue_recovery_work(wl);
  203. mutex_unlock(&wl->mutex);
  204. return count;
  205. }
  206. static const struct file_operations start_recovery_ops = {
  207. .write = start_recovery_write,
  208. .open = simple_open,
  209. .llseek = default_llseek,
  210. };
  211. static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
  212. size_t count, loff_t *ppos)
  213. {
  214. struct wl1271 *wl = file->private_data;
  215. return wl1271_format_buffer(user_buf, count,
  216. ppos, "%d\n",
  217. wl->conf.conn.dynamic_ps_timeout);
  218. }
  219. static ssize_t dynamic_ps_timeout_write(struct file *file,
  220. const char __user *user_buf,
  221. size_t count, loff_t *ppos)
  222. {
  223. struct wl1271 *wl = file->private_data;
  224. struct wl12xx_vif *wlvif;
  225. unsigned long value;
  226. int ret;
  227. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  228. if (ret < 0) {
  229. wl1271_warning("illegal value in dynamic_ps");
  230. return -EINVAL;
  231. }
  232. if (value < 1 || value > 65535) {
  233. wl1271_warning("dyanmic_ps_timeout is not in valid range");
  234. return -ERANGE;
  235. }
  236. mutex_lock(&wl->mutex);
  237. wl->conf.conn.dynamic_ps_timeout = value;
  238. if (wl->state == WL1271_STATE_OFF)
  239. goto out;
  240. ret = wl1271_ps_elp_wakeup(wl);
  241. if (ret < 0)
  242. goto out;
  243. /* In case we're already in PSM, trigger it again to set new timeout
  244. * immediately without waiting for re-association
  245. */
  246. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  247. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  248. wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
  249. }
  250. wl1271_ps_elp_sleep(wl);
  251. out:
  252. mutex_unlock(&wl->mutex);
  253. return count;
  254. }
  255. static const struct file_operations dynamic_ps_timeout_ops = {
  256. .read = dynamic_ps_timeout_read,
  257. .write = dynamic_ps_timeout_write,
  258. .open = simple_open,
  259. .llseek = default_llseek,
  260. };
  261. static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
  262. size_t count, loff_t *ppos)
  263. {
  264. struct wl1271 *wl = file->private_data;
  265. return wl1271_format_buffer(user_buf, count,
  266. ppos, "%d\n",
  267. wl->conf.conn.forced_ps);
  268. }
  269. static ssize_t forced_ps_write(struct file *file,
  270. const char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct wl1271 *wl = file->private_data;
  274. struct wl12xx_vif *wlvif;
  275. unsigned long value;
  276. int ret, ps_mode;
  277. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  278. if (ret < 0) {
  279. wl1271_warning("illegal value in forced_ps");
  280. return -EINVAL;
  281. }
  282. if (value != 1 && value != 0) {
  283. wl1271_warning("forced_ps should be either 0 or 1");
  284. return -ERANGE;
  285. }
  286. mutex_lock(&wl->mutex);
  287. if (wl->conf.conn.forced_ps == value)
  288. goto out;
  289. wl->conf.conn.forced_ps = value;
  290. if (wl->state == WL1271_STATE_OFF)
  291. goto out;
  292. ret = wl1271_ps_elp_wakeup(wl);
  293. if (ret < 0)
  294. goto out;
  295. /* In case we're already in PSM, trigger it again to switch mode
  296. * immediately without waiting for re-association
  297. */
  298. ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
  299. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  300. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  301. wl1271_ps_set_mode(wl, wlvif, ps_mode);
  302. }
  303. wl1271_ps_elp_sleep(wl);
  304. out:
  305. mutex_unlock(&wl->mutex);
  306. return count;
  307. }
  308. static const struct file_operations forced_ps_ops = {
  309. .read = forced_ps_read,
  310. .write = forced_ps_write,
  311. .open = simple_open,
  312. .llseek = default_llseek,
  313. };
  314. static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
  315. size_t count, loff_t *ppos)
  316. {
  317. struct wl1271 *wl = file->private_data;
  318. return wl1271_format_buffer(user_buf, count,
  319. ppos, "%d\n",
  320. wl->conf.scan.split_scan_timeout / 1000);
  321. }
  322. static ssize_t split_scan_timeout_write(struct file *file,
  323. const char __user *user_buf,
  324. size_t count, loff_t *ppos)
  325. {
  326. struct wl1271 *wl = file->private_data;
  327. unsigned long value;
  328. int ret;
  329. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  330. if (ret < 0) {
  331. wl1271_warning("illegal value in split_scan_timeout");
  332. return -EINVAL;
  333. }
  334. if (value == 0)
  335. wl1271_info("split scan will be disabled");
  336. mutex_lock(&wl->mutex);
  337. wl->conf.scan.split_scan_timeout = value * 1000;
  338. mutex_unlock(&wl->mutex);
  339. return count;
  340. }
  341. static const struct file_operations split_scan_timeout_ops = {
  342. .read = split_scan_timeout_read,
  343. .write = split_scan_timeout_write,
  344. .open = simple_open,
  345. .llseek = default_llseek,
  346. };
  347. static ssize_t driver_state_read(struct file *file, char __user *user_buf,
  348. size_t count, loff_t *ppos)
  349. {
  350. struct wl1271 *wl = file->private_data;
  351. int res = 0;
  352. ssize_t ret;
  353. char *buf;
  354. #define DRIVER_STATE_BUF_LEN 1024
  355. buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
  356. if (!buf)
  357. return -ENOMEM;
  358. mutex_lock(&wl->mutex);
  359. #define DRIVER_STATE_PRINT(x, fmt) \
  360. (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
  361. #x " = " fmt "\n", wl->x))
  362. #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
  363. #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
  364. #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
  365. #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
  366. #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
  367. DRIVER_STATE_PRINT_INT(tx_blocks_available);
  368. DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
  369. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
  370. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
  371. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
  372. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
  373. DRIVER_STATE_PRINT_INT(tx_frames_cnt);
  374. DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
  375. DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
  376. DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
  377. DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
  378. DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
  379. DRIVER_STATE_PRINT_INT(tx_packets_count);
  380. DRIVER_STATE_PRINT_INT(tx_results_count);
  381. DRIVER_STATE_PRINT_LHEX(flags);
  382. DRIVER_STATE_PRINT_INT(tx_blocks_freed);
  383. DRIVER_STATE_PRINT_INT(rx_counter);
  384. DRIVER_STATE_PRINT_INT(state);
  385. DRIVER_STATE_PRINT_INT(channel);
  386. DRIVER_STATE_PRINT_INT(band);
  387. DRIVER_STATE_PRINT_INT(power_level);
  388. DRIVER_STATE_PRINT_INT(sg_enabled);
  389. DRIVER_STATE_PRINT_INT(enable_11a);
  390. DRIVER_STATE_PRINT_INT(noise);
  391. DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
  392. DRIVER_STATE_PRINT_LHEX(ap_ps_map);
  393. DRIVER_STATE_PRINT_HEX(quirks);
  394. DRIVER_STATE_PRINT_HEX(irq);
  395. /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
  396. DRIVER_STATE_PRINT_HEX(hw_pg_ver);
  397. DRIVER_STATE_PRINT_HEX(platform_quirks);
  398. DRIVER_STATE_PRINT_HEX(chip.id);
  399. DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
  400. DRIVER_STATE_PRINT_INT(sched_scanning);
  401. #undef DRIVER_STATE_PRINT_INT
  402. #undef DRIVER_STATE_PRINT_LONG
  403. #undef DRIVER_STATE_PRINT_HEX
  404. #undef DRIVER_STATE_PRINT_LHEX
  405. #undef DRIVER_STATE_PRINT_STR
  406. #undef DRIVER_STATE_PRINT
  407. #undef DRIVER_STATE_BUF_LEN
  408. mutex_unlock(&wl->mutex);
  409. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  410. kfree(buf);
  411. return ret;
  412. }
  413. static const struct file_operations driver_state_ops = {
  414. .read = driver_state_read,
  415. .open = simple_open,
  416. .llseek = default_llseek,
  417. };
  418. static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
  419. size_t count, loff_t *ppos)
  420. {
  421. struct wl1271 *wl = file->private_data;
  422. struct wl12xx_vif *wlvif;
  423. int ret, res = 0;
  424. const int buf_size = 4096;
  425. char *buf;
  426. char tmp_buf[64];
  427. buf = kzalloc(buf_size, GFP_KERNEL);
  428. if (!buf)
  429. return -ENOMEM;
  430. mutex_lock(&wl->mutex);
  431. #define VIF_STATE_PRINT(x, fmt) \
  432. (res += scnprintf(buf + res, buf_size - res, \
  433. #x " = " fmt "\n", wlvif->x))
  434. #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
  435. #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
  436. #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
  437. #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
  438. #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
  439. #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
  440. #define VIF_STATE_PRINT_NSTR(x, len) \
  441. do { \
  442. memset(tmp_buf, 0, sizeof(tmp_buf)); \
  443. memcpy(tmp_buf, wlvif->x, \
  444. min_t(u8, len, sizeof(tmp_buf) - 1)); \
  445. res += scnprintf(buf + res, buf_size - res, \
  446. #x " = %s\n", tmp_buf); \
  447. } while (0)
  448. wl12xx_for_each_wlvif(wl, wlvif) {
  449. VIF_STATE_PRINT_INT(role_id);
  450. VIF_STATE_PRINT_INT(bss_type);
  451. VIF_STATE_PRINT_LHEX(flags);
  452. VIF_STATE_PRINT_INT(p2p);
  453. VIF_STATE_PRINT_INT(dev_role_id);
  454. VIF_STATE_PRINT_INT(dev_hlid);
  455. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  456. wlvif->bss_type == BSS_TYPE_IBSS) {
  457. VIF_STATE_PRINT_INT(sta.hlid);
  458. VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
  459. VIF_STATE_PRINT_INT(sta.basic_rate_idx);
  460. VIF_STATE_PRINT_INT(sta.ap_rate_idx);
  461. VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
  462. VIF_STATE_PRINT_INT(sta.qos);
  463. } else {
  464. VIF_STATE_PRINT_INT(ap.global_hlid);
  465. VIF_STATE_PRINT_INT(ap.bcast_hlid);
  466. VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
  467. VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
  468. VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
  469. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
  470. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
  471. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
  472. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
  473. }
  474. VIF_STATE_PRINT_INT(last_tx_hlid);
  475. VIF_STATE_PRINT_LHEX(links_map[0]);
  476. VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
  477. VIF_STATE_PRINT_INT(band);
  478. VIF_STATE_PRINT_INT(channel);
  479. VIF_STATE_PRINT_HEX(bitrate_masks[0]);
  480. VIF_STATE_PRINT_HEX(bitrate_masks[1]);
  481. VIF_STATE_PRINT_HEX(basic_rate_set);
  482. VIF_STATE_PRINT_HEX(basic_rate);
  483. VIF_STATE_PRINT_HEX(rate_set);
  484. VIF_STATE_PRINT_INT(beacon_int);
  485. VIF_STATE_PRINT_INT(default_key);
  486. VIF_STATE_PRINT_INT(aid);
  487. VIF_STATE_PRINT_INT(session_counter);
  488. VIF_STATE_PRINT_INT(psm_entry_retry);
  489. VIF_STATE_PRINT_INT(power_level);
  490. VIF_STATE_PRINT_INT(rssi_thold);
  491. VIF_STATE_PRINT_INT(last_rssi_event);
  492. VIF_STATE_PRINT_INT(ba_support);
  493. VIF_STATE_PRINT_INT(ba_allowed);
  494. VIF_STATE_PRINT_LLHEX(tx_security_seq);
  495. VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
  496. }
  497. #undef VIF_STATE_PRINT_INT
  498. #undef VIF_STATE_PRINT_LONG
  499. #undef VIF_STATE_PRINT_HEX
  500. #undef VIF_STATE_PRINT_LHEX
  501. #undef VIF_STATE_PRINT_LLHEX
  502. #undef VIF_STATE_PRINT_STR
  503. #undef VIF_STATE_PRINT_NSTR
  504. #undef VIF_STATE_PRINT
  505. mutex_unlock(&wl->mutex);
  506. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  507. kfree(buf);
  508. return ret;
  509. }
  510. static const struct file_operations vifs_state_ops = {
  511. .read = vifs_state_read,
  512. .open = simple_open,
  513. .llseek = default_llseek,
  514. };
  515. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  516. size_t count, loff_t *ppos)
  517. {
  518. struct wl1271 *wl = file->private_data;
  519. u8 value;
  520. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  521. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  522. value = wl->conf.conn.listen_interval;
  523. else
  524. value = 0;
  525. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  526. }
  527. static ssize_t dtim_interval_write(struct file *file,
  528. const char __user *user_buf,
  529. size_t count, loff_t *ppos)
  530. {
  531. struct wl1271 *wl = file->private_data;
  532. unsigned long value;
  533. int ret;
  534. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  535. if (ret < 0) {
  536. wl1271_warning("illegal value for dtim_interval");
  537. return -EINVAL;
  538. }
  539. if (value < 1 || value > 10) {
  540. wl1271_warning("dtim value is not in valid range");
  541. return -ERANGE;
  542. }
  543. mutex_lock(&wl->mutex);
  544. wl->conf.conn.listen_interval = value;
  545. /* for some reason there are different event types for 1 and >1 */
  546. if (value == 1)
  547. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  548. else
  549. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  550. /*
  551. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  552. * take effect on the next time we enter psm.
  553. */
  554. mutex_unlock(&wl->mutex);
  555. return count;
  556. }
  557. static const struct file_operations dtim_interval_ops = {
  558. .read = dtim_interval_read,
  559. .write = dtim_interval_write,
  560. .open = simple_open,
  561. .llseek = default_llseek,
  562. };
  563. static ssize_t suspend_dtim_interval_read(struct file *file,
  564. char __user *user_buf,
  565. size_t count, loff_t *ppos)
  566. {
  567. struct wl1271 *wl = file->private_data;
  568. u8 value;
  569. if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  570. wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  571. value = wl->conf.conn.suspend_listen_interval;
  572. else
  573. value = 0;
  574. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  575. }
  576. static ssize_t suspend_dtim_interval_write(struct file *file,
  577. const char __user *user_buf,
  578. size_t count, loff_t *ppos)
  579. {
  580. struct wl1271 *wl = file->private_data;
  581. unsigned long value;
  582. int ret;
  583. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  584. if (ret < 0) {
  585. wl1271_warning("illegal value for suspend_dtim_interval");
  586. return -EINVAL;
  587. }
  588. if (value < 1 || value > 10) {
  589. wl1271_warning("suspend_dtim value is not in valid range");
  590. return -ERANGE;
  591. }
  592. mutex_lock(&wl->mutex);
  593. wl->conf.conn.suspend_listen_interval = value;
  594. /* for some reason there are different event types for 1 and >1 */
  595. if (value == 1)
  596. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  597. else
  598. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  599. mutex_unlock(&wl->mutex);
  600. return count;
  601. }
  602. static const struct file_operations suspend_dtim_interval_ops = {
  603. .read = suspend_dtim_interval_read,
  604. .write = suspend_dtim_interval_write,
  605. .open = simple_open,
  606. .llseek = default_llseek,
  607. };
  608. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  609. size_t count, loff_t *ppos)
  610. {
  611. struct wl1271 *wl = file->private_data;
  612. u8 value;
  613. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  614. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  615. value = wl->conf.conn.listen_interval;
  616. else
  617. value = 0;
  618. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  619. }
  620. static ssize_t beacon_interval_write(struct file *file,
  621. const char __user *user_buf,
  622. size_t count, loff_t *ppos)
  623. {
  624. struct wl1271 *wl = file->private_data;
  625. unsigned long value;
  626. int ret;
  627. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  628. if (ret < 0) {
  629. wl1271_warning("illegal value for beacon_interval");
  630. return -EINVAL;
  631. }
  632. if (value < 1 || value > 255) {
  633. wl1271_warning("beacon interval value is not in valid range");
  634. return -ERANGE;
  635. }
  636. mutex_lock(&wl->mutex);
  637. wl->conf.conn.listen_interval = value;
  638. /* for some reason there are different event types for 1 and >1 */
  639. if (value == 1)
  640. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  641. else
  642. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  643. /*
  644. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  645. * take effect on the next time we enter psm.
  646. */
  647. mutex_unlock(&wl->mutex);
  648. return count;
  649. }
  650. static const struct file_operations beacon_interval_ops = {
  651. .read = beacon_interval_read,
  652. .write = beacon_interval_write,
  653. .open = simple_open,
  654. .llseek = default_llseek,
  655. };
  656. static ssize_t rx_streaming_interval_write(struct file *file,
  657. const char __user *user_buf,
  658. size_t count, loff_t *ppos)
  659. {
  660. struct wl1271 *wl = file->private_data;
  661. struct wl12xx_vif *wlvif;
  662. unsigned long value;
  663. int ret;
  664. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  665. if (ret < 0) {
  666. wl1271_warning("illegal value in rx_streaming_interval!");
  667. return -EINVAL;
  668. }
  669. /* valid values: 0, 10-100 */
  670. if (value && (value < 10 || value > 100)) {
  671. wl1271_warning("value is not in range!");
  672. return -ERANGE;
  673. }
  674. mutex_lock(&wl->mutex);
  675. wl->conf.rx_streaming.interval = value;
  676. ret = wl1271_ps_elp_wakeup(wl);
  677. if (ret < 0)
  678. goto out;
  679. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  680. wl1271_recalc_rx_streaming(wl, wlvif);
  681. }
  682. wl1271_ps_elp_sleep(wl);
  683. out:
  684. mutex_unlock(&wl->mutex);
  685. return count;
  686. }
  687. static ssize_t rx_streaming_interval_read(struct file *file,
  688. char __user *userbuf,
  689. size_t count, loff_t *ppos)
  690. {
  691. struct wl1271 *wl = file->private_data;
  692. return wl1271_format_buffer(userbuf, count, ppos,
  693. "%d\n", wl->conf.rx_streaming.interval);
  694. }
  695. static const struct file_operations rx_streaming_interval_ops = {
  696. .read = rx_streaming_interval_read,
  697. .write = rx_streaming_interval_write,
  698. .open = simple_open,
  699. .llseek = default_llseek,
  700. };
  701. static ssize_t rx_streaming_always_write(struct file *file,
  702. const char __user *user_buf,
  703. size_t count, loff_t *ppos)
  704. {
  705. struct wl1271 *wl = file->private_data;
  706. struct wl12xx_vif *wlvif;
  707. unsigned long value;
  708. int ret;
  709. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  710. if (ret < 0) {
  711. wl1271_warning("illegal value in rx_streaming_write!");
  712. return -EINVAL;
  713. }
  714. /* valid values: 0, 10-100 */
  715. if (!(value == 0 || value == 1)) {
  716. wl1271_warning("value is not in valid!");
  717. return -EINVAL;
  718. }
  719. mutex_lock(&wl->mutex);
  720. wl->conf.rx_streaming.always = value;
  721. ret = wl1271_ps_elp_wakeup(wl);
  722. if (ret < 0)
  723. goto out;
  724. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  725. wl1271_recalc_rx_streaming(wl, wlvif);
  726. }
  727. wl1271_ps_elp_sleep(wl);
  728. out:
  729. mutex_unlock(&wl->mutex);
  730. return count;
  731. }
  732. static ssize_t rx_streaming_always_read(struct file *file,
  733. char __user *userbuf,
  734. size_t count, loff_t *ppos)
  735. {
  736. struct wl1271 *wl = file->private_data;
  737. return wl1271_format_buffer(userbuf, count, ppos,
  738. "%d\n", wl->conf.rx_streaming.always);
  739. }
  740. static const struct file_operations rx_streaming_always_ops = {
  741. .read = rx_streaming_always_read,
  742. .write = rx_streaming_always_write,
  743. .open = simple_open,
  744. .llseek = default_llseek,
  745. };
  746. static ssize_t beacon_filtering_write(struct file *file,
  747. const char __user *user_buf,
  748. size_t count, loff_t *ppos)
  749. {
  750. struct wl1271 *wl = file->private_data;
  751. struct wl12xx_vif *wlvif;
  752. char buf[10];
  753. size_t len;
  754. unsigned long value;
  755. int ret;
  756. len = min(count, sizeof(buf) - 1);
  757. if (copy_from_user(buf, user_buf, len))
  758. return -EFAULT;
  759. buf[len] = '\0';
  760. ret = kstrtoul(buf, 0, &value);
  761. if (ret < 0) {
  762. wl1271_warning("illegal value for beacon_filtering!");
  763. return -EINVAL;
  764. }
  765. mutex_lock(&wl->mutex);
  766. ret = wl1271_ps_elp_wakeup(wl);
  767. if (ret < 0)
  768. goto out;
  769. wl12xx_for_each_wlvif(wl, wlvif) {
  770. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
  771. }
  772. wl1271_ps_elp_sleep(wl);
  773. out:
  774. mutex_unlock(&wl->mutex);
  775. return count;
  776. }
  777. static const struct file_operations beacon_filtering_ops = {
  778. .write = beacon_filtering_write,
  779. .open = simple_open,
  780. .llseek = default_llseek,
  781. };
  782. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  783. struct dentry *rootdir)
  784. {
  785. int ret = 0;
  786. struct dentry *entry, *streaming;
  787. DEBUGFS_ADD(tx_queue_len, rootdir);
  788. DEBUGFS_ADD(retry_count, rootdir);
  789. DEBUGFS_ADD(excessive_retries, rootdir);
  790. DEBUGFS_ADD(gpio_power, rootdir);
  791. DEBUGFS_ADD(start_recovery, rootdir);
  792. DEBUGFS_ADD(driver_state, rootdir);
  793. DEBUGFS_ADD(vifs_state, rootdir);
  794. DEBUGFS_ADD(dtim_interval, rootdir);
  795. DEBUGFS_ADD(suspend_dtim_interval, rootdir);
  796. DEBUGFS_ADD(beacon_interval, rootdir);
  797. DEBUGFS_ADD(beacon_filtering, rootdir);
  798. DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
  799. DEBUGFS_ADD(forced_ps, rootdir);
  800. DEBUGFS_ADD(split_scan_timeout, rootdir);
  801. DEBUGFS_ADD(irq_pkt_threshold, rootdir);
  802. DEBUGFS_ADD(irq_blk_threshold, rootdir);
  803. DEBUGFS_ADD(irq_timeout, rootdir);
  804. streaming = debugfs_create_dir("rx_streaming", rootdir);
  805. if (!streaming || IS_ERR(streaming))
  806. goto err;
  807. DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
  808. DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
  809. return 0;
  810. err:
  811. if (IS_ERR(entry))
  812. ret = PTR_ERR(entry);
  813. else
  814. ret = -ENOMEM;
  815. return ret;
  816. }
  817. void wl1271_debugfs_reset(struct wl1271 *wl)
  818. {
  819. if (!wl->stats.fw_stats)
  820. return;
  821. memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
  822. wl->stats.retry_count = 0;
  823. wl->stats.excessive_retries = 0;
  824. }
  825. int wl1271_debugfs_init(struct wl1271 *wl)
  826. {
  827. int ret;
  828. struct dentry *rootdir;
  829. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  830. wl->hw->wiphy->debugfsdir);
  831. if (IS_ERR(rootdir)) {
  832. ret = PTR_ERR(rootdir);
  833. goto out;
  834. }
  835. wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
  836. if (!wl->stats.fw_stats) {
  837. ret = -ENOMEM;
  838. goto out_remove;
  839. }
  840. wl->stats.fw_stats_update = jiffies;
  841. ret = wl1271_debugfs_add_files(wl, rootdir);
  842. if (ret < 0)
  843. goto out_exit;
  844. ret = wlcore_debugfs_init(wl, rootdir);
  845. if (ret < 0)
  846. goto out_exit;
  847. goto out;
  848. out_exit:
  849. wl1271_debugfs_exit(wl);
  850. out_remove:
  851. debugfs_remove_recursive(rootdir);
  852. out:
  853. return ret;
  854. }
  855. void wl1271_debugfs_exit(struct wl1271 *wl)
  856. {
  857. kfree(wl->stats.fw_stats);
  858. wl->stats.fw_stats = NULL;
  859. }