blob: f955b2d66ed6e7609836e919678fc8c79d479b4b [file] [log] [blame]
Alexey Dobriyana6b7a402011-06-06 10:43:46 +00001#include <linux/hardirq.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002#include <linux/netdevice.h>
3#include <linux/ethtool.h>
4#include <linux/delay.h>
5
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include "decl.h"
David Woodhouse506e9022007-12-12 20:06:06 -05007#include "cmd.h"
Daniel Drake49fee692011-07-21 20:43:17 +01008#include "mesh.h"
David Woodhouse506e9022007-12-12 20:06:06 -05009
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010
Holger Schurig10078322007-11-15 18:05:47 -050011static void lbs_ethtool_get_drvinfo(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012 struct ethtool_drvinfo *info)
13{
Kiran Divekarab65f642009-02-19 19:32:39 -050014 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015
Rick Jones1f80c232011-11-15 10:40:49 -080016 snprintf(info->fw_version, sizeof(info->fw_version),
17 "%u.%u.%u.p%u",
Holger Schurigfb14a7e2008-04-02 18:04:35 +020018 priv->fwrelease >> 24 & 0xff,
19 priv->fwrelease >> 16 & 0xff,
20 priv->fwrelease >> 8 & 0xff,
21 priv->fwrelease & 0xff);
Rick Jones1f80c232011-11-15 10:40:49 -080022 strlcpy(info->driver, "libertas", sizeof(info->driver));
23 strlcpy(info->version, lbs_driver_version, sizeof(info->version));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024}
25
Randy Dunlap8973a6e2011-04-26 15:25:29 -070026/*
27 * All 8388 parts have 16KiB EEPROM size at the time of writing.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028 * In case that changes this needs fixing.
29 */
Holger Schurig10078322007-11-15 18:05:47 -050030#define LBS_EEPROM_LEN 16384
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020031
Holger Schurig10078322007-11-15 18:05:47 -050032static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020033{
Holger Schurig10078322007-11-15 18:05:47 -050034 return LBS_EEPROM_LEN;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020035}
36
Holger Schurig10078322007-11-15 18:05:47 -050037static int lbs_ethtool_get_eeprom(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020038 struct ethtool_eeprom *eeprom, u8 * bytes)
39{
Kiran Divekarab65f642009-02-19 19:32:39 -050040 struct lbs_private *priv = dev->ml_priv;
Holger Schurig7460f5a2008-03-26 10:03:48 +010041 struct cmd_ds_802_11_eeprom_access cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042 int ret;
43
Holger Schurig7460f5a2008-03-26 10:03:48 +010044 lbs_deb_enter(LBS_DEB_ETHTOOL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
Holger Schurig7460f5a2008-03-26 10:03:48 +010046 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
47 eeprom->len > LBS_EEPROM_READ_LEN) {
48 ret = -EINVAL;
49 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 }
51
Holger Schurig7460f5a2008-03-26 10:03:48 +010052 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
53 LBS_EEPROM_READ_LEN + eeprom->len);
54 cmd.action = cpu_to_le16(CMD_ACT_GET);
55 cmd.offset = cpu_to_le16(eeprom->offset);
56 cmd.len = cpu_to_le16(eeprom->len);
57 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
58 if (!ret)
59 memcpy(bytes, cmd.value, eeprom->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060
Holger Schurig7460f5a2008-03-26 10:03:48 +010061out:
62 lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
Holger Schurig9012b282007-05-25 11:27:16 -040063 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064}
65
David Woodhouse506e9022007-12-12 20:06:06 -050066static void lbs_ethtool_get_wol(struct net_device *dev,
67 struct ethtool_wolinfo *wol)
68{
Kiran Divekarab65f642009-02-19 19:32:39 -050069 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050070
David Woodhouse506e9022007-12-12 20:06:06 -050071 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
72
Sascha Silbe84efa0e2010-06-05 13:30:12 +020073 if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
74 return;
75
David Woodhouse506e9022007-12-12 20:06:06 -050076 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
77 wol->wolopts |= WAKE_UCAST;
78 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
79 wol->wolopts |= WAKE_MCAST;
80 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
81 wol->wolopts |= WAKE_BCAST;
82 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
83 wol->wolopts |= WAKE_PHY;
84}
85
86static int lbs_ethtool_set_wol(struct net_device *dev,
87 struct ethtool_wolinfo *wol)
88{
Kiran Divekarab65f642009-02-19 19:32:39 -050089 struct lbs_private *priv = dev->ml_priv;
David Woodhouse506e9022007-12-12 20:06:06 -050090
David Woodhouse506e9022007-12-12 20:06:06 -050091 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
92 return -EOPNOTSUPP;
93
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070094 priv->wol_criteria = 0;
Bing Zhao866d4702009-11-09 18:04:12 -080095 if (wol->wolopts & WAKE_UCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070096 priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -080097 if (wol->wolopts & WAKE_MCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -070098 priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -080099 if (wol->wolopts & WAKE_BCAST)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700100 priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
Bing Zhao866d4702009-11-09 18:04:12 -0800101 if (wol->wolopts & WAKE_PHY)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700102 priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
Bing Zhaoc3b866a2009-11-09 18:04:13 -0800103 if (wol->wolopts == 0)
Amitkumar Karwar66fceb62010-05-19 03:24:38 -0700104 priv->wol_criteria |= EHS_REMOVE_WAKEUP;
105 return 0;
David Woodhouse506e9022007-12-12 20:06:06 -0500106}
107
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700108const struct ethtool_ops lbs_ethtool_ops = {
Holger Schurig10078322007-11-15 18:05:47 -0500109 .get_drvinfo = lbs_ethtool_get_drvinfo,
110 .get_eeprom = lbs_ethtool_get_eeprom,
111 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
Holger Schurig4143a232009-12-02 15:26:02 +0100112#ifdef CONFIG_LIBERTAS_MESH
Holger Schurigc7fe64c2009-11-25 13:10:49 +0100113 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
114 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
115 .get_strings = lbs_mesh_ethtool_get_strings,
Holger Schurig4143a232009-12-02 15:26:02 +0100116#endif
David Woodhouse506e9022007-12-12 20:06:06 -0500117 .get_wol = lbs_ethtool_get_wol,
118 .set_wol = lbs_ethtool_set_wol,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119};
120