smd.c 64 KB

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