fw_common.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../pci.h"
  27. #include "../base.h"
  28. #include "../core.h"
  29. #include "../efuse.h"
  30. #include "../rtl8192ce/reg.h"
  31. #include "../rtl8192ce/def.h"
  32. #include "fw_common.h"
  33. #include <linux/export.h>
  34. static void _rtl92c_enable_fw_download(struct ieee80211_hw *hw, bool enable)
  35. {
  36. struct rtl_priv *rtlpriv = rtl_priv(hw);
  37. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  38. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU) {
  39. u32 value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
  40. if (enable)
  41. value32 |= MCUFWDL_EN;
  42. else
  43. value32 &= ~MCUFWDL_EN;
  44. rtl_write_dword(rtlpriv, REG_MCUFWDL, value32);
  45. } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE) {
  46. u8 tmp;
  47. if (enable) {
  48. tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  49. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1,
  50. tmp | 0x04);
  51. tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
  52. rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp | 0x01);
  53. tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL + 2);
  54. rtl_write_byte(rtlpriv, REG_MCUFWDL + 2, tmp & 0xf7);
  55. } else {
  56. tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
  57. rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp & 0xfe);
  58. rtl_write_byte(rtlpriv, REG_MCUFWDL + 1, 0x00);
  59. }
  60. }
  61. }
  62. static void _rtl92c_write_fw(struct ieee80211_hw *hw,
  63. enum version_8192c version, u8 *buffer, u32 size)
  64. {
  65. struct rtl_priv *rtlpriv = rtl_priv(hw);
  66. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  67. bool is_version_b;
  68. u8 *bufferptr = (u8 *)buffer;
  69. RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, "FW size is %d bytes,\n", size);
  70. is_version_b = IS_NORMAL_CHIP(version);
  71. if (is_version_b) {
  72. u32 pageNums, remainsize;
  73. u32 page, offset;
  74. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE)
  75. rtl_fill_dummy(bufferptr, &size);
  76. pageNums = size / FW_8192C_PAGE_SIZE;
  77. remainsize = size % FW_8192C_PAGE_SIZE;
  78. if (pageNums > 4)
  79. pr_err("Page numbers should not greater then 4\n");
  80. for (page = 0; page < pageNums; page++) {
  81. offset = page * FW_8192C_PAGE_SIZE;
  82. rtl_fw_page_write(hw, page, (bufferptr + offset),
  83. FW_8192C_PAGE_SIZE);
  84. }
  85. if (remainsize) {
  86. offset = pageNums * FW_8192C_PAGE_SIZE;
  87. page = pageNums;
  88. rtl_fw_page_write(hw, page, (bufferptr + offset),
  89. remainsize);
  90. }
  91. } else {
  92. rtl_fw_block_write(hw, buffer, size);
  93. }
  94. }
  95. static int _rtl92c_fw_free_to_go(struct ieee80211_hw *hw)
  96. {
  97. struct rtl_priv *rtlpriv = rtl_priv(hw);
  98. int err = -EIO;
  99. u32 counter = 0;
  100. u32 value32;
  101. do {
  102. value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
  103. } while ((counter++ < FW_8192C_POLLING_TIMEOUT_COUNT) &&
  104. (!(value32 & FWDL_ChkSum_rpt)));
  105. if (counter >= FW_8192C_POLLING_TIMEOUT_COUNT) {
  106. pr_err("chksum report fail! REG_MCUFWDL:0x%08x .\n",
  107. value32);
  108. goto exit;
  109. }
  110. value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
  111. value32 |= MCUFWDL_RDY;
  112. value32 &= ~WINTINI_RDY;
  113. rtl_write_dword(rtlpriv, REG_MCUFWDL, value32);
  114. counter = 0;
  115. do {
  116. value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
  117. if (value32 & WINTINI_RDY)
  118. return 0;
  119. mdelay(FW_8192C_POLLING_DELAY);
  120. } while (counter++ < FW_8192C_POLLING_TIMEOUT_COUNT);
  121. pr_err("Polling FW ready fail! REG_MCUFWDL:0x%08x.\n",
  122. value32);
  123. exit:
  124. return err;
  125. }
  126. int rtl92c_download_fw(struct ieee80211_hw *hw)
  127. {
  128. struct rtl_priv *rtlpriv = rtl_priv(hw);
  129. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  130. struct rtlwifi_firmware_header *pfwheader;
  131. u8 *pfwdata;
  132. u32 fwsize;
  133. int err;
  134. enum version_8192c version = rtlhal->version;
  135. if (!rtlhal->pfirmware)
  136. return 1;
  137. pfwheader = (struct rtlwifi_firmware_header *)rtlhal->pfirmware;
  138. pfwdata = (u8 *)rtlhal->pfirmware;
  139. fwsize = rtlhal->fwsize;
  140. if (IS_FW_HEADER_EXIST(pfwheader)) {
  141. RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG,
  142. "Firmware Version(%d), Signature(%#x),Size(%d)\n",
  143. pfwheader->version, pfwheader->signature,
  144. (int)sizeof(struct rtlwifi_firmware_header));
  145. rtlhal->fw_version = le16_to_cpu(pfwheader->version);
  146. rtlhal->fw_subversion = pfwheader->subversion;
  147. pfwdata = pfwdata + sizeof(struct rtlwifi_firmware_header);
  148. fwsize = fwsize - sizeof(struct rtlwifi_firmware_header);
  149. }
  150. _rtl92c_enable_fw_download(hw, true);
  151. _rtl92c_write_fw(hw, version, pfwdata, fwsize);
  152. _rtl92c_enable_fw_download(hw, false);
  153. err = _rtl92c_fw_free_to_go(hw);
  154. if (err)
  155. pr_err("Firmware is not ready to run!\n");
  156. return 0;
  157. }
  158. EXPORT_SYMBOL(rtl92c_download_fw);
  159. static bool _rtl92c_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum)
  160. {
  161. struct rtl_priv *rtlpriv = rtl_priv(hw);
  162. u8 val_hmetfr, val_mcutst_1;
  163. bool result = false;
  164. val_hmetfr = rtl_read_byte(rtlpriv, REG_HMETFR);
  165. val_mcutst_1 = rtl_read_byte(rtlpriv, (REG_MCUTST_1 + boxnum));
  166. if (((val_hmetfr >> boxnum) & BIT(0)) == 0 && val_mcutst_1 == 0)
  167. result = true;
  168. return result;
  169. }
  170. static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw,
  171. u8 element_id, u32 cmd_len, u8 *cmdbuffer)
  172. {
  173. struct rtl_priv *rtlpriv = rtl_priv(hw);
  174. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  175. u8 boxnum;
  176. u16 box_reg = 0, box_extreg = 0;
  177. u8 u1b_tmp;
  178. bool isfw_read = false;
  179. u8 buf_index = 0;
  180. bool bwrite_sucess = false;
  181. u8 wait_h2c_limmit = 100;
  182. u8 wait_writeh2c_limmit = 100;
  183. u8 boxcontent[4], boxextcontent[2];
  184. u32 h2c_waitcounter = 0;
  185. unsigned long flag;
  186. u8 idx;
  187. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n");
  188. while (true) {
  189. spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
  190. if (rtlhal->h2c_setinprogress) {
  191. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  192. "H2C set in progress! Wait to set..element_id(%d).\n",
  193. element_id);
  194. while (rtlhal->h2c_setinprogress) {
  195. spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock,
  196. flag);
  197. h2c_waitcounter++;
  198. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  199. "Wait 100 us (%d times)...\n",
  200. h2c_waitcounter);
  201. udelay(100);
  202. if (h2c_waitcounter > 1000)
  203. return;
  204. spin_lock_irqsave(&rtlpriv->locks.h2c_lock,
  205. flag);
  206. }
  207. spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
  208. } else {
  209. rtlhal->h2c_setinprogress = true;
  210. spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
  211. break;
  212. }
  213. }
  214. while (!bwrite_sucess) {
  215. wait_writeh2c_limmit--;
  216. if (wait_writeh2c_limmit == 0) {
  217. pr_err("Write H2C fail because no trigger for FW INT!\n");
  218. break;
  219. }
  220. boxnum = rtlhal->last_hmeboxnum;
  221. switch (boxnum) {
  222. case 0:
  223. box_reg = REG_HMEBOX_0;
  224. box_extreg = REG_HMEBOX_EXT_0;
  225. break;
  226. case 1:
  227. box_reg = REG_HMEBOX_1;
  228. box_extreg = REG_HMEBOX_EXT_1;
  229. break;
  230. case 2:
  231. box_reg = REG_HMEBOX_2;
  232. box_extreg = REG_HMEBOX_EXT_2;
  233. break;
  234. case 3:
  235. box_reg = REG_HMEBOX_3;
  236. box_extreg = REG_HMEBOX_EXT_3;
  237. break;
  238. default:
  239. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  240. "switch case %#x not processed\n", boxnum);
  241. break;
  242. }
  243. isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum);
  244. while (!isfw_read) {
  245. wait_h2c_limmit--;
  246. if (wait_h2c_limmit == 0) {
  247. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  248. "Waiting too long for FW read clear HMEBox(%d)!\n",
  249. boxnum);
  250. break;
  251. }
  252. udelay(10);
  253. isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum);
  254. u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF);
  255. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  256. "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n",
  257. boxnum, u1b_tmp);
  258. }
  259. if (!isfw_read) {
  260. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  261. "Write H2C register BOX[%d] fail!!!!! Fw do not read.\n",
  262. boxnum);
  263. break;
  264. }
  265. memset(boxcontent, 0, sizeof(boxcontent));
  266. memset(boxextcontent, 0, sizeof(boxextcontent));
  267. boxcontent[0] = element_id;
  268. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  269. "Write element_id box_reg(%4x) = %2x\n",
  270. box_reg, element_id);
  271. switch (cmd_len) {
  272. case 1:
  273. boxcontent[0] &= ~(BIT(7));
  274. memcpy((u8 *)(boxcontent) + 1,
  275. cmdbuffer + buf_index, 1);
  276. for (idx = 0; idx < 4; idx++) {
  277. rtl_write_byte(rtlpriv, box_reg + idx,
  278. boxcontent[idx]);
  279. }
  280. break;
  281. case 2:
  282. boxcontent[0] &= ~(BIT(7));
  283. memcpy((u8 *)(boxcontent) + 1,
  284. cmdbuffer + buf_index, 2);
  285. for (idx = 0; idx < 4; idx++) {
  286. rtl_write_byte(rtlpriv, box_reg + idx,
  287. boxcontent[idx]);
  288. }
  289. break;
  290. case 3:
  291. boxcontent[0] &= ~(BIT(7));
  292. memcpy((u8 *)(boxcontent) + 1,
  293. cmdbuffer + buf_index, 3);
  294. for (idx = 0; idx < 4; idx++) {
  295. rtl_write_byte(rtlpriv, box_reg + idx,
  296. boxcontent[idx]);
  297. }
  298. break;
  299. case 4:
  300. boxcontent[0] |= (BIT(7));
  301. memcpy((u8 *)(boxextcontent),
  302. cmdbuffer + buf_index, 2);
  303. memcpy((u8 *)(boxcontent) + 1,
  304. cmdbuffer + buf_index + 2, 2);
  305. for (idx = 0; idx < 2; idx++) {
  306. rtl_write_byte(rtlpriv, box_extreg + idx,
  307. boxextcontent[idx]);
  308. }
  309. for (idx = 0; idx < 4; idx++) {
  310. rtl_write_byte(rtlpriv, box_reg + idx,
  311. boxcontent[idx]);
  312. }
  313. break;
  314. case 5:
  315. boxcontent[0] |= (BIT(7));
  316. memcpy((u8 *)(boxextcontent),
  317. cmdbuffer + buf_index, 2);
  318. memcpy((u8 *)(boxcontent) + 1,
  319. cmdbuffer + buf_index + 2, 3);
  320. for (idx = 0; idx < 2; idx++) {
  321. rtl_write_byte(rtlpriv, box_extreg + idx,
  322. boxextcontent[idx]);
  323. }
  324. for (idx = 0; idx < 4; idx++) {
  325. rtl_write_byte(rtlpriv, box_reg + idx,
  326. boxcontent[idx]);
  327. }
  328. break;
  329. default:
  330. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  331. "switch case %#x not processed\n", cmd_len);
  332. break;
  333. }
  334. bwrite_sucess = true;
  335. rtlhal->last_hmeboxnum = boxnum + 1;
  336. if (rtlhal->last_hmeboxnum == 4)
  337. rtlhal->last_hmeboxnum = 0;
  338. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  339. "pHalData->last_hmeboxnum = %d\n",
  340. rtlhal->last_hmeboxnum);
  341. }
  342. spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
  343. rtlhal->h2c_setinprogress = false;
  344. spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
  345. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n");
  346. }
  347. void rtl92c_fill_h2c_cmd(struct ieee80211_hw *hw,
  348. u8 element_id, u32 cmd_len, u8 *cmdbuffer)
  349. {
  350. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  351. u32 tmp_cmdbuf[2];
  352. if (!rtlhal->fw_ready) {
  353. WARN_ONCE(true,
  354. "rtl8192c-common: return H2C cmd because of Fw download fail!!!\n");
  355. return;
  356. }
  357. memset(tmp_cmdbuf, 0, 8);
  358. memcpy(tmp_cmdbuf, cmdbuffer, cmd_len);
  359. _rtl92c_fill_h2c_command(hw, element_id, cmd_len, (u8 *)&tmp_cmdbuf);
  360. return;
  361. }
  362. EXPORT_SYMBOL(rtl92c_fill_h2c_cmd);
  363. void rtl92c_firmware_selfreset(struct ieee80211_hw *hw)
  364. {
  365. u8 u1b_tmp;
  366. u8 delay = 100;
  367. struct rtl_priv *rtlpriv = rtl_priv(hw);
  368. rtl_write_byte(rtlpriv, REG_HMETFR + 3, 0x20);
  369. u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  370. while (u1b_tmp & BIT(2)) {
  371. delay--;
  372. if (delay == 0) {
  373. WARN_ONCE(true, "rtl8192c-common: 8051 reset fail.\n");
  374. break;
  375. }
  376. udelay(50);
  377. u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  378. }
  379. }
  380. EXPORT_SYMBOL(rtl92c_firmware_selfreset);
  381. void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode)
  382. {
  383. struct rtl_priv *rtlpriv = rtl_priv(hw);
  384. u8 u1_h2c_set_pwrmode[3] = { 0 };
  385. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  386. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "FW LPS mode = %d\n", mode);
  387. SET_H2CCMD_PWRMODE_PARM_MODE(u1_h2c_set_pwrmode, mode);
  388. SET_H2CCMD_PWRMODE_PARM_SMART_PS(u1_h2c_set_pwrmode,
  389. (rtlpriv->mac80211.p2p) ? ppsc->smart_ps : 1);
  390. SET_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(u1_h2c_set_pwrmode,
  391. ppsc->reg_max_lps_awakeintvl);
  392. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
  393. "rtl92c_set_fw_rsvdpagepkt(): u1_h2c_set_pwrmode\n",
  394. u1_h2c_set_pwrmode, 3);
  395. rtl92c_fill_h2c_cmd(hw, H2C_SETPWRMODE, 3, u1_h2c_set_pwrmode);
  396. }
  397. EXPORT_SYMBOL(rtl92c_set_fw_pwrmode_cmd);
  398. #define BEACON_PG 0 /*->1*/
  399. #define PSPOLL_PG 2
  400. #define NULL_PG 3
  401. #define PROBERSP_PG 4 /*->5*/
  402. #define TOTAL_RESERVED_PKT_LEN 768
  403. static u8 reserved_page_packet[TOTAL_RESERVED_PKT_LEN] = {
  404. /* page 0 beacon */
  405. 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  406. 0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
  407. 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x50, 0x08,
  408. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  409. 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
  410. 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
  411. 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
  412. 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
  413. 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
  414. 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
  415. 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  416. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  418. 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
  419. 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  421. /* page 1 beacon */
  422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  425. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  426. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  427. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  430. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  431. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  432. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  433. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  434. 0x10, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x10, 0x00,
  435. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  436. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  437. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  438. /* page 2 ps-poll */
  439. 0xA4, 0x10, 0x01, 0xC0, 0x00, 0x40, 0x10, 0x10,
  440. 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
  441. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  442. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  443. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  444. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  445. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  446. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  447. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  448. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  449. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  450. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  451. 0x18, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
  452. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  453. 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  454. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  455. /* page 3 null */
  456. 0x48, 0x01, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
  457. 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
  458. 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
  459. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  460. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  461. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  462. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  463. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  464. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  465. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  466. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  467. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  468. 0x72, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
  469. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  470. 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  471. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  472. /* page 4 probe_resp */
  473. 0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
  474. 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
  475. 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
  476. 0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00,
  477. 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
  478. 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
  479. 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
  480. 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
  481. 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
  482. 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
  483. 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  484. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  485. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  486. 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
  487. 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  488. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  489. /* page 5 probe_resp */
  490. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  491. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  492. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  493. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  494. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  495. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  496. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  497. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  498. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  499. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  500. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  501. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  502. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  503. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  504. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  505. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  506. };
  507. void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw,
  508. bool (*cmd_send_packet)(struct ieee80211_hw *, struct sk_buff *))
  509. {
  510. struct rtl_priv *rtlpriv = rtl_priv(hw);
  511. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  512. struct sk_buff *skb = NULL;
  513. u32 totalpacketlen;
  514. bool rtstatus;
  515. u8 u1rsvdpageloc[3] = { 0 };
  516. bool b_dlok = false;
  517. u8 *beacon;
  518. u8 *p_pspoll;
  519. u8 *nullfunc;
  520. u8 *p_probersp;
  521. /*---------------------------------------------------------
  522. (1) beacon
  523. ---------------------------------------------------------*/
  524. beacon = &reserved_page_packet[BEACON_PG * 128];
  525. SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr);
  526. SET_80211_HDR_ADDRESS3(beacon, mac->bssid);
  527. /*-------------------------------------------------------
  528. (2) ps-poll
  529. --------------------------------------------------------*/
  530. p_pspoll = &reserved_page_packet[PSPOLL_PG * 128];
  531. SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000));
  532. SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid);
  533. SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr);
  534. SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1rsvdpageloc, PSPOLL_PG);
  535. /*--------------------------------------------------------
  536. (3) null data
  537. ---------------------------------------------------------*/
  538. nullfunc = &reserved_page_packet[NULL_PG * 128];
  539. SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid);
  540. SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr);
  541. SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid);
  542. SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1rsvdpageloc, NULL_PG);
  543. /*---------------------------------------------------------
  544. (4) probe response
  545. ----------------------------------------------------------*/
  546. p_probersp = &reserved_page_packet[PROBERSP_PG * 128];
  547. SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid);
  548. SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr);
  549. SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid);
  550. SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1rsvdpageloc, PROBERSP_PG);
  551. totalpacketlen = TOTAL_RESERVED_PKT_LEN;
  552. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
  553. "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n",
  554. &reserved_page_packet[0], totalpacketlen);
  555. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
  556. "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL\n",
  557. u1rsvdpageloc, 3);
  558. skb = dev_alloc_skb(totalpacketlen);
  559. if (!skb)
  560. return;
  561. skb_put_data(skb, &reserved_page_packet, totalpacketlen);
  562. if (cmd_send_packet)
  563. rtstatus = cmd_send_packet(hw, skb);
  564. else
  565. rtstatus = rtl_cmd_send_packet(hw, skb);
  566. if (rtstatus)
  567. b_dlok = true;
  568. if (b_dlok) {
  569. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  570. "Set RSVD page location to Fw.\n");
  571. RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
  572. "H2C_RSVDPAGE:\n",
  573. u1rsvdpageloc, 3);
  574. rtl92c_fill_h2c_cmd(hw, H2C_RSVDPAGE,
  575. sizeof(u1rsvdpageloc), u1rsvdpageloc);
  576. } else
  577. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  578. "Set RSVD page location to Fw FAIL!!!!!!.\n");
  579. }
  580. EXPORT_SYMBOL(rtl92c_set_fw_rsvdpagepkt);
  581. void rtl92c_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus)
  582. {
  583. u8 u1_joinbssrpt_parm[1] = { 0 };
  584. SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(u1_joinbssrpt_parm, mstatus);
  585. rtl92c_fill_h2c_cmd(hw, H2C_JOINBSSRPT, 1, u1_joinbssrpt_parm);
  586. }
  587. EXPORT_SYMBOL(rtl92c_set_fw_joinbss_report_cmd);
  588. static void rtl92c_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow)
  589. {
  590. u8 u1_ctwindow_period[1] = { ctwindow};
  591. rtl92c_fill_h2c_cmd(hw, H2C_P2P_PS_CTW_CMD, 1, u1_ctwindow_period);
  592. }
  593. /* refactored routine */
  594. static void set_noa_data(struct rtl_priv *rtlpriv,
  595. struct rtl_p2p_ps_info *p2pinfo,
  596. struct p2p_ps_offload_t *p2p_ps_offload)
  597. {
  598. int i;
  599. u32 start_time, tsf_low;
  600. /* hw only support 2 set of NoA */
  601. for (i = 0 ; i < p2pinfo->noa_num ; i++) {
  602. /* To control the reg setting for which NOA*/
  603. rtl_write_byte(rtlpriv, 0x5cf, (i << 4));
  604. if (i == 0)
  605. p2p_ps_offload->noa0_en = 1;
  606. else
  607. p2p_ps_offload->noa1_en = 1;
  608. /* config P2P NoA Descriptor Register */
  609. rtl_write_dword(rtlpriv, 0x5E0,
  610. p2pinfo->noa_duration[i]);
  611. rtl_write_dword(rtlpriv, 0x5E4,
  612. p2pinfo->noa_interval[i]);
  613. /*Get Current TSF value */
  614. tsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  615. start_time = p2pinfo->noa_start_time[i];
  616. if (p2pinfo->noa_count_type[i] != 1) {
  617. while (start_time <= (tsf_low+(50*1024))) {
  618. start_time += p2pinfo->noa_interval[i];
  619. if (p2pinfo->noa_count_type[i] != 255)
  620. p2pinfo->noa_count_type[i]--;
  621. }
  622. }
  623. rtl_write_dword(rtlpriv, 0x5E8, start_time);
  624. rtl_write_dword(rtlpriv, 0x5EC,
  625. p2pinfo->noa_count_type[i]);
  626. }
  627. }
  628. void rtl92c_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state)
  629. {
  630. struct rtl_priv *rtlpriv = rtl_priv(hw);
  631. struct rtl_ps_ctl *rtlps = rtl_psc(rtl_priv(hw));
  632. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  633. struct rtl_p2p_ps_info *p2pinfo = &(rtlps->p2p_ps_info);
  634. struct p2p_ps_offload_t *p2p_ps_offload = &rtlhal->p2p_ps_offload;
  635. u16 ctwindow;
  636. switch (p2p_ps_state) {
  637. case P2P_PS_DISABLE:
  638. RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD,
  639. "P2P_PS_DISABLE\n");
  640. memset(p2p_ps_offload, 0, sizeof(*p2p_ps_offload));
  641. break;
  642. case P2P_PS_ENABLE:
  643. RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD,
  644. "P2P_PS_ENABLE\n");
  645. /* update CTWindow value. */
  646. if (p2pinfo->ctwindow > 0) {
  647. p2p_ps_offload->ctwindow_en = 1;
  648. ctwindow = p2pinfo->ctwindow;
  649. rtl92c_set_p2p_ctw_period_cmd(hw, ctwindow);
  650. }
  651. /* call refactored routine */
  652. set_noa_data(rtlpriv, p2pinfo, p2p_ps_offload);
  653. if ((p2pinfo->opp_ps == 1) || (p2pinfo->noa_num > 0)) {
  654. /* rst p2p circuit */
  655. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST,
  656. BIT(4));
  657. p2p_ps_offload->offload_en = 1;
  658. if (P2P_ROLE_GO == rtlpriv->mac80211.p2p) {
  659. p2p_ps_offload->role = 1;
  660. p2p_ps_offload->allstasleep = 0;
  661. } else {
  662. p2p_ps_offload->role = 0;
  663. }
  664. p2p_ps_offload->discovery = 0;
  665. }
  666. break;
  667. case P2P_PS_SCAN:
  668. RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN\n");
  669. p2p_ps_offload->discovery = 1;
  670. break;
  671. case P2P_PS_SCAN_DONE:
  672. RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD,
  673. "P2P_PS_SCAN_DONE\n");
  674. p2p_ps_offload->discovery = 0;
  675. p2pinfo->p2p_ps_state = P2P_PS_ENABLE;
  676. break;
  677. default:
  678. break;
  679. }
  680. rtl92c_fill_h2c_cmd(hw, H2C_P2P_PS_OFFLOAD, 1, (u8 *)p2p_ps_offload);
  681. }
  682. EXPORT_SYMBOL_GPL(rtl92c_set_p2p_ps_offload_cmd);