Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / 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 cmd_ds_802_11_eeprom_access cmd;
52         int ret;
53
54         lbs_deb_enter(LBS_DEB_ETHTOOL);
55
56         if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
57             eeprom->len > LBS_EEPROM_READ_LEN) {
58                 ret = -EINVAL;
59                 goto out;
60         }
61
62         cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
63                 LBS_EEPROM_READ_LEN + eeprom->len);
64         cmd.action = cpu_to_le16(CMD_ACT_GET);
65         cmd.offset = cpu_to_le16(eeprom->offset);
66         cmd.len    = cpu_to_le16(eeprom->len);
67         ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
68         if (!ret)
69                 memcpy(bytes, cmd.value, eeprom->len);
70
71 out:
72         lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
73         return ret;
74 }
75
76 static void lbs_ethtool_get_stats(struct net_device * dev,
77                                 struct ethtool_stats * stats, u64 * data)
78 {
79         struct lbs_private *priv = dev->priv;
80         struct cmd_ds_mesh_access mesh_access;
81         int ret;
82
83         lbs_deb_enter(LBS_DEB_ETHTOOL);
84
85         /* Get Mesh Statistics */
86         ret = lbs_prepare_and_send_command(priv,
87                         CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
88                         CMD_OPTION_WAITFORRSP, 0, &mesh_access);
89
90         if (ret)
91                 return;
92
93         priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
94         priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
95         priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
96         priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
97         priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
98         priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
99         priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
100         priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
101
102         data[0] = priv->mstats.fwd_drop_rbt;
103         data[1] = priv->mstats.fwd_drop_ttl;
104         data[2] = priv->mstats.fwd_drop_noroute;
105         data[3] = priv->mstats.fwd_drop_nobuf;
106         data[4] = priv->mstats.fwd_unicast_cnt;
107         data[5] = priv->mstats.fwd_bcast_cnt;
108         data[6] = priv->mstats.drop_blind;
109         data[7] = priv->mstats.tx_failed_cnt;
110
111         lbs_deb_enter(LBS_DEB_ETHTOOL);
112 }
113
114 static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
115 {
116         switch (sset) {
117         case ETH_SS_STATS:
118                 return MESH_STATS_NUM;
119         default:
120                 return -EOPNOTSUPP;
121         }
122 }
123
124 static void lbs_ethtool_get_strings(struct net_device *dev,
125                                           u32 stringset,
126                                           u8 * s)
127 {
128         int i;
129
130         lbs_deb_enter(LBS_DEB_ETHTOOL);
131
132         switch (stringset) {
133         case ETH_SS_STATS:
134                 for (i=0; i < MESH_STATS_NUM; i++) {
135                         memcpy(s + i * ETH_GSTRING_LEN,
136                                         mesh_stat_strings[i],
137                                         ETH_GSTRING_LEN);
138                 }
139                 break;
140         }
141         lbs_deb_enter(LBS_DEB_ETHTOOL);
142 }
143
144 static void lbs_ethtool_get_wol(struct net_device *dev,
145                                 struct ethtool_wolinfo *wol)
146 {
147         struct lbs_private *priv = dev->priv;
148
149         if (priv->wol_criteria == 0xffffffff) {
150                 /* Interface driver didn't configure wake */
151                 wol->supported = wol->wolopts = 0;
152                 return;
153         }
154
155         wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
156
157         if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
158                 wol->wolopts |= WAKE_UCAST;
159         if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
160                 wol->wolopts |= WAKE_MCAST;
161         if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
162                 wol->wolopts |= WAKE_BCAST;
163         if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
164                 wol->wolopts |= WAKE_PHY;
165 }
166
167 static int lbs_ethtool_set_wol(struct net_device *dev,
168                                struct ethtool_wolinfo *wol)
169 {
170         struct lbs_private *priv = dev->priv;
171         uint32_t criteria = 0;
172
173         if (priv->wol_criteria == 0xffffffff && wol->wolopts)
174                 return -EOPNOTSUPP;
175
176         if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
177                 return -EOPNOTSUPP;
178
179         if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
180         if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
181         if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
182         if (wol->wolopts & WAKE_PHY)   criteria |= EHS_WAKE_ON_MAC_EVENT;
183
184         return lbs_host_sleep_cfg(priv, criteria);
185 }
186
187 struct ethtool_ops lbs_ethtool_ops = {
188         .get_drvinfo = lbs_ethtool_get_drvinfo,
189         .get_eeprom =  lbs_ethtool_get_eeprom,
190         .get_eeprom_len = lbs_ethtool_get_eeprom_len,
191         .get_sset_count = lbs_ethtool_get_sset_count,
192         .get_ethtool_stats = lbs_ethtool_get_stats,
193         .get_strings = lbs_ethtool_get_strings,
194         .get_wol = lbs_ethtool_get_wol,
195         .set_wol = lbs_ethtool_set_wol,
196 };
197