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 <linux/kernel.h>
18 #include <linux/module.h>
27 #include "wlc_types.h"
34 #include "phy/wlc_phy_hal.h"
35 #include "wlc_channel.h"
40 #define MIN_SPATIAL_EXPANSION 0
41 #define MAX_SPATIAL_EXPANSION 1
43 #define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
44 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
46 static bool wlc_stf_stbc_tx_set(struct wlc_info
*wlc
, s32 int_val
);
47 static int wlc_stf_txcore_set(struct wlc_info
*wlc
, u8 Nsts
, u8 val
);
48 static int wlc_stf_spatial_policy_set(struct wlc_info
*wlc
, int val
);
49 static void wlc_stf_stbc_rx_ht_update(struct wlc_info
*wlc
, int val
);
51 static void _wlc_stf_phy_txant_upd(struct wlc_info
*wlc
);
52 static u16
_wlc_stf_phytxchain_sel(struct wlc_info
*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(struct wlc_info
*wlc
, int val
)
68 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
69 if (WLC_STF_SS_STBC_RX(wlc
)) {
70 if ((wlc
->stf
->rxstreams
== 1) && (val
!= HT_CAP_RX_STBC_NO
))
74 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_RX_STBC
;
75 wlc
->ht_cap
.cap_info
|= (val
<< IEEE80211_HT_CAP_RX_STBC_SHIFT
);
78 wlc_update_beacon(wlc
);
79 wlc_update_probe_resp(wlc
, true);
83 /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
84 void wlc_tempsense_upd(struct wlc_info
*wlc
)
86 wlc_phy_t
*pi
= wlc
->band
->pi
;
87 uint active_chains
, txchain
;
89 /* Check if the chip is too hot. Disable one Tx chain, if it is */
90 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
91 active_chains
= wlc_phy_stf_chain_active_get(pi
);
92 txchain
= active_chains
& 0xf;
94 if (wlc
->stf
->txchain
== wlc
->stf
->hw_txchain
) {
95 if (txchain
&& (txchain
< wlc
->stf
->hw_txchain
)) {
96 /* turn off 1 tx chain */
97 wlc_stf_txchain_set(wlc
, txchain
, true);
99 } else if (wlc
->stf
->txchain
< wlc
->stf
->hw_txchain
) {
100 if (txchain
== wlc
->stf
->hw_txchain
) {
101 /* turn back on txchain */
102 wlc_stf_txchain_set(wlc
, txchain
, true);
108 wlc_stf_ss_algo_channel_get(struct wlc_info
*wlc
, u16
*ss_algo_channel
,
112 u8 siso_mcs_id
, cdd_mcs_id
, stbc_mcs_id
;
114 /* Clear previous settings */
115 *ss_algo_channel
= 0;
118 *ss_algo_channel
= (u16
) -1;
122 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
123 CHSPEC_CHANNEL(chanspec
));
125 siso_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
126 WL_TX_POWER_MCS40_SISO_FIRST
: WL_TX_POWER_MCS20_SISO_FIRST
;
127 cdd_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
128 WL_TX_POWER_MCS40_CDD_FIRST
: WL_TX_POWER_MCS20_CDD_FIRST
;
129 stbc_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
130 WL_TX_POWER_MCS40_STBC_FIRST
: WL_TX_POWER_MCS20_STBC_FIRST
;
132 /* criteria to choose stf mode */
134 /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
137 if (power
.target
[siso_mcs_id
] > (power
.target
[cdd_mcs_id
] + 12))
138 setbit(ss_algo_channel
, PHY_TXC1_MODE_SISO
);
140 setbit(ss_algo_channel
, PHY_TXC1_MODE_CDD
);
142 /* STBC is ORed into to algo channel as STBC requires per-packet SCB capability check
143 * so cannot be default mode of operation. One of SISO, CDD have to be set
145 if (power
.target
[siso_mcs_id
] <= (power
.target
[stbc_mcs_id
] + 12))
146 setbit(ss_algo_channel
, PHY_TXC1_MODE_STBC
);
149 static bool wlc_stf_stbc_tx_set(struct wlc_info
*wlc
, s32 int_val
)
151 if ((int_val
!= AUTO
) && (int_val
!= OFF
) && (int_val
!= ON
)) {
155 if ((int_val
== ON
) && (wlc
->stf
->txstreams
== 1))
158 if ((int_val
== OFF
) || (wlc
->stf
->txstreams
== 1)
159 || !WLC_STBC_CAP_PHY(wlc
))
160 wlc
->ht_cap
.cap_info
&= ~IEEE80211_HT_CAP_TX_STBC
;
162 wlc
->ht_cap
.cap_info
|= IEEE80211_HT_CAP_TX_STBC
;
164 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= (s8
) int_val
;
165 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= (s8
) int_val
;
170 bool wlc_stf_stbc_rx_set(struct wlc_info
*wlc
, s32 int_val
)
172 if ((int_val
!= HT_CAP_RX_STBC_NO
)
173 && (int_val
!= HT_CAP_RX_STBC_ONE_STREAM
)) {
177 if (WLC_STF_SS_STBC_RX(wlc
)) {
178 if ((int_val
!= HT_CAP_RX_STBC_NO
)
179 && (wlc
->stf
->rxstreams
== 1))
183 wlc_stf_stbc_rx_ht_update(wlc
, int_val
);
187 static int wlc_stf_txcore_set(struct wlc_info
*wlc
, u8 Nsts
, u8 core_mask
)
189 BCMMSG(wlc
->wiphy
, "wl%d: Nsts %d core_mask %x\n",
190 wlc
->pub
->unit
, Nsts
, core_mask
);
192 if (WLC_BITSCNT(core_mask
) > wlc
->stf
->txstreams
) {
196 if ((WLC_BITSCNT(core_mask
) == wlc
->stf
->txstreams
) &&
197 ((core_mask
& ~wlc
->stf
->txchain
)
198 || !(core_mask
& wlc
->stf
->txchain
))) {
199 core_mask
= wlc
->stf
->txchain
;
202 wlc
->stf
->txcore
[Nsts
] = core_mask
;
203 /* Nsts = 1..4, txcore index = 1..4 */
205 /* Needs to update beacon and ucode generated response
206 * frames when 1 stream core map changed
208 wlc
->stf
->phytxant
= core_mask
<< PHY_TXC_ANT_SHIFT
;
209 wlc_bmac_txant_set(wlc
->hw
, wlc
->stf
->phytxant
);
211 wlc_suspend_mac_and_wait(wlc
);
212 wlc_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
220 static int wlc_stf_spatial_policy_set(struct wlc_info
*wlc
, int val
)
225 BCMMSG(wlc
->wiphy
, "wl%d: val %x\n", wlc
->pub
->unit
, val
);
227 wlc
->stf
->spatial_policy
= (s8
) val
;
228 for (i
= 1; i
<= MAX_STREAMS_SUPPORTED
; i
++) {
229 core_mask
= (val
== MAX_SPATIAL_EXPANSION
) ?
230 wlc
->stf
->txchain
: txcore_default
[i
];
231 wlc_stf_txcore_set(wlc
, (u8
) i
, core_mask
);
236 int wlc_stf_txchain_set(struct wlc_info
*wlc
, s32 int_val
, bool force
)
238 u8 txchain
= (u8
) int_val
;
242 if (wlc
->stf
->txchain
== txchain
)
245 if ((txchain
& ~wlc
->stf
->hw_txchain
)
246 || !(txchain
& wlc
->stf
->hw_txchain
))
249 /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
250 txstreams
= (u8
) WLC_BITSCNT(txchain
);
251 if (txstreams
> MAX_STREAMS_SUPPORTED
)
254 if (txstreams
== 1) {
255 for (i
= 0; i
< NBANDS(wlc
); i
++)
256 if ((RSPEC_STF(wlc
->bandstate
[i
]->rspec_override
) !=
258 || (RSPEC_STF(wlc
->bandstate
[i
]->mrspec_override
) !=
259 PHY_TXC1_MODE_SISO
)) {
263 /* over-write the override rspec */
264 if (RSPEC_STF(wlc
->bandstate
[i
]->rspec_override
)
265 != PHY_TXC1_MODE_SISO
) {
266 wlc
->bandstate
[i
]->rspec_override
= 0;
267 wiphy_err(wlc
->wiphy
, "%s(): temp "
268 "sense override non-SISO "
273 (wlc
->bandstate
[i
]->mrspec_override
) !=
274 PHY_TXC1_MODE_SISO
) {
275 wlc
->bandstate
[i
]->mrspec_override
= 0;
276 wiphy_err(wlc
->wiphy
, "%s(): temp "
277 "sense override non-SISO "
284 wlc
->stf
->txchain
= txchain
;
285 wlc
->stf
->txstreams
= txstreams
;
286 wlc_stf_stbc_tx_set(wlc
, wlc
->band
->band_stf_stbc_tx
);
287 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
288 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
290 (wlc
->stf
->txstreams
== 1) ? ANT_TX_FORCE_0
: ANT_TX_DEF
;
291 _wlc_stf_phy_txant_upd(wlc
);
293 wlc_phy_stf_chain_set(wlc
->band
->pi
, wlc
->stf
->txchain
,
296 for (i
= 1; i
<= MAX_STREAMS_SUPPORTED
; i
++)
297 wlc_stf_txcore_set(wlc
, (u8
) i
, txcore_default
[i
]);
302 /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
303 int wlc_stf_ss_update(struct wlc_info
*wlc
, struct wlcband
*band
)
309 prev_stf_ss
= wlc
->stf
->ss_opmode
;
311 /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
312 if (WLC_STBC_CAP_PHY(wlc
) &&
313 wlc
->stf
->ss_algosel_auto
314 && (wlc
->stf
->ss_algo_channel
!= (u16
) -1)) {
315 upd_stf_ss
= (wlc
->stf
->no_cddstbc
|| (wlc
->stf
->txstreams
== 1)
316 || isset(&wlc
->stf
->ss_algo_channel
,
317 PHY_TXC1_MODE_SISO
)) ? PHY_TXC1_MODE_SISO
320 if (wlc
->band
!= band
)
322 upd_stf_ss
= (wlc
->stf
->no_cddstbc
323 || (wlc
->stf
->txstreams
==
324 1)) ? PHY_TXC1_MODE_SISO
: band
->
327 if (prev_stf_ss
!= upd_stf_ss
) {
328 wlc
->stf
->ss_opmode
= upd_stf_ss
;
329 wlc_bmac_band_stf_ss_set(wlc
->hw
, upd_stf_ss
);
335 int wlc_stf_attach(struct wlc_info
*wlc
)
337 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_ss_mode
= PHY_TXC1_MODE_SISO
;
338 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_ss_mode
= PHY_TXC1_MODE_CDD
;
340 if (WLCISNPHY(wlc
->band
) &&
341 (wlc_phy_txpower_hw_ctrl_get(wlc
->band
->pi
) != PHY_TPC_HW_ON
))
342 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_ss_mode
=
344 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
345 wlc_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
347 wlc_stf_stbc_rx_ht_update(wlc
, HT_CAP_RX_STBC_NO
);
348 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
349 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
351 if (WLC_STBC_CAP_PHY(wlc
)) {
352 wlc
->stf
->ss_algosel_auto
= true;
353 wlc
->stf
->ss_algo_channel
= (u16
) -1; /* Init the default value */
358 void wlc_stf_detach(struct wlc_info
*wlc
)
363 * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
366 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
367 * achieve various tx/rx antenna selection schemes
369 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
370 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
371 * do tx-antenna selection for SISO transmissions
372 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
373 * do tx-antenna selection for SISO transmissions
374 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
376 static void _wlc_stf_phy_txant_upd(struct wlc_info
*wlc
)
380 txant
= (s8
) wlc
->stf
->txant
;
381 if (WLC_PHY_11N_CAP(wlc
->band
)) {
382 if (txant
== ANT_TX_FORCE_0
) {
383 wlc
->stf
->phytxant
= PHY_TXC_ANT_0
;
384 } else if (txant
== ANT_TX_FORCE_1
) {
385 wlc
->stf
->phytxant
= PHY_TXC_ANT_1
;
387 if (WLCISNPHY(wlc
->band
) &&
388 NREV_GE(wlc
->band
->phyrev
, 3)
389 && NREV_LT(wlc
->band
->phyrev
, 7)) {
390 wlc
->stf
->phytxant
= PHY_TXC_ANT_2
;
393 if (WLCISLCNPHY(wlc
->band
) || WLCISSSLPNPHY(wlc
->band
))
394 wlc
->stf
->phytxant
= PHY_TXC_LCNPHY_ANT_LAST
;
396 /* catch out of sync wlc->stf->txcore */
397 WARN_ON(wlc
->stf
->txchain
<= 0);
399 wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
403 if (txant
== ANT_TX_FORCE_0
)
404 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_0
;
405 else if (txant
== ANT_TX_FORCE_1
)
406 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_1
;
408 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_LAST
;
411 wlc_bmac_txant_set(wlc
->hw
, wlc
->stf
->phytxant
);
414 void wlc_stf_phy_txant_upd(struct wlc_info
*wlc
)
416 _wlc_stf_phy_txant_upd(wlc
);
419 void wlc_stf_phy_chain_calc(struct wlc_info
*wlc
)
421 /* get available rx/tx chains */
422 wlc
->stf
->hw_txchain
= (u8
) getintvar(wlc
->pub
->vars
, "txchain");
423 wlc
->stf
->hw_rxchain
= (u8
) getintvar(wlc
->pub
->vars
, "rxchain");
425 /* these parameter are intended to be used for all PHY types */
426 if (wlc
->stf
->hw_txchain
== 0 || wlc
->stf
->hw_txchain
== 0xf) {
427 if (WLCISNPHY(wlc
->band
)) {
428 wlc
->stf
->hw_txchain
= TXCHAIN_DEF_NPHY
;
430 wlc
->stf
->hw_txchain
= TXCHAIN_DEF
;
434 wlc
->stf
->txchain
= wlc
->stf
->hw_txchain
;
435 wlc
->stf
->txstreams
= (u8
) WLC_BITSCNT(wlc
->stf
->hw_txchain
);
437 if (wlc
->stf
->hw_rxchain
== 0 || wlc
->stf
->hw_rxchain
== 0xf) {
438 if (WLCISNPHY(wlc
->band
)) {
439 wlc
->stf
->hw_rxchain
= RXCHAIN_DEF_NPHY
;
441 wlc
->stf
->hw_rxchain
= RXCHAIN_DEF
;
445 wlc
->stf
->rxchain
= wlc
->stf
->hw_rxchain
;
446 wlc
->stf
->rxstreams
= (u8
) WLC_BITSCNT(wlc
->stf
->hw_rxchain
);
448 /* initialize the txcore table */
449 memcpy(wlc
->stf
->txcore
, txcore_default
, sizeof(wlc
->stf
->txcore
));
451 /* default spatial_policy */
452 wlc
->stf
->spatial_policy
= MIN_SPATIAL_EXPANSION
;
453 wlc_stf_spatial_policy_set(wlc
, MIN_SPATIAL_EXPANSION
);
456 static u16
_wlc_stf_phytxchain_sel(struct wlc_info
*wlc
, ratespec_t rspec
)
458 u16 phytxant
= wlc
->stf
->phytxant
;
460 if (RSPEC_STF(rspec
) != PHY_TXC1_MODE_SISO
) {
461 phytxant
= wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
462 } else if (wlc
->stf
->txant
== ANT_TX_DEF
)
463 phytxant
= wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
464 phytxant
&= PHY_TXC_ANT_MASK
;
468 u16
wlc_stf_phytxchain_sel(struct wlc_info
*wlc
, ratespec_t rspec
)
470 return _wlc_stf_phytxchain_sel(wlc
, rspec
);
473 u16
wlc_stf_d11hdrs_phyctl_txant(struct wlc_info
*wlc
, ratespec_t rspec
)
475 u16 phytxant
= wlc
->stf
->phytxant
;
476 u16 mask
= PHY_TXC_ANT_MASK
;
478 /* for non-siso rates or default setting, use the available chains */
479 if (WLCISNPHY(wlc
->band
)) {
480 phytxant
= _wlc_stf_phytxchain_sel(wlc
, rspec
);
481 mask
= PHY_TXC_HTANT_MASK
;
483 phytxant
|= phytxant
& mask
;