Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / drivers / net / wireless / b43legacy / xmit.c
1 /*
2
3   Broadcom B43legacy wireless driver
4
5   Transmission (TX/RX) related functions.
6
7   Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
8   Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
9   Copyright (C) 2005, 2006 Michael Buesch <mb@bu3sch.de>
10   Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
11   Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
12   Copyright (C) 2007 Larry Finger <Larry.Finger@lwfinger.net>
13
14   This program is free software; you can redistribute it and/or modify
15   it under the terms of the GNU General Public License as published by
16   the Free Software Foundation; either version 2 of the License, or
17   (at your option) any later version.
18
19   This program is distributed in the hope that it will be useful,
20   but WITHOUT ANY WARRANTY; without even the implied warranty of
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   GNU General Public License for more details.
23
24   You should have received a copy of the GNU General Public License
25   along with this program; see the file COPYING.  If not, write to
26   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27   Boston, MA 02110-1301, USA.
28
29 */
30
31 #include <net/dst.h>
32
33 #include "xmit.h"
34 #include "phy.h"
35 #include "dma.h"
36 #include "pio.h"
37
38
39 /* Extract the bitrate out of a CCK PLCP header. */
40 static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp)
41 {
42         switch (plcp->raw[0]) {
43         case 0x0A:
44                 return 0;
45         case 0x14:
46                 return 1;
47         case 0x37:
48                 return 2;
49         case 0x6E:
50                 return 3;
51         }
52         B43legacy_BUG_ON(1);
53         return -1;
54 }
55
56 /* Extract the bitrate out of an OFDM PLCP header. */
57 static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp,
58                                               bool aphy)
59 {
60         int base = aphy ? 0 : 4;
61
62         switch (plcp->raw[0] & 0xF) {
63         case 0xB:
64                 return base + 0;
65         case 0xF:
66                 return base + 1;
67         case 0xA:
68                 return base + 2;
69         case 0xE:
70                 return base + 3;
71         case 0x9:
72                 return base + 4;
73         case 0xD:
74                 return base + 5;
75         case 0x8:
76                 return base + 6;
77         case 0xC:
78                 return base + 7;
79         }
80         B43legacy_BUG_ON(1);
81         return -1;
82 }
83
84 u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate)
85 {
86         switch (bitrate) {
87         case B43legacy_CCK_RATE_1MB:
88                 return 0x0A;
89         case B43legacy_CCK_RATE_2MB:
90                 return 0x14;
91         case B43legacy_CCK_RATE_5MB:
92                 return 0x37;
93         case B43legacy_CCK_RATE_11MB:
94                 return 0x6E;
95         }
96         B43legacy_BUG_ON(1);
97         return 0;
98 }
99
100 u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate)
101 {
102         switch (bitrate) {
103         case B43legacy_OFDM_RATE_6MB:
104                 return 0xB;
105         case B43legacy_OFDM_RATE_9MB:
106                 return 0xF;
107         case B43legacy_OFDM_RATE_12MB:
108                 return 0xA;
109         case B43legacy_OFDM_RATE_18MB:
110                 return 0xE;
111         case B43legacy_OFDM_RATE_24MB:
112                 return 0x9;
113         case B43legacy_OFDM_RATE_36MB:
114                 return 0xD;
115         case B43legacy_OFDM_RATE_48MB:
116                 return 0x8;
117         case B43legacy_OFDM_RATE_54MB:
118                 return 0xC;
119         }
120         B43legacy_BUG_ON(1);
121         return 0;
122 }
123
124 void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp,
125                                  const u16 octets, const u8 bitrate)
126 {
127         __le32 *data = &(plcp->data);
128         __u8 *raw = plcp->raw;
129
130         if (b43legacy_is_ofdm_rate(bitrate)) {
131                 u16 d;
132
133                 d = b43legacy_plcp_get_ratecode_ofdm(bitrate);
134                 B43legacy_WARN_ON(octets & 0xF000);
135                 d |= (octets << 5);
136                 *data = cpu_to_le32(d);
137         } else {
138                 u32 plen;
139
140                 plen = octets * 16 / bitrate;
141                 if ((octets * 16 % bitrate) > 0) {
142                         plen++;
143                         if ((bitrate == B43legacy_CCK_RATE_11MB)
144                             && ((octets * 8 % 11) < 4))
145                                 raw[1] = 0x84;
146                         else
147                                 raw[1] = 0x04;
148                 } else
149                         raw[1] = 0x04;
150                 *data |= cpu_to_le32(plen << 16);
151                 raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate);
152         }
153 }
154
155 static u8 b43legacy_calc_fallback_rate(u8 bitrate)
156 {
157         switch (bitrate) {
158         case B43legacy_CCK_RATE_1MB:
159                 return B43legacy_CCK_RATE_1MB;
160         case B43legacy_CCK_RATE_2MB:
161                 return B43legacy_CCK_RATE_1MB;
162         case B43legacy_CCK_RATE_5MB:
163                 return B43legacy_CCK_RATE_2MB;
164         case B43legacy_CCK_RATE_11MB:
165                 return B43legacy_CCK_RATE_5MB;
166         case B43legacy_OFDM_RATE_6MB:
167                 return B43legacy_CCK_RATE_5MB;
168         case B43legacy_OFDM_RATE_9MB:
169                 return B43legacy_OFDM_RATE_6MB;
170         case B43legacy_OFDM_RATE_12MB:
171                 return B43legacy_OFDM_RATE_9MB;
172         case B43legacy_OFDM_RATE_18MB:
173                 return B43legacy_OFDM_RATE_12MB;
174         case B43legacy_OFDM_RATE_24MB:
175                 return B43legacy_OFDM_RATE_18MB;
176         case B43legacy_OFDM_RATE_36MB:
177                 return B43legacy_OFDM_RATE_24MB;
178         case B43legacy_OFDM_RATE_48MB:
179                 return B43legacy_OFDM_RATE_36MB;
180         case B43legacy_OFDM_RATE_54MB:
181                 return B43legacy_OFDM_RATE_48MB;
182         }
183         B43legacy_BUG_ON(1);
184         return 0;
185 }
186
187 static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
188                                struct b43legacy_txhdr_fw3 *txhdr,
189                                const unsigned char *fragment_data,
190                                unsigned int fragment_len,
191                                const struct ieee80211_tx_info *info,
192                                u16 cookie)
193 {
194         const struct ieee80211_hdr *wlhdr;
195         int use_encryption = !!info->control.hw_key;
196         u8 rate;
197         struct ieee80211_rate *rate_fb;
198         int rate_ofdm;
199         int rate_fb_ofdm;
200         unsigned int plcp_fragment_len;
201         u32 mac_ctl = 0;
202         u16 phy_ctl = 0;
203         struct ieee80211_rate *tx_rate;
204
205         wlhdr = (const struct ieee80211_hdr *)fragment_data;
206
207         memset(txhdr, 0, sizeof(*txhdr));
208
209         tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info);
210
211         rate = tx_rate->hw_value;
212         rate_ofdm = b43legacy_is_ofdm_rate(rate);
213         rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : tx_rate;
214         rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
215
216         txhdr->mac_frame_ctl = wlhdr->frame_control;
217         memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
218
219         /* Calculate duration for fallback rate */
220         if ((rate_fb->hw_value == rate) ||
221             (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
222             (wlhdr->duration_id == cpu_to_le16(0))) {
223                 /* If the fallback rate equals the normal rate or the
224                  * dur_id field contains an AID, CFP magic or 0,
225                  * use the original dur_id field. */
226                 txhdr->dur_fb = wlhdr->duration_id;
227         } else {
228                 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
229                                                          info->control.vif,
230                                                          fragment_len,
231                                                          rate_fb);
232         }
233
234         plcp_fragment_len = fragment_len + FCS_LEN;
235         if (use_encryption) {
236                 u8 key_idx = info->control.hw_key->hw_key_idx;
237                 struct b43legacy_key *key;
238                 int wlhdr_len;
239                 size_t iv_len;
240
241                 B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
242                 key = &(dev->key[key_idx]);
243
244                 if (key->enabled) {
245                         /* Hardware appends ICV. */
246                         plcp_fragment_len += info->control.hw_key->icv_len;
247
248                         key_idx = b43legacy_kidx_to_fw(dev, key_idx);
249                         mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
250                                    B43legacy_TX4_MAC_KEYIDX;
251                         mac_ctl |= (key->algorithm <<
252                                    B43legacy_TX4_MAC_KEYALG_SHIFT) &
253                                    B43legacy_TX4_MAC_KEYALG;
254                         wlhdr_len = ieee80211_hdrlen(wlhdr->frame_control);
255                         iv_len = min((size_t)info->control.hw_key->iv_len,
256                                      ARRAY_SIZE(txhdr->iv));
257                         memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
258                 } else {
259                         /* This key is invalid. This might only happen
260                          * in a short timeframe after machine resume before
261                          * we were able to reconfigure keys.
262                          * Drop this packet completely. Do not transmit it
263                          * unencrypted to avoid leaking information. */
264                         return -ENOKEY;
265                 }
266         }
267         b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
268                                     (&txhdr->plcp), plcp_fragment_len,
269                                     rate);
270         b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
271                                     (&txhdr->plcp_fb), plcp_fragment_len,
272                                     rate_fb->hw_value);
273
274         /* PHY TX Control word */
275         if (rate_ofdm)
276                 phy_ctl |= B43legacy_TX4_PHY_OFDM;
277         if (dev->short_preamble)
278                 phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
279         switch (info->antenna_sel_tx) {
280         case 0:
281                 phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
282                 break;
283         case 1:
284                 phy_ctl |= B43legacy_TX4_PHY_ANT0;
285                 break;
286         case 2:
287                 phy_ctl |= B43legacy_TX4_PHY_ANT1;
288                 break;
289         default:
290                 B43legacy_BUG_ON(1);
291         }
292
293         /* MAC control */
294         if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
295                 mac_ctl |= B43legacy_TX4_MAC_ACK;
296         if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
297                 mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
298         if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
299                 mac_ctl |= B43legacy_TX4_MAC_STMSDU;
300         if (rate_fb_ofdm)
301                 mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
302         if (info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
303                 mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
304
305         /* Generate the RTS or CTS-to-self frame */
306         if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
307             (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
308                 unsigned int len;
309                 struct ieee80211_hdr *hdr;
310                 int rts_rate;
311                 int rts_rate_fb;
312                 int rts_rate_ofdm;
313                 int rts_rate_fb_ofdm;
314
315                 rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
316                 rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate);
317                 rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
318                 rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
319                 if (rts_rate_fb_ofdm)
320                         mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
321
322                 if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
323                         ieee80211_ctstoself_get(dev->wl->hw,
324                                                 info->control.vif,
325                                                 fragment_data,
326                                                 fragment_len, info,
327                                                 (struct ieee80211_cts *)
328                                                 (txhdr->rts_frame));
329                         mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
330                         len = sizeof(struct ieee80211_cts);
331                 } else {
332                         ieee80211_rts_get(dev->wl->hw,
333                                           info->control.vif,
334                                           fragment_data, fragment_len, info,
335                                           (struct ieee80211_rts *)
336                                           (txhdr->rts_frame));
337                         mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
338                         len = sizeof(struct ieee80211_rts);
339                 }
340                 len += FCS_LEN;
341                 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
342                                             (&txhdr->rts_plcp),
343                                             len, rts_rate);
344                 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
345                                             (&txhdr->rts_plcp_fb),
346                                             len, rts_rate_fb);
347                 hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
348                 txhdr->rts_dur_fb = hdr->duration_id;
349         }
350
351         /* Magic cookie */
352         txhdr->cookie = cpu_to_le16(cookie);
353
354         /* Apply the bitfields */
355         txhdr->mac_ctl = cpu_to_le32(mac_ctl);
356         txhdr->phy_ctl = cpu_to_le16(phy_ctl);
357
358         return 0;
359 }
360
361 int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
362                               u8 *txhdr,
363                               const unsigned char *fragment_data,
364                               unsigned int fragment_len,
365                               const struct ieee80211_tx_info *info,
366                               u16 cookie)
367 {
368         return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
369                            fragment_data, fragment_len,
370                            info, cookie);
371 }
372
373 static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
374                                      u8 in_rssi, int ofdm,
375                                      int adjust_2053, int adjust_2050)
376 {
377         struct b43legacy_phy *phy = &dev->phy;
378         s32 tmp;
379
380         switch (phy->radio_ver) {
381         case 0x2050:
382                 if (ofdm) {
383                         tmp = in_rssi;
384                         if (tmp > 127)
385                                 tmp -= 256;
386                         tmp *= 73;
387                         tmp /= 64;
388                         if (adjust_2050)
389                                 tmp += 25;
390                         else
391                                 tmp -= 3;
392                 } else {
393                         if (dev->dev->bus->sprom.boardflags_lo
394                             & B43legacy_BFL_RSSI) {
395                                 if (in_rssi > 63)
396                                         in_rssi = 63;
397                                 tmp = phy->nrssi_lt[in_rssi];
398                                 tmp = 31 - tmp;
399                                 tmp *= -131;
400                                 tmp /= 128;
401                                 tmp -= 57;
402                         } else {
403                                 tmp = in_rssi;
404                                 tmp = 31 - tmp;
405                                 tmp *= -149;
406                                 tmp /= 128;
407                                 tmp -= 68;
408                         }
409                         if (phy->type == B43legacy_PHYTYPE_G &&
410                             adjust_2050)
411                                 tmp += 25;
412                 }
413                 break;
414         case 0x2060:
415                 if (in_rssi > 127)
416                         tmp = in_rssi - 256;
417                 else
418                         tmp = in_rssi;
419                 break;
420         default:
421                 tmp = in_rssi;
422                 tmp -= 11;
423                 tmp *= 103;
424                 tmp /= 64;
425                 if (adjust_2053)
426                         tmp -= 109;
427                 else
428                         tmp -= 83;
429         }
430
431         return (s8)tmp;
432 }
433
434 void b43legacy_rx(struct b43legacy_wldev *dev,
435                   struct sk_buff *skb,
436                   const void *_rxhdr)
437 {
438         struct ieee80211_rx_status status;
439         struct b43legacy_plcp_hdr6 *plcp;
440         struct ieee80211_hdr *wlhdr;
441         const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
442         __le16 fctl;
443         u16 phystat0;
444         u16 phystat3;
445         u16 chanstat;
446         u16 mactime;
447         u32 macstat;
448         u16 chanid;
449         u8 jssi;
450         int padding;
451
452         memset(&status, 0, sizeof(status));
453
454         /* Get metadata about the frame from the header. */
455         phystat0 = le16_to_cpu(rxhdr->phy_status0);
456         phystat3 = le16_to_cpu(rxhdr->phy_status3);
457         jssi = rxhdr->jssi;
458         macstat = le16_to_cpu(rxhdr->mac_status);
459         mactime = le16_to_cpu(rxhdr->mac_time);
460         chanstat = le16_to_cpu(rxhdr->channel);
461
462         if (macstat & B43legacy_RX_MAC_FCSERR)
463                 dev->wl->ieee_stats.dot11FCSErrorCount++;
464
465         /* Skip PLCP and padding */
466         padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
467         if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
468             padding))) {
469                 b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
470                 goto drop;
471         }
472         plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
473         skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
474         /* The skb contains the Wireless Header + payload data now */
475         if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
476                 b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
477                 goto drop;
478         }
479         wlhdr = (struct ieee80211_hdr *)(skb->data);
480         fctl = wlhdr->frame_control;
481
482         if ((macstat & B43legacy_RX_MAC_DEC) &&
483             !(macstat & B43legacy_RX_MAC_DECERR)) {
484                 unsigned int keyidx;
485                 int wlhdr_len;
486                 int iv_len;
487                 int icv_len;
488
489                 keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
490                           >> B43legacy_RX_MAC_KEYIDX_SHIFT);
491                 /* We must adjust the key index here. We want the "physical"
492                  * key index, but the ucode passed it slightly different.
493                  */
494                 keyidx = b43legacy_kidx_to_raw(dev, keyidx);
495                 B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
496
497                 if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
498                         /* Remove PROTECTED flag to mark it as decrypted. */
499                         B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
500                         fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
501                         wlhdr->frame_control = fctl;
502
503                         wlhdr_len = ieee80211_hdrlen(fctl);
504                         if (unlikely(skb->len < (wlhdr_len + 3))) {
505                                 b43legacydbg(dev->wl, "RX: Packet size"
506                                              " underrun3\n");
507                                 goto drop;
508                         }
509                         if (skb->data[wlhdr_len + 3] & (1 << 5)) {
510                                 /* The Ext-IV Bit is set in the "KeyID"
511                                  * octet of the IV.
512                                  */
513                                 iv_len = 8;
514                                 icv_len = 8;
515                         } else {
516                                 iv_len = 4;
517                                 icv_len = 4;
518                         }
519                         if (unlikely(skb->len < (wlhdr_len + iv_len +
520                             icv_len))) {
521                                 b43legacydbg(dev->wl, "RX: Packet size"
522                                              " underrun4\n");
523                                 goto drop;
524                         }
525                         /* Remove the IV */
526                         memmove(skb->data + iv_len, skb->data, wlhdr_len);
527                         skb_pull(skb, iv_len);
528                         /* Remove the ICV */
529                         skb_trim(skb, skb->len - icv_len);
530
531                         status.flag |= RX_FLAG_DECRYPTED;
532                 }
533         }
534
535         status.signal = b43legacy_rssi_postprocess(dev, jssi,
536                                       (phystat0 & B43legacy_RX_PHYST0_OFDM),
537                                       (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
538                                       (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
539         status.noise = dev->stats.link_noise;
540         status.qual = (jssi * 100) / B43legacy_RX_MAX_SSI;
541         /* change to support A PHY */
542         if (phystat0 & B43legacy_RX_PHYST0_OFDM)
543                 status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
544         else
545                 status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
546         status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
547
548         /*
549          * All frames on monitor interfaces and beacons always need a full
550          * 64-bit timestamp. Monitor interfaces need it for diagnostic
551          * purposes and beacons for IBSS merging.
552          * This code assumes we get to process the packet within 16 bits
553          * of timestamp, i.e. about 65 milliseconds after the PHY received
554          * the first symbol.
555          */
556         if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
557                 u16 low_mactime_now;
558
559                 b43legacy_tsf_read(dev, &status.mactime);
560                 low_mactime_now = status.mactime;
561                 status.mactime = status.mactime & ~0xFFFFULL;
562                 status.mactime += mactime;
563                 if (low_mactime_now <= mactime)
564                         status.mactime -= 0x10000;
565                 status.flag |= RX_FLAG_TSFT;
566         }
567
568         chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
569                   B43legacy_RX_CHAN_ID_SHIFT;
570         switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
571         case B43legacy_PHYTYPE_B:
572         case B43legacy_PHYTYPE_G:
573                 status.band = IEEE80211_BAND_2GHZ;
574                 status.freq = chanid + 2400;
575                 break;
576         default:
577                 b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
578                        chanstat);
579         }
580
581         dev->stats.last_rx = jiffies;
582         ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
583
584         return;
585 drop:
586         b43legacydbg(dev->wl, "RX: Packet dropped\n");
587         dev_kfree_skb_any(skb);
588 }
589
590 void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
591                              const struct b43legacy_txstatus *status)
592 {
593         b43legacy_debugfs_log_txstat(dev, status);
594
595         if (status->intermediate)
596                 return;
597         if (status->for_ampdu)
598                 return;
599         if (!status->acked)
600                 dev->wl->ieee_stats.dot11ACKFailureCount++;
601         if (status->rts_count) {
602                 if (status->rts_count == 0xF) /* FIXME */
603                         dev->wl->ieee_stats.dot11RTSFailureCount++;
604                 else
605                         dev->wl->ieee_stats.dot11RTSSuccessCount++;
606         }
607
608         if (b43legacy_using_pio(dev))
609                 b43legacy_pio_handle_txstatus(dev, status);
610         else
611                 b43legacy_dma_handle_txstatus(dev, status);
612 }
613
614 /* Handle TX status report as received through DMA/PIO queues */
615 void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
616                                  const struct b43legacy_hwtxstatus *hw)
617 {
618         struct b43legacy_txstatus status;
619         u8 tmp;
620
621         status.cookie = le16_to_cpu(hw->cookie);
622         status.seq = le16_to_cpu(hw->seq);
623         status.phy_stat = hw->phy_stat;
624         tmp = hw->count;
625         status.frame_count = (tmp >> 4);
626         status.rts_count = (tmp & 0x0F);
627         tmp = hw->flags << 1;
628         status.supp_reason = ((tmp & 0x1C) >> 2);
629         status.pm_indicated = !!(tmp & 0x80);
630         status.intermediate = !!(tmp & 0x40);
631         status.for_ampdu = !!(tmp & 0x20);
632         status.acked = !!(tmp & 0x02);
633
634         b43legacy_handle_txstatus(dev, &status);
635 }
636
637 /* Stop any TX operation on the device (suspend the hardware queues) */
638 void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
639 {
640         if (b43legacy_using_pio(dev))
641                 b43legacy_pio_freeze_txqueues(dev);
642         else
643                 b43legacy_dma_tx_suspend(dev);
644 }
645
646 /* Resume any TX operation on the device (resume the hardware queues) */
647 void b43legacy_tx_resume(struct b43legacy_wldev *dev)
648 {
649         if (b43legacy_using_pio(dev))
650                 b43legacy_pio_thaw_txqueues(dev);
651         else
652                 b43legacy_dma_tx_resume(dev);
653 }
654
655 /* Initialize the QoS parameters */
656 void b43legacy_qos_init(struct b43legacy_wldev *dev)
657 {
658         /* FIXME: This function must probably be called from the mac80211
659          * config callback. */
660 return;
661
662         b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
663         /* FIXME kill magic */
664         b43legacy_write16(dev, 0x688,
665                           b43legacy_read16(dev, 0x688) | 0x4);
666
667
668         /*TODO: We might need some stack support here to get the values. */
669 }