blob: 50193aac679e81b5c0a157e933db006958fa4463 [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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02005#include "decl.h"
David Woodhouse506e9022007-12-12 20:06:06 -05006#include "cmd.h"
7
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008
Holger Schurig10078322007-11-15 18:05:47 -05009static void lbs_ethtool_get_drvinfo(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010 struct ethtool_drvinfo *info)
11{
Kiran Divekarab65f642009-02-19 19:32:39 -050012 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
Holger Schurigfb14a7e2008-04-02 18:04:35 +020014 snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
15 priv->fwrelease >> 24 & 0xff,
16 priv->fwrelease >> 16 & 0xff,
17 priv->fwrelease >> 8 & 0xff,
18 priv->fwrelease & 0xff);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019 strcpy(info->driver, "libertas");
Holger Schurig10078322007-11-15 18:05:47 -050020 strcpy(info->version, lbs_driver_version);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021}
22
23/* All 8388 parts have 16KiB EEPROM size at the time of writing.
24 * In case that changes this needs fixing.
25 */
Holger Schurig10078322007-11-15 18:05:47 -050026#define LBS_EEPROM_LEN 16384
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027
Holger Schurig10078322007-11-15 18:05:47 -050028static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029{
Holger Schurig10078322007-11-15 18:05:47 -050030 return LBS_EEPROM_LEN;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020031}
32
Holger Schurig10078322007-11-15 18:05:47 -050033static int lbs_ethtool_get_eeprom(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020034 struct ethtool_eeprom *eeprom, u8 * bytes)
35{
Kiran Divekarab65f642009-02-19 19:32:39 -050036 struct lbs_private *priv = dev->ml_priv;
Holger Schurig7460f5a2008-03-26 10:03:48 +010037 struct cmd_ds_802_11_eeprom_access cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020038 int ret;
39
Holger Schurig7460f5a2008-03-26 10:03:48 +010040 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041
Holger Schurig7460f5a2008-03-26 10:03:48 +010042 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
43 eeprom->len > LBS_EEPROM_READ_LEN) {
44 ret = -EINVAL;
45 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 }
47
Holger Schurig7460f5a2008-03-26 10:03:48 +010048 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
49 LBS_EEPROM_READ_LEN + eeprom->len);
50 cmd.action = cpu_to_le16(CMD_ACT_GET);
51 cmd.offset = cpu_to_le16(eeprom->offset);
52 cmd.len = cpu_to_le16(eeprom->len);
53 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
54 if (!ret)
55 memcpy(bytes, cmd.value, eeprom->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020056
Holger Schurig7460f5a2008-03-26 10:03:48 +010057out:
58 lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -040059 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060}
61
David Woodhouse506e9022007-12-12 20:06:06 -050062static void lbs_ethtool_get_wol(struct net_device *dev,
63 struct ethtool_wolinfo *wol)
64{
Kiran Divekarab65f642009-02-19 19:32:39 -050065 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050066
David Woodhouse506e9022007-12-12 20:06:06 -050067 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
68
Sascha Silbe84efa0e2010-06-05 13:30:12 +020069 if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
70 return;
71
David Woodhouse506e9022007-12-12 20:06:06 -050072 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
73 wol->wolopts |= WAKE_UCAST;
74 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
75 wol->wolopts |= WAKE_MCAST;
76 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
77 wol->wolopts |= WAKE_BCAST;
78 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
79 wol->wolopts |= WAKE_PHY;
80}
81
82static int lbs_ethtool_set_wol(struct net_device *dev,
83 struct ethtool_wolinfo *wol)
84{
Kiran Divekarab65f642009-02-19 19:32:39 -050085 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050086
David Woodhouse506e9022007-12-12 20:06:06 -050087 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
88 return -EOPNOTSUPP;
89
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070090 priv->wol_criteria = 0;
Bing Zhao866d4702009-11-09 18:04:12 -080091 if (wol->wolopts & WAKE_UCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070092 priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -080093 if (wol->wolopts & WAKE_MCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070094 priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -080095 if (wol->wolopts & WAKE_BCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070096 priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -080097 if (wol->wolopts & WAKE_PHY)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070098 priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
Bing Zhaoc3b866a2009-11-09 18:04:13 -080099 if (wol->wolopts == 0)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700100 priv->wol_criteria |= EHS_REMOVE_WAKEUP;
101 return 0;
David Woodhouse506e9022007-12-12 20:06:06 -0500102}
103
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700104const struct ethtool_ops lbs_ethtool_ops = {
Holger Schurig10078322007-11-15 18:05:47 -0500105 .get_drvinfo = lbs_ethtool_get_drvinfo,
106 .get_eeprom = lbs_ethtool_get_eeprom,
107 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
Holger Schurig4143a232009-12-02 15:26:02 +0100108#ifdef CONFIG_LIBERTAS_MESH
Holger Schurigc7fe64c2009-11-25 13:10:49 +0100109 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
110 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
111 .get_strings = lbs_mesh_ethtool_get_strings,
Holger Schurig4143a232009-12-02 15:26:02 +0100112#endif
David Woodhouse506e9022007-12-12 20:06:06 -0500113 .get_wol = lbs_ethtool_get_wol,
114 .set_wol = lbs_ethtool_set_wol,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115};
116