]>
Commit | Line | Data |
---|---|---|
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> | |
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 | ||
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" | |
31 | #include "phy.h" | |
32 | #include "dma.h" | |
33 | #include "pio.h" | |
34 | ||
35 | /* Extract the bitrate out of a CCK PLCP header. */ | |
36 | static u8 b43_plcp_get_bitrate_cck(struct b43_plcp_hdr6 *plcp) | |
37 | { | |
38 | switch (plcp->raw[0]) { | |
39 | case 0x0A: | |
40 | return B43_CCK_RATE_1MB; | |
41 | case 0x14: | |
42 | return B43_CCK_RATE_2MB; | |
43 | case 0x37: | |
44 | return B43_CCK_RATE_5MB; | |
45 | case 0x6E: | |
46 | return B43_CCK_RATE_11MB; | |
47 | } | |
48 | B43_WARN_ON(1); | |
49 | return 0; | |
50 | } | |
51 | ||
52 | /* Extract the bitrate out of an OFDM PLCP header. */ | |
53 | static u8 b43_plcp_get_bitrate_ofdm(struct b43_plcp_hdr6 *plcp) | |
54 | { | |
55 | switch (plcp->raw[0] & 0xF) { | |
56 | case 0xB: | |
57 | return B43_OFDM_RATE_6MB; | |
58 | case 0xF: | |
59 | return B43_OFDM_RATE_9MB; | |
60 | case 0xA: | |
61 | return B43_OFDM_RATE_12MB; | |
62 | case 0xE: | |
63 | return B43_OFDM_RATE_18MB; | |
64 | case 0x9: | |
65 | return B43_OFDM_RATE_24MB; | |
66 | case 0xD: | |
67 | return B43_OFDM_RATE_36MB; | |
68 | case 0x8: | |
69 | return B43_OFDM_RATE_48MB; | |
70 | case 0xC: | |
71 | return B43_OFDM_RATE_54MB; | |
72 | } | |
73 | B43_WARN_ON(1); | |
74 | return 0; | |
75 | } | |
76 | ||
77 | u8 b43_plcp_get_ratecode_cck(const u8 bitrate) | |
78 | { | |
79 | switch (bitrate) { | |
80 | case B43_CCK_RATE_1MB: | |
81 | return 0x0A; | |
82 | case B43_CCK_RATE_2MB: | |
83 | return 0x14; | |
84 | case B43_CCK_RATE_5MB: | |
85 | return 0x37; | |
86 | case B43_CCK_RATE_11MB: | |
87 | return 0x6E; | |
88 | } | |
89 | B43_WARN_ON(1); | |
90 | return 0; | |
91 | } | |
92 | ||
93 | u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate) | |
94 | { | |
95 | switch (bitrate) { | |
96 | case B43_OFDM_RATE_6MB: | |
97 | return 0xB; | |
98 | case B43_OFDM_RATE_9MB: | |
99 | return 0xF; | |
100 | case B43_OFDM_RATE_12MB: | |
101 | return 0xA; | |
102 | case B43_OFDM_RATE_18MB: | |
103 | return 0xE; | |
104 | case B43_OFDM_RATE_24MB: | |
105 | return 0x9; | |
106 | case B43_OFDM_RATE_36MB: | |
107 | return 0xD; | |
108 | case B43_OFDM_RATE_48MB: | |
109 | return 0x8; | |
110 | case B43_OFDM_RATE_54MB: | |
111 | return 0xC; | |
112 | } | |
113 | B43_WARN_ON(1); | |
114 | return 0; | |
115 | } | |
116 | ||
117 | void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp, | |
118 | const u16 octets, const u8 bitrate) | |
119 | { | |
120 | __le32 *data = &(plcp->data); | |
121 | __u8 *raw = plcp->raw; | |
122 | ||
123 | if (b43_is_ofdm_rate(bitrate)) { | |
124 | *data = b43_plcp_get_ratecode_ofdm(bitrate); | |
125 | B43_WARN_ON(octets & 0xF000); | |
126 | *data |= (octets << 5); | |
127 | *data = cpu_to_le32(*data); | |
128 | } else { | |
129 | u32 plen; | |
130 | ||
131 | plen = octets * 16 / bitrate; | |
132 | if ((octets * 16 % bitrate) > 0) { | |
133 | plen++; | |
134 | if ((bitrate == B43_CCK_RATE_11MB) | |
135 | && ((octets * 8 % 11) < 4)) { | |
136 | raw[1] = 0x84; | |
137 | } else | |
138 | raw[1] = 0x04; | |
139 | } else | |
140 | raw[1] = 0x04; | |
141 | *data |= cpu_to_le32(plen << 16); | |
142 | raw[0] = b43_plcp_get_ratecode_cck(bitrate); | |
143 | } | |
144 | } | |
145 | ||
146 | static u8 b43_calc_fallback_rate(u8 bitrate) | |
147 | { | |
148 | switch (bitrate) { | |
149 | case B43_CCK_RATE_1MB: | |
150 | return B43_CCK_RATE_1MB; | |
151 | case B43_CCK_RATE_2MB: | |
152 | return B43_CCK_RATE_1MB; | |
153 | case B43_CCK_RATE_5MB: | |
154 | return B43_CCK_RATE_2MB; | |
155 | case B43_CCK_RATE_11MB: | |
156 | return B43_CCK_RATE_5MB; | |
157 | case B43_OFDM_RATE_6MB: | |
158 | return B43_CCK_RATE_5MB; | |
159 | case B43_OFDM_RATE_9MB: | |
160 | return B43_OFDM_RATE_6MB; | |
161 | case B43_OFDM_RATE_12MB: | |
162 | return B43_OFDM_RATE_9MB; | |
163 | case B43_OFDM_RATE_18MB: | |
164 | return B43_OFDM_RATE_12MB; | |
165 | case B43_OFDM_RATE_24MB: | |
166 | return B43_OFDM_RATE_18MB; | |
167 | case B43_OFDM_RATE_36MB: | |
168 | return B43_OFDM_RATE_24MB; | |
169 | case B43_OFDM_RATE_48MB: | |
170 | return B43_OFDM_RATE_36MB; | |
171 | case B43_OFDM_RATE_54MB: | |
172 | return B43_OFDM_RATE_48MB; | |
173 | } | |
174 | B43_WARN_ON(1); | |
175 | return 0; | |
176 | } | |
177 | ||
178 | static void generate_txhdr_fw4(struct b43_wldev *dev, | |
179 | struct b43_txhdr_fw4 *txhdr, | |
180 | const unsigned char *fragment_data, | |
181 | unsigned int fragment_len, | |
182 | const struct ieee80211_tx_control *txctl, | |
183 | u16 cookie) | |
184 | { | |
185 | const struct b43_phy *phy = &dev->phy; | |
186 | const struct ieee80211_hdr *wlhdr = | |
187 | (const struct ieee80211_hdr *)fragment_data; | |
188 | int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)); | |
189 | u16 fctl = le16_to_cpu(wlhdr->frame_control); | |
190 | u8 rate, rate_fb; | |
191 | int rate_ofdm, rate_fb_ofdm; | |
192 | unsigned int plcp_fragment_len; | |
193 | u32 mac_ctl = 0; | |
194 | u16 phy_ctl = 0; | |
195 | u8 extra_ft = 0; | |
196 | ||
197 | memset(txhdr, 0, sizeof(*txhdr)); | |
198 | ||
199 | rate = txctl->tx_rate; | |
200 | rate_ofdm = b43_is_ofdm_rate(rate); | |
201 | rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate; | |
202 | rate_fb_ofdm = b43_is_ofdm_rate(rate_fb); | |
203 | ||
204 | if (rate_ofdm) | |
205 | txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate); | |
206 | else | |
207 | txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate); | |
208 | txhdr->mac_frame_ctl = wlhdr->frame_control; | |
209 | memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); | |
210 | ||
211 | /* Calculate duration for fallback rate */ | |
212 | if ((rate_fb == rate) || | |
213 | (wlhdr->duration_id & cpu_to_le16(0x8000)) || | |
214 | (wlhdr->duration_id == cpu_to_le16(0))) { | |
215 | /* If the fallback rate equals the normal rate or the | |
216 | * dur_id field contains an AID, CFP magic or 0, | |
217 | * use the original dur_id field. */ | |
218 | txhdr->dur_fb = wlhdr->duration_id; | |
219 | } else { | |
220 | int fbrate_base100kbps = B43_RATE_TO_BASE100KBPS(rate_fb); | |
221 | txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, | |
222 | dev->wl->if_id, | |
223 | fragment_len, | |
224 | fbrate_base100kbps); | |
225 | } | |
226 | ||
227 | plcp_fragment_len = fragment_len + FCS_LEN; | |
228 | if (use_encryption) { | |
229 | u8 key_idx = (u16) (txctl->key_idx); | |
230 | struct b43_key *key; | |
231 | int wlhdr_len; | |
232 | size_t iv_len; | |
233 | ||
234 | B43_WARN_ON(key_idx >= dev->max_nr_keys); | |
235 | key = &(dev->key[key_idx]); | |
236 | B43_WARN_ON(!key->keyconf); | |
237 | ||
238 | /* Hardware appends ICV. */ | |
239 | plcp_fragment_len += txctl->icv_len; | |
240 | ||
241 | key_idx = b43_kidx_to_fw(dev, key_idx); | |
242 | mac_ctl |= (key_idx << B43_TX4_MAC_KEYIDX_SHIFT) & | |
243 | B43_TX4_MAC_KEYIDX; | |
244 | mac_ctl |= (key->algorithm << B43_TX4_MAC_KEYALG_SHIFT) & | |
245 | B43_TX4_MAC_KEYALG; | |
246 | wlhdr_len = ieee80211_get_hdrlen(fctl); | |
247 | iv_len = min((size_t) txctl->iv_len, | |
248 | ARRAY_SIZE(txhdr->iv)); | |
249 | memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len); | |
250 | } | |
251 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp), | |
252 | plcp_fragment_len, rate); | |
253 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb), | |
254 | plcp_fragment_len, rate_fb); | |
255 | ||
256 | /* Extra Frame Types */ | |
257 | if (rate_fb_ofdm) | |
258 | extra_ft |= B43_TX4_EFT_FBOFDM; | |
259 | ||
260 | /* Set channel radio code. Note that the micrcode ORs 0x100 to | |
261 | * this value before comparing it to the value in SHM, if this | |
262 | * is a 5Ghz packet. | |
263 | */ | |
264 | txhdr->chan_radio_code = phy->channel; | |
265 | ||
266 | /* PHY TX Control word */ | |
267 | if (rate_ofdm) | |
268 | phy_ctl |= B43_TX4_PHY_OFDM; | |
269 | if (dev->short_preamble) | |
270 | phy_ctl |= B43_TX4_PHY_SHORTPRMBL; | |
271 | switch (txctl->antenna_sel_tx) { | |
272 | case 0: | |
273 | phy_ctl |= B43_TX4_PHY_ANTLAST; | |
274 | break; | |
275 | case 1: | |
276 | phy_ctl |= B43_TX4_PHY_ANT0; | |
277 | break; | |
278 | case 2: | |
279 | phy_ctl |= B43_TX4_PHY_ANT1; | |
280 | break; | |
281 | default: | |
282 | B43_WARN_ON(1); | |
283 | } | |
284 | ||
285 | /* MAC control */ | |
286 | if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK)) | |
287 | mac_ctl |= B43_TX4_MAC_ACK; | |
288 | if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && | |
289 | ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) | |
290 | mac_ctl |= B43_TX4_MAC_HWSEQ; | |
291 | if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT) | |
292 | mac_ctl |= B43_TX4_MAC_STMSDU; | |
293 | if (phy->type == B43_PHYTYPE_A) | |
294 | mac_ctl |= B43_TX4_MAC_5GHZ; | |
295 | ||
296 | /* Generate the RTS or CTS-to-self frame */ | |
297 | if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) || | |
298 | (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) { | |
299 | unsigned int len; | |
300 | struct ieee80211_hdr *hdr; | |
301 | int rts_rate, rts_rate_fb; | |
302 | int rts_rate_ofdm, rts_rate_fb_ofdm; | |
303 | ||
304 | rts_rate = txctl->rts_cts_rate; | |
305 | rts_rate_ofdm = b43_is_ofdm_rate(rts_rate); | |
306 | rts_rate_fb = b43_calc_fallback_rate(rts_rate); | |
307 | rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb); | |
308 | ||
309 | if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { | |
310 | ieee80211_ctstoself_get(dev->wl->hw, dev->wl->if_id, | |
311 | fragment_data, fragment_len, | |
312 | txctl, | |
313 | (struct ieee80211_cts *)(txhdr-> | |
314 | rts_frame)); | |
315 | mac_ctl |= B43_TX4_MAC_SENDCTS; | |
316 | len = sizeof(struct ieee80211_cts); | |
317 | } else { | |
318 | ieee80211_rts_get(dev->wl->hw, dev->wl->if_id, | |
319 | fragment_data, fragment_len, txctl, | |
320 | (struct ieee80211_rts *)(txhdr-> | |
321 | rts_frame)); | |
322 | mac_ctl |= B43_TX4_MAC_SENDRTS; | |
323 | len = sizeof(struct ieee80211_rts); | |
324 | } | |
325 | len += FCS_LEN; | |
326 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr-> | |
327 | rts_plcp), len, | |
328 | rts_rate); | |
329 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr-> | |
330 | rts_plcp_fb), | |
331 | len, rts_rate_fb); | |
332 | hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame); | |
333 | txhdr->rts_dur_fb = hdr->duration_id; | |
334 | if (rts_rate_ofdm) { | |
335 | extra_ft |= B43_TX4_EFT_RTSOFDM; | |
336 | txhdr->phy_rate_rts = | |
337 | b43_plcp_get_ratecode_ofdm(rts_rate); | |
338 | } else | |
339 | txhdr->phy_rate_rts = | |
340 | b43_plcp_get_ratecode_cck(rts_rate); | |
341 | if (rts_rate_fb_ofdm) | |
342 | extra_ft |= B43_TX4_EFT_RTSFBOFDM; | |
343 | mac_ctl |= B43_TX4_MAC_LONGFRAME; | |
344 | } | |
345 | ||
346 | /* Magic cookie */ | |
347 | txhdr->cookie = cpu_to_le16(cookie); | |
348 | ||
349 | /* Apply the bitfields */ | |
350 | txhdr->mac_ctl = cpu_to_le32(mac_ctl); | |
351 | txhdr->phy_ctl = cpu_to_le16(phy_ctl); | |
352 | txhdr->extra_ft = extra_ft; | |
353 | } | |
354 | ||
355 | void b43_generate_txhdr(struct b43_wldev *dev, | |
356 | u8 * txhdr, | |
357 | const unsigned char *fragment_data, | |
358 | unsigned int fragment_len, | |
359 | const struct ieee80211_tx_control *txctl, u16 cookie) | |
360 | { | |
361 | generate_txhdr_fw4(dev, (struct b43_txhdr_fw4 *)txhdr, | |
362 | fragment_data, fragment_len, txctl, cookie); | |
363 | } | |
364 | ||
365 | static s8 b43_rssi_postprocess(struct b43_wldev *dev, | |
366 | u8 in_rssi, int ofdm, | |
367 | int adjust_2053, int adjust_2050) | |
368 | { | |
369 | struct b43_phy *phy = &dev->phy; | |
370 | s32 tmp; | |
371 | ||
372 | switch (phy->radio_ver) { | |
373 | case 0x2050: | |
374 | if (ofdm) { | |
375 | tmp = in_rssi; | |
376 | if (tmp > 127) | |
377 | tmp -= 256; | |
378 | tmp *= 73; | |
379 | tmp /= 64; | |
380 | if (adjust_2050) | |
381 | tmp += 25; | |
382 | else | |
383 | tmp -= 3; | |
384 | } else { | |
385 | if (dev->dev->bus->sprom.r1. | |
386 | boardflags_lo & B43_BFL_RSSI) { | |
387 | if (in_rssi > 63) | |
388 | in_rssi = 63; | |
389 | tmp = phy->nrssi_lt[in_rssi]; | |
390 | tmp = 31 - tmp; | |
391 | tmp *= -131; | |
392 | tmp /= 128; | |
393 | tmp -= 57; | |
394 | } else { | |
395 | tmp = in_rssi; | |
396 | tmp = 31 - tmp; | |
397 | tmp *= -149; | |
398 | tmp /= 128; | |
399 | tmp -= 68; | |
400 | } | |
401 | if (phy->type == B43_PHYTYPE_G && adjust_2050) | |
402 | tmp += 25; | |
403 | } | |
404 | break; | |
405 | case 0x2060: | |
406 | if (in_rssi > 127) | |
407 | tmp = in_rssi - 256; | |
408 | else | |
409 | tmp = in_rssi; | |
410 | break; | |
411 | default: | |
412 | tmp = in_rssi; | |
413 | tmp -= 11; | |
414 | tmp *= 103; | |
415 | tmp /= 64; | |
416 | if (adjust_2053) | |
417 | tmp -= 109; | |
418 | else | |
419 | tmp -= 83; | |
420 | } | |
421 | ||
422 | return (s8) tmp; | |
423 | } | |
424 | ||
425 | //TODO | |
426 | #if 0 | |
427 | static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi) | |
428 | { | |
429 | struct b43_phy *phy = &dev->phy; | |
430 | s8 ret; | |
431 | ||
432 | if (phy->type == B43_PHYTYPE_A) { | |
433 | //TODO: Incomplete specs. | |
434 | ret = 0; | |
435 | } else | |
436 | ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1); | |
437 | ||
438 | return ret; | |
439 | } | |
440 | #endif | |
441 | ||
442 | void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) | |
443 | { | |
444 | struct ieee80211_rx_status status; | |
445 | struct b43_plcp_hdr6 *plcp; | |
446 | struct ieee80211_hdr *wlhdr; | |
447 | const struct b43_rxhdr_fw4 *rxhdr = _rxhdr; | |
448 | u16 fctl; | |
449 | u16 phystat0, phystat3, chanstat, mactime; | |
450 | u32 macstat; | |
451 | u16 chanid; | |
452 | u8 jssi; | |
453 | int padding; | |
454 | ||
455 | memset(&status, 0, sizeof(status)); | |
456 | ||
457 | /* Get metadata about the frame from the header. */ | |
458 | phystat0 = le16_to_cpu(rxhdr->phy_status0); | |
459 | phystat3 = le16_to_cpu(rxhdr->phy_status3); | |
460 | jssi = rxhdr->jssi; | |
461 | macstat = le32_to_cpu(rxhdr->mac_status); | |
462 | mactime = le16_to_cpu(rxhdr->mac_time); | |
463 | chanstat = le16_to_cpu(rxhdr->channel); | |
464 | ||
465 | if (macstat & B43_RX_MAC_FCSERR) | |
466 | dev->wl->ieee_stats.dot11FCSErrorCount++; | |
467 | if (macstat & B43_RX_MAC_DECERR) { | |
468 | /* Decryption with the given key failed. | |
469 | * Drop the packet. We also won't be able to decrypt it with | |
470 | * the key in software. */ | |
471 | goto drop; | |
472 | } | |
473 | ||
474 | /* Skip PLCP and padding */ | |
475 | padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0; | |
476 | if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) { | |
477 | b43dbg(dev->wl, "RX: Packet size underrun (1)\n"); | |
478 | goto drop; | |
479 | } | |
480 | plcp = (struct b43_plcp_hdr6 *)(skb->data + padding); | |
481 | skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding); | |
482 | /* The skb contains the Wireless Header + payload data now */ | |
483 | if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) { | |
484 | b43dbg(dev->wl, "RX: Packet size underrun (2)\n"); | |
485 | goto drop; | |
486 | } | |
487 | wlhdr = (struct ieee80211_hdr *)(skb->data); | |
488 | fctl = le16_to_cpu(wlhdr->frame_control); | |
489 | skb_trim(skb, skb->len - FCS_LEN); | |
490 | ||
491 | if (macstat & B43_RX_MAC_DEC) { | |
492 | unsigned int keyidx; | |
493 | int wlhdr_len; | |
494 | ||
495 | keyidx = ((macstat & B43_RX_MAC_KEYIDX) | |
496 | >> B43_RX_MAC_KEYIDX_SHIFT); | |
497 | /* We must adjust the key index here. We want the "physical" | |
498 | * key index, but the ucode passed it slightly different. | |
499 | */ | |
500 | keyidx = b43_kidx_to_raw(dev, keyidx); | |
501 | B43_WARN_ON(keyidx >= dev->max_nr_keys); | |
502 | ||
503 | if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) { | |
504 | wlhdr_len = ieee80211_get_hdrlen(fctl); | |
505 | if (unlikely(skb->len < (wlhdr_len + 3))) { | |
506 | b43dbg(dev->wl, | |
507 | "RX: Packet size underrun (3)\n"); | |
508 | goto drop; | |
509 | } | |
510 | status.flag |= RX_FLAG_DECRYPTED; | |
511 | } | |
512 | } | |
513 | ||
514 | status.ssi = b43_rssi_postprocess(dev, jssi, | |
515 | (phystat0 & B43_RX_PHYST0_OFDM), | |
516 | (phystat0 & B43_RX_PHYST0_GAINCTL), | |
517 | (phystat3 & B43_RX_PHYST3_TRSTATE)); | |
518 | status.noise = dev->stats.link_noise; | |
519 | /* the next line looks wrong, but is what mac80211 wants */ | |
520 | status.signal = (jssi * 100) / B43_RX_MAX_SSI; | |
521 | if (phystat0 & B43_RX_PHYST0_OFDM) | |
522 | status.rate = b43_plcp_get_bitrate_ofdm(plcp); | |
523 | else | |
524 | status.rate = b43_plcp_get_bitrate_cck(plcp); | |
525 | status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT); | |
526 | status.mactime = mactime; | |
527 | ||
528 | chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT; | |
529 | switch (chanstat & B43_RX_CHAN_PHYTYPE) { | |
530 | case B43_PHYTYPE_A: | |
531 | status.phymode = MODE_IEEE80211A; | |
532 | status.freq = chanid; | |
533 | status.channel = b43_freq_to_channel_a(chanid); | |
534 | break; | |
535 | case B43_PHYTYPE_B: | |
536 | status.phymode = MODE_IEEE80211B; | |
537 | status.freq = chanid + 2400; | |
538 | status.channel = b43_freq_to_channel_bg(chanid + 2400); | |
539 | break; | |
540 | case B43_PHYTYPE_G: | |
541 | status.phymode = MODE_IEEE80211G; | |
542 | status.freq = chanid + 2400; | |
543 | status.channel = b43_freq_to_channel_bg(chanid + 2400); | |
544 | break; | |
545 | default: | |
546 | B43_WARN_ON(1); | |
547 | } | |
548 | ||
549 | dev->stats.last_rx = jiffies; | |
550 | ieee80211_rx_irqsafe(dev->wl->hw, skb, &status); | |
551 | ||
552 | return; | |
553 | drop: | |
554 | b43dbg(dev->wl, "RX: Packet dropped\n"); | |
555 | dev_kfree_skb_any(skb); | |
556 | } | |
557 | ||
558 | void b43_handle_txstatus(struct b43_wldev *dev, | |
559 | const struct b43_txstatus *status) | |
560 | { | |
561 | b43_debugfs_log_txstat(dev, status); | |
562 | ||
563 | if (status->intermediate) | |
564 | return; | |
565 | if (status->for_ampdu) | |
566 | return; | |
567 | if (!status->acked) | |
568 | dev->wl->ieee_stats.dot11ACKFailureCount++; | |
569 | if (status->rts_count) { | |
570 | if (status->rts_count == 0xF) //FIXME | |
571 | dev->wl->ieee_stats.dot11RTSFailureCount++; | |
572 | else | |
573 | dev->wl->ieee_stats.dot11RTSSuccessCount++; | |
574 | } | |
575 | ||
576 | if (b43_using_pio(dev)) | |
577 | b43_pio_handle_txstatus(dev, status); | |
578 | else | |
579 | b43_dma_handle_txstatus(dev, status); | |
580 | } | |
581 | ||
582 | /* Handle TX status report as received through DMA/PIO queues */ | |
583 | void b43_handle_hwtxstatus(struct b43_wldev *dev, | |
584 | const struct b43_hwtxstatus *hw) | |
585 | { | |
586 | struct b43_txstatus status; | |
587 | u8 tmp; | |
588 | ||
589 | status.cookie = le16_to_cpu(hw->cookie); | |
590 | status.seq = le16_to_cpu(hw->seq); | |
591 | status.phy_stat = hw->phy_stat; | |
592 | tmp = hw->count; | |
593 | status.frame_count = (tmp >> 4); | |
594 | status.rts_count = (tmp & 0x0F); | |
595 | tmp = hw->flags; | |
596 | status.supp_reason = ((tmp & 0x1C) >> 2); | |
597 | status.pm_indicated = !!(tmp & 0x80); | |
598 | status.intermediate = !!(tmp & 0x40); | |
599 | status.for_ampdu = !!(tmp & 0x20); | |
600 | status.acked = !!(tmp & 0x02); | |
601 | ||
602 | b43_handle_txstatus(dev, &status); | |
603 | } | |
604 | ||
605 | /* Stop any TX operation on the device (suspend the hardware queues) */ | |
606 | void b43_tx_suspend(struct b43_wldev *dev) | |
607 | { | |
608 | if (b43_using_pio(dev)) | |
609 | b43_pio_freeze_txqueues(dev); | |
610 | else | |
611 | b43_dma_tx_suspend(dev); | |
612 | } | |
613 | ||
614 | /* Resume any TX operation on the device (resume the hardware queues) */ | |
615 | void b43_tx_resume(struct b43_wldev *dev) | |
616 | { | |
617 | if (b43_using_pio(dev)) | |
618 | b43_pio_thaw_txqueues(dev); | |
619 | else | |
620 | b43_dma_tx_resume(dev); | |
621 | } | |
622 | ||
623 | #if 0 | |
624 | static void upload_qos_parms(struct b43_wldev *dev, | |
625 | const u16 * parms, u16 offset) | |
626 | { | |
627 | int i; | |
628 | ||
629 | for (i = 0; i < B43_NR_QOSPARMS; i++) { | |
630 | b43_shm_write16(dev, B43_SHM_SHARED, | |
631 | offset + (i * 2), parms[i]); | |
632 | } | |
633 | } | |
634 | #endif | |
635 | ||
636 | /* Initialize the QoS parameters */ | |
637 | void b43_qos_init(struct b43_wldev *dev) | |
638 | { | |
639 | /* FIXME: This function must probably be called from the mac80211 | |
640 | * config callback. */ | |
641 | return; | |
642 | ||
643 | b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF); | |
644 | //FIXME kill magic | |
645 | b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4); | |
646 | ||
647 | /*TODO: We might need some stack support here to get the values. */ | |
648 | } |