blob: a54b4f406af2d5d1ca2160751c62dc10dba254fe [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001#include <linux/netdevice.h>
2#include <linux/ethtool.h>
3#include <linux/delay.h>
4
5#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include "decl.h"
7#include "defs.h"
8#include "dev.h"
9#include "join.h"
10#include "wext.h"
11static const char * mesh_stat_strings[]= {
12 "drop_duplicate_bcast",
13 "drop_ttl_zero",
14 "drop_no_fwd_route",
15 "drop_no_buffers",
16 "fwded_unicast_cnt",
17 "fwded_bcast_cnt",
Javier Cardona0601e7e2007-05-25 12:12:06 -040018 "drop_blind_table",
19 "tx_failed_cnt"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020};
21
Holger Schurig10078322007-11-15 18:05:47 -050022static void lbs_ethtool_get_drvinfo(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023 struct ethtool_drvinfo *info)
24{
Holger Schurig69f90322007-11-23 15:43:44 +010025 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026 char fwver[32];
27
David Woodhouseaa21c002007-12-08 20:04:36 +000028 lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029
30 strcpy(info->driver, "libertas");
Holger Schurig10078322007-11-15 18:05:47 -050031 strcpy(info->version, lbs_driver_version);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020032 strcpy(info->fw_version, fwver);
33}
34
35/* All 8388 parts have 16KiB EEPROM size at the time of writing.
36 * In case that changes this needs fixing.
37 */
Holger Schurig10078322007-11-15 18:05:47 -050038#define LBS_EEPROM_LEN 16384
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039
Holger Schurig10078322007-11-15 18:05:47 -050040static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041{
Holger Schurig10078322007-11-15 18:05:47 -050042 return LBS_EEPROM_LEN;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020043}
44
Holger Schurig10078322007-11-15 18:05:47 -050045static int lbs_ethtool_get_eeprom(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 struct ethtool_eeprom *eeprom, u8 * bytes)
47{
Holger Schurig69f90322007-11-23 15:43:44 +010048 struct lbs_private *priv = (struct lbs_private *) dev->priv;
Holger Schurig10078322007-11-15 18:05:47 -050049 struct lbs_ioctl_regrdwr regctrl;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 char *ptr;
51 int ret;
52
53 regctrl.action = 0;
54 regctrl.offset = eeprom->offset;
55 regctrl.NOB = eeprom->len;
56
Holger Schurig10078322007-11-15 18:05:47 -050057 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020058 return -EINVAL;
59
60// mutex_lock(&priv->mutex);
61
David Woodhouseaa21c002007-12-08 20:04:36 +000062 priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
63 if (!priv->prdeeprom)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 return -ENOMEM;
David Woodhouseaa21c002007-12-08 20:04:36 +000065 memcpy(priv->prdeeprom, &regctrl, sizeof(regctrl));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066
67 /* +14 is for action, offset, and NOB in
68 * response */
Holger Schurig9012b282007-05-25 11:27:16 -040069 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070 regctrl.action, regctrl.offset, regctrl.NOB);
71
Holger Schurig10078322007-11-15 18:05:47 -050072 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -040073 CMD_802_11_EEPROM_ACCESS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 regctrl.action,
Dan Williams0aef64d2007-08-02 11:31:18 -040075 CMD_OPTION_WAITFORRSP, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 &regctrl);
77
78 if (ret) {
David Woodhouseaa21c002007-12-08 20:04:36 +000079 if (priv->prdeeprom)
80 kfree(priv->prdeeprom);
Holger Schurig9012b282007-05-25 11:27:16 -040081 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020082 }
83
84 mdelay(10);
85
David Woodhouseaa21c002007-12-08 20:04:36 +000086 ptr = (char *)priv->prdeeprom;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020087
88 /* skip the command header, but include the "value" u32 variable */
Holger Schurig10078322007-11-15 18:05:47 -050089 ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
91 /*
92 * Return the result back to the user
93 */
94 memcpy(bytes, ptr, eeprom->len);
95
David Woodhouseaa21c002007-12-08 20:04:36 +000096 if (priv->prdeeprom)
97 kfree(priv->prdeeprom);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098// mutex_unlock(&priv->mutex);
99
Holger Schurig9012b282007-05-25 11:27:16 -0400100 ret = 0;
101
102done:
103 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
104 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105}
106
Holger Schurig10078322007-11-15 18:05:47 -0500107static void lbs_ethtool_get_stats(struct net_device * dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 struct ethtool_stats * stats, u64 * data)
109{
Holger Schurig69f90322007-11-23 15:43:44 +0100110 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111 struct cmd_ds_mesh_access mesh_access;
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700112 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113
Holger Schurig9012b282007-05-25 11:27:16 -0400114 lbs_deb_enter(LBS_DEB_ETHTOOL);
115
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116 /* Get Mesh Statistics */
Holger Schurig10078322007-11-15 18:05:47 -0500117 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400118 CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
119 CMD_OPTION_WAITFORRSP, 0, &mesh_access);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700121 if (ret)
122 return;
123
124 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
125 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
126 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
127 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
128 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
129 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
130 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
131 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
132
133 data[0] = priv->mstats.fwd_drop_rbt;
134 data[1] = priv->mstats.fwd_drop_ttl;
135 data[2] = priv->mstats.fwd_drop_noroute;
136 data[3] = priv->mstats.fwd_drop_nobuf;
137 data[4] = priv->mstats.fwd_unicast_cnt;
138 data[5] = priv->mstats.fwd_bcast_cnt;
139 data[6] = priv->mstats.drop_blind;
140 data[7] = priv->mstats.tx_failed_cnt;
141
142 lbs_deb_enter(LBS_DEB_ETHTOOL);
143}
144
Holger Schurig10078322007-11-15 18:05:47 -0500145static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700146{
147 switch (sset) {
148 case ETH_SS_STATS:
149 return MESH_STATS_NUM;
150 default:
151 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153}
154
Holger Schurig10078322007-11-15 18:05:47 -0500155static void lbs_ethtool_get_strings(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156 u32 stringset,
157 u8 * s)
158{
159 int i;
160
Holger Schurig9012b282007-05-25 11:27:16 -0400161 lbs_deb_enter(LBS_DEB_ETHTOOL);
162
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 switch (stringset) {
164 case ETH_SS_STATS:
165 for (i=0; i < MESH_STATS_NUM; i++) {
166 memcpy(s + i * ETH_GSTRING_LEN,
167 mesh_stat_strings[i],
168 ETH_GSTRING_LEN);
169 }
170 break;
171 }
Holger Schurig9012b282007-05-25 11:27:16 -0400172 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173}
174
Holger Schurig10078322007-11-15 18:05:47 -0500175struct ethtool_ops lbs_ethtool_ops = {
176 .get_drvinfo = lbs_ethtool_get_drvinfo,
177 .get_eeprom = lbs_ethtool_get_eeprom,
178 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
179 .get_sset_count = lbs_ethtool_get_sset_count,
180 .get_ethtool_stats = lbs_ethtool_get_stats,
181 .get_strings = lbs_ethtool_get_strings,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182};
183