smd.c 58 KB

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