debugfs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. #include <linux/module.h>
  2. #include <linux/dcache.h>
  3. #include <linux/debugfs.h>
  4. #include <linux/delay.h>
  5. #include <linux/mm.h>
  6. #include <linux/string.h>
  7. #include <net/iw_handler.h>
  8. #include <net/lib80211.h>
  9. #include "dev.h"
  10. #include "decl.h"
  11. #include "host.h"
  12. #include "debugfs.h"
  13. #include "cmd.h"
  14. static struct dentry *lbs_dir;
  15. static char *szStates[] = {
  16. "Connected",
  17. "Disconnected"
  18. };
  19. #ifdef PROC_DEBUG
  20. static void lbs_debug_init(struct lbs_private *priv);
  21. #endif
  22. static int open_file_generic(struct inode *inode, struct file *file)
  23. {
  24. file->private_data = inode->i_private;
  25. return 0;
  26. }
  27. static ssize_t write_file_dummy(struct file *file, const char __user *buf,
  28. size_t count, loff_t *ppos)
  29. {
  30. return -EINVAL;
  31. }
  32. static const size_t len = PAGE_SIZE;
  33. static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
  34. size_t count, loff_t *ppos)
  35. {
  36. struct lbs_private *priv = file->private_data;
  37. size_t pos = 0;
  38. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  39. char *buf = (char *)addr;
  40. ssize_t res;
  41. pos += snprintf(buf+pos, len-pos, "state = %s\n",
  42. szStates[priv->connect_status]);
  43. pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
  44. (u32) priv->regioncode);
  45. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  46. free_page(addr);
  47. return res;
  48. }
  49. static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
  50. size_t count, loff_t *ppos)
  51. {
  52. struct lbs_private *priv = file->private_data;
  53. size_t pos = 0;
  54. int numscansdone = 0, res;
  55. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  56. char *buf = (char *)addr;
  57. DECLARE_SSID_BUF(ssid);
  58. struct bss_descriptor * iter_bss;
  59. pos += snprintf(buf+pos, len-pos,
  60. "# | ch | rssi | bssid | cap | Qual | SSID \n");
  61. mutex_lock(&priv->lock);
  62. list_for_each_entry (iter_bss, &priv->network_list, list) {
  63. u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
  64. u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
  65. u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
  66. pos += snprintf(buf+pos, len-pos, "%02u| %03d | %04d | %pM |",
  67. numscansdone, iter_bss->channel, iter_bss->rssi,
  68. iter_bss->bssid);
  69. pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
  70. pos += snprintf(buf+pos, len-pos, "%c%c%c |",
  71. ibss ? 'A' : 'I', privacy ? 'P' : ' ',
  72. spectrum_mgmt ? 'S' : ' ');
  73. pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
  74. pos += snprintf(buf+pos, len-pos, " %s\n",
  75. print_ssid(ssid, iter_bss->ssid,
  76. iter_bss->ssid_len));
  77. numscansdone++;
  78. }
  79. mutex_unlock(&priv->lock);
  80. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  81. free_page(addr);
  82. return res;
  83. }
  84. static ssize_t lbs_sleepparams_write(struct file *file,
  85. const char __user *user_buf, size_t count,
  86. loff_t *ppos)
  87. {
  88. struct lbs_private *priv = file->private_data;
  89. ssize_t buf_size, ret;
  90. struct sleep_params sp;
  91. int p1, p2, p3, p4, p5, p6;
  92. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  93. char *buf = (char *)addr;
  94. buf_size = min(count, len - 1);
  95. if (copy_from_user(buf, user_buf, buf_size)) {
  96. ret = -EFAULT;
  97. goto out_unlock;
  98. }
  99. ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
  100. if (ret != 6) {
  101. ret = -EINVAL;
  102. goto out_unlock;
  103. }
  104. sp.sp_error = p1;
  105. sp.sp_offset = p2;
  106. sp.sp_stabletime = p3;
  107. sp.sp_calcontrol = p4;
  108. sp.sp_extsleepclk = p5;
  109. sp.sp_reserved = p6;
  110. ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
  111. if (!ret)
  112. ret = count;
  113. else if (ret > 0)
  114. ret = -EINVAL;
  115. out_unlock:
  116. free_page(addr);
  117. return ret;
  118. }
  119. static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
  120. size_t count, loff_t *ppos)
  121. {
  122. struct lbs_private *priv = file->private_data;
  123. ssize_t ret;
  124. size_t pos = 0;
  125. struct sleep_params sp;
  126. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  127. char *buf = (char *)addr;
  128. ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
  129. if (ret)
  130. goto out_unlock;
  131. pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
  132. sp.sp_offset, sp.sp_stabletime,
  133. sp.sp_calcontrol, sp.sp_extsleepclk,
  134. sp.sp_reserved);
  135. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  136. out_unlock:
  137. free_page(addr);
  138. return ret;
  139. }
  140. /*
  141. * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
  142. * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
  143. * firmware. Here's an example:
  144. * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
  145. * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
  146. * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  147. *
  148. * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
  149. * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
  150. * defined in mrvlietypes_thresholds
  151. *
  152. * This function searches in this TLV data chunk for a given TLV type
  153. * and returns a pointer to the first data byte of the TLV, or to NULL
  154. * if the TLV hasn't been found.
  155. */
  156. static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
  157. {
  158. struct mrvlietypesheader *tlv_h;
  159. uint16_t length;
  160. ssize_t pos = 0;
  161. while (pos < size) {
  162. tlv_h = (struct mrvlietypesheader *) tlv;
  163. if (!tlv_h->len)
  164. return NULL;
  165. if (tlv_h->type == cpu_to_le16(tlv_type))
  166. return tlv_h;
  167. length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
  168. pos += length;
  169. tlv += length;
  170. }
  171. return NULL;
  172. }
  173. static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
  174. struct file *file, char __user *userbuf,
  175. size_t count, loff_t *ppos)
  176. {
  177. struct cmd_ds_802_11_subscribe_event *subscribed;
  178. struct mrvlietypes_thresholds *got;
  179. struct lbs_private *priv = file->private_data;
  180. ssize_t ret = 0;
  181. size_t pos = 0;
  182. char *buf;
  183. u8 value;
  184. u8 freq;
  185. int events = 0;
  186. buf = (char *)get_zeroed_page(GFP_KERNEL);
  187. if (!buf)
  188. return -ENOMEM;
  189. subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
  190. if (!subscribed) {
  191. ret = -ENOMEM;
  192. goto out_page;
  193. }
  194. subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
  195. subscribed->action = cpu_to_le16(CMD_ACT_GET);
  196. ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
  197. if (ret)
  198. goto out_cmd;
  199. got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
  200. if (got) {
  201. value = got->value;
  202. freq = got->freq;
  203. events = le16_to_cpu(subscribed->events);
  204. pos += snprintf(buf, len, "%d %d %d\n", value, freq,
  205. !!(events & event_mask));
  206. }
  207. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  208. out_cmd:
  209. kfree(subscribed);
  210. out_page:
  211. free_page((unsigned long)buf);
  212. return ret;
  213. }
  214. static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
  215. struct file *file,
  216. const char __user *userbuf, size_t count,
  217. loff_t *ppos)
  218. {
  219. struct cmd_ds_802_11_subscribe_event *events;
  220. struct mrvlietypes_thresholds *tlv;
  221. struct lbs_private *priv = file->private_data;
  222. ssize_t buf_size;
  223. int value, freq, new_mask;
  224. uint16_t curr_mask;
  225. char *buf;
  226. int ret;
  227. buf = (char *)get_zeroed_page(GFP_KERNEL);
  228. if (!buf)
  229. return -ENOMEM;
  230. buf_size = min(count, len - 1);
  231. if (copy_from_user(buf, userbuf, buf_size)) {
  232. ret = -EFAULT;
  233. goto out_page;
  234. }
  235. ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
  236. if (ret != 3) {
  237. ret = -EINVAL;
  238. goto out_page;
  239. }
  240. events = kzalloc(sizeof(*events), GFP_KERNEL);
  241. if (!events) {
  242. ret = -ENOMEM;
  243. goto out_page;
  244. }
  245. events->hdr.size = cpu_to_le16(sizeof(*events));
  246. events->action = cpu_to_le16(CMD_ACT_GET);
  247. ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
  248. if (ret)
  249. goto out_events;
  250. curr_mask = le16_to_cpu(events->events);
  251. if (new_mask)
  252. new_mask = curr_mask | event_mask;
  253. else
  254. new_mask = curr_mask & ~event_mask;
  255. /* Now everything is set and we can send stuff down to the firmware */
  256. tlv = (void *)events->tlv;
  257. events->action = cpu_to_le16(CMD_ACT_SET);
  258. events->events = cpu_to_le16(new_mask);
  259. tlv->header.type = cpu_to_le16(tlv_type);
  260. tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
  261. tlv->value = value;
  262. if (tlv_type != TLV_TYPE_BCNMISS)
  263. tlv->freq = freq;
  264. /* The command header, the action, the event mask, and one TLV */
  265. events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
  266. ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
  267. if (!ret)
  268. ret = count;
  269. out_events:
  270. kfree(events);
  271. out_page:
  272. free_page((unsigned long)buf);
  273. return ret;
  274. }
  275. static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
  276. size_t count, loff_t *ppos)
  277. {
  278. return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
  279. file, userbuf, count, ppos);
  280. }
  281. static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
  282. size_t count, loff_t *ppos)
  283. {
  284. return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
  285. file, userbuf, count, ppos);
  286. }
  287. static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
  288. size_t count, loff_t *ppos)
  289. {
  290. return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
  291. file, userbuf, count, ppos);
  292. }
  293. static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
  294. size_t count, loff_t *ppos)
  295. {
  296. return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
  297. file, userbuf, count, ppos);
  298. }
  299. static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
  300. size_t count, loff_t *ppos)
  301. {
  302. return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
  303. file, userbuf, count, ppos);
  304. }
  305. static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
  306. size_t count, loff_t *ppos)
  307. {
  308. return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
  309. file, userbuf, count, ppos);
  310. }
  311. static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
  312. size_t count, loff_t *ppos)
  313. {
  314. return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
  315. file, userbuf, count, ppos);
  316. }
  317. static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
  318. size_t count, loff_t *ppos)
  319. {
  320. return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
  321. file, userbuf, count, ppos);
  322. }
  323. static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
  324. size_t count, loff_t *ppos)
  325. {
  326. return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
  327. file, userbuf, count, ppos);
  328. }
  329. static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
  330. size_t count, loff_t *ppos)
  331. {
  332. return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
  333. file, userbuf, count, ppos);
  334. }
  335. static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
  336. size_t count, loff_t *ppos)
  337. {
  338. return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
  339. file, userbuf, count, ppos);
  340. }
  341. static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
  342. size_t count, loff_t *ppos)
  343. {
  344. return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
  345. file, userbuf, count, ppos);
  346. }
  347. static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
  348. size_t count, loff_t *ppos)
  349. {
  350. struct lbs_private *priv = file->private_data;
  351. struct lbs_offset_value offval;
  352. ssize_t pos = 0;
  353. int ret;
  354. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  355. char *buf = (char *)addr;
  356. offval.offset = priv->mac_offset;
  357. offval.value = 0;
  358. ret = lbs_prepare_and_send_command(priv,
  359. CMD_MAC_REG_ACCESS, 0,
  360. CMD_OPTION_WAITFORRSP, 0, &offval);
  361. mdelay(10);
  362. pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
  363. priv->mac_offset, priv->offsetvalue.value);
  364. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  365. free_page(addr);
  366. return ret;
  367. }
  368. static ssize_t lbs_rdmac_write(struct file *file,
  369. const char __user *userbuf,
  370. size_t count, loff_t *ppos)
  371. {
  372. struct lbs_private *priv = file->private_data;
  373. ssize_t res, buf_size;
  374. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  375. char *buf = (char *)addr;
  376. buf_size = min(count, len - 1);
  377. if (copy_from_user(buf, userbuf, buf_size)) {
  378. res = -EFAULT;
  379. goto out_unlock;
  380. }
  381. priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
  382. res = count;
  383. out_unlock:
  384. free_page(addr);
  385. return res;
  386. }
  387. static ssize_t lbs_wrmac_write(struct file *file,
  388. const char __user *userbuf,
  389. size_t count, loff_t *ppos)
  390. {
  391. struct lbs_private *priv = file->private_data;
  392. ssize_t res, buf_size;
  393. u32 offset, value;
  394. struct lbs_offset_value offval;
  395. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  396. char *buf = (char *)addr;
  397. buf_size = min(count, len - 1);
  398. if (copy_from_user(buf, userbuf, buf_size)) {
  399. res = -EFAULT;
  400. goto out_unlock;
  401. }
  402. res = sscanf(buf, "%x %x", &offset, &value);
  403. if (res != 2) {
  404. res = -EFAULT;
  405. goto out_unlock;
  406. }
  407. offval.offset = offset;
  408. offval.value = value;
  409. res = lbs_prepare_and_send_command(priv,
  410. CMD_MAC_REG_ACCESS, 1,
  411. CMD_OPTION_WAITFORRSP, 0, &offval);
  412. mdelay(10);
  413. res = count;
  414. out_unlock:
  415. free_page(addr);
  416. return res;
  417. }
  418. static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
  419. size_t count, loff_t *ppos)
  420. {
  421. struct lbs_private *priv = file->private_data;
  422. struct lbs_offset_value offval;
  423. ssize_t pos = 0;
  424. int ret;
  425. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  426. char *buf = (char *)addr;
  427. offval.offset = priv->bbp_offset;
  428. offval.value = 0;
  429. ret = lbs_prepare_and_send_command(priv,
  430. CMD_BBP_REG_ACCESS, 0,
  431. CMD_OPTION_WAITFORRSP, 0, &offval);
  432. mdelay(10);
  433. pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
  434. priv->bbp_offset, priv->offsetvalue.value);
  435. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  436. free_page(addr);
  437. return ret;
  438. }
  439. static ssize_t lbs_rdbbp_write(struct file *file,
  440. const char __user *userbuf,
  441. size_t count, loff_t *ppos)
  442. {
  443. struct lbs_private *priv = file->private_data;
  444. ssize_t res, buf_size;
  445. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  446. char *buf = (char *)addr;
  447. buf_size = min(count, len - 1);
  448. if (copy_from_user(buf, userbuf, buf_size)) {
  449. res = -EFAULT;
  450. goto out_unlock;
  451. }
  452. priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
  453. res = count;
  454. out_unlock:
  455. free_page(addr);
  456. return res;
  457. }
  458. static ssize_t lbs_wrbbp_write(struct file *file,
  459. const char __user *userbuf,
  460. size_t count, loff_t *ppos)
  461. {
  462. struct lbs_private *priv = file->private_data;
  463. ssize_t res, buf_size;
  464. u32 offset, value;
  465. struct lbs_offset_value offval;
  466. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  467. char *buf = (char *)addr;
  468. buf_size = min(count, len - 1);
  469. if (copy_from_user(buf, userbuf, buf_size)) {
  470. res = -EFAULT;
  471. goto out_unlock;
  472. }
  473. res = sscanf(buf, "%x %x", &offset, &value);
  474. if (res != 2) {
  475. res = -EFAULT;
  476. goto out_unlock;
  477. }
  478. offval.offset = offset;
  479. offval.value = value;
  480. res = lbs_prepare_and_send_command(priv,
  481. CMD_BBP_REG_ACCESS, 1,
  482. CMD_OPTION_WAITFORRSP, 0, &offval);
  483. mdelay(10);
  484. res = count;
  485. out_unlock:
  486. free_page(addr);
  487. return res;
  488. }
  489. static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
  490. size_t count, loff_t *ppos)
  491. {
  492. struct lbs_private *priv = file->private_data;
  493. struct lbs_offset_value offval;
  494. ssize_t pos = 0;
  495. int ret;
  496. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  497. char *buf = (char *)addr;
  498. offval.offset = priv->rf_offset;
  499. offval.value = 0;
  500. ret = lbs_prepare_and_send_command(priv,
  501. CMD_RF_REG_ACCESS, 0,
  502. CMD_OPTION_WAITFORRSP, 0, &offval);
  503. mdelay(10);
  504. pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
  505. priv->rf_offset, priv->offsetvalue.value);
  506. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  507. free_page(addr);
  508. return ret;
  509. }
  510. static ssize_t lbs_rdrf_write(struct file *file,
  511. const char __user *userbuf,
  512. size_t count, loff_t *ppos)
  513. {
  514. struct lbs_private *priv = file->private_data;
  515. ssize_t res, buf_size;
  516. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  517. char *buf = (char *)addr;
  518. buf_size = min(count, len - 1);
  519. if (copy_from_user(buf, userbuf, buf_size)) {
  520. res = -EFAULT;
  521. goto out_unlock;
  522. }
  523. priv->rf_offset = simple_strtoul(buf, NULL, 16);
  524. res = count;
  525. out_unlock:
  526. free_page(addr);
  527. return res;
  528. }
  529. static ssize_t lbs_wrrf_write(struct file *file,
  530. const char __user *userbuf,
  531. size_t count, loff_t *ppos)
  532. {
  533. struct lbs_private *priv = file->private_data;
  534. ssize_t res, buf_size;
  535. u32 offset, value;
  536. struct lbs_offset_value offval;
  537. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  538. char *buf = (char *)addr;
  539. buf_size = min(count, len - 1);
  540. if (copy_from_user(buf, userbuf, buf_size)) {
  541. res = -EFAULT;
  542. goto out_unlock;
  543. }
  544. res = sscanf(buf, "%x %x", &offset, &value);
  545. if (res != 2) {
  546. res = -EFAULT;
  547. goto out_unlock;
  548. }
  549. offval.offset = offset;
  550. offval.value = value;
  551. res = lbs_prepare_and_send_command(priv,
  552. CMD_RF_REG_ACCESS, 1,
  553. CMD_OPTION_WAITFORRSP, 0, &offval);
  554. mdelay(10);
  555. res = count;
  556. out_unlock:
  557. free_page(addr);
  558. return res;
  559. }
  560. #define FOPS(fread, fwrite) { \
  561. .owner = THIS_MODULE, \
  562. .open = open_file_generic, \
  563. .read = (fread), \
  564. .write = (fwrite), \
  565. }
  566. struct lbs_debugfs_files {
  567. const char *name;
  568. int perm;
  569. struct file_operations fops;
  570. };
  571. static const struct lbs_debugfs_files debugfs_files[] = {
  572. { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
  573. { "getscantable", 0444, FOPS(lbs_getscantable,
  574. write_file_dummy), },
  575. { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
  576. lbs_sleepparams_write), },
  577. };
  578. static const struct lbs_debugfs_files debugfs_events_files[] = {
  579. {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
  580. lbs_lowrssi_write), },
  581. {"low_snr", 0644, FOPS(lbs_lowsnr_read,
  582. lbs_lowsnr_write), },
  583. {"failure_count", 0644, FOPS(lbs_failcount_read,
  584. lbs_failcount_write), },
  585. {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
  586. lbs_bcnmiss_write), },
  587. {"high_rssi", 0644, FOPS(lbs_highrssi_read,
  588. lbs_highrssi_write), },
  589. {"high_snr", 0644, FOPS(lbs_highsnr_read,
  590. lbs_highsnr_write), },
  591. };
  592. static const struct lbs_debugfs_files debugfs_regs_files[] = {
  593. {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
  594. {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
  595. {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
  596. {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
  597. {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
  598. {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
  599. };
  600. void lbs_debugfs_init(void)
  601. {
  602. if (!lbs_dir)
  603. lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
  604. return;
  605. }
  606. void lbs_debugfs_remove(void)
  607. {
  608. if (lbs_dir)
  609. debugfs_remove(lbs_dir);
  610. return;
  611. }
  612. void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
  613. {
  614. int i;
  615. const struct lbs_debugfs_files *files;
  616. if (!lbs_dir)
  617. goto exit;
  618. priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
  619. if (!priv->debugfs_dir)
  620. goto exit;
  621. for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
  622. files = &debugfs_files[i];
  623. priv->debugfs_files[i] = debugfs_create_file(files->name,
  624. files->perm,
  625. priv->debugfs_dir,
  626. priv,
  627. &files->fops);
  628. }
  629. priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
  630. if (!priv->events_dir)
  631. goto exit;
  632. for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
  633. files = &debugfs_events_files[i];
  634. priv->debugfs_events_files[i] = debugfs_create_file(files->name,
  635. files->perm,
  636. priv->events_dir,
  637. priv,
  638. &files->fops);
  639. }
  640. priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
  641. if (!priv->regs_dir)
  642. goto exit;
  643. for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
  644. files = &debugfs_regs_files[i];
  645. priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
  646. files->perm,
  647. priv->regs_dir,
  648. priv,
  649. &files->fops);
  650. }
  651. #ifdef PROC_DEBUG
  652. lbs_debug_init(priv);
  653. #endif
  654. exit:
  655. return;
  656. }
  657. void lbs_debugfs_remove_one(struct lbs_private *priv)
  658. {
  659. int i;
  660. for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
  661. debugfs_remove(priv->debugfs_regs_files[i]);
  662. debugfs_remove(priv->regs_dir);
  663. for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
  664. debugfs_remove(priv->debugfs_events_files[i]);
  665. debugfs_remove(priv->events_dir);
  666. #ifdef PROC_DEBUG
  667. debugfs_remove(priv->debugfs_debug);
  668. #endif
  669. for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
  670. debugfs_remove(priv->debugfs_files[i]);
  671. debugfs_remove(priv->debugfs_dir);
  672. }
  673. /* debug entry */
  674. #ifdef PROC_DEBUG
  675. #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
  676. #define item_addr(n) (offsetof(struct lbs_private, n))
  677. struct debug_data {
  678. char name[32];
  679. u32 size;
  680. size_t addr;
  681. };
  682. /* To debug any member of struct lbs_private, simply add one line here.
  683. */
  684. static struct debug_data items[] = {
  685. {"psmode", item_size(psmode), item_addr(psmode)},
  686. {"psstate", item_size(psstate), item_addr(psstate)},
  687. };
  688. static int num_of_items = ARRAY_SIZE(items);
  689. /**
  690. * @brief proc read function
  691. *
  692. * @param page pointer to buffer
  693. * @param s read data starting position
  694. * @param off offset
  695. * @param cnt counter
  696. * @param eof end of file flag
  697. * @param data data to output
  698. * @return number of output data
  699. */
  700. static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
  701. size_t count, loff_t *ppos)
  702. {
  703. int val = 0;
  704. size_t pos = 0;
  705. ssize_t res;
  706. char *p;
  707. int i;
  708. struct debug_data *d;
  709. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  710. char *buf = (char *)addr;
  711. p = buf;
  712. d = (struct debug_data *)file->private_data;
  713. for (i = 0; i < num_of_items; i++) {
  714. if (d[i].size == 1)
  715. val = *((u8 *) d[i].addr);
  716. else if (d[i].size == 2)
  717. val = *((u16 *) d[i].addr);
  718. else if (d[i].size == 4)
  719. val = *((u32 *) d[i].addr);
  720. else if (d[i].size == 8)
  721. val = *((u64 *) d[i].addr);
  722. pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
  723. }
  724. res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
  725. free_page(addr);
  726. return res;
  727. }
  728. /**
  729. * @brief proc write function
  730. *
  731. * @param f file pointer
  732. * @param buf pointer to data buffer
  733. * @param cnt data number to write
  734. * @param data data to write
  735. * @return number of data
  736. */
  737. static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
  738. size_t cnt, loff_t *ppos)
  739. {
  740. int r, i;
  741. char *pdata;
  742. char *p;
  743. char *p0;
  744. char *p1;
  745. char *p2;
  746. struct debug_data *d = (struct debug_data *)f->private_data;
  747. pdata = kmalloc(cnt, GFP_KERNEL);
  748. if (pdata == NULL)
  749. return 0;
  750. if (copy_from_user(pdata, buf, cnt)) {
  751. lbs_deb_debugfs("Copy from user failed\n");
  752. kfree(pdata);
  753. return 0;
  754. }
  755. p0 = pdata;
  756. for (i = 0; i < num_of_items; i++) {
  757. do {
  758. p = strstr(p0, d[i].name);
  759. if (p == NULL)
  760. break;
  761. p1 = strchr(p, '\n');
  762. if (p1 == NULL)
  763. break;
  764. p0 = p1++;
  765. p2 = strchr(p, '=');
  766. if (!p2)
  767. break;
  768. p2++;
  769. r = simple_strtoul(p2, NULL, 0);
  770. if (d[i].size == 1)
  771. *((u8 *) d[i].addr) = (u8) r;
  772. else if (d[i].size == 2)
  773. *((u16 *) d[i].addr) = (u16) r;
  774. else if (d[i].size == 4)
  775. *((u32 *) d[i].addr) = (u32) r;
  776. else if (d[i].size == 8)
  777. *((u64 *) d[i].addr) = (u64) r;
  778. break;
  779. } while (1);
  780. }
  781. kfree(pdata);
  782. return (ssize_t)cnt;
  783. }
  784. static const struct file_operations lbs_debug_fops = {
  785. .owner = THIS_MODULE,
  786. .open = open_file_generic,
  787. .write = lbs_debugfs_write,
  788. .read = lbs_debugfs_read,
  789. };
  790. /**
  791. * @brief create debug proc file
  792. *
  793. * @param priv pointer struct lbs_private
  794. * @param dev pointer net_device
  795. * @return N/A
  796. */
  797. static void lbs_debug_init(struct lbs_private *priv)
  798. {
  799. int i;
  800. if (!priv->debugfs_dir)
  801. return;
  802. for (i = 0; i < num_of_items; i++)
  803. items[i].addr += (size_t) priv;
  804. priv->debugfs_debug = debugfs_create_file("debug", 0644,
  805. priv->debugfs_dir, &items[0],
  806. &lbs_debug_fops);
  807. }
  808. #endif