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.
17 #include <net/mac80211.h>
22 #include "phy/phy_hal.h"
28 #define MIN_SPATIAL_EXPANSION 0
29 #define MAX_SPATIAL_EXPANSION 1
31 #define BRCMS_STF_SS_STBC_RX(wlc) (BRCMS_ISNPHY(wlc->band) && \
32 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
34 static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info *wlc, s32 int_val);
35 static int brcms_c_stf_txcore_set(struct brcms_c_info *wlc, u8 Nsts, u8 val);
36 static int brcms_c_stf_spatial_policy_set(struct brcms_c_info *wlc, int val);
37 static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info *wlc, int val);
39 static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc);
40 static u16 _brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc,
47 const u8 txcore_default[5] = {
48 (0), /* bitmap of the core enabled */
49 (0x01), /* For Nsts = 1, enable core 1 */
50 (0x03), /* For Nsts = 2, enable core 1 & 2 */
51 (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
52 (0x0f) /* For Nsts = 4, enable all cores */
55 static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info *wlc, int val)
57 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
58 if (BRCMS_STF_SS_STBC_RX(wlc)) {
59 if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
63 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_RX_STBC;
64 wlc->ht_cap.cap_info |= (val << IEEE80211_HT_CAP_RX_STBC_SHIFT);
67 brcms_c_update_beacon(wlc);
68 brcms_c_update_probe_resp(wlc, true);
72 /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
73 void brcms_c_tempsense_upd(struct brcms_c_info *wlc)
75 struct brcms_phy_pub *pi = wlc->band->pi;
76 uint active_chains, txchain;
78 /* Check if the chip is too hot. Disable one Tx chain, if it is */
79 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
80 active_chains = wlc_phy_stf_chain_active_get(pi);
81 txchain = active_chains & 0xf;
83 if (wlc->stf->txchain == wlc->stf->hw_txchain) {
84 if (txchain && (txchain < wlc->stf->hw_txchain)) {
85 /* turn off 1 tx chain */
86 brcms_c_stf_txchain_set(wlc, txchain, true);
88 } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
89 if (txchain == wlc->stf->hw_txchain) {
90 /* turn back on txchain */
91 brcms_c_stf_txchain_set(wlc, txchain, true);
97 brcms_c_stf_ss_algo_channel_get(struct brcms_c_info *wlc, u16 *ss_algo_channel,
100 struct tx_power power;
101 u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
103 /* Clear previous settings */
104 *ss_algo_channel = 0;
107 *ss_algo_channel = (u16) -1;
111 wlc_phy_txpower_get_current(wlc->band->pi, &power,
112 CHSPEC_CHANNEL(chanspec));
114 siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
115 WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
116 cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
117 WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
118 stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
119 WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
121 /* criteria to choose stf mode */
123 /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
126 if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
127 setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
129 setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
131 /* STBC is ORed into to algo channel as STBC requires per-packet SCB capability check
132 * so cannot be default mode of operation. One of SISO, CDD have to be set
134 if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
135 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
138 static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info *wlc, s32 int_val)
140 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
144 if ((int_val == ON) && (wlc->stf->txstreams == 1))
147 if ((int_val == OFF) || (wlc->stf->txstreams == 1)
148 || !BRCMS_STBC_CAP_PHY(wlc))
149 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
151 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_TX_STBC;
153 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
154 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
159 bool brcms_c_stf_stbc_rx_set(struct brcms_c_info *wlc, s32 int_val)
161 if ((int_val != HT_CAP_RX_STBC_NO)
162 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
166 if (BRCMS_STF_SS_STBC_RX(wlc)) {
167 if ((int_val != HT_CAP_RX_STBC_NO)
168 && (wlc->stf->rxstreams == 1))
172 brcms_c_stf_stbc_rx_ht_update(wlc, int_val);
176 static int brcms_c_stf_txcore_set(struct brcms_c_info *wlc, u8 Nsts,
179 BCMMSG(wlc->wiphy, "wl%d: Nsts %d core_mask %x\n",
180 wlc->pub->unit, Nsts, core_mask);
182 if (BRCMS_BITSCNT(core_mask) > wlc->stf->txstreams) {
186 if ((BRCMS_BITSCNT(core_mask) == wlc->stf->txstreams) &&
187 ((core_mask & ~wlc->stf->txchain)
188 || !(core_mask & wlc->stf->txchain))) {
189 core_mask = wlc->stf->txchain;
192 wlc->stf->txcore[Nsts] = core_mask;
193 /* Nsts = 1..4, txcore index = 1..4 */
195 /* Needs to update beacon and ucode generated response
196 * frames when 1 stream core map changed
198 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
199 brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
201 brcms_c_suspend_mac_and_wait(wlc);
202 brcms_c_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
203 brcms_c_enable_mac(wlc);
210 static int brcms_c_stf_spatial_policy_set(struct brcms_c_info *wlc, int val)
215 BCMMSG(wlc->wiphy, "wl%d: val %x\n", wlc->pub->unit, val);
217 wlc->stf->spatial_policy = (s8) val;
218 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
219 core_mask = (val == MAX_SPATIAL_EXPANSION) ?
220 wlc->stf->txchain : txcore_default[i];
221 brcms_c_stf_txcore_set(wlc, (u8) i, core_mask);
226 int brcms_c_stf_txchain_set(struct brcms_c_info *wlc, s32 int_val, bool force)
228 u8 txchain = (u8) int_val;
232 if (wlc->stf->txchain == txchain)
235 if ((txchain & ~wlc->stf->hw_txchain)
236 || !(txchain & wlc->stf->hw_txchain))
239 /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
240 txstreams = (u8) BRCMS_BITSCNT(txchain);
241 if (txstreams > MAX_STREAMS_SUPPORTED)
244 if (txstreams == 1) {
245 for (i = 0; i < NBANDS(wlc); i++)
246 if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) !=
248 || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) !=
249 PHY_TXC1_MODE_SISO)) {
253 /* over-write the override rspec */
254 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
255 != PHY_TXC1_MODE_SISO) {
256 wlc->bandstate[i]->rspec_override = 0;
257 wiphy_err(wlc->wiphy, "%s(): temp "
258 "sense override non-SISO "
263 (wlc->bandstate[i]->mrspec_override) !=
264 PHY_TXC1_MODE_SISO) {
265 wlc->bandstate[i]->mrspec_override = 0;
266 wiphy_err(wlc->wiphy, "%s(): temp "
267 "sense override non-SISO "
274 wlc->stf->txchain = txchain;
275 wlc->stf->txstreams = txstreams;
276 brcms_c_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
277 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
278 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
280 (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
281 _brcms_c_stf_phy_txant_upd(wlc);
283 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
286 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
287 brcms_c_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
292 /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
293 int brcms_c_stf_ss_update(struct brcms_c_info *wlc, struct brcms_band *band)
299 prev_stf_ss = wlc->stf->ss_opmode;
301 /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
302 if (BRCMS_STBC_CAP_PHY(wlc) &&
303 wlc->stf->ss_algosel_auto
304 && (wlc->stf->ss_algo_channel != (u16) -1)) {
305 upd_stf_ss = (wlc->stf->no_cddstbc || (wlc->stf->txstreams == 1)
306 || isset(&wlc->stf->ss_algo_channel,
307 PHY_TXC1_MODE_SISO)) ? PHY_TXC1_MODE_SISO
310 if (wlc->band != band)
312 upd_stf_ss = (wlc->stf->no_cddstbc
313 || (wlc->stf->txstreams ==
314 1)) ? PHY_TXC1_MODE_SISO : band->
317 if (prev_stf_ss != upd_stf_ss) {
318 wlc->stf->ss_opmode = upd_stf_ss;
319 brcms_b_band_stf_ss_set(wlc->hw, upd_stf_ss);
325 int brcms_c_stf_attach(struct brcms_c_info *wlc)
327 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
328 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
330 if (BRCMS_ISNPHY(wlc->band) &&
331 (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
332 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
334 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
335 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
337 brcms_c_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
338 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
339 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
341 if (BRCMS_STBC_CAP_PHY(wlc)) {
342 wlc->stf->ss_algosel_auto = true;
343 wlc->stf->ss_algo_channel = (u16) -1; /* Init the default value */
348 void brcms_c_stf_detach(struct brcms_c_info *wlc)
353 * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
356 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
357 * achieve various tx/rx antenna selection schemes
359 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
360 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
361 * do tx-antenna selection for SISO transmissions
362 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
363 * do tx-antenna selection for SISO transmissions
364 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
366 static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
370 txant = (s8) wlc->stf->txant;
371 if (BRCMS_PHY_11N_CAP(wlc->band)) {
372 if (txant == ANT_TX_FORCE_0) {
373 wlc->stf->phytxant = PHY_TXC_ANT_0;
374 } else if (txant == ANT_TX_FORCE_1) {
375 wlc->stf->phytxant = PHY_TXC_ANT_1;
377 if (BRCMS_ISNPHY(wlc->band) &&
378 NREV_GE(wlc->band->phyrev, 3)
379 && NREV_LT(wlc->band->phyrev, 7)) {
380 wlc->stf->phytxant = PHY_TXC_ANT_2;
383 if (BRCMS_ISLCNPHY(wlc->band) ||
384 BRCMS_ISSSLPNPHY(wlc->band))
385 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
387 /* catch out of sync wlc->stf->txcore */
388 WARN_ON(wlc->stf->txchain <= 0);
390 wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
394 if (txant == ANT_TX_FORCE_0)
395 wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
396 else if (txant == ANT_TX_FORCE_1)
397 wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
399 wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
402 brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
405 void brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
407 _brcms_c_stf_phy_txant_upd(wlc);
410 void brcms_c_stf_phy_chain_calc(struct brcms_c_info *wlc)
412 /* get available rx/tx chains */
413 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
414 wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain");
416 /* these parameter are intended to be used for all PHY types */
417 if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
418 if (BRCMS_ISNPHY(wlc->band)) {
419 wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
421 wlc->stf->hw_txchain = TXCHAIN_DEF;
425 wlc->stf->txchain = wlc->stf->hw_txchain;
426 wlc->stf->txstreams = (u8) BRCMS_BITSCNT(wlc->stf->hw_txchain);
428 if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
429 if (BRCMS_ISNPHY(wlc->band)) {
430 wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
432 wlc->stf->hw_rxchain = RXCHAIN_DEF;
436 wlc->stf->rxchain = wlc->stf->hw_rxchain;
437 wlc->stf->rxstreams = (u8) BRCMS_BITSCNT(wlc->stf->hw_rxchain);
439 /* initialize the txcore table */
440 memcpy(wlc->stf->txcore, txcore_default, sizeof(wlc->stf->txcore));
442 /* default spatial_policy */
443 wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
444 brcms_c_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
447 static u16 _brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc,
450 u16 phytxant = wlc->stf->phytxant;
452 if (RSPEC_STF(rspec) != PHY_TXC1_MODE_SISO) {
453 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
454 } else if (wlc->stf->txant == ANT_TX_DEF)
455 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
456 phytxant &= PHY_TXC_ANT_MASK;
460 u16 brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc, ratespec_t rspec)
462 return _brcms_c_stf_phytxchain_sel(wlc, rspec);
465 u16 brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info *wlc, ratespec_t rspec)
467 u16 phytxant = wlc->stf->phytxant;
468 u16 mask = PHY_TXC_ANT_MASK;
470 /* for non-siso rates or default setting, use the available chains */
471 if (BRCMS_ISNPHY(wlc->band)) {
472 phytxant = _brcms_c_stf_phytxchain_sel(wlc, rspec);
473 mask = PHY_TXC_HTANT_MASK;
475 phytxant |= phytxant & mask;