qlcnic_ethtool.c 51.8 KB
Newer Older
1
/*
S
Sritej Velaga 已提交
2
 * QLogic qlcnic NIC Driver
3
 * Copyright (c) 2009-2013 QLogic Corporation
4
 *
S
Sritej Velaga 已提交
5
 * See LICENSE.qlcnic for copyright and licensing details.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 */

#include <linux/types.h>
#include <linux/delay.h>
#include <linux/pci.h>
#include <linux/io.h>
#include <linux/netdevice.h>
#include <linux/ethtool.h>

#include "qlcnic.h"

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

#define QLC_SIZEOF(m) FIELD_SIZEOF(struct qlcnic_adapter, m)
#define QLC_OFF(m) offsetof(struct qlcnic_adapter, m)
25 26 27
static const u32 qlcnic_fw_dump_level[] = {
	0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
};
28 29

static const struct qlcnic_stats qlcnic_gstrings_stats[] = {
30 31
	{"xmit_on", QLC_SIZEOF(stats.xmit_on), QLC_OFF(stats.xmit_on)},
	{"xmit_off", QLC_SIZEOF(stats.xmit_off), QLC_OFF(stats.xmit_off)},
32
	{"xmit_called", QLC_SIZEOF(stats.xmitcalled),
33
	 QLC_OFF(stats.xmitcalled)},
34
	{"xmit_finished", QLC_SIZEOF(stats.xmitfinished),
35 36 37 38
	 QLC_OFF(stats.xmitfinished)},
	{"tx dma map error", QLC_SIZEOF(stats.tx_dma_map_error),
	 QLC_OFF(stats.tx_dma_map_error)},
	{"tx_bytes", QLC_SIZEOF(stats.txbytes), QLC_OFF(stats.txbytes)},
39
	{"tx_dropped", QLC_SIZEOF(stats.txdropped), QLC_OFF(stats.txdropped)},
40 41
	{"rx dma map error", QLC_SIZEOF(stats.rx_dma_map_error),
	 QLC_OFF(stats.rx_dma_map_error)},
42 43
	{"rx_pkts", QLC_SIZEOF(stats.rx_pkts), QLC_OFF(stats.rx_pkts)},
	{"rx_bytes", QLC_SIZEOF(stats.rxbytes), QLC_OFF(stats.rxbytes)},
44 45 46 47
	{"rx_dropped", QLC_SIZEOF(stats.rxdropped), QLC_OFF(stats.rxdropped)},
	{"null rxbuf", QLC_SIZEOF(stats.null_rxbuf), QLC_OFF(stats.null_rxbuf)},
	{"csummed", QLC_SIZEOF(stats.csummed), QLC_OFF(stats.csummed)},
	{"lro_pkts", QLC_SIZEOF(stats.lro_pkts), QLC_OFF(stats.lro_pkts)},
48 49
	{"lrobytes", QLC_SIZEOF(stats.lrobytes), QLC_OFF(stats.lrobytes)},
	{"lso_frames", QLC_SIZEOF(stats.lso_frames), QLC_OFF(stats.lso_frames)},
50
	{"skb_alloc_failure", QLC_SIZEOF(stats.skb_alloc_failure),
51 52
	 QLC_OFF(stats.skb_alloc_failure)},
	{"mac_filter_limit_overrun", QLC_SIZEOF(stats.mac_filter_limit_overrun),
53
	 QLC_OFF(stats.mac_filter_limit_overrun)},
54 55
	{"spurious intr", QLC_SIZEOF(stats.spurious_intr),
	 QLC_OFF(stats.spurious_intr)},
56

57 58
};

A
amit salecha 已提交
59 60 61 62 63 64 65 66
static const char qlcnic_device_gstrings_stats[][ETH_GSTRING_LEN] = {
	"tx unicast frames",
	"tx multicast frames",
	"tx broadcast frames",
	"tx dropped frames",
	"tx errors",
	"tx local frames",
	"tx numbytes",
67 68 69 70 71 72 73
	"rx unicast frames",
	"rx multicast frames",
	"rx broadcast frames",
	"rx dropped frames",
	"rx errors",
	"rx local frames",
	"rx numbytes",
A
amit salecha 已提交
74 75
};

76 77 78 79 80 81 82 83 84
static const char qlcnic_83xx_tx_stats_strings[][ETH_GSTRING_LEN] = {
	"ctx_tx_bytes",
	"ctx_tx_pkts",
	"ctx_tx_errors",
	"ctx_tx_dropped_pkts",
	"ctx_tx_num_buffers",
};

static const char qlcnic_83xx_mac_stats_strings[][ETH_GSTRING_LEN] = {
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	"mac_tx_frames",
	"mac_tx_bytes",
	"mac_tx_mcast_pkts",
	"mac_tx_bcast_pkts",
	"mac_tx_pause_cnt",
	"mac_tx_ctrl_pkt",
	"mac_tx_lt_64b_pkts",
	"mac_tx_lt_127b_pkts",
	"mac_tx_lt_255b_pkts",
	"mac_tx_lt_511b_pkts",
	"mac_tx_lt_1023b_pkts",
	"mac_tx_lt_1518b_pkts",
	"mac_tx_gt_1518b_pkts",
	"mac_rx_frames",
	"mac_rx_bytes",
	"mac_rx_mcast_pkts",
	"mac_rx_bcast_pkts",
	"mac_rx_pause_cnt",
	"mac_rx_ctrl_pkt",
	"mac_rx_lt_64b_pkts",
	"mac_rx_lt_127b_pkts",
	"mac_rx_lt_255b_pkts",
	"mac_rx_lt_511b_pkts",
	"mac_rx_lt_1023b_pkts",
	"mac_rx_lt_1518b_pkts",
	"mac_rx_gt_1518b_pkts",
	"mac_rx_length_error",
	"mac_rx_length_small",
	"mac_rx_length_large",
	"mac_rx_jabber",
	"mac_rx_dropped",
116
	"mac_crc_error",
117
	"mac_align_error",
118 119 120 121 122 123 124
	"eswitch_frames",
	"eswitch_bytes",
	"eswitch_multicast_frames",
	"eswitch_broadcast_frames",
	"eswitch_unicast_frames",
	"eswitch_error_free_frames",
	"eswitch_error_free_bytes",
125 126
};

127
#define QLCNIC_STATS_LEN	ARRAY_SIZE(qlcnic_gstrings_stats)
128

129
static const char qlcnic_tx_queue_stats_strings[][ETH_GSTRING_LEN] = {
130 131 132 133
	"xmit_on",
	"xmit_off",
	"xmit_called",
	"xmit_finished",
134
	"tx_bytes",
135 136
};

137 138
#define QLCNIC_TX_STATS_LEN	ARRAY_SIZE(qlcnic_tx_queue_stats_strings)

139 140 141 142 143 144
static const char qlcnic_83xx_rx_stats_strings[][ETH_GSTRING_LEN] = {
	"ctx_rx_bytes",
	"ctx_rx_pkts",
	"ctx_lro_pkt_cnt",
	"ctx_ip_csum_error",
	"ctx_rx_pkts_wo_ctx",
S
Shahed Shaikh 已提交
145 146
	"ctx_rx_pkts_drop_wo_sds_on_card",
	"ctx_rx_pkts_drop_wo_sds_on_host",
147 148 149 150
	"ctx_rx_osized_pkts",
	"ctx_rx_pkts_dropped_wo_rds",
	"ctx_rx_unexpected_mcast_pkts",
	"ctx_invalid_mac_address",
S
Shahed Shaikh 已提交
151
	"ctx_rx_rds_ring_prim_attempted",
152 153 154 155 156 157
	"ctx_rx_rds_ring_prim_success",
	"ctx_num_lro_flows_added",
	"ctx_num_lro_flows_removed",
	"ctx_num_lro_flows_active",
	"ctx_pkts_dropped_unknown",
};
158 159 160

static const char qlcnic_gstrings_test[][ETH_GSTRING_LEN] = {
	"Register_Test_on_offline",
161
	"Link_Test_on_offline",
162
	"Interrupt_Test_offline",
163
	"Internal_Loopback_offline",
164
	"External_Loopback_offline",
165
	"EEPROM_Test_offline"
166 167 168 169
};

#define QLCNIC_TEST_LEN	ARRAY_SIZE(qlcnic_gstrings_test)

170
static inline int qlcnic_82xx_statistics(struct qlcnic_adapter *adapter)
171
{
172 173 174
	return ARRAY_SIZE(qlcnic_gstrings_stats) +
	       ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
	       QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
175 176
}

177
static inline int qlcnic_83xx_statistics(struct qlcnic_adapter *adapter)
178
{
179 180
	return ARRAY_SIZE(qlcnic_gstrings_stats) +
	       ARRAY_SIZE(qlcnic_83xx_tx_stats_strings) +
181
	       ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
182 183
	       ARRAY_SIZE(qlcnic_83xx_rx_stats_strings) +
	       QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
184 185 186 187
}

static int qlcnic_dev_statistics_len(struct qlcnic_adapter *adapter)
{
188 189 190 191 192 193 194 195 196 197 198
	int len = -1;

	if (qlcnic_82xx_check(adapter)) {
		len = qlcnic_82xx_statistics(adapter);
		if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
			len += ARRAY_SIZE(qlcnic_device_gstrings_stats);
	} else if (qlcnic_83xx_check(adapter)) {
		len = qlcnic_83xx_statistics(adapter);
	}

	return len;
199 200
}

201 202
#define	QLCNIC_TX_INTR_NOT_CONFIGURED	0X78563412

203 204 205
#define QLCNIC_MAX_EEPROM_LEN   1024

static const u32 diag_registers[] = {
206 207 208
	QLCNIC_CMDPEG_STATE,
	QLCNIC_RCVPEG_STATE,
	QLCNIC_FW_CAPABILITIES,
A
Amit Kumar Salecha 已提交
209
	QLCNIC_CRB_DRV_ACTIVE,
210 211 212 213 214 215 216 217
	QLCNIC_CRB_DEV_STATE,
	QLCNIC_CRB_DRV_STATE,
	QLCNIC_CRB_DRV_SCRATCH,
	QLCNIC_CRB_DEV_PARTITION_INFO,
	QLCNIC_CRB_DRV_IDC_VER,
	QLCNIC_PEG_ALIVE_COUNTER,
	QLCNIC_PEG_HALT_STATUS1,
	QLCNIC_PEG_HALT_STATUS2,
218 219 220
	-1
};

221

222 223 224
static const u32 ext_diag_registers[] = {
	CRB_XG_STATE_P3P,
	ISR_INT_STATE_REG,
225 226 227 228 229 230 231
	QLCNIC_CRB_PEG_NET_0+0x3c,
	QLCNIC_CRB_PEG_NET_1+0x3c,
	QLCNIC_CRB_PEG_NET_2+0x3c,
	QLCNIC_CRB_PEG_NET_4+0x3c,
	-1
};

232
#define QLCNIC_MGMT_API_VERSION	3
233 234 235 236
#define QLCNIC_ETHTOOL_REGS_VER	4

static inline int qlcnic_get_ring_regs_len(struct qlcnic_adapter *adapter)
{
237
	int ring_regs_cnt = (adapter->drv_tx_rings * 5) +
238
			    (adapter->max_rds_rings * 2) +
239
			    (adapter->drv_sds_rings * 3) + 5;
240 241
	return ring_regs_cnt * sizeof(u32);
}
242

243 244
static int qlcnic_get_regs_len(struct net_device *dev)
{
245 246 247 248 249 250 251 252
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	u32 len;

	if (qlcnic_83xx_check(adapter))
		len = qlcnic_83xx_get_regs_len(adapter);
	else
		len = sizeof(ext_diag_registers) + sizeof(diag_registers);

253 254 255
	len += ((QLCNIC_DEV_INFO_SIZE + 2) * sizeof(u32));
	len += qlcnic_get_ring_regs_len(adapter);
	return len;
256 257 258 259 260 261 262 263 264 265 266 267
}

static int qlcnic_get_eeprom_len(struct net_device *dev)
{
	return QLCNIC_FLASH_TOTAL_SIZE;
}

static void
qlcnic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	u32 fw_major, fw_minor, fw_build;
268 269 270
	fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
	fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
	fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
271 272 273 274 275 276 277 278
	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
		"%d.%d.%d", fw_major, fw_minor, fw_build);

	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
		sizeof(drvinfo->bus_info));
	strlcpy(drvinfo->driver, qlcnic_driver_name, sizeof(drvinfo->driver));
	strlcpy(drvinfo->version, QLCNIC_LINUX_VERSIONID,
		sizeof(drvinfo->version));
279 280
}

281 282
static int qlcnic_82xx_get_settings(struct qlcnic_adapter *adapter,
				    struct ethtool_cmd *ecmd)
283
{
284 285
	struct qlcnic_hardware_context *ahw = adapter->ahw;
	u32 speed, reg;
286
	int check_sfp_module = 0, err = 0;
287
	u16 pcifn = ahw->pci_func;
288 289

	/* read which mode */
A
Anirban Chakraborty 已提交
290
	if (adapter->ahw->port_type == QLCNIC_GBE) {
291 292 293 294 295 296 297 298 299 300 301 302
		ecmd->supported = (SUPPORTED_10baseT_Half |
				   SUPPORTED_10baseT_Full |
				   SUPPORTED_100baseT_Half |
				   SUPPORTED_100baseT_Full |
				   SUPPORTED_1000baseT_Half |
				   SUPPORTED_1000baseT_Full);

		ecmd->advertising = (ADVERTISED_100baseT_Half |
				     ADVERTISED_100baseT_Full |
				     ADVERTISED_1000baseT_Half |
				     ADVERTISED_1000baseT_Full);

303 304 305
		ethtool_cmd_speed_set(ecmd, adapter->ahw->link_speed);
		ecmd->duplex = adapter->ahw->link_duplex;
		ecmd->autoneg = adapter->ahw->link_autoneg;
306

A
Anirban Chakraborty 已提交
307
	} else if (adapter->ahw->port_type == QLCNIC_XGBE) {
308
		u32 val = 0;
309
		val = QLCRD32(adapter, QLCNIC_PORT_MODE_ADDR, &err);
310 311 312 313 314 315 316 317 318

		if (val == QLCNIC_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;
		}

319
		if (netif_running(adapter->netdev) && ahw->has_link_events) {
320 321
			if (ahw->linkup) {
				reg = QLCRD32(adapter,
322
					      P3P_LINK_SPEED_REG(pcifn), &err);
323 324 325 326
				speed = P3P_LINK_SPEED_VAL(pcifn, reg);
				ahw->link_speed = speed * P3P_LINK_SPEED_MHZ;
			}

327 328 329
			ethtool_cmd_speed_set(ecmd, ahw->link_speed);
			ecmd->autoneg = ahw->link_autoneg;
			ecmd->duplex = ahw->link_duplex;
330 331 332
			goto skip;
		}

333 334
		ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
		ecmd->duplex = DUPLEX_UNKNOWN;
335 336 337 338 339
		ecmd->autoneg = AUTONEG_DISABLE;
	} else
		return -EIO;

skip:
340
	ecmd->phy_address = adapter->ahw->physical_port;
341 342
	ecmd->transceiver = XCVR_EXTERNAL;

A
Anirban Chakraborty 已提交
343
	switch (adapter->ahw->board_type) {
344 345 346
	case QLCNIC_BRDTYPE_P3P_REF_QG:
	case QLCNIC_BRDTYPE_P3P_4_GB:
	case QLCNIC_BRDTYPE_P3P_4_GB_MM:
347 348 349

		ecmd->supported |= SUPPORTED_Autoneg;
		ecmd->advertising |= ADVERTISED_Autoneg;
350 351 352
	case QLCNIC_BRDTYPE_P3P_10G_CX4:
	case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
	case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
353 354 355
		ecmd->supported |= SUPPORTED_TP;
		ecmd->advertising |= ADVERTISED_TP;
		ecmd->port = PORT_TP;
356
		ecmd->autoneg =  adapter->ahw->link_autoneg;
357
		break;
358 359 360
	case QLCNIC_BRDTYPE_P3P_IMEZ:
	case QLCNIC_BRDTYPE_P3P_XG_LOM:
	case QLCNIC_BRDTYPE_P3P_HMEZ:
361 362 363 364 365
		ecmd->supported |= SUPPORTED_MII;
		ecmd->advertising |= ADVERTISED_MII;
		ecmd->port = PORT_MII;
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
366 367 368
	case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
	case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
	case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
369 370
		ecmd->advertising |= ADVERTISED_TP;
		ecmd->supported |= SUPPORTED_TP;
371 372
		check_sfp_module = netif_running(adapter->netdev) &&
				   ahw->has_link_events;
373
	case QLCNIC_BRDTYPE_P3P_10G_XFP:
374 375 376 377 378
		ecmd->supported |= SUPPORTED_FIBRE;
		ecmd->advertising |= ADVERTISED_FIBRE;
		ecmd->port = PORT_FIBRE;
		ecmd->autoneg = AUTONEG_DISABLE;
		break;
379
	case QLCNIC_BRDTYPE_P3P_10G_TP:
A
Anirban Chakraborty 已提交
380
		if (adapter->ahw->port_type == QLCNIC_XGBE) {
381 382 383 384 385
			ecmd->autoneg = AUTONEG_DISABLE;
			ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
			ecmd->advertising |=
				(ADVERTISED_FIBRE | ADVERTISED_TP);
			ecmd->port = PORT_FIBRE;
386 387
			check_sfp_module = netif_running(adapter->netdev) &&
					   ahw->has_link_events;
388 389 390 391 392 393 394 395 396 397
		} else {
			ecmd->autoneg = AUTONEG_ENABLE;
			ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
			ecmd->advertising |=
				(ADVERTISED_TP | ADVERTISED_Autoneg);
			ecmd->port = PORT_TP;
		}
		break;
	default:
		dev_err(&adapter->pdev->dev, "Unsupported board model %d\n",
A
Anirban Chakraborty 已提交
398
			adapter->ahw->board_type);
399 400 401 402
		return -EIO;
	}

	if (check_sfp_module) {
403
		switch (adapter->ahw->module_type) {
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
		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;
			break;
		default:
			ecmd->port = PORT_OTHER;
		}
	}

	return 0;
}

423 424 425 426 427 428 429 430 431 432 433 434 435 436
static int qlcnic_get_settings(struct net_device *dev,
			       struct ethtool_cmd *ecmd)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);

	if (qlcnic_82xx_check(adapter))
		return qlcnic_82xx_get_settings(adapter, ecmd);
	else if (qlcnic_83xx_check(adapter))
		return qlcnic_83xx_get_settings(adapter, ecmd);

	return -EIO;
}


437 438
static int qlcnic_set_port_config(struct qlcnic_adapter *adapter,
				  struct ethtool_cmd *ecmd)
439
{
440
	u32 ret = 0, config = 0;
441
	/* read which mode */
442 443
	if (ecmd->duplex)
		config |= 0x1;
444

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
	if (ecmd->autoneg)
		config |= 0x2;

	switch (ethtool_cmd_speed(ecmd)) {
	case SPEED_10:
		config |= (0 << 8);
		break;
	case SPEED_100:
		config |= (1 << 8);
		break;
	case SPEED_1000:
		config |= (10 << 8);
		break;
	default:
		return -EIO;
	}

	ret = qlcnic_fw_cmd_set_port(adapter, config);

	if (ret == QLCNIC_RCODE_NOT_SUPPORTED)
465
		return -EOPNOTSUPP;
466 467
	else if (ret)
		return -EIO;
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
	return ret;
}

static int qlcnic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
	u32 ret = 0;
	struct qlcnic_adapter *adapter = netdev_priv(dev);

	if (adapter->ahw->port_type != QLCNIC_GBE)
		return -EOPNOTSUPP;

	if (qlcnic_83xx_check(adapter))
		ret = qlcnic_83xx_set_settings(adapter, ecmd);
	else
		ret = qlcnic_set_port_config(adapter, ecmd);

	if (!ret)
		return ret;
486

487 488 489
	adapter->ahw->link_speed = ethtool_cmd_speed(ecmd);
	adapter->ahw->link_duplex = ecmd->duplex;
	adapter->ahw->link_autoneg = ecmd->autoneg;
490 491 492 493 494 495 496 497

	if (!netif_running(dev))
		return 0;

	dev->netdev_ops->ndo_stop(dev);
	return dev->netdev_ops->ndo_open(dev);
}

498 499 500
static int qlcnic_82xx_get_registers(struct qlcnic_adapter *adapter,
				     u32 *regs_buff)
{
501
	int i, j = 0, err = 0;
502 503 504 505 506

	for (i = QLCNIC_DEV_INFO_SIZE + 1; diag_registers[j] != -1; j++, i++)
		regs_buff[i] = QLC_SHARED_REG_RD32(adapter, diag_registers[j]);
	j = 0;
	while (ext_diag_registers[j] != -1)
507 508
		regs_buff[i++] = QLCRD32(adapter, ext_diag_registers[j++],
					 &err);
509 510 511
	return i;
}

512 513 514 515
static void
qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
A
Anirban Chakraborty 已提交
516
	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
517
	struct qlcnic_host_sds_ring *sds_ring;
518 519
	struct qlcnic_host_rds_ring *rds_rings;
	struct qlcnic_host_tx_ring *tx_ring;
520
	u32 *regs_buff = p;
521
	int ring, i = 0;
522 523

	memset(p, 0, qlcnic_get_regs_len(dev));
524

525
	regs->version = (QLCNIC_ETHTOOL_REGS_VER << 24) |
A
Anirban Chakraborty 已提交
526
		(adapter->ahw->revision_id << 16) | (adapter->pdev)->device;
527

528 529 530
	regs_buff[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE & 0xffff));
	regs_buff[1] = QLCNIC_MGMT_API_VERSION;

531 532 533
	if (adapter->ahw->capabilities & QLC_83XX_ESWITCH_CAPABILITY)
		regs_buff[2] = adapter->ahw->max_vnic_func;

534 535 536 537
	if (qlcnic_82xx_check(adapter))
		i = qlcnic_82xx_get_registers(adapter, regs_buff);
	else
		i = qlcnic_83xx_get_registers(adapter, regs_buff);
538

539
	if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
540 541
		return;

542 543 544
	/* Marker btw regs and TX ring count */
	regs_buff[i++] = 0xFFEFCDAB;

545 546
	regs_buff[i++] = adapter->drv_tx_rings; /* No. of TX ring */
	for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
547 548 549 550 551 552 553 554 555 556
		tx_ring = &adapter->tx_ring[ring];
		regs_buff[i++] = le32_to_cpu(*(tx_ring->hw_consumer));
		regs_buff[i++] = tx_ring->sw_consumer;
		regs_buff[i++] = readl(tx_ring->crb_cmd_producer);
		regs_buff[i++] = tx_ring->producer;
		if (tx_ring->crb_intr_mask)
			regs_buff[i++] = readl(tx_ring->crb_intr_mask);
		else
			regs_buff[i++] = QLCNIC_TX_INTR_NOT_CONFIGURED;
	}
557

558 559 560 561 562 563
	regs_buff[i++] = adapter->max_rds_rings; /* No. of RX ring */
	for (ring = 0; ring < adapter->max_rds_rings; ring++) {
		rds_rings = &recv_ctx->rds_rings[ring];
		regs_buff[i++] = readl(rds_rings->crb_rcv_producer);
		regs_buff[i++] = rds_rings->producer;
	}
564

565 566
	regs_buff[i++] = adapter->drv_sds_rings; /* No. of SDS ring */
	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
567 568
		sds_ring = &(recv_ctx->sds_rings[ring]);
		regs_buff[i++] = readl(sds_ring->crb_sts_consumer);
569 570
		regs_buff[i++] = sds_ring->consumer;
		regs_buff[i++] = readl(sds_ring->crb_intr_mask);
571 572 573 574 575 576
	}
}

static u32 qlcnic_test_link(struct net_device *dev)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
577
	int err = 0;
578 579
	u32 val;

580 581 582 583
	if (qlcnic_83xx_check(adapter)) {
		val = qlcnic_83xx_test_link(adapter);
		return (val & 1) ? 0 : 1;
	}
584 585 586
	val = QLCRD32(adapter, CRB_XG_STATE_P3P, &err);
	if (err == -EIO)
		return err;
A
Anirban Chakraborty 已提交
587
	val = XG_LINK_STATE_P3P(adapter->ahw->pci_func, val);
588
	return (val == XG_LINK_UP_P3P) ? 0 : 1;
589 590 591 592 593 594 595 596
}

static int
qlcnic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
		      u8 *bytes)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	int offset;
597
	int ret = -1;
598

599 600
	if (qlcnic_83xx_check(adapter))
		return 0;
601 602 603 604 605 606 607
	if (eeprom->len == 0)
		return -EINVAL;

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

608 609 610
	if (qlcnic_82xx_check(adapter))
		ret = qlcnic_rom_fast_read_words(adapter, offset, bytes,
						 eeprom->len);
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
	if (ret < 0)
		return ret;

	return 0;
}

static void
qlcnic_get_ringparam(struct net_device *dev,
		struct ethtool_ringparam *ring)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);

	ring->rx_pending = adapter->num_rxd;
	ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
	ring->tx_pending = adapter->num_txd;

S
Sony Chacko 已提交
627 628
	ring->rx_max_pending = adapter->max_rxd;
	ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd;
629 630 631 632 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
	ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
}

static u32
qlcnic_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",
		       qlcnic_driver_name, r_name, num_desc, val);
	}

	return num_desc;
}

static int
qlcnic_set_ringparam(struct net_device *dev,
		struct ethtool_ringparam *ring)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	u16 num_rxd, num_jumbo_rxd, num_txd;

	if (ring->rx_mini_pending)
		return -EOPNOTSUPP;

	num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
S
Sony Chacko 已提交
659
			MIN_RCV_DESCRIPTORS, adapter->max_rxd, "rx");
660 661

	num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
S
Sony Chacko 已提交
662 663
			MIN_JUMBO_DESCRIPTORS, adapter->max_jumbo_rxd,
						"rx jumbo");
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678

	num_txd = qlcnic_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 qlcnic_reset_context(adapter);
}

679 680 681
static int qlcnic_validate_ring_count(struct qlcnic_adapter *adapter,
				      u8 rx_ring, u8 tx_ring)
{
682 683 684
	if (rx_ring == 0 || tx_ring == 0)
		return -EINVAL;

685 686
	if (rx_ring != 0) {
		if (rx_ring > adapter->max_sds_rings) {
687 688
			netdev_err(adapter->netdev,
				   "Invalid ring count, SDS ring count %d should not be greater than max %d driver sds rings.\n",
689 690 691 692 693 694
				   rx_ring, adapter->max_sds_rings);
			return -EINVAL;
		}
	}

	 if (tx_ring != 0) {
695
		if (tx_ring > adapter->max_tx_rings) {
696 697 698 699 700 701 702 703 704 705
			netdev_err(adapter->netdev,
				   "Invalid ring count, Tx ring count %d should not be greater than max %d driver Tx rings.\n",
				   tx_ring, adapter->max_tx_rings);
			return -EINVAL;
		}
	}

	return 0;
}

706 707 708 709 710
static void qlcnic_get_channels(struct net_device *dev,
		struct ethtool_channels *channel)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);

711 712 713 714
	channel->max_rx = adapter->max_sds_rings;
	channel->max_tx = adapter->max_tx_rings;
	channel->rx_count = adapter->drv_sds_rings;
	channel->tx_count = adapter->drv_tx_rings;
715 716 717
}

static int qlcnic_set_channels(struct net_device *dev,
718
			       struct ethtool_channels *channel)
719 720 721 722
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	int err;

723
	if (channel->other_count || channel->combined_count)
724 725
		return -EINVAL;

726 727 728 729 730
	err = qlcnic_validate_ring_count(adapter, channel->rx_count,
					 channel->tx_count);
	if (err)
		return err;

731
	if (channel->rx_count) {
732 733 734 735 736
		err = qlcnic_validate_rings(adapter, channel->rx_count,
					    QLCNIC_RX_QUEUE);
		if (err) {
			netdev_err(dev, "Unable to configure %u SDS rings\n",
				   channel->rx_count);
737
			return err;
738
		}
739 740
	}

741
	if (channel->tx_count) {
742 743 744 745 746
		err = qlcnic_validate_rings(adapter, channel->tx_count,
					    QLCNIC_TX_QUEUE);
		if (err) {
			netdev_err(dev, "Unable to configure %u Tx rings\n",
				   channel->tx_count);
747
			return err;
748
		}
749
	}
750

751 752 753 754 755
	err = qlcnic_setup_rings(adapter, channel->rx_count,
				 channel->tx_count);
	netdev_info(dev, "Allocated %d SDS rings and %d Tx rings\n",
		    adapter->drv_sds_rings, adapter->drv_tx_rings);

756 757 758
	return err;
}

759 760 761 762 763
static void
qlcnic_get_pauseparam(struct net_device *netdev,
			  struct ethtool_pauseparam *pause)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
764
	int port = adapter->ahw->physical_port;
765
	int err = 0;
766 767
	__u32 val;

768 769 770 771
	if (qlcnic_83xx_check(adapter)) {
		qlcnic_83xx_get_pauseparam(adapter, pause);
		return;
	}
A
Anirban Chakraborty 已提交
772
	if (adapter->ahw->port_type == QLCNIC_GBE) {
773 774 775
		if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
			return;
		/* get flow control settings */
776 777 778
		val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
		if (err == -EIO)
			return;
779
		pause->rx_pause = qlcnic_gb_get_rx_flowctl(val);
780 781 782
		val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
		if (err == -EIO)
			return;
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
		switch (port) {
		case 0:
			pause->tx_pause = !(qlcnic_gb_get_gb0_mask(val));
			break;
		case 1:
			pause->tx_pause = !(qlcnic_gb_get_gb1_mask(val));
			break;
		case 2:
			pause->tx_pause = !(qlcnic_gb_get_gb2_mask(val));
			break;
		case 3:
		default:
			pause->tx_pause = !(qlcnic_gb_get_gb3_mask(val));
			break;
		}
A
Anirban Chakraborty 已提交
798
	} else if (adapter->ahw->port_type == QLCNIC_XGBE) {
799 800 801
		if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
			return;
		pause->rx_pause = 1;
802 803 804
		val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
		if (err == -EIO)
			return;
805 806 807 808 809 810
		if (port == 0)
			pause->tx_pause = !(qlcnic_xg_get_xg0_mask(val));
		else
			pause->tx_pause = !(qlcnic_xg_get_xg1_mask(val));
	} else {
		dev_err(&netdev->dev, "Unknown board type: %x\n",
A
Anirban Chakraborty 已提交
811
					adapter->ahw->port_type);
812 813 814 815 816 817 818 819
	}
}

static int
qlcnic_set_pauseparam(struct net_device *netdev,
			  struct ethtool_pauseparam *pause)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
820
	int port = adapter->ahw->physical_port;
821
	int err = 0;
822 823
	__u32 val;

824 825 826
	if (qlcnic_83xx_check(adapter))
		return qlcnic_83xx_set_pauseparam(adapter, pause);

827
	/* read mode */
A
Anirban Chakraborty 已提交
828
	if (adapter->ahw->port_type == QLCNIC_GBE) {
829 830 831
		if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
			return -EIO;
		/* set flow control */
832 833 834
		val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
		if (err == -EIO)
			return err;
835 836 837 838 839 840 841 842

		if (pause->rx_pause)
			qlcnic_gb_rx_flowctl(val);
		else
			qlcnic_gb_unset_rx_flowctl(val);

		QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port),
				val);
843
		QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), val);
844
		/* set autoneg */
845 846 847
		val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
		if (err == -EIO)
			return err;
848 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
		switch (port) {
		case 0:
			if (pause->tx_pause)
				qlcnic_gb_unset_gb0_mask(val);
			else
				qlcnic_gb_set_gb0_mask(val);
			break;
		case 1:
			if (pause->tx_pause)
				qlcnic_gb_unset_gb1_mask(val);
			else
				qlcnic_gb_set_gb1_mask(val);
			break;
		case 2:
			if (pause->tx_pause)
				qlcnic_gb_unset_gb2_mask(val);
			else
				qlcnic_gb_set_gb2_mask(val);
			break;
		case 3:
		default:
			if (pause->tx_pause)
				qlcnic_gb_unset_gb3_mask(val);
			else
				qlcnic_gb_set_gb3_mask(val);
			break;
		}
		QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, val);
A
Anirban Chakraborty 已提交
876
	} else if (adapter->ahw->port_type == QLCNIC_XGBE) {
877 878 879
		if (!pause->rx_pause || pause->autoneg)
			return -EOPNOTSUPP;

880 881
		if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
			return -EIO;
882

883 884 885
		val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
		if (err == -EIO)
			return err;
886 887 888 889 890 891 892 893 894 895 896 897 898 899
		if (port == 0) {
			if (pause->tx_pause)
				qlcnic_xg_unset_xg0_mask(val);
			else
				qlcnic_xg_set_xg0_mask(val);
		} else {
			if (pause->tx_pause)
				qlcnic_xg_unset_xg1_mask(val);
			else
				qlcnic_xg_set_xg1_mask(val);
		}
		QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, val);
	} else {
		dev_err(&netdev->dev, "Unknown board type: %x\n",
A
Anirban Chakraborty 已提交
900
				adapter->ahw->port_type);
901 902 903 904 905 906 907
	}
	return 0;
}

static int qlcnic_reg_test(struct net_device *dev)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
908
	u32 data_read;
909
	int err = 0;
910

911 912 913
	if (qlcnic_83xx_check(adapter))
		return qlcnic_83xx_reg_test(adapter);

914 915 916
	data_read = QLCRD32(adapter, QLCNIC_PCIX_PH_REG(0), &err);
	if (err == -EIO)
		return err;
917 918 919 920 921 922
	if ((data_read & 0xffff) != adapter->pdev->vendor)
		return 1;

	return 0;
}

923 924 925 926 927 928 929 930 931 932
static int qlcnic_eeprom_test(struct net_device *dev)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);

	if (qlcnic_82xx_check(adapter))
		return 0;

	return qlcnic_83xx_flash_test(adapter);
}

933 934
static int qlcnic_get_sset_count(struct net_device *dev, int sset)
{
935

A
amit salecha 已提交
936
	struct qlcnic_adapter *adapter = netdev_priv(dev);
937 938 939 940
	switch (sset) {
	case ETH_SS_TEST:
		return QLCNIC_TEST_LEN;
	case ETH_SS_STATS:
941
		return qlcnic_dev_statistics_len(adapter);
942 943 944 945 946
	default:
		return -EOPNOTSUPP;
	}
}

947 948 949
static int qlcnic_irq_test(struct net_device *netdev)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
950
	struct qlcnic_hardware_context *ahw = adapter->ahw;
951
	struct qlcnic_cmd_args cmd;
952
	int ret, drv_sds_rings = adapter->drv_sds_rings;
953
	int drv_tx_rings = adapter->drv_tx_rings;
954 955 956

	if (qlcnic_83xx_check(adapter))
		return qlcnic_83xx_interrupt_test(netdev);
957 958 959 960 961 962

	if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
		return -EIO;

	ret = qlcnic_diag_alloc_res(netdev, QLCNIC_INTERRUPT_TEST);
	if (ret)
963
		goto clear_diag_irq;
964

965
	ahw->diag_cnt = 0;
966 967 968
	ret = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_INTRPT_TEST);
	if (ret)
		goto free_diag_res;
969

970 971
	cmd.req.arg[1] = ahw->pci_func;
	ret = qlcnic_issue_cmd(adapter, &cmd);
972 973 974
	if (ret)
		goto done;

975
	usleep_range(1000, 12000);
976
	ret = !ahw->diag_cnt;
977 978

done:
979
	qlcnic_free_mbx_args(&cmd);
980 981

free_diag_res:
982
	qlcnic_diag_free_res(netdev, drv_sds_rings);
983

984
clear_diag_irq:
985
	adapter->drv_sds_rings = drv_sds_rings;
986
	adapter->drv_tx_rings = drv_tx_rings;
987
	clear_bit(__QLCNIC_RESETTING, &adapter->state);
988

989 990 991
	return ret;
}

992 993 994 995 996
#define QLCNIC_ILB_PKT_SIZE		64
#define QLCNIC_NUM_ILB_PKT		16
#define QLCNIC_ILB_MAX_RCV_LOOP		10
#define QLCNIC_LB_PKT_POLL_DELAY_MSEC	1
#define QLCNIC_LB_PKT_POLL_COUNT	20
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

static void qlcnic_create_loopback_buff(unsigned char *data, u8 mac[])
{
	unsigned char random_data[] = {0xa8, 0x06, 0x45, 0x00};

	memset(data, 0x4e, QLCNIC_ILB_PKT_SIZE);

	memcpy(data, mac, ETH_ALEN);
	memcpy(data + ETH_ALEN, mac, ETH_ALEN);

	memcpy(data + 2 * ETH_ALEN, random_data, sizeof(random_data));
}

int qlcnic_check_loopback_buff(unsigned char *data, u8 mac[])
{
	unsigned char buff[QLCNIC_ILB_PKT_SIZE];
	qlcnic_create_loopback_buff(buff, mac);
	return memcmp(data, buff, QLCNIC_ILB_PKT_SIZE);
}

1017
int qlcnic_do_lb_test(struct qlcnic_adapter *adapter, u8 mode)
1018 1019 1020 1021 1022 1023 1024
{
	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
	struct qlcnic_host_sds_ring *sds_ring = &recv_ctx->sds_rings[0];
	struct sk_buff *skb;
	int i, loop, cnt = 0;

	for (i = 0; i < QLCNIC_NUM_ILB_PKT; i++) {
1025
		skb = netdev_alloc_skb(adapter->netdev, QLCNIC_ILB_PKT_SIZE);
1026 1027
		qlcnic_create_loopback_buff(skb->data, adapter->mac_addr);
		skb_put(skb, QLCNIC_ILB_PKT_SIZE);
1028
		adapter->ahw->diag_cnt = 0;
1029 1030
		qlcnic_xmit_frame(skb, adapter->netdev);
		loop = 0;
1031

1032
		do {
1033
			msleep(QLCNIC_LB_PKT_POLL_DELAY_MSEC);
1034
			qlcnic_process_rcv_ring_diag(sds_ring);
1035
			if (loop++ > QLCNIC_LB_PKT_POLL_COUNT)
1036
				break;
1037
		} while (!adapter->ahw->diag_cnt);
1038 1039 1040

		dev_kfree_skb_any(skb);

1041
		if (!adapter->ahw->diag_cnt)
1042 1043 1044
			dev_warn(&adapter->pdev->dev,
				 "LB Test: packet #%d was not received\n",
				 i + 1);
1045 1046 1047 1048
		else
			cnt++;
	}
	if (cnt != i) {
1049 1050 1051
		dev_err(&adapter->pdev->dev,
			"LB Test: failed, TX[%d], RX[%d]\n", i, cnt);
		if (mode != QLCNIC_ILB_MODE)
1052
			dev_warn(&adapter->pdev->dev,
1053
				 "WARNING: Please check loopback cable\n");
1054 1055 1056 1057 1058
		return -1;
	}
	return 0;
}

1059
static int qlcnic_loopback_test(struct net_device *netdev, u8 mode)
1060 1061
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
1062 1063
	int drv_tx_rings = adapter->drv_tx_rings;
	int drv_sds_rings = adapter->drv_sds_rings;
1064
	struct qlcnic_host_sds_ring *sds_ring;
1065
	struct qlcnic_hardware_context *ahw = adapter->ahw;
1066 1067 1068
	int loop = 0;
	int ret;

1069
	if (qlcnic_83xx_check(adapter))
1070 1071
		return qlcnic_83xx_loopback_test(netdev, mode);

1072 1073 1074
	if (!(ahw->capabilities & QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK)) {
		dev_info(&adapter->pdev->dev,
			 "Firmware do not support loopback test\n");
1075 1076
		return -EOPNOTSUPP;
	}
1077

1078 1079 1080 1081 1082
	dev_warn(&adapter->pdev->dev, "%s loopback test in progress\n",
		 mode == QLCNIC_ILB_MODE ? "internal" : "external");
	if (ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
		dev_warn(&adapter->pdev->dev,
			 "Loopback test not supported in nonprivileged mode\n");
1083 1084 1085 1086
		return 0;
	}

	if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1087
		return -EBUSY;
1088 1089 1090 1091 1092 1093

	ret = qlcnic_diag_alloc_res(netdev, QLCNIC_LOOPBACK_TEST);
	if (ret)
		goto clear_it;

	sds_ring = &adapter->recv_ctx->sds_rings[0];
1094
	ret = qlcnic_set_lb_mode(adapter, mode);
1095 1096 1097
	if (ret)
		goto free_res;

1098
	ahw->diag_cnt = 0;
1099 1100 1101
	do {
		msleep(500);
		qlcnic_process_rcv_ring_diag(sds_ring);
1102
		if (loop++ > QLCNIC_ILB_MAX_RCV_LOOP) {
1103 1104 1105
			netdev_info(netdev,
				    "Firmware didn't sent link up event to loopback request\n");
			ret = -ETIMEDOUT;
1106
			goto free_res;
1107 1108
		} else if (adapter->ahw->diag_cnt) {
			ret = adapter->ahw->diag_cnt;
1109 1110
			goto free_res;
		}
1111
	} while (!QLCNIC_IS_LB_CONFIGURED(ahw->loopback_state));
1112

1113
	ret = qlcnic_do_lb_test(adapter, mode);
1114

1115
	qlcnic_clear_lb_mode(adapter, mode);
1116 1117

 free_res:
1118
	qlcnic_diag_free_res(netdev, drv_sds_rings);
1119 1120

 clear_it:
1121 1122
	adapter->drv_sds_rings = drv_sds_rings;
	adapter->drv_tx_rings = drv_tx_rings;
1123 1124 1125 1126
	clear_bit(__QLCNIC_RESETTING, &adapter->state);
	return ret;
}

1127 1128 1129 1130 1131
static void
qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
		     u64 *data)
{
	memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
1132

S
Sony Chacko 已提交
1133 1134 1135 1136 1137 1138 1139 1140
	data[0] = qlcnic_reg_test(dev);
	if (data[0])
		eth_test->flags |= ETH_TEST_FL_FAILED;

	data[1] = (u64) qlcnic_test_link(dev);
	if (data[1])
		eth_test->flags |= ETH_TEST_FL_FAILED;

1141
	if (eth_test->flags & ETH_TEST_FL_OFFLINE) {
1142 1143 1144
		data[2] = qlcnic_irq_test(dev);
		if (data[2])
			eth_test->flags |= ETH_TEST_FL_FAILED;
1145

1146
		data[3] = qlcnic_loopback_test(dev, QLCNIC_ILB_MODE);
1147 1148
		if (data[3])
			eth_test->flags |= ETH_TEST_FL_FAILED;
1149

1150 1151 1152 1153 1154 1155 1156 1157 1158
		if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
			data[4] = qlcnic_loopback_test(dev, QLCNIC_ELB_MODE);
			if (data[4])
				eth_test->flags |= ETH_TEST_FL_FAILED;
			eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
		}

		data[5] = qlcnic_eeprom_test(dev);
		if (data[5])
1159
			eth_test->flags |= ETH_TEST_FL_FAILED;
1160
	}
1161 1162 1163
}

static void
1164
qlcnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1165
{
A
amit salecha 已提交
1166
	struct qlcnic_adapter *adapter = netdev_priv(dev);
1167
	int index, i, num_stats;
1168 1169 1170 1171 1172 1173 1174

	switch (stringset) {
	case ETH_SS_TEST:
		memcpy(data, *qlcnic_gstrings_test,
		       QLCNIC_TEST_LEN * ETH_GSTRING_LEN);
		break;
	case ETH_SS_STATS:
1175
		num_stats = ARRAY_SIZE(qlcnic_tx_queue_stats_strings);
1176
		for (i = 0; i < adapter->drv_tx_rings; i++) {
1177
			for (index = 0; index < num_stats; index++) {
1178 1179
				sprintf(data, "tx_queue_%d %s", i,
					qlcnic_tx_queue_stats_strings[index]);
1180 1181 1182 1183
				data += ETH_GSTRING_LEN;
			}
		}

1184 1185 1186 1187 1188
		for (index = 0; index < QLCNIC_STATS_LEN; index++) {
			memcpy(data + index * ETH_GSTRING_LEN,
			       qlcnic_gstrings_stats[index].stat_string,
			       ETH_GSTRING_LEN);
		}
1189

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
		if (qlcnic_83xx_check(adapter)) {
			num_stats = ARRAY_SIZE(qlcnic_83xx_tx_stats_strings);
			for (i = 0; i < num_stats; i++, index++)
				memcpy(data + index * ETH_GSTRING_LEN,
				       qlcnic_83xx_tx_stats_strings[i],
				       ETH_GSTRING_LEN);
			num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
			for (i = 0; i < num_stats; i++, index++)
				memcpy(data + index * ETH_GSTRING_LEN,
				       qlcnic_83xx_mac_stats_strings[i],
				       ETH_GSTRING_LEN);
			num_stats = ARRAY_SIZE(qlcnic_83xx_rx_stats_strings);
			for (i = 0; i < num_stats; i++, index++)
				memcpy(data + index * ETH_GSTRING_LEN,
				       qlcnic_83xx_rx_stats_strings[i],
				       ETH_GSTRING_LEN);
			return;
		} else {
			num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
			for (i = 0; i < num_stats; i++, index++)
				memcpy(data + index * ETH_GSTRING_LEN,
				       qlcnic_83xx_mac_stats_strings[i],
				       ETH_GSTRING_LEN);
1213
		}
A
amit salecha 已提交
1214 1215
		if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
			return;
1216 1217
		num_stats = ARRAY_SIZE(qlcnic_device_gstrings_stats);
		for (i = 0; i < num_stats; index++, i++) {
A
amit salecha 已提交
1218 1219 1220 1221
			memcpy(data + index * ETH_GSTRING_LEN,
			       qlcnic_device_gstrings_stats[i],
			       ETH_GSTRING_LEN);
		}
1222 1223 1224
	}
}

1225
static u64 *qlcnic_fill_stats(u64 *data, void *stats, int type)
A
amit salecha 已提交
1226
{
1227 1228 1229
	if (type == QLCNIC_MAC_STATS) {
		struct qlcnic_mac_statistics *mac_stats =
					(struct qlcnic_mac_statistics *)stats;
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_frames);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bytes);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_mcast_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bcast_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_pause_cnt);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_ctrl_pkt);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_64b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_127b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_255b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_511b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1023b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1518b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_gt_1518b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_frames);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bytes);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_mcast_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bcast_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_pause_cnt);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_ctrl_pkt);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_64b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_127b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_255b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_511b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1023b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1518b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_gt_1518b_pkts);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_error);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_small);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_large);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_jabber);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_dropped);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_crc_error);
		*data++ = QLCNIC_FILL_STATS(mac_stats->mac_align_error);
1263 1264 1265
	} else if (type == QLCNIC_ESW_STATS) {
		struct __qlcnic_esw_statistics *esw_stats =
				(struct __qlcnic_esw_statistics *)stats;
1266 1267 1268 1269 1270 1271 1272
		*data++ = QLCNIC_FILL_STATS(esw_stats->unicast_frames);
		*data++ = QLCNIC_FILL_STATS(esw_stats->multicast_frames);
		*data++ = QLCNIC_FILL_STATS(esw_stats->broadcast_frames);
		*data++ = QLCNIC_FILL_STATS(esw_stats->dropped_frames);
		*data++ = QLCNIC_FILL_STATS(esw_stats->errors);
		*data++ = QLCNIC_FILL_STATS(esw_stats->local_frames);
		*data++ = QLCNIC_FILL_STATS(esw_stats->numbytes);
1273
	}
1274
	return data;
A
amit salecha 已提交
1275 1276
}

M
Manish Chopra 已提交
1277
void qlcnic_update_stats(struct qlcnic_adapter *adapter)
1278 1279 1280 1281
{
	struct qlcnic_host_tx_ring *tx_ring;
	int ring;

1282
	for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
		tx_ring = &adapter->tx_ring[ring];
		adapter->stats.xmit_on += tx_ring->tx_stats.xmit_on;
		adapter->stats.xmit_off += tx_ring->tx_stats.xmit_off;
		adapter->stats.xmitcalled += tx_ring->tx_stats.xmit_called;
		adapter->stats.xmitfinished += tx_ring->tx_stats.xmit_finished;
		adapter->stats.txbytes += tx_ring->tx_stats.tx_bytes;
	}
}

static u64 *qlcnic_fill_tx_queue_stats(u64 *data, void *stats)
{
	struct qlcnic_host_tx_ring *tx_ring;

	tx_ring = (struct qlcnic_host_tx_ring *)stats;

	*data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_on);
	*data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_off);
	*data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_called);
	*data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_finished);
	*data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.tx_bytes);

	return data;
}

1307 1308
static void qlcnic_get_ethtool_stats(struct net_device *dev,
				     struct ethtool_stats *stats, u64 *data)
1309 1310
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
1311
	struct qlcnic_host_tx_ring *tx_ring;
A
amit salecha 已提交
1312
	struct qlcnic_esw_statistics port_stats;
1313
	struct qlcnic_mac_statistics mac_stats;
1314
	int index, ret, length, size, tx_size, ring;
1315 1316
	char *p;

1317
	tx_size = adapter->drv_tx_rings * QLCNIC_TX_STATS_LEN;
1318 1319

	memset(data, 0, tx_size * sizeof(u64));
1320
	for (ring = 0, index = 0; ring < adapter->drv_tx_rings; ring++) {
1321 1322
		if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
			tx_ring = &adapter->tx_ring[ring];
1323 1324
			data = qlcnic_fill_tx_queue_stats(data, tx_ring);
			qlcnic_update_stats(adapter);
1325 1326
		}
	}
1327

1328 1329 1330 1331 1332 1333
	memset(data, 0, stats->n_stats * sizeof(u64));
	length = QLCNIC_STATS_LEN;
	for (index = 0; index < length; index++) {
		p = (char *)adapter + qlcnic_gstrings_stats[index].stat_offset;
		size = qlcnic_gstrings_stats[index].sizeof_stat;
		*data++ = (size == sizeof(u64)) ? (*(u64 *)p) : ((*(u32 *)p));
1334
	}
A
amit salecha 已提交
1335

1336 1337 1338 1339 1340 1341 1342 1343
	if (qlcnic_83xx_check(adapter)) {
		if (adapter->ahw->linkup)
			qlcnic_83xx_get_stats(adapter, data);
		return;
	} else {
		/* Retrieve MAC statistics from firmware */
		memset(&mac_stats, 0, sizeof(struct qlcnic_mac_statistics));
		qlcnic_get_mac_stats(adapter, &mac_stats);
1344
		data = qlcnic_fill_stats(data, &mac_stats, QLCNIC_MAC_STATS);
1345
	}
1346

A
amit salecha 已提交
1347 1348 1349 1350
	if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
		return;

	memset(&port_stats, 0, sizeof(struct qlcnic_esw_statistics));
A
Anirban Chakraborty 已提交
1351
	ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
A
amit salecha 已提交
1352 1353 1354 1355
			QLCNIC_QUERY_RX_COUNTER, &port_stats.rx);
	if (ret)
		return;

1356
	data = qlcnic_fill_stats(data, &port_stats.rx, QLCNIC_ESW_STATS);
A
Anirban Chakraborty 已提交
1357
	ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
A
amit salecha 已提交
1358 1359 1360 1361
			QLCNIC_QUERY_TX_COUNTER, &port_stats.tx);
	if (ret)
		return;

1362
	qlcnic_fill_stats(data, &port_stats.tx, QLCNIC_ESW_STATS);
1363 1364
}

1365 1366
static int qlcnic_set_led(struct net_device *dev,
			  enum ethtool_phys_id_state state)
1367 1368
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
1369
	int drv_sds_rings = adapter->drv_sds_rings;
1370 1371
	int err = -EIO, active = 1;

1372
	if (qlcnic_83xx_check(adapter))
1373 1374
		return qlcnic_83xx_set_led(dev, state);

1375
	if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1376 1377 1378 1379
		netdev_warn(dev, "LED test not supported for non "
				"privilege function\n");
		return -EOPNOTSUPP;
	}
1380

1381 1382
	switch (state) {
	case ETHTOOL_ID_ACTIVE:
1383 1384 1385
		if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
			return -EBUSY;

1386 1387
		if (test_bit(__QLCNIC_RESETTING, &adapter->state))
			break;
1388

1389 1390 1391
		if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
			if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
				break;
1392
			set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1393
		}
1394

1395 1396 1397 1398
		if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0) {
			err = 0;
			break;
		}
1399

1400 1401
		dev_err(&adapter->pdev->dev,
			"Failed to set LED blink state.\n");
1402
		break;
1403

1404
	case ETHTOOL_ID_INACTIVE:
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
		active = 0;

		if (test_bit(__QLCNIC_RESETTING, &adapter->state))
			break;

		if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
			if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
				break;
			set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
		}

1416 1417 1418
		if (adapter->nic_ops->config_led(adapter, 0, 0xf))
			dev_err(&adapter->pdev->dev,
				"Failed to reset LED blink state.\n");
1419

1420 1421 1422 1423
		break;

	default:
		return -EINVAL;
1424 1425
	}

1426
	if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
1427
		qlcnic_diag_free_res(dev, drv_sds_rings);
1428

1429 1430
	if (!active || err)
		clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
1431

1432
	return err;
1433 1434
}

1435 1436 1437 1438 1439
static void
qlcnic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	u32 wol_cfg;
1440
	int err = 0;
1441

1442 1443
	if (qlcnic_83xx_check(adapter))
		return;
1444 1445 1446
	wol->supported = 0;
	wol->wolopts = 0;

1447 1448 1449
	wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
	if (err == -EIO)
		return;
1450 1451 1452
	if (wol_cfg & (1UL << adapter->portnum))
		wol->supported |= WAKE_MAGIC;

1453
	wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1454 1455 1456 1457 1458 1459 1460 1461 1462
	if (wol_cfg & (1UL << adapter->portnum))
		wol->wolopts |= WAKE_MAGIC;
}

static int
qlcnic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct qlcnic_adapter *adapter = netdev_priv(dev);
	u32 wol_cfg;
1463
	int err = 0;
1464

1465
	if (qlcnic_83xx_check(adapter))
1466
		return -EOPNOTSUPP;
1467 1468
	if (wol->wolopts & ~WAKE_MAGIC)
		return -EINVAL;
1469

1470 1471 1472
	wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
	if (err == -EIO)
		return err;
1473 1474 1475
	if (!(wol_cfg & (1 << adapter->portnum)))
		return -EOPNOTSUPP;

1476 1477 1478
	wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
	if (err == -EIO)
		return err;
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
	if (wol->wolopts & WAKE_MAGIC)
		wol_cfg |= 1UL << adapter->portnum;
	else
		wol_cfg &= ~(1UL << adapter->portnum);

	QLCWR32(adapter, QLCNIC_WOL_CONFIG, wol_cfg);

	return 0;
}

/*
 * 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 qlcnic_set_intr_coalesce(struct net_device *netdev,
			struct ethtool_coalesce *ethcoal)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
1498 1499 1500
	struct qlcnic_nic_intr_coalesce *coal;
	u32 rx_coalesce_usecs, rx_max_frames;
	u32 tx_coalesce_usecs, tx_max_frames;
1501

1502
	if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
1503 1504 1505 1506 1507 1508 1509 1510
		return -EINVAL;

	/*
	* Return Error if unsupported values or
	* unsupported parameters are set.
	*/
	if (ethcoal->rx_coalesce_usecs > 0xffff ||
		ethcoal->rx_max_coalesced_frames > 0xffff ||
1511 1512
		ethcoal->tx_coalesce_usecs > 0xffff ||
		ethcoal->tx_max_coalesced_frames > 0xffff ||
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
		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;

1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
	coal = &adapter->ahw->coal;

	if (qlcnic_83xx_check(adapter)) {
		if (!ethcoal->tx_coalesce_usecs ||
		    !ethcoal->tx_max_coalesced_frames ||
		    !ethcoal->rx_coalesce_usecs ||
		    !ethcoal->rx_max_coalesced_frames) {
			coal->flag = QLCNIC_INTR_DEFAULT;
			coal->type = QLCNIC_INTR_COAL_TYPE_RX;
			coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
			coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
			coal->tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
			coal->tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
		} else {
			tx_coalesce_usecs = ethcoal->tx_coalesce_usecs;
			tx_max_frames = ethcoal->tx_max_coalesced_frames;
			rx_coalesce_usecs = ethcoal->rx_coalesce_usecs;
			rx_max_frames = ethcoal->rx_max_coalesced_frames;
			coal->flag = 0;

			if ((coal->rx_time_us == rx_coalesce_usecs) &&
			    (coal->rx_packets == rx_max_frames)) {
				coal->type = QLCNIC_INTR_COAL_TYPE_TX;
				coal->tx_time_us = tx_coalesce_usecs;
				coal->tx_packets = tx_max_frames;
			} else if ((coal->tx_time_us == tx_coalesce_usecs) &&
				   (coal->tx_packets == tx_max_frames)) {
				coal->type = QLCNIC_INTR_COAL_TYPE_RX;
				coal->rx_time_us = rx_coalesce_usecs;
				coal->rx_packets = rx_max_frames;
			} else {
				coal->type = QLCNIC_INTR_COAL_TYPE_RX;
				coal->rx_time_us = rx_coalesce_usecs;
				coal->rx_packets = rx_max_frames;
				coal->tx_time_us = tx_coalesce_usecs;
				coal->tx_packets = tx_max_frames;
			}
		}
1570
	} else {
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
		if (!ethcoal->rx_coalesce_usecs ||
		    !ethcoal->rx_max_coalesced_frames) {
			coal->flag = QLCNIC_INTR_DEFAULT;
			coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
			coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
		} else {
			coal->flag = 0;
			coal->rx_time_us = ethcoal->rx_coalesce_usecs;
			coal->rx_packets = ethcoal->rx_max_coalesced_frames;
		}
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
	}

	qlcnic_config_intr_coalesce(adapter);

	return 0;
}

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

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

A
Anirban Chakraborty 已提交
1596 1597
	ethcoal->rx_coalesce_usecs = adapter->ahw->coal.rx_time_us;
	ethcoal->rx_max_coalesced_frames = adapter->ahw->coal.rx_packets;
1598 1599
	ethcoal->tx_coalesce_usecs = adapter->ahw->coal.tx_time_us;
	ethcoal->tx_max_coalesced_frames = adapter->ahw->coal.tx_packets;
1600 1601 1602 1603

	return 0;
}

1604 1605 1606 1607
static u32 qlcnic_get_msglevel(struct net_device *netdev)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);

1608
	return adapter->ahw->msg_enable;
1609 1610 1611 1612 1613 1614
}

static void qlcnic_set_msglevel(struct net_device *netdev, u32 msglvl)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);

1615
	adapter->ahw->msg_enable = msglvl;
1616 1617
}

1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
int qlcnic_enable_fw_dump_state(struct qlcnic_adapter *adapter)
{
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
	u32 val;

	if (qlcnic_84xx_check(adapter)) {
		if (qlcnic_83xx_lock_driver(adapter))
			return -EBUSY;

		val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
		val &= ~QLC_83XX_IDC_DISABLE_FW_DUMP;
		QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);

		qlcnic_83xx_unlock_driver(adapter);
	} else {
		fw_dump->enable = true;
	}

	dev_info(&adapter->pdev->dev, "FW dump enabled\n");

	return 0;
}

static int qlcnic_disable_fw_dump_state(struct qlcnic_adapter *adapter)
{
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
	u32 val;

	if (qlcnic_84xx_check(adapter)) {
		if (qlcnic_83xx_lock_driver(adapter))
			return -EBUSY;

		val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
		val |= QLC_83XX_IDC_DISABLE_FW_DUMP;
		QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);

		qlcnic_83xx_unlock_driver(adapter);
	} else {
		fw_dump->enable = false;
	}

	dev_info(&adapter->pdev->dev, "FW dump disabled\n");

	return 0;
}

bool qlcnic_check_fw_dump_state(struct qlcnic_adapter *adapter)
{
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
	bool state;
	u32 val;

	if (qlcnic_84xx_check(adapter)) {
		val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
		state = (val & QLC_83XX_IDC_DISABLE_FW_DUMP) ? false : true;
	} else {
		state = fw_dump->enable;
	}

	return state;
}

1680 1681 1682 1683 1684 1685
static int
qlcnic_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;

1686 1687 1688 1689 1690
	if (!fw_dump->tmpl_hdr) {
		netdev_err(adapter->netdev, "FW Dump not supported\n");
		return -ENOTSUPP;
	}

1691 1692 1693 1694
	if (fw_dump->clr)
		dump->len = fw_dump->tmpl_hdr->size + fw_dump->size;
	else
		dump->len = 0;
1695

1696
	if (!qlcnic_check_fw_dump_state(adapter))
1697 1698 1699 1700
		dump->flag = ETH_FW_DUMP_DISABLE;
	else
		dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;

1701 1702 1703 1704 1705 1706 1707 1708 1709
	dump->version = adapter->fw_version;
	return 0;
}

static int
qlcnic_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
			void *buffer)
{
	int i, copy_sz;
1710 1711
	u32 *hdr_ptr;
	__le32 *data;
1712 1713 1714
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;

1715 1716 1717 1718 1719
	if (!fw_dump->tmpl_hdr) {
		netdev_err(netdev, "FW Dump not supported\n");
		return -ENOTSUPP;
	}

1720 1721 1722 1723 1724 1725 1726
	if (!fw_dump->clr) {
		netdev_info(netdev, "Dump not available\n");
		return -EINVAL;
	}
	/* Copy template header first */
	copy_sz = fw_dump->tmpl_hdr->size;
	hdr_ptr = (u32 *) fw_dump->tmpl_hdr;
1727
	data = buffer;
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
	for (i = 0; i < copy_sz/sizeof(u32); i++)
		*data++ = cpu_to_le32(*hdr_ptr++);

	/* Copy captured dump data */
	memcpy(buffer + copy_sz, fw_dump->data, fw_dump->size);
	dump->len = copy_sz + fw_dump->size;
	dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;

	/* Free dump area once data has been captured */
	vfree(fw_dump->data);
	fw_dump->data = NULL;
	fw_dump->clr = 0;
M
Manish chopra 已提交
1740
	netdev_info(netdev, "extracted the FW dump Successfully\n");
1741 1742 1743
	return 0;
}

1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
static int qlcnic_set_dump_mask(struct qlcnic_adapter *adapter, u32 mask)
{
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
	struct net_device *netdev = adapter->netdev;

	if (!qlcnic_check_fw_dump_state(adapter)) {
		netdev_info(netdev,
			    "Can not change driver mask to 0x%x. FW dump not enabled\n",
			    mask);
		return -EOPNOTSUPP;
	}

	fw_dump->tmpl_hdr->drv_cap_mask = mask;
	netdev_info(netdev, "Driver mask changed to: 0x%x\n", mask);
	return 0;
}

1761 1762 1763 1764 1765
static int
qlcnic_set_dump(struct net_device *netdev, struct ethtool_dump *val)
{
	struct qlcnic_adapter *adapter = netdev_priv(netdev);
	struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1766 1767
	bool valid_mask = false;
	int i, ret = 0;
1768

1769 1770
	switch (val->flag) {
	case QLCNIC_FORCE_FW_DUMP_KEY:
1771 1772
		if (!fw_dump->tmpl_hdr) {
			netdev_err(netdev, "FW dump not supported\n");
1773 1774
			ret = -EOPNOTSUPP;
			break;
1775
		}
1776 1777

		if (!qlcnic_check_fw_dump_state(adapter)) {
1778
			netdev_info(netdev, "FW dump not enabled\n");
1779 1780
			ret = -EOPNOTSUPP;
			break;
1781
		}
1782

1783
		if (fw_dump->clr) {
M
Manish chopra 已提交
1784
			netdev_info(netdev,
1785 1786
				    "Previous dump not cleared, not forcing dump\n");
			break;
1787
		}
1788

1789
		netdev_info(netdev, "Forcing a FW dump\n");
1790
		qlcnic_dev_request_reset(adapter, val->flag);
1791 1792
		break;
	case QLCNIC_DISABLE_FW_DUMP:
1793 1794 1795 1796
		if (!fw_dump->tmpl_hdr) {
			netdev_err(netdev, "FW dump not supported\n");
			ret = -EOPNOTSUPP;
			break;
1797
		}
1798 1799 1800 1801

		ret = qlcnic_disable_fw_dump_state(adapter);
		break;

1802
	case QLCNIC_ENABLE_FW_DUMP:
1803 1804
		if (!fw_dump->tmpl_hdr) {
			netdev_err(netdev, "FW dump not supported\n");
1805 1806
			ret = -EOPNOTSUPP;
			break;
1807
		}
1808 1809 1810 1811

		ret = qlcnic_enable_fw_dump_state(adapter);
		break;

1812 1813
	case QLCNIC_FORCE_FW_RESET:
		netdev_info(netdev, "Forcing a FW reset\n");
1814
		qlcnic_dev_request_reset(adapter, val->flag);
1815
		adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
1816
		break;
D
Dan Carpenter 已提交
1817

1818 1819
	case QLCNIC_SET_QUIESCENT:
	case QLCNIC_RESET_QUIESCENT:
1820 1821
		if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
			netdev_info(netdev, "Device is in non-operational state\n");
1822 1823
		break;

1824
	default:
1825 1826
		if (!fw_dump->tmpl_hdr) {
			netdev_err(netdev, "FW dump not supported\n");
1827 1828
			ret = -EOPNOTSUPP;
			break;
1829
		}
1830

1831 1832
		for (i = 0; i < ARRAY_SIZE(qlcnic_fw_dump_level); i++) {
			if (val->flag == qlcnic_fw_dump_level[i]) {
1833 1834
				valid_mask = true;
				break;
1835
			}
1836
		}
1837 1838 1839 1840 1841 1842 1843 1844

		if (valid_mask) {
			ret = qlcnic_set_dump_mask(adapter, val->flag);
		} else {
			netdev_info(netdev, "Invalid dump level: 0x%x\n",
				    val->flag);
			ret = -EINVAL;
		}
1845
	}
1846
	return ret;
1847 1848
}

1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
const struct ethtool_ops qlcnic_ethtool_ops = {
	.get_settings = qlcnic_get_settings,
	.set_settings = qlcnic_set_settings,
	.get_drvinfo = qlcnic_get_drvinfo,
	.get_regs_len = qlcnic_get_regs_len,
	.get_regs = qlcnic_get_regs,
	.get_link = ethtool_op_get_link,
	.get_eeprom_len = qlcnic_get_eeprom_len,
	.get_eeprom = qlcnic_get_eeprom,
	.get_ringparam = qlcnic_get_ringparam,
	.set_ringparam = qlcnic_set_ringparam,
1860 1861
	.get_channels = qlcnic_get_channels,
	.set_channels = qlcnic_set_channels,
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
	.get_pauseparam = qlcnic_get_pauseparam,
	.set_pauseparam = qlcnic_set_pauseparam,
	.get_wol = qlcnic_get_wol,
	.set_wol = qlcnic_set_wol,
	.self_test = qlcnic_diag_test,
	.get_strings = qlcnic_get_strings,
	.get_ethtool_stats = qlcnic_get_ethtool_stats,
	.get_sset_count = qlcnic_get_sset_count,
	.get_coalesce = qlcnic_get_intr_coalesce,
	.set_coalesce = qlcnic_set_intr_coalesce,
1872
	.set_phys_id = qlcnic_set_led,
1873 1874
	.set_msglevel = qlcnic_set_msglevel,
	.get_msglevel = qlcnic_get_msglevel,
1875 1876 1877
	.get_dump_flag = qlcnic_get_dump_flag,
	.get_dump_data = qlcnic_get_dump_data,
	.set_dump = qlcnic_set_dump,
1878
};
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900

const struct ethtool_ops qlcnic_sriov_vf_ethtool_ops = {
	.get_settings		= qlcnic_get_settings,
	.get_drvinfo		= qlcnic_get_drvinfo,
	.get_regs_len		= qlcnic_get_regs_len,
	.get_regs		= qlcnic_get_regs,
	.get_link		= ethtool_op_get_link,
	.get_eeprom_len		= qlcnic_get_eeprom_len,
	.get_eeprom		= qlcnic_get_eeprom,
	.get_ringparam		= qlcnic_get_ringparam,
	.set_ringparam		= qlcnic_set_ringparam,
	.get_channels		= qlcnic_get_channels,
	.get_pauseparam		= qlcnic_get_pauseparam,
	.get_wol		= qlcnic_get_wol,
	.get_strings		= qlcnic_get_strings,
	.get_ethtool_stats	= qlcnic_get_ethtool_stats,
	.get_sset_count		= qlcnic_get_sset_count,
	.get_coalesce		= qlcnic_get_intr_coalesce,
	.set_coalesce		= qlcnic_set_intr_coalesce,
	.set_msglevel		= qlcnic_set_msglevel,
	.get_msglevel		= qlcnic_get_msglevel,
};
1901 1902 1903 1904 1905 1906 1907 1908

const struct ethtool_ops qlcnic_ethtool_failed_ops = {
	.get_settings		= qlcnic_get_settings,
	.get_drvinfo		= qlcnic_get_drvinfo,
	.set_msglevel		= qlcnic_set_msglevel,
	.get_msglevel		= qlcnic_get_msglevel,
	.set_dump		= qlcnic_set_dump,
};