bcm43xx_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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_mmio(bcm, flags);
  60. if (!bcm->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 mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
  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).flags & BCM43xx_COREFLAG_AVAILABLE \
  85. ? "available" : "nonavailable", \
  86. (info).flags & BCM43xx_COREFLAG_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("V90", bcm->core_v90);
  92. fappend_core("PCMCIA", bcm->core_pcmcia);
  93. fappend_core("ETHERNET", bcm->core_ethernet);
  94. fappend_core("first 80211", bcm->core_80211[0]);
  95. fappend_core("second 80211", bcm->core_80211[1]);
  96. #undef fappend_core
  97. tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
  98. fappend("LEDs: ");
  99. for (i = 0; i < BCM43xx_NR_LEDS; i++)
  100. fappend("%d ", !!(tmp16 & (1 << i)));
  101. fappend("\n");
  102. out:
  103. bcm43xx_unlock_mmio(bcm, flags);
  104. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  105. up(&big_buffer_sem);
  106. return res;
  107. }
  108. static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
  109. size_t count, loff_t *ppos)
  110. {
  111. const size_t len = REALLY_BIG_BUFFER_SIZE;
  112. char *buf = really_big_buffer;
  113. size_t pos = 0;
  114. ssize_t res;
  115. down(&big_buffer_sem);
  116. /* This is where the information is written to the "driver" file */
  117. fappend(KBUILD_MODNAME " driver\n");
  118. fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
  119. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  120. up(&big_buffer_sem);
  121. return res;
  122. }
  123. static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
  124. size_t count, loff_t *ppos)
  125. {
  126. const size_t len = REALLY_BIG_BUFFER_SIZE;
  127. struct bcm43xx_private *bcm = file->private_data;
  128. char *buf = really_big_buffer;
  129. size_t pos = 0;
  130. ssize_t res;
  131. unsigned long flags;
  132. down(&big_buffer_sem);
  133. bcm43xx_lock_mmio(bcm, flags);
  134. if (!bcm->initialized) {
  135. fappend("Board not initialized.\n");
  136. goto out;
  137. }
  138. /* This is where the information is written to the "sprom_dump" file */
  139. fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
  140. out:
  141. bcm43xx_unlock_mmio(bcm, flags);
  142. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  143. up(&big_buffer_sem);
  144. return res;
  145. }
  146. static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
  147. size_t count, loff_t *ppos)
  148. {
  149. const size_t len = REALLY_BIG_BUFFER_SIZE;
  150. struct bcm43xx_private *bcm = file->private_data;
  151. char *buf = really_big_buffer;
  152. size_t pos = 0;
  153. ssize_t res;
  154. unsigned long flags;
  155. u64 tsf;
  156. down(&big_buffer_sem);
  157. bcm43xx_lock_mmio(bcm, flags);
  158. if (!bcm->initialized) {
  159. fappend("Board not initialized.\n");
  160. goto out;
  161. }
  162. bcm43xx_tsf_read(bcm, &tsf);
  163. fappend("0x%08x%08x\n",
  164. (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
  165. (unsigned int)(tsf & 0xFFFFFFFFULL));
  166. out:
  167. bcm43xx_unlock_mmio(bcm, flags);
  168. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  169. up(&big_buffer_sem);
  170. return res;
  171. }
  172. static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
  173. size_t count, loff_t *ppos)
  174. {
  175. struct bcm43xx_private *bcm = file->private_data;
  176. char *buf = really_big_buffer;
  177. ssize_t buf_size;
  178. ssize_t res;
  179. unsigned long flags;
  180. u64 tsf;
  181. buf_size = min(count, sizeof (really_big_buffer) - 1);
  182. down(&big_buffer_sem);
  183. if (copy_from_user(buf, user_buf, buf_size)) {
  184. res = -EFAULT;
  185. goto out_up;
  186. }
  187. bcm43xx_lock_mmio(bcm, flags);
  188. if (!bcm->initialized) {
  189. printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
  190. res = -EFAULT;
  191. goto out_unlock;
  192. }
  193. if (sscanf(buf, "%lli", &tsf) != 1) {
  194. printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
  195. res = -EINVAL;
  196. goto out_unlock;
  197. }
  198. bcm43xx_tsf_write(bcm, tsf);
  199. res = buf_size;
  200. out_unlock:
  201. bcm43xx_unlock_mmio(bcm, flags);
  202. out_up:
  203. up(&big_buffer_sem);
  204. return res;
  205. }
  206. static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
  207. size_t count, loff_t *ppos)
  208. {
  209. const size_t len = REALLY_BIG_BUFFER_SIZE;
  210. struct bcm43xx_private *bcm = file->private_data;
  211. char *buf = really_big_buffer;
  212. size_t pos = 0;
  213. ssize_t res;
  214. unsigned long flags;
  215. struct bcm43xx_dfsentry *e;
  216. struct bcm43xx_xmitstatus *status;
  217. int i, cnt, j = 0;
  218. down(&big_buffer_sem);
  219. bcm43xx_lock(bcm, flags);
  220. fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
  221. BCM43xx_NR_LOGGED_XMITSTATUS);
  222. e = bcm->dfsentry;
  223. if (e->xmitstatus_printing == 0) {
  224. /* At the beginning, make a copy of all data to avoid
  225. * concurrency, as this function is called multiple
  226. * times for big logs. Without copying, the data might
  227. * change between reads. This would result in total trash.
  228. */
  229. e->xmitstatus_printing = 1;
  230. e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
  231. e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
  232. memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
  233. BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
  234. }
  235. i = e->saved_xmitstatus_ptr - 1;
  236. if (i < 0)
  237. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  238. cnt = e->saved_xmitstatus_cnt;
  239. while (cnt) {
  240. status = e->xmitstatus_print_buffer + i;
  241. fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
  242. "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
  243. "unk: 0x%04x\n", j,
  244. status->cookie, status->flags,
  245. status->cnt1, status->cnt2, status->seq,
  246. status->unknown);
  247. j++;
  248. cnt--;
  249. i--;
  250. if (i < 0)
  251. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  252. }
  253. bcm43xx_unlock(bcm, flags);
  254. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  255. bcm43xx_lock(bcm, flags);
  256. if (*ppos == pos) {
  257. /* Done. Drop the copied data. */
  258. e->xmitstatus_printing = 0;
  259. }
  260. bcm43xx_unlock(bcm, flags);
  261. up(&big_buffer_sem);
  262. return res;
  263. }
  264. #undef fappend
  265. static struct file_operations devinfo_fops = {
  266. .read = devinfo_read_file,
  267. .write = write_file_dummy,
  268. .open = open_file_generic,
  269. };
  270. static struct file_operations spromdump_fops = {
  271. .read = spromdump_read_file,
  272. .write = write_file_dummy,
  273. .open = open_file_generic,
  274. };
  275. static struct file_operations drvinfo_fops = {
  276. .read = drvinfo_read_file,
  277. .write = write_file_dummy,
  278. .open = open_file_generic,
  279. };
  280. static struct file_operations tsf_fops = {
  281. .read = tsf_read_file,
  282. .write = tsf_write_file,
  283. .open = open_file_generic,
  284. };
  285. static struct file_operations txstat_fops = {
  286. .read = txstat_read_file,
  287. .write = write_file_dummy,
  288. .open = open_file_generic,
  289. };
  290. void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
  291. {
  292. struct bcm43xx_dfsentry *e;
  293. char devdir[IFNAMSIZ];
  294. assert(bcm);
  295. e = kzalloc(sizeof(*e), GFP_KERNEL);
  296. if (!e) {
  297. printk(KERN_ERR PFX "out of memory\n");
  298. return;
  299. }
  300. e->bcm = bcm;
  301. e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  302. * sizeof(*(e->xmitstatus_buffer)),
  303. GFP_KERNEL);
  304. if (!e->xmitstatus_buffer) {
  305. printk(KERN_ERR PFX "out of memory\n");
  306. kfree(e);
  307. return;
  308. }
  309. e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  310. * sizeof(*(e->xmitstatus_buffer)),
  311. GFP_KERNEL);
  312. if (!e->xmitstatus_print_buffer) {
  313. printk(KERN_ERR PFX "out of memory\n");
  314. kfree(e);
  315. return;
  316. }
  317. bcm->dfsentry = e;
  318. strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
  319. e->subdir = debugfs_create_dir(devdir, fs.root);
  320. e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
  321. bcm, &devinfo_fops);
  322. if (!e->dentry_devinfo)
  323. printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
  324. e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
  325. bcm, &spromdump_fops);
  326. if (!e->dentry_spromdump)
  327. printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
  328. e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
  329. bcm, &tsf_fops);
  330. if (!e->dentry_tsf)
  331. printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
  332. e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
  333. bcm, &txstat_fops);
  334. if (!e->dentry_txstat)
  335. printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
  336. }
  337. void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
  338. {
  339. struct bcm43xx_dfsentry *e;
  340. if (!bcm)
  341. return;
  342. e = bcm->dfsentry;
  343. assert(e);
  344. debugfs_remove(e->dentry_spromdump);
  345. debugfs_remove(e->dentry_devinfo);
  346. debugfs_remove(e->dentry_tsf);
  347. debugfs_remove(e->dentry_txstat);
  348. debugfs_remove(e->subdir);
  349. kfree(e->xmitstatus_buffer);
  350. kfree(e->xmitstatus_print_buffer);
  351. kfree(e);
  352. }
  353. void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
  354. struct bcm43xx_xmitstatus *status)
  355. {
  356. struct bcm43xx_dfsentry *e;
  357. struct bcm43xx_xmitstatus *savedstatus;
  358. /* This is protected by bcm->_lock */
  359. e = bcm->dfsentry;
  360. assert(e);
  361. savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
  362. memcpy(savedstatus, status, sizeof(*status));
  363. e->xmitstatus_ptr++;
  364. if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
  365. e->xmitstatus_ptr = 0;
  366. if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
  367. e->xmitstatus_cnt++;
  368. }
  369. void bcm43xx_debugfs_init(void)
  370. {
  371. memset(&fs, 0, sizeof(fs));
  372. fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  373. if (!fs.root)
  374. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
  375. fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
  376. if (!fs.dentry_driverinfo)
  377. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
  378. }
  379. void bcm43xx_debugfs_exit(void)
  380. {
  381. debugfs_remove(fs.dentry_driverinfo);
  382. debugfs_remove(fs.root);
  383. }
  384. void bcm43xx_printk_dump(const char *data,
  385. size_t size,
  386. const char *description)
  387. {
  388. size_t i;
  389. char c;
  390. printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
  391. description, size);
  392. for (i = 0; i < size; i++) {
  393. c = data[i];
  394. if (i % 8 == 0)
  395. printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
  396. else
  397. printk("0x%02x, ", c & 0xff);
  398. }
  399. printk("\n");
  400. }
  401. void bcm43xx_printk_bitdump(const unsigned char *data,
  402. size_t bytes, int msb_to_lsb,
  403. const char *description)
  404. {
  405. size_t i;
  406. int j;
  407. const unsigned char *d;
  408. printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
  409. description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
  410. for (i = 0; i < bytes; i++) {
  411. d = data + i;
  412. if (i % 8 == 0)
  413. printk("\n" KERN_INFO PFX "0x%08x: ", i);
  414. if (msb_to_lsb) {
  415. for (j = 7; j >= 0; j--) {
  416. if (*d & (1 << j))
  417. printk("1");
  418. else
  419. printk("0");
  420. }
  421. } else {
  422. for (j = 0; j < 8; j++) {
  423. if (*d & (1 << j))
  424. printk("1");
  425. else
  426. printk("0");
  427. }
  428. }
  429. printk(" ");
  430. }
  431. printk("\n");
  432. }
  433. /* vim: set ts=8 sw=8 sts=8: */