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