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 /**
18  * DOC: wlan_afc_ucfg_api.c
19  *
20  * This file has the AFC dispatcher API implementation which is exposed
21  * to outside of AFC component.
22  */
23 
24 #include <wlan_afc_main.h>
25 #include <wlan_afc_ucfg_api.h>
26 #include <wlan_objmgr_global_obj.h>
27 
ucfg_afc_register_data_send_cb(struct wlan_objmgr_psoc * psoc,send_response_to_afcmem func)28 QDF_STATUS ucfg_afc_register_data_send_cb(struct wlan_objmgr_psoc *psoc,
29 					  send_response_to_afcmem func)
30 {
31 	return wlan_afc_register_data_send_cb(psoc, func);
32 }
33 
ucfg_afc_data_send(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_pdev * pdev,struct wlan_afc_host_resp * data,uint32_t len)34 int ucfg_afc_data_send(struct wlan_objmgr_psoc *psoc,
35 		       struct wlan_objmgr_pdev *pdev,
36 		       struct wlan_afc_host_resp *data,
37 		       uint32_t len)
38 {
39 	return wlan_afc_data_send(psoc, pdev, data, len);
40 }
41 
ucfg_afc_init(void)42 QDF_STATUS ucfg_afc_init(void)
43 {
44 	QDF_STATUS status;
45 
46 	status = wlan_objmgr_register_psoc_create_handler(WLAN_UMAC_COMP_AFC,
47 							  wlan_afc_psoc_created_notification,
48 							  NULL);
49 	if (QDF_IS_STATUS_ERROR(status)) {
50 		afc_err("Failed to register psoc create handler");
51 		goto fail_create_psoc;
52 	}
53 
54 	status = wlan_objmgr_register_psoc_destroy_handler(WLAN_UMAC_COMP_AFC,
55 							   wlan_afc_psoc_destroyed_notification,
56 							   NULL);
57 	if (QDF_IS_STATUS_ERROR(status)) {
58 		afc_err("Failed to register psoc delete handler");
59 		goto fail_psoc_destroy;
60 	}
61 
62 	status = wlan_objmgr_register_pdev_create_handler(WLAN_UMAC_COMP_AFC,
63 							  wlan_afc_pdev_obj_create_handler,
64 							  NULL);
65 	if (QDF_IS_STATUS_ERROR(status)) {
66 		afc_err("Failed to register pdev create handler");
67 		goto fail_create_pdev;
68 	}
69 
70 	status = wlan_objmgr_register_pdev_destroy_handler(WLAN_UMAC_COMP_AFC,
71 							   wlan_afc_pdev_obj_destroy_handler,
72 							   NULL);
73 	if (QDF_IS_STATUS_ERROR(status)) {
74 		afc_err("Failed to register pdev delete handler");
75 		goto fail_pdev_destroy;
76 	}
77 
78 	return status;
79 
80 fail_pdev_destroy:
81 	wlan_objmgr_unregister_pdev_create_handler(WLAN_UMAC_COMP_AFC,
82 						   wlan_afc_pdev_obj_create_handler,
83 						   NULL);
84 fail_create_pdev:
85 	wlan_objmgr_unregister_psoc_destroy_handler(WLAN_UMAC_COMP_AFC,
86 						    wlan_afc_psoc_destroyed_notification,
87 						    NULL);
88 fail_psoc_destroy:
89 	wlan_objmgr_unregister_psoc_create_handler(WLAN_UMAC_COMP_AFC,
90 						   wlan_afc_psoc_created_notification,
91 						   NULL);
92 fail_create_psoc:
93 	return status;
94 }
95 
ucfg_afc_deinit(void)96 QDF_STATUS ucfg_afc_deinit(void)
97 {
98 	QDF_STATUS status;
99 
100 	status = wlan_objmgr_unregister_pdev_destroy_handler(WLAN_UMAC_COMP_AFC,
101 							     wlan_afc_pdev_obj_destroy_handler,
102 							     NULL);
103 	if (QDF_IS_STATUS_ERROR(status))
104 		afc_err("Failed to unregister pdev destroy handler");
105 
106 	status = wlan_objmgr_unregister_pdev_create_handler(WLAN_UMAC_COMP_AFC,
107 							    wlan_afc_pdev_obj_create_handler,
108 							    NULL);
109 	if (QDF_IS_STATUS_ERROR(status))
110 		afc_err("Failed to unregister pdev create handler");
111 
112 	status = wlan_objmgr_unregister_psoc_destroy_handler(WLAN_UMAC_COMP_AFC,
113 							     wlan_afc_psoc_destroyed_notification,
114 							     NULL);
115 	if (QDF_IS_STATUS_ERROR(status))
116 		afc_err("Failed to unregister psoc destroy handler");
117 
118 	status = wlan_objmgr_unregister_psoc_create_handler(WLAN_UMAC_COMP_AFC,
119 							    wlan_afc_psoc_created_notification,
120 							    NULL);
121 	if (QDF_IS_STATUS_ERROR(status))
122 		afc_err("Failed to unregister psoc create handler");
123 
124 	return status;
125 }
126