a1db289a1209c5fce3f7e267c09fa8a39dbc3f22
[pandora-kernel.git] / drivers / staging / brcm80211 / sys / wlc_stf.c
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>
19 #include <linux/kernel.h>
20 #include <linuxver.h>
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 <bcmwifi.h>
29 #include <d11.h>
30 #include <wlc_rate.h>
31 #include <wlc_pub.h>
32 #include <wlc_key.h>
33 #include <wlc_channel.h>
34 #include <wlc_bsscfg.h>
35 #include <wlc_mac80211.h>
36 #include <wlc_scb.h>
37 #include <wl_export.h>
38 #include <wlc_bmac.h>
39 #include <wlc_stf.h>
40
41 #define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
42         NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
43
44 static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc);
45 static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val);
46 static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 val);
47 static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val);
48 static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val);
49
50 static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc);
51 static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec);
52
53 #define NSTS_1  1
54 #define NSTS_2  2
55 #define NSTS_3  3
56 #define NSTS_4  4
57 const u8 txcore_default[5] = {
58         (0),                    /* bitmap of the core enabled */
59         (0x01),                 /* For Nsts = 1, enable core 1 */
60         (0x03),                 /* For Nsts = 2, enable core 1 & 2 */
61         (0x07),                 /* For Nsts = 3, enable core 1, 2 & 3 */
62         (0x0f)                  /* For Nsts = 4, enable all cores */
63 };
64
65 static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val)
66 {
67         ASSERT((val == HT_CAP_RX_STBC_NO)
68                || (val == HT_CAP_RX_STBC_ONE_STREAM));
69
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;
74         }
75
76         wlc->ht_cap.cap &= ~HT_CAP_RX_STBC_MASK;
77         wlc->ht_cap.cap |= (val << HT_CAP_RX_STBC_SHIFT);
78
79         if (wlc->pub->up) {
80                 wlc_update_beacon(wlc);
81                 wlc_update_probe_resp(wlc, true);
82         }
83 }
84
85 /* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
86 void wlc_tempsense_upd(wlc_info_t *wlc)
87 {
88         wlc_phy_t *pi = wlc->band->pi;
89         uint active_chains, txchain;
90
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;
95
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);
100                 }
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);
105                 }
106         }
107 }
108
109 void
110 wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, u16 *ss_algo_channel,
111                             chanspec_t chanspec)
112 {
113         tx_power_t power;
114         u8 siso_mcs_id, cdd_mcs_id, stbc_mcs_id;
115
116         /* Clear previous settings */
117         *ss_algo_channel = 0;
118
119         if (!wlc->pub->up) {
120                 *ss_algo_channel = (u16) -1;
121                 return;
122         }
123
124         wlc_phy_txpower_get_current(wlc->band->pi, &power,
125                                     CHSPEC_CHANNEL(chanspec));
126
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;
133
134         /* criteria to choose stf mode */
135
136         /* the "+3dbm (12 0.25db units)" is to account for the fact that with CDD, tx occurs
137          * on both chains
138          */
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);
143
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
146          */
147         if (power.target[siso_mcs_id] <= (power.target[stbc_mcs_id] + 12))
148                 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
149 }
150
151 static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc)
152 {
153         return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT;
154 }
155
156 static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val)
157 {
158         if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
159                 return false;
160         }
161
162         if ((int_val == ON) && (wlc->stf->txstreams == 1))
163                 return false;
164
165         if ((int_val == OFF) || (wlc->stf->txstreams == 1)
166             || !WLC_STBC_CAP_PHY(wlc))
167                 wlc->ht_cap.cap &= ~HT_CAP_TX_STBC;
168         else
169                 wlc->ht_cap.cap |= HT_CAP_TX_STBC;
170
171         wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = (s8) int_val;
172         wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = (s8) int_val;
173
174         return true;
175 }
176
177 bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val)
178 {
179         if ((int_val != HT_CAP_RX_STBC_NO)
180             && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
181                 return false;
182         }
183
184         if (WLC_STF_SS_STBC_RX(wlc)) {
185                 if ((int_val != HT_CAP_RX_STBC_NO)
186                     && (wlc->stf->rxstreams == 1))
187                         return false;
188         }
189
190         wlc_stf_stbc_rx_ht_update(wlc, int_val);
191         return true;
192 }
193
194 static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask)
195 {
196         WL_TRACE(("wl%d: %s: Nsts %d core_mask %x\n",
197                   wlc->pub->unit, __func__, Nsts, core_mask));
198
199         ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED));
200
201         if (WLC_BITSCNT(core_mask) > wlc->stf->txstreams) {
202                 core_mask = 0;
203         }
204
205         if ((WLC_BITSCNT(core_mask) == wlc->stf->txstreams) &&
206             ((core_mask & ~wlc->stf->txchain)
207              || !(core_mask & wlc->stf->txchain))) {
208                 core_mask = wlc->stf->txchain;
209         }
210
211         ASSERT(!core_mask || Nsts <= WLC_BITSCNT(core_mask));
212
213         wlc->stf->txcore[Nsts] = core_mask;
214         /* Nsts = 1..4, txcore index = 1..4 */
215         if (Nsts == 1) {
216                 /* Needs to update beacon and ucode generated response
217                  * frames when 1 stream core map changed
218                  */
219                 wlc->stf->phytxant = core_mask << PHY_TXC_ANT_SHIFT;
220                 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
221                 if (wlc->clk) {
222                         wlc_suspend_mac_and_wait(wlc);
223                         wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
224                         wlc_enable_mac(wlc);
225                 }
226         }
227
228         return BCME_OK;
229 }
230
231 static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val)
232 {
233         int i;
234         u8 core_mask = 0;
235
236         WL_TRACE(("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val));
237
238         wlc->stf->spatial_policy = (s8) val;
239         for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
240                 core_mask = (val == MAX_SPATIAL_EXPANSION) ?
241                     wlc->stf->txchain : txcore_default[i];
242                 wlc_stf_txcore_set(wlc, (u8) i, core_mask);
243         }
244         return BCME_OK;
245 }
246
247 int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force)
248 {
249         u8 txchain = (u8) int_val;
250         u8 txstreams;
251         uint i;
252
253         if (wlc->stf->txchain == txchain)
254                 return BCME_OK;
255
256         if ((txchain & ~wlc->stf->hw_txchain)
257             || !(txchain & wlc->stf->hw_txchain))
258                 return BCME_RANGE;
259
260         /* if nrate override is configured to be non-SISO STF mode, reject reducing txchain to 1 */
261         txstreams = (u8) WLC_BITSCNT(txchain);
262         if (txstreams > MAX_STREAMS_SUPPORTED)
263                 return BCME_RANGE;
264
265         if (txstreams == 1) {
266                 for (i = 0; i < NBANDS(wlc); i++)
267                         if ((RSPEC_STF(wlc->bandstate[i]->rspec_override) !=
268                              PHY_TXC1_MODE_SISO)
269                             || (RSPEC_STF(wlc->bandstate[i]->mrspec_override) !=
270                                 PHY_TXC1_MODE_SISO)) {
271                                 if (!force)
272                                         return BCME_ERROR;
273
274                                 /* over-write the override rspec */
275                                 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
276                                     != PHY_TXC1_MODE_SISO) {
277                                         wlc->bandstate[i]->rspec_override = 0;
278                                         WL_ERROR(("%s(): temp sense override non-SISO" " rspec_override.\n", __func__));
279                                 }
280                                 if (RSPEC_STF
281                                     (wlc->bandstate[i]->mrspec_override) !=
282                                     PHY_TXC1_MODE_SISO) {
283                                         wlc->bandstate[i]->mrspec_override = 0;
284                                         WL_ERROR(("%s(): temp sense override non-SISO" " mrspec_override.\n", __func__));
285                                 }
286                         }
287         }
288
289         wlc->stf->txchain = txchain;
290         wlc->stf->txstreams = txstreams;
291         wlc_stf_stbc_tx_set(wlc, wlc->band->band_stf_stbc_tx);
292         wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
293         wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
294         wlc->stf->txant =
295             (wlc->stf->txstreams == 1) ? ANT_TX_FORCE_0 : ANT_TX_DEF;
296         _wlc_stf_phy_txant_upd(wlc);
297
298         wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
299                               wlc->stf->rxchain);
300
301         for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++)
302                 wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]);
303
304         return BCME_OK;
305 }
306
307 int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val)
308 {
309         u8 rxchain_cnt;
310         u8 rxchain = (u8) int_val;
311         u8 mimops_mode;
312         u8 old_rxchain, old_rxchain_cnt;
313
314         if (wlc->stf->rxchain == rxchain)
315                 return BCME_OK;
316
317         if ((rxchain & ~wlc->stf->hw_rxchain)
318             || !(rxchain & wlc->stf->hw_rxchain))
319                 return BCME_RANGE;
320
321         rxchain_cnt = (u8) WLC_BITSCNT(rxchain);
322         if (WLC_STF_SS_STBC_RX(wlc)) {
323                 if ((rxchain_cnt == 1)
324                     && (wlc_stf_stbc_rx_get(wlc) != HT_CAP_RX_STBC_NO))
325                         return BCME_RANGE;
326         }
327
328         if (APSTA_ENAB(wlc->pub) && (wlc->pub->associated))
329                 return BCME_ASSOCIATED;
330
331         old_rxchain = wlc->stf->rxchain;
332         old_rxchain_cnt = wlc->stf->rxstreams;
333
334         wlc->stf->rxchain = rxchain;
335         wlc->stf->rxstreams = rxchain_cnt;
336
337         if (rxchain_cnt != old_rxchain_cnt) {
338                 mimops_mode =
339                     (rxchain_cnt == 1) ? HT_CAP_MIMO_PS_ON : HT_CAP_MIMO_PS_OFF;
340                 wlc->mimops_PM = mimops_mode;
341                 if (AP_ENAB(wlc->pub)) {
342                         wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
343                                               wlc->stf->rxchain);
344                         wlc_ht_mimops_cap_update(wlc, mimops_mode);
345                         if (wlc->pub->associated)
346                                 wlc_mimops_action_ht_send(wlc, wlc->cfg,
347                                                           mimops_mode);
348                         return BCME_OK;
349                 }
350                 if (wlc->pub->associated) {
351                         if (mimops_mode == HT_CAP_MIMO_PS_OFF) {
352                                 /* if mimops is off, turn on the Rx chain first */
353                                 wlc_phy_stf_chain_set(wlc->band->pi,
354                                                       wlc->stf->txchain,
355                                                       wlc->stf->rxchain);
356                                 wlc_ht_mimops_cap_update(wlc, mimops_mode);
357                         }
358                 } else {
359                         wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
360                                               wlc->stf->rxchain);
361                         wlc_ht_mimops_cap_update(wlc, mimops_mode);
362                 }
363         } else if (old_rxchain != rxchain)
364                 wlc_phy_stf_chain_set(wlc->band->pi, wlc->stf->txchain,
365                                       wlc->stf->rxchain);
366
367         return BCME_OK;
368 }
369
370 /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
371 int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band)
372 {
373         int ret_code = 0;
374         u8 prev_stf_ss;
375         u8 upd_stf_ss;
376
377         prev_stf_ss = wlc->stf->ss_opmode;
378
379         /* NOTE: opmode can only be SISO or CDD as STBC is decided on a per-packet basis */
380         if (WLC_STBC_CAP_PHY(wlc) &&
381             wlc->stf->ss_algosel_auto
382             && (wlc->stf->ss_algo_channel != (u16) -1)) {
383                 ASSERT(isset(&wlc->stf->ss_algo_channel, PHY_TXC1_MODE_CDD)
384                        || isset(&wlc->stf->ss_algo_channel,
385                                 PHY_TXC1_MODE_SISO));
386                 upd_stf_ss = (wlc->stf->no_cddstbc || (wlc->stf->txstreams == 1)
387                               || isset(&wlc->stf->ss_algo_channel,
388                                        PHY_TXC1_MODE_SISO)) ? PHY_TXC1_MODE_SISO
389                     : PHY_TXC1_MODE_CDD;
390         } else {
391                 if (wlc->band != band)
392                         return ret_code;
393                 upd_stf_ss = (wlc->stf->no_cddstbc
394                               || (wlc->stf->txstreams ==
395                                   1)) ? PHY_TXC1_MODE_SISO : band->
396                     band_stf_ss_mode;
397         }
398         if (prev_stf_ss != upd_stf_ss) {
399                 wlc->stf->ss_opmode = upd_stf_ss;
400                 wlc_bmac_band_stf_ss_set(wlc->hw, upd_stf_ss);
401         }
402
403         return ret_code;
404 }
405
406 int wlc_stf_attach(wlc_info_t *wlc)
407 {
408         wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
409         wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
410
411         if (WLCISNPHY(wlc->band) &&
412             (wlc_phy_txpower_hw_ctrl_get(wlc->band->pi) != PHY_TPC_HW_ON))
413                 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode =
414                     PHY_TXC1_MODE_CDD;
415         wlc_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
416         wlc_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
417
418         wlc_stf_stbc_rx_ht_update(wlc, HT_CAP_RX_STBC_NO);
419         wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
420         wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
421
422         if (WLC_STBC_CAP_PHY(wlc)) {
423                 wlc->stf->ss_algosel_auto = true;
424                 wlc->stf->ss_algo_channel = (u16) -1;   /* Init the default value */
425         }
426         return 0;
427 }
428
429 void wlc_stf_detach(wlc_info_t *wlc)
430 {
431 }
432
433 int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val)
434 {
435         int bcmerror = BCME_OK;
436
437         /* when there is only 1 tx_streams, don't allow to change the txant */
438         if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
439                 return ((val == wlc->stf->txant) ? bcmerror : BCME_RANGE);
440
441         switch (val) {
442         case -1:
443                 val = ANT_TX_DEF;
444                 break;
445         case 0:
446                 val = ANT_TX_FORCE_0;
447                 break;
448         case 1:
449                 val = ANT_TX_FORCE_1;
450                 break;
451         case 3:
452                 val = ANT_TX_LAST_RX;
453                 break;
454         default:
455                 bcmerror = BCME_RANGE;
456                 break;
457         }
458
459         if (bcmerror == BCME_OK)
460                 wlc->stf->txant = (s8) val;
461
462         return bcmerror;
463
464 }
465
466 /*
467  * Centralized txant update function. call it whenever wlc->stf->txant and/or wlc->stf->txchain
468  *  change
469  *
470  * Antennas are controlled by ucode indirectly, which drives PHY or GPIO to
471  *   achieve various tx/rx antenna selection schemes
472  *
473  * legacy phy, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means auto(last rx)
474  * for NREV<3, bit 6 and bit 7 means antenna 0 and 1 respectively, bit6+bit7 means last rx and
475  *    do tx-antenna selection for SISO transmissions
476  * for NREV=3, bit 6 and bit _8_ means antenna 0 and 1 respectively, bit6+bit7 means last rx and
477  *    do tx-antenna selection for SISO transmissions
478  * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
479 */
480 static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc)
481 {
482         s8 txant;
483
484         txant = (s8) wlc->stf->txant;
485         ASSERT(txant == ANT_TX_FORCE_0 || txant == ANT_TX_FORCE_1
486                || txant == ANT_TX_LAST_RX);
487
488         if (WLC_PHY_11N_CAP(wlc->band)) {
489                 if (txant == ANT_TX_FORCE_0) {
490                         wlc->stf->phytxant = PHY_TXC_ANT_0;
491                 } else if (txant == ANT_TX_FORCE_1) {
492                         wlc->stf->phytxant = PHY_TXC_ANT_1;
493
494                         if (WLCISNPHY(wlc->band) &&
495                             NREV_GE(wlc->band->phyrev, 3)
496                             && NREV_LT(wlc->band->phyrev, 7)) {
497                                 wlc->stf->phytxant = PHY_TXC_ANT_2;
498                         }
499                 } else {
500                         if (WLCISLCNPHY(wlc->band) || WLCISSSLPNPHY(wlc->band))
501                                 wlc->stf->phytxant = PHY_TXC_LCNPHY_ANT_LAST;
502                         else {
503                                 /* keep this assert to catch out of sync wlc->stf->txcore */
504                                 ASSERT(wlc->stf->txchain > 0);
505                                 wlc->stf->phytxant =
506                                     wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
507                         }
508                 }
509         } else {
510                 if (txant == ANT_TX_FORCE_0)
511                         wlc->stf->phytxant = PHY_TXC_OLD_ANT_0;
512                 else if (txant == ANT_TX_FORCE_1)
513                         wlc->stf->phytxant = PHY_TXC_OLD_ANT_1;
514                 else
515                         wlc->stf->phytxant = PHY_TXC_OLD_ANT_LAST;
516         }
517
518         wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
519 }
520
521 void wlc_stf_phy_txant_upd(wlc_info_t *wlc)
522 {
523         _wlc_stf_phy_txant_upd(wlc);
524 }
525
526 void wlc_stf_phy_chain_calc(wlc_info_t *wlc)
527 {
528         /* get available rx/tx chains */
529         wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
530         wlc->stf->hw_rxchain = (u8) getintvar(wlc->pub->vars, "rxchain");
531
532         /* these parameter are intended to be used for all PHY types */
533         if (wlc->stf->hw_txchain == 0 || wlc->stf->hw_txchain == 0xf) {
534                 if (WLCISNPHY(wlc->band)) {
535                         wlc->stf->hw_txchain = TXCHAIN_DEF_NPHY;
536                 } else {
537                         wlc->stf->hw_txchain = TXCHAIN_DEF;
538                 }
539         }
540
541         wlc->stf->txchain = wlc->stf->hw_txchain;
542         wlc->stf->txstreams = (u8) WLC_BITSCNT(wlc->stf->hw_txchain);
543
544         if (wlc->stf->hw_rxchain == 0 || wlc->stf->hw_rxchain == 0xf) {
545                 if (WLCISNPHY(wlc->band)) {
546                         wlc->stf->hw_rxchain = RXCHAIN_DEF_NPHY;
547                 } else {
548                         wlc->stf->hw_rxchain = RXCHAIN_DEF;
549                 }
550         }
551
552         wlc->stf->rxchain = wlc->stf->hw_rxchain;
553         wlc->stf->rxstreams = (u8) WLC_BITSCNT(wlc->stf->hw_rxchain);
554
555         /* initialize the txcore table */
556         bcopy(txcore_default, wlc->stf->txcore, sizeof(wlc->stf->txcore));
557
558         /* default spatial_policy */
559         wlc->stf->spatial_policy = MIN_SPATIAL_EXPANSION;
560         wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
561 }
562
563 static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
564 {
565         u16 phytxant = wlc->stf->phytxant;
566
567         if (RSPEC_STF(rspec) != PHY_TXC1_MODE_SISO) {
568                 ASSERT(wlc->stf->txstreams > 1);
569                 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
570         } else if (wlc->stf->txant == ANT_TX_DEF)
571                 phytxant = wlc->stf->txchain << PHY_TXC_ANT_SHIFT;
572         phytxant &= PHY_TXC_ANT_MASK;
573         return phytxant;
574 }
575
576 u16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
577 {
578         return _wlc_stf_phytxchain_sel(wlc, rspec);
579 }
580
581 u16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec)
582 {
583         u16 phytxant = wlc->stf->phytxant;
584         u16 mask = PHY_TXC_ANT_MASK;
585
586         /* for non-siso rates or default setting, use the available chains */
587         if (WLCISNPHY(wlc->band)) {
588                 ASSERT(wlc->stf->txchain != 0);
589                 phytxant = _wlc_stf_phytxchain_sel(wlc, rspec);
590                 mask = PHY_TXC_HTANT_MASK;
591         }
592         phytxant |= phytxant & mask;
593         return phytxant;
594 }