- Update to 2.6.25-rc3.
[linux-flexiantxendom0-3.2.10.git] / drivers / net / wireless / libertas / ethtool.c
1 #include <linux/netdevice.h>
2 #include <linux/ethtool.h>
3 #include <linux/delay.h>
4
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"
12
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"
22 };
23
24 static void lbs_ethtool_get_drvinfo(struct net_device *dev,
25                                          struct ethtool_drvinfo *info)
26 {
27         struct lbs_private *priv = (struct lbs_private *) dev->priv;
28         char fwver[32];
29
30         lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
31
32         strcpy(info->driver, "libertas");
33         strcpy(info->version, lbs_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 LBS_EEPROM_LEN 16384
41
42 static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
43 {
44         return LBS_EEPROM_LEN;
45 }
46
47 static int lbs_ethtool_get_eeprom(struct net_device *dev,
48                                   struct ethtool_eeprom *eeprom, u8 * bytes)
49 {
50         struct lbs_private *priv = (struct lbs_private *) dev->priv;
51         struct lbs_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 > LBS_EEPROM_LEN)
60                 return -EINVAL;
61
62 //      mutex_lock(&priv->mutex);
63
64         priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
65         if (!priv->prdeeprom)
66                 return -ENOMEM;
67         memcpy(priv->prdeeprom, &regctrl, sizeof(regctrl));
68
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);
73
74         ret = lbs_prepare_and_send_command(priv,
75                                     CMD_802_11_EEPROM_ACCESS,
76                                     regctrl.action,
77                                     CMD_OPTION_WAITFORRSP, 0,
78                                     &regctrl);
79
80         if (ret) {
81                 if (priv->prdeeprom)
82                         kfree(priv->prdeeprom);
83                 goto done;
84         }
85
86         mdelay(10);
87
88         ptr = (char *)priv->prdeeprom;
89
90         /* skip the command header, but include the "value" u32 variable */
91         ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4;
92
93         /*
94          * Return the result back to the user
95          */
96         memcpy(bytes, ptr, eeprom->len);
97
98         if (priv->prdeeprom)
99                 kfree(priv->prdeeprom);
100 //      mutex_unlock(&priv->mutex);
101
102         ret = 0;
103
104 done:
105         lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
106         return ret;
107 }
108
109 static void lbs_ethtool_get_stats(struct net_device * dev,
110                                 struct ethtool_stats * stats, u64 * data)
111 {
112         struct lbs_private *priv = dev->priv;
113         struct cmd_ds_mesh_access mesh_access;
114         int ret;
115
116         lbs_deb_enter(LBS_DEB_ETHTOOL);
117
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);
122
123         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
147 static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
148 {
149         switch (sset) {
150         case ETH_SS_STATS:
151                 return MESH_STATS_NUM;
152         default:
153                 return -EOPNOTSUPP;
154         }
155 }
156
157 static void lbs_ethtool_get_strings(struct net_device *dev,
158                                           u32 stringset,
159                                           u8 * s)
160 {
161         int i;
162
163         lbs_deb_enter(LBS_DEB_ETHTOOL);
164
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);
171                 }
172                 break;
173         }
174         lbs_deb_enter(LBS_DEB_ETHTOOL);
175 }
176
177 static 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
200 static 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
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,
229 };
230