-
Notifications
You must be signed in to change notification settings - Fork 13
/
aq_drvinfo.c
123 lines (98 loc) · 2.96 KB
/
aq_drvinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* aQuantia Corporation Network Driver
* Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*/
/* File aq_drvinfo.c: Definition of common code for firmware info in sys.*/
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/stat.h>
#include <linux/string.h>
#ifndef __VMKLNX__
#include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h>
#include <linux/uaccess.h>
#endif
#include "aq_drvinfo.h"
#ifndef __VMKLNX__
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
static ssize_t temperature_show(struct device *ndev,
struct device_attribute *attr, char *buf)
{
int err;
struct aq_nic_s *aq_nic = pci_get_drvdata(to_pci_dev(ndev));
int temp = 0;
if (!aq_nic->aq_fw_ops->get_temp)
return -ENXIO;
mutex_lock(&aq_nic->fwreq_mutex);
err = aq_nic->aq_fw_ops->get_temp(aq_nic->aq_hw, &temp);
mutex_unlock(&aq_nic->fwreq_mutex);
if (err == 0)
return sprintf(buf, "%d\n", temp * 10);
return -ENXIO;
}
static ssize_t cable_show(struct device *ndev,
struct device_attribute *attr, char *buf)
{
int err;
struct aq_nic_s *aq_nic = pci_get_drvdata(to_pci_dev(ndev));
int cable_len = 0;
if (!aq_nic->aq_fw_ops->get_cable_len)
return -ENXIO;
mutex_lock(&aq_nic->fwreq_mutex);
err = aq_nic->aq_fw_ops->get_cable_len(aq_nic->aq_hw, &cable_len);
mutex_unlock(&aq_nic->fwreq_mutex);
if (err == 0)
return sprintf(buf, "%d\n", cable_len);
return -ENXIO;
}
static ssize_t cable_label_show(struct device *ndev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "Estimated cable length (meters)\n");
}
static ssize_t temperature_label_show(struct device *ndev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "PHY temperature\n");
}
static DEVICE_ATTR(temp1_label, S_IWUSR | S_IRUGO, temperature_label_show,
NULL);
static SENSOR_DEVICE_ATTR(temp1_input, S_IWUSR | S_IRUGO, temperature_show,
NULL, 0);
static DEVICE_ATTR(cable_label, S_IWUSR | S_IRUGO, cable_label_show, NULL);
static SENSOR_DEVICE_ATTR(cable_input, S_IWUSR | S_IRUGO, cable_show, NULL, 1);
static struct attribute *aq_dev_attrs[] = {
&dev_attr_temp1_label.attr,
&sensor_dev_attr_temp1_input.dev_attr.attr,
&dev_attr_cable_label.attr,
&sensor_dev_attr_cable_input.dev_attr.attr,
NULL
};
ATTRIBUTE_GROUPS(aq_dev);
#endif
#endif
int aq_drvinfo_init(struct net_device *ndev)
{
int err = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
struct device *dev;
struct aq_nic_s *aq_nic = netdev_priv(ndev);
struct pci_dev *pdev = aq_nic->pdev;
dev =
devm_hwmon_device_register_with_groups(&pdev->dev,
ndev->name,
dev_get_drvdata(&pdev->dev),
aq_dev_groups);
if (IS_ERR(dev))
err = PTR_ERR(dev);
#endif
return err;
}
void aq_drvinfo_exit(struct net_device *ndev)
{
}