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