diff options
author | Larry Finger <Larry.Finger@lwfinger.net> | 2007-09-25 19:46:54 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:51:38 -0400 |
commit | 75388acd0cd827dc1498043daa7d1c760902cd67 (patch) | |
tree | 43fac7501291145963444e439f2ff30b9e5726e3 /drivers/net/wireless/b43legacy/xmit.c | |
parent | e4d6b7951812d98417feb10784e400e253caf633 (diff) |
[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/b43legacy/xmit.c')
-rw-r--r-- | drivers/net/wireless/b43legacy/xmit.c | 642 |
1 files changed, 642 insertions, 0 deletions
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c new file mode 100644 index 000000000000..fa1e65687a63 --- /dev/null +++ b/drivers/net/wireless/b43legacy/xmit.c | |||
@@ -0,0 +1,642 @@ | |||
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> | ||
8 | Copyright (C) 2005 Stefano Brivio <st3@riseup.net> | ||
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 | 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. */ | ||
40 | static u8 b43legacy_plcp_get_bitrate_cck(struct b43legacy_plcp_hdr6 *plcp) | ||
41 | { | ||
42 | switch (plcp->raw[0]) { | ||
43 | case 0x0A: | ||
44 | return B43legacy_CCK_RATE_1MB; | ||
45 | case 0x14: | ||
46 | return B43legacy_CCK_RATE_2MB; | ||
47 | case 0x37: | ||
48 | return B43legacy_CCK_RATE_5MB; | ||
49 | case 0x6E: | ||
50 | return B43legacy_CCK_RATE_11MB; | ||
51 | } | ||
52 | B43legacy_BUG_ON(1); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | /* Extract the bitrate out of an OFDM PLCP header. */ | ||
57 | static u8 b43legacy_plcp_get_bitrate_ofdm(struct b43legacy_plcp_hdr6 *plcp) | ||
58 | { | ||
59 | switch (plcp->raw[0] & 0xF) { | ||
60 | case 0xB: | ||
61 | return B43legacy_OFDM_RATE_6MB; | ||
62 | case 0xF: | ||
63 | return B43legacy_OFDM_RATE_9MB; | ||
64 | case 0xA: | ||
65 | return B43legacy_OFDM_RATE_12MB; | ||
66 | case 0xE: | ||
67 | return B43legacy_OFDM_RATE_18MB; | ||
68 | case 0x9: | ||
69 | return B43legacy_OFDM_RATE_24MB; | ||
70 | case 0xD: | ||
71 | return B43legacy_OFDM_RATE_36MB; | ||
72 | case 0x8: | ||
73 | return B43legacy_OFDM_RATE_48MB; | ||
74 | case 0xC: | ||
75 | return B43legacy_OFDM_RATE_54MB; | ||
76 | } | ||
77 | B43legacy_BUG_ON(1); | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate) | ||
82 | { | ||
83 | switch (bitrate) { | ||
84 | case B43legacy_CCK_RATE_1MB: | ||
85 | return 0x0A; | ||
86 | case B43legacy_CCK_RATE_2MB: | ||
87 | return 0x14; | ||
88 | case B43legacy_CCK_RATE_5MB: | ||
89 | return 0x37; | ||
90 | case B43legacy_CCK_RATE_11MB: | ||
91 | return 0x6E; | ||
92 | } | ||
93 | B43legacy_BUG_ON(1); | ||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate) | ||
98 | { | ||
99 | switch (bitrate) { | ||
100 | case B43legacy_OFDM_RATE_6MB: | ||
101 | return 0xB; | ||
102 | case B43legacy_OFDM_RATE_9MB: | ||
103 | return 0xF; | ||
104 | case B43legacy_OFDM_RATE_12MB: | ||
105 | return 0xA; | ||
106 | case B43legacy_OFDM_RATE_18MB: | ||
107 | return 0xE; | ||
108 | case B43legacy_OFDM_RATE_24MB: | ||
109 | return 0x9; | ||
110 | case B43legacy_OFDM_RATE_36MB: | ||
111 | return 0xD; | ||
112 | case B43legacy_OFDM_RATE_48MB: | ||
113 | return 0x8; | ||
114 | case B43legacy_OFDM_RATE_54MB: | ||
115 | return 0xC; | ||
116 | } | ||
117 | B43legacy_BUG_ON(1); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp, | ||
122 | const u16 octets, const u8 bitrate) | ||
123 | { | ||
124 | __le32 *data = &(plcp->data); | ||
125 | __u8 *raw = plcp->raw; | ||
126 | |||
127 | if (b43legacy_is_ofdm_rate(bitrate)) { | ||
128 | u16 d; | ||
129 | |||
130 | d = b43legacy_plcp_get_ratecode_ofdm(bitrate); | ||
131 | B43legacy_WARN_ON(octets & 0xF000); | ||
132 | d |= (octets << 5); | ||
133 | *data = cpu_to_le32(d); | ||
134 | } else { | ||
135 | u32 plen; | ||
136 | |||
137 | plen = octets * 16 / bitrate; | ||
138 | if ((octets * 16 % bitrate) > 0) { | ||
139 | plen++; | ||
140 | if ((bitrate == B43legacy_CCK_RATE_11MB) | ||
141 | && ((octets * 8 % 11) < 4)) | ||
142 | raw[1] = 0x84; | ||
143 | else | ||
144 | raw[1] = 0x04; | ||
145 | } else | ||
146 | raw[1] = 0x04; | ||
147 | *data |= cpu_to_le32(plen << 16); | ||
148 | raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | static u8 b43legacy_calc_fallback_rate(u8 bitrate) | ||
153 | { | ||
154 | switch (bitrate) { | ||
155 | case B43legacy_CCK_RATE_1MB: | ||
156 | return B43legacy_CCK_RATE_1MB; | ||
157 | case B43legacy_CCK_RATE_2MB: | ||
158 | return B43legacy_CCK_RATE_1MB; | ||
159 | case B43legacy_CCK_RATE_5MB: | ||
160 | return B43legacy_CCK_RATE_2MB; | ||
161 | case B43legacy_CCK_RATE_11MB: | ||
162 | return B43legacy_CCK_RATE_5MB; | ||
163 | case B43legacy_OFDM_RATE_6MB: | ||
164 | return B43legacy_CCK_RATE_5MB; | ||
165 | case B43legacy_OFDM_RATE_9MB: | ||
166 | return B43legacy_OFDM_RATE_6MB; | ||
167 | case B43legacy_OFDM_RATE_12MB: | ||
168 | return B43legacy_OFDM_RATE_9MB; | ||
169 | case B43legacy_OFDM_RATE_18MB: | ||
170 | return B43legacy_OFDM_RATE_12MB; | ||
171 | case B43legacy_OFDM_RATE_24MB: | ||
172 | return B43legacy_OFDM_RATE_18MB; | ||
173 | case B43legacy_OFDM_RATE_36MB: | ||
174 | return B43legacy_OFDM_RATE_24MB; | ||
175 | case B43legacy_OFDM_RATE_48MB: | ||
176 | return B43legacy_OFDM_RATE_36MB; | ||
177 | case B43legacy_OFDM_RATE_54MB: | ||
178 | return B43legacy_OFDM_RATE_48MB; | ||
179 | } | ||
180 | B43legacy_BUG_ON(1); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static void generate_txhdr_fw3(struct b43legacy_wldev *dev, | ||
185 | struct b43legacy_txhdr_fw3 *txhdr, | ||
186 | const unsigned char *fragment_data, | ||
187 | unsigned int fragment_len, | ||
188 | const struct ieee80211_tx_control *txctl, | ||
189 | u16 cookie) | ||
190 | { | ||
191 | const struct ieee80211_hdr *wlhdr; | ||
192 | int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)); | ||
193 | u16 fctl; | ||
194 | u8 rate; | ||
195 | u8 rate_fb; | ||
196 | int rate_ofdm; | ||
197 | int rate_fb_ofdm; | ||
198 | unsigned int plcp_fragment_len; | ||
199 | u32 mac_ctl = 0; | ||
200 | u16 phy_ctl = 0; | ||
201 | |||
202 | wlhdr = (const struct ieee80211_hdr *)fragment_data; | ||
203 | fctl = le16_to_cpu(wlhdr->frame_control); | ||
204 | |||
205 | memset(txhdr, 0, sizeof(*txhdr)); | ||
206 | |||
207 | rate = txctl->tx_rate; | ||
208 | rate_ofdm = b43legacy_is_ofdm_rate(rate); | ||
209 | rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate; | ||
210 | rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb); | ||
211 | |||
212 | txhdr->mac_frame_ctl = wlhdr->frame_control; | ||
213 | memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); | ||
214 | |||
215 | /* Calculate duration for fallback rate */ | ||
216 | if ((rate_fb == rate) || | ||
217 | (wlhdr->duration_id & cpu_to_le16(0x8000)) || | ||
218 | (wlhdr->duration_id == cpu_to_le16(0))) { | ||
219 | /* If the fallback rate equals the normal rate or the | ||
220 | * dur_id field contains an AID, CFP magic or 0, | ||
221 | * use the original dur_id field. */ | ||
222 | txhdr->dur_fb = wlhdr->duration_id; | ||
223 | } else { | ||
224 | int fbrate_base100kbps = B43legacy_RATE_TO_100KBPS(rate_fb); | ||
225 | txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, | ||
226 | dev->wl->if_id, | ||
227 | fragment_len, | ||
228 | fbrate_base100kbps); | ||
229 | } | ||
230 | |||
231 | plcp_fragment_len = fragment_len + FCS_LEN; | ||
232 | if (use_encryption) { | ||
233 | u8 key_idx = (u16)(txctl->key_idx); | ||
234 | struct b43legacy_key *key; | ||
235 | int wlhdr_len; | ||
236 | size_t iv_len; | ||
237 | |||
238 | B43legacy_WARN_ON(key_idx >= dev->max_nr_keys); | ||
239 | key = &(dev->key[key_idx]); | ||
240 | |||
241 | if (key->enabled) { | ||
242 | /* Hardware appends ICV. */ | ||
243 | plcp_fragment_len += txctl->icv_len; | ||
244 | |||
245 | key_idx = b43legacy_kidx_to_fw(dev, key_idx); | ||
246 | mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) & | ||
247 | B43legacy_TX4_MAC_KEYIDX; | ||
248 | mac_ctl |= (key->algorithm << | ||
249 | B43legacy_TX4_MAC_KEYALG_SHIFT) & | ||
250 | B43legacy_TX4_MAC_KEYALG; | ||
251 | wlhdr_len = ieee80211_get_hdrlen(fctl); | ||
252 | iv_len = min((size_t)txctl->iv_len, | ||
253 | ARRAY_SIZE(txhdr->iv)); | ||
254 | memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len); | ||
255 | } | ||
256 | } | ||
257 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | ||
258 | (&txhdr->plcp), plcp_fragment_len, | ||
259 | rate); | ||
260 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | ||
261 | (&txhdr->plcp_fb), plcp_fragment_len, | ||
262 | rate_fb); | ||
263 | |||
264 | /* PHY TX Control word */ | ||
265 | if (rate_ofdm) | ||
266 | phy_ctl |= B43legacy_TX4_PHY_OFDM; | ||
267 | if (dev->short_preamble) | ||
268 | phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL; | ||
269 | switch (txctl->antenna_sel_tx) { | ||
270 | case 0: | ||
271 | phy_ctl |= B43legacy_TX4_PHY_ANTLAST; | ||
272 | break; | ||
273 | case 1: | ||
274 | phy_ctl |= B43legacy_TX4_PHY_ANT0; | ||
275 | break; | ||
276 | case 2: | ||
277 | phy_ctl |= B43legacy_TX4_PHY_ANT1; | ||
278 | break; | ||
279 | default: | ||
280 | B43legacy_BUG_ON(1); | ||
281 | } | ||
282 | |||
283 | /* MAC control */ | ||
284 | if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK)) | ||
285 | mac_ctl |= B43legacy_TX4_MAC_ACK; | ||
286 | if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && | ||
287 | ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) | ||
288 | mac_ctl |= B43legacy_TX4_MAC_HWSEQ; | ||
289 | if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT) | ||
290 | mac_ctl |= B43legacy_TX4_MAC_STMSDU; | ||
291 | if (rate_fb_ofdm) | ||
292 | mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM; | ||
293 | |||
294 | /* Generate the RTS or CTS-to-self frame */ | ||
295 | if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) || | ||
296 | (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) { | ||
297 | unsigned int len; | ||
298 | struct ieee80211_hdr *hdr; | ||
299 | int rts_rate; | ||
300 | int rts_rate_fb; | ||
301 | int rts_rate_ofdm; | ||
302 | int rts_rate_fb_ofdm; | ||
303 | |||
304 | rts_rate = txctl->rts_cts_rate; | ||
305 | rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate); | ||
306 | rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate); | ||
307 | rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb); | ||
308 | if (rts_rate_fb_ofdm) | ||
309 | mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM; | ||
310 | |||
311 | if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { | ||
312 | ieee80211_ctstoself_get(dev->wl->hw, | ||
313 | dev->wl->if_id, | ||
314 | fragment_data, | ||
315 | fragment_len, txctl, | ||
316 | (struct ieee80211_cts *) | ||
317 | (txhdr->rts_frame)); | ||
318 | mac_ctl |= B43legacy_TX4_MAC_SENDCTS; | ||
319 | len = sizeof(struct ieee80211_cts); | ||
320 | } else { | ||
321 | ieee80211_rts_get(dev->wl->hw, | ||
322 | dev->wl->if_id, | ||
323 | fragment_data, fragment_len, txctl, | ||
324 | (struct ieee80211_rts *) | ||
325 | (txhdr->rts_frame)); | ||
326 | mac_ctl |= B43legacy_TX4_MAC_SENDRTS; | ||
327 | len = sizeof(struct ieee80211_rts); | ||
328 | } | ||
329 | len += FCS_LEN; | ||
330 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | ||
331 | (&txhdr->rts_plcp), | ||
332 | len, rts_rate); | ||
333 | b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *) | ||
334 | (&txhdr->rts_plcp_fb), | ||
335 | len, rts_rate_fb); | ||
336 | hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame); | ||
337 | txhdr->rts_dur_fb = hdr->duration_id; | ||
338 | mac_ctl |= B43legacy_TX4_MAC_LONGFRAME; | ||
339 | } | ||
340 | |||
341 | /* Magic cookie */ | ||
342 | txhdr->cookie = cpu_to_le16(cookie); | ||
343 | |||
344 | /* Apply the bitfields */ | ||
345 | txhdr->mac_ctl = cpu_to_le32(mac_ctl); | ||
346 | txhdr->phy_ctl = cpu_to_le16(phy_ctl); | ||
347 | } | ||
348 | |||
349 | void b43legacy_generate_txhdr(struct b43legacy_wldev *dev, | ||
350 | u8 *txhdr, | ||
351 | const unsigned char *fragment_data, | ||
352 | unsigned int fragment_len, | ||
353 | const struct ieee80211_tx_control *txctl, | ||
354 | u16 cookie) | ||
355 | { | ||
356 | generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr, | ||
357 | fragment_data, fragment_len, | ||
358 | txctl, cookie); | ||
359 | } | ||
360 | |||
361 | static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev, | ||
362 | u8 in_rssi, int ofdm, | ||
363 | int adjust_2053, int adjust_2050) | ||
364 | { | ||
365 | struct b43legacy_phy *phy = &dev->phy; | ||
366 | s32 tmp; | ||
367 | |||
368 | switch (phy->radio_ver) { | ||
369 | case 0x2050: | ||
370 | if (ofdm) { | ||
371 | tmp = in_rssi; | ||
372 | if (tmp > 127) | ||
373 | tmp -= 256; | ||
374 | tmp *= 73; | ||
375 | tmp /= 64; | ||
376 | if (adjust_2050) | ||
377 | tmp += 25; | ||
378 | else | ||
379 | tmp -= 3; | ||
380 | } else { | ||
381 | if (dev->dev->bus->sprom.r1.boardflags_lo | ||
382 | & B43legacy_BFL_RSSI) { | ||
383 | if (in_rssi > 63) | ||
384 | in_rssi = 63; | ||
385 | tmp = phy->nrssi_lt[in_rssi]; | ||
386 | tmp = 31 - tmp; | ||
387 | tmp *= -131; | ||
388 | tmp /= 128; | ||
389 | tmp -= 57; | ||
390 | } else { | ||
391 | tmp = in_rssi; | ||
392 | tmp = 31 - tmp; | ||
393 | tmp *= -149; | ||
394 | tmp /= 128; | ||
395 | tmp -= 68; | ||
396 | } | ||
397 | if (phy->type == B43legacy_PHYTYPE_G && | ||
398 | adjust_2050) | ||
399 | tmp += 25; | ||
400 | } | ||
401 | break; | ||
402 | case 0x2060: | ||
403 | if (in_rssi > 127) | ||
404 | tmp = in_rssi - 256; | ||
405 | else | ||
406 | tmp = in_rssi; | ||
407 | break; | ||
408 | default: | ||
409 | tmp = in_rssi; | ||
410 | tmp -= 11; | ||
411 | tmp *= 103; | ||
412 | tmp /= 64; | ||
413 | if (adjust_2053) | ||
414 | tmp -= 109; | ||
415 | else | ||
416 | tmp -= 83; | ||
417 | } | ||
418 | |||
419 | return (s8)tmp; | ||
420 | } | ||
421 | |||
422 | void b43legacy_rx(struct b43legacy_wldev *dev, | ||
423 | struct sk_buff *skb, | ||
424 | const void *_rxhdr) | ||
425 | { | ||
426 | struct ieee80211_rx_status status; | ||
427 | struct b43legacy_plcp_hdr6 *plcp; | ||
428 | struct ieee80211_hdr *wlhdr; | ||
429 | const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr; | ||
430 | u16 fctl; | ||
431 | u16 phystat0; | ||
432 | u16 phystat3; | ||
433 | u16 chanstat; | ||
434 | u16 mactime; | ||
435 | u32 macstat; | ||
436 | u16 chanid; | ||
437 | u8 jssi; | ||
438 | int padding; | ||
439 | |||
440 | memset(&status, 0, sizeof(status)); | ||
441 | |||
442 | /* Get metadata about the frame from the header. */ | ||
443 | phystat0 = le16_to_cpu(rxhdr->phy_status0); | ||
444 | phystat3 = le16_to_cpu(rxhdr->phy_status3); | ||
445 | jssi = rxhdr->jssi; | ||
446 | macstat = le16_to_cpu(rxhdr->mac_status); | ||
447 | mactime = le16_to_cpu(rxhdr->mac_time); | ||
448 | chanstat = le16_to_cpu(rxhdr->channel); | ||
449 | |||
450 | if (macstat & B43legacy_RX_MAC_FCSERR) | ||
451 | dev->wl->ieee_stats.dot11FCSErrorCount++; | ||
452 | |||
453 | /* Skip PLCP and padding */ | ||
454 | padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0; | ||
455 | if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) + | ||
456 | padding))) { | ||
457 | b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n"); | ||
458 | goto drop; | ||
459 | } | ||
460 | plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding); | ||
461 | skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding); | ||
462 | /* The skb contains the Wireless Header + payload data now */ | ||
463 | if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) { | ||
464 | b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n"); | ||
465 | goto drop; | ||
466 | } | ||
467 | wlhdr = (struct ieee80211_hdr *)(skb->data); | ||
468 | fctl = le16_to_cpu(wlhdr->frame_control); | ||
469 | |||
470 | if ((macstat & B43legacy_RX_MAC_DEC) && | ||
471 | !(macstat & B43legacy_RX_MAC_DECERR)) { | ||
472 | unsigned int keyidx; | ||
473 | int wlhdr_len; | ||
474 | int iv_len; | ||
475 | int icv_len; | ||
476 | |||
477 | keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX) | ||
478 | >> B43legacy_RX_MAC_KEYIDX_SHIFT); | ||
479 | /* We must adjust the key index here. We want the "physical" | ||
480 | * key index, but the ucode passed it slightly different. | ||
481 | */ | ||
482 | keyidx = b43legacy_kidx_to_raw(dev, keyidx); | ||
483 | B43legacy_WARN_ON(keyidx >= dev->max_nr_keys); | ||
484 | |||
485 | if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) { | ||
486 | /* Remove PROTECTED flag to mark it as decrypted. */ | ||
487 | B43legacy_WARN_ON(!(fctl & IEEE80211_FCTL_PROTECTED)); | ||
488 | fctl &= ~IEEE80211_FCTL_PROTECTED; | ||
489 | wlhdr->frame_control = cpu_to_le16(fctl); | ||
490 | |||
491 | wlhdr_len = ieee80211_get_hdrlen(fctl); | ||
492 | if (unlikely(skb->len < (wlhdr_len + 3))) { | ||
493 | b43legacydbg(dev->wl, "RX: Packet size" | ||
494 | " underrun3\n"); | ||
495 | goto drop; | ||
496 | } | ||
497 | if (skb->data[wlhdr_len + 3] & (1 << 5)) { | ||
498 | /* The Ext-IV Bit is set in the "KeyID" | ||
499 | * octet of the IV. | ||
500 | */ | ||
501 | iv_len = 8; | ||
502 | icv_len = 8; | ||
503 | } else { | ||
504 | iv_len = 4; | ||
505 | icv_len = 4; | ||
506 | } | ||
507 | if (unlikely(skb->len < (wlhdr_len + iv_len + | ||
508 | icv_len))) { | ||
509 | b43legacydbg(dev->wl, "RX: Packet size" | ||
510 | " underrun4\n"); | ||
511 | goto drop; | ||
512 | } | ||
513 | /* Remove the IV */ | ||
514 | memmove(skb->data + iv_len, skb->data, wlhdr_len); | ||
515 | skb_pull(skb, iv_len); | ||
516 | /* Remove the ICV */ | ||
517 | skb_trim(skb, skb->len - icv_len); | ||
518 | |||
519 | status.flag |= RX_FLAG_DECRYPTED; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | status.ssi = b43legacy_rssi_postprocess(dev, jssi, | ||
524 | (phystat0 & B43legacy_RX_PHYST0_OFDM), | ||
525 | (phystat0 & B43legacy_RX_PHYST0_GAINCTL), | ||
526 | (phystat3 & B43legacy_RX_PHYST3_TRSTATE)); | ||
527 | status.noise = dev->stats.link_noise; | ||
528 | status.signal = (jssi * 100) / B43legacy_RX_MAX_SSI; | ||
529 | if (phystat0 & B43legacy_RX_PHYST0_OFDM) | ||
530 | status.rate = b43legacy_plcp_get_bitrate_ofdm(plcp); | ||
531 | else | ||
532 | status.rate = b43legacy_plcp_get_bitrate_cck(plcp); | ||
533 | status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT); | ||
534 | status.mactime = mactime; | ||
535 | |||
536 | chanid = (chanstat & B43legacy_RX_CHAN_ID) >> | ||
537 | B43legacy_RX_CHAN_ID_SHIFT; | ||
538 | switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) { | ||
539 | case B43legacy_PHYTYPE_B: | ||
540 | status.phymode = MODE_IEEE80211B; | ||
541 | status.freq = chanid + 2400; | ||
542 | status.channel = b43legacy_freq_to_channel_bg(chanid + 2400); | ||
543 | break; | ||
544 | case B43legacy_PHYTYPE_G: | ||
545 | status.phymode = MODE_IEEE80211G; | ||
546 | status.freq = chanid + 2400; | ||
547 | status.channel = b43legacy_freq_to_channel_bg(chanid + 2400); | ||
548 | break; | ||
549 | default: | ||
550 | b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n", | ||
551 | chanstat); | ||
552 | } | ||
553 | |||
554 | dev->stats.last_rx = jiffies; | ||
555 | ieee80211_rx_irqsafe(dev->wl->hw, skb, &status); | ||
556 | |||
557 | return; | ||
558 | drop: | ||
559 | b43legacydbg(dev->wl, "RX: Packet dropped\n"); | ||
560 | dev_kfree_skb_any(skb); | ||
561 | } | ||
562 | |||
563 | void b43legacy_handle_txstatus(struct b43legacy_wldev *dev, | ||
564 | const struct b43legacy_txstatus *status) | ||
565 | { | ||
566 | b43legacy_debugfs_log_txstat(dev, status); | ||
567 | |||
568 | if (status->intermediate) | ||
569 | return; | ||
570 | if (status->for_ampdu) | ||
571 | return; | ||
572 | if (!status->acked) | ||
573 | dev->wl->ieee_stats.dot11ACKFailureCount++; | ||
574 | if (status->rts_count) { | ||
575 | if (status->rts_count == 0xF) /* FIXME */ | ||
576 | dev->wl->ieee_stats.dot11RTSFailureCount++; | ||
577 | else | ||
578 | dev->wl->ieee_stats.dot11RTSSuccessCount++; | ||
579 | } | ||
580 | |||
581 | if (b43legacy_using_pio(dev)) | ||
582 | b43legacy_pio_handle_txstatus(dev, status); | ||
583 | else | ||
584 | b43legacy_dma_handle_txstatus(dev, status); | ||
585 | } | ||
586 | |||
587 | /* Handle TX status report as received through DMA/PIO queues */ | ||
588 | void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev, | ||
589 | const struct b43legacy_hwtxstatus *hw) | ||
590 | { | ||
591 | struct b43legacy_txstatus status; | ||
592 | u8 tmp; | ||
593 | |||
594 | status.cookie = le16_to_cpu(hw->cookie); | ||
595 | status.seq = le16_to_cpu(hw->seq); | ||
596 | status.phy_stat = hw->phy_stat; | ||
597 | tmp = hw->count; | ||
598 | status.frame_count = (tmp >> 4); | ||
599 | status.rts_count = (tmp & 0x0F); | ||
600 | tmp = hw->flags; | ||
601 | status.supp_reason = ((tmp & 0x1C) >> 2); | ||
602 | status.pm_indicated = !!(tmp & 0x80); | ||
603 | status.intermediate = !!(tmp & 0x40); | ||
604 | status.for_ampdu = !!(tmp & 0x20); | ||
605 | status.acked = !!(tmp & 0x02); | ||
606 | |||
607 | b43legacy_handle_txstatus(dev, &status); | ||
608 | } | ||
609 | |||
610 | /* Stop any TX operation on the device (suspend the hardware queues) */ | ||
611 | void b43legacy_tx_suspend(struct b43legacy_wldev *dev) | ||
612 | { | ||
613 | if (b43legacy_using_pio(dev)) | ||
614 | b43legacy_pio_freeze_txqueues(dev); | ||
615 | else | ||
616 | b43legacy_dma_tx_suspend(dev); | ||
617 | } | ||
618 | |||
619 | /* Resume any TX operation on the device (resume the hardware queues) */ | ||
620 | void b43legacy_tx_resume(struct b43legacy_wldev *dev) | ||
621 | { | ||
622 | if (b43legacy_using_pio(dev)) | ||
623 | b43legacy_pio_thaw_txqueues(dev); | ||
624 | else | ||
625 | b43legacy_dma_tx_resume(dev); | ||
626 | } | ||
627 | |||
628 | /* Initialize the QoS parameters */ | ||
629 | void b43legacy_qos_init(struct b43legacy_wldev *dev) | ||
630 | { | ||
631 | /* FIXME: This function must probably be called from the mac80211 | ||
632 | * config callback. */ | ||
633 | return; | ||
634 | |||
635 | b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF); | ||
636 | /* FIXME kill magic */ | ||
637 | b43legacy_write16(dev, 0x688, | ||
638 | b43legacy_read16(dev, 0x688) | 0x4); | ||
639 | |||
640 | |||
641 | /*TODO: We might need some stack support here to get the values. */ | ||
642 | } | ||