smd.c 60 KB

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