b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | --- a/drivers/net/wireless/ath/ath9k/debug.c |
| 2 | +++ b/drivers/net/wireless/ath/ath9k/debug.c |
| 3 | @@ -1512,6 +1512,50 @@ static const struct file_operations fops |
| 4 | #endif |
| 5 | |
| 6 | |
| 7 | +static ssize_t read_file_diag(struct file *file, char __user *user_buf, |
| 8 | + size_t count, loff_t *ppos) |
| 9 | +{ |
| 10 | + struct ath_softc *sc = file->private_data; |
| 11 | + struct ath_hw *ah = sc->sc_ah; |
| 12 | + char buf[32]; |
| 13 | + unsigned int len; |
| 14 | + |
| 15 | + len = sprintf(buf, "0x%08lx\n", ah->diag); |
| 16 | + return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 17 | +} |
| 18 | + |
| 19 | +static ssize_t write_file_diag(struct file *file, const char __user *user_buf, |
| 20 | + size_t count, loff_t *ppos) |
| 21 | +{ |
| 22 | + struct ath_softc *sc = file->private_data; |
| 23 | + struct ath_hw *ah = sc->sc_ah; |
| 24 | + unsigned long diag; |
| 25 | + char buf[32]; |
| 26 | + ssize_t len; |
| 27 | + |
| 28 | + len = min(count, sizeof(buf) - 1); |
| 29 | + if (copy_from_user(buf, user_buf, len)) |
| 30 | + return -EFAULT; |
| 31 | + |
| 32 | + buf[len] = '\0'; |
| 33 | + if (kstrtoul(buf, 0, &diag)) |
| 34 | + return -EINVAL; |
| 35 | + |
| 36 | + ah->diag = diag; |
| 37 | + ath9k_hw_update_diag(ah); |
| 38 | + |
| 39 | + return count; |
| 40 | +} |
| 41 | + |
| 42 | +static const struct file_operations fops_diag = { |
| 43 | + .read = read_file_diag, |
| 44 | + .write = write_file_diag, |
| 45 | + .open = simple_open, |
| 46 | + .owner = THIS_MODULE, |
| 47 | + .llseek = default_llseek, |
| 48 | +}; |
| 49 | + |
| 50 | + |
| 51 | int ath9k_init_debug(struct ath_hw *ah) |
| 52 | { |
| 53 | struct ath_common *common = ath9k_hw_common(ah); |
| 54 | @@ -1539,6 +1583,8 @@ int ath9k_init_debug(struct ath_hw *ah) |
| 55 | debugfs_create_file("gpio_led", S_IWUSR, |
| 56 | sc->debug.debugfs_phy, sc, &fops_gpio_led); |
| 57 | #endif |
| 58 | + debugfs_create_file("diag", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, |
| 59 | + sc, &fops_diag); |
| 60 | debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy, |
| 61 | read_file_dma); |
| 62 | debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy, |
| 63 | --- a/drivers/net/wireless/ath/ath9k/hw.h |
| 64 | +++ b/drivers/net/wireless/ath/ath9k/hw.h |
| 65 | @@ -522,6 +522,12 @@ enum { |
| 66 | ATH9K_RESET_COLD, |
| 67 | }; |
| 68 | |
| 69 | +enum { |
| 70 | + ATH_DIAG_DISABLE_RX, |
| 71 | + ATH_DIAG_DISABLE_TX, |
| 72 | + ATH_DIAG_TRIGGER_ERROR, |
| 73 | +}; |
| 74 | + |
| 75 | struct ath9k_hw_version { |
| 76 | u32 magic; |
| 77 | u16 devid; |
| 78 | @@ -810,6 +816,8 @@ struct ath_hw { |
| 79 | u32 ah_flags; |
| 80 | s16 nf_override; |
| 81 | |
| 82 | + unsigned long diag; |
| 83 | + |
| 84 | bool reset_power_on; |
| 85 | bool htc_reset_init; |
| 86 | |
| 87 | @@ -1077,6 +1085,7 @@ void ath9k_hw_check_nav(struct ath_hw *a |
| 88 | bool ath9k_hw_check_alive(struct ath_hw *ah); |
| 89 | |
| 90 | bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode); |
| 91 | +void ath9k_hw_update_diag(struct ath_hw *ah); |
| 92 | |
| 93 | /* Generic hw timer primitives */ |
| 94 | struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, |
| 95 | --- a/drivers/net/wireless/ath/ath9k/hw.c |
| 96 | +++ b/drivers/net/wireless/ath/ath9k/hw.c |
| 97 | @@ -1882,6 +1882,20 @@ u32 ath9k_hw_get_tsf_offset(struct times |
| 98 | } |
| 99 | EXPORT_SYMBOL(ath9k_hw_get_tsf_offset); |
| 100 | |
| 101 | +void ath9k_hw_update_diag(struct ath_hw *ah) |
| 102 | +{ |
| 103 | + if (test_bit(ATH_DIAG_DISABLE_RX, &ah->diag)) |
| 104 | + REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS); |
| 105 | + else |
| 106 | + REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS); |
| 107 | + |
| 108 | + if (test_bit(ATH_DIAG_DISABLE_TX, &ah->diag)) |
| 109 | + REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_LOOP_BACK); |
| 110 | + else |
| 111 | + REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_LOOP_BACK); |
| 112 | +} |
| 113 | +EXPORT_SYMBOL(ath9k_hw_update_diag); |
| 114 | + |
| 115 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, |
| 116 | struct ath9k_hw_cal_data *caldata, bool fastcc) |
| 117 | { |
| 118 | @@ -2090,6 +2104,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st |
| 119 | ar9003_hw_disable_phy_restart(ah); |
| 120 | |
| 121 | ath9k_hw_apply_gpio_override(ah); |
| 122 | + ath9k_hw_update_diag(ah); |
| 123 | |
| 124 | if (AR_SREV_9565(ah) && common->bt_ant_diversity) |
| 125 | REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON); |
| 126 | --- a/drivers/net/wireless/ath/ath9k/main.c |
| 127 | +++ b/drivers/net/wireless/ath/ath9k/main.c |
| 128 | @@ -538,6 +538,11 @@ irqreturn_t ath_isr(int irq, void *dev) |
| 129 | return IRQ_HANDLED; |
| 130 | } |
| 131 | |
| 132 | + if (test_bit(ATH_DIAG_TRIGGER_ERROR, &ah->diag)) { |
| 133 | + status |= ATH9K_INT_FATAL; |
| 134 | + clear_bit(ATH_DIAG_TRIGGER_ERROR, &ah->diag); |
| 135 | + } |
| 136 | + |
| 137 | /* |
| 138 | * If there are no status bits set, then this interrupt was not |
| 139 | * for me (should have been caught above). |