staging: brcm80211: removed unused stuff from proto/802.11.h
[pohmelfs.git] / drivers / staging / brcm80211 / brcmsmac / wlc_stf.c
bloba08db2e4ee69376ce9705a3a822d56eb6ab6373e
1 /*
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>
20 #include <bcmdefs.h>
21 #include <bcmutils.h>
22 #include <aiutils.h>
23 #include <bcmwifi.h>
24 #include <bcmnvram.h>
25 #include <sbdma.h>
27 #include "wlc_types.h"
28 #include "d11.h"
29 #include "wl_dbg.h"
30 #include "wlc_cfg.h"
31 #include "wlc_rate.h"
32 #include "wlc_scb.h"
33 #include "wlc_pub.h"
34 #include "wlc_key.h"
35 #include "phy/wlc_phy_hal.h"
36 #include "wlc_channel.h"
37 #include "wlc_main.h"
38 #include "wl_export.h"
39 #include "wlc_bmac.h"
40 #include "wlc_stf.h"
42 #define MIN_SPATIAL_EXPANSION 0
43 #define MAX_SPATIAL_EXPANSION 1
45 #define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
46 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
48 static bool wlc_stf_stbc_tx_set(struct wlc_info *wlc, s32 int_val);
49 static int wlc_stf_txcore_set(struct wlc_info *wlc, u8 Nsts, u8 val);
50 static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val);
51 static void wlc_stf_stbc_rx_ht_update(struct wlc_info *wlc, int val);
53 static void _wlc_stf_phy_txant_upd(struct wlc_info *wlc);
54 static u16 _wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec);
56 #define NSTS_1 1
57 #define NSTS_2 2
58 #define NSTS_3 3
59 #define NSTS_4 4
60 const u8 txcore_default[5] = {
61 (0), /* bitmap of the core enabled */
62 (0x01), /* For Nsts = 1, enable core 1 */
63 (0x03), /* For Nsts = 2, enable core 1 & 2 */
64 (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
65 (0x0f) /* For Nsts = 4, enable all cores */
68 static void wlc_stf_stbc_rx_ht_update(struct wlc_info *wlc, int val)
70 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
71 if (WLC_STF_SS_STBC_RX(wlc)) {
72 if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
73 return;
76 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_RX_STBC;
77 wlc->ht_cap.cap_info |= (val << IEEE80211_HT_CAP_RX_STBC_SHIFT);
79 if (wlc->pub->up) {
80 wlc_update_beacon(wlc);
81 wlc_update_probe_resp(wlc, true);
85 /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
86 void wlc_tempsense_upd(struct wlc_info *wlc)
88 wlc_phy_t *pi = wlc->band->pi;
89 uint active_chains, txchain;
91 /* Check if the chip is too hot. Disable one Tx chain, if it is */
92 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
93 active_chains = wlc_phy_stf_chain_active_get(pi);
94 txchain = active_chains & 0xf;
96 if (wlc->stf->txchain == wlc->stf->hw_txchain) {
97 if (txchain && (txchain < wlc->stf->hw_txchain)) {
98 /* turn off 1 tx chain */
99 wlc_stf_txchain_set(wlc, txchain, true);
101 } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
102 if (txchain == wlc->stf->hw_txchain) {
103 /* turn back on txchain */
104 wlc_stf_txchain_set(wlc, txchain, true);
109 void
110 wlc_stf_ss_algo_channel_get(struct wlc_info *wlc, u16 *ss_algo_channel,
111 chanspec_t chanspec)
113 tx_power_t power;
114 u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
116 /* Clear previous settings */
117 *ss_algo_channel = 0;
119 if (!wlc->pub->up) {
120 *ss_algo_channel = (u16) -1;
121 return;
124 wlc_phy_txpower_get_current(wlc->band->pi, &power,
125 CHSPEC_CHANNEL(chanspec));
127 siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
128 WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
129 cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
130 WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
131 stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
132 WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
134 /* criteria to choose stf mode */
136 /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
137 * on both chains
139 if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
140 setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
141 else
142 setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
144 /* STBC is ORed into to algo channel as STBC requires per-packet SCB capability check
145 * so cannot be default mode of operation. One of SISO, CDD have to be set
147 if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
148 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
151 static bool wlc_stf_stbc_tx_set(struct wlc_info *wlc, s32 int_val)
153 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
154 return false;
157 if ((int_val == ON) && (wlc->stf->txstreams == 1))
158 return false;
160 if ((int_val == OFF) || (wlc->stf->txstreams == 1)
161 || !WLC_STBC_CAP_PHY(wlc))
162 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
163 else
164 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_TX_STBC;
166 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
167 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
169 return true;
172 bool wlc_stf_stbc_rx_set(struct wlc_info *wlc, s32 int_val)
174 if ((int_val != HT_CAP_RX_STBC_NO)
175 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
176 return false;
179 if (WLC_STF_SS_STBC_RX(wlc)) {
180 if ((int_val != HT_CAP_RX_STBC_NO)
181 && (wlc->stf->rxstreams == 1))
182 return false;
185 wlc_stf_stbc_rx_ht_update(wlc, int_val);
186 return true;
189 static int wlc_stf_txcore_set(struct wlc_info *wlc, u8 Nsts, u8 core_mask)
191 BCMMSG(wlc->wiphy, "wl%d: Nsts %d core_mask %x\n",
192 wlc->pub->unit, Nsts, core_mask);
194 if (WLC_BITSCNT(core_mask) > wlc->stf->txstreams) {
195 core_mask = 0;
198 if ((WLC_BITSCNT(core_mask) == wlc->stf->txstreams) &&
199 ((core_mask & ~wlc->stf->txchain)
200 || !(core_mask & wlc->stf->txchain))) {
201 core_mask = wlc->stf->txchain;
204 wlc->stf->txcore[Nsts] = core_mask;
205 /* Nsts = 1..4, txcore index = 1..4 */
206 if (Nsts == 1) {
207 /* Needs to update beacon and ucode generated response
208 * frames when 1 stream core map changed
210 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
211 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
212 if (wlc->clk) {
213 wlc_suspend_mac_and_wait(wlc);
214 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
215 wlc_enable_mac(wlc);
219 return 0;
222 static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val)
224 int i;
225 u8 core_mask = 0;
227 BCMMSG(wlc->wiphy, "wl%d: val %x\n", wlc->pub->unit, val);
229 wlc->stf->spatial_policy = (s8) val;
230 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
231 core_mask = (val == MAX_SPATIAL_EXPANSION) ?
232 wlc->stf->txchain : txcore_default[i];
233 wlc_stf_txcore_set(wlc, (u8) i, core_mask);
235 return 0;
238 int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force)
240 u8 txchain = (u8) int_val;
241 u8 txstreams;
242 uint i;
244 if (wlc->stf->txchain == txchain)
245 return 0;
247 if ((txchain & ~wlc->stf->hw_txchain)
248 || !(txchain & wlc->stf->hw_txchain))
249 return -EINVAL;
251 /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
252 txstreams = (u8) WLC_BITSCNT(txchain);
253 if (txstreams > MAX_STREAMS_SUPPORTED)
254 return -EINVAL;
256 if (txstreams == 1) {
257 for (i = 0; i < NBANDS(wlc); i++)
258 if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) !=
259 PHY_TXC1_MODE_SISO)
260 || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) !=
261 PHY_TXC1_MODE_SISO)) {
262 if (!force)
263 return -EBADE;
265 /* over-write the override rspec */
266 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
267 != PHY_TXC1_MODE_SISO) {
268 wlc->bandstate[i]->rspec_override = 0;
269 wiphy_err(wlc->wiphy, "%s(): temp "
270 "sense override non-SISO "
271 "rspec_override\n",
272 __func__);
274 if (RSPEC_STF
275 (wlc->bandstate[i]->mrspec_override) !=
276 PHY_TXC1_MODE_SISO) {
277 wlc->bandstate[i]->mrspec_override = 0;
278 wiphy_err(wlc->wiphy, "%s(): temp "
279 "sense override non-SISO "
280 "mrspec_override\n",
281 __func__);
286 wlc->stf->txchain = txchain;
287 wlc->stf->txstreams = txstreams;
288 wlc_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
289 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
290 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
291 wlc->stf->txant =
292 (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
293 _wlc_stf_phy_txant_upd(wlc);
295 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
296 wlc->stf->rxchain);
298 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
299 wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
301 return 0;
304 /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
305 int wlc_stf_ss_update(struct wlc_info *wlc, struct wlcband *band)
307 int ret_code = 0;
308 u8 prev_stf_ss;
309 u8 upd_stf_ss;
311 prev_stf_ss = wlc->stf->ss_opmode;
313 /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
314 if (WLC_STBC_CAP_PHY(wlc) &&
315 wlc->stf->ss_algosel_auto
316 && (wlc->stf->ss_algo_channel != (u16) -1)) {
317 upd_stf_ss = (wlc->stf->no_cddstbc || (wlc->stf->txstreams == 1)
318 || isset(&wlc->stf->ss_algo_channel,
319 PHY_TXC1_MODE_SISO)) ? PHY_TXC1_MODE_SISO
320 : PHY_TXC1_MODE_CDD;
321 } else {
322 if (wlc->band != band)
323 return ret_code;
324 upd_stf_ss = (wlc->stf->no_cddstbc
325 || (wlc->stf->txstreams ==
326 1)) ? PHY_TXC1_MODE_SISO : band->
327 band_stf_ss_mode;
329 if (prev_stf_ss != upd_stf_ss) {
330 wlc->stf->ss_opmode = upd_stf_ss;
331 wlc_bmac_band_stf_ss_set(wlc->hw, upd_stf_ss);
334 return ret_code;
337 int wlc_stf_attach(struct wlc_info *wlc)
339 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
340 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
342 if (WLCISNPHY(wlc->band) &&
343 (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
344 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
345 PHY_TXC1_MODE_CDD;
346 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
347 wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
349 wlc_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
350 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
351 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
353 if (WLC_STBC_CAP_PHY(wlc)) {
354 wlc->stf->ss_algosel_auto = true;
355 wlc->stf->ss_algo_channel = (u16) -1; /* Init the default value */
357 return 0;
360 void wlc_stf_detach(struct wlc_info *wlc)
365 * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
366 * change
368 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
369 * achieve various tx/rx antenna selection schemes
371 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
372 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
373 * do tx-antenna selection for SISO transmissions
374 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
375 * do tx-antenna selection for SISO transmissions
376 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
378 static void _wlc_stf_phy_txant_upd(struct wlc_info *wlc)
380 s8 txant;
382 txant = (s8) wlc->stf->txant;
383 if (WLC_PHY_11N_CAP(wlc->band)) {
384 if (txant == ANT_TX_FORCE_0) {
385 wlc->stf->phytxant = PHY_TXC_ANT_0;
386 } else if (txant == ANT_TX_FORCE_1) {
387 wlc->stf->phytxant = PHY_TXC_ANT_1;
389 if (WLCISNPHY(wlc->band) &&
390 NREV_GE(wlc->band->phyrev, 3)
391 && NREV_LT(wlc->band->phyrev, 7)) {
392 wlc->stf->phytxant = PHY_TXC_ANT_2;
394 } else {
395 if (WLCISLCNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band))
396 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
397 else {
398 /* catch out of sync wlc->stf->txcore */
399 WARN_ON(wlc->stf->txchain <= 0);
400 wlc->stf->phytxant =
401 wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
404 } else {
405 if (txant == ANT_TX_FORCE_0)
406 wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
407 else if (txant == ANT_TX_FORCE_1)
408 wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
409 else
410 wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
413 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
416 void wlc_stf_phy_txant_upd(struct wlc_info *wlc)
418 _wlc_stf_phy_txant_upd(wlc);
421 void wlc_stf_phy_chain_calc(struct wlc_info *wlc)
423 /* get available rx/tx chains */
424 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
425 wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain");
427 /* these parameter are intended to be used for all PHY types */
428 if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
429 if (WLCISNPHY(wlc->band)) {
430 wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
431 } else {
432 wlc->stf->hw_txchain = TXCHAIN_DEF;
436 wlc->stf->txchain = wlc->stf->hw_txchain;
437 wlc->stf->txstreams = (u8) WLC_BITSCNT(wlc->stf->hw_txchain);
439 if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
440 if (WLCISNPHY(wlc->band)) {
441 wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
442 } else {
443 wlc->stf->hw_rxchain = RXCHAIN_DEF;
447 wlc->stf->rxchain = wlc->stf->hw_rxchain;
448 wlc->stf->rxstreams = (u8) WLC_BITSCNT(wlc->stf->hw_rxchain);
450 /* initialize the txcore table */
451 memcpy(wlc->stf->txcore, txcore_default, sizeof(wlc->stf->txcore));
453 /* default spatial_policy */
454 wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
455 wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
458 static u16 _wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec)
460 u16 phytxant = wlc->stf->phytxant;
462 if (RSPEC_STF(rspec) != PHY_TXC1_MODE_SISO) {
463 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
464 } else if (wlc->stf->txant == ANT_TX_DEF)
465 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
466 phytxant &= PHY_TXC_ANT_MASK;
467 return phytxant;
470 u16 wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec)
472 return _wlc_stf_phytxchain_sel(wlc, rspec);
475 u16 wlc_stf_d11hdrs_phyctl_txant(struct wlc_info *wlc, ratespec_t rspec)
477 u16 phytxant = wlc->stf->phytxant;
478 u16 mask = PHY_TXC_ANT_MASK;
480 /* for non-siso rates or default setting, use the available chains */
481 if (WLCISNPHY(wlc->band)) {
482 phytxant = _wlc_stf_phytxchain_sel(wlc, rspec);
483 mask = PHY_TXC_HTANT_MASK;
485 phytxant |= phytxant & mask;
486 return phytxant;