stf.c 12 KB

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