smd.c 64 KB

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