mac80211: adjust patches based on upstream feedback
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 530-ath9k_cleanup.patch
1 --- a/drivers/net/wireless/ath/ath9k/common.h
2 +++ b/drivers/net/wireless/ath/ath9k/common.h
3 @@ -81,6 +81,7 @@ struct ath_buf {
4 u16 bf_flags;
5 struct ath_buf_state bf_state;
6 dma_addr_t bf_dmacontext;
7 + struct ath_wiphy *aphy;
8 };
9
10 struct ath_atx_tid {
11 --- a/drivers/net/wireless/ath/ath9k/rc.h
12 +++ b/drivers/net/wireless/ath/ath9k/rc.h
13 @@ -167,24 +167,18 @@ struct ath_rate_priv {
14 struct ath_rate_softc *asc;
15 };
16
17 +#define ATH_TX_INFO_FRAME_TYPE_INTERNAL (1 << 0)
18 +#define ATH_TX_INFO_FRAME_TYPE_PAUSE (1 << 1)
19 +#define ATH_TX_INFO_UPDATE_RC (1 << 2)
20 +#define ATH_TX_INFO_XRETRY (1 << 3)
21 +#define ATH_TX_INFO_UNDERRUN (1 << 4)
22 +
23 enum ath9k_internal_frame_type {
24 ATH9K_NOT_INTERNAL,
25 ATH9K_INT_PAUSE,
26 ATH9K_INT_UNPAUSE
27 };
28
29 -struct ath_tx_info_priv {
30 - struct ath_wiphy *aphy;
31 - struct ath_tx_status tx;
32 - int n_frames;
33 - int n_bad_frames;
34 - bool update_rc;
35 - enum ath9k_internal_frame_type frame_type;
36 -};
37 -
38 -#define ATH_TX_INFO_PRIV(tx_info) \
39 - ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
40 -
41 void ath_rate_attach(struct ath_softc *sc);
42 u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
43 int ath_rate_control_register(void);
44 --- a/drivers/net/wireless/ath/ath9k/virtual.c
45 +++ b/drivers/net/wireless/ath/ath9k/virtual.c
46 @@ -338,13 +338,11 @@ void ath9k_wiphy_chan_work(struct work_s
47 void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
48 {
49 struct ath_wiphy *aphy = hw->priv;
50 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
51 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
52 - struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
53
54 - if (tx_info_priv && tx_info_priv->frame_type == ATH9K_INT_PAUSE &&
55 + if ((tx_info->pad[0] & ATH_TX_INFO_FRAME_TYPE_PAUSE) &&
56 aphy->state == ATH_WIPHY_PAUSING) {
57 - if (!(info->flags & IEEE80211_TX_STAT_ACK)) {
58 + if (!(tx_info->flags & IEEE80211_TX_STAT_ACK)) {
59 printk(KERN_DEBUG "ath9k: %s: no ACK for pause "
60 "frame\n", wiphy_name(hw->wiphy));
61 /*
62 @@ -363,9 +361,6 @@ void ath9k_tx_status(struct ieee80211_hw
63 }
64 }
65
66 - kfree(tx_info_priv);
67 - tx_info->rate_driver_data[0] = NULL;
68 -
69 dev_kfree_skb(skb);
70 }
71
72 --- a/drivers/net/wireless/ath/ath9k/xmit.c
73 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
74 @@ -251,6 +251,7 @@ static struct ath_buf* ath_clone_txbuf(s
75
76 ATH_TXBUF_RESET(tbf);
77
78 + tbf->aphy = bf->aphy;
79 tbf->bf_mpdu = bf->bf_mpdu;
80 tbf->bf_buf_addr = bf->bf_buf_addr;
81 *(tbf->bf_desc) = *(bf->bf_desc);
82 @@ -270,7 +271,6 @@ static void ath_tx_complete_aggr(struct
83 struct ieee80211_hw *hw;
84 struct ieee80211_hdr *hdr;
85 struct ieee80211_tx_info *tx_info;
86 - struct ath_tx_info_priv *tx_info_priv;
87 struct ath_atx_tid *tid = NULL;
88 struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
89 struct ath_desc *ds = bf_last->bf_desc;
90 @@ -284,8 +284,7 @@ static void ath_tx_complete_aggr(struct
91 hdr = (struct ieee80211_hdr *)skb->data;
92
93 tx_info = IEEE80211_SKB_CB(skb);
94 - tx_info_priv = (struct ath_tx_info_priv *) tx_info->rate_driver_data[0];
95 - hw = tx_info_priv->aphy->hw;
96 + hw = bf->aphy->hw;
97
98 rcu_read_lock();
99
100 @@ -464,7 +463,6 @@ static u32 ath_lookup_rate(struct ath_so
101 struct sk_buff *skb;
102 struct ieee80211_tx_info *tx_info;
103 struct ieee80211_tx_rate *rates;
104 - struct ath_tx_info_priv *tx_info_priv;
105 u32 max_4ms_framelen, frmlen;
106 u16 aggr_limit, legacy = 0;
107 int i;
108 @@ -472,7 +470,6 @@ static u32 ath_lookup_rate(struct ath_so
109 skb = bf->bf_mpdu;
110 tx_info = IEEE80211_SKB_CB(skb);
111 rates = tx_info->control.rates;
112 - tx_info_priv = (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
113
114 /*
115 * Find the lowest frame length among the rate series that will have a
116 @@ -1560,21 +1557,26 @@ static int ath_tx_setup_buffer(struct ie
117 struct ath_softc *sc = aphy->sc;
118 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
119 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
120 - struct ath_tx_info_priv *tx_info_priv;
121 int hdrlen;
122 __le16 fc;
123
124 - tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
125 - if (unlikely(!tx_info_priv))
126 - return -ENOMEM;
127 - tx_info->rate_driver_data[0] = tx_info_priv;
128 - tx_info_priv->aphy = aphy;
129 - tx_info_priv->frame_type = txctl->frame_type;
130 + tx_info->pad[0] = 0;
131 + switch (txctl->frame_type) {
132 + case ATH9K_NOT_INTERNAL:
133 + break;
134 + case ATH9K_INT_PAUSE:
135 + tx_info->pad[0] |= ATH_TX_INFO_FRAME_TYPE_PAUSE;
136 + /* fall through */
137 + case ATH9K_INT_UNPAUSE:
138 + tx_info->pad[0] |= ATH_TX_INFO_FRAME_TYPE_INTERNAL;
139 + break;
140 + }
141 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
142 fc = hdr->frame_control;
143
144 ATH_TXBUF_RESET(bf);
145
146 + bf->aphy = aphy;
147 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
148
149 if (conf_is_ht(&hw->conf) && !is_pae(skb))
150 @@ -1599,8 +1601,6 @@ static int ath_tx_setup_buffer(struct ie
151 skb->len, DMA_TO_DEVICE);
152 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
153 bf->bf_mpdu = NULL;
154 - kfree(tx_info_priv);
155 - tx_info->rate_driver_data[0] = NULL;
156 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
157 "dma_mapping_error() on TX\n");
158 return -ENOMEM;
159 @@ -1781,27 +1781,17 @@ exit:
160 /*****************/
161
162 static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
163 - int tx_flags)
164 + struct ath_wiphy *aphy, int tx_flags)
165 {
166 struct ieee80211_hw *hw = sc->hw;
167 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
168 - struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
169 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
170 int hdrlen, padsize;
171 - int frame_type = ATH9K_NOT_INTERNAL;
172
173 ath_print(common, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
174
175 - if (tx_info_priv) {
176 - hw = tx_info_priv->aphy->hw;
177 - frame_type = tx_info_priv->frame_type;
178 - }
179 -
180 - if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
181 - tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
182 - kfree(tx_info_priv);
183 - tx_info->rate_driver_data[0] = NULL;
184 - }
185 + if (aphy)
186 + hw = aphy->hw;
187
188 if (tx_flags & ATH_TX_BAR)
189 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
190 @@ -1833,10 +1823,10 @@ static void ath_tx_complete(struct ath_s
191 SC_OP_WAIT_FOR_TX_ACK));
192 }
193
194 - if (frame_type == ATH9K_NOT_INTERNAL)
195 - ieee80211_tx_status(hw, skb);
196 - else
197 + if (unlikely(tx_info->pad[0] & ATH_TX_INFO_FRAME_TYPE_INTERNAL))
198 ath9k_tx_status(hw, skb);
199 + else
200 + ieee80211_tx_status(hw, skb);
201 }
202
203 static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
204 @@ -1859,7 +1849,7 @@ static void ath_tx_complete_buf(struct a
205 }
206
207 dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
208 - ath_tx_complete(sc, skb, tx_flags);
209 + ath_tx_complete(sc, skb, bf->aphy, tx_flags);
210 ath_debug_stat_tx(sc, txq, bf);
211
212 /*
213 @@ -1907,8 +1897,7 @@ static void ath_tx_rc_status(struct ath_
214 struct sk_buff *skb = bf->bf_mpdu;
215 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
216 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
217 - struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
218 - struct ieee80211_hw *hw = tx_info_priv->aphy->hw;
219 + struct ieee80211_hw *hw = bf->aphy->hw;
220 u8 i, tx_rateindex;
221
222 if (txok)
223 @@ -1917,17 +1906,22 @@ static void ath_tx_rc_status(struct ath_
224 tx_rateindex = ds->ds_txstat.ts_rateindex;
225 WARN_ON(tx_rateindex >= hw->max_rates);
226
227 - tx_info_priv->update_rc = update_rc;
228 + if (update_rc)
229 + tx_info->pad[0] |= ATH_TX_INFO_UPDATE_RC;
230 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
231 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
232
233 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
234 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0 && update_rc) {
235 if (ieee80211_is_data(hdr->frame_control)) {
236 - memcpy(&tx_info_priv->tx, &ds->ds_txstat,
237 - sizeof(tx_info_priv->tx));
238 - tx_info_priv->n_frames = bf->bf_nframes;
239 - tx_info_priv->n_bad_frames = nbad;
240 + if (ds->ds_txstat.ts_flags &
241 + (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN))
242 + tx_info->pad[0] |= ATH_TX_INFO_UNDERRUN;
243 + if ((ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY) ||
244 + (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO))
245 + tx_info->pad[0] |= ATH_TX_INFO_XRETRY;
246 + tx_info->status.ampdu_len = bf->bf_nframes;
247 + tx_info->status.ampdu_ack_len = bf->bf_nframes - nbad;
248 }
249 }
250
251 --- a/drivers/net/wireless/ath/ath9k/debug.c
252 +++ b/drivers/net/wireless/ath/ath9k/debug.c
253 @@ -257,14 +257,17 @@ static const struct file_operations fops
254
255 void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
256 {
257 - struct ath_tx_info_priv *tx_info_priv = NULL;
258 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
259 struct ieee80211_tx_rate *rates = tx_info->status.rates;
260 - int final_ts_idx, idx;
261 + int final_ts_idx = 0, idx, i;
262 struct ath_rc_stats *stats;
263
264 - tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
265 - final_ts_idx = tx_info_priv->tx.ts_rateindex;
266 + for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
267 + if (!rates[i].count)
268 + break;
269 +
270 + final_ts_idx = i;
271 + }
272 idx = rates[final_ts_idx].idx;
273 stats = &sc->debug.stats.rcstats[idx];
274 stats->success++;
275 --- a/drivers/net/wireless/ath/ath9k/rc.c
276 +++ b/drivers/net/wireless/ath/ath9k/rc.c
277 @@ -859,12 +859,12 @@ static void ath_get_rate(void *priv, str
278 static bool ath_rc_update_per(struct ath_softc *sc,
279 const struct ath_rate_table *rate_table,
280 struct ath_rate_priv *ath_rc_priv,
281 - struct ath_tx_info_priv *tx_info_priv,
282 + struct ieee80211_tx_info *tx_info,
283 int tx_rate, int xretries, int retries,
284 u32 now_msec)
285 {
286 bool state_change = false;
287 - int count;
288 + int count, n_bad_frames;
289 u8 last_per;
290 static u32 nretry_to_per_lookup[10] = {
291 100 * 0 / 1,
292 @@ -880,6 +880,7 @@ static bool ath_rc_update_per(struct ath
293 };
294
295 last_per = ath_rc_priv->per[tx_rate];
296 + n_bad_frames = tx_info->status.ampdu_len - tx_info->status.ampdu_ack_len;
297
298 if (xretries) {
299 if (xretries == 1) {
300 @@ -907,7 +908,7 @@ static bool ath_rc_update_per(struct ath
301 if (retries >= count)
302 retries = count - 1;
303
304 - if (tx_info_priv->n_bad_frames) {
305 + if (n_bad_frames) {
306 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
307 * Assuming that n_frames is not 0. The current PER
308 * from the retries is 100 * retries / (retries+1),
309 @@ -920,14 +921,14 @@ static bool ath_rc_update_per(struct ath
310 * the above PER. The expression below is a
311 * simplified version of the sum of these two terms.
312 */
313 - if (tx_info_priv->n_frames > 0) {
314 - int n_frames, n_bad_frames;
315 + if (tx_info->status.ampdu_len > 0) {
316 + int n_frames, n_bad_tries;
317 u8 cur_per, new_per;
318
319 - n_bad_frames = retries * tx_info_priv->n_frames +
320 - tx_info_priv->n_bad_frames;
321 - n_frames = tx_info_priv->n_frames * (retries + 1);
322 - cur_per = (100 * n_bad_frames / n_frames) >> 3;
323 + n_bad_tries = retries * tx_info->status.ampdu_len +
324 + n_bad_frames;
325 + n_frames = tx_info->status.ampdu_len * (retries + 1);
326 + cur_per = (100 * n_bad_tries / n_frames) >> 3;
327 new_per = (u8)(last_per - (last_per >> 3) + cur_per);
328 ath_rc_priv->per[tx_rate] = new_per;
329 }
330 @@ -943,8 +944,7 @@ static bool ath_rc_update_per(struct ath
331 * this was a probe. Otherwise, ignore the probe.
332 */
333 if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
334 - if (retries > 0 || 2 * tx_info_priv->n_bad_frames >
335 - tx_info_priv->n_frames) {
336 + if (retries > 0 || 2 * n_bad_frames > tx_info->status.ampdu_len) {
337 /*
338 * Since we probed with just a single attempt,
339 * any retries means the probe failed. Also,
340 @@ -1003,7 +1003,7 @@ static bool ath_rc_update_per(struct ath
341
342 static void ath_rc_update_ht(struct ath_softc *sc,
343 struct ath_rate_priv *ath_rc_priv,
344 - struct ath_tx_info_priv *tx_info_priv,
345 + struct ieee80211_tx_info *tx_info,
346 int tx_rate, int xretries, int retries)
347 {
348 u32 now_msec = jiffies_to_msecs(jiffies);
349 @@ -1020,7 +1020,7 @@ static void ath_rc_update_ht(struct ath_
350
351 /* Update PER first */
352 state_change = ath_rc_update_per(sc, rate_table, ath_rc_priv,
353 - tx_info_priv, tx_rate, xretries,
354 + tx_info, tx_rate, xretries,
355 retries, now_msec);
356
357 /*
358 @@ -1098,7 +1098,6 @@ static void ath_rc_tx_status(struct ath_
359 struct ieee80211_tx_info *tx_info,
360 int final_ts_idx, int xretries, int long_retry)
361 {
362 - struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
363 const struct ath_rate_table *rate_table;
364 struct ieee80211_tx_rate *rates = tx_info->status.rates;
365 u8 flags;
366 @@ -1124,9 +1123,8 @@ static void ath_rc_tx_status(struct ath_
367 return;
368
369 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
370 - ath_rc_update_ht(sc, ath_rc_priv,
371 - tx_info_priv, rix,
372 - xretries ? 1 : 2,
373 + ath_rc_update_ht(sc, ath_rc_priv, tx_info,
374 + rix, xretries ? 1 : 2,
375 rates[i].count);
376 }
377 }
378 @@ -1149,8 +1147,7 @@ static void ath_rc_tx_status(struct ath_
379 return;
380
381 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
382 - ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
383 - xretries, long_retry);
384 + ath_rc_update_ht(sc, ath_rc_priv, tx_info, rix, xretries, long_retry);
385 }
386
387 static const
388 @@ -1301,23 +1298,30 @@ static void ath_tx_status(void *priv, st
389 {
390 struct ath_softc *sc = priv;
391 struct ath_rate_priv *ath_rc_priv = priv_sta;
392 - struct ath_tx_info_priv *tx_info_priv = NULL;
393 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
394 struct ieee80211_hdr *hdr;
395 - int final_ts_idx, tx_status = 0, is_underrun = 0;
396 + int final_ts_idx = 0, tx_status = 0, is_underrun = 0;
397 + int long_retry = 0;
398 __le16 fc;
399 + int i;
400
401 hdr = (struct ieee80211_hdr *)skb->data;
402 fc = hdr->frame_control;
403 - tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
404 - final_ts_idx = tx_info_priv->tx.ts_rateindex;
405 + for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
406 + struct ieee80211_tx_rate *rate = &tx_info->status.rates[i];
407 + if (!rate->count)
408 + break;
409 +
410 + final_ts_idx = i;
411 + long_retry = rate->count - 1;
412 + }
413
414 if (!priv_sta || !ieee80211_is_data(fc) ||
415 - !tx_info_priv->update_rc)
416 - goto exit;
417 + !(tx_info->pad[0] & ATH_TX_INFO_UPDATE_RC))
418 + return;
419
420 - if (tx_info_priv->tx.ts_status & ATH9K_TXERR_FILT)
421 - goto exit;
422 + if (tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED)
423 + return;
424
425 /*
426 * If underrun error is seen assume it as an excessive retry only
427 @@ -1325,20 +1329,17 @@ static void ath_tx_status(void *priv, st
428 * Adjust the long retry as if the frame was tried hw->max_rate_tries
429 * times. This affects how ratectrl updates PER for the failed rate.
430 */
431 - if (tx_info_priv->tx.ts_flags &
432 - (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
433 - ((sc->sc_ah->tx_trig_level) >= ath_rc_priv->tx_triglevel_max)) {
434 + if ((tx_info->pad[0] & ATH_TX_INFO_UNDERRUN) &&
435 + (sc->sc_ah->tx_trig_level >= ath_rc_priv->tx_triglevel_max)) {
436 tx_status = 1;
437 is_underrun = 1;
438 }
439
440 - if ((tx_info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
441 - (tx_info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
442 + if (tx_info->pad[0] & ATH_TX_INFO_XRETRY)
443 tx_status = 1;
444
445 ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
446 - (is_underrun) ? sc->hw->max_rate_tries :
447 - tx_info_priv->tx.ts_longretry);
448 + (is_underrun) ? sc->hw->max_rate_tries : long_retry);
449
450 /* Check if aggregation has to be enabled for this tid */
451 if (conf_is_ht(&sc->hw->conf) &&
452 @@ -1357,8 +1358,6 @@ static void ath_tx_status(void *priv, st
453 }
454
455 ath_debug_stat_rc(sc, skb);
456 -exit:
457 - kfree(tx_info_priv);
458 }
459
460 static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,