smd.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  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 ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/etherdevice.h>
  18. #include <linux/firmware.h>
  19. #include <linux/bitops.h>
  20. #include "smd.h"
  21. static int put_cfg_tlv_u32(struct wcn36xx *wcn, size_t *len, u32 id, u32 value)
  22. {
  23. struct wcn36xx_hal_cfg *entry;
  24. u32 *val;
  25. if (*len + sizeof(*entry) + sizeof(u32) >= WCN36XX_HAL_BUF_SIZE) {
  26. wcn36xx_err("Not enough room for TLV entry\n");
  27. return -ENOMEM;
  28. }
  29. entry = (struct wcn36xx_hal_cfg *) (wcn->hal_buf + *len);
  30. entry->id = id;
  31. entry->len = sizeof(u32);
  32. entry->pad_bytes = 0;
  33. entry->reserve = 0;
  34. val = (u32 *) (entry + 1);
  35. *val = value;
  36. *len += sizeof(*entry) + sizeof(u32);
  37. return 0;
  38. }
  39. static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx *wcn,
  40. struct ieee80211_sta *sta,
  41. struct wcn36xx_hal_config_bss_params *bss_params)
  42. {
  43. if (IEEE80211_BAND_5GHZ == WCN36XX_BAND(wcn))
  44. bss_params->nw_type = WCN36XX_HAL_11A_NW_TYPE;
  45. else if (sta && sta->ht_cap.ht_supported)
  46. bss_params->nw_type = WCN36XX_HAL_11N_NW_TYPE;
  47. else if (sta && (sta->supp_rates[IEEE80211_BAND_2GHZ] & 0x7f))
  48. bss_params->nw_type = WCN36XX_HAL_11G_NW_TYPE;
  49. else
  50. bss_params->nw_type = WCN36XX_HAL_11B_NW_TYPE;
  51. }
  52. static inline u8 is_cap_supported(unsigned long caps, unsigned long flag)
  53. {
  54. return caps & flag ? 1 : 0;
  55. }
  56. static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif *vif,
  57. struct ieee80211_sta *sta,
  58. struct wcn36xx_hal_config_bss_params *bss_params)
  59. {
  60. if (sta && sta->ht_cap.ht_supported) {
  61. unsigned long caps = sta->ht_cap.cap;
  62. bss_params->ht = sta->ht_cap.ht_supported;
  63. bss_params->tx_channel_width_set = is_cap_supported(caps,
  64. IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  65. bss_params->lsig_tx_op_protection_full_support =
  66. is_cap_supported(caps,
  67. IEEE80211_HT_CAP_LSIG_TXOP_PROT);
  68. bss_params->ht_oper_mode = vif->bss_conf.ht_operation_mode;
  69. bss_params->lln_non_gf_coexist =
  70. !!(vif->bss_conf.ht_operation_mode &
  71. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  72. /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */
  73. bss_params->dual_cts_protection = 0;
  74. /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */
  75. bss_params->ht20_coexist = 0;
  76. }
  77. }
  78. static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta *sta,
  79. struct wcn36xx_hal_config_sta_params *sta_params)
  80. {
  81. if (sta->ht_cap.ht_supported) {
  82. unsigned long caps = sta->ht_cap.cap;
  83. sta_params->ht_capable = sta->ht_cap.ht_supported;
  84. sta_params->tx_channel_width_set = is_cap_supported(caps,
  85. IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  86. sta_params->lsig_txop_protection = is_cap_supported(caps,
  87. IEEE80211_HT_CAP_LSIG_TXOP_PROT);
  88. sta_params->max_ampdu_size = sta->ht_cap.ampdu_factor;
  89. sta_params->max_ampdu_density = sta->ht_cap.ampdu_density;
  90. sta_params->max_amsdu_size = is_cap_supported(caps,
  91. IEEE80211_HT_CAP_MAX_AMSDU);
  92. sta_params->sgi_20Mhz = is_cap_supported(caps,
  93. IEEE80211_HT_CAP_SGI_20);
  94. sta_params->sgi_40mhz = is_cap_supported(caps,
  95. IEEE80211_HT_CAP_SGI_40);
  96. sta_params->green_field_capable = is_cap_supported(caps,
  97. IEEE80211_HT_CAP_GRN_FLD);
  98. sta_params->delayed_ba_support = is_cap_supported(caps,
  99. IEEE80211_HT_CAP_DELAY_BA);
  100. sta_params->dsss_cck_mode_40mhz = is_cap_supported(caps,
  101. IEEE80211_HT_CAP_DSSSCCK40);
  102. }
  103. }
  104. static void wcn36xx_smd_set_sta_params(struct wcn36xx *wcn,
  105. struct ieee80211_vif *vif,
  106. struct ieee80211_sta *sta,
  107. struct wcn36xx_hal_config_sta_params *sta_params)
  108. {
  109. struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
  110. struct wcn36xx_sta *priv_sta = NULL;
  111. if (vif->type == NL80211_IFTYPE_ADHOC ||
  112. vif->type == NL80211_IFTYPE_AP ||
  113. vif->type == NL80211_IFTYPE_MESH_POINT) {
  114. sta_params->type = 1;
  115. sta_params->sta_index = 0xFF;
  116. } else {
  117. sta_params->type = 0;
  118. sta_params->sta_index = 1;
  119. }
  120. sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
  121. /*
  122. * In STA mode ieee80211_sta contains bssid and ieee80211_vif
  123. * contains our mac address. In AP mode we are bssid so vif
  124. * contains bssid and ieee80211_sta contains mac.
  125. */
  126. if (NL80211_IFTYPE_STATION == vif->type)
  127. memcpy(&sta_params->mac, vif->addr, ETH_ALEN);
  128. else
  129. memcpy(&sta_params->bssid, vif->addr, ETH_ALEN);
  130. sta_params->encrypt_type = priv_vif->encrypt_type;
  131. sta_params->short_preamble_supported =
  132. !(WCN36XX_FLAGS(wcn) &
  133. IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE);
  134. sta_params->rifs_mode = 0;
  135. sta_params->rmf = 0;
  136. sta_params->action = 0;
  137. sta_params->uapsd = 0;
  138. sta_params->mimo_ps = WCN36XX_HAL_HT_MIMO_PS_STATIC;
  139. sta_params->max_ampdu_duration = 0;
  140. sta_params->bssid_index = priv_vif->bss_index;
  141. sta_params->p2p = 0;
  142. if (sta) {
  143. priv_sta = (struct wcn36xx_sta *)sta->drv_priv;
  144. if (NL80211_IFTYPE_STATION == vif->type)
  145. memcpy(&sta_params->bssid, sta->addr, ETH_ALEN);
  146. else
  147. memcpy(&sta_params->mac, sta->addr, ETH_ALEN);
  148. sta_params->wmm_enabled = sta->wme;
  149. sta_params->max_sp_len = sta->max_sp;
  150. sta_params->aid = priv_sta->aid;
  151. wcn36xx_smd_set_sta_ht_params(sta, sta_params);
  152. memcpy(&sta_params->supported_rates, &priv_sta->supported_rates,
  153. sizeof(priv_sta->supported_rates));
  154. } else {
  155. wcn36xx_set_default_rates(&sta_params->supported_rates);
  156. }
  157. }
  158. static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
  159. {
  160. int ret = 0;
  161. wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len);
  162. init_completion(&wcn->hal_rsp_compl);
  163. ret = wcn->ctrl_ops->tx(wcn->hal_buf, len);
  164. if (ret) {
  165. wcn36xx_err("HAL TX failed\n");
  166. goto out;
  167. }
  168. if (wait_for_completion_timeout(&wcn->hal_rsp_compl,
  169. msecs_to_jiffies(HAL_MSG_TIMEOUT)) <= 0) {
  170. wcn36xx_err("Timeout while waiting SMD response\n");
  171. ret = -ETIME;
  172. goto out;
  173. }
  174. out:
  175. return ret;
  176. }
  177. #define INIT_HAL_MSG(msg_body, type) \
  178. do { \
  179. memset(&msg_body, 0, sizeof(msg_body)); \
  180. msg_body.header.msg_type = type; \
  181. msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
  182. msg_body.header.len = sizeof(msg_body); \
  183. } while (0) \
  184. #define PREPARE_HAL_BUF(send_buf, msg_body) \
  185. do { \
  186. memset(send_buf, 0, msg_body.header.len); \
  187. memcpy(send_buf, &msg_body, sizeof(msg_body)); \
  188. } while (0) \
  189. static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
  190. {
  191. struct wcn36xx_fw_msg_status_rsp *rsp;
  192. if (len < sizeof(struct wcn36xx_hal_msg_header) +
  193. sizeof(struct wcn36xx_fw_msg_status_rsp))
  194. return -EIO;
  195. rsp = (struct wcn36xx_fw_msg_status_rsp *)
  196. (buf + sizeof(struct wcn36xx_hal_msg_header));
  197. if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
  198. return rsp->status;
  199. return 0;
  200. }
  201. int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
  202. {
  203. const struct firmware *nv;
  204. struct nv_data *nv_d;
  205. struct wcn36xx_hal_nv_img_download_req_msg msg_body;
  206. int fw_bytes_left;
  207. int ret;
  208. u16 fm_offset = 0;
  209. ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev);
  210. if (ret) {
  211. wcn36xx_err("Failed to load nv file %s: %d\n",
  212. WLAN_NV_FILE, ret);
  213. goto out_free_nv;
  214. }
  215. nv_d = (struct nv_data *)nv->data;
  216. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
  217. msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
  218. msg_body.frag_number = 0;
  219. /* hal_buf must be protected with mutex */
  220. mutex_lock(&wcn->hal_mutex);
  221. do {
  222. fw_bytes_left = nv->size - fm_offset - 4;
  223. if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
  224. msg_body.last_fragment = 0;
  225. msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
  226. } else {
  227. msg_body.last_fragment = 1;
  228. msg_body.nv_img_buffer_size = fw_bytes_left;
  229. /* Do not forget update general message len */
  230. msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
  231. }
  232. /* Add load NV request message header */
  233. memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
  234. /* Add NV body itself */
  235. memcpy(wcn->hal_buf + sizeof(msg_body),
  236. &nv_d->table + fm_offset,
  237. msg_body.nv_img_buffer_size);
  238. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  239. if (ret)
  240. goto out_unlock;
  241. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
  242. wcn->hal_rsp_len);
  243. if (ret) {
  244. wcn36xx_err("hal_load_nv response failed err=%d\n",
  245. ret);
  246. goto out_unlock;
  247. }
  248. msg_body.frag_number++;
  249. fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
  250. } while (msg_body.last_fragment != 1);
  251. out_unlock:
  252. mutex_unlock(&wcn->hal_mutex);
  253. out_free_nv:
  254. release_firmware(nv);
  255. return ret;
  256. }
  257. static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
  258. {
  259. struct wcn36xx_hal_mac_start_rsp_msg *rsp;
  260. if (len < sizeof(*rsp))
  261. return -EIO;
  262. rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
  263. if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
  264. return -EIO;
  265. memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
  266. WCN36XX_HAL_VERSION_LENGTH);
  267. memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
  268. WCN36XX_HAL_VERSION_LENGTH);
  269. /* null terminate the strings, just in case */
  270. wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
  271. wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
  272. wcn->fw_revision = rsp->start_rsp_params.version.revision;
  273. wcn->fw_version = rsp->start_rsp_params.version.version;
  274. wcn->fw_minor = rsp->start_rsp_params.version.minor;
  275. wcn->fw_major = rsp->start_rsp_params.version.major;
  276. wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
  277. wcn->wlan_version, wcn->crm_version);
  278. wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
  279. wcn->fw_major, wcn->fw_minor,
  280. wcn->fw_version, wcn->fw_revision,
  281. rsp->start_rsp_params.stations,
  282. rsp->start_rsp_params.bssids);
  283. return 0;
  284. }
  285. int wcn36xx_smd_start(struct wcn36xx *wcn)
  286. {
  287. struct wcn36xx_hal_mac_start_req_msg msg_body;
  288. int ret = 0;
  289. mutex_lock(&wcn->hal_mutex);
  290. INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
  291. msg_body.params.type = DRIVER_TYPE_PRODUCTION;
  292. msg_body.params.len = 0;
  293. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  294. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
  295. msg_body.params.type);
  296. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  297. if (ret) {
  298. wcn36xx_err("Sending hal_start failed\n");
  299. goto out;
  300. }
  301. ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
  302. if (ret) {
  303. wcn36xx_err("hal_start response failed err=%d\n", ret);
  304. goto out;
  305. }
  306. out:
  307. mutex_unlock(&wcn->hal_mutex);
  308. return ret;
  309. }
  310. int wcn36xx_smd_stop(struct wcn36xx *wcn)
  311. {
  312. struct wcn36xx_hal_mac_stop_req_msg msg_body;
  313. int ret = 0;
  314. mutex_lock(&wcn->hal_mutex);
  315. INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
  316. msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
  317. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  318. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  319. if (ret) {
  320. wcn36xx_err("Sending hal_stop failed\n");
  321. goto out;
  322. }
  323. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  324. if (ret) {
  325. wcn36xx_err("hal_stop response failed err=%d\n", ret);
  326. goto out;
  327. }
  328. out:
  329. mutex_unlock(&wcn->hal_mutex);
  330. return ret;
  331. }
  332. int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
  333. {
  334. struct wcn36xx_hal_init_scan_req_msg msg_body;
  335. int ret = 0;
  336. mutex_lock(&wcn->hal_mutex);
  337. INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
  338. msg_body.mode = mode;
  339. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  340. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
  341. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  342. if (ret) {
  343. wcn36xx_err("Sending hal_init_scan failed\n");
  344. goto out;
  345. }
  346. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  347. if (ret) {
  348. wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
  349. goto out;
  350. }
  351. out:
  352. mutex_unlock(&wcn->hal_mutex);
  353. return ret;
  354. }
  355. int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
  356. {
  357. struct wcn36xx_hal_start_scan_req_msg msg_body;
  358. int ret = 0;
  359. mutex_lock(&wcn->hal_mutex);
  360. INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
  361. msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
  362. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  363. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
  364. msg_body.scan_channel);
  365. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  366. if (ret) {
  367. wcn36xx_err("Sending hal_start_scan failed\n");
  368. goto out;
  369. }
  370. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  371. if (ret) {
  372. wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
  373. goto out;
  374. }
  375. out:
  376. mutex_unlock(&wcn->hal_mutex);
  377. return ret;
  378. }
  379. int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
  380. {
  381. struct wcn36xx_hal_end_scan_req_msg msg_body;
  382. int ret = 0;
  383. mutex_lock(&wcn->hal_mutex);
  384. INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
  385. msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
  386. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  387. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
  388. msg_body.scan_channel);
  389. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  390. if (ret) {
  391. wcn36xx_err("Sending hal_end_scan failed\n");
  392. goto out;
  393. }
  394. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  395. if (ret) {
  396. wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
  397. goto out;
  398. }
  399. out:
  400. mutex_unlock(&wcn->hal_mutex);
  401. return ret;
  402. }
  403. int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
  404. enum wcn36xx_hal_sys_mode mode)
  405. {
  406. struct wcn36xx_hal_finish_scan_req_msg msg_body;
  407. int ret = 0;
  408. mutex_lock(&wcn->hal_mutex);
  409. INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
  410. msg_body.mode = mode;
  411. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  412. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
  413. msg_body.mode);
  414. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  415. if (ret) {
  416. wcn36xx_err("Sending hal_finish_scan failed\n");
  417. goto out;
  418. }
  419. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  420. if (ret) {
  421. wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
  422. goto out;
  423. }
  424. out:
  425. mutex_unlock(&wcn->hal_mutex);
  426. return ret;
  427. }
  428. static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
  429. {
  430. struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
  431. int ret = 0;
  432. ret = wcn36xx_smd_rsp_status_check(buf, len);
  433. if (ret)
  434. return ret;
  435. rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
  436. wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
  437. rsp->channel_number, rsp->status);
  438. return ret;
  439. }
  440. int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
  441. struct ieee80211_vif *vif, int ch)
  442. {
  443. struct wcn36xx_hal_switch_channel_req_msg msg_body;
  444. int ret = 0;
  445. mutex_lock(&wcn->hal_mutex);
  446. INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
  447. msg_body.channel_number = (u8)ch;
  448. msg_body.tx_mgmt_power = 0xbf;
  449. msg_body.max_tx_power = 0xbf;
  450. memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
  451. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  452. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  453. if (ret) {
  454. wcn36xx_err("Sending hal_switch_channel failed\n");
  455. goto out;
  456. }
  457. ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
  458. if (ret) {
  459. wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
  460. goto out;
  461. }
  462. out:
  463. mutex_unlock(&wcn->hal_mutex);
  464. return ret;
  465. }
  466. static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
  467. {
  468. struct wcn36xx_hal_update_scan_params_resp *rsp;
  469. rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
  470. /* Remove the PNO version bit */
  471. rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
  472. if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
  473. wcn36xx_warn("error response from update scan\n");
  474. return rsp->status;
  475. }
  476. return 0;
  477. }
  478. int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
  479. {
  480. struct wcn36xx_hal_update_scan_params_req msg_body;
  481. int ret = 0;
  482. mutex_lock(&wcn->hal_mutex);
  483. INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
  484. msg_body.dot11d_enabled = 0;
  485. msg_body.dot11d_resolved = 0;
  486. msg_body.channel_count = 26;
  487. msg_body.active_min_ch_time = 60;
  488. msg_body.active_max_ch_time = 120;
  489. msg_body.passive_min_ch_time = 60;
  490. msg_body.passive_max_ch_time = 110;
  491. msg_body.state = 0;
  492. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  493. wcn36xx_dbg(WCN36XX_DBG_HAL,
  494. "hal update scan params channel_count %d\n",
  495. msg_body.channel_count);
  496. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  497. if (ret) {
  498. wcn36xx_err("Sending hal_update_scan_params failed\n");
  499. goto out;
  500. }
  501. ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
  502. wcn->hal_rsp_len);
  503. if (ret) {
  504. wcn36xx_err("hal_update_scan_params response failed err=%d\n",
  505. ret);
  506. goto out;
  507. }
  508. out:
  509. mutex_unlock(&wcn->hal_mutex);
  510. return ret;
  511. }
  512. static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
  513. struct ieee80211_vif *vif,
  514. void *buf,
  515. size_t len)
  516. {
  517. struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
  518. struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
  519. if (len < sizeof(*rsp))
  520. return -EINVAL;
  521. rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
  522. if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
  523. wcn36xx_warn("hal add sta self failure: %d\n",
  524. rsp->status);
  525. return rsp->status;
  526. }
  527. wcn36xx_dbg(WCN36XX_DBG_HAL,
  528. "hal add sta self status %d self_sta_index %d dpu_index %d\n",
  529. rsp->status, rsp->self_sta_index, rsp->dpu_index);
  530. priv_vif->self_sta_index = rsp->self_sta_index;
  531. priv_vif->self_dpu_desc_index = rsp->dpu_index;
  532. return 0;
  533. }
  534. int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
  535. {
  536. struct wcn36xx_hal_add_sta_self_req msg_body;
  537. int ret = 0;
  538. mutex_lock(&wcn->hal_mutex);
  539. INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
  540. memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
  541. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  542. wcn36xx_dbg(WCN36XX_DBG_HAL,
  543. "hal add sta self self_addr %pM status %d\n",
  544. msg_body.self_addr, msg_body.status);
  545. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  546. if (ret) {
  547. wcn36xx_err("Sending hal_add_sta_self failed\n");
  548. goto out;
  549. }
  550. ret = wcn36xx_smd_add_sta_self_rsp(wcn,
  551. vif,
  552. wcn->hal_buf,
  553. wcn->hal_rsp_len);
  554. if (ret) {
  555. wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
  556. goto out;
  557. }
  558. out:
  559. mutex_unlock(&wcn->hal_mutex);
  560. return ret;
  561. }
  562. int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
  563. {
  564. struct wcn36xx_hal_del_sta_self_req_msg msg_body;
  565. int ret = 0;
  566. mutex_lock(&wcn->hal_mutex);
  567. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
  568. memcpy(&msg_body.self_addr, addr, ETH_ALEN);
  569. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  570. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  571. if (ret) {
  572. wcn36xx_err("Sending hal_delete_sta_self failed\n");
  573. goto out;
  574. }
  575. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  576. if (ret) {
  577. wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
  578. ret);
  579. goto out;
  580. }
  581. out:
  582. mutex_unlock(&wcn->hal_mutex);
  583. return ret;
  584. }
  585. int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
  586. {
  587. struct wcn36xx_hal_delete_sta_req_msg msg_body;
  588. int ret = 0;
  589. mutex_lock(&wcn->hal_mutex);
  590. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
  591. msg_body.sta_index = sta_index;
  592. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  593. wcn36xx_dbg(WCN36XX_DBG_HAL,
  594. "hal delete sta sta_index %d\n",
  595. msg_body.sta_index);
  596. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  597. if (ret) {
  598. wcn36xx_err("Sending hal_delete_sta failed\n");
  599. goto out;
  600. }
  601. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  602. if (ret) {
  603. wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
  604. goto out;
  605. }
  606. out:
  607. mutex_unlock(&wcn->hal_mutex);
  608. return ret;
  609. }
  610. static int wcn36xx_smd_join_rsp(void *buf, size_t len)
  611. {
  612. struct wcn36xx_hal_join_rsp_msg *rsp;
  613. if (wcn36xx_smd_rsp_status_check(buf, len))
  614. return -EIO;
  615. rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
  616. wcn36xx_dbg(WCN36XX_DBG_HAL,
  617. "hal rsp join status %d tx_mgmt_power %d\n",
  618. rsp->status, rsp->tx_mgmt_power);
  619. return 0;
  620. }
  621. int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
  622. {
  623. struct wcn36xx_hal_join_req_msg msg_body;
  624. int ret = 0;
  625. mutex_lock(&wcn->hal_mutex);
  626. INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
  627. memcpy(&msg_body.bssid, bssid, ETH_ALEN);
  628. memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
  629. msg_body.channel = ch;
  630. if (conf_is_ht40_minus(&wcn->hw->conf))
  631. msg_body.secondary_channel_offset =
  632. PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
  633. else if (conf_is_ht40_plus(&wcn->hw->conf))
  634. msg_body.secondary_channel_offset =
  635. PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
  636. else
  637. msg_body.secondary_channel_offset =
  638. PHY_SINGLE_CHANNEL_CENTERED;
  639. msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
  640. msg_body.max_tx_power = 0xbf;
  641. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  642. wcn36xx_dbg(WCN36XX_DBG_HAL,
  643. "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
  644. msg_body.bssid, msg_body.self_sta_mac_addr,
  645. msg_body.channel, msg_body.link_state);
  646. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  647. if (ret) {
  648. wcn36xx_err("Sending hal_join failed\n");
  649. goto out;
  650. }
  651. ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
  652. if (ret) {
  653. wcn36xx_err("hal_join response failed err=%d\n", ret);
  654. goto out;
  655. }
  656. out:
  657. mutex_unlock(&wcn->hal_mutex);
  658. return ret;
  659. }
  660. int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
  661. const u8 *sta_mac,
  662. enum wcn36xx_hal_link_state state)
  663. {
  664. struct wcn36xx_hal_set_link_state_req_msg msg_body;
  665. int ret = 0;
  666. mutex_lock(&wcn->hal_mutex);
  667. INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
  668. memcpy(&msg_body.bssid, bssid, ETH_ALEN);
  669. memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
  670. msg_body.state = state;
  671. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  672. wcn36xx_dbg(WCN36XX_DBG_HAL,
  673. "hal set link state bssid %pM self_mac_addr %pM state %d\n",
  674. msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
  675. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  676. if (ret) {
  677. wcn36xx_err("Sending hal_set_link_st failed\n");
  678. goto out;
  679. }
  680. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  681. if (ret) {
  682. wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
  683. goto out;
  684. }
  685. out:
  686. mutex_unlock(&wcn->hal_mutex);
  687. return ret;
  688. }
  689. static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
  690. const struct wcn36xx_hal_config_sta_params *orig,
  691. struct wcn36xx_hal_config_sta_params_v1 *v1)
  692. {
  693. /* convert orig to v1 format */
  694. memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
  695. memcpy(&v1->mac, orig->mac, ETH_ALEN);
  696. v1->aid = orig->aid;
  697. v1->type = orig->type;
  698. v1->listen_interval = orig->listen_interval;
  699. v1->ht_capable = orig->ht_capable;
  700. v1->max_ampdu_size = orig->max_ampdu_size;
  701. v1->max_ampdu_density = orig->max_ampdu_density;
  702. v1->sgi_40mhz = orig->sgi_40mhz;
  703. v1->sgi_20Mhz = orig->sgi_20Mhz;
  704. memcpy(&v1->supported_rates, &orig->supported_rates,
  705. sizeof(orig->supported_rates));
  706. v1->sta_index = orig->sta_index;
  707. }
  708. static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
  709. struct ieee80211_sta *sta,
  710. void *buf,
  711. size_t len)
  712. {
  713. struct wcn36xx_hal_config_sta_rsp_msg *rsp;
  714. struct config_sta_rsp_params *params;
  715. struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
  716. if (len < sizeof(*rsp))
  717. return -EINVAL;
  718. rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
  719. params = &rsp->params;
  720. if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
  721. wcn36xx_warn("hal config sta response failure: %d\n",
  722. params->status);
  723. return -EIO;
  724. }
  725. sta_priv->sta_index = params->sta_index;
  726. sta_priv->dpu_desc_index = params->dpu_index;
  727. wcn36xx_dbg(WCN36XX_DBG_HAL,
  728. "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n",
  729. params->status, params->sta_index, params->bssid_index,
  730. params->p2p);
  731. return 0;
  732. }
  733. static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
  734. const struct wcn36xx_hal_config_sta_req_msg *orig)
  735. {
  736. struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
  737. struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
  738. INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
  739. wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
  740. &msg_body.sta_params);
  741. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  742. wcn36xx_dbg(WCN36XX_DBG_HAL,
  743. "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
  744. sta->action, sta->sta_index, sta->bssid_index,
  745. sta->bssid, sta->type, sta->mac, sta->aid);
  746. return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  747. }
  748. int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
  749. struct ieee80211_sta *sta)
  750. {
  751. struct wcn36xx_hal_config_sta_req_msg msg;
  752. struct wcn36xx_hal_config_sta_params *sta_params;
  753. int ret = 0;
  754. mutex_lock(&wcn->hal_mutex);
  755. INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
  756. sta_params = &msg.sta_params;
  757. wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
  758. if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
  759. ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
  760. } else {
  761. PREPARE_HAL_BUF(wcn->hal_buf, msg);
  762. wcn36xx_dbg(WCN36XX_DBG_HAL,
  763. "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
  764. sta_params->action, sta_params->sta_index,
  765. sta_params->bssid_index, sta_params->bssid,
  766. sta_params->type, sta_params->mac, sta_params->aid);
  767. ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
  768. }
  769. if (ret) {
  770. wcn36xx_err("Sending hal_config_sta failed\n");
  771. goto out;
  772. }
  773. ret = wcn36xx_smd_config_sta_rsp(wcn,
  774. sta,
  775. wcn->hal_buf,
  776. wcn->hal_rsp_len);
  777. if (ret) {
  778. wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
  779. goto out;
  780. }
  781. out:
  782. mutex_unlock(&wcn->hal_mutex);
  783. return ret;
  784. }
  785. static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
  786. const struct wcn36xx_hal_config_bss_req_msg *orig)
  787. {
  788. struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
  789. struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
  790. struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
  791. INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
  792. /* convert orig to v1 */
  793. memcpy(&msg_body.bss_params.bssid,
  794. &orig->bss_params.bssid, ETH_ALEN);
  795. memcpy(&msg_body.bss_params.self_mac_addr,
  796. &orig->bss_params.self_mac_addr, ETH_ALEN);
  797. msg_body.bss_params.bss_type = orig->bss_params.bss_type;
  798. msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
  799. msg_body.bss_params.nw_type = orig->bss_params.nw_type;
  800. msg_body.bss_params.short_slot_time_supported =
  801. orig->bss_params.short_slot_time_supported;
  802. msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
  803. msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
  804. msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
  805. msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
  806. msg_body.bss_params.lln_non_gf_coexist =
  807. orig->bss_params.lln_non_gf_coexist;
  808. msg_body.bss_params.lsig_tx_op_protection_full_support =
  809. orig->bss_params.lsig_tx_op_protection_full_support;
  810. msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
  811. msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
  812. msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
  813. msg_body.bss_params.tx_channel_width_set =
  814. orig->bss_params.tx_channel_width_set;
  815. msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
  816. msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
  817. msg_body.bss_params.reserved = orig->bss_params.reserved;
  818. memcpy(&msg_body.bss_params.ssid,
  819. &orig->bss_params.ssid,
  820. sizeof(orig->bss_params.ssid));
  821. msg_body.bss_params.action = orig->bss_params.action;
  822. msg_body.bss_params.rateset = orig->bss_params.rateset;
  823. msg_body.bss_params.ht = orig->bss_params.ht;
  824. msg_body.bss_params.obss_prot_enabled =
  825. orig->bss_params.obss_prot_enabled;
  826. msg_body.bss_params.rmf = orig->bss_params.rmf;
  827. msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
  828. msg_body.bss_params.dual_cts_protection =
  829. orig->bss_params.dual_cts_protection;
  830. msg_body.bss_params.max_probe_resp_retry_limit =
  831. orig->bss_params.max_probe_resp_retry_limit;
  832. msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
  833. msg_body.bss_params.proxy_probe_resp =
  834. orig->bss_params.proxy_probe_resp;
  835. msg_body.bss_params.edca_params_valid =
  836. orig->bss_params.edca_params_valid;
  837. memcpy(&msg_body.bss_params.acbe,
  838. &orig->bss_params.acbe,
  839. sizeof(orig->bss_params.acbe));
  840. memcpy(&msg_body.bss_params.acbk,
  841. &orig->bss_params.acbk,
  842. sizeof(orig->bss_params.acbk));
  843. memcpy(&msg_body.bss_params.acvi,
  844. &orig->bss_params.acvi,
  845. sizeof(orig->bss_params.acvi));
  846. memcpy(&msg_body.bss_params.acvo,
  847. &orig->bss_params.acvo,
  848. sizeof(orig->bss_params.acvo));
  849. msg_body.bss_params.ext_set_sta_key_param_valid =
  850. orig->bss_params.ext_set_sta_key_param_valid;
  851. memcpy(&msg_body.bss_params.ext_set_sta_key_param,
  852. &orig->bss_params.ext_set_sta_key_param,
  853. sizeof(orig->bss_params.acvo));
  854. msg_body.bss_params.wcn36xx_hal_persona =
  855. orig->bss_params.wcn36xx_hal_persona;
  856. msg_body.bss_params.spectrum_mgt_enable =
  857. orig->bss_params.spectrum_mgt_enable;
  858. msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
  859. msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
  860. wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
  861. &msg_body.bss_params.sta);
  862. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  863. wcn36xx_dbg(WCN36XX_DBG_HAL,
  864. "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
  865. bss->bssid, bss->self_mac_addr, bss->bss_type,
  866. bss->oper_mode, bss->nw_type);
  867. wcn36xx_dbg(WCN36XX_DBG_HAL,
  868. "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
  869. sta->bssid, sta->action, sta->sta_index,
  870. sta->bssid_index, sta->aid, sta->type, sta->mac);
  871. return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  872. }
  873. static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
  874. struct ieee80211_vif *vif,
  875. void *buf,
  876. size_t len)
  877. {
  878. struct wcn36xx_hal_config_bss_rsp_msg *rsp;
  879. struct wcn36xx_hal_config_bss_rsp_params *params;
  880. struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
  881. if (len < sizeof(*rsp))
  882. return -EINVAL;
  883. rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
  884. params = &rsp->bss_rsp_params;
  885. if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
  886. wcn36xx_warn("hal config bss response failure: %d\n",
  887. params->status);
  888. return -EIO;
  889. }
  890. wcn36xx_dbg(WCN36XX_DBG_HAL,
  891. "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
  892. " sta_idx %d self_idx %d bcast_idx %d mac %pM"
  893. " power %d ucast_dpu_signature %d\n",
  894. params->status, params->bss_index, params->dpu_desc_index,
  895. params->bss_sta_index, params->bss_self_sta_index,
  896. params->bss_bcast_sta_idx, params->mac,
  897. params->tx_mgmt_power, params->ucast_dpu_signature);
  898. priv_vif->bss_index = params->bss_index;
  899. if (priv_vif->sta) {
  900. priv_vif->sta->bss_sta_index = params->bss_sta_index;
  901. priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index;
  902. }
  903. priv_vif->ucast_dpu_signature = params->ucast_dpu_signature;
  904. return 0;
  905. }
  906. int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
  907. struct ieee80211_sta *sta, const u8 *bssid,
  908. bool update)
  909. {
  910. struct wcn36xx_hal_config_bss_req_msg msg;
  911. struct wcn36xx_hal_config_bss_params *bss;
  912. struct wcn36xx_hal_config_sta_params *sta_params;
  913. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  914. int ret = 0;
  915. mutex_lock(&wcn->hal_mutex);
  916. INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
  917. bss = &msg.bss_params;
  918. sta_params = &bss->sta;
  919. WARN_ON(is_zero_ether_addr(bssid));
  920. memcpy(&bss->bssid, bssid, ETH_ALEN);
  921. memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
  922. if (vif->type == NL80211_IFTYPE_STATION) {
  923. bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
  924. /* STA */
  925. bss->oper_mode = 1;
  926. bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
  927. } else if (vif->type == NL80211_IFTYPE_AP) {
  928. bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
  929. /* AP */
  930. bss->oper_mode = 0;
  931. bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
  932. } else if (vif->type == NL80211_IFTYPE_ADHOC ||
  933. vif->type == NL80211_IFTYPE_MESH_POINT) {
  934. bss->bss_type = WCN36XX_HAL_IBSS_MODE;
  935. /* STA */
  936. bss->oper_mode = 1;
  937. } else {
  938. wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
  939. }
  940. if (vif->type == NL80211_IFTYPE_STATION)
  941. wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
  942. else
  943. bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
  944. bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
  945. bss->lla_coexist = 0;
  946. bss->llb_coexist = 0;
  947. bss->llg_coexist = 0;
  948. bss->rifs_mode = 0;
  949. bss->beacon_interval = vif->bss_conf.beacon_int;
  950. bss->dtim_period = vif_priv->dtim_period;
  951. wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
  952. bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
  953. if (conf_is_ht40_minus(&wcn->hw->conf))
  954. bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  955. else if (conf_is_ht40_plus(&wcn->hw->conf))
  956. bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  957. else
  958. bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  959. bss->reserved = 0;
  960. wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
  961. /* wcn->ssid is only valid in AP and IBSS mode */
  962. bss->ssid.length = vif_priv->ssid.length;
  963. memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
  964. bss->obss_prot_enabled = 0;
  965. bss->rmf = 0;
  966. bss->max_probe_resp_retry_limit = 0;
  967. bss->hidden_ssid = vif->bss_conf.hidden_ssid;
  968. bss->proxy_probe_resp = 0;
  969. bss->edca_params_valid = 0;
  970. /* FIXME: set acbe, acbk, acvi and acvo */
  971. bss->ext_set_sta_key_param_valid = 0;
  972. /* FIXME: set ext_set_sta_key_param */
  973. bss->spectrum_mgt_enable = 0;
  974. bss->tx_mgmt_power = 0;
  975. bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
  976. bss->action = update;
  977. wcn36xx_dbg(WCN36XX_DBG_HAL,
  978. "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
  979. bss->bssid, bss->self_mac_addr, bss->bss_type,
  980. bss->oper_mode, bss->nw_type);
  981. wcn36xx_dbg(WCN36XX_DBG_HAL,
  982. "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
  983. sta_params->bssid, sta_params->action,
  984. sta_params->sta_index, sta_params->bssid_index,
  985. sta_params->aid, sta_params->type,
  986. sta_params->mac);
  987. if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
  988. ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
  989. } else {
  990. PREPARE_HAL_BUF(wcn->hal_buf, msg);
  991. ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
  992. }
  993. if (ret) {
  994. wcn36xx_err("Sending hal_config_bss failed\n");
  995. goto out;
  996. }
  997. ret = wcn36xx_smd_config_bss_rsp(wcn,
  998. vif,
  999. wcn->hal_buf,
  1000. wcn->hal_rsp_len);
  1001. if (ret) {
  1002. wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
  1003. goto out;
  1004. }
  1005. out:
  1006. mutex_unlock(&wcn->hal_mutex);
  1007. return ret;
  1008. }
  1009. int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
  1010. {
  1011. struct wcn36xx_hal_delete_bss_req_msg msg_body;
  1012. struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
  1013. int ret = 0;
  1014. mutex_lock(&wcn->hal_mutex);
  1015. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
  1016. msg_body.bss_index = priv_vif->bss_index;
  1017. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1018. wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
  1019. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1020. if (ret) {
  1021. wcn36xx_err("Sending hal_delete_bss failed\n");
  1022. goto out;
  1023. }
  1024. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1025. if (ret) {
  1026. wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
  1027. goto out;
  1028. }
  1029. out:
  1030. mutex_unlock(&wcn->hal_mutex);
  1031. return ret;
  1032. }
  1033. int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
  1034. struct sk_buff *skb_beacon, u16 tim_off,
  1035. u16 p2p_off)
  1036. {
  1037. struct wcn36xx_hal_send_beacon_req_msg msg_body;
  1038. int ret = 0;
  1039. mutex_lock(&wcn->hal_mutex);
  1040. INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
  1041. /* TODO need to find out why this is needed? */
  1042. msg_body.beacon_length = skb_beacon->len + 6;
  1043. if (BEACON_TEMPLATE_SIZE > msg_body.beacon_length) {
  1044. memcpy(&msg_body.beacon, &skb_beacon->len, sizeof(u32));
  1045. memcpy(&(msg_body.beacon[4]), skb_beacon->data,
  1046. skb_beacon->len);
  1047. } else {
  1048. wcn36xx_err("Beacon is to big: beacon size=%d\n",
  1049. msg_body.beacon_length);
  1050. ret = -ENOMEM;
  1051. goto out;
  1052. }
  1053. memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
  1054. /* TODO need to find out why this is needed? */
  1055. msg_body.tim_ie_offset = tim_off+4;
  1056. msg_body.p2p_ie_offset = p2p_off;
  1057. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1058. wcn36xx_dbg(WCN36XX_DBG_HAL,
  1059. "hal send beacon beacon_length %d\n",
  1060. msg_body.beacon_length);
  1061. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1062. if (ret) {
  1063. wcn36xx_err("Sending hal_send_beacon failed\n");
  1064. goto out;
  1065. }
  1066. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1067. if (ret) {
  1068. wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
  1069. goto out;
  1070. }
  1071. out:
  1072. mutex_unlock(&wcn->hal_mutex);
  1073. return ret;
  1074. }
  1075. int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
  1076. struct ieee80211_vif *vif,
  1077. struct sk_buff *skb)
  1078. {
  1079. struct wcn36xx_hal_send_probe_resp_req_msg msg;
  1080. int ret = 0;
  1081. mutex_lock(&wcn->hal_mutex);
  1082. INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
  1083. if (skb->len > BEACON_TEMPLATE_SIZE) {
  1084. wcn36xx_warn("probe response template is too big: %d\n",
  1085. skb->len);
  1086. ret = -E2BIG;
  1087. goto out;
  1088. }
  1089. msg.probe_resp_template_len = skb->len;
  1090. memcpy(&msg.probe_resp_template, skb->data, skb->len);
  1091. memcpy(msg.bssid, vif->addr, ETH_ALEN);
  1092. PREPARE_HAL_BUF(wcn->hal_buf, msg);
  1093. wcn36xx_dbg(WCN36XX_DBG_HAL,
  1094. "hal update probe rsp len %d bssid %pM\n",
  1095. msg.probe_resp_template_len, msg.bssid);
  1096. ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
  1097. if (ret) {
  1098. wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
  1099. goto out;
  1100. }
  1101. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1102. if (ret) {
  1103. wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
  1104. ret);
  1105. goto out;
  1106. }
  1107. out:
  1108. mutex_unlock(&wcn->hal_mutex);
  1109. return ret;
  1110. }
  1111. int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
  1112. enum ani_ed_type enc_type,
  1113. u8 keyidx,
  1114. u8 keylen,
  1115. u8 *key,
  1116. u8 sta_index)
  1117. {
  1118. struct wcn36xx_hal_set_sta_key_req_msg msg_body;
  1119. int ret = 0;
  1120. mutex_lock(&wcn->hal_mutex);
  1121. INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
  1122. msg_body.set_sta_key_params.sta_index = sta_index;
  1123. msg_body.set_sta_key_params.enc_type = enc_type;
  1124. msg_body.set_sta_key_params.key[0].id = keyidx;
  1125. msg_body.set_sta_key_params.key[0].unicast = 1;
  1126. msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
  1127. msg_body.set_sta_key_params.key[0].pae_role = 0;
  1128. msg_body.set_sta_key_params.key[0].length = keylen;
  1129. memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
  1130. msg_body.set_sta_key_params.single_tid_rc = 1;
  1131. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1132. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1133. if (ret) {
  1134. wcn36xx_err("Sending hal_set_stakey failed\n");
  1135. goto out;
  1136. }
  1137. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1138. if (ret) {
  1139. wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
  1140. goto out;
  1141. }
  1142. out:
  1143. mutex_unlock(&wcn->hal_mutex);
  1144. return ret;
  1145. }
  1146. int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
  1147. enum ani_ed_type enc_type,
  1148. u8 keyidx,
  1149. u8 keylen,
  1150. u8 *key)
  1151. {
  1152. struct wcn36xx_hal_set_bss_key_req_msg msg_body;
  1153. int ret = 0;
  1154. mutex_lock(&wcn->hal_mutex);
  1155. INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
  1156. msg_body.bss_idx = 0;
  1157. msg_body.enc_type = enc_type;
  1158. msg_body.num_keys = 1;
  1159. msg_body.keys[0].id = keyidx;
  1160. msg_body.keys[0].unicast = 0;
  1161. msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
  1162. msg_body.keys[0].pae_role = 0;
  1163. msg_body.keys[0].length = keylen;
  1164. memcpy(msg_body.keys[0].key, key, keylen);
  1165. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1166. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1167. if (ret) {
  1168. wcn36xx_err("Sending hal_set_bsskey failed\n");
  1169. goto out;
  1170. }
  1171. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1172. if (ret) {
  1173. wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
  1174. goto out;
  1175. }
  1176. out:
  1177. mutex_unlock(&wcn->hal_mutex);
  1178. return ret;
  1179. }
  1180. int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
  1181. enum ani_ed_type enc_type,
  1182. u8 keyidx,
  1183. u8 sta_index)
  1184. {
  1185. struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
  1186. int ret = 0;
  1187. mutex_lock(&wcn->hal_mutex);
  1188. INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
  1189. msg_body.sta_idx = sta_index;
  1190. msg_body.enc_type = enc_type;
  1191. msg_body.key_id = keyidx;
  1192. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1193. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1194. if (ret) {
  1195. wcn36xx_err("Sending hal_remove_stakey failed\n");
  1196. goto out;
  1197. }
  1198. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1199. if (ret) {
  1200. wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
  1201. goto out;
  1202. }
  1203. out:
  1204. mutex_unlock(&wcn->hal_mutex);
  1205. return ret;
  1206. }
  1207. int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
  1208. enum ani_ed_type enc_type,
  1209. u8 keyidx)
  1210. {
  1211. struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
  1212. int ret = 0;
  1213. mutex_lock(&wcn->hal_mutex);
  1214. INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
  1215. msg_body.bss_idx = 0;
  1216. msg_body.enc_type = enc_type;
  1217. msg_body.key_id = keyidx;
  1218. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1219. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1220. if (ret) {
  1221. wcn36xx_err("Sending hal_remove_bsskey failed\n");
  1222. goto out;
  1223. }
  1224. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1225. if (ret) {
  1226. wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
  1227. goto out;
  1228. }
  1229. out:
  1230. mutex_unlock(&wcn->hal_mutex);
  1231. return ret;
  1232. }
  1233. int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
  1234. {
  1235. struct wcn36xx_hal_enter_bmps_req_msg msg_body;
  1236. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  1237. int ret = 0;
  1238. mutex_lock(&wcn->hal_mutex);
  1239. INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
  1240. msg_body.bss_index = vif_priv->bss_index;
  1241. msg_body.tbtt = vif->bss_conf.sync_tsf;
  1242. msg_body.dtim_period = vif_priv->dtim_period;
  1243. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1244. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1245. if (ret) {
  1246. wcn36xx_err("Sending hal_enter_bmps failed\n");
  1247. goto out;
  1248. }
  1249. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1250. if (ret) {
  1251. wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
  1252. goto out;
  1253. }
  1254. out:
  1255. mutex_unlock(&wcn->hal_mutex);
  1256. return ret;
  1257. }
  1258. int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
  1259. {
  1260. struct wcn36xx_hal_enter_bmps_req_msg msg_body;
  1261. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  1262. int ret = 0;
  1263. mutex_lock(&wcn->hal_mutex);
  1264. INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
  1265. msg_body.bss_index = vif_priv->bss_index;
  1266. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1267. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1268. if (ret) {
  1269. wcn36xx_err("Sending hal_exit_bmps failed\n");
  1270. goto out;
  1271. }
  1272. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1273. if (ret) {
  1274. wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
  1275. goto out;
  1276. }
  1277. out:
  1278. mutex_unlock(&wcn->hal_mutex);
  1279. return ret;
  1280. }
  1281. int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
  1282. {
  1283. struct wcn36xx_hal_set_power_params_req_msg msg_body;
  1284. int ret = 0;
  1285. mutex_lock(&wcn->hal_mutex);
  1286. INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
  1287. /*
  1288. * When host is down ignore every second dtim
  1289. */
  1290. if (ignore_dtim) {
  1291. msg_body.ignore_dtim = 1;
  1292. msg_body.dtim_period = 2;
  1293. }
  1294. msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
  1295. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1296. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1297. if (ret) {
  1298. wcn36xx_err("Sending hal_set_power_params failed\n");
  1299. goto out;
  1300. }
  1301. out:
  1302. mutex_unlock(&wcn->hal_mutex);
  1303. return ret;
  1304. }
  1305. /* Notice: This function should be called after associated, or else it
  1306. * will be invalid
  1307. */
  1308. int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
  1309. struct ieee80211_vif *vif,
  1310. int packet_type)
  1311. {
  1312. struct wcn36xx_hal_keep_alive_req_msg msg_body;
  1313. struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
  1314. int ret = 0;
  1315. mutex_lock(&wcn->hal_mutex);
  1316. INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
  1317. if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
  1318. msg_body.bss_index = vif_priv->bss_index;
  1319. msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
  1320. msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
  1321. } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
  1322. /* TODO: it also support ARP response type */
  1323. } else {
  1324. wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
  1325. ret = -EINVAL;
  1326. goto out;
  1327. }
  1328. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1329. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1330. if (ret) {
  1331. wcn36xx_err("Sending hal_exit_bmps failed\n");
  1332. goto out;
  1333. }
  1334. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1335. if (ret) {
  1336. wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
  1337. goto out;
  1338. }
  1339. out:
  1340. mutex_unlock(&wcn->hal_mutex);
  1341. return ret;
  1342. }
  1343. int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
  1344. u32 arg3, u32 arg4, u32 arg5)
  1345. {
  1346. struct wcn36xx_hal_dump_cmd_req_msg msg_body;
  1347. int ret = 0;
  1348. mutex_lock(&wcn->hal_mutex);
  1349. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
  1350. msg_body.arg1 = arg1;
  1351. msg_body.arg2 = arg2;
  1352. msg_body.arg3 = arg3;
  1353. msg_body.arg4 = arg4;
  1354. msg_body.arg5 = arg5;
  1355. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1356. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1357. if (ret) {
  1358. wcn36xx_err("Sending hal_dump_cmd failed\n");
  1359. goto out;
  1360. }
  1361. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1362. if (ret) {
  1363. wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
  1364. goto out;
  1365. }
  1366. out:
  1367. mutex_unlock(&wcn->hal_mutex);
  1368. return ret;
  1369. }
  1370. static inline void set_feat_caps(u32 *bitmap,
  1371. enum place_holder_in_cap_bitmap cap)
  1372. {
  1373. int arr_idx, bit_idx;
  1374. if (cap < 0 || cap > 127) {
  1375. wcn36xx_warn("error cap idx %d\n", cap);
  1376. return;
  1377. }
  1378. arr_idx = cap / 32;
  1379. bit_idx = cap % 32;
  1380. bitmap[arr_idx] |= (1 << bit_idx);
  1381. }
  1382. static inline int get_feat_caps(u32 *bitmap,
  1383. enum place_holder_in_cap_bitmap cap)
  1384. {
  1385. int arr_idx, bit_idx;
  1386. int ret = 0;
  1387. if (cap < 0 || cap > 127) {
  1388. wcn36xx_warn("error cap idx %d\n", cap);
  1389. return -EINVAL;
  1390. }
  1391. arr_idx = cap / 32;
  1392. bit_idx = cap % 32;
  1393. ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
  1394. return ret;
  1395. }
  1396. static inline void clear_feat_caps(u32 *bitmap,
  1397. enum place_holder_in_cap_bitmap cap)
  1398. {
  1399. int arr_idx, bit_idx;
  1400. if (cap < 0 || cap > 127) {
  1401. wcn36xx_warn("error cap idx %d\n", cap);
  1402. return;
  1403. }
  1404. arr_idx = cap / 32;
  1405. bit_idx = cap % 32;
  1406. bitmap[arr_idx] &= ~(1 << bit_idx);
  1407. }
  1408. int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
  1409. {
  1410. struct wcn36xx_hal_feat_caps_msg msg_body;
  1411. int ret = 0;
  1412. mutex_lock(&wcn->hal_mutex);
  1413. INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
  1414. set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
  1415. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1416. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1417. if (ret) {
  1418. wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
  1419. goto out;
  1420. }
  1421. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1422. if (ret) {
  1423. wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n",
  1424. ret);
  1425. goto out;
  1426. }
  1427. out:
  1428. mutex_unlock(&wcn->hal_mutex);
  1429. return ret;
  1430. }
  1431. int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
  1432. struct ieee80211_sta *sta,
  1433. u16 tid,
  1434. u16 *ssn,
  1435. u8 direction,
  1436. u8 sta_index)
  1437. {
  1438. struct wcn36xx_hal_add_ba_session_req_msg msg_body;
  1439. int ret = 0;
  1440. mutex_lock(&wcn->hal_mutex);
  1441. INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
  1442. msg_body.sta_index = sta_index;
  1443. memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
  1444. msg_body.dialog_token = 0x10;
  1445. msg_body.tid = tid;
  1446. /* Immediate BA because Delayed BA is not supported */
  1447. msg_body.policy = 1;
  1448. msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
  1449. msg_body.timeout = 0;
  1450. if (ssn)
  1451. msg_body.ssn = *ssn;
  1452. msg_body.direction = direction;
  1453. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1454. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1455. if (ret) {
  1456. wcn36xx_err("Sending hal_add_ba_session failed\n");
  1457. goto out;
  1458. }
  1459. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1460. if (ret) {
  1461. wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
  1462. goto out;
  1463. }
  1464. out:
  1465. mutex_unlock(&wcn->hal_mutex);
  1466. return ret;
  1467. }
  1468. int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
  1469. {
  1470. struct wcn36xx_hal_add_ba_req_msg msg_body;
  1471. int ret = 0;
  1472. mutex_lock(&wcn->hal_mutex);
  1473. INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
  1474. msg_body.session_id = 0;
  1475. msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
  1476. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1477. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1478. if (ret) {
  1479. wcn36xx_err("Sending hal_add_ba failed\n");
  1480. goto out;
  1481. }
  1482. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1483. if (ret) {
  1484. wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
  1485. goto out;
  1486. }
  1487. out:
  1488. mutex_unlock(&wcn->hal_mutex);
  1489. return ret;
  1490. }
  1491. int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
  1492. {
  1493. struct wcn36xx_hal_del_ba_req_msg msg_body;
  1494. int ret = 0;
  1495. mutex_lock(&wcn->hal_mutex);
  1496. INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
  1497. msg_body.sta_index = sta_index;
  1498. msg_body.tid = tid;
  1499. msg_body.direction = 0;
  1500. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1501. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1502. if (ret) {
  1503. wcn36xx_err("Sending hal_del_ba failed\n");
  1504. goto out;
  1505. }
  1506. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1507. if (ret) {
  1508. wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
  1509. goto out;
  1510. }
  1511. out:
  1512. mutex_unlock(&wcn->hal_mutex);
  1513. return ret;
  1514. }
  1515. int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
  1516. {
  1517. struct wcn36xx_hal_trigger_ba_req_msg msg_body;
  1518. struct wcn36xx_hal_trigget_ba_req_candidate *candidate;
  1519. int ret = 0;
  1520. mutex_lock(&wcn->hal_mutex);
  1521. INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
  1522. msg_body.session_id = 0;
  1523. msg_body.candidate_cnt = 1;
  1524. msg_body.header.len += sizeof(*candidate);
  1525. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1526. candidate = (struct wcn36xx_hal_trigget_ba_req_candidate *)
  1527. (wcn->hal_buf + sizeof(msg_body));
  1528. candidate->sta_index = sta_index;
  1529. candidate->tid_bitmap = 1;
  1530. ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
  1531. if (ret) {
  1532. wcn36xx_err("Sending hal_trigger_ba failed\n");
  1533. goto out;
  1534. }
  1535. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1536. if (ret) {
  1537. wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
  1538. goto out;
  1539. }
  1540. out:
  1541. mutex_unlock(&wcn->hal_mutex);
  1542. return ret;
  1543. }
  1544. static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
  1545. {
  1546. struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
  1547. if (len != sizeof(*rsp)) {
  1548. wcn36xx_warn("Bad TX complete indication\n");
  1549. return -EIO;
  1550. }
  1551. wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
  1552. return 0;
  1553. }
  1554. static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
  1555. void *buf,
  1556. size_t len)
  1557. {
  1558. struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
  1559. struct ieee80211_vif *vif = NULL;
  1560. struct wcn36xx_vif *tmp;
  1561. /* Old FW does not have bss index */
  1562. if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
  1563. list_for_each_entry(tmp, &wcn->vif_list, list) {
  1564. wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
  1565. tmp->bss_index);
  1566. vif = container_of((void *)tmp,
  1567. struct ieee80211_vif,
  1568. drv_priv);
  1569. ieee80211_connection_loss(vif);
  1570. }
  1571. return 0;
  1572. }
  1573. if (len != sizeof(*rsp)) {
  1574. wcn36xx_warn("Corrupted missed beacon indication\n");
  1575. return -EIO;
  1576. }
  1577. list_for_each_entry(tmp, &wcn->vif_list, list) {
  1578. if (tmp->bss_index == rsp->bss_index) {
  1579. wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
  1580. rsp->bss_index);
  1581. vif = container_of((void *)tmp,
  1582. struct ieee80211_vif,
  1583. drv_priv);
  1584. ieee80211_connection_loss(vif);
  1585. return 0;
  1586. }
  1587. }
  1588. wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
  1589. return -ENOENT;
  1590. }
  1591. static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
  1592. void *buf,
  1593. size_t len)
  1594. {
  1595. struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
  1596. struct wcn36xx_vif *tmp;
  1597. struct ieee80211_sta *sta = NULL;
  1598. if (len != sizeof(*rsp)) {
  1599. wcn36xx_warn("Corrupted delete sta indication\n");
  1600. return -EIO;
  1601. }
  1602. list_for_each_entry(tmp, &wcn->vif_list, list) {
  1603. if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
  1604. sta = container_of((void *)tmp->sta,
  1605. struct ieee80211_sta,
  1606. drv_priv);
  1607. wcn36xx_dbg(WCN36XX_DBG_HAL,
  1608. "delete station indication %pM index %d\n",
  1609. rsp->addr2,
  1610. rsp->sta_id);
  1611. ieee80211_report_low_ack(sta, 0);
  1612. return 0;
  1613. }
  1614. }
  1615. wcn36xx_warn("STA with addr %pM and index %d not found\n",
  1616. rsp->addr2,
  1617. rsp->sta_id);
  1618. return -ENOENT;
  1619. }
  1620. int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
  1621. {
  1622. struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
  1623. size_t len;
  1624. int ret = 0;
  1625. mutex_lock(&wcn->hal_mutex);
  1626. INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
  1627. PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
  1628. body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
  1629. len = msg_body.header.len;
  1630. put_cfg_tlv_u32(wcn, &len, cfg_id, value);
  1631. body->header.len = len;
  1632. body->len = len - sizeof(*body);
  1633. ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
  1634. if (ret) {
  1635. wcn36xx_err("Sending hal_update_cfg failed\n");
  1636. goto out;
  1637. }
  1638. ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
  1639. if (ret) {
  1640. wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
  1641. goto out;
  1642. }
  1643. out:
  1644. mutex_unlock(&wcn->hal_mutex);
  1645. return ret;
  1646. }
  1647. static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
  1648. {
  1649. struct wcn36xx_hal_msg_header *msg_header = buf;
  1650. struct wcn36xx_hal_ind_msg *msg_ind;
  1651. wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
  1652. switch (msg_header->msg_type) {
  1653. case WCN36XX_HAL_START_RSP:
  1654. case WCN36XX_HAL_CONFIG_STA_RSP:
  1655. case WCN36XX_HAL_CONFIG_BSS_RSP:
  1656. case WCN36XX_HAL_ADD_STA_SELF_RSP:
  1657. case WCN36XX_HAL_STOP_RSP:
  1658. case WCN36XX_HAL_DEL_STA_SELF_RSP:
  1659. case WCN36XX_HAL_DELETE_STA_RSP:
  1660. case WCN36XX_HAL_INIT_SCAN_RSP:
  1661. case WCN36XX_HAL_START_SCAN_RSP:
  1662. case WCN36XX_HAL_END_SCAN_RSP:
  1663. case WCN36XX_HAL_FINISH_SCAN_RSP:
  1664. case WCN36XX_HAL_DOWNLOAD_NV_RSP:
  1665. case WCN36XX_HAL_DELETE_BSS_RSP:
  1666. case WCN36XX_HAL_SEND_BEACON_RSP:
  1667. case WCN36XX_HAL_SET_LINK_ST_RSP:
  1668. case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
  1669. case WCN36XX_HAL_SET_BSSKEY_RSP:
  1670. case WCN36XX_HAL_SET_STAKEY_RSP:
  1671. case WCN36XX_HAL_RMV_STAKEY_RSP:
  1672. case WCN36XX_HAL_RMV_BSSKEY_RSP:
  1673. case WCN36XX_HAL_ENTER_BMPS_RSP:
  1674. case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
  1675. case WCN36XX_HAL_EXIT_BMPS_RSP:
  1676. case WCN36XX_HAL_KEEP_ALIVE_RSP:
  1677. case WCN36XX_HAL_DUMP_COMMAND_RSP:
  1678. case WCN36XX_HAL_ADD_BA_SESSION_RSP:
  1679. case WCN36XX_HAL_ADD_BA_RSP:
  1680. case WCN36XX_HAL_DEL_BA_RSP:
  1681. case WCN36XX_HAL_TRIGGER_BA_RSP:
  1682. case WCN36XX_HAL_UPDATE_CFG_RSP:
  1683. case WCN36XX_HAL_JOIN_RSP:
  1684. case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
  1685. case WCN36XX_HAL_CH_SWITCH_RSP:
  1686. case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
  1687. memcpy(wcn->hal_buf, buf, len);
  1688. wcn->hal_rsp_len = len;
  1689. complete(&wcn->hal_rsp_compl);
  1690. break;
  1691. case WCN36XX_HAL_OTA_TX_COMPL_IND:
  1692. case WCN36XX_HAL_MISSED_BEACON_IND:
  1693. case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
  1694. mutex_lock(&wcn->hal_ind_mutex);
  1695. msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
  1696. if (msg_ind) {
  1697. msg_ind->msg_len = len;
  1698. msg_ind->msg = kmalloc(len, GFP_KERNEL);
  1699. memcpy(msg_ind->msg, buf, len);
  1700. list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
  1701. queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
  1702. wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
  1703. }
  1704. mutex_unlock(&wcn->hal_ind_mutex);
  1705. if (msg_ind)
  1706. break;
  1707. /* FIXME: Do something smarter then just printing an error. */
  1708. wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
  1709. msg_header->msg_type);
  1710. break;
  1711. default:
  1712. wcn36xx_err("SMD_EVENT (%d) not supported\n",
  1713. msg_header->msg_type);
  1714. }
  1715. }
  1716. static void wcn36xx_ind_smd_work(struct work_struct *work)
  1717. {
  1718. struct wcn36xx *wcn =
  1719. container_of(work, struct wcn36xx, hal_ind_work);
  1720. struct wcn36xx_hal_msg_header *msg_header;
  1721. struct wcn36xx_hal_ind_msg *hal_ind_msg;
  1722. mutex_lock(&wcn->hal_ind_mutex);
  1723. hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
  1724. struct wcn36xx_hal_ind_msg,
  1725. list);
  1726. msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
  1727. switch (msg_header->msg_type) {
  1728. case WCN36XX_HAL_OTA_TX_COMPL_IND:
  1729. wcn36xx_smd_tx_compl_ind(wcn,
  1730. hal_ind_msg->msg,
  1731. hal_ind_msg->msg_len);
  1732. break;
  1733. case WCN36XX_HAL_MISSED_BEACON_IND:
  1734. wcn36xx_smd_missed_beacon_ind(wcn,
  1735. hal_ind_msg->msg,
  1736. hal_ind_msg->msg_len);
  1737. break;
  1738. case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
  1739. wcn36xx_smd_delete_sta_context_ind(wcn,
  1740. hal_ind_msg->msg,
  1741. hal_ind_msg->msg_len);
  1742. break;
  1743. default:
  1744. wcn36xx_err("SMD_EVENT (%d) not supported\n",
  1745. msg_header->msg_type);
  1746. }
  1747. list_del(wcn->hal_ind_queue.next);
  1748. kfree(hal_ind_msg->msg);
  1749. kfree(hal_ind_msg);
  1750. mutex_unlock(&wcn->hal_ind_mutex);
  1751. }
  1752. int wcn36xx_smd_open(struct wcn36xx *wcn)
  1753. {
  1754. int ret = 0;
  1755. wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
  1756. if (!wcn->hal_ind_wq) {
  1757. wcn36xx_err("failed to allocate wq\n");
  1758. ret = -ENOMEM;
  1759. goto out;
  1760. }
  1761. INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
  1762. INIT_LIST_HEAD(&wcn->hal_ind_queue);
  1763. mutex_init(&wcn->hal_ind_mutex);
  1764. ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
  1765. if (ret) {
  1766. wcn36xx_err("failed to open control channel\n");
  1767. goto free_wq;
  1768. }
  1769. return ret;
  1770. free_wq:
  1771. destroy_workqueue(wcn->hal_ind_wq);
  1772. out:
  1773. return ret;
  1774. }
  1775. void wcn36xx_smd_close(struct wcn36xx *wcn)
  1776. {
  1777. wcn->ctrl_ops->close();
  1778. destroy_workqueue(wcn->hal_ind_wq);
  1779. mutex_destroy(&wcn->hal_ind_mutex);
  1780. }