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/slab.h>
41 #include <linux/module.h>
42 #include <linux/etherdevice.h>
43 #include <linux/random.h>
44 #include <net/mac80211.h>
45 #include <net/cfg80211.h>
50 static bool modparam_nohwcrypt
;
51 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, S_IRUGO
);
52 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware crypto offload.");
55 module_param_named(noht
, modparam_noht
, int, S_IRUGO
);
56 MODULE_PARM_DESC(noht
, "Disable MPDU aggregation.");
58 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
59 .bitrate = (_bitrate), \
61 .hw_value = (_hw_rate) | (_txpidx) << 4, \
64 struct ieee80211_rate __carl9170_ratetable
[] = {
66 RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE
),
67 RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE
),
68 RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE
),
80 #define carl9170_g_ratetable (__carl9170_ratetable + 0)
81 #define carl9170_g_ratetable_size 12
82 #define carl9170_a_ratetable (__carl9170_ratetable + 4)
83 #define carl9170_a_ratetable_size 8
86 * NB: The hw_value is used as an index into the carl9170_phy_freq_params
87 * array in phy.c so that we don't have to do frequency lookups!
89 #define CHAN(_freq, _idx) { \
90 .center_freq = (_freq), \
92 .max_power = 18, /* XXX */ \
95 static struct ieee80211_channel carl9170_2ghz_chantable
[] = {
112 static struct ieee80211_channel carl9170_5ghz_chantable
[] = {
151 #define CARL9170_HT_CAP \
153 .ht_supported = true, \
154 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
155 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
156 IEEE80211_HT_CAP_SGI_40 | \
157 IEEE80211_HT_CAP_DSSSCCK40 | \
158 IEEE80211_HT_CAP_SM_PS, \
159 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
160 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
162 .rx_mask = { 0xff, 0xff, 0, 0, 0x1, 0, 0, 0, 0, 0, }, \
163 .rx_highest = cpu_to_le16(300), \
164 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
168 static struct ieee80211_supported_band carl9170_band_2GHz
= {
169 .channels
= carl9170_2ghz_chantable
,
170 .n_channels
= ARRAY_SIZE(carl9170_2ghz_chantable
),
171 .bitrates
= carl9170_g_ratetable
,
172 .n_bitrates
= carl9170_g_ratetable_size
,
173 .ht_cap
= CARL9170_HT_CAP
,
176 static struct ieee80211_supported_band carl9170_band_5GHz
= {
177 .channels
= carl9170_5ghz_chantable
,
178 .n_channels
= ARRAY_SIZE(carl9170_5ghz_chantable
),
179 .bitrates
= carl9170_a_ratetable
,
180 .n_bitrates
= carl9170_a_ratetable_size
,
181 .ht_cap
= CARL9170_HT_CAP
,
184 static void carl9170_ampdu_gc(struct ar9170
*ar
)
186 struct carl9170_sta_tid
*tid_info
;
190 list_for_each_entry_rcu(tid_info
, &ar
->tx_ampdu_list
, list
) {
191 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
192 if (tid_info
->state
== CARL9170_TID_STATE_SHUTDOWN
) {
193 tid_info
->state
= CARL9170_TID_STATE_KILLED
;
194 list_del_rcu(&tid_info
->list
);
195 ar
->tx_ampdu_list_len
--;
196 list_add_tail(&tid_info
->tmp_list
, &tid_gc
);
198 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
201 rcu_assign_pointer(ar
->tx_ampdu_iter
, tid_info
);
206 while (!list_empty(&tid_gc
)) {
208 tid_info
= list_first_entry(&tid_gc
, struct carl9170_sta_tid
,
211 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
212 carl9170_tx_status(ar
, skb
, false);
214 list_del_init(&tid_info
->tmp_list
);
219 static void carl9170_flush(struct ar9170
*ar
, bool drop_queued
)
225 * We can only drop frames which have not been uploaded
229 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
232 while ((skb
= skb_dequeue(&ar
->tx_pending
[i
]))) {
233 struct ieee80211_tx_info
*info
;
235 info
= IEEE80211_SKB_CB(skb
);
236 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
237 atomic_dec(&ar
->tx_ampdu_upload
);
239 carl9170_tx_status(ar
, skb
, false);
244 /* Wait for all other outstanding frames to timeout. */
245 if (atomic_read(&ar
->tx_total_queued
))
246 WARN_ON(wait_for_completion_timeout(&ar
->tx_flush
, HZ
) == 0);
249 static void carl9170_flush_ba(struct ar9170
*ar
)
251 struct sk_buff_head free
;
252 struct carl9170_sta_tid
*tid_info
;
255 __skb_queue_head_init(&free
);
258 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
259 list_for_each_entry_rcu(tid_info
, &ar
->tx_ampdu_list
, list
) {
260 if (tid_info
->state
> CARL9170_TID_STATE_SUSPEND
) {
261 tid_info
->state
= CARL9170_TID_STATE_SUSPEND
;
263 spin_lock(&tid_info
->lock
);
264 while ((skb
= __skb_dequeue(&tid_info
->queue
)))
265 __skb_queue_tail(&free
, skb
);
266 spin_unlock(&tid_info
->lock
);
269 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
272 while ((skb
= __skb_dequeue(&free
)))
273 carl9170_tx_status(ar
, skb
, false);
276 static void carl9170_zap_queues(struct ar9170
*ar
)
278 struct carl9170_vif_info
*cvif
;
281 carl9170_ampdu_gc(ar
);
283 carl9170_flush_ba(ar
);
284 carl9170_flush(ar
, true);
286 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
287 spin_lock_bh(&ar
->tx_status
[i
].lock
);
288 while (!skb_queue_empty(&ar
->tx_status
[i
])) {
291 skb
= skb_peek(&ar
->tx_status
[i
]);
292 carl9170_tx_get_skb(skb
);
293 spin_unlock_bh(&ar
->tx_status
[i
].lock
);
294 carl9170_tx_drop(ar
, skb
);
295 spin_lock_bh(&ar
->tx_status
[i
].lock
);
296 carl9170_tx_put_skb(skb
);
298 spin_unlock_bh(&ar
->tx_status
[i
].lock
);
301 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_SOFT
< 1);
302 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_HARD
< CARL9170_NUM_TX_LIMIT_SOFT
);
303 BUILD_BUG_ON(CARL9170_NUM_TX_LIMIT_HARD
>= CARL9170_BAW_BITS
);
305 /* reinitialize queues statistics */
306 memset(&ar
->tx_stats
, 0, sizeof(ar
->tx_stats
));
307 for (i
= 0; i
< ar
->hw
->queues
; i
++)
308 ar
->tx_stats
[i
].limit
= CARL9170_NUM_TX_LIMIT_HARD
;
310 for (i
= 0; i
< DIV_ROUND_UP(ar
->fw
.mem_blocks
, BITS_PER_LONG
); i
++)
311 ar
->mem_bitmap
[i
] = 0;
314 list_for_each_entry_rcu(cvif
, &ar
->vif_list
, list
) {
315 spin_lock_bh(&ar
->beacon_lock
);
316 dev_kfree_skb_any(cvif
->beacon
);
318 spin_unlock_bh(&ar
->beacon_lock
);
322 atomic_set(&ar
->tx_ampdu_upload
, 0);
323 atomic_set(&ar
->tx_ampdu_scheduler
, 0);
324 atomic_set(&ar
->tx_total_pending
, 0);
325 atomic_set(&ar
->tx_total_queued
, 0);
326 atomic_set(&ar
->mem_free_blocks
, ar
->fw
.mem_blocks
);
329 #define CARL9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
331 queue.aifs = ai_fs; \
332 queue.cw_min = cwmin; \
333 queue.cw_max = cwmax; \
334 queue.txop = _txop; \
337 static int carl9170_op_start(struct ieee80211_hw
*hw
)
339 struct ar9170
*ar
= hw
->priv
;
342 mutex_lock(&ar
->mutex
);
344 carl9170_zap_queues(ar
);
346 /* reset QoS defaults */
347 CARL9170_FILL_QUEUE(ar
->edcf
[AR9170_TXQ_VO
], 2, 3, 7, 47);
348 CARL9170_FILL_QUEUE(ar
->edcf
[AR9170_TXQ_VI
], 2, 7, 15, 94);
349 CARL9170_FILL_QUEUE(ar
->edcf
[AR9170_TXQ_BE
], 3, 15, 1023, 0);
350 CARL9170_FILL_QUEUE(ar
->edcf
[AR9170_TXQ_BK
], 7, 15, 1023, 0);
351 CARL9170_FILL_QUEUE(ar
->edcf
[AR9170_TXQ_SPECIAL
], 2, 3, 7, 0);
353 ar
->current_factor
= ar
->current_density
= -1;
354 /* "The first key is unique." */
356 ar
->filter_state
= 0;
357 ar
->ps
.last_action
= jiffies
;
358 ar
->ps
.last_slept
= jiffies
;
359 ar
->erp_mode
= CARL9170_ERP_AUTO
;
361 /* Set "disable hw crypto offload" whenever the module parameter
362 * nohwcrypt is true or if the firmware does not support it.
364 ar
->disable_offload
= modparam_nohwcrypt
|
365 ar
->fw
.disable_offload_fw
;
366 ar
->rx_software_decryption
= ar
->disable_offload
;
368 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
369 ar
->queue_stop_timeout
[i
] = jiffies
;
370 ar
->max_queue_stop_timeout
[i
] = 0;
373 atomic_set(&ar
->mem_allocs
, 0);
375 err
= carl9170_usb_open(ar
);
379 err
= carl9170_init_mac(ar
);
383 err
= carl9170_set_qos(ar
);
387 if (ar
->fw
.rx_filter
) {
388 err
= carl9170_rx_filter(ar
, CARL9170_RX_FILTER_OTHER_RA
|
389 CARL9170_RX_FILTER_CTL_OTHER
| CARL9170_RX_FILTER_BAD
);
394 err
= carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
,
395 AR9170_DMA_TRIGGER_RXQ
);
399 /* Clear key-cache */
400 for (i
= 0; i
< AR9170_CAM_MAX_USER
+ 4; i
++) {
401 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
406 err
= carl9170_upload_key(ar
, i
, NULL
, AR9170_ENC_ALG_NONE
,
411 if (i
< AR9170_CAM_MAX_USER
) {
412 err
= carl9170_disable_key(ar
, i
);
418 carl9170_set_state_when(ar
, CARL9170_IDLE
, CARL9170_STARTED
);
420 ieee80211_queue_delayed_work(ar
->hw
, &ar
->stat_work
,
421 round_jiffies(msecs_to_jiffies(CARL9170_STAT_WORK
)));
423 ieee80211_wake_queues(ar
->hw
);
427 mutex_unlock(&ar
->mutex
);
431 static void carl9170_cancel_worker(struct ar9170
*ar
)
433 cancel_delayed_work_sync(&ar
->stat_work
);
434 cancel_delayed_work_sync(&ar
->tx_janitor
);
435 #ifdef CONFIG_CARL9170_LEDS
436 cancel_delayed_work_sync(&ar
->led_work
);
437 #endif /* CONFIG_CARL9170_LEDS */
438 cancel_work_sync(&ar
->ps_work
);
439 cancel_work_sync(&ar
->ping_work
);
440 cancel_work_sync(&ar
->ampdu_work
);
443 static void carl9170_op_stop(struct ieee80211_hw
*hw
)
445 struct ar9170
*ar
= hw
->priv
;
447 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
449 ieee80211_stop_queues(ar
->hw
);
451 mutex_lock(&ar
->mutex
);
452 if (IS_ACCEPTING_CMD(ar
)) {
453 RCU_INIT_POINTER(ar
->beacon_iter
, NULL
);
455 carl9170_led_set_state(ar
, 0);
458 carl9170_write_reg(ar
, AR9170_MAC_REG_DMA_TRIGGER
, 0);
459 carl9170_usb_stop(ar
);
462 carl9170_zap_queues(ar
);
463 mutex_unlock(&ar
->mutex
);
465 carl9170_cancel_worker(ar
);
468 static void carl9170_restart_work(struct work_struct
*work
)
470 struct ar9170
*ar
= container_of(work
, struct ar9170
,
475 ar
->filter_state
= 0;
476 carl9170_cancel_worker(ar
);
478 mutex_lock(&ar
->mutex
);
479 if (!ar
->force_usb_reset
) {
480 err
= carl9170_usb_restart(ar
);
481 if (net_ratelimit()) {
483 dev_err(&ar
->udev
->dev
, "Failed to restart device (%d).\n", err
);
485 dev_info(&ar
->udev
->dev
, "device restarted successfully.\n");
488 carl9170_zap_queues(ar
);
489 mutex_unlock(&ar
->mutex
);
491 if (!err
&& !ar
->force_usb_reset
) {
492 ar
->restart_counter
++;
493 atomic_set(&ar
->pending_restarts
, 0);
495 ieee80211_restart_hw(ar
->hw
);
498 * The reset was unsuccessful and the device seems to
499 * be dead. But there's still one option: a low-level
500 * usb subsystem reset...
503 carl9170_usb_reset(ar
);
507 void carl9170_restart(struct ar9170
*ar
, const enum carl9170_restart_reasons r
)
509 carl9170_set_state_when(ar
, CARL9170_STARTED
, CARL9170_IDLE
);
512 * Sometimes, an error can trigger several different reset events.
513 * By ignoring these *surplus* reset events, the device won't be
514 * killed again, right after it has recovered.
516 if (atomic_inc_return(&ar
->pending_restarts
) > 1) {
517 dev_dbg(&ar
->udev
->dev
, "ignoring restart (%d)\n", r
);
521 ieee80211_stop_queues(ar
->hw
);
523 dev_err(&ar
->udev
->dev
, "restart device (%d)\n", r
);
525 if (!WARN_ON(r
== CARL9170_RR_NO_REASON
) ||
526 !WARN_ON(r
>= __CARL9170_RR_LAST
))
532 if (!IS_ACCEPTING_CMD(ar
) || ar
->needs_full_reset
)
533 ar
->force_usb_reset
= true;
535 ieee80211_queue_work(ar
->hw
, &ar
->restart_work
);
538 * At this point, the device instance might have vanished/disabled.
539 * So, don't put any code which access the ar9170 struct
540 * without proper protection.
544 static void carl9170_ping_work(struct work_struct
*work
)
546 struct ar9170
*ar
= container_of(work
, struct ar9170
, ping_work
);
552 mutex_lock(&ar
->mutex
);
553 err
= carl9170_echo_test(ar
, 0xdeadbeef);
555 carl9170_restart(ar
, CARL9170_RR_UNRESPONSIVE_DEVICE
);
556 mutex_unlock(&ar
->mutex
);
559 static int carl9170_init_interface(struct ar9170
*ar
,
560 struct ieee80211_vif
*vif
)
562 struct ath_common
*common
= &ar
->common
;
566 WARN_ON_ONCE(IS_STARTED(ar
));
570 memcpy(common
->macaddr
, vif
->addr
, ETH_ALEN
);
572 /* We have to fall back to software crypto, whenever
573 * the user choose to participates in an IBSS. HW
574 * offload for IBSS RSN is not supported by this driver.
576 * NOTE: If the previous main interface has already
577 * disabled hw crypto offload, we have to keep this
578 * previous disable_offload setting as it was.
579 * Altough ideally, we should notify mac80211 and tell
580 * it to forget about any HW crypto offload for now.
582 ar
->disable_offload
|= ((vif
->type
!= NL80211_IFTYPE_STATION
) &&
583 (vif
->type
!= NL80211_IFTYPE_AP
));
585 /* While the driver supports HW offload in a single
586 * P2P client configuration, it doesn't support HW
587 * offload in the favourit, concurrent P2P GO+CLIENT
588 * configuration. Hence, HW offload will always be
591 ar
->disable_offload
|= vif
->p2p
;
593 ar
->rx_software_decryption
= ar
->disable_offload
;
595 err
= carl9170_set_operating_mode(ar
);
599 static int carl9170_op_add_interface(struct ieee80211_hw
*hw
,
600 struct ieee80211_vif
*vif
)
602 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
603 struct ieee80211_vif
*main_vif
, *old_main
= NULL
;
604 struct ar9170
*ar
= hw
->priv
;
605 int vif_id
= -1, err
= 0;
607 mutex_lock(&ar
->mutex
);
609 if (vif_priv
->active
) {
611 * Skip the interface structure initialization,
612 * if the vif survived the _restart call.
614 vif_id
= vif_priv
->id
;
615 vif_priv
->enable_beacon
= false;
617 spin_lock_bh(&ar
->beacon_lock
);
618 dev_kfree_skb_any(vif_priv
->beacon
);
619 vif_priv
->beacon
= NULL
;
620 spin_unlock_bh(&ar
->beacon_lock
);
625 /* Because the AR9170 HW's MAC doesn't provide full support for
626 * multiple, independent interfaces [of different operation modes].
627 * We have to select ONE main interface [main mode of HW], but we
628 * can have multiple slaves [AKA: entry in the ACK-table].
630 * The first (from HEAD/TOP) interface in the ar->vif_list is
631 * always the main intf. All following intfs in this list
632 * are considered to be slave intfs.
634 main_vif
= carl9170_get_main_vif(ar
);
637 switch (main_vif
->type
) {
638 case NL80211_IFTYPE_STATION
:
639 if (vif
->type
== NL80211_IFTYPE_STATION
)
642 /* P2P GO [master] use-case
643 * Because the P2P GO station is selected dynamically
644 * by all participating peers of a WIFI Direct network,
645 * the driver has be able to change the main interface
646 * operating mode on the fly.
648 if (main_vif
->p2p
&& vif
->p2p
&&
649 vif
->type
== NL80211_IFTYPE_AP
) {
659 case NL80211_IFTYPE_MESH_POINT
:
660 case NL80211_IFTYPE_AP
:
661 if ((vif
->type
== NL80211_IFTYPE_STATION
) ||
662 (vif
->type
== NL80211_IFTYPE_WDS
) ||
663 (vif
->type
== NL80211_IFTYPE_AP
) ||
664 (vif
->type
== NL80211_IFTYPE_MESH_POINT
))
677 vif_id
= bitmap_find_free_region(&ar
->vif_bitmap
, ar
->fw
.vif_num
, 0);
686 BUG_ON(ar
->vif_priv
[vif_id
].id
!= vif_id
);
688 vif_priv
->active
= true;
689 vif_priv
->id
= vif_id
;
690 vif_priv
->enable_beacon
= false;
693 /* We end up in here, if the main interface is being replaced.
694 * Put the new main interface at the HEAD of the list and the
695 * previous inteface will automatically become second in line.
697 list_add_rcu(&vif_priv
->list
, &ar
->vif_list
);
699 /* Add new inteface. If the list is empty, it will become the
700 * main inteface, otherwise it will be slave.
702 list_add_tail_rcu(&vif_priv
->list
, &ar
->vif_list
);
704 rcu_assign_pointer(ar
->vif_priv
[vif_id
].vif
, vif
);
707 main_vif
= carl9170_get_main_vif(ar
);
709 if (main_vif
== vif
) {
710 rcu_assign_pointer(ar
->beacon_iter
, vif_priv
);
714 struct carl9170_vif_info
*old_main_priv
=
715 (void *) old_main
->drv_priv
;
716 /* downgrade old main intf to slave intf.
717 * NOTE: We are no longer under rcu_read_lock.
718 * But we are still holding ar->mutex, so the
719 * vif data [id, addr] is safe.
721 err
= carl9170_mod_virtual_mac(ar
, old_main_priv
->id
,
727 err
= carl9170_init_interface(ar
, vif
);
732 err
= carl9170_mod_virtual_mac(ar
, vif_id
, vif
->addr
);
738 if (ar
->fw
.tx_seq_table
) {
739 err
= carl9170_write_reg(ar
, ar
->fw
.tx_seq_table
+ vif_id
* 4,
746 if (err
&& (vif_id
>= 0)) {
747 vif_priv
->active
= false;
748 bitmap_release_region(&ar
->vif_bitmap
, vif_id
, 0);
750 RCU_INIT_POINTER(ar
->vif_priv
[vif_id
].vif
, NULL
);
751 list_del_rcu(&vif_priv
->list
);
752 mutex_unlock(&ar
->mutex
);
756 ar
->ps
.off_override
|= PS_OFF_VIF
;
758 mutex_unlock(&ar
->mutex
);
764 static void carl9170_op_remove_interface(struct ieee80211_hw
*hw
,
765 struct ieee80211_vif
*vif
)
767 struct carl9170_vif_info
*vif_priv
= (void *) vif
->drv_priv
;
768 struct ieee80211_vif
*main_vif
;
769 struct ar9170
*ar
= hw
->priv
;
772 mutex_lock(&ar
->mutex
);
774 if (WARN_ON_ONCE(!vif_priv
->active
))
780 main_vif
= carl9170_get_main_vif(ar
);
784 vif_priv
->active
= false;
785 WARN_ON(vif_priv
->enable_beacon
);
786 vif_priv
->enable_beacon
= false;
787 list_del_rcu(&vif_priv
->list
);
788 RCU_INIT_POINTER(ar
->vif_priv
[id
].vif
, NULL
);
790 if (vif
== main_vif
) {
794 WARN_ON(carl9170_init_interface(ar
,
795 carl9170_get_main_vif(ar
)));
797 carl9170_set_operating_mode(ar
);
802 WARN_ON(carl9170_mod_virtual_mac(ar
, id
, NULL
));
805 carl9170_update_beacon(ar
, false);
806 carl9170_flush_cab(ar
, id
);
808 spin_lock_bh(&ar
->beacon_lock
);
809 dev_kfree_skb_any(vif_priv
->beacon
);
810 vif_priv
->beacon
= NULL
;
811 spin_unlock_bh(&ar
->beacon_lock
);
813 bitmap_release_region(&ar
->vif_bitmap
, id
, 0);
815 carl9170_set_beacon_timers(ar
);
818 ar
->ps
.off_override
&= ~PS_OFF_VIF
;
821 mutex_unlock(&ar
->mutex
);
826 void carl9170_ps_check(struct ar9170
*ar
)
828 ieee80211_queue_work(ar
->hw
, &ar
->ps_work
);
831 /* caller must hold ar->mutex */
832 static int carl9170_ps_update(struct ar9170
*ar
)
837 if (!ar
->ps
.off_override
)
838 ps
= (ar
->hw
->conf
.flags
& IEEE80211_CONF_PS
);
840 if (ps
!= ar
->ps
.state
) {
841 err
= carl9170_powersave(ar
, ps
);
845 if (ar
->ps
.state
&& !ps
) {
846 ar
->ps
.sleep_ms
= jiffies_to_msecs(jiffies
-
851 ar
->ps
.last_slept
= jiffies
;
853 ar
->ps
.last_action
= jiffies
;
860 static void carl9170_ps_work(struct work_struct
*work
)
862 struct ar9170
*ar
= container_of(work
, struct ar9170
,
864 mutex_lock(&ar
->mutex
);
866 WARN_ON_ONCE(carl9170_ps_update(ar
) != 0);
867 mutex_unlock(&ar
->mutex
);
870 static int carl9170_update_survey(struct ar9170
*ar
, bool flush
, bool noise
)
875 err
= carl9170_get_noisefloor(ar
);
880 if (ar
->fw
.hw_counters
) {
881 err
= carl9170_collect_tally(ar
);
887 memset(&ar
->tally
, 0, sizeof(ar
->tally
));
892 static void carl9170_stat_work(struct work_struct
*work
)
894 struct ar9170
*ar
= container_of(work
, struct ar9170
, stat_work
.work
);
897 mutex_lock(&ar
->mutex
);
898 err
= carl9170_update_survey(ar
, false, true);
899 mutex_unlock(&ar
->mutex
);
904 ieee80211_queue_delayed_work(ar
->hw
, &ar
->stat_work
,
905 round_jiffies(msecs_to_jiffies(CARL9170_STAT_WORK
)));
908 static int carl9170_op_config(struct ieee80211_hw
*hw
, u32 changed
)
910 struct ar9170
*ar
= hw
->priv
;
913 mutex_lock(&ar
->mutex
);
914 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
919 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
920 err
= carl9170_ps_update(ar
);
925 if (changed
& IEEE80211_CONF_CHANGE_SMPS
) {
930 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
931 enum nl80211_channel_type channel_type
=
932 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
934 /* adjust slot time for 5 GHz */
935 err
= carl9170_set_slot_time(ar
);
939 err
= carl9170_update_survey(ar
, true, false);
943 err
= carl9170_set_channel(ar
, hw
->conf
.chandef
.chan
,
948 err
= carl9170_update_survey(ar
, false, true);
952 err
= carl9170_set_dyn_sifs_ack(ar
);
956 err
= carl9170_set_rts_cts_rate(ar
);
961 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
962 err
= carl9170_set_mac_tpc(ar
, ar
->hw
->conf
.chandef
.chan
);
968 mutex_unlock(&ar
->mutex
);
972 static u64
carl9170_op_prepare_multicast(struct ieee80211_hw
*hw
,
973 struct netdev_hw_addr_list
*mc_list
)
975 struct netdev_hw_addr
*ha
;
978 /* always get broadcast frames */
979 mchash
= 1ULL << (0xff >> 2);
981 netdev_hw_addr_list_for_each(ha
, mc_list
)
982 mchash
|= 1ULL << (ha
->addr
[5] >> 2);
987 static void carl9170_op_configure_filter(struct ieee80211_hw
*hw
,
988 unsigned int changed_flags
,
989 unsigned int *new_flags
,
992 struct ar9170
*ar
= hw
->priv
;
994 /* mask supported flags */
995 *new_flags
&= FIF_ALLMULTI
| ar
->rx_filter_caps
;
997 if (!IS_ACCEPTING_CMD(ar
))
1000 mutex_lock(&ar
->mutex
);
1002 ar
->filter_state
= *new_flags
;
1004 * We can support more by setting the sniffer bit and
1005 * then checking the error flags, later.
1008 if (*new_flags
& FIF_ALLMULTI
)
1011 if (multicast
!= ar
->cur_mc_hash
)
1012 WARN_ON(carl9170_update_multicast(ar
, multicast
));
1014 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
1015 ar
->sniffer_enabled
= !!(*new_flags
&
1016 (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
));
1018 WARN_ON(carl9170_set_operating_mode(ar
));
1021 if (ar
->fw
.rx_filter
&& changed_flags
& ar
->rx_filter_caps
) {
1024 if (!ar
->fw
.ba_filter
)
1025 rx_filter
|= CARL9170_RX_FILTER_CTL_OTHER
;
1027 if (!(*new_flags
& (FIF_FCSFAIL
| FIF_PLCPFAIL
)))
1028 rx_filter
|= CARL9170_RX_FILTER_BAD
;
1030 if (!(*new_flags
& FIF_CONTROL
))
1031 rx_filter
|= CARL9170_RX_FILTER_CTL_OTHER
;
1033 if (!(*new_flags
& FIF_PSPOLL
))
1034 rx_filter
|= CARL9170_RX_FILTER_CTL_PSPOLL
;
1036 if (!(*new_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
))) {
1037 rx_filter
|= CARL9170_RX_FILTER_OTHER_RA
;
1038 rx_filter
|= CARL9170_RX_FILTER_DECRY_FAIL
;
1041 WARN_ON(carl9170_rx_filter(ar
, rx_filter
));
1044 mutex_unlock(&ar
->mutex
);
1048 static void carl9170_op_bss_info_changed(struct ieee80211_hw
*hw
,
1049 struct ieee80211_vif
*vif
,
1050 struct ieee80211_bss_conf
*bss_conf
,
1053 struct ar9170
*ar
= hw
->priv
;
1054 struct ath_common
*common
= &ar
->common
;
1056 struct carl9170_vif_info
*vif_priv
;
1057 struct ieee80211_vif
*main_vif
;
1059 mutex_lock(&ar
->mutex
);
1060 vif_priv
= (void *) vif
->drv_priv
;
1061 main_vif
= carl9170_get_main_vif(ar
);
1062 if (WARN_ON(!main_vif
))
1065 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
1066 struct carl9170_vif_info
*iter
;
1069 vif_priv
->enable_beacon
= bss_conf
->enable_beacon
;
1071 list_for_each_entry_rcu(iter
, &ar
->vif_list
, list
) {
1072 if (iter
->active
&& iter
->enable_beacon
)
1078 ar
->beacon_enabled
= i
;
1081 if (changed
& BSS_CHANGED_BEACON
) {
1082 err
= carl9170_update_beacon(ar
, false);
1087 if (changed
& (BSS_CHANGED_BEACON_ENABLED
| BSS_CHANGED_BEACON
|
1088 BSS_CHANGED_BEACON_INT
)) {
1090 if (main_vif
!= vif
) {
1091 bss_conf
->beacon_int
= main_vif
->bss_conf
.beacon_int
;
1092 bss_conf
->dtim_period
= main_vif
->bss_conf
.dtim_period
;
1096 * Therefore a hard limit for the broadcast traffic should
1097 * prevent false alarms.
1099 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
1100 (bss_conf
->beacon_int
* bss_conf
->dtim_period
>=
1101 (CARL9170_QUEUE_STUCK_TIMEOUT
/ 2))) {
1106 err
= carl9170_set_beacon_timers(ar
);
1111 if (changed
& BSS_CHANGED_HT
) {
1118 if (main_vif
!= vif
)
1122 * The following settings can only be changed by the
1126 if (changed
& BSS_CHANGED_BSSID
) {
1127 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1128 err
= carl9170_set_operating_mode(ar
);
1133 if (changed
& BSS_CHANGED_ASSOC
) {
1134 ar
->common
.curaid
= bss_conf
->aid
;
1135 err
= carl9170_set_beacon_timers(ar
);
1140 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1141 err
= carl9170_set_slot_time(ar
);
1146 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1147 err
= carl9170_set_mac_rates(ar
);
1153 WARN_ON_ONCE(err
&& IS_STARTED(ar
));
1154 mutex_unlock(&ar
->mutex
);
1157 static u64
carl9170_op_get_tsf(struct ieee80211_hw
*hw
,
1158 struct ieee80211_vif
*vif
)
1160 struct ar9170
*ar
= hw
->priv
;
1161 struct carl9170_tsf_rsp tsf
;
1164 mutex_lock(&ar
->mutex
);
1165 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_READ_TSF
,
1166 0, NULL
, sizeof(tsf
), &tsf
);
1167 mutex_unlock(&ar
->mutex
);
1171 return le64_to_cpu(tsf
.tsf_64
);
1174 static int carl9170_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1175 struct ieee80211_vif
*vif
,
1176 struct ieee80211_sta
*sta
,
1177 struct ieee80211_key_conf
*key
)
1179 struct ar9170
*ar
= hw
->priv
;
1183 if (ar
->disable_offload
|| !vif
)
1186 /* Fall back to software encryption whenever the driver is connected
1187 * to more than one network.
1189 * This is very unfortunate, because some machines cannot handle
1190 * the high througput speed in 802.11n networks.
1193 if (!is_main_vif(ar
, vif
)) {
1194 mutex_lock(&ar
->mutex
);
1199 * While the hardware supports *catch-all* key, for offloading
1200 * group-key en-/de-cryption. The way of how the hardware
1201 * decides which keyId maps to which key, remains a mystery...
1203 if ((vif
->type
!= NL80211_IFTYPE_STATION
&&
1204 vif
->type
!= NL80211_IFTYPE_ADHOC
) &&
1205 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1208 switch (key
->cipher
) {
1209 case WLAN_CIPHER_SUITE_WEP40
:
1210 ktype
= AR9170_ENC_ALG_WEP64
;
1212 case WLAN_CIPHER_SUITE_WEP104
:
1213 ktype
= AR9170_ENC_ALG_WEP128
;
1215 case WLAN_CIPHER_SUITE_TKIP
:
1216 ktype
= AR9170_ENC_ALG_TKIP
;
1218 case WLAN_CIPHER_SUITE_CCMP
:
1219 ktype
= AR9170_ENC_ALG_AESCCMP
;
1220 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1226 mutex_lock(&ar
->mutex
);
1227 if (cmd
== SET_KEY
) {
1228 if (!IS_STARTED(ar
)) {
1233 if (!(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1236 i
= 64 + key
->keyidx
;
1238 for (i
= 0; i
< 64; i
++)
1239 if (!(ar
->usedkeys
& BIT(i
)))
1245 key
->hw_key_idx
= i
;
1247 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
: NULL
,
1249 min_t(u8
, 16, key
->keylen
));
1253 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1254 err
= carl9170_upload_key(ar
, i
, sta
? sta
->addr
:
1261 * hardware is not capable generating MMIC
1262 * of fragmented frames!
1264 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1268 ar
->usedkeys
|= BIT(i
);
1270 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1272 if (!IS_STARTED(ar
)) {
1273 /* The device is gone... together with the key ;-) */
1278 if (key
->hw_key_idx
< 64) {
1279 ar
->usedkeys
&= ~BIT(key
->hw_key_idx
);
1281 err
= carl9170_upload_key(ar
, key
->hw_key_idx
, NULL
,
1282 AR9170_ENC_ALG_NONE
, 0,
1287 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1288 err
= carl9170_upload_key(ar
, key
->hw_key_idx
,
1290 AR9170_ENC_ALG_NONE
,
1298 err
= carl9170_disable_key(ar
, key
->hw_key_idx
);
1304 mutex_unlock(&ar
->mutex
);
1308 if (!ar
->rx_software_decryption
) {
1309 ar
->rx_software_decryption
= true;
1310 carl9170_set_operating_mode(ar
);
1312 mutex_unlock(&ar
->mutex
);
1316 static int carl9170_op_sta_add(struct ieee80211_hw
*hw
,
1317 struct ieee80211_vif
*vif
,
1318 struct ieee80211_sta
*sta
)
1320 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1323 atomic_set(&sta_info
->pending_frames
, 0);
1325 if (sta
->ht_cap
.ht_supported
) {
1326 if (sta
->ht_cap
.ampdu_density
> 6) {
1328 * HW does support 16us AMPDU density.
1329 * No HT-Xmit for station.
1335 for (i
= 0; i
< ARRAY_SIZE(sta_info
->agg
); i
++)
1336 RCU_INIT_POINTER(sta_info
->agg
[i
], NULL
);
1338 sta_info
->ampdu_max_len
= 1 << (3 + sta
->ht_cap
.ampdu_factor
);
1339 sta_info
->ht_sta
= true;
1345 static int carl9170_op_sta_remove(struct ieee80211_hw
*hw
,
1346 struct ieee80211_vif
*vif
,
1347 struct ieee80211_sta
*sta
)
1349 struct ar9170
*ar
= hw
->priv
;
1350 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1352 bool cleanup
= false;
1354 if (sta
->ht_cap
.ht_supported
) {
1356 sta_info
->ht_sta
= false;
1359 for (i
= 0; i
< ARRAY_SIZE(sta_info
->agg
); i
++) {
1360 struct carl9170_sta_tid
*tid_info
;
1362 tid_info
= rcu_dereference(sta_info
->agg
[i
]);
1363 RCU_INIT_POINTER(sta_info
->agg
[i
], NULL
);
1368 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1369 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1370 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1371 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1377 carl9170_ampdu_gc(ar
);
1383 static int carl9170_op_conf_tx(struct ieee80211_hw
*hw
,
1384 struct ieee80211_vif
*vif
, u16 queue
,
1385 const struct ieee80211_tx_queue_params
*param
)
1387 struct ar9170
*ar
= hw
->priv
;
1390 mutex_lock(&ar
->mutex
);
1391 if (queue
< ar
->hw
->queues
) {
1392 memcpy(&ar
->edcf
[ar9170_qmap
[queue
]], param
, sizeof(*param
));
1393 ret
= carl9170_set_qos(ar
);
1398 mutex_unlock(&ar
->mutex
);
1402 static void carl9170_ampdu_work(struct work_struct
*work
)
1404 struct ar9170
*ar
= container_of(work
, struct ar9170
,
1407 if (!IS_STARTED(ar
))
1410 mutex_lock(&ar
->mutex
);
1411 carl9170_ampdu_gc(ar
);
1412 mutex_unlock(&ar
->mutex
);
1415 static int carl9170_op_ampdu_action(struct ieee80211_hw
*hw
,
1416 struct ieee80211_vif
*vif
,
1417 enum ieee80211_ampdu_mlme_action action
,
1418 struct ieee80211_sta
*sta
,
1419 u16 tid
, u16
*ssn
, u8 buf_size
)
1421 struct ar9170
*ar
= hw
->priv
;
1422 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1423 struct carl9170_sta_tid
*tid_info
;
1429 case IEEE80211_AMPDU_TX_START
:
1430 if (!sta_info
->ht_sta
)
1434 if (rcu_dereference(sta_info
->agg
[tid
])) {
1439 tid_info
= kzalloc(sizeof(struct carl9170_sta_tid
),
1446 tid_info
->hsn
= tid_info
->bsn
= tid_info
->snx
= (*ssn
);
1447 tid_info
->state
= CARL9170_TID_STATE_PROGRESS
;
1448 tid_info
->tid
= tid
;
1449 tid_info
->max
= sta_info
->ampdu_max_len
;
1450 tid_info
->sta
= sta
;
1451 tid_info
->vif
= vif
;
1453 INIT_LIST_HEAD(&tid_info
->list
);
1454 INIT_LIST_HEAD(&tid_info
->tmp_list
);
1455 skb_queue_head_init(&tid_info
->queue
);
1456 spin_lock_init(&tid_info
->lock
);
1458 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1459 ar
->tx_ampdu_list_len
++;
1460 list_add_tail_rcu(&tid_info
->list
, &ar
->tx_ampdu_list
);
1461 rcu_assign_pointer(sta_info
->agg
[tid
], tid_info
);
1462 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1465 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1468 case IEEE80211_AMPDU_TX_STOP_CONT
:
1469 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1470 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1472 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1474 spin_lock_bh(&ar
->tx_ampdu_list_lock
);
1475 if (tid_info
->state
> CARL9170_TID_STATE_SHUTDOWN
)
1476 tid_info
->state
= CARL9170_TID_STATE_SHUTDOWN
;
1477 spin_unlock_bh(&ar
->tx_ampdu_list_lock
);
1480 RCU_INIT_POINTER(sta_info
->agg
[tid
], NULL
);
1483 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1484 ieee80211_queue_work(ar
->hw
, &ar
->ampdu_work
);
1487 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1489 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
1491 sta_info
->stats
[tid
].clear
= true;
1492 sta_info
->stats
[tid
].req
= false;
1495 bitmap_zero(tid_info
->bitmap
, CARL9170_BAW_SIZE
);
1496 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1500 if (WARN_ON_ONCE(!tid_info
))
1505 case IEEE80211_AMPDU_RX_START
:
1506 case IEEE80211_AMPDU_RX_STOP
:
1507 /* Handled by hardware */
1517 #ifdef CONFIG_CARL9170_WPC
1518 static int carl9170_register_wps_button(struct ar9170
*ar
)
1520 struct input_dev
*input
;
1523 if (!(ar
->features
& CARL9170_WPS_BUTTON
))
1526 input
= input_allocate_device();
1530 snprintf(ar
->wps
.name
, sizeof(ar
->wps
.name
), "%s WPS Button",
1531 wiphy_name(ar
->hw
->wiphy
));
1533 snprintf(ar
->wps
.phys
, sizeof(ar
->wps
.phys
),
1534 "ieee80211/%s/input0", wiphy_name(ar
->hw
->wiphy
));
1536 input
->name
= ar
->wps
.name
;
1537 input
->phys
= ar
->wps
.phys
;
1538 input
->id
.bustype
= BUS_USB
;
1539 input
->dev
.parent
= &ar
->hw
->wiphy
->dev
;
1541 input_set_capability(input
, EV_KEY
, KEY_WPS_BUTTON
);
1543 err
= input_register_device(input
);
1545 input_free_device(input
);
1549 ar
->wps
.pbc
= input
;
1552 #endif /* CONFIG_CARL9170_WPC */
1554 #ifdef CONFIG_CARL9170_HWRNG
1555 static int carl9170_rng_get(struct ar9170
*ar
)
1558 #define RW (CARL9170_MAX_CMD_PAYLOAD_LEN / sizeof(u32))
1559 #define RB (CARL9170_MAX_CMD_PAYLOAD_LEN)
1561 static const __le32 rng_load
[RW
] = {
1562 [0 ... (RW
- 1)] = cpu_to_le32(AR9170_RAND_REG_NUM
)};
1566 unsigned int i
, off
= 0, transfer
, count
;
1569 BUILD_BUG_ON(RB
> CARL9170_MAX_CMD_PAYLOAD_LEN
);
1571 if (!IS_ACCEPTING_CMD(ar
) || !ar
->rng
.initialized
)
1574 count
= ARRAY_SIZE(ar
->rng
.cache
);
1576 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_RREG
,
1577 RB
, (u8
*) rng_load
,
1582 transfer
= min_t(unsigned int, count
, RW
);
1583 for (i
= 0; i
< transfer
; i
++)
1584 ar
->rng
.cache
[off
+ i
] = buf
[i
];
1590 ar
->rng
.cache_idx
= 0;
1597 static int carl9170_rng_read(struct hwrng
*rng
, u32
*data
)
1599 struct ar9170
*ar
= (struct ar9170
*)rng
->priv
;
1602 mutex_lock(&ar
->mutex
);
1603 if (ar
->rng
.cache_idx
>= ARRAY_SIZE(ar
->rng
.cache
)) {
1604 ret
= carl9170_rng_get(ar
);
1606 mutex_unlock(&ar
->mutex
);
1611 *data
= ar
->rng
.cache
[ar
->rng
.cache_idx
++];
1612 mutex_unlock(&ar
->mutex
);
1617 static void carl9170_unregister_hwrng(struct ar9170
*ar
)
1619 if (ar
->rng
.initialized
) {
1620 hwrng_unregister(&ar
->rng
.rng
);
1621 ar
->rng
.initialized
= false;
1625 static int carl9170_register_hwrng(struct ar9170
*ar
)
1629 snprintf(ar
->rng
.name
, ARRAY_SIZE(ar
->rng
.name
),
1630 "%s_%s", KBUILD_MODNAME
, wiphy_name(ar
->hw
->wiphy
));
1631 ar
->rng
.rng
.name
= ar
->rng
.name
;
1632 ar
->rng
.rng
.data_read
= carl9170_rng_read
;
1633 ar
->rng
.rng
.priv
= (unsigned long)ar
;
1635 if (WARN_ON(ar
->rng
.initialized
))
1638 err
= hwrng_register(&ar
->rng
.rng
);
1640 dev_err(&ar
->udev
->dev
, "Failed to register the random "
1641 "number generator (%d)\n", err
);
1645 ar
->rng
.initialized
= true;
1647 err
= carl9170_rng_get(ar
);
1649 carl9170_unregister_hwrng(ar
);
1655 #endif /* CONFIG_CARL9170_HWRNG */
1657 static int carl9170_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
1658 struct survey_info
*survey
)
1660 struct ar9170
*ar
= hw
->priv
;
1661 struct ieee80211_channel
*chan
;
1662 struct ieee80211_supported_band
*band
;
1669 if (idx
== chan
->hw_value
) {
1670 mutex_lock(&ar
->mutex
);
1671 err
= carl9170_update_survey(ar
, false, true);
1672 mutex_unlock(&ar
->mutex
);
1677 for (b
= 0; b
< IEEE80211_NUM_BANDS
; b
++) {
1678 band
= ar
->hw
->wiphy
->bands
[b
];
1683 for (i
= 0; i
< band
->n_channels
; i
++) {
1684 if (band
->channels
[i
].hw_value
== idx
) {
1685 chan
= &band
->channels
[i
];
1693 memcpy(survey
, &ar
->survey
[idx
], sizeof(*survey
));
1695 survey
->channel
= chan
;
1696 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1698 if (ar
->channel
== chan
)
1699 survey
->filled
|= SURVEY_INFO_IN_USE
;
1701 if (ar
->fw
.hw_counters
) {
1702 survey
->filled
|= SURVEY_INFO_CHANNEL_TIME
|
1703 SURVEY_INFO_CHANNEL_TIME_BUSY
|
1704 SURVEY_INFO_CHANNEL_TIME_TX
;
1710 static void carl9170_op_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
1712 struct ar9170
*ar
= hw
->priv
;
1715 mutex_lock(&ar
->mutex
);
1716 for_each_set_bit(vid
, &ar
->vif_bitmap
, ar
->fw
.vif_num
)
1717 carl9170_flush_cab(ar
, vid
);
1719 carl9170_flush(ar
, drop
);
1720 mutex_unlock(&ar
->mutex
);
1723 static int carl9170_op_get_stats(struct ieee80211_hw
*hw
,
1724 struct ieee80211_low_level_stats
*stats
)
1726 struct ar9170
*ar
= hw
->priv
;
1728 memset(stats
, 0, sizeof(*stats
));
1729 stats
->dot11ACKFailureCount
= ar
->tx_ack_failures
;
1730 stats
->dot11FCSErrorCount
= ar
->tx_fcs_errors
;
1734 static void carl9170_op_sta_notify(struct ieee80211_hw
*hw
,
1735 struct ieee80211_vif
*vif
,
1736 enum sta_notify_cmd cmd
,
1737 struct ieee80211_sta
*sta
)
1739 struct carl9170_sta_info
*sta_info
= (void *) sta
->drv_priv
;
1742 case STA_NOTIFY_SLEEP
:
1743 sta_info
->sleeping
= true;
1744 if (atomic_read(&sta_info
->pending_frames
))
1745 ieee80211_sta_block_awake(hw
, sta
, true);
1748 case STA_NOTIFY_AWAKE
:
1749 sta_info
->sleeping
= false;
1754 static bool carl9170_tx_frames_pending(struct ieee80211_hw
*hw
)
1756 struct ar9170
*ar
= hw
->priv
;
1758 return !!atomic_read(&ar
->tx_total_queued
);
1761 static const struct ieee80211_ops carl9170_ops
= {
1762 .start
= carl9170_op_start
,
1763 .stop
= carl9170_op_stop
,
1764 .tx
= carl9170_op_tx
,
1765 .flush
= carl9170_op_flush
,
1766 .add_interface
= carl9170_op_add_interface
,
1767 .remove_interface
= carl9170_op_remove_interface
,
1768 .config
= carl9170_op_config
,
1769 .prepare_multicast
= carl9170_op_prepare_multicast
,
1770 .configure_filter
= carl9170_op_configure_filter
,
1771 .conf_tx
= carl9170_op_conf_tx
,
1772 .bss_info_changed
= carl9170_op_bss_info_changed
,
1773 .get_tsf
= carl9170_op_get_tsf
,
1774 .set_key
= carl9170_op_set_key
,
1775 .sta_add
= carl9170_op_sta_add
,
1776 .sta_remove
= carl9170_op_sta_remove
,
1777 .sta_notify
= carl9170_op_sta_notify
,
1778 .get_survey
= carl9170_op_get_survey
,
1779 .get_stats
= carl9170_op_get_stats
,
1780 .ampdu_action
= carl9170_op_ampdu_action
,
1781 .tx_frames_pending
= carl9170_tx_frames_pending
,
1784 void *carl9170_alloc(size_t priv_size
)
1786 struct ieee80211_hw
*hw
;
1788 struct sk_buff
*skb
;
1792 * this buffer is used for rx stream reconstruction.
1793 * Under heavy load this device (or the transport layer?)
1794 * tends to split the streams into separate rx descriptors.
1797 skb
= __dev_alloc_skb(AR9170_RX_STREAM_MAX_SIZE
, GFP_KERNEL
);
1801 hw
= ieee80211_alloc_hw(priv_size
, &carl9170_ops
);
1807 ar
->rx_failover
= skb
;
1809 memset(&ar
->rx_plcp
, 0, sizeof(struct ar9170_rx_head
));
1810 ar
->rx_has_plcp
= false;
1813 * Here's a hidden pitfall!
1815 * All 4 AC queues work perfectly well under _legacy_ operation.
1816 * However as soon as aggregation is enabled, the traffic flow
1817 * gets very bumpy. Therefore we have to _switch_ to a
1818 * software AC with a single HW queue.
1820 hw
->queues
= __AR9170_NUM_TXQ
;
1822 mutex_init(&ar
->mutex
);
1823 spin_lock_init(&ar
->beacon_lock
);
1824 spin_lock_init(&ar
->cmd_lock
);
1825 spin_lock_init(&ar
->tx_stats_lock
);
1826 spin_lock_init(&ar
->tx_ampdu_list_lock
);
1827 spin_lock_init(&ar
->mem_lock
);
1828 spin_lock_init(&ar
->state_lock
);
1829 atomic_set(&ar
->pending_restarts
, 0);
1831 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1832 skb_queue_head_init(&ar
->tx_status
[i
]);
1833 skb_queue_head_init(&ar
->tx_pending
[i
]);
1835 INIT_LIST_HEAD(&ar
->bar_list
[i
]);
1836 spin_lock_init(&ar
->bar_list_lock
[i
]);
1838 INIT_WORK(&ar
->ps_work
, carl9170_ps_work
);
1839 INIT_WORK(&ar
->ping_work
, carl9170_ping_work
);
1840 INIT_WORK(&ar
->restart_work
, carl9170_restart_work
);
1841 INIT_WORK(&ar
->ampdu_work
, carl9170_ampdu_work
);
1842 INIT_DELAYED_WORK(&ar
->stat_work
, carl9170_stat_work
);
1843 INIT_DELAYED_WORK(&ar
->tx_janitor
, carl9170_tx_janitor
);
1844 INIT_LIST_HEAD(&ar
->tx_ampdu_list
);
1845 rcu_assign_pointer(ar
->tx_ampdu_iter
,
1846 (struct carl9170_sta_tid
*) &ar
->tx_ampdu_list
);
1848 bitmap_zero(&ar
->vif_bitmap
, ar
->fw
.vif_num
);
1849 INIT_LIST_HEAD(&ar
->vif_list
);
1850 init_completion(&ar
->tx_flush
);
1852 /* firmware decides which modes we support */
1853 hw
->wiphy
->interface_modes
= 0;
1855 hw
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
|
1856 IEEE80211_HW_MFP_CAPABLE
|
1857 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
1858 IEEE80211_HW_SUPPORTS_PS
|
1859 IEEE80211_HW_PS_NULLFUNC_STACK
|
1860 IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC
|
1861 IEEE80211_HW_SUPPORTS_RC_TABLE
|
1862 IEEE80211_HW_SIGNAL_DBM
|
1863 IEEE80211_HW_SUPPORTS_HT_CCK_RATES
;
1865 if (!modparam_noht
) {
1867 * see the comment above, why we allow the user
1868 * to disable HT by a module parameter.
1870 hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
1873 hw
->extra_tx_headroom
= sizeof(struct _carl9170_tx_superframe
);
1874 hw
->sta_data_size
= sizeof(struct carl9170_sta_info
);
1875 hw
->vif_data_size
= sizeof(struct carl9170_vif_info
);
1877 hw
->max_rates
= CARL9170_TX_MAX_RATES
;
1878 hw
->max_rate_tries
= CARL9170_TX_USER_RATE_TRIES
;
1880 for (i
= 0; i
< ARRAY_SIZE(ar
->noise
); i
++)
1881 ar
->noise
[i
] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1887 return ERR_PTR(-ENOMEM
);
1890 static int carl9170_read_eeprom(struct ar9170
*ar
)
1892 #define RW 8 /* number of words to read at once */
1893 #define RB (sizeof(u32) * RW)
1894 u8
*eeprom
= (void *)&ar
->eeprom
;
1898 BUILD_BUG_ON(sizeof(ar
->eeprom
) & 3);
1900 BUILD_BUG_ON(RB
> CARL9170_MAX_CMD_LEN
- 4);
1902 /* don't want to handle trailing remains */
1903 BUILD_BUG_ON(sizeof(ar
->eeprom
) % RB
);
1906 for (i
= 0; i
< sizeof(ar
->eeprom
) / RB
; i
++) {
1907 for (j
= 0; j
< RW
; j
++)
1908 offsets
[j
] = cpu_to_le32(AR9170_EEPROM_START
+
1911 err
= carl9170_exec_cmd(ar
, CARL9170_CMD_RREG
,
1912 RB
, (u8
*) &offsets
,
1913 RB
, eeprom
+ RB
* i
);
1923 static int carl9170_parse_eeprom(struct ar9170
*ar
)
1925 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1926 unsigned int rx_streams
, tx_streams
, tx_params
= 0;
1930 if (ar
->eeprom
.length
== cpu_to_le16(0xffff))
1933 rx_streams
= hweight8(ar
->eeprom
.rx_mask
);
1934 tx_streams
= hweight8(ar
->eeprom
.tx_mask
);
1936 if (rx_streams
!= tx_streams
) {
1937 tx_params
= IEEE80211_HT_MCS_TX_RX_DIFF
;
1939 WARN_ON(!(tx_streams
>= 1 && tx_streams
<=
1940 IEEE80211_HT_MCS_TX_MAX_STREAMS
));
1942 tx_params
= (tx_streams
- 1) <<
1943 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1945 carl9170_band_2GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1946 carl9170_band_5GHz
.ht_cap
.mcs
.tx_params
|= tx_params
;
1949 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_2GHZ
) {
1950 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
1951 &carl9170_band_2GHz
;
1952 chans
+= carl9170_band_2GHz
.n_channels
;
1955 if (ar
->eeprom
.operating_flags
& AR9170_OPFLAG_5GHZ
) {
1956 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
1957 &carl9170_band_5GHz
;
1958 chans
+= carl9170_band_5GHz
.n_channels
;
1965 ar
->survey
= kzalloc(sizeof(struct survey_info
) * chans
, GFP_KERNEL
);
1968 ar
->num_channels
= chans
;
1970 regulatory
->current_rd
= le16_to_cpu(ar
->eeprom
.reg_domain
[0]);
1972 /* second part of wiphy init */
1973 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->eeprom
.mac_address
);
1978 static void carl9170_reg_notifier(struct wiphy
*wiphy
,
1979 struct regulatory_request
*request
)
1981 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1982 struct ar9170
*ar
= hw
->priv
;
1984 ath_reg_notifier_apply(wiphy
, request
, &ar
->common
.regulatory
);
1987 int carl9170_register(struct ar9170
*ar
)
1989 struct ath_regulatory
*regulatory
= &ar
->common
.regulatory
;
1992 if (WARN_ON(ar
->mem_bitmap
))
1995 ar
->mem_bitmap
= kzalloc(roundup(ar
->fw
.mem_blocks
, BITS_PER_LONG
) *
1996 sizeof(unsigned long), GFP_KERNEL
);
1998 if (!ar
->mem_bitmap
)
2001 /* try to read EEPROM, init MAC addr */
2002 err
= carl9170_read_eeprom(ar
);
2006 err
= carl9170_parse_eeprom(ar
);
2010 err
= ath_regd_init(regulatory
, ar
->hw
->wiphy
,
2011 carl9170_reg_notifier
);
2015 if (modparam_noht
) {
2016 carl9170_band_2GHz
.ht_cap
.ht_supported
= false;
2017 carl9170_band_5GHz
.ht_cap
.ht_supported
= false;
2020 for (i
= 0; i
< ar
->fw
.vif_num
; i
++) {
2021 ar
->vif_priv
[i
].id
= i
;
2022 ar
->vif_priv
[i
].vif
= NULL
;
2025 err
= ieee80211_register_hw(ar
->hw
);
2029 /* mac80211 interface is now registered */
2030 ar
->registered
= true;
2032 if (!ath_is_world_regd(regulatory
))
2033 regulatory_hint(ar
->hw
->wiphy
, regulatory
->alpha2
);
2035 #ifdef CONFIG_CARL9170_DEBUGFS
2036 carl9170_debugfs_register(ar
);
2037 #endif /* CONFIG_CARL9170_DEBUGFS */
2039 err
= carl9170_led_init(ar
);
2043 #ifdef CONFIG_CARL9170_LEDS
2044 err
= carl9170_led_register(ar
);
2047 #endif /* CONFIG_CARL9170_LEDS */
2049 #ifdef CONFIG_CARL9170_WPC
2050 err
= carl9170_register_wps_button(ar
);
2053 #endif /* CONFIG_CARL9170_WPC */
2055 #ifdef CONFIG_CARL9170_HWRNG
2056 err
= carl9170_register_hwrng(ar
);
2059 #endif /* CONFIG_CARL9170_HWRNG */
2061 dev_info(&ar
->udev
->dev
, "Atheros AR9170 is registered as '%s'\n",
2062 wiphy_name(ar
->hw
->wiphy
));
2067 carl9170_unregister(ar
);
2071 void carl9170_unregister(struct ar9170
*ar
)
2073 if (!ar
->registered
)
2076 ar
->registered
= false;
2078 #ifdef CONFIG_CARL9170_LEDS
2079 carl9170_led_unregister(ar
);
2080 #endif /* CONFIG_CARL9170_LEDS */
2082 #ifdef CONFIG_CARL9170_DEBUGFS
2083 carl9170_debugfs_unregister(ar
);
2084 #endif /* CONFIG_CARL9170_DEBUGFS */
2086 #ifdef CONFIG_CARL9170_WPC
2088 input_unregister_device(ar
->wps
.pbc
);
2091 #endif /* CONFIG_CARL9170_WPC */
2093 #ifdef CONFIG_CARL9170_HWRNG
2094 carl9170_unregister_hwrng(ar
);
2095 #endif /* CONFIG_CARL9170_HWRNG */
2097 carl9170_cancel_worker(ar
);
2098 cancel_work_sync(&ar
->restart_work
);
2100 ieee80211_unregister_hw(ar
->hw
);
2103 void carl9170_free(struct ar9170
*ar
)
2105 WARN_ON(ar
->registered
);
2106 WARN_ON(IS_INITIALIZED(ar
));
2108 kfree_skb(ar
->rx_failover
);
2109 ar
->rx_failover
= NULL
;
2111 kfree(ar
->mem_bitmap
);
2112 ar
->mem_bitmap
= NULL
;
2117 mutex_destroy(&ar
->mutex
);
2119 ieee80211_free_hw(ar
->hw
);