1 // SPDX-License-Identifier: GPL-2.0-or-later
4 Broadcom B43 wireless driver
6 Transmission (TX/RX) related functions.
8 Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
9 Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
10 Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
11 Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
12 Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
18 #include "phy_common.h"
22 static const struct b43_tx_legacy_rate_phy_ctl_entry b43_tx_legacy_rate_phy_ctl
[] = {
23 { B43_CCK_RATE_1MB
, 0x0, 0x0 },
24 { B43_CCK_RATE_2MB
, 0x0, 0x1 },
25 { B43_CCK_RATE_5MB
, 0x0, 0x2 },
26 { B43_CCK_RATE_11MB
, 0x0, 0x3 },
27 { B43_OFDM_RATE_6MB
, B43_TXH_PHY1_CRATE_1_2
, B43_TXH_PHY1_MODUL_BPSK
},
28 { B43_OFDM_RATE_9MB
, B43_TXH_PHY1_CRATE_3_4
, B43_TXH_PHY1_MODUL_BPSK
},
29 { B43_OFDM_RATE_12MB
, B43_TXH_PHY1_CRATE_1_2
, B43_TXH_PHY1_MODUL_QPSK
},
30 { B43_OFDM_RATE_18MB
, B43_TXH_PHY1_CRATE_3_4
, B43_TXH_PHY1_MODUL_QPSK
},
31 { B43_OFDM_RATE_24MB
, B43_TXH_PHY1_CRATE_1_2
, B43_TXH_PHY1_MODUL_QAM16
},
32 { B43_OFDM_RATE_36MB
, B43_TXH_PHY1_CRATE_3_4
, B43_TXH_PHY1_MODUL_QAM16
},
33 { B43_OFDM_RATE_48MB
, B43_TXH_PHY1_CRATE_2_3
, B43_TXH_PHY1_MODUL_QAM64
},
34 { B43_OFDM_RATE_54MB
, B43_TXH_PHY1_CRATE_3_4
, B43_TXH_PHY1_MODUL_QAM64
},
37 static const struct b43_tx_legacy_rate_phy_ctl_entry
*
38 b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate
)
40 const struct b43_tx_legacy_rate_phy_ctl_entry
*e
;
43 for (i
= 0; i
< ARRAY_SIZE(b43_tx_legacy_rate_phy_ctl
); i
++) {
44 e
= &(b43_tx_legacy_rate_phy_ctl
[i
]);
45 if (e
->bitrate
== bitrate
)
53 /* Extract the bitrate index out of a CCK PLCP header. */
54 static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6
*plcp
)
56 switch (plcp
->raw
[0]) {
69 /* Extract the bitrate index out of an OFDM PLCP header. */
70 static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6
*plcp
, bool ghz5
)
72 /* For 2 GHz band first OFDM rate is at index 4, see main.c */
73 int base
= ghz5
? 0 : 4;
75 switch (plcp
->raw
[0] & 0xF) {
96 u8
b43_plcp_get_ratecode_cck(const u8 bitrate
)
99 case B43_CCK_RATE_1MB
:
101 case B43_CCK_RATE_2MB
:
103 case B43_CCK_RATE_5MB
:
105 case B43_CCK_RATE_11MB
:
112 u8
b43_plcp_get_ratecode_ofdm(const u8 bitrate
)
115 case B43_OFDM_RATE_6MB
:
117 case B43_OFDM_RATE_9MB
:
119 case B43_OFDM_RATE_12MB
:
121 case B43_OFDM_RATE_18MB
:
123 case B43_OFDM_RATE_24MB
:
125 case B43_OFDM_RATE_36MB
:
127 case B43_OFDM_RATE_48MB
:
129 case B43_OFDM_RATE_54MB
:
136 void b43_generate_plcp_hdr(struct b43_plcp_hdr4
*plcp
,
137 const u16 octets
, const u8 bitrate
)
139 __u8
*raw
= plcp
->raw
;
141 if (b43_is_ofdm_rate(bitrate
)) {
144 d
= b43_plcp_get_ratecode_ofdm(bitrate
);
145 B43_WARN_ON(octets
& 0xF000);
147 plcp
->data
= cpu_to_le32(d
);
151 plen
= octets
* 16 / bitrate
;
152 if ((octets
* 16 % bitrate
) > 0) {
154 if ((bitrate
== B43_CCK_RATE_11MB
)
155 && ((octets
* 8 % 11) < 4)) {
161 plcp
->data
|= cpu_to_le32(plen
<< 16);
162 raw
[0] = b43_plcp_get_ratecode_cck(bitrate
);
166 /* TODO: verify if needed for SSLPN or LCN */
167 static u16
b43_generate_tx_phy_ctl1(struct b43_wldev
*dev
, u8 bitrate
)
169 const struct b43_phy
*phy
= &dev
->phy
;
170 const struct b43_tx_legacy_rate_phy_ctl_entry
*e
;
174 if (phy
->type
== B43_PHYTYPE_LP
)
175 bw
= B43_TXH_PHY1_BW_20
;
177 bw
= B43_TXH_PHY1_BW_20
;
179 if (0) { /* FIXME: MIMO */
180 } else if (b43_is_cck_rate(bitrate
) && phy
->type
!= B43_PHYTYPE_LP
) {
184 e
= b43_tx_legacy_rate_phy_ctl_ent(bitrate
);
186 control
|= e
->coding_rate
;
187 control
|= e
->modulation
;
189 control
|= B43_TXH_PHY1_MODE_SISO
;
195 static u8
b43_calc_fallback_rate(u8 bitrate
, int gmode
)
198 case B43_CCK_RATE_1MB
:
199 return B43_CCK_RATE_1MB
;
200 case B43_CCK_RATE_2MB
:
201 return B43_CCK_RATE_1MB
;
202 case B43_CCK_RATE_5MB
:
203 return B43_CCK_RATE_2MB
;
204 case B43_CCK_RATE_11MB
:
205 return B43_CCK_RATE_5MB
;
207 * Don't just fallback to CCK; it may be in 5GHz operation
208 * and falling back to CCK won't work out very well.
210 case B43_OFDM_RATE_6MB
:
212 return B43_CCK_RATE_5MB
;
214 return B43_OFDM_RATE_6MB
;
215 case B43_OFDM_RATE_9MB
:
216 return B43_OFDM_RATE_6MB
;
217 case B43_OFDM_RATE_12MB
:
218 return B43_OFDM_RATE_9MB
;
219 case B43_OFDM_RATE_18MB
:
220 return B43_OFDM_RATE_12MB
;
221 case B43_OFDM_RATE_24MB
:
222 return B43_OFDM_RATE_18MB
;
223 case B43_OFDM_RATE_36MB
:
224 return B43_OFDM_RATE_24MB
;
225 case B43_OFDM_RATE_48MB
:
226 return B43_OFDM_RATE_36MB
;
227 case B43_OFDM_RATE_54MB
:
228 return B43_OFDM_RATE_48MB
;
234 /* Generate a TX data header. */
235 int b43_generate_txhdr(struct b43_wldev
*dev
,
237 struct sk_buff
*skb_frag
,
238 struct ieee80211_tx_info
*info
,
241 const unsigned char *fragment_data
= skb_frag
->data
;
242 unsigned int fragment_len
= skb_frag
->len
;
243 struct b43_txhdr
*txhdr
= (struct b43_txhdr
*)_txhdr
;
244 const struct b43_phy
*phy
= &dev
->phy
;
245 const struct ieee80211_hdr
*wlhdr
=
246 (const struct ieee80211_hdr
*)fragment_data
;
247 int use_encryption
= !!info
->control
.hw_key
;
248 __le16 fctl
= wlhdr
->frame_control
;
249 struct ieee80211_rate
*fbrate
;
251 int rate_ofdm
, rate_fb_ofdm
;
252 unsigned int plcp_fragment_len
;
255 bool fill_phy_ctl1
= (phy
->type
== B43_PHYTYPE_LP
||
256 phy
->type
== B43_PHYTYPE_N
||
257 phy
->type
== B43_PHYTYPE_HT
);
259 struct ieee80211_rate
*txrate
;
260 struct ieee80211_tx_rate
*rates
;
262 memset(txhdr
, 0, sizeof(*txhdr
));
264 txrate
= ieee80211_get_tx_rate(dev
->wl
->hw
, info
);
265 rate
= txrate
? txrate
->hw_value
: B43_CCK_RATE_1MB
;
266 rate_ofdm
= b43_is_ofdm_rate(rate
);
267 fbrate
= ieee80211_get_alt_retry_rate(dev
->wl
->hw
, info
, 0) ? : txrate
;
268 rate_fb
= fbrate
->hw_value
;
269 rate_fb_ofdm
= b43_is_ofdm_rate(rate_fb
);
272 txhdr
->phy_rate
= b43_plcp_get_ratecode_ofdm(rate
);
274 txhdr
->phy_rate
= b43_plcp_get_ratecode_cck(rate
);
275 txhdr
->mac_frame_ctl
= wlhdr
->frame_control
;
276 memcpy(txhdr
->tx_receiver
, wlhdr
->addr1
, ETH_ALEN
);
278 /* Calculate duration for fallback rate */
279 if ((rate_fb
== rate
) ||
280 (wlhdr
->duration_id
& cpu_to_le16(0x8000)) ||
281 (wlhdr
->duration_id
== cpu_to_le16(0))) {
282 /* If the fallback rate equals the normal rate or the
283 * dur_id field contains an AID, CFP magic or 0,
284 * use the original dur_id field. */
285 txhdr
->dur_fb
= wlhdr
->duration_id
;
287 txhdr
->dur_fb
= ieee80211_generic_frame_duration(
288 dev
->wl
->hw
, info
->control
.vif
, info
->band
,
289 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_t(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_598
.plcp
),
343 plcp_fragment_len
, rate
);
346 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->format_351
.plcp
),
347 plcp_fragment_len
, rate
);
350 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->format_410
.plcp
),
351 plcp_fragment_len
, rate
);
354 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)(&txhdr
->plcp_fb
),
355 plcp_fragment_len
, rate_fb
);
357 /* Extra Frame Types */
359 extra_ft
|= B43_TXH_EFT_FB_OFDM
;
361 extra_ft
|= B43_TXH_EFT_FB_CCK
;
363 /* Set channel radio code. Note that the micrcode ORs 0x100 to
364 * this value before comparing it to the value in SHM, if this
367 txhdr
->chan_radio_code
= phy
->channel
;
369 /* PHY TX Control word */
371 phy_ctl
|= B43_TXH_PHY_ENC_OFDM
;
373 phy_ctl
|= B43_TXH_PHY_ENC_CCK
;
374 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
375 phy_ctl
|= B43_TXH_PHY_SHORTPRMBL
;
377 switch (b43_ieee80211_antenna_sanitize(dev
, 0)) {
378 case 0: /* Default */
379 phy_ctl
|= B43_TXH_PHY_ANT01AUTO
;
381 case 1: /* Antenna 0 */
382 phy_ctl
|= B43_TXH_PHY_ANT0
;
384 case 2: /* Antenna 1 */
385 phy_ctl
|= B43_TXH_PHY_ANT1
;
387 case 3: /* Antenna 2 */
388 phy_ctl
|= B43_TXH_PHY_ANT2
;
390 case 4: /* Antenna 3 */
391 phy_ctl
|= B43_TXH_PHY_ANT3
;
397 rates
= info
->control
.rates
;
399 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
400 mac_ctl
|= B43_TXH_MAC_ACK
;
401 /* use hardware sequence counter as the non-TID counter */
402 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
)
403 mac_ctl
|= B43_TXH_MAC_HWSEQ
;
404 if (info
->flags
& IEEE80211_TX_CTL_FIRST_FRAGMENT
)
405 mac_ctl
|= B43_TXH_MAC_STMSDU
;
407 mac_ctl
|= B43_TXH_MAC_5GHZ
;
409 /* Overwrite rates[0].count to make the retry calculation
410 * in the tx status easier. need the actual retry limit to
411 * detect whether the fallback rate was used.
413 if ((rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) ||
414 (rates
[0].count
<= dev
->wl
->hw
->conf
.long_frame_max_tx_count
)) {
415 rates
[0].count
= dev
->wl
->hw
->conf
.long_frame_max_tx_count
;
416 mac_ctl
|= B43_TXH_MAC_LONGFRAME
;
418 rates
[0].count
= dev
->wl
->hw
->conf
.short_frame_max_tx_count
;
421 /* Generate the RTS or CTS-to-self frame */
422 if ((rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) ||
423 (rates
[0].flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
)) {
425 struct ieee80211_hdr
*uninitialized_var(hdr
);
426 int rts_rate
, rts_rate_fb
;
427 int rts_rate_ofdm
, rts_rate_fb_ofdm
;
428 struct b43_plcp_hdr6
*uninitialized_var(plcp
);
429 struct ieee80211_rate
*rts_cts_rate
;
431 rts_cts_rate
= ieee80211_get_rts_cts_rate(dev
->wl
->hw
, info
);
433 rts_rate
= rts_cts_rate
? rts_cts_rate
->hw_value
: B43_CCK_RATE_1MB
;
434 rts_rate_ofdm
= b43_is_ofdm_rate(rts_rate
);
435 rts_rate_fb
= b43_calc_fallback_rate(rts_rate
, phy
->gmode
);
436 rts_rate_fb_ofdm
= b43_is_ofdm_rate(rts_rate_fb
);
438 if (rates
[0].flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
439 struct ieee80211_cts
*uninitialized_var(cts
);
441 switch (dev
->fw
.hdr_format
) {
443 cts
= (struct ieee80211_cts
*)
444 (txhdr
->format_598
.rts_frame
);
447 cts
= (struct ieee80211_cts
*)
448 (txhdr
->format_351
.rts_frame
);
451 cts
= (struct ieee80211_cts
*)
452 (txhdr
->format_410
.rts_frame
);
455 ieee80211_ctstoself_get(dev
->wl
->hw
, info
->control
.vif
,
456 fragment_data
, fragment_len
,
458 mac_ctl
|= B43_TXH_MAC_SENDCTS
;
459 len
= sizeof(struct ieee80211_cts
);
461 struct ieee80211_rts
*uninitialized_var(rts
);
463 switch (dev
->fw
.hdr_format
) {
465 rts
= (struct ieee80211_rts
*)
466 (txhdr
->format_598
.rts_frame
);
469 rts
= (struct ieee80211_rts
*)
470 (txhdr
->format_351
.rts_frame
);
473 rts
= (struct ieee80211_rts
*)
474 (txhdr
->format_410
.rts_frame
);
477 ieee80211_rts_get(dev
->wl
->hw
, info
->control
.vif
,
478 fragment_data
, fragment_len
,
480 mac_ctl
|= B43_TXH_MAC_SENDRTS
;
481 len
= sizeof(struct ieee80211_rts
);
485 /* Generate the PLCP headers for the RTS/CTS frame */
486 switch (dev
->fw
.hdr_format
) {
488 plcp
= &txhdr
->format_598
.rts_plcp
;
491 plcp
= &txhdr
->format_351
.rts_plcp
;
494 plcp
= &txhdr
->format_410
.rts_plcp
;
497 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)plcp
,
499 plcp
= &txhdr
->rts_plcp_fb
;
500 b43_generate_plcp_hdr((struct b43_plcp_hdr4
*)plcp
,
503 switch (dev
->fw
.hdr_format
) {
505 hdr
= (struct ieee80211_hdr
*)
506 (&txhdr
->format_598
.rts_frame
);
509 hdr
= (struct ieee80211_hdr
*)
510 (&txhdr
->format_351
.rts_frame
);
513 hdr
= (struct ieee80211_hdr
*)
514 (&txhdr
->format_410
.rts_frame
);
517 txhdr
->rts_dur_fb
= hdr
->duration_id
;
520 extra_ft
|= B43_TXH_EFT_RTS_OFDM
;
521 txhdr
->phy_rate_rts
=
522 b43_plcp_get_ratecode_ofdm(rts_rate
);
524 extra_ft
|= B43_TXH_EFT_RTS_CCK
;
525 txhdr
->phy_rate_rts
=
526 b43_plcp_get_ratecode_cck(rts_rate
);
528 if (rts_rate_fb_ofdm
)
529 extra_ft
|= B43_TXH_EFT_RTSFB_OFDM
;
531 extra_ft
|= B43_TXH_EFT_RTSFB_CCK
;
533 if (rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
&&
535 txhdr
->phy_ctl1_rts
= cpu_to_le16(
536 b43_generate_tx_phy_ctl1(dev
, rts_rate
));
537 txhdr
->phy_ctl1_rts_fb
= cpu_to_le16(
538 b43_generate_tx_phy_ctl1(dev
, rts_rate_fb
));
543 switch (dev
->fw
.hdr_format
) {
545 txhdr
->format_598
.cookie
= cpu_to_le16(cookie
);
548 txhdr
->format_351
.cookie
= cpu_to_le16(cookie
);
551 txhdr
->format_410
.cookie
= cpu_to_le16(cookie
);
557 cpu_to_le16(b43_generate_tx_phy_ctl1(dev
, rate
));
559 cpu_to_le16(b43_generate_tx_phy_ctl1(dev
, rate_fb
));
562 /* Apply the bitfields */
563 txhdr
->mac_ctl
= cpu_to_le32(mac_ctl
);
564 txhdr
->phy_ctl
= cpu_to_le16(phy_ctl
);
565 txhdr
->extra_ft
= extra_ft
;
570 static s8
b43_rssi_postprocess(struct b43_wldev
*dev
,
571 u8 in_rssi
, int ofdm
,
572 int adjust_2053
, int adjust_2050
)
574 struct b43_phy
*phy
= &dev
->phy
;
575 struct b43_phy_g
*gphy
= phy
->g
;
578 switch (phy
->radio_ver
) {
591 if (dev
->dev
->bus_sprom
->
592 boardflags_lo
& B43_BFL_RSSI
) {
595 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
596 tmp
= gphy
->nrssi_lt
[in_rssi
];
608 if (phy
->type
== B43_PHYTYPE_G
&& adjust_2050
)
634 static s8
b43_rssinoise_postprocess(struct b43_wldev
*dev
, u8 in_rssi
)
636 struct b43_phy
*phy
= &dev
->phy
;
639 ret
= b43_rssi_postprocess(dev
, in_rssi
, 0, 1, 1);
645 void b43_rx(struct b43_wldev
*dev
, struct sk_buff
*skb
, const void *_rxhdr
)
647 struct ieee80211_rx_status status
;
648 struct b43_plcp_hdr6
*plcp
;
649 struct ieee80211_hdr
*wlhdr
;
650 const struct b43_rxhdr_fw4
*rxhdr
= _rxhdr
;
652 u16 phystat0
, phystat3
;
653 u16
uninitialized_var(chanstat
), uninitialized_var(mactime
);
654 u32
uninitialized_var(macstat
);
656 int padding
, rate_idx
;
658 memset(&status
, 0, sizeof(status
));
660 /* Get metadata about the frame from the header. */
661 phystat0
= le16_to_cpu(rxhdr
->phy_status0
);
662 phystat3
= le16_to_cpu(rxhdr
->phy_status3
);
663 switch (dev
->fw
.hdr_format
) {
665 macstat
= le32_to_cpu(rxhdr
->format_598
.mac_status
);
666 mactime
= le16_to_cpu(rxhdr
->format_598
.mac_time
);
667 chanstat
= le16_to_cpu(rxhdr
->format_598
.channel
);
671 macstat
= le32_to_cpu(rxhdr
->format_351
.mac_status
);
672 mactime
= le16_to_cpu(rxhdr
->format_351
.mac_time
);
673 chanstat
= le16_to_cpu(rxhdr
->format_351
.channel
);
677 if (unlikely(macstat
& B43_RX_MAC_FCSERR
)) {
678 dev
->wl
->ieee_stats
.dot11FCSErrorCount
++;
679 status
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
681 if (unlikely(phystat0
& (B43_RX_PHYST0_PLCPHCF
| B43_RX_PHYST0_PLCPFV
)))
682 status
.flag
|= RX_FLAG_FAILED_PLCP_CRC
;
683 if (phystat0
& B43_RX_PHYST0_SHORTPRMBL
)
684 status
.enc_flags
|= RX_ENC_FLAG_SHORTPRE
;
685 if (macstat
& B43_RX_MAC_DECERR
) {
686 /* Decryption with the given key failed.
687 * Drop the packet. We also won't be able to decrypt it with
688 * the key in software. */
692 /* Skip PLCP and padding */
693 padding
= (macstat
& B43_RX_MAC_PADDING
) ? 2 : 0;
694 if (unlikely(skb
->len
< (sizeof(struct b43_plcp_hdr6
) + padding
))) {
695 b43dbg(dev
->wl
, "RX: Packet size underrun (1)\n");
698 plcp
= (struct b43_plcp_hdr6
*)(skb
->data
+ padding
);
699 skb_pull(skb
, sizeof(struct b43_plcp_hdr6
) + padding
);
700 /* The skb contains the Wireless Header + payload data now */
701 if (unlikely(skb
->len
< (2 + 2 + 6 /*minimum hdr */ + FCS_LEN
))) {
702 b43dbg(dev
->wl
, "RX: Packet size underrun (2)\n");
705 wlhdr
= (struct ieee80211_hdr
*)(skb
->data
);
706 fctl
= wlhdr
->frame_control
;
708 if (macstat
& B43_RX_MAC_DEC
) {
712 keyidx
= ((macstat
& B43_RX_MAC_KEYIDX
)
713 >> B43_RX_MAC_KEYIDX_SHIFT
);
714 /* We must adjust the key index here. We want the "physical"
715 * key index, but the ucode passed it slightly different.
717 keyidx
= b43_kidx_to_raw(dev
, keyidx
);
718 B43_WARN_ON(keyidx
>= ARRAY_SIZE(dev
->key
));
720 if (dev
->key
[keyidx
].algorithm
!= B43_SEC_ALGO_NONE
) {
721 wlhdr_len
= ieee80211_hdrlen(fctl
);
722 if (unlikely(skb
->len
< (wlhdr_len
+ 3))) {
724 "RX: Packet size underrun (3)\n");
727 status
.flag
|= RX_FLAG_DECRYPTED
;
731 /* Link quality statistics */
732 switch (chanstat
& B43_RX_CHAN_PHYTYPE
) {
734 /* TODO: is max the right choice? */
735 status
.signal
= max_t(__s8
,
736 max(rxhdr
->phy_ht_power0
, rxhdr
->phy_ht_power1
),
737 rxhdr
->phy_ht_power2
);
740 /* Broadcom has code for min and avg, but always uses max */
741 if (rxhdr
->power0
== 16 || rxhdr
->power0
== 32)
742 status
.signal
= max(rxhdr
->power1
, rxhdr
->power2
);
744 status
.signal
= max(rxhdr
->power0
, rxhdr
->power1
);
749 status
.signal
= b43_rssi_postprocess(dev
, rxhdr
->jssi
,
750 (phystat0
& B43_RX_PHYST0_OFDM
),
751 (phystat0
& B43_RX_PHYST0_GAINCTL
),
752 (phystat3
& B43_RX_PHYST3_TRSTATE
));
756 if (phystat0
& B43_RX_PHYST0_OFDM
)
757 rate_idx
= b43_plcp_get_bitrate_idx_ofdm(plcp
,
758 !!(chanstat
& B43_RX_CHAN_5GHZ
));
760 rate_idx
= b43_plcp_get_bitrate_idx_cck(plcp
);
761 if (unlikely(rate_idx
== -1)) {
762 /* PLCP seems to be corrupted.
763 * Drop the frame, if we are not interested in corrupted frames. */
764 if (!(dev
->wl
->filter_flags
& FIF_PLCPFAIL
))
767 status
.rate_idx
= rate_idx
;
768 status
.antenna
= !!(phystat0
& B43_RX_PHYST0_ANT
);
771 * All frames on monitor interfaces and beacons always need a full
772 * 64-bit timestamp. Monitor interfaces need it for diagnostic
773 * purposes and beacons for IBSS merging.
774 * This code assumes we get to process the packet within 16 bits
775 * of timestamp, i.e. about 65 milliseconds after the PHY received
778 if (ieee80211_is_beacon(fctl
) || dev
->wl
->radiotap_enabled
) {
781 b43_tsf_read(dev
, &status
.mactime
);
782 low_mactime_now
= status
.mactime
;
783 status
.mactime
= status
.mactime
& ~0xFFFFULL
;
784 status
.mactime
+= mactime
;
785 if (low_mactime_now
<= mactime
)
786 status
.mactime
-= 0x10000;
787 status
.flag
|= RX_FLAG_MACTIME_START
;
790 chanid
= (chanstat
& B43_RX_CHAN_ID
) >> B43_RX_CHAN_ID_SHIFT
;
791 switch (chanstat
& B43_RX_CHAN_PHYTYPE
) {
793 status
.band
= NL80211_BAND_2GHZ
;
794 /* Somewhere between 478.104 and 508.1084 firmware for G-PHY
795 * has been modified to be compatible with N-PHY and others.
797 if (dev
->fw
.rev
>= 508)
798 status
.freq
= ieee80211_channel_to_frequency(chanid
, status
.band
);
800 status
.freq
= chanid
+ 2400;
805 /* chanid is the SHM channel cookie. Which is the plain
806 * channel number in b43. */
807 if (chanstat
& B43_RX_CHAN_5GHZ
)
808 status
.band
= NL80211_BAND_5GHZ
;
810 status
.band
= NL80211_BAND_2GHZ
;
812 ieee80211_channel_to_frequency(chanid
, status
.band
);
819 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
820 ieee80211_rx_ni(dev
->wl
->hw
, skb
);
827 dev_kfree_skb_any(skb
);
830 void b43_handle_txstatus(struct b43_wldev
*dev
,
831 const struct b43_txstatus
*status
)
833 b43_debugfs_log_txstat(dev
, status
);
835 if (status
->intermediate
)
837 if (status
->for_ampdu
)
840 dev
->wl
->ieee_stats
.dot11ACKFailureCount
++;
841 if (status
->rts_count
) {
842 if (status
->rts_count
== 0xF) //FIXME
843 dev
->wl
->ieee_stats
.dot11RTSFailureCount
++;
845 dev
->wl
->ieee_stats
.dot11RTSSuccessCount
++;
848 if (b43_using_pio_transfers(dev
))
849 b43_pio_handle_txstatus(dev
, status
);
851 b43_dma_handle_txstatus(dev
, status
);
853 b43_phy_txpower_check(dev
, 0);
856 /* Fill out the mac80211 TXstatus report based on the b43-specific
857 * txstatus report data. This returns a boolean whether the frame was
858 * successfully transmitted. */
859 bool b43_fill_txstatus_report(struct b43_wldev
*dev
,
860 struct ieee80211_tx_info
*report
,
861 const struct b43_txstatus
*status
)
863 bool frame_success
= true;
866 /* preserve the confiured retry limit before clearing the status
867 * The xmit function has overwritten the rc's value with the actual
868 * retry limit done by the hardware */
869 retry_limit
= report
->status
.rates
[0].count
;
870 ieee80211_tx_info_clear_status(report
);
873 /* The frame was ACKed. */
874 report
->flags
|= IEEE80211_TX_STAT_ACK
;
876 /* The frame was not ACKed... */
877 if (!(report
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
878 /* ...but we expected an ACK. */
879 frame_success
= false;
882 if (status
->frame_count
== 0) {
883 /* The frame was not transmitted at all. */
884 report
->status
.rates
[0].count
= 0;
885 } else if (status
->rts_count
> dev
->wl
->hw
->conf
.short_frame_max_tx_count
) {
887 * If the short retries (RTS, not data frame) have exceeded
888 * the limit, the hw will not have tried the selected rate,
889 * but will have used the fallback rate instead.
890 * Don't let the rate control count attempts for the selected
891 * rate in this case, otherwise the statistics will be off.
893 report
->status
.rates
[0].count
= 0;
894 report
->status
.rates
[1].count
= status
->frame_count
;
896 if (status
->frame_count
> retry_limit
) {
897 report
->status
.rates
[0].count
= retry_limit
;
898 report
->status
.rates
[1].count
= status
->frame_count
-
902 report
->status
.rates
[0].count
= status
->frame_count
;
903 report
->status
.rates
[1].idx
= -1;
907 return frame_success
;
910 /* Stop any TX operation on the device (suspend the hardware queues) */
911 void b43_tx_suspend(struct b43_wldev
*dev
)
913 if (b43_using_pio_transfers(dev
))
914 b43_pio_tx_suspend(dev
);
916 b43_dma_tx_suspend(dev
);
919 /* Resume any TX operation on the device (resume the hardware queues) */
920 void b43_tx_resume(struct b43_wldev
*dev
)
922 if (b43_using_pio_transfers(dev
))
923 b43_pio_tx_resume(dev
);
925 b43_dma_tx_resume(dev
);