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 <m@bues.ch>
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.
31 #include "phy_common.h"
35 static const struct b43_tx_legacy_rate_phy_ctl_entry b43_tx_legacy_rate_phy_ctl[] = {
36 { B43_CCK_RATE_1MB, 0x0, 0x0 },
37 { B43_CCK_RATE_2MB, 0x0, 0x1 },
38 { B43_CCK_RATE_5MB, 0x0, 0x2 },
39 { B43_CCK_RATE_11MB, 0x0, 0x3 },
40 { B43_OFDM_RATE_6MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_BPSK },
41 { B43_OFDM_RATE_9MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_BPSK },
42 { B43_OFDM_RATE_12MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QPSK },
43 { B43_OFDM_RATE_18MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QPSK },
44 { B43_OFDM_RATE_24MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QAM16 },
45 { B43_OFDM_RATE_36MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM16 },
46 { B43_OFDM_RATE_48MB, B43_TXH_PHY1_CRATE_2_3, B43_TXH_PHY1_MODUL_QAM64 },
47 { B43_OFDM_RATE_54MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM64 },
50 static const struct b43_tx_legacy_rate_phy_ctl_entry *
51 b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate)
53 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
56 for (i = 0; i < ARRAY_SIZE(b43_tx_legacy_rate_phy_ctl); i++) {
57 e = &(b43_tx_legacy_rate_phy_ctl[i]);
58 if (e->bitrate == bitrate)
66 /* Extract the bitrate index out of a CCK PLCP header. */
67 static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
69 switch (plcp->raw[0]) {
82 /* Extract the bitrate index out of an OFDM PLCP header. */
83 static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool ghz5)
85 /* For 2 GHz band first OFDM rate is at index 4, see main.c */
86 int base = ghz5 ? 0 : 4;
88 switch (plcp->raw[0] & 0xF) {
109 u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
112 case B43_CCK_RATE_1MB:
114 case B43_CCK_RATE_2MB:
116 case B43_CCK_RATE_5MB:
118 case B43_CCK_RATE_11MB:
125 u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
128 case B43_OFDM_RATE_6MB:
130 case B43_OFDM_RATE_9MB:
132 case B43_OFDM_RATE_12MB:
134 case B43_OFDM_RATE_18MB:
136 case B43_OFDM_RATE_24MB:
138 case B43_OFDM_RATE_36MB:
140 case B43_OFDM_RATE_48MB:
142 case B43_OFDM_RATE_54MB:
149 void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
150 const u16 octets, const u8 bitrate)
152 __u8 *raw = plcp->raw;
154 if (b43_is_ofdm_rate(bitrate)) {
157 d = b43_plcp_get_ratecode_ofdm(bitrate);
158 B43_WARN_ON(octets & 0xF000);
160 plcp->data = cpu_to_le32(d);
164 plen = octets * 16 / bitrate;
165 if ((octets * 16 % bitrate) > 0) {
167 if ((bitrate == B43_CCK_RATE_11MB)
168 && ((octets * 8 % 11) < 4)) {
174 plcp->data |= cpu_to_le32(plen << 16);
175 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
179 /* TODO: verify if needed for SSLPN or LCN */
180 static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate)
182 const struct b43_phy *phy = &dev->phy;
183 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
187 if (phy->type == B43_PHYTYPE_LP)
188 bw = B43_TXH_PHY1_BW_20;
190 bw = B43_TXH_PHY1_BW_20;
192 if (0) { /* FIXME: MIMO */
193 } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) {
197 e = b43_tx_legacy_rate_phy_ctl_ent(bitrate);
199 control |= e->coding_rate;
200 control |= e->modulation;
202 control |= B43_TXH_PHY1_MODE_SISO;
208 static u8 b43_calc_fallback_rate(u8 bitrate, int gmode)
211 case B43_CCK_RATE_1MB:
212 return B43_CCK_RATE_1MB;
213 case B43_CCK_RATE_2MB:
214 return B43_CCK_RATE_1MB;
215 case B43_CCK_RATE_5MB:
216 return B43_CCK_RATE_2MB;
217 case B43_CCK_RATE_11MB:
218 return B43_CCK_RATE_5MB;
220 * Don't just fallback to CCK; it may be in 5GHz operation
221 * and falling back to CCK won't work out very well.
223 case B43_OFDM_RATE_6MB:
225 return B43_CCK_RATE_5MB;
227 return B43_OFDM_RATE_6MB;
228 case B43_OFDM_RATE_9MB:
229 return B43_OFDM_RATE_6MB;
230 case B43_OFDM_RATE_12MB:
231 return B43_OFDM_RATE_9MB;
232 case B43_OFDM_RATE_18MB:
233 return B43_OFDM_RATE_12MB;
234 case B43_OFDM_RATE_24MB:
235 return B43_OFDM_RATE_18MB;
236 case B43_OFDM_RATE_36MB:
237 return B43_OFDM_RATE_24MB;
238 case B43_OFDM_RATE_48MB:
239 return B43_OFDM_RATE_36MB;
240 case B43_OFDM_RATE_54MB:
241 return B43_OFDM_RATE_48MB;
247 /* Generate a TX data header. */
248 int b43_generate_txhdr(struct b43_wldev *dev,
250 struct sk_buff *skb_frag,
251 struct ieee80211_tx_info *info,
254 const unsigned char *fragment_data = skb_frag->data;
255 unsigned int fragment_len = skb_frag->len;
256 struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
257 const struct b43_phy *phy = &dev->phy;
258 const struct ieee80211_hdr *wlhdr =
259 (const struct ieee80211_hdr *)fragment_data;
260 int use_encryption = !!info->control.hw_key;
261 __le16 fctl = wlhdr->frame_control;
262 struct ieee80211_rate *fbrate;
264 int rate_ofdm, rate_fb_ofdm;
265 unsigned int plcp_fragment_len;
268 bool fill_phy_ctl1 = (phy->type == B43_PHYTYPE_LP ||
269 phy->type == B43_PHYTYPE_N ||
270 phy->type == B43_PHYTYPE_HT);
272 struct ieee80211_rate *txrate;
273 struct ieee80211_tx_rate *rates;
275 memset(txhdr, 0, sizeof(*txhdr));
277 txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
278 rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
279 rate_ofdm = b43_is_ofdm_rate(rate);
280 fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
281 rate_fb = fbrate->hw_value;
282 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
285 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
287 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
288 txhdr->mac_frame_ctl = wlhdr->frame_control;
289 memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN);
291 /* Calculate duration for fallback rate */
292 if ((rate_fb == rate) ||
293 (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
294 (wlhdr->duration_id == cpu_to_le16(0))) {
295 /* If the fallback rate equals the normal rate or the
296 * dur_id field contains an AID, CFP magic or 0,
297 * use the original dur_id field. */
298 txhdr->dur_fb = wlhdr->duration_id;
300 txhdr->dur_fb = ieee80211_generic_frame_duration(
301 dev->wl->hw, info->control.vif, info->band,
302 fragment_len, fbrate);
305 plcp_fragment_len = fragment_len + FCS_LEN;
306 if (use_encryption) {
307 u8 key_idx = info->control.hw_key->hw_key_idx;
312 B43_WARN_ON(key_idx >= ARRAY_SIZE(dev->key));
313 key = &(dev->key[key_idx]);
315 if (unlikely(!key->keyconf)) {
316 /* This key is invalid. This might only happen
317 * in a short timeframe after machine resume before
318 * we were able to reconfigure keys.
319 * Drop this packet completely. Do not transmit it
320 * unencrypted to avoid leaking information. */
324 /* Hardware appends ICV. */
325 plcp_fragment_len += info->control.hw_key->icv_len;
327 key_idx = b43_kidx_to_fw(dev, key_idx);
328 mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
330 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
332 wlhdr_len = ieee80211_hdrlen(fctl);
333 if (key->algorithm == B43_SEC_ALGO_TKIP) {
336 /* we give the phase1key and iv16 here, the key is stored in
337 * shm. With that the hardware can do phase 2 and encryption.
339 ieee80211_get_tkip_p1k(info->control.hw_key, skb_frag, phase1key);
340 /* phase1key is in host endian. Copy to little-endian txhdr->iv. */
341 for (i = 0; i < 5; i++) {
342 txhdr->iv[i * 2 + 0] = phase1key[i];
343 txhdr->iv[i * 2 + 1] = phase1key[i] >> 8;
346 memcpy(txhdr->iv + 10, ((u8 *) wlhdr) + wlhdr_len, 3);
348 iv_len = min_t(size_t, info->control.hw_key->iv_len,
349 ARRAY_SIZE(txhdr->iv));
350 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
353 switch (dev->fw.hdr_format) {
355 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_598.plcp),
356 plcp_fragment_len, rate);
359 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_351.plcp),
360 plcp_fragment_len, rate);
363 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_410.plcp),
364 plcp_fragment_len, rate);
367 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
368 plcp_fragment_len, rate_fb);
370 /* Extra Frame Types */
372 extra_ft |= B43_TXH_EFT_FB_OFDM;
374 extra_ft |= B43_TXH_EFT_FB_CCK;
376 /* Set channel radio code. Note that the micrcode ORs 0x100 to
377 * this value before comparing it to the value in SHM, if this
380 txhdr->chan_radio_code = phy->channel;
382 /* PHY TX Control word */
384 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
386 phy_ctl |= B43_TXH_PHY_ENC_CCK;
387 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
388 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
390 switch (b43_ieee80211_antenna_sanitize(dev, 0)) {
391 case 0: /* Default */
392 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
394 case 1: /* Antenna 0 */
395 phy_ctl |= B43_TXH_PHY_ANT0;
397 case 2: /* Antenna 1 */
398 phy_ctl |= B43_TXH_PHY_ANT1;
400 case 3: /* Antenna 2 */
401 phy_ctl |= B43_TXH_PHY_ANT2;
403 case 4: /* Antenna 3 */
404 phy_ctl |= B43_TXH_PHY_ANT3;
410 rates = info->control.rates;
412 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
413 mac_ctl |= B43_TXH_MAC_ACK;
414 /* use hardware sequence counter as the non-TID counter */
415 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
416 mac_ctl |= B43_TXH_MAC_HWSEQ;
417 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
418 mac_ctl |= B43_TXH_MAC_STMSDU;
420 mac_ctl |= B43_TXH_MAC_5GHZ;
422 /* Overwrite rates[0].count to make the retry calculation
423 * in the tx status easier. need the actual retry limit to
424 * detect whether the fallback rate was used.
426 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
427 (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
428 rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
429 mac_ctl |= B43_TXH_MAC_LONGFRAME;
431 rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
434 /* Generate the RTS or CTS-to-self frame */
435 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
436 (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
438 struct ieee80211_hdr *uninitialized_var(hdr);
439 int rts_rate, rts_rate_fb;
440 int rts_rate_ofdm, rts_rate_fb_ofdm;
441 struct b43_plcp_hdr6 *uninitialized_var(plcp);
442 struct ieee80211_rate *rts_cts_rate;
444 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
446 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
447 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
448 rts_rate_fb = b43_calc_fallback_rate(rts_rate, phy->gmode);
449 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
451 if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
452 struct ieee80211_cts *uninitialized_var(cts);
454 switch (dev->fw.hdr_format) {
456 cts = (struct ieee80211_cts *)
457 (txhdr->format_598.rts_frame);
460 cts = (struct ieee80211_cts *)
461 (txhdr->format_351.rts_frame);
464 cts = (struct ieee80211_cts *)
465 (txhdr->format_410.rts_frame);
468 ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
469 fragment_data, fragment_len,
471 mac_ctl |= B43_TXH_MAC_SENDCTS;
472 len = sizeof(struct ieee80211_cts);
474 struct ieee80211_rts *uninitialized_var(rts);
476 switch (dev->fw.hdr_format) {
478 rts = (struct ieee80211_rts *)
479 (txhdr->format_598.rts_frame);
482 rts = (struct ieee80211_rts *)
483 (txhdr->format_351.rts_frame);
486 rts = (struct ieee80211_rts *)
487 (txhdr->format_410.rts_frame);
490 ieee80211_rts_get(dev->wl->hw, info->control.vif,
491 fragment_data, fragment_len,
493 mac_ctl |= B43_TXH_MAC_SENDRTS;
494 len = sizeof(struct ieee80211_rts);
498 /* Generate the PLCP headers for the RTS/CTS frame */
499 switch (dev->fw.hdr_format) {
501 plcp = &txhdr->format_598.rts_plcp;
504 plcp = &txhdr->format_351.rts_plcp;
507 plcp = &txhdr->format_410.rts_plcp;
510 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
512 plcp = &txhdr->rts_plcp_fb;
513 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
516 switch (dev->fw.hdr_format) {
518 hdr = (struct ieee80211_hdr *)
519 (&txhdr->format_598.rts_frame);
522 hdr = (struct ieee80211_hdr *)
523 (&txhdr->format_351.rts_frame);
526 hdr = (struct ieee80211_hdr *)
527 (&txhdr->format_410.rts_frame);
530 txhdr->rts_dur_fb = hdr->duration_id;
533 extra_ft |= B43_TXH_EFT_RTS_OFDM;
534 txhdr->phy_rate_rts =
535 b43_plcp_get_ratecode_ofdm(rts_rate);
537 extra_ft |= B43_TXH_EFT_RTS_CCK;
538 txhdr->phy_rate_rts =
539 b43_plcp_get_ratecode_cck(rts_rate);
541 if (rts_rate_fb_ofdm)
542 extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
544 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
546 if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS &&
548 txhdr->phy_ctl1_rts = cpu_to_le16(
549 b43_generate_tx_phy_ctl1(dev, rts_rate));
550 txhdr->phy_ctl1_rts_fb = cpu_to_le16(
551 b43_generate_tx_phy_ctl1(dev, rts_rate_fb));
556 switch (dev->fw.hdr_format) {
558 txhdr->format_598.cookie = cpu_to_le16(cookie);
561 txhdr->format_351.cookie = cpu_to_le16(cookie);
564 txhdr->format_410.cookie = cpu_to_le16(cookie);
570 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate));
572 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate_fb));
575 /* Apply the bitfields */
576 txhdr->mac_ctl = cpu_to_le32(mac_ctl);
577 txhdr->phy_ctl = cpu_to_le16(phy_ctl);
578 txhdr->extra_ft = extra_ft;
583 static s8 b43_rssi_postprocess(struct b43_wldev *dev,
584 u8 in_rssi, int ofdm,
585 int adjust_2053, int adjust_2050)
587 struct b43_phy *phy = &dev->phy;
588 struct b43_phy_g *gphy = phy->g;
591 switch (phy->radio_ver) {
604 if (dev->dev->bus_sprom->
605 boardflags_lo & B43_BFL_RSSI) {
608 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
609 tmp = gphy->nrssi_lt[in_rssi];
621 if (phy->type == B43_PHYTYPE_G && adjust_2050)
647 static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
649 struct b43_phy *phy = &dev->phy;
652 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
658 void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
660 struct ieee80211_rx_status status;
661 struct b43_plcp_hdr6 *plcp;
662 struct ieee80211_hdr *wlhdr;
663 const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
665 u16 phystat0, phystat3;
666 u16 uninitialized_var(chanstat), uninitialized_var(mactime);
667 u32 uninitialized_var(macstat);
669 int padding, rate_idx;
671 memset(&status, 0, sizeof(status));
673 /* Get metadata about the frame from the header. */
674 phystat0 = le16_to_cpu(rxhdr->phy_status0);
675 phystat3 = le16_to_cpu(rxhdr->phy_status3);
676 switch (dev->fw.hdr_format) {
678 macstat = le32_to_cpu(rxhdr->format_598.mac_status);
679 mactime = le16_to_cpu(rxhdr->format_598.mac_time);
680 chanstat = le16_to_cpu(rxhdr->format_598.channel);
684 macstat = le32_to_cpu(rxhdr->format_351.mac_status);
685 mactime = le16_to_cpu(rxhdr->format_351.mac_time);
686 chanstat = le16_to_cpu(rxhdr->format_351.channel);
690 if (unlikely(macstat & B43_RX_MAC_FCSERR)) {
691 dev->wl->ieee_stats.dot11FCSErrorCount++;
692 status.flag |= RX_FLAG_FAILED_FCS_CRC;
694 if (unlikely(phystat0 & (B43_RX_PHYST0_PLCPHCF | B43_RX_PHYST0_PLCPFV)))
695 status.flag |= RX_FLAG_FAILED_PLCP_CRC;
696 if (phystat0 & B43_RX_PHYST0_SHORTPRMBL)
697 status.enc_flags |= RX_ENC_FLAG_SHORTPRE;
698 if (macstat & B43_RX_MAC_DECERR) {
699 /* Decryption with the given key failed.
700 * Drop the packet. We also won't be able to decrypt it with
701 * the key in software. */
705 /* Skip PLCP and padding */
706 padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
707 if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
708 b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
711 plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
712 skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
713 /* The skb contains the Wireless Header + payload data now */
714 if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
715 b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
718 wlhdr = (struct ieee80211_hdr *)(skb->data);
719 fctl = wlhdr->frame_control;
721 if (macstat & B43_RX_MAC_DEC) {
725 keyidx = ((macstat & B43_RX_MAC_KEYIDX)
726 >> B43_RX_MAC_KEYIDX_SHIFT);
727 /* We must adjust the key index here. We want the "physical"
728 * key index, but the ucode passed it slightly different.
730 keyidx = b43_kidx_to_raw(dev, keyidx);
731 B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
733 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
734 wlhdr_len = ieee80211_hdrlen(fctl);
735 if (unlikely(skb->len < (wlhdr_len + 3))) {
737 "RX: Packet size underrun (3)\n");
740 status.flag |= RX_FLAG_DECRYPTED;
744 /* Link quality statistics */
745 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
747 /* TODO: is max the right choice? */
748 status.signal = max_t(__s8,
749 max(rxhdr->phy_ht_power0, rxhdr->phy_ht_power1),
750 rxhdr->phy_ht_power2);
753 /* Broadcom has code for min and avg, but always uses max */
754 if (rxhdr->power0 == 16 || rxhdr->power0 == 32)
755 status.signal = max(rxhdr->power1, rxhdr->power2);
757 status.signal = max(rxhdr->power0, rxhdr->power1);
762 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
763 (phystat0 & B43_RX_PHYST0_OFDM),
764 (phystat0 & B43_RX_PHYST0_GAINCTL),
765 (phystat3 & B43_RX_PHYST3_TRSTATE));
769 if (phystat0 & B43_RX_PHYST0_OFDM)
770 rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
771 !!(chanstat & B43_RX_CHAN_5GHZ));
773 rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
774 if (unlikely(rate_idx == -1)) {
775 /* PLCP seems to be corrupted.
776 * Drop the frame, if we are not interested in corrupted frames. */
777 if (!(dev->wl->filter_flags & FIF_PLCPFAIL))
780 status.rate_idx = rate_idx;
781 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
784 * All frames on monitor interfaces and beacons always need a full
785 * 64-bit timestamp. Monitor interfaces need it for diagnostic
786 * purposes and beacons for IBSS merging.
787 * This code assumes we get to process the packet within 16 bits
788 * of timestamp, i.e. about 65 milliseconds after the PHY received
791 if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
794 b43_tsf_read(dev, &status.mactime);
795 low_mactime_now = status.mactime;
796 status.mactime = status.mactime & ~0xFFFFULL;
797 status.mactime += mactime;
798 if (low_mactime_now <= mactime)
799 status.mactime -= 0x10000;
800 status.flag |= RX_FLAG_MACTIME_START;
803 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
804 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
806 status.band = NL80211_BAND_2GHZ;
807 /* Somewhere between 478.104 and 508.1084 firmware for G-PHY
808 * has been modified to be compatible with N-PHY and others.
810 if (dev->fw.rev >= 508)
811 status.freq = ieee80211_channel_to_frequency(chanid, status.band);
813 status.freq = chanid + 2400;
818 /* chanid is the SHM channel cookie. Which is the plain
819 * channel number in b43. */
820 if (chanstat & B43_RX_CHAN_5GHZ)
821 status.band = NL80211_BAND_5GHZ;
823 status.band = NL80211_BAND_2GHZ;
825 ieee80211_channel_to_frequency(chanid, status.band);
832 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
833 ieee80211_rx_ni(dev->wl->hw, skb);
840 dev_kfree_skb_any(skb);
843 void b43_handle_txstatus(struct b43_wldev *dev,
844 const struct b43_txstatus *status)
846 b43_debugfs_log_txstat(dev, status);
848 if (status->intermediate)
850 if (status->for_ampdu)
853 dev->wl->ieee_stats.dot11ACKFailureCount++;
854 if (status->rts_count) {
855 if (status->rts_count == 0xF) //FIXME
856 dev->wl->ieee_stats.dot11RTSFailureCount++;
858 dev->wl->ieee_stats.dot11RTSSuccessCount++;
861 if (b43_using_pio_transfers(dev))
862 b43_pio_handle_txstatus(dev, status);
864 b43_dma_handle_txstatus(dev, status);
866 b43_phy_txpower_check(dev, 0);
869 /* Fill out the mac80211 TXstatus report based on the b43-specific
870 * txstatus report data. This returns a boolean whether the frame was
871 * successfully transmitted. */
872 bool b43_fill_txstatus_report(struct b43_wldev *dev,
873 struct ieee80211_tx_info *report,
874 const struct b43_txstatus *status)
876 bool frame_success = true;
879 /* preserve the confiured retry limit before clearing the status
880 * The xmit function has overwritten the rc's value with the actual
881 * retry limit done by the hardware */
882 retry_limit = report->status.rates[0].count;
883 ieee80211_tx_info_clear_status(report);
886 /* The frame was ACKed. */
887 report->flags |= IEEE80211_TX_STAT_ACK;
889 /* The frame was not ACKed... */
890 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
891 /* ...but we expected an ACK. */
892 frame_success = false;
895 if (status->frame_count == 0) {
896 /* The frame was not transmitted at all. */
897 report->status.rates[0].count = 0;
898 } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
900 * If the short retries (RTS, not data frame) have exceeded
901 * the limit, the hw will not have tried the selected rate,
902 * but will have used the fallback rate instead.
903 * Don't let the rate control count attempts for the selected
904 * rate in this case, otherwise the statistics will be off.
906 report->status.rates[0].count = 0;
907 report->status.rates[1].count = status->frame_count;
909 if (status->frame_count > retry_limit) {
910 report->status.rates[0].count = retry_limit;
911 report->status.rates[1].count = status->frame_count -
915 report->status.rates[0].count = status->frame_count;
916 report->status.rates[1].idx = -1;
920 return frame_success;
923 /* Stop any TX operation on the device (suspend the hardware queues) */
924 void b43_tx_suspend(struct b43_wldev *dev)
926 if (b43_using_pio_transfers(dev))
927 b43_pio_tx_suspend(dev);
929 b43_dma_tx_suspend(dev);
932 /* Resume any TX operation on the device (resume the hardware queues) */
933 void b43_tx_resume(struct b43_wldev *dev)
935 if (b43_using_pio_transfers(dev))
936 b43_pio_tx_resume(dev);
938 b43_dma_tx_resume(dev);