rt2x00debug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00lib
  19. Abstract: rt2x00 debugfs specific routines.
  20. */
  21. #include <linux/debugfs.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/poll.h>
  25. #include <linux/sched.h>
  26. #include <linux/slab.h>
  27. #include <linux/uaccess.h>
  28. #include "rt2x00.h"
  29. #include "rt2x00lib.h"
  30. #include "rt2x00dump.h"
  31. #define MAX_LINE_LENGTH 64
  32. struct rt2x00debug_crypto {
  33. unsigned long success;
  34. unsigned long icv_error;
  35. unsigned long mic_error;
  36. unsigned long key_error;
  37. };
  38. struct rt2x00debug_intf {
  39. /*
  40. * Pointer to driver structure where
  41. * this debugfs entry belongs to.
  42. */
  43. struct rt2x00_dev *rt2x00dev;
  44. /*
  45. * Reference to the rt2x00debug structure
  46. * which can be used to communicate with
  47. * the registers.
  48. */
  49. const struct rt2x00debug *debug;
  50. /*
  51. * Debugfs entries for:
  52. * - driver folder
  53. * - driver file
  54. * - chipset file
  55. * - device state flags file
  56. * - device capability flags file
  57. * - register folder
  58. * - csr offset/value files
  59. * - eeprom offset/value files
  60. * - bbp offset/value files
  61. * - rf offset/value files
  62. * - queue folder
  63. * - frame dump file
  64. * - queue stats file
  65. * - crypto stats file
  66. */
  67. struct dentry *driver_folder;
  68. struct dentry *driver_entry;
  69. struct dentry *chipset_entry;
  70. struct dentry *dev_flags;
  71. struct dentry *cap_flags;
  72. struct dentry *register_folder;
  73. struct dentry *csr_off_entry;
  74. struct dentry *csr_val_entry;
  75. struct dentry *eeprom_off_entry;
  76. struct dentry *eeprom_val_entry;
  77. struct dentry *bbp_off_entry;
  78. struct dentry *bbp_val_entry;
  79. struct dentry *rf_off_entry;
  80. struct dentry *rf_val_entry;
  81. struct dentry *queue_folder;
  82. struct dentry *queue_frame_dump_entry;
  83. struct dentry *queue_stats_entry;
  84. struct dentry *crypto_stats_entry;
  85. /*
  86. * The frame dump file only allows a single reader,
  87. * so we need to store the current state here.
  88. */
  89. unsigned long frame_dump_flags;
  90. #define FRAME_DUMP_FILE_OPEN 1
  91. /*
  92. * We queue each frame before dumping it to the user,
  93. * per read command we will pass a single skb structure
  94. * so we should be prepared to queue multiple sk buffers
  95. * before sending it to userspace.
  96. */
  97. struct sk_buff_head frame_dump_skbqueue;
  98. wait_queue_head_t frame_dump_waitqueue;
  99. /*
  100. * HW crypto statistics.
  101. * All statistics are stored separately per cipher type.
  102. */
  103. struct rt2x00debug_crypto crypto_stats[CIPHER_MAX];
  104. /*
  105. * Driver and chipset files will use a data buffer
  106. * that has been created in advance. This will simplify
  107. * the code since we can use the debugfs functions.
  108. */
  109. struct debugfs_blob_wrapper driver_blob;
  110. struct debugfs_blob_wrapper chipset_blob;
  111. /*
  112. * Requested offset for each register type.
  113. */
  114. unsigned int offset_csr;
  115. unsigned int offset_eeprom;
  116. unsigned int offset_bbp;
  117. unsigned int offset_rf;
  118. };
  119. void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  120. struct rxdone_entry_desc *rxdesc)
  121. {
  122. struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
  123. enum cipher cipher = rxdesc->cipher;
  124. enum rx_crypto status = rxdesc->cipher_status;
  125. if (cipher == CIPHER_TKIP_NO_MIC)
  126. cipher = CIPHER_TKIP;
  127. if (cipher == CIPHER_NONE || cipher >= CIPHER_MAX)
  128. return;
  129. /* Remove CIPHER_NONE index */
  130. cipher--;
  131. intf->crypto_stats[cipher].success += (status == RX_CRYPTO_SUCCESS);
  132. intf->crypto_stats[cipher].icv_error += (status == RX_CRYPTO_FAIL_ICV);
  133. intf->crypto_stats[cipher].mic_error += (status == RX_CRYPTO_FAIL_MIC);
  134. intf->crypto_stats[cipher].key_error += (status == RX_CRYPTO_FAIL_KEY);
  135. }
  136. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  137. enum rt2x00_dump_type type, struct sk_buff *skb)
  138. {
  139. struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
  140. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  141. struct sk_buff *skbcopy;
  142. struct rt2x00dump_hdr *dump_hdr;
  143. struct timeval timestamp;
  144. u32 data_len;
  145. if (likely(!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)))
  146. return;
  147. do_gettimeofday(&timestamp);
  148. if (skb_queue_len(&intf->frame_dump_skbqueue) > 20) {
  149. DEBUG(rt2x00dev, "txrx dump queue length exceeded.\n");
  150. return;
  151. }
  152. data_len = skb->len;
  153. if (skbdesc->flags & SKBDESC_DESC_IN_SKB)
  154. data_len -= skbdesc->desc_len;
  155. skbcopy = alloc_skb(sizeof(*dump_hdr) + skbdesc->desc_len + data_len,
  156. GFP_ATOMIC);
  157. if (!skbcopy) {
  158. DEBUG(rt2x00dev, "Failed to copy skb for dump.\n");
  159. return;
  160. }
  161. dump_hdr = (struct rt2x00dump_hdr *)skb_put(skbcopy, sizeof(*dump_hdr));
  162. dump_hdr->version = cpu_to_le32(DUMP_HEADER_VERSION);
  163. dump_hdr->header_length = cpu_to_le32(sizeof(*dump_hdr));
  164. dump_hdr->desc_length = cpu_to_le32(skbdesc->desc_len);
  165. dump_hdr->data_length = cpu_to_le32(data_len);
  166. dump_hdr->chip_rt = cpu_to_le16(rt2x00dev->chip.rt);
  167. dump_hdr->chip_rf = cpu_to_le16(rt2x00dev->chip.rf);
  168. dump_hdr->chip_rev = cpu_to_le16(rt2x00dev->chip.rev);
  169. dump_hdr->type = cpu_to_le16(type);
  170. dump_hdr->queue_index = skbdesc->entry->queue->qid;
  171. dump_hdr->entry_index = skbdesc->entry->entry_idx;
  172. dump_hdr->timestamp_sec = cpu_to_le32(timestamp.tv_sec);
  173. dump_hdr->timestamp_usec = cpu_to_le32(timestamp.tv_usec);
  174. if (!(skbdesc->flags & SKBDESC_DESC_IN_SKB))
  175. memcpy(skb_put(skbcopy, skbdesc->desc_len), skbdesc->desc,
  176. skbdesc->desc_len);
  177. memcpy(skb_put(skbcopy, skb->len), skb->data, skb->len);
  178. skb_queue_tail(&intf->frame_dump_skbqueue, skbcopy);
  179. wake_up_interruptible(&intf->frame_dump_waitqueue);
  180. /*
  181. * Verify that the file has not been closed while we were working.
  182. */
  183. if (!test_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags))
  184. skb_queue_purge(&intf->frame_dump_skbqueue);
  185. }
  186. EXPORT_SYMBOL_GPL(rt2x00debug_dump_frame);
  187. static int rt2x00debug_file_open(struct inode *inode, struct file *file)
  188. {
  189. struct rt2x00debug_intf *intf = inode->i_private;
  190. file->private_data = inode->i_private;
  191. if (!try_module_get(intf->debug->owner))
  192. return -EBUSY;
  193. return 0;
  194. }
  195. static int rt2x00debug_file_release(struct inode *inode, struct file *file)
  196. {
  197. struct rt2x00debug_intf *intf = file->private_data;
  198. module_put(intf->debug->owner);
  199. return 0;
  200. }
  201. static int rt2x00debug_open_queue_dump(struct inode *inode, struct file *file)
  202. {
  203. struct rt2x00debug_intf *intf = inode->i_private;
  204. int retval;
  205. retval = rt2x00debug_file_open(inode, file);
  206. if (retval)
  207. return retval;
  208. if (test_and_set_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags)) {
  209. rt2x00debug_file_release(inode, file);
  210. return -EBUSY;
  211. }
  212. return 0;
  213. }
  214. static int rt2x00debug_release_queue_dump(struct inode *inode, struct file *file)
  215. {
  216. struct rt2x00debug_intf *intf = inode->i_private;
  217. skb_queue_purge(&intf->frame_dump_skbqueue);
  218. clear_bit(FRAME_DUMP_FILE_OPEN, &intf->frame_dump_flags);
  219. return rt2x00debug_file_release(inode, file);
  220. }
  221. static ssize_t rt2x00debug_read_queue_dump(struct file *file,
  222. char __user *buf,
  223. size_t length,
  224. loff_t *offset)
  225. {
  226. struct rt2x00debug_intf *intf = file->private_data;
  227. struct sk_buff *skb;
  228. size_t status;
  229. int retval;
  230. if (file->f_flags & O_NONBLOCK)
  231. return -EAGAIN;
  232. retval =
  233. wait_event_interruptible(intf->frame_dump_waitqueue,
  234. (skb =
  235. skb_dequeue(&intf->frame_dump_skbqueue)));
  236. if (retval)
  237. return retval;
  238. status = min((size_t)skb->len, length);
  239. if (copy_to_user(buf, skb->data, status)) {
  240. status = -EFAULT;
  241. goto exit;
  242. }
  243. *offset += status;
  244. exit:
  245. kfree_skb(skb);
  246. return status;
  247. }
  248. static unsigned int rt2x00debug_poll_queue_dump(struct file *file,
  249. poll_table *wait)
  250. {
  251. struct rt2x00debug_intf *intf = file->private_data;
  252. poll_wait(file, &intf->frame_dump_waitqueue, wait);
  253. if (!skb_queue_empty(&intf->frame_dump_skbqueue))
  254. return POLLOUT | POLLWRNORM;
  255. return 0;
  256. }
  257. static const struct file_operations rt2x00debug_fop_queue_dump = {
  258. .owner = THIS_MODULE,
  259. .read = rt2x00debug_read_queue_dump,
  260. .poll = rt2x00debug_poll_queue_dump,
  261. .open = rt2x00debug_open_queue_dump,
  262. .release = rt2x00debug_release_queue_dump,
  263. .llseek = default_llseek,
  264. };
  265. static ssize_t rt2x00debug_read_queue_stats(struct file *file,
  266. char __user *buf,
  267. size_t length,
  268. loff_t *offset)
  269. {
  270. struct rt2x00debug_intf *intf = file->private_data;
  271. struct data_queue *queue;
  272. unsigned long irqflags;
  273. unsigned int lines = 1 + intf->rt2x00dev->data_queues;
  274. size_t size;
  275. char *data;
  276. char *temp;
  277. if (*offset)
  278. return 0;
  279. data = kcalloc(lines, MAX_LINE_LENGTH, GFP_KERNEL);
  280. if (!data)
  281. return -ENOMEM;
  282. temp = data +
  283. sprintf(data, "qid\tflags\t\tcount\tlimit\tlength\tindex\tdma done\tdone\n");
  284. queue_for_each(intf->rt2x00dev, queue) {
  285. spin_lock_irqsave(&queue->index_lock, irqflags);
  286. temp += sprintf(temp, "%d\t0x%.8x\t%d\t%d\t%d\t%d\t%d\t\t%d\n",
  287. queue->qid, (unsigned int)queue->flags,
  288. queue->count, queue->limit, queue->length,
  289. queue->index[Q_INDEX],
  290. queue->index[Q_INDEX_DMA_DONE],
  291. queue->index[Q_INDEX_DONE]);
  292. spin_unlock_irqrestore(&queue->index_lock, irqflags);
  293. }
  294. size = strlen(data);
  295. size = min(size, length);
  296. if (copy_to_user(buf, data, size)) {
  297. kfree(data);
  298. return -EFAULT;
  299. }
  300. kfree(data);
  301. *offset += size;
  302. return size;
  303. }
  304. static const struct file_operations rt2x00debug_fop_queue_stats = {
  305. .owner = THIS_MODULE,
  306. .read = rt2x00debug_read_queue_stats,
  307. .open = rt2x00debug_file_open,
  308. .release = rt2x00debug_file_release,
  309. .llseek = default_llseek,
  310. };
  311. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  312. static ssize_t rt2x00debug_read_crypto_stats(struct file *file,
  313. char __user *buf,
  314. size_t length,
  315. loff_t *offset)
  316. {
  317. struct rt2x00debug_intf *intf = file->private_data;
  318. static const char * const name[] = { "WEP64", "WEP128", "TKIP", "AES" };
  319. char *data;
  320. char *temp;
  321. size_t size;
  322. unsigned int i;
  323. if (*offset)
  324. return 0;
  325. data = kzalloc((1 + CIPHER_MAX) * MAX_LINE_LENGTH, GFP_KERNEL);
  326. if (!data)
  327. return -ENOMEM;
  328. temp = data;
  329. temp += sprintf(data, "cipher\tsuccess\ticv err\tmic err\tkey err\n");
  330. for (i = 0; i < CIPHER_MAX; i++) {
  331. temp += sprintf(temp, "%s\t%lu\t%lu\t%lu\t%lu\n", name[i],
  332. intf->crypto_stats[i].success,
  333. intf->crypto_stats[i].icv_error,
  334. intf->crypto_stats[i].mic_error,
  335. intf->crypto_stats[i].key_error);
  336. }
  337. size = strlen(data);
  338. size = min(size, length);
  339. if (copy_to_user(buf, data, size)) {
  340. kfree(data);
  341. return -EFAULT;
  342. }
  343. kfree(data);
  344. *offset += size;
  345. return size;
  346. }
  347. static const struct file_operations rt2x00debug_fop_crypto_stats = {
  348. .owner = THIS_MODULE,
  349. .read = rt2x00debug_read_crypto_stats,
  350. .open = rt2x00debug_file_open,
  351. .release = rt2x00debug_file_release,
  352. .llseek = default_llseek,
  353. };
  354. #endif
  355. #define RT2X00DEBUGFS_OPS_READ(__name, __format, __type) \
  356. static ssize_t rt2x00debug_read_##__name(struct file *file, \
  357. char __user *buf, \
  358. size_t length, \
  359. loff_t *offset) \
  360. { \
  361. struct rt2x00debug_intf *intf = file->private_data; \
  362. const struct rt2x00debug *debug = intf->debug; \
  363. char line[16]; \
  364. size_t size; \
  365. unsigned int index = intf->offset_##__name; \
  366. __type value; \
  367. \
  368. if (*offset) \
  369. return 0; \
  370. \
  371. if (index >= debug->__name.word_count) \
  372. return -EINVAL; \
  373. \
  374. index += (debug->__name.word_base / \
  375. debug->__name.word_size); \
  376. \
  377. if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
  378. index *= debug->__name.word_size; \
  379. \
  380. debug->__name.read(intf->rt2x00dev, index, &value); \
  381. \
  382. size = sprintf(line, __format, value); \
  383. \
  384. if (copy_to_user(buf, line, size)) \
  385. return -EFAULT; \
  386. \
  387. *offset += size; \
  388. return size; \
  389. }
  390. #define RT2X00DEBUGFS_OPS_WRITE(__name, __type) \
  391. static ssize_t rt2x00debug_write_##__name(struct file *file, \
  392. const char __user *buf,\
  393. size_t length, \
  394. loff_t *offset) \
  395. { \
  396. struct rt2x00debug_intf *intf = file->private_data; \
  397. const struct rt2x00debug *debug = intf->debug; \
  398. char line[16]; \
  399. size_t size; \
  400. unsigned int index = intf->offset_##__name; \
  401. __type value; \
  402. \
  403. if (*offset) \
  404. return 0; \
  405. \
  406. if (index >= debug->__name.word_count) \
  407. return -EINVAL; \
  408. \
  409. if (length > sizeof(line)) \
  410. return -EINVAL; \
  411. \
  412. if (copy_from_user(line, buf, length)) \
  413. return -EFAULT; \
  414. \
  415. size = strlen(line); \
  416. value = simple_strtoul(line, NULL, 0); \
  417. \
  418. index += (debug->__name.word_base / \
  419. debug->__name.word_size); \
  420. \
  421. if (debug->__name.flags & RT2X00DEBUGFS_OFFSET) \
  422. index *= debug->__name.word_size; \
  423. \
  424. debug->__name.write(intf->rt2x00dev, index, value); \
  425. \
  426. *offset += size; \
  427. return size; \
  428. }
  429. #define RT2X00DEBUGFS_OPS(__name, __format, __type) \
  430. RT2X00DEBUGFS_OPS_READ(__name, __format, __type); \
  431. RT2X00DEBUGFS_OPS_WRITE(__name, __type); \
  432. \
  433. static const struct file_operations rt2x00debug_fop_##__name = {\
  434. .owner = THIS_MODULE, \
  435. .read = rt2x00debug_read_##__name, \
  436. .write = rt2x00debug_write_##__name, \
  437. .open = rt2x00debug_file_open, \
  438. .release = rt2x00debug_file_release, \
  439. .llseek = generic_file_llseek, \
  440. };
  441. RT2X00DEBUGFS_OPS(csr, "0x%.8x\n", u32);
  442. RT2X00DEBUGFS_OPS(eeprom, "0x%.4x\n", u16);
  443. RT2X00DEBUGFS_OPS(bbp, "0x%.2x\n", u8);
  444. RT2X00DEBUGFS_OPS(rf, "0x%.8x\n", u32);
  445. static ssize_t rt2x00debug_read_dev_flags(struct file *file,
  446. char __user *buf,
  447. size_t length,
  448. loff_t *offset)
  449. {
  450. struct rt2x00debug_intf *intf = file->private_data;
  451. char line[16];
  452. size_t size;
  453. if (*offset)
  454. return 0;
  455. size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->flags);
  456. if (copy_to_user(buf, line, size))
  457. return -EFAULT;
  458. *offset += size;
  459. return size;
  460. }
  461. static const struct file_operations rt2x00debug_fop_dev_flags = {
  462. .owner = THIS_MODULE,
  463. .read = rt2x00debug_read_dev_flags,
  464. .open = rt2x00debug_file_open,
  465. .release = rt2x00debug_file_release,
  466. .llseek = default_llseek,
  467. };
  468. static ssize_t rt2x00debug_read_cap_flags(struct file *file,
  469. char __user *buf,
  470. size_t length,
  471. loff_t *offset)
  472. {
  473. struct rt2x00debug_intf *intf = file->private_data;
  474. char line[16];
  475. size_t size;
  476. if (*offset)
  477. return 0;
  478. size = sprintf(line, "0x%.8x\n", (unsigned int)intf->rt2x00dev->cap_flags);
  479. if (copy_to_user(buf, line, size))
  480. return -EFAULT;
  481. *offset += size;
  482. return size;
  483. }
  484. static const struct file_operations rt2x00debug_fop_cap_flags = {
  485. .owner = THIS_MODULE,
  486. .read = rt2x00debug_read_cap_flags,
  487. .open = rt2x00debug_file_open,
  488. .release = rt2x00debug_file_release,
  489. .llseek = default_llseek,
  490. };
  491. static struct dentry *rt2x00debug_create_file_driver(const char *name,
  492. struct rt2x00debug_intf
  493. *intf,
  494. struct debugfs_blob_wrapper
  495. *blob)
  496. {
  497. char *data;
  498. data = kzalloc(3 * MAX_LINE_LENGTH, GFP_KERNEL);
  499. if (!data)
  500. return NULL;
  501. blob->data = data;
  502. data += sprintf(data, "driver:\t%s\n", intf->rt2x00dev->ops->name);
  503. data += sprintf(data, "version:\t%s\n", DRV_VERSION);
  504. blob->size = strlen(blob->data);
  505. return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
  506. }
  507. static struct dentry *rt2x00debug_create_file_chipset(const char *name,
  508. struct rt2x00debug_intf
  509. *intf,
  510. struct
  511. debugfs_blob_wrapper
  512. *blob)
  513. {
  514. const struct rt2x00debug *debug = intf->debug;
  515. char *data;
  516. data = kzalloc(8 * MAX_LINE_LENGTH, GFP_KERNEL);
  517. if (!data)
  518. return NULL;
  519. blob->data = data;
  520. data += sprintf(data, "rt chip:\t%04x\n", intf->rt2x00dev->chip.rt);
  521. data += sprintf(data, "rf chip:\t%04x\n", intf->rt2x00dev->chip.rf);
  522. data += sprintf(data, "revision:\t%04x\n", intf->rt2x00dev->chip.rev);
  523. data += sprintf(data, "\n");
  524. data += sprintf(data, "register\tbase\twords\twordsize\n");
  525. data += sprintf(data, "csr\t%d\t%d\t%d\n",
  526. debug->csr.word_base,
  527. debug->csr.word_count,
  528. debug->csr.word_size);
  529. data += sprintf(data, "eeprom\t%d\t%d\t%d\n",
  530. debug->eeprom.word_base,
  531. debug->eeprom.word_count,
  532. debug->eeprom.word_size);
  533. data += sprintf(data, "bbp\t%d\t%d\t%d\n",
  534. debug->bbp.word_base,
  535. debug->bbp.word_count,
  536. debug->bbp.word_size);
  537. data += sprintf(data, "rf\t%d\t%d\t%d\n",
  538. debug->rf.word_base,
  539. debug->rf.word_count,
  540. debug->rf.word_size);
  541. blob->size = strlen(blob->data);
  542. return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
  543. }
  544. void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
  545. {
  546. const struct rt2x00debug *debug = rt2x00dev->ops->debugfs;
  547. struct rt2x00debug_intf *intf;
  548. intf = kzalloc(sizeof(struct rt2x00debug_intf), GFP_KERNEL);
  549. if (!intf) {
  550. ERROR(rt2x00dev, "Failed to allocate debug handler.\n");
  551. return;
  552. }
  553. intf->debug = debug;
  554. intf->rt2x00dev = rt2x00dev;
  555. rt2x00dev->debugfs_intf = intf;
  556. intf->driver_folder =
  557. debugfs_create_dir(intf->rt2x00dev->ops->name,
  558. rt2x00dev->hw->wiphy->debugfsdir);
  559. if (IS_ERR(intf->driver_folder) || !intf->driver_folder)
  560. goto exit;
  561. intf->driver_entry =
  562. rt2x00debug_create_file_driver("driver", intf, &intf->driver_blob);
  563. if (IS_ERR(intf->driver_entry) || !intf->driver_entry)
  564. goto exit;
  565. intf->chipset_entry =
  566. rt2x00debug_create_file_chipset("chipset",
  567. intf, &intf->chipset_blob);
  568. if (IS_ERR(intf->chipset_entry) || !intf->chipset_entry)
  569. goto exit;
  570. intf->dev_flags = debugfs_create_file("dev_flags", S_IRUSR,
  571. intf->driver_folder, intf,
  572. &rt2x00debug_fop_dev_flags);
  573. if (IS_ERR(intf->dev_flags) || !intf->dev_flags)
  574. goto exit;
  575. intf->cap_flags = debugfs_create_file("cap_flags", S_IRUSR,
  576. intf->driver_folder, intf,
  577. &rt2x00debug_fop_cap_flags);
  578. if (IS_ERR(intf->cap_flags) || !intf->cap_flags)
  579. goto exit;
  580. intf->register_folder =
  581. debugfs_create_dir("register", intf->driver_folder);
  582. if (IS_ERR(intf->register_folder) || !intf->register_folder)
  583. goto exit;
  584. #define RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(__intf, __name) \
  585. ({ \
  586. (__intf)->__name##_off_entry = \
  587. debugfs_create_u32(__stringify(__name) "_offset", \
  588. S_IRUSR | S_IWUSR, \
  589. (__intf)->register_folder, \
  590. &(__intf)->offset_##__name); \
  591. if (IS_ERR((__intf)->__name##_off_entry) \
  592. || !(__intf)->__name##_off_entry) \
  593. goto exit; \
  594. \
  595. (__intf)->__name##_val_entry = \
  596. debugfs_create_file(__stringify(__name) "_value", \
  597. S_IRUSR | S_IWUSR, \
  598. (__intf)->register_folder, \
  599. (__intf), &rt2x00debug_fop_##__name);\
  600. if (IS_ERR((__intf)->__name##_val_entry) \
  601. || !(__intf)->__name##_val_entry) \
  602. goto exit; \
  603. })
  604. RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, csr);
  605. RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, eeprom);
  606. RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, bbp);
  607. RT2X00DEBUGFS_CREATE_REGISTER_ENTRY(intf, rf);
  608. #undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY
  609. intf->queue_folder =
  610. debugfs_create_dir("queue", intf->driver_folder);
  611. if (IS_ERR(intf->queue_folder) || !intf->queue_folder)
  612. goto exit;
  613. intf->queue_frame_dump_entry =
  614. debugfs_create_file("dump", S_IRUSR, intf->queue_folder,
  615. intf, &rt2x00debug_fop_queue_dump);
  616. if (IS_ERR(intf->queue_frame_dump_entry)
  617. || !intf->queue_frame_dump_entry)
  618. goto exit;
  619. skb_queue_head_init(&intf->frame_dump_skbqueue);
  620. init_waitqueue_head(&intf->frame_dump_waitqueue);
  621. intf->queue_stats_entry =
  622. debugfs_create_file("queue", S_IRUSR, intf->queue_folder,
  623. intf, &rt2x00debug_fop_queue_stats);
  624. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  625. if (test_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags))
  626. intf->crypto_stats_entry =
  627. debugfs_create_file("crypto", S_IRUGO, intf->queue_folder,
  628. intf, &rt2x00debug_fop_crypto_stats);
  629. #endif
  630. return;
  631. exit:
  632. rt2x00debug_deregister(rt2x00dev);
  633. ERROR(rt2x00dev, "Failed to register debug handler.\n");
  634. }
  635. void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
  636. {
  637. struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf;
  638. if (unlikely(!intf))
  639. return;
  640. skb_queue_purge(&intf->frame_dump_skbqueue);
  641. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  642. debugfs_remove(intf->crypto_stats_entry);
  643. #endif
  644. debugfs_remove(intf->queue_stats_entry);
  645. debugfs_remove(intf->queue_frame_dump_entry);
  646. debugfs_remove(intf->queue_folder);
  647. debugfs_remove(intf->rf_val_entry);
  648. debugfs_remove(intf->rf_off_entry);
  649. debugfs_remove(intf->bbp_val_entry);
  650. debugfs_remove(intf->bbp_off_entry);
  651. debugfs_remove(intf->eeprom_val_entry);
  652. debugfs_remove(intf->eeprom_off_entry);
  653. debugfs_remove(intf->csr_val_entry);
  654. debugfs_remove(intf->csr_off_entry);
  655. debugfs_remove(intf->register_folder);
  656. debugfs_remove(intf->dev_flags);
  657. debugfs_remove(intf->cap_flags);
  658. debugfs_remove(intf->chipset_entry);
  659. debugfs_remove(intf->driver_entry);
  660. debugfs_remove(intf->driver_folder);
  661. kfree(intf->chipset_blob.data);
  662. kfree(intf->driver_blob.data);
  663. kfree(intf);
  664. rt2x00dev->debugfs_intf = NULL;
  665. }