gl_proc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/os/linux/gl_proc.c#2
  3. */
  4. /*! \file "gl_proc.c"
  5. \brief This file defines the interface which can interact with users in /proc fs.
  6. Detail description.
  7. */
  8. /*
  9. ** Log: gl_proc.c
  10. **
  11. ** 09 17 2012 cm.chang
  12. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  13. ** Duplicate source from MT6620 v2.3 driver branch
  14. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  15. **
  16. ** 08 24 2012 cp.wu
  17. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  18. ** .
  19. **
  20. ** 08 24 2012 cp.wu
  21. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  22. ** cfg80211 support merge back from ALPS.JB to DaVinci - MT6620 Driver v2.3 branch.
  23. *
  24. * 11 10 2011 cp.wu
  25. * [WCXRP00001098] [MT6620 Wi-Fi][Driver] Replace printk by DBG LOG macros in linux porting layer
  26. * 1. eliminaite direct calls to printk in porting layer.
  27. * 2. replaced by DBGLOG, which would be XLOG on ALPS platforms.
  28. *
  29. * 12 10 2010 kevin.huang
  30. * [WCXRP00000128] [MT6620 Wi-Fi][Driver] Add proc support to Android Driver for debug and driver status check
  31. * Add Linux Proc Support
  32. ** \main\maintrunk.MT5921\19 2008-09-02 21:08:37 GMT mtk01461
  33. ** Fix the compile error of SPRINTF()
  34. ** \main\maintrunk.MT5921\18 2008-08-10 18:48:28 GMT mtk01461
  35. ** Update for Driver Review
  36. ** \main\maintrunk.MT5921\17 2008-08-04 16:52:01 GMT mtk01461
  37. ** Add proc dbg print message of DOMAIN_INDEX level
  38. ** \main\maintrunk.MT5921\16 2008-07-10 00:45:16 GMT mtk01461
  39. ** Remove the check of MCR offset, we may use the MCR address which is not align to DW boundary or proprietary usage.
  40. ** \main\maintrunk.MT5921\15 2008-06-03 20:49:44 GMT mtk01461
  41. ** \main\maintrunk.MT5921\14 2008-06-02 22:56:00 GMT mtk01461
  42. ** Rename some functions for linux proc
  43. ** \main\maintrunk.MT5921\13 2008-06-02 20:23:18 GMT mtk01461
  44. ** Revise PROC mcr read / write for supporting TELNET
  45. ** \main\maintrunk.MT5921\12 2008-03-28 10:40:25 GMT mtk01461
  46. ** Remove temporary set desired rate in linux proc
  47. ** \main\maintrunk.MT5921\11 2008-01-07 15:07:29 GMT mtk01461
  48. ** Add User Update Desired Rate Set for QA in Linux
  49. ** \main\maintrunk.MT5921\10 2007-12-11 00:11:14 GMT mtk01461
  50. ** Fix SPIN_LOCK protection
  51. ** \main\maintrunk.MT5921\9 2007-12-04 18:07:57 GMT mtk01461
  52. ** Add additional debug category to proc
  53. ** \main\maintrunk.MT5921\8 2007-11-02 01:03:23 GMT mtk01461
  54. ** Unify TX Path for Normal and IBSS Power Save + IBSS neighbor learning
  55. ** \main\maintrunk.MT5921\7 2007-10-25 18:08:14 GMT mtk01461
  56. ** Add VOIP SCAN Support & Refine Roaming
  57. ** Revision 1.3 2007/07/05 07:25:33 MTK01461
  58. ** Add Linux initial code, modify doc, add 11BB, RF init code
  59. **
  60. ** Revision 1.2 2007/06/27 02:18:51 MTK01461
  61. ** Update SCAN_FSM, Initial(Can Load Module), Proc(Can do Reg R/W), TX API
  62. **
  63. */
  64. /*******************************************************************************
  65. * C O M P I L E R F L A G S
  66. ********************************************************************************
  67. */
  68. /*******************************************************************************
  69. * E X T E R N A L R E F E R E N C E S
  70. ********************************************************************************
  71. */
  72. #include "gl_os.h"
  73. #include "gl_kal.h"
  74. #include "debug.h"
  75. #include "wlan_lib.h"
  76. #include "debug.h"
  77. /*******************************************************************************
  78. * C O N S T A N T S
  79. ********************************************************************************
  80. */
  81. #define PROC_MCR_ACCESS "mcr"
  82. #define PROC_ROOT_NAME "wlan"
  83. #if CFG_SUPPORT_DEBUG_FS
  84. #define PROC_ROAM_PARAM "roam_param"
  85. #define PROC_COUNTRY "country"
  86. #endif
  87. #define PROC_DRV_STATUS "status"
  88. #define PROC_RX_STATISTICS "rx_statistics"
  89. #define PROC_TX_STATISTICS "tx_statistics"
  90. #define PROC_DBG_LEVEL_NAME "dbg_level"
  91. #define PROC_MCR_ACCESS_MAX_USER_INPUT_LEN 20
  92. #define PROC_RX_STATISTICS_MAX_USER_INPUT_LEN 10
  93. #define PROC_TX_STATISTICS_MAX_USER_INPUT_LEN 10
  94. #define PROC_DBG_LEVEL_MAX_USER_INPUT_LEN 20
  95. #define PROC_DBG_LEVEL_MAX_DISPLAY_STR_LEN 30
  96. #define PROC_UID_SHELL 2000
  97. #define PROC_GID_WIFI 1010
  98. /*******************************************************************************
  99. * D A T A T Y P E S
  100. ********************************************************************************
  101. */
  102. /*******************************************************************************
  103. * P U B L I C D A T A
  104. ********************************************************************************
  105. */
  106. /*******************************************************************************
  107. * P R I V A T E D A T A
  108. ********************************************************************************
  109. */
  110. static P_GLUE_INFO_T g_prGlueInfo_proc;
  111. static UINT_32 u4McrOffset;
  112. static struct proc_dir_entry *gprProcRoot;
  113. static UINT_8 aucDbModuleName[][PROC_DBG_LEVEL_MAX_DISPLAY_STR_LEN] = {
  114. "INIT", "HAL", "INTR", "REQ", "TX", "RX", "RFTEST", "EMU", "SW1", "SW2",
  115. "SW3", "SW4", "HEM", "AIS", "RLM", "MEM", "CNM", "RSN", "BSS", "SCN",
  116. "SAA", "AAA", "P2P", "QM", "SEC", "BOW", "WAPI", "ROAMING", "TDLS", "OID",
  117. "NIC"
  118. };
  119. static UINT_8 aucProcBuf[1536];
  120. /*******************************************************************************
  121. * M A C R O S
  122. ********************************************************************************
  123. */
  124. /*******************************************************************************
  125. * F U N C T I O N D E C L A R A T I O N S
  126. ********************************************************************************
  127. */
  128. static ssize_t procDbgLevelRead(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  129. {
  130. UINT_8 *temp = &aucProcBuf[0];
  131. UINT_32 u4CopySize = 0;
  132. UINT_16 i;
  133. UINT_16 u2ModuleNum = 0;
  134. /* if *f_ops>0, we should return 0 to make cat command exit */
  135. if (*f_pos > 0)
  136. return 0;
  137. kalStrCpy(temp, "\nTEMP|LOUD|INFO|TRACE | EVENT|STATE|WARN|ERROR\n"
  138. "bit7|bit6|bit5|bit4 | bit3|bit2|bit1|bit0\n\n"
  139. "Usage: Module Index:Module Level, such as 0x00:0xff\n\n"
  140. "Debug Module\tIndex\tLevel\tDebug Module\tIndex\tLevel\n\n");
  141. temp += kalStrLen(temp);
  142. u2ModuleNum = (sizeof(aucDbModuleName) / PROC_DBG_LEVEL_MAX_DISPLAY_STR_LEN) & 0xfe;
  143. for (i = 0; i < u2ModuleNum; i += 2)
  144. SPRINTF(temp, ("DBG_%s_IDX\t(0x%02x):\t0x%02x\tDBG_%s_IDX\t(0x%02x):\t0x%02x\n",
  145. &aucDbModuleName[i][0], i, aucDebugModule[i],
  146. &aucDbModuleName[i+1][0], i+1, aucDebugModule[i+1]));
  147. if ((sizeof(aucDbModuleName) / PROC_DBG_LEVEL_MAX_DISPLAY_STR_LEN) & 0x1)
  148. SPRINTF(temp, ("DBG_%s_IDX\t(0x%02x):\t0x%02x\n",
  149. &aucDbModuleName[u2ModuleNum][0], u2ModuleNum, aucDebugModule[u2ModuleNum]));
  150. u4CopySize = kalStrLen(aucProcBuf);
  151. if (u4CopySize > count)
  152. u4CopySize = count;
  153. if (copy_to_user(buf, aucProcBuf, u4CopySize)) {
  154. DBGLOG(HAL, ERROR, "copy to user failed\n");
  155. return -EFAULT;
  156. }
  157. *f_pos += u4CopySize;
  158. return (ssize_t)u4CopySize;
  159. }
  160. static ssize_t procDbgLevelWrite(struct file *file, const char __user *buffer, size_t count, loff_t *data)
  161. {
  162. UINT_32 u4NewDbgModule, u4NewDbgLevel;
  163. UINT_8 *temp = &aucProcBuf[0];
  164. UINT_32 u4CopySize = sizeof(aucProcBuf);
  165. kalMemSet(aucProcBuf, 0, u4CopySize);
  166. if (u4CopySize >= count+1)
  167. u4CopySize = count;
  168. if (copy_from_user(aucProcBuf, buffer, u4CopySize)) {
  169. pr_err("error of copy from user\n");
  170. return -EFAULT;
  171. }
  172. aucProcBuf[u4CopySize] = '\0';
  173. while (temp) {
  174. if (sscanf(temp, "0x%x:0x%x", &u4NewDbgModule, &u4NewDbgLevel) != 2) {
  175. pr_info("debug module and debug level should be one byte in length\n");
  176. break;
  177. }
  178. if (u4NewDbgModule == 0xFF) {
  179. UINT_8 i = 0;
  180. for (; i < DBG_MODULE_NUM; i++)
  181. aucDebugModule[i] = u4NewDbgLevel & DBG_CLASS_MASK;
  182. break;
  183. } else if (u4NewDbgModule >= DBG_MODULE_NUM) {
  184. pr_info("debug module index should less than %d\n", DBG_MODULE_NUM);
  185. break;
  186. }
  187. aucDebugModule[u4NewDbgModule] = u4NewDbgLevel & DBG_CLASS_MASK;
  188. temp = kalStrChr(temp, ',');
  189. if (!temp)
  190. break;
  191. temp++; /* skip ',' */
  192. }
  193. return count;
  194. }
  195. static const struct file_operations dbglevel_ops = {
  196. .owner = THIS_MODULE,
  197. .read = procDbgLevelRead,
  198. .write = procDbgLevelWrite,
  199. };
  200. /*******************************************************************************
  201. * F U N C T I O N S
  202. ********************************************************************************
  203. */
  204. /*----------------------------------------------------------------------------*/
  205. /*!
  206. * \brief The PROC function for reading MCR register to User Space, the offset of
  207. * the MCR is specified in u4McrOffset.
  208. *
  209. * \param[in] page Buffer provided by kernel.
  210. * \param[in out] start Start Address to read(3 methods).
  211. * \param[in] off Offset.
  212. * \param[in] count Allowable number to read.
  213. * \param[out] eof End of File indication.
  214. * \param[in] data Pointer to the private data structure.
  215. *
  216. * \return number of characters print to the buffer from User Space.
  217. */
  218. /*----------------------------------------------------------------------------*/
  219. static ssize_t procMCRRead(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  220. {
  221. P_GLUE_INFO_T prGlueInfo;
  222. PARAM_CUSTOM_MCR_RW_STRUCT_T rMcrInfo;
  223. UINT_32 u4BufLen;
  224. UINT_32 u4Count;
  225. UINT_8 *temp = &aucProcBuf[0];
  226. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  227. /* Kevin: Apply PROC read method 1. */
  228. if (*f_pos > 0)
  229. return 0; /* To indicate end of file. */
  230. prGlueInfo = g_prGlueInfo_proc;
  231. rMcrInfo.u4McrOffset = u4McrOffset;
  232. rStatus = kalIoctl(prGlueInfo,
  233. wlanoidQueryMcrRead, (PVOID)&rMcrInfo, sizeof(rMcrInfo), TRUE, TRUE, TRUE, &u4BufLen);
  234. kalMemZero(aucProcBuf, sizeof(aucProcBuf));
  235. SPRINTF(temp, ("MCR (0x%08xh): 0x%08x\n", rMcrInfo.u4McrOffset, rMcrInfo.u4McrData));
  236. u4Count = kalStrLen(aucProcBuf);
  237. if (copy_to_user(buf, aucProcBuf, u4Count)) {
  238. pr_err("copy to user failed\n");
  239. return -EFAULT;
  240. }
  241. *f_pos += u4Count;
  242. return (int)u4Count;
  243. } /* end of procMCRRead() */
  244. /*----------------------------------------------------------------------------*/
  245. /*!
  246. * \brief The PROC function for writing MCR register to HW or update u4McrOffset
  247. * for reading MCR later.
  248. *
  249. * \param[in] file pointer to file.
  250. * \param[in] buffer Buffer from user space.
  251. * \param[in] count Number of characters to write
  252. * \param[in] data Pointer to the private data structure.
  253. *
  254. * \return number of characters write from User Space.
  255. */
  256. /*----------------------------------------------------------------------------*/
  257. static ssize_t procMCRWrite(struct file *file, const char __user *buffer,
  258. size_t count, loff_t *data)
  259. {
  260. P_GLUE_INFO_T prGlueInfo;
  261. char acBuf[PROC_MCR_ACCESS_MAX_USER_INPUT_LEN + 1]; /* + 1 for "\0" */
  262. int i4CopySize;
  263. PARAM_CUSTOM_MCR_RW_STRUCT_T rMcrInfo;
  264. UINT_32 u4BufLen;
  265. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  266. int num = 0;
  267. ASSERT(data);
  268. i4CopySize = (count < (sizeof(acBuf) - 1)) ? count : (sizeof(acBuf) - 1);
  269. if (copy_from_user(acBuf, buffer, i4CopySize))
  270. return 0;
  271. acBuf[i4CopySize] = '\0';
  272. num = sscanf(acBuf, "0x%x 0x%x", &rMcrInfo.u4McrOffset, &rMcrInfo.u4McrData);
  273. switch (num) {
  274. case 2:
  275. /* NOTE: Sometimes we want to test if bus will still be ok, after accessing
  276. * the MCR which is not align to DW boundary.
  277. */
  278. /* if (IS_ALIGN_4(rMcrInfo.u4McrOffset)) */
  279. {
  280. prGlueInfo = (P_GLUE_INFO_T) netdev_priv((struct net_device *)data);
  281. u4McrOffset = rMcrInfo.u4McrOffset;
  282. /* printk("Write 0x%lx to MCR 0x%04lx\n", */
  283. /* rMcrInfo.u4McrOffset, rMcrInfo.u4McrData); */
  284. rStatus = kalIoctl(prGlueInfo,
  285. wlanoidSetMcrWrite,
  286. (PVOID)&rMcrInfo, sizeof(rMcrInfo), FALSE, FALSE, TRUE, &u4BufLen);
  287. }
  288. break;
  289. case 1:
  290. /* if (IS_ALIGN_4(rMcrInfo.u4McrOffset)) */
  291. {
  292. u4McrOffset = rMcrInfo.u4McrOffset;
  293. }
  294. break;
  295. default:
  296. break;
  297. }
  298. return count;
  299. } /* end of procMCRWrite() */
  300. static const struct file_operations mcr_ops = {
  301. .owner = THIS_MODULE,
  302. .read = procMCRRead,
  303. .write = procMCRWrite,
  304. };
  305. #if CFG_SUPPORT_DEBUG_FS
  306. static ssize_t procRoamRead(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  307. {
  308. UINT_32 u4CopySize;
  309. WLAN_STATUS rStatus;
  310. UINT_32 u4BufLen;
  311. /* if *f_pos > 0, it means has read successed last time, don't try again */
  312. if (*f_pos > 0)
  313. return 0;
  314. rStatus = kalIoctl(g_prGlueInfo_proc, wlanoidGetRoamParams, aucProcBuf, sizeof(aucProcBuf),
  315. TRUE, FALSE, TRUE, &u4BufLen);
  316. if (rStatus != WLAN_STATUS_SUCCESS) {
  317. DBGLOG(INIT, INFO, "failed to read roam params\n");
  318. return -EINVAL;
  319. }
  320. u4CopySize = kalStrLen(aucProcBuf);
  321. if (copy_to_user(buf, aucProcBuf, u4CopySize)) {
  322. pr_err("copy to user failed\n");
  323. return -EFAULT;
  324. }
  325. *f_pos += u4CopySize;
  326. return (INT_32)u4CopySize;
  327. }
  328. static ssize_t procRoamWrite(struct file *file, const char __user *buffer,
  329. size_t count, loff_t *data)
  330. {
  331. WLAN_STATUS rStatus;
  332. UINT_32 u4BufLen = 0;
  333. UINT_32 u4CopySize = sizeof(aucProcBuf);
  334. kalMemSet(aucProcBuf, 0, u4CopySize);
  335. if (u4CopySize >= count+1)
  336. u4CopySize = count;
  337. if (copy_from_user(aucProcBuf, buffer, u4CopySize)) {
  338. pr_err("error of copy from user\n");
  339. return -EFAULT;
  340. }
  341. aucProcBuf[u4CopySize] = '\0';
  342. if (kalStrnCmp(aucProcBuf, "force_roam", 10) == 0)
  343. rStatus = kalIoctl(g_prGlueInfo_proc, wlanoidSetForceRoam, NULL, 0,
  344. FALSE, FALSE, TRUE, &u4BufLen);
  345. else
  346. rStatus = kalIoctl(g_prGlueInfo_proc, wlanoidSetRoamParams, aucProcBuf,
  347. kalStrLen(aucProcBuf), FALSE, FALSE, TRUE, &u4BufLen);
  348. if (rStatus != WLAN_STATUS_SUCCESS) {
  349. DBGLOG(INIT, INFO, "failed to set roam params: %s\n", aucProcBuf);
  350. return -EINVAL;
  351. }
  352. return count;
  353. }
  354. static const struct file_operations roam_ops = {
  355. .owner = THIS_MODULE,
  356. .read = procRoamRead,
  357. .write = procRoamWrite,
  358. };
  359. static ssize_t procCountryRead(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  360. {
  361. UINT_32 u4CopySize;
  362. UINT_16 u2CountryCode = 0;
  363. UINT_32 u4BufLen;
  364. WLAN_STATUS rStatus;
  365. /* if *f_pos > 0, it means has read successed last time, don't try again */
  366. if (*f_pos > 0)
  367. return 0;
  368. rStatus = kalIoctl(g_prGlueInfo_proc, wlanoidGetCountryCode, &u2CountryCode, 2, TRUE, FALSE, TRUE, &u4BufLen);
  369. if (rStatus != WLAN_STATUS_SUCCESS) {
  370. DBGLOG(INIT, INFO, "failed to get country code\n");
  371. return -EINVAL;
  372. }
  373. if (u2CountryCode)
  374. kalSprintf(aucProcBuf, "Current Country Code: %c%c\n", (u2CountryCode>>8) & 0xff, u2CountryCode & 0xff);
  375. else
  376. kalStrCpy(aucProcBuf, "Current Country Code: NULL\n");
  377. u4CopySize = kalStrLen(aucProcBuf);
  378. if (copy_to_user(buf, aucProcBuf, u4CopySize)) {
  379. pr_err("copy to user failed\n");
  380. return -EFAULT;
  381. }
  382. *f_pos += u4CopySize;
  383. return (INT_32)u4CopySize;
  384. }
  385. static ssize_t procCountryWrite(struct file *file, const char __user *buffer,
  386. size_t count, loff_t *data)
  387. {
  388. UINT_32 u4BufLen = 0;
  389. WLAN_STATUS rStatus;
  390. UINT_32 u4CopySize = sizeof(aucProcBuf);
  391. kalMemSet(aucProcBuf, 0, u4CopySize);
  392. if (u4CopySize >= count+1)
  393. u4CopySize = count;
  394. if (copy_from_user(aucProcBuf, buffer, u4CopySize)) {
  395. pr_err("error of copy from user\n");
  396. return -EFAULT;
  397. }
  398. aucProcBuf[u4CopySize] = '\0';
  399. rStatus = kalIoctl(g_prGlueInfo_proc, wlanoidSetCountryCode, &aucProcBuf[0], 2, FALSE, FALSE, TRUE, &u4BufLen);
  400. if (rStatus != WLAN_STATUS_SUCCESS) {
  401. DBGLOG(INIT, INFO, "failed set country code: %s\n", aucProcBuf);
  402. return -EINVAL;
  403. }
  404. return count;
  405. }
  406. static const struct file_operations country_ops = {
  407. .owner = THIS_MODULE,
  408. .read = procCountryRead,
  409. .write = procCountryWrite,
  410. };
  411. #endif
  412. INT_32 procInitFs(VOID)
  413. {
  414. struct proc_dir_entry *prEntry;
  415. if (init_net.proc_net == (struct proc_dir_entry *)NULL) {
  416. pr_err("init proc fs fail: proc_net == NULL\n");
  417. return -ENOENT;
  418. }
  419. /*
  420. * Directory: Root (/proc/net/wlan0)
  421. */
  422. gprProcRoot = proc_mkdir(PROC_ROOT_NAME, init_net.proc_net);
  423. if (!gprProcRoot) {
  424. pr_err("gprProcRoot == NULL\n");
  425. return -ENOENT;
  426. }
  427. proc_set_user(gprProcRoot, KUIDT_INIT(PROC_UID_SHELL), KGIDT_INIT(PROC_GID_WIFI));
  428. prEntry = proc_create(PROC_DBG_LEVEL_NAME, 0664, gprProcRoot, &dbglevel_ops);
  429. if (prEntry == NULL) {
  430. pr_err("Unable to create /proc entry dbgLevel\n\r");
  431. return -1;
  432. }
  433. proc_set_user(prEntry, KUIDT_INIT(PROC_UID_SHELL), KGIDT_INIT(PROC_GID_WIFI));
  434. return 0;
  435. } /* end of procInitProcfs() */
  436. INT_32 procUninitProcFs(VOID)
  437. {
  438. remove_proc_subtree(PROC_ROOT_NAME, init_net.proc_net);
  439. return 0;
  440. }
  441. /*----------------------------------------------------------------------------*/
  442. /*!
  443. * \brief This function clean up a PROC fs created by procInitProcfs().
  444. *
  445. * \param[in] prDev Pointer to the struct net_device.
  446. * \param[in] pucDevName Pointer to the name of net_device.
  447. *
  448. * \return N/A
  449. */
  450. /*----------------------------------------------------------------------------*/
  451. INT_32 procRemoveProcfs(VOID)
  452. {
  453. remove_proc_entry(PROC_MCR_ACCESS, gprProcRoot);
  454. #if CFG_SUPPORT_DEBUG_FS
  455. remove_proc_entry(PROC_ROAM_PARAM, gprProcRoot);
  456. remove_proc_entry(PROC_COUNTRY, gprProcRoot);
  457. #endif
  458. return 0;
  459. } /* end of procRemoveProcfs() */
  460. INT_32 procCreateFsEntry(P_GLUE_INFO_T prGlueInfo)
  461. {
  462. struct proc_dir_entry *prEntry;
  463. DBGLOG(INIT, LOUD, "[%s]\n", __func__);
  464. g_prGlueInfo_proc = prGlueInfo;
  465. prEntry = proc_create(PROC_MCR_ACCESS, 0664, gprProcRoot, &mcr_ops);
  466. if (prEntry == NULL) {
  467. DBGLOG(INIT, ERROR, "Unable to create /proc entry\n\r");
  468. return -1;
  469. }
  470. #if CFG_SUPPORT_DEBUG_FS
  471. prEntry = proc_create(PROC_ROAM_PARAM, 0664, gprProcRoot, &roam_ops);
  472. if (prEntry == NULL) {
  473. DBGLOG(INIT, ERROR, "Unable to create /proc entry\n\r");
  474. return -1;
  475. }
  476. prEntry = proc_create(PROC_COUNTRY, 0664, gprProcRoot, &country_ops);
  477. if (prEntry == NULL) {
  478. DBGLOG(INIT, ERROR, "Unable to create /proc entry\n\r");
  479. return -1;
  480. }
  481. #endif
  482. return 0;
  483. }
  484. #if 0
  485. /*----------------------------------------------------------------------------*/
  486. /*!
  487. * \brief The PROC function for reading Driver Status to User Space.
  488. *
  489. * \param[in] page Buffer provided by kernel.
  490. * \param[in out] start Start Address to read(3 methods).
  491. * \param[in] off Offset.
  492. * \param[in] count Allowable number to read.
  493. * \param[out] eof End of File indication.
  494. * \param[in] data Pointer to the private data structure.
  495. *
  496. * \return number of characters print to the buffer from User Space.
  497. */
  498. /*----------------------------------------------------------------------------*/
  499. static int procDrvStatusRead(char *page, char **start, off_t off, int count, int *eof, void *data)
  500. {
  501. P_GLUE_INFO_T prGlueInfo = ((struct net_device *)data)->priv;
  502. char *p = page;
  503. UINT_32 u4Count;
  504. GLUE_SPIN_LOCK_DECLARATION();
  505. ASSERT(data);
  506. /* Kevin: Apply PROC read method 1. */
  507. if (off != 0)
  508. return 0; /* To indicate end of file. */
  509. SPRINTF(p, ("GLUE LAYER STATUS:"));
  510. SPRINTF(p, ("\n=================="));
  511. SPRINTF(p, ("\n* Number of Pending Frames: %ld\n", prGlueInfo->u4TxPendingFrameNum));
  512. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  513. wlanoidQueryDrvStatusForLinuxProc(prGlueInfo->prAdapter, p, &u4Count);
  514. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  515. u4Count += (UINT_32) (p - page);
  516. *eof = 1;
  517. return (int)u4Count;
  518. } /* end of procDrvStatusRead() */
  519. /*----------------------------------------------------------------------------*/
  520. /*!
  521. * \brief The PROC function for reading Driver RX Statistic Counters to User Space.
  522. *
  523. * \param[in] page Buffer provided by kernel.
  524. * \param[in out] start Start Address to read(3 methods).
  525. * \param[in] off Offset.
  526. * \param[in] count Allowable number to read.
  527. * \param[out] eof End of File indication.
  528. * \param[in] data Pointer to the private data structure.
  529. *
  530. * \return number of characters print to the buffer from User Space.
  531. */
  532. /*----------------------------------------------------------------------------*/
  533. static int procRxStatisticsRead(char *page, char **start, off_t off, int count, int *eof, void *data)
  534. {
  535. P_GLUE_INFO_T prGlueInfo = ((struct net_device *)data)->priv;
  536. char *p = page;
  537. UINT_32 u4Count;
  538. GLUE_SPIN_LOCK_DECLARATION();
  539. ASSERT(data);
  540. /* Kevin: Apply PROC read method 1. */
  541. if (off != 0)
  542. return 0; /* To indicate end of file. */
  543. SPRINTF(p, ("RX STATISTICS (Write 1 to clear):"));
  544. SPRINTF(p, ("\n=================================\n"));
  545. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  546. wlanoidQueryRxStatisticsForLinuxProc(prGlueInfo->prAdapter, p, &u4Count);
  547. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  548. u4Count += (UINT_32) (p - page);
  549. *eof = 1;
  550. return (int)u4Count;
  551. } /* end of procRxStatisticsRead() */
  552. /*----------------------------------------------------------------------------*/
  553. /*!
  554. * \brief The PROC function for reset Driver RX Statistic Counters.
  555. *
  556. * \param[in] file pointer to file.
  557. * \param[in] buffer Buffer from user space.
  558. * \param[in] count Number of characters to write
  559. * \param[in] data Pointer to the private data structure.
  560. *
  561. * \return number of characters write from User Space.
  562. */
  563. /*----------------------------------------------------------------------------*/
  564. static int procRxStatisticsWrite(struct file *file, const char *buffer, unsigned long count, void *data)
  565. {
  566. P_GLUE_INFO_T prGlueInfo = ((struct net_device *)data)->priv;
  567. char acBuf[PROC_RX_STATISTICS_MAX_USER_INPUT_LEN + 1]; /* + 1 for "\0" */
  568. UINT_32 u4CopySize;
  569. UINT_32 u4ClearCounter;
  570. GLUE_SPIN_LOCK_DECLARATION();
  571. ASSERT(data);
  572. u4CopySize = (count < (sizeof(acBuf) - 1)) ? count : (sizeof(acBuf) - 1);
  573. copy_from_user(acBuf, buffer, u4CopySize);
  574. acBuf[u4CopySize] = '\0';
  575. if (kstrtouint(acBuf, 0, &u4ClearCounter) == 1) {
  576. if (u4ClearCounter == 1) {
  577. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  578. wlanoidSetRxStatisticsForLinuxProc(prGlueInfo->prAdapter);
  579. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  580. }
  581. }
  582. return count;
  583. } /* end of procRxStatisticsWrite() */
  584. /*----------------------------------------------------------------------------*/
  585. /*!
  586. * \brief The PROC function for reading Driver TX Statistic Counters to User Space.
  587. *
  588. * \param[in] page Buffer provided by kernel.
  589. * \param[in out] start Start Address to read(3 methods).
  590. * \param[in] off Offset.
  591. * \param[in] count Allowable number to read.
  592. * \param[out] eof End of File indication.
  593. * \param[in] data Pointer to the private data structure.
  594. *
  595. * \return number of characters print to the buffer from User Space.
  596. */
  597. /*----------------------------------------------------------------------------*/
  598. static int procTxStatisticsRead(char *page, char **start, off_t off, int count, int *eof, void *data)
  599. {
  600. P_GLUE_INFO_T prGlueInfo = ((struct net_device *)data)->priv;
  601. char *p = page;
  602. UINT_32 u4Count;
  603. GLUE_SPIN_LOCK_DECLARATION();
  604. ASSERT(data);
  605. /* Kevin: Apply PROC read method 1. */
  606. if (off != 0)
  607. return 0; /* To indicate end of file. */
  608. SPRINTF(p, ("TX STATISTICS (Write 1 to clear):"));
  609. SPRINTF(p, ("\n=================================\n"));
  610. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  611. wlanoidQueryTxStatisticsForLinuxProc(prGlueInfo->prAdapter, p, &u4Count);
  612. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  613. u4Count += (UINT_32) (p - page);
  614. *eof = 1;
  615. return (int)u4Count;
  616. } /* end of procTxStatisticsRead() */
  617. /*----------------------------------------------------------------------------*/
  618. /*!
  619. * \brief The PROC function for reset Driver TX Statistic Counters.
  620. *
  621. * \param[in] file pointer to file.
  622. * \param[in] buffer Buffer from user space.
  623. * \param[in] count Number of characters to write
  624. * \param[in] data Pointer to the private data structure.
  625. *
  626. * \return number of characters write from User Space.
  627. */
  628. /*----------------------------------------------------------------------------*/
  629. static int procTxStatisticsWrite(struct file *file, const char *buffer, unsigned long count, void *data)
  630. {
  631. P_GLUE_INFO_T prGlueInfo = ((struct net_device *)data)->priv;
  632. char acBuf[PROC_RX_STATISTICS_MAX_USER_INPUT_LEN + 1]; /* + 1 for "\0" */
  633. UINT_32 u4CopySize;
  634. UINT_32 u4ClearCounter;
  635. GLUE_SPIN_LOCK_DECLARATION();
  636. ASSERT(data);
  637. u4CopySize = (count < (sizeof(acBuf) - 1)) ? count : (sizeof(acBuf) - 1);
  638. copy_from_user(acBuf, buffer, u4CopySize);
  639. acBuf[u4CopySize] = '\0';
  640. if (kstrtouint(acBuf, 0, &u4ClearCounter) == 1) {
  641. if (u4ClearCounter == 1) {
  642. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  643. wlanoidSetTxStatisticsForLinuxProc(prGlueInfo->prAdapter);
  644. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_FSM);
  645. }
  646. }
  647. return count;
  648. } /* end of procTxStatisticsWrite() */
  649. #endif