mac80211: update to 2011-02-25
[oweals/openwrt.git] / package / mac80211 / patches / 531-ath9k_fix_ap_ps_buffering.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -203,6 +203,7 @@ struct ath_atx_ac {
4         int sched;
5         struct list_head list;
6         struct list_head tid_q;
7 +       bool clear_ps_filter;
8  };
9  
10  struct ath_frame_info {
11 @@ -260,6 +261,8 @@ struct ath_node {
12         struct ath_atx_ac ac[WME_NUM_AC];
13         u16 maxampdu;
14         u8 mpdudensity;
15 +
16 +       bool sleeping;
17  };
18  
19  #define AGGR_CLEANUP         BIT(1)
20 @@ -341,6 +344,9 @@ int ath_tx_aggr_start(struct ath_softc *
21  void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
22  void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
23  
24 +void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
25 +bool ath_tx_aggr_sleep(struct ath_softc *sc, struct ath_node *an);
26 +
27  /********/
28  /* VIFs */
29  /********/
30 --- a/drivers/net/wireless/ath/ath9k/main.c
31 +++ b/drivers/net/wireless/ath/ath9k/main.c
32 @@ -1791,6 +1791,27 @@ static int ath9k_sta_remove(struct ieee8
33         return 0;
34  }
35  
36 +static void ath9k_sta_notify(struct ieee80211_hw *hw,
37 +                        struct ieee80211_vif *vif,
38 +                        enum sta_notify_cmd cmd,
39 +                        struct ieee80211_sta *sta)
40 +{
41 +       struct ath_softc *sc = hw->priv;
42 +       struct ath_node *an = (struct ath_node *) sta->drv_priv;
43 +
44 +       switch (cmd) {
45 +       case STA_NOTIFY_SLEEP:
46 +               an->sleeping = true;
47 +               if (ath_tx_aggr_sleep(sc, an))
48 +                       ieee80211_sta_set_tim(sta);
49 +               break;
50 +       case STA_NOTIFY_AWAKE:
51 +               an->sleeping = false;
52 +               ath_tx_aggr_wakeup(sc, an);
53 +               break;
54 +       }
55 +}
56 +
57  static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
58                          const struct ieee80211_tx_queue_params *params)
59  {
60 @@ -2191,6 +2212,7 @@ struct ieee80211_ops ath9k_ops = {
61         .configure_filter   = ath9k_configure_filter,
62         .sta_add            = ath9k_sta_add,
63         .sta_remove         = ath9k_sta_remove,
64 +       .sta_notify         = ath9k_sta_notify,
65         .conf_tx            = ath9k_conf_tx,
66         .bss_info_changed   = ath9k_bss_info_changed,
67         .set_key            = ath9k_set_key,
68 --- a/drivers/net/wireless/ath/ath9k/xmit.c
69 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
70 @@ -357,6 +357,7 @@ static void ath_tx_complete_aggr(struct 
71         struct ath_frame_info *fi;
72         int nframes;
73         u8 tidno;
74 +       bool clear_filter;
75  
76         skb = bf->bf_mpdu;
77         hdr = (struct ieee80211_hdr *)skb->data;
78 @@ -442,7 +443,11 @@ static void ath_tx_complete_aggr(struct 
79                         acked_cnt++;
80                 } else {
81                         if (!(tid->state & AGGR_CLEANUP) && retry) {
82 -                               if (fi->retries < ATH_MAX_SW_RETRIES) {
83 +                               if (ts->ts_status & ATH9K_TXERR_FILT) {
84 +                                       if (!an->sleeping)
85 +                                               clear_filter = true;
86 +                                       txpending = 1;
87 +                               } else if (fi->retries < ATH_MAX_SW_RETRIES) {
88                                         ath_tx_set_retry(sc, txq, bf->bf_mpdu);
89                                         txpending = 1;
90                                 } else {
91 @@ -496,6 +501,7 @@ static void ath_tx_complete_aggr(struct 
92                                 !txfail, sendbar);
93                 } else {
94                         /* retry the un-acked ones */
95 +                       ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, false);
96                         if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)) {
97                                 if (bf->bf_next == NULL && bf_last->bf_stale) {
98                                         struct ath_buf *tbf;
99 @@ -546,7 +552,12 @@ static void ath_tx_complete_aggr(struct 
100  
101         /* prepend un-acked frames to the beginning of the pending frame queue */
102         if (!list_empty(&bf_pending)) {
103 +               if (an->sleeping)
104 +                       ieee80211_sta_set_tim(sta);
105 +
106                 spin_lock_bh(&txq->axq_lock);
107 +               if (clear_filter)
108 +                       tid->ac->clear_ps_filter = true;
109                 list_splice(&bf_pending, &tid->buf_q);
110                 ath_tx_queue_tid(txq, tid);
111                 spin_unlock_bh(&txq->axq_lock);
112 @@ -816,6 +827,11 @@ static void ath_tx_sched_aggr(struct ath
113                 bf = list_first_entry(&bf_q, struct ath_buf, list);
114                 bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
115  
116 +               if (tid->ac->clear_ps_filter) {
117 +                       tid->ac->clear_ps_filter = false;
118 +                       ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true);
119 +               }
120 +
121                 /* if only one frame, send as non-aggregate */
122                 if (bf == bf->bf_lastbf) {
123                         fi = get_frame_info(bf->bf_mpdu);
124 @@ -896,6 +912,67 @@ void ath_tx_aggr_stop(struct ath_softc *
125         ath_tx_flush_tid(sc, txtid);
126  }
127  
128 +bool ath_tx_aggr_sleep(struct ath_softc *sc, struct ath_node *an)
129 +{
130 +       struct ath_atx_tid *tid;
131 +       struct ath_atx_ac *ac;
132 +       struct ath_txq *txq;
133 +       bool buffered = false;
134 +       int tidno;
135 +
136 +       for (tidno = 0, tid = &an->tid[tidno];
137 +            tidno < WME_NUM_TID; tidno++, tid++) {
138 +
139 +               if (!tid->sched)
140 +                       continue;
141 +
142 +               ac = tid->ac;
143 +               txq = ac->txq;
144 +
145 +               spin_lock_bh(&txq->axq_lock);
146 +
147 +               if (!list_empty(&tid->buf_q))
148 +                       buffered = true;
149 +
150 +               tid->sched = false;
151 +               list_del(&tid->list);
152 +
153 +               if (ac->sched) {
154 +                       ac->sched = false;
155 +                       list_del(&ac->list);
156 +               }
157 +
158 +               spin_unlock_bh(&txq->axq_lock);
159 +       }
160 +
161 +       return buffered;
162 +}
163 +
164 +void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an)
165 +{
166 +       struct ath_atx_tid *tid;
167 +       struct ath_atx_ac *ac;
168 +       struct ath_txq *txq;
169 +       int tidno;
170 +
171 +       for (tidno = 0, tid = &an->tid[tidno];
172 +            tidno < WME_NUM_TID; tidno++, tid++) {
173 +
174 +               ac = tid->ac;
175 +               txq = ac->txq;
176 +
177 +               spin_lock_bh(&txq->axq_lock);
178 +               ac->clear_ps_filter = true;
179 +
180 +               if (!list_empty(&tid->buf_q) && !tid->paused) {
181 +                       ath_tx_queue_tid(txq, tid);
182 +                       ath_txq_schedule(sc, txq);
183 +               }
184 +
185 +               spin_unlock_bh(&txq->axq_lock);
186 +       }
187 +}
188 +
189  void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
190  {
191         struct ath_atx_tid *txtid;
192 @@ -1493,7 +1570,6 @@ static int setup_tx_flags(struct sk_buff
193         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
194         int flags = 0;
195  
196 -       flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
197         flags |= ATH9K_TXDESC_INTREQ;
198  
199         if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
200 @@ -1756,6 +1832,9 @@ static void ath_tx_start_dma(struct ath_
201                 if (txctl->paprd)
202                         bf->bf_state.bfs_paprd_timestamp = jiffies;
203  
204 +               if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
205 +                       ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true);
206 +
207                 ath_tx_send_normal(sc, txctl->txq, tid, &bf_head);
208         }
209  
210 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
211 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
212 @@ -128,6 +128,11 @@ static inline void ath9k_hw_set11n_virtu
213         ath9k_hw_ops(ah)->set11n_virtualmorefrag(ah, ds, vmf);
214  }
215  
216 +static inline void ath9k_hw_set_clrdmask(struct ath_hw *ah, void *ds, bool val)
217 +{
218 +       ath9k_hw_ops(ah)->set_clrdmask(ah, ds, val);
219 +}
220 +
221  /* Private hardware call ops */
222  
223  /* PHY ops */
224 --- a/drivers/net/wireless/ath/ath9k/hw.h
225 +++ b/drivers/net/wireless/ath/ath9k/hw.h
226 @@ -642,6 +642,7 @@ struct ath_hw_ops {
227                                      u32 burstDuration);
228         void (*set11n_virtualmorefrag)(struct ath_hw *ah, void *ds,
229                                        u32 vmf);
230 +       void (*set_clrdmask)(struct ath_hw *ah, void *ds, bool val);
231  };
232  
233  struct ath_nf_limits {
234 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
235 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
236 @@ -290,7 +290,6 @@ static void ar9002_hw_set11n_txdesc(stru
237                 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
238                 | SM(txPower, AR_XmitPower)
239                 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
240 -               | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
241                 | (flags & ATH9K_TXDESC_INTREQ ? AR_TxIntrReq : 0)
242                 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0);
243  
244 @@ -311,6 +310,16 @@ static void ar9002_hw_set11n_txdesc(stru
245         }
246  }
247  
248 +static void ar9002_hw_set_clrdmask(struct ath_hw *ah, void *ds, bool val)
249 +{
250 +       struct ar5416_desc *ads = AR5416DESC(ds);
251 +
252 +       if (val)
253 +               ads->ds_ctl0 |= AR_ClrDestMask;
254 +       else
255 +               ads->ds_ctl0 &= ~AR_ClrDestMask;
256 +}
257 +
258  static void ar9002_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
259                                           void *lastds,
260                                           u32 durUpdateEn, u32 rtsctsRate,
261 @@ -460,4 +469,5 @@ void ar9002_hw_attach_mac_ops(struct ath
262         ops->clr11n_aggr = ar9002_hw_clr11n_aggr;
263         ops->set11n_burstduration = ar9002_hw_set11n_burstduration;
264         ops->set11n_virtualmorefrag = ar9002_hw_set11n_virtualmorefrag;
265 +       ops->set_clrdmask = ar9002_hw_set_clrdmask;
266  }
267 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
268 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
269 @@ -329,7 +329,6 @@ static void ar9003_hw_set11n_txdesc(stru
270                 | (flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
271                 | SM(txpower, AR_XmitPower)
272                 | (flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
273 -               | (flags & ATH9K_TXDESC_CLRDMASK ? AR_ClrDestMask : 0)
274                 | (keyIx != ATH9K_TXKEYIX_INVALID ? AR_DestIdxValid : 0)
275                 | (flags & ATH9K_TXDESC_LOWRXCHAIN ? AR_LowRxChain : 0);
276  
277 @@ -350,6 +349,16 @@ static void ar9003_hw_set11n_txdesc(stru
278         ads->ctl22 = 0;
279  }
280  
281 +static void ar9003_hw_set_clrdmask(struct ath_hw *ah, void *ds, bool val)
282 +{
283 +       struct ar9003_txc *ads = (struct ar9003_txc *) ds;
284 +
285 +       if (val)
286 +               ads->ctl11 |= AR_ClrDestMask;
287 +       else
288 +               ads->ctl11 &= ~AR_ClrDestMask;
289 +}
290 +
291  static void ar9003_hw_set11n_ratescenario(struct ath_hw *ah, void *ds,
292                                           void *lastds,
293                                           u32 durUpdateEn, u32 rtsctsRate,
294 @@ -522,6 +531,7 @@ void ar9003_hw_attach_mac_ops(struct ath
295         ops->clr11n_aggr = ar9003_hw_clr11n_aggr;
296         ops->set11n_burstduration = ar9003_hw_set11n_burstduration;
297         ops->set11n_virtualmorefrag = ar9003_hw_set11n_virtualmorefrag;
298 +       ops->set_clrdmask = ar9003_hw_set_clrdmask;
299  }
300  
301  void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
302 --- a/drivers/net/wireless/ath/ath9k/mac.h
303 +++ b/drivers/net/wireless/ath/ath9k/mac.h
304 @@ -239,7 +239,6 @@ struct ath_desc {
305         void *ds_vdata;
306  } __packed __aligned(4);
307  
308 -#define ATH9K_TXDESC_CLRDMASK          0x0001
309  #define ATH9K_TXDESC_NOACK             0x0002
310  #define ATH9K_TXDESC_RTSENA            0x0004
311  #define ATH9K_TXDESC_CTSENA            0x0008