debugfs.c 21 KB

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