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 Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 9 | Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch> |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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 | |
Michael Buesch | 88499ab | 2009-10-09 20:33:32 +0200 | [diff] [blame] | 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 | |
Rafał Miłecki | 3311abb | 2011-02-25 12:34:11 +0100 | [diff] [blame] | 35 | static const struct b43_tx_legacy_rate_phy_ctl_entry b43_tx_legacy_rate_phy_ctl[] = { |
| 36 | { B43_CCK_RATE_1MB, 0x0, 0x0 }, |
| 37 | { B43_CCK_RATE_2MB, 0x0, 0x1 }, |
| 38 | { B43_CCK_RATE_5MB, 0x0, 0x2 }, |
| 39 | { B43_CCK_RATE_11MB, 0x0, 0x3 }, |
| 40 | { B43_OFDM_RATE_6MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_BPSK }, |
| 41 | { B43_OFDM_RATE_9MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_BPSK }, |
| 42 | { B43_OFDM_RATE_12MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QPSK }, |
| 43 | { B43_OFDM_RATE_18MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QPSK }, |
| 44 | { B43_OFDM_RATE_24MB, B43_TXH_PHY1_CRATE_1_2, B43_TXH_PHY1_MODUL_QAM16 }, |
| 45 | { B43_OFDM_RATE_36MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM16 }, |
| 46 | { B43_OFDM_RATE_48MB, B43_TXH_PHY1_CRATE_2_3, B43_TXH_PHY1_MODUL_QAM64 }, |
| 47 | { B43_OFDM_RATE_54MB, B43_TXH_PHY1_CRATE_3_4, B43_TXH_PHY1_MODUL_QAM64 }, |
| 48 | }; |
| 49 | |
| 50 | static const struct b43_tx_legacy_rate_phy_ctl_entry * |
| 51 | b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate) |
| 52 | { |
| 53 | const struct b43_tx_legacy_rate_phy_ctl_entry *e; |
| 54 | unsigned int i; |
| 55 | |
| 56 | for (i = 0; i < ARRAY_SIZE(b43_tx_legacy_rate_phy_ctl); i++) { |
| 57 | e = &(b43_tx_legacy_rate_phy_ctl[i]); |
| 58 | if (e->bitrate == bitrate) |
| 59 | return e; |
| 60 | } |
| 61 | |
| 62 | B43_WARN_ON(1); |
| 63 | return NULL; |
| 64 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 66 | /* Extract the bitrate index out of a CCK PLCP header. */ |
| 67 | 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] | 68 | { |
| 69 | switch (plcp->raw[0]) { |
| 70 | case 0x0A: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 71 | return 0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 72 | case 0x14: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 73 | return 1; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 74 | case 0x37: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 75 | return 2; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 76 | case 0x6E: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 77 | return 3; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 78 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 79 | return -1; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 82 | /* Extract the bitrate index out of an OFDM PLCP header. */ |
Lorenzo Nava | a3c0b87 | 2009-03-22 19:15:41 +0100 | [diff] [blame] | 83 | 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] | 84 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 85 | int base = aphy ? 0 : 4; |
| 86 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 87 | switch (plcp->raw[0] & 0xF) { |
| 88 | case 0xB: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 89 | return base + 0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 90 | case 0xF: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 91 | return base + 1; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 92 | case 0xA: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 93 | return base + 2; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 94 | case 0xE: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 95 | return base + 3; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 96 | case 0x9: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 97 | return base + 4; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 98 | case 0xD: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 99 | return base + 5; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 100 | case 0x8: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 101 | return base + 6; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 102 | case 0xC: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 103 | return base + 7; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 104 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 105 | return -1; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | u8 b43_plcp_get_ratecode_cck(const u8 bitrate) |
| 109 | { |
| 110 | switch (bitrate) { |
| 111 | case B43_CCK_RATE_1MB: |
| 112 | return 0x0A; |
| 113 | case B43_CCK_RATE_2MB: |
| 114 | return 0x14; |
| 115 | case B43_CCK_RATE_5MB: |
| 116 | return 0x37; |
| 117 | case B43_CCK_RATE_11MB: |
| 118 | return 0x6E; |
| 119 | } |
| 120 | B43_WARN_ON(1); |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate) |
| 125 | { |
| 126 | switch (bitrate) { |
| 127 | case B43_OFDM_RATE_6MB: |
| 128 | return 0xB; |
| 129 | case B43_OFDM_RATE_9MB: |
| 130 | return 0xF; |
| 131 | case B43_OFDM_RATE_12MB: |
| 132 | return 0xA; |
| 133 | case B43_OFDM_RATE_18MB: |
| 134 | return 0xE; |
| 135 | case B43_OFDM_RATE_24MB: |
| 136 | return 0x9; |
| 137 | case B43_OFDM_RATE_36MB: |
| 138 | return 0xD; |
| 139 | case B43_OFDM_RATE_48MB: |
| 140 | return 0x8; |
| 141 | case B43_OFDM_RATE_54MB: |
| 142 | return 0xC; |
| 143 | } |
| 144 | B43_WARN_ON(1); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp, |
| 149 | const u16 octets, const u8 bitrate) |
| 150 | { |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 151 | __u8 *raw = plcp->raw; |
| 152 | |
| 153 | if (b43_is_ofdm_rate(bitrate)) { |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 154 | u32 d; |
| 155 | |
| 156 | d = b43_plcp_get_ratecode_ofdm(bitrate); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 157 | B43_WARN_ON(octets & 0xF000); |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 158 | d |= (octets << 5); |
Matthieu CASTET | b52a033 | 2009-06-04 23:18:33 +0200 | [diff] [blame] | 159 | plcp->data = cpu_to_le32(d); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 160 | } else { |
| 161 | u32 plen; |
| 162 | |
| 163 | plen = octets * 16 / bitrate; |
| 164 | if ((octets * 16 % bitrate) > 0) { |
| 165 | plen++; |
| 166 | if ((bitrate == B43_CCK_RATE_11MB) |
| 167 | && ((octets * 8 % 11) < 4)) { |
| 168 | raw[1] = 0x84; |
| 169 | } else |
| 170 | raw[1] = 0x04; |
| 171 | } else |
| 172 | raw[1] = 0x04; |
Matthieu CASTET | b52a033 | 2009-06-04 23:18:33 +0200 | [diff] [blame] | 173 | plcp->data |= cpu_to_le32(plen << 16); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 174 | raw[0] = b43_plcp_get_ratecode_cck(bitrate); |
| 175 | } |
| 176 | } |
| 177 | |
Rafał Miłecki | 694718d | 2011-10-17 16:59:25 +0200 | [diff] [blame] | 178 | /* TODO: verify if needed for SSLPN or LCN */ |
Rafał Miłecki | 3311abb | 2011-02-25 12:34:11 +0100 | [diff] [blame] | 179 | static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate) |
| 180 | { |
| 181 | const struct b43_phy *phy = &dev->phy; |
| 182 | const struct b43_tx_legacy_rate_phy_ctl_entry *e; |
| 183 | u16 control = 0; |
| 184 | u16 bw; |
| 185 | |
| 186 | if (phy->type == B43_PHYTYPE_LP) |
| 187 | bw = B43_TXH_PHY1_BW_20; |
| 188 | else /* FIXME */ |
| 189 | bw = B43_TXH_PHY1_BW_20; |
| 190 | |
| 191 | if (0) { /* FIXME: MIMO */ |
| 192 | } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) { |
| 193 | control = bw; |
| 194 | } else { |
| 195 | control = bw; |
| 196 | e = b43_tx_legacy_rate_phy_ctl_ent(bitrate); |
| 197 | if (e) { |
| 198 | control |= e->coding_rate; |
| 199 | control |= e->modulation; |
| 200 | } |
| 201 | control |= B43_TXH_PHY1_MODE_SISO; |
| 202 | } |
| 203 | |
| 204 | return control; |
| 205 | } |
| 206 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 207 | static u8 b43_calc_fallback_rate(u8 bitrate) |
| 208 | { |
| 209 | switch (bitrate) { |
| 210 | case B43_CCK_RATE_1MB: |
| 211 | return B43_CCK_RATE_1MB; |
| 212 | case B43_CCK_RATE_2MB: |
| 213 | return B43_CCK_RATE_1MB; |
| 214 | case B43_CCK_RATE_5MB: |
| 215 | return B43_CCK_RATE_2MB; |
| 216 | case B43_CCK_RATE_11MB: |
| 217 | return B43_CCK_RATE_5MB; |
| 218 | case B43_OFDM_RATE_6MB: |
| 219 | return B43_CCK_RATE_5MB; |
| 220 | case B43_OFDM_RATE_9MB: |
| 221 | return B43_OFDM_RATE_6MB; |
| 222 | case B43_OFDM_RATE_12MB: |
| 223 | return B43_OFDM_RATE_9MB; |
| 224 | case B43_OFDM_RATE_18MB: |
| 225 | return B43_OFDM_RATE_12MB; |
| 226 | case B43_OFDM_RATE_24MB: |
| 227 | return B43_OFDM_RATE_18MB; |
| 228 | case B43_OFDM_RATE_36MB: |
| 229 | return B43_OFDM_RATE_24MB; |
| 230 | case B43_OFDM_RATE_48MB: |
| 231 | return B43_OFDM_RATE_36MB; |
| 232 | case B43_OFDM_RATE_54MB: |
| 233 | return B43_OFDM_RATE_48MB; |
| 234 | } |
| 235 | B43_WARN_ON(1); |
| 236 | return 0; |
| 237 | } |
| 238 | |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 239 | /* Generate a TX data header. */ |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 240 | int b43_generate_txhdr(struct b43_wldev *dev, |
| 241 | u8 *_txhdr, |
gregor kowski | 035d024 | 2009-08-19 22:35:45 +0200 | [diff] [blame] | 242 | struct sk_buff *skb_frag, |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 243 | struct ieee80211_tx_info *info, |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 244 | u16 cookie) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 245 | { |
gregor kowski | 035d024 | 2009-08-19 22:35:45 +0200 | [diff] [blame] | 246 | const unsigned char *fragment_data = skb_frag->data; |
| 247 | unsigned int fragment_len = skb_frag->len; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 248 | struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 249 | const struct b43_phy *phy = &dev->phy; |
| 250 | const struct ieee80211_hdr *wlhdr = |
| 251 | (const struct ieee80211_hdr *)fragment_data; |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 252 | int use_encryption = !!info->control.hw_key; |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 253 | __le16 fctl = wlhdr->frame_control; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 254 | struct ieee80211_rate *fbrate; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 255 | u8 rate, rate_fb; |
| 256 | int rate_ofdm, rate_fb_ofdm; |
| 257 | unsigned int plcp_fragment_len; |
| 258 | u32 mac_ctl = 0; |
| 259 | u16 phy_ctl = 0; |
Rafał Miłecki | 694718d | 2011-10-17 16:59:25 +0200 | [diff] [blame] | 260 | bool fill_phy_ctl1 = (phy->type == B43_PHYTYPE_LP || |
| 261 | phy->type == B43_PHYTYPE_N || |
| 262 | phy->type == B43_PHYTYPE_HT); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 263 | u8 extra_ft = 0; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 264 | struct ieee80211_rate *txrate; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 265 | struct ieee80211_tx_rate *rates; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 266 | |
| 267 | memset(txhdr, 0, sizeof(*txhdr)); |
| 268 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 269 | txrate = ieee80211_get_tx_rate(dev->wl->hw, info); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 270 | rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 271 | rate_ofdm = b43_is_ofdm_rate(rate); |
Felix Fietkau | 870abdf | 2008-10-05 18:04:24 +0200 | [diff] [blame] | 272 | fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 273 | rate_fb = fbrate->hw_value; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 274 | rate_fb_ofdm = b43_is_ofdm_rate(rate_fb); |
| 275 | |
| 276 | if (rate_ofdm) |
| 277 | txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate); |
| 278 | else |
| 279 | txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate); |
| 280 | txhdr->mac_frame_ctl = wlhdr->frame_control; |
| 281 | memcpy(txhdr->tx_receiver, wlhdr->addr1, 6); |
| 282 | |
| 283 | /* Calculate duration for fallback rate */ |
| 284 | if ((rate_fb == rate) || |
| 285 | (wlhdr->duration_id & cpu_to_le16(0x8000)) || |
| 286 | (wlhdr->duration_id == cpu_to_le16(0))) { |
| 287 | /* If the fallback rate equals the normal rate or the |
| 288 | * dur_id field contains an AID, CFP magic or 0, |
| 289 | * use the original dur_id field. */ |
| 290 | txhdr->dur_fb = wlhdr->duration_id; |
| 291 | } else { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 292 | txhdr->dur_fb = ieee80211_generic_frame_duration( |
| 293 | dev->wl->hw, info->control.vif, fragment_len, fbrate); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | plcp_fragment_len = fragment_len + FCS_LEN; |
| 297 | if (use_encryption) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 298 | u8 key_idx = info->control.hw_key->hw_key_idx; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 299 | struct b43_key *key; |
| 300 | int wlhdr_len; |
| 301 | size_t iv_len; |
| 302 | |
Michael Buesch | 66d2d08 | 2009-08-06 10:36:50 +0200 | [diff] [blame] | 303 | B43_WARN_ON(key_idx >= ARRAY_SIZE(dev->key)); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 304 | key = &(dev->key[key_idx]); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 305 | |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 306 | if (unlikely(!key->keyconf)) { |
| 307 | /* This key is invalid. This might only happen |
| 308 | * in a short timeframe after machine resume before |
| 309 | * we were able to reconfigure keys. |
| 310 | * Drop this packet completely. Do not transmit it |
| 311 | * unencrypted to avoid leaking information. */ |
| 312 | return -ENOKEY; |
Michael Buesch | 7be1bb6 | 2008-01-23 21:10:56 +0100 | [diff] [blame] | 313 | } |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 314 | |
| 315 | /* Hardware appends ICV. */ |
Felix Fietkau | 76708de | 2008-10-05 18:02:48 +0200 | [diff] [blame] | 316 | plcp_fragment_len += info->control.hw_key->icv_len; |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 317 | |
| 318 | key_idx = b43_kidx_to_fw(dev, key_idx); |
| 319 | mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) & |
| 320 | B43_TXH_MAC_KEYIDX; |
| 321 | mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) & |
| 322 | B43_TXH_MAC_KEYALG; |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 323 | wlhdr_len = ieee80211_hdrlen(fctl); |
gregor kowski | 035d024 | 2009-08-19 22:35:45 +0200 | [diff] [blame] | 324 | if (key->algorithm == B43_SEC_ALGO_TKIP) { |
| 325 | u16 phase1key[5]; |
| 326 | int i; |
| 327 | /* we give the phase1key and iv16 here, the key is stored in |
| 328 | * shm. With that the hardware can do phase 2 and encryption. |
| 329 | */ |
Johannes Berg | 523b02e | 2011-07-07 22:28:01 +0200 | [diff] [blame] | 330 | ieee80211_get_tkip_p1k(info->control.hw_key, skb_frag, phase1key); |
Michael Buesch | cde1b55 | 2009-09-06 16:18:58 +0200 | [diff] [blame] | 331 | /* phase1key is in host endian. Copy to little-endian txhdr->iv. */ |
| 332 | for (i = 0; i < 5; i++) { |
| 333 | txhdr->iv[i * 2 + 0] = phase1key[i]; |
| 334 | txhdr->iv[i * 2 + 1] = phase1key[i] >> 8; |
| 335 | } |
gregor kowski | 035d024 | 2009-08-19 22:35:45 +0200 | [diff] [blame] | 336 | /* iv16 */ |
| 337 | memcpy(txhdr->iv + 10, ((u8 *) wlhdr) + wlhdr_len, 3); |
| 338 | } else { |
| 339 | iv_len = min((size_t) info->control.hw_key->iv_len, |
| 340 | ARRAY_SIZE(txhdr->iv)); |
| 341 | memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len); |
| 342 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 343 | } |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 344 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 345 | case B43_FW_HDR_598: |
| 346 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_598.plcp), |
| 347 | plcp_fragment_len, rate); |
| 348 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 349 | case B43_FW_HDR_351: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 350 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_351.plcp), |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 351 | plcp_fragment_len, rate); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 352 | break; |
| 353 | case B43_FW_HDR_410: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 354 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_410.plcp), |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 355 | plcp_fragment_len, rate); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 356 | break; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 357 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 358 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb), |
| 359 | plcp_fragment_len, rate_fb); |
| 360 | |
| 361 | /* Extra Frame Types */ |
| 362 | if (rate_fb_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 363 | extra_ft |= B43_TXH_EFT_FB_OFDM; |
| 364 | else |
| 365 | extra_ft |= B43_TXH_EFT_FB_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 366 | |
| 367 | /* Set channel radio code. Note that the micrcode ORs 0x100 to |
| 368 | * this value before comparing it to the value in SHM, if this |
| 369 | * is a 5Ghz packet. |
| 370 | */ |
| 371 | txhdr->chan_radio_code = phy->channel; |
| 372 | |
| 373 | /* PHY TX Control word */ |
| 374 | if (rate_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 375 | phy_ctl |= B43_TXH_PHY_ENC_OFDM; |
| 376 | else |
| 377 | phy_ctl |= B43_TXH_PHY_ENC_CCK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 378 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 379 | phy_ctl |= B43_TXH_PHY_SHORTPRMBL; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 380 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 381 | switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) { |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 382 | case 0: /* Default */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 383 | phy_ctl |= B43_TXH_PHY_ANT01AUTO; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 384 | break; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 385 | case 1: /* Antenna 0 */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 386 | phy_ctl |= B43_TXH_PHY_ANT0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 387 | break; |
Michael Buesch | 9db1f6d | 2007-12-22 21:54:20 +0100 | [diff] [blame] | 388 | case 2: /* Antenna 1 */ |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 389 | phy_ctl |= B43_TXH_PHY_ANT1; |
| 390 | break; |
| 391 | case 3: /* Antenna 2 */ |
| 392 | phy_ctl |= B43_TXH_PHY_ANT2; |
| 393 | break; |
| 394 | case 4: /* Antenna 3 */ |
| 395 | phy_ctl |= B43_TXH_PHY_ANT3; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 396 | break; |
| 397 | default: |
| 398 | B43_WARN_ON(1); |
| 399 | } |
| 400 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 401 | rates = info->control.rates; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 402 | /* MAC control */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 403 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 404 | mac_ctl |= B43_TXH_MAC_ACK; |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 405 | /* use hardware sequence counter as the non-TID counter */ |
| 406 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 407 | mac_ctl |= B43_TXH_MAC_HWSEQ; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 408 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 409 | mac_ctl |= B43_TXH_MAC_STMSDU; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 410 | if (phy->type == B43_PHYTYPE_A) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 411 | mac_ctl |= B43_TXH_MAC_5GHZ; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 412 | |
| 413 | /* Overwrite rates[0].count to make the retry calculation |
| 414 | * in the tx status easier. need the actual retry limit to |
| 415 | * detect whether the fallback rate was used. |
| 416 | */ |
| 417 | if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || |
| 418 | (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) { |
| 419 | rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 420 | mac_ctl |= B43_TXH_MAC_LONGFRAME; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 421 | } else { |
| 422 | rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count; |
| 423 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 424 | |
| 425 | /* Generate the RTS or CTS-to-self frame */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 426 | if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) || |
| 427 | (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) { |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 428 | unsigned int len; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 429 | struct ieee80211_hdr *uninitialized_var(hdr); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 430 | int rts_rate, rts_rate_fb; |
| 431 | int rts_rate_ofdm, rts_rate_fb_ofdm; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 432 | struct b43_plcp_hdr6 *uninitialized_var(plcp); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 433 | struct ieee80211_rate *rts_cts_rate; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 434 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 435 | rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 436 | |
| 437 | 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] | 438 | rts_rate_ofdm = b43_is_ofdm_rate(rts_rate); |
| 439 | rts_rate_fb = b43_calc_fallback_rate(rts_rate); |
| 440 | rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb); |
| 441 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 442 | if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 443 | struct ieee80211_cts *uninitialized_var(cts); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 444 | |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 445 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 446 | case B43_FW_HDR_598: |
| 447 | cts = (struct ieee80211_cts *) |
| 448 | (txhdr->format_598.rts_frame); |
| 449 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 450 | case B43_FW_HDR_351: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 451 | cts = (struct ieee80211_cts *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 452 | (txhdr->format_351.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 453 | break; |
| 454 | case B43_FW_HDR_410: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 455 | cts = (struct ieee80211_cts *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 456 | (txhdr->format_410.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 457 | break; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 458 | } |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 459 | ieee80211_ctstoself_get(dev->wl->hw, info->control.vif, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 460 | fragment_data, fragment_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 461 | info, cts); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 462 | mac_ctl |= B43_TXH_MAC_SENDCTS; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 463 | len = sizeof(struct ieee80211_cts); |
| 464 | } else { |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 465 | struct ieee80211_rts *uninitialized_var(rts); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 466 | |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 467 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 468 | case B43_FW_HDR_598: |
| 469 | rts = (struct ieee80211_rts *) |
| 470 | (txhdr->format_598.rts_frame); |
| 471 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 472 | case B43_FW_HDR_351: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 473 | rts = (struct ieee80211_rts *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 474 | (txhdr->format_351.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 475 | break; |
| 476 | case B43_FW_HDR_410: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 477 | rts = (struct ieee80211_rts *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 478 | (txhdr->format_410.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 479 | break; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 480 | } |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 481 | ieee80211_rts_get(dev->wl->hw, info->control.vif, |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 482 | fragment_data, fragment_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 483 | info, rts); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 484 | mac_ctl |= B43_TXH_MAC_SENDRTS; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 485 | len = sizeof(struct ieee80211_rts); |
| 486 | } |
| 487 | len += FCS_LEN; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 488 | |
| 489 | /* Generate the PLCP headers for the RTS/CTS frame */ |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 490 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 491 | case B43_FW_HDR_598: |
| 492 | plcp = &txhdr->format_598.rts_plcp; |
| 493 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 494 | case B43_FW_HDR_351: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 495 | plcp = &txhdr->format_351.rts_plcp; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 496 | break; |
| 497 | case B43_FW_HDR_410: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 498 | plcp = &txhdr->format_410.rts_plcp; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 499 | break; |
| 500 | } |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 501 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, |
| 502 | len, rts_rate); |
| 503 | plcp = &txhdr->rts_plcp_fb; |
| 504 | b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 505 | len, rts_rate_fb); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 506 | |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 507 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 508 | case B43_FW_HDR_598: |
| 509 | hdr = (struct ieee80211_hdr *) |
| 510 | (&txhdr->format_598.rts_frame); |
| 511 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 512 | case B43_FW_HDR_351: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 513 | hdr = (struct ieee80211_hdr *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 514 | (&txhdr->format_351.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 515 | break; |
| 516 | case B43_FW_HDR_410: |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 517 | hdr = (struct ieee80211_hdr *) |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 518 | (&txhdr->format_410.rts_frame); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 519 | break; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 520 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 521 | txhdr->rts_dur_fb = hdr->duration_id; |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 522 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 523 | if (rts_rate_ofdm) { |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 524 | extra_ft |= B43_TXH_EFT_RTS_OFDM; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 525 | txhdr->phy_rate_rts = |
| 526 | b43_plcp_get_ratecode_ofdm(rts_rate); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 527 | } else { |
| 528 | extra_ft |= B43_TXH_EFT_RTS_CCK; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 529 | txhdr->phy_rate_rts = |
| 530 | b43_plcp_get_ratecode_cck(rts_rate); |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 531 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 532 | if (rts_rate_fb_ofdm) |
Michael Buesch | eb189d8b | 2008-01-28 14:47:41 -0800 | [diff] [blame] | 533 | extra_ft |= B43_TXH_EFT_RTSFB_OFDM; |
| 534 | else |
| 535 | extra_ft |= B43_TXH_EFT_RTSFB_CCK; |
Rafał Miłecki | 3311abb | 2011-02-25 12:34:11 +0100 | [diff] [blame] | 536 | |
| 537 | if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS && |
Rafał Miłecki | 694718d | 2011-10-17 16:59:25 +0200 | [diff] [blame] | 538 | fill_phy_ctl1) { |
Rafał Miłecki | 3311abb | 2011-02-25 12:34:11 +0100 | [diff] [blame] | 539 | txhdr->phy_ctl1_rts = cpu_to_le16( |
| 540 | b43_generate_tx_phy_ctl1(dev, rts_rate)); |
| 541 | txhdr->phy_ctl1_rts_fb = cpu_to_le16( |
| 542 | b43_generate_tx_phy_ctl1(dev, rts_rate_fb)); |
| 543 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* Magic cookie */ |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 547 | switch (dev->fw.hdr_format) { |
Rafał Miłecki | 5d85290 | 2011-08-11 15:07:16 +0200 | [diff] [blame] | 548 | case B43_FW_HDR_598: |
| 549 | txhdr->format_598.cookie = cpu_to_le16(cookie); |
| 550 | break; |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 551 | case B43_FW_HDR_351: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 552 | txhdr->format_351.cookie = cpu_to_le16(cookie); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 553 | break; |
| 554 | case B43_FW_HDR_410: |
Rafał Miłecki | 2391b7e | 2011-08-11 15:07:14 +0200 | [diff] [blame] | 555 | txhdr->format_410.cookie = cpu_to_le16(cookie); |
Rafał Miłecki | efe0249 | 2011-08-11 15:07:15 +0200 | [diff] [blame] | 556 | break; |
| 557 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 558 | |
Rafał Miłecki | 694718d | 2011-10-17 16:59:25 +0200 | [diff] [blame] | 559 | if (fill_phy_ctl1) { |
Rafał Miłecki | 3311abb | 2011-02-25 12:34:11 +0100 | [diff] [blame] | 560 | txhdr->phy_ctl1 = |
| 561 | cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate)); |
| 562 | txhdr->phy_ctl1_fb = |
| 563 | cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate_fb)); |
| 564 | } |
| 565 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 566 | /* Apply the bitfields */ |
| 567 | txhdr->mac_ctl = cpu_to_le32(mac_ctl); |
| 568 | txhdr->phy_ctl = cpu_to_le16(phy_ctl); |
| 569 | txhdr->extra_ft = extra_ft; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 570 | |
Michael Buesch | 09552cc | 2008-01-23 21:44:15 +0100 | [diff] [blame] | 571 | return 0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | static s8 b43_rssi_postprocess(struct b43_wldev *dev, |
| 575 | u8 in_rssi, int ofdm, |
| 576 | int adjust_2053, int adjust_2050) |
| 577 | { |
| 578 | struct b43_phy *phy = &dev->phy; |
Michael Buesch | ef1a628 | 2008-08-27 18:53:02 +0200 | [diff] [blame] | 579 | struct b43_phy_g *gphy = phy->g; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 580 | s32 tmp; |
| 581 | |
| 582 | switch (phy->radio_ver) { |
| 583 | case 0x2050: |
| 584 | if (ofdm) { |
| 585 | tmp = in_rssi; |
| 586 | if (tmp > 127) |
| 587 | tmp -= 256; |
| 588 | tmp *= 73; |
| 589 | tmp /= 64; |
| 590 | if (adjust_2050) |
| 591 | tmp += 25; |
| 592 | else |
| 593 | tmp -= 3; |
| 594 | } else { |
Rafał Miłecki | 0581483 | 2011-05-18 02:06:39 +0200 | [diff] [blame] | 595 | if (dev->dev->bus_sprom-> |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 596 | boardflags_lo & B43_BFL_RSSI) { |
| 597 | if (in_rssi > 63) |
| 598 | in_rssi = 63; |
Michael Buesch | ef1a628 | 2008-08-27 18:53:02 +0200 | [diff] [blame] | 599 | B43_WARN_ON(phy->type != B43_PHYTYPE_G); |
| 600 | tmp = gphy->nrssi_lt[in_rssi]; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 601 | tmp = 31 - tmp; |
| 602 | tmp *= -131; |
| 603 | tmp /= 128; |
| 604 | tmp -= 57; |
| 605 | } else { |
| 606 | tmp = in_rssi; |
| 607 | tmp = 31 - tmp; |
| 608 | tmp *= -149; |
| 609 | tmp /= 128; |
| 610 | tmp -= 68; |
| 611 | } |
| 612 | if (phy->type == B43_PHYTYPE_G && adjust_2050) |
| 613 | tmp += 25; |
| 614 | } |
| 615 | break; |
| 616 | case 0x2060: |
| 617 | if (in_rssi > 127) |
| 618 | tmp = in_rssi - 256; |
| 619 | else |
| 620 | tmp = in_rssi; |
| 621 | break; |
| 622 | default: |
| 623 | tmp = in_rssi; |
| 624 | tmp -= 11; |
| 625 | tmp *= 103; |
| 626 | tmp /= 64; |
| 627 | if (adjust_2053) |
| 628 | tmp -= 109; |
| 629 | else |
| 630 | tmp -= 83; |
| 631 | } |
| 632 | |
| 633 | return (s8) tmp; |
| 634 | } |
| 635 | |
| 636 | //TODO |
| 637 | #if 0 |
| 638 | static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi) |
| 639 | { |
| 640 | struct b43_phy *phy = &dev->phy; |
| 641 | s8 ret; |
| 642 | |
| 643 | if (phy->type == B43_PHYTYPE_A) { |
| 644 | //TODO: Incomplete specs. |
| 645 | ret = 0; |
| 646 | } else |
| 647 | ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1); |
| 648 | |
| 649 | return ret; |
| 650 | } |
| 651 | #endif |
| 652 | |
| 653 | void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) |
| 654 | { |
| 655 | struct ieee80211_rx_status status; |
| 656 | struct b43_plcp_hdr6 *plcp; |
| 657 | struct ieee80211_hdr *wlhdr; |
| 658 | const struct b43_rxhdr_fw4 *rxhdr = _rxhdr; |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 659 | __le16 fctl; |
Rafał Miłecki | 17030f4 | 2011-08-11 17:16:27 +0200 | [diff] [blame] | 660 | u16 phystat0, phystat3; |
| 661 | u16 uninitialized_var(chanstat), uninitialized_var(mactime); |
| 662 | u32 uninitialized_var(macstat); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 663 | u16 chanid; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 664 | u16 phytype; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 665 | int padding; |
| 666 | |
| 667 | memset(&status, 0, sizeof(status)); |
| 668 | |
| 669 | /* Get metadata about the frame from the header. */ |
| 670 | phystat0 = le16_to_cpu(rxhdr->phy_status0); |
| 671 | phystat3 = le16_to_cpu(rxhdr->phy_status3); |
Rafał Miłecki | 17030f4 | 2011-08-11 17:16:27 +0200 | [diff] [blame] | 672 | switch (dev->fw.hdr_format) { |
| 673 | case B43_FW_HDR_598: |
| 674 | macstat = le32_to_cpu(rxhdr->format_598.mac_status); |
| 675 | mactime = le16_to_cpu(rxhdr->format_598.mac_time); |
| 676 | chanstat = le16_to_cpu(rxhdr->format_598.channel); |
| 677 | break; |
| 678 | case B43_FW_HDR_410: |
| 679 | case B43_FW_HDR_351: |
| 680 | macstat = le32_to_cpu(rxhdr->format_351.mac_status); |
| 681 | mactime = le16_to_cpu(rxhdr->format_351.mac_time); |
| 682 | chanstat = le16_to_cpu(rxhdr->format_351.channel); |
| 683 | break; |
| 684 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 685 | phytype = chanstat & B43_RX_CHAN_PHYTYPE; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 686 | |
Michael Buesch | ce4fbdb | 2009-03-02 23:18:37 +0100 | [diff] [blame] | 687 | if (unlikely(macstat & B43_RX_MAC_FCSERR)) { |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 688 | dev->wl->ieee_stats.dot11FCSErrorCount++; |
Michael Buesch | ce4fbdb | 2009-03-02 23:18:37 +0100 | [diff] [blame] | 689 | status.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 690 | } |
| 691 | if (unlikely(phystat0 & (B43_RX_PHYST0_PLCPHCF | B43_RX_PHYST0_PLCPFV))) |
| 692 | status.flag |= RX_FLAG_FAILED_PLCP_CRC; |
| 693 | if (phystat0 & B43_RX_PHYST0_SHORTPRMBL) |
| 694 | status.flag |= RX_FLAG_SHORTPRE; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 695 | if (macstat & B43_RX_MAC_DECERR) { |
| 696 | /* Decryption with the given key failed. |
| 697 | * Drop the packet. We also won't be able to decrypt it with |
| 698 | * the key in software. */ |
| 699 | goto drop; |
| 700 | } |
| 701 | |
| 702 | /* Skip PLCP and padding */ |
| 703 | padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0; |
| 704 | if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) { |
| 705 | b43dbg(dev->wl, "RX: Packet size underrun (1)\n"); |
| 706 | goto drop; |
| 707 | } |
| 708 | plcp = (struct b43_plcp_hdr6 *)(skb->data + padding); |
| 709 | skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding); |
| 710 | /* The skb contains the Wireless Header + payload data now */ |
| 711 | if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) { |
| 712 | b43dbg(dev->wl, "RX: Packet size underrun (2)\n"); |
| 713 | goto drop; |
| 714 | } |
| 715 | wlhdr = (struct ieee80211_hdr *)(skb->data); |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 716 | fctl = wlhdr->frame_control; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 717 | |
| 718 | if (macstat & B43_RX_MAC_DEC) { |
| 719 | unsigned int keyidx; |
| 720 | int wlhdr_len; |
| 721 | |
| 722 | keyidx = ((macstat & B43_RX_MAC_KEYIDX) |
| 723 | >> B43_RX_MAC_KEYIDX_SHIFT); |
| 724 | /* We must adjust the key index here. We want the "physical" |
| 725 | * key index, but the ucode passed it slightly different. |
| 726 | */ |
| 727 | keyidx = b43_kidx_to_raw(dev, keyidx); |
Michael Buesch | 66d2d08 | 2009-08-06 10:36:50 +0200 | [diff] [blame] | 728 | B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key)); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 729 | |
| 730 | if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) { |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 731 | wlhdr_len = ieee80211_hdrlen(fctl); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 732 | if (unlikely(skb->len < (wlhdr_len + 3))) { |
| 733 | b43dbg(dev->wl, |
| 734 | "RX: Packet size underrun (3)\n"); |
| 735 | goto drop; |
| 736 | } |
| 737 | status.flag |= RX_FLAG_DECRYPTED; |
| 738 | } |
| 739 | } |
| 740 | |
Michael Buesch | 7b58416 | 2008-04-03 18:01:12 +0200 | [diff] [blame] | 741 | /* Link quality statistics */ |
Rafał Miłecki | 207ae4a | 2011-10-12 23:18:15 +0200 | [diff] [blame] | 742 | switch (chanstat & B43_RX_CHAN_PHYTYPE) { |
Rafał Miłecki | 73d51f3 | 2011-10-17 17:15:44 +0200 | [diff] [blame] | 743 | case B43_PHYTYPE_HT: |
| 744 | /* TODO: is max the right choice? */ |
| 745 | status.signal = max_t(__s8, |
| 746 | max(rxhdr->phy_ht_power0, rxhdr->phy_ht_power1), |
| 747 | rxhdr->phy_ht_power2); |
| 748 | break; |
Rafał Miłecki | 207ae4a | 2011-10-12 23:18:15 +0200 | [diff] [blame] | 749 | case B43_PHYTYPE_N: |
Rafał Miłecki | 73d51f3 | 2011-10-17 17:15:44 +0200 | [diff] [blame] | 750 | /* Broadcom has code for min and avg, but always uses max */ |
Rafał Miłecki | 207ae4a | 2011-10-12 23:18:15 +0200 | [diff] [blame] | 751 | if (rxhdr->power0 == 16 || rxhdr->power0 == 32) |
| 752 | status.signal = max(rxhdr->power1, rxhdr->power2); |
| 753 | else |
| 754 | status.signal = max(rxhdr->power0, rxhdr->power1); |
| 755 | break; |
| 756 | case B43_PHYTYPE_A: |
| 757 | case B43_PHYTYPE_B: |
| 758 | case B43_PHYTYPE_G: |
| 759 | case B43_PHYTYPE_LP: |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 760 | status.signal = b43_rssi_postprocess(dev, rxhdr->jssi, |
Michael Buesch | 7b58416 | 2008-04-03 18:01:12 +0200 | [diff] [blame] | 761 | (phystat0 & B43_RX_PHYST0_OFDM), |
| 762 | (phystat0 & B43_RX_PHYST0_GAINCTL), |
| 763 | (phystat3 & B43_RX_PHYST3_TRSTATE)); |
Rafał Miłecki | 207ae4a | 2011-10-12 23:18:15 +0200 | [diff] [blame] | 764 | break; |
Michael Buesch | 7b58416 | 2008-04-03 18:01:12 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 767 | if (phystat0 & B43_RX_PHYST0_OFDM) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 768 | status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp, |
| 769 | phytype == B43_PHYTYPE_A); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 770 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 771 | status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp); |
Michael Buesch | ce4fbdb | 2009-03-02 23:18:37 +0100 | [diff] [blame] | 772 | if (unlikely(status.rate_idx == -1)) { |
| 773 | /* PLCP seems to be corrupted. |
| 774 | * Drop the frame, if we are not interested in corrupted frames. */ |
| 775 | if (!(dev->wl->filter_flags & FIF_PLCPFAIL)) |
| 776 | goto drop; |
| 777 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 778 | status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT); |
John W. Linville | c0ddd04 | 2008-01-21 13:41:18 -0500 | [diff] [blame] | 779 | |
| 780 | /* |
Johannes Berg | d007b7f | 2008-02-18 18:53:55 +0100 | [diff] [blame] | 781 | * All frames on monitor interfaces and beacons always need a full |
| 782 | * 64-bit timestamp. Monitor interfaces need it for diagnostic |
| 783 | * purposes and beacons for IBSS merging. |
| 784 | * This code assumes we get to process the packet within 16 bits |
| 785 | * of timestamp, i.e. about 65 milliseconds after the PHY received |
| 786 | * the first symbol. |
John W. Linville | c0ddd04 | 2008-01-21 13:41:18 -0500 | [diff] [blame] | 787 | */ |
Harvey Harrison | f37d923 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 788 | if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) { |
John W. Linville | c0ddd04 | 2008-01-21 13:41:18 -0500 | [diff] [blame] | 789 | u16 low_mactime_now; |
| 790 | |
| 791 | b43_tsf_read(dev, &status.mactime); |
| 792 | low_mactime_now = status.mactime; |
| 793 | status.mactime = status.mactime & ~0xFFFFULL; |
| 794 | status.mactime += mactime; |
| 795 | if (low_mactime_now <= mactime) |
| 796 | status.mactime -= 0x10000; |
Johannes Berg | 6ebacbb | 2011-02-23 15:06:08 +0100 | [diff] [blame] | 797 | status.flag |= RX_FLAG_MACTIME_MPDU; |
John W. Linville | c0ddd04 | 2008-01-21 13:41:18 -0500 | [diff] [blame] | 798 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 799 | |
| 800 | chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT; |
| 801 | switch (chanstat & B43_RX_CHAN_PHYTYPE) { |
| 802 | case B43_PHYTYPE_A: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 803 | status.band = IEEE80211_BAND_5GHZ; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 804 | B43_WARN_ON(1); |
| 805 | /* FIXME: We don't really know which value the "chanid" contains. |
| 806 | * So the following assignment might be wrong. */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 807 | status.freq = b43_channel_to_freq_5ghz(chanid); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 808 | break; |
| 809 | case B43_PHYTYPE_G: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 810 | status.band = IEEE80211_BAND_2GHZ; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 811 | /* chanid is the radio channel cookie value as used |
| 812 | * to tune the radio. */ |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 813 | status.freq = chanid + 2400; |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 814 | break; |
| 815 | case B43_PHYTYPE_N: |
Gábor Stefanik | 826ee70 | 2009-08-15 00:52:02 +0200 | [diff] [blame] | 816 | case B43_PHYTYPE_LP: |
Rafał Miłecki | 6a461c2 | 2011-08-12 00:03:25 +0200 | [diff] [blame] | 817 | case B43_PHYTYPE_HT: |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 818 | /* chanid is the SHM channel cookie. Which is the plain |
| 819 | * channel number in b43. */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 820 | if (chanstat & B43_RX_CHAN_5GHZ) { |
| 821 | status.band = IEEE80211_BAND_5GHZ; |
| 822 | status.freq = b43_freq_to_channel_5ghz(chanid); |
| 823 | } else { |
| 824 | status.band = IEEE80211_BAND_2GHZ; |
| 825 | status.freq = b43_freq_to_channel_2ghz(chanid); |
| 826 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 827 | break; |
| 828 | default: |
| 829 | B43_WARN_ON(1); |
Michael Buesch | d987160 | 2008-01-02 18:55:53 +0100 | [diff] [blame] | 830 | goto drop; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 831 | } |
| 832 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 833 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
John W. Linville | 72f5f45 | 2009-10-16 14:35:51 -0400 | [diff] [blame] | 834 | ieee80211_rx_ni(dev->wl->hw, skb); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 835 | |
Michael Buesch | 990b86f | 2009-09-12 00:48:03 +0200 | [diff] [blame] | 836 | #if B43_DEBUG |
| 837 | dev->rx_count++; |
| 838 | #endif |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 839 | return; |
| 840 | drop: |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 841 | dev_kfree_skb_any(skb); |
| 842 | } |
| 843 | |
| 844 | void b43_handle_txstatus(struct b43_wldev *dev, |
| 845 | const struct b43_txstatus *status) |
| 846 | { |
| 847 | b43_debugfs_log_txstat(dev, status); |
| 848 | |
| 849 | if (status->intermediate) |
| 850 | return; |
| 851 | if (status->for_ampdu) |
| 852 | return; |
| 853 | if (!status->acked) |
| 854 | dev->wl->ieee_stats.dot11ACKFailureCount++; |
| 855 | if (status->rts_count) { |
| 856 | if (status->rts_count == 0xF) //FIXME |
| 857 | dev->wl->ieee_stats.dot11RTSFailureCount++; |
| 858 | else |
| 859 | dev->wl->ieee_stats.dot11RTSSuccessCount++; |
| 860 | } |
| 861 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 862 | if (b43_using_pio_transfers(dev)) |
| 863 | b43_pio_handle_txstatus(dev, status); |
| 864 | else |
| 865 | b43_dma_handle_txstatus(dev, status); |
Michael Buesch | 18c8ade | 2008-08-28 19:33:40 +0200 | [diff] [blame] | 866 | |
| 867 | b43_phy_txpower_check(dev, 0); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 870 | /* Fill out the mac80211 TXstatus report based on the b43-specific |
| 871 | * txstatus report data. This returns a boolean whether the frame was |
| 872 | * successfully transmitted. */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 873 | bool b43_fill_txstatus_report(struct b43_wldev *dev, |
| 874 | struct ieee80211_tx_info *report, |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 875 | const struct b43_txstatus *status) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 876 | { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 877 | bool frame_success = true; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 878 | int retry_limit; |
| 879 | |
| 880 | /* preserve the confiured retry limit before clearing the status |
| 881 | * The xmit function has overwritten the rc's value with the actual |
| 882 | * retry limit done by the hardware */ |
| 883 | retry_limit = report->status.rates[0].count; |
| 884 | ieee80211_tx_info_clear_status(report); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 885 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 886 | if (status->acked) { |
| 887 | /* The frame was ACKed. */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 888 | report->flags |= IEEE80211_TX_STAT_ACK; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 889 | } else { |
| 890 | /* The frame was not ACKed... */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 891 | if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 892 | /* ...but we expected an ACK. */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 893 | frame_success = false; |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | if (status->frame_count == 0) { |
| 897 | /* The frame was not transmitted at all. */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 898 | report->status.rates[0].count = 0; |
| 899 | } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) { |
| 900 | /* |
| 901 | * If the short retries (RTS, not data frame) have exceeded |
| 902 | * the limit, the hw will not have tried the selected rate, |
| 903 | * but will have used the fallback rate instead. |
| 904 | * Don't let the rate control count attempts for the selected |
| 905 | * rate in this case, otherwise the statistics will be off. |
| 906 | */ |
| 907 | report->status.rates[0].count = 0; |
| 908 | report->status.rates[1].count = status->frame_count; |
| 909 | } else { |
| 910 | if (status->frame_count > retry_limit) { |
| 911 | report->status.rates[0].count = retry_limit; |
| 912 | report->status.rates[1].count = status->frame_count - |
| 913 | retry_limit; |
| 914 | |
| 915 | } else { |
| 916 | report->status.rates[0].count = status->frame_count; |
| 917 | report->status.rates[1].idx = -1; |
| 918 | } |
| 919 | } |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 920 | |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 921 | return frame_success; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /* Stop any TX operation on the device (suspend the hardware queues) */ |
| 925 | void b43_tx_suspend(struct b43_wldev *dev) |
| 926 | { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 927 | if (b43_using_pio_transfers(dev)) |
| 928 | b43_pio_tx_suspend(dev); |
| 929 | else |
| 930 | b43_dma_tx_suspend(dev); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* Resume any TX operation on the device (resume the hardware queues) */ |
| 934 | void b43_tx_resume(struct b43_wldev *dev) |
| 935 | { |
Michael Buesch | 5100d5a | 2008-03-29 21:01:16 +0100 | [diff] [blame] | 936 | if (b43_using_pio_transfers(dev)) |
| 937 | b43_pio_tx_resume(dev); |
| 938 | else |
| 939 | b43_dma_tx_resume(dev); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 940 | } |