bcm43xx_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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).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_mmio(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_mmio(bcm, flags);
  131. if (!bcm->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_mmio(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_mmio(bcm, flags);
  155. if (!bcm->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_mmio(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_mmio(bcm, flags);
  185. if (!bcm->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. res = buf_size;
  197. out_unlock:
  198. bcm43xx_unlock_mmio(bcm, flags);
  199. out_up:
  200. up(&big_buffer_sem);
  201. return res;
  202. }
  203. static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
  204. size_t count, loff_t *ppos)
  205. {
  206. const size_t len = REALLY_BIG_BUFFER_SIZE;
  207. struct bcm43xx_private *bcm = file->private_data;
  208. char *buf = really_big_buffer;
  209. size_t pos = 0;
  210. ssize_t res;
  211. unsigned long flags;
  212. struct bcm43xx_dfsentry *e;
  213. struct bcm43xx_xmitstatus *status;
  214. int i, cnt, j = 0;
  215. down(&big_buffer_sem);
  216. bcm43xx_lock(bcm, flags);
  217. fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
  218. BCM43xx_NR_LOGGED_XMITSTATUS);
  219. e = bcm->dfsentry;
  220. if (e->xmitstatus_printing == 0) {
  221. /* At the beginning, make a copy of all data to avoid
  222. * concurrency, as this function is called multiple
  223. * times for big logs. Without copying, the data might
  224. * change between reads. This would result in total trash.
  225. */
  226. e->xmitstatus_printing = 1;
  227. e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
  228. e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
  229. memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
  230. BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
  231. }
  232. i = e->saved_xmitstatus_ptr - 1;
  233. if (i < 0)
  234. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  235. cnt = e->saved_xmitstatus_cnt;
  236. while (cnt) {
  237. status = e->xmitstatus_print_buffer + i;
  238. fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
  239. "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
  240. "unk: 0x%04x\n", j,
  241. status->cookie, status->flags,
  242. status->cnt1, status->cnt2, status->seq,
  243. status->unknown);
  244. j++;
  245. cnt--;
  246. i--;
  247. if (i < 0)
  248. i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
  249. }
  250. bcm43xx_unlock(bcm, flags);
  251. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  252. bcm43xx_lock(bcm, flags);
  253. if (*ppos == pos) {
  254. /* Done. Drop the copied data. */
  255. e->xmitstatus_printing = 0;
  256. }
  257. bcm43xx_unlock(bcm, flags);
  258. up(&big_buffer_sem);
  259. return res;
  260. }
  261. #undef fappend
  262. static struct file_operations devinfo_fops = {
  263. .read = devinfo_read_file,
  264. .write = write_file_dummy,
  265. .open = open_file_generic,
  266. };
  267. static struct file_operations spromdump_fops = {
  268. .read = spromdump_read_file,
  269. .write = write_file_dummy,
  270. .open = open_file_generic,
  271. };
  272. static struct file_operations drvinfo_fops = {
  273. .read = drvinfo_read_file,
  274. .write = write_file_dummy,
  275. .open = open_file_generic,
  276. };
  277. static struct file_operations tsf_fops = {
  278. .read = tsf_read_file,
  279. .write = tsf_write_file,
  280. .open = open_file_generic,
  281. };
  282. static struct file_operations txstat_fops = {
  283. .read = txstat_read_file,
  284. .write = write_file_dummy,
  285. .open = open_file_generic,
  286. };
  287. void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
  288. {
  289. struct bcm43xx_dfsentry *e;
  290. char devdir[IFNAMSIZ];
  291. assert(bcm);
  292. e = kzalloc(sizeof(*e), GFP_KERNEL);
  293. if (!e) {
  294. printk(KERN_ERR PFX "out of memory\n");
  295. return;
  296. }
  297. e->bcm = bcm;
  298. e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  299. * sizeof(*(e->xmitstatus_buffer)),
  300. GFP_KERNEL);
  301. if (!e->xmitstatus_buffer) {
  302. printk(KERN_ERR PFX "out of memory\n");
  303. kfree(e);
  304. return;
  305. }
  306. e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
  307. * sizeof(*(e->xmitstatus_buffer)),
  308. GFP_KERNEL);
  309. if (!e->xmitstatus_print_buffer) {
  310. printk(KERN_ERR PFX "out of memory\n");
  311. kfree(e);
  312. return;
  313. }
  314. bcm->dfsentry = e;
  315. strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
  316. e->subdir = debugfs_create_dir(devdir, fs.root);
  317. e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
  318. bcm, &devinfo_fops);
  319. if (!e->dentry_devinfo)
  320. printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
  321. e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
  322. bcm, &spromdump_fops);
  323. if (!e->dentry_spromdump)
  324. printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
  325. e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
  326. bcm, &tsf_fops);
  327. if (!e->dentry_tsf)
  328. printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
  329. e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
  330. bcm, &txstat_fops);
  331. if (!e->dentry_txstat)
  332. printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
  333. }
  334. void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
  335. {
  336. struct bcm43xx_dfsentry *e;
  337. if (!bcm)
  338. return;
  339. e = bcm->dfsentry;
  340. assert(e);
  341. debugfs_remove(e->dentry_spromdump);
  342. debugfs_remove(e->dentry_devinfo);
  343. debugfs_remove(e->dentry_tsf);
  344. debugfs_remove(e->dentry_txstat);
  345. debugfs_remove(e->subdir);
  346. kfree(e->xmitstatus_buffer);
  347. kfree(e->xmitstatus_print_buffer);
  348. kfree(e);
  349. }
  350. void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
  351. struct bcm43xx_xmitstatus *status)
  352. {
  353. struct bcm43xx_dfsentry *e;
  354. struct bcm43xx_xmitstatus *savedstatus;
  355. /* This is protected by bcm->_lock */
  356. e = bcm->dfsentry;
  357. assert(e);
  358. savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
  359. memcpy(savedstatus, status, sizeof(*status));
  360. e->xmitstatus_ptr++;
  361. if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
  362. e->xmitstatus_ptr = 0;
  363. if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
  364. e->xmitstatus_cnt++;
  365. }
  366. void bcm43xx_debugfs_init(void)
  367. {
  368. memset(&fs, 0, sizeof(fs));
  369. fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  370. if (!fs.root)
  371. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
  372. fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
  373. if (!fs.dentry_driverinfo)
  374. printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
  375. }
  376. void bcm43xx_debugfs_exit(void)
  377. {
  378. debugfs_remove(fs.dentry_driverinfo);
  379. debugfs_remove(fs.root);
  380. }
  381. void bcm43xx_printk_dump(const char *data,
  382. size_t size,
  383. const char *description)
  384. {
  385. size_t i;
  386. char c;
  387. printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
  388. description, size);
  389. for (i = 0; i < size; i++) {
  390. c = data[i];
  391. if (i % 8 == 0)
  392. printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
  393. else
  394. printk("0x%02x, ", c & 0xff);
  395. }
  396. printk("\n");
  397. }
  398. void bcm43xx_printk_bitdump(const unsigned char *data,
  399. size_t bytes, int msb_to_lsb,
  400. const char *description)
  401. {
  402. size_t i;
  403. int j;
  404. const unsigned char *d;
  405. printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
  406. description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
  407. for (i = 0; i < bytes; i++) {
  408. d = data + i;
  409. if (i % 8 == 0)
  410. printk("\n" KERN_INFO PFX "0x%08x: ", i);
  411. if (msb_to_lsb) {
  412. for (j = 7; j >= 0; j--) {
  413. if (*d & (1 << j))
  414. printk("1");
  415. else
  416. printk("0");
  417. }
  418. } else {
  419. for (j = 0; j < 8; j++) {
  420. if (*d & (1 << j))
  421. printk("1");
  422. else
  423. printk("0");
  424. }
  425. }
  426. printk(" ");
  427. }
  428. printk("\n");
  429. }