wmi_unified_tlv.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906
  1. /*
  2. * Copyright (c) 2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #include "wmi_unified_tlv.h"
  27. #include "wmi_unified_api.h"
  28. #include "wmi.h"
  29. #include "wmi_unified_priv.h"
  30. #include "wma_api.h"
  31. #include "wma.h"
  32. /**
  33. * send_vdev_create_cmd_tlv() - send VDEV create command to fw
  34. * @wmi_handle: wmi handle
  35. * @param: pointer to hold vdev create parameter
  36. * @macaddr: vdev mac address
  37. *
  38. * Return: 0 for success or error code
  39. */
  40. int32_t send_vdev_create_cmd_tlv(wmi_unified_t wmi_handle,
  41. uint8_t macaddr[IEEE80211_ADDR_LEN],
  42. struct vdev_create_params *param)
  43. {
  44. wmi_vdev_create_cmd_fixed_param *cmd;
  45. wmi_buf_t buf;
  46. int32_t len = sizeof(*cmd);
  47. int32_t ret;
  48. buf = wmi_buf_alloc(wmi_handle, len);
  49. if (!buf) {
  50. WMA_LOGP("%s:wmi_buf_alloc failed", __func__);
  51. return -ENOMEM;
  52. }
  53. cmd = (wmi_vdev_create_cmd_fixed_param *) wmi_buf_data(buf);
  54. WMITLV_SET_HDR(&cmd->tlv_header,
  55. WMITLV_TAG_STRUC_wmi_vdev_create_cmd_fixed_param,
  56. WMITLV_GET_STRUCT_TLVLEN
  57. (wmi_vdev_create_cmd_fixed_param));
  58. cmd->vdev_id = param->if_id;
  59. cmd->vdev_type = param->type;
  60. cmd->vdev_subtype = param->subtype;
  61. WMI_CHAR_ARRAY_TO_MAC_ADDR(macaddr, &cmd->vdev_macaddr);
  62. WMA_LOGD("%s: ID = %d VAP Addr = %02x:%02x:%02x:%02x:%02x:%02x",
  63. __func__, param->if_id,
  64. macaddr[0], macaddr[1], macaddr[2],
  65. macaddr[3], macaddr[4], macaddr[5]);
  66. ret = wmi_unified_cmd_send(wmi_handle, buf, len, WMI_VDEV_CREATE_CMDID);
  67. if (ret != EOK) {
  68. WMA_LOGE("Failed to send WMI_VDEV_CREATE_CMDID");
  69. wmi_buf_free(buf);
  70. }
  71. return ret;
  72. }
  73. /**
  74. * send_vdev_delete_cmd_tlv() - send VDEV delete command to fw
  75. * @wmi_handle: wmi handle
  76. * @if_id: vdev id
  77. *
  78. * Return: 0 for success or error code
  79. */
  80. int32_t send_vdev_delete_cmd_tlv(wmi_unified_t wmi_handle,
  81. uint8_t if_id)
  82. {
  83. wmi_vdev_delete_cmd_fixed_param *cmd;
  84. wmi_buf_t buf;
  85. int32_t ret;
  86. buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
  87. if (!buf) {
  88. WMA_LOGP("%s:wmi_buf_alloc failed", __func__);
  89. return -ENOMEM;
  90. }
  91. cmd = (wmi_vdev_delete_cmd_fixed_param *) wmi_buf_data(buf);
  92. WMITLV_SET_HDR(&cmd->tlv_header,
  93. WMITLV_TAG_STRUC_wmi_vdev_delete_cmd_fixed_param,
  94. WMITLV_GET_STRUCT_TLVLEN
  95. (wmi_vdev_delete_cmd_fixed_param));
  96. cmd->vdev_id = if_id;
  97. ret = wmi_unified_cmd_send(wmi_handle, buf,
  98. sizeof(wmi_vdev_delete_cmd_fixed_param),
  99. WMI_VDEV_DELETE_CMDID);
  100. if (ret != EOK) {
  101. WMA_LOGE("Failed to send WMI_VDEV_DELETE_CMDID");
  102. wmi_buf_free(buf);
  103. }
  104. WMA_LOGD("%s:vdev id = %d", __func__, if_id);
  105. return ret;
  106. }
  107. /**
  108. * send_vdev_stop_cmd_tlv() - send vdev stop command to fw
  109. * @wmi: wmi handle
  110. * @vdev_id: vdev id
  111. *
  112. * Return: 0 for success or erro code
  113. */
  114. int32_t send_vdev_stop_cmd_tlv(wmi_unified_t wmi,
  115. uint8_t vdev_id)
  116. {
  117. wmi_vdev_stop_cmd_fixed_param *cmd;
  118. wmi_buf_t buf;
  119. int32_t len = sizeof(*cmd);
  120. buf = wmi_buf_alloc(wmi, len);
  121. if (!buf) {
  122. WMA_LOGP("%s : wmi_buf_alloc failed", __func__);
  123. return -ENOMEM;
  124. }
  125. cmd = (wmi_vdev_stop_cmd_fixed_param *) wmi_buf_data(buf);
  126. WMITLV_SET_HDR(&cmd->tlv_header,
  127. WMITLV_TAG_STRUC_wmi_vdev_stop_cmd_fixed_param,
  128. WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_stop_cmd_fixed_param));
  129. cmd->vdev_id = vdev_id;
  130. if (wmi_unified_cmd_send(wmi, buf, len, WMI_VDEV_STOP_CMDID)) {
  131. WMA_LOGP("%s: Failed to send vdev stop command", __func__);
  132. cdf_nbuf_free(buf);
  133. return -EIO;
  134. }
  135. return 0;
  136. }
  137. /**
  138. * send_vdev_down_cmd_tlv() - send vdev down command to fw
  139. * @wmi: wmi handle
  140. * @vdev_id: vdev id
  141. *
  142. * Return: 0 for success or error code
  143. */
  144. int32_t send_vdev_down_cmd_tlv(wmi_unified_t wmi, uint8_t vdev_id)
  145. {
  146. wmi_vdev_down_cmd_fixed_param *cmd;
  147. wmi_buf_t buf;
  148. int32_t len = sizeof(*cmd);
  149. buf = wmi_buf_alloc(wmi, len);
  150. if (!buf) {
  151. WMA_LOGP("%s : wmi_buf_alloc failed", __func__);
  152. return -ENOMEM;
  153. }
  154. cmd = (wmi_vdev_down_cmd_fixed_param *) wmi_buf_data(buf);
  155. WMITLV_SET_HDR(&cmd->tlv_header,
  156. WMITLV_TAG_STRUC_wmi_vdev_down_cmd_fixed_param,
  157. WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_down_cmd_fixed_param));
  158. cmd->vdev_id = vdev_id;
  159. if (wmi_unified_cmd_send(wmi, buf, len, WMI_VDEV_DOWN_CMDID)) {
  160. WMA_LOGP("%s: Failed to send vdev down", __func__);
  161. cdf_nbuf_free(buf);
  162. return -EIO;
  163. }
  164. WMA_LOGD("%s: vdev_id %d", __func__, vdev_id);
  165. return 0;
  166. }
  167. /**
  168. * send_peer_flush_tids_cmd_tlv() - flush peer tids packets in fw
  169. * @wmi: wmi handle
  170. * @peer_addr: peer mac address
  171. * @param: pointer to hold peer flush tid parameter
  172. *
  173. * Return: 0 for sucess or error code
  174. */
  175. int32_t send_peer_flush_tids_cmd_tlv(wmi_unified_t wmi,
  176. uint8_t peer_addr[IEEE80211_ADDR_LEN],
  177. struct peer_flush_params *param)
  178. {
  179. wmi_peer_flush_tids_cmd_fixed_param *cmd;
  180. wmi_buf_t buf;
  181. int32_t len = sizeof(*cmd);
  182. buf = wmi_buf_alloc(wmi, len);
  183. if (!buf) {
  184. WMA_LOGP("%s: wmi_buf_alloc failed", __func__);
  185. return -ENOMEM;
  186. }
  187. cmd = (wmi_peer_flush_tids_cmd_fixed_param *) wmi_buf_data(buf);
  188. WMITLV_SET_HDR(&cmd->tlv_header,
  189. WMITLV_TAG_STRUC_wmi_peer_flush_tids_cmd_fixed_param,
  190. WMITLV_GET_STRUCT_TLVLEN
  191. (wmi_peer_flush_tids_cmd_fixed_param));
  192. WMI_CHAR_ARRAY_TO_MAC_ADDR(peer_addr, &cmd->peer_macaddr);
  193. cmd->peer_tid_bitmap = param->peer_tid_bitmap;
  194. cmd->vdev_id = param->vdev_id;
  195. WMA_LOGD("%s: peer_addr %pM vdev_id %d and peer bitmap %d", __func__,
  196. peer_addr, param->vdev_id,
  197. param->peer_tid_bitmap);
  198. if (wmi_unified_cmd_send(wmi, buf, len, WMI_PEER_FLUSH_TIDS_CMDID)) {
  199. WMA_LOGP("%s: Failed to send flush tid command", __func__);
  200. cdf_nbuf_free(buf);
  201. return -EIO;
  202. }
  203. return 0;
  204. }
  205. /**
  206. * send_peer_delete_cmd_tlv() - send PEER delete command to fw
  207. * @wmi: wmi handle
  208. * @peer_addr: peer mac addr
  209. * @vdev_id: vdev id
  210. *
  211. * Return: 0 for success or error code
  212. */
  213. int32_t send_peer_delete_cmd_tlv(wmi_unified_t wmi,
  214. uint8_t peer_addr[IEEE80211_ADDR_LEN],
  215. uint8_t vdev_id)
  216. {
  217. wmi_peer_delete_cmd_fixed_param *cmd;
  218. wmi_buf_t buf;
  219. int32_t len = sizeof(*cmd);
  220. buf = wmi_buf_alloc(wmi, len);
  221. if (!buf) {
  222. WMA_LOGP("%s: wmi_buf_alloc failed", __func__);
  223. return -ENOMEM;
  224. }
  225. cmd = (wmi_peer_delete_cmd_fixed_param *) wmi_buf_data(buf);
  226. WMITLV_SET_HDR(&cmd->tlv_header,
  227. WMITLV_TAG_STRUC_wmi_peer_delete_cmd_fixed_param,
  228. WMITLV_GET_STRUCT_TLVLEN
  229. (wmi_peer_delete_cmd_fixed_param));
  230. WMI_CHAR_ARRAY_TO_MAC_ADDR(peer_addr, &cmd->peer_macaddr);
  231. cmd->vdev_id = vdev_id;
  232. if (wmi_unified_cmd_send(wmi, buf, len, WMI_PEER_DELETE_CMDID)) {
  233. WMA_LOGP("%s: Failed to send peer delete command", __func__);
  234. cdf_nbuf_free(buf);
  235. return -EIO;
  236. }
  237. WMA_LOGD("%s: peer_addr %pM vdev_id %d", __func__, peer_addr, vdev_id);
  238. return 0;
  239. }
  240. /**
  241. * send_peer_param_cmd_tlv() - set peer parameter in fw
  242. * @wma_ctx: wmi handle
  243. * @peer_addr: peer mac address
  244. * @param : pointer to hold peer set parameter
  245. *
  246. * Return: 0 for success or error code
  247. */
  248. int32_t send_peer_param_cmd_tlv(wmi_unified_t wmi,
  249. uint8_t peer_addr[IEEE80211_ADDR_LEN],
  250. struct peer_set_params *param)
  251. {
  252. wmi_peer_set_param_cmd_fixed_param *cmd;
  253. wmi_buf_t buf;
  254. int32_t err;
  255. buf = wmi_buf_alloc(wmi, sizeof(*cmd));
  256. if (!buf) {
  257. WMA_LOGE("Failed to allocate buffer to send set_param cmd");
  258. return -ENOMEM;
  259. }
  260. cmd = (wmi_peer_set_param_cmd_fixed_param *) wmi_buf_data(buf);
  261. WMITLV_SET_HDR(&cmd->tlv_header,
  262. WMITLV_TAG_STRUC_wmi_peer_set_param_cmd_fixed_param,
  263. WMITLV_GET_STRUCT_TLVLEN
  264. (wmi_peer_set_param_cmd_fixed_param));
  265. cmd->vdev_id = param->vdev_id;
  266. WMI_CHAR_ARRAY_TO_MAC_ADDR(peer_addr, &cmd->peer_macaddr);
  267. cmd->param_id = param->param_id;
  268. cmd->param_value = param->param_value;
  269. err = wmi_unified_cmd_send(wmi, buf,
  270. sizeof(wmi_peer_set_param_cmd_fixed_param),
  271. WMI_PEER_SET_PARAM_CMDID);
  272. if (err) {
  273. WMA_LOGE("Failed to send set_param cmd");
  274. cdf_mem_free(buf);
  275. return -EIO;
  276. }
  277. return 0;
  278. }
  279. /**
  280. * send_vdev_up_cmd_tlv() - send vdev up command in fw
  281. * @wmi: wmi handle
  282. * @bssid: bssid
  283. * @vdev_up_params: pointer to hold vdev up parameter
  284. *
  285. * Return: 0 for success or error code
  286. */
  287. int32_t send_vdev_up_cmd_tlv(wmi_unified_t wmi,
  288. uint8_t bssid[IEEE80211_ADDR_LEN],
  289. struct vdev_up_params *params)
  290. {
  291. wmi_vdev_up_cmd_fixed_param *cmd;
  292. wmi_buf_t buf;
  293. int32_t len = sizeof(*cmd);
  294. WMA_LOGD("%s: VDEV_UP", __func__);
  295. WMA_LOGD("%s: vdev_id %d aid %d bssid %pM", __func__,
  296. params->vdev_id, params->assoc_id, bssid);
  297. buf = wmi_buf_alloc(wmi, len);
  298. if (!buf) {
  299. WMA_LOGP("%s: wmi_buf_alloc failed", __func__);
  300. return -ENOMEM;
  301. }
  302. cmd = (wmi_vdev_up_cmd_fixed_param *) wmi_buf_data(buf);
  303. WMITLV_SET_HDR(&cmd->tlv_header,
  304. WMITLV_TAG_STRUC_wmi_vdev_up_cmd_fixed_param,
  305. WMITLV_GET_STRUCT_TLVLEN(wmi_vdev_up_cmd_fixed_param));
  306. cmd->vdev_id = params->vdev_id;
  307. cmd->vdev_assoc_id = params->assoc_id;
  308. WMI_CHAR_ARRAY_TO_MAC_ADDR(bssid, &cmd->vdev_bssid);
  309. if (wmi_unified_cmd_send(wmi, buf, len, WMI_VDEV_UP_CMDID)) {
  310. WMA_LOGP("%s: Failed to send vdev up command", __func__);
  311. cdf_nbuf_free(buf);
  312. return -EIO;
  313. }
  314. return 0;
  315. }
  316. /**
  317. * send_peer_create_cmd_tlv() - send peer create command to fw
  318. * @wmi: wmi handle
  319. * @peer_addr: peer mac address
  320. * @peer_type: peer type
  321. * @vdev_id: vdev id
  322. *
  323. * Return: 0 for success or error code
  324. */
  325. int32_t send_peer_create_cmd_tlv(wmi_unified_t wmi,
  326. struct peer_create_params *param)
  327. {
  328. wmi_peer_create_cmd_fixed_param *cmd;
  329. wmi_buf_t buf;
  330. int32_t len = sizeof(*cmd);
  331. buf = wmi_buf_alloc(wmi, len);
  332. if (!buf) {
  333. WMA_LOGP("%s: wmi_buf_alloc failed", __func__);
  334. return -ENOMEM;
  335. }
  336. cmd = (wmi_peer_create_cmd_fixed_param *) wmi_buf_data(buf);
  337. WMITLV_SET_HDR(&cmd->tlv_header,
  338. WMITLV_TAG_STRUC_wmi_peer_create_cmd_fixed_param,
  339. WMITLV_GET_STRUCT_TLVLEN
  340. (wmi_peer_create_cmd_fixed_param));
  341. WMI_CHAR_ARRAY_TO_MAC_ADDR(param->peer_addr, &cmd->peer_macaddr);
  342. cmd->peer_type = param->peer_type;
  343. cmd->vdev_id = param->vdev_id;
  344. if (wmi_unified_cmd_send(wmi, buf, len, WMI_PEER_CREATE_CMDID)) {
  345. WMA_LOGP("%s: failed to send WMI_PEER_CREATE_CMDID", __func__);
  346. cdf_nbuf_free(buf);
  347. return -EIO;
  348. }
  349. WMA_LOGD("%s: peer_addr %pM vdev_id %d", __func__, param->peer_addr,
  350. param->vdev_id);
  351. return 0;
  352. }
  353. /**
  354. * send_green_ap_ps_cmd_tlv() - enable green ap powersave command
  355. * @wmi_handle: wmi handle
  356. * @value: value
  357. * @mac_id: mac id to have radio context
  358. *
  359. * Return: 0 for success or error code
  360. */
  361. int32_t send_green_ap_ps_cmd_tlv(wmi_unified_t wmi_handle,
  362. uint32_t value, uint8_t mac_id)
  363. {
  364. wmi_pdev_green_ap_ps_enable_cmd_fixed_param *cmd;
  365. wmi_buf_t buf;
  366. int32_t len = sizeof(*cmd);
  367. WMA_LOGD("Set Green AP PS val %d", value);
  368. buf = wmi_buf_alloc(wmi_handle, len);
  369. if (!buf) {
  370. WMA_LOGP("%s: Green AP PS Mem Alloc Failed", __func__);
  371. return -ENOMEM;
  372. }
  373. cmd = (wmi_pdev_green_ap_ps_enable_cmd_fixed_param *) wmi_buf_data(buf);
  374. WMITLV_SET_HDR(&cmd->tlv_header,
  375. WMITLV_TAG_STRUC_wmi_pdev_green_ap_ps_enable_cmd_fixed_param,
  376. WMITLV_GET_STRUCT_TLVLEN
  377. (wmi_pdev_green_ap_ps_enable_cmd_fixed_param));
  378. cmd->reserved0 = 0;
  379. cmd->enable = value;
  380. if (wmi_unified_cmd_send(wmi_handle, buf, len,
  381. WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID)) {
  382. WMA_LOGE("Set Green AP PS param Failed val %d", value);
  383. cdf_nbuf_free(buf);
  384. return -EIO;
  385. }
  386. return 0;
  387. }
  388. /**
  389. * send_pdev_utf_cmd_tlv() - send utf command to fw
  390. * @wmi_handle: wmi handle
  391. * @param: pointer to pdev_utf_params
  392. * @mac_id: mac id to have radio context
  393. *
  394. * Return: 0 for success or error code
  395. */
  396. int32_t
  397. send_pdev_utf_cmd_tlv(wmi_unified_t wmi_handle,
  398. struct pdev_utf_params *param,
  399. uint8_t mac_id)
  400. {
  401. wmi_buf_t buf;
  402. uint8_t *cmd;
  403. int32_t ret = 0;
  404. static uint8_t msgref = 1;
  405. uint8_t segNumber = 0, segInfo, numSegments;
  406. uint16_t chunk_len, total_bytes;
  407. uint8_t *bufpos;
  408. struct seg_hdr_info segHdrInfo;
  409. bufpos = param->utf_payload;
  410. total_bytes = param->len;
  411. ASSERT(total_bytes / MAX_WMI_UTF_LEN ==
  412. (uint8_t) (total_bytes / MAX_WMI_UTF_LEN));
  413. numSegments = (uint8_t) (total_bytes / MAX_WMI_UTF_LEN);
  414. if (param->len - (numSegments * MAX_WMI_UTF_LEN))
  415. numSegments++;
  416. while (param->len) {
  417. if (param->len > MAX_WMI_UTF_LEN)
  418. chunk_len = MAX_WMI_UTF_LEN; /* MAX messsage */
  419. else
  420. chunk_len = param->len;
  421. buf = wmi_buf_alloc(wmi_handle,
  422. (chunk_len + sizeof(segHdrInfo) +
  423. WMI_TLV_HDR_SIZE));
  424. if (!buf) {
  425. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  426. return -ENOMEM;
  427. }
  428. cmd = (uint8_t *) wmi_buf_data(buf);
  429. segHdrInfo.len = total_bytes;
  430. segHdrInfo.msgref = msgref;
  431. segInfo = ((numSegments << 4) & 0xF0) | (segNumber & 0xF);
  432. segHdrInfo.segmentInfo = segInfo;
  433. segHdrInfo.pad = 0;
  434. WMA_LOGD("%s:segHdrInfo.len = %d, segHdrInfo.msgref = %d,"
  435. " segHdrInfo.segmentInfo = %d",
  436. __func__, segHdrInfo.len, segHdrInfo.msgref,
  437. segHdrInfo.segmentInfo);
  438. WMA_LOGD("%s:total_bytes %d segNumber %d totalSegments %d"
  439. "chunk len %d", __func__, total_bytes, segNumber,
  440. numSegments, chunk_len);
  441. segNumber++;
  442. WMITLV_SET_HDR(cmd, WMITLV_TAG_ARRAY_BYTE,
  443. (chunk_len + sizeof(segHdrInfo)));
  444. cmd += WMI_TLV_HDR_SIZE;
  445. memcpy(cmd, &segHdrInfo, sizeof(segHdrInfo)); /* 4 bytes */
  446. memcpy(&cmd[sizeof(segHdrInfo)], bufpos, chunk_len);
  447. ret = wmi_unified_cmd_send(wmi_handle, buf,
  448. (chunk_len + sizeof(segHdrInfo) +
  449. WMI_TLV_HDR_SIZE),
  450. WMI_PDEV_UTF_CMDID);
  451. if (ret != EOK) {
  452. WMA_LOGE("Failed to send WMI_PDEV_UTF_CMDID command");
  453. wmi_buf_free(buf);
  454. break;
  455. }
  456. param->len -= chunk_len;
  457. bufpos += chunk_len;
  458. }
  459. msgref++;
  460. return ret;
  461. }
  462. /**
  463. * send_pdev_param_cmd_tlv() - set pdev parameters
  464. * @wmi_handle: wmi handle
  465. * @param: pointer to pdev parameter
  466. * @mac_id: radio context
  467. *
  468. * Return: 0 on success, errno on failure
  469. */
  470. int32_t
  471. send_pdev_param_cmd_tlv(wmi_unified_t wmi_handle,
  472. struct pdev_params *param,
  473. uint8_t mac_id)
  474. {
  475. int32_t ret;
  476. wmi_pdev_set_param_cmd_fixed_param *cmd;
  477. wmi_buf_t buf;
  478. uint16_t len = sizeof(*cmd);
  479. buf = wmi_buf_alloc(wmi_handle, len);
  480. if (!buf) {
  481. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  482. return -ENOMEM;
  483. }
  484. cmd = (wmi_pdev_set_param_cmd_fixed_param *) wmi_buf_data(buf);
  485. WMITLV_SET_HDR(&cmd->tlv_header,
  486. WMITLV_TAG_STRUC_wmi_pdev_set_param_cmd_fixed_param,
  487. WMITLV_GET_STRUCT_TLVLEN
  488. (wmi_pdev_set_param_cmd_fixed_param));
  489. cmd->reserved0 = 0;
  490. cmd->param_id = param->param_id;
  491. cmd->param_value = param->param_value;
  492. WMA_LOGD("Setting pdev param = %x, value = %u", param->param_id,
  493. param->param_value);
  494. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  495. WMI_PDEV_SET_PARAM_CMDID);
  496. if (ret != EOK) {
  497. WMA_LOGE("Failed to send set param command ret = %d", ret);
  498. wmi_buf_free(buf);
  499. }
  500. return ret;
  501. }
  502. /**
  503. * send_suspend_cmd_tlv() - WMI suspend function
  504. * @param wmi_handle : handle to WMI.
  505. * @param param : pointer to hold suspend parameter
  506. * @mac_id: radio context
  507. *
  508. * Return 0 on success and -ve on failure.
  509. */
  510. int32_t send_suspend_cmd_tlv(wmi_unified_t wmi_handle,
  511. struct suspend_params *param,
  512. uint8_t mac_id)
  513. {
  514. wmi_pdev_suspend_cmd_fixed_param *cmd;
  515. wmi_buf_t wmibuf;
  516. uint32_t len = sizeof(*cmd);
  517. int32_t ret;
  518. /*
  519. * send the comand to Target to ignore the
  520. * PCIE reset so as to ensure that Host and target
  521. * states are in sync
  522. */
  523. wmibuf = wmi_buf_alloc(wmi_handle, len);
  524. if (wmibuf == NULL)
  525. return -ENOMEM;
  526. cmd = (wmi_pdev_suspend_cmd_fixed_param *) wmi_buf_data(wmibuf);
  527. WMITLV_SET_HDR(&cmd->tlv_header,
  528. WMITLV_TAG_STRUC_wmi_pdev_suspend_cmd_fixed_param,
  529. WMITLV_GET_STRUCT_TLVLEN
  530. (wmi_pdev_suspend_cmd_fixed_param));
  531. if (param->disable_target_intr)
  532. cmd->suspend_opt = WMI_PDEV_SUSPEND_AND_DISABLE_INTR;
  533. else
  534. cmd->suspend_opt = WMI_PDEV_SUSPEND;
  535. ret = wmi_unified_cmd_send(wmi_handle, wmibuf, len,
  536. WMI_PDEV_SUSPEND_CMDID);
  537. if (ret) {
  538. cdf_nbuf_free(wmibuf);
  539. WMA_LOGE("Failed to send WMI_PDEV_SUSPEND_CMDID command");
  540. }
  541. return ret;
  542. }
  543. /**
  544. * send_resume_cmd_tlv() - WMI resume function
  545. * @param wmi_handle : handle to WMI.
  546. * @mac_id: radio context
  547. *
  548. * Return: 0 on success and -ve on failure.
  549. */
  550. int32_t send_resume_cmd_tlv(wmi_unified_t wmi_handle,
  551. uint8_t mac_id)
  552. {
  553. wmi_buf_t wmibuf;
  554. wmi_pdev_resume_cmd_fixed_param *cmd;
  555. int32_t ret;
  556. wmibuf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
  557. if (wmibuf == NULL)
  558. return -ENOMEM;
  559. cmd = (wmi_pdev_resume_cmd_fixed_param *) wmi_buf_data(wmibuf);
  560. WMITLV_SET_HDR(&cmd->tlv_header,
  561. WMITLV_TAG_STRUC_wmi_pdev_resume_cmd_fixed_param,
  562. WMITLV_GET_STRUCT_TLVLEN
  563. (wmi_pdev_resume_cmd_fixed_param));
  564. cmd->reserved0 = 0;
  565. ret = wmi_unified_cmd_send(wmi_handle, wmibuf, sizeof(*cmd),
  566. WMI_PDEV_RESUME_CMDID);
  567. if (ret != EOK) {
  568. WMA_LOGE("Failed to send WMI_PDEV_RESUME_CMDID command");
  569. wmi_buf_free(wmibuf);
  570. }
  571. return ret;
  572. }
  573. /**
  574. * send_wow_enable_cmd_tlv() - WMI wow enable function
  575. * @param wmi_handle : handle to WMI.
  576. * @param param : pointer to hold wow enable parameter
  577. * @mac_id: radio context
  578. *
  579. * Return: 0 on success and -ve on failure.
  580. */
  581. int32_t send_wow_enable_cmd_tlv(wmi_unified_t wmi_handle,
  582. struct wow_cmd_params *param,
  583. uint8_t mac_id)
  584. {
  585. wmi_wow_enable_cmd_fixed_param *cmd;
  586. wmi_buf_t buf;
  587. int32_t len;
  588. int32_t ret;
  589. len = sizeof(wmi_wow_enable_cmd_fixed_param);
  590. buf = wmi_buf_alloc(wmi_handle, len);
  591. if (!buf) {
  592. WMA_LOGE("%s: Failed allocate wmi buffer", __func__);
  593. return CDF_STATUS_E_NOMEM;
  594. }
  595. cmd = (wmi_wow_enable_cmd_fixed_param *) wmi_buf_data(buf);
  596. WMITLV_SET_HDR(&cmd->tlv_header,
  597. WMITLV_TAG_STRUC_wmi_wow_enable_cmd_fixed_param,
  598. WMITLV_GET_STRUCT_TLVLEN
  599. (wmi_wow_enable_cmd_fixed_param));
  600. cmd->enable = param->enable;
  601. if (param->can_suspend_link)
  602. cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
  603. else
  604. cmd->pause_iface_config = WOW_IFACE_PAUSE_DISABLED;
  605. WMA_LOGI("suspend type: %s",
  606. cmd->pause_iface_config == WOW_IFACE_PAUSE_ENABLED ?
  607. "WOW_IFACE_PAUSE_ENABLED" : "WOW_IFACE_PAUSE_DISABLED");
  608. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  609. WMI_WOW_ENABLE_CMDID);
  610. if (ret)
  611. wmi_buf_free(buf);
  612. return ret;
  613. }
  614. /**
  615. * send_set_ap_ps_param_cmd_tlv() - set ap powersave parameters
  616. * @wma_ctx: wma context
  617. * @peer_addr: peer mac address
  618. * @param: pointer to ap_ps parameter structure
  619. *
  620. * Return: 0 for success or error code
  621. */
  622. int32_t send_set_ap_ps_param_cmd_tlv(wmi_unified_t wmi_handle,
  623. uint8_t *peer_addr,
  624. struct ap_ps_params *param)
  625. {
  626. wmi_ap_ps_peer_cmd_fixed_param *cmd;
  627. wmi_buf_t buf;
  628. int32_t err;
  629. buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
  630. if (!buf) {
  631. WMA_LOGE("Failed to allocate buffer to send set_ap_ps_param cmd");
  632. return -ENOMEM;
  633. }
  634. cmd = (wmi_ap_ps_peer_cmd_fixed_param *) wmi_buf_data(buf);
  635. WMITLV_SET_HDR(&cmd->tlv_header,
  636. WMITLV_TAG_STRUC_wmi_ap_ps_peer_cmd_fixed_param,
  637. WMITLV_GET_STRUCT_TLVLEN
  638. (wmi_ap_ps_peer_cmd_fixed_param));
  639. cmd->vdev_id = param->vdev_id;
  640. WMI_CHAR_ARRAY_TO_MAC_ADDR(peer_addr, &cmd->peer_macaddr);
  641. cmd->param = param->param;
  642. cmd->value = param->value;
  643. err = wmi_unified_cmd_send(wmi_handle, buf,
  644. sizeof(*cmd), WMI_AP_PS_PEER_PARAM_CMDID);
  645. if (err) {
  646. WMA_LOGE("Failed to send set_ap_ps_param cmd");
  647. cdf_mem_free(buf);
  648. return -EIO;
  649. }
  650. return 0;
  651. }
  652. /**
  653. * send_set_sta_ps_param_cmd_tlv() - set sta powersave parameters
  654. * @wma_ctx: wma context
  655. * @peer_addr: peer mac address
  656. * @param: pointer to sta_ps parameter structure
  657. *
  658. * Return: 0 for success or error code
  659. */
  660. int32_t send_set_sta_ps_param_cmd_tlv(wmi_unified_t wmi_handle,
  661. struct sta_ps_params *param)
  662. {
  663. wmi_sta_powersave_param_cmd_fixed_param *cmd;
  664. wmi_buf_t buf;
  665. int32_t len = sizeof(*cmd);
  666. buf = wmi_buf_alloc(wmi_handle, len);
  667. if (!buf) {
  668. WMA_LOGP("%s: Set Sta Ps param Mem Alloc Failed", __func__);
  669. return -ENOMEM;
  670. }
  671. cmd = (wmi_sta_powersave_param_cmd_fixed_param *) wmi_buf_data(buf);
  672. WMITLV_SET_HDR(&cmd->tlv_header,
  673. WMITLV_TAG_STRUC_wmi_sta_powersave_param_cmd_fixed_param,
  674. WMITLV_GET_STRUCT_TLVLEN
  675. (wmi_sta_powersave_param_cmd_fixed_param));
  676. cmd->vdev_id = param->vdev_id;
  677. cmd->param = param->param;
  678. cmd->value = param->value;
  679. if (wmi_unified_cmd_send(wmi_handle, buf, len,
  680. WMI_STA_POWERSAVE_PARAM_CMDID)) {
  681. WMA_LOGE("Set Sta Ps param Failed vdevId %d Param %d val %d",
  682. param->vdev_id, param->param, param->value);
  683. cdf_nbuf_free(buf);
  684. return -EIO;
  685. }
  686. return 0;
  687. }
  688. /**
  689. * send_crash_inject_cmd_tlv() - inject fw crash
  690. * @wma_handle: wma handle
  691. * @param: ponirt to crash inject paramter structure
  692. *
  693. * Return: 0 for success or return error
  694. */
  695. int32_t send_crash_inject_cmd_tlv(wmi_unified_t wmi_handle,
  696. struct crash_inject *param)
  697. {
  698. int32_t ret = 0;
  699. WMI_FORCE_FW_HANG_CMD_fixed_param *cmd;
  700. uint16_t len = sizeof(*cmd);
  701. wmi_buf_t buf;
  702. buf = wmi_buf_alloc(wmi_handle, len);
  703. if (!buf) {
  704. WMA_LOGE("%s: wmi_buf_alloc failed!", __func__);
  705. return -ENOMEM;
  706. }
  707. cmd = (WMI_FORCE_FW_HANG_CMD_fixed_param *) wmi_buf_data(buf);
  708. WMITLV_SET_HDR(&cmd->tlv_header,
  709. WMITLV_TAG_STRUC_WMI_FORCE_FW_HANG_CMD_fixed_param,
  710. WMITLV_GET_STRUCT_TLVLEN
  711. (WMI_FORCE_FW_HANG_CMD_fixed_param));
  712. cmd->type = param->type;
  713. cmd->delay_time_ms = param->delay_time_ms;
  714. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  715. WMI_FORCE_FW_HANG_CMDID);
  716. if (ret) {
  717. WMA_LOGE("%s: Failed to send set param command, ret = %d",
  718. __func__, ret);
  719. wmi_buf_free(buf);
  720. }
  721. return ret;
  722. }
  723. /**
  724. * send_dbglog_cmd_tlv() - set debug log level
  725. * @param wmi_handle : handle to WMI.
  726. * @param param : pointer to hold dbglog level parameter
  727. *
  728. * Return: 0 on success and -ve on failure.
  729. */
  730. int32_t
  731. send_dbglog_cmd_tlv(wmi_unified_t wmi_handle,
  732. struct dbglog_params *dbglog_param)
  733. {
  734. wmi_buf_t buf;
  735. wmi_debug_log_config_cmd_fixed_param *configmsg;
  736. A_STATUS status = A_OK;
  737. int32_t i;
  738. int32_t len;
  739. int8_t *buf_ptr;
  740. int32_t *module_id_bitmap_array; /* Used to fomr the second tlv */
  741. ASSERT(bitmap_len < MAX_MODULE_ID_BITMAP_WORDS);
  742. /* Allocate size for 2 tlvs - including tlv hdr space for second tlv */
  743. len = sizeof(wmi_debug_log_config_cmd_fixed_param) + WMI_TLV_HDR_SIZE +
  744. (sizeof(int32_t) * MAX_MODULE_ID_BITMAP_WORDS);
  745. buf = wmi_buf_alloc(wmi_handle, len);
  746. if (buf == NULL)
  747. return A_NO_MEMORY;
  748. configmsg =
  749. (wmi_debug_log_config_cmd_fixed_param *) (wmi_buf_data(buf));
  750. buf_ptr = (int8_t *) configmsg;
  751. WMITLV_SET_HDR(&configmsg->tlv_header,
  752. WMITLV_TAG_STRUC_wmi_debug_log_config_cmd_fixed_param,
  753. WMITLV_GET_STRUCT_TLVLEN
  754. (wmi_debug_log_config_cmd_fixed_param));
  755. configmsg->dbg_log_param = dbglog_param->param;
  756. configmsg->value = dbglog_param->val;
  757. /* Filling in the data part of second tlv -- should
  758. * follow first tlv _ WMI_TLV_HDR_SIZE */
  759. module_id_bitmap_array = (A_UINT32 *) (buf_ptr +
  760. sizeof
  761. (wmi_debug_log_config_cmd_fixed_param)
  762. + WMI_TLV_HDR_SIZE);
  763. WMITLV_SET_HDR(buf_ptr + sizeof(wmi_debug_log_config_cmd_fixed_param),
  764. WMITLV_TAG_ARRAY_UINT32,
  765. sizeof(A_UINT32) * MAX_MODULE_ID_BITMAP_WORDS);
  766. if (dbglog_param->module_id_bitmap) {
  767. for (i = 0; i < dbglog_param->bitmap_len; ++i) {
  768. module_id_bitmap_array[i] =
  769. dbglog_param->module_id_bitmap[i];
  770. }
  771. }
  772. status = wmi_unified_cmd_send(wmi_handle, buf,
  773. len, WMI_DBGLOG_CFG_CMDID);
  774. if (status != A_OK)
  775. cdf_nbuf_free(buf);
  776. return status;
  777. }
  778. /**
  779. * send_vdev_set_param_cmd_tlv() - WMI vdev set parameter function
  780. * @param wmi_handle : handle to WMI.
  781. * @param macaddr : MAC address
  782. * @param param : pointer to hold vdev set parameter
  783. *
  784. * Return: 0 on success and -ve on failure.
  785. */
  786. int32_t send_vdev_set_param_cmd_tlv(wmi_unified_t wmi_handle,
  787. struct vdev_set_params *param)
  788. {
  789. int32_t ret;
  790. wmi_vdev_set_param_cmd_fixed_param *cmd;
  791. wmi_buf_t buf;
  792. uint16_t len = sizeof(*cmd);
  793. buf = wmi_buf_alloc(wmi_handle, len);
  794. if (!buf) {
  795. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  796. return -ENOMEM;
  797. }
  798. cmd = (wmi_vdev_set_param_cmd_fixed_param *) wmi_buf_data(buf);
  799. WMITLV_SET_HDR(&cmd->tlv_header,
  800. WMITLV_TAG_STRUC_wmi_vdev_set_param_cmd_fixed_param,
  801. WMITLV_GET_STRUCT_TLVLEN
  802. (wmi_vdev_set_param_cmd_fixed_param));
  803. cmd->vdev_id = param->if_id;
  804. cmd->param_id = param->param_id;
  805. cmd->param_value = param->param_value;
  806. WMA_LOGD("Setting vdev %d param = %x, value = %u",
  807. param->if_id, param->param_id, param->param_value);
  808. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  809. WMI_VDEV_SET_PARAM_CMDID);
  810. if (ret < 0) {
  811. WMA_LOGE("Failed to send set param command ret = %d", ret);
  812. wmi_buf_free(buf);
  813. }
  814. return ret;
  815. }
  816. /**
  817. * send_stats_request_cmd_tlv() - WMI request stats function
  818. * @param wmi_handle : handle to WMI.
  819. * @param macaddr : MAC address
  820. * @param param : pointer to hold stats request parameter
  821. *
  822. * Return: 0 on success and -ve on failure.
  823. */
  824. int32_t send_stats_request_cmd_tlv(wmi_unified_t wmi_handle,
  825. uint8_t macaddr[IEEE80211_ADDR_LEN],
  826. struct stats_request_params *param)
  827. {
  828. int32_t ret;
  829. wmi_request_stats_cmd_fixed_param *cmd;
  830. wmi_buf_t buf;
  831. uint16_t len = sizeof(wmi_request_stats_cmd_fixed_param);
  832. buf = wmi_buf_alloc(wmi_handle, len);
  833. if (!buf) {
  834. WMA_LOGE("%s: wmi_buf_alloc failed", __func__);
  835. return -CDF_STATUS_E_NOMEM;
  836. }
  837. cmd = (wmi_request_stats_cmd_fixed_param *) wmi_buf_data(buf);
  838. WMITLV_SET_HDR(&cmd->tlv_header,
  839. WMITLV_TAG_STRUC_wmi_request_stats_cmd_fixed_param,
  840. WMITLV_GET_STRUCT_TLVLEN
  841. (wmi_request_stats_cmd_fixed_param));
  842. cmd->stats_id = param->stats_id;
  843. cmd->vdev_id = param->vdev_id;
  844. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  845. WMI_REQUEST_STATS_CMDID);
  846. if (ret) {
  847. WMA_LOGE("Failed to send status request to fw =%d", ret);
  848. wmi_buf_free(buf);
  849. }
  850. return ret;
  851. }
  852. /**
  853. * send_packet_log_enable_cmd_tlv() - WMI request stats function
  854. * @param wmi_handle : handle to WMI.
  855. * @param macaddr : MAC address
  856. * @param param : pointer to hold stats request parameter
  857. *
  858. * Return: 0 on success and -ve on failure.
  859. */
  860. int32_t send_packet_log_enable_cmd_tlv(wmi_unified_t wmi_handle,
  861. uint8_t macaddr[IEEE80211_ADDR_LEN],
  862. struct packet_enable_params *param)
  863. {
  864. return 0;
  865. }
  866. /**
  867. * send_beacon_send_cmd_tlv() - WMI beacon send function
  868. * @param wmi_handle : handle to WMI.
  869. * @param param : pointer to hold beacon send cmd parameter
  870. *
  871. * Return: 0 on success and -ve on failure.
  872. */
  873. int32_t send_beacon_send_cmd_tlv(wmi_unified_t wmi_handle,
  874. struct beacon_params *param)
  875. {
  876. int32_t ret;
  877. wmi_bcn_tmpl_cmd_fixed_param *cmd;
  878. wmi_bcn_prb_info *bcn_prb_info;
  879. wmi_buf_t wmi_buf;
  880. uint8_t *buf_ptr;
  881. uint32_t wmi_buf_len;
  882. wmi_buf_len = sizeof(wmi_bcn_tmpl_cmd_fixed_param) +
  883. sizeof(wmi_bcn_prb_info) + WMI_TLV_HDR_SIZE +
  884. param->tmpl_len_aligned;
  885. wmi_buf = wmi_buf_alloc(wmi_handle, wmi_buf_len);
  886. if (!wmi_buf) {
  887. WMA_LOGE("%s : wmi_buf_alloc failed", __func__);
  888. return -ENOMEM;
  889. }
  890. buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
  891. cmd = (wmi_bcn_tmpl_cmd_fixed_param *) buf_ptr;
  892. WMITLV_SET_HDR(&cmd->tlv_header,
  893. WMITLV_TAG_STRUC_wmi_bcn_tmpl_cmd_fixed_param,
  894. WMITLV_GET_STRUCT_TLVLEN(wmi_bcn_tmpl_cmd_fixed_param));
  895. cmd->vdev_id = param->vdev_id;
  896. cmd->tim_ie_offset = param->tim_ie_offset;
  897. cmd->buf_len = param->tmpl_len;
  898. buf_ptr += sizeof(wmi_bcn_tmpl_cmd_fixed_param);
  899. bcn_prb_info = (wmi_bcn_prb_info *) buf_ptr;
  900. WMITLV_SET_HDR(&bcn_prb_info->tlv_header,
  901. WMITLV_TAG_STRUC_wmi_bcn_prb_info,
  902. WMITLV_GET_STRUCT_TLVLEN(wmi_bcn_prb_info));
  903. bcn_prb_info->caps = 0;
  904. bcn_prb_info->erp = 0;
  905. buf_ptr += sizeof(wmi_bcn_prb_info);
  906. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, param->tmpl_len_aligned);
  907. buf_ptr += WMI_TLV_HDR_SIZE;
  908. cdf_mem_copy(buf_ptr, param->frm, param->tmpl_len);
  909. ret = wmi_unified_cmd_send(wmi_handle,
  910. wmi_buf, wmi_buf_len, WMI_BCN_TMPL_CMDID);
  911. if (ret) {
  912. WMA_LOGE("%s: Failed to send bcn tmpl: %d", __func__, ret);
  913. wmi_buf_free(wmi_buf);
  914. }
  915. return 0;
  916. }
  917. /**
  918. * send_peer_assoc_cmd_tlv() - WMI peer assoc function
  919. * @param wmi_handle : handle to WMI.
  920. * @param param : pointer to peer assoc parameter
  921. *
  922. * Return: 0 on success and -ve on failure.
  923. */
  924. int32_t send_peer_assoc_cmd_tlv(wmi_unified_t wmi_handle,
  925. struct peer_assoc_params *param)
  926. {
  927. wmi_peer_assoc_complete_cmd_fixed_param *cmd;
  928. wmi_vht_rate_set *mcs;
  929. wmi_buf_t buf;
  930. int32_t len;
  931. uint8_t *buf_ptr;
  932. int ret;
  933. len = sizeof(*cmd) + WMI_TLV_HDR_SIZE +
  934. (param->num_peer_legacy_rates * sizeof(uint8_t)) +
  935. WMI_TLV_HDR_SIZE +
  936. (param->num_peer_ht_rates * sizeof(uint8_t)) +
  937. sizeof(wmi_vht_rate_set);
  938. buf = wmi_buf_alloc(wmi_handle, len);
  939. if (!buf) {
  940. WMA_LOGE("%s: wmi_buf_alloc failed", __func__);
  941. return -ENOMEM;
  942. }
  943. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  944. cmd = (wmi_peer_assoc_complete_cmd_fixed_param *) buf_ptr;
  945. WMITLV_SET_HDR(&cmd->tlv_header,
  946. WMITLV_TAG_STRUC_wmi_peer_assoc_complete_cmd_fixed_param,
  947. WMITLV_GET_STRUCT_TLVLEN
  948. (wmi_peer_assoc_complete_cmd_fixed_param));
  949. cmd->vdev_id = param->vdev_id;
  950. cmd->peer_new_assoc = param->peer_new_assoc;
  951. cmd->peer_associd = param->peer_associd;
  952. cmd->peer_flags = param->peer_flags;
  953. cmd->peer_rate_caps = param->peer_rate_caps;
  954. cmd->peer_caps = param->peer_caps;
  955. cmd->peer_listen_intval = param->peer_listen_intval;
  956. cmd->peer_ht_caps = param->peer_ht_caps;
  957. cmd->peer_max_mpdu = param->peer_max_mpdu;
  958. cmd->peer_mpdu_density = param->peer_mpdu_density;
  959. cmd->num_peer_legacy_rates = param->num_peer_legacy_rates;
  960. cmd->num_peer_ht_rates = param->num_peer_ht_rates;
  961. cmd->peer_vht_caps = param->peer_vht_caps;
  962. cmd->peer_phymode = param->peer_phymode;
  963. /* Update peer legacy rate information */
  964. buf_ptr += sizeof(*cmd);
  965. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  966. param->num_peer_legacy_rates);
  967. buf_ptr += WMI_TLV_HDR_SIZE;
  968. cmd->num_peer_legacy_rates = param->num_peer_legacy_rates;
  969. cdf_mem_copy(buf_ptr, param->peer_legacy_rates.rates,
  970. param->peer_legacy_rates.num_rates);
  971. /* Update peer HT rate information */
  972. buf_ptr += param->num_peer_legacy_rates;
  973. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  974. param->num_peer_ht_rates);
  975. buf_ptr += WMI_TLV_HDR_SIZE;
  976. cmd->num_peer_ht_rates = param->num_peer_ht_rates;
  977. cdf_mem_copy(buf_ptr, param->peer_ht_rates.rates,
  978. param->peer_ht_rates.num_rates);
  979. /* VHT Rates */
  980. buf_ptr += param->num_peer_ht_rates;
  981. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_STRUC_wmi_vht_rate_set,
  982. WMITLV_GET_STRUCT_TLVLEN(wmi_vht_rate_set));
  983. cmd->peer_nss = param->peer_nss;
  984. mcs = (wmi_vht_rate_set *) buf_ptr;
  985. if (param->vht_capable) {
  986. mcs->rx_max_rate = param->rx_max_rate;
  987. mcs->rx_mcs_set = param->rx_mcs_set;
  988. mcs->tx_max_rate = param->tx_max_rate;
  989. mcs->tx_mcs_set = param->tx_mcs_set;
  990. }
  991. WMA_LOGD("%s: vdev_id %d associd %d peer_flags %x rate_caps %x "
  992. "peer_caps %x listen_intval %d ht_caps %x max_mpdu %d "
  993. "nss %d phymode %d peer_mpdu_density %d "
  994. "cmd->peer_vht_caps %x", __func__,
  995. cmd->vdev_id, cmd->peer_associd, cmd->peer_flags,
  996. cmd->peer_rate_caps, cmd->peer_caps,
  997. cmd->peer_listen_intval, cmd->peer_ht_caps,
  998. cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
  999. cmd->peer_mpdu_density,
  1000. cmd->peer_vht_caps);
  1001. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  1002. WMI_PEER_ASSOC_CMDID);
  1003. if (ret != EOK) {
  1004. WMA_LOGP("%s: Failed to send peer assoc command ret = %d",
  1005. __func__, ret);
  1006. cdf_nbuf_free(buf);
  1007. }
  1008. return ret;
  1009. }
  1010. /**
  1011. * send_scan_start_cmd_tlv() - WMI scan start function
  1012. * @param wmi_handle : handle to WMI.
  1013. * @param param : pointer to hold scan start cmd parameter
  1014. *
  1015. * Return: 0 on success and -ve on failure.
  1016. */
  1017. int32_t send_scan_start_cmd_tlv(wmi_unified_t wmi_handle,
  1018. struct scan_start_params *params)
  1019. {
  1020. int32_t ret = 0;
  1021. int32_t i;
  1022. wmi_buf_t wmi_buf;
  1023. wmi_start_scan_cmd_fixed_param *cmd;
  1024. uint8_t *buf_ptr;
  1025. uint32_t *tmp_ptr;
  1026. wmi_ssid *ssid = NULL;
  1027. wmi_mac_addr *bssid;
  1028. int len = sizeof(*cmd);
  1029. /* Length TLV placeholder for array of uint32_t */
  1030. len += WMI_TLV_HDR_SIZE;
  1031. /* calculate the length of buffer required */
  1032. if (params->num_chan)
  1033. len += params->num_chan * sizeof(uint32_t);
  1034. /* Length TLV placeholder for array of wmi_ssid structures */
  1035. len += WMI_TLV_HDR_SIZE;
  1036. if (params->num_ssids)
  1037. len += params->num_ssids * sizeof(wmi_ssid);
  1038. /* Length TLV placeholder for array of wmi_mac_addr structures */
  1039. len += WMI_TLV_HDR_SIZE;
  1040. len += sizeof(wmi_mac_addr);
  1041. /* Length TLV placeholder for array of bytes */
  1042. len += WMI_TLV_HDR_SIZE;
  1043. if (params->ie_len)
  1044. len += roundup(params->ie_len, sizeof(uint32_t));
  1045. /* Allocate the memory */
  1046. wmi_buf = wmi_buf_alloc(wmi_handle, len);
  1047. if (!wmi_buf) {
  1048. WMA_LOGP("%s: failed to allocate memory for start scan cmd",
  1049. __func__);
  1050. return CDF_STATUS_E_FAILURE;
  1051. }
  1052. buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
  1053. cmd = (wmi_start_scan_cmd_fixed_param *) buf_ptr;
  1054. WMITLV_SET_HDR(&cmd->tlv_header,
  1055. WMITLV_TAG_STRUC_wmi_start_scan_cmd_fixed_param,
  1056. WMITLV_GET_STRUCT_TLVLEN
  1057. (wmi_start_scan_cmd_fixed_param));
  1058. cmd->scan_id = params->scan_id;
  1059. cmd->scan_req_id = params->scan_req_id;
  1060. cmd->vdev_id = params->vdev_id;
  1061. cmd->scan_priority = params->scan_priority;
  1062. cmd->notify_scan_events = params->notify_scan_events;
  1063. cmd->dwell_time_active = params->dwell_time_active;
  1064. cmd->dwell_time_passive = params->dwell_time_passive;
  1065. cmd->min_rest_time = params->min_rest_time;
  1066. cmd->max_rest_time = params->max_rest_time;
  1067. cmd->repeat_probe_time = params->repeat_probe_time;
  1068. cmd->probe_spacing_time = params->probe_spacing_time;
  1069. cmd->idle_time = params->idle_time;
  1070. cmd->max_scan_time = params->max_scan_time;
  1071. cmd->probe_delay = params->probe_delay;
  1072. cmd->scan_ctrl_flags = params->scan_ctrl_flags;
  1073. cmd->burst_duration = params->burst_duration;
  1074. cmd->num_chan = params->num_chan;
  1075. cmd->num_bssid = params->num_bssid;
  1076. cmd->num_ssids = params->num_ssids;
  1077. cmd->ie_len = params->ie_len;
  1078. cmd->n_probes = params->n_probes;
  1079. buf_ptr += sizeof(*cmd);
  1080. tmp_ptr = (uint32_t *) (buf_ptr + WMI_TLV_HDR_SIZE);
  1081. for (i = 0; i < params->num_chan; ++i)
  1082. tmp_ptr[i] = params->chan_list[i];
  1083. WMITLV_SET_HDR(buf_ptr,
  1084. WMITLV_TAG_ARRAY_UINT32,
  1085. (params->num_chan * sizeof(uint32_t)));
  1086. buf_ptr += WMI_TLV_HDR_SIZE + (params->num_chan * sizeof(uint32_t));
  1087. if (params->num_ssids > SIR_SCAN_MAX_NUM_SSID) {
  1088. WMA_LOGE("Invalid value for numSsid");
  1089. goto error;
  1090. }
  1091. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_FIXED_STRUC,
  1092. (params->num_ssids * sizeof(wmi_ssid)));
  1093. if (params->num_ssids) {
  1094. ssid = (wmi_ssid *) (buf_ptr + WMI_TLV_HDR_SIZE);
  1095. for (i = 0; i < params->num_ssids; ++i) {
  1096. ssid->ssid_len = params->ssid[i].length;
  1097. cdf_mem_copy(ssid->ssid, params->ssid[i].mac_ssid,
  1098. params->ssid[i].length);
  1099. ssid++;
  1100. }
  1101. }
  1102. buf_ptr += WMI_TLV_HDR_SIZE + (params->num_ssids * sizeof(wmi_ssid));
  1103. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_FIXED_STRUC,
  1104. (params->num_bssid * sizeof(wmi_mac_addr)));
  1105. bssid = (wmi_mac_addr *) (buf_ptr + WMI_TLV_HDR_SIZE);
  1106. WMI_CHAR_ARRAY_TO_MAC_ADDR(params->mac_add_bytes, bssid);
  1107. buf_ptr += WMI_TLV_HDR_SIZE + (params->num_bssid * sizeof(wmi_mac_addr));
  1108. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, params->ie_len_with_pad);
  1109. if (params->ie_len) {
  1110. cdf_mem_copy(buf_ptr + WMI_TLV_HDR_SIZE,
  1111. (uint8_t *) params->ie_base +
  1112. (params->uie_fieldOffset), params->ie_len);
  1113. }
  1114. buf_ptr += WMI_TLV_HDR_SIZE + params->ie_len_with_pad;
  1115. ret = wmi_unified_cmd_send(wmi_handle, wmi_buf,
  1116. len, WMI_START_SCAN_CMDID);
  1117. if (ret) {
  1118. WMA_LOGE("%s: Failed to start scan: %d", __func__, ret);
  1119. wmi_buf_free(wmi_buf);
  1120. }
  1121. return ret;
  1122. error:
  1123. cdf_nbuf_free(wmi_buf);
  1124. return CDF_STATUS_E_FAILURE;
  1125. }
  1126. /**
  1127. * send_scan_stop_cmd_tlv() - WMI scan start function
  1128. * @param wmi_handle : handle to WMI.
  1129. * @param param : pointer to hold scan start cmd parameter
  1130. *
  1131. * Return: 0 on success and -ve on failure.
  1132. */
  1133. int32_t send_scan_stop_cmd_tlv(wmi_unified_t wmi_handle,
  1134. struct scan_stop_params *param)
  1135. {
  1136. wmi_stop_scan_cmd_fixed_param *cmd;
  1137. int ret;
  1138. int len = sizeof(*cmd);
  1139. wmi_buf_t wmi_buf;
  1140. /* Allocate the memory */
  1141. wmi_buf = wmi_buf_alloc(wmi_handle, len);
  1142. if (!wmi_buf) {
  1143. WMA_LOGP("%s: failed to allocate memory for stop scan cmd",
  1144. __func__);
  1145. ret = -ENOMEM;
  1146. goto error;
  1147. }
  1148. cmd = (wmi_stop_scan_cmd_fixed_param *) wmi_buf_data(wmi_buf);
  1149. WMITLV_SET_HDR(&cmd->tlv_header,
  1150. WMITLV_TAG_STRUC_wmi_stop_scan_cmd_fixed_param,
  1151. WMITLV_GET_STRUCT_TLVLEN(wmi_stop_scan_cmd_fixed_param));
  1152. cmd->vdev_id = param->vdev_id;
  1153. cmd->requestor = param->requestor;
  1154. cmd->scan_id = param->scan_id;
  1155. /* stop the scan with the corresponding scan_id */
  1156. cmd->req_type = param->req_type;
  1157. ret = wmi_unified_cmd_send(wmi_handle, wmi_buf,
  1158. len, WMI_STOP_SCAN_CMDID);
  1159. if (ret) {
  1160. WMA_LOGE("%s: Failed to send stop scan: %d", __func__, ret);
  1161. wmi_buf_free(wmi_buf);
  1162. }
  1163. error:
  1164. return ret;
  1165. }
  1166. /**
  1167. * send_scan_chan_list_cmd_tlv() - WMI scan channel list function
  1168. * @param wmi_handle : handle to WMI.
  1169. * @param param : pointer to hold scan channel list parameter
  1170. *
  1171. * Return: 0 on success and -ve on failure.
  1172. */
  1173. int32_t send_scan_chan_list_cmd_tlv(wmi_unified_t wmi_handle,
  1174. struct scan_chan_list_params *chan_list)
  1175. {
  1176. wmi_buf_t buf;
  1177. CDF_STATUS cdf_status = CDF_STATUS_SUCCESS;
  1178. wmi_scan_chan_list_cmd_fixed_param *cmd;
  1179. int status, i;
  1180. uint8_t *buf_ptr;
  1181. wmi_channel *chan_info, *tchan_info;
  1182. uint16_t len = sizeof(*cmd) + WMI_TLV_HDR_SIZE;
  1183. len += sizeof(wmi_channel) * chan_list->num_scan_chans;
  1184. buf = wmi_buf_alloc(wmi_handle, len);
  1185. if (!buf) {
  1186. WMA_LOGE("Failed to allocate memory");
  1187. cdf_status = CDF_STATUS_E_NOMEM;
  1188. goto end;
  1189. }
  1190. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  1191. cmd = (wmi_scan_chan_list_cmd_fixed_param *) buf_ptr;
  1192. WMITLV_SET_HDR(&cmd->tlv_header,
  1193. WMITLV_TAG_STRUC_wmi_scan_chan_list_cmd_fixed_param,
  1194. WMITLV_GET_STRUCT_TLVLEN
  1195. (wmi_scan_chan_list_cmd_fixed_param));
  1196. WMA_LOGD("no of channels = %d, len = %d", chan_list->num_scan_chans, len);
  1197. cmd->num_scan_chans = chan_list->num_scan_chans;
  1198. WMITLV_SET_HDR((buf_ptr + sizeof(wmi_scan_chan_list_cmd_fixed_param)),
  1199. WMITLV_TAG_ARRAY_STRUC,
  1200. sizeof(wmi_channel) * chan_list->num_scan_chans);
  1201. chan_info = (wmi_channel *) (buf_ptr + sizeof(*cmd) + WMI_TLV_HDR_SIZE);
  1202. tchan_info = chan_list->chan_info;
  1203. for (i = 0; i < chan_list->num_scan_chans; ++i) {
  1204. WMITLV_SET_HDR(&chan_info->tlv_header,
  1205. WMITLV_TAG_STRUC_wmi_channel,
  1206. WMITLV_GET_STRUCT_TLVLEN(wmi_channel));
  1207. chan_info->mhz = tchan_info->mhz;
  1208. chan_info->band_center_freq1 =
  1209. tchan_info->band_center_freq1;
  1210. chan_info->band_center_freq2 =
  1211. tchan_info->band_center_freq2;
  1212. chan_info->info = tchan_info->info;
  1213. chan_info->reg_info_1 = tchan_info->reg_info_1;
  1214. chan_info->reg_info_2 = tchan_info->reg_info_2;
  1215. WMA_LOGD("chan[%d] = %u", i, chan_info->mhz);
  1216. /*TODO: Set WMI_SET_CHANNEL_MIN_POWER */
  1217. /*TODO: Set WMI_SET_CHANNEL_ANTENNA_MAX */
  1218. /*TODO: WMI_SET_CHANNEL_REG_CLASSID */
  1219. tchan_info++;
  1220. chan_info++;
  1221. }
  1222. status = wmi_unified_cmd_send(wmi_handle, buf, len,
  1223. WMI_SCAN_CHAN_LIST_CMDID);
  1224. if (status != EOK) {
  1225. cdf_status = CDF_STATUS_E_FAILURE;
  1226. WMA_LOGE("Failed to send WMI_SCAN_CHAN_LIST_CMDID");
  1227. wmi_buf_free(buf);
  1228. }
  1229. end:
  1230. return cdf_status;
  1231. }
  1232. /**
  1233. * send_mgmt_cmd_tlv() - WMI scan start function
  1234. * @wmi_handle : handle to WMI.
  1235. * @param : pointer to hold mgmt cmd parameter
  1236. *
  1237. * Return: 0 on success and -ve on failure.
  1238. */
  1239. int32_t send_mgmt_cmd_tlv(wmi_unified_t wmi_handle,
  1240. struct wmi_mgmt_params *param)
  1241. {
  1242. wmi_buf_t buf;
  1243. wmi_mgmt_tx_send_cmd_fixed_param *cmd;
  1244. int32_t cmd_len;
  1245. uint64_t dma_addr;
  1246. struct wmi_desc_t *wmi_desc = NULL;
  1247. void *cdf_ctx = param->cdf_ctx;
  1248. uint8_t *bufp;
  1249. int32_t bufp_len = (param->frm_len < mgmt_tx_dl_frm_len) ? param->frm_len :
  1250. mgmt_tx_dl_frm_len;
  1251. cmd_len = sizeof(wmi_mgmt_tx_send_cmd_fixed_param) +
  1252. WMI_TLV_HDR_SIZE + roundup(bufp_len, sizeof(uint32_t));
  1253. buf = wmi_buf_alloc(wmi_handle, cmd_len);
  1254. if (!buf) {
  1255. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  1256. return CDF_STATUS_E_NOMEM;
  1257. }
  1258. cmd = (wmi_mgmt_tx_send_cmd_fixed_param *)wmi_buf_data(buf);
  1259. bufp = (uint8_t *) cmd;
  1260. WMITLV_SET_HDR(&cmd->tlv_header,
  1261. WMITLV_TAG_STRUC_wmi_mgmt_tx_send_cmd_fixed_param,
  1262. WMITLV_GET_STRUCT_TLVLEN
  1263. (wmi_mgmt_tx_send_cmd_fixed_param));
  1264. cmd->vdev_id = param->vdev_id;
  1265. wmi_desc = param->wmi_desc;
  1266. if (!wmi_desc) {
  1267. WMA_LOGE("%s: Failed to get wmi_desc", __func__);
  1268. goto err1;
  1269. }
  1270. wmi_desc->nbuf = param->tx_frame;
  1271. wmi_desc->tx_cmpl_cb = param->tx_complete_cb;
  1272. wmi_desc->ota_post_proc_cb = param->tx_ota_post_proc_cb;
  1273. cmd->desc_id = wmi_desc->desc_id;
  1274. cmd->chanfreq = param->chanfreq;
  1275. bufp += sizeof(wmi_mgmt_tx_send_cmd_fixed_param);
  1276. WMITLV_SET_HDR(bufp, WMITLV_TAG_ARRAY_BYTE, roundup(bufp_len,
  1277. sizeof(uint32_t)));
  1278. bufp += WMI_TLV_HDR_SIZE;
  1279. cdf_mem_copy(bufp, param->pdata, bufp_len);
  1280. cdf_nbuf_map_single(cdf_ctx, param->tx_frame, CDF_DMA_TO_DEVICE);
  1281. dma_addr = cdf_nbuf_get_frag_paddr_lo(param->tx_frame, 0);
  1282. cmd->paddr_lo = (uint32_t)(dma_addr & 0xffffffff);
  1283. #if defined(HELIUMPLUS_PADDR64)
  1284. cmd->paddr_hi = (uint32_t)((dma_addr >> 32) & 0x1F);
  1285. #endif
  1286. cmd->frame_len = param->frm_len;
  1287. cmd->buf_len = bufp_len;
  1288. if (wmi_unified_cmd_send(wmi_handle, buf, cmd_len,
  1289. WMI_MGMT_TX_SEND_CMDID)) {
  1290. WMA_LOGE("%s: Failed to send mgmt Tx", __func__);
  1291. goto err1;
  1292. }
  1293. return CDF_STATUS_SUCCESS;
  1294. err1:
  1295. wmi_buf_free(buf);
  1296. return CDF_STATUS_E_FAILURE;
  1297. }
  1298. /**
  1299. * send_modem_power_state_cmd_tlv() - set modem power state to fw
  1300. * @wmi_handle: wmi handle
  1301. * @param_value: parameter value
  1302. *
  1303. * Return: 0 for success or error code
  1304. */
  1305. int32_t send_modem_power_state_cmd_tlv(wmi_unified_t wmi_handle,
  1306. uint32_t param_value)
  1307. {
  1308. int ret;
  1309. wmi_modem_power_state_cmd_param *cmd;
  1310. wmi_buf_t buf;
  1311. uint16_t len = sizeof(*cmd);
  1312. buf = wmi_buf_alloc(wmi_handle, len);
  1313. if (!buf) {
  1314. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  1315. return -ENOMEM;
  1316. }
  1317. cmd = (wmi_modem_power_state_cmd_param *) wmi_buf_data(buf);
  1318. WMITLV_SET_HDR(&cmd->tlv_header,
  1319. WMITLV_TAG_STRUC_wmi_modem_power_state_cmd_param,
  1320. WMITLV_GET_STRUCT_TLVLEN
  1321. (wmi_modem_power_state_cmd_param));
  1322. cmd->modem_power_state = param_value;
  1323. WMA_LOGD("%s: Setting cmd->modem_power_state = %u", __func__,
  1324. param_value);
  1325. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  1326. WMI_MODEM_POWER_STATE_CMDID);
  1327. if (ret != EOK) {
  1328. WMA_LOGE("Failed to send notify cmd ret = %d", ret);
  1329. wmi_buf_free(buf);
  1330. }
  1331. return ret;
  1332. }
  1333. /**
  1334. * send_set_sta_ps_mode_cmd_tlv() - set sta powersave mode in fw
  1335. * @wmi_handle: wmi handle
  1336. * @vdev_id: vdev id
  1337. * @val: value
  1338. *
  1339. * Return: 0 for success or error code.
  1340. */
  1341. int32_t send_set_sta_ps_mode_cmd_tlv(wmi_unified_t wmi_handle,
  1342. uint32_t vdev_id, uint8_t val)
  1343. {
  1344. wmi_sta_powersave_mode_cmd_fixed_param *cmd;
  1345. wmi_buf_t buf;
  1346. int32_t len = sizeof(*cmd);
  1347. WMA_LOGD("Set Sta Mode Ps vdevId %d val %d", vdev_id, val);
  1348. buf = wmi_buf_alloc(wmi_handle, len);
  1349. if (!buf) {
  1350. WMA_LOGP("%s: Set Sta Mode Ps Mem Alloc Failed", __func__);
  1351. return -ENOMEM;
  1352. }
  1353. cmd = (wmi_sta_powersave_mode_cmd_fixed_param *) wmi_buf_data(buf);
  1354. WMITLV_SET_HDR(&cmd->tlv_header,
  1355. WMITLV_TAG_STRUC_wmi_sta_powersave_mode_cmd_fixed_param,
  1356. WMITLV_GET_STRUCT_TLVLEN
  1357. (wmi_sta_powersave_mode_cmd_fixed_param));
  1358. cmd->vdev_id = vdev_id;
  1359. if (val)
  1360. cmd->sta_ps_mode = WMI_STA_PS_MODE_ENABLED;
  1361. else
  1362. cmd->sta_ps_mode = WMI_STA_PS_MODE_DISABLED;
  1363. if (wmi_unified_cmd_send(wmi_handle, buf, len,
  1364. WMI_STA_POWERSAVE_MODE_CMDID)) {
  1365. WMA_LOGE("Set Sta Mode Ps Failed vdevId %d val %d",
  1366. vdev_id, val);
  1367. cdf_nbuf_free(buf);
  1368. return -EIO;
  1369. }
  1370. return 0;
  1371. }
  1372. /**
  1373. * send_set_mimops_cmd_tlv() - set MIMO powersave
  1374. * @wmi_handle: wmi handle
  1375. * @vdev_id: vdev id
  1376. * @value: value
  1377. *
  1378. * Return: CDF_STATUS_SUCCESS for success or error code.
  1379. */
  1380. int32_t send_set_mimops_cmd_tlv(wmi_unified_t wmi_handle,
  1381. uint8_t vdev_id, int value)
  1382. {
  1383. int ret = CDF_STATUS_SUCCESS;
  1384. wmi_sta_smps_force_mode_cmd_fixed_param *cmd;
  1385. wmi_buf_t buf;
  1386. uint16_t len = sizeof(*cmd);
  1387. buf = wmi_buf_alloc(wmi_handle, len);
  1388. if (!buf) {
  1389. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  1390. return -ENOMEM;
  1391. }
  1392. cmd = (wmi_sta_smps_force_mode_cmd_fixed_param *) wmi_buf_data(buf);
  1393. WMITLV_SET_HDR(&cmd->tlv_header,
  1394. WMITLV_TAG_STRUC_wmi_sta_smps_force_mode_cmd_fixed_param,
  1395. WMITLV_GET_STRUCT_TLVLEN
  1396. (wmi_sta_smps_force_mode_cmd_fixed_param));
  1397. cmd->vdev_id = vdev_id;
  1398. switch (value) {
  1399. case 0:
  1400. cmd->forced_mode = WMI_SMPS_FORCED_MODE_NONE;
  1401. break;
  1402. case 1:
  1403. cmd->forced_mode = WMI_SMPS_FORCED_MODE_DISABLED;
  1404. break;
  1405. case 2:
  1406. cmd->forced_mode = WMI_SMPS_FORCED_MODE_STATIC;
  1407. break;
  1408. case 3:
  1409. cmd->forced_mode = WMI_SMPS_FORCED_MODE_DYNAMIC;
  1410. break;
  1411. default:
  1412. WMA_LOGE("%s:INVALID Mimo PS CONFIG", __func__);
  1413. return CDF_STATUS_E_FAILURE;
  1414. }
  1415. WMA_LOGD("Setting vdev %d value = %u", vdev_id, value);
  1416. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  1417. WMI_STA_SMPS_FORCE_MODE_CMDID);
  1418. if (ret < 0) {
  1419. WMA_LOGE("Failed to send set Mimo PS ret = %d", ret);
  1420. wmi_buf_free(buf);
  1421. }
  1422. return ret;
  1423. }
  1424. /**
  1425. * send_set_smps_params_cmd_tlv() - set smps params
  1426. * @wmi_handle: wmi handle
  1427. * @vdev_id: vdev id
  1428. * @value: value
  1429. *
  1430. * Return: CDF_STATUS_SUCCESS for success or error code.
  1431. */
  1432. int32_t send_set_smps_params_cmd_tlv(wmi_unified_t wmi_handle, uint8_t vdev_id,
  1433. int value)
  1434. {
  1435. int ret = CDF_STATUS_SUCCESS;
  1436. wmi_sta_smps_param_cmd_fixed_param *cmd;
  1437. wmi_buf_t buf;
  1438. uint16_t len = sizeof(*cmd);
  1439. buf = wmi_buf_alloc(wmi_handle, len);
  1440. if (!buf) {
  1441. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  1442. return -ENOMEM;
  1443. }
  1444. cmd = (wmi_sta_smps_param_cmd_fixed_param *) wmi_buf_data(buf);
  1445. WMITLV_SET_HDR(&cmd->tlv_header,
  1446. WMITLV_TAG_STRUC_wmi_sta_smps_param_cmd_fixed_param,
  1447. WMITLV_GET_STRUCT_TLVLEN
  1448. (wmi_sta_smps_param_cmd_fixed_param));
  1449. cmd->vdev_id = vdev_id;
  1450. cmd->value = value & WMI_SMPS_MASK_LOWER_16BITS;
  1451. cmd->param =
  1452. (value >> WMI_SMPS_PARAM_VALUE_S) & WMI_SMPS_MASK_UPPER_3BITS;
  1453. WMA_LOGD("Setting vdev %d value = %x param %x", vdev_id, cmd->value,
  1454. cmd->param);
  1455. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  1456. WMI_STA_SMPS_PARAM_CMDID);
  1457. if (ret < 0) {
  1458. WMA_LOGE("Failed to send set Mimo PS ret = %d", ret);
  1459. wmi_buf_free(buf);
  1460. }
  1461. return ret;
  1462. }
  1463. /**
  1464. * send_set_p2pgo_noa_req_cmd_tlv() - send p2p go noa request to fw
  1465. * @wmi_handle: wmi handle
  1466. * @noa: p2p power save parameters
  1467. *
  1468. * Return: none
  1469. */
  1470. int32_t send_set_p2pgo_noa_req_cmd_tlv(wmi_unified_t wmi_handle,
  1471. struct p2p_ps_params *noa)
  1472. {
  1473. wmi_p2p_set_noa_cmd_fixed_param *cmd;
  1474. wmi_p2p_noa_descriptor *noa_discriptor;
  1475. wmi_buf_t buf;
  1476. uint8_t *buf_ptr;
  1477. uint16_t len;
  1478. int32_t status;
  1479. uint32_t duration;
  1480. WMA_LOGD("%s: Enter", __func__);
  1481. len = sizeof(*cmd) + WMI_TLV_HDR_SIZE + sizeof(*noa_discriptor);
  1482. buf = wmi_buf_alloc(wmi_handle, len);
  1483. if (!buf) {
  1484. WMA_LOGE("Failed to allocate memory");
  1485. status = CDF_STATUS_E_FAILURE;
  1486. goto end;
  1487. }
  1488. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  1489. cmd = (wmi_p2p_set_noa_cmd_fixed_param *) buf_ptr;
  1490. WMITLV_SET_HDR(&cmd->tlv_header,
  1491. WMITLV_TAG_STRUC_wmi_p2p_set_noa_cmd_fixed_param,
  1492. WMITLV_GET_STRUCT_TLVLEN
  1493. (wmi_p2p_set_noa_cmd_fixed_param));
  1494. duration = (noa->count == 1) ? noa->single_noa_duration : noa->duration;
  1495. cmd->vdev_id = noa->session_id;
  1496. cmd->enable = (duration) ? true : false;
  1497. cmd->num_noa = 1;
  1498. WMITLV_SET_HDR((buf_ptr + sizeof(wmi_p2p_set_noa_cmd_fixed_param)),
  1499. WMITLV_TAG_ARRAY_STRUC, sizeof(wmi_p2p_noa_descriptor));
  1500. noa_discriptor = (wmi_p2p_noa_descriptor *) (buf_ptr +
  1501. sizeof
  1502. (wmi_p2p_set_noa_cmd_fixed_param)
  1503. + WMI_TLV_HDR_SIZE);
  1504. WMITLV_SET_HDR(&noa_discriptor->tlv_header,
  1505. WMITLV_TAG_STRUC_wmi_p2p_noa_descriptor,
  1506. WMITLV_GET_STRUCT_TLVLEN(wmi_p2p_noa_descriptor));
  1507. noa_discriptor->type_count = noa->count;
  1508. noa_discriptor->duration = duration;
  1509. noa_discriptor->interval = noa->interval;
  1510. noa_discriptor->start_time = 0;
  1511. WMA_LOGI("SET P2P GO NOA:vdev_id:%d count:%d duration:%d interval:%d",
  1512. cmd->vdev_id, noa->count, noa_discriptor->duration,
  1513. noa->interval);
  1514. status = wmi_unified_cmd_send(wmi_handle, buf, len,
  1515. WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
  1516. if (status != EOK) {
  1517. WMA_LOGE("Failed to send WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID");
  1518. wmi_buf_free(buf);
  1519. }
  1520. end:
  1521. WMA_LOGD("%s: Exit", __func__);
  1522. return status;
  1523. }
  1524. /**
  1525. * send_set_p2pgo_oppps_req_cmd_tlv() - send p2p go opp power save request to fw
  1526. * @wmi_handle: wmi handle
  1527. * @noa: p2p opp power save parameters
  1528. *
  1529. * Return: none
  1530. */
  1531. int32_t send_set_p2pgo_oppps_req_cmd_tlv(wmi_unified_t wmi_handle,
  1532. struct p2p_ps_params *oppps)
  1533. {
  1534. wmi_p2p_set_oppps_cmd_fixed_param *cmd;
  1535. wmi_buf_t buf;
  1536. int32_t status;
  1537. WMA_LOGD("%s: Enter", __func__);
  1538. buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
  1539. if (!buf) {
  1540. WMA_LOGE("Failed to allocate memory");
  1541. status = CDF_STATUS_E_FAILURE;
  1542. goto end;
  1543. }
  1544. cmd = (wmi_p2p_set_oppps_cmd_fixed_param *) wmi_buf_data(buf);
  1545. WMITLV_SET_HDR(&cmd->tlv_header,
  1546. WMITLV_TAG_STRUC_wmi_p2p_set_oppps_cmd_fixed_param,
  1547. WMITLV_GET_STRUCT_TLVLEN
  1548. (wmi_p2p_set_oppps_cmd_fixed_param));
  1549. cmd->vdev_id = oppps->session_id;
  1550. if (oppps->ctwindow)
  1551. WMI_UNIFIED_OPPPS_ATTR_ENABLED_SET(cmd);
  1552. WMI_UNIFIED_OPPPS_ATTR_CTWIN_SET(cmd, oppps->ctwindow);
  1553. WMA_LOGI("SET P2P GO OPPPS:vdev_id:%d ctwindow:%d",
  1554. cmd->vdev_id, oppps->ctwindow);
  1555. status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
  1556. WMI_P2P_SET_OPPPS_PARAM_CMDID);
  1557. if (status != EOK) {
  1558. WMA_LOGE("Failed to send WMI_P2P_SET_OPPPS_PARAM_CMDID");
  1559. wmi_buf_free(buf);
  1560. }
  1561. end:
  1562. WMA_LOGD("%s: Exit", __func__);
  1563. return status;
  1564. }
  1565. /**
  1566. * send_get_temperature_cmd_tlv() - get pdev temperature req
  1567. * @wmi_handle: wmi handle
  1568. *
  1569. * Return: CDF_STATUS_SUCCESS for success or error code.
  1570. */
  1571. int32_t send_get_temperature_cmd_tlv(wmi_unified_t wmi_handle)
  1572. {
  1573. wmi_pdev_get_temperature_cmd_fixed_param *cmd;
  1574. wmi_buf_t wmi_buf;
  1575. uint32_t len = sizeof(wmi_pdev_get_temperature_cmd_fixed_param);
  1576. uint8_t *buf_ptr;
  1577. if (!wmi_handle) {
  1578. WMA_LOGE(FL("WMA is closed, can not issue cmd"));
  1579. return CDF_STATUS_E_INVAL;
  1580. }
  1581. wmi_buf = wmi_buf_alloc(wmi_handle, len);
  1582. if (!wmi_buf) {
  1583. WMA_LOGE(FL("wmi_buf_alloc failed"));
  1584. return CDF_STATUS_E_NOMEM;
  1585. }
  1586. buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
  1587. cmd = (wmi_pdev_get_temperature_cmd_fixed_param *) buf_ptr;
  1588. WMITLV_SET_HDR(&cmd->tlv_header,
  1589. WMITLV_TAG_STRUC_wmi_pdev_get_temperature_cmd_fixed_param,
  1590. WMITLV_GET_STRUCT_TLVLEN
  1591. (wmi_pdev_get_temperature_cmd_fixed_param));
  1592. if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
  1593. WMI_PDEV_GET_TEMPERATURE_CMDID)) {
  1594. WMA_LOGE(FL("failed to send get temperature command"));
  1595. wmi_buf_free(wmi_buf);
  1596. return CDF_STATUS_E_FAILURE;
  1597. }
  1598. return CDF_STATUS_SUCCESS;
  1599. }
  1600. /**
  1601. * send_set_sta_uapsd_auto_trig_cmd_tlv() - set uapsd auto trigger command
  1602. * @wmi_handle: wmi handle
  1603. * @vdevid: vdev id
  1604. * @peer_addr: peer mac address
  1605. * @auto_triggerparam: auto trigger parameters
  1606. * @num_ac: number of access category
  1607. *
  1608. * This function sets the trigger
  1609. * uapsd params such as service interval, delay interval
  1610. * and suspend interval which will be used by the firmware
  1611. * to send trigger frames periodically when there is no
  1612. * traffic on the transmit side.
  1613. *
  1614. * Return: 0 for success or error code.
  1615. */
  1616. int32_t send_set_sta_uapsd_auto_trig_cmd_tlv(wmi_unified_t wmi_handle,
  1617. struct sta_uapsd_trig_params *param)
  1618. {
  1619. wmi_sta_uapsd_auto_trig_cmd_fixed_param *cmd;
  1620. int32_t ret;
  1621. uint32_t param_len = param->num_ac * sizeof(wmi_sta_uapsd_auto_trig_param);
  1622. uint32_t cmd_len = sizeof(*cmd) + param_len + WMI_TLV_HDR_SIZE;
  1623. uint32_t i;
  1624. wmi_buf_t buf;
  1625. uint8_t *buf_ptr;
  1626. buf = wmi_buf_alloc(wmi_handle, cmd_len);
  1627. if (!buf) {
  1628. WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
  1629. return -ENOMEM;
  1630. }
  1631. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  1632. cmd = (wmi_sta_uapsd_auto_trig_cmd_fixed_param *) buf_ptr;
  1633. WMITLV_SET_HDR(&cmd->tlv_header,
  1634. WMITLV_TAG_STRUC_wmi_sta_uapsd_auto_trig_cmd_fixed_param,
  1635. WMITLV_GET_STRUCT_TLVLEN
  1636. (wmi_sta_uapsd_auto_trig_cmd_fixed_param));
  1637. cmd->vdev_id = param->vdevid;
  1638. cmd->num_ac = param->num_ac;
  1639. WMI_CHAR_ARRAY_TO_MAC_ADDR(param->peer_addr, &cmd->peer_macaddr);
  1640. /* TLV indicating array of structures to follow */
  1641. buf_ptr += sizeof(*cmd);
  1642. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, param_len);
  1643. buf_ptr += WMI_TLV_HDR_SIZE;
  1644. cdf_mem_copy(buf_ptr, param->auto_triggerparam, param_len);
  1645. /*
  1646. * Update tag and length for uapsd auto trigger params (this will take
  1647. * care of updating tag and length if it is not pre-filled by caller).
  1648. */
  1649. for (i = 0; i < param->num_ac; i++) {
  1650. WMITLV_SET_HDR((buf_ptr +
  1651. (i * sizeof(wmi_sta_uapsd_auto_trig_param))),
  1652. WMITLV_TAG_STRUC_wmi_sta_uapsd_auto_trig_param,
  1653. WMITLV_GET_STRUCT_TLVLEN
  1654. (wmi_sta_uapsd_auto_trig_param));
  1655. }
  1656. ret = wmi_unified_cmd_send(wmi_handle, buf, cmd_len,
  1657. WMI_STA_UAPSD_AUTO_TRIG_CMDID);
  1658. if (ret != EOK) {
  1659. WMA_LOGE("Failed to send set uapsd param ret = %d", ret);
  1660. wmi_buf_free(buf);
  1661. }
  1662. return ret;
  1663. }
  1664. struct wmi_ops tlv_ops = {
  1665. .send_vdev_create_cmd = send_vdev_create_cmd_tlv,
  1666. .send_vdev_delete_cmd = send_vdev_delete_cmd_tlv,
  1667. .send_vdev_down_cmd = send_vdev_down_cmd_tlv,
  1668. .send_peer_flush_tids_cmd = send_peer_flush_tids_cmd_tlv,
  1669. .send_peer_param_cmd = send_peer_param_cmd_tlv,
  1670. .send_vdev_up_cmd = send_vdev_up_cmd_tlv,
  1671. .send_vdev_stop_cmd = send_vdev_stop_cmd_tlv,
  1672. .send_peer_create_cmd = send_peer_create_cmd_tlv,
  1673. .send_peer_delete_cmd = send_peer_delete_cmd_tlv,
  1674. .send_green_ap_ps_cmd = send_green_ap_ps_cmd_tlv,
  1675. .send_pdev_utf_cmd = send_pdev_utf_cmd_tlv,
  1676. .send_pdev_param_cmd = send_pdev_param_cmd_tlv,
  1677. .send_suspend_cmd = send_suspend_cmd_tlv,
  1678. .send_resume_cmd = send_resume_cmd_tlv,
  1679. .send_wow_enable_cmd = send_wow_enable_cmd_tlv,
  1680. .send_set_ap_ps_param_cmd = send_set_ap_ps_param_cmd_tlv,
  1681. .send_set_sta_ps_param_cmd = send_set_sta_ps_param_cmd_tlv,
  1682. .send_crash_inject_cmd = send_crash_inject_cmd_tlv,
  1683. .send_dbglog_cmd = send_dbglog_cmd_tlv,
  1684. .send_vdev_set_param_cmd = send_vdev_set_param_cmd_tlv,
  1685. .send_stats_request_cmd = send_stats_request_cmd_tlv,
  1686. .send_packet_log_enable_cmd = send_packet_log_enable_cmd_tlv,
  1687. .send_beacon_send_cmd = send_beacon_send_cmd_tlv,
  1688. .send_peer_assoc_cmd = send_peer_assoc_cmd_tlv,
  1689. .send_scan_start_cmd = send_scan_start_cmd_tlv,
  1690. .send_scan_stop_cmd = send_scan_stop_cmd_tlv,
  1691. .send_scan_chan_list_cmd = send_scan_chan_list_cmd_tlv,
  1692. .send_mgmt_cmd = send_mgmt_cmd_tlv,
  1693. .send_modem_power_state_cmd = send_modem_power_state_cmd_tlv,
  1694. .send_set_sta_ps_mode_cmd = send_set_sta_ps_mode_cmd_tlv,
  1695. .send_set_sta_uapsd_auto_trig_cmd = send_set_sta_uapsd_auto_trig_cmd_tlv,
  1696. .send_get_temperature_cmd = send_get_temperature_cmd_tlv,
  1697. .send_set_p2pgo_oppps_req_cmd = send_set_p2pgo_oppps_req_cmd_tlv,
  1698. .send_set_p2pgo_noa_req_cmd = send_set_p2pgo_noa_req_cmd_tlv,
  1699. .send_set_smps_params_cmd = send_set_smps_params_cmd_tlv,
  1700. .send_set_mimops_cmd = send_set_mimops_cmd_tlv,
  1701. /* TODO - Add other tlv apis here */
  1702. };
  1703. /**
  1704. * wmi_get_tlv_ops() - gives pointer to wmi tlv ops
  1705. *
  1706. * Return: pointer to wmi tlv ops
  1707. */
  1708. struct wmi_ops *wmi_get_tlv_ops(void)
  1709. {
  1710. return &tlv_ops;
  1711. }