debugfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. * Proc info file read handler.
  132. *
  133. * This function is called when the 'info' file is opened for reading.
  134. * It prints the following driver related information -
  135. * - Driver name
  136. * - Driver version
  137. * - Driver extended version
  138. * - Interface name
  139. * - BSS mode
  140. * - Media state (connected or disconnected)
  141. * - MAC address
  142. * - Total number of Tx bytes
  143. * - Total number of Rx bytes
  144. * - Total number of Tx packets
  145. * - Total number of Rx packets
  146. * - Total number of dropped Tx packets
  147. * - Total number of dropped Rx packets
  148. * - Total number of corrupted Tx packets
  149. * - Total number of corrupted Rx packets
  150. * - Carrier status (on or off)
  151. * - Tx queue status (started or stopped)
  152. *
  153. * For STA mode drivers, it also prints the following extra -
  154. * - ESSID
  155. * - BSSID
  156. * - Channel
  157. * - Region code
  158. * - Multicast count
  159. * - Multicast addresses
  160. */
  161. static ssize_t
  162. mwifiex_info_read(struct file *file, char __user *ubuf,
  163. size_t count, loff_t *ppos)
  164. {
  165. struct mwifiex_private *priv =
  166. (struct mwifiex_private *) file->private_data;
  167. struct net_device *netdev = priv->netdev;
  168. struct netdev_hw_addr *ha;
  169. struct netdev_queue *txq;
  170. unsigned long page = get_zeroed_page(GFP_KERNEL);
  171. char *p = (char *) page, fmt[64];
  172. struct mwifiex_bss_info info;
  173. ssize_t ret;
  174. int i = 0;
  175. if (!p)
  176. return -ENOMEM;
  177. memset(&info, 0, sizeof(info));
  178. ret = mwifiex_get_bss_info(priv, &info);
  179. if (ret)
  180. goto free_and_exit;
  181. mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
  182. if (!priv->version_str[0])
  183. mwifiex_get_ver_ext(priv);
  184. p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
  185. p += sprintf(p, "driver_version = %s", fmt);
  186. p += sprintf(p, "\nverext = %s", priv->version_str);
  187. p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
  188. p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
  189. p += sprintf(p, "media_state=\"%s\"\n",
  190. (!priv->media_connected ? "Disconnected" : "Connected"));
  191. p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
  192. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
  193. p += sprintf(p, "multicast_count=\"%d\"\n",
  194. netdev_mc_count(netdev));
  195. p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
  196. p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
  197. p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
  198. p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
  199. netdev_for_each_mc_addr(ha, netdev)
  200. p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
  201. i++, ha->addr);
  202. }
  203. p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
  204. p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
  205. p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
  206. p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
  207. p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
  208. p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
  209. p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
  210. p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
  211. p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
  212. ? "on" : "off"));
  213. p += sprintf(p, "tx queue");
  214. for (i = 0; i < netdev->num_tx_queues; i++) {
  215. txq = netdev_get_tx_queue(netdev, i);
  216. p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
  217. "stopped" : "started");
  218. }
  219. p += sprintf(p, "\n");
  220. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  221. (unsigned long) p - page);
  222. free_and_exit:
  223. free_page(page);
  224. return ret;
  225. }
  226. /*
  227. * Proc getlog file read handler.
  228. *
  229. * This function is called when the 'getlog' file is opened for reading
  230. * It prints the following log information -
  231. * - Number of multicast Tx frames
  232. * - Number of failed packets
  233. * - Number of Tx retries
  234. * - Number of multicast Tx retries
  235. * - Number of duplicate frames
  236. * - Number of RTS successes
  237. * - Number of RTS failures
  238. * - Number of ACK failures
  239. * - Number of fragmented Rx frames
  240. * - Number of multicast Rx frames
  241. * - Number of FCS errors
  242. * - Number of Tx frames
  243. * - WEP ICV error counts
  244. */
  245. static ssize_t
  246. mwifiex_getlog_read(struct file *file, char __user *ubuf,
  247. size_t count, loff_t *ppos)
  248. {
  249. struct mwifiex_private *priv =
  250. (struct mwifiex_private *) file->private_data;
  251. unsigned long page = get_zeroed_page(GFP_KERNEL);
  252. char *p = (char *) page;
  253. ssize_t ret;
  254. struct mwifiex_ds_get_stats stats;
  255. if (!p)
  256. return -ENOMEM;
  257. memset(&stats, 0, sizeof(stats));
  258. ret = mwifiex_get_stats_info(priv, &stats);
  259. if (ret)
  260. goto free_and_exit;
  261. p += sprintf(p, "\n"
  262. "mcasttxframe %u\n"
  263. "failed %u\n"
  264. "retry %u\n"
  265. "multiretry %u\n"
  266. "framedup %u\n"
  267. "rtssuccess %u\n"
  268. "rtsfailure %u\n"
  269. "ackfailure %u\n"
  270. "rxfrag %u\n"
  271. "mcastrxframe %u\n"
  272. "fcserror %u\n"
  273. "txframe %u\n"
  274. "wepicverrcnt-1 %u\n"
  275. "wepicverrcnt-2 %u\n"
  276. "wepicverrcnt-3 %u\n"
  277. "wepicverrcnt-4 %u\n",
  278. stats.mcast_tx_frame,
  279. stats.failed,
  280. stats.retry,
  281. stats.multi_retry,
  282. stats.frame_dup,
  283. stats.rts_success,
  284. stats.rts_failure,
  285. stats.ack_failure,
  286. stats.rx_frag,
  287. stats.mcast_rx_frame,
  288. stats.fcs_error,
  289. stats.tx_frame,
  290. stats.wep_icv_error[0],
  291. stats.wep_icv_error[1],
  292. stats.wep_icv_error[2],
  293. stats.wep_icv_error[3]);
  294. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  295. (unsigned long) p - page);
  296. free_and_exit:
  297. free_page(page);
  298. return ret;
  299. }
  300. static struct mwifiex_debug_info info;
  301. /*
  302. * Proc debug file read handler.
  303. *
  304. * This function is called when the 'debug' file is opened for reading
  305. * It prints the following log information -
  306. * - Interrupt count
  307. * - WMM AC VO packets count
  308. * - WMM AC VI packets count
  309. * - WMM AC BE packets count
  310. * - WMM AC BK packets count
  311. * - Maximum Tx buffer size
  312. * - Tx buffer size
  313. * - Current Tx buffer size
  314. * - Power Save mode
  315. * - Power Save state
  316. * - Deep Sleep status
  317. * - Device wakeup required status
  318. * - Number of wakeup tries
  319. * - Host Sleep configured status
  320. * - Host Sleep activated status
  321. * - Number of Tx timeouts
  322. * - Number of command timeouts
  323. * - Last timed out command ID
  324. * - Last timed out command action
  325. * - Last command ID
  326. * - Last command action
  327. * - Last command index
  328. * - Last command response ID
  329. * - Last command response index
  330. * - Last event
  331. * - Last event index
  332. * - Number of host to card command failures
  333. * - Number of sleep confirm command failures
  334. * - Number of host to card data failure
  335. * - Number of deauthentication events
  336. * - Number of disassociation events
  337. * - Number of link lost events
  338. * - Number of deauthentication commands
  339. * - Number of association success commands
  340. * - Number of association failure commands
  341. * - Number of commands sent
  342. * - Number of data packets sent
  343. * - Number of command responses received
  344. * - Number of events received
  345. * - Tx BA stream table (TID, RA)
  346. * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
  347. */
  348. static ssize_t
  349. mwifiex_debug_read(struct file *file, char __user *ubuf,
  350. size_t count, loff_t *ppos)
  351. {
  352. struct mwifiex_private *priv =
  353. (struct mwifiex_private *) file->private_data;
  354. struct mwifiex_debug_data *d = &items[0];
  355. unsigned long page = get_zeroed_page(GFP_KERNEL);
  356. char *p = (char *) page;
  357. ssize_t ret;
  358. size_t size, addr;
  359. long val;
  360. int i, j;
  361. if (!p)
  362. return -ENOMEM;
  363. ret = mwifiex_get_debug_info(priv, &info);
  364. if (ret)
  365. goto free_and_exit;
  366. for (i = 0; i < num_of_items; i++) {
  367. p += sprintf(p, "%s=", d[i].name);
  368. size = d[i].size / d[i].num;
  369. if (i < (num_of_items - 3))
  370. addr = d[i].addr + (size_t) &info;
  371. else /* The last 3 items are struct mwifiex_adapter variables */
  372. addr = d[i].addr + (size_t) priv->adapter;
  373. for (j = 0; j < d[i].num; j++) {
  374. switch (size) {
  375. case 1:
  376. val = *((u8 *) addr);
  377. break;
  378. case 2:
  379. val = *((u16 *) addr);
  380. break;
  381. case 4:
  382. val = *((u32 *) addr);
  383. break;
  384. case 8:
  385. val = *((long long *) addr);
  386. break;
  387. default:
  388. val = -1;
  389. break;
  390. }
  391. p += sprintf(p, "%#lx ", val);
  392. addr += size;
  393. }
  394. p += sprintf(p, "\n");
  395. }
  396. if (info.tx_tbl_num) {
  397. p += sprintf(p, "Tx BA stream table:\n");
  398. for (i = 0; i < info.tx_tbl_num; i++)
  399. p += sprintf(p, "tid = %d, ra = %pM\n",
  400. info.tx_tbl[i].tid, info.tx_tbl[i].ra);
  401. }
  402. if (info.rx_tbl_num) {
  403. p += sprintf(p, "Rx reorder table:\n");
  404. for (i = 0; i < info.rx_tbl_num; i++) {
  405. p += sprintf(p, "tid = %d, ta = %pM, "
  406. "start_win = %d, "
  407. "win_size = %d, buffer: ",
  408. info.rx_tbl[i].tid,
  409. info.rx_tbl[i].ta,
  410. info.rx_tbl[i].start_win,
  411. info.rx_tbl[i].win_size);
  412. for (j = 0; j < info.rx_tbl[i].win_size; j++)
  413. p += sprintf(p, "%c ",
  414. info.rx_tbl[i].buffer[j] ?
  415. '1' : '0');
  416. p += sprintf(p, "\n");
  417. }
  418. }
  419. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  420. (unsigned long) p - page);
  421. free_and_exit:
  422. free_page(page);
  423. return ret;
  424. }
  425. static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
  426. /*
  427. * Proc regrdwr file write handler.
  428. *
  429. * This function is called when the 'regrdwr' file is opened for writing
  430. *
  431. * This function can be used to write to a register.
  432. */
  433. static ssize_t
  434. mwifiex_regrdwr_write(struct file *file,
  435. const char __user *ubuf, size_t count, loff_t *ppos)
  436. {
  437. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  438. char *buf = (char *) addr;
  439. size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
  440. int ret;
  441. u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
  442. if (!buf)
  443. return -ENOMEM;
  444. if (copy_from_user(buf, ubuf, buf_size)) {
  445. ret = -EFAULT;
  446. goto done;
  447. }
  448. sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
  449. if (reg_type == 0 || reg_offset == 0) {
  450. ret = -EINVAL;
  451. goto done;
  452. } else {
  453. saved_reg_type = reg_type;
  454. saved_reg_offset = reg_offset;
  455. saved_reg_value = reg_value;
  456. ret = count;
  457. }
  458. done:
  459. free_page(addr);
  460. return ret;
  461. }
  462. /*
  463. * Proc regrdwr file read handler.
  464. *
  465. * This function is called when the 'regrdwr' file is opened for reading
  466. *
  467. * This function can be used to read from a register.
  468. */
  469. static ssize_t
  470. mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
  471. size_t count, loff_t *ppos)
  472. {
  473. struct mwifiex_private *priv =
  474. (struct mwifiex_private *) file->private_data;
  475. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  476. char *buf = (char *) addr;
  477. int pos = 0, ret = 0;
  478. u32 reg_value;
  479. if (!buf)
  480. return -ENOMEM;
  481. if (!saved_reg_type) {
  482. /* No command has been given */
  483. pos += snprintf(buf, PAGE_SIZE, "0");
  484. goto done;
  485. }
  486. /* Set command has been given */
  487. if (saved_reg_value != UINT_MAX) {
  488. ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
  489. saved_reg_value);
  490. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
  491. saved_reg_type, saved_reg_offset,
  492. saved_reg_value);
  493. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  494. goto done;
  495. }
  496. /* Get command has been given */
  497. ret = mwifiex_reg_read(priv, saved_reg_type,
  498. saved_reg_offset, &reg_value);
  499. if (ret) {
  500. ret = -EINVAL;
  501. goto done;
  502. }
  503. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
  504. saved_reg_offset, reg_value);
  505. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  506. done:
  507. free_page(addr);
  508. return ret;
  509. }
  510. static u32 saved_offset = -1, saved_bytes = -1;
  511. /*
  512. * Proc rdeeprom file write handler.
  513. *
  514. * This function is called when the 'rdeeprom' file is opened for writing
  515. *
  516. * This function can be used to write to a RDEEPROM location.
  517. */
  518. static ssize_t
  519. mwifiex_rdeeprom_write(struct file *file,
  520. const char __user *ubuf, size_t count, loff_t *ppos)
  521. {
  522. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  523. char *buf = (char *) addr;
  524. size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1));
  525. int ret = 0;
  526. int offset = -1, bytes = -1;
  527. if (!buf)
  528. return -ENOMEM;
  529. if (copy_from_user(buf, ubuf, buf_size)) {
  530. ret = -EFAULT;
  531. goto done;
  532. }
  533. sscanf(buf, "%d %d", &offset, &bytes);
  534. if (offset == -1 || bytes == -1) {
  535. ret = -EINVAL;
  536. goto done;
  537. } else {
  538. saved_offset = offset;
  539. saved_bytes = bytes;
  540. ret = count;
  541. }
  542. done:
  543. free_page(addr);
  544. return ret;
  545. }
  546. /*
  547. * Proc rdeeprom read write handler.
  548. *
  549. * This function is called when the 'rdeeprom' file is opened for reading
  550. *
  551. * This function can be used to read from a RDEEPROM location.
  552. */
  553. static ssize_t
  554. mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
  555. size_t count, loff_t *ppos)
  556. {
  557. struct mwifiex_private *priv =
  558. (struct mwifiex_private *) file->private_data;
  559. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  560. char *buf = (char *) addr;
  561. int pos = 0, ret = 0, i;
  562. u8 value[MAX_EEPROM_DATA];
  563. if (!buf)
  564. return -ENOMEM;
  565. if (saved_offset == -1) {
  566. /* No command has been given */
  567. pos += snprintf(buf, PAGE_SIZE, "0");
  568. goto done;
  569. }
  570. /* Get command has been given */
  571. ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
  572. (u16) saved_bytes, value);
  573. if (ret) {
  574. ret = -EINVAL;
  575. goto done;
  576. }
  577. pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
  578. for (i = 0; i < saved_bytes; i++)
  579. pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
  580. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  581. done:
  582. free_page(addr);
  583. return ret;
  584. }
  585. #define MWIFIEX_DFS_ADD_FILE(name) do { \
  586. if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
  587. priv, &mwifiex_dfs_##name##_fops)) \
  588. return; \
  589. } while (0);
  590. #define MWIFIEX_DFS_FILE_OPS(name) \
  591. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  592. .read = mwifiex_##name##_read, \
  593. .write = mwifiex_##name##_write, \
  594. .open = simple_open, \
  595. };
  596. #define MWIFIEX_DFS_FILE_READ_OPS(name) \
  597. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  598. .read = mwifiex_##name##_read, \
  599. .open = simple_open, \
  600. };
  601. #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
  602. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  603. .write = mwifiex_##name##_write, \
  604. .open = simple_open, \
  605. };
  606. MWIFIEX_DFS_FILE_READ_OPS(info);
  607. MWIFIEX_DFS_FILE_READ_OPS(debug);
  608. MWIFIEX_DFS_FILE_READ_OPS(getlog);
  609. MWIFIEX_DFS_FILE_OPS(regrdwr);
  610. MWIFIEX_DFS_FILE_OPS(rdeeprom);
  611. /*
  612. * This function creates the debug FS directory structure and the files.
  613. */
  614. void
  615. mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
  616. {
  617. if (!mwifiex_dfs_dir || !priv)
  618. return;
  619. priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
  620. mwifiex_dfs_dir);
  621. if (!priv->dfs_dev_dir)
  622. return;
  623. MWIFIEX_DFS_ADD_FILE(info);
  624. MWIFIEX_DFS_ADD_FILE(debug);
  625. MWIFIEX_DFS_ADD_FILE(getlog);
  626. MWIFIEX_DFS_ADD_FILE(regrdwr);
  627. MWIFIEX_DFS_ADD_FILE(rdeeprom);
  628. }
  629. /*
  630. * This function removes the debug FS directory structure and the files.
  631. */
  632. void
  633. mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
  634. {
  635. if (!priv)
  636. return;
  637. debugfs_remove_recursive(priv->dfs_dev_dir);
  638. }
  639. /*
  640. * This function creates the top level proc directory.
  641. */
  642. void
  643. mwifiex_debugfs_init(void)
  644. {
  645. if (!mwifiex_dfs_dir)
  646. mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
  647. }
  648. /*
  649. * This function removes the top level proc directory.
  650. */
  651. void
  652. mwifiex_debugfs_remove(void)
  653. {
  654. if (mwifiex_dfs_dir)
  655. debugfs_remove(mwifiex_dfs_dir);
  656. }