2 * Copyright (c) 2010 Broadcom Corporation
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <linux/kernel.h>
25 #include <bcmendian.h>
26 #include <proto/802.11.h>
34 #include <wlc_channel.h>
35 #include <wlc_bsscfg.h>
36 #include <wlc_mac80211.h>
38 #include <wl_export.h>
42 #define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
43 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
45 static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc);
46 static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val);
47 static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 val);
48 static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val);
49 static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val);
51 static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc);
52 static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec);
58 const u8 txcore_default[5] = {
59 (0), /* bitmap of the core enabled */
60 (0x01), /* For Nsts = 1, enable core 1 */
61 (0x03), /* For Nsts = 2, enable core 1 & 2 */
62 (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
63 (0x0f) /* For Nsts = 4, enable all cores */
66 static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val)
68 ASSERT((val == HT_CAP_RX_STBC_NO)
69 || (val == HT_CAP_RX_STBC_ONE_STREAM));
71 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
72 if (WLC_STF_SS_STBC_RX(wlc)) {
73 if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
77 wlc->ht_cap.cap &= ~HT_CAP_RX_STBC_MASK;
78 wlc->ht_cap.cap |= (val << HT_CAP_RX_STBC_SHIFT);
81 wlc_update_beacon(wlc);
82 wlc_update_probe_resp(wlc, TRUE);
86 /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
87 void wlc_tempsense_upd(wlc_info_t *wlc)
89 wlc_phy_t *pi = wlc->band->pi;
90 uint active_chains, txchain;
92 /* Check if the chip is too hot. Disable one Tx chain, if it is */
93 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
94 active_chains = wlc_phy_stf_chain_active_get(pi);
95 txchain = active_chains & 0xf;
97 if (wlc->stf->txchain == wlc->stf->hw_txchain) {
98 if (txchain && (txchain < wlc->stf->hw_txchain)) {
99 /* turn off 1 tx chain */
100 wlc_stf_txchain_set(wlc, txchain, TRUE);
102 } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
103 if (txchain == wlc->stf->hw_txchain) {
104 /* turn back on txchain */
105 wlc_stf_txchain_set(wlc, txchain, TRUE);
111 wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, u16 *ss_algo_channel,
115 u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
117 /* Clear previous settings */
118 *ss_algo_channel = 0;
121 *ss_algo_channel = (u16) -1;
125 wlc_phy_txpower_get_current(wlc->band->pi, &power,
126 CHSPEC_CHANNEL(chanspec));
128 siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
129 WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
130 cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
131 WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
132 stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
133 WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
135 /* criteria to choose stf mode */
137 /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
140 if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
141 setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
143 setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
145 /* STBC is ORed into to algo channel as STBC requires per-packet SCB capability check
146 * so cannot be default mode of operation. One of SISO, CDD have to be set
148 if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
149 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
152 static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc)
154 return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT;
157 static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val)
159 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
163 if ((int_val == ON) && (wlc->stf->txstreams == 1))
166 if ((int_val == OFF) || (wlc->stf->txstreams == 1)
167 || !WLC_STBC_CAP_PHY(wlc))
168 wlc->ht_cap.cap &= ~HT_CAP_TX_STBC;
170 wlc->ht_cap.cap |= HT_CAP_TX_STBC;
172 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
173 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
178 bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val)
180 if ((int_val != HT_CAP_RX_STBC_NO)
181 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
185 if (WLC_STF_SS_STBC_RX(wlc)) {
186 if ((int_val != HT_CAP_RX_STBC_NO)
187 && (wlc->stf->rxstreams == 1))
191 wlc_stf_stbc_rx_ht_update(wlc, int_val);
195 static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask)
197 WL_TRACE(("wl%d: %s: Nsts %d core_mask %x\n",
198 wlc->pub->unit, __func__, Nsts, core_mask));
200 ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED));
202 if (WLC_BITSCNT(core_mask) > wlc->stf->txstreams) {
206 if ((WLC_BITSCNT(core_mask) == wlc->stf->txstreams) &&
207 ((core_mask & ~wlc->stf->txchain)
208 || !(core_mask & wlc->stf->txchain))) {
209 core_mask = wlc->stf->txchain;
212 ASSERT(!core_mask || Nsts <= WLC_BITSCNT(core_mask));
214 wlc->stf->txcore[Nsts] = core_mask;
215 /* Nsts = 1..4, txcore index = 1..4 */
217 /* Needs to update beacon and ucode generated response
218 * frames when 1 stream core map changed
220 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
221 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
223 wlc_suspend_mac_and_wait(wlc);
224 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
232 static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val)
237 WL_TRACE(("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val));
239 wlc->stf->spatial_policy = (s8) val;
240 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
241 core_mask = (val == MAX_SPATIAL_EXPANSION) ?
242 wlc->stf->txchain : txcore_default[i];
243 wlc_stf_txcore_set(wlc, (u8) i, core_mask);
248 int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force)
250 u8 txchain = (u8) int_val;
254 if (wlc->stf->txchain == txchain)
257 if ((txchain & ~wlc->stf->hw_txchain)
258 || !(txchain & wlc->stf->hw_txchain))
261 /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
262 txstreams = (u8) WLC_BITSCNT(txchain);
263 if (txstreams > MAX_STREAMS_SUPPORTED)
266 if (txstreams == 1) {
267 for (i = 0; i < NBANDS(wlc); i++)
268 if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) !=
270 || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) !=
271 PHY_TXC1_MODE_SISO)) {
275 /* over-write the override rspec */
276 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
277 != PHY_TXC1_MODE_SISO) {
278 wlc->bandstate[i]->rspec_override = 0;
279 WL_ERROR(("%s(): temp sense override non-SISO" " rspec_override.\n", __func__));
282 (wlc->bandstate[i]->mrspec_override) !=
283 PHY_TXC1_MODE_SISO) {
284 wlc->bandstate[i]->mrspec_override = 0;
285 WL_ERROR(("%s(): temp sense override non-SISO" " mrspec_override.\n", __func__));
290 wlc->stf->txchain = txchain;
291 wlc->stf->txstreams = txstreams;
292 wlc_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
293 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
294 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
296 (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
297 _wlc_stf_phy_txant_upd(wlc);
299 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
302 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
303 wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
308 int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val)
311 u8 rxchain = (u8) int_val;
313 u8 old_rxchain, old_rxchain_cnt;
315 if (wlc->stf->rxchain == rxchain)
318 if ((rxchain & ~wlc->stf->hw_rxchain)
319 || !(rxchain & wlc->stf->hw_rxchain))
322 rxchain_cnt = (u8) WLC_BITSCNT(rxchain);
323 if (WLC_STF_SS_STBC_RX(wlc)) {
324 if ((rxchain_cnt == 1)
325 && (wlc_stf_stbc_rx_get(wlc) != HT_CAP_RX_STBC_NO))
329 if (APSTA_ENAB(wlc->pub) && (wlc->pub->associated))
330 return BCME_ASSOCIATED;
332 old_rxchain = wlc->stf->rxchain;
333 old_rxchain_cnt = wlc->stf->rxstreams;
335 wlc->stf->rxchain = rxchain;
336 wlc->stf->rxstreams = rxchain_cnt;
338 if (rxchain_cnt != old_rxchain_cnt) {
340 (rxchain_cnt == 1) ? HT_CAP_MIMO_PS_ON : HT_CAP_MIMO_PS_OFF;
341 wlc->mimops_PM = mimops_mode;
342 if (AP_ENAB(wlc->pub)) {
343 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
345 wlc_ht_mimops_cap_update(wlc, mimops_mode);
346 if (wlc->pub->associated)
347 wlc_mimops_action_ht_send(wlc, wlc->cfg,
351 if (wlc->pub->associated) {
352 if (mimops_mode == HT_CAP_MIMO_PS_OFF) {
353 /* if mimops is off, turn on the Rx chain first */
354 wlc_phy_stf_chain_set(wlc->band->pi,
357 wlc_ht_mimops_cap_update(wlc, mimops_mode);
360 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
362 wlc_ht_mimops_cap_update(wlc, mimops_mode);
364 } else if (old_rxchain != rxchain)
365 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
371 /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
372 int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band)
378 prev_stf_ss = wlc->stf->ss_opmode;
380 /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
381 if (WLC_STBC_CAP_PHY(wlc) &&
382 wlc->stf->ss_algosel_auto
383 && (wlc->stf->ss_algo_channel != (u16) -1)) {
384 ASSERT(isset(&wlc->stf->ss_algo_channel, PHY_TXC1_MODE_CDD)
385 || isset(&wlc->stf->ss_algo_channel,
386 PHY_TXC1_MODE_SISO));
387 upd_stf_ss = (wlc->stf->no_cddstbc || (wlc->stf->txstreams == 1)
388 || isset(&wlc->stf->ss_algo_channel,
389 PHY_TXC1_MODE_SISO)) ? PHY_TXC1_MODE_SISO
392 if (wlc->band != band)
394 upd_stf_ss = (wlc->stf->no_cddstbc
395 || (wlc->stf->txstreams ==
396 1)) ? PHY_TXC1_MODE_SISO : band->
399 if (prev_stf_ss != upd_stf_ss) {
400 wlc->stf->ss_opmode = upd_stf_ss;
401 wlc_bmac_band_stf_ss_set(wlc->hw, upd_stf_ss);
407 int BCMATTACHFN(wlc_stf_attach) (wlc_info_t *wlc)
409 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
410 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
412 if (WLCISNPHY(wlc->band) &&
413 (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
414 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
416 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
417 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
419 wlc_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
420 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
421 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
423 if (WLC_STBC_CAP_PHY(wlc)) {
424 wlc->stf->ss_algosel_auto = TRUE;
425 wlc->stf->ss_algo_channel = (u16) -1; /* Init the default value */
430 void BCMATTACHFN(wlc_stf_detach) (wlc_info_t *wlc)
434 int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val)
436 int bcmerror = BCME_OK;
438 /* when there is only 1 tx_streams, don't allow to change the txant */
439 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
440 return ((val == wlc->stf->txant) ? bcmerror : BCME_RANGE);
447 val = ANT_TX_FORCE_0;
450 val = ANT_TX_FORCE_1;
453 val = ANT_TX_LAST_RX;
456 bcmerror = BCME_RANGE;
460 if (bcmerror == BCME_OK)
461 wlc->stf->txant = (s8) val;
468 * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
471 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
472 * achieve various tx/rx antenna selection schemes
474 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
475 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
476 * do tx-antenna selection for SISO transmissions
477 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
478 * do tx-antenna selection for SISO transmissions
479 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
481 static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc)
485 txant = (s8) wlc->stf->txant;
486 ASSERT(txant == ANT_TX_FORCE_0 || txant == ANT_TX_FORCE_1
487 || txant == ANT_TX_LAST_RX);
489 if (WLC_PHY_11N_CAP(wlc->band)) {
490 if (txant == ANT_TX_FORCE_0) {
491 wlc->stf->phytxant = PHY_TXC_ANT_0;
492 } else if (txant == ANT_TX_FORCE_1) {
493 wlc->stf->phytxant = PHY_TXC_ANT_1;
495 if (WLCISNPHY(wlc->band) &&
496 NREV_GE(wlc->band->phyrev, 3)
497 && NREV_LT(wlc->band->phyrev, 7)) {
498 wlc->stf->phytxant = PHY_TXC_ANT_2;
501 if (WLCISLCNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band))
502 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
504 /* keep this assert to catch out of sync wlc->stf->txcore */
505 ASSERT(wlc->stf->txchain > 0);
507 wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
511 if (txant == ANT_TX_FORCE_0)
512 wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
513 else if (txant == ANT_TX_FORCE_1)
514 wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
516 wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
519 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
522 void wlc_stf_phy_txant_upd(wlc_info_t *wlc)
524 _wlc_stf_phy_txant_upd(wlc);
527 void BCMATTACHFN(wlc_stf_phy_chain_calc) (wlc_info_t *wlc)
529 /* get available rx/tx chains */
530 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
531 wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain");
533 /* these parameter are intended to be used for all PHY types */
534 if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
535 if (WLCISNPHY(wlc->band)) {
536 wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
538 wlc->stf->hw_txchain = TXCHAIN_DEF;
542 wlc->stf->txchain = wlc->stf->hw_txchain;
543 wlc->stf->txstreams = (u8) WLC_BITSCNT(wlc->stf->hw_txchain);
545 if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
546 if (WLCISNPHY(wlc->band)) {
547 wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
549 wlc->stf->hw_rxchain = RXCHAIN_DEF;
553 wlc->stf->rxchain = wlc->stf->hw_rxchain;
554 wlc->stf->rxstreams = (u8) WLC_BITSCNT(wlc->stf->hw_rxchain);
556 /* initialize the txcore table */
557 bcopy(txcore_default, wlc->stf->txcore, sizeof(wlc->stf->txcore));
559 /* default spatial_policy */
560 wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
561 wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
564 static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
566 u16 phytxant = wlc->stf->phytxant;
568 if (RSPEC_STF(rspec) != PHY_TXC1_MODE_SISO) {
569 ASSERT(wlc->stf->txstreams > 1);
570 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
571 } else if (wlc->stf->txant == ANT_TX_DEF)
572 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
573 phytxant &= PHY_TXC_ANT_MASK;
577 u16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
579 return _wlc_stf_phytxchain_sel(wlc, rspec);
582 u16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec)
584 u16 phytxant = wlc->stf->phytxant;
585 u16 mask = PHY_TXC_ANT_MASK;
587 /* for non-siso rates or default setting, use the available chains */
588 if (WLCISNPHY(wlc->band)) {
589 ASSERT(wlc->stf->txchain != 0);
590 phytxant = _wlc_stf_phytxchain_sel(wlc, rspec);
591 mask = PHY_TXC_HTANT_MASK;
593 phytxant |= phytxant & mask;