blob: 21e6f988ea81cf9e1753df30e98811e6c9e9da5b [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"
David Woodhouse506e9022007-12-12 20:06:06 -050011#include "cmd.h"
12
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013static 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
Holger Schurig10078322007-11-15 18:05:47 -050024static void lbs_ethtool_get_drvinfo(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025 struct ethtool_drvinfo *info)
26{
Holger Schurig69f90322007-11-23 15:43:44 +010027 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028 char fwver[32];
29
David Woodhouseaa21c002007-12-08 20:04:36 +000030 lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020031
32 strcpy(info->driver, "libertas");
Holger Schurig10078322007-11-15 18:05:47 -050033 strcpy(info->version, lbs_driver_version);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020034 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 */
Holger Schurig10078322007-11-15 18:05:47 -050040#define LBS_EEPROM_LEN 16384
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041
Holger Schurig10078322007-11-15 18:05:47 -050042static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020043{
Holger Schurig10078322007-11-15 18:05:47 -050044 return LBS_EEPROM_LEN;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045}
46
Holger Schurig10078322007-11-15 18:05:47 -050047static int lbs_ethtool_get_eeprom(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048 struct ethtool_eeprom *eeprom, u8 * bytes)
49{
Holger Schurig69f90322007-11-23 15:43:44 +010050 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Holger Schurig10078322007-11-15 18:05:47 -050051 struct lbs_ioctl_regrdwr regctrl;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052 char *ptr;
53 int ret;
54
55 regctrl.action = 0;
56 regctrl.offset = eeprom->offset;
57 regctrl.NOB = eeprom->len;
58
Holger Schurig10078322007-11-15 18:05:47 -050059 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060 return -EINVAL;
61
62// mutex_lock(&priv->mutex);
63
David Woodhouseaa21c002007-12-08 20:04:36 +000064 priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
65 if (!priv->prdeeprom)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 return -ENOMEM;
David Woodhouseaa21c002007-12-08 20:04:36 +000067 memcpy(priv->prdeeprom, &regctrl, sizeof(regctrl));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068
69 /* +14 is for action, offset, and NOB in
70 * response */
Holger Schurig9012b282007-05-25 11:27:16 -040071 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 regctrl.action, regctrl.offset, regctrl.NOB);
73
Holger Schurig10078322007-11-15 18:05:47 -050074 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -040075 CMD_802_11_EEPROM_ACCESS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 regctrl.action,
Dan Williams0aef64d2007-08-02 11:31:18 -040077 CMD_OPTION_WAITFORRSP, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 &regctrl);
79
80 if (ret) {
David Woodhouseaa21c002007-12-08 20:04:36 +000081 if (priv->prdeeprom)
82 kfree(priv->prdeeprom);
Holger Schurig9012b282007-05-25 11:27:16 -040083 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084 }
85
86 mdelay(10);
87
David Woodhouseaa21c002007-12-08 20:04:36 +000088 ptr = (char *)priv->prdeeprom;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
90 /* skip the command header, but include the "value" u32 variable */
Holger Schurig10078322007-11-15 18:05:47 -050091 ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092
93 /*
94 * Return the result back to the user
95 */
96 memcpy(bytes, ptr, eeprom->len);
97
David Woodhouseaa21c002007-12-08 20:04:36 +000098 if (priv->prdeeprom)
99 kfree(priv->prdeeprom);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100// mutex_unlock(&priv->mutex);
101
Holger Schurig9012b282007-05-25 11:27:16 -0400102 ret = 0;
103
104done:
105 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
106 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107}
108
Holger Schurig10078322007-11-15 18:05:47 -0500109static void lbs_ethtool_get_stats(struct net_device * dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 struct ethtool_stats * stats, u64 * data)
111{
Holger Schurig69f90322007-11-23 15:43:44 +0100112 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113 struct cmd_ds_mesh_access mesh_access;
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700114 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
Holger Schurig9012b282007-05-25 11:27:16 -0400116 lbs_deb_enter(LBS_DEB_ETHTOOL);
117
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118 /* Get Mesh Statistics */
Holger Schurig10078322007-11-15 18:05:47 -0500119 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400120 CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
121 CMD_OPTION_WAITFORRSP, 0, &mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700123 if (ret)
124 return;
125
126 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
127 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
128 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
129 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
130 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
131 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
132 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
133 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
134
135 data[0] = priv->mstats.fwd_drop_rbt;
136 data[1] = priv->mstats.fwd_drop_ttl;
137 data[2] = priv->mstats.fwd_drop_noroute;
138 data[3] = priv->mstats.fwd_drop_nobuf;
139 data[4] = priv->mstats.fwd_unicast_cnt;
140 data[5] = priv->mstats.fwd_bcast_cnt;
141 data[6] = priv->mstats.drop_blind;
142 data[7] = priv->mstats.tx_failed_cnt;
143
144 lbs_deb_enter(LBS_DEB_ETHTOOL);
145}
146
Holger Schurig10078322007-11-15 18:05:47 -0500147static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700148{
149 switch (sset) {
150 case ETH_SS_STATS:
151 return MESH_STATS_NUM;
152 default:
153 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155}
156
Holger Schurig10078322007-11-15 18:05:47 -0500157static void lbs_ethtool_get_strings(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 u32 stringset,
159 u8 * s)
160{
161 int i;
162
Holger Schurig9012b282007-05-25 11:27:16 -0400163 lbs_deb_enter(LBS_DEB_ETHTOOL);
164
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165 switch (stringset) {
166 case ETH_SS_STATS:
167 for (i=0; i < MESH_STATS_NUM; i++) {
168 memcpy(s + i * ETH_GSTRING_LEN,
169 mesh_stat_strings[i],
170 ETH_GSTRING_LEN);
171 }
172 break;
173 }
Holger Schurig9012b282007-05-25 11:27:16 -0400174 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175}
176
David Woodhouse506e9022007-12-12 20:06:06 -0500177static void lbs_ethtool_get_wol(struct net_device *dev,
178 struct ethtool_wolinfo *wol)
179{
180 struct lbs_private *priv = dev->priv;
181
182 if (priv->wol_criteria == 0xffffffff) {
183 /* Interface driver didn't configure wake */
184 wol->supported = wol->wolopts = 0;
185 return;
186 }
187
188 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
189
190 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
191 wol->wolopts |= WAKE_UCAST;
192 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
193 wol->wolopts |= WAKE_MCAST;
194 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
195 wol->wolopts |= WAKE_BCAST;
196 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
197 wol->wolopts |= WAKE_PHY;
198}
199
200static int lbs_ethtool_set_wol(struct net_device *dev,
201 struct ethtool_wolinfo *wol)
202{
203 struct lbs_private *priv = dev->priv;
204 uint32_t criteria = 0;
205
206 if (priv->wol_criteria == 0xffffffff && wol->wolopts)
207 return -EOPNOTSUPP;
208
209 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
210 return -EOPNOTSUPP;
211
212 if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
213 if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
214 if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
215 if (wol->wolopts & WAKE_PHY) criteria |= EHS_WAKE_ON_MAC_EVENT;
216
217 return lbs_host_sleep_cfg(priv, criteria);
218}
219
Holger Schurig10078322007-11-15 18:05:47 -0500220struct ethtool_ops lbs_ethtool_ops = {
221 .get_drvinfo = lbs_ethtool_get_drvinfo,
222 .get_eeprom = lbs_ethtool_get_eeprom,
223 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
224 .get_sset_count = lbs_ethtool_get_sset_count,
225 .get_ethtool_stats = lbs_ethtool_get_stats,
226 .get_strings = lbs_ethtool_get_strings,
David Woodhouse506e9022007-12-12 20:06:06 -0500227 .get_wol = lbs_ethtool_get_wol,
228 .set_wol = lbs_ethtool_set_wol,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229};
230