2 * Atheros AR9170 driver
4 * mac80211 interaction code
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, Christian Lamparter <chunkeey@web.de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
23 * This file incorporates work covered by the following copyright and
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 #include <linux/init.h>
41 #include <linux/module.h>
42 #include <linux/etherdevice.h>
43 #include <net/mac80211.h>
48 static int modparam_nohwcrypt;
49 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
50 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
52 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
53 .bitrate = (_bitrate), \
55 .hw_value = (_hw_rate) | (_txpidx) << 4, \
58 static struct ieee80211_rate __ar9170_ratetable[] = {
60 RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE),
61 RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE),
62 RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE),
74 #define ar9170_g_ratetable (__ar9170_ratetable + 0)
75 #define ar9170_g_ratetable_size 12
76 #define ar9170_a_ratetable (__ar9170_ratetable + 4)
77 #define ar9170_a_ratetable_size 8
80 * NB: The hw_value is used as an index into the ar9170_phy_freq_params
81 * array in phy.c so that we don't have to do frequency lookups!
83 #define CHAN(_freq, _idx) { \
84 .center_freq = (_freq), \
86 .max_power = 18, /* XXX */ \
89 static struct ieee80211_channel ar9170_2ghz_chantable[] = {
106 static struct ieee80211_channel ar9170_5ghz_chantable[] = {
145 #define AR9170_HT_CAP \
147 .ht_supported = true, \
148 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
149 IEEE80211_HT_CAP_SM_PS | \
150 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
151 IEEE80211_HT_CAP_SGI_40 | \
152 IEEE80211_HT_CAP_DSSSCCK40 | \
153 IEEE80211_HT_CAP_SM_PS, \
154 .ampdu_factor = 3, /* ?? */ \
155 .ampdu_density = 7, /* ?? */ \
157 .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \
161 static struct ieee80211_supported_band ar9170_band_2GHz = {
162 .channels = ar9170_2ghz_chantable,
163 .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable),
164 .bitrates = ar9170_g_ratetable,
165 .n_bitrates = ar9170_g_ratetable_size,
166 .ht_cap = AR9170_HT_CAP,
169 static struct ieee80211_supported_band ar9170_band_5GHz = {
170 .channels = ar9170_5ghz_chantable,
171 .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable),
172 .bitrates = ar9170_a_ratetable,
173 .n_bitrates = ar9170_a_ratetable_size,
174 .ht_cap = AR9170_HT_CAP,
177 #ifdef AR9170_QUEUE_DEBUG
179 * In case some wants works with AR9170's crazy tx_status queueing techniques.
180 * He might need this rather useful probing function.
182 * NOTE: caller must hold the queue's spinlock!
185 static void ar9170_print_txheader(struct ar9170 *ar, struct sk_buff *skb)
187 struct ar9170_tx_control *txc = (void *) skb->data;
188 struct ieee80211_hdr *hdr = (void *)txc->frame_data;
190 printk(KERN_DEBUG "%s: => FRAME [skb:%p, queue:%d, DA:[%pM] "
191 "mac_control:%04x, phy_control:%08x]\n",
192 wiphy_name(ar->hw->wiphy), skb, skb_get_queue_mapping(skb),
193 ieee80211_get_DA(hdr), le16_to_cpu(txc->mac_control),
194 le32_to_cpu(txc->phy_control));
197 static void ar9170_dump_station_tx_status_queue(struct ar9170 *ar,
198 struct sk_buff_head *queue)
203 printk(KERN_DEBUG "---[ cut here ]---\n");
204 printk(KERN_DEBUG "%s: %d entries in tx_status queue.\n",
205 wiphy_name(ar->hw->wiphy), skb_queue_len(queue));
207 skb_queue_walk(queue, skb) {
208 struct ar9170_tx_control *txc = (void *) skb->data;
209 struct ieee80211_hdr *hdr = (void *)txc->frame_data;
211 printk(KERN_DEBUG "index:%d => \n", i);
212 ar9170_print_txheader(ar, skb);
214 printk(KERN_DEBUG "---[ end ]---\n");
216 #endif /* AR9170_QUEUE_DEBUG */
218 void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb,
219 bool valid_status, u16 tx_status)
221 struct ieee80211_tx_info *txinfo;
222 unsigned int retries = 0, queue = skb_get_queue_mapping(skb);
225 spin_lock_irqsave(&ar->tx_stats_lock, flags);
226 ar->tx_stats[queue].len--;
227 if (ieee80211_queue_stopped(ar->hw, queue))
228 ieee80211_wake_queue(ar->hw, queue);
229 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
231 txinfo = IEEE80211_SKB_CB(skb);
232 ieee80211_tx_info_clear_status(txinfo);
235 case AR9170_TX_STATUS_RETRY:
237 case AR9170_TX_STATUS_COMPLETE:
238 txinfo->flags |= IEEE80211_TX_STAT_ACK;
241 case AR9170_TX_STATUS_FAILED:
242 retries = ar->hw->conf.long_frame_max_tx_count;
246 printk(KERN_ERR "%s: invalid tx_status response (%x).\n",
247 wiphy_name(ar->hw->wiphy), tx_status);
252 txinfo->status.rates[0].count = retries + 1;
254 skb_pull(skb, sizeof(struct ar9170_tx_control));
255 ieee80211_tx_status_irqsafe(ar->hw, skb);
258 static struct sk_buff *ar9170_find_skb_in_queue(struct ar9170 *ar,
261 struct sk_buff_head *q)
266 spin_lock_irqsave(&q->lock, flags);
267 skb_queue_walk(q, skb) {
268 struct ar9170_tx_control *txc = (void *) skb->data;
269 struct ieee80211_hdr *hdr = (void *) txc->frame_data;
270 u32 txc_queue = (le32_to_cpu(txc->phy_control) &
271 AR9170_TX_PHY_QOS_MASK) >>
272 AR9170_TX_PHY_QOS_SHIFT;
274 if ((queue != txc_queue) ||
275 (compare_ether_addr(ieee80211_get_DA(hdr), mac)))
278 __skb_unlink(skb, q);
279 spin_unlock_irqrestore(&q->lock, flags);
282 spin_unlock_irqrestore(&q->lock, flags);
286 static struct sk_buff *ar9170_find_queued_skb(struct ar9170 *ar, const u8 *mac,
289 struct ieee80211_sta *sta;
293 * Unfortunately, the firmware does not tell to which (queued) frame
294 * this transmission status report belongs to.
296 * So we have to make risky guesses - with the scarce information
297 * the firmware provided (-> destination MAC, and phy_control) -
298 * and hope that we picked the right one...
301 sta = ieee80211_find_sta(ar->hw, mac);
304 struct ar9170_sta_info *sta_priv = (void *) sta->drv_priv;
305 skb = skb_dequeue(&sta_priv->tx_status[queue]);
312 /* scan the waste queue for candidates */
313 skb = ar9170_find_skb_in_queue(ar, mac, queue,
314 &ar->global_tx_status_waste);
316 /* so it still _must_ be in the global list. */
317 skb = ar9170_find_skb_in_queue(ar, mac, queue,
318 &ar->global_tx_status);
321 #ifdef AR9170_QUEUE_DEBUG
322 if (unlikely((!skb) && net_ratelimit())) {
323 printk(KERN_ERR "%s: ESS:[%pM] does not have any "
324 "outstanding frames in this queue (%d).\n",
325 wiphy_name(ar->hw->wiphy), mac, queue);
327 #endif /* AR9170_QUEUE_DEBUG */
332 * This worker tries to keep the global tx_status queue empty.
333 * So we can guarantee that incoming tx_status reports for
334 * unregistered stations are always synced with the actual
335 * frame - which we think - belongs to.
338 static void ar9170_tx_status_janitor(struct work_struct *work)
340 struct ar9170 *ar = container_of(work, struct ar9170,
341 tx_status_janitor.work);
344 if (unlikely(!IS_STARTED(ar)))
347 mutex_lock(&ar->mutex);
348 /* recycle the garbage back to mac80211... one by one. */
349 while ((skb = skb_dequeue(&ar->global_tx_status_waste))) {
350 #ifdef AR9170_QUEUE_DEBUG
351 printk(KERN_DEBUG "%s: dispose queued frame =>\n",
352 wiphy_name(ar->hw->wiphy));
353 ar9170_print_txheader(ar, skb);
354 #endif /* AR9170_QUEUE_DEBUG */
355 ar9170_handle_tx_status(ar, skb, false,
356 AR9170_TX_STATUS_FAILED);
359 while ((skb = skb_dequeue(&ar->global_tx_status))) {
360 #ifdef AR9170_QUEUE_DEBUG
361 printk(KERN_DEBUG "%s: moving frame into waste queue =>\n",
362 wiphy_name(ar->hw->wiphy));
364 ar9170_print_txheader(ar, skb);
365 #endif /* AR9170_QUEUE_DEBUG */
366 skb_queue_tail(&ar->global_tx_status_waste, skb);
369 /* recall the janitor in 100ms - if there's garbage in the can. */
370 if (skb_queue_len(&ar->global_tx_status_waste) > 0)
371 queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor,
372 msecs_to_jiffies(100));
374 mutex_unlock(&ar->mutex);
377 static void ar9170_handle_command_response(struct ar9170 *ar,
380 struct ar9170_cmd_response *cmd = (void *) buf;
382 if ((cmd->type & 0xc0) != 0xc0) {
383 ar->callback_cmd(ar, len, buf);
387 /* hardware event handlers */
391 * TX status notification:
392 * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1
396 * M1-M6 is the MAC address
397 * R1-R4 is the transmit rate
398 * S1-S2 is the transmit status
402 u32 queue = (le32_to_cpu(cmd->tx_status.rate) &
403 AR9170_TX_PHY_QOS_MASK) >> AR9170_TX_PHY_QOS_SHIFT;
405 skb = ar9170_find_queued_skb(ar, cmd->tx_status.dst, queue);
409 ar9170_handle_tx_status(ar, skb, true,
410 le16_to_cpu(cmd->tx_status.status));
418 if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP)
419 queue_work(ar->hw->workqueue, &ar->beacon_work);
424 * (IBSS) beacon send notification
425 * bytes: 04 c2 XX YY B4 B3 B2 B1
429 * B1-B4 "should" be the number of send out beacons.
434 /* End of Atim Window */
439 /* BlockACK events */
443 /* Watchdog Interrupt */
447 /* retransmission issue / SIFS/EIFS collision ?! */
451 printk(KERN_INFO "received unhandled event %x\n", cmd->type);
452 print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len);
458 * If the frame alignment is right (or the kernel has
459 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
460 * is only a single MPDU in the USB frame, then we can
461 * submit to mac80211 the SKB directly. However, since
462 * there may be multiple packets in one SKB in stream
463 * mode, and we need to observe the proper ordering,
464 * this is non-trivial.
466 static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len)
469 struct ar9170_rx_head *head = (void *)buf;
470 struct ar9170_rx_tail *tail;
471 struct ieee80211_rx_status status;
473 u8 error, antennas = 0, decrypt;
477 if (unlikely(!IS_STARTED(ar)))
482 mpdu_len -= sizeof(struct ar9170_rx_head);
483 mpdu_len -= sizeof(struct ar9170_rx_tail);
484 BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12);
485 BUILD_BUG_ON(sizeof(struct ar9170_rx_tail) != 24);
487 if (mpdu_len <= FCS_LEN)
490 tail = (void *)(buf + sizeof(struct ar9170_rx_head) + mpdu_len);
492 for (i = 0; i < 3; i++)
493 if (tail->rssi[i] != 0x80)
496 /* post-process RSSI */
497 for (i = 0; i < 7; i++)
498 if (tail->rssi[i] & 0x80)
499 tail->rssi[i] = ((tail->rssi[i] & 0x7f) + 1) & 0x7f;
501 memset(&status, 0, sizeof(status));
503 status.band = ar->channel->band;
504 status.freq = ar->channel->center_freq;
505 status.signal = ar->noise[0] + tail->rssi_combined;
506 status.noise = ar->noise[0];
507 status.antenna = antennas;
509 switch (tail->status & AR9170_RX_STATUS_MODULATION_MASK) {
510 case AR9170_RX_STATUS_MODULATION_CCK:
511 if (tail->status & AR9170_RX_STATUS_SHORT_PREAMBLE)
512 status.flag |= RX_FLAG_SHORTPRE;
513 switch (head->plcp[0]) {
527 if ((!ar->sniffer_enabled) && (net_ratelimit()))
528 printk(KERN_ERR "%s: invalid plcp cck rate "
529 "(%x).\n", wiphy_name(ar->hw->wiphy),
534 case AR9170_RX_STATUS_MODULATION_OFDM:
535 switch (head->plcp[0] & 0xF) {
561 if ((!ar->sniffer_enabled) && (net_ratelimit()))
562 printk(KERN_ERR "%s: invalid plcp ofdm rate "
563 "(%x).\n", wiphy_name(ar->hw->wiphy),
567 if (status.band == IEEE80211_BAND_2GHZ)
568 status.rate_idx += 4;
570 case AR9170_RX_STATUS_MODULATION_HT:
571 case AR9170_RX_STATUS_MODULATION_DUPOFDM:
575 printk(KERN_ERR "%s: invalid modulation\n",
576 wiphy_name(ar->hw->wiphy));
582 if (error & AR9170_RX_ERROR_MMIC) {
583 status.flag |= RX_FLAG_MMIC_ERROR;
584 error &= ~AR9170_RX_ERROR_MMIC;
587 if (error & AR9170_RX_ERROR_PLCP) {
588 status.flag |= RX_FLAG_FAILED_PLCP_CRC;
589 error &= ~AR9170_RX_ERROR_PLCP;
592 if (error & AR9170_RX_ERROR_FCS) {
593 status.flag |= RX_FLAG_FAILED_FCS_CRC;
594 error &= ~AR9170_RX_ERROR_FCS;
597 decrypt = ar9170_get_decrypt_type(tail);
598 if (!(decrypt & AR9170_RX_ENC_SOFTWARE) &&
599 decrypt != AR9170_ENC_ALG_NONE)
600 status.flag |= RX_FLAG_DECRYPTED;
602 /* ignore wrong RA errors */
603 error &= ~AR9170_RX_ERROR_WRONG_RA;
605 if (error & AR9170_RX_ERROR_DECRYPT) {
606 error &= ~AR9170_RX_ERROR_DECRYPT;
609 * Rx decryption is done in place,
610 * the original data is lost anyway.
615 /* drop any other error frames */
616 if ((error) && (net_ratelimit())) {
617 printk(KERN_DEBUG "%s: errors: %#x\n",
618 wiphy_name(ar->hw->wiphy), error);
622 buf += sizeof(struct ar9170_rx_head);
625 if (ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc))
630 skb = dev_alloc_skb(mpdu_len + reserved);
634 skb_reserve(skb, reserved);
635 memcpy(skb_put(skb, mpdu_len), buf, mpdu_len);
636 ieee80211_rx_irqsafe(ar->hw, skb, &status);
639 void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb)
641 unsigned int i, tlen, resplen;
648 int clen = tbuf[1] << 8 | tbuf[0];
649 int wlen = (clen + 3) & ~3;
652 * parse stream (if any)
654 if (tbuf[2] != 0 || tbuf[3] != 0x4e) {
655 printk(KERN_ERR "%s: missing tag!\n",
656 wiphy_name(ar->hw->wiphy));
659 if (wlen > tlen - 4) {
660 printk(KERN_ERR "%s: invalid RX (%d, %d, %d)\n",
661 wiphy_name(ar->hw->wiphy), clen, wlen, tlen);
662 print_hex_dump(KERN_DEBUG, "data: ",
664 16, 1, tbuf, tlen, true);
674 /* weird thing, but this is the same in the original driver */
675 while (resplen > 2 && i < 12 &&
676 respbuf[0] == 0xff && respbuf[1] == 0xff) {
685 /* found the 6 * 0xffff marker? */
687 ar9170_handle_command_response(ar, respbuf, resplen);
689 ar9170_handle_mpdu(ar, respbuf, resplen);
693 printk(KERN_ERR "%s: buffer remains!\n",
694 wiphy_name(ar->hw->wiphy));
697 #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
699 queue.aifs = ai_fs; \
700 queue.cw_min = cwmin; \
701 queue.cw_max = cwmax; \
702 queue.txop = _txop; \
705 static int ar9170_op_start(struct ieee80211_hw *hw)
707 struct ar9170 *ar = hw->priv;
710 mutex_lock(&ar->mutex);
712 /* reinitialize queues statistics */
713 memset(&ar->tx_stats, 0, sizeof(ar->tx_stats));
714 for (i = 0; i < ARRAY_SIZE(ar->tx_stats); i++)
715 ar->tx_stats[i].limit = 8;
717 /* reset QoS defaults */
718 AR9170_FILL_QUEUE(ar->edcf[0], 3, 15, 1023, 0); /* BEST EFFORT*/
719 AR9170_FILL_QUEUE(ar->edcf[1], 7, 15, 1023, 0); /* BACKGROUND */
720 AR9170_FILL_QUEUE(ar->edcf[2], 2, 7, 15, 94); /* VIDEO */
721 AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */
722 AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */
728 err = ar9170_init_mac(ar);
732 err = ar9170_set_qos(ar);
736 err = ar9170_init_phy(ar, IEEE80211_BAND_2GHZ);
740 err = ar9170_init_rf(ar);
745 err = ar9170_write_reg(ar, 0x1c3d30, 0x100);
749 ar->state = AR9170_STARTED;
752 mutex_unlock(&ar->mutex);
756 static void ar9170_op_stop(struct ieee80211_hw *hw)
758 struct ar9170 *ar = hw->priv;
761 ar->state = AR9170_IDLE;
763 flush_workqueue(ar->hw->workqueue);
765 mutex_lock(&ar->mutex);
766 cancel_delayed_work_sync(&ar->tx_status_janitor);
767 cancel_work_sync(&ar->filter_config_work);
768 cancel_work_sync(&ar->beacon_work);
769 skb_queue_purge(&ar->global_tx_status_waste);
770 skb_queue_purge(&ar->global_tx_status);
772 if (IS_ACCEPTING_CMD(ar)) {
773 ar9170_set_leds_state(ar, 0);
776 ar9170_write_reg(ar, 0x1c3d30, 0);
780 mutex_unlock(&ar->mutex);
783 int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
785 struct ar9170 *ar = hw->priv;
786 struct ieee80211_hdr *hdr;
787 struct ar9170_tx_control *txc;
788 struct ieee80211_tx_info *info;
789 struct ieee80211_rate *rate = NULL;
790 struct ieee80211_tx_rate *txrate;
791 unsigned int queue = skb_get_queue_mapping(skb);
792 unsigned long flags = 0;
793 struct ar9170_sta_info *sta_info = NULL;
800 if (unlikely(!IS_STARTED(ar)))
803 hdr = (void *)skb->data;
804 info = IEEE80211_SKB_CB(skb);
807 spin_lock_irqsave(&ar->tx_stats_lock, flags);
808 if (ar->tx_stats[queue].limit < ar->tx_stats[queue].len) {
809 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
813 ar->tx_stats[queue].len++;
814 ar->tx_stats[queue].count++;
815 if (ar->tx_stats[queue].limit == ar->tx_stats[queue].len)
816 ieee80211_stop_queue(hw, queue);
818 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
820 txc = (void *)skb_push(skb, sizeof(*txc));
822 tx_status = (((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) != 0) ||
823 ((info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) != 0));
825 if (info->control.hw_key) {
826 icv = info->control.hw_key->icv_len;
828 switch (info->control.hw_key->alg) {
830 keytype = AR9170_TX_MAC_ENCR_RC4;
833 keytype = AR9170_TX_MAC_ENCR_RC4;
836 keytype = AR9170_TX_MAC_ENCR_AES;
845 txc->length = cpu_to_le16(len + icv + 4);
847 txc->mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION |
848 AR9170_TX_MAC_BACKOFF);
849 txc->mac_control |= cpu_to_le16(ar9170_qos_hwmap[queue] <<
850 AR9170_TX_MAC_QOS_SHIFT);
851 txc->mac_control |= cpu_to_le16(keytype);
852 txc->phy_control = cpu_to_le32(0);
854 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
855 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_NO_ACK);
857 if (info->flags & IEEE80211_TX_CTL_AMPDU)
858 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_AGGR);
860 txrate = &info->control.rates[0];
862 if (txrate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
863 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS);
864 else if (txrate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
865 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS);
867 if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
868 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD);
870 if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
871 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE);
873 if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
874 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ);
875 /* this works because 40 MHz is 2 and dup is 3 */
876 if (txrate->flags & IEEE80211_TX_RC_DUP_DATA)
877 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP);
879 if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
880 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI);
882 if (txrate->flags & IEEE80211_TX_RC_MCS) {
886 r <<= AR9170_TX_PHY_MCS_SHIFT;
887 if (WARN_ON(r & ~AR9170_TX_PHY_MCS_MASK))
889 txc->phy_control |= cpu_to_le32(r & AR9170_TX_PHY_MCS_MASK);
890 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_MOD_HT);
892 if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
893 if (info->band == IEEE80211_BAND_5GHZ)
894 txpower = ar->power_5G_ht40;
896 txpower = ar->power_2G_ht40;
898 if (info->band == IEEE80211_BAND_5GHZ)
899 txpower = ar->power_5G_ht20;
901 txpower = ar->power_2G_ht20;
904 power = txpower[(txrate->idx) & 7];
909 u8 idx = txrate->idx;
911 if (info->band != IEEE80211_BAND_2GHZ) {
913 txpower = ar->power_5G_leg;
914 mod = AR9170_TX_PHY_MOD_OFDM;
917 txpower = ar->power_2G_cck;
918 mod = AR9170_TX_PHY_MOD_CCK;
920 mod = AR9170_TX_PHY_MOD_OFDM;
921 txpower = ar->power_2G_ofdm;
925 rate = &__ar9170_ratetable[idx];
927 phyrate = rate->hw_value & 0xF;
928 power = txpower[(rate->hw_value & 0x30) >> 4];
929 phyrate <<= AR9170_TX_PHY_MCS_SHIFT;
931 txc->phy_control |= cpu_to_le32(mod);
932 txc->phy_control |= cpu_to_le32(phyrate);
935 power <<= AR9170_TX_PHY_TX_PWR_SHIFT;
936 power &= AR9170_TX_PHY_TX_PWR_MASK;
937 txc->phy_control |= cpu_to_le32(power);
940 if (ar->eeprom.tx_mask == 1) {
941 chains = AR9170_TX_PHY_TXCHAIN_1;
943 chains = AR9170_TX_PHY_TXCHAIN_2;
945 /* >= 36M legacy OFDM - use only one chain */
946 if (rate && rate->bitrate >= 360)
947 chains = AR9170_TX_PHY_TXCHAIN_1;
949 txc->phy_control |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_SHIFT);
952 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE);
955 * Putting the QoS queue bits into an unexplored territory is
956 * certainly not elegant.
958 * In my defense: This idea provides a reasonable way to
959 * smuggle valuable information to the tx_status callback.
960 * Also, the idea behind this bit-abuse came straight from
961 * the original driver code.
965 cpu_to_le32(queue << AR9170_TX_PHY_QOS_SHIFT);
967 if (info->control.sta) {
968 sta_info = (void *) info->control.sta->drv_priv;
969 skb_queue_tail(&sta_info->tx_status[queue], skb);
971 skb_queue_tail(&ar->global_tx_status, skb);
973 queue_delayed_work(ar->hw->workqueue,
974 &ar->tx_status_janitor,
975 msecs_to_jiffies(100));
979 err = ar->tx(ar, skb, tx_status, 0);
980 if (unlikely(tx_status && err)) {
981 if (info->control.sta)
982 skb_unlink(skb, &sta_info->tx_status[queue]);
984 skb_unlink(skb, &ar->global_tx_status);
990 spin_lock_irqsave(&ar->tx_stats_lock, flags);
991 ar->tx_stats[queue].len--;
992 ar->tx_stats[queue].count--;
993 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
1000 static int ar9170_op_add_interface(struct ieee80211_hw *hw,
1001 struct ieee80211_if_init_conf *conf)
1003 struct ar9170 *ar = hw->priv;
1006 mutex_lock(&ar->mutex);
1013 ar->vif = conf->vif;
1014 memcpy(ar->mac_addr, conf->mac_addr, ETH_ALEN);
1016 if (modparam_nohwcrypt || (ar->vif->type != NL80211_IFTYPE_STATION)) {
1017 ar->rx_software_decryption = true;
1018 ar->disable_offload = true;
1022 ar->want_filter = AR9170_MAC_REG_FTF_DEFAULTS;
1023 err = ar9170_update_frame_filter(ar);
1027 err = ar9170_set_operating_mode(ar);
1030 mutex_unlock(&ar->mutex);
1034 static void ar9170_op_remove_interface(struct ieee80211_hw *hw,
1035 struct ieee80211_if_init_conf *conf)
1037 struct ar9170 *ar = hw->priv;
1039 mutex_lock(&ar->mutex);
1041 ar->want_filter = 0;
1042 ar9170_update_frame_filter(ar);
1043 ar9170_set_beacon_timers(ar);
1044 dev_kfree_skb(ar->beacon);
1046 ar->sniffer_enabled = false;
1047 ar->rx_software_decryption = false;
1048 ar9170_set_operating_mode(ar);
1049 mutex_unlock(&ar->mutex);
1052 static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed)
1054 struct ar9170 *ar = hw->priv;
1057 mutex_lock(&ar->mutex);
1059 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
1064 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
1069 if (changed & IEEE80211_CONF_CHANGE_PS) {
1074 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1079 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
1081 * is it long_frame_max_tx_count or short_frame_max_tx_count?
1084 err = ar9170_set_hwretry_limit(ar,
1085 ar->hw->conf.long_frame_max_tx_count);
1090 if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL) {
1091 err = ar9170_set_beacon_timers(ar);
1096 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1097 err = ar9170_set_channel(ar, hw->conf.channel,
1099 nl80211_to_ar9170(hw->conf.channel_type));
1102 /* adjust slot time for 5 GHz */
1103 if (hw->conf.channel->band == IEEE80211_BAND_5GHZ)
1104 err = ar9170_write_reg(ar, AR9170_MAC_REG_SLOT_TIME,
1109 mutex_unlock(&ar->mutex);
1113 static int ar9170_op_config_interface(struct ieee80211_hw *hw,
1114 struct ieee80211_vif *vif,
1115 struct ieee80211_if_conf *conf)
1117 struct ar9170 *ar = hw->priv;
1120 mutex_lock(&ar->mutex);
1122 if (conf->changed & IEEE80211_IFCC_BSSID) {
1123 memcpy(ar->bssid, conf->bssid, ETH_ALEN);
1124 err = ar9170_set_operating_mode(ar);
1127 if (conf->changed & IEEE80211_IFCC_BEACON) {
1128 err = ar9170_update_beacon(ar);
1132 err = ar9170_set_beacon_timers(ar);
1136 mutex_unlock(&ar->mutex);
1140 static void ar9170_set_filters(struct work_struct *work)
1142 struct ar9170 *ar = container_of(work, struct ar9170,
1143 filter_config_work);
1146 if (unlikely(!IS_STARTED(ar)))
1149 mutex_lock(&ar->mutex);
1150 if (ar->filter_changed & AR9170_FILTER_CHANGED_PROMISC) {
1151 err = ar9170_set_operating_mode(ar);
1156 if (ar->filter_changed & AR9170_FILTER_CHANGED_MULTICAST) {
1157 err = ar9170_update_multicast(ar);
1162 if (ar->filter_changed & AR9170_FILTER_CHANGED_FRAMEFILTER)
1163 err = ar9170_update_frame_filter(ar);
1166 mutex_unlock(&ar->mutex);
1169 static void ar9170_op_configure_filter(struct ieee80211_hw *hw,
1170 unsigned int changed_flags,
1171 unsigned int *new_flags,
1172 int mc_count, struct dev_mc_list *mclist)
1174 struct ar9170 *ar = hw->priv;
1176 /* mask supported flags */
1177 *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC |
1181 * We can support more by setting the sniffer bit and
1182 * then checking the error flags, later.
1185 if (changed_flags & FIF_ALLMULTI) {
1186 if (*new_flags & FIF_ALLMULTI) {
1187 ar->want_mc_hash = ~0ULL;
1192 /* always get broadcast frames */
1193 mchash = 1ULL << (0xff>>2);
1195 for (i = 0; i < mc_count; i++) {
1196 if (WARN_ON(!mclist))
1198 mchash |= 1ULL << (mclist->dmi_addr[5] >> 2);
1199 mclist = mclist->next;
1201 ar->want_mc_hash = mchash;
1203 ar->filter_changed |= AR9170_FILTER_CHANGED_MULTICAST;
1206 if (changed_flags & FIF_CONTROL) {
1207 u32 filter = AR9170_MAC_REG_FTF_PSPOLL |
1208 AR9170_MAC_REG_FTF_RTS |
1209 AR9170_MAC_REG_FTF_CTS |
1210 AR9170_MAC_REG_FTF_ACK |
1211 AR9170_MAC_REG_FTF_CFE |
1212 AR9170_MAC_REG_FTF_CFE_ACK;
1214 if (*new_flags & FIF_CONTROL)
1215 ar->want_filter = ar->cur_filter | filter;
1217 ar->want_filter = ar->cur_filter & ~filter;
1219 ar->filter_changed |= AR9170_FILTER_CHANGED_FRAMEFILTER;
1222 if (changed_flags & FIF_PROMISC_IN_BSS) {
1223 ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0;
1224 ar->filter_changed |= AR9170_FILTER_CHANGED_PROMISC;
1227 if (likely(IS_STARTED(ar)))
1228 queue_work(ar->hw->workqueue, &ar->filter_config_work);
1231 static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw,
1232 struct ieee80211_vif *vif,
1233 struct ieee80211_bss_conf *bss_conf,
1236 struct ar9170 *ar = hw->priv;
1239 mutex_lock(&ar->mutex);
1241 ar9170_regwrite_begin(ar);
1243 if (changed & BSS_CHANGED_ASSOC) {
1244 ar->state = bss_conf->assoc ? AR9170_ASSOCIATED : ar->state;
1246 #ifndef CONFIG_AR9170_LEDS
1247 /* enable assoc LED. */
1248 err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0);
1249 #endif /* CONFIG_AR9170_LEDS */
1252 if (changed & BSS_CHANGED_HT) {
1257 if (changed & BSS_CHANGED_ERP_SLOT) {
1260 if (bss_conf->use_short_slot)
1263 ar9170_regwrite(AR9170_MAC_REG_SLOT_TIME, slottime << 10);
1266 if (changed & BSS_CHANGED_BASIC_RATES) {
1269 if (hw->conf.channel->band == IEEE80211_BAND_5GHZ) {
1270 ofdm = bss_conf->basic_rates;
1273 /* four cck rates */
1274 cck = bss_conf->basic_rates & 0xf;
1275 ofdm = bss_conf->basic_rates >> 4;
1277 ar9170_regwrite(AR9170_MAC_REG_BASIC_RATE,
1281 ar9170_regwrite_finish();
1282 err = ar9170_regwrite_result();
1283 mutex_unlock(&ar->mutex);
1286 static u64 ar9170_op_get_tsf(struct ieee80211_hw *hw)
1288 struct ar9170 *ar = hw->priv;
1294 mutex_lock(&ar->mutex);
1295 err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_L, &tsf_low);
1297 err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_H, &tsf_high);
1298 mutex_unlock(&ar->mutex);
1304 tsf = (tsf << 32) | tsf_low;
1308 static int ar9170_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1309 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1310 struct ieee80211_key_conf *key)
1312 struct ar9170 *ar = hw->priv;
1316 if ((!ar->vif) || (ar->disable_offload))
1321 if (key->keylen == LEN_WEP40)
1322 ktype = AR9170_ENC_ALG_WEP64;
1324 ktype = AR9170_ENC_ALG_WEP128;
1327 ktype = AR9170_ENC_ALG_TKIP;
1330 ktype = AR9170_ENC_ALG_AESCCMP;
1336 mutex_lock(&ar->mutex);
1337 if (cmd == SET_KEY) {
1338 if (unlikely(!IS_STARTED(ar))) {
1343 /* group keys need all-zeroes address */
1344 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
1347 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
1348 for (i = 0; i < 64; i++)
1349 if (!(ar->usedkeys & BIT(i)))
1352 ar->rx_software_decryption = true;
1353 ar9170_set_operating_mode(ar);
1358 i = 64 + key->keyidx;
1361 key->hw_key_idx = i;
1363 err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, ktype, 0,
1364 key->key, min_t(u8, 16, key->keylen));
1368 if (key->alg == ALG_TKIP) {
1369 err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL,
1370 ktype, 1, key->key + 16, 16);
1375 * hardware is not capable generating the MMIC
1376 * for fragmented frames!
1378 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1382 ar->usedkeys |= BIT(i);
1384 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1386 if (unlikely(!IS_STARTED(ar))) {
1387 /* The device is gone... together with the key ;-) */
1392 err = ar9170_disable_key(ar, key->hw_key_idx);
1396 if (key->hw_key_idx < 64) {
1397 ar->usedkeys &= ~BIT(key->hw_key_idx);
1399 err = ar9170_upload_key(ar, key->hw_key_idx, NULL,
1400 AR9170_ENC_ALG_NONE, 0,
1405 if (key->alg == ALG_TKIP) {
1406 err = ar9170_upload_key(ar, key->hw_key_idx,
1408 AR9170_ENC_ALG_NONE, 1,
1417 ar9170_regwrite_begin(ar);
1418 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L, ar->usedkeys);
1419 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H, ar->usedkeys >> 32);
1420 ar9170_regwrite_finish();
1421 err = ar9170_regwrite_result();
1424 mutex_unlock(&ar->mutex);
1429 static void ar9170_sta_notify(struct ieee80211_hw *hw,
1430 struct ieee80211_vif *vif,
1431 enum sta_notify_cmd cmd,
1432 struct ieee80211_sta *sta)
1434 struct ar9170 *ar = hw->priv;
1435 struct ar9170_sta_info *info = (void *) sta->drv_priv;
1436 struct sk_buff *skb;
1440 case STA_NOTIFY_ADD:
1441 for (i = 0; i < ar->hw->queues; i++)
1442 skb_queue_head_init(&info->tx_status[i]);
1445 case STA_NOTIFY_REMOVE:
1448 * transfer all outstanding frames that need a tx_status
1449 * reports to the global tx_status queue
1452 for (i = 0; i < ar->hw->queues; i++) {
1453 while ((skb = skb_dequeue(&info->tx_status[i]))) {
1454 #ifdef AR9170_QUEUE_DEBUG
1455 printk(KERN_DEBUG "%s: queueing frame in "
1456 "global tx_status queue =>\n",
1457 wiphy_name(ar->hw->wiphy));
1459 ar9170_print_txheader(ar, skb);
1460 #endif /* AR9170_QUEUE_DEBUG */
1461 skb_queue_tail(&ar->global_tx_status, skb);
1464 queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor,
1465 msecs_to_jiffies(100));
1473 static int ar9170_get_stats(struct ieee80211_hw *hw,
1474 struct ieee80211_low_level_stats *stats)
1476 struct ar9170 *ar = hw->priv;
1480 mutex_lock(&ar->mutex);
1481 err = ar9170_read_reg(ar, AR9170_MAC_REG_TX_RETRY, &val);
1482 ar->stats.dot11ACKFailureCount += val;
1484 memcpy(stats, &ar->stats, sizeof(*stats));
1485 mutex_unlock(&ar->mutex);
1490 static int ar9170_get_tx_stats(struct ieee80211_hw *hw,
1491 struct ieee80211_tx_queue_stats *tx_stats)
1493 struct ar9170 *ar = hw->priv;
1495 spin_lock_bh(&ar->tx_stats_lock);
1496 memcpy(tx_stats, ar->tx_stats, sizeof(tx_stats[0]) * hw->queues);
1497 spin_unlock_bh(&ar->tx_stats_lock);
1502 static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue,
1503 const struct ieee80211_tx_queue_params *param)
1505 struct ar9170 *ar = hw->priv;
1508 mutex_lock(&ar->mutex);
1509 if ((param) && !(queue > ar->hw->queues)) {
1510 memcpy(&ar->edcf[ar9170_qos_hwmap[queue]],
1511 param, sizeof(*param));
1513 ret = ar9170_set_qos(ar);
1517 mutex_unlock(&ar->mutex);
1521 static int ar9170_ampdu_action(struct ieee80211_hw *hw,
1522 enum ieee80211_ampdu_mlme_action action,
1523 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1526 case IEEE80211_AMPDU_RX_START:
1527 case IEEE80211_AMPDU_RX_STOP:
1529 * Something goes wrong -- RX locks up
1530 * after a while of receiving aggregated
1531 * frames -- not enabling for now.
1539 static const struct ieee80211_ops ar9170_ops = {
1540 .start = ar9170_op_start,
1541 .stop = ar9170_op_stop,
1543 .add_interface = ar9170_op_add_interface,
1544 .remove_interface = ar9170_op_remove_interface,
1545 .config = ar9170_op_config,
1546 .config_interface = ar9170_op_config_interface,
1547 .configure_filter = ar9170_op_configure_filter,
1548 .conf_tx = ar9170_conf_tx,
1549 .bss_info_changed = ar9170_op_bss_info_changed,
1550 .get_tsf = ar9170_op_get_tsf,
1551 .set_key = ar9170_set_key,
1552 .sta_notify = ar9170_sta_notify,
1553 .get_stats = ar9170_get_stats,
1554 .get_tx_stats = ar9170_get_tx_stats,
1555 .ampdu_action = ar9170_ampdu_action,
1558 void *ar9170_alloc(size_t priv_size)
1560 struct ieee80211_hw *hw;
1564 hw = ieee80211_alloc_hw(priv_size, &ar9170_ops);
1566 return ERR_PTR(-ENOMEM);
1571 mutex_init(&ar->mutex);
1572 spin_lock_init(&ar->cmdlock);
1573 spin_lock_init(&ar->tx_stats_lock);
1574 skb_queue_head_init(&ar->global_tx_status);
1575 skb_queue_head_init(&ar->global_tx_status_waste);
1576 INIT_WORK(&ar->filter_config_work, ar9170_set_filters);
1577 INIT_WORK(&ar->beacon_work, ar9170_new_beacon);
1578 INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor);
1580 /* all hw supports 2.4 GHz, so set channel to 1 by default */
1581 ar->channel = &ar9170_2ghz_chantable[0];
1583 /* first part of wiphy init */
1584 ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1585 BIT(NL80211_IFTYPE_WDS) |
1586 BIT(NL80211_IFTYPE_ADHOC);
1587 ar->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS |
1588 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1589 IEEE80211_HW_SIGNAL_DBM |
1590 IEEE80211_HW_NOISE_DBM;
1592 ar->hw->queues = __AR9170_NUM_TXQ;
1593 ar->hw->extra_tx_headroom = 8;
1594 ar->hw->sta_data_size = sizeof(struct ar9170_sta_info);
1596 ar->hw->max_rates = 1;
1597 ar->hw->max_rate_tries = 3;
1599 for (i = 0; i < ARRAY_SIZE(ar->noise); i++)
1600 ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1605 static int ar9170_read_eeprom(struct ar9170 *ar)
1607 #define RW 8 /* number of words to read at once */
1608 #define RB (sizeof(u32) * RW)
1609 DECLARE_MAC_BUF(mbuf);
1610 u8 *eeprom = (void *)&ar->eeprom;
1611 u8 *addr = ar->eeprom.mac_address;
1613 int i, j, err, bands = 0;
1615 BUILD_BUG_ON(sizeof(ar->eeprom) & 3);
1617 BUILD_BUG_ON(RB > AR9170_MAX_CMD_LEN - 4);
1619 /* don't want to handle trailing remains */
1620 BUILD_BUG_ON(sizeof(ar->eeprom) % RB);
1623 for (i = 0; i < sizeof(ar->eeprom)/RB; i++) {
1624 for (j = 0; j < RW; j++)
1625 offsets[j] = cpu_to_le32(AR9170_EEPROM_START +
1628 err = ar->exec_cmd(ar, AR9170_CMD_RREG,
1629 RB, (u8 *) &offsets,
1630 RB, eeprom + RB * i);
1638 if (ar->eeprom.length == cpu_to_le16(0xFFFF))
1641 if (ar->eeprom.operating_flags & AR9170_OPFLAG_2GHZ) {
1642 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar9170_band_2GHz;
1645 if (ar->eeprom.operating_flags & AR9170_OPFLAG_5GHZ) {
1646 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar9170_band_5GHz;
1650 * I measured this, a bandswitch takes roughly
1651 * 135 ms and a frequency switch about 80.
1653 * FIXME: measure these values again once EEPROM settings
1654 * are used, that will influence them!
1657 ar->hw->channel_change_time = 135 * 1000;
1659 ar->hw->channel_change_time = 80 * 1000;
1661 ar->regulatory.current_rd = le16_to_cpu(ar->eeprom.reg_domain[0]);
1662 ar->regulatory.current_rd_ext = le16_to_cpu(ar->eeprom.reg_domain[1]);
1664 /* second part of wiphy init */
1665 SET_IEEE80211_PERM_ADDR(ar->hw, addr);
1667 return bands ? 0 : -EINVAL;
1670 static int ar9170_reg_notifier(struct wiphy *wiphy,
1671 struct regulatory_request *request)
1673 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1674 struct ar9170 *ar = hw->priv;
1676 return ath_reg_notifier_apply(wiphy, request, &ar->regulatory);
1679 int ar9170_register(struct ar9170 *ar, struct device *pdev)
1683 /* try to read EEPROM, init MAC addr */
1684 err = ar9170_read_eeprom(ar);
1688 err = ath_regd_init(&ar->regulatory, ar->hw->wiphy,
1689 ar9170_reg_notifier);
1693 err = ieee80211_register_hw(ar->hw);
1697 if (!ath_is_world_regd(&ar->regulatory))
1698 regulatory_hint(ar->hw->wiphy, ar->regulatory.alpha2);
1700 err = ar9170_init_leds(ar);
1704 #ifdef CONFIG_AR9170_LEDS
1705 err = ar9170_register_leds(ar);
1708 #endif /* CONFIG_AR9170_LEDS */
1710 dev_info(pdev, "Atheros AR9170 is registered as '%s'\n",
1711 wiphy_name(ar->hw->wiphy));
1716 ieee80211_unregister_hw(ar->hw);
1722 void ar9170_unregister(struct ar9170 *ar)
1724 #ifdef CONFIG_AR9170_LEDS
1725 ar9170_unregister_leds(ar);
1726 #endif /* CONFIG_AR9170_LEDS */
1728 ieee80211_unregister_hw(ar->hw);
1729 mutex_destroy(&ar->mutex);