bf6f6c1ed4cf5193117a88da50493a3e965b6426
[safe/jmp/linux-2.6] / drivers / net / wireless / b43 / xmit.c
1 /*
2
3   Broadcom B43 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
13   This program is free software; you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation; either version 2 of the License, or
16   (at your option) any later version.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program; see the file COPYING.  If not, write to
25   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
26   Boston, MA 02110-1301, USA.
27
28 */
29
30 #include "xmit.h"
31 #include "phy.h"
32 #include "dma.h"
33 #include "pio.h"
34
35
36 /* Extract the bitrate index out of a CCK PLCP header. */
37 static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
38 {
39         switch (plcp->raw[0]) {
40         case 0x0A:
41                 return 0;
42         case 0x14:
43                 return 1;
44         case 0x37:
45                 return 2;
46         case 0x6E:
47                 return 3;
48         }
49         B43_WARN_ON(1);
50         return -1;
51 }
52
53 /* Extract the bitrate index out of an OFDM PLCP header. */
54 static u8 b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
55 {
56         int base = aphy ? 0 : 4;
57
58         switch (plcp->raw[0] & 0xF) {
59         case 0xB:
60                 return base + 0;
61         case 0xF:
62                 return base + 1;
63         case 0xA:
64                 return base + 2;
65         case 0xE:
66                 return base + 3;
67         case 0x9:
68                 return base + 4;
69         case 0xD:
70                 return base + 5;
71         case 0x8:
72                 return base + 6;
73         case 0xC:
74                 return base + 7;
75         }
76         B43_WARN_ON(1);
77         return -1;
78 }
79
80 u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
81 {
82         switch (bitrate) {
83         case B43_CCK_RATE_1MB:
84                 return 0x0A;
85         case B43_CCK_RATE_2MB:
86                 return 0x14;
87         case B43_CCK_RATE_5MB:
88                 return 0x37;
89         case B43_CCK_RATE_11MB:
90                 return 0x6E;
91         }
92         B43_WARN_ON(1);
93         return 0;
94 }
95
96 u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
97 {
98         switch (bitrate) {
99         case B43_OFDM_RATE_6MB:
100                 return 0xB;
101         case B43_OFDM_RATE_9MB:
102                 return 0xF;
103         case B43_OFDM_RATE_12MB:
104                 return 0xA;
105         case B43_OFDM_RATE_18MB:
106                 return 0xE;
107         case B43_OFDM_RATE_24MB:
108                 return 0x9;
109         case B43_OFDM_RATE_36MB:
110                 return 0xD;
111         case B43_OFDM_RATE_48MB:
112                 return 0x8;
113         case B43_OFDM_RATE_54MB:
114                 return 0xC;
115         }
116         B43_WARN_ON(1);
117         return 0;
118 }
119
120 void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
121                            const u16 octets, const u8 bitrate)
122 {
123         __le32 *data = &(plcp->data);
124         __u8 *raw = plcp->raw;
125
126         if (b43_is_ofdm_rate(bitrate)) {
127                 u32 d;
128
129                 d = b43_plcp_get_ratecode_ofdm(bitrate);
130                 B43_WARN_ON(octets & 0xF000);
131                 d |= (octets << 5);
132                 *data = cpu_to_le32(d);
133         } else {
134                 u32 plen;
135
136                 plen = octets * 16 / bitrate;
137                 if ((octets * 16 % bitrate) > 0) {
138                         plen++;
139                         if ((bitrate == B43_CCK_RATE_11MB)
140                             && ((octets * 8 % 11) < 4)) {
141                                 raw[1] = 0x84;
142                         } else
143                                 raw[1] = 0x04;
144                 } else
145                         raw[1] = 0x04;
146                 *data |= cpu_to_le32(plen << 16);
147                 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
148         }
149 }
150
151 static u8 b43_calc_fallback_rate(u8 bitrate)
152 {
153         switch (bitrate) {
154         case B43_CCK_RATE_1MB:
155                 return B43_CCK_RATE_1MB;
156         case B43_CCK_RATE_2MB:
157                 return B43_CCK_RATE_1MB;
158         case B43_CCK_RATE_5MB:
159                 return B43_CCK_RATE_2MB;
160         case B43_CCK_RATE_11MB:
161                 return B43_CCK_RATE_5MB;
162         case B43_OFDM_RATE_6MB:
163                 return B43_CCK_RATE_5MB;
164         case B43_OFDM_RATE_9MB:
165                 return B43_OFDM_RATE_6MB;
166         case B43_OFDM_RATE_12MB:
167                 return B43_OFDM_RATE_9MB;
168         case B43_OFDM_RATE_18MB:
169                 return B43_OFDM_RATE_12MB;
170         case B43_OFDM_RATE_24MB:
171                 return B43_OFDM_RATE_18MB;
172         case B43_OFDM_RATE_36MB:
173                 return B43_OFDM_RATE_24MB;
174         case B43_OFDM_RATE_48MB:
175                 return B43_OFDM_RATE_36MB;
176         case B43_OFDM_RATE_54MB:
177                 return B43_OFDM_RATE_48MB;
178         }
179         B43_WARN_ON(1);
180         return 0;
181 }
182
183 /* Generate a TX data header. */
184 int b43_generate_txhdr(struct b43_wldev *dev,
185                        u8 *_txhdr,
186                        const unsigned char *fragment_data,
187                        unsigned int fragment_len,
188                        const struct ieee80211_tx_info *info,
189                        u16 cookie)
190 {
191         struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
192         const struct b43_phy *phy = &dev->phy;
193         const struct ieee80211_hdr *wlhdr =
194             (const struct ieee80211_hdr *)fragment_data;
195         int use_encryption = (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT));
196         __le16 fctl = wlhdr->frame_control;
197         struct ieee80211_rate *fbrate;
198         u8 rate, rate_fb;
199         int rate_ofdm, rate_fb_ofdm;
200         unsigned int plcp_fragment_len;
201         u32 mac_ctl = 0;
202         u16 phy_ctl = 0;
203         u8 extra_ft = 0;
204         struct ieee80211_rate *txrate;
205
206         memset(txhdr, 0, sizeof(*txhdr));
207
208         txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
209         rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
210         rate_ofdm = b43_is_ofdm_rate(rate);
211         fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info) ? : txrate;
212         rate_fb = fbrate->hw_value;
213         rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
214
215         if (rate_ofdm)
216                 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
217         else
218                 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
219         txhdr->mac_frame_ctl = wlhdr->frame_control;
220         memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
221
222         /* Calculate duration for fallback rate */
223         if ((rate_fb == rate) ||
224             (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
225             (wlhdr->duration_id == cpu_to_le16(0))) {
226                 /* If the fallback rate equals the normal rate or the
227                  * dur_id field contains an AID, CFP magic or 0,
228                  * use the original dur_id field. */
229                 txhdr->dur_fb = wlhdr->duration_id;
230         } else {
231                 txhdr->dur_fb = ieee80211_generic_frame_duration(
232                         dev->wl->hw, info->control.vif, fragment_len, fbrate);
233         }
234
235         plcp_fragment_len = fragment_len + FCS_LEN;
236         if (use_encryption) {
237                 u8 key_idx = info->control.hw_key->hw_key_idx;
238                 struct b43_key *key;
239                 int wlhdr_len;
240                 size_t iv_len;
241
242                 B43_WARN_ON(key_idx >= dev->max_nr_keys);
243                 key = &(dev->key[key_idx]);
244
245                 if (unlikely(!key->keyconf)) {
246                         /* This key is invalid. This might only happen
247                          * in a short timeframe after machine resume before
248                          * we were able to reconfigure keys.
249                          * Drop this packet completely. Do not transmit it
250                          * unencrypted to avoid leaking information. */
251                         return -ENOKEY;
252                 }
253
254                 /* Hardware appends ICV. */
255                 plcp_fragment_len += info->control.icv_len;
256
257                 key_idx = b43_kidx_to_fw(dev, key_idx);
258                 mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
259                            B43_TXH_MAC_KEYIDX;
260                 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
261                            B43_TXH_MAC_KEYALG;
262                 wlhdr_len = ieee80211_hdrlen(fctl);
263                 iv_len = min((size_t) info->control.iv_len,
264                              ARRAY_SIZE(txhdr->iv));
265                 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
266         }
267         if (b43_is_old_txhdr_format(dev)) {
268                 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
269                                       plcp_fragment_len, rate);
270         } else {
271                 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
272                                       plcp_fragment_len, rate);
273         }
274         b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
275                               plcp_fragment_len, rate_fb);
276
277         /* Extra Frame Types */
278         if (rate_fb_ofdm)
279                 extra_ft |= B43_TXH_EFT_FB_OFDM;
280         else
281                 extra_ft |= B43_TXH_EFT_FB_CCK;
282
283         /* Set channel radio code. Note that the micrcode ORs 0x100 to
284          * this value before comparing it to the value in SHM, if this
285          * is a 5Ghz packet.
286          */
287         txhdr->chan_radio_code = phy->channel;
288
289         /* PHY TX Control word */
290         if (rate_ofdm)
291                 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
292         else
293                 phy_ctl |= B43_TXH_PHY_ENC_CCK;
294         if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE)
295                 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
296
297         switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) {
298         case 0: /* Default */
299                 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
300                 break;
301         case 1: /* Antenna 0 */
302                 phy_ctl |= B43_TXH_PHY_ANT0;
303                 break;
304         case 2: /* Antenna 1 */
305                 phy_ctl |= B43_TXH_PHY_ANT1;
306                 break;
307         case 3: /* Antenna 2 */
308                 phy_ctl |= B43_TXH_PHY_ANT2;
309                 break;
310         case 4: /* Antenna 3 */
311                 phy_ctl |= B43_TXH_PHY_ANT3;
312                 break;
313         default:
314                 B43_WARN_ON(1);
315         }
316
317         /* MAC control */
318         if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
319                 mac_ctl |= B43_TXH_MAC_ACK;
320         if (!ieee80211_is_pspoll(fctl))
321                 mac_ctl |= B43_TXH_MAC_HWSEQ;
322         if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
323                 mac_ctl |= B43_TXH_MAC_STMSDU;
324         if (phy->type == B43_PHYTYPE_A)
325                 mac_ctl |= B43_TXH_MAC_5GHZ;
326         if (info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
327                 mac_ctl |= B43_TXH_MAC_LONGFRAME;
328
329         /* Generate the RTS or CTS-to-self frame */
330         if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
331             (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
332                 unsigned int len;
333                 struct ieee80211_hdr *hdr;
334                 int rts_rate, rts_rate_fb;
335                 int rts_rate_ofdm, rts_rate_fb_ofdm;
336                 struct b43_plcp_hdr6 *plcp;
337                 struct ieee80211_rate *rts_cts_rate;
338
339                 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
340
341                 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
342                 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
343                 rts_rate_fb = b43_calc_fallback_rate(rts_rate);
344                 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
345
346                 if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
347                         struct ieee80211_cts *cts;
348
349                         if (b43_is_old_txhdr_format(dev)) {
350                                 cts = (struct ieee80211_cts *)
351                                         (txhdr->old_format.rts_frame);
352                         } else {
353                                 cts = (struct ieee80211_cts *)
354                                         (txhdr->new_format.rts_frame);
355                         }
356                         ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
357                                                 fragment_data, fragment_len,
358                                                 info, cts);
359                         mac_ctl |= B43_TXH_MAC_SENDCTS;
360                         len = sizeof(struct ieee80211_cts);
361                 } else {
362                         struct ieee80211_rts *rts;
363
364                         if (b43_is_old_txhdr_format(dev)) {
365                                 rts = (struct ieee80211_rts *)
366                                         (txhdr->old_format.rts_frame);
367                         } else {
368                                 rts = (struct ieee80211_rts *)
369                                         (txhdr->new_format.rts_frame);
370                         }
371                         ieee80211_rts_get(dev->wl->hw, info->control.vif,
372                                           fragment_data, fragment_len,
373                                           info, rts);
374                         mac_ctl |= B43_TXH_MAC_SENDRTS;
375                         len = sizeof(struct ieee80211_rts);
376                 }
377                 len += FCS_LEN;
378
379                 /* Generate the PLCP headers for the RTS/CTS frame */
380                 if (b43_is_old_txhdr_format(dev))
381                         plcp = &txhdr->old_format.rts_plcp;
382                 else
383                         plcp = &txhdr->new_format.rts_plcp;
384                 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
385                                       len, rts_rate);
386                 plcp = &txhdr->rts_plcp_fb;
387                 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
388                                       len, rts_rate_fb);
389
390                 if (b43_is_old_txhdr_format(dev)) {
391                         hdr = (struct ieee80211_hdr *)
392                                 (&txhdr->old_format.rts_frame);
393                 } else {
394                         hdr = (struct ieee80211_hdr *)
395                                 (&txhdr->new_format.rts_frame);
396                 }
397                 txhdr->rts_dur_fb = hdr->duration_id;
398
399                 if (rts_rate_ofdm) {
400                         extra_ft |= B43_TXH_EFT_RTS_OFDM;
401                         txhdr->phy_rate_rts =
402                             b43_plcp_get_ratecode_ofdm(rts_rate);
403                 } else {
404                         extra_ft |= B43_TXH_EFT_RTS_CCK;
405                         txhdr->phy_rate_rts =
406                             b43_plcp_get_ratecode_cck(rts_rate);
407                 }
408                 if (rts_rate_fb_ofdm)
409                         extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
410                 else
411                         extra_ft |= B43_TXH_EFT_RTSFB_CCK;
412         }
413
414         /* Magic cookie */
415         if (b43_is_old_txhdr_format(dev))
416                 txhdr->old_format.cookie = cpu_to_le16(cookie);
417         else
418                 txhdr->new_format.cookie = cpu_to_le16(cookie);
419
420         /* Apply the bitfields */
421         txhdr->mac_ctl = cpu_to_le32(mac_ctl);
422         txhdr->phy_ctl = cpu_to_le16(phy_ctl);
423         txhdr->extra_ft = extra_ft;
424
425         return 0;
426 }
427
428 static s8 b43_rssi_postprocess(struct b43_wldev *dev,
429                                u8 in_rssi, int ofdm,
430                                int adjust_2053, int adjust_2050)
431 {
432         struct b43_phy *phy = &dev->phy;
433         s32 tmp;
434
435         switch (phy->radio_ver) {
436         case 0x2050:
437                 if (ofdm) {
438                         tmp = in_rssi;
439                         if (tmp > 127)
440                                 tmp -= 256;
441                         tmp *= 73;
442                         tmp /= 64;
443                         if (adjust_2050)
444                                 tmp += 25;
445                         else
446                                 tmp -= 3;
447                 } else {
448                         if (dev->dev->bus->sprom.
449                             boardflags_lo & B43_BFL_RSSI) {
450                                 if (in_rssi > 63)
451                                         in_rssi = 63;
452                                 tmp = phy->nrssi_lt[in_rssi];
453                                 tmp = 31 - tmp;
454                                 tmp *= -131;
455                                 tmp /= 128;
456                                 tmp -= 57;
457                         } else {
458                                 tmp = in_rssi;
459                                 tmp = 31 - tmp;
460                                 tmp *= -149;
461                                 tmp /= 128;
462                                 tmp -= 68;
463                         }
464                         if (phy->type == B43_PHYTYPE_G && adjust_2050)
465                                 tmp += 25;
466                 }
467                 break;
468         case 0x2060:
469                 if (in_rssi > 127)
470                         tmp = in_rssi - 256;
471                 else
472                         tmp = in_rssi;
473                 break;
474         default:
475                 tmp = in_rssi;
476                 tmp -= 11;
477                 tmp *= 103;
478                 tmp /= 64;
479                 if (adjust_2053)
480                         tmp -= 109;
481                 else
482                         tmp -= 83;
483         }
484
485         return (s8) tmp;
486 }
487
488 //TODO
489 #if 0
490 static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
491 {
492         struct b43_phy *phy = &dev->phy;
493         s8 ret;
494
495         if (phy->type == B43_PHYTYPE_A) {
496                 //TODO: Incomplete specs.
497                 ret = 0;
498         } else
499                 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
500
501         return ret;
502 }
503 #endif
504
505 void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
506 {
507         struct ieee80211_rx_status status;
508         struct b43_plcp_hdr6 *plcp;
509         struct ieee80211_hdr *wlhdr;
510         const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
511         __le16 fctl;
512         u16 phystat0, phystat3, chanstat, mactime;
513         u32 macstat;
514         u16 chanid;
515         u16 phytype;
516         int padding;
517
518         memset(&status, 0, sizeof(status));
519
520         /* Get metadata about the frame from the header. */
521         phystat0 = le16_to_cpu(rxhdr->phy_status0);
522         phystat3 = le16_to_cpu(rxhdr->phy_status3);
523         macstat = le32_to_cpu(rxhdr->mac_status);
524         mactime = le16_to_cpu(rxhdr->mac_time);
525         chanstat = le16_to_cpu(rxhdr->channel);
526         phytype = chanstat & B43_RX_CHAN_PHYTYPE;
527
528         if (macstat & B43_RX_MAC_FCSERR)
529                 dev->wl->ieee_stats.dot11FCSErrorCount++;
530         if (macstat & B43_RX_MAC_DECERR) {
531                 /* Decryption with the given key failed.
532                  * Drop the packet. We also won't be able to decrypt it with
533                  * the key in software. */
534                 goto drop;
535         }
536
537         /* Skip PLCP and padding */
538         padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
539         if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
540                 b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
541                 goto drop;
542         }
543         plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
544         skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
545         /* The skb contains the Wireless Header + payload data now */
546         if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */  + FCS_LEN))) {
547                 b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
548                 goto drop;
549         }
550         wlhdr = (struct ieee80211_hdr *)(skb->data);
551         fctl = wlhdr->frame_control;
552
553         if (macstat & B43_RX_MAC_DEC) {
554                 unsigned int keyidx;
555                 int wlhdr_len;
556
557                 keyidx = ((macstat & B43_RX_MAC_KEYIDX)
558                           >> B43_RX_MAC_KEYIDX_SHIFT);
559                 /* We must adjust the key index here. We want the "physical"
560                  * key index, but the ucode passed it slightly different.
561                  */
562                 keyidx = b43_kidx_to_raw(dev, keyidx);
563                 B43_WARN_ON(keyidx >= dev->max_nr_keys);
564
565                 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
566                         wlhdr_len = ieee80211_hdrlen(fctl);
567                         if (unlikely(skb->len < (wlhdr_len + 3))) {
568                                 b43dbg(dev->wl,
569                                        "RX: Packet size underrun (3)\n");
570                                 goto drop;
571                         }
572                         status.flag |= RX_FLAG_DECRYPTED;
573                 }
574         }
575
576         /* Link quality statistics */
577         status.noise = dev->stats.link_noise;
578         if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
579 //              s8 rssi = max(rxhdr->power0, rxhdr->power1);
580                 //TODO: Find out what the rssi value is (dBm or percentage?)
581                 //      and also find out what the maximum possible value is.
582                 //      Fill status.ssi and status.signal fields.
583         } else {
584                 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
585                                                   (phystat0 & B43_RX_PHYST0_OFDM),
586                                                   (phystat0 & B43_RX_PHYST0_GAINCTL),
587                                                   (phystat3 & B43_RX_PHYST3_TRSTATE));
588                 status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
589         }
590
591         if (phystat0 & B43_RX_PHYST0_OFDM)
592                 status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
593                                                 phytype == B43_PHYTYPE_A);
594         else
595                 status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
596         status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
597
598         /*
599          * All frames on monitor interfaces and beacons always need a full
600          * 64-bit timestamp. Monitor interfaces need it for diagnostic
601          * purposes and beacons for IBSS merging.
602          * This code assumes we get to process the packet within 16 bits
603          * of timestamp, i.e. about 65 milliseconds after the PHY received
604          * the first symbol.
605          */
606         if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
607                 u16 low_mactime_now;
608
609                 b43_tsf_read(dev, &status.mactime);
610                 low_mactime_now = status.mactime;
611                 status.mactime = status.mactime & ~0xFFFFULL;
612                 status.mactime += mactime;
613                 if (low_mactime_now <= mactime)
614                         status.mactime -= 0x10000;
615                 status.flag |= RX_FLAG_TSFT;
616         }
617
618         chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
619         switch (chanstat & B43_RX_CHAN_PHYTYPE) {
620         case B43_PHYTYPE_A:
621                 status.band = IEEE80211_BAND_5GHZ;
622                 B43_WARN_ON(1);
623                 /* FIXME: We don't really know which value the "chanid" contains.
624                  *        So the following assignment might be wrong. */
625                 status.freq = b43_channel_to_freq_5ghz(chanid);
626                 break;
627         case B43_PHYTYPE_G:
628                 status.band = IEEE80211_BAND_2GHZ;
629                 /* chanid is the radio channel cookie value as used
630                  * to tune the radio. */
631                 status.freq = chanid + 2400;
632                 break;
633         case B43_PHYTYPE_N:
634                 /* chanid is the SHM channel cookie. Which is the plain
635                  * channel number in b43. */
636                 if (chanstat & B43_RX_CHAN_5GHZ) {
637                         status.band = IEEE80211_BAND_5GHZ;
638                         status.freq = b43_freq_to_channel_5ghz(chanid);
639                 } else {
640                         status.band = IEEE80211_BAND_2GHZ;
641                         status.freq = b43_freq_to_channel_2ghz(chanid);
642                 }
643                 break;
644         default:
645                 B43_WARN_ON(1);
646                 goto drop;
647         }
648
649         dev->stats.last_rx = jiffies;
650         ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
651
652         return;
653 drop:
654         b43dbg(dev->wl, "RX: Packet dropped\n");
655         dev_kfree_skb_any(skb);
656 }
657
658 void b43_handle_txstatus(struct b43_wldev *dev,
659                          const struct b43_txstatus *status)
660 {
661         b43_debugfs_log_txstat(dev, status);
662
663         if (status->intermediate)
664                 return;
665         if (status->for_ampdu)
666                 return;
667         if (!status->acked)
668                 dev->wl->ieee_stats.dot11ACKFailureCount++;
669         if (status->rts_count) {
670                 if (status->rts_count == 0xF)   //FIXME
671                         dev->wl->ieee_stats.dot11RTSFailureCount++;
672                 else
673                         dev->wl->ieee_stats.dot11RTSSuccessCount++;
674         }
675
676         if (b43_using_pio_transfers(dev))
677                 b43_pio_handle_txstatus(dev, status);
678         else
679                 b43_dma_handle_txstatus(dev, status);
680 }
681
682 /* Fill out the mac80211 TXstatus report based on the b43-specific
683  * txstatus report data. This returns a boolean whether the frame was
684  * successfully transmitted. */
685 bool b43_fill_txstatus_report(struct ieee80211_tx_info *report,
686                               const struct b43_txstatus *status)
687 {
688         bool frame_success = 1;
689
690         if (status->acked) {
691                 /* The frame was ACKed. */
692                 report->flags |= IEEE80211_TX_STAT_ACK;
693         } else {
694                 /* The frame was not ACKed... */
695                 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
696                         /* ...but we expected an ACK. */
697                         frame_success = 0;
698                         report->status.excessive_retries = 1;
699                 }
700         }
701         if (status->frame_count == 0) {
702                 /* The frame was not transmitted at all. */
703                 report->status.retry_count = 0;
704         } else
705                 report->status.retry_count = status->frame_count - 1;
706
707         return frame_success;
708 }
709
710 /* Stop any TX operation on the device (suspend the hardware queues) */
711 void b43_tx_suspend(struct b43_wldev *dev)
712 {
713         if (b43_using_pio_transfers(dev))
714                 b43_pio_tx_suspend(dev);
715         else
716                 b43_dma_tx_suspend(dev);
717 }
718
719 /* Resume any TX operation on the device (resume the hardware queues) */
720 void b43_tx_resume(struct b43_wldev *dev)
721 {
722         if (b43_using_pio_transfers(dev))
723                 b43_pio_tx_resume(dev);
724         else
725                 b43_dma_tx_resume(dev);
726 }