rsi_91x_mgmt.c 52 KB

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