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