xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_tx_stbc.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 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: wlan_hdd_sysfs_tx_stbc.c
20  *
21  * implementation for creating sysfs file tx_stbc
22  */
23 
24 #include <wlan_hdd_includes.h>
25 #include <wlan_hdd_sysfs.h>
26 #include "osif_vdev_sync.h"
27 #include "sme_api.h"
28 #include <wlan_hdd_sysfs_tx_stbc.h>
29 
hdd_sysfs_get_tx_stbc(struct hdd_adapter * adapter,int * value)30 static int hdd_sysfs_get_tx_stbc(struct hdd_adapter *adapter, int *value)
31 {
32 	mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
33 	int ret;
34 
35 	hdd_enter();
36 	ret = sme_get_ht_config(mac_handle, adapter->deflink->vdev_id,
37 				WNI_CFG_HT_CAP_INFO_TX_STBC);
38 	if (ret < 0) {
39 		hdd_err("Failed to get TX STBC value");
40 	} else {
41 		*value = ret;
42 		ret = 0;
43 	}
44 
45 	return ret;
46 }
47 
48 static ssize_t
__hdd_sysfs_tx_stbc_show(struct net_device * net_dev,char * buf)49 __hdd_sysfs_tx_stbc_show(struct net_device *net_dev, char *buf)
50 {
51 	struct hdd_adapter *adapter = netdev_priv(net_dev);
52 	struct hdd_context *hdd_ctx;
53 	int ret;
54 	int value;
55 
56 	if (hdd_validate_adapter(adapter))
57 		return -EINVAL;
58 
59 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
60 	ret = wlan_hdd_validate_context(hdd_ctx);
61 	if (ret)
62 		return ret;
63 
64 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
65 		return -EINVAL;
66 
67 	ret = hdd_sysfs_get_tx_stbc(adapter, &value);
68 	if (ret) {
69 		hdd_err_rl("Get_TX_STBC failed %d", ret);
70 		return ret;
71 	}
72 
73 	return scnprintf(buf, PAGE_SIZE, "%d\n", value);
74 }
75 
76 static ssize_t
hdd_sysfs_tx_stbc_show(struct device * dev,struct device_attribute * attr,char * buf)77 hdd_sysfs_tx_stbc_show(struct device *dev,
78 		       struct device_attribute *attr,
79 		       char *buf)
80 {
81 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
82 	struct osif_vdev_sync *vdev_sync;
83 	ssize_t err_size;
84 
85 	err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
86 	if (err_size)
87 		return err_size;
88 
89 	err_size = __hdd_sysfs_tx_stbc_show(net_dev, buf);
90 
91 	osif_vdev_sync_op_stop(vdev_sync);
92 
93 	return err_size;
94 }
95 
96 static DEVICE_ATTR(tx_stbc, 0440,
97 		   hdd_sysfs_tx_stbc_show, NULL);
98 
hdd_sysfs_tx_stbc_create(struct hdd_adapter * adapter)99 int hdd_sysfs_tx_stbc_create(struct hdd_adapter *adapter)
100 {
101 	int error;
102 
103 	error = device_create_file(&adapter->dev->dev,
104 				   &dev_attr_tx_stbc);
105 	if (error)
106 		hdd_err("could not create tx_stbc sysfs file");
107 
108 	return error;
109 }
110 
hdd_sysfs_tx_stbc_destroy(struct hdd_adapter * adapter)111 void hdd_sysfs_tx_stbc_destroy(struct hdd_adapter *adapter)
112 {
113 	device_remove_file(&adapter->dev->dev, &dev_attr_tx_stbc);
114 }
115