2 * Copyright (c) 2010-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
24 static enum htc_phymode
ath9k_htc_get_curmode(struct ath9k_htc_priv
*priv
,
25 struct ath9k_channel
*ichan
)
27 if (IS_CHAN_5GHZ(ichan
))
33 bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
34 enum ath9k_power_mode mode
)
38 mutex_lock(&priv
->htc_pm_lock
);
39 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
40 mutex_unlock(&priv
->htc_pm_lock
);
45 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
47 mutex_lock(&priv
->htc_pm_lock
);
48 if (++priv
->ps_usecount
!= 1)
50 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
53 mutex_unlock(&priv
->htc_pm_lock
);
56 void ath9k_htc_ps_restore(struct ath9k_htc_priv
*priv
)
60 mutex_lock(&priv
->htc_pm_lock
);
61 if (--priv
->ps_usecount
!= 0)
65 ath9k_hw_setrxabort(priv
->ah
, true);
66 ath9k_hw_stopdmarecv(priv
->ah
, &reset
);
67 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
68 } else if (priv
->ps_enabled
) {
69 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
73 mutex_unlock(&priv
->htc_pm_lock
);
76 void ath9k_ps_work(struct work_struct
*work
)
78 struct ath9k_htc_priv
*priv
=
79 container_of(work
, struct ath9k_htc_priv
,
81 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
83 /* The chip wakes up after receiving the first beacon
84 while network sleep is enabled. For the driver to
85 be in sync with the hw, set the chip to awake and
86 only then set it to sleep.
88 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
91 static void ath9k_htc_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
93 struct ath9k_htc_priv
*priv
= data
;
94 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
96 if ((vif
->type
== NL80211_IFTYPE_AP
||
97 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
98 bss_conf
->enable_beacon
) {
99 priv
->reconfig_beacon
= true;
100 priv
->rearm_ani
= true;
103 if (bss_conf
->assoc
) {
104 priv
->rearm_ani
= true;
105 priv
->reconfig_beacon
= true;
109 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv
*priv
)
111 priv
->rearm_ani
= false;
112 priv
->reconfig_beacon
= false;
114 ieee80211_iterate_active_interfaces_atomic(
115 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
116 ath9k_htc_vif_iter
, priv
);
118 ath9k_htc_start_ani(priv
);
120 if (priv
->reconfig_beacon
) {
121 ath9k_htc_ps_wakeup(priv
);
122 ath9k_htc_beacon_reconfig(priv
);
123 ath9k_htc_ps_restore(priv
);
127 static void ath9k_htc_bssid_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
129 struct ath9k_vif_iter_data
*iter_data
= data
;
132 if (iter_data
->hw_macaddr
!= NULL
) {
133 for (i
= 0; i
< ETH_ALEN
; i
++)
134 iter_data
->mask
[i
] &= ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
136 iter_data
->hw_macaddr
= mac
;
140 static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv
*priv
,
141 struct ieee80211_vif
*vif
)
143 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
144 struct ath9k_vif_iter_data iter_data
;
147 * Pick the MAC address of the first interface as the new hardware
148 * MAC address. The hardware will use it together with the BSSID mask
149 * when matching addresses.
151 iter_data
.hw_macaddr
= NULL
;
152 memset(&iter_data
.mask
, 0xff, ETH_ALEN
);
155 ath9k_htc_bssid_iter(&iter_data
, vif
->addr
, vif
);
157 /* Get list of all active MAC addresses */
158 ieee80211_iterate_active_interfaces_atomic(
159 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
160 ath9k_htc_bssid_iter
, &iter_data
);
162 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
164 if (iter_data
.hw_macaddr
)
165 memcpy(common
->macaddr
, iter_data
.hw_macaddr
, ETH_ALEN
);
167 ath_hw_setbssidmask(common
);
170 static void ath9k_htc_set_opmode(struct ath9k_htc_priv
*priv
)
172 if (priv
->num_ibss_vif
)
173 priv
->ah
->opmode
= NL80211_IFTYPE_ADHOC
;
174 else if (priv
->num_ap_vif
)
175 priv
->ah
->opmode
= NL80211_IFTYPE_AP
;
176 else if (priv
->num_mbss_vif
)
177 priv
->ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
179 priv
->ah
->opmode
= NL80211_IFTYPE_STATION
;
181 ath9k_hw_setopmode(priv
->ah
);
184 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
186 struct ath_hw
*ah
= priv
->ah
;
187 struct ath_common
*common
= ath9k_hw_common(ah
);
188 struct ieee80211_channel
*channel
= priv
->hw
->conf
.chandef
.chan
;
189 struct ath9k_hw_cal_data
*caldata
= NULL
;
190 enum htc_phymode mode
;
195 mutex_lock(&priv
->mutex
);
196 ath9k_htc_ps_wakeup(priv
);
198 ath9k_htc_stop_ani(priv
);
199 ieee80211_stop_queues(priv
->hw
);
201 del_timer_sync(&priv
->tx
.cleanup_timer
);
202 ath9k_htc_tx_drain(priv
);
204 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
205 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
206 WMI_CMD(WMI_STOP_RECV_CMDID
);
208 ath9k_wmi_event_drain(priv
);
210 caldata
= &priv
->caldata
;
211 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
214 "Unable to reset device (%u Mhz) reset status %d\n",
215 channel
->center_freq
, ret
);
218 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
221 WMI_CMD(WMI_START_RECV_CMDID
);
222 ath9k_host_rx_init(priv
);
224 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
225 htc_mode
= cpu_to_be16(mode
);
226 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
228 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
229 htc_start(priv
->htc
);
230 ath9k_htc_vif_reconfig(priv
);
231 ieee80211_wake_queues(priv
->hw
);
233 mod_timer(&priv
->tx
.cleanup_timer
,
234 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
236 ath9k_htc_ps_restore(priv
);
237 mutex_unlock(&priv
->mutex
);
240 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
241 struct ieee80211_hw
*hw
,
242 struct ath9k_channel
*hchan
)
244 struct ath_hw
*ah
= priv
->ah
;
245 struct ath_common
*common
= ath9k_hw_common(ah
);
246 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
248 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
249 struct ath9k_hw_cal_data
*caldata
= NULL
;
250 enum htc_phymode mode
;
255 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
))
258 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
260 ath9k_htc_ps_wakeup(priv
);
262 ath9k_htc_stop_ani(priv
);
263 del_timer_sync(&priv
->tx
.cleanup_timer
);
264 ath9k_htc_tx_drain(priv
);
266 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
267 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
268 WMI_CMD(WMI_STOP_RECV_CMDID
);
270 ath9k_wmi_event_drain(priv
);
272 ath_dbg(common
, CONFIG
,
273 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
274 priv
->ah
->curchan
->channel
,
275 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
279 caldata
= &priv
->caldata
;
281 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
284 "Unable to reset channel (%u Mhz) reset status %d\n",
285 channel
->center_freq
, ret
);
289 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
292 WMI_CMD(WMI_START_RECV_CMDID
);
296 ath9k_host_rx_init(priv
);
298 mode
= ath9k_htc_get_curmode(priv
, hchan
);
299 htc_mode
= cpu_to_be16(mode
);
300 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
304 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
308 htc_start(priv
->htc
);
310 if (!test_bit(ATH_OP_SCANNING
, &common
->op_flags
) &&
311 !(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
312 ath9k_htc_vif_reconfig(priv
);
314 mod_timer(&priv
->tx
.cleanup_timer
,
315 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
317 /* perform spectral scan if requested. */
318 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
) &&
319 priv
->spec_priv
.spectral_mode
== SPECTRAL_CHANSCAN
)
320 ath9k_cmn_spectral_scan_trigger(common
, &priv
->spec_priv
);
322 ath9k_htc_ps_restore(priv
);
327 * Monitor mode handling is a tad complicated because the firmware requires
328 * an interface to be created exclusively, while mac80211 doesn't associate
329 * an interface with the mode.
331 * So, for now, only one monitor interface can be configured.
333 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
335 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
336 struct ath9k_htc_target_vif hvif
;
340 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
341 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
342 hvif
.index
= priv
->mon_vif_idx
;
343 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
345 ath_err(common
, "Unable to remove monitor interface at idx: %d\n",
350 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
353 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
355 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
356 struct ath9k_htc_target_vif hvif
;
357 struct ath9k_htc_target_sta tsta
;
358 int ret
= 0, sta_idx
;
361 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
362 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
367 sta_idx
= ffz(priv
->sta_slot
);
368 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
376 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
377 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
379 hvif
.opmode
= HTC_M_MONITOR
;
380 hvif
.index
= ffz(priv
->vif_slot
);
382 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
387 * Assign the monitor interface index as a special case here.
388 * This is needed when the interface is brought down.
390 priv
->mon_vif_idx
= hvif
.index
;
391 priv
->vif_slot
|= (1 << hvif
.index
);
394 * Set the hardware mode to monitor only if there are no
398 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
403 * Associate a station with the interface for packet injection.
405 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
407 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
410 tsta
.sta_index
= sta_idx
;
411 tsta
.vif_index
= hvif
.index
;
412 tsta
.maxampdu
= cpu_to_be16(0xffff);
414 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
416 ath_err(common
, "Unable to add station entry for monitor mode\n");
420 priv
->sta_slot
|= (1 << sta_idx
);
422 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
423 priv
->ah
->is_monitoring
= true;
425 ath_dbg(common
, CONFIG
,
426 "Attached a monitor interface at idx: %d, sta idx: %d\n",
427 priv
->mon_vif_idx
, sta_idx
);
433 * Remove the interface from the target.
435 __ath9k_htc_remove_monitor_interface(priv
);
437 ath_dbg(common
, FATAL
, "Unable to attach a monitor interface\n");
442 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
444 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
448 __ath9k_htc_remove_monitor_interface(priv
);
450 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
452 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
454 ath_err(common
, "Unable to remove station entry for monitor mode\n");
458 priv
->sta_slot
&= ~(1 << sta_idx
);
460 priv
->ah
->is_monitoring
= false;
462 ath_dbg(common
, CONFIG
,
463 "Removed a monitor interface at idx: %d, sta idx: %d\n",
464 priv
->mon_vif_idx
, sta_idx
);
469 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
470 struct ieee80211_vif
*vif
,
471 struct ieee80211_sta
*sta
)
473 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
474 struct ath9k_htc_target_sta tsta
;
475 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
476 struct ath9k_htc_sta
*ista
;
481 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
484 sta_idx
= ffz(priv
->sta_slot
);
485 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
488 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
491 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
492 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
493 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
494 ista
->index
= sta_idx
;
496 maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
497 sta
->ht_cap
.ampdu_factor
);
498 tsta
.maxampdu
= cpu_to_be16(maxampdu
);
500 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
502 tsta
.maxampdu
= cpu_to_be16(0xffff);
505 tsta
.sta_index
= sta_idx
;
506 tsta
.vif_index
= avp
->index
;
508 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
512 "Unable to add station entry for: %pM\n",
518 ath_dbg(common
, CONFIG
,
519 "Added a station entry for: %pM (idx: %d)\n",
520 sta
->addr
, tsta
.sta_index
);
522 ath_dbg(common
, CONFIG
,
523 "Added a station entry for VIF %d (idx: %d)\n",
524 avp
->index
, tsta
.sta_index
);
527 priv
->sta_slot
|= (1 << sta_idx
);
530 priv
->vif_sta_pos
[avp
->index
] = sta_idx
;
535 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
536 struct ieee80211_vif
*vif
,
537 struct ieee80211_sta
*sta
)
539 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
540 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
541 struct ath9k_htc_sta
*ista
;
546 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
547 sta_idx
= ista
->index
;
549 sta_idx
= priv
->vif_sta_pos
[avp
->index
];
552 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
556 "Unable to remove station entry for: %pM\n",
562 ath_dbg(common
, CONFIG
,
563 "Removed a station entry for: %pM (idx: %d)\n",
566 ath_dbg(common
, CONFIG
,
567 "Removed a station entry for VIF %d (idx: %d)\n",
568 avp
->index
, sta_idx
);
571 priv
->sta_slot
&= ~(1 << sta_idx
);
577 int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
,
580 struct ath9k_htc_cap_target tcap
;
584 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
586 tcap
.ampdu_limit
= cpu_to_be32(0xffff);
587 tcap
.ampdu_subframes
= 0xff;
588 tcap
.enable_coex
= enable_coex
;
589 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
591 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
596 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
597 struct ieee80211_sta
*sta
,
598 struct ath9k_htc_target_rate
*trate
)
600 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
601 struct ieee80211_supported_band
*sband
;
605 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.chandef
.chan
->band
];
607 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
608 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
609 trate
->rates
.legacy_rates
.rs_rates
[j
]
610 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
614 trate
->rates
.legacy_rates
.rs_nrates
= j
;
616 if (sta
->ht_cap
.ht_supported
) {
617 for (i
= 0, j
= 0; i
< 77; i
++) {
618 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
619 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
620 if (j
== ATH_HTC_RATE_MAX
)
623 trate
->rates
.ht_rates
.rs_nrates
= j
;
625 caps
= WLAN_RC_HT_FLAG
;
626 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_RX_STBC
)
627 caps
|= ATH_RC_TX_STBC_FLAG
;
628 if (sta
->ht_cap
.mcs
.rx_mask
[1])
629 caps
|= WLAN_RC_DS_FLAG
;
630 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
631 (conf_is_ht40(&priv
->hw
->conf
)))
632 caps
|= WLAN_RC_40_FLAG
;
633 if (conf_is_ht40(&priv
->hw
->conf
) &&
634 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
635 caps
|= WLAN_RC_SGI_FLAG
;
636 else if (conf_is_ht20(&priv
->hw
->conf
) &&
637 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
638 caps
|= WLAN_RC_SGI_FLAG
;
641 trate
->sta_index
= ista
->index
;
643 trate
->capflags
= cpu_to_be32(caps
);
646 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
647 struct ath9k_htc_target_rate
*trate
)
649 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
653 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
656 "Unable to initialize Rate information on target\n");
662 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
663 struct ieee80211_sta
*sta
)
665 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
666 struct ath9k_htc_target_rate trate
;
669 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
670 ath9k_htc_setup_rate(priv
, sta
, &trate
);
671 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
673 ath_dbg(common
, CONFIG
,
674 "Updated target sta: %pM, rate caps: 0x%X\n",
675 sta
->addr
, be32_to_cpu(trate
.capflags
));
678 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
679 struct ieee80211_vif
*vif
,
680 struct ieee80211_bss_conf
*bss_conf
)
682 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
683 struct ath9k_htc_target_rate trate
;
684 struct ieee80211_sta
*sta
;
687 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
690 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
695 ath9k_htc_setup_rate(priv
, sta
, &trate
);
698 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
700 ath_dbg(common
, CONFIG
,
701 "Updated target sta: %pM, rate caps: 0x%X\n",
702 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
705 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
706 struct ieee80211_vif
*vif
,
707 struct ieee80211_sta
*sta
,
708 enum ieee80211_ampdu_mlme_action action
,
711 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
712 struct ath9k_htc_target_aggr aggr
;
713 struct ath9k_htc_sta
*ista
;
717 if (tid
>= ATH9K_HTC_MAX_TID
)
720 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
721 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
723 aggr
.sta_index
= ista
->index
;
724 aggr
.tidno
= tid
& 0xf;
725 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
727 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
729 ath_dbg(common
, CONFIG
,
730 "Unable to %s TX aggregation for (%pM, %d)\n",
731 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
733 ath_dbg(common
, CONFIG
,
734 "%s TX aggregation for (%pM, %d)\n",
735 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
738 spin_lock_bh(&priv
->tx
.tx_lock
);
739 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
740 spin_unlock_bh(&priv
->tx
.tx_lock
);
749 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
751 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
752 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
754 common
->ani
.longcal_timer
= timestamp
;
755 common
->ani
.shortcal_timer
= timestamp
;
756 common
->ani
.checkani_timer
= timestamp
;
758 set_bit(ATH_OP_ANI_RUN
, &common
->op_flags
);
760 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
761 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
764 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
766 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
767 cancel_delayed_work_sync(&priv
->ani_work
);
768 clear_bit(ATH_OP_ANI_RUN
, &common
->op_flags
);
771 void ath9k_htc_ani_work(struct work_struct
*work
)
773 struct ath9k_htc_priv
*priv
=
774 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
775 struct ath_hw
*ah
= priv
->ah
;
776 struct ath_common
*common
= ath9k_hw_common(ah
);
777 bool longcal
= false;
778 bool shortcal
= false;
779 bool aniflag
= false;
780 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
781 u32 cal_interval
, short_cal_interval
;
783 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
784 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
786 /* Only calibrate if awake */
787 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
790 /* Long calibration runs independently of short calibration. */
791 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
793 ath_dbg(common
, ANI
, "longcal @%lu\n", jiffies
);
794 common
->ani
.longcal_timer
= timestamp
;
797 /* Short calibration applies only while caldone is false */
798 if (!common
->ani
.caldone
) {
799 if ((timestamp
- common
->ani
.shortcal_timer
) >=
800 short_cal_interval
) {
802 ath_dbg(common
, ANI
, "shortcal @%lu\n", jiffies
);
803 common
->ani
.shortcal_timer
= timestamp
;
804 common
->ani
.resetcal_timer
= timestamp
;
807 if ((timestamp
- common
->ani
.resetcal_timer
) >=
808 ATH_RESTART_CALINTERVAL
) {
809 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
810 if (common
->ani
.caldone
)
811 common
->ani
.resetcal_timer
= timestamp
;
815 /* Verify whether we must check ANI */
816 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
818 common
->ani
.checkani_timer
= timestamp
;
821 /* Skip all processing if there's nothing to do. */
822 if (longcal
|| shortcal
|| aniflag
) {
824 ath9k_htc_ps_wakeup(priv
);
826 /* Call ANI routine if necessary */
828 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
830 /* Perform calibration if necessary */
831 if (longcal
|| shortcal
)
832 common
->ani
.caldone
=
833 ath9k_hw_calibrate(ah
, ah
->curchan
,
834 ah
->rxchainmask
, longcal
);
836 ath9k_htc_ps_restore(priv
);
841 * Set timer interval based on previous results.
842 * The interval must be the shortest necessary to satisfy ANI,
843 * short calibration and long calibration.
845 cal_interval
= ATH_LONG_CALINTERVAL
;
846 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
847 if (!common
->ani
.caldone
)
848 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
850 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
851 msecs_to_jiffies(cal_interval
));
854 /**********************/
855 /* mac80211 Callbacks */
856 /**********************/
858 static void ath9k_htc_tx(struct ieee80211_hw
*hw
,
859 struct ieee80211_tx_control
*control
,
862 struct ieee80211_hdr
*hdr
;
863 struct ath9k_htc_priv
*priv
= hw
->priv
;
864 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
865 int padpos
, padsize
, ret
, slot
;
867 hdr
= (struct ieee80211_hdr
*) skb
->data
;
869 /* Add the padding after the header if this is not already done */
870 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
871 padsize
= padpos
& 3;
872 if (padsize
&& skb
->len
> padpos
) {
873 if (skb_headroom(skb
) < padsize
) {
874 ath_dbg(common
, XMIT
, "No room for padding\n");
877 skb_push(skb
, padsize
);
878 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
881 slot
= ath9k_htc_tx_get_slot(priv
);
883 ath_dbg(common
, XMIT
, "No free TX slot\n");
887 ret
= ath9k_htc_tx_start(priv
, control
->sta
, skb
, slot
, false);
889 ath_dbg(common
, XMIT
, "Tx failed\n");
893 ath9k_htc_check_stop_queues(priv
);
898 ath9k_htc_tx_clear_slot(priv
, slot
);
900 dev_kfree_skb_any(skb
);
903 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
905 struct ath9k_htc_priv
*priv
= hw
->priv
;
906 struct ath_hw
*ah
= priv
->ah
;
907 struct ath_common
*common
= ath9k_hw_common(ah
);
908 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
909 struct ath9k_channel
*init_channel
;
911 enum htc_phymode mode
;
915 mutex_lock(&priv
->mutex
);
917 ath_dbg(common
, CONFIG
,
918 "Starting driver with initial channel: %d MHz\n",
919 curchan
->center_freq
);
921 /* Ensure that HW is awake before flushing RX */
922 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
923 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
925 /* setup initial channel */
926 init_channel
= ath9k_cmn_get_channel(hw
, ah
, &hw
->conf
.chandef
);
928 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
931 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
932 ret
, curchan
->center_freq
);
933 mutex_unlock(&priv
->mutex
);
937 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
940 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
941 htc_mode
= cpu_to_be16(mode
);
942 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
943 WMI_CMD(WMI_ATH_INIT_CMDID
);
944 WMI_CMD(WMI_START_RECV_CMDID
);
946 ath9k_host_rx_init(priv
);
948 ret
= ath9k_htc_update_cap_target(priv
, 0);
950 ath_dbg(common
, CONFIG
,
951 "Failed to update capability in target\n");
953 clear_bit(ATH_OP_INVALID
, &common
->op_flags
);
954 htc_start(priv
->htc
);
956 spin_lock_bh(&priv
->tx
.tx_lock
);
957 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
958 spin_unlock_bh(&priv
->tx
.tx_lock
);
960 ieee80211_wake_queues(hw
);
962 mod_timer(&priv
->tx
.cleanup_timer
,
963 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
965 ath9k_htc_start_btcoex(priv
);
967 mutex_unlock(&priv
->mutex
);
972 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
974 struct ath9k_htc_priv
*priv
= hw
->priv
;
975 struct ath_hw
*ah
= priv
->ah
;
976 struct ath_common
*common
= ath9k_hw_common(ah
);
977 int ret
__attribute__ ((unused
));
980 mutex_lock(&priv
->mutex
);
982 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
983 ath_dbg(common
, ANY
, "Device not present\n");
984 mutex_unlock(&priv
->mutex
);
988 ath9k_htc_ps_wakeup(priv
);
990 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
991 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
992 WMI_CMD(WMI_STOP_RECV_CMDID
);
994 tasklet_kill(&priv
->rx_tasklet
);
996 del_timer_sync(&priv
->tx
.cleanup_timer
);
997 ath9k_htc_tx_drain(priv
);
998 ath9k_wmi_event_drain(priv
);
1000 mutex_unlock(&priv
->mutex
);
1002 /* Cancel all the running timers/work .. */
1003 cancel_work_sync(&priv
->fatal_work
);
1004 cancel_work_sync(&priv
->ps_work
);
1006 #ifdef CONFIG_MAC80211_LEDS
1007 cancel_work_sync(&priv
->led_work
);
1009 ath9k_htc_stop_ani(priv
);
1011 mutex_lock(&priv
->mutex
);
1013 ath9k_htc_stop_btcoex(priv
);
1015 /* Remove a monitor interface if it's present. */
1016 if (priv
->ah
->is_monitoring
)
1017 ath9k_htc_remove_monitor_interface(priv
);
1019 ath9k_hw_phy_disable(ah
);
1020 ath9k_hw_disable(ah
);
1021 ath9k_htc_ps_restore(priv
);
1022 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1024 set_bit(ATH_OP_INVALID
, &common
->op_flags
);
1026 ath_dbg(common
, CONFIG
, "Driver halt\n");
1027 mutex_unlock(&priv
->mutex
);
1030 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1031 struct ieee80211_vif
*vif
)
1033 struct ath9k_htc_priv
*priv
= hw
->priv
;
1034 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1035 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1036 struct ath9k_htc_target_vif hvif
;
1040 mutex_lock(&priv
->mutex
);
1042 ath9k_htc_ps_wakeup(priv
);
1043 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1044 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1046 switch (vif
->type
) {
1047 case NL80211_IFTYPE_STATION
:
1048 hvif
.opmode
= HTC_M_STA
;
1050 case NL80211_IFTYPE_ADHOC
:
1051 hvif
.opmode
= HTC_M_IBSS
;
1053 case NL80211_IFTYPE_AP
:
1054 hvif
.opmode
= HTC_M_HOSTAP
;
1056 case NL80211_IFTYPE_MESH_POINT
:
1057 hvif
.opmode
= HTC_M_WDS
; /* close enough */
1061 "Interface type %d not yet supported\n", vif
->type
);
1066 /* Index starts from zero on the target */
1067 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1068 hvif
.rtsthreshold
= cpu_to_be16(2304);
1069 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1074 * We need a node in target to tx mgmt frames
1075 * before association.
1077 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1079 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1083 ath9k_htc_set_mac_bssid_mask(priv
, vif
);
1085 priv
->vif_slot
|= (1 << avp
->index
);
1088 INC_VIF(priv
, vif
->type
);
1090 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1091 (vif
->type
== NL80211_IFTYPE_MESH_POINT
) ||
1092 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1093 ath9k_htc_assign_bslot(priv
, vif
);
1095 ath9k_htc_set_opmode(priv
);
1097 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1098 !test_bit(ATH_OP_ANI_RUN
, &common
->op_flags
)) {
1099 ath9k_hw_set_tsfadjust(priv
->ah
, true);
1100 ath9k_htc_start_ani(priv
);
1103 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d at idx: %d\n",
1104 vif
->type
, avp
->index
);
1107 ath9k_htc_ps_restore(priv
);
1108 mutex_unlock(&priv
->mutex
);
1113 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1114 struct ieee80211_vif
*vif
)
1116 struct ath9k_htc_priv
*priv
= hw
->priv
;
1117 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1118 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1119 struct ath9k_htc_target_vif hvif
;
1123 mutex_lock(&priv
->mutex
);
1124 ath9k_htc_ps_wakeup(priv
);
1126 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1127 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1128 hvif
.index
= avp
->index
;
1129 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1131 ath_err(common
, "Unable to remove interface at idx: %d\n",
1135 priv
->vif_slot
&= ~(1 << avp
->index
);
1137 ath9k_htc_remove_station(priv
, vif
, NULL
);
1139 DEC_VIF(priv
, vif
->type
);
1141 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1142 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
1143 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1144 ath9k_htc_remove_bslot(priv
, vif
);
1146 ath9k_htc_set_opmode(priv
);
1148 ath9k_htc_set_mac_bssid_mask(priv
, vif
);
1151 * Stop ANI only if there are no associated station interfaces.
1153 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1154 priv
->rearm_ani
= false;
1155 ieee80211_iterate_active_interfaces_atomic(
1156 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1157 ath9k_htc_vif_iter
, priv
);
1158 if (!priv
->rearm_ani
)
1159 ath9k_htc_stop_ani(priv
);
1162 ath_dbg(common
, CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1164 ath9k_htc_ps_restore(priv
);
1165 mutex_unlock(&priv
->mutex
);
1168 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1170 struct ath9k_htc_priv
*priv
= hw
->priv
;
1171 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1172 struct ieee80211_conf
*conf
= &hw
->conf
;
1173 bool chip_reset
= false;
1176 mutex_lock(&priv
->mutex
);
1177 ath9k_htc_ps_wakeup(priv
);
1179 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1180 mutex_lock(&priv
->htc_pm_lock
);
1182 priv
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1186 mutex_unlock(&priv
->htc_pm_lock
);
1190 * Monitor interface should be added before
1191 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1193 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1194 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1195 !priv
->ah
->is_monitoring
)
1196 ath9k_htc_add_monitor_interface(priv
);
1197 else if (priv
->ah
->is_monitoring
)
1198 ath9k_htc_remove_monitor_interface(priv
);
1201 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) || chip_reset
) {
1202 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
1203 int pos
= curchan
->hw_value
;
1205 ath_dbg(common
, CONFIG
, "Set channel: %d MHz\n",
1206 curchan
->center_freq
);
1208 ath9k_cmn_get_channel(hw
, priv
->ah
, &hw
->conf
.chandef
);
1209 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1210 ath_err(common
, "Unable to set channel\n");
1217 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1218 if (conf
->flags
& IEEE80211_CONF_PS
) {
1219 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1220 priv
->ps_enabled
= true;
1222 priv
->ps_enabled
= false;
1223 cancel_work_sync(&priv
->ps_work
);
1224 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1228 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1229 priv
->txpowlimit
= 2 * conf
->power_level
;
1230 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1231 priv
->txpowlimit
, &priv
->curtxpow
);
1235 ath9k_htc_ps_restore(priv
);
1236 mutex_unlock(&priv
->mutex
);
1240 #define SUPPORTED_FILTERS \
1241 (FIF_PROMISC_IN_BSS | \
1246 FIF_BCN_PRBRESP_PROMISC | \
1250 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1251 unsigned int changed_flags
,
1252 unsigned int *total_flags
,
1255 struct ath9k_htc_priv
*priv
= hw
->priv
;
1256 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1259 mutex_lock(&priv
->mutex
);
1260 changed_flags
&= SUPPORTED_FILTERS
;
1261 *total_flags
&= SUPPORTED_FILTERS
;
1263 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
1264 ath_dbg(ath9k_hw_common(priv
->ah
), ANY
,
1265 "Unable to configure filter on invalid state\n");
1266 mutex_unlock(&priv
->mutex
);
1269 ath9k_htc_ps_wakeup(priv
);
1271 priv
->rxfilter
= *total_flags
;
1272 rfilt
= ath9k_htc_calcrxfilter(priv
);
1273 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1275 ath_dbg(ath9k_hw_common(priv
->ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1278 ath9k_htc_ps_restore(priv
);
1279 mutex_unlock(&priv
->mutex
);
1282 static void ath9k_htc_sta_rc_update_work(struct work_struct
*work
)
1284 struct ath9k_htc_sta
*ista
=
1285 container_of(work
, struct ath9k_htc_sta
, rc_update_work
);
1286 struct ieee80211_sta
*sta
=
1287 container_of((void *)ista
, struct ieee80211_sta
, drv_priv
);
1288 struct ath9k_htc_priv
*priv
= ista
->htc_priv
;
1289 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1290 struct ath9k_htc_target_rate trate
;
1292 mutex_lock(&priv
->mutex
);
1293 ath9k_htc_ps_wakeup(priv
);
1295 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
1296 ath9k_htc_setup_rate(priv
, sta
, &trate
);
1297 if (!ath9k_htc_send_rate_cmd(priv
, &trate
))
1298 ath_dbg(common
, CONFIG
,
1299 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1300 sta
->addr
, be32_to_cpu(trate
.capflags
));
1302 ath_dbg(common
, CONFIG
,
1303 "Unable to update supported rates for sta: %pM\n",
1306 ath9k_htc_ps_restore(priv
);
1307 mutex_unlock(&priv
->mutex
);
1310 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1311 struct ieee80211_vif
*vif
,
1312 struct ieee80211_sta
*sta
)
1314 struct ath9k_htc_priv
*priv
= hw
->priv
;
1315 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1318 mutex_lock(&priv
->mutex
);
1319 ath9k_htc_ps_wakeup(priv
);
1320 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1322 INIT_WORK(&ista
->rc_update_work
, ath9k_htc_sta_rc_update_work
);
1323 ista
->htc_priv
= priv
;
1324 ath9k_htc_init_rate(priv
, sta
);
1326 ath9k_htc_ps_restore(priv
);
1327 mutex_unlock(&priv
->mutex
);
1332 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1333 struct ieee80211_vif
*vif
,
1334 struct ieee80211_sta
*sta
)
1336 struct ath9k_htc_priv
*priv
= hw
->priv
;
1337 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1340 cancel_work_sync(&ista
->rc_update_work
);
1342 mutex_lock(&priv
->mutex
);
1343 ath9k_htc_ps_wakeup(priv
);
1344 htc_sta_drain(priv
->htc
, ista
->index
);
1345 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1346 ath9k_htc_ps_restore(priv
);
1347 mutex_unlock(&priv
->mutex
);
1352 static void ath9k_htc_sta_rc_update(struct ieee80211_hw
*hw
,
1353 struct ieee80211_vif
*vif
,
1354 struct ieee80211_sta
*sta
, u32 changed
)
1356 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1358 if (!(changed
& IEEE80211_RC_SUPP_RATES_CHANGED
))
1361 schedule_work(&ista
->rc_update_work
);
1364 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
,
1365 struct ieee80211_vif
*vif
, u16 queue
,
1366 const struct ieee80211_tx_queue_params
*params
)
1368 struct ath9k_htc_priv
*priv
= hw
->priv
;
1369 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1370 struct ath9k_tx_queue_info qi
;
1373 if (queue
>= IEEE80211_NUM_ACS
)
1376 mutex_lock(&priv
->mutex
);
1377 ath9k_htc_ps_wakeup(priv
);
1379 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1381 qi
.tqi_aifs
= params
->aifs
;
1382 qi
.tqi_cwmin
= params
->cw_min
;
1383 qi
.tqi_cwmax
= params
->cw_max
;
1384 qi
.tqi_burstTime
= params
->txop
* 32;
1386 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1388 ath_dbg(common
, CONFIG
,
1389 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1390 queue
, qnum
, params
->aifs
, params
->cw_min
,
1391 params
->cw_max
, params
->txop
);
1393 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1395 ath_err(common
, "TXQ Update failed\n");
1399 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1400 (qnum
== priv
->hwq_map
[IEEE80211_AC_BE
]))
1401 ath9k_htc_beaconq_config(priv
);
1403 ath9k_htc_ps_restore(priv
);
1404 mutex_unlock(&priv
->mutex
);
1409 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1410 enum set_key_cmd cmd
,
1411 struct ieee80211_vif
*vif
,
1412 struct ieee80211_sta
*sta
,
1413 struct ieee80211_key_conf
*key
)
1415 struct ath9k_htc_priv
*priv
= hw
->priv
;
1416 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1419 if (htc_modparam_nohwcrypt
)
1422 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1423 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1424 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1425 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1426 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1428 * For now, disable hw crypto for the RSN IBSS group keys. This
1429 * could be optimized in the future to use a modified key cache
1430 * design to support per-STA RX GTK, but until that gets
1431 * implemented, use of software crypto for group addressed
1432 * frames is a acceptable to allow RSN IBSS to be used.
1437 mutex_lock(&priv
->mutex
);
1438 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1439 ath9k_htc_ps_wakeup(priv
);
1443 ret
= ath_key_config(common
, vif
, sta
, key
);
1445 key
->hw_key_idx
= ret
;
1446 /* push IV and Michael MIC generation to stack */
1447 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1448 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1449 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1450 if (priv
->ah
->sw_mgmt_crypto_tx
&&
1451 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1452 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1457 ath_key_delete(common
, key
);
1463 ath9k_htc_ps_restore(priv
);
1464 mutex_unlock(&priv
->mutex
);
1469 static void ath9k_htc_set_bssid(struct ath9k_htc_priv
*priv
)
1471 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1473 ath9k_hw_write_associd(priv
->ah
);
1474 ath_dbg(common
, CONFIG
, "BSSID: %pM aid: 0x%x\n",
1475 common
->curbssid
, common
->curaid
);
1478 static void ath9k_htc_bss_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1480 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*)data
;
1481 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1482 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1484 if ((vif
->type
== NL80211_IFTYPE_STATION
) && bss_conf
->assoc
) {
1485 common
->curaid
= bss_conf
->aid
;
1486 common
->last_rssi
= ATH_RSSI_DUMMY_MARKER
;
1487 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1488 set_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1492 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv
*priv
)
1494 if (priv
->num_sta_assoc_vif
== 1) {
1495 ieee80211_iterate_active_interfaces_atomic(
1496 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1497 ath9k_htc_bss_iter
, priv
);
1498 ath9k_htc_set_bssid(priv
);
1502 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1503 struct ieee80211_vif
*vif
,
1504 struct ieee80211_bss_conf
*bss_conf
,
1507 struct ath9k_htc_priv
*priv
= hw
->priv
;
1508 struct ath_hw
*ah
= priv
->ah
;
1509 struct ath_common
*common
= ath9k_hw_common(ah
);
1512 mutex_lock(&priv
->mutex
);
1513 ath9k_htc_ps_wakeup(priv
);
1515 if (changed
& BSS_CHANGED_ASSOC
) {
1516 ath_dbg(common
, CONFIG
, "BSS Changed ASSOC %d\n",
1520 priv
->num_sta_assoc_vif
++ : priv
->num_sta_assoc_vif
--;
1522 if (!bss_conf
->assoc
)
1523 clear_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1525 if (priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) {
1526 ath9k_htc_choose_set_bssid(priv
);
1527 if (bss_conf
->assoc
&& (priv
->num_sta_assoc_vif
== 1))
1528 ath9k_htc_start_ani(priv
);
1529 else if (priv
->num_sta_assoc_vif
== 0)
1530 ath9k_htc_stop_ani(priv
);
1534 if (changed
& BSS_CHANGED_IBSS
) {
1535 if (priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
1536 common
->curaid
= bss_conf
->aid
;
1537 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1538 ath9k_htc_set_bssid(priv
);
1542 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1543 ath_dbg(common
, CONFIG
, "Beacon enabled for BSS: %pM\n",
1545 ath9k_htc_set_tsfadjust(priv
, vif
);
1546 priv
->cur_beacon_conf
.enable_beacon
= 1;
1547 ath9k_htc_beacon_config(priv
, vif
);
1550 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1552 * Disable SWBA interrupt only if there are no
1553 * concurrent AP/mesh or IBSS interfaces.
1555 if ((priv
->num_ap_vif
+ priv
->num_mbss_vif
<= 1) ||
1556 priv
->num_ibss_vif
) {
1557 ath_dbg(common
, CONFIG
,
1558 "Beacon disabled for BSS: %pM\n",
1560 priv
->cur_beacon_conf
.enable_beacon
= 0;
1561 ath9k_htc_beacon_config(priv
, vif
);
1565 if (changed
& BSS_CHANGED_BEACON_INT
) {
1567 * Reset the HW TSF for the first AP or mesh interface.
1569 if (priv
->nvifs
== 1 &&
1570 ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
&&
1571 vif
->type
== NL80211_IFTYPE_AP
&&
1572 priv
->num_ap_vif
== 1) ||
1573 (priv
->ah
->opmode
== NL80211_IFTYPE_MESH_POINT
&&
1574 vif
->type
== NL80211_IFTYPE_MESH_POINT
&&
1575 priv
->num_mbss_vif
== 1))) {
1576 set_bit(OP_TSF_RESET
, &priv
->op_flags
);
1578 ath_dbg(common
, CONFIG
,
1579 "Beacon interval changed for BSS: %pM\n",
1581 ath9k_htc_beacon_config(priv
, vif
);
1584 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1585 if (bss_conf
->use_short_slot
)
1589 if (vif
->type
== NL80211_IFTYPE_AP
) {
1591 * Defer update, so that connected stations can adjust
1592 * their settings at the same time.
1593 * See beacon.c for more details
1595 priv
->beacon
.slottime
= slottime
;
1596 priv
->beacon
.updateslot
= UPDATE
;
1598 ah
->slottime
= slottime
;
1599 ath9k_hw_init_global_settings(ah
);
1603 if (changed
& BSS_CHANGED_HT
)
1604 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1606 ath9k_htc_ps_restore(priv
);
1607 mutex_unlock(&priv
->mutex
);
1610 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
,
1611 struct ieee80211_vif
*vif
)
1613 struct ath9k_htc_priv
*priv
= hw
->priv
;
1616 mutex_lock(&priv
->mutex
);
1617 ath9k_htc_ps_wakeup(priv
);
1618 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1619 ath9k_htc_ps_restore(priv
);
1620 mutex_unlock(&priv
->mutex
);
1625 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
,
1626 struct ieee80211_vif
*vif
, u64 tsf
)
1628 struct ath9k_htc_priv
*priv
= hw
->priv
;
1630 mutex_lock(&priv
->mutex
);
1631 ath9k_htc_ps_wakeup(priv
);
1632 ath9k_hw_settsf64(priv
->ah
, tsf
);
1633 ath9k_htc_ps_restore(priv
);
1634 mutex_unlock(&priv
->mutex
);
1637 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
,
1638 struct ieee80211_vif
*vif
)
1640 struct ath9k_htc_priv
*priv
= hw
->priv
;
1642 mutex_lock(&priv
->mutex
);
1643 ath9k_htc_ps_wakeup(priv
);
1644 ath9k_hw_reset_tsf(priv
->ah
);
1645 ath9k_htc_ps_restore(priv
);
1646 mutex_unlock(&priv
->mutex
);
1649 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1650 struct ieee80211_vif
*vif
,
1651 enum ieee80211_ampdu_mlme_action action
,
1652 struct ieee80211_sta
*sta
,
1653 u16 tid
, u16
*ssn
, u8 buf_size
)
1655 struct ath9k_htc_priv
*priv
= hw
->priv
;
1656 struct ath9k_htc_sta
*ista
;
1659 mutex_lock(&priv
->mutex
);
1660 ath9k_htc_ps_wakeup(priv
);
1663 case IEEE80211_AMPDU_RX_START
:
1665 case IEEE80211_AMPDU_RX_STOP
:
1667 case IEEE80211_AMPDU_TX_START
:
1668 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1670 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1672 case IEEE80211_AMPDU_TX_STOP_CONT
:
1673 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1674 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1675 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1676 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1678 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1679 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1680 spin_lock_bh(&priv
->tx
.tx_lock
);
1681 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1682 spin_unlock_bh(&priv
->tx
.tx_lock
);
1685 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1688 ath9k_htc_ps_restore(priv
);
1689 mutex_unlock(&priv
->mutex
);
1694 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
,
1695 struct ieee80211_vif
*vif
,
1698 struct ath9k_htc_priv
*priv
= hw
->priv
;
1699 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1701 mutex_lock(&priv
->mutex
);
1702 spin_lock_bh(&priv
->beacon_lock
);
1703 set_bit(ATH_OP_SCANNING
, &common
->op_flags
);
1704 spin_unlock_bh(&priv
->beacon_lock
);
1705 cancel_work_sync(&priv
->ps_work
);
1706 ath9k_htc_stop_ani(priv
);
1707 mutex_unlock(&priv
->mutex
);
1710 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
,
1711 struct ieee80211_vif
*vif
)
1713 struct ath9k_htc_priv
*priv
= hw
->priv
;
1714 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1716 mutex_lock(&priv
->mutex
);
1717 spin_lock_bh(&priv
->beacon_lock
);
1718 clear_bit(ATH_OP_SCANNING
, &common
->op_flags
);
1719 spin_unlock_bh(&priv
->beacon_lock
);
1720 ath9k_htc_ps_wakeup(priv
);
1721 ath9k_htc_vif_reconfig(priv
);
1722 ath9k_htc_ps_restore(priv
);
1723 mutex_unlock(&priv
->mutex
);
1726 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1731 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1734 struct ath9k_htc_priv
*priv
= hw
->priv
;
1736 mutex_lock(&priv
->mutex
);
1737 ath9k_htc_ps_wakeup(priv
);
1738 priv
->ah
->coverage_class
= coverage_class
;
1739 ath9k_hw_init_global_settings(priv
->ah
);
1740 ath9k_htc_ps_restore(priv
);
1741 mutex_unlock(&priv
->mutex
);
1745 * Currently, this is used only for selecting the minimum rate
1746 * for management frames, rate selection for data frames remain
1749 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw
*hw
,
1750 struct ieee80211_vif
*vif
,
1751 const struct cfg80211_bitrate_mask
*mask
)
1753 struct ath9k_htc_priv
*priv
= hw
->priv
;
1754 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1755 struct ath9k_htc_target_rate_mask tmask
;
1756 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1760 memset(&tmask
, 0, sizeof(struct ath9k_htc_target_rate_mask
));
1762 tmask
.vif_index
= avp
->index
;
1763 tmask
.band
= IEEE80211_BAND_2GHZ
;
1764 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_2GHZ
].legacy
);
1766 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1769 "Unable to set 2G rate mask for "
1770 "interface at idx: %d\n", avp
->index
);
1774 tmask
.band
= IEEE80211_BAND_5GHZ
;
1775 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1777 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1780 "Unable to set 5G rate mask for "
1781 "interface at idx: %d\n", avp
->index
);
1785 ath_dbg(common
, CONFIG
, "Set bitrate masks: 0x%x, 0x%x\n",
1786 mask
->control
[IEEE80211_BAND_2GHZ
].legacy
,
1787 mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1793 static int ath9k_htc_get_stats(struct ieee80211_hw
*hw
,
1794 struct ieee80211_low_level_stats
*stats
)
1796 struct ath9k_htc_priv
*priv
= hw
->priv
;
1797 struct ath_hw
*ah
= priv
->ah
;
1798 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1800 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1801 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1802 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1803 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1808 struct base_eep_header
*ath9k_htc_get_eeprom_base(struct ath9k_htc_priv
*priv
)
1810 struct base_eep_header
*pBase
= NULL
;
1812 * This can be done since all the 3 EEPROM families have the
1813 * same base header upto a certain point, and we are interested in
1814 * the data only upto that point.
1817 if (AR_SREV_9271(priv
->ah
))
1818 pBase
= (struct base_eep_header
*)
1819 &priv
->ah
->eeprom
.map4k
.baseEepHeader
;
1820 else if (priv
->ah
->hw_version
.usbdev
== AR9280_USB
)
1821 pBase
= (struct base_eep_header
*)
1822 &priv
->ah
->eeprom
.def
.baseEepHeader
;
1823 else if (priv
->ah
->hw_version
.usbdev
== AR9287_USB
)
1824 pBase
= (struct base_eep_header
*)
1825 &priv
->ah
->eeprom
.map9287
.baseEepHeader
;
1830 static int ath9k_htc_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
,
1833 struct ath9k_htc_priv
*priv
= hw
->priv
;
1834 struct base_eep_header
*pBase
= ath9k_htc_get_eeprom_base(priv
);
1836 *tx_ant
= pBase
->txMask
;
1837 *rx_ant
= pBase
->rxMask
;
1845 struct ieee80211_ops ath9k_htc_ops
= {
1847 .start
= ath9k_htc_start
,
1848 .stop
= ath9k_htc_stop
,
1849 .add_interface
= ath9k_htc_add_interface
,
1850 .remove_interface
= ath9k_htc_remove_interface
,
1851 .config
= ath9k_htc_config
,
1852 .configure_filter
= ath9k_htc_configure_filter
,
1853 .sta_add
= ath9k_htc_sta_add
,
1854 .sta_remove
= ath9k_htc_sta_remove
,
1855 .conf_tx
= ath9k_htc_conf_tx
,
1856 .sta_rc_update
= ath9k_htc_sta_rc_update
,
1857 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1858 .set_key
= ath9k_htc_set_key
,
1859 .get_tsf
= ath9k_htc_get_tsf
,
1860 .set_tsf
= ath9k_htc_set_tsf
,
1861 .reset_tsf
= ath9k_htc_reset_tsf
,
1862 .ampdu_action
= ath9k_htc_ampdu_action
,
1863 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1864 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1865 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1866 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1867 .set_coverage_class
= ath9k_htc_set_coverage_class
,
1868 .set_bitrate_mask
= ath9k_htc_set_bitrate_mask
,
1869 .get_stats
= ath9k_htc_get_stats
,
1870 .get_antenna
= ath9k_htc_get_antenna
,
1872 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1873 .get_et_sset_count
= ath9k_htc_get_et_sset_count
,
1874 .get_et_stats
= ath9k_htc_get_et_stats
,
1875 .get_et_strings
= ath9k_htc_get_et_strings
,