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