debugfs.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "mt76.h"
  17. static int
  18. mt76_reg_set(void *data, u64 val)
  19. {
  20. struct mt76_dev *dev = data;
  21. dev->bus->wr(dev, dev->debugfs_reg, val);
  22. return 0;
  23. }
  24. static int
  25. mt76_reg_get(void *data, u64 *val)
  26. {
  27. struct mt76_dev *dev = data;
  28. *val = dev->bus->rr(dev, dev->debugfs_reg);
  29. return 0;
  30. }
  31. DEFINE_DEBUGFS_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set,
  32. "0x%08llx\n");
  33. static int
  34. mt76_queues_read(struct seq_file *s, void *data)
  35. {
  36. struct mt76_dev *dev = dev_get_drvdata(s->private);
  37. int i;
  38. for (i = 0; i < ARRAY_SIZE(dev->q_tx); i++) {
  39. struct mt76_queue *q = &dev->q_tx[i];
  40. if (!q->ndesc)
  41. continue;
  42. seq_printf(s,
  43. "%d: queued=%d head=%d tail=%d swq_queued=%d\n",
  44. i, q->queued, q->head, q->tail, q->swq_queued);
  45. }
  46. return 0;
  47. }
  48. struct dentry *mt76_register_debugfs(struct mt76_dev *dev)
  49. {
  50. struct dentry *dir;
  51. dir = debugfs_create_dir("mt76", dev->hw->wiphy->debugfsdir);
  52. if (!dir)
  53. return NULL;
  54. debugfs_create_u8("led_pin", 0600, dir, &dev->led_pin);
  55. debugfs_create_u32("regidx", 0600, dir, &dev->debugfs_reg);
  56. debugfs_create_file_unsafe("regval", 0600, dir, dev,
  57. &fops_regval);
  58. debugfs_create_blob("eeprom", 0400, dir, &dev->eeprom);
  59. if (dev->otp.data)
  60. debugfs_create_blob("otp", 0400, dir, &dev->otp);
  61. debugfs_create_devm_seqfile(dev->dev, "queues", dir, mt76_queues_read);
  62. return dir;
  63. }
  64. EXPORT_SYMBOL_GPL(mt76_register_debugfs);