0001
0002 #include <linux/hardirq.h>
0003 #include <linux/netdevice.h>
0004 #include <linux/ethtool.h>
0005 #include <linux/delay.h>
0006
0007 #include "decl.h"
0008 #include "cmd.h"
0009 #include "mesh.h"
0010
0011
0012 static void lbs_ethtool_get_drvinfo(struct net_device *dev,
0013 struct ethtool_drvinfo *info)
0014 {
0015 struct lbs_private *priv = dev->ml_priv;
0016
0017 snprintf(info->fw_version, sizeof(info->fw_version),
0018 "%u.%u.%u.p%u",
0019 priv->fwrelease >> 24 & 0xff,
0020 priv->fwrelease >> 16 & 0xff,
0021 priv->fwrelease >> 8 & 0xff,
0022 priv->fwrelease & 0xff);
0023 strlcpy(info->driver, "libertas", sizeof(info->driver));
0024 strlcpy(info->version, lbs_driver_version, sizeof(info->version));
0025 }
0026
0027
0028
0029
0030
0031 #define LBS_EEPROM_LEN 16384
0032
0033 static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
0034 {
0035 return LBS_EEPROM_LEN;
0036 }
0037
0038 static int lbs_ethtool_get_eeprom(struct net_device *dev,
0039 struct ethtool_eeprom *eeprom, u8 * bytes)
0040 {
0041 struct lbs_private *priv = dev->ml_priv;
0042 struct cmd_ds_802_11_eeprom_access cmd;
0043 int ret;
0044
0045 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
0046 eeprom->len > LBS_EEPROM_READ_LEN)
0047 return -EINVAL;
0048
0049 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
0050 LBS_EEPROM_READ_LEN + eeprom->len);
0051 cmd.action = cpu_to_le16(CMD_ACT_GET);
0052 cmd.offset = cpu_to_le16(eeprom->offset);
0053 cmd.len = cpu_to_le16(eeprom->len);
0054 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
0055 if (!ret)
0056 memcpy(bytes, cmd.value, eeprom->len);
0057
0058 return ret;
0059 }
0060
0061 static void lbs_ethtool_get_wol(struct net_device *dev,
0062 struct ethtool_wolinfo *wol)
0063 {
0064 struct lbs_private *priv = dev->ml_priv;
0065
0066 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
0067
0068 if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
0069 return;
0070
0071 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
0072 wol->wolopts |= WAKE_UCAST;
0073 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
0074 wol->wolopts |= WAKE_MCAST;
0075 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
0076 wol->wolopts |= WAKE_BCAST;
0077 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
0078 wol->wolopts |= WAKE_PHY;
0079 }
0080
0081 static int lbs_ethtool_set_wol(struct net_device *dev,
0082 struct ethtool_wolinfo *wol)
0083 {
0084 struct lbs_private *priv = dev->ml_priv;
0085
0086 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
0087 return -EOPNOTSUPP;
0088
0089 priv->wol_criteria = 0;
0090 if (wol->wolopts & WAKE_UCAST)
0091 priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
0092 if (wol->wolopts & WAKE_MCAST)
0093 priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
0094 if (wol->wolopts & WAKE_BCAST)
0095 priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
0096 if (wol->wolopts & WAKE_PHY)
0097 priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
0098 if (wol->wolopts == 0)
0099 priv->wol_criteria |= EHS_REMOVE_WAKEUP;
0100 return 0;
0101 }
0102
0103 const struct ethtool_ops lbs_ethtool_ops = {
0104 .get_drvinfo = lbs_ethtool_get_drvinfo,
0105 .get_eeprom = lbs_ethtool_get_eeprom,
0106 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
0107 #ifdef CONFIG_LIBERTAS_MESH
0108 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
0109 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
0110 .get_strings = lbs_mesh_ethtool_get_strings,
0111 #endif
0112 .get_wol = lbs_ethtool_get_wol,
0113 .set_wol = lbs_ethtool_set_wol,
0114 };
0115