rsi_91x_mgmt.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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 = IEEE80211_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. }
  216. /**
  217. * rsi_set_contention_vals() - This function sets the contention values for the
  218. * backoff procedure.
  219. * @common: Pointer to the driver private structure.
  220. *
  221. * Return: None.
  222. */
  223. static void rsi_set_contention_vals(struct rsi_common *common)
  224. {
  225. u8 ii = 0;
  226. for (; ii < NUM_EDCA_QUEUES; ii++) {
  227. common->tx_qinfo[ii].wme_params =
  228. (((common->edca_params[ii].cw_min / 2) +
  229. (common->edca_params[ii].aifs)) *
  230. WMM_SHORT_SLOT_TIME + SIFS_DURATION);
  231. common->tx_qinfo[ii].weight = common->tx_qinfo[ii].wme_params;
  232. common->tx_qinfo[ii].pkt_contended = 0;
  233. }
  234. }
  235. /**
  236. * rsi_send_internal_mgmt_frame() - This function sends management frames to
  237. * firmware.Also schedules packet to queue
  238. * for transmission.
  239. * @common: Pointer to the driver private structure.
  240. * @skb: Pointer to the socket buffer structure.
  241. *
  242. * Return: 0 on success, -1 on failure.
  243. */
  244. static int rsi_send_internal_mgmt_frame(struct rsi_common *common,
  245. struct sk_buff *skb)
  246. {
  247. struct skb_info *tx_params;
  248. if (skb == NULL) {
  249. rsi_dbg(ERR_ZONE, "%s: Unable to allocate skb\n", __func__);
  250. return -ENOMEM;
  251. }
  252. tx_params = (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
  253. tx_params->flags |= INTERNAL_MGMT_PKT;
  254. skb_queue_tail(&common->tx_queue[MGMT_SOFT_Q], skb);
  255. rsi_set_event(&common->tx_thread.event);
  256. return 0;
  257. }
  258. /**
  259. * rsi_load_radio_caps() - This function is used to send radio capabilities
  260. * values to firmware.
  261. * @common: Pointer to the driver private structure.
  262. *
  263. * Return: 0 on success, corresponding negative error code on failure.
  264. */
  265. static int rsi_load_radio_caps(struct rsi_common *common)
  266. {
  267. struct rsi_radio_caps *radio_caps;
  268. struct rsi_hw *adapter = common->priv;
  269. struct ieee80211_hw *hw = adapter->hw;
  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 ieee80211_conf *conf = &hw->conf;
  279. struct sk_buff *skb;
  280. rsi_dbg(INFO_ZONE, "%s: Sending rate symbol req frame\n", __func__);
  281. skb = dev_alloc_skb(sizeof(struct rsi_radio_caps));
  282. if (!skb) {
  283. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  284. __func__);
  285. return -ENOMEM;
  286. }
  287. memset(skb->data, 0, sizeof(struct rsi_radio_caps));
  288. radio_caps = (struct rsi_radio_caps *)skb->data;
  289. radio_caps->desc_word[1] = cpu_to_le16(RADIO_CAPABILITIES);
  290. radio_caps->desc_word[4] = cpu_to_le16(RSI_RF_TYPE << 8);
  291. if (common->channel_width == BW_40MHZ) {
  292. radio_caps->desc_word[7] |= cpu_to_le16(RSI_LMAC_CLOCK_80MHZ);
  293. radio_caps->desc_word[7] |= cpu_to_le16(RSI_ENABLE_40MHZ);
  294. if (common->channel_width) {
  295. radio_caps->desc_word[5] =
  296. cpu_to_le16(common->channel_width << 12);
  297. radio_caps->desc_word[5] |= cpu_to_le16(FULL40M_ENABLE);
  298. }
  299. if (conf_is_ht40_minus(conf)) {
  300. radio_caps->desc_word[5] = 0;
  301. radio_caps->desc_word[5] |=
  302. cpu_to_le16(LOWER_20_ENABLE);
  303. radio_caps->desc_word[5] |=
  304. cpu_to_le16(LOWER_20_ENABLE >> 12);
  305. }
  306. if (conf_is_ht40_plus(conf)) {
  307. radio_caps->desc_word[5] = 0;
  308. radio_caps->desc_word[5] |=
  309. cpu_to_le16(UPPER_20_ENABLE);
  310. radio_caps->desc_word[5] |=
  311. cpu_to_le16(UPPER_20_ENABLE >> 12);
  312. }
  313. }
  314. radio_caps->desc_word[7] |= cpu_to_le16(radio_id << 8);
  315. for (ii = 0; ii < MAX_HW_QUEUES; ii++) {
  316. radio_caps->qos_params[ii].cont_win_min_q = cpu_to_le16(3);
  317. radio_caps->qos_params[ii].cont_win_max_q = cpu_to_le16(0x3f);
  318. radio_caps->qos_params[ii].aifsn_val_q = cpu_to_le16(2);
  319. radio_caps->qos_params[ii].txop_q = 0;
  320. }
  321. for (ii = 0; ii < MAX_HW_QUEUES - 4; ii++) {
  322. radio_caps->qos_params[ii].cont_win_min_q =
  323. cpu_to_le16(common->edca_params[ii].cw_min);
  324. radio_caps->qos_params[ii].cont_win_max_q =
  325. cpu_to_le16(common->edca_params[ii].cw_max);
  326. radio_caps->qos_params[ii].aifsn_val_q =
  327. cpu_to_le16((common->edca_params[ii].aifs) << 8);
  328. radio_caps->qos_params[ii].txop_q =
  329. cpu_to_le16(common->edca_params[ii].txop);
  330. }
  331. memcpy(&common->rate_pwr[0], &gc[0], 40);
  332. for (ii = 0; ii < 20; ii++)
  333. radio_caps->gcpd_per_rate[inx++] =
  334. cpu_to_le16(common->rate_pwr[ii] & 0x00FF);
  335. radio_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_radio_caps) -
  336. FRAME_DESC_SZ) |
  337. (RSI_WIFI_MGMT_Q << 12));
  338. skb_put(skb, (sizeof(struct rsi_radio_caps)));
  339. return rsi_send_internal_mgmt_frame(common, skb);
  340. }
  341. /**
  342. * rsi_mgmt_pkt_to_core() - This function is the entry point for Mgmt module.
  343. * @common: Pointer to the driver private structure.
  344. * @msg: Pointer to received packet.
  345. * @msg_len: Length of the recieved packet.
  346. * @type: Type of recieved packet.
  347. *
  348. * Return: 0 on success, -1 on failure.
  349. */
  350. static int rsi_mgmt_pkt_to_core(struct rsi_common *common,
  351. u8 *msg,
  352. s32 msg_len,
  353. u8 type)
  354. {
  355. struct rsi_hw *adapter = common->priv;
  356. struct ieee80211_tx_info *info;
  357. struct skb_info *rx_params;
  358. u8 pad_bytes = msg[4];
  359. u8 pkt_recv;
  360. struct sk_buff *skb;
  361. char *buffer;
  362. if (type == RX_DOT11_MGMT) {
  363. if (!adapter->sc_nvifs)
  364. return -ENOLINK;
  365. msg_len -= pad_bytes;
  366. if ((msg_len <= 0) || (!msg)) {
  367. rsi_dbg(MGMT_RX_ZONE,
  368. "%s: Invalid rx msg of len = %d\n",
  369. __func__, msg_len);
  370. return -EINVAL;
  371. }
  372. skb = dev_alloc_skb(msg_len);
  373. if (!skb) {
  374. rsi_dbg(ERR_ZONE, "%s: Failed to allocate skb\n",
  375. __func__);
  376. return -ENOMEM;
  377. }
  378. buffer = skb_put(skb, msg_len);
  379. memcpy(buffer,
  380. (u8 *)(msg + FRAME_DESC_SZ + pad_bytes),
  381. msg_len);
  382. pkt_recv = buffer[0];
  383. info = IEEE80211_SKB_CB(skb);
  384. rx_params = (struct skb_info *)info->driver_data;
  385. rx_params->rssi = rsi_get_rssi(msg);
  386. rx_params->channel = rsi_get_channel(msg);
  387. rsi_indicate_pkt_to_os(common, skb);
  388. } else {
  389. rsi_dbg(MGMT_TX_ZONE, "%s: Internal Packet\n", __func__);
  390. }
  391. return 0;
  392. }
  393. /**
  394. * rsi_hal_send_sta_notify_frame() - This function sends the station notify
  395. * frame to firmware.
  396. * @common: Pointer to the driver private structure.
  397. * @opmode: Operating mode of device.
  398. * @notify_event: Notification about station connection.
  399. * @bssid: bssid.
  400. * @qos_enable: Qos is enabled.
  401. * @aid: Aid (unique for all STA).
  402. *
  403. * Return: status: 0 on success, corresponding negative error code on failure.
  404. */
  405. static int rsi_hal_send_sta_notify_frame(struct rsi_common *common,
  406. u8 opmode,
  407. u8 notify_event,
  408. const unsigned char *bssid,
  409. u8 qos_enable,
  410. u16 aid)
  411. {
  412. struct sk_buff *skb = NULL;
  413. struct rsi_peer_notify *peer_notify;
  414. u16 vap_id = 0;
  415. int status;
  416. rsi_dbg(MGMT_TX_ZONE, "%s: Sending sta notify frame\n", __func__);
  417. skb = dev_alloc_skb(sizeof(struct rsi_peer_notify));
  418. if (!skb) {
  419. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  420. __func__);
  421. return -ENOMEM;
  422. }
  423. memset(skb->data, 0, sizeof(struct rsi_peer_notify));
  424. peer_notify = (struct rsi_peer_notify *)skb->data;
  425. peer_notify->command = cpu_to_le16(opmode << 1);
  426. switch (notify_event) {
  427. case STA_CONNECTED:
  428. peer_notify->command |= cpu_to_le16(RSI_ADD_PEER);
  429. break;
  430. case STA_DISCONNECTED:
  431. peer_notify->command |= cpu_to_le16(RSI_DELETE_PEER);
  432. break;
  433. default:
  434. break;
  435. }
  436. peer_notify->command |= cpu_to_le16((aid & 0xfff) << 4);
  437. ether_addr_copy(peer_notify->mac_addr, bssid);
  438. peer_notify->sta_flags = cpu_to_le32((qos_enable) ? 1 : 0);
  439. peer_notify->desc_word[0] =
  440. cpu_to_le16((sizeof(struct rsi_peer_notify) - FRAME_DESC_SZ) |
  441. (RSI_WIFI_MGMT_Q << 12));
  442. peer_notify->desc_word[1] = cpu_to_le16(PEER_NOTIFY);
  443. peer_notify->desc_word[7] |= cpu_to_le16(vap_id << 8);
  444. skb_put(skb, sizeof(struct rsi_peer_notify));
  445. status = rsi_send_internal_mgmt_frame(common, skb);
  446. if (!status && qos_enable) {
  447. rsi_set_contention_vals(common);
  448. status = rsi_load_radio_caps(common);
  449. }
  450. return status;
  451. }
  452. /**
  453. * rsi_send_aggregation_params_frame() - This function sends the ampdu
  454. * indication frame to firmware.
  455. * @common: Pointer to the driver private structure.
  456. * @tid: traffic identifier.
  457. * @ssn: ssn.
  458. * @buf_size: buffer size.
  459. * @event: notification about station connection.
  460. *
  461. * Return: 0 on success, corresponding negative error code on failure.
  462. */
  463. int rsi_send_aggregation_params_frame(struct rsi_common *common,
  464. u16 tid,
  465. u16 ssn,
  466. u8 buf_size,
  467. u8 event)
  468. {
  469. struct sk_buff *skb = NULL;
  470. struct rsi_mac_frame *mgmt_frame;
  471. u8 peer_id = 0;
  472. skb = dev_alloc_skb(FRAME_DESC_SZ);
  473. if (!skb) {
  474. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  475. __func__);
  476. return -ENOMEM;
  477. }
  478. memset(skb->data, 0, FRAME_DESC_SZ);
  479. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  480. rsi_dbg(MGMT_TX_ZONE, "%s: Sending AMPDU indication frame\n", __func__);
  481. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  482. mgmt_frame->desc_word[1] = cpu_to_le16(AMPDU_IND);
  483. if (event == STA_TX_ADDBA_DONE) {
  484. mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
  485. mgmt_frame->desc_word[5] = cpu_to_le16(buf_size);
  486. mgmt_frame->desc_word[7] =
  487. cpu_to_le16((tid | (START_AMPDU_AGGR << 4) | (peer_id << 8)));
  488. } else if (event == STA_RX_ADDBA_DONE) {
  489. mgmt_frame->desc_word[4] = cpu_to_le16(ssn);
  490. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  491. (START_AMPDU_AGGR << 4) |
  492. (RX_BA_INDICATION << 5) |
  493. (peer_id << 8));
  494. } else if (event == STA_TX_DELBA) {
  495. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  496. (STOP_AMPDU_AGGR << 4) |
  497. (peer_id << 8));
  498. } else if (event == STA_RX_DELBA) {
  499. mgmt_frame->desc_word[7] = cpu_to_le16(tid |
  500. (STOP_AMPDU_AGGR << 4) |
  501. (RX_BA_INDICATION << 5) |
  502. (peer_id << 8));
  503. }
  504. skb_put(skb, FRAME_DESC_SZ);
  505. return rsi_send_internal_mgmt_frame(common, skb);
  506. }
  507. /**
  508. * rsi_program_bb_rf() - This function starts base band and RF programming.
  509. * This is called after initial configurations are done.
  510. * @common: Pointer to the driver private structure.
  511. *
  512. * Return: 0 on success, corresponding negative error code on failure.
  513. */
  514. static int rsi_program_bb_rf(struct rsi_common *common)
  515. {
  516. struct sk_buff *skb;
  517. struct rsi_mac_frame *mgmt_frame;
  518. rsi_dbg(MGMT_TX_ZONE, "%s: Sending program BB/RF frame\n", __func__);
  519. skb = dev_alloc_skb(FRAME_DESC_SZ);
  520. if (!skb) {
  521. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  522. __func__);
  523. return -ENOMEM;
  524. }
  525. memset(skb->data, 0, FRAME_DESC_SZ);
  526. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  527. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  528. mgmt_frame->desc_word[1] = cpu_to_le16(BBP_PROG_IN_TA);
  529. mgmt_frame->desc_word[4] = cpu_to_le16(common->endpoint << 8);
  530. if (common->rf_reset) {
  531. mgmt_frame->desc_word[7] = cpu_to_le16(RF_RESET_ENABLE);
  532. rsi_dbg(MGMT_TX_ZONE, "%s: ===> RF RESET REQUEST SENT <===\n",
  533. __func__);
  534. common->rf_reset = 0;
  535. }
  536. common->bb_rf_prog_count = 1;
  537. mgmt_frame->desc_word[7] |= cpu_to_le16(PUT_BBP_RESET |
  538. BBP_REG_WRITE | (RSI_RF_TYPE << 4));
  539. skb_put(skb, FRAME_DESC_SZ);
  540. return rsi_send_internal_mgmt_frame(common, skb);
  541. }
  542. /**
  543. * rsi_set_vap_capabilities() - This function send vap capability to firmware.
  544. * @common: Pointer to the driver private structure.
  545. * @opmode: Operating mode of device.
  546. *
  547. * Return: 0 on success, corresponding negative error code on failure.
  548. */
  549. int rsi_set_vap_capabilities(struct rsi_common *common, enum opmode mode)
  550. {
  551. struct sk_buff *skb = NULL;
  552. struct rsi_vap_caps *vap_caps;
  553. u16 vap_id = 0;
  554. rsi_dbg(MGMT_TX_ZONE, "%s: Sending VAP capabilities frame\n", __func__);
  555. skb = dev_alloc_skb(sizeof(struct rsi_vap_caps));
  556. if (!skb) {
  557. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  558. __func__);
  559. return -ENOMEM;
  560. }
  561. memset(skb->data, 0, sizeof(struct rsi_vap_caps));
  562. vap_caps = (struct rsi_vap_caps *)skb->data;
  563. vap_caps->desc_word[0] = cpu_to_le16((sizeof(struct rsi_vap_caps) -
  564. FRAME_DESC_SZ) |
  565. (RSI_WIFI_MGMT_Q << 12));
  566. vap_caps->desc_word[1] = cpu_to_le16(VAP_CAPABILITIES);
  567. vap_caps->desc_word[4] = cpu_to_le16(mode |
  568. (common->channel_width << 8));
  569. vap_caps->desc_word[7] = cpu_to_le16((vap_id << 8) |
  570. (common->mac_id << 4) |
  571. common->radio_id);
  572. memcpy(vap_caps->mac_addr, common->mac_addr, IEEE80211_ADDR_LEN);
  573. vap_caps->keep_alive_period = cpu_to_le16(90);
  574. vap_caps->frag_threshold = cpu_to_le16(IEEE80211_MAX_FRAG_THRESHOLD);
  575. vap_caps->rts_threshold = cpu_to_le16(common->rts_threshold);
  576. vap_caps->default_mgmt_rate = 0;
  577. if (conf_is_ht40(&common->priv->hw->conf)) {
  578. vap_caps->default_ctrl_rate =
  579. cpu_to_le32(RSI_RATE_6 | FULL40M_ENABLE << 16);
  580. } else {
  581. vap_caps->default_ctrl_rate = cpu_to_le32(RSI_RATE_6);
  582. }
  583. vap_caps->default_data_rate = 0;
  584. vap_caps->beacon_interval = cpu_to_le16(200);
  585. vap_caps->dtim_period = cpu_to_le16(4);
  586. skb_put(skb, sizeof(*vap_caps));
  587. return rsi_send_internal_mgmt_frame(common, skb);
  588. }
  589. /**
  590. * rsi_hal_load_key() - This function is used to load keys within the firmware.
  591. * @common: Pointer to the driver private structure.
  592. * @data: Pointer to the key data.
  593. * @key_len: Key length to be loaded.
  594. * @key_type: Type of key: GROUP/PAIRWISE.
  595. * @key_id: Key index.
  596. * @cipher: Type of cipher used.
  597. *
  598. * Return: 0 on success, -1 on failure.
  599. */
  600. int rsi_hal_load_key(struct rsi_common *common,
  601. u8 *data,
  602. u16 key_len,
  603. u8 key_type,
  604. u8 key_id,
  605. u32 cipher)
  606. {
  607. struct sk_buff *skb = NULL;
  608. struct rsi_set_key *set_key;
  609. u16 key_descriptor = 0;
  610. rsi_dbg(MGMT_TX_ZONE, "%s: Sending load key frame\n", __func__);
  611. skb = dev_alloc_skb(sizeof(struct rsi_set_key));
  612. if (!skb) {
  613. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  614. __func__);
  615. return -ENOMEM;
  616. }
  617. memset(skb->data, 0, sizeof(struct rsi_set_key));
  618. set_key = (struct rsi_set_key *)skb->data;
  619. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  620. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  621. key_len += 1;
  622. key_descriptor |= BIT(2);
  623. if (key_len >= 13)
  624. key_descriptor |= BIT(3);
  625. } else if (cipher != KEY_TYPE_CLEAR) {
  626. key_descriptor |= BIT(4);
  627. if (key_type == RSI_PAIRWISE_KEY)
  628. key_id = 0;
  629. if (cipher == WLAN_CIPHER_SUITE_TKIP)
  630. key_descriptor |= BIT(5);
  631. }
  632. key_descriptor |= (key_type | BIT(13) | (key_id << 14));
  633. set_key->desc_word[0] = cpu_to_le16((sizeof(struct rsi_set_key) -
  634. FRAME_DESC_SZ) |
  635. (RSI_WIFI_MGMT_Q << 12));
  636. set_key->desc_word[1] = cpu_to_le16(SET_KEY_REQ);
  637. set_key->desc_word[4] = cpu_to_le16(key_descriptor);
  638. if ((cipher == WLAN_CIPHER_SUITE_WEP40) ||
  639. (cipher == WLAN_CIPHER_SUITE_WEP104)) {
  640. memcpy(&set_key->key[key_id][1],
  641. data,
  642. key_len * 2);
  643. } else {
  644. memcpy(&set_key->key[0][0], data, key_len);
  645. }
  646. memcpy(set_key->tx_mic_key, &data[16], 8);
  647. memcpy(set_key->rx_mic_key, &data[24], 8);
  648. skb_put(skb, sizeof(struct rsi_set_key));
  649. return rsi_send_internal_mgmt_frame(common, skb);
  650. }
  651. /*
  652. * rsi_load_bootup_params() - This function send bootup params to the firmware.
  653. * @common: Pointer to the driver private structure.
  654. *
  655. * Return: 0 on success, corresponding error code on failure.
  656. */
  657. static int rsi_load_bootup_params(struct rsi_common *common)
  658. {
  659. struct sk_buff *skb;
  660. struct rsi_boot_params *boot_params;
  661. rsi_dbg(MGMT_TX_ZONE, "%s: Sending boot params frame\n", __func__);
  662. skb = dev_alloc_skb(sizeof(struct rsi_boot_params));
  663. if (!skb) {
  664. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  665. __func__);
  666. return -ENOMEM;
  667. }
  668. memset(skb->data, 0, sizeof(struct rsi_boot_params));
  669. boot_params = (struct rsi_boot_params *)skb->data;
  670. rsi_dbg(MGMT_TX_ZONE, "%s:\n", __func__);
  671. if (common->channel_width == BW_40MHZ) {
  672. memcpy(&boot_params->bootup_params,
  673. &boot_params_40,
  674. sizeof(struct bootup_params));
  675. rsi_dbg(MGMT_TX_ZONE, "%s: Packet 40MHZ <=== %d\n", __func__,
  676. UMAC_CLK_40BW);
  677. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40BW);
  678. } else {
  679. memcpy(&boot_params->bootup_params,
  680. &boot_params_20,
  681. sizeof(struct bootup_params));
  682. if (boot_params_20.valid != cpu_to_le32(VALID_20)) {
  683. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_20BW);
  684. rsi_dbg(MGMT_TX_ZONE,
  685. "%s: Packet 20MHZ <=== %d\n", __func__,
  686. UMAC_CLK_20BW);
  687. } else {
  688. boot_params->desc_word[7] = cpu_to_le16(UMAC_CLK_40MHZ);
  689. rsi_dbg(MGMT_TX_ZONE,
  690. "%s: Packet 20MHZ <=== %d\n", __func__,
  691. UMAC_CLK_40MHZ);
  692. }
  693. }
  694. /**
  695. * Bit{0:11} indicates length of the Packet
  696. * Bit{12:15} indicates host queue number
  697. */
  698. boot_params->desc_word[0] = cpu_to_le16(sizeof(struct bootup_params) |
  699. (RSI_WIFI_MGMT_Q << 12));
  700. boot_params->desc_word[1] = cpu_to_le16(BOOTUP_PARAMS_REQUEST);
  701. skb_put(skb, sizeof(struct rsi_boot_params));
  702. return rsi_send_internal_mgmt_frame(common, skb);
  703. }
  704. /**
  705. * rsi_send_reset_mac() - This function prepares reset MAC request and sends an
  706. * internal management frame to indicate it to firmware.
  707. * @common: Pointer to the driver private structure.
  708. *
  709. * Return: 0 on success, corresponding error code on failure.
  710. */
  711. static int rsi_send_reset_mac(struct rsi_common *common)
  712. {
  713. struct sk_buff *skb;
  714. struct rsi_mac_frame *mgmt_frame;
  715. rsi_dbg(MGMT_TX_ZONE, "%s: Sending reset MAC frame\n", __func__);
  716. skb = dev_alloc_skb(FRAME_DESC_SZ);
  717. if (!skb) {
  718. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  719. __func__);
  720. return -ENOMEM;
  721. }
  722. memset(skb->data, 0, FRAME_DESC_SZ);
  723. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  724. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  725. mgmt_frame->desc_word[1] = cpu_to_le16(RESET_MAC_REQ);
  726. mgmt_frame->desc_word[4] = cpu_to_le16(RETRY_COUNT << 8);
  727. skb_put(skb, FRAME_DESC_SZ);
  728. return rsi_send_internal_mgmt_frame(common, skb);
  729. }
  730. /**
  731. * rsi_set_channel() - This function programs the channel.
  732. * @common: Pointer to the driver private structure.
  733. * @channel: Channel value to be set.
  734. *
  735. * Return: 0 on success, corresponding error code on failure.
  736. */
  737. int rsi_set_channel(struct rsi_common *common, u16 channel)
  738. {
  739. struct sk_buff *skb = NULL;
  740. struct rsi_mac_frame *mgmt_frame;
  741. rsi_dbg(MGMT_TX_ZONE,
  742. "%s: Sending scan req frame\n", __func__);
  743. if (common->band == IEEE80211_BAND_5GHZ) {
  744. if ((channel >= 36) && (channel <= 64))
  745. channel = ((channel - 32) / 4);
  746. else if ((channel > 64) && (channel <= 140))
  747. channel = ((channel - 102) / 4) + 8;
  748. else if (channel >= 149)
  749. channel = ((channel - 151) / 4) + 18;
  750. else
  751. return -EINVAL;
  752. } else {
  753. if (channel > 14) {
  754. rsi_dbg(ERR_ZONE, "%s: Invalid chno %d, band = %d\n",
  755. __func__, channel, common->band);
  756. return -EINVAL;
  757. }
  758. }
  759. skb = dev_alloc_skb(FRAME_DESC_SZ);
  760. if (!skb) {
  761. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  762. __func__);
  763. return -ENOMEM;
  764. }
  765. memset(skb->data, 0, FRAME_DESC_SZ);
  766. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  767. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  768. mgmt_frame->desc_word[1] = cpu_to_le16(SCAN_REQUEST);
  769. mgmt_frame->desc_word[4] = cpu_to_le16(channel);
  770. mgmt_frame->desc_word[7] = cpu_to_le16(PUT_BBP_RESET |
  771. BBP_REG_WRITE |
  772. (RSI_RF_TYPE << 4));
  773. mgmt_frame->desc_word[5] = cpu_to_le16(0x01);
  774. if (common->channel_width == BW_40MHZ)
  775. mgmt_frame->desc_word[5] |= cpu_to_le16(0x1 << 8);
  776. common->channel = channel;
  777. skb_put(skb, FRAME_DESC_SZ);
  778. return rsi_send_internal_mgmt_frame(common, skb);
  779. }
  780. /**
  781. * rsi_compare() - This function is used to compare two integers
  782. * @a: pointer to the first integer
  783. * @b: pointer to the second integer
  784. *
  785. * Return: 0 if both are equal, -1 if the first is smaller, else 1
  786. */
  787. static int rsi_compare(const void *a, const void *b)
  788. {
  789. u16 _a = *(const u16 *)(a);
  790. u16 _b = *(const u16 *)(b);
  791. if (_a > _b)
  792. return -1;
  793. if (_a < _b)
  794. return 1;
  795. return 0;
  796. }
  797. /**
  798. * rsi_map_rates() - This function is used to map selected rates to hw rates.
  799. * @rate: The standard rate to be mapped.
  800. * @offset: Offset that will be returned.
  801. *
  802. * Return: 0 if it is a mcs rate, else 1
  803. */
  804. static bool rsi_map_rates(u16 rate, int *offset)
  805. {
  806. int kk;
  807. for (kk = 0; kk < ARRAY_SIZE(rsi_mcsrates); kk++) {
  808. if (rate == mcs[kk]) {
  809. *offset = kk;
  810. return false;
  811. }
  812. }
  813. for (kk = 0; kk < ARRAY_SIZE(rsi_rates); kk++) {
  814. if (rate == rsi_rates[kk].bitrate / 5) {
  815. *offset = kk;
  816. break;
  817. }
  818. }
  819. return true;
  820. }
  821. /**
  822. * rsi_send_auto_rate_request() - This function is to set rates for connection
  823. * and send autorate request to firmware.
  824. * @common: Pointer to the driver private structure.
  825. *
  826. * Return: 0 on success, corresponding error code on failure.
  827. */
  828. static int rsi_send_auto_rate_request(struct rsi_common *common)
  829. {
  830. struct sk_buff *skb;
  831. struct rsi_auto_rate *auto_rate;
  832. int ii = 0, jj = 0, kk = 0;
  833. struct ieee80211_hw *hw = common->priv->hw;
  834. u8 band = hw->conf.chandef.chan->band;
  835. u8 num_supported_rates = 0;
  836. u8 rate_offset = 0;
  837. u32 rate_bitmap = common->bitrate_mask[band];
  838. u16 *selected_rates, min_rate;
  839. skb = dev_alloc_skb(sizeof(struct rsi_auto_rate));
  840. if (!skb) {
  841. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  842. __func__);
  843. return -ENOMEM;
  844. }
  845. selected_rates = kmalloc(2 * RSI_TBL_SZ, GFP_KERNEL);
  846. if (!selected_rates) {
  847. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of mem\n",
  848. __func__);
  849. dev_kfree_skb(skb);
  850. return -ENOMEM;
  851. }
  852. memset(skb->data, 0, sizeof(struct rsi_auto_rate));
  853. memset(selected_rates, 0, 2 * RSI_TBL_SZ);
  854. auto_rate = (struct rsi_auto_rate *)skb->data;
  855. auto_rate->aarf_rssi = cpu_to_le16(((u16)3 << 6) | (u16)(18 & 0x3f));
  856. auto_rate->collision_tolerance = cpu_to_le16(3);
  857. auto_rate->failure_limit = cpu_to_le16(3);
  858. auto_rate->initial_boundary = cpu_to_le16(3);
  859. auto_rate->max_threshold_limt = cpu_to_le16(27);
  860. auto_rate->desc_word[1] = cpu_to_le16(AUTO_RATE_IND);
  861. if (common->channel_width == BW_40MHZ)
  862. auto_rate->desc_word[7] |= cpu_to_le16(1);
  863. if (band == IEEE80211_BAND_2GHZ)
  864. min_rate = STD_RATE_01;
  865. else
  866. min_rate = STD_RATE_06;
  867. for (ii = 0, jj = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
  868. if (rate_bitmap & BIT(ii)) {
  869. selected_rates[jj++] = (rsi_rates[ii].bitrate / 5);
  870. rate_offset++;
  871. }
  872. }
  873. num_supported_rates = jj;
  874. if (common->vif_info[0].is_ht) {
  875. for (ii = 0; ii < ARRAY_SIZE(mcs); ii++)
  876. selected_rates[jj++] = mcs[ii];
  877. num_supported_rates += ARRAY_SIZE(mcs);
  878. rate_offset += ARRAY_SIZE(mcs);
  879. }
  880. if (rate_offset < (RSI_TBL_SZ / 2) - 1) {
  881. for (ii = jj; ii < (RSI_TBL_SZ / 2); ii++) {
  882. selected_rates[jj++] = min_rate;
  883. rate_offset++;
  884. }
  885. }
  886. sort(selected_rates, jj, sizeof(u16), &rsi_compare, NULL);
  887. /* mapping the rates to RSI rates */
  888. for (ii = 0; ii < jj; ii++) {
  889. if (rsi_map_rates(selected_rates[ii], &kk)) {
  890. auto_rate->supported_rates[ii] =
  891. cpu_to_le16(rsi_rates[kk].hw_value);
  892. } else {
  893. auto_rate->supported_rates[ii] =
  894. cpu_to_le16(rsi_mcsrates[kk]);
  895. }
  896. }
  897. /* loading HT rates in the bottom half of the auto rate table */
  898. if (common->vif_info[0].is_ht) {
  899. if (common->vif_info[0].sgi)
  900. auto_rate->supported_rates[rate_offset++] =
  901. cpu_to_le16(RSI_RATE_MCS7_SG);
  902. for (ii = rate_offset, kk = ARRAY_SIZE(rsi_mcsrates) - 1;
  903. ii < rate_offset + 2 * ARRAY_SIZE(rsi_mcsrates); ii++) {
  904. if (common->vif_info[0].sgi)
  905. auto_rate->supported_rates[ii++] =
  906. cpu_to_le16(rsi_mcsrates[kk] | BIT(9));
  907. auto_rate->supported_rates[ii] =
  908. cpu_to_le16(rsi_mcsrates[kk--]);
  909. }
  910. for (; ii < RSI_TBL_SZ; ii++) {
  911. auto_rate->supported_rates[ii] =
  912. cpu_to_le16(rsi_mcsrates[0]);
  913. }
  914. }
  915. auto_rate->num_supported_rates = cpu_to_le16(num_supported_rates * 2);
  916. auto_rate->moderate_rate_inx = cpu_to_le16(num_supported_rates / 2);
  917. auto_rate->desc_word[7] |= cpu_to_le16(0 << 8);
  918. num_supported_rates *= 2;
  919. auto_rate->desc_word[0] = cpu_to_le16((sizeof(*auto_rate) -
  920. FRAME_DESC_SZ) |
  921. (RSI_WIFI_MGMT_Q << 12));
  922. skb_put(skb,
  923. sizeof(struct rsi_auto_rate));
  924. kfree(selected_rates);
  925. return rsi_send_internal_mgmt_frame(common, skb);
  926. }
  927. /**
  928. * rsi_inform_bss_status() - This function informs about bss status with the
  929. * help of sta notify params by sending an internal
  930. * management frame to firmware.
  931. * @common: Pointer to the driver private structure.
  932. * @status: Bss status type.
  933. * @bssid: Bssid.
  934. * @qos_enable: Qos is enabled.
  935. * @aid: Aid (unique for all STAs).
  936. *
  937. * Return: None.
  938. */
  939. void rsi_inform_bss_status(struct rsi_common *common,
  940. u8 status,
  941. const unsigned char *bssid,
  942. u8 qos_enable,
  943. u16 aid)
  944. {
  945. if (status) {
  946. rsi_hal_send_sta_notify_frame(common,
  947. RSI_IFTYPE_STATION,
  948. STA_CONNECTED,
  949. bssid,
  950. qos_enable,
  951. aid);
  952. if (common->min_rate == 0xffff)
  953. rsi_send_auto_rate_request(common);
  954. } else {
  955. rsi_hal_send_sta_notify_frame(common,
  956. RSI_IFTYPE_STATION,
  957. STA_DISCONNECTED,
  958. bssid,
  959. qos_enable,
  960. aid);
  961. }
  962. }
  963. /**
  964. * rsi_eeprom_read() - This function sends a frame to read the mac address
  965. * from the eeprom.
  966. * @common: Pointer to the driver private structure.
  967. *
  968. * Return: 0 on success, -1 on failure.
  969. */
  970. static int rsi_eeprom_read(struct rsi_common *common)
  971. {
  972. struct rsi_mac_frame *mgmt_frame;
  973. struct sk_buff *skb;
  974. rsi_dbg(MGMT_TX_ZONE, "%s: Sending EEPROM read req frame\n", __func__);
  975. skb = dev_alloc_skb(FRAME_DESC_SZ);
  976. if (!skb) {
  977. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of skb\n",
  978. __func__);
  979. return -ENOMEM;
  980. }
  981. memset(skb->data, 0, FRAME_DESC_SZ);
  982. mgmt_frame = (struct rsi_mac_frame *)skb->data;
  983. /* FrameType */
  984. mgmt_frame->desc_word[1] = cpu_to_le16(EEPROM_READ_TYPE);
  985. mgmt_frame->desc_word[0] = cpu_to_le16(RSI_WIFI_MGMT_Q << 12);
  986. /* Number of bytes to read */
  987. mgmt_frame->desc_word[3] = cpu_to_le16(ETH_ALEN +
  988. WLAN_MAC_MAGIC_WORD_LEN +
  989. WLAN_HOST_MODE_LEN +
  990. WLAN_FW_VERSION_LEN);
  991. /* Address to read */
  992. mgmt_frame->desc_word[4] = cpu_to_le16(WLAN_MAC_EEPROM_ADDR);
  993. skb_put(skb, FRAME_DESC_SZ);
  994. return rsi_send_internal_mgmt_frame(common, skb);
  995. }
  996. /**
  997. * rsi_handle_ta_confirm_type() - This function handles the confirm frames.
  998. * @common: Pointer to the driver private structure.
  999. * @msg: Pointer to received packet.
  1000. *
  1001. * Return: 0 on success, -1 on failure.
  1002. */
  1003. static int rsi_handle_ta_confirm_type(struct rsi_common *common,
  1004. u8 *msg)
  1005. {
  1006. u8 sub_type = (msg[15] & 0xff);
  1007. switch (sub_type) {
  1008. case BOOTUP_PARAMS_REQUEST:
  1009. rsi_dbg(FSM_ZONE, "%s: Boot up params confirm received\n",
  1010. __func__);
  1011. if (common->fsm_state == FSM_BOOT_PARAMS_SENT) {
  1012. if (rsi_eeprom_read(common)) {
  1013. common->fsm_state = FSM_CARD_NOT_READY;
  1014. goto out;
  1015. } else {
  1016. common->fsm_state = FSM_EEPROM_READ_MAC_ADDR;
  1017. }
  1018. } else {
  1019. rsi_dbg(ERR_ZONE,
  1020. "%s: Received bootup params cfm in %d state\n",
  1021. __func__, common->fsm_state);
  1022. return 0;
  1023. }
  1024. break;
  1025. case EEPROM_READ_TYPE:
  1026. if (common->fsm_state == FSM_EEPROM_READ_MAC_ADDR) {
  1027. if (msg[16] == MAGIC_WORD) {
  1028. u8 offset = (FRAME_DESC_SZ + WLAN_HOST_MODE_LEN
  1029. + WLAN_MAC_MAGIC_WORD_LEN);
  1030. memcpy(common->mac_addr,
  1031. &msg[offset],
  1032. ETH_ALEN);
  1033. memcpy(&common->fw_ver,
  1034. &msg[offset + ETH_ALEN],
  1035. sizeof(struct version_info));
  1036. } else {
  1037. common->fsm_state = FSM_CARD_NOT_READY;
  1038. break;
  1039. }
  1040. if (rsi_send_reset_mac(common))
  1041. goto out;
  1042. else
  1043. common->fsm_state = FSM_RESET_MAC_SENT;
  1044. } else {
  1045. rsi_dbg(ERR_ZONE,
  1046. "%s: Received eeprom mac addr in %d state\n",
  1047. __func__, common->fsm_state);
  1048. return 0;
  1049. }
  1050. break;
  1051. case RESET_MAC_REQ:
  1052. if (common->fsm_state == FSM_RESET_MAC_SENT) {
  1053. rsi_dbg(FSM_ZONE, "%s: Reset MAC cfm received\n",
  1054. __func__);
  1055. if (rsi_load_radio_caps(common))
  1056. goto out;
  1057. else
  1058. common->fsm_state = FSM_RADIO_CAPS_SENT;
  1059. } else {
  1060. rsi_dbg(ERR_ZONE,
  1061. "%s: Received reset mac cfm in %d state\n",
  1062. __func__, common->fsm_state);
  1063. return 0;
  1064. }
  1065. break;
  1066. case RADIO_CAPABILITIES:
  1067. if (common->fsm_state == FSM_RADIO_CAPS_SENT) {
  1068. common->rf_reset = 1;
  1069. if (rsi_program_bb_rf(common)) {
  1070. goto out;
  1071. } else {
  1072. common->fsm_state = FSM_BB_RF_PROG_SENT;
  1073. rsi_dbg(FSM_ZONE, "%s: Radio cap cfm received\n",
  1074. __func__);
  1075. }
  1076. } else {
  1077. rsi_dbg(ERR_ZONE,
  1078. "%s: Received radio caps cfm in %d state\n",
  1079. __func__, common->fsm_state);
  1080. return 0;
  1081. }
  1082. break;
  1083. case BB_PROG_VALUES_REQUEST:
  1084. case RF_PROG_VALUES_REQUEST:
  1085. case BBP_PROG_IN_TA:
  1086. rsi_dbg(FSM_ZONE, "%s: BB/RF cfm received\n", __func__);
  1087. if (common->fsm_state == FSM_BB_RF_PROG_SENT) {
  1088. common->bb_rf_prog_count--;
  1089. if (!common->bb_rf_prog_count) {
  1090. common->fsm_state = FSM_MAC_INIT_DONE;
  1091. return rsi_mac80211_attach(common);
  1092. }
  1093. } else {
  1094. goto out;
  1095. }
  1096. break;
  1097. default:
  1098. rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
  1099. __func__);
  1100. break;
  1101. }
  1102. return 0;
  1103. out:
  1104. rsi_dbg(ERR_ZONE, "%s: Unable to send pkt/Invalid frame received\n",
  1105. __func__);
  1106. return -EINVAL;
  1107. }
  1108. /**
  1109. * rsi_mgmt_pkt_recv() - This function processes the management packets
  1110. * recieved from the hardware.
  1111. * @common: Pointer to the driver private structure.
  1112. * @msg: Pointer to the received packet.
  1113. *
  1114. * Return: 0 on success, -1 on failure.
  1115. */
  1116. int rsi_mgmt_pkt_recv(struct rsi_common *common, u8 *msg)
  1117. {
  1118. s32 msg_len = (le16_to_cpu(*(__le16 *)&msg[0]) & 0x0fff);
  1119. u16 msg_type = (msg[2]);
  1120. int ret;
  1121. rsi_dbg(FSM_ZONE, "%s: Msg Len: %d, Msg Type: %4x\n",
  1122. __func__, msg_len, msg_type);
  1123. if (msg_type == TA_CONFIRM_TYPE) {
  1124. return rsi_handle_ta_confirm_type(common, msg);
  1125. } else if (msg_type == CARD_READY_IND) {
  1126. rsi_dbg(FSM_ZONE, "%s: Card ready indication received\n",
  1127. __func__);
  1128. if (common->fsm_state == FSM_CARD_NOT_READY) {
  1129. rsi_set_default_parameters(common);
  1130. ret = rsi_load_bootup_params(common);
  1131. if (ret)
  1132. return ret;
  1133. else
  1134. common->fsm_state = FSM_BOOT_PARAMS_SENT;
  1135. } else {
  1136. return -EINVAL;
  1137. }
  1138. } else if (msg_type == TX_STATUS_IND) {
  1139. if (msg[15] == PROBEREQ_CONFIRM) {
  1140. common->mgmt_q_block = false;
  1141. rsi_dbg(FSM_ZONE, "%s: Probe confirm received\n",
  1142. __func__);
  1143. }
  1144. } else {
  1145. return rsi_mgmt_pkt_to_core(common, msg, msg_len, msg_type);
  1146. }
  1147. return 0;
  1148. }