xref: /wlan-driver/qcacld-3.0/components/disa/dispatcher/src/wlan_disa_tgt_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2018 The Linux Foundation. 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  * DOC: Implements public API for disa to interact with target/WMI
20  */
21 
22 #include "wlan_disa_tgt_api.h"
23 #include "wlan_disa_main.h"
24 #include "wlan_disa_public_struct.h"
25 
26 /**
27  * tgt_disa_encrypt_decrypt_req() - send encrypt/decrypt request to target if
28  * @psoc: objmgr psoc object
29  * @req: encrypt/decrypt parameters
30  *
31  * Return: QDF_STATUS
32  */
tgt_disa_encrypt_decrypt_req(struct wlan_objmgr_psoc * psoc,struct disa_encrypt_decrypt_req_params * req)33 QDF_STATUS tgt_disa_encrypt_decrypt_req(struct wlan_objmgr_psoc *psoc,
34 		struct disa_encrypt_decrypt_req_params *req)
35 {
36 	struct wlan_disa_tx_ops *disa_tx_ops;
37 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
38 
39 	DISA_ENTER();
40 
41 	disa_tx_ops = GET_DISA_TX_OPS_FROM_PSOC(psoc);
42 	QDF_ASSERT(disa_tx_ops->disa_encrypt_decrypt_req);
43 
44 	if (disa_tx_ops->disa_encrypt_decrypt_req)
45 		status = disa_tx_ops->disa_encrypt_decrypt_req(psoc, req);
46 
47 	DISA_EXIT();
48 	return status;
49 }
50 
51 /**
52  * tgt_disa_encrypt_decrypt_resp() - receive encrypt/decrypt response
53  *	from target if
54  * @psoc: objmgr psoc object
55  * @resp: encrypt/decrypt response containing results
56  *
57  * Return: QDF_STATUS
58  */
tgt_disa_encrypt_decrypt_resp(struct wlan_objmgr_psoc * psoc,struct disa_encrypt_decrypt_resp_params * resp)59 QDF_STATUS tgt_disa_encrypt_decrypt_resp(struct wlan_objmgr_psoc *psoc,
60 		struct disa_encrypt_decrypt_resp_params *resp)
61 {
62 	struct wlan_disa_ctx *disa_ctx;
63 	encrypt_decrypt_resp_callback cb;
64 	void *cookie;
65 
66 	DISA_ENTER();
67 
68 	if (!resp) {
69 		disa_err("encrypt/decrypt resp is null");
70 		return QDF_STATUS_E_NULL_VALUE;
71 	}
72 
73 	disa_ctx = disa_get_context();
74 	if (!disa_ctx) {
75 		disa_err("DISA context is NULL!");
76 		return QDF_STATUS_E_INVAL;
77 	}
78 
79 	qdf_spin_lock_bh(&disa_ctx->lock);
80 	cb = disa_ctx->callback;
81 	disa_ctx->callback = NULL;
82 	cookie = disa_ctx->callback_context;
83 	disa_ctx->callback_context = NULL;
84 	disa_ctx->request_active = false;
85 	qdf_spin_unlock_bh(&disa_ctx->lock);
86 
87 	if (cb)
88 		cb(cookie, resp);
89 
90 	DISA_EXIT();
91 	return QDF_STATUS_SUCCESS;
92 }
93 
94 /**
95  * tgt_disa_register_ev_handlers() - API to register disa event handlers
96  * @psoc: objmgr psoc object
97  *
98  * Return: QDF_STATUS_SUCCESS in case of success else return error
99  */
tgt_disa_register_ev_handlers(struct wlan_objmgr_psoc * psoc)100 QDF_STATUS tgt_disa_register_ev_handlers(struct wlan_objmgr_psoc *psoc)
101 {
102 	struct wlan_disa_tx_ops *disa_tx_ops;
103 
104 	disa_tx_ops = GET_DISA_TX_OPS_FROM_PSOC(psoc);
105 
106 	QDF_ASSERT(disa_tx_ops->disa_register_ev_handlers);
107 
108 	if (disa_tx_ops->disa_register_ev_handlers)
109 		return disa_tx_ops->disa_register_ev_handlers(psoc);
110 
111 	return QDF_STATUS_SUCCESS;
112 }
113 
114 /**
115  * tgt_disa_unregister_ev_handlers() - API to unregister disa event handlers
116  * @psoc: objmgr psoc object
117  *
118  * Return: QDF_STATUS_SUCCESS in case of success else return error
119  */
tgt_disa_unregister_ev_handlers(struct wlan_objmgr_psoc * psoc)120 QDF_STATUS tgt_disa_unregister_ev_handlers(struct wlan_objmgr_psoc *psoc)
121 {
122 	struct wlan_disa_tx_ops *disa_tx_ops;
123 
124 	disa_tx_ops = GET_DISA_TX_OPS_FROM_PSOC(psoc);
125 
126 	QDF_ASSERT(disa_tx_ops->disa_unregister_ev_handlers);
127 
128 	if (disa_tx_ops->disa_unregister_ev_handlers)
129 		return disa_tx_ops->disa_unregister_ev_handlers(psoc);
130 
131 	return QDF_STATUS_SUCCESS;
132 }
133 
134