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