Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1 | /* zd_mac.c |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #include <linux/netdevice.h> |
| 19 | #include <linux/etherdevice.h> |
| 20 | #include <linux/wireless.h> |
| 21 | #include <linux/usb.h> |
| 22 | #include <linux/jiffies.h> |
| 23 | #include <net/ieee80211_radiotap.h> |
| 24 | |
| 25 | #include "zd_def.h" |
| 26 | #include "zd_chip.h" |
| 27 | #include "zd_mac.h" |
| 28 | #include "zd_ieee80211.h" |
| 29 | #include "zd_netdev.h" |
| 30 | #include "zd_rf.h" |
| 31 | #include "zd_util.h" |
| 32 | |
| 33 | static void ieee_init(struct ieee80211_device *ieee); |
| 34 | static void softmac_init(struct ieee80211softmac_device *sm); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 35 | static void set_rts_cts_work(void *d); |
| 36 | static void set_basic_rates_work(void *d); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 37 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 38 | static void housekeeping_init(struct zd_mac *mac); |
| 39 | static void housekeeping_enable(struct zd_mac *mac); |
| 40 | static void housekeeping_disable(struct zd_mac *mac); |
| 41 | |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 42 | static void set_multicast_hash_handler(void *mac_ptr); |
| 43 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 44 | int zd_mac_init(struct zd_mac *mac, |
| 45 | struct net_device *netdev, |
| 46 | struct usb_interface *intf) |
| 47 | { |
| 48 | struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev); |
| 49 | |
| 50 | memset(mac, 0, sizeof(*mac)); |
| 51 | spin_lock_init(&mac->lock); |
| 52 | mac->netdev = netdev; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 53 | INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work, mac); |
| 54 | INIT_WORK(&mac->set_basic_rates_work, set_basic_rates_work, mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 55 | |
| 56 | ieee_init(ieee); |
| 57 | softmac_init(ieee80211_priv(netdev)); |
| 58 | zd_chip_init(&mac->chip, netdev, intf); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 59 | housekeeping_init(mac); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 60 | INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler, |
| 61 | mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int reset_channel(struct zd_mac *mac) |
| 66 | { |
| 67 | int r; |
| 68 | unsigned long flags; |
| 69 | const struct channel_range *range; |
| 70 | |
| 71 | spin_lock_irqsave(&mac->lock, flags); |
| 72 | range = zd_channel_range(mac->regdomain); |
| 73 | if (!range->start) { |
| 74 | r = -EINVAL; |
| 75 | goto out; |
| 76 | } |
| 77 | mac->requested_channel = range->start; |
| 78 | r = 0; |
| 79 | out: |
| 80 | spin_unlock_irqrestore(&mac->lock, flags); |
| 81 | return r; |
| 82 | } |
| 83 | |
| 84 | int zd_mac_init_hw(struct zd_mac *mac, u8 device_type) |
| 85 | { |
| 86 | int r; |
| 87 | struct zd_chip *chip = &mac->chip; |
| 88 | u8 addr[ETH_ALEN]; |
| 89 | u8 default_regdomain; |
| 90 | |
| 91 | r = zd_chip_enable_int(chip); |
| 92 | if (r) |
| 93 | goto out; |
| 94 | r = zd_chip_init_hw(chip, device_type); |
| 95 | if (r) |
| 96 | goto disable_int; |
| 97 | |
| 98 | zd_get_e2p_mac_addr(chip, addr); |
| 99 | r = zd_write_mac_addr(chip, addr); |
| 100 | if (r) |
| 101 | goto disable_int; |
| 102 | ZD_ASSERT(!irqs_disabled()); |
| 103 | spin_lock_irq(&mac->lock); |
| 104 | memcpy(mac->netdev->dev_addr, addr, ETH_ALEN); |
| 105 | spin_unlock_irq(&mac->lock); |
| 106 | |
| 107 | r = zd_read_regdomain(chip, &default_regdomain); |
| 108 | if (r) |
| 109 | goto disable_int; |
| 110 | if (!zd_regdomain_supported(default_regdomain)) { |
| 111 | dev_dbg_f(zd_mac_dev(mac), |
| 112 | "Regulatory Domain %#04x is not supported.\n", |
| 113 | default_regdomain); |
| 114 | r = -EINVAL; |
| 115 | goto disable_int; |
| 116 | } |
| 117 | spin_lock_irq(&mac->lock); |
| 118 | mac->regdomain = mac->default_regdomain = default_regdomain; |
| 119 | spin_unlock_irq(&mac->lock); |
| 120 | r = reset_channel(mac); |
| 121 | if (r) |
| 122 | goto disable_int; |
| 123 | |
Daniel Drake | 40da08b | 2006-08-01 23:43:32 +0200 | [diff] [blame] | 124 | /* We must inform the device that we are doing encryption/decryption in |
| 125 | * software at the moment. */ |
| 126 | r = zd_set_encryption_type(chip, ENC_SNIFFER); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 127 | if (r) |
| 128 | goto disable_int; |
| 129 | |
| 130 | r = zd_geo_init(zd_mac_to_ieee80211(mac), mac->regdomain); |
| 131 | if (r) |
| 132 | goto disable_int; |
| 133 | |
| 134 | r = 0; |
| 135 | disable_int: |
| 136 | zd_chip_disable_int(chip); |
| 137 | out: |
| 138 | return r; |
| 139 | } |
| 140 | |
| 141 | void zd_mac_clear(struct zd_mac *mac) |
| 142 | { |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 143 | flush_workqueue(zd_workqueue); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 144 | zd_chip_clear(&mac->chip); |
Ulrich Kunitz | c48cf12 | 2006-08-12 18:00:17 +0100 | [diff] [blame] | 145 | ZD_ASSERT(!spin_is_locked(&mac->lock)); |
| 146 | ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static int reset_mode(struct zd_mac *mac) |
| 150 | { |
| 151 | struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); |
| 152 | struct zd_ioreq32 ioreqs[3] = { |
Ulrich Kunitz | fde627b | 2006-08-01 23:43:35 +0200 | [diff] [blame] | 153 | { CR_RX_FILTER, STA_RX_FILTER }, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 154 | { CR_SNIFFER_ON, 0U }, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 158 | ioreqs[0].value = 0xffffffff; |
| 159 | ioreqs[1].value = 0x1; |
| 160 | ioreqs[2].value = ENC_SNIFFER; |
| 161 | } |
| 162 | |
| 163 | return zd_iowrite32a(&mac->chip, ioreqs, 3); |
| 164 | } |
| 165 | |
| 166 | int zd_mac_open(struct net_device *netdev) |
| 167 | { |
| 168 | struct zd_mac *mac = zd_netdev_mac(netdev); |
| 169 | struct zd_chip *chip = &mac->chip; |
| 170 | int r; |
| 171 | |
| 172 | r = zd_chip_enable_int(chip); |
| 173 | if (r < 0) |
| 174 | goto out; |
| 175 | |
| 176 | r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G); |
| 177 | if (r < 0) |
| 178 | goto disable_int; |
| 179 | r = reset_mode(mac); |
| 180 | if (r) |
| 181 | goto disable_int; |
| 182 | r = zd_chip_switch_radio_on(chip); |
| 183 | if (r < 0) |
| 184 | goto disable_int; |
| 185 | r = zd_chip_set_channel(chip, mac->requested_channel); |
| 186 | if (r < 0) |
| 187 | goto disable_radio; |
| 188 | r = zd_chip_enable_rx(chip); |
| 189 | if (r < 0) |
| 190 | goto disable_radio; |
| 191 | r = zd_chip_enable_hwint(chip); |
| 192 | if (r < 0) |
| 193 | goto disable_rx; |
| 194 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 195 | housekeeping_enable(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 196 | ieee80211softmac_start(netdev); |
| 197 | return 0; |
| 198 | disable_rx: |
| 199 | zd_chip_disable_rx(chip); |
| 200 | disable_radio: |
| 201 | zd_chip_switch_radio_off(chip); |
| 202 | disable_int: |
| 203 | zd_chip_disable_int(chip); |
| 204 | out: |
| 205 | return r; |
| 206 | } |
| 207 | |
| 208 | int zd_mac_stop(struct net_device *netdev) |
| 209 | { |
| 210 | struct zd_mac *mac = zd_netdev_mac(netdev); |
| 211 | struct zd_chip *chip = &mac->chip; |
| 212 | |
Daniel Drake | c9a4b35 | 2006-06-11 23:18:54 +0100 | [diff] [blame] | 213 | netif_stop_queue(netdev); |
| 214 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 215 | /* |
| 216 | * The order here deliberately is a little different from the open() |
| 217 | * method, since we need to make sure there is no opportunity for RX |
| 218 | * frames to be processed by softmac after we have stopped it. |
| 219 | */ |
| 220 | |
| 221 | zd_chip_disable_rx(chip); |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 222 | housekeeping_disable(mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 223 | ieee80211softmac_stop(netdev); |
| 224 | |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 225 | /* Ensure no work items are running or queued from this point */ |
| 226 | cancel_delayed_work(&mac->set_rts_cts_work); |
| 227 | cancel_delayed_work(&mac->set_basic_rates_work); |
| 228 | flush_workqueue(zd_workqueue); |
| 229 | mac->updating_rts_rate = 0; |
| 230 | mac->updating_basic_rates = 0; |
| 231 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 232 | zd_chip_disable_hwint(chip); |
| 233 | zd_chip_switch_radio_off(chip); |
| 234 | zd_chip_disable_int(chip); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | int zd_mac_set_mac_address(struct net_device *netdev, void *p) |
| 240 | { |
| 241 | int r; |
| 242 | unsigned long flags; |
| 243 | struct sockaddr *addr = p; |
| 244 | struct zd_mac *mac = zd_netdev_mac(netdev); |
| 245 | struct zd_chip *chip = &mac->chip; |
| 246 | |
| 247 | if (!is_valid_ether_addr(addr->sa_data)) |
| 248 | return -EADDRNOTAVAIL; |
| 249 | |
| 250 | dev_dbg_f(zd_mac_dev(mac), |
| 251 | "Setting MAC to " MAC_FMT "\n", MAC_ARG(addr->sa_data)); |
| 252 | |
| 253 | r = zd_write_mac_addr(chip, addr->sa_data); |
| 254 | if (r) |
| 255 | return r; |
| 256 | |
| 257 | spin_lock_irqsave(&mac->lock, flags); |
| 258 | memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN); |
| 259 | spin_unlock_irqrestore(&mac->lock, flags); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 264 | static void set_multicast_hash_handler(void *mac_ptr) |
| 265 | { |
| 266 | struct zd_mac *mac = mac_ptr; |
| 267 | struct zd_mc_hash hash; |
| 268 | |
| 269 | spin_lock_irq(&mac->lock); |
| 270 | hash = mac->multicast_hash; |
| 271 | spin_unlock_irq(&mac->lock); |
| 272 | |
| 273 | zd_chip_set_multicast_hash(&mac->chip, &hash); |
| 274 | } |
| 275 | |
| 276 | void zd_mac_set_multicast_list(struct net_device *dev) |
| 277 | { |
| 278 | struct zd_mc_hash hash; |
| 279 | struct zd_mac *mac = zd_netdev_mac(dev); |
| 280 | struct dev_mc_list *mc; |
| 281 | unsigned long flags; |
| 282 | |
| 283 | if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI)) { |
| 284 | zd_mc_add_all(&hash); |
| 285 | } else { |
| 286 | zd_mc_clear(&hash); |
| 287 | for (mc = dev->mc_list; mc; mc = mc->next) { |
| 288 | dev_dbg_f(zd_mac_dev(mac), "mc addr " MAC_FMT "\n", |
| 289 | MAC_ARG(mc->dmi_addr)); |
| 290 | zd_mc_add_addr(&hash, mc->dmi_addr); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | spin_lock_irqsave(&mac->lock, flags); |
| 295 | mac->multicast_hash = hash; |
| 296 | spin_unlock_irqrestore(&mac->lock, flags); |
| 297 | queue_work(zd_workqueue, &mac->set_multicast_hash_work); |
| 298 | } |
| 299 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 300 | int zd_mac_set_regdomain(struct zd_mac *mac, u8 regdomain) |
| 301 | { |
| 302 | int r; |
| 303 | u8 channel; |
| 304 | |
| 305 | ZD_ASSERT(!irqs_disabled()); |
| 306 | spin_lock_irq(&mac->lock); |
| 307 | if (regdomain == 0) { |
| 308 | regdomain = mac->default_regdomain; |
| 309 | } |
| 310 | if (!zd_regdomain_supported(regdomain)) { |
| 311 | spin_unlock_irq(&mac->lock); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | mac->regdomain = regdomain; |
| 315 | channel = mac->requested_channel; |
| 316 | spin_unlock_irq(&mac->lock); |
| 317 | |
| 318 | r = zd_geo_init(zd_mac_to_ieee80211(mac), regdomain); |
| 319 | if (r) |
| 320 | return r; |
| 321 | if (!zd_regdomain_supports_channel(regdomain, channel)) { |
| 322 | r = reset_channel(mac); |
| 323 | if (r) |
| 324 | return r; |
| 325 | } |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | u8 zd_mac_get_regdomain(struct zd_mac *mac) |
| 331 | { |
| 332 | unsigned long flags; |
| 333 | u8 regdomain; |
| 334 | |
| 335 | spin_lock_irqsave(&mac->lock, flags); |
| 336 | regdomain = mac->regdomain; |
| 337 | spin_unlock_irqrestore(&mac->lock, flags); |
| 338 | return regdomain; |
| 339 | } |
| 340 | |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 341 | /* Fallback to lowest rate, if rate is unknown. */ |
| 342 | static u8 rate_to_zd_rate(u8 rate) |
| 343 | { |
| 344 | switch (rate) { |
| 345 | case IEEE80211_CCK_RATE_2MB: |
| 346 | return ZD_CCK_RATE_2M; |
| 347 | case IEEE80211_CCK_RATE_5MB: |
| 348 | return ZD_CCK_RATE_5_5M; |
| 349 | case IEEE80211_CCK_RATE_11MB: |
| 350 | return ZD_CCK_RATE_11M; |
| 351 | case IEEE80211_OFDM_RATE_6MB: |
| 352 | return ZD_OFDM_RATE_6M; |
| 353 | case IEEE80211_OFDM_RATE_9MB: |
| 354 | return ZD_OFDM_RATE_9M; |
| 355 | case IEEE80211_OFDM_RATE_12MB: |
| 356 | return ZD_OFDM_RATE_12M; |
| 357 | case IEEE80211_OFDM_RATE_18MB: |
| 358 | return ZD_OFDM_RATE_18M; |
| 359 | case IEEE80211_OFDM_RATE_24MB: |
| 360 | return ZD_OFDM_RATE_24M; |
| 361 | case IEEE80211_OFDM_RATE_36MB: |
| 362 | return ZD_OFDM_RATE_36M; |
| 363 | case IEEE80211_OFDM_RATE_48MB: |
| 364 | return ZD_OFDM_RATE_48M; |
| 365 | case IEEE80211_OFDM_RATE_54MB: |
| 366 | return ZD_OFDM_RATE_54M; |
| 367 | } |
| 368 | return ZD_CCK_RATE_1M; |
| 369 | } |
| 370 | |
| 371 | static u16 rate_to_cr_rate(u8 rate) |
| 372 | { |
| 373 | switch (rate) { |
| 374 | case IEEE80211_CCK_RATE_2MB: |
| 375 | return CR_RATE_1M; |
| 376 | case IEEE80211_CCK_RATE_5MB: |
| 377 | return CR_RATE_5_5M; |
| 378 | case IEEE80211_CCK_RATE_11MB: |
| 379 | return CR_RATE_11M; |
| 380 | case IEEE80211_OFDM_RATE_6MB: |
| 381 | return CR_RATE_6M; |
| 382 | case IEEE80211_OFDM_RATE_9MB: |
| 383 | return CR_RATE_9M; |
| 384 | case IEEE80211_OFDM_RATE_12MB: |
| 385 | return CR_RATE_12M; |
| 386 | case IEEE80211_OFDM_RATE_18MB: |
| 387 | return CR_RATE_18M; |
| 388 | case IEEE80211_OFDM_RATE_24MB: |
| 389 | return CR_RATE_24M; |
| 390 | case IEEE80211_OFDM_RATE_36MB: |
| 391 | return CR_RATE_36M; |
| 392 | case IEEE80211_OFDM_RATE_48MB: |
| 393 | return CR_RATE_48M; |
| 394 | case IEEE80211_OFDM_RATE_54MB: |
| 395 | return CR_RATE_54M; |
| 396 | } |
| 397 | return CR_RATE_1M; |
| 398 | } |
| 399 | |
| 400 | static void try_enable_tx(struct zd_mac *mac) |
| 401 | { |
| 402 | unsigned long flags; |
| 403 | |
| 404 | spin_lock_irqsave(&mac->lock, flags); |
| 405 | if (mac->updating_rts_rate == 0 && mac->updating_basic_rates == 0) |
| 406 | netif_wake_queue(mac->netdev); |
| 407 | spin_unlock_irqrestore(&mac->lock, flags); |
| 408 | } |
| 409 | |
| 410 | static void set_rts_cts_work(void *d) |
| 411 | { |
| 412 | struct zd_mac *mac = d; |
| 413 | unsigned long flags; |
| 414 | u8 rts_rate; |
| 415 | unsigned int short_preamble; |
| 416 | |
| 417 | mutex_lock(&mac->chip.mutex); |
| 418 | |
| 419 | spin_lock_irqsave(&mac->lock, flags); |
| 420 | mac->updating_rts_rate = 0; |
| 421 | rts_rate = mac->rts_rate; |
| 422 | short_preamble = mac->short_preamble; |
| 423 | spin_unlock_irqrestore(&mac->lock, flags); |
| 424 | |
| 425 | zd_chip_set_rts_cts_rate_locked(&mac->chip, rts_rate, short_preamble); |
| 426 | mutex_unlock(&mac->chip.mutex); |
| 427 | |
| 428 | try_enable_tx(mac); |
| 429 | } |
| 430 | |
| 431 | static void set_basic_rates_work(void *d) |
| 432 | { |
| 433 | struct zd_mac *mac = d; |
| 434 | unsigned long flags; |
| 435 | u16 basic_rates; |
| 436 | |
| 437 | mutex_lock(&mac->chip.mutex); |
| 438 | |
| 439 | spin_lock_irqsave(&mac->lock, flags); |
| 440 | mac->updating_basic_rates = 0; |
| 441 | basic_rates = mac->basic_rates; |
| 442 | spin_unlock_irqrestore(&mac->lock, flags); |
| 443 | |
| 444 | zd_chip_set_basic_rates_locked(&mac->chip, basic_rates); |
| 445 | mutex_unlock(&mac->chip.mutex); |
| 446 | |
| 447 | try_enable_tx(mac); |
| 448 | } |
| 449 | |
| 450 | static void bssinfo_change(struct net_device *netdev, u32 changes) |
| 451 | { |
| 452 | struct zd_mac *mac = zd_netdev_mac(netdev); |
| 453 | struct ieee80211softmac_device *softmac = ieee80211_priv(netdev); |
| 454 | struct ieee80211softmac_bss_info *bssinfo = &softmac->bssinfo; |
| 455 | int need_set_rts_cts = 0; |
| 456 | int need_set_rates = 0; |
| 457 | u16 basic_rates; |
| 458 | unsigned long flags; |
| 459 | |
| 460 | dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes); |
| 461 | |
| 462 | if (changes & IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE) { |
| 463 | spin_lock_irqsave(&mac->lock, flags); |
| 464 | mac->short_preamble = bssinfo->short_preamble; |
| 465 | spin_unlock_irqrestore(&mac->lock, flags); |
| 466 | need_set_rts_cts = 1; |
| 467 | } |
| 468 | |
| 469 | if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) { |
| 470 | /* Set RTS rate to highest available basic rate */ |
| 471 | u8 rate = ieee80211softmac_highest_supported_rate(softmac, |
| 472 | &bssinfo->supported_rates, 1); |
| 473 | rate = rate_to_zd_rate(rate); |
| 474 | |
| 475 | spin_lock_irqsave(&mac->lock, flags); |
| 476 | if (rate != mac->rts_rate) { |
| 477 | mac->rts_rate = rate; |
| 478 | need_set_rts_cts = 1; |
| 479 | } |
| 480 | spin_unlock_irqrestore(&mac->lock, flags); |
| 481 | |
| 482 | /* Set basic rates */ |
| 483 | need_set_rates = 1; |
| 484 | if (bssinfo->supported_rates.count == 0) { |
| 485 | /* Allow the device to be flexible */ |
| 486 | basic_rates = CR_RATES_80211B | CR_RATES_80211G; |
| 487 | } else { |
| 488 | int i = 0; |
| 489 | basic_rates = 0; |
| 490 | |
| 491 | for (i = 0; i < bssinfo->supported_rates.count; i++) { |
| 492 | u16 rate = bssinfo->supported_rates.rates[i]; |
| 493 | if ((rate & IEEE80211_BASIC_RATE_MASK) == 0) |
| 494 | continue; |
| 495 | |
| 496 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 497 | basic_rates |= rate_to_cr_rate(rate); |
| 498 | } |
| 499 | } |
| 500 | spin_lock_irqsave(&mac->lock, flags); |
| 501 | mac->basic_rates = basic_rates; |
| 502 | spin_unlock_irqrestore(&mac->lock, flags); |
| 503 | } |
| 504 | |
| 505 | /* Schedule any changes we made above */ |
| 506 | |
| 507 | spin_lock_irqsave(&mac->lock, flags); |
| 508 | if (need_set_rts_cts && !mac->updating_rts_rate) { |
| 509 | mac->updating_rts_rate = 1; |
| 510 | netif_stop_queue(mac->netdev); |
| 511 | queue_work(zd_workqueue, &mac->set_rts_cts_work); |
| 512 | } |
| 513 | if (need_set_rates && !mac->updating_basic_rates) { |
| 514 | mac->updating_basic_rates = 1; |
| 515 | netif_stop_queue(mac->netdev); |
| 516 | queue_work(zd_workqueue, &mac->set_basic_rates_work); |
| 517 | } |
| 518 | spin_unlock_irqrestore(&mac->lock, flags); |
| 519 | } |
| 520 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 521 | static void set_channel(struct net_device *netdev, u8 channel) |
| 522 | { |
| 523 | struct zd_mac *mac = zd_netdev_mac(netdev); |
| 524 | |
| 525 | dev_dbg_f(zd_mac_dev(mac), "channel %d\n", channel); |
| 526 | |
| 527 | zd_chip_set_channel(&mac->chip, channel); |
| 528 | } |
| 529 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 530 | int zd_mac_request_channel(struct zd_mac *mac, u8 channel) |
| 531 | { |
| 532 | unsigned long lock_flags; |
| 533 | struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); |
| 534 | |
| 535 | if (ieee->iw_mode == IW_MODE_INFRA) |
| 536 | return -EPERM; |
| 537 | |
| 538 | spin_lock_irqsave(&mac->lock, lock_flags); |
| 539 | if (!zd_regdomain_supports_channel(mac->regdomain, channel)) { |
| 540 | spin_unlock_irqrestore(&mac->lock, lock_flags); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | mac->requested_channel = channel; |
| 544 | spin_unlock_irqrestore(&mac->lock, lock_flags); |
| 545 | if (netif_running(mac->netdev)) |
| 546 | return zd_chip_set_channel(&mac->chip, channel); |
| 547 | else |
| 548 | return 0; |
| 549 | } |
| 550 | |
Daniel Drake | 84bc715 | 2006-11-22 00:05:30 +0000 | [diff] [blame] | 551 | u8 zd_mac_get_channel(struct zd_mac *mac) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 552 | { |
Daniel Drake | 84bc715 | 2006-11-22 00:05:30 +0000 | [diff] [blame] | 553 | u8 channel = zd_chip_get_channel(&mac->chip); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 554 | |
Daniel Drake | 84bc715 | 2006-11-22 00:05:30 +0000 | [diff] [blame] | 555 | dev_dbg_f(zd_mac_dev(mac), "channel %u\n", channel); |
| 556 | return channel; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* If wrong rate is given, we are falling back to the slowest rate: 1MBit/s */ |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 560 | static u8 zd_rate_typed(u8 zd_rate) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 561 | { |
| 562 | static const u8 typed_rates[16] = { |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 563 | [ZD_CCK_RATE_1M] = ZD_CS_CCK|ZD_CCK_RATE_1M, |
| 564 | [ZD_CCK_RATE_2M] = ZD_CS_CCK|ZD_CCK_RATE_2M, |
| 565 | [ZD_CCK_RATE_5_5M] = ZD_CS_CCK|ZD_CCK_RATE_5_5M, |
| 566 | [ZD_CCK_RATE_11M] = ZD_CS_CCK|ZD_CCK_RATE_11M, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 567 | [ZD_OFDM_RATE_6M] = ZD_CS_OFDM|ZD_OFDM_RATE_6M, |
| 568 | [ZD_OFDM_RATE_9M] = ZD_CS_OFDM|ZD_OFDM_RATE_9M, |
| 569 | [ZD_OFDM_RATE_12M] = ZD_CS_OFDM|ZD_OFDM_RATE_12M, |
| 570 | [ZD_OFDM_RATE_18M] = ZD_CS_OFDM|ZD_OFDM_RATE_18M, |
| 571 | [ZD_OFDM_RATE_24M] = ZD_CS_OFDM|ZD_OFDM_RATE_24M, |
| 572 | [ZD_OFDM_RATE_36M] = ZD_CS_OFDM|ZD_OFDM_RATE_36M, |
| 573 | [ZD_OFDM_RATE_48M] = ZD_CS_OFDM|ZD_OFDM_RATE_48M, |
| 574 | [ZD_OFDM_RATE_54M] = ZD_CS_OFDM|ZD_OFDM_RATE_54M, |
| 575 | }; |
| 576 | |
| 577 | ZD_ASSERT(ZD_CS_RATE_MASK == 0x0f); |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 578 | return typed_rates[zd_rate & ZD_CS_RATE_MASK]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 581 | int zd_mac_set_mode(struct zd_mac *mac, u32 mode) |
| 582 | { |
| 583 | struct ieee80211_device *ieee; |
| 584 | |
| 585 | switch (mode) { |
| 586 | case IW_MODE_AUTO: |
| 587 | case IW_MODE_ADHOC: |
| 588 | case IW_MODE_INFRA: |
| 589 | mac->netdev->type = ARPHRD_ETHER; |
| 590 | break; |
| 591 | case IW_MODE_MONITOR: |
| 592 | mac->netdev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 593 | break; |
| 594 | default: |
| 595 | dev_dbg_f(zd_mac_dev(mac), "wrong mode %u\n", mode); |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | |
| 599 | ieee = zd_mac_to_ieee80211(mac); |
| 600 | ZD_ASSERT(!irqs_disabled()); |
| 601 | spin_lock_irq(&ieee->lock); |
| 602 | ieee->iw_mode = mode; |
| 603 | spin_unlock_irq(&ieee->lock); |
| 604 | |
| 605 | if (netif_running(mac->netdev)) |
| 606 | return reset_mode(mac); |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | int zd_mac_get_mode(struct zd_mac *mac, u32 *mode) |
| 612 | { |
| 613 | unsigned long flags; |
| 614 | struct ieee80211_device *ieee; |
| 615 | |
| 616 | ieee = zd_mac_to_ieee80211(mac); |
| 617 | spin_lock_irqsave(&ieee->lock, flags); |
| 618 | *mode = ieee->iw_mode; |
| 619 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range) |
| 624 | { |
| 625 | int i; |
| 626 | const struct channel_range *channel_range; |
| 627 | u8 regdomain; |
| 628 | |
| 629 | memset(range, 0, sizeof(*range)); |
| 630 | |
| 631 | /* FIXME: Not so important and depends on the mode. For 802.11g |
| 632 | * usually this value is used. It seems to be that Bit/s number is |
| 633 | * given here. |
| 634 | */ |
| 635 | range->throughput = 27 * 1000 * 1000; |
| 636 | |
| 637 | range->max_qual.qual = 100; |
| 638 | range->max_qual.level = 100; |
| 639 | |
| 640 | /* FIXME: Needs still to be tuned. */ |
| 641 | range->avg_qual.qual = 71; |
| 642 | range->avg_qual.level = 80; |
| 643 | |
| 644 | /* FIXME: depends on standard? */ |
| 645 | range->min_rts = 256; |
| 646 | range->max_rts = 2346; |
| 647 | |
| 648 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 649 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 650 | |
| 651 | range->max_encoding_tokens = WEP_KEYS; |
| 652 | range->num_encoding_sizes = 2; |
| 653 | range->encoding_size[0] = 5; |
| 654 | range->encoding_size[1] = WEP_KEY_LEN; |
| 655 | |
| 656 | range->we_version_compiled = WIRELESS_EXT; |
| 657 | range->we_version_source = 20; |
| 658 | |
Daniel Drake | ff9b99b | 2006-12-01 00:57:11 +0000 | [diff] [blame] | 659 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 660 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 661 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 662 | ZD_ASSERT(!irqs_disabled()); |
| 663 | spin_lock_irq(&mac->lock); |
| 664 | regdomain = mac->regdomain; |
| 665 | spin_unlock_irq(&mac->lock); |
| 666 | channel_range = zd_channel_range(regdomain); |
| 667 | |
| 668 | range->num_channels = channel_range->end - channel_range->start; |
| 669 | range->old_num_channels = range->num_channels; |
| 670 | range->num_frequency = range->num_channels; |
| 671 | range->old_num_frequency = range->num_frequency; |
| 672 | |
| 673 | for (i = 0; i < range->num_frequency; i++) { |
| 674 | struct iw_freq *freq = &range->freq[i]; |
| 675 | freq->i = channel_range->start + i; |
| 676 | zd_channel_to_freq(freq, freq->i); |
| 677 | } |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 682 | 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] | 683 | { |
| 684 | static const u8 rate_divisor[] = { |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 685 | [ZD_CCK_RATE_1M] = 1, |
| 686 | [ZD_CCK_RATE_2M] = 2, |
| 687 | [ZD_CCK_RATE_5_5M] = 11, /* bits must be doubled */ |
| 688 | [ZD_CCK_RATE_11M] = 11, |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 689 | [ZD_OFDM_RATE_6M] = 6, |
| 690 | [ZD_OFDM_RATE_9M] = 9, |
| 691 | [ZD_OFDM_RATE_12M] = 12, |
| 692 | [ZD_OFDM_RATE_18M] = 18, |
| 693 | [ZD_OFDM_RATE_24M] = 24, |
| 694 | [ZD_OFDM_RATE_36M] = 36, |
| 695 | [ZD_OFDM_RATE_48M] = 48, |
| 696 | [ZD_OFDM_RATE_54M] = 54, |
| 697 | }; |
| 698 | |
| 699 | u32 bits = (u32)tx_length * 8; |
| 700 | u32 divisor; |
| 701 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 702 | divisor = rate_divisor[zd_rate]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 703 | if (divisor == 0) |
| 704 | return -EINVAL; |
| 705 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 706 | switch (zd_rate) { |
| 707 | case ZD_CCK_RATE_5_5M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 708 | bits = (2*bits) + 10; /* round up to the next integer */ |
| 709 | break; |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 710 | case ZD_CCK_RATE_11M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 711 | if (service) { |
| 712 | u32 t = bits % 11; |
| 713 | *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 714 | if (0 < t && t <= 3) { |
| 715 | *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION; |
| 716 | } |
| 717 | } |
| 718 | bits += 10; /* round up to the next integer */ |
| 719 | break; |
| 720 | } |
| 721 | |
| 722 | return bits/divisor; |
| 723 | } |
| 724 | |
| 725 | enum { |
| 726 | R2M_SHORT_PREAMBLE = 0x01, |
| 727 | R2M_11A = 0x02, |
| 728 | }; |
| 729 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 730 | static u8 zd_rate_to_modulation(u8 zd_rate, int flags) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 731 | { |
| 732 | u8 modulation; |
| 733 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 734 | modulation = zd_rate_typed(zd_rate); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 735 | if (flags & R2M_SHORT_PREAMBLE) { |
| 736 | switch (ZD_CS_RATE(modulation)) { |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 737 | case ZD_CCK_RATE_2M: |
| 738 | case ZD_CCK_RATE_5_5M: |
| 739 | case ZD_CCK_RATE_11M: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 740 | modulation |= ZD_CS_CCK_PREA_SHORT; |
| 741 | return modulation; |
| 742 | } |
| 743 | } |
| 744 | if (flags & R2M_11A) { |
| 745 | if (ZD_CS_TYPE(modulation) == ZD_CS_OFDM) |
| 746 | modulation |= ZD_CS_OFDM_MODE_11A; |
| 747 | } |
| 748 | return modulation; |
| 749 | } |
| 750 | |
| 751 | static void cs_set_modulation(struct zd_mac *mac, struct zd_ctrlset *cs, |
| 752 | struct ieee80211_hdr_4addr *hdr) |
| 753 | { |
| 754 | struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev); |
| 755 | u16 ftype = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_ctl)); |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 756 | u8 rate, zd_rate; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 757 | int is_mgt = (ftype == IEEE80211_FTYPE_MGMT) != 0; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 758 | int is_multicast = is_multicast_ether_addr(hdr->addr1); |
| 759 | int short_preamble = ieee80211softmac_short_preamble_ok(softmac, |
| 760 | is_multicast, is_mgt); |
| 761 | int flags = 0; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 762 | |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 763 | /* FIXME: 802.11a? */ |
| 764 | rate = ieee80211softmac_suggest_txrate(softmac, is_multicast, is_mgt); |
| 765 | |
| 766 | if (short_preamble) |
| 767 | flags |= R2M_SHORT_PREAMBLE; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 768 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 769 | zd_rate = rate_to_zd_rate(rate); |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 770 | cs->modulation = zd_rate_to_modulation(zd_rate, flags); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs, |
| 774 | struct ieee80211_hdr_4addr *header) |
| 775 | { |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 776 | struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 777 | unsigned int tx_length = le16_to_cpu(cs->tx_length); |
| 778 | u16 fctl = le16_to_cpu(header->frame_ctl); |
| 779 | u16 ftype = WLAN_FC_GET_TYPE(fctl); |
| 780 | u16 stype = WLAN_FC_GET_STYPE(fctl); |
| 781 | |
| 782 | /* |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 783 | * CONTROL TODO: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 784 | * - if backoff needed, enable bit 0 |
| 785 | * - if burst (backoff not needed) disable bit 0 |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 786 | */ |
| 787 | |
| 788 | cs->control = 0; |
| 789 | |
| 790 | /* First fragment */ |
| 791 | if (WLAN_GET_SEQ_FRAG(le16_to_cpu(header->seq_ctl)) == 0) |
| 792 | cs->control |= ZD_CS_NEED_RANDOM_BACKOFF; |
| 793 | |
| 794 | /* Multicast */ |
| 795 | if (is_multicast_ether_addr(header->addr1)) |
| 796 | cs->control |= ZD_CS_MULTICAST; |
| 797 | |
| 798 | /* PS-POLL */ |
| 799 | if (stype == IEEE80211_STYPE_PSPOLL) |
| 800 | cs->control |= ZD_CS_PS_POLL_FRAME; |
| 801 | |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 802 | /* Unicast data frames over the threshold should have RTS */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 803 | if (!is_multicast_ether_addr(header->addr1) && |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 804 | ftype != IEEE80211_FTYPE_MGMT && |
| 805 | tx_length > zd_netdev_ieee80211(mac->netdev)->rts) |
| 806 | cs->control |= ZD_CS_RTS; |
| 807 | |
| 808 | /* Use CTS-to-self protection if required */ |
| 809 | if (ZD_CS_TYPE(cs->modulation) == ZD_CS_OFDM && |
| 810 | ieee80211softmac_protection_needed(softmac)) { |
| 811 | /* FIXME: avoid sending RTS *and* self-CTS, is that correct? */ |
| 812 | cs->control &= ~ZD_CS_RTS; |
| 813 | cs->control |= ZD_CS_SELF_CTS; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /* FIXME: Management frame? */ |
| 817 | } |
| 818 | |
| 819 | static int fill_ctrlset(struct zd_mac *mac, |
| 820 | struct ieee80211_txb *txb, |
| 821 | int frag_num) |
| 822 | { |
| 823 | int r; |
| 824 | struct sk_buff *skb = txb->fragments[frag_num]; |
| 825 | struct ieee80211_hdr_4addr *hdr = |
| 826 | (struct ieee80211_hdr_4addr *) skb->data; |
| 827 | unsigned int frag_len = skb->len + IEEE80211_FCS_LEN; |
| 828 | unsigned int next_frag_len; |
| 829 | unsigned int packet_length; |
| 830 | struct zd_ctrlset *cs = (struct zd_ctrlset *) |
| 831 | skb_push(skb, sizeof(struct zd_ctrlset)); |
| 832 | |
| 833 | if (frag_num+1 < txb->nr_frags) { |
| 834 | next_frag_len = txb->fragments[frag_num+1]->len + |
| 835 | IEEE80211_FCS_LEN; |
| 836 | } else { |
| 837 | next_frag_len = 0; |
| 838 | } |
| 839 | ZD_ASSERT(frag_len <= 0xffff); |
| 840 | ZD_ASSERT(next_frag_len <= 0xffff); |
| 841 | |
| 842 | cs_set_modulation(mac, cs, hdr); |
| 843 | |
| 844 | cs->tx_length = cpu_to_le16(frag_len); |
| 845 | |
| 846 | cs_set_control(mac, cs, hdr); |
| 847 | |
| 848 | packet_length = frag_len + sizeof(struct zd_ctrlset) + 10; |
| 849 | ZD_ASSERT(packet_length <= 0xffff); |
| 850 | /* ZD1211B: Computing the length difference this way, gives us |
| 851 | * flexibility to compute the packet length. |
| 852 | */ |
| 853 | cs->packet_length = cpu_to_le16(mac->chip.is_zd1211b ? |
| 854 | packet_length - frag_len : packet_length); |
| 855 | |
| 856 | /* |
| 857 | * CURRENT LENGTH: |
| 858 | * - transmit frame length in microseconds |
| 859 | * - seems to be derived from frame length |
| 860 | * - see Cal_Us_Service() in zdinlinef.h |
| 861 | * - if macp->bTxBurstEnable is enabled, then multiply by 4 |
| 862 | * - bTxBurstEnable is never set in the vendor driver |
| 863 | * |
| 864 | * SERVICE: |
| 865 | * - "for PLCP configuration" |
| 866 | * - always 0 except in some situations at 802.11b 11M |
| 867 | * - see line 53 of zdinlinef.h |
| 868 | */ |
| 869 | cs->service = 0; |
| 870 | r = zd_calc_tx_length_us(&cs->service, ZD_CS_RATE(cs->modulation), |
| 871 | le16_to_cpu(cs->tx_length)); |
| 872 | if (r < 0) |
| 873 | return r; |
| 874 | cs->current_length = cpu_to_le16(r); |
| 875 | |
| 876 | if (next_frag_len == 0) { |
| 877 | cs->next_frame_length = 0; |
| 878 | } else { |
| 879 | r = zd_calc_tx_length_us(NULL, ZD_CS_RATE(cs->modulation), |
| 880 | next_frag_len); |
| 881 | if (r < 0) |
| 882 | return r; |
| 883 | cs->next_frame_length = cpu_to_le16(r); |
| 884 | } |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri) |
| 890 | { |
| 891 | int i, r; |
| 892 | |
| 893 | for (i = 0; i < txb->nr_frags; i++) { |
| 894 | struct sk_buff *skb = txb->fragments[i]; |
| 895 | |
| 896 | r = fill_ctrlset(mac, txb, i); |
| 897 | if (r) |
| 898 | return r; |
| 899 | r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len); |
| 900 | if (r) |
| 901 | return r; |
| 902 | } |
| 903 | |
| 904 | /* FIXME: shouldn't this be handled by the upper layers? */ |
| 905 | mac->netdev->trans_start = jiffies; |
| 906 | |
| 907 | ieee80211_txb_free(txb); |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | struct zd_rt_hdr { |
| 912 | struct ieee80211_radiotap_header rt_hdr; |
| 913 | u8 rt_flags; |
Ulrich Kunitz | 99f65f2 | 2006-08-01 23:43:30 +0200 | [diff] [blame] | 914 | u8 rt_rate; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 915 | u16 rt_channel; |
| 916 | u16 rt_chbitmask; |
John W. Linville | a88556a | 2006-11-28 14:16:37 -0500 | [diff] [blame] | 917 | } __attribute__((packed)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 918 | |
| 919 | static void fill_rt_header(void *buffer, struct zd_mac *mac, |
| 920 | const struct ieee80211_rx_stats *stats, |
| 921 | const struct rx_status *status) |
| 922 | { |
| 923 | struct zd_rt_hdr *hdr = buffer; |
| 924 | |
| 925 | hdr->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 926 | hdr->rt_hdr.it_pad = 0; |
| 927 | hdr->rt_hdr.it_len = cpu_to_le16(sizeof(struct zd_rt_hdr)); |
| 928 | hdr->rt_hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 929 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 930 | (1 << IEEE80211_RADIOTAP_RATE)); |
| 931 | |
| 932 | hdr->rt_flags = 0; |
| 933 | if (status->decryption_type & (ZD_RX_WEP64|ZD_RX_WEP128|ZD_RX_WEP256)) |
| 934 | hdr->rt_flags |= IEEE80211_RADIOTAP_F_WEP; |
| 935 | |
Ulrich Kunitz | 99f65f2 | 2006-08-01 23:43:30 +0200 | [diff] [blame] | 936 | hdr->rt_rate = stats->rate / 5; |
| 937 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 938 | /* FIXME: 802.11a */ |
| 939 | hdr->rt_channel = cpu_to_le16(ieee80211chan2mhz( |
| 940 | _zd_chip_get_channel(&mac->chip))); |
| 941 | hdr->rt_chbitmask = cpu_to_le16(IEEE80211_CHAN_2GHZ | |
| 942 | ((status->frame_status & ZD_RX_FRAME_MODULATION_MASK) == |
| 943 | ZD_RX_OFDM ? IEEE80211_CHAN_OFDM : IEEE80211_CHAN_CCK)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | /* Returns 1 if the data packet is for us and 0 otherwise. */ |
| 947 | static int is_data_packet_for_us(struct ieee80211_device *ieee, |
| 948 | struct ieee80211_hdr_4addr *hdr) |
| 949 | { |
| 950 | struct net_device *netdev = ieee->dev; |
| 951 | u16 fc = le16_to_cpu(hdr->frame_ctl); |
| 952 | |
| 953 | ZD_ASSERT(WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA); |
| 954 | |
| 955 | switch (ieee->iw_mode) { |
| 956 | case IW_MODE_ADHOC: |
| 957 | if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != 0 || |
| 958 | memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) != 0) |
| 959 | return 0; |
| 960 | break; |
| 961 | case IW_MODE_AUTO: |
| 962 | case IW_MODE_INFRA: |
| 963 | if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != |
| 964 | IEEE80211_FCTL_FROMDS || |
| 965 | memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) != 0) |
| 966 | return 0; |
| 967 | break; |
| 968 | default: |
| 969 | ZD_ASSERT(ieee->iw_mode != IW_MODE_MONITOR); |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | return memcmp(hdr->addr1, netdev->dev_addr, ETH_ALEN) == 0 || |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 974 | (is_multicast_ether_addr(hdr->addr1) && |
| 975 | memcmp(hdr->addr3, netdev->dev_addr, ETH_ALEN) != 0) || |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 976 | (netdev->flags & IFF_PROMISC); |
| 977 | } |
| 978 | |
Ulrich Kunitz | 741fec5 | 2006-11-22 00:05:53 +0000 | [diff] [blame] | 979 | /* Filters received packets. The function returns 1 if the packet should be |
| 980 | * forwarded to ieee80211_rx(). If the packet should be ignored the function |
| 981 | * returns 0. If an invalid packet is found the function returns -EINVAL. |
| 982 | * |
| 983 | * The function calls ieee80211_rx_mgt() directly. |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 984 | * |
| 985 | * It has been based on ieee80211_rx_any. |
| 986 | */ |
| 987 | static int filter_rx(struct ieee80211_device *ieee, |
| 988 | const u8 *buffer, unsigned int length, |
| 989 | struct ieee80211_rx_stats *stats) |
| 990 | { |
| 991 | struct ieee80211_hdr_4addr *hdr; |
| 992 | u16 fc; |
| 993 | |
| 994 | if (ieee->iw_mode == IW_MODE_MONITOR) |
| 995 | return 1; |
| 996 | |
| 997 | hdr = (struct ieee80211_hdr_4addr *)buffer; |
| 998 | fc = le16_to_cpu(hdr->frame_ctl); |
| 999 | if ((fc & IEEE80211_FCTL_VERS) != 0) |
| 1000 | return -EINVAL; |
| 1001 | |
| 1002 | switch (WLAN_FC_GET_TYPE(fc)) { |
| 1003 | case IEEE80211_FTYPE_MGMT: |
| 1004 | if (length < sizeof(struct ieee80211_hdr_3addr)) |
| 1005 | return -EINVAL; |
| 1006 | ieee80211_rx_mgt(ieee, hdr, stats); |
| 1007 | return 0; |
| 1008 | case IEEE80211_FTYPE_CTL: |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1009 | return 0; |
| 1010 | case IEEE80211_FTYPE_DATA: |
Ulrich Kunitz | 741fec5 | 2006-11-22 00:05:53 +0000 | [diff] [blame] | 1011 | /* Ignore invalid short buffers */ |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1012 | if (length < sizeof(struct ieee80211_hdr_3addr)) |
| 1013 | return -EINVAL; |
| 1014 | return is_data_packet_for_us(ieee, hdr); |
| 1015 | } |
| 1016 | |
| 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1020 | static void update_qual_rssi(struct zd_mac *mac, |
| 1021 | const u8 *buffer, unsigned int length, |
| 1022 | u8 qual_percent, u8 rssi_percent) |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1023 | { |
| 1024 | unsigned long flags; |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1025 | struct ieee80211_hdr_3addr *hdr; |
| 1026 | int i; |
| 1027 | |
| 1028 | hdr = (struct ieee80211_hdr_3addr *)buffer; |
| 1029 | if (length < offsetof(struct ieee80211_hdr_3addr, addr3)) |
| 1030 | return; |
| 1031 | if (memcmp(hdr->addr2, zd_mac_to_ieee80211(mac)->bssid, ETH_ALEN) != 0) |
| 1032 | return; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1033 | |
| 1034 | spin_lock_irqsave(&mac->lock, flags); |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1035 | i = mac->stats_count % ZD_MAC_STATS_BUFFER_SIZE; |
| 1036 | mac->qual_buffer[i] = qual_percent; |
| 1037 | mac->rssi_buffer[i] = rssi_percent; |
| 1038 | mac->stats_count++; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1039 | spin_unlock_irqrestore(&mac->lock, flags); |
| 1040 | } |
| 1041 | |
| 1042 | static int fill_rx_stats(struct ieee80211_rx_stats *stats, |
| 1043 | const struct rx_status **pstatus, |
| 1044 | struct zd_mac *mac, |
| 1045 | const u8 *buffer, unsigned int length) |
| 1046 | { |
| 1047 | const struct rx_status *status; |
| 1048 | |
| 1049 | *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status)); |
| 1050 | if (status->frame_status & ZD_RX_ERROR) { |
| 1051 | /* FIXME: update? */ |
| 1052 | return -EINVAL; |
| 1053 | } |
| 1054 | memset(stats, 0, sizeof(struct ieee80211_rx_stats)); |
| 1055 | stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN + |
| 1056 | + sizeof(struct rx_status)); |
| 1057 | /* FIXME: 802.11a */ |
| 1058 | stats->freq = IEEE80211_24GHZ_BAND; |
| 1059 | stats->received_channel = _zd_chip_get_channel(&mac->chip); |
| 1060 | stats->rssi = zd_rx_strength_percent(status->signal_strength); |
| 1061 | stats->signal = zd_rx_qual_percent(buffer, |
| 1062 | length - sizeof(struct rx_status), |
| 1063 | status); |
| 1064 | stats->mask = IEEE80211_STATMASK_RSSI | IEEE80211_STATMASK_SIGNAL; |
| 1065 | stats->rate = zd_rx_rate(buffer, status); |
| 1066 | if (stats->rate) |
| 1067 | stats->mask |= IEEE80211_STATMASK_RATE; |
| 1068 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length) |
| 1073 | { |
| 1074 | int r; |
| 1075 | struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); |
| 1076 | struct ieee80211_rx_stats stats; |
| 1077 | const struct rx_status *status; |
| 1078 | struct sk_buff *skb; |
| 1079 | |
| 1080 | if (length < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + |
| 1081 | IEEE80211_FCS_LEN + sizeof(struct rx_status)) |
| 1082 | return -EINVAL; |
| 1083 | |
| 1084 | r = fill_rx_stats(&stats, &status, mac, buffer, length); |
| 1085 | if (r) |
| 1086 | return r; |
| 1087 | |
| 1088 | length -= ZD_PLCP_HEADER_SIZE+IEEE80211_FCS_LEN+ |
| 1089 | sizeof(struct rx_status); |
| 1090 | buffer += ZD_PLCP_HEADER_SIZE; |
| 1091 | |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1092 | update_qual_rssi(mac, buffer, length, stats.signal, stats.rssi); |
| 1093 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1094 | r = filter_rx(ieee, buffer, length, &stats); |
| 1095 | if (r <= 0) |
| 1096 | return r; |
| 1097 | |
| 1098 | skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length); |
| 1099 | if (!skb) |
| 1100 | return -ENOMEM; |
| 1101 | if (ieee->iw_mode == IW_MODE_MONITOR) |
| 1102 | fill_rt_header(skb_put(skb, sizeof(struct zd_rt_hdr)), mac, |
| 1103 | &stats, status); |
| 1104 | memcpy(skb_put(skb, length), buffer, length); |
| 1105 | |
| 1106 | r = ieee80211_rx(ieee, skb, &stats); |
Daniel Drake | 383956a | 2006-12-01 00:56:50 +0000 | [diff] [blame] | 1107 | if (!r) |
| 1108 | dev_kfree_skb_any(skb); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static int netdev_tx(struct ieee80211_txb *txb, struct net_device *netdev, |
| 1113 | int pri) |
| 1114 | { |
| 1115 | return zd_mac_tx(zd_netdev_mac(netdev), txb, pri); |
| 1116 | } |
| 1117 | |
| 1118 | static void set_security(struct net_device *netdev, |
| 1119 | struct ieee80211_security *sec) |
| 1120 | { |
| 1121 | struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev); |
| 1122 | struct ieee80211_security *secinfo = &ieee->sec; |
| 1123 | int keyidx; |
| 1124 | |
| 1125 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), "\n"); |
| 1126 | |
| 1127 | for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) |
| 1128 | if (sec->flags & (1<<keyidx)) { |
| 1129 | secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx]; |
| 1130 | secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx]; |
| 1131 | memcpy(secinfo->keys[keyidx], sec->keys[keyidx], |
| 1132 | SCM_KEY_LEN); |
| 1133 | } |
| 1134 | |
| 1135 | if (sec->flags & SEC_ACTIVE_KEY) { |
| 1136 | secinfo->active_key = sec->active_key; |
| 1137 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1138 | " .active_key = %d\n", sec->active_key); |
| 1139 | } |
| 1140 | if (sec->flags & SEC_UNICAST_GROUP) { |
| 1141 | secinfo->unicast_uses_group = sec->unicast_uses_group; |
| 1142 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1143 | " .unicast_uses_group = %d\n", |
| 1144 | sec->unicast_uses_group); |
| 1145 | } |
| 1146 | if (sec->flags & SEC_LEVEL) { |
| 1147 | secinfo->level = sec->level; |
| 1148 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1149 | " .level = %d\n", sec->level); |
| 1150 | } |
| 1151 | if (sec->flags & SEC_ENABLED) { |
| 1152 | secinfo->enabled = sec->enabled; |
| 1153 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1154 | " .enabled = %d\n", sec->enabled); |
| 1155 | } |
| 1156 | if (sec->flags & SEC_ENCRYPT) { |
| 1157 | secinfo->encrypt = sec->encrypt; |
| 1158 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1159 | " .encrypt = %d\n", sec->encrypt); |
| 1160 | } |
| 1161 | if (sec->flags & SEC_AUTH_MODE) { |
| 1162 | secinfo->auth_mode = sec->auth_mode; |
| 1163 | dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), |
| 1164 | " .auth_mode = %d\n", sec->auth_mode); |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | static void ieee_init(struct ieee80211_device *ieee) |
| 1169 | { |
| 1170 | ieee->mode = IEEE_B | IEEE_G; |
| 1171 | ieee->freq_band = IEEE80211_24GHZ_BAND; |
| 1172 | ieee->modulation = IEEE80211_OFDM_MODULATION | IEEE80211_CCK_MODULATION; |
| 1173 | ieee->tx_headroom = sizeof(struct zd_ctrlset); |
| 1174 | ieee->set_security = set_security; |
| 1175 | ieee->hard_start_xmit = netdev_tx; |
| 1176 | |
| 1177 | /* Software encryption/decryption for now */ |
| 1178 | ieee->host_build_iv = 0; |
| 1179 | ieee->host_encrypt = 1; |
| 1180 | ieee->host_decrypt = 1; |
| 1181 | |
| 1182 | /* FIXME: default to managed mode, until ieee80211 and zd1211rw can |
| 1183 | * correctly support AUTO */ |
| 1184 | ieee->iw_mode = IW_MODE_INFRA; |
| 1185 | } |
| 1186 | |
| 1187 | static void softmac_init(struct ieee80211softmac_device *sm) |
| 1188 | { |
| 1189 | sm->set_channel = set_channel; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 1190 | sm->bssinfo_change = bssinfo_change; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev) |
| 1194 | { |
| 1195 | struct zd_mac *mac = zd_netdev_mac(ndev); |
| 1196 | struct iw_statistics *iw_stats = &mac->iw_stats; |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1197 | unsigned int i, count, qual_total, rssi_total; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1198 | |
| 1199 | memset(iw_stats, 0, sizeof(struct iw_statistics)); |
| 1200 | /* We are not setting the status, because ieee->state is not updated |
| 1201 | * at all and this driver doesn't track authentication state. |
| 1202 | */ |
| 1203 | spin_lock_irq(&mac->lock); |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1204 | count = mac->stats_count < ZD_MAC_STATS_BUFFER_SIZE ? |
| 1205 | mac->stats_count : ZD_MAC_STATS_BUFFER_SIZE; |
| 1206 | qual_total = rssi_total = 0; |
| 1207 | for (i = 0; i < count; i++) { |
| 1208 | qual_total += mac->qual_buffer[i]; |
| 1209 | rssi_total += mac->rssi_buffer[i]; |
| 1210 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1211 | spin_unlock_irq(&mac->lock); |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1212 | iw_stats->qual.updated = IW_QUAL_NOISE_INVALID; |
| 1213 | if (count > 0) { |
| 1214 | iw_stats->qual.qual = qual_total / count; |
| 1215 | iw_stats->qual.level = rssi_total / count; |
| 1216 | iw_stats->qual.updated |= |
| 1217 | IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED; |
| 1218 | } else { |
| 1219 | iw_stats->qual.updated |= |
| 1220 | IW_QUAL_QUAL_INVALID|IW_QUAL_LEVEL_INVALID; |
| 1221 | } |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 1222 | /* TODO: update counter */ |
| 1223 | return iw_stats; |
| 1224 | } |
| 1225 | |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1226 | #define LINK_LED_WORK_DELAY HZ |
| 1227 | |
| 1228 | static void link_led_handler(void *p) |
| 1229 | { |
| 1230 | struct zd_mac *mac = p; |
| 1231 | struct zd_chip *chip = &mac->chip; |
| 1232 | struct ieee80211softmac_device *sm = ieee80211_priv(mac->netdev); |
| 1233 | int is_associated; |
| 1234 | int r; |
| 1235 | |
| 1236 | spin_lock_irq(&mac->lock); |
John W. Linville | 41072a1 | 2006-10-17 13:47:40 -0400 | [diff] [blame] | 1237 | is_associated = sm->associnfo.associated != 0; |
Ulrich Kunitz | 583afd1 | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 1238 | spin_unlock_irq(&mac->lock); |
| 1239 | |
| 1240 | r = zd_chip_control_leds(chip, |
| 1241 | is_associated ? LED_ASSOCIATED : LED_SCANNING); |
| 1242 | if (r) |
| 1243 | dev_err(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r); |
| 1244 | |
| 1245 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1246 | LINK_LED_WORK_DELAY); |
| 1247 | } |
| 1248 | |
| 1249 | static void housekeeping_init(struct zd_mac *mac) |
| 1250 | { |
| 1251 | INIT_WORK(&mac->housekeeping.link_led_work, link_led_handler, mac); |
| 1252 | } |
| 1253 | |
| 1254 | static void housekeeping_enable(struct zd_mac *mac) |
| 1255 | { |
| 1256 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1257 | queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, |
| 1258 | 0); |
| 1259 | } |
| 1260 | |
| 1261 | static void housekeeping_disable(struct zd_mac *mac) |
| 1262 | { |
| 1263 | dev_dbg_f(zd_mac_dev(mac), "\n"); |
| 1264 | cancel_rearming_delayed_workqueue(zd_workqueue, |
| 1265 | &mac->housekeeping.link_led_work); |
| 1266 | zd_chip_control_leds(&mac->chip, LED_OFF); |
| 1267 | } |