1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -2149,6 +2149,50 @@ static const struct file_operations fops
7 +static ssize_t read_file_diag(struct file *file, char __user *user_buf,
8 + size_t count, loff_t *ppos)
10 + struct ath_softc *sc = file->private_data;
11 + struct ath_hw *ah = sc->sc_ah;
15 + len = sprintf(buf, "0x%08lx\n", ah->diag);
16 + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
19 +static ssize_t write_file_diag(struct file *file, const char __user *user_buf,
20 + size_t count, loff_t *ppos)
22 + struct ath_softc *sc = file->private_data;
23 + struct ath_hw *ah = sc->sc_ah;
28 + len = min(count, sizeof(buf) - 1);
29 + if (copy_from_user(buf, user_buf, len))
33 + if (strict_strtoul(buf, 0, &diag))
37 + ath9k_hw_update_diag(ah);
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,
51 int ath9k_init_debug(struct ath_hw *ah)
53 struct ath_common *common = ath9k_hw_common(ah);
54 @@ -2174,6 +2218,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);
58 + debugfs_create_file("diag", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
60 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
62 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
63 --- a/drivers/net/wireless/ath/ath9k/hw.h
64 +++ b/drivers/net/wireless/ath/ath9k/hw.h
65 @@ -500,6 +500,12 @@ enum {
70 + ATH_DIAG_DISABLE_RX,
71 + ATH_DIAG_DISABLE_TX,
72 + ATH_DIAG_TRIGGER_ERROR,
75 struct ath9k_hw_version {
78 @@ -778,6 +784,8 @@ struct ath_hw {
87 @@ -1041,6 +1049,7 @@ void ath9k_hw_set_sta_beacon_timers(stru
88 bool ath9k_hw_check_alive(struct ath_hw *ah);
90 bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode);
91 +void ath9k_hw_update_diag(struct ath_hw *ah);
93 #ifdef CONFIG_ATH9K_DEBUGFS
94 void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause);
95 --- a/drivers/net/wireless/ath/ath9k/hw.c
96 +++ b/drivers/net/wireless/ath/ath9k/hw.c
97 @@ -1747,6 +1747,20 @@ fail:
101 +void ath9k_hw_update_diag(struct ath_hw *ah)
103 + if (test_bit(ATH_DIAG_DISABLE_RX, &ah->diag))
104 + REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
106 + REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
108 + if (test_bit(ATH_DIAG_DISABLE_TX, &ah->diag))
109 + REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_LOOP_BACK);
111 + REG_CLR_BIT(ah, AR_DIAG_SW, AR_DIAG_LOOP_BACK);
113 +EXPORT_SYMBOL(ath9k_hw_update_diag);
115 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
116 struct ath9k_hw_cal_data *caldata, bool fastcc)
118 @@ -2024,6 +2038,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
121 ath9k_hw_apply_gpio_override(ah);
122 + ath9k_hw_update_diag(ah);
124 if (AR_SREV_9565(ah) && ah->shared_chain_lnadiv)
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 @@ -459,6 +459,11 @@ irqreturn_t ath_isr(int irq, void *dev)
129 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
130 status &= ah->imask; /* discard unasked-for bits */
132 + if (test_bit(ATH_DIAG_TRIGGER_ERROR, &ah->diag)) {
133 + status |= ATH9K_INT_FATAL;
134 + clear_bit(ATH_DIAG_TRIGGER_ERROR, &ah->diag);
138 * If there are no status bits set, then this interrupt was not
139 * for me (should have been caught above).