RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / net / wireless / zd1211rw / zd_mac.c
blob6753d240c16825f9c0b0c4801f2874e8b57c462f
1 /* zd_mac.c
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.
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.
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
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>
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"
33 static void ieee_init(struct ieee80211_device *ieee);
34 static void softmac_init(struct ieee80211softmac_device *sm);
35 static void set_rts_cts_work(struct work_struct *work);
36 static void set_basic_rates_work(struct work_struct *work);
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);
42 static void set_multicast_hash_handler(struct work_struct *work);
44 static void do_rx(unsigned long mac_ptr);
46 int zd_mac_init(struct zd_mac *mac,
47 struct net_device *netdev,
48 struct usb_interface *intf)
50 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
52 memset(mac, 0, sizeof(*mac));
53 spin_lock_init(&mac->lock);
54 mac->netdev = netdev;
55 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
56 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work);
58 skb_queue_head_init(&mac->rx_queue);
59 tasklet_init(&mac->rx_tasklet, do_rx, (unsigned long)mac);
60 tasklet_disable(&mac->rx_tasklet);
62 ieee_init(ieee);
63 softmac_init(ieee80211_priv(netdev));
64 zd_chip_init(&mac->chip, netdev, intf);
65 housekeeping_init(mac);
66 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
67 return 0;
70 static int reset_channel(struct zd_mac *mac)
72 int r;
73 unsigned long flags;
74 const struct channel_range *range;
76 spin_lock_irqsave(&mac->lock, flags);
77 range = zd_channel_range(mac->regdomain);
78 if (!range->start) {
79 r = -EINVAL;
80 goto out;
82 mac->requested_channel = range->start;
83 r = 0;
84 out:
85 spin_unlock_irqrestore(&mac->lock, flags);
86 return r;
89 int zd_mac_init_hw(struct zd_mac *mac, u8 device_type)
91 int r;
92 struct zd_chip *chip = &mac->chip;
93 u8 addr[ETH_ALEN];
94 u8 default_regdomain;
96 r = zd_chip_enable_int(chip);
97 if (r)
98 goto out;
99 r = zd_chip_init_hw(chip, device_type);
100 if (r)
101 goto disable_int;
103 zd_get_e2p_mac_addr(chip, addr);
104 r = zd_write_mac_addr(chip, addr);
105 if (r)
106 goto disable_int;
107 ZD_ASSERT(!irqs_disabled());
108 spin_lock_irq(&mac->lock);
109 memcpy(mac->netdev->dev_addr, addr, ETH_ALEN);
110 spin_unlock_irq(&mac->lock);
112 r = zd_read_regdomain(chip, &default_regdomain);
113 if (r)
114 goto disable_int;
115 if (!zd_regdomain_supported(default_regdomain)) {
116 dev_dbg_f(zd_mac_dev(mac),
117 "Regulatory Domain %#04x is not supported.\n",
118 default_regdomain);
119 r = -EINVAL;
120 goto disable_int;
122 spin_lock_irq(&mac->lock);
123 mac->regdomain = mac->default_regdomain = default_regdomain;
124 spin_unlock_irq(&mac->lock);
125 r = reset_channel(mac);
126 if (r)
127 goto disable_int;
129 /* We must inform the device that we are doing encryption/decryption in
130 * software at the moment. */
131 r = zd_set_encryption_type(chip, ENC_SNIFFER);
132 if (r)
133 goto disable_int;
135 r = zd_geo_init(zd_mac_to_ieee80211(mac), mac->regdomain);
136 if (r)
137 goto disable_int;
139 r = 0;
140 disable_int:
141 zd_chip_disable_int(chip);
142 out:
143 return r;
146 void zd_mac_clear(struct zd_mac *mac)
148 flush_workqueue(zd_workqueue);
149 skb_queue_purge(&mac->rx_queue);
150 tasklet_kill(&mac->rx_tasklet);
151 zd_chip_clear(&mac->chip);
152 ZD_ASSERT(!spin_is_locked(&mac->lock));
153 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
156 static int reset_mode(struct zd_mac *mac)
158 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
159 u32 filter = (ieee->iw_mode == IW_MODE_MONITOR) ? ~0 : STA_RX_FILTER;
160 return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
163 int zd_mac_open(struct net_device *netdev)
165 struct zd_mac *mac = zd_netdev_mac(netdev);
166 struct zd_chip *chip = &mac->chip;
167 int r;
169 tasklet_enable(&mac->rx_tasklet);
171 r = zd_chip_enable_int(chip);
172 if (r < 0)
173 goto out;
175 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
176 if (r < 0)
177 goto disable_int;
178 r = reset_mode(mac);
179 if (r)
180 goto disable_int;
181 r = zd_chip_switch_radio_on(chip);
182 if (r < 0)
183 goto disable_int;
184 r = zd_chip_set_channel(chip, mac->requested_channel);
185 if (r < 0)
186 goto disable_radio;
187 r = zd_chip_enable_rx(chip);
188 if (r < 0)
189 goto disable_radio;
190 r = zd_chip_enable_hwint(chip);
191 if (r < 0)
192 goto disable_rx;
194 housekeeping_enable(mac);
195 ieee80211softmac_start(netdev);
196 return 0;
197 disable_rx:
198 zd_chip_disable_rx(chip);
199 disable_radio:
200 zd_chip_switch_radio_off(chip);
201 disable_int:
202 zd_chip_disable_int(chip);
203 out:
204 return r;
207 int zd_mac_stop(struct net_device *netdev)
209 struct zd_mac *mac = zd_netdev_mac(netdev);
210 struct zd_chip *chip = &mac->chip;
212 netif_stop_queue(netdev);
215 * The order here deliberately is a little different from the open()
216 * method, since we need to make sure there is no opportunity for RX
217 * frames to be processed by softmac after we have stopped it.
220 zd_chip_disable_rx(chip);
221 skb_queue_purge(&mac->rx_queue);
222 tasklet_disable(&mac->rx_tasklet);
223 housekeeping_disable(mac);
224 ieee80211softmac_stop(netdev);
226 /* Ensure no work items are running or queued from this point */
227 cancel_delayed_work(&mac->set_rts_cts_work);
228 cancel_delayed_work(&mac->set_basic_rates_work);
229 flush_workqueue(zd_workqueue);
230 mac->updating_rts_rate = 0;
231 mac->updating_basic_rates = 0;
233 zd_chip_disable_hwint(chip);
234 zd_chip_switch_radio_off(chip);
235 zd_chip_disable_int(chip);
237 return 0;
240 int zd_mac_set_mac_address(struct net_device *netdev, void *p)
242 int r;
243 unsigned long flags;
244 struct sockaddr *addr = p;
245 struct zd_mac *mac = zd_netdev_mac(netdev);
246 struct zd_chip *chip = &mac->chip;
248 if (!is_valid_ether_addr(addr->sa_data))
249 return -EADDRNOTAVAIL;
251 dev_dbg_f(zd_mac_dev(mac),
252 "Setting MAC to " MAC_FMT "\n", MAC_ARG(addr->sa_data));
254 r = zd_write_mac_addr(chip, addr->sa_data);
255 if (r)
256 return r;
258 spin_lock_irqsave(&mac->lock, flags);
259 memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN);
260 spin_unlock_irqrestore(&mac->lock, flags);
262 return 0;
265 static void set_multicast_hash_handler(struct work_struct *work)
267 struct zd_mac *mac = container_of(work, struct zd_mac,
268 set_multicast_hash_work);
269 struct zd_mc_hash hash;
271 spin_lock_irq(&mac->lock);
272 hash = mac->multicast_hash;
273 spin_unlock_irq(&mac->lock);
275 zd_chip_set_multicast_hash(&mac->chip, &hash);
278 void zd_mac_set_multicast_list(struct net_device *dev)
280 struct zd_mc_hash hash;
281 struct zd_mac *mac = zd_netdev_mac(dev);
282 struct dev_mc_list *mc;
283 unsigned long flags;
285 if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI)) {
286 zd_mc_add_all(&hash);
287 } else {
288 zd_mc_clear(&hash);
289 for (mc = dev->mc_list; mc; mc = mc->next) {
290 dev_dbg_f(zd_mac_dev(mac), "mc addr " MAC_FMT "\n",
291 MAC_ARG(mc->dmi_addr));
292 zd_mc_add_addr(&hash, mc->dmi_addr);
296 spin_lock_irqsave(&mac->lock, flags);
297 mac->multicast_hash = hash;
298 spin_unlock_irqrestore(&mac->lock, flags);
299 queue_work(zd_workqueue, &mac->set_multicast_hash_work);
302 int zd_mac_set_regdomain(struct zd_mac *mac, u8 regdomain)
304 int r;
305 u8 channel;
307 ZD_ASSERT(!irqs_disabled());
308 spin_lock_irq(&mac->lock);
309 if (regdomain == 0) {
310 regdomain = mac->default_regdomain;
312 if (!zd_regdomain_supported(regdomain)) {
313 spin_unlock_irq(&mac->lock);
314 return -EINVAL;
316 mac->regdomain = regdomain;
317 channel = mac->requested_channel;
318 spin_unlock_irq(&mac->lock);
320 r = zd_geo_init(zd_mac_to_ieee80211(mac), regdomain);
321 if (r)
322 return r;
323 if (!zd_regdomain_supports_channel(regdomain, channel)) {
324 r = reset_channel(mac);
325 if (r)
326 return r;
329 return 0;
332 u8 zd_mac_get_regdomain(struct zd_mac *mac)
334 unsigned long flags;
335 u8 regdomain;
337 spin_lock_irqsave(&mac->lock, flags);
338 regdomain = mac->regdomain;
339 spin_unlock_irqrestore(&mac->lock, flags);
340 return regdomain;
343 /* Fallback to lowest rate, if rate is unknown. */
344 static u8 rate_to_zd_rate(u8 rate)
346 switch (rate) {
347 case IEEE80211_CCK_RATE_2MB:
348 return ZD_CCK_RATE_2M;
349 case IEEE80211_CCK_RATE_5MB:
350 return ZD_CCK_RATE_5_5M;
351 case IEEE80211_CCK_RATE_11MB:
352 return ZD_CCK_RATE_11M;
353 case IEEE80211_OFDM_RATE_6MB:
354 return ZD_OFDM_RATE_6M;
355 case IEEE80211_OFDM_RATE_9MB:
356 return ZD_OFDM_RATE_9M;
357 case IEEE80211_OFDM_RATE_12MB:
358 return ZD_OFDM_RATE_12M;
359 case IEEE80211_OFDM_RATE_18MB:
360 return ZD_OFDM_RATE_18M;
361 case IEEE80211_OFDM_RATE_24MB:
362 return ZD_OFDM_RATE_24M;
363 case IEEE80211_OFDM_RATE_36MB:
364 return ZD_OFDM_RATE_36M;
365 case IEEE80211_OFDM_RATE_48MB:
366 return ZD_OFDM_RATE_48M;
367 case IEEE80211_OFDM_RATE_54MB:
368 return ZD_OFDM_RATE_54M;
370 return ZD_CCK_RATE_1M;
373 static u16 rate_to_cr_rate(u8 rate)
375 switch (rate) {
376 case IEEE80211_CCK_RATE_2MB:
377 return CR_RATE_1M;
378 case IEEE80211_CCK_RATE_5MB:
379 return CR_RATE_5_5M;
380 case IEEE80211_CCK_RATE_11MB:
381 return CR_RATE_11M;
382 case IEEE80211_OFDM_RATE_6MB:
383 return CR_RATE_6M;
384 case IEEE80211_OFDM_RATE_9MB:
385 return CR_RATE_9M;
386 case IEEE80211_OFDM_RATE_12MB:
387 return CR_RATE_12M;
388 case IEEE80211_OFDM_RATE_18MB:
389 return CR_RATE_18M;
390 case IEEE80211_OFDM_RATE_24MB:
391 return CR_RATE_24M;
392 case IEEE80211_OFDM_RATE_36MB:
393 return CR_RATE_36M;
394 case IEEE80211_OFDM_RATE_48MB:
395 return CR_RATE_48M;
396 case IEEE80211_OFDM_RATE_54MB:
397 return CR_RATE_54M;
399 return CR_RATE_1M;
402 static void try_enable_tx(struct zd_mac *mac)
404 unsigned long flags;
406 spin_lock_irqsave(&mac->lock, flags);
407 if (mac->updating_rts_rate == 0 && mac->updating_basic_rates == 0)
408 netif_wake_queue(mac->netdev);
409 spin_unlock_irqrestore(&mac->lock, flags);
412 static void set_rts_cts_work(struct work_struct *work)
414 struct zd_mac *mac =
415 container_of(work, struct zd_mac, set_rts_cts_work.work);
416 unsigned long flags;
417 u8 rts_rate;
418 unsigned int short_preamble;
420 mutex_lock(&mac->chip.mutex);
422 spin_lock_irqsave(&mac->lock, flags);
423 mac->updating_rts_rate = 0;
424 rts_rate = mac->rts_rate;
425 short_preamble = mac->short_preamble;
426 spin_unlock_irqrestore(&mac->lock, flags);
428 zd_chip_set_rts_cts_rate_locked(&mac->chip, rts_rate, short_preamble);
429 mutex_unlock(&mac->chip.mutex);
431 try_enable_tx(mac);
434 static void set_basic_rates_work(struct work_struct *work)
436 struct zd_mac *mac =
437 container_of(work, struct zd_mac, set_basic_rates_work.work);
438 unsigned long flags;
439 u16 basic_rates;
441 mutex_lock(&mac->chip.mutex);
443 spin_lock_irqsave(&mac->lock, flags);
444 mac->updating_basic_rates = 0;
445 basic_rates = mac->basic_rates;
446 spin_unlock_irqrestore(&mac->lock, flags);
448 zd_chip_set_basic_rates_locked(&mac->chip, basic_rates);
449 mutex_unlock(&mac->chip.mutex);
451 try_enable_tx(mac);
454 static void bssinfo_change(struct net_device *netdev, u32 changes)
456 struct zd_mac *mac = zd_netdev_mac(netdev);
457 struct ieee80211softmac_device *softmac = ieee80211_priv(netdev);
458 struct ieee80211softmac_bss_info *bssinfo = &softmac->bssinfo;
459 int need_set_rts_cts = 0;
460 int need_set_rates = 0;
461 u16 basic_rates;
462 unsigned long flags;
464 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
466 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE) {
467 spin_lock_irqsave(&mac->lock, flags);
468 mac->short_preamble = bssinfo->short_preamble;
469 spin_unlock_irqrestore(&mac->lock, flags);
470 need_set_rts_cts = 1;
473 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) {
474 /* Set RTS rate to highest available basic rate */
475 u8 hi_rate = ieee80211softmac_highest_supported_rate(softmac,
476 &bssinfo->supported_rates, 1);
477 hi_rate = rate_to_zd_rate(hi_rate);
479 spin_lock_irqsave(&mac->lock, flags);
480 if (hi_rate != mac->rts_rate) {
481 mac->rts_rate = hi_rate;
482 need_set_rts_cts = 1;
484 spin_unlock_irqrestore(&mac->lock, flags);
486 /* Set basic rates */
487 need_set_rates = 1;
488 if (bssinfo->supported_rates.count == 0) {
489 /* Allow the device to be flexible */
490 basic_rates = CR_RATES_80211B | CR_RATES_80211G;
491 } else {
492 int i = 0;
493 basic_rates = 0;
495 for (i = 0; i < bssinfo->supported_rates.count; i++) {
496 u16 rate = bssinfo->supported_rates.rates[i];
497 if ((rate & IEEE80211_BASIC_RATE_MASK) == 0)
498 continue;
500 rate &= ~IEEE80211_BASIC_RATE_MASK;
501 basic_rates |= rate_to_cr_rate(rate);
504 spin_lock_irqsave(&mac->lock, flags);
505 mac->basic_rates = basic_rates;
506 spin_unlock_irqrestore(&mac->lock, flags);
509 /* Schedule any changes we made above */
511 spin_lock_irqsave(&mac->lock, flags);
512 if (need_set_rts_cts && !mac->updating_rts_rate) {
513 mac->updating_rts_rate = 1;
514 netif_stop_queue(mac->netdev);
515 queue_delayed_work(zd_workqueue, &mac->set_rts_cts_work, 0);
517 if (need_set_rates && !mac->updating_basic_rates) {
518 mac->updating_basic_rates = 1;
519 netif_stop_queue(mac->netdev);
520 queue_delayed_work(zd_workqueue, &mac->set_basic_rates_work,
523 spin_unlock_irqrestore(&mac->lock, flags);
526 static void set_channel(struct net_device *netdev, u8 channel)
528 struct zd_mac *mac = zd_netdev_mac(netdev);
530 dev_dbg_f(zd_mac_dev(mac), "channel %d\n", channel);
532 zd_chip_set_channel(&mac->chip, channel);
535 int zd_mac_request_channel(struct zd_mac *mac, u8 channel)
537 unsigned long lock_flags;
538 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
540 if (ieee->iw_mode == IW_MODE_INFRA)
541 return -EPERM;
543 spin_lock_irqsave(&mac->lock, lock_flags);
544 if (!zd_regdomain_supports_channel(mac->regdomain, channel)) {
545 spin_unlock_irqrestore(&mac->lock, lock_flags);
546 return -EINVAL;
548 mac->requested_channel = channel;
549 spin_unlock_irqrestore(&mac->lock, lock_flags);
550 if (netif_running(mac->netdev))
551 return zd_chip_set_channel(&mac->chip, channel);
552 else
553 return 0;
556 u8 zd_mac_get_channel(struct zd_mac *mac)
558 u8 channel = zd_chip_get_channel(&mac->chip);
560 dev_dbg_f(zd_mac_dev(mac), "channel %u\n", channel);
561 return channel;
564 /* If wrong rate is given, we are falling back to the slowest rate: 1MBit/s */
565 static u8 zd_rate_typed(u8 zd_rate)
567 static const u8 typed_rates[16] = {
568 [ZD_CCK_RATE_1M] = ZD_CS_CCK|ZD_CCK_RATE_1M,
569 [ZD_CCK_RATE_2M] = ZD_CS_CCK|ZD_CCK_RATE_2M,
570 [ZD_CCK_RATE_5_5M] = ZD_CS_CCK|ZD_CCK_RATE_5_5M,
571 [ZD_CCK_RATE_11M] = ZD_CS_CCK|ZD_CCK_RATE_11M,
572 [ZD_OFDM_RATE_6M] = ZD_CS_OFDM|ZD_OFDM_RATE_6M,
573 [ZD_OFDM_RATE_9M] = ZD_CS_OFDM|ZD_OFDM_RATE_9M,
574 [ZD_OFDM_RATE_12M] = ZD_CS_OFDM|ZD_OFDM_RATE_12M,
575 [ZD_OFDM_RATE_18M] = ZD_CS_OFDM|ZD_OFDM_RATE_18M,
576 [ZD_OFDM_RATE_24M] = ZD_CS_OFDM|ZD_OFDM_RATE_24M,
577 [ZD_OFDM_RATE_36M] = ZD_CS_OFDM|ZD_OFDM_RATE_36M,
578 [ZD_OFDM_RATE_48M] = ZD_CS_OFDM|ZD_OFDM_RATE_48M,
579 [ZD_OFDM_RATE_54M] = ZD_CS_OFDM|ZD_OFDM_RATE_54M,
582 ZD_ASSERT(ZD_CS_RATE_MASK == 0x0f);
583 return typed_rates[zd_rate & ZD_CS_RATE_MASK];
586 int zd_mac_set_mode(struct zd_mac *mac, u32 mode)
588 struct ieee80211_device *ieee;
590 switch (mode) {
591 case IW_MODE_AUTO:
592 case IW_MODE_ADHOC:
593 case IW_MODE_INFRA:
594 mac->netdev->type = ARPHRD_ETHER;
595 break;
596 case IW_MODE_MONITOR:
597 mac->netdev->type = ARPHRD_IEEE80211_RADIOTAP;
598 break;
599 default:
600 dev_dbg_f(zd_mac_dev(mac), "wrong mode %u\n", mode);
601 return -EINVAL;
604 ieee = zd_mac_to_ieee80211(mac);
605 ZD_ASSERT(!irqs_disabled());
606 spin_lock_irq(&ieee->lock);
607 ieee->iw_mode = mode;
608 spin_unlock_irq(&ieee->lock);
610 if (netif_running(mac->netdev))
611 return reset_mode(mac);
613 return 0;
616 int zd_mac_get_mode(struct zd_mac *mac, u32 *mode)
618 unsigned long flags;
619 struct ieee80211_device *ieee;
621 ieee = zd_mac_to_ieee80211(mac);
622 spin_lock_irqsave(&ieee->lock, flags);
623 *mode = ieee->iw_mode;
624 spin_unlock_irqrestore(&ieee->lock, flags);
625 return 0;
628 int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range)
630 int i;
631 const struct channel_range *channel_range;
632 u8 regdomain;
634 memset(range, 0, sizeof(*range));
636 /* FIXME: Not so important and depends on the mode. For 802.11g
637 * usually this value is used. It seems to be that Bit/s number is
638 * given here.
640 range->throughput = 27 * 1000 * 1000;
642 range->max_qual.qual = 100;
643 range->max_qual.level = 100;
645 /* FIXME: Needs still to be tuned. */
646 range->avg_qual.qual = 71;
647 range->avg_qual.level = 80;
649 /* FIXME: depends on standard? */
650 range->min_rts = 256;
651 range->max_rts = 2346;
653 range->min_frag = MIN_FRAG_THRESHOLD;
654 range->max_frag = MAX_FRAG_THRESHOLD;
656 range->max_encoding_tokens = WEP_KEYS;
657 range->num_encoding_sizes = 2;
658 range->encoding_size[0] = 5;
659 range->encoding_size[1] = WEP_KEY_LEN;
661 range->we_version_compiled = WIRELESS_EXT;
662 range->we_version_source = 20;
664 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
665 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
667 ZD_ASSERT(!irqs_disabled());
668 spin_lock_irq(&mac->lock);
669 regdomain = mac->regdomain;
670 spin_unlock_irq(&mac->lock);
671 channel_range = zd_channel_range(regdomain);
673 range->num_channels = channel_range->end - channel_range->start;
674 range->old_num_channels = range->num_channels;
675 range->num_frequency = range->num_channels;
676 range->old_num_frequency = range->num_frequency;
678 for (i = 0; i < range->num_frequency; i++) {
679 struct iw_freq *freq = &range->freq[i];
680 freq->i = channel_range->start + i;
681 zd_channel_to_freq(freq, freq->i);
684 return 0;
687 static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
689 static const u8 rate_divisor[] = {
690 [ZD_CCK_RATE_1M] = 1,
691 [ZD_CCK_RATE_2M] = 2,
692 [ZD_CCK_RATE_5_5M] = 11, /* bits must be doubled */
693 [ZD_CCK_RATE_11M] = 11,
694 [ZD_OFDM_RATE_6M] = 6,
695 [ZD_OFDM_RATE_9M] = 9,
696 [ZD_OFDM_RATE_12M] = 12,
697 [ZD_OFDM_RATE_18M] = 18,
698 [ZD_OFDM_RATE_24M] = 24,
699 [ZD_OFDM_RATE_36M] = 36,
700 [ZD_OFDM_RATE_48M] = 48,
701 [ZD_OFDM_RATE_54M] = 54,
704 u32 bits = (u32)tx_length * 8;
705 u32 divisor;
707 divisor = rate_divisor[zd_rate];
708 if (divisor == 0)
709 return -EINVAL;
711 switch (zd_rate) {
712 case ZD_CCK_RATE_5_5M:
713 bits = (2*bits) + 10; /* round up to the next integer */
714 break;
715 case ZD_CCK_RATE_11M:
716 if (service) {
717 u32 t = bits % 11;
718 *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
719 if (0 < t && t <= 3) {
720 *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
723 bits += 10; /* round up to the next integer */
724 break;
727 return bits/divisor;
730 enum {
731 R2M_SHORT_PREAMBLE = 0x01,
732 R2M_11A = 0x02,
735 static u8 zd_rate_to_modulation(u8 zd_rate, int flags)
737 u8 modulation;
739 modulation = zd_rate_typed(zd_rate);
740 if (flags & R2M_SHORT_PREAMBLE) {
741 switch (ZD_CS_RATE(modulation)) {
742 case ZD_CCK_RATE_2M:
743 case ZD_CCK_RATE_5_5M:
744 case ZD_CCK_RATE_11M:
745 modulation |= ZD_CS_CCK_PREA_SHORT;
746 return modulation;
749 if (flags & R2M_11A) {
750 if (ZD_CS_TYPE(modulation) == ZD_CS_OFDM)
751 modulation |= ZD_CS_OFDM_MODE_11A;
753 return modulation;
756 static void cs_set_modulation(struct zd_mac *mac, struct zd_ctrlset *cs,
757 struct ieee80211_hdr_4addr *hdr)
759 struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev);
760 u16 ftype = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_ctl));
761 u8 rate, zd_rate;
762 int is_mgt = (ftype == IEEE80211_FTYPE_MGMT) != 0;
763 int is_multicast = is_multicast_ether_addr(hdr->addr1);
764 int short_preamble = ieee80211softmac_short_preamble_ok(softmac,
765 is_multicast, is_mgt);
766 int flags = 0;
768 /* FIXME: 802.11a? */
769 rate = ieee80211softmac_suggest_txrate(softmac, is_multicast, is_mgt);
771 if (short_preamble)
772 flags |= R2M_SHORT_PREAMBLE;
774 zd_rate = rate_to_zd_rate(rate);
775 cs->modulation = zd_rate_to_modulation(zd_rate, flags);
778 static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
779 struct ieee80211_hdr_4addr *header)
781 struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev);
782 unsigned int tx_length = le16_to_cpu(cs->tx_length);
783 u16 fctl = le16_to_cpu(header->frame_ctl);
784 u16 ftype = WLAN_FC_GET_TYPE(fctl);
785 u16 stype = WLAN_FC_GET_STYPE(fctl);
788 * CONTROL TODO:
789 * - if backoff needed, enable bit 0
790 * - if burst (backoff not needed) disable bit 0
793 cs->control = 0;
795 /* First fragment */
796 if (WLAN_GET_SEQ_FRAG(le16_to_cpu(header->seq_ctl)) == 0)
797 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
799 /* Multicast */
800 if (is_multicast_ether_addr(header->addr1))
801 cs->control |= ZD_CS_MULTICAST;
803 /* PS-POLL */
804 if (stype == IEEE80211_STYPE_PSPOLL)
805 cs->control |= ZD_CS_PS_POLL_FRAME;
807 /* Unicast data frames over the threshold should have RTS */
808 if (!is_multicast_ether_addr(header->addr1) &&
809 ftype != IEEE80211_FTYPE_MGMT &&
810 tx_length > zd_netdev_ieee80211(mac->netdev)->rts)
811 cs->control |= ZD_CS_RTS;
813 /* Use CTS-to-self protection if required */
814 if (ZD_CS_TYPE(cs->modulation) == ZD_CS_OFDM &&
815 ieee80211softmac_protection_needed(softmac)) {
816 /* FIXME: avoid sending RTS *and* self-CTS, is that correct? */
817 cs->control &= ~ZD_CS_RTS;
818 cs->control |= ZD_CS_SELF_CTS;
821 /* FIXME: Management frame? */
824 static int fill_ctrlset(struct zd_mac *mac,
825 struct ieee80211_txb *txb,
826 int frag_num)
828 int r;
829 struct sk_buff *skb = txb->fragments[frag_num];
830 struct ieee80211_hdr_4addr *hdr =
831 (struct ieee80211_hdr_4addr *) skb->data;
832 unsigned int frag_len = skb->len + IEEE80211_FCS_LEN;
833 unsigned int next_frag_len;
834 unsigned int packet_length;
835 struct zd_ctrlset *cs = (struct zd_ctrlset *)
836 skb_push(skb, sizeof(struct zd_ctrlset));
838 if (frag_num+1 < txb->nr_frags) {
839 next_frag_len = txb->fragments[frag_num+1]->len +
840 IEEE80211_FCS_LEN;
841 } else {
842 next_frag_len = 0;
844 ZD_ASSERT(frag_len <= 0xffff);
845 ZD_ASSERT(next_frag_len <= 0xffff);
847 cs_set_modulation(mac, cs, hdr);
849 cs->tx_length = cpu_to_le16(frag_len);
851 cs_set_control(mac, cs, hdr);
853 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
854 ZD_ASSERT(packet_length <= 0xffff);
855 /* ZD1211B: Computing the length difference this way, gives us
856 * flexibility to compute the packet length.
858 cs->packet_length = cpu_to_le16(mac->chip.is_zd1211b ?
859 packet_length - frag_len : packet_length);
862 * CURRENT LENGTH:
863 * - transmit frame length in microseconds
864 * - seems to be derived from frame length
865 * - see Cal_Us_Service() in zdinlinef.h
866 * - if macp->bTxBurstEnable is enabled, then multiply by 4
867 * - bTxBurstEnable is never set in the vendor driver
869 * SERVICE:
870 * - "for PLCP configuration"
871 * - always 0 except in some situations at 802.11b 11M
872 * - see line 53 of zdinlinef.h
874 cs->service = 0;
875 r = zd_calc_tx_length_us(&cs->service, ZD_CS_RATE(cs->modulation),
876 le16_to_cpu(cs->tx_length));
877 if (r < 0)
878 return r;
879 cs->current_length = cpu_to_le16(r);
881 if (next_frag_len == 0) {
882 cs->next_frame_length = 0;
883 } else {
884 r = zd_calc_tx_length_us(NULL, ZD_CS_RATE(cs->modulation),
885 next_frag_len);
886 if (r < 0)
887 return r;
888 cs->next_frame_length = cpu_to_le16(r);
891 return 0;
894 static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri)
896 int i, r;
897 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
899 for (i = 0; i < txb->nr_frags; i++) {
900 struct sk_buff *skb = txb->fragments[i];
902 r = fill_ctrlset(mac, txb, i);
903 if (r) {
904 ieee->stats.tx_dropped++;
905 return r;
907 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len);
908 if (r) {
909 ieee->stats.tx_dropped++;
910 return r;
914 /* FIXME: shouldn't this be handled by the upper layers? */
915 mac->netdev->trans_start = jiffies;
917 ieee80211_txb_free(txb);
918 return 0;
921 struct zd_rt_hdr {
922 struct ieee80211_radiotap_header rt_hdr;
923 u8 rt_flags;
924 u8 rt_rate;
925 u16 rt_channel;
926 u16 rt_chbitmask;
927 } __attribute__((packed));
929 static void fill_rt_header(void *buffer, struct zd_mac *mac,
930 const struct ieee80211_rx_stats *stats,
931 const struct rx_status *status)
933 struct zd_rt_hdr *hdr = buffer;
935 hdr->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
936 hdr->rt_hdr.it_pad = 0;
937 hdr->rt_hdr.it_len = cpu_to_le16(sizeof(struct zd_rt_hdr));
938 hdr->rt_hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
939 (1 << IEEE80211_RADIOTAP_CHANNEL) |
940 (1 << IEEE80211_RADIOTAP_RATE));
942 hdr->rt_flags = 0;
943 if (status->decryption_type & (ZD_RX_WEP64|ZD_RX_WEP128|ZD_RX_WEP256))
944 hdr->rt_flags |= IEEE80211_RADIOTAP_F_WEP;
946 hdr->rt_rate = stats->rate / 5;
948 /* FIXME: 802.11a */
949 hdr->rt_channel = cpu_to_le16(ieee80211chan2mhz(
950 _zd_chip_get_channel(&mac->chip)));
951 hdr->rt_chbitmask = cpu_to_le16(IEEE80211_CHAN_2GHZ |
952 ((status->frame_status & ZD_RX_FRAME_MODULATION_MASK) ==
953 ZD_RX_OFDM ? IEEE80211_CHAN_OFDM : IEEE80211_CHAN_CCK));
956 /* Returns 1 if the data packet is for us and 0 otherwise. */
957 static int is_data_packet_for_us(struct ieee80211_device *ieee,
958 struct ieee80211_hdr_4addr *hdr)
960 struct net_device *netdev = ieee->dev;
961 u16 fc = le16_to_cpu(hdr->frame_ctl);
963 ZD_ASSERT(WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA);
965 switch (ieee->iw_mode) {
966 case IW_MODE_ADHOC:
967 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != 0 ||
968 compare_ether_addr(hdr->addr3, ieee->bssid) != 0)
969 return 0;
970 break;
971 case IW_MODE_AUTO:
972 case IW_MODE_INFRA:
973 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) !=
974 IEEE80211_FCTL_FROMDS ||
975 compare_ether_addr(hdr->addr2, ieee->bssid) != 0)
976 return 0;
977 break;
978 default:
979 ZD_ASSERT(ieee->iw_mode != IW_MODE_MONITOR);
980 return 0;
983 return compare_ether_addr(hdr->addr1, netdev->dev_addr) == 0 ||
984 (is_multicast_ether_addr(hdr->addr1) &&
985 compare_ether_addr(hdr->addr3, netdev->dev_addr) != 0) ||
986 (netdev->flags & IFF_PROMISC);
989 /* Filters received packets. The function returns 1 if the packet should be
990 * forwarded to ieee80211_rx(). If the packet should be ignored the function
991 * returns 0. If an invalid packet is found the function returns -EINVAL.
993 * The function calls ieee80211_rx_mgt() directly.
995 * It has been based on ieee80211_rx_any.
997 static int filter_rx(struct ieee80211_device *ieee,
998 const u8 *buffer, unsigned int length,
999 struct ieee80211_rx_stats *stats)
1001 struct ieee80211_hdr_4addr *hdr;
1002 u16 fc;
1004 if (ieee->iw_mode == IW_MODE_MONITOR)
1005 return 1;
1007 hdr = (struct ieee80211_hdr_4addr *)buffer;
1008 fc = le16_to_cpu(hdr->frame_ctl);
1009 if ((fc & IEEE80211_FCTL_VERS) != 0)
1010 return -EINVAL;
1012 switch (WLAN_FC_GET_TYPE(fc)) {
1013 case IEEE80211_FTYPE_MGMT:
1014 if (length < sizeof(struct ieee80211_hdr_3addr))
1015 return -EINVAL;
1016 ieee80211_rx_mgt(ieee, hdr, stats);
1017 return 0;
1018 case IEEE80211_FTYPE_CTL:
1019 return 0;
1020 case IEEE80211_FTYPE_DATA:
1021 /* Ignore invalid short buffers */
1022 if (length < sizeof(struct ieee80211_hdr_3addr))
1023 return -EINVAL;
1024 return is_data_packet_for_us(ieee, hdr);
1027 return -EINVAL;
1030 static void update_qual_rssi(struct zd_mac *mac,
1031 const u8 *buffer, unsigned int length,
1032 u8 qual_percent, u8 rssi_percent)
1034 unsigned long flags;
1035 struct ieee80211_hdr_3addr *hdr;
1036 int i;
1038 hdr = (struct ieee80211_hdr_3addr *)buffer;
1039 if (length < offsetof(struct ieee80211_hdr_3addr, addr3))
1040 return;
1041 if (compare_ether_addr(hdr->addr2, zd_mac_to_ieee80211(mac)->bssid) != 0)
1042 return;
1044 spin_lock_irqsave(&mac->lock, flags);
1045 i = mac->stats_count % ZD_MAC_STATS_BUFFER_SIZE;
1046 mac->qual_buffer[i] = qual_percent;
1047 mac->rssi_buffer[i] = rssi_percent;
1048 mac->stats_count++;
1049 spin_unlock_irqrestore(&mac->lock, flags);
1052 static int fill_rx_stats(struct ieee80211_rx_stats *stats,
1053 const struct rx_status **pstatus,
1054 struct zd_mac *mac,
1055 const u8 *buffer, unsigned int length)
1057 const struct rx_status *status;
1059 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status));
1060 if (status->frame_status & ZD_RX_ERROR) {
1061 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1062 ieee->stats.rx_errors++;
1063 if (status->frame_status & ZD_RX_TIMEOUT_ERROR)
1064 ieee->stats.rx_missed_errors++;
1065 else if (status->frame_status & ZD_RX_FIFO_OVERRUN_ERROR)
1066 ieee->stats.rx_fifo_errors++;
1067 else if (status->frame_status & ZD_RX_DECRYPTION_ERROR)
1068 ieee->ieee_stats.rx_discards_undecryptable++;
1069 else if (status->frame_status & ZD_RX_CRC32_ERROR) {
1070 ieee->stats.rx_crc_errors++;
1071 ieee->ieee_stats.rx_fcs_errors++;
1073 else if (status->frame_status & ZD_RX_CRC16_ERROR)
1074 ieee->stats.rx_crc_errors++;
1075 return -EINVAL;
1078 memset(stats, 0, sizeof(struct ieee80211_rx_stats));
1079 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN +
1080 + sizeof(struct rx_status));
1081 /* FIXME: 802.11a */
1082 stats->freq = IEEE80211_24GHZ_BAND;
1083 stats->received_channel = _zd_chip_get_channel(&mac->chip);
1084 stats->rssi = zd_rx_strength_percent(status->signal_strength);
1085 stats->signal = zd_rx_qual_percent(buffer,
1086 length - sizeof(struct rx_status),
1087 status);
1088 stats->mask = IEEE80211_STATMASK_RSSI | IEEE80211_STATMASK_SIGNAL;
1089 stats->rate = zd_rx_rate(buffer, status);
1090 if (stats->rate)
1091 stats->mask |= IEEE80211_STATMASK_RATE;
1093 return 0;
1096 static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1098 int r;
1099 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1100 struct ieee80211_rx_stats stats;
1101 const struct rx_status *status;
1103 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
1104 IEEE80211_FCS_LEN + sizeof(struct rx_status))
1106 ieee->stats.rx_errors++;
1107 ieee->stats.rx_length_errors++;
1108 goto free_skb;
1111 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len);
1112 if (r) {
1113 /* Only packets with rx errors are included here.
1114 * The error stats have already been set in fill_rx_stats.
1116 goto free_skb;
1119 __skb_pull(skb, ZD_PLCP_HEADER_SIZE);
1120 __skb_trim(skb, skb->len -
1121 (IEEE80211_FCS_LEN + sizeof(struct rx_status)));
1123 update_qual_rssi(mac, skb->data, skb->len, stats.signal,
1124 status->signal_strength);
1126 r = filter_rx(ieee, skb->data, skb->len, &stats);
1127 if (r <= 0) {
1128 if (r < 0) {
1129 ieee->stats.rx_errors++;
1130 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1132 goto free_skb;
1135 if (ieee->iw_mode == IW_MODE_MONITOR)
1136 fill_rt_header(skb_push(skb, sizeof(struct zd_rt_hdr)), mac,
1137 &stats, status);
1139 r = ieee80211_rx(ieee, skb, &stats);
1140 if (r)
1141 return;
1142 free_skb:
1143 /* We are always in a soft irq. */
1144 dev_kfree_skb(skb);
1147 static void do_rx(unsigned long mac_ptr)
1149 struct zd_mac *mac = (struct zd_mac *)mac_ptr;
1150 struct sk_buff *skb;
1152 while ((skb = skb_dequeue(&mac->rx_queue)) != NULL)
1153 zd_mac_rx(mac, skb);
1156 int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1158 struct sk_buff *skb;
1160 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1161 if (!skb) {
1162 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1163 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1164 ieee->stats.rx_dropped++;
1165 return -ENOMEM;
1167 skb_reserve(skb, sizeof(struct zd_rt_hdr));
1168 memcpy(__skb_put(skb, length), buffer, length);
1169 skb_queue_tail(&mac->rx_queue, skb);
1170 tasklet_schedule(&mac->rx_tasklet);
1171 return 0;
1174 static int netdev_tx(struct ieee80211_txb *txb, struct net_device *netdev,
1175 int pri)
1177 return zd_mac_tx(zd_netdev_mac(netdev), txb, pri);
1180 static void set_security(struct net_device *netdev,
1181 struct ieee80211_security *sec)
1183 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
1184 struct ieee80211_security *secinfo = &ieee->sec;
1185 int keyidx;
1187 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), "\n");
1189 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
1190 if (sec->flags & (1<<keyidx)) {
1191 secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
1192 secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
1193 memcpy(secinfo->keys[keyidx], sec->keys[keyidx],
1194 SCM_KEY_LEN);
1197 if (sec->flags & SEC_ACTIVE_KEY) {
1198 secinfo->active_key = sec->active_key;
1199 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1200 " .active_key = %d\n", sec->active_key);
1202 if (sec->flags & SEC_UNICAST_GROUP) {
1203 secinfo->unicast_uses_group = sec->unicast_uses_group;
1204 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1205 " .unicast_uses_group = %d\n",
1206 sec->unicast_uses_group);
1208 if (sec->flags & SEC_LEVEL) {
1209 secinfo->level = sec->level;
1210 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1211 " .level = %d\n", sec->level);
1213 if (sec->flags & SEC_ENABLED) {
1214 secinfo->enabled = sec->enabled;
1215 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1216 " .enabled = %d\n", sec->enabled);
1218 if (sec->flags & SEC_ENCRYPT) {
1219 secinfo->encrypt = sec->encrypt;
1220 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1221 " .encrypt = %d\n", sec->encrypt);
1223 if (sec->flags & SEC_AUTH_MODE) {
1224 secinfo->auth_mode = sec->auth_mode;
1225 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1226 " .auth_mode = %d\n", sec->auth_mode);
1230 static void ieee_init(struct ieee80211_device *ieee)
1232 ieee->mode = IEEE_B | IEEE_G;
1233 ieee->freq_band = IEEE80211_24GHZ_BAND;
1234 ieee->modulation = IEEE80211_OFDM_MODULATION | IEEE80211_CCK_MODULATION;
1235 ieee->tx_headroom = sizeof(struct zd_ctrlset);
1236 ieee->set_security = set_security;
1237 ieee->hard_start_xmit = netdev_tx;
1239 /* Software encryption/decryption for now */
1240 ieee->host_build_iv = 0;
1241 ieee->host_encrypt = 1;
1242 ieee->host_decrypt = 1;
1244 /* FIXME: default to managed mode, until ieee80211 and zd1211rw can
1245 * correctly support AUTO */
1246 ieee->iw_mode = IW_MODE_INFRA;
1249 static void softmac_init(struct ieee80211softmac_device *sm)
1251 sm->set_channel = set_channel;
1252 sm->bssinfo_change = bssinfo_change;
1255 struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev)
1257 struct zd_mac *mac = zd_netdev_mac(ndev);
1258 struct iw_statistics *iw_stats = &mac->iw_stats;
1259 unsigned int i, count, qual_total, rssi_total;
1261 memset(iw_stats, 0, sizeof(struct iw_statistics));
1262 /* We are not setting the status, because ieee->state is not updated
1263 * at all and this driver doesn't track authentication state.
1265 spin_lock_irq(&mac->lock);
1266 count = mac->stats_count < ZD_MAC_STATS_BUFFER_SIZE ?
1267 mac->stats_count : ZD_MAC_STATS_BUFFER_SIZE;
1268 qual_total = rssi_total = 0;
1269 for (i = 0; i < count; i++) {
1270 qual_total += mac->qual_buffer[i];
1271 rssi_total += mac->rssi_buffer[i];
1273 spin_unlock_irq(&mac->lock);
1274 iw_stats->qual.updated = IW_QUAL_NOISE_INVALID;
1275 if (count > 0) {
1276 iw_stats->qual.qual = qual_total / count;
1277 iw_stats->qual.level = rssi_total / count;
1278 iw_stats->qual.updated |=
1279 IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED;
1280 } else {
1281 iw_stats->qual.updated |=
1282 IW_QUAL_QUAL_INVALID|IW_QUAL_LEVEL_INVALID;
1284 /* TODO: update counter */
1285 return iw_stats;
1288 #define LINK_LED_WORK_DELAY HZ
1290 static void link_led_handler(struct work_struct *work)
1292 struct zd_mac *mac =
1293 container_of(work, struct zd_mac, housekeeping.link_led_work.work);
1294 struct zd_chip *chip = &mac->chip;
1295 struct ieee80211softmac_device *sm = ieee80211_priv(mac->netdev);
1296 int is_associated;
1297 int r;
1299 spin_lock_irq(&mac->lock);
1300 is_associated = sm->associnfo.associated != 0;
1301 spin_unlock_irq(&mac->lock);
1303 r = zd_chip_control_leds(chip,
1304 is_associated ? LED_ASSOCIATED : LED_SCANNING);
1305 if (r)
1306 dev_err(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
1308 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1309 LINK_LED_WORK_DELAY);
1312 static void housekeeping_init(struct zd_mac *mac)
1314 INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler);
1317 static void housekeeping_enable(struct zd_mac *mac)
1319 dev_dbg_f(zd_mac_dev(mac), "\n");
1320 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1324 static void housekeeping_disable(struct zd_mac *mac)
1326 dev_dbg_f(zd_mac_dev(mac), "\n");
1327 cancel_rearming_delayed_workqueue(zd_workqueue,
1328 &mac->housekeeping.link_led_work);
1329 zd_chip_control_leds(&mac->chip, LED_OFF);