netxen_nic_ethtool.c 19.2 KB
Newer Older
A
Amit S. Kale 已提交
1 2 3
/*
 * Copyright (C) 2003 - 2006 NetXen, Inc.
 * All rights reserved.
4
 *
A
Amit S. Kale 已提交
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
9
 *
A
Amit S. Kale 已提交
10 11 12 13
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14
 *
A
Amit S. Kale 已提交
15 16 17 18
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA  02111-1307, USA.
19
 *
A
Amit S. Kale 已提交
20 21
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.
22
 *
A
Amit S. Kale 已提交
23 24 25 26 27 28 29 30 31 32 33 34
 * Contact Information:
 *    info@netxen.com
 * NetXen,
 * 3965 Freedom Circle, Fourth floor,
 * Santa Clara, CA 95054
 *
 *
 * ethtool support for netxen nic
 *
 */

#include <linux/types.h>
35
#include <linux/delay.h>
A
Amit S. Kale 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <asm/uaccess.h>
#include <linux/pci.h>
#include <asm/io.h>
#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/version.h>

#include "netxen_nic_hw.h"
#include "netxen_nic.h"
#include "netxen_nic_phan_reg.h"

struct netxen_nic_stats {
	char stat_string[ETH_GSTRING_LEN];
	int sizeof_stat;
	int stat_offset;
};

53 54
#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
			offsetof(struct netxen_adapter, m)
A
Amit S. Kale 已提交
55

56 57 58
#define NETXEN_NIC_PORT_WINDOW 0x10000
#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF

A
Amit S. Kale 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
	{"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
	{"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
	{"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
	{"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
	{"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
	{"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
	{"polled", NETXEN_NIC_STAT(stats.polled)},
	{"uphappy", NETXEN_NIC_STAT(stats.uphappy)},
	{"updropped", NETXEN_NIC_STAT(stats.updropped)},
	{"uplcong", NETXEN_NIC_STAT(stats.uplcong)},
	{"uphcong", NETXEN_NIC_STAT(stats.uphcong)},
	{"upmcong", NETXEN_NIC_STAT(stats.upmcong)},
	{"updunno", NETXEN_NIC_STAT(stats.updunno)},
	{"skb_freed", NETXEN_NIC_STAT(stats.skbfreed)},
	{"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
	{"tx_null_skb", NETXEN_NIC_STAT(stats.txnullskb)},
	{"csummed", NETXEN_NIC_STAT(stats.csummed)},
	{"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
	{"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
	{"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
};

S
Stephen Hemminger 已提交
82
#define NETXEN_NIC_STATS_LEN	ARRAY_SIZE(netxen_nic_gstrings_stats)
A
Amit S. Kale 已提交
83 84

static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
85
	"Register_Test_on_offline",
A
Amit S. Kale 已提交
86 87 88 89 90 91 92 93 94 95 96
	"Link_Test_on_offline"
};

#define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN

#define NETXEN_NIC_REGS_COUNT 42
#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
#define NETXEN_MAX_EEPROM_LEN   1024

static int netxen_nic_get_eeprom_len(struct net_device *dev)
{
97
	return FLASH_TOTAL_SIZE;
A
Amit S. Kale 已提交
98 99 100 101 102
}

static void
netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
{
103
	struct netxen_adapter *adapter = netdev_priv(dev);
104 105 106
	u32 fw_major = 0;
	u32 fw_minor = 0;
	u32 fw_build = 0;
A
Amit S. Kale 已提交
107

108
	strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
A
Amit S. Kale 已提交
109 110 111 112 113 114 115 116
	strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
	fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
					      NETXEN_FW_VERSION_MAJOR));
	fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
					      NETXEN_FW_VERSION_MINOR));
	fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
	sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);

117
	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
A
Amit S. Kale 已提交
118 119 120 121 122 123 124 125 126
	drvinfo->n_stats = NETXEN_NIC_STATS_LEN;
	drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN;
	drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
	drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
}

static int
netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
127
	struct netxen_adapter *adapter = netdev_priv(dev);
128
	struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
A
Amit S. Kale 已提交
129 130 131 132 133 134 135 136

	/* read which mode */
	if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
		ecmd->supported = (SUPPORTED_10baseT_Half |
				   SUPPORTED_10baseT_Full |
				   SUPPORTED_100baseT_Half |
				   SUPPORTED_100baseT_Full |
				   SUPPORTED_1000baseT_Half |
137
				   SUPPORTED_1000baseT_Full);
A
Amit S. Kale 已提交
138 139 140 141

		ecmd->advertising = (ADVERTISED_100baseT_Half |
				     ADVERTISED_100baseT_Full |
				     ADVERTISED_1000baseT_Half |
142
				     ADVERTISED_1000baseT_Full);
A
Amit S. Kale 已提交
143 144 145 146

		ecmd->port = PORT_TP;

		if (netif_running(dev)) {
147 148
			ecmd->speed = adapter->link_speed;
			ecmd->duplex = adapter->link_duplex;
A
Amit S. Kale 已提交
149 150
		} else
			return -EIO;	/* link absent */
151
	} else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
A
Amit S. Kale 已提交
152 153 154 155 156 157 158 159 160 161 162
		ecmd->supported = (SUPPORTED_TP |
				   SUPPORTED_1000baseT_Full |
				   SUPPORTED_10000baseT_Full);
		ecmd->advertising = (ADVERTISED_TP |
				     ADVERTISED_1000baseT_Full |
				     ADVERTISED_10000baseT_Full);
		ecmd->port = PORT_TP;

		ecmd->speed = SPEED_10000;
		ecmd->duplex = DUPLEX_FULL;
		ecmd->autoneg = AUTONEG_DISABLE;
163 164 165
	} else
		return -EIO;

166
	ecmd->phy_address = adapter->portnum;
167 168 169 170 171 172 173 174 175 176 177 178 179
	ecmd->transceiver = XCVR_EXTERNAL;

	switch ((netxen_brdtype_t) boardinfo->board_type) {
	case NETXEN_BRDTYPE_P2_SB35_4G:
	case NETXEN_BRDTYPE_P2_SB31_2G:
		ecmd->supported |= SUPPORTED_Autoneg;
		ecmd->advertising |= ADVERTISED_Autoneg;
	case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
		ecmd->supported |= SUPPORTED_TP;
		ecmd->advertising |= ADVERTISED_TP;
		ecmd->port = PORT_TP;
		ecmd->autoneg = (boardinfo->board_type ==
				 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
180
		    (AUTONEG_DISABLE) : (adapter->link_autoneg);
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
		break;
	case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
	case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
		ecmd->supported |= SUPPORTED_MII;
		ecmd->advertising |= ADVERTISED_MII;
		ecmd->port = PORT_FIBRE;
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
	case NETXEN_BRDTYPE_P2_SB31_10G:
		ecmd->supported |= SUPPORTED_FIBRE;
		ecmd->advertising |= ADVERTISED_FIBRE;
		ecmd->port = PORT_FIBRE;
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
	default:
196
		printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
197 198
		       (netxen_brdtype_t) boardinfo->board_type);
		return -EIO;
A
Amit S. Kale 已提交
199 200
	}

201
	return 0;
A
Amit S. Kale 已提交
202 203 204 205 206
}

static int
netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
207
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
208
	__u32 status;
A
Amit S. Kale 已提交
209 210 211 212

	/* read which mode */
	if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
		/* autonegotiation */
213
		if (adapter->phy_write
214
		    && adapter->phy_write(adapter,
215
					  NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
A
Al Viro 已提交
216
					  ecmd->autoneg) != 0)
A
Amit S. Kale 已提交
217 218
			return -EIO;
		else
219
			adapter->link_autoneg = ecmd->autoneg;
A
Amit S. Kale 已提交
220

221
		if (adapter->phy_read
222
		    && adapter->phy_read(adapter,
223 224
					 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
					 &status) != 0)
A
Amit S. Kale 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
			return -EIO;

		/* speed */
		switch (ecmd->speed) {
		case SPEED_10:
			netxen_set_phy_speed(status, 0);
			break;
		case SPEED_100:
			netxen_set_phy_speed(status, 1);
			break;
		case SPEED_1000:
			netxen_set_phy_speed(status, 2);
			break;
		}
		/* set duplex mode */
		if (ecmd->duplex == DUPLEX_HALF)
			netxen_clear_phy_duplex(status);
		if (ecmd->duplex == DUPLEX_FULL)
			netxen_set_phy_duplex(status);
244
		if (adapter->phy_write
245
		    && adapter->phy_write(adapter,
246 247
					  NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
					  *((int *)&status)) != 0)
A
Amit S. Kale 已提交
248 249
			return -EIO;
		else {
250 251
			adapter->link_speed = ecmd->speed;
			adapter->link_duplex = ecmd->duplex;
A
Amit S. Kale 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
		}
	} else
		return -EOPNOTSUPP;

	if (netif_running(dev)) {
		dev->stop(dev);
		dev->open(dev);
	}
	return 0;
}

static int netxen_nic_get_regs_len(struct net_device *dev)
{
	return NETXEN_NIC_REGS_LEN;
}

struct netxen_niu_regs {
A
Al Viro 已提交
269
	__u32 reg[NETXEN_NIC_REGS_COUNT];
A
Amit S. Kale 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
};

static struct netxen_niu_regs niu_registers[] = {
	{
	 /* GB Mode */
	 {
	  NETXEN_NIU_GB_SERDES_RESET,
	  NETXEN_NIU_GB0_MII_MODE,
	  NETXEN_NIU_GB1_MII_MODE,
	  NETXEN_NIU_GB2_MII_MODE,
	  NETXEN_NIU_GB3_MII_MODE,
	  NETXEN_NIU_GB0_GMII_MODE,
	  NETXEN_NIU_GB1_GMII_MODE,
	  NETXEN_NIU_GB2_GMII_MODE,
	  NETXEN_NIU_GB3_GMII_MODE,
	  NETXEN_NIU_REMOTE_LOOPBACK,
	  NETXEN_NIU_GB0_HALF_DUPLEX,
	  NETXEN_NIU_GB1_HALF_DUPLEX,
	  NETXEN_NIU_RESET_SYS_FIFOS,
	  NETXEN_NIU_GB_CRC_DROP,
	  NETXEN_NIU_GB_DROP_WRONGADDR,
	  NETXEN_NIU_TEST_MUX_CTL,

	  NETXEN_NIU_GB_MAC_CONFIG_0(0),
	  NETXEN_NIU_GB_MAC_CONFIG_1(0),
	  NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
	  NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
	  NETXEN_NIU_GB_TEST_REG(0),
	  NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
	  NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
	  NETXEN_NIU_GB_MII_MGMT_ADDR(0),
	  NETXEN_NIU_GB_MII_MGMT_CTRL(0),
	  NETXEN_NIU_GB_MII_MGMT_STATUS(0),
	  NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
	  NETXEN_NIU_GB_INTERFACE_CTRL(0),
	  NETXEN_NIU_GB_INTERFACE_STATUS(0),
	  NETXEN_NIU_GB_STATION_ADDR_0(0),
	  NETXEN_NIU_GB_STATION_ADDR_1(0),
	  -1,
	  }
	 },
	{
	 /* XG Mode */
	 {
	  NETXEN_NIU_XG_SINGLE_TERM,
	  NETXEN_NIU_XG_DRIVE_HI,
	  NETXEN_NIU_XG_DRIVE_LO,
	  NETXEN_NIU_XG_DTX,
	  NETXEN_NIU_XG_DEQ,
	  NETXEN_NIU_XG_WORD_ALIGN,
	  NETXEN_NIU_XG_RESET,
	  NETXEN_NIU_XG_POWER_DOWN,
	  NETXEN_NIU_XG_RESET_PLL,
	  NETXEN_NIU_XG_SERDES_LOOPBACK,
	  NETXEN_NIU_XG_DO_BYTE_ALIGN,
	  NETXEN_NIU_XG_TX_ENABLE,
	  NETXEN_NIU_XG_RX_ENABLE,
	  NETXEN_NIU_XG_STATUS,
	  NETXEN_NIU_XG_PAUSE_THRESHOLD,
	  NETXEN_NIU_XGE_CONFIG_0,
	  NETXEN_NIU_XGE_CONFIG_1,
	  NETXEN_NIU_XGE_IPG,
	  NETXEN_NIU_XGE_STATION_ADDR_0_HI,
	  NETXEN_NIU_XGE_STATION_ADDR_0_1,
	  NETXEN_NIU_XGE_STATION_ADDR_1_LO,
	  NETXEN_NIU_XGE_STATUS,
	  NETXEN_NIU_XGE_MAX_FRAME_SIZE,
	  NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
	  NETXEN_NIU_XGE_TX_BYTE_CNT,
	  NETXEN_NIU_XGE_TX_FRAME_CNT,
	  NETXEN_NIU_XGE_RX_BYTE_CNT,
	  NETXEN_NIU_XGE_RX_FRAME_CNT,
	  NETXEN_NIU_XGE_AGGR_ERROR_CNT,
	  NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
	  NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
	  NETXEN_NIU_XGE_CRC_ERROR_CNT,
	  NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
	  NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
	  NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
	  NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
	  NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
	  NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
	  -1,
	  }
	 }
};

static void
netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
{
360
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
361
	__u32 mode, *regs_buff = p;
A
Amit S. Kale 已提交
362 363 364 365 366
	void __iomem *addr;
	int i, window;

	memset(p, 0, NETXEN_NIC_REGS_LEN);
	regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
367
	    (adapter->pdev)->device;
A
Amit S. Kale 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381
	/* which mode */
	NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, &regs_buff[0]);
	mode = regs_buff[0];

	/* Common registers to all the modes */
	NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER,
				   &regs_buff[2]);
	/* GB/XGB Mode */
	mode = (mode / 2) - 1;
	window = 0;
	if (mode <= 1) {
		for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
			/* GB: port specific registers */
			if (mode == 0 && i >= 19)
382 383
				window = adapter->portnum * 
					NETXEN_NIC_PORT_WINDOW;
A
Amit S. Kale 已提交
384 385 386 387 388 389 390 391 392

			NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode].
						   reg[i - 3] + window,
						   &regs_buff[i]);
		}

	}
}

393
static u32 netxen_nic_test_link(struct net_device *dev)
A
Amit S. Kale 已提交
394
{
395
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
396
	__u32 status;
397
	int val;
A
Amit S. Kale 已提交
398 399 400

	/* read which mode */
	if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
401
		if (adapter->phy_read
402
		    && adapter->phy_read(adapter,
403 404
					 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
					 &status) != 0)
A
Amit S. Kale 已提交
405
			return -EIO;
406 407 408 409
		else {
			val = netxen_get_phy_link(status);
			return !val;
		}
A
Amit S. Kale 已提交
410
	} else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
411 412
		val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
		return (val == XG_LINK_UP) ? 0 : 1;
A
Amit S. Kale 已提交
413 414 415 416 417 418 419 420
	}
	return -EIO;
}

static int
netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
		      u8 * bytes)
{
421
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Amit S. Kale 已提交
422
	int offset;
423
	int ret;
A
Amit S. Kale 已提交
424 425 426 427

	if (eeprom->len == 0)
		return -EINVAL;

428 429
	eeprom->magic = (adapter->pdev)->vendor | 
			((adapter->pdev)->device << 16);
430 431 432 433 434 435 436
	offset = eeprom->offset;

	ret = netxen_rom_fast_read_words(adapter, offset, bytes, 
						eeprom->len);
	if (ret < 0)
		return ret;

A
Amit S. Kale 已提交
437 438 439
	return 0;
}

440 441 442 443
static int
netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
			u8 * bytes)
{
444
	struct netxen_adapter *adapter = netdev_priv(dev);
445 446 447 448 449 450
	int offset = eeprom->offset;
	static int flash_start;
	static int ready_to_flash;
	int ret;

	if (flash_start == 0) {
451
		netxen_halt_pegs(adapter);
452 453 454 455 456 457 458 459
		ret = netxen_flash_unlock(adapter);
		if (ret < 0) {
			printk(KERN_ERR "%s: Flash unlock failed.\n",
				netxen_nic_driver_name);
			return ret;
		}
		printk(KERN_INFO "%s: flash unlocked. \n", 
			netxen_nic_driver_name);
460
		last_schedule_time = jiffies;
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
		ret = netxen_flash_erase_secondary(adapter);
		if (ret != FLASH_SUCCESS) {
			printk(KERN_ERR "%s: Flash erase failed.\n", 
				netxen_nic_driver_name);
			return ret;
		}
		printk(KERN_INFO "%s: secondary flash erased successfully.\n", 
			netxen_nic_driver_name);
		flash_start = 1;
		return 0;
	}

	if (offset == BOOTLD_START) {
		ret = netxen_flash_erase_primary(adapter);
		if (ret != FLASH_SUCCESS) {
			printk(KERN_ERR "%s: Flash erase failed.\n", 
				netxen_nic_driver_name);
			return ret;
		}

		ret = netxen_rom_se(adapter, USER_START);
		if (ret != FLASH_SUCCESS)
			return ret;
		ret = netxen_rom_se(adapter, FIXED_START);
		if (ret != FLASH_SUCCESS)
			return ret;

		printk(KERN_INFO "%s: primary flash erased successfully\n", 
			netxen_nic_driver_name);

		ret = netxen_backup_crbinit(adapter);
		if (ret != FLASH_SUCCESS) {
			printk(KERN_ERR "%s: CRBinit backup failed.\n", 
				netxen_nic_driver_name);
			return ret;
		}
		printk(KERN_INFO "%s: CRBinit backup done.\n", 
			netxen_nic_driver_name);
		ready_to_flash = 1;
	}

	if (!ready_to_flash) {
		printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
			netxen_nic_driver_name);
		return -EINVAL;
	}

	return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
}

A
Amit S. Kale 已提交
511 512 513
static void
netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
{
514
	struct netxen_adapter *adapter = netdev_priv(dev);
515
	int i;
A
Amit S. Kale 已提交
516 517

	ring->rx_pending = 0;
518
	ring->rx_jumbo_pending = 0;
A
Amit S. Kale 已提交
519
	for (i = 0; i < MAX_RCV_CTX; ++i) {
520 521 522 523
		ring->rx_pending += adapter->recv_ctx[i].
		    rcv_desc[RCV_DESC_NORMAL_CTXID].rcv_pending;
		ring->rx_jumbo_pending += adapter->recv_ctx[i].
		    rcv_desc[RCV_DESC_JUMBO_CTXID].rcv_pending;
A
Amit S. Kale 已提交
524 525 526 527
	}

	ring->rx_max_pending = adapter->max_rx_desc_count;
	ring->tx_max_pending = adapter->max_tx_desc_count;
528
	ring->rx_jumbo_max_pending = adapter->max_jumbo_rx_desc_count;
A
Amit S. Kale 已提交
529 530 531 532 533 534 535 536 537
	ring->rx_mini_max_pending = 0;
	ring->rx_mini_pending = 0;
	ring->rx_jumbo_pending = 0;
}

static void
netxen_nic_get_pauseparam(struct net_device *dev,
			  struct ethtool_pauseparam *pause)
{
538
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
539
	__u32 val;
A
Amit S. Kale 已提交
540 541 542 543

	if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
		/* get flow control settings */
		netxen_nic_read_w0(adapter,
544
				   NETXEN_NIU_GB_MAC_CONFIG_0(adapter->portnum),
A
Al Viro 已提交
545
				   &val);
A
Amit S. Kale 已提交
546 547 548
		pause->rx_pause = netxen_gb_get_rx_flowctl(val);
		pause->tx_pause = netxen_gb_get_tx_flowctl(val);
		/* get autoneg settings */
549
		pause->autoneg = adapter->link_autoneg;
A
Amit S. Kale 已提交
550 551 552 553 554 555 556
	}
}

static int
netxen_nic_set_pauseparam(struct net_device *dev,
			  struct ethtool_pauseparam *pause)
{
557
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
558
	__u32 val;
A
Amit S. Kale 已提交
559 560 561 562 563 564
	unsigned int autoneg;

	/* read mode */
	if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
		/* set flow control */
		netxen_nic_read_w0(adapter,
565
				   NETXEN_NIU_GB_MAC_CONFIG_0(adapter->portnum),
A
Amit S. Kale 已提交
566 567 568 569 570 571 572 573 574 575 576
				   (u32 *) & val);
		if (pause->tx_pause)
			netxen_gb_tx_flowctl(val);
		else
			netxen_gb_unset_tx_flowctl(val);
		if (pause->rx_pause)
			netxen_gb_rx_flowctl(val);
		else
			netxen_gb_unset_rx_flowctl(val);

		netxen_nic_write_w0(adapter,
577
				    NETXEN_NIU_GB_MAC_CONFIG_0(adapter->portnum),
A
Al Viro 已提交
578
				    *&val);
A
Amit S. Kale 已提交
579 580
		/* set autoneg */
		autoneg = pause->autoneg;
581
		if (adapter->phy_write
582
		    && adapter->phy_write(adapter,
583
					  NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
A
Al Viro 已提交
584
					  autoneg) != 0)
A
Amit S. Kale 已提交
585 586
			return -EIO;
		else {
587
			adapter->link_autoneg = pause->autoneg;
A
Amit S. Kale 已提交
588 589 590 591 592 593 594 595
			return 0;
		}
	} else
		return -EOPNOTSUPP;
}

static int netxen_nic_reg_test(struct net_device *dev)
{
596 597
	struct netxen_adapter *adapter = netdev_priv(dev);
	u32 data_read, data_written;
A
Amit S. Kale 已提交
598

599 600 601
	netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
	if ((data_read & 0xffff) != PHAN_VENDOR_ID)
	return 1;
A
Amit S. Kale 已提交
602

603
	data_written = (u32)0xa5a5a5a5;
A
Amit S. Kale 已提交
604

605 606 607 608
	netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
	data_read = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_SCRATCHPAD_TEST));
	if (data_written != data_read)
		return 1;
A
Amit S. Kale 已提交
609

610
	return 0;
A
Amit S. Kale 已提交
611 612 613 614 615 616 617 618 619 620 621 622 623
}

static int netxen_nic_diag_test_count(struct net_device *dev)
{
	return NETXEN_NIC_TEST_LEN;
}

static void
netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
		     u64 * data)
{
	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {	/* offline tests */
		/* link test */
624
		if ((data[1] = (u64) netxen_nic_test_link(dev)))
A
Amit S. Kale 已提交
625 626 627
			eth_test->flags |= ETH_TEST_FL_FAILED;

		/* register tests */
628
		if ((data[0] = netxen_nic_reg_test(dev)))
A
Amit S. Kale 已提交
629 630
			eth_test->flags |= ETH_TEST_FL_FAILED;
	} else {		/* online tests */
631 632
		/* register tests */
		if((data[0] = netxen_nic_reg_test(dev)))
A
Amit S. Kale 已提交
633 634
			eth_test->flags |= ETH_TEST_FL_FAILED;

635 636 637
		/* link test */
		if ((data[1] = (u64) netxen_nic_test_link(dev)))
			eth_test->flags |= ETH_TEST_FL_FAILED;
A
Amit S. Kale 已提交
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
	}
}

static void
netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
{
	int index;

	switch (stringset) {
	case ETH_SS_TEST:
		memcpy(data, *netxen_nic_gstrings_test,
		       NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
		break;
	case ETH_SS_STATS:
		for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
			memcpy(data + index * ETH_GSTRING_LEN,
			       netxen_nic_gstrings_stats[index].stat_string,
			       ETH_GSTRING_LEN);
		}
		break;
	}
}

static int netxen_nic_get_stats_count(struct net_device *dev)
{
	return NETXEN_NIC_STATS_LEN;
}

static void
netxen_nic_get_ethtool_stats(struct net_device *dev,
			     struct ethtool_stats *stats, u64 * data)
{
670
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Amit S. Kale 已提交
671 672 673 674
	int index;

	for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
		char *p =
675 676
		    (char *)adapter +
		    netxen_nic_gstrings_stats[index].stat_offset;
A
Amit S. Kale 已提交
677 678 679 680 681 682 683 684 685 686 687 688
		data[index] =
		    (netxen_nic_gstrings_stats[index].sizeof_stat ==
		     sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
	}
}

struct ethtool_ops netxen_nic_ethtool_ops = {
	.get_settings = netxen_nic_get_settings,
	.set_settings = netxen_nic_set_settings,
	.get_drvinfo = netxen_nic_get_drvinfo,
	.get_regs_len = netxen_nic_get_regs_len,
	.get_regs = netxen_nic_get_regs,
689
	.get_link = ethtool_op_get_link,
A
Amit S. Kale 已提交
690 691
	.get_eeprom_len = netxen_nic_get_eeprom_len,
	.get_eeprom = netxen_nic_get_eeprom,
692
	.set_eeprom = netxen_nic_set_eeprom,
A
Amit S. Kale 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
	.get_ringparam = netxen_nic_get_ringparam,
	.get_pauseparam = netxen_nic_get_pauseparam,
	.set_pauseparam = netxen_nic_set_pauseparam,
	.get_tx_csum = ethtool_op_get_tx_csum,
	.set_tx_csum = ethtool_op_set_tx_csum,
	.get_sg = ethtool_op_get_sg,
	.set_sg = ethtool_op_set_sg,
	.get_tso = ethtool_op_get_tso,
	.set_tso = ethtool_op_set_tso,
	.self_test_count = netxen_nic_diag_test_count,
	.self_test = netxen_nic_diag_test,
	.get_strings = netxen_nic_get_strings,
	.get_stats_count = netxen_nic_get_stats_count,
	.get_ethtool_stats = netxen_nic_get_ethtool_stats,
	.get_perm_addr = ethtool_op_get_perm_addr,
};