Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * ethtool support for netxen nic |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <linux/types.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <asm/io.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/ethtool.h> |
| 40 | #include <linux/version.h> |
| 41 | |
| 42 | #include "netxen_nic_hw.h" |
| 43 | #include "netxen_nic.h" |
| 44 | #include "netxen_nic_phan_reg.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 45 | |
| 46 | struct netxen_nic_stats { |
| 47 | char stat_string[ETH_GSTRING_LEN]; |
| 48 | int sizeof_stat; |
| 49 | int stat_offset; |
| 50 | }; |
| 51 | |
| 52 | #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_port *)0)->m), \ |
| 53 | offsetof(struct netxen_port, m) |
| 54 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 55 | #define NETXEN_NIC_PORT_WINDOW 0x10000 |
| 56 | #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF |
| 57 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 58 | static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = { |
| 59 | {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)}, |
| 60 | {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)}, |
| 61 | {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)}, |
| 62 | {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)}, |
| 63 | {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)}, |
| 64 | {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)}, |
| 65 | {"polled", NETXEN_NIC_STAT(stats.polled)}, |
| 66 | {"uphappy", NETXEN_NIC_STAT(stats.uphappy)}, |
| 67 | {"updropped", NETXEN_NIC_STAT(stats.updropped)}, |
| 68 | {"uplcong", NETXEN_NIC_STAT(stats.uplcong)}, |
| 69 | {"uphcong", NETXEN_NIC_STAT(stats.uphcong)}, |
| 70 | {"upmcong", NETXEN_NIC_STAT(stats.upmcong)}, |
| 71 | {"updunno", NETXEN_NIC_STAT(stats.updunno)}, |
| 72 | {"skb_freed", NETXEN_NIC_STAT(stats.skbfreed)}, |
| 73 | {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)}, |
| 74 | {"tx_null_skb", NETXEN_NIC_STAT(stats.txnullskb)}, |
| 75 | {"csummed", NETXEN_NIC_STAT(stats.csummed)}, |
| 76 | {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)}, |
| 77 | {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)}, |
| 78 | {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, |
| 79 | }; |
| 80 | |
Stephen Hemminger | 92104e9 | 2006-12-15 07:57:08 -0800 | [diff] [blame^] | 81 | #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 82 | |
| 83 | static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { |
| 84 | "Register_Test_offline", "EEPROM_Test_offline", |
| 85 | "Interrupt_Test_offline", "Loopback_Test_offline", |
| 86 | "Link_Test_on_offline" |
| 87 | }; |
| 88 | |
| 89 | #define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN |
| 90 | |
| 91 | #define NETXEN_NIC_REGS_COUNT 42 |
| 92 | #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32)) |
| 93 | #define NETXEN_MAX_EEPROM_LEN 1024 |
| 94 | |
| 95 | static int netxen_nic_get_eeprom_len(struct net_device *dev) |
| 96 | { |
| 97 | struct netxen_port *port = netdev_priv(dev); |
| 98 | struct netxen_adapter *adapter = port->adapter; |
| 99 | int n; |
| 100 | |
| 101 | if ((netxen_rom_fast_read(adapter, 0, &n) == 0) |
| 102 | && (n & NETXEN_ROM_ROUNDUP)) { |
| 103 | n &= ~NETXEN_ROM_ROUNDUP; |
| 104 | if (n < NETXEN_MAX_EEPROM_LEN) |
| 105 | return n; |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) |
| 112 | { |
| 113 | struct netxen_port *port = netdev_priv(dev); |
| 114 | struct netxen_adapter *adapter = port->adapter; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 115 | u32 fw_major = 0; |
| 116 | u32 fw_minor = 0; |
| 117 | u32 fw_build = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 118 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 119 | strncpy(drvinfo->driver, netxen_nic_driver_name, 32); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 120 | strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32); |
| 121 | fw_major = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 122 | NETXEN_FW_VERSION_MAJOR)); |
| 123 | fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 124 | NETXEN_FW_VERSION_MINOR)); |
| 125 | fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB)); |
| 126 | sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build); |
| 127 | |
| 128 | strncpy(drvinfo->bus_info, pci_name(port->pdev), 32); |
| 129 | drvinfo->n_stats = NETXEN_NIC_STATS_LEN; |
| 130 | drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN; |
| 131 | drvinfo->regdump_len = NETXEN_NIC_REGS_LEN; |
| 132 | drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev); |
| 133 | } |
| 134 | |
| 135 | static int |
| 136 | netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 137 | { |
| 138 | struct netxen_port *port = netdev_priv(dev); |
| 139 | struct netxen_adapter *adapter = port->adapter; |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 140 | struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 141 | |
| 142 | /* read which mode */ |
| 143 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
| 144 | ecmd->supported = (SUPPORTED_10baseT_Half | |
| 145 | SUPPORTED_10baseT_Full | |
| 146 | SUPPORTED_100baseT_Half | |
| 147 | SUPPORTED_100baseT_Full | |
| 148 | SUPPORTED_1000baseT_Half | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 149 | SUPPORTED_1000baseT_Full); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 150 | |
| 151 | ecmd->advertising = (ADVERTISED_100baseT_Half | |
| 152 | ADVERTISED_100baseT_Full | |
| 153 | ADVERTISED_1000baseT_Half | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 154 | ADVERTISED_1000baseT_Full); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 155 | |
| 156 | ecmd->port = PORT_TP; |
| 157 | |
| 158 | if (netif_running(dev)) { |
| 159 | ecmd->speed = port->link_speed; |
| 160 | ecmd->duplex = port->link_duplex; |
| 161 | } else |
| 162 | return -EIO; /* link absent */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 163 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 164 | ecmd->supported = (SUPPORTED_TP | |
| 165 | SUPPORTED_1000baseT_Full | |
| 166 | SUPPORTED_10000baseT_Full); |
| 167 | ecmd->advertising = (ADVERTISED_TP | |
| 168 | ADVERTISED_1000baseT_Full | |
| 169 | ADVERTISED_10000baseT_Full); |
| 170 | ecmd->port = PORT_TP; |
| 171 | |
| 172 | ecmd->speed = SPEED_10000; |
| 173 | ecmd->duplex = DUPLEX_FULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 174 | ecmd->autoneg = AUTONEG_DISABLE; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 175 | } else |
| 176 | return -EIO; |
| 177 | |
| 178 | ecmd->phy_address = port->portnum; |
| 179 | ecmd->transceiver = XCVR_EXTERNAL; |
| 180 | |
| 181 | switch ((netxen_brdtype_t) boardinfo->board_type) { |
| 182 | case NETXEN_BRDTYPE_P2_SB35_4G: |
| 183 | case NETXEN_BRDTYPE_P2_SB31_2G: |
| 184 | ecmd->supported |= SUPPORTED_Autoneg; |
| 185 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 186 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: |
| 187 | ecmd->supported |= SUPPORTED_TP; |
| 188 | ecmd->advertising |= ADVERTISED_TP; |
| 189 | ecmd->port = PORT_TP; |
| 190 | ecmd->autoneg = (boardinfo->board_type == |
| 191 | NETXEN_BRDTYPE_P2_SB31_10G_CX4) ? |
| 192 | (AUTONEG_DISABLE) : (port->link_autoneg); |
| 193 | break; |
| 194 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 195 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 196 | ecmd->supported |= SUPPORTED_MII; |
| 197 | ecmd->advertising |= ADVERTISED_MII; |
| 198 | ecmd->port = PORT_FIBRE; |
| 199 | ecmd->autoneg = AUTONEG_DISABLE; |
| 200 | break; |
| 201 | case NETXEN_BRDTYPE_P2_SB31_10G: |
| 202 | ecmd->supported |= SUPPORTED_FIBRE; |
| 203 | ecmd->advertising |= ADVERTISED_FIBRE; |
| 204 | ecmd->port = PORT_FIBRE; |
| 205 | ecmd->autoneg = AUTONEG_DISABLE; |
| 206 | break; |
| 207 | default: |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 208 | printk(KERN_ERR "netxen-nic: Unsupported board model %d\n", |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 209 | (netxen_brdtype_t) boardinfo->board_type); |
| 210 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 213 | return 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int |
| 217 | netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 218 | { |
| 219 | struct netxen_port *port = netdev_priv(dev); |
| 220 | struct netxen_adapter *adapter = port->adapter; |
| 221 | __le32 status; |
| 222 | |
| 223 | /* read which mode */ |
| 224 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
| 225 | /* autonegotiation */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 226 | if (adapter->phy_write |
| 227 | && adapter->phy_write(adapter, port->portnum, |
| 228 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, |
| 229 | (__le32) ecmd->autoneg) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 230 | return -EIO; |
| 231 | else |
| 232 | port->link_autoneg = ecmd->autoneg; |
| 233 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 234 | if (adapter->phy_read |
| 235 | && adapter->phy_read(adapter, port->portnum, |
| 236 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 237 | &status) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 238 | return -EIO; |
| 239 | |
| 240 | /* speed */ |
| 241 | switch (ecmd->speed) { |
| 242 | case SPEED_10: |
| 243 | netxen_set_phy_speed(status, 0); |
| 244 | break; |
| 245 | case SPEED_100: |
| 246 | netxen_set_phy_speed(status, 1); |
| 247 | break; |
| 248 | case SPEED_1000: |
| 249 | netxen_set_phy_speed(status, 2); |
| 250 | break; |
| 251 | } |
| 252 | /* set duplex mode */ |
| 253 | if (ecmd->duplex == DUPLEX_HALF) |
| 254 | netxen_clear_phy_duplex(status); |
| 255 | if (ecmd->duplex == DUPLEX_FULL) |
| 256 | netxen_set_phy_duplex(status); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 257 | if (adapter->phy_write |
| 258 | && adapter->phy_write(adapter, port->portnum, |
| 259 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 260 | *((int *)&status)) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 261 | return -EIO; |
| 262 | else { |
| 263 | port->link_speed = ecmd->speed; |
| 264 | port->link_duplex = ecmd->duplex; |
| 265 | } |
| 266 | } else |
| 267 | return -EOPNOTSUPP; |
| 268 | |
| 269 | if (netif_running(dev)) { |
| 270 | dev->stop(dev); |
| 271 | dev->open(dev); |
| 272 | } |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int netxen_nic_get_regs_len(struct net_device *dev) |
| 277 | { |
| 278 | return NETXEN_NIC_REGS_LEN; |
| 279 | } |
| 280 | |
| 281 | struct netxen_niu_regs { |
| 282 | __le32 reg[NETXEN_NIC_REGS_COUNT]; |
| 283 | }; |
| 284 | |
| 285 | static struct netxen_niu_regs niu_registers[] = { |
| 286 | { |
| 287 | /* GB Mode */ |
| 288 | { |
| 289 | NETXEN_NIU_GB_SERDES_RESET, |
| 290 | NETXEN_NIU_GB0_MII_MODE, |
| 291 | NETXEN_NIU_GB1_MII_MODE, |
| 292 | NETXEN_NIU_GB2_MII_MODE, |
| 293 | NETXEN_NIU_GB3_MII_MODE, |
| 294 | NETXEN_NIU_GB0_GMII_MODE, |
| 295 | NETXEN_NIU_GB1_GMII_MODE, |
| 296 | NETXEN_NIU_GB2_GMII_MODE, |
| 297 | NETXEN_NIU_GB3_GMII_MODE, |
| 298 | NETXEN_NIU_REMOTE_LOOPBACK, |
| 299 | NETXEN_NIU_GB0_HALF_DUPLEX, |
| 300 | NETXEN_NIU_GB1_HALF_DUPLEX, |
| 301 | NETXEN_NIU_RESET_SYS_FIFOS, |
| 302 | NETXEN_NIU_GB_CRC_DROP, |
| 303 | NETXEN_NIU_GB_DROP_WRONGADDR, |
| 304 | NETXEN_NIU_TEST_MUX_CTL, |
| 305 | |
| 306 | NETXEN_NIU_GB_MAC_CONFIG_0(0), |
| 307 | NETXEN_NIU_GB_MAC_CONFIG_1(0), |
| 308 | NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0), |
| 309 | NETXEN_NIU_GB_MAX_FRAME_SIZE(0), |
| 310 | NETXEN_NIU_GB_TEST_REG(0), |
| 311 | NETXEN_NIU_GB_MII_MGMT_CONFIG(0), |
| 312 | NETXEN_NIU_GB_MII_MGMT_COMMAND(0), |
| 313 | NETXEN_NIU_GB_MII_MGMT_ADDR(0), |
| 314 | NETXEN_NIU_GB_MII_MGMT_CTRL(0), |
| 315 | NETXEN_NIU_GB_MII_MGMT_STATUS(0), |
| 316 | NETXEN_NIU_GB_MII_MGMT_INDICATE(0), |
| 317 | NETXEN_NIU_GB_INTERFACE_CTRL(0), |
| 318 | NETXEN_NIU_GB_INTERFACE_STATUS(0), |
| 319 | NETXEN_NIU_GB_STATION_ADDR_0(0), |
| 320 | NETXEN_NIU_GB_STATION_ADDR_1(0), |
| 321 | -1, |
| 322 | } |
| 323 | }, |
| 324 | { |
| 325 | /* XG Mode */ |
| 326 | { |
| 327 | NETXEN_NIU_XG_SINGLE_TERM, |
| 328 | NETXEN_NIU_XG_DRIVE_HI, |
| 329 | NETXEN_NIU_XG_DRIVE_LO, |
| 330 | NETXEN_NIU_XG_DTX, |
| 331 | NETXEN_NIU_XG_DEQ, |
| 332 | NETXEN_NIU_XG_WORD_ALIGN, |
| 333 | NETXEN_NIU_XG_RESET, |
| 334 | NETXEN_NIU_XG_POWER_DOWN, |
| 335 | NETXEN_NIU_XG_RESET_PLL, |
| 336 | NETXEN_NIU_XG_SERDES_LOOPBACK, |
| 337 | NETXEN_NIU_XG_DO_BYTE_ALIGN, |
| 338 | NETXEN_NIU_XG_TX_ENABLE, |
| 339 | NETXEN_NIU_XG_RX_ENABLE, |
| 340 | NETXEN_NIU_XG_STATUS, |
| 341 | NETXEN_NIU_XG_PAUSE_THRESHOLD, |
| 342 | NETXEN_NIU_XGE_CONFIG_0, |
| 343 | NETXEN_NIU_XGE_CONFIG_1, |
| 344 | NETXEN_NIU_XGE_IPG, |
| 345 | NETXEN_NIU_XGE_STATION_ADDR_0_HI, |
| 346 | NETXEN_NIU_XGE_STATION_ADDR_0_1, |
| 347 | NETXEN_NIU_XGE_STATION_ADDR_1_LO, |
| 348 | NETXEN_NIU_XGE_STATUS, |
| 349 | NETXEN_NIU_XGE_MAX_FRAME_SIZE, |
| 350 | NETXEN_NIU_XGE_PAUSE_FRAME_VALUE, |
| 351 | NETXEN_NIU_XGE_TX_BYTE_CNT, |
| 352 | NETXEN_NIU_XGE_TX_FRAME_CNT, |
| 353 | NETXEN_NIU_XGE_RX_BYTE_CNT, |
| 354 | NETXEN_NIU_XGE_RX_FRAME_CNT, |
| 355 | NETXEN_NIU_XGE_AGGR_ERROR_CNT, |
| 356 | NETXEN_NIU_XGE_MULTICAST_FRAME_CNT, |
| 357 | NETXEN_NIU_XGE_UNICAST_FRAME_CNT, |
| 358 | NETXEN_NIU_XGE_CRC_ERROR_CNT, |
| 359 | NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR, |
| 360 | NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR, |
| 361 | NETXEN_NIU_XGE_LOCAL_ERROR_CNT, |
| 362 | NETXEN_NIU_XGE_REMOTE_ERROR_CNT, |
| 363 | NETXEN_NIU_XGE_CONTROL_CHAR_CNT, |
| 364 | NETXEN_NIU_XGE_PAUSE_FRAME_CNT, |
| 365 | -1, |
| 366 | } |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | static void |
| 371 | netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) |
| 372 | { |
| 373 | struct netxen_port *port = netdev_priv(dev); |
| 374 | struct netxen_adapter *adapter = port->adapter; |
| 375 | __le32 mode, *regs_buff = p; |
| 376 | void __iomem *addr; |
| 377 | int i, window; |
| 378 | |
| 379 | memset(p, 0, NETXEN_NIC_REGS_LEN); |
| 380 | regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | |
| 381 | (port->pdev)->device; |
| 382 | /* which mode */ |
| 383 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, ®s_buff[0]); |
| 384 | mode = regs_buff[0]; |
| 385 | |
| 386 | /* Common registers to all the modes */ |
| 387 | NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, |
| 388 | ®s_buff[2]); |
| 389 | /* GB/XGB Mode */ |
| 390 | mode = (mode / 2) - 1; |
| 391 | window = 0; |
| 392 | if (mode <= 1) { |
| 393 | for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) { |
| 394 | /* GB: port specific registers */ |
| 395 | if (mode == 0 && i >= 19) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 396 | window = port->portnum * NETXEN_NIC_PORT_WINDOW; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 397 | |
| 398 | NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode]. |
| 399 | reg[i - 3] + window, |
| 400 | ®s_buff[i]); |
| 401 | } |
| 402 | |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | static void |
| 407 | netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 408 | { |
| 409 | wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 410 | /* options can be added depending upon the mode */ |
| 411 | wol->wolopts = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static u32 netxen_nic_get_link(struct net_device *dev) |
| 415 | { |
| 416 | struct netxen_port *port = netdev_priv(dev); |
| 417 | struct netxen_adapter *adapter = port->adapter; |
| 418 | __le32 status; |
| 419 | |
| 420 | /* read which mode */ |
| 421 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 422 | if (adapter->phy_read |
| 423 | && adapter->phy_read(adapter, port->portnum, |
| 424 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 425 | &status) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 426 | return -EIO; |
| 427 | else |
| 428 | return (netxen_get_phy_link(status)); |
| 429 | } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) { |
| 430 | int val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); |
| 431 | return val == XG_LINK_UP; |
| 432 | } |
| 433 | return -EIO; |
| 434 | } |
| 435 | |
| 436 | static int |
| 437 | netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, |
| 438 | u8 * bytes) |
| 439 | { |
| 440 | struct netxen_port *port = netdev_priv(dev); |
| 441 | struct netxen_adapter *adapter = port->adapter; |
| 442 | int offset; |
| 443 | |
| 444 | if (eeprom->len == 0) |
| 445 | return -EINVAL; |
| 446 | |
| 447 | eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16); |
| 448 | for (offset = 0; offset < eeprom->len; offset++) |
| 449 | if (netxen_rom_fast_read |
| 450 | (adapter, (8 * offset) + 8, (int *)eeprom->data) == -1) |
| 451 | return -EIO; |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static void |
| 456 | netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) |
| 457 | { |
| 458 | struct netxen_port *port = netdev_priv(dev); |
| 459 | struct netxen_adapter *adapter = port->adapter; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 460 | int i; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 461 | |
| 462 | ring->rx_pending = 0; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 463 | ring->rx_jumbo_pending = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 464 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 465 | ring->rx_pending += adapter->recv_ctx[i]. |
| 466 | rcv_desc[RCV_DESC_NORMAL_CTXID].rcv_pending; |
| 467 | ring->rx_jumbo_pending += adapter->recv_ctx[i]. |
| 468 | rcv_desc[RCV_DESC_JUMBO_CTXID].rcv_pending; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | ring->rx_max_pending = adapter->max_rx_desc_count; |
| 472 | ring->tx_max_pending = adapter->max_tx_desc_count; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 473 | ring->rx_jumbo_max_pending = adapter->max_jumbo_rx_desc_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 474 | ring->rx_mini_max_pending = 0; |
| 475 | ring->rx_mini_pending = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 476 | ring->rx_jumbo_pending = 0; |
| 477 | } |
| 478 | |
| 479 | static void |
| 480 | netxen_nic_get_pauseparam(struct net_device *dev, |
| 481 | struct ethtool_pauseparam *pause) |
| 482 | { |
| 483 | struct netxen_port *port = netdev_priv(dev); |
| 484 | struct netxen_adapter *adapter = port->adapter; |
| 485 | __le32 val; |
| 486 | |
| 487 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
| 488 | /* get flow control settings */ |
| 489 | netxen_nic_read_w0(adapter, |
| 490 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), |
| 491 | (u32 *) & val); |
| 492 | pause->rx_pause = netxen_gb_get_rx_flowctl(val); |
| 493 | pause->tx_pause = netxen_gb_get_tx_flowctl(val); |
| 494 | /* get autoneg settings */ |
| 495 | pause->autoneg = port->link_autoneg; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | static int |
| 500 | netxen_nic_set_pauseparam(struct net_device *dev, |
| 501 | struct ethtool_pauseparam *pause) |
| 502 | { |
| 503 | struct netxen_port *port = netdev_priv(dev); |
| 504 | struct netxen_adapter *adapter = port->adapter; |
| 505 | __le32 val; |
| 506 | unsigned int autoneg; |
| 507 | |
| 508 | /* read mode */ |
| 509 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
| 510 | /* set flow control */ |
| 511 | netxen_nic_read_w0(adapter, |
| 512 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), |
| 513 | (u32 *) & val); |
| 514 | if (pause->tx_pause) |
| 515 | netxen_gb_tx_flowctl(val); |
| 516 | else |
| 517 | netxen_gb_unset_tx_flowctl(val); |
| 518 | if (pause->rx_pause) |
| 519 | netxen_gb_rx_flowctl(val); |
| 520 | else |
| 521 | netxen_gb_unset_rx_flowctl(val); |
| 522 | |
| 523 | netxen_nic_write_w0(adapter, |
| 524 | NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum), |
| 525 | *(u32 *) (&val)); |
| 526 | /* set autoneg */ |
| 527 | autoneg = pause->autoneg; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 528 | if (adapter->phy_write |
| 529 | && adapter->phy_write(adapter, port->portnum, |
| 530 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, |
| 531 | (__le32) autoneg) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 532 | return -EIO; |
| 533 | else { |
| 534 | port->link_autoneg = pause->autoneg; |
| 535 | return 0; |
| 536 | } |
| 537 | } else |
| 538 | return -EOPNOTSUPP; |
| 539 | } |
| 540 | |
| 541 | static int netxen_nic_reg_test(struct net_device *dev) |
| 542 | { |
| 543 | struct netxen_port *port = netdev_priv(dev); |
| 544 | struct netxen_adapter *adapter = port->adapter; |
| 545 | u32 data_read, data_written, save; |
| 546 | __le32 mode; |
| 547 | |
| 548 | /* |
| 549 | * first test the "Read Only" registers by writing which mode |
| 550 | */ |
| 551 | netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); |
| 552 | if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */ |
| 553 | netxen_nic_read_w0(adapter, |
| 554 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), |
| 555 | &data_read); |
| 556 | |
| 557 | save = data_read; |
| 558 | if (data_read) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 559 | data_written = data_read & NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 560 | else |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 561 | data_written = NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 562 | netxen_nic_write_w0(adapter, |
| 563 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> |
| 564 | portnum), |
| 565 | data_written); |
| 566 | netxen_nic_read_w0(adapter, |
| 567 | NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum), |
| 568 | &data_read); |
| 569 | |
| 570 | if (data_written == data_read) { |
| 571 | netxen_nic_write_w0(adapter, |
| 572 | NETXEN_NIU_GB_MII_MGMT_STATUS(port-> |
| 573 | portnum), |
| 574 | save); |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | /* netxen_niu_gb_mii_mgmt_indicators is read only */ |
| 580 | netxen_nic_read_w0(adapter, |
| 581 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> |
| 582 | portnum), |
| 583 | &data_read); |
| 584 | |
| 585 | save = data_read; |
| 586 | if (data_read) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 587 | data_written = data_read & NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 588 | else |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 589 | data_written = NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 590 | netxen_nic_write_w0(adapter, |
| 591 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> |
| 592 | portnum), |
| 593 | data_written); |
| 594 | |
| 595 | netxen_nic_read_w0(adapter, |
| 596 | NETXEN_NIU_GB_MII_MGMT_INDICATE(port-> |
| 597 | portnum), |
| 598 | &data_read); |
| 599 | |
| 600 | if (data_written == data_read) { |
| 601 | netxen_nic_write_w0(adapter, |
| 602 | NETXEN_NIU_GB_MII_MGMT_INDICATE |
| 603 | (port->portnum), save); |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | /* netxen_niu_gb_interface_status is read only */ |
| 608 | netxen_nic_read_w0(adapter, |
| 609 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> |
| 610 | portnum), |
| 611 | &data_read); |
| 612 | |
| 613 | save = data_read; |
| 614 | if (data_read) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 615 | data_written = data_read & NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 616 | else |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 617 | data_written = NETXEN_NIC_INVALID_DATA; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 618 | netxen_nic_write_w0(adapter, |
| 619 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> |
| 620 | portnum), |
| 621 | data_written); |
| 622 | |
| 623 | netxen_nic_read_w0(adapter, |
| 624 | NETXEN_NIU_GB_INTERFACE_STATUS(port-> |
| 625 | portnum), |
| 626 | &data_read); |
| 627 | |
| 628 | if (data_written == data_read) { |
| 629 | netxen_nic_write_w0(adapter, |
| 630 | NETXEN_NIU_GB_INTERFACE_STATUS |
| 631 | (port->portnum), save); |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | } /* GB Mode */ |
| 636 | return 1; |
| 637 | } |
| 638 | |
| 639 | static int netxen_nic_diag_test_count(struct net_device *dev) |
| 640 | { |
| 641 | return NETXEN_NIC_TEST_LEN; |
| 642 | } |
| 643 | |
| 644 | static void |
| 645 | netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test, |
| 646 | u64 * data) |
| 647 | { |
| 648 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */ |
| 649 | /* link test */ |
| 650 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) |
| 651 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 652 | |
| 653 | if (netif_running(dev)) |
| 654 | dev->stop(dev); |
| 655 | |
| 656 | /* register tests */ |
| 657 | if (!(data[0] = netxen_nic_reg_test(dev))) |
| 658 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 659 | /* other tests pass as of now */ |
| 660 | data[1] = data[2] = data[3] = 1; |
| 661 | if (netif_running(dev)) |
| 662 | dev->open(dev); |
| 663 | } else { /* online tests */ |
| 664 | /* link test */ |
| 665 | if (!(data[4] = (u64) netxen_nic_get_link(dev))) |
| 666 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 667 | |
| 668 | /* other tests pass by default */ |
| 669 | data[0] = data[1] = data[2] = data[3] = 1; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | static void |
| 674 | netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data) |
| 675 | { |
| 676 | int index; |
| 677 | |
| 678 | switch (stringset) { |
| 679 | case ETH_SS_TEST: |
| 680 | memcpy(data, *netxen_nic_gstrings_test, |
| 681 | NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN); |
| 682 | break; |
| 683 | case ETH_SS_STATS: |
| 684 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { |
| 685 | memcpy(data + index * ETH_GSTRING_LEN, |
| 686 | netxen_nic_gstrings_stats[index].stat_string, |
| 687 | ETH_GSTRING_LEN); |
| 688 | } |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | static int netxen_nic_get_stats_count(struct net_device *dev) |
| 694 | { |
| 695 | return NETXEN_NIC_STATS_LEN; |
| 696 | } |
| 697 | |
| 698 | static void |
| 699 | netxen_nic_get_ethtool_stats(struct net_device *dev, |
| 700 | struct ethtool_stats *stats, u64 * data) |
| 701 | { |
| 702 | struct netxen_port *port = netdev_priv(dev); |
| 703 | int index; |
| 704 | |
| 705 | for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) { |
| 706 | char *p = |
| 707 | (char *)port + netxen_nic_gstrings_stats[index].stat_offset; |
| 708 | data[index] = |
| 709 | (netxen_nic_gstrings_stats[index].sizeof_stat == |
| 710 | sizeof(u64)) ? *(u64 *) p : *(u32 *) p; |
| 711 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | struct ethtool_ops netxen_nic_ethtool_ops = { |
| 715 | .get_settings = netxen_nic_get_settings, |
| 716 | .set_settings = netxen_nic_set_settings, |
| 717 | .get_drvinfo = netxen_nic_get_drvinfo, |
| 718 | .get_regs_len = netxen_nic_get_regs_len, |
| 719 | .get_regs = netxen_nic_get_regs, |
| 720 | .get_wol = netxen_nic_get_wol, |
| 721 | .get_link = netxen_nic_get_link, |
| 722 | .get_eeprom_len = netxen_nic_get_eeprom_len, |
| 723 | .get_eeprom = netxen_nic_get_eeprom, |
| 724 | .get_ringparam = netxen_nic_get_ringparam, |
| 725 | .get_pauseparam = netxen_nic_get_pauseparam, |
| 726 | .set_pauseparam = netxen_nic_set_pauseparam, |
| 727 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 728 | .set_tx_csum = ethtool_op_set_tx_csum, |
| 729 | .get_sg = ethtool_op_get_sg, |
| 730 | .set_sg = ethtool_op_set_sg, |
| 731 | .get_tso = ethtool_op_get_tso, |
| 732 | .set_tso = ethtool_op_set_tso, |
| 733 | .self_test_count = netxen_nic_diag_test_count, |
| 734 | .self_test = netxen_nic_diag_test, |
| 735 | .get_strings = netxen_nic_get_strings, |
| 736 | .get_stats_count = netxen_nic_get_stats_count, |
| 737 | .get_ethtool_stats = netxen_nic_get_ethtool_stats, |
| 738 | .get_perm_addr = ethtool_op_get_perm_addr, |
| 739 | }; |