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