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
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: offload lmac interface APIs implementation for P2P mcc quota event
21 * processing
22 */
23
24 #include <wmi_unified_api.h>
25 #include "wlan_p2p_mcc_quota_public_struct.h"
26 #include "target_if.h"
27 #include "target_if_p2p_mcc_quota.h"
28
29 /**
30 * target_if_mcc_quota_event_handler() - WMI callback for mcc_quota
31 * @scn: pointer to scn
32 * @data: event buffer
33 * @datalen: buffer length
34 *
35 * This function gets called from WMI when triggered WMI event
36 * WMI_RESMGR_CHAN_TIME_QUOTA_CHANGED_EVENTID
37 *
38 * Return: 0 - success, others - failure
39 */
target_if_mcc_quota_event_handler(ol_scn_t scn,uint8_t * data,uint32_t datalen)40 static int target_if_mcc_quota_event_handler(ol_scn_t scn, uint8_t *data,
41 uint32_t datalen)
42 {
43 struct wlan_objmgr_psoc *psoc;
44 struct wmi_unified *wmi_handle;
45 struct mcc_quota_info *event_info;
46 struct wlan_lmac_if_rx_ops *rx_ops;
47 struct wlan_lmac_if_p2p_rx_ops *p2p_rx_ops;
48 QDF_STATUS status = QDF_STATUS_E_FAILURE;
49
50 target_if_debug("scn:%pK, data:%pK, datalen:%d", scn, data, datalen);
51
52 if (!scn || !data) {
53 target_if_err("scn: 0x%pK, data: 0x%pK", scn, data);
54 return -EINVAL;
55 }
56
57 psoc = target_if_get_psoc_from_scn_hdl(scn);
58 if (!psoc) {
59 target_if_err("null psoc");
60 return -EINVAL;
61 }
62
63 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
64 if (!wmi_handle) {
65 target_if_err("null wmi handle");
66 return -EINVAL;
67 }
68
69 event_info = qdf_mem_malloc(sizeof(*event_info));
70 if (!event_info)
71 return -ENOMEM;
72
73 if (wmi_extract_mcc_quota_ev_param(wmi_handle, data,
74 event_info)) {
75 target_if_err("failed to extract mcc quota event");
76 qdf_mem_free(event_info);
77 return -EINVAL;
78 }
79 rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
80 if (!rx_ops) {
81 target_if_err("failed to get soc rx ops");
82 qdf_mem_free(event_info);
83 return -EINVAL;
84 }
85 p2p_rx_ops = &rx_ops->p2p;
86 if (p2p_rx_ops->mcc_quota_ev_handler) {
87 status = p2p_rx_ops->mcc_quota_ev_handler(psoc, event_info);
88 if (QDF_IS_STATUS_ERROR(status))
89 target_if_debug("quota event handler, status:%d",
90 status);
91 } else {
92 target_if_debug("no valid mcc quota event handler");
93 }
94 qdf_mem_free(event_info);
95
96 return qdf_status_to_os_return(status);
97 }
98
99 /**
100 * target_if_register_mcc_quota_event_handler() - Register or unregister
101 * mcc quota wmi event handler
102 * @psoc: psoc object
103 * @reg: register or unregister flag
104 *
105 * Return: QDF_STATUS_SUCCESS - in case of success
106 */
107 static QDF_STATUS
target_if_register_mcc_quota_event_handler(struct wlan_objmgr_psoc * psoc,bool reg)108 target_if_register_mcc_quota_event_handler(struct wlan_objmgr_psoc *psoc,
109 bool reg)
110 {
111 QDF_STATUS status;
112 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
113
114 if (!wmi_handle) {
115 target_if_err("Invalid wmi handle");
116 return QDF_STATUS_E_INVAL;
117 }
118 if (reg) {
119 status = wmi_unified_register_event_handler(wmi_handle,
120 wmi_resmgr_chan_time_quota_changed_eventid,
121 target_if_mcc_quota_event_handler,
122 WMI_RX_SERIALIZER_CTX);
123
124 target_if_debug("wmi register mcc_quota event handle, status:%d",
125 status);
126 } else {
127 status = wmi_unified_unregister_event_handler(wmi_handle,
128 wmi_resmgr_chan_time_quota_changed_eventid);
129
130 target_if_debug("wmi unregister mcc_quota event handle, status:%d",
131 status);
132 }
133
134 return status;
135 }
136
target_if_mcc_quota_register_tx_ops(struct wlan_lmac_if_tx_ops * tx_ops)137 void target_if_mcc_quota_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
138 {
139 struct wlan_lmac_if_p2p_tx_ops *p2p_tx_ops = &tx_ops->p2p;
140
141 p2p_tx_ops->reg_mcc_quota_ev_handler =
142 target_if_register_mcc_quota_event_handler;
143 }
144