smd.c 58 KB

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