8ad39386cf9e27dae1d5df72981c5c08dc9ed950
[openwrt.git] / package / bcm43xx-mac80211 / src / bcm43xx / bcm43xx_xmit.c
1 /*
2
3   Broadcom BCM43xx 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 <st3@riseup.net>
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 "bcm43xx_xmit.h"
31 #include "bcm43xx_phy.h"
32 #include "bcm43xx_dma.h"
33 #include "bcm43xx_pio.h"
34
35
36 /* Extract the bitrate out of a CCK PLCP header. */
37 static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr6 *plcp)
38 {
39         switch (plcp->raw[0]) {
40         case 0x0A:
41                 return BCM43xx_CCK_RATE_1MB;
42         case 0x14:
43                 return BCM43xx_CCK_RATE_2MB;
44         case 0x37:
45                 return BCM43xx_CCK_RATE_5MB;
46         case 0x6E:
47                 return BCM43xx_CCK_RATE_11MB;
48         }
49         assert(0);
50         return 0;
51 }
52
53 /* Extract the bitrate out of an OFDM PLCP header. */
54 static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr6 *plcp)
55 {
56         switch (plcp->raw[0] & 0xF) {
57         case 0xB:
58                 return BCM43xx_OFDM_RATE_6MB;
59         case 0xF:
60                 return BCM43xx_OFDM_RATE_9MB;
61         case 0xA:
62                 return BCM43xx_OFDM_RATE_12MB;
63         case 0xE:
64                 return BCM43xx_OFDM_RATE_18MB;
65         case 0x9:
66                 return BCM43xx_OFDM_RATE_24MB;
67         case 0xD:
68                 return BCM43xx_OFDM_RATE_36MB;
69         case 0x8:
70                 return BCM43xx_OFDM_RATE_48MB;
71         case 0xC:
72                 return BCM43xx_OFDM_RATE_54MB;
73         }
74         assert(0);
75         return 0;
76 }
77
78 u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
79 {
80         switch (bitrate) {
81         case BCM43xx_CCK_RATE_1MB:
82                 return 0x0A;
83         case BCM43xx_CCK_RATE_2MB:
84                 return 0x14;
85         case BCM43xx_CCK_RATE_5MB:
86                 return 0x37;
87         case BCM43xx_CCK_RATE_11MB:
88                 return 0x6E;
89         }
90         assert(0);
91         return 0;
92 }
93
94 u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
95 {
96         switch (bitrate) {
97         case BCM43xx_OFDM_RATE_6MB:
98                 return 0xB;
99         case BCM43xx_OFDM_RATE_9MB:
100                 return 0xF;
101         case BCM43xx_OFDM_RATE_12MB:
102                 return 0xA;
103         case BCM43xx_OFDM_RATE_18MB:
104                 return 0xE;
105         case BCM43xx_OFDM_RATE_24MB:
106                 return 0x9;
107         case BCM43xx_OFDM_RATE_36MB:
108                 return 0xD;
109         case BCM43xx_OFDM_RATE_48MB:
110                 return 0x8;
111         case BCM43xx_OFDM_RATE_54MB:
112                 return 0xC;
113         }
114         assert(0);
115         return 0;
116 }
117
118 void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
119                                const u16 octets, const u8 bitrate)
120 {
121         __le32 *data = &(plcp->data);
122         __u8 *raw = plcp->raw;
123
124         if (bcm43xx_is_ofdm_rate(bitrate)) {
125                 *data = bcm43xx_plcp_get_ratecode_ofdm(bitrate);
126                 assert(!(octets & 0xF000));
127                 *data |= (octets << 5);
128                 *data = cpu_to_le32(*data);
129         } else {
130                 u32 plen;
131
132                 plen = octets * 16 / bitrate;
133                 if ((octets * 16 % bitrate) > 0) {
134                         plen++;
135                         if ((bitrate == BCM43xx_CCK_RATE_11MB)
136                             && ((octets * 8 % 11) < 4)) {
137                                 raw[1] = 0x84;
138                         } else
139                                 raw[1] = 0x04;
140                 } else
141                         raw[1] = 0x04;
142                 *data |= cpu_to_le32(plen << 16);
143                 raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
144         }
145 }
146
147 static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
148 {
149         switch (bitrate) {
150         case BCM43xx_CCK_RATE_1MB:
151                 return BCM43xx_CCK_RATE_1MB;
152         case BCM43xx_CCK_RATE_2MB:
153                 return BCM43xx_CCK_RATE_1MB;
154         case BCM43xx_CCK_RATE_5MB:
155                 return BCM43xx_CCK_RATE_2MB;
156         case BCM43xx_CCK_RATE_11MB:
157                 return BCM43xx_CCK_RATE_5MB;
158         case BCM43xx_OFDM_RATE_6MB:
159                 return BCM43xx_CCK_RATE_5MB;
160         case BCM43xx_OFDM_RATE_9MB:
161                 return BCM43xx_OFDM_RATE_6MB;
162         case BCM43xx_OFDM_RATE_12MB:
163                 return BCM43xx_OFDM_RATE_9MB;
164         case BCM43xx_OFDM_RATE_18MB:
165                 return BCM43xx_OFDM_RATE_12MB;
166         case BCM43xx_OFDM_RATE_24MB:
167                 return BCM43xx_OFDM_RATE_18MB;
168         case BCM43xx_OFDM_RATE_36MB:
169                 return BCM43xx_OFDM_RATE_24MB;
170         case BCM43xx_OFDM_RATE_48MB:
171                 return BCM43xx_OFDM_RATE_36MB;
172         case BCM43xx_OFDM_RATE_54MB:
173                 return BCM43xx_OFDM_RATE_48MB;
174         }
175         assert(0);
176         return 0;
177 }
178
179 static void generate_txhdr_fw4(struct bcm43xx_wldev *dev,
180                                struct bcm43xx_txhdr_fw4 *txhdr,
181                                const unsigned char *fragment_data,
182                                unsigned int fragment_len,
183                                const struct ieee80211_tx_control *txctl,
184                                u16 cookie)
185 {
186         const struct bcm43xx_phy *phy = &dev->phy;
187         const struct ieee80211_hdr *wlhdr = (const struct ieee80211_hdr *)fragment_data;
188         int use_encryption = ((!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) &&
189                               (txctl->key_idx >= 0));
190         u16 fctl = le16_to_cpu(wlhdr->frame_control);
191         u8 rate, rate_fb;
192         int rate_ofdm, rate_fb_ofdm;
193         unsigned int plcp_fragment_len;
194         u32 mac_ctl = 0;
195         u16 phy_ctl = 0;
196         u8 extra_ft = 0;
197
198         memset(txhdr, 0, sizeof(*txhdr));
199
200         rate = txctl->tx_rate;
201         rate_ofdm = bcm43xx_is_ofdm_rate(rate);
202         rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate;
203         rate_fb_ofdm = bcm43xx_is_ofdm_rate(rate_fb);
204
205         if (rate_ofdm)
206                 txhdr->phy_rate = bcm43xx_plcp_get_ratecode_ofdm(rate);
207         else
208                 txhdr->phy_rate = bcm43xx_plcp_get_ratecode_cck(rate);
209         txhdr->mac_frame_ctl = wlhdr->frame_control;
210         memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
211
212         /* Calculate duration for fallback rate */
213         if ((rate_fb == rate) ||
214             (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
215             (wlhdr->duration_id == cpu_to_le16(0))) { 
216                 /* If the fallback rate equals the normal rate or the
217                  * dur_id field contains an AID, CFP magic or 0,
218                  * use the original dur_id field. */
219                 txhdr->dur_fb = wlhdr->duration_id;
220         } else {
221                 int fbrate_base100kbps = BCM43xx_RATE_TO_BASE100KBPS(rate_fb);
222                 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
223                                                                  fragment_len,
224                                                                  fbrate_base100kbps);
225         }
226
227         plcp_fragment_len = fragment_len + FCS_LEN;
228         if (use_encryption) {
229                 u8 key_idx = (u16)(txctl->key_idx);
230                 struct bcm43xx_key *key;
231                 int wlhdr_len;
232                 size_t iv_len;
233
234                 assert(key_idx < dev->max_nr_keys);
235                 key = &(dev->key[key_idx]);
236
237                 if (key->enabled) {
238                         /* Hardware appends ICV. */
239                         plcp_fragment_len += txctl->icv_len;
240
241                         key_idx = bcm43xx_kidx_to_fw(dev, key_idx);
242                         mac_ctl |= (key_idx << BCM43xx_TX4_MAC_KEYIDX_SHIFT) &
243                                    BCM43xx_TX4_MAC_KEYIDX;
244                         mac_ctl |= (key->algorithm << BCM43xx_TX4_MAC_KEYALG_SHIFT) &
245                                    BCM43xx_TX4_MAC_KEYALG;
246                         wlhdr_len = ieee80211_get_hdrlen(fctl);
247                         iv_len = min((size_t)txctl->iv_len,
248                                      ARRAY_SIZE(txhdr->iv));
249                         memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
250                 }
251         }
252         bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp),
253                                   plcp_fragment_len, rate);
254         bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp_fb),
255                                   plcp_fragment_len, rate_fb);
256
257         /* Extra Frame Types */
258         if (rate_fb_ofdm)
259                 extra_ft |= BCM43xx_TX4_EFT_FBOFDM;
260
261         /* Set channel radio code. Note that the micrcode ORs 0x100 to
262          * this value before comparing it to the value in SHM, if this
263          * is a 5Ghz packet.
264          */
265         txhdr->chan_radio_code = phy->channel;
266
267         /* PHY TX Control word */
268         if (rate_ofdm)
269                 phy_ctl |= BCM43xx_TX4_PHY_OFDM;
270         if (dev->short_preamble)
271                 phy_ctl |= BCM43xx_TX4_PHY_SHORTPRMBL;
272         switch (txctl->antenna_sel_tx) {
273         case 0:
274                 phy_ctl |= BCM43xx_TX4_PHY_ANTLAST;
275                 break;
276         case 1:
277                 phy_ctl |= BCM43xx_TX4_PHY_ANT0;
278                 break;
279         case 2:
280                 phy_ctl |= BCM43xx_TX4_PHY_ANT1;
281                 break;
282         default:
283                 assert(0);
284         }
285
286         /* MAC control */
287         if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
288                 mac_ctl |= BCM43xx_TX4_MAC_ACK;
289         if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
290               ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
291                 mac_ctl |= BCM43xx_TX4_MAC_HWSEQ;
292         if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
293                 mac_ctl |= BCM43xx_TX4_MAC_STMSDU;
294         if (phy->type == BCM43xx_PHYTYPE_A)
295                 mac_ctl |= BCM43xx_TX4_MAC_5GHZ;
296
297         /* Generate the RTS or CTS-to-self frame */
298         if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
299             (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
300                 unsigned int len;
301                 struct ieee80211_hdr *hdr;
302                 int rts_rate, rts_rate_fb;
303                 int rts_rate_ofdm, rts_rate_fb_ofdm;
304
305                 rts_rate = txctl->rts_cts_rate;
306                 rts_rate_ofdm = bcm43xx_is_ofdm_rate(rts_rate);
307                 rts_rate_fb = bcm43xx_calc_fallback_rate(rts_rate);
308                 rts_rate_fb_ofdm = bcm43xx_is_ofdm_rate(rts_rate_fb);
309
310                 if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
311                         ieee80211_ctstoself_get(dev->wl->hw,
312                                                 fragment_data, fragment_len, txctl,
313                                                 (struct ieee80211_cts *)(txhdr->rts_frame));
314                         mac_ctl |= BCM43xx_TX4_MAC_SENDCTS;
315                         len = sizeof(struct ieee80211_cts);
316                 } else {
317                         ieee80211_rts_get(dev->wl->hw,
318                                           fragment_data, fragment_len, txctl,
319                                           (struct ieee80211_rts *)(txhdr->rts_frame));
320                         mac_ctl |= BCM43xx_TX4_MAC_SENDRTS;
321                         len = sizeof(struct ieee80211_rts);
322                 }
323                 len += FCS_LEN;
324                 bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_plcp),
325                                           len, rts_rate);
326                 bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_plcp_fb),
327                                           len, rts_rate_fb);
328                 hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
329                 txhdr->rts_dur_fb = hdr->duration_id;
330                 if (rts_rate_ofdm) {
331                         extra_ft |= BCM43xx_TX4_EFT_RTSOFDM;
332                         txhdr->phy_rate_rts = bcm43xx_plcp_get_ratecode_ofdm(rts_rate);
333                 } else
334                         txhdr->phy_rate_rts = bcm43xx_plcp_get_ratecode_cck(rts_rate);
335                 if (rts_rate_fb_ofdm)
336                         extra_ft |= BCM43xx_TX4_EFT_RTSFBOFDM;
337                 mac_ctl |= BCM43xx_TX4_MAC_LONGFRAME;
338         }
339
340         /* Magic cookie */
341         txhdr->cookie = cpu_to_le16(cookie);
342
343         /* Apply the bitfields */
344         txhdr->mac_ctl = cpu_to_le32(mac_ctl);
345         txhdr->phy_ctl = cpu_to_le16(phy_ctl);
346         txhdr->extra_ft = extra_ft;
347 }
348
349 void bcm43xx_generate_txhdr(struct bcm43xx_wldev *dev,
350                             u8 *txhdr,
351                             const unsigned char *fragment_data,
352                             unsigned int fragment_len,
353                             const struct ieee80211_tx_control *txctl,
354                             u16 cookie)
355 {
356         generate_txhdr_fw4(dev, (struct bcm43xx_txhdr_fw4 *)txhdr,
357                            fragment_data, fragment_len,
358                            txctl, cookie);
359 }
360
361 static s8 bcm43xx_rssi_postprocess(struct bcm43xx_wldev *dev,
362                                    u8 in_rssi, int ofdm,
363                                    int adjust_2053, int adjust_2050)
364 {
365         struct bcm43xx_phy *phy = &dev->phy;
366         s32 tmp;
367
368         switch (phy->radio_ver) {
369         case 0x2050:
370                 if (ofdm) {
371                         tmp = in_rssi;
372                         if (tmp > 127)
373                                 tmp -= 256;
374                         tmp *= 73;
375                         tmp /= 64;
376                         if (adjust_2050)
377                                 tmp += 25;
378                         else
379                                 tmp -= 3;
380                 } else {
381                         if (dev->dev->bus->sprom.r1.boardflags_lo & BCM43xx_BFL_RSSI) {
382                                 if (in_rssi > 63)
383                                         in_rssi = 63;
384                                 tmp = phy->nrssi_lt[in_rssi];
385                                 tmp = 31 - tmp;
386                                 tmp *= -131;
387                                 tmp /= 128;
388                                 tmp -= 57;
389                         } else {
390                                 tmp = in_rssi;
391                                 tmp = 31 - tmp;
392                                 tmp *= -149;
393                                 tmp /= 128;
394                                 tmp -= 68;
395                         }
396                         if (phy->type == BCM43xx_PHYTYPE_G &&
397                             adjust_2050)
398                                 tmp += 25;
399                 }
400                 break;
401         case 0x2060:
402                 if (in_rssi > 127)
403                         tmp = in_rssi - 256;
404                 else
405                         tmp = in_rssi;
406                 break;
407         default:
408                 tmp = in_rssi;
409                 tmp -= 11;
410                 tmp *= 103;
411                 tmp /= 64;
412                 if (adjust_2053)
413                         tmp -= 109;
414                 else
415                         tmp -= 83;
416         }
417
418         return (s8)tmp;
419 }
420
421 //TODO
422 #if 0
423 static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_wldev *dev,
424                                         u8 in_rssi)
425 {
426         struct bcm43xx_phy *phy = &dev->phy;
427         s8 ret;
428
429         if (phy->type == BCM43xx_PHYTYPE_A) {
430                 //TODO: Incomplete specs.
431                 ret = 0;
432         } else
433                 ret = bcm43xx_rssi_postprocess(dev, in_rssi, 0, 1, 1);
434
435         return ret;
436 }
437 #endif
438
439 void bcm43xx_rx(struct bcm43xx_wldev *dev,
440                 struct sk_buff *skb,
441                 const void *_rxhdr)
442 {
443         struct ieee80211_rx_status status;
444         struct bcm43xx_plcp_hdr6 *plcp;
445         struct ieee80211_hdr *wlhdr;
446         const struct bcm43xx_rxhdr_fw4 *rxhdr = _rxhdr;
447         u16 fctl;
448         u16 phystat0, phystat3, chanstat, mactime;
449         u32 macstat;
450         u16 chanid;
451         u8 jssi;
452         int padding;
453
454         memset(&status, 0, sizeof(status));
455
456         /* Get metadata about the frame from the header. */
457         phystat0 = le16_to_cpu(rxhdr->phy_status0);
458         phystat3 = le16_to_cpu(rxhdr->phy_status3);
459         jssi = rxhdr->jssi;
460         macstat = le32_to_cpu(rxhdr->mac_status);
461         mactime = le16_to_cpu(rxhdr->mac_time);
462         chanstat = le16_to_cpu(rxhdr->channel);
463
464         if (macstat & BCM43xx_RX_MAC_FCSERR)
465                 dev->wl->ieee_stats.dot11FCSErrorCount++;
466
467         /* Skip PLCP and padding */
468         padding = (macstat & BCM43xx_RX_MAC_PADDING) ? 2 : 0;
469         plcp = (struct bcm43xx_plcp_hdr6 *)(skb->data + padding);
470         skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6) + padding);
471         /* The skb contains the Wireless Header + payload data now */
472         wlhdr = (struct ieee80211_hdr *)(skb->data);
473         fctl = le16_to_cpu(wlhdr->frame_control);
474
475         skb_trim(skb, skb->len - FCS_LEN);
476
477         if ((macstat & BCM43xx_RX_MAC_DEC) &&
478             !(macstat & BCM43xx_RX_MAC_DECERR)) {
479                 unsigned int keyidx;
480                 int wlhdr_len;
481                 int iv_len;
482                 int icv_len;
483
484                 keyidx = ((macstat & BCM43xx_RX_MAC_KEYIDX)
485                           >> BCM43xx_RX_MAC_KEYIDX_SHIFT);
486                 /* We must adjust the key index here. We want the "physical"
487                  * key index, but the ucode passed it slightly different.
488                  */
489                 keyidx = bcm43xx_kidx_to_raw(dev, keyidx);
490                 assert(keyidx < dev->max_nr_keys);
491
492                 if (dev->key[keyidx].algorithm != BCM43xx_SEC_ALGO_NONE) {
493                         /* Remove PROTECTED flag to mark it as decrypted. */
494                         assert(fctl & IEEE80211_FCTL_PROTECTED);
495                         fctl &= ~IEEE80211_FCTL_PROTECTED;
496                         wlhdr->frame_control = cpu_to_le16(fctl);
497
498                         wlhdr_len = ieee80211_get_hdrlen(fctl);
499                         if (skb->data[wlhdr_len + 3] & (1 << 5)) {
500                                 /* The Ext-IV Bit is set in the "KeyID"
501                                  * octet of the IV.
502                                  */
503                                 iv_len = 8;
504                                 icv_len = 8;
505                         } else {
506                                 iv_len = 4;
507                                 icv_len = 4;
508                         }
509
510                         /* Remove the IV */
511                         memmove(skb->data + iv_len, skb->data, wlhdr_len);
512                         skb_pull(skb, iv_len);
513                         /* Remove the ICV */
514                         skb_trim(skb, skb->len - icv_len);
515
516                         status.flag |= RX_FLAG_DECRYPTED;
517                 }
518         }
519
520         status.ssi = bcm43xx_rssi_postprocess(dev, jssi,
521                                               (phystat0 & BCM43xx_RX_PHYST0_OFDM),
522                                               (phystat0 & BCM43xx_RX_PHYST0_GAINCTL),
523                                               (phystat3 & BCM43xx_RX_PHYST3_TRSTATE));
524         status.noise = dev->stats.link_noise;
525         status.signal = jssi; /* this looks wrong, but is what mac80211 wants */
526         if (phystat0 & BCM43xx_RX_PHYST0_OFDM)
527                 status.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
528         else
529                 status.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
530         status.antenna = !!(phystat0 & BCM43xx_RX_PHYST0_ANT);
531         status.mactime = mactime;
532
533         chanid = (chanstat & BCM43xx_RX_CHAN_ID) >> BCM43xx_RX_CHAN_ID_SHIFT;
534         switch (chanstat & BCM43xx_RX_CHAN_PHYTYPE) {
535         case BCM43xx_PHYTYPE_A:
536                 status.phymode = MODE_IEEE80211A;
537                 status.freq = chanid;
538                 status.channel = bcm43xx_freq_to_channel_a(chanid);
539                 break;
540         case BCM43xx_PHYTYPE_B:
541                 status.phymode = MODE_IEEE80211B;
542                 status.freq = chanid + 2400;
543                 status.channel = bcm43xx_freq_to_channel_bg(chanid + 2400);
544                 break;
545         case BCM43xx_PHYTYPE_G:
546                 status.phymode = MODE_IEEE80211G;
547                 status.freq = chanid + 2400;
548                 status.channel = bcm43xx_freq_to_channel_bg(chanid + 2400);
549                 break;
550         default:
551                 assert(0);
552         }
553
554         dev->stats.last_rx = jiffies;
555         ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
556 }
557
558 void bcm43xx_handle_txstatus(struct bcm43xx_wldev *dev,
559                              const struct bcm43xx_txstatus *status)
560 {
561         bcm43xx_debugfs_log_txstat(dev, status);
562
563         if (status->intermediate)
564                 return;
565         if (status->for_ampdu)
566                 return;
567         if (!status->acked)
568                 dev->wl->ieee_stats.dot11ACKFailureCount++;
569         if (status->rts_count) {
570                 if (status->rts_count == 0xF) //FIXME
571                         dev->wl->ieee_stats.dot11RTSFailureCount++;
572                 else
573                         dev->wl->ieee_stats.dot11RTSSuccessCount++;
574         }
575
576         if (bcm43xx_using_pio(dev))
577                 bcm43xx_pio_handle_txstatus(dev, status);
578         else
579                 bcm43xx_dma_handle_txstatus(dev, status);
580 }
581
582 /* Handle TX status report as received through DMA/PIO queues */
583 void bcm43xx_handle_hwtxstatus(struct bcm43xx_wldev *dev,
584                                const struct bcm43xx_hwtxstatus *hw)
585 {
586         struct bcm43xx_txstatus status;
587         u8 tmp;
588
589         status.cookie = le16_to_cpu(hw->cookie);
590         status.seq = le16_to_cpu(hw->seq);
591         status.phy_stat = hw->phy_stat;
592         tmp = hw->count;
593         status.frame_count = (tmp >> 4);
594         status.rts_count = (tmp & 0x0F);
595         tmp = hw->flags;
596         status.supp_reason = ((tmp & 0x1C) >> 2);
597         status.pm_indicated = !!(tmp & 0x80);
598         status.intermediate = !!(tmp & 0x40);
599         status.for_ampdu = !!(tmp & 0x20);
600         status.acked = !!(tmp & 0x02);
601
602         bcm43xx_handle_txstatus(dev, &status);
603 }
604
605 /* Stop any TX operation on the device (suspend the hardware queues) */
606 void bcm43xx_tx_suspend(struct bcm43xx_wldev *dev)
607 {
608         if (bcm43xx_using_pio(dev))
609                 bcm43xx_pio_freeze_txqueues(dev);
610         else
611                 bcm43xx_dma_tx_suspend(dev);
612 }
613
614 /* Resume any TX operation on the device (resume the hardware queues) */
615 void bcm43xx_tx_resume(struct bcm43xx_wldev *dev)
616 {
617         if (bcm43xx_using_pio(dev))
618                 bcm43xx_pio_thaw_txqueues(dev);
619         else
620                 bcm43xx_dma_tx_resume(dev);
621 }
622
623 #if 0
624 static void upload_qos_parms(struct bcm43xx_wldev *dev,
625                              const u16 *parms,
626                              u16 offset)
627 {
628         int i;
629
630         for (i = 0; i < BCM43xx_NR_QOSPARMS; i++) {
631                 bcm43xx_shm_write16(dev, BCM43xx_SHM_SHARED,
632                                     offset + (i * 2), parms[i]);
633         }
634 }
635 #endif
636
637 /* Initialize the QoS parameters */
638 void bcm43xx_qos_init(struct bcm43xx_wldev *dev)
639 {
640         /* FIXME: This function must probably be called from the mac80211
641          * config callback. */
642 return;
643
644         bcm43xx_hf_write(dev, bcm43xx_hf_read(dev) | BCM43xx_HF_EDCF);
645         //FIXME kill magic
646         bcm43xx_write16(dev, 0x688,
647                         bcm43xx_read16(dev, 0x688) | 0x4);
648
649
650         /*TODO: We might need some stack support here to get the values. */
651 }