ath9k: add fixes for rx processing and baseband hang detection
[openwrt.git] / package / kernel / mac80211 / patches / 542-ath9k_debugfs_diag.patch
1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -1631,6 +1631,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 @@ -1658,6 +1702,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_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
61                             &fops_dma);
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 {
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 @@ -762,6 +768,8 @@ struct ath_hw {
79         u32 rfkill_polarity;
80         u32 ah_flags;
81  
82 +       unsigned long diag;
83 +
84         bool reset_power_on;
85         bool htc_reset_init;
86  
87 @@ -1013,6 +1021,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 @@ -1736,6 +1736,20 @@ fail:
98         return -EINVAL;
99  }
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 @@ -1941,6 +1955,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 @@ -602,6 +602,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 */
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).