Commit | Line | Data |
---|---|---|
a9533e7e HP |
1 | /* |
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 | ||
17 | #include <wlc_cfg.h> | |
18 | #include <typedefs.h> | |
3327989a BR |
19 | #include <linux/kernel.h> |
20 | #include <linuxver.h> | |
a9533e7e HP |
21 | #include <bcmdefs.h> |
22 | #include <osl.h> | |
23 | #include <bcmutils.h> | |
24 | #include <siutils.h> | |
25 | #include <bcmendian.h> | |
26 | #include <proto/802.11.h> | |
27 | #include <wlioctl.h> | |
28 | #include <bcmwpa.h> | |
29 | #include <bcmwifi.h> | |
30 | #include <d11.h> | |
31 | #include <wlc_rate.h> | |
32 | #include <wlc_pub.h> | |
33 | #include <wlc_key.h> | |
34 | #include <wlc_channel.h> | |
35 | #include <wlc_bsscfg.h> | |
36 | #include <wlc_mac80211.h> | |
37 | #include <wlc_scb.h> | |
38 | #include <wl_export.h> | |
39 | #include <wlc_bmac.h> | |
40 | #include <wlc_stf.h> | |
41 | ||
42 | #define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \ | |
43 | NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6)) | |
44 | ||
7cc4a4c0 JC |
45 | static int8 wlc_stf_stbc_rx_get(wlc_info_t *wlc); |
46 | static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, int32 int_val); | |
41feb5ed | 47 | static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 val); |
7cc4a4c0 JC |
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); | |
a9533e7e | 50 | |
7cc4a4c0 JC |
51 | static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc); |
52 | static uint16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec); | |
a9533e7e HP |
53 | |
54 | #define NSTS_1 1 | |
55 | #define NSTS_2 2 | |
56 | #define NSTS_3 3 | |
57 | #define NSTS_4 4 | |
41feb5ed | 58 | const u8 txcore_default[5] = { |
a9533e7e HP |
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 */ | |
64 | }; | |
65 | ||
7cc4a4c0 | 66 | static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val) |
a9533e7e HP |
67 | { |
68 | ASSERT((val == HT_CAP_RX_STBC_NO) | |
69 | || (val == HT_CAP_RX_STBC_ONE_STREAM)); | |
70 | ||
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)) | |
74 | return; | |
75 | } | |
76 | ||
77 | wlc->ht_cap.cap &= ~HT_CAP_RX_STBC_MASK; | |
78 | wlc->ht_cap.cap |= (val << HT_CAP_RX_STBC_SHIFT); | |
79 | ||
80 | if (wlc->pub->up) { | |
81 | wlc_update_beacon(wlc); | |
82 | wlc_update_probe_resp(wlc, TRUE); | |
83 | } | |
84 | } | |
85 | ||
86 | /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */ | |
7cc4a4c0 | 87 | void wlc_tempsense_upd(wlc_info_t *wlc) |
a9533e7e HP |
88 | { |
89 | wlc_phy_t *pi = wlc->band->pi; | |
90 | uint active_chains, txchain; | |
91 | ||
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; | |
96 | ||
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); | |
101 | } | |
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); | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | void | |
7cc4a4c0 | 111 | wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, uint16 *ss_algo_channel, |
a9533e7e HP |
112 | chanspec_t chanspec) |
113 | { | |
114 | tx_power_t power; | |
41feb5ed | 115 | u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id; |
a9533e7e HP |
116 | |
117 | /* Clear previous settings */ | |
118 | *ss_algo_channel = 0; | |
119 | ||
120 | if (!wlc->pub->up) { | |
29c4275a | 121 | *ss_algo_channel = (uint16) -1; |
a9533e7e HP |
122 | return; |
123 | } | |
124 | ||
125 | wlc_phy_txpower_get_current(wlc->band->pi, &power, | |
126 | CHSPEC_CHANNEL(chanspec)); | |
127 | ||
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; | |
134 | ||
135 | /* criteria to choose stf mode */ | |
136 | ||
137 | /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs | |
138 | * on both chains | |
139 | */ | |
140 | if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12)) | |
141 | setbit(ss_algo_channel, PHY_TXC1_MODE_SISO); | |
142 | else | |
143 | setbit(ss_algo_channel, PHY_TXC1_MODE_CDD); | |
144 | ||
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 | |
147 | */ | |
148 | if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12)) | |
149 | setbit(ss_algo_channel, PHY_TXC1_MODE_STBC); | |
150 | } | |
151 | ||
7cc4a4c0 | 152 | static int8 wlc_stf_stbc_rx_get(wlc_info_t *wlc) |
a9533e7e HP |
153 | { |
154 | return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT; | |
155 | } | |
156 | ||
7cc4a4c0 | 157 | static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, int32 int_val) |
a9533e7e HP |
158 | { |
159 | if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) { | |
160 | return FALSE; | |
161 | } | |
162 | ||
163 | if ((int_val == ON) && (wlc->stf->txstreams == 1)) | |
164 | return FALSE; | |
165 | ||
166 | if ((int_val == OFF) || (wlc->stf->txstreams == 1) | |
167 | || !WLC_STBC_CAP_PHY(wlc)) | |
168 | wlc->ht_cap.cap &= ~HT_CAP_TX_STBC; | |
169 | else | |
170 | wlc->ht_cap.cap |= HT_CAP_TX_STBC; | |
171 | ||
172 | wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (int8) int_val; | |
173 | wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (int8) int_val; | |
174 | ||
175 | return TRUE; | |
176 | } | |
177 | ||
7cc4a4c0 | 178 | bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, int32 int_val) |
a9533e7e HP |
179 | { |
180 | if ((int_val != HT_CAP_RX_STBC_NO) | |
181 | && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) { | |
182 | return FALSE; | |
183 | } | |
184 | ||
185 | if (WLC_STF_SS_STBC_RX(wlc)) { | |
186 | if ((int_val != HT_CAP_RX_STBC_NO) | |
187 | && (wlc->stf->rxstreams == 1)) | |
188 | return FALSE; | |
189 | } | |
190 | ||
191 | wlc_stf_stbc_rx_ht_update(wlc, int_val); | |
192 | return TRUE; | |
193 | } | |
194 | ||
41feb5ed | 195 | static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask) |
a9533e7e HP |
196 | { |
197 | WL_TRACE(("wl%d: %s: Nsts %d core_mask %x\n", | |
198 | wlc->pub->unit, __func__, Nsts, core_mask)); | |
199 | ||
200 | ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED)); | |
201 | ||
202 | if (WLC_BITSCNT(core_mask) > wlc->stf->txstreams) { | |
203 | core_mask = 0; | |
204 | } | |
205 | ||
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; | |
210 | } | |
211 | ||
212 | ASSERT(!core_mask || Nsts <= WLC_BITSCNT(core_mask)); | |
213 | ||
214 | wlc->stf->txcore[Nsts] = core_mask; | |
215 | /* Nsts = 1..4, txcore index = 1..4 */ | |
216 | if (Nsts == 1) { | |
217 | /* Needs to update beacon and ucode generated response | |
218 | * frames when 1 stream core map changed | |
219 | */ | |
220 | wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT; | |
221 | wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant); | |
222 | if (wlc->clk) { | |
223 | wlc_suspend_mac_and_wait(wlc); | |
224 | wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec); | |
225 | wlc_enable_mac(wlc); | |
226 | } | |
227 | } | |
228 | ||
229 | return BCME_OK; | |
230 | } | |
231 | ||
7cc4a4c0 | 232 | static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val) |
a9533e7e HP |
233 | { |
234 | int i; | |
41feb5ed | 235 | u8 core_mask = 0; |
a9533e7e HP |
236 | |
237 | WL_TRACE(("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val)); | |
238 | ||
239 | wlc->stf->spatial_policy = (int8) val; | |
240 | for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) { | |
241 | core_mask = (val == MAX_SPATIAL_EXPANSION) ? | |
242 | wlc->stf->txchain : txcore_default[i]; | |
41feb5ed | 243 | wlc_stf_txcore_set(wlc, (u8) i, core_mask); |
a9533e7e HP |
244 | } |
245 | return BCME_OK; | |
246 | } | |
247 | ||
7cc4a4c0 | 248 | int wlc_stf_txchain_set(wlc_info_t *wlc, int32 int_val, bool force) |
a9533e7e | 249 | { |
41feb5ed GKH |
250 | u8 txchain = (u8) int_val; |
251 | u8 txstreams; | |
a9533e7e HP |
252 | uint i; |
253 | ||
254 | if (wlc->stf->txchain == txchain) | |
255 | return BCME_OK; | |
256 | ||
257 | if ((txchain & ~wlc->stf->hw_txchain) | |
258 | || !(txchain & wlc->stf->hw_txchain)) | |
259 | return BCME_RANGE; | |
260 | ||
261 | /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */ | |
41feb5ed | 262 | txstreams = (u8) WLC_BITSCNT(txchain); |
a9533e7e HP |
263 | if (txstreams > MAX_STREAMS_SUPPORTED) |
264 | return BCME_RANGE; | |
265 | ||
266 | if (txstreams == 1) { | |
267 | for (i = 0; i < NBANDS(wlc); i++) | |
268 | if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) != | |
269 | PHY_TXC1_MODE_SISO) | |
270 | || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) != | |
271 | PHY_TXC1_MODE_SISO)) { | |
272 | if (!force) | |
273 | return BCME_ERROR; | |
274 | ||
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__)); | |
280 | } | |
281 | if (RSPEC_STF | |
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__)); | |
286 | } | |
287 | } | |
288 | } | |
289 | ||
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]); | |
295 | wlc->stf->txant = | |
296 | (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF; | |
297 | _wlc_stf_phy_txant_upd(wlc); | |
298 | ||
299 | wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain, | |
300 | wlc->stf->rxchain); | |
301 | ||
302 | for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) | |
41feb5ed | 303 | wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]); |
a9533e7e HP |
304 | |
305 | return BCME_OK; | |
306 | } | |
307 | ||
7cc4a4c0 | 308 | int wlc_stf_rxchain_set(wlc_info_t *wlc, int32 int_val) |
a9533e7e | 309 | { |
41feb5ed GKH |
310 | u8 rxchain_cnt; |
311 | u8 rxchain = (u8) int_val; | |
312 | u8 mimops_mode; | |
313 | u8 old_rxchain, old_rxchain_cnt; | |
a9533e7e HP |
314 | |
315 | if (wlc->stf->rxchain == rxchain) | |
316 | return BCME_OK; | |
317 | ||
318 | if ((rxchain & ~wlc->stf->hw_rxchain) | |
319 | || !(rxchain & wlc->stf->hw_rxchain)) | |
320 | return BCME_RANGE; | |
321 | ||
41feb5ed | 322 | rxchain_cnt = (u8) WLC_BITSCNT(rxchain); |
a9533e7e HP |
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)) | |
326 | return BCME_RANGE; | |
327 | } | |
328 | ||
329 | if (APSTA_ENAB(wlc->pub) && (wlc->pub->associated)) | |
330 | return BCME_ASSOCIATED; | |
331 | ||
332 | old_rxchain = wlc->stf->rxchain; | |
333 | old_rxchain_cnt = wlc->stf->rxstreams; | |
334 | ||
335 | wlc->stf->rxchain = rxchain; | |
336 | wlc->stf->rxstreams = rxchain_cnt; | |
337 | ||
338 | if (rxchain_cnt != old_rxchain_cnt) { | |
339 | mimops_mode = | |
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, | |
344 | wlc->stf->rxchain); | |
345 | wlc_ht_mimops_cap_update(wlc, mimops_mode); | |
346 | if (wlc->pub->associated) | |
347 | wlc_mimops_action_ht_send(wlc, wlc->cfg, | |
348 | mimops_mode); | |
349 | return BCME_OK; | |
350 | } | |
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, | |
355 | wlc->stf->txchain, | |
356 | wlc->stf->rxchain); | |
357 | wlc_ht_mimops_cap_update(wlc, mimops_mode); | |
358 | } | |
359 | } else { | |
360 | wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain, | |
361 | wlc->stf->rxchain); | |
362 | wlc_ht_mimops_cap_update(wlc, mimops_mode); | |
363 | } | |
364 | } else if (old_rxchain != rxchain) | |
365 | wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain, | |
366 | wlc->stf->rxchain); | |
367 | ||
368 | return BCME_OK; | |
369 | } | |
370 | ||
371 | /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */ | |
7cc4a4c0 | 372 | int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band) |
a9533e7e HP |
373 | { |
374 | int ret_code = 0; | |
41feb5ed GKH |
375 | u8 prev_stf_ss; |
376 | u8 upd_stf_ss; | |
a9533e7e HP |
377 | |
378 | prev_stf_ss = wlc->stf->ss_opmode; | |
379 | ||
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 | |
29c4275a | 383 | && (wlc->stf->ss_algo_channel != (uint16) -1)) { |
a9533e7e HP |
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 | |
390 | : PHY_TXC1_MODE_CDD; | |
391 | } else { | |
392 | if (wlc->band != band) | |
393 | return ret_code; | |
394 | upd_stf_ss = (wlc->stf->no_cddstbc | |
395 | || (wlc->stf->txstreams == | |
396 | 1)) ? PHY_TXC1_MODE_SISO : band-> | |
397 | band_stf_ss_mode; | |
398 | } | |
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); | |
402 | } | |
403 | ||
404 | return ret_code; | |
405 | } | |
406 | ||
a2627bc0 JC |
407 | int BCMATTACHFN(wlc_stf_attach) (wlc_info_t *wlc) |
408 | { | |
a9533e7e HP |
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; | |
411 | ||
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 = | |
415 | PHY_TXC1_MODE_CDD; | |
416 | wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]); | |
417 | wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]); | |
418 | ||
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; | |
422 | ||
423 | if (WLC_STBC_CAP_PHY(wlc)) { | |
424 | wlc->stf->ss_algosel_auto = TRUE; | |
29c4275a | 425 | wlc->stf->ss_algo_channel = (uint16) -1; /* Init the default value */ |
a9533e7e HP |
426 | } |
427 | return 0; | |
428 | } | |
429 | ||
a2627bc0 JC |
430 | void BCMATTACHFN(wlc_stf_detach) (wlc_info_t *wlc) |
431 | { | |
a9533e7e HP |
432 | } |
433 | ||
7cc4a4c0 | 434 | int wlc_stf_ant_txant_validate(wlc_info_t *wlc, int8 val) |
a9533e7e HP |
435 | { |
436 | int bcmerror = BCME_OK; | |
437 | ||
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); | |
441 | ||
442 | switch (val) { | |
443 | case -1: | |
444 | val = ANT_TX_DEF; | |
445 | break; | |
446 | case 0: | |
447 | val = ANT_TX_FORCE_0; | |
448 | break; | |
449 | case 1: | |
450 | val = ANT_TX_FORCE_1; | |
451 | break; | |
452 | case 3: | |
453 | val = ANT_TX_LAST_RX; | |
454 | break; | |
455 | default: | |
456 | bcmerror = BCME_RANGE; | |
457 | break; | |
458 | } | |
459 | ||
460 | if (bcmerror == BCME_OK) | |
461 | wlc->stf->txant = (int8) val; | |
462 | ||
463 | return bcmerror; | |
464 | ||
465 | } | |
466 | ||
467 | /* | |
468 | * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain | |
469 | * change | |
470 | * | |
471 | * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to | |
472 | * achieve various tx/rx antenna selection schemes | |
473 | * | |
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 | |
480 | */ | |
7cc4a4c0 | 481 | static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc) |
a9533e7e HP |
482 | { |
483 | int8 txant; | |
484 | ||
485 | txant = (int8) wlc->stf->txant; | |
486 | ASSERT(txant == ANT_TX_FORCE_0 || txant == ANT_TX_FORCE_1 | |
487 | || txant == ANT_TX_LAST_RX); | |
488 | ||
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; | |
494 | ||
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; | |
499 | } | |
500 | } else { | |
501 | if (WLCISLCNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band)) | |
502 | wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST; | |
503 | else { | |
504 | /* keep this assert to catch out of sync wlc->stf->txcore */ | |
505 | ASSERT(wlc->stf->txchain > 0); | |
506 | wlc->stf->phytxant = | |
507 | wlc->stf->txchain << PHY_TXC_ANT_SHIFT; | |
508 | } | |
509 | } | |
510 | } else { | |
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; | |
515 | else | |
516 | wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST; | |
517 | } | |
518 | ||
519 | wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant); | |
520 | } | |
521 | ||
7cc4a4c0 | 522 | void wlc_stf_phy_txant_upd(wlc_info_t *wlc) |
a9533e7e HP |
523 | { |
524 | _wlc_stf_phy_txant_upd(wlc); | |
525 | } | |
526 | ||
a2627bc0 JC |
527 | void BCMATTACHFN(wlc_stf_phy_chain_calc) (wlc_info_t *wlc) |
528 | { | |
a9533e7e | 529 | /* get available rx/tx chains */ |
41feb5ed GKH |
530 | wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain"); |
531 | wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain"); | |
a9533e7e HP |
532 | |
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; | |
537 | } else { | |
538 | wlc->stf->hw_txchain = TXCHAIN_DEF; | |
539 | } | |
540 | } | |
541 | ||
542 | wlc->stf->txchain = wlc->stf->hw_txchain; | |
41feb5ed | 543 | wlc->stf->txstreams = (u8) WLC_BITSCNT(wlc->stf->hw_txchain); |
a9533e7e HP |
544 | |
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; | |
548 | } else { | |
549 | wlc->stf->hw_rxchain = RXCHAIN_DEF; | |
550 | } | |
551 | } | |
552 | ||
553 | wlc->stf->rxchain = wlc->stf->hw_rxchain; | |
41feb5ed | 554 | wlc->stf->rxstreams = (u8) WLC_BITSCNT(wlc->stf->hw_rxchain); |
a9533e7e HP |
555 | |
556 | /* initialize the txcore table */ | |
557 | bcopy(txcore_default, wlc->stf->txcore, sizeof(wlc->stf->txcore)); | |
558 | ||
559 | /* default spatial_policy */ | |
560 | wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION; | |
561 | wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION); | |
562 | } | |
563 | ||
7cc4a4c0 | 564 | static uint16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec) |
a9533e7e HP |
565 | { |
566 | uint16 phytxant = wlc->stf->phytxant; | |
567 | ||
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; | |
574 | return phytxant; | |
575 | } | |
576 | ||
7cc4a4c0 | 577 | uint16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec) |
a9533e7e HP |
578 | { |
579 | return _wlc_stf_phytxchain_sel(wlc, rspec); | |
580 | } | |
581 | ||
7cc4a4c0 | 582 | uint16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec) |
a9533e7e HP |
583 | { |
584 | uint16 phytxant = wlc->stf->phytxant; | |
585 | uint16 mask = PHY_TXC_ANT_MASK; | |
586 | ||
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; | |
592 | } | |
593 | phytxant |= phytxant & mask; | |
594 | return phytxant; | |
595 | } |