3 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/netdevice.h>
21 #include <linux/etherdevice.h>
22 #include <linux/usb.h>
23 #include <linux/jiffies.h>
24 #include <net/ieee80211_radiotap.h>
29 #include "zd_ieee80211.h"
32 /* This table contains the hardware specific values for the modulation rates. */
33 static const struct ieee80211_rate zd_rates
[] = {
35 .val
= ZD_CCK_RATE_1M
,
36 .flags
= IEEE80211_RATE_CCK
},
38 .val
= ZD_CCK_RATE_2M
,
39 .val2
= ZD_CCK_RATE_2M
| ZD_CCK_PREA_SHORT
,
40 .flags
= IEEE80211_RATE_CCK_2
},
42 .val
= ZD_CCK_RATE_5_5M
,
43 .val2
= ZD_CCK_RATE_5_5M
| ZD_CCK_PREA_SHORT
,
44 .flags
= IEEE80211_RATE_CCK_2
},
46 .val
= ZD_CCK_RATE_11M
,
47 .val2
= ZD_CCK_RATE_11M
| ZD_CCK_PREA_SHORT
,
48 .flags
= IEEE80211_RATE_CCK_2
},
50 .val
= ZD_OFDM_RATE_6M
,
51 .flags
= IEEE80211_RATE_OFDM
},
53 .val
= ZD_OFDM_RATE_9M
,
54 .flags
= IEEE80211_RATE_OFDM
},
56 .val
= ZD_OFDM_RATE_12M
,
57 .flags
= IEEE80211_RATE_OFDM
},
59 .val
= ZD_OFDM_RATE_18M
,
60 .flags
= IEEE80211_RATE_OFDM
},
62 .val
= ZD_OFDM_RATE_24M
,
63 .flags
= IEEE80211_RATE_OFDM
},
65 .val
= ZD_OFDM_RATE_36M
,
66 .flags
= IEEE80211_RATE_OFDM
},
68 .val
= ZD_OFDM_RATE_48M
,
69 .flags
= IEEE80211_RATE_OFDM
},
71 .val
= ZD_OFDM_RATE_54M
,
72 .flags
= IEEE80211_RATE_OFDM
},
75 static const struct ieee80211_channel zd_channels
[] = {
106 static void housekeeping_init(struct zd_mac
*mac
);
107 static void housekeeping_enable(struct zd_mac
*mac
);
108 static void housekeeping_disable(struct zd_mac
*mac
);
110 int zd_mac_preinit_hw(struct ieee80211_hw
*hw
)
114 struct zd_mac
*mac
= zd_hw_mac(hw
);
116 r
= zd_chip_read_mac_addr_fw(&mac
->chip
, addr
);
120 SET_IEEE80211_PERM_ADDR(hw
, addr
);
125 int zd_mac_init_hw(struct ieee80211_hw
*hw
)
128 struct zd_mac
*mac
= zd_hw_mac(hw
);
129 struct zd_chip
*chip
= &mac
->chip
;
130 u8 default_regdomain
;
132 r
= zd_chip_enable_int(chip
);
135 r
= zd_chip_init_hw(chip
);
139 ZD_ASSERT(!irqs_disabled());
141 r
= zd_read_regdomain(chip
, &default_regdomain
);
144 spin_lock_irq(&mac
->lock
);
145 mac
->regdomain
= mac
->default_regdomain
= default_regdomain
;
146 spin_unlock_irq(&mac
->lock
);
148 /* We must inform the device that we are doing encryption/decryption in
149 * software at the moment. */
150 r
= zd_set_encryption_type(chip
, ENC_SNIFFER
);
154 zd_geo_init(hw
, mac
->regdomain
);
158 zd_chip_disable_int(chip
);
163 void zd_mac_clear(struct zd_mac
*mac
)
165 flush_workqueue(zd_workqueue
);
166 zd_chip_clear(&mac
->chip
);
167 ZD_ASSERT(!spin_is_locked(&mac
->lock
));
168 ZD_MEMCLEAR(mac
, sizeof(struct zd_mac
));
171 static int set_rx_filter(struct zd_mac
*mac
)
174 u32 filter
= STA_RX_FILTER
;
176 spin_lock_irqsave(&mac
->lock
, flags
);
178 filter
|= RX_FILTER_CTRL
;
179 spin_unlock_irqrestore(&mac
->lock
, flags
);
181 return zd_iowrite32(&mac
->chip
, CR_RX_FILTER
, filter
);
184 static int set_mc_hash(struct zd_mac
*mac
)
186 struct zd_mc_hash hash
;
188 return zd_chip_set_multicast_hash(&mac
->chip
, &hash
);
191 static int zd_op_start(struct ieee80211_hw
*hw
)
193 struct zd_mac
*mac
= zd_hw_mac(hw
);
194 struct zd_chip
*chip
= &mac
->chip
;
195 struct zd_usb
*usb
= &chip
->usb
;
198 if (!usb
->initialized
) {
199 r
= zd_usb_init_hw(usb
);
204 r
= zd_chip_enable_int(chip
);
208 r
= zd_chip_set_basic_rates(chip
, CR_RATES_80211B
| CR_RATES_80211G
);
211 r
= set_rx_filter(mac
);
214 r
= set_mc_hash(mac
);
217 r
= zd_chip_switch_radio_on(chip
);
220 r
= zd_chip_enable_rxtx(chip
);
223 r
= zd_chip_enable_hwint(chip
);
227 housekeeping_enable(mac
);
230 zd_chip_disable_rxtx(chip
);
232 zd_chip_switch_radio_off(chip
);
234 zd_chip_disable_int(chip
);
240 * clear_tx_skb_control_block - clears the control block of tx skbuffs
241 * @skb: a &struct sk_buff pointer
243 * This clears the control block of skbuff buffers, which were transmitted to
244 * the device. Notify that the function is not thread-safe, so prevent
247 static void clear_tx_skb_control_block(struct sk_buff
*skb
)
249 struct zd_tx_skb_control_block
*cb
=
250 (struct zd_tx_skb_control_block
*)skb
->cb
;
257 * kfree_tx_skb - frees a tx skbuff
258 * @skb: a &struct sk_buff pointer
260 * Frees the tx skbuff. Frees also the allocated control structure in the
261 * control block if necessary.
263 static void kfree_tx_skb(struct sk_buff
*skb
)
265 clear_tx_skb_control_block(skb
);
266 dev_kfree_skb_any(skb
);
269 static void zd_op_stop(struct ieee80211_hw
*hw
)
271 struct zd_mac
*mac
= zd_hw_mac(hw
);
272 struct zd_chip
*chip
= &mac
->chip
;
274 struct sk_buff_head
*ack_wait_queue
= &mac
->ack_wait_queue
;
276 /* The order here deliberately is a little different from the open()
277 * method, since we need to make sure there is no opportunity for RX
278 * frames to be processed by mac80211 after we have stopped it.
281 zd_chip_disable_rxtx(chip
);
282 housekeeping_disable(mac
);
283 flush_workqueue(zd_workqueue
);
285 zd_chip_disable_hwint(chip
);
286 zd_chip_switch_radio_off(chip
);
287 zd_chip_disable_int(chip
);
290 while ((skb
= skb_dequeue(ack_wait_queue
)))
295 * init_tx_skb_control_block - initializes skb control block
296 * @skb: a &sk_buff pointer
297 * @dev: pointer to the mac80221 device
298 * @control: mac80211 tx control applying for the frame in @skb
300 * Initializes the control block of the skbuff to be transmitted.
302 static int init_tx_skb_control_block(struct sk_buff
*skb
,
303 struct ieee80211_hw
*hw
,
304 struct ieee80211_tx_control
*control
)
306 struct zd_tx_skb_control_block
*cb
=
307 (struct zd_tx_skb_control_block
*)skb
->cb
;
309 ZD_ASSERT(sizeof(*cb
) <= sizeof(skb
->cb
));
310 memset(cb
, 0, sizeof(*cb
));
312 cb
->control
= kmalloc(sizeof(*control
), GFP_ATOMIC
);
313 if (cb
->control
== NULL
)
315 memcpy(cb
->control
, control
, sizeof(*control
));
321 * tx_status - reports tx status of a packet if required
322 * @hw - a &struct ieee80211_hw pointer
324 * @status - the tx status of the packet without control information
325 * @success - True for successfull transmission of the frame
327 * This information calls ieee80211_tx_status_irqsafe() if required by the
328 * control information. It copies the control information into the status
331 * If no status information has been requested, the skb is freed.
333 static void tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
334 struct ieee80211_tx_status
*status
,
337 struct zd_tx_skb_control_block
*cb
= (struct zd_tx_skb_control_block
*)
340 ZD_ASSERT(cb
->control
!= NULL
);
341 memcpy(&status
->control
, cb
->control
, sizeof(status
->control
));
343 status
->excessive_retries
= 1;
344 clear_tx_skb_control_block(skb
);
345 ieee80211_tx_status_irqsafe(hw
, skb
, status
);
349 * zd_mac_tx_failed - callback for failed frames
350 * @dev: the mac80211 wireless device
352 * This function is called if a frame couldn't be succesfully be
353 * transferred. The first frame from the tx queue, will be selected and
354 * reported as error to the upper layers.
356 void zd_mac_tx_failed(struct ieee80211_hw
*hw
)
358 struct sk_buff_head
*q
= &zd_hw_mac(hw
)->ack_wait_queue
;
360 struct ieee80211_tx_status status
= {{0}};
362 skb
= skb_dequeue(q
);
365 tx_status(hw
, skb
, &status
, 0);
369 * zd_mac_tx_to_dev - callback for USB layer
370 * @skb: a &sk_buff pointer
371 * @error: error value, 0 if transmission successful
373 * Informs the MAC layer that the frame has successfully transferred to the
374 * device. If an ACK is required and the transfer to the device has been
375 * successful, the packets are put on the @ack_wait_queue with
376 * the control set removed.
378 void zd_mac_tx_to_dev(struct sk_buff
*skb
, int error
)
380 struct zd_tx_skb_control_block
*cb
=
381 (struct zd_tx_skb_control_block
*)skb
->cb
;
382 struct ieee80211_hw
*hw
= cb
->hw
;
384 if (likely(cb
->control
)) {
385 skb_pull(skb
, sizeof(struct zd_ctrlset
));
386 if (unlikely(error
||
387 (cb
->control
->flags
& IEEE80211_TXCTL_NO_ACK
)))
389 struct ieee80211_tx_status status
= {{0}};
390 tx_status(hw
, skb
, &status
, !error
);
392 struct sk_buff_head
*q
=
393 &zd_hw_mac(hw
)->ack_wait_queue
;
395 skb_queue_tail(q
, skb
);
396 while (skb_queue_len(q
) > ZD_MAC_MAX_ACK_WAITERS
)
397 zd_mac_tx_failed(hw
);
404 static int zd_calc_tx_length_us(u8
*service
, u8 zd_rate
, u16 tx_length
)
406 /* ZD_PURE_RATE() must be used to remove the modulation type flag of
407 * the zd-rate values.
409 static const u8 rate_divisor
[] = {
410 [ZD_PURE_RATE(ZD_CCK_RATE_1M
)] = 1,
411 [ZD_PURE_RATE(ZD_CCK_RATE_2M
)] = 2,
412 /* Bits must be doubled. */
413 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M
)] = 11,
414 [ZD_PURE_RATE(ZD_CCK_RATE_11M
)] = 11,
415 [ZD_PURE_RATE(ZD_OFDM_RATE_6M
)] = 6,
416 [ZD_PURE_RATE(ZD_OFDM_RATE_9M
)] = 9,
417 [ZD_PURE_RATE(ZD_OFDM_RATE_12M
)] = 12,
418 [ZD_PURE_RATE(ZD_OFDM_RATE_18M
)] = 18,
419 [ZD_PURE_RATE(ZD_OFDM_RATE_24M
)] = 24,
420 [ZD_PURE_RATE(ZD_OFDM_RATE_36M
)] = 36,
421 [ZD_PURE_RATE(ZD_OFDM_RATE_48M
)] = 48,
422 [ZD_PURE_RATE(ZD_OFDM_RATE_54M
)] = 54,
425 u32 bits
= (u32
)tx_length
* 8;
428 divisor
= rate_divisor
[ZD_PURE_RATE(zd_rate
)];
433 case ZD_CCK_RATE_5_5M
:
434 bits
= (2*bits
) + 10; /* round up to the next integer */
436 case ZD_CCK_RATE_11M
:
439 *service
&= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION
;
440 if (0 < t
&& t
<= 3) {
441 *service
|= ZD_PLCP_SERVICE_LENGTH_EXTENSION
;
444 bits
+= 10; /* round up to the next integer */
451 static void cs_set_control(struct zd_mac
*mac
, struct zd_ctrlset
*cs
,
452 struct ieee80211_hdr
*header
, u32 flags
)
454 u16 fctl
= le16_to_cpu(header
->frame_control
);
458 * - if backoff needed, enable bit 0
459 * - if burst (backoff not needed) disable bit 0
465 if (flags
& IEEE80211_TXCTL_FIRST_FRAGMENT
)
466 cs
->control
|= ZD_CS_NEED_RANDOM_BACKOFF
;
469 if (is_multicast_ether_addr(header
->addr1
))
470 cs
->control
|= ZD_CS_MULTICAST
;
473 if ((fctl
& (IEEE80211_FCTL_FTYPE
|IEEE80211_FCTL_STYPE
)) ==
474 (IEEE80211_FTYPE_CTL
|IEEE80211_STYPE_PSPOLL
))
475 cs
->control
|= ZD_CS_PS_POLL_FRAME
;
477 if (flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
478 cs
->control
|= ZD_CS_RTS
;
480 if (flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
)
481 cs
->control
|= ZD_CS_SELF_CTS
;
483 /* FIXME: Management frame? */
486 static int fill_ctrlset(struct zd_mac
*mac
,
488 struct ieee80211_tx_control
*control
)
491 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
492 unsigned int frag_len
= skb
->len
+ FCS_LEN
;
493 unsigned int packet_length
;
494 struct zd_ctrlset
*cs
= (struct zd_ctrlset
*)
495 skb_push(skb
, sizeof(struct zd_ctrlset
));
497 ZD_ASSERT(frag_len
<= 0xffff);
499 cs
->modulation
= control
->tx_rate
;
501 cs
->tx_length
= cpu_to_le16(frag_len
);
503 cs_set_control(mac
, cs
, hdr
, control
->flags
);
505 packet_length
= frag_len
+ sizeof(struct zd_ctrlset
) + 10;
506 ZD_ASSERT(packet_length
<= 0xffff);
507 /* ZD1211B: Computing the length difference this way, gives us
508 * flexibility to compute the packet length.
510 cs
->packet_length
= cpu_to_le16(zd_chip_is_zd1211b(&mac
->chip
) ?
511 packet_length
- frag_len
: packet_length
);
515 * - transmit frame length in microseconds
516 * - seems to be derived from frame length
517 * - see Cal_Us_Service() in zdinlinef.h
518 * - if macp->bTxBurstEnable is enabled, then multiply by 4
519 * - bTxBurstEnable is never set in the vendor driver
522 * - "for PLCP configuration"
523 * - always 0 except in some situations at 802.11b 11M
524 * - see line 53 of zdinlinef.h
527 r
= zd_calc_tx_length_us(&cs
->service
, ZD_RATE(cs
->modulation
),
528 le16_to_cpu(cs
->tx_length
));
531 cs
->current_length
= cpu_to_le16(r
);
532 cs
->next_frame_length
= 0;
538 * zd_op_tx - transmits a network frame to the device
540 * @dev: mac80211 hardware device
541 * @skb: socket buffer
542 * @control: the control structure
544 * This function transmit an IEEE 802.11 network frame to the device. The
545 * control block of the skbuff will be initialized. If necessary the incoming
546 * mac80211 queues will be stopped.
548 static int zd_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
549 struct ieee80211_tx_control
*control
)
551 struct zd_mac
*mac
= zd_hw_mac(hw
);
554 r
= fill_ctrlset(mac
, skb
, control
);
558 r
= init_tx_skb_control_block(skb
, hw
, control
);
561 r
= zd_usb_tx(&mac
->chip
.usb
, skb
);
563 clear_tx_skb_control_block(skb
);
570 * filter_ack - filters incoming packets for acknowledgements
571 * @dev: the mac80211 device
572 * @rx_hdr: received header
573 * @stats: the status for the received packet
575 * This functions looks for ACK packets and tries to match them with the
576 * frames in the tx queue. If a match is found the frame will be dequeued and
577 * the upper layers is informed about the successful transmission. If
578 * mac80211 queues have been stopped and the number of frames still to be
579 * transmitted is low the queues will be opened again.
581 * Returns 1 if the frame was an ACK, 0 if it was ignored.
583 static int filter_ack(struct ieee80211_hw
*hw
, struct ieee80211_hdr
*rx_hdr
,
584 struct ieee80211_rx_status
*stats
)
586 u16 fc
= le16_to_cpu(rx_hdr
->frame_control
);
588 struct sk_buff_head
*q
;
591 if ((fc
& (IEEE80211_FCTL_FTYPE
| IEEE80211_FCTL_STYPE
)) !=
592 (IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_ACK
))
595 q
= &zd_hw_mac(hw
)->ack_wait_queue
;
596 spin_lock_irqsave(&q
->lock
, flags
);
597 for (skb
= q
->next
; skb
!= (struct sk_buff
*)q
; skb
= skb
->next
) {
598 struct ieee80211_hdr
*tx_hdr
;
600 tx_hdr
= (struct ieee80211_hdr
*)skb
->data
;
601 if (likely(!compare_ether_addr(tx_hdr
->addr2
, rx_hdr
->addr1
)))
603 struct ieee80211_tx_status status
= {{0}};
604 status
.flags
= IEEE80211_TX_STATUS_ACK
;
605 status
.ack_signal
= stats
->ssi
;
606 __skb_unlink(skb
, q
);
607 tx_status(hw
, skb
, &status
, 1);
612 spin_unlock_irqrestore(&q
->lock
, flags
);
616 int zd_mac_rx(struct ieee80211_hw
*hw
, const u8
*buffer
, unsigned int length
)
618 struct zd_mac
*mac
= zd_hw_mac(hw
);
619 struct ieee80211_rx_status stats
;
620 const struct rx_status
*status
;
624 if (length
< ZD_PLCP_HEADER_SIZE
+ 10 /* IEEE80211_1ADDR_LEN */ +
625 FCS_LEN
+ sizeof(struct rx_status
))
628 memset(&stats
, 0, sizeof(stats
));
630 /* Note about pass_failed_fcs and pass_ctrl access below:
631 * mac locking intentionally omitted here, as this is the only unlocked
632 * reader and the only writer is configure_filter. Plus, if there were
633 * any races accessing these variables, it wouldn't really matter.
634 * If mac80211 ever provides a way for us to access filter flags
635 * from outside configure_filter, we could improve on this. Also, this
636 * situation may change once we implement some kind of DMA-into-skb
639 /* Caller has to ensure that length >= sizeof(struct rx_status). */
640 status
= (struct rx_status
*)
641 (buffer
+ (length
- sizeof(struct rx_status
)));
642 if (status
->frame_status
& ZD_RX_ERROR
) {
643 if (mac
->pass_failed_fcs
&&
644 (status
->frame_status
& ZD_RX_CRC32_ERROR
)) {
645 stats
.flag
|= RX_FLAG_FAILED_FCS_CRC
;
652 stats
.channel
= _zd_chip_get_channel(&mac
->chip
);
653 stats
.freq
= zd_channels
[stats
.channel
- 1].freq
;
654 stats
.phymode
= MODE_IEEE80211G
;
655 stats
.ssi
= status
->signal_strength
;
656 stats
.signal
= zd_rx_qual_percent(buffer
,
657 length
- sizeof(struct rx_status
),
659 stats
.rate
= zd_rx_rate(buffer
, status
);
661 length
-= ZD_PLCP_HEADER_SIZE
+ sizeof(struct rx_status
);
662 buffer
+= ZD_PLCP_HEADER_SIZE
;
664 /* Except for bad frames, filter each frame to see if it is an ACK, in
665 * which case our internal TX tracking is updated. Normally we then
666 * bail here as there's no need to pass ACKs on up to the stack, but
667 * there is also the case where the stack has requested us to pass
668 * control frames on up (pass_ctrl) which we must consider. */
670 filter_ack(hw
, (struct ieee80211_hdr
*)buffer
, &stats
)
674 skb
= dev_alloc_skb(length
);
677 memcpy(skb_put(skb
, length
), buffer
, length
);
679 ieee80211_rx_irqsafe(hw
, skb
, &stats
);
683 static int zd_op_add_interface(struct ieee80211_hw
*hw
,
684 struct ieee80211_if_init_conf
*conf
)
686 struct zd_mac
*mac
= zd_hw_mac(hw
);
688 /* using IEEE80211_IF_TYPE_INVALID to indicate no mode selected */
689 if (mac
->type
!= IEEE80211_IF_TYPE_INVALID
)
692 switch (conf
->type
) {
693 case IEEE80211_IF_TYPE_MNTR
:
694 case IEEE80211_IF_TYPE_STA
:
695 mac
->type
= conf
->type
;
701 return zd_write_mac_addr(&mac
->chip
, conf
->mac_addr
);
704 static void zd_op_remove_interface(struct ieee80211_hw
*hw
,
705 struct ieee80211_if_init_conf
*conf
)
707 struct zd_mac
*mac
= zd_hw_mac(hw
);
708 mac
->type
= IEEE80211_IF_TYPE_INVALID
;
709 zd_write_mac_addr(&mac
->chip
, NULL
);
712 static int zd_op_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
714 struct zd_mac
*mac
= zd_hw_mac(hw
);
715 return zd_chip_set_channel(&mac
->chip
, conf
->channel
);
718 static int zd_op_config_interface(struct ieee80211_hw
*hw
, int if_id
,
719 struct ieee80211_if_conf
*conf
)
721 struct zd_mac
*mac
= zd_hw_mac(hw
);
723 spin_lock_irq(&mac
->lock
);
724 mac
->associated
= is_valid_ether_addr(conf
->bssid
);
725 spin_unlock_irq(&mac
->lock
);
727 /* TODO: do hardware bssid filtering */
731 static void set_multicast_hash_handler(struct work_struct
*work
)
734 container_of(work
, struct zd_mac
, set_multicast_hash_work
);
735 struct zd_mc_hash hash
;
737 spin_lock_irq(&mac
->lock
);
738 hash
= mac
->multicast_hash
;
739 spin_unlock_irq(&mac
->lock
);
741 zd_chip_set_multicast_hash(&mac
->chip
, &hash
);
744 static void set_rx_filter_handler(struct work_struct
*work
)
747 container_of(work
, struct zd_mac
, set_rx_filter_work
);
750 dev_dbg_f(zd_mac_dev(mac
), "\n");
751 r
= set_rx_filter(mac
);
753 dev_err(zd_mac_dev(mac
), "set_rx_filter_handler error %d\n", r
);
756 #define SUPPORTED_FIF_FLAGS \
757 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
759 static void zd_op_configure_filter(struct ieee80211_hw
*hw
,
760 unsigned int changed_flags
,
761 unsigned int *new_flags
,
762 int mc_count
, struct dev_mc_list
*mclist
)
764 struct zd_mc_hash hash
;
765 struct zd_mac
*mac
= zd_hw_mac(hw
);
769 /* Only deal with supported flags */
770 changed_flags
&= SUPPORTED_FIF_FLAGS
;
771 *new_flags
&= SUPPORTED_FIF_FLAGS
;
773 /* changed_flags is always populated but this driver
774 * doesn't support all FIF flags so its possible we don't
775 * need to do anything */
779 if (*new_flags
& (FIF_PROMISC_IN_BSS
| FIF_ALLMULTI
)) {
780 zd_mc_add_all(&hash
);
782 DECLARE_MAC_BUF(macbuf
);
785 for (i
= 0; i
< mc_count
; i
++) {
788 dev_dbg_f(zd_mac_dev(mac
), "mc addr %s\n",
789 print_mac(macbuf
, mclist
->dmi_addr
));
790 zd_mc_add_addr(&hash
, mclist
->dmi_addr
);
791 mclist
= mclist
->next
;
795 spin_lock_irqsave(&mac
->lock
, flags
);
796 mac
->pass_failed_fcs
= !!(*new_flags
& FIF_FCSFAIL
);
797 mac
->pass_ctrl
= !!(*new_flags
& FIF_CONTROL
);
798 mac
->multicast_hash
= hash
;
799 spin_unlock_irqrestore(&mac
->lock
, flags
);
800 queue_work(zd_workqueue
, &mac
->set_multicast_hash_work
);
802 if (changed_flags
& FIF_CONTROL
)
803 queue_work(zd_workqueue
, &mac
->set_rx_filter_work
);
805 /* no handling required for FIF_OTHER_BSS as we don't currently
806 * do BSSID filtering */
807 /* FIXME: in future it would be nice to enable the probe response
808 * filter (so that the driver doesn't see them) until
809 * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
810 * have to schedule work to enable prbresp reception, which might
811 * happen too late. For now we'll just listen and forward them all the
815 static void set_rts_cts_work(struct work_struct
*work
)
818 container_of(work
, struct zd_mac
, set_rts_cts_work
);
820 unsigned int short_preamble
;
822 mutex_lock(&mac
->chip
.mutex
);
824 spin_lock_irqsave(&mac
->lock
, flags
);
825 mac
->updating_rts_rate
= 0;
826 short_preamble
= mac
->short_preamble
;
827 spin_unlock_irqrestore(&mac
->lock
, flags
);
829 zd_chip_set_rts_cts_rate_locked(&mac
->chip
, short_preamble
);
830 mutex_unlock(&mac
->chip
.mutex
);
833 static void zd_op_erp_ie_changed(struct ieee80211_hw
*hw
, u8 changes
,
834 int cts_protection
, int preamble
)
836 struct zd_mac
*mac
= zd_hw_mac(hw
);
839 dev_dbg_f(zd_mac_dev(mac
), "changes: %x\n", changes
);
841 if (changes
& IEEE80211_ERP_CHANGE_PREAMBLE
) {
842 spin_lock_irqsave(&mac
->lock
, flags
);
843 mac
->short_preamble
= !preamble
;
844 if (!mac
->updating_rts_rate
) {
845 mac
->updating_rts_rate
= 1;
846 /* FIXME: should disable TX here, until work has
847 * completed and RTS_CTS reg is updated */
848 queue_work(zd_workqueue
, &mac
->set_rts_cts_work
);
850 spin_unlock_irqrestore(&mac
->lock
, flags
);
854 static const struct ieee80211_ops zd_ops
= {
856 .start
= zd_op_start
,
858 .add_interface
= zd_op_add_interface
,
859 .remove_interface
= zd_op_remove_interface
,
860 .config
= zd_op_config
,
861 .config_interface
= zd_op_config_interface
,
862 .configure_filter
= zd_op_configure_filter
,
863 .erp_ie_changed
= zd_op_erp_ie_changed
,
866 struct ieee80211_hw
*zd_mac_alloc_hw(struct usb_interface
*intf
)
869 struct ieee80211_hw
*hw
;
872 hw
= ieee80211_alloc_hw(sizeof(struct zd_mac
), &zd_ops
);
874 dev_dbg_f(&intf
->dev
, "out of memory\n");
880 memset(mac
, 0, sizeof(*mac
));
881 spin_lock_init(&mac
->lock
);
884 mac
->type
= IEEE80211_IF_TYPE_INVALID
;
886 memcpy(mac
->channels
, zd_channels
, sizeof(zd_channels
));
887 memcpy(mac
->rates
, zd_rates
, sizeof(zd_rates
));
888 mac
->modes
[0].mode
= MODE_IEEE80211G
;
889 mac
->modes
[0].num_rates
= ARRAY_SIZE(zd_rates
);
890 mac
->modes
[0].rates
= mac
->rates
;
891 mac
->modes
[0].num_channels
= ARRAY_SIZE(zd_channels
);
892 mac
->modes
[0].channels
= mac
->channels
;
893 mac
->modes
[1].mode
= MODE_IEEE80211B
;
894 mac
->modes
[1].num_rates
= 4;
895 mac
->modes
[1].rates
= mac
->rates
;
896 mac
->modes
[1].num_channels
= ARRAY_SIZE(zd_channels
);
897 mac
->modes
[1].channels
= mac
->channels
;
899 hw
->flags
= IEEE80211_HW_RX_INCLUDES_FCS
|
900 IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
;
902 hw
->max_signal
= 100;
905 hw
->extra_tx_headroom
= sizeof(struct zd_ctrlset
);
907 skb_queue_head_init(&mac
->ack_wait_queue
);
909 for (i
= 0; i
< 2; i
++) {
910 if (ieee80211_register_hwmode(hw
, &mac
->modes
[i
])) {
911 dev_dbg_f(&intf
->dev
, "cannot register hwmode\n");
912 ieee80211_free_hw(hw
);
917 zd_chip_init(&mac
->chip
, hw
, intf
);
918 housekeeping_init(mac
);
919 INIT_WORK(&mac
->set_multicast_hash_work
, set_multicast_hash_handler
);
920 INIT_WORK(&mac
->set_rts_cts_work
, set_rts_cts_work
);
921 INIT_WORK(&mac
->set_rx_filter_work
, set_rx_filter_handler
);
923 SET_IEEE80211_DEV(hw
, &intf
->dev
);
927 #define LINK_LED_WORK_DELAY HZ
929 static void link_led_handler(struct work_struct
*work
)
932 container_of(work
, struct zd_mac
, housekeeping
.link_led_work
.work
);
933 struct zd_chip
*chip
= &mac
->chip
;
937 spin_lock_irq(&mac
->lock
);
938 is_associated
= mac
->associated
;
939 spin_unlock_irq(&mac
->lock
);
941 r
= zd_chip_control_leds(chip
,
942 is_associated
? LED_ASSOCIATED
: LED_SCANNING
);
944 dev_dbg_f(zd_mac_dev(mac
), "zd_chip_control_leds error %d\n", r
);
946 queue_delayed_work(zd_workqueue
, &mac
->housekeeping
.link_led_work
,
947 LINK_LED_WORK_DELAY
);
950 static void housekeeping_init(struct zd_mac
*mac
)
952 INIT_DELAYED_WORK(&mac
->housekeeping
.link_led_work
, link_led_handler
);
955 static void housekeeping_enable(struct zd_mac
*mac
)
957 dev_dbg_f(zd_mac_dev(mac
), "\n");
958 queue_delayed_work(zd_workqueue
, &mac
->housekeeping
.link_led_work
,
962 static void housekeeping_disable(struct zd_mac
*mac
)
964 dev_dbg_f(zd_mac_dev(mac
), "\n");
965 cancel_rearming_delayed_workqueue(zd_workqueue
,
966 &mac
->housekeeping
.link_led_work
);
967 zd_chip_control_leds(&mac
->chip
, LED_OFF
);