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