smd.c 61 KB

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