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