bcm43xx_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. Broadcom BCM43xx wireless driver
  3. debugfs driver debugging code
  4. Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/slab.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/pci.h>
  23. #include <asm/io.h>
  24. #include "bcm43xx.h"
  25. #include "bcm43xx_main.h"
  26. #include "bcm43xx_debugfs.h"
  27. #include "bcm43xx_dma.h"
  28. #include "bcm43xx_pio.h"
  29. #include "bcm43xx_xmit.h"
  30. #define REALLY_BIG_BUFFER_SIZE (1024*256)
  31. static struct bcm43xx_debugfs fs;
  32. static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
  33. static DECLARE_MUTEX(big_buffer_sem);
  34. static ssize_t write_file_dummy(struct file *file, const char __user *buf,
  35. size_t count, loff_t *ppos)
  36. {
  37. return count;
  38. }
  39. static int open_file_generic(struct inode *inode, struct file *file)
  40. {
  41. file->private_data = inode->u.generic_ip;
  42. return 0;
  43. }
  44. #define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
  45. static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
  46. size_t count, loff_t *ppos)
  47. {
  48. const size_t len = REALLY_BIG_BUFFER_SIZE;
  49. struct bcm43xx_private *bcm = file->private_data;
  50. char *buf = really_big_buffer;
  51. size_t pos = 0;
  52. ssize_t res;
  53. struct net_device *net_dev;
  54. struct pci_dev *pci_dev;
  55. unsigned long flags;
  56. u16 tmp16;
  57. int i;
  58. down(&big_buffer_sem);
  59. bcm43xx_lock_irqsafe(bcm, flags);
  60. if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
  61. fappend("Board not initialized.\n");
  62. goto out;
  63. }
  64. net_dev = bcm->net_dev;
  65. pci_dev = bcm->pci_dev;
  66. /* This is where the information is written to the "devinfo" file */
  67. fappend("*** %s devinfo ***\n", net_dev->name);
  68. fappend("vendor: 0x%04x device: 0x%04x\n",
  69. pci_dev->vendor, pci_dev->device);
  70. fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
  71. pci_dev->subsystem_vendor, pci_dev->subsystem_device);
  72. fappend("IRQ: %d\n", bcm->irq);
  73. fappend("mmio_addr: 0x%p\n", bcm->mmio_addr);
  74. fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
  75. if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
  76. fappend("Radio disabled by hardware!\n");
  77. if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
  78. fappend("Radio disabled by hardware!\n");
  79. fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm->board_vendor,
  80. bcm->board_type);
  81. fappend("\nCores:\n");
  82. #define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
  83. "rev: 0x%02x, index: 0x%02x\n", \
  84. (info).available \
  85. ? "available" : "nonavailable", \
  86. (info).enabled \
  87. ? "enabled" : "disabled", \
  88. (info).id, (info).rev, (info).index)
  89. fappend_core("CHIPCOMMON", bcm->core_chipcommon);
  90. fappend_core("PCI", bcm->core_pci);
  91. fappend_core("first 80211", bcm->core_80211[0]);
  92. fappend_core("second 80211", bcm->core_80211[1]);
  93. #undef fappend_core
  94. tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
  95. fappend("LEDs: ");
  96. for (i = 0; i < BCM43xx_NR_LEDS; i++)
  97. fappend("%d ", !!(tmp16 & (1 << i)));
  98. fappend("\n");
  99. out:
  100. bcm43xx_unlock_irqsafe(bcm, flags);
  101. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  102. up(&big_buffer_sem);
  103. return res;
  104. }
  105. static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
  106. size_t count, loff_t *ppos)
  107. {
  108. const size_t len = REALLY_BIG_BUFFER_SIZE;
  109. char *buf = really_big_buffer;
  110. size_t pos = 0;
  111. ssize_t res;
  112. down(&big_buffer_sem);
  113. /* This is where the information is written to the "driver" file */
  114. fappend(KBUILD_MODNAME " driver\n");
  115. fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
  116. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  117. up(&big_buffer_sem);
  118. return res;
  119. }
  120. static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
  121. size_t count, loff_t *ppos)
  122. {
  123. const size_t len = REALLY_BIG_BUFFER_SIZE;
  124. struct bcm43xx_private *bcm = file->private_data;
  125. char *buf = really_big_buffer;
  126. size_t pos = 0;
  127. ssize_t res;
  128. unsigned long flags;
  129. down(&big_buffer_sem);
  130. bcm43xx_lock_irqsafe(bcm, flags);
  131. if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
  132. fappend("Board not initialized.\n");
  133. goto out;
  134. }
  135. /* This is where the information is written to the "sprom_dump" file */
  136. fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
  137. out:
  138. bcm43xx_unlock_irqsafe(bcm, flags);
  139. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  140. up(&big_buffer_sem);
  141. return res;
  142. }
  143. static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
  144. size_t count, loff_t *ppos)
  145. {
  146. const size_t len = REALLY_BIG_BUFFER_SIZE;
  147. struct bcm43xx_private *bcm = file->private_data;
  148. char *buf = really_big_buffer;
  149. size_t pos = 0;
  150. ssize_t res;
  151. unsigned long flags;
  152. u64 tsf;
  153. down(&big_buffer_sem);
  154. bcm43xx_lock_irqsafe(bcm, flags);
  155. if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
  156. fappend("Board not initialized.\n");
  157. goto out;
  158. }
  159. bcm43xx_tsf_read(bcm, &tsf);
  160. fappend("0x%08x%08x\n",
  161. (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
  162. (unsigned int)(tsf & 0xFFFFFFFFULL));
  163. out:
  164. bcm43xx_unlock_irqsafe(bcm, flags);
  165. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  166. up(&big_buffer_sem);
  167. return res;
  168. }
  169. static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
  170. size_t count, loff_t *ppos)
  171. {
  172. struct bcm43xx_private *bcm = file->private_data;
  173. char *buf = really_big_buffer;
  174. ssize_t buf_size;
  175. ssize_t res;
  176. unsigned long flags;
  177. u64 tsf;
  178. buf_size = min(count, sizeof (really_big_buffer) - 1);
  179. down(&big_buffer_sem);
  180. if (copy_from_user(buf, user_buf, buf_size)) {
  181. res = -EFAULT;
  182. goto out_up;
  183. }
  184. bcm43xx_lock_irqsafe(bcm, flags);
  185. if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED) {
  186. printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
  187. res = -EFAULT;
  188. goto out_unlock;
  189. }
  190. if (sscanf(buf, "%lli", &tsf) != 1) {
  191. printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
  192. res = -EINVAL;
  193. goto out_unlock;
  194. }
  195. bcm43xx_tsf_write(bcm, tsf);
  196. mmiowb();
  197. res = buf_size;
  198. out_unlock:
  199. bcm43xx_unlock_irqsafe(bcm, flags);
  200. out_up:
  201. up(&big_buffer_sem);
  202. return res;
  203. }
  204. static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
  205. size_t count, loff_t *ppos)
  206. {
  207. const size_t len = REALLY_BIG_BUFFER_SIZE;
  208. struct bcm43xx_private *bcm = file->private_data;
  209. char *buf = really_big_buffer;
  210. size_t pos = 0;
  211. ssize_t res;
  212. unsigned long flags;
  213. struct bcm43xx_dfsentry *e;
  214. struct bcm43xx_xmitstatus *status;
  215. int i, cnt, j = 0;
  216. down(&big_buffer_sem);
  217. bcm43xx_lock_irqsafe(bcm, flags);
  218. fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
  219. BCM43xx_NR_LOGGED_XMITSTATUS);
  220. e = bcm->dfsentry;
  221. if (e->xmitstatus_printing == 0) {
  222. /* At the beginning, make a copy of all data to avoid
  223. * concurrency, as this function is called multiple
  224. * times for big logs. Without copying, the data might
  225. * change between reads. This would result in total trash.
  226. */
  227. e->xmitstatus_printing = 1;
  228. e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
  229. e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
  230. memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
  231. BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
  232. }
  233. i = e->saved_xmitstatus_ptr - 1;
  234. if (i < 0)
  235. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  236. cnt = e->saved_xmitstatus_cnt;
  237. while (cnt) {
  238. status = e->xmitstatus_print_buffer + i;
  239. fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
  240. "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
  241. "unk: 0x%04x\n", j,
  242. status->cookie, status->flags,
  243. status->cnt1, status->cnt2, status->seq,
  244. status->unknown);
  245. j++;
  246. cnt--;
  247. i--;
  248. if (i < 0)
  249. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  250. }
  251. bcm43xx_unlock_irqsafe(bcm, flags);
  252. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  253. bcm43xx_lock_irqsafe(bcm, flags);
  254. if (*ppos == pos) {
  255. /* Done. Drop the copied data. */
  256. e->xmitstatus_printing = 0;
  257. }
  258. bcm43xx_unlock_irqsafe(bcm, flags);
  259. up(&big_buffer_sem);
  260. return res;
  261. }
  262. #undef fappend
  263. static struct file_operations devinfo_fops = {
  264. .read = devinfo_read_file,
  265. .write = write_file_dummy,
  266. .open = open_file_generic,
  267. };
  268. static struct file_operations spromdump_fops = {
  269. .read = spromdump_read_file,
  270. .write = write_file_dummy,
  271. .open = open_file_generic,
  272. };
  273. static struct file_operations drvinfo_fops = {
  274. .read = drvinfo_read_file,
  275. .write = write_file_dummy,
  276. .open = open_file_generic,
  277. };
  278. static struct file_operations tsf_fops = {
  279. .read = tsf_read_file,
  280. .write = tsf_write_file,
  281. .open = open_file_generic,
  282. };
  283. static struct file_operations txstat_fops = {
  284. .read = txstat_read_file,
  285. .write = write_file_dummy,
  286. .open = open_file_generic,
  287. };
  288. void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
  289. {
  290. struct bcm43xx_dfsentry *e;
  291. char devdir[IFNAMSIZ];
  292. assert(bcm);
  293. e = kzalloc(sizeof(*e), GFP_KERNEL);
  294. if (!e) {
  295. printk(KERN_ERR PFX "out of memory\n");
  296. return;
  297. }
  298. e->bcm = bcm;
  299. e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  300. * sizeof(*(e->xmitstatus_buffer)),
  301. GFP_KERNEL);
  302. if (!e->xmitstatus_buffer) {
  303. printk(KERN_ERR PFX "out of memory\n");
  304. kfree(e);
  305. return;
  306. }
  307. e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  308. * sizeof(*(e->xmitstatus_buffer)),
  309. GFP_KERNEL);
  310. if (!e->xmitstatus_print_buffer) {
  311. printk(KERN_ERR PFX "out of memory\n");
  312. kfree(e);
  313. return;
  314. }
  315. bcm->dfsentry = e;
  316. strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
  317. e->subdir = debugfs_create_dir(devdir, fs.root);
  318. e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
  319. bcm, &devinfo_fops);
  320. if (!e->dentry_devinfo)
  321. printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
  322. e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
  323. bcm, &spromdump_fops);
  324. if (!e->dentry_spromdump)
  325. printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
  326. e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
  327. bcm, &tsf_fops);
  328. if (!e->dentry_tsf)
  329. printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
  330. e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
  331. bcm, &txstat_fops);
  332. if (!e->dentry_txstat)
  333. printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
  334. }
  335. void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
  336. {
  337. struct bcm43xx_dfsentry *e;
  338. if (!bcm)
  339. return;
  340. e = bcm->dfsentry;
  341. assert(e);
  342. debugfs_remove(e->dentry_spromdump);
  343. debugfs_remove(e->dentry_devinfo);
  344. debugfs_remove(e->dentry_tsf);
  345. debugfs_remove(e->dentry_txstat);
  346. debugfs_remove(e->subdir);
  347. kfree(e->xmitstatus_buffer);
  348. kfree(e->xmitstatus_print_buffer);
  349. kfree(e);
  350. }
  351. void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
  352. struct bcm43xx_xmitstatus *status)
  353. {
  354. struct bcm43xx_dfsentry *e;
  355. struct bcm43xx_xmitstatus *savedstatus;
  356. /* This is protected by bcm->_lock */
  357. e = bcm->dfsentry;
  358. assert(e);
  359. savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
  360. memcpy(savedstatus, status, sizeof(*status));
  361. e->xmitstatus_ptr++;
  362. if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
  363. e->xmitstatus_ptr = 0;
  364. if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
  365. e->xmitstatus_cnt++;
  366. }
  367. void bcm43xx_debugfs_init(void)
  368. {
  369. memset(&fs, 0, sizeof(fs));
  370. fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  371. if (!fs.root)
  372. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
  373. fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
  374. if (!fs.dentry_driverinfo)
  375. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
  376. }
  377. void bcm43xx_debugfs_exit(void)
  378. {
  379. debugfs_remove(fs.dentry_driverinfo);
  380. debugfs_remove(fs.root);
  381. }
  382. void bcm43xx_printk_dump(const char *data,
  383. size_t size,
  384. const char *description)
  385. {
  386. size_t i;
  387. char c;
  388. printk(KERN_INFO PFX "Data dump (%s, %zd bytes):",
  389. description, size);
  390. for (i = 0; i < size; i++) {
  391. c = data[i];
  392. if (i % 8 == 0)
  393. printk("\n" KERN_INFO PFX "0x%08zx: 0x%02x, ", i, c & 0xff);
  394. else
  395. printk("0x%02x, ", c & 0xff);
  396. }
  397. printk("\n");
  398. }
  399. void bcm43xx_printk_bitdump(const unsigned char *data,
  400. size_t bytes, int msb_to_lsb,
  401. const char *description)
  402. {
  403. size_t i;
  404. int j;
  405. const unsigned char *d;
  406. printk(KERN_INFO PFX "*** Bitdump (%s, %zd bytes, %s) ***",
  407. description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
  408. for (i = 0; i < bytes; i++) {
  409. d = data + i;
  410. if (i % 8 == 0)
  411. printk("\n" KERN_INFO PFX "0x%08zx: ", i);
  412. if (msb_to_lsb) {
  413. for (j = 7; j >= 0; j--) {
  414. if (*d & (1 << j))
  415. printk("1");
  416. else
  417. printk("0");
  418. }
  419. } else {
  420. for (j = 0; j < 8; j++) {
  421. if (*d & (1 << j))
  422. printk("1");
  423. else
  424. printk("0");
  425. }
  426. }
  427. printk(" ");
  428. }
  429. printk("\n");
  430. }