1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -1437,6 +1437,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 (kstrtoul(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 @@ -1464,6 +1508,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 @@ -482,6 +482,12 @@ enum {
70 + ATH_DIAG_DISABLE_RX,
71 + ATH_DIAG_DISABLE_TX,
72 + ATH_DIAG_TRIGGER_ERROR,
75 struct ath9k_hw_version {
78 @@ -762,6 +768,8 @@ struct ath_hw {
87 @@ -1013,6 +1021,7 @@ void ath9k_hw_check_nav(struct ath_hw *a
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 /* 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 @@ -1735,6 +1735,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 @@ -1940,6 +1954,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
119 ar9003_hw_disable_phy_restart(ah);
121 ath9k_hw_apply_gpio_override(ah);
122 + ath9k_hw_update_diag(ah);
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 @@ -605,6 +605,11 @@ irqreturn_t ath_isr(int irq, void *dev)
129 ath9k_debug_sync_cause(sc, sync_cause);
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).