1  /*
2   * Copyright (c) 2011-2020 The Linux Foundation. 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_sysfs_temperature.c
19   *
20   * Implementation for creating sysfs file temperature
21   */
22  
23  #include <wlan_hdd_includes.h>
24  #include <wlan_hdd_sysfs.h>
25  #include "osif_vdev_sync.h"
26  #include <wlan_hdd_sysfs_temperature.h>
27  #include <wlan_hdd_stats.h>
28  
29  static ssize_t
__hdd_sysfs_temperature_show(struct net_device * net_dev,char * buf)30  __hdd_sysfs_temperature_show(struct net_device *net_dev, char *buf)
31  {
32  	struct hdd_adapter *adapter = netdev_priv(net_dev);
33  	struct hdd_context *hdd_ctx;
34  	int value;
35  	int ret;
36  
37  	if (hdd_validate_adapter(adapter))
38  		return -EINVAL;
39  
40  	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
41  	ret = wlan_hdd_validate_context(hdd_ctx);
42  	if (ret)
43  		return ret;
44  
45  	if (!wlan_hdd_validate_modules_state(hdd_ctx))
46  		return -EINVAL;
47  
48  	hdd_debug("SYSFS_GET_TEMPERATURE");
49  	ret = wlan_hdd_get_temperature(adapter, &value);
50  
51  	if (ret) {
52  		hdd_err_rl("GET_TEMP failed: %d", ret);
53  		return ret;
54  	}
55  
56  	return scnprintf(buf, PAGE_SIZE, "%d\n", value);
57  }
58  
59  static ssize_t
hdd_sysfs_temperature_show(struct device * dev,struct device_attribute * attr,char * buf)60  hdd_sysfs_temperature_show(struct device *dev,
61  			   struct device_attribute *attr,
62  			   char *buf)
63  {
64  	struct net_device *net_dev = container_of(dev, struct net_device, dev);
65  	struct osif_vdev_sync *vdev_sync;
66  	ssize_t err_size;
67  
68  	err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
69  	if (err_size)
70  		return err_size;
71  
72  	err_size = __hdd_sysfs_temperature_show(net_dev, buf);
73  
74  	osif_vdev_sync_op_stop(vdev_sync);
75  
76  	return err_size;
77  }
78  
79  static DEVICE_ATTR(temperature, 0440,
80  		   hdd_sysfs_temperature_show, NULL);
81  
hdd_sysfs_temperature_create(struct hdd_adapter * adapter)82  int hdd_sysfs_temperature_create(struct hdd_adapter *adapter)
83  {
84  	int error;
85  
86  	error = device_create_file(&adapter->dev->dev,
87  				   &dev_attr_temperature);
88  	if (error)
89  		hdd_err("could not create temperature sysfs file");
90  
91  	return error;
92  }
93  
hdd_sysfs_temperature_destroy(struct hdd_adapter * adapter)94  void hdd_sysfs_temperature_destroy(struct hdd_adapter *adapter)
95  {
96  	device_remove_file(&adapter->dev->dev, &dev_attr_temperature);
97  }
98