Path: blob/main/sys/contrib/dev/broadcom/brcm80211/brcmsmac/stf.c
178665 views
/*1* Copyright (c) 2010 Broadcom Corporation2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY10* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION12* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN13* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*/1516#include <net/mac80211.h>1718#include "types.h"19#include "d11.h"20#include "rate.h"21#include "phy/phy_hal.h"22#include "channel.h"23#include "main.h"24#include "stf.h"25#include "debug.h"2627#define MIN_SPATIAL_EXPANSION 028#define MAX_SPATIAL_EXPANSION 12930#define BRCMS_STF_SS_STBC_RX(wlc) (BRCMS_ISNPHY(wlc->band) && \31NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))3233#define NSTS_1 134#define NSTS_2 235#define NSTS_3 336#define NSTS_4 43738static const u8 txcore_default[5] = {39(0), /* bitmap of the core enabled */40(0x01), /* For Nsts = 1, enable core 1 */41(0x03), /* For Nsts = 2, enable core 1 & 2 */42(0x07), /* For Nsts = 3, enable core 1, 2 & 3 */43(0x0f) /* For Nsts = 4, enable all cores */44};4546static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info *wlc, int val)47{48/* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */49if (BRCMS_STF_SS_STBC_RX(wlc)) {50if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))51return;52}5354if (wlc->pub->up) {55brcms_c_update_beacon(wlc);56brcms_c_update_probe_resp(wlc, true);57}58}5960/*61* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to62* turn on/off txchain.63*/64void brcms_c_tempsense_upd(struct brcms_c_info *wlc)65{66struct brcms_phy_pub *pi = wlc->band->pi;67uint active_chains, txchain;6869/* Check if the chip is too hot. Disable one Tx chain, if it is */70/* high 4 bits are for Rx chain, low 4 bits are for Tx chain */71active_chains = wlc_phy_stf_chain_active_get(pi);72txchain = active_chains & 0xf;7374if (wlc->stf->txchain == wlc->stf->hw_txchain) {75if (txchain && (txchain < wlc->stf->hw_txchain))76/* turn off 1 tx chain */77brcms_c_stf_txchain_set(wlc, txchain, true);78} else if (wlc->stf->txchain < wlc->stf->hw_txchain) {79if (txchain == wlc->stf->hw_txchain)80/* turn back on txchain */81brcms_c_stf_txchain_set(wlc, txchain, true);82}83}8485void86brcms_c_stf_ss_algo_channel_get(struct brcms_c_info *wlc, u16 *ss_algo_channel,87u16 chanspec)88{89struct tx_power power = { };90u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;9192/* Clear previous settings */93*ss_algo_channel = 0;9495if (!wlc->pub->up) {96*ss_algo_channel = (u16) -1;97return;98}99100wlc_phy_txpower_get_current(wlc->band->pi, &power,101CHSPEC_CHANNEL(chanspec));102103siso_mcs_id = (CHSPEC_IS40(chanspec)) ?104WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;105cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?106WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;107stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?108WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;109110/* criteria to choose stf mode */111112/*113* the "+3dbm (12 0.25db units)" is to account for the fact that with114* CDD, tx occurs on both chains115*/116if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))117setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);118else119setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);120121/*122* STBC is ORed into to algo channel as STBC requires per-packet SCB123* capability check so cannot be default mode of operation. One of124* SISO, CDD have to be set125*/126if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))127setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);128}129130static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info *wlc, s32 int_val)131{132if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON))133return false;134135if ((int_val == ON) && (wlc->stf->txstreams == 1))136return false;137138wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;139wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;140141return true;142}143144bool brcms_c_stf_stbc_rx_set(struct brcms_c_info *wlc, s32 int_val)145{146if ((int_val != HT_CAP_RX_STBC_NO)147&& (int_val != HT_CAP_RX_STBC_ONE_STREAM))148return false;149150if (BRCMS_STF_SS_STBC_RX(wlc)) {151if ((int_val != HT_CAP_RX_STBC_NO)152&& (wlc->stf->rxstreams == 1))153return false;154}155156brcms_c_stf_stbc_rx_ht_update(wlc, int_val);157return true;158}159160static int brcms_c_stf_txcore_set(struct brcms_c_info *wlc, u8 Nsts,161u8 core_mask)162{163brcms_dbg_ht(wlc->hw->d11core, "wl%d: Nsts %d core_mask %x\n",164wlc->pub->unit, Nsts, core_mask);165166if (hweight8(core_mask) > wlc->stf->txstreams)167core_mask = 0;168169if ((hweight8(core_mask) == wlc->stf->txstreams) &&170((core_mask & ~wlc->stf->txchain)171|| !(core_mask & wlc->stf->txchain)))172core_mask = wlc->stf->txchain;173174wlc->stf->txcore[Nsts] = core_mask;175/* Nsts = 1..4, txcore index = 1..4 */176if (Nsts == 1) {177/* Needs to update beacon and ucode generated response178* frames when 1 stream core map changed179*/180wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;181brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);182if (wlc->clk) {183brcms_c_suspend_mac_and_wait(wlc);184brcms_c_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);185brcms_c_enable_mac(wlc);186}187}188189return 0;190}191192static int brcms_c_stf_spatial_policy_set(struct brcms_c_info *wlc, int val)193{194int i;195u8 core_mask = 0;196197brcms_dbg_ht(wlc->hw->d11core, "wl%d: val %x\n", wlc->pub->unit,198val);199200wlc->stf->spatial_policy = (s8) val;201for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {202core_mask = (val == MAX_SPATIAL_EXPANSION) ?203wlc->stf->txchain : txcore_default[i];204brcms_c_stf_txcore_set(wlc, (u8) i, core_mask);205}206return 0;207}208209/*210* Centralized txant update function. call it whenever wlc->stf->txant and/or211* wlc->stf->txchain change.212*213* Antennas are controlled by ucode indirectly, which drives PHY or GPIO to214* achieve various tx/rx antenna selection schemes215*216* legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7217* means auto(last rx).218* for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7219* means last rx and do tx-antenna selection for SISO transmissions220* for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7221* means last rx and do tx-antenna selection for SISO transmissions222* for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7223* means both cores active224*/225static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)226{227s8 txant;228229txant = (s8) wlc->stf->txant;230if (BRCMS_PHY_11N_CAP(wlc->band)) {231if (txant == ANT_TX_FORCE_0) {232wlc->stf->phytxant = PHY_TXC_ANT_0;233} else if (txant == ANT_TX_FORCE_1) {234wlc->stf->phytxant = PHY_TXC_ANT_1;235236if (BRCMS_ISNPHY(wlc->band) &&237NREV_GE(wlc->band->phyrev, 3)238&& NREV_LT(wlc->band->phyrev, 7))239wlc->stf->phytxant = PHY_TXC_ANT_2;240} else {241if (BRCMS_ISLCNPHY(wlc->band) ||242BRCMS_ISSSLPNPHY(wlc->band))243wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;244else {245/* catch out of sync wlc->stf->txcore */246WARN_ON(wlc->stf->txchain <= 0);247wlc->stf->phytxant =248wlc->stf->txchain << PHY_TXC_ANT_SHIFT;249}250}251} else {252if (txant == ANT_TX_FORCE_0)253wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;254else if (txant == ANT_TX_FORCE_1)255wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;256else257wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;258}259260brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);261}262263int brcms_c_stf_txchain_set(struct brcms_c_info *wlc, s32 int_val, bool force)264{265u8 txchain = (u8) int_val;266u8 txstreams;267uint i;268269if (wlc->stf->txchain == txchain)270return 0;271272if ((txchain & ~wlc->stf->hw_txchain)273|| !(txchain & wlc->stf->hw_txchain))274return -EINVAL;275276/*277* if nrate override is configured to be non-SISO STF mode, reject278* reducing txchain to 1279*/280txstreams = (u8) hweight8(txchain);281if (txstreams > MAX_STREAMS_SUPPORTED)282return -EINVAL;283284wlc->stf->txchain = txchain;285wlc->stf->txstreams = txstreams;286brcms_c_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);287brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);288brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);289wlc->stf->txant =290(wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;291_brcms_c_stf_phy_txant_upd(wlc);292293wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,294wlc->stf->rxchain);295296for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)297brcms_c_stf_txcore_set(wlc, (u8) i, txcore_default[i]);298299return 0;300}301302/*303* update wlc->stf->ss_opmode which represents the operational stf_ss mode304* we're using305*/306void brcms_c_stf_ss_update(struct brcms_c_info *wlc, struct brcms_band *band)307{308u8 prev_stf_ss;309u8 upd_stf_ss;310311prev_stf_ss = wlc->stf->ss_opmode;312313/*314* NOTE: opmode can only be SISO or CDD as STBC is decided on a315* per-packet basis316*/317if (BRCMS_STBC_CAP_PHY(wlc) &&318wlc->stf->ss_algosel_auto319&& (wlc->stf->ss_algo_channel != (u16) -1)) {320upd_stf_ss = (wlc->stf->txstreams == 1 ||321isset(&wlc->stf->ss_algo_channel,322PHY_TXC1_MODE_SISO)) ?323PHY_TXC1_MODE_SISO : PHY_TXC1_MODE_CDD;324} else {325if (wlc->band != band)326return;327upd_stf_ss = (wlc->stf->txstreams == 1) ?328PHY_TXC1_MODE_SISO : band->band_stf_ss_mode;329}330if (prev_stf_ss != upd_stf_ss) {331wlc->stf->ss_opmode = upd_stf_ss;332brcms_b_band_stf_ss_set(wlc->hw, upd_stf_ss);333}334}335336int brcms_c_stf_attach(struct brcms_c_info *wlc)337{338wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;339wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;340341if (BRCMS_ISNPHY(wlc->band) &&342(wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))343wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =344PHY_TXC1_MODE_CDD;345brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);346brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);347348brcms_c_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);349wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;350wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;351352if (BRCMS_STBC_CAP_PHY(wlc)) {353wlc->stf->ss_algosel_auto = true;354/* Init the default value */355wlc->stf->ss_algo_channel = (u16) -1;356}357return 0;358}359360void brcms_c_stf_detach(struct brcms_c_info *wlc)361{362}363364void brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)365{366_brcms_c_stf_phy_txant_upd(wlc);367}368369void brcms_c_stf_phy_chain_calc(struct brcms_c_info *wlc)370{371struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;372373/* get available rx/tx chains */374wlc->stf->hw_txchain = sprom->txchain;375wlc->stf->hw_rxchain = sprom->rxchain;376377/* these parameter are intended to be used for all PHY types */378if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {379if (BRCMS_ISNPHY(wlc->band))380wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;381else382wlc->stf->hw_txchain = TXCHAIN_DEF;383}384385wlc->stf->txchain = wlc->stf->hw_txchain;386wlc->stf->txstreams = (u8) hweight8(wlc->stf->hw_txchain);387388if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {389if (BRCMS_ISNPHY(wlc->band))390wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;391else392wlc->stf->hw_rxchain = RXCHAIN_DEF;393}394395wlc->stf->rxchain = wlc->stf->hw_rxchain;396wlc->stf->rxstreams = (u8) hweight8(wlc->stf->hw_rxchain);397398/* initialize the txcore table */399memcpy(wlc->stf->txcore, txcore_default, sizeof(wlc->stf->txcore));400401/* default spatial_policy */402wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;403brcms_c_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);404}405406static u16 _brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc,407u32 rspec)408{409u16 phytxant = wlc->stf->phytxant;410411if (rspec_stf(rspec) != PHY_TXC1_MODE_SISO)412phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;413else if (wlc->stf->txant == ANT_TX_DEF)414phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;415phytxant &= PHY_TXC_ANT_MASK;416return phytxant;417}418419u16 brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc, u32 rspec)420{421return _brcms_c_stf_phytxchain_sel(wlc, rspec);422}423424u16 brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info *wlc, u32 rspec)425{426u16 phytxant = wlc->stf->phytxant;427u16 mask = PHY_TXC_ANT_MASK;428429/* for non-siso rates or default setting, use the available chains */430if (BRCMS_ISNPHY(wlc->band)) {431phytxant = _brcms_c_stf_phytxchain_sel(wlc, rspec);432mask = PHY_TXC_HTANT_MASK;433}434phytxant |= phytxant & mask;435return phytxant;436}437438439