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 (vif
->cfg
.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 eth_broadcast_addr(iter_data
.mask
);
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
;
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
),
277 caldata
= fastcc
? NULL
: &priv
->caldata
;
278 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
281 "Unable to reset channel (%u Mhz) reset status %d\n",
282 channel
->center_freq
, ret
);
286 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
289 WMI_CMD(WMI_START_RECV_CMDID
);
293 ath9k_host_rx_init(priv
);
295 mode
= ath9k_htc_get_curmode(priv
, hchan
);
296 htc_mode
= cpu_to_be16(mode
);
297 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
301 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
305 htc_start(priv
->htc
);
307 if (!test_bit(ATH_OP_SCANNING
, &common
->op_flags
) &&
308 !(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
309 ath9k_htc_vif_reconfig(priv
);
311 mod_timer(&priv
->tx
.cleanup_timer
,
312 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
314 /* perform spectral scan if requested. */
315 if (test_bit(ATH_OP_SCANNING
, &common
->op_flags
) &&
316 priv
->spec_priv
.spectral_mode
== SPECTRAL_CHANSCAN
)
317 ath9k_cmn_spectral_scan_trigger(common
, &priv
->spec_priv
);
319 ath9k_htc_ps_restore(priv
);
324 * Monitor mode handling is a tad complicated because the firmware requires
325 * an interface to be created exclusively, while mac80211 doesn't associate
326 * an interface with the mode.
328 * So, for now, only one monitor interface can be configured.
330 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
332 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
333 struct ath9k_htc_target_vif hvif
;
337 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
338 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
339 hvif
.index
= priv
->mon_vif_idx
;
340 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
342 ath_err(common
, "Unable to remove monitor interface at idx: %d\n",
347 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
350 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
352 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
353 struct ath9k_htc_target_vif hvif
;
354 struct ath9k_htc_target_sta tsta
;
355 int ret
= 0, sta_idx
;
358 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
359 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
364 sta_idx
= ffz(priv
->sta_slot
);
365 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
373 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
374 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
376 hvif
.opmode
= HTC_M_MONITOR
;
377 hvif
.index
= ffz(priv
->vif_slot
);
379 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
384 * Assign the monitor interface index as a special case here.
385 * This is needed when the interface is brought down.
387 priv
->mon_vif_idx
= hvif
.index
;
388 priv
->vif_slot
|= (1 << hvif
.index
);
391 * Set the hardware mode to monitor only if there are no
395 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
400 * Associate a station with the interface for packet injection.
402 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
404 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
407 tsta
.sta_index
= sta_idx
;
408 tsta
.vif_index
= hvif
.index
;
409 tsta
.maxampdu
= cpu_to_be16(0xffff);
411 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
413 ath_err(common
, "Unable to add station entry for monitor mode\n");
417 priv
->sta_slot
|= (1 << sta_idx
);
419 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
420 priv
->ah
->is_monitoring
= true;
422 ath_dbg(common
, CONFIG
,
423 "Attached a monitor interface at idx: %d, sta idx: %d\n",
424 priv
->mon_vif_idx
, sta_idx
);
430 * Remove the interface from the target.
432 __ath9k_htc_remove_monitor_interface(priv
);
434 ath_dbg(common
, FATAL
, "Unable to attach a monitor interface\n");
439 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
441 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
445 __ath9k_htc_remove_monitor_interface(priv
);
447 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
449 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
451 ath_err(common
, "Unable to remove station entry for monitor mode\n");
455 priv
->sta_slot
&= ~(1 << sta_idx
);
457 priv
->ah
->is_monitoring
= false;
459 ath_dbg(common
, CONFIG
,
460 "Removed a monitor interface at idx: %d, sta idx: %d\n",
461 priv
->mon_vif_idx
, sta_idx
);
466 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
467 struct ieee80211_vif
*vif
,
468 struct ieee80211_sta
*sta
)
470 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
471 struct ath9k_htc_target_sta tsta
;
472 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
473 struct ath9k_htc_sta
*ista
;
478 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
481 sta_idx
= ffz(priv
->sta_slot
);
482 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
485 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
488 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
489 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
490 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
491 ista
->index
= sta_idx
;
493 maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
494 sta
->deflink
.ht_cap
.ampdu_factor
);
495 tsta
.maxampdu
= cpu_to_be16(maxampdu
);
497 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
499 tsta
.maxampdu
= cpu_to_be16(0xffff);
502 tsta
.sta_index
= sta_idx
;
503 tsta
.vif_index
= avp
->index
;
505 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
509 "Unable to add station entry for: %pM\n",
515 ath_dbg(common
, CONFIG
,
516 "Added a station entry for: %pM (idx: %d)\n",
517 sta
->addr
, tsta
.sta_index
);
519 ath_dbg(common
, CONFIG
,
520 "Added a station entry for VIF %d (idx: %d)\n",
521 avp
->index
, tsta
.sta_index
);
524 priv
->sta_slot
|= (1 << sta_idx
);
527 priv
->vif_sta_pos
[avp
->index
] = sta_idx
;
532 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
533 struct ieee80211_vif
*vif
,
534 struct ieee80211_sta
*sta
)
536 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
537 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
538 struct ath9k_htc_sta
*ista
;
543 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
544 sta_idx
= ista
->index
;
546 sta_idx
= priv
->vif_sta_pos
[avp
->index
];
549 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
553 "Unable to remove station entry for: %pM\n",
559 ath_dbg(common
, CONFIG
,
560 "Removed a station entry for: %pM (idx: %d)\n",
563 ath_dbg(common
, CONFIG
,
564 "Removed a station entry for VIF %d (idx: %d)\n",
565 avp
->index
, sta_idx
);
568 priv
->sta_slot
&= ~(1 << sta_idx
);
574 int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
,
577 struct ath9k_htc_cap_target tcap
;
581 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
583 tcap
.ampdu_limit
= cpu_to_be32(0xffff);
584 tcap
.ampdu_subframes
= 0xff;
585 tcap
.enable_coex
= enable_coex
;
586 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
588 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
593 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
594 struct ieee80211_sta
*sta
,
595 struct ath9k_htc_target_rate
*trate
)
597 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
598 struct ieee80211_supported_band
*sband
;
602 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.chandef
.chan
->band
];
604 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
605 if (sta
->deflink
.supp_rates
[sband
->band
] & BIT(i
)) {
606 trate
->rates
.legacy_rates
.rs_rates
[j
]
607 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
611 trate
->rates
.legacy_rates
.rs_nrates
= j
;
613 if (sta
->deflink
.ht_cap
.ht_supported
) {
614 for (i
= 0, j
= 0; i
< 77; i
++) {
615 if (sta
->deflink
.ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
616 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
617 if (j
== ATH_HTC_RATE_MAX
)
620 trate
->rates
.ht_rates
.rs_nrates
= j
;
622 caps
= WLAN_RC_HT_FLAG
;
623 if (sta
->deflink
.ht_cap
.cap
& IEEE80211_HT_CAP_RX_STBC
)
624 caps
|= ATH_RC_TX_STBC_FLAG
;
625 if (sta
->deflink
.ht_cap
.mcs
.rx_mask
[1])
626 caps
|= WLAN_RC_DS_FLAG
;
627 if ((sta
->deflink
.ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
628 (conf_is_ht40(&priv
->hw
->conf
)))
629 caps
|= WLAN_RC_40_FLAG
;
630 if (conf_is_ht40(&priv
->hw
->conf
) &&
631 (sta
->deflink
.ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
632 caps
|= WLAN_RC_SGI_FLAG
;
633 else if (conf_is_ht20(&priv
->hw
->conf
) &&
634 (sta
->deflink
.ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
635 caps
|= WLAN_RC_SGI_FLAG
;
638 trate
->sta_index
= ista
->index
;
640 trate
->capflags
= cpu_to_be32(caps
);
643 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
644 struct ath9k_htc_target_rate
*trate
)
646 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
650 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
653 "Unable to initialize Rate information on target\n");
659 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
660 struct ieee80211_sta
*sta
)
662 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
663 struct ath9k_htc_target_rate trate
;
666 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
667 ath9k_htc_setup_rate(priv
, sta
, &trate
);
668 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
670 ath_dbg(common
, CONFIG
,
671 "Updated target sta: %pM, rate caps: 0x%X\n",
672 sta
->addr
, be32_to_cpu(trate
.capflags
));
675 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
676 struct ieee80211_vif
*vif
,
677 struct ieee80211_bss_conf
*bss_conf
)
679 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
680 struct ath9k_htc_target_rate trate
;
681 struct ieee80211_sta
*sta
;
684 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
687 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
692 ath9k_htc_setup_rate(priv
, sta
, &trate
);
695 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
697 ath_dbg(common
, CONFIG
,
698 "Updated target sta: %pM, rate caps: 0x%X\n",
699 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
702 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
703 struct ieee80211_vif
*vif
,
704 struct ieee80211_sta
*sta
,
705 enum ieee80211_ampdu_mlme_action action
,
708 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
709 struct ath9k_htc_target_aggr aggr
;
710 struct ath9k_htc_sta
*ista
;
714 if (tid
>= ATH9K_HTC_MAX_TID
)
717 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
718 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
720 aggr
.sta_index
= ista
->index
;
721 aggr
.tidno
= tid
& 0xf;
722 aggr
.aggr_enable
= action
== IEEE80211_AMPDU_TX_START
;
724 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
726 ath_dbg(common
, CONFIG
,
727 "Unable to %s TX aggregation for (%pM, %d)\n",
728 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
730 ath_dbg(common
, CONFIG
,
731 "%s TX aggregation for (%pM, %d)\n",
732 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
735 spin_lock_bh(&priv
->tx
.tx_lock
);
736 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
737 spin_unlock_bh(&priv
->tx
.tx_lock
);
746 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
748 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
749 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
751 common
->ani
.longcal_timer
= timestamp
;
752 common
->ani
.shortcal_timer
= timestamp
;
753 common
->ani
.checkani_timer
= timestamp
;
755 set_bit(ATH_OP_ANI_RUN
, &common
->op_flags
);
757 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
758 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
761 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
763 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
764 cancel_delayed_work_sync(&priv
->ani_work
);
765 clear_bit(ATH_OP_ANI_RUN
, &common
->op_flags
);
768 void ath9k_htc_ani_work(struct work_struct
*work
)
770 struct ath9k_htc_priv
*priv
=
771 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
772 struct ath_hw
*ah
= priv
->ah
;
773 struct ath_common
*common
= ath9k_hw_common(ah
);
774 bool longcal
= false;
775 bool shortcal
= false;
776 bool aniflag
= false;
777 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
778 u32 cal_interval
, short_cal_interval
;
780 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
781 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
783 /* Only calibrate if awake */
784 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
787 /* Long calibration runs independently of short calibration. */
788 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
790 ath_dbg(common
, ANI
, "longcal @%lu\n", jiffies
);
791 common
->ani
.longcal_timer
= timestamp
;
795 * Short calibration applies only while caldone
796 * is false or -ETIMEDOUT
798 if (common
->ani
.caldone
<= 0) {
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
) > 0;
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
);
848 * Short calibration applies only while caldone
849 * is false or -ETIMEDOUT
851 if (common
->ani
.caldone
<= 0)
852 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
854 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
855 msecs_to_jiffies(cal_interval
));
858 /**********************/
859 /* mac80211 Callbacks */
860 /**********************/
862 static void ath9k_htc_tx(struct ieee80211_hw
*hw
,
863 struct ieee80211_tx_control
*control
,
866 struct ieee80211_hdr
*hdr
;
867 struct ath9k_htc_priv
*priv
= hw
->priv
;
868 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
869 int padpos
, padsize
, ret
, slot
;
871 hdr
= (struct ieee80211_hdr
*) skb
->data
;
873 /* Add the padding after the header if this is not already done */
874 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
875 padsize
= padpos
& 3;
876 if (padsize
&& skb
->len
> padpos
) {
877 if (skb_headroom(skb
) < padsize
) {
878 ath_dbg(common
, XMIT
, "No room for padding\n");
881 skb_push(skb
, padsize
);
882 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
885 slot
= ath9k_htc_tx_get_slot(priv
);
887 ath_dbg(common
, XMIT
, "No free TX slot\n");
891 ret
= ath9k_htc_tx_start(priv
, control
->sta
, skb
, slot
, false);
893 ath_dbg(common
, XMIT
, "Tx failed\n");
897 ath9k_htc_check_stop_queues(priv
);
902 ath9k_htc_tx_clear_slot(priv
, slot
);
904 dev_kfree_skb_any(skb
);
907 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
909 struct ath9k_htc_priv
*priv
= hw
->priv
;
910 struct ath_hw
*ah
= priv
->ah
;
911 struct ath_common
*common
= ath9k_hw_common(ah
);
912 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
913 struct ath9k_channel
*init_channel
;
915 enum htc_phymode mode
;
919 mutex_lock(&priv
->mutex
);
921 ath_dbg(common
, CONFIG
,
922 "Starting driver with initial channel: %d MHz\n",
923 curchan
->center_freq
);
925 /* Ensure that HW is awake before flushing RX */
926 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
927 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
929 /* setup initial channel */
930 init_channel
= ath9k_cmn_get_channel(hw
, ah
, &hw
->conf
.chandef
);
932 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
935 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
936 ret
, curchan
->center_freq
);
937 mutex_unlock(&priv
->mutex
);
941 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
944 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
945 htc_mode
= cpu_to_be16(mode
);
946 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
947 WMI_CMD(WMI_ATH_INIT_CMDID
);
948 WMI_CMD(WMI_START_RECV_CMDID
);
950 ath9k_host_rx_init(priv
);
952 ret
= ath9k_htc_update_cap_target(priv
, 0);
954 ath_dbg(common
, CONFIG
,
955 "Failed to update capability in target\n");
957 clear_bit(ATH_OP_INVALID
, &common
->op_flags
);
958 htc_start(priv
->htc
);
960 spin_lock_bh(&priv
->tx
.tx_lock
);
961 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
962 spin_unlock_bh(&priv
->tx
.tx_lock
);
964 ieee80211_wake_queues(hw
);
966 mod_timer(&priv
->tx
.cleanup_timer
,
967 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
969 ath9k_htc_start_btcoex(priv
);
971 mutex_unlock(&priv
->mutex
);
976 static void ath9k_htc_stop(struct ieee80211_hw
*hw
, bool suspend
)
978 struct ath9k_htc_priv
*priv
= hw
->priv
;
979 struct ath_hw
*ah
= priv
->ah
;
980 struct ath_common
*common
= ath9k_hw_common(ah
);
981 int ret
__attribute__ ((unused
));
984 mutex_lock(&priv
->mutex
);
986 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
987 ath_dbg(common
, ANY
, "Device not present\n");
988 mutex_unlock(&priv
->mutex
);
992 ath9k_htc_ps_wakeup(priv
);
994 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
995 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
996 WMI_CMD(WMI_STOP_RECV_CMDID
);
998 tasklet_kill(&priv
->rx_tasklet
);
1000 del_timer_sync(&priv
->tx
.cleanup_timer
);
1001 ath9k_htc_tx_drain(priv
);
1002 ath9k_wmi_event_drain(priv
);
1004 mutex_unlock(&priv
->mutex
);
1006 /* Cancel all the running timers/work .. */
1007 cancel_work_sync(&priv
->fatal_work
);
1008 cancel_work_sync(&priv
->ps_work
);
1010 #ifdef CONFIG_MAC80211_LEDS
1011 cancel_work_sync(&priv
->led_work
);
1013 ath9k_htc_stop_ani(priv
);
1015 mutex_lock(&priv
->mutex
);
1017 ath9k_htc_stop_btcoex(priv
);
1019 /* Remove a monitor interface if it's present. */
1020 if (priv
->ah
->is_monitoring
)
1021 ath9k_htc_remove_monitor_interface(priv
);
1023 ath9k_hw_phy_disable(ah
);
1024 ath9k_hw_disable(ah
);
1025 ath9k_htc_ps_restore(priv
);
1026 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1028 set_bit(ATH_OP_INVALID
, &common
->op_flags
);
1030 ath_dbg(common
, CONFIG
, "Driver halt\n");
1031 mutex_unlock(&priv
->mutex
);
1034 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1035 struct ieee80211_vif
*vif
)
1037 struct ath9k_htc_priv
*priv
= hw
->priv
;
1038 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1039 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1040 struct ath9k_htc_target_vif hvif
;
1044 mutex_lock(&priv
->mutex
);
1046 ath9k_htc_ps_wakeup(priv
);
1047 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1048 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1050 switch (vif
->type
) {
1051 case NL80211_IFTYPE_STATION
:
1052 hvif
.opmode
= HTC_M_STA
;
1054 case NL80211_IFTYPE_ADHOC
:
1055 hvif
.opmode
= HTC_M_IBSS
;
1057 case NL80211_IFTYPE_AP
:
1058 hvif
.opmode
= HTC_M_HOSTAP
;
1060 case NL80211_IFTYPE_MESH_POINT
:
1061 hvif
.opmode
= HTC_M_WDS
; /* close enough */
1065 "Interface type %d not yet supported\n", vif
->type
);
1070 /* Index starts from zero on the target */
1071 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1072 hvif
.rtsthreshold
= cpu_to_be16(2304);
1073 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1078 * We need a node in target to tx mgmt frames
1079 * before association.
1081 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1083 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1087 ath9k_htc_set_mac_bssid_mask(priv
, vif
);
1089 priv
->vif_slot
|= (1 << avp
->index
);
1092 INC_VIF(priv
, vif
->type
);
1094 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1095 (vif
->type
== NL80211_IFTYPE_MESH_POINT
) ||
1096 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1097 ath9k_htc_assign_bslot(priv
, vif
);
1099 ath9k_htc_set_opmode(priv
);
1101 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1102 !test_bit(ATH_OP_ANI_RUN
, &common
->op_flags
)) {
1103 ath9k_hw_set_tsfadjust(priv
->ah
, true);
1104 ath9k_htc_start_ani(priv
);
1107 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d at idx: %d\n",
1108 vif
->type
, avp
->index
);
1111 ath9k_htc_ps_restore(priv
);
1112 mutex_unlock(&priv
->mutex
);
1117 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1118 struct ieee80211_vif
*vif
)
1120 struct ath9k_htc_priv
*priv
= hw
->priv
;
1121 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1122 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1123 struct ath9k_htc_target_vif hvif
;
1127 mutex_lock(&priv
->mutex
);
1128 ath9k_htc_ps_wakeup(priv
);
1130 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1131 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1132 hvif
.index
= avp
->index
;
1133 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1135 ath_err(common
, "Unable to remove interface at idx: %d\n",
1139 priv
->vif_slot
&= ~(1 << avp
->index
);
1141 if (priv
->csa_vif
== vif
)
1142 priv
->csa_vif
= NULL
;
1144 ath9k_htc_remove_station(priv
, vif
, NULL
);
1146 DEC_VIF(priv
, vif
->type
);
1148 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1149 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
1150 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1151 ath9k_htc_remove_bslot(priv
, vif
);
1153 ath9k_htc_set_opmode(priv
);
1155 ath9k_htc_set_mac_bssid_mask(priv
, vif
);
1158 * Stop ANI only if there are no associated station interfaces.
1160 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1161 priv
->rearm_ani
= false;
1162 ieee80211_iterate_active_interfaces_atomic(
1163 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1164 ath9k_htc_vif_iter
, priv
);
1165 if (!priv
->rearm_ani
)
1166 ath9k_htc_stop_ani(priv
);
1169 ath_dbg(common
, CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1171 ath9k_htc_ps_restore(priv
);
1172 mutex_unlock(&priv
->mutex
);
1175 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1177 struct ath9k_htc_priv
*priv
= hw
->priv
;
1178 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1179 struct ieee80211_conf
*conf
= &hw
->conf
;
1180 bool chip_reset
= false;
1183 mutex_lock(&priv
->mutex
);
1184 ath9k_htc_ps_wakeup(priv
);
1186 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1187 mutex_lock(&priv
->htc_pm_lock
);
1189 priv
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1193 mutex_unlock(&priv
->htc_pm_lock
);
1197 * Monitor interface should be added before
1198 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1200 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1201 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1202 !priv
->ah
->is_monitoring
)
1203 ath9k_htc_add_monitor_interface(priv
);
1204 else if (priv
->ah
->is_monitoring
)
1205 ath9k_htc_remove_monitor_interface(priv
);
1208 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) || chip_reset
) {
1209 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
1210 int pos
= curchan
->hw_value
;
1212 ath_dbg(common
, CONFIG
, "Set channel: %d MHz\n",
1213 curchan
->center_freq
);
1215 ath9k_cmn_get_channel(hw
, priv
->ah
, &hw
->conf
.chandef
);
1216 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1217 ath_err(common
, "Unable to set channel\n");
1224 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1225 if (conf
->flags
& IEEE80211_CONF_PS
) {
1226 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1227 priv
->ps_enabled
= true;
1229 priv
->ps_enabled
= false;
1230 cancel_work_sync(&priv
->ps_work
);
1231 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1235 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1236 priv
->txpowlimit
= 2 * conf
->power_level
;
1237 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1238 priv
->txpowlimit
, &priv
->curtxpow
);
1242 ath9k_htc_ps_restore(priv
);
1243 mutex_unlock(&priv
->mutex
);
1247 #define SUPPORTED_FILTERS \
1252 FIF_BCN_PRBRESP_PROMISC | \
1254 FIF_MCAST_ACTION | \
1257 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1258 unsigned int changed_flags
,
1259 unsigned int *total_flags
,
1262 struct ath9k_htc_priv
*priv
= hw
->priv
;
1263 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1266 mutex_lock(&priv
->mutex
);
1267 *total_flags
&= SUPPORTED_FILTERS
;
1269 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
1270 ath_dbg(ath9k_hw_common(priv
->ah
), ANY
,
1271 "Unable to configure filter on invalid state\n");
1272 mutex_unlock(&priv
->mutex
);
1275 ath9k_htc_ps_wakeup(priv
);
1277 priv
->rxfilter
= *total_flags
;
1278 rfilt
= ath9k_htc_calcrxfilter(priv
);
1279 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1281 ath_dbg(ath9k_hw_common(priv
->ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1284 ath9k_htc_ps_restore(priv
);
1285 mutex_unlock(&priv
->mutex
);
1288 static void ath9k_htc_sta_rc_update_work(struct work_struct
*work
)
1290 struct ath9k_htc_sta
*ista
=
1291 container_of(work
, struct ath9k_htc_sta
, rc_update_work
);
1292 struct ieee80211_sta
*sta
=
1293 container_of((void *)ista
, struct ieee80211_sta
, drv_priv
);
1294 struct ath9k_htc_priv
*priv
= ista
->htc_priv
;
1295 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1296 struct ath9k_htc_target_rate trate
;
1298 mutex_lock(&priv
->mutex
);
1299 ath9k_htc_ps_wakeup(priv
);
1301 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
1302 ath9k_htc_setup_rate(priv
, sta
, &trate
);
1303 if (!ath9k_htc_send_rate_cmd(priv
, &trate
))
1304 ath_dbg(common
, CONFIG
,
1305 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1306 sta
->addr
, be32_to_cpu(trate
.capflags
));
1308 ath_dbg(common
, CONFIG
,
1309 "Unable to update supported rates for sta: %pM\n",
1312 ath9k_htc_ps_restore(priv
);
1313 mutex_unlock(&priv
->mutex
);
1316 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1317 struct ieee80211_vif
*vif
,
1318 struct ieee80211_sta
*sta
)
1320 struct ath9k_htc_priv
*priv
= hw
->priv
;
1321 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1324 mutex_lock(&priv
->mutex
);
1325 ath9k_htc_ps_wakeup(priv
);
1326 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1328 INIT_WORK(&ista
->rc_update_work
, ath9k_htc_sta_rc_update_work
);
1329 ista
->htc_priv
= priv
;
1330 ath9k_htc_init_rate(priv
, sta
);
1332 ath9k_htc_ps_restore(priv
);
1333 mutex_unlock(&priv
->mutex
);
1338 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1339 struct ieee80211_vif
*vif
,
1340 struct ieee80211_sta
*sta
)
1342 struct ath9k_htc_priv
*priv
= hw
->priv
;
1343 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1346 cancel_work_sync(&ista
->rc_update_work
);
1348 mutex_lock(&priv
->mutex
);
1349 ath9k_htc_ps_wakeup(priv
);
1350 htc_sta_drain(priv
->htc
, ista
->index
);
1351 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1352 ath9k_htc_ps_restore(priv
);
1353 mutex_unlock(&priv
->mutex
);
1358 static void ath9k_htc_sta_rc_update(struct ieee80211_hw
*hw
,
1359 struct ieee80211_vif
*vif
,
1360 struct ieee80211_link_sta
*link_sta
,
1363 struct ieee80211_sta
*sta
= link_sta
->sta
;
1364 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1366 if (!(changed
& IEEE80211_RC_SUPP_RATES_CHANGED
))
1369 schedule_work(&ista
->rc_update_work
);
1372 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
,
1373 struct ieee80211_vif
*vif
,
1374 unsigned int link_id
, u16 queue
,
1375 const struct ieee80211_tx_queue_params
*params
)
1377 struct ath9k_htc_priv
*priv
= hw
->priv
;
1378 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1379 struct ath9k_tx_queue_info qi
;
1382 if (queue
>= IEEE80211_NUM_ACS
)
1385 mutex_lock(&priv
->mutex
);
1386 ath9k_htc_ps_wakeup(priv
);
1388 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1390 qi
.tqi_aifs
= params
->aifs
;
1391 qi
.tqi_cwmin
= params
->cw_min
;
1392 qi
.tqi_cwmax
= params
->cw_max
;
1393 qi
.tqi_burstTime
= params
->txop
* 32;
1395 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1397 ath_dbg(common
, CONFIG
,
1398 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1399 queue
, qnum
, params
->aifs
, params
->cw_min
,
1400 params
->cw_max
, params
->txop
);
1402 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1404 ath_err(common
, "TXQ Update failed\n");
1408 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1409 (qnum
== priv
->hwq_map
[IEEE80211_AC_BE
]))
1410 ath9k_htc_beaconq_config(priv
);
1412 ath9k_htc_ps_restore(priv
);
1413 mutex_unlock(&priv
->mutex
);
1418 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1419 enum set_key_cmd cmd
,
1420 struct ieee80211_vif
*vif
,
1421 struct ieee80211_sta
*sta
,
1422 struct ieee80211_key_conf
*key
)
1424 struct ath9k_htc_priv
*priv
= hw
->priv
;
1425 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1428 if (htc_modparam_nohwcrypt
)
1431 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1432 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1433 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1434 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1435 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1437 * For now, disable hw crypto for the RSN IBSS group keys. This
1438 * could be optimized in the future to use a modified key cache
1439 * design to support per-STA RX GTK, but until that gets
1440 * implemented, use of software crypto for group addressed
1441 * frames is a acceptable to allow RSN IBSS to be used.
1446 mutex_lock(&priv
->mutex
);
1447 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1448 ath9k_htc_ps_wakeup(priv
);
1452 ret
= ath_key_config(common
, vif
, sta
, key
);
1454 key
->hw_key_idx
= ret
;
1455 /* push IV and Michael MIC generation to stack */
1456 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1457 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1458 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1459 if (priv
->ah
->sw_mgmt_crypto_tx
&&
1460 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1461 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1466 ath_key_delete(common
, key
->hw_key_idx
);
1472 ath9k_htc_ps_restore(priv
);
1473 mutex_unlock(&priv
->mutex
);
1478 static void ath9k_htc_set_bssid(struct ath9k_htc_priv
*priv
)
1480 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1482 ath9k_hw_write_associd(priv
->ah
);
1483 ath_dbg(common
, CONFIG
, "BSSID: %pM aid: 0x%x\n",
1484 common
->curbssid
, common
->curaid
);
1487 static void ath9k_htc_bss_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1489 struct ath9k_htc_priv
*priv
= data
;
1490 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1491 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1493 if ((vif
->type
== NL80211_IFTYPE_STATION
) && vif
->cfg
.assoc
) {
1494 common
->curaid
= vif
->cfg
.aid
;
1495 common
->last_rssi
= ATH_RSSI_DUMMY_MARKER
;
1496 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1497 set_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1501 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv
*priv
)
1503 if (priv
->num_sta_assoc_vif
== 1) {
1504 ieee80211_iterate_active_interfaces_atomic(
1505 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1506 ath9k_htc_bss_iter
, priv
);
1507 ath9k_htc_set_bssid(priv
);
1511 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1512 struct ieee80211_vif
*vif
,
1513 struct ieee80211_bss_conf
*bss_conf
,
1516 struct ath9k_htc_priv
*priv
= hw
->priv
;
1517 struct ath_hw
*ah
= priv
->ah
;
1518 struct ath_common
*common
= ath9k_hw_common(ah
);
1521 mutex_lock(&priv
->mutex
);
1522 ath9k_htc_ps_wakeup(priv
);
1524 if (changed
& BSS_CHANGED_ASSOC
) {
1525 ath_dbg(common
, CONFIG
, "BSS Changed ASSOC %d\n",
1529 priv
->num_sta_assoc_vif
++ : priv
->num_sta_assoc_vif
--;
1531 if (!vif
->cfg
.assoc
)
1532 clear_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1534 if (priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) {
1535 ath9k_htc_choose_set_bssid(priv
);
1536 if (vif
->cfg
.assoc
&& (priv
->num_sta_assoc_vif
== 1))
1537 ath9k_htc_start_ani(priv
);
1538 else if (priv
->num_sta_assoc_vif
== 0)
1539 ath9k_htc_stop_ani(priv
);
1543 if (changed
& BSS_CHANGED_IBSS
) {
1544 if (priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
1545 common
->curaid
= vif
->cfg
.aid
;
1546 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1547 ath9k_htc_set_bssid(priv
);
1551 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1552 ath_dbg(common
, CONFIG
, "Beacon enabled for BSS: %pM\n",
1554 ath9k_htc_set_tsfadjust(priv
, vif
);
1555 priv
->cur_beacon_conf
.enable_beacon
= 1;
1556 ath9k_htc_beacon_config(priv
, vif
);
1559 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1561 * Disable SWBA interrupt only if there are no
1562 * concurrent AP/mesh or IBSS interfaces.
1564 if ((priv
->num_ap_vif
+ priv
->num_mbss_vif
<= 1) ||
1565 priv
->num_ibss_vif
) {
1566 ath_dbg(common
, CONFIG
,
1567 "Beacon disabled for BSS: %pM\n",
1569 priv
->cur_beacon_conf
.enable_beacon
= 0;
1570 ath9k_htc_beacon_config(priv
, vif
);
1574 if (changed
& BSS_CHANGED_BEACON_INT
) {
1576 * Reset the HW TSF for the first AP or mesh interface.
1578 if (priv
->nvifs
== 1 &&
1579 ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
&&
1580 vif
->type
== NL80211_IFTYPE_AP
&&
1581 priv
->num_ap_vif
== 1) ||
1582 (priv
->ah
->opmode
== NL80211_IFTYPE_MESH_POINT
&&
1583 vif
->type
== NL80211_IFTYPE_MESH_POINT
&&
1584 priv
->num_mbss_vif
== 1))) {
1585 set_bit(OP_TSF_RESET
, &priv
->op_flags
);
1587 ath_dbg(common
, CONFIG
,
1588 "Beacon interval changed for BSS: %pM\n",
1590 ath9k_htc_beacon_config(priv
, vif
);
1593 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1594 if (bss_conf
->use_short_slot
)
1598 if (vif
->type
== NL80211_IFTYPE_AP
) {
1600 * Defer update, so that connected stations can adjust
1601 * their settings at the same time.
1602 * See beacon.c for more details
1604 priv
->beacon
.slottime
= slottime
;
1605 priv
->beacon
.updateslot
= UPDATE
;
1607 ah
->slottime
= slottime
;
1608 ath9k_hw_init_global_settings(ah
);
1612 if (changed
& BSS_CHANGED_HT
)
1613 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1615 ath9k_htc_ps_restore(priv
);
1616 mutex_unlock(&priv
->mutex
);
1619 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
,
1620 struct ieee80211_vif
*vif
)
1622 struct ath9k_htc_priv
*priv
= hw
->priv
;
1625 mutex_lock(&priv
->mutex
);
1626 ath9k_htc_ps_wakeup(priv
);
1627 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1628 ath9k_htc_ps_restore(priv
);
1629 mutex_unlock(&priv
->mutex
);
1634 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
,
1635 struct ieee80211_vif
*vif
, u64 tsf
)
1637 struct ath9k_htc_priv
*priv
= hw
->priv
;
1639 mutex_lock(&priv
->mutex
);
1640 ath9k_htc_ps_wakeup(priv
);
1641 ath9k_hw_settsf64(priv
->ah
, tsf
);
1642 ath9k_htc_ps_restore(priv
);
1643 mutex_unlock(&priv
->mutex
);
1646 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
,
1647 struct ieee80211_vif
*vif
)
1649 struct ath9k_htc_priv
*priv
= hw
->priv
;
1651 mutex_lock(&priv
->mutex
);
1652 ath9k_htc_ps_wakeup(priv
);
1653 ath9k_hw_reset_tsf(priv
->ah
);
1654 ath9k_htc_ps_restore(priv
);
1655 mutex_unlock(&priv
->mutex
);
1658 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1659 struct ieee80211_vif
*vif
,
1660 struct ieee80211_ampdu_params
*params
)
1662 struct ath9k_htc_priv
*priv
= hw
->priv
;
1663 struct ath9k_htc_sta
*ista
;
1665 struct ieee80211_sta
*sta
= params
->sta
;
1666 enum ieee80211_ampdu_mlme_action action
= params
->action
;
1667 u16 tid
= params
->tid
;
1669 mutex_lock(&priv
->mutex
);
1670 ath9k_htc_ps_wakeup(priv
);
1673 case IEEE80211_AMPDU_RX_START
:
1675 case IEEE80211_AMPDU_RX_STOP
:
1677 case IEEE80211_AMPDU_TX_START
:
1678 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1680 ret
= IEEE80211_AMPDU_TX_START_IMMEDIATE
;
1682 case IEEE80211_AMPDU_TX_STOP_CONT
:
1683 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1684 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1685 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1686 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1688 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1689 if (tid
>= ATH9K_HTC_MAX_TID
) {
1693 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1694 spin_lock_bh(&priv
->tx
.tx_lock
);
1695 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1696 spin_unlock_bh(&priv
->tx
.tx_lock
);
1699 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1702 ath9k_htc_ps_restore(priv
);
1703 mutex_unlock(&priv
->mutex
);
1708 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
,
1709 struct ieee80211_vif
*vif
,
1712 struct ath9k_htc_priv
*priv
= hw
->priv
;
1713 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1715 mutex_lock(&priv
->mutex
);
1716 spin_lock_bh(&priv
->beacon_lock
);
1717 set_bit(ATH_OP_SCANNING
, &common
->op_flags
);
1718 spin_unlock_bh(&priv
->beacon_lock
);
1719 cancel_work_sync(&priv
->ps_work
);
1720 ath9k_htc_stop_ani(priv
);
1721 mutex_unlock(&priv
->mutex
);
1724 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
,
1725 struct ieee80211_vif
*vif
)
1727 struct ath9k_htc_priv
*priv
= hw
->priv
;
1728 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1730 mutex_lock(&priv
->mutex
);
1731 spin_lock_bh(&priv
->beacon_lock
);
1732 clear_bit(ATH_OP_SCANNING
, &common
->op_flags
);
1733 spin_unlock_bh(&priv
->beacon_lock
);
1734 ath9k_htc_ps_wakeup(priv
);
1735 ath9k_htc_vif_reconfig(priv
);
1736 ath9k_htc_ps_restore(priv
);
1737 mutex_unlock(&priv
->mutex
);
1740 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1745 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1748 struct ath9k_htc_priv
*priv
= hw
->priv
;
1750 mutex_lock(&priv
->mutex
);
1751 ath9k_htc_ps_wakeup(priv
);
1752 priv
->ah
->coverage_class
= coverage_class
;
1753 ath9k_hw_init_global_settings(priv
->ah
);
1754 ath9k_htc_ps_restore(priv
);
1755 mutex_unlock(&priv
->mutex
);
1759 * Currently, this is used only for selecting the minimum rate
1760 * for management frames, rate selection for data frames remain
1763 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw
*hw
,
1764 struct ieee80211_vif
*vif
,
1765 const struct cfg80211_bitrate_mask
*mask
)
1767 struct ath9k_htc_priv
*priv
= hw
->priv
;
1768 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1769 struct ath9k_htc_target_rate_mask tmask
;
1770 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1774 memset(&tmask
, 0, sizeof(struct ath9k_htc_target_rate_mask
));
1776 tmask
.vif_index
= avp
->index
;
1777 tmask
.band
= NL80211_BAND_2GHZ
;
1778 tmask
.mask
= cpu_to_be32(mask
->control
[NL80211_BAND_2GHZ
].legacy
);
1780 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1783 "Unable to set 2G rate mask for "
1784 "interface at idx: %d\n", avp
->index
);
1788 tmask
.band
= NL80211_BAND_5GHZ
;
1789 tmask
.mask
= cpu_to_be32(mask
->control
[NL80211_BAND_5GHZ
].legacy
);
1791 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1794 "Unable to set 5G rate mask for "
1795 "interface at idx: %d\n", avp
->index
);
1799 ath_dbg(common
, CONFIG
, "Set bitrate masks: 0x%x, 0x%x\n",
1800 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
1801 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
1807 static int ath9k_htc_get_stats(struct ieee80211_hw
*hw
,
1808 struct ieee80211_low_level_stats
*stats
)
1810 struct ath9k_htc_priv
*priv
= hw
->priv
;
1811 struct ath_hw
*ah
= priv
->ah
;
1812 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1814 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1815 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1816 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1817 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1822 struct base_eep_header
*ath9k_htc_get_eeprom_base(struct ath9k_htc_priv
*priv
)
1824 struct base_eep_header
*pBase
= NULL
;
1826 * This can be done since all the 3 EEPROM families have the
1827 * same base header upto a certain point, and we are interested in
1828 * the data only upto that point.
1831 if (AR_SREV_9271(priv
->ah
))
1832 pBase
= (struct base_eep_header
*)
1833 &priv
->ah
->eeprom
.map4k
.baseEepHeader
;
1834 else if (priv
->ah
->hw_version
.usbdev
== AR9280_USB
)
1835 pBase
= (struct base_eep_header
*)
1836 &priv
->ah
->eeprom
.def
.baseEepHeader
;
1837 else if (priv
->ah
->hw_version
.usbdev
== AR9287_USB
)
1838 pBase
= (struct base_eep_header
*)
1839 &priv
->ah
->eeprom
.map9287
.baseEepHeader
;
1844 static int ath9k_htc_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
,
1847 struct ath9k_htc_priv
*priv
= hw
->priv
;
1848 struct base_eep_header
*pBase
= ath9k_htc_get_eeprom_base(priv
);
1850 *tx_ant
= pBase
->txMask
;
1851 *rx_ant
= pBase
->rxMask
;
1859 static void ath9k_htc_channel_switch_beacon(struct ieee80211_hw
*hw
,
1860 struct ieee80211_vif
*vif
,
1861 struct cfg80211_chan_def
*chandef
)
1863 struct ath9k_htc_priv
*priv
= hw
->priv
;
1865 /* mac80211 does not support CSA in multi-if cases (yet) */
1866 if (WARN_ON(priv
->csa_vif
))
1869 priv
->csa_vif
= vif
;
1872 struct ieee80211_ops ath9k_htc_ops
= {
1873 .add_chanctx
= ieee80211_emulate_add_chanctx
,
1874 .remove_chanctx
= ieee80211_emulate_remove_chanctx
,
1875 .change_chanctx
= ieee80211_emulate_change_chanctx
,
1876 .switch_vif_chanctx
= ieee80211_emulate_switch_vif_chanctx
,
1878 .wake_tx_queue
= ieee80211_handle_wake_tx_queue
,
1879 .start
= ath9k_htc_start
,
1880 .stop
= ath9k_htc_stop
,
1881 .add_interface
= ath9k_htc_add_interface
,
1882 .remove_interface
= ath9k_htc_remove_interface
,
1883 .config
= ath9k_htc_config
,
1884 .configure_filter
= ath9k_htc_configure_filter
,
1885 .sta_add
= ath9k_htc_sta_add
,
1886 .sta_remove
= ath9k_htc_sta_remove
,
1887 .conf_tx
= ath9k_htc_conf_tx
,
1888 .link_sta_rc_update
= ath9k_htc_sta_rc_update
,
1889 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1890 .set_key
= ath9k_htc_set_key
,
1891 .get_tsf
= ath9k_htc_get_tsf
,
1892 .set_tsf
= ath9k_htc_set_tsf
,
1893 .reset_tsf
= ath9k_htc_reset_tsf
,
1894 .ampdu_action
= ath9k_htc_ampdu_action
,
1895 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1896 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1897 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1898 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1899 .set_coverage_class
= ath9k_htc_set_coverage_class
,
1900 .set_bitrate_mask
= ath9k_htc_set_bitrate_mask
,
1901 .get_stats
= ath9k_htc_get_stats
,
1902 .get_antenna
= ath9k_htc_get_antenna
,
1903 .channel_switch_beacon
= ath9k_htc_channel_switch_beacon
,
1905 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1906 .get_et_sset_count
= ath9k_htc_get_et_sset_count
,
1907 .get_et_stats
= ath9k_htc_get_et_stats
,
1908 .get_et_strings
= ath9k_htc_get_et_strings
,