1*b4c3e9b5SBjoern A. Zeeb /*
2*b4c3e9b5SBjoern A. Zeeb * Copyright (c) 2010 Broadcom Corporation
3*b4c3e9b5SBjoern A. Zeeb *
4*b4c3e9b5SBjoern A. Zeeb * Permission to use, copy, modify, and/or distribute this software for any
5*b4c3e9b5SBjoern A. Zeeb * purpose with or without fee is hereby granted, provided that the above
6*b4c3e9b5SBjoern A. Zeeb * copyright notice and this permission notice appear in all copies.
7*b4c3e9b5SBjoern A. Zeeb *
8*b4c3e9b5SBjoern A. Zeeb * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*b4c3e9b5SBjoern A. Zeeb * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*b4c3e9b5SBjoern A. Zeeb * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11*b4c3e9b5SBjoern A. Zeeb * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*b4c3e9b5SBjoern A. Zeeb * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13*b4c3e9b5SBjoern A. Zeeb * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14*b4c3e9b5SBjoern A. Zeeb * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*b4c3e9b5SBjoern A. Zeeb */
16*b4c3e9b5SBjoern A. Zeeb
17*b4c3e9b5SBjoern A. Zeeb #include <net/mac80211.h>
18*b4c3e9b5SBjoern A. Zeeb
19*b4c3e9b5SBjoern A. Zeeb #include "types.h"
20*b4c3e9b5SBjoern A. Zeeb #include "d11.h"
21*b4c3e9b5SBjoern A. Zeeb #include "rate.h"
22*b4c3e9b5SBjoern A. Zeeb #include "phy/phy_hal.h"
23*b4c3e9b5SBjoern A. Zeeb #include "channel.h"
24*b4c3e9b5SBjoern A. Zeeb #include "main.h"
25*b4c3e9b5SBjoern A. Zeeb #include "stf.h"
26*b4c3e9b5SBjoern A. Zeeb #include "debug.h"
27*b4c3e9b5SBjoern A. Zeeb
28*b4c3e9b5SBjoern A. Zeeb #define MIN_SPATIAL_EXPANSION 0
29*b4c3e9b5SBjoern A. Zeeb #define MAX_SPATIAL_EXPANSION 1
30*b4c3e9b5SBjoern A. Zeeb
31*b4c3e9b5SBjoern A. Zeeb #define BRCMS_STF_SS_STBC_RX(wlc) (BRCMS_ISNPHY(wlc->band) && \
32*b4c3e9b5SBjoern A. Zeeb NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
33*b4c3e9b5SBjoern A. Zeeb
34*b4c3e9b5SBjoern A. Zeeb #define NSTS_1 1
35*b4c3e9b5SBjoern A. Zeeb #define NSTS_2 2
36*b4c3e9b5SBjoern A. Zeeb #define NSTS_3 3
37*b4c3e9b5SBjoern A. Zeeb #define NSTS_4 4
38*b4c3e9b5SBjoern A. Zeeb
39*b4c3e9b5SBjoern A. Zeeb static const u8 txcore_default[5] = {
40*b4c3e9b5SBjoern A. Zeeb (0), /* bitmap of the core enabled */
41*b4c3e9b5SBjoern A. Zeeb (0x01), /* For Nsts = 1, enable core 1 */
42*b4c3e9b5SBjoern A. Zeeb (0x03), /* For Nsts = 2, enable core 1 & 2 */
43*b4c3e9b5SBjoern A. Zeeb (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
44*b4c3e9b5SBjoern A. Zeeb (0x0f) /* For Nsts = 4, enable all cores */
45*b4c3e9b5SBjoern A. Zeeb };
46*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info * wlc,int val)47*b4c3e9b5SBjoern A. Zeeb static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info *wlc, int val)
48*b4c3e9b5SBjoern A. Zeeb {
49*b4c3e9b5SBjoern A. Zeeb /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
50*b4c3e9b5SBjoern A. Zeeb if (BRCMS_STF_SS_STBC_RX(wlc)) {
51*b4c3e9b5SBjoern A. Zeeb if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
52*b4c3e9b5SBjoern A. Zeeb return;
53*b4c3e9b5SBjoern A. Zeeb }
54*b4c3e9b5SBjoern A. Zeeb
55*b4c3e9b5SBjoern A. Zeeb if (wlc->pub->up) {
56*b4c3e9b5SBjoern A. Zeeb brcms_c_update_beacon(wlc);
57*b4c3e9b5SBjoern A. Zeeb brcms_c_update_probe_resp(wlc, true);
58*b4c3e9b5SBjoern A. Zeeb }
59*b4c3e9b5SBjoern A. Zeeb }
60*b4c3e9b5SBjoern A. Zeeb
61*b4c3e9b5SBjoern A. Zeeb /*
62*b4c3e9b5SBjoern A. Zeeb * every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to
63*b4c3e9b5SBjoern A. Zeeb * turn on/off txchain.
64*b4c3e9b5SBjoern A. Zeeb */
brcms_c_tempsense_upd(struct brcms_c_info * wlc)65*b4c3e9b5SBjoern A. Zeeb void brcms_c_tempsense_upd(struct brcms_c_info *wlc)
66*b4c3e9b5SBjoern A. Zeeb {
67*b4c3e9b5SBjoern A. Zeeb struct brcms_phy_pub *pi = wlc->band->pi;
68*b4c3e9b5SBjoern A. Zeeb uint active_chains, txchain;
69*b4c3e9b5SBjoern A. Zeeb
70*b4c3e9b5SBjoern A. Zeeb /* Check if the chip is too hot. Disable one Tx chain, if it is */
71*b4c3e9b5SBjoern A. Zeeb /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
72*b4c3e9b5SBjoern A. Zeeb active_chains = wlc_phy_stf_chain_active_get(pi);
73*b4c3e9b5SBjoern A. Zeeb txchain = active_chains & 0xf;
74*b4c3e9b5SBjoern A. Zeeb
75*b4c3e9b5SBjoern A. Zeeb if (wlc->stf->txchain == wlc->stf->hw_txchain) {
76*b4c3e9b5SBjoern A. Zeeb if (txchain && (txchain < wlc->stf->hw_txchain))
77*b4c3e9b5SBjoern A. Zeeb /* turn off 1 tx chain */
78*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_txchain_set(wlc, txchain, true);
79*b4c3e9b5SBjoern A. Zeeb } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
80*b4c3e9b5SBjoern A. Zeeb if (txchain == wlc->stf->hw_txchain)
81*b4c3e9b5SBjoern A. Zeeb /* turn back on txchain */
82*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_txchain_set(wlc, txchain, true);
83*b4c3e9b5SBjoern A. Zeeb }
84*b4c3e9b5SBjoern A. Zeeb }
85*b4c3e9b5SBjoern A. Zeeb
86*b4c3e9b5SBjoern A. Zeeb void
brcms_c_stf_ss_algo_channel_get(struct brcms_c_info * wlc,u16 * ss_algo_channel,u16 chanspec)87*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_ss_algo_channel_get(struct brcms_c_info *wlc, u16 *ss_algo_channel,
88*b4c3e9b5SBjoern A. Zeeb u16 chanspec)
89*b4c3e9b5SBjoern A. Zeeb {
90*b4c3e9b5SBjoern A. Zeeb struct tx_power power = { };
91*b4c3e9b5SBjoern A. Zeeb u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
92*b4c3e9b5SBjoern A. Zeeb
93*b4c3e9b5SBjoern A. Zeeb /* Clear previous settings */
94*b4c3e9b5SBjoern A. Zeeb *ss_algo_channel = 0;
95*b4c3e9b5SBjoern A. Zeeb
96*b4c3e9b5SBjoern A. Zeeb if (!wlc->pub->up) {
97*b4c3e9b5SBjoern A. Zeeb *ss_algo_channel = (u16) -1;
98*b4c3e9b5SBjoern A. Zeeb return;
99*b4c3e9b5SBjoern A. Zeeb }
100*b4c3e9b5SBjoern A. Zeeb
101*b4c3e9b5SBjoern A. Zeeb wlc_phy_txpower_get_current(wlc->band->pi, &power,
102*b4c3e9b5SBjoern A. Zeeb CHSPEC_CHANNEL(chanspec));
103*b4c3e9b5SBjoern A. Zeeb
104*b4c3e9b5SBjoern A. Zeeb siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
105*b4c3e9b5SBjoern A. Zeeb WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
106*b4c3e9b5SBjoern A. Zeeb cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
107*b4c3e9b5SBjoern A. Zeeb WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
108*b4c3e9b5SBjoern A. Zeeb stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
109*b4c3e9b5SBjoern A. Zeeb WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
110*b4c3e9b5SBjoern A. Zeeb
111*b4c3e9b5SBjoern A. Zeeb /* criteria to choose stf mode */
112*b4c3e9b5SBjoern A. Zeeb
113*b4c3e9b5SBjoern A. Zeeb /*
114*b4c3e9b5SBjoern A. Zeeb * the "+3dbm (12 0.25db units)" is to account for the fact that with
115*b4c3e9b5SBjoern A. Zeeb * CDD, tx occurs on both chains
116*b4c3e9b5SBjoern A. Zeeb */
117*b4c3e9b5SBjoern A. Zeeb if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
118*b4c3e9b5SBjoern A. Zeeb setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
119*b4c3e9b5SBjoern A. Zeeb else
120*b4c3e9b5SBjoern A. Zeeb setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
121*b4c3e9b5SBjoern A. Zeeb
122*b4c3e9b5SBjoern A. Zeeb /*
123*b4c3e9b5SBjoern A. Zeeb * STBC is ORed into to algo channel as STBC requires per-packet SCB
124*b4c3e9b5SBjoern A. Zeeb * capability check so cannot be default mode of operation. One of
125*b4c3e9b5SBjoern A. Zeeb * SISO, CDD have to be set
126*b4c3e9b5SBjoern A. Zeeb */
127*b4c3e9b5SBjoern A. Zeeb if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
128*b4c3e9b5SBjoern A. Zeeb setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
129*b4c3e9b5SBjoern A. Zeeb }
130*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_stbc_tx_set(struct brcms_c_info * wlc,s32 int_val)131*b4c3e9b5SBjoern A. Zeeb static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info *wlc, s32 int_val)
132*b4c3e9b5SBjoern A. Zeeb {
133*b4c3e9b5SBjoern A. Zeeb if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON))
134*b4c3e9b5SBjoern A. Zeeb return false;
135*b4c3e9b5SBjoern A. Zeeb
136*b4c3e9b5SBjoern A. Zeeb if ((int_val == ON) && (wlc->stf->txstreams == 1))
137*b4c3e9b5SBjoern A. Zeeb return false;
138*b4c3e9b5SBjoern A. Zeeb
139*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
140*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
141*b4c3e9b5SBjoern A. Zeeb
142*b4c3e9b5SBjoern A. Zeeb return true;
143*b4c3e9b5SBjoern A. Zeeb }
144*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_stbc_rx_set(struct brcms_c_info * wlc,s32 int_val)145*b4c3e9b5SBjoern A. Zeeb bool brcms_c_stf_stbc_rx_set(struct brcms_c_info *wlc, s32 int_val)
146*b4c3e9b5SBjoern A. Zeeb {
147*b4c3e9b5SBjoern A. Zeeb if ((int_val != HT_CAP_RX_STBC_NO)
148*b4c3e9b5SBjoern A. Zeeb && (int_val != HT_CAP_RX_STBC_ONE_STREAM))
149*b4c3e9b5SBjoern A. Zeeb return false;
150*b4c3e9b5SBjoern A. Zeeb
151*b4c3e9b5SBjoern A. Zeeb if (BRCMS_STF_SS_STBC_RX(wlc)) {
152*b4c3e9b5SBjoern A. Zeeb if ((int_val != HT_CAP_RX_STBC_NO)
153*b4c3e9b5SBjoern A. Zeeb && (wlc->stf->rxstreams == 1))
154*b4c3e9b5SBjoern A. Zeeb return false;
155*b4c3e9b5SBjoern A. Zeeb }
156*b4c3e9b5SBjoern A. Zeeb
157*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_stbc_rx_ht_update(wlc, int_val);
158*b4c3e9b5SBjoern A. Zeeb return true;
159*b4c3e9b5SBjoern A. Zeeb }
160*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_txcore_set(struct brcms_c_info * wlc,u8 Nsts,u8 core_mask)161*b4c3e9b5SBjoern A. Zeeb static int brcms_c_stf_txcore_set(struct brcms_c_info *wlc, u8 Nsts,
162*b4c3e9b5SBjoern A. Zeeb u8 core_mask)
163*b4c3e9b5SBjoern A. Zeeb {
164*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core, "wl%d: Nsts %d core_mask %x\n",
165*b4c3e9b5SBjoern A. Zeeb wlc->pub->unit, Nsts, core_mask);
166*b4c3e9b5SBjoern A. Zeeb
167*b4c3e9b5SBjoern A. Zeeb if (hweight8(core_mask) > wlc->stf->txstreams)
168*b4c3e9b5SBjoern A. Zeeb core_mask = 0;
169*b4c3e9b5SBjoern A. Zeeb
170*b4c3e9b5SBjoern A. Zeeb if ((hweight8(core_mask) == wlc->stf->txstreams) &&
171*b4c3e9b5SBjoern A. Zeeb ((core_mask & ~wlc->stf->txchain)
172*b4c3e9b5SBjoern A. Zeeb || !(core_mask & wlc->stf->txchain)))
173*b4c3e9b5SBjoern A. Zeeb core_mask = wlc->stf->txchain;
174*b4c3e9b5SBjoern A. Zeeb
175*b4c3e9b5SBjoern A. Zeeb wlc->stf->txcore[Nsts] = core_mask;
176*b4c3e9b5SBjoern A. Zeeb /* Nsts = 1..4, txcore index = 1..4 */
177*b4c3e9b5SBjoern A. Zeeb if (Nsts == 1) {
178*b4c3e9b5SBjoern A. Zeeb /* Needs to update beacon and ucode generated response
179*b4c3e9b5SBjoern A. Zeeb * frames when 1 stream core map changed
180*b4c3e9b5SBjoern A. Zeeb */
181*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
182*b4c3e9b5SBjoern A. Zeeb brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
183*b4c3e9b5SBjoern A. Zeeb if (wlc->clk) {
184*b4c3e9b5SBjoern A. Zeeb brcms_c_suspend_mac_and_wait(wlc);
185*b4c3e9b5SBjoern A. Zeeb brcms_c_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
186*b4c3e9b5SBjoern A. Zeeb brcms_c_enable_mac(wlc);
187*b4c3e9b5SBjoern A. Zeeb }
188*b4c3e9b5SBjoern A. Zeeb }
189*b4c3e9b5SBjoern A. Zeeb
190*b4c3e9b5SBjoern A. Zeeb return 0;
191*b4c3e9b5SBjoern A. Zeeb }
192*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_spatial_policy_set(struct brcms_c_info * wlc,int val)193*b4c3e9b5SBjoern A. Zeeb static int brcms_c_stf_spatial_policy_set(struct brcms_c_info *wlc, int val)
194*b4c3e9b5SBjoern A. Zeeb {
195*b4c3e9b5SBjoern A. Zeeb int i;
196*b4c3e9b5SBjoern A. Zeeb u8 core_mask = 0;
197*b4c3e9b5SBjoern A. Zeeb
198*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core, "wl%d: val %x\n", wlc->pub->unit,
199*b4c3e9b5SBjoern A. Zeeb val);
200*b4c3e9b5SBjoern A. Zeeb
201*b4c3e9b5SBjoern A. Zeeb wlc->stf->spatial_policy = (s8) val;
202*b4c3e9b5SBjoern A. Zeeb for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
203*b4c3e9b5SBjoern A. Zeeb core_mask = (val == MAX_SPATIAL_EXPANSION) ?
204*b4c3e9b5SBjoern A. Zeeb wlc->stf->txchain : txcore_default[i];
205*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_txcore_set(wlc, (u8) i, core_mask);
206*b4c3e9b5SBjoern A. Zeeb }
207*b4c3e9b5SBjoern A. Zeeb return 0;
208*b4c3e9b5SBjoern A. Zeeb }
209*b4c3e9b5SBjoern A. Zeeb
210*b4c3e9b5SBjoern A. Zeeb /*
211*b4c3e9b5SBjoern A. Zeeb * Centralized txant update function. call it whenever wlc->stf->txant and/or
212*b4c3e9b5SBjoern A. Zeeb * wlc->stf->txchain change.
213*b4c3e9b5SBjoern A. Zeeb *
214*b4c3e9b5SBjoern A. Zeeb * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
215*b4c3e9b5SBjoern A. Zeeb * achieve various tx/rx antenna selection schemes
216*b4c3e9b5SBjoern A. Zeeb *
217*b4c3e9b5SBjoern A. Zeeb * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7
218*b4c3e9b5SBjoern A. Zeeb * means auto(last rx).
219*b4c3e9b5SBjoern A. Zeeb * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7
220*b4c3e9b5SBjoern A. Zeeb * means last rx and do tx-antenna selection for SISO transmissions
221*b4c3e9b5SBjoern A. Zeeb * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7
222*b4c3e9b5SBjoern A. Zeeb * means last rx and do tx-antenna selection for SISO transmissions
223*b4c3e9b5SBjoern A. Zeeb * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7
224*b4c3e9b5SBjoern A. Zeeb * means both cores active
225*b4c3e9b5SBjoern A. Zeeb */
_brcms_c_stf_phy_txant_upd(struct brcms_c_info * wlc)226*b4c3e9b5SBjoern A. Zeeb static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
227*b4c3e9b5SBjoern A. Zeeb {
228*b4c3e9b5SBjoern A. Zeeb s8 txant;
229*b4c3e9b5SBjoern A. Zeeb
230*b4c3e9b5SBjoern A. Zeeb txant = (s8) wlc->stf->txant;
231*b4c3e9b5SBjoern A. Zeeb if (BRCMS_PHY_11N_CAP(wlc->band)) {
232*b4c3e9b5SBjoern A. Zeeb if (txant == ANT_TX_FORCE_0) {
233*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_ANT_0;
234*b4c3e9b5SBjoern A. Zeeb } else if (txant == ANT_TX_FORCE_1) {
235*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_ANT_1;
236*b4c3e9b5SBjoern A. Zeeb
237*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band) &&
238*b4c3e9b5SBjoern A. Zeeb NREV_GE(wlc->band->phyrev, 3)
239*b4c3e9b5SBjoern A. Zeeb && NREV_LT(wlc->band->phyrev, 7))
240*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_ANT_2;
241*b4c3e9b5SBjoern A. Zeeb } else {
242*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISLCNPHY(wlc->band) ||
243*b4c3e9b5SBjoern A. Zeeb BRCMS_ISSSLPNPHY(wlc->band))
244*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
245*b4c3e9b5SBjoern A. Zeeb else {
246*b4c3e9b5SBjoern A. Zeeb /* catch out of sync wlc->stf->txcore */
247*b4c3e9b5SBjoern A. Zeeb WARN_ON(wlc->stf->txchain <= 0);
248*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant =
249*b4c3e9b5SBjoern A. Zeeb wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
250*b4c3e9b5SBjoern A. Zeeb }
251*b4c3e9b5SBjoern A. Zeeb }
252*b4c3e9b5SBjoern A. Zeeb } else {
253*b4c3e9b5SBjoern A. Zeeb if (txant == ANT_TX_FORCE_0)
254*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
255*b4c3e9b5SBjoern A. Zeeb else if (txant == ANT_TX_FORCE_1)
256*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
257*b4c3e9b5SBjoern A. Zeeb else
258*b4c3e9b5SBjoern A. Zeeb wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
259*b4c3e9b5SBjoern A. Zeeb }
260*b4c3e9b5SBjoern A. Zeeb
261*b4c3e9b5SBjoern A. Zeeb brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
262*b4c3e9b5SBjoern A. Zeeb }
263*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_txchain_set(struct brcms_c_info * wlc,s32 int_val,bool force)264*b4c3e9b5SBjoern A. Zeeb int brcms_c_stf_txchain_set(struct brcms_c_info *wlc, s32 int_val, bool force)
265*b4c3e9b5SBjoern A. Zeeb {
266*b4c3e9b5SBjoern A. Zeeb u8 txchain = (u8) int_val;
267*b4c3e9b5SBjoern A. Zeeb u8 txstreams;
268*b4c3e9b5SBjoern A. Zeeb uint i;
269*b4c3e9b5SBjoern A. Zeeb
270*b4c3e9b5SBjoern A. Zeeb if (wlc->stf->txchain == txchain)
271*b4c3e9b5SBjoern A. Zeeb return 0;
272*b4c3e9b5SBjoern A. Zeeb
273*b4c3e9b5SBjoern A. Zeeb if ((txchain & ~wlc->stf->hw_txchain)
274*b4c3e9b5SBjoern A. Zeeb || !(txchain & wlc->stf->hw_txchain))
275*b4c3e9b5SBjoern A. Zeeb return -EINVAL;
276*b4c3e9b5SBjoern A. Zeeb
277*b4c3e9b5SBjoern A. Zeeb /*
278*b4c3e9b5SBjoern A. Zeeb * if nrate override is configured to be non-SISO STF mode, reject
279*b4c3e9b5SBjoern A. Zeeb * reducing txchain to 1
280*b4c3e9b5SBjoern A. Zeeb */
281*b4c3e9b5SBjoern A. Zeeb txstreams = (u8) hweight8(txchain);
282*b4c3e9b5SBjoern A. Zeeb if (txstreams > MAX_STREAMS_SUPPORTED)
283*b4c3e9b5SBjoern A. Zeeb return -EINVAL;
284*b4c3e9b5SBjoern A. Zeeb
285*b4c3e9b5SBjoern A. Zeeb wlc->stf->txchain = txchain;
286*b4c3e9b5SBjoern A. Zeeb wlc->stf->txstreams = txstreams;
287*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
288*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
289*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
290*b4c3e9b5SBjoern A. Zeeb wlc->stf->txant =
291*b4c3e9b5SBjoern A. Zeeb (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
292*b4c3e9b5SBjoern A. Zeeb _brcms_c_stf_phy_txant_upd(wlc);
293*b4c3e9b5SBjoern A. Zeeb
294*b4c3e9b5SBjoern A. Zeeb wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
295*b4c3e9b5SBjoern A. Zeeb wlc->stf->rxchain);
296*b4c3e9b5SBjoern A. Zeeb
297*b4c3e9b5SBjoern A. Zeeb for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
298*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
299*b4c3e9b5SBjoern A. Zeeb
300*b4c3e9b5SBjoern A. Zeeb return 0;
301*b4c3e9b5SBjoern A. Zeeb }
302*b4c3e9b5SBjoern A. Zeeb
303*b4c3e9b5SBjoern A. Zeeb /*
304*b4c3e9b5SBjoern A. Zeeb * update wlc->stf->ss_opmode which represents the operational stf_ss mode
305*b4c3e9b5SBjoern A. Zeeb * we're using
306*b4c3e9b5SBjoern A. Zeeb */
brcms_c_stf_ss_update(struct brcms_c_info * wlc,struct brcms_band * band)307*b4c3e9b5SBjoern A. Zeeb void brcms_c_stf_ss_update(struct brcms_c_info *wlc, struct brcms_band *band)
308*b4c3e9b5SBjoern A. Zeeb {
309*b4c3e9b5SBjoern A. Zeeb u8 prev_stf_ss;
310*b4c3e9b5SBjoern A. Zeeb u8 upd_stf_ss;
311*b4c3e9b5SBjoern A. Zeeb
312*b4c3e9b5SBjoern A. Zeeb prev_stf_ss = wlc->stf->ss_opmode;
313*b4c3e9b5SBjoern A. Zeeb
314*b4c3e9b5SBjoern A. Zeeb /*
315*b4c3e9b5SBjoern A. Zeeb * NOTE: opmode can only be SISO or CDD as STBC is decided on a
316*b4c3e9b5SBjoern A. Zeeb * per-packet basis
317*b4c3e9b5SBjoern A. Zeeb */
318*b4c3e9b5SBjoern A. Zeeb if (BRCMS_STBC_CAP_PHY(wlc) &&
319*b4c3e9b5SBjoern A. Zeeb wlc->stf->ss_algosel_auto
320*b4c3e9b5SBjoern A. Zeeb && (wlc->stf->ss_algo_channel != (u16) -1)) {
321*b4c3e9b5SBjoern A. Zeeb upd_stf_ss = (wlc->stf->txstreams == 1 ||
322*b4c3e9b5SBjoern A. Zeeb isset(&wlc->stf->ss_algo_channel,
323*b4c3e9b5SBjoern A. Zeeb PHY_TXC1_MODE_SISO)) ?
324*b4c3e9b5SBjoern A. Zeeb PHY_TXC1_MODE_SISO : PHY_TXC1_MODE_CDD;
325*b4c3e9b5SBjoern A. Zeeb } else {
326*b4c3e9b5SBjoern A. Zeeb if (wlc->band != band)
327*b4c3e9b5SBjoern A. Zeeb return;
328*b4c3e9b5SBjoern A. Zeeb upd_stf_ss = (wlc->stf->txstreams == 1) ?
329*b4c3e9b5SBjoern A. Zeeb PHY_TXC1_MODE_SISO : band->band_stf_ss_mode;
330*b4c3e9b5SBjoern A. Zeeb }
331*b4c3e9b5SBjoern A. Zeeb if (prev_stf_ss != upd_stf_ss) {
332*b4c3e9b5SBjoern A. Zeeb wlc->stf->ss_opmode = upd_stf_ss;
333*b4c3e9b5SBjoern A. Zeeb brcms_b_band_stf_ss_set(wlc->hw, upd_stf_ss);
334*b4c3e9b5SBjoern A. Zeeb }
335*b4c3e9b5SBjoern A. Zeeb }
336*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_attach(struct brcms_c_info * wlc)337*b4c3e9b5SBjoern A. Zeeb int brcms_c_stf_attach(struct brcms_c_info *wlc)
338*b4c3e9b5SBjoern A. Zeeb {
339*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
340*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
341*b4c3e9b5SBjoern A. Zeeb
342*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band) &&
343*b4c3e9b5SBjoern A. Zeeb (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
344*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
345*b4c3e9b5SBjoern A. Zeeb PHY_TXC1_MODE_CDD;
346*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
347*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
348*b4c3e9b5SBjoern A. Zeeb
349*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
350*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
351*b4c3e9b5SBjoern A. Zeeb wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
352*b4c3e9b5SBjoern A. Zeeb
353*b4c3e9b5SBjoern A. Zeeb if (BRCMS_STBC_CAP_PHY(wlc)) {
354*b4c3e9b5SBjoern A. Zeeb wlc->stf->ss_algosel_auto = true;
355*b4c3e9b5SBjoern A. Zeeb /* Init the default value */
356*b4c3e9b5SBjoern A. Zeeb wlc->stf->ss_algo_channel = (u16) -1;
357*b4c3e9b5SBjoern A. Zeeb }
358*b4c3e9b5SBjoern A. Zeeb return 0;
359*b4c3e9b5SBjoern A. Zeeb }
360*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_detach(struct brcms_c_info * wlc)361*b4c3e9b5SBjoern A. Zeeb void brcms_c_stf_detach(struct brcms_c_info *wlc)
362*b4c3e9b5SBjoern A. Zeeb {
363*b4c3e9b5SBjoern A. Zeeb }
364*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_phy_txant_upd(struct brcms_c_info * wlc)365*b4c3e9b5SBjoern A. Zeeb void brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
366*b4c3e9b5SBjoern A. Zeeb {
367*b4c3e9b5SBjoern A. Zeeb _brcms_c_stf_phy_txant_upd(wlc);
368*b4c3e9b5SBjoern A. Zeeb }
369*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_phy_chain_calc(struct brcms_c_info * wlc)370*b4c3e9b5SBjoern A. Zeeb void brcms_c_stf_phy_chain_calc(struct brcms_c_info *wlc)
371*b4c3e9b5SBjoern A. Zeeb {
372*b4c3e9b5SBjoern A. Zeeb struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
373*b4c3e9b5SBjoern A. Zeeb
374*b4c3e9b5SBjoern A. Zeeb /* get available rx/tx chains */
375*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_txchain = sprom->txchain;
376*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_rxchain = sprom->rxchain;
377*b4c3e9b5SBjoern A. Zeeb
378*b4c3e9b5SBjoern A. Zeeb /* these parameter are intended to be used for all PHY types */
379*b4c3e9b5SBjoern A. Zeeb if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
380*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band))
381*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
382*b4c3e9b5SBjoern A. Zeeb else
383*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_txchain = TXCHAIN_DEF;
384*b4c3e9b5SBjoern A. Zeeb }
385*b4c3e9b5SBjoern A. Zeeb
386*b4c3e9b5SBjoern A. Zeeb wlc->stf->txchain = wlc->stf->hw_txchain;
387*b4c3e9b5SBjoern A. Zeeb wlc->stf->txstreams = (u8) hweight8(wlc->stf->hw_txchain);
388*b4c3e9b5SBjoern A. Zeeb
389*b4c3e9b5SBjoern A. Zeeb if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
390*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band))
391*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
392*b4c3e9b5SBjoern A. Zeeb else
393*b4c3e9b5SBjoern A. Zeeb wlc->stf->hw_rxchain = RXCHAIN_DEF;
394*b4c3e9b5SBjoern A. Zeeb }
395*b4c3e9b5SBjoern A. Zeeb
396*b4c3e9b5SBjoern A. Zeeb wlc->stf->rxchain = wlc->stf->hw_rxchain;
397*b4c3e9b5SBjoern A. Zeeb wlc->stf->rxstreams = (u8) hweight8(wlc->stf->hw_rxchain);
398*b4c3e9b5SBjoern A. Zeeb
399*b4c3e9b5SBjoern A. Zeeb /* initialize the txcore table */
400*b4c3e9b5SBjoern A. Zeeb memcpy(wlc->stf->txcore, txcore_default, sizeof(wlc->stf->txcore));
401*b4c3e9b5SBjoern A. Zeeb
402*b4c3e9b5SBjoern A. Zeeb /* default spatial_policy */
403*b4c3e9b5SBjoern A. Zeeb wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
404*b4c3e9b5SBjoern A. Zeeb brcms_c_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
405*b4c3e9b5SBjoern A. Zeeb }
406*b4c3e9b5SBjoern A. Zeeb
_brcms_c_stf_phytxchain_sel(struct brcms_c_info * wlc,u32 rspec)407*b4c3e9b5SBjoern A. Zeeb static u16 _brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc,
408*b4c3e9b5SBjoern A. Zeeb u32 rspec)
409*b4c3e9b5SBjoern A. Zeeb {
410*b4c3e9b5SBjoern A. Zeeb u16 phytxant = wlc->stf->phytxant;
411*b4c3e9b5SBjoern A. Zeeb
412*b4c3e9b5SBjoern A. Zeeb if (rspec_stf(rspec) != PHY_TXC1_MODE_SISO)
413*b4c3e9b5SBjoern A. Zeeb phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
414*b4c3e9b5SBjoern A. Zeeb else if (wlc->stf->txant == ANT_TX_DEF)
415*b4c3e9b5SBjoern A. Zeeb phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
416*b4c3e9b5SBjoern A. Zeeb phytxant &= PHY_TXC_ANT_MASK;
417*b4c3e9b5SBjoern A. Zeeb return phytxant;
418*b4c3e9b5SBjoern A. Zeeb }
419*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_phytxchain_sel(struct brcms_c_info * wlc,u32 rspec)420*b4c3e9b5SBjoern A. Zeeb u16 brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc, u32 rspec)
421*b4c3e9b5SBjoern A. Zeeb {
422*b4c3e9b5SBjoern A. Zeeb return _brcms_c_stf_phytxchain_sel(wlc, rspec);
423*b4c3e9b5SBjoern A. Zeeb }
424*b4c3e9b5SBjoern A. Zeeb
brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info * wlc,u32 rspec)425*b4c3e9b5SBjoern A. Zeeb u16 brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info *wlc, u32 rspec)
426*b4c3e9b5SBjoern A. Zeeb {
427*b4c3e9b5SBjoern A. Zeeb u16 phytxant = wlc->stf->phytxant;
428*b4c3e9b5SBjoern A. Zeeb u16 mask = PHY_TXC_ANT_MASK;
429*b4c3e9b5SBjoern A. Zeeb
430*b4c3e9b5SBjoern A. Zeeb /* for non-siso rates or default setting, use the available chains */
431*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band)) {
432*b4c3e9b5SBjoern A. Zeeb phytxant = _brcms_c_stf_phytxchain_sel(wlc, rspec);
433*b4c3e9b5SBjoern A. Zeeb mask = PHY_TXC_HTANT_MASK;
434*b4c3e9b5SBjoern A. Zeeb }
435*b4c3e9b5SBjoern A. Zeeb phytxant |= phytxant & mask;
436*b4c3e9b5SBjoern A. Zeeb return phytxant;
437*b4c3e9b5SBjoern A. Zeeb }
438