stf.c 13 KB

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