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
)
80 mutex_lock(&priv
->htc_pm_lock
);
81 if (--priv
->ps_usecount
!= 0)
85 ath9k_hw_setrxabort(priv
->ah
, true);
86 ath9k_hw_stopdmarecv(priv
->ah
, &reset
);
87 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
88 } else if (priv
->ps_enabled
) {
89 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
93 mutex_unlock(&priv
->htc_pm_lock
);
96 void ath9k_ps_work(struct work_struct
*work
)
98 struct ath9k_htc_priv
*priv
=
99 container_of(work
, struct ath9k_htc_priv
,
101 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
103 /* The chip wakes up after receiving the first beacon
104 while network sleep is enabled. For the driver to
105 be in sync with the hw, set the chip to awake and
106 only then set it to sleep.
108 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
111 static void ath9k_htc_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
113 struct ath9k_htc_priv
*priv
= data
;
114 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
116 if ((vif
->type
== NL80211_IFTYPE_AP
||
117 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
118 bss_conf
->enable_beacon
)
119 priv
->reconfig_beacon
= true;
121 if (bss_conf
->assoc
) {
122 priv
->rearm_ani
= true;
123 priv
->reconfig_beacon
= true;
127 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv
*priv
)
129 priv
->rearm_ani
= false;
130 priv
->reconfig_beacon
= false;
132 ieee80211_iterate_active_interfaces_atomic(
133 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
134 ath9k_htc_vif_iter
, priv
);
136 ath9k_htc_start_ani(priv
);
138 if (priv
->reconfig_beacon
) {
139 ath9k_htc_ps_wakeup(priv
);
140 ath9k_htc_beacon_reconfig(priv
);
141 ath9k_htc_ps_restore(priv
);
145 static void ath9k_htc_bssid_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
147 struct ath9k_vif_iter_data
*iter_data
= data
;
150 for (i
= 0; i
< ETH_ALEN
; i
++)
151 iter_data
->mask
[i
] &= ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
154 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv
*priv
,
155 struct ieee80211_vif
*vif
)
157 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
158 struct ath9k_vif_iter_data iter_data
;
161 * Use the hardware MAC address as reference, the hardware uses it
162 * together with the BSSID mask when matching addresses.
164 iter_data
.hw_macaddr
= common
->macaddr
;
165 memset(&iter_data
.mask
, 0xff, ETH_ALEN
);
168 ath9k_htc_bssid_iter(&iter_data
, vif
->addr
, vif
);
170 /* Get list of all active MAC addresses */
171 ieee80211_iterate_active_interfaces_atomic(
172 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
173 ath9k_htc_bssid_iter
, &iter_data
);
175 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
176 ath_hw_setbssidmask(common
);
179 static void ath9k_htc_set_opmode(struct ath9k_htc_priv
*priv
)
181 if (priv
->num_ibss_vif
)
182 priv
->ah
->opmode
= NL80211_IFTYPE_ADHOC
;
183 else if (priv
->num_ap_vif
)
184 priv
->ah
->opmode
= NL80211_IFTYPE_AP
;
185 else if (priv
->num_mbss_vif
)
186 priv
->ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
188 priv
->ah
->opmode
= NL80211_IFTYPE_STATION
;
190 ath9k_hw_setopmode(priv
->ah
);
193 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
195 struct ath_hw
*ah
= priv
->ah
;
196 struct ath_common
*common
= ath9k_hw_common(ah
);
197 struct ieee80211_channel
*channel
= priv
->hw
->conf
.chandef
.chan
;
198 struct ath9k_hw_cal_data
*caldata
= NULL
;
199 enum htc_phymode mode
;
204 mutex_lock(&priv
->mutex
);
205 ath9k_htc_ps_wakeup(priv
);
207 ath9k_htc_stop_ani(priv
);
208 ieee80211_stop_queues(priv
->hw
);
210 del_timer_sync(&priv
->tx
.cleanup_timer
);
211 ath9k_htc_tx_drain(priv
);
213 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
214 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
215 WMI_CMD(WMI_STOP_RECV_CMDID
);
217 ath9k_wmi_event_drain(priv
);
219 caldata
= &priv
->caldata
;
220 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
223 "Unable to reset device (%u Mhz) reset status %d\n",
224 channel
->center_freq
, ret
);
227 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
230 WMI_CMD(WMI_START_RECV_CMDID
);
231 ath9k_host_rx_init(priv
);
233 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
234 htc_mode
= cpu_to_be16(mode
);
235 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
237 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
238 htc_start(priv
->htc
);
239 ath9k_htc_vif_reconfig(priv
);
240 ieee80211_wake_queues(priv
->hw
);
242 mod_timer(&priv
->tx
.cleanup_timer
,
243 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
245 ath9k_htc_ps_restore(priv
);
246 mutex_unlock(&priv
->mutex
);
249 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
250 struct ieee80211_hw
*hw
,
251 struct ath9k_channel
*hchan
)
253 struct ath_hw
*ah
= priv
->ah
;
254 struct ath_common
*common
= ath9k_hw_common(ah
);
255 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
257 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
258 struct ath9k_hw_cal_data
*caldata
= NULL
;
259 enum htc_phymode mode
;
264 if (test_bit(OP_INVALID
, &priv
->op_flags
))
267 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
269 ath9k_htc_ps_wakeup(priv
);
271 del_timer_sync(&priv
->tx
.cleanup_timer
);
272 ath9k_htc_tx_drain(priv
);
274 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
275 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
276 WMI_CMD(WMI_STOP_RECV_CMDID
);
278 ath9k_wmi_event_drain(priv
);
280 ath_dbg(common
, CONFIG
,
281 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
282 priv
->ah
->curchan
->channel
,
283 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
287 caldata
= &priv
->caldata
;
289 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
292 "Unable to reset channel (%u Mhz) reset status %d\n",
293 channel
->center_freq
, ret
);
297 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
300 WMI_CMD(WMI_START_RECV_CMDID
);
304 ath9k_host_rx_init(priv
);
306 mode
= ath9k_htc_get_curmode(priv
, hchan
);
307 htc_mode
= cpu_to_be16(mode
);
308 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
312 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
316 htc_start(priv
->htc
);
318 if (!test_bit(OP_SCANNING
, &priv
->op_flags
) &&
319 !(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
320 ath9k_htc_vif_reconfig(priv
);
322 mod_timer(&priv
->tx
.cleanup_timer
,
323 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
326 ath9k_htc_ps_restore(priv
);
331 * Monitor mode handling is a tad complicated because the firmware requires
332 * an interface to be created exclusively, while mac80211 doesn't associate
333 * an interface with the mode.
335 * So, for now, only one monitor interface can be configured.
337 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
339 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
340 struct ath9k_htc_target_vif hvif
;
344 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
345 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
346 hvif
.index
= priv
->mon_vif_idx
;
347 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
349 ath_err(common
, "Unable to remove monitor interface at idx: %d\n",
354 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
357 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
359 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
360 struct ath9k_htc_target_vif hvif
;
361 struct ath9k_htc_target_sta tsta
;
362 int ret
= 0, sta_idx
;
365 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
366 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
371 sta_idx
= ffz(priv
->sta_slot
);
372 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
380 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
381 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
383 hvif
.opmode
= HTC_M_MONITOR
;
384 hvif
.index
= ffz(priv
->vif_slot
);
386 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
391 * Assign the monitor interface index as a special case here.
392 * This is needed when the interface is brought down.
394 priv
->mon_vif_idx
= hvif
.index
;
395 priv
->vif_slot
|= (1 << hvif
.index
);
398 * Set the hardware mode to monitor only if there are no
402 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
407 * Associate a station with the interface for packet injection.
409 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
411 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
414 tsta
.sta_index
= sta_idx
;
415 tsta
.vif_index
= hvif
.index
;
416 tsta
.maxampdu
= cpu_to_be16(0xffff);
418 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
420 ath_err(common
, "Unable to add station entry for monitor mode\n");
424 priv
->sta_slot
|= (1 << sta_idx
);
426 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
427 priv
->ah
->is_monitoring
= true;
429 ath_dbg(common
, CONFIG
,
430 "Attached a monitor interface at idx: %d, sta idx: %d\n",
431 priv
->mon_vif_idx
, sta_idx
);
437 * Remove the interface from the target.
439 __ath9k_htc_remove_monitor_interface(priv
);
441 ath_dbg(common
, FATAL
, "Unable to attach a monitor interface\n");
446 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
448 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
452 __ath9k_htc_remove_monitor_interface(priv
);
454 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
456 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
458 ath_err(common
, "Unable to remove station entry for monitor mode\n");
462 priv
->sta_slot
&= ~(1 << sta_idx
);
464 priv
->ah
->is_monitoring
= false;
466 ath_dbg(common
, CONFIG
,
467 "Removed a monitor interface at idx: %d, sta idx: %d\n",
468 priv
->mon_vif_idx
, sta_idx
);
473 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
474 struct ieee80211_vif
*vif
,
475 struct ieee80211_sta
*sta
)
477 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
478 struct ath9k_htc_target_sta tsta
;
479 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
480 struct ath9k_htc_sta
*ista
;
485 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
488 sta_idx
= ffz(priv
->sta_slot
);
489 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
492 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
495 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
496 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
497 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
498 ista
->index
= sta_idx
;
500 maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
501 sta
->ht_cap
.ampdu_factor
);
502 tsta
.maxampdu
= cpu_to_be16(maxampdu
);
504 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
506 tsta
.maxampdu
= cpu_to_be16(0xffff);
509 tsta
.sta_index
= sta_idx
;
510 tsta
.vif_index
= avp
->index
;
512 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
516 "Unable to add station entry for: %pM\n",
522 ath_dbg(common
, CONFIG
,
523 "Added a station entry for: %pM (idx: %d)\n",
524 sta
->addr
, tsta
.sta_index
);
526 ath_dbg(common
, CONFIG
,
527 "Added a station entry for VIF %d (idx: %d)\n",
528 avp
->index
, tsta
.sta_index
);
531 priv
->sta_slot
|= (1 << sta_idx
);
534 priv
->vif_sta_pos
[avp
->index
] = sta_idx
;
539 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
540 struct ieee80211_vif
*vif
,
541 struct ieee80211_sta
*sta
)
543 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
544 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
545 struct ath9k_htc_sta
*ista
;
550 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
551 sta_idx
= ista
->index
;
553 sta_idx
= priv
->vif_sta_pos
[avp
->index
];
556 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
560 "Unable to remove station entry for: %pM\n",
566 ath_dbg(common
, CONFIG
,
567 "Removed a station entry for: %pM (idx: %d)\n",
570 ath_dbg(common
, CONFIG
,
571 "Removed a station entry for VIF %d (idx: %d)\n",
572 avp
->index
, sta_idx
);
575 priv
->sta_slot
&= ~(1 << sta_idx
);
581 int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
,
584 struct ath9k_htc_cap_target tcap
;
588 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
590 tcap
.ampdu_limit
= cpu_to_be32(0xffff);
591 tcap
.ampdu_subframes
= 0xff;
592 tcap
.enable_coex
= enable_coex
;
593 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
595 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
600 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
601 struct ieee80211_sta
*sta
,
602 struct ath9k_htc_target_rate
*trate
)
604 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
605 struct ieee80211_supported_band
*sband
;
609 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.chandef
.chan
->band
];
611 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
612 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
613 trate
->rates
.legacy_rates
.rs_rates
[j
]
614 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
618 trate
->rates
.legacy_rates
.rs_nrates
= j
;
620 if (sta
->ht_cap
.ht_supported
) {
621 for (i
= 0, j
= 0; i
< 77; i
++) {
622 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
623 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
624 if (j
== ATH_HTC_RATE_MAX
)
627 trate
->rates
.ht_rates
.rs_nrates
= j
;
629 caps
= WLAN_RC_HT_FLAG
;
630 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_RX_STBC
)
631 caps
|= ATH_RC_TX_STBC_FLAG
;
632 if (sta
->ht_cap
.mcs
.rx_mask
[1])
633 caps
|= WLAN_RC_DS_FLAG
;
634 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
635 (conf_is_ht40(&priv
->hw
->conf
)))
636 caps
|= WLAN_RC_40_FLAG
;
637 if (conf_is_ht40(&priv
->hw
->conf
) &&
638 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
639 caps
|= WLAN_RC_SGI_FLAG
;
640 else if (conf_is_ht20(&priv
->hw
->conf
) &&
641 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
642 caps
|= WLAN_RC_SGI_FLAG
;
645 trate
->sta_index
= ista
->index
;
647 trate
->capflags
= cpu_to_be32(caps
);
650 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
651 struct ath9k_htc_target_rate
*trate
)
653 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
657 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
660 "Unable to initialize Rate information on target\n");
666 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
667 struct ieee80211_sta
*sta
)
669 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
670 struct ath9k_htc_target_rate trate
;
673 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
674 ath9k_htc_setup_rate(priv
, sta
, &trate
);
675 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
677 ath_dbg(common
, CONFIG
,
678 "Updated target sta: %pM, rate caps: 0x%X\n",
679 sta
->addr
, be32_to_cpu(trate
.capflags
));
682 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
683 struct ieee80211_vif
*vif
,
684 struct ieee80211_bss_conf
*bss_conf
)
686 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
687 struct ath9k_htc_target_rate trate
;
688 struct ieee80211_sta
*sta
;
691 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
694 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
699 ath9k_htc_setup_rate(priv
, sta
, &trate
);
702 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
704 ath_dbg(common
, CONFIG
,
705 "Updated target sta: %pM, rate caps: 0x%X\n",
706 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
709 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
710 struct ieee80211_vif
*vif
,
711 struct ieee80211_sta
*sta
,
712 enum ieee80211_ampdu_mlme_action action
,
715 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
716 struct ath9k_htc_target_aggr aggr
;
717 struct ath9k_htc_sta
*ista
;
721 if (tid
>= ATH9K_HTC_MAX_TID
)
724 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
725 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
727 aggr
.sta_index
= ista
->index
;
728 aggr
.tidno
= tid
& 0xf;
729 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
731 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
733 ath_dbg(common
, CONFIG
,
734 "Unable to %s TX aggregation for (%pM, %d)\n",
735 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
737 ath_dbg(common
, CONFIG
,
738 "%s TX aggregation for (%pM, %d)\n",
739 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
742 spin_lock_bh(&priv
->tx
.tx_lock
);
743 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
744 spin_unlock_bh(&priv
->tx
.tx_lock
);
753 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
755 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
756 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
758 common
->ani
.longcal_timer
= timestamp
;
759 common
->ani
.shortcal_timer
= timestamp
;
760 common
->ani
.checkani_timer
= timestamp
;
762 set_bit(OP_ANI_RUNNING
, &priv
->op_flags
);
764 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
765 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
768 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
770 cancel_delayed_work_sync(&priv
->ani_work
);
771 clear_bit(OP_ANI_RUNNING
, &priv
->op_flags
);
774 void ath9k_htc_ani_work(struct work_struct
*work
)
776 struct ath9k_htc_priv
*priv
=
777 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
778 struct ath_hw
*ah
= priv
->ah
;
779 struct ath_common
*common
= ath9k_hw_common(ah
);
780 bool longcal
= false;
781 bool shortcal
= false;
782 bool aniflag
= false;
783 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
784 u32 cal_interval
, short_cal_interval
;
786 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
787 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
789 /* Only calibrate if awake */
790 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
793 /* Long calibration runs independently of short calibration. */
794 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
796 ath_dbg(common
, ANI
, "longcal @%lu\n", jiffies
);
797 common
->ani
.longcal_timer
= timestamp
;
800 /* Short calibration applies only while caldone is false */
801 if (!common
->ani
.caldone
) {
802 if ((timestamp
- common
->ani
.shortcal_timer
) >=
803 short_cal_interval
) {
805 ath_dbg(common
, ANI
, "shortcal @%lu\n", jiffies
);
806 common
->ani
.shortcal_timer
= timestamp
;
807 common
->ani
.resetcal_timer
= timestamp
;
810 if ((timestamp
- common
->ani
.resetcal_timer
) >=
811 ATH_RESTART_CALINTERVAL
) {
812 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
813 if (common
->ani
.caldone
)
814 common
->ani
.resetcal_timer
= timestamp
;
818 /* Verify whether we must check ANI */
819 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
821 common
->ani
.checkani_timer
= timestamp
;
824 /* Skip all processing if there's nothing to do. */
825 if (longcal
|| shortcal
|| aniflag
) {
827 ath9k_htc_ps_wakeup(priv
);
829 /* Call ANI routine if necessary */
831 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
833 /* Perform calibration if necessary */
834 if (longcal
|| shortcal
)
835 common
->ani
.caldone
=
836 ath9k_hw_calibrate(ah
, ah
->curchan
,
837 ah
->rxchainmask
, longcal
);
839 ath9k_htc_ps_restore(priv
);
844 * Set timer interval based on previous results.
845 * The interval must be the shortest necessary to satisfy ANI,
846 * short calibration and long calibration.
848 cal_interval
= ATH_LONG_CALINTERVAL
;
849 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
850 if (!common
->ani
.caldone
)
851 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
853 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
854 msecs_to_jiffies(cal_interval
));
857 /**********************/
858 /* mac80211 Callbacks */
859 /**********************/
861 static void ath9k_htc_tx(struct ieee80211_hw
*hw
,
862 struct ieee80211_tx_control
*control
,
865 struct ieee80211_hdr
*hdr
;
866 struct ath9k_htc_priv
*priv
= hw
->priv
;
867 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
868 int padpos
, padsize
, ret
, slot
;
870 hdr
= (struct ieee80211_hdr
*) skb
->data
;
872 /* Add the padding after the header if this is not already done */
873 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
874 padsize
= padpos
& 3;
875 if (padsize
&& skb
->len
> padpos
) {
876 if (skb_headroom(skb
) < padsize
) {
877 ath_dbg(common
, XMIT
, "No room for padding\n");
880 skb_push(skb
, padsize
);
881 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
884 slot
= ath9k_htc_tx_get_slot(priv
);
886 ath_dbg(common
, XMIT
, "No free TX slot\n");
890 ret
= ath9k_htc_tx_start(priv
, control
->sta
, skb
, slot
, false);
892 ath_dbg(common
, XMIT
, "Tx failed\n");
896 ath9k_htc_check_stop_queues(priv
);
901 ath9k_htc_tx_clear_slot(priv
, slot
);
903 dev_kfree_skb_any(skb
);
906 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
908 struct ath9k_htc_priv
*priv
= hw
->priv
;
909 struct ath_hw
*ah
= priv
->ah
;
910 struct ath_common
*common
= ath9k_hw_common(ah
);
911 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
912 struct ath9k_channel
*init_channel
;
914 enum htc_phymode mode
;
918 mutex_lock(&priv
->mutex
);
920 ath_dbg(common
, CONFIG
,
921 "Starting driver with initial channel: %d MHz\n",
922 curchan
->center_freq
);
924 /* Ensure that HW is awake before flushing RX */
925 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
926 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
928 /* setup initial channel */
929 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
931 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
934 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
935 ret
, curchan
->center_freq
);
936 mutex_unlock(&priv
->mutex
);
940 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
943 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
944 htc_mode
= cpu_to_be16(mode
);
945 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
946 WMI_CMD(WMI_ATH_INIT_CMDID
);
947 WMI_CMD(WMI_START_RECV_CMDID
);
949 ath9k_host_rx_init(priv
);
951 ret
= ath9k_htc_update_cap_target(priv
, 0);
953 ath_dbg(common
, CONFIG
,
954 "Failed to update capability in target\n");
956 clear_bit(OP_INVALID
, &priv
->op_flags
);
957 htc_start(priv
->htc
);
959 spin_lock_bh(&priv
->tx
.tx_lock
);
960 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
961 spin_unlock_bh(&priv
->tx
.tx_lock
);
963 ieee80211_wake_queues(hw
);
965 mod_timer(&priv
->tx
.cleanup_timer
,
966 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
968 ath9k_htc_start_btcoex(priv
);
970 mutex_unlock(&priv
->mutex
);
975 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
977 struct ath9k_htc_priv
*priv
= hw
->priv
;
978 struct ath_hw
*ah
= priv
->ah
;
979 struct ath_common
*common
= ath9k_hw_common(ah
);
980 int ret
__attribute__ ((unused
));
983 mutex_lock(&priv
->mutex
);
985 if (test_bit(OP_INVALID
, &priv
->op_flags
)) {
986 ath_dbg(common
, ANY
, "Device not present\n");
987 mutex_unlock(&priv
->mutex
);
991 ath9k_htc_ps_wakeup(priv
);
993 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
994 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
995 WMI_CMD(WMI_STOP_RECV_CMDID
);
997 tasklet_kill(&priv
->rx_tasklet
);
999 del_timer_sync(&priv
->tx
.cleanup_timer
);
1000 ath9k_htc_tx_drain(priv
);
1001 ath9k_wmi_event_drain(priv
);
1003 mutex_unlock(&priv
->mutex
);
1005 /* Cancel all the running timers/work .. */
1006 cancel_work_sync(&priv
->fatal_work
);
1007 cancel_work_sync(&priv
->ps_work
);
1009 #ifdef CONFIG_MAC80211_LEDS
1010 cancel_work_sync(&priv
->led_work
);
1012 ath9k_htc_stop_ani(priv
);
1014 mutex_lock(&priv
->mutex
);
1016 ath9k_htc_stop_btcoex(priv
);
1018 /* Remove a monitor interface if it's present. */
1019 if (priv
->ah
->is_monitoring
)
1020 ath9k_htc_remove_monitor_interface(priv
);
1022 ath9k_hw_phy_disable(ah
);
1023 ath9k_hw_disable(ah
);
1024 ath9k_htc_ps_restore(priv
);
1025 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1027 set_bit(OP_INVALID
, &priv
->op_flags
);
1029 ath_dbg(common
, CONFIG
, "Driver halt\n");
1030 mutex_unlock(&priv
->mutex
);
1033 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1034 struct ieee80211_vif
*vif
)
1036 struct ath9k_htc_priv
*priv
= hw
->priv
;
1037 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1038 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1039 struct ath9k_htc_target_vif hvif
;
1043 mutex_lock(&priv
->mutex
);
1045 ath9k_htc_ps_wakeup(priv
);
1046 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1047 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1049 switch (vif
->type
) {
1050 case NL80211_IFTYPE_STATION
:
1051 hvif
.opmode
= HTC_M_STA
;
1053 case NL80211_IFTYPE_ADHOC
:
1054 hvif
.opmode
= HTC_M_IBSS
;
1056 case NL80211_IFTYPE_AP
:
1057 hvif
.opmode
= HTC_M_HOSTAP
;
1059 case NL80211_IFTYPE_MESH_POINT
:
1060 hvif
.opmode
= HTC_M_WDS
; /* close enough */
1064 "Interface type %d not yet supported\n", vif
->type
);
1069 /* Index starts from zero on the target */
1070 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1071 hvif
.rtsthreshold
= cpu_to_be16(2304);
1072 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1077 * We need a node in target to tx mgmt frames
1078 * before association.
1080 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1082 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1086 ath9k_htc_set_bssid_mask(priv
, vif
);
1088 priv
->vif_slot
|= (1 << avp
->index
);
1091 INC_VIF(priv
, vif
->type
);
1093 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1094 (vif
->type
== NL80211_IFTYPE_MESH_POINT
) ||
1095 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1096 ath9k_htc_assign_bslot(priv
, vif
);
1098 ath9k_htc_set_opmode(priv
);
1100 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1101 !test_bit(OP_ANI_RUNNING
, &priv
->op_flags
)) {
1102 ath9k_hw_set_tsfadjust(priv
->ah
, true);
1103 ath9k_htc_start_ani(priv
);
1106 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d at idx: %d\n",
1107 vif
->type
, avp
->index
);
1110 ath9k_htc_ps_restore(priv
);
1111 mutex_unlock(&priv
->mutex
);
1116 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1117 struct ieee80211_vif
*vif
)
1119 struct ath9k_htc_priv
*priv
= hw
->priv
;
1120 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1121 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1122 struct ath9k_htc_target_vif hvif
;
1126 mutex_lock(&priv
->mutex
);
1127 ath9k_htc_ps_wakeup(priv
);
1129 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1130 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1131 hvif
.index
= avp
->index
;
1132 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1134 ath_err(common
, "Unable to remove interface at idx: %d\n",
1138 priv
->vif_slot
&= ~(1 << avp
->index
);
1140 ath9k_htc_remove_station(priv
, vif
, NULL
);
1142 DEC_VIF(priv
, vif
->type
);
1144 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1145 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
1146 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1147 ath9k_htc_remove_bslot(priv
, vif
);
1149 ath9k_htc_set_opmode(priv
);
1151 ath9k_htc_set_bssid_mask(priv
, vif
);
1154 * Stop ANI only if there are no associated station interfaces.
1156 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1157 priv
->rearm_ani
= false;
1158 ieee80211_iterate_active_interfaces_atomic(
1159 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1160 ath9k_htc_vif_iter
, priv
);
1161 if (!priv
->rearm_ani
)
1162 ath9k_htc_stop_ani(priv
);
1165 ath_dbg(common
, CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1167 ath9k_htc_ps_restore(priv
);
1168 mutex_unlock(&priv
->mutex
);
1171 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1173 struct ath9k_htc_priv
*priv
= hw
->priv
;
1174 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1175 struct ieee80211_conf
*conf
= &hw
->conf
;
1176 bool chip_reset
= false;
1179 mutex_lock(&priv
->mutex
);
1180 ath9k_htc_ps_wakeup(priv
);
1182 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1183 mutex_lock(&priv
->htc_pm_lock
);
1185 priv
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1189 mutex_unlock(&priv
->htc_pm_lock
);
1193 * Monitor interface should be added before
1194 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1196 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1197 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1198 !priv
->ah
->is_monitoring
)
1199 ath9k_htc_add_monitor_interface(priv
);
1200 else if (priv
->ah
->is_monitoring
)
1201 ath9k_htc_remove_monitor_interface(priv
);
1204 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) || chip_reset
) {
1205 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
1206 enum nl80211_channel_type channel_type
=
1207 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
1208 int pos
= curchan
->hw_value
;
1210 ath_dbg(common
, CONFIG
, "Set channel: %d MHz\n",
1211 curchan
->center_freq
);
1213 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1214 hw
->conf
.chandef
.chan
,
1217 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1218 ath_err(common
, "Unable to set channel\n");
1225 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1226 if (conf
->flags
& IEEE80211_CONF_PS
) {
1227 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1228 priv
->ps_enabled
= true;
1230 priv
->ps_enabled
= false;
1231 cancel_work_sync(&priv
->ps_work
);
1232 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1236 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1237 priv
->txpowlimit
= 2 * conf
->power_level
;
1238 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1239 priv
->txpowlimit
, &priv
->curtxpow
);
1243 ath9k_htc_ps_restore(priv
);
1244 mutex_unlock(&priv
->mutex
);
1248 #define SUPPORTED_FILTERS \
1249 (FIF_PROMISC_IN_BSS | \
1254 FIF_BCN_PRBRESP_PROMISC | \
1258 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1259 unsigned int changed_flags
,
1260 unsigned int *total_flags
,
1263 struct ath9k_htc_priv
*priv
= hw
->priv
;
1266 mutex_lock(&priv
->mutex
);
1267 changed_flags
&= SUPPORTED_FILTERS
;
1268 *total_flags
&= SUPPORTED_FILTERS
;
1270 if (test_bit(OP_INVALID
, &priv
->op_flags
)) {
1271 ath_dbg(ath9k_hw_common(priv
->ah
), ANY
,
1272 "Unable to configure filter on invalid state\n");
1273 mutex_unlock(&priv
->mutex
);
1276 ath9k_htc_ps_wakeup(priv
);
1278 priv
->rxfilter
= *total_flags
;
1279 rfilt
= ath9k_htc_calcrxfilter(priv
);
1280 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1282 ath_dbg(ath9k_hw_common(priv
->ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1285 ath9k_htc_ps_restore(priv
);
1286 mutex_unlock(&priv
->mutex
);
1289 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1290 struct ieee80211_vif
*vif
,
1291 struct ieee80211_sta
*sta
)
1293 struct ath9k_htc_priv
*priv
= hw
->priv
;
1296 mutex_lock(&priv
->mutex
);
1297 ath9k_htc_ps_wakeup(priv
);
1298 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1300 ath9k_htc_init_rate(priv
, sta
);
1301 ath9k_htc_ps_restore(priv
);
1302 mutex_unlock(&priv
->mutex
);
1307 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1308 struct ieee80211_vif
*vif
,
1309 struct ieee80211_sta
*sta
)
1311 struct ath9k_htc_priv
*priv
= hw
->priv
;
1312 struct ath9k_htc_sta
*ista
;
1315 mutex_lock(&priv
->mutex
);
1316 ath9k_htc_ps_wakeup(priv
);
1317 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1318 htc_sta_drain(priv
->htc
, ista
->index
);
1319 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1320 ath9k_htc_ps_restore(priv
);
1321 mutex_unlock(&priv
->mutex
);
1326 static void ath9k_htc_sta_rc_update(struct ieee80211_hw
*hw
,
1327 struct ieee80211_vif
*vif
,
1328 struct ieee80211_sta
*sta
, u32 changed
)
1330 struct ath9k_htc_priv
*priv
= hw
->priv
;
1331 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1332 struct ath9k_htc_target_rate trate
;
1334 mutex_lock(&priv
->mutex
);
1335 ath9k_htc_ps_wakeup(priv
);
1337 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
1338 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
1339 ath9k_htc_setup_rate(priv
, sta
, &trate
);
1340 if (!ath9k_htc_send_rate_cmd(priv
, &trate
))
1341 ath_dbg(common
, CONFIG
,
1342 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1343 sta
->addr
, be32_to_cpu(trate
.capflags
));
1345 ath_dbg(common
, CONFIG
,
1346 "Unable to update supported rates for sta: %pM\n",
1350 ath9k_htc_ps_restore(priv
);
1351 mutex_unlock(&priv
->mutex
);
1354 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
,
1355 struct ieee80211_vif
*vif
, u16 queue
,
1356 const struct ieee80211_tx_queue_params
*params
)
1358 struct ath9k_htc_priv
*priv
= hw
->priv
;
1359 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1360 struct ath9k_tx_queue_info qi
;
1363 if (queue
>= IEEE80211_NUM_ACS
)
1366 mutex_lock(&priv
->mutex
);
1367 ath9k_htc_ps_wakeup(priv
);
1369 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1371 qi
.tqi_aifs
= params
->aifs
;
1372 qi
.tqi_cwmin
= params
->cw_min
;
1373 qi
.tqi_cwmax
= params
->cw_max
;
1374 qi
.tqi_burstTime
= params
->txop
* 32;
1376 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1378 ath_dbg(common
, CONFIG
,
1379 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1380 queue
, qnum
, params
->aifs
, params
->cw_min
,
1381 params
->cw_max
, params
->txop
);
1383 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1385 ath_err(common
, "TXQ Update failed\n");
1389 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1390 (qnum
== priv
->hwq_map
[IEEE80211_AC_BE
]))
1391 ath9k_htc_beaconq_config(priv
);
1393 ath9k_htc_ps_restore(priv
);
1394 mutex_unlock(&priv
->mutex
);
1399 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1400 enum set_key_cmd cmd
,
1401 struct ieee80211_vif
*vif
,
1402 struct ieee80211_sta
*sta
,
1403 struct ieee80211_key_conf
*key
)
1405 struct ath9k_htc_priv
*priv
= hw
->priv
;
1406 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1409 if (htc_modparam_nohwcrypt
)
1412 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1413 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1414 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1415 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1416 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1418 * For now, disable hw crypto for the RSN IBSS group keys. This
1419 * could be optimized in the future to use a modified key cache
1420 * design to support per-STA RX GTK, but until that gets
1421 * implemented, use of software crypto for group addressed
1422 * frames is a acceptable to allow RSN IBSS to be used.
1427 mutex_lock(&priv
->mutex
);
1428 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1429 ath9k_htc_ps_wakeup(priv
);
1433 ret
= ath_key_config(common
, vif
, sta
, key
);
1435 key
->hw_key_idx
= ret
;
1436 /* push IV and Michael MIC generation to stack */
1437 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1438 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1439 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1440 if (priv
->ah
->sw_mgmt_crypto
&&
1441 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1442 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1447 ath_key_delete(common
, key
);
1453 ath9k_htc_ps_restore(priv
);
1454 mutex_unlock(&priv
->mutex
);
1459 static void ath9k_htc_set_bssid(struct ath9k_htc_priv
*priv
)
1461 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1463 ath9k_hw_write_associd(priv
->ah
);
1464 ath_dbg(common
, CONFIG
, "BSSID: %pM aid: 0x%x\n",
1465 common
->curbssid
, common
->curaid
);
1468 static void ath9k_htc_bss_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1470 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*)data
;
1471 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1472 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1474 if ((vif
->type
== NL80211_IFTYPE_STATION
) && bss_conf
->assoc
) {
1475 common
->curaid
= bss_conf
->aid
;
1476 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1480 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv
*priv
)
1482 if (priv
->num_sta_assoc_vif
== 1) {
1483 ieee80211_iterate_active_interfaces_atomic(
1484 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1485 ath9k_htc_bss_iter
, priv
);
1486 ath9k_htc_set_bssid(priv
);
1490 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1491 struct ieee80211_vif
*vif
,
1492 struct ieee80211_bss_conf
*bss_conf
,
1495 struct ath9k_htc_priv
*priv
= hw
->priv
;
1496 struct ath_hw
*ah
= priv
->ah
;
1497 struct ath_common
*common
= ath9k_hw_common(ah
);
1499 mutex_lock(&priv
->mutex
);
1500 ath9k_htc_ps_wakeup(priv
);
1502 if (changed
& BSS_CHANGED_ASSOC
) {
1503 ath_dbg(common
, CONFIG
, "BSS Changed ASSOC %d\n",
1507 priv
->num_sta_assoc_vif
++ : priv
->num_sta_assoc_vif
--;
1509 if (priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) {
1510 ath9k_htc_choose_set_bssid(priv
);
1511 if (bss_conf
->assoc
&& (priv
->num_sta_assoc_vif
== 1))
1512 ath9k_htc_start_ani(priv
);
1513 else if (priv
->num_sta_assoc_vif
== 0)
1514 ath9k_htc_stop_ani(priv
);
1518 if (changed
& BSS_CHANGED_IBSS
) {
1519 if (priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
1520 common
->curaid
= bss_conf
->aid
;
1521 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1522 ath9k_htc_set_bssid(priv
);
1526 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1527 ath_dbg(common
, CONFIG
, "Beacon enabled for BSS: %pM\n",
1529 ath9k_htc_set_tsfadjust(priv
, vif
);
1530 set_bit(OP_ENABLE_BEACON
, &priv
->op_flags
);
1531 ath9k_htc_beacon_config(priv
, vif
);
1534 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1536 * Disable SWBA interrupt only if there are no
1537 * concurrent AP/mesh or IBSS interfaces.
1539 if ((priv
->num_ap_vif
+ priv
->num_mbss_vif
<= 1) ||
1540 priv
->num_ibss_vif
) {
1541 ath_dbg(common
, CONFIG
,
1542 "Beacon disabled for BSS: %pM\n",
1544 clear_bit(OP_ENABLE_BEACON
, &priv
->op_flags
);
1545 ath9k_htc_beacon_config(priv
, vif
);
1549 if (changed
& BSS_CHANGED_BEACON_INT
) {
1551 * Reset the HW TSF for the first AP or mesh interface.
1553 if (priv
->nvifs
== 1 &&
1554 ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
&&
1555 vif
->type
== NL80211_IFTYPE_AP
&&
1556 priv
->num_ap_vif
== 1) ||
1557 (priv
->ah
->opmode
== NL80211_IFTYPE_MESH_POINT
&&
1558 vif
->type
== NL80211_IFTYPE_MESH_POINT
&&
1559 priv
->num_mbss_vif
== 1))) {
1560 set_bit(OP_TSF_RESET
, &priv
->op_flags
);
1562 ath_dbg(common
, CONFIG
,
1563 "Beacon interval changed for BSS: %pM\n",
1565 ath9k_htc_beacon_config(priv
, vif
);
1568 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1569 if (bss_conf
->use_short_slot
)
1574 ath9k_hw_init_global_settings(ah
);
1577 if (changed
& BSS_CHANGED_HT
)
1578 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1580 ath9k_htc_ps_restore(priv
);
1581 mutex_unlock(&priv
->mutex
);
1584 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
,
1585 struct ieee80211_vif
*vif
)
1587 struct ath9k_htc_priv
*priv
= hw
->priv
;
1590 mutex_lock(&priv
->mutex
);
1591 ath9k_htc_ps_wakeup(priv
);
1592 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1593 ath9k_htc_ps_restore(priv
);
1594 mutex_unlock(&priv
->mutex
);
1599 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
,
1600 struct ieee80211_vif
*vif
, u64 tsf
)
1602 struct ath9k_htc_priv
*priv
= hw
->priv
;
1604 mutex_lock(&priv
->mutex
);
1605 ath9k_htc_ps_wakeup(priv
);
1606 ath9k_hw_settsf64(priv
->ah
, tsf
);
1607 ath9k_htc_ps_restore(priv
);
1608 mutex_unlock(&priv
->mutex
);
1611 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
,
1612 struct ieee80211_vif
*vif
)
1614 struct ath9k_htc_priv
*priv
= hw
->priv
;
1616 mutex_lock(&priv
->mutex
);
1617 ath9k_htc_ps_wakeup(priv
);
1618 ath9k_hw_reset_tsf(priv
->ah
);
1619 ath9k_htc_ps_restore(priv
);
1620 mutex_unlock(&priv
->mutex
);
1623 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1624 struct ieee80211_vif
*vif
,
1625 enum ieee80211_ampdu_mlme_action action
,
1626 struct ieee80211_sta
*sta
,
1627 u16 tid
, u16
*ssn
, u8 buf_size
)
1629 struct ath9k_htc_priv
*priv
= hw
->priv
;
1630 struct ath9k_htc_sta
*ista
;
1633 mutex_lock(&priv
->mutex
);
1634 ath9k_htc_ps_wakeup(priv
);
1637 case IEEE80211_AMPDU_RX_START
:
1639 case IEEE80211_AMPDU_RX_STOP
:
1641 case IEEE80211_AMPDU_TX_START
:
1642 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1644 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1646 case IEEE80211_AMPDU_TX_STOP_CONT
:
1647 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1648 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1649 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1650 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1652 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1653 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1654 spin_lock_bh(&priv
->tx
.tx_lock
);
1655 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1656 spin_unlock_bh(&priv
->tx
.tx_lock
);
1659 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1662 ath9k_htc_ps_restore(priv
);
1663 mutex_unlock(&priv
->mutex
);
1668 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1670 struct ath9k_htc_priv
*priv
= hw
->priv
;
1672 mutex_lock(&priv
->mutex
);
1673 spin_lock_bh(&priv
->beacon_lock
);
1674 set_bit(OP_SCANNING
, &priv
->op_flags
);
1675 spin_unlock_bh(&priv
->beacon_lock
);
1676 cancel_work_sync(&priv
->ps_work
);
1677 ath9k_htc_stop_ani(priv
);
1678 mutex_unlock(&priv
->mutex
);
1681 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1683 struct ath9k_htc_priv
*priv
= hw
->priv
;
1685 mutex_lock(&priv
->mutex
);
1686 spin_lock_bh(&priv
->beacon_lock
);
1687 clear_bit(OP_SCANNING
, &priv
->op_flags
);
1688 spin_unlock_bh(&priv
->beacon_lock
);
1689 ath9k_htc_ps_wakeup(priv
);
1690 ath9k_htc_vif_reconfig(priv
);
1691 ath9k_htc_ps_restore(priv
);
1692 mutex_unlock(&priv
->mutex
);
1695 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1700 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1703 struct ath9k_htc_priv
*priv
= hw
->priv
;
1705 mutex_lock(&priv
->mutex
);
1706 ath9k_htc_ps_wakeup(priv
);
1707 priv
->ah
->coverage_class
= coverage_class
;
1708 ath9k_hw_init_global_settings(priv
->ah
);
1709 ath9k_htc_ps_restore(priv
);
1710 mutex_unlock(&priv
->mutex
);
1714 * Currently, this is used only for selecting the minimum rate
1715 * for management frames, rate selection for data frames remain
1718 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw
*hw
,
1719 struct ieee80211_vif
*vif
,
1720 const struct cfg80211_bitrate_mask
*mask
)
1722 struct ath9k_htc_priv
*priv
= hw
->priv
;
1723 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1724 struct ath9k_htc_target_rate_mask tmask
;
1725 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1729 memset(&tmask
, 0, sizeof(struct ath9k_htc_target_rate_mask
));
1731 tmask
.vif_index
= avp
->index
;
1732 tmask
.band
= IEEE80211_BAND_2GHZ
;
1733 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_2GHZ
].legacy
);
1735 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1738 "Unable to set 2G rate mask for "
1739 "interface at idx: %d\n", avp
->index
);
1743 tmask
.band
= IEEE80211_BAND_5GHZ
;
1744 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1746 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1749 "Unable to set 5G rate mask for "
1750 "interface at idx: %d\n", avp
->index
);
1754 ath_dbg(common
, CONFIG
, "Set bitrate masks: 0x%x, 0x%x\n",
1755 mask
->control
[IEEE80211_BAND_2GHZ
].legacy
,
1756 mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1762 static int ath9k_htc_get_stats(struct ieee80211_hw
*hw
,
1763 struct ieee80211_low_level_stats
*stats
)
1765 struct ath9k_htc_priv
*priv
= hw
->priv
;
1766 struct ath_hw
*ah
= priv
->ah
;
1767 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1769 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1770 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1771 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1772 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1777 struct base_eep_header
*ath9k_htc_get_eeprom_base(struct ath9k_htc_priv
*priv
)
1779 struct base_eep_header
*pBase
= NULL
;
1781 * This can be done since all the 3 EEPROM families have the
1782 * same base header upto a certain point, and we are interested in
1783 * the data only upto that point.
1786 if (AR_SREV_9271(priv
->ah
))
1787 pBase
= (struct base_eep_header
*)
1788 &priv
->ah
->eeprom
.map4k
.baseEepHeader
;
1789 else if (priv
->ah
->hw_version
.usbdev
== AR9280_USB
)
1790 pBase
= (struct base_eep_header
*)
1791 &priv
->ah
->eeprom
.def
.baseEepHeader
;
1792 else if (priv
->ah
->hw_version
.usbdev
== AR9287_USB
)
1793 pBase
= (struct base_eep_header
*)
1794 &priv
->ah
->eeprom
.map9287
.baseEepHeader
;
1799 static int ath9k_htc_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
,
1802 struct ath9k_htc_priv
*priv
= hw
->priv
;
1803 struct base_eep_header
*pBase
= ath9k_htc_get_eeprom_base(priv
);
1805 *tx_ant
= pBase
->txMask
;
1806 *rx_ant
= pBase
->rxMask
;
1814 struct ieee80211_ops ath9k_htc_ops
= {
1816 .start
= ath9k_htc_start
,
1817 .stop
= ath9k_htc_stop
,
1818 .add_interface
= ath9k_htc_add_interface
,
1819 .remove_interface
= ath9k_htc_remove_interface
,
1820 .config
= ath9k_htc_config
,
1821 .configure_filter
= ath9k_htc_configure_filter
,
1822 .sta_add
= ath9k_htc_sta_add
,
1823 .sta_remove
= ath9k_htc_sta_remove
,
1824 .conf_tx
= ath9k_htc_conf_tx
,
1825 .sta_rc_update
= ath9k_htc_sta_rc_update
,
1826 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1827 .set_key
= ath9k_htc_set_key
,
1828 .get_tsf
= ath9k_htc_get_tsf
,
1829 .set_tsf
= ath9k_htc_set_tsf
,
1830 .reset_tsf
= ath9k_htc_reset_tsf
,
1831 .ampdu_action
= ath9k_htc_ampdu_action
,
1832 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1833 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1834 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1835 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1836 .set_coverage_class
= ath9k_htc_set_coverage_class
,
1837 .set_bitrate_mask
= ath9k_htc_set_bitrate_mask
,
1838 .get_stats
= ath9k_htc_get_stats
,
1839 .get_antenna
= ath9k_htc_get_antenna
,
1841 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1842 .get_et_sset_count
= ath9k_htc_get_et_sset_count
,
1843 .get_et_stats
= ath9k_htc_get_et_stats
,
1844 .get_et_strings
= ath9k_htc_get_et_strings
,