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_hdd_afc.c
19 *
20 * This file has the AFC osif interface with linux kernel.
21 */
22
23 #include <wlan_hdd_afc.h>
24 #include <osif_psoc_sync.h>
25 #include <wlan_cfg80211_afc.h>
26 #include <wlan_hdd_main.h>
27 #include <pld_common.h>
28 #include <wlan_afc_ucfg_api.h>
29
wlan_hdd_vendor_afc_response(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)30 int wlan_hdd_vendor_afc_response(struct wiphy *wiphy,
31 struct wireless_dev *wdev,
32 const void *data,
33 int data_len)
34 {
35 struct osif_psoc_sync *psoc_sync;
36 struct hdd_context *hdd_ctx;
37 int ret;
38
39 hdd_enter();
40
41 ret = osif_psoc_sync_op_start(wiphy_dev(wiphy), &psoc_sync);
42 if (ret)
43 return ret;
44
45 hdd_ctx = wiphy_priv(wiphy);
46
47 if (!hdd_ctx->psoc) {
48 osif_err("psoc is null");
49 ret = -EINVAL;
50 goto sync_stop;
51 }
52
53 if (!hdd_ctx->pdev) {
54 osif_err("pdev is null");
55 ret = -EINVAL;
56 goto sync_stop;
57 }
58
59 ret = wlan_cfg80211_vendor_afc_response(hdd_ctx->psoc,
60 hdd_ctx->pdev,
61 data,
62 data_len);
63 sync_stop:
64 osif_psoc_sync_op_stop(psoc_sync);
65
66 hdd_exit();
67
68 return ret;
69 }
70
71 /**
72 * wlan_hdd_send_response_to_afcmem() - Callback function register to AFC
73 * common component.
74 * @psoc: Pointer to PSOC object
75 * @pdev: Pointer to PDEV object
76 * @data: Pointer to AFC response data pass to target
77 * @len: Length of AFC response data pass to target
78 *
79 * Return: 0 if success, otherwise error code
80 */
wlan_hdd_send_response_to_afcmem(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_pdev * pdev,struct wlan_afc_host_resp * data,uint32_t len)81 static int wlan_hdd_send_response_to_afcmem(struct wlan_objmgr_psoc *psoc,
82 struct wlan_objmgr_pdev *pdev,
83 struct wlan_afc_host_resp *data,
84 uint32_t len)
85 {
86 qdf_device_t qdf_dev;
87 int pdev_id;
88 const uint8_t *afcdb = (const uint8_t *)data;
89
90 qdf_dev = wlan_psoc_get_qdf_dev(psoc);
91 if (!qdf_dev) {
92 osif_err("Invalid qdf dev");
93 return -EINVAL;
94 }
95
96 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
97
98 return pld_send_buffer_to_afcmem(qdf_dev->dev,
99 afcdb,
100 len,
101 pdev_id);
102 }
103
wlan_hdd_register_afc_pld_cb(struct wlan_objmgr_psoc * psoc)104 void wlan_hdd_register_afc_pld_cb(struct wlan_objmgr_psoc *psoc)
105 {
106 ucfg_afc_register_data_send_cb(psoc, wlan_hdd_send_response_to_afcmem);
107 }
108