rsi_91x_mgmt.c 52 KB

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