Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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> |
Stefano Brivio | 1f21ad2 | 2007-11-06 22:49:20 +0100 | [diff] [blame] | 8 | Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it> |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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" |
Michael Buesch | 03b2977 | 2007-12-26 14:41:30 +0100 | [diff] [blame] | 33 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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)) { |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 124 | u32 d; |
| 125 | |
| 126 | d = b43_plcp_get_ratecode_ofdm(bitrate); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 127 | B43_WARN_ON(octets & 0xF000); |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 128 | d |= (octets << 5); |
| 129 | *data = cpu_to_le32(d); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 130 | } else { |
| 131 | u32 plen; |
| 132 | |
| 133 | plen = octets * 16 / bitrate; |
| 134 | if ((octets * 16 % bitrate) > 0) { |
| 135 | plen++; |
| 136 | if ((bitrate == B43_CCK_RATE_11MB) |
| 137 | && ((octets * 8 % 11) < 4)) { |
| 138 | raw[1] = 0x84; |
| 139 | } else |
| 140 | raw[1] = 0x04; |
| 141 | } else |
| 142 | raw[1] = 0x04; |
| 143 | *data |= cpu_to_le32(plen << 16); |
| 144 | raw[0] = b43_plcp_get_ratecode_cck(bitrate); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static u8 b43_calc_fallback_rate(u8 bitrate) |
| 149 | { |
| 150 | switch (bitrate) { |
| 151 | case B43_CCK_RATE_1MB: |
| 152 | return B43_CCK_RATE_1MB; |
| 153 | case B43_CCK_RATE_2MB: |
| 154 | return B43_CCK_RATE_1MB; |
| 155 | case B43_CCK_RATE_5MB: |
| 156 | return B43_CCK_RATE_2MB; |
| 157 | case B43_CCK_RATE_11MB: |
| 158 | return B43_CCK_RATE_5MB; |
| 159 | case B43_OFDM_RATE_6MB: |
| 160 | return B43_CCK_RATE_5MB; |
| 161 | case B43_OFDM_RATE_9MB: |
| 162 | return B43_OFDM_RATE_6MB; |
| 163 | case B43_OFDM_RATE_12MB: |
| 164 | return B43_OFDM_RATE_9MB; |
| 165 | case B43_OFDM_RATE_18MB: |
| 166 | return B43_OFDM_RATE_12MB; |
| 167 | case B43_OFDM_RATE_24MB: |
| 168 | return B43_OFDM_RATE_18MB; |
| 169 | case B43_OFDM_RATE_36MB: |
| 170 | return B43_OFDM_RATE_24MB; |
| 171 | case B43_OFDM_RATE_48MB: |
| 172 | return B43_OFDM_RATE_36MB; |
| 173 | case B43_OFDM_RATE_54MB: |
| 174 | return B43_OFDM_RATE_48MB; |
| 175 | } |
| 176 | B43_WARN_ON(1); |
| 177 | return 0; |
| 178 | } |
| 179 | |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 180 | /* Generate a TX data header. */ |
| 181 | void b43_generate_txhdr(struct b43_wldev *dev, |
| 182 | u8 *_txhdr, |
| 183 | const unsigned char *fragment_data, |
| 184 | unsigned int fragment_len, |
| 185 | const struct ieee80211_tx_control *txctl, |
| 186 | u16 cookie) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 187 | { |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 188 | struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 189 | const struct b43_phy *phy = &dev->phy; |
| 190 | const struct ieee80211_hdr *wlhdr = |
| 191 | (const struct ieee80211_hdr *)fragment_data; |
| 192 | int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)); |
| 193 | u16 fctl = le16_to_cpu(wlhdr->frame_control); |
| 194 | u8 rate, rate_fb; |
| 195 | int rate_ofdm, rate_fb_ofdm; |
| 196 | unsigned int plcp_fragment_len; |
| 197 | u32 mac_ctl = 0; |
| 198 | u16 phy_ctl = 0; |
| 199 | u8 extra_ft = 0; |
| 200 | |
| 201 | memset(txhdr, 0, sizeof(*txhdr)); |
| 202 | |
| 203 | rate = txctl->tx_rate; |
| 204 | rate_ofdm = b43_is_ofdm_rate(rate); |
| 205 | rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate; |
| 206 | rate_fb_ofdm = b43_is_ofdm_rate(rate_fb); |
| 207 | |
| 208 | if (rate_ofdm) |
| 209 | txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate); |
| 210 | else |
| 211 | txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate); |
| 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 = B43_RATE_TO_BASE100KBPS(rate_fb); |
| 225 | txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw, |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 226 | txctl->vif, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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 b43_key *key; |
| 235 | int wlhdr_len; |
| 236 | size_t iv_len; |
| 237 | |
| 238 | B43_WARN_ON(key_idx >= dev->max_nr_keys); |
| 239 | key = &(dev->key[key_idx]); |
| 240 | B43_WARN_ON(!key->keyconf); |
| 241 | |
| 242 | /* Hardware appends ICV. */ |
| 243 | plcp_fragment_len += txctl->icv_len; |
| 244 | |
| 245 | key_idx = b43_kidx_to_fw(dev, key_idx); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 246 | mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) & |
| 247 | B43_TXH_MAC_KEYIDX; |
| 248 | mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) & |
| 249 | B43_TXH_MAC_KEYALG; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 250 | wlhdr_len = ieee80211_get_hdrlen(fctl); |
| 251 | iv_len = min((size_t) txctl->iv_len, |
| 252 | ARRAY_SIZE(txhdr->iv)); |
| 253 | memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len); |
| 254 | } |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 255 | if (b43_is_old_txhdr_format(dev)) { |
| 256 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp), |
| 257 | plcp_fragment_len, rate); |
| 258 | } else { |
| 259 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp), |
| 260 | plcp_fragment_len, rate); |
| 261 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 262 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb), |
| 263 | plcp_fragment_len, rate_fb); |
| 264 | |
| 265 | /* Extra Frame Types */ |
| 266 | if (rate_fb_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 267 | extra_ft |= B43_TXH_EFT_FB_OFDM; |
| 268 | else |
| 269 | extra_ft |= B43_TXH_EFT_FB_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 270 | |
| 271 | /* Set channel radio code. Note that the micrcode ORs 0x100 to |
| 272 | * this value before comparing it to the value in SHM, if this |
| 273 | * is a 5Ghz packet. |
| 274 | */ |
| 275 | txhdr->chan_radio_code = phy->channel; |
| 276 | |
| 277 | /* PHY TX Control word */ |
| 278 | if (rate_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 279 | phy_ctl |= B43_TXH_PHY_ENC_OFDM; |
| 280 | else |
| 281 | phy_ctl |= B43_TXH_PHY_ENC_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 282 | if (dev->short_preamble) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 283 | phy_ctl |= B43_TXH_PHY_SHORTPRMBL; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 284 | |
| 285 | switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) { |
| 286 | case 0: /* Default */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 287 | phy_ctl |= B43_TXH_PHY_ANT01AUTO; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 288 | break; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 289 | case 1: /* Antenna 0 */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 290 | phy_ctl |= B43_TXH_PHY_ANT0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 291 | break; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 292 | case 2: /* Antenna 1 */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 293 | phy_ctl |= B43_TXH_PHY_ANT1; |
| 294 | break; |
| 295 | case 3: /* Antenna 2 */ |
| 296 | phy_ctl |= B43_TXH_PHY_ANT2; |
| 297 | break; |
| 298 | case 4: /* Antenna 3 */ |
| 299 | phy_ctl |= B43_TXH_PHY_ANT3; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 300 | break; |
| 301 | default: |
| 302 | B43_WARN_ON(1); |
| 303 | } |
| 304 | |
| 305 | /* MAC control */ |
| 306 | if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK)) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 307 | mac_ctl |= B43_TXH_MAC_ACK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 308 | if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && |
| 309 | ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 310 | mac_ctl |= B43_TXH_MAC_HWSEQ; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 311 | if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 312 | mac_ctl |= B43_TXH_MAC_STMSDU; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 313 | if (phy->type == B43_PHYTYPE_A) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 314 | mac_ctl |= B43_TXH_MAC_5GHZ; |
Michael Buesch | 74cfdba | 2007-10-28 16:19:44 +0100 | [diff] [blame] | 315 | if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 316 | mac_ctl |= B43_TXH_MAC_LONGFRAME; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 317 | |
| 318 | /* Generate the RTS or CTS-to-self frame */ |
| 319 | if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) || |
| 320 | (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) { |
| 321 | unsigned int len; |
| 322 | struct ieee80211_hdr *hdr; |
| 323 | int rts_rate, rts_rate_fb; |
| 324 | int rts_rate_ofdm, rts_rate_fb_ofdm; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 325 | struct b43_plcp_hdr6 *plcp; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 326 | |
| 327 | rts_rate = txctl->rts_cts_rate; |
| 328 | rts_rate_ofdm = b43_is_ofdm_rate(rts_rate); |
| 329 | rts_rate_fb = b43_calc_fallback_rate(rts_rate); |
| 330 | rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb); |
| 331 | |
| 332 | if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 333 | struct ieee80211_cts *cts; |
| 334 | |
| 335 | if (b43_is_old_txhdr_format(dev)) { |
| 336 | cts = (struct ieee80211_cts *) |
| 337 | (txhdr->old_format.rts_frame); |
| 338 | } else { |
| 339 | cts = (struct ieee80211_cts *) |
| 340 | (txhdr->new_format.rts_frame); |
| 341 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 342 | ieee80211_ctstoself_get(dev->wl->hw, txctl->vif, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 343 | fragment_data, fragment_len, |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 344 | txctl, cts); |
| 345 | mac_ctl |= B43_TXH_MAC_SENDCTS; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 346 | len = sizeof(struct ieee80211_cts); |
| 347 | } else { |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 348 | struct ieee80211_rts *rts; |
| 349 | |
| 350 | if (b43_is_old_txhdr_format(dev)) { |
| 351 | rts = (struct ieee80211_rts *) |
| 352 | (txhdr->old_format.rts_frame); |
| 353 | } else { |
| 354 | rts = (struct ieee80211_rts *) |
| 355 | (txhdr->new_format.rts_frame); |
| 356 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 357 | ieee80211_rts_get(dev->wl->hw, txctl->vif, |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 358 | fragment_data, fragment_len, |
| 359 | txctl, rts); |
| 360 | mac_ctl |= B43_TXH_MAC_SENDRTS; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 361 | len = sizeof(struct ieee80211_rts); |
| 362 | } |
| 363 | len += FCS_LEN; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 364 | |
| 365 | /* Generate the PLCP headers for the RTS/CTS frame */ |
| 366 | if (b43_is_old_txhdr_format(dev)) |
| 367 | plcp = &txhdr->old_format.rts_plcp; |
| 368 | else |
| 369 | plcp = &txhdr->new_format.rts_plcp; |
| 370 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, |
| 371 | len, rts_rate); |
| 372 | plcp = &txhdr->rts_plcp_fb; |
| 373 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 374 | len, rts_rate_fb); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 375 | |
| 376 | if (b43_is_old_txhdr_format(dev)) { |
| 377 | hdr = (struct ieee80211_hdr *) |
| 378 | (&txhdr->old_format.rts_frame); |
| 379 | } else { |
| 380 | hdr = (struct ieee80211_hdr *) |
| 381 | (&txhdr->new_format.rts_frame); |
| 382 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 383 | txhdr->rts_dur_fb = hdr->duration_id; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 384 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 385 | if (rts_rate_ofdm) { |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 386 | extra_ft |= B43_TXH_EFT_RTS_OFDM; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 387 | txhdr->phy_rate_rts = |
| 388 | b43_plcp_get_ratecode_ofdm(rts_rate); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 389 | } else { |
| 390 | extra_ft |= B43_TXH_EFT_RTS_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 391 | txhdr->phy_rate_rts = |
| 392 | b43_plcp_get_ratecode_cck(rts_rate); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 393 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 394 | if (rts_rate_fb_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 395 | extra_ft |= B43_TXH_EFT_RTSFB_OFDM; |
| 396 | else |
| 397 | extra_ft |= B43_TXH_EFT_RTSFB_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /* Magic cookie */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame^] | 401 | if (b43_is_old_txhdr_format(dev)) |
| 402 | txhdr->old_format.cookie = cpu_to_le16(cookie); |
| 403 | else |
| 404 | txhdr->new_format.cookie = cpu_to_le16(cookie); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 405 | |
| 406 | /* Apply the bitfields */ |
| 407 | txhdr->mac_ctl = cpu_to_le32(mac_ctl); |
| 408 | txhdr->phy_ctl = cpu_to_le16(phy_ctl); |
| 409 | txhdr->extra_ft = extra_ft; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 410 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static s8 b43_rssi_postprocess(struct b43_wldev *dev, |
| 414 | u8 in_rssi, int ofdm, |
| 415 | int adjust_2053, int adjust_2050) |
| 416 | { |
| 417 | struct b43_phy *phy = &dev->phy; |
| 418 | s32 tmp; |
| 419 | |
| 420 | switch (phy->radio_ver) { |
| 421 | case 0x2050: |
| 422 | if (ofdm) { |
| 423 | tmp = in_rssi; |
| 424 | if (tmp > 127) |
| 425 | tmp -= 256; |
| 426 | tmp *= 73; |
| 427 | tmp /= 64; |
| 428 | if (adjust_2050) |
| 429 | tmp += 25; |
| 430 | else |
| 431 | tmp -= 3; |
| 432 | } else { |
Larry Finger | 95de284 | 2007-11-09 16:57:18 -0600 | [diff] [blame] | 433 | if (dev->dev->bus->sprom. |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 434 | boardflags_lo & B43_BFL_RSSI) { |
| 435 | if (in_rssi > 63) |
| 436 | in_rssi = 63; |
| 437 | tmp = phy->nrssi_lt[in_rssi]; |
| 438 | tmp = 31 - tmp; |
| 439 | tmp *= -131; |
| 440 | tmp /= 128; |
| 441 | tmp -= 57; |
| 442 | } else { |
| 443 | tmp = in_rssi; |
| 444 | tmp = 31 - tmp; |
| 445 | tmp *= -149; |
| 446 | tmp /= 128; |
| 447 | tmp -= 68; |
| 448 | } |
| 449 | if (phy->type == B43_PHYTYPE_G && adjust_2050) |
| 450 | tmp += 25; |
| 451 | } |
| 452 | break; |
| 453 | case 0x2060: |
| 454 | if (in_rssi > 127) |
| 455 | tmp = in_rssi - 256; |
| 456 | else |
| 457 | tmp = in_rssi; |
| 458 | break; |
| 459 | default: |
| 460 | tmp = in_rssi; |
| 461 | tmp -= 11; |
| 462 | tmp *= 103; |
| 463 | tmp /= 64; |
| 464 | if (adjust_2053) |
| 465 | tmp -= 109; |
| 466 | else |
| 467 | tmp -= 83; |
| 468 | } |
| 469 | |
| 470 | return (s8) tmp; |
| 471 | } |
| 472 | |
| 473 | //TODO |
| 474 | #if 0 |
| 475 | static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi) |
| 476 | { |
| 477 | struct b43_phy *phy = &dev->phy; |
| 478 | s8 ret; |
| 479 | |
| 480 | if (phy->type == B43_PHYTYPE_A) { |
| 481 | //TODO: Incomplete specs. |
| 482 | ret = 0; |
| 483 | } else |
| 484 | ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1); |
| 485 | |
| 486 | return ret; |
| 487 | } |
| 488 | #endif |
| 489 | |
| 490 | void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) |
| 491 | { |
| 492 | struct ieee80211_rx_status status; |
| 493 | struct b43_plcp_hdr6 *plcp; |
| 494 | struct ieee80211_hdr *wlhdr; |
| 495 | const struct b43_rxhdr_fw4 *rxhdr = _rxhdr; |
| 496 | u16 fctl; |
| 497 | u16 phystat0, phystat3, chanstat, mactime; |
| 498 | u32 macstat; |
| 499 | u16 chanid; |
| 500 | u8 jssi; |
| 501 | int padding; |
| 502 | |
| 503 | memset(&status, 0, sizeof(status)); |
| 504 | |
| 505 | /* Get metadata about the frame from the header. */ |
| 506 | phystat0 = le16_to_cpu(rxhdr->phy_status0); |
| 507 | phystat3 = le16_to_cpu(rxhdr->phy_status3); |
| 508 | jssi = rxhdr->jssi; |
| 509 | macstat = le32_to_cpu(rxhdr->mac_status); |
| 510 | mactime = le16_to_cpu(rxhdr->mac_time); |
| 511 | chanstat = le16_to_cpu(rxhdr->channel); |
| 512 | |
| 513 | if (macstat & B43_RX_MAC_FCSERR) |
| 514 | dev->wl->ieee_stats.dot11FCSErrorCount++; |
| 515 | if (macstat & B43_RX_MAC_DECERR) { |
| 516 | /* Decryption with the given key failed. |
| 517 | * Drop the packet. We also won't be able to decrypt it with |
| 518 | * the key in software. */ |
| 519 | goto drop; |
| 520 | } |
| 521 | |
| 522 | /* Skip PLCP and padding */ |
| 523 | padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0; |
| 524 | if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) { |
| 525 | b43dbg(dev->wl, "RX: Packet size underrun (1)\n"); |
| 526 | goto drop; |
| 527 | } |
| 528 | plcp = (struct b43_plcp_hdr6 *)(skb->data + padding); |
| 529 | skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding); |
| 530 | /* The skb contains the Wireless Header + payload data now */ |
| 531 | if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) { |
| 532 | b43dbg(dev->wl, "RX: Packet size underrun (2)\n"); |
| 533 | goto drop; |
| 534 | } |
| 535 | wlhdr = (struct ieee80211_hdr *)(skb->data); |
| 536 | fctl = le16_to_cpu(wlhdr->frame_control); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 537 | |
| 538 | if (macstat & B43_RX_MAC_DEC) { |
| 539 | unsigned int keyidx; |
| 540 | int wlhdr_len; |
| 541 | |
| 542 | keyidx = ((macstat & B43_RX_MAC_KEYIDX) |
| 543 | >> B43_RX_MAC_KEYIDX_SHIFT); |
| 544 | /* We must adjust the key index here. We want the "physical" |
| 545 | * key index, but the ucode passed it slightly different. |
| 546 | */ |
| 547 | keyidx = b43_kidx_to_raw(dev, keyidx); |
| 548 | B43_WARN_ON(keyidx >= dev->max_nr_keys); |
| 549 | |
| 550 | if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) { |
| 551 | wlhdr_len = ieee80211_get_hdrlen(fctl); |
| 552 | if (unlikely(skb->len < (wlhdr_len + 3))) { |
| 553 | b43dbg(dev->wl, |
| 554 | "RX: Packet size underrun (3)\n"); |
| 555 | goto drop; |
| 556 | } |
| 557 | status.flag |= RX_FLAG_DECRYPTED; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | status.ssi = b43_rssi_postprocess(dev, jssi, |
| 562 | (phystat0 & B43_RX_PHYST0_OFDM), |
| 563 | (phystat0 & B43_RX_PHYST0_GAINCTL), |
| 564 | (phystat3 & B43_RX_PHYST3_TRSTATE)); |
| 565 | status.noise = dev->stats.link_noise; |
| 566 | /* the next line looks wrong, but is what mac80211 wants */ |
| 567 | status.signal = (jssi * 100) / B43_RX_MAX_SSI; |
| 568 | if (phystat0 & B43_RX_PHYST0_OFDM) |
| 569 | status.rate = b43_plcp_get_bitrate_ofdm(plcp); |
| 570 | else |
| 571 | status.rate = b43_plcp_get_bitrate_cck(plcp); |
| 572 | status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT); |
John W. Linville | c0ddd04 | 2008-01-21 13:41:18 -0500 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * If monitors are present get full 64-bit timestamp. This |
| 576 | * code assumes we get to process the packet within 16 bits |
| 577 | * of timestamp, i.e. about 65 milliseconds after the PHY |
| 578 | * received the first symbol. |
| 579 | */ |
| 580 | if (dev->wl->radiotap_enabled) { |
| 581 | u16 low_mactime_now; |
| 582 | |
| 583 | b43_tsf_read(dev, &status.mactime); |
| 584 | low_mactime_now = status.mactime; |
| 585 | status.mactime = status.mactime & ~0xFFFFULL; |
| 586 | status.mactime += mactime; |
| 587 | if (low_mactime_now <= mactime) |
| 588 | status.mactime -= 0x10000; |
| 589 | status.flag |= RX_FLAG_TSFT; |
| 590 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 591 | |
| 592 | chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT; |
| 593 | switch (chanstat & B43_RX_CHAN_PHYTYPE) { |
| 594 | case B43_PHYTYPE_A: |
| 595 | status.phymode = MODE_IEEE80211A; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 596 | B43_WARN_ON(1); |
| 597 | /* FIXME: We don't really know which value the "chanid" contains. |
| 598 | * So the following assignment might be wrong. */ |
| 599 | status.channel = chanid; |
| 600 | status.freq = b43_channel_to_freq_5ghz(status.channel); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 601 | break; |
| 602 | case B43_PHYTYPE_G: |
| 603 | status.phymode = MODE_IEEE80211G; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 604 | /* chanid is the radio channel cookie value as used |
| 605 | * to tune the radio. */ |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 606 | status.freq = chanid + 2400; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 607 | status.channel = b43_freq_to_channel_2ghz(status.freq); |
| 608 | break; |
| 609 | case B43_PHYTYPE_N: |
| 610 | status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/; |
| 611 | /* chanid is the SHM channel cookie. Which is the plain |
| 612 | * channel number in b43. */ |
| 613 | status.channel = chanid; |
| 614 | if (chanstat & B43_RX_CHAN_5GHZ) |
| 615 | status.freq = b43_freq_to_channel_5ghz(status.freq); |
| 616 | else |
| 617 | status.freq = b43_freq_to_channel_2ghz(status.freq); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 618 | break; |
| 619 | default: |
| 620 | B43_WARN_ON(1); |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 621 | goto drop; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | dev->stats.last_rx = jiffies; |
| 625 | ieee80211_rx_irqsafe(dev->wl->hw, skb, &status); |
| 626 | |
| 627 | return; |
| 628 | drop: |
| 629 | b43dbg(dev->wl, "RX: Packet dropped\n"); |
| 630 | dev_kfree_skb_any(skb); |
| 631 | } |
| 632 | |
| 633 | void b43_handle_txstatus(struct b43_wldev *dev, |
| 634 | const struct b43_txstatus *status) |
| 635 | { |
| 636 | b43_debugfs_log_txstat(dev, status); |
| 637 | |
| 638 | if (status->intermediate) |
| 639 | return; |
| 640 | if (status->for_ampdu) |
| 641 | return; |
| 642 | if (!status->acked) |
| 643 | dev->wl->ieee_stats.dot11ACKFailureCount++; |
| 644 | if (status->rts_count) { |
| 645 | if (status->rts_count == 0xF) //FIXME |
| 646 | dev->wl->ieee_stats.dot11RTSFailureCount++; |
| 647 | else |
| 648 | dev->wl->ieee_stats.dot11RTSSuccessCount++; |
| 649 | } |
| 650 | |
Michael Buesch | 03b2977 | 2007-12-26 14:41:30 +0100 | [diff] [blame] | 651 | b43_dma_handle_txstatus(dev, status); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* Handle TX status report as received through DMA/PIO queues */ |
| 655 | void b43_handle_hwtxstatus(struct b43_wldev *dev, |
| 656 | const struct b43_hwtxstatus *hw) |
| 657 | { |
| 658 | struct b43_txstatus status; |
| 659 | u8 tmp; |
| 660 | |
| 661 | status.cookie = le16_to_cpu(hw->cookie); |
| 662 | status.seq = le16_to_cpu(hw->seq); |
| 663 | status.phy_stat = hw->phy_stat; |
| 664 | tmp = hw->count; |
| 665 | status.frame_count = (tmp >> 4); |
| 666 | status.rts_count = (tmp & 0x0F); |
| 667 | tmp = hw->flags; |
| 668 | status.supp_reason = ((tmp & 0x1C) >> 2); |
| 669 | status.pm_indicated = !!(tmp & 0x80); |
| 670 | status.intermediate = !!(tmp & 0x40); |
| 671 | status.for_ampdu = !!(tmp & 0x20); |
| 672 | status.acked = !!(tmp & 0x02); |
| 673 | |
| 674 | b43_handle_txstatus(dev, &status); |
| 675 | } |
| 676 | |
| 677 | /* Stop any TX operation on the device (suspend the hardware queues) */ |
| 678 | void b43_tx_suspend(struct b43_wldev *dev) |
| 679 | { |
Michael Buesch | 03b2977 | 2007-12-26 14:41:30 +0100 | [diff] [blame] | 680 | b43_dma_tx_suspend(dev); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /* Resume any TX operation on the device (resume the hardware queues) */ |
| 684 | void b43_tx_resume(struct b43_wldev *dev) |
| 685 | { |
Michael Buesch | 03b2977 | 2007-12-26 14:41:30 +0100 | [diff] [blame] | 686 | b43_dma_tx_resume(dev); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | #if 0 |
| 690 | static void upload_qos_parms(struct b43_wldev *dev, |
| 691 | const u16 * parms, u16 offset) |
| 692 | { |
| 693 | int i; |
| 694 | |
| 695 | for (i = 0; i < B43_NR_QOSPARMS; i++) { |
| 696 | b43_shm_write16(dev, B43_SHM_SHARED, |
| 697 | offset + (i * 2), parms[i]); |
| 698 | } |
| 699 | } |
| 700 | #endif |
| 701 | |
| 702 | /* Initialize the QoS parameters */ |
| 703 | void b43_qos_init(struct b43_wldev *dev) |
| 704 | { |
| 705 | /* FIXME: This function must probably be called from the mac80211 |
| 706 | * config callback. */ |
| 707 | return; |
| 708 | |
| 709 | b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF); |
| 710 | //FIXME kill magic |
| 711 | b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4); |
| 712 | |
| 713 | /*TODO: We might need some stack support here to get the values. */ |
| 714 | } |