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
);
666 if (err
&& (vif_id
>= 0)) {
667 vif_priv
->active
= false;
668 bitmap_release_region(&ar
->vif_bitmap
, vif_id
, 0);
670 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, NULL
);
671 list_del_rcu(&vif_priv
->list
);
672 mutex_unlock(&ar
->mutex
);
676 ar
->ps
.off_override
|= PS_OFF_VIF
;
678 mutex_unlock(&ar
->mutex
);
684 static void carl9170_op_remove_interface(struct ieee80211_hw
*hw
,
685 struct ieee80211_vif
*vif
)
687 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
688 struct ieee80211_vif
*main_vif
;
689 struct ar9170
*ar
= hw
->priv
;
692 mutex_lock(&ar
->mutex
);
694 if (WARN_ON_ONCE(!vif_priv
->active
))
700 main_vif
= carl9170_get_main_vif(ar
);
704 vif_priv
->active
= false;
705 WARN_ON(vif_priv
->enable_beacon
);
706 vif_priv
->enable_beacon
= false;
707 list_del_rcu(&vif_priv
->list
);
708 rcu_assign_pointer(ar
->vif_priv
[id
].vif
, NULL
);
710 if (vif
== main_vif
) {
714 WARN_ON(carl9170_init_interface(ar
,
715 carl9170_get_main_vif(ar
)));
717 carl9170_set_operating_mode(ar
);
722 WARN_ON(carl9170_mod_virtual_mac(ar
, id
, NULL
));
725 carl9170_update_beacon(ar
, false);
726 carl9170_flush_cab(ar
, id
);
728 spin_lock_bh(&ar
->beacon_lock
);
729 dev_kfree_skb_any(vif_priv
->beacon
);
730 vif_priv
->beacon
= NULL
;
731 spin_unlock_bh(&ar
->beacon_lock
);
733 bitmap_release_region(&ar
->vif_bitmap
, id
, 0);
735 carl9170_set_beacon_timers(ar
);
738 ar
->ps
.off_override
&= ~PS_OFF_VIF
;
741 mutex_unlock(&ar
->mutex
);
746 void carl9170_ps_check(struct ar9170
*ar
)
748 ieee80211_queue_work(ar
->hw
, &ar
->ps_work
);
751 /* caller must hold ar->mutex */
752 static int carl9170_ps_update(struct ar9170
*ar
)
757 if (!ar
->ps
.off_override
)
758 ps
= (ar
->hw
->conf
.flags
& IEEE80211_CONF_PS
);
760 if (ps
!= ar
->ps
.state
) {
761 err
= carl9170_powersave(ar
, ps
);
765 if (ar
->ps
.state
&& !ps
) {
766 ar
->ps
.sleep_ms
= jiffies_to_msecs(jiffies
-
771 ar
->ps
.last_slept
= jiffies
;
773 ar
->ps
.last_action
= jiffies
;
780 static void carl9170_ps_work(struct work_struct
*work
)
782 struct ar9170
*ar
= container_of(work
, struct ar9170
,
784 mutex_lock(&ar
->mutex
);
786 WARN_ON_ONCE(carl9170_ps_update(ar
) != 0);
787 mutex_unlock(&ar
->mutex
);
791 static int carl9170_op_config(struct ieee80211_hw
*hw
, u32 changed
)
793 struct ar9170
*ar
= hw
->priv
;
796 mutex_lock(&ar
->mutex
);
797 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
802 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
803 err
= carl9170_ps_update(ar
);
808 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
813 if (changed
& IEEE80211_CONF_CHANGE_SMPS
) {
818 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
819 /* adjust slot time for 5 GHz */
820 err
= carl9170_set_slot_time(ar
);
824 err
= carl9170_set_channel(ar
, hw
->conf
.channel
,
825 hw
->conf
.channel_type
, CARL9170_RFI_NONE
);
829 err
= carl9170_set_dyn_sifs_ack(ar
);
833 err
= carl9170_set_rts_cts_rate(ar
);
839 mutex_unlock(&ar
->mutex
);
843 static u64
carl9170_op_prepare_multicast(struct ieee80211_hw
*hw
,
844 struct netdev_hw_addr_list
*mc_list
)
846 struct netdev_hw_addr
*ha
;
849 /* always get broadcast frames */
850 mchash
= 1ULL << (0xff >> 2);
852 netdev_hw_addr_list_for_each(ha
, mc_list
)
853 mchash
|= 1ULL << (ha
->addr
[5] >> 2);
858 static void carl9170_op_configure_filter(struct ieee80211_hw
*hw
,
859 unsigned int changed_flags
,
860 unsigned int *new_flags
,
863 struct ar9170
*ar
= hw
->priv
;
865 /* mask supported flags */
866 *new_flags
&= FIF_ALLMULTI
| ar
->rx_filter_caps
;
868 if (!IS_ACCEPTING_CMD(ar
))
871 mutex_lock(&ar
->mutex
);
873 ar
->filter_state
= *new_flags
;
875 * We can support more by setting the sniffer bit and
876 * then checking the error flags, later.
879 if (changed_flags
& FIF_ALLMULTI
&& *new_flags
& FIF_ALLMULTI
)
882 if (multicast
!= ar
->cur_mc_hash
)
883 WARN_ON(carl9170_update_multicast(ar
, multicast
));
885 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
886 ar
->sniffer_enabled
= !!(*new_flags
&
887 (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
));
889 WARN_ON(carl9170_set_operating_mode(ar
));
892 if (ar
->fw
.rx_filter
&& changed_flags
& ar
->rx_filter_caps
) {
895 if (!(*new_flags
& (FIF_FCSFAIL
| FIF_PLCPFAIL
)))
896 rx_filter
|= CARL9170_RX_FILTER_BAD
;
898 if (!(*new_flags
& FIF_CONTROL
))
899 rx_filter
|= CARL9170_RX_FILTER_CTL_OTHER
;
901 if (!(*new_flags
& FIF_PSPOLL
))
902 rx_filter
|= CARL9170_RX_FILTER_CTL_PSPOLL
;
904 if (!(*new_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
))) {
905 rx_filter
|= CARL9170_RX_FILTER_OTHER_RA
;
906 rx_filter
|= CARL9170_RX_FILTER_DECRY_FAIL
;
909 WARN_ON(carl9170_rx_filter(ar
, rx_filter
));
912 mutex_unlock(&ar
->mutex
);
916 static void carl9170_op_bss_info_changed(struct ieee80211_hw
*hw
,
917 struct ieee80211_vif
*vif
,
918 struct ieee80211_bss_conf
*bss_conf
,
921 struct ar9170
*ar
= hw
->priv
;
922 struct ath_common
*common
= &ar
->common
;
924 struct carl9170_vif_info
*vif_priv
;
925 struct ieee80211_vif
*main_vif
;
927 mutex_lock(&ar
->mutex
);
928 vif_priv
= (void *) vif
->drv_priv
;
929 main_vif
= carl9170_get_main_vif(ar
);
930 if (WARN_ON(!main_vif
))
933 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
934 struct carl9170_vif_info
*iter
;
937 vif_priv
->enable_beacon
= bss_conf
->enable_beacon
;
939 list_for_each_entry_rcu(iter
, &ar
->vif_list
, list
) {
940 if (iter
->active
&& iter
->enable_beacon
)
946 ar
->beacon_enabled
= i
;
949 if (changed
& BSS_CHANGED_BEACON
) {
950 err
= carl9170_update_beacon(ar
, false);
955 if (changed
& (BSS_CHANGED_BEACON_ENABLED
| BSS_CHANGED_BEACON
|
956 BSS_CHANGED_BEACON_INT
)) {
958 if (main_vif
!= vif
) {
959 bss_conf
->beacon_int
= main_vif
->bss_conf
.beacon_int
;
960 bss_conf
->dtim_period
= main_vif
->bss_conf
.dtim_period
;
964 * Therefore a hard limit for the broadcast traffic should
965 * prevent false alarms.
967 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
968 (bss_conf
->beacon_int
* bss_conf
->dtim_period
>=
969 (CARL9170_QUEUE_STUCK_TIMEOUT
/ 2))) {
974 err
= carl9170_set_beacon_timers(ar
);
979 if (changed
& BSS_CHANGED_HT
) {
990 * The following settings can only be changed by the
994 if (changed
& BSS_CHANGED_BSSID
) {
995 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
996 err
= carl9170_set_operating_mode(ar
);
1001 if (changed
& BSS_CHANGED_ASSOC
) {
1002 ar
->common
.curaid
= bss_conf
->aid
;
1003 err
= carl9170_set_beacon_timers(ar
);
1008 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1009 err
= carl9170_set_slot_time(ar
);
1014 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1015 err
= carl9170_set_mac_rates(ar
);
1021 WARN_ON_ONCE(err
&& IS_STARTED(ar
));
1022 mutex_unlock(&ar
->mutex
);
1025 static u64
carl9170_op_get_tsf(struct ieee80211_hw
*hw
)
1027 struct ar9170
*ar
= hw
->priv
;
1028 struct carl9170_tsf_rsp tsf
;
1031 mutex_lock(&ar
->mutex
);
1032 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_READ_TSF
,
1033 0, NULL
, sizeof(tsf
), &tsf
);
1034 mutex_unlock(&ar
->mutex
);
1038 return le64_to_cpu(tsf
.tsf_64
);
1041 static int carl9170_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1042 struct ieee80211_vif
*vif
,
1043 struct ieee80211_sta
*sta
,
1044 struct ieee80211_key_conf
*key
)
1046 struct ar9170
*ar
= hw
->priv
;
1050 if (ar
->disable_offload
|| !vif
)
1054 * We have to fall back to software encryption, whenever
1055 * the user choose to participates in an IBSS or is connected
1056 * to more than one network.
1058 * This is very unfortunate, because some machines cannot handle
1059 * the high througput speed in 802.11n networks.
1062 if (!is_main_vif(ar
, vif
))
1066 * While the hardware supports *catch-all* key, for offloading
1067 * group-key en-/de-cryption. The way of how the hardware
1068 * decides which keyId maps to which key, remains a mystery...
1070 if ((vif
->type
!= NL80211_IFTYPE_STATION
&&
1071 vif
->type
!= NL80211_IFTYPE_ADHOC
) &&
1072 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1075 switch (key
->cipher
) {
1076 case WLAN_CIPHER_SUITE_WEP40
:
1077 ktype
= AR9170_ENC_ALG_WEP64
;
1079 case WLAN_CIPHER_SUITE_WEP104
:
1080 ktype
= AR9170_ENC_ALG_WEP128
;
1082 case WLAN_CIPHER_SUITE_TKIP
:
1083 ktype
= AR9170_ENC_ALG_TKIP
;
1085 case WLAN_CIPHER_SUITE_CCMP
:
1086 ktype
= AR9170_ENC_ALG_AESCCMP
;
1092 mutex_lock(&ar
->mutex
);
1093 if (cmd
== SET_KEY
) {
1094 if (!IS_STARTED(ar
)) {
1099 if (!(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1102 i
= 64 + key
->keyidx
;
1104 for (i
= 0; i
< 64; i
++)
1105 if (!(ar
->usedkeys
& BIT(i
)))
1111 key
->hw_key_idx
= i
;
1113 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
,
1115 min_t(u8
, 16, key
->keylen
));
1119 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1120 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
:
1127 * hardware is not capable generating MMIC
1128 * of fragmented frames!
1130 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1134 ar
->usedkeys
|= BIT(i
);
1136 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1138 if (!IS_STARTED(ar
)) {
1139 /* The device is gone... together with the key ;-) */
1144 if (key
->hw_key_idx
< 64) {
1145 ar
->usedkeys
&= ~BIT(key
->hw_key_idx
);
1147 err
= carl9170_upload_key(ar
, key
->hw_key_idx
, NULL
,
1148 AR9170_ENC_ALG_NONE
, 0,
1153 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1154 err
= carl9170_upload_key(ar
, key
->hw_key_idx
,
1156 AR9170_ENC_ALG_NONE
,
1164 err
= carl9170_disable_key(ar
, key
->hw_key_idx
);
1170 mutex_unlock(&ar
->mutex
);
1174 if (!ar
->rx_software_decryption
) {
1175 ar
->rx_software_decryption
= true;
1176 carl9170_set_operating_mode(ar
);
1178 mutex_unlock(&ar
->mutex
);
1182 static int carl9170_op_sta_add(struct ieee80211_hw
*hw
,
1183 struct ieee80211_vif
*vif
,
1184 struct ieee80211_sta
*sta
)
1186 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1189 if (sta
->ht_cap
.ht_supported
) {
1190 if (sta
->ht_cap
.ampdu_density
> 6) {
1192 * HW does support 16us AMPDU density.
1193 * No HT-Xmit for station.
1199 for (i
= 0; i
< CARL9170_NUM_TID
; i
++)
1200 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1202 sta_info
->ampdu_max_len
= 1 << (3 + sta
->ht_cap
.ampdu_factor
);
1203 sta_info
->ht_sta
= true;
1209 static int carl9170_op_sta_remove(struct ieee80211_hw
*hw
,
1210 struct ieee80211_vif
*vif
,
1211 struct ieee80211_sta
*sta
)
1213 struct ar9170
*ar
= hw
->priv
;
1214 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1216 bool cleanup
= false;
1218 if (sta
->ht_cap
.ht_supported
) {
1220 sta_info
->ht_sta
= false;
1223 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1224 struct carl9170_sta_tid
*tid_info
;
1226 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1227 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1232 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1233 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1234 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1235 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1241 carl9170_ampdu_gc(ar
);
1247 static int carl9170_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1248 const struct ieee80211_tx_queue_params
*param
)
1250 struct ar9170
*ar
= hw
->priv
;
1253 mutex_lock(&ar
->mutex
);
1254 if (queue
< ar
->hw
->queues
) {
1255 memcpy(&ar
->edcf
[ar9170_qmap
[queue
]], param
, sizeof(*param
));
1256 ret
= carl9170_set_qos(ar
);
1261 mutex_unlock(&ar
->mutex
);
1265 static void carl9170_ampdu_work(struct work_struct
*work
)
1267 struct ar9170
*ar
= container_of(work
, struct ar9170
,
1270 if (!IS_STARTED(ar
))
1273 mutex_lock(&ar
->mutex
);
1274 carl9170_ampdu_gc(ar
);
1275 mutex_unlock(&ar
->mutex
);
1278 static int carl9170_op_ampdu_action(struct ieee80211_hw
*hw
,
1279 struct ieee80211_vif
*vif
,
1280 enum ieee80211_ampdu_mlme_action action
,
1281 struct ieee80211_sta
*sta
,
1284 struct ar9170
*ar
= hw
->priv
;
1285 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1286 struct carl9170_sta_tid
*tid_info
;
1292 case IEEE80211_AMPDU_TX_START
:
1293 if (!sta_info
->ht_sta
)
1297 if (rcu_dereference(sta_info
->agg
[tid
])) {
1302 tid_info
= kzalloc(sizeof(struct carl9170_sta_tid
),
1309 tid_info
->hsn
= tid_info
->bsn
= tid_info
->snx
= (*ssn
);
1310 tid_info
->state
= CARL9170_TID_STATE_PROGRESS
;
1311 tid_info
->tid
= tid
;
1312 tid_info
->max
= sta_info
->ampdu_max_len
;
1314 INIT_LIST_HEAD(&tid_info
->list
);
1315 INIT_LIST_HEAD(&tid_info
->tmp_list
);
1316 skb_queue_head_init(&tid_info
->queue
);
1317 spin_lock_init(&tid_info
->lock
);
1319 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1320 ar
->tx_ampdu_list_len
++;
1321 list_add_tail_rcu(&tid_info
->list
, &ar
->tx_ampdu_list
);
1322 rcu_assign_pointer(sta_info
->agg
[tid
], tid_info
);
1323 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1326 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1329 case IEEE80211_AMPDU_TX_STOP
:
1331 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1333 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1334 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1335 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1336 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1339 rcu_assign_pointer(sta_info
->agg
[tid
], NULL
);
1342 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1343 ieee80211_queue_work(ar
->hw
, &ar
->ampdu_work
);
1346 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1348 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1350 sta_info
->stats
[tid
].clear
= true;
1353 bitmap_zero(tid_info
->bitmap
, CARL9170_BAW_SIZE
);
1354 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1358 if (WARN_ON_ONCE(!tid_info
))
1363 case IEEE80211_AMPDU_RX_START
:
1364 case IEEE80211_AMPDU_RX_STOP
:
1365 /* Handled by hardware */
1375 #ifdef CONFIG_CARL9170_WPC
1376 static int carl9170_register_wps_button(struct ar9170
*ar
)
1378 struct input_dev
*input
;
1381 if (!(ar
->features
& CARL9170_WPS_BUTTON
))
1384 input
= input_allocate_device();
1388 snprintf(ar
->wps
.name
, sizeof(ar
->wps
.name
), "%s WPS Button",
1389 wiphy_name(ar
->hw
->wiphy
));
1391 snprintf(ar
->wps
.phys
, sizeof(ar
->wps
.phys
),
1392 "ieee80211/%s/input0", wiphy_name(ar
->hw
->wiphy
));
1394 input
->name
= ar
->wps
.name
;
1395 input
->phys
= ar
->wps
.phys
;
1396 input
->id
.bustype
= BUS_USB
;
1397 input
->dev
.parent
= &ar
->hw
->wiphy
->dev
;
1399 input_set_capability(input
, EV_KEY
, KEY_WPS_BUTTON
);
1401 err
= input_register_device(input
);
1403 input_free_device(input
);
1407 ar
->wps
.pbc
= input
;
1410 #endif /* CONFIG_CARL9170_WPC */
1412 static int carl9170_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
1413 struct survey_info
*survey
)
1415 struct ar9170
*ar
= hw
->priv
;
1421 mutex_lock(&ar
->mutex
);
1422 err
= carl9170_get_noisefloor(ar
);
1423 mutex_unlock(&ar
->mutex
);
1427 survey
->channel
= ar
->channel
;
1428 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1429 survey
->noise
= ar
->noise
[0];
1433 static void carl9170_op_flush(struct ieee80211_hw
*hw
, bool drop
)
1435 struct ar9170
*ar
= hw
->priv
;
1438 mutex_lock(&ar
->mutex
);
1439 for_each_set_bit(vid
, &ar
->vif_bitmap
, ar
->fw
.vif_num
)
1440 carl9170_flush_cab(ar
, vid
);
1442 carl9170_flush(ar
, drop
);
1443 mutex_unlock(&ar
->mutex
);
1446 static int carl9170_op_get_stats(struct ieee80211_hw
*hw
,
1447 struct ieee80211_low_level_stats
*stats
)
1449 struct ar9170
*ar
= hw
->priv
;
1451 memset(stats
, 0, sizeof(*stats
));
1452 stats
->dot11ACKFailureCount
= ar
->tx_ack_failures
;
1453 stats
->dot11FCSErrorCount
= ar
->tx_fcs_errors
;
1457 static void carl9170_op_sta_notify(struct ieee80211_hw
*hw
,
1458 struct ieee80211_vif
*vif
,
1459 enum sta_notify_cmd cmd
,
1460 struct ieee80211_sta
*sta
)
1462 struct ar9170
*ar
= hw
->priv
;
1463 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1464 struct sk_buff
*skb
, *tmp
;
1465 struct sk_buff_head free
;
1469 case STA_NOTIFY_SLEEP
:
1471 * Since the peer is no longer listening, we have to return
1472 * as many SKBs as possible back to the mac80211 stack.
1473 * It will deal with the retry procedure, once the peer
1474 * has become available again.
1476 * NB: Ideally, the driver should return the all frames in
1477 * the correct, ascending order. However, I think that this
1478 * functionality should be implemented in the stack and not
1482 __skb_queue_head_init(&free
);
1484 if (sta
->ht_cap
.ht_supported
) {
1486 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1487 struct carl9170_sta_tid
*tid_info
;
1489 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1494 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1495 if (tid_info
->state
>
1496 CARL9170_TID_STATE_SUSPEND
)
1498 CARL9170_TID_STATE_SUSPEND
;
1499 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1501 spin_lock_bh(&tid_info
->lock
);
1502 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
1503 __skb_queue_tail(&free
, skb
);
1504 spin_unlock_bh(&tid_info
->lock
);
1509 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1510 spin_lock_bh(&ar
->tx_pending
[i
].lock
);
1511 skb_queue_walk_safe(&ar
->tx_pending
[i
], skb
, tmp
) {
1512 struct _carl9170_tx_superframe
*super
;
1513 struct ieee80211_hdr
*hdr
;
1514 struct ieee80211_tx_info
*info
;
1516 super
= (void *) skb
->data
;
1517 hdr
= (void *) super
->frame_data
;
1519 if (compare_ether_addr(hdr
->addr1
, sta
->addr
))
1522 __skb_unlink(skb
, &ar
->tx_pending
[i
]);
1524 info
= IEEE80211_SKB_CB(skb
);
1525 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1526 atomic_dec(&ar
->tx_ampdu_upload
);
1528 carl9170_tx_status(ar
, skb
, false);
1530 spin_unlock_bh(&ar
->tx_pending
[i
].lock
);
1533 while ((skb
= __skb_dequeue(&free
)))
1534 carl9170_tx_status(ar
, skb
, false);
1538 case STA_NOTIFY_AWAKE
:
1539 if (!sta
->ht_cap
.ht_supported
)
1543 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1544 struct carl9170_sta_tid
*tid_info
;
1546 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1551 if ((tid_info
->state
== CARL9170_TID_STATE_SUSPEND
))
1552 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1559 static const struct ieee80211_ops carl9170_ops
= {
1560 .start
= carl9170_op_start
,
1561 .stop
= carl9170_op_stop
,
1562 .tx
= carl9170_op_tx
,
1563 .flush
= carl9170_op_flush
,
1564 .add_interface
= carl9170_op_add_interface
,
1565 .remove_interface
= carl9170_op_remove_interface
,
1566 .config
= carl9170_op_config
,
1567 .prepare_multicast
= carl9170_op_prepare_multicast
,
1568 .configure_filter
= carl9170_op_configure_filter
,
1569 .conf_tx
= carl9170_op_conf_tx
,
1570 .bss_info_changed
= carl9170_op_bss_info_changed
,
1571 .get_tsf
= carl9170_op_get_tsf
,
1572 .set_key
= carl9170_op_set_key
,
1573 .sta_add
= carl9170_op_sta_add
,
1574 .sta_remove
= carl9170_op_sta_remove
,
1575 .sta_notify
= carl9170_op_sta_notify
,
1576 .get_survey
= carl9170_op_get_survey
,
1577 .get_stats
= carl9170_op_get_stats
,
1578 .ampdu_action
= carl9170_op_ampdu_action
,
1581 void *carl9170_alloc(size_t priv_size
)
1583 struct ieee80211_hw
*hw
;
1585 struct sk_buff
*skb
;
1589 * this buffer is used for rx stream reconstruction.
1590 * Under heavy load this device (or the transport layer?)
1591 * tends to split the streams into separate rx descriptors.
1594 skb
= __dev_alloc_skb(AR9170_RX_STREAM_MAX_SIZE
, GFP_KERNEL
);
1598 hw
= ieee80211_alloc_hw(priv_size
, &carl9170_ops
);
1604 ar
->rx_failover
= skb
;
1606 memset(&ar
->rx_plcp
, 0, sizeof(struct ar9170_rx_head
));
1607 ar
->rx_has_plcp
= false;
1610 * Here's a hidden pitfall!
1612 * All 4 AC queues work perfectly well under _legacy_ operation.
1613 * However as soon as aggregation is enabled, the traffic flow
1614 * gets very bumpy. Therefore we have to _switch_ to a
1615 * software AC with a single HW queue.
1617 hw
->queues
= __AR9170_NUM_TXQ
;
1619 mutex_init(&ar
->mutex
);
1620 spin_lock_init(&ar
->beacon_lock
);
1621 spin_lock_init(&ar
->cmd_lock
);
1622 spin_lock_init(&ar
->tx_stats_lock
);
1623 spin_lock_init(&ar
->tx_ampdu_list_lock
);
1624 spin_lock_init(&ar
->mem_lock
);
1625 spin_lock_init(&ar
->state_lock
);
1626 atomic_set(&ar
->pending_restarts
, 0);
1628 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1629 skb_queue_head_init(&ar
->tx_status
[i
]);
1630 skb_queue_head_init(&ar
->tx_pending
[i
]);
1632 INIT_WORK(&ar
->ps_work
, carl9170_ps_work
);
1633 INIT_WORK(&ar
->ping_work
, carl9170_ping_work
);
1634 INIT_WORK(&ar
->restart_work
, carl9170_restart_work
);
1635 INIT_WORK(&ar
->ampdu_work
, carl9170_ampdu_work
);
1636 INIT_DELAYED_WORK(&ar
->tx_janitor
, carl9170_tx_janitor
);
1637 INIT_LIST_HEAD(&ar
->tx_ampdu_list
);
1638 rcu_assign_pointer(ar
->tx_ampdu_iter
,
1639 (struct carl9170_sta_tid
*) &ar
->tx_ampdu_list
);
1641 bitmap_zero(&ar
->vif_bitmap
, ar
->fw
.vif_num
);
1642 INIT_LIST_HEAD(&ar
->vif_list
);
1643 init_completion(&ar
->tx_flush
);
1647 * IBSS/ADHOC and AP mode are only enabled, if the firmware
1648 * supports these modes. The code which will add the
1649 * additional interface_modes is in fw.c.
1651 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1652 BIT(NL80211_IFTYPE_P2P_CLIENT
);
1654 hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
|
1655 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
1656 IEEE80211_HW_SUPPORTS_PS
|
1657 IEEE80211_HW_PS_NULLFUNC_STACK
|
1658 IEEE80211_HW_SIGNAL_DBM
;
1660 if (!modparam_noht
) {
1662 * see the comment above, why we allow the user
1663 * to disable HT by a module parameter.
1665 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1668 hw
->extra_tx_headroom
= sizeof(struct _carl9170_tx_superframe
);
1669 hw
->sta_data_size
= sizeof(struct carl9170_sta_info
);
1670 hw
->vif_data_size
= sizeof(struct carl9170_vif_info
);
1672 hw
->max_rates
= CARL9170_TX_MAX_RATES
;
1673 hw
->max_rate_tries
= CARL9170_TX_USER_RATE_TRIES
;
1675 for (i
= 0; i
< ARRAY_SIZE(ar
->noise
); i
++)
1676 ar
->noise
[i
] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1678 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
1683 return ERR_PTR(-ENOMEM
);
1686 static int carl9170_read_eeprom(struct ar9170
*ar
)
1688 #define RW 8 /* number of words to read at once */
1689 #define RB (sizeof(u32) * RW)
1690 u8
*eeprom
= (void *)&ar
->eeprom
;
1694 BUILD_BUG_ON(sizeof(ar
->eeprom
) & 3);
1696 BUILD_BUG_ON(RB
> CARL9170_MAX_CMD_LEN
- 4);
1698 /* don't want to handle trailing remains */
1699 BUILD_BUG_ON(sizeof(ar
->eeprom
) % RB
);
1702 for (i
= 0; i
< sizeof(ar
->eeprom
)/RB
; i
++) {
1703 for (j
= 0; j
< RW
; j
++)
1704 offsets
[j
] = cpu_to_le32(AR9170_EEPROM_START
+
1707 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_RREG
,
1708 RB
, (u8
*) &offsets
,
1709 RB
, eeprom
+ RB
* i
);
1719 static int carl9170_parse_eeprom(struct ar9170
*ar
)
1721 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1722 unsigned int rx_streams
, tx_streams
, tx_params
= 0;
1725 if (ar
->eeprom
.length
== cpu_to_le16(0xffff))
1728 rx_streams
= hweight8(ar
->eeprom
.rx_mask
);
1729 tx_streams
= hweight8(ar
->eeprom
.tx_mask
);
1731 if (rx_streams
!= tx_streams
) {
1732 tx_params
= IEEE80211_HT_MCS_TX_RX_DIFF
;
1734 WARN_ON(!(tx_streams
>= 1 && tx_streams
<=
1735 IEEE80211_HT_MCS_TX_MAX_STREAMS
));
1737 tx_params
= (tx_streams
- 1) <<
1738 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1740 carl9170_band_2GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1741 carl9170_band_5GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1744 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_2GHZ
) {
1745 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1746 &carl9170_band_2GHz
;
1749 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_5GHZ
) {
1750 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1751 &carl9170_band_5GHz
;
1756 * I measured this, a bandswitch takes roughly
1757 * 135 ms and a frequency switch about 80.
1759 * FIXME: measure these values again once EEPROM settings
1760 * are used, that will influence them!
1763 ar
->hw
->channel_change_time
= 135 * 1000;
1765 ar
->hw
->channel_change_time
= 80 * 1000;
1767 regulatory
->current_rd
= le16_to_cpu(ar
->eeprom
.reg_domain
[0]);
1768 regulatory
->current_rd_ext
= le16_to_cpu(ar
->eeprom
.reg_domain
[1]);
1770 /* second part of wiphy init */
1771 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->eeprom
.mac_address
);
1773 return bands
? 0 : -EINVAL
;
1776 static int carl9170_reg_notifier(struct wiphy
*wiphy
,
1777 struct regulatory_request
*request
)
1779 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1780 struct ar9170
*ar
= hw
->priv
;
1782 return ath_reg_notifier_apply(wiphy
, request
, &ar
->common
.regulatory
);
1785 int carl9170_register(struct ar9170
*ar
)
1787 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1790 if (WARN_ON(ar
->mem_bitmap
))
1793 ar
->mem_bitmap
= kzalloc(roundup(ar
->fw
.mem_blocks
, BITS_PER_LONG
) *
1794 sizeof(unsigned long), GFP_KERNEL
);
1796 if (!ar
->mem_bitmap
)
1799 /* try to read EEPROM, init MAC addr */
1800 err
= carl9170_read_eeprom(ar
);
1804 err
= carl9170_fw_fix_eeprom(ar
);
1808 err
= carl9170_parse_eeprom(ar
);
1812 err
= ath_regd_init(regulatory
, ar
->hw
->wiphy
,
1813 carl9170_reg_notifier
);
1817 if (modparam_noht
) {
1818 carl9170_band_2GHz
.ht_cap
.ht_supported
= false;
1819 carl9170_band_5GHz
.ht_cap
.ht_supported
= false;
1822 for (i
= 0; i
< ar
->fw
.vif_num
; i
++) {
1823 ar
->vif_priv
[i
].id
= i
;
1824 ar
->vif_priv
[i
].vif
= NULL
;
1827 err
= ieee80211_register_hw(ar
->hw
);
1831 /* mac80211 interface is now registered */
1832 ar
->registered
= true;
1834 if (!ath_is_world_regd(regulatory
))
1835 regulatory_hint(ar
->hw
->wiphy
, regulatory
->alpha2
);
1837 #ifdef CONFIG_CARL9170_DEBUGFS
1838 carl9170_debugfs_register(ar
);
1839 #endif /* CONFIG_CARL9170_DEBUGFS */
1841 err
= carl9170_led_init(ar
);
1845 #ifdef CONFIG_CARL9170_LEDS
1846 err
= carl9170_led_register(ar
);
1849 #endif /* CONFIG_CARL9170_LEDS */
1851 #ifdef CONFIG_CARL9170_WPC
1852 err
= carl9170_register_wps_button(ar
);
1855 #endif /* CONFIG_CARL9170_WPC */
1857 dev_info(&ar
->udev
->dev
, "Atheros AR9170 is registered as '%s'\n",
1858 wiphy_name(ar
->hw
->wiphy
));
1863 carl9170_unregister(ar
);
1867 void carl9170_unregister(struct ar9170
*ar
)
1869 if (!ar
->registered
)
1872 ar
->registered
= false;
1874 #ifdef CONFIG_CARL9170_LEDS
1875 carl9170_led_unregister(ar
);
1876 #endif /* CONFIG_CARL9170_LEDS */
1878 #ifdef CONFIG_CARL9170_DEBUGFS
1879 carl9170_debugfs_unregister(ar
);
1880 #endif /* CONFIG_CARL9170_DEBUGFS */
1882 #ifdef CONFIG_CARL9170_WPC
1884 input_unregister_device(ar
->wps
.pbc
);
1887 #endif /* CONFIG_CARL9170_WPC */
1889 carl9170_cancel_worker(ar
);
1890 cancel_work_sync(&ar
->restart_work
);
1892 ieee80211_unregister_hw(ar
->hw
);
1895 void carl9170_free(struct ar9170
*ar
)
1897 WARN_ON(ar
->registered
);
1898 WARN_ON(IS_INITIALIZED(ar
));
1900 kfree_skb(ar
->rx_failover
);
1901 ar
->rx_failover
= NULL
;
1903 kfree(ar
->mem_bitmap
);
1904 ar
->mem_bitmap
= NULL
;
1906 mutex_destroy(&ar
->mutex
);
1908 ieee80211_free_hw(ar
->hw
);