rsi_91x_mgmt.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  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. static struct bootup_params boot_params_20 = {
  20. .magic_number = cpu_to_le16(0x5aa5),
  21. .crystal_good_time = 0x0,
  22. .valid = cpu_to_le32(VALID_20),
  23. .reserved_for_valids = 0x0,
  24. .bootup_mode_info = 0x0,
  25. .digital_loop_back_params = 0x0,
  26. .rtls_timestamp_en = 0x0,
  27. .host_spi_intr_cfg = 0x0,
  28. .device_clk_info = {{
  29. .pll_config_g = {
  30. .tapll_info_g = {
  31. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  32. (TA_PLL_M_VAL_20)),
  33. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  34. },
  35. .pll960_info_g = {
  36. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  37. (PLL960_N_VAL_20)),
  38. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  39. .pll_reg_3 = 0x0,
  40. },
  41. .afepll_info_g = {
  42. .pll_reg = cpu_to_le16(0x9f0),
  43. }
  44. },
  45. .switch_clk_g = {
  46. .switch_clk_info = cpu_to_le16(BIT(3)),
  47. .bbp_lmac_clk_reg_val = cpu_to_le16(0x121),
  48. .umac_clock_reg_config = 0x0,
  49. .qspi_uart_clock_reg_config = 0x0
  50. }
  51. },
  52. {
  53. .pll_config_g = {
  54. .tapll_info_g = {
  55. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  56. (TA_PLL_M_VAL_20)),
  57. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  58. },
  59. .pll960_info_g = {
  60. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  61. (PLL960_N_VAL_20)),
  62. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  63. .pll_reg_3 = 0x0,
  64. },
  65. .afepll_info_g = {
  66. .pll_reg = cpu_to_le16(0x9f0),
  67. }
  68. },
  69. .switch_clk_g = {
  70. .switch_clk_info = 0x0,
  71. .bbp_lmac_clk_reg_val = 0x0,
  72. .umac_clock_reg_config = 0x0,
  73. .qspi_uart_clock_reg_config = 0x0
  74. }
  75. },
  76. {
  77. .pll_config_g = {
  78. .tapll_info_g = {
  79. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_20 << 8)|
  80. (TA_PLL_M_VAL_20)),
  81. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_20),
  82. },
  83. .pll960_info_g = {
  84. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_20 << 8)|
  85. (PLL960_N_VAL_20)),
  86. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_20),
  87. .pll_reg_3 = 0x0,
  88. },
  89. .afepll_info_g = {
  90. .pll_reg = cpu_to_le16(0x9f0),
  91. }
  92. },
  93. .switch_clk_g = {
  94. .switch_clk_info = 0x0,
  95. .bbp_lmac_clk_reg_val = 0x0,
  96. .umac_clock_reg_config = 0x0,
  97. .qspi_uart_clock_reg_config = 0x0
  98. }
  99. } },
  100. .buckboost_wakeup_cnt = 0x0,
  101. .pmu_wakeup_wait = 0x0,
  102. .shutdown_wait_time = 0x0,
  103. .pmu_slp_clkout_sel = 0x0,
  104. .wdt_prog_value = 0x0,
  105. .wdt_soc_rst_delay = 0x0,
  106. .dcdc_operation_mode = 0x0,
  107. .soc_reset_wait_cnt = 0x0
  108. };
  109. static struct bootup_params boot_params_40 = {
  110. .magic_number = cpu_to_le16(0x5aa5),
  111. .crystal_good_time = 0x0,
  112. .valid = cpu_to_le32(VALID_40),
  113. .reserved_for_valids = 0x0,
  114. .bootup_mode_info = 0x0,
  115. .digital_loop_back_params = 0x0,
  116. .rtls_timestamp_en = 0x0,
  117. .host_spi_intr_cfg = 0x0,
  118. .device_clk_info = {{
  119. .pll_config_g = {
  120. .tapll_info_g = {
  121. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  122. (TA_PLL_M_VAL_40)),
  123. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  124. },
  125. .pll960_info_g = {
  126. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  127. (PLL960_N_VAL_40)),
  128. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  129. .pll_reg_3 = 0x0,
  130. },
  131. .afepll_info_g = {
  132. .pll_reg = cpu_to_le16(0x9f0),
  133. }
  134. },
  135. .switch_clk_g = {
  136. .switch_clk_info = cpu_to_le16(0x09),
  137. .bbp_lmac_clk_reg_val = cpu_to_le16(0x1121),
  138. .umac_clock_reg_config = cpu_to_le16(0x48),
  139. .qspi_uart_clock_reg_config = 0x0
  140. }
  141. },
  142. {
  143. .pll_config_g = {
  144. .tapll_info_g = {
  145. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  146. (TA_PLL_M_VAL_40)),
  147. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  148. },
  149. .pll960_info_g = {
  150. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  151. (PLL960_N_VAL_40)),
  152. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  153. .pll_reg_3 = 0x0,
  154. },
  155. .afepll_info_g = {
  156. .pll_reg = cpu_to_le16(0x9f0),
  157. }
  158. },
  159. .switch_clk_g = {
  160. .switch_clk_info = 0x0,
  161. .bbp_lmac_clk_reg_val = 0x0,
  162. .umac_clock_reg_config = 0x0,
  163. .qspi_uart_clock_reg_config = 0x0
  164. }
  165. },
  166. {
  167. .pll_config_g = {
  168. .tapll_info_g = {
  169. .pll_reg_1 = cpu_to_le16((TA_PLL_N_VAL_40 << 8)|
  170. (TA_PLL_M_VAL_40)),
  171. .pll_reg_2 = cpu_to_le16(TA_PLL_P_VAL_40),
  172. },
  173. .pll960_info_g = {
  174. .pll_reg_1 = cpu_to_le16((PLL960_P_VAL_40 << 8)|
  175. (PLL960_N_VAL_40)),
  176. .pll_reg_2 = cpu_to_le16(PLL960_M_VAL_40),
  177. .pll_reg_3 = 0x0,
  178. },
  179. .afepll_info_g = {
  180. .pll_reg = cpu_to_le16(0x9f0),
  181. }
  182. },
  183. .switch_clk_g = {
  184. .switch_clk_info = 0x0,
  185. .bbp_lmac_clk_reg_val = 0x0,
  186. .umac_clock_reg_config = 0x0,
  187. .qspi_uart_clock_reg_config = 0x0
  188. }
  189. } },
  190. .buckboost_wakeup_cnt = 0x0,
  191. .pmu_wakeup_wait = 0x0,
  192. .shutdown_wait_time = 0x0,
  193. .pmu_slp_clkout_sel = 0x0,
  194. .wdt_prog_value = 0x0,
  195. .wdt_soc_rst_delay = 0x0,
  196. .dcdc_operation_mode = 0x0,
  197. .soc_reset_wait_cnt = 0x0
  198. };
  199. static u16 mcs[] = {13, 26, 39, 52, 78, 104, 117, 130};
  200. /**
  201. * rsi_set_default_parameters() - This function sets default parameters.
  202. * @common: Pointer to the driver private structure.
  203. *
  204. * Return: none
  205. */
  206. static void rsi_set_default_parameters(struct rsi_common *common)
  207. {
  208. common->band = NL80211_BAND_2GHZ;
  209. common->channel_width = BW_20MHZ;
  210. common->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  211. common->channel = 1;
  212. common->min_rate = 0xffff;
  213. common->fsm_state = FSM_CARD_NOT_READY;
  214. common->iface_down = true;
  215. common->endpoint = EP_2GHZ_20MHZ;
  216. }
  217. /**
  218. * rsi_set_contention_vals() - This function sets the contention values for the
  219. * backoff procedure.
  220. * @common: Pointer to the driver private structure.
  221. *
  222. * Return: None.
  223. */
  224. static void rsi_set_contention_vals(struct rsi_common *common)
  225. {
  226. u8 ii = 0;
  227. for (; ii < NUM_EDCA_QUEUES; ii++) {
  228. common->tx_qinfo[ii].wme_params =
  229. (((common->edca_params[ii].cw_min / 2) +
  230. (common->edca_params[ii].aifs)) *
  231. WMM_SHORT_SLOT_TIME + SIFS_DURATION);
  232. common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
  233. common->tx_qinfo[ii].pkt_contended = 0;
  234. }
  235. }
  236. /**
  237. * rsi_send_internal_mgmt_frame() - This function sends management frames to
  238. * firmware.Also schedules packet to queue
  239. * for transmission.
  240. * @common: Pointer to the driver private structure.
  241. * @skb: Pointer to the socket buffer structure.
  242. *
  243. * Return: 0 on success, -1 on failure.
  244. */
  245. static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
  246. struct sk_buff *skb)
  247. {
  248. struct skb_info *tx_params;
  249. if (skb == NULL) {
  250. rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
  251. return -ENOMEM;
  252. }
  253. tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
  254. tx_params->flags |= INTERNAL_MGMT_PKT;
  255. skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
  256. rsi_set_event(&common->tx_thread.event);
  257. return 0;
  258. }
  259. /**
  260. * rsi_load_radio_caps() - This function is used to send radio capabilities
  261. * values to firmware.
  262. * @common: Pointer to the driver private structure.
  263. *
  264. * Return: 0 on success, corresponding negative error code on failure.
  265. */
  266. static int rsi_load_radio_caps(struct rsi_common *common)
  267. {
  268. struct rsi_radio_caps *radio_caps;
  269. struct rsi_hw *adapter = common->priv;
  270. u16 inx = 0;
  271. u8 ii;
  272. u8 radio_id = 0;
  273. u16 gc[20] = {0xf0, 0xf0, 0xf0, 0xf0,
  274. 0xf0, 0xf0, 0xf0, 0xf0,
  275. 0xf0, 0xf0, 0xf0, 0xf0,
  276. 0xf0, 0xf0, 0xf0, 0xf0,
  277. 0xf0, 0xf0, 0xf0, 0xf0};
  278. struct sk_buff *skb;
  279. rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
  280. skb = dev_alloc_skb(sizeof(struct rsi_radio_caps));
  281. if (!skb) {
  282. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  283. __func__);
  284. return -ENOMEM;
  285. }
  286. memset(skb->data, 0, sizeof(struct rsi_radio_caps));
  287. radio_caps = (struct rsi_radio_caps *)skb->data;
  288. radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES);
  289. radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8);
  290. if (common->channel_width == BW_40MHZ) {
  291. radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ);
  292. radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ);
  293. if (common->fsm_state == FSM_MAC_INIT_DONE) {
  294. struct ieee80211_hw *hw = adapter->hw;
  295. struct ieee80211_conf *conf = &hw->conf;
  296. if (conf_is_ht40_plus(conf)) {
  297. radio_caps->desc_word[5] =
  298. cpu_to_le16(LOWER_20_ENABLE);
  299. radio_caps->desc_word[5] |=
  300. cpu_to_le16(LOWER_20_ENABLE >> 12);
  301. } else if (conf_is_ht40_minus(conf)) {
  302. radio_caps->desc_word[5] =
  303. cpu_to_le16(UPPER_20_ENABLE);
  304. radio_caps->desc_word[5] |=
  305. cpu_to_le16(UPPER_20_ENABLE >> 12);
  306. } else {
  307. radio_caps->desc_word[5] =
  308. cpu_to_le16(BW_40MHZ << 12);
  309. radio_caps->desc_word[5] |=
  310. cpu_to_le16(FULL40M_ENABLE);
  311. }
  312. }
  313. }
  314. radio_caps->sifs_tx_11n = cpu_to_le16(SIFS_TX_11N_VALUE);
  315. radio_caps->sifs_tx_11b = cpu_to_le16(SIFS_TX_11B_VALUE);
  316. radio_caps->slot_rx_11n = cpu_to_le16(SHORT_SLOT_VALUE);
  317. radio_caps->ofdm_ack_tout = cpu_to_le16(OFDM_ACK_TOUT_VALUE);
  318. radio_caps->cck_ack_tout = cpu_to_le16(CCK_ACK_TOUT_VALUE);
  319. radio_caps->preamble_type = cpu_to_le16(LONG_PREAMBLE);
  320. radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8);
  321. for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
  322. radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
  323. radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
  324. radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
  325. radio_caps->qos_params[ii].txop_q = 0;
  326. }
  327. for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) {
  328. radio_caps->qos_params[ii].cont_win_min_q =
  329. cpu_to_le16(common->edca_params[ii].cw_min);
  330. radio_caps->qos_params[ii].cont_win_max_q =
  331. cpu_to_le16(common->edca_params[ii].cw_max);
  332. radio_caps->qos_params[ii].aifsn_val_q =
  333. cpu_to_le16((common->edca_params[ii].aifs) << 8);
  334. radio_caps->qos_params[ii].txop_q =
  335. cpu_to_le16(common->edca_params[ii].txop);
  336. }
  337. memcpy(&common->rate_pwr[0], &gc[0], 40);
  338. for (ii = 0; ii < 20; ii++)
  339. radio_caps->gcpd_per_rate[inx++] =
  340. cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
  341. radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) -
  342. FRAME_DESC_SZ) |
  343. (RSI_WIFI_MGMT_Q << 12));
  344. skb_put(skb, (sizeof(struct rsi_radio_caps)));
  345. return rsi_send_internal_mgmt_frame(common, skb);
  346. }
  347. /**
  348. * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
  349. * @common: Pointer to the driver private structure.
  350. * @msg: Pointer to received packet.
  351. * @msg_len: Length of the recieved packet.
  352. * @type: Type of recieved packet.
  353. *
  354. * Return: 0 on success, -1 on failure.
  355. */
  356. static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
  357. u8 *msg,
  358. s32 msg_len,
  359. u8 type)
  360. {
  361. struct rsi_hw *adapter = common->priv;
  362. struct ieee80211_tx_info *info;
  363. struct skb_info *rx_params;
  364. u8 pad_bytes = msg[4];
  365. u8 pkt_recv;
  366. struct sk_buff *skb;
  367. char *buffer;
  368. if (type == RX_DOT11_MGMT) {
  369. if (!adapter->sc_nvifs)
  370. return -ENOLINK;
  371. msg_len -= pad_bytes;
  372. if (msg_len <= 0) {
  373. rsi_dbg(MGMT_RX_ZONE,
  374. "%s: Invalid rx msg of len = %d\n",
  375. __func__, msg_len);
  376. return -EINVAL;
  377. }
  378. skb = dev_alloc_skb(msg_len);
  379. if (!skb) {
  380. rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n",
  381. __func__);
  382. return -ENOMEM;
  383. }
  384. buffer = skb_put(skb, msg_len);
  385. memcpy(buffer,
  386. (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
  387. msg_len);
  388. pkt_recv = buffer[0];
  389. info = IEEE80211_SKB_CB(skb);
  390. rx_params = (struct skb_info *)info->driver_data;
  391. rx_params->rssi = rsi_get_rssi(msg);
  392. rx_params->channel = rsi_get_channel(msg);
  393. rsi_indicate_pkt_to_os(common, skb);
  394. } else {
  395. rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__);
  396. }
  397. return 0;
  398. }
  399. /**
  400. * rsi_hal_send_sta_notify_frame() - This function sends the station notify
  401. * frame to firmware.
  402. * @common: Pointer to the driver private structure.
  403. * @opmode: Operating mode of device.
  404. * @notify_event: Notification about station connection.
  405. * @bssid: bssid.
  406. * @qos_enable: Qos is enabled.
  407. * @aid: Aid (unique for all STA).
  408. *
  409. * Return: status: 0 on success, corresponding negative error code on failure.
  410. */
  411. static int rsi_hal_send_sta_notify_frame(struct rsi_common *common,
  412. u8 opmode,
  413. u8 notify_event,
  414. const unsigned char *bssid,
  415. u8 qos_enable,
  416. u16 aid)
  417. {
  418. struct sk_buff *skb = NULL;
  419. struct rsi_peer_notify *peer_notify;
  420. u16 vap_id = 0;
  421. int status;
  422. rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
  423. skb = dev_alloc_skb(sizeof(struct rsi_peer_notify));
  424. if (!skb) {
  425. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  426. __func__);
  427. return -ENOMEM;
  428. }
  429. memset(skb->data, 0, sizeof(struct rsi_peer_notify));
  430. peer_notify = (struct rsi_peer_notify *)skb->data;
  431. peer_notify->command = cpu_to_le16(opmode << 1);
  432. switch (notify_event) {
  433. case STA_CONNECTED:
  434. peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
  435. break;
  436. case STA_DISCONNECTED:
  437. peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
  438. break;
  439. default:
  440. break;
  441. }
  442. peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
  443. ether_addr_copy(peer_notify->mac_addr, bssid);
  444. peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
  445. peer_notify->desc_word[0] =
  446. cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) |
  447. (RSI_WIFI_MGMT_Q << 12));
  448. peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY);
  449. peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8);
  450. skb_put(skb, sizeof(struct rsi_peer_notify));
  451. status = rsi_send_internal_mgmt_frame(common, skb);
  452. if (!status && qos_enable) {
  453. rsi_set_contention_vals(common);
  454. status = rsi_load_radio_caps(common);
  455. }
  456. return status;
  457. }
  458. /**
  459. * rsi_send_aggregation_params_frame() - This function sends the ampdu
  460. * indication frame to firmware.
  461. * @common: Pointer to the driver private structure.
  462. * @tid: traffic identifier.
  463. * @ssn: ssn.
  464. * @buf_size: buffer size.
  465. * @event: notification about station connection.
  466. *
  467. * Return: 0 on success, corresponding negative error code on failure.
  468. */
  469. int rsi_send_aggregation_params_frame(struct rsi_common *common,
  470. u16 tid,
  471. u16 ssn,
  472. u8 buf_size,
  473. u8 event)
  474. {
  475. struct sk_buff *skb = NULL;
  476. struct rsi_mac_frame *mgmt_frame;
  477. u8 peer_id = 0;
  478. skb = dev_alloc_skb(FRAME_DESC_SZ);
  479. if (!skb) {
  480. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  481. __func__);
  482. return -ENOMEM;
  483. }
  484. memset(skb->data, 0, FRAME_DESC_SZ);
  485. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  486. rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
  487. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  488. mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND);
  489. if (event == STA_TX_ADDBA_DONE) {
  490. mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
  491. mgmt_frame->desc_word[5] = cpu_to_le16(buf_size);
  492. mgmt_frame->desc_word[7] =
  493. cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8)));
  494. } else if (event == STA_RX_ADDBA_DONE) {
  495. mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
  496. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  497. (START_AMPDU_AGGR << 4) |
  498. (RX_BA_INDICATION << 5) |
  499. (peer_id << 8));
  500. } else if (event == STA_TX_DELBA) {
  501. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  502. (STOP_AMPDU_AGGR << 4) |
  503. (peer_id << 8));
  504. } else if (event == STA_RX_DELBA) {
  505. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  506. (STOP_AMPDU_AGGR << 4) |
  507. (RX_BA_INDICATION << 5) |
  508. (peer_id << 8));
  509. }
  510. skb_put(skb, FRAME_DESC_SZ);
  511. return rsi_send_internal_mgmt_frame(common, skb);
  512. }
  513. /**
  514. * rsi_program_bb_rf() - This function starts base band and RF programming.
  515. * This is called after initial configurations are done.
  516. * @common: Pointer to the driver private structure.
  517. *
  518. * Return: 0 on success, corresponding negative error code on failure.
  519. */
  520. static int rsi_program_bb_rf(struct rsi_common *common)
  521. {
  522. struct sk_buff *skb;
  523. struct rsi_mac_frame *mgmt_frame;
  524. rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
  525. skb = dev_alloc_skb(FRAME_DESC_SZ);
  526. if (!skb) {
  527. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  528. __func__);
  529. return -ENOMEM;
  530. }
  531. memset(skb->data, 0, FRAME_DESC_SZ);
  532. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  533. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  534. mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA);
  535. mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint);
  536. if (common->rf_reset) {
  537. mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE);
  538. rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
  539. __func__);
  540. common->rf_reset = 0;
  541. }
  542. common->bb_rf_prog_count = 1;
  543. mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET |
  544. BBP_REG_WRITE | (RSI_RF_TYPE << 4));
  545. skb_put(skb, FRAME_DESC_SZ);
  546. return rsi_send_internal_mgmt_frame(common, skb);
  547. }
  548. /**
  549. * rsi_set_vap_capabilities() - This function send vap capability to firmware.
  550. * @common: Pointer to the driver private structure.
  551. * @opmode: Operating mode of device.
  552. *
  553. * Return: 0 on success, corresponding negative error code on failure.
  554. */
  555. int rsi_set_vap_capabilities(struct rsi_common *common,
  556. enum opmode mode,
  557. u8 vap_status)
  558. {
  559. struct sk_buff *skb = NULL;
  560. struct rsi_vap_caps *vap_caps;
  561. struct rsi_hw *adapter = common->priv;
  562. struct ieee80211_hw *hw = adapter->hw;
  563. struct ieee80211_conf *conf = &hw->conf;
  564. u16 vap_id = 0;
  565. rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
  566. skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
  567. if (!skb) {
  568. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  569. __func__);
  570. return -ENOMEM;
  571. }
  572. memset(skb->data, 0, sizeof(struct rsi_vap_caps));
  573. vap_caps = (struct rsi_vap_caps *)skb->data;
  574. vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
  575. FRAME_DESC_SZ) |
  576. (RSI_WIFI_MGMT_Q << 12));
  577. vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
  578. vap_caps->desc_word[2] = cpu_to_le16(vap_status << 8);
  579. vap_caps->desc_word[4] = cpu_to_le16(mode |
  580. (common->channel_width << 8));
  581. vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
  582. (common->mac_id << 4) |
  583. common->radio_id);
  584. memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
  585. vap_caps->keep_alive_period = cpu_to_le16(90);
  586. vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
  587. vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
  588. vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6);
  589. if (common->band == NL80211_BAND_5GHZ) {
  590. vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
  591. if (conf_is_ht40(&common->priv->hw->conf)) {
  592. vap_caps->default_ctrl_rate |=
  593. cpu_to_le32(FULL40M_ENABLE << 16);
  594. }
  595. } else {
  596. vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_1);
  597. if (conf_is_ht40_minus(conf))
  598. vap_caps->default_ctrl_rate |=
  599. cpu_to_le32(UPPER_20_ENABLE << 16);
  600. else if (conf_is_ht40_plus(conf))
  601. vap_caps->default_ctrl_rate |=
  602. cpu_to_le32(LOWER_20_ENABLE << 16);
  603. }
  604. vap_caps->default_data_rate = 0;
  605. vap_caps->beacon_interval = cpu_to_le16(200);
  606. vap_caps->dtim_period = cpu_to_le16(4);
  607. skb_put(skb, sizeof(*vap_caps));
  608. return rsi_send_internal_mgmt_frame(common, skb);
  609. }
  610. /**
  611. * rsi_hal_load_key() - This function is used to load keys within the firmware.
  612. * @common: Pointer to the driver private structure.
  613. * @data: Pointer to the key data.
  614. * @key_len: Key length to be loaded.
  615. * @key_type: Type of key: GROUP/PAIRWISE.
  616. * @key_id: Key index.
  617. * @cipher: Type of cipher used.
  618. *
  619. * Return: 0 on success, -1 on failure.
  620. */
  621. int rsi_hal_load_key(struct rsi_common *common,
  622. u8 *data,
  623. u16 key_len,
  624. u8 key_type,
  625. u8 key_id,
  626. u32 cipher)
  627. {
  628. struct sk_buff *skb = NULL;
  629. struct rsi_set_key *set_key;
  630. u16 key_descriptor = 0;
  631. rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
  632. skb = dev_alloc_skb(sizeof(struct rsi_set_key));
  633. if (!skb) {
  634. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  635. __func__);
  636. return -ENOMEM;
  637. }
  638. memset(skb->data, 0, sizeof(struct rsi_set_key));
  639. set_key = (struct rsi_set_key *)skb->data;
  640. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  641. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  642. key_len += 1;
  643. key_descriptor |= BIT(2);
  644. if (key_len >= 13)
  645. key_descriptor |= BIT(3);
  646. } else if (cipher != KEY_TYPE_CLEAR) {
  647. key_descriptor |= BIT(4);
  648. if (key_type == RSI_PAIRWISE_KEY)
  649. key_id = 0;
  650. if (cipher == WLAN_CIPHER_SUITE_TKIP)
  651. key_descriptor |= BIT(5);
  652. }
  653. key_descriptor |= (key_type | BIT(13) | (key_id << 14));
  654. set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
  655. FRAME_DESC_SZ) |
  656. (RSI_WIFI_MGMT_Q << 12));
  657. set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
  658. set_key->desc_word[4] = cpu_to_le16(key_descriptor);
  659. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  660. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  661. memcpy(&set_key->key[key_id][1],
  662. data,
  663. key_len * 2);
  664. } else {
  665. memcpy(&set_key->key[0][0], data, key_len);
  666. }
  667. memcpy(set_key->tx_mic_key, &data[16], 8);
  668. memcpy(set_key->rx_mic_key, &data[24], 8);
  669. skb_put(skb, sizeof(struct rsi_set_key));
  670. return rsi_send_internal_mgmt_frame(common, skb);
  671. }
  672. /*
  673. * rsi_load_bootup_params() - This function send bootup params to the firmware.
  674. * @common: Pointer to the driver private structure.
  675. *
  676. * Return: 0 on success, corresponding error code on failure.
  677. */
  678. static int rsi_load_bootup_params(struct rsi_common *common)
  679. {
  680. struct sk_buff *skb;
  681. struct rsi_boot_params *boot_params;
  682. rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
  683. skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
  684. if (!skb) {
  685. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  686. __func__);
  687. return -ENOMEM;
  688. }
  689. memset(skb->data, 0, sizeof(struct rsi_boot_params));
  690. boot_params = (struct rsi_boot_params *)skb->data;
  691. rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
  692. if (common->channel_width == BW_40MHZ) {
  693. memcpy(&boot_params->bootup_params,
  694. &boot_params_40,
  695. sizeof(struct bootup_params));
  696. rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
  697. UMAC_CLK_40BW);
  698. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
  699. } else {
  700. memcpy(&boot_params->bootup_params,
  701. &boot_params_20,
  702. sizeof(struct bootup_params));
  703. if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
  704. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
  705. rsi_dbg(MGMT_TX_ZONE,
  706. "%s: Packet 20MHZ <=== %d\n", __func__,
  707. UMAC_CLK_20BW);
  708. } else {
  709. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
  710. rsi_dbg(MGMT_TX_ZONE,
  711. "%s: Packet 20MHZ <=== %d\n", __func__,
  712. UMAC_CLK_40MHZ);
  713. }
  714. }
  715. /**
  716. * Bit{0:11} indicates length of the Packet
  717. * Bit{12:15} indicates host queue number
  718. */
  719. boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
  720. (RSI_WIFI_MGMT_Q << 12));
  721. boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
  722. skb_put(skb, sizeof(struct rsi_boot_params));
  723. return rsi_send_internal_mgmt_frame(common, skb);
  724. }
  725. /**
  726. * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
  727. * internal management frame to indicate it to firmware.
  728. * @common: Pointer to the driver private structure.
  729. *
  730. * Return: 0 on success, corresponding error code on failure.
  731. */
  732. static int rsi_send_reset_mac(struct rsi_common *common)
  733. {
  734. struct sk_buff *skb;
  735. struct rsi_mac_frame *mgmt_frame;
  736. rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
  737. skb = dev_alloc_skb(FRAME_DESC_SZ);
  738. if (!skb) {
  739. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  740. __func__);
  741. return -ENOMEM;
  742. }
  743. memset(skb->data, 0, FRAME_DESC_SZ);
  744. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  745. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  746. mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
  747. mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
  748. skb_put(skb, FRAME_DESC_SZ);
  749. return rsi_send_internal_mgmt_frame(common, skb);
  750. }
  751. /**
  752. * rsi_band_check() - This function programs the band
  753. * @common: Pointer to the driver private structure.
  754. *
  755. * Return: 0 on success, corresponding error code on failure.
  756. */
  757. int rsi_band_check(struct rsi_common *common)
  758. {
  759. struct rsi_hw *adapter = common->priv;
  760. struct ieee80211_hw *hw = adapter->hw;
  761. u8 prev_bw = common->channel_width;
  762. u8 prev_ep = common->endpoint;
  763. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  764. int status = 0;
  765. if (common->band != curchan->band) {
  766. common->rf_reset = 1;
  767. common->band = curchan->band;
  768. }
  769. if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) ||
  770. (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20))
  771. common->channel_width = BW_20MHZ;
  772. else
  773. common->channel_width = BW_40MHZ;
  774. if (common->band == NL80211_BAND_2GHZ) {
  775. if (common->channel_width)
  776. common->endpoint = EP_2GHZ_40MHZ;
  777. else
  778. common->endpoint = EP_2GHZ_20MHZ;
  779. } else {
  780. if (common->channel_width)
  781. common->endpoint = EP_5GHZ_40MHZ;
  782. else
  783. common->endpoint = EP_5GHZ_20MHZ;
  784. }
  785. if (common->endpoint != prev_ep) {
  786. status = rsi_program_bb_rf(common);
  787. if (status)
  788. return status;
  789. }
  790. if (common->channel_width != prev_bw) {
  791. status = rsi_load_bootup_params(common);
  792. if (status)
  793. return status;
  794. status = rsi_load_radio_caps(common);
  795. if (status)
  796. return status;
  797. }
  798. return status;
  799. }
  800. /**
  801. * rsi_set_channel() - This function programs the channel.
  802. * @common: Pointer to the driver private structure.
  803. * @channel: Channel value to be set.
  804. *
  805. * Return: 0 on success, corresponding error code on failure.
  806. */
  807. int rsi_set_channel(struct rsi_common *common,
  808. struct ieee80211_channel *channel)
  809. {
  810. struct sk_buff *skb = NULL;
  811. struct rsi_mac_frame *mgmt_frame;
  812. rsi_dbg(MGMT_TX_ZONE,
  813. "%s: Sending scan req frame\n", __func__);
  814. skb = dev_alloc_skb(FRAME_DESC_SZ);
  815. if (!skb) {
  816. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  817. __func__);
  818. return -ENOMEM;
  819. }
  820. if (!channel) {
  821. dev_kfree_skb(skb);
  822. return 0;
  823. }
  824. memset(skb->data, 0, FRAME_DESC_SZ);
  825. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  826. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  827. mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
  828. mgmt_frame->desc_word[4] = cpu_to_le16(channel->hw_value);
  829. mgmt_frame->desc_word[4] |=
  830. cpu_to_le16(((char)(channel->max_antenna_gain)) << 8);
  831. mgmt_frame->desc_word[5] =
  832. cpu_to_le16((char)(channel->max_antenna_gain));
  833. mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
  834. BBP_REG_WRITE |
  835. (RSI_RF_TYPE << 4));
  836. if (!(channel->flags & IEEE80211_CHAN_NO_IR) &&
  837. !(channel->flags & IEEE80211_CHAN_RADAR)) {
  838. if (common->tx_power < channel->max_power)
  839. mgmt_frame->desc_word[6] = cpu_to_le16(common->tx_power);
  840. else
  841. mgmt_frame->desc_word[6] = cpu_to_le16(channel->max_power);
  842. }
  843. mgmt_frame->desc_word[7] = cpu_to_le16(common->priv->dfs_region);
  844. if (common->channel_width == BW_40MHZ)
  845. mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
  846. common->channel = channel->hw_value;
  847. skb_put(skb, FRAME_DESC_SZ);
  848. return rsi_send_internal_mgmt_frame(common, skb);
  849. }
  850. /**
  851. * rsi_send_radio_params_update() - This function sends the radio
  852. * parameters update to device
  853. * @common: Pointer to the driver private structure.
  854. * @channel: Channel value to be set.
  855. *
  856. * Return: 0 on success, corresponding error code on failure.
  857. */
  858. int rsi_send_radio_params_update(struct rsi_common *common)
  859. {
  860. struct rsi_mac_frame *cmd_frame;
  861. struct sk_buff *skb = NULL;
  862. rsi_dbg(MGMT_TX_ZONE,
  863. "%s: Sending Radio Params update frame\n", __func__);
  864. skb = dev_alloc_skb(FRAME_DESC_SZ);
  865. if (!skb) {
  866. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  867. __func__);
  868. return -ENOMEM;
  869. }
  870. memset(skb->data, 0, FRAME_DESC_SZ);
  871. cmd_frame = (struct rsi_mac_frame *)skb->data;
  872. cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  873. cmd_frame->desc_word[1] = cpu_to_le16(RADIO_PARAMS_UPDATE);
  874. cmd_frame->desc_word[3] = cpu_to_le16(BIT(0));
  875. cmd_frame->desc_word[3] |= cpu_to_le16(common->tx_power << 8);
  876. skb_put(skb, FRAME_DESC_SZ);
  877. return rsi_send_internal_mgmt_frame(common, skb);
  878. }
  879. /**
  880. * rsi_compare() - This function is used to compare two integers
  881. * @a: pointer to the first integer
  882. * @b: pointer to the second integer
  883. *
  884. * Return: 0 if both are equal, -1 if the first is smaller, else 1
  885. */
  886. static int rsi_compare(const void *a, const void *b)
  887. {
  888. u16 _a = *(const u16 *)(a);
  889. u16 _b = *(const u16 *)(b);
  890. if (_a > _b)
  891. return -1;
  892. if (_a < _b)
  893. return 1;
  894. return 0;
  895. }
  896. /**
  897. * rsi_map_rates() - This function is used to map selected rates to hw rates.
  898. * @rate: The standard rate to be mapped.
  899. * @offset: Offset that will be returned.
  900. *
  901. * Return: 0 if it is a mcs rate, else 1
  902. */
  903. static bool rsi_map_rates(u16 rate, int *offset)
  904. {
  905. int kk;
  906. for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
  907. if (rate == mcs[kk]) {
  908. *offset = kk;
  909. return false;
  910. }
  911. }
  912. for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
  913. if (rate == rsi_rates[kk].bitrate / 5) {
  914. *offset = kk;
  915. break;
  916. }
  917. }
  918. return true;
  919. }
  920. /**
  921. * rsi_send_auto_rate_request() - This function is to set rates for connection
  922. * and send autorate request to firmware.
  923. * @common: Pointer to the driver private structure.
  924. *
  925. * Return: 0 on success, corresponding error code on failure.
  926. */
  927. static int rsi_send_auto_rate_request(struct rsi_common *common)
  928. {
  929. struct sk_buff *skb;
  930. struct rsi_auto_rate *auto_rate;
  931. int ii = 0, jj = 0, kk = 0;
  932. struct ieee80211_hw *hw = common->priv->hw;
  933. u8 band = hw->conf.chandef.chan->band;
  934. u8 num_supported_rates = 0;
  935. u8 rate_table_offset, rate_offset = 0;
  936. u32 rate_bitmap = common->bitrate_mask[band];
  937. u16 *selected_rates, min_rate;
  938. skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
  939. if (!skb) {
  940. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  941. __func__);
  942. return -ENOMEM;
  943. }
  944. selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
  945. if (!selected_rates) {
  946. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
  947. __func__);
  948. dev_kfree_skb(skb);
  949. return -ENOMEM;
  950. }
  951. memset(skb->data, 0, sizeof(struct rsi_auto_rate));
  952. auto_rate = (struct rsi_auto_rate *)skb->data;
  953. auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
  954. auto_rate->collision_tolerance = cpu_to_le16(3);
  955. auto_rate->failure_limit = cpu_to_le16(3);
  956. auto_rate->initial_boundary = cpu_to_le16(3);
  957. auto_rate->max_threshold_limt = cpu_to_le16(27);
  958. auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
  959. if (common->channel_width == BW_40MHZ)
  960. auto_rate->desc_word[7] |= cpu_to_le16(1);
  961. if (band == NL80211_BAND_2GHZ) {
  962. min_rate = RSI_RATE_1;
  963. rate_table_offset = 0;
  964. } else {
  965. min_rate = RSI_RATE_6;
  966. rate_table_offset = 4;
  967. }
  968. for (ii = 0, jj = 0;
  969. ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) {
  970. if (rate_bitmap & BIT(ii)) {
  971. selected_rates[jj++] =
  972. (rsi_rates[ii + rate_table_offset].bitrate / 5);
  973. rate_offset++;
  974. }
  975. }
  976. num_supported_rates = jj;
  977. if (common->vif_info[0].is_ht) {
  978. for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
  979. selected_rates[jj++] = mcs[ii];
  980. num_supported_rates += ARRAY_SIZE(mcs);
  981. rate_offset += ARRAY_SIZE(mcs);
  982. }
  983. sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
  984. /* mapping the rates to RSI rates */
  985. for (ii = 0; ii < jj; ii++) {
  986. if (rsi_map_rates(selected_rates[ii], &kk)) {
  987. auto_rate->supported_rates[ii] =
  988. cpu_to_le16(rsi_rates[kk].hw_value);
  989. } else {
  990. auto_rate->supported_rates[ii] =
  991. cpu_to_le16(rsi_mcsrates[kk]);
  992. }
  993. }
  994. /* loading HT rates in the bottom half of the auto rate table */
  995. if (common->vif_info[0].is_ht) {
  996. for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
  997. ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
  998. if (common->vif_info[0].sgi ||
  999. conf_is_ht40(&common->priv->hw->conf))
  1000. auto_rate->supported_rates[ii++] =
  1001. cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
  1002. auto_rate->supported_rates[ii] =
  1003. cpu_to_le16(rsi_mcsrates[kk--]);
  1004. }
  1005. for (; ii < (RSI_TBL_SZ - 1); ii++) {
  1006. auto_rate->supported_rates[ii] =
  1007. cpu_to_le16(rsi_mcsrates[0]);
  1008. }
  1009. }
  1010. for (; ii < RSI_TBL_SZ; ii++)
  1011. auto_rate->supported_rates[ii] = cpu_to_le16(min_rate);
  1012. auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
  1013. auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
  1014. auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
  1015. num_supported_rates *= 2;
  1016. auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
  1017. FRAME_DESC_SZ) |
  1018. (RSI_WIFI_MGMT_Q << 12));
  1019. skb_put(skb,
  1020. sizeof(struct rsi_auto_rate));
  1021. kfree(selected_rates);
  1022. return rsi_send_internal_mgmt_frame(common, skb);
  1023. }
  1024. /**
  1025. * rsi_inform_bss_status() - This function informs about bss status with the
  1026. * help of sta notify params by sending an internal
  1027. * management frame to firmware.
  1028. * @common: Pointer to the driver private structure.
  1029. * @status: Bss status type.
  1030. * @bssid: Bssid.
  1031. * @qos_enable: Qos is enabled.
  1032. * @aid: Aid (unique for all STAs).
  1033. *
  1034. * Return: None.
  1035. */
  1036. void rsi_inform_bss_status(struct rsi_common *common,
  1037. u8 status,
  1038. const unsigned char *bssid,
  1039. u8 qos_enable,
  1040. u16 aid)
  1041. {
  1042. if (status) {
  1043. rsi_hal_send_sta_notify_frame(common,
  1044. RSI_IFTYPE_STATION,
  1045. STA_CONNECTED,
  1046. bssid,
  1047. qos_enable,
  1048. aid);
  1049. if (common->min_rate == 0xffff)
  1050. rsi_send_auto_rate_request(common);
  1051. } else {
  1052. rsi_hal_send_sta_notify_frame(common,
  1053. RSI_IFTYPE_STATION,
  1054. STA_DISCONNECTED,
  1055. bssid,
  1056. qos_enable,
  1057. aid);
  1058. }
  1059. }
  1060. /**
  1061. * rsi_eeprom_read() - This function sends a frame to read the mac address
  1062. * from the eeprom.
  1063. * @common: Pointer to the driver private structure.
  1064. *
  1065. * Return: 0 on success, -1 on failure.
  1066. */
  1067. static int rsi_eeprom_read(struct rsi_common *common)
  1068. {
  1069. struct rsi_mac_frame *mgmt_frame;
  1070. struct sk_buff *skb;
  1071. rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
  1072. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1073. if (!skb) {
  1074. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1075. __func__);
  1076. return -ENOMEM;
  1077. }
  1078. memset(skb->data, 0, FRAME_DESC_SZ);
  1079. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  1080. /* FrameType */
  1081. mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
  1082. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1083. /* Number of bytes to read */
  1084. mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
  1085. WLAN_MAC_MAGIC_WORD_LEN +
  1086. WLAN_HOST_MODE_LEN +
  1087. WLAN_FW_VERSION_LEN);
  1088. /* Address to read */
  1089. mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
  1090. skb_put(skb, FRAME_DESC_SZ);
  1091. return rsi_send_internal_mgmt_frame(common, skb);
  1092. }
  1093. /**
  1094. * This function sends a frame to block/unblock
  1095. * data queues in the firmware
  1096. *
  1097. * @param common Pointer to the driver private structure.
  1098. * @param block event - block if true, unblock if false
  1099. * @return 0 on success, -1 on failure.
  1100. */
  1101. int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event)
  1102. {
  1103. struct rsi_mac_frame *mgmt_frame;
  1104. struct sk_buff *skb;
  1105. rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__);
  1106. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1107. if (!skb) {
  1108. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1109. __func__);
  1110. return -ENOMEM;
  1111. }
  1112. memset(skb->data, 0, FRAME_DESC_SZ);
  1113. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  1114. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1115. mgmt_frame->desc_word[1] = cpu_to_le16(BLOCK_HW_QUEUE);
  1116. if (block_event) {
  1117. rsi_dbg(INFO_ZONE, "blocking the data qs\n");
  1118. mgmt_frame->desc_word[4] = cpu_to_le16(0xf);
  1119. } else {
  1120. rsi_dbg(INFO_ZONE, "unblocking the data qs\n");
  1121. mgmt_frame->desc_word[5] = cpu_to_le16(0xf);
  1122. }
  1123. skb_put(skb, FRAME_DESC_SZ);
  1124. return rsi_send_internal_mgmt_frame(common, skb);
  1125. }
  1126. /**
  1127. * rsi_send_rx_filter_frame() - Sends a frame to filter the RX packets
  1128. *
  1129. * @common: Pointer to the driver private structure.
  1130. * @rx_filter_word: Flags of filter packets
  1131. *
  1132. * @Return: 0 on success, -1 on failure.
  1133. */
  1134. int rsi_send_rx_filter_frame(struct rsi_common *common, u16 rx_filter_word)
  1135. {
  1136. struct rsi_mac_frame *cmd_frame;
  1137. struct sk_buff *skb;
  1138. rsi_dbg(MGMT_TX_ZONE, "Sending RX filter frame\n");
  1139. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1140. if (!skb) {
  1141. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1142. __func__);
  1143. return -ENOMEM;
  1144. }
  1145. memset(skb->data, 0, FRAME_DESC_SZ);
  1146. cmd_frame = (struct rsi_mac_frame *)skb->data;
  1147. cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1148. cmd_frame->desc_word[1] = cpu_to_le16(SET_RX_FILTER);
  1149. cmd_frame->desc_word[4] = cpu_to_le16(rx_filter_word);
  1150. skb_put(skb, FRAME_DESC_SZ);
  1151. return rsi_send_internal_mgmt_frame(common, skb);
  1152. }
  1153. /**
  1154. * rsi_set_antenna() - This fuction send antenna configuration request
  1155. * to device
  1156. *
  1157. * @common: Pointer to the driver private structure.
  1158. * @antenna: bitmap for tx antenna selection
  1159. *
  1160. * Return: 0 on Success, negative error code on failure
  1161. */
  1162. int rsi_set_antenna(struct rsi_common *common, u8 antenna)
  1163. {
  1164. struct rsi_mac_frame *cmd_frame;
  1165. struct sk_buff *skb;
  1166. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1167. if (!skb) {
  1168. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1169. __func__);
  1170. return -ENOMEM;
  1171. }
  1172. memset(skb->data, 0, FRAME_DESC_SZ);
  1173. cmd_frame = (struct rsi_mac_frame *)skb->data;
  1174. cmd_frame->desc_word[1] = cpu_to_le16(ANT_SEL_FRAME);
  1175. cmd_frame->desc_word[3] = cpu_to_le16(antenna & 0x00ff);
  1176. cmd_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1177. skb_put(skb, FRAME_DESC_SZ);
  1178. return rsi_send_internal_mgmt_frame(common, skb);
  1179. }
  1180. /**
  1181. * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
  1182. * @common: Pointer to the driver private structure.
  1183. * @msg: Pointer to received packet.
  1184. *
  1185. * Return: 0 on success, -1 on failure.
  1186. */
  1187. static int rsi_handle_ta_confirm_type(struct rsi_common *common,
  1188. u8 *msg)
  1189. {
  1190. u8 sub_type = (msg[15] & 0xff);
  1191. switch (sub_type) {
  1192. case BOOTUP_PARAMS_REQUEST:
  1193. rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
  1194. __func__);
  1195. if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
  1196. if (rsi_eeprom_read(common)) {
  1197. common->fsm_state = FSM_CARD_NOT_READY;
  1198. goto out;
  1199. } else {
  1200. common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
  1201. }
  1202. } else {
  1203. rsi_dbg(INFO_ZONE,
  1204. "%s: Received bootup params cfm in %d state\n",
  1205. __func__, common->fsm_state);
  1206. return 0;
  1207. }
  1208. break;
  1209. case EEPROM_READ_TYPE:
  1210. if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
  1211. if (msg[16] == MAGIC_WORD) {
  1212. u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
  1213. + WLAN_MAC_MAGIC_WORD_LEN);
  1214. memcpy(common->mac_addr,
  1215. &msg[offset],
  1216. ETH_ALEN);
  1217. memcpy(&common->fw_ver,
  1218. &msg[offset + ETH_ALEN],
  1219. sizeof(struct version_info));
  1220. } else {
  1221. common->fsm_state = FSM_CARD_NOT_READY;
  1222. break;
  1223. }
  1224. if (rsi_send_reset_mac(common))
  1225. goto out;
  1226. else
  1227. common->fsm_state = FSM_RESET_MAC_SENT;
  1228. } else {
  1229. rsi_dbg(ERR_ZONE,
  1230. "%s: Received eeprom mac addr in %d state\n",
  1231. __func__, common->fsm_state);
  1232. return 0;
  1233. }
  1234. break;
  1235. case RESET_MAC_REQ:
  1236. if (common->fsm_state == FSM_RESET_MAC_SENT) {
  1237. rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
  1238. __func__);
  1239. if (rsi_load_radio_caps(common))
  1240. goto out;
  1241. else
  1242. common->fsm_state = FSM_RADIO_CAPS_SENT;
  1243. } else {
  1244. rsi_dbg(ERR_ZONE,
  1245. "%s: Received reset mac cfm in %d state\n",
  1246. __func__, common->fsm_state);
  1247. return 0;
  1248. }
  1249. break;
  1250. case RADIO_CAPABILITIES:
  1251. if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
  1252. common->rf_reset = 1;
  1253. if (rsi_program_bb_rf(common)) {
  1254. goto out;
  1255. } else {
  1256. common->fsm_state = FSM_BB_RF_PROG_SENT;
  1257. rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
  1258. __func__);
  1259. }
  1260. } else {
  1261. rsi_dbg(INFO_ZONE,
  1262. "%s: Received radio caps cfm in %d state\n",
  1263. __func__, common->fsm_state);
  1264. return 0;
  1265. }
  1266. break;
  1267. case BB_PROG_VALUES_REQUEST:
  1268. case RF_PROG_VALUES_REQUEST:
  1269. case BBP_PROG_IN_TA:
  1270. rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
  1271. if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
  1272. common->bb_rf_prog_count--;
  1273. if (!common->bb_rf_prog_count) {
  1274. common->fsm_state = FSM_MAC_INIT_DONE;
  1275. return rsi_mac80211_attach(common);
  1276. }
  1277. } else {
  1278. rsi_dbg(INFO_ZONE,
  1279. "%s: Received bbb_rf cfm in %d state\n",
  1280. __func__, common->fsm_state);
  1281. return 0;
  1282. }
  1283. break;
  1284. default:
  1285. rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
  1286. __func__);
  1287. break;
  1288. }
  1289. return 0;
  1290. out:
  1291. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
  1292. __func__);
  1293. return -EINVAL;
  1294. }
  1295. /**
  1296. * rsi_mgmt_pkt_recv() - This function processes the management packets
  1297. * recieved from the hardware.
  1298. * @common: Pointer to the driver private structure.
  1299. * @msg: Pointer to the received packet.
  1300. *
  1301. * Return: 0 on success, -1 on failure.
  1302. */
  1303. int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
  1304. {
  1305. s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
  1306. u16 msg_type = (msg[2]);
  1307. int ret;
  1308. rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
  1309. __func__, msg_len, msg_type);
  1310. if (msg_type == TA_CONFIRM_TYPE) {
  1311. return rsi_handle_ta_confirm_type(common, msg);
  1312. } else if (msg_type == CARD_READY_IND) {
  1313. rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
  1314. __func__);
  1315. if (common->fsm_state == FSM_CARD_NOT_READY) {
  1316. rsi_set_default_parameters(common);
  1317. ret = rsi_load_bootup_params(common);
  1318. if (ret)
  1319. return ret;
  1320. else
  1321. common->fsm_state = FSM_BOOT_PARAMS_SENT;
  1322. } else {
  1323. return -EINVAL;
  1324. }
  1325. } else if (msg_type == TX_STATUS_IND) {
  1326. if (msg[15] == PROBEREQ_CONFIRM) {
  1327. common->mgmt_q_block = false;
  1328. rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
  1329. __func__);
  1330. }
  1331. } else {
  1332. return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);
  1333. }
  1334. return 0;
  1335. }