1 /*
2 * Copyright (c) 2019-2021 The Linux Foundation. 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: Implements PDEV MLME APIs
19 */
20
21 #include <wlan_objmgr_cmn.h>
22 #include <wlan_objmgr_global_obj.h>
23 #include <wlan_objmgr_pdev_obj.h>
24 #include <wlan_mlme_dbg.h>
25 #include "include/wlan_mlme_cmn.h"
26 #include "include/wlan_pdev_mlme.h"
27 #include "wlan_pdev_mlme_main.h"
28 #include "wlan_pdev_mlme_api.h"
29 #include <wlan_utility.h>
30
mlme_pdev_obj_create_handler(struct wlan_objmgr_pdev * pdev,void * arg)31 static QDF_STATUS mlme_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev,
32 void *arg)
33 {
34 struct pdev_mlme_obj *pdev_mlme;
35 struct wlan_objmgr_psoc *psoc;
36
37 if (!pdev) {
38 mlme_err(" PDEV is NULL");
39 return QDF_STATUS_E_FAILURE;
40 }
41
42 psoc = wlan_pdev_get_psoc(pdev);
43 if (!psoc) {
44 mlme_err("PSOC is NULL");
45 return QDF_STATUS_E_FAILURE;
46 }
47
48 pdev_mlme = qdf_mem_malloc(sizeof(*pdev_mlme));
49 if (!pdev_mlme) {
50 mlme_err(" MLME component object alloc failed");
51 return QDF_STATUS_E_NOMEM;
52 }
53 wlan_minidump_log(pdev_mlme, sizeof(*pdev_mlme), psoc,
54 WLAN_MD_OBJMGR_PDEV_MLME, "pdev_mlme");
55 pdev_mlme->pdev = pdev;
56
57 if (mlme_pdev_ops_ext_hdl_create(pdev_mlme) != QDF_STATUS_SUCCESS)
58 goto init_failed;
59
60 wlan_objmgr_pdev_component_obj_attach(pdev, WLAN_UMAC_COMP_MLME,
61 (void *)pdev_mlme,
62 QDF_STATUS_SUCCESS);
63
64 return QDF_STATUS_SUCCESS;
65
66 init_failed:
67 wlan_minidump_remove(pdev_mlme, sizeof(*pdev_mlme), psoc,
68 WLAN_MD_OBJMGR_PDEV_MLME, "pdev_mlme");
69
70 qdf_mem_free(pdev_mlme);
71
72 return QDF_STATUS_E_FAILURE;
73 }
74
mlme_pdev_obj_destroy_handler(struct wlan_objmgr_pdev * pdev,void * arg)75 static QDF_STATUS mlme_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
76 void *arg)
77 {
78 struct pdev_mlme_obj *pdev_mlme;
79
80 pdev_mlme = wlan_pdev_mlme_get_cmpt_obj(pdev);
81 if (!pdev_mlme) {
82 mlme_info(" PDEV MLME component object is NULL");
83 return QDF_STATUS_SUCCESS;
84 }
85
86 mlme_pdev_ops_ext_hdl_destroy(pdev_mlme);
87 wlan_objmgr_pdev_component_obj_detach(pdev, WLAN_UMAC_COMP_MLME,
88 (void *)pdev_mlme);
89
90 wlan_minidump_remove(pdev_mlme, sizeof(*pdev_mlme),
91 wlan_pdev_get_psoc(pdev),
92 WLAN_MD_OBJMGR_PDEV_MLME, "pdev_mlme");
93
94 qdf_mem_free(pdev_mlme);
95
96 return QDF_STATUS_SUCCESS;
97 }
98
wlan_pdev_mlme_init(void)99 QDF_STATUS wlan_pdev_mlme_init(void)
100 {
101 if (wlan_objmgr_register_pdev_create_handler
102 (WLAN_UMAC_COMP_MLME,
103 mlme_pdev_obj_create_handler, NULL)
104 != QDF_STATUS_SUCCESS)
105 return QDF_STATUS_E_FAILURE;
106
107 if (wlan_objmgr_register_pdev_destroy_handler
108 (WLAN_UMAC_COMP_MLME,
109 mlme_pdev_obj_destroy_handler, NULL)
110 != QDF_STATUS_SUCCESS) {
111 if (wlan_objmgr_unregister_pdev_create_handler
112 (WLAN_UMAC_COMP_MLME,
113 mlme_pdev_obj_create_handler, NULL)
114 != QDF_STATUS_SUCCESS)
115 return QDF_STATUS_E_FAILURE;
116
117 return QDF_STATUS_E_FAILURE;
118 }
119
120 return QDF_STATUS_SUCCESS;
121 }
122
wlan_pdev_mlme_deinit(void)123 QDF_STATUS wlan_pdev_mlme_deinit(void)
124 {
125 if (wlan_objmgr_unregister_pdev_create_handler
126 (WLAN_UMAC_COMP_MLME,
127 mlme_pdev_obj_create_handler, NULL)
128 != QDF_STATUS_SUCCESS)
129 return QDF_STATUS_E_FAILURE;
130
131 if (wlan_objmgr_unregister_pdev_destroy_handler
132 (WLAN_UMAC_COMP_MLME,
133 mlme_pdev_obj_destroy_handler, NULL)
134 != QDF_STATUS_SUCCESS)
135 return QDF_STATUS_E_FAILURE;
136
137 return QDF_STATUS_SUCCESS;
138 }
139