netxen_nic_ethtool.c 26.4 KB
Newer Older
A
Amit S. Kale 已提交
1
/*
D
Dhananjay Phadke 已提交
2
 * Copyright (C) 2003 - 2009 NetXen, Inc.
D
Dhananjay Phadke 已提交
3
 * Copyright (C) 2009 - QLogic Corporation.
A
Amit S. Kale 已提交
4
 * All rights reserved.
5
 *
A
Amit S. Kale 已提交
6 7 8 9
 * 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.
10
 *
A
Amit S. Kale 已提交
11 12 13 14
 * 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.
15
 *
A
Amit S. Kale 已提交
16 17 18 19
 * 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.
20
 *
A
Amit S. Kale 已提交
21 22
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.
23
 *
A
Amit S. Kale 已提交
24 25 26
 */

#include <linux/types.h>
27
#include <linux/delay.h>
A
Amit S. Kale 已提交
28 29 30 31 32 33
#include <linux/pci.h>
#include <asm/io.h>
#include <linux/netdevice.h>
#include <linux/ethtool.h>

#include "netxen_nic.h"
34
#include "netxen_nic_hw.h"
A
Amit S. Kale 已提交
35 36 37 38 39 40 41

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

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

45 46 47
#define NETXEN_NIC_PORT_WINDOW 0x10000
#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF

A
Amit S. Kale 已提交
48 49 50
static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
	{"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
	{"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
D
Dhananjay Phadke 已提交
51
	{"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
A
Amit S. Kale 已提交
52 53
	{"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
	{"csummed", NETXEN_NIC_STAT(stats.csummed)},
54 55
	{"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
	{"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
A
Amit S. Kale 已提交
56 57 58 59
	{"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
	{"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
};

S
Stephen Hemminger 已提交
60
#define NETXEN_NIC_STATS_LEN	ARRAY_SIZE(netxen_nic_gstrings_stats)
A
Amit S. Kale 已提交
61 62

static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
63
	"Register_Test_on_offline",
A
Amit S. Kale 已提交
64 65 66
	"Link_Test_on_offline"
};

67
#define NETXEN_NIC_TEST_LEN	ARRAY_SIZE(netxen_nic_gstrings_test)
A
Amit S. Kale 已提交
68 69 70 71 72 73 74

#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)
{
75
	return NETXEN_FLASH_TOTAL_SIZE;
A
Amit S. Kale 已提交
76 77 78 79 80
}

static void
netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
{
81
	struct netxen_adapter *adapter = netdev_priv(dev);
82 83 84
	u32 fw_major = 0;
	u32 fw_minor = 0;
	u32 fw_build = 0;
A
Amit S. Kale 已提交
85

86
	strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
A
Amit S. Kale 已提交
87
	strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
88 89 90
	fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
	fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
	fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
A
Amit S. Kale 已提交
91 92
	sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);

93
	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
A
Amit S. Kale 已提交
94 95 96 97 98 99 100
	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)
{
101
	struct netxen_adapter *adapter = netdev_priv(dev);
102
	int check_sfp_module = 0;
A
Amit S. Kale 已提交
103 104

	/* read which mode */
105
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
A
Amit S. Kale 已提交
106 107 108 109 110
		ecmd->supported = (SUPPORTED_10baseT_Half |
				   SUPPORTED_10baseT_Full |
				   SUPPORTED_100baseT_Half |
				   SUPPORTED_100baseT_Full |
				   SUPPORTED_1000baseT_Half |
111
				   SUPPORTED_1000baseT_Full);
A
Amit S. Kale 已提交
112 113 114 115

		ecmd->advertising = (ADVERTISED_100baseT_Half |
				     ADVERTISED_100baseT_Full |
				     ADVERTISED_1000baseT_Half |
116
				     ADVERTISED_1000baseT_Full);
A
Amit S. Kale 已提交
117 118 119

		ecmd->port = PORT_TP;

120 121 122
		ecmd->speed = adapter->link_speed;
		ecmd->duplex = adapter->link_duplex;
		ecmd->autoneg = adapter->link_autoneg;
123

124
	} else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
125 126
		u32 val;

127
		val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
128 129 130 131 132 133 134 135
		if (val == NETXEN_PORT_MODE_802_3_AP) {
			ecmd->supported = SUPPORTED_1000baseT_Full;
			ecmd->advertising = ADVERTISED_1000baseT_Full;
		} else {
			ecmd->supported = SUPPORTED_10000baseT_Full;
			ecmd->advertising = ADVERTISED_10000baseT_Full;
		}

136 137 138 139 140 141 142
		if (netif_running(dev) && adapter->has_link_events) {
			ecmd->speed = adapter->link_speed;
			ecmd->autoneg = adapter->link_autoneg;
			ecmd->duplex = adapter->link_duplex;
			goto skip;
		}

A
Amit S. Kale 已提交
143 144
		ecmd->port = PORT_TP;

145 146 147
		if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
			u16 pcifn = adapter->ahw.pci_func;

148
			val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
149 150 151 152 153
			ecmd->speed = P3_LINK_SPEED_MHZ *
					P3_LINK_SPEED_VAL(pcifn, val);
		} else
			ecmd->speed = SPEED_10000;

A
Amit S. Kale 已提交
154 155
		ecmd->duplex = DUPLEX_FULL;
		ecmd->autoneg = AUTONEG_DISABLE;
156 157 158
	} else
		return -EIO;

159
skip:
160
	ecmd->phy_address = adapter->physical_port;
161 162
	ecmd->transceiver = XCVR_EXTERNAL;

D
Dhananjay Phadke 已提交
163
	switch (adapter->ahw.board_type) {
164 165
	case NETXEN_BRDTYPE_P2_SB35_4G:
	case NETXEN_BRDTYPE_P2_SB31_2G:
166 167 168 169
	case NETXEN_BRDTYPE_P3_REF_QG:
	case NETXEN_BRDTYPE_P3_4_GB:
	case NETXEN_BRDTYPE_P3_4_GB_MM:

170 171 172
		ecmd->supported |= SUPPORTED_Autoneg;
		ecmd->advertising |= ADVERTISED_Autoneg;
	case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
173 174
	case NETXEN_BRDTYPE_P3_10G_CX4:
	case NETXEN_BRDTYPE_P3_10G_CX4_LP:
175
	case NETXEN_BRDTYPE_P3_10000_BASE_T:
176 177 178
		ecmd->supported |= SUPPORTED_TP;
		ecmd->advertising |= ADVERTISED_TP;
		ecmd->port = PORT_TP;
179
		ecmd->autoneg = (adapter->ahw.board_type ==
180
				 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
181
		    (AUTONEG_DISABLE) : (adapter->link_autoneg);
182 183 184
		break;
	case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
	case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
185 186 187
	case NETXEN_BRDTYPE_P3_IMEZ:
	case NETXEN_BRDTYPE_P3_XG_LOM:
	case NETXEN_BRDTYPE_P3_HMEZ:
188 189
		ecmd->supported |= SUPPORTED_MII;
		ecmd->advertising |= ADVERTISED_MII;
190
		ecmd->port = PORT_MII;
191 192
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
193
	case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
D
Dhananjay Phadke 已提交
194 195
	case NETXEN_BRDTYPE_P3_10G_SFP_CT:
	case NETXEN_BRDTYPE_P3_10G_SFP_QT:
196 197
		ecmd->advertising |= ADVERTISED_TP;
		ecmd->supported |= SUPPORTED_TP;
198 199
		check_sfp_module = netif_running(dev) &&
			adapter->has_link_events;
200
	case NETXEN_BRDTYPE_P2_SB31_10G:
201
	case NETXEN_BRDTYPE_P3_10G_XFP:
202 203 204 205 206
		ecmd->supported |= SUPPORTED_FIBRE;
		ecmd->advertising |= ADVERTISED_FIBRE;
		ecmd->port = PORT_FIBRE;
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
207
	case NETXEN_BRDTYPE_P3_10G_TP:
208
		if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
209 210 211 212 213
			ecmd->autoneg = AUTONEG_DISABLE;
			ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
			ecmd->advertising |=
				(ADVERTISED_FIBRE | ADVERTISED_TP);
			ecmd->port = PORT_FIBRE;
214 215
			check_sfp_module = netif_running(dev) &&
				adapter->has_link_events;
216 217 218 219 220 221 222 223
		} else {
			ecmd->autoneg = AUTONEG_ENABLE;
			ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
			ecmd->advertising |=
				(ADVERTISED_TP | ADVERTISED_Autoneg);
			ecmd->port = PORT_TP;
		}
		break;
224
	default:
225
		printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
D
Dhananjay Phadke 已提交
226
				adapter->ahw.board_type);
227
		return -EIO;
A
Amit S. Kale 已提交
228 229
	}

230 231 232 233 234 235 236 237 238 239 240 241
	if (check_sfp_module) {
		switch (adapter->module_type) {
		case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
		case LINKEVENT_MODULE_OPTICAL_SRLR:
		case LINKEVENT_MODULE_OPTICAL_LRM:
		case LINKEVENT_MODULE_OPTICAL_SFP_1G:
			ecmd->port = PORT_FIBRE;
			break;
		case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
		case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
		case LINKEVENT_MODULE_TWINAX:
			ecmd->port = PORT_TP;
242
			break;
243 244 245 246 247
		default:
			ecmd->port = -1;
		}
	}

248
	return 0;
A
Amit S. Kale 已提交
249 250 251 252 253
}

static int
netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
254
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
255
	__u32 status;
A
Amit S. Kale 已提交
256 257

	/* read which mode */
258
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
A
Amit S. Kale 已提交
259
		/* autonegotiation */
260 261 262 263
		if (adapter->phy_write &&
		    adapter->phy_write(adapter,
				       NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
				       ecmd->autoneg) != 0)
A
Amit S. Kale 已提交
264 265
			return -EIO;
		else
266
			adapter->link_autoneg = ecmd->autoneg;
A
Amit S. Kale 已提交
267

268 269 270 271
		if (adapter->phy_read &&
		    adapter->phy_read(adapter,
				      NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
				      &status) != 0)
A
Amit S. Kale 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
			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);
291 292 293 294
		if (adapter->phy_write &&
		    adapter->phy_write(adapter,
				       NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
				       *((int *)&status)) != 0)
A
Amit S. Kale 已提交
295 296
			return -EIO;
		else {
297 298
			adapter->link_speed = ecmd->speed;
			adapter->link_duplex = ecmd->duplex;
A
Amit S. Kale 已提交
299 300 301 302
		}
	} else
		return -EOPNOTSUPP;

303 304 305 306 307
	if (!netif_running(dev))
		return 0;

	dev->netdev_ops->ndo_stop(dev);
	return dev->netdev_ops->ndo_open(dev);
A
Amit S. Kale 已提交
308 309 310 311 312 313 314 315
}

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

struct netxen_niu_regs {
A
Al Viro 已提交
316
	__u32 reg[NETXEN_NIC_REGS_COUNT];
A
Amit S. Kale 已提交
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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
};

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)
{
407
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
408
	__u32 mode, *regs_buff = p;
A
Amit S. Kale 已提交
409 410 411 412
	int i, window;

	memset(p, 0, NETXEN_NIC_REGS_LEN);
	regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
413
	    (adapter->pdev)->device;
A
Amit S. Kale 已提交
414
	/* which mode */
415
	regs_buff[0] = NXRD32(adapter, NETXEN_NIU_MODE);
A
Amit S. Kale 已提交
416 417 418
	mode = regs_buff[0];

	/* Common registers to all the modes */
419
	regs_buff[2] = NXRD32(adapter, NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER);
A
Amit S. Kale 已提交
420 421 422 423 424 425 426
	/* 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)
427
				window = adapter->physical_port *
428
					NETXEN_NIC_PORT_WINDOW;
A
Amit S. Kale 已提交
429

430
			regs_buff[i] = NXRD32(adapter,
431
				niu_registers[mode].reg[i - 3] + window);
A
Amit S. Kale 已提交
432 433 434 435 436
		}

	}
}

437
static u32 netxen_nic_test_link(struct net_device *dev)
A
Amit S. Kale 已提交
438
{
439
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
440
	__u32 status;
441
	int val;
A
Amit S. Kale 已提交
442 443

	/* read which mode */
444
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
445 446 447 448
		if (adapter->phy_read &&
		    adapter->phy_read(adapter,
				      NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
				      &status) != 0)
A
Amit S. Kale 已提交
449
			return -EIO;
450 451 452 453
		else {
			val = netxen_get_phy_link(status);
			return !val;
		}
454
	} else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
455
		val = NXRD32(adapter, CRB_XG_STATE);
456
		return (val == XG_LINK_UP) ? 0 : 1;
A
Amit S. Kale 已提交
457 458 459 460 461 462 463 464
	}
	return -EIO;
}

static int
netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
		      u8 * bytes)
{
465
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Amit S. Kale 已提交
466
	int offset;
467
	int ret;
A
Amit S. Kale 已提交
468 469 470 471

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

472
	eeprom->magic = (adapter->pdev)->vendor |
473
			((adapter->pdev)->device << 16);
474 475
	offset = eeprom->offset;

476
	ret = netxen_rom_fast_read_words(adapter, offset, bytes,
477 478 479 480
						eeprom->len);
	if (ret < 0)
		return ret;

A
Amit S. Kale 已提交
481 482 483 484
	return 0;
}

static void
485 486
netxen_nic_get_ringparam(struct net_device *dev,
		struct ethtool_ringparam *ring)
A
Amit S. Kale 已提交
487
{
488
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Amit S. Kale 已提交
489

490 491 492
	ring->rx_pending = adapter->num_rxd;
	ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
	ring->rx_jumbo_pending += adapter->num_lro_rxd;
493
	ring->tx_pending = adapter->num_txd;
A
Amit S. Kale 已提交
494

495
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
496
		ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
497 498
		ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
	} else {
499
		ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
500 501 502 503 504
		ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
	}

	ring->tx_max_pending = MAX_CMD_DESCRIPTORS;

A
Amit S. Kale 已提交
505 506 507 508
	ring->rx_mini_max_pending = 0;
	ring->rx_mini_pending = 0;
}

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
static u32
netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
{
	u32 num_desc;
	num_desc = max(val, min);
	num_desc = min(num_desc, max);
	num_desc = roundup_pow_of_two(num_desc);

	if (val != num_desc) {
		printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
		       netxen_nic_driver_name, r_name, num_desc, val);
	}

	return num_desc;
}

static int
netxen_nic_set_ringparam(struct net_device *dev,
		struct ethtool_ringparam *ring)
{
	struct netxen_adapter *adapter = netdev_priv(dev);
	u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
	u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
	u16 num_rxd, num_jumbo_rxd, num_txd;

	if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
		return -EOPNOTSUPP;

	if (ring->rx_mini_pending)
		return -EOPNOTSUPP;

	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
		max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
		max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
	}

	num_rxd = netxen_validate_ringparam(ring->rx_pending,
			MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");

	num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
			MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");

	num_txd = netxen_validate_ringparam(ring->tx_pending,
			MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");

	if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
			num_jumbo_rxd == adapter->num_jumbo_rxd)
		return 0;

	adapter->num_rxd = num_rxd;
	adapter->num_jumbo_rxd = num_jumbo_rxd;
	adapter->num_txd = num_txd;

	return netxen_nic_reset_context(adapter);
}

A
Amit S. Kale 已提交
565 566 567 568
static void
netxen_nic_get_pauseparam(struct net_device *dev,
			  struct ethtool_pauseparam *pause)
{
569
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
570
	__u32 val;
571
	int port = adapter->physical_port;
A
Amit S. Kale 已提交
572

573
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
574 575
		if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
			return;
A
Amit S. Kale 已提交
576
		/* get flow control settings */
577
		val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
A
Amit S. Kale 已提交
578
		pause->rx_pause = netxen_gb_get_rx_flowctl(val);
579
		val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
		switch (port) {
			case 0:
				pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
				break;
			case 1:
				pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
				break;
			case 2:
				pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
				break;
			case 3:
			default:
				pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
				break;
		}
595
	} else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
596 597 598
		if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
			return;
		pause->rx_pause = 1;
599
		val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
600 601 602 603 604
		if (port == 0)
			pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
		else
			pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
	} else {
605
		printk(KERN_ERR"%s: Unknown board type: %x\n",
606
				netxen_nic_driver_name, adapter->ahw.port_type);
A
Amit S. Kale 已提交
607 608 609 610 611 612 613
	}
}

static int
netxen_nic_set_pauseparam(struct net_device *dev,
			  struct ethtool_pauseparam *pause)
{
614
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Al Viro 已提交
615
	__u32 val;
616
	int port = adapter->physical_port;
A
Amit S. Kale 已提交
617
	/* read mode */
618
	if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
619 620
		if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
			return -EIO;
A
Amit S. Kale 已提交
621
		/* set flow control */
622
		val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
623

A
Amit S. Kale 已提交
624 625 626 627 628
		if (pause->rx_pause)
			netxen_gb_rx_flowctl(val);
		else
			netxen_gb_unset_rx_flowctl(val);

629
		NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
630
				val);
A
Amit S. Kale 已提交
631
		/* set autoneg */
632
		val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
		switch (port) {
			case 0:
				if (pause->tx_pause)
					netxen_gb_unset_gb0_mask(val);
				else
					netxen_gb_set_gb0_mask(val);
				break;
			case 1:
				if (pause->tx_pause)
					netxen_gb_unset_gb1_mask(val);
				else
					netxen_gb_set_gb1_mask(val);
				break;
			case 2:
				if (pause->tx_pause)
					netxen_gb_unset_gb2_mask(val);
				else
					netxen_gb_set_gb2_mask(val);
				break;
			case 3:
			default:
				if (pause->tx_pause)
					netxen_gb_unset_gb3_mask(val);
				else
					netxen_gb_set_gb3_mask(val);
				break;
		}
660
		NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
661
	} else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
662
		if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
A
Amit S. Kale 已提交
663
			return -EIO;
664
		val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
665 666 667 668 669 670 671 672 673 674
		if (port == 0) {
			if (pause->tx_pause)
				netxen_xg_unset_xg0_mask(val);
			else
				netxen_xg_set_xg0_mask(val);
		} else {
			if (pause->tx_pause)
				netxen_xg_unset_xg1_mask(val);
			else
				netxen_xg_set_xg1_mask(val);
A
Amit S. Kale 已提交
675
		}
676
		NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
677 678
	} else {
		printk(KERN_ERR "%s: Unknown board type: %x\n",
679
				netxen_nic_driver_name,
680
				adapter->ahw.port_type);
681 682
	}
	return 0;
A
Amit S. Kale 已提交
683 684 685 686
}

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

690
	data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
691 692
	if ((data_read & 0xffff) != adapter->pdev->vendor)
		return 1;
A
Amit S. Kale 已提交
693

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

696 697
	NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
	data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
698 699
	if (data_written != data_read)
		return 1;
A
Amit S. Kale 已提交
700

701
	return 0;
A
Amit S. Kale 已提交
702 703
}

704
static int netxen_get_sset_count(struct net_device *dev, int sset)
A
Amit S. Kale 已提交
705
{
706 707 708 709 710 711 712 713
	switch (sset) {
	case ETH_SS_TEST:
		return NETXEN_NIC_TEST_LEN;
	case ETH_SS_STATS:
		return NETXEN_NIC_STATS_LEN;
	default:
		return -EOPNOTSUPP;
	}
A
Amit S. Kale 已提交
714 715 716 717 718 719
}

static void
netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
		     u64 * data)
{
720 721 722 723 724 725
	memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
	if ((data[0] = netxen_nic_reg_test(dev)))
		eth_test->flags |= ETH_TEST_FL_FAILED;
	/* link test */
	if ((data[1] = (u64) netxen_nic_test_link(dev)))
		eth_test->flags |= ETH_TEST_FL_FAILED;
A
Amit S. Kale 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
}

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 void
netxen_nic_get_ethtool_stats(struct net_device *dev,
			     struct ethtool_stats *stats, u64 * data)
{
752
	struct netxen_adapter *adapter = netdev_priv(dev);
A
Amit S. Kale 已提交
753 754 755 756
	int index;

	for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
		char *p =
757 758
		    (char *)adapter +
		    netxen_nic_gstrings_stats[index].stat_offset;
A
Amit S. Kale 已提交
759 760 761 762 763 764
		data[index] =
		    (netxen_nic_gstrings_stats[index].sizeof_stat ==
		     sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
	}
}

D
Dhananjay Phadke 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777
static u32 netxen_nic_get_rx_csum(struct net_device *dev)
{
	struct netxen_adapter *adapter = netdev_priv(dev);
	return adapter->rx_csum;
}

static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
{
	struct netxen_adapter *adapter = netdev_priv(dev);
	adapter->rx_csum = !!data;
	return 0;
}

778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
static u32 netxen_nic_get_tso(struct net_device *dev)
{
	struct netxen_adapter *adapter = netdev_priv(dev);

	if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
		return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;

	return (dev->features & NETIF_F_TSO) != 0;
}

static int netxen_nic_set_tso(struct net_device *dev, u32 data)
{
	if (data) {
		struct netxen_adapter *adapter = netdev_priv(dev);

		dev->features |= NETIF_F_TSO;
		if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
			dev->features |= NETIF_F_TSO6;
	} else
		dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);

	return 0;
}

802 803 804 805 806 807 808 809 810 811 812 813
static void
netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct netxen_adapter *adapter = netdev_priv(dev);
	u32 wol_cfg = 0;

	wol->supported = 0;
	wol->wolopts = 0;

	if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
		return;

814
	wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
815 816 817
	if (wol_cfg & (1UL << adapter->portnum))
		wol->supported |= WAKE_MAGIC;

818
	wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
	if (wol_cfg & (1UL << adapter->portnum))
		wol->wolopts |= WAKE_MAGIC;
}

static int
netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct netxen_adapter *adapter = netdev_priv(dev);
	u32 wol_cfg = 0;

	if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
		return -EOPNOTSUPP;

	if (wol->wolopts & ~WAKE_MAGIC)
		return -EOPNOTSUPP;

835
	wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
836 837 838
	if (!(wol_cfg & (1 << adapter->portnum)))
		return -EOPNOTSUPP;

839
	wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
840 841 842 843
	if (wol->wolopts & WAKE_MAGIC)
		wol_cfg |= 1UL << adapter->portnum;
	else
		wol_cfg &= ~(1UL << adapter->portnum);
844
	NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
845 846 847 848

	return 0;
}

849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
/*
 * Set the coalescing parameters. Currently only normal is supported.
 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
 * firmware coalescing to default.
 */
static int netxen_set_intr_coalesce(struct net_device *netdev,
			struct ethtool_coalesce *ethcoal)
{
	struct netxen_adapter *adapter = netdev_priv(netdev);

	if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
		return -EINVAL;

	if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
		return -EINVAL;

	/*
	* Return Error if unsupported values or
	* unsupported parameters are set.
	*/
	if (ethcoal->rx_coalesce_usecs > 0xffff ||
		ethcoal->rx_max_coalesced_frames > 0xffff ||
		ethcoal->tx_coalesce_usecs > 0xffff ||
		ethcoal->tx_max_coalesced_frames > 0xffff ||
		ethcoal->rx_coalesce_usecs_irq ||
		ethcoal->rx_max_coalesced_frames_irq ||
		ethcoal->tx_coalesce_usecs_irq ||
		ethcoal->tx_max_coalesced_frames_irq ||
		ethcoal->stats_block_coalesce_usecs ||
		ethcoal->use_adaptive_rx_coalesce ||
		ethcoal->use_adaptive_tx_coalesce ||
		ethcoal->pkt_rate_low ||
		ethcoal->rx_coalesce_usecs_low ||
		ethcoal->rx_max_coalesced_frames_low ||
		ethcoal->tx_coalesce_usecs_low ||
		ethcoal->tx_max_coalesced_frames_low ||
		ethcoal->pkt_rate_high ||
		ethcoal->rx_coalesce_usecs_high ||
		ethcoal->rx_max_coalesced_frames_high ||
		ethcoal->tx_coalesce_usecs_high ||
		ethcoal->tx_max_coalesced_frames_high)
		return -EINVAL;

	if (!ethcoal->rx_coalesce_usecs ||
		!ethcoal->rx_max_coalesced_frames) {
		adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
		adapter->coal.normal.data.rx_time_us =
			NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
		adapter->coal.normal.data.rx_packets =
			NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
	} else {
		adapter->coal.flags = 0;
		adapter->coal.normal.data.rx_time_us =
		ethcoal->rx_coalesce_usecs;
		adapter->coal.normal.data.rx_packets =
		ethcoal->rx_max_coalesced_frames;
	}
	adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
	adapter->coal.normal.data.tx_packets =
	ethcoal->tx_max_coalesced_frames;

	netxen_config_intr_coalesce(adapter);

	return 0;
}

static int netxen_get_intr_coalesce(struct net_device *netdev,
			struct ethtool_coalesce *ethcoal)
{
	struct netxen_adapter *adapter = netdev_priv(netdev);

	if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
		return -EINVAL;

	if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
		return -EINVAL;

	ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
	ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
	ethcoal->rx_max_coalesced_frames =
		adapter->coal.normal.data.rx_packets;
	ethcoal->tx_max_coalesced_frames =
		adapter->coal.normal.data.tx_packets;

	return 0;
}

936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
static int netxen_nic_set_flags(struct net_device *netdev, u32 data)
{
	struct netxen_adapter *adapter = netdev_priv(netdev);
	int hw_lro;

	if (!(adapter->capabilities & NX_FW_CAPABILITY_HW_LRO))
		return -EINVAL;

	ethtool_op_set_flags(netdev, data);

	hw_lro = (data & ETH_FLAG_LRO) ? NETXEN_NIC_LRO_ENABLED : 0;

	if (netxen_config_hw_lro(adapter, hw_lro))
		return -EIO;

	if ((hw_lro == 0) && netxen_send_lro_cleanup(adapter))
		return -EIO;


	return 0;
}

958
const struct ethtool_ops netxen_nic_ethtool_ops = {
A
Amit S. Kale 已提交
959 960 961 962 963
	.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,
964
	.get_link = ethtool_op_get_link,
A
Amit S. Kale 已提交
965 966 967
	.get_eeprom_len = netxen_nic_get_eeprom_len,
	.get_eeprom = netxen_nic_get_eeprom,
	.get_ringparam = netxen_nic_get_ringparam,
968
	.set_ringparam = netxen_nic_set_ringparam,
A
Amit S. Kale 已提交
969 970 971 972
	.get_pauseparam = netxen_nic_get_pauseparam,
	.set_pauseparam = netxen_nic_set_pauseparam,
	.set_tx_csum = ethtool_op_set_tx_csum,
	.set_sg = ethtool_op_set_sg,
973 974
	.get_tso = netxen_nic_get_tso,
	.set_tso = netxen_nic_set_tso,
975 976
	.get_wol = netxen_nic_get_wol,
	.set_wol = netxen_nic_set_wol,
A
Amit S. Kale 已提交
977 978 979
	.self_test = netxen_nic_diag_test,
	.get_strings = netxen_nic_get_strings,
	.get_ethtool_stats = netxen_nic_get_ethtool_stats,
980
	.get_sset_count = netxen_get_sset_count,
D
Dhananjay Phadke 已提交
981 982
	.get_rx_csum = netxen_nic_get_rx_csum,
	.set_rx_csum = netxen_nic_set_rx_csum,
983 984
	.get_coalesce = netxen_get_intr_coalesce,
	.set_coalesce = netxen_set_intr_coalesce,
985 986
	.get_flags = ethtool_op_get_flags,
	.set_flags = netxen_nic_set_flags,
A
Amit S. Kale 已提交
987
};