Linux Audio

Check our new training course

Loading...
Note: File does not exist in v4.17.
  1#include <linux/hardirq.h>
  2#include <linux/netdevice.h>
  3#include <linux/ethtool.h>
  4#include <linux/delay.h>
  5
  6#include "decl.h"
  7#include "cmd.h"
  8
  9
 10static void lbs_ethtool_get_drvinfo(struct net_device *dev,
 11					 struct ethtool_drvinfo *info)
 12{
 13	struct lbs_private *priv = dev->ml_priv;
 14
 15	snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
 16		priv->fwrelease >> 24 & 0xff,
 17		priv->fwrelease >> 16 & 0xff,
 18		priv->fwrelease >>  8 & 0xff,
 19		priv->fwrelease       & 0xff);
 20	strcpy(info->driver, "libertas");
 21	strcpy(info->version, lbs_driver_version);
 22}
 23
 24/*
 25 * All 8388 parts have 16KiB EEPROM size at the time of writing.
 26 * In case that changes this needs fixing.
 27 */
 28#define LBS_EEPROM_LEN 16384
 29
 30static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
 31{
 32	return LBS_EEPROM_LEN;
 33}
 34
 35static int lbs_ethtool_get_eeprom(struct net_device *dev,
 36                                  struct ethtool_eeprom *eeprom, u8 * bytes)
 37{
 38	struct lbs_private *priv = dev->ml_priv;
 39	struct cmd_ds_802_11_eeprom_access cmd;
 40	int ret;
 41
 42	lbs_deb_enter(LBS_DEB_ETHTOOL);
 43
 44	if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
 45	    eeprom->len > LBS_EEPROM_READ_LEN) {
 46		ret = -EINVAL;
 47		goto out;
 48	}
 49
 50	cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
 51		LBS_EEPROM_READ_LEN + eeprom->len);
 52	cmd.action = cpu_to_le16(CMD_ACT_GET);
 53	cmd.offset = cpu_to_le16(eeprom->offset);
 54	cmd.len    = cpu_to_le16(eeprom->len);
 55	ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
 56	if (!ret)
 57		memcpy(bytes, cmd.value, eeprom->len);
 58
 59out:
 60	lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
 61        return ret;
 62}
 63
 64static void lbs_ethtool_get_wol(struct net_device *dev,
 65				struct ethtool_wolinfo *wol)
 66{
 67	struct lbs_private *priv = dev->ml_priv;
 68
 69	wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
 70
 71	if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
 72		return;
 73
 74	if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
 75		wol->wolopts |= WAKE_UCAST;
 76	if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
 77		wol->wolopts |= WAKE_MCAST;
 78	if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
 79		wol->wolopts |= WAKE_BCAST;
 80	if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
 81		wol->wolopts |= WAKE_PHY;
 82}
 83
 84static int lbs_ethtool_set_wol(struct net_device *dev,
 85			       struct ethtool_wolinfo *wol)
 86{
 87	struct lbs_private *priv = dev->ml_priv;
 88
 89	if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
 90		return -EOPNOTSUPP;
 91
 92	priv->wol_criteria = 0;
 93	if (wol->wolopts & WAKE_UCAST)
 94		priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
 95	if (wol->wolopts & WAKE_MCAST)
 96		priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
 97	if (wol->wolopts & WAKE_BCAST)
 98		priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
 99	if (wol->wolopts & WAKE_PHY)
100		priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
101	if (wol->wolopts == 0)
102		priv->wol_criteria |= EHS_REMOVE_WAKEUP;
103	return 0;
104}
105
106const struct ethtool_ops lbs_ethtool_ops = {
107	.get_drvinfo = lbs_ethtool_get_drvinfo,
108	.get_eeprom =  lbs_ethtool_get_eeprom,
109	.get_eeprom_len = lbs_ethtool_get_eeprom_len,
110#ifdef CONFIG_LIBERTAS_MESH
111	.get_sset_count = lbs_mesh_ethtool_get_sset_count,
112	.get_ethtool_stats = lbs_mesh_ethtool_get_stats,
113	.get_strings = lbs_mesh_ethtool_get_strings,
114#endif
115	.get_wol = lbs_ethtool_get_wol,
116	.set_wol = lbs_ethtool_set_wol,
117};
118