]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/libertas/ethtool.c
[PATCH] libertas: added transmission failures to mesh statistics
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / libertas / ethtool.c
1
2 #include <linux/netdevice.h>
3 #include <linux/ethtool.h>
4 #include <linux/delay.h>
5
6 #include "host.h"
7 #include "sbi.h"
8 #include "decl.h"
9 #include "defs.h"
10 #include "dev.h"
11 #include "join.h"
12 #include "wext.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"
22 };
23
24 static void libertas_ethtool_get_drvinfo(struct net_device *dev,
25                                          struct ethtool_drvinfo *info)
26 {
27         wlan_private *priv = (wlan_private *) dev->priv;
28         char fwver[32];
29
30         libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
31
32         strcpy(info->driver, "libertas");
33         strcpy(info->version, libertas_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 LIBERTAS_EEPROM_LEN 16384
41
42 static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
43 {
44         return LIBERTAS_EEPROM_LEN;
45 }
46
47 static int libertas_ethtool_get_eeprom(struct net_device *dev,
48                                   struct ethtool_eeprom *eeprom, u8 * bytes)
49 {
50         wlan_private *priv = (wlan_private *) dev->priv;
51         wlan_adapter *adapter = priv->adapter;
52         struct wlan_ioctl_regrdwr regctrl;
53         char *ptr;
54         int ret;
55
56         regctrl.action = 0;
57         regctrl.offset = eeprom->offset;
58         regctrl.NOB = eeprom->len;
59
60         if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
61                 return -EINVAL;
62
63 //      mutex_lock(&priv->mutex);
64
65         adapter->prdeeprom =
66                     (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
67         if (!adapter->prdeeprom)
68                 return -ENOMEM;
69         memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
70
71         /* +14 is for action, offset, and NOB in
72          * response */
73         lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
74                regctrl.action, regctrl.offset, regctrl.NOB);
75
76         ret = libertas_prepare_and_send_command(priv,
77                                     cmd_802_11_eeprom_access,
78                                     regctrl.action,
79                                     cmd_option_waitforrsp, 0,
80                                     &regctrl);
81
82         if (ret) {
83                 if (adapter->prdeeprom)
84                         kfree(adapter->prdeeprom);
85                 goto done;
86         }
87
88         mdelay(10);
89
90         ptr = (char *)adapter->prdeeprom;
91
92         /* skip the command header, but include the "value" u32 variable */
93         ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
94
95         /*
96          * Return the result back to the user
97          */
98         memcpy(bytes, ptr, eeprom->len);
99
100         if (adapter->prdeeprom)
101                 kfree(adapter->prdeeprom);
102 //      mutex_unlock(&priv->mutex);
103
104         ret = 0;
105
106 done:
107         lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
108         return ret;
109 }
110
111 static void libertas_ethtool_get_stats(struct net_device * dev,
112                                 struct ethtool_stats * stats, u64 * data)
113 {
114         wlan_private *priv = dev->priv;
115
116         lbs_deb_enter(LBS_DEB_ETHTOOL);
117
118         stats->cmd = ETHTOOL_GSTATS;
119         BUG_ON(stats->n_stats != MESH_STATS_NUM);
120
121         data[0] = priv->mstats.fwd_drop_rbt;
122         data[1] = priv->mstats.fwd_drop_ttl;
123         data[2] = priv->mstats.fwd_drop_noroute;
124         data[3] = priv->mstats.fwd_drop_nobuf;
125         data[4] = priv->mstats.fwd_unicast_cnt;
126         data[5] = priv->mstats.fwd_bcast_cnt;
127         data[6] = priv->mstats.drop_blind;
128         data[7] = priv->mstats.tx_failed_cnt;
129
130         lbs_deb_enter(LBS_DEB_ETHTOOL);
131 }
132
133 static int libertas_ethtool_get_stats_count(struct net_device * dev)
134 {
135         int ret;
136         wlan_private *priv = dev->priv;
137         struct cmd_ds_mesh_access mesh_access;
138
139         lbs_deb_enter(LBS_DEB_ETHTOOL);
140
141         /* Get Mesh Statistics */
142         ret = libertas_prepare_and_send_command(priv,
143                         cmd_mesh_access, cmd_act_mesh_get_stats,
144                         cmd_option_waitforrsp, 0, &mesh_access);
145
146         if (ret) {
147                 ret = 0;
148                 goto done;
149         }
150
151         priv->mstats.fwd_drop_rbt = mesh_access.data[0];
152         priv->mstats.fwd_drop_ttl = mesh_access.data[1];
153         priv->mstats.fwd_drop_noroute = mesh_access.data[2];
154         priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
155         priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
156         priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
157         priv->mstats.drop_blind = mesh_access.data[6];
158         priv->mstats.tx_failed_cnt = mesh_access.data[7];
159
160         ret = MESH_STATS_NUM;
161
162 done:
163         lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
164         return ret;
165 }
166
167 static void libertas_ethtool_get_strings (struct net_device * dev,
168                                           u32 stringset,
169                                           u8 * s)
170 {
171         int i;
172
173         lbs_deb_enter(LBS_DEB_ETHTOOL);
174
175         switch (stringset) {
176         case ETH_SS_STATS:
177                 for (i=0; i < MESH_STATS_NUM; i++) {
178                         memcpy(s + i * ETH_GSTRING_LEN,
179                                         mesh_stat_strings[i],
180                                         ETH_GSTRING_LEN);
181                 }
182                 break;
183         }
184         lbs_deb_enter(LBS_DEB_ETHTOOL);
185 }
186
187 struct ethtool_ops libertas_ethtool_ops = {
188         .get_drvinfo = libertas_ethtool_get_drvinfo,
189         .get_eeprom =  libertas_ethtool_get_eeprom,
190         .get_eeprom_len = libertas_ethtool_get_eeprom_len,
191         .get_stats_count = libertas_ethtool_get_stats_count,
192         .get_ethtool_stats = libertas_ethtool_get_stats,
193         .get_strings = libertas_ethtool_get_strings,
194 };
195