2024-09-09 08:52:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2011 Atheros Communications Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ath9k.h"
|
|
|
|
#include "mci.h"
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
u8 ath_mci_duty_cycle[] = { 0, 50, 60, 70, 80, 85, 90, 95, 98 };
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
static struct ath_mci_profile_info*
|
|
|
|
ath_mci_find_profile(struct ath_mci_profile *mci,
|
|
|
|
struct ath_mci_profile_info *info)
|
|
|
|
{
|
|
|
|
struct ath_mci_profile_info *entry;
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &mci->info, list) {
|
|
|
|
if (entry->conn_handle == info->conn_handle)
|
2024-09-09 08:57:42 +00:00
|
|
|
break;
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
return entry;
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool ath_mci_add_profile(struct ath_common *common,
|
|
|
|
struct ath_mci_profile *mci,
|
|
|
|
struct ath_mci_profile_info *info)
|
|
|
|
{
|
|
|
|
struct ath_mci_profile_info *entry;
|
|
|
|
|
|
|
|
if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
|
2024-09-09 08:57:42 +00:00
|
|
|
(info->type == MCI_GPM_COEX_PROFILE_VOICE)) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Too many SCO profile, failed to add new profile\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
return false;
|
2024-09-09 08:57:42 +00:00
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) &&
|
2024-09-09 08:57:42 +00:00
|
|
|
(info->type != MCI_GPM_COEX_PROFILE_VOICE)) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Too many ACL profile, failed to add new profile\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
return false;
|
2024-09-09 08:57:42 +00:00
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
entry = ath_mci_find_profile(mci, info);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
if (entry)
|
|
|
|
memcpy(entry, info, 10);
|
|
|
|
else {
|
|
|
|
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
|
|
|
|
if (!entry)
|
|
|
|
return false;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
memcpy(entry, info, 10);
|
|
|
|
INC_PROF(mci, info);
|
|
|
|
list_add_tail(&info->list, &mci->info);
|
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ath_mci_del_profile(struct ath_common *common,
|
|
|
|
struct ath_mci_profile *mci,
|
2024-09-09 08:57:42 +00:00
|
|
|
struct ath_mci_profile_info *info)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
2024-09-09 08:57:42 +00:00
|
|
|
struct ath_mci_profile_info *entry;
|
|
|
|
|
|
|
|
entry = ath_mci_find_profile(mci, info);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
if (!entry) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Profile to be deleted not found\n");
|
|
|
|
return;
|
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
DEC_PROF(mci, entry);
|
|
|
|
list_del(&entry->list);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ath_mci_flush_profile(struct ath_mci_profile *mci)
|
|
|
|
{
|
|
|
|
struct ath_mci_profile_info *info, *tinfo;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(info, tinfo, &mci->info, list) {
|
|
|
|
list_del(&info->list);
|
|
|
|
DEC_PROF(mci, info);
|
|
|
|
kfree(info);
|
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
mci->aggr_limit = 0;
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
|
|
|
|
{
|
|
|
|
struct ath_mci_profile *mci = &btcoex->mci;
|
|
|
|
u32 wlan_airtime = btcoex->btcoex_period *
|
|
|
|
(100 - btcoex->duty_cycle) / 100;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms.
|
|
|
|
* When wlan_airtime is less than 4ms, aggregation limit has to be
|
|
|
|
* adjusted half of wlan_airtime to ensure that the aggregation can fit
|
|
|
|
* without collision with BT traffic.
|
|
|
|
*/
|
|
|
|
if ((wlan_airtime <= 4) &&
|
|
|
|
(!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime))))
|
|
|
|
mci->aggr_limit = 2 * wlan_airtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ath_mci_update_scheme(struct ath_softc *sc)
|
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_mci_profile *mci = &btcoex->mci;
|
|
|
|
struct ath_mci_profile_info *info;
|
|
|
|
u32 num_profile = NUM_PROF(mci);
|
|
|
|
|
|
|
|
if (num_profile == 1) {
|
|
|
|
info = list_first_entry(&mci->info,
|
|
|
|
struct ath_mci_profile_info,
|
|
|
|
list);
|
2024-09-09 08:57:42 +00:00
|
|
|
if (mci->num_sco && info->T == 12) {
|
|
|
|
mci->aggr_limit = 8;
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Single SCO, aggregation limit 2 ms\n");
|
|
|
|
} else if ((info->type == MCI_GPM_COEX_PROFILE_BNEP) &&
|
|
|
|
!info->master) {
|
|
|
|
btcoex->btcoex_period = 60;
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Single slave PAN/FTP, bt period 60 ms\n");
|
|
|
|
} else if ((info->type == MCI_GPM_COEX_PROFILE_HID) &&
|
|
|
|
(info->T > 0 && info->T < 50) &&
|
|
|
|
(info->A > 1 || info->W > 1)) {
|
2024-09-09 08:52:07 +00:00
|
|
|
btcoex->duty_cycle = 30;
|
2024-09-09 08:57:42 +00:00
|
|
|
mci->aggr_limit = 8;
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
2024-09-09 08:52:07 +00:00
|
|
|
"Multiple attempt/timeout single HID "
|
2024-09-09 08:57:42 +00:00
|
|
|
"aggregation limit 2 ms dutycycle 30%%\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
2024-09-09 08:57:42 +00:00
|
|
|
} else if ((num_profile == 2) && (mci->num_hid == 2)) {
|
|
|
|
btcoex->duty_cycle = 30;
|
|
|
|
mci->aggr_limit = 8;
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Two HIDs aggregation limit 2 ms dutycycle 30%%\n");
|
|
|
|
} else if (num_profile > 3) {
|
2024-09-09 08:52:07 +00:00
|
|
|
mci->aggr_limit = 6;
|
2024-09-09 08:57:42 +00:00
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Three or more profiles aggregation limit 1.5 ms\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
|
|
|
|
if (IS_CHAN_HT(sc->sc_ah->curchan))
|
|
|
|
ath_mci_adjust_aggr_limit(btcoex);
|
|
|
|
else
|
|
|
|
btcoex->btcoex_period >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ath9k_hw_btcoex_disable(sc->sc_ah);
|
2024-09-09 08:57:42 +00:00
|
|
|
ath9k_btcoex_timer_pause(sc);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
|
|
|
|
return;
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_MAX_DUTY_CYCLE : 0);
|
2024-09-09 08:52:07 +00:00
|
|
|
if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
|
|
|
|
btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
btcoex->btcoex_period *= 1000;
|
|
|
|
btcoex->btcoex_no_stomp = btcoex->btcoex_period *
|
|
|
|
(100 - btcoex->duty_cycle) / 100;
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
ath9k_hw_btcoex_enable(sc->sc_ah);
|
|
|
|
ath9k_btcoex_timer_resume(sc);
|
|
|
|
}
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
void ath_mci_process_profile(struct ath_softc *sc,
|
|
|
|
struct ath_mci_profile_info *info)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
|
|
|
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
|
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_mci_profile *mci = &btcoex->mci;
|
|
|
|
|
|
|
|
if (info->start) {
|
2024-09-09 08:57:42 +00:00
|
|
|
if (!ath_mci_add_profile(common, mci, info))
|
2024-09-09 08:52:07 +00:00
|
|
|
return;
|
|
|
|
} else
|
2024-09-09 08:57:42 +00:00
|
|
|
ath_mci_del_profile(common, mci, info);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
|
|
|
|
mci->aggr_limit = mci->num_sco ? 6 : 0;
|
2024-09-09 08:57:42 +00:00
|
|
|
if (NUM_PROF(mci)) {
|
2024-09-09 08:52:07 +00:00
|
|
|
btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
|
2024-09-09 08:57:42 +00:00
|
|
|
btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)];
|
|
|
|
} else {
|
2024-09-09 08:52:07 +00:00
|
|
|
btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
|
|
|
|
ATH_BTCOEX_STOMP_LOW;
|
2024-09-09 08:57:42 +00:00
|
|
|
btcoex->duty_cycle = ATH_BTCOEX_DEF_DUTY_CYCLE;
|
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
ath_mci_update_scheme(sc);
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
void ath_mci_process_status(struct ath_softc *sc,
|
|
|
|
struct ath_mci_profile_status *status)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
2024-09-09 08:57:42 +00:00
|
|
|
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
|
2024-09-09 08:52:07 +00:00
|
|
|
struct ath_btcoex *btcoex = &sc->btcoex;
|
|
|
|
struct ath_mci_profile *mci = &btcoex->mci;
|
|
|
|
struct ath_mci_profile_info info;
|
|
|
|
int i = 0, old_num_mgmt = mci->num_mgmt;
|
|
|
|
|
|
|
|
/* Link status type are not handled */
|
2024-09-09 08:57:42 +00:00
|
|
|
if (status->is_link) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Skip link type status update\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
return;
|
2024-09-09 08:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(struct ath_mci_profile_info));
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
info.conn_handle = status->conn_handle;
|
2024-09-09 08:57:42 +00:00
|
|
|
if (ath_mci_find_profile(mci, &info)) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Skip non link state update for existing profile %d\n",
|
|
|
|
status->conn_handle);
|
2024-09-09 08:52:07 +00:00
|
|
|
return;
|
2024-09-09 08:57:42 +00:00
|
|
|
}
|
|
|
|
if (status->conn_handle >= ATH_MCI_MAX_PROFILE) {
|
|
|
|
ath_dbg(common, ATH_DBG_MCI,
|
|
|
|
"Ignore too many non-link update\n");
|
2024-09-09 08:52:07 +00:00
|
|
|
return;
|
2024-09-09 08:57:42 +00:00
|
|
|
}
|
2024-09-09 08:52:07 +00:00
|
|
|
if (status->is_critical)
|
|
|
|
__set_bit(status->conn_handle, mci->status);
|
|
|
|
else
|
|
|
|
__clear_bit(status->conn_handle, mci->status);
|
|
|
|
|
|
|
|
mci->num_mgmt = 0;
|
|
|
|
do {
|
|
|
|
if (test_bit(i, mci->status))
|
|
|
|
mci->num_mgmt++;
|
|
|
|
} while (++i < ATH_MCI_MAX_PROFILE);
|
|
|
|
|
|
|
|
if (old_num_mgmt != mci->num_mgmt)
|
2024-09-09 08:57:42 +00:00
|
|
|
ath_mci_update_scheme(sc);
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|