Commit | Line | Data |
---|---|---|
75388acd LF |
1 | /* |
2 | ||
3 | Broadcom B43legacy 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> |
eb032b98 | 9 | Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch> |
75388acd LF |
10 | Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org> |
11 | Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch> | |
12 | Copyright (C) 2007 Larry Finger <Larry.Finger@lwfinger.net> | |
13 | ||
14 | This program is free software; you can redistribute it and/or modify | |
15 | it under the terms of the GNU General Public License as published by | |
16 | the Free Software Foundation; either version 2 of the License, or | |
17 | (at your option) any later version. | |
18 | ||
19 | This program is distributed in the hope that it will be useful, | |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
23 | ||
24 | You should have received a copy of the GNU General Public License | |
25 | along with this program; see the file COPYING. If not, write to | |
26 | the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, | |
27 | Boston, MA 02110-1301, USA. | |
28 | ||
29 | */ | |
30 | ||
31 | #include <net/dst.h> | |
32 | ||
33 | #include "xmit.h" | |
34 | #include "phy.h" | |
35 | #include "dma.h" | |
36 | #include "pio.h" | |
37 | ||
38 | ||
39 | /* Extract the bitrate out of a CCK PLCP header. */ | |
8318d78a | 40 | static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp) |
75388acd LF |
41 | { |
42 | switch (plcp->raw[0]) { | |
43 | case 0x0A: | |
8318d78a | 44 | return 0; |
75388acd | 45 | case 0x14: |
8318d78a | 46 | return 1; |
75388acd | 47 | case 0x37: |
8318d78a | 48 | return 2; |
75388acd | 49 | case 0x6E: |
8318d78a | 50 | return 3; |
75388acd LF |
51 | } |
52 | B43legacy_BUG_ON(1); | |
8318d78a | 53 | return -1; |
75388acd LF |
54 | } |
55 | ||
56 | /* Extract the bitrate out of an OFDM PLCP header. */ | |
8318d78a JB |
57 | static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp, |
58 | bool aphy) | |
75388acd | 59 | { |
8318d78a JB |
60 | int base = aphy ? 0 : 4; |
61 | ||
75388acd LF |
62 | switch (plcp->raw[0] & 0xF) { |
63 | case 0xB: | |
8318d78a | 64 | return base + 0; |
75388acd | 65 | case 0xF: |
8318d78a | 66 | return base + 1; |
75388acd | 67 | case 0xA: |
8318d78a | 68 | return base + 2; |
75388acd | 69 | case 0xE: |
8318d78a | 70 | return base + 3; |
75388acd | 71 | case 0x9: |
8318d78a | 72 | return base + 4; |
75388acd | 73 | case 0xD: |
8318d78a | 74 | return base + 5; |
75388acd | 75 | case 0x8: |
8318d78a | 76 | return base + 6; |
75388acd | 77 | case 0xC: |
8318d78a | 78 | return base + 7; |
75388acd LF |
79 | } |
80 | B43legacy_BUG_ON(1); | |
8318d78a | 81 | return -1; |
75388acd LF |
82 | } |
83 | ||
84 | u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate) | |
85 | { | |
86 | switch (bitrate) { | |
87 | case B43legacy_CCK_RATE_1MB: | |
88 | return 0x0A; | |
89 | case B43legacy_CCK_RATE_2MB: | |
90 | return 0x14; | |
91 | case B43legacy_CCK_RATE_5MB: | |
92 | return 0x37; | |
93 | case B43legacy_CCK_RATE_11MB: | |
94 | return 0x6E; | |
95 | } | |
96 | B43legacy_BUG_ON(1); | |
97 | return 0; | |
98 | } | |
99 | ||
100 | u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate) | |
101 | { | |
102 | switch (bitrate) { | |
103 | case B43legacy_OFDM_RATE_6MB: | |
104 | return 0xB; | |
105 | case B43legacy_OFDM_RATE_9MB: | |
106 | return 0xF; | |
107 | case B43legacy_OFDM_RATE_12MB: | |
108 | return 0xA; | |
109 | case B43legacy_OFDM_RATE_18MB: | |
110 | return 0xE; | |
111 | case B43legacy_OFDM_RATE_24MB: | |
112 | return 0x9; | |
113 | case B43legacy_OFDM_RATE_36MB: | |
114 | return 0xD; | |
115 | case B43legacy_OFDM_RATE_48MB: | |
116 | return 0x8; | |
117 | case B43legacy_OFDM_RATE_54MB: | |
118 | return 0xC; | |
119 | } | |
120 | B43legacy_BUG_ON(1); | |
121 | return 0; | |
122 | } | |
123 | ||
124 | void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp, | |
125 | const u16 octets, const u8 bitrate) | |
126 | { | |
127 | __le32 *data = &(plcp->data); | |
128 | __u8 *raw = plcp->raw; | |
129 | ||
130 | if (b43legacy_is_ofdm_rate(bitrate)) { | |
131 | u16 d; | |
132 | ||
133 | d = b43legacy_plcp_get_ratecode_ofdm(bitrate); | |
134 | B43legacy_WARN_ON(octets & 0xF000); | |
135 | d |= (octets << 5); | |
136 | *data = cpu_to_le32(d); | |
137 | } else { | |
138 | u32 plen; | |
139 | ||
140 | plen = octets * 16 / bitrate; | |
141 | if ((octets * 16 % bitrate) > 0) { | |
142 | plen++; | |
143 | if ((bitrate == B43legacy_CCK_RATE_11MB) | |
144 | && ((octets * 8 % 11) < 4)) | |
145 | raw[1] = 0x84; | |
146 | else | |
147 | raw[1] = 0x04; | |
148 | } else | |
149 | raw[1] = 0x04; | |
150 | *data |= cpu_to_le32(plen << 16); | |
151 | raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate); | |
152 | } | |
153 | } | |
154 | ||
155 | static u8 b43legacy_calc_fallback_rate(u8 bitrate) | |
156 | { | |
157 | switch (bitrate) { | |
158 | case B43legacy_CCK_RATE_1MB: | |
159 | return B43legacy_CCK_RATE_1MB; | |
160 | case B43legacy_CCK_RATE_2MB: | |
161 | return B43legacy_CCK_RATE_1MB; | |
162 | case B43legacy_CCK_RATE_5MB: | |
163 | return B43legacy_CCK_RATE_2MB; | |
164 | case B43legacy_CCK_RATE_11MB: | |
165 | return B43legacy_CCK_RATE_5MB; | |
166 | case B43legacy_OFDM_RATE_6MB: | |
167 | return B43legacy_CCK_RATE_5MB; | |
168 | case B43legacy_OFDM_RATE_9MB: | |
169 | return B43legacy_OFDM_RATE_6MB; | |
170 | case B43legacy_OFDM_RATE_12MB: | |
171 | return B43legacy_OFDM_RATE_9MB; | |
172 | case B43legacy_OFDM_RATE_18MB: | |
173 | return B43legacy_OFDM_RATE_12MB; | |
174 | case B43legacy_OFDM_RATE_24MB: | |
175 | return B43legacy_OFDM_RATE_18MB; | |
176 | case B43legacy_OFDM_RATE_36MB: | |
177 | return B43legacy_OFDM_RATE_24MB; | |
178 | case B43legacy_OFDM_RATE_48MB: | |
179 | return B43legacy_OFDM_RATE_36MB; | |
180 | case B43legacy_OFDM_RATE_54MB: | |
181 | return B43legacy_OFDM_RATE_48MB; | |
182 | } | |
183 | B43legacy_BUG_ON(1); | |
184 | return 0; | |
185 | } | |
186 | ||
9eca9a8e | 187 | static int generate_txhdr_fw3(struct b43legacy_wldev *dev, |
75388acd LF |
188 | struct b43legacy_txhdr_fw3 *txhdr, |
189 | const unsigned char *fragment_data, | |
190 | unsigned int fragment_len, | |
e6a9854b | 191 | struct ieee80211_tx_info *info, |
75388acd LF |
192 | u16 cookie) |
193 | { | |
194 | const struct ieee80211_hdr *wlhdr; | |
d0f09804 | 195 | int use_encryption = !!info->control.hw_key; |
75388acd | 196 | u8 rate; |
8318d78a | 197 | struct ieee80211_rate *rate_fb; |
75388acd LF |
198 | int rate_ofdm; |
199 | int rate_fb_ofdm; | |
200 | unsigned int plcp_fragment_len; | |
201 | u32 mac_ctl = 0; | |
202 | u16 phy_ctl = 0; | |
2e92e6f2 | 203 | struct ieee80211_rate *tx_rate; |
e6a9854b | 204 | struct ieee80211_tx_rate *rates; |
75388acd LF |
205 | |
206 | wlhdr = (const struct ieee80211_hdr *)fragment_data; | |
75388acd LF |
207 | |
208 | memset(txhdr, 0, sizeof(*txhdr)); | |
209 | ||
e039fa4a | 210 | tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info); |
2e92e6f2 JB |
211 | |
212 | rate = tx_rate->hw_value; | |
75388acd | 213 | rate_ofdm = b43legacy_is_ofdm_rate(rate); |
870abdf6 | 214 | rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : tx_rate; |
8318d78a | 215 | rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value); |
75388acd LF |
216 | |
217 | txhdr->mac_frame_ctl = wlhdr->frame_control; | |
218 | memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); | |
219 | ||
220 | /* Calculate duration for fallback rate */ | |
8318d78a | 221 | if ((rate_fb->hw_value == rate) || |
75388acd LF |
222 | (wlhdr->duration_id & cpu_to_le16(0x8000)) || |
223 | (wlhdr->duration_id == cpu_to_le16(0))) { | |
224 | /* If the fallback rate equals the normal rate or the | |
225 | * dur_id field contains an AID, CFP magic or 0, | |
226 | * use the original dur_id field. */ | |
227 | txhdr->dur_fb = wlhdr->duration_id; | |
228 | } else { | |
75388acd | 229 | txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, |
e039fa4a | 230 | info->control.vif, |
4ee73f33 | 231 | info->band, |
75388acd | 232 | fragment_len, |
8318d78a | 233 | rate_fb); |
75388acd LF |
234 | } |
235 | ||
236 | plcp_fragment_len = fragment_len + FCS_LEN; | |
237 | if (use_encryption) { | |
e039fa4a | 238 | u8 key_idx = info->control.hw_key->hw_key_idx; |
75388acd LF |
239 | struct b43legacy_key *key; |
240 | int wlhdr_len; | |
241 | size_t iv_len; | |
242 | ||
243 | B43legacy_WARN_ON(key_idx >= dev->max_nr_keys); | |
244 | key = &(dev->key[key_idx]); | |
245 | ||
246 | if (key->enabled) { | |
247 | /* Hardware appends ICV. */ | |
76708dee | 248 | plcp_fragment_len += info->control.hw_key->icv_len; |
75388acd LF |
249 | |
250 | key_idx = b43legacy_kidx_to_fw(dev, key_idx); | |
251 | mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) & | |
252 | B43legacy_TX4_MAC_KEYIDX; | |
253 | mac_ctl |= (key->algorithm << | |
254 | B43legacy_TX4_MAC_KEYALG_SHIFT) & | |
255 | B43legacy_TX4_MAC_KEYALG; | |
ba5b6efe | 256 | wlhdr_len = ieee80211_hdrlen(wlhdr->frame_control); |
76708dee | 257 | iv_len = min((size_t)info->control.hw_key->iv_len, |
75388acd LF |
258 | ARRAY_SIZE(txhdr->iv)); |
259 | memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len); | |
9eca9a8e SB |
260 | } else { |
261 | /* This key is invalid. This might only happen | |
262 | * in a short timeframe after machine resume before | |
263 | * we were able to reconfigure keys. | |
264 | * Drop this packet completely. Do not transmit it | |
265 | * unencrypted to avoid leaking information. */ | |
266 | return -ENOKEY; | |
75388acd LF |
267 | } |
268 | } | |
269 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | |
270 | (&txhdr->plcp), plcp_fragment_len, | |
271 | rate); | |
272 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | |
273 | (&txhdr->plcp_fb), plcp_fragment_len, | |
8318d78a | 274 | rate_fb->hw_value); |
75388acd LF |
275 | |
276 | /* PHY TX Control word */ | |
277 | if (rate_ofdm) | |
2d1f96dd | 278 | phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM; |
e6a9854b | 279 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
75388acd | 280 | phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL; |
d748b464 | 281 | phy_ctl |= B43legacy_TX4_PHY_ANTLAST; |
75388acd LF |
282 | |
283 | /* MAC control */ | |
e6a9854b | 284 | rates = info->control.rates; |
e039fa4a | 285 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) |
75388acd | 286 | mac_ctl |= B43legacy_TX4_MAC_ACK; |
f591fa5d | 287 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) |
75388acd | 288 | mac_ctl |= B43legacy_TX4_MAC_HWSEQ; |
e039fa4a | 289 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
75388acd LF |
290 | mac_ctl |= B43legacy_TX4_MAC_STMSDU; |
291 | if (rate_fb_ofdm) | |
292 | mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM; | |
e6a9854b JB |
293 | |
294 | /* Overwrite rates[0].count to make the retry calculation | |
295 | * in the tx status easier. need the actual retry limit to | |
296 | * detect whether the fallback rate was used. | |
297 | */ | |
298 | if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || | |
299 | (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) { | |
300 | rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count; | |
0a6e1bee | 301 | mac_ctl |= B43legacy_TX4_MAC_LONGFRAME; |
e6a9854b JB |
302 | } else { |
303 | rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count; | |
304 | } | |
75388acd LF |
305 | |
306 | /* Generate the RTS or CTS-to-self frame */ | |
e6a9854b JB |
307 | if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || |
308 | (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) { | |
75388acd LF |
309 | unsigned int len; |
310 | struct ieee80211_hdr *hdr; | |
311 | int rts_rate; | |
312 | int rts_rate_fb; | |
75388acd LF |
313 | int rts_rate_fb_ofdm; |
314 | ||
e039fa4a | 315 | rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value; |
75388acd LF |
316 | rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate); |
317 | rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb); | |
318 | if (rts_rate_fb_ofdm) | |
319 | mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM; | |
320 | ||
e6a9854b | 321 | if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
75388acd | 322 | ieee80211_ctstoself_get(dev->wl->hw, |
e039fa4a | 323 | info->control.vif, |
75388acd | 324 | fragment_data, |
e039fa4a | 325 | fragment_len, info, |
75388acd LF |
326 | (struct ieee80211_cts *) |
327 | (txhdr->rts_frame)); | |
328 | mac_ctl |= B43legacy_TX4_MAC_SENDCTS; | |
329 | len = sizeof(struct ieee80211_cts); | |
330 | } else { | |
331 | ieee80211_rts_get(dev->wl->hw, | |
e039fa4a JB |
332 | info->control.vif, |
333 | fragment_data, fragment_len, info, | |
75388acd LF |
334 | (struct ieee80211_rts *) |
335 | (txhdr->rts_frame)); | |
336 | mac_ctl |= B43legacy_TX4_MAC_SENDRTS; | |
337 | len = sizeof(struct ieee80211_rts); | |
338 | } | |
339 | len += FCS_LEN; | |
340 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | |
341 | (&txhdr->rts_plcp), | |
342 | len, rts_rate); | |
343 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | |
344 | (&txhdr->rts_plcp_fb), | |
345 | len, rts_rate_fb); | |
346 | hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame); | |
347 | txhdr->rts_dur_fb = hdr->duration_id; | |
75388acd LF |
348 | } |
349 | ||
350 | /* Magic cookie */ | |
351 | txhdr->cookie = cpu_to_le16(cookie); | |
352 | ||
353 | /* Apply the bitfields */ | |
354 | txhdr->mac_ctl = cpu_to_le32(mac_ctl); | |
355 | txhdr->phy_ctl = cpu_to_le16(phy_ctl); | |
9eca9a8e SB |
356 | |
357 | return 0; | |
75388acd LF |
358 | } |
359 | ||
9eca9a8e | 360 | int b43legacy_generate_txhdr(struct b43legacy_wldev *dev, |
75388acd LF |
361 | u8 *txhdr, |
362 | const unsigned char *fragment_data, | |
363 | unsigned int fragment_len, | |
e6a9854b | 364 | struct ieee80211_tx_info *info, |
75388acd LF |
365 | u16 cookie) |
366 | { | |
9eca9a8e | 367 | return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr, |
75388acd | 368 | fragment_data, fragment_len, |
e039fa4a | 369 | info, cookie); |
75388acd LF |
370 | } |
371 | ||
372 | static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev, | |
373 | u8 in_rssi, int ofdm, | |
374 | int adjust_2053, int adjust_2050) | |
375 | { | |
376 | struct b43legacy_phy *phy = &dev->phy; | |
377 | s32 tmp; | |
378 | ||
379 | switch (phy->radio_ver) { | |
380 | case 0x2050: | |
381 | if (ofdm) { | |
382 | tmp = in_rssi; | |
383 | if (tmp > 127) | |
384 | tmp -= 256; | |
385 | tmp *= 73; | |
386 | tmp /= 64; | |
387 | if (adjust_2050) | |
388 | tmp += 25; | |
389 | else | |
390 | tmp -= 3; | |
391 | } else { | |
7797aa38 | 392 | if (dev->dev->bus->sprom.boardflags_lo |
75388acd LF |
393 | & B43legacy_BFL_RSSI) { |
394 | if (in_rssi > 63) | |
395 | in_rssi = 63; | |
396 | tmp = phy->nrssi_lt[in_rssi]; | |
397 | tmp = 31 - tmp; | |
398 | tmp *= -131; | |
399 | tmp /= 128; | |
400 | tmp -= 57; | |
401 | } else { | |
402 | tmp = in_rssi; | |
403 | tmp = 31 - tmp; | |
404 | tmp *= -149; | |
405 | tmp /= 128; | |
406 | tmp -= 68; | |
407 | } | |
408 | if (phy->type == B43legacy_PHYTYPE_G && | |
409 | adjust_2050) | |
410 | tmp += 25; | |
411 | } | |
412 | break; | |
413 | case 0x2060: | |
414 | if (in_rssi > 127) | |
415 | tmp = in_rssi - 256; | |
416 | else | |
417 | tmp = in_rssi; | |
418 | break; | |
419 | default: | |
420 | tmp = in_rssi; | |
421 | tmp -= 11; | |
422 | tmp *= 103; | |
423 | tmp /= 64; | |
424 | if (adjust_2053) | |
425 | tmp -= 109; | |
426 | else | |
427 | tmp -= 83; | |
428 | } | |
429 | ||
430 | return (s8)tmp; | |
431 | } | |
432 | ||
433 | void b43legacy_rx(struct b43legacy_wldev *dev, | |
434 | struct sk_buff *skb, | |
435 | const void *_rxhdr) | |
436 | { | |
437 | struct ieee80211_rx_status status; | |
438 | struct b43legacy_plcp_hdr6 *plcp; | |
439 | struct ieee80211_hdr *wlhdr; | |
440 | const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr; | |
b99a017c | 441 | __le16 fctl; |
75388acd LF |
442 | u16 phystat0; |
443 | u16 phystat3; | |
444 | u16 chanstat; | |
445 | u16 mactime; | |
446 | u32 macstat; | |
447 | u16 chanid; | |
448 | u8 jssi; | |
449 | int padding; | |
450 | ||
451 | memset(&status, 0, sizeof(status)); | |
452 | ||
453 | /* Get metadata about the frame from the header. */ | |
454 | phystat0 = le16_to_cpu(rxhdr->phy_status0); | |
455 | phystat3 = le16_to_cpu(rxhdr->phy_status3); | |
456 | jssi = rxhdr->jssi; | |
457 | macstat = le16_to_cpu(rxhdr->mac_status); | |
458 | mactime = le16_to_cpu(rxhdr->mac_time); | |
459 | chanstat = le16_to_cpu(rxhdr->channel); | |
460 | ||
461 | if (macstat & B43legacy_RX_MAC_FCSERR) | |
462 | dev->wl->ieee_stats.dot11FCSErrorCount++; | |
463 | ||
464 | /* Skip PLCP and padding */ | |
465 | padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0; | |
466 | if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) + | |
467 | padding))) { | |
468 | b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n"); | |
469 | goto drop; | |
470 | } | |
471 | plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding); | |
472 | skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding); | |
473 | /* The skb contains the Wireless Header + payload data now */ | |
474 | if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) { | |
475 | b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n"); | |
476 | goto drop; | |
477 | } | |
478 | wlhdr = (struct ieee80211_hdr *)(skb->data); | |
b99a017c | 479 | fctl = wlhdr->frame_control; |
75388acd LF |
480 | |
481 | if ((macstat & B43legacy_RX_MAC_DEC) && | |
482 | !(macstat & B43legacy_RX_MAC_DECERR)) { | |
483 | unsigned int keyidx; | |
484 | int wlhdr_len; | |
485 | int iv_len; | |
486 | int icv_len; | |
487 | ||
488 | keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX) | |
489 | >> B43legacy_RX_MAC_KEYIDX_SHIFT); | |
490 | /* We must adjust the key index here. We want the "physical" | |
491 | * key index, but the ucode passed it slightly different. | |
492 | */ | |
493 | keyidx = b43legacy_kidx_to_raw(dev, keyidx); | |
494 | B43legacy_WARN_ON(keyidx >= dev->max_nr_keys); | |
495 | ||
496 | if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) { | |
497 | /* Remove PROTECTED flag to mark it as decrypted. */ | |
b99a017c HH |
498 | B43legacy_WARN_ON(!ieee80211_has_protected(fctl)); |
499 | fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
500 | wlhdr->frame_control = fctl; | |
75388acd | 501 | |
b99a017c | 502 | wlhdr_len = ieee80211_hdrlen(fctl); |
75388acd LF |
503 | if (unlikely(skb->len < (wlhdr_len + 3))) { |
504 | b43legacydbg(dev->wl, "RX: Packet size" | |
505 | " underrun3\n"); | |
506 | goto drop; | |
507 | } | |
508 | if (skb->data[wlhdr_len + 3] & (1 << 5)) { | |
509 | /* The Ext-IV Bit is set in the "KeyID" | |
510 | * octet of the IV. | |
511 | */ | |
512 | iv_len = 8; | |
513 | icv_len = 8; | |
514 | } else { | |
515 | iv_len = 4; | |
516 | icv_len = 4; | |
517 | } | |
518 | if (unlikely(skb->len < (wlhdr_len + iv_len + | |
519 | icv_len))) { | |
520 | b43legacydbg(dev->wl, "RX: Packet size" | |
521 | " underrun4\n"); | |
522 | goto drop; | |
523 | } | |
524 | /* Remove the IV */ | |
525 | memmove(skb->data + iv_len, skb->data, wlhdr_len); | |
526 | skb_pull(skb, iv_len); | |
527 | /* Remove the ICV */ | |
528 | skb_trim(skb, skb->len - icv_len); | |
529 | ||
530 | status.flag |= RX_FLAG_DECRYPTED; | |
531 | } | |
532 | } | |
533 | ||
566bfe5a | 534 | status.signal = b43legacy_rssi_postprocess(dev, jssi, |
75388acd LF |
535 | (phystat0 & B43legacy_RX_PHYST0_OFDM), |
536 | (phystat0 & B43legacy_RX_PHYST0_GAINCTL), | |
537 | (phystat3 & B43legacy_RX_PHYST3_TRSTATE)); | |
8318d78a | 538 | /* change to support A PHY */ |
75388acd | 539 | if (phystat0 & B43legacy_RX_PHYST0_OFDM) |
8318d78a | 540 | status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false); |
75388acd | 541 | else |
8318d78a | 542 | status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp); |
75388acd | 543 | status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT); |
c0ddd04d JL |
544 | |
545 | /* | |
d007b7f4 JB |
546 | * All frames on monitor interfaces and beacons always need a full |
547 | * 64-bit timestamp. Monitor interfaces need it for diagnostic | |
548 | * purposes and beacons for IBSS merging. | |
549 | * This code assumes we get to process the packet within 16 bits | |
550 | * of timestamp, i.e. about 65 milliseconds after the PHY received | |
551 | * the first symbol. | |
c0ddd04d | 552 | */ |
b99a017c | 553 | if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) { |
c0ddd04d JL |
554 | u16 low_mactime_now; |
555 | ||
556 | b43legacy_tsf_read(dev, &status.mactime); | |
557 | low_mactime_now = status.mactime; | |
558 | status.mactime = status.mactime & ~0xFFFFULL; | |
559 | status.mactime += mactime; | |
560 | if (low_mactime_now <= mactime) | |
561 | status.mactime -= 0x10000; | |
6ebacbb7 | 562 | status.flag |= RX_FLAG_MACTIME_MPDU; |
c0ddd04d | 563 | } |
75388acd LF |
564 | |
565 | chanid = (chanstat & B43legacy_RX_CHAN_ID) >> | |
566 | B43legacy_RX_CHAN_ID_SHIFT; | |
567 | switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) { | |
568 | case B43legacy_PHYTYPE_B: | |
75388acd | 569 | case B43legacy_PHYTYPE_G: |
8318d78a | 570 | status.band = IEEE80211_BAND_2GHZ; |
75388acd | 571 | status.freq = chanid + 2400; |
75388acd LF |
572 | break; |
573 | default: | |
574 | b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n", | |
575 | chanstat); | |
576 | } | |
577 | ||
f1d58c25 JB |
578 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
579 | ieee80211_rx_irqsafe(dev->wl->hw, skb); | |
75388acd LF |
580 | |
581 | return; | |
582 | drop: | |
583 | b43legacydbg(dev->wl, "RX: Packet dropped\n"); | |
584 | dev_kfree_skb_any(skb); | |
585 | } | |
586 | ||
587 | void b43legacy_handle_txstatus(struct b43legacy_wldev *dev, | |
588 | const struct b43legacy_txstatus *status) | |
589 | { | |
590 | b43legacy_debugfs_log_txstat(dev, status); | |
591 | ||
592 | if (status->intermediate) | |
593 | return; | |
594 | if (status->for_ampdu) | |
595 | return; | |
596 | if (!status->acked) | |
597 | dev->wl->ieee_stats.dot11ACKFailureCount++; | |
598 | if (status->rts_count) { | |
599 | if (status->rts_count == 0xF) /* FIXME */ | |
600 | dev->wl->ieee_stats.dot11RTSFailureCount++; | |
601 | else | |
602 | dev->wl->ieee_stats.dot11RTSSuccessCount++; | |
603 | } | |
604 | ||
605 | if (b43legacy_using_pio(dev)) | |
606 | b43legacy_pio_handle_txstatus(dev, status); | |
607 | else | |
608 | b43legacy_dma_handle_txstatus(dev, status); | |
609 | } | |
610 | ||
611 | /* Handle TX status report as received through DMA/PIO queues */ | |
612 | void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev, | |
613 | const struct b43legacy_hwtxstatus *hw) | |
614 | { | |
615 | struct b43legacy_txstatus status; | |
616 | u8 tmp; | |
617 | ||
618 | status.cookie = le16_to_cpu(hw->cookie); | |
619 | status.seq = le16_to_cpu(hw->seq); | |
620 | status.phy_stat = hw->phy_stat; | |
621 | tmp = hw->count; | |
622 | status.frame_count = (tmp >> 4); | |
623 | status.rts_count = (tmp & 0x0F); | |
c6a2afda | 624 | tmp = hw->flags << 1; |
75388acd LF |
625 | status.supp_reason = ((tmp & 0x1C) >> 2); |
626 | status.pm_indicated = !!(tmp & 0x80); | |
627 | status.intermediate = !!(tmp & 0x40); | |
628 | status.for_ampdu = !!(tmp & 0x20); | |
629 | status.acked = !!(tmp & 0x02); | |
630 | ||
631 | b43legacy_handle_txstatus(dev, &status); | |
632 | } | |
633 | ||
634 | /* Stop any TX operation on the device (suspend the hardware queues) */ | |
635 | void b43legacy_tx_suspend(struct b43legacy_wldev *dev) | |
636 | { | |
637 | if (b43legacy_using_pio(dev)) | |
638 | b43legacy_pio_freeze_txqueues(dev); | |
639 | else | |
640 | b43legacy_dma_tx_suspend(dev); | |
641 | } | |
642 | ||
643 | /* Resume any TX operation on the device (resume the hardware queues) */ | |
644 | void b43legacy_tx_resume(struct b43legacy_wldev *dev) | |
645 | { | |
646 | if (b43legacy_using_pio(dev)) | |
647 | b43legacy_pio_thaw_txqueues(dev); | |
648 | else | |
649 | b43legacy_dma_tx_resume(dev); | |
650 | } | |
651 | ||
652 | /* Initialize the QoS parameters */ | |
653 | void b43legacy_qos_init(struct b43legacy_wldev *dev) | |
654 | { | |
655 | /* FIXME: This function must probably be called from the mac80211 | |
656 | * config callback. */ | |
657 | return; | |
658 | ||
659 | b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF); | |
660 | /* FIXME kill magic */ | |
661 | b43legacy_write16(dev, 0x688, | |
662 | b43legacy_read16(dev, 0x688) | 0x4); | |
663 | ||
664 | ||
665 | /*TODO: We might need some stack support here to get the values. */ | |
666 | } |