rsi_91x_mgmt.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  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
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include <linux/timer.h>
  18. #include "rsi_mgmt.h"
  19. #include "rsi_common.h"
  20. #include "rsi_ps.h"
  21. #include "rsi_hal.h"
  22. static struct bootup_params boot_params_20 = {
  23. .magic_number = cpu_to_le16(0x5aa5),
  24. .crystal_good_time = 0x0,
  25. .valid = cpu_to_le32(VALID_20),
  26. .reserved_for_valids = 0x0,
  27. .bootup_mode_info = 0x0,
  28. .digital_loop_back_params = 0x0,
  29. .rtls_timestamp_en = 0x0,
  30. .host_spi_intr_cfg = 0x0,
  31. .device_clk_info = {{
  32. .pll_config_g = {
  33. .tapll_info_g = {
  34. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  35. (TA_PLL_M_VAL_20)),
  36. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  37. },
  38. .pll960_info_g = {
  39. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  40. (PLL960_N_VAL_20)),
  41. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  42. .pll_reg_3 = 0x0,
  43. },
  44. .afepll_info_g = {
  45. .pll_reg = cpu_to_le16(0x9f0),
  46. }
  47. },
  48. .switch_clk_g = {
  49. .switch_clk_info = cpu_to_le16(0xb),
  50. .bbp_lmac_clk_reg_val = cpu_to_le16(0x111),
  51. .umac_clock_reg_config = cpu_to_le16(0x48),
  52. .qspi_uart_clock_reg_config = cpu_to_le16(0x1211)
  53. }
  54. },
  55. {
  56. .pll_config_g = {
  57. .tapll_info_g = {
  58. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  59. (TA_PLL_M_VAL_20)),
  60. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  61. },
  62. .pll960_info_g = {
  63. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  64. (PLL960_N_VAL_20)),
  65. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  66. .pll_reg_3 = 0x0,
  67. },
  68. .afepll_info_g = {
  69. .pll_reg = cpu_to_le16(0x9f0),
  70. }
  71. },
  72. .switch_clk_g = {
  73. .switch_clk_info = 0x0,
  74. .bbp_lmac_clk_reg_val = 0x0,
  75. .umac_clock_reg_config = 0x0,
  76. .qspi_uart_clock_reg_config = 0x0
  77. }
  78. },
  79. {
  80. .pll_config_g = {
  81. .tapll_info_g = {
  82. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  83. (TA_PLL_M_VAL_20)),
  84. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  85. },
  86. .pll960_info_g = {
  87. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  88. (PLL960_N_VAL_20)),
  89. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  90. .pll_reg_3 = 0x0,
  91. },
  92. .afepll_info_g = {
  93. .pll_reg = cpu_to_le16(0x9f0),
  94. }
  95. },
  96. .switch_clk_g = {
  97. .switch_clk_info = 0x0,
  98. .bbp_lmac_clk_reg_val = 0x0,
  99. .umac_clock_reg_config = 0x0,
  100. .qspi_uart_clock_reg_config = 0x0
  101. }
  102. } },
  103. .buckboost_wakeup_cnt = 0x0,
  104. .pmu_wakeup_wait = 0x0,
  105. .shutdown_wait_time = 0x0,
  106. .pmu_slp_clkout_sel = 0x0,
  107. .wdt_prog_value = 0x0,
  108. .wdt_soc_rst_delay = 0x0,
  109. .dcdc_operation_mode = 0x0,
  110. .soc_reset_wait_cnt = 0x0,
  111. .waiting_time_at_fresh_sleep = 0x0,
  112. .max_threshold_to_avoid_sleep = 0x0,
  113. .beacon_resedue_alg_en = 0,
  114. };
  115. static struct bootup_params boot_params_40 = {
  116. .magic_number = cpu_to_le16(0x5aa5),
  117. .crystal_good_time = 0x0,
  118. .valid = cpu_to_le32(VALID_40),
  119. .reserved_for_valids = 0x0,
  120. .bootup_mode_info = 0x0,
  121. .digital_loop_back_params = 0x0,
  122. .rtls_timestamp_en = 0x0,
  123. .host_spi_intr_cfg = 0x0,
  124. .device_clk_info = {{
  125. .pll_config_g = {
  126. .tapll_info_g = {
  127. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  128. (TA_PLL_M_VAL_40)),
  129. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  130. },
  131. .pll960_info_g = {
  132. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  133. (PLL960_N_VAL_40)),
  134. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  135. .pll_reg_3 = 0x0,
  136. },
  137. .afepll_info_g = {
  138. .pll_reg = cpu_to_le16(0x9f0),
  139. }
  140. },
  141. .switch_clk_g = {
  142. .switch_clk_info = cpu_to_le16(0x09),
  143. .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121),
  144. .umac_clock_reg_config = cpu_to_le16(0x48),
  145. .qspi_uart_clock_reg_config = cpu_to_le16(0x1211)
  146. }
  147. },
  148. {
  149. .pll_config_g = {
  150. .tapll_info_g = {
  151. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  152. (TA_PLL_M_VAL_40)),
  153. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  154. },
  155. .pll960_info_g = {
  156. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  157. (PLL960_N_VAL_40)),
  158. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  159. .pll_reg_3 = 0x0,
  160. },
  161. .afepll_info_g = {
  162. .pll_reg = cpu_to_le16(0x9f0),
  163. }
  164. },
  165. .switch_clk_g = {
  166. .switch_clk_info = 0x0,
  167. .bbp_lmac_clk_reg_val = 0x0,
  168. .umac_clock_reg_config = 0x0,
  169. .qspi_uart_clock_reg_config = 0x0
  170. }
  171. },
  172. {
  173. .pll_config_g = {
  174. .tapll_info_g = {
  175. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  176. (TA_PLL_M_VAL_40)),
  177. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  178. },
  179. .pll960_info_g = {
  180. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  181. (PLL960_N_VAL_40)),
  182. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  183. .pll_reg_3 = 0x0,
  184. },
  185. .afepll_info_g = {
  186. .pll_reg = cpu_to_le16(0x9f0),
  187. }
  188. },
  189. .switch_clk_g = {
  190. .switch_clk_info = 0x0,
  191. .bbp_lmac_clk_reg_val = 0x0,
  192. .umac_clock_reg_config = 0x0,
  193. .qspi_uart_clock_reg_config = 0x0
  194. }
  195. } },
  196. .buckboost_wakeup_cnt = 0x0,
  197. .pmu_wakeup_wait = 0x0,
  198. .shutdown_wait_time = 0x0,
  199. .pmu_slp_clkout_sel = 0x0,
  200. .wdt_prog_value = 0x0,
  201. .wdt_soc_rst_delay = 0x0,
  202. .dcdc_operation_mode = 0x0,
  203. .soc_reset_wait_cnt = 0x0,
  204. .waiting_time_at_fresh_sleep = 0x0,
  205. .max_threshold_to_avoid_sleep = 0x0,
  206. .beacon_resedue_alg_en = 0,
  207. };
  208. static struct bootup_params_9116 boot_params_9116_20 = {
  209. .magic_number = cpu_to_le16(LOADED_TOKEN),
  210. .valid = cpu_to_le32(VALID_20),
  211. .device_clk_info_9116 = {{
  212. .pll_config_9116_g = {
  213. .pll_ctrl_set_reg = cpu_to_le16(0xd518),
  214. .pll_ctrl_clr_reg = cpu_to_le16(0x2ae7),
  215. .pll_modem_conig_reg = cpu_to_le16(0x2000),
  216. .soc_clk_config_reg = cpu_to_le16(0x0c18),
  217. .adc_dac_strm1_config_reg = cpu_to_le16(0x1100),
  218. .adc_dac_strm2_config_reg = cpu_to_le16(0x6600),
  219. },
  220. .switch_clk_9116_g = {
  221. .switch_clk_info =
  222. cpu_to_le32((RSI_SWITCH_TASS_CLK |
  223. RSI_SWITCH_WLAN_BBP_LMAC_CLK_REG |
  224. RSI_SWITCH_BBP_LMAC_CLK_REG)),
  225. .tass_clock_reg = cpu_to_le32(0x083C0503),
  226. .wlan_bbp_lmac_clk_reg_val = cpu_to_le32(0x01042001),
  227. .zbbt_bbp_lmac_clk_reg_val = cpu_to_le32(0x02010001),
  228. .bbp_lmac_clk_en_val = cpu_to_le32(0x0000003b),
  229. }
  230. },
  231. },
  232. };
  233. static struct bootup_params_9116 boot_params_9116_40 = {
  234. .magic_number = cpu_to_le16(LOADED_TOKEN),
  235. .valid = cpu_to_le32(VALID_40),
  236. .device_clk_info_9116 = {{
  237. .pll_config_9116_g = {
  238. .pll_ctrl_set_reg = cpu_to_le16(0xd518),
  239. .pll_ctrl_clr_reg = cpu_to_le16(0x2ae7),
  240. .pll_modem_conig_reg = cpu_to_le16(0x3000),
  241. .soc_clk_config_reg = cpu_to_le16(0x0c18),
  242. .adc_dac_strm1_config_reg = cpu_to_le16(0x0000),
  243. .adc_dac_strm2_config_reg = cpu_to_le16(0x6600),
  244. },
  245. .switch_clk_9116_g = {
  246. .switch_clk_info =
  247. cpu_to_le32((RSI_SWITCH_TASS_CLK |
  248. RSI_SWITCH_WLAN_BBP_LMAC_CLK_REG |
  249. RSI_SWITCH_BBP_LMAC_CLK_REG |
  250. RSI_MODEM_CLK_160MHZ)),
  251. .tass_clock_reg = cpu_to_le32(0x083C0503),
  252. .wlan_bbp_lmac_clk_reg_val = cpu_to_le32(0x01042002),
  253. .zbbt_bbp_lmac_clk_reg_val = cpu_to_le32(0x04010002),
  254. .bbp_lmac_clk_en_val = cpu_to_le32(0x0000003b),
  255. }
  256. },
  257. },
  258. };
  259. static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130};
  260. /**
  261. * rsi_set_default_parameters() - This function sets default parameters.
  262. * @common: Pointer to the driver private structure.
  263. *
  264. * Return: none
  265. */
  266. static void rsi_set_default_parameters(struct rsi_common *common)
  267. {
  268. common->band = NL80211_BAND_2GHZ;
  269. common->channel_width = BW_20MHZ;
  270. common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  271. common->channel = 1;
  272. common->min_rate = 0xffff;
  273. common->fsm_state = FSM_CARD_NOT_READY;
  274. common->iface_down = true;
  275. common->endpoint = EP_2GHZ_20MHZ;
  276. common->driver_mode = 1; /* End to end mode */
  277. common->lp_ps_handshake_mode = 0; /* Default no handShake mode*/
  278. common->ulp_ps_handshake_mode = 2; /* Default PKT handShake mode*/
  279. common->rf_power_val = 0; /* Default 1.9V */
  280. common->wlan_rf_power_mode = 0;
  281. common->obm_ant_sel_val = 2;
  282. common->beacon_interval = RSI_BEACON_INTERVAL;
  283. common->dtim_cnt = RSI_DTIM_COUNT;
  284. common->w9116_features.pll_mode = 0x0;
  285. common->w9116_features.rf_type = 1;
  286. common->w9116_features.wireless_mode = 0;
  287. common->w9116_features.enable_ppe = 0;
  288. common->w9116_features.afe_type = 1;
  289. common->w9116_features.dpd = 0;
  290. common->w9116_features.sifs_tx_enable = 0;
  291. common->w9116_features.ps_options = 0;
  292. }
  293. void init_bgscan_params(struct rsi_common *common)
  294. {
  295. memset((u8 *)&common->bgscan, 0, sizeof(struct rsi_bgscan_params));
  296. common->bgscan.bgscan_threshold = RSI_DEF_BGSCAN_THRLD;
  297. common->bgscan.roam_threshold = RSI_DEF_ROAM_THRLD;
  298. common->bgscan.bgscan_periodicity = RSI_BGSCAN_PERIODICITY;
  299. common->bgscan.num_bgscan_channels = 0;
  300. common->bgscan.two_probe = 1;
  301. common->bgscan.active_scan_duration = RSI_ACTIVE_SCAN_TIME;
  302. common->bgscan.passive_scan_duration = RSI_PASSIVE_SCAN_TIME;
  303. }
  304. /**
  305. * rsi_set_contention_vals() - This function sets the contention values for the
  306. * backoff procedure.
  307. * @common: Pointer to the driver private structure.
  308. *
  309. * Return: None.
  310. */
  311. static void rsi_set_contention_vals(struct rsi_common *common)
  312. {
  313. u8 ii = 0;
  314. for (; ii < NUM_EDCA_QUEUES; ii++) {
  315. common->tx_qinfo[ii].wme_params =
  316. (((common->edca_params[ii].cw_min / 2) +
  317. (common->edca_params[ii].aifs)) *
  318. WMM_SHORT_SLOT_TIME + SIFS_DURATION);
  319. common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
  320. common->tx_qinfo[ii].pkt_contended = 0;
  321. }
  322. }
  323. /**
  324. * rsi_send_internal_mgmt_frame() - This function sends management frames to
  325. * firmware.Also schedules packet to queue
  326. * for transmission.
  327. * @common: Pointer to the driver private structure.
  328. * @skb: Pointer to the socket buffer structure.
  329. *
  330. * Return: 0 on success, -1 on failure.
  331. */
  332. static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
  333. struct sk_buff *skb)
  334. {
  335. struct skb_info *tx_params;
  336. struct rsi_cmd_desc *desc;
  337. if (skb == NULL) {
  338. rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
  339. return -ENOMEM;
  340. }
  341. desc = (struct rsi_cmd_desc *)skb->data;
  342. desc->desc_dword0.len_qno |= cpu_to_le16(DESC_IMMEDIATE_WAKEUP);
  343. skb->priority = MGMT_SOFT_Q;
  344. tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
  345. tx_params->flags |= INTERNAL_MGMT_PKT;
  346. skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
  347. rsi_set_event(&common->tx_thread.event);
  348. return 0;
  349. }
  350. /**
  351. * rsi_load_radio_caps() - This function is used to send radio capabilities
  352. * values to firmware.
  353. * @common: Pointer to the driver private structure.
  354. *
  355. * Return: 0 on success, corresponding negative error code on failure.
  356. */
  357. static int rsi_load_radio_caps(struct rsi_common *common)
  358. {
  359. struct rsi_radio_caps *radio_caps;
  360. struct rsi_hw *adapter = common->priv;
  361. u16 inx = 0;
  362. u8 ii;
  363. u8 radio_id = 0;
  364. u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
  365. 0xf0, 0xf0, 0xf0, 0xf0,
  366. 0xf0, 0xf0, 0xf0, 0xf0,
  367. 0xf0, 0xf0, 0xf0, 0xf0,
  368. 0xf0, 0xf0, 0xf0, 0xf0};
  369. struct sk_buff *skb;
  370. u16 frame_len = sizeof(struct rsi_radio_caps);
  371. rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
  372. skb = dev_alloc_skb(frame_len);
  373. if (!skb) {
  374. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  375. __func__);
  376. return -ENOMEM;
  377. }
  378. memset(skb->data, 0, frame_len);
  379. radio_caps = (struct rsi_radio_caps *)skb->data;
  380. radio_caps->desc_dword0.frame_type = RADIO_CAPABILITIES;
  381. radio_caps->channel_num = common->channel;
  382. radio_caps->rf_model = RSI_RF_TYPE;
  383. radio_caps->radio_cfg_info = RSI_LMAC_CLOCK_80MHZ;
  384. if (common->channel_width == BW_40MHZ) {
  385. radio_caps->radio_cfg_info |= RSI_ENABLE_40MHZ;
  386. if (common->fsm_state == FSM_MAC_INIT_DONE) {
  387. struct ieee80211_hw *hw = adapter->hw;
  388. struct ieee80211_conf *conf = &hw->conf;
  389. if (conf_is_ht40_plus(conf)) {
  390. radio_caps->ppe_ack_rate =
  391. cpu_to_le16(LOWER_20_ENABLE |
  392. (LOWER_20_ENABLE >> 12));
  393. } else if (conf_is_ht40_minus(conf)) {
  394. radio_caps->ppe_ack_rate =
  395. cpu_to_le16(UPPER_20_ENABLE |
  396. (UPPER_20_ENABLE >> 12));
  397. } else {
  398. radio_caps->ppe_ack_rate =
  399. cpu_to_le16((BW_40MHZ << 12) |
  400. FULL40M_ENABLE);
  401. }
  402. }
  403. }
  404. radio_caps->radio_info |= radio_id;
  405. if (adapter->device_model == RSI_DEV_9116 &&
  406. common->channel_width == BW_20MHZ)
  407. radio_caps->radio_cfg_info &= ~0x3;
  408. radio_caps->sifs_tx_11n = cpu_to_le16(SIFS_TX_11N_VALUE);
  409. radio_caps->sifs_tx_11b = cpu_to_le16(SIFS_TX_11B_VALUE);
  410. radio_caps->slot_rx_11n = cpu_to_le16(SHORT_SLOT_VALUE);
  411. radio_caps->ofdm_ack_tout = cpu_to_le16(OFDM_ACK_TOUT_VALUE);
  412. radio_caps->cck_ack_tout = cpu_to_le16(CCK_ACK_TOUT_VALUE);
  413. radio_caps->preamble_type = cpu_to_le16(LONG_PREAMBLE);
  414. for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
  415. radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
  416. radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
  417. radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
  418. radio_caps->qos_params[ii].txop_q = 0;
  419. }
  420. for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
  421. if (common->edca_params[ii].cw_max > 0) {
  422. radio_caps->qos_params[ii].cont_win_min_q =
  423. cpu_to_le16(common->edca_params[ii].cw_min);
  424. radio_caps->qos_params[ii].cont_win_max_q =
  425. cpu_to_le16(common->edca_params[ii].cw_max);
  426. radio_caps->qos_params[ii].aifsn_val_q =
  427. cpu_to_le16(common->edca_params[ii].aifs << 8);
  428. radio_caps->qos_params[ii].txop_q =
  429. cpu_to_le16(common->edca_params[ii].txop);
  430. }
  431. }
  432. radio_caps->qos_params[BROADCAST_HW_Q].txop_q = cpu_to_le16(0xffff);
  433. radio_caps->qos_params[MGMT_HW_Q].txop_q = 0;
  434. radio_caps->qos_params[BEACON_HW_Q].txop_q = cpu_to_le16(0xffff);
  435. memcpy(&common->rate_pwr[0], &gc[0], 40);
  436. for (ii = 0; ii < 20; ii++)
  437. radio_caps->gcpd_per_rate[inx++] =
  438. cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
  439. rsi_set_len_qno(&radio_caps->desc_dword0.len_qno,
  440. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  441. skb_put(skb, frame_len);
  442. return rsi_send_internal_mgmt_frame(common, skb);
  443. }
  444. /**
  445. * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
  446. * @common: Pointer to the driver private structure.
  447. * @msg: Pointer to received packet.
  448. * @msg_len: Length of the received packet.
  449. * @type: Type of received packet.
  450. *
  451. * Return: 0 on success, -1 on failure.
  452. */
  453. static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
  454. u8 *msg,
  455. s32 msg_len)
  456. {
  457. struct rsi_hw *adapter = common->priv;
  458. struct ieee80211_tx_info *info;
  459. struct skb_info *rx_params;
  460. u8 pad_bytes = msg[4];
  461. struct sk_buff *skb;
  462. if (!adapter->sc_nvifs)
  463. return -ENOLINK;
  464. msg_len -= pad_bytes;
  465. if (msg_len <= 0) {
  466. rsi_dbg(MGMT_RX_ZONE,
  467. "%s: Invalid rx msg of len = %d\n",
  468. __func__, msg_len);
  469. return -EINVAL;
  470. }
  471. skb = dev_alloc_skb(msg_len);
  472. if (!skb)
  473. return -ENOMEM;
  474. skb_put_data(skb,
  475. (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
  476. msg_len);
  477. info = IEEE80211_SKB_CB(skb);
  478. rx_params = (struct skb_info *)info->driver_data;
  479. rx_params->rssi = rsi_get_rssi(msg);
  480. rx_params->channel = rsi_get_channel(msg);
  481. rsi_indicate_pkt_to_os(common, skb);
  482. return 0;
  483. }
  484. /**
  485. * rsi_hal_send_sta_notify_frame() - This function sends the station notify
  486. * frame to firmware.
  487. * @common: Pointer to the driver private structure.
  488. * @opmode: Operating mode of device.
  489. * @notify_event: Notification about station connection.
  490. * @bssid: bssid.
  491. * @qos_enable: Qos is enabled.
  492. * @aid: Aid (unique for all STA).
  493. *
  494. * Return: status: 0 on success, corresponding negative error code on failure.
  495. */
  496. int rsi_hal_send_sta_notify_frame(struct rsi_common *common, enum opmode opmode,
  497. u8 notify_event, const unsigned char *bssid,
  498. u8 qos_enable, u16 aid, u16 sta_id,
  499. struct ieee80211_vif *vif)
  500. {
  501. struct sk_buff *skb = NULL;
  502. struct rsi_peer_notify *peer_notify;
  503. u16 vap_id = ((struct vif_priv *)vif->drv_priv)->vap_id;
  504. int status;
  505. u16 frame_len = sizeof(struct rsi_peer_notify);
  506. rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
  507. skb = dev_alloc_skb(frame_len);
  508. if (!skb) {
  509. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  510. __func__);
  511. return -ENOMEM;
  512. }
  513. memset(skb->data, 0, frame_len);
  514. peer_notify = (struct rsi_peer_notify *)skb->data;
  515. if (opmode == RSI_OPMODE_STA)
  516. peer_notify->command = cpu_to_le16(PEER_TYPE_AP << 1);
  517. else if (opmode == RSI_OPMODE_AP)
  518. peer_notify->command = cpu_to_le16(PEER_TYPE_STA << 1);
  519. switch (notify_event) {
  520. case STA_CONNECTED:
  521. peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
  522. break;
  523. case STA_DISCONNECTED:
  524. peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
  525. break;
  526. default:
  527. break;
  528. }
  529. peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
  530. ether_addr_copy(peer_notify->mac_addr, bssid);
  531. peer_notify->mpdu_density = cpu_to_le16(RSI_MPDU_DENSITY);
  532. peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
  533. rsi_set_len_qno(&peer_notify->desc.desc_dword0.len_qno,
  534. (frame_len - FRAME_DESC_SZ),
  535. RSI_WIFI_MGMT_Q);
  536. peer_notify->desc.desc_dword0.frame_type = PEER_NOTIFY;
  537. peer_notify->desc.desc_dword3.qid_tid = sta_id;
  538. peer_notify->desc.desc_dword3.sta_id = vap_id;
  539. skb_put(skb, frame_len);
  540. status = rsi_send_internal_mgmt_frame(common, skb);
  541. if ((vif->type == NL80211_IFTYPE_STATION) &&
  542. (!status && qos_enable)) {
  543. rsi_set_contention_vals(common);
  544. status = rsi_load_radio_caps(common);
  545. }
  546. return status;
  547. }
  548. /**
  549. * rsi_send_aggregation_params_frame() - This function sends the ampdu
  550. * indication frame to firmware.
  551. * @common: Pointer to the driver private structure.
  552. * @tid: traffic identifier.
  553. * @ssn: ssn.
  554. * @buf_size: buffer size.
  555. * @event: notification about station connection.
  556. *
  557. * Return: 0 on success, corresponding negative error code on failure.
  558. */
  559. int rsi_send_aggregation_params_frame(struct rsi_common *common,
  560. u16 tid,
  561. u16 ssn,
  562. u8 buf_size,
  563. u8 event,
  564. u8 sta_id)
  565. {
  566. struct sk_buff *skb = NULL;
  567. struct rsi_aggr_params *aggr_params;
  568. u16 frame_len = sizeof(struct rsi_aggr_params);
  569. skb = dev_alloc_skb(frame_len);
  570. if (!skb) {
  571. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  572. __func__);
  573. return -ENOMEM;
  574. }
  575. memset(skb->data, 0, frame_len);
  576. aggr_params = (struct rsi_aggr_params *)skb->data;
  577. rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
  578. rsi_set_len_qno(&aggr_params->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
  579. aggr_params->desc_dword0.frame_type = AMPDU_IND;
  580. aggr_params->aggr_params = tid & RSI_AGGR_PARAMS_TID_MASK;
  581. aggr_params->peer_id = sta_id;
  582. if (event == STA_TX_ADDBA_DONE) {
  583. aggr_params->seq_start = cpu_to_le16(ssn);
  584. aggr_params->baw_size = cpu_to_le16(buf_size);
  585. aggr_params->aggr_params |= RSI_AGGR_PARAMS_START;
  586. } else if (event == STA_RX_ADDBA_DONE) {
  587. aggr_params->seq_start = cpu_to_le16(ssn);
  588. aggr_params->aggr_params |= (RSI_AGGR_PARAMS_START |
  589. RSI_AGGR_PARAMS_RX_AGGR);
  590. } else if (event == STA_RX_DELBA) {
  591. aggr_params->aggr_params |= RSI_AGGR_PARAMS_RX_AGGR;
  592. }
  593. skb_put(skb, frame_len);
  594. return rsi_send_internal_mgmt_frame(common, skb);
  595. }
  596. /**
  597. * rsi_program_bb_rf() - This function starts base band and RF programming.
  598. * This is called after initial configurations are done.
  599. * @common: Pointer to the driver private structure.
  600. *
  601. * Return: 0 on success, corresponding negative error code on failure.
  602. */
  603. static int rsi_program_bb_rf(struct rsi_common *common)
  604. {
  605. struct sk_buff *skb;
  606. struct rsi_bb_rf_prog *bb_rf_prog;
  607. u16 frame_len = sizeof(struct rsi_bb_rf_prog);
  608. rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
  609. skb = dev_alloc_skb(frame_len);
  610. if (!skb) {
  611. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  612. __func__);
  613. return -ENOMEM;
  614. }
  615. memset(skb->data, 0, frame_len);
  616. bb_rf_prog = (struct rsi_bb_rf_prog *)skb->data;
  617. rsi_set_len_qno(&bb_rf_prog->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
  618. bb_rf_prog->desc_dword0.frame_type = BBP_PROG_IN_TA;
  619. bb_rf_prog->endpoint = common->endpoint;
  620. bb_rf_prog->rf_power_mode = common->wlan_rf_power_mode;
  621. if (common->rf_reset) {
  622. bb_rf_prog->flags = cpu_to_le16(RF_RESET_ENABLE);
  623. rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
  624. __func__);
  625. common->rf_reset = 0;
  626. }
  627. common->bb_rf_prog_count = 1;
  628. bb_rf_prog->flags |= cpu_to_le16(PUT_BBP_RESET | BBP_REG_WRITE |
  629. (RSI_RF_TYPE << 4));
  630. skb_put(skb, frame_len);
  631. return rsi_send_internal_mgmt_frame(common, skb);
  632. }
  633. /**
  634. * rsi_set_vap_capabilities() - This function send vap capability to firmware.
  635. * @common: Pointer to the driver private structure.
  636. * @opmode: Operating mode of device.
  637. *
  638. * Return: 0 on success, corresponding negative error code on failure.
  639. */
  640. int rsi_set_vap_capabilities(struct rsi_common *common,
  641. enum opmode mode,
  642. u8 *mac_addr,
  643. u8 vap_id,
  644. u8 vap_status)
  645. {
  646. struct sk_buff *skb = NULL;
  647. struct rsi_vap_caps *vap_caps;
  648. struct rsi_hw *adapter = common->priv;
  649. struct ieee80211_hw *hw = adapter->hw;
  650. struct ieee80211_conf *conf = &hw->conf;
  651. u16 frame_len = sizeof(struct rsi_vap_caps);
  652. rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
  653. skb = dev_alloc_skb(frame_len);
  654. if (!skb) {
  655. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  656. __func__);
  657. return -ENOMEM;
  658. }
  659. memset(skb->data, 0, frame_len);
  660. vap_caps = (struct rsi_vap_caps *)skb->data;
  661. rsi_set_len_qno(&vap_caps->desc_dword0.len_qno,
  662. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  663. vap_caps->desc_dword0.frame_type = VAP_CAPABILITIES;
  664. vap_caps->status = vap_status;
  665. vap_caps->vif_type = mode;
  666. vap_caps->channel_bw = common->channel_width;
  667. vap_caps->vap_id = vap_id;
  668. vap_caps->radioid_macid = ((common->mac_id & 0xf) << 4) |
  669. (common->radio_id & 0xf);
  670. memcpy(vap_caps->mac_addr, mac_addr, IEEE80211_ADDR_LEN);
  671. vap_caps->keep_alive_period = cpu_to_le16(90);
  672. vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
  673. vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
  674. if (common->band == NL80211_BAND_5GHZ) {
  675. vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_6);
  676. vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6);
  677. } else {
  678. vap_caps->default_ctrl_rate = cpu_to_le16(RSI_RATE_1);
  679. vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_1);
  680. }
  681. if (conf_is_ht40(conf)) {
  682. if (conf_is_ht40_minus(conf))
  683. vap_caps->ctrl_rate_flags =
  684. cpu_to_le16(UPPER_20_ENABLE);
  685. else if (conf_is_ht40_plus(conf))
  686. vap_caps->ctrl_rate_flags =
  687. cpu_to_le16(LOWER_20_ENABLE);
  688. else
  689. vap_caps->ctrl_rate_flags =
  690. cpu_to_le16(FULL40M_ENABLE);
  691. }
  692. vap_caps->default_data_rate = 0;
  693. vap_caps->beacon_interval = cpu_to_le16(common->beacon_interval);
  694. vap_caps->dtim_period = cpu_to_le16(common->dtim_cnt);
  695. skb_put(skb, frame_len);
  696. return rsi_send_internal_mgmt_frame(common, skb);
  697. }
  698. /**
  699. * rsi_hal_load_key() - This function is used to load keys within the firmware.
  700. * @common: Pointer to the driver private structure.
  701. * @data: Pointer to the key data.
  702. * @key_len: Key length to be loaded.
  703. * @key_type: Type of key: GROUP/PAIRWISE.
  704. * @key_id: Key index.
  705. * @cipher: Type of cipher used.
  706. *
  707. * Return: 0 on success, -1 on failure.
  708. */
  709. int rsi_hal_load_key(struct rsi_common *common,
  710. u8 *data,
  711. u16 key_len,
  712. u8 key_type,
  713. u8 key_id,
  714. u32 cipher,
  715. s16 sta_id,
  716. struct ieee80211_vif *vif)
  717. {
  718. struct sk_buff *skb = NULL;
  719. struct rsi_set_key *set_key;
  720. u16 key_descriptor = 0;
  721. u16 frame_len = sizeof(struct rsi_set_key);
  722. rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
  723. skb = dev_alloc_skb(frame_len);
  724. if (!skb) {
  725. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  726. __func__);
  727. return -ENOMEM;
  728. }
  729. memset(skb->data, 0, frame_len);
  730. set_key = (struct rsi_set_key *)skb->data;
  731. if (key_type == RSI_GROUP_KEY) {
  732. key_descriptor = RSI_KEY_TYPE_BROADCAST;
  733. if (vif->type == NL80211_IFTYPE_AP)
  734. key_descriptor |= RSI_KEY_MODE_AP;
  735. }
  736. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  737. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  738. key_id = 0;
  739. key_descriptor |= RSI_WEP_KEY;
  740. if (key_len >= 13)
  741. key_descriptor |= RSI_WEP_KEY_104;
  742. } else if (cipher != KEY_TYPE_CLEAR) {
  743. key_descriptor |= RSI_CIPHER_WPA;
  744. if (cipher == WLAN_CIPHER_SUITE_TKIP)
  745. key_descriptor |= RSI_CIPHER_TKIP;
  746. }
  747. key_descriptor |= RSI_PROTECT_DATA_FRAMES;
  748. key_descriptor |= (key_id << RSI_KEY_ID_OFFSET);
  749. rsi_set_len_qno(&set_key->desc_dword0.len_qno,
  750. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  751. set_key->desc_dword0.frame_type = SET_KEY_REQ;
  752. set_key->key_desc = cpu_to_le16(key_descriptor);
  753. set_key->sta_id = sta_id;
  754. if (data) {
  755. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  756. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  757. memcpy(&set_key->key[key_id][1], data, key_len * 2);
  758. } else {
  759. memcpy(&set_key->key[0][0], data, key_len);
  760. }
  761. memcpy(set_key->tx_mic_key, &data[16], 8);
  762. memcpy(set_key->rx_mic_key, &data[24], 8);
  763. } else {
  764. memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ);
  765. }
  766. skb_put(skb, frame_len);
  767. return rsi_send_internal_mgmt_frame(common, skb);
  768. }
  769. /*
  770. * This function sends the common device configuration parameters to device.
  771. * This frame includes the useful information to make device works on
  772. * specific operating mode.
  773. */
  774. static int rsi_send_common_dev_params(struct rsi_common *common)
  775. {
  776. struct sk_buff *skb;
  777. u16 frame_len;
  778. struct rsi_config_vals *dev_cfgs;
  779. frame_len = sizeof(struct rsi_config_vals);
  780. rsi_dbg(MGMT_TX_ZONE, "Sending common device config params\n");
  781. skb = dev_alloc_skb(frame_len);
  782. if (!skb) {
  783. rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
  784. return -ENOMEM;
  785. }
  786. memset(skb->data, 0, frame_len);
  787. dev_cfgs = (struct rsi_config_vals *)skb->data;
  788. memset(dev_cfgs, 0, (sizeof(struct rsi_config_vals)));
  789. rsi_set_len_qno(&dev_cfgs->len_qno, (frame_len - FRAME_DESC_SZ),
  790. RSI_COEX_Q);
  791. dev_cfgs->pkt_type = COMMON_DEV_CONFIG;
  792. dev_cfgs->lp_ps_handshake = common->lp_ps_handshake_mode;
  793. dev_cfgs->ulp_ps_handshake = common->ulp_ps_handshake_mode;
  794. dev_cfgs->unused_ulp_gpio = RSI_UNUSED_ULP_GPIO_BITMAP;
  795. dev_cfgs->unused_soc_gpio_bitmap =
  796. cpu_to_le32(RSI_UNUSED_SOC_GPIO_BITMAP);
  797. dev_cfgs->opermode = common->oper_mode;
  798. dev_cfgs->wlan_rf_pwr_mode = common->wlan_rf_power_mode;
  799. dev_cfgs->driver_mode = common->driver_mode;
  800. dev_cfgs->region_code = NL80211_DFS_FCC;
  801. dev_cfgs->antenna_sel_val = common->obm_ant_sel_val;
  802. skb_put(skb, frame_len);
  803. return rsi_send_internal_mgmt_frame(common, skb);
  804. }
  805. /*
  806. * rsi_load_bootup_params() - This function send bootup params to the firmware.
  807. * @common: Pointer to the driver private structure.
  808. *
  809. * Return: 0 on success, corresponding error code on failure.
  810. */
  811. static int rsi_load_bootup_params(struct rsi_common *common)
  812. {
  813. struct sk_buff *skb;
  814. struct rsi_boot_params *boot_params;
  815. rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
  816. skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
  817. if (!skb) {
  818. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  819. __func__);
  820. return -ENOMEM;
  821. }
  822. memset(skb->data, 0, sizeof(struct rsi_boot_params));
  823. boot_params = (struct rsi_boot_params *)skb->data;
  824. rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
  825. if (common->channel_width == BW_40MHZ) {
  826. memcpy(&boot_params->bootup_params,
  827. &boot_params_40,
  828. sizeof(struct bootup_params));
  829. rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
  830. UMAC_CLK_40BW);
  831. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
  832. } else {
  833. memcpy(&boot_params->bootup_params,
  834. &boot_params_20,
  835. sizeof(struct bootup_params));
  836. if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
  837. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
  838. rsi_dbg(MGMT_TX_ZONE,
  839. "%s: Packet 20MHZ <=== %d\n", __func__,
  840. UMAC_CLK_20BW);
  841. } else {
  842. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
  843. rsi_dbg(MGMT_TX_ZONE,
  844. "%s: Packet 20MHZ <=== %d\n", __func__,
  845. UMAC_CLK_40MHZ);
  846. }
  847. }
  848. /**
  849. * Bit{0:11} indicates length of the Packet
  850. * Bit{12:15} indicates host queue number
  851. */
  852. boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
  853. (RSI_WIFI_MGMT_Q << 12));
  854. boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
  855. skb_put(skb, sizeof(struct rsi_boot_params));
  856. return rsi_send_internal_mgmt_frame(common, skb);
  857. }
  858. static int rsi_load_9116_bootup_params(struct rsi_common *common)
  859. {
  860. struct sk_buff *skb;
  861. struct rsi_boot_params_9116 *boot_params;
  862. rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
  863. skb = dev_alloc_skb(sizeof(struct rsi_boot_params_9116));
  864. if (!skb)
  865. return -ENOMEM;
  866. memset(skb->data, 0, sizeof(struct rsi_boot_params));
  867. boot_params = (struct rsi_boot_params_9116 *)skb->data;
  868. if (common->channel_width == BW_40MHZ) {
  869. memcpy(&boot_params->bootup_params,
  870. &boot_params_9116_40,
  871. sizeof(struct bootup_params_9116));
  872. rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
  873. UMAC_CLK_40BW);
  874. boot_params->umac_clk = cpu_to_le16(UMAC_CLK_40BW);
  875. } else {
  876. memcpy(&boot_params->bootup_params,
  877. &boot_params_9116_20,
  878. sizeof(struct bootup_params_9116));
  879. if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
  880. boot_params->umac_clk = cpu_to_le16(UMAC_CLK_20BW);
  881. rsi_dbg(MGMT_TX_ZONE,
  882. "%s: Packet 20MHZ <=== %d\n", __func__,
  883. UMAC_CLK_20BW);
  884. } else {
  885. boot_params->umac_clk = cpu_to_le16(UMAC_CLK_40MHZ);
  886. rsi_dbg(MGMT_TX_ZONE,
  887. "%s: Packet 20MHZ <=== %d\n", __func__,
  888. UMAC_CLK_40MHZ);
  889. }
  890. }
  891. rsi_set_len_qno(&boot_params->desc_dword0.len_qno,
  892. sizeof(struct bootup_params_9116), RSI_WIFI_MGMT_Q);
  893. boot_params->desc_dword0.frame_type = BOOTUP_PARAMS_REQUEST;
  894. skb_put(skb, sizeof(struct rsi_boot_params_9116));
  895. return rsi_send_internal_mgmt_frame(common, skb);
  896. }
  897. /**
  898. * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
  899. * internal management frame to indicate it to firmware.
  900. * @common: Pointer to the driver private structure.
  901. *
  902. * Return: 0 on success, corresponding error code on failure.
  903. */
  904. static int rsi_send_reset_mac(struct rsi_common *common)
  905. {
  906. struct sk_buff *skb;
  907. struct rsi_mac_frame *mgmt_frame;
  908. rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
  909. skb = dev_alloc_skb(FRAME_DESC_SZ);
  910. if (!skb) {
  911. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  912. __func__);
  913. return -ENOMEM;
  914. }
  915. memset(skb->data, 0, FRAME_DESC_SZ);
  916. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  917. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  918. mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
  919. mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
  920. #define RSI_9116_DEF_TA_AGGR 3
  921. if (common->priv->device_model == RSI_DEV_9116)
  922. mgmt_frame->desc_word[3] |=
  923. cpu_to_le16(RSI_9116_DEF_TA_AGGR << 8);
  924. skb_put(skb, FRAME_DESC_SZ);
  925. return rsi_send_internal_mgmt_frame(common, skb);
  926. }
  927. /**
  928. * rsi_band_check() - This function programs the band
  929. * @common: Pointer to the driver private structure.
  930. *
  931. * Return: 0 on success, corresponding error code on failure.
  932. */
  933. int rsi_band_check(struct rsi_common *common,
  934. struct ieee80211_channel *curchan)
  935. {
  936. struct rsi_hw *adapter = common->priv;
  937. struct ieee80211_hw *hw = adapter->hw;
  938. u8 prev_bw = common->channel_width;
  939. u8 prev_ep = common->endpoint;
  940. int status = 0;
  941. if (common->band != curchan->band) {
  942. common->rf_reset = 1;
  943. common->band = curchan->band;
  944. }
  945. if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) ||
  946. (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20))
  947. common->channel_width = BW_20MHZ;
  948. else
  949. common->channel_width = BW_40MHZ;
  950. if (common->band == NL80211_BAND_2GHZ) {
  951. if (common->channel_width)
  952. common->endpoint = EP_2GHZ_40MHZ;
  953. else
  954. common->endpoint = EP_2GHZ_20MHZ;
  955. } else {
  956. if (common->channel_width)
  957. common->endpoint = EP_5GHZ_40MHZ;
  958. else
  959. common->endpoint = EP_5GHZ_20MHZ;
  960. }
  961. if (common->endpoint != prev_ep) {
  962. status = rsi_program_bb_rf(common);
  963. if (status)
  964. return status;
  965. }
  966. if (common->channel_width != prev_bw) {
  967. if (adapter->device_model == RSI_DEV_9116)
  968. status = rsi_load_9116_bootup_params(common);
  969. else
  970. status = rsi_load_bootup_params(common);
  971. if (status)
  972. return status;
  973. status = rsi_load_radio_caps(common);
  974. if (status)
  975. return status;
  976. }
  977. return status;
  978. }
  979. /**
  980. * rsi_set_channel() - This function programs the channel.
  981. * @common: Pointer to the driver private structure.
  982. * @channel: Channel value to be set.
  983. *
  984. * Return: 0 on success, corresponding error code on failure.
  985. */
  986. int rsi_set_channel(struct rsi_common *common,
  987. struct ieee80211_channel *channel)
  988. {
  989. struct sk_buff *skb = NULL;
  990. struct rsi_chan_config *chan_cfg;
  991. u16 frame_len = sizeof(struct rsi_chan_config);
  992. rsi_dbg(MGMT_TX_ZONE,
  993. "%s: Sending scan req frame\n", __func__);
  994. skb = dev_alloc_skb(frame_len);
  995. if (!skb) {
  996. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  997. __func__);
  998. return -ENOMEM;
  999. }
  1000. if (!channel) {
  1001. dev_kfree_skb(skb);
  1002. return 0;
  1003. }
  1004. memset(skb->data, 0, frame_len);
  1005. chan_cfg = (struct rsi_chan_config *)skb->data;
  1006. rsi_set_len_qno(&chan_cfg->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
  1007. chan_cfg->desc_dword0.frame_type = SCAN_REQUEST;
  1008. chan_cfg->channel_number = channel->hw_value;
  1009. chan_cfg->antenna_gain_offset_2g = channel->max_antenna_gain;
  1010. chan_cfg->antenna_gain_offset_5g = channel->max_antenna_gain;
  1011. chan_cfg->region_rftype = (RSI_RF_TYPE & 0xf) << 4;
  1012. if ((channel->flags & IEEE80211_CHAN_NO_IR) ||
  1013. (channel->flags & IEEE80211_CHAN_RADAR)) {
  1014. chan_cfg->antenna_gain_offset_2g |= RSI_CHAN_RADAR;
  1015. } else {
  1016. if (common->tx_power < channel->max_power)
  1017. chan_cfg->tx_power = cpu_to_le16(common->tx_power);
  1018. else
  1019. chan_cfg->tx_power = cpu_to_le16(channel->max_power);
  1020. }
  1021. chan_cfg->region_rftype |= (common->priv->dfs_region & 0xf);
  1022. if (common->channel_width == BW_40MHZ)
  1023. chan_cfg->channel_width = 0x1;
  1024. common->channel = channel->hw_value;
  1025. skb_put(skb, frame_len);
  1026. return rsi_send_internal_mgmt_frame(common, skb);
  1027. }
  1028. /**
  1029. * rsi_send_radio_params_update() - This function sends the radio
  1030. * parameters update to device
  1031. * @common: Pointer to the driver private structure.
  1032. * @channel: Channel value to be set.
  1033. *
  1034. * Return: 0 on success, corresponding error code on failure.
  1035. */
  1036. int rsi_send_radio_params_update(struct rsi_common *common)
  1037. {
  1038. struct rsi_mac_frame *cmd_frame;
  1039. struct sk_buff *skb = NULL;
  1040. rsi_dbg(MGMT_TX_ZONE,
  1041. "%s: Sending Radio Params update frame\n", __func__);
  1042. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1043. if (!skb) {
  1044. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1045. __func__);
  1046. return -ENOMEM;
  1047. }
  1048. memset(skb->data, 0, FRAME_DESC_SZ);
  1049. cmd_frame = (struct rsi_mac_frame *)skb->data;
  1050. cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1051. cmd_frame->desc_word[1] = cpu_to_le16(RADIO_PARAMS_UPDATE);
  1052. cmd_frame->desc_word[3] = cpu_to_le16(BIT(0));
  1053. cmd_frame->desc_word[3] |= cpu_to_le16(common->tx_power << 8);
  1054. skb_put(skb, FRAME_DESC_SZ);
  1055. return rsi_send_internal_mgmt_frame(common, skb);
  1056. }
  1057. /* This function programs the threshold. */
  1058. int rsi_send_vap_dynamic_update(struct rsi_common *common)
  1059. {
  1060. struct sk_buff *skb;
  1061. struct rsi_dynamic_s *dynamic_frame;
  1062. rsi_dbg(MGMT_TX_ZONE,
  1063. "%s: Sending vap update indication frame\n", __func__);
  1064. skb = dev_alloc_skb(sizeof(struct rsi_dynamic_s));
  1065. if (!skb)
  1066. return -ENOMEM;
  1067. memset(skb->data, 0, sizeof(struct rsi_dynamic_s));
  1068. dynamic_frame = (struct rsi_dynamic_s *)skb->data;
  1069. rsi_set_len_qno(&dynamic_frame->desc_dword0.len_qno,
  1070. sizeof(dynamic_frame->frame_body), RSI_WIFI_MGMT_Q);
  1071. dynamic_frame->desc_dword0.frame_type = VAP_DYNAMIC_UPDATE;
  1072. dynamic_frame->desc_dword2.pkt_info =
  1073. cpu_to_le32(common->rts_threshold);
  1074. if (common->wow_flags & RSI_WOW_ENABLED) {
  1075. /* Beacon miss threshold */
  1076. dynamic_frame->desc_dword3.token =
  1077. cpu_to_le16(RSI_BCN_MISS_THRESHOLD);
  1078. dynamic_frame->frame_body.keep_alive_period =
  1079. cpu_to_le16(RSI_WOW_KEEPALIVE);
  1080. } else {
  1081. dynamic_frame->frame_body.keep_alive_period =
  1082. cpu_to_le16(RSI_DEF_KEEPALIVE);
  1083. }
  1084. dynamic_frame->desc_dword3.sta_id = 0; /* vap id */
  1085. skb_put(skb, sizeof(struct rsi_dynamic_s));
  1086. return rsi_send_internal_mgmt_frame(common, skb);
  1087. }
  1088. /**
  1089. * rsi_compare() - This function is used to compare two integers
  1090. * @a: pointer to the first integer
  1091. * @b: pointer to the second integer
  1092. *
  1093. * Return: 0 if both are equal, -1 if the first is smaller, else 1
  1094. */
  1095. static int rsi_compare(const void *a, const void *b)
  1096. {
  1097. u16 _a = *(const u16 *)(a);
  1098. u16 _b = *(const u16 *)(b);
  1099. if (_a > _b)
  1100. return -1;
  1101. if (_a < _b)
  1102. return 1;
  1103. return 0;
  1104. }
  1105. /**
  1106. * rsi_map_rates() - This function is used to map selected rates to hw rates.
  1107. * @rate: The standard rate to be mapped.
  1108. * @offset: Offset that will be returned.
  1109. *
  1110. * Return: 0 if it is a mcs rate, else 1
  1111. */
  1112. static bool rsi_map_rates(u16 rate, int *offset)
  1113. {
  1114. int kk;
  1115. for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
  1116. if (rate == mcs[kk]) {
  1117. *offset = kk;
  1118. return false;
  1119. }
  1120. }
  1121. for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
  1122. if (rate == rsi_rates[kk].bitrate / 5) {
  1123. *offset = kk;
  1124. break;
  1125. }
  1126. }
  1127. return true;
  1128. }
  1129. /**
  1130. * rsi_send_auto_rate_request() - This function is to set rates for connection
  1131. * and send autorate request to firmware.
  1132. * @common: Pointer to the driver private structure.
  1133. *
  1134. * Return: 0 on success, corresponding error code on failure.
  1135. */
  1136. static int rsi_send_auto_rate_request(struct rsi_common *common,
  1137. struct ieee80211_sta *sta,
  1138. u16 sta_id,
  1139. struct ieee80211_vif *vif)
  1140. {
  1141. struct sk_buff *skb;
  1142. struct rsi_auto_rate *auto_rate;
  1143. int ii = 0, jj = 0, kk = 0;
  1144. struct ieee80211_hw *hw = common->priv->hw;
  1145. u8 band = hw->conf.chandef.chan->band;
  1146. u8 num_supported_rates = 0;
  1147. u8 rate_table_offset, rate_offset = 0;
  1148. u32 rate_bitmap;
  1149. u16 *selected_rates, min_rate;
  1150. bool is_ht = false, is_sgi = false;
  1151. u16 frame_len = sizeof(struct rsi_auto_rate);
  1152. rsi_dbg(MGMT_TX_ZONE,
  1153. "%s: Sending auto rate request frame\n", __func__);
  1154. skb = dev_alloc_skb(frame_len);
  1155. if (!skb) {
  1156. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1157. __func__);
  1158. return -ENOMEM;
  1159. }
  1160. memset(skb->data, 0, frame_len);
  1161. selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
  1162. if (!selected_rates) {
  1163. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
  1164. __func__);
  1165. dev_kfree_skb(skb);
  1166. return -ENOMEM;
  1167. }
  1168. auto_rate = (struct rsi_auto_rate *)skb->data;
  1169. auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
  1170. auto_rate->collision_tolerance = cpu_to_le16(3);
  1171. auto_rate->failure_limit = cpu_to_le16(3);
  1172. auto_rate->initial_boundary = cpu_to_le16(3);
  1173. auto_rate->max_threshold_limt = cpu_to_le16(27);
  1174. auto_rate->desc.desc_dword0.frame_type = AUTO_RATE_IND;
  1175. if (common->channel_width == BW_40MHZ)
  1176. auto_rate->desc.desc_dword3.qid_tid = BW_40MHZ;
  1177. auto_rate->desc.desc_dword3.sta_id = sta_id;
  1178. if (vif->type == NL80211_IFTYPE_STATION) {
  1179. rate_bitmap = common->bitrate_mask[band];
  1180. is_ht = common->vif_info[0].is_ht;
  1181. is_sgi = common->vif_info[0].sgi;
  1182. } else {
  1183. rate_bitmap = sta->supp_rates[band];
  1184. is_ht = sta->ht_cap.ht_supported;
  1185. if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
  1186. (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
  1187. is_sgi = true;
  1188. }
  1189. if (band == NL80211_BAND_2GHZ) {
  1190. if ((rate_bitmap == 0) && (is_ht))
  1191. min_rate = RSI_RATE_MCS0;
  1192. else
  1193. min_rate = RSI_RATE_1;
  1194. rate_table_offset = 0;
  1195. } else {
  1196. if ((rate_bitmap == 0) && (is_ht))
  1197. min_rate = RSI_RATE_MCS0;
  1198. else
  1199. min_rate = RSI_RATE_6;
  1200. rate_table_offset = 4;
  1201. }
  1202. for (ii = 0, jj = 0;
  1203. ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) {
  1204. if (rate_bitmap & BIT(ii)) {
  1205. selected_rates[jj++] =
  1206. (rsi_rates[ii + rate_table_offset].bitrate / 5);
  1207. rate_offset++;
  1208. }
  1209. }
  1210. num_supported_rates = jj;
  1211. if (is_ht) {
  1212. for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
  1213. selected_rates[jj++] = mcs[ii];
  1214. num_supported_rates += ARRAY_SIZE(mcs);
  1215. rate_offset += ARRAY_SIZE(mcs);
  1216. }
  1217. sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
  1218. /* mapping the rates to RSI rates */
  1219. for (ii = 0; ii < jj; ii++) {
  1220. if (rsi_map_rates(selected_rates[ii], &kk)) {
  1221. auto_rate->supported_rates[ii] =
  1222. cpu_to_le16(rsi_rates[kk].hw_value);
  1223. } else {
  1224. auto_rate->supported_rates[ii] =
  1225. cpu_to_le16(rsi_mcsrates[kk]);
  1226. }
  1227. }
  1228. /* loading HT rates in the bottom half of the auto rate table */
  1229. if (is_ht) {
  1230. for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
  1231. ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
  1232. if (is_sgi || conf_is_ht40(&common->priv->hw->conf))
  1233. auto_rate->supported_rates[ii++] =
  1234. cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
  1235. else
  1236. auto_rate->supported_rates[ii++] =
  1237. cpu_to_le16(rsi_mcsrates[kk]);
  1238. auto_rate->supported_rates[ii] =
  1239. cpu_to_le16(rsi_mcsrates[kk--]);
  1240. }
  1241. for (; ii < (RSI_TBL_SZ - 1); ii++) {
  1242. auto_rate->supported_rates[ii] =
  1243. cpu_to_le16(rsi_mcsrates[0]);
  1244. }
  1245. }
  1246. for (; ii < RSI_TBL_SZ; ii++)
  1247. auto_rate->supported_rates[ii] = cpu_to_le16(min_rate);
  1248. auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
  1249. auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
  1250. num_supported_rates *= 2;
  1251. rsi_set_len_qno(&auto_rate->desc.desc_dword0.len_qno,
  1252. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  1253. skb_put(skb, frame_len);
  1254. kfree(selected_rates);
  1255. return rsi_send_internal_mgmt_frame(common, skb);
  1256. }
  1257. /**
  1258. * rsi_inform_bss_status() - This function informs about bss status with the
  1259. * help of sta notify params by sending an internal
  1260. * management frame to firmware.
  1261. * @common: Pointer to the driver private structure.
  1262. * @status: Bss status type.
  1263. * @bssid: Bssid.
  1264. * @qos_enable: Qos is enabled.
  1265. * @aid: Aid (unique for all STAs).
  1266. *
  1267. * Return: None.
  1268. */
  1269. void rsi_inform_bss_status(struct rsi_common *common,
  1270. enum opmode opmode,
  1271. u8 status,
  1272. const u8 *addr,
  1273. u8 qos_enable,
  1274. u16 aid,
  1275. struct ieee80211_sta *sta,
  1276. u16 sta_id,
  1277. u16 assoc_cap,
  1278. struct ieee80211_vif *vif)
  1279. {
  1280. if (status) {
  1281. if (opmode == RSI_OPMODE_STA)
  1282. common->hw_data_qs_blocked = true;
  1283. rsi_hal_send_sta_notify_frame(common,
  1284. opmode,
  1285. STA_CONNECTED,
  1286. addr,
  1287. qos_enable,
  1288. aid, sta_id,
  1289. vif);
  1290. if (common->min_rate == 0xffff)
  1291. rsi_send_auto_rate_request(common, sta, sta_id, vif);
  1292. if (opmode == RSI_OPMODE_STA &&
  1293. !(assoc_cap & WLAN_CAPABILITY_PRIVACY) &&
  1294. !rsi_send_block_unblock_frame(common, false))
  1295. common->hw_data_qs_blocked = false;
  1296. } else {
  1297. if (opmode == RSI_OPMODE_STA)
  1298. common->hw_data_qs_blocked = true;
  1299. if (!(common->wow_flags & RSI_WOW_ENABLED))
  1300. rsi_hal_send_sta_notify_frame(common, opmode,
  1301. STA_DISCONNECTED, addr,
  1302. qos_enable, aid, sta_id,
  1303. vif);
  1304. if (opmode == RSI_OPMODE_STA)
  1305. rsi_send_block_unblock_frame(common, true);
  1306. }
  1307. }
  1308. /**
  1309. * rsi_eeprom_read() - This function sends a frame to read the mac address
  1310. * from the eeprom.
  1311. * @common: Pointer to the driver private structure.
  1312. *
  1313. * Return: 0 on success, -1 on failure.
  1314. */
  1315. static int rsi_eeprom_read(struct rsi_common *common)
  1316. {
  1317. struct rsi_eeprom_read_frame *mgmt_frame;
  1318. struct rsi_hw *adapter = common->priv;
  1319. struct sk_buff *skb;
  1320. rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
  1321. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1322. if (!skb) {
  1323. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1324. __func__);
  1325. return -ENOMEM;
  1326. }
  1327. memset(skb->data, 0, FRAME_DESC_SZ);
  1328. mgmt_frame = (struct rsi_eeprom_read_frame *)skb->data;
  1329. /* FrameType */
  1330. rsi_set_len_qno(&mgmt_frame->len_qno, 0, RSI_WIFI_MGMT_Q);
  1331. mgmt_frame->pkt_type = EEPROM_READ;
  1332. /* Number of bytes to read */
  1333. mgmt_frame->pkt_info =
  1334. cpu_to_le32((adapter->eeprom.length << RSI_EEPROM_LEN_OFFSET) &
  1335. RSI_EEPROM_LEN_MASK);
  1336. mgmt_frame->pkt_info |= cpu_to_le32((3 << RSI_EEPROM_HDR_SIZE_OFFSET) &
  1337. RSI_EEPROM_HDR_SIZE_MASK);
  1338. /* Address to read */
  1339. mgmt_frame->eeprom_offset = cpu_to_le32(adapter->eeprom.offset);
  1340. skb_put(skb, FRAME_DESC_SZ);
  1341. return rsi_send_internal_mgmt_frame(common, skb);
  1342. }
  1343. /**
  1344. * This function sends a frame to block/unblock
  1345. * data queues in the firmware
  1346. *
  1347. * @param common Pointer to the driver private structure.
  1348. * @param block event - block if true, unblock if false
  1349. * @return 0 on success, -1 on failure.
  1350. */
  1351. int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event)
  1352. {
  1353. struct rsi_block_unblock_data *mgmt_frame;
  1354. struct sk_buff *skb;
  1355. rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__);
  1356. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1357. if (!skb) {
  1358. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1359. __func__);
  1360. return -ENOMEM;
  1361. }
  1362. memset(skb->data, 0, FRAME_DESC_SZ);
  1363. mgmt_frame = (struct rsi_block_unblock_data *)skb->data;
  1364. rsi_set_len_qno(&mgmt_frame->desc_dword0.len_qno, 0, RSI_WIFI_MGMT_Q);
  1365. mgmt_frame->desc_dword0.frame_type = BLOCK_HW_QUEUE;
  1366. mgmt_frame->host_quiet_info = QUIET_INFO_VALID;
  1367. if (block_event) {
  1368. rsi_dbg(INFO_ZONE, "blocking the data qs\n");
  1369. mgmt_frame->block_q_bitmap = cpu_to_le16(0xf);
  1370. mgmt_frame->block_q_bitmap |= cpu_to_le16(0xf << 4);
  1371. } else {
  1372. rsi_dbg(INFO_ZONE, "unblocking the data qs\n");
  1373. mgmt_frame->unblock_q_bitmap = cpu_to_le16(0xf);
  1374. mgmt_frame->unblock_q_bitmap |= cpu_to_le16(0xf << 4);
  1375. }
  1376. skb_put(skb, FRAME_DESC_SZ);
  1377. return rsi_send_internal_mgmt_frame(common, skb);
  1378. }
  1379. /**
  1380. * rsi_send_rx_filter_frame() - Sends a frame to filter the RX packets
  1381. *
  1382. * @common: Pointer to the driver private structure.
  1383. * @rx_filter_word: Flags of filter packets
  1384. *
  1385. * @Return: 0 on success, -1 on failure.
  1386. */
  1387. int rsi_send_rx_filter_frame(struct rsi_common *common, u16 rx_filter_word)
  1388. {
  1389. struct rsi_mac_frame *cmd_frame;
  1390. struct sk_buff *skb;
  1391. rsi_dbg(MGMT_TX_ZONE, "Sending RX filter frame\n");
  1392. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1393. if (!skb) {
  1394. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1395. __func__);
  1396. return -ENOMEM;
  1397. }
  1398. memset(skb->data, 0, FRAME_DESC_SZ);
  1399. cmd_frame = (struct rsi_mac_frame *)skb->data;
  1400. cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1401. cmd_frame->desc_word[1] = cpu_to_le16(SET_RX_FILTER);
  1402. cmd_frame->desc_word[4] = cpu_to_le16(rx_filter_word);
  1403. skb_put(skb, FRAME_DESC_SZ);
  1404. return rsi_send_internal_mgmt_frame(common, skb);
  1405. }
  1406. int rsi_send_ps_request(struct rsi_hw *adapter, bool enable,
  1407. struct ieee80211_vif *vif)
  1408. {
  1409. struct rsi_common *common = adapter->priv;
  1410. struct ieee80211_bss_conf *bss = &vif->bss_conf;
  1411. struct rsi_request_ps *ps;
  1412. struct rsi_ps_info *ps_info;
  1413. struct sk_buff *skb;
  1414. int frame_len = sizeof(*ps);
  1415. skb = dev_alloc_skb(frame_len);
  1416. if (!skb)
  1417. return -ENOMEM;
  1418. memset(skb->data, 0, frame_len);
  1419. ps = (struct rsi_request_ps *)skb->data;
  1420. ps_info = &adapter->ps_info;
  1421. rsi_set_len_qno(&ps->desc.desc_dword0.len_qno,
  1422. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  1423. ps->desc.desc_dword0.frame_type = WAKEUP_SLEEP_REQUEST;
  1424. if (enable) {
  1425. ps->ps_sleep.enable = RSI_PS_ENABLE;
  1426. ps->desc.desc_dword3.token = cpu_to_le16(RSI_SLEEP_REQUEST);
  1427. } else {
  1428. ps->ps_sleep.enable = RSI_PS_DISABLE;
  1429. ps->desc.desc_dword0.len_qno |= cpu_to_le16(RSI_PS_DISABLE_IND);
  1430. ps->desc.desc_dword3.token = cpu_to_le16(RSI_WAKEUP_REQUEST);
  1431. }
  1432. ps->ps_uapsd_acs = common->uapsd_bitmap;
  1433. ps->ps_sleep.sleep_type = ps_info->sleep_type;
  1434. ps->ps_sleep.num_bcns_per_lis_int =
  1435. cpu_to_le16(ps_info->num_bcns_per_lis_int);
  1436. ps->ps_sleep.sleep_duration =
  1437. cpu_to_le32(ps_info->deep_sleep_wakeup_period);
  1438. if (bss->assoc)
  1439. ps->ps_sleep.connected_sleep = RSI_CONNECTED_SLEEP;
  1440. else
  1441. ps->ps_sleep.connected_sleep = RSI_DEEP_SLEEP;
  1442. ps->ps_listen_interval = cpu_to_le32(ps_info->listen_interval);
  1443. ps->ps_dtim_interval_duration =
  1444. cpu_to_le32(ps_info->dtim_interval_duration);
  1445. if (ps_info->listen_interval > ps_info->dtim_interval_duration)
  1446. ps->ps_listen_interval = cpu_to_le32(RSI_PS_DISABLE);
  1447. ps->ps_num_dtim_intervals = cpu_to_le16(ps_info->num_dtims_per_sleep);
  1448. skb_put(skb, frame_len);
  1449. return rsi_send_internal_mgmt_frame(common, skb);
  1450. }
  1451. static int rsi_send_w9116_features(struct rsi_common *common)
  1452. {
  1453. struct rsi_wlan_9116_features *w9116_features;
  1454. u16 frame_len = sizeof(struct rsi_wlan_9116_features);
  1455. struct sk_buff *skb;
  1456. rsi_dbg(MGMT_TX_ZONE,
  1457. "%s: Sending wlan 9116 features\n", __func__);
  1458. skb = dev_alloc_skb(frame_len);
  1459. if (!skb)
  1460. return -ENOMEM;
  1461. memset(skb->data, 0, frame_len);
  1462. w9116_features = (struct rsi_wlan_9116_features *)skb->data;
  1463. w9116_features->pll_mode = common->w9116_features.pll_mode;
  1464. w9116_features->rf_type = common->w9116_features.rf_type;
  1465. w9116_features->wireless_mode = common->w9116_features.wireless_mode;
  1466. w9116_features->enable_ppe = common->w9116_features.enable_ppe;
  1467. w9116_features->afe_type = common->w9116_features.afe_type;
  1468. if (common->w9116_features.dpd)
  1469. w9116_features->feature_enable |= cpu_to_le32(RSI_DPD);
  1470. if (common->w9116_features.sifs_tx_enable)
  1471. w9116_features->feature_enable |=
  1472. cpu_to_le32(RSI_SIFS_TX_ENABLE);
  1473. if (common->w9116_features.ps_options & RSI_DUTY_CYCLING)
  1474. w9116_features->feature_enable |= cpu_to_le32(RSI_DUTY_CYCLING);
  1475. if (common->w9116_features.ps_options & RSI_END_OF_FRAME)
  1476. w9116_features->feature_enable |= cpu_to_le32(RSI_END_OF_FRAME);
  1477. w9116_features->feature_enable |=
  1478. cpu_to_le32((common->w9116_features.ps_options & ~0x3) << 2);
  1479. rsi_set_len_qno(&w9116_features->desc.desc_dword0.len_qno,
  1480. frame_len - FRAME_DESC_SZ, RSI_WIFI_MGMT_Q);
  1481. w9116_features->desc.desc_dword0.frame_type = FEATURES_ENABLE;
  1482. skb_put(skb, frame_len);
  1483. return rsi_send_internal_mgmt_frame(common, skb);
  1484. }
  1485. /**
  1486. * rsi_set_antenna() - This function send antenna configuration request
  1487. * to device
  1488. *
  1489. * @common: Pointer to the driver private structure.
  1490. * @antenna: bitmap for tx antenna selection
  1491. *
  1492. * Return: 0 on Success, negative error code on failure
  1493. */
  1494. int rsi_set_antenna(struct rsi_common *common, u8 antenna)
  1495. {
  1496. struct rsi_ant_sel_frame *ant_sel_frame;
  1497. struct sk_buff *skb;
  1498. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1499. if (!skb) {
  1500. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1501. __func__);
  1502. return -ENOMEM;
  1503. }
  1504. memset(skb->data, 0, FRAME_DESC_SZ);
  1505. ant_sel_frame = (struct rsi_ant_sel_frame *)skb->data;
  1506. ant_sel_frame->desc_dword0.frame_type = ANT_SEL_FRAME;
  1507. ant_sel_frame->sub_frame_type = ANTENNA_SEL_TYPE;
  1508. ant_sel_frame->ant_value = cpu_to_le16(antenna & ANTENNA_MASK_VALUE);
  1509. rsi_set_len_qno(&ant_sel_frame->desc_dword0.len_qno,
  1510. 0, RSI_WIFI_MGMT_Q);
  1511. skb_put(skb, FRAME_DESC_SZ);
  1512. return rsi_send_internal_mgmt_frame(common, skb);
  1513. }
  1514. static int rsi_send_beacon(struct rsi_common *common)
  1515. {
  1516. struct sk_buff *skb = NULL;
  1517. u8 dword_align_bytes = 0;
  1518. skb = dev_alloc_skb(MAX_MGMT_PKT_SIZE);
  1519. if (!skb)
  1520. return -ENOMEM;
  1521. memset(skb->data, 0, MAX_MGMT_PKT_SIZE);
  1522. dword_align_bytes = ((unsigned long)skb->data & 0x3f);
  1523. if (dword_align_bytes)
  1524. skb_pull(skb, (64 - dword_align_bytes));
  1525. if (rsi_prepare_beacon(common, skb)) {
  1526. rsi_dbg(ERR_ZONE, "Failed to prepare beacon\n");
  1527. dev_kfree_skb(skb);
  1528. return -EINVAL;
  1529. }
  1530. skb_queue_tail(&common->tx_queue[MGMT_BEACON_Q], skb);
  1531. rsi_set_event(&common->tx_thread.event);
  1532. rsi_dbg(DATA_TX_ZONE, "%s: Added to beacon queue\n", __func__);
  1533. return 0;
  1534. }
  1535. #ifdef CONFIG_PM
  1536. int rsi_send_wowlan_request(struct rsi_common *common, u16 flags,
  1537. u16 sleep_status)
  1538. {
  1539. struct rsi_wowlan_req *cmd_frame;
  1540. struct sk_buff *skb;
  1541. u8 length;
  1542. rsi_dbg(ERR_ZONE, "%s: Sending wowlan request frame\n", __func__);
  1543. length = sizeof(*cmd_frame);
  1544. skb = dev_alloc_skb(length);
  1545. if (!skb)
  1546. return -ENOMEM;
  1547. memset(skb->data, 0, length);
  1548. cmd_frame = (struct rsi_wowlan_req *)skb->data;
  1549. rsi_set_len_qno(&cmd_frame->desc.desc_dword0.len_qno,
  1550. (length - FRAME_DESC_SZ),
  1551. RSI_WIFI_MGMT_Q);
  1552. cmd_frame->desc.desc_dword0.frame_type = WOWLAN_CONFIG_PARAMS;
  1553. cmd_frame->host_sleep_status = sleep_status;
  1554. if (common->secinfo.gtk_cipher)
  1555. flags |= RSI_WOW_GTK_REKEY;
  1556. if (sleep_status)
  1557. cmd_frame->wow_flags = flags;
  1558. rsi_dbg(INFO_ZONE, "Host_Sleep_Status : %d Flags : %d\n",
  1559. cmd_frame->host_sleep_status, cmd_frame->wow_flags);
  1560. skb_put(skb, length);
  1561. return rsi_send_internal_mgmt_frame(common, skb);
  1562. }
  1563. #endif
  1564. int rsi_send_bgscan_params(struct rsi_common *common, int enable)
  1565. {
  1566. struct rsi_bgscan_params *params = &common->bgscan;
  1567. struct cfg80211_scan_request *scan_req = common->hwscan;
  1568. struct rsi_bgscan_config *bgscan;
  1569. struct sk_buff *skb;
  1570. u16 frame_len = sizeof(*bgscan);
  1571. u8 i;
  1572. rsi_dbg(MGMT_TX_ZONE, "%s: Sending bgscan params frame\n", __func__);
  1573. skb = dev_alloc_skb(frame_len);
  1574. if (!skb)
  1575. return -ENOMEM;
  1576. memset(skb->data, 0, frame_len);
  1577. bgscan = (struct rsi_bgscan_config *)skb->data;
  1578. rsi_set_len_qno(&bgscan->desc_dword0.len_qno,
  1579. (frame_len - FRAME_DESC_SZ), RSI_WIFI_MGMT_Q);
  1580. bgscan->desc_dword0.frame_type = BG_SCAN_PARAMS;
  1581. bgscan->bgscan_threshold = cpu_to_le16(params->bgscan_threshold);
  1582. bgscan->roam_threshold = cpu_to_le16(params->roam_threshold);
  1583. if (enable)
  1584. bgscan->bgscan_periodicity =
  1585. cpu_to_le16(params->bgscan_periodicity);
  1586. bgscan->active_scan_duration =
  1587. cpu_to_le16(params->active_scan_duration);
  1588. bgscan->passive_scan_duration =
  1589. cpu_to_le16(params->passive_scan_duration);
  1590. bgscan->two_probe = params->two_probe;
  1591. bgscan->num_bgscan_channels = scan_req->n_channels;
  1592. for (i = 0; i < bgscan->num_bgscan_channels; i++)
  1593. bgscan->channels2scan[i] =
  1594. cpu_to_le16(scan_req->channels[i]->hw_value);
  1595. skb_put(skb, frame_len);
  1596. return rsi_send_internal_mgmt_frame(common, skb);
  1597. }
  1598. /* This function sends the probe request to be used by firmware in
  1599. * background scan
  1600. */
  1601. int rsi_send_bgscan_probe_req(struct rsi_common *common,
  1602. struct ieee80211_vif *vif)
  1603. {
  1604. struct cfg80211_scan_request *scan_req = common->hwscan;
  1605. struct rsi_bgscan_probe *bgscan;
  1606. struct sk_buff *skb;
  1607. struct sk_buff *probereq_skb;
  1608. u16 frame_len = sizeof(*bgscan);
  1609. size_t ssid_len = 0;
  1610. u8 *ssid = NULL;
  1611. rsi_dbg(MGMT_TX_ZONE,
  1612. "%s: Sending bgscan probe req frame\n", __func__);
  1613. if (common->priv->sc_nvifs <= 0)
  1614. return -ENODEV;
  1615. if (scan_req->n_ssids) {
  1616. ssid = scan_req->ssids[0].ssid;
  1617. ssid_len = scan_req->ssids[0].ssid_len;
  1618. }
  1619. skb = dev_alloc_skb(frame_len + MAX_BGSCAN_PROBE_REQ_LEN);
  1620. if (!skb)
  1621. return -ENOMEM;
  1622. memset(skb->data, 0, frame_len + MAX_BGSCAN_PROBE_REQ_LEN);
  1623. bgscan = (struct rsi_bgscan_probe *)skb->data;
  1624. bgscan->desc_dword0.frame_type = BG_SCAN_PROBE_REQ;
  1625. bgscan->flags = cpu_to_le16(HOST_BG_SCAN_TRIG);
  1626. if (common->band == NL80211_BAND_5GHZ) {
  1627. bgscan->mgmt_rate = cpu_to_le16(RSI_RATE_6);
  1628. bgscan->def_chan = cpu_to_le16(40);
  1629. } else {
  1630. bgscan->mgmt_rate = cpu_to_le16(RSI_RATE_1);
  1631. bgscan->def_chan = cpu_to_le16(11);
  1632. }
  1633. bgscan->channel_scan_time = cpu_to_le16(RSI_CHANNEL_SCAN_TIME);
  1634. probereq_skb = ieee80211_probereq_get(common->priv->hw, vif->addr, ssid,
  1635. ssid_len, scan_req->ie_len);
  1636. if (!probereq_skb) {
  1637. dev_kfree_skb(skb);
  1638. return -ENOMEM;
  1639. }
  1640. memcpy(&skb->data[frame_len], probereq_skb->data, probereq_skb->len);
  1641. bgscan->probe_req_length = cpu_to_le16(probereq_skb->len);
  1642. rsi_set_len_qno(&bgscan->desc_dword0.len_qno,
  1643. (frame_len - FRAME_DESC_SZ + probereq_skb->len),
  1644. RSI_WIFI_MGMT_Q);
  1645. skb_put(skb, frame_len + probereq_skb->len);
  1646. dev_kfree_skb(probereq_skb);
  1647. return rsi_send_internal_mgmt_frame(common, skb);
  1648. }
  1649. /**
  1650. * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
  1651. * @common: Pointer to the driver private structure.
  1652. * @msg: Pointer to received packet.
  1653. *
  1654. * Return: 0 on success, -1 on failure.
  1655. */
  1656. static int rsi_handle_ta_confirm_type(struct rsi_common *common,
  1657. u8 *msg)
  1658. {
  1659. struct rsi_hw *adapter = common->priv;
  1660. u8 sub_type = (msg[15] & 0xff);
  1661. u16 msg_len = ((u16 *)msg)[0] & 0xfff;
  1662. u8 offset;
  1663. switch (sub_type) {
  1664. case BOOTUP_PARAMS_REQUEST:
  1665. rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
  1666. __func__);
  1667. if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
  1668. if (adapter->device_model == RSI_DEV_9116) {
  1669. common->band = NL80211_BAND_5GHZ;
  1670. common->num_supp_bands = 2;
  1671. if (rsi_send_reset_mac(common))
  1672. goto out;
  1673. else
  1674. common->fsm_state = FSM_RESET_MAC_SENT;
  1675. } else {
  1676. adapter->eeprom.length =
  1677. (IEEE80211_ADDR_LEN +
  1678. WLAN_MAC_MAGIC_WORD_LEN +
  1679. WLAN_HOST_MODE_LEN);
  1680. adapter->eeprom.offset = WLAN_MAC_EEPROM_ADDR;
  1681. if (rsi_eeprom_read(common)) {
  1682. common->fsm_state = FSM_CARD_NOT_READY;
  1683. goto out;
  1684. }
  1685. common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
  1686. }
  1687. } else {
  1688. rsi_dbg(INFO_ZONE,
  1689. "%s: Received bootup params cfm in %d state\n",
  1690. __func__, common->fsm_state);
  1691. return 0;
  1692. }
  1693. break;
  1694. case EEPROM_READ:
  1695. rsi_dbg(FSM_ZONE, "EEPROM READ confirm received\n");
  1696. if (msg_len <= 0) {
  1697. rsi_dbg(FSM_ZONE,
  1698. "%s: [EEPROM_READ] Invalid len %d\n",
  1699. __func__, msg_len);
  1700. goto out;
  1701. }
  1702. if (msg[16] != MAGIC_WORD) {
  1703. rsi_dbg(FSM_ZONE,
  1704. "%s: [EEPROM_READ] Invalid token\n", __func__);
  1705. common->fsm_state = FSM_CARD_NOT_READY;
  1706. goto out;
  1707. }
  1708. if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
  1709. offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN +
  1710. WLAN_MAC_MAGIC_WORD_LEN);
  1711. memcpy(common->mac_addr, &msg[offset], ETH_ALEN);
  1712. adapter->eeprom.length =
  1713. ((WLAN_MAC_MAGIC_WORD_LEN + 3) & (~3));
  1714. adapter->eeprom.offset = WLAN_EEPROM_RFTYPE_ADDR;
  1715. if (rsi_eeprom_read(common)) {
  1716. rsi_dbg(ERR_ZONE,
  1717. "%s: Failed reading RF band\n",
  1718. __func__);
  1719. common->fsm_state = FSM_CARD_NOT_READY;
  1720. goto out;
  1721. }
  1722. common->fsm_state = FSM_EEPROM_READ_RF_TYPE;
  1723. } else if (common->fsm_state == FSM_EEPROM_READ_RF_TYPE) {
  1724. if ((msg[17] & 0x3) == 0x3) {
  1725. rsi_dbg(INIT_ZONE, "Dual band supported\n");
  1726. common->band = NL80211_BAND_5GHZ;
  1727. common->num_supp_bands = 2;
  1728. } else if ((msg[17] & 0x3) == 0x1) {
  1729. rsi_dbg(INIT_ZONE,
  1730. "Only 2.4Ghz band supported\n");
  1731. common->band = NL80211_BAND_2GHZ;
  1732. common->num_supp_bands = 1;
  1733. }
  1734. if (rsi_send_reset_mac(common))
  1735. goto out;
  1736. common->fsm_state = FSM_RESET_MAC_SENT;
  1737. } else {
  1738. rsi_dbg(ERR_ZONE, "%s: Invalid EEPROM read type\n",
  1739. __func__);
  1740. return 0;
  1741. }
  1742. break;
  1743. case RESET_MAC_REQ:
  1744. if (common->fsm_state == FSM_RESET_MAC_SENT) {
  1745. rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
  1746. __func__);
  1747. if (rsi_load_radio_caps(common))
  1748. goto out;
  1749. else
  1750. common->fsm_state = FSM_RADIO_CAPS_SENT;
  1751. } else {
  1752. rsi_dbg(ERR_ZONE,
  1753. "%s: Received reset mac cfm in %d state\n",
  1754. __func__, common->fsm_state);
  1755. return 0;
  1756. }
  1757. break;
  1758. case RADIO_CAPABILITIES:
  1759. if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
  1760. common->rf_reset = 1;
  1761. if (adapter->device_model == RSI_DEV_9116 &&
  1762. rsi_send_w9116_features(common)) {
  1763. rsi_dbg(ERR_ZONE,
  1764. "Failed to send 9116 features\n");
  1765. goto out;
  1766. }
  1767. if (rsi_program_bb_rf(common)) {
  1768. goto out;
  1769. } else {
  1770. common->fsm_state = FSM_BB_RF_PROG_SENT;
  1771. rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
  1772. __func__);
  1773. }
  1774. } else {
  1775. rsi_dbg(INFO_ZONE,
  1776. "%s: Received radio caps cfm in %d state\n",
  1777. __func__, common->fsm_state);
  1778. return 0;
  1779. }
  1780. break;
  1781. case BB_PROG_VALUES_REQUEST:
  1782. case RF_PROG_VALUES_REQUEST:
  1783. case BBP_PROG_IN_TA:
  1784. rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
  1785. if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
  1786. common->bb_rf_prog_count--;
  1787. if (!common->bb_rf_prog_count) {
  1788. common->fsm_state = FSM_MAC_INIT_DONE;
  1789. if (common->reinit_hw) {
  1790. complete(&common->wlan_init_completion);
  1791. } else {
  1792. return rsi_mac80211_attach(common);
  1793. }
  1794. }
  1795. } else {
  1796. rsi_dbg(INFO_ZONE,
  1797. "%s: Received bbb_rf cfm in %d state\n",
  1798. __func__, common->fsm_state);
  1799. return 0;
  1800. }
  1801. break;
  1802. case SCAN_REQUEST:
  1803. rsi_dbg(INFO_ZONE, "Set channel confirm\n");
  1804. break;
  1805. case WAKEUP_SLEEP_REQUEST:
  1806. rsi_dbg(INFO_ZONE, "Wakeup/Sleep confirmation.\n");
  1807. return rsi_handle_ps_confirm(adapter, msg);
  1808. case BG_SCAN_PROBE_REQ:
  1809. rsi_dbg(INFO_ZONE, "BG scan complete event\n");
  1810. if (common->bgscan_en) {
  1811. struct cfg80211_scan_info info;
  1812. if (!rsi_send_bgscan_params(common, RSI_STOP_BGSCAN))
  1813. common->bgscan_en = 0;
  1814. info.aborted = false;
  1815. ieee80211_scan_completed(adapter->hw, &info);
  1816. }
  1817. rsi_dbg(INFO_ZONE, "Background scan completed\n");
  1818. break;
  1819. default:
  1820. rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
  1821. __func__);
  1822. break;
  1823. }
  1824. return 0;
  1825. out:
  1826. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
  1827. __func__);
  1828. return -EINVAL;
  1829. }
  1830. int rsi_handle_card_ready(struct rsi_common *common, u8 *msg)
  1831. {
  1832. int status;
  1833. switch (common->fsm_state) {
  1834. case FSM_CARD_NOT_READY:
  1835. rsi_dbg(INIT_ZONE, "Card ready indication from Common HAL\n");
  1836. rsi_set_default_parameters(common);
  1837. if (rsi_send_common_dev_params(common) < 0)
  1838. return -EINVAL;
  1839. common->fsm_state = FSM_COMMON_DEV_PARAMS_SENT;
  1840. break;
  1841. case FSM_COMMON_DEV_PARAMS_SENT:
  1842. rsi_dbg(INIT_ZONE, "Card ready indication from WLAN HAL\n");
  1843. if (common->priv->device_model == RSI_DEV_9116) {
  1844. if (msg[16] != MAGIC_WORD) {
  1845. rsi_dbg(FSM_ZONE,
  1846. "%s: [EEPROM_READ] Invalid token\n",
  1847. __func__);
  1848. common->fsm_state = FSM_CARD_NOT_READY;
  1849. return -EINVAL;
  1850. }
  1851. memcpy(common->mac_addr, &msg[20], ETH_ALEN);
  1852. rsi_dbg(INIT_ZONE, "MAC Addr %pM", common->mac_addr);
  1853. }
  1854. /* Get usb buffer status register address */
  1855. common->priv->usb_buffer_status_reg = *(u32 *)&msg[8];
  1856. rsi_dbg(INFO_ZONE, "USB buffer status register = %x\n",
  1857. common->priv->usb_buffer_status_reg);
  1858. if (common->priv->device_model == RSI_DEV_9116)
  1859. status = rsi_load_9116_bootup_params(common);
  1860. else
  1861. status = rsi_load_bootup_params(common);
  1862. if (status < 0) {
  1863. common->fsm_state = FSM_CARD_NOT_READY;
  1864. return status;
  1865. }
  1866. common->fsm_state = FSM_BOOT_PARAMS_SENT;
  1867. break;
  1868. default:
  1869. rsi_dbg(ERR_ZONE,
  1870. "%s: card ready indication in invalid state %d.\n",
  1871. __func__, common->fsm_state);
  1872. return -EINVAL;
  1873. }
  1874. return 0;
  1875. }
  1876. /**
  1877. * rsi_mgmt_pkt_recv() - This function processes the management packets
  1878. * received from the hardware.
  1879. * @common: Pointer to the driver private structure.
  1880. * @msg: Pointer to the received packet.
  1881. *
  1882. * Return: 0 on success, -1 on failure.
  1883. */
  1884. int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
  1885. {
  1886. s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
  1887. u16 msg_type = (msg[2]);
  1888. rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
  1889. __func__, msg_len, msg_type);
  1890. switch (msg_type) {
  1891. case TA_CONFIRM_TYPE:
  1892. return rsi_handle_ta_confirm_type(common, msg);
  1893. case CARD_READY_IND:
  1894. common->hibernate_resume = false;
  1895. rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
  1896. __func__);
  1897. return rsi_handle_card_ready(common, msg);
  1898. case TX_STATUS_IND:
  1899. switch (msg[RSI_TX_STATUS_TYPE]) {
  1900. case PROBEREQ_CONFIRM:
  1901. common->mgmt_q_block = false;
  1902. rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
  1903. __func__);
  1904. break;
  1905. case EAPOL4_CONFIRM:
  1906. if (msg[RSI_TX_STATUS]) {
  1907. common->eapol4_confirm = true;
  1908. if (!rsi_send_block_unblock_frame(common,
  1909. false))
  1910. common->hw_data_qs_blocked = false;
  1911. }
  1912. }
  1913. break;
  1914. case BEACON_EVENT_IND:
  1915. rsi_dbg(INFO_ZONE, "Beacon event\n");
  1916. if (common->fsm_state != FSM_MAC_INIT_DONE)
  1917. return -1;
  1918. if (common->iface_down)
  1919. return -1;
  1920. if (!common->beacon_enabled)
  1921. return -1;
  1922. rsi_send_beacon(common);
  1923. break;
  1924. case WOWLAN_WAKEUP_REASON:
  1925. rsi_dbg(ERR_ZONE, "\n\nWakeup Type: %x\n", msg[15]);
  1926. switch (msg[15]) {
  1927. case RSI_UNICAST_MAGIC_PKT:
  1928. rsi_dbg(ERR_ZONE,
  1929. "*** Wakeup for Unicast magic packet ***\n");
  1930. break;
  1931. case RSI_BROADCAST_MAGICPKT:
  1932. rsi_dbg(ERR_ZONE,
  1933. "*** Wakeup for Broadcast magic packet ***\n");
  1934. break;
  1935. case RSI_EAPOL_PKT:
  1936. rsi_dbg(ERR_ZONE,
  1937. "*** Wakeup for GTK renewal ***\n");
  1938. break;
  1939. case RSI_DISCONNECT_PKT:
  1940. rsi_dbg(ERR_ZONE,
  1941. "*** Wakeup for Disconnect ***\n");
  1942. break;
  1943. case RSI_HW_BMISS_PKT:
  1944. rsi_dbg(ERR_ZONE,
  1945. "*** Wakeup for HW Beacon miss ***\n");
  1946. break;
  1947. default:
  1948. rsi_dbg(ERR_ZONE,
  1949. "##### Un-intentional Wakeup #####\n");
  1950. break;
  1951. }
  1952. break;
  1953. case RX_DOT11_MGMT:
  1954. return rsi_mgmt_pkt_to_core(common, msg, msg_len);
  1955. default:
  1956. rsi_dbg(INFO_ZONE, "Received packet type: 0x%x\n", msg_type);
  1957. }
  1958. return 0;
  1959. }