]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/libertas/ethtool.c
[PATCH] libertas: make debug configurable
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / libertas / ethtool.c
CommitLineData
876c9d3a
MT
1
2#include <linux/netdevice.h>
3#include <linux/ethtool.h>
4#include <linux/delay.h>
5
6#include "host.h"
7#include "sbi.h"
8#include "decl.h"
9#include "defs.h"
10#include "dev.h"
11#include "join.h"
12#include "wext.h"
13static const char * mesh_stat_strings[]= {
14 "drop_duplicate_bcast",
15 "drop_ttl_zero",
16 "drop_no_fwd_route",
17 "drop_no_buffers",
18 "fwded_unicast_cnt",
19 "fwded_bcast_cnt",
20 "drop_blind_table"
21};
22
23static void libertas_ethtool_get_drvinfo(struct net_device *dev,
24 struct ethtool_drvinfo *info)
25{
26 wlan_private *priv = (wlan_private *) dev->priv;
27 char fwver[32];
28
29 libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
30
31 strcpy(info->driver, "libertas");
32 strcpy(info->version, libertas_driver_version);
33 strcpy(info->fw_version, fwver);
34}
35
36/* All 8388 parts have 16KiB EEPROM size at the time of writing.
37 * In case that changes this needs fixing.
38 */
39#define LIBERTAS_EEPROM_LEN 16384
40
41static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
42{
43 return LIBERTAS_EEPROM_LEN;
44}
45
46static int libertas_ethtool_get_eeprom(struct net_device *dev,
47 struct ethtool_eeprom *eeprom, u8 * bytes)
48{
49 wlan_private *priv = (wlan_private *) dev->priv;
50 wlan_adapter *adapter = priv->adapter;
51 struct wlan_ioctl_regrdwr regctrl;
52 char *ptr;
53 int ret;
54
55 regctrl.action = 0;
56 regctrl.offset = eeprom->offset;
57 regctrl.NOB = eeprom->len;
58
59 if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
60 return -EINVAL;
61
62// mutex_lock(&priv->mutex);
63
64 adapter->prdeeprom =
65 (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
66 if (!adapter->prdeeprom)
67 return -ENOMEM;
68 memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
69
70 /* +14 is for action, offset, and NOB in
71 * response */
9012b28a 72 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
876c9d3a
MT
73 regctrl.action, regctrl.offset, regctrl.NOB);
74
75 ret = libertas_prepare_and_send_command(priv,
76 cmd_802_11_eeprom_access,
77 regctrl.action,
78 cmd_option_waitforrsp, 0,
79 &regctrl);
80
81 if (ret) {
82 if (adapter->prdeeprom)
83 kfree(adapter->prdeeprom);
9012b28a 84 goto done;
876c9d3a
MT
85 }
86
87 mdelay(10);
88
89 ptr = (char *)adapter->prdeeprom;
90
91 /* skip the command header, but include the "value" u32 variable */
92 ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
93
94 /*
95 * Return the result back to the user
96 */
97 memcpy(bytes, ptr, eeprom->len);
98
99 if (adapter->prdeeprom)
100 kfree(adapter->prdeeprom);
101// mutex_unlock(&priv->mutex);
102
9012b28a
HS
103 ret = 0;
104
105done:
106 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
107 return ret;
876c9d3a
MT
108}
109
110static void libertas_ethtool_get_stats(struct net_device * dev,
111 struct ethtool_stats * stats, u64 * data)
112{
113 wlan_private *priv = dev->priv;
114
9012b28a 115 lbs_deb_enter(LBS_DEB_ETHTOOL);
876c9d3a
MT
116
117 stats->cmd = ETHTOOL_GSTATS;
118 BUG_ON(stats->n_stats != MESH_STATS_NUM);
119
120 data[0] = priv->mstats.fwd_drop_rbt;
121 data[1] = priv->mstats.fwd_drop_ttl;
122 data[2] = priv->mstats.fwd_drop_noroute;
123 data[3] = priv->mstats.fwd_drop_nobuf;
124 data[4] = priv->mstats.fwd_unicast_cnt;
125 data[5] = priv->mstats.fwd_bcast_cnt;
126 data[6] = priv->mstats.drop_blind;
127
9012b28a 128 lbs_deb_enter(LBS_DEB_ETHTOOL);
876c9d3a
MT
129}
130
131static int libertas_ethtool_get_stats_count(struct net_device * dev)
132{
133 int ret;
134 wlan_private *priv = dev->priv;
135 struct cmd_ds_mesh_access mesh_access;
136
9012b28a
HS
137 lbs_deb_enter(LBS_DEB_ETHTOOL);
138
876c9d3a
MT
139 /* Get Mesh Statistics */
140 ret = libertas_prepare_and_send_command(priv,
141 cmd_mesh_access, cmd_act_mesh_get_stats,
142 cmd_option_waitforrsp, 0, &mesh_access);
143
144 if (ret) {
9012b28a
HS
145 ret = 0;
146 goto done;
876c9d3a
MT
147 }
148
149 priv->mstats.fwd_drop_rbt = mesh_access.data[0];
150 priv->mstats.fwd_drop_ttl = mesh_access.data[1];
151 priv->mstats.fwd_drop_noroute = mesh_access.data[2];
152 priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
153 priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
154 priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
155 priv->mstats.drop_blind = mesh_access.data[6];
156
9012b28a
HS
157 ret = MESH_STATS_NUM;
158
159done:
160 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
161 return ret;
876c9d3a
MT
162}
163
164static void libertas_ethtool_get_strings (struct net_device * dev,
165 u32 stringset,
166 u8 * s)
167{
168 int i;
169
9012b28a
HS
170 lbs_deb_enter(LBS_DEB_ETHTOOL);
171
876c9d3a
MT
172 switch (stringset) {
173 case ETH_SS_STATS:
174 for (i=0; i < MESH_STATS_NUM; i++) {
175 memcpy(s + i * ETH_GSTRING_LEN,
176 mesh_stat_strings[i],
177 ETH_GSTRING_LEN);
178 }
179 break;
180 }
9012b28a 181 lbs_deb_enter(LBS_DEB_ETHTOOL);
876c9d3a
MT
182}
183
184struct ethtool_ops libertas_ethtool_ops = {
185 .get_drvinfo = libertas_ethtool_get_drvinfo,
186 .get_eeprom = libertas_ethtool_get_eeprom,
187 .get_eeprom_len = libertas_ethtool_get_eeprom_len,
188 .get_stats_count = libertas_ethtool_get_stats_count,
189 .get_ethtool_stats = libertas_ethtool_get_stats,
190 .get_strings = libertas_ethtool_get_strings,
191};
192