libertas: move association code from join.c into scan.c
[safe/jmp/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 "wext.h"
10 #include "cmd.h"
11
12 static const char * mesh_stat_strings[]= {
13                         "drop_duplicate_bcast",
14                         "drop_ttl_zero",
15                         "drop_no_fwd_route",
16                         "drop_no_buffers",
17                         "fwded_unicast_cnt",
18                         "fwded_bcast_cnt",
19                         "drop_blind_table",
20                         "tx_failed_cnt"
21 };
22
23 static void lbs_ethtool_get_drvinfo(struct net_device *dev,
24                                          struct ethtool_drvinfo *info)
25 {
26         struct lbs_private *priv = (struct lbs_private *) dev->priv;
27         char fwver[32];
28
29         lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
30
31         strcpy(info->driver, "libertas");
32         strcpy(info->version, lbs_driver_version);
33         strcpy(info->fw_version, fwver);
34 }
35
36 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
37  * In case that changes this needs fixing.
38  */
39 #define LBS_EEPROM_LEN 16384
40
41 static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
42 {
43         return LBS_EEPROM_LEN;
44 }
45
46 static int lbs_ethtool_get_eeprom(struct net_device *dev,
47                                   struct ethtool_eeprom *eeprom, u8 * bytes)
48 {
49         struct lbs_private *priv = (struct lbs_private *) dev->priv;
50         struct cmd_ds_802_11_eeprom_access cmd;
51         int ret;
52
53         lbs_deb_enter(LBS_DEB_ETHTOOL);
54
55         if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
56             eeprom->len > LBS_EEPROM_READ_LEN) {
57                 ret = -EINVAL;
58                 goto out;
59         }
60
61         cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
62                 LBS_EEPROM_READ_LEN + eeprom->len);
63         cmd.action = cpu_to_le16(CMD_ACT_GET);
64         cmd.offset = cpu_to_le16(eeprom->offset);
65         cmd.len    = cpu_to_le16(eeprom->len);
66         ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
67         if (!ret)
68                 memcpy(bytes, cmd.value, eeprom->len);
69
70 out:
71         lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
72         return ret;
73 }
74
75 static void lbs_ethtool_get_stats(struct net_device * dev,
76                                 struct ethtool_stats * stats, u64 * data)
77 {
78         struct lbs_private *priv = dev->priv;
79         struct cmd_ds_mesh_access mesh_access;
80         int ret;
81
82         lbs_deb_enter(LBS_DEB_ETHTOOL);
83
84         /* Get Mesh Statistics */
85         ret = lbs_prepare_and_send_command(priv,
86                         CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
87                         CMD_OPTION_WAITFORRSP, 0, &mesh_access);
88
89         if (ret)
90                 return;
91
92         priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
93         priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
94         priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
95         priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
96         priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
97         priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
98         priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
99         priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
100
101         data[0] = priv->mstats.fwd_drop_rbt;
102         data[1] = priv->mstats.fwd_drop_ttl;
103         data[2] = priv->mstats.fwd_drop_noroute;
104         data[3] = priv->mstats.fwd_drop_nobuf;
105         data[4] = priv->mstats.fwd_unicast_cnt;
106         data[5] = priv->mstats.fwd_bcast_cnt;
107         data[6] = priv->mstats.drop_blind;
108         data[7] = priv->mstats.tx_failed_cnt;
109
110         lbs_deb_enter(LBS_DEB_ETHTOOL);
111 }
112
113 static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
114 {
115         switch (sset) {
116         case ETH_SS_STATS:
117                 return MESH_STATS_NUM;
118         default:
119                 return -EOPNOTSUPP;
120         }
121 }
122
123 static void lbs_ethtool_get_strings(struct net_device *dev,
124                                           u32 stringset,
125                                           u8 * s)
126 {
127         int i;
128
129         lbs_deb_enter(LBS_DEB_ETHTOOL);
130
131         switch (stringset) {
132         case ETH_SS_STATS:
133                 for (i=0; i < MESH_STATS_NUM; i++) {
134                         memcpy(s + i * ETH_GSTRING_LEN,
135                                         mesh_stat_strings[i],
136                                         ETH_GSTRING_LEN);
137                 }
138                 break;
139         }
140         lbs_deb_enter(LBS_DEB_ETHTOOL);
141 }
142
143 static void lbs_ethtool_get_wol(struct net_device *dev,
144                                 struct ethtool_wolinfo *wol)
145 {
146         struct lbs_private *priv = dev->priv;
147
148         if (priv->wol_criteria == 0xffffffff) {
149                 /* Interface driver didn't configure wake */
150                 wol->supported = wol->wolopts = 0;
151                 return;
152         }
153
154         wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
155
156         if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
157                 wol->wolopts |= WAKE_UCAST;
158         if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
159                 wol->wolopts |= WAKE_MCAST;
160         if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
161                 wol->wolopts |= WAKE_BCAST;
162         if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
163                 wol->wolopts |= WAKE_PHY;
164 }
165
166 static int lbs_ethtool_set_wol(struct net_device *dev,
167                                struct ethtool_wolinfo *wol)
168 {
169         struct lbs_private *priv = dev->priv;
170         uint32_t criteria = 0;
171
172         if (priv->wol_criteria == 0xffffffff && wol->wolopts)
173                 return -EOPNOTSUPP;
174
175         if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
176                 return -EOPNOTSUPP;
177
178         if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
179         if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
180         if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
181         if (wol->wolopts & WAKE_PHY)   criteria |= EHS_WAKE_ON_MAC_EVENT;
182
183         return lbs_host_sleep_cfg(priv, criteria);
184 }
185
186 struct ethtool_ops lbs_ethtool_ops = {
187         .get_drvinfo = lbs_ethtool_get_drvinfo,
188         .get_eeprom =  lbs_ethtool_get_eeprom,
189         .get_eeprom_len = lbs_ethtool_get_eeprom_len,
190         .get_sset_count = lbs_ethtool_get_sset_count,
191         .get_ethtool_stats = lbs_ethtool_get_stats,
192         .get_strings = lbs_ethtool_get_strings,
193         .get_wol = lbs_ethtool_get_wol,
194         .set_wol = lbs_ethtool_set_wol,
195 };
196