rsi_91x_mgmt.c 52 KB

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