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> |
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" }, |
| 44 | { ZD_REGDOMAIN_JAPAN_ADD, "JP" }, |
| 45 | { ZD_REGDOMAIN_SPAIN, "ES" }, |
| 46 | { ZD_REGDOMAIN_FRANCE, "FR" }, |
| 47 | }; |
| 48 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 49 | /* This table contains the hardware specific values for the modulation rates. */ |
| 50 | static const struct ieee80211_rate zd_rates[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 51 | { .bitrate = 10, |
| 52 | .hw_value = ZD_CCK_RATE_1M, }, |
| 53 | { .bitrate = 20, |
| 54 | .hw_value = ZD_CCK_RATE_2M, |
| 55 | .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT, |
| 56 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 57 | { .bitrate = 55, |
| 58 | .hw_value = ZD_CCK_RATE_5_5M, |
| 59 | .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT, |
| 60 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 61 | { .bitrate = 110, |
| 62 | .hw_value = ZD_CCK_RATE_11M, |
| 63 | .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT, |
| 64 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 65 | { .bitrate = 60, |
| 66 | .hw_value = ZD_OFDM_RATE_6M, |
| 67 | .flags = 0 }, |
| 68 | { .bitrate = 90, |
| 69 | .hw_value = ZD_OFDM_RATE_9M, |
| 70 | .flags = 0 }, |
| 71 | { .bitrate = 120, |
| 72 | .hw_value = ZD_OFDM_RATE_12M, |
| 73 | .flags = 0 }, |
| 74 | { .bitrate = 180, |
| 75 | .hw_value = ZD_OFDM_RATE_18M, |
| 76 | .flags = 0 }, |
| 77 | { .bitrate = 240, |
| 78 | .hw_value = ZD_OFDM_RATE_24M, |
| 79 | .flags = 0 }, |
| 80 | { .bitrate = 360, |
| 81 | .hw_value = ZD_OFDM_RATE_36M, |
| 82 | .flags = 0 }, |
| 83 | { .bitrate = 480, |
| 84 | .hw_value = ZD_OFDM_RATE_48M, |
| 85 | .flags = 0 }, |
| 86 | { .bitrate = 540, |
| 87 | .hw_value = ZD_OFDM_RATE_54M, |
| 88 | .flags = 0 }, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | static const struct ieee80211_channel zd_channels[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 92 | { .center_freq = 2412, .hw_value = 1 }, |
| 93 | { .center_freq = 2417, .hw_value = 2 }, |
| 94 | { .center_freq = 2422, .hw_value = 3 }, |
| 95 | { .center_freq = 2427, .hw_value = 4 }, |
| 96 | { .center_freq = 2432, .hw_value = 5 }, |
| 97 | { .center_freq = 2437, .hw_value = 6 }, |
| 98 | { .center_freq = 2442, .hw_value = 7 }, |
| 99 | { .center_freq = 2447, .hw_value = 8 }, |
| 100 | { .center_freq = 2452, .hw_value = 9 }, |
| 101 | { .center_freq = 2457, .hw_value = 10 }, |
| 102 | { .center_freq = 2462, .hw_value = 11 }, |
| 103 | { .center_freq = 2467, .hw_value = 12 }, |
| 104 | { .center_freq = 2472, .hw_value = 13 }, |
| 105 | { .center_freq = 2484, .hw_value = 14 }, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 106 | }; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 107 | |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 108 | static void housekeeping_init(struct zd_mac *mac); |
| 109 | static void housekeeping_enable(struct zd_mac *mac); |
| 110 | static void housekeeping_disable(struct zd_mac *mac); |
| 111 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 112 | static int zd_reg2alpha2(u8 regdomain, char *alpha2) |
| 113 | { |
| 114 | unsigned int i; |
| 115 | struct zd_reg_alpha2_map *reg_map; |
| 116 | for (i = 0; i < ARRAY_SIZE(reg_alpha2_map); i++) { |
| 117 | reg_map = ®_alpha2_map[i]; |
| 118 | if (regdomain == reg_map->reg) { |
| 119 | alpha2[0] = reg_map->alpha2[0]; |
| 120 | alpha2[1] = reg_map->alpha2[1]; |
| 121 | return 0; |
| 122 | } |
| 123 | } |
| 124 | return 1; |
| 125 | } |
| 126 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 127 | int zd_mac_preinit_hw(struct ieee80211_hw *hw) |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 128 | { |
| 129 | int r; |
| 130 | u8 addr[ETH_ALEN]; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 131 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 132 | |
| 133 | r = zd_chip_read_mac_addr_fw(&mac->chip, addr); |
| 134 | if (r) |
| 135 | return r; |
| 136 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 137 | SET_IEEE80211_PERM_ADDR(hw, addr); |
| 138 | |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 142 | int zd_mac_init_hw(struct ieee80211_hw *hw) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 143 | { |
| 144 | int r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 145 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 146 | struct zd_chip *chip = &mac->chip; |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 147 | char alpha2[2]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 148 | u8 default_regdomain; |
| 149 | |
| 150 | r = zd_chip_enable_int(chip); |
| 151 | if (r) |
| 152 | goto out; |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 153 | r = zd_chip_init_hw(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 154 | if (r) |
| 155 | goto disable_int; |
| 156 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 157 | ZD_ASSERT(!irqs_disabled()); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 158 | |
| 159 | r = zd_read_regdomain(chip, &default_regdomain); |
| 160 | if (r) |
| 161 | goto disable_int; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 162 | spin_lock_irq(&mac->lock); |
| 163 | mac->regdomain = mac->default_regdomain = default_regdomain; |
| 164 | spin_unlock_irq(&mac->lock); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 165 | |
Daniel Drake | 40da08b | 2006-08-01 23:43:32 +0200 | [diff] [blame] | 166 | /* We must inform the device that we are doing encryption/decryption in |
| 167 | * software at the moment. */ |
| 168 | r = zd_set_encryption_type(chip, ENC_SNIFFER); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 169 | if (r) |
| 170 | goto disable_int; |
| 171 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 172 | r = zd_reg2alpha2(mac->regdomain, alpha2); |
| 173 | if (!r) |
| 174 | regulatory_hint(hw->wiphy, alpha2, NULL); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 175 | |
| 176 | r = 0; |
| 177 | disable_int: |
| 178 | zd_chip_disable_int(chip); |
| 179 | out: |
| 180 | return r; |
| 181 | } |
| 182 | |
| 183 | void zd_mac_clear(struct zd_mac *mac) |
| 184 | { |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 185 | flush_workqueue(zd_workqueue); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 186 | zd_chip_clear(&mac->chip); |
Ulrich Kunitz | c48cf12 | 2006-08-12 18:00:17 +0100 | [diff] [blame] | 187 | ZD_ASSERT(!spin_is_locked(&mac->lock)); |
| 188 | ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 191 | static int set_rx_filter(struct zd_mac *mac) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 192 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 193 | unsigned long flags; |
| 194 | u32 filter = STA_RX_FILTER; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 195 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 196 | spin_lock_irqsave(&mac->lock, flags); |
| 197 | if (mac->pass_ctrl) |
| 198 | filter |= RX_FILTER_CTRL; |
| 199 | spin_unlock_irqrestore(&mac->lock, flags); |
| 200 | |
| 201 | return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter); |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int set_mc_hash(struct zd_mac *mac) |
| 205 | { |
| 206 | struct zd_mc_hash hash; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 207 | zd_mc_clear(&hash); |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 208 | return zd_chip_set_multicast_hash(&mac->chip, &hash); |
| 209 | } |
| 210 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 211 | static int zd_op_start(struct ieee80211_hw *hw) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 212 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 213 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 214 | struct zd_chip *chip = &mac->chip; |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 215 | struct zd_usb *usb = &chip->usb; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 216 | int r; |
| 217 | |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 218 | if (!usb->initialized) { |
| 219 | r = zd_usb_init_hw(usb); |
| 220 | if (r) |
| 221 | goto out; |
| 222 | } |
| 223 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 224 | r = zd_chip_enable_int(chip); |
| 225 | if (r < 0) |
| 226 | goto out; |
| 227 | |
| 228 | r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G); |
| 229 | if (r < 0) |
| 230 | goto disable_int; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 231 | r = set_rx_filter(mac); |
| 232 | if (r) |
| 233 | goto disable_int; |
Ulrich Kunitz | c569123 | 2007-07-21 22:42:13 +0100 | [diff] [blame] | 234 | r = set_mc_hash(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 235 | if (r) |
| 236 | goto disable_int; |
| 237 | r = zd_chip_switch_radio_on(chip); |
| 238 | if (r < 0) |
| 239 | goto disable_int; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 240 | r = zd_chip_enable_rxtx(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 241 | if (r < 0) |
| 242 | goto disable_radio; |
| 243 | r = zd_chip_enable_hwint(chip); |
| 244 | if (r < 0) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 245 | goto disable_rxtx; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 246 | |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 247 | housekeeping_enable(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 248 | return 0; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 249 | disable_rxtx: |
| 250 | zd_chip_disable_rxtx(chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 251 | disable_radio: |
| 252 | zd_chip_switch_radio_off(chip); |
| 253 | disable_int: |
| 254 | zd_chip_disable_int(chip); |
| 255 | out: |
| 256 | return r; |
| 257 | } |
| 258 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 259 | static void zd_op_stop(struct ieee80211_hw *hw) |
| 260 | { |
| 261 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 262 | struct zd_chip *chip = &mac->chip; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 263 | struct sk_buff *skb; |
| 264 | struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 265 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 266 | /* The order here deliberately is a little different from the open() |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 267 | * 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] | 268 | * frames to be processed by mac80211 after we have stopped it. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 269 | */ |
| 270 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 271 | zd_chip_disable_rxtx(chip); |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 272 | housekeeping_disable(mac); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 273 | flush_workqueue(zd_workqueue); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 274 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 275 | zd_chip_disable_hwint(chip); |
| 276 | zd_chip_switch_radio_off(chip); |
| 277 | zd_chip_disable_int(chip); |
| 278 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 279 | |
| 280 | while ((skb = skb_dequeue(ack_wait_queue))) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 281 | dev_kfree_skb_any(skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 284 | /** |
| 285 | * tx_status - reports tx status of a packet if required |
| 286 | * @hw - a &struct ieee80211_hw pointer |
| 287 | * @skb - a sk-buffer |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 288 | * @flags: extra flags to set in the TX status info |
| 289 | * @ackssi: ACK signal strength |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 290 | * @success - True for successfull transmission of the frame |
| 291 | * |
| 292 | * This information calls ieee80211_tx_status_irqsafe() if required by the |
| 293 | * control information. It copies the control information into the status |
| 294 | * information. |
| 295 | * |
| 296 | * If no status information has been requested, the skb is freed. |
| 297 | */ |
| 298 | static void tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 299 | u32 flags, int ackssi, bool success) |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 300 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 301 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 302 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 303 | memset(&info->status, 0, sizeof(info->status)); |
| 304 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 305 | if (!success) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 306 | info->status.excessive_retries = 1; |
| 307 | info->flags |= flags; |
| 308 | info->status.ack_signal = ackssi; |
| 309 | ieee80211_tx_status_irqsafe(hw, skb); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 312 | /** |
| 313 | * zd_mac_tx_failed - callback for failed frames |
| 314 | * @dev: the mac80211 wireless device |
| 315 | * |
| 316 | * This function is called if a frame couldn't be succesfully be |
| 317 | * transferred. The first frame from the tx queue, will be selected and |
| 318 | * reported as error to the upper layers. |
| 319 | */ |
| 320 | void zd_mac_tx_failed(struct ieee80211_hw *hw) |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 321 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 322 | struct sk_buff_head *q = &zd_hw_mac(hw)->ack_wait_queue; |
| 323 | struct sk_buff *skb; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 324 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 325 | skb = skb_dequeue(q); |
| 326 | if (skb == NULL) |
| 327 | return; |
Johannes Berg | 5078ed5 | 2008-02-20 12:09:25 +0100 | [diff] [blame] | 328 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 329 | tx_status(hw, skb, 0, 0, 0); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 332 | /** |
| 333 | * zd_mac_tx_to_dev - callback for USB layer |
| 334 | * @skb: a &sk_buff pointer |
| 335 | * @error: error value, 0 if transmission successful |
| 336 | * |
| 337 | * Informs the MAC layer that the frame has successfully transferred to the |
| 338 | * device. If an ACK is required and the transfer to the device has been |
| 339 | * successful, the packets are put on the @ack_wait_queue with |
| 340 | * the control set removed. |
| 341 | */ |
| 342 | void zd_mac_tx_to_dev(struct sk_buff *skb, int error) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 343 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 344 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 345 | struct ieee80211_hw *hw = info->driver_data[0]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 346 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 347 | skb_pull(skb, sizeof(struct zd_ctrlset)); |
| 348 | if (unlikely(error || |
| 349 | (info->flags & IEEE80211_TX_CTL_NO_ACK))) { |
| 350 | tx_status(hw, skb, 0, 0, !error); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 351 | } else { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 352 | struct sk_buff_head *q = |
| 353 | &zd_hw_mac(hw)->ack_wait_queue; |
| 354 | |
| 355 | skb_queue_tail(q, skb); |
| 356 | while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) |
| 357 | zd_mac_tx_failed(hw); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 358 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 361 | 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] | 362 | { |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 363 | /* 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] | 364 | * the zd-rate values. |
| 365 | */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 366 | static const u8 rate_divisor[] = { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 367 | [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1, |
| 368 | [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2, |
| 369 | /* Bits must be doubled. */ |
| 370 | [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11, |
| 371 | [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11, |
| 372 | [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6, |
| 373 | [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9, |
| 374 | [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12, |
| 375 | [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18, |
| 376 | [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24, |
| 377 | [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36, |
| 378 | [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48, |
| 379 | [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | u32 bits = (u32)tx_length * 8; |
| 383 | u32 divisor; |
| 384 | |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 385 | divisor = rate_divisor[ZD_PURE_RATE(zd_rate)]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 386 | if (divisor == 0) |
| 387 | return -EINVAL; |
| 388 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 389 | switch (zd_rate) { |
| 390 | case ZD_CCK_RATE_5_5M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 391 | bits = (2*bits) + 10; /* round up to the next integer */ |
| 392 | break; |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 393 | case ZD_CCK_RATE_11M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 394 | if (service) { |
| 395 | u32 t = bits % 11; |
| 396 | *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 397 | if (0 < t && t <= 3) { |
| 398 | *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 399 | } |
| 400 | } |
| 401 | bits += 10; /* round up to the next integer */ |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | return bits/divisor; |
| 406 | } |
| 407 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 408 | static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 409 | struct ieee80211_hdr *header, u32 flags) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 410 | { |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 411 | /* |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 412 | * CONTROL TODO: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 413 | * - if backoff needed, enable bit 0 |
| 414 | * - if burst (backoff not needed) disable bit 0 |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 415 | */ |
| 416 | |
| 417 | cs->control = 0; |
| 418 | |
| 419 | /* First fragment */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 420 | if (flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 421 | cs->control |= ZD_CS_NEED_RANDOM_BACKOFF; |
| 422 | |
| 423 | /* Multicast */ |
| 424 | if (is_multicast_ether_addr(header->addr1)) |
| 425 | cs->control |= ZD_CS_MULTICAST; |
| 426 | |
| 427 | /* PS-POLL */ |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 428 | if (ieee80211_is_pspoll(header->frame_control)) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 429 | cs->control |= ZD_CS_PS_POLL_FRAME; |
| 430 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 431 | if (flags & IEEE80211_TX_CTL_USE_RTS_CTS) |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 432 | cs->control |= ZD_CS_RTS; |
| 433 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 434 | if (flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 435 | cs->control |= ZD_CS_SELF_CTS; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 436 | |
| 437 | /* FIXME: Management frame? */ |
| 438 | } |
| 439 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 440 | 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] | 441 | { |
| 442 | struct zd_mac *mac = zd_hw_mac(hw); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 443 | int r; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 444 | u32 tmp, j = 0; |
| 445 | /* 4 more bytes for tail CRC */ |
| 446 | u32 full_len = beacon->len + 4; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 447 | |
| 448 | r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 0); |
| 449 | if (r < 0) |
| 450 | return r; |
| 451 | r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp); |
| 452 | if (r < 0) |
| 453 | return r; |
| 454 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 455 | while (tmp & 0x2) { |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 456 | r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp); |
| 457 | if (r < 0) |
| 458 | return r; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 459 | if ((++j % 100) == 0) { |
| 460 | printk(KERN_ERR "CR_BCN_FIFO_SEMAPHORE not ready\n"); |
| 461 | if (j >= 500) { |
| 462 | printk(KERN_ERR "Giving up beacon config.\n"); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 463 | return -ETIMEDOUT; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | msleep(1); |
| 467 | } |
| 468 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 469 | r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, full_len - 1); |
| 470 | if (r < 0) |
| 471 | return r; |
| 472 | if (zd_chip_is_zd1211b(&mac->chip)) { |
| 473 | r = zd_iowrite32(&mac->chip, CR_BCN_LENGTH, full_len - 1); |
| 474 | if (r < 0) |
| 475 | return r; |
| 476 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 477 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 478 | for (j = 0 ; j < beacon->len; j++) { |
| 479 | r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 480 | *((u8 *)(beacon->data + j))); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 481 | if (r < 0) |
| 482 | return r; |
| 483 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 484 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 485 | for (j = 0; j < 4; j++) { |
| 486 | r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, 0x0); |
| 487 | if (r < 0) |
| 488 | return r; |
| 489 | } |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 490 | |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 491 | r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 1); |
| 492 | if (r < 0) |
| 493 | return r; |
| 494 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 495 | /* 802.11b/g 2.4G CCK 1Mb |
| 496 | * 802.11a, not yet implemented, uses different values (see GPL vendor |
| 497 | * driver) |
| 498 | */ |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 499 | return zd_iowrite32(&mac->chip, CR_BCN_PLCP_CFG, 0x00000400 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 500 | (full_len << 19)); |
| 501 | } |
| 502 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 503 | static int fill_ctrlset(struct zd_mac *mac, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 504 | struct sk_buff *skb) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 505 | { |
| 506 | int r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 507 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 508 | unsigned int frag_len = skb->len + FCS_LEN; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 509 | unsigned int packet_length; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 510 | struct ieee80211_rate *txrate; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 511 | struct zd_ctrlset *cs = (struct zd_ctrlset *) |
| 512 | skb_push(skb, sizeof(struct zd_ctrlset)); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 513 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 514 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 515 | ZD_ASSERT(frag_len <= 0xffff); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 516 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 517 | txrate = ieee80211_get_tx_rate(mac->hw, info); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 518 | |
| 519 | cs->modulation = txrate->hw_value; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 520 | if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE) |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 521 | cs->modulation = txrate->hw_value_short; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 522 | |
| 523 | cs->tx_length = cpu_to_le16(frag_len); |
| 524 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 525 | cs_set_control(mac, cs, hdr, info->flags); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 526 | |
| 527 | packet_length = frag_len + sizeof(struct zd_ctrlset) + 10; |
| 528 | ZD_ASSERT(packet_length <= 0xffff); |
| 529 | /* ZD1211B: Computing the length difference this way, gives us |
| 530 | * flexibility to compute the packet length. |
| 531 | */ |
Daniel Drake | 74553ae | 2007-07-01 18:22:32 +0100 | [diff] [blame] | 532 | cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ? |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 533 | packet_length - frag_len : packet_length); |
| 534 | |
| 535 | /* |
| 536 | * CURRENT LENGTH: |
| 537 | * - transmit frame length in microseconds |
| 538 | * - seems to be derived from frame length |
| 539 | * - see Cal_Us_Service() in zdinlinef.h |
| 540 | * - if macp->bTxBurstEnable is enabled, then multiply by 4 |
| 541 | * - bTxBurstEnable is never set in the vendor driver |
| 542 | * |
| 543 | * SERVICE: |
| 544 | * - "for PLCP configuration" |
| 545 | * - always 0 except in some situations at 802.11b 11M |
| 546 | * - see line 53 of zdinlinef.h |
| 547 | */ |
| 548 | cs->service = 0; |
Ulrich Kunitz | 64f222c | 2007-08-06 01:24:31 +0100 | [diff] [blame] | 549 | r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation), |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 550 | le16_to_cpu(cs->tx_length)); |
| 551 | if (r < 0) |
| 552 | return r; |
| 553 | cs->current_length = cpu_to_le16(r); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 554 | cs->next_frame_length = 0; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 555 | |
| 556 | return 0; |
| 557 | } |
| 558 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 559 | /** |
| 560 | * zd_op_tx - transmits a network frame to the device |
Ulrich Kunitz | 741fec5 | 2006-11-22 00:05:53 +0000 | [diff] [blame] | 561 | * |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 562 | * @dev: mac80211 hardware device |
| 563 | * @skb: socket buffer |
| 564 | * @control: the control structure |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 565 | * |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 566 | * This function transmit an IEEE 802.11 network frame to the device. The |
| 567 | * control block of the skbuff will be initialized. If necessary the incoming |
| 568 | * mac80211 queues will be stopped. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 569 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 570 | 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] | 571 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 572 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 573 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 574 | int r; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 575 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 576 | r = fill_ctrlset(mac, skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 577 | if (r) |
| 578 | return r; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 579 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 580 | info->driver_data[0] = hw; |
| 581 | |
| 582 | r = zd_usb_tx(&mac->chip.usb, skb); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 583 | if (r) |
| 584 | return r; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * filter_ack - filters incoming packets for acknowledgements |
| 590 | * @dev: the mac80211 device |
| 591 | * @rx_hdr: received header |
| 592 | * @stats: the status for the received packet |
| 593 | * |
| 594 | * This functions looks for ACK packets and tries to match them with the |
| 595 | * frames in the tx queue. If a match is found the frame will be dequeued and |
| 596 | * the upper layers is informed about the successful transmission. If |
| 597 | * mac80211 queues have been stopped and the number of frames still to be |
| 598 | * transmitted is low the queues will be opened again. |
| 599 | * |
| 600 | * Returns 1 if the frame was an ACK, 0 if it was ignored. |
| 601 | */ |
| 602 | static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr, |
| 603 | struct ieee80211_rx_status *stats) |
| 604 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 605 | struct sk_buff *skb; |
| 606 | struct sk_buff_head *q; |
| 607 | unsigned long flags; |
| 608 | |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 609 | if (!ieee80211_is_ack(rx_hdr->frame_control)) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 610 | return 0; |
| 611 | |
| 612 | q = &zd_hw_mac(hw)->ack_wait_queue; |
| 613 | spin_lock_irqsave(&q->lock, flags); |
David S. Miller | 47a227d | 2008-09-23 00:23:30 -0700 | [diff] [blame] | 614 | skb_queue_walk(q, skb) { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 615 | struct ieee80211_hdr *tx_hdr; |
| 616 | |
| 617 | tx_hdr = (struct ieee80211_hdr *)skb->data; |
| 618 | if (likely(!compare_ether_addr(tx_hdr->addr2, rx_hdr->addr1))) |
| 619 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 620 | __skb_unlink(skb, q); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 621 | tx_status(hw, skb, IEEE80211_TX_STAT_ACK, stats->signal, 1); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 622 | goto out; |
| 623 | } |
| 624 | } |
| 625 | out: |
| 626 | spin_unlock_irqrestore(&q->lock, flags); |
| 627 | return 1; |
| 628 | } |
| 629 | |
| 630 | int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length) |
| 631 | { |
| 632 | struct zd_mac *mac = zd_hw_mac(hw); |
| 633 | struct ieee80211_rx_status stats; |
| 634 | const struct rx_status *status; |
| 635 | struct sk_buff *skb; |
| 636 | int bad_frame = 0; |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 637 | __le16 fc; |
| 638 | int need_padding; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 639 | int i; |
| 640 | u8 rate; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 641 | |
| 642 | if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ + |
| 643 | FCS_LEN + sizeof(struct rx_status)) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 644 | return -EINVAL; |
| 645 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 646 | memset(&stats, 0, sizeof(stats)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 647 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 648 | /* Note about pass_failed_fcs and pass_ctrl access below: |
| 649 | * mac locking intentionally omitted here, as this is the only unlocked |
| 650 | * reader and the only writer is configure_filter. Plus, if there were |
| 651 | * any races accessing these variables, it wouldn't really matter. |
| 652 | * If mac80211 ever provides a way for us to access filter flags |
| 653 | * from outside configure_filter, we could improve on this. Also, this |
| 654 | * situation may change once we implement some kind of DMA-into-skb |
| 655 | * RX path. */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 656 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 657 | /* Caller has to ensure that length >= sizeof(struct rx_status). */ |
| 658 | status = (struct rx_status *) |
Ulrich Kunitz | 937a049 | 2007-10-02 18:36:53 +0100 | [diff] [blame] | 659 | (buffer + (length - sizeof(struct rx_status))); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 660 | if (status->frame_status & ZD_RX_ERROR) { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 661 | if (mac->pass_failed_fcs && |
| 662 | (status->frame_status & ZD_RX_CRC32_ERROR)) { |
| 663 | stats.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 664 | bad_frame = 1; |
| 665 | } else { |
| 666 | return -EINVAL; |
Ulrich Kunitz | 22d3405 | 2007-01-29 01:00:03 +0000 | [diff] [blame] | 667 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 668 | } |
Ulrich Kunitz | 22d3405 | 2007-01-29 01:00:03 +0000 | [diff] [blame] | 669 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 670 | stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq; |
| 671 | stats.band = IEEE80211_BAND_2GHZ; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 672 | stats.signal = status->signal_strength; |
| 673 | stats.qual = zd_rx_qual_percent(buffer, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 674 | length - sizeof(struct rx_status), |
| 675 | status); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 676 | |
| 677 | rate = zd_rx_rate(buffer, status); |
| 678 | |
| 679 | /* todo: return index in the big switches in zd_rx_rate instead */ |
| 680 | for (i = 0; i < mac->band.n_bitrates; i++) |
| 681 | if (rate == mac->band.bitrates[i].hw_value) |
| 682 | stats.rate_idx = i; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 683 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 684 | length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status); |
| 685 | buffer += ZD_PLCP_HEADER_SIZE; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 686 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 687 | /* Except for bad frames, filter each frame to see if it is an ACK, in |
| 688 | * which case our internal TX tracking is updated. Normally we then |
| 689 | * bail here as there's no need to pass ACKs on up to the stack, but |
| 690 | * there is also the case where the stack has requested us to pass |
| 691 | * control frames on up (pass_ctrl) which we must consider. */ |
| 692 | if (!bad_frame && |
| 693 | filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats) |
| 694 | && !mac->pass_ctrl) |
| 695 | return 0; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 696 | |
Harvey Harrison | 8536582 | 2008-06-14 23:33:39 -0700 | [diff] [blame] | 697 | fc = *(__le16 *)buffer; |
| 698 | need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc); |
Michael Buesch | 9081728 | 2007-12-29 17:24:23 +0100 | [diff] [blame] | 699 | |
| 700 | skb = dev_alloc_skb(length + (need_padding ? 2 : 0)); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 701 | if (skb == NULL) |
Ulrich Kunitz | 4d1feab | 2006-12-10 11:13:12 -0800 | [diff] [blame] | 702 | return -ENOMEM; |
Michael Buesch | 9081728 | 2007-12-29 17:24:23 +0100 | [diff] [blame] | 703 | if (need_padding) { |
| 704 | /* Make sure the the payload data is 4 byte aligned. */ |
| 705 | skb_reserve(skb, 2); |
| 706 | } |
| 707 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 708 | memcpy(skb_put(skb, length), buffer, length); |
| 709 | |
| 710 | ieee80211_rx_irqsafe(hw, skb, &stats); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 714 | static int zd_op_add_interface(struct ieee80211_hw *hw, |
| 715 | struct ieee80211_if_init_conf *conf) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 716 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 717 | struct zd_mac *mac = zd_hw_mac(hw); |
| 718 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 719 | /* using NL80211_IFTYPE_UNSPECIFIED to indicate no mode selected */ |
| 720 | if (mac->type != NL80211_IFTYPE_UNSPECIFIED) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 721 | return -EOPNOTSUPP; |
| 722 | |
| 723 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 724 | case NL80211_IFTYPE_MONITOR: |
| 725 | case NL80211_IFTYPE_MESH_POINT: |
| 726 | case NL80211_IFTYPE_STATION: |
| 727 | case NL80211_IFTYPE_ADHOC: |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 728 | mac->type = conf->type; |
| 729 | break; |
| 730 | default: |
| 731 | return -EOPNOTSUPP; |
| 732 | } |
| 733 | |
| 734 | return zd_write_mac_addr(&mac->chip, conf->mac_addr); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 735 | } |
| 736 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 737 | static void zd_op_remove_interface(struct ieee80211_hw *hw, |
| 738 | struct ieee80211_if_init_conf *conf) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 739 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 740 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 741 | mac->type = NL80211_IFTYPE_UNSPECIFIED; |
Luis Carlos Cobo | 86229f0 | 2008-07-08 16:19:21 +0200 | [diff] [blame] | 742 | zd_set_beacon_interval(&mac->chip, 0); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 743 | zd_write_mac_addr(&mac->chip, NULL); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 746 | static int zd_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 747 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 748 | struct zd_mac *mac = zd_hw_mac(hw); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 749 | return zd_chip_set_channel(&mac->chip, conf->channel->hw_value); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 750 | } |
| 751 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 752 | static int zd_op_config_interface(struct ieee80211_hw *hw, |
| 753 | struct ieee80211_vif *vif, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 754 | struct ieee80211_if_conf *conf) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 755 | { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 756 | struct zd_mac *mac = zd_hw_mac(hw); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 757 | int associated; |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 758 | int r; |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 759 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 760 | if (mac->type == NL80211_IFTYPE_MESH_POINT || |
| 761 | mac->type == NL80211_IFTYPE_ADHOC) { |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 762 | associated = true; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 763 | if (conf->changed & IEEE80211_IFCC_BEACON) { |
| 764 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 765 | |
| 766 | if (!beacon) |
| 767 | return -ENOMEM; |
| 768 | r = zd_mac_config_beacon(hw, beacon); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 769 | if (r < 0) |
| 770 | return r; |
| 771 | r = zd_set_beacon_interval(&mac->chip, BCN_MODE_IBSS | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 772 | hw->conf.beacon_int); |
Daniel Drake | f2cae6c | 2008-07-04 04:30:49 +0100 | [diff] [blame] | 773 | if (r < 0) |
| 774 | return r; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 775 | kfree_skb(beacon); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 776 | } |
| 777 | } else |
| 778 | associated = is_valid_ether_addr(conf->bssid); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 779 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 780 | spin_lock_irq(&mac->lock); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 781 | mac->associated = associated; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 782 | spin_unlock_irq(&mac->lock); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 783 | |
| 784 | /* TODO: do hardware bssid filtering */ |
| 785 | return 0; |
| 786 | } |
| 787 | |
Luis R. Rodriguez | e83a107 | 2008-09-09 23:19:49 -0700 | [diff] [blame] | 788 | static void zd_process_intr(struct work_struct *work) |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 789 | { |
| 790 | u16 int_status; |
| 791 | struct zd_mac *mac = container_of(work, struct zd_mac, process_intr); |
| 792 | |
Al Viro | d63ddce | 2008-05-21 01:34:30 +0100 | [diff] [blame] | 793 | int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer+4)); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 794 | if (int_status & INT_CFG_NEXT_BCN) { |
| 795 | if (net_ratelimit()) |
| 796 | dev_dbg_f(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n"); |
| 797 | } else |
| 798 | dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n"); |
| 799 | |
| 800 | zd_chip_enable_hwint(&mac->chip); |
| 801 | } |
| 802 | |
| 803 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 804 | static void set_multicast_hash_handler(struct work_struct *work) |
| 805 | { |
| 806 | struct zd_mac *mac = |
| 807 | container_of(work, struct zd_mac, set_multicast_hash_work); |
| 808 | struct zd_mc_hash hash; |
| 809 | |
| 810 | spin_lock_irq(&mac->lock); |
| 811 | hash = mac->multicast_hash; |
| 812 | spin_unlock_irq(&mac->lock); |
| 813 | |
| 814 | zd_chip_set_multicast_hash(&mac->chip, &hash); |
| 815 | } |
| 816 | |
| 817 | static void set_rx_filter_handler(struct work_struct *work) |
| 818 | { |
| 819 | struct zd_mac *mac = |
| 820 | container_of(work, struct zd_mac, set_rx_filter_work); |
| 821 | int r; |
| 822 | |
| 823 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 824 | r = set_rx_filter(mac); |
| 825 | if (r) |
| 826 | dev_err(zd_mac_dev(mac), "set_rx_filter_handler error %d\n", r); |
| 827 | } |
| 828 | |
| 829 | #define SUPPORTED_FIF_FLAGS \ |
| 830 | (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \ |
Michael Buesch | 2c1a1b1 | 2008-02-10 16:03:55 +0100 | [diff] [blame] | 831 | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 832 | static void zd_op_configure_filter(struct ieee80211_hw *hw, |
| 833 | unsigned int changed_flags, |
| 834 | unsigned int *new_flags, |
| 835 | int mc_count, struct dev_mc_list *mclist) |
| 836 | { |
| 837 | struct zd_mc_hash hash; |
| 838 | struct zd_mac *mac = zd_hw_mac(hw); |
| 839 | unsigned long flags; |
| 840 | int i; |
| 841 | |
| 842 | /* Only deal with supported flags */ |
| 843 | changed_flags &= SUPPORTED_FIF_FLAGS; |
| 844 | *new_flags &= SUPPORTED_FIF_FLAGS; |
| 845 | |
| 846 | /* changed_flags is always populated but this driver |
| 847 | * doesn't support all FIF flags so its possible we don't |
| 848 | * need to do anything */ |
| 849 | if (!changed_flags) |
| 850 | return; |
| 851 | |
| 852 | if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)) { |
| 853 | zd_mc_add_all(&hash); |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 854 | } else { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 855 | DECLARE_MAC_BUF(macbuf); |
| 856 | |
| 857 | zd_mc_clear(&hash); |
| 858 | for (i = 0; i < mc_count; i++) { |
| 859 | if (!mclist) |
| 860 | break; |
| 861 | dev_dbg_f(zd_mac_dev(mac), "mc addr %s\n", |
| 862 | print_mac(macbuf, mclist->dmi_addr)); |
| 863 | zd_mc_add_addr(&hash, mclist->dmi_addr); |
| 864 | mclist = mclist->next; |
| 865 | } |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 866 | } |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 867 | |
| 868 | spin_lock_irqsave(&mac->lock, flags); |
| 869 | mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL); |
| 870 | mac->pass_ctrl = !!(*new_flags & FIF_CONTROL); |
| 871 | mac->multicast_hash = hash; |
| 872 | spin_unlock_irqrestore(&mac->lock, flags); |
| 873 | queue_work(zd_workqueue, &mac->set_multicast_hash_work); |
| 874 | |
| 875 | if (changed_flags & FIF_CONTROL) |
| 876 | queue_work(zd_workqueue, &mac->set_rx_filter_work); |
| 877 | |
| 878 | /* no handling required for FIF_OTHER_BSS as we don't currently |
| 879 | * do BSSID filtering */ |
| 880 | /* FIXME: in future it would be nice to enable the probe response |
| 881 | * filter (so that the driver doesn't see them) until |
| 882 | * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd |
| 883 | * have to schedule work to enable prbresp reception, which might |
| 884 | * happen too late. For now we'll just listen and forward them all the |
| 885 | * time. */ |
| 886 | } |
| 887 | |
| 888 | static void set_rts_cts_work(struct work_struct *work) |
| 889 | { |
| 890 | struct zd_mac *mac = |
| 891 | container_of(work, struct zd_mac, set_rts_cts_work); |
| 892 | unsigned long flags; |
| 893 | unsigned int short_preamble; |
| 894 | |
| 895 | mutex_lock(&mac->chip.mutex); |
| 896 | |
| 897 | spin_lock_irqsave(&mac->lock, flags); |
| 898 | mac->updating_rts_rate = 0; |
| 899 | short_preamble = mac->short_preamble; |
| 900 | spin_unlock_irqrestore(&mac->lock, flags); |
| 901 | |
| 902 | zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble); |
| 903 | mutex_unlock(&mac->chip.mutex); |
| 904 | } |
| 905 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 906 | static void zd_op_bss_info_changed(struct ieee80211_hw *hw, |
| 907 | struct ieee80211_vif *vif, |
| 908 | struct ieee80211_bss_conf *bss_conf, |
| 909 | u32 changes) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 910 | { |
| 911 | struct zd_mac *mac = zd_hw_mac(hw); |
| 912 | unsigned long flags; |
| 913 | |
| 914 | dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes); |
| 915 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 916 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 917 | spin_lock_irqsave(&mac->lock, flags); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 918 | mac->short_preamble = bss_conf->use_short_preamble; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 919 | if (!mac->updating_rts_rate) { |
| 920 | mac->updating_rts_rate = 1; |
| 921 | /* FIXME: should disable TX here, until work has |
| 922 | * completed and RTS_CTS reg is updated */ |
| 923 | queue_work(zd_workqueue, &mac->set_rts_cts_work); |
| 924 | } |
| 925 | spin_unlock_irqrestore(&mac->lock, flags); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | static const struct ieee80211_ops zd_ops = { |
| 930 | .tx = zd_op_tx, |
| 931 | .start = zd_op_start, |
| 932 | .stop = zd_op_stop, |
| 933 | .add_interface = zd_op_add_interface, |
| 934 | .remove_interface = zd_op_remove_interface, |
| 935 | .config = zd_op_config, |
| 936 | .config_interface = zd_op_config_interface, |
| 937 | .configure_filter = zd_op_configure_filter, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 938 | .bss_info_changed = zd_op_bss_info_changed, |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 939 | }; |
| 940 | |
| 941 | struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf) |
| 942 | { |
| 943 | struct zd_mac *mac; |
| 944 | struct ieee80211_hw *hw; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 945 | |
| 946 | hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops); |
| 947 | if (!hw) { |
| 948 | dev_dbg_f(&intf->dev, "out of memory\n"); |
| 949 | return NULL; |
| 950 | } |
| 951 | |
| 952 | mac = zd_hw_mac(hw); |
| 953 | |
| 954 | memset(mac, 0, sizeof(*mac)); |
| 955 | spin_lock_init(&mac->lock); |
| 956 | mac->hw = hw; |
| 957 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 958 | mac->type = NL80211_IFTYPE_UNSPECIFIED; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 959 | |
| 960 | memcpy(mac->channels, zd_channels, sizeof(zd_channels)); |
| 961 | memcpy(mac->rates, zd_rates, sizeof(zd_rates)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 962 | mac->band.n_bitrates = ARRAY_SIZE(zd_rates); |
| 963 | mac->band.bitrates = mac->rates; |
| 964 | mac->band.n_channels = ARRAY_SIZE(zd_channels); |
| 965 | mac->band.channels = mac->channels; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 966 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 967 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band; |
| 968 | |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 969 | hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 970 | IEEE80211_HW_SIGNAL_DB; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 971 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 972 | hw->wiphy->interface_modes = |
| 973 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 974 | BIT(NL80211_IFTYPE_STATION) | |
| 975 | BIT(NL80211_IFTYPE_ADHOC); |
| 976 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 977 | hw->max_signal = 100; |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 978 | hw->queues = 1; |
| 979 | hw->extra_tx_headroom = sizeof(struct zd_ctrlset); |
| 980 | |
| 981 | skb_queue_head_init(&mac->ack_wait_queue); |
| 982 | |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 983 | zd_chip_init(&mac->chip, hw, intf); |
| 984 | housekeeping_init(mac); |
| 985 | INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler); |
| 986 | INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work); |
| 987 | INIT_WORK(&mac->set_rx_filter_work, set_rx_filter_handler); |
Luis Carlos Cobo | 72e77a8 | 2008-03-03 12:32:15 -0800 | [diff] [blame] | 988 | INIT_WORK(&mac->process_intr, zd_process_intr); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 989 | |
| 990 | SET_IEEE80211_DEV(hw, &intf->dev); |
| 991 | return hw; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 994 | #define LINK_LED_WORK_DELAY HZ |
| 995 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 996 | static void link_led_handler(struct work_struct *work) |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 997 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 998 | struct zd_mac *mac = |
| 999 | container_of(work, struct zd_mac, housekeeping.link_led_work.work); |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1000 | struct zd_chip *chip = &mac->chip; |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1001 | int is_associated; |
| 1002 | int r; |
| 1003 | |
| 1004 | spin_lock_irq(&mac->lock); |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1005 | is_associated = mac->associated; |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1006 | spin_unlock_irq(&mac->lock); |
| 1007 | |
| 1008 | r = zd_chip_control_leds(chip, |
| 1009 | is_associated ? LED_ASSOCIATED : LED_SCANNING); |
| 1010 | if (r) |
Daniel Drake | 459c51a | 2007-11-19 15:00:29 +0000 | [diff] [blame] | 1011 | 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] | 1012 | |
| 1013 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1014 | LINK_LED_WORK_DELAY); |
| 1015 | } |
| 1016 | |
| 1017 | static void housekeeping_init(struct zd_mac *mac) |
| 1018 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1019 | INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler); |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static void housekeeping_enable(struct zd_mac *mac) |
| 1023 | { |
| 1024 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1025 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1026 | 0); |
| 1027 | } |
| 1028 | |
| 1029 | static void housekeeping_disable(struct zd_mac *mac) |
| 1030 | { |
| 1031 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1032 | cancel_rearming_delayed_workqueue(zd_workqueue, |
| 1033 | &mac->housekeeping.link_led_work); |
| 1034 | zd_chip_control_leds(&mac->chip, LED_OFF); |
| 1035 | } |