Merge branch 'linus' into release
[deliverable/linux.git] / drivers / net / wireless / b43 / xmit.c
CommitLineData
e4d6b795
MB
1/*
2
3 Broadcom B43 wireless driver
4
5 Transmission (TX/RX) related functions.
6
7 Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
1f21ad2a 8 Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
e4d6b795
MB
9 Copyright (C) 2005, 2006 Michael Buesch <mb@bu3sch.de>
10 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
30#include "xmit.h"
ef1a628d 31#include "phy_common.h"
e4d6b795 32#include "dma.h"
5100d5ac 33#include "pio.h"
03b29773 34
e4d6b795 35
8318d78a
JB
36/* Extract the bitrate index out of a CCK PLCP header. */
37static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
e4d6b795
MB
38{
39 switch (plcp->raw[0]) {
40 case 0x0A:
8318d78a 41 return 0;
e4d6b795 42 case 0x14:
8318d78a 43 return 1;
e4d6b795 44 case 0x37:
8318d78a 45 return 2;
e4d6b795 46 case 0x6E:
8318d78a 47 return 3;
e4d6b795 48 }
8318d78a 49 return -1;
e4d6b795
MB
50}
51
8318d78a 52/* Extract the bitrate index out of an OFDM PLCP header. */
a3c0b87c 53static int b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
e4d6b795 54{
8318d78a
JB
55 int base = aphy ? 0 : 4;
56
e4d6b795
MB
57 switch (plcp->raw[0] & 0xF) {
58 case 0xB:
8318d78a 59 return base + 0;
e4d6b795 60 case 0xF:
8318d78a 61 return base + 1;
e4d6b795 62 case 0xA:
8318d78a 63 return base + 2;
e4d6b795 64 case 0xE:
8318d78a 65 return base + 3;
e4d6b795 66 case 0x9:
8318d78a 67 return base + 4;
e4d6b795 68 case 0xD:
8318d78a 69 return base + 5;
e4d6b795 70 case 0x8:
8318d78a 71 return base + 6;
e4d6b795 72 case 0xC:
8318d78a 73 return base + 7;
e4d6b795 74 }
8318d78a 75 return -1;
e4d6b795
MB
76}
77
78u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
79{
80 switch (bitrate) {
81 case B43_CCK_RATE_1MB:
82 return 0x0A;
83 case B43_CCK_RATE_2MB:
84 return 0x14;
85 case B43_CCK_RATE_5MB:
86 return 0x37;
87 case B43_CCK_RATE_11MB:
88 return 0x6E;
89 }
90 B43_WARN_ON(1);
91 return 0;
92}
93
94u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
95{
96 switch (bitrate) {
97 case B43_OFDM_RATE_6MB:
98 return 0xB;
99 case B43_OFDM_RATE_9MB:
100 return 0xF;
101 case B43_OFDM_RATE_12MB:
102 return 0xA;
103 case B43_OFDM_RATE_18MB:
104 return 0xE;
105 case B43_OFDM_RATE_24MB:
106 return 0x9;
107 case B43_OFDM_RATE_36MB:
108 return 0xD;
109 case B43_OFDM_RATE_48MB:
110 return 0x8;
111 case B43_OFDM_RATE_54MB:
112 return 0xC;
113 }
114 B43_WARN_ON(1);
115 return 0;
116}
117
118void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
119 const u16 octets, const u8 bitrate)
120{
121 __le32 *data = &(plcp->data);
122 __u8 *raw = plcp->raw;
123
124 if (b43_is_ofdm_rate(bitrate)) {
1a09404a
MB
125 u32 d;
126
127 d = b43_plcp_get_ratecode_ofdm(bitrate);
e4d6b795 128 B43_WARN_ON(octets & 0xF000);
1a09404a
MB
129 d |= (octets << 5);
130 *data = cpu_to_le32(d);
e4d6b795
MB
131 } else {
132 u32 plen;
133
134 plen = octets * 16 / bitrate;
135 if ((octets * 16 % bitrate) > 0) {
136 plen++;
137 if ((bitrate == B43_CCK_RATE_11MB)
138 && ((octets * 8 % 11) < 4)) {
139 raw[1] = 0x84;
140 } else
141 raw[1] = 0x04;
142 } else
143 raw[1] = 0x04;
144 *data |= cpu_to_le32(plen << 16);
145 raw[0] = b43_plcp_get_ratecode_cck(bitrate);
146 }
147}
148
149static u8 b43_calc_fallback_rate(u8 bitrate)
150{
151 switch (bitrate) {
152 case B43_CCK_RATE_1MB:
153 return B43_CCK_RATE_1MB;
154 case B43_CCK_RATE_2MB:
155 return B43_CCK_RATE_1MB;
156 case B43_CCK_RATE_5MB:
157 return B43_CCK_RATE_2MB;
158 case B43_CCK_RATE_11MB:
159 return B43_CCK_RATE_5MB;
160 case B43_OFDM_RATE_6MB:
161 return B43_CCK_RATE_5MB;
162 case B43_OFDM_RATE_9MB:
163 return B43_OFDM_RATE_6MB;
164 case B43_OFDM_RATE_12MB:
165 return B43_OFDM_RATE_9MB;
166 case B43_OFDM_RATE_18MB:
167 return B43_OFDM_RATE_12MB;
168 case B43_OFDM_RATE_24MB:
169 return B43_OFDM_RATE_18MB;
170 case B43_OFDM_RATE_36MB:
171 return B43_OFDM_RATE_24MB;
172 case B43_OFDM_RATE_48MB:
173 return B43_OFDM_RATE_36MB;
174 case B43_OFDM_RATE_54MB:
175 return B43_OFDM_RATE_48MB;
176 }
177 B43_WARN_ON(1);
178 return 0;
179}
180
eb189d8b 181/* Generate a TX data header. */
09552ccd
MB
182int b43_generate_txhdr(struct b43_wldev *dev,
183 u8 *_txhdr,
184 const unsigned char *fragment_data,
185 unsigned int fragment_len,
e6a9854b 186 struct ieee80211_tx_info *info,
09552ccd 187 u16 cookie)
e4d6b795 188{
eb189d8b 189 struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
e4d6b795
MB
190 const struct b43_phy *phy = &dev->phy;
191 const struct ieee80211_hdr *wlhdr =
192 (const struct ieee80211_hdr *)fragment_data;
d0f09804 193 int use_encryption = !!info->control.hw_key;
f37d9234 194 __le16 fctl = wlhdr->frame_control;
8318d78a 195 struct ieee80211_rate *fbrate;
e4d6b795
MB
196 u8 rate, rate_fb;
197 int rate_ofdm, rate_fb_ofdm;
198 unsigned int plcp_fragment_len;
199 u32 mac_ctl = 0;
200 u16 phy_ctl = 0;
201 u8 extra_ft = 0;
2e92e6f2 202 struct ieee80211_rate *txrate;
e6a9854b 203 struct ieee80211_tx_rate *rates;
e4d6b795
MB
204
205 memset(txhdr, 0, sizeof(*txhdr));
206
e039fa4a 207 txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
2e92e6f2 208 rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
e4d6b795 209 rate_ofdm = b43_is_ofdm_rate(rate);
870abdf6 210 fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
8318d78a 211 rate_fb = fbrate->hw_value;
e4d6b795
MB
212 rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
213
214 if (rate_ofdm)
215 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
216 else
217 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
218 txhdr->mac_frame_ctl = wlhdr->frame_control;
219 memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
220
221 /* Calculate duration for fallback rate */
222 if ((rate_fb == rate) ||
223 (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
224 (wlhdr->duration_id == cpu_to_le16(0))) {
225 /* If the fallback rate equals the normal rate or the
226 * dur_id field contains an AID, CFP magic or 0,
227 * use the original dur_id field. */
228 txhdr->dur_fb = wlhdr->duration_id;
229 } else {
e039fa4a
JB
230 txhdr->dur_fb = ieee80211_generic_frame_duration(
231 dev->wl->hw, info->control.vif, fragment_len, fbrate);
e4d6b795
MB
232 }
233
234 plcp_fragment_len = fragment_len + FCS_LEN;
235 if (use_encryption) {
e039fa4a 236 u8 key_idx = info->control.hw_key->hw_key_idx;
e4d6b795
MB
237 struct b43_key *key;
238 int wlhdr_len;
239 size_t iv_len;
240
241 B43_WARN_ON(key_idx >= dev->max_nr_keys);
242 key = &(dev->key[key_idx]);
7be1bb6b 243
09552ccd
MB
244 if (unlikely(!key->keyconf)) {
245 /* This key is invalid. This might only happen
246 * in a short timeframe after machine resume before
247 * we were able to reconfigure keys.
248 * Drop this packet completely. Do not transmit it
249 * unencrypted to avoid leaking information. */
250 return -ENOKEY;
7be1bb6b 251 }
09552ccd
MB
252
253 /* Hardware appends ICV. */
76708dee 254 plcp_fragment_len += info->control.hw_key->icv_len;
09552ccd
MB
255
256 key_idx = b43_kidx_to_fw(dev, key_idx);
257 mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
258 B43_TXH_MAC_KEYIDX;
259 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
260 B43_TXH_MAC_KEYALG;
f37d9234 261 wlhdr_len = ieee80211_hdrlen(fctl);
76708dee 262 iv_len = min((size_t) info->control.hw_key->iv_len,
09552ccd
MB
263 ARRAY_SIZE(txhdr->iv));
264 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
e4d6b795 265 }
eb189d8b
MB
266 if (b43_is_old_txhdr_format(dev)) {
267 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
268 plcp_fragment_len, rate);
269 } else {
270 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
271 plcp_fragment_len, rate);
272 }
e4d6b795
MB
273 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
274 plcp_fragment_len, rate_fb);
275
276 /* Extra Frame Types */
277 if (rate_fb_ofdm)
eb189d8b
MB
278 extra_ft |= B43_TXH_EFT_FB_OFDM;
279 else
280 extra_ft |= B43_TXH_EFT_FB_CCK;
e4d6b795
MB
281
282 /* Set channel radio code. Note that the micrcode ORs 0x100 to
283 * this value before comparing it to the value in SHM, if this
284 * is a 5Ghz packet.
285 */
286 txhdr->chan_radio_code = phy->channel;
287
288 /* PHY TX Control word */
289 if (rate_ofdm)
eb189d8b
MB
290 phy_ctl |= B43_TXH_PHY_ENC_OFDM;
291 else
292 phy_ctl |= B43_TXH_PHY_ENC_CCK;
e6a9854b 293 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
eb189d8b 294 phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
9db1f6d7 295
e039fa4a 296 switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) {
9db1f6d7 297 case 0: /* Default */
eb189d8b 298 phy_ctl |= B43_TXH_PHY_ANT01AUTO;
e4d6b795 299 break;
9db1f6d7 300 case 1: /* Antenna 0 */
eb189d8b 301 phy_ctl |= B43_TXH_PHY_ANT0;
e4d6b795 302 break;
9db1f6d7 303 case 2: /* Antenna 1 */
eb189d8b
MB
304 phy_ctl |= B43_TXH_PHY_ANT1;
305 break;
306 case 3: /* Antenna 2 */
307 phy_ctl |= B43_TXH_PHY_ANT2;
308 break;
309 case 4: /* Antenna 3 */
310 phy_ctl |= B43_TXH_PHY_ANT3;
e4d6b795
MB
311 break;
312 default:
313 B43_WARN_ON(1);
314 }
315
e6a9854b 316 rates = info->control.rates;
e4d6b795 317 /* MAC control */
e039fa4a 318 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
eb189d8b 319 mac_ctl |= B43_TXH_MAC_ACK;
f591fa5d
JB
320 /* use hardware sequence counter as the non-TID counter */
321 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
eb189d8b 322 mac_ctl |= B43_TXH_MAC_HWSEQ;
e039fa4a 323 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
eb189d8b 324 mac_ctl |= B43_TXH_MAC_STMSDU;
e4d6b795 325 if (phy->type == B43_PHYTYPE_A)
eb189d8b 326 mac_ctl |= B43_TXH_MAC_5GHZ;
e6a9854b
JB
327
328 /* Overwrite rates[0].count to make the retry calculation
329 * in the tx status easier. need the actual retry limit to
330 * detect whether the fallback rate was used.
331 */
332 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
333 (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
334 rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
eb189d8b 335 mac_ctl |= B43_TXH_MAC_LONGFRAME;
e6a9854b
JB
336 } else {
337 rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
338 }
e4d6b795
MB
339
340 /* Generate the RTS or CTS-to-self frame */
e6a9854b
JB
341 if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
342 (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
e4d6b795
MB
343 unsigned int len;
344 struct ieee80211_hdr *hdr;
345 int rts_rate, rts_rate_fb;
346 int rts_rate_ofdm, rts_rate_fb_ofdm;
eb189d8b 347 struct b43_plcp_hdr6 *plcp;
2e92e6f2 348 struct ieee80211_rate *rts_cts_rate;
e4d6b795 349
e039fa4a 350 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
2e92e6f2
JB
351
352 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
e4d6b795
MB
353 rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
354 rts_rate_fb = b43_calc_fallback_rate(rts_rate);
355 rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
356
e6a9854b 357 if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
eb189d8b
MB
358 struct ieee80211_cts *cts;
359
360 if (b43_is_old_txhdr_format(dev)) {
361 cts = (struct ieee80211_cts *)
362 (txhdr->old_format.rts_frame);
363 } else {
364 cts = (struct ieee80211_cts *)
365 (txhdr->new_format.rts_frame);
366 }
e039fa4a 367 ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
e4d6b795 368 fragment_data, fragment_len,
e039fa4a 369 info, cts);
eb189d8b 370 mac_ctl |= B43_TXH_MAC_SENDCTS;
e4d6b795
MB
371 len = sizeof(struct ieee80211_cts);
372 } else {
eb189d8b
MB
373 struct ieee80211_rts *rts;
374
375 if (b43_is_old_txhdr_format(dev)) {
376 rts = (struct ieee80211_rts *)
377 (txhdr->old_format.rts_frame);
378 } else {
379 rts = (struct ieee80211_rts *)
380 (txhdr->new_format.rts_frame);
381 }
e039fa4a 382 ieee80211_rts_get(dev->wl->hw, info->control.vif,
eb189d8b 383 fragment_data, fragment_len,
e039fa4a 384 info, rts);
eb189d8b 385 mac_ctl |= B43_TXH_MAC_SENDRTS;
e4d6b795
MB
386 len = sizeof(struct ieee80211_rts);
387 }
388 len += FCS_LEN;
eb189d8b
MB
389
390 /* Generate the PLCP headers for the RTS/CTS frame */
391 if (b43_is_old_txhdr_format(dev))
392 plcp = &txhdr->old_format.rts_plcp;
393 else
394 plcp = &txhdr->new_format.rts_plcp;
395 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
396 len, rts_rate);
397 plcp = &txhdr->rts_plcp_fb;
398 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
e4d6b795 399 len, rts_rate_fb);
eb189d8b
MB
400
401 if (b43_is_old_txhdr_format(dev)) {
402 hdr = (struct ieee80211_hdr *)
403 (&txhdr->old_format.rts_frame);
404 } else {
405 hdr = (struct ieee80211_hdr *)
406 (&txhdr->new_format.rts_frame);
407 }
e4d6b795 408 txhdr->rts_dur_fb = hdr->duration_id;
eb189d8b 409
e4d6b795 410 if (rts_rate_ofdm) {
eb189d8b 411 extra_ft |= B43_TXH_EFT_RTS_OFDM;
e4d6b795
MB
412 txhdr->phy_rate_rts =
413 b43_plcp_get_ratecode_ofdm(rts_rate);
eb189d8b
MB
414 } else {
415 extra_ft |= B43_TXH_EFT_RTS_CCK;
e4d6b795
MB
416 txhdr->phy_rate_rts =
417 b43_plcp_get_ratecode_cck(rts_rate);
eb189d8b 418 }
e4d6b795 419 if (rts_rate_fb_ofdm)
eb189d8b
MB
420 extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
421 else
422 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
e4d6b795
MB
423 }
424
425 /* Magic cookie */
eb189d8b
MB
426 if (b43_is_old_txhdr_format(dev))
427 txhdr->old_format.cookie = cpu_to_le16(cookie);
428 else
429 txhdr->new_format.cookie = cpu_to_le16(cookie);
e4d6b795
MB
430
431 /* Apply the bitfields */
432 txhdr->mac_ctl = cpu_to_le32(mac_ctl);
433 txhdr->phy_ctl = cpu_to_le16(phy_ctl);
434 txhdr->extra_ft = extra_ft;
e4d6b795 435
09552ccd 436 return 0;
e4d6b795
MB
437}
438
439static s8 b43_rssi_postprocess(struct b43_wldev *dev,
440 u8 in_rssi, int ofdm,
441 int adjust_2053, int adjust_2050)
442{
443 struct b43_phy *phy = &dev->phy;
ef1a628d 444 struct b43_phy_g *gphy = phy->g;
e4d6b795
MB
445 s32 tmp;
446
447 switch (phy->radio_ver) {
448 case 0x2050:
449 if (ofdm) {
450 tmp = in_rssi;
451 if (tmp > 127)
452 tmp -= 256;
453 tmp *= 73;
454 tmp /= 64;
455 if (adjust_2050)
456 tmp += 25;
457 else
458 tmp -= 3;
459 } else {
95de2841 460 if (dev->dev->bus->sprom.
e4d6b795
MB
461 boardflags_lo & B43_BFL_RSSI) {
462 if (in_rssi > 63)
463 in_rssi = 63;
ef1a628d
MB
464 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
465 tmp = gphy->nrssi_lt[in_rssi];
e4d6b795
MB
466 tmp = 31 - tmp;
467 tmp *= -131;
468 tmp /= 128;
469 tmp -= 57;
470 } else {
471 tmp = in_rssi;
472 tmp = 31 - tmp;
473 tmp *= -149;
474 tmp /= 128;
475 tmp -= 68;
476 }
477 if (phy->type == B43_PHYTYPE_G && adjust_2050)
478 tmp += 25;
479 }
480 break;
481 case 0x2060:
482 if (in_rssi > 127)
483 tmp = in_rssi - 256;
484 else
485 tmp = in_rssi;
486 break;
487 default:
488 tmp = in_rssi;
489 tmp -= 11;
490 tmp *= 103;
491 tmp /= 64;
492 if (adjust_2053)
493 tmp -= 109;
494 else
495 tmp -= 83;
496 }
497
498 return (s8) tmp;
499}
500
501//TODO
502#if 0
503static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
504{
505 struct b43_phy *phy = &dev->phy;
506 s8 ret;
507
508 if (phy->type == B43_PHYTYPE_A) {
509 //TODO: Incomplete specs.
510 ret = 0;
511 } else
512 ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
513
514 return ret;
515}
516#endif
517
518void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
519{
520 struct ieee80211_rx_status status;
521 struct b43_plcp_hdr6 *plcp;
522 struct ieee80211_hdr *wlhdr;
523 const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
f37d9234 524 __le16 fctl;
e4d6b795
MB
525 u16 phystat0, phystat3, chanstat, mactime;
526 u32 macstat;
527 u16 chanid;
8318d78a 528 u16 phytype;
e4d6b795
MB
529 int padding;
530
531 memset(&status, 0, sizeof(status));
532
533 /* Get metadata about the frame from the header. */
534 phystat0 = le16_to_cpu(rxhdr->phy_status0);
535 phystat3 = le16_to_cpu(rxhdr->phy_status3);
e4d6b795
MB
536 macstat = le32_to_cpu(rxhdr->mac_status);
537 mactime = le16_to_cpu(rxhdr->mac_time);
538 chanstat = le16_to_cpu(rxhdr->channel);
8318d78a 539 phytype = chanstat & B43_RX_CHAN_PHYTYPE;
e4d6b795 540
ce4fbdbf 541 if (unlikely(macstat & B43_RX_MAC_FCSERR)) {
e4d6b795 542 dev->wl->ieee_stats.dot11FCSErrorCount++;
ce4fbdbf
MB
543 status.flag |= RX_FLAG_FAILED_FCS_CRC;
544 }
545 if (unlikely(phystat0 & (B43_RX_PHYST0_PLCPHCF | B43_RX_PHYST0_PLCPFV)))
546 status.flag |= RX_FLAG_FAILED_PLCP_CRC;
547 if (phystat0 & B43_RX_PHYST0_SHORTPRMBL)
548 status.flag |= RX_FLAG_SHORTPRE;
e4d6b795
MB
549 if (macstat & B43_RX_MAC_DECERR) {
550 /* Decryption with the given key failed.
551 * Drop the packet. We also won't be able to decrypt it with
552 * the key in software. */
553 goto drop;
554 }
555
556 /* Skip PLCP and padding */
557 padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
558 if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
559 b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
560 goto drop;
561 }
562 plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
563 skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
564 /* The skb contains the Wireless Header + payload data now */
565 if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
566 b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
567 goto drop;
568 }
569 wlhdr = (struct ieee80211_hdr *)(skb->data);
f37d9234 570 fctl = wlhdr->frame_control;
e4d6b795
MB
571
572 if (macstat & B43_RX_MAC_DEC) {
573 unsigned int keyidx;
574 int wlhdr_len;
575
576 keyidx = ((macstat & B43_RX_MAC_KEYIDX)
577 >> B43_RX_MAC_KEYIDX_SHIFT);
578 /* We must adjust the key index here. We want the "physical"
579 * key index, but the ucode passed it slightly different.
580 */
581 keyidx = b43_kidx_to_raw(dev, keyidx);
582 B43_WARN_ON(keyidx >= dev->max_nr_keys);
583
584 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
f37d9234 585 wlhdr_len = ieee80211_hdrlen(fctl);
e4d6b795
MB
586 if (unlikely(skb->len < (wlhdr_len + 3))) {
587 b43dbg(dev->wl,
588 "RX: Packet size underrun (3)\n");
589 goto drop;
590 }
591 status.flag |= RX_FLAG_DECRYPTED;
592 }
593 }
594
7b584163 595 /* Link quality statistics */
e4d6b795 596 status.noise = dev->stats.link_noise;
7b584163
MB
597 if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
598// s8 rssi = max(rxhdr->power0, rxhdr->power1);
599 //TODO: Find out what the rssi value is (dBm or percentage?)
600 // and also find out what the maximum possible value is.
601 // Fill status.ssi and status.signal fields.
602 } else {
566bfe5a 603 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
7b584163
MB
604 (phystat0 & B43_RX_PHYST0_OFDM),
605 (phystat0 & B43_RX_PHYST0_GAINCTL),
606 (phystat3 & B43_RX_PHYST3_TRSTATE));
566bfe5a 607 status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
7b584163
MB
608 }
609
e4d6b795 610 if (phystat0 & B43_RX_PHYST0_OFDM)
8318d78a
JB
611 status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
612 phytype == B43_PHYTYPE_A);
e4d6b795 613 else
8318d78a 614 status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
ce4fbdbf
MB
615 if (unlikely(status.rate_idx == -1)) {
616 /* PLCP seems to be corrupted.
617 * Drop the frame, if we are not interested in corrupted frames. */
618 if (!(dev->wl->filter_flags & FIF_PLCPFAIL))
619 goto drop;
620 }
e4d6b795 621 status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
c0ddd04d
JL
622
623 /*
d007b7f4
JB
624 * All frames on monitor interfaces and beacons always need a full
625 * 64-bit timestamp. Monitor interfaces need it for diagnostic
626 * purposes and beacons for IBSS merging.
627 * This code assumes we get to process the packet within 16 bits
628 * of timestamp, i.e. about 65 milliseconds after the PHY received
629 * the first symbol.
c0ddd04d 630 */
f37d9234 631 if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
c0ddd04d
JL
632 u16 low_mactime_now;
633
634 b43_tsf_read(dev, &status.mactime);
635 low_mactime_now = status.mactime;
636 status.mactime = status.mactime & ~0xFFFFULL;
637 status.mactime += mactime;
638 if (low_mactime_now <= mactime)
639 status.mactime -= 0x10000;
640 status.flag |= RX_FLAG_TSFT;
641 }
e4d6b795
MB
642
643 chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
644 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
645 case B43_PHYTYPE_A:
8318d78a 646 status.band = IEEE80211_BAND_5GHZ;
d987160b
MB
647 B43_WARN_ON(1);
648 /* FIXME: We don't really know which value the "chanid" contains.
649 * So the following assignment might be wrong. */
8318d78a 650 status.freq = b43_channel_to_freq_5ghz(chanid);
e4d6b795
MB
651 break;
652 case B43_PHYTYPE_G:
8318d78a 653 status.band = IEEE80211_BAND_2GHZ;
d987160b
MB
654 /* chanid is the radio channel cookie value as used
655 * to tune the radio. */
e4d6b795 656 status.freq = chanid + 2400;
d987160b
MB
657 break;
658 case B43_PHYTYPE_N:
d987160b
MB
659 /* chanid is the SHM channel cookie. Which is the plain
660 * channel number in b43. */
8318d78a
JB
661 if (chanstat & B43_RX_CHAN_5GHZ) {
662 status.band = IEEE80211_BAND_5GHZ;
663 status.freq = b43_freq_to_channel_5ghz(chanid);
664 } else {
665 status.band = IEEE80211_BAND_2GHZ;
666 status.freq = b43_freq_to_channel_2ghz(chanid);
667 }
e4d6b795
MB
668 break;
669 default:
670 B43_WARN_ON(1);
d987160b 671 goto drop;
e4d6b795
MB
672 }
673
e4d6b795
MB
674 ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
675
676 return;
677drop:
678 b43dbg(dev->wl, "RX: Packet dropped\n");
679 dev_kfree_skb_any(skb);
680}
681
682void b43_handle_txstatus(struct b43_wldev *dev,
683 const struct b43_txstatus *status)
684{
685 b43_debugfs_log_txstat(dev, status);
686
687 if (status->intermediate)
688 return;
689 if (status->for_ampdu)
690 return;
691 if (!status->acked)
692 dev->wl->ieee_stats.dot11ACKFailureCount++;
693 if (status->rts_count) {
694 if (status->rts_count == 0xF) //FIXME
695 dev->wl->ieee_stats.dot11RTSFailureCount++;
696 else
697 dev->wl->ieee_stats.dot11RTSSuccessCount++;
698 }
699
5100d5ac
MB
700 if (b43_using_pio_transfers(dev))
701 b43_pio_handle_txstatus(dev, status);
702 else
703 b43_dma_handle_txstatus(dev, status);
18c8adeb
MB
704
705 b43_phy_txpower_check(dev, 0);
e4d6b795
MB
706}
707
5100d5ac
MB
708/* Fill out the mac80211 TXstatus report based on the b43-specific
709 * txstatus report data. This returns a boolean whether the frame was
710 * successfully transmitted. */
e6a9854b
JB
711bool b43_fill_txstatus_report(struct b43_wldev *dev,
712 struct ieee80211_tx_info *report,
5100d5ac 713 const struct b43_txstatus *status)
e4d6b795 714{
5100d5ac 715 bool frame_success = 1;
e6a9854b
JB
716 int retry_limit;
717
718 /* preserve the confiured retry limit before clearing the status
719 * The xmit function has overwritten the rc's value with the actual
720 * retry limit done by the hardware */
721 retry_limit = report->status.rates[0].count;
722 ieee80211_tx_info_clear_status(report);
5100d5ac
MB
723
724 if (status->acked) {
725 /* The frame was ACKed. */
e039fa4a 726 report->flags |= IEEE80211_TX_STAT_ACK;
5100d5ac
MB
727 } else {
728 /* The frame was not ACKed... */
e039fa4a 729 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
5100d5ac
MB
730 /* ...but we expected an ACK. */
731 frame_success = 0;
5100d5ac
MB
732 }
733 }
734 if (status->frame_count == 0) {
735 /* The frame was not transmitted at all. */
e6a9854b
JB
736 report->status.rates[0].count = 0;
737 } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
738 /*
739 * If the short retries (RTS, not data frame) have exceeded
740 * the limit, the hw will not have tried the selected rate,
741 * but will have used the fallback rate instead.
742 * Don't let the rate control count attempts for the selected
743 * rate in this case, otherwise the statistics will be off.
744 */
745 report->status.rates[0].count = 0;
746 report->status.rates[1].count = status->frame_count;
747 } else {
748 if (status->frame_count > retry_limit) {
749 report->status.rates[0].count = retry_limit;
750 report->status.rates[1].count = status->frame_count -
751 retry_limit;
752
753 } else {
754 report->status.rates[0].count = status->frame_count;
755 report->status.rates[1].idx = -1;
756 }
757 }
5100d5ac
MB
758
759 return frame_success;
e4d6b795
MB
760}
761
762/* Stop any TX operation on the device (suspend the hardware queues) */
763void b43_tx_suspend(struct b43_wldev *dev)
764{
5100d5ac
MB
765 if (b43_using_pio_transfers(dev))
766 b43_pio_tx_suspend(dev);
767 else
768 b43_dma_tx_suspend(dev);
e4d6b795
MB
769}
770
771/* Resume any TX operation on the device (resume the hardware queues) */
772void b43_tx_resume(struct b43_wldev *dev)
773{
5100d5ac
MB
774 if (b43_using_pio_transfers(dev))
775 b43_pio_tx_resume(dev);
776 else
777 b43_dma_tx_resume(dev);
e4d6b795 778}
This page took 0.313161 seconds and 5 git commands to generate.