1 /*
2 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /**
20 * DOC: wma_fw_state.c
21 *
22 * The implementation for getting firmware state
23 */
24
25 #include "wma_fw_state.h"
26 #include "wmi_unified_api.h"
27
wma_get_fw_state(tp_wma_handle wma_handle)28 QDF_STATUS wma_get_fw_state(tp_wma_handle wma_handle)
29 {
30 wmi_echo_cmd_fixed_param *cmd;
31 wmi_buf_t wmi_buf;
32 uint32_t len = sizeof(*cmd);
33
34 if (wma_validate_handle(wma_handle))
35 return QDF_STATUS_E_INVAL;
36
37 wmi_buf = wmi_buf_alloc(wma_handle->wmi_handle, len);
38 if (!wmi_buf)
39 return QDF_STATUS_E_NOMEM;
40
41 cmd = (wmi_echo_cmd_fixed_param *)wmi_buf_data(wmi_buf);
42 WMITLV_SET_HDR(&cmd->tlv_header,
43 WMITLV_TAG_STRUC_wmi_echo_cmd_fixed_param,
44 WMITLV_GET_STRUCT_TLVLEN(
45 wmi_echo_cmd_fixed_param));
46 cmd->value = true;
47
48 if (wmi_unified_cmd_send(wma_handle->wmi_handle, wmi_buf, len,
49 WMI_ECHO_CMDID)) {
50 wmi_buf_free(wmi_buf);
51 return QDF_STATUS_E_FAILURE;
52 }
53
54 return QDF_STATUS_SUCCESS;
55 }
56
57 /**
58 * wma_echo_event_handler() - process fw state rsp
59 * @handle: wma interface
60 * @buf: wmi event buf pointer
61 * @len: length of event buffer
62 *
63 * This function will send eWNI_SME_FW_STATUS_IND to SME
64 *
65 * Return: 0 for success or error code
66 */
wma_echo_event_handler(void * handle,uint8_t * buf,uint32_t len)67 static int wma_echo_event_handler(void *handle, uint8_t *buf, uint32_t len)
68 {
69 struct scheduler_msg sme_msg = {
70 .type = eWNI_SME_FW_STATUS_IND,
71 };
72 QDF_STATUS qdf_status;
73
74 wma_debug("Received Echo reply from firmware!");
75
76 qdf_status = scheduler_post_message(QDF_MODULE_ID_WMA,
77 QDF_MODULE_ID_SME,
78 QDF_MODULE_ID_SME, &sme_msg);
79 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
80 wma_err("Fail to post fw state reply msg");
81 return -EINVAL;
82 }
83
84 return 0;
85 }
86
wma_register_fw_state_events(wmi_unified_t wmi_handle)87 void wma_register_fw_state_events(wmi_unified_t wmi_handle)
88 {
89 wmi_unified_register_event_handler(wmi_handle,
90 wmi_echo_event_id,
91 wma_echo_event_handler,
92 WMA_RX_SERIALIZER_CTX);
93 }
94