debugfs.c 22 KB

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