blob: 0587452195160521586d01bb0d53db42527fb8a2 [file] [log] [blame]
Thomas Gleixnerca47d342019-05-19 15:51:50 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Michael Buesche4d6b792007-09-18 15:39:42 -04002/*
3
4 Broadcom B43 wireless driver
5
6 Transmission (TX/RX) related functions.
7
8 Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
Stefano Brivio1f21ad22007-11-06 22:49:20 +01009 Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
Michael Büscheb032b92011-07-04 20:50:05 +020010 Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
Michael Buesche4d6b792007-09-18 15:39:42 -040011 Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
12 Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
13
Michael Buesche4d6b792007-09-18 15:39:42 -040014
15*/
16
Michael Buesch88499ab2009-10-09 20:33:32 +020017#include "xmit.h"
Michael Bueschef1a6282008-08-27 18:53:02 +020018#include "phy_common.h"
Michael Buesche4d6b792007-09-18 15:39:42 -040019#include "dma.h"
Michael Buesch5100d5a2008-03-29 21:01:16 +010020#include "pio.h"
Michael Buesch03b29772007-12-26 14:41:30 +010021
Rafał Miłecki3311abb2011-02-25 12:34:11 +010022static 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 },
35};
36
37static const struct b43_tx_legacy_rate_phy_ctl_entry *
38b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate)
39{
40 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
41 unsigned int i;
42
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)
46 return e;
47 }
48
49 B43_WARN_ON(1);
50 return NULL;
51}
Michael Buesche4d6b792007-09-18 15:39:42 -040052
Johannes Berg8318d782008-01-24 19:38:38 +010053/* Extract the bitrate index out of a CCK PLCP header. */
54static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
Michael Buesche4d6b792007-09-18 15:39:42 -040055{
56 switch (plcp->raw[0]) {
57 case 0x0A:
Johannes Berg8318d782008-01-24 19:38:38 +010058 return 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040059 case 0x14:
Johannes Berg8318d782008-01-24 19:38:38 +010060 return 1;
Michael Buesche4d6b792007-09-18 15:39:42 -040061 case 0x37:
Johannes Berg8318d782008-01-24 19:38:38 +010062 return 2;
Michael Buesche4d6b792007-09-18 15:39:42 -040063 case 0x6E:
Johannes Berg8318d782008-01-24 19:38:38 +010064 return 3;
Michael Buesche4d6b792007-09-18 15:39:42 -040065 }
Johannes Berg8318d782008-01-24 19:38:38 +010066 return -1;
Michael Buesche4d6b792007-09-18 15:39:42 -040067}
68
Johannes Berg8318d782008-01-24 19:38:38 +010069/* Extract the bitrate index out of an OFDM PLCP header. */
Rafał Miłeckic0624882014-07-23 16:55:44 +020070static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool ghz5)
Michael Buesche4d6b792007-09-18 15:39:42 -040071{
Rafał Miłeckic0624882014-07-23 16:55:44 +020072 /* For 2 GHz band first OFDM rate is at index 4, see main.c */
73 int base = ghz5 ? 0 : 4;
Johannes Berg8318d782008-01-24 19:38:38 +010074
Michael Buesche4d6b792007-09-18 15:39:42 -040075 switch (plcp->raw[0] & 0xF) {
76 case 0xB:
Johannes Berg8318d782008-01-24 19:38:38 +010077 return base + 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040078 case 0xF:
Johannes Berg8318d782008-01-24 19:38:38 +010079 return base + 1;
Michael Buesche4d6b792007-09-18 15:39:42 -040080 case 0xA:
Johannes Berg8318d782008-01-24 19:38:38 +010081 return base + 2;
Michael Buesche4d6b792007-09-18 15:39:42 -040082 case 0xE:
Johannes Berg8318d782008-01-24 19:38:38 +010083 return base + 3;
Michael Buesche4d6b792007-09-18 15:39:42 -040084 case 0x9:
Johannes Berg8318d782008-01-24 19:38:38 +010085 return base + 4;
Michael Buesche4d6b792007-09-18 15:39:42 -040086 case 0xD:
Johannes Berg8318d782008-01-24 19:38:38 +010087 return base + 5;
Michael Buesche4d6b792007-09-18 15:39:42 -040088 case 0x8:
Johannes Berg8318d782008-01-24 19:38:38 +010089 return base + 6;
Michael Buesche4d6b792007-09-18 15:39:42 -040090 case 0xC:
Johannes Berg8318d782008-01-24 19:38:38 +010091 return base + 7;
Michael Buesche4d6b792007-09-18 15:39:42 -040092 }
Johannes Berg8318d782008-01-24 19:38:38 +010093 return -1;
Michael Buesche4d6b792007-09-18 15:39:42 -040094}
95
96u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
97{
98 switch (bitrate) {
99 case B43_CCK_RATE_1MB:
100 return 0x0A;
101 case B43_CCK_RATE_2MB:
102 return 0x14;
103 case B43_CCK_RATE_5MB:
104 return 0x37;
105 case B43_CCK_RATE_11MB:
106 return 0x6E;
107 }
108 B43_WARN_ON(1);
109 return 0;
110}
111
112u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
113{
114 switch (bitrate) {
115 case B43_OFDM_RATE_6MB:
116 return 0xB;
117 case B43_OFDM_RATE_9MB:
118 return 0xF;
119 case B43_OFDM_RATE_12MB:
120 return 0xA;
121 case B43_OFDM_RATE_18MB:
122 return 0xE;
123 case B43_OFDM_RATE_24MB:
124 return 0x9;
125 case B43_OFDM_RATE_36MB:
126 return 0xD;
127 case B43_OFDM_RATE_48MB:
128 return 0x8;
129 case B43_OFDM_RATE_54MB:
130 return 0xC;
131 }
132 B43_WARN_ON(1);
133 return 0;
134}
135
136void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
137 const u16 octets, const u8 bitrate)
138{
Michael Buesche4d6b792007-09-18 15:39:42 -0400139 __u8 *raw = plcp->raw;
140
141 if (b43_is_ofdm_rate(bitrate)) {
Michael Buesch1a094042007-09-20 11:13:40 -0700142 u32 d;
143
144 d = b43_plcp_get_ratecode_ofdm(bitrate);
Michael Buesche4d6b792007-09-18 15:39:42 -0400145 B43_WARN_ON(octets & 0xF000);
Michael Buesch1a094042007-09-20 11:13:40 -0700146 d |= (octets << 5);
Matthieu CASTETb52a0332009-06-04 23:18:33 +0200147 plcp->data = cpu_to_le32(d);
Michael Buesche4d6b792007-09-18 15:39:42 -0400148 } else {
149 u32 plen;
150
151 plen = octets * 16 / bitrate;
152 if ((octets * 16 % bitrate) > 0) {
153 plen++;
154 if ((bitrate == B43_CCK_RATE_11MB)
155 && ((octets * 8 % 11) < 4)) {
156 raw[1] = 0x84;
157 } else
158 raw[1] = 0x04;
159 } else
160 raw[1] = 0x04;
Matthieu CASTETb52a0332009-06-04 23:18:33 +0200161 plcp->data |= cpu_to_le32(plen << 16);
Michael Buesche4d6b792007-09-18 15:39:42 -0400162 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
163 }
164}
165
Rafał Miłecki694718d2011-10-17 16:59:25 +0200166/* TODO: verify if needed for SSLPN or LCN */
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100167static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate)
168{
169 const struct b43_phy *phy = &dev->phy;
170 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
171 u16 control = 0;
172 u16 bw;
173
174 if (phy->type == B43_PHYTYPE_LP)
175 bw = B43_TXH_PHY1_BW_20;
176 else /* FIXME */
177 bw = B43_TXH_PHY1_BW_20;
178
179 if (0) { /* FIXME: MIMO */
180 } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) {
181 control = bw;
182 } else {
183 control = bw;
184 e = b43_tx_legacy_rate_phy_ctl_ent(bitrate);
185 if (e) {
186 control |= e->coding_rate;
187 control |= e->modulation;
188 }
189 control |= B43_TXH_PHY1_MODE_SISO;
190 }
191
192 return control;
193}
194
Adrian Chaddd0b034392016-05-16 20:25:34 -0700195static u8 b43_calc_fallback_rate(u8 bitrate, int gmode)
Michael Buesche4d6b792007-09-18 15:39:42 -0400196{
197 switch (bitrate) {
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;
Adrian Chaddd0b034392016-05-16 20:25:34 -0700206 /*
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.
209 */
Michael Buesche4d6b792007-09-18 15:39:42 -0400210 case B43_OFDM_RATE_6MB:
Adrian Chaddd0b034392016-05-16 20:25:34 -0700211 if (gmode)
212 return B43_CCK_RATE_5MB;
213 else
214 return B43_OFDM_RATE_6MB;
Michael Buesche4d6b792007-09-18 15:39:42 -0400215 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;
229 }
230 B43_WARN_ON(1);
231 return 0;
232}
233
Michael Buescheb189d8b2008-01-28 14:47:41 -0800234/* Generate a TX data header. */
Michael Buesch09552cc2008-01-23 21:44:15 +0100235int b43_generate_txhdr(struct b43_wldev *dev,
236 u8 *_txhdr,
gregor kowski035d0242009-08-19 22:35:45 +0200237 struct sk_buff *skb_frag,
Johannes Berge6a98542008-10-21 12:40:02 +0200238 struct ieee80211_tx_info *info,
Michael Buesch09552cc2008-01-23 21:44:15 +0100239 u16 cookie)
Michael Buesche4d6b792007-09-18 15:39:42 -0400240{
gregor kowski035d0242009-08-19 22:35:45 +0200241 const unsigned char *fragment_data = skb_frag->data;
242 unsigned int fragment_len = skb_frag->len;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800243 struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
Michael Buesche4d6b792007-09-18 15:39:42 -0400244 const struct b43_phy *phy = &dev->phy;
245 const struct ieee80211_hdr *wlhdr =
246 (const struct ieee80211_hdr *)fragment_data;
Johannes Bergd0f09802008-07-29 11:32:07 +0200247 int use_encryption = !!info->control.hw_key;
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700248 __le16 fctl = wlhdr->frame_control;
Johannes Berg8318d782008-01-24 19:38:38 +0100249 struct ieee80211_rate *fbrate;
Michael Buesche4d6b792007-09-18 15:39:42 -0400250 u8 rate, rate_fb;
251 int rate_ofdm, rate_fb_ofdm;
252 unsigned int plcp_fragment_len;
253 u32 mac_ctl = 0;
254 u16 phy_ctl = 0;
Rafał Miłecki694718d2011-10-17 16:59:25 +0200255 bool fill_phy_ctl1 = (phy->type == B43_PHYTYPE_LP ||
256 phy->type == B43_PHYTYPE_N ||
257 phy->type == B43_PHYTYPE_HT);
Michael Buesche4d6b792007-09-18 15:39:42 -0400258 u8 extra_ft = 0;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200259 struct ieee80211_rate *txrate;
Johannes Berge6a98542008-10-21 12:40:02 +0200260 struct ieee80211_tx_rate *rates;
Michael Buesche4d6b792007-09-18 15:39:42 -0400261
262 memset(txhdr, 0, sizeof(*txhdr));
263
Johannes Berge039fa42008-05-15 12:55:29 +0200264 txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200265 rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
Michael Buesche4d6b792007-09-18 15:39:42 -0400266 rate_ofdm = b43_is_ofdm_rate(rate);
Felix Fietkau870abdf2008-10-05 18:04:24 +0200267 fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
Johannes Berg8318d782008-01-24 19:38:38 +0100268 rate_fb = fbrate->hw_value;
Michael Buesche4d6b792007-09-18 15:39:42 -0400269 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
270
271 if (rate_ofdm)
272 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
273 else
274 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
275 txhdr->mac_frame_ctl = wlhdr->frame_control;
Joe Perchesd458cdf2013-10-01 19:04:40 -0700276 memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN);
Michael Buesche4d6b792007-09-18 15:39:42 -0400277
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;
286 } else {
Johannes Berge039fa42008-05-15 12:55:29 +0200287 txhdr->dur_fb = ieee80211_generic_frame_duration(
Michal Kazior4ee73f32012-04-11 08:47:56 +0200288 dev->wl->hw, info->control.vif, info->band,
289 fragment_len, fbrate);
Michael Buesche4d6b792007-09-18 15:39:42 -0400290 }
291
292 plcp_fragment_len = fragment_len + FCS_LEN;
293 if (use_encryption) {
Johannes Berge039fa42008-05-15 12:55:29 +0200294 u8 key_idx = info->control.hw_key->hw_key_idx;
Michael Buesche4d6b792007-09-18 15:39:42 -0400295 struct b43_key *key;
296 int wlhdr_len;
297 size_t iv_len;
298
Michael Buesch66d2d082009-08-06 10:36:50 +0200299 B43_WARN_ON(key_idx >= ARRAY_SIZE(dev->key));
Michael Buesche4d6b792007-09-18 15:39:42 -0400300 key = &(dev->key[key_idx]);
Michael Buesche4d6b792007-09-18 15:39:42 -0400301
Michael Buesch09552cc2008-01-23 21:44:15 +0100302 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. */
308 return -ENOKEY;
Michael Buesch7be1bb62008-01-23 21:10:56 +0100309 }
Michael Buesch09552cc2008-01-23 21:44:15 +0100310
311 /* Hardware appends ICV. */
Felix Fietkau76708de2008-10-05 18:02:48 +0200312 plcp_fragment_len += info->control.hw_key->icv_len;
Michael Buesch09552cc2008-01-23 21:44:15 +0100313
314 key_idx = b43_kidx_to_fw(dev, key_idx);
315 mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
316 B43_TXH_MAC_KEYIDX;
317 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
318 B43_TXH_MAC_KEYALG;
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700319 wlhdr_len = ieee80211_hdrlen(fctl);
gregor kowski035d0242009-08-19 22:35:45 +0200320 if (key->algorithm == B43_SEC_ALGO_TKIP) {
321 u16 phase1key[5];
322 int i;
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.
325 */
Johannes Berg523b02e2011-07-07 22:28:01 +0200326 ieee80211_get_tkip_p1k(info->control.hw_key, skb_frag, phase1key);
Michael Bueschcde1b552009-09-06 16:18:58 +0200327 /* 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;
331 }
gregor kowski035d0242009-08-19 22:35:45 +0200332 /* iv16 */
333 memcpy(txhdr->iv + 10, ((u8 *) wlhdr) + wlhdr_len, 3);
334 } else {
Silvan Jegenc8e49552014-02-25 18:12:52 +0100335 iv_len = min_t(size_t, info->control.hw_key->iv_len,
gregor kowski035d0242009-08-19 22:35:45 +0200336 ARRAY_SIZE(txhdr->iv));
337 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
338 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400339 }
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200340 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200341 case B43_FW_HDR_598:
342 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_598.plcp),
343 plcp_fragment_len, rate);
344 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200345 case B43_FW_HDR_351:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200346 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_351.plcp),
Michael Buescheb189d8b2008-01-28 14:47:41 -0800347 plcp_fragment_len, rate);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200348 break;
349 case B43_FW_HDR_410:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200350 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_410.plcp),
Michael Buescheb189d8b2008-01-28 14:47:41 -0800351 plcp_fragment_len, rate);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200352 break;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800353 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400354 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
355 plcp_fragment_len, rate_fb);
356
357 /* Extra Frame Types */
358 if (rate_fb_ofdm)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800359 extra_ft |= B43_TXH_EFT_FB_OFDM;
360 else
361 extra_ft |= B43_TXH_EFT_FB_CCK;
Michael Buesche4d6b792007-09-18 15:39:42 -0400362
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
365 * is a 5Ghz packet.
366 */
367 txhdr->chan_radio_code = phy->channel;
368
369 /* PHY TX Control word */
370 if (rate_ofdm)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800371 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
372 else
373 phy_ctl |= B43_TXH_PHY_ENC_CCK;
Johannes Berge6a98542008-10-21 12:40:02 +0200374 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800375 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100376
Johannes Bergd748b462012-03-28 11:04:23 +0200377 switch (b43_ieee80211_antenna_sanitize(dev, 0)) {
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100378 case 0: /* Default */
Michael Buescheb189d8b2008-01-28 14:47:41 -0800379 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
Michael Buesche4d6b792007-09-18 15:39:42 -0400380 break;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100381 case 1: /* Antenna 0 */
Michael Buescheb189d8b2008-01-28 14:47:41 -0800382 phy_ctl |= B43_TXH_PHY_ANT0;
Michael Buesche4d6b792007-09-18 15:39:42 -0400383 break;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100384 case 2: /* Antenna 1 */
Michael Buescheb189d8b2008-01-28 14:47:41 -0800385 phy_ctl |= B43_TXH_PHY_ANT1;
386 break;
387 case 3: /* Antenna 2 */
388 phy_ctl |= B43_TXH_PHY_ANT2;
389 break;
390 case 4: /* Antenna 3 */
391 phy_ctl |= B43_TXH_PHY_ANT3;
Michael Buesche4d6b792007-09-18 15:39:42 -0400392 break;
393 default:
394 B43_WARN_ON(1);
395 }
396
Johannes Berge6a98542008-10-21 12:40:02 +0200397 rates = info->control.rates;
Michael Buesche4d6b792007-09-18 15:39:42 -0400398 /* MAC control */
Johannes Berge039fa42008-05-15 12:55:29 +0200399 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Michael Buescheb189d8b2008-01-28 14:47:41 -0800400 mac_ctl |= B43_TXH_MAC_ACK;
Johannes Bergf591fa52008-07-10 11:21:26 +0200401 /* use hardware sequence counter as the non-TID counter */
402 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800403 mac_ctl |= B43_TXH_MAC_HWSEQ;
Johannes Berge039fa42008-05-15 12:55:29 +0200404 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800405 mac_ctl |= B43_TXH_MAC_STMSDU;
Rafał Miłecki24acfc62014-05-20 09:27:18 +0200406 if (!phy->gmode)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800407 mac_ctl |= B43_TXH_MAC_5GHZ;
Johannes Berge6a98542008-10-21 12:40:02 +0200408
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.
412 */
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;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800416 mac_ctl |= B43_TXH_MAC_LONGFRAME;
Johannes Berge6a98542008-10-21 12:40:02 +0200417 } else {
418 rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
419 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400420
421 /* Generate the RTS or CTS-to-self frame */
Johannes Berge6a98542008-10-21 12:40:02 +0200422 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
423 (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
Michael Buesche4d6b792007-09-18 15:39:42 -0400424 unsigned int len;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200425 struct ieee80211_hdr *uninitialized_var(hdr);
Michael Buesche4d6b792007-09-18 15:39:42 -0400426 int rts_rate, rts_rate_fb;
427 int rts_rate_ofdm, rts_rate_fb_ofdm;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200428 struct b43_plcp_hdr6 *uninitialized_var(plcp);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200429 struct ieee80211_rate *rts_cts_rate;
Michael Buesche4d6b792007-09-18 15:39:42 -0400430
Johannes Berge039fa42008-05-15 12:55:29 +0200431 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200432
433 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
Michael Buesche4d6b792007-09-18 15:39:42 -0400434 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
Adrian Chaddd0b034392016-05-16 20:25:34 -0700435 rts_rate_fb = b43_calc_fallback_rate(rts_rate, phy->gmode);
Michael Buesche4d6b792007-09-18 15:39:42 -0400436 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
437
Johannes Berge6a98542008-10-21 12:40:02 +0200438 if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200439 struct ieee80211_cts *uninitialized_var(cts);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800440
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200441 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200442 case B43_FW_HDR_598:
443 cts = (struct ieee80211_cts *)
444 (txhdr->format_598.rts_frame);
445 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200446 case B43_FW_HDR_351:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800447 cts = (struct ieee80211_cts *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200448 (txhdr->format_351.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200449 break;
450 case B43_FW_HDR_410:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800451 cts = (struct ieee80211_cts *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200452 (txhdr->format_410.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200453 break;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800454 }
Johannes Berge039fa42008-05-15 12:55:29 +0200455 ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
Michael Buesche4d6b792007-09-18 15:39:42 -0400456 fragment_data, fragment_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200457 info, cts);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800458 mac_ctl |= B43_TXH_MAC_SENDCTS;
Michael Buesche4d6b792007-09-18 15:39:42 -0400459 len = sizeof(struct ieee80211_cts);
460 } else {
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200461 struct ieee80211_rts *uninitialized_var(rts);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800462
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200463 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200464 case B43_FW_HDR_598:
465 rts = (struct ieee80211_rts *)
466 (txhdr->format_598.rts_frame);
467 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200468 case B43_FW_HDR_351:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800469 rts = (struct ieee80211_rts *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200470 (txhdr->format_351.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200471 break;
472 case B43_FW_HDR_410:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800473 rts = (struct ieee80211_rts *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200474 (txhdr->format_410.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200475 break;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800476 }
Johannes Berge039fa42008-05-15 12:55:29 +0200477 ieee80211_rts_get(dev->wl->hw, info->control.vif,
Michael Buescheb189d8b2008-01-28 14:47:41 -0800478 fragment_data, fragment_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200479 info, rts);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800480 mac_ctl |= B43_TXH_MAC_SENDRTS;
Michael Buesche4d6b792007-09-18 15:39:42 -0400481 len = sizeof(struct ieee80211_rts);
482 }
483 len += FCS_LEN;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800484
485 /* Generate the PLCP headers for the RTS/CTS frame */
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200486 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200487 case B43_FW_HDR_598:
488 plcp = &txhdr->format_598.rts_plcp;
489 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200490 case B43_FW_HDR_351:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200491 plcp = &txhdr->format_351.rts_plcp;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200492 break;
493 case B43_FW_HDR_410:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200494 plcp = &txhdr->format_410.rts_plcp;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200495 break;
496 }
Michael Buescheb189d8b2008-01-28 14:47:41 -0800497 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
498 len, rts_rate);
499 plcp = &txhdr->rts_plcp_fb;
500 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
Michael Buesche4d6b792007-09-18 15:39:42 -0400501 len, rts_rate_fb);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800502
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200503 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200504 case B43_FW_HDR_598:
505 hdr = (struct ieee80211_hdr *)
506 (&txhdr->format_598.rts_frame);
507 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200508 case B43_FW_HDR_351:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800509 hdr = (struct ieee80211_hdr *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200510 (&txhdr->format_351.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200511 break;
512 case B43_FW_HDR_410:
Michael Buescheb189d8b2008-01-28 14:47:41 -0800513 hdr = (struct ieee80211_hdr *)
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200514 (&txhdr->format_410.rts_frame);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200515 break;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800516 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400517 txhdr->rts_dur_fb = hdr->duration_id;
Michael Buescheb189d8b2008-01-28 14:47:41 -0800518
Michael Buesche4d6b792007-09-18 15:39:42 -0400519 if (rts_rate_ofdm) {
Michael Buescheb189d8b2008-01-28 14:47:41 -0800520 extra_ft |= B43_TXH_EFT_RTS_OFDM;
Michael Buesche4d6b792007-09-18 15:39:42 -0400521 txhdr->phy_rate_rts =
522 b43_plcp_get_ratecode_ofdm(rts_rate);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800523 } else {
524 extra_ft |= B43_TXH_EFT_RTS_CCK;
Michael Buesche4d6b792007-09-18 15:39:42 -0400525 txhdr->phy_rate_rts =
526 b43_plcp_get_ratecode_cck(rts_rate);
Michael Buescheb189d8b2008-01-28 14:47:41 -0800527 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400528 if (rts_rate_fb_ofdm)
Michael Buescheb189d8b2008-01-28 14:47:41 -0800529 extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
530 else
531 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100532
533 if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS &&
Rafał Miłecki694718d2011-10-17 16:59:25 +0200534 fill_phy_ctl1) {
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100535 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));
539 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400540 }
541
542 /* Magic cookie */
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200543 switch (dev->fw.hdr_format) {
Rafał Miłecki5d852902011-08-11 15:07:16 +0200544 case B43_FW_HDR_598:
545 txhdr->format_598.cookie = cpu_to_le16(cookie);
546 break;
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200547 case B43_FW_HDR_351:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200548 txhdr->format_351.cookie = cpu_to_le16(cookie);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200549 break;
550 case B43_FW_HDR_410:
Rafał Miłecki2391b7e2011-08-11 15:07:14 +0200551 txhdr->format_410.cookie = cpu_to_le16(cookie);
Rafał Miłeckiefe02492011-08-11 15:07:15 +0200552 break;
553 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400554
Rafał Miłecki694718d2011-10-17 16:59:25 +0200555 if (fill_phy_ctl1) {
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100556 txhdr->phy_ctl1 =
557 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate));
558 txhdr->phy_ctl1_fb =
559 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate_fb));
560 }
561
Michael Buesche4d6b792007-09-18 15:39:42 -0400562 /* 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;
Michael Buesche4d6b792007-09-18 15:39:42 -0400566
Michael Buesch09552cc2008-01-23 21:44:15 +0100567 return 0;
Michael Buesche4d6b792007-09-18 15:39:42 -0400568}
569
570static s8 b43_rssi_postprocess(struct b43_wldev *dev,
571 u8 in_rssi, int ofdm,
572 int adjust_2053, int adjust_2050)
573{
574 struct b43_phy *phy = &dev->phy;
Michael Bueschef1a6282008-08-27 18:53:02 +0200575 struct b43_phy_g *gphy = phy->g;
Michael Buesche4d6b792007-09-18 15:39:42 -0400576 s32 tmp;
577
578 switch (phy->radio_ver) {
579 case 0x2050:
580 if (ofdm) {
581 tmp = in_rssi;
582 if (tmp > 127)
583 tmp -= 256;
584 tmp *= 73;
585 tmp /= 64;
586 if (adjust_2050)
587 tmp += 25;
588 else
589 tmp -= 3;
590 } else {
Rafał Miłecki05814832011-05-18 02:06:39 +0200591 if (dev->dev->bus_sprom->
Michael Buesche4d6b792007-09-18 15:39:42 -0400592 boardflags_lo & B43_BFL_RSSI) {
593 if (in_rssi > 63)
594 in_rssi = 63;
Michael Bueschef1a6282008-08-27 18:53:02 +0200595 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
596 tmp = gphy->nrssi_lt[in_rssi];
Michael Buesche4d6b792007-09-18 15:39:42 -0400597 tmp = 31 - tmp;
598 tmp *= -131;
599 tmp /= 128;
600 tmp -= 57;
601 } else {
602 tmp = in_rssi;
603 tmp = 31 - tmp;
604 tmp *= -149;
605 tmp /= 128;
606 tmp -= 68;
607 }
608 if (phy->type == B43_PHYTYPE_G && adjust_2050)
609 tmp += 25;
610 }
611 break;
612 case 0x2060:
613 if (in_rssi > 127)
614 tmp = in_rssi - 256;
615 else
616 tmp = in_rssi;
617 break;
618 default:
619 tmp = in_rssi;
620 tmp -= 11;
621 tmp *= 103;
622 tmp /= 64;
623 if (adjust_2053)
624 tmp -= 109;
625 else
626 tmp -= 83;
627 }
628
629 return (s8) tmp;
630}
631
632//TODO
633#if 0
634static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
635{
636 struct b43_phy *phy = &dev->phy;
637 s8 ret;
638
Guenter Roeckafdfdc42016-06-04 07:54:13 -0700639 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
Michael Buesche4d6b792007-09-18 15:39:42 -0400640
641 return ret;
642}
643#endif
644
645void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
646{
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;
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700651 __le16 fctl;
Rafał Miłecki17030f42011-08-11 17:16:27 +0200652 u16 phystat0, phystat3;
653 u16 uninitialized_var(chanstat), uninitialized_var(mactime);
654 u32 uninitialized_var(macstat);
Michael Buesche4d6b792007-09-18 15:39:42 -0400655 u16 chanid;
Johannes Berg1924b4e2012-07-13 10:57:36 +0200656 int padding, rate_idx;
Michael Buesche4d6b792007-09-18 15:39:42 -0400657
658 memset(&status, 0, sizeof(status));
659
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);
Rafał Miłecki17030f42011-08-11 17:16:27 +0200663 switch (dev->fw.hdr_format) {
664 case B43_FW_HDR_598:
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);
668 break;
669 case B43_FW_HDR_410:
670 case B43_FW_HDR_351:
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);
674 break;
675 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400676
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100677 if (unlikely(macstat & B43_RX_MAC_FCSERR)) {
Michael Buesche4d6b792007-09-18 15:39:42 -0400678 dev->wl->ieee_stats.dot11FCSErrorCount++;
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100679 status.flag |= RX_FLAG_FAILED_FCS_CRC;
680 }
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)
Johannes Berg7fdd69c2017-04-26 11:13:00 +0200684 status.enc_flags |= RX_ENC_FLAG_SHORTPRE;
Michael Buesche4d6b792007-09-18 15:39:42 -0400685 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. */
689 goto drop;
690 }
691
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");
696 goto drop;
697 }
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");
703 goto drop;
704 }
705 wlhdr = (struct ieee80211_hdr *)(skb->data);
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700706 fctl = wlhdr->frame_control;
Michael Buesche4d6b792007-09-18 15:39:42 -0400707
708 if (macstat & B43_RX_MAC_DEC) {
709 unsigned int keyidx;
710 int wlhdr_len;
711
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.
716 */
717 keyidx = b43_kidx_to_raw(dev, keyidx);
Michael Buesch66d2d082009-08-06 10:36:50 +0200718 B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
Michael Buesche4d6b792007-09-18 15:39:42 -0400719
720 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700721 wlhdr_len = ieee80211_hdrlen(fctl);
Michael Buesche4d6b792007-09-18 15:39:42 -0400722 if (unlikely(skb->len < (wlhdr_len + 3))) {
723 b43dbg(dev->wl,
724 "RX: Packet size underrun (3)\n");
725 goto drop;
726 }
727 status.flag |= RX_FLAG_DECRYPTED;
728 }
729 }
730
Michael Buesch7b584162008-04-03 18:01:12 +0200731 /* Link quality statistics */
Rafał Miłecki207ae4a2011-10-12 23:18:15 +0200732 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
Rafał Miłecki73d51f32011-10-17 17:15:44 +0200733 case B43_PHYTYPE_HT:
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);
738 break;
Rafał Miłecki207ae4a2011-10-12 23:18:15 +0200739 case B43_PHYTYPE_N:
Rafał Miłecki73d51f32011-10-17 17:15:44 +0200740 /* Broadcom has code for min and avg, but always uses max */
Rafał Miłecki207ae4a2011-10-12 23:18:15 +0200741 if (rxhdr->power0 == 16 || rxhdr->power0 == 32)
742 status.signal = max(rxhdr->power1, rxhdr->power2);
743 else
744 status.signal = max(rxhdr->power0, rxhdr->power1);
745 break;
Rafał Miłecki207ae4a2011-10-12 23:18:15 +0200746 case B43_PHYTYPE_B:
747 case B43_PHYTYPE_G:
748 case B43_PHYTYPE_LP:
Bruno Randolf566bfe52008-05-08 19:15:40 +0200749 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
Michael Buesch7b584162008-04-03 18:01:12 +0200750 (phystat0 & B43_RX_PHYST0_OFDM),
751 (phystat0 & B43_RX_PHYST0_GAINCTL),
752 (phystat3 & B43_RX_PHYST3_TRSTATE));
Rafał Miłecki207ae4a2011-10-12 23:18:15 +0200753 break;
Michael Buesch7b584162008-04-03 18:01:12 +0200754 }
755
Michael Buesche4d6b792007-09-18 15:39:42 -0400756 if (phystat0 & B43_RX_PHYST0_OFDM)
Johannes Berg1924b4e2012-07-13 10:57:36 +0200757 rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
Rafał Miłeckic0624882014-07-23 16:55:44 +0200758 !!(chanstat & B43_RX_CHAN_5GHZ));
Michael Buesche4d6b792007-09-18 15:39:42 -0400759 else
Johannes Berg1924b4e2012-07-13 10:57:36 +0200760 rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
761 if (unlikely(rate_idx == -1)) {
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100762 /* 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))
765 goto drop;
766 }
Johannes Berg1924b4e2012-07-13 10:57:36 +0200767 status.rate_idx = rate_idx;
Michael Buesche4d6b792007-09-18 15:39:42 -0400768 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
John W. Linvillec0ddd042008-01-21 13:41:18 -0500769
770 /*
Johannes Bergd007b7f2008-02-18 18:53:55 +0100771 * 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
776 * the first symbol.
John W. Linvillec0ddd042008-01-21 13:41:18 -0500777 */
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700778 if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
John W. Linvillec0ddd042008-01-21 13:41:18 -0500779 u16 low_mactime_now;
780
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;
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800787 status.flag |= RX_FLAG_MACTIME_START;
John W. Linvillec0ddd042008-01-21 13:41:18 -0500788 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400789
790 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
791 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
Michael Buesche4d6b792007-09-18 15:39:42 -0400792 case B43_PHYTYPE_G:
Johannes Berg57fbcce2016-04-12 15:56:15 +0200793 status.band = NL80211_BAND_2GHZ;
Rafał Miłecki2fc68eb2014-06-12 22:28:22 +0200794 /* Somewhere between 478.104 and 508.1084 firmware for G-PHY
795 * has been modified to be compatible with N-PHY and others.
796 */
797 if (dev->fw.rev >= 508)
798 status.freq = ieee80211_channel_to_frequency(chanid, status.band);
799 else
800 status.freq = chanid + 2400;
Michael Bueschd9871602008-01-02 18:55:53 +0100801 break;
802 case B43_PHYTYPE_N:
Gábor Stefanik826ee702009-08-15 00:52:02 +0200803 case B43_PHYTYPE_LP:
Rafał Miłecki6a461c22011-08-12 00:03:25 +0200804 case B43_PHYTYPE_HT:
Michael Bueschd9871602008-01-02 18:55:53 +0100805 /* chanid is the SHM channel cookie. Which is the plain
806 * channel number in b43. */
ZHAO Gangbb6bd252014-01-18 00:17:39 +0800807 if (chanstat & B43_RX_CHAN_5GHZ)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200808 status.band = NL80211_BAND_5GHZ;
ZHAO Gangbb6bd252014-01-18 00:17:39 +0800809 else
Johannes Berg57fbcce2016-04-12 15:56:15 +0200810 status.band = NL80211_BAND_2GHZ;
ZHAO Gangbb6bd252014-01-18 00:17:39 +0800811 status.freq =
812 ieee80211_channel_to_frequency(chanid, status.band);
Michael Buesche4d6b792007-09-18 15:39:42 -0400813 break;
814 default:
815 B43_WARN_ON(1);
Michael Bueschd9871602008-01-02 18:55:53 +0100816 goto drop;
Michael Buesche4d6b792007-09-18 15:39:42 -0400817 }
818
Johannes Bergf1d58c22009-06-17 13:13:00 +0200819 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
John W. Linville72f5f452009-10-16 14:35:51 -0400820 ieee80211_rx_ni(dev->wl->hw, skb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400821
Michael Buesch990b86f2009-09-12 00:48:03 +0200822#if B43_DEBUG
823 dev->rx_count++;
824#endif
Michael Buesche4d6b792007-09-18 15:39:42 -0400825 return;
826drop:
Michael Buesche4d6b792007-09-18 15:39:42 -0400827 dev_kfree_skb_any(skb);
828}
829
830void b43_handle_txstatus(struct b43_wldev *dev,
831 const struct b43_txstatus *status)
832{
833 b43_debugfs_log_txstat(dev, status);
834
835 if (status->intermediate)
836 return;
837 if (status->for_ampdu)
838 return;
839 if (!status->acked)
840 dev->wl->ieee_stats.dot11ACKFailureCount++;
841 if (status->rts_count) {
842 if (status->rts_count == 0xF) //FIXME
843 dev->wl->ieee_stats.dot11RTSFailureCount++;
844 else
845 dev->wl->ieee_stats.dot11RTSSuccessCount++;
846 }
847
Michael Buesch5100d5a2008-03-29 21:01:16 +0100848 if (b43_using_pio_transfers(dev))
849 b43_pio_handle_txstatus(dev, status);
850 else
851 b43_dma_handle_txstatus(dev, status);
Michael Buesch18c8ade2008-08-28 19:33:40 +0200852
853 b43_phy_txpower_check(dev, 0);
Michael Buesche4d6b792007-09-18 15:39:42 -0400854}
855
Michael Buesch5100d5a2008-03-29 21:01:16 +0100856/* 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. */
Johannes Berge6a98542008-10-21 12:40:02 +0200859bool b43_fill_txstatus_report(struct b43_wldev *dev,
860 struct ieee80211_tx_info *report,
Michael Buesch5100d5a2008-03-29 21:01:16 +0100861 const struct b43_txstatus *status)
Michael Buesche4d6b792007-09-18 15:39:42 -0400862{
Rusty Russell3db1cd52011-12-19 13:56:45 +0000863 bool frame_success = true;
Johannes Berge6a98542008-10-21 12:40:02 +0200864 int retry_limit;
865
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);
Michael Buesche4d6b792007-09-18 15:39:42 -0400871
Michael Buesch5100d5a2008-03-29 21:01:16 +0100872 if (status->acked) {
873 /* The frame was ACKed. */
Johannes Berge039fa42008-05-15 12:55:29 +0200874 report->flags |= IEEE80211_TX_STAT_ACK;
Michael Buesch5100d5a2008-03-29 21:01:16 +0100875 } else {
876 /* The frame was not ACKed... */
Johannes Berge039fa42008-05-15 12:55:29 +0200877 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
Michael Buesch5100d5a2008-03-29 21:01:16 +0100878 /* ...but we expected an ACK. */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000879 frame_success = false;
Michael Buesch5100d5a2008-03-29 21:01:16 +0100880 }
881 }
882 if (status->frame_count == 0) {
883 /* The frame was not transmitted at all. */
Johannes Berge6a98542008-10-21 12:40:02 +0200884 report->status.rates[0].count = 0;
885 } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
886 /*
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.
892 */
893 report->status.rates[0].count = 0;
894 report->status.rates[1].count = status->frame_count;
895 } else {
896 if (status->frame_count > retry_limit) {
897 report->status.rates[0].count = retry_limit;
898 report->status.rates[1].count = status->frame_count -
899 retry_limit;
900
901 } else {
902 report->status.rates[0].count = status->frame_count;
903 report->status.rates[1].idx = -1;
904 }
905 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400906
Michael Buesch5100d5a2008-03-29 21:01:16 +0100907 return frame_success;
Michael Buesche4d6b792007-09-18 15:39:42 -0400908}
909
910/* Stop any TX operation on the device (suspend the hardware queues) */
911void b43_tx_suspend(struct b43_wldev *dev)
912{
Michael Buesch5100d5a2008-03-29 21:01:16 +0100913 if (b43_using_pio_transfers(dev))
914 b43_pio_tx_suspend(dev);
915 else
916 b43_dma_tx_suspend(dev);
Michael Buesche4d6b792007-09-18 15:39:42 -0400917}
918
919/* Resume any TX operation on the device (resume the hardware queues) */
920void b43_tx_resume(struct b43_wldev *dev)
921{
Michael Buesch5100d5a2008-03-29 21:01:16 +0100922 if (b43_using_pio_transfers(dev))
923 b43_pio_tx_resume(dev);
924 else
925 b43_dma_tx_resume(dev);
Michael Buesche4d6b792007-09-18 15:39:42 -0400926}