Daniel Drake | 66bb42f | 2007-11-19 16:20:12 +0000 | [diff] [blame] | 1 | /* ZD1211 USB-WLAN driver for Linux |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 2 | * |
Daniel Drake | 66bb42f | 2007-11-19 16:20:12 +0000 | [diff] [blame] | 3 | * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de> |
| 4 | * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org> |
| 5 | * Copyright (C) 2006-2007 Michael Wu <flamingice@sourmilk.net> |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 6 | * Copyright (C) 2007-2008 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu> |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 7 | * |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 26 | #include <linux/usb.h> |
| 27 | #include <linux/jiffies.h> |
| 28 | #include <net/ieee80211_radiotap.h> |
| 29 | |
| 30 | #include "zd_def.h" |
| 31 | #include "zd_chip.h" |
| 32 | #include "zd_mac.h" |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 33 | #include "zd_rf.h" |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 34 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 35 | struct zd_reg_alpha2_map { |
| 36 | u32 reg; |
| 37 | char alpha2[2]; |
| 38 | }; |
| 39 | |
| 40 | static struct zd_reg_alpha2_map reg_alpha2_map[] = { |
| 41 | { ZD_REGDOMAIN_FCC, "US" }, |
| 42 | { ZD_REGDOMAIN_IC, "CA" }, |
| 43 | { ZD_REGDOMAIN_ETSI, "DE" }, /* Generic ETSI, use most restrictive */ |
| 44 | { ZD_REGDOMAIN_JAPAN, "JP" }, |
John W. Linville | 3d3b33b | 2010-06-16 14:41:36 -0400 | [diff] [blame] | 45 | { ZD_REGDOMAIN_JAPAN_2, "JP" }, |
| 46 | { ZD_REGDOMAIN_JAPAN_3, "JP" }, |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 47 | { ZD_REGDOMAIN_SPAIN, "ES" }, |
| 48 | { ZD_REGDOMAIN_FRANCE, "FR" }, |
| 49 | }; |
| 50 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 51 | /* This table contains the hardware specific values for the modulation rates. */ |
| 52 | static const struct ieee80211_rate zd_rates[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 53 | { .bitrate = 10, |
| 54 | .hw_value = ZD_CCK_RATE_1M, }, |
| 55 | { .bitrate = 20, |
| 56 | .hw_value = ZD_CCK_RATE_2M, |
| 57 | .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT, |
| 58 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 59 | { .bitrate = 55, |
| 60 | .hw_value = ZD_CCK_RATE_5_5M, |
| 61 | .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT, |
| 62 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 63 | { .bitrate = 110, |
| 64 | .hw_value = ZD_CCK_RATE_11M, |
| 65 | .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT, |
| 66 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 67 | { .bitrate = 60, |
| 68 | .hw_value = ZD_OFDM_RATE_6M, |
| 69 | .flags = 0 }, |
| 70 | { .bitrate = 90, |
| 71 | .hw_value = ZD_OFDM_RATE_9M, |
| 72 | .flags = 0 }, |
| 73 | { .bitrate = 120, |
| 74 | .hw_value = ZD_OFDM_RATE_12M, |
| 75 | .flags = 0 }, |
| 76 | { .bitrate = 180, |
| 77 | .hw_value = ZD_OFDM_RATE_18M, |
| 78 | .flags = 0 }, |
| 79 | { .bitrate = 240, |
| 80 | .hw_value = ZD_OFDM_RATE_24M, |
| 81 | .flags = 0 }, |
| 82 | { .bitrate = 360, |
| 83 | .hw_value = ZD_OFDM_RATE_36M, |
| 84 | .flags = 0 }, |
| 85 | { .bitrate = 480, |
| 86 | .hw_value = ZD_OFDM_RATE_48M, |
| 87 | .flags = 0 }, |
| 88 | { .bitrate = 540, |
| 89 | .hw_value = ZD_OFDM_RATE_54M, |
| 90 | .flags = 0 }, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 93 | /* |
| 94 | * Zydas retry rates table. Each line is listed in the same order as |
| 95 | * in zd_rates[] and contains all the rate used when a packet is sent |
| 96 | * starting with a given rates. Let's consider an example : |
| 97 | * |
| 98 | * "11 Mbits : 4, 3, 2, 1, 0" means : |
| 99 | * - packet is sent using 4 different rates |
| 100 | * - 1st rate is index 3 (ie 11 Mbits) |
| 101 | * - 2nd rate is index 2 (ie 5.5 Mbits) |
| 102 | * - 3rd rate is index 1 (ie 2 Mbits) |
| 103 | * - 4th rate is index 0 (ie 1 Mbits) |
| 104 | */ |
| 105 | |
| 106 | static const struct tx_retry_rate zd_retry_rates[] = { |
| 107 | { /* 1 Mbits */ 1, { 0 }}, |
| 108 | { /* 2 Mbits */ 2, { 1, 0 }}, |
| 109 | { /* 5.5 Mbits */ 3, { 2, 1, 0 }}, |
| 110 | { /* 11 Mbits */ 4, { 3, 2, 1, 0 }}, |
| 111 | { /* 6 Mbits */ 5, { 4, 3, 2, 1, 0 }}, |
| 112 | { /* 9 Mbits */ 6, { 5, 4, 3, 2, 1, 0}}, |
| 113 | { /* 12 Mbits */ 5, { 6, 3, 2, 1, 0 }}, |
| 114 | { /* 18 Mbits */ 6, { 7, 6, 3, 2, 1, 0 }}, |
| 115 | { /* 24 Mbits */ 6, { 8, 6, 3, 2, 1, 0 }}, |
| 116 | { /* 36 Mbits */ 7, { 9, 8, 6, 3, 2, 1, 0 }}, |
| 117 | { /* 48 Mbits */ 8, {10, 9, 8, 6, 3, 2, 1, 0 }}, |
| 118 | { /* 54 Mbits */ 9, {11, 10, 9, 8, 6, 3, 2, 1, 0 }} |
| 119 | }; |
| 120 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 121 | static const struct ieee80211_channel zd_channels[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 122 | { .center_freq = 2412, .hw_value = 1 }, |
| 123 | { .center_freq = 2417, .hw_value = 2 }, |
| 124 | { .center_freq = 2422, .hw_value = 3 }, |
| 125 | { .center_freq = 2427, .hw_value = 4 }, |
| 126 | { .center_freq = 2432, .hw_value = 5 }, |
| 127 | { .center_freq = 2437, .hw_value = 6 }, |
| 128 | { .center_freq = 2442, .hw_value = 7 }, |
| 129 | { .center_freq = 2447, .hw_value = 8 }, |
| 130 | { .center_freq = 2452, .hw_value = 9 }, |
| 131 | { .center_freq = 2457, .hw_value = 10 }, |
| 132 | { .center_freq = 2462, .hw_value = 11 }, |
| 133 | { .center_freq = 2467, .hw_value = 12 }, |
| 134 | { .center_freq = 2472, .hw_value = 13 }, |
| 135 | { .center_freq = 2484, .hw_value = 14 }, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 136 | }; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 137 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 138 | static void housekeeping_init(struct zd_mac *mac); |
| 139 | static void housekeeping_enable(struct zd_mac *mac); |
| 140 | static void housekeeping_disable(struct zd_mac *mac); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 141 | static void beacon_init(struct zd_mac *mac); |
| 142 | static void beacon_enable(struct zd_mac *mac); |
| 143 | static void beacon_disable(struct zd_mac *mac); |
Jussi Kivilinna | 212e1a5 | 2011-01-31 20:49:43 +0200 | [diff] [blame] | 144 | static void set_rts_cts(struct zd_mac *mac, unsigned int short_preamble); |
| 145 | static int zd_mac_config_beacon(struct ieee80211_hw *hw, |
| 146 | struct sk_buff *beacon); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 147 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 148 | static int zd_reg2alpha2(u8 regdomain, char *alpha2) |
| 149 | { |
| 150 | unsigned int i; |
| 151 | struct zd_reg_alpha2_map *reg_map; |
| 152 | for (i = 0; i < ARRAY_SIZE(reg_alpha2_map); i++) { |
| 153 | reg_map = ®_alpha2_map[i]; |
| 154 | if (regdomain == reg_map->reg) { |
| 155 | alpha2[0] = reg_map->alpha2[0]; |
| 156 | alpha2[1] = reg_map->alpha2[1]; |
| 157 | return 0; |
| 158 | } |
| 159 | } |
| 160 | return 1; |
| 161 | } |
| 162 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 163 | int zd_mac_preinit_hw(struct ieee80211_hw *hw) |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 164 | { |
| 165 | int r; |
| 166 | u8 addr[ETH_ALEN]; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 167 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 168 | |
| 169 | r = zd_chip_read_mac_addr_fw(&mac->chip, addr); |
| 170 | if (r) |
| 171 | return r; |
| 172 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 173 | SET_IEEE80211_PERM_ADDR(hw, addr); |
| 174 | |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 178 | int zd_mac_init_hw(struct ieee80211_hw *hw) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 179 | { |
| 180 | int r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 181 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 182 | struct zd_chip *chip = &mac->chip; |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 183 | char alpha2[2]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 184 | u8 default_regdomain; |
| 185 | |
| 186 | r = zd_chip_enable_int(chip); |
| 187 | if (r) |
| 188 | goto out; |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 189 | r = zd_chip_init_hw(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 190 | if (r) |
| 191 | goto disable_int; |
| 192 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 193 | ZD_ASSERT(!irqs_disabled()); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 194 | |
| 195 | r = zd_read_regdomain(chip, &default_regdomain); |
| 196 | if (r) |
| 197 | goto disable_int; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 198 | spin_lock_irq(&mac->lock); |
| 199 | mac->regdomain = mac->default_regdomain = default_regdomain; |
| 200 | spin_unlock_irq(&mac->lock); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 201 | |
Daniel Drake | 40da08b | 2006-08-01 23:43:32 +0200 | [diff] [blame] | 202 | /* We must inform the device that we are doing encryption/decryption in |
| 203 | * software at the moment. */ |
| 204 | r = zd_set_encryption_type(chip, ENC_SNIFFER); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 205 | if (r) |
| 206 | goto disable_int; |
| 207 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 208 | r = zd_reg2alpha2(mac->regdomain, alpha2); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 209 | if (r) |
| 210 | goto disable_int; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 211 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 212 | r = regulatory_hint(hw->wiphy, alpha2); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 213 | disable_int: |
| 214 | zd_chip_disable_int(chip); |
| 215 | out: |
| 216 | return r; |
| 217 | } |
| 218 | |
| 219 | void zd_mac_clear(struct zd_mac *mac) |
| 220 | { |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 221 | flush_workqueue(zd_workqueue); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 222 | zd_chip_clear(&mac->chip); |
Ulrich Kunitz | c48cf12 | 2006-08-12 18:00:17 +0100 | [diff] [blame] | 223 | ZD_ASSERT(!spin_is_locked(&mac->lock)); |
| 224 | ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 227 | static int set_rx_filter(struct zd_mac *mac) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 228 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 229 | unsigned long flags; |
| 230 | u32 filter = STA_RX_FILTER; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 231 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 232 | spin_lock_irqsave(&mac->lock, flags); |
| 233 | if (mac->pass_ctrl) |
| 234 | filter |= RX_FILTER_CTRL; |
| 235 | spin_unlock_irqrestore(&mac->lock, flags); |
| 236 | |
| 237 | return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter); |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Jussi Kivilinna | c2fadcb | 2011-01-31 20:48:06 +0200 | [diff] [blame] | 240 | static int set_mac_and_bssid(struct zd_mac *mac) |
| 241 | { |
| 242 | int r; |
| 243 | |
| 244 | if (!mac->vif) |
| 245 | return -1; |
| 246 | |
| 247 | r = zd_write_mac_addr(&mac->chip, mac->vif->addr); |
| 248 | if (r) |
| 249 | return r; |
| 250 | |
| 251 | /* Vendor driver after setting MAC either sets BSSID for AP or |
| 252 | * filter for other modes. |
| 253 | */ |
| 254 | if (mac->type != NL80211_IFTYPE_AP) |
| 255 | return set_rx_filter(mac); |
| 256 | else |
| 257 | return zd_write_bssid(&mac->chip, mac->vif->addr); |
| 258 | } |
| 259 | |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 260 | static int set_mc_hash(struct zd_mac *mac) |
| 261 | { |
| 262 | struct zd_mc_hash hash; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 263 | zd_mc_clear(&hash); |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 264 | return zd_chip_set_multicast_hash(&mac->chip, &hash); |
| 265 | } |
| 266 | |
Jussi Kivilinna | a0fd751 | 2011-01-31 20:49:52 +0200 | [diff] [blame] | 267 | int zd_op_start(struct ieee80211_hw *hw) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 268 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 269 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 270 | struct zd_chip *chip = &mac->chip; |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 271 | struct zd_usb *usb = &chip->usb; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 272 | int r; |
| 273 | |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 274 | if (!usb->initialized) { |
| 275 | r = zd_usb_init_hw(usb); |
| 276 | if (r) |
| 277 | goto out; |
| 278 | } |
| 279 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 280 | r = zd_chip_enable_int(chip); |
| 281 | if (r < 0) |
| 282 | goto out; |
| 283 | |
| 284 | r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G); |
| 285 | if (r < 0) |
| 286 | goto disable_int; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 287 | r = set_rx_filter(mac); |
| 288 | if (r) |
| 289 | goto disable_int; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 290 | r = set_mc_hash(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 291 | if (r) |
| 292 | goto disable_int; |
| 293 | r = zd_chip_switch_radio_on(chip); |
| 294 | if (r < 0) |
| 295 | goto disable_int; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 296 | r = zd_chip_enable_rxtx(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 297 | if (r < 0) |
| 298 | goto disable_radio; |
| 299 | r = zd_chip_enable_hwint(chip); |
| 300 | if (r < 0) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 301 | goto disable_rxtx; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 302 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 303 | housekeeping_enable(mac); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 304 | beacon_enable(mac); |
| 305 | set_bit(ZD_DEVICE_RUNNING, &mac->flags); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 306 | return 0; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 307 | disable_rxtx: |
| 308 | zd_chip_disable_rxtx(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 309 | disable_radio: |
| 310 | zd_chip_switch_radio_off(chip); |
| 311 | disable_int: |
| 312 | zd_chip_disable_int(chip); |
| 313 | out: |
| 314 | return r; |
| 315 | } |
| 316 | |
Jussi Kivilinna | a0fd751 | 2011-01-31 20:49:52 +0200 | [diff] [blame] | 317 | void zd_op_stop(struct ieee80211_hw *hw) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 318 | { |
| 319 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 320 | struct zd_chip *chip = &mac->chip; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 321 | struct sk_buff *skb; |
| 322 | struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 323 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 324 | clear_bit(ZD_DEVICE_RUNNING, &mac->flags); |
| 325 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 326 | /* The order here deliberately is a little different from the open() |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 327 | * method, since we need to make sure there is no opportunity for RX |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 328 | * frames to be processed by mac80211 after we have stopped it. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 329 | */ |
| 330 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 331 | zd_chip_disable_rxtx(chip); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 332 | beacon_disable(mac); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 333 | housekeeping_disable(mac); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 334 | flush_workqueue(zd_workqueue); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 335 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 336 | zd_chip_disable_hwint(chip); |
| 337 | zd_chip_switch_radio_off(chip); |
| 338 | zd_chip_disable_int(chip); |
| 339 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 340 | |
| 341 | while ((skb = skb_dequeue(ack_wait_queue))) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 342 | dev_kfree_skb_any(skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Jussi Kivilinna | 212e1a5 | 2011-01-31 20:49:43 +0200 | [diff] [blame] | 345 | int zd_restore_settings(struct zd_mac *mac) |
| 346 | { |
| 347 | struct sk_buff *beacon; |
| 348 | struct zd_mc_hash multicast_hash; |
| 349 | unsigned int short_preamble; |
| 350 | int r, beacon_interval, beacon_period; |
| 351 | u8 channel; |
| 352 | |
| 353 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 354 | |
| 355 | spin_lock_irq(&mac->lock); |
| 356 | multicast_hash = mac->multicast_hash; |
| 357 | short_preamble = mac->short_preamble; |
| 358 | beacon_interval = mac->beacon.interval; |
| 359 | beacon_period = mac->beacon.period; |
| 360 | channel = mac->channel; |
| 361 | spin_unlock_irq(&mac->lock); |
| 362 | |
| 363 | r = set_mac_and_bssid(mac); |
| 364 | if (r < 0) { |
| 365 | dev_dbg_f(zd_mac_dev(mac), "set_mac_and_bssid failed, %d\n", r); |
| 366 | return r; |
| 367 | } |
| 368 | |
| 369 | r = zd_chip_set_channel(&mac->chip, channel); |
| 370 | if (r < 0) { |
| 371 | dev_dbg_f(zd_mac_dev(mac), "zd_chip_set_channel failed, %d\n", |
| 372 | r); |
| 373 | return r; |
| 374 | } |
| 375 | |
| 376 | set_rts_cts(mac, short_preamble); |
| 377 | |
| 378 | r = zd_chip_set_multicast_hash(&mac->chip, &multicast_hash); |
| 379 | if (r < 0) { |
| 380 | dev_dbg_f(zd_mac_dev(mac), |
| 381 | "zd_chip_set_multicast_hash failed, %d\n", r); |
| 382 | return r; |
| 383 | } |
| 384 | |
| 385 | if (mac->type == NL80211_IFTYPE_MESH_POINT || |
| 386 | mac->type == NL80211_IFTYPE_ADHOC || |
| 387 | mac->type == NL80211_IFTYPE_AP) { |
| 388 | if (mac->vif != NULL) { |
| 389 | beacon = ieee80211_beacon_get(mac->hw, mac->vif); |
| 390 | if (beacon) { |
| 391 | zd_mac_config_beacon(mac->hw, beacon); |
| 392 | kfree_skb(beacon); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | zd_set_beacon_interval(&mac->chip, beacon_interval, |
| 397 | beacon_period, mac->type); |
| 398 | |
| 399 | spin_lock_irq(&mac->lock); |
| 400 | mac->beacon.last_update = jiffies; |
| 401 | spin_unlock_irq(&mac->lock); |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 407 | /** |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 408 | * zd_mac_tx_status - reports tx status of a packet if required |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 409 | * @hw - a &struct ieee80211_hw pointer |
| 410 | * @skb - a sk-buffer |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 411 | * @flags: extra flags to set in the TX status info |
| 412 | * @ackssi: ACK signal strength |
Coly Li | 73ac36e | 2009-01-07 18:09:16 -0800 | [diff] [blame] | 413 | * @success - True for successful transmission of the frame |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 414 | * |
| 415 | * This information calls ieee80211_tx_status_irqsafe() if required by the |
| 416 | * control information. It copies the control information into the status |
| 417 | * information. |
| 418 | * |
| 419 | * If no status information has been requested, the skb is freed. |
| 420 | */ |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 421 | static void zd_mac_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 422 | int ackssi, struct tx_status *tx_status) |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 423 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 424 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 425 | int i; |
| 426 | int success = 1, retry = 1; |
| 427 | int first_idx; |
| 428 | const struct tx_retry_rate *retries; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 429 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 430 | ieee80211_tx_info_clear_status(info); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 431 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 432 | if (tx_status) { |
| 433 | success = !tx_status->failure; |
| 434 | retry = tx_status->retry + success; |
| 435 | } |
| 436 | |
| 437 | if (success) { |
| 438 | /* success */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 439 | info->flags |= IEEE80211_TX_STAT_ACK; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 440 | } else { |
| 441 | /* failure */ |
| 442 | info->flags &= ~IEEE80211_TX_STAT_ACK; |
| 443 | } |
| 444 | |
| 445 | first_idx = info->status.rates[0].idx; |
| 446 | ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates)); |
| 447 | retries = &zd_retry_rates[first_idx]; |
Dan Carpenter | 86baf71 | 2010-02-27 09:12:34 +0300 | [diff] [blame] | 448 | ZD_ASSERT(1 <= retry && retry <= retries->count); |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 449 | |
| 450 | info->status.rates[0].idx = retries->rate[0]; |
| 451 | info->status.rates[0].count = 1; // (retry > 1 ? 2 : 1); |
| 452 | |
| 453 | for (i=1; i<IEEE80211_TX_MAX_RATES-1 && i<retry; i++) { |
| 454 | info->status.rates[i].idx = retries->rate[i]; |
| 455 | info->status.rates[i].count = 1; // ((i==retry-1) && success ? 1:2); |
| 456 | } |
| 457 | for (; i<IEEE80211_TX_MAX_RATES && i<retry; i++) { |
Dan Carpenter | 86baf71 | 2010-02-27 09:12:34 +0300 | [diff] [blame] | 458 | info->status.rates[i].idx = retries->rate[retry - 1]; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 459 | info->status.rates[i].count = 1; // (success ? 1:2); |
| 460 | } |
| 461 | if (i<IEEE80211_TX_MAX_RATES) |
| 462 | info->status.rates[i].idx = -1; /* terminate */ |
| 463 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 464 | info->status.ack_signal = ackssi; |
| 465 | ieee80211_tx_status_irqsafe(hw, skb); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 468 | /** |
| 469 | * zd_mac_tx_failed - callback for failed frames |
| 470 | * @dev: the mac80211 wireless device |
| 471 | * |
Adam Buchbinder | 303863f | 2009-12-11 16:35:37 -0500 | [diff] [blame] | 472 | * This function is called if a frame couldn't be successfully |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 473 | * transferred. The first frame from the tx queue, will be selected and |
| 474 | * reported as error to the upper layers. |
| 475 | */ |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 476 | void zd_mac_tx_failed(struct urb *urb) |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 477 | { |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 478 | struct ieee80211_hw * hw = zd_usb_to_hw(urb->context); |
| 479 | struct zd_mac *mac = zd_hw_mac(hw); |
| 480 | struct sk_buff_head *q = &mac->ack_wait_queue; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 481 | struct sk_buff *skb; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 482 | struct tx_status *tx_status = (struct tx_status *)urb->transfer_buffer; |
| 483 | unsigned long flags; |
| 484 | int success = !tx_status->failure; |
| 485 | int retry = tx_status->retry + success; |
| 486 | int found = 0; |
| 487 | int i, position = 0; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 488 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 489 | q = &mac->ack_wait_queue; |
| 490 | spin_lock_irqsave(&q->lock, flags); |
Johannes Berg | 5078ed5 | 2008-02-20 12:09:25 +0100 | [diff] [blame] | 491 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 492 | skb_queue_walk(q, skb) { |
| 493 | struct ieee80211_hdr *tx_hdr; |
| 494 | struct ieee80211_tx_info *info; |
| 495 | int first_idx, final_idx; |
| 496 | const struct tx_retry_rate *retries; |
| 497 | u8 final_rate; |
| 498 | |
| 499 | position ++; |
| 500 | |
| 501 | /* if the hardware reports a failure and we had a 802.11 ACK |
| 502 | * pending, then we skip the first skb when searching for a |
| 503 | * matching frame */ |
| 504 | if (tx_status->failure && mac->ack_pending && |
| 505 | skb_queue_is_first(q, skb)) { |
| 506 | continue; |
| 507 | } |
| 508 | |
| 509 | tx_hdr = (struct ieee80211_hdr *)skb->data; |
| 510 | |
| 511 | /* we skip all frames not matching the reported destination */ |
| 512 | if (unlikely(memcmp(tx_hdr->addr1, tx_status->mac, ETH_ALEN))) { |
| 513 | continue; |
| 514 | } |
| 515 | |
| 516 | /* we skip all frames not matching the reported final rate */ |
| 517 | |
| 518 | info = IEEE80211_SKB_CB(skb); |
| 519 | first_idx = info->status.rates[0].idx; |
| 520 | ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates)); |
| 521 | retries = &zd_retry_rates[first_idx]; |
Dan Carpenter | 86baf71 | 2010-02-27 09:12:34 +0300 | [diff] [blame] | 522 | if (retry <= 0 || retry > retries->count) |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 523 | continue; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 524 | |
Dan Carpenter | 86baf71 | 2010-02-27 09:12:34 +0300 | [diff] [blame] | 525 | final_idx = retries->rate[retry - 1]; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 526 | final_rate = zd_rates[final_idx].hw_value; |
| 527 | |
| 528 | if (final_rate != tx_status->rate) { |
| 529 | continue; |
| 530 | } |
| 531 | |
| 532 | found = 1; |
| 533 | break; |
| 534 | } |
| 535 | |
| 536 | if (found) { |
| 537 | for (i=1; i<=position; i++) { |
| 538 | skb = __skb_dequeue(q); |
| 539 | zd_mac_tx_status(hw, skb, |
| 540 | mac->ack_pending ? mac->ack_signal : 0, |
| 541 | i == position ? tx_status : NULL); |
| 542 | mac->ack_pending = 0; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | spin_unlock_irqrestore(&q->lock, flags); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 549 | /** |
| 550 | * zd_mac_tx_to_dev - callback for USB layer |
| 551 | * @skb: a &sk_buff pointer |
| 552 | * @error: error value, 0 if transmission successful |
| 553 | * |
| 554 | * Informs the MAC layer that the frame has successfully transferred to the |
| 555 | * device. If an ACK is required and the transfer to the device has been |
| 556 | * successful, the packets are put on the @ack_wait_queue with |
| 557 | * the control set removed. |
| 558 | */ |
| 559 | void zd_mac_tx_to_dev(struct sk_buff *skb, int error) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 560 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 561 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 562 | struct ieee80211_hw *hw = info->rate_driver_data[0]; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 563 | struct zd_mac *mac = zd_hw_mac(hw); |
| 564 | |
| 565 | ieee80211_tx_info_clear_status(info); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 566 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 567 | skb_pull(skb, sizeof(struct zd_ctrlset)); |
| 568 | if (unlikely(error || |
| 569 | (info->flags & IEEE80211_TX_CTL_NO_ACK))) { |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 570 | /* |
| 571 | * FIXME : do we need to fill in anything ? |
| 572 | */ |
| 573 | ieee80211_tx_status_irqsafe(hw, skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 574 | } else { |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 575 | struct sk_buff_head *q = &mac->ack_wait_queue; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 576 | |
| 577 | skb_queue_tail(q, skb); |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 578 | while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) { |
| 579 | zd_mac_tx_status(hw, skb_dequeue(q), |
| 580 | mac->ack_pending ? mac->ack_signal : 0, |
| 581 | NULL); |
| 582 | mac->ack_pending = 0; |
| 583 | } |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 584 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 587 | static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 588 | { |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 589 | /* ZD_PURE_RATE() must be used to remove the modulation type flag of |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 590 | * the zd-rate values. |
| 591 | */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 592 | static const u8 rate_divisor[] = { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 593 | [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1, |
| 594 | [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2, |
| 595 | /* Bits must be doubled. */ |
| 596 | [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11, |
| 597 | [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11, |
| 598 | [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6, |
| 599 | [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9, |
| 600 | [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12, |
| 601 | [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18, |
| 602 | [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24, |
| 603 | [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36, |
| 604 | [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48, |
| 605 | [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 606 | }; |
| 607 | |
| 608 | u32 bits = (u32)tx_length * 8; |
| 609 | u32 divisor; |
| 610 | |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 611 | divisor = rate_divisor[ZD_PURE_RATE(zd_rate)]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 612 | if (divisor == 0) |
| 613 | return -EINVAL; |
| 614 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 615 | switch (zd_rate) { |
| 616 | case ZD_CCK_RATE_5_5M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 617 | bits = (2*bits) + 10; /* round up to the next integer */ |
| 618 | break; |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 619 | case ZD_CCK_RATE_11M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 620 | if (service) { |
| 621 | u32 t = bits % 11; |
| 622 | *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 623 | if (0 < t && t <= 3) { |
| 624 | *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 625 | } |
| 626 | } |
| 627 | bits += 10; /* round up to the next integer */ |
| 628 | break; |
| 629 | } |
| 630 | |
| 631 | return bits/divisor; |
| 632 | } |
| 633 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 634 | static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs, |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 635 | struct ieee80211_hdr *header, |
| 636 | struct ieee80211_tx_info *info) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 637 | { |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 638 | /* |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 639 | * CONTROL TODO: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 640 | * - if backoff needed, enable bit 0 |
| 641 | * - if burst (backoff not needed) disable bit 0 |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 642 | */ |
| 643 | |
| 644 | cs->control = 0; |
| 645 | |
| 646 | /* First fragment */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 647 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 648 | cs->control |= ZD_CS_NEED_RANDOM_BACKOFF; |
| 649 | |
Gábor Stefanik | 13bdcd9 | 2009-05-14 17:34:59 +0000 | [diff] [blame] | 650 | /* No ACK expected (multicast, etc.) */ |
| 651 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 652 | cs->control |= ZD_CS_NO_ACK; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 653 | |
| 654 | /* PS-POLL */ |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 655 | if (ieee80211_is_pspoll(header->frame_control)) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 656 | cs->control |= ZD_CS_PS_POLL_FRAME; |
| 657 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 658 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 659 | cs->control |= ZD_CS_RTS; |
| 660 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 661 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 662 | cs->control |= ZD_CS_SELF_CTS; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 663 | |
| 664 | /* FIXME: Management frame? */ |
| 665 | } |
| 666 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 667 | static int zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon) |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 668 | { |
| 669 | struct zd_mac *mac = zd_hw_mac(hw); |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 670 | int r, ret, num_cmds, req_pos = 0; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 671 | u32 tmp, j = 0; |
| 672 | /* 4 more bytes for tail CRC */ |
| 673 | u32 full_len = beacon->len + 4; |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 674 | unsigned long end_jiffies, message_jiffies; |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 675 | struct zd_ioreq32 *ioreqs; |
| 676 | |
| 677 | /* Alloc memory for full beacon write at once. */ |
| 678 | num_cmds = 1 + zd_chip_is_zd1211b(&mac->chip) + full_len; |
| 679 | ioreqs = kmalloc(num_cmds * sizeof(struct zd_ioreq32), GFP_KERNEL); |
| 680 | if (!ioreqs) |
| 681 | return -ENOMEM; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 682 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 683 | mutex_lock(&mac->chip.mutex); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 684 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 685 | r = zd_iowrite32_locked(&mac->chip, 0, CR_BCN_FIFO_SEMAPHORE); |
| 686 | if (r < 0) |
| 687 | goto out; |
| 688 | r = zd_ioread32_locked(&mac->chip, &tmp, CR_BCN_FIFO_SEMAPHORE); |
| 689 | if (r < 0) |
| 690 | goto release_sema; |
| 691 | |
| 692 | end_jiffies = jiffies + HZ / 2; /*~500ms*/ |
| 693 | message_jiffies = jiffies + HZ / 10; /*~100ms*/ |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 694 | while (tmp & 0x2) { |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 695 | r = zd_ioread32_locked(&mac->chip, &tmp, CR_BCN_FIFO_SEMAPHORE); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 696 | if (r < 0) |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 697 | goto release_sema; |
| 698 | if (time_is_before_eq_jiffies(message_jiffies)) { |
| 699 | message_jiffies = jiffies + HZ / 10; |
| 700 | dev_err(zd_mac_dev(mac), |
| 701 | "CR_BCN_FIFO_SEMAPHORE not ready\n"); |
| 702 | if (time_is_before_eq_jiffies(end_jiffies)) { |
| 703 | dev_err(zd_mac_dev(mac), |
| 704 | "Giving up beacon config.\n"); |
| 705 | r = -ETIMEDOUT; |
Jussi Kivilinna | 3985a46 | 2011-01-31 20:50:02 +0200 | [diff] [blame] | 706 | goto reset_device; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 707 | } |
| 708 | } |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 709 | msleep(20); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 712 | ioreqs[req_pos].addr = CR_BCN_FIFO; |
| 713 | ioreqs[req_pos].value = full_len - 1; |
| 714 | req_pos++; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 715 | if (zd_chip_is_zd1211b(&mac->chip)) { |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 716 | ioreqs[req_pos].addr = CR_BCN_LENGTH; |
| 717 | ioreqs[req_pos].value = full_len - 1; |
| 718 | req_pos++; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 719 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 720 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 721 | for (j = 0 ; j < beacon->len; j++) { |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 722 | ioreqs[req_pos].addr = CR_BCN_FIFO; |
| 723 | ioreqs[req_pos].value = *((u8 *)(beacon->data + j)); |
| 724 | req_pos++; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 725 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 726 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 727 | for (j = 0; j < 4; j++) { |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 728 | ioreqs[req_pos].addr = CR_BCN_FIFO; |
| 729 | ioreqs[req_pos].value = 0x0; |
| 730 | req_pos++; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 731 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 732 | |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 733 | BUG_ON(req_pos != num_cmds); |
| 734 | |
| 735 | r = zd_iowrite32a_locked(&mac->chip, ioreqs, num_cmds); |
| 736 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 737 | release_sema: |
| 738 | /* |
| 739 | * Try very hard to release device beacon semaphore, as otherwise |
| 740 | * device/driver can be left in unusable state. |
| 741 | */ |
| 742 | end_jiffies = jiffies + HZ / 2; /*~500ms*/ |
| 743 | ret = zd_iowrite32_locked(&mac->chip, 1, CR_BCN_FIFO_SEMAPHORE); |
| 744 | while (ret < 0) { |
| 745 | if (time_is_before_eq_jiffies(end_jiffies)) { |
| 746 | ret = -ETIMEDOUT; |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | msleep(20); |
| 751 | ret = zd_iowrite32_locked(&mac->chip, 1, CR_BCN_FIFO_SEMAPHORE); |
| 752 | } |
| 753 | |
| 754 | if (ret < 0) |
| 755 | dev_err(zd_mac_dev(mac), "Could not release " |
| 756 | "CR_BCN_FIFO_SEMAPHORE!\n"); |
| 757 | if (r < 0 || ret < 0) { |
| 758 | if (r >= 0) |
| 759 | r = ret; |
| 760 | goto out; |
| 761 | } |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 762 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 763 | /* 802.11b/g 2.4G CCK 1Mb |
| 764 | * 802.11a, not yet implemented, uses different values (see GPL vendor |
| 765 | * driver) |
| 766 | */ |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 767 | r = zd_iowrite32_locked(&mac->chip, 0x00000400 | (full_len << 19), |
| 768 | CR_BCN_PLCP_CFG); |
| 769 | out: |
| 770 | mutex_unlock(&mac->chip.mutex); |
Jussi Kivilinna | 5127229 | 2011-01-31 20:49:05 +0200 | [diff] [blame] | 771 | kfree(ioreqs); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 772 | return r; |
Jussi Kivilinna | 3985a46 | 2011-01-31 20:50:02 +0200 | [diff] [blame] | 773 | |
| 774 | reset_device: |
| 775 | mutex_unlock(&mac->chip.mutex); |
| 776 | kfree(ioreqs); |
| 777 | |
| 778 | /* semaphore stuck, reset device to avoid fw freeze later */ |
| 779 | dev_warn(zd_mac_dev(mac), "CR_BCN_FIFO_SEMAPHORE stuck, " |
| 780 | "reseting device..."); |
| 781 | usb_queue_reset_device(mac->chip.usb.intf); |
| 782 | |
| 783 | return r; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 786 | static int fill_ctrlset(struct zd_mac *mac, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 787 | struct sk_buff *skb) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 788 | { |
| 789 | int r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 790 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 791 | unsigned int frag_len = skb->len + FCS_LEN; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 792 | unsigned int packet_length; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 793 | struct ieee80211_rate *txrate; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 794 | struct zd_ctrlset *cs = (struct zd_ctrlset *) |
| 795 | skb_push(skb, sizeof(struct zd_ctrlset)); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 796 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 797 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 798 | ZD_ASSERT(frag_len <= 0xffff); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 799 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 800 | txrate = ieee80211_get_tx_rate(mac->hw, info); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 801 | |
| 802 | cs->modulation = txrate->hw_value; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 803 | if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 804 | cs->modulation = txrate->hw_value_short; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 805 | |
| 806 | cs->tx_length = cpu_to_le16(frag_len); |
| 807 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 808 | cs_set_control(mac, cs, hdr, info); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 809 | |
| 810 | packet_length = frag_len + sizeof(struct zd_ctrlset) + 10; |
| 811 | ZD_ASSERT(packet_length <= 0xffff); |
| 812 | /* ZD1211B: Computing the length difference this way, gives us |
| 813 | * flexibility to compute the packet length. |
| 814 | */ |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 815 | cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ? |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 816 | packet_length - frag_len : packet_length); |
| 817 | |
| 818 | /* |
| 819 | * CURRENT LENGTH: |
| 820 | * - transmit frame length in microseconds |
| 821 | * - seems to be derived from frame length |
| 822 | * - see Cal_Us_Service() in zdinlinef.h |
| 823 | * - if macp->bTxBurstEnable is enabled, then multiply by 4 |
| 824 | * - bTxBurstEnable is never set in the vendor driver |
| 825 | * |
| 826 | * SERVICE: |
| 827 | * - "for PLCP configuration" |
| 828 | * - always 0 except in some situations at 802.11b 11M |
| 829 | * - see line 53 of zdinlinef.h |
| 830 | */ |
| 831 | cs->service = 0; |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 832 | r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation), |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 833 | le16_to_cpu(cs->tx_length)); |
| 834 | if (r < 0) |
| 835 | return r; |
| 836 | cs->current_length = cpu_to_le16(r); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 837 | cs->next_frame_length = 0; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 842 | /** |
| 843 | * zd_op_tx - transmits a network frame to the device |
Ulrich Kunitz | 741fec5 | 2006-11-22 00:05:53 +0000 | [diff] [blame] | 844 | * |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 845 | * @dev: mac80211 hardware device |
| 846 | * @skb: socket buffer |
| 847 | * @control: the control structure |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 848 | * |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 849 | * This function transmit an IEEE 802.11 network frame to the device. The |
| 850 | * control block of the skbuff will be initialized. If necessary the incoming |
| 851 | * mac80211 queues will be stopped. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 852 | */ |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 853 | static void zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 854 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 855 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 856 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 857 | int r; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 858 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 859 | r = fill_ctrlset(mac, skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 860 | if (r) |
Jouni Malinen | 640c65e | 2009-03-16 21:47:33 +0200 | [diff] [blame] | 861 | goto fail; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 862 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 863 | info->rate_driver_data[0] = hw; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 864 | |
| 865 | r = zd_usb_tx(&mac->chip.usb, skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 866 | if (r) |
Jouni Malinen | 640c65e | 2009-03-16 21:47:33 +0200 | [diff] [blame] | 867 | goto fail; |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 868 | return; |
Jouni Malinen | 640c65e | 2009-03-16 21:47:33 +0200 | [diff] [blame] | 869 | |
| 870 | fail: |
| 871 | dev_kfree_skb(skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
| 875 | * filter_ack - filters incoming packets for acknowledgements |
| 876 | * @dev: the mac80211 device |
| 877 | * @rx_hdr: received header |
| 878 | * @stats: the status for the received packet |
| 879 | * |
| 880 | * This functions looks for ACK packets and tries to match them with the |
| 881 | * frames in the tx queue. If a match is found the frame will be dequeued and |
| 882 | * the upper layers is informed about the successful transmission. If |
| 883 | * mac80211 queues have been stopped and the number of frames still to be |
| 884 | * transmitted is low the queues will be opened again. |
| 885 | * |
| 886 | * Returns 1 if the frame was an ACK, 0 if it was ignored. |
| 887 | */ |
| 888 | static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr, |
| 889 | struct ieee80211_rx_status *stats) |
| 890 | { |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 891 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 892 | struct sk_buff *skb; |
| 893 | struct sk_buff_head *q; |
| 894 | unsigned long flags; |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 895 | int found = 0; |
| 896 | int i, position = 0; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 897 | |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 898 | if (!ieee80211_is_ack(rx_hdr->frame_control)) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 899 | return 0; |
| 900 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 901 | q = &mac->ack_wait_queue; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 902 | spin_lock_irqsave(&q->lock, flags); |
David S. Miller | 47a227d | 2008-09-23 00:23:30 -0700 | [diff] [blame] | 903 | skb_queue_walk(q, skb) { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 904 | struct ieee80211_hdr *tx_hdr; |
| 905 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 906 | position ++; |
| 907 | |
| 908 | if (mac->ack_pending && skb_queue_is_first(q, skb)) |
| 909 | continue; |
| 910 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 911 | tx_hdr = (struct ieee80211_hdr *)skb->data; |
Shaddy Baddah | cde6901 | 2008-11-28 17:10:45 +1100 | [diff] [blame] | 912 | if (likely(!memcmp(tx_hdr->addr2, rx_hdr->addr1, ETH_ALEN))) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 913 | { |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 914 | found = 1; |
| 915 | break; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 918 | |
| 919 | if (found) { |
| 920 | for (i=1; i<position; i++) { |
| 921 | skb = __skb_dequeue(q); |
| 922 | zd_mac_tx_status(hw, skb, |
| 923 | mac->ack_pending ? mac->ack_signal : 0, |
| 924 | NULL); |
| 925 | mac->ack_pending = 0; |
| 926 | } |
| 927 | |
| 928 | mac->ack_pending = 1; |
| 929 | mac->ack_signal = stats->signal; |
Jussi Kivilinna | f773e40 | 2011-01-31 20:48:16 +0200 | [diff] [blame] | 930 | |
| 931 | /* Prevent pending tx-packet on AP-mode */ |
| 932 | if (mac->type == NL80211_IFTYPE_AP) { |
| 933 | skb = __skb_dequeue(q); |
| 934 | zd_mac_tx_status(hw, skb, mac->ack_signal, NULL); |
| 935 | mac->ack_pending = 0; |
| 936 | } |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 939 | spin_unlock_irqrestore(&q->lock, flags); |
| 940 | return 1; |
| 941 | } |
| 942 | |
| 943 | int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length) |
| 944 | { |
| 945 | struct zd_mac *mac = zd_hw_mac(hw); |
| 946 | struct ieee80211_rx_status stats; |
| 947 | const struct rx_status *status; |
| 948 | struct sk_buff *skb; |
| 949 | int bad_frame = 0; |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 950 | __le16 fc; |
| 951 | int need_padding; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 952 | int i; |
| 953 | u8 rate; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 954 | |
| 955 | if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ + |
| 956 | FCS_LEN + sizeof(struct rx_status)) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 957 | return -EINVAL; |
| 958 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 959 | memset(&stats, 0, sizeof(stats)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 960 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 961 | /* Note about pass_failed_fcs and pass_ctrl access below: |
| 962 | * mac locking intentionally omitted here, as this is the only unlocked |
| 963 | * reader and the only writer is configure_filter. Plus, if there were |
| 964 | * any races accessing these variables, it wouldn't really matter. |
| 965 | * If mac80211 ever provides a way for us to access filter flags |
| 966 | * from outside configure_filter, we could improve on this. Also, this |
| 967 | * situation may change once we implement some kind of DMA-into-skb |
| 968 | * RX path. */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 969 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 970 | /* Caller has to ensure that length >= sizeof(struct rx_status). */ |
| 971 | status = (struct rx_status *) |
Ulrich Kunitz | 937a049 | 2007-10-02 18:36:53 +0100 | [diff] [blame] | 972 | (buffer + (length - sizeof(struct rx_status))); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 973 | if (status->frame_status & ZD_RX_ERROR) { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 974 | if (mac->pass_failed_fcs && |
| 975 | (status->frame_status & ZD_RX_CRC32_ERROR)) { |
| 976 | stats.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 977 | bad_frame = 1; |
| 978 | } else { |
| 979 | return -EINVAL; |
Ulrich Kunitz | 22d3405 | 2007-01-29 01:00:03 +0000 | [diff] [blame] | 980 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 981 | } |
Ulrich Kunitz | 22d3405 | 2007-01-29 01:00:03 +0000 | [diff] [blame] | 982 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 983 | stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq; |
| 984 | stats.band = IEEE80211_BAND_2GHZ; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 985 | stats.signal = status->signal_strength; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 986 | |
| 987 | rate = zd_rx_rate(buffer, status); |
| 988 | |
| 989 | /* todo: return index in the big switches in zd_rx_rate instead */ |
| 990 | for (i = 0; i < mac->band.n_bitrates; i++) |
| 991 | if (rate == mac->band.bitrates[i].hw_value) |
| 992 | stats.rate_idx = i; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 993 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 994 | length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status); |
| 995 | buffer += ZD_PLCP_HEADER_SIZE; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 996 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 997 | /* Except for bad frames, filter each frame to see if it is an ACK, in |
| 998 | * which case our internal TX tracking is updated. Normally we then |
| 999 | * bail here as there's no need to pass ACKs on up to the stack, but |
| 1000 | * there is also the case where the stack has requested us to pass |
| 1001 | * control frames on up (pass_ctrl) which we must consider. */ |
| 1002 | if (!bad_frame && |
| 1003 | filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats) |
| 1004 | && !mac->pass_ctrl) |
| 1005 | return 0; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1006 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1007 | fc = get_unaligned((__le16*)buffer); |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 1008 | need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc); |
Michael Buesch | 9081728 | 2007-12-29 17:24:23 +0100 | [diff] [blame] | 1009 | |
| 1010 | skb = dev_alloc_skb(length + (need_padding ? 2 : 0)); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1011 | if (skb == NULL) |
Ulrich Kunitz | 4d1feab | 2006-12-10 11:13:12 -0800 | [diff] [blame] | 1012 | return -ENOMEM; |
Michael Buesch | 9081728 | 2007-12-29 17:24:23 +0100 | [diff] [blame] | 1013 | if (need_padding) { |
Walter Goldens | 77c2061 | 2010-05-18 04:44:54 -0700 | [diff] [blame] | 1014 | /* Make sure the payload data is 4 byte aligned. */ |
Michael Buesch | 9081728 | 2007-12-29 17:24:23 +0100 | [diff] [blame] | 1015 | skb_reserve(skb, 2); |
| 1016 | } |
| 1017 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 1018 | /* FIXME : could we avoid this big memcpy ? */ |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1019 | memcpy(skb_put(skb, length), buffer, length); |
| 1020 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1021 | memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats)); |
| 1022 | ieee80211_rx_irqsafe(hw, skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1026 | static int zd_op_add_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1027 | struct ieee80211_vif *vif) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1028 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1029 | struct zd_mac *mac = zd_hw_mac(hw); |
| 1030 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1031 | /* using NL80211_IFTYPE_UNSPECIFIED to indicate no mode selected */ |
| 1032 | if (mac->type != NL80211_IFTYPE_UNSPECIFIED) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1033 | return -EOPNOTSUPP; |
| 1034 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1035 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1036 | case NL80211_IFTYPE_MONITOR: |
| 1037 | case NL80211_IFTYPE_MESH_POINT: |
| 1038 | case NL80211_IFTYPE_STATION: |
| 1039 | case NL80211_IFTYPE_ADHOC: |
Jussi Kivilinna | ab419e9 | 2011-01-31 20:50:21 +0200 | [diff] [blame] | 1040 | case NL80211_IFTYPE_AP: |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1041 | mac->type = vif->type; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | default: |
| 1044 | return -EOPNOTSUPP; |
| 1045 | } |
| 1046 | |
Jussi Kivilinna | c2fadcb | 2011-01-31 20:48:06 +0200 | [diff] [blame] | 1047 | mac->vif = vif; |
| 1048 | |
| 1049 | return set_mac_and_bssid(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1052 | static void zd_op_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1053 | struct ieee80211_vif *vif) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1054 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1055 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1056 | mac->type = NL80211_IFTYPE_UNSPECIFIED; |
Jussi Kivilinna | c2fadcb | 2011-01-31 20:48:06 +0200 | [diff] [blame] | 1057 | mac->vif = NULL; |
Jussi Kivilinna | b91a515 | 2011-01-31 20:48:25 +0200 | [diff] [blame] | 1058 | zd_set_beacon_interval(&mac->chip, 0, 0, NL80211_IFTYPE_UNSPECIFIED); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1059 | zd_write_mac_addr(&mac->chip, NULL); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1062 | static int zd_op_config(struct ieee80211_hw *hw, u32 changed) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1063 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1064 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1065 | struct ieee80211_conf *conf = &hw->conf; |
| 1066 | |
Jussi Kivilinna | 212e1a5 | 2011-01-31 20:49:43 +0200 | [diff] [blame] | 1067 | spin_lock_irq(&mac->lock); |
| 1068 | mac->channel = conf->channel->hw_value; |
| 1069 | spin_unlock_irq(&mac->lock); |
| 1070 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1071 | return zd_chip_set_channel(&mac->chip, conf->channel->hw_value); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1074 | static void zd_beacon_done(struct zd_mac *mac) |
| 1075 | { |
| 1076 | struct sk_buff *skb, *beacon; |
| 1077 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1078 | if (!test_bit(ZD_DEVICE_RUNNING, &mac->flags)) |
| 1079 | return; |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1080 | if (!mac->vif || mac->vif->type != NL80211_IFTYPE_AP) |
| 1081 | return; |
| 1082 | |
| 1083 | /* |
| 1084 | * Send out buffered broad- and multicast frames. |
| 1085 | */ |
| 1086 | while (!ieee80211_queue_stopped(mac->hw, 0)) { |
| 1087 | skb = ieee80211_get_buffered_bc(mac->hw, mac->vif); |
| 1088 | if (!skb) |
| 1089 | break; |
| 1090 | zd_op_tx(mac->hw, skb); |
| 1091 | } |
| 1092 | |
| 1093 | /* |
| 1094 | * Fetch next beacon so that tim_count is updated. |
| 1095 | */ |
| 1096 | beacon = ieee80211_beacon_get(mac->hw, mac->vif); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1097 | if (beacon) { |
| 1098 | zd_mac_config_beacon(mac->hw, beacon); |
| 1099 | kfree_skb(beacon); |
| 1100 | } |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1101 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1102 | spin_lock_irq(&mac->lock); |
| 1103 | mac->beacon.last_update = jiffies; |
| 1104 | spin_unlock_irq(&mac->lock); |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 1107 | static void zd_process_intr(struct work_struct *work) |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1108 | { |
| 1109 | u16 int_status; |
Jussi Kivilinna | 8b17f75 | 2011-01-31 20:47:27 +0200 | [diff] [blame] | 1110 | unsigned long flags; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1111 | struct zd_mac *mac = container_of(work, struct zd_mac, process_intr); |
| 1112 | |
Jussi Kivilinna | 8b17f75 | 2011-01-31 20:47:27 +0200 | [diff] [blame] | 1113 | spin_lock_irqsave(&mac->lock, flags); |
| 1114 | int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer + 4)); |
| 1115 | spin_unlock_irqrestore(&mac->lock, flags); |
| 1116 | |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1117 | if (int_status & INT_CFG_NEXT_BCN) { |
| 1118 | /*dev_dbg_f_limit(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n");*/ |
| 1119 | zd_beacon_done(mac); |
| 1120 | } else { |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1121 | dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n"); |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1122 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1123 | |
| 1124 | zd_chip_enable_hwint(&mac->chip); |
| 1125 | } |
| 1126 | |
| 1127 | |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1128 | static u64 zd_op_prepare_multicast(struct ieee80211_hw *hw, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1129 | struct netdev_hw_addr_list *mc_list) |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1130 | { |
| 1131 | struct zd_mac *mac = zd_hw_mac(hw); |
| 1132 | struct zd_mc_hash hash; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1133 | struct netdev_hw_addr *ha; |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1134 | |
| 1135 | zd_mc_clear(&hash); |
| 1136 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1137 | netdev_hw_addr_list_for_each(ha, mc_list) { |
| 1138 | dev_dbg_f(zd_mac_dev(mac), "mc addr %pM\n", ha->addr); |
| 1139 | zd_mc_add_addr(&hash, ha->addr); |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | return hash.low | ((u64)hash.high << 32); |
| 1143 | } |
| 1144 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1145 | #define SUPPORTED_FIF_FLAGS \ |
| 1146 | (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \ |
Michael Buesch | 2c1a1b1 | 2008-02-10 16:03:55 +0100 | [diff] [blame] | 1147 | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1148 | static void zd_op_configure_filter(struct ieee80211_hw *hw, |
| 1149 | unsigned int changed_flags, |
| 1150 | unsigned int *new_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1151 | u64 multicast) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1152 | { |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1153 | struct zd_mc_hash hash = { |
| 1154 | .low = multicast, |
| 1155 | .high = multicast >> 32, |
| 1156 | }; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1157 | struct zd_mac *mac = zd_hw_mac(hw); |
| 1158 | unsigned long flags; |
Jussi Kivilinna | a6fb071 | 2011-01-31 20:47:46 +0200 | [diff] [blame] | 1159 | int r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1160 | |
| 1161 | /* Only deal with supported flags */ |
| 1162 | changed_flags &= SUPPORTED_FIF_FLAGS; |
| 1163 | *new_flags &= SUPPORTED_FIF_FLAGS; |
| 1164 | |
Benoit Papillault | 7de3c5d | 2010-01-03 10:20:01 +0100 | [diff] [blame] | 1165 | /* |
| 1166 | * If multicast parameter (as returned by zd_op_prepare_multicast) |
| 1167 | * has changed, no bit in changed_flags is set. To handle this |
| 1168 | * situation, we do not return if changed_flags is 0. If we do so, |
| 1169 | * we will have some issue with IPv6 which uses multicast for link |
| 1170 | * layer address resolution. |
| 1171 | */ |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1172 | if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1173 | zd_mc_add_all(&hash); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1174 | |
| 1175 | spin_lock_irqsave(&mac->lock, flags); |
| 1176 | mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL); |
| 1177 | mac->pass_ctrl = !!(*new_flags & FIF_CONTROL); |
| 1178 | mac->multicast_hash = hash; |
| 1179 | spin_unlock_irqrestore(&mac->lock, flags); |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1180 | |
Jussi Kivilinna | a6fb071 | 2011-01-31 20:47:46 +0200 | [diff] [blame] | 1181 | zd_chip_set_multicast_hash(&mac->chip, &hash); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1182 | |
Jussi Kivilinna | a6fb071 | 2011-01-31 20:47:46 +0200 | [diff] [blame] | 1183 | if (changed_flags & FIF_CONTROL) { |
| 1184 | r = set_rx_filter(mac); |
| 1185 | if (r) |
| 1186 | dev_err(zd_mac_dev(mac), "set_rx_filter error %d\n", r); |
| 1187 | } |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1188 | |
| 1189 | /* no handling required for FIF_OTHER_BSS as we don't currently |
| 1190 | * do BSSID filtering */ |
| 1191 | /* FIXME: in future it would be nice to enable the probe response |
| 1192 | * filter (so that the driver doesn't see them) until |
| 1193 | * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd |
| 1194 | * have to schedule work to enable prbresp reception, which might |
| 1195 | * happen too late. For now we'll just listen and forward them all the |
| 1196 | * time. */ |
| 1197 | } |
| 1198 | |
Jussi Kivilinna | 5cf6cf8 | 2011-01-31 20:47:56 +0200 | [diff] [blame] | 1199 | static void set_rts_cts(struct zd_mac *mac, unsigned int short_preamble) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1200 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1201 | mutex_lock(&mac->chip.mutex); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1202 | zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble); |
| 1203 | mutex_unlock(&mac->chip.mutex); |
| 1204 | } |
| 1205 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1206 | static void zd_op_bss_info_changed(struct ieee80211_hw *hw, |
| 1207 | struct ieee80211_vif *vif, |
| 1208 | struct ieee80211_bss_conf *bss_conf, |
| 1209 | u32 changes) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1210 | { |
| 1211 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1212 | int associated; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1213 | |
| 1214 | dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes); |
| 1215 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1216 | if (mac->type == NL80211_IFTYPE_MESH_POINT || |
Jussi Kivilinna | ab419e9 | 2011-01-31 20:50:21 +0200 | [diff] [blame] | 1217 | mac->type == NL80211_IFTYPE_ADHOC || |
| 1218 | mac->type == NL80211_IFTYPE_AP) { |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1219 | associated = true; |
| 1220 | if (changes & BSS_CHANGED_BEACON) { |
| 1221 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 1222 | |
| 1223 | if (beacon) { |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1224 | zd_chip_disable_hwint(&mac->chip); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1225 | zd_mac_config_beacon(hw, beacon); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1226 | zd_chip_enable_hwint(&mac->chip); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1227 | kfree_skb(beacon); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | if (changes & BSS_CHANGED_BEACON_ENABLED) { |
Jussi Kivilinna | b91a515 | 2011-01-31 20:48:25 +0200 | [diff] [blame] | 1232 | u16 interval = 0; |
| 1233 | u8 period = 0; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1234 | |
Jussi Kivilinna | b91a515 | 2011-01-31 20:48:25 +0200 | [diff] [blame] | 1235 | if (bss_conf->enable_beacon) { |
| 1236 | period = bss_conf->dtim_period; |
| 1237 | interval = bss_conf->beacon_int; |
| 1238 | } |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1239 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1240 | spin_lock_irq(&mac->lock); |
| 1241 | mac->beacon.period = period; |
| 1242 | mac->beacon.interval = interval; |
| 1243 | mac->beacon.last_update = jiffies; |
| 1244 | spin_unlock_irq(&mac->lock); |
| 1245 | |
Jussi Kivilinna | b91a515 | 2011-01-31 20:48:25 +0200 | [diff] [blame] | 1246 | zd_set_beacon_interval(&mac->chip, interval, period, |
| 1247 | mac->type); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1248 | } |
| 1249 | } else |
| 1250 | associated = is_valid_ether_addr(bss_conf->bssid); |
| 1251 | |
| 1252 | spin_lock_irq(&mac->lock); |
| 1253 | mac->associated = associated; |
| 1254 | spin_unlock_irq(&mac->lock); |
| 1255 | |
| 1256 | /* TODO: do hardware bssid filtering */ |
| 1257 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1258 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Jussi Kivilinna | 5cf6cf8 | 2011-01-31 20:47:56 +0200 | [diff] [blame] | 1259 | spin_lock_irq(&mac->lock); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1260 | mac->short_preamble = bss_conf->use_short_preamble; |
Jussi Kivilinna | 5cf6cf8 | 2011-01-31 20:47:56 +0200 | [diff] [blame] | 1261 | spin_unlock_irq(&mac->lock); |
| 1262 | |
| 1263 | set_rts_cts(mac, bss_conf->use_short_preamble); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Alina Friedrichsen | 5fe7319 | 2009-02-25 00:49:18 +0100 | [diff] [blame] | 1267 | static u64 zd_op_get_tsf(struct ieee80211_hw *hw) |
| 1268 | { |
| 1269 | struct zd_mac *mac = zd_hw_mac(hw); |
| 1270 | return zd_chip_get_tsf(&mac->chip); |
| 1271 | } |
| 1272 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1273 | static const struct ieee80211_ops zd_ops = { |
| 1274 | .tx = zd_op_tx, |
| 1275 | .start = zd_op_start, |
| 1276 | .stop = zd_op_stop, |
| 1277 | .add_interface = zd_op_add_interface, |
| 1278 | .remove_interface = zd_op_remove_interface, |
| 1279 | .config = zd_op_config, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1280 | .prepare_multicast = zd_op_prepare_multicast, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1281 | .configure_filter = zd_op_configure_filter, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1282 | .bss_info_changed = zd_op_bss_info_changed, |
Alina Friedrichsen | 5fe7319 | 2009-02-25 00:49:18 +0100 | [diff] [blame] | 1283 | .get_tsf = zd_op_get_tsf, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1284 | }; |
| 1285 | |
| 1286 | struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf) |
| 1287 | { |
| 1288 | struct zd_mac *mac; |
| 1289 | struct ieee80211_hw *hw; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1290 | |
| 1291 | hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops); |
| 1292 | if (!hw) { |
| 1293 | dev_dbg_f(&intf->dev, "out of memory\n"); |
| 1294 | return NULL; |
| 1295 | } |
| 1296 | |
| 1297 | mac = zd_hw_mac(hw); |
| 1298 | |
| 1299 | memset(mac, 0, sizeof(*mac)); |
| 1300 | spin_lock_init(&mac->lock); |
| 1301 | mac->hw = hw; |
| 1302 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1303 | mac->type = NL80211_IFTYPE_UNSPECIFIED; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1304 | |
| 1305 | memcpy(mac->channels, zd_channels, sizeof(zd_channels)); |
| 1306 | memcpy(mac->rates, zd_rates, sizeof(zd_rates)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1307 | mac->band.n_bitrates = ARRAY_SIZE(zd_rates); |
| 1308 | mac->band.bitrates = mac->rates; |
| 1309 | mac->band.n_channels = ARRAY_SIZE(zd_channels); |
| 1310 | mac->band.channels = mac->channels; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1311 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1312 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band; |
| 1313 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1314 | hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
Jussi Kivilinna | 4099e2f | 2011-01-31 20:48:35 +0200 | [diff] [blame] | 1315 | IEEE80211_HW_SIGNAL_UNSPEC | |
| 1316 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1317 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1318 | hw->wiphy->interface_modes = |
| 1319 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 1320 | BIT(NL80211_IFTYPE_STATION) | |
Jussi Kivilinna | ab419e9 | 2011-01-31 20:50:21 +0200 | [diff] [blame] | 1321 | BIT(NL80211_IFTYPE_ADHOC) | |
| 1322 | BIT(NL80211_IFTYPE_AP); |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1323 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1324 | hw->max_signal = 100; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1325 | hw->queues = 1; |
| 1326 | hw->extra_tx_headroom = sizeof(struct zd_ctrlset); |
| 1327 | |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 1328 | /* |
| 1329 | * Tell mac80211 that we support multi rate retries |
| 1330 | */ |
| 1331 | hw->max_rates = IEEE80211_TX_MAX_RATES; |
| 1332 | hw->max_rate_tries = 18; /* 9 rates * 2 retries/rate */ |
| 1333 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1334 | skb_queue_head_init(&mac->ack_wait_queue); |
Benoit PAPILLAULT | 7f4013f | 2009-10-22 12:04:52 +0200 | [diff] [blame] | 1335 | mac->ack_pending = 0; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1336 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1337 | zd_chip_init(&mac->chip, hw, intf); |
| 1338 | housekeeping_init(mac); |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1339 | beacon_init(mac); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 1340 | INIT_WORK(&mac->process_intr, zd_process_intr); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1341 | |
| 1342 | SET_IEEE80211_DEV(hw, &intf->dev); |
| 1343 | return hw; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
Jussi Kivilinna | 9be2325 | 2011-01-31 20:48:55 +0200 | [diff] [blame] | 1346 | #define BEACON_WATCHDOG_DELAY round_jiffies_relative(HZ) |
| 1347 | |
| 1348 | static void beacon_watchdog_handler(struct work_struct *work) |
| 1349 | { |
| 1350 | struct zd_mac *mac = |
| 1351 | container_of(work, struct zd_mac, beacon.watchdog_work.work); |
| 1352 | struct sk_buff *beacon; |
| 1353 | unsigned long timeout; |
| 1354 | int interval, period; |
| 1355 | |
| 1356 | if (!test_bit(ZD_DEVICE_RUNNING, &mac->flags)) |
| 1357 | goto rearm; |
| 1358 | if (mac->type != NL80211_IFTYPE_AP || !mac->vif) |
| 1359 | goto rearm; |
| 1360 | |
| 1361 | spin_lock_irq(&mac->lock); |
| 1362 | interval = mac->beacon.interval; |
| 1363 | period = mac->beacon.period; |
| 1364 | timeout = mac->beacon.last_update + msecs_to_jiffies(interval) + HZ; |
| 1365 | spin_unlock_irq(&mac->lock); |
| 1366 | |
| 1367 | if (interval > 0 && time_is_before_jiffies(timeout)) { |
| 1368 | dev_dbg_f(zd_mac_dev(mac), "beacon interrupt stalled, " |
| 1369 | "restarting. " |
| 1370 | "(interval: %d, dtim: %d)\n", |
| 1371 | interval, period); |
| 1372 | |
| 1373 | zd_chip_disable_hwint(&mac->chip); |
| 1374 | |
| 1375 | beacon = ieee80211_beacon_get(mac->hw, mac->vif); |
| 1376 | if (beacon) { |
| 1377 | zd_mac_config_beacon(mac->hw, beacon); |
| 1378 | kfree_skb(beacon); |
| 1379 | } |
| 1380 | |
| 1381 | zd_set_beacon_interval(&mac->chip, interval, period, mac->type); |
| 1382 | |
| 1383 | zd_chip_enable_hwint(&mac->chip); |
| 1384 | |
| 1385 | spin_lock_irq(&mac->lock); |
| 1386 | mac->beacon.last_update = jiffies; |
| 1387 | spin_unlock_irq(&mac->lock); |
| 1388 | } |
| 1389 | |
| 1390 | rearm: |
| 1391 | queue_delayed_work(zd_workqueue, &mac->beacon.watchdog_work, |
| 1392 | BEACON_WATCHDOG_DELAY); |
| 1393 | } |
| 1394 | |
| 1395 | static void beacon_init(struct zd_mac *mac) |
| 1396 | { |
| 1397 | INIT_DELAYED_WORK(&mac->beacon.watchdog_work, beacon_watchdog_handler); |
| 1398 | } |
| 1399 | |
| 1400 | static void beacon_enable(struct zd_mac *mac) |
| 1401 | { |
| 1402 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1403 | |
| 1404 | mac->beacon.last_update = jiffies; |
| 1405 | queue_delayed_work(zd_workqueue, &mac->beacon.watchdog_work, |
| 1406 | BEACON_WATCHDOG_DELAY); |
| 1407 | } |
| 1408 | |
| 1409 | static void beacon_disable(struct zd_mac *mac) |
| 1410 | { |
| 1411 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1412 | cancel_delayed_work_sync(&mac->beacon.watchdog_work); |
| 1413 | } |
| 1414 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1415 | #define LINK_LED_WORK_DELAY HZ |
| 1416 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1417 | static void link_led_handler(struct work_struct *work) |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1418 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1419 | struct zd_mac *mac = |
| 1420 | container_of(work, struct zd_mac, housekeeping.link_led_work.work); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1421 | struct zd_chip *chip = &mac->chip; |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1422 | int is_associated; |
| 1423 | int r; |
| 1424 | |
Jussi Kivilinna | a0fd751 | 2011-01-31 20:49:52 +0200 | [diff] [blame] | 1425 | if (!test_bit(ZD_DEVICE_RUNNING, &mac->flags)) |
| 1426 | goto requeue; |
| 1427 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1428 | spin_lock_irq(&mac->lock); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1429 | is_associated = mac->associated; |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1430 | spin_unlock_irq(&mac->lock); |
| 1431 | |
| 1432 | r = zd_chip_control_leds(chip, |
Luis R. Rodriguez | 14b46c8 | 2009-08-04 14:04:17 -0700 | [diff] [blame] | 1433 | is_associated ? ZD_LED_ASSOCIATED : ZD_LED_SCANNING); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1434 | if (r) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1435 | dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1436 | |
Jussi Kivilinna | a0fd751 | 2011-01-31 20:49:52 +0200 | [diff] [blame] | 1437 | requeue: |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1438 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1439 | LINK_LED_WORK_DELAY); |
| 1440 | } |
| 1441 | |
| 1442 | static void housekeeping_init(struct zd_mac *mac) |
| 1443 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1444 | INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | static void housekeeping_enable(struct zd_mac *mac) |
| 1448 | { |
| 1449 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1450 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1451 | 0); |
| 1452 | } |
| 1453 | |
| 1454 | static void housekeeping_disable(struct zd_mac *mac) |
| 1455 | { |
| 1456 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
Tejun Heo | afe2c51 | 2010-12-14 16:21:17 +0100 | [diff] [blame] | 1457 | cancel_delayed_work_sync(&mac->housekeeping.link_led_work); |
Luis R. Rodriguez | 14b46c8 | 2009-08-04 14:04:17 -0700 | [diff] [blame] | 1458 | zd_chip_control_leds(&mac->chip, ZD_LED_OFF); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1459 | } |