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