blob: c3a26fce02ca00c2670cab8bafd44defd4616fc2 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001
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",
Javier Cardona0601e7e2007-05-25 12:12:06 -040020 "drop_blind_table",
21 "tx_failed_cnt"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022};
23
24static void libertas_ethtool_get_drvinfo(struct net_device *dev,
25 struct ethtool_drvinfo *info)
26{
27 wlan_private *priv = (wlan_private *) dev->priv;
28 char fwver[32];
29
30 libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
31
32 strcpy(info->driver, "libertas");
33 strcpy(info->version, libertas_driver_version);
34 strcpy(info->fw_version, fwver);
35}
36
37/* All 8388 parts have 16KiB EEPROM size at the time of writing.
38 * In case that changes this needs fixing.
39 */
40#define LIBERTAS_EEPROM_LEN 16384
41
42static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
43{
44 return LIBERTAS_EEPROM_LEN;
45}
46
47static int libertas_ethtool_get_eeprom(struct net_device *dev,
48 struct ethtool_eeprom *eeprom, u8 * bytes)
49{
50 wlan_private *priv = (wlan_private *) dev->priv;
51 wlan_adapter *adapter = priv->adapter;
52 struct wlan_ioctl_regrdwr regctrl;
53 char *ptr;
54 int ret;
55
56 regctrl.action = 0;
57 regctrl.offset = eeprom->offset;
58 regctrl.NOB = eeprom->len;
59
60 if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
61 return -EINVAL;
62
63// mutex_lock(&priv->mutex);
64
65 adapter->prdeeprom =
66 (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
67 if (!adapter->prdeeprom)
68 return -ENOMEM;
69 memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
70
71 /* +14 is for action, offset, and NOB in
72 * response */
Holger Schurig9012b282007-05-25 11:27:16 -040073 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 regctrl.action, regctrl.offset, regctrl.NOB);
75
76 ret = libertas_prepare_and_send_command(priv,
77 cmd_802_11_eeprom_access,
78 regctrl.action,
79 cmd_option_waitforrsp, 0,
80 &regctrl);
81
82 if (ret) {
83 if (adapter->prdeeprom)
84 kfree(adapter->prdeeprom);
Holger Schurig9012b282007-05-25 11:27:16 -040085 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086 }
87
88 mdelay(10);
89
90 ptr = (char *)adapter->prdeeprom;
91
92 /* skip the command header, but include the "value" u32 variable */
93 ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
94
95 /*
96 * Return the result back to the user
97 */
98 memcpy(bytes, ptr, eeprom->len);
99
100 if (adapter->prdeeprom)
101 kfree(adapter->prdeeprom);
102// mutex_unlock(&priv->mutex);
103
Holger Schurig9012b282007-05-25 11:27:16 -0400104 ret = 0;
105
106done:
107 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
108 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200109}
110
111static void libertas_ethtool_get_stats(struct net_device * dev,
112 struct ethtool_stats * stats, u64 * data)
113{
114 wlan_private *priv = dev->priv;
115
Holger Schurig9012b282007-05-25 11:27:16 -0400116 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117
118 stats->cmd = ETHTOOL_GSTATS;
119 BUG_ON(stats->n_stats != MESH_STATS_NUM);
120
121 data[0] = priv->mstats.fwd_drop_rbt;
122 data[1] = priv->mstats.fwd_drop_ttl;
123 data[2] = priv->mstats.fwd_drop_noroute;
124 data[3] = priv->mstats.fwd_drop_nobuf;
125 data[4] = priv->mstats.fwd_unicast_cnt;
126 data[5] = priv->mstats.fwd_bcast_cnt;
127 data[6] = priv->mstats.drop_blind;
Javier Cardona0601e7e2007-05-25 12:12:06 -0400128 data[7] = priv->mstats.tx_failed_cnt;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129
Holger Schurig9012b282007-05-25 11:27:16 -0400130 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131}
132
133static int libertas_ethtool_get_stats_count(struct net_device * dev)
134{
135 int ret;
136 wlan_private *priv = dev->priv;
137 struct cmd_ds_mesh_access mesh_access;
138
Holger Schurig9012b282007-05-25 11:27:16 -0400139 lbs_deb_enter(LBS_DEB_ETHTOOL);
140
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141 /* Get Mesh Statistics */
142 ret = libertas_prepare_and_send_command(priv,
143 cmd_mesh_access, cmd_act_mesh_get_stats,
144 cmd_option_waitforrsp, 0, &mesh_access);
145
146 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400147 ret = 0;
148 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 }
150
151 priv->mstats.fwd_drop_rbt = mesh_access.data[0];
152 priv->mstats.fwd_drop_ttl = mesh_access.data[1];
153 priv->mstats.fwd_drop_noroute = mesh_access.data[2];
154 priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
155 priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
156 priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
157 priv->mstats.drop_blind = mesh_access.data[6];
Javier Cardona0601e7e2007-05-25 12:12:06 -0400158 priv->mstats.tx_failed_cnt = mesh_access.data[7];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159
Holger Schurig9012b282007-05-25 11:27:16 -0400160 ret = MESH_STATS_NUM;
161
162done:
163 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
164 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165}
166
167static void libertas_ethtool_get_strings (struct net_device * dev,
168 u32 stringset,
169 u8 * s)
170{
171 int i;
172
Holger Schurig9012b282007-05-25 11:27:16 -0400173 lbs_deb_enter(LBS_DEB_ETHTOOL);
174
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 switch (stringset) {
176 case ETH_SS_STATS:
177 for (i=0; i < MESH_STATS_NUM; i++) {
178 memcpy(s + i * ETH_GSTRING_LEN,
179 mesh_stat_strings[i],
180 ETH_GSTRING_LEN);
181 }
182 break;
183 }
Holger Schurig9012b282007-05-25 11:27:16 -0400184 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185}
186
187struct ethtool_ops libertas_ethtool_ops = {
188 .get_drvinfo = libertas_ethtool_get_drvinfo,
189 .get_eeprom = libertas_ethtool_get_eeprom,
190 .get_eeprom_len = libertas_ethtool_get_eeprom_len,
191 .get_stats_count = libertas_ethtool_get_stats_count,
192 .get_ethtool_stats = libertas_ethtool_get_stats,
193 .get_strings = libertas_ethtool_get_strings,
194};
195