xref: /linux/net/wireless/ethtool.c (revision 0d456bad36d42d16022be045c8a53ddbb59ee478)
1 #include <linux/utsname.h>
2 #include <net/cfg80211.h>
3 #include "core.h"
4 #include "ethtool.h"
5 #include "rdev-ops.h"
6 
7 static void cfg80211_get_drvinfo(struct net_device *dev,
8 					struct ethtool_drvinfo *info)
9 {
10 	struct wireless_dev *wdev = dev->ieee80211_ptr;
11 
12 	strlcpy(info->driver, wiphy_dev(wdev->wiphy)->driver->name,
13 		sizeof(info->driver));
14 
15 	strlcpy(info->version, init_utsname()->release, sizeof(info->version));
16 
17 	if (wdev->wiphy->fw_version[0])
18 		strncpy(info->fw_version, wdev->wiphy->fw_version,
19 			sizeof(info->fw_version));
20 	else
21 		strncpy(info->fw_version, "N/A", sizeof(info->fw_version));
22 
23 	strlcpy(info->bus_info, dev_name(wiphy_dev(wdev->wiphy)),
24 		sizeof(info->bus_info));
25 }
26 
27 static int cfg80211_get_regs_len(struct net_device *dev)
28 {
29 	/* For now, return 0... */
30 	return 0;
31 }
32 
33 static void cfg80211_get_regs(struct net_device *dev, struct ethtool_regs *regs,
34 			void *data)
35 {
36 	struct wireless_dev *wdev = dev->ieee80211_ptr;
37 
38 	regs->version = wdev->wiphy->hw_version;
39 	regs->len = 0;
40 }
41 
42 static void cfg80211_get_ringparam(struct net_device *dev,
43 				   struct ethtool_ringparam *rp)
44 {
45 	struct wireless_dev *wdev = dev->ieee80211_ptr;
46 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
47 
48 	memset(rp, 0, sizeof(*rp));
49 
50 	if (rdev->ops->get_ringparam)
51 		rdev_get_ringparam(rdev, &rp->tx_pending, &rp->tx_max_pending,
52 				   &rp->rx_pending, &rp->rx_max_pending);
53 }
54 
55 static int cfg80211_set_ringparam(struct net_device *dev,
56 				  struct ethtool_ringparam *rp)
57 {
58 	struct wireless_dev *wdev = dev->ieee80211_ptr;
59 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
60 
61 	if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
62 		return -EINVAL;
63 
64 	if (rdev->ops->set_ringparam)
65 		return rdev_set_ringparam(rdev, rp->tx_pending, rp->rx_pending);
66 
67 	return -ENOTSUPP;
68 }
69 
70 static int cfg80211_get_sset_count(struct net_device *dev, int sset)
71 {
72 	struct wireless_dev *wdev = dev->ieee80211_ptr;
73 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
74 	if (rdev->ops->get_et_sset_count)
75 		return rdev_get_et_sset_count(rdev, dev, sset);
76 	return -EOPNOTSUPP;
77 }
78 
79 static void cfg80211_get_stats(struct net_device *dev,
80 			       struct ethtool_stats *stats, u64 *data)
81 {
82 	struct wireless_dev *wdev = dev->ieee80211_ptr;
83 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
84 	if (rdev->ops->get_et_stats)
85 		rdev_get_et_stats(rdev, dev, stats, data);
86 }
87 
88 static void cfg80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
89 {
90 	struct wireless_dev *wdev = dev->ieee80211_ptr;
91 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
92 	if (rdev->ops->get_et_strings)
93 		rdev_get_et_strings(rdev, dev, sset, data);
94 }
95 
96 const struct ethtool_ops cfg80211_ethtool_ops = {
97 	.get_drvinfo = cfg80211_get_drvinfo,
98 	.get_regs_len = cfg80211_get_regs_len,
99 	.get_regs = cfg80211_get_regs,
100 	.get_link = ethtool_op_get_link,
101 	.get_ringparam = cfg80211_get_ringparam,
102 	.set_ringparam = cfg80211_set_ringparam,
103 	.get_strings = cfg80211_get_strings,
104 	.get_ethtool_stats = cfg80211_get_stats,
105 	.get_sset_count = cfg80211_get_sset_count,
106 };
107