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 enum htc_phymode mode
;
31 switch (ichan
->chanmode
) {
34 case CHANNEL_G_HT40PLUS
:
35 case CHANNEL_G_HT40MINUS
:
40 case CHANNEL_A_HT40PLUS
:
41 case CHANNEL_A_HT40MINUS
:
53 bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
54 enum ath9k_power_mode mode
)
58 mutex_lock(&priv
->htc_pm_lock
);
59 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
60 mutex_unlock(&priv
->htc_pm_lock
);
65 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
67 mutex_lock(&priv
->htc_pm_lock
);
68 if (++priv
->ps_usecount
!= 1)
70 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
73 mutex_unlock(&priv
->htc_pm_lock
);
76 void ath9k_htc_ps_restore(struct ath9k_htc_priv
*priv
)
78 mutex_lock(&priv
->htc_pm_lock
);
79 if (--priv
->ps_usecount
!= 0)
83 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
84 else if (priv
->ps_enabled
)
85 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
88 mutex_unlock(&priv
->htc_pm_lock
);
91 void ath9k_ps_work(struct work_struct
*work
)
93 struct ath9k_htc_priv
*priv
=
94 container_of(work
, struct ath9k_htc_priv
,
96 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
98 /* The chip wakes up after receiving the first beacon
99 while network sleep is enabled. For the driver to
100 be in sync with the hw, set the chip to awake and
101 only then set it to sleep.
103 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
106 static void ath9k_htc_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
108 struct ath9k_htc_priv
*priv
= data
;
109 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
111 if ((vif
->type
== NL80211_IFTYPE_AP
) && bss_conf
->enable_beacon
)
112 priv
->reconfig_beacon
= true;
114 if (bss_conf
->assoc
) {
115 priv
->rearm_ani
= true;
116 priv
->reconfig_beacon
= true;
120 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv
*priv
)
122 priv
->rearm_ani
= false;
123 priv
->reconfig_beacon
= false;
125 ieee80211_iterate_active_interfaces_atomic(priv
->hw
,
126 ath9k_htc_vif_iter
, priv
);
128 ath9k_htc_start_ani(priv
);
130 if (priv
->reconfig_beacon
) {
131 ath9k_htc_ps_wakeup(priv
);
132 ath9k_htc_beacon_reconfig(priv
);
133 ath9k_htc_ps_restore(priv
);
137 static void ath9k_htc_bssid_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
139 struct ath9k_vif_iter_data
*iter_data
= data
;
142 for (i
= 0; i
< ETH_ALEN
; i
++)
143 iter_data
->mask
[i
] &= ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
146 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv
*priv
,
147 struct ieee80211_vif
*vif
)
149 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
150 struct ath9k_vif_iter_data iter_data
;
153 * Use the hardware MAC address as reference, the hardware uses it
154 * together with the BSSID mask when matching addresses.
156 iter_data
.hw_macaddr
= common
->macaddr
;
157 memset(&iter_data
.mask
, 0xff, ETH_ALEN
);
160 ath9k_htc_bssid_iter(&iter_data
, vif
->addr
, vif
);
162 /* Get list of all active MAC addresses */
163 ieee80211_iterate_active_interfaces_atomic(priv
->hw
, ath9k_htc_bssid_iter
,
166 memcpy(common
->bssidmask
, iter_data
.mask
, 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
;
177 priv
->ah
->opmode
= NL80211_IFTYPE_STATION
;
179 ath9k_hw_setopmode(priv
->ah
);
182 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
184 struct ath_hw
*ah
= priv
->ah
;
185 struct ath_common
*common
= ath9k_hw_common(ah
);
186 struct ieee80211_channel
*channel
= priv
->hw
->conf
.channel
;
187 struct ath9k_hw_cal_data
*caldata
= NULL
;
188 enum htc_phymode mode
;
193 mutex_lock(&priv
->mutex
);
194 ath9k_htc_ps_wakeup(priv
);
196 ath9k_htc_stop_ani(priv
);
197 ieee80211_stop_queues(priv
->hw
);
199 del_timer_sync(&priv
->tx
.cleanup_timer
);
200 ath9k_htc_tx_drain(priv
);
202 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
203 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
204 WMI_CMD(WMI_STOP_RECV_CMDID
);
206 ath9k_wmi_event_drain(priv
);
208 caldata
= &priv
->caldata
;
209 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
212 "Unable to reset device (%u Mhz) reset status %d\n",
213 channel
->center_freq
, ret
);
216 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
219 WMI_CMD(WMI_START_RECV_CMDID
);
220 ath9k_host_rx_init(priv
);
222 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
223 htc_mode
= cpu_to_be16(mode
);
224 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
226 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
227 htc_start(priv
->htc
);
228 ath9k_htc_vif_reconfig(priv
);
229 ieee80211_wake_queues(priv
->hw
);
231 mod_timer(&priv
->tx
.cleanup_timer
,
232 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
234 ath9k_htc_ps_restore(priv
);
235 mutex_unlock(&priv
->mutex
);
238 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
239 struct ieee80211_hw
*hw
,
240 struct ath9k_channel
*hchan
)
242 struct ath_hw
*ah
= priv
->ah
;
243 struct ath_common
*common
= ath9k_hw_common(ah
);
244 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
246 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
247 struct ath9k_hw_cal_data
*caldata
= NULL
;
248 enum htc_phymode mode
;
253 if (priv
->op_flags
& OP_INVALID
)
256 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
258 ath9k_htc_ps_wakeup(priv
);
260 del_timer_sync(&priv
->tx
.cleanup_timer
);
261 ath9k_htc_tx_drain(priv
);
263 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
264 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
265 WMI_CMD(WMI_STOP_RECV_CMDID
);
267 ath9k_wmi_event_drain(priv
);
269 ath_dbg(common
, CONFIG
,
270 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
271 priv
->ah
->curchan
->channel
,
272 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
276 caldata
= &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 (!(priv
->op_flags
& OP_SCANNING
) &&
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
));
315 ath9k_htc_ps_restore(priv
);
320 * Monitor mode handling is a tad complicated because the firmware requires
321 * an interface to be created exclusively, while mac80211 doesn't associate
322 * an interface with the mode.
324 * So, for now, only one monitor interface can be configured.
326 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
328 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
329 struct ath9k_htc_target_vif hvif
;
333 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
334 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
335 hvif
.index
= priv
->mon_vif_idx
;
336 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
338 ath_err(common
, "Unable to remove monitor interface at idx: %d\n",
343 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
346 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
348 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
349 struct ath9k_htc_target_vif hvif
;
350 struct ath9k_htc_target_sta tsta
;
351 int ret
= 0, sta_idx
;
354 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
355 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
360 sta_idx
= ffz(priv
->sta_slot
);
361 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
369 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
370 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
372 hvif
.opmode
= HTC_M_MONITOR
;
373 hvif
.index
= ffz(priv
->vif_slot
);
375 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
380 * Assign the monitor interface index as a special case here.
381 * This is needed when the interface is brought down.
383 priv
->mon_vif_idx
= hvif
.index
;
384 priv
->vif_slot
|= (1 << hvif
.index
);
387 * Set the hardware mode to monitor only if there are no
391 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
396 * Associate a station with the interface for packet injection.
398 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
400 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
403 tsta
.sta_index
= sta_idx
;
404 tsta
.vif_index
= hvif
.index
;
405 tsta
.maxampdu
= cpu_to_be16(0xffff);
407 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
409 ath_err(common
, "Unable to add station entry for monitor mode\n");
413 priv
->sta_slot
|= (1 << sta_idx
);
415 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
416 priv
->ah
->is_monitoring
= true;
418 ath_dbg(common
, CONFIG
,
419 "Attached a monitor interface at idx: %d, sta idx: %d\n",
420 priv
->mon_vif_idx
, sta_idx
);
426 * Remove the interface from the target.
428 __ath9k_htc_remove_monitor_interface(priv
);
430 ath_dbg(common
, FATAL
, "Unable to attach a monitor interface\n");
435 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
437 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
441 __ath9k_htc_remove_monitor_interface(priv
);
443 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
445 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
447 ath_err(common
, "Unable to remove station entry for monitor mode\n");
451 priv
->sta_slot
&= ~(1 << sta_idx
);
453 priv
->ah
->is_monitoring
= false;
455 ath_dbg(common
, CONFIG
,
456 "Removed a monitor interface at idx: %d, sta idx: %d\n",
457 priv
->mon_vif_idx
, sta_idx
);
462 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
463 struct ieee80211_vif
*vif
,
464 struct ieee80211_sta
*sta
)
466 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
467 struct ath9k_htc_target_sta tsta
;
468 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
469 struct ath9k_htc_sta
*ista
;
474 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
477 sta_idx
= ffz(priv
->sta_slot
);
478 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
481 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
484 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
485 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
486 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
488 ista
->index
= sta_idx
;
490 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
494 tsta
.sta_index
= sta_idx
;
495 tsta
.vif_index
= avp
->index
;
498 tsta
.maxampdu
= cpu_to_be16(0xffff);
500 maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
501 sta
->ht_cap
.ampdu_factor
);
502 tsta
.maxampdu
= cpu_to_be16(maxampdu
);
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
.channel
->band
];
604 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
605 if (sta
->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
->ht_cap
.ht_supported
) {
614 for (i
= 0, j
= 0; i
< 77; i
++) {
615 if (sta
->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
->ht_cap
.mcs
.rx_mask
[1])
624 caps
|= WLAN_RC_DS_FLAG
;
625 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
626 (conf_is_ht40(&priv
->hw
->conf
)))
627 caps
|= WLAN_RC_40_FLAG
;
628 if (conf_is_ht40(&priv
->hw
->conf
) &&
629 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
630 caps
|= WLAN_RC_SGI_FLAG
;
631 else if (conf_is_ht20(&priv
->hw
->conf
) &&
632 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
633 caps
|= WLAN_RC_SGI_FLAG
;
636 trate
->sta_index
= ista
->index
;
638 trate
->capflags
= cpu_to_be32(caps
);
641 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
642 struct ath9k_htc_target_rate
*trate
)
644 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
648 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
651 "Unable to initialize Rate information on target\n");
657 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
658 struct ieee80211_sta
*sta
)
660 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
661 struct ath9k_htc_target_rate trate
;
664 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
665 ath9k_htc_setup_rate(priv
, sta
, &trate
);
666 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
668 ath_dbg(common
, CONFIG
,
669 "Updated target sta: %pM, rate caps: 0x%X\n",
670 sta
->addr
, be32_to_cpu(trate
.capflags
));
673 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
674 struct ieee80211_vif
*vif
,
675 struct ieee80211_bss_conf
*bss_conf
)
677 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
678 struct ath9k_htc_target_rate trate
;
679 struct ieee80211_sta
*sta
;
682 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
685 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
690 ath9k_htc_setup_rate(priv
, sta
, &trate
);
693 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
695 ath_dbg(common
, CONFIG
,
696 "Updated target sta: %pM, rate caps: 0x%X\n",
697 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
700 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
701 struct ieee80211_vif
*vif
,
702 struct ieee80211_sta
*sta
,
703 enum ieee80211_ampdu_mlme_action action
,
706 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
707 struct ath9k_htc_target_aggr aggr
;
708 struct ath9k_htc_sta
*ista
;
712 if (tid
>= ATH9K_HTC_MAX_TID
)
715 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
716 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
718 aggr
.sta_index
= ista
->index
;
719 aggr
.tidno
= tid
& 0xf;
720 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
722 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
724 ath_dbg(common
, CONFIG
,
725 "Unable to %s TX aggregation for (%pM, %d)\n",
726 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
728 ath_dbg(common
, CONFIG
,
729 "%s TX aggregation for (%pM, %d)\n",
730 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
733 spin_lock_bh(&priv
->tx
.tx_lock
);
734 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
735 spin_unlock_bh(&priv
->tx
.tx_lock
);
744 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
746 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
747 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
749 common
->ani
.longcal_timer
= timestamp
;
750 common
->ani
.shortcal_timer
= timestamp
;
751 common
->ani
.checkani_timer
= timestamp
;
753 priv
->op_flags
|= OP_ANI_RUNNING
;
755 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
756 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
759 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
761 cancel_delayed_work_sync(&priv
->ani_work
);
762 priv
->op_flags
&= ~OP_ANI_RUNNING
;
765 void ath9k_htc_ani_work(struct work_struct
*work
)
767 struct ath9k_htc_priv
*priv
=
768 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
769 struct ath_hw
*ah
= priv
->ah
;
770 struct ath_common
*common
= ath9k_hw_common(ah
);
771 bool longcal
= false;
772 bool shortcal
= false;
773 bool aniflag
= false;
774 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
775 u32 cal_interval
, short_cal_interval
;
777 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
778 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
780 /* Only calibrate if awake */
781 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
784 /* Long calibration runs independently of short calibration. */
785 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
787 ath_dbg(common
, ANI
, "longcal @%lu\n", jiffies
);
788 common
->ani
.longcal_timer
= timestamp
;
791 /* Short calibration applies only while caldone is false */
792 if (!common
->ani
.caldone
) {
793 if ((timestamp
- common
->ani
.shortcal_timer
) >=
794 short_cal_interval
) {
796 ath_dbg(common
, ANI
, "shortcal @%lu\n", jiffies
);
797 common
->ani
.shortcal_timer
= timestamp
;
798 common
->ani
.resetcal_timer
= timestamp
;
801 if ((timestamp
- common
->ani
.resetcal_timer
) >=
802 ATH_RESTART_CALINTERVAL
) {
803 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
804 if (common
->ani
.caldone
)
805 common
->ani
.resetcal_timer
= timestamp
;
809 /* Verify whether we must check ANI */
810 if (ah
->config
.enable_ani
&&
811 (timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
813 common
->ani
.checkani_timer
= timestamp
;
816 /* Skip all processing if there's nothing to do. */
817 if (longcal
|| shortcal
|| aniflag
) {
819 ath9k_htc_ps_wakeup(priv
);
821 /* Call ANI routine if necessary */
823 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
825 /* Perform calibration if necessary */
826 if (longcal
|| shortcal
)
827 common
->ani
.caldone
=
828 ath9k_hw_calibrate(ah
, ah
->curchan
,
829 ah
->rxchainmask
, longcal
);
831 ath9k_htc_ps_restore(priv
);
836 * Set timer interval based on previous results.
837 * The interval must be the shortest necessary to satisfy ANI,
838 * short calibration and long calibration.
840 cal_interval
= ATH_LONG_CALINTERVAL
;
841 if (ah
->config
.enable_ani
)
842 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
843 if (!common
->ani
.caldone
)
844 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
846 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
847 msecs_to_jiffies(cal_interval
));
850 /**********************/
851 /* mac80211 Callbacks */
852 /**********************/
854 static void ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
856 struct ieee80211_hdr
*hdr
;
857 struct ath9k_htc_priv
*priv
= hw
->priv
;
858 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
859 int padpos
, padsize
, ret
, slot
;
861 hdr
= (struct ieee80211_hdr
*) skb
->data
;
863 /* Add the padding after the header if this is not already done */
864 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
865 padsize
= padpos
& 3;
866 if (padsize
&& skb
->len
> padpos
) {
867 if (skb_headroom(skb
) < padsize
) {
868 ath_dbg(common
, XMIT
, "No room for padding\n");
871 skb_push(skb
, padsize
);
872 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
875 slot
= ath9k_htc_tx_get_slot(priv
);
877 ath_dbg(common
, XMIT
, "No free TX slot\n");
881 ret
= ath9k_htc_tx_start(priv
, skb
, slot
, false);
883 ath_dbg(common
, XMIT
, "Tx failed\n");
887 ath9k_htc_check_stop_queues(priv
);
892 ath9k_htc_tx_clear_slot(priv
, slot
);
894 dev_kfree_skb_any(skb
);
897 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
899 struct ath9k_htc_priv
*priv
= hw
->priv
;
900 struct ath_hw
*ah
= priv
->ah
;
901 struct ath_common
*common
= ath9k_hw_common(ah
);
902 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
903 struct ath9k_channel
*init_channel
;
905 enum htc_phymode mode
;
909 mutex_lock(&priv
->mutex
);
911 ath_dbg(common
, CONFIG
,
912 "Starting driver with initial channel: %d MHz\n",
913 curchan
->center_freq
);
915 /* Ensure that HW is awake before flushing RX */
916 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
917 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
919 /* setup initial channel */
920 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
922 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
925 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
926 ret
, curchan
->center_freq
);
927 mutex_unlock(&priv
->mutex
);
931 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
934 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
935 htc_mode
= cpu_to_be16(mode
);
936 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
937 WMI_CMD(WMI_ATH_INIT_CMDID
);
938 WMI_CMD(WMI_START_RECV_CMDID
);
940 ath9k_host_rx_init(priv
);
942 ret
= ath9k_htc_update_cap_target(priv
, 0);
944 ath_dbg(common
, CONFIG
,
945 "Failed to update capability in target\n");
947 priv
->op_flags
&= ~OP_INVALID
;
948 htc_start(priv
->htc
);
950 spin_lock_bh(&priv
->tx
.tx_lock
);
951 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
952 spin_unlock_bh(&priv
->tx
.tx_lock
);
954 ieee80211_wake_queues(hw
);
956 mod_timer(&priv
->tx
.cleanup_timer
,
957 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
959 ath9k_htc_start_btcoex(priv
);
961 mutex_unlock(&priv
->mutex
);
966 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
968 struct ath9k_htc_priv
*priv
= hw
->priv
;
969 struct ath_hw
*ah
= priv
->ah
;
970 struct ath_common
*common
= ath9k_hw_common(ah
);
971 int ret
__attribute__ ((unused
));
974 mutex_lock(&priv
->mutex
);
976 if (priv
->op_flags
& OP_INVALID
) {
977 ath_dbg(common
, ANY
, "Device not present\n");
978 mutex_unlock(&priv
->mutex
);
982 ath9k_htc_ps_wakeup(priv
);
984 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
985 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
986 WMI_CMD(WMI_STOP_RECV_CMDID
);
988 tasklet_kill(&priv
->rx_tasklet
);
990 del_timer_sync(&priv
->tx
.cleanup_timer
);
991 ath9k_htc_tx_drain(priv
);
992 ath9k_wmi_event_drain(priv
);
994 mutex_unlock(&priv
->mutex
);
996 /* Cancel all the running timers/work .. */
997 cancel_work_sync(&priv
->fatal_work
);
998 cancel_work_sync(&priv
->ps_work
);
1000 #ifdef CONFIG_MAC80211_LEDS
1001 cancel_work_sync(&priv
->led_work
);
1003 ath9k_htc_stop_ani(priv
);
1005 mutex_lock(&priv
->mutex
);
1007 ath9k_htc_stop_btcoex(priv
);
1009 /* Remove a monitor interface if it's present. */
1010 if (priv
->ah
->is_monitoring
)
1011 ath9k_htc_remove_monitor_interface(priv
);
1013 ath9k_hw_phy_disable(ah
);
1014 ath9k_hw_disable(ah
);
1015 ath9k_htc_ps_restore(priv
);
1016 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1018 priv
->op_flags
|= OP_INVALID
;
1020 ath_dbg(common
, CONFIG
, "Driver halt\n");
1021 mutex_unlock(&priv
->mutex
);
1024 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1025 struct ieee80211_vif
*vif
)
1027 struct ath9k_htc_priv
*priv
= hw
->priv
;
1028 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1029 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1030 struct ath9k_htc_target_vif hvif
;
1034 mutex_lock(&priv
->mutex
);
1036 if (priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) {
1037 mutex_unlock(&priv
->mutex
);
1041 if (priv
->num_ibss_vif
||
1042 (priv
->nvifs
&& vif
->type
== NL80211_IFTYPE_ADHOC
)) {
1043 ath_err(common
, "IBSS coexistence with other modes is not allowed\n");
1044 mutex_unlock(&priv
->mutex
);
1048 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
1049 (vif
->type
== NL80211_IFTYPE_ADHOC
)) &&
1050 ((priv
->num_ap_vif
+ priv
->num_ibss_vif
) >= ATH9K_HTC_MAX_BCN_VIF
)) {
1051 ath_err(common
, "Max. number of beaconing interfaces reached\n");
1052 mutex_unlock(&priv
->mutex
);
1056 ath9k_htc_ps_wakeup(priv
);
1057 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1058 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1060 switch (vif
->type
) {
1061 case NL80211_IFTYPE_STATION
:
1062 hvif
.opmode
= HTC_M_STA
;
1064 case NL80211_IFTYPE_ADHOC
:
1065 hvif
.opmode
= HTC_M_IBSS
;
1067 case NL80211_IFTYPE_AP
:
1068 hvif
.opmode
= HTC_M_HOSTAP
;
1072 "Interface type %d not yet supported\n", vif
->type
);
1077 /* Index starts from zero on the target */
1078 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1079 hvif
.rtsthreshold
= cpu_to_be16(2304);
1080 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1085 * We need a node in target to tx mgmt frames
1086 * before association.
1088 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1090 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1094 ath9k_htc_set_bssid_mask(priv
, vif
);
1096 priv
->vif_slot
|= (1 << avp
->index
);
1099 INC_VIF(priv
, vif
->type
);
1101 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1102 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1103 ath9k_htc_assign_bslot(priv
, vif
);
1105 ath9k_htc_set_opmode(priv
);
1107 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1108 !(priv
->op_flags
& OP_ANI_RUNNING
)) {
1109 ath9k_hw_set_tsfadjust(priv
->ah
, 1);
1110 ath9k_htc_start_ani(priv
);
1113 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d at idx: %d\n",
1114 vif
->type
, avp
->index
);
1117 ath9k_htc_ps_restore(priv
);
1118 mutex_unlock(&priv
->mutex
);
1123 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1124 struct ieee80211_vif
*vif
)
1126 struct ath9k_htc_priv
*priv
= hw
->priv
;
1127 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1128 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1129 struct ath9k_htc_target_vif hvif
;
1133 mutex_lock(&priv
->mutex
);
1134 ath9k_htc_ps_wakeup(priv
);
1136 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1137 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1138 hvif
.index
= avp
->index
;
1139 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1141 ath_err(common
, "Unable to remove interface at idx: %d\n",
1145 priv
->vif_slot
&= ~(1 << avp
->index
);
1147 ath9k_htc_remove_station(priv
, vif
, NULL
);
1149 DEC_VIF(priv
, vif
->type
);
1151 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1152 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1153 ath9k_htc_remove_bslot(priv
, vif
);
1155 ath9k_htc_set_opmode(priv
);
1157 ath9k_htc_set_bssid_mask(priv
, vif
);
1160 * Stop ANI only if there are no associated station interfaces.
1162 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1163 priv
->rearm_ani
= false;
1164 ieee80211_iterate_active_interfaces_atomic(priv
->hw
,
1165 ath9k_htc_vif_iter
, priv
);
1166 if (!priv
->rearm_ani
)
1167 ath9k_htc_stop_ani(priv
);
1170 ath_dbg(common
, CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1172 ath9k_htc_ps_restore(priv
);
1173 mutex_unlock(&priv
->mutex
);
1176 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1178 struct ath9k_htc_priv
*priv
= hw
->priv
;
1179 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1180 struct ieee80211_conf
*conf
= &hw
->conf
;
1182 mutex_lock(&priv
->mutex
);
1184 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1185 bool enable_radio
= false;
1186 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1188 mutex_lock(&priv
->htc_pm_lock
);
1189 if (!idle
&& priv
->ps_idle
)
1190 enable_radio
= true;
1191 priv
->ps_idle
= idle
;
1192 mutex_unlock(&priv
->htc_pm_lock
);
1195 ath_dbg(common
, CONFIG
, "not-idle: enabling radio\n");
1196 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1197 ath9k_htc_radio_enable(hw
);
1202 * Monitor interface should be added before
1203 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1205 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1206 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1207 !priv
->ah
->is_monitoring
)
1208 ath9k_htc_add_monitor_interface(priv
);
1209 else if (priv
->ah
->is_monitoring
)
1210 ath9k_htc_remove_monitor_interface(priv
);
1213 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1214 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1215 int pos
= curchan
->hw_value
;
1217 ath_dbg(common
, CONFIG
, "Set channel: %d MHz\n",
1218 curchan
->center_freq
);
1220 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1222 hw
->conf
.channel_type
);
1224 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1225 ath_err(common
, "Unable to set channel\n");
1226 mutex_unlock(&priv
->mutex
);
1232 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1233 if (conf
->flags
& IEEE80211_CONF_PS
) {
1234 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1235 priv
->ps_enabled
= true;
1237 priv
->ps_enabled
= false;
1238 cancel_work_sync(&priv
->ps_work
);
1239 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1243 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1244 priv
->txpowlimit
= 2 * conf
->power_level
;
1245 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1246 priv
->txpowlimit
, &priv
->curtxpow
);
1249 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1250 mutex_lock(&priv
->htc_pm_lock
);
1251 if (!priv
->ps_idle
) {
1252 mutex_unlock(&priv
->htc_pm_lock
);
1255 mutex_unlock(&priv
->htc_pm_lock
);
1257 ath_dbg(common
, CONFIG
, "idle: disabling radio\n");
1258 ath9k_htc_radio_disable(hw
);
1262 mutex_unlock(&priv
->mutex
);
1266 #define SUPPORTED_FILTERS \
1267 (FIF_PROMISC_IN_BSS | \
1272 FIF_BCN_PRBRESP_PROMISC | \
1276 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1277 unsigned int changed_flags
,
1278 unsigned int *total_flags
,
1281 struct ath9k_htc_priv
*priv
= hw
->priv
;
1284 mutex_lock(&priv
->mutex
);
1285 changed_flags
&= SUPPORTED_FILTERS
;
1286 *total_flags
&= SUPPORTED_FILTERS
;
1288 if (priv
->op_flags
& OP_INVALID
) {
1289 ath_dbg(ath9k_hw_common(priv
->ah
), ANY
,
1290 "Unable to configure filter on invalid state\n");
1291 mutex_unlock(&priv
->mutex
);
1294 ath9k_htc_ps_wakeup(priv
);
1296 priv
->rxfilter
= *total_flags
;
1297 rfilt
= ath9k_htc_calcrxfilter(priv
);
1298 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1300 ath_dbg(ath9k_hw_common(priv
->ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1303 ath9k_htc_ps_restore(priv
);
1304 mutex_unlock(&priv
->mutex
);
1307 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1308 struct ieee80211_vif
*vif
,
1309 struct ieee80211_sta
*sta
)
1311 struct ath9k_htc_priv
*priv
= hw
->priv
;
1314 mutex_lock(&priv
->mutex
);
1315 ath9k_htc_ps_wakeup(priv
);
1316 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1318 ath9k_htc_init_rate(priv
, sta
);
1319 ath9k_htc_ps_restore(priv
);
1320 mutex_unlock(&priv
->mutex
);
1325 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1326 struct ieee80211_vif
*vif
,
1327 struct ieee80211_sta
*sta
)
1329 struct ath9k_htc_priv
*priv
= hw
->priv
;
1330 struct ath9k_htc_sta
*ista
;
1333 mutex_lock(&priv
->mutex
);
1334 ath9k_htc_ps_wakeup(priv
);
1335 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1336 htc_sta_drain(priv
->htc
, ista
->index
);
1337 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1338 ath9k_htc_ps_restore(priv
);
1339 mutex_unlock(&priv
->mutex
);
1344 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
,
1345 struct ieee80211_vif
*vif
, u16 queue
,
1346 const struct ieee80211_tx_queue_params
*params
)
1348 struct ath9k_htc_priv
*priv
= hw
->priv
;
1349 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1350 struct ath9k_tx_queue_info qi
;
1353 if (queue
>= WME_NUM_AC
)
1356 mutex_lock(&priv
->mutex
);
1357 ath9k_htc_ps_wakeup(priv
);
1359 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1361 qi
.tqi_aifs
= params
->aifs
;
1362 qi
.tqi_cwmin
= params
->cw_min
;
1363 qi
.tqi_cwmax
= params
->cw_max
;
1364 qi
.tqi_burstTime
= params
->txop
;
1366 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1368 ath_dbg(common
, CONFIG
,
1369 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1370 queue
, qnum
, params
->aifs
, params
->cw_min
,
1371 params
->cw_max
, params
->txop
);
1373 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1375 ath_err(common
, "TXQ Update failed\n");
1379 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1380 (qnum
== priv
->hwq_map
[WME_AC_BE
]))
1381 ath9k_htc_beaconq_config(priv
);
1383 ath9k_htc_ps_restore(priv
);
1384 mutex_unlock(&priv
->mutex
);
1389 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1390 enum set_key_cmd cmd
,
1391 struct ieee80211_vif
*vif
,
1392 struct ieee80211_sta
*sta
,
1393 struct ieee80211_key_conf
*key
)
1395 struct ath9k_htc_priv
*priv
= hw
->priv
;
1396 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1399 if (htc_modparam_nohwcrypt
)
1402 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1403 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1404 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1405 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1406 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1408 * For now, disable hw crypto for the RSN IBSS group keys. This
1409 * could be optimized in the future to use a modified key cache
1410 * design to support per-STA RX GTK, but until that gets
1411 * implemented, use of software crypto for group addressed
1412 * frames is a acceptable to allow RSN IBSS to be used.
1417 mutex_lock(&priv
->mutex
);
1418 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1419 ath9k_htc_ps_wakeup(priv
);
1423 ret
= ath_key_config(common
, vif
, sta
, key
);
1425 key
->hw_key_idx
= ret
;
1426 /* push IV and Michael MIC generation to stack */
1427 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1428 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1429 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1430 if (priv
->ah
->sw_mgmt_crypto
&&
1431 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1432 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1437 ath_key_delete(common
, key
);
1443 ath9k_htc_ps_restore(priv
);
1444 mutex_unlock(&priv
->mutex
);
1449 static void ath9k_htc_set_bssid(struct ath9k_htc_priv
*priv
)
1451 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1453 ath9k_hw_write_associd(priv
->ah
);
1454 ath_dbg(common
, CONFIG
, "BSSID: %pM aid: 0x%x\n",
1455 common
->curbssid
, common
->curaid
);
1458 static void ath9k_htc_bss_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1460 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*)data
;
1461 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1462 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1464 if ((vif
->type
== NL80211_IFTYPE_STATION
) && bss_conf
->assoc
) {
1465 common
->curaid
= bss_conf
->aid
;
1466 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1470 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv
*priv
)
1472 if (priv
->num_sta_assoc_vif
== 1) {
1473 ieee80211_iterate_active_interfaces_atomic(priv
->hw
,
1474 ath9k_htc_bss_iter
, priv
);
1475 ath9k_htc_set_bssid(priv
);
1479 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1480 struct ieee80211_vif
*vif
,
1481 struct ieee80211_bss_conf
*bss_conf
,
1484 struct ath9k_htc_priv
*priv
= hw
->priv
;
1485 struct ath_hw
*ah
= priv
->ah
;
1486 struct ath_common
*common
= ath9k_hw_common(ah
);
1488 mutex_lock(&priv
->mutex
);
1489 ath9k_htc_ps_wakeup(priv
);
1491 if (changed
& BSS_CHANGED_ASSOC
) {
1492 ath_dbg(common
, CONFIG
, "BSS Changed ASSOC %d\n",
1496 priv
->num_sta_assoc_vif
++ : priv
->num_sta_assoc_vif
--;
1498 if (priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) {
1499 ath9k_htc_choose_set_bssid(priv
);
1500 if (bss_conf
->assoc
&& (priv
->num_sta_assoc_vif
== 1))
1501 ath9k_htc_start_ani(priv
);
1502 else if (priv
->num_sta_assoc_vif
== 0)
1503 ath9k_htc_stop_ani(priv
);
1507 if (changed
& BSS_CHANGED_IBSS
) {
1508 if (priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
1509 common
->curaid
= bss_conf
->aid
;
1510 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1511 ath9k_htc_set_bssid(priv
);
1515 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1516 ath_dbg(common
, CONFIG
, "Beacon enabled for BSS: %pM\n",
1518 ath9k_htc_set_tsfadjust(priv
, vif
);
1519 priv
->op_flags
|= OP_ENABLE_BEACON
;
1520 ath9k_htc_beacon_config(priv
, vif
);
1523 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1525 * Disable SWBA interrupt only if there are no
1526 * AP/IBSS interfaces.
1528 if ((priv
->num_ap_vif
<= 1) || priv
->num_ibss_vif
) {
1529 ath_dbg(common
, CONFIG
,
1530 "Beacon disabled for BSS: %pM\n",
1532 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1533 ath9k_htc_beacon_config(priv
, vif
);
1537 if (changed
& BSS_CHANGED_BEACON_INT
) {
1539 * Reset the HW TSF for the first AP interface.
1541 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1542 (priv
->nvifs
== 1) &&
1543 (priv
->num_ap_vif
== 1) &&
1544 (vif
->type
== NL80211_IFTYPE_AP
)) {
1545 priv
->op_flags
|= OP_TSF_RESET
;
1547 ath_dbg(common
, CONFIG
,
1548 "Beacon interval changed for BSS: %pM\n",
1550 ath9k_htc_beacon_config(priv
, vif
);
1553 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1554 if (bss_conf
->use_short_slot
)
1559 ath9k_hw_init_global_settings(ah
);
1562 if (changed
& BSS_CHANGED_HT
)
1563 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1565 ath9k_htc_ps_restore(priv
);
1566 mutex_unlock(&priv
->mutex
);
1569 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
,
1570 struct ieee80211_vif
*vif
)
1572 struct ath9k_htc_priv
*priv
= hw
->priv
;
1575 mutex_lock(&priv
->mutex
);
1576 ath9k_htc_ps_wakeup(priv
);
1577 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1578 ath9k_htc_ps_restore(priv
);
1579 mutex_unlock(&priv
->mutex
);
1584 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
,
1585 struct ieee80211_vif
*vif
, u64 tsf
)
1587 struct ath9k_htc_priv
*priv
= hw
->priv
;
1589 mutex_lock(&priv
->mutex
);
1590 ath9k_htc_ps_wakeup(priv
);
1591 ath9k_hw_settsf64(priv
->ah
, tsf
);
1592 ath9k_htc_ps_restore(priv
);
1593 mutex_unlock(&priv
->mutex
);
1596 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
,
1597 struct ieee80211_vif
*vif
)
1599 struct ath9k_htc_priv
*priv
= hw
->priv
;
1601 mutex_lock(&priv
->mutex
);
1602 ath9k_htc_ps_wakeup(priv
);
1603 ath9k_hw_reset_tsf(priv
->ah
);
1604 ath9k_htc_ps_restore(priv
);
1605 mutex_unlock(&priv
->mutex
);
1608 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1609 struct ieee80211_vif
*vif
,
1610 enum ieee80211_ampdu_mlme_action action
,
1611 struct ieee80211_sta
*sta
,
1612 u16 tid
, u16
*ssn
, u8 buf_size
)
1614 struct ath9k_htc_priv
*priv
= hw
->priv
;
1615 struct ath9k_htc_sta
*ista
;
1618 mutex_lock(&priv
->mutex
);
1619 ath9k_htc_ps_wakeup(priv
);
1622 case IEEE80211_AMPDU_RX_START
:
1624 case IEEE80211_AMPDU_RX_STOP
:
1626 case IEEE80211_AMPDU_TX_START
:
1627 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1629 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1631 case IEEE80211_AMPDU_TX_STOP
:
1632 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1633 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1635 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1636 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1637 spin_lock_bh(&priv
->tx
.tx_lock
);
1638 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1639 spin_unlock_bh(&priv
->tx
.tx_lock
);
1642 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1645 ath9k_htc_ps_restore(priv
);
1646 mutex_unlock(&priv
->mutex
);
1651 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1653 struct ath9k_htc_priv
*priv
= hw
->priv
;
1655 mutex_lock(&priv
->mutex
);
1656 spin_lock_bh(&priv
->beacon_lock
);
1657 priv
->op_flags
|= OP_SCANNING
;
1658 spin_unlock_bh(&priv
->beacon_lock
);
1659 cancel_work_sync(&priv
->ps_work
);
1660 ath9k_htc_stop_ani(priv
);
1661 mutex_unlock(&priv
->mutex
);
1664 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1666 struct ath9k_htc_priv
*priv
= hw
->priv
;
1668 mutex_lock(&priv
->mutex
);
1669 spin_lock_bh(&priv
->beacon_lock
);
1670 priv
->op_flags
&= ~OP_SCANNING
;
1671 spin_unlock_bh(&priv
->beacon_lock
);
1672 ath9k_htc_ps_wakeup(priv
);
1673 ath9k_htc_vif_reconfig(priv
);
1674 ath9k_htc_ps_restore(priv
);
1675 mutex_unlock(&priv
->mutex
);
1678 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1683 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1686 struct ath9k_htc_priv
*priv
= hw
->priv
;
1688 mutex_lock(&priv
->mutex
);
1689 ath9k_htc_ps_wakeup(priv
);
1690 priv
->ah
->coverage_class
= coverage_class
;
1691 ath9k_hw_init_global_settings(priv
->ah
);
1692 ath9k_htc_ps_restore(priv
);
1693 mutex_unlock(&priv
->mutex
);
1697 * Currently, this is used only for selecting the minimum rate
1698 * for management frames, rate selection for data frames remain
1701 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw
*hw
,
1702 struct ieee80211_vif
*vif
,
1703 const struct cfg80211_bitrate_mask
*mask
)
1705 struct ath9k_htc_priv
*priv
= hw
->priv
;
1706 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1707 struct ath9k_htc_target_rate_mask tmask
;
1708 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1712 memset(&tmask
, 0, sizeof(struct ath9k_htc_target_rate_mask
));
1714 tmask
.vif_index
= avp
->index
;
1715 tmask
.band
= IEEE80211_BAND_2GHZ
;
1716 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_2GHZ
].legacy
);
1718 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1721 "Unable to set 2G rate mask for "
1722 "interface at idx: %d\n", avp
->index
);
1726 tmask
.band
= IEEE80211_BAND_5GHZ
;
1727 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1729 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1732 "Unable to set 5G rate mask for "
1733 "interface at idx: %d\n", avp
->index
);
1737 ath_dbg(common
, CONFIG
, "Set bitrate masks: 0x%x, 0x%x\n",
1738 mask
->control
[IEEE80211_BAND_2GHZ
].legacy
,
1739 mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1745 static int ath9k_htc_get_stats(struct ieee80211_hw
*hw
,
1746 struct ieee80211_low_level_stats
*stats
)
1748 struct ath9k_htc_priv
*priv
= hw
->priv
;
1749 struct ath_hw
*ah
= priv
->ah
;
1750 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1752 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1753 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1754 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1755 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1760 struct ieee80211_ops ath9k_htc_ops
= {
1762 .start
= ath9k_htc_start
,
1763 .stop
= ath9k_htc_stop
,
1764 .add_interface
= ath9k_htc_add_interface
,
1765 .remove_interface
= ath9k_htc_remove_interface
,
1766 .config
= ath9k_htc_config
,
1767 .configure_filter
= ath9k_htc_configure_filter
,
1768 .sta_add
= ath9k_htc_sta_add
,
1769 .sta_remove
= ath9k_htc_sta_remove
,
1770 .conf_tx
= ath9k_htc_conf_tx
,
1771 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1772 .set_key
= ath9k_htc_set_key
,
1773 .get_tsf
= ath9k_htc_get_tsf
,
1774 .set_tsf
= ath9k_htc_set_tsf
,
1775 .reset_tsf
= ath9k_htc_reset_tsf
,
1776 .ampdu_action
= ath9k_htc_ampdu_action
,
1777 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1778 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1779 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1780 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1781 .set_coverage_class
= ath9k_htc_set_coverage_class
,
1782 .set_bitrate_mask
= ath9k_htc_set_bitrate_mask
,
1783 .get_stats
= ath9k_htc_get_stats
,