rsi_91x_mgmt.c 51 KB

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