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