1 #include <linux/netdevice.h>
2 #include <linux/ethtool.h>
3 #include <linux/delay.h>
11 static const char * mesh_stat_strings[]= {
12 "drop_duplicate_bcast",
22 static void libertas_ethtool_get_drvinfo(struct net_device *dev,
23 struct ethtool_drvinfo *info)
25 wlan_private *priv = (wlan_private *) dev->priv;
28 libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);
30 strcpy(info->driver, "libertas");
31 strcpy(info->version, libertas_driver_version);
32 strcpy(info->fw_version, fwver);
35 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
36 * In case that changes this needs fixing.
38 #define LIBERTAS_EEPROM_LEN 16384
40 static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
42 return LIBERTAS_EEPROM_LEN;
45 static int libertas_ethtool_get_eeprom(struct net_device *dev,
46 struct ethtool_eeprom *eeprom, u8 * bytes)
48 wlan_private *priv = (wlan_private *) dev->priv;
49 wlan_adapter *adapter = priv->adapter;
50 struct wlan_ioctl_regrdwr regctrl;
55 regctrl.offset = eeprom->offset;
56 regctrl.NOB = eeprom->len;
58 if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
61 // mutex_lock(&priv->mutex);
63 adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
64 if (!adapter->prdeeprom)
66 memcpy(adapter->prdeeprom, ®ctrl, sizeof(regctrl));
68 /* +14 is for action, offset, and NOB in
70 lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
71 regctrl.action, regctrl.offset, regctrl.NOB);
73 ret = libertas_prepare_and_send_command(priv,
74 CMD_802_11_EEPROM_ACCESS,
76 CMD_OPTION_WAITFORRSP, 0,
80 if (adapter->prdeeprom)
81 kfree(adapter->prdeeprom);
87 ptr = (char *)adapter->prdeeprom;
89 /* skip the command header, but include the "value" u32 variable */
90 ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;
93 * Return the result back to the user
95 memcpy(bytes, ptr, eeprom->len);
97 if (adapter->prdeeprom)
98 kfree(adapter->prdeeprom);
99 // mutex_unlock(&priv->mutex);
104 lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
108 static void libertas_ethtool_get_stats(struct net_device * dev,
109 struct ethtool_stats * stats, u64 * data)
111 wlan_private *priv = dev->priv;
112 struct cmd_ds_mesh_access mesh_access;
115 lbs_deb_enter(LBS_DEB_ETHTOOL);
117 /* Get Mesh Statistics */
118 ret = libertas_prepare_and_send_command(priv,
119 CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
120 CMD_OPTION_WAITFORRSP, 0, &mesh_access);
125 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
126 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
127 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
128 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
129 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
130 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
131 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
132 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
134 data[0] = priv->mstats.fwd_drop_rbt;
135 data[1] = priv->mstats.fwd_drop_ttl;
136 data[2] = priv->mstats.fwd_drop_noroute;
137 data[3] = priv->mstats.fwd_drop_nobuf;
138 data[4] = priv->mstats.fwd_unicast_cnt;
139 data[5] = priv->mstats.fwd_bcast_cnt;
140 data[6] = priv->mstats.drop_blind;
141 data[7] = priv->mstats.tx_failed_cnt;
143 lbs_deb_enter(LBS_DEB_ETHTOOL);
146 static int libertas_ethtool_get_sset_count(struct net_device * dev, int sset)
150 return MESH_STATS_NUM;
156 static void libertas_ethtool_get_strings (struct net_device * dev,
162 lbs_deb_enter(LBS_DEB_ETHTOOL);
166 for (i=0; i < MESH_STATS_NUM; i++) {
167 memcpy(s + i * ETH_GSTRING_LEN,
168 mesh_stat_strings[i],
173 lbs_deb_enter(LBS_DEB_ETHTOOL);
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_sset_count = libertas_ethtool_get_sset_count,
181 .get_ethtool_stats = libertas_ethtool_get_stats,
182 .get_strings = libertas_ethtool_get_strings,