debugfs.c 21 KB

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