rsi_91x_mgmt.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  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, enum opmode mode)
  556. {
  557. struct sk_buff *skb = NULL;
  558. struct rsi_vap_caps *vap_caps;
  559. struct rsi_hw *adapter = common->priv;
  560. struct ieee80211_hw *hw = adapter->hw;
  561. struct ieee80211_conf *conf = &hw->conf;
  562. u16 vap_id = 0;
  563. rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
  564. skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
  565. if (!skb) {
  566. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  567. __func__);
  568. return -ENOMEM;
  569. }
  570. memset(skb->data, 0, sizeof(struct rsi_vap_caps));
  571. vap_caps = (struct rsi_vap_caps *)skb->data;
  572. vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
  573. FRAME_DESC_SZ) |
  574. (RSI_WIFI_MGMT_Q << 12));
  575. vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
  576. vap_caps->desc_word[4] = cpu_to_le16(mode |
  577. (common->channel_width << 8));
  578. vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
  579. (common->mac_id << 4) |
  580. common->radio_id);
  581. memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
  582. vap_caps->keep_alive_period = cpu_to_le16(90);
  583. vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
  584. vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
  585. vap_caps->default_mgmt_rate = cpu_to_le32(RSI_RATE_6);
  586. if (common->band == NL80211_BAND_5GHZ) {
  587. vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
  588. if (conf_is_ht40(&common->priv->hw->conf)) {
  589. vap_caps->default_ctrl_rate |=
  590. cpu_to_le32(FULL40M_ENABLE << 16);
  591. }
  592. } else {
  593. vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_1);
  594. if (conf_is_ht40_minus(conf))
  595. vap_caps->default_ctrl_rate |=
  596. cpu_to_le32(UPPER_20_ENABLE << 16);
  597. else if (conf_is_ht40_plus(conf))
  598. vap_caps->default_ctrl_rate |=
  599. cpu_to_le32(LOWER_20_ENABLE << 16);
  600. }
  601. vap_caps->default_data_rate = 0;
  602. vap_caps->beacon_interval = cpu_to_le16(200);
  603. vap_caps->dtim_period = cpu_to_le16(4);
  604. skb_put(skb, sizeof(*vap_caps));
  605. return rsi_send_internal_mgmt_frame(common, skb);
  606. }
  607. /**
  608. * rsi_hal_load_key() - This function is used to load keys within the firmware.
  609. * @common: Pointer to the driver private structure.
  610. * @data: Pointer to the key data.
  611. * @key_len: Key length to be loaded.
  612. * @key_type: Type of key: GROUP/PAIRWISE.
  613. * @key_id: Key index.
  614. * @cipher: Type of cipher used.
  615. *
  616. * Return: 0 on success, -1 on failure.
  617. */
  618. int rsi_hal_load_key(struct rsi_common *common,
  619. u8 *data,
  620. u16 key_len,
  621. u8 key_type,
  622. u8 key_id,
  623. u32 cipher)
  624. {
  625. struct sk_buff *skb = NULL;
  626. struct rsi_set_key *set_key;
  627. u16 key_descriptor = 0;
  628. rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
  629. skb = dev_alloc_skb(sizeof(struct rsi_set_key));
  630. if (!skb) {
  631. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  632. __func__);
  633. return -ENOMEM;
  634. }
  635. memset(skb->data, 0, sizeof(struct rsi_set_key));
  636. set_key = (struct rsi_set_key *)skb->data;
  637. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  638. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  639. key_len += 1;
  640. key_descriptor |= BIT(2);
  641. if (key_len >= 13)
  642. key_descriptor |= BIT(3);
  643. } else if (cipher != KEY_TYPE_CLEAR) {
  644. key_descriptor |= BIT(4);
  645. if (key_type == RSI_PAIRWISE_KEY)
  646. key_id = 0;
  647. if (cipher == WLAN_CIPHER_SUITE_TKIP)
  648. key_descriptor |= BIT(5);
  649. }
  650. key_descriptor |= (key_type | BIT(13) | (key_id << 14));
  651. set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
  652. FRAME_DESC_SZ) |
  653. (RSI_WIFI_MGMT_Q << 12));
  654. set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
  655. set_key->desc_word[4] = cpu_to_le16(key_descriptor);
  656. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  657. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  658. memcpy(&set_key->key[key_id][1],
  659. data,
  660. key_len * 2);
  661. } else {
  662. memcpy(&set_key->key[0][0], data, key_len);
  663. }
  664. memcpy(set_key->tx_mic_key, &data[16], 8);
  665. memcpy(set_key->rx_mic_key, &data[24], 8);
  666. skb_put(skb, sizeof(struct rsi_set_key));
  667. return rsi_send_internal_mgmt_frame(common, skb);
  668. }
  669. /*
  670. * rsi_load_bootup_params() - This function send bootup params to the firmware.
  671. * @common: Pointer to the driver private structure.
  672. *
  673. * Return: 0 on success, corresponding error code on failure.
  674. */
  675. static int rsi_load_bootup_params(struct rsi_common *common)
  676. {
  677. struct sk_buff *skb;
  678. struct rsi_boot_params *boot_params;
  679. rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
  680. skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
  681. if (!skb) {
  682. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  683. __func__);
  684. return -ENOMEM;
  685. }
  686. memset(skb->data, 0, sizeof(struct rsi_boot_params));
  687. boot_params = (struct rsi_boot_params *)skb->data;
  688. rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
  689. if (common->channel_width == BW_40MHZ) {
  690. memcpy(&boot_params->bootup_params,
  691. &boot_params_40,
  692. sizeof(struct bootup_params));
  693. rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
  694. UMAC_CLK_40BW);
  695. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
  696. } else {
  697. memcpy(&boot_params->bootup_params,
  698. &boot_params_20,
  699. sizeof(struct bootup_params));
  700. if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
  701. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
  702. rsi_dbg(MGMT_TX_ZONE,
  703. "%s: Packet 20MHZ <=== %d\n", __func__,
  704. UMAC_CLK_20BW);
  705. } else {
  706. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
  707. rsi_dbg(MGMT_TX_ZONE,
  708. "%s: Packet 20MHZ <=== %d\n", __func__,
  709. UMAC_CLK_40MHZ);
  710. }
  711. }
  712. /**
  713. * Bit{0:11} indicates length of the Packet
  714. * Bit{12:15} indicates host queue number
  715. */
  716. boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
  717. (RSI_WIFI_MGMT_Q << 12));
  718. boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
  719. skb_put(skb, sizeof(struct rsi_boot_params));
  720. return rsi_send_internal_mgmt_frame(common, skb);
  721. }
  722. /**
  723. * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
  724. * internal management frame to indicate it to firmware.
  725. * @common: Pointer to the driver private structure.
  726. *
  727. * Return: 0 on success, corresponding error code on failure.
  728. */
  729. static int rsi_send_reset_mac(struct rsi_common *common)
  730. {
  731. struct sk_buff *skb;
  732. struct rsi_mac_frame *mgmt_frame;
  733. rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
  734. skb = dev_alloc_skb(FRAME_DESC_SZ);
  735. if (!skb) {
  736. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  737. __func__);
  738. return -ENOMEM;
  739. }
  740. memset(skb->data, 0, FRAME_DESC_SZ);
  741. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  742. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  743. mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
  744. mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
  745. skb_put(skb, FRAME_DESC_SZ);
  746. return rsi_send_internal_mgmt_frame(common, skb);
  747. }
  748. /**
  749. * rsi_band_check() - This function programs the band
  750. * @common: Pointer to the driver private structure.
  751. *
  752. * Return: 0 on success, corresponding error code on failure.
  753. */
  754. int rsi_band_check(struct rsi_common *common)
  755. {
  756. struct rsi_hw *adapter = common->priv;
  757. struct ieee80211_hw *hw = adapter->hw;
  758. u8 prev_bw = common->channel_width;
  759. u8 prev_ep = common->endpoint;
  760. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  761. int status = 0;
  762. if (common->band != curchan->band) {
  763. common->rf_reset = 1;
  764. common->band = curchan->band;
  765. }
  766. if ((hw->conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) ||
  767. (hw->conf.chandef.width == NL80211_CHAN_WIDTH_20))
  768. common->channel_width = BW_20MHZ;
  769. else
  770. common->channel_width = BW_40MHZ;
  771. if (common->band == NL80211_BAND_2GHZ) {
  772. if (common->channel_width)
  773. common->endpoint = EP_2GHZ_40MHZ;
  774. else
  775. common->endpoint = EP_2GHZ_20MHZ;
  776. } else {
  777. if (common->channel_width)
  778. common->endpoint = EP_5GHZ_40MHZ;
  779. else
  780. common->endpoint = EP_5GHZ_20MHZ;
  781. }
  782. if (common->endpoint != prev_ep) {
  783. status = rsi_program_bb_rf(common);
  784. if (status)
  785. return status;
  786. }
  787. if (common->channel_width != prev_bw) {
  788. status = rsi_load_bootup_params(common);
  789. if (status)
  790. return status;
  791. status = rsi_load_radio_caps(common);
  792. if (status)
  793. return status;
  794. }
  795. return status;
  796. }
  797. /**
  798. * rsi_set_channel() - This function programs the channel.
  799. * @common: Pointer to the driver private structure.
  800. * @channel: Channel value to be set.
  801. *
  802. * Return: 0 on success, corresponding error code on failure.
  803. */
  804. int rsi_set_channel(struct rsi_common *common, u16 channel)
  805. {
  806. struct sk_buff *skb = NULL;
  807. struct rsi_mac_frame *mgmt_frame;
  808. rsi_dbg(MGMT_TX_ZONE,
  809. "%s: Sending scan req frame\n", __func__);
  810. skb = dev_alloc_skb(FRAME_DESC_SZ);
  811. if (!skb) {
  812. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  813. __func__);
  814. return -ENOMEM;
  815. }
  816. memset(skb->data, 0, FRAME_DESC_SZ);
  817. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  818. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  819. mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
  820. mgmt_frame->desc_word[4] = cpu_to_le16(channel);
  821. mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
  822. BBP_REG_WRITE |
  823. (RSI_RF_TYPE << 4));
  824. mgmt_frame->desc_word[5] = cpu_to_le16(0x01);
  825. mgmt_frame->desc_word[6] = cpu_to_le16(0x12);
  826. if (common->channel_width == BW_40MHZ)
  827. mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
  828. common->channel = channel;
  829. skb_put(skb, FRAME_DESC_SZ);
  830. return rsi_send_internal_mgmt_frame(common, skb);
  831. }
  832. /**
  833. * rsi_compare() - This function is used to compare two integers
  834. * @a: pointer to the first integer
  835. * @b: pointer to the second integer
  836. *
  837. * Return: 0 if both are equal, -1 if the first is smaller, else 1
  838. */
  839. static int rsi_compare(const void *a, const void *b)
  840. {
  841. u16 _a = *(const u16 *)(a);
  842. u16 _b = *(const u16 *)(b);
  843. if (_a > _b)
  844. return -1;
  845. if (_a < _b)
  846. return 1;
  847. return 0;
  848. }
  849. /**
  850. * rsi_map_rates() - This function is used to map selected rates to hw rates.
  851. * @rate: The standard rate to be mapped.
  852. * @offset: Offset that will be returned.
  853. *
  854. * Return: 0 if it is a mcs rate, else 1
  855. */
  856. static bool rsi_map_rates(u16 rate, int *offset)
  857. {
  858. int kk;
  859. for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
  860. if (rate == mcs[kk]) {
  861. *offset = kk;
  862. return false;
  863. }
  864. }
  865. for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
  866. if (rate == rsi_rates[kk].bitrate / 5) {
  867. *offset = kk;
  868. break;
  869. }
  870. }
  871. return true;
  872. }
  873. /**
  874. * rsi_send_auto_rate_request() - This function is to set rates for connection
  875. * and send autorate request to firmware.
  876. * @common: Pointer to the driver private structure.
  877. *
  878. * Return: 0 on success, corresponding error code on failure.
  879. */
  880. static int rsi_send_auto_rate_request(struct rsi_common *common)
  881. {
  882. struct sk_buff *skb;
  883. struct rsi_auto_rate *auto_rate;
  884. int ii = 0, jj = 0, kk = 0;
  885. struct ieee80211_hw *hw = common->priv->hw;
  886. u8 band = hw->conf.chandef.chan->band;
  887. u8 num_supported_rates = 0;
  888. u8 rate_table_offset, rate_offset = 0;
  889. u32 rate_bitmap = common->bitrate_mask[band];
  890. u16 *selected_rates, min_rate;
  891. skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
  892. if (!skb) {
  893. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  894. __func__);
  895. return -ENOMEM;
  896. }
  897. selected_rates = kzalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
  898. if (!selected_rates) {
  899. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
  900. __func__);
  901. dev_kfree_skb(skb);
  902. return -ENOMEM;
  903. }
  904. memset(skb->data, 0, sizeof(struct rsi_auto_rate));
  905. auto_rate = (struct rsi_auto_rate *)skb->data;
  906. auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
  907. auto_rate->collision_tolerance = cpu_to_le16(3);
  908. auto_rate->failure_limit = cpu_to_le16(3);
  909. auto_rate->initial_boundary = cpu_to_le16(3);
  910. auto_rate->max_threshold_limt = cpu_to_le16(27);
  911. auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
  912. if (common->channel_width == BW_40MHZ)
  913. auto_rate->desc_word[7] |= cpu_to_le16(1);
  914. if (band == NL80211_BAND_2GHZ) {
  915. min_rate = RSI_RATE_1;
  916. rate_table_offset = 0;
  917. } else {
  918. min_rate = RSI_RATE_6;
  919. rate_table_offset = 4;
  920. }
  921. for (ii = 0, jj = 0;
  922. ii < (ARRAY_SIZE(rsi_rates) - rate_table_offset); ii++) {
  923. if (rate_bitmap & BIT(ii)) {
  924. selected_rates[jj++] =
  925. (rsi_rates[ii + rate_table_offset].bitrate / 5);
  926. rate_offset++;
  927. }
  928. }
  929. num_supported_rates = jj;
  930. if (common->vif_info[0].is_ht) {
  931. for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
  932. selected_rates[jj++] = mcs[ii];
  933. num_supported_rates += ARRAY_SIZE(mcs);
  934. rate_offset += ARRAY_SIZE(mcs);
  935. }
  936. sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
  937. /* mapping the rates to RSI rates */
  938. for (ii = 0; ii < jj; ii++) {
  939. if (rsi_map_rates(selected_rates[ii], &kk)) {
  940. auto_rate->supported_rates[ii] =
  941. cpu_to_le16(rsi_rates[kk].hw_value);
  942. } else {
  943. auto_rate->supported_rates[ii] =
  944. cpu_to_le16(rsi_mcsrates[kk]);
  945. }
  946. }
  947. /* loading HT rates in the bottom half of the auto rate table */
  948. if (common->vif_info[0].is_ht) {
  949. for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
  950. ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
  951. if (common->vif_info[0].sgi ||
  952. conf_is_ht40(&common->priv->hw->conf))
  953. auto_rate->supported_rates[ii++] =
  954. cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
  955. auto_rate->supported_rates[ii] =
  956. cpu_to_le16(rsi_mcsrates[kk--]);
  957. }
  958. for (; ii < (RSI_TBL_SZ - 1); ii++) {
  959. auto_rate->supported_rates[ii] =
  960. cpu_to_le16(rsi_mcsrates[0]);
  961. }
  962. }
  963. for (; ii < RSI_TBL_SZ; ii++)
  964. auto_rate->supported_rates[ii] = cpu_to_le16(min_rate);
  965. auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
  966. auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
  967. auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
  968. num_supported_rates *= 2;
  969. auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
  970. FRAME_DESC_SZ) |
  971. (RSI_WIFI_MGMT_Q << 12));
  972. skb_put(skb,
  973. sizeof(struct rsi_auto_rate));
  974. kfree(selected_rates);
  975. return rsi_send_internal_mgmt_frame(common, skb);
  976. }
  977. /**
  978. * rsi_inform_bss_status() - This function informs about bss status with the
  979. * help of sta notify params by sending an internal
  980. * management frame to firmware.
  981. * @common: Pointer to the driver private structure.
  982. * @status: Bss status type.
  983. * @bssid: Bssid.
  984. * @qos_enable: Qos is enabled.
  985. * @aid: Aid (unique for all STAs).
  986. *
  987. * Return: None.
  988. */
  989. void rsi_inform_bss_status(struct rsi_common *common,
  990. u8 status,
  991. const unsigned char *bssid,
  992. u8 qos_enable,
  993. u16 aid)
  994. {
  995. if (status) {
  996. rsi_hal_send_sta_notify_frame(common,
  997. RSI_IFTYPE_STATION,
  998. STA_CONNECTED,
  999. bssid,
  1000. qos_enable,
  1001. aid);
  1002. if (common->min_rate == 0xffff)
  1003. rsi_send_auto_rate_request(common);
  1004. } else {
  1005. rsi_hal_send_sta_notify_frame(common,
  1006. RSI_IFTYPE_STATION,
  1007. STA_DISCONNECTED,
  1008. bssid,
  1009. qos_enable,
  1010. aid);
  1011. }
  1012. }
  1013. /**
  1014. * rsi_eeprom_read() - This function sends a frame to read the mac address
  1015. * from the eeprom.
  1016. * @common: Pointer to the driver private structure.
  1017. *
  1018. * Return: 0 on success, -1 on failure.
  1019. */
  1020. static int rsi_eeprom_read(struct rsi_common *common)
  1021. {
  1022. struct rsi_mac_frame *mgmt_frame;
  1023. struct sk_buff *skb;
  1024. rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
  1025. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1026. if (!skb) {
  1027. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1028. __func__);
  1029. return -ENOMEM;
  1030. }
  1031. memset(skb->data, 0, FRAME_DESC_SZ);
  1032. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  1033. /* FrameType */
  1034. mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
  1035. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1036. /* Number of bytes to read */
  1037. mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
  1038. WLAN_MAC_MAGIC_WORD_LEN +
  1039. WLAN_HOST_MODE_LEN +
  1040. WLAN_FW_VERSION_LEN);
  1041. /* Address to read */
  1042. mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
  1043. skb_put(skb, FRAME_DESC_SZ);
  1044. return rsi_send_internal_mgmt_frame(common, skb);
  1045. }
  1046. /**
  1047. * This function sends a frame to block/unblock
  1048. * data queues in the firmware
  1049. *
  1050. * @param common Pointer to the driver private structure.
  1051. * @param block event - block if true, unblock if false
  1052. * @return 0 on success, -1 on failure.
  1053. */
  1054. int rsi_send_block_unblock_frame(struct rsi_common *common, bool block_event)
  1055. {
  1056. struct rsi_mac_frame *mgmt_frame;
  1057. struct sk_buff *skb;
  1058. rsi_dbg(MGMT_TX_ZONE, "%s: Sending block/unblock frame\n", __func__);
  1059. skb = dev_alloc_skb(FRAME_DESC_SZ);
  1060. if (!skb) {
  1061. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  1062. __func__);
  1063. return -ENOMEM;
  1064. }
  1065. memset(skb->data, 0, FRAME_DESC_SZ);
  1066. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  1067. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  1068. mgmt_frame->desc_word[1] = cpu_to_le16(BLOCK_HW_QUEUE);
  1069. if (block_event) {
  1070. rsi_dbg(INFO_ZONE, "blocking the data qs\n");
  1071. mgmt_frame->desc_word[4] = cpu_to_le16(0xf);
  1072. } else {
  1073. rsi_dbg(INFO_ZONE, "unblocking the data qs\n");
  1074. mgmt_frame->desc_word[5] = cpu_to_le16(0xf);
  1075. }
  1076. skb_put(skb, FRAME_DESC_SZ);
  1077. return rsi_send_internal_mgmt_frame(common, skb);
  1078. }
  1079. /**
  1080. * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
  1081. * @common: Pointer to the driver private structure.
  1082. * @msg: Pointer to received packet.
  1083. *
  1084. * Return: 0 on success, -1 on failure.
  1085. */
  1086. static int rsi_handle_ta_confirm_type(struct rsi_common *common,
  1087. u8 *msg)
  1088. {
  1089. u8 sub_type = (msg[15] & 0xff);
  1090. switch (sub_type) {
  1091. case BOOTUP_PARAMS_REQUEST:
  1092. rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
  1093. __func__);
  1094. if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
  1095. if (rsi_eeprom_read(common)) {
  1096. common->fsm_state = FSM_CARD_NOT_READY;
  1097. goto out;
  1098. } else {
  1099. common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
  1100. }
  1101. } else {
  1102. rsi_dbg(INFO_ZONE,
  1103. "%s: Received bootup params cfm in %d state\n",
  1104. __func__, common->fsm_state);
  1105. return 0;
  1106. }
  1107. break;
  1108. case EEPROM_READ_TYPE:
  1109. if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
  1110. if (msg[16] == MAGIC_WORD) {
  1111. u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
  1112. + WLAN_MAC_MAGIC_WORD_LEN);
  1113. memcpy(common->mac_addr,
  1114. &msg[offset],
  1115. ETH_ALEN);
  1116. memcpy(&common->fw_ver,
  1117. &msg[offset + ETH_ALEN],
  1118. sizeof(struct version_info));
  1119. } else {
  1120. common->fsm_state = FSM_CARD_NOT_READY;
  1121. break;
  1122. }
  1123. if (rsi_send_reset_mac(common))
  1124. goto out;
  1125. else
  1126. common->fsm_state = FSM_RESET_MAC_SENT;
  1127. } else {
  1128. rsi_dbg(ERR_ZONE,
  1129. "%s: Received eeprom mac addr in %d state\n",
  1130. __func__, common->fsm_state);
  1131. return 0;
  1132. }
  1133. break;
  1134. case RESET_MAC_REQ:
  1135. if (common->fsm_state == FSM_RESET_MAC_SENT) {
  1136. rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
  1137. __func__);
  1138. if (rsi_load_radio_caps(common))
  1139. goto out;
  1140. else
  1141. common->fsm_state = FSM_RADIO_CAPS_SENT;
  1142. } else {
  1143. rsi_dbg(ERR_ZONE,
  1144. "%s: Received reset mac cfm in %d state\n",
  1145. __func__, common->fsm_state);
  1146. return 0;
  1147. }
  1148. break;
  1149. case RADIO_CAPABILITIES:
  1150. if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
  1151. common->rf_reset = 1;
  1152. if (rsi_program_bb_rf(common)) {
  1153. goto out;
  1154. } else {
  1155. common->fsm_state = FSM_BB_RF_PROG_SENT;
  1156. rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
  1157. __func__);
  1158. }
  1159. } else {
  1160. rsi_dbg(INFO_ZONE,
  1161. "%s: Received radio caps cfm in %d state\n",
  1162. __func__, common->fsm_state);
  1163. return 0;
  1164. }
  1165. break;
  1166. case BB_PROG_VALUES_REQUEST:
  1167. case RF_PROG_VALUES_REQUEST:
  1168. case BBP_PROG_IN_TA:
  1169. rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
  1170. if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
  1171. common->bb_rf_prog_count--;
  1172. if (!common->bb_rf_prog_count) {
  1173. common->fsm_state = FSM_MAC_INIT_DONE;
  1174. return rsi_mac80211_attach(common);
  1175. }
  1176. } else {
  1177. rsi_dbg(INFO_ZONE,
  1178. "%s: Received bbb_rf cfm in %d state\n",
  1179. __func__, common->fsm_state);
  1180. return 0;
  1181. }
  1182. break;
  1183. default:
  1184. rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
  1185. __func__);
  1186. break;
  1187. }
  1188. return 0;
  1189. out:
  1190. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
  1191. __func__);
  1192. return -EINVAL;
  1193. }
  1194. /**
  1195. * rsi_mgmt_pkt_recv() - This function processes the management packets
  1196. * recieved from the hardware.
  1197. * @common: Pointer to the driver private structure.
  1198. * @msg: Pointer to the received packet.
  1199. *
  1200. * Return: 0 on success, -1 on failure.
  1201. */
  1202. int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
  1203. {
  1204. s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
  1205. u16 msg_type = (msg[2]);
  1206. int ret;
  1207. rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
  1208. __func__, msg_len, msg_type);
  1209. if (msg_type == TA_CONFIRM_TYPE) {
  1210. return rsi_handle_ta_confirm_type(common, msg);
  1211. } else if (msg_type == CARD_READY_IND) {
  1212. rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
  1213. __func__);
  1214. if (common->fsm_state == FSM_CARD_NOT_READY) {
  1215. rsi_set_default_parameters(common);
  1216. ret = rsi_load_bootup_params(common);
  1217. if (ret)
  1218. return ret;
  1219. else
  1220. common->fsm_state = FSM_BOOT_PARAMS_SENT;
  1221. } else {
  1222. return -EINVAL;
  1223. }
  1224. } else if (msg_type == TX_STATUS_IND) {
  1225. if (msg[15] == PROBEREQ_CONFIRM) {
  1226. common->mgmt_q_block = false;
  1227. rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
  1228. __func__);
  1229. }
  1230. } else {
  1231. return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);
  1232. }
  1233. return 0;
  1234. }