1 /*
2  * Copyright (c) 2022 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: This file contains main P2P mcc quota event process core function
21  * implementation
22  */
23 
24 #include <wlan_objmgr_psoc_obj.h>
25 #include <wlan_objmgr_pdev_obj.h>
26 #include <wlan_objmgr_vdev_obj.h>
27 #include "wlan_p2p_mcc_quota_public_struct.h"
28 #include "wlan_p2p_public_struct.h"
29 #include "wlan_p2p_ucfg_api.h"
30 #include "wlan_p2p_main.h"
31 #include "wlan_p2p_mcc_quota.h"
32 
33 /**
34  * struct wlan_mcc_quota_context - context for vdev iterate handler
35  * @indicated: mcc quota info indicated to os
36  * @quota_info: mcc quota information
37  * @p2p_soc_obj: p2p soc object
38  */
39 struct wlan_mcc_quota_context {
40 	bool indicated;
41 	struct mcc_quota_info *quota_info;
42 	struct p2p_soc_priv_obj *p2p_soc_obj;
43 };
44 
45 /**
46  * wlan_indicate_quota_vdev_handler() - Vdev iterate handler to indicate
47  * mcc quota event to vdev object
48  * @psoc: psoc object
49  * @obj: vdev object
50  * @args: handler context
51  *
52  * Return: void
53  */
wlan_indicate_quota_vdev_handler(struct wlan_objmgr_psoc * psoc,void * obj,void * args)54 static void wlan_indicate_quota_vdev_handler(struct wlan_objmgr_psoc *psoc,
55 					     void *obj, void *args)
56 {
57 	struct wlan_objmgr_vdev *vdev = obj;
58 	struct wlan_mcc_quota_context *context = args;
59 	struct p2p_soc_priv_obj *p2p_soc_obj = context->p2p_soc_obj;
60 	enum QDF_OPMODE op_mode;
61 	QDF_STATUS status;
62 
63 	op_mode = wlan_vdev_mlme_get_opmode(vdev);
64 	if (op_mode != QDF_STA_MODE &&
65 	    op_mode != QDF_SAP_MODE &&
66 	    op_mode != QDF_P2P_CLIENT_MODE &&
67 	    op_mode != QDF_P2P_GO_MODE)
68 		return;
69 
70 	status = p2p_soc_obj->mcc_quota_ev_os_if_cb(psoc, vdev,
71 						    context->quota_info);
72 	if (status != QDF_STATUS_SUCCESS)
73 		return;
74 
75 	context->indicated = true;
76 }
77 
p2p_mcc_quota_event_process(struct wlan_objmgr_psoc * psoc,struct mcc_quota_info * event_info)78 QDF_STATUS p2p_mcc_quota_event_process(struct wlan_objmgr_psoc *psoc,
79 				       struct mcc_quota_info *event_info)
80 {
81 	struct p2p_soc_priv_obj *p2p_soc_obj;
82 	struct wlan_mcc_quota_context context;
83 
84 	if (!event_info) {
85 		p2p_err("invalid mcc quota event information");
86 		return QDF_STATUS_E_INVAL;
87 	}
88 
89 	if (!psoc) {
90 		p2p_err("psoc context passed is NULL");
91 		return QDF_STATUS_E_INVAL;
92 	}
93 	p2p_soc_obj = wlan_objmgr_psoc_get_comp_private_obj(psoc,
94 							    WLAN_UMAC_COMP_P2P);
95 	if (!p2p_soc_obj) {
96 		p2p_err("p2p soc object is NULL");
97 		return QDF_STATUS_E_INVAL;
98 	}
99 	if (!p2p_soc_obj->mcc_quota_ev_os_if_cb) {
100 		p2p_err("mcc_quota_ev_os_if_cb is NULL");
101 		return QDF_STATUS_E_INVAL;
102 	}
103 
104 	qdf_mem_zero(&context, sizeof(struct wlan_mcc_quota_context));
105 	context.quota_info = event_info;
106 	context.p2p_soc_obj = p2p_soc_obj;
107 	wlan_objmgr_iterate_obj_list(psoc, WLAN_VDEV_OP,
108 				     wlan_indicate_quota_vdev_handler,
109 				     &context, true, WLAN_P2P_ID);
110 
111 	if (context.indicated)
112 		return QDF_STATUS_SUCCESS;
113 	else
114 		return p2p_soc_obj->mcc_quota_ev_os_if_cb(psoc, NULL,
115 							  event_info);
116 }
117