Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-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->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT));
196         u16 fctl;
197         u8 rate;
198         struct ieee80211_rate *rate_fb;
199         int rate_ofdm;
200         int rate_fb_ofdm;
201         unsigned int plcp_fragment_len;
202         u32 mac_ctl = 0;
203         u16 phy_ctl = 0;
204         struct ieee80211_rate *tx_rate;
205
206         wlhdr = (const struct ieee80211_hdr *)fragment_data;
207         fctl = le16_to_cpu(wlhdr->frame_control);
208
209         memset(txhdr, 0, sizeof(*txhdr));
210
211         tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info);
212
213         rate = tx_rate->hw_value;
214         rate_ofdm = b43legacy_is_ofdm_rate(rate);
215         rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info) ? : tx_rate;
216         rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
217
218         txhdr->mac_frame_ctl = wlhdr->frame_control;
219         memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
220
221         /* Calculate duration for fallback rate */
222         if ((rate_fb->hw_value == rate) ||
223             (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
224             (wlhdr->duration_id == cpu_to_le16(0))) {
225                 /* If the fallback rate equals the normal rate or the
226                  * dur_id field contains an AID, CFP magic or 0,
227                  * use the original dur_id field. */
228                 txhdr->dur_fb = wlhdr->duration_id;
229         } else {
230                 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
231                                                          info->control.vif,
232                                                          fragment_len,
233                                                          rate_fb);
234         }
235
236         plcp_fragment_len = fragment_len + FCS_LEN;
237         if (use_encryption) {
238                 u8 key_idx = info->control.hw_key->hw_key_idx;
239                 struct b43legacy_key *key;
240                 int wlhdr_len;
241                 size_t iv_len;
242
243                 B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
244                 key = &(dev->key[key_idx]);
245
246                 if (key->enabled) {
247                         /* Hardware appends ICV. */
248                         plcp_fragment_len += info->control.icv_len;
249
250                         key_idx = b43legacy_kidx_to_fw(dev, key_idx);
251                         mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
252                                    B43legacy_TX4_MAC_KEYIDX;
253                         mac_ctl |= (key->algorithm <<
254                                    B43legacy_TX4_MAC_KEYALG_SHIFT) &
255                                    B43legacy_TX4_MAC_KEYALG;
256                         wlhdr_len = ieee80211_get_hdrlen(fctl);
257                         iv_len = min((size_t)info->control.iv_len,
258                                      ARRAY_SIZE(txhdr->iv));
259                         memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
260                 } else {
261                         /* This key is invalid. This might only happen
262                          * in a short timeframe after machine resume before
263                          * we were able to reconfigure keys.
264                          * Drop this packet completely. Do not transmit it
265                          * unencrypted to avoid leaking information. */
266                         return -ENOKEY;
267                 }
268         }
269         b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
270                                     (&txhdr->plcp), plcp_fragment_len,
271                                     rate);
272         b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
273                                     (&txhdr->plcp_fb), plcp_fragment_len,
274                                     rate_fb->hw_value);
275
276         /* PHY TX Control word */
277         if (rate_ofdm)
278                 phy_ctl |= B43legacy_TX4_PHY_OFDM;
279         if (dev->short_preamble)
280                 phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
281         switch (info->antenna_sel_tx) {
282         case 0:
283                 phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
284                 break;
285         case 1:
286                 phy_ctl |= B43legacy_TX4_PHY_ANT0;
287                 break;
288         case 2:
289                 phy_ctl |= B43legacy_TX4_PHY_ANT1;
290                 break;
291         default:
292                 B43legacy_BUG_ON(1);
293         }
294
295         /* MAC control */
296         if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
297                 mac_ctl |= B43legacy_TX4_MAC_ACK;
298         if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
299               ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
300                 mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
301         if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
302                 mac_ctl |= B43legacy_TX4_MAC_STMSDU;
303         if (rate_fb_ofdm)
304                 mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
305         if (info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
306                 mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
307
308         /* Generate the RTS or CTS-to-self frame */
309         if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
310             (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
311                 unsigned int len;
312                 struct ieee80211_hdr *hdr;
313                 int rts_rate;
314                 int rts_rate_fb;
315                 int rts_rate_ofdm;
316                 int rts_rate_fb_ofdm;
317
318                 rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
319                 rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate);
320                 rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
321                 rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
322                 if (rts_rate_fb_ofdm)
323                         mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
324
325                 if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
326                         ieee80211_ctstoself_get(dev->wl->hw,
327                                                 info->control.vif,
328                                                 fragment_data,
329                                                 fragment_len, info,
330                                                 (struct ieee80211_cts *)
331                                                 (txhdr->rts_frame));
332                         mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
333                         len = sizeof(struct ieee80211_cts);
334                 } else {
335                         ieee80211_rts_get(dev->wl->hw,
336                                           info->control.vif,
337                                           fragment_data, fragment_len, info,
338                                           (struct ieee80211_rts *)
339                                           (txhdr->rts_frame));
340                         mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
341                         len = sizeof(struct ieee80211_rts);
342                 }
343                 len += FCS_LEN;
344                 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
345                                             (&txhdr->rts_plcp),
346                                             len, rts_rate);
347                 b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
348                                             (&txhdr->rts_plcp_fb),
349                                             len, rts_rate_fb);
350                 hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
351                 txhdr->rts_dur_fb = hdr->duration_id;
352         }
353
354         /* Magic cookie */
355         txhdr->cookie = cpu_to_le16(cookie);
356
357         /* Apply the bitfields */
358         txhdr->mac_ctl = cpu_to_le32(mac_ctl);
359         txhdr->phy_ctl = cpu_to_le16(phy_ctl);
360
361         return 0;
362 }
363
364 int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
365                               u8 *txhdr,
366                               const unsigned char *fragment_data,
367                               unsigned int fragment_len,
368                               const struct ieee80211_tx_info *info,
369                               u16 cookie)
370 {
371         return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
372                            fragment_data, fragment_len,
373                            info, cookie);
374 }
375
376 static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
377                                      u8 in_rssi, int ofdm,
378                                      int adjust_2053, int adjust_2050)
379 {
380         struct b43legacy_phy *phy = &dev->phy;
381         s32 tmp;
382
383         switch (phy->radio_ver) {
384         case 0x2050:
385                 if (ofdm) {
386                         tmp = in_rssi;
387                         if (tmp > 127)
388                                 tmp -= 256;
389                         tmp *= 73;
390                         tmp /= 64;
391                         if (adjust_2050)
392                                 tmp += 25;
393                         else
394                                 tmp -= 3;
395                 } else {
396                         if (dev->dev->bus->sprom.boardflags_lo
397                             & B43legacy_BFL_RSSI) {
398                                 if (in_rssi > 63)
399                                         in_rssi = 63;
400                                 tmp = phy->nrssi_lt[in_rssi];
401                                 tmp = 31 - tmp;
402                                 tmp *= -131;
403                                 tmp /= 128;
404                                 tmp -= 57;
405                         } else {
406                                 tmp = in_rssi;
407                                 tmp = 31 - tmp;
408                                 tmp *= -149;
409                                 tmp /= 128;
410                                 tmp -= 68;
411                         }
412                         if (phy->type == B43legacy_PHYTYPE_G &&
413                             adjust_2050)
414                                 tmp += 25;
415                 }
416                 break;
417         case 0x2060:
418                 if (in_rssi > 127)
419                         tmp = in_rssi - 256;
420                 else
421                         tmp = in_rssi;
422                 break;
423         default:
424                 tmp = in_rssi;
425                 tmp -= 11;
426                 tmp *= 103;
427                 tmp /= 64;
428                 if (adjust_2053)
429                         tmp -= 109;
430                 else
431                         tmp -= 83;
432         }
433
434         return (s8)tmp;
435 }
436
437 void b43legacy_rx(struct b43legacy_wldev *dev,
438                   struct sk_buff *skb,
439                   const void *_rxhdr)
440 {
441         struct ieee80211_rx_status status;
442         struct b43legacy_plcp_hdr6 *plcp;
443         struct ieee80211_hdr *wlhdr;
444         const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
445         __le16 fctl;
446         u16 phystat0;
447         u16 phystat3;
448         u16 chanstat;
449         u16 mactime;
450         u32 macstat;
451         u16 chanid;
452         u8 jssi;
453         int padding;
454
455         memset(&status, 0, sizeof(status));
456
457         /* Get metadata about the frame from the header. */
458         phystat0 = le16_to_cpu(rxhdr->phy_status0);
459         phystat3 = le16_to_cpu(rxhdr->phy_status3);
460         jssi = rxhdr->jssi;
461         macstat = le16_to_cpu(rxhdr->mac_status);
462         mactime = le16_to_cpu(rxhdr->mac_time);
463         chanstat = le16_to_cpu(rxhdr->channel);
464
465         if (macstat & B43legacy_RX_MAC_FCSERR)
466                 dev->wl->ieee_stats.dot11FCSErrorCount++;
467
468         /* Skip PLCP and padding */
469         padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
470         if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
471             padding))) {
472                 b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
473                 goto drop;
474         }
475         plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
476         skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
477         /* The skb contains the Wireless Header + payload data now */
478         if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
479                 b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
480                 goto drop;
481         }
482         wlhdr = (struct ieee80211_hdr *)(skb->data);
483         fctl = wlhdr->frame_control;
484
485         if ((macstat & B43legacy_RX_MAC_DEC) &&
486             !(macstat & B43legacy_RX_MAC_DECERR)) {
487                 unsigned int keyidx;
488                 int wlhdr_len;
489                 int iv_len;
490                 int icv_len;
491
492                 keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
493                           >> B43legacy_RX_MAC_KEYIDX_SHIFT);
494                 /* We must adjust the key index here. We want the "physical"
495                  * key index, but the ucode passed it slightly different.
496                  */
497                 keyidx = b43legacy_kidx_to_raw(dev, keyidx);
498                 B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
499
500                 if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
501                         /* Remove PROTECTED flag to mark it as decrypted. */
502                         B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
503                         fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
504                         wlhdr->frame_control = fctl;
505
506                         wlhdr_len = ieee80211_hdrlen(fctl);
507                         if (unlikely(skb->len < (wlhdr_len + 3))) {
508                                 b43legacydbg(dev->wl, "RX: Packet size"
509                                              " underrun3\n");
510                                 goto drop;
511                         }
512                         if (skb->data[wlhdr_len + 3] & (1 << 5)) {
513                                 /* The Ext-IV Bit is set in the "KeyID"
514                                  * octet of the IV.
515                                  */
516                                 iv_len = 8;
517                                 icv_len = 8;
518                         } else {
519                                 iv_len = 4;
520                                 icv_len = 4;
521                         }
522                         if (unlikely(skb->len < (wlhdr_len + iv_len +
523                             icv_len))) {
524                                 b43legacydbg(dev->wl, "RX: Packet size"
525                                              " underrun4\n");
526                                 goto drop;
527                         }
528                         /* Remove the IV */
529                         memmove(skb->data + iv_len, skb->data, wlhdr_len);
530                         skb_pull(skb, iv_len);
531                         /* Remove the ICV */
532                         skb_trim(skb, skb->len - icv_len);
533
534                         status.flag |= RX_FLAG_DECRYPTED;
535                 }
536         }
537
538         status.signal = b43legacy_rssi_postprocess(dev, jssi,
539                                       (phystat0 & B43legacy_RX_PHYST0_OFDM),
540                                       (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
541                                       (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
542         status.noise = dev->stats.link_noise;
543         status.qual = (jssi * 100) / B43legacy_RX_MAX_SSI;
544         /* change to support A PHY */
545         if (phystat0 & B43legacy_RX_PHYST0_OFDM)
546                 status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
547         else
548                 status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
549         status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
550
551         /*
552          * All frames on monitor interfaces and beacons always need a full
553          * 64-bit timestamp. Monitor interfaces need it for diagnostic
554          * purposes and beacons for IBSS merging.
555          * This code assumes we get to process the packet within 16 bits
556          * of timestamp, i.e. about 65 milliseconds after the PHY received
557          * the first symbol.
558          */
559         if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
560                 u16 low_mactime_now;
561
562                 b43legacy_tsf_read(dev, &status.mactime);
563                 low_mactime_now = status.mactime;
564                 status.mactime = status.mactime & ~0xFFFFULL;
565                 status.mactime += mactime;
566                 if (low_mactime_now <= mactime)
567                         status.mactime -= 0x10000;
568                 status.flag |= RX_FLAG_TSFT;
569         }
570
571         chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
572                   B43legacy_RX_CHAN_ID_SHIFT;
573         switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
574         case B43legacy_PHYTYPE_B:
575         case B43legacy_PHYTYPE_G:
576                 status.band = IEEE80211_BAND_2GHZ;
577                 status.freq = chanid + 2400;
578                 break;
579         default:
580                 b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
581                        chanstat);
582         }
583
584         dev->stats.last_rx = jiffies;
585         ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
586
587         return;
588 drop:
589         b43legacydbg(dev->wl, "RX: Packet dropped\n");
590         dev_kfree_skb_any(skb);
591 }
592
593 void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
594                              const struct b43legacy_txstatus *status)
595 {
596         b43legacy_debugfs_log_txstat(dev, status);
597
598         if (status->intermediate)
599                 return;
600         if (status->for_ampdu)
601                 return;
602         if (!status->acked)
603                 dev->wl->ieee_stats.dot11ACKFailureCount++;
604         if (status->rts_count) {
605                 if (status->rts_count == 0xF) /* FIXME */
606                         dev->wl->ieee_stats.dot11RTSFailureCount++;
607                 else
608                         dev->wl->ieee_stats.dot11RTSSuccessCount++;
609         }
610
611         if (b43legacy_using_pio(dev))
612                 b43legacy_pio_handle_txstatus(dev, status);
613         else
614                 b43legacy_dma_handle_txstatus(dev, status);
615 }
616
617 /* Handle TX status report as received through DMA/PIO queues */
618 void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
619                                  const struct b43legacy_hwtxstatus *hw)
620 {
621         struct b43legacy_txstatus status;
622         u8 tmp;
623
624         status.cookie = le16_to_cpu(hw->cookie);
625         status.seq = le16_to_cpu(hw->seq);
626         status.phy_stat = hw->phy_stat;
627         tmp = hw->count;
628         status.frame_count = (tmp >> 4);
629         status.rts_count = (tmp & 0x0F);
630         tmp = hw->flags;
631         status.supp_reason = ((tmp & 0x1C) >> 2);
632         status.pm_indicated = !!(tmp & 0x80);
633         status.intermediate = !!(tmp & 0x40);
634         status.for_ampdu = !!(tmp & 0x20);
635         status.acked = !!(tmp & 0x02);
636
637         b43legacy_handle_txstatus(dev, &status);
638 }
639
640 /* Stop any TX operation on the device (suspend the hardware queues) */
641 void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
642 {
643         if (b43legacy_using_pio(dev))
644                 b43legacy_pio_freeze_txqueues(dev);
645         else
646                 b43legacy_dma_tx_suspend(dev);
647 }
648
649 /* Resume any TX operation on the device (resume the hardware queues) */
650 void b43legacy_tx_resume(struct b43legacy_wldev *dev)
651 {
652         if (b43legacy_using_pio(dev))
653                 b43legacy_pio_thaw_txqueues(dev);
654         else
655                 b43legacy_dma_tx_resume(dev);
656 }
657
658 /* Initialize the QoS parameters */
659 void b43legacy_qos_init(struct b43legacy_wldev *dev)
660 {
661         /* FIXME: This function must probably be called from the mac80211
662          * config callback. */
663 return;
664
665         b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
666         /* FIXME kill magic */
667         b43legacy_write16(dev, 0x688,
668                           b43legacy_read16(dev, 0x688) | 0x4);
669
670
671         /*TODO: We might need some stack support here to get the values. */
672 }