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