ethtool.c 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/delay.h>

#include "host.h"
#include "decl.h"
#include "defs.h"
#include "dev.h"
#include "join.h"
#include "wext.h"
static const char * mesh_stat_strings[]= {
			"drop_duplicate_bcast",
			"drop_ttl_zero",
			"drop_no_fwd_route",
			"drop_no_buffers",
			"fwded_unicast_cnt",
			"fwded_bcast_cnt",
18 19
			"drop_blind_table",
			"tx_failed_cnt"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
};

static void libertas_ethtool_get_drvinfo(struct net_device *dev,
					 struct ethtool_drvinfo *info)
{
	wlan_private *priv = (wlan_private *) dev->priv;
	char fwver[32];

	libertas_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1);

	strcpy(info->driver, "libertas");
	strcpy(info->version, libertas_driver_version);
	strcpy(info->fw_version, fwver);
}

/* All 8388 parts have 16KiB EEPROM size at the time of writing.
 * In case that changes this needs fixing.
 */
#define LIBERTAS_EEPROM_LEN 16384

static int libertas_ethtool_get_eeprom_len(struct net_device *dev)
{
	return LIBERTAS_EEPROM_LEN;
}

static int libertas_ethtool_get_eeprom(struct net_device *dev,
                                  struct ethtool_eeprom *eeprom, u8 * bytes)
{
	wlan_private *priv = (wlan_private *) dev->priv;
	wlan_adapter *adapter = priv->adapter;
	struct wlan_ioctl_regrdwr regctrl;
	char *ptr;
	int ret;

	regctrl.action = 0;
	regctrl.offset = eeprom->offset;
	regctrl.NOB = eeprom->len;

	if (eeprom->offset + eeprom->len > LIBERTAS_EEPROM_LEN)
		return -EINVAL;

//      mutex_lock(&priv->mutex);

63
	adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
64 65 66 67 68 69
	if (!adapter->prdeeprom)
		return -ENOMEM;
	memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));

	/* +14 is for action, offset, and NOB in
	 * response */
70
	lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n",
71 72 73
	       regctrl.action, regctrl.offset, regctrl.NOB);

	ret = libertas_prepare_and_send_command(priv,
74
				    CMD_802_11_EEPROM_ACCESS,
75
				    regctrl.action,
76
				    CMD_OPTION_WAITFORRSP, 0,
77 78 79 80 81
				    &regctrl);

	if (ret) {
		if (adapter->prdeeprom)
			kfree(adapter->prdeeprom);
82
		goto done;
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	}

	mdelay(10);

	ptr = (char *)adapter->prdeeprom;

	/* skip the command header, but include the "value" u32 variable */
	ptr = ptr + sizeof(struct wlan_ioctl_regrdwr) - 4;

	/*
	 * Return the result back to the user
	 */
	memcpy(bytes, ptr, eeprom->len);

	if (adapter->prdeeprom)
		kfree(adapter->prdeeprom);
//	mutex_unlock(&priv->mutex);

101 102 103 104 105
	ret = 0;

done:
	lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
        return ret;
106 107 108 109 110 111 112
}

static void libertas_ethtool_get_stats(struct net_device * dev,
				struct ethtool_stats * stats, u64 * data)
{
	wlan_private *priv = dev->priv;

113
	lbs_deb_enter(LBS_DEB_ETHTOOL);
114 115 116 117 118 119 120 121 122 123 124

	stats->cmd = ETHTOOL_GSTATS;
	BUG_ON(stats->n_stats != MESH_STATS_NUM);

        data[0] = priv->mstats.fwd_drop_rbt;
        data[1] = priv->mstats.fwd_drop_ttl;
        data[2] = priv->mstats.fwd_drop_noroute;
        data[3] = priv->mstats.fwd_drop_nobuf;
        data[4] = priv->mstats.fwd_unicast_cnt;
        data[5] = priv->mstats.fwd_bcast_cnt;
        data[6] = priv->mstats.drop_blind;
125
        data[7] = priv->mstats.tx_failed_cnt;
126

127
	lbs_deb_enter(LBS_DEB_ETHTOOL);
128 129 130 131 132 133 134 135
}

static int libertas_ethtool_get_stats_count(struct net_device * dev)
{
	int ret;
	wlan_private *priv = dev->priv;
	struct cmd_ds_mesh_access mesh_access;

136 137
	lbs_deb_enter(LBS_DEB_ETHTOOL);

138 139
	/* Get Mesh Statistics */
	ret = libertas_prepare_and_send_command(priv,
140 141
			CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
			CMD_OPTION_WAITFORRSP, 0, &mesh_access);
142 143

	if (ret) {
144 145
		ret = 0;
		goto done;
146 147
	}

148 149 150 151 152 153 154 155
        priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
        priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
        priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
        priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
        priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
        priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
        priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
        priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
156

157 158 159 160 161
	ret = MESH_STATS_NUM;

done:
	lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret);
	return ret;
162 163 164 165 166 167 168 169
}

static void libertas_ethtool_get_strings (struct net_device * dev,
					  u32 stringset,
					  u8 * s)
{
	int i;

170 171
	lbs_deb_enter(LBS_DEB_ETHTOOL);

172 173 174 175 176 177 178 179 180
	switch (stringset) {
        case ETH_SS_STATS:
		for (i=0; i < MESH_STATS_NUM; i++) {
			memcpy(s + i * ETH_GSTRING_LEN,
					mesh_stat_strings[i],
					ETH_GSTRING_LEN);
		}
		break;
        }
181
	lbs_deb_enter(LBS_DEB_ETHTOOL);
182 183 184 185 186 187 188 189 190 191 192
}

struct ethtool_ops libertas_ethtool_ops = {
	.get_drvinfo = libertas_ethtool_get_drvinfo,
	.get_eeprom =  libertas_ethtool_get_eeprom,
	.get_eeprom_len = libertas_ethtool_get_eeprom_len,
	.get_stats_count = libertas_ethtool_get_stats_count,
	.get_ethtool_stats = libertas_ethtool_get_stats,
	.get_strings = libertas_ethtool_get_strings,
};