Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | #include <linux/netdevice.h> |
| 2 | #include <linux/ethtool.h> |
| 3 | #include <linux/delay.h> |
| 4 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 5 | #include "decl.h" |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 6 | #include "cmd.h" |
| 7 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 9 | static void lbs_ethtool_get_drvinfo(struct net_device *dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | struct ethtool_drvinfo *info) |
| 11 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 12 | struct lbs_private *priv = dev->ml_priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | |
Holger Schurig | fb14a7e | 2008-04-02 18:04:35 +0200 | [diff] [blame] | 14 | 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | strcpy(info->driver, "libertas"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 20 | strcpy(info->version, lbs_driver_version); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 21 | } |
| 22 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 23 | /* |
| 24 | * All 8388 parts have 16KiB EEPROM size at the time of writing. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 | * In case that changes this needs fixing. |
| 26 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 27 | #define LBS_EEPROM_LEN 16384 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 28 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 29 | static int lbs_ethtool_get_eeprom_len(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 30 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 31 | return LBS_EEPROM_LEN; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 32 | } |
| 33 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 34 | static int lbs_ethtool_get_eeprom(struct net_device *dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 35 | struct ethtool_eeprom *eeprom, u8 * bytes) |
| 36 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 37 | struct lbs_private *priv = dev->ml_priv; |
Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 38 | struct cmd_ds_802_11_eeprom_access cmd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 39 | int ret; |
| 40 | |
Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 41 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 42 | |
Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 43 | if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN || |
| 44 | eeprom->len > LBS_EEPROM_READ_LEN) { |
| 45 | ret = -EINVAL; |
| 46 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 47 | } |
| 48 | |
Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 49 | cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) - |
| 50 | LBS_EEPROM_READ_LEN + eeprom->len); |
| 51 | cmd.action = cpu_to_le16(CMD_ACT_GET); |
| 52 | cmd.offset = cpu_to_le16(eeprom->offset); |
| 53 | cmd.len = cpu_to_le16(eeprom->len); |
| 54 | ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd); |
| 55 | if (!ret) |
| 56 | memcpy(bytes, cmd.value, eeprom->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 57 | |
Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 58 | out: |
| 59 | lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 60 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 61 | } |
| 62 | |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 63 | static void lbs_ethtool_get_wol(struct net_device *dev, |
| 64 | struct ethtool_wolinfo *wol) |
| 65 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 66 | struct lbs_private *priv = dev->ml_priv; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 67 | |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 68 | wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY; |
| 69 | |
Sascha Silbe | 84efa0e | 2010-06-05 13:30:12 +0200 | [diff] [blame] | 70 | if (priv->wol_criteria == EHS_REMOVE_WAKEUP) |
| 71 | return; |
| 72 | |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 73 | if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA) |
| 74 | wol->wolopts |= WAKE_UCAST; |
| 75 | if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA) |
| 76 | wol->wolopts |= WAKE_MCAST; |
| 77 | if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA) |
| 78 | wol->wolopts |= WAKE_BCAST; |
| 79 | if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT) |
| 80 | wol->wolopts |= WAKE_PHY; |
| 81 | } |
| 82 | |
| 83 | static int lbs_ethtool_set_wol(struct net_device *dev, |
| 84 | struct ethtool_wolinfo *wol) |
| 85 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 86 | struct lbs_private *priv = dev->ml_priv; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 87 | |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 88 | if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) |
| 89 | return -EOPNOTSUPP; |
| 90 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 91 | priv->wol_criteria = 0; |
Bing Zhao | 866d470 | 2009-11-09 18:04:12 -0800 | [diff] [blame] | 92 | if (wol->wolopts & WAKE_UCAST) |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 93 | priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA; |
Bing Zhao | 866d470 | 2009-11-09 18:04:12 -0800 | [diff] [blame] | 94 | if (wol->wolopts & WAKE_MCAST) |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 95 | priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA; |
Bing Zhao | 866d470 | 2009-11-09 18:04:12 -0800 | [diff] [blame] | 96 | if (wol->wolopts & WAKE_BCAST) |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 97 | priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA; |
Bing Zhao | 866d470 | 2009-11-09 18:04:12 -0800 | [diff] [blame] | 98 | if (wol->wolopts & WAKE_PHY) |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 99 | priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT; |
Bing Zhao | c3b866a | 2009-11-09 18:04:13 -0800 | [diff] [blame] | 100 | if (wol->wolopts == 0) |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 101 | priv->wol_criteria |= EHS_REMOVE_WAKEUP; |
| 102 | return 0; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 103 | } |
| 104 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 105 | const struct ethtool_ops lbs_ethtool_ops = { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 106 | .get_drvinfo = lbs_ethtool_get_drvinfo, |
| 107 | .get_eeprom = lbs_ethtool_get_eeprom, |
| 108 | .get_eeprom_len = lbs_ethtool_get_eeprom_len, |
Holger Schurig | 4143a23 | 2009-12-02 15:26:02 +0100 | [diff] [blame] | 109 | #ifdef CONFIG_LIBERTAS_MESH |
Holger Schurig | c7fe64c | 2009-11-25 13:10:49 +0100 | [diff] [blame] | 110 | .get_sset_count = lbs_mesh_ethtool_get_sset_count, |
| 111 | .get_ethtool_stats = lbs_mesh_ethtool_get_stats, |
| 112 | .get_strings = lbs_mesh_ethtool_get_strings, |
Holger Schurig | 4143a23 | 2009-12-02 15:26:02 +0100 | [diff] [blame] | 113 | #endif |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 114 | .get_wol = lbs_ethtool_get_wol, |
| 115 | .set_wol = lbs_ethtool_set_wol, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 116 | }; |
| 117 | |