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