| 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" | 
|  | 9 | #include "join.h" | 
|  | 10 | #include "wext.h" | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 11 | #include "cmd.h" | 
|  | 12 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | static const char * mesh_stat_strings[]= { | 
|  | 14 | "drop_duplicate_bcast", | 
|  | 15 | "drop_ttl_zero", | 
|  | 16 | "drop_no_fwd_route", | 
|  | 17 | "drop_no_buffers", | 
|  | 18 | "fwded_unicast_cnt", | 
|  | 19 | "fwded_bcast_cnt", | 
| Javier Cardona | 0601e7e | 2007-05-25 12:12:06 -0400 | [diff] [blame] | 20 | "drop_blind_table", | 
|  | 21 | "tx_failed_cnt" | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 22 | }; | 
|  | 23 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 24 | static void lbs_ethtool_get_drvinfo(struct net_device *dev, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 | struct ethtool_drvinfo *info) | 
|  | 26 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 27 | struct lbs_private *priv = (struct lbs_private *) dev->priv; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 28 | char fwver[32]; | 
|  | 29 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 30 | lbs_get_fwversion(priv, fwver, sizeof(fwver) - 1); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 31 |  | 
|  | 32 | strcpy(info->driver, "libertas"); | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 33 | strcpy(info->version, lbs_driver_version); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 34 | strcpy(info->fw_version, fwver); | 
|  | 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 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 50 | struct lbs_private *priv = (struct lbs_private *) dev->priv; | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 51 | struct lbs_ioctl_regrdwr regctrl; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 52 | char *ptr; | 
|  | 53 | int ret; | 
|  | 54 |  | 
|  | 55 | regctrl.action = 0; | 
|  | 56 | regctrl.offset = eeprom->offset; | 
|  | 57 | regctrl.NOB = eeprom->len; | 
|  | 58 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 59 | if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 60 | return -EINVAL; | 
|  | 61 |  | 
|  | 62 | //      mutex_lock(&priv->mutex); | 
|  | 63 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 64 | priv->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL); | 
|  | 65 | if (!priv->prdeeprom) | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 66 | return -ENOMEM; | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 67 | memcpy(priv->prdeeprom, ®ctrl, sizeof(regctrl)); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 68 |  | 
|  | 69 | /* +14 is for action, offset, and NOB in | 
|  | 70 | * response */ | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 71 | lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n", | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 72 | regctrl.action, regctrl.offset, regctrl.NOB); | 
|  | 73 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 74 | ret = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 75 | CMD_802_11_EEPROM_ACCESS, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 76 | regctrl.action, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 77 | CMD_OPTION_WAITFORRSP, 0, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | ®ctrl); | 
|  | 79 |  | 
|  | 80 | if (ret) { | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 81 | if (priv->prdeeprom) | 
|  | 82 | kfree(priv->prdeeprom); | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 83 | goto done; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
|  | 86 | mdelay(10); | 
|  | 87 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 88 | ptr = (char *)priv->prdeeprom; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 89 |  | 
|  | 90 | /* skip the command header, but include the "value" u32 variable */ | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 91 | ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 92 |  | 
|  | 93 | /* | 
|  | 94 | * Return the result back to the user | 
|  | 95 | */ | 
|  | 96 | memcpy(bytes, ptr, eeprom->len); | 
|  | 97 |  | 
| David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 98 | if (priv->prdeeprom) | 
|  | 99 | kfree(priv->prdeeprom); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 100 | //	mutex_unlock(&priv->mutex); | 
|  | 101 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 102 | ret = 0; | 
|  | 103 |  | 
|  | 104 | done: | 
|  | 105 | lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret); | 
|  | 106 | return ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 109 | static void lbs_ethtool_get_stats(struct net_device * dev, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 110 | struct ethtool_stats * stats, u64 * data) | 
|  | 111 | { | 
| Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 112 | struct lbs_private *priv = dev->priv; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 113 | struct cmd_ds_mesh_access mesh_access; | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 114 | int ret; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 116 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 117 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 118 | /* Get Mesh Statistics */ | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 119 | ret = lbs_prepare_and_send_command(priv, | 
| Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 120 | CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS, | 
|  | 121 | CMD_OPTION_WAITFORRSP, 0, &mesh_access); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 122 |  | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 123 | if (ret) | 
|  | 124 | return; | 
|  | 125 |  | 
|  | 126 | priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]); | 
|  | 127 | priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]); | 
|  | 128 | priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]); | 
|  | 129 | priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]); | 
|  | 130 | priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]); | 
|  | 131 | priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]); | 
|  | 132 | priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]); | 
|  | 133 | priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]); | 
|  | 134 |  | 
|  | 135 | data[0] = priv->mstats.fwd_drop_rbt; | 
|  | 136 | data[1] = priv->mstats.fwd_drop_ttl; | 
|  | 137 | data[2] = priv->mstats.fwd_drop_noroute; | 
|  | 138 | data[3] = priv->mstats.fwd_drop_nobuf; | 
|  | 139 | data[4] = priv->mstats.fwd_unicast_cnt; | 
|  | 140 | data[5] = priv->mstats.fwd_bcast_cnt; | 
|  | 141 | data[6] = priv->mstats.drop_blind; | 
|  | 142 | data[7] = priv->mstats.tx_failed_cnt; | 
|  | 143 |  | 
|  | 144 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 145 | } | 
|  | 146 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 147 | 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] | 148 | { | 
|  | 149 | switch (sset) { | 
|  | 150 | case ETH_SS_STATS: | 
|  | 151 | return MESH_STATS_NUM; | 
|  | 152 | default: | 
|  | 153 | return -EOPNOTSUPP; | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | } | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 157 | static void lbs_ethtool_get_strings(struct net_device *dev, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 158 | u32 stringset, | 
|  | 159 | u8 * s) | 
|  | 160 | { | 
|  | 161 | int i; | 
|  | 162 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 163 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
|  | 164 |  | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 165 | switch (stringset) { | 
|  | 166 | case ETH_SS_STATS: | 
|  | 167 | for (i=0; i < MESH_STATS_NUM; i++) { | 
|  | 168 | memcpy(s + i * ETH_GSTRING_LEN, | 
|  | 169 | mesh_stat_strings[i], | 
|  | 170 | ETH_GSTRING_LEN); | 
|  | 171 | } | 
|  | 172 | break; | 
|  | 173 | } | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 174 | lbs_deb_enter(LBS_DEB_ETHTOOL); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 175 | } | 
|  | 176 |  | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 177 | static void lbs_ethtool_get_wol(struct net_device *dev, | 
|  | 178 | struct ethtool_wolinfo *wol) | 
|  | 179 | { | 
|  | 180 | struct lbs_private *priv = dev->priv; | 
|  | 181 |  | 
|  | 182 | if (priv->wol_criteria == 0xffffffff) { | 
|  | 183 | /* Interface driver didn't configure wake */ | 
|  | 184 | wol->supported = wol->wolopts = 0; | 
|  | 185 | return; | 
|  | 186 | } | 
|  | 187 |  | 
|  | 188 | wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY; | 
|  | 189 |  | 
|  | 190 | if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA) | 
|  | 191 | wol->wolopts |= WAKE_UCAST; | 
|  | 192 | if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA) | 
|  | 193 | wol->wolopts |= WAKE_MCAST; | 
|  | 194 | if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA) | 
|  | 195 | wol->wolopts |= WAKE_BCAST; | 
|  | 196 | if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT) | 
|  | 197 | wol->wolopts |= WAKE_PHY; | 
|  | 198 | } | 
|  | 199 |  | 
|  | 200 | static int lbs_ethtool_set_wol(struct net_device *dev, | 
|  | 201 | struct ethtool_wolinfo *wol) | 
|  | 202 | { | 
|  | 203 | struct lbs_private *priv = dev->priv; | 
|  | 204 | uint32_t criteria = 0; | 
|  | 205 |  | 
|  | 206 | if (priv->wol_criteria == 0xffffffff && wol->wolopts) | 
|  | 207 | return -EOPNOTSUPP; | 
|  | 208 |  | 
|  | 209 | if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY)) | 
|  | 210 | return -EOPNOTSUPP; | 
|  | 211 |  | 
|  | 212 | if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA; | 
|  | 213 | if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA; | 
|  | 214 | if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA; | 
|  | 215 | if (wol->wolopts & WAKE_PHY)   criteria |= EHS_WAKE_ON_MAC_EVENT; | 
|  | 216 |  | 
|  | 217 | return lbs_host_sleep_cfg(priv, criteria); | 
|  | 218 | } | 
|  | 219 |  | 
| Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 220 | struct ethtool_ops lbs_ethtool_ops = { | 
|  | 221 | .get_drvinfo = lbs_ethtool_get_drvinfo, | 
|  | 222 | .get_eeprom =  lbs_ethtool_get_eeprom, | 
|  | 223 | .get_eeprom_len = lbs_ethtool_get_eeprom_len, | 
|  | 224 | .get_sset_count = lbs_ethtool_get_sset_count, | 
|  | 225 | .get_ethtool_stats = lbs_ethtool_get_stats, | 
|  | 226 | .get_strings = lbs_ethtool_get_strings, | 
| David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 227 | .get_wol = lbs_ethtool_get_wol, | 
|  | 228 | .set_wol = lbs_ethtool_set_wol, | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 229 | }; | 
|  | 230 |  |