rsi_91x_mgmt.c 52 KB

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