mac80211: brcmsmac: do a read after write when writing objmem to device.
[openwrt.git] / package / mac80211 / patches / 564-ath9k_debugfs_diag.patch
1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -1678,6 +1678,50 @@ static const struct file_operations fops
4  };
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 (strict_strtoul(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 @@ -1760,5 +1804,8 @@ int ath9k_init_debug(struct ath_hw *ah)
55         debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
56                             sc, &fops_chanbw);
57  
58 +       debugfs_create_file("diag", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
59 +                           sc, &fops_diag);
60 +
61         return 0;
62  }
63 --- a/drivers/net/wireless/ath/ath9k/hw.h
64 +++ b/drivers/net/wireless/ath/ath9k/hw.h
65 @@ -498,6 +498,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 @@ -741,6 +747,8 @@ struct ath_hw {
79         u32 rfkill_polarity;
80         u32 ah_flags;
81  
82 +       unsigned long diag;
83 +
84         bool htc_reset_init;
85  
86         enum nl80211_iftype opmode;
87 @@ -1007,6 +1015,7 @@ void ath9k_hw_set_sta_beacon_timers(stru
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  #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 @@ -1749,6 +1749,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 @@ -2026,6 +2040,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
119         }
120  
121         ath9k_hw_apply_gpio_override(ah);
122 +       ath9k_hw_update_diag(ah);
123  
124         return 0;
125  }
126 --- a/drivers/net/wireless/ath/ath9k/main.c
127 +++ b/drivers/net/wireless/ath/ath9k/main.c
128 @@ -476,6 +476,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 */
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).