CRIS: Move common Kconfig variable ETRAX_RTC to arch independet Kconfig.
[wrt350n-kernel.git] / drivers / net / wireless / b43 / xmit.c
blob7caa26eb410588a8b4de1a03328141db52888787
1 /*
3 Broadcom B43 wireless driver
5 Transmission (TX/RX) related functions.
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>
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.
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.
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.
30 #include "xmit.h"
31 #include "phy.h"
32 #include "dma.h"
35 /* Extract the bitrate out of a CCK PLCP header. */
36 static u8 b43_plcp_get_bitrate_cck(struct b43_plcp_hdr6 *plcp)
38 switch (plcp->raw[0]) {
39 case 0x0A:
40 return B43_CCK_RATE_1MB;
41 case 0x14:
42 return B43_CCK_RATE_2MB;
43 case 0x37:
44 return B43_CCK_RATE_5MB;
45 case 0x6E:
46 return B43_CCK_RATE_11MB;
48 B43_WARN_ON(1);
49 return 0;
52 /* Extract the bitrate out of an OFDM PLCP header. */
53 static u8 b43_plcp_get_bitrate_ofdm(struct b43_plcp_hdr6 *plcp)
55 switch (plcp->raw[0] & 0xF) {
56 case 0xB:
57 return B43_OFDM_RATE_6MB;
58 case 0xF:
59 return B43_OFDM_RATE_9MB;
60 case 0xA:
61 return B43_OFDM_RATE_12MB;
62 case 0xE:
63 return B43_OFDM_RATE_18MB;
64 case 0x9:
65 return B43_OFDM_RATE_24MB;
66 case 0xD:
67 return B43_OFDM_RATE_36MB;
68 case 0x8:
69 return B43_OFDM_RATE_48MB;
70 case 0xC:
71 return B43_OFDM_RATE_54MB;
73 B43_WARN_ON(1);
74 return 0;
77 u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
79 switch (bitrate) {
80 case B43_CCK_RATE_1MB:
81 return 0x0A;
82 case B43_CCK_RATE_2MB:
83 return 0x14;
84 case B43_CCK_RATE_5MB:
85 return 0x37;
86 case B43_CCK_RATE_11MB:
87 return 0x6E;
89 B43_WARN_ON(1);
90 return 0;
93 u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
95 switch (bitrate) {
96 case B43_OFDM_RATE_6MB:
97 return 0xB;
98 case B43_OFDM_RATE_9MB:
99 return 0xF;
100 case B43_OFDM_RATE_12MB:
101 return 0xA;
102 case B43_OFDM_RATE_18MB:
103 return 0xE;
104 case B43_OFDM_RATE_24MB:
105 return 0x9;
106 case B43_OFDM_RATE_36MB:
107 return 0xD;
108 case B43_OFDM_RATE_48MB:
109 return 0x8;
110 case B43_OFDM_RATE_54MB:
111 return 0xC;
113 B43_WARN_ON(1);
114 return 0;
117 void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
118 const u16 octets, const u8 bitrate)
120 __le32 *data = &(plcp->data);
121 __u8 *raw = plcp->raw;
123 if (b43_is_ofdm_rate(bitrate)) {
124 u32 d;
126 d = b43_plcp_get_ratecode_ofdm(bitrate);
127 B43_WARN_ON(octets & 0xF000);
128 d |= (octets << 5);
129 *data = cpu_to_le32(d);
130 } else {
131 u32 plen;
133 plen = octets * 16 / bitrate;
134 if ((octets * 16 % bitrate) > 0) {
135 plen++;
136 if ((bitrate == B43_CCK_RATE_11MB)
137 && ((octets * 8 % 11) < 4)) {
138 raw[1] = 0x84;
139 } else
140 raw[1] = 0x04;
141 } else
142 raw[1] = 0x04;
143 *data |= cpu_to_le32(plen << 16);
144 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
148 static u8 b43_calc_fallback_rate(u8 bitrate)
150 switch (bitrate) {
151 case B43_CCK_RATE_1MB:
152 return B43_CCK_RATE_1MB;
153 case B43_CCK_RATE_2MB:
154 return B43_CCK_RATE_1MB;
155 case B43_CCK_RATE_5MB:
156 return B43_CCK_RATE_2MB;
157 case B43_CCK_RATE_11MB:
158 return B43_CCK_RATE_5MB;
159 case B43_OFDM_RATE_6MB:
160 return B43_CCK_RATE_5MB;
161 case B43_OFDM_RATE_9MB:
162 return B43_OFDM_RATE_6MB;
163 case B43_OFDM_RATE_12MB:
164 return B43_OFDM_RATE_9MB;
165 case B43_OFDM_RATE_18MB:
166 return B43_OFDM_RATE_12MB;
167 case B43_OFDM_RATE_24MB:
168 return B43_OFDM_RATE_18MB;
169 case B43_OFDM_RATE_36MB:
170 return B43_OFDM_RATE_24MB;
171 case B43_OFDM_RATE_48MB:
172 return B43_OFDM_RATE_36MB;
173 case B43_OFDM_RATE_54MB:
174 return B43_OFDM_RATE_48MB;
176 B43_WARN_ON(1);
177 return 0;
180 /* Generate a TX data header. */
181 int b43_generate_txhdr(struct b43_wldev *dev,
182 u8 *_txhdr,
183 const unsigned char *fragment_data,
184 unsigned int fragment_len,
185 const struct ieee80211_tx_control *txctl,
186 u16 cookie)
188 struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
189 const struct b43_phy *phy = &dev->phy;
190 const struct ieee80211_hdr *wlhdr =
191 (const struct ieee80211_hdr *)fragment_data;
192 int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
193 u16 fctl = le16_to_cpu(wlhdr->frame_control);
194 u8 rate, rate_fb;
195 int rate_ofdm, rate_fb_ofdm;
196 unsigned int plcp_fragment_len;
197 u32 mac_ctl = 0;
198 u16 phy_ctl = 0;
199 u8 extra_ft = 0;
201 memset(txhdr, 0, sizeof(*txhdr));
203 rate = txctl->tx_rate;
204 rate_ofdm = b43_is_ofdm_rate(rate);
205 rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate;
206 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
208 if (rate_ofdm)
209 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
210 else
211 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
212 txhdr->mac_frame_ctl = wlhdr->frame_control;
213 memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
215 /* Calculate duration for fallback rate */
216 if ((rate_fb == rate) ||
217 (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
218 (wlhdr->duration_id == cpu_to_le16(0))) {
219 /* If the fallback rate equals the normal rate or the
220 * dur_id field contains an AID, CFP magic or 0,
221 * use the original dur_id field. */
222 txhdr->dur_fb = wlhdr->duration_id;
223 } else {
224 int fbrate_base100kbps = B43_RATE_TO_BASE100KBPS(rate_fb);
225 txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
226 txctl->vif,
227 fragment_len,
228 fbrate_base100kbps);
231 plcp_fragment_len = fragment_len + FCS_LEN;
232 if (use_encryption) {
233 u8 key_idx = (u16) (txctl->key_idx);
234 struct b43_key *key;
235 int wlhdr_len;
236 size_t iv_len;
238 B43_WARN_ON(key_idx >= dev->max_nr_keys);
239 key = &(dev->key[key_idx]);
241 if (unlikely(!key->keyconf)) {
242 /* This key is invalid. This might only happen
243 * in a short timeframe after machine resume before
244 * we were able to reconfigure keys.
245 * Drop this packet completely. Do not transmit it
246 * unencrypted to avoid leaking information. */
247 return -ENOKEY;
250 /* Hardware appends ICV. */
251 plcp_fragment_len += txctl->icv_len;
253 key_idx = b43_kidx_to_fw(dev, key_idx);
254 mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
255 B43_TXH_MAC_KEYIDX;
256 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
257 B43_TXH_MAC_KEYALG;
258 wlhdr_len = ieee80211_get_hdrlen(fctl);
259 iv_len = min((size_t) txctl->iv_len,
260 ARRAY_SIZE(txhdr->iv));
261 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
263 if (b43_is_old_txhdr_format(dev)) {
264 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
265 plcp_fragment_len, rate);
266 } else {
267 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
268 plcp_fragment_len, rate);
270 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
271 plcp_fragment_len, rate_fb);
273 /* Extra Frame Types */
274 if (rate_fb_ofdm)
275 extra_ft |= B43_TXH_EFT_FB_OFDM;
276 else
277 extra_ft |= B43_TXH_EFT_FB_CCK;
279 /* Set channel radio code. Note that the micrcode ORs 0x100 to
280 * this value before comparing it to the value in SHM, if this
281 * is a 5Ghz packet.
283 txhdr->chan_radio_code = phy->channel;
285 /* PHY TX Control word */
286 if (rate_ofdm)
287 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
288 else
289 phy_ctl |= B43_TXH_PHY_ENC_CCK;
290 if (dev->short_preamble)
291 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
293 switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) {
294 case 0: /* Default */
295 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
296 break;
297 case 1: /* Antenna 0 */
298 phy_ctl |= B43_TXH_PHY_ANT0;
299 break;
300 case 2: /* Antenna 1 */
301 phy_ctl |= B43_TXH_PHY_ANT1;
302 break;
303 case 3: /* Antenna 2 */
304 phy_ctl |= B43_TXH_PHY_ANT2;
305 break;
306 case 4: /* Antenna 3 */
307 phy_ctl |= B43_TXH_PHY_ANT3;
308 break;
309 default:
310 B43_WARN_ON(1);
313 /* MAC control */
314 if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
315 mac_ctl |= B43_TXH_MAC_ACK;
316 if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
317 ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
318 mac_ctl |= B43_TXH_MAC_HWSEQ;
319 if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
320 mac_ctl |= B43_TXH_MAC_STMSDU;
321 if (phy->type == B43_PHYTYPE_A)
322 mac_ctl |= B43_TXH_MAC_5GHZ;
323 if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
324 mac_ctl |= B43_TXH_MAC_LONGFRAME;
326 /* Generate the RTS or CTS-to-self frame */
327 if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
328 (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
329 unsigned int len;
330 struct ieee80211_hdr *hdr;
331 int rts_rate, rts_rate_fb;
332 int rts_rate_ofdm, rts_rate_fb_ofdm;
333 struct b43_plcp_hdr6 *plcp;
335 rts_rate = txctl->rts_cts_rate;
336 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
337 rts_rate_fb = b43_calc_fallback_rate(rts_rate);
338 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
340 if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
341 struct ieee80211_cts *cts;
343 if (b43_is_old_txhdr_format(dev)) {
344 cts = (struct ieee80211_cts *)
345 (txhdr->old_format.rts_frame);
346 } else {
347 cts = (struct ieee80211_cts *)
348 (txhdr->new_format.rts_frame);
350 ieee80211_ctstoself_get(dev->wl->hw, txctl->vif,
351 fragment_data, fragment_len,
352 txctl, cts);
353 mac_ctl |= B43_TXH_MAC_SENDCTS;
354 len = sizeof(struct ieee80211_cts);
355 } else {
356 struct ieee80211_rts *rts;
358 if (b43_is_old_txhdr_format(dev)) {
359 rts = (struct ieee80211_rts *)
360 (txhdr->old_format.rts_frame);
361 } else {
362 rts = (struct ieee80211_rts *)
363 (txhdr->new_format.rts_frame);
365 ieee80211_rts_get(dev->wl->hw, txctl->vif,
366 fragment_data, fragment_len,
367 txctl, rts);
368 mac_ctl |= B43_TXH_MAC_SENDRTS;
369 len = sizeof(struct ieee80211_rts);
371 len += FCS_LEN;
373 /* Generate the PLCP headers for the RTS/CTS frame */
374 if (b43_is_old_txhdr_format(dev))
375 plcp = &txhdr->old_format.rts_plcp;
376 else
377 plcp = &txhdr->new_format.rts_plcp;
378 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
379 len, rts_rate);
380 plcp = &txhdr->rts_plcp_fb;
381 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
382 len, rts_rate_fb);
384 if (b43_is_old_txhdr_format(dev)) {
385 hdr = (struct ieee80211_hdr *)
386 (&txhdr->old_format.rts_frame);
387 } else {
388 hdr = (struct ieee80211_hdr *)
389 (&txhdr->new_format.rts_frame);
391 txhdr->rts_dur_fb = hdr->duration_id;
393 if (rts_rate_ofdm) {
394 extra_ft |= B43_TXH_EFT_RTS_OFDM;
395 txhdr->phy_rate_rts =
396 b43_plcp_get_ratecode_ofdm(rts_rate);
397 } else {
398 extra_ft |= B43_TXH_EFT_RTS_CCK;
399 txhdr->phy_rate_rts =
400 b43_plcp_get_ratecode_cck(rts_rate);
402 if (rts_rate_fb_ofdm)
403 extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
404 else
405 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
408 /* Magic cookie */
409 if (b43_is_old_txhdr_format(dev))
410 txhdr->old_format.cookie = cpu_to_le16(cookie);
411 else
412 txhdr->new_format.cookie = cpu_to_le16(cookie);
414 /* Apply the bitfields */
415 txhdr->mac_ctl = cpu_to_le32(mac_ctl);
416 txhdr->phy_ctl = cpu_to_le16(phy_ctl);
417 txhdr->extra_ft = extra_ft;
419 return 0;
422 static s8 b43_rssi_postprocess(struct b43_wldev *dev,
423 u8 in_rssi, int ofdm,
424 int adjust_2053, int adjust_2050)
426 struct b43_phy *phy = &dev->phy;
427 s32 tmp;
429 switch (phy->radio_ver) {
430 case 0x2050:
431 if (ofdm) {
432 tmp = in_rssi;
433 if (tmp > 127)
434 tmp -= 256;
435 tmp *= 73;
436 tmp /= 64;
437 if (adjust_2050)
438 tmp += 25;
439 else
440 tmp -= 3;
441 } else {
442 if (dev->dev->bus->sprom.
443 boardflags_lo & B43_BFL_RSSI) {
444 if (in_rssi > 63)
445 in_rssi = 63;
446 tmp = phy->nrssi_lt[in_rssi];
447 tmp = 31 - tmp;
448 tmp *= -131;
449 tmp /= 128;
450 tmp -= 57;
451 } else {
452 tmp = in_rssi;
453 tmp = 31 - tmp;
454 tmp *= -149;
455 tmp /= 128;
456 tmp -= 68;
458 if (phy->type == B43_PHYTYPE_G && adjust_2050)
459 tmp += 25;
461 break;
462 case 0x2060:
463 if (in_rssi > 127)
464 tmp = in_rssi - 256;
465 else
466 tmp = in_rssi;
467 break;
468 default:
469 tmp = in_rssi;
470 tmp -= 11;
471 tmp *= 103;
472 tmp /= 64;
473 if (adjust_2053)
474 tmp -= 109;
475 else
476 tmp -= 83;
479 return (s8) tmp;
482 //TODO
483 #if 0
484 static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
486 struct b43_phy *phy = &dev->phy;
487 s8 ret;
489 if (phy->type == B43_PHYTYPE_A) {
490 //TODO: Incomplete specs.
491 ret = 0;
492 } else
493 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
495 return ret;
497 #endif
499 void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
501 struct ieee80211_rx_status status;
502 struct b43_plcp_hdr6 *plcp;
503 struct ieee80211_hdr *wlhdr;
504 const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
505 u16 fctl;
506 u16 phystat0, phystat3, chanstat, mactime;
507 u32 macstat;
508 u16 chanid;
509 u8 jssi;
510 int padding;
512 memset(&status, 0, sizeof(status));
514 /* Get metadata about the frame from the header. */
515 phystat0 = le16_to_cpu(rxhdr->phy_status0);
516 phystat3 = le16_to_cpu(rxhdr->phy_status3);
517 jssi = rxhdr->jssi;
518 macstat = le32_to_cpu(rxhdr->mac_status);
519 mactime = le16_to_cpu(rxhdr->mac_time);
520 chanstat = le16_to_cpu(rxhdr->channel);
522 if (macstat & B43_RX_MAC_FCSERR)
523 dev->wl->ieee_stats.dot11FCSErrorCount++;
524 if (macstat & B43_RX_MAC_DECERR) {
525 /* Decryption with the given key failed.
526 * Drop the packet. We also won't be able to decrypt it with
527 * the key in software. */
528 goto drop;
531 /* Skip PLCP and padding */
532 padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
533 if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
534 b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
535 goto drop;
537 plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
538 skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
539 /* The skb contains the Wireless Header + payload data now */
540 if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
541 b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
542 goto drop;
544 wlhdr = (struct ieee80211_hdr *)(skb->data);
545 fctl = le16_to_cpu(wlhdr->frame_control);
547 if (macstat & B43_RX_MAC_DEC) {
548 unsigned int keyidx;
549 int wlhdr_len;
551 keyidx = ((macstat & B43_RX_MAC_KEYIDX)
552 >> B43_RX_MAC_KEYIDX_SHIFT);
553 /* We must adjust the key index here. We want the "physical"
554 * key index, but the ucode passed it slightly different.
556 keyidx = b43_kidx_to_raw(dev, keyidx);
557 B43_WARN_ON(keyidx >= dev->max_nr_keys);
559 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
560 wlhdr_len = ieee80211_get_hdrlen(fctl);
561 if (unlikely(skb->len < (wlhdr_len + 3))) {
562 b43dbg(dev->wl,
563 "RX: Packet size underrun (3)\n");
564 goto drop;
566 status.flag |= RX_FLAG_DECRYPTED;
570 status.ssi = b43_rssi_postprocess(dev, jssi,
571 (phystat0 & B43_RX_PHYST0_OFDM),
572 (phystat0 & B43_RX_PHYST0_GAINCTL),
573 (phystat3 & B43_RX_PHYST3_TRSTATE));
574 status.noise = dev->stats.link_noise;
575 /* the next line looks wrong, but is what mac80211 wants */
576 status.signal = (jssi * 100) / B43_RX_MAX_SSI;
577 if (phystat0 & B43_RX_PHYST0_OFDM)
578 status.rate = b43_plcp_get_bitrate_ofdm(plcp);
579 else
580 status.rate = b43_plcp_get_bitrate_cck(plcp);
581 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
584 * If monitors are present get full 64-bit timestamp. This
585 * code assumes we get to process the packet within 16 bits
586 * of timestamp, i.e. about 65 milliseconds after the PHY
587 * received the first symbol.
589 if (dev->wl->radiotap_enabled) {
590 u16 low_mactime_now;
592 b43_tsf_read(dev, &status.mactime);
593 low_mactime_now = status.mactime;
594 status.mactime = status.mactime & ~0xFFFFULL;
595 status.mactime += mactime;
596 if (low_mactime_now <= mactime)
597 status.mactime -= 0x10000;
598 status.flag |= RX_FLAG_TSFT;
601 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
602 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
603 case B43_PHYTYPE_A:
604 status.phymode = MODE_IEEE80211A;
605 B43_WARN_ON(1);
606 /* FIXME: We don't really know which value the "chanid" contains.
607 * So the following assignment might be wrong. */
608 status.channel = chanid;
609 status.freq = b43_channel_to_freq_5ghz(status.channel);
610 break;
611 case B43_PHYTYPE_G:
612 status.phymode = MODE_IEEE80211G;
613 /* chanid is the radio channel cookie value as used
614 * to tune the radio. */
615 status.freq = chanid + 2400;
616 status.channel = b43_freq_to_channel_2ghz(status.freq);
617 break;
618 case B43_PHYTYPE_N:
619 status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
620 /* chanid is the SHM channel cookie. Which is the plain
621 * channel number in b43. */
622 status.channel = chanid;
623 if (chanstat & B43_RX_CHAN_5GHZ)
624 status.freq = b43_freq_to_channel_5ghz(status.freq);
625 else
626 status.freq = b43_freq_to_channel_2ghz(status.freq);
627 break;
628 default:
629 B43_WARN_ON(1);
630 goto drop;
633 dev->stats.last_rx = jiffies;
634 ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
636 return;
637 drop:
638 b43dbg(dev->wl, "RX: Packet dropped\n");
639 dev_kfree_skb_any(skb);
642 void b43_handle_txstatus(struct b43_wldev *dev,
643 const struct b43_txstatus *status)
645 b43_debugfs_log_txstat(dev, status);
647 if (status->intermediate)
648 return;
649 if (status->for_ampdu)
650 return;
651 if (!status->acked)
652 dev->wl->ieee_stats.dot11ACKFailureCount++;
653 if (status->rts_count) {
654 if (status->rts_count == 0xF) //FIXME
655 dev->wl->ieee_stats.dot11RTSFailureCount++;
656 else
657 dev->wl->ieee_stats.dot11RTSSuccessCount++;
660 b43_dma_handle_txstatus(dev, status);
663 /* Handle TX status report as received through DMA/PIO queues */
664 void b43_handle_hwtxstatus(struct b43_wldev *dev,
665 const struct b43_hwtxstatus *hw)
667 struct b43_txstatus status;
668 u8 tmp;
670 status.cookie = le16_to_cpu(hw->cookie);
671 status.seq = le16_to_cpu(hw->seq);
672 status.phy_stat = hw->phy_stat;
673 tmp = hw->count;
674 status.frame_count = (tmp >> 4);
675 status.rts_count = (tmp & 0x0F);
676 tmp = hw->flags;
677 status.supp_reason = ((tmp & 0x1C) >> 2);
678 status.pm_indicated = !!(tmp & 0x80);
679 status.intermediate = !!(tmp & 0x40);
680 status.for_ampdu = !!(tmp & 0x20);
681 status.acked = !!(tmp & 0x02);
683 b43_handle_txstatus(dev, &status);
686 /* Stop any TX operation on the device (suspend the hardware queues) */
687 void b43_tx_suspend(struct b43_wldev *dev)
689 b43_dma_tx_suspend(dev);
692 /* Resume any TX operation on the device (resume the hardware queues) */
693 void b43_tx_resume(struct b43_wldev *dev)
695 b43_dma_tx_resume(dev);
698 #if 0
699 static void upload_qos_parms(struct b43_wldev *dev,
700 const u16 * parms, u16 offset)
702 int i;
704 for (i = 0; i < B43_NR_QOSPARMS; i++) {
705 b43_shm_write16(dev, B43_SHM_SHARED,
706 offset + (i * 2), parms[i]);
709 #endif
711 /* Initialize the QoS parameters */
712 void b43_qos_init(struct b43_wldev *dev)
714 /* FIXME: This function must probably be called from the mac80211
715 * config callback. */
716 return;
718 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
719 //FIXME kill magic
720 b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
722 /*TODO: We might need some stack support here to get the values. */