halmac_mimo_88xx.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. ******************************************************************************/
  15. #include "halmac_mimo_88xx.h"
  16. #include "halmac_88xx_cfg.h"
  17. #include "halmac_common_88xx.h"
  18. #include "halmac_init_88xx.h"
  19. #if HALMAC_88XX_SUPPORT
  20. #define TXBF_CTRL_CFG (BIT_R_ENABLE_NDPA | BIT_USE_NDPA_PARAMETER | \
  21. BIT_R_EN_NDPA_INT | BIT_DIS_NDP_BFEN)
  22. static void
  23. cfg_mu_bfee_88xx(struct halmac_adapter *adapter,
  24. struct halmac_cfg_mumimo_para *param);
  25. static void
  26. cfg_mu_bfer_88xx(struct halmac_adapter *adapter,
  27. struct halmac_cfg_mumimo_para *param);
  28. static enum halmac_cmd_construct_state
  29. fw_snding_cmd_cnstr_state_88xx(struct halmac_adapter *adapter);
  30. static enum halmac_ret_status
  31. cnv_fw_snding_state_88xx(struct halmac_adapter *adapter,
  32. enum halmac_cmd_construct_state dest_state);
  33. static u8
  34. snding_pkt_chk_88xx(struct halmac_adapter *adapter, u8 *pkt);
  35. /**
  36. * cfg_txbf_88xx() - enable/disable specific user's txbf
  37. * @adapter : the adapter of halmac
  38. * @userid : su bfee userid = 0 or 1 to apply TXBF
  39. * @bw : the sounding bandwidth
  40. * @txbf_en : 0: disable TXBF, 1: enable TXBF
  41. * Author : chunchu
  42. * Return : enum halmac_ret_status
  43. * More details of status code can be found in prototype document
  44. */
  45. enum halmac_ret_status
  46. cfg_txbf_88xx(struct halmac_adapter *adapter, u8 userid, enum halmac_bw bw,
  47. u8 txbf_en)
  48. {
  49. u16 tmp42c = 0;
  50. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  51. if (txbf_en) {
  52. switch (bw) {
  53. case HALMAC_BW_80:
  54. tmp42c |= BIT_R_TXBF0_80M;
  55. case HALMAC_BW_40:
  56. tmp42c |= BIT_R_TXBF0_40M;
  57. case HALMAC_BW_20:
  58. tmp42c |= BIT_R_TXBF0_20M;
  59. break;
  60. default:
  61. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  62. }
  63. }
  64. switch (userid) {
  65. case 0:
  66. tmp42c |= HALMAC_REG_R16(REG_TXBF_CTRL) &
  67. ~(BIT_R_TXBF0_20M | BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  68. HALMAC_REG_W16(REG_TXBF_CTRL, tmp42c);
  69. break;
  70. case 1:
  71. tmp42c |= HALMAC_REG_R16(REG_TXBF_CTRL + 2) &
  72. ~(BIT_R_TXBF0_20M | BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  73. HALMAC_REG_W16(REG_TXBF_CTRL + 2, tmp42c);
  74. break;
  75. default:
  76. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  77. }
  78. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  79. return HALMAC_RET_SUCCESS;
  80. }
  81. /**
  82. * cfg_mumimo_88xx() -config mumimo
  83. * @adapter : the adapter of halmac
  84. * @param : parameters to configure MU PPDU Tx/Rx
  85. * Author : chunchu
  86. * Return : enum halmac_ret_status
  87. * More details of status code can be found in prototype document
  88. */
  89. enum halmac_ret_status
  90. cfg_mumimo_88xx(struct halmac_adapter *adapter,
  91. struct halmac_cfg_mumimo_para *param)
  92. {
  93. if (param->role == HAL_BFEE)
  94. cfg_mu_bfee_88xx(adapter, param);
  95. else
  96. cfg_mu_bfer_88xx(adapter, param);
  97. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  98. return HALMAC_RET_SUCCESS;
  99. }
  100. static void
  101. cfg_mu_bfee_88xx(struct halmac_adapter *adapter,
  102. struct halmac_cfg_mumimo_para *param)
  103. {
  104. u8 mu_tbl_sel;
  105. u8 tmp14c0;
  106. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  107. tmp14c0 = HALMAC_REG_R8(REG_MU_TX_CTL) & ~BIT_MASK_R_MU_TABLE_VALID;
  108. HALMAC_REG_W8(REG_MU_TX_CTL, (tmp14c0 | BIT(0) | BIT(1)) & ~(BIT(7)));
  109. /*config GID valid table and user position table*/
  110. mu_tbl_sel = HALMAC_REG_R8(REG_MU_TX_CTL + 1) & 0xF8;
  111. HALMAC_REG_W8(REG_MU_TX_CTL + 1, mu_tbl_sel);
  112. HALMAC_REG_W32(REG_MU_STA_GID_VLD, param->given_gid_tab[0]);
  113. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO, param->given_user_pos[0]);
  114. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO + 4, param->given_user_pos[1]);
  115. HALMAC_REG_W8(REG_MU_TX_CTL + 1, mu_tbl_sel | 1);
  116. HALMAC_REG_W32(REG_MU_STA_GID_VLD, param->given_gid_tab[1]);
  117. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO, param->given_user_pos[2]);
  118. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO + 4, param->given_user_pos[3]);
  119. }
  120. static void
  121. cfg_mu_bfer_88xx(struct halmac_adapter *adapter,
  122. struct halmac_cfg_mumimo_para *param)
  123. {
  124. u8 i;
  125. u8 idx;
  126. u8 id0;
  127. u8 id1;
  128. u8 gid;
  129. u8 mu_tbl_sel;
  130. u8 mu_tbl_valid = 0;
  131. u32 gid_valid[6] = {0};
  132. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  133. if (param->mu_tx_en == 0) {
  134. HALMAC_REG_W8(REG_MU_TX_CTL,
  135. HALMAC_REG_R8(REG_MU_TX_CTL) & ~(BIT(7)));
  136. return;
  137. }
  138. for (idx = 0; idx < 15; idx++) {
  139. if (idx < 5) {
  140. /*grouping_bitmap bit0~4, MU_STA0 with MUSTA1~5*/
  141. id0 = 0;
  142. id1 = (u8)(idx + 1);
  143. } else if (idx < 9) {
  144. /*grouping_bitmap bit5~8, MU_STA1 with MUSTA2~5*/
  145. id0 = 1;
  146. id1 = (u8)(idx - 3);
  147. } else if (idx < 12) {
  148. /*grouping_bitmap bit9~11, MU_STA2 with MUSTA3~5*/
  149. id0 = 2;
  150. id1 = (u8)(idx - 6);
  151. } else if (idx < 14) {
  152. /*grouping_bitmap bit12~13, MU_STA3 with MUSTA4~5*/
  153. id0 = 3;
  154. id1 = (u8)(idx - 8);
  155. } else {
  156. /*grouping_bitmap bit14, MU_STA4 with MUSTA5*/
  157. id0 = 4;
  158. id1 = (u8)(idx - 9);
  159. }
  160. if (param->grouping_bitmap & BIT(idx)) {
  161. /*Pair 1*/
  162. gid = (idx << 1) + 1;
  163. gid_valid[id0] |= (BIT(gid));
  164. gid_valid[id1] |= (BIT(gid));
  165. /*Pair 2*/
  166. gid += 1;
  167. gid_valid[id0] |= (BIT(gid));
  168. gid_valid[id1] |= (BIT(gid));
  169. } else {
  170. /*Pair 1*/
  171. gid = (idx << 1) + 1;
  172. gid_valid[id0] &= ~(BIT(gid));
  173. gid_valid[id1] &= ~(BIT(gid));
  174. /*Pair 2*/
  175. gid += 1;
  176. gid_valid[id0] &= ~(BIT(gid));
  177. gid_valid[id1] &= ~(BIT(gid));
  178. }
  179. }
  180. /*set MU STA GID valid TABLE*/
  181. mu_tbl_sel = HALMAC_REG_R8(REG_MU_TX_CTL + 1) & 0xF8;
  182. for (idx = 0; idx < 6; idx++) {
  183. HALMAC_REG_W8(REG_MU_TX_CTL + 1, idx | mu_tbl_sel);
  184. HALMAC_REG_W32(REG_MU_STA_GID_VLD, gid_valid[idx]);
  185. }
  186. /*To validate the sounding successful MU STA and enable MU TX*/
  187. for (i = 0; i < 6; i++) {
  188. if (param->sounding_sts[i] == 1)
  189. mu_tbl_valid |= BIT(i);
  190. }
  191. HALMAC_REG_W8(REG_MU_TX_CTL, mu_tbl_valid | BIT(7));
  192. }
  193. /**
  194. * cfg_sounding_88xx() - configure general sounding
  195. * @adapter : the adapter of halmac
  196. * @role : driver's role, BFer or BFee
  197. * @rate : set ndpa tx rate if driver is BFer,
  198. * or set csi response rate if driver is BFee
  199. * Author : chunchu
  200. * Return : enum halmac_ret_status
  201. * More details of status code can be found in prototype document
  202. */
  203. enum halmac_ret_status
  204. cfg_sounding_88xx(struct halmac_adapter *adapter, enum halmac_snd_role role,
  205. enum halmac_data_rate rate)
  206. {
  207. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  208. u32 tmp6dc = 0;
  209. u8 csi_rsc = 0x1;
  210. /*use ndpa rx rate to decide csi rate*/
  211. tmp6dc = HALMAC_REG_R32(REG_BBPSF_CTRL) | BIT_WMAC_USE_NDPARATE
  212. | (csi_rsc << 13);
  213. switch (role) {
  214. case HAL_BFER:
  215. HALMAC_REG_W32_SET(REG_TXBF_CTRL, TXBF_CTRL_CFG);
  216. HALMAC_REG_W8(REG_NDPA_RATE, rate);
  217. HALMAC_REG_W8_CLR(REG_NDPA_OPT_CTRL, BIT(0) | BIT(1));
  218. HALMAC_REG_W8(REG_SND_PTCL_CTRL + 1, 0x2 | BIT(7));
  219. HALMAC_REG_W8(REG_SND_PTCL_CTRL + 2, 0x2);
  220. break;
  221. case HAL_BFEE:
  222. HALMAC_REG_W8(REG_SND_PTCL_CTRL, 0xDB);
  223. HALMAC_REG_W8(REG_SND_PTCL_CTRL + 3, 0x26);
  224. HALMAC_REG_W8_CLR(REG_RXFLTMAP1, BIT(4));
  225. HALMAC_REG_W8_CLR(REG_RXFLTMAP4, BIT(4));
  226. break;
  227. default:
  228. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  229. }
  230. /*AP mode set tx gid to 63*/
  231. /*STA mode set tx gid to 0*/
  232. if (BIT_GET_NETYPE0(HALMAC_REG_R32(REG_CR)) == 0x3)
  233. HALMAC_REG_W32(REG_BBPSF_CTRL, tmp6dc | BIT(12));
  234. else
  235. HALMAC_REG_W32(REG_BBPSF_CTRL, tmp6dc & ~(BIT(12)));
  236. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  237. return HALMAC_RET_SUCCESS;
  238. }
  239. /**
  240. * del_sounding_88xx() - reset general sounding
  241. * @adapter : the adapter of halmac
  242. * @role : driver's role, BFer or BFee
  243. * Author : chunchu
  244. * Return : enum halmac_ret_status
  245. * More details of status code can be found in prototype document
  246. */
  247. enum halmac_ret_status
  248. del_sounding_88xx(struct halmac_adapter *adapter, enum halmac_snd_role role)
  249. {
  250. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  251. switch (role) {
  252. case HAL_BFER:
  253. HALMAC_REG_W8(REG_TXBF_CTRL + 3, 0);
  254. break;
  255. case HAL_BFEE:
  256. HALMAC_REG_W8(REG_SND_PTCL_CTRL, 0);
  257. break;
  258. default:
  259. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  260. }
  261. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  262. return HALMAC_RET_SUCCESS;
  263. }
  264. /**
  265. * su_bfee_entry_init_88xx() - config SU beamformee's registers
  266. * @adapter : the adapter of halmac
  267. * @userid : SU bfee userid = 0 or 1 to be added
  268. * @paid : partial AID of this bfee
  269. * Author : chunchu
  270. * Return : enum halmac_ret_status
  271. * More details of status code can be found in prototype document
  272. */
  273. enum halmac_ret_status
  274. su_bfee_entry_init_88xx(struct halmac_adapter *adapter, u8 userid, u16 paid)
  275. {
  276. u16 tmp42c = 0;
  277. u16 tmp168x = 0;
  278. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  279. switch (userid) {
  280. case 0:
  281. tmp42c = HALMAC_REG_R16(REG_TXBF_CTRL) &
  282. ~(BIT_MASK_R_TXBF0_AID | BIT_R_TXBF0_20M |
  283. BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  284. HALMAC_REG_W16(REG_TXBF_CTRL, tmp42c | paid);
  285. HALMAC_REG_W16(REG_ASSOCIATED_BFMEE_SEL, paid);
  286. #if HALMAC_8822C_SUPPORT
  287. if (adapter->chip_id == HALMAC_CHIP_ID_8822C)
  288. HALMAC_REG_W16(REG_ASSOCIATED_BFMEE_SEL, paid | BIT(9));
  289. #endif
  290. break;
  291. case 1:
  292. tmp42c = HALMAC_REG_R16(REG_TXBF_CTRL + 2) &
  293. ~(BIT_MASK_R_TXBF1_AID | BIT_R_TXBF0_20M |
  294. BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  295. HALMAC_REG_W16(REG_TXBF_CTRL + 2, tmp42c | paid);
  296. HALMAC_REG_W16(REG_ASSOCIATED_BFMEE_SEL + 2, paid | BIT(9));
  297. break;
  298. case 2:
  299. tmp168x = HALMAC_REG_R16(REG_WMAC_ASSOCIATED_MU_BFMEE2);
  300. tmp168x = BIT_CLEAR_WMAC_MU_BFEE2_AID(tmp168x);
  301. tmp168x |= (paid | BIT(9));
  302. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE2, tmp168x);
  303. break;
  304. case 3:
  305. tmp168x = HALMAC_REG_R16(REG_WMAC_ASSOCIATED_MU_BFMEE3);
  306. tmp168x = BIT_CLEAR_WMAC_MU_BFEE3_AID(tmp168x);
  307. tmp168x |= (paid | BIT(9));
  308. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE3, tmp168x);
  309. break;
  310. case 4:
  311. tmp168x = HALMAC_REG_R16(REG_WMAC_ASSOCIATED_MU_BFMEE4);
  312. tmp168x = BIT_CLEAR_WMAC_MU_BFEE4_AID(tmp168x);
  313. tmp168x |= (paid | BIT(9));
  314. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE4, tmp168x);
  315. break;
  316. case 5:
  317. tmp168x = HALMAC_REG_R16(REG_WMAC_ASSOCIATED_MU_BFMEE5);
  318. tmp168x = BIT_CLEAR_WMAC_MU_BFEE5_AID(tmp168x);
  319. tmp168x |= (paid | BIT(9));
  320. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE5, tmp168x);
  321. break;
  322. default:
  323. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  324. }
  325. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  326. return HALMAC_RET_SUCCESS;
  327. }
  328. /**
  329. * su_bfee_entry_init_88xx() - config SU beamformer's registers
  330. * @adapter : the adapter of halmac
  331. * @param : parameters to configure SU BFER entry
  332. * Author : chunchu
  333. * Return : enum halmac_ret_status
  334. * More details of status code can be found in prototype document
  335. */
  336. enum halmac_ret_status
  337. su_bfer_entry_init_88xx(struct halmac_adapter *adapter,
  338. struct halmac_su_bfer_init_para *param)
  339. {
  340. u16 mac_addr_h;
  341. u32 mac_addr_l;
  342. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  343. mac_addr_l = rtk_le32_to_cpu(param->bfer_address.addr_l_h.low);
  344. mac_addr_h = rtk_le16_to_cpu(param->bfer_address.addr_l_h.high);
  345. switch (param->userid) {
  346. case 0:
  347. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO, mac_addr_l);
  348. HALMAC_REG_W16(REG_ASSOCIATED_BFMER0_INFO + 4, mac_addr_h);
  349. HALMAC_REG_W16(REG_ASSOCIATED_BFMER0_INFO + 6, param->paid);
  350. HALMAC_REG_W16(REG_TX_CSI_RPT_PARAM_BW20, param->csi_para);
  351. break;
  352. case 1:
  353. HALMAC_REG_W32(REG_ASSOCIATED_BFMER1_INFO, mac_addr_l);
  354. HALMAC_REG_W16(REG_ASSOCIATED_BFMER1_INFO + 4, mac_addr_h);
  355. HALMAC_REG_W16(REG_ASSOCIATED_BFMER1_INFO + 6, param->paid);
  356. HALMAC_REG_W16(REG_TX_CSI_RPT_PARAM_BW20 + 2, param->csi_para);
  357. break;
  358. default:
  359. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  360. }
  361. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  362. return HALMAC_RET_SUCCESS;
  363. }
  364. /**
  365. * mu_bfee_entry_init_88xx() - config MU beamformee's registers
  366. * @adapter : the adapter of halmac
  367. * @param : parameters to configure MU BFEE entry
  368. * Author : chunchu
  369. * Return : enum halmac_ret_status
  370. * More details of status code can be found in prototype document
  371. */
  372. enum halmac_ret_status
  373. mu_bfee_entry_init_88xx(struct halmac_adapter *adapter,
  374. struct halmac_mu_bfee_init_para *param)
  375. {
  376. u16 tmp168x = 0;
  377. u16 tmp14c0;
  378. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  379. tmp168x |= param->paid | BIT(9);
  380. HALMAC_REG_W16((0x1680 + param->userid * 2), tmp168x);
  381. tmp14c0 = HALMAC_REG_R16(REG_MU_TX_CTL) & ~(BIT(8) | BIT(9) | BIT(10));
  382. HALMAC_REG_W16(REG_MU_TX_CTL, tmp14c0 | ((param->userid - 2) << 8));
  383. HALMAC_REG_W32(REG_MU_STA_GID_VLD, 0);
  384. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO, param->user_position_l);
  385. HALMAC_REG_W32(REG_MU_STA_USER_POS_INFO + 4, param->user_position_h);
  386. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  387. return HALMAC_RET_SUCCESS;
  388. }
  389. /**
  390. * mu_bfer_entry_init_88xx() - config MU beamformer's registers
  391. * @adapter : the adapter of halmac
  392. * @param : parameters to configure MU BFER entry
  393. * Author : chunchu
  394. * Return : enum halmac_ret_status
  395. * More details of status code can be found in prototype document
  396. */
  397. enum halmac_ret_status
  398. mu_bfer_entry_init_88xx(struct halmac_adapter *adapter,
  399. struct halmac_mu_bfer_init_para *param)
  400. {
  401. u16 tmp1680 = 0;
  402. u16 mac_addr_h;
  403. u32 mac_addr_l;
  404. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  405. mac_addr_l = rtk_le32_to_cpu(param->bfer_address.addr_l_h.low);
  406. mac_addr_h = rtk_le16_to_cpu(param->bfer_address.addr_l_h.high);
  407. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO, mac_addr_l);
  408. HALMAC_REG_W16(REG_ASSOCIATED_BFMER0_INFO + 4, mac_addr_h);
  409. HALMAC_REG_W16(REG_ASSOCIATED_BFMER0_INFO + 6, param->paid);
  410. HALMAC_REG_W16(REG_TX_CSI_RPT_PARAM_BW20, param->csi_para);
  411. tmp1680 = HALMAC_REG_R16(0x1680) & 0xC000;
  412. tmp1680 |= param->my_aid | (param->csi_length_sel << 12);
  413. HALMAC_REG_W16(0x1680, tmp1680);
  414. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  415. return HALMAC_RET_SUCCESS;
  416. }
  417. /**
  418. * su_bfee_entry_del_88xx() - reset SU beamformee's registers
  419. * @adapter : the adapter of halmac
  420. * @userid : the SU BFee userid to be deleted
  421. * Author : chunchu
  422. * Return : enum halmac_ret_status
  423. * More details of status code can be found in prototype document
  424. */
  425. enum halmac_ret_status
  426. su_bfee_entry_del_88xx(struct halmac_adapter *adapter, u8 userid)
  427. {
  428. u16 value16;
  429. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  430. switch (userid) {
  431. case 0:
  432. value16 = HALMAC_REG_R16(REG_TXBF_CTRL);
  433. value16 &= ~(BIT_MASK_R_TXBF0_AID | BIT_R_TXBF0_20M |
  434. BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  435. HALMAC_REG_W16(REG_TXBF_CTRL, value16);
  436. HALMAC_REG_W16(REG_ASSOCIATED_BFMEE_SEL, 0);
  437. break;
  438. case 1:
  439. value16 = HALMAC_REG_R16(REG_TXBF_CTRL + 2);
  440. value16 &= ~(BIT_MASK_R_TXBF1_AID | BIT_R_TXBF0_20M |
  441. BIT_R_TXBF0_40M | BIT_R_TXBF0_80M);
  442. HALMAC_REG_W16(REG_TXBF_CTRL + 2, value16);
  443. HALMAC_REG_W16(REG_ASSOCIATED_BFMEE_SEL + 2, 0);
  444. break;
  445. case 2:
  446. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE2, 0);
  447. break;
  448. case 3:
  449. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE3, 0);
  450. break;
  451. case 4:
  452. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE4, 0);
  453. break;
  454. case 5:
  455. HALMAC_REG_W16(REG_WMAC_ASSOCIATED_MU_BFMEE5, 0);
  456. break;
  457. default:
  458. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  459. }
  460. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  461. return HALMAC_RET_SUCCESS;
  462. }
  463. /**
  464. * su_bfee_entry_del_88xx() - reset SU beamformer's registers
  465. * @adapter : the adapter of halmac
  466. * @userid : the SU BFer userid to be deleted
  467. * Author : chunchu
  468. * Return : enum halmac_ret_status
  469. * More details of status code can be found in prototype document
  470. */
  471. enum halmac_ret_status
  472. su_bfer_entry_del_88xx(struct halmac_adapter *adapter, u8 userid)
  473. {
  474. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  475. switch (userid) {
  476. case 0:
  477. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO, 0);
  478. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO + 4, 0);
  479. break;
  480. case 1:
  481. HALMAC_REG_W32(REG_ASSOCIATED_BFMER1_INFO, 0);
  482. HALMAC_REG_W32(REG_ASSOCIATED_BFMER1_INFO + 4, 0);
  483. break;
  484. default:
  485. return HALMAC_RET_INVALID_SOUNDING_SETTING;
  486. }
  487. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  488. return HALMAC_RET_SUCCESS;
  489. }
  490. /**
  491. * mu_bfee_entry_del_88xx() - reset MU beamformee's registers
  492. * @adapter : the adapter of halmac
  493. * @userid : the MU STA userid to be deleted
  494. * Author : chunchu
  495. * Return : enum halmac_ret_status
  496. * More details of status code can be found in prototype document
  497. */
  498. enum halmac_ret_status
  499. mu_bfee_entry_del_88xx(struct halmac_adapter *adapter, u8 userid)
  500. {
  501. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  502. HALMAC_REG_W16(0x1680 + userid * 2, 0);
  503. HALMAC_REG_W8_CLR(REG_MU_TX_CTL, BIT(userid - 2));
  504. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  505. return HALMAC_RET_SUCCESS;
  506. }
  507. /**
  508. * mu_bfer_entry_del_88xx() -reset MU beamformer's registers
  509. * @adapter : the adapter of halmac
  510. * Author : chunchu
  511. * Return : enum halmac_ret_status
  512. * More details of status code can be found in prototype document
  513. */
  514. enum halmac_ret_status
  515. mu_bfer_entry_del_88xx(struct halmac_adapter *adapter)
  516. {
  517. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  518. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO, 0);
  519. HALMAC_REG_W32(REG_ASSOCIATED_BFMER0_INFO + 4, 0);
  520. HALMAC_REG_W16(0x1680, 0);
  521. HALMAC_REG_W8(REG_MU_TX_CTL, 0);
  522. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  523. return HALMAC_RET_SUCCESS;
  524. }
  525. /**
  526. * cfg_csi_rate_88xx() - config CSI frame Tx rate
  527. * @adapter : the adapter of halmac
  528. * @rssi : rssi in decimal value
  529. * @cur_rate : current CSI frame rate
  530. * @fixrate_en : enable to fix CSI frame in VHT rate, otherwise legacy OFDM rate
  531. * @new_rate : API returns the final CSI frame rate
  532. * Author : chunchu
  533. * Return : enum halmac_ret_status
  534. * More details of status code can be found in prototype document
  535. */
  536. enum halmac_ret_status
  537. cfg_csi_rate_88xx(struct halmac_adapter *adapter, u8 rssi, u8 cur_rate,
  538. u8 fixrate_en, u8 *new_rate)
  539. {
  540. u32 csi_cfg;
  541. u16 cur_rrsr;
  542. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  543. PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
  544. #if HALMAC_8821C_SUPPORT
  545. if (adapter->chip_id == HALMAC_CHIP_ID_8821C && fixrate_en) {
  546. csi_cfg = HALMAC_REG_R32(REG_BBPSF_CTRL) & ~BITS_WMAC_CSI_RATE;
  547. HALMAC_REG_W32(REG_BBPSF_CTRL,
  548. csi_cfg | BIT_CSI_FORCE_RATE_EN |
  549. BIT_CSI_RSC(1) |
  550. BIT_WMAC_CSI_RATE(HALMAC_VHT_NSS1_MCS3));
  551. *new_rate = HALMAC_VHT_NSS1_MCS3;
  552. return HALMAC_RET_SUCCESS;
  553. }
  554. csi_cfg = HALMAC_REG_R32(REG_BBPSF_CTRL) & ~BITS_WMAC_CSI_RATE &
  555. ~BIT_CSI_FORCE_RATE_EN;
  556. #else
  557. csi_cfg = HALMAC_REG_R32(REG_BBPSF_CTRL) & ~BITS_WMAC_CSI_RATE;
  558. #endif
  559. cur_rrsr = HALMAC_REG_R16(REG_RRSR);
  560. if (rssi >= 40) {
  561. if (cur_rate != HALMAC_OFDM54) {
  562. cur_rrsr |= BIT(HALMAC_OFDM54);
  563. csi_cfg |= BIT_WMAC_CSI_RATE(HALMAC_OFDM54);
  564. HALMAC_REG_W16(REG_RRSR, cur_rrsr);
  565. HALMAC_REG_W32(REG_BBPSF_CTRL, csi_cfg);
  566. }
  567. *new_rate = HALMAC_OFDM54;
  568. } else {
  569. if (cur_rate != HALMAC_OFDM24) {
  570. cur_rrsr &= ~(BIT(HALMAC_OFDM54));
  571. csi_cfg |= BIT_WMAC_CSI_RATE(HALMAC_OFDM24);
  572. HALMAC_REG_W16(REG_RRSR, cur_rrsr);
  573. HALMAC_REG_W32(REG_BBPSF_CTRL, csi_cfg);
  574. }
  575. *new_rate = HALMAC_OFDM24;
  576. }
  577. return HALMAC_RET_SUCCESS;
  578. }
  579. /**
  580. * fw_snding_88xx() - fw sounding control
  581. * @adapter : the adapter of halmac
  582. * @su_info :
  583. * su0_en : enable/disable fw sounding
  584. * su0_ndpa_pkt : ndpa pkt, shall include txdesc
  585. * su0_pkt_sz : ndpa pkt size, shall include txdesc
  586. * @mu_info : currently not in use, input NULL is acceptable
  587. * @period : sounding period, unit is 5ms
  588. * Author : Ivan Lin
  589. * Return : enum halmac_ret_status
  590. * More details of status code can be found in prototype document
  591. */
  592. enum halmac_ret_status
  593. fw_snding_88xx(struct halmac_adapter *adapter,
  594. struct halmac_su_snding_info *su_info,
  595. struct halmac_mu_snding_info *mu_info, u8 period)
  596. {
  597. u8 h2c_buf[H2C_PKT_SIZE_88XX] = { 0 };
  598. u16 seq_num;
  599. u16 snding_info_addr;
  600. struct halmac_h2c_header_info hdr_info;
  601. enum halmac_cmd_process_status *proc_status;
  602. enum halmac_ret_status status;
  603. proc_status = &adapter->halmac_state.fw_snding_state.proc_status;
  604. if (adapter->chip_id == HALMAC_CHIP_ID_8821C)
  605. return HALMAC_RET_NOT_SUPPORT;
  606. if (halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
  607. return HALMAC_RET_NO_DLFW;
  608. if (adapter->fw_ver.h2c_version < 9)
  609. return HALMAC_RET_FW_NO_SUPPORT;
  610. if (*proc_status == HALMAC_CMD_PROCESS_SENDING) {
  611. PLTFM_MSG_TRACE("[TRACE]Wait event(snd)\n");
  612. return HALMAC_RET_BUSY_STATE;
  613. }
  614. if (su_info->su0_en == 1) {
  615. if (!su_info->su0_ndpa_pkt)
  616. return HALMAC_RET_NULL_POINTER;
  617. if (su_info->su0_pkt_sz > (u32)SU0_SNDING_PKT_RSVDPG_SIZE -
  618. adapter->hw_cfg_info.txdesc_size)
  619. return HALMAC_RET_DATA_SIZE_INCORRECT;
  620. if (!snding_pkt_chk_88xx(adapter, su_info->su0_ndpa_pkt))
  621. return HALMAC_RET_TXDESC_SET_FAIL;
  622. if (fw_snding_cmd_cnstr_state_88xx(adapter) !=
  623. HALMAC_CMD_CNSTR_IDLE) {
  624. PLTFM_MSG_ERR("[ERR]Not idle(snd)\n");
  625. return HALMAC_RET_ERROR_STATE;
  626. }
  627. snding_info_addr = adapter->txff_alloc.rsvd_h2c_sta_info_addr +
  628. SU0_SNDING_PKT_OFFSET;
  629. status = dl_rsvd_page_88xx(adapter, snding_info_addr,
  630. su_info->su0_ndpa_pkt,
  631. su_info->su0_pkt_sz);
  632. if (status != HALMAC_RET_SUCCESS) {
  633. PLTFM_MSG_ERR("[ERR]dl rsvd page\n");
  634. return status;
  635. }
  636. FW_SNDING_SET_SU0(h2c_buf, 1);
  637. FW_SNDING_SET_PERIOD(h2c_buf, period);
  638. FW_SNDING_SET_NDPA0_HEAD_PG(h2c_buf, snding_info_addr -
  639. adapter->txff_alloc.rsvd_boundary);
  640. } else {
  641. if (fw_snding_cmd_cnstr_state_88xx(adapter) !=
  642. HALMAC_CMD_CNSTR_BUSY) {
  643. PLTFM_MSG_ERR("[ERR]Not snd(snd)\n");
  644. return HALMAC_RET_ERROR_STATE;
  645. }
  646. FW_SNDING_SET_SU0(h2c_buf, 0);
  647. }
  648. *proc_status = HALMAC_CMD_PROCESS_SENDING;
  649. hdr_info.sub_cmd_id = SUB_CMD_ID_FW_SNDING;
  650. hdr_info.content_size = 8;
  651. hdr_info.ack = 1;
  652. set_h2c_pkt_hdr_88xx(adapter, h2c_buf, &hdr_info, &seq_num);
  653. adapter->halmac_state.fw_snding_state.seq_num = seq_num;
  654. status = send_h2c_pkt_88xx(adapter, h2c_buf);
  655. if (status != HALMAC_RET_SUCCESS) {
  656. PLTFM_MSG_ERR("[ERR]send h2c\n");
  657. reset_ofld_feature_88xx(adapter, HALMAC_FEATURE_FW_SNDING);
  658. return status;
  659. }
  660. if (cnv_fw_snding_state_88xx(adapter, su_info->su0_en == 1 ?
  661. HALMAC_CMD_CNSTR_BUSY :
  662. HALMAC_CMD_CNSTR_IDLE)
  663. != HALMAC_RET_SUCCESS)
  664. return HALMAC_RET_ERROR_STATE;
  665. return HALMAC_RET_SUCCESS;
  666. }
  667. static u8
  668. snding_pkt_chk_88xx(struct halmac_adapter *adapter, u8 *pkt)
  669. {
  670. u8 data_rate;
  671. if (GET_TX_DESC_NDPA(pkt) == 0) {
  672. PLTFM_MSG_ERR("[ERR]txdesc ndpa = 0\n");
  673. return 0;
  674. }
  675. data_rate = (u8)GET_TX_DESC_DATARATE(pkt);
  676. if (!(data_rate >= HALMAC_VHT_NSS2_MCS0 &&
  677. data_rate <= HALMAC_VHT_NSS2_MCS9)) {
  678. if (!(data_rate >= HALMAC_MCS8 && data_rate <= HALMAC_MCS15)) {
  679. PLTFM_MSG_ERR("[ERR]txdesc rate\n");
  680. return 0;
  681. }
  682. }
  683. if (GET_TX_DESC_NAVUSEHDR(pkt) == 0) {
  684. PLTFM_MSG_ERR("[ERR]txdesc navusehdr = 0\n");
  685. return 0;
  686. }
  687. if (GET_TX_DESC_USE_RATE(pkt) == 0) {
  688. PLTFM_MSG_ERR("[ERR]txdesc userate = 0\n");
  689. return 0;
  690. }
  691. return 1;
  692. }
  693. static enum halmac_cmd_construct_state
  694. fw_snding_cmd_cnstr_state_88xx(struct halmac_adapter *adapter)
  695. {
  696. return adapter->halmac_state.fw_snding_state.cmd_cnstr_state;
  697. }
  698. enum halmac_ret_status
  699. get_h2c_ack_fw_snding_88xx(struct halmac_adapter *adapter, u8 *buf, u32 size)
  700. {
  701. u8 seq_num = 0;
  702. u8 fw_rc;
  703. struct halmac_fw_snding_state *state;
  704. enum halmac_cmd_process_status proc_status;
  705. state = &adapter->halmac_state.fw_snding_state;
  706. seq_num = (u8)H2C_ACK_HDR_GET_H2C_SEQ(buf);
  707. PLTFM_MSG_TRACE("[TRACE]Seq num:h2c->%d c2h->%d\n",
  708. state->seq_num, seq_num);
  709. if (seq_num != state->seq_num) {
  710. PLTFM_MSG_ERR("[ERR]Seq num mismatch:h2c->%d c2h->%d\n",
  711. state->seq_num, seq_num);
  712. return HALMAC_RET_SUCCESS;
  713. }
  714. if (state->proc_status != HALMAC_CMD_PROCESS_SENDING) {
  715. PLTFM_MSG_ERR("[ERR]not sending(snd)\n");
  716. return HALMAC_RET_SUCCESS;
  717. }
  718. fw_rc = (u8)H2C_ACK_HDR_GET_H2C_RETURN_CODE(buf);
  719. state->fw_rc = fw_rc;
  720. if ((enum halmac_h2c_return_code)fw_rc == HALMAC_H2C_RETURN_SUCCESS) {
  721. proc_status = HALMAC_CMD_PROCESS_DONE;
  722. state->proc_status = proc_status;
  723. PLTFM_EVENT_SIG(HALMAC_FEATURE_FW_SNDING, proc_status,
  724. NULL, 0);
  725. } else {
  726. proc_status = HALMAC_CMD_PROCESS_ERROR;
  727. state->proc_status = proc_status;
  728. PLTFM_EVENT_SIG(HALMAC_FEATURE_FW_SNDING, proc_status,
  729. &fw_rc, 1);
  730. }
  731. return HALMAC_RET_SUCCESS;
  732. }
  733. enum halmac_ret_status
  734. get_fw_snding_status_88xx(struct halmac_adapter *adapter,
  735. enum halmac_cmd_process_status *proc_status)
  736. {
  737. *proc_status = adapter->halmac_state.fw_snding_state.proc_status;
  738. return HALMAC_RET_SUCCESS;
  739. }
  740. static enum halmac_ret_status
  741. cnv_fw_snding_state_88xx(struct halmac_adapter *adapter,
  742. enum halmac_cmd_construct_state dest_state)
  743. {
  744. struct halmac_fw_snding_state *state;
  745. state = &adapter->halmac_state.fw_snding_state;
  746. if (state->cmd_cnstr_state != HALMAC_CMD_CNSTR_IDLE &&
  747. state->cmd_cnstr_state != HALMAC_CMD_CNSTR_BUSY)
  748. return HALMAC_RET_ERROR_STATE;
  749. if (dest_state == HALMAC_CMD_CNSTR_IDLE) {
  750. if (state->cmd_cnstr_state == HALMAC_CMD_CNSTR_IDLE)
  751. return HALMAC_RET_ERROR_STATE;
  752. } else if (dest_state == HALMAC_CMD_CNSTR_BUSY) {
  753. if (state->cmd_cnstr_state == HALMAC_CMD_CNSTR_BUSY)
  754. return HALMAC_RET_ERROR_STATE;
  755. }
  756. state->cmd_cnstr_state = dest_state;
  757. return HALMAC_RET_SUCCESS;
  758. }
  759. #endif /* HALMAC_88XX_SUPPORT */