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