debugfs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  4. */
  5. #include "mt76.h"
  6. static int
  7. mt76_reg_set(void *data, u64 val)
  8. {
  9. struct mt76_dev *dev = data;
  10. __mt76_wr(dev, dev->debugfs_reg, val);
  11. return 0;
  12. }
  13. static int
  14. mt76_reg_get(void *data, u64 *val)
  15. {
  16. struct mt76_dev *dev = data;
  17. *val = __mt76_rr(dev, dev->debugfs_reg);
  18. return 0;
  19. }
  20. DEFINE_DEBUGFS_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set,
  21. "0x%08llx\n");
  22. int mt76_queues_read(struct seq_file *s, void *data)
  23. {
  24. struct mt76_dev *dev = dev_get_drvdata(s->private);
  25. int i;
  26. for (i = 0; i < ARRAY_SIZE(dev->phy.q_tx); i++) {
  27. struct mt76_queue *q = dev->phy.q_tx[i];
  28. if (!q)
  29. continue;
  30. seq_printf(s,
  31. "%d: queued=%d head=%d tail=%d\n",
  32. i, q->queued, q->head, q->tail);
  33. }
  34. return 0;
  35. }
  36. EXPORT_SYMBOL_GPL(mt76_queues_read);
  37. static int mt76_rx_queues_read(struct seq_file *s, void *data)
  38. {
  39. struct mt76_dev *dev = dev_get_drvdata(s->private);
  40. int i, queued;
  41. mt76_for_each_q_rx(dev, i) {
  42. struct mt76_queue *q = &dev->q_rx[i];
  43. queued = mt76_is_usb(dev) ? q->ndesc - q->queued : q->queued;
  44. seq_printf(s, "%d: queued=%d head=%d tail=%d\n",
  45. i, queued, q->head, q->tail);
  46. }
  47. return 0;
  48. }
  49. void mt76_seq_puts_array(struct seq_file *file, const char *str,
  50. s8 *val, int len)
  51. {
  52. int i;
  53. seq_printf(file, "%10s:", str);
  54. for (i = 0; i < len; i++)
  55. seq_printf(file, " %2d", val[i]);
  56. seq_puts(file, "\n");
  57. }
  58. EXPORT_SYMBOL_GPL(mt76_seq_puts_array);
  59. static int mt76_read_rate_txpower(struct seq_file *s, void *data)
  60. {
  61. struct mt76_dev *dev = dev_get_drvdata(s->private);
  62. mt76_seq_puts_array(s, "CCK", dev->rate_power.cck,
  63. ARRAY_SIZE(dev->rate_power.cck));
  64. mt76_seq_puts_array(s, "OFDM", dev->rate_power.ofdm,
  65. ARRAY_SIZE(dev->rate_power.ofdm));
  66. mt76_seq_puts_array(s, "STBC", dev->rate_power.stbc,
  67. ARRAY_SIZE(dev->rate_power.stbc));
  68. mt76_seq_puts_array(s, "HT", dev->rate_power.ht,
  69. ARRAY_SIZE(dev->rate_power.ht));
  70. mt76_seq_puts_array(s, "VHT", dev->rate_power.vht,
  71. ARRAY_SIZE(dev->rate_power.vht));
  72. return 0;
  73. }
  74. struct dentry *mt76_register_debugfs(struct mt76_dev *dev)
  75. {
  76. struct dentry *dir;
  77. dir = debugfs_create_dir("mt76", dev->hw->wiphy->debugfsdir);
  78. if (!dir)
  79. return NULL;
  80. debugfs_create_u8("led_pin", 0600, dir, &dev->led_pin);
  81. debugfs_create_bool("led_active_low", 0600, dir, &dev->led_al);
  82. debugfs_create_u32("regidx", 0600, dir, &dev->debugfs_reg);
  83. debugfs_create_file_unsafe("regval", 0600, dir, dev,
  84. &fops_regval);
  85. debugfs_create_blob("eeprom", 0400, dir, &dev->eeprom);
  86. if (dev->otp.data)
  87. debugfs_create_blob("otp", 0400, dir, &dev->otp);
  88. debugfs_create_devm_seqfile(dev->dev, "rate_txpower", dir,
  89. mt76_read_rate_txpower);
  90. debugfs_create_devm_seqfile(dev->dev, "rx-queues", dir,
  91. mt76_rx_queues_read);
  92. return dir;
  93. }
  94. EXPORT_SYMBOL_GPL(mt76_register_debugfs);