1 /*
2 * Copyright (c) 2018-2020 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: Implement various api / helper function which shall be used for
20 * DISA user and target interface.
21 */
22
23 #include "wlan_disa_main.h"
24 #include "wlan_disa_obj_mgmt_public_struct.h"
25 #include "wlan_disa_tgt_api.h"
26
27 static struct wlan_disa_ctx *gp_disa_ctx;
28
disa_allocate_ctx(void)29 QDF_STATUS disa_allocate_ctx(void)
30 {
31 /* If it is already created, ignore */
32 if (gp_disa_ctx) {
33 disa_debug("already allocated disa_ctx");
34 return QDF_STATUS_SUCCESS;
35 }
36
37 /* allocate DISA ctx */
38 gp_disa_ctx = qdf_mem_malloc(sizeof(*gp_disa_ctx));
39 if (!gp_disa_ctx)
40 return QDF_STATUS_E_NOMEM;
41
42 qdf_spinlock_create(&gp_disa_ctx->lock);
43
44 return QDF_STATUS_SUCCESS;
45 }
46
disa_free_ctx(void)47 void disa_free_ctx(void)
48 {
49 if (!gp_disa_ctx) {
50 disa_err("disa ctx is already freed");
51 QDF_ASSERT(0);
52 return;
53 }
54 qdf_spinlock_destroy(&gp_disa_ctx->lock);
55 qdf_mem_free(gp_disa_ctx);
56 gp_disa_ctx = NULL;
57 }
58
disa_get_context(void)59 struct wlan_disa_ctx *disa_get_context(void)
60 {
61 return gp_disa_ctx;
62 }
63
disa_core_encrypt_decrypt_req(struct wlan_objmgr_psoc * psoc,struct disa_encrypt_decrypt_req_params * req,encrypt_decrypt_resp_callback cb,void * cookie)64 QDF_STATUS disa_core_encrypt_decrypt_req(struct wlan_objmgr_psoc *psoc,
65 struct disa_encrypt_decrypt_req_params *req,
66 encrypt_decrypt_resp_callback cb,
67 void *cookie)
68 {
69 struct wlan_disa_ctx *disa_ctx;
70 QDF_STATUS status = QDF_STATUS_SUCCESS;
71
72 DISA_ENTER();
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 if (!disa_ctx->request_active) {
81 disa_ctx->callback = cb;
82 disa_ctx->callback_context = cookie;
83 disa_ctx->request_active = true;
84 } else {
85 status = QDF_STATUS_E_INVAL;
86 }
87 qdf_spin_unlock_bh(&disa_ctx->lock);
88
89 if (status != QDF_STATUS_SUCCESS) {
90 disa_err("A request is already active!");
91 return status;
92 }
93
94 status = disa_psoc_get_ref(psoc);
95 if (status != QDF_STATUS_SUCCESS) {
96 disa_err("DISA cannot get the reference out of psoc");
97 return status;
98 }
99
100 status = tgt_disa_encrypt_decrypt_req(psoc, req);
101 disa_psoc_put_ref(psoc);
102
103 DISA_EXIT();
104 return status;
105 }
106