debugfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. Broadcom B43 wireless driver
  3. debugfs driver debugging code
  4. Copyright (c) 2005-2007 Michael Buesch <mb@bu3sch.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 <linux/mutex.h>
  24. #include "b43.h"
  25. #include "main.h"
  26. #include "debugfs.h"
  27. #include "dma.h"
  28. #include "xmit.h"
  29. /* The root directory. */
  30. static struct dentry *rootdir;
  31. struct b43_debugfs_fops {
  32. ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
  33. int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
  34. struct file_operations fops;
  35. /* Offset of struct b43_dfs_file in struct b43_dfsentry */
  36. size_t file_struct_offset;
  37. /* Take wl->irq_lock before calling read/write? */
  38. bool take_irqlock;
  39. };
  40. static inline
  41. struct b43_dfs_file * fops_to_dfs_file(struct b43_wldev *dev,
  42. const struct b43_debugfs_fops *dfops)
  43. {
  44. void *p;
  45. p = dev->dfsentry;
  46. p += dfops->file_struct_offset;
  47. return p;
  48. }
  49. #define fappend(fmt, x...) \
  50. do { \
  51. if (bufsize - count) \
  52. count += snprintf(buf + count, \
  53. bufsize - count, \
  54. fmt , ##x); \
  55. else \
  56. printk(KERN_ERR "b43: fappend overflow\n"); \
  57. } while (0)
  58. /* wl->irq_lock is locked */
  59. static ssize_t tsf_read_file(struct b43_wldev *dev,
  60. char *buf, size_t bufsize)
  61. {
  62. ssize_t count = 0;
  63. u64 tsf;
  64. b43_tsf_read(dev, &tsf);
  65. fappend("0x%08x%08x\n",
  66. (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
  67. (unsigned int)(tsf & 0xFFFFFFFFULL));
  68. return count;
  69. }
  70. /* wl->irq_lock is locked */
  71. static int tsf_write_file(struct b43_wldev *dev,
  72. const char *buf, size_t count)
  73. {
  74. u64 tsf;
  75. if (sscanf(buf, "%llu", (unsigned long long *)(&tsf)) != 1)
  76. return -EINVAL;
  77. b43_tsf_write(dev, tsf);
  78. return 0;
  79. }
  80. /* wl->irq_lock is locked */
  81. static ssize_t ucode_regs_read_file(struct b43_wldev *dev,
  82. char *buf, size_t bufsize)
  83. {
  84. ssize_t count = 0;
  85. int i;
  86. for (i = 0; i < 64; i++) {
  87. fappend("r%d = 0x%04x\n", i,
  88. b43_shm_read16(dev, B43_SHM_SCRATCH, i));
  89. }
  90. return count;
  91. }
  92. /* wl->irq_lock is locked */
  93. static ssize_t shm_read_file(struct b43_wldev *dev,
  94. char *buf, size_t bufsize)
  95. {
  96. ssize_t count = 0;
  97. int i;
  98. u16 tmp;
  99. __le16 *le16buf = (__le16 *)buf;
  100. for (i = 0; i < 0x1000; i++) {
  101. if (bufsize < sizeof(tmp))
  102. break;
  103. tmp = b43_shm_read16(dev, B43_SHM_SHARED, 2 * i);
  104. le16buf[i] = cpu_to_le16(tmp);
  105. count += sizeof(tmp);
  106. bufsize -= sizeof(tmp);
  107. }
  108. return count;
  109. }
  110. static ssize_t txstat_read_file(struct b43_wldev *dev,
  111. char *buf, size_t bufsize)
  112. {
  113. struct b43_txstatus_log *log = &dev->dfsentry->txstatlog;
  114. ssize_t count = 0;
  115. unsigned long flags;
  116. int i, idx;
  117. struct b43_txstatus *stat;
  118. spin_lock_irqsave(&log->lock, flags);
  119. if (log->end < 0) {
  120. fappend("Nothing transmitted, yet\n");
  121. goto out_unlock;
  122. }
  123. fappend("b43 TX status reports:\n\n"
  124. "index | cookie | seq | phy_stat | frame_count | "
  125. "rts_count | supp_reason | pm_indicated | "
  126. "intermediate | for_ampdu | acked\n" "---\n");
  127. i = log->end + 1;
  128. idx = 0;
  129. while (1) {
  130. if (i == B43_NR_LOGGED_TXSTATUS)
  131. i = 0;
  132. stat = &(log->log[i]);
  133. if (stat->cookie) {
  134. fappend("%03d | "
  135. "0x%04X | 0x%04X | 0x%02X | "
  136. "0x%X | 0x%X | "
  137. "%u | %u | "
  138. "%u | %u | %u\n",
  139. idx,
  140. stat->cookie, stat->seq, stat->phy_stat,
  141. stat->frame_count, stat->rts_count,
  142. stat->supp_reason, stat->pm_indicated,
  143. stat->intermediate, stat->for_ampdu,
  144. stat->acked);
  145. idx++;
  146. }
  147. if (i == log->end)
  148. break;
  149. i++;
  150. }
  151. out_unlock:
  152. spin_unlock_irqrestore(&log->lock, flags);
  153. return count;
  154. }
  155. static ssize_t txpower_g_read_file(struct b43_wldev *dev,
  156. char *buf, size_t bufsize)
  157. {
  158. ssize_t count = 0;
  159. if (dev->phy.type != B43_PHYTYPE_G) {
  160. fappend("Device is not a G-PHY\n");
  161. goto out;
  162. }
  163. fappend("Control: %s\n", dev->phy.manual_txpower_control ?
  164. "MANUAL" : "AUTOMATIC");
  165. fappend("Baseband attenuation: %u\n", dev->phy.bbatt.att);
  166. fappend("Radio attenuation: %u\n", dev->phy.rfatt.att);
  167. fappend("TX Mixer Gain: %s\n",
  168. (dev->phy.tx_control & B43_TXCTL_TXMIX) ? "ON" : "OFF");
  169. fappend("PA Gain 2dB: %s\n",
  170. (dev->phy.tx_control & B43_TXCTL_PA2DB) ? "ON" : "OFF");
  171. fappend("PA Gain 3dB: %s\n",
  172. (dev->phy.tx_control & B43_TXCTL_PA3DB) ? "ON" : "OFF");
  173. fappend("\n\n");
  174. fappend("You can write to this file:\n");
  175. fappend("Writing \"auto\" enables automatic txpower control.\n");
  176. fappend
  177. ("Writing the attenuation values as \"bbatt rfatt txmix pa2db pa3db\" "
  178. "enables manual txpower control.\n");
  179. fappend("Example: 5 4 0 0 1\n");
  180. fappend("Enables manual control with Baseband attenuation 5, "
  181. "Radio attenuation 4, No TX Mixer Gain, "
  182. "No PA Gain 2dB, With PA Gain 3dB.\n");
  183. out:
  184. return count;
  185. }
  186. static int txpower_g_write_file(struct b43_wldev *dev,
  187. const char *buf, size_t count)
  188. {
  189. if (dev->phy.type != B43_PHYTYPE_G)
  190. return -ENODEV;
  191. if ((count >= 4) && (memcmp(buf, "auto", 4) == 0)) {
  192. /* Automatic control */
  193. dev->phy.manual_txpower_control = 0;
  194. b43_phy_xmitpower(dev);
  195. } else {
  196. int bbatt = 0, rfatt = 0, txmix = 0, pa2db = 0, pa3db = 0;
  197. /* Manual control */
  198. if (sscanf(buf, "%d %d %d %d %d", &bbatt, &rfatt,
  199. &txmix, &pa2db, &pa3db) != 5)
  200. return -EINVAL;
  201. b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
  202. dev->phy.manual_txpower_control = 1;
  203. dev->phy.bbatt.att = bbatt;
  204. dev->phy.rfatt.att = rfatt;
  205. dev->phy.tx_control = 0;
  206. if (txmix)
  207. dev->phy.tx_control |= B43_TXCTL_TXMIX;
  208. if (pa2db)
  209. dev->phy.tx_control |= B43_TXCTL_PA2DB;
  210. if (pa3db)
  211. dev->phy.tx_control |= B43_TXCTL_PA3DB;
  212. b43_phy_lock(dev);
  213. b43_radio_lock(dev);
  214. b43_set_txpower_g(dev, &dev->phy.bbatt,
  215. &dev->phy.rfatt, dev->phy.tx_control);
  216. b43_radio_unlock(dev);
  217. b43_phy_unlock(dev);
  218. }
  219. return 0;
  220. }
  221. /* wl->irq_lock is locked */
  222. static int restart_write_file(struct b43_wldev *dev,
  223. const char *buf, size_t count)
  224. {
  225. int err = 0;
  226. if (count > 0 && buf[0] == '1') {
  227. b43_controller_restart(dev, "manually restarted");
  228. } else
  229. err = -EINVAL;
  230. return err;
  231. }
  232. static unsigned long calc_expire_secs(unsigned long now,
  233. unsigned long time,
  234. unsigned long expire)
  235. {
  236. expire = time + expire;
  237. if (time_after(now, expire))
  238. return 0; /* expired */
  239. if (expire < now) {
  240. /* jiffies wrapped */
  241. expire -= MAX_JIFFY_OFFSET;
  242. now -= MAX_JIFFY_OFFSET;
  243. }
  244. B43_WARN_ON(expire < now);
  245. return (expire - now) / HZ;
  246. }
  247. static ssize_t loctls_read_file(struct b43_wldev *dev,
  248. char *buf, size_t bufsize)
  249. {
  250. ssize_t count = 0;
  251. struct b43_txpower_lo_control *lo;
  252. int i, err = 0;
  253. struct b43_lo_calib *cal;
  254. unsigned long now = jiffies;
  255. struct b43_phy *phy = &dev->phy;
  256. if (phy->type != B43_PHYTYPE_G) {
  257. fappend("Device is not a G-PHY\n");
  258. err = -ENODEV;
  259. goto out;
  260. }
  261. lo = phy->lo_control;
  262. fappend("-- Local Oscillator calibration data --\n\n");
  263. fappend("HW-power-control enabled: %d\n",
  264. dev->phy.hardware_power_control);
  265. fappend("TX Bias: 0x%02X, TX Magn: 0x%02X (expire in %lu sec)\n",
  266. lo->tx_bias, lo->tx_magn,
  267. calc_expire_secs(now, lo->txctl_measured_time,
  268. B43_LO_TXCTL_EXPIRE));
  269. fappend("Power Vector: 0x%08X%08X (expires in %lu sec)\n",
  270. (unsigned int)((lo->power_vector & 0xFFFFFFFF00000000ULL) >> 32),
  271. (unsigned int)(lo->power_vector & 0x00000000FFFFFFFFULL),
  272. calc_expire_secs(now, lo->pwr_vec_read_time,
  273. B43_LO_PWRVEC_EXPIRE));
  274. fappend("\nCalibrated settings:\n");
  275. list_for_each_entry(cal, &lo->calib_list, list) {
  276. bool active;
  277. active = (b43_compare_bbatt(&cal->bbatt, &phy->bbatt) &&
  278. b43_compare_rfatt(&cal->rfatt, &phy->rfatt));
  279. fappend("BB(%d), RF(%d,%d) -> I=%d, Q=%d "
  280. "(expires in %lu sec)%s\n",
  281. cal->bbatt.att,
  282. cal->rfatt.att, cal->rfatt.with_padmix,
  283. cal->ctl.i, cal->ctl.q,
  284. calc_expire_secs(now, cal->calib_time,
  285. B43_LO_CALIB_EXPIRE),
  286. active ? " ACTIVE" : "");
  287. }
  288. fappend("\nUsed RF attenuation values: Value(WithPadmix flag)\n");
  289. for (i = 0; i < lo->rfatt_list.len; i++) {
  290. fappend("%u(%d), ",
  291. lo->rfatt_list.list[i].att,
  292. lo->rfatt_list.list[i].with_padmix);
  293. }
  294. fappend("\n");
  295. fappend("\nUsed Baseband attenuation values:\n");
  296. for (i = 0; i < lo->bbatt_list.len; i++) {
  297. fappend("%u, ",
  298. lo->bbatt_list.list[i].att);
  299. }
  300. fappend("\n");
  301. out:
  302. return err ? err : count;
  303. }
  304. #undef fappend
  305. static int b43_debugfs_open(struct inode *inode, struct file *file)
  306. {
  307. file->private_data = inode->i_private;
  308. return 0;
  309. }
  310. static ssize_t b43_debugfs_read(struct file *file, char __user *userbuf,
  311. size_t count, loff_t *ppos)
  312. {
  313. struct b43_wldev *dev;
  314. struct b43_debugfs_fops *dfops;
  315. struct b43_dfs_file *dfile;
  316. ssize_t uninitialized_var(ret);
  317. char *buf;
  318. const size_t bufsize = 1024 * 16; /* 16 kiB buffer */
  319. const size_t buforder = get_order(bufsize);
  320. int err = 0;
  321. if (!count)
  322. return 0;
  323. dev = file->private_data;
  324. if (!dev)
  325. return -ENODEV;
  326. mutex_lock(&dev->wl->mutex);
  327. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  328. err = -ENODEV;
  329. goto out_unlock;
  330. }
  331. dfops = container_of(file->f_op, struct b43_debugfs_fops, fops);
  332. if (!dfops->read) {
  333. err = -ENOSYS;
  334. goto out_unlock;
  335. }
  336. dfile = fops_to_dfs_file(dev, dfops);
  337. if (!dfile->buffer) {
  338. buf = (char *)__get_free_pages(GFP_KERNEL, buforder);
  339. if (!buf) {
  340. err = -ENOMEM;
  341. goto out_unlock;
  342. }
  343. memset(buf, 0, bufsize);
  344. if (dfops->take_irqlock) {
  345. spin_lock_irq(&dev->wl->irq_lock);
  346. ret = dfops->read(dev, buf, bufsize);
  347. spin_unlock_irq(&dev->wl->irq_lock);
  348. } else
  349. ret = dfops->read(dev, buf, bufsize);
  350. if (ret <= 0) {
  351. free_pages((unsigned long)buf, buforder);
  352. err = ret;
  353. goto out_unlock;
  354. }
  355. dfile->data_len = ret;
  356. dfile->buffer = buf;
  357. }
  358. ret = simple_read_from_buffer(userbuf, count, ppos,
  359. dfile->buffer,
  360. dfile->data_len);
  361. if (*ppos >= dfile->data_len) {
  362. free_pages((unsigned long)dfile->buffer, buforder);
  363. dfile->buffer = NULL;
  364. dfile->data_len = 0;
  365. }
  366. out_unlock:
  367. mutex_unlock(&dev->wl->mutex);
  368. return err ? err : ret;
  369. }
  370. static ssize_t b43_debugfs_write(struct file *file,
  371. const char __user *userbuf,
  372. size_t count, loff_t *ppos)
  373. {
  374. struct b43_wldev *dev;
  375. struct b43_debugfs_fops *dfops;
  376. char *buf;
  377. int err = 0;
  378. if (!count)
  379. return 0;
  380. if (count > PAGE_SIZE)
  381. return -E2BIG;
  382. dev = file->private_data;
  383. if (!dev)
  384. return -ENODEV;
  385. mutex_lock(&dev->wl->mutex);
  386. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  387. err = -ENODEV;
  388. goto out_unlock;
  389. }
  390. dfops = container_of(file->f_op, struct b43_debugfs_fops, fops);
  391. if (!dfops->write) {
  392. err = -ENOSYS;
  393. goto out_unlock;
  394. }
  395. buf = (char *)get_zeroed_page(GFP_KERNEL);
  396. if (!buf) {
  397. err = -ENOMEM;
  398. goto out_unlock;
  399. }
  400. if (copy_from_user(buf, userbuf, count)) {
  401. err = -EFAULT;
  402. goto out_freepage;
  403. }
  404. if (dfops->take_irqlock) {
  405. spin_lock_irq(&dev->wl->irq_lock);
  406. err = dfops->write(dev, buf, count);
  407. spin_unlock_irq(&dev->wl->irq_lock);
  408. } else
  409. err = dfops->write(dev, buf, count);
  410. if (err)
  411. goto out_freepage;
  412. out_freepage:
  413. free_page((unsigned long)buf);
  414. out_unlock:
  415. mutex_unlock(&dev->wl->mutex);
  416. return err ? err : count;
  417. }
  418. #define B43_DEBUGFS_FOPS(name, _read, _write, _take_irqlock) \
  419. static struct b43_debugfs_fops fops_##name = { \
  420. .read = _read, \
  421. .write = _write, \
  422. .fops = { \
  423. .open = b43_debugfs_open, \
  424. .read = b43_debugfs_read, \
  425. .write = b43_debugfs_write, \
  426. }, \
  427. .file_struct_offset = offsetof(struct b43_dfsentry, \
  428. file_##name), \
  429. .take_irqlock = _take_irqlock, \
  430. }
  431. B43_DEBUGFS_FOPS(tsf, tsf_read_file, tsf_write_file, 1);
  432. B43_DEBUGFS_FOPS(ucode_regs, ucode_regs_read_file, NULL, 1);
  433. B43_DEBUGFS_FOPS(shm, shm_read_file, NULL, 1);
  434. B43_DEBUGFS_FOPS(txstat, txstat_read_file, NULL, 0);
  435. B43_DEBUGFS_FOPS(txpower_g, txpower_g_read_file, txpower_g_write_file, 0);
  436. B43_DEBUGFS_FOPS(restart, NULL, restart_write_file, 1);
  437. B43_DEBUGFS_FOPS(loctls, loctls_read_file, NULL, 0);
  438. int b43_debug(struct b43_wldev *dev, enum b43_dyndbg feature)
  439. {
  440. return !!(dev->dfsentry && dev->dfsentry->dyn_debug[feature]);
  441. }
  442. static void b43_remove_dynamic_debug(struct b43_wldev *dev)
  443. {
  444. struct b43_dfsentry *e = dev->dfsentry;
  445. int i;
  446. for (i = 0; i < __B43_NR_DYNDBG; i++)
  447. debugfs_remove(e->dyn_debug_dentries[i]);
  448. }
  449. static void b43_add_dynamic_debug(struct b43_wldev *dev)
  450. {
  451. struct b43_dfsentry *e = dev->dfsentry;
  452. struct dentry *d;
  453. #define add_dyn_dbg(name, id, initstate) do { \
  454. e->dyn_debug[id] = (initstate); \
  455. d = debugfs_create_bool(name, 0600, e->subdir, \
  456. &(e->dyn_debug[id])); \
  457. if (!IS_ERR(d)) \
  458. e->dyn_debug_dentries[id] = d; \
  459. } while (0)
  460. add_dyn_dbg("debug_xmitpower", B43_DBG_XMITPOWER, 0);
  461. add_dyn_dbg("debug_dmaoverflow", B43_DBG_DMAOVERFLOW, 0);
  462. add_dyn_dbg("debug_dmaverbose", B43_DBG_DMAVERBOSE, 0);
  463. add_dyn_dbg("debug_pwork_fast", B43_DBG_PWORK_FAST, 0);
  464. add_dyn_dbg("debug_pwork_stop", B43_DBG_PWORK_STOP, 0);
  465. add_dyn_dbg("debug_lo", B43_DBG_LO, 0);
  466. #undef add_dyn_dbg
  467. }
  468. void b43_debugfs_add_device(struct b43_wldev *dev)
  469. {
  470. struct b43_dfsentry *e;
  471. struct b43_txstatus_log *log;
  472. char devdir[16];
  473. B43_WARN_ON(!dev);
  474. e = kzalloc(sizeof(*e), GFP_KERNEL);
  475. if (!e) {
  476. b43err(dev->wl, "debugfs: add device OOM\n");
  477. return;
  478. }
  479. e->dev = dev;
  480. log = &e->txstatlog;
  481. log->log = kcalloc(B43_NR_LOGGED_TXSTATUS,
  482. sizeof(struct b43_txstatus), GFP_KERNEL);
  483. if (!log->log) {
  484. b43err(dev->wl, "debugfs: add device txstatus OOM\n");
  485. kfree(e);
  486. return;
  487. }
  488. log->end = -1;
  489. spin_lock_init(&log->lock);
  490. dev->dfsentry = e;
  491. snprintf(devdir, sizeof(devdir), "%s", wiphy_name(dev->wl->hw->wiphy));
  492. e->subdir = debugfs_create_dir(devdir, rootdir);
  493. if (!e->subdir || IS_ERR(e->subdir)) {
  494. if (e->subdir == ERR_PTR(-ENODEV)) {
  495. b43dbg(dev->wl, "DebugFS (CONFIG_DEBUG_FS) not "
  496. "enabled in kernel config\n");
  497. } else {
  498. b43err(dev->wl, "debugfs: cannot create %s directory\n",
  499. devdir);
  500. }
  501. dev->dfsentry = NULL;
  502. kfree(log->log);
  503. kfree(e);
  504. return;
  505. }
  506. #define ADD_FILE(name, mode) \
  507. do { \
  508. struct dentry *d; \
  509. d = debugfs_create_file(__stringify(name), \
  510. mode, e->subdir, dev, \
  511. &fops_##name.fops); \
  512. e->file_##name.dentry = NULL; \
  513. if (!IS_ERR(d)) \
  514. e->file_##name.dentry = d; \
  515. } while (0)
  516. ADD_FILE(tsf, 0600);
  517. ADD_FILE(ucode_regs, 0400);
  518. ADD_FILE(shm, 0400);
  519. ADD_FILE(txstat, 0400);
  520. ADD_FILE(txpower_g, 0600);
  521. ADD_FILE(restart, 0200);
  522. ADD_FILE(loctls, 0400);
  523. #undef ADD_FILE
  524. b43_add_dynamic_debug(dev);
  525. }
  526. void b43_debugfs_remove_device(struct b43_wldev *dev)
  527. {
  528. struct b43_dfsentry *e;
  529. if (!dev)
  530. return;
  531. e = dev->dfsentry;
  532. if (!e)
  533. return;
  534. b43_remove_dynamic_debug(dev);
  535. debugfs_remove(e->file_tsf.dentry);
  536. debugfs_remove(e->file_ucode_regs.dentry);
  537. debugfs_remove(e->file_shm.dentry);
  538. debugfs_remove(e->file_txstat.dentry);
  539. debugfs_remove(e->file_txpower_g.dentry);
  540. debugfs_remove(e->file_restart.dentry);
  541. debugfs_remove(e->file_loctls.dentry);
  542. debugfs_remove(e->subdir);
  543. kfree(e->txstatlog.log);
  544. kfree(e);
  545. }
  546. /* Called with IRQs disabled. */
  547. void b43_debugfs_log_txstat(struct b43_wldev *dev,
  548. const struct b43_txstatus *status)
  549. {
  550. struct b43_dfsentry *e = dev->dfsentry;
  551. struct b43_txstatus_log *log;
  552. struct b43_txstatus *cur;
  553. int i;
  554. if (!e)
  555. return;
  556. log = &e->txstatlog;
  557. spin_lock(&log->lock); /* IRQs are already disabled. */
  558. i = log->end + 1;
  559. if (i == B43_NR_LOGGED_TXSTATUS)
  560. i = 0;
  561. log->end = i;
  562. cur = &(log->log[i]);
  563. memcpy(cur, status, sizeof(*cur));
  564. spin_unlock(&log->lock);
  565. }
  566. void b43_debugfs_init(void)
  567. {
  568. rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
  569. if (IS_ERR(rootdir))
  570. rootdir = NULL;
  571. }
  572. void b43_debugfs_exit(void)
  573. {
  574. debugfs_remove(rootdir);
  575. }