debugfs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. /*
  2. * Marvell Wireless LAN device driver: debugfs
  3. *
  4. * Copyright (C) 2011-2014, 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. {"is_cmd_timedout", item_size(is_cmd_timedout),
  80. item_addr(is_cmd_timedout), 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 firmware dump read handler.
  236. *
  237. * This function is called when the 'fw_dump' file is opened for
  238. * reading.
  239. * This function dumps firmware memory in different files
  240. * (ex. DTCM, ITCM, SQRAM etc.) based on the the segments for
  241. * debugging.
  242. */
  243. static ssize_t
  244. mwifiex_fw_dump_read(struct file *file, char __user *ubuf,
  245. size_t count, loff_t *ppos)
  246. {
  247. struct mwifiex_private *priv = file->private_data;
  248. if (!priv->adapter->if_ops.fw_dump)
  249. return -EIO;
  250. priv->adapter->if_ops.fw_dump(priv->adapter);
  251. return 0;
  252. }
  253. /*
  254. * Proc getlog file read handler.
  255. *
  256. * This function is called when the 'getlog' file is opened for reading
  257. * It prints the following log information -
  258. * - Number of multicast Tx frames
  259. * - Number of failed packets
  260. * - Number of Tx retries
  261. * - Number of multicast Tx retries
  262. * - Number of duplicate frames
  263. * - Number of RTS successes
  264. * - Number of RTS failures
  265. * - Number of ACK failures
  266. * - Number of fragmented Rx frames
  267. * - Number of multicast Rx frames
  268. * - Number of FCS errors
  269. * - Number of Tx frames
  270. * - WEP ICV error counts
  271. */
  272. static ssize_t
  273. mwifiex_getlog_read(struct file *file, char __user *ubuf,
  274. size_t count, loff_t *ppos)
  275. {
  276. struct mwifiex_private *priv =
  277. (struct mwifiex_private *) file->private_data;
  278. unsigned long page = get_zeroed_page(GFP_KERNEL);
  279. char *p = (char *) page;
  280. ssize_t ret;
  281. struct mwifiex_ds_get_stats stats;
  282. if (!p)
  283. return -ENOMEM;
  284. memset(&stats, 0, sizeof(stats));
  285. ret = mwifiex_get_stats_info(priv, &stats);
  286. if (ret)
  287. goto free_and_exit;
  288. p += sprintf(p, "\n"
  289. "mcasttxframe %u\n"
  290. "failed %u\n"
  291. "retry %u\n"
  292. "multiretry %u\n"
  293. "framedup %u\n"
  294. "rtssuccess %u\n"
  295. "rtsfailure %u\n"
  296. "ackfailure %u\n"
  297. "rxfrag %u\n"
  298. "mcastrxframe %u\n"
  299. "fcserror %u\n"
  300. "txframe %u\n"
  301. "wepicverrcnt-1 %u\n"
  302. "wepicverrcnt-2 %u\n"
  303. "wepicverrcnt-3 %u\n"
  304. "wepicverrcnt-4 %u\n",
  305. stats.mcast_tx_frame,
  306. stats.failed,
  307. stats.retry,
  308. stats.multi_retry,
  309. stats.frame_dup,
  310. stats.rts_success,
  311. stats.rts_failure,
  312. stats.ack_failure,
  313. stats.rx_frag,
  314. stats.mcast_rx_frame,
  315. stats.fcs_error,
  316. stats.tx_frame,
  317. stats.wep_icv_error[0],
  318. stats.wep_icv_error[1],
  319. stats.wep_icv_error[2],
  320. stats.wep_icv_error[3]);
  321. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  322. (unsigned long) p - page);
  323. free_and_exit:
  324. free_page(page);
  325. return ret;
  326. }
  327. static struct mwifiex_debug_info info;
  328. /*
  329. * Proc debug file read handler.
  330. *
  331. * This function is called when the 'debug' file is opened for reading
  332. * It prints the following log information -
  333. * - Interrupt count
  334. * - WMM AC VO packets count
  335. * - WMM AC VI packets count
  336. * - WMM AC BE packets count
  337. * - WMM AC BK packets count
  338. * - Maximum Tx buffer size
  339. * - Tx buffer size
  340. * - Current Tx buffer size
  341. * - Power Save mode
  342. * - Power Save state
  343. * - Deep Sleep status
  344. * - Device wakeup required status
  345. * - Number of wakeup tries
  346. * - Host Sleep configured status
  347. * - Host Sleep activated status
  348. * - Number of Tx timeouts
  349. * - Number of command timeouts
  350. * - Last timed out command ID
  351. * - Last timed out command action
  352. * - Last command ID
  353. * - Last command action
  354. * - Last command index
  355. * - Last command response ID
  356. * - Last command response index
  357. * - Last event
  358. * - Last event index
  359. * - Number of host to card command failures
  360. * - Number of sleep confirm command failures
  361. * - Number of host to card data failure
  362. * - Number of deauthentication events
  363. * - Number of disassociation events
  364. * - Number of link lost events
  365. * - Number of deauthentication commands
  366. * - Number of association success commands
  367. * - Number of association failure commands
  368. * - Number of commands sent
  369. * - Number of data packets sent
  370. * - Number of command responses received
  371. * - Number of events received
  372. * - Tx BA stream table (TID, RA)
  373. * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
  374. */
  375. static ssize_t
  376. mwifiex_debug_read(struct file *file, char __user *ubuf,
  377. size_t count, loff_t *ppos)
  378. {
  379. struct mwifiex_private *priv =
  380. (struct mwifiex_private *) file->private_data;
  381. struct mwifiex_debug_data *d = &items[0];
  382. unsigned long page = get_zeroed_page(GFP_KERNEL);
  383. char *p = (char *) page;
  384. ssize_t ret;
  385. size_t size, addr;
  386. long val;
  387. int i, j;
  388. if (!p)
  389. return -ENOMEM;
  390. ret = mwifiex_get_debug_info(priv, &info);
  391. if (ret)
  392. goto free_and_exit;
  393. for (i = 0; i < num_of_items; i++) {
  394. p += sprintf(p, "%s=", d[i].name);
  395. size = d[i].size / d[i].num;
  396. if (i < (num_of_items - 3))
  397. addr = d[i].addr + (size_t) &info;
  398. else /* The last 3 items are struct mwifiex_adapter variables */
  399. addr = d[i].addr + (size_t) priv->adapter;
  400. for (j = 0; j < d[i].num; j++) {
  401. switch (size) {
  402. case 1:
  403. val = *((u8 *) addr);
  404. break;
  405. case 2:
  406. val = *((u16 *) addr);
  407. break;
  408. case 4:
  409. val = *((u32 *) addr);
  410. break;
  411. case 8:
  412. val = *((long long *) addr);
  413. break;
  414. default:
  415. val = -1;
  416. break;
  417. }
  418. p += sprintf(p, "%#lx ", val);
  419. addr += size;
  420. }
  421. p += sprintf(p, "\n");
  422. }
  423. if (info.tx_tbl_num) {
  424. p += sprintf(p, "Tx BA stream table:\n");
  425. for (i = 0; i < info.tx_tbl_num; i++)
  426. p += sprintf(p, "tid = %d, ra = %pM\n",
  427. info.tx_tbl[i].tid, info.tx_tbl[i].ra);
  428. }
  429. if (info.rx_tbl_num) {
  430. p += sprintf(p, "Rx reorder table:\n");
  431. for (i = 0; i < info.rx_tbl_num; i++) {
  432. p += sprintf(p, "tid = %d, ta = %pM, "
  433. "start_win = %d, "
  434. "win_size = %d, buffer: ",
  435. info.rx_tbl[i].tid,
  436. info.rx_tbl[i].ta,
  437. info.rx_tbl[i].start_win,
  438. info.rx_tbl[i].win_size);
  439. for (j = 0; j < info.rx_tbl[i].win_size; j++)
  440. p += sprintf(p, "%c ",
  441. info.rx_tbl[i].buffer[j] ?
  442. '1' : '0');
  443. p += sprintf(p, "\n");
  444. }
  445. }
  446. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  447. (unsigned long) p - page);
  448. free_and_exit:
  449. free_page(page);
  450. return ret;
  451. }
  452. static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
  453. /*
  454. * Proc regrdwr file write handler.
  455. *
  456. * This function is called when the 'regrdwr' file is opened for writing
  457. *
  458. * This function can be used to write to a register.
  459. */
  460. static ssize_t
  461. mwifiex_regrdwr_write(struct file *file,
  462. const char __user *ubuf, size_t count, loff_t *ppos)
  463. {
  464. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  465. char *buf = (char *) addr;
  466. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  467. int ret;
  468. u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
  469. if (!buf)
  470. return -ENOMEM;
  471. if (copy_from_user(buf, ubuf, buf_size)) {
  472. ret = -EFAULT;
  473. goto done;
  474. }
  475. sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
  476. if (reg_type == 0 || reg_offset == 0) {
  477. ret = -EINVAL;
  478. goto done;
  479. } else {
  480. saved_reg_type = reg_type;
  481. saved_reg_offset = reg_offset;
  482. saved_reg_value = reg_value;
  483. ret = count;
  484. }
  485. done:
  486. free_page(addr);
  487. return ret;
  488. }
  489. /*
  490. * Proc regrdwr file read handler.
  491. *
  492. * This function is called when the 'regrdwr' file is opened for reading
  493. *
  494. * This function can be used to read from a register.
  495. */
  496. static ssize_t
  497. mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
  498. size_t count, loff_t *ppos)
  499. {
  500. struct mwifiex_private *priv =
  501. (struct mwifiex_private *) file->private_data;
  502. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  503. char *buf = (char *) addr;
  504. int pos = 0, ret = 0;
  505. u32 reg_value;
  506. if (!buf)
  507. return -ENOMEM;
  508. if (!saved_reg_type) {
  509. /* No command has been given */
  510. pos += snprintf(buf, PAGE_SIZE, "0");
  511. goto done;
  512. }
  513. /* Set command has been given */
  514. if (saved_reg_value != UINT_MAX) {
  515. ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
  516. saved_reg_value);
  517. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
  518. saved_reg_type, saved_reg_offset,
  519. saved_reg_value);
  520. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  521. goto done;
  522. }
  523. /* Get command has been given */
  524. ret = mwifiex_reg_read(priv, saved_reg_type,
  525. saved_reg_offset, &reg_value);
  526. if (ret) {
  527. ret = -EINVAL;
  528. goto done;
  529. }
  530. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
  531. saved_reg_offset, reg_value);
  532. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  533. done:
  534. free_page(addr);
  535. return ret;
  536. }
  537. static u32 saved_offset = -1, saved_bytes = -1;
  538. /*
  539. * Proc rdeeprom file write handler.
  540. *
  541. * This function is called when the 'rdeeprom' file is opened for writing
  542. *
  543. * This function can be used to write to a RDEEPROM location.
  544. */
  545. static ssize_t
  546. mwifiex_rdeeprom_write(struct file *file,
  547. const char __user *ubuf, size_t count, loff_t *ppos)
  548. {
  549. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  550. char *buf = (char *) addr;
  551. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  552. int ret = 0;
  553. int offset = -1, bytes = -1;
  554. if (!buf)
  555. return -ENOMEM;
  556. if (copy_from_user(buf, ubuf, buf_size)) {
  557. ret = -EFAULT;
  558. goto done;
  559. }
  560. sscanf(buf, "%d %d", &offset, &bytes);
  561. if (offset == -1 || bytes == -1) {
  562. ret = -EINVAL;
  563. goto done;
  564. } else {
  565. saved_offset = offset;
  566. saved_bytes = bytes;
  567. ret = count;
  568. }
  569. done:
  570. free_page(addr);
  571. return ret;
  572. }
  573. /*
  574. * Proc rdeeprom read write handler.
  575. *
  576. * This function is called when the 'rdeeprom' file is opened for reading
  577. *
  578. * This function can be used to read from a RDEEPROM location.
  579. */
  580. static ssize_t
  581. mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
  582. size_t count, loff_t *ppos)
  583. {
  584. struct mwifiex_private *priv =
  585. (struct mwifiex_private *) file->private_data;
  586. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  587. char *buf = (char *) addr;
  588. int pos = 0, ret = 0, i;
  589. u8 value[MAX_EEPROM_DATA];
  590. if (!buf)
  591. return -ENOMEM;
  592. if (saved_offset == -1) {
  593. /* No command has been given */
  594. pos += snprintf(buf, PAGE_SIZE, "0");
  595. goto done;
  596. }
  597. /* Get command has been given */
  598. ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
  599. (u16) saved_bytes, value);
  600. if (ret) {
  601. ret = -EINVAL;
  602. goto done;
  603. }
  604. pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
  605. for (i = 0; i < saved_bytes; i++)
  606. pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
  607. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  608. done:
  609. free_page(addr);
  610. return ret;
  611. }
  612. /* Proc hscfg file write handler
  613. * This function can be used to configure the host sleep parameters.
  614. */
  615. static ssize_t
  616. mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
  617. size_t count, loff_t *ppos)
  618. {
  619. struct mwifiex_private *priv = (void *)file->private_data;
  620. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  621. char *buf = (char *)addr;
  622. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  623. int ret, arg_num;
  624. struct mwifiex_ds_hs_cfg hscfg;
  625. int conditions = HS_CFG_COND_DEF;
  626. u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
  627. if (!buf)
  628. return -ENOMEM;
  629. if (copy_from_user(buf, ubuf, buf_size)) {
  630. ret = -EFAULT;
  631. goto done;
  632. }
  633. arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
  634. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  635. if (arg_num > 3) {
  636. dev_err(priv->adapter->dev, "Too many arguments\n");
  637. ret = -EINVAL;
  638. goto done;
  639. }
  640. if (arg_num >= 1 && arg_num < 3)
  641. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
  642. MWIFIEX_SYNC_CMD, &hscfg);
  643. if (arg_num) {
  644. if (conditions == HS_CFG_CANCEL) {
  645. mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
  646. ret = count;
  647. goto done;
  648. }
  649. hscfg.conditions = conditions;
  650. }
  651. if (arg_num >= 2)
  652. hscfg.gpio = gpio;
  653. if (arg_num == 3)
  654. hscfg.gap = gap;
  655. hscfg.is_invoke_hostcmd = false;
  656. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  657. MWIFIEX_SYNC_CMD, &hscfg);
  658. mwifiex_enable_hs(priv->adapter);
  659. priv->adapter->hs_enabling = false;
  660. ret = count;
  661. done:
  662. free_page(addr);
  663. return ret;
  664. }
  665. /* Proc hscfg file read handler
  666. * This function can be used to read host sleep configuration
  667. * parameters from driver.
  668. */
  669. static ssize_t
  670. mwifiex_hscfg_read(struct file *file, char __user *ubuf,
  671. size_t count, loff_t *ppos)
  672. {
  673. struct mwifiex_private *priv = (void *)file->private_data;
  674. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  675. char *buf = (char *)addr;
  676. int pos, ret;
  677. struct mwifiex_ds_hs_cfg hscfg;
  678. if (!buf)
  679. return -ENOMEM;
  680. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
  681. MWIFIEX_SYNC_CMD, &hscfg);
  682. pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
  683. hscfg.gpio, hscfg.gap);
  684. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  685. free_page(addr);
  686. return ret;
  687. }
  688. #define MWIFIEX_DFS_ADD_FILE(name) do { \
  689. if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
  690. priv, &mwifiex_dfs_##name##_fops)) \
  691. return; \
  692. } while (0);
  693. #define MWIFIEX_DFS_FILE_OPS(name) \
  694. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  695. .read = mwifiex_##name##_read, \
  696. .write = mwifiex_##name##_write, \
  697. .open = simple_open, \
  698. };
  699. #define MWIFIEX_DFS_FILE_READ_OPS(name) \
  700. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  701. .read = mwifiex_##name##_read, \
  702. .open = simple_open, \
  703. };
  704. #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
  705. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  706. .write = mwifiex_##name##_write, \
  707. .open = simple_open, \
  708. };
  709. MWIFIEX_DFS_FILE_READ_OPS(info);
  710. MWIFIEX_DFS_FILE_READ_OPS(debug);
  711. MWIFIEX_DFS_FILE_READ_OPS(getlog);
  712. MWIFIEX_DFS_FILE_READ_OPS(fw_dump);
  713. MWIFIEX_DFS_FILE_OPS(regrdwr);
  714. MWIFIEX_DFS_FILE_OPS(rdeeprom);
  715. MWIFIEX_DFS_FILE_OPS(hscfg);
  716. /*
  717. * This function creates the debug FS directory structure and the files.
  718. */
  719. void
  720. mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
  721. {
  722. if (!mwifiex_dfs_dir || !priv)
  723. return;
  724. priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
  725. mwifiex_dfs_dir);
  726. if (!priv->dfs_dev_dir)
  727. return;
  728. MWIFIEX_DFS_ADD_FILE(info);
  729. MWIFIEX_DFS_ADD_FILE(debug);
  730. MWIFIEX_DFS_ADD_FILE(getlog);
  731. MWIFIEX_DFS_ADD_FILE(regrdwr);
  732. MWIFIEX_DFS_ADD_FILE(rdeeprom);
  733. MWIFIEX_DFS_ADD_FILE(fw_dump);
  734. MWIFIEX_DFS_ADD_FILE(hscfg);
  735. }
  736. /*
  737. * This function removes the debug FS directory structure and the files.
  738. */
  739. void
  740. mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
  741. {
  742. if (!priv)
  743. return;
  744. debugfs_remove_recursive(priv->dfs_dev_dir);
  745. }
  746. /*
  747. * This function creates the top level proc directory.
  748. */
  749. void
  750. mwifiex_debugfs_init(void)
  751. {
  752. if (!mwifiex_dfs_dir)
  753. mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
  754. }
  755. /*
  756. * This function removes the top level proc directory.
  757. */
  758. void
  759. mwifiex_debugfs_remove(void)
  760. {
  761. if (mwifiex_dfs_dir)
  762. debugfs_remove(mwifiex_dfs_dir);
  763. }