1 /*
2  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: defines driver functions interfacing with linux kernel
20  */
21 #include <qdf_list.h>
22 #include <qdf_status.h>
23 #include <linux/wireless.h>
24 #include <linux/netdevice.h>
25 #include <wlan_cfg80211.h>
26 #include <wlan_osif_priv.h>
27 #include <osif_psoc_sync.h>
28 #include <qdf_mem.h>
29 #include <wlan_utility.h>
30 #include "wlan_hdd_main.h"
31 #include "cfg_ucfg_api.h"
32 #include <wlan_hdd_gpio.h>
33 
34 /**
35  * __wlan_hdd_cfg80211_set_gpio_config() - Set the gpio configuration
36  * @wiphy: pointer to wiphy
37  * @wdev: pointer to wireless_wdev
38  * @data: pointer to data
39  * @data_len: data length
40  *
41  * __wlan_hdd_cfg80211_set_gpio_config will forward the GPIO setting to FW by
42  * WMI_GPIO_CONFIG/OUTPUT_CMDID
43  *
44  * Return: 0 on success; errno on failure
45  */
46 static int
__wlan_hdd_cfg80211_set_gpio_config(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)47 __wlan_hdd_cfg80211_set_gpio_config(struct wiphy *wiphy,
48 				    struct wireless_dev *wdev,
49 				    const void *data,
50 				    int data_len)
51 {
52 	int ret;
53 	struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
54 	struct net_device *dev = wdev->netdev;
55 	struct hdd_adapter *adapter;
56 
57 	hdd_enter();
58 
59 	ret = wlan_hdd_validate_context(hdd_ctx);
60 	if (ret)
61 		return ret;
62 
63 	if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
64 		hdd_err("Command not allowed in FTM mode");
65 		return -EPERM;
66 	}
67 
68 	adapter = WLAN_HDD_GET_PRIV_PTR(dev);
69 	if (wlan_hdd_validate_vdev_id(adapter->deflink->vdev_id))
70 		return -EINVAL;
71 
72 	ret = wlan_cfg80211_start_gpio_config(wiphy,
73 					      hdd_ctx->psoc,
74 					      data, data_len);
75 	hdd_exit();
76 
77 	return ret;
78 }
79 
80 /**
81  * wlan_hdd_cfg80211_set_gpio_config() - Set GPIO Configuration
82  * @wiphy: wiphy structure pointer
83  * @wdev: Wireless device structure pointer
84  * @data: Pointer to the data received
85  * @data_len: Length of @data
86  *
87  * Return: 0 on success; errno on failure
88  */
wlan_hdd_cfg80211_set_gpio_config(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int data_len)89 int wlan_hdd_cfg80211_set_gpio_config(struct wiphy *wiphy,
90 				      struct wireless_dev *wdev,
91 				      const void *data, int data_len)
92 {
93 	struct osif_psoc_sync *psoc_sync;
94 	int errno;
95 
96 	errno = osif_psoc_sync_op_start(wiphy_dev(wiphy), &psoc_sync);
97 	if (errno)
98 		return errno;
99 
100 	errno = __wlan_hdd_cfg80211_set_gpio_config(wiphy,
101 						    wdev,
102 						    data,
103 						    data_len);
104 
105 	osif_psoc_sync_op_stop(psoc_sync);
106 
107 	return errno;
108 }
109