smd.c 61 KB

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