ath9k: make the regulatory override less intrusive - allow it to parse CTLs
[openwrt.git] / package / mac80211 / patches / 540-ath9k_rc_debugfs.patch
1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -378,95 +378,6 @@ static const struct file_operations fops
4         .owner = THIS_MODULE
5  };
6  
7 -void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
8 -{
9 -       struct ath_rc_stats *stats;
10 -
11 -       stats = &sc->debug.stats.rcstats[final_rate];
12 -       stats->success++;
13 -}
14 -
15 -void ath_debug_stat_retries(struct ath_softc *sc, int rix,
16 -                           int xretries, int retries, u8 per)
17 -{
18 -       struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
19 -
20 -       stats->xretries += xretries;
21 -       stats->retries += retries;
22 -       stats->per = per;
23 -}
24 -
25 -static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
26 -                               size_t count, loff_t *ppos)
27 -{
28 -       struct ath_softc *sc = file->private_data;
29 -       char *buf;
30 -       unsigned int len = 0, max;
31 -       int i = 0;
32 -       ssize_t retval;
33 -
34 -       if (sc->cur_rate_table == NULL)
35 -               return 0;
36 -
37 -       max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1;
38 -       buf = kmalloc(max, GFP_KERNEL);
39 -       if (buf == NULL)
40 -               return -ENOMEM;
41 -
42 -       len += sprintf(buf, "%6s %6s %6s "
43 -                      "%10s %10s %10s %10s\n",
44 -                      "HT", "MCS", "Rate",
45 -                      "Success", "Retries", "XRetries", "PER");
46 -
47 -       for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
48 -               u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
49 -               struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
50 -               char mcs[5];
51 -               char htmode[5];
52 -               int used_mcs = 0, used_htmode = 0;
53 -
54 -               if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
55 -                       used_mcs = snprintf(mcs, 5, "%d",
56 -                               sc->cur_rate_table->info[i].ratecode);
57 -
58 -                       if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
59 -                               used_htmode = snprintf(htmode, 5, "HT40");
60 -                       else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
61 -                               used_htmode = snprintf(htmode, 5, "HT20");
62 -                       else
63 -                               used_htmode = snprintf(htmode, 5, "????");
64 -               }
65 -
66 -               mcs[used_mcs] = '\0';
67 -               htmode[used_htmode] = '\0';
68 -
69 -               len += snprintf(buf + len, max - len,
70 -                       "%6s %6s %3u.%d: "
71 -                       "%10u %10u %10u %10u\n",
72 -                       htmode,
73 -                       mcs,
74 -                       ratekbps / 1000,
75 -                       (ratekbps % 1000) / 100,
76 -                       stats->success,
77 -                       stats->retries,
78 -                       stats->xretries,
79 -                       stats->per);
80 -       }
81 -
82 -       if (len > max)
83 -               len = max;
84 -
85 -       retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
86 -       kfree(buf);
87 -       return retval;
88 -}
89 -
90 -static const struct file_operations fops_rcstat = {
91 -       .read = read_file_rcstat,
92 -       .open = ath9k_debugfs_open,
93 -       .owner = THIS_MODULE
94 -};
95 -
96  static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
97  {
98         switch (state) {
99 @@ -1024,10 +935,6 @@ int ath9k_init_debug(struct ath_hw *ah)
100                         sc, &fops_interrupt))
101                 goto err;
102  
103 -       if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy,
104 -                       sc, &fops_rcstat))
105 -               goto err;
106 -
107         if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
108                         sc->debug.debugfs_phy, sc, &fops_wiphy))
109                 goto err;
110 --- a/drivers/net/wireless/ath/ath9k/debug.h
111 +++ b/drivers/net/wireless/ath/ath9k/debug.h
112 @@ -80,13 +80,6 @@ struct ath_interrupt_stats {
113         u32 bb_watchdog;
114  };
115  
116 -struct ath_rc_stats {
117 -       u32 success;
118 -       u32 retries;
119 -       u32 xretries;
120 -       u8 per;
121 -};
122 -
123  /**
124   * struct ath_tx_stats - Statistics about TX
125   * @tx_pkts_all:  No. of total frames transmitted, including ones that
126 @@ -160,7 +153,6 @@ struct ath_rx_stats {
127  
128  struct ath_stats {
129         struct ath_interrupt_stats istats;
130 -       struct ath_rc_stats rcstats[RATE_TABLE_SIZE];
131         struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES];
132         struct ath_rx_stats rxstats;
133  };
134 @@ -177,12 +169,9 @@ void ath9k_exit_debug(struct ath_hw *ah)
135  int ath9k_debug_create_root(void);
136  void ath9k_debug_remove_root(void);
137  void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status);
138 -void ath_debug_stat_rc(struct ath_softc *sc, int final_rate);
139  void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
140                        struct ath_buf *bf, struct ath_tx_status *ts);
141  void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs);
142 -void ath_debug_stat_retries(struct ath_softc *sc, int rix,
143 -                           int xretries, int retries, u8 per);
144  
145  #else
146  
147 @@ -209,11 +198,6 @@ static inline void ath_debug_stat_interr
148  {
149  }
150  
151 -static inline void ath_debug_stat_rc(struct ath_softc *sc,
152 -                                    int final_rate)
153 -{
154 -}
155 -
156  static inline void ath_debug_stat_tx(struct ath_softc *sc,
157                                      struct ath_txq *txq,
158                                      struct ath_buf *bf,
159 @@ -226,11 +210,6 @@ static inline void ath_debug_stat_rx(str
160  {
161  }
162  
163 -static inline void ath_debug_stat_retries(struct ath_softc *sc, int rix,
164 -                                         int xretries, int retries, u8 per)
165 -{
166 -}
167 -
168  #endif /* CONFIG_ATH9K_DEBUGFS */
169  
170  #endif /* DEBUG_H */
171 --- a/drivers/net/wireless/ath/ath9k/rc.c
172 +++ b/drivers/net/wireless/ath/ath9k/rc.c
173 @@ -1026,6 +1026,16 @@ static bool ath_rc_update_per(struct ath
174         return state_change;
175  }
176  
177 +static void ath_debug_stat_retries(struct ath_rate_priv *rc, int rix,
178 +                                  int xretries, int retries, u8 per)
179 +{
180 +       struct ath_rc_stats *stats = &rc->rcstats[rix];
181 +
182 +       stats->xretries += xretries;
183 +       stats->retries += retries;
184 +       stats->per = per;
185 +}
186 +
187  /* Update PER, RSSI and whatever else that the code thinks it is doing.
188     If you can make sense of all this, you really need to go out more. */
189  
190 @@ -1098,7 +1108,7 @@ static void ath_rc_update_ht(struct ath_
191                 ath_rc_priv->per_down_time = now_msec;
192         }
193  
194 -       ath_debug_stat_retries(sc, tx_rate, xretries, retries,
195 +       ath_debug_stat_retries(ath_rc_priv, tx_rate, xretries, retries,
196                                ath_rc_priv->per[tx_rate]);
197  
198  }
199 @@ -1294,6 +1304,7 @@ static void ath_rc_init(struct ath_softc
200         ath_rc_sort_validrates(rate_table, ath_rc_priv);
201         ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
202         sc->cur_rate_table = rate_table;
203 +       ath_rc_priv->rate_table = rate_table;
204  
205         ath_print(common, ATH_DBG_CONFIG,
206                   "RC Initialized with capabilities: 0x%x\n",
207 @@ -1340,6 +1351,15 @@ static bool ath_tx_aggr_check(struct ath
208  /* mac80211 Rate Control callbacks */
209  /***********************************/
210  
211 +static void ath_debug_stat_rc(struct ath_rate_priv *rc, int final_rate)
212 +{
213 +       struct ath_rc_stats *stats;
214 +
215 +       stats = &rc->rcstats[final_rate];
216 +       stats->success++;
217 +}
218 +
219 +
220  static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
221                           struct ieee80211_sta *sta, void *priv_sta,
222                           struct sk_buff *skb)
223 @@ -1419,7 +1439,7 @@ static void ath_tx_status(void *priv, st
224                 }
225         }
226  
227 -       ath_debug_stat_rc(sc, ath_rc_get_rateindex(sc->cur_rate_table,
228 +       ath_debug_stat_rc(ath_rc_priv, ath_rc_get_rateindex(sc->cur_rate_table,
229                 &tx_info->status.rates[final_ts_idx]));
230  }
231  
232 @@ -1521,6 +1541,94 @@ static void ath_rate_update(void *priv, 
233         }
234  }
235  
236 +#ifdef CONFIG_ATH9K_DEBUGFS
237 +
238 +static int ath9k_debugfs_open(struct inode *inode, struct file *file)
239 +{
240 +       file->private_data = inode->i_private;
241 +       return 0;
242 +}
243 +
244 +static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
245 +                               size_t count, loff_t *ppos)
246 +{
247 +       struct ath_rate_priv *rc = file->private_data;
248 +       char *buf;
249 +       unsigned int len = 0, max;
250 +       int i = 0;
251 +       ssize_t retval;
252 +
253 +       if (rc->rate_table == NULL)
254 +               return 0;
255 +
256 +       max = 80 + rc->rate_table->rate_cnt * 1024 + 1;
257 +       buf = kmalloc(max, GFP_KERNEL);
258 +       if (buf == NULL)
259 +               return -ENOMEM;
260 +
261 +       len += sprintf(buf, "%6s %6s %6s "
262 +                      "%10s %10s %10s %10s\n",
263 +                      "HT", "MCS", "Rate",
264 +                      "Success", "Retries", "XRetries", "PER");
265 +
266 +       for (i = 0; i < rc->rate_table->rate_cnt; i++) {
267 +               u32 ratekbps = rc->rate_table->info[i].ratekbps;
268 +               struct ath_rc_stats *stats = &rc->rcstats[i];
269 +               char mcs[5];
270 +               char htmode[5];
271 +               int used_mcs = 0, used_htmode = 0;
272 +
273 +               if (WLAN_RC_PHY_HT(rc->rate_table->info[i].phy)) {
274 +                       used_mcs = snprintf(mcs, 5, "%d",
275 +                               rc->rate_table->info[i].ratecode);
276 +
277 +                       if (WLAN_RC_PHY_40(rc->rate_table->info[i].phy))
278 +                               used_htmode = snprintf(htmode, 5, "HT40");
279 +                       else if (WLAN_RC_PHY_20(rc->rate_table->info[i].phy))
280 +                               used_htmode = snprintf(htmode, 5, "HT20");
281 +                       else
282 +                               used_htmode = snprintf(htmode, 5, "????");
283 +               }
284 +
285 +               mcs[used_mcs] = '\0';
286 +               htmode[used_htmode] = '\0';
287 +
288 +               len += snprintf(buf + len, max - len,
289 +                       "%6s %6s %3u.%d: "
290 +                       "%10u %10u %10u %10u\n",
291 +                       htmode,
292 +                       mcs,
293 +                       ratekbps / 1000,
294 +                       (ratekbps % 1000) / 100,
295 +                       stats->success,
296 +                       stats->retries,
297 +                       stats->xretries,
298 +                       stats->per);
299 +       }
300 +
301 +       if (len > max)
302 +               len = max;
303 +
304 +       retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
305 +       kfree(buf);
306 +       return retval;
307 +}
308 +
309 +static const struct file_operations fops_rcstat = {
310 +       .read = read_file_rcstat,
311 +       .open = ath9k_debugfs_open,
312 +       .owner = THIS_MODULE
313 +};
314 +
315 +static void ath_rate_add_sta_debugfs(void *priv, void *priv_sta,
316 +                                    struct dentry *dir)
317 +{
318 +       struct ath_rate_priv *rc = priv_sta;
319 +       debugfs_create_file("rc_stats", S_IRUGO, dir, rc, &fops_rcstat);
320 +}
321 +
322 +#endif /* CONFIG_ATH9K_DEBUGFS */
323 +
324  static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
325  {
326         struct ath_wiphy *aphy = hw->priv;
327 @@ -1567,6 +1675,9 @@ static struct rate_control_ops ath_rate_
328         .free = ath_rate_free,
329         .alloc_sta = ath_rate_alloc_sta,
330         .free_sta = ath_rate_free_sta,
331 +#ifdef CONFIG_ATH9K_DEBUGFS
332 +       .add_sta_debugfs = ath_rate_add_sta_debugfs,
333 +#endif
334  };
335  
336  int ath_rate_control_register(void)
337 --- a/drivers/net/wireless/ath/ath9k/rc.h
338 +++ b/drivers/net/wireless/ath/ath9k/rc.h
339 @@ -176,6 +176,13 @@ struct ath_rateset {
340         u8 rs_rates[ATH_RATE_MAX];
341  };
342  
343 +struct ath_rc_stats {
344 +       u32 success;
345 +       u32 retries;
346 +       u32 xretries;
347 +       u8 per;
348 +};
349 +
350  /**
351   * struct ath_rate_priv - Rate Control priv data
352   * @state: RC state
353 @@ -212,6 +219,10 @@ struct ath_rate_priv {
354         struct ath_rateset neg_rates;
355         struct ath_rateset neg_ht_rates;
356         struct ath_rate_softc *asc;
357 +       const struct ath_rate_table *rate_table;
358 +
359 +       struct dentry *debugfs_rcstats;
360 +       struct ath_rc_stats rcstats[RATE_TABLE_SIZE];
361  };
362  
363  #define ATH_TX_INFO_FRAME_TYPE_INTERNAL        (1 << 0)