1 /* ZD1211 USB-WLAN driver for Linux
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
5 * Copyright (C) 2006-2007 Michael Wu <flamingice@sourmilk.net>
6 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/usb.h>
26 #include <linux/jiffies.h>
27 #include <net/ieee80211_radiotap.h>
32 #include "zd_ieee80211.h"
35 /* This table contains the hardware specific values for the modulation rates. */
36 static const struct ieee80211_rate zd_rates[] = {
38 .hw_value = ZD_CCK_RATE_1M, },
40 .hw_value = ZD_CCK_RATE_2M,
41 .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT,
42 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
44 .hw_value = ZD_CCK_RATE_5_5M,
45 .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT,
46 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
48 .hw_value = ZD_CCK_RATE_11M,
49 .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT,
50 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
52 .hw_value = ZD_OFDM_RATE_6M,
55 .hw_value = ZD_OFDM_RATE_9M,
58 .hw_value = ZD_OFDM_RATE_12M,
61 .hw_value = ZD_OFDM_RATE_18M,
64 .hw_value = ZD_OFDM_RATE_24M,
67 .hw_value = ZD_OFDM_RATE_36M,
70 .hw_value = ZD_OFDM_RATE_48M,
73 .hw_value = ZD_OFDM_RATE_54M,
77 static const struct ieee80211_channel zd_channels[] = {
78 { .center_freq = 2412, .hw_value = 1 },
79 { .center_freq = 2417, .hw_value = 2 },
80 { .center_freq = 2422, .hw_value = 3 },
81 { .center_freq = 2427, .hw_value = 4 },
82 { .center_freq = 2432, .hw_value = 5 },
83 { .center_freq = 2437, .hw_value = 6 },
84 { .center_freq = 2442, .hw_value = 7 },
85 { .center_freq = 2447, .hw_value = 8 },
86 { .center_freq = 2452, .hw_value = 9 },
87 { .center_freq = 2457, .hw_value = 10 },
88 { .center_freq = 2462, .hw_value = 11 },
89 { .center_freq = 2467, .hw_value = 12 },
90 { .center_freq = 2472, .hw_value = 13 },
91 { .center_freq = 2484, .hw_value = 14 },
94 static void housekeeping_init(struct zd_mac *mac);
95 static void housekeeping_enable(struct zd_mac *mac);
96 static void housekeeping_disable(struct zd_mac *mac);
98 int zd_mac_preinit_hw(struct ieee80211_hw *hw)
102 struct zd_mac *mac = zd_hw_mac(hw);
104 r = zd_chip_read_mac_addr_fw(&mac->chip, addr);
108 SET_IEEE80211_PERM_ADDR(hw, addr);
113 int zd_mac_init_hw(struct ieee80211_hw *hw)
116 struct zd_mac *mac = zd_hw_mac(hw);
117 struct zd_chip *chip = &mac->chip;
118 u8 default_regdomain;
120 r = zd_chip_enable_int(chip);
123 r = zd_chip_init_hw(chip);
127 ZD_ASSERT(!irqs_disabled());
129 r = zd_read_regdomain(chip, &default_regdomain);
132 spin_lock_irq(&mac->lock);
133 mac->regdomain = mac->default_regdomain = default_regdomain;
134 spin_unlock_irq(&mac->lock);
136 /* We must inform the device that we are doing encryption/decryption in
137 * software at the moment. */
138 r = zd_set_encryption_type(chip, ENC_SNIFFER);
142 zd_geo_init(hw, mac->regdomain);
146 zd_chip_disable_int(chip);
151 void zd_mac_clear(struct zd_mac *mac)
153 flush_workqueue(zd_workqueue);
154 zd_chip_clear(&mac->chip);
155 ZD_ASSERT(!spin_is_locked(&mac->lock));
156 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
159 static int set_rx_filter(struct zd_mac *mac)
162 u32 filter = STA_RX_FILTER;
164 spin_lock_irqsave(&mac->lock, flags);
166 filter |= RX_FILTER_CTRL;
167 spin_unlock_irqrestore(&mac->lock, flags);
169 return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
172 static int set_mc_hash(struct zd_mac *mac)
174 struct zd_mc_hash hash;
176 return zd_chip_set_multicast_hash(&mac->chip, &hash);
179 static int zd_op_start(struct ieee80211_hw *hw)
181 struct zd_mac *mac = zd_hw_mac(hw);
182 struct zd_chip *chip = &mac->chip;
183 struct zd_usb *usb = &chip->usb;
186 if (!usb->initialized) {
187 r = zd_usb_init_hw(usb);
192 r = zd_chip_enable_int(chip);
196 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
199 r = set_rx_filter(mac);
202 r = set_mc_hash(mac);
205 r = zd_chip_switch_radio_on(chip);
208 r = zd_chip_enable_rxtx(chip);
211 r = zd_chip_enable_hwint(chip);
215 housekeeping_enable(mac);
218 zd_chip_disable_rxtx(chip);
220 zd_chip_switch_radio_off(chip);
222 zd_chip_disable_int(chip);
227 static void zd_op_stop(struct ieee80211_hw *hw)
229 struct zd_mac *mac = zd_hw_mac(hw);
230 struct zd_chip *chip = &mac->chip;
232 struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue;
234 /* The order here deliberately is a little different from the open()
235 * method, since we need to make sure there is no opportunity for RX
236 * frames to be processed by mac80211 after we have stopped it.
239 zd_chip_disable_rxtx(chip);
240 housekeeping_disable(mac);
241 flush_workqueue(zd_workqueue);
243 zd_chip_disable_hwint(chip);
244 zd_chip_switch_radio_off(chip);
245 zd_chip_disable_int(chip);
248 while ((skb = skb_dequeue(ack_wait_queue)))
249 dev_kfree_skb_any(skb);
253 * tx_status - reports tx status of a packet if required
254 * @hw - a &struct ieee80211_hw pointer
256 * @flags: extra flags to set in the TX status info
257 * @ackssi: ACK signal strength
258 * @success - True for successfull transmission of the frame
260 * This information calls ieee80211_tx_status_irqsafe() if required by the
261 * control information. It copies the control information into the status
264 * If no status information has been requested, the skb is freed.
266 static void tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
267 u32 flags, int ackssi, bool success)
269 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
271 memset(&info->status, 0, sizeof(info->status));
274 info->status.excessive_retries = 1;
275 info->flags |= flags;
276 info->status.ack_signal = ackssi;
277 ieee80211_tx_status_irqsafe(hw, skb);
281 * zd_mac_tx_failed - callback for failed frames
282 * @dev: the mac80211 wireless device
284 * This function is called if a frame couldn't be succesfully be
285 * transferred. The first frame from the tx queue, will be selected and
286 * reported as error to the upper layers.
288 void zd_mac_tx_failed(struct ieee80211_hw *hw)
290 struct sk_buff_head *q = &zd_hw_mac(hw)->ack_wait_queue;
293 skb = skb_dequeue(q);
297 tx_status(hw, skb, 0, 0, 0);
301 * zd_mac_tx_to_dev - callback for USB layer
302 * @skb: a &sk_buff pointer
303 * @error: error value, 0 if transmission successful
305 * Informs the MAC layer that the frame has successfully transferred to the
306 * device. If an ACK is required and the transfer to the device has been
307 * successful, the packets are put on the @ack_wait_queue with
308 * the control set removed.
310 void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
312 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
313 struct ieee80211_hw *hw = info->driver_data[0];
315 skb_pull(skb, sizeof(struct zd_ctrlset));
316 if (unlikely(error ||
317 (info->flags & IEEE80211_TX_CTL_NO_ACK))) {
318 tx_status(hw, skb, 0, 0, !error);
320 struct sk_buff_head *q =
321 &zd_hw_mac(hw)->ack_wait_queue;
323 skb_queue_tail(q, skb);
324 while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS)
325 zd_mac_tx_failed(hw);
329 static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
331 /* ZD_PURE_RATE() must be used to remove the modulation type flag of
332 * the zd-rate values.
334 static const u8 rate_divisor[] = {
335 [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1,
336 [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2,
337 /* Bits must be doubled. */
338 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11,
339 [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11,
340 [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6,
341 [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9,
342 [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12,
343 [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18,
344 [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24,
345 [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36,
346 [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
347 [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
350 u32 bits = (u32)tx_length * 8;
353 divisor = rate_divisor[ZD_PURE_RATE(zd_rate)];
358 case ZD_CCK_RATE_5_5M:
359 bits = (2*bits) + 10; /* round up to the next integer */
361 case ZD_CCK_RATE_11M:
364 *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
365 if (0 < t && t <= 3) {
366 *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
369 bits += 10; /* round up to the next integer */
376 static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
377 struct ieee80211_hdr *header, u32 flags)
381 * - if backoff needed, enable bit 0
382 * - if burst (backoff not needed) disable bit 0
388 if (flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
389 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
392 if (is_multicast_ether_addr(header->addr1))
393 cs->control |= ZD_CS_MULTICAST;
396 if (ieee80211_is_pspoll(header->frame_control))
397 cs->control |= ZD_CS_PS_POLL_FRAME;
399 if (flags & IEEE80211_TX_CTL_USE_RTS_CTS)
400 cs->control |= ZD_CS_RTS;
402 if (flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)
403 cs->control |= ZD_CS_SELF_CTS;
405 /* FIXME: Management frame? */
408 void zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon)
410 struct zd_mac *mac = zd_hw_mac(hw);
412 /* 4 more bytes for tail CRC */
413 u32 full_len = beacon->len + 4;
414 zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 0);
415 zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
417 zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
418 if ((++j % 100) == 0) {
419 printk(KERN_ERR "CR_BCN_FIFO_SEMAPHORE not ready\n");
421 printk(KERN_ERR "Giving up beacon config.\n");
428 zd_iowrite32(&mac->chip, CR_BCN_FIFO, full_len - 1);
429 if (zd_chip_is_zd1211b(&mac->chip))
430 zd_iowrite32(&mac->chip, CR_BCN_LENGTH, full_len - 1);
432 for (j = 0 ; j < beacon->len; j++)
433 zd_iowrite32(&mac->chip, CR_BCN_FIFO,
434 *((u8 *)(beacon->data + j)));
436 for (j = 0; j < 4; j++)
437 zd_iowrite32(&mac->chip, CR_BCN_FIFO, 0x0);
439 zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 1);
440 /* 802.11b/g 2.4G CCK 1Mb
441 * 802.11a, not yet implemented, uses different values (see GPL vendor
444 zd_iowrite32(&mac->chip, CR_BCN_PLCP_CFG, 0x00000400 |
448 static int fill_ctrlset(struct zd_mac *mac,
452 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
453 unsigned int frag_len = skb->len + FCS_LEN;
454 unsigned int packet_length;
455 struct ieee80211_rate *txrate;
456 struct zd_ctrlset *cs = (struct zd_ctrlset *)
457 skb_push(skb, sizeof(struct zd_ctrlset));
458 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
460 ZD_ASSERT(frag_len <= 0xffff);
462 txrate = ieee80211_get_tx_rate(mac->hw, info);
464 cs->modulation = txrate->hw_value;
465 if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE)
466 cs->modulation = txrate->hw_value_short;
468 cs->tx_length = cpu_to_le16(frag_len);
470 cs_set_control(mac, cs, hdr, info->flags);
472 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
473 ZD_ASSERT(packet_length <= 0xffff);
474 /* ZD1211B: Computing the length difference this way, gives us
475 * flexibility to compute the packet length.
477 cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ?
478 packet_length - frag_len : packet_length);
482 * - transmit frame length in microseconds
483 * - seems to be derived from frame length
484 * - see Cal_Us_Service() in zdinlinef.h
485 * - if macp->bTxBurstEnable is enabled, then multiply by 4
486 * - bTxBurstEnable is never set in the vendor driver
489 * - "for PLCP configuration"
490 * - always 0 except in some situations at 802.11b 11M
491 * - see line 53 of zdinlinef.h
494 r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation),
495 le16_to_cpu(cs->tx_length));
498 cs->current_length = cpu_to_le16(r);
499 cs->next_frame_length = 0;
505 * zd_op_tx - transmits a network frame to the device
507 * @dev: mac80211 hardware device
508 * @skb: socket buffer
509 * @control: the control structure
511 * This function transmit an IEEE 802.11 network frame to the device. The
512 * control block of the skbuff will be initialized. If necessary the incoming
513 * mac80211 queues will be stopped.
515 static int zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
517 struct zd_mac *mac = zd_hw_mac(hw);
518 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
521 r = fill_ctrlset(mac, skb);
525 info->driver_data[0] = hw;
527 r = zd_usb_tx(&mac->chip.usb, skb);
534 * filter_ack - filters incoming packets for acknowledgements
535 * @dev: the mac80211 device
536 * @rx_hdr: received header
537 * @stats: the status for the received packet
539 * This functions looks for ACK packets and tries to match them with the
540 * frames in the tx queue. If a match is found the frame will be dequeued and
541 * the upper layers is informed about the successful transmission. If
542 * mac80211 queues have been stopped and the number of frames still to be
543 * transmitted is low the queues will be opened again.
545 * Returns 1 if the frame was an ACK, 0 if it was ignored.
547 static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
548 struct ieee80211_rx_status *stats)
551 struct sk_buff_head *q;
554 if (!ieee80211_is_ack(rx_hdr->frame_control))
557 q = &zd_hw_mac(hw)->ack_wait_queue;
558 spin_lock_irqsave(&q->lock, flags);
559 for (skb = q->next; skb != (struct sk_buff *)q; skb = skb->next) {
560 struct ieee80211_hdr *tx_hdr;
562 tx_hdr = (struct ieee80211_hdr *)skb->data;
563 if (likely(!compare_ether_addr(tx_hdr->addr2, rx_hdr->addr1)))
565 __skb_unlink(skb, q);
566 tx_status(hw, skb, IEEE80211_TX_STAT_ACK, stats->signal, 1);
571 spin_unlock_irqrestore(&q->lock, flags);
575 int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
577 struct zd_mac *mac = zd_hw_mac(hw);
578 struct ieee80211_rx_status stats;
579 const struct rx_status *status;
587 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
588 FCS_LEN + sizeof(struct rx_status))
591 memset(&stats, 0, sizeof(stats));
593 /* Note about pass_failed_fcs and pass_ctrl access below:
594 * mac locking intentionally omitted here, as this is the only unlocked
595 * reader and the only writer is configure_filter. Plus, if there were
596 * any races accessing these variables, it wouldn't really matter.
597 * If mac80211 ever provides a way for us to access filter flags
598 * from outside configure_filter, we could improve on this. Also, this
599 * situation may change once we implement some kind of DMA-into-skb
602 /* Caller has to ensure that length >= sizeof(struct rx_status). */
603 status = (struct rx_status *)
604 (buffer + (length - sizeof(struct rx_status)));
605 if (status->frame_status & ZD_RX_ERROR) {
606 if (mac->pass_failed_fcs &&
607 (status->frame_status & ZD_RX_CRC32_ERROR)) {
608 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
615 stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq;
616 stats.band = IEEE80211_BAND_2GHZ;
617 stats.signal = status->signal_strength;
618 stats.qual = zd_rx_qual_percent(buffer,
619 length - sizeof(struct rx_status),
622 rate = zd_rx_rate(buffer, status);
624 /* todo: return index in the big switches in zd_rx_rate instead */
625 for (i = 0; i < mac->band.n_bitrates; i++)
626 if (rate == mac->band.bitrates[i].hw_value)
629 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
630 buffer += ZD_PLCP_HEADER_SIZE;
632 /* Except for bad frames, filter each frame to see if it is an ACK, in
633 * which case our internal TX tracking is updated. Normally we then
634 * bail here as there's no need to pass ACKs on up to the stack, but
635 * there is also the case where the stack has requested us to pass
636 * control frames on up (pass_ctrl) which we must consider. */
638 filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats)
642 fc = *(__le16 *)buffer;
643 need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
645 skb = dev_alloc_skb(length + (need_padding ? 2 : 0));
649 /* Make sure the the payload data is 4 byte aligned. */
653 memcpy(skb_put(skb, length), buffer, length);
655 ieee80211_rx_irqsafe(hw, skb, &stats);
659 static int zd_op_add_interface(struct ieee80211_hw *hw,
660 struct ieee80211_if_init_conf *conf)
662 struct zd_mac *mac = zd_hw_mac(hw);
664 /* using IEEE80211_IF_TYPE_INVALID to indicate no mode selected */
665 if (mac->type != IEEE80211_IF_TYPE_INVALID)
668 switch (conf->type) {
669 case IEEE80211_IF_TYPE_MNTR:
670 case IEEE80211_IF_TYPE_MESH_POINT:
671 case IEEE80211_IF_TYPE_STA:
672 case IEEE80211_IF_TYPE_IBSS:
673 mac->type = conf->type;
679 return zd_write_mac_addr(&mac->chip, conf->mac_addr);
682 static void zd_op_remove_interface(struct ieee80211_hw *hw,
683 struct ieee80211_if_init_conf *conf)
685 struct zd_mac *mac = zd_hw_mac(hw);
686 mac->type = IEEE80211_IF_TYPE_INVALID;
687 zd_write_mac_addr(&mac->chip, NULL);
690 static int zd_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
692 struct zd_mac *mac = zd_hw_mac(hw);
693 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
696 static int zd_op_config_interface(struct ieee80211_hw *hw,
697 struct ieee80211_vif *vif,
698 struct ieee80211_if_conf *conf)
700 struct zd_mac *mac = zd_hw_mac(hw);
703 if (mac->type == IEEE80211_IF_TYPE_MESH_POINT ||
704 mac->type == IEEE80211_IF_TYPE_IBSS) {
707 zd_mac_config_beacon(hw, conf->beacon);
708 kfree_skb(conf->beacon);
709 zd_set_beacon_interval(&mac->chip, BCN_MODE_IBSS |
710 hw->conf.beacon_int);
713 associated = is_valid_ether_addr(conf->bssid);
715 spin_lock_irq(&mac->lock);
716 mac->associated = associated;
717 spin_unlock_irq(&mac->lock);
719 /* TODO: do hardware bssid filtering */
723 void zd_process_intr(struct work_struct *work)
726 struct zd_mac *mac = container_of(work, struct zd_mac, process_intr);
728 int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer+4));
729 if (int_status & INT_CFG_NEXT_BCN) {
731 dev_dbg_f(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n");
733 dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n");
735 zd_chip_enable_hwint(&mac->chip);
739 static void set_multicast_hash_handler(struct work_struct *work)
742 container_of(work, struct zd_mac, set_multicast_hash_work);
743 struct zd_mc_hash hash;
745 spin_lock_irq(&mac->lock);
746 hash = mac->multicast_hash;
747 spin_unlock_irq(&mac->lock);
749 zd_chip_set_multicast_hash(&mac->chip, &hash);
752 static void set_rx_filter_handler(struct work_struct *work)
755 container_of(work, struct zd_mac, set_rx_filter_work);
758 dev_dbg_f(zd_mac_dev(mac), "\n");
759 r = set_rx_filter(mac);
761 dev_err(zd_mac_dev(mac), "set_rx_filter_handler error %d\n", r);
764 #define SUPPORTED_FIF_FLAGS \
765 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
766 FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
767 static void zd_op_configure_filter(struct ieee80211_hw *hw,
768 unsigned int changed_flags,
769 unsigned int *new_flags,
770 int mc_count, struct dev_mc_list *mclist)
772 struct zd_mc_hash hash;
773 struct zd_mac *mac = zd_hw_mac(hw);
777 /* Only deal with supported flags */
778 changed_flags &= SUPPORTED_FIF_FLAGS;
779 *new_flags &= SUPPORTED_FIF_FLAGS;
781 /* changed_flags is always populated but this driver
782 * doesn't support all FIF flags so its possible we don't
783 * need to do anything */
787 if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)) {
788 zd_mc_add_all(&hash);
790 DECLARE_MAC_BUF(macbuf);
793 for (i = 0; i < mc_count; i++) {
796 dev_dbg_f(zd_mac_dev(mac), "mc addr %s\n",
797 print_mac(macbuf, mclist->dmi_addr));
798 zd_mc_add_addr(&hash, mclist->dmi_addr);
799 mclist = mclist->next;
803 spin_lock_irqsave(&mac->lock, flags);
804 mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
805 mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
806 mac->multicast_hash = hash;
807 spin_unlock_irqrestore(&mac->lock, flags);
808 queue_work(zd_workqueue, &mac->set_multicast_hash_work);
810 if (changed_flags & FIF_CONTROL)
811 queue_work(zd_workqueue, &mac->set_rx_filter_work);
813 /* no handling required for FIF_OTHER_BSS as we don't currently
814 * do BSSID filtering */
815 /* FIXME: in future it would be nice to enable the probe response
816 * filter (so that the driver doesn't see them) until
817 * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
818 * have to schedule work to enable prbresp reception, which might
819 * happen too late. For now we'll just listen and forward them all the
823 static void set_rts_cts_work(struct work_struct *work)
826 container_of(work, struct zd_mac, set_rts_cts_work);
828 unsigned int short_preamble;
830 mutex_lock(&mac->chip.mutex);
832 spin_lock_irqsave(&mac->lock, flags);
833 mac->updating_rts_rate = 0;
834 short_preamble = mac->short_preamble;
835 spin_unlock_irqrestore(&mac->lock, flags);
837 zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble);
838 mutex_unlock(&mac->chip.mutex);
841 static void zd_op_bss_info_changed(struct ieee80211_hw *hw,
842 struct ieee80211_vif *vif,
843 struct ieee80211_bss_conf *bss_conf,
846 struct zd_mac *mac = zd_hw_mac(hw);
849 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
851 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
852 spin_lock_irqsave(&mac->lock, flags);
853 mac->short_preamble = bss_conf->use_short_preamble;
854 if (!mac->updating_rts_rate) {
855 mac->updating_rts_rate = 1;
856 /* FIXME: should disable TX here, until work has
857 * completed and RTS_CTS reg is updated */
858 queue_work(zd_workqueue, &mac->set_rts_cts_work);
860 spin_unlock_irqrestore(&mac->lock, flags);
864 static int zd_op_beacon_update(struct ieee80211_hw *hw,
867 struct zd_mac *mac = zd_hw_mac(hw);
868 zd_mac_config_beacon(hw, skb);
870 zd_set_beacon_interval(&mac->chip, BCN_MODE_IBSS |
871 hw->conf.beacon_int);
875 static const struct ieee80211_ops zd_ops = {
877 .start = zd_op_start,
879 .add_interface = zd_op_add_interface,
880 .remove_interface = zd_op_remove_interface,
881 .config = zd_op_config,
882 .config_interface = zd_op_config_interface,
883 .configure_filter = zd_op_configure_filter,
884 .bss_info_changed = zd_op_bss_info_changed,
885 .beacon_update = zd_op_beacon_update,
888 struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
891 struct ieee80211_hw *hw;
893 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
895 dev_dbg_f(&intf->dev, "out of memory\n");
901 memset(mac, 0, sizeof(*mac));
902 spin_lock_init(&mac->lock);
905 mac->type = IEEE80211_IF_TYPE_INVALID;
907 memcpy(mac->channels, zd_channels, sizeof(zd_channels));
908 memcpy(mac->rates, zd_rates, sizeof(zd_rates));
909 mac->band.n_bitrates = ARRAY_SIZE(zd_rates);
910 mac->band.bitrates = mac->rates;
911 mac->band.n_channels = ARRAY_SIZE(zd_channels);
912 mac->band.channels = mac->channels;
914 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band;
916 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
917 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
918 IEEE80211_HW_SIGNAL_DB;
920 hw->max_signal = 100;
922 hw->extra_tx_headroom = sizeof(struct zd_ctrlset);
924 skb_queue_head_init(&mac->ack_wait_queue);
926 zd_chip_init(&mac->chip, hw, intf);
927 housekeeping_init(mac);
928 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
929 INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
930 INIT_WORK(&mac->set_rx_filter_work, set_rx_filter_handler);
931 INIT_WORK(&mac->process_intr, zd_process_intr);
933 SET_IEEE80211_DEV(hw, &intf->dev);
937 #define LINK_LED_WORK_DELAY HZ
939 static void link_led_handler(struct work_struct *work)
942 container_of(work, struct zd_mac, housekeeping.link_led_work.work);
943 struct zd_chip *chip = &mac->chip;
947 spin_lock_irq(&mac->lock);
948 is_associated = mac->associated;
949 spin_unlock_irq(&mac->lock);
951 r = zd_chip_control_leds(chip,
952 is_associated ? LED_ASSOCIATED : LED_SCANNING);
954 dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
956 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
957 LINK_LED_WORK_DELAY);
960 static void housekeeping_init(struct zd_mac *mac)
962 INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler);
965 static void housekeeping_enable(struct zd_mac *mac)
967 dev_dbg_f(zd_mac_dev(mac), "\n");
968 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
972 static void housekeeping_disable(struct zd_mac *mac)
974 dev_dbg_f(zd_mac_dev(mac), "\n");
975 cancel_rearming_delayed_workqueue(zd_workqueue,
976 &mac->housekeeping.link_led_work);
977 zd_chip_control_leds(&mac->chip, LED_OFF);