2 * Atheros CARL9170 driver
4 * mac80211 interaction code
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
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/slab.h>
42 #include <linux/module.h>
43 #include <linux/etherdevice.h>
44 #include <linux/random.h>
45 #include <net/mac80211.h>
46 #include <net/cfg80211.h>
51 static int modparam_nohwcrypt
;
52 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, S_IRUGO
);
53 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware crypto offload.");
56 module_param_named(noht
, modparam_noht
, int, S_IRUGO
);
57 MODULE_PARM_DESC(noht
, "Disable MPDU aggregation.");
59 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
60 .bitrate = (_bitrate), \
62 .hw_value = (_hw_rate) | (_txpidx) << 4, \
65 struct ieee80211_rate __carl9170_ratetable
[] = {
67 RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE
),
68 RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE
),
69 RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE
),
81 #define carl9170_g_ratetable (__carl9170_ratetable + 0)
82 #define carl9170_g_ratetable_size 12
83 #define carl9170_a_ratetable (__carl9170_ratetable + 4)
84 #define carl9170_a_ratetable_size 8
87 * NB: The hw_value is used as an index into the carl9170_phy_freq_params
88 * array in phy.c so that we don't have to do frequency lookups!
90 #define CHAN(_freq, _idx) { \
91 .center_freq = (_freq), \
93 .max_power = 18, /* XXX */ \
96 static struct ieee80211_channel carl9170_2ghz_chantable
[] = {
113 static struct ieee80211_channel carl9170_5ghz_chantable
[] = {
152 #define CARL9170_HT_CAP \
154 .ht_supported = true, \
155 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
156 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
157 IEEE80211_HT_CAP_SGI_40 | \
158 IEEE80211_HT_CAP_DSSSCCK40 | \
159 IEEE80211_HT_CAP_SM_PS, \
160 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
161 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
163 .rx_mask = { 0xff, 0xff, 0, 0, 0x1, 0, 0, 0, 0, 0, }, \
164 .rx_highest = cpu_to_le16(300), \
165 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
169 static struct ieee80211_supported_band carl9170_band_2GHz
= {
170 .channels
= carl9170_2ghz_chantable
,
171 .n_channels
= ARRAY_SIZE(carl9170_2ghz_chantable
),
172 .bitrates
= carl9170_g_ratetable
,
173 .n_bitrates
= carl9170_g_ratetable_size
,
174 .ht_cap
= CARL9170_HT_CAP
,
177 static struct ieee80211_supported_band carl9170_band_5GHz
= {
178 .channels
= carl9170_5ghz_chantable
,
179 .n_channels
= ARRAY_SIZE(carl9170_5ghz_chantable
),
180 .bitrates
= carl9170_a_ratetable
,
181 .n_bitrates
= carl9170_a_ratetable_size
,
182 .ht_cap
= CARL9170_HT_CAP
,
185 static void carl9170_ampdu_gc(struct ar9170
*ar
)
187 struct carl9170_sta_tid
*tid_info
;
191 list_for_each_entry_rcu(tid_info
, &ar
->tx_ampdu_list
, list
) {
192 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
193 if (tid_info
->state
== CARL9170_TID_STATE_SHUTDOWN
) {
194 tid_info
->state
= CARL9170_TID_STATE_KILLED
;
195 list_del_rcu(&tid_info
->list
);
196 ar
->tx_ampdu_list_len
--;
197 list_add_tail(&tid_info
->tmp_list
, &tid_gc
);
199 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
202 rcu_assign_pointer(ar
->tx_ampdu_iter
, tid_info
);
207 while (!list_empty(&tid_gc
)) {
209 tid_info
= list_first_entry(&tid_gc
, struct carl9170_sta_tid
,
212 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
213 carl9170_tx_status(ar
, skb
, false);
215 list_del_init(&tid_info
->tmp_list
);
220 static void carl9170_flush(struct ar9170
*ar
, bool drop_queued
)
226 * We can only drop frames which have not been uploaded
230 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
233 while ((skb
= skb_dequeue(&ar
->tx_pending
[i
]))) {
234 struct ieee80211_tx_info
*info
;
236 info
= IEEE80211_SKB_CB(skb
);
237 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
238 atomic_dec(&ar
->tx_ampdu_upload
);
240 carl9170_tx_status(ar
, skb
, false);
245 /* Wait for all other outstanding frames to timeout. */
246 if (atomic_read(&ar
->tx_total_queued
))
247 WARN_ON(wait_for_completion_timeout(&ar
->tx_flush
, HZ
) == 0);
250 static void carl9170_flush_ba(struct ar9170
*ar
)
252 struct sk_buff_head free
;
253 struct carl9170_sta_tid
*tid_info
;
256 __skb_queue_head_init(&free
);
259 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
260 list_for_each_entry_rcu(tid_info
, &ar
->tx_ampdu_list
, list
) {
261 if (tid_info
->state
> CARL9170_TID_STATE_SUSPEND
) {
262 tid_info
->state
= CARL9170_TID_STATE_SUSPEND
;
264 spin_lock(&tid_info
->lock
);
265 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
266 __skb_queue_tail(&free
, skb
);
267 spin_unlock(&tid_info
->lock
);
270 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
273 while ((skb
= __skb_dequeue(&free
)))
274 carl9170_tx_status(ar
, skb
, false);
277 static void carl9170_zap_queues(struct ar9170
*ar
)
279 struct carl9170_vif_info
*cvif
;
282 carl9170_ampdu_gc(ar
);
284 carl9170_flush_ba(ar
);
285 carl9170_flush(ar
, true);
287 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
288 spin_lock_bh(&ar
->tx_status
[i
].lock
);
289 while (!skb_queue_empty(&ar
->tx_status
[i
])) {
292 skb
= skb_peek(&ar
->tx_status
[i
]);
293 carl9170_tx_get_skb(skb
);
294 spin_unlock_bh(&ar
->tx_status
[i
].lock
);
295 carl9170_tx_drop(ar
, skb
);
296 spin_lock_bh(&ar
->tx_status
[i
].lock
);
297 carl9170_tx_put_skb(skb
);
299 spin_unlock_bh(&ar
->tx_status
[i
].lock
);
302 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_SOFT
< 1);
303 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_HARD
< CARL9170_NUM_TX_LIMIT_SOFT
);
304 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_HARD
>= CARL9170_BAW_BITS
);
306 /* reinitialize queues statistics */
307 memset(&ar
->tx_stats
, 0, sizeof(ar
->tx_stats
));
308 for (i
= 0; i
< ar
->hw
->queues
; i
++)
309 ar
->tx_stats
[i
].limit
= CARL9170_NUM_TX_LIMIT_HARD
;
311 for (i
= 0; i
< DIV_ROUND_UP(ar
->fw
.mem_blocks
, BITS_PER_LONG
); i
++)
312 ar
->mem_bitmap
[i
] = 0;
315 list_for_each_entry_rcu(cvif
, &ar
->vif_list
, list
) {
316 spin_lock_bh(&ar
->beacon_lock
);
317 dev_kfree_skb_any(cvif
->beacon
);
319 spin_unlock_bh(&ar
->beacon_lock
);
323 atomic_set(&ar
->tx_ampdu_upload
, 0);
324 atomic_set(&ar
->tx_ampdu_scheduler
, 0);
325 atomic_set(&ar
->tx_total_pending
, 0);
326 atomic_set(&ar
->tx_total_queued
, 0);
327 atomic_set(&ar
->mem_free_blocks
, ar
->fw
.mem_blocks
);
330 #define CARL9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
332 queue.aifs = ai_fs; \
333 queue.cw_min = cwmin; \
334 queue.cw_max = cwmax; \
335 queue.txop = _txop; \
338 static int carl9170_op_start(struct ieee80211_hw
*hw
)
340 struct ar9170
*ar
= hw
->priv
;
343 mutex_lock(&ar
->mutex
);
345 carl9170_zap_queues(ar
);
347 /* reset QoS defaults */
348 CARL9170_FILL_QUEUE(ar
->edcf
[0], 3, 15, 1023, 0); /* BEST EFFORT */
349 CARL9170_FILL_QUEUE(ar
->edcf
[1], 2, 7, 15, 94); /* VIDEO */
350 CARL9170_FILL_QUEUE(ar
->edcf
[2], 2, 3, 7, 47); /* VOICE */
351 CARL9170_FILL_QUEUE(ar
->edcf
[3], 7, 15, 1023, 0); /* BACKGROUND */
352 CARL9170_FILL_QUEUE(ar
->edcf
[4], 2, 3, 7, 0); /* SPECIAL */
354 ar
->current_factor
= ar
->current_density
= -1;
355 /* "The first key is unique." */
357 ar
->filter_state
= 0;
358 ar
->ps
.last_action
= jiffies
;
359 ar
->ps
.last_slept
= jiffies
;
360 ar
->erp_mode
= CARL9170_ERP_AUTO
;
361 ar
->rx_software_decryption
= false;
362 ar
->disable_offload
= false;
364 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
365 ar
->queue_stop_timeout
[i
] = jiffies
;
366 ar
->max_queue_stop_timeout
[i
] = 0;
369 atomic_set(&ar
->mem_allocs
, 0);
371 err
= carl9170_usb_open(ar
);
375 err
= carl9170_init_mac(ar
);
379 err
= carl9170_set_qos(ar
);
383 if (ar
->fw
.rx_filter
) {
384 err
= carl9170_rx_filter(ar
, CARL9170_RX_FILTER_OTHER_RA
|
385 CARL9170_RX_FILTER_CTL_OTHER
| CARL9170_RX_FILTER_BAD
);
390 err
= carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
,
391 AR9170_DMA_TRIGGER_RXQ
);
395 /* Clear key-cache */
396 for (i
= 0; i
< AR9170_CAM_MAX_USER
+ 4; i
++) {
397 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
402 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
407 if (i
< AR9170_CAM_MAX_USER
) {
408 err
= carl9170_disable_key(ar
, i
);
414 carl9170_set_state_when(ar
, CARL9170_IDLE
, CARL9170_STARTED
);
416 ieee80211_wake_queues(ar
->hw
);
420 mutex_unlock(&ar
->mutex
);
424 static void carl9170_cancel_worker(struct ar9170
*ar
)
426 cancel_delayed_work_sync(&ar
->tx_janitor
);
427 #ifdef CONFIG_CARL9170_LEDS
428 cancel_delayed_work_sync(&ar
->led_work
);
429 #endif /* CONFIG_CARL9170_LEDS */
430 cancel_work_sync(&ar
->ps_work
);
431 cancel_work_sync(&ar
->ping_work
);
432 cancel_work_sync(&ar
->ampdu_work
);
435 static void carl9170_op_stop(struct ieee80211_hw
*hw
)
437 struct ar9170
*ar
= hw
->priv
;
439 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
441 ieee80211_stop_queues(ar
->hw
);
443 mutex_lock(&ar
->mutex
);
444 if (IS_ACCEPTING_CMD(ar
)) {
445 rcu_assign_pointer(ar
->beacon_iter
, NULL
);
447 carl9170_led_set_state(ar
, 0);
450 carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
, 0);
451 carl9170_usb_stop(ar
);
454 carl9170_zap_queues(ar
);
455 mutex_unlock(&ar
->mutex
);
457 carl9170_cancel_worker(ar
);
460 static void carl9170_restart_work(struct work_struct
*work
)
462 struct ar9170
*ar
= container_of(work
, struct ar9170
,
467 ar
->filter_state
= 0;
468 carl9170_cancel_worker(ar
);
470 mutex_lock(&ar
->mutex
);
471 err
= carl9170_usb_restart(ar
);
472 if (net_ratelimit()) {
474 dev_err(&ar
->udev
->dev
, "Failed to restart device "
477 dev_info(&ar
->udev
->dev
, "device restarted "
482 carl9170_zap_queues(ar
);
483 mutex_unlock(&ar
->mutex
);
485 ar
->restart_counter
++;
486 atomic_set(&ar
->pending_restarts
, 0);
488 ieee80211_restart_hw(ar
->hw
);
491 * The reset was unsuccessful and the device seems to
492 * be dead. But there's still one option: a low-level
493 * usb subsystem reset...
496 carl9170_usb_reset(ar
);
500 void carl9170_restart(struct ar9170
*ar
, const enum carl9170_restart_reasons r
)
502 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
505 * Sometimes, an error can trigger several different reset events.
506 * By ignoring these *surplus* reset events, the device won't be
507 * killed again, right after it has recovered.
509 if (atomic_inc_return(&ar
->pending_restarts
) > 1) {
510 dev_dbg(&ar
->udev
->dev
, "ignoring restart (%d)\n", r
);
514 ieee80211_stop_queues(ar
->hw
);
516 dev_err(&ar
->udev
->dev
, "restart device (%d)\n", r
);
518 if (!WARN_ON(r
== CARL9170_RR_NO_REASON
) ||
519 !WARN_ON(r
>= __CARL9170_RR_LAST
))
525 if (IS_ACCEPTING_CMD(ar
) && !ar
->needs_full_reset
)
526 ieee80211_queue_work(ar
->hw
, &ar
->restart_work
);
528 carl9170_usb_reset(ar
);
531 * At this point, the device instance might have vanished/disabled.
532 * So, don't put any code which access the ar9170 struct
533 * without proper protection.
537 static void carl9170_ping_work(struct work_struct
*work
)
539 struct ar9170
*ar
= container_of(work
, struct ar9170
, ping_work
);
545 mutex_lock(&ar
->mutex
);
546 err
= carl9170_echo_test(ar
, 0xdeadbeef);
548 carl9170_restart(ar
, CARL9170_RR_UNRESPONSIVE_DEVICE
);
549 mutex_unlock(&ar
->mutex
);
552 static int carl9170_init_interface(struct ar9170
*ar
,
553 struct ieee80211_vif
*vif
)
555 struct ath_common
*common
= &ar
->common
;
559 WARN_ON_ONCE(IS_STARTED(ar
));
563 memcpy(common
->macaddr
, vif
->addr
, ETH_ALEN
);
565 if (modparam_nohwcrypt
||
566 ((vif
->type
!= NL80211_IFTYPE_STATION
) &&
567 (vif
->type
!= NL80211_IFTYPE_AP
))) {
568 ar
->rx_software_decryption
= true;
569 ar
->disable_offload
= true;
572 err
= carl9170_set_operating_mode(ar
);
576 static int carl9170_op_add_interface(struct ieee80211_hw
*hw
,
577 struct ieee80211_vif
*vif
)
579 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
580 struct ieee80211_vif
*main_vif
;
581 struct ar9170
*ar
= hw
->priv
;
582 int vif_id
= -1, err
= 0;
584 mutex_lock(&ar
->mutex
);
586 if (vif_priv
->active
) {
588 * Skip the interface structure initialization,
589 * if the vif survived the _restart call.
591 vif_id
= vif_priv
->id
;
592 vif_priv
->enable_beacon
= false;
594 spin_lock_bh(&ar
->beacon_lock
);
595 dev_kfree_skb_any(vif_priv
->beacon
);
596 vif_priv
->beacon
= NULL
;
597 spin_unlock_bh(&ar
->beacon_lock
);
602 main_vif
= carl9170_get_main_vif(ar
);
605 switch (main_vif
->type
) {
606 case NL80211_IFTYPE_STATION
:
607 if (vif
->type
== NL80211_IFTYPE_STATION
)
615 case NL80211_IFTYPE_AP
:
616 if ((vif
->type
== NL80211_IFTYPE_STATION
) ||
617 (vif
->type
== NL80211_IFTYPE_WDS
) ||
618 (vif
->type
== NL80211_IFTYPE_AP
))
631 vif_id
= bitmap_find_free_region(&ar
->vif_bitmap
, ar
->fw
.vif_num
, 0);
640 BUG_ON(ar
->vif_priv
[vif_id
].id
!= vif_id
);
642 vif_priv
->active
= true;
643 vif_priv
->id
= vif_id
;
644 vif_priv
->enable_beacon
= false;
646 list_add_tail_rcu(&vif_priv
->list
, &ar
->vif_list
);
647 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, vif
);
650 if (carl9170_get_main_vif(ar
) == vif
) {
651 rcu_assign_pointer(ar
->beacon_iter
, vif_priv
);
654 err
= carl9170_init_interface(ar
, vif
);
659 err
= carl9170_mod_virtual_mac(ar
, vif_id
, vif
->addr
);
665 if (ar
->fw
.tx_seq_table
) {
666 err
= carl9170_write_reg(ar
, ar
->fw
.tx_seq_table
+ vif_id
* 4,
673 if (err
&& (vif_id
>= 0)) {
674 vif_priv
->active
= false;
675 bitmap_release_region(&ar
->vif_bitmap
, vif_id
, 0);
677 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, NULL
);
678 list_del_rcu(&vif_priv
->list
);
679 mutex_unlock(&ar
->mutex
);
683 ar
->ps
.off_override
|= PS_OFF_VIF
;
685 mutex_unlock(&ar
->mutex
);
691 static void carl9170_op_remove_interface(struct ieee80211_hw
*hw
,
692 struct ieee80211_vif
*vif
)
694 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
695 struct ieee80211_vif
*main_vif
;
696 struct ar9170
*ar
= hw
->priv
;
699 mutex_lock(&ar
->mutex
);
701 if (WARN_ON_ONCE(!vif_priv
->active
))
707 main_vif
= carl9170_get_main_vif(ar
);
711 vif_priv
->active
= false;
712 WARN_ON(vif_priv
->enable_beacon
);
713 vif_priv
->enable_beacon
= false;
714 list_del_rcu(&vif_priv
->list
);
715 rcu_assign_pointer(ar
->vif_priv
[id
].vif
, NULL
);
717 if (vif
== main_vif
) {
721 WARN_ON(carl9170_init_interface(ar
,
722 carl9170_get_main_vif(ar
)));
724 carl9170_set_operating_mode(ar
);
729 WARN_ON(carl9170_mod_virtual_mac(ar
, id
, NULL
));
732 carl9170_update_beacon(ar
, false);
733 carl9170_flush_cab(ar
, id
);
735 spin_lock_bh(&ar
->beacon_lock
);
736 dev_kfree_skb_any(vif_priv
->beacon
);
737 vif_priv
->beacon
= NULL
;
738 spin_unlock_bh(&ar
->beacon_lock
);
740 bitmap_release_region(&ar
->vif_bitmap
, id
, 0);
742 carl9170_set_beacon_timers(ar
);
745 ar
->ps
.off_override
&= ~PS_OFF_VIF
;
748 mutex_unlock(&ar
->mutex
);
753 void carl9170_ps_check(struct ar9170
*ar
)
755 ieee80211_queue_work(ar
->hw
, &ar
->ps_work
);
758 /* caller must hold ar->mutex */
759 static int carl9170_ps_update(struct ar9170
*ar
)
764 if (!ar
->ps
.off_override
)
765 ps
= (ar
->hw
->conf
.flags
& IEEE80211_CONF_PS
);
767 if (ps
!= ar
->ps
.state
) {
768 err
= carl9170_powersave(ar
, ps
);
772 if (ar
->ps
.state
&& !ps
) {
773 ar
->ps
.sleep_ms
= jiffies_to_msecs(jiffies
-
778 ar
->ps
.last_slept
= jiffies
;
780 ar
->ps
.last_action
= jiffies
;
787 static void carl9170_ps_work(struct work_struct
*work
)
789 struct ar9170
*ar
= container_of(work
, struct ar9170
,
791 mutex_lock(&ar
->mutex
);
793 WARN_ON_ONCE(carl9170_ps_update(ar
) != 0);
794 mutex_unlock(&ar
->mutex
);
798 static int carl9170_op_config(struct ieee80211_hw
*hw
, u32 changed
)
800 struct ar9170
*ar
= hw
->priv
;
803 mutex_lock(&ar
->mutex
);
804 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
809 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
810 err
= carl9170_ps_update(ar
);
815 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
820 if (changed
& IEEE80211_CONF_CHANGE_SMPS
) {
825 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
826 /* adjust slot time for 5 GHz */
827 err
= carl9170_set_slot_time(ar
);
831 err
= carl9170_set_channel(ar
, hw
->conf
.channel
,
832 hw
->conf
.channel_type
, CARL9170_RFI_NONE
);
836 err
= carl9170_set_dyn_sifs_ack(ar
);
840 err
= carl9170_set_rts_cts_rate(ar
);
846 mutex_unlock(&ar
->mutex
);
850 static u64
carl9170_op_prepare_multicast(struct ieee80211_hw
*hw
,
851 struct netdev_hw_addr_list
*mc_list
)
853 struct netdev_hw_addr
*ha
;
856 /* always get broadcast frames */
857 mchash
= 1ULL << (0xff >> 2);
859 netdev_hw_addr_list_for_each(ha
, mc_list
)
860 mchash
|= 1ULL << (ha
->addr
[5] >> 2);
865 static void carl9170_op_configure_filter(struct ieee80211_hw
*hw
,
866 unsigned int changed_flags
,
867 unsigned int *new_flags
,
870 struct ar9170
*ar
= hw
->priv
;
872 /* mask supported flags */
873 *new_flags
&= FIF_ALLMULTI
| ar
->rx_filter_caps
;
875 if (!IS_ACCEPTING_CMD(ar
))
878 mutex_lock(&ar
->mutex
);
880 ar
->filter_state
= *new_flags
;
882 * We can support more by setting the sniffer bit and
883 * then checking the error flags, later.
886 if (*new_flags
& FIF_ALLMULTI
)
889 if (multicast
!= ar
->cur_mc_hash
)
890 WARN_ON(carl9170_update_multicast(ar
, multicast
));
892 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
893 ar
->sniffer_enabled
= !!(*new_flags
&
894 (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
));
896 WARN_ON(carl9170_set_operating_mode(ar
));
899 if (ar
->fw
.rx_filter
&& changed_flags
& ar
->rx_filter_caps
) {
902 if (!(*new_flags
& (FIF_FCSFAIL
| FIF_PLCPFAIL
)))
903 rx_filter
|= CARL9170_RX_FILTER_BAD
;
905 if (!(*new_flags
& FIF_CONTROL
))
906 rx_filter
|= CARL9170_RX_FILTER_CTL_OTHER
;
908 if (!(*new_flags
& FIF_PSPOLL
))
909 rx_filter
|= CARL9170_RX_FILTER_CTL_PSPOLL
;
911 if (!(*new_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
))) {
912 rx_filter
|= CARL9170_RX_FILTER_OTHER_RA
;
913 rx_filter
|= CARL9170_RX_FILTER_DECRY_FAIL
;
916 WARN_ON(carl9170_rx_filter(ar
, rx_filter
));
919 mutex_unlock(&ar
->mutex
);
923 static void carl9170_op_bss_info_changed(struct ieee80211_hw
*hw
,
924 struct ieee80211_vif
*vif
,
925 struct ieee80211_bss_conf
*bss_conf
,
928 struct ar9170
*ar
= hw
->priv
;
929 struct ath_common
*common
= &ar
->common
;
931 struct carl9170_vif_info
*vif_priv
;
932 struct ieee80211_vif
*main_vif
;
934 mutex_lock(&ar
->mutex
);
935 vif_priv
= (void *) vif
->drv_priv
;
936 main_vif
= carl9170_get_main_vif(ar
);
937 if (WARN_ON(!main_vif
))
940 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
941 struct carl9170_vif_info
*iter
;
944 vif_priv
->enable_beacon
= bss_conf
->enable_beacon
;
946 list_for_each_entry_rcu(iter
, &ar
->vif_list
, list
) {
947 if (iter
->active
&& iter
->enable_beacon
)
953 ar
->beacon_enabled
= i
;
956 if (changed
& BSS_CHANGED_BEACON
) {
957 err
= carl9170_update_beacon(ar
, false);
962 if (changed
& (BSS_CHANGED_BEACON_ENABLED
| BSS_CHANGED_BEACON
|
963 BSS_CHANGED_BEACON_INT
)) {
965 if (main_vif
!= vif
) {
966 bss_conf
->beacon_int
= main_vif
->bss_conf
.beacon_int
;
967 bss_conf
->dtim_period
= main_vif
->bss_conf
.dtim_period
;
971 * Therefore a hard limit for the broadcast traffic should
972 * prevent false alarms.
974 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
975 (bss_conf
->beacon_int
* bss_conf
->dtim_period
>=
976 (CARL9170_QUEUE_STUCK_TIMEOUT
/ 2))) {
981 err
= carl9170_set_beacon_timers(ar
);
986 if (changed
& BSS_CHANGED_HT
) {
997 * The following settings can only be changed by the
1001 if (changed
& BSS_CHANGED_BSSID
) {
1002 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1003 err
= carl9170_set_operating_mode(ar
);
1008 if (changed
& BSS_CHANGED_ASSOC
) {
1009 ar
->common
.curaid
= bss_conf
->aid
;
1010 err
= carl9170_set_beacon_timers(ar
);
1015 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1016 err
= carl9170_set_slot_time(ar
);
1021 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1022 err
= carl9170_set_mac_rates(ar
);
1028 WARN_ON_ONCE(err
&& IS_STARTED(ar
));
1029 mutex_unlock(&ar
->mutex
);
1032 static u64
carl9170_op_get_tsf(struct ieee80211_hw
*hw
)
1034 struct ar9170
*ar
= hw
->priv
;
1035 struct carl9170_tsf_rsp tsf
;
1038 mutex_lock(&ar
->mutex
);
1039 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_READ_TSF
,
1040 0, NULL
, sizeof(tsf
), &tsf
);
1041 mutex_unlock(&ar
->mutex
);
1045 return le64_to_cpu(tsf
.tsf_64
);
1048 static int carl9170_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1049 struct ieee80211_vif
*vif
,
1050 struct ieee80211_sta
*sta
,
1051 struct ieee80211_key_conf
*key
)
1053 struct ar9170
*ar
= hw
->priv
;
1057 if (ar
->disable_offload
|| !vif
)
1061 * We have to fall back to software encryption, whenever
1062 * the user choose to participates in an IBSS or is connected
1063 * to more than one network.
1065 * This is very unfortunate, because some machines cannot handle
1066 * the high througput speed in 802.11n networks.
1069 if (!is_main_vif(ar
, vif
))
1073 * While the hardware supports *catch-all* key, for offloading
1074 * group-key en-/de-cryption. The way of how the hardware
1075 * decides which keyId maps to which key, remains a mystery...
1077 if ((vif
->type
!= NL80211_IFTYPE_STATION
&&
1078 vif
->type
!= NL80211_IFTYPE_ADHOC
) &&
1079 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1082 switch (key
->cipher
) {
1083 case WLAN_CIPHER_SUITE_WEP40
:
1084 ktype
= AR9170_ENC_ALG_WEP64
;
1086 case WLAN_CIPHER_SUITE_WEP104
:
1087 ktype
= AR9170_ENC_ALG_WEP128
;
1089 case WLAN_CIPHER_SUITE_TKIP
:
1090 ktype
= AR9170_ENC_ALG_TKIP
;
1092 case WLAN_CIPHER_SUITE_CCMP
:
1093 ktype
= AR9170_ENC_ALG_AESCCMP
;
1099 mutex_lock(&ar
->mutex
);
1100 if (cmd
== SET_KEY
) {
1101 if (!IS_STARTED(ar
)) {
1106 if (!(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1109 i
= 64 + key
->keyidx
;
1111 for (i
= 0; i
< 64; i
++)
1112 if (!(ar
->usedkeys
& BIT(i
)))
1118 key
->hw_key_idx
= i
;
1120 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
,
1122 min_t(u8
, 16, key
->keylen
));
1126 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1127 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
:
1134 * hardware is not capable generating MMIC
1135 * of fragmented frames!
1137 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1141 ar
->usedkeys
|= BIT(i
);
1143 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1145 if (!IS_STARTED(ar
)) {
1146 /* The device is gone... together with the key ;-) */
1151 if (key
->hw_key_idx
< 64) {
1152 ar
->usedkeys
&= ~BIT(key
->hw_key_idx
);
1154 err
= carl9170_upload_key(ar
, key
->hw_key_idx
, NULL
,
1155 AR9170_ENC_ALG_NONE
, 0,
1160 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1161 err
= carl9170_upload_key(ar
, key
->hw_key_idx
,
1163 AR9170_ENC_ALG_NONE
,
1171 err
= carl9170_disable_key(ar
, key
->hw_key_idx
);
1177 mutex_unlock(&ar
->mutex
);
1181 if (!ar
->rx_software_decryption
) {
1182 ar
->rx_software_decryption
= true;
1183 carl9170_set_operating_mode(ar
);
1185 mutex_unlock(&ar
->mutex
);
1189 static int carl9170_op_sta_add(struct ieee80211_hw
*hw
,
1190 struct ieee80211_vif
*vif
,
1191 struct ieee80211_sta
*sta
)
1193 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1196 atomic_set(&sta_info
->pending_frames
, 0);
1198 if (sta
->ht_cap
.ht_supported
) {
1199 if (sta
->ht_cap
.ampdu_density
> 6) {
1201 * HW does support 16us AMPDU density.
1202 * No HT-Xmit for station.
1208 for (i
= 0; i
< CARL9170_NUM_TID
; i
++)
1209 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1211 sta_info
->ampdu_max_len
= 1 << (3 + sta
->ht_cap
.ampdu_factor
);
1212 sta_info
->ht_sta
= true;
1218 static int carl9170_op_sta_remove(struct ieee80211_hw
*hw
,
1219 struct ieee80211_vif
*vif
,
1220 struct ieee80211_sta
*sta
)
1222 struct ar9170
*ar
= hw
->priv
;
1223 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1225 bool cleanup
= false;
1227 if (sta
->ht_cap
.ht_supported
) {
1229 sta_info
->ht_sta
= false;
1232 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1233 struct carl9170_sta_tid
*tid_info
;
1235 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1236 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1241 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1242 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1243 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1244 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1250 carl9170_ampdu_gc(ar
);
1256 static int carl9170_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1257 const struct ieee80211_tx_queue_params
*param
)
1259 struct ar9170
*ar
= hw
->priv
;
1262 mutex_lock(&ar
->mutex
);
1263 if (queue
< ar
->hw
->queues
) {
1264 memcpy(&ar
->edcf
[ar9170_qmap
[queue
]], param
, sizeof(*param
));
1265 ret
= carl9170_set_qos(ar
);
1270 mutex_unlock(&ar
->mutex
);
1274 static void carl9170_ampdu_work(struct work_struct
*work
)
1276 struct ar9170
*ar
= container_of(work
, struct ar9170
,
1279 if (!IS_STARTED(ar
))
1282 mutex_lock(&ar
->mutex
);
1283 carl9170_ampdu_gc(ar
);
1284 mutex_unlock(&ar
->mutex
);
1287 static int carl9170_op_ampdu_action(struct ieee80211_hw
*hw
,
1288 struct ieee80211_vif
*vif
,
1289 enum ieee80211_ampdu_mlme_action action
,
1290 struct ieee80211_sta
*sta
,
1291 u16 tid
, u16
*ssn
, u8 buf_size
)
1293 struct ar9170
*ar
= hw
->priv
;
1294 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1295 struct carl9170_sta_tid
*tid_info
;
1301 case IEEE80211_AMPDU_TX_START
:
1302 if (!sta_info
->ht_sta
)
1306 if (rcu_dereference(sta_info
->agg
[tid
])) {
1311 tid_info
= kzalloc(sizeof(struct carl9170_sta_tid
),
1318 tid_info
->hsn
= tid_info
->bsn
= tid_info
->snx
= (*ssn
);
1319 tid_info
->state
= CARL9170_TID_STATE_PROGRESS
;
1320 tid_info
->tid
= tid
;
1321 tid_info
->max
= sta_info
->ampdu_max_len
;
1323 INIT_LIST_HEAD(&tid_info
->list
);
1324 INIT_LIST_HEAD(&tid_info
->tmp_list
);
1325 skb_queue_head_init(&tid_info
->queue
);
1326 spin_lock_init(&tid_info
->lock
);
1328 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1329 ar
->tx_ampdu_list_len
++;
1330 list_add_tail_rcu(&tid_info
->list
, &ar
->tx_ampdu_list
);
1331 rcu_assign_pointer(sta_info
->agg
[tid
], tid_info
);
1332 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1335 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1338 case IEEE80211_AMPDU_TX_STOP
:
1340 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1342 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1343 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1344 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1345 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1348 rcu_assign_pointer(sta_info
->agg
[tid
], NULL
);
1351 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1352 ieee80211_queue_work(ar
->hw
, &ar
->ampdu_work
);
1355 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1357 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1359 sta_info
->stats
[tid
].clear
= true;
1360 sta_info
->stats
[tid
].req
= false;
1363 bitmap_zero(tid_info
->bitmap
, CARL9170_BAW_SIZE
);
1364 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1368 if (WARN_ON_ONCE(!tid_info
))
1373 case IEEE80211_AMPDU_RX_START
:
1374 case IEEE80211_AMPDU_RX_STOP
:
1375 /* Handled by hardware */
1385 #ifdef CONFIG_CARL9170_WPC
1386 static int carl9170_register_wps_button(struct ar9170
*ar
)
1388 struct input_dev
*input
;
1391 if (!(ar
->features
& CARL9170_WPS_BUTTON
))
1394 input
= input_allocate_device();
1398 snprintf(ar
->wps
.name
, sizeof(ar
->wps
.name
), "%s WPS Button",
1399 wiphy_name(ar
->hw
->wiphy
));
1401 snprintf(ar
->wps
.phys
, sizeof(ar
->wps
.phys
),
1402 "ieee80211/%s/input0", wiphy_name(ar
->hw
->wiphy
));
1404 input
->name
= ar
->wps
.name
;
1405 input
->phys
= ar
->wps
.phys
;
1406 input
->id
.bustype
= BUS_USB
;
1407 input
->dev
.parent
= &ar
->hw
->wiphy
->dev
;
1409 input_set_capability(input
, EV_KEY
, KEY_WPS_BUTTON
);
1411 err
= input_register_device(input
);
1413 input_free_device(input
);
1417 ar
->wps
.pbc
= input
;
1420 #endif /* CONFIG_CARL9170_WPC */
1422 static int carl9170_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
1423 struct survey_info
*survey
)
1425 struct ar9170
*ar
= hw
->priv
;
1431 mutex_lock(&ar
->mutex
);
1432 err
= carl9170_get_noisefloor(ar
);
1433 mutex_unlock(&ar
->mutex
);
1437 survey
->channel
= ar
->channel
;
1438 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1439 survey
->noise
= ar
->noise
[0];
1443 static void carl9170_op_flush(struct ieee80211_hw
*hw
, bool drop
)
1445 struct ar9170
*ar
= hw
->priv
;
1448 mutex_lock(&ar
->mutex
);
1449 for_each_set_bit(vid
, &ar
->vif_bitmap
, ar
->fw
.vif_num
)
1450 carl9170_flush_cab(ar
, vid
);
1452 carl9170_flush(ar
, drop
);
1453 mutex_unlock(&ar
->mutex
);
1456 static int carl9170_op_get_stats(struct ieee80211_hw
*hw
,
1457 struct ieee80211_low_level_stats
*stats
)
1459 struct ar9170
*ar
= hw
->priv
;
1461 memset(stats
, 0, sizeof(*stats
));
1462 stats
->dot11ACKFailureCount
= ar
->tx_ack_failures
;
1463 stats
->dot11FCSErrorCount
= ar
->tx_fcs_errors
;
1467 static void carl9170_op_sta_notify(struct ieee80211_hw
*hw
,
1468 struct ieee80211_vif
*vif
,
1469 enum sta_notify_cmd cmd
,
1470 struct ieee80211_sta
*sta
)
1472 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1475 case STA_NOTIFY_SLEEP
:
1476 sta_info
->sleeping
= true;
1477 if (atomic_read(&sta_info
->pending_frames
))
1478 ieee80211_sta_block_awake(hw
, sta
, true);
1481 case STA_NOTIFY_AWAKE
:
1482 sta_info
->sleeping
= false;
1487 static const struct ieee80211_ops carl9170_ops
= {
1488 .start
= carl9170_op_start
,
1489 .stop
= carl9170_op_stop
,
1490 .tx
= carl9170_op_tx
,
1491 .flush
= carl9170_op_flush
,
1492 .add_interface
= carl9170_op_add_interface
,
1493 .remove_interface
= carl9170_op_remove_interface
,
1494 .config
= carl9170_op_config
,
1495 .prepare_multicast
= carl9170_op_prepare_multicast
,
1496 .configure_filter
= carl9170_op_configure_filter
,
1497 .conf_tx
= carl9170_op_conf_tx
,
1498 .bss_info_changed
= carl9170_op_bss_info_changed
,
1499 .get_tsf
= carl9170_op_get_tsf
,
1500 .set_key
= carl9170_op_set_key
,
1501 .sta_add
= carl9170_op_sta_add
,
1502 .sta_remove
= carl9170_op_sta_remove
,
1503 .sta_notify
= carl9170_op_sta_notify
,
1504 .get_survey
= carl9170_op_get_survey
,
1505 .get_stats
= carl9170_op_get_stats
,
1506 .ampdu_action
= carl9170_op_ampdu_action
,
1509 void *carl9170_alloc(size_t priv_size
)
1511 struct ieee80211_hw
*hw
;
1513 struct sk_buff
*skb
;
1517 * this buffer is used for rx stream reconstruction.
1518 * Under heavy load this device (or the transport layer?)
1519 * tends to split the streams into separate rx descriptors.
1522 skb
= __dev_alloc_skb(AR9170_RX_STREAM_MAX_SIZE
, GFP_KERNEL
);
1526 hw
= ieee80211_alloc_hw(priv_size
, &carl9170_ops
);
1532 ar
->rx_failover
= skb
;
1534 memset(&ar
->rx_plcp
, 0, sizeof(struct ar9170_rx_head
));
1535 ar
->rx_has_plcp
= false;
1538 * Here's a hidden pitfall!
1540 * All 4 AC queues work perfectly well under _legacy_ operation.
1541 * However as soon as aggregation is enabled, the traffic flow
1542 * gets very bumpy. Therefore we have to _switch_ to a
1543 * software AC with a single HW queue.
1545 hw
->queues
= __AR9170_NUM_TXQ
;
1547 mutex_init(&ar
->mutex
);
1548 spin_lock_init(&ar
->beacon_lock
);
1549 spin_lock_init(&ar
->cmd_lock
);
1550 spin_lock_init(&ar
->tx_stats_lock
);
1551 spin_lock_init(&ar
->tx_ampdu_list_lock
);
1552 spin_lock_init(&ar
->mem_lock
);
1553 spin_lock_init(&ar
->state_lock
);
1554 atomic_set(&ar
->pending_restarts
, 0);
1556 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1557 skb_queue_head_init(&ar
->tx_status
[i
]);
1558 skb_queue_head_init(&ar
->tx_pending
[i
]);
1560 INIT_WORK(&ar
->ps_work
, carl9170_ps_work
);
1561 INIT_WORK(&ar
->ping_work
, carl9170_ping_work
);
1562 INIT_WORK(&ar
->restart_work
, carl9170_restart_work
);
1563 INIT_WORK(&ar
->ampdu_work
, carl9170_ampdu_work
);
1564 INIT_DELAYED_WORK(&ar
->tx_janitor
, carl9170_tx_janitor
);
1565 INIT_LIST_HEAD(&ar
->tx_ampdu_list
);
1566 rcu_assign_pointer(ar
->tx_ampdu_iter
,
1567 (struct carl9170_sta_tid
*) &ar
->tx_ampdu_list
);
1569 bitmap_zero(&ar
->vif_bitmap
, ar
->fw
.vif_num
);
1570 INIT_LIST_HEAD(&ar
->vif_list
);
1571 init_completion(&ar
->tx_flush
);
1575 * IBSS/ADHOC and AP mode are only enabled, if the firmware
1576 * supports these modes. The code which will add the
1577 * additional interface_modes is in fw.c.
1579 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1580 BIT(NL80211_IFTYPE_P2P_CLIENT
);
1582 hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
|
1583 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
1584 IEEE80211_HW_SUPPORTS_PS
|
1585 IEEE80211_HW_PS_NULLFUNC_STACK
|
1586 IEEE80211_HW_SIGNAL_DBM
;
1588 if (!modparam_noht
) {
1590 * see the comment above, why we allow the user
1591 * to disable HT by a module parameter.
1593 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1596 hw
->extra_tx_headroom
= sizeof(struct _carl9170_tx_superframe
);
1597 hw
->sta_data_size
= sizeof(struct carl9170_sta_info
);
1598 hw
->vif_data_size
= sizeof(struct carl9170_vif_info
);
1600 hw
->max_rates
= CARL9170_TX_MAX_RATES
;
1601 hw
->max_rate_tries
= CARL9170_TX_USER_RATE_TRIES
;
1603 for (i
= 0; i
< ARRAY_SIZE(ar
->noise
); i
++)
1604 ar
->noise
[i
] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1606 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
1611 return ERR_PTR(-ENOMEM
);
1614 static int carl9170_read_eeprom(struct ar9170
*ar
)
1616 #define RW 8 /* number of words to read at once */
1617 #define RB (sizeof(u32) * RW)
1618 u8
*eeprom
= (void *)&ar
->eeprom
;
1622 BUILD_BUG_ON(sizeof(ar
->eeprom
) & 3);
1624 BUILD_BUG_ON(RB
> CARL9170_MAX_CMD_LEN
- 4);
1626 /* don't want to handle trailing remains */
1627 BUILD_BUG_ON(sizeof(ar
->eeprom
) % RB
);
1630 for (i
= 0; i
< sizeof(ar
->eeprom
)/RB
; i
++) {
1631 for (j
= 0; j
< RW
; j
++)
1632 offsets
[j
] = cpu_to_le32(AR9170_EEPROM_START
+
1635 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_RREG
,
1636 RB
, (u8
*) &offsets
,
1637 RB
, eeprom
+ RB
* i
);
1647 static int carl9170_parse_eeprom(struct ar9170
*ar
)
1649 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1650 unsigned int rx_streams
, tx_streams
, tx_params
= 0;
1653 if (ar
->eeprom
.length
== cpu_to_le16(0xffff))
1656 rx_streams
= hweight8(ar
->eeprom
.rx_mask
);
1657 tx_streams
= hweight8(ar
->eeprom
.tx_mask
);
1659 if (rx_streams
!= tx_streams
) {
1660 tx_params
= IEEE80211_HT_MCS_TX_RX_DIFF
;
1662 WARN_ON(!(tx_streams
>= 1 && tx_streams
<=
1663 IEEE80211_HT_MCS_TX_MAX_STREAMS
));
1665 tx_params
= (tx_streams
- 1) <<
1666 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1668 carl9170_band_2GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1669 carl9170_band_5GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1672 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_2GHZ
) {
1673 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1674 &carl9170_band_2GHz
;
1677 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_5GHZ
) {
1678 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1679 &carl9170_band_5GHz
;
1684 * I measured this, a bandswitch takes roughly
1685 * 135 ms and a frequency switch about 80.
1687 * FIXME: measure these values again once EEPROM settings
1688 * are used, that will influence them!
1691 ar
->hw
->channel_change_time
= 135 * 1000;
1693 ar
->hw
->channel_change_time
= 80 * 1000;
1695 regulatory
->current_rd
= le16_to_cpu(ar
->eeprom
.reg_domain
[0]);
1696 regulatory
->current_rd_ext
= le16_to_cpu(ar
->eeprom
.reg_domain
[1]);
1698 /* second part of wiphy init */
1699 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->eeprom
.mac_address
);
1701 return bands
? 0 : -EINVAL
;
1704 static int carl9170_reg_notifier(struct wiphy
*wiphy
,
1705 struct regulatory_request
*request
)
1707 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1708 struct ar9170
*ar
= hw
->priv
;
1710 return ath_reg_notifier_apply(wiphy
, request
, &ar
->common
.regulatory
);
1713 int carl9170_register(struct ar9170
*ar
)
1715 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1718 if (WARN_ON(ar
->mem_bitmap
))
1721 ar
->mem_bitmap
= kzalloc(roundup(ar
->fw
.mem_blocks
, BITS_PER_LONG
) *
1722 sizeof(unsigned long), GFP_KERNEL
);
1724 if (!ar
->mem_bitmap
)
1727 /* try to read EEPROM, init MAC addr */
1728 err
= carl9170_read_eeprom(ar
);
1732 err
= carl9170_fw_fix_eeprom(ar
);
1736 err
= carl9170_parse_eeprom(ar
);
1740 err
= ath_regd_init(regulatory
, ar
->hw
->wiphy
,
1741 carl9170_reg_notifier
);
1745 if (modparam_noht
) {
1746 carl9170_band_2GHz
.ht_cap
.ht_supported
= false;
1747 carl9170_band_5GHz
.ht_cap
.ht_supported
= false;
1750 for (i
= 0; i
< ar
->fw
.vif_num
; i
++) {
1751 ar
->vif_priv
[i
].id
= i
;
1752 ar
->vif_priv
[i
].vif
= NULL
;
1755 err
= ieee80211_register_hw(ar
->hw
);
1759 /* mac80211 interface is now registered */
1760 ar
->registered
= true;
1762 if (!ath_is_world_regd(regulatory
))
1763 regulatory_hint(ar
->hw
->wiphy
, regulatory
->alpha2
);
1765 #ifdef CONFIG_CARL9170_DEBUGFS
1766 carl9170_debugfs_register(ar
);
1767 #endif /* CONFIG_CARL9170_DEBUGFS */
1769 err
= carl9170_led_init(ar
);
1773 #ifdef CONFIG_CARL9170_LEDS
1774 err
= carl9170_led_register(ar
);
1777 #endif /* CONFIG_CARL9170_LEDS */
1779 #ifdef CONFIG_CARL9170_WPC
1780 err
= carl9170_register_wps_button(ar
);
1783 #endif /* CONFIG_CARL9170_WPC */
1785 dev_info(&ar
->udev
->dev
, "Atheros AR9170 is registered as '%s'\n",
1786 wiphy_name(ar
->hw
->wiphy
));
1791 carl9170_unregister(ar
);
1795 void carl9170_unregister(struct ar9170
*ar
)
1797 if (!ar
->registered
)
1800 ar
->registered
= false;
1802 #ifdef CONFIG_CARL9170_LEDS
1803 carl9170_led_unregister(ar
);
1804 #endif /* CONFIG_CARL9170_LEDS */
1806 #ifdef CONFIG_CARL9170_DEBUGFS
1807 carl9170_debugfs_unregister(ar
);
1808 #endif /* CONFIG_CARL9170_DEBUGFS */
1810 #ifdef CONFIG_CARL9170_WPC
1812 input_unregister_device(ar
->wps
.pbc
);
1815 #endif /* CONFIG_CARL9170_WPC */
1817 carl9170_cancel_worker(ar
);
1818 cancel_work_sync(&ar
->restart_work
);
1820 ieee80211_unregister_hw(ar
->hw
);
1823 void carl9170_free(struct ar9170
*ar
)
1825 WARN_ON(ar
->registered
);
1826 WARN_ON(IS_INITIALIZED(ar
));
1828 kfree_skb(ar
->rx_failover
);
1829 ar
->rx_failover
= NULL
;
1831 kfree(ar
->mem_bitmap
);
1832 ar
->mem_bitmap
= NULL
;
1834 mutex_destroy(&ar
->mutex
);
1836 ieee80211_free_hw(ar
->hw
);