debugfs.c 21 KB

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