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 <net/mac80211.h>
22 #include "phy/phy_hal.h"
27 #define MIN_SPATIAL_EXPANSION 0
28 #define MAX_SPATIAL_EXPANSION 1
30 #define BRCMS_STF_SS_STBC_RX(wlc) (BRCMS_ISNPHY(wlc->band) && \
31 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
33 #define BRCMS_BITSCNT(x) brcmu_bitcount((u8 *)&(x), sizeof(u8))
40 static const u8 txcore_default
[5] = {
41 (0), /* bitmap of the core enabled */
42 (0x01), /* For Nsts = 1, enable core 1 */
43 (0x03), /* For Nsts = 2, enable core 1 & 2 */
44 (0x07), /* For Nsts = 3, enable core 1, 2 & 3 */
45 (0x0f) /* For Nsts = 4, enable all cores */
48 static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info
*wlc
, int val
)
50 /* MIMOPHYs rev3-6 cannot receive STBC with only one rx core active */
51 if (BRCMS_STF_SS_STBC_RX(wlc
)) {
52 if ((wlc
->stf
->rxstreams
== 1) && (val
!= HT_CAP_RX_STBC_NO
))
57 brcms_c_update_beacon(wlc
);
58 brcms_c_update_probe_resp(wlc
, true);
63 * every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to
64 * turn on/off txchain.
66 void brcms_c_tempsense_upd(struct brcms_c_info
*wlc
)
68 struct brcms_phy_pub
*pi
= wlc
->band
->pi
;
69 uint active_chains
, txchain
;
71 /* Check if the chip is too hot. Disable one Tx chain, if it is */
72 /* high 4 bits are for Rx chain, low 4 bits are for Tx chain */
73 active_chains
= wlc_phy_stf_chain_active_get(pi
);
74 txchain
= active_chains
& 0xf;
76 if (wlc
->stf
->txchain
== wlc
->stf
->hw_txchain
) {
77 if (txchain
&& (txchain
< wlc
->stf
->hw_txchain
))
78 /* turn off 1 tx chain */
79 brcms_c_stf_txchain_set(wlc
, txchain
, true);
80 } else if (wlc
->stf
->txchain
< wlc
->stf
->hw_txchain
) {
81 if (txchain
== wlc
->stf
->hw_txchain
)
82 /* turn back on txchain */
83 brcms_c_stf_txchain_set(wlc
, txchain
, true);
88 brcms_c_stf_ss_algo_channel_get(struct brcms_c_info
*wlc
, u16
*ss_algo_channel
,
91 struct tx_power power
;
92 u8 siso_mcs_id
, cdd_mcs_id
, stbc_mcs_id
;
94 /* Clear previous settings */
98 *ss_algo_channel
= (u16
) -1;
102 wlc_phy_txpower_get_current(wlc
->band
->pi
, &power
,
103 CHSPEC_CHANNEL(chanspec
));
105 siso_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
106 WL_TX_POWER_MCS40_SISO_FIRST
: WL_TX_POWER_MCS20_SISO_FIRST
;
107 cdd_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
108 WL_TX_POWER_MCS40_CDD_FIRST
: WL_TX_POWER_MCS20_CDD_FIRST
;
109 stbc_mcs_id
= (CHSPEC_IS40(chanspec
)) ?
110 WL_TX_POWER_MCS40_STBC_FIRST
: WL_TX_POWER_MCS20_STBC_FIRST
;
112 /* criteria to choose stf mode */
115 * the "+3dbm (12 0.25db units)" is to account for the fact that with
116 * CDD, tx occurs on both chains
118 if (power
.target
[siso_mcs_id
] > (power
.target
[cdd_mcs_id
] + 12))
119 setbit(ss_algo_channel
, PHY_TXC1_MODE_SISO
);
121 setbit(ss_algo_channel
, PHY_TXC1_MODE_CDD
);
124 * STBC is ORed into to algo channel as STBC requires per-packet SCB
125 * capability check so cannot be default mode of operation. One of
126 * SISO, CDD have to be set
128 if (power
.target
[siso_mcs_id
] <= (power
.target
[stbc_mcs_id
] + 12))
129 setbit(ss_algo_channel
, PHY_TXC1_MODE_STBC
);
132 static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info
*wlc
, s32 int_val
)
134 if ((int_val
!= AUTO
) && (int_val
!= OFF
) && (int_val
!= ON
))
137 if ((int_val
== ON
) && (wlc
->stf
->txstreams
== 1))
140 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= (s8
) int_val
;
141 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= (s8
) int_val
;
146 bool brcms_c_stf_stbc_rx_set(struct brcms_c_info
*wlc
, s32 int_val
)
148 if ((int_val
!= HT_CAP_RX_STBC_NO
)
149 && (int_val
!= HT_CAP_RX_STBC_ONE_STREAM
))
152 if (BRCMS_STF_SS_STBC_RX(wlc
)) {
153 if ((int_val
!= HT_CAP_RX_STBC_NO
)
154 && (wlc
->stf
->rxstreams
== 1))
158 brcms_c_stf_stbc_rx_ht_update(wlc
, int_val
);
162 static int brcms_c_stf_txcore_set(struct brcms_c_info
*wlc
, u8 Nsts
,
165 BCMMSG(wlc
->wiphy
, "wl%d: Nsts %d core_mask %x\n",
166 wlc
->pub
->unit
, Nsts
, core_mask
);
168 if (hweight8(core_mask
) > wlc
->stf
->txstreams
)
171 if ((hweight8(core_mask
) == wlc
->stf
->txstreams
) &&
172 ((core_mask
& ~wlc
->stf
->txchain
)
173 || !(core_mask
& wlc
->stf
->txchain
)))
174 core_mask
= wlc
->stf
->txchain
;
176 wlc
->stf
->txcore
[Nsts
] = core_mask
;
177 /* Nsts = 1..4, txcore index = 1..4 */
179 /* Needs to update beacon and ucode generated response
180 * frames when 1 stream core map changed
182 wlc
->stf
->phytxant
= core_mask
<< PHY_TXC_ANT_SHIFT
;
183 brcms_b_txant_set(wlc
->hw
, wlc
->stf
->phytxant
);
185 brcms_c_suspend_mac_and_wait(wlc
);
186 brcms_c_beacon_phytxctl_txant_upd(wlc
, wlc
->bcn_rspec
);
187 brcms_c_enable_mac(wlc
);
194 static int brcms_c_stf_spatial_policy_set(struct brcms_c_info
*wlc
, int val
)
199 BCMMSG(wlc
->wiphy
, "wl%d: val %x\n", wlc
->pub
->unit
, val
);
201 wlc
->stf
->spatial_policy
= (s8
) val
;
202 for (i
= 1; i
<= MAX_STREAMS_SUPPORTED
; i
++) {
203 core_mask
= (val
== MAX_SPATIAL_EXPANSION
) ?
204 wlc
->stf
->txchain
: txcore_default
[i
];
205 brcms_c_stf_txcore_set(wlc
, (u8
) i
, core_mask
);
211 * Centralized txant update function. call it whenever wlc->stf->txant and/or
212 * wlc->stf->txchain change.
214 * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
215 * achieve various tx/rx antenna selection schemes
217 * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7
218 * means auto(last rx).
219 * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7
220 * means last rx and do tx-antenna selection for SISO transmissions
221 * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7
222 * means last rx and do tx-antenna selection for SISO transmissions
223 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7
224 * means both cores active
226 static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info
*wlc
)
230 txant
= (s8
) wlc
->stf
->txant
;
231 if (BRCMS_PHY_11N_CAP(wlc
->band
)) {
232 if (txant
== ANT_TX_FORCE_0
) {
233 wlc
->stf
->phytxant
= PHY_TXC_ANT_0
;
234 } else if (txant
== ANT_TX_FORCE_1
) {
235 wlc
->stf
->phytxant
= PHY_TXC_ANT_1
;
237 if (BRCMS_ISNPHY(wlc
->band
) &&
238 NREV_GE(wlc
->band
->phyrev
, 3)
239 && NREV_LT(wlc
->band
->phyrev
, 7))
240 wlc
->stf
->phytxant
= PHY_TXC_ANT_2
;
242 if (BRCMS_ISLCNPHY(wlc
->band
) ||
243 BRCMS_ISSSLPNPHY(wlc
->band
))
244 wlc
->stf
->phytxant
= PHY_TXC_LCNPHY_ANT_LAST
;
246 /* catch out of sync wlc->stf->txcore */
247 WARN_ON(wlc
->stf
->txchain
<= 0);
249 wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
253 if (txant
== ANT_TX_FORCE_0
)
254 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_0
;
255 else if (txant
== ANT_TX_FORCE_1
)
256 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_1
;
258 wlc
->stf
->phytxant
= PHY_TXC_OLD_ANT_LAST
;
261 brcms_b_txant_set(wlc
->hw
, wlc
->stf
->phytxant
);
264 int brcms_c_stf_txchain_set(struct brcms_c_info
*wlc
, s32 int_val
, bool force
)
266 u8 txchain
= (u8
) int_val
;
270 if (wlc
->stf
->txchain
== txchain
)
273 if ((txchain
& ~wlc
->stf
->hw_txchain
)
274 || !(txchain
& wlc
->stf
->hw_txchain
))
278 * if nrate override is configured to be non-SISO STF mode, reject
279 * reducing txchain to 1
281 txstreams
= (u8
) hweight8(txchain
);
282 if (txstreams
> MAX_STREAMS_SUPPORTED
)
285 wlc
->stf
->txchain
= txchain
;
286 wlc
->stf
->txstreams
= txstreams
;
287 brcms_c_stf_stbc_tx_set(wlc
, wlc
->band
->band_stf_stbc_tx
);
288 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
289 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
291 (wlc
->stf
->txstreams
== 1) ? ANT_TX_FORCE_0
: ANT_TX_DEF
;
292 _brcms_c_stf_phy_txant_upd(wlc
);
294 wlc_phy_stf_chain_set(wlc
->band
->pi
, wlc
->stf
->txchain
,
297 for (i
= 1; i
<= MAX_STREAMS_SUPPORTED
; i
++)
298 brcms_c_stf_txcore_set(wlc
, (u8
) i
, txcore_default
[i
]);
304 * update wlc->stf->ss_opmode which represents the operational stf_ss mode
307 int brcms_c_stf_ss_update(struct brcms_c_info
*wlc
, struct brcms_band
*band
)
313 prev_stf_ss
= wlc
->stf
->ss_opmode
;
316 * NOTE: opmode can only be SISO or CDD as STBC is decided on a
319 if (BRCMS_STBC_CAP_PHY(wlc
) &&
320 wlc
->stf
->ss_algosel_auto
321 && (wlc
->stf
->ss_algo_channel
!= (u16
) -1)) {
322 upd_stf_ss
= (wlc
->stf
->txstreams
== 1 ||
323 isset(&wlc
->stf
->ss_algo_channel
,
324 PHY_TXC1_MODE_SISO
)) ?
325 PHY_TXC1_MODE_SISO
: PHY_TXC1_MODE_CDD
;
327 if (wlc
->band
!= band
)
329 upd_stf_ss
= (wlc
->stf
->txstreams
== 1) ?
330 PHY_TXC1_MODE_SISO
: band
->band_stf_ss_mode
;
332 if (prev_stf_ss
!= upd_stf_ss
) {
333 wlc
->stf
->ss_opmode
= upd_stf_ss
;
334 brcms_b_band_stf_ss_set(wlc
->hw
, upd_stf_ss
);
340 int brcms_c_stf_attach(struct brcms_c_info
*wlc
)
342 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_ss_mode
= PHY_TXC1_MODE_SISO
;
343 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_ss_mode
= PHY_TXC1_MODE_CDD
;
345 if (BRCMS_ISNPHY(wlc
->band
) &&
346 (wlc_phy_txpower_hw_ctrl_get(wlc
->band
->pi
) != PHY_TPC_HW_ON
))
347 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_ss_mode
=
349 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_2G_INDEX
]);
350 brcms_c_stf_ss_update(wlc
, wlc
->bandstate
[BAND_5G_INDEX
]);
352 brcms_c_stf_stbc_rx_ht_update(wlc
, HT_CAP_RX_STBC_NO
);
353 wlc
->bandstate
[BAND_2G_INDEX
]->band_stf_stbc_tx
= OFF
;
354 wlc
->bandstate
[BAND_5G_INDEX
]->band_stf_stbc_tx
= OFF
;
356 if (BRCMS_STBC_CAP_PHY(wlc
)) {
357 wlc
->stf
->ss_algosel_auto
= true;
358 /* Init the default value */
359 wlc
->stf
->ss_algo_channel
= (u16
) -1;
364 void brcms_c_stf_detach(struct brcms_c_info
*wlc
)
368 void brcms_c_stf_phy_txant_upd(struct brcms_c_info
*wlc
)
370 _brcms_c_stf_phy_txant_upd(wlc
);
373 void brcms_c_stf_phy_chain_calc(struct brcms_c_info
*wlc
)
375 /* get available rx/tx chains */
376 wlc
->stf
->hw_txchain
= (u8
) getintvar(wlc
->hw
->sih
, "txchain");
377 wlc
->stf
->hw_rxchain
= (u8
) getintvar(wlc
->hw
->sih
, "rxchain");
379 /* these parameter are intended to be used for all PHY types */
380 if (wlc
->stf
->hw_txchain
== 0 || wlc
->stf
->hw_txchain
== 0xf) {
381 if (BRCMS_ISNPHY(wlc
->band
))
382 wlc
->stf
->hw_txchain
= TXCHAIN_DEF_NPHY
;
384 wlc
->stf
->hw_txchain
= TXCHAIN_DEF
;
387 wlc
->stf
->txchain
= wlc
->stf
->hw_txchain
;
388 wlc
->stf
->txstreams
= (u8
) hweight8(wlc
->stf
->hw_txchain
);
390 if (wlc
->stf
->hw_rxchain
== 0 || wlc
->stf
->hw_rxchain
== 0xf) {
391 if (BRCMS_ISNPHY(wlc
->band
))
392 wlc
->stf
->hw_rxchain
= RXCHAIN_DEF_NPHY
;
394 wlc
->stf
->hw_rxchain
= RXCHAIN_DEF
;
397 wlc
->stf
->rxchain
= wlc
->stf
->hw_rxchain
;
398 wlc
->stf
->rxstreams
= (u8
) hweight8(wlc
->stf
->hw_rxchain
);
400 /* initialize the txcore table */
401 memcpy(wlc
->stf
->txcore
, txcore_default
, sizeof(wlc
->stf
->txcore
));
403 /* default spatial_policy */
404 wlc
->stf
->spatial_policy
= MIN_SPATIAL_EXPANSION
;
405 brcms_c_stf_spatial_policy_set(wlc
, MIN_SPATIAL_EXPANSION
);
408 static u16
_brcms_c_stf_phytxchain_sel(struct brcms_c_info
*wlc
,
411 u16 phytxant
= wlc
->stf
->phytxant
;
413 if (rspec_stf(rspec
) != PHY_TXC1_MODE_SISO
)
414 phytxant
= wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
415 else if (wlc
->stf
->txant
== ANT_TX_DEF
)
416 phytxant
= wlc
->stf
->txchain
<< PHY_TXC_ANT_SHIFT
;
417 phytxant
&= PHY_TXC_ANT_MASK
;
421 u16
brcms_c_stf_phytxchain_sel(struct brcms_c_info
*wlc
, u32 rspec
)
423 return _brcms_c_stf_phytxchain_sel(wlc
, rspec
);
426 u16
brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info
*wlc
, u32 rspec
)
428 u16 phytxant
= wlc
->stf
->phytxant
;
429 u16 mask
= PHY_TXC_ANT_MASK
;
431 /* for non-siso rates or default setting, use the available chains */
432 if (BRCMS_ISNPHY(wlc
->band
)) {
433 phytxant
= _brcms_c_stf_phytxchain_sel(wlc
, rspec
);
434 mask
= PHY_TXC_HTANT_MASK
;
436 phytxant
|= phytxant
& mask
;