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