1 /*
2  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * DOC: wlan_qmi_ucfg_api.c
19  *
20  * QMI component north bound interface definitions
21  */
22 
23 #include "wlan_qmi_ucfg_api.h"
24 #include "wlan_qmi_main.h"
25 #include "wlan_qmi_objmgr.h"
26 #include "wlan_objmgr_global_obj.h"
27 #include "wlan_cmn.h"
28 
ucfg_qmi_init(void)29 QDF_STATUS ucfg_qmi_init(void)
30 {
31 	QDF_STATUS status;
32 
33 	status = wlan_objmgr_register_psoc_create_handler(
34 			WLAN_UMAC_COMP_QMI,
35 			qmi_psoc_obj_create_notification, NULL);
36 	if (QDF_IS_STATUS_ERROR(status)) {
37 		qmi_err("Failed to register psoc create handler for QMI");
38 		return status;
39 	}
40 
41 	status = wlan_objmgr_register_psoc_destroy_handler(
42 			WLAN_UMAC_COMP_QMI,
43 			qmi_psoc_obj_destroy_notification, NULL);
44 	if (QDF_IS_STATUS_ERROR(status)) {
45 		qmi_err("Failed to register psoc destroy handler for QMI");
46 		goto fail_destroy_psoc;
47 	}
48 
49 	return status;
50 
51 fail_destroy_psoc:
52 	wlan_objmgr_unregister_psoc_create_handler(
53 				WLAN_UMAC_COMP_QMI,
54 				qmi_psoc_obj_create_notification, NULL);
55 
56 	return status;
57 }
58 
ucfg_qmi_deinit(void)59 QDF_STATUS ucfg_qmi_deinit(void)
60 {
61 	QDF_STATUS status;
62 
63 	qmi_debug("QMI module dispatcher deinit");
64 
65 	status = wlan_objmgr_unregister_psoc_destroy_handler(
66 				WLAN_UMAC_COMP_QMI,
67 				qmi_psoc_obj_destroy_notification, NULL);
68 	if (QDF_IS_STATUS_ERROR(status))
69 		qmi_err("Failed to unregister QMI psoc delete handle:%d",
70 			status);
71 
72 	status = wlan_objmgr_unregister_psoc_create_handler(
73 				WLAN_UMAC_COMP_QMI,
74 				qmi_psoc_obj_create_notification, NULL);
75 	if (QDF_IS_STATUS_ERROR(status))
76 		qmi_err("Failed to unregister QMI psoc create handle:%d",
77 			status);
78 
79 	return status;
80 }
81 
82 #ifdef QMI_WFDS
83 /**
84  * ucfg_qmi_wfds_register_os_if_callbacks() - API to register wfds os if
85  *  callbacks with QMI component
86  * @qmi_ctx: QMI component context
87  * @cb_obj: callback object
88  *
89  * Return: None
90  */
91 static void
ucfg_qmi_wfds_register_os_if_callbacks(struct wlan_qmi_psoc_context * qmi_ctx,struct wlan_qmi_psoc_callbacks * cb_obj)92 ucfg_qmi_wfds_register_os_if_callbacks(struct wlan_qmi_psoc_context *qmi_ctx,
93 				       struct wlan_qmi_psoc_callbacks *cb_obj)
94 {
95 	qmi_ctx->qmi_cbs.qmi_wfds_init = cb_obj->qmi_wfds_init;
96 	qmi_ctx->qmi_cbs.qmi_wfds_deinit = cb_obj->qmi_wfds_deinit;
97 	qmi_ctx->qmi_cbs.qmi_wfds_send_config_msg =
98 				cb_obj->qmi_wfds_send_config_msg;
99 	qmi_ctx->qmi_cbs.qmi_wfds_send_req_mem_msg =
100 				cb_obj->qmi_wfds_send_req_mem_msg;
101 	qmi_ctx->qmi_cbs.qmi_wfds_send_ipcc_map_n_cfg_msg =
102 				cb_obj->qmi_wfds_send_ipcc_map_n_cfg_msg;
103 	qmi_ctx->qmi_cbs.qmi_wfds_send_misc_req_msg =
104 				cb_obj->qmi_wfds_send_misc_req_msg;
105 }
106 #else
107 static inline void
ucfg_qmi_wfds_register_os_if_callbacks(struct wlan_qmi_psoc_context * qmi_ctx,struct wlan_qmi_psoc_callbacks * cb_obj)108 ucfg_qmi_wfds_register_os_if_callbacks(struct wlan_qmi_psoc_context *qmi_ctx,
109 				       struct wlan_qmi_psoc_callbacks *cb_obj)
110 {
111 }
112 #endif
113 
ucfg_qmi_register_os_if_callbacks(struct wlan_objmgr_psoc * psoc,struct wlan_qmi_psoc_callbacks * cb_obj)114 void ucfg_qmi_register_os_if_callbacks(struct wlan_objmgr_psoc *psoc,
115 				       struct wlan_qmi_psoc_callbacks *cb_obj)
116 {
117 	struct wlan_qmi_psoc_context *qmi_ctx = qmi_psoc_get_priv(psoc);
118 
119 	if (!qmi_ctx) {
120 		qmi_err("QMI context is NULL");
121 		return;
122 	}
123 
124 	ucfg_qmi_wfds_register_os_if_callbacks(qmi_ctx, cb_obj);
125 }
126