| 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 |  | 
|  | 5 | #include "host.h" | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | #include "decl.h" | 
|  | 7 | #include "defs.h" | 
|  | 8 | #include "dev.h" | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 9 | #include "wext.h" | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 10 | #include "cmd.h" | 
|  | 11 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 12 | static const char * mesh_stat_strings[]= { | 
|  | 13 | "drop_duplicate_bcast", | 
|  | 14 | "drop_ttl_zero", | 
|  | 15 | "drop_no_fwd_route", | 
|  | 16 | "drop_no_buffers", | 
|  | 17 | "fwded_unicast_cnt", | 
|  | 18 | "fwded_bcast_cnt", | 
| Javier Cardona | 0601e7e | 2007-05-25 12:12:06 -0400 | [diff] [blame] | 19 | "drop_blind_table", | 
|  | 20 | "tx_failed_cnt" | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 21 | }; | 
|  | 22 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 23 | static void lbs_ethtool_get_drvinfo(struct net_device *dev, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | struct ethtool_drvinfo *info) | 
|  | 25 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 26 | struct lbs_private *priv = dev->ml_priv; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 |  | 
| Holger Schurig | fb14a7e | 2008-04-02 18:04:35 +0200 | [diff] [blame] | 28 | snprintf(info->fw_version, 32, "%u.%u.%u.p%u", | 
|  | 29 | priv->fwrelease >> 24 & 0xff, | 
|  | 30 | priv->fwrelease >> 16 & 0xff, | 
|  | 31 | priv->fwrelease >>  8 & 0xff, | 
|  | 32 | priv->fwrelease       & 0xff); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 33 | strcpy(info->driver, "libertas"); | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 34 | strcpy(info->version, lbs_driver_version); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
|  | 37 | /* All 8388 parts have 16KiB EEPROM size at the time of writing. | 
|  | 38 | * In case that changes this needs fixing. | 
|  | 39 | */ | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 40 | #define LBS_EEPROM_LEN 16384 | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 41 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 42 | static int lbs_ethtool_get_eeprom_len(struct net_device *dev) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 43 | { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 44 | return LBS_EEPROM_LEN; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 45 | } | 
|  | 46 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 47 | static int lbs_ethtool_get_eeprom(struct net_device *dev, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 48 | struct ethtool_eeprom *eeprom, u8 * bytes) | 
|  | 49 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 50 | struct lbs_private *priv = dev->ml_priv; | 
| Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 51 | struct cmd_ds_802_11_eeprom_access cmd; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 52 | int ret; | 
|  | 53 |  | 
| Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 54 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 55 |  | 
| Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 56 | if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN || | 
|  | 57 | eeprom->len > LBS_EEPROM_READ_LEN) { | 
|  | 58 | ret = -EINVAL; | 
|  | 59 | goto out; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 60 | } | 
|  | 61 |  | 
| Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 62 | cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) - | 
|  | 63 | LBS_EEPROM_READ_LEN + eeprom->len); | 
|  | 64 | cmd.action = cpu_to_le16(CMD_ACT_GET); | 
|  | 65 | cmd.offset = cpu_to_le16(eeprom->offset); | 
|  | 66 | cmd.len    = cpu_to_le16(eeprom->len); | 
|  | 67 | ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd); | 
|  | 68 | if (!ret) | 
|  | 69 | memcpy(bytes, cmd.value, eeprom->len); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 70 |  | 
| Holger Schurig | 7460f5a | 2008-03-26 10:03:48 +0100 | [diff] [blame] | 71 | out: | 
|  | 72 | lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret); | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 73 | return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | } | 
|  | 75 |  | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 76 | static void lbs_ethtool_get_stats(struct net_device *dev, | 
|  | 77 | struct ethtool_stats *stats, uint64_t *data) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 79 | struct lbs_private *priv = dev->ml_priv; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 80 | struct cmd_ds_mesh_access mesh_access; | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 81 | int ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 82 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 83 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 84 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 85 | /* Get Mesh Statistics */ | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 86 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 87 |  | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 88 | if (ret) { | 
|  | 89 | memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t))); | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 90 | return; | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 91 | } | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]); | 
|  | 94 | priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]); | 
|  | 95 | priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]); | 
|  | 96 | priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]); | 
|  | 97 | priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]); | 
|  | 98 | priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]); | 
|  | 99 | priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]); | 
|  | 100 | priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]); | 
|  | 101 |  | 
|  | 102 | data[0] = priv->mstats.fwd_drop_rbt; | 
|  | 103 | data[1] = priv->mstats.fwd_drop_ttl; | 
|  | 104 | data[2] = priv->mstats.fwd_drop_noroute; | 
|  | 105 | data[3] = priv->mstats.fwd_drop_nobuf; | 
|  | 106 | data[4] = priv->mstats.fwd_unicast_cnt; | 
|  | 107 | data[5] = priv->mstats.fwd_bcast_cnt; | 
|  | 108 | data[6] = priv->mstats.drop_blind; | 
|  | 109 | data[7] = priv->mstats.tx_failed_cnt; | 
|  | 110 |  | 
|  | 111 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 112 | } | 
|  | 113 |  | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 114 | static int lbs_ethtool_get_sset_count(struct net_device *dev, int sset) | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 115 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 116 | struct lbs_private *priv = dev->ml_priv; | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 117 |  | 
|  | 118 | if (sset == ETH_SS_STATS && dev == priv->mesh_dev) | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 119 | return MESH_STATS_NUM; | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 120 |  | 
|  | 121 | return -EOPNOTSUPP; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 124 | static void lbs_ethtool_get_strings(struct net_device *dev, | 
| David Woodhouse | 5d283e8 | 2008-05-19 16:32:02 +0100 | [diff] [blame] | 125 | uint32_t stringset, uint8_t *s) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 126 | { | 
|  | 127 | int i; | 
|  | 128 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 129 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 130 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 131 | switch (stringset) { | 
|  | 132 | case ETH_SS_STATS: | 
|  | 133 | for (i=0; i < MESH_STATS_NUM; i++) { | 
|  | 134 | memcpy(s + i * ETH_GSTRING_LEN, | 
|  | 135 | mesh_stat_strings[i], | 
|  | 136 | ETH_GSTRING_LEN); | 
|  | 137 | } | 
|  | 138 | break; | 
|  | 139 | } | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 140 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 143 | static void lbs_ethtool_get_wol(struct net_device *dev, | 
|  | 144 | struct ethtool_wolinfo *wol) | 
|  | 145 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 146 | struct lbs_private *priv = dev->ml_priv; | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 147 |  | 
|  | 148 | if (priv->wol_criteria == 0xffffffff) { | 
|  | 149 | /* Interface driver didn't configure wake */ | 
|  | 150 | wol->supported = wol->wolopts = 0; | 
|  | 151 | return; | 
|  | 152 | } | 
|  | 153 |  | 
|  | 154 | wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY; | 
|  | 155 |  | 
|  | 156 | if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA) | 
|  | 157 | wol->wolopts |= WAKE_UCAST; | 
|  | 158 | if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA) | 
|  | 159 | wol->wolopts |= WAKE_MCAST; | 
|  | 160 | if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA) | 
|  | 161 | wol->wolopts |= WAKE_BCAST; | 
|  | 162 | if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT) | 
|  | 163 | wol->wolopts |= WAKE_PHY; | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | static int lbs_ethtool_set_wol(struct net_device *dev, | 
|  | 167 | struct ethtool_wolinfo *wol) | 
|  | 168 | { | 
| Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 169 | struct lbs_private *priv = dev->ml_priv; | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 170 | uint32_t criteria = 0; | 
|  | 171 |  | 
|  | 172 | if (priv->wol_criteria == 0xffffffff && wol->wolopts) | 
|  | 173 | return -EOPNOTSUPP; | 
|  | 174 |  | 
|  | 175 | if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) | 
|  | 176 | return -EOPNOTSUPP; | 
|  | 177 |  | 
|  | 178 | if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA; | 
|  | 179 | if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA; | 
|  | 180 | if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA; | 
|  | 181 | if (wol->wolopts & WAKE_PHY)   criteria |= EHS_WAKE_ON_MAC_EVENT; | 
|  | 182 |  | 
| Anna Neal | 582c1b5 | 2008-10-20 16:46:56 -0700 | [diff] [blame] | 183 | return lbs_host_sleep_cfg(priv, criteria, (struct wol_config *)NULL); | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 184 | } | 
|  | 185 |  | 
| Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 186 | const struct ethtool_ops lbs_ethtool_ops = { | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 187 | .get_drvinfo = lbs_ethtool_get_drvinfo, | 
|  | 188 | .get_eeprom =  lbs_ethtool_get_eeprom, | 
|  | 189 | .get_eeprom_len = lbs_ethtool_get_eeprom_len, | 
|  | 190 | .get_sset_count = lbs_ethtool_get_sset_count, | 
|  | 191 | .get_ethtool_stats = lbs_ethtool_get_stats, | 
|  | 192 | .get_strings = lbs_ethtool_get_strings, | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 193 | .get_wol = lbs_ethtool_get_wol, | 
|  | 194 | .set_wol = lbs_ethtool_set_wol, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 195 | }; | 
|  | 196 |  |