2 #include <linux/netdevice.h>
3 #include <linux/ethtool.h>
4 #include <linux/delay.h>
13 static const char * mesh_stat_strings[]= {
14 "drop_duplicate_bcast",
23 static void libertas_ethtool_get_drvinfo(struct net_device *dev,
24 struct ethtool_drvinfo *info)
26 wlan_private *priv = (wlan_private *) dev->priv;
29 libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
31 strcpy(info->driver, "libertas");
32 strcpy(info->version, libertas_driver_version);
33 strcpy(info->fw_version, fwver);
36 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
37 * In case that changes this needs fixing.
39 #define LIBERTAS_EEPROM_LEN 16384
41 static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
43 return LIBERTAS_EEPROM_LEN;
46 static int libertas_ethtool_get_eeprom(struct net_device *dev,
47 struct ethtool_eeprom *eeprom, u8 * bytes)
49 wlan_private *priv = (wlan_private *) dev->priv;
50 wlan_adapter *adapter = priv->adapter;
51 struct wlan_ioctl_regrdwr regctrl;
56 regctrl.offset = eeprom->offset;
57 regctrl.NOB = eeprom->len;
59 if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
62 // mutex_lock(&priv->mutex);
65 (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
66 if (!adapter->prdeeprom)
68 memcpy(adapter->prdeeprom, ®ctrl, sizeof(regctrl));
70 /* +14 is for action, offset, and NOB in
72 lbs_pr_debug(1, "action:%d offset: %x NOB: %02x\n",
73 regctrl.action, regctrl.offset, regctrl.NOB);
75 ret = libertas_prepare_and_send_command(priv,
76 cmd_802_11_eeprom_access,
78 cmd_option_waitforrsp, 0,
82 if (adapter->prdeeprom)
83 kfree(adapter->prdeeprom);
90 ptr = (char *)adapter->prdeeprom;
92 /* skip the command header, but include the "value" u32 variable */
93 ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
96 * Return the result back to the user
98 memcpy(bytes, ptr, eeprom->len);
100 if (adapter->prdeeprom)
101 kfree(adapter->prdeeprom);
102 // mutex_unlock(&priv->mutex);
107 static void libertas_ethtool_get_stats(struct net_device * dev,
108 struct ethtool_stats * stats, u64 * data)
110 wlan_private *priv = dev->priv;
114 stats->cmd = ETHTOOL_GSTATS;
115 BUG_ON(stats->n_stats != MESH_STATS_NUM);
117 data[0] = priv->mstats.fwd_drop_rbt;
118 data[1] = priv->mstats.fwd_drop_ttl;
119 data[2] = priv->mstats.fwd_drop_noroute;
120 data[3] = priv->mstats.fwd_drop_nobuf;
121 data[4] = priv->mstats.fwd_unicast_cnt;
122 data[5] = priv->mstats.fwd_bcast_cnt;
123 data[6] = priv->mstats.drop_blind;
128 static int libertas_ethtool_get_stats_count(struct net_device * dev)
131 wlan_private *priv = dev->priv;
132 struct cmd_ds_mesh_access mesh_access;
135 /* Get Mesh Statistics */
136 ret = libertas_prepare_and_send_command(priv,
137 cmd_mesh_access, cmd_act_mesh_get_stats,
138 cmd_option_waitforrsp, 0, &mesh_access);
145 priv->mstats.fwd_drop_rbt = mesh_access.data[0];
146 priv->mstats.fwd_drop_ttl = mesh_access.data[1];
147 priv->mstats.fwd_drop_noroute = mesh_access.data[2];
148 priv->mstats.fwd_drop_nobuf = mesh_access.data[3];
149 priv->mstats.fwd_unicast_cnt = mesh_access.data[4];
150 priv->mstats.fwd_bcast_cnt = mesh_access.data[5];
151 priv->mstats.drop_blind = mesh_access.data[6];
154 return MESH_STATS_NUM;
157 static void libertas_ethtool_get_strings (struct net_device * dev,
166 for (i=0; i < MESH_STATS_NUM; i++) {
167 memcpy(s + i * ETH_GSTRING_LEN,
168 mesh_stat_strings[i],
176 struct ethtool_ops libertas_ethtool_ops = {
177 .get_drvinfo = libertas_ethtool_get_drvinfo,
178 .get_eeprom = libertas_ethtool_get_eeprom,
179 .get_eeprom_len = libertas_ethtool_get_eeprom_len,
180 .get_stats_count = libertas_ethtool_get_stats_count,
181 .get_ethtool_stats = libertas_ethtool_get_stats,
182 .get_strings = libertas_ethtool_get_strings,