debugfs.c 23 KB

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