Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/net/ehea/ehea_ethtool.c |
| 3 | * |
| 4 | * eHEA ethernet device driver for IBM eServer System p |
| 5 | * |
| 6 | * (C) Copyright IBM Corp. 2006 |
| 7 | * |
| 8 | * Authors: |
| 9 | * Christoph Raisch <raisch@de.ibm.com> |
| 10 | * Jan-Bernd Themann <themann@de.ibm.com> |
| 11 | * Thomas Klein <tklein@de.ibm.com> |
| 12 | * |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
| 17 | * any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 31 | #include "ehea.h" |
| 32 | #include "ehea_phyp.h" |
| 33 | |
| 34 | static int ehea_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 35 | { |
| 36 | struct ehea_port *port = netdev_priv(dev); |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 37 | u32 speed; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 38 | int ret; |
| 39 | |
| 40 | ret = ehea_sense_port_attr(port); |
| 41 | |
| 42 | if (ret) |
| 43 | return ret; |
| 44 | |
| 45 | if (netif_carrier_ok(dev)) { |
Doug Maxey | 13da93d | 2008-01-31 20:20:48 -0600 | [diff] [blame] | 46 | switch (port->port_speed) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 47 | case EHEA_SPEED_10M: |
| 48 | speed = SPEED_10; |
| 49 | break; |
| 50 | case EHEA_SPEED_100M: |
| 51 | speed = SPEED_100; |
| 52 | break; |
| 53 | case EHEA_SPEED_1G: |
| 54 | speed = SPEED_1000; |
| 55 | break; |
| 56 | case EHEA_SPEED_10G: |
| 57 | speed = SPEED_10000; |
| 58 | break; |
| 59 | default: |
| 60 | speed = -1; |
| 61 | break; /* BUG */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 62 | } |
| 63 | cmd->duplex = port->full_duplex == 1 ? |
| 64 | DUPLEX_FULL : DUPLEX_HALF; |
| 65 | } else { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 66 | speed = ~0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 67 | cmd->duplex = -1; |
| 68 | } |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 69 | ethtool_cmd_speed_set(cmd, speed); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 70 | |
Kleber Sacilotto de Souza | dcbe14b | 2011-05-04 13:05:11 +0000 | [diff] [blame] | 71 | if (cmd->speed == SPEED_10000) { |
| 72 | cmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); |
| 73 | cmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); |
| 74 | cmd->port = PORT_FIBRE; |
| 75 | } else { |
| 76 | cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_100baseT_Full |
| 77 | | SUPPORTED_100baseT_Half | SUPPORTED_10baseT_Full |
| 78 | | SUPPORTED_10baseT_Half | SUPPORTED_Autoneg |
| 79 | | SUPPORTED_TP); |
| 80 | cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
| 81 | | ADVERTISED_TP); |
| 82 | cmd->port = PORT_TP; |
| 83 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 84 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 85 | cmd->autoneg = port->autoneg == 1 ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static int ehea_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 91 | { |
| 92 | struct ehea_port *port = netdev_priv(dev); |
| 93 | int ret = 0; |
| 94 | u32 sp; |
| 95 | |
| 96 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 97 | sp = EHEA_SPEED_AUTONEG; |
| 98 | goto doit; |
| 99 | } |
| 100 | |
Doug Maxey | 13da93d | 2008-01-31 20:20:48 -0600 | [diff] [blame] | 101 | switch (cmd->speed) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 102 | case SPEED_10: |
| 103 | if (cmd->duplex == DUPLEX_FULL) |
| 104 | sp = H_SPEED_10M_F; |
| 105 | else |
| 106 | sp = H_SPEED_10M_H; |
| 107 | break; |
| 108 | |
| 109 | case SPEED_100: |
| 110 | if (cmd->duplex == DUPLEX_FULL) |
| 111 | sp = H_SPEED_100M_F; |
| 112 | else |
| 113 | sp = H_SPEED_100M_H; |
| 114 | break; |
| 115 | |
| 116 | case SPEED_1000: |
| 117 | if (cmd->duplex == DUPLEX_FULL) |
| 118 | sp = H_SPEED_1G_F; |
| 119 | else |
| 120 | ret = -EINVAL; |
| 121 | break; |
| 122 | |
| 123 | case SPEED_10000: |
| 124 | if (cmd->duplex == DUPLEX_FULL) |
| 125 | sp = H_SPEED_10G_F; |
| 126 | else |
| 127 | ret = -EINVAL; |
| 128 | break; |
| 129 | |
| 130 | default: |
| 131 | ret = -EINVAL; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | if (ret) |
| 136 | goto out; |
| 137 | doit: |
| 138 | ret = ehea_set_portspeed(port, sp); |
| 139 | |
| 140 | if (!ret) |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 141 | netdev_info(dev, |
| 142 | "Port speed successfully set: %dMbps %s Duplex\n", |
| 143 | port->port_speed, |
| 144 | port->full_duplex == 1 ? "Full" : "Half"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 145 | out: |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | static int ehea_nway_reset(struct net_device *dev) |
| 150 | { |
| 151 | struct ehea_port *port = netdev_priv(dev); |
| 152 | int ret; |
| 153 | |
| 154 | ret = ehea_set_portspeed(port, EHEA_SPEED_AUTONEG); |
| 155 | |
| 156 | if (!ret) |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 157 | netdev_info(port->netdev, |
| 158 | "Port speed successfully set: %dMbps %s Duplex\n", |
| 159 | port->port_speed, |
| 160 | port->full_duplex == 1 ? "Full" : "Half"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | static void ehea_get_drvinfo(struct net_device *dev, |
| 165 | struct ethtool_drvinfo *info) |
| 166 | { |
Jean Delvare | 4eccccb | 2007-03-26 21:47:22 -0800 | [diff] [blame] | 167 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
| 168 | strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static u32 ehea_get_msglevel(struct net_device *dev) |
| 172 | { |
| 173 | struct ehea_port *port = netdev_priv(dev); |
| 174 | return port->msg_enable; |
| 175 | } |
| 176 | |
| 177 | static void ehea_set_msglevel(struct net_device *dev, u32 value) |
| 178 | { |
| 179 | struct ehea_port *port = netdev_priv(dev); |
| 180 | port->msg_enable = value; |
| 181 | } |
| 182 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 183 | static char ehea_ethtool_stats_keys[][ETH_GSTRING_LEN] = { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 184 | {"sig_comp_iv"}, |
| 185 | {"swqe_refill_th"}, |
| 186 | {"port resets"}, |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 187 | {"Receive errors"}, |
| 188 | {"TCP cksum errors"}, |
| 189 | {"IP cksum errors"}, |
| 190 | {"Frame cksum errors"}, |
| 191 | {"num SQ stopped"}, |
| 192 | {"SQ stopped"}, |
| 193 | {"PR0 free_swqes"}, |
| 194 | {"PR1 free_swqes"}, |
| 195 | {"PR2 free_swqes"}, |
| 196 | {"PR3 free_swqes"}, |
| 197 | {"PR4 free_swqes"}, |
| 198 | {"PR5 free_swqes"}, |
| 199 | {"PR6 free_swqes"}, |
| 200 | {"PR7 free_swqes"}, |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 201 | {"LRO aggregated"}, |
| 202 | {"LRO flushed"}, |
| 203 | {"LRO no_desc"}, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | static void ehea_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 207 | { |
| 208 | if (stringset == ETH_SS_STATS) { |
| 209 | memcpy(data, &ehea_ethtool_stats_keys, |
| 210 | sizeof(ehea_ethtool_stats_keys)); |
| 211 | } |
| 212 | } |
| 213 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 214 | static int ehea_get_sset_count(struct net_device *dev, int sset) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 215 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 216 | switch (sset) { |
| 217 | case ETH_SS_STATS: |
| 218 | return ARRAY_SIZE(ehea_ethtool_stats_keys); |
| 219 | default: |
| 220 | return -EOPNOTSUPP; |
| 221 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void ehea_get_ethtool_stats(struct net_device *dev, |
| 225 | struct ethtool_stats *stats, u64 *data) |
| 226 | { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 227 | int i, k, tmp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 228 | struct ehea_port *port = netdev_priv(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 229 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 230 | for (i = 0; i < ehea_get_sset_count(dev, ETH_SS_STATS); i++) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 231 | data[i] = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 232 | i = 0; |
| 233 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 234 | data[i++] = port->sig_comp_iv; |
| 235 | data[i++] = port->port_res[0].swqe_refill_th; |
| 236 | data[i++] = port->resets; |
| 237 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 238 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 239 | tmp += port->port_res[k].p_stats.poll_receive_errors; |
| 240 | data[i++] = tmp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 241 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 242 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 243 | tmp += port->port_res[k].p_stats.err_tcp_cksum; |
| 244 | data[i++] = tmp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 245 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 246 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 247 | tmp += port->port_res[k].p_stats.err_ip_cksum; |
| 248 | data[i++] = tmp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 249 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 250 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 251 | tmp += port->port_res[k].p_stats.err_frame_crc; |
| 252 | data[i++] = tmp; |
| 253 | |
| 254 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 255 | tmp += port->port_res[k].p_stats.queue_stopped; |
| 256 | data[i++] = tmp; |
| 257 | |
| 258 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 259 | tmp |= port->port_res[k].queue_stopped; |
| 260 | data[i++] = tmp; |
| 261 | |
| 262 | for (k = 0; k < 8; k++) |
| 263 | data[i++] = atomic_read(&port->port_res[k].swqe_avail); |
| 264 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 265 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 266 | tmp |= port->port_res[k].lro_mgr.stats.aggregated; |
| 267 | data[i++] = tmp; |
| 268 | |
| 269 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 270 | tmp |= port->port_res[k].lro_mgr.stats.flushed; |
| 271 | data[i++] = tmp; |
| 272 | |
| 273 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) |
| 274 | tmp |= port->port_res[k].lro_mgr.stats.no_desc; |
| 275 | data[i++] = tmp; |
| 276 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 279 | const struct ethtool_ops ehea_ethtool_ops = { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 280 | .get_settings = ehea_get_settings, |
| 281 | .get_drvinfo = ehea_get_drvinfo, |
| 282 | .get_msglevel = ehea_get_msglevel, |
| 283 | .set_msglevel = ehea_set_msglevel, |
| 284 | .get_link = ethtool_op_get_link, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 285 | .get_strings = ehea_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 286 | .get_sset_count = ehea_get_sset_count, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 287 | .get_ethtool_stats = ehea_get_ethtool_stats, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 288 | .set_settings = ehea_set_settings, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 289 | .nway_reset = ehea_nway_reset, /* Restart autonegotiation */ |
| 290 | }; |
| 291 | |
| 292 | void ehea_set_ethtool_ops(struct net_device *netdev) |
| 293 | { |
| 294 | SET_ETHTOOL_OPS(netdev, &ehea_ethtool_ops); |
| 295 | } |