carl9170: fix CONFIG_CARL9170FW_DEBUG && !CONFIG_CARL9170FW_RADIO_FUNC
[carl9170fw.git] / carlfw / src / wlantx.c
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * WLAN transmit and tx status
5  *
6  * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7  * Copyright (c) 2007-2009 Atheros Communications, Inc.
8  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
9  * Copyright 2009-2012  Christian Lamparter <chunkeey@googlemail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include "carl9170.h"
27 #include "shared/phy.h"
28 #include "hostif.h"
29 #include "timer.h"
30 #include "wl.h"
31 #include "printf.h"
32 #include "rf.h"
33 #include "linux/ieee80211.h"
34 #include "wol.h"
35
36 static void wlan_txunstuck(unsigned int queue)
37 {
38         set_wlan_txq_dma_addr(queue, ((uint32_t) fw.wlan.tx_queue[queue].head) | 1);
39 }
40
41 #ifdef CONFIG_CARL9170FW_DMA_QUEUE_BUMP
42 static void wlan_txupdate(unsigned int queue)
43 {
44         set_wlan_txq_dma_addr(queue, ((uint32_t) fw.wlan.tx_queue[queue].head));
45 }
46
47 void wlan_dma_bump(unsigned int qidx)
48 {
49         unsigned int offset = qidx;
50         uint32_t status, trigger;
51
52         status = get(AR9170_MAC_REG_DMA_STATUS) >> 12;
53         trigger = get(AR9170_MAC_REG_DMA_TRIGGER) >> 12;
54
55         while (offset != 0) {
56                 status >>= 4;
57                 trigger >>= 4;
58                 offset--;
59         }
60
61         status &= 0xf;
62         trigger &= 0xf;
63
64         if ((trigger == 0xa) && (status == 0x8)) {
65                 DBG("UNSTUCK");
66                 wlan_txunstuck(qidx);
67         } else {
68                 DBG("UPDATE");
69                 wlan_txupdate(qidx);
70         }
71 }
72 #else
73 void wlan_dma_bump(unsigned int __unused qidx)
74 {
75 }
76 #endif /* CONFIG_CARL9170FW_DMA_QUEUE_BUMP */
77
78 void wlan_send_buffered_tx_status(void)
79 {
80         unsigned int len;
81
82         while (fw.wlan.tx_status_pending) {
83                 len = min((unsigned int)fw.wlan.tx_status_pending,
84                           CARL9170_RSP_TX_STATUS_NUM);
85                 len = min(len, CARL9170_TX_STATUS_NUM - fw.wlan.tx_status_head_idx);
86
87                 /*
88                  * rather than memcpy each individual request into a large buffer,
89                  * we _splice_ them all together.
90                  *
91                  * The only downside is however that we have to be careful around
92                  * the edges of the tx_status_cache.
93                  *
94                  * Note:
95                  * Each tx_status is about 2 bytes. However every command package
96                  * must have a size which is a multiple of 4.
97                  */
98
99                 send_cmd_to_host((len * sizeof(struct carl9170_tx_status) + 3) & ~3,
100                                  CARL9170_RSP_TXCOMP, len, (void *)
101                                  &fw.wlan.tx_status_cache[fw.wlan.tx_status_head_idx]);
102
103                 fw.wlan.tx_status_pending -= len;
104                 fw.wlan.tx_status_head_idx += len;
105                 fw.wlan.tx_status_head_idx %= CARL9170_TX_STATUS_NUM;
106         }
107 }
108
109 static struct carl9170_tx_status *wlan_get_tx_status_buffer(void)
110 {
111         struct carl9170_tx_status *tmp;
112
113         tmp = &fw.wlan.tx_status_cache[fw.wlan.tx_status_tail_idx++];
114         fw.wlan.tx_status_tail_idx %= CARL9170_TX_STATUS_NUM;
115
116         if (fw.wlan.tx_status_pending == CARL9170_TX_STATUS_NUM)
117                 wlan_send_buffered_tx_status();
118
119         fw.wlan.tx_status_pending++;
120
121         return tmp;
122 }
123
124 /* generate _aggregated_ tx_status for the host */
125 void wlan_tx_complete(struct carl9170_tx_superframe *super,
126                       bool txs)
127 {
128         struct carl9170_tx_status *status;
129
130         status = wlan_get_tx_status_buffer();
131
132         /*
133          * The *unique* cookie and AC_ID is used by the driver for
134          * frame lookup.
135          */
136         status->cookie = super->s.cookie;
137         status->queue = super->s.queue;
138         super->s.cookie = 0;
139
140         /*
141          * This field holds the number of tries of the rate in
142          * the rate index field (rix).
143          */
144         status->rix = super->s.rix;
145         status->tries = super->s.cnt;
146         status->success = (txs) ? 1 : 0;
147 }
148
149 static bool wlan_tx_consume_retry(struct carl9170_tx_superframe *super)
150 {
151         /* check if this was the last possible retry with this rate */
152         if (unlikely(super->s.cnt >= super->s.ri[super->s.rix].tries)) {
153                 /* end of the road - indicate tx failure */
154                 if (unlikely(super->s.rix == CARL9170_TX_MAX_RETRY_RATES))
155                         return false;
156
157                 /* check if there are alternative rates available */
158                 if (!super->s.rr[super->s.rix].set)
159                         return false;
160
161                 /* try next retry rate */
162                 super->f.hdr.phy.set = super->s.rr[super->s.rix].set;
163
164                 /* finally - mark the old rate as USED */
165                 super->s.rix++;
166
167                 /* update MAC flags */
168                 super->f.hdr.mac.erp_prot = super->s.ri[super->s.rix].erp_prot;
169                 super->f.hdr.mac.ampdu = super->s.ri[super->s.rix].ampdu;
170
171                 /* reinitialize try counter */
172                 super->s.cnt = 1;
173         } else {
174                 /* just increase retry counter */
175                 super->s.cnt++;
176         }
177
178         return true;
179 }
180
181 static inline u16 get_tid(struct ieee80211_hdr *hdr)
182 {
183         return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
184 }
185
186 /* This function will only work on uint32_t-aligned pointers! */
187 static bool same_hdr(const void *_d0, const void *_d1)
188 {
189         const uint32_t *d0 = _d0;
190         const uint32_t *d1 = _d1;
191
192         /* BUG_ON((unsigned long)d0 & 3 || (unsigned long)d1 & 3)) */
193         return !((d0[0] ^ d1[0]) |                      /* FC + DU */
194                  (d0[1] ^ d1[1]) |                      /* addr1 */
195                  (d0[2] ^ d1[2]) | (d0[3] ^ d1[3]) |    /* addr2 + addr3 */
196                  (d0[4] ^ d1[4]));                      /* addr3 */
197 }
198
199 static inline bool same_aggr(struct ieee80211_hdr *a, struct ieee80211_hdr *b)
200 {
201         return (get_tid(a) == get_tid(b)) || same_hdr(a, b);
202 }
203
204 static void wlan_tx_ampdu_reset(unsigned int qidx)
205 {
206         fw.wlan.ampdu_prev[qidx] = NULL;
207 }
208
209 static void wlan_tx_ampdu_end(unsigned int qidx)
210 {
211         struct carl9170_tx_superframe *ht_prev = fw.wlan.ampdu_prev[qidx];
212
213         if (ht_prev)
214                 ht_prev->f.hdr.mac.ba_end = 1;
215
216         wlan_tx_ampdu_reset(qidx);
217 }
218
219 static void wlan_tx_ampdu(struct carl9170_tx_superframe *super)
220 {
221         unsigned int qidx = super->s.queue;
222         struct carl9170_tx_superframe *ht_prev = fw.wlan.ampdu_prev[qidx];
223
224         if (super->f.hdr.mac.ampdu) {
225                 if (ht_prev &&
226                     !same_aggr(&super->f.data.i3e, &ht_prev->f.data.i3e))
227                         ht_prev->f.hdr.mac.ba_end = 1;
228                 else
229                         super->f.hdr.mac.ba_end = 0;
230
231                 fw.wlan.ampdu_prev[qidx] = super;
232         } else {
233                 wlan_tx_ampdu_end(qidx);
234         }
235 }
236
237 /* for all tries */
238 static void __wlan_tx(struct dma_desc *desc)
239 {
240         struct carl9170_tx_superframe *super = get_super(desc);
241
242         if (unlikely(super->s.fill_in_tsf)) {
243                 struct ieee80211_mgmt *mgmt = (void *) &super->f.data.i3e;
244                 uint32_t *tsf = (uint32_t *) &mgmt->u.probe_resp.timestamp;
245
246                 /*
247                  * Truth be told: this is a hack.
248                  *
249                  * The *real* TSF is definitely going to be higher/older.
250                  * But this hardware emulation code is head and shoulders
251                  * above anything a driver can possibly do.
252                  *
253                  * (even, if it's got an accurate atomic clock source).
254                  */
255
256                 read_tsf(tsf);
257         }
258
259         wlan_tx_ampdu(super);
260
261 #if (defined CONFIG_CARL9170FW_DEBUG) && (defined CONFIG_CARL9170FW_RADIO_FUNCTIONS)
262         BUG_ON(fw.phy.psm.state != CARL9170_PSM_WAKE);
263 #endif /* CONFIG_CARL9170FW_DEBUG && CONFIG_CARL9170FW_RADIO_FUNCTIONS */
264
265         /* insert desc into the right queue */
266         dma_put(&fw.wlan.tx_queue[super->s.queue], desc);
267 }
268
269 static void wlan_assign_seq(struct ieee80211_hdr *hdr, unsigned int vif)
270 {
271         hdr->seq_ctrl &= cpu_to_le16(~IEEE80211_SCTL_SEQ);
272         hdr->seq_ctrl |= cpu_to_le16(fw.wlan.sequence[vif]);
273
274         if (ieee80211_is_first_frag(hdr->seq_ctrl))
275                 fw.wlan.sequence[vif] += 0x10;
276 }
277
278 /* prepares frame for the first transmission */
279 static void _wlan_tx(struct dma_desc *desc)
280 {
281         struct carl9170_tx_superframe *super = get_super(desc);
282
283         if (unlikely(super->s.assign_seq))
284                 wlan_assign_seq(&super->f.data.i3e, super->s.vif_id);
285
286         if (unlikely(super->s.ampdu_commit_density)) {
287                 set(AR9170_MAC_REG_AMPDU_DENSITY,
288                     MOD_VAL(AR9170_MAC_AMPDU_DENSITY,
289                             get(AR9170_MAC_REG_AMPDU_DENSITY),
290                             super->s.ampdu_density));
291         }
292
293         if (unlikely(super->s.ampdu_commit_factor)) {
294                 set(AR9170_MAC_REG_AMPDU_FACTOR,
295                     MOD_VAL(AR9170_MAC_AMPDU_FACTOR,
296                             get(AR9170_MAC_REG_AMPDU_FACTOR),
297                             8 << super->s.ampdu_factor));
298         }
299 }
300
301 /* propagate transmission status back to the driver */
302 static bool wlan_tx_status(struct dma_queue *queue,
303                            struct dma_desc *desc)
304 {
305         struct carl9170_tx_superframe *super = get_super(desc);
306         unsigned int qidx = super->s.queue;
307         bool txfail = false, success;
308
309         success = true;
310
311         /* update hangcheck */
312         fw.wlan.last_super_num[qidx] = 0;
313
314         /*
315          * Note:
316          * There could be a corner case when the TXFAIL is set
317          * even though the frame was properly ACKed by the peer:
318          *   a BlockAckReq with the immediate policy will cause
319          *   the receiving peer to produce a BlockACK unfortunately
320          *   the MAC in this chip seems to be expecting a legacy
321          *   ACK and marks the BAR as failed!
322          */
323
324         if (!!(desc->ctrl & AR9170_CTRL_FAIL)) {
325                 txfail = !!(desc->ctrl & AR9170_CTRL_TXFAIL);
326
327                 /* reset retry indicator flags */
328                 desc->ctrl &= ~(AR9170_CTRL_TXFAIL | AR9170_CTRL_BAFAIL);
329
330                 /*
331                  * Note: wlan_tx_consume_retry will override the old
332                  * phy [CCK,OFDM, HT, BW20/40, MCS...] and mac vectors
333                  * [AMPDU,RTS/CTS,...] therefore be careful when they
334                  * are used.
335                  */
336                 if (wlan_tx_consume_retry(super)) {
337                         /*
338                          * retry for simple and aggregated 802.11 frames.
339                          *
340                          * Note: We must not mess up the original frame
341                          * order.
342                          */
343
344                         if (!super->f.hdr.mac.ampdu) {
345                                 /*
346                                  * 802.11 - 7.1.3.1.5.
347                                  * set "Retry Field" for consecutive attempts
348                                  *
349                                  * Note: For AMPDU see:
350                                  * 802.11n 9.9.1.6 "Retransmit Procedures"
351                                  */
352                                 super->f.data.i3e.frame_control |=
353                                         cpu_to_le16(IEEE80211_FCTL_RETRY);
354                         }
355
356                         if (txfail) {
357                                 /* Normal TX Failure */
358
359                                 /* demise descriptor ownership back to the hardware */
360                                 dma_rearm(desc);
361
362                                 /*
363                                  * And this will get the queue going again.
364                                  * To understand why: you have to get the HW
365                                  * specs... But sadly I never saw them.
366                                  */
367                                 wlan_txunstuck(qidx);
368
369                                 /* abort cycle - this is necessary due to HW design */
370                                 return false;
371                         } else {
372                                 /* (HT-) BlockACK failure */
373
374                                 /*
375                                  * Unlink the failed attempt and put it into
376                                  * the retry queue. The caller routine must
377                                  * be aware of this so the frames don't get lost.
378                                  */
379
380 #ifndef CONFIG_CARL9170FW_DEBUG
381                                 dma_unlink_head(queue);
382 #else /* CONFIG_CARL9170FW_DEBUG */
383                                 BUG_ON(dma_unlink_head(queue) != desc);
384 #endif /* CONFIG_CARL9170FW_DEBUG */
385                                 dma_put(&fw.wlan.tx_retry, desc);
386                                 return true;
387                         }
388                 } else {
389                         /* out of frame attempts - discard frame */
390                         success = false;
391                 }
392         }
393
394 #ifndef CONFIG_CARL9170FW_DEBUG
395         dma_unlink_head(queue);
396 #else /* CONFIG_CARL9170FW_DEBUG */
397         BUG_ON(dma_unlink_head(queue) != desc);
398 #endif /* CONFIG_CARL9170FW_DEBUG */
399         if (txfail) {
400                 /*
401                  * Issue the queue bump,
402                  * We need to do this in case this was the frame's last
403                  * possible retry attempt and it unfortunately: it failed.
404                  */
405
406                 wlan_txunstuck(qidx);
407         }
408
409         unhide_super(desc);
410
411         if (unlikely(super == fw.wlan.fw_desc_data)) {
412                 fw.wlan.fw_desc = desc;
413                 fw.wlan.fw_desc_available = 1;
414
415                 if (fw.wlan.fw_desc_callback)
416                         fw.wlan.fw_desc_callback(super, success);
417
418                 return true;
419         }
420
421         if (unlikely(super->s.cab))
422                 fw.wlan.cab_queue_len[super->s.vif_id]--;
423
424         wlan_tx_complete(super, success);
425
426         if (ieee80211_is_back_req(super->f.data.i3e.frame_control)) {
427                 fw.wlan.queued_bar--;
428         }
429
430         /* recycle freed descriptors */
431         dma_reclaim(&fw.pta.down_queue, desc);
432         down_trigger();
433         return true;
434 }
435
436 void handle_wlan_tx_completion(void)
437 {
438         struct dma_desc *desc;
439         int i;
440
441         for (i = AR9170_TXQ_SPECIAL; i >= AR9170_TXQ0; i--) {
442                 __while_desc_bits(desc, &fw.wlan.tx_queue[i], AR9170_OWN_BITS_SW) {
443                         if (!wlan_tx_status(&fw.wlan.tx_queue[i], desc)) {
444                                 /* termination requested. */
445                                 break;
446                         }
447                 }
448
449                 wlan_tx_ampdu_reset(i);
450
451                 for_each_desc(desc, &fw.wlan.tx_retry)
452                         __wlan_tx(desc);
453
454                 wlan_tx_ampdu_end(i);
455                 if (!queue_empty(&fw.wlan.tx_queue[i]))
456                         wlan_trigger(BIT(i));
457         }
458 }
459
460 void __hot wlan_tx(struct dma_desc *desc)
461 {
462         struct carl9170_tx_superframe *super = DESC_PAYLOAD(desc);
463
464         if (ieee80211_is_back_req(super->f.data.i3e.frame_control)) {
465                 fw.wlan.queued_bar++;
466         }
467
468         /* initialize rate control struct */
469         super->s.rix = 0;
470         super->s.cnt = 1;
471         hide_super(desc);
472
473         if (unlikely(super->s.cab)) {
474                 fw.wlan.cab_queue_len[super->s.vif_id]++;
475                 dma_put(&fw.wlan.cab_queue[super->s.vif_id], desc);
476                 return;
477         }
478
479         _wlan_tx(desc);
480         __wlan_tx(desc);
481         wlan_trigger(BIT(super->s.queue));
482 }
483
484 void wlan_tx_fw(struct carl9170_tx_superdesc *super, fw_desc_callback_t cb)
485 {
486         if (!fw.wlan.fw_desc_available)
487                 return;
488
489         fw.wlan.fw_desc_available = 0;
490
491         /* Format BlockAck */
492         fw.wlan.fw_desc->ctrl = AR9170_CTRL_FS_BIT | AR9170_CTRL_LS_BIT;
493         fw.wlan.fw_desc->status = AR9170_OWN_BITS_SW;
494
495         fw.wlan.fw_desc->totalLen = fw.wlan.fw_desc->dataSize = super->len;
496         fw.wlan.fw_desc_data = fw.wlan.fw_desc->dataAddr = super;
497         fw.wlan.fw_desc->nextAddr = fw.wlan.fw_desc->lastAddr =
498                 fw.wlan.fw_desc;
499         fw.wlan.fw_desc_callback = cb;
500         wlan_tx(fw.wlan.fw_desc);
501 }
502
503 void wlan_send_buffered_ba(void)
504 {
505         struct carl9170_tx_ba_superframe *baf = &dma_mem.reserved.ba.ba;
506         struct ieee80211_ba *ba = (struct ieee80211_ba *) &baf->f.ba;
507         struct carl9170_bar_ctx *ctx;
508
509         if (likely(!fw.wlan.queued_ba))
510                 return;
511
512         /* there's no point to continue when the ba_desc is not available. */
513         if (!fw.wlan.fw_desc_available)
514                 return;
515
516         ctx = &fw.wlan.ba_cache[fw.wlan.ba_head_idx];
517         fw.wlan.ba_head_idx++;
518         fw.wlan.ba_head_idx %= CONFIG_CARL9170FW_BACK_REQS_NUM;
519         fw.wlan.queued_ba--;
520
521         baf->s.len = sizeof(struct carl9170_tx_superdesc) +
522                      sizeof(struct ar9170_tx_hwdesc) +
523                      sizeof(struct ieee80211_ba);
524         baf->s.ri[0].tries = 1;
525         baf->s.cookie = 0;
526         baf->s.queue = AR9170_TXQ_VO;
527         baf->f.hdr.length = sizeof(struct ieee80211_ba) + FCS_LEN;
528
529         baf->f.hdr.mac.no_ack = 1;
530
531         baf->f.hdr.phy.modulation = 1; /* OFDM */
532         baf->f.hdr.phy.tx_power = 34; /* 17 dBm */
533         baf->f.hdr.phy.chains = 1;
534         baf->f.hdr.phy.mcs = AR9170_TXRX_PHY_RATE_OFDM_6M;
535
536         /* format outgoing BA */
537         ba->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
538         ba->duration = cpu_to_le16(0);
539
540         /* the BAR contains all necessary MACs. All we need is to swap them */
541         memcpy(ba->ra, ctx->ta, 6);
542         memcpy(ba->ta, ctx->ra, 6);
543
544         /*
545          * Unfortunately, we cannot look into the hardware's scoreboard.
546          * Therefore we have to proceed as described in 802.11n 9.10.7.5
547          * and send a null BlockAck.
548          */
549         memset(ba->bitmap, 0x0, sizeof(ba->bitmap));
550
551         /*
552          * Both, the original firmare and ath9k set the NO ACK flag in
553          * the BA Ack Policy subfield.
554          */
555         ba->control = ctx->control | cpu_to_le16(1);
556         ba->start_seq_num = ctx->start_seq_num;
557         wlan_tx_fw(&baf->s, NULL);
558 }
559
560 void wlan_cab_flush_queue(const unsigned int vif)
561 {
562         struct dma_queue *cab_queue = &fw.wlan.cab_queue[vif];
563         struct dma_desc *desc;
564
565         /* move queued frames into the main tx queues */
566         for_each_desc(desc, cab_queue) {
567                 struct carl9170_tx_superframe *super = get_super(desc);
568                 if (!queue_empty(cab_queue)) {
569                         /*
570                          * Set MOREDATA flag for all,
571                          * but the last queued frame.
572                          * see: 802.11-2007 11.2.1.5 f)
573                          *
574                          * This is actually the reason to why
575                          * we need to prevent the reentry.
576                          */
577
578                         super->f.data.i3e.frame_control |=
579                                 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
580                 } else {
581                         super->f.data.i3e.frame_control &=
582                                 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
583                 }
584
585                 /* ready to roll! */
586                 _wlan_tx(desc);
587                 __wlan_tx(desc);
588                 wlan_trigger(BIT(super->s.queue));
589         }
590 }
591
592 static uint8_t *beacon_find_ie(uint8_t ie, void *addr,
593                                const unsigned int len)
594 {
595         struct ieee80211_mgmt *mgmt = addr;
596         uint8_t *pos, *end;
597
598         pos = mgmt->u.beacon.variable;
599         end = (uint8_t *) ((unsigned long)mgmt + (len - FCS_LEN));
600         while (pos < end) {
601                 if (pos + 2 + pos[1] > end)
602                         return NULL;
603
604                 if (pos[0] == ie)
605                         return pos;
606
607                 pos += pos[1] + 2;
608         }
609
610         return NULL;
611 }
612
613 void wlan_modify_beacon(const unsigned int vif,
614         const unsigned int addr, const unsigned int len)
615 {
616         uint8_t *_ie;
617         struct ieee80211_tim_ie *ie;
618
619         _ie = beacon_find_ie(WLAN_EID_TIM, (void *)addr, len);
620         if (likely(_ie)) {
621                 ie = (struct ieee80211_tim_ie *) &_ie[2];
622
623                 if (!queue_empty(&fw.wlan.cab_queue[vif]) && (ie->dtim_count == 0)) {
624                         /* schedule DTIM transfer */
625                         fw.wlan.cab_flush_trigger[vif] = CARL9170_CAB_TRIGGER_ARMED;
626                 } else if ((fw.wlan.cab_queue_len[vif] == 0) && (fw.wlan.cab_flush_trigger[vif])) {
627                         /* undo all chances to the beacon structure */
628                         ie->bitmap_ctrl &= ~0x1;
629                         fw.wlan.cab_flush_trigger[vif] = CARL9170_CAB_TRIGGER_EMPTY;
630                 }
631
632                 /* Triggered by CARL9170_CAB_TRIGGER_ARMED || CARL9170_CAB_TRIGGER_DEFER */
633                 if (fw.wlan.cab_flush_trigger[vif]) {
634                         /* Set the almighty Multicast Traffic Indication Bit. */
635                         ie->bitmap_ctrl |= 0x1;
636                 }
637         }
638
639         /*
640          * Ideally, the sequence number should be assigned by the TX arbiter
641          * hardware. But AFAIK that's not possible, so we have to go for the
642          * next best thing and write it into the beacon fifo during the open
643          * beacon update window.
644          */
645
646         wlan_assign_seq((struct ieee80211_hdr *)addr, vif);
647 }
648
649 void wlan_send_buffered_cab(void)
650 {
651         unsigned int i;
652
653         for (i = 0; i < CARL9170_INTF_NUM; i++) {
654                 if (unlikely(fw.wlan.cab_flush_trigger[i] == CARL9170_CAB_TRIGGER_ARMED)) {
655                         /*
656                          * This is hardcoded into carl9170usb driver.
657                          *
658                          * The driver must set the PRETBTT event to beacon_interval -
659                          * CARL9170_PRETBTT_KUS (usually 6) Kus.
660                          *
661                          * But still, we can only do so much about 802.11-2007 9.3.2.1 &
662                          * 11.2.1.6. Let's hope the current solution is adequate enough.
663                          */
664
665                         if (is_after_msecs(fw.wlan.cab_flush_time, (CARL9170_TBTT_DELTA))) {
666                                 wlan_cab_flush_queue(i);
667
668                                 /*
669                                  * This prevents the code from sending new BC/MC frames
670                                  * which were queued after the previous buffered traffic
671                                  * has been sent out... They will have to wait until the
672                                  * next DTIM beacon comes along.
673                                  */
674                                 fw.wlan.cab_flush_trigger[i] = CARL9170_CAB_TRIGGER_DEFER;
675                         }
676                 }
677
678         }
679 }