debugfs.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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. #define WLCORE_MAX_BLOCK_SIZE ((size_t)(4*PAGE_SIZE))
  37. /* debugfs macros idea from mac80211 */
  38. int wl1271_format_buffer(char __user *userbuf, size_t count,
  39. loff_t *ppos, char *fmt, ...)
  40. {
  41. va_list args;
  42. char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
  43. int res;
  44. va_start(args, fmt);
  45. res = vscnprintf(buf, sizeof(buf), fmt, args);
  46. va_end(args);
  47. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  48. }
  49. EXPORT_SYMBOL_GPL(wl1271_format_buffer);
  50. void wl1271_debugfs_update_stats(struct wl1271 *wl)
  51. {
  52. int ret;
  53. mutex_lock(&wl->mutex);
  54. if (unlikely(wl->state != WLCORE_STATE_ON))
  55. goto out;
  56. ret = wl1271_ps_elp_wakeup(wl);
  57. if (ret < 0)
  58. goto out;
  59. if (!wl->plt &&
  60. time_after(jiffies, wl->stats.fw_stats_update +
  61. msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
  62. wl1271_acx_statistics(wl, wl->stats.fw_stats);
  63. wl->stats.fw_stats_update = jiffies;
  64. }
  65. wl1271_ps_elp_sleep(wl);
  66. out:
  67. mutex_unlock(&wl->mutex);
  68. }
  69. EXPORT_SYMBOL_GPL(wl1271_debugfs_update_stats);
  70. DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
  71. DEBUGFS_READONLY_FILE(excessive_retries, "%u",
  72. wl->stats.excessive_retries);
  73. static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
  74. size_t count, loff_t *ppos)
  75. {
  76. struct wl1271 *wl = file->private_data;
  77. u32 queue_len;
  78. char buf[20];
  79. int res;
  80. queue_len = wl1271_tx_total_queue_count(wl);
  81. res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
  82. return simple_read_from_buffer(userbuf, count, ppos, buf, res);
  83. }
  84. static const struct file_operations tx_queue_len_ops = {
  85. .read = tx_queue_len_read,
  86. .open = simple_open,
  87. .llseek = default_llseek,
  88. };
  89. static void chip_op_handler(struct wl1271 *wl, unsigned long value,
  90. void *arg)
  91. {
  92. int ret;
  93. int (*chip_op) (struct wl1271 *wl);
  94. if (!arg) {
  95. wl1271_warning("debugfs chip_op_handler with no callback");
  96. return;
  97. }
  98. ret = wl1271_ps_elp_wakeup(wl);
  99. if (ret < 0)
  100. return;
  101. chip_op = arg;
  102. chip_op(wl);
  103. wl1271_ps_elp_sleep(wl);
  104. }
  105. static inline void no_write_handler(struct wl1271 *wl,
  106. unsigned long value,
  107. unsigned long param)
  108. {
  109. }
  110. #define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
  111. min_val, max_val, write_handler_locked, \
  112. write_handler_arg) \
  113. static ssize_t param##_read(struct file *file, \
  114. char __user *user_buf, \
  115. size_t count, loff_t *ppos) \
  116. { \
  117. struct wl1271 *wl = file->private_data; \
  118. return wl1271_format_buffer(user_buf, count, \
  119. ppos, "%d\n", \
  120. wl->conf.conf_sub_struct.param); \
  121. } \
  122. \
  123. static ssize_t param##_write(struct file *file, \
  124. const char __user *user_buf, \
  125. size_t count, loff_t *ppos) \
  126. { \
  127. struct wl1271 *wl = file->private_data; \
  128. unsigned long value; \
  129. int ret; \
  130. \
  131. ret = kstrtoul_from_user(user_buf, count, 10, &value); \
  132. if (ret < 0) { \
  133. wl1271_warning("illegal value for " #param); \
  134. return -EINVAL; \
  135. } \
  136. \
  137. if (value < min_val || value > max_val) { \
  138. wl1271_warning(#param " is not in valid range"); \
  139. return -ERANGE; \
  140. } \
  141. \
  142. mutex_lock(&wl->mutex); \
  143. wl->conf.conf_sub_struct.param = value; \
  144. \
  145. write_handler_locked(wl, value, write_handler_arg); \
  146. \
  147. mutex_unlock(&wl->mutex); \
  148. return count; \
  149. } \
  150. \
  151. static const struct file_operations param##_ops = { \
  152. .read = param##_read, \
  153. .write = param##_write, \
  154. .open = simple_open, \
  155. .llseek = default_llseek, \
  156. };
  157. WL12XX_CONF_DEBUGFS(irq_pkt_threshold, rx, 0, 65535,
  158. chip_op_handler, wl1271_acx_init_rx_interrupt)
  159. WL12XX_CONF_DEBUGFS(irq_blk_threshold, rx, 0, 65535,
  160. chip_op_handler, wl1271_acx_init_rx_interrupt)
  161. WL12XX_CONF_DEBUGFS(irq_timeout, rx, 0, 100,
  162. chip_op_handler, wl1271_acx_init_rx_interrupt)
  163. static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
  164. size_t count, loff_t *ppos)
  165. {
  166. struct wl1271 *wl = file->private_data;
  167. bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  168. int res;
  169. char buf[10];
  170. res = scnprintf(buf, sizeof(buf), "%d\n", state);
  171. return simple_read_from_buffer(user_buf, count, ppos, buf, res);
  172. }
  173. static ssize_t gpio_power_write(struct file *file,
  174. const char __user *user_buf,
  175. size_t count, loff_t *ppos)
  176. {
  177. struct wl1271 *wl = file->private_data;
  178. unsigned long value;
  179. int ret;
  180. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  181. if (ret < 0) {
  182. wl1271_warning("illegal value in gpio_power");
  183. return -EINVAL;
  184. }
  185. mutex_lock(&wl->mutex);
  186. if (value)
  187. wl1271_power_on(wl);
  188. else
  189. wl1271_power_off(wl);
  190. mutex_unlock(&wl->mutex);
  191. return count;
  192. }
  193. static const struct file_operations gpio_power_ops = {
  194. .read = gpio_power_read,
  195. .write = gpio_power_write,
  196. .open = simple_open,
  197. .llseek = default_llseek,
  198. };
  199. static ssize_t start_recovery_write(struct file *file,
  200. const char __user *user_buf,
  201. size_t count, loff_t *ppos)
  202. {
  203. struct wl1271 *wl = file->private_data;
  204. mutex_lock(&wl->mutex);
  205. wl12xx_queue_recovery_work(wl);
  206. mutex_unlock(&wl->mutex);
  207. return count;
  208. }
  209. static const struct file_operations start_recovery_ops = {
  210. .write = start_recovery_write,
  211. .open = simple_open,
  212. .llseek = default_llseek,
  213. };
  214. static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
  215. size_t count, loff_t *ppos)
  216. {
  217. struct wl1271 *wl = file->private_data;
  218. return wl1271_format_buffer(user_buf, count,
  219. ppos, "%d\n",
  220. wl->conf.conn.dynamic_ps_timeout);
  221. }
  222. static ssize_t dynamic_ps_timeout_write(struct file *file,
  223. const char __user *user_buf,
  224. size_t count, loff_t *ppos)
  225. {
  226. struct wl1271 *wl = file->private_data;
  227. struct wl12xx_vif *wlvif;
  228. unsigned long value;
  229. int ret;
  230. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  231. if (ret < 0) {
  232. wl1271_warning("illegal value in dynamic_ps");
  233. return -EINVAL;
  234. }
  235. if (value < 1 || value > 65535) {
  236. wl1271_warning("dyanmic_ps_timeout is not in valid range");
  237. return -ERANGE;
  238. }
  239. mutex_lock(&wl->mutex);
  240. wl->conf.conn.dynamic_ps_timeout = value;
  241. if (unlikely(wl->state != WLCORE_STATE_ON))
  242. goto out;
  243. ret = wl1271_ps_elp_wakeup(wl);
  244. if (ret < 0)
  245. goto out;
  246. /* In case we're already in PSM, trigger it again to set new timeout
  247. * immediately without waiting for re-association
  248. */
  249. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  250. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  251. wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
  252. }
  253. wl1271_ps_elp_sleep(wl);
  254. out:
  255. mutex_unlock(&wl->mutex);
  256. return count;
  257. }
  258. static const struct file_operations dynamic_ps_timeout_ops = {
  259. .read = dynamic_ps_timeout_read,
  260. .write = dynamic_ps_timeout_write,
  261. .open = simple_open,
  262. .llseek = default_llseek,
  263. };
  264. static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
  265. size_t count, loff_t *ppos)
  266. {
  267. struct wl1271 *wl = file->private_data;
  268. return wl1271_format_buffer(user_buf, count,
  269. ppos, "%d\n",
  270. wl->conf.conn.forced_ps);
  271. }
  272. static ssize_t forced_ps_write(struct file *file,
  273. const char __user *user_buf,
  274. size_t count, loff_t *ppos)
  275. {
  276. struct wl1271 *wl = file->private_data;
  277. struct wl12xx_vif *wlvif;
  278. unsigned long value;
  279. int ret, ps_mode;
  280. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  281. if (ret < 0) {
  282. wl1271_warning("illegal value in forced_ps");
  283. return -EINVAL;
  284. }
  285. if (value != 1 && value != 0) {
  286. wl1271_warning("forced_ps should be either 0 or 1");
  287. return -ERANGE;
  288. }
  289. mutex_lock(&wl->mutex);
  290. if (wl->conf.conn.forced_ps == value)
  291. goto out;
  292. wl->conf.conn.forced_ps = value;
  293. if (unlikely(wl->state != WLCORE_STATE_ON))
  294. goto out;
  295. ret = wl1271_ps_elp_wakeup(wl);
  296. if (ret < 0)
  297. goto out;
  298. /* In case we're already in PSM, trigger it again to switch mode
  299. * immediately without waiting for re-association
  300. */
  301. ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
  302. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  303. if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
  304. wl1271_ps_set_mode(wl, wlvif, ps_mode);
  305. }
  306. wl1271_ps_elp_sleep(wl);
  307. out:
  308. mutex_unlock(&wl->mutex);
  309. return count;
  310. }
  311. static const struct file_operations forced_ps_ops = {
  312. .read = forced_ps_read,
  313. .write = forced_ps_write,
  314. .open = simple_open,
  315. .llseek = default_llseek,
  316. };
  317. static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
  318. size_t count, loff_t *ppos)
  319. {
  320. struct wl1271 *wl = file->private_data;
  321. return wl1271_format_buffer(user_buf, count,
  322. ppos, "%d\n",
  323. wl->conf.scan.split_scan_timeout / 1000);
  324. }
  325. static ssize_t split_scan_timeout_write(struct file *file,
  326. const char __user *user_buf,
  327. size_t count, loff_t *ppos)
  328. {
  329. struct wl1271 *wl = file->private_data;
  330. unsigned long value;
  331. int ret;
  332. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  333. if (ret < 0) {
  334. wl1271_warning("illegal value in split_scan_timeout");
  335. return -EINVAL;
  336. }
  337. if (value == 0)
  338. wl1271_info("split scan will be disabled");
  339. mutex_lock(&wl->mutex);
  340. wl->conf.scan.split_scan_timeout = value * 1000;
  341. mutex_unlock(&wl->mutex);
  342. return count;
  343. }
  344. static const struct file_operations split_scan_timeout_ops = {
  345. .read = split_scan_timeout_read,
  346. .write = split_scan_timeout_write,
  347. .open = simple_open,
  348. .llseek = default_llseek,
  349. };
  350. static ssize_t driver_state_read(struct file *file, char __user *user_buf,
  351. size_t count, loff_t *ppos)
  352. {
  353. struct wl1271 *wl = file->private_data;
  354. int res = 0;
  355. ssize_t ret;
  356. char *buf;
  357. #define DRIVER_STATE_BUF_LEN 1024
  358. buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
  359. if (!buf)
  360. return -ENOMEM;
  361. mutex_lock(&wl->mutex);
  362. #define DRIVER_STATE_PRINT(x, fmt) \
  363. (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
  364. #x " = " fmt "\n", wl->x))
  365. #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
  366. #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
  367. #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
  368. #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
  369. #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
  370. DRIVER_STATE_PRINT_INT(tx_blocks_available);
  371. DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
  372. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
  373. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
  374. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
  375. DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
  376. DRIVER_STATE_PRINT_INT(tx_frames_cnt);
  377. DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
  378. DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
  379. DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
  380. DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
  381. DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
  382. DRIVER_STATE_PRINT_INT(tx_packets_count);
  383. DRIVER_STATE_PRINT_INT(tx_results_count);
  384. DRIVER_STATE_PRINT_LHEX(flags);
  385. DRIVER_STATE_PRINT_INT(tx_blocks_freed);
  386. DRIVER_STATE_PRINT_INT(rx_counter);
  387. DRIVER_STATE_PRINT_INT(state);
  388. DRIVER_STATE_PRINT_INT(channel);
  389. DRIVER_STATE_PRINT_INT(band);
  390. DRIVER_STATE_PRINT_INT(power_level);
  391. DRIVER_STATE_PRINT_INT(sg_enabled);
  392. DRIVER_STATE_PRINT_INT(enable_11a);
  393. DRIVER_STATE_PRINT_INT(noise);
  394. DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
  395. DRIVER_STATE_PRINT_LHEX(ap_ps_map);
  396. DRIVER_STATE_PRINT_HEX(quirks);
  397. DRIVER_STATE_PRINT_HEX(irq);
  398. /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
  399. DRIVER_STATE_PRINT_HEX(hw_pg_ver);
  400. DRIVER_STATE_PRINT_HEX(platform_quirks);
  401. DRIVER_STATE_PRINT_HEX(chip.id);
  402. DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
  403. DRIVER_STATE_PRINT_STR(chip.phy_fw_ver_str);
  404. DRIVER_STATE_PRINT_INT(recovery_count);
  405. #undef DRIVER_STATE_PRINT_INT
  406. #undef DRIVER_STATE_PRINT_LONG
  407. #undef DRIVER_STATE_PRINT_HEX
  408. #undef DRIVER_STATE_PRINT_LHEX
  409. #undef DRIVER_STATE_PRINT_STR
  410. #undef DRIVER_STATE_PRINT
  411. #undef DRIVER_STATE_BUF_LEN
  412. mutex_unlock(&wl->mutex);
  413. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  414. kfree(buf);
  415. return ret;
  416. }
  417. static const struct file_operations driver_state_ops = {
  418. .read = driver_state_read,
  419. .open = simple_open,
  420. .llseek = default_llseek,
  421. };
  422. static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
  423. size_t count, loff_t *ppos)
  424. {
  425. struct wl1271 *wl = file->private_data;
  426. struct wl12xx_vif *wlvif;
  427. int ret, res = 0;
  428. const int buf_size = 4096;
  429. char *buf;
  430. char tmp_buf[64];
  431. buf = kzalloc(buf_size, GFP_KERNEL);
  432. if (!buf)
  433. return -ENOMEM;
  434. mutex_lock(&wl->mutex);
  435. #define VIF_STATE_PRINT(x, fmt) \
  436. (res += scnprintf(buf + res, buf_size - res, \
  437. #x " = " fmt "\n", wlvif->x))
  438. #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
  439. #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
  440. #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
  441. #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
  442. #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
  443. #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
  444. #define VIF_STATE_PRINT_NSTR(x, len) \
  445. do { \
  446. memset(tmp_buf, 0, sizeof(tmp_buf)); \
  447. memcpy(tmp_buf, wlvif->x, \
  448. min_t(u8, len, sizeof(tmp_buf) - 1)); \
  449. res += scnprintf(buf + res, buf_size - res, \
  450. #x " = %s\n", tmp_buf); \
  451. } while (0)
  452. wl12xx_for_each_wlvif(wl, wlvif) {
  453. VIF_STATE_PRINT_INT(role_id);
  454. VIF_STATE_PRINT_INT(bss_type);
  455. VIF_STATE_PRINT_LHEX(flags);
  456. VIF_STATE_PRINT_INT(p2p);
  457. VIF_STATE_PRINT_INT(dev_role_id);
  458. VIF_STATE_PRINT_INT(dev_hlid);
  459. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  460. wlvif->bss_type == BSS_TYPE_IBSS) {
  461. VIF_STATE_PRINT_INT(sta.hlid);
  462. VIF_STATE_PRINT_INT(sta.basic_rate_idx);
  463. VIF_STATE_PRINT_INT(sta.ap_rate_idx);
  464. VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
  465. VIF_STATE_PRINT_INT(sta.qos);
  466. } else {
  467. VIF_STATE_PRINT_INT(ap.global_hlid);
  468. VIF_STATE_PRINT_INT(ap.bcast_hlid);
  469. VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
  470. VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
  471. VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
  472. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
  473. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
  474. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
  475. VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
  476. }
  477. VIF_STATE_PRINT_INT(last_tx_hlid);
  478. VIF_STATE_PRINT_INT(tx_queue_count[0]);
  479. VIF_STATE_PRINT_INT(tx_queue_count[1]);
  480. VIF_STATE_PRINT_INT(tx_queue_count[2]);
  481. VIF_STATE_PRINT_INT(tx_queue_count[3]);
  482. VIF_STATE_PRINT_LHEX(links_map[0]);
  483. VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
  484. VIF_STATE_PRINT_INT(band);
  485. VIF_STATE_PRINT_INT(channel);
  486. VIF_STATE_PRINT_HEX(bitrate_masks[0]);
  487. VIF_STATE_PRINT_HEX(bitrate_masks[1]);
  488. VIF_STATE_PRINT_HEX(basic_rate_set);
  489. VIF_STATE_PRINT_HEX(basic_rate);
  490. VIF_STATE_PRINT_HEX(rate_set);
  491. VIF_STATE_PRINT_INT(beacon_int);
  492. VIF_STATE_PRINT_INT(default_key);
  493. VIF_STATE_PRINT_INT(aid);
  494. VIF_STATE_PRINT_INT(psm_entry_retry);
  495. VIF_STATE_PRINT_INT(power_level);
  496. VIF_STATE_PRINT_INT(rssi_thold);
  497. VIF_STATE_PRINT_INT(last_rssi_event);
  498. VIF_STATE_PRINT_INT(ba_support);
  499. VIF_STATE_PRINT_INT(ba_allowed);
  500. VIF_STATE_PRINT_LLHEX(tx_security_seq);
  501. VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
  502. }
  503. #undef VIF_STATE_PRINT_INT
  504. #undef VIF_STATE_PRINT_LONG
  505. #undef VIF_STATE_PRINT_HEX
  506. #undef VIF_STATE_PRINT_LHEX
  507. #undef VIF_STATE_PRINT_LLHEX
  508. #undef VIF_STATE_PRINT_STR
  509. #undef VIF_STATE_PRINT_NSTR
  510. #undef VIF_STATE_PRINT
  511. mutex_unlock(&wl->mutex);
  512. ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
  513. kfree(buf);
  514. return ret;
  515. }
  516. static const struct file_operations vifs_state_ops = {
  517. .read = vifs_state_read,
  518. .open = simple_open,
  519. .llseek = default_llseek,
  520. };
  521. static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
  522. size_t count, loff_t *ppos)
  523. {
  524. struct wl1271 *wl = file->private_data;
  525. u8 value;
  526. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  527. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  528. value = wl->conf.conn.listen_interval;
  529. else
  530. value = 0;
  531. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  532. }
  533. static ssize_t dtim_interval_write(struct file *file,
  534. const char __user *user_buf,
  535. size_t count, loff_t *ppos)
  536. {
  537. struct wl1271 *wl = file->private_data;
  538. unsigned long value;
  539. int ret;
  540. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  541. if (ret < 0) {
  542. wl1271_warning("illegal value for dtim_interval");
  543. return -EINVAL;
  544. }
  545. if (value < 1 || value > 10) {
  546. wl1271_warning("dtim value is not in valid range");
  547. return -ERANGE;
  548. }
  549. mutex_lock(&wl->mutex);
  550. wl->conf.conn.listen_interval = value;
  551. /* for some reason there are different event types for 1 and >1 */
  552. if (value == 1)
  553. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  554. else
  555. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  556. /*
  557. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  558. * take effect on the next time we enter psm.
  559. */
  560. mutex_unlock(&wl->mutex);
  561. return count;
  562. }
  563. static const struct file_operations dtim_interval_ops = {
  564. .read = dtim_interval_read,
  565. .write = dtim_interval_write,
  566. .open = simple_open,
  567. .llseek = default_llseek,
  568. };
  569. static ssize_t suspend_dtim_interval_read(struct file *file,
  570. char __user *user_buf,
  571. size_t count, loff_t *ppos)
  572. {
  573. struct wl1271 *wl = file->private_data;
  574. u8 value;
  575. if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
  576. wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
  577. value = wl->conf.conn.suspend_listen_interval;
  578. else
  579. value = 0;
  580. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  581. }
  582. static ssize_t suspend_dtim_interval_write(struct file *file,
  583. const char __user *user_buf,
  584. size_t count, loff_t *ppos)
  585. {
  586. struct wl1271 *wl = file->private_data;
  587. unsigned long value;
  588. int ret;
  589. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  590. if (ret < 0) {
  591. wl1271_warning("illegal value for suspend_dtim_interval");
  592. return -EINVAL;
  593. }
  594. if (value < 1 || value > 10) {
  595. wl1271_warning("suspend_dtim value is not in valid range");
  596. return -ERANGE;
  597. }
  598. mutex_lock(&wl->mutex);
  599. wl->conf.conn.suspend_listen_interval = value;
  600. /* for some reason there are different event types for 1 and >1 */
  601. if (value == 1)
  602. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
  603. else
  604. wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
  605. mutex_unlock(&wl->mutex);
  606. return count;
  607. }
  608. static const struct file_operations suspend_dtim_interval_ops = {
  609. .read = suspend_dtim_interval_read,
  610. .write = suspend_dtim_interval_write,
  611. .open = simple_open,
  612. .llseek = default_llseek,
  613. };
  614. static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
  615. size_t count, loff_t *ppos)
  616. {
  617. struct wl1271 *wl = file->private_data;
  618. u8 value;
  619. if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
  620. wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
  621. value = wl->conf.conn.listen_interval;
  622. else
  623. value = 0;
  624. return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
  625. }
  626. static ssize_t beacon_interval_write(struct file *file,
  627. const char __user *user_buf,
  628. size_t count, loff_t *ppos)
  629. {
  630. struct wl1271 *wl = file->private_data;
  631. unsigned long value;
  632. int ret;
  633. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  634. if (ret < 0) {
  635. wl1271_warning("illegal value for beacon_interval");
  636. return -EINVAL;
  637. }
  638. if (value < 1 || value > 255) {
  639. wl1271_warning("beacon interval value is not in valid range");
  640. return -ERANGE;
  641. }
  642. mutex_lock(&wl->mutex);
  643. wl->conf.conn.listen_interval = value;
  644. /* for some reason there are different event types for 1 and >1 */
  645. if (value == 1)
  646. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
  647. else
  648. wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
  649. /*
  650. * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
  651. * take effect on the next time we enter psm.
  652. */
  653. mutex_unlock(&wl->mutex);
  654. return count;
  655. }
  656. static const struct file_operations beacon_interval_ops = {
  657. .read = beacon_interval_read,
  658. .write = beacon_interval_write,
  659. .open = simple_open,
  660. .llseek = default_llseek,
  661. };
  662. static ssize_t rx_streaming_interval_write(struct file *file,
  663. const char __user *user_buf,
  664. size_t count, loff_t *ppos)
  665. {
  666. struct wl1271 *wl = file->private_data;
  667. struct wl12xx_vif *wlvif;
  668. unsigned long value;
  669. int ret;
  670. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  671. if (ret < 0) {
  672. wl1271_warning("illegal value in rx_streaming_interval!");
  673. return -EINVAL;
  674. }
  675. /* valid values: 0, 10-100 */
  676. if (value && (value < 10 || value > 100)) {
  677. wl1271_warning("value is not in range!");
  678. return -ERANGE;
  679. }
  680. mutex_lock(&wl->mutex);
  681. wl->conf.rx_streaming.interval = value;
  682. ret = wl1271_ps_elp_wakeup(wl);
  683. if (ret < 0)
  684. goto out;
  685. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  686. wl1271_recalc_rx_streaming(wl, wlvif);
  687. }
  688. wl1271_ps_elp_sleep(wl);
  689. out:
  690. mutex_unlock(&wl->mutex);
  691. return count;
  692. }
  693. static ssize_t rx_streaming_interval_read(struct file *file,
  694. char __user *userbuf,
  695. size_t count, loff_t *ppos)
  696. {
  697. struct wl1271 *wl = file->private_data;
  698. return wl1271_format_buffer(userbuf, count, ppos,
  699. "%d\n", wl->conf.rx_streaming.interval);
  700. }
  701. static const struct file_operations rx_streaming_interval_ops = {
  702. .read = rx_streaming_interval_read,
  703. .write = rx_streaming_interval_write,
  704. .open = simple_open,
  705. .llseek = default_llseek,
  706. };
  707. static ssize_t rx_streaming_always_write(struct file *file,
  708. const char __user *user_buf,
  709. size_t count, loff_t *ppos)
  710. {
  711. struct wl1271 *wl = file->private_data;
  712. struct wl12xx_vif *wlvif;
  713. unsigned long value;
  714. int ret;
  715. ret = kstrtoul_from_user(user_buf, count, 10, &value);
  716. if (ret < 0) {
  717. wl1271_warning("illegal value in rx_streaming_write!");
  718. return -EINVAL;
  719. }
  720. /* valid values: 0, 10-100 */
  721. if (!(value == 0 || value == 1)) {
  722. wl1271_warning("value is not in valid!");
  723. return -EINVAL;
  724. }
  725. mutex_lock(&wl->mutex);
  726. wl->conf.rx_streaming.always = value;
  727. ret = wl1271_ps_elp_wakeup(wl);
  728. if (ret < 0)
  729. goto out;
  730. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  731. wl1271_recalc_rx_streaming(wl, wlvif);
  732. }
  733. wl1271_ps_elp_sleep(wl);
  734. out:
  735. mutex_unlock(&wl->mutex);
  736. return count;
  737. }
  738. static ssize_t rx_streaming_always_read(struct file *file,
  739. char __user *userbuf,
  740. size_t count, loff_t *ppos)
  741. {
  742. struct wl1271 *wl = file->private_data;
  743. return wl1271_format_buffer(userbuf, count, ppos,
  744. "%d\n", wl->conf.rx_streaming.always);
  745. }
  746. static const struct file_operations rx_streaming_always_ops = {
  747. .read = rx_streaming_always_read,
  748. .write = rx_streaming_always_write,
  749. .open = simple_open,
  750. .llseek = default_llseek,
  751. };
  752. static ssize_t beacon_filtering_write(struct file *file,
  753. const char __user *user_buf,
  754. size_t count, loff_t *ppos)
  755. {
  756. struct wl1271 *wl = file->private_data;
  757. struct wl12xx_vif *wlvif;
  758. char buf[10];
  759. size_t len;
  760. unsigned long value;
  761. int ret;
  762. len = min(count, sizeof(buf) - 1);
  763. if (copy_from_user(buf, user_buf, len))
  764. return -EFAULT;
  765. buf[len] = '\0';
  766. ret = kstrtoul(buf, 0, &value);
  767. if (ret < 0) {
  768. wl1271_warning("illegal value for beacon_filtering!");
  769. return -EINVAL;
  770. }
  771. mutex_lock(&wl->mutex);
  772. ret = wl1271_ps_elp_wakeup(wl);
  773. if (ret < 0)
  774. goto out;
  775. wl12xx_for_each_wlvif(wl, wlvif) {
  776. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
  777. }
  778. wl1271_ps_elp_sleep(wl);
  779. out:
  780. mutex_unlock(&wl->mutex);
  781. return count;
  782. }
  783. static const struct file_operations beacon_filtering_ops = {
  784. .write = beacon_filtering_write,
  785. .open = simple_open,
  786. .llseek = default_llseek,
  787. };
  788. static ssize_t fw_stats_raw_read(struct file *file,
  789. char __user *userbuf,
  790. size_t count, loff_t *ppos)
  791. {
  792. struct wl1271 *wl = file->private_data;
  793. wl1271_debugfs_update_stats(wl);
  794. return simple_read_from_buffer(userbuf, count, ppos,
  795. wl->stats.fw_stats,
  796. wl->stats.fw_stats_len);
  797. }
  798. static const struct file_operations fw_stats_raw_ops = {
  799. .read = fw_stats_raw_read,
  800. .open = simple_open,
  801. .llseek = default_llseek,
  802. };
  803. static ssize_t sleep_auth_read(struct file *file, char __user *user_buf,
  804. size_t count, loff_t *ppos)
  805. {
  806. struct wl1271 *wl = file->private_data;
  807. return wl1271_format_buffer(user_buf, count,
  808. ppos, "%d\n",
  809. wl->sleep_auth);
  810. }
  811. static ssize_t sleep_auth_write(struct file *file,
  812. const char __user *user_buf,
  813. size_t count, loff_t *ppos)
  814. {
  815. struct wl1271 *wl = file->private_data;
  816. unsigned long value;
  817. int ret;
  818. ret = kstrtoul_from_user(user_buf, count, 0, &value);
  819. if (ret < 0) {
  820. wl1271_warning("illegal value in sleep_auth");
  821. return -EINVAL;
  822. }
  823. if (value > WL1271_PSM_MAX) {
  824. wl1271_warning("sleep_auth must be between 0 and %d",
  825. WL1271_PSM_MAX);
  826. return -ERANGE;
  827. }
  828. mutex_lock(&wl->mutex);
  829. wl->conf.conn.sta_sleep_auth = value;
  830. if (unlikely(wl->state != WLCORE_STATE_ON)) {
  831. /* this will show up on "read" in case we are off */
  832. wl->sleep_auth = value;
  833. goto out;
  834. }
  835. ret = wl1271_ps_elp_wakeup(wl);
  836. if (ret < 0)
  837. goto out;
  838. ret = wl1271_acx_sleep_auth(wl, value);
  839. if (ret < 0)
  840. goto out_sleep;
  841. out_sleep:
  842. wl1271_ps_elp_sleep(wl);
  843. out:
  844. mutex_unlock(&wl->mutex);
  845. return count;
  846. }
  847. static const struct file_operations sleep_auth_ops = {
  848. .read = sleep_auth_read,
  849. .write = sleep_auth_write,
  850. .open = simple_open,
  851. .llseek = default_llseek,
  852. };
  853. static ssize_t dev_mem_read(struct file *file,
  854. char __user *user_buf, size_t count,
  855. loff_t *ppos)
  856. {
  857. struct wl1271 *wl = file->private_data;
  858. struct wlcore_partition_set part, old_part;
  859. size_t bytes = count;
  860. int ret;
  861. char *buf;
  862. /* only requests of dword-aligned size and offset are supported */
  863. if (bytes % 4)
  864. return -EINVAL;
  865. if (*ppos % 4)
  866. return -EINVAL;
  867. /* function should return in reasonable time */
  868. bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
  869. if (bytes == 0)
  870. return -EINVAL;
  871. memset(&part, 0, sizeof(part));
  872. part.mem.start = file->f_pos;
  873. part.mem.size = bytes;
  874. buf = kmalloc(bytes, GFP_KERNEL);
  875. if (!buf)
  876. return -ENOMEM;
  877. mutex_lock(&wl->mutex);
  878. if (unlikely(wl->state == WLCORE_STATE_OFF)) {
  879. ret = -EFAULT;
  880. goto skip_read;
  881. }
  882. /*
  883. * Don't fail if elp_wakeup returns an error, so the device's memory
  884. * could be read even if the FW crashed
  885. */
  886. wl1271_ps_elp_wakeup(wl);
  887. /* store current partition and switch partition */
  888. memcpy(&old_part, &wl->curr_part, sizeof(old_part));
  889. ret = wlcore_set_partition(wl, &part);
  890. if (ret < 0)
  891. goto part_err;
  892. ret = wlcore_raw_read(wl, 0, buf, bytes, false);
  893. if (ret < 0)
  894. goto read_err;
  895. read_err:
  896. /* recover partition */
  897. ret = wlcore_set_partition(wl, &old_part);
  898. if (ret < 0)
  899. goto part_err;
  900. part_err:
  901. wl1271_ps_elp_sleep(wl);
  902. skip_read:
  903. mutex_unlock(&wl->mutex);
  904. if (ret == 0) {
  905. ret = copy_to_user(user_buf, buf, bytes);
  906. if (ret < bytes) {
  907. bytes -= ret;
  908. *ppos += bytes;
  909. ret = 0;
  910. } else {
  911. ret = -EFAULT;
  912. }
  913. }
  914. kfree(buf);
  915. return ((ret == 0) ? bytes : ret);
  916. }
  917. static ssize_t dev_mem_write(struct file *file, const char __user *user_buf,
  918. size_t count, loff_t *ppos)
  919. {
  920. struct wl1271 *wl = file->private_data;
  921. struct wlcore_partition_set part, old_part;
  922. size_t bytes = count;
  923. int ret;
  924. char *buf;
  925. /* only requests of dword-aligned size and offset are supported */
  926. if (bytes % 4)
  927. return -EINVAL;
  928. if (*ppos % 4)
  929. return -EINVAL;
  930. /* function should return in reasonable time */
  931. bytes = min(bytes, WLCORE_MAX_BLOCK_SIZE);
  932. if (bytes == 0)
  933. return -EINVAL;
  934. memset(&part, 0, sizeof(part));
  935. part.mem.start = file->f_pos;
  936. part.mem.size = bytes;
  937. buf = kmalloc(bytes, GFP_KERNEL);
  938. if (!buf)
  939. return -ENOMEM;
  940. ret = copy_from_user(buf, user_buf, bytes);
  941. if (ret) {
  942. ret = -EFAULT;
  943. goto err_out;
  944. }
  945. mutex_lock(&wl->mutex);
  946. if (unlikely(wl->state == WLCORE_STATE_OFF)) {
  947. ret = -EFAULT;
  948. goto skip_write;
  949. }
  950. /*
  951. * Don't fail if elp_wakeup returns an error, so the device's memory
  952. * could be read even if the FW crashed
  953. */
  954. wl1271_ps_elp_wakeup(wl);
  955. /* store current partition and switch partition */
  956. memcpy(&old_part, &wl->curr_part, sizeof(old_part));
  957. ret = wlcore_set_partition(wl, &part);
  958. if (ret < 0)
  959. goto part_err;
  960. ret = wlcore_raw_write(wl, 0, buf, bytes, false);
  961. if (ret < 0)
  962. goto write_err;
  963. write_err:
  964. /* recover partition */
  965. ret = wlcore_set_partition(wl, &old_part);
  966. if (ret < 0)
  967. goto part_err;
  968. part_err:
  969. wl1271_ps_elp_sleep(wl);
  970. skip_write:
  971. mutex_unlock(&wl->mutex);
  972. if (ret == 0)
  973. *ppos += bytes;
  974. err_out:
  975. kfree(buf);
  976. return ((ret == 0) ? bytes : ret);
  977. }
  978. static loff_t dev_mem_seek(struct file *file, loff_t offset, int orig)
  979. {
  980. loff_t ret;
  981. /* only requests of dword-aligned size and offset are supported */
  982. if (offset % 4)
  983. return -EINVAL;
  984. switch (orig) {
  985. case SEEK_SET:
  986. file->f_pos = offset;
  987. ret = file->f_pos;
  988. break;
  989. case SEEK_CUR:
  990. file->f_pos += offset;
  991. ret = file->f_pos;
  992. break;
  993. default:
  994. ret = -EINVAL;
  995. }
  996. return ret;
  997. }
  998. static const struct file_operations dev_mem_ops = {
  999. .open = simple_open,
  1000. .read = dev_mem_read,
  1001. .write = dev_mem_write,
  1002. .llseek = dev_mem_seek,
  1003. };
  1004. static int wl1271_debugfs_add_files(struct wl1271 *wl,
  1005. struct dentry *rootdir)
  1006. {
  1007. int ret = 0;
  1008. struct dentry *entry, *streaming;
  1009. DEBUGFS_ADD(tx_queue_len, rootdir);
  1010. DEBUGFS_ADD(retry_count, rootdir);
  1011. DEBUGFS_ADD(excessive_retries, rootdir);
  1012. DEBUGFS_ADD(gpio_power, rootdir);
  1013. DEBUGFS_ADD(start_recovery, rootdir);
  1014. DEBUGFS_ADD(driver_state, rootdir);
  1015. DEBUGFS_ADD(vifs_state, rootdir);
  1016. DEBUGFS_ADD(dtim_interval, rootdir);
  1017. DEBUGFS_ADD(suspend_dtim_interval, rootdir);
  1018. DEBUGFS_ADD(beacon_interval, rootdir);
  1019. DEBUGFS_ADD(beacon_filtering, rootdir);
  1020. DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
  1021. DEBUGFS_ADD(forced_ps, rootdir);
  1022. DEBUGFS_ADD(split_scan_timeout, rootdir);
  1023. DEBUGFS_ADD(irq_pkt_threshold, rootdir);
  1024. DEBUGFS_ADD(irq_blk_threshold, rootdir);
  1025. DEBUGFS_ADD(irq_timeout, rootdir);
  1026. DEBUGFS_ADD(fw_stats_raw, rootdir);
  1027. DEBUGFS_ADD(sleep_auth, rootdir);
  1028. streaming = debugfs_create_dir("rx_streaming", rootdir);
  1029. if (!streaming || IS_ERR(streaming))
  1030. goto err;
  1031. DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
  1032. DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
  1033. DEBUGFS_ADD_PREFIX(dev, mem, rootdir);
  1034. return 0;
  1035. err:
  1036. if (IS_ERR(entry))
  1037. ret = PTR_ERR(entry);
  1038. else
  1039. ret = -ENOMEM;
  1040. return ret;
  1041. }
  1042. void wl1271_debugfs_reset(struct wl1271 *wl)
  1043. {
  1044. if (!wl->stats.fw_stats)
  1045. return;
  1046. memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
  1047. wl->stats.retry_count = 0;
  1048. wl->stats.excessive_retries = 0;
  1049. }
  1050. int wl1271_debugfs_init(struct wl1271 *wl)
  1051. {
  1052. int ret;
  1053. struct dentry *rootdir;
  1054. rootdir = debugfs_create_dir(KBUILD_MODNAME,
  1055. wl->hw->wiphy->debugfsdir);
  1056. if (IS_ERR(rootdir)) {
  1057. ret = PTR_ERR(rootdir);
  1058. goto out;
  1059. }
  1060. wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
  1061. if (!wl->stats.fw_stats) {
  1062. ret = -ENOMEM;
  1063. goto out_remove;
  1064. }
  1065. wl->stats.fw_stats_update = jiffies;
  1066. ret = wl1271_debugfs_add_files(wl, rootdir);
  1067. if (ret < 0)
  1068. goto out_exit;
  1069. ret = wlcore_debugfs_init(wl, rootdir);
  1070. if (ret < 0)
  1071. goto out_exit;
  1072. goto out;
  1073. out_exit:
  1074. wl1271_debugfs_exit(wl);
  1075. out_remove:
  1076. debugfs_remove_recursive(rootdir);
  1077. out:
  1078. return ret;
  1079. }
  1080. void wl1271_debugfs_exit(struct wl1271 *wl)
  1081. {
  1082. kfree(wl->stats.fw_stats);
  1083. wl->stats.fw_stats = NULL;
  1084. }