blob: b74f25ec1ab4a89b4c1380b9ca9213b396a0ca49 [file] [log] [blame]
Michael Buesche4d6b792007-09-18 15:39:42 -04001/*
2
3 Broadcom B43 wireless driver
4
5 Transmission (TX/RX) related functions.
6
7 Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
Stefano Brivio1f21ad22007-11-06 22:49:20 +01008 Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
Michael Büscheb032b92011-07-04 20:50:05 +02009 Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
Michael Buesche4d6b792007-09-18 15:39:42 -040010 Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
11 Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
12
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.
17
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.
22
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.
27
28*/
29
Michael Buesch88499ab2009-10-09 20:33:32 +020030#include "xmit.h"
Michael Bueschef1a6282008-08-27 18:53:02 +020031#include "phy_common.h"
Michael Buesche4d6b792007-09-18 15:39:42 -040032#include "dma.h"
Michael Buesch5100d5a2008-03-29 21:01:16 +010033#include "pio.h"
Michael Buesch03b29772007-12-26 14:41:30 +010034
Rafał Miłecki3311abb2011-02-25 12:34:11 +010035static 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 },
48};
49
50static const struct b43_tx_legacy_rate_phy_ctl_entry *
51b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate)
52{
53 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
54 unsigned int i;
55
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)
59 return e;
60 }
61
62 B43_WARN_ON(1);
63 return NULL;
64}
Michael Buesche4d6b792007-09-18 15:39:42 -040065
Johannes Berg8318d782008-01-24 19:38:38 +010066/* Extract the bitrate index out of a CCK PLCP header. */
67static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
Michael Buesche4d6b792007-09-18 15:39:42 -040068{
69 switch (plcp->raw[0]) {
70 case 0x0A:
Johannes Berg8318d782008-01-24 19:38:38 +010071 return 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040072 case 0x14:
Johannes Berg8318d782008-01-24 19:38:38 +010073 return 1;
Michael Buesche4d6b792007-09-18 15:39:42 -040074 case 0x37:
Johannes Berg8318d782008-01-24 19:38:38 +010075 return 2;
Michael Buesche4d6b792007-09-18 15:39:42 -040076 case 0x6E:
Johannes Berg8318d782008-01-24 19:38:38 +010077 return 3;
Michael Buesche4d6b792007-09-18 15:39:42 -040078 }
Johannes Berg8318d782008-01-24 19:38:38 +010079 return -1;
Michael Buesche4d6b792007-09-18 15:39:42 -040080}
81
Johannes Berg8318d782008-01-24 19:38:38 +010082/* Extract the bitrate index out of an OFDM PLCP header. */
Lorenzo Navaa3c0b872009-03-22 19:15:41 +010083static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
Michael Buesche4d6b792007-09-18 15:39:42 -040084{
Johannes Berg8318d782008-01-24 19:38:38 +010085 int base = aphy ? 0 : 4;
86
Michael Buesche4d6b792007-09-18 15:39:42 -040087 switch (plcp->raw[0] & 0xF) {
88 case 0xB:
Johannes Berg8318d782008-01-24 19:38:38 +010089 return base + 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040090 case 0xF:
Johannes Berg8318d782008-01-24 19:38:38 +010091 return base + 1;
Michael Buesche4d6b792007-09-18 15:39:42 -040092 case 0xA:
Johannes Berg8318d782008-01-24 19:38:38 +010093 return base + 2;
Michael Buesche4d6b792007-09-18 15:39:42 -040094 case 0xE:
Johannes Berg8318d782008-01-24 19:38:38 +010095 return base + 3;
Michael Buesche4d6b792007-09-18 15:39:42 -040096 case 0x9:
Johannes Berg8318d782008-01-24 19:38:38 +010097 return base + 4;
Michael Buesche4d6b792007-09-18 15:39:42 -040098 case 0xD:
Johannes Berg8318d782008-01-24 19:38:38 +010099 return base + 5;
Michael Buesche4d6b792007-09-18 15:39:42 -0400100 case 0x8:
Johannes Berg8318d782008-01-24 19:38:38 +0100101 return base + 6;
Michael Buesche4d6b792007-09-18 15:39:42 -0400102 case 0xC:
Johannes Berg8318d782008-01-24 19:38:38 +0100103 return base + 7;
Michael Buesche4d6b792007-09-18 15:39:42 -0400104 }
Johannes Berg8318d782008-01-24 19:38:38 +0100105 return -1;
Michael Buesche4d6b792007-09-18 15:39:42 -0400106}
107
108u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
109{
110 switch (bitrate) {
111 case B43_CCK_RATE_1MB:
112 return 0x0A;
113 case B43_CCK_RATE_2MB:
114 return 0x14;
115 case B43_CCK_RATE_5MB:
116 return 0x37;
117 case B43_CCK_RATE_11MB:
118 return 0x6E;
119 }
120 B43_WARN_ON(1);
121 return 0;
122}
123
124u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
125{
126 switch (bitrate) {
127 case B43_OFDM_RATE_6MB:
128 return 0xB;
129 case B43_OFDM_RATE_9MB:
130 return 0xF;
131 case B43_OFDM_RATE_12MB:
132 return 0xA;
133 case B43_OFDM_RATE_18MB:
134 return 0xE;
135 case B43_OFDM_RATE_24MB:
136 return 0x9;
137 case B43_OFDM_RATE_36MB:
138 return 0xD;
139 case B43_OFDM_RATE_48MB:
140 return 0x8;
141 case B43_OFDM_RATE_54MB:
142 return 0xC;
143 }
144 B43_WARN_ON(1);
145 return 0;
146}
147
148void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
149 const u16 octets, const u8 bitrate)
150{
Michael Buesche4d6b792007-09-18 15:39:42 -0400151 __u8 *raw = plcp->raw;
152
153 if (b43_is_ofdm_rate(bitrate)) {
Michael Buesch1a094042007-09-20 11:13:40 -0700154 u32 d;
155
156 d = b43_plcp_get_ratecode_ofdm(bitrate);
Michael Buesche4d6b792007-09-18 15:39:42 -0400157 B43_WARN_ON(octets & 0xF000);
Michael Buesch1a094042007-09-20 11:13:40 -0700158 d |= (octets << 5);
Matthieu CASTETb52a0332009-06-04 23:18:33 +0200159 plcp->data = cpu_to_le32(d);
Michael Buesche4d6b792007-09-18 15:39:42 -0400160 } else {
161 u32 plen;
162
163 plen = octets * 16 / bitrate;
164 if ((octets * 16 % bitrate) > 0) {
165 plen++;
166 if ((bitrate == B43_CCK_RATE_11MB)
167 && ((octets * 8 % 11) < 4)) {
168 raw[1] = 0x84;
169 } else
170 raw[1] = 0x04;
171 } else
172 raw[1] = 0x04;
Matthieu CASTETb52a0332009-06-04 23:18:33 +0200173 plcp->data |= cpu_to_le32(plen << 16);
Michael Buesche4d6b792007-09-18 15:39:42 -0400174 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
175 }
176}
177
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100178static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate)
179{
180 const struct b43_phy *phy = &dev->phy;
181 const struct b43_tx_legacy_rate_phy_ctl_entry *e;
182 u16 control = 0;
183 u16 bw;
184
185 if (phy->type == B43_PHYTYPE_LP)
186 bw = B43_TXH_PHY1_BW_20;
187 else /* FIXME */
188 bw = B43_TXH_PHY1_BW_20;
189
190 if (0) { /* FIXME: MIMO */
191 } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) {
192 control = bw;
193 } else {
194 control = bw;
195 e = b43_tx_legacy_rate_phy_ctl_ent(bitrate);
196 if (e) {
197 control |= e->coding_rate;
198 control |= e->modulation;
199 }
200 control |= B43_TXH_PHY1_MODE_SISO;
201 }
202
203 return control;
204}
205
Michael Buesche4d6b792007-09-18 15:39:42 -0400206static u8 b43_calc_fallback_rate(u8 bitrate)
207{
208 switch (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;
233 }
234 B43_WARN_ON(1);
235 return 0;
236}
237
Michael Buescheb189d82008-01-28 14:47:41 -0800238/* Generate a TX data header. */
Michael Buesch09552cc2008-01-23 21:44:15 +0100239int b43_generate_txhdr(struct b43_wldev *dev,
240 u8 *_txhdr,
gregor kowski035d0242009-08-19 22:35:45 +0200241 struct sk_buff *skb_frag,
Johannes Berge6a98542008-10-21 12:40:02 +0200242 struct ieee80211_tx_info *info,
Michael Buesch09552cc2008-01-23 21:44:15 +0100243 u16 cookie)
Michael Buesche4d6b792007-09-18 15:39:42 -0400244{
gregor kowski035d0242009-08-19 22:35:45 +0200245 const unsigned char *fragment_data = skb_frag->data;
246 unsigned int fragment_len = skb_frag->len;
Michael Buescheb189d82008-01-28 14:47:41 -0800247 struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
Michael Buesche4d6b792007-09-18 15:39:42 -0400248 const struct b43_phy *phy = &dev->phy;
249 const struct ieee80211_hdr *wlhdr =
250 (const struct ieee80211_hdr *)fragment_data;
Johannes Bergd0f09802008-07-29 11:32:07 +0200251 int use_encryption = !!info->control.hw_key;
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700252 __le16 fctl = wlhdr->frame_control;
Johannes Berg8318d782008-01-24 19:38:38 +0100253 struct ieee80211_rate *fbrate;
Michael Buesche4d6b792007-09-18 15:39:42 -0400254 u8 rate, rate_fb;
255 int rate_ofdm, rate_fb_ofdm;
256 unsigned int plcp_fragment_len;
257 u32 mac_ctl = 0;
258 u16 phy_ctl = 0;
259 u8 extra_ft = 0;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200260 struct ieee80211_rate *txrate;
Johannes Berge6a98542008-10-21 12:40:02 +0200261 struct ieee80211_tx_rate *rates;
Michael Buesche4d6b792007-09-18 15:39:42 -0400262
263 memset(txhdr, 0, sizeof(*txhdr));
264
Johannes Berge039fa42008-05-15 12:55:29 +0200265 txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200266 rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
Michael Buesche4d6b792007-09-18 15:39:42 -0400267 rate_ofdm = b43_is_ofdm_rate(rate);
Felix Fietkau870abdf2008-10-05 18:04:24 +0200268 fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
Johannes Berg8318d782008-01-24 19:38:38 +0100269 rate_fb = fbrate->hw_value;
Michael Buesche4d6b792007-09-18 15:39:42 -0400270 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
271
272 if (rate_ofdm)
273 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
274 else
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);
278
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;
287 } else {
Johannes Berge039fa42008-05-15 12:55:29 +0200288 txhdr->dur_fb = ieee80211_generic_frame_duration(
289 dev->wl->hw, info->control.vif, 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 {
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);
338 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400339 }
Michael Buescheb189d82008-01-28 14:47:41 -0800340 if (b43_is_old_txhdr_format(dev)) {
341 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
342 plcp_fragment_len, rate);
343 } else {
344 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
345 plcp_fragment_len, rate);
346 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400347 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
348 plcp_fragment_len, rate_fb);
349
350 /* Extra Frame Types */
351 if (rate_fb_ofdm)
Michael Buescheb189d82008-01-28 14:47:41 -0800352 extra_ft |= B43_TXH_EFT_FB_OFDM;
353 else
354 extra_ft |= B43_TXH_EFT_FB_CCK;
Michael Buesche4d6b792007-09-18 15:39:42 -0400355
356 /* Set channel radio code. Note that the micrcode ORs 0x100 to
357 * this value before comparing it to the value in SHM, if this
358 * is a 5Ghz packet.
359 */
360 txhdr->chan_radio_code = phy->channel;
361
362 /* PHY TX Control word */
363 if (rate_ofdm)
Michael Buescheb189d82008-01-28 14:47:41 -0800364 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
365 else
366 phy_ctl |= B43_TXH_PHY_ENC_CCK;
Johannes Berge6a98542008-10-21 12:40:02 +0200367 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Michael Buescheb189d82008-01-28 14:47:41 -0800368 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100369
Johannes Berge039fa42008-05-15 12:55:29 +0200370 switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) {
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100371 case 0: /* Default */
Michael Buescheb189d82008-01-28 14:47:41 -0800372 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
Michael Buesche4d6b792007-09-18 15:39:42 -0400373 break;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100374 case 1: /* Antenna 0 */
Michael Buescheb189d82008-01-28 14:47:41 -0800375 phy_ctl |= B43_TXH_PHY_ANT0;
Michael Buesche4d6b792007-09-18 15:39:42 -0400376 break;
Michael Buesch9db1f6d2007-12-22 21:54:20 +0100377 case 2: /* Antenna 1 */
Michael Buescheb189d82008-01-28 14:47:41 -0800378 phy_ctl |= B43_TXH_PHY_ANT1;
379 break;
380 case 3: /* Antenna 2 */
381 phy_ctl |= B43_TXH_PHY_ANT2;
382 break;
383 case 4: /* Antenna 3 */
384 phy_ctl |= B43_TXH_PHY_ANT3;
Michael Buesche4d6b792007-09-18 15:39:42 -0400385 break;
386 default:
387 B43_WARN_ON(1);
388 }
389
Johannes Berge6a98542008-10-21 12:40:02 +0200390 rates = info->control.rates;
Michael Buesche4d6b792007-09-18 15:39:42 -0400391 /* MAC control */
Johannes Berge039fa42008-05-15 12:55:29 +0200392 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Michael Buescheb189d82008-01-28 14:47:41 -0800393 mac_ctl |= B43_TXH_MAC_ACK;
Johannes Bergf591fa52008-07-10 11:21:26 +0200394 /* use hardware sequence counter as the non-TID counter */
395 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
Michael Buescheb189d82008-01-28 14:47:41 -0800396 mac_ctl |= B43_TXH_MAC_HWSEQ;
Johannes Berge039fa42008-05-15 12:55:29 +0200397 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Michael Buescheb189d82008-01-28 14:47:41 -0800398 mac_ctl |= B43_TXH_MAC_STMSDU;
Michael Buesche4d6b792007-09-18 15:39:42 -0400399 if (phy->type == B43_PHYTYPE_A)
Michael Buescheb189d82008-01-28 14:47:41 -0800400 mac_ctl |= B43_TXH_MAC_5GHZ;
Johannes Berge6a98542008-10-21 12:40:02 +0200401
402 /* Overwrite rates[0].count to make the retry calculation
403 * in the tx status easier. need the actual retry limit to
404 * detect whether the fallback rate was used.
405 */
406 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
407 (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
408 rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
Michael Buescheb189d82008-01-28 14:47:41 -0800409 mac_ctl |= B43_TXH_MAC_LONGFRAME;
Johannes Berge6a98542008-10-21 12:40:02 +0200410 } else {
411 rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
412 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400413
414 /* Generate the RTS or CTS-to-self frame */
Johannes Berge6a98542008-10-21 12:40:02 +0200415 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
416 (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
Michael Buesche4d6b792007-09-18 15:39:42 -0400417 unsigned int len;
418 struct ieee80211_hdr *hdr;
419 int rts_rate, rts_rate_fb;
420 int rts_rate_ofdm, rts_rate_fb_ofdm;
Michael Buescheb189d82008-01-28 14:47:41 -0800421 struct b43_plcp_hdr6 *plcp;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200422 struct ieee80211_rate *rts_cts_rate;
Michael Buesche4d6b792007-09-18 15:39:42 -0400423
Johannes Berge039fa42008-05-15 12:55:29 +0200424 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200425
426 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
Michael Buesche4d6b792007-09-18 15:39:42 -0400427 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
428 rts_rate_fb = b43_calc_fallback_rate(rts_rate);
429 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
430
Johannes Berge6a98542008-10-21 12:40:02 +0200431 if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Michael Buescheb189d82008-01-28 14:47:41 -0800432 struct ieee80211_cts *cts;
433
434 if (b43_is_old_txhdr_format(dev)) {
435 cts = (struct ieee80211_cts *)
436 (txhdr->old_format.rts_frame);
437 } else {
438 cts = (struct ieee80211_cts *)
439 (txhdr->new_format.rts_frame);
440 }
Johannes Berge039fa42008-05-15 12:55:29 +0200441 ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
Michael Buesche4d6b792007-09-18 15:39:42 -0400442 fragment_data, fragment_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200443 info, cts);
Michael Buescheb189d82008-01-28 14:47:41 -0800444 mac_ctl |= B43_TXH_MAC_SENDCTS;
Michael Buesche4d6b792007-09-18 15:39:42 -0400445 len = sizeof(struct ieee80211_cts);
446 } else {
Michael Buescheb189d82008-01-28 14:47:41 -0800447 struct ieee80211_rts *rts;
448
449 if (b43_is_old_txhdr_format(dev)) {
450 rts = (struct ieee80211_rts *)
451 (txhdr->old_format.rts_frame);
452 } else {
453 rts = (struct ieee80211_rts *)
454 (txhdr->new_format.rts_frame);
455 }
Johannes Berge039fa42008-05-15 12:55:29 +0200456 ieee80211_rts_get(dev->wl->hw, info->control.vif,
Michael Buescheb189d82008-01-28 14:47:41 -0800457 fragment_data, fragment_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200458 info, rts);
Michael Buescheb189d82008-01-28 14:47:41 -0800459 mac_ctl |= B43_TXH_MAC_SENDRTS;
Michael Buesche4d6b792007-09-18 15:39:42 -0400460 len = sizeof(struct ieee80211_rts);
461 }
462 len += FCS_LEN;
Michael Buescheb189d82008-01-28 14:47:41 -0800463
464 /* Generate the PLCP headers for the RTS/CTS frame */
465 if (b43_is_old_txhdr_format(dev))
466 plcp = &txhdr->old_format.rts_plcp;
467 else
468 plcp = &txhdr->new_format.rts_plcp;
469 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
470 len, rts_rate);
471 plcp = &txhdr->rts_plcp_fb;
472 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
Michael Buesche4d6b792007-09-18 15:39:42 -0400473 len, rts_rate_fb);
Michael Buescheb189d82008-01-28 14:47:41 -0800474
475 if (b43_is_old_txhdr_format(dev)) {
476 hdr = (struct ieee80211_hdr *)
477 (&txhdr->old_format.rts_frame);
478 } else {
479 hdr = (struct ieee80211_hdr *)
480 (&txhdr->new_format.rts_frame);
481 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400482 txhdr->rts_dur_fb = hdr->duration_id;
Michael Buescheb189d82008-01-28 14:47:41 -0800483
Michael Buesche4d6b792007-09-18 15:39:42 -0400484 if (rts_rate_ofdm) {
Michael Buescheb189d82008-01-28 14:47:41 -0800485 extra_ft |= B43_TXH_EFT_RTS_OFDM;
Michael Buesche4d6b792007-09-18 15:39:42 -0400486 txhdr->phy_rate_rts =
487 b43_plcp_get_ratecode_ofdm(rts_rate);
Michael Buescheb189d82008-01-28 14:47:41 -0800488 } else {
489 extra_ft |= B43_TXH_EFT_RTS_CCK;
Michael Buesche4d6b792007-09-18 15:39:42 -0400490 txhdr->phy_rate_rts =
491 b43_plcp_get_ratecode_cck(rts_rate);
Michael Buescheb189d82008-01-28 14:47:41 -0800492 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400493 if (rts_rate_fb_ofdm)
Michael Buescheb189d82008-01-28 14:47:41 -0800494 extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
495 else
496 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100497
498 if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS &&
499 phy->type == B43_PHYTYPE_N) {
500 txhdr->phy_ctl1_rts = cpu_to_le16(
501 b43_generate_tx_phy_ctl1(dev, rts_rate));
502 txhdr->phy_ctl1_rts_fb = cpu_to_le16(
503 b43_generate_tx_phy_ctl1(dev, rts_rate_fb));
504 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400505 }
506
507 /* Magic cookie */
Michael Buescheb189d82008-01-28 14:47:41 -0800508 if (b43_is_old_txhdr_format(dev))
509 txhdr->old_format.cookie = cpu_to_le16(cookie);
510 else
511 txhdr->new_format.cookie = cpu_to_le16(cookie);
Michael Buesche4d6b792007-09-18 15:39:42 -0400512
Rafał Miłecki3311abb2011-02-25 12:34:11 +0100513 if (phy->type == B43_PHYTYPE_N) {
514 txhdr->phy_ctl1 =
515 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate));
516 txhdr->phy_ctl1_fb =
517 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate_fb));
518 }
519
Michael Buesche4d6b792007-09-18 15:39:42 -0400520 /* Apply the bitfields */
521 txhdr->mac_ctl = cpu_to_le32(mac_ctl);
522 txhdr->phy_ctl = cpu_to_le16(phy_ctl);
523 txhdr->extra_ft = extra_ft;
Michael Buesche4d6b792007-09-18 15:39:42 -0400524
Michael Buesch09552cc2008-01-23 21:44:15 +0100525 return 0;
Michael Buesche4d6b792007-09-18 15:39:42 -0400526}
527
528static s8 b43_rssi_postprocess(struct b43_wldev *dev,
529 u8 in_rssi, int ofdm,
530 int adjust_2053, int adjust_2050)
531{
532 struct b43_phy *phy = &dev->phy;
Michael Bueschef1a6282008-08-27 18:53:02 +0200533 struct b43_phy_g *gphy = phy->g;
Michael Buesche4d6b792007-09-18 15:39:42 -0400534 s32 tmp;
535
536 switch (phy->radio_ver) {
537 case 0x2050:
538 if (ofdm) {
539 tmp = in_rssi;
540 if (tmp > 127)
541 tmp -= 256;
542 tmp *= 73;
543 tmp /= 64;
544 if (adjust_2050)
545 tmp += 25;
546 else
547 tmp -= 3;
548 } else {
Rafał Miłecki05814832011-05-18 02:06:39 +0200549 if (dev->dev->bus_sprom->
Michael Buesche4d6b792007-09-18 15:39:42 -0400550 boardflags_lo & B43_BFL_RSSI) {
551 if (in_rssi > 63)
552 in_rssi = 63;
Michael Bueschef1a6282008-08-27 18:53:02 +0200553 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
554 tmp = gphy->nrssi_lt[in_rssi];
Michael Buesche4d6b792007-09-18 15:39:42 -0400555 tmp = 31 - tmp;
556 tmp *= -131;
557 tmp /= 128;
558 tmp -= 57;
559 } else {
560 tmp = in_rssi;
561 tmp = 31 - tmp;
562 tmp *= -149;
563 tmp /= 128;
564 tmp -= 68;
565 }
566 if (phy->type == B43_PHYTYPE_G && adjust_2050)
567 tmp += 25;
568 }
569 break;
570 case 0x2060:
571 if (in_rssi > 127)
572 tmp = in_rssi - 256;
573 else
574 tmp = in_rssi;
575 break;
576 default:
577 tmp = in_rssi;
578 tmp -= 11;
579 tmp *= 103;
580 tmp /= 64;
581 if (adjust_2053)
582 tmp -= 109;
583 else
584 tmp -= 83;
585 }
586
587 return (s8) tmp;
588}
589
590//TODO
591#if 0
592static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
593{
594 struct b43_phy *phy = &dev->phy;
595 s8 ret;
596
597 if (phy->type == B43_PHYTYPE_A) {
598 //TODO: Incomplete specs.
599 ret = 0;
600 } else
601 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
602
603 return ret;
604}
605#endif
606
607void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
608{
609 struct ieee80211_rx_status status;
610 struct b43_plcp_hdr6 *plcp;
611 struct ieee80211_hdr *wlhdr;
612 const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700613 __le16 fctl;
Michael Buesche4d6b792007-09-18 15:39:42 -0400614 u16 phystat0, phystat3, chanstat, mactime;
615 u32 macstat;
616 u16 chanid;
Johannes Berg8318d782008-01-24 19:38:38 +0100617 u16 phytype;
Michael Buesche4d6b792007-09-18 15:39:42 -0400618 int padding;
619
620 memset(&status, 0, sizeof(status));
621
622 /* Get metadata about the frame from the header. */
623 phystat0 = le16_to_cpu(rxhdr->phy_status0);
624 phystat3 = le16_to_cpu(rxhdr->phy_status3);
Michael Buesche4d6b792007-09-18 15:39:42 -0400625 macstat = le32_to_cpu(rxhdr->mac_status);
626 mactime = le16_to_cpu(rxhdr->mac_time);
627 chanstat = le16_to_cpu(rxhdr->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100628 phytype = chanstat & B43_RX_CHAN_PHYTYPE;
Michael Buesche4d6b792007-09-18 15:39:42 -0400629
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100630 if (unlikely(macstat & B43_RX_MAC_FCSERR)) {
Michael Buesche4d6b792007-09-18 15:39:42 -0400631 dev->wl->ieee_stats.dot11FCSErrorCount++;
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100632 status.flag |= RX_FLAG_FAILED_FCS_CRC;
633 }
634 if (unlikely(phystat0 & (B43_RX_PHYST0_PLCPHCF | B43_RX_PHYST0_PLCPFV)))
635 status.flag |= RX_FLAG_FAILED_PLCP_CRC;
636 if (phystat0 & B43_RX_PHYST0_SHORTPRMBL)
637 status.flag |= RX_FLAG_SHORTPRE;
Michael Buesche4d6b792007-09-18 15:39:42 -0400638 if (macstat & B43_RX_MAC_DECERR) {
639 /* Decryption with the given key failed.
640 * Drop the packet. We also won't be able to decrypt it with
641 * the key in software. */
642 goto drop;
643 }
644
645 /* Skip PLCP and padding */
646 padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
647 if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
648 b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
649 goto drop;
650 }
651 plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
652 skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
653 /* The skb contains the Wireless Header + payload data now */
654 if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
655 b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
656 goto drop;
657 }
658 wlhdr = (struct ieee80211_hdr *)(skb->data);
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700659 fctl = wlhdr->frame_control;
Michael Buesche4d6b792007-09-18 15:39:42 -0400660
661 if (macstat & B43_RX_MAC_DEC) {
662 unsigned int keyidx;
663 int wlhdr_len;
664
665 keyidx = ((macstat & B43_RX_MAC_KEYIDX)
666 >> B43_RX_MAC_KEYIDX_SHIFT);
667 /* We must adjust the key index here. We want the "physical"
668 * key index, but the ucode passed it slightly different.
669 */
670 keyidx = b43_kidx_to_raw(dev, keyidx);
Michael Buesch66d2d082009-08-06 10:36:50 +0200671 B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key));
Michael Buesche4d6b792007-09-18 15:39:42 -0400672
673 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700674 wlhdr_len = ieee80211_hdrlen(fctl);
Michael Buesche4d6b792007-09-18 15:39:42 -0400675 if (unlikely(skb->len < (wlhdr_len + 3))) {
676 b43dbg(dev->wl,
677 "RX: Packet size underrun (3)\n");
678 goto drop;
679 }
680 status.flag |= RX_FLAG_DECRYPTED;
681 }
682 }
683
Michael Buesch7b584162008-04-03 18:01:12 +0200684 /* Link quality statistics */
Michael Buesch7b584162008-04-03 18:01:12 +0200685 if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
686// s8 rssi = max(rxhdr->power0, rxhdr->power1);
687 //TODO: Find out what the rssi value is (dBm or percentage?)
688 // and also find out what the maximum possible value is.
689 // Fill status.ssi and status.signal fields.
690 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200691 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
Michael Buesch7b584162008-04-03 18:01:12 +0200692 (phystat0 & B43_RX_PHYST0_OFDM),
693 (phystat0 & B43_RX_PHYST0_GAINCTL),
694 (phystat3 & B43_RX_PHYST3_TRSTATE));
Michael Buesch7b584162008-04-03 18:01:12 +0200695 }
696
Michael Buesche4d6b792007-09-18 15:39:42 -0400697 if (phystat0 & B43_RX_PHYST0_OFDM)
Johannes Berg8318d782008-01-24 19:38:38 +0100698 status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
699 phytype == B43_PHYTYPE_A);
Michael Buesche4d6b792007-09-18 15:39:42 -0400700 else
Johannes Berg8318d782008-01-24 19:38:38 +0100701 status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
Michael Bueschce4fbdb2009-03-02 23:18:37 +0100702 if (unlikely(status.rate_idx == -1)) {
703 /* PLCP seems to be corrupted.
704 * Drop the frame, if we are not interested in corrupted frames. */
705 if (!(dev->wl->filter_flags & FIF_PLCPFAIL))
706 goto drop;
707 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400708 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
John W. Linvillec0ddd042008-01-21 13:41:18 -0500709
710 /*
Johannes Bergd007b7f2008-02-18 18:53:55 +0100711 * All frames on monitor interfaces and beacons always need a full
712 * 64-bit timestamp. Monitor interfaces need it for diagnostic
713 * purposes and beacons for IBSS merging.
714 * This code assumes we get to process the packet within 16 bits
715 * of timestamp, i.e. about 65 milliseconds after the PHY received
716 * the first symbol.
John W. Linvillec0ddd042008-01-21 13:41:18 -0500717 */
Harvey Harrisonf37d9232008-06-14 23:33:39 -0700718 if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
John W. Linvillec0ddd042008-01-21 13:41:18 -0500719 u16 low_mactime_now;
720
721 b43_tsf_read(dev, &status.mactime);
722 low_mactime_now = status.mactime;
723 status.mactime = status.mactime & ~0xFFFFULL;
724 status.mactime += mactime;
725 if (low_mactime_now <= mactime)
726 status.mactime -= 0x10000;
Johannes Berg6ebacbb2011-02-23 15:06:08 +0100727 status.flag |= RX_FLAG_MACTIME_MPDU;
John W. Linvillec0ddd042008-01-21 13:41:18 -0500728 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400729
730 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
731 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
732 case B43_PHYTYPE_A:
Johannes Berg8318d782008-01-24 19:38:38 +0100733 status.band = IEEE80211_BAND_5GHZ;
Michael Bueschd9871602008-01-02 18:55:53 +0100734 B43_WARN_ON(1);
735 /* FIXME: We don't really know which value the "chanid" contains.
736 * So the following assignment might be wrong. */
Johannes Berg8318d782008-01-24 19:38:38 +0100737 status.freq = b43_channel_to_freq_5ghz(chanid);
Michael Buesche4d6b792007-09-18 15:39:42 -0400738 break;
739 case B43_PHYTYPE_G:
Johannes Berg8318d782008-01-24 19:38:38 +0100740 status.band = IEEE80211_BAND_2GHZ;
Michael Bueschd9871602008-01-02 18:55:53 +0100741 /* chanid is the radio channel cookie value as used
742 * to tune the radio. */
Michael Buesche4d6b792007-09-18 15:39:42 -0400743 status.freq = chanid + 2400;
Michael Bueschd9871602008-01-02 18:55:53 +0100744 break;
745 case B43_PHYTYPE_N:
Gábor Stefanik826ee702009-08-15 00:52:02 +0200746 case B43_PHYTYPE_LP:
Michael Bueschd9871602008-01-02 18:55:53 +0100747 /* chanid is the SHM channel cookie. Which is the plain
748 * channel number in b43. */
Johannes Berg8318d782008-01-24 19:38:38 +0100749 if (chanstat & B43_RX_CHAN_5GHZ) {
750 status.band = IEEE80211_BAND_5GHZ;
751 status.freq = b43_freq_to_channel_5ghz(chanid);
752 } else {
753 status.band = IEEE80211_BAND_2GHZ;
754 status.freq = b43_freq_to_channel_2ghz(chanid);
755 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400756 break;
757 default:
758 B43_WARN_ON(1);
Michael Bueschd9871602008-01-02 18:55:53 +0100759 goto drop;
Michael Buesche4d6b792007-09-18 15:39:42 -0400760 }
761
Johannes Bergf1d58c22009-06-17 13:13:00 +0200762 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
John W. Linville72f5f452009-10-16 14:35:51 -0400763 ieee80211_rx_ni(dev->wl->hw, skb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400764
Michael Buesch990b86f2009-09-12 00:48:03 +0200765#if B43_DEBUG
766 dev->rx_count++;
767#endif
Michael Buesche4d6b792007-09-18 15:39:42 -0400768 return;
769drop:
770 b43dbg(dev->wl, "RX: Packet dropped\n");
771 dev_kfree_skb_any(skb);
772}
773
774void b43_handle_txstatus(struct b43_wldev *dev,
775 const struct b43_txstatus *status)
776{
777 b43_debugfs_log_txstat(dev, status);
778
779 if (status->intermediate)
780 return;
781 if (status->for_ampdu)
782 return;
783 if (!status->acked)
784 dev->wl->ieee_stats.dot11ACKFailureCount++;
785 if (status->rts_count) {
786 if (status->rts_count == 0xF) //FIXME
787 dev->wl->ieee_stats.dot11RTSFailureCount++;
788 else
789 dev->wl->ieee_stats.dot11RTSSuccessCount++;
790 }
791
Michael Buesch5100d5a2008-03-29 21:01:16 +0100792 if (b43_using_pio_transfers(dev))
793 b43_pio_handle_txstatus(dev, status);
794 else
795 b43_dma_handle_txstatus(dev, status);
Michael Buesch18c8ade2008-08-28 19:33:40 +0200796
797 b43_phy_txpower_check(dev, 0);
Michael Buesche4d6b792007-09-18 15:39:42 -0400798}
799
Michael Buesch5100d5a2008-03-29 21:01:16 +0100800/* Fill out the mac80211 TXstatus report based on the b43-specific
801 * txstatus report data. This returns a boolean whether the frame was
802 * successfully transmitted. */
Johannes Berge6a98542008-10-21 12:40:02 +0200803bool b43_fill_txstatus_report(struct b43_wldev *dev,
804 struct ieee80211_tx_info *report,
Michael Buesch5100d5a2008-03-29 21:01:16 +0100805 const struct b43_txstatus *status)
Michael Buesche4d6b792007-09-18 15:39:42 -0400806{
Michael Buesch5100d5a2008-03-29 21:01:16 +0100807 bool frame_success = 1;
Johannes Berge6a98542008-10-21 12:40:02 +0200808 int retry_limit;
809
810 /* preserve the confiured retry limit before clearing the status
811 * The xmit function has overwritten the rc's value with the actual
812 * retry limit done by the hardware */
813 retry_limit = report->status.rates[0].count;
814 ieee80211_tx_info_clear_status(report);
Michael Buesche4d6b792007-09-18 15:39:42 -0400815
Michael Buesch5100d5a2008-03-29 21:01:16 +0100816 if (status->acked) {
817 /* The frame was ACKed. */
Johannes Berge039fa42008-05-15 12:55:29 +0200818 report->flags |= IEEE80211_TX_STAT_ACK;
Michael Buesch5100d5a2008-03-29 21:01:16 +0100819 } else {
820 /* The frame was not ACKed... */
Johannes Berge039fa42008-05-15 12:55:29 +0200821 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
Michael Buesch5100d5a2008-03-29 21:01:16 +0100822 /* ...but we expected an ACK. */
823 frame_success = 0;
Michael Buesch5100d5a2008-03-29 21:01:16 +0100824 }
825 }
826 if (status->frame_count == 0) {
827 /* The frame was not transmitted at all. */
Johannes Berge6a98542008-10-21 12:40:02 +0200828 report->status.rates[0].count = 0;
829 } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
830 /*
831 * If the short retries (RTS, not data frame) have exceeded
832 * the limit, the hw will not have tried the selected rate,
833 * but will have used the fallback rate instead.
834 * Don't let the rate control count attempts for the selected
835 * rate in this case, otherwise the statistics will be off.
836 */
837 report->status.rates[0].count = 0;
838 report->status.rates[1].count = status->frame_count;
839 } else {
840 if (status->frame_count > retry_limit) {
841 report->status.rates[0].count = retry_limit;
842 report->status.rates[1].count = status->frame_count -
843 retry_limit;
844
845 } else {
846 report->status.rates[0].count = status->frame_count;
847 report->status.rates[1].idx = -1;
848 }
849 }
Michael Buesche4d6b792007-09-18 15:39:42 -0400850
Michael Buesch5100d5a2008-03-29 21:01:16 +0100851 return frame_success;
Michael Buesche4d6b792007-09-18 15:39:42 -0400852}
853
854/* Stop any TX operation on the device (suspend the hardware queues) */
855void b43_tx_suspend(struct b43_wldev *dev)
856{
Michael Buesch5100d5a2008-03-29 21:01:16 +0100857 if (b43_using_pio_transfers(dev))
858 b43_pio_tx_suspend(dev);
859 else
860 b43_dma_tx_suspend(dev);
Michael Buesche4d6b792007-09-18 15:39:42 -0400861}
862
863/* Resume any TX operation on the device (resume the hardware queues) */
864void b43_tx_resume(struct b43_wldev *dev)
865{
Michael Buesch5100d5a2008-03-29 21:01:16 +0100866 if (b43_using_pio_transfers(dev))
867 b43_pio_tx_resume(dev);
868 else
869 b43_dma_tx_resume(dev);
Michael Buesche4d6b792007-09-18 15:39:42 -0400870}