ethtool.c 3.22 KB
Newer Older
1
#include <linux/hardirq.h>
2 3 4 5 6
#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/delay.h>

#include "decl.h"
7
#include "cmd.h"
8
#include "mesh.h"
9

10

11
static void lbs_ethtool_get_drvinfo(struct net_device *dev,
12 13
					 struct ethtool_drvinfo *info)
{
14
	struct lbs_private *priv = dev->ml_priv;
15

16 17 18 19 20
	snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
		priv->fwrelease >> 24 & 0xff,
		priv->fwrelease >> 16 & 0xff,
		priv->fwrelease >>  8 & 0xff,
		priv->fwrelease       & 0xff);
21
	strcpy(info->driver, "libertas");
22
	strcpy(info->version, lbs_driver_version);
23 24
}

25 26
/*
 * All 8388 parts have 16KiB EEPROM size at the time of writing.
27 28
 * In case that changes this needs fixing.
 */
29
#define LBS_EEPROM_LEN 16384
30

31
static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
32
{
33
	return LBS_EEPROM_LEN;
34 35
}

36
static int lbs_ethtool_get_eeprom(struct net_device *dev,
37 38
                                  struct ethtool_eeprom *eeprom, u8 * bytes)
{
39
	struct lbs_private *priv = dev->ml_priv;
40
	struct cmd_ds_802_11_eeprom_access cmd;
41 42
	int ret;

43
	lbs_deb_enter(LBS_DEB_ETHTOOL);
44

45 46 47 48
	if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
	    eeprom->len > LBS_EEPROM_READ_LEN) {
		ret = -EINVAL;
		goto out;
49 50
	}

51 52 53 54 55 56 57 58 59 60 61
	cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
		LBS_EEPROM_READ_LEN + eeprom->len);
	cmd.action = cpu_to_le16(CMD_ACT_GET);
	cmd.offset = cpu_to_le16(eeprom->offset);
	cmd.len    = cpu_to_le16(eeprom->len);
	ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
	if (!ret)
		memcpy(bytes, cmd.value, eeprom->len);

out:
	lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
62
        return ret;
63 64
}

65 66 67
static void lbs_ethtool_get_wol(struct net_device *dev,
				struct ethtool_wolinfo *wol)
{
68
	struct lbs_private *priv = dev->ml_priv;
69 70 71

	wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;

72 73 74
	if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
		return;

75 76 77 78 79 80 81 82 83 84 85 86 87
	if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
		wol->wolopts |= WAKE_UCAST;
	if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
		wol->wolopts |= WAKE_MCAST;
	if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
		wol->wolopts |= WAKE_BCAST;
	if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
		wol->wolopts |= WAKE_PHY;
}

static int lbs_ethtool_set_wol(struct net_device *dev,
			       struct ethtool_wolinfo *wol)
{
88
	struct lbs_private *priv = dev->ml_priv;
89 90 91 92

	if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
		return -EOPNOTSUPP;

93
	priv->wol_criteria = 0;
94
	if (wol->wolopts & WAKE_UCAST)
95
		priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
96
	if (wol->wolopts & WAKE_MCAST)
97
		priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
98
	if (wol->wolopts & WAKE_BCAST)
99
		priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
100
	if (wol->wolopts & WAKE_PHY)
101
		priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
102
	if (wol->wolopts == 0)
103 104
		priv->wol_criteria |= EHS_REMOVE_WAKEUP;
	return 0;
105 106
}

107
const struct ethtool_ops lbs_ethtool_ops = {
108 109 110
	.get_drvinfo = lbs_ethtool_get_drvinfo,
	.get_eeprom =  lbs_ethtool_get_eeprom,
	.get_eeprom_len = lbs_ethtool_get_eeprom_len,
111
#ifdef CONFIG_LIBERTAS_MESH
112 113 114
	.get_sset_count = lbs_mesh_ethtool_get_sset_count,
	.get_ethtool_stats = lbs_mesh_ethtool_get_stats,
	.get_strings = lbs_mesh_ethtool_get_strings,
115
#endif
116 117
	.get_wol = lbs_ethtool_get_wol,
	.set_wol = lbs_ethtool_set_wol,
118 119
};