xref: /wlan-driver/qcacld-3.0/components/target_if/sap/ll_sap/src/target_if_ll_sap.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 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 #include "target_if.h"
18 #include "target_if_ll_sap.h"
19 #include "wlan_ll_sap_public_structs.h"
20 #include "wmi_unified_ll_sap_api.h"
21 #include "../../umac/mlme/sap/ll_sap/core/src/wlan_ll_sap_main.h"
22 #include "wlan_ll_sap_api.h"
23 
24 /**
25  * target_if_send_audio_transport_switch_resp() - Send audio transport switch
26  * response to fw
27  * @psoc: pointer to psoc
28  * @req_type: Bearer switch request type
29  * @status: Status of the bearer switch request
30  *
31  * Return: pointer to tx ops
32  */
target_if_send_audio_transport_switch_resp(struct wlan_objmgr_psoc * psoc,enum bearer_switch_req_type req_type,enum bearer_switch_status status)33 static QDF_STATUS target_if_send_audio_transport_switch_resp(
34 					struct wlan_objmgr_psoc *psoc,
35 					enum bearer_switch_req_type req_type,
36 					enum bearer_switch_status status)
37 {
38 	struct wmi_unified *wmi_handle;
39 
40 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
41 	if (!wmi_handle) {
42 		target_if_err("wmi_handle is null.");
43 		return QDF_STATUS_E_NULL_VALUE;
44 	}
45 
46 	return wmi_unified_audio_transport_switch_resp_send(wmi_handle,
47 							    req_type, status);
48 }
49 
target_if_send_audio_transport_switch_req_event_handler(ol_scn_t scn,uint8_t * event,uint32_t len)50 static int target_if_send_audio_transport_switch_req_event_handler(
51 							ol_scn_t scn,
52 							uint8_t *event,
53 							uint32_t len)
54 {
55 	struct wlan_objmgr_psoc *psoc;
56 	struct ll_sap_psoc_priv_obj *psoc_ll_sap_obj;
57 	enum bearer_switch_req_type req_type;
58 	struct wmi_unified *wmi_handle;
59 	struct wlan_ll_sap_rx_ops *rx_ops;
60 	QDF_STATUS qdf_status;
61 
62 	psoc = target_if_get_psoc_from_scn_hdl(scn);
63 	if (!psoc) {
64 		target_if_err("psoc is null");
65 		return -EINVAL;
66 	}
67 
68 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
69 	if (!wmi_handle) {
70 		target_if_err("wmi_handle is null");
71 		return -EINVAL;
72 	}
73 
74 	psoc_ll_sap_obj = wlan_objmgr_psoc_get_comp_private_obj(
75 							psoc,
76 							WLAN_UMAC_COMP_LL_SAP);
77 
78 	if (!psoc_ll_sap_obj) {
79 		target_if_err("psoc_ll_sap_obj is null");
80 		return -EINVAL;
81 	}
82 
83 	rx_ops = &psoc_ll_sap_obj->rx_ops;
84 	if (!rx_ops || !rx_ops->audio_transport_switch_req) {
85 		target_if_err("Invalid ll_sap rx ops");
86 		return -EINVAL;
87 	}
88 
89 	qdf_status = wmi_extract_audio_transport_switch_req_event(wmi_handle,
90 								  event, len,
91 								  &req_type);
92 	if (QDF_IS_STATUS_ERROR(qdf_status)) {
93 		target_if_err("parsing of event failed, %d", qdf_status);
94 		return -EINVAL;
95 	}
96 	rx_ops->audio_transport_switch_req(psoc, req_type);
97 
98 	return 0;
99 }
100 
101 void
target_if_ll_sap_register_tx_ops(struct wlan_ll_sap_tx_ops * tx_ops)102 target_if_ll_sap_register_tx_ops(struct wlan_ll_sap_tx_ops *tx_ops)
103 {
104 	tx_ops->send_audio_transport_switch_resp =
105 		target_if_send_audio_transport_switch_resp;
106 }
107 
108 void
target_if_ll_sap_register_rx_ops(struct wlan_ll_sap_rx_ops * rx_ops)109 target_if_ll_sap_register_rx_ops(struct wlan_ll_sap_rx_ops *rx_ops)
110 {
111 	rx_ops->audio_transport_switch_req =
112 		wlan_ll_sap_fw_bearer_switch_req;
113 }
114 
115 QDF_STATUS
target_if_ll_sap_register_events(struct wlan_objmgr_psoc * psoc)116 target_if_ll_sap_register_events(struct wlan_objmgr_psoc *psoc)
117 {
118 	QDF_STATUS ret;
119 	wmi_unified_t handle = get_wmi_unified_hdl_from_psoc(psoc);
120 
121 	if (!handle) {
122 		target_if_err("handle is NULL");
123 		return QDF_STATUS_E_FAILURE;
124 	}
125 
126 	ret = wmi_unified_register_event_handler(
127 			handle,
128 			wmi_audio_transport_switch_type_event_id,
129 			target_if_send_audio_transport_switch_req_event_handler,
130 			WMI_RX_SERIALIZER_CTX);
131 	return ret;
132 }
133 
134 QDF_STATUS
target_if_ll_sap_deregister_events(struct wlan_objmgr_psoc * psoc)135 target_if_ll_sap_deregister_events(struct wlan_objmgr_psoc *psoc)
136 {
137 	QDF_STATUS ret;
138 	wmi_unified_t handle = get_wmi_unified_hdl_from_psoc(psoc);
139 
140 	if (!handle) {
141 		target_if_err("handle is NULL");
142 		return QDF_STATUS_E_FAILURE;
143 	}
144 
145 	ret = wmi_unified_unregister_event_handler(
146 			handle,
147 			wmi_audio_transport_switch_type_event_id);
148 	return ret;
149 }
150