This source file includes following definitions.
- brcms_c_stf_stbc_rx_ht_update
- brcms_c_tempsense_upd
- brcms_c_stf_ss_algo_channel_get
- brcms_c_stf_stbc_tx_set
- brcms_c_stf_stbc_rx_set
- brcms_c_stf_txcore_set
- brcms_c_stf_spatial_policy_set
- _brcms_c_stf_phy_txant_upd
- brcms_c_stf_txchain_set
- brcms_c_stf_ss_update
- brcms_c_stf_attach
- brcms_c_stf_detach
- brcms_c_stf_phy_txant_upd
- brcms_c_stf_phy_chain_calc
- _brcms_c_stf_phytxchain_sel
- brcms_c_stf_phytxchain_sel
- brcms_c_stf_d11hdrs_phyctl_txant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <net/mac80211.h>
18
19 #include "types.h"
20 #include "d11.h"
21 #include "rate.h"
22 #include "phy/phy_hal.h"
23 #include "channel.h"
24 #include "main.h"
25 #include "stf.h"
26 #include "debug.h"
27
28 #define MIN_SPATIAL_EXPANSION 0
29 #define MAX_SPATIAL_EXPANSION 1
30
31 #define BRCMS_STF_SS_STBC_RX(wlc) (BRCMS_ISNPHY(wlc->band) && \
32 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
33
34 #define NSTS_1 1
35 #define NSTS_2 2
36 #define NSTS_3 3
37 #define NSTS_4 4
38
39 static const u8 txcore_default[5] = {
40 (0),
41 (0x01),
42 (0x03),
43 (0x07),
44 (0x0f)
45 };
46
47 static void brcms_c_stf_stbc_rx_ht_update(struct brcms_c_info *wlc, int val)
48 {
49
50 if (BRCMS_STF_SS_STBC_RX(wlc)) {
51 if ((wlc->stf->rxstreams == 1) && (val != HT_CAP_RX_STBC_NO))
52 return;
53 }
54
55 if (wlc->pub->up) {
56 brcms_c_update_beacon(wlc);
57 brcms_c_update_probe_resp(wlc, true);
58 }
59 }
60
61
62
63
64
65 void brcms_c_tempsense_upd(struct brcms_c_info *wlc)
66 {
67 struct brcms_phy_pub *pi = wlc->band->pi;
68 uint active_chains, txchain;
69
70
71
72 active_chains = wlc_phy_stf_chain_active_get(pi);
73 txchain = active_chains & 0xf;
74
75 if (wlc->stf->txchain == wlc->stf->hw_txchain) {
76 if (txchain && (txchain < wlc->stf->hw_txchain))
77
78 brcms_c_stf_txchain_set(wlc, txchain, true);
79 } else if (wlc->stf->txchain < wlc->stf->hw_txchain) {
80 if (txchain == wlc->stf->hw_txchain)
81
82 brcms_c_stf_txchain_set(wlc, txchain, true);
83 }
84 }
85
86 void
87 brcms_c_stf_ss_algo_channel_get(struct brcms_c_info *wlc, u16 *ss_algo_channel,
88 u16 chanspec)
89 {
90 struct tx_power power = { };
91 u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
92
93
94 *ss_algo_channel = 0;
95
96 if (!wlc->pub->up) {
97 *ss_algo_channel = (u16) -1;
98 return;
99 }
100
101 wlc_phy_txpower_get_current(wlc->band->pi, &power,
102 CHSPEC_CHANNEL(chanspec));
103
104 siso_mcs_id = (CHSPEC_IS40(chanspec)) ?
105 WL_TX_POWER_MCS40_SISO_FIRST : WL_TX_POWER_MCS20_SISO_FIRST;
106 cdd_mcs_id = (CHSPEC_IS40(chanspec)) ?
107 WL_TX_POWER_MCS40_CDD_FIRST : WL_TX_POWER_MCS20_CDD_FIRST;
108 stbc_mcs_id = (CHSPEC_IS40(chanspec)) ?
109 WL_TX_POWER_MCS40_STBC_FIRST : WL_TX_POWER_MCS20_STBC_FIRST;
110
111
112
113
114
115
116
117 if (power.target[siso_mcs_id] > (power.target[cdd_mcs_id] + 12))
118 setbit(ss_algo_channel, PHY_TXC1_MODE_SISO);
119 else
120 setbit(ss_algo_channel, PHY_TXC1_MODE_CDD);
121
122
123
124
125
126
127 if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
128 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
129 }
130
131 static bool brcms_c_stf_stbc_tx_set(struct brcms_c_info *wlc, s32 int_val)
132 {
133 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON))
134 return false;
135
136 if ((int_val == ON) && (wlc->stf->txstreams == 1))
137 return false;
138
139 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
140 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
141
142 return true;
143 }
144
145 bool brcms_c_stf_stbc_rx_set(struct brcms_c_info *wlc, s32 int_val)
146 {
147 if ((int_val != HT_CAP_RX_STBC_NO)
148 && (int_val != HT_CAP_RX_STBC_ONE_STREAM))
149 return false;
150
151 if (BRCMS_STF_SS_STBC_RX(wlc)) {
152 if ((int_val != HT_CAP_RX_STBC_NO)
153 && (wlc->stf->rxstreams == 1))
154 return false;
155 }
156
157 brcms_c_stf_stbc_rx_ht_update(wlc, int_val);
158 return true;
159 }
160
161 static int brcms_c_stf_txcore_set(struct brcms_c_info *wlc, u8 Nsts,
162 u8 core_mask)
163 {
164 brcms_dbg_ht(wlc->hw->d11core, "wl%d: Nsts %d core_mask %x\n",
165 wlc->pub->unit, Nsts, core_mask);
166
167 if (hweight8(core_mask) > wlc->stf->txstreams)
168 core_mask = 0;
169
170 if ((hweight8(core_mask) == wlc->stf->txstreams) &&
171 ((core_mask & ~wlc->stf->txchain)
172 || !(core_mask & wlc->stf->txchain)))
173 core_mask = wlc->stf->txchain;
174
175 wlc->stf->txcore[Nsts] = core_mask;
176
177 if (Nsts == 1) {
178
179
180
181 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
182 brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
183 if (wlc->clk) {
184 brcms_c_suspend_mac_and_wait(wlc);
185 brcms_c_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
186 brcms_c_enable_mac(wlc);
187 }
188 }
189
190 return 0;
191 }
192
193 static int brcms_c_stf_spatial_policy_set(struct brcms_c_info *wlc, int val)
194 {
195 int i;
196 u8 core_mask = 0;
197
198 brcms_dbg_ht(wlc->hw->d11core, "wl%d: val %x\n", wlc->pub->unit,
199 val);
200
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);
206 }
207 return 0;
208 }
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 static void _brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
227 {
228 s8 txant;
229
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;
236
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;
241 } else {
242 if (BRCMS_ISLCNPHY(wlc->band) ||
243 BRCMS_ISSSLPNPHY(wlc->band))
244 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
245 else {
246
247 WARN_ON(wlc->stf->txchain <= 0);
248 wlc->stf->phytxant =
249 wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
250 }
251 }
252 } else {
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;
257 else
258 wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
259 }
260
261 brcms_b_txant_set(wlc->hw, wlc->stf->phytxant);
262 }
263
264 int brcms_c_stf_txchain_set(struct brcms_c_info *wlc, s32 int_val, bool force)
265 {
266 u8 txchain = (u8) int_val;
267 u8 txstreams;
268 uint i;
269
270 if (wlc->stf->txchain == txchain)
271 return 0;
272
273 if ((txchain & ~wlc->stf->hw_txchain)
274 || !(txchain & wlc->stf->hw_txchain))
275 return -EINVAL;
276
277
278
279
280
281 txstreams = (u8) hweight8(txchain);
282 if (txstreams > MAX_STREAMS_SUPPORTED)
283 return -EINVAL;
284
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]);
290 wlc->stf->txant =
291 (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
292 _brcms_c_stf_phy_txant_upd(wlc);
293
294 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
295 wlc->stf->rxchain);
296
297 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
298 brcms_c_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
299
300 return 0;
301 }
302
303
304
305
306
307 int brcms_c_stf_ss_update(struct brcms_c_info *wlc, struct brcms_band *band)
308 {
309 int ret_code = 0;
310 u8 prev_stf_ss;
311 u8 upd_stf_ss;
312
313 prev_stf_ss = wlc->stf->ss_opmode;
314
315
316
317
318
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;
326 } else {
327 if (wlc->band != band)
328 return ret_code;
329 upd_stf_ss = (wlc->stf->txstreams == 1) ?
330 PHY_TXC1_MODE_SISO : band->band_stf_ss_mode;
331 }
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);
335 }
336
337 return ret_code;
338 }
339
340 int brcms_c_stf_attach(struct brcms_c_info *wlc)
341 {
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;
344
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 =
348 PHY_TXC1_MODE_CDD;
349 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
350 brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
351
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;
355
356 if (BRCMS_STBC_CAP_PHY(wlc)) {
357 wlc->stf->ss_algosel_auto = true;
358
359 wlc->stf->ss_algo_channel = (u16) -1;
360 }
361 return 0;
362 }
363
364 void brcms_c_stf_detach(struct brcms_c_info *wlc)
365 {
366 }
367
368 void brcms_c_stf_phy_txant_upd(struct brcms_c_info *wlc)
369 {
370 _brcms_c_stf_phy_txant_upd(wlc);
371 }
372
373 void brcms_c_stf_phy_chain_calc(struct brcms_c_info *wlc)
374 {
375 struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
376
377
378 wlc->stf->hw_txchain = sprom->txchain;
379 wlc->stf->hw_rxchain = sprom->rxchain;
380
381
382 if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
383 if (BRCMS_ISNPHY(wlc->band))
384 wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
385 else
386 wlc->stf->hw_txchain = TXCHAIN_DEF;
387 }
388
389 wlc->stf->txchain = wlc->stf->hw_txchain;
390 wlc->stf->txstreams = (u8) hweight8(wlc->stf->hw_txchain);
391
392 if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
393 if (BRCMS_ISNPHY(wlc->band))
394 wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
395 else
396 wlc->stf->hw_rxchain = RXCHAIN_DEF;
397 }
398
399 wlc->stf->rxchain = wlc->stf->hw_rxchain;
400 wlc->stf->rxstreams = (u8) hweight8(wlc->stf->hw_rxchain);
401
402
403 memcpy(wlc->stf->txcore, txcore_default, sizeof(wlc->stf->txcore));
404
405
406 wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
407 brcms_c_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
408 }
409
410 static u16 _brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc,
411 u32 rspec)
412 {
413 u16 phytxant = wlc->stf->phytxant;
414
415 if (rspec_stf(rspec) != PHY_TXC1_MODE_SISO)
416 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
417 else if (wlc->stf->txant == ANT_TX_DEF)
418 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
419 phytxant &= PHY_TXC_ANT_MASK;
420 return phytxant;
421 }
422
423 u16 brcms_c_stf_phytxchain_sel(struct brcms_c_info *wlc, u32 rspec)
424 {
425 return _brcms_c_stf_phytxchain_sel(wlc, rspec);
426 }
427
428 u16 brcms_c_stf_d11hdrs_phyctl_txant(struct brcms_c_info *wlc, u32 rspec)
429 {
430 u16 phytxant = wlc->stf->phytxant;
431 u16 mask = PHY_TXC_ANT_MASK;
432
433
434 if (BRCMS_ISNPHY(wlc->band)) {
435 phytxant = _brcms_c_stf_phytxchain_sel(wlc, rspec);
436 mask = PHY_TXC_HTANT_MASK;
437 }
438 phytxant |= phytxant & mask;
439 return phytxant;
440 }