wmi_unified_fwol_tlv.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "osdep.h"
  20. #include "wmi.h"
  21. #include "wmi_unified_priv.h"
  22. #include "wlan_fwol_public_structs.h"
  23. #include "wmi_unified_fwol_api.h"
  24. #ifdef WLAN_FEATURE_ELNA
  25. /**
  26. * send_set_elna_bypass_cmd_tlv() - send set elna bypass cmd to fw
  27. * @wmi_handle: wmi handle
  28. * @req: set eLNA bypass request
  29. *
  30. * Send WMI_SET_ELNA_BYPASS_CMDID to fw.
  31. *
  32. * Return: QDF_STATUS
  33. */
  34. static QDF_STATUS
  35. send_set_elna_bypass_cmd_tlv(wmi_unified_t wmi_handle,
  36. struct set_elna_bypass_request *req)
  37. {
  38. wmi_buf_t buf;
  39. wmi_set_elna_bypass_cmd_fixed_param *cmd;
  40. uint16_t len = sizeof(*cmd);
  41. QDF_STATUS ret;
  42. buf = wmi_buf_alloc(wmi_handle, len);
  43. if (!buf) {
  44. wmi_err("Failed to allocate wmi buffer");
  45. return QDF_STATUS_E_NOMEM;
  46. }
  47. cmd = (wmi_set_elna_bypass_cmd_fixed_param *)wmi_buf_data(buf);
  48. WMITLV_SET_HDR(&cmd->tlv_header,
  49. WMITLV_TAG_STRUC_wmi_set_elna_bypass_cmd_fixed_param,
  50. WMITLV_GET_STRUCT_TLVLEN
  51. (wmi_set_elna_bypass_cmd_fixed_param));
  52. cmd->vdev_id = req->vdev_id;
  53. cmd->en_dis = req->elna_mode;
  54. wmi_mtrace(WMI_SET_ELNA_BYPASS_CMDID, req->vdev_id, req->elna_mode);
  55. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  56. WMI_SET_ELNA_BYPASS_CMDID);
  57. if (QDF_IS_STATUS_ERROR(ret)) {
  58. wmi_err("Failed to send set param command ret = %d", ret);
  59. wmi_buf_free(buf);
  60. }
  61. return ret;
  62. }
  63. /**
  64. * send_get_elna_bypass_cmd_tlv() - send get elna bypass cmd to fw
  65. * @wmi_handle: wmi handle
  66. * @req: get eLNA bypass request
  67. *
  68. * Send WMI_GET_ELNA_BYPASS_CMDID to fw.
  69. *
  70. * Return: QDF_STATUS
  71. */
  72. static QDF_STATUS
  73. send_get_elna_bypass_cmd_tlv(wmi_unified_t wmi_handle,
  74. struct get_elna_bypass_request *req)
  75. {
  76. wmi_buf_t buf;
  77. wmi_get_elna_bypass_cmd_fixed_param *cmd;
  78. uint16_t len = sizeof(*cmd);
  79. QDF_STATUS ret;
  80. buf = wmi_buf_alloc(wmi_handle, len);
  81. if (!buf) {
  82. wmi_err("Failed to allocate wmi buffer");
  83. return QDF_STATUS_E_NOMEM;
  84. }
  85. cmd = (wmi_get_elna_bypass_cmd_fixed_param *)wmi_buf_data(buf);
  86. WMITLV_SET_HDR(&cmd->tlv_header,
  87. WMITLV_TAG_STRUC_wmi_get_elna_bypass_cmd_fixed_param,
  88. WMITLV_GET_STRUCT_TLVLEN
  89. (wmi_get_elna_bypass_cmd_fixed_param));
  90. cmd->vdev_id = req->vdev_id;
  91. wmi_mtrace(WMI_GET_ELNA_BYPASS_CMDID, req->vdev_id, 0);
  92. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  93. WMI_GET_ELNA_BYPASS_CMDID);
  94. if (QDF_IS_STATUS_ERROR(ret)) {
  95. wmi_err("Failed to send set param command ret = %d", ret);
  96. wmi_buf_free(buf);
  97. }
  98. return ret;
  99. }
  100. /**
  101. * extract_get_elna_bypass_resp_tlv() - Extract WMI get eLNA bypass response
  102. * @wmi_handle: wmi handle
  103. * @resp_buf: response buffer
  104. * @resp: get eLNA bypass response
  105. *
  106. * Extract WMI get eLNA bypass response from firmware.
  107. *
  108. * Return: QDF_STATUS
  109. */
  110. static QDF_STATUS
  111. extract_get_elna_bypass_resp_tlv(struct wmi_unified *wmi_handle, void *resp_buf,
  112. struct get_elna_bypass_response *resp)
  113. {
  114. WMI_GET_ELNA_BYPASS_EVENTID_param_tlvs *param_buf;
  115. wmi_get_elna_bypass_event_fixed_param *evt;
  116. param_buf = resp_buf;
  117. evt = param_buf->fixed_param;
  118. if (!evt) {
  119. wmi_err("Invalid get elna bypass event");
  120. return QDF_STATUS_E_INVAL;
  121. }
  122. wmi_debug("Get elna bypass %d from vdev %d",
  123. evt->en_dis, evt->vdev_id);
  124. resp->vdev_id = evt->vdev_id;
  125. resp->elna_mode = evt->en_dis;
  126. return QDF_STATUS_SUCCESS;
  127. }
  128. #endif /* WLAN_FEATURE_ELNA */
  129. #ifdef WLAN_FEATURE_ELNA
  130. static void wmi_fwol_attach_elna_tlv(struct wmi_ops *ops)
  131. {
  132. ops->send_set_elna_bypass_cmd = send_set_elna_bypass_cmd_tlv;
  133. ops->send_get_elna_bypass_cmd = send_get_elna_bypass_cmd_tlv;
  134. ops->extract_get_elna_bypass_resp = extract_get_elna_bypass_resp_tlv;
  135. }
  136. #else
  137. static void wmi_fwol_attach_elna_tlv(struct wmi_ops *ops)
  138. {
  139. }
  140. #endif /* WLAN_FEATURE_ELNA */
  141. #ifdef WLAN_SEND_DSCP_UP_MAP_TO_FW
  142. /**
  143. * send_dscp_tid_map_cmd_tlv() - send dscp to tid map cmd to fw
  144. * @wmi_handle: wmi handle
  145. * @dscp_to_tid_map: array of dscp to tid map values
  146. *
  147. * Send WMI_PDEV_SET_DSCP_TID_MAP_CMDID to fw.
  148. *
  149. * Return: QDF_STATUS
  150. */
  151. static QDF_STATUS
  152. send_dscp_tid_map_cmd_tlv(wmi_unified_t wmi_handle,
  153. uint32_t *dscp_to_tid_map)
  154. {
  155. QDF_STATUS status;
  156. wmi_pdev_set_dscp_tid_map_cmd_fixed_param *cmd;
  157. wmi_buf_t buf;
  158. uint16_t len = sizeof(*cmd);
  159. buf = wmi_buf_alloc(wmi_handle, len);
  160. if (!buf) {
  161. wmi_err("Failed to allocate wmi buffer");
  162. return QDF_STATUS_E_NOMEM;
  163. }
  164. cmd = (wmi_pdev_set_dscp_tid_map_cmd_fixed_param *)wmi_buf_data(buf);
  165. WMITLV_SET_HDR(
  166. &cmd->tlv_header,
  167. WMITLV_TAG_STRUC_wmi_pdev_set_dscp_tid_map_cmd_fixed_param,
  168. WMITLV_GET_STRUCT_TLVLEN
  169. (wmi_pdev_set_dscp_tid_map_cmd_fixed_param));
  170. cmd->reserved0 = WMI_PDEV_ID_SOC;
  171. qdf_mem_copy(&cmd->dscp_to_tid_map, dscp_to_tid_map,
  172. sizeof(uint32_t) * WMI_DSCP_MAP_MAX);
  173. status = wmi_unified_cmd_send(wmi_handle, buf, len,
  174. WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
  175. if (status) {
  176. wmi_err("Failed to send dscp_up_map_to_fw %d", status);
  177. wmi_buf_free(buf);
  178. }
  179. return status;
  180. }
  181. static void wmi_fwol_attach_dscp_tid_tlv(struct wmi_ops *ops)
  182. {
  183. ops->send_dscp_tid_map_cmd = send_dscp_tid_map_cmd_tlv;
  184. }
  185. #else
  186. static void wmi_fwol_attach_dscp_tid_tlv(struct wmi_ops *ops)
  187. {
  188. }
  189. #endif /* WLAN_SEND_DSCP_UP_MAP_TO_FW */
  190. #ifdef WLAN_FEATURE_MDNS_OFFLOAD
  191. /**
  192. * send_set_mdns_fqdn_cmd_tlv() - send set mDNS FQDN cmd to fw
  193. * @wmi_handle: wmi handle
  194. * @mdns_info: mDNS config info
  195. *
  196. * Send WMI_MDNS_SET_FQDN_CMDID to fw.
  197. *
  198. * Return: QDF_STATUS
  199. */
  200. static QDF_STATUS
  201. send_set_mdns_fqdn_cmd_tlv(wmi_unified_t wmi_handle,
  202. struct mdns_config_info *mdns_info)
  203. {
  204. wmi_buf_t buf;
  205. uint8_t *buf_ptr;
  206. wmi_mdns_set_fqdn_cmd_fixed_param *cmd;
  207. uint16_t len = sizeof(*cmd);
  208. uint16_t fqdn_len_aligned;
  209. QDF_STATUS ret;
  210. fqdn_len_aligned = roundup(mdns_info->fqdn_len, sizeof(uint32_t));
  211. if (fqdn_len_aligned < mdns_info->fqdn_len) {
  212. wmi_err_rl("integer overflow while rounding up data_len");
  213. return QDF_STATUS_E_FAILURE;
  214. }
  215. if (fqdn_len_aligned > WMI_SVC_MSG_MAX_SIZE - WMI_TLV_HDR_SIZE) {
  216. wmi_err_rl("wmi_max_msg_size overflow for given data_len");
  217. return QDF_STATUS_E_FAILURE;
  218. }
  219. len += WMI_TLV_HDR_SIZE + fqdn_len_aligned;
  220. buf = wmi_buf_alloc(wmi_handle, len);
  221. if (!buf) {
  222. wmi_err_rl("Failed to allocate wmi buffer");
  223. return QDF_STATUS_E_NOMEM;
  224. }
  225. buf_ptr = wmi_buf_data(buf);
  226. cmd = (wmi_mdns_set_fqdn_cmd_fixed_param *)buf_ptr;
  227. WMITLV_SET_HDR(&cmd->tlv_header,
  228. WMITLV_TAG_STRUC_wmi_mdns_set_fqdn_cmd_fixed_param,
  229. WMITLV_GET_STRUCT_TLVLEN
  230. (wmi_mdns_set_fqdn_cmd_fixed_param));
  231. cmd->vdev_id = mdns_info->vdev_id;
  232. cmd->type = mdns_info->fqdn_type;
  233. cmd->fqdn_len = mdns_info->fqdn_len;
  234. buf_ptr += sizeof(*cmd);
  235. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, fqdn_len_aligned);
  236. buf_ptr += WMI_TLV_HDR_SIZE;
  237. qdf_mem_copy(buf_ptr, mdns_info->fqdn_data, cmd->fqdn_len);
  238. wmi_mtrace(WMI_MDNS_SET_FQDN_CMDID, mdns_info->vdev_id,
  239. mdns_info->fqdn_type);
  240. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  241. WMI_MDNS_SET_FQDN_CMDID);
  242. if (QDF_IS_STATUS_ERROR(ret))
  243. wmi_buf_free(buf);
  244. return ret;
  245. }
  246. /**
  247. * send_set_mdns_response_cmd_tlv() - send set mDNS response cmd to fw
  248. * @wmi_handle: wmi handle
  249. * @mdns_info: mDNS config info
  250. *
  251. * Send WMI_MDNS_SET_RESPONSE_CMDID to fw.
  252. *
  253. * Return: QDF_STATUS
  254. */
  255. static QDF_STATUS
  256. send_set_mdns_response_cmd_tlv(wmi_unified_t wmi_handle,
  257. struct mdns_config_info *mdns_info)
  258. {
  259. wmi_buf_t buf;
  260. uint8_t *buf_ptr;
  261. wmi_mdns_set_resp_cmd_fixed_param *cmd;
  262. uint16_t len = sizeof(*cmd);
  263. uint16_t resp_len_aligned;
  264. QDF_STATUS ret;
  265. resp_len_aligned = roundup(mdns_info->answer_payload_len, sizeof(uint32_t));
  266. if (resp_len_aligned < mdns_info->answer_payload_len) {
  267. wmi_err_rl("integer overflow while rounding up data_len");
  268. return QDF_STATUS_E_FAILURE;
  269. }
  270. if (resp_len_aligned > WMI_SVC_MSG_MAX_SIZE - WMI_TLV_HDR_SIZE) {
  271. wmi_err_rl("wmi_max_msg_size overflow for given data_len");
  272. return QDF_STATUS_E_FAILURE;
  273. }
  274. len += WMI_TLV_HDR_SIZE + resp_len_aligned;
  275. buf = wmi_buf_alloc(wmi_handle, len);
  276. if (!buf) {
  277. wmi_err_rl("Failed to allocate wmi buffer");
  278. return QDF_STATUS_E_NOMEM;
  279. }
  280. buf_ptr = wmi_buf_data(buf);
  281. cmd = (wmi_mdns_set_resp_cmd_fixed_param *)buf_ptr;
  282. WMITLV_SET_HDR(&cmd->tlv_header,
  283. WMITLV_TAG_STRUC_wmi_mdns_set_resp_cmd_fixed_param,
  284. WMITLV_GET_STRUCT_TLVLEN
  285. (wmi_mdns_set_resp_cmd_fixed_param));
  286. cmd->vdev_id = mdns_info->vdev_id;
  287. cmd->AR_count = mdns_info->resource_record_count;
  288. cmd->resp_len = mdns_info->answer_payload_len;
  289. buf_ptr += sizeof(*cmd);
  290. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE, resp_len_aligned);
  291. buf_ptr += WMI_TLV_HDR_SIZE;
  292. qdf_mem_copy(buf_ptr, mdns_info->answer_payload_data, cmd->resp_len);
  293. wmi_mtrace(WMI_MDNS_SET_RESPONSE_CMDID, mdns_info->vdev_id, 0);
  294. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  295. WMI_MDNS_SET_RESPONSE_CMDID);
  296. if (QDF_IS_STATUS_ERROR(ret))
  297. wmi_buf_free(buf);
  298. return ret;
  299. }
  300. /**
  301. * send_set_mdns_offload_cmd_tlv() - send set mDNS offload cmd to fw
  302. * @wmi_handle: wmi handle
  303. * @mdns_info: mDNS config info
  304. *
  305. * Send WMI_MDNS_OFFLOAD_ENABLE_CMDID to fw.
  306. *
  307. * Return: QDF_STATUS
  308. */
  309. static QDF_STATUS
  310. send_set_mdns_offload_cmd_tlv(wmi_unified_t wmi_handle,
  311. struct mdns_config_info *mdns_info)
  312. {
  313. wmi_buf_t buf;
  314. wmi_mdns_offload_cmd_fixed_param *cmd;
  315. uint16_t len = sizeof(*cmd);
  316. QDF_STATUS ret;
  317. buf = wmi_buf_alloc(wmi_handle, len);
  318. if (!buf) {
  319. wmi_err_rl("Failed to allocate wmi buffer");
  320. return QDF_STATUS_E_NOMEM;
  321. }
  322. cmd = (wmi_mdns_offload_cmd_fixed_param *)wmi_buf_data(buf);
  323. WMITLV_SET_HDR(&cmd->tlv_header,
  324. WMITLV_TAG_STRUC_wmi_mdns_offload_cmd_fixed_param,
  325. WMITLV_GET_STRUCT_TLVLEN
  326. (wmi_mdns_offload_cmd_fixed_param));
  327. cmd->vdev_id = mdns_info->vdev_id;
  328. cmd->enable = mdns_info->enable;
  329. wmi_mtrace(WMI_MDNS_OFFLOAD_ENABLE_CMDID, mdns_info->vdev_id, 0);
  330. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  331. WMI_MDNS_OFFLOAD_ENABLE_CMDID);
  332. if (QDF_IS_STATUS_ERROR(ret))
  333. wmi_buf_free(buf);
  334. return ret;
  335. }
  336. /**
  337. * send_set_mdns_config_cmd_tlv() - send set mDNS config cmd to fw
  338. * @wmi_handle: wmi handle
  339. * @mdns_info: mdns config info
  340. *
  341. * Return: QDF_STATUS
  342. */
  343. static QDF_STATUS
  344. send_set_mdns_config_cmd_tlv(wmi_unified_t wmi_handle,
  345. struct mdns_config_info *mdns_info)
  346. {
  347. QDF_STATUS ret;
  348. if (!mdns_info->enable) {
  349. ret = send_set_mdns_offload_cmd_tlv(wmi_handle, mdns_info);
  350. if (QDF_IS_STATUS_ERROR(ret))
  351. wmi_err_rl("Failed to send mDNS offload command. ret = %d", ret);
  352. return ret;
  353. }
  354. ret = send_set_mdns_fqdn_cmd_tlv(wmi_handle, mdns_info);
  355. if (QDF_IS_STATUS_ERROR(ret)) {
  356. wmi_err_rl("Failed to send set fqdn command. ret = %d", ret);
  357. return ret;
  358. }
  359. ret = send_set_mdns_response_cmd_tlv(wmi_handle, mdns_info);
  360. if (QDF_IS_STATUS_ERROR(ret)) {
  361. wmi_err_rl("Failed to send set mDNS response command. ret = %d", ret);
  362. return ret;
  363. }
  364. ret = send_set_mdns_offload_cmd_tlv(wmi_handle, mdns_info);
  365. if (QDF_IS_STATUS_ERROR(ret)) {
  366. wmi_err_rl("Failed to send set mDNS offload command. ret = %d", ret);
  367. return ret;
  368. }
  369. return ret;
  370. }
  371. static void wmi_fwol_attach_mdns_tlv(struct wmi_ops *ops)
  372. {
  373. ops->send_set_mdns_config_cmd = send_set_mdns_config_cmd_tlv;
  374. }
  375. #else
  376. static void wmi_fwol_attach_mdns_tlv(struct wmi_ops *ops)
  377. {
  378. }
  379. #endif /* WLAN_FEATURE_MDNS_OFFLOAD */
  380. #ifdef THERMAL_STATS_SUPPORT
  381. /**
  382. * send_get_thermal_stats_cmd_tlv() - send get thermal stats cmd to fw
  383. * @wmi_handle: wmi handle
  384. * @req_type: req type
  385. * @temp_offset: temperature offset
  386. *
  387. * Send WMI_REQUEST_THERMAL_STATS_CMDID to fw.
  388. *
  389. * Return: QDF_STATUS
  390. */
  391. static QDF_STATUS
  392. send_get_thermal_stats_cmd_tlv(wmi_unified_t wmi_handle,
  393. enum thermal_stats_request_type req_type,
  394. uint8_t temp_offset)
  395. {
  396. wmi_buf_t buf;
  397. wmi_thermal_stats_cmd_fixed_param *cmd;
  398. uint16_t len = sizeof(*cmd);
  399. QDF_STATUS ret;
  400. buf = wmi_buf_alloc(wmi_handle, len);
  401. if (!buf) {
  402. wmi_err("Failed to allocate wmi buffer");
  403. return QDF_STATUS_E_NOMEM;
  404. }
  405. cmd = (wmi_thermal_stats_cmd_fixed_param *)wmi_buf_data(buf);
  406. WMITLV_SET_HDR(&cmd->tlv_header,
  407. WMITLV_TAG_STRUC_wmi_thermal_stats_cmd_fixed_param,
  408. WMITLV_GET_STRUCT_TLVLEN
  409. (wmi_thermal_stats_cmd_fixed_param));
  410. cmd->thermal_action = req_type;
  411. cmd->thermal_offset = temp_offset;
  412. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  413. WMI_REQUEST_THERMAL_STATS_CMDID);
  414. if (QDF_IS_STATUS_ERROR(ret)) {
  415. wmi_err("Failed to send get thermal stats cmd = %d", ret);
  416. wmi_buf_free(buf);
  417. }
  418. return ret;
  419. }
  420. static void wmi_fwol_attach_thermal_stats_tlv(struct wmi_ops *ops)
  421. {
  422. ops->send_get_thermal_stats_cmd = send_get_thermal_stats_cmd_tlv;
  423. }
  424. #else
  425. static void wmi_fwol_attach_thermal_stats_tlv(struct wmi_ops *ops)
  426. {
  427. }
  428. #endif /* FW_THERMAL_THROTTLE_SUPPORT */
  429. void wmi_fwol_attach_tlv(wmi_unified_t wmi_handle)
  430. {
  431. struct wmi_ops *ops = wmi_handle->ops;
  432. wmi_fwol_attach_elna_tlv(ops);
  433. wmi_fwol_attach_dscp_tid_tlv(ops);
  434. wmi_fwol_attach_mdns_tlv(ops);
  435. wmi_fwol_attach_thermal_stats_tlv(ops);
  436. }