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 aphy
)
85 int base
= aphy
? 0 : 4;
87 switch (plcp
->raw
[0] & 0xF) {
108 u8
b43_plcp_get_ratecode_cck(const u8 bitrate
)
111 case B43_CCK_RATE_1MB
:
113 case B43_CCK_RATE_2MB
:
115 case B43_CCK_RATE_5MB
:
117 case B43_CCK_RATE_11MB
:
124 u8
b43_plcp_get_ratecode_ofdm(const u8 bitrate
)
127 case B43_OFDM_RATE_6MB
:
129 case B43_OFDM_RATE_9MB
:
131 case B43_OFDM_RATE_12MB
:
133 case B43_OFDM_RATE_18MB
:
135 case B43_OFDM_RATE_24MB
:
137 case B43_OFDM_RATE_36MB
:
139 case B43_OFDM_RATE_48MB
:
141 case B43_OFDM_RATE_54MB
:
148 void b43_generate_plcp_hdr(struct b43_plcp_hdr4
*plcp
,
149 const u16 octets
, const u8 bitrate
)
151 __u8
*raw
= plcp
->raw
;
153 if (b43_is_ofdm_rate(bitrate
)) {
156 d
= b43_plcp_get_ratecode_ofdm(bitrate
);
157 B43_WARN_ON(octets
& 0xF000);
159 plcp
->data
= cpu_to_le32(d
);
163 plen
= octets
* 16 / bitrate
;
164 if ((octets
* 16 % bitrate
) > 0) {
166 if ((bitrate
== B43_CCK_RATE_11MB
)
167 && ((octets
* 8 % 11) < 4)) {
173 plcp
->data
|= cpu_to_le32(plen
<< 16);
174 raw
[0] = b43_plcp_get_ratecode_cck(bitrate
);
178 static u16
b43_generate_tx_phy_ctl1(struct b43_wldev
*dev
, u8 bitrate
)
180 const struct b43_phy
*phy
= &dev
->phy
;
181 const struct b43_tx_legacy_rate_phy_ctl_entry
*e
;
185 if (phy
->type
== B43_PHYTYPE_LP
)
186 bw
= B43_TXH_PHY1_BW_20
;
188 bw
= B43_TXH_PHY1_BW_20
;
190 if (0) { /* FIXME: MIMO */
191 } else if (b43_is_cck_rate(bitrate
) && phy
->type
!= B43_PHYTYPE_LP
) {
195 e
= b43_tx_legacy_rate_phy_ctl_ent(bitrate
);
197 control
|= e
->coding_rate
;
198 control
|= e
->modulation
;
200 control
|= B43_TXH_PHY1_MODE_SISO
;
206 static u8
b43_calc_fallback_rate(u8 bitrate
)
209 case B43_CCK_RATE_1MB
:
210 return B43_CCK_RATE_1MB
;
211 case B43_CCK_RATE_2MB
:
212 return B43_CCK_RATE_1MB
;
213 case B43_CCK_RATE_5MB
:
214 return B43_CCK_RATE_2MB
;
215 case B43_CCK_RATE_11MB
:
216 return B43_CCK_RATE_5MB
;
217 case B43_OFDM_RATE_6MB
:
218 return B43_CCK_RATE_5MB
;
219 case B43_OFDM_RATE_9MB
:
220 return B43_OFDM_RATE_6MB
;
221 case B43_OFDM_RATE_12MB
:
222 return B43_OFDM_RATE_9MB
;
223 case B43_OFDM_RATE_18MB
:
224 return B43_OFDM_RATE_12MB
;
225 case B43_OFDM_RATE_24MB
:
226 return B43_OFDM_RATE_18MB
;
227 case B43_OFDM_RATE_36MB
:
228 return B43_OFDM_RATE_24MB
;
229 case B43_OFDM_RATE_48MB
:
230 return B43_OFDM_RATE_36MB
;
231 case B43_OFDM_RATE_54MB
:
232 return B43_OFDM_RATE_48MB
;
238 /* Generate a TX data header. */
239 int b43_generate_txhdr(struct b43_wldev
*dev
,
241 struct sk_buff
*skb_frag
,
242 struct ieee80211_tx_info
*info
,
245 const unsigned char *fragment_data
= skb_frag
->data
;
246 unsigned int fragment_len
= skb_frag
->len
;
247 struct b43_txhdr
*txhdr
= (struct b43_txhdr
*)_txhdr
;
248 const struct b43_phy
*phy
= &dev
->phy
;
249 const struct ieee80211_hdr
*wlhdr
=
250 (const struct ieee80211_hdr
*)fragment_data
;
251 int use_encryption
= !!info
->control
.hw_key
;
252 __le16 fctl
= wlhdr
->frame_control
;
253 struct ieee80211_rate
*fbrate
;
255 int rate_ofdm
, rate_fb_ofdm
;
256 unsigned int plcp_fragment_len
;
260 struct ieee80211_rate
*txrate
;
261 struct ieee80211_tx_rate
*rates
;
263 memset(txhdr
, 0, sizeof(*txhdr
));
265 txrate
= ieee80211_get_tx_rate(dev
->wl
->hw
, info
);
266 rate
= txrate
? txrate
->hw_value
: B43_CCK_RATE_1MB
;
267 rate_ofdm
= b43_is_ofdm_rate(rate
);
268 fbrate
= ieee80211_get_alt_retry_rate(dev
->wl
->hw
, info
, 0) ? : txrate
;
269 rate_fb
= fbrate
->hw_value
;
270 rate_fb_ofdm
= b43_is_ofdm_rate(rate_fb
);
273 txhdr
->phy_rate
= b43_plcp_get_ratecode_ofdm(rate
);
275 txhdr
->phy_rate
= b43_plcp_get_ratecode_cck(rate
);
276 txhdr
->mac_frame_ctl
= wlhdr
->frame_control
;
277 memcpy(txhdr
->tx_receiver
, wlhdr
->addr1
, 6);
279 /* Calculate duration for fallback rate */
280 if ((rate_fb
== rate
) ||
281 (wlhdr
->duration_id
& cpu_to_le16(0x8000)) ||
282 (wlhdr
->duration_id
== cpu_to_le16(0))) {
283 /* If the fallback rate equals the normal rate or the
284 * dur_id field contains an AID, CFP magic or 0,
285 * use the original dur_id field. */
286 txhdr
->dur_fb
= wlhdr
->duration_id
;
288 txhdr
->dur_fb
= ieee80211_generic_frame_duration(
289 dev
->wl
->hw
, info
->control
.vif
, fragment_len
, fbrate
);
292 plcp_fragment_len
= fragment_len
+ FCS_LEN
;
293 if (use_encryption
) {
294 u8 key_idx
= info
->control
.hw_key
->hw_key_idx
;
299 B43_WARN_ON(key_idx
>= ARRAY_SIZE(dev
->key
));
300 key
= &(dev
->key
[key_idx
]);
302 if (unlikely(!key
->keyconf
)) {
303 /* This key is invalid. This might only happen
304 * in a short timeframe after machine resume before
305 * we were able to reconfigure keys.
306 * Drop this packet completely. Do not transmit it
307 * unencrypted to avoid leaking information. */
311 /* Hardware appends ICV. */
312 plcp_fragment_len
+= info
->control
.hw_key
->icv_len
;
314 key_idx
= b43_kidx_to_fw(dev
, key_idx
);
315 mac_ctl
|= (key_idx
<< B43_TXH_MAC_KEYIDX_SHIFT
) &
317 mac_ctl
|= (key
->algorithm
<< B43_TXH_MAC_KEYALG_SHIFT
) &
319 wlhdr_len
= ieee80211_hdrlen(fctl
);
320 if (key
->algorithm
== B43_SEC_ALGO_TKIP
) {
323 /* we give the phase1key and iv16 here, the key is stored in
324 * shm. With that the hardware can do phase 2 and encryption.
326 ieee80211_get_tkip_p1k(info
->control
.hw_key
, skb_frag
, phase1key
);
327 /* phase1key is in host endian. Copy to little-endian txhdr->iv. */
328 for (i
= 0; i
< 5; i
++) {
329 txhdr
->iv
[i
* 2 + 0] = phase1key
[i
];
330 txhdr
->iv
[i
* 2 + 1] = phase1key
[i
] >> 8;
333 memcpy(txhdr
->iv
+ 10, ((u8
*) wlhdr
) + wlhdr_len
, 3);
335 iv_len
= min((size_t) info
->control
.hw_key
->iv_len
,
336 ARRAY_SIZE(txhdr
->iv
));
337 memcpy(txhdr
->iv
, ((u8
*) wlhdr
) + wlhdr_len
, iv_len
);
340 switch (dev
->fw
.hdr_format
) {
342 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->format_351
.plcp
),
343 plcp_fragment_len
, rate
);
346 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->format_410
.plcp
),
347 plcp_fragment_len
, rate
);
350 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->plcp_fb
),
351 plcp_fragment_len
, rate_fb
);
353 /* Extra Frame Types */
355 extra_ft
|= B43_TXH_EFT_FB_OFDM
;
357 extra_ft
|= B43_TXH_EFT_FB_CCK
;
359 /* Set channel radio code. Note that the micrcode ORs 0x100 to
360 * this value before comparing it to the value in SHM, if this
363 txhdr
->chan_radio_code
= phy
->channel
;
365 /* PHY TX Control word */
367 phy_ctl
|= B43_TXH_PHY_ENC_OFDM
;
369 phy_ctl
|= B43_TXH_PHY_ENC_CCK
;
370 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
371 phy_ctl
|= B43_TXH_PHY_SHORTPRMBL
;
373 switch (b43_ieee80211_antenna_sanitize(dev
, info
->antenna_sel_tx
)) {
374 case 0: /* Default */
375 phy_ctl
|= B43_TXH_PHY_ANT01AUTO
;
377 case 1: /* Antenna 0 */
378 phy_ctl
|= B43_TXH_PHY_ANT0
;
380 case 2: /* Antenna 1 */
381 phy_ctl
|= B43_TXH_PHY_ANT1
;
383 case 3: /* Antenna 2 */
384 phy_ctl
|= B43_TXH_PHY_ANT2
;
386 case 4: /* Antenna 3 */
387 phy_ctl
|= B43_TXH_PHY_ANT3
;
393 rates
= info
->control
.rates
;
395 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
396 mac_ctl
|= B43_TXH_MAC_ACK
;
397 /* use hardware sequence counter as the non-TID counter */
398 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
)
399 mac_ctl
|= B43_TXH_MAC_HWSEQ
;
400 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
401 mac_ctl
|= B43_TXH_MAC_STMSDU
;
402 if (phy
->type
== B43_PHYTYPE_A
)
403 mac_ctl
|= B43_TXH_MAC_5GHZ
;
405 /* Overwrite rates[0].count to make the retry calculation
406 * in the tx status easier. need the actual retry limit to
407 * detect whether the fallback rate was used.
409 if ((rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) ||
410 (rates
[0].count
<= dev
->wl
->hw
->conf
.long_frame_max_tx_count
)) {
411 rates
[0].count
= dev
->wl
->hw
->conf
.long_frame_max_tx_count
;
412 mac_ctl
|= B43_TXH_MAC_LONGFRAME
;
414 rates
[0].count
= dev
->wl
->hw
->conf
.short_frame_max_tx_count
;
417 /* Generate the RTS or CTS-to-self frame */
418 if ((rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) ||
419 (rates
[0].flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
)) {
421 struct ieee80211_hdr
*uninitialized_var(hdr
);
422 int rts_rate
, rts_rate_fb
;
423 int rts_rate_ofdm
, rts_rate_fb_ofdm
;
424 struct b43_plcp_hdr6
*uninitialized_var(plcp
);
425 struct ieee80211_rate
*rts_cts_rate
;
427 rts_cts_rate
= ieee80211_get_rts_cts_rate(dev
->wl
->hw
, info
);
429 rts_rate
= rts_cts_rate
? rts_cts_rate
->hw_value
: B43_CCK_RATE_1MB
;
430 rts_rate_ofdm
= b43_is_ofdm_rate(rts_rate
);
431 rts_rate_fb
= b43_calc_fallback_rate(rts_rate
);
432 rts_rate_fb_ofdm
= b43_is_ofdm_rate(rts_rate_fb
);
434 if (rates
[0].flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
435 struct ieee80211_cts
*uninitialized_var(cts
);
437 switch (dev
->fw
.hdr_format
) {
439 cts
= (struct ieee80211_cts
*)
440 (txhdr
->format_351
.rts_frame
);
443 cts
= (struct ieee80211_cts
*)
444 (txhdr
->format_410
.rts_frame
);
447 ieee80211_ctstoself_get(dev
->wl
->hw
, info
->control
.vif
,
448 fragment_data
, fragment_len
,
450 mac_ctl
|= B43_TXH_MAC_SENDCTS
;
451 len
= sizeof(struct ieee80211_cts
);
453 struct ieee80211_rts
*uninitialized_var(rts
);
455 switch (dev
->fw
.hdr_format
) {
457 rts
= (struct ieee80211_rts
*)
458 (txhdr
->format_351
.rts_frame
);
461 rts
= (struct ieee80211_rts
*)
462 (txhdr
->format_410
.rts_frame
);
465 ieee80211_rts_get(dev
->wl
->hw
, info
->control
.vif
,
466 fragment_data
, fragment_len
,
468 mac_ctl
|= B43_TXH_MAC_SENDRTS
;
469 len
= sizeof(struct ieee80211_rts
);
473 /* Generate the PLCP headers for the RTS/CTS frame */
474 switch (dev
->fw
.hdr_format
) {
476 plcp
= &txhdr
->format_351
.rts_plcp
;
479 plcp
= &txhdr
->format_410
.rts_plcp
;
482 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)plcp
,
484 plcp
= &txhdr
->rts_plcp_fb
;
485 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)plcp
,
488 switch (dev
->fw
.hdr_format
) {
490 hdr
= (struct ieee80211_hdr
*)
491 (&txhdr
->format_351
.rts_frame
);
494 hdr
= (struct ieee80211_hdr
*)
495 (&txhdr
->format_410
.rts_frame
);
498 txhdr
->rts_dur_fb
= hdr
->duration_id
;
501 extra_ft
|= B43_TXH_EFT_RTS_OFDM
;
502 txhdr
->phy_rate_rts
=
503 b43_plcp_get_ratecode_ofdm(rts_rate
);
505 extra_ft
|= B43_TXH_EFT_RTS_CCK
;
506 txhdr
->phy_rate_rts
=
507 b43_plcp_get_ratecode_cck(rts_rate
);
509 if (rts_rate_fb_ofdm
)
510 extra_ft
|= B43_TXH_EFT_RTSFB_OFDM
;
512 extra_ft
|= B43_TXH_EFT_RTSFB_CCK
;
514 if (rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
&&
515 phy
->type
== B43_PHYTYPE_N
) {
516 txhdr
->phy_ctl1_rts
= cpu_to_le16(
517 b43_generate_tx_phy_ctl1(dev
, rts_rate
));
518 txhdr
->phy_ctl1_rts_fb
= cpu_to_le16(
519 b43_generate_tx_phy_ctl1(dev
, rts_rate_fb
));
524 switch (dev
->fw
.hdr_format
) {
526 txhdr
->format_351
.cookie
= cpu_to_le16(cookie
);
529 txhdr
->format_410
.cookie
= cpu_to_le16(cookie
);
533 if (phy
->type
== B43_PHYTYPE_N
) {
535 cpu_to_le16(b43_generate_tx_phy_ctl1(dev
, rate
));
537 cpu_to_le16(b43_generate_tx_phy_ctl1(dev
, rate_fb
));
540 /* Apply the bitfields */
541 txhdr
->mac_ctl
= cpu_to_le32(mac_ctl
);
542 txhdr
->phy_ctl
= cpu_to_le16(phy_ctl
);
543 txhdr
->extra_ft
= extra_ft
;
548 static s8
b43_rssi_postprocess(struct b43_wldev
*dev
,
549 u8 in_rssi
, int ofdm
,
550 int adjust_2053
, int adjust_2050
)
552 struct b43_phy
*phy
= &dev
->phy
;
553 struct b43_phy_g
*gphy
= phy
->g
;
556 switch (phy
->radio_ver
) {
569 if (dev
->dev
->bus_sprom
->
570 boardflags_lo
& B43_BFL_RSSI
) {
573 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
574 tmp
= gphy
->nrssi_lt
[in_rssi
];
586 if (phy
->type
== B43_PHYTYPE_G
&& adjust_2050
)
612 static s8
b43_rssinoise_postprocess(struct b43_wldev
*dev
, u8 in_rssi
)
614 struct b43_phy
*phy
= &dev
->phy
;
617 if (phy
->type
== B43_PHYTYPE_A
) {
618 //TODO: Incomplete specs.
621 ret
= b43_rssi_postprocess(dev
, in_rssi
, 0, 1, 1);
627 void b43_rx(struct b43_wldev
*dev
, struct sk_buff
*skb
, const void *_rxhdr
)
629 struct ieee80211_rx_status status
;
630 struct b43_plcp_hdr6
*plcp
;
631 struct ieee80211_hdr
*wlhdr
;
632 const struct b43_rxhdr_fw4
*rxhdr
= _rxhdr
;
634 u16 phystat0
, phystat3
, chanstat
, mactime
;
640 memset(&status
, 0, sizeof(status
));
642 /* Get metadata about the frame from the header. */
643 phystat0
= le16_to_cpu(rxhdr
->phy_status0
);
644 phystat3
= le16_to_cpu(rxhdr
->phy_status3
);
645 macstat
= le32_to_cpu(rxhdr
->mac_status
);
646 mactime
= le16_to_cpu(rxhdr
->mac_time
);
647 chanstat
= le16_to_cpu(rxhdr
->channel
);
648 phytype
= chanstat
& B43_RX_CHAN_PHYTYPE
;
650 if (unlikely(macstat
& B43_RX_MAC_FCSERR
)) {
651 dev
->wl
->ieee_stats
.dot11FCSErrorCount
++;
652 status
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
654 if (unlikely(phystat0
& (B43_RX_PHYST0_PLCPHCF
| B43_RX_PHYST0_PLCPFV
)))
655 status
.flag
|= RX_FLAG_FAILED_PLCP_CRC
;
656 if (phystat0
& B43_RX_PHYST0_SHORTPRMBL
)
657 status
.flag
|= RX_FLAG_SHORTPRE
;
658 if (macstat
& B43_RX_MAC_DECERR
) {
659 /* Decryption with the given key failed.
660 * Drop the packet. We also won't be able to decrypt it with
661 * the key in software. */
665 /* Skip PLCP and padding */
666 padding
= (macstat
& B43_RX_MAC_PADDING
) ? 2 : 0;
667 if (unlikely(skb
->len
< (sizeof(struct b43_plcp_hdr6
) + padding
))) {
668 b43dbg(dev
->wl
, "RX: Packet size underrun (1)\n");
671 plcp
= (struct b43_plcp_hdr6
*)(skb
->data
+ padding
);
672 skb_pull(skb
, sizeof(struct b43_plcp_hdr6
) + padding
);
673 /* The skb contains the Wireless Header + payload data now */
674 if (unlikely(skb
->len
< (2 + 2 + 6 /*minimum hdr */ + FCS_LEN
))) {
675 b43dbg(dev
->wl
, "RX: Packet size underrun (2)\n");
678 wlhdr
= (struct ieee80211_hdr
*)(skb
->data
);
679 fctl
= wlhdr
->frame_control
;
681 if (macstat
& B43_RX_MAC_DEC
) {
685 keyidx
= ((macstat
& B43_RX_MAC_KEYIDX
)
686 >> B43_RX_MAC_KEYIDX_SHIFT
);
687 /* We must adjust the key index here. We want the "physical"
688 * key index, but the ucode passed it slightly different.
690 keyidx
= b43_kidx_to_raw(dev
, keyidx
);
691 B43_WARN_ON(keyidx
>= ARRAY_SIZE(dev
->key
));
693 if (dev
->key
[keyidx
].algorithm
!= B43_SEC_ALGO_NONE
) {
694 wlhdr_len
= ieee80211_hdrlen(fctl
);
695 if (unlikely(skb
->len
< (wlhdr_len
+ 3))) {
697 "RX: Packet size underrun (3)\n");
700 status
.flag
|= RX_FLAG_DECRYPTED
;
704 /* Link quality statistics */
705 if ((chanstat
& B43_RX_CHAN_PHYTYPE
) == B43_PHYTYPE_N
) {
706 // s8 rssi = max(rxhdr->power0, rxhdr->power1);
707 //TODO: Find out what the rssi value is (dBm or percentage?)
708 // and also find out what the maximum possible value is.
709 // Fill status.ssi and status.signal fields.
711 status
.signal
= b43_rssi_postprocess(dev
, rxhdr
->jssi
,
712 (phystat0
& B43_RX_PHYST0_OFDM
),
713 (phystat0
& B43_RX_PHYST0_GAINCTL
),
714 (phystat3
& B43_RX_PHYST3_TRSTATE
));
717 if (phystat0
& B43_RX_PHYST0_OFDM
)
718 status
.rate_idx
= b43_plcp_get_bitrate_idx_ofdm(plcp
,
719 phytype
== B43_PHYTYPE_A
);
721 status
.rate_idx
= b43_plcp_get_bitrate_idx_cck(plcp
);
722 if (unlikely(status
.rate_idx
== -1)) {
723 /* PLCP seems to be corrupted.
724 * Drop the frame, if we are not interested in corrupted frames. */
725 if (!(dev
->wl
->filter_flags
& FIF_PLCPFAIL
))
728 status
.antenna
= !!(phystat0
& B43_RX_PHYST0_ANT
);
731 * All frames on monitor interfaces and beacons always need a full
732 * 64-bit timestamp. Monitor interfaces need it for diagnostic
733 * purposes and beacons for IBSS merging.
734 * This code assumes we get to process the packet within 16 bits
735 * of timestamp, i.e. about 65 milliseconds after the PHY received
738 if (ieee80211_is_beacon(fctl
) || dev
->wl
->radiotap_enabled
) {
741 b43_tsf_read(dev
, &status
.mactime
);
742 low_mactime_now
= status
.mactime
;
743 status
.mactime
= status
.mactime
& ~0xFFFFULL
;
744 status
.mactime
+= mactime
;
745 if (low_mactime_now
<= mactime
)
746 status
.mactime
-= 0x10000;
747 status
.flag
|= RX_FLAG_MACTIME_MPDU
;
750 chanid
= (chanstat
& B43_RX_CHAN_ID
) >> B43_RX_CHAN_ID_SHIFT
;
751 switch (chanstat
& B43_RX_CHAN_PHYTYPE
) {
753 status
.band
= IEEE80211_BAND_5GHZ
;
755 /* FIXME: We don't really know which value the "chanid" contains.
756 * So the following assignment might be wrong. */
757 status
.freq
= b43_channel_to_freq_5ghz(chanid
);
760 status
.band
= IEEE80211_BAND_2GHZ
;
761 /* chanid is the radio channel cookie value as used
762 * to tune the radio. */
763 status
.freq
= chanid
+ 2400;
767 /* chanid is the SHM channel cookie. Which is the plain
768 * channel number in b43. */
769 if (chanstat
& B43_RX_CHAN_5GHZ
) {
770 status
.band
= IEEE80211_BAND_5GHZ
;
771 status
.freq
= b43_freq_to_channel_5ghz(chanid
);
773 status
.band
= IEEE80211_BAND_2GHZ
;
774 status
.freq
= b43_freq_to_channel_2ghz(chanid
);
782 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
783 ieee80211_rx_ni(dev
->wl
->hw
, skb
);
790 b43dbg(dev
->wl
, "RX: Packet dropped\n");
791 dev_kfree_skb_any(skb
);
794 void b43_handle_txstatus(struct b43_wldev
*dev
,
795 const struct b43_txstatus
*status
)
797 b43_debugfs_log_txstat(dev
, status
);
799 if (status
->intermediate
)
801 if (status
->for_ampdu
)
804 dev
->wl
->ieee_stats
.dot11ACKFailureCount
++;
805 if (status
->rts_count
) {
806 if (status
->rts_count
== 0xF) //FIXME
807 dev
->wl
->ieee_stats
.dot11RTSFailureCount
++;
809 dev
->wl
->ieee_stats
.dot11RTSSuccessCount
++;
812 if (b43_using_pio_transfers(dev
))
813 b43_pio_handle_txstatus(dev
, status
);
815 b43_dma_handle_txstatus(dev
, status
);
817 b43_phy_txpower_check(dev
, 0);
820 /* Fill out the mac80211 TXstatus report based on the b43-specific
821 * txstatus report data. This returns a boolean whether the frame was
822 * successfully transmitted. */
823 bool b43_fill_txstatus_report(struct b43_wldev
*dev
,
824 struct ieee80211_tx_info
*report
,
825 const struct b43_txstatus
*status
)
827 bool frame_success
= 1;
830 /* preserve the confiured retry limit before clearing the status
831 * The xmit function has overwritten the rc's value with the actual
832 * retry limit done by the hardware */
833 retry_limit
= report
->status
.rates
[0].count
;
834 ieee80211_tx_info_clear_status(report
);
837 /* The frame was ACKed. */
838 report
->flags
|= IEEE80211_TX_STAT_ACK
;
840 /* The frame was not ACKed... */
841 if (!(report
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
842 /* ...but we expected an ACK. */
846 if (status
->frame_count
== 0) {
847 /* The frame was not transmitted at all. */
848 report
->status
.rates
[0].count
= 0;
849 } else if (status
->rts_count
> dev
->wl
->hw
->conf
.short_frame_max_tx_count
) {
851 * If the short retries (RTS, not data frame) have exceeded
852 * the limit, the hw will not have tried the selected rate,
853 * but will have used the fallback rate instead.
854 * Don't let the rate control count attempts for the selected
855 * rate in this case, otherwise the statistics will be off.
857 report
->status
.rates
[0].count
= 0;
858 report
->status
.rates
[1].count
= status
->frame_count
;
860 if (status
->frame_count
> retry_limit
) {
861 report
->status
.rates
[0].count
= retry_limit
;
862 report
->status
.rates
[1].count
= status
->frame_count
-
866 report
->status
.rates
[0].count
= status
->frame_count
;
867 report
->status
.rates
[1].idx
= -1;
871 return frame_success
;
874 /* Stop any TX operation on the device (suspend the hardware queues) */
875 void b43_tx_suspend(struct b43_wldev
*dev
)
877 if (b43_using_pio_transfers(dev
))
878 b43_pio_tx_suspend(dev
);
880 b43_dma_tx_suspend(dev
);
883 /* Resume any TX operation on the device (resume the hardware queues) */
884 void b43_tx_resume(struct b43_wldev
*dev
)
886 if (b43_using_pio_transfers(dev
))
887 b43_pio_tx_resume(dev
);
889 b43_dma_tx_resume(dev
);