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 err
= carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
,
384 AR9170_DMA_TRIGGER_RXQ
);
388 /* Clear key-cache */
389 for (i
= 0; i
< AR9170_CAM_MAX_USER
+ 4; i
++) {
390 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
395 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
400 if (i
< AR9170_CAM_MAX_USER
) {
401 err
= carl9170_disable_key(ar
, i
);
407 carl9170_set_state_when(ar
, CARL9170_IDLE
, CARL9170_STARTED
);
409 ieee80211_wake_queues(ar
->hw
);
413 mutex_unlock(&ar
->mutex
);
417 static void carl9170_cancel_worker(struct ar9170
*ar
)
419 cancel_delayed_work_sync(&ar
->tx_janitor
);
420 #ifdef CONFIG_CARL9170_LEDS
421 cancel_delayed_work_sync(&ar
->led_work
);
422 #endif /* CONFIG_CARL9170_LEDS */
423 cancel_work_sync(&ar
->ps_work
);
424 cancel_work_sync(&ar
->ampdu_work
);
427 static void carl9170_op_stop(struct ieee80211_hw
*hw
)
429 struct ar9170
*ar
= hw
->priv
;
431 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
433 ieee80211_stop_queues(ar
->hw
);
435 mutex_lock(&ar
->mutex
);
436 if (IS_ACCEPTING_CMD(ar
)) {
437 rcu_assign_pointer(ar
->beacon_iter
, NULL
);
439 carl9170_led_set_state(ar
, 0);
442 carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
, 0);
443 carl9170_usb_stop(ar
);
446 carl9170_zap_queues(ar
);
447 mutex_unlock(&ar
->mutex
);
449 carl9170_cancel_worker(ar
);
452 static void carl9170_restart_work(struct work_struct
*work
)
454 struct ar9170
*ar
= container_of(work
, struct ar9170
,
459 ar
->filter_state
= 0;
460 carl9170_cancel_worker(ar
);
462 mutex_lock(&ar
->mutex
);
463 err
= carl9170_usb_restart(ar
);
464 if (net_ratelimit()) {
466 dev_err(&ar
->udev
->dev
, "Failed to restart device "
469 dev_info(&ar
->udev
->dev
, "device restarted "
474 carl9170_zap_queues(ar
);
475 mutex_unlock(&ar
->mutex
);
477 ar
->restart_counter
++;
478 atomic_set(&ar
->pending_restarts
, 0);
480 ieee80211_restart_hw(ar
->hw
);
483 * The reset was unsuccessful and the device seems to
484 * be dead. But there's still one option: a low-level
485 * usb subsystem reset...
488 carl9170_usb_reset(ar
);
492 void carl9170_restart(struct ar9170
*ar
, const enum carl9170_restart_reasons r
)
494 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
497 * Sometimes, an error can trigger several different reset events.
498 * By ignoring these *surplus* reset events, the device won't be
499 * killed again, right after it has recovered.
501 if (atomic_inc_return(&ar
->pending_restarts
) > 1) {
502 dev_dbg(&ar
->udev
->dev
, "ignoring restart (%d)\n", r
);
506 ieee80211_stop_queues(ar
->hw
);
508 dev_err(&ar
->udev
->dev
, "restart device (%d)\n", r
);
510 if (!WARN_ON(r
== CARL9170_RR_NO_REASON
) ||
511 !WARN_ON(r
>= __CARL9170_RR_LAST
))
517 if (IS_ACCEPTING_CMD(ar
) && !ar
->needs_full_reset
)
518 ieee80211_queue_work(ar
->hw
, &ar
->restart_work
);
520 carl9170_usb_reset(ar
);
523 * At this point, the device instance might have vanished/disabled.
524 * So, don't put any code which access the ar9170 struct
525 * without proper protection.
529 static int carl9170_init_interface(struct ar9170
*ar
,
530 struct ieee80211_vif
*vif
)
532 struct ath_common
*common
= &ar
->common
;
536 WARN_ON_ONCE(IS_STARTED(ar
));
540 memcpy(common
->macaddr
, vif
->addr
, ETH_ALEN
);
542 if (modparam_nohwcrypt
||
543 ((vif
->type
!= NL80211_IFTYPE_STATION
) &&
544 (vif
->type
!= NL80211_IFTYPE_AP
))) {
545 ar
->rx_software_decryption
= true;
546 ar
->disable_offload
= true;
549 err
= carl9170_set_operating_mode(ar
);
553 static int carl9170_op_add_interface(struct ieee80211_hw
*hw
,
554 struct ieee80211_vif
*vif
)
556 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
557 struct ieee80211_vif
*main_vif
;
558 struct ar9170
*ar
= hw
->priv
;
559 int vif_id
= -1, err
= 0;
561 mutex_lock(&ar
->mutex
);
563 if (vif_priv
->active
) {
565 * Skip the interface structure initialization,
566 * if the vif survived the _restart call.
568 vif_id
= vif_priv
->id
;
569 vif_priv
->enable_beacon
= false;
571 spin_lock_bh(&ar
->beacon_lock
);
572 dev_kfree_skb_any(vif_priv
->beacon
);
573 vif_priv
->beacon
= NULL
;
574 spin_unlock_bh(&ar
->beacon_lock
);
579 main_vif
= carl9170_get_main_vif(ar
);
582 switch (main_vif
->type
) {
583 case NL80211_IFTYPE_STATION
:
584 if (vif
->type
== NL80211_IFTYPE_STATION
)
592 case NL80211_IFTYPE_AP
:
593 if ((vif
->type
== NL80211_IFTYPE_STATION
) ||
594 (vif
->type
== NL80211_IFTYPE_WDS
) ||
595 (vif
->type
== NL80211_IFTYPE_AP
))
608 vif_id
= bitmap_find_free_region(&ar
->vif_bitmap
, ar
->fw
.vif_num
, 0);
617 BUG_ON(ar
->vif_priv
[vif_id
].id
!= vif_id
);
619 vif_priv
->active
= true;
620 vif_priv
->id
= vif_id
;
621 vif_priv
->enable_beacon
= false;
623 list_add_tail_rcu(&vif_priv
->list
, &ar
->vif_list
);
624 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, vif
);
627 if (carl9170_get_main_vif(ar
) == vif
) {
628 rcu_assign_pointer(ar
->beacon_iter
, vif_priv
);
631 err
= carl9170_init_interface(ar
, vif
);
635 err
= carl9170_mod_virtual_mac(ar
, vif_id
, vif
->addr
);
643 if (err
&& (vif_id
!= -1)) {
644 vif_priv
->active
= false;
645 bitmap_release_region(&ar
->vif_bitmap
, vif_id
, 0);
647 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, NULL
);
648 list_del_rcu(&vif_priv
->list
);
649 mutex_unlock(&ar
->mutex
);
653 ar
->ps
.off_override
|= PS_OFF_VIF
;
655 mutex_unlock(&ar
->mutex
);
661 static void carl9170_op_remove_interface(struct ieee80211_hw
*hw
,
662 struct ieee80211_vif
*vif
)
664 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
665 struct ieee80211_vif
*main_vif
;
666 struct ar9170
*ar
= hw
->priv
;
669 mutex_lock(&ar
->mutex
);
671 if (WARN_ON_ONCE(!vif_priv
->active
))
677 main_vif
= carl9170_get_main_vif(ar
);
681 vif_priv
->active
= false;
682 WARN_ON(vif_priv
->enable_beacon
);
683 vif_priv
->enable_beacon
= false;
684 list_del_rcu(&vif_priv
->list
);
685 rcu_assign_pointer(ar
->vif_priv
[id
].vif
, NULL
);
687 if (vif
== main_vif
) {
691 WARN_ON(carl9170_init_interface(ar
,
692 carl9170_get_main_vif(ar
)));
694 carl9170_set_operating_mode(ar
);
699 WARN_ON(carl9170_mod_virtual_mac(ar
, id
, NULL
));
702 carl9170_update_beacon(ar
, false);
703 carl9170_flush_cab(ar
, id
);
705 spin_lock_bh(&ar
->beacon_lock
);
706 dev_kfree_skb_any(vif_priv
->beacon
);
707 vif_priv
->beacon
= NULL
;
708 spin_unlock_bh(&ar
->beacon_lock
);
710 bitmap_release_region(&ar
->vif_bitmap
, id
, 0);
712 carl9170_set_beacon_timers(ar
);
715 ar
->ps
.off_override
&= ~PS_OFF_VIF
;
718 mutex_unlock(&ar
->mutex
);
723 void carl9170_ps_check(struct ar9170
*ar
)
725 ieee80211_queue_work(ar
->hw
, &ar
->ps_work
);
728 /* caller must hold ar->mutex */
729 static int carl9170_ps_update(struct ar9170
*ar
)
734 if (!ar
->ps
.off_override
)
735 ps
= (ar
->hw
->conf
.flags
& IEEE80211_CONF_PS
);
737 if (ps
!= ar
->ps
.state
) {
738 err
= carl9170_powersave(ar
, ps
);
742 if (ar
->ps
.state
&& !ps
) {
743 ar
->ps
.sleep_ms
= jiffies_to_msecs(jiffies
-
748 ar
->ps
.last_slept
= jiffies
;
750 ar
->ps
.last_action
= jiffies
;
757 static void carl9170_ps_work(struct work_struct
*work
)
759 struct ar9170
*ar
= container_of(work
, struct ar9170
,
761 mutex_lock(&ar
->mutex
);
763 WARN_ON_ONCE(carl9170_ps_update(ar
) != 0);
764 mutex_unlock(&ar
->mutex
);
768 static int carl9170_op_config(struct ieee80211_hw
*hw
, u32 changed
)
770 struct ar9170
*ar
= hw
->priv
;
773 mutex_lock(&ar
->mutex
);
774 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
779 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
780 err
= carl9170_ps_update(ar
);
785 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
790 if (changed
& IEEE80211_CONF_CHANGE_SMPS
) {
795 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
796 /* adjust slot time for 5 GHz */
797 err
= carl9170_set_slot_time(ar
);
801 err
= carl9170_set_channel(ar
, hw
->conf
.channel
,
802 hw
->conf
.channel_type
, CARL9170_RFI_NONE
);
806 err
= carl9170_set_dyn_sifs_ack(ar
);
810 err
= carl9170_set_rts_cts_rate(ar
);
816 mutex_unlock(&ar
->mutex
);
820 static u64
carl9170_op_prepare_multicast(struct ieee80211_hw
*hw
,
821 struct netdev_hw_addr_list
*mc_list
)
823 struct netdev_hw_addr
*ha
;
826 /* always get broadcast frames */
827 mchash
= 1ULL << (0xff >> 2);
829 netdev_hw_addr_list_for_each(ha
, mc_list
)
830 mchash
|= 1ULL << (ha
->addr
[5] >> 2);
835 static void carl9170_op_configure_filter(struct ieee80211_hw
*hw
,
836 unsigned int changed_flags
,
837 unsigned int *new_flags
,
840 struct ar9170
*ar
= hw
->priv
;
842 /* mask supported flags */
843 *new_flags
&= FIF_ALLMULTI
| FIF_FCSFAIL
| FIF_PLCPFAIL
|
844 FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
;
846 if (!IS_ACCEPTING_CMD(ar
))
849 mutex_lock(&ar
->mutex
);
851 ar
->filter_state
= *new_flags
;
853 * We can support more by setting the sniffer bit and
854 * then checking the error flags, later.
857 if (changed_flags
& FIF_ALLMULTI
&& *new_flags
& FIF_ALLMULTI
)
860 if (multicast
!= ar
->cur_mc_hash
)
861 WARN_ON(carl9170_update_multicast(ar
, multicast
));
863 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
864 ar
->sniffer_enabled
= !!(*new_flags
&
865 (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
));
867 WARN_ON(carl9170_set_operating_mode(ar
));
870 mutex_unlock(&ar
->mutex
);
874 static void carl9170_op_bss_info_changed(struct ieee80211_hw
*hw
,
875 struct ieee80211_vif
*vif
,
876 struct ieee80211_bss_conf
*bss_conf
,
879 struct ar9170
*ar
= hw
->priv
;
880 struct ath_common
*common
= &ar
->common
;
882 struct carl9170_vif_info
*vif_priv
;
883 struct ieee80211_vif
*main_vif
;
885 mutex_lock(&ar
->mutex
);
886 vif_priv
= (void *) vif
->drv_priv
;
887 main_vif
= carl9170_get_main_vif(ar
);
888 if (WARN_ON(!main_vif
))
891 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
892 struct carl9170_vif_info
*iter
;
895 vif_priv
->enable_beacon
= bss_conf
->enable_beacon
;
897 list_for_each_entry_rcu(iter
, &ar
->vif_list
, list
) {
898 if (iter
->active
&& iter
->enable_beacon
)
904 ar
->beacon_enabled
= i
;
907 if (changed
& BSS_CHANGED_BEACON
) {
908 err
= carl9170_update_beacon(ar
, false);
913 if (changed
& (BSS_CHANGED_BEACON_ENABLED
| BSS_CHANGED_BEACON
|
914 BSS_CHANGED_BEACON_INT
)) {
916 if (main_vif
!= vif
) {
917 bss_conf
->beacon_int
= main_vif
->bss_conf
.beacon_int
;
918 bss_conf
->dtim_period
= main_vif
->bss_conf
.dtim_period
;
922 * Therefore a hard limit for the broadcast traffic should
923 * prevent false alarms.
925 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
926 (bss_conf
->beacon_int
* bss_conf
->dtim_period
>=
927 (CARL9170_QUEUE_STUCK_TIMEOUT
/ 2))) {
932 err
= carl9170_set_beacon_timers(ar
);
937 if (changed
& BSS_CHANGED_HT
) {
948 * The following settings can only be changed by the
952 if (changed
& BSS_CHANGED_BSSID
) {
953 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
954 err
= carl9170_set_operating_mode(ar
);
959 if (changed
& BSS_CHANGED_ASSOC
) {
960 ar
->common
.curaid
= bss_conf
->aid
;
961 err
= carl9170_set_beacon_timers(ar
);
966 if (changed
& BSS_CHANGED_ERP_SLOT
) {
967 err
= carl9170_set_slot_time(ar
);
972 if (changed
& BSS_CHANGED_BASIC_RATES
) {
973 err
= carl9170_set_mac_rates(ar
);
979 WARN_ON_ONCE(err
&& IS_STARTED(ar
));
980 mutex_unlock(&ar
->mutex
);
983 static u64
carl9170_op_get_tsf(struct ieee80211_hw
*hw
)
985 struct ar9170
*ar
= hw
->priv
;
986 struct carl9170_tsf_rsp tsf
;
989 mutex_lock(&ar
->mutex
);
990 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_READ_TSF
,
991 0, NULL
, sizeof(tsf
), &tsf
);
992 mutex_unlock(&ar
->mutex
);
996 return le64_to_cpu(tsf
.tsf_64
);
999 static int carl9170_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1000 struct ieee80211_vif
*vif
,
1001 struct ieee80211_sta
*sta
,
1002 struct ieee80211_key_conf
*key
)
1004 struct ar9170
*ar
= hw
->priv
;
1008 if (ar
->disable_offload
|| !vif
)
1012 * We have to fall back to software encryption, whenever
1013 * the user choose to participates in an IBSS or is connected
1014 * to more than one network.
1016 * This is very unfortunate, because some machines cannot handle
1017 * the high througput speed in 802.11n networks.
1020 if (!is_main_vif(ar
, vif
))
1024 * While the hardware supports *catch-all* key, for offloading
1025 * group-key en-/de-cryption. The way of how the hardware
1026 * decides which keyId maps to which key, remains a mystery...
1028 if ((vif
->type
!= NL80211_IFTYPE_STATION
&&
1029 vif
->type
!= NL80211_IFTYPE_ADHOC
) &&
1030 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1033 switch (key
->cipher
) {
1034 case WLAN_CIPHER_SUITE_WEP40
:
1035 ktype
= AR9170_ENC_ALG_WEP64
;
1037 case WLAN_CIPHER_SUITE_WEP104
:
1038 ktype
= AR9170_ENC_ALG_WEP128
;
1040 case WLAN_CIPHER_SUITE_TKIP
:
1041 ktype
= AR9170_ENC_ALG_TKIP
;
1043 case WLAN_CIPHER_SUITE_CCMP
:
1044 ktype
= AR9170_ENC_ALG_AESCCMP
;
1050 mutex_lock(&ar
->mutex
);
1051 if (cmd
== SET_KEY
) {
1052 if (!IS_STARTED(ar
)) {
1057 if (!(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1060 i
= 64 + key
->keyidx
;
1062 for (i
= 0; i
< 64; i
++)
1063 if (!(ar
->usedkeys
& BIT(i
)))
1069 key
->hw_key_idx
= i
;
1071 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
,
1073 min_t(u8
, 16, key
->keylen
));
1077 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1078 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
:
1085 * hardware is not capable generating MMIC
1086 * of fragmented frames!
1088 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1092 ar
->usedkeys
|= BIT(i
);
1094 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1096 if (!IS_STARTED(ar
)) {
1097 /* The device is gone... together with the key ;-) */
1102 if (key
->hw_key_idx
< 64) {
1103 ar
->usedkeys
&= ~BIT(key
->hw_key_idx
);
1105 err
= carl9170_upload_key(ar
, key
->hw_key_idx
, NULL
,
1106 AR9170_ENC_ALG_NONE
, 0,
1111 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1112 err
= carl9170_upload_key(ar
, key
->hw_key_idx
,
1114 AR9170_ENC_ALG_NONE
,
1122 err
= carl9170_disable_key(ar
, key
->hw_key_idx
);
1128 mutex_unlock(&ar
->mutex
);
1132 if (!ar
->rx_software_decryption
) {
1133 ar
->rx_software_decryption
= true;
1134 carl9170_set_operating_mode(ar
);
1136 mutex_unlock(&ar
->mutex
);
1140 static int carl9170_op_sta_add(struct ieee80211_hw
*hw
,
1141 struct ieee80211_vif
*vif
,
1142 struct ieee80211_sta
*sta
)
1144 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1147 if (sta
->ht_cap
.ht_supported
) {
1148 if (sta
->ht_cap
.ampdu_density
> 6) {
1150 * HW does support 16us AMPDU density.
1151 * No HT-Xmit for station.
1157 for (i
= 0; i
< CARL9170_NUM_TID
; i
++)
1158 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1160 sta_info
->ampdu_max_len
= 1 << (3 + sta
->ht_cap
.ampdu_factor
);
1161 sta_info
->ht_sta
= true;
1167 static int carl9170_op_sta_remove(struct ieee80211_hw
*hw
,
1168 struct ieee80211_vif
*vif
,
1169 struct ieee80211_sta
*sta
)
1171 struct ar9170
*ar
= hw
->priv
;
1172 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1174 bool cleanup
= false;
1176 if (sta
->ht_cap
.ht_supported
) {
1178 sta_info
->ht_sta
= false;
1181 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1182 struct carl9170_sta_tid
*tid_info
;
1184 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1185 rcu_assign_pointer(sta_info
->agg
[i
], NULL
);
1190 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1191 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1192 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1193 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1199 carl9170_ampdu_gc(ar
);
1205 static int carl9170_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1206 const struct ieee80211_tx_queue_params
*param
)
1208 struct ar9170
*ar
= hw
->priv
;
1211 mutex_lock(&ar
->mutex
);
1212 if (queue
< ar
->hw
->queues
) {
1213 memcpy(&ar
->edcf
[ar9170_qmap
[queue
]], param
, sizeof(*param
));
1214 ret
= carl9170_set_qos(ar
);
1219 mutex_unlock(&ar
->mutex
);
1223 static void carl9170_ampdu_work(struct work_struct
*work
)
1225 struct ar9170
*ar
= container_of(work
, struct ar9170
,
1228 if (!IS_STARTED(ar
))
1231 mutex_lock(&ar
->mutex
);
1232 carl9170_ampdu_gc(ar
);
1233 mutex_unlock(&ar
->mutex
);
1236 static int carl9170_op_ampdu_action(struct ieee80211_hw
*hw
,
1237 struct ieee80211_vif
*vif
,
1238 enum ieee80211_ampdu_mlme_action action
,
1239 struct ieee80211_sta
*sta
,
1242 struct ar9170
*ar
= hw
->priv
;
1243 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1244 struct carl9170_sta_tid
*tid_info
;
1250 case IEEE80211_AMPDU_TX_START
:
1251 if (!sta_info
->ht_sta
)
1255 if (rcu_dereference(sta_info
->agg
[tid
])) {
1260 tid_info
= kzalloc(sizeof(struct carl9170_sta_tid
),
1267 tid_info
->hsn
= tid_info
->bsn
= tid_info
->snx
= (*ssn
);
1268 tid_info
->state
= CARL9170_TID_STATE_PROGRESS
;
1269 tid_info
->tid
= tid
;
1270 tid_info
->max
= sta_info
->ampdu_max_len
;
1272 INIT_LIST_HEAD(&tid_info
->list
);
1273 INIT_LIST_HEAD(&tid_info
->tmp_list
);
1274 skb_queue_head_init(&tid_info
->queue
);
1275 spin_lock_init(&tid_info
->lock
);
1277 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1278 ar
->tx_ampdu_list_len
++;
1279 list_add_tail_rcu(&tid_info
->list
, &ar
->tx_ampdu_list
);
1280 rcu_assign_pointer(sta_info
->agg
[tid
], tid_info
);
1281 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1284 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1287 case IEEE80211_AMPDU_TX_STOP
:
1289 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1291 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1292 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1293 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1294 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1297 rcu_assign_pointer(sta_info
->agg
[tid
], NULL
);
1300 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1301 ieee80211_queue_work(ar
->hw
, &ar
->ampdu_work
);
1304 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1306 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1308 sta_info
->stats
[tid
].clear
= true;
1311 bitmap_zero(tid_info
->bitmap
, CARL9170_BAW_SIZE
);
1312 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1316 if (WARN_ON_ONCE(!tid_info
))
1321 case IEEE80211_AMPDU_RX_START
:
1322 case IEEE80211_AMPDU_RX_STOP
:
1323 /* Handled by hardware */
1333 #ifdef CONFIG_CARL9170_WPC
1334 static int carl9170_register_wps_button(struct ar9170
*ar
)
1336 struct input_dev
*input
;
1339 if (!(ar
->features
& CARL9170_WPS_BUTTON
))
1342 input
= input_allocate_device();
1346 snprintf(ar
->wps
.name
, sizeof(ar
->wps
.name
), "%s WPS Button",
1347 wiphy_name(ar
->hw
->wiphy
));
1349 snprintf(ar
->wps
.phys
, sizeof(ar
->wps
.phys
),
1350 "ieee80211/%s/input0", wiphy_name(ar
->hw
->wiphy
));
1352 input
->name
= ar
->wps
.name
;
1353 input
->phys
= ar
->wps
.phys
;
1354 input
->id
.bustype
= BUS_USB
;
1355 input
->dev
.parent
= &ar
->hw
->wiphy
->dev
;
1357 input_set_capability(input
, EV_KEY
, KEY_WPS_BUTTON
);
1359 err
= input_register_device(input
);
1361 input_free_device(input
);
1365 ar
->wps
.pbc
= input
;
1368 #endif /* CONFIG_CARL9170_WPC */
1370 static int carl9170_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
1371 struct survey_info
*survey
)
1373 struct ar9170
*ar
= hw
->priv
;
1379 mutex_lock(&ar
->mutex
);
1380 err
= carl9170_get_noisefloor(ar
);
1381 mutex_unlock(&ar
->mutex
);
1385 survey
->channel
= ar
->channel
;
1386 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1387 survey
->noise
= ar
->noise
[0];
1391 static void carl9170_op_flush(struct ieee80211_hw
*hw
, bool drop
)
1393 struct ar9170
*ar
= hw
->priv
;
1396 mutex_lock(&ar
->mutex
);
1397 for_each_set_bit(vid
, &ar
->vif_bitmap
, ar
->fw
.vif_num
)
1398 carl9170_flush_cab(ar
, vid
);
1400 carl9170_flush(ar
, drop
);
1401 mutex_unlock(&ar
->mutex
);
1404 static int carl9170_op_get_stats(struct ieee80211_hw
*hw
,
1405 struct ieee80211_low_level_stats
*stats
)
1407 struct ar9170
*ar
= hw
->priv
;
1409 memset(stats
, 0, sizeof(*stats
));
1410 stats
->dot11ACKFailureCount
= ar
->tx_ack_failures
;
1411 stats
->dot11FCSErrorCount
= ar
->tx_fcs_errors
;
1415 static void carl9170_op_sta_notify(struct ieee80211_hw
*hw
,
1416 struct ieee80211_vif
*vif
,
1417 enum sta_notify_cmd cmd
,
1418 struct ieee80211_sta
*sta
)
1420 struct ar9170
*ar
= hw
->priv
;
1421 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1422 struct sk_buff
*skb
, *tmp
;
1423 struct sk_buff_head free
;
1427 case STA_NOTIFY_SLEEP
:
1429 * Since the peer is no longer listening, we have to return
1430 * as many SKBs as possible back to the mac80211 stack.
1431 * It will deal with the retry procedure, once the peer
1432 * has become available again.
1434 * NB: Ideally, the driver should return the all frames in
1435 * the correct, ascending order. However, I think that this
1436 * functionality should be implemented in the stack and not
1440 __skb_queue_head_init(&free
);
1442 if (sta
->ht_cap
.ht_supported
) {
1444 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1445 struct carl9170_sta_tid
*tid_info
;
1447 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1452 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1453 if (tid_info
->state
>
1454 CARL9170_TID_STATE_SUSPEND
)
1456 CARL9170_TID_STATE_SUSPEND
;
1457 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1459 spin_lock_bh(&tid_info
->lock
);
1460 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
1461 __skb_queue_tail(&free
, skb
);
1462 spin_unlock_bh(&tid_info
->lock
);
1467 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1468 spin_lock_bh(&ar
->tx_pending
[i
].lock
);
1469 skb_queue_walk_safe(&ar
->tx_pending
[i
], skb
, tmp
) {
1470 struct _carl9170_tx_superframe
*super
;
1471 struct ieee80211_hdr
*hdr
;
1472 struct ieee80211_tx_info
*info
;
1474 super
= (void *) skb
->data
;
1475 hdr
= (void *) super
->frame_data
;
1477 if (compare_ether_addr(hdr
->addr1
, sta
->addr
))
1480 __skb_unlink(skb
, &ar
->tx_pending
[i
]);
1482 info
= IEEE80211_SKB_CB(skb
);
1483 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1484 atomic_dec(&ar
->tx_ampdu_upload
);
1486 carl9170_tx_status(ar
, skb
, false);
1488 spin_unlock_bh(&ar
->tx_pending
[i
].lock
);
1491 while ((skb
= __skb_dequeue(&free
)))
1492 carl9170_tx_status(ar
, skb
, false);
1496 case STA_NOTIFY_AWAKE
:
1497 if (!sta
->ht_cap
.ht_supported
)
1501 for (i
= 0; i
< CARL9170_NUM_TID
; i
++) {
1502 struct carl9170_sta_tid
*tid_info
;
1504 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1509 if ((tid_info
->state
== CARL9170_TID_STATE_SUSPEND
))
1510 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1517 static const struct ieee80211_ops carl9170_ops
= {
1518 .start
= carl9170_op_start
,
1519 .stop
= carl9170_op_stop
,
1520 .tx
= carl9170_op_tx
,
1521 .flush
= carl9170_op_flush
,
1522 .add_interface
= carl9170_op_add_interface
,
1523 .remove_interface
= carl9170_op_remove_interface
,
1524 .config
= carl9170_op_config
,
1525 .prepare_multicast
= carl9170_op_prepare_multicast
,
1526 .configure_filter
= carl9170_op_configure_filter
,
1527 .conf_tx
= carl9170_op_conf_tx
,
1528 .bss_info_changed
= carl9170_op_bss_info_changed
,
1529 .get_tsf
= carl9170_op_get_tsf
,
1530 .set_key
= carl9170_op_set_key
,
1531 .sta_add
= carl9170_op_sta_add
,
1532 .sta_remove
= carl9170_op_sta_remove
,
1533 .sta_notify
= carl9170_op_sta_notify
,
1534 .get_survey
= carl9170_op_get_survey
,
1535 .get_stats
= carl9170_op_get_stats
,
1536 .ampdu_action
= carl9170_op_ampdu_action
,
1539 void *carl9170_alloc(size_t priv_size
)
1541 struct ieee80211_hw
*hw
;
1543 struct sk_buff
*skb
;
1547 * this buffer is used for rx stream reconstruction.
1548 * Under heavy load this device (or the transport layer?)
1549 * tends to split the streams into separate rx descriptors.
1552 skb
= __dev_alloc_skb(AR9170_RX_STREAM_MAX_SIZE
, GFP_KERNEL
);
1556 hw
= ieee80211_alloc_hw(priv_size
, &carl9170_ops
);
1562 ar
->rx_failover
= skb
;
1564 memset(&ar
->rx_plcp
, 0, sizeof(struct ar9170_rx_head
));
1565 ar
->rx_has_plcp
= false;
1568 * Here's a hidden pitfall!
1570 * All 4 AC queues work perfectly well under _legacy_ operation.
1571 * However as soon as aggregation is enabled, the traffic flow
1572 * gets very bumpy. Therefore we have to _switch_ to a
1573 * software AC with a single HW queue.
1575 hw
->queues
= __AR9170_NUM_TXQ
;
1577 mutex_init(&ar
->mutex
);
1578 spin_lock_init(&ar
->beacon_lock
);
1579 spin_lock_init(&ar
->cmd_lock
);
1580 spin_lock_init(&ar
->tx_stats_lock
);
1581 spin_lock_init(&ar
->tx_ampdu_list_lock
);
1582 spin_lock_init(&ar
->mem_lock
);
1583 spin_lock_init(&ar
->state_lock
);
1584 atomic_set(&ar
->pending_restarts
, 0);
1586 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1587 skb_queue_head_init(&ar
->tx_status
[i
]);
1588 skb_queue_head_init(&ar
->tx_pending
[i
]);
1590 INIT_WORK(&ar
->ps_work
, carl9170_ps_work
);
1591 INIT_WORK(&ar
->restart_work
, carl9170_restart_work
);
1592 INIT_WORK(&ar
->ampdu_work
, carl9170_ampdu_work
);
1593 INIT_DELAYED_WORK(&ar
->tx_janitor
, carl9170_tx_janitor
);
1594 INIT_LIST_HEAD(&ar
->tx_ampdu_list
);
1595 rcu_assign_pointer(ar
->tx_ampdu_iter
,
1596 (struct carl9170_sta_tid
*) &ar
->tx_ampdu_list
);
1598 bitmap_zero(&ar
->vif_bitmap
, ar
->fw
.vif_num
);
1599 INIT_LIST_HEAD(&ar
->vif_list
);
1600 init_completion(&ar
->tx_flush
);
1604 * IBSS/ADHOC and AP mode are only enabled, if the firmware
1605 * supports these modes. The code which will add the
1606 * additional interface_modes is in fw.c.
1608 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
1610 hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
|
1611 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
1612 IEEE80211_HW_SUPPORTS_PS
|
1613 IEEE80211_HW_PS_NULLFUNC_STACK
|
1614 IEEE80211_HW_SIGNAL_DBM
;
1616 if (!modparam_noht
) {
1618 * see the comment above, why we allow the user
1619 * to disable HT by a module parameter.
1621 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1624 hw
->extra_tx_headroom
= sizeof(struct _carl9170_tx_superframe
);
1625 hw
->sta_data_size
= sizeof(struct carl9170_sta_info
);
1626 hw
->vif_data_size
= sizeof(struct carl9170_vif_info
);
1628 hw
->max_rates
= CARL9170_TX_MAX_RATES
;
1629 hw
->max_rate_tries
= CARL9170_TX_USER_RATE_TRIES
;
1631 for (i
= 0; i
< ARRAY_SIZE(ar
->noise
); i
++)
1632 ar
->noise
[i
] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1634 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
1639 return ERR_PTR(-ENOMEM
);
1642 static int carl9170_read_eeprom(struct ar9170
*ar
)
1644 #define RW 8 /* number of words to read at once */
1645 #define RB (sizeof(u32) * RW)
1646 u8
*eeprom
= (void *)&ar
->eeprom
;
1650 BUILD_BUG_ON(sizeof(ar
->eeprom
) & 3);
1652 BUILD_BUG_ON(RB
> CARL9170_MAX_CMD_LEN
- 4);
1654 /* don't want to handle trailing remains */
1655 BUILD_BUG_ON(sizeof(ar
->eeprom
) % RB
);
1658 for (i
= 0; i
< sizeof(ar
->eeprom
)/RB
; i
++) {
1659 for (j
= 0; j
< RW
; j
++)
1660 offsets
[j
] = cpu_to_le32(AR9170_EEPROM_START
+
1663 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_RREG
,
1664 RB
, (u8
*) &offsets
,
1665 RB
, eeprom
+ RB
* i
);
1675 static int carl9170_parse_eeprom(struct ar9170
*ar
)
1677 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1678 unsigned int rx_streams
, tx_streams
, tx_params
= 0;
1681 if (ar
->eeprom
.length
== cpu_to_le16(0xffff))
1684 rx_streams
= hweight8(ar
->eeprom
.rx_mask
);
1685 tx_streams
= hweight8(ar
->eeprom
.tx_mask
);
1687 if (rx_streams
!= tx_streams
) {
1688 tx_params
= IEEE80211_HT_MCS_TX_RX_DIFF
;
1690 WARN_ON(!(tx_streams
>= 1 && tx_streams
<=
1691 IEEE80211_HT_MCS_TX_MAX_STREAMS
));
1693 tx_params
= (tx_streams
- 1) <<
1694 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1696 carl9170_band_2GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1697 carl9170_band_5GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1700 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_2GHZ
) {
1701 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1702 &carl9170_band_2GHz
;
1705 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_5GHZ
) {
1706 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1707 &carl9170_band_5GHz
;
1712 * I measured this, a bandswitch takes roughly
1713 * 135 ms and a frequency switch about 80.
1715 * FIXME: measure these values again once EEPROM settings
1716 * are used, that will influence them!
1719 ar
->hw
->channel_change_time
= 135 * 1000;
1721 ar
->hw
->channel_change_time
= 80 * 1000;
1723 regulatory
->current_rd
= le16_to_cpu(ar
->eeprom
.reg_domain
[0]);
1724 regulatory
->current_rd_ext
= le16_to_cpu(ar
->eeprom
.reg_domain
[1]);
1726 /* second part of wiphy init */
1727 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->eeprom
.mac_address
);
1729 return bands
? 0 : -EINVAL
;
1732 static int carl9170_reg_notifier(struct wiphy
*wiphy
,
1733 struct regulatory_request
*request
)
1735 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1736 struct ar9170
*ar
= hw
->priv
;
1738 return ath_reg_notifier_apply(wiphy
, request
, &ar
->common
.regulatory
);
1741 int carl9170_register(struct ar9170
*ar
)
1743 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1746 if (WARN_ON(ar
->mem_bitmap
))
1749 ar
->mem_bitmap
= kzalloc(roundup(ar
->fw
.mem_blocks
, BITS_PER_LONG
) *
1750 sizeof(unsigned long), GFP_KERNEL
);
1752 if (!ar
->mem_bitmap
)
1755 /* try to read EEPROM, init MAC addr */
1756 err
= carl9170_read_eeprom(ar
);
1760 err
= carl9170_fw_fix_eeprom(ar
);
1764 err
= carl9170_parse_eeprom(ar
);
1768 err
= ath_regd_init(regulatory
, ar
->hw
->wiphy
,
1769 carl9170_reg_notifier
);
1773 if (modparam_noht
) {
1774 carl9170_band_2GHz
.ht_cap
.ht_supported
= false;
1775 carl9170_band_5GHz
.ht_cap
.ht_supported
= false;
1778 for (i
= 0; i
< ar
->fw
.vif_num
; i
++) {
1779 ar
->vif_priv
[i
].id
= i
;
1780 ar
->vif_priv
[i
].vif
= NULL
;
1783 err
= ieee80211_register_hw(ar
->hw
);
1787 /* mac80211 interface is now registered */
1788 ar
->registered
= true;
1790 if (!ath_is_world_regd(regulatory
))
1791 regulatory_hint(ar
->hw
->wiphy
, regulatory
->alpha2
);
1793 #ifdef CONFIG_CARL9170_DEBUGFS
1794 carl9170_debugfs_register(ar
);
1795 #endif /* CONFIG_CARL9170_DEBUGFS */
1797 err
= carl9170_led_init(ar
);
1801 #ifdef CONFIG_CARL9170_LEDS
1802 err
= carl9170_led_register(ar
);
1805 #endif /* CONFIG_CAR9L170_LEDS */
1807 #ifdef CONFIG_CARL9170_WPC
1808 err
= carl9170_register_wps_button(ar
);
1811 #endif /* CONFIG_CARL9170_WPC */
1813 dev_info(&ar
->udev
->dev
, "Atheros AR9170 is registered as '%s'\n",
1814 wiphy_name(ar
->hw
->wiphy
));
1819 carl9170_unregister(ar
);
1823 void carl9170_unregister(struct ar9170
*ar
)
1825 if (!ar
->registered
)
1828 ar
->registered
= false;
1830 #ifdef CONFIG_CARL9170_LEDS
1831 carl9170_led_unregister(ar
);
1832 #endif /* CONFIG_CARL9170_LEDS */
1834 #ifdef CONFIG_CARL9170_DEBUGFS
1835 carl9170_debugfs_unregister(ar
);
1836 #endif /* CONFIG_CARL9170_DEBUGFS */
1838 #ifdef CONFIG_CARL9170_WPC
1840 input_unregister_device(ar
->wps
.pbc
);
1843 #endif /* CONFIG_CARL9170_WPC */
1845 carl9170_cancel_worker(ar
);
1846 cancel_work_sync(&ar
->restart_work
);
1848 ieee80211_unregister_hw(ar
->hw
);
1851 void carl9170_free(struct ar9170
*ar
)
1853 WARN_ON(ar
->registered
);
1854 WARN_ON(IS_INITIALIZED(ar
));
1856 kfree_skb(ar
->rx_failover
);
1857 ar
->rx_failover
= NULL
;
1859 kfree(ar
->mem_bitmap
);
1860 ar
->mem_bitmap
= NULL
;
1862 mutex_destroy(&ar
->mutex
);
1864 ieee80211_free_hw(ar
->hw
);