blob: 4728ad90e295f8bb25adb721b92078f54ccde4f7 [file] [log] [blame]
Henry Ptasinskia9533e72010-09-08 21:04:42 -07001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
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.
7 *
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.
15 */
16
Brett Rudley33279892010-10-01 18:03:27 -070017#include <linux/kernel.h>
Greg Kroah-Hartmana1c16ed2010-10-21 11:17:44 -070018#include <wlc_cfg.h>
Brett Rudley33279892010-10-01 18:03:27 -070019#include <linuxver.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070020#include <bcmdefs.h>
21#include <osl.h>
22#include <bcmutils.h>
23#include <siutils.h>
24#include <bcmendian.h>
25#include <proto/802.11.h>
26#include <wlioctl.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070027#include <bcmwifi.h>
28#include <d11.h>
29#include <wlc_rate.h>
30#include <wlc_pub.h>
31#include <wlc_key.h>
32#include <wlc_channel.h>
33#include <wlc_bsscfg.h>
34#include <wlc_mac80211.h>
35#include <wlc_scb.h>
36#include <wl_export.h>
37#include <wlc_bmac.h>
38#include <wlc_stf.h>
39
40#define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
41 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
42
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -070043static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc);
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -070044static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val);
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -070045static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 val);
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040046static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val);
47static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070048
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040049static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc);
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -070050static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070051
52#define NSTS_1 1
53#define NSTS_2 2
54#define NSTS_3 3
55#define NSTS_4 4
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -070056const u8 txcore_default[5] = {
Henry Ptasinskia9533e72010-09-08 21:04:42 -070057 (0), /* bitmap of the core enabled */
58 (0x01), /* For Nsts = 1, enable core 1 */
59 (0x03), /* For Nsts = 2, enable core 1 & 2 */
60 (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
61 (0x0f) /* For Nsts = 4, enable all cores */
62};
63
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040064static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070065{
66 ASSERT((val == HT_CAP_RX_STBC_NO)
67 || (val == HT_CAP_RX_STBC_ONE_STREAM));
68
69 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
70 if (WLC_STF_SS_STBC_RX(wlc)) {
71 if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
72 return;
73 }
74
75 wlc->ht_cap.cap &= ~HT_CAP_RX_STBC_MASK;
76 wlc->ht_cap.cap |= (val << HT_CAP_RX_STBC_SHIFT);
77
78 if (wlc->pub->up) {
79 wlc_update_beacon(wlc);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -070080 wlc_update_probe_resp(wlc, true);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070081 }
82}
83
84/* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040085void wlc_tempsense_upd(wlc_info_t *wlc)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070086{
87 wlc_phy_t *pi = wlc->band->pi;
88 uint active_chains, txchain;
89
90 /* Check if the chip is too hot. Disable one Tx chain, if it is */
91 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
92 active_chains = wlc_phy_stf_chain_active_get(pi);
93 txchain = active_chains & 0xf;
94
95 if (wlc->stf->txchain == wlc->stf->hw_txchain) {
96 if (txchain && (txchain < wlc->stf->hw_txchain)) {
97 /* turn off 1 tx chain */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -070098 wlc_stf_txchain_set(wlc, txchain, true);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070099 }
100 } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
101 if (txchain == wlc->stf->hw_txchain) {
102 /* turn back on txchain */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700103 wlc_stf_txchain_set(wlc, txchain, true);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700104 }
105 }
106}
107
108void
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700109wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, u16 *ss_algo_channel,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700110 chanspec_t chanspec)
111{
112 tx_power_t power;
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700113 u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700114
115 /* Clear previous settings */
116 *ss_algo_channel = 0;
117
118 if (!wlc->pub->up) {
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700119 *ss_algo_channel = (u16) -1;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700120 return;
121 }
122
123 wlc_phy_txpower_get_current(wlc->band->pi, &power,
124 CHSPEC_CHANNEL(chanspec));
125
126 siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
127 WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
128 cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
129 WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
130 stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
131 WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
132
133 /* criteria to choose stf mode */
134
135 /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
136 * on both chains
137 */
138 if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
139 setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
140 else
141 setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
142
143 /* STBC is ORed into to algo channel as STBC requires per-packet SCB capability check
144 * so cannot be default mode of operation. One of SISO, CDD have to be set
145 */
146 if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
147 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
148}
149
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700150static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700151{
152 return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT;
153}
154
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700155static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700156{
157 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700158 return false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700159 }
160
161 if ((int_val == ON) && (wlc->stf->txstreams == 1))
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700162 return false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700163
164 if ((int_val == OFF) || (wlc->stf->txstreams == 1)
165 || !WLC_STBC_CAP_PHY(wlc))
166 wlc->ht_cap.cap &= ~HT_CAP_TX_STBC;
167 else
168 wlc->ht_cap.cap |= HT_CAP_TX_STBC;
169
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700170 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
171 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700172
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700173 return true;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700174}
175
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700176bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700177{
178 if ((int_val != HT_CAP_RX_STBC_NO)
179 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700180 return false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700181 }
182
183 if (WLC_STF_SS_STBC_RX(wlc)) {
184 if ((int_val != HT_CAP_RX_STBC_NO)
185 && (wlc->stf->rxstreams == 1))
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700186 return false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700187 }
188
189 wlc_stf_stbc_rx_ht_update(wlc, int_val);
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700190 return true;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700191}
192
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700193static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700194{
195 WL_TRACE(("wl%d: %s: Nsts %d core_mask %x\n",
196 wlc->pub->unit, __func__, Nsts, core_mask));
197
198 ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED));
199
200 if (WLC_BITSCNT(core_mask) > wlc->stf->txstreams) {
201 core_mask = 0;
202 }
203
204 if ((WLC_BITSCNT(core_mask) == wlc->stf->txstreams) &&
205 ((core_mask & ~wlc->stf->txchain)
206 || !(core_mask & wlc->stf->txchain))) {
207 core_mask = wlc->stf->txchain;
208 }
209
210 ASSERT(!core_mask || Nsts <= WLC_BITSCNT(core_mask));
211
212 wlc->stf->txcore[Nsts] = core_mask;
213 /* Nsts = 1..4, txcore index = 1..4 */
214 if (Nsts == 1) {
215 /* Needs to update beacon and ucode generated response
216 * frames when 1 stream core map changed
217 */
218 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
219 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
220 if (wlc->clk) {
221 wlc_suspend_mac_and_wait(wlc);
222 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
223 wlc_enable_mac(wlc);
224 }
225 }
226
227 return BCME_OK;
228}
229
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400230static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700231{
232 int i;
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700233 u8 core_mask = 0;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700234
235 WL_TRACE(("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val));
236
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700237 wlc->stf->spatial_policy = (s8) val;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700238 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
239 core_mask = (val == MAX_SPATIAL_EXPANSION) ?
240 wlc->stf->txchain : txcore_default[i];
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700241 wlc_stf_txcore_set(wlc, (u8) i, core_mask);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700242 }
243 return BCME_OK;
244}
245
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700246int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700247{
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700248 u8 txchain = (u8) int_val;
249 u8 txstreams;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700250 uint i;
251
252 if (wlc->stf->txchain == txchain)
253 return BCME_OK;
254
255 if ((txchain & ~wlc->stf->hw_txchain)
256 || !(txchain & wlc->stf->hw_txchain))
257 return BCME_RANGE;
258
259 /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700260 txstreams = (u8) WLC_BITSCNT(txchain);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700261 if (txstreams > MAX_STREAMS_SUPPORTED)
262 return BCME_RANGE;
263
264 if (txstreams == 1) {
265 for (i = 0; i < NBANDS(wlc); i++)
266 if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) !=
267 PHY_TXC1_MODE_SISO)
268 || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) !=
269 PHY_TXC1_MODE_SISO)) {
270 if (!force)
271 return BCME_ERROR;
272
273 /* over-write the override rspec */
274 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
275 != PHY_TXC1_MODE_SISO) {
276 wlc->bandstate[i]->rspec_override = 0;
277 WL_ERROR(("%s(): temp sense override non-SISO" " rspec_override.\n", __func__));
278 }
279 if (RSPEC_STF
280 (wlc->bandstate[i]->mrspec_override) !=
281 PHY_TXC1_MODE_SISO) {
282 wlc->bandstate[i]->mrspec_override = 0;
283 WL_ERROR(("%s(): temp sense override non-SISO" " mrspec_override.\n", __func__));
284 }
285 }
286 }
287
288 wlc->stf->txchain = txchain;
289 wlc->stf->txstreams = txstreams;
290 wlc_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
291 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
292 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
293 wlc->stf->txant =
294 (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
295 _wlc_stf_phy_txant_upd(wlc);
296
297 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
298 wlc->stf->rxchain);
299
300 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700301 wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700302
303 return BCME_OK;
304}
305
Greg Kroah-Hartman3e264162010-10-08 11:11:13 -0700306int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700307{
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700308 u8 rxchain_cnt;
309 u8 rxchain = (u8) int_val;
310 u8 mimops_mode;
311 u8 old_rxchain, old_rxchain_cnt;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700312
313 if (wlc->stf->rxchain == rxchain)
314 return BCME_OK;
315
316 if ((rxchain & ~wlc->stf->hw_rxchain)
317 || !(rxchain & wlc->stf->hw_rxchain))
318 return BCME_RANGE;
319
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700320 rxchain_cnt = (u8) WLC_BITSCNT(rxchain);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700321 if (WLC_STF_SS_STBC_RX(wlc)) {
322 if ((rxchain_cnt == 1)
323 && (wlc_stf_stbc_rx_get(wlc) != HT_CAP_RX_STBC_NO))
324 return BCME_RANGE;
325 }
326
327 if (APSTA_ENAB(wlc->pub) && (wlc->pub->associated))
328 return BCME_ASSOCIATED;
329
330 old_rxchain = wlc->stf->rxchain;
331 old_rxchain_cnt = wlc->stf->rxstreams;
332
333 wlc->stf->rxchain = rxchain;
334 wlc->stf->rxstreams = rxchain_cnt;
335
336 if (rxchain_cnt != old_rxchain_cnt) {
337 mimops_mode =
338 (rxchain_cnt == 1) ? HT_CAP_MIMO_PS_ON : HT_CAP_MIMO_PS_OFF;
339 wlc->mimops_PM = mimops_mode;
340 if (AP_ENAB(wlc->pub)) {
341 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
342 wlc->stf->rxchain);
343 wlc_ht_mimops_cap_update(wlc, mimops_mode);
344 if (wlc->pub->associated)
345 wlc_mimops_action_ht_send(wlc, wlc->cfg,
346 mimops_mode);
347 return BCME_OK;
348 }
349 if (wlc->pub->associated) {
350 if (mimops_mode == HT_CAP_MIMO_PS_OFF) {
351 /* if mimops is off, turn on the Rx chain first */
352 wlc_phy_stf_chain_set(wlc->band->pi,
353 wlc->stf->txchain,
354 wlc->stf->rxchain);
355 wlc_ht_mimops_cap_update(wlc, mimops_mode);
356 }
357 } else {
358 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
359 wlc->stf->rxchain);
360 wlc_ht_mimops_cap_update(wlc, mimops_mode);
361 }
362 } else if (old_rxchain != rxchain)
363 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
364 wlc->stf->rxchain);
365
366 return BCME_OK;
367}
368
369/* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400370int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700371{
372 int ret_code = 0;
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700373 u8 prev_stf_ss;
374 u8 upd_stf_ss;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700375
376 prev_stf_ss = wlc->stf->ss_opmode;
377
378 /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
379 if (WLC_STBC_CAP_PHY(wlc) &&
380 wlc->stf->ss_algosel_auto
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700381 && (wlc->stf->ss_algo_channel != (u16) -1)) {
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700382 ASSERT(isset(&wlc->stf->ss_algo_channel, PHY_TXC1_MODE_CDD)
383 || isset(&wlc->stf->ss_algo_channel,
384 PHY_TXC1_MODE_SISO));
385 upd_stf_ss = (wlc->stf->no_cddstbc || (wlc->stf->txstreams == 1)
386 || isset(&wlc->stf->ss_algo_channel,
387 PHY_TXC1_MODE_SISO)) ? PHY_TXC1_MODE_SISO
388 : PHY_TXC1_MODE_CDD;
389 } else {
390 if (wlc->band != band)
391 return ret_code;
392 upd_stf_ss = (wlc->stf->no_cddstbc
393 || (wlc->stf->txstreams ==
394 1)) ? PHY_TXC1_MODE_SISO : band->
395 band_stf_ss_mode;
396 }
397 if (prev_stf_ss != upd_stf_ss) {
398 wlc->stf->ss_opmode = upd_stf_ss;
399 wlc_bmac_band_stf_ss_set(wlc->hw, upd_stf_ss);
400 }
401
402 return ret_code;
403}
404
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -0700405int wlc_stf_attach(wlc_info_t *wlc)
Jason Coopera2627bc2010-09-14 09:45:31 -0400406{
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700407 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
408 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
409
410 if (WLCISNPHY(wlc->band) &&
411 (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
412 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
413 PHY_TXC1_MODE_CDD;
414 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
415 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
416
417 wlc_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
418 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
419 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
420
421 if (WLC_STBC_CAP_PHY(wlc)) {
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700422 wlc->stf->ss_algosel_auto = true;
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700423 wlc->stf->ss_algo_channel = (u16) -1; /* Init the default value */
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700424 }
425 return 0;
426}
427
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -0700428void wlc_stf_detach(wlc_info_t *wlc)
Jason Coopera2627bc2010-09-14 09:45:31 -0400429{
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700430}
431
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700432int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700433{
434 int bcmerror = BCME_OK;
435
436 /* when there is only 1 tx_streams, don't allow to change the txant */
437 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
438 return ((val == wlc->stf->txant) ? bcmerror : BCME_RANGE);
439
440 switch (val) {
441 case -1:
442 val = ANT_TX_DEF;
443 break;
444 case 0:
445 val = ANT_TX_FORCE_0;
446 break;
447 case 1:
448 val = ANT_TX_FORCE_1;
449 break;
450 case 3:
451 val = ANT_TX_LAST_RX;
452 break;
453 default:
454 bcmerror = BCME_RANGE;
455 break;
456 }
457
458 if (bcmerror == BCME_OK)
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700459 wlc->stf->txant = (s8) val;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700460
461 return bcmerror;
462
463}
464
465/*
466 * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
467 * change
468 *
469 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
470 * achieve various tx/rx antenna selection schemes
471 *
472 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
473 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
474 * do tx-antenna selection for SISO transmissions
475 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
476 * do tx-antenna selection for SISO transmissions
477 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
478*/
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400479static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700480{
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700481 s8 txant;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700482
Greg Kroah-Hartman562c8852010-10-05 11:04:17 -0700483 txant = (s8) wlc->stf->txant;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700484 ASSERT(txant == ANT_TX_FORCE_0 || txant == ANT_TX_FORCE_1
485 || txant == ANT_TX_LAST_RX);
486
487 if (WLC_PHY_11N_CAP(wlc->band)) {
488 if (txant == ANT_TX_FORCE_0) {
489 wlc->stf->phytxant = PHY_TXC_ANT_0;
490 } else if (txant == ANT_TX_FORCE_1) {
491 wlc->stf->phytxant = PHY_TXC_ANT_1;
492
493 if (WLCISNPHY(wlc->band) &&
494 NREV_GE(wlc->band->phyrev, 3)
495 && NREV_LT(wlc->band->phyrev, 7)) {
496 wlc->stf->phytxant = PHY_TXC_ANT_2;
497 }
498 } else {
499 if (WLCISLCNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band))
500 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
501 else {
502 /* keep this assert to catch out of sync wlc->stf->txcore */
503 ASSERT(wlc->stf->txchain > 0);
504 wlc->stf->phytxant =
505 wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
506 }
507 }
508 } else {
509 if (txant == ANT_TX_FORCE_0)
510 wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
511 else if (txant == ANT_TX_FORCE_1)
512 wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
513 else
514 wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
515 }
516
517 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
518}
519
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400520void wlc_stf_phy_txant_upd(wlc_info_t *wlc)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700521{
522 _wlc_stf_phy_txant_upd(wlc);
523}
524
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -0700525void wlc_stf_phy_chain_calc(wlc_info_t *wlc)
Jason Coopera2627bc2010-09-14 09:45:31 -0400526{
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700527 /* get available rx/tx chains */
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700528 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
529 wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain");
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700530
531 /* these parameter are intended to be used for all PHY types */
532 if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
533 if (WLCISNPHY(wlc->band)) {
534 wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
535 } else {
536 wlc->stf->hw_txchain = TXCHAIN_DEF;
537 }
538 }
539
540 wlc->stf->txchain = wlc->stf->hw_txchain;
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700541 wlc->stf->txstreams = (u8) WLC_BITSCNT(wlc->stf->hw_txchain);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700542
543 if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
544 if (WLCISNPHY(wlc->band)) {
545 wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
546 } else {
547 wlc->stf->hw_rxchain = RXCHAIN_DEF;
548 }
549 }
550
551 wlc->stf->rxchain = wlc->stf->hw_rxchain;
Greg Kroah-Hartman41feb5e2010-10-05 10:09:00 -0700552 wlc->stf->rxstreams = (u8) WLC_BITSCNT(wlc->stf->hw_rxchain);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700553
554 /* initialize the txcore table */
555 bcopy(txcore_default, wlc->stf->txcore, sizeof(wlc->stf->txcore));
556
557 /* default spatial_policy */
558 wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
559 wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
560}
561
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700562static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700563{
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700564 u16 phytxant = wlc->stf->phytxant;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700565
566 if (RSPEC_STF(rspec) != PHY_TXC1_MODE_SISO) {
567 ASSERT(wlc->stf->txstreams > 1);
568 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
569 } else if (wlc->stf->txant == ANT_TX_DEF)
570 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
571 phytxant &= PHY_TXC_ANT_MASK;
572 return phytxant;
573}
574
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700575u16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700576{
577 return _wlc_stf_phytxchain_sel(wlc, rspec);
578}
579
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700580u16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700581{
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700582 u16 phytxant = wlc->stf->phytxant;
583 u16 mask = PHY_TXC_ANT_MASK;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700584
585 /* for non-siso rates or default setting, use the available chains */
586 if (WLCISNPHY(wlc->band)) {
587 ASSERT(wlc->stf->txchain != 0);
588 phytxant = _wlc_stf_phytxchain_sel(wlc, rspec);
589 mask = PHY_TXC_HTANT_MASK;
590 }
591 phytxant |= phytxant & mask;
592 return phytxant;
593}