blob: d793d843f7d5a95476a08662571cfa3666d95d18 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001#include <linux/netdevice.h>
2#include <linux/ethtool.h>
3#include <linux/delay.h>
4
5#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include "decl.h"
7#include "defs.h"
8#include "dev.h"
9#include "join.h"
10#include "wext.h"
11static const char * mesh_stat_strings[]= {
12 "drop_duplicate_bcast",
13 "drop_ttl_zero",
14 "drop_no_fwd_route",
15 "drop_no_buffers",
16 "fwded_unicast_cnt",
17 "fwded_bcast_cnt",
Javier Cardona0601e7e2007-05-25 12:12:06 -040018 "drop_blind_table",
19 "tx_failed_cnt"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020};
21
22static void libertas_ethtool_get_drvinfo(struct net_device *dev,
23 struct ethtool_drvinfo *info)
24{
25 wlan_private *priv = (wlan_private *) dev->priv;
26 char fwver[32];
27
28 libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
29
30 strcpy(info->driver, "libertas");
31 strcpy(info->version, libertas_driver_version);
32 strcpy(info->fw_version, fwver);
33}
34
35/* All 8388 parts have 16KiB EEPROM size at the time of writing.
36 * In case that changes this needs fixing.
37 */
38#define LIBERTAS_EEPROM_LEN 16384
39
40static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
41{
42 return LIBERTAS_EEPROM_LEN;
43}
44
45static int libertas_ethtool_get_eeprom(struct net_device *dev,
46 struct ethtool_eeprom *eeprom, u8 * bytes)
47{
48 wlan_private *priv = (wlan_private *) dev->priv;
49 wlan_adapter *adapter = priv->adapter;
50 struct wlan_ioctl_regrdwr regctrl;
51 char *ptr;
52 int ret;
53
54 regctrl.action = 0;
55 regctrl.offset = eeprom->offset;
56 regctrl.NOB = eeprom->len;
57
58 if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
59 return -EINVAL;
60
61// mutex_lock(&priv->mutex);
62
Jesper Juhl655b4d12007-08-24 11:48:16 -040063 adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 if (!adapter->prdeeprom)
65 return -ENOMEM;
66 memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
67
68 /* +14 is for action, offset, and NOB in
69 * response */
Holger Schurig9012b282007-05-25 11:27:16 -040070 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071 regctrl.action, regctrl.offset, regctrl.NOB);
72
73 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -040074 CMD_802_11_EEPROM_ACCESS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 regctrl.action,
Dan Williams0aef64d2007-08-02 11:31:18 -040076 CMD_OPTION_WAITFORRSP, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077 &regctrl);
78
79 if (ret) {
80 if (adapter->prdeeprom)
81 kfree(adapter->prdeeprom);
Holger Schurig9012b282007-05-25 11:27:16 -040082 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083 }
84
85 mdelay(10);
86
87 ptr = (char *)adapter->prdeeprom;
88
89 /* skip the command header, but include the "value" u32 variable */
90 ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
91
92 /*
93 * Return the result back to the user
94 */
95 memcpy(bytes, ptr, eeprom->len);
96
97 if (adapter->prdeeprom)
98 kfree(adapter->prdeeprom);
99// mutex_unlock(&priv->mutex);
100
Holger Schurig9012b282007-05-25 11:27:16 -0400101 ret = 0;
102
103done:
104 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
105 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106}
107
108static void libertas_ethtool_get_stats(struct net_device * dev,
109 struct ethtool_stats * stats, u64 * data)
110{
111 wlan_private *priv = dev->priv;
112
Holger Schurig9012b282007-05-25 11:27:16 -0400113 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114
115 stats->cmd = ETHTOOL_GSTATS;
116 BUG_ON(stats->n_stats != MESH_STATS_NUM);
117
118 data[0] = priv->mstats.fwd_drop_rbt;
119 data[1] = priv->mstats.fwd_drop_ttl;
120 data[2] = priv->mstats.fwd_drop_noroute;
121 data[3] = priv->mstats.fwd_drop_nobuf;
122 data[4] = priv->mstats.fwd_unicast_cnt;
123 data[5] = priv->mstats.fwd_bcast_cnt;
124 data[6] = priv->mstats.drop_blind;
Javier Cardona0601e7e2007-05-25 12:12:06 -0400125 data[7] = priv->mstats.tx_failed_cnt;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126
Holger Schurig9012b282007-05-25 11:27:16 -0400127 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200128}
129
130static int libertas_ethtool_get_stats_count(struct net_device * dev)
131{
132 int ret;
133 wlan_private *priv = dev->priv;
134 struct cmd_ds_mesh_access mesh_access;
135
Holger Schurig9012b282007-05-25 11:27:16 -0400136 lbs_deb_enter(LBS_DEB_ETHTOOL);
137
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 /* Get Mesh Statistics */
139 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400140 CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
141 CMD_OPTION_WAITFORRSP, 0, &mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142
143 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400144 ret = 0;
145 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146 }
147
David Woodhouse981f1872007-05-25 23:36:54 -0400148 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
149 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
150 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
151 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
152 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
153 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
154 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
155 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156
Holger Schurig9012b282007-05-25 11:27:16 -0400157 ret = MESH_STATS_NUM;
158
159done:
160 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
161 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162}
163
164static void libertas_ethtool_get_strings (struct net_device * dev,
165 u32 stringset,
166 u8 * s)
167{
168 int i;
169
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_enter(LBS_DEB_ETHTOOL);
171
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172 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 }
Holger Schurig9012b282007-05-25 11:27:16 -0400181 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182}
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