x86: fix bootup crash in native_read_tsc()
[wrt350n-kernel.git] / drivers / net / wireless / libertas / ethtool.c
blob21e6f988ea81cf9e1753df30e98811e6c9e9da5b
1 #include <linux/netdevice.h>
2 #include <linux/ethtool.h>
3 #include <linux/delay.h>
5 #include "host.h"
6 #include "decl.h"
7 #include "defs.h"
8 #include "dev.h"
9 #include "join.h"
10 #include "wext.h"
11 #include "cmd.h"
13 static 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 "tx_failed_cnt"
24 static void lbs_ethtool_get_drvinfo(struct net_device *dev,
25 struct ethtool_drvinfo *info)
27 struct lbs_private *priv = (struct lbs_private *) dev->priv;
28 char fwver[32];
30 lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
32 strcpy(info->driver, "libertas");
33 strcpy(info->version, lbs_driver_version);
34 strcpy(info->fw_version, fwver);
37 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
38 * In case that changes this needs fixing.
40 #define LBS_EEPROM_LEN 16384
42 static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
44 return LBS_EEPROM_LEN;
47 static int lbs_ethtool_get_eeprom(struct net_device *dev,
48 struct ethtool_eeprom *eeprom, u8 * bytes)
50 struct lbs_private *priv = (struct lbs_private *) dev->priv;
51 struct lbs_ioctl_regrdwr regctrl;
52 char *ptr;
53 int ret;
55 regctrl.action = 0;
56 regctrl.offset = eeprom->offset;
57 regctrl.NOB = eeprom->len;
59 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN)
60 return -EINVAL;
62 // mutex_lock(&priv->mutex);
64 priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
65 if (!priv->prdeeprom)
66 return -ENOMEM;
67 memcpy(priv->prdeeprom, &regctrl, sizeof(regctrl));
69 /* +14 is for action, offset, and NOB in
70 * response */
71 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
72 regctrl.action, regctrl.offset, regctrl.NOB);
74 ret = lbs_prepare_and_send_command(priv,
75 CMD_802_11_EEPROM_ACCESS,
76 regctrl.action,
77 CMD_OPTION_WAITFORRSP, 0,
78 &regctrl);
80 if (ret) {
81 if (priv->prdeeprom)
82 kfree(priv->prdeeprom);
83 goto done;
86 mdelay(10);
88 ptr = (char *)priv->prdeeprom;
90 /* skip the command header, but include the "value" u32 variable */
91 ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4;
94 * Return the result back to the user
96 memcpy(bytes, ptr, eeprom->len);
98 if (priv->prdeeprom)
99 kfree(priv->prdeeprom);
100 // mutex_unlock(&priv->mutex);
102 ret = 0;
104 done:
105 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
106 return ret;
109 static void lbs_ethtool_get_stats(struct net_device * dev,
110 struct ethtool_stats * stats, u64 * data)
112 struct lbs_private *priv = dev->priv;
113 struct cmd_ds_mesh_access mesh_access;
114 int ret;
116 lbs_deb_enter(LBS_DEB_ETHTOOL);
118 /* Get Mesh Statistics */
119 ret = lbs_prepare_and_send_command(priv,
120 CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
121 CMD_OPTION_WAITFORRSP, 0, &mesh_access);
123 if (ret)
124 return;
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]);
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;
144 lbs_deb_enter(LBS_DEB_ETHTOOL);
147 static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
149 switch (sset) {
150 case ETH_SS_STATS:
151 return MESH_STATS_NUM;
152 default:
153 return -EOPNOTSUPP;
157 static void lbs_ethtool_get_strings(struct net_device *dev,
158 u32 stringset,
159 u8 * s)
161 int i;
163 lbs_deb_enter(LBS_DEB_ETHTOOL);
165 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);
172 break;
174 lbs_deb_enter(LBS_DEB_ETHTOOL);
177 static void lbs_ethtool_get_wol(struct net_device *dev,
178 struct ethtool_wolinfo *wol)
180 struct lbs_private *priv = dev->priv;
182 if (priv->wol_criteria == 0xffffffff) {
183 /* Interface driver didn't configure wake */
184 wol->supported = wol->wolopts = 0;
185 return;
188 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
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;
200 static int lbs_ethtool_set_wol(struct net_device *dev,
201 struct ethtool_wolinfo *wol)
203 struct lbs_private *priv = dev->priv;
204 uint32_t criteria = 0;
206 if (priv->wol_criteria == 0xffffffff && wol->wolopts)
207 return -EOPNOTSUPP;
209 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
210 return -EOPNOTSUPP;
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;
217 return lbs_host_sleep_cfg(priv, criteria);
220 struct 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,
227 .get_wol = lbs_ethtool_get_wol,
228 .set_wol = lbs_ethtool_set_wol,