blob: 63d020374c2bda16b4176c7e5996628de2e7fedc [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001#include <linux/netdevice.h>
2#include <linux/ethtool.h>
3#include <linux/delay.h>
4
5#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include "decl.h"
7#include "defs.h"
8#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include "wext.h"
David Woodhouse506e9022007-12-12 20:06:06 -050010#include "cmd.h"
Holger Schurigc7fe64c2009-11-25 13:10:49 +010011#include "mesh.h"
David Woodhouse506e9022007-12-12 20:06:06 -050012
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
Holger Schurig10078322007-11-15 18:05:47 -050014static void lbs_ethtool_get_drvinfo(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015 struct ethtool_drvinfo *info)
16{
Kiran Divekarab65f642009-02-19 19:32:39 -050017 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018
Holger Schurigfb14a7e2008-04-02 18:04:35 +020019 snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
20 priv->fwrelease >> 24 & 0xff,
21 priv->fwrelease >> 16 & 0xff,
22 priv->fwrelease >> 8 & 0xff,
23 priv->fwrelease & 0xff);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024 strcpy(info->driver, "libertas");
Holger Schurig10078322007-11-15 18:05:47 -050025 strcpy(info->version, lbs_driver_version);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026}
27
28/* All 8388 parts have 16KiB EEPROM size at the time of writing.
29 * In case that changes this needs fixing.
30 */
Holger Schurig10078322007-11-15 18:05:47 -050031#define LBS_EEPROM_LEN 16384
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020032
Holger Schurig10078322007-11-15 18:05:47 -050033static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020034{
Holger Schurig10078322007-11-15 18:05:47 -050035 return LBS_EEPROM_LEN;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020036}
37
Holger Schurig10078322007-11-15 18:05:47 -050038static int lbs_ethtool_get_eeprom(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039 struct ethtool_eeprom *eeprom, u8 * bytes)
40{
Kiran Divekarab65f642009-02-19 19:32:39 -050041 struct lbs_private *priv = dev->ml_priv;
Holger Schurig7460f5a2008-03-26 10:03:48 +010042 struct cmd_ds_802_11_eeprom_access cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020043 int ret;
44
Holger Schurig7460f5a2008-03-26 10:03:48 +010045 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046
Holger Schurig7460f5a2008-03-26 10:03:48 +010047 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
48 eeprom->len > LBS_EEPROM_READ_LEN) {
49 ret = -EINVAL;
50 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 }
52
Holger Schurig7460f5a2008-03-26 10:03:48 +010053 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
54 LBS_EEPROM_READ_LEN + eeprom->len);
55 cmd.action = cpu_to_le16(CMD_ACT_GET);
56 cmd.offset = cpu_to_le16(eeprom->offset);
57 cmd.len = cpu_to_le16(eeprom->len);
58 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
59 if (!ret)
60 memcpy(bytes, cmd.value, eeprom->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061
Holger Schurig7460f5a2008-03-26 10:03:48 +010062out:
63 lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -040064 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065}
66
David Woodhouse506e9022007-12-12 20:06:06 -050067static void lbs_ethtool_get_wol(struct net_device *dev,
68 struct ethtool_wolinfo *wol)
69{
Kiran Divekarab65f642009-02-19 19:32:39 -050070 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050071
72 if (priv->wol_criteria == 0xffffffff) {
73 /* Interface driver didn't configure wake */
74 wol->supported = wol->wolopts = 0;
75 return;
76 }
77
78 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
79
80 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
81 wol->wolopts |= WAKE_UCAST;
82 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
83 wol->wolopts |= WAKE_MCAST;
84 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
85 wol->wolopts |= WAKE_BCAST;
86 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
87 wol->wolopts |= WAKE_PHY;
88}
89
90static int lbs_ethtool_set_wol(struct net_device *dev,
91 struct ethtool_wolinfo *wol)
92{
Kiran Divekarab65f642009-02-19 19:32:39 -050093 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050094 uint32_t criteria = 0;
95
David Woodhouse506e9022007-12-12 20:06:06 -050096 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
97 return -EOPNOTSUPP;
98
Bing Zhao866d4702009-11-09 18:04:12 -080099 if (wol->wolopts & WAKE_UCAST)
100 criteria |= EHS_WAKE_ON_UNICAST_DATA;
101 if (wol->wolopts & WAKE_MCAST)
102 criteria |= EHS_WAKE_ON_MULTICAST_DATA;
103 if (wol->wolopts & WAKE_BCAST)
104 criteria |= EHS_WAKE_ON_BROADCAST_DATA;
105 if (wol->wolopts & WAKE_PHY)
106 criteria |= EHS_WAKE_ON_MAC_EVENT;
Bing Zhaoc3b866a2009-11-09 18:04:13 -0800107 if (wol->wolopts == 0)
108 criteria |= EHS_REMOVE_WAKEUP;
David Woodhouse506e9022007-12-12 20:06:06 -0500109
Anna Neal582c1b52008-10-20 16:46:56 -0700110 return lbs_host_sleep_cfg(priv, criteria, (struct wol_config *)NULL);
David Woodhouse506e9022007-12-12 20:06:06 -0500111}
112
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700113const struct ethtool_ops lbs_ethtool_ops = {
Holger Schurig10078322007-11-15 18:05:47 -0500114 .get_drvinfo = lbs_ethtool_get_drvinfo,
115 .get_eeprom = lbs_ethtool_get_eeprom,
116 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
Holger Schurigc7fe64c2009-11-25 13:10:49 +0100117 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
118 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
119 .get_strings = lbs_mesh_ethtool_get_strings,
David Woodhouse506e9022007-12-12 20:06:06 -0500120 .get_wol = lbs_ethtool_get_wol,
121 .set_wol = lbs_ethtool_set_wol,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122};
123