debugfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * Marvell Wireless LAN device driver: debugfs
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include <linux/debugfs.h>
  20. #include "main.h"
  21. #include "11n.h"
  22. static struct dentry *mwifiex_dfs_dir;
  23. static char *bss_modes[] = {
  24. "Unknown",
  25. "Ad-hoc",
  26. "Managed",
  27. "Auto"
  28. };
  29. /* size/addr for mwifiex_debug_info */
  30. #define item_size(n) (FIELD_SIZEOF(struct mwifiex_debug_info, n))
  31. #define item_addr(n) (offsetof(struct mwifiex_debug_info, n))
  32. /* size/addr for struct mwifiex_adapter */
  33. #define adapter_item_size(n) (FIELD_SIZEOF(struct mwifiex_adapter, n))
  34. #define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n))
  35. struct mwifiex_debug_data {
  36. char name[32]; /* variable/array name */
  37. u32 size; /* size of the variable/array */
  38. size_t addr; /* address of the variable/array */
  39. int num; /* number of variables in an array */
  40. };
  41. static struct mwifiex_debug_data items[] = {
  42. {"int_counter", item_size(int_counter),
  43. item_addr(int_counter), 1},
  44. {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]),
  45. item_addr(packets_out[WMM_AC_VO]), 1},
  46. {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]),
  47. item_addr(packets_out[WMM_AC_VI]), 1},
  48. {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]),
  49. item_addr(packets_out[WMM_AC_BE]), 1},
  50. {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
  51. item_addr(packets_out[WMM_AC_BK]), 1},
  52. {"max_tx_buf_size", item_size(max_tx_buf_size),
  53. item_addr(max_tx_buf_size), 1},
  54. {"tx_buf_size", item_size(tx_buf_size),
  55. item_addr(tx_buf_size), 1},
  56. {"curr_tx_buf_size", item_size(curr_tx_buf_size),
  57. item_addr(curr_tx_buf_size), 1},
  58. {"ps_mode", item_size(ps_mode),
  59. item_addr(ps_mode), 1},
  60. {"ps_state", item_size(ps_state),
  61. item_addr(ps_state), 1},
  62. {"is_deep_sleep", item_size(is_deep_sleep),
  63. item_addr(is_deep_sleep), 1},
  64. {"wakeup_dev_req", item_size(pm_wakeup_card_req),
  65. item_addr(pm_wakeup_card_req), 1},
  66. {"wakeup_tries", item_size(pm_wakeup_fw_try),
  67. item_addr(pm_wakeup_fw_try), 1},
  68. {"hs_configured", item_size(is_hs_configured),
  69. item_addr(is_hs_configured), 1},
  70. {"hs_activated", item_size(hs_activated),
  71. item_addr(hs_activated), 1},
  72. {"num_tx_timeout", item_size(num_tx_timeout),
  73. item_addr(num_tx_timeout), 1},
  74. {"num_cmd_timeout", item_size(num_cmd_timeout),
  75. item_addr(num_cmd_timeout), 1},
  76. {"timeout_cmd_id", item_size(timeout_cmd_id),
  77. item_addr(timeout_cmd_id), 1},
  78. {"timeout_cmd_act", item_size(timeout_cmd_act),
  79. item_addr(timeout_cmd_act), 1},
  80. {"last_cmd_id", item_size(last_cmd_id),
  81. item_addr(last_cmd_id), DBG_CMD_NUM},
  82. {"last_cmd_act", item_size(last_cmd_act),
  83. item_addr(last_cmd_act), DBG_CMD_NUM},
  84. {"last_cmd_index", item_size(last_cmd_index),
  85. item_addr(last_cmd_index), 1},
  86. {"last_cmd_resp_id", item_size(last_cmd_resp_id),
  87. item_addr(last_cmd_resp_id), DBG_CMD_NUM},
  88. {"last_cmd_resp_index", item_size(last_cmd_resp_index),
  89. item_addr(last_cmd_resp_index), 1},
  90. {"last_event", item_size(last_event),
  91. item_addr(last_event), DBG_CMD_NUM},
  92. {"last_event_index", item_size(last_event_index),
  93. item_addr(last_event_index), 1},
  94. {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
  95. item_addr(num_cmd_host_to_card_failure), 1},
  96. {"num_cmd_sleep_cfm_fail",
  97. item_size(num_cmd_sleep_cfm_host_to_card_failure),
  98. item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
  99. {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
  100. item_addr(num_tx_host_to_card_failure), 1},
  101. {"num_evt_deauth", item_size(num_event_deauth),
  102. item_addr(num_event_deauth), 1},
  103. {"num_evt_disassoc", item_size(num_event_disassoc),
  104. item_addr(num_event_disassoc), 1},
  105. {"num_evt_link_lost", item_size(num_event_link_lost),
  106. item_addr(num_event_link_lost), 1},
  107. {"num_cmd_deauth", item_size(num_cmd_deauth),
  108. item_addr(num_cmd_deauth), 1},
  109. {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
  110. item_addr(num_cmd_assoc_success), 1},
  111. {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
  112. item_addr(num_cmd_assoc_failure), 1},
  113. {"cmd_sent", item_size(cmd_sent),
  114. item_addr(cmd_sent), 1},
  115. {"data_sent", item_size(data_sent),
  116. item_addr(data_sent), 1},
  117. {"cmd_resp_received", item_size(cmd_resp_received),
  118. item_addr(cmd_resp_received), 1},
  119. {"event_received", item_size(event_received),
  120. item_addr(event_received), 1},
  121. /* variables defined in struct mwifiex_adapter */
  122. {"cmd_pending", adapter_item_size(cmd_pending),
  123. adapter_item_addr(cmd_pending), 1},
  124. {"tx_pending", adapter_item_size(tx_pending),
  125. adapter_item_addr(tx_pending), 1},
  126. {"rx_pending", adapter_item_size(rx_pending),
  127. adapter_item_addr(rx_pending), 1},
  128. };
  129. static int num_of_items = ARRAY_SIZE(items);
  130. /*
  131. * Generic proc file open handler.
  132. *
  133. * This function is called every time a file is accessed for read or write.
  134. */
  135. static int
  136. mwifiex_open_generic(struct inode *inode, struct file *file)
  137. {
  138. file->private_data = inode->i_private;
  139. return 0;
  140. }
  141. /*
  142. * Proc info file read handler.
  143. *
  144. * This function is called when the 'info' file is opened for reading.
  145. * It prints the following driver related information -
  146. * - Driver name
  147. * - Driver version
  148. * - Driver extended version
  149. * - Interface name
  150. * - BSS mode
  151. * - Media state (connected or disconnected)
  152. * - MAC address
  153. * - Total number of Tx bytes
  154. * - Total number of Rx bytes
  155. * - Total number of Tx packets
  156. * - Total number of Rx packets
  157. * - Total number of dropped Tx packets
  158. * - Total number of dropped Rx packets
  159. * - Total number of corrupted Tx packets
  160. * - Total number of corrupted Rx packets
  161. * - Carrier status (on or off)
  162. * - Tx queue status (started or stopped)
  163. *
  164. * For STA mode drivers, it also prints the following extra -
  165. * - ESSID
  166. * - BSSID
  167. * - Channel
  168. * - Region code
  169. * - Multicast count
  170. * - Multicast addresses
  171. */
  172. static ssize_t
  173. mwifiex_info_read(struct file *file, char __user *ubuf,
  174. size_t count, loff_t *ppos)
  175. {
  176. struct mwifiex_private *priv =
  177. (struct mwifiex_private *) file->private_data;
  178. struct net_device *netdev = priv->netdev;
  179. struct netdev_hw_addr *ha;
  180. unsigned long page = get_zeroed_page(GFP_KERNEL);
  181. char *p = (char *) page, fmt[64];
  182. struct mwifiex_bss_info info;
  183. ssize_t ret;
  184. int i = 0;
  185. if (!p)
  186. return -ENOMEM;
  187. memset(&info, 0, sizeof(info));
  188. ret = mwifiex_get_bss_info(priv, &info);
  189. if (ret)
  190. goto free_and_exit;
  191. mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
  192. if (!priv->version_str[0])
  193. mwifiex_get_ver_ext(priv);
  194. p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
  195. p += sprintf(p, "driver_version = %s", fmt);
  196. p += sprintf(p, "\nverext = %s", priv->version_str);
  197. p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
  198. p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
  199. p += sprintf(p, "media_state=\"%s\"\n",
  200. (!priv->media_connected ? "Disconnected" : "Connected"));
  201. p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
  202. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
  203. p += sprintf(p, "multicast_count=\"%d\"\n",
  204. netdev_mc_count(netdev));
  205. p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
  206. p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
  207. p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
  208. p += sprintf(p, "region_code = \"%02x\"\n", info.region_code);
  209. netdev_for_each_mc_addr(ha, netdev)
  210. p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
  211. i++, ha->addr);
  212. }
  213. p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
  214. p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
  215. p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
  216. p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
  217. p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
  218. p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
  219. p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
  220. p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
  221. p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
  222. ? "on" : "off"));
  223. p += sprintf(p, "tx queue %s\n", ((netif_queue_stopped(priv->netdev))
  224. ? "stopped" : "started"));
  225. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  226. (unsigned long) p - page);
  227. free_and_exit:
  228. free_page(page);
  229. return ret;
  230. }
  231. /*
  232. * Proc getlog file read handler.
  233. *
  234. * This function is called when the 'getlog' file is opened for reading
  235. * It prints the following log information -
  236. * - Number of multicast Tx frames
  237. * - Number of failed packets
  238. * - Number of Tx retries
  239. * - Number of multicast Tx retries
  240. * - Number of duplicate frames
  241. * - Number of RTS successes
  242. * - Number of RTS failures
  243. * - Number of ACK failures
  244. * - Number of fragmented Rx frames
  245. * - Number of multicast Rx frames
  246. * - Number of FCS errors
  247. * - Number of Tx frames
  248. * - WEP ICV error counts
  249. */
  250. static ssize_t
  251. mwifiex_getlog_read(struct file *file, char __user *ubuf,
  252. size_t count, loff_t *ppos)
  253. {
  254. struct mwifiex_private *priv =
  255. (struct mwifiex_private *) file->private_data;
  256. unsigned long page = get_zeroed_page(GFP_KERNEL);
  257. char *p = (char *) page;
  258. ssize_t ret;
  259. struct mwifiex_ds_get_stats stats;
  260. if (!p)
  261. return -ENOMEM;
  262. memset(&stats, 0, sizeof(stats));
  263. ret = mwifiex_get_stats_info(priv, &stats);
  264. if (ret)
  265. goto free_and_exit;
  266. p += sprintf(p, "\n"
  267. "mcasttxframe %u\n"
  268. "failed %u\n"
  269. "retry %u\n"
  270. "multiretry %u\n"
  271. "framedup %u\n"
  272. "rtssuccess %u\n"
  273. "rtsfailure %u\n"
  274. "ackfailure %u\n"
  275. "rxfrag %u\n"
  276. "mcastrxframe %u\n"
  277. "fcserror %u\n"
  278. "txframe %u\n"
  279. "wepicverrcnt-1 %u\n"
  280. "wepicverrcnt-2 %u\n"
  281. "wepicverrcnt-3 %u\n"
  282. "wepicverrcnt-4 %u\n",
  283. stats.mcast_tx_frame,
  284. stats.failed,
  285. stats.retry,
  286. stats.multi_retry,
  287. stats.frame_dup,
  288. stats.rts_success,
  289. stats.rts_failure,
  290. stats.ack_failure,
  291. stats.rx_frag,
  292. stats.mcast_rx_frame,
  293. stats.fcs_error,
  294. stats.tx_frame,
  295. stats.wep_icv_error[0],
  296. stats.wep_icv_error[1],
  297. stats.wep_icv_error[2],
  298. stats.wep_icv_error[3]);
  299. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  300. (unsigned long) p - page);
  301. free_and_exit:
  302. free_page(page);
  303. return ret;
  304. }
  305. static struct mwifiex_debug_info info;
  306. /*
  307. * Proc debug file read handler.
  308. *
  309. * This function is called when the 'debug' file is opened for reading
  310. * It prints the following log information -
  311. * - Interrupt count
  312. * - WMM AC VO packets count
  313. * - WMM AC VI packets count
  314. * - WMM AC BE packets count
  315. * - WMM AC BK packets count
  316. * - Maximum Tx buffer size
  317. * - Tx buffer size
  318. * - Current Tx buffer size
  319. * - Power Save mode
  320. * - Power Save state
  321. * - Deep Sleep status
  322. * - Device wakeup required status
  323. * - Number of wakeup tries
  324. * - Host Sleep configured status
  325. * - Host Sleep activated status
  326. * - Number of Tx timeouts
  327. * - Number of command timeouts
  328. * - Last timed out command ID
  329. * - Last timed out command action
  330. * - Last command ID
  331. * - Last command action
  332. * - Last command index
  333. * - Last command response ID
  334. * - Last command response index
  335. * - Last event
  336. * - Last event index
  337. * - Number of host to card command failures
  338. * - Number of sleep confirm command failures
  339. * - Number of host to card data failure
  340. * - Number of deauthentication events
  341. * - Number of disassociation events
  342. * - Number of link lost events
  343. * - Number of deauthentication commands
  344. * - Number of association success commands
  345. * - Number of association failure commands
  346. * - Number of commands sent
  347. * - Number of data packets sent
  348. * - Number of command responses received
  349. * - Number of events received
  350. * - Tx BA stream table (TID, RA)
  351. * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
  352. */
  353. static ssize_t
  354. mwifiex_debug_read(struct file *file, char __user *ubuf,
  355. size_t count, loff_t *ppos)
  356. {
  357. struct mwifiex_private *priv =
  358. (struct mwifiex_private *) file->private_data;
  359. struct mwifiex_debug_data *d = &items[0];
  360. unsigned long page = get_zeroed_page(GFP_KERNEL);
  361. char *p = (char *) page;
  362. ssize_t ret;
  363. size_t size, addr;
  364. long val;
  365. int i, j;
  366. if (!p)
  367. return -ENOMEM;
  368. ret = mwifiex_get_debug_info(priv, &info);
  369. if (ret)
  370. goto free_and_exit;
  371. for (i = 0; i < num_of_items; i++) {
  372. p += sprintf(p, "%s=", d[i].name);
  373. size = d[i].size / d[i].num;
  374. if (i < (num_of_items - 3))
  375. addr = d[i].addr + (size_t) &info;
  376. else /* The last 3 items are struct mwifiex_adapter variables */
  377. addr = d[i].addr + (size_t) priv->adapter;
  378. for (j = 0; j < d[i].num; j++) {
  379. switch (size) {
  380. case 1:
  381. val = *((u8 *) addr);
  382. break;
  383. case 2:
  384. val = *((u16 *) addr);
  385. break;
  386. case 4:
  387. val = *((u32 *) addr);
  388. break;
  389. case 8:
  390. val = *((long long *) addr);
  391. break;
  392. default:
  393. val = -1;
  394. break;
  395. }
  396. p += sprintf(p, "%#lx ", val);
  397. addr += size;
  398. }
  399. p += sprintf(p, "\n");
  400. }
  401. if (info.tx_tbl_num) {
  402. p += sprintf(p, "Tx BA stream table:\n");
  403. for (i = 0; i < info.tx_tbl_num; i++)
  404. p += sprintf(p, "tid = %d, ra = %pM\n",
  405. info.tx_tbl[i].tid, info.tx_tbl[i].ra);
  406. }
  407. if (info.rx_tbl_num) {
  408. p += sprintf(p, "Rx reorder table:\n");
  409. for (i = 0; i < info.rx_tbl_num; i++) {
  410. p += sprintf(p, "tid = %d, ta = %pM, "
  411. "start_win = %d, "
  412. "win_size = %d, buffer: ",
  413. info.rx_tbl[i].tid,
  414. info.rx_tbl[i].ta,
  415. info.rx_tbl[i].start_win,
  416. info.rx_tbl[i].win_size);
  417. for (j = 0; j < info.rx_tbl[i].win_size; j++)
  418. p += sprintf(p, "%c ",
  419. info.rx_tbl[i].buffer[j] ?
  420. '1' : '0');
  421. p += sprintf(p, "\n");
  422. }
  423. }
  424. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  425. (unsigned long) p - page);
  426. free_and_exit:
  427. free_page(page);
  428. return ret;
  429. }
  430. static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
  431. /*
  432. * Proc regrdwr file write handler.
  433. *
  434. * This function is called when the 'regrdwr' file is opened for writing
  435. *
  436. * This function can be used to write to a register.
  437. */
  438. static ssize_t
  439. mwifiex_regrdwr_write(struct file *file,
  440. const char __user *ubuf, size_t count, loff_t *ppos)
  441. {
  442. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  443. char *buf = (char *) addr;
  444. size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
  445. int ret;
  446. u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
  447. if (!buf)
  448. return -ENOMEM;
  449. if (copy_from_user(buf, ubuf, buf_size)) {
  450. ret = -EFAULT;
  451. goto done;
  452. }
  453. sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
  454. if (reg_type == 0 || reg_offset == 0) {
  455. ret = -EINVAL;
  456. goto done;
  457. } else {
  458. saved_reg_type = reg_type;
  459. saved_reg_offset = reg_offset;
  460. saved_reg_value = reg_value;
  461. ret = count;
  462. }
  463. done:
  464. free_page(addr);
  465. return ret;
  466. }
  467. /*
  468. * Proc regrdwr file read handler.
  469. *
  470. * This function is called when the 'regrdwr' file is opened for reading
  471. *
  472. * This function can be used to read from a register.
  473. */
  474. static ssize_t
  475. mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
  476. size_t count, loff_t *ppos)
  477. {
  478. struct mwifiex_private *priv =
  479. (struct mwifiex_private *) file->private_data;
  480. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  481. char *buf = (char *) addr;
  482. int pos = 0, ret = 0;
  483. u32 reg_value;
  484. if (!buf)
  485. return -ENOMEM;
  486. if (!saved_reg_type) {
  487. /* No command has been given */
  488. pos += snprintf(buf, PAGE_SIZE, "0");
  489. goto done;
  490. }
  491. /* Set command has been given */
  492. if (saved_reg_value != UINT_MAX) {
  493. ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
  494. saved_reg_value);
  495. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
  496. saved_reg_type, saved_reg_offset,
  497. saved_reg_value);
  498. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  499. goto done;
  500. }
  501. /* Get command has been given */
  502. ret = mwifiex_reg_read(priv, saved_reg_type,
  503. saved_reg_offset, &reg_value);
  504. if (ret) {
  505. ret = -EINVAL;
  506. goto done;
  507. }
  508. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
  509. saved_reg_offset, reg_value);
  510. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  511. done:
  512. free_page(addr);
  513. return ret;
  514. }
  515. static u32 saved_offset = -1, saved_bytes = -1;
  516. /*
  517. * Proc rdeeprom file write handler.
  518. *
  519. * This function is called when the 'rdeeprom' file is opened for writing
  520. *
  521. * This function can be used to write to a RDEEPROM location.
  522. */
  523. static ssize_t
  524. mwifiex_rdeeprom_write(struct file *file,
  525. const char __user *ubuf, size_t count, loff_t *ppos)
  526. {
  527. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  528. char *buf = (char *) addr;
  529. size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
  530. int ret = 0;
  531. int offset = -1, bytes = -1;
  532. if (!buf)
  533. return -ENOMEM;
  534. if (copy_from_user(buf, ubuf, buf_size)) {
  535. ret = -EFAULT;
  536. goto done;
  537. }
  538. sscanf(buf, "%d %d", &offset, &bytes);
  539. if (offset == -1 || bytes == -1) {
  540. ret = -EINVAL;
  541. goto done;
  542. } else {
  543. saved_offset = offset;
  544. saved_bytes = bytes;
  545. ret = count;
  546. }
  547. done:
  548. free_page(addr);
  549. return ret;
  550. }
  551. /*
  552. * Proc rdeeprom read write handler.
  553. *
  554. * This function is called when the 'rdeeprom' file is opened for reading
  555. *
  556. * This function can be used to read from a RDEEPROM location.
  557. */
  558. static ssize_t
  559. mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
  560. size_t count, loff_t *ppos)
  561. {
  562. struct mwifiex_private *priv =
  563. (struct mwifiex_private *) file->private_data;
  564. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  565. char *buf = (char *) addr;
  566. int pos = 0, ret = 0, i;
  567. u8 value[MAX_EEPROM_DATA];
  568. if (!buf)
  569. return -ENOMEM;
  570. if (saved_offset == -1) {
  571. /* No command has been given */
  572. pos += snprintf(buf, PAGE_SIZE, "0");
  573. goto done;
  574. }
  575. /* Get command has been given */
  576. ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
  577. (u16) saved_bytes, value);
  578. if (ret) {
  579. ret = -EINVAL;
  580. goto done;
  581. }
  582. pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
  583. for (i = 0; i < saved_bytes; i++)
  584. pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
  585. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  586. done:
  587. free_page(addr);
  588. return ret;
  589. }
  590. #define MWIFIEX_DFS_ADD_FILE(name) do { \
  591. if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
  592. priv, &mwifiex_dfs_##name##_fops)) \
  593. return; \
  594. } while (0);
  595. #define MWIFIEX_DFS_FILE_OPS(name) \
  596. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  597. .read = mwifiex_##name##_read, \
  598. .write = mwifiex_##name##_write, \
  599. .open = mwifiex_open_generic, \
  600. };
  601. #define MWIFIEX_DFS_FILE_READ_OPS(name) \
  602. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  603. .read = mwifiex_##name##_read, \
  604. .open = mwifiex_open_generic, \
  605. };
  606. #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
  607. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  608. .write = mwifiex_##name##_write, \
  609. .open = mwifiex_open_generic, \
  610. };
  611. MWIFIEX_DFS_FILE_READ_OPS(info);
  612. MWIFIEX_DFS_FILE_READ_OPS(debug);
  613. MWIFIEX_DFS_FILE_READ_OPS(getlog);
  614. MWIFIEX_DFS_FILE_OPS(regrdwr);
  615. MWIFIEX_DFS_FILE_OPS(rdeeprom);
  616. /*
  617. * This function creates the debug FS directory structure and the files.
  618. */
  619. void
  620. mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
  621. {
  622. if (!mwifiex_dfs_dir || !priv)
  623. return;
  624. priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
  625. mwifiex_dfs_dir);
  626. if (!priv->dfs_dev_dir)
  627. return;
  628. MWIFIEX_DFS_ADD_FILE(info);
  629. MWIFIEX_DFS_ADD_FILE(debug);
  630. MWIFIEX_DFS_ADD_FILE(getlog);
  631. MWIFIEX_DFS_ADD_FILE(regrdwr);
  632. MWIFIEX_DFS_ADD_FILE(rdeeprom);
  633. }
  634. /*
  635. * This function removes the debug FS directory structure and the files.
  636. */
  637. void
  638. mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
  639. {
  640. if (!priv)
  641. return;
  642. debugfs_remove_recursive(priv->dfs_dev_dir);
  643. }
  644. /*
  645. * This function creates the top level proc directory.
  646. */
  647. void
  648. mwifiex_debugfs_init(void)
  649. {
  650. if (!mwifiex_dfs_dir)
  651. mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
  652. }
  653. /*
  654. * This function removes the top level proc directory.
  655. */
  656. void
  657. mwifiex_debugfs_remove(void)
  658. {
  659. if (mwifiex_dfs_dir)
  660. debugfs_remove(mwifiex_dfs_dir);
  661. }