debugfs.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  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. /*
  37. * Proc info file read handler.
  38. *
  39. * This function is called when the 'info' file is opened for reading.
  40. * It prints the following driver related information -
  41. * - Driver name
  42. * - Driver version
  43. * - Driver extended version
  44. * - Interface name
  45. * - BSS mode
  46. * - Media state (connected or disconnected)
  47. * - MAC address
  48. * - Total number of Tx bytes
  49. * - Total number of Rx bytes
  50. * - Total number of Tx packets
  51. * - Total number of Rx packets
  52. * - Total number of dropped Tx packets
  53. * - Total number of dropped Rx packets
  54. * - Total number of corrupted Tx packets
  55. * - Total number of corrupted Rx packets
  56. * - Carrier status (on or off)
  57. * - Tx queue status (started or stopped)
  58. *
  59. * For STA mode drivers, it also prints the following extra -
  60. * - ESSID
  61. * - BSSID
  62. * - Channel
  63. * - Region code
  64. * - Multicast count
  65. * - Multicast addresses
  66. */
  67. static ssize_t
  68. mwifiex_info_read(struct file *file, char __user *ubuf,
  69. size_t count, loff_t *ppos)
  70. {
  71. struct mwifiex_private *priv =
  72. (struct mwifiex_private *) file->private_data;
  73. struct net_device *netdev = priv->netdev;
  74. struct netdev_hw_addr *ha;
  75. struct netdev_queue *txq;
  76. unsigned long page = get_zeroed_page(GFP_KERNEL);
  77. char *p = (char *) page, fmt[64];
  78. struct mwifiex_bss_info info;
  79. ssize_t ret;
  80. int i = 0;
  81. if (!p)
  82. return -ENOMEM;
  83. memset(&info, 0, sizeof(info));
  84. ret = mwifiex_get_bss_info(priv, &info);
  85. if (ret)
  86. goto free_and_exit;
  87. mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1);
  88. if (!priv->version_str[0])
  89. mwifiex_get_ver_ext(priv);
  90. p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
  91. p += sprintf(p, "driver_version = %s", fmt);
  92. p += sprintf(p, "\nverext = %s", priv->version_str);
  93. p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
  94. if (info.bss_mode >= ARRAY_SIZE(bss_modes))
  95. p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
  96. else
  97. p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
  98. p += sprintf(p, "media_state=\"%s\"\n",
  99. (!priv->media_connected ? "Disconnected" : "Connected"));
  100. p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
  101. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
  102. p += sprintf(p, "multicast_count=\"%d\"\n",
  103. netdev_mc_count(netdev));
  104. p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
  105. p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
  106. p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
  107. p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
  108. netdev_for_each_mc_addr(ha, netdev)
  109. p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
  110. i++, ha->addr);
  111. }
  112. p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
  113. p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
  114. p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
  115. p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
  116. p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
  117. p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
  118. p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
  119. p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
  120. p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev))
  121. ? "on" : "off"));
  122. p += sprintf(p, "tx queue");
  123. for (i = 0; i < netdev->num_tx_queues; i++) {
  124. txq = netdev_get_tx_queue(netdev, i);
  125. p += sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ?
  126. "stopped" : "started");
  127. }
  128. p += sprintf(p, "\n");
  129. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  130. (unsigned long) p - page);
  131. free_and_exit:
  132. free_page(page);
  133. return ret;
  134. }
  135. /*
  136. * Proc device dump read handler.
  137. *
  138. * This function is called when the 'device_dump' file is opened for
  139. * reading.
  140. * This function dumps driver information and firmware memory segments
  141. * (ex. DTCM, ITCM, SQRAM etc.) for
  142. * debugging.
  143. */
  144. static ssize_t
  145. mwifiex_device_dump_read(struct file *file, char __user *ubuf,
  146. size_t count, loff_t *ppos)
  147. {
  148. struct mwifiex_private *priv = file->private_data;
  149. if (!priv->adapter->if_ops.device_dump)
  150. return -EIO;
  151. priv->adapter->if_ops.device_dump(priv->adapter);
  152. return 0;
  153. }
  154. /*
  155. * Proc getlog file read handler.
  156. *
  157. * This function is called when the 'getlog' file is opened for reading
  158. * It prints the following log information -
  159. * - Number of multicast Tx frames
  160. * - Number of failed packets
  161. * - Number of Tx retries
  162. * - Number of multicast Tx retries
  163. * - Number of duplicate frames
  164. * - Number of RTS successes
  165. * - Number of RTS failures
  166. * - Number of ACK failures
  167. * - Number of fragmented Rx frames
  168. * - Number of multicast Rx frames
  169. * - Number of FCS errors
  170. * - Number of Tx frames
  171. * - WEP ICV error counts
  172. * - Number of received beacons
  173. * - Number of missed beacons
  174. */
  175. static ssize_t
  176. mwifiex_getlog_read(struct file *file, char __user *ubuf,
  177. size_t count, loff_t *ppos)
  178. {
  179. struct mwifiex_private *priv =
  180. (struct mwifiex_private *) file->private_data;
  181. unsigned long page = get_zeroed_page(GFP_KERNEL);
  182. char *p = (char *) page;
  183. ssize_t ret;
  184. struct mwifiex_ds_get_stats stats;
  185. if (!p)
  186. return -ENOMEM;
  187. memset(&stats, 0, sizeof(stats));
  188. ret = mwifiex_get_stats_info(priv, &stats);
  189. if (ret)
  190. goto free_and_exit;
  191. p += sprintf(p, "\n"
  192. "mcasttxframe %u\n"
  193. "failed %u\n"
  194. "retry %u\n"
  195. "multiretry %u\n"
  196. "framedup %u\n"
  197. "rtssuccess %u\n"
  198. "rtsfailure %u\n"
  199. "ackfailure %u\n"
  200. "rxfrag %u\n"
  201. "mcastrxframe %u\n"
  202. "fcserror %u\n"
  203. "txframe %u\n"
  204. "wepicverrcnt-1 %u\n"
  205. "wepicverrcnt-2 %u\n"
  206. "wepicverrcnt-3 %u\n"
  207. "wepicverrcnt-4 %u\n"
  208. "bcn_rcv_cnt %u\n"
  209. "bcn_miss_cnt %u\n",
  210. stats.mcast_tx_frame,
  211. stats.failed,
  212. stats.retry,
  213. stats.multi_retry,
  214. stats.frame_dup,
  215. stats.rts_success,
  216. stats.rts_failure,
  217. stats.ack_failure,
  218. stats.rx_frag,
  219. stats.mcast_rx_frame,
  220. stats.fcs_error,
  221. stats.tx_frame,
  222. stats.wep_icv_error[0],
  223. stats.wep_icv_error[1],
  224. stats.wep_icv_error[2],
  225. stats.wep_icv_error[3],
  226. stats.bcn_rcv_cnt,
  227. stats.bcn_miss_cnt);
  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. /* Sysfs histogram file read handler.
  235. *
  236. * This function is called when the 'histogram' file is opened for reading
  237. * It prints the following histogram information -
  238. * - Number of histogram samples
  239. * - Receive packet number of each rx_rate
  240. * - Receive packet number of each snr
  241. * - Receive packet number of each nosie_flr
  242. * - Receive packet number of each signal streath
  243. */
  244. static ssize_t
  245. mwifiex_histogram_read(struct file *file, char __user *ubuf,
  246. size_t count, loff_t *ppos)
  247. {
  248. struct mwifiex_private *priv =
  249. (struct mwifiex_private *)file->private_data;
  250. ssize_t ret;
  251. struct mwifiex_histogram_data *phist_data;
  252. int i, value;
  253. unsigned long page = get_zeroed_page(GFP_KERNEL);
  254. char *p = (char *)page;
  255. if (!p)
  256. return -ENOMEM;
  257. if (!priv || !priv->hist_data)
  258. return -EFAULT;
  259. phist_data = priv->hist_data;
  260. p += sprintf(p, "\n"
  261. "total samples = %d\n",
  262. atomic_read(&phist_data->num_samples));
  263. p += sprintf(p, "rx rates (in Mbps): 0=1M 1=2M");
  264. p += sprintf(p, "2=5.5M 3=11M 4=6M 5=9M 6=12M\n");
  265. p += sprintf(p, "7=18M 8=24M 9=36M 10=48M 11=54M");
  266. p += sprintf(p, "12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
  267. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
  268. p += sprintf(p, "44-53=MCS0-9(VHT:BW20)");
  269. p += sprintf(p, "54-63=MCS0-9(VHT:BW40)");
  270. p += sprintf(p, "64-73=MCS0-9(VHT:BW80)\n\n");
  271. } else {
  272. p += sprintf(p, "\n");
  273. }
  274. for (i = 0; i < MWIFIEX_MAX_RX_RATES; i++) {
  275. value = atomic_read(&phist_data->rx_rate[i]);
  276. if (value)
  277. p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
  278. }
  279. if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
  280. for (i = MWIFIEX_MAX_RX_RATES; i < MWIFIEX_MAX_AC_RX_RATES;
  281. i++) {
  282. value = atomic_read(&phist_data->rx_rate[i]);
  283. if (value)
  284. p += sprintf(p, "rx_rate[%02d] = %d\n",
  285. i, value);
  286. }
  287. }
  288. for (i = 0; i < MWIFIEX_MAX_SNR; i++) {
  289. value = atomic_read(&phist_data->snr[i]);
  290. if (value)
  291. p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
  292. }
  293. for (i = 0; i < MWIFIEX_MAX_NOISE_FLR; i++) {
  294. value = atomic_read(&phist_data->noise_flr[i]);
  295. if (value)
  296. p += sprintf(p, "noise_flr[-%02ddBm] = %d\n",
  297. (int)(i-128), value);
  298. }
  299. for (i = 0; i < MWIFIEX_MAX_SIG_STRENGTH; i++) {
  300. value = atomic_read(&phist_data->sig_str[i]);
  301. if (value)
  302. p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
  303. i, value);
  304. }
  305. ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
  306. (unsigned long)p - page);
  307. return ret;
  308. }
  309. static ssize_t
  310. mwifiex_histogram_write(struct file *file, const char __user *ubuf,
  311. size_t count, loff_t *ppos)
  312. {
  313. struct mwifiex_private *priv = (void *)file->private_data;
  314. if (priv && priv->hist_data)
  315. mwifiex_hist_data_reset(priv);
  316. return 0;
  317. }
  318. static struct mwifiex_debug_info info;
  319. /*
  320. * Proc debug file read handler.
  321. *
  322. * This function is called when the 'debug' file is opened for reading
  323. * It prints the following log information -
  324. * - Interrupt count
  325. * - WMM AC VO packets count
  326. * - WMM AC VI packets count
  327. * - WMM AC BE packets count
  328. * - WMM AC BK packets count
  329. * - Maximum Tx buffer size
  330. * - Tx buffer size
  331. * - Current Tx buffer size
  332. * - Power Save mode
  333. * - Power Save state
  334. * - Deep Sleep status
  335. * - Device wakeup required status
  336. * - Number of wakeup tries
  337. * - Host Sleep configured status
  338. * - Host Sleep activated status
  339. * - Number of Tx timeouts
  340. * - Number of command timeouts
  341. * - Last timed out command ID
  342. * - Last timed out command action
  343. * - Last command ID
  344. * - Last command action
  345. * - Last command index
  346. * - Last command response ID
  347. * - Last command response index
  348. * - Last event
  349. * - Last event index
  350. * - Number of host to card command failures
  351. * - Number of sleep confirm command failures
  352. * - Number of host to card data failure
  353. * - Number of deauthentication events
  354. * - Number of disassociation events
  355. * - Number of link lost events
  356. * - Number of deauthentication commands
  357. * - Number of association success commands
  358. * - Number of association failure commands
  359. * - Number of commands sent
  360. * - Number of data packets sent
  361. * - Number of command responses received
  362. * - Number of events received
  363. * - Tx BA stream table (TID, RA)
  364. * - Rx reorder table (TID, TA, Start window, Window size, Buffer)
  365. */
  366. static ssize_t
  367. mwifiex_debug_read(struct file *file, char __user *ubuf,
  368. size_t count, loff_t *ppos)
  369. {
  370. struct mwifiex_private *priv =
  371. (struct mwifiex_private *) file->private_data;
  372. unsigned long page = get_zeroed_page(GFP_KERNEL);
  373. char *p = (char *) page;
  374. ssize_t ret;
  375. if (!p)
  376. return -ENOMEM;
  377. ret = mwifiex_get_debug_info(priv, &info);
  378. if (ret)
  379. goto free_and_exit;
  380. p += mwifiex_debug_info_to_buffer(priv, p, &info);
  381. ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page,
  382. (unsigned long) p - page);
  383. free_and_exit:
  384. free_page(page);
  385. return ret;
  386. }
  387. static u32 saved_reg_type, saved_reg_offset, saved_reg_value;
  388. /*
  389. * Proc regrdwr file write handler.
  390. *
  391. * This function is called when the 'regrdwr' file is opened for writing
  392. *
  393. * This function can be used to write to a register.
  394. */
  395. static ssize_t
  396. mwifiex_regrdwr_write(struct file *file,
  397. const char __user *ubuf, size_t count, loff_t *ppos)
  398. {
  399. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  400. char *buf = (char *) addr;
  401. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  402. int ret;
  403. u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX;
  404. if (!buf)
  405. return -ENOMEM;
  406. if (copy_from_user(buf, ubuf, buf_size)) {
  407. ret = -EFAULT;
  408. goto done;
  409. }
  410. sscanf(buf, "%u %x %x", &reg_type, &reg_offset, &reg_value);
  411. if (reg_type == 0 || reg_offset == 0) {
  412. ret = -EINVAL;
  413. goto done;
  414. } else {
  415. saved_reg_type = reg_type;
  416. saved_reg_offset = reg_offset;
  417. saved_reg_value = reg_value;
  418. ret = count;
  419. }
  420. done:
  421. free_page(addr);
  422. return ret;
  423. }
  424. /*
  425. * Proc regrdwr file read handler.
  426. *
  427. * This function is called when the 'regrdwr' file is opened for reading
  428. *
  429. * This function can be used to read from a register.
  430. */
  431. static ssize_t
  432. mwifiex_regrdwr_read(struct file *file, char __user *ubuf,
  433. size_t count, loff_t *ppos)
  434. {
  435. struct mwifiex_private *priv =
  436. (struct mwifiex_private *) file->private_data;
  437. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  438. char *buf = (char *) addr;
  439. int pos = 0, ret = 0;
  440. u32 reg_value;
  441. if (!buf)
  442. return -ENOMEM;
  443. if (!saved_reg_type) {
  444. /* No command has been given */
  445. pos += snprintf(buf, PAGE_SIZE, "0");
  446. goto done;
  447. }
  448. /* Set command has been given */
  449. if (saved_reg_value != UINT_MAX) {
  450. ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset,
  451. saved_reg_value);
  452. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n",
  453. saved_reg_type, saved_reg_offset,
  454. saved_reg_value);
  455. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  456. goto done;
  457. }
  458. /* Get command has been given */
  459. ret = mwifiex_reg_read(priv, saved_reg_type,
  460. saved_reg_offset, &reg_value);
  461. if (ret) {
  462. ret = -EINVAL;
  463. goto done;
  464. }
  465. pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type,
  466. saved_reg_offset, reg_value);
  467. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  468. done:
  469. free_page(addr);
  470. return ret;
  471. }
  472. /* Proc debug_mask file read handler.
  473. * This function is called when the 'debug_mask' file is opened for reading
  474. * This function can be used read driver debugging mask value.
  475. */
  476. static ssize_t
  477. mwifiex_debug_mask_read(struct file *file, char __user *ubuf,
  478. size_t count, loff_t *ppos)
  479. {
  480. struct mwifiex_private *priv =
  481. (struct mwifiex_private *)file->private_data;
  482. unsigned long page = get_zeroed_page(GFP_KERNEL);
  483. char *buf = (char *)page;
  484. size_t ret = 0;
  485. int pos = 0;
  486. if (!buf)
  487. return -ENOMEM;
  488. pos += snprintf(buf, PAGE_SIZE, "debug mask=0x%08x\n",
  489. priv->adapter->debug_mask);
  490. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  491. free_page(page);
  492. return ret;
  493. }
  494. /* Proc debug_mask file read handler.
  495. * This function is called when the 'debug_mask' file is opened for reading
  496. * This function can be used read driver debugging mask value.
  497. */
  498. static ssize_t
  499. mwifiex_debug_mask_write(struct file *file, const char __user *ubuf,
  500. size_t count, loff_t *ppos)
  501. {
  502. int ret;
  503. unsigned long debug_mask;
  504. struct mwifiex_private *priv = (void *)file->private_data;
  505. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  506. char *buf = (void *)addr;
  507. size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
  508. if (!buf)
  509. return -ENOMEM;
  510. if (copy_from_user(buf, ubuf, buf_size)) {
  511. ret = -EFAULT;
  512. goto done;
  513. }
  514. if (kstrtoul(buf, 0, &debug_mask)) {
  515. ret = -EINVAL;
  516. goto done;
  517. }
  518. priv->adapter->debug_mask = debug_mask;
  519. ret = count;
  520. done:
  521. free_page(addr);
  522. return ret;
  523. }
  524. /* Proc memrw file write handler.
  525. * This function is called when the 'memrw' file is opened for writing
  526. * This function can be used to write to a memory location.
  527. */
  528. static ssize_t
  529. mwifiex_memrw_write(struct file *file, const char __user *ubuf, size_t count,
  530. loff_t *ppos)
  531. {
  532. int ret;
  533. char cmd;
  534. struct mwifiex_ds_mem_rw mem_rw;
  535. u16 cmd_action;
  536. struct mwifiex_private *priv = (void *)file->private_data;
  537. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  538. char *buf = (void *)addr;
  539. size_t buf_size = min(count, (size_t)(PAGE_SIZE - 1));
  540. if (!buf)
  541. return -ENOMEM;
  542. if (copy_from_user(buf, ubuf, buf_size)) {
  543. ret = -EFAULT;
  544. goto done;
  545. }
  546. ret = sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value);
  547. if (ret != 3) {
  548. ret = -EINVAL;
  549. goto done;
  550. }
  551. if ((cmd == 'r') || (cmd == 'R')) {
  552. cmd_action = HostCmd_ACT_GEN_GET;
  553. mem_rw.value = 0;
  554. } else if ((cmd == 'w') || (cmd == 'W')) {
  555. cmd_action = HostCmd_ACT_GEN_SET;
  556. } else {
  557. ret = -EINVAL;
  558. goto done;
  559. }
  560. memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw));
  561. if (mwifiex_send_cmd(priv, HostCmd_CMD_MEM_ACCESS, cmd_action, 0,
  562. &mem_rw, true))
  563. ret = -1;
  564. else
  565. ret = count;
  566. done:
  567. free_page(addr);
  568. return ret;
  569. }
  570. /* Proc memrw file read handler.
  571. * This function is called when the 'memrw' file is opened for reading
  572. * This function can be used to read from a memory location.
  573. */
  574. static ssize_t
  575. mwifiex_memrw_read(struct file *file, char __user *ubuf,
  576. size_t count, loff_t *ppos)
  577. {
  578. struct mwifiex_private *priv = (void *)file->private_data;
  579. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  580. char *buf = (char *)addr;
  581. int ret, pos = 0;
  582. if (!buf)
  583. return -ENOMEM;
  584. pos += snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr,
  585. priv->mem_rw.value);
  586. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  587. free_page(addr);
  588. return ret;
  589. }
  590. static u32 saved_offset = -1, saved_bytes = -1;
  591. /*
  592. * Proc rdeeprom file write handler.
  593. *
  594. * This function is called when the 'rdeeprom' file is opened for writing
  595. *
  596. * This function can be used to write to a RDEEPROM location.
  597. */
  598. static ssize_t
  599. mwifiex_rdeeprom_write(struct file *file,
  600. const char __user *ubuf, size_t count, loff_t *ppos)
  601. {
  602. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  603. char *buf = (char *) addr;
  604. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  605. int ret = 0;
  606. int offset = -1, bytes = -1;
  607. if (!buf)
  608. return -ENOMEM;
  609. if (copy_from_user(buf, ubuf, buf_size)) {
  610. ret = -EFAULT;
  611. goto done;
  612. }
  613. sscanf(buf, "%d %d", &offset, &bytes);
  614. if (offset == -1 || bytes == -1) {
  615. ret = -EINVAL;
  616. goto done;
  617. } else {
  618. saved_offset = offset;
  619. saved_bytes = bytes;
  620. ret = count;
  621. }
  622. done:
  623. free_page(addr);
  624. return ret;
  625. }
  626. /*
  627. * Proc rdeeprom read write handler.
  628. *
  629. * This function is called when the 'rdeeprom' file is opened for reading
  630. *
  631. * This function can be used to read from a RDEEPROM location.
  632. */
  633. static ssize_t
  634. mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
  635. size_t count, loff_t *ppos)
  636. {
  637. struct mwifiex_private *priv =
  638. (struct mwifiex_private *) file->private_data;
  639. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  640. char *buf = (char *) addr;
  641. int pos = 0, ret = 0, i;
  642. u8 value[MAX_EEPROM_DATA];
  643. if (!buf)
  644. return -ENOMEM;
  645. if (saved_offset == -1) {
  646. /* No command has been given */
  647. pos += snprintf(buf, PAGE_SIZE, "0");
  648. goto done;
  649. }
  650. /* Get command has been given */
  651. ret = mwifiex_eeprom_read(priv, (u16) saved_offset,
  652. (u16) saved_bytes, value);
  653. if (ret) {
  654. ret = -EINVAL;
  655. goto done;
  656. }
  657. pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
  658. for (i = 0; i < saved_bytes; i++)
  659. pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
  660. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  661. done:
  662. free_page(addr);
  663. return ret;
  664. }
  665. /* Proc hscfg file write handler
  666. * This function can be used to configure the host sleep parameters.
  667. */
  668. static ssize_t
  669. mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
  670. size_t count, loff_t *ppos)
  671. {
  672. struct mwifiex_private *priv = (void *)file->private_data;
  673. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  674. char *buf = (char *)addr;
  675. size_t buf_size = min_t(size_t, count, PAGE_SIZE - 1);
  676. int ret, arg_num;
  677. struct mwifiex_ds_hs_cfg hscfg;
  678. int conditions = HS_CFG_COND_DEF;
  679. u32 gpio = HS_CFG_GPIO_DEF, gap = HS_CFG_GAP_DEF;
  680. if (!buf)
  681. return -ENOMEM;
  682. if (copy_from_user(buf, ubuf, buf_size)) {
  683. ret = -EFAULT;
  684. goto done;
  685. }
  686. arg_num = sscanf(buf, "%d %x %x", &conditions, &gpio, &gap);
  687. memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
  688. if (arg_num > 3) {
  689. mwifiex_dbg(priv->adapter, ERROR,
  690. "Too many arguments\n");
  691. ret = -EINVAL;
  692. goto done;
  693. }
  694. if (arg_num >= 1 && arg_num < 3)
  695. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
  696. MWIFIEX_SYNC_CMD, &hscfg);
  697. if (arg_num) {
  698. if (conditions == HS_CFG_CANCEL) {
  699. mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
  700. ret = count;
  701. goto done;
  702. }
  703. hscfg.conditions = conditions;
  704. }
  705. if (arg_num >= 2)
  706. hscfg.gpio = gpio;
  707. if (arg_num == 3)
  708. hscfg.gap = gap;
  709. hscfg.is_invoke_hostcmd = false;
  710. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
  711. MWIFIEX_SYNC_CMD, &hscfg);
  712. mwifiex_enable_hs(priv->adapter);
  713. priv->adapter->hs_enabling = false;
  714. ret = count;
  715. done:
  716. free_page(addr);
  717. return ret;
  718. }
  719. /* Proc hscfg file read handler
  720. * This function can be used to read host sleep configuration
  721. * parameters from driver.
  722. */
  723. static ssize_t
  724. mwifiex_hscfg_read(struct file *file, char __user *ubuf,
  725. size_t count, loff_t *ppos)
  726. {
  727. struct mwifiex_private *priv = (void *)file->private_data;
  728. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  729. char *buf = (char *)addr;
  730. int pos, ret;
  731. struct mwifiex_ds_hs_cfg hscfg;
  732. if (!buf)
  733. return -ENOMEM;
  734. mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_GET,
  735. MWIFIEX_SYNC_CMD, &hscfg);
  736. pos = snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions,
  737. hscfg.gpio, hscfg.gap);
  738. ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
  739. free_page(addr);
  740. return ret;
  741. }
  742. #define MWIFIEX_DFS_ADD_FILE(name) do { \
  743. if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \
  744. priv, &mwifiex_dfs_##name##_fops)) \
  745. return; \
  746. } while (0);
  747. #define MWIFIEX_DFS_FILE_OPS(name) \
  748. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  749. .read = mwifiex_##name##_read, \
  750. .write = mwifiex_##name##_write, \
  751. .open = simple_open, \
  752. };
  753. #define MWIFIEX_DFS_FILE_READ_OPS(name) \
  754. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  755. .read = mwifiex_##name##_read, \
  756. .open = simple_open, \
  757. };
  758. #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \
  759. static const struct file_operations mwifiex_dfs_##name##_fops = { \
  760. .write = mwifiex_##name##_write, \
  761. .open = simple_open, \
  762. };
  763. MWIFIEX_DFS_FILE_READ_OPS(info);
  764. MWIFIEX_DFS_FILE_READ_OPS(debug);
  765. MWIFIEX_DFS_FILE_READ_OPS(getlog);
  766. MWIFIEX_DFS_FILE_READ_OPS(device_dump);
  767. MWIFIEX_DFS_FILE_OPS(regrdwr);
  768. MWIFIEX_DFS_FILE_OPS(rdeeprom);
  769. MWIFIEX_DFS_FILE_OPS(memrw);
  770. MWIFIEX_DFS_FILE_OPS(hscfg);
  771. MWIFIEX_DFS_FILE_OPS(histogram);
  772. MWIFIEX_DFS_FILE_OPS(debug_mask);
  773. /*
  774. * This function creates the debug FS directory structure and the files.
  775. */
  776. void
  777. mwifiex_dev_debugfs_init(struct mwifiex_private *priv)
  778. {
  779. if (!mwifiex_dfs_dir || !priv)
  780. return;
  781. priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name,
  782. mwifiex_dfs_dir);
  783. if (!priv->dfs_dev_dir)
  784. return;
  785. MWIFIEX_DFS_ADD_FILE(info);
  786. MWIFIEX_DFS_ADD_FILE(debug);
  787. MWIFIEX_DFS_ADD_FILE(getlog);
  788. MWIFIEX_DFS_ADD_FILE(regrdwr);
  789. MWIFIEX_DFS_ADD_FILE(rdeeprom);
  790. MWIFIEX_DFS_ADD_FILE(device_dump);
  791. MWIFIEX_DFS_ADD_FILE(memrw);
  792. MWIFIEX_DFS_ADD_FILE(hscfg);
  793. MWIFIEX_DFS_ADD_FILE(histogram);
  794. MWIFIEX_DFS_ADD_FILE(debug_mask);
  795. }
  796. /*
  797. * This function removes the debug FS directory structure and the files.
  798. */
  799. void
  800. mwifiex_dev_debugfs_remove(struct mwifiex_private *priv)
  801. {
  802. if (!priv)
  803. return;
  804. debugfs_remove_recursive(priv->dfs_dev_dir);
  805. }
  806. /*
  807. * This function creates the top level proc directory.
  808. */
  809. void
  810. mwifiex_debugfs_init(void)
  811. {
  812. if (!mwifiex_dfs_dir)
  813. mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL);
  814. }
  815. /*
  816. * This function removes the top level proc directory.
  817. */
  818. void
  819. mwifiex_debugfs_remove(void)
  820. {
  821. if (mwifiex_dfs_dir)
  822. debugfs_remove(mwifiex_dfs_dir);
  823. }