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" |
| 11 | static const char * mesh_stat_strings[]= { |
| 12 | "drop_duplicate_bcast", |
| 13 | "drop_ttl_zero", |
| 14 | "drop_no_fwd_route", |
| 15 | "drop_no_buffers", |
| 16 | "fwded_unicast_cnt", |
| 17 | "fwded_bcast_cnt", |
Javier Cardona | 0601e7e | 2007-05-25 12:12:06 -0400 | [diff] [blame] | 18 | "drop_blind_table", |
| 19 | "tx_failed_cnt" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | }; |
| 21 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 22 | static void lbs_ethtool_get_drvinfo(struct net_device *dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 23 | struct ethtool_drvinfo *info) |
| 24 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame^] | 25 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 26 | char fwver[32]; |
| 27 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 28 | lbs_get_fwversion(priv->adapter, fwver, sizeof(fwver) - 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 29 | |
| 30 | strcpy(info->driver, "libertas"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 31 | strcpy(info->version, lbs_driver_version); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 32 | strcpy(info->fw_version, fwver); |
| 33 | } |
| 34 | |
| 35 | /* All 8388 parts have 16KiB EEPROM size at the time of writing. |
| 36 | * In case that changes this needs fixing. |
| 37 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 38 | #define LBS_EEPROM_LEN 16384 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 39 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 40 | static int lbs_ethtool_get_eeprom_len(struct net_device *dev) |
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 | return LBS_EEPROM_LEN; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 43 | } |
| 44 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 45 | static int lbs_ethtool_get_eeprom(struct net_device *dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | struct ethtool_eeprom *eeprom, u8 * bytes) |
| 47 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame^] | 48 | struct lbs_private *priv = (struct lbs_private *) dev->priv; |
| 49 | struct lbs_adapter *adapter = priv->adapter; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 50 | struct lbs_ioctl_regrdwr regctrl; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 51 | char *ptr; |
| 52 | int ret; |
| 53 | |
| 54 | regctrl.action = 0; |
| 55 | regctrl.offset = eeprom->offset; |
| 56 | regctrl.NOB = eeprom->len; |
| 57 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 58 | if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | |
| 61 | // mutex_lock(&priv->mutex); |
| 62 | |
Jesper Juhl | 655b4d1 | 2007-08-24 11:48:16 -0400 | [diff] [blame] | 63 | adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 64 | if (!adapter->prdeeprom) |
| 65 | return -ENOMEM; |
| 66 | memcpy(adapter->prdeeprom, ®ctrl, sizeof(regctrl)); |
| 67 | |
| 68 | /* +14 is for action, offset, and NOB in |
| 69 | * response */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 70 | lbs_deb_ethtool("action:%d offset: %x NOB: %02x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | regctrl.action, regctrl.offset, regctrl.NOB); |
| 72 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 73 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 74 | CMD_802_11_EEPROM_ACCESS, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | regctrl.action, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 76 | CMD_OPTION_WAITFORRSP, 0, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 77 | ®ctrl); |
| 78 | |
| 79 | if (ret) { |
| 80 | if (adapter->prdeeprom) |
| 81 | kfree(adapter->prdeeprom); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 82 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | mdelay(10); |
| 86 | |
| 87 | ptr = (char *)adapter->prdeeprom; |
| 88 | |
| 89 | /* skip the command header, but include the "value" u32 variable */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 90 | ptr = ptr + sizeof(struct lbs_ioctl_regrdwr) - 4; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * Return the result back to the user |
| 94 | */ |
| 95 | memcpy(bytes, ptr, eeprom->len); |
| 96 | |
| 97 | if (adapter->prdeeprom) |
| 98 | kfree(adapter->prdeeprom); |
| 99 | // mutex_unlock(&priv->mutex); |
| 100 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 101 | ret = 0; |
| 102 | |
| 103 | done: |
| 104 | lbs_deb_enter_args(LBS_DEB_ETHTOOL, "ret %d", ret); |
| 105 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 106 | } |
| 107 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 108 | static void lbs_ethtool_get_stats(struct net_device * dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 109 | struct ethtool_stats * stats, u64 * data) |
| 110 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame^] | 111 | struct lbs_private *priv = dev->priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 112 | struct cmd_ds_mesh_access mesh_access; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 113 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 114 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 115 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 116 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | /* Get Mesh Statistics */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 118 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 119 | CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS, |
| 120 | CMD_OPTION_WAITFORRSP, 0, &mesh_access); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 121 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 122 | if (ret) |
| 123 | return; |
| 124 | |
| 125 | priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]); |
| 126 | priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]); |
| 127 | priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]); |
| 128 | priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]); |
| 129 | priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]); |
| 130 | priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]); |
| 131 | priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]); |
| 132 | priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]); |
| 133 | |
| 134 | data[0] = priv->mstats.fwd_drop_rbt; |
| 135 | data[1] = priv->mstats.fwd_drop_ttl; |
| 136 | data[2] = priv->mstats.fwd_drop_noroute; |
| 137 | data[3] = priv->mstats.fwd_drop_nobuf; |
| 138 | data[4] = priv->mstats.fwd_unicast_cnt; |
| 139 | data[5] = priv->mstats.fwd_bcast_cnt; |
| 140 | data[6] = priv->mstats.drop_blind; |
| 141 | data[7] = priv->mstats.tx_failed_cnt; |
| 142 | |
| 143 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 144 | } |
| 145 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 146 | 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] | 147 | { |
| 148 | switch (sset) { |
| 149 | case ETH_SS_STATS: |
| 150 | return MESH_STATS_NUM; |
| 151 | default: |
| 152 | return -EOPNOTSUPP; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 153 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | } |
| 155 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 156 | static void lbs_ethtool_get_strings(struct net_device *dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 157 | u32 stringset, |
| 158 | u8 * s) |
| 159 | { |
| 160 | int i; |
| 161 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 162 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 163 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 164 | switch (stringset) { |
| 165 | case ETH_SS_STATS: |
| 166 | for (i=0; i < MESH_STATS_NUM; i++) { |
| 167 | memcpy(s + i * ETH_GSTRING_LEN, |
| 168 | mesh_stat_strings[i], |
| 169 | ETH_GSTRING_LEN); |
| 170 | } |
| 171 | break; |
| 172 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 173 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 174 | } |
| 175 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 176 | struct ethtool_ops lbs_ethtool_ops = { |
| 177 | .get_drvinfo = lbs_ethtool_get_drvinfo, |
| 178 | .get_eeprom = lbs_ethtool_get_eeprom, |
| 179 | .get_eeprom_len = lbs_ethtool_get_eeprom_len, |
| 180 | .get_sset_count = lbs_ethtool_get_sset_count, |
| 181 | .get_ethtool_stats = lbs_ethtool_get_stats, |
| 182 | .get_strings = lbs_ethtool_get_strings, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 183 | }; |
| 184 | |