bnx2x_ethtool.c 99.0 KB
Newer Older
1
/* bnx2x_ethtool.c: QLogic Everest network driver.
2
 *
3
 * Copyright (c) 2007-2013 Broadcom Corporation
4 5
 * Copyright (c) 2014 QLogic Corporation
 * All rights reserved
6 7 8 9 10
 *
 * 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.
 *
11
 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
12 13 14 15 16 17 18
 * Written by: Eliezer Tamir
 * Based on code from Michael Chan's bnx2 driver
 * UDP CSUM errata workaround by Arik Gendelman
 * Slowpath and fastpath rework by Vladislav Zolotarov
 * Statistics and Link management by Yitchak Gertner
 *
 */
19 20 21

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

22 23 24 25 26 27 28 29
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/crc32.h>
#include "bnx2x.h"
#include "bnx2x_cmn.h"
#include "bnx2x_dump.h"
30
#include "bnx2x_init.h"
31

V
Vladislav Zolotarov 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/* Note: in the format strings below %s is replaced by the queue-name which is
 * either its index or 'fcoe' for the fcoe queue. Make sure the format string
 * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
 */
#define MAX_QUEUE_NAME_LEN	4
static const struct {
	long offset;
	int size;
	char string[ETH_GSTRING_LEN];
} bnx2x_q_stats_arr[] = {
/* 1 */	{ Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
	{ Q_STATS_OFFSET32(total_unicast_packets_received_hi),
						8, "[%s]: rx_ucast_packets" },
	{ Q_STATS_OFFSET32(total_multicast_packets_received_hi),
						8, "[%s]: rx_mcast_packets" },
	{ Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
						8, "[%s]: rx_bcast_packets" },
	{ Q_STATS_OFFSET32(no_buff_discard_hi),	8, "[%s]: rx_discards" },
	{ Q_STATS_OFFSET32(rx_err_discard_pkt),
					 4, "[%s]: rx_phy_ip_err_discards"},
	{ Q_STATS_OFFSET32(rx_skb_alloc_failed),
					 4, "[%s]: rx_skb_alloc_discard" },
	{ Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
55
	{ Q_STATS_OFFSET32(driver_xoff), 4, "[%s]: tx_exhaustion_events" },
56 57
	{ Q_STATS_OFFSET32(total_bytes_transmitted_hi),	8, "[%s]: tx_bytes" },
/* 10 */{ Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
V
Vladislav Zolotarov 已提交
58 59 60 61
						8, "[%s]: tx_ucast_packets" },
	{ Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
						8, "[%s]: tx_mcast_packets" },
	{ Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
62 63 64 65 66
						8, "[%s]: tx_bcast_packets" },
	{ Q_STATS_OFFSET32(total_tpa_aggregations_hi),
						8, "[%s]: tpa_aggregations" },
	{ Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
					8, "[%s]: tpa_aggregated_frames"},
67 68 69
	{ Q_STATS_OFFSET32(total_tpa_bytes_hi),	8, "[%s]: tpa_bytes"},
	{ Q_STATS_OFFSET32(driver_filtered_tx_pkt),
					4, "[%s]: driver_filtered_tx_pkt" }
V
Vladislav Zolotarov 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
};

#define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)

static const struct {
	long offset;
	int size;
	u32 flags;
#define STATS_FLAGS_PORT		1
#define STATS_FLAGS_FUNC		2
#define STATS_FLAGS_BOTH		(STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
	char string[ETH_GSTRING_LEN];
} bnx2x_stats_arr[] = {
/* 1 */	{ STATS_OFFSET32(total_bytes_received_hi),
				8, STATS_FLAGS_BOTH, "rx_bytes" },
	{ STATS_OFFSET32(error_bytes_received_hi),
				8, STATS_FLAGS_BOTH, "rx_error_bytes" },
	{ STATS_OFFSET32(total_unicast_packets_received_hi),
				8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
	{ STATS_OFFSET32(total_multicast_packets_received_hi),
				8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
	{ STATS_OFFSET32(total_broadcast_packets_received_hi),
				8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
	{ STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
				8, STATS_FLAGS_PORT, "rx_crc_errors" },
	{ STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
				8, STATS_FLAGS_PORT, "rx_align_errors" },
	{ STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
				8, STATS_FLAGS_PORT, "rx_undersize_packets" },
	{ STATS_OFFSET32(etherstatsoverrsizepkts_hi),
				8, STATS_FLAGS_PORT, "rx_oversize_packets" },
/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
				8, STATS_FLAGS_PORT, "rx_fragments" },
	{ STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
				8, STATS_FLAGS_PORT, "rx_jabbers" },
	{ STATS_OFFSET32(no_buff_discard_hi),
				8, STATS_FLAGS_BOTH, "rx_discards" },
	{ STATS_OFFSET32(mac_filter_discard),
				4, STATS_FLAGS_PORT, "rx_filtered_packets" },
109 110
	{ STATS_OFFSET32(mf_tag_discard),
				4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
B
Barak Witkowski 已提交
111 112 113 114
	{ STATS_OFFSET32(pfc_frames_received_hi),
				8, STATS_FLAGS_PORT, "pfc_frames_received" },
	{ STATS_OFFSET32(pfc_frames_sent_hi),
				8, STATS_FLAGS_PORT, "pfc_frames_sent" },
V
Vladislav Zolotarov 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	{ STATS_OFFSET32(brb_drop_hi),
				8, STATS_FLAGS_PORT, "rx_brb_discard" },
	{ STATS_OFFSET32(brb_truncate_hi),
				8, STATS_FLAGS_PORT, "rx_brb_truncate" },
	{ STATS_OFFSET32(pause_frames_received_hi),
				8, STATS_FLAGS_PORT, "rx_pause_frames" },
	{ STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
				8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
	{ STATS_OFFSET32(nig_timer_max),
			4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
				4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
	{ STATS_OFFSET32(rx_skb_alloc_failed),
				4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
	{ STATS_OFFSET32(hw_csum_err),
				4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
131 132
	{ STATS_OFFSET32(driver_xoff),
				4, STATS_FLAGS_BOTH, "tx_exhaustion_events" },
V
Vladislav Zolotarov 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
	{ STATS_OFFSET32(total_bytes_transmitted_hi),
				8, STATS_FLAGS_BOTH, "tx_bytes" },
	{ STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
				8, STATS_FLAGS_PORT, "tx_error_bytes" },
	{ STATS_OFFSET32(total_unicast_packets_transmitted_hi),
				8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
	{ STATS_OFFSET32(total_multicast_packets_transmitted_hi),
				8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
	{ STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
				8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
	{ STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
				8, STATS_FLAGS_PORT, "tx_mac_errors" },
	{ STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
				8, STATS_FLAGS_PORT, "tx_carrier_errors" },
/* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
				8, STATS_FLAGS_PORT, "tx_single_collisions" },
	{ STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
				8, STATS_FLAGS_PORT, "tx_multi_collisions" },
	{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
				8, STATS_FLAGS_PORT, "tx_deferred" },
	{ STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
				8, STATS_FLAGS_PORT, "tx_excess_collisions" },
	{ STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
				8, STATS_FLAGS_PORT, "tx_late_collisions" },
	{ STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
				8, STATS_FLAGS_PORT, "tx_total_collisions" },
	{ STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
				8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
	{ STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
			8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
	{ STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
			8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
	{ STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
			8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
/* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
			8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
	{ STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
			8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
	{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
			8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
	{ STATS_OFFSET32(pause_frames_sent_hi),
174 175 176 177 178 179
				8, STATS_FLAGS_PORT, "tx_pause_frames" },
	{ STATS_OFFSET32(total_tpa_aggregations_hi),
			8, STATS_FLAGS_FUNC, "tpa_aggregations" },
	{ STATS_OFFSET32(total_tpa_aggregated_frames_hi),
			8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
	{ STATS_OFFSET32(total_tpa_bytes_hi),
180 181 182 183 184
			8, STATS_FLAGS_FUNC, "tpa_bytes"},
	{ STATS_OFFSET32(recoverable_error),
			4, STATS_FLAGS_FUNC, "recoverable_errors" },
	{ STATS_OFFSET32(unrecoverable_error),
			4, STATS_FLAGS_FUNC, "unrecoverable_errors" },
185 186
	{ STATS_OFFSET32(driver_filtered_tx_pkt),
			4, STATS_FLAGS_FUNC, "driver_filtered_tx_pkt" },
Y
Yuval Mintz 已提交
187 188
	{ STATS_OFFSET32(eee_tx_lpi),
			4, STATS_FLAGS_PORT, "Tx LPI entry count"}
V
Vladislav Zolotarov 已提交
189 190 191
};

#define BNX2X_NUM_STATS		ARRAY_SIZE(bnx2x_stats_arr)
192

Y
Yaniv Rosner 已提交
193 194 195 196 197
static int bnx2x_get_port_type(struct bnx2x *bp)
{
	int port_type;
	u32 phy_idx = bnx2x_get_cur_phy_idx(bp);
	switch (bp->link_params.phy[phy_idx].media_type) {
Y
Yuval Mintz 已提交
198 199
	case ETH_PHY_SFPP_10G_FIBER:
	case ETH_PHY_SFP_1G_FIBER:
Y
Yaniv Rosner 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
	case ETH_PHY_XFP_FIBER:
	case ETH_PHY_KR:
	case ETH_PHY_CX4:
		port_type = PORT_FIBRE;
		break;
	case ETH_PHY_DA_TWINAX:
		port_type = PORT_DA;
		break;
	case ETH_PHY_BASE_T:
		port_type = PORT_TP;
		break;
	case ETH_PHY_NOT_PRESENT:
		port_type = PORT_NONE;
		break;
	case ETH_PHY_UNSPECIFIED:
	default:
		port_type = PORT_OTHER;
		break;
	}
	return port_type;
}
V
Vladislav Zolotarov 已提交
221

D
Dmitry Kravkov 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
static int bnx2x_get_vf_settings(struct net_device *dev,
				 struct ethtool_cmd *cmd)
{
	struct bnx2x *bp = netdev_priv(dev);

	if (bp->state == BNX2X_STATE_OPEN) {
		if (test_bit(BNX2X_LINK_REPORT_FD,
			     &bp->vf_link_vars.link_report_flags))
			cmd->duplex = DUPLEX_FULL;
		else
			cmd->duplex = DUPLEX_HALF;

		ethtool_cmd_speed_set(cmd, bp->vf_link_vars.line_speed);
	} else {
		cmd->duplex = DUPLEX_UNKNOWN;
		ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
	}

	cmd->port		= PORT_OTHER;
	cmd->phy_address	= 0;
	cmd->transceiver	= XCVR_INTERNAL;
	cmd->autoneg		= AUTONEG_DISABLE;
	cmd->maxtxpkt		= 0;
	cmd->maxrxpkt		= 0;

	DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
	   "  supported 0x%x  advertising 0x%x  speed %u\n"
	   "  duplex %d  port %d  phy_address %d  transceiver %d\n"
	   "  autoneg %d  maxtxpkt %d  maxrxpkt %d\n",
	   cmd->cmd, cmd->supported, cmd->advertising,
	   ethtool_cmd_speed(cmd),
	   cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
	   cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);

	return 0;
}

259 260 261
static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
{
	struct bnx2x *bp = netdev_priv(dev);
Y
Yaniv Rosner 已提交
262
	int cfg_idx = bnx2x_get_link_cfg_idx(bp);
263
	u32 media_type;
264

Y
Yaniv Rosner 已提交
265 266 267 268 269
	/* Dual Media boards present all available port types */
	cmd->supported = bp->port.supported[cfg_idx] |
		(bp->port.supported[cfg_idx ^ 1] &
		 (SUPPORTED_TP | SUPPORTED_FIBRE));
	cmd->advertising = bp->port.advertising[cfg_idx];
270 271
	media_type = bp->link_params.phy[bnx2x_get_cur_phy_idx(bp)].media_type;
	if (media_type == ETH_PHY_SFP_1G_FIBER) {
Y
Yuval Mintz 已提交
272 273 274
		cmd->supported &= ~(SUPPORTED_10000baseT_Full);
		cmd->advertising &= ~(ADVERTISED_10000baseT_Full);
	}
275

276 277
	if ((bp->state == BNX2X_STATE_OPEN) && bp->link_vars.link_up &&
	    !(bp->flags & MF_FUNC_DIS)) {
Y
Yuval Mintz 已提交
278
		cmd->duplex = bp->link_vars.duplex;
279 280 281

		if (IS_MF(bp) && !BP_NOMCP(bp))
			ethtool_cmd_speed_set(cmd, bnx2x_get_mf_speed(bp));
282 283
		else
			ethtool_cmd_speed_set(cmd, bp->link_vars.line_speed);
284
	} else {
285 286
		cmd->duplex = DUPLEX_UNKNOWN;
		ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
287
	}
D
Dmitry Kravkov 已提交
288

Y
Yaniv Rosner 已提交
289
	cmd->port = bnx2x_get_port_type(bp);
Y
Yaniv Rosner 已提交
290

291 292 293
	cmd->phy_address = bp->mdio.prtad;
	cmd->transceiver = XCVR_INTERNAL;

Y
Yaniv Rosner 已提交
294
	if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
295 296 297 298
		cmd->autoneg = AUTONEG_ENABLE;
	else
		cmd->autoneg = AUTONEG_DISABLE;

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
	/* Publish LP advertised speeds and FC */
	if (bp->link_vars.link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
		u32 status = bp->link_vars.link_status;

		cmd->lp_advertising |= ADVERTISED_Autoneg;
		if (status & LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE)
			cmd->lp_advertising |= ADVERTISED_Pause;
		if (status & LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
			cmd->lp_advertising |= ADVERTISED_Asym_Pause;

		if (status & LINK_STATUS_LINK_PARTNER_10THD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_10baseT_Half;
		if (status & LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_10baseT_Full;
		if (status & LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_100baseT_Half;
		if (status & LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_100baseT_Full;
		if (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_1000baseT_Half;
319 320 321 322 323 324 325 326 327
		if (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) {
			if (media_type == ETH_PHY_KR) {
				cmd->lp_advertising |=
					ADVERTISED_1000baseKX_Full;
			} else {
				cmd->lp_advertising |=
					ADVERTISED_1000baseT_Full;
			}
		}
328 329
		if (status & LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_2500baseX_Full;
330 331 332 333 334 335 336 337 338
		if (status & LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE) {
			if (media_type == ETH_PHY_KR) {
				cmd->lp_advertising |=
					ADVERTISED_10000baseKR_Full;
			} else {
				cmd->lp_advertising |=
					ADVERTISED_10000baseT_Full;
			}
		}
Y
Yaniv Rosner 已提交
339 340
		if (status & LINK_STATUS_LINK_PARTNER_20GXFD_CAPABLE)
			cmd->lp_advertising |= ADVERTISED_20000baseKR2_Full;
341 342
	}

343 344 345
	cmd->maxtxpkt = 0;
	cmd->maxrxpkt = 0;

M
Merav Sicron 已提交
346
	DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
347 348 349
	   "  supported 0x%x  advertising 0x%x  speed %u\n"
	   "  duplex %d  port %d  phy_address %d  transceiver %d\n"
	   "  autoneg %d  maxtxpkt %d  maxrxpkt %d\n",
350 351
	   cmd->cmd, cmd->supported, cmd->advertising,
	   ethtool_cmd_speed(cmd),
352 353 354 355 356 357 358 359 360
	   cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
	   cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);

	return 0;
}

static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
{
	struct bnx2x *bp = netdev_priv(dev);
Y
Yaniv Rosner 已提交
361
	u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
Y
Yuval Mintz 已提交
362
	u32 speed, phy_idx;
363

364
	if (IS_MF_SD(bp))
365 366
		return 0;

M
Merav Sicron 已提交
367
	DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
368
	   "  supported 0x%x  advertising 0x%x  speed %u\n"
369 370
	   "  duplex %d  port %d  phy_address %d  transceiver %d\n"
	   "  autoneg %d  maxtxpkt %d  maxrxpkt %d\n",
371 372
	   cmd->cmd, cmd->supported, cmd->advertising,
	   ethtool_cmd_speed(cmd),
373 374 375
	   cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
	   cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);

376
	speed = ethtool_cmd_speed(cmd);
377

378
	/* If received a request for an unknown duplex, assume full*/
379 380 381
	if (cmd->duplex == DUPLEX_UNKNOWN)
		cmd->duplex = DUPLEX_FULL;

382
	if (IS_MF_SI(bp)) {
383
		u32 part;
384 385 386 387 388 389 390
		u32 line_speed = bp->link_vars.line_speed;

		/* use 10G if no link detected */
		if (!line_speed)
			line_speed = 10000;

		if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
M
Merav Sicron 已提交
391 392 393
			DP(BNX2X_MSG_ETHTOOL,
			   "To set speed BC %X or higher is required, please upgrade BC\n",
			   REQ_BC_VER_4_SET_MF_BW);
394 395
			return -EINVAL;
		}
396

397
		part = (speed * 100) / line_speed;
398

399
		if (line_speed < speed || !part) {
M
Merav Sicron 已提交
400 401
			DP(BNX2X_MSG_ETHTOOL,
			   "Speed setting should be in a range from 1%% to 100%% of actual line speed\n");
402 403 404
			return -EINVAL;
		}

405 406 407 408 409
		if (bp->state != BNX2X_STATE_OPEN)
			/* store value for following "load" */
			bp->pending_max = part;
		else
			bnx2x_update_max_mf_config(bp, part);
410 411 412 413

		return 0;
	}

Y
Yaniv Rosner 已提交
414 415
	cfg_idx = bnx2x_get_link_cfg_idx(bp);
	old_multi_phy_config = bp->link_params.multi_phy_config;
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
	if (cmd->port != bnx2x_get_port_type(bp)) {
		switch (cmd->port) {
		case PORT_TP:
			if (!(bp->port.supported[0] & SUPPORTED_TP ||
			      bp->port.supported[1] & SUPPORTED_TP)) {
				DP(BNX2X_MSG_ETHTOOL,
				   "Unsupported port type\n");
				return -EINVAL;
			}
			bp->link_params.multi_phy_config &=
				~PORT_HW_CFG_PHY_SELECTION_MASK;
			if (bp->link_params.multi_phy_config &
			    PORT_HW_CFG_PHY_SWAPPED_ENABLED)
				bp->link_params.multi_phy_config |=
				PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
			else
				bp->link_params.multi_phy_config |=
				PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
			break;
		case PORT_FIBRE:
		case PORT_DA:
437
		case PORT_NONE:
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
			if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
			      bp->port.supported[1] & SUPPORTED_FIBRE)) {
				DP(BNX2X_MSG_ETHTOOL,
				   "Unsupported port type\n");
				return -EINVAL;
			}
			bp->link_params.multi_phy_config &=
				~PORT_HW_CFG_PHY_SELECTION_MASK;
			if (bp->link_params.multi_phy_config &
			    PORT_HW_CFG_PHY_SWAPPED_ENABLED)
				bp->link_params.multi_phy_config |=
				PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
			else
				bp->link_params.multi_phy_config |=
				PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
			break;
		default:
M
Merav Sicron 已提交
455
			DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
Y
Yaniv Rosner 已提交
456 457 458
			return -EINVAL;
		}
	}
Y
Yuval Mintz 已提交
459
	/* Save new config in case command complete successfully */
Y
Yaniv Rosner 已提交
460 461 462 463 464
	new_multi_phy_config = bp->link_params.multi_phy_config;
	/* Get the new cfg_idx */
	cfg_idx = bnx2x_get_link_cfg_idx(bp);
	/* Restore old config in case command failed */
	bp->link_params.multi_phy_config = old_multi_phy_config;
M
Merav Sicron 已提交
465
	DP(BNX2X_MSG_ETHTOOL, "cfg_idx = %x\n", cfg_idx);
Y
Yaniv Rosner 已提交
466

467
	if (cmd->autoneg == AUTONEG_ENABLE) {
468 469 470 471 472
		u32 an_supported_speed = bp->port.supported[cfg_idx];
		if (bp->link_params.phy[EXT_PHY1].type ==
		    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
			an_supported_speed |= (SUPPORTED_100baseT_Half |
					       SUPPORTED_100baseT_Full);
Y
Yaniv Rosner 已提交
473
		if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
M
Merav Sicron 已提交
474
			DP(BNX2X_MSG_ETHTOOL, "Autoneg not supported\n");
475 476 477 478
			return -EINVAL;
		}

		/* advertise the requested speed and duplex if supported */
479
		if (cmd->advertising & ~an_supported_speed) {
M
Merav Sicron 已提交
480 481
			DP(BNX2X_MSG_ETHTOOL,
			   "Advertisement parameters are not supported\n");
Y
Yaniv Rosner 已提交
482 483
			return -EINVAL;
		}
484

Y
Yaniv Rosner 已提交
485
		bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
Y
Yaniv Rosner 已提交
486 487
		bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
		bp->port.advertising[cfg_idx] = (ADVERTISED_Autoneg |
488
					 cmd->advertising);
Y
Yaniv Rosner 已提交
489 490 491 492 493 494 495 496 497 498
		if (cmd->advertising) {

			bp->link_params.speed_cap_mask[cfg_idx] = 0;
			if (cmd->advertising & ADVERTISED_10baseT_Half) {
				bp->link_params.speed_cap_mask[cfg_idx] |=
				PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF;
			}
			if (cmd->advertising & ADVERTISED_10baseT_Full)
				bp->link_params.speed_cap_mask[cfg_idx] |=
				PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL;
499

Y
Yaniv Rosner 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
			if (cmd->advertising & ADVERTISED_100baseT_Full)
				bp->link_params.speed_cap_mask[cfg_idx] |=
				PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL;

			if (cmd->advertising & ADVERTISED_100baseT_Half) {
				bp->link_params.speed_cap_mask[cfg_idx] |=
				     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF;
			}
			if (cmd->advertising & ADVERTISED_1000baseT_Half) {
				bp->link_params.speed_cap_mask[cfg_idx] |=
					PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
			}
			if (cmd->advertising & (ADVERTISED_1000baseT_Full |
						ADVERTISED_1000baseKX_Full))
				bp->link_params.speed_cap_mask[cfg_idx] |=
					PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;

			if (cmd->advertising & (ADVERTISED_10000baseT_Full |
						ADVERTISED_10000baseKX4_Full |
						ADVERTISED_10000baseKR_Full))
				bp->link_params.speed_cap_mask[cfg_idx] |=
					PORT_HW_CFG_SPEED_CAPABILITY_D0_10G;
Y
Yaniv Rosner 已提交
522 523 524 525

			if (cmd->advertising & ADVERTISED_20000baseKR2_Full)
				bp->link_params.speed_cap_mask[cfg_idx] |=
					PORT_HW_CFG_SPEED_CAPABILITY_D0_20G;
Y
Yaniv Rosner 已提交
526
		}
527 528
	} else { /* forced speed */
		/* advertise the requested speed and duplex if supported */
Y
Yaniv Rosner 已提交
529
		switch (speed) {
530 531
		case SPEED_10:
			if (cmd->duplex == DUPLEX_FULL) {
Y
Yaniv Rosner 已提交
532
				if (!(bp->port.supported[cfg_idx] &
533
				      SUPPORTED_10baseT_Full)) {
M
Merav Sicron 已提交
534
					DP(BNX2X_MSG_ETHTOOL,
535 536 537 538 539 540 541
					   "10M full not supported\n");
					return -EINVAL;
				}

				advertising = (ADVERTISED_10baseT_Full |
					       ADVERTISED_TP);
			} else {
Y
Yaniv Rosner 已提交
542
				if (!(bp->port.supported[cfg_idx] &
543
				      SUPPORTED_10baseT_Half)) {
M
Merav Sicron 已提交
544
					DP(BNX2X_MSG_ETHTOOL,
545 546 547 548 549 550 551 552 553 554 555
					   "10M half not supported\n");
					return -EINVAL;
				}

				advertising = (ADVERTISED_10baseT_Half |
					       ADVERTISED_TP);
			}
			break;

		case SPEED_100:
			if (cmd->duplex == DUPLEX_FULL) {
Y
Yaniv Rosner 已提交
556
				if (!(bp->port.supported[cfg_idx] &
557
						SUPPORTED_100baseT_Full)) {
M
Merav Sicron 已提交
558
					DP(BNX2X_MSG_ETHTOOL,
559 560 561 562 563 564 565
					   "100M full not supported\n");
					return -EINVAL;
				}

				advertising = (ADVERTISED_100baseT_Full |
					       ADVERTISED_TP);
			} else {
Y
Yaniv Rosner 已提交
566
				if (!(bp->port.supported[cfg_idx] &
567
						SUPPORTED_100baseT_Half)) {
M
Merav Sicron 已提交
568
					DP(BNX2X_MSG_ETHTOOL,
569 570 571 572 573 574 575 576 577 578 579
					   "100M half not supported\n");
					return -EINVAL;
				}

				advertising = (ADVERTISED_100baseT_Half |
					       ADVERTISED_TP);
			}
			break;

		case SPEED_1000:
			if (cmd->duplex != DUPLEX_FULL) {
M
Merav Sicron 已提交
580 581
				DP(BNX2X_MSG_ETHTOOL,
				   "1G half not supported\n");
582 583 584
				return -EINVAL;
			}

585 586 587 588 589 590 591 592 593
			if (bp->port.supported[cfg_idx] &
			     SUPPORTED_1000baseT_Full) {
				advertising = (ADVERTISED_1000baseT_Full |
					       ADVERTISED_TP);

			} else if (bp->port.supported[cfg_idx] &
				   SUPPORTED_1000baseKX_Full) {
				advertising = ADVERTISED_1000baseKX_Full;
			} else {
M
Merav Sicron 已提交
594 595
				DP(BNX2X_MSG_ETHTOOL,
				   "1G full not supported\n");
596 597 598 599 600 601 602
				return -EINVAL;
			}

			break;

		case SPEED_2500:
			if (cmd->duplex != DUPLEX_FULL) {
M
Merav Sicron 已提交
603
				DP(BNX2X_MSG_ETHTOOL,
604 605 606 607
				   "2.5G half not supported\n");
				return -EINVAL;
			}

Y
Yaniv Rosner 已提交
608 609
			if (!(bp->port.supported[cfg_idx]
			      & SUPPORTED_2500baseX_Full)) {
M
Merav Sicron 已提交
610
				DP(BNX2X_MSG_ETHTOOL,
611 612 613 614 615 616 617 618 619 620
				   "2.5G full not supported\n");
				return -EINVAL;
			}

			advertising = (ADVERTISED_2500baseX_Full |
				       ADVERTISED_TP);
			break;

		case SPEED_10000:
			if (cmd->duplex != DUPLEX_FULL) {
M
Merav Sicron 已提交
621 622
				DP(BNX2X_MSG_ETHTOOL,
				   "10G half not supported\n");
623 624
				return -EINVAL;
			}
Y
Yuval Mintz 已提交
625
			phy_idx = bnx2x_get_cur_phy_idx(bp);
626 627 628
			if ((bp->port.supported[cfg_idx] &
			     SUPPORTED_10000baseT_Full) &&
			    (bp->link_params.phy[phy_idx].media_type !=
Y
Yuval Mintz 已提交
629
			     ETH_PHY_SFP_1G_FIBER)) {
630 631 632 633 634 635 636
				advertising = (ADVERTISED_10000baseT_Full |
					       ADVERTISED_FIBRE);
			} else if (bp->port.supported[cfg_idx] &
			       SUPPORTED_10000baseKR_Full) {
				advertising = (ADVERTISED_10000baseKR_Full |
					       ADVERTISED_FIBRE);
			} else {
M
Merav Sicron 已提交
637 638
				DP(BNX2X_MSG_ETHTOOL,
				   "10G full not supported\n");
639 640 641 642 643 644
				return -EINVAL;
			}

			break;

		default:
M
Merav Sicron 已提交
645
			DP(BNX2X_MSG_ETHTOOL, "Unsupported speed %u\n", speed);
646 647 648
			return -EINVAL;
		}

Y
Yaniv Rosner 已提交
649 650 651
		bp->link_params.req_line_speed[cfg_idx] = speed;
		bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
		bp->port.advertising[cfg_idx] = advertising;
652 653
	}

M
Merav Sicron 已提交
654
	DP(BNX2X_MSG_ETHTOOL, "req_line_speed %d\n"
655
	   "  req_duplex %d  advertising 0x%x\n",
Y
Yaniv Rosner 已提交
656 657 658
	   bp->link_params.req_line_speed[cfg_idx],
	   bp->link_params.req_duplex[cfg_idx],
	   bp->port.advertising[cfg_idx]);
659

Y
Yaniv Rosner 已提交
660 661
	/* Set new config */
	bp->link_params.multi_phy_config = new_multi_phy_config;
662 663
	if (netif_running(dev)) {
		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
664
		bnx2x_force_link_reset(bp);
665 666 667 668 669 670
		bnx2x_link_set(bp);
	}

	return 0;
}

671 672
#define DUMP_ALL_PRESETS		0x1FFF
#define DUMP_MAX_PRESETS		13
673

674
static int __bnx2x_get_preset_regs_len(struct bnx2x *bp, u32 preset)
675 676
{
	if (CHIP_IS_E1(bp))
677
		return dump_num_registers[0][preset-1];
678
	else if (CHIP_IS_E1H(bp))
679
		return dump_num_registers[1][preset-1];
680
	else if (CHIP_IS_E2(bp))
681
		return dump_num_registers[2][preset-1];
682
	else if (CHIP_IS_E3A0(bp))
683
		return dump_num_registers[3][preset-1];
684
	else if (CHIP_IS_E3B0(bp))
685
		return dump_num_registers[4][preset-1];
686
	else
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
		return 0;
}

static int __bnx2x_get_regs_len(struct bnx2x *bp)
{
	u32 preset_idx;
	int regdump_len = 0;

	/* Calculate the total preset regs length */
	for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++)
		regdump_len += __bnx2x_get_preset_regs_len(bp, preset_idx);

	return regdump_len;
}

static int bnx2x_get_regs_len(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);
	int regdump_len = 0;

Y
Yuval Mintz 已提交
707 708 709
	if (IS_VF(bp))
		return 0;

710 711 712 713 714
	regdump_len = __bnx2x_get_regs_len(bp);
	regdump_len *= 4;
	regdump_len += sizeof(struct dump_header);

	return regdump_len;
715 716
}

717 718 719 720 721 722 723 724 725
#define IS_E1_REG(chips)	((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
#define IS_E1H_REG(chips)	((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
#define IS_E2_REG(chips)	((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
#define IS_E3A0_REG(chips)	((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
#define IS_E3B0_REG(chips)	((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)

#define IS_REG_IN_PRESET(presets, idx)  \
		((presets & (1 << (idx-1))) == (1 << (idx-1)))

726
/******* Paged registers info selectors ********/
E
Eric Dumazet 已提交
727
static const u32 *__bnx2x_get_page_addr_ar(struct bnx2x *bp)
728 729 730 731 732 733 734 735 736
{
	if (CHIP_IS_E2(bp))
		return page_vals_e2;
	else if (CHIP_IS_E3(bp))
		return page_vals_e3;
	else
		return NULL;
}

E
Eric Dumazet 已提交
737
static u32 __bnx2x_get_page_reg_num(struct bnx2x *bp)
738 739 740 741 742 743 744 745 746
{
	if (CHIP_IS_E2(bp))
		return PAGE_MODE_VALUES_E2;
	else if (CHIP_IS_E3(bp))
		return PAGE_MODE_VALUES_E3;
	else
		return 0;
}

E
Eric Dumazet 已提交
747
static const u32 *__bnx2x_get_page_write_ar(struct bnx2x *bp)
748 749 750 751 752 753 754 755 756
{
	if (CHIP_IS_E2(bp))
		return page_write_regs_e2;
	else if (CHIP_IS_E3(bp))
		return page_write_regs_e3;
	else
		return NULL;
}

E
Eric Dumazet 已提交
757
static u32 __bnx2x_get_page_write_num(struct bnx2x *bp)
758 759 760 761 762 763 764 765 766
{
	if (CHIP_IS_E2(bp))
		return PAGE_WRITE_REGS_E2;
	else if (CHIP_IS_E3(bp))
		return PAGE_WRITE_REGS_E3;
	else
		return 0;
}

E
Eric Dumazet 已提交
767
static const struct reg_addr *__bnx2x_get_page_read_ar(struct bnx2x *bp)
768 769 770 771 772 773 774 775 776
{
	if (CHIP_IS_E2(bp))
		return page_read_regs_e2;
	else if (CHIP_IS_E3(bp))
		return page_read_regs_e3;
	else
		return NULL;
}

E
Eric Dumazet 已提交
777
static u32 __bnx2x_get_page_read_num(struct bnx2x *bp)
778 779 780 781 782 783 784 785 786
{
	if (CHIP_IS_E2(bp))
		return PAGE_READ_REGS_E2;
	else if (CHIP_IS_E3(bp))
		return PAGE_READ_REGS_E3;
	else
		return 0;
}

787 788
static bool bnx2x_is_reg_in_chip(struct bnx2x *bp,
				       const struct reg_addr *reg_info)
789
{
790 791 792 793 794 795 796 797 798 799 800 801
	if (CHIP_IS_E1(bp))
		return IS_E1_REG(reg_info->chips);
	else if (CHIP_IS_E1H(bp))
		return IS_E1H_REG(reg_info->chips);
	else if (CHIP_IS_E2(bp))
		return IS_E2_REG(reg_info->chips);
	else if (CHIP_IS_E3A0(bp))
		return IS_E3A0_REG(reg_info->chips);
	else if (CHIP_IS_E3B0(bp))
		return IS_E3B0_REG(reg_info->chips);
	else
		return false;
802
}
803

804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
static bool bnx2x_is_wreg_in_chip(struct bnx2x *bp,
	const struct wreg_addr *wreg_info)
{
	if (CHIP_IS_E1(bp))
		return IS_E1_REG(wreg_info->chips);
	else if (CHIP_IS_E1H(bp))
		return IS_E1H_REG(wreg_info->chips);
	else if (CHIP_IS_E2(bp))
		return IS_E2_REG(wreg_info->chips);
	else if (CHIP_IS_E3A0(bp))
		return IS_E3A0_REG(wreg_info->chips);
	else if (CHIP_IS_E3B0(bp))
		return IS_E3B0_REG(wreg_info->chips);
	else
		return false;
819 820
}

821 822 823 824 825 826
/**
 * bnx2x_read_pages_regs - read "paged" registers
 *
 * @bp		device handle
 * @p		output buffer
 *
Y
Yuval Mintz 已提交
827 828 829 830
 * Reads "paged" memories: memories that may only be read by first writing to a
 * specific address ("write address") and then reading from a specific address
 * ("read address"). There may be more than one write address per "page" and
 * more than one read address per write address.
831
 */
832
static void bnx2x_read_pages_regs(struct bnx2x *bp, u32 *p, u32 preset)
D
Dmitry Kravkov 已提交
833 834
{
	u32 i, j, k, n;
835

836 837 838 839 840 841 842 843 844 845 846 847
	/* addresses of the paged registers */
	const u32 *page_addr = __bnx2x_get_page_addr_ar(bp);
	/* number of paged registers */
	int num_pages = __bnx2x_get_page_reg_num(bp);
	/* write addresses */
	const u32 *write_addr = __bnx2x_get_page_write_ar(bp);
	/* number of write addresses */
	int write_num = __bnx2x_get_page_write_num(bp);
	/* read addresses info */
	const struct reg_addr *read_addr = __bnx2x_get_page_read_ar(bp);
	/* number of read addresses */
	int read_num = __bnx2x_get_page_read_num(bp);
848
	u32 addr, size;
849 850 851 852

	for (i = 0; i < num_pages; i++) {
		for (j = 0; j < write_num; j++) {
			REG_WR(bp, write_addr[j], page_addr[i]);
853 854 855 856 857 858 859 860 861 862 863

			for (k = 0; k < read_num; k++) {
				if (IS_REG_IN_PRESET(read_addr[k].presets,
						     preset)) {
					size = read_addr[k].size;
					for (n = 0; n < size; n++) {
						addr = read_addr[k].addr + n*4;
						*p++ = REG_RD(bp, addr);
					}
				}
			}
D
Dmitry Kravkov 已提交
864 865 866 867
		}
	}
}

868
static int __bnx2x_get_preset_regs(struct bnx2x *bp, u32 *p, u32 preset)
869
{
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
	u32 i, j, addr;
	const struct wreg_addr *wreg_addr_p = NULL;

	if (CHIP_IS_E1(bp))
		wreg_addr_p = &wreg_addr_e1;
	else if (CHIP_IS_E1H(bp))
		wreg_addr_p = &wreg_addr_e1h;
	else if (CHIP_IS_E2(bp))
		wreg_addr_p = &wreg_addr_e2;
	else if (CHIP_IS_E3A0(bp))
		wreg_addr_p = &wreg_addr_e3;
	else if (CHIP_IS_E3B0(bp))
		wreg_addr_p = &wreg_addr_e3b0;

	/* Read the idle_chk registers */
	for (i = 0; i < IDLE_REGS_COUNT; i++) {
		if (bnx2x_is_reg_in_chip(bp, &idle_reg_addrs[i]) &&
		    IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
			for (j = 0; j < idle_reg_addrs[i].size; j++)
				*p++ = REG_RD(bp, idle_reg_addrs[i].addr + j*4);
		}
	}
892 893

	/* Read the regular registers */
894 895 896
	for (i = 0; i < REGS_COUNT; i++) {
		if (bnx2x_is_reg_in_chip(bp, &reg_addrs[i]) &&
		    IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
897 898
			for (j = 0; j < reg_addrs[i].size; j++)
				*p++ = REG_RD(bp, reg_addrs[i].addr + j*4);
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
		}
	}

	/* Read the CAM registers */
	if (bnx2x_is_wreg_in_chip(bp, wreg_addr_p) &&
	    IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
		for (i = 0; i < wreg_addr_p->size; i++) {
			*p++ = REG_RD(bp, wreg_addr_p->addr + i*4);

			/* In case of wreg_addr register, read additional
			   registers from read_regs array
			*/
			for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
				addr = *(wreg_addr_p->read_regs);
				*p++ = REG_RD(bp, addr + j*4);
			}
		}
	}

	/* Paged registers are supported in E2 & E3 only */
	if (CHIP_IS_E2(bp) || CHIP_IS_E3(bp)) {
920
		/* Read "paged" registers */
921 922 923 924 925 926 927 928 929
		bnx2x_read_pages_regs(bp, p, preset);
	}

	return 0;
}

static void __bnx2x_get_regs(struct bnx2x *bp, u32 *p)
{
	u32 preset_idx;
930

931 932 933 934 935 936 937 938 939 940 941
	/* Read all registers, by reading all preset registers */
	for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
		/* Skip presets with IOR */
		if ((preset_idx == 2) ||
		    (preset_idx == 5) ||
		    (preset_idx == 8) ||
		    (preset_idx == 11))
			continue;
		__bnx2x_get_preset_regs(bp, p, preset_idx);
		p += __bnx2x_get_preset_regs_len(bp, preset_idx);
	}
942 943
}

944 945 946
static void bnx2x_get_regs(struct net_device *dev,
			   struct ethtool_regs *regs, void *_p)
{
947
	u32 *p = _p;
948
	struct bnx2x *bp = netdev_priv(dev);
949
	struct dump_header dump_hdr = {0};
950

951
	regs->version = 2;
952 953 954 955 956
	memset(p, 0, regs->len);

	if (!netif_running(bp->dev))
		return;

957 958 959 960
	/* Disable parity attentions as long as following dump may
	 * cause false alarms by reading never written registers. We
	 * will re-enable parity attentions right after the dump.
	 */
961

962 963
	bnx2x_disable_blocks_parity(bp);

964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
	dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
	dump_hdr.preset = DUMP_ALL_PRESETS;
	dump_hdr.version = BNX2X_DUMP_VERSION;

	/* dump_meta_data presents OR of CHIP and PATH. */
	if (CHIP_IS_E1(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E1;
	} else if (CHIP_IS_E1H(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
	} else if (CHIP_IS_E2(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	} else if (CHIP_IS_E3A0(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	} else if (CHIP_IS_E3B0(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	}

	memcpy(p, &dump_hdr, sizeof(struct dump_header));
	p += dump_hdr.header_size + 1;
986

987 988 989
	/* Actually read the registers */
	__bnx2x_get_regs(bp, p);

990
	/* Re-enable parity attentions */
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
	bnx2x_clear_blocks_parity(bp);
	bnx2x_enable_blocks_parity(bp);
}

static int bnx2x_get_preset_regs_len(struct net_device *dev, u32 preset)
{
	struct bnx2x *bp = netdev_priv(dev);
	int regdump_len = 0;

	regdump_len = __bnx2x_get_preset_regs_len(bp, preset);
	regdump_len *= 4;
	regdump_len += sizeof(struct dump_header);

	return regdump_len;
}

static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
{
	struct bnx2x *bp = netdev_priv(dev);

	/* Use the ethtool_dump "flag" field as the dump preset index */
M
Michal Schmidt 已提交
1012 1013 1014
	if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
		return -EINVAL;

1015 1016 1017 1018 1019 1020 1021 1022 1023
	bp->dump_preset_idx = val->flag;
	return 0;
}

static int bnx2x_get_dump_flag(struct net_device *dev,
			       struct ethtool_dump *dump)
{
	struct bnx2x *bp = netdev_priv(dev);

1024 1025
	dump->version = BNX2X_DUMP_VERSION;
	dump->flag = bp->dump_preset_idx;
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
	/* Calculate the requested preset idx length */
	dump->len = bnx2x_get_preset_regs_len(dev, bp->dump_preset_idx);
	DP(BNX2X_MSG_ETHTOOL, "Get dump preset %d length=%d\n",
	   bp->dump_preset_idx, dump->len);
	return 0;
}

static int bnx2x_get_dump_data(struct net_device *dev,
			       struct ethtool_dump *dump,
			       void *buffer)
{
	u32 *p = buffer;
	struct bnx2x *bp = netdev_priv(dev);
	struct dump_header dump_hdr = {0};

	/* Disable parity attentions as long as following dump may
	 * cause false alarms by reading never written registers. We
	 * will re-enable parity attentions right after the dump.
	 */

	bnx2x_disable_blocks_parity(bp);

	dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
	dump_hdr.preset = bp->dump_preset_idx;
	dump_hdr.version = BNX2X_DUMP_VERSION;

	DP(BNX2X_MSG_ETHTOOL, "Get dump data of preset %d\n", dump_hdr.preset);

	/* dump_meta_data presents OR of CHIP and PATH. */
	if (CHIP_IS_E1(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E1;
	} else if (CHIP_IS_E1H(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
	} else if (CHIP_IS_E2(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	} else if (CHIP_IS_E3A0(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	} else if (CHIP_IS_E3B0(bp)) {
		dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
	}

	memcpy(p, &dump_hdr, sizeof(struct dump_header));
	p += dump_hdr.header_size + 1;

	/* Actually read the registers */
	__bnx2x_get_preset_regs(bp, p, dump_hdr.preset);

1076
	/* Re-enable parity attentions */
1077 1078 1079 1080
	bnx2x_clear_blocks_parity(bp);
	bnx2x_enable_blocks_parity(bp);

	return 0;
1081 1082 1083 1084 1085 1086 1087
}

static void bnx2x_get_drvinfo(struct net_device *dev,
			      struct ethtool_drvinfo *info)
{
	struct bnx2x *bp = netdev_priv(dev);

1088 1089
	strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
	strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
1090

1091 1092
	bnx2x_fill_fw_str(bp, info->fw_version, sizeof(info->fw_version));

1093
	strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
}

static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct bnx2x *bp = netdev_priv(dev);

	if (bp->flags & NO_WOL_FLAG) {
		wol->supported = 0;
		wol->wolopts = 0;
	} else {
		wol->supported = WAKE_MAGIC;
		if (bp->wol)
			wol->wolopts = WAKE_MAGIC;
		else
			wol->wolopts = 0;
	}
	memset(&wol->sopass, 0, sizeof(wol->sopass));
}

static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct bnx2x *bp = netdev_priv(dev);

M
Merav Sicron 已提交
1117
	if (wol->wolopts & ~WAKE_MAGIC) {
Y
Yuval Mintz 已提交
1118
		DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
1119
		return -EINVAL;
M
Merav Sicron 已提交
1120
	}
1121 1122

	if (wol->wolopts & WAKE_MAGIC) {
M
Merav Sicron 已提交
1123
		if (bp->flags & NO_WOL_FLAG) {
Y
Yuval Mintz 已提交
1124
			DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
1125
			return -EINVAL;
M
Merav Sicron 已提交
1126
		}
1127 1128 1129 1130
		bp->wol = 1;
	} else
		bp->wol = 0;

1131 1132 1133
	if (SHMEM2_HAS(bp, curr_cfg))
		SHMEM2_WR(bp, curr_cfg, CURR_CFG_MET_OS);

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
	return 0;
}

static u32 bnx2x_get_msglevel(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);

	return bp->msg_enable;
}

static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
{
	struct bnx2x *bp = netdev_priv(dev);

1148 1149
	if (capable(CAP_NET_ADMIN)) {
		/* dump MCP trace */
A
Ariel Elior 已提交
1150
		if (IS_PF(bp) && (level & BNX2X_MSG_MCP))
1151
			bnx2x_fw_dump_lvl(bp, KERN_INFO);
1152
		bp->msg_enable = level;
1153
	}
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
}

static int bnx2x_nway_reset(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);

	if (!bp->port.pmf)
		return 0;

	if (netif_running(dev)) {
		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Y
Yuval Mintz 已提交
1165
		bnx2x_force_link_reset(bp);
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
		bnx2x_link_set(bp);
	}

	return 0;
}

static u32 bnx2x_get_link(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);

D
Dmitry Kravkov 已提交
1176
	if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
1177 1178
		return 0;

D
Dmitry Kravkov 已提交
1179 1180 1181 1182
	if (IS_VF(bp))
		return !test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
				 &bp->vf_link_vars.link_report_flags);

1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
	return bp->link_vars.link_up;
}

static int bnx2x_get_eeprom_len(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);

	return bp->common.flash_size;
}

1193 1194
/* Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
 * had we done things the other way around, if two pfs from the same port would
A
Ariel Elior 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203
 * attempt to access nvram at the same time, we could run into a scenario such
 * as:
 * pf A takes the port lock.
 * pf B succeeds in taking the same lock since they are from the same port.
 * pf A takes the per pf misc lock. Performs eeprom access.
 * pf A finishes. Unlocks the per pf misc lock.
 * Pf B takes the lock and proceeds to perform it's own access.
 * pf A unlocks the per port lock, while pf B is still working (!).
 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
Y
Yuval Mintz 已提交
1204
 * access corrupted by pf B)
A
Ariel Elior 已提交
1205
 */
1206 1207 1208 1209
static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
{
	int port = BP_PORT(bp);
	int count, i;
A
Ariel Elior 已提交
1210 1211 1212 1213
	u32 val;

	/* acquire HW lock: protect against other PFs in PF Direct Assignment */
	bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
1214 1215

	/* adjust timeout for emulation/FPGA */
D
Dmitry Kravkov 已提交
1216
	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
	if (CHIP_REV_IS_SLOW(bp))
		count *= 100;

	/* request access to nvram interface */
	REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
	       (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));

	for (i = 0; i < count*10; i++) {
		val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
		if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
			break;

		udelay(5);
	}

	if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
M
Merav Sicron 已提交
1233 1234
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot get access to nvram interface\n");
1235
		bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
		return -EBUSY;
	}

	return 0;
}

static int bnx2x_release_nvram_lock(struct bnx2x *bp)
{
	int port = BP_PORT(bp);
	int count, i;
A
Ariel Elior 已提交
1246
	u32 val;
1247 1248

	/* adjust timeout for emulation/FPGA */
D
Dmitry Kravkov 已提交
1249
	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
	if (CHIP_REV_IS_SLOW(bp))
		count *= 100;

	/* relinquish nvram interface */
	REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
	       (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));

	for (i = 0; i < count*10; i++) {
		val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
		if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
			break;

		udelay(5);
	}

	if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
M
Merav Sicron 已提交
1266 1267
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot free access to nvram interface\n");
1268 1269 1270
		return -EBUSY;
	}

A
Ariel Elior 已提交
1271 1272
	/* release HW lock: protect against other PFs in PF Direct Assignment */
	bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
	return 0;
}

static void bnx2x_enable_nvram_access(struct bnx2x *bp)
{
	u32 val;

	val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);

	/* enable both bits, even on read */
	REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
	       (val | MCPR_NVM_ACCESS_ENABLE_EN |
		      MCPR_NVM_ACCESS_ENABLE_WR_EN));
}

static void bnx2x_disable_nvram_access(struct bnx2x *bp)
{
	u32 val;

	val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);

	/* disable both bits, even after read */
	REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
	       (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
			MCPR_NVM_ACCESS_ENABLE_WR_EN)));
}

static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
				  u32 cmd_flags)
{
	int count, i, rc;
	u32 val;

	/* build the command word */
	cmd_flags |= MCPR_NVM_COMMAND_DOIT;

	/* need to clear DONE bit separately */
	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);

	/* address of the NVRAM to read from */
	REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
	       (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));

	/* issue a read command */
	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);

	/* adjust timeout for emulation/FPGA */
D
Dmitry Kravkov 已提交
1320
	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
	if (CHIP_REV_IS_SLOW(bp))
		count *= 100;

	/* wait for completion */
	*ret_val = 0;
	rc = -EBUSY;
	for (i = 0; i < count; i++) {
		udelay(5);
		val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);

		if (val & MCPR_NVM_COMMAND_DONE) {
			val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
			/* we read nvram data in cpu order
			 * but ethtool sees it as an array of bytes
1335 1336
			 * converting to big-endian will do the work
			 */
1337 1338 1339 1340 1341
			*ret_val = cpu_to_be32(val);
			rc = 0;
			break;
		}
	}
M
Merav Sicron 已提交
1342 1343 1344
	if (rc == -EBUSY)
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "nvram read timeout expired\n");
1345 1346 1347
	return rc;
}

Y
Yuval Mintz 已提交
1348 1349
int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
		     int buf_size)
1350 1351 1352 1353 1354 1355
{
	int rc;
	u32 cmd_flags;
	__be32 val;

	if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
M
Merav Sicron 已提交
1356
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1357 1358 1359 1360 1361 1362
		   "Invalid parameter: offset 0x%x  buf_size 0x%x\n",
		   offset, buf_size);
		return -EINVAL;
	}

	if (offset + buf_size > bp->common.flash_size) {
M
Merav Sicron 已提交
1363 1364
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
		   offset, buf_size, bp->common.flash_size);
		return -EINVAL;
	}

	/* request access to nvram interface */
	rc = bnx2x_acquire_nvram_lock(bp);
	if (rc)
		return rc;

	/* enable access to nvram interface */
	bnx2x_enable_nvram_access(bp);

	/* read the first word(s) */
	cmd_flags = MCPR_NVM_COMMAND_FIRST;
	while ((buf_size > sizeof(u32)) && (rc == 0)) {
		rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
		memcpy(ret_buf, &val, 4);

		/* advance to the next dword */
		offset += sizeof(u32);
		ret_buf += sizeof(u32);
		buf_size -= sizeof(u32);
		cmd_flags = 0;
	}

	if (rc == 0) {
		cmd_flags |= MCPR_NVM_COMMAND_LAST;
		rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
		memcpy(ret_buf, &val, 4);
	}

	/* disable access to nvram interface */
	bnx2x_disable_nvram_access(bp);
	bnx2x_release_nvram_lock(bp);

	return rc;
}

1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
static int bnx2x_nvram_read32(struct bnx2x *bp, u32 offset, u32 *buf,
			      int buf_size)
{
	int rc;

	rc = bnx2x_nvram_read(bp, offset, (u8 *)buf, buf_size);

	if (!rc) {
		__be32 *be = (__be32 *)buf;

		while ((buf_size -= 4) >= 0)
			*buf++ = be32_to_cpu(*be++);
	}

	return rc;
}

1420 1421 1422 1423 1424 1425
static bool bnx2x_is_nvm_accessible(struct bnx2x *bp)
{
	int rc = 1;
	u16 pm = 0;
	struct net_device *dev = pci_get_drvdata(bp->pdev);

J
Jon Mason 已提交
1426
	if (bp->pdev->pm_cap)
1427
		rc = pci_read_config_word(bp->pdev,
J
Jon Mason 已提交
1428
					  bp->pdev->pm_cap + PCI_PM_CTRL, &pm);
1429

Y
Yuval Mintz 已提交
1430
	if ((rc && !netif_running(dev)) ||
1431
	    (!rc && ((pm & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0)))
1432 1433 1434 1435 1436
		return false;

	return true;
}

1437 1438 1439 1440 1441
static int bnx2x_get_eeprom(struct net_device *dev,
			    struct ethtool_eeprom *eeprom, u8 *eebuf)
{
	struct bnx2x *bp = netdev_priv(dev);

1442
	if (!bnx2x_is_nvm_accessible(bp)) {
M
Merav Sicron 已提交
1443 1444
		DP(BNX2X_MSG_ETHTOOL  | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
1445
		return -EAGAIN;
M
Merav Sicron 已提交
1446
	}
1447

M
Merav Sicron 已提交
1448
	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
1449
	   "  magic 0x%x  offset 0x%x (%d)  len 0x%x (%d)\n",
1450 1451 1452 1453 1454
	   eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
	   eeprom->len, eeprom->len);

	/* parameters already validated in ethtool_get_eeprom */

1455
	return bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
1456 1457
}

Y
Yuval Mintz 已提交
1458 1459 1460 1461 1462
static int bnx2x_get_module_eeprom(struct net_device *dev,
				   struct ethtool_eeprom *ee,
				   u8 *data)
{
	struct bnx2x *bp = netdev_priv(dev);
1463
	int rc = -EINVAL, phy_idx;
Y
Yuval Mintz 已提交
1464
	u8 *user_data = data;
1465
	unsigned int start_addr = ee->offset, xfer_size = 0;
Y
Yuval Mintz 已提交
1466

1467
	if (!bnx2x_is_nvm_accessible(bp)) {
Y
Yuval Mintz 已提交
1468 1469 1470 1471 1472 1473
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
		return -EAGAIN;
	}

	phy_idx = bnx2x_get_cur_phy_idx(bp);
1474 1475 1476 1477 1478 1479 1480 1481 1482

	/* Read A0 section */
	if (start_addr < ETH_MODULE_SFF_8079_LEN) {
		/* Limit transfer size to the A0 section boundary */
		if (start_addr + ee->len > ETH_MODULE_SFF_8079_LEN)
			xfer_size = ETH_MODULE_SFF_8079_LEN - start_addr;
		else
			xfer_size = ee->len;
		bnx2x_acquire_phy_lock(bp);
Y
Yuval Mintz 已提交
1483 1484
		rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
						  &bp->link_params,
1485 1486
						  I2C_DEV_ADDR_A0,
						  start_addr,
Y
Yuval Mintz 已提交
1487 1488
						  xfer_size,
						  user_data);
1489 1490 1491 1492 1493 1494
		bnx2x_release_phy_lock(bp);
		if (rc) {
			DP(BNX2X_MSG_ETHTOOL, "Failed reading A0 section\n");

			return -EINVAL;
		}
Y
Yuval Mintz 已提交
1495
		user_data += xfer_size;
1496
		start_addr += xfer_size;
Y
Yuval Mintz 已提交
1497 1498
	}

1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
	/* Read A2 section */
	if ((start_addr >= ETH_MODULE_SFF_8079_LEN) &&
	    (start_addr < ETH_MODULE_SFF_8472_LEN)) {
		xfer_size = ee->len - xfer_size;
		/* Limit transfer size to the A2 section boundary */
		if (start_addr + xfer_size > ETH_MODULE_SFF_8472_LEN)
			xfer_size = ETH_MODULE_SFF_8472_LEN - start_addr;
		start_addr -= ETH_MODULE_SFF_8079_LEN;
		bnx2x_acquire_phy_lock(bp);
		rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
						  &bp->link_params,
						  I2C_DEV_ADDR_A2,
						  start_addr,
						  xfer_size,
						  user_data);
		bnx2x_release_phy_lock(bp);
		if (rc) {
			DP(BNX2X_MSG_ETHTOOL, "Failed reading A2 section\n");
			return -EINVAL;
		}
	}
Y
Yuval Mintz 已提交
1520 1521 1522 1523 1524 1525 1526
	return rc;
}

static int bnx2x_get_module_info(struct net_device *dev,
				 struct ethtool_modinfo *modinfo)
{
	struct bnx2x *bp = netdev_priv(dev);
1527 1528 1529
	int phy_idx, rc;
	u8 sff8472_comp, diag_type;

1530
	if (!bnx2x_is_nvm_accessible(bp)) {
1531
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
Y
Yuval Mintz 已提交
1532 1533 1534 1535
		   "cannot access eeprom when the interface is down\n");
		return -EAGAIN;
	}
	phy_idx = bnx2x_get_cur_phy_idx(bp);
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
	bnx2x_acquire_phy_lock(bp);
	rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
					  &bp->link_params,
					  I2C_DEV_ADDR_A0,
					  SFP_EEPROM_SFF_8472_COMP_ADDR,
					  SFP_EEPROM_SFF_8472_COMP_SIZE,
					  &sff8472_comp);
	bnx2x_release_phy_lock(bp);
	if (rc) {
		DP(BNX2X_MSG_ETHTOOL, "Failed reading SFF-8472 comp field\n");
		return -EINVAL;
	}

	bnx2x_acquire_phy_lock(bp);
	rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
					  &bp->link_params,
					  I2C_DEV_ADDR_A0,
					  SFP_EEPROM_DIAG_TYPE_ADDR,
					  SFP_EEPROM_DIAG_TYPE_SIZE,
					  &diag_type);
	bnx2x_release_phy_lock(bp);
	if (rc) {
		DP(BNX2X_MSG_ETHTOOL, "Failed reading Diag Type field\n");
		return -EINVAL;
	}

	if (!sff8472_comp ||
	    (diag_type & SFP_EEPROM_DIAG_ADDR_CHANGE_REQ)) {
Y
Yuval Mintz 已提交
1564 1565
		modinfo->type = ETH_MODULE_SFF_8079;
		modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
1566 1567 1568
	} else {
		modinfo->type = ETH_MODULE_SFF_8472;
		modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
Y
Yuval Mintz 已提交
1569
	}
1570
	return 0;
Y
Yuval Mintz 已提交
1571 1572
}

1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
				   u32 cmd_flags)
{
	int count, i, rc;

	/* build the command word */
	cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;

	/* need to clear DONE bit separately */
	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);

	/* write the data */
	REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);

	/* address of the NVRAM to write to */
	REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
	       (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));

	/* issue the write command */
	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);

	/* adjust timeout for emulation/FPGA */
D
Dmitry Kravkov 已提交
1595
	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
	if (CHIP_REV_IS_SLOW(bp))
		count *= 100;

	/* wait for completion */
	rc = -EBUSY;
	for (i = 0; i < count; i++) {
		udelay(5);
		val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
		if (val & MCPR_NVM_COMMAND_DONE) {
			rc = 0;
			break;
		}
	}

M
Merav Sicron 已提交
1610 1611 1612
	if (rc == -EBUSY)
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "nvram write timeout expired\n");
1613 1614 1615 1616 1617 1618 1619 1620 1621
	return rc;
}

#define BYTE_OFFSET(offset)		(8 * (offset & 0x03))

static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
			      int buf_size)
{
	int rc;
1622 1623
	u32 cmd_flags, align_offset, val;
	__be32 val_be;
1624 1625

	if (offset + buf_size > bp->common.flash_size) {
M
Merav Sicron 已提交
1626 1627
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
		   offset, buf_size, bp->common.flash_size);
		return -EINVAL;
	}

	/* request access to nvram interface */
	rc = bnx2x_acquire_nvram_lock(bp);
	if (rc)
		return rc;

	/* enable access to nvram interface */
	bnx2x_enable_nvram_access(bp);

	cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
	align_offset = (offset & ~0x03);
1642
	rc = bnx2x_nvram_read_dword(bp, align_offset, &val_be, cmd_flags);
1643 1644 1645

	if (rc == 0) {
		/* nvram data is returned as an array of bytes
1646 1647
		 * convert it back to cpu order
		 */
1648 1649
		val = be32_to_cpu(val_be);

1650 1651 1652 1653
		val &= ~le32_to_cpu((__force __le32)
				    (0xff << BYTE_OFFSET(offset)));
		val |= le32_to_cpu((__force __le32)
				   (*data_buf << BYTE_OFFSET(offset)));
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677

		rc = bnx2x_nvram_write_dword(bp, align_offset, val,
					     cmd_flags);
	}

	/* disable access to nvram interface */
	bnx2x_disable_nvram_access(bp);
	bnx2x_release_nvram_lock(bp);

	return rc;
}

static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
			     int buf_size)
{
	int rc;
	u32 cmd_flags;
	u32 val;
	u32 written_so_far;

	if (buf_size == 1)	/* ethtool */
		return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);

	if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
M
Merav Sicron 已提交
1678
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1679 1680 1681 1682 1683 1684
		   "Invalid parameter: offset 0x%x  buf_size 0x%x\n",
		   offset, buf_size);
		return -EINVAL;
	}

	if (offset + buf_size > bp->common.flash_size) {
M
Merav Sicron 已提交
1685 1686
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
		   offset, buf_size, bp->common.flash_size);
		return -EINVAL;
	}

	/* request access to nvram interface */
	rc = bnx2x_acquire_nvram_lock(bp);
	if (rc)
		return rc;

	/* enable access to nvram interface */
	bnx2x_enable_nvram_access(bp);

	written_so_far = 0;
	cmd_flags = MCPR_NVM_COMMAND_FIRST;
	while ((written_so_far < buf_size) && (rc == 0)) {
		if (written_so_far == (buf_size - sizeof(u32)))
			cmd_flags |= MCPR_NVM_COMMAND_LAST;
D
Dmitry Kravkov 已提交
1704
		else if (((offset + 4) % BNX2X_NVRAM_PAGE_SIZE) == 0)
1705
			cmd_flags |= MCPR_NVM_COMMAND_LAST;
D
Dmitry Kravkov 已提交
1706
		else if ((offset % BNX2X_NVRAM_PAGE_SIZE) == 0)
1707 1708 1709 1710
			cmd_flags |= MCPR_NVM_COMMAND_FIRST;

		memcpy(&val, data_buf, 4);

1711 1712 1713 1714 1715 1716
		/* Notice unlike bnx2x_nvram_read_dword() this will not
		 * change val using be32_to_cpu(), which causes data to flip
		 * if the eeprom is read and then written back. This is due
		 * to tools utilizing this functionality that would break
		 * if this would be resolved.
		 */
1717 1718 1719 1720 1721 1722
		rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);

		/* advance to the next dword */
		offset += sizeof(u32);
		data_buf += sizeof(u32);
		written_so_far += sizeof(u32);
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738

		/* At end of each 4Kb page, release nvram lock to allow MFW
		 * chance to take it for its own use.
		 */
		if ((cmd_flags & MCPR_NVM_COMMAND_LAST) &&
		    (written_so_far < buf_size)) {
			DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
			   "Releasing NVM lock after offset 0x%x\n",
			   (u32)(offset - sizeof(u32)));
			bnx2x_release_nvram_lock(bp);
			usleep_range(1000, 2000);
			rc = bnx2x_acquire_nvram_lock(bp);
			if (rc)
				return rc;
		}

1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
		cmd_flags = 0;
	}

	/* disable access to nvram interface */
	bnx2x_disable_nvram_access(bp);
	bnx2x_release_nvram_lock(bp);

	return rc;
}

static int bnx2x_set_eeprom(struct net_device *dev,
			    struct ethtool_eeprom *eeprom, u8 *eebuf)
{
	struct bnx2x *bp = netdev_priv(dev);
	int port = BP_PORT(bp);
	int rc = 0;
Y
Yaniv Rosner 已提交
1755
	u32 ext_phy_config;
1756 1757

	if (!bnx2x_is_nvm_accessible(bp)) {
M
Merav Sicron 已提交
1758 1759
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
1760
		return -EAGAIN;
M
Merav Sicron 已提交
1761
	}
1762

M
Merav Sicron 已提交
1763
	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
1764
	   "  magic 0x%x  offset 0x%x (%d)  len 0x%x (%d)\n",
1765 1766 1767 1768 1769 1770 1771
	   eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
	   eeprom->len, eeprom->len);

	/* parameters already validated in ethtool_set_eeprom */

	/* PHY eeprom can be accessed only by the PMF */
	if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
M
Merav Sicron 已提交
1772 1773 1774
	    !bp->port.pmf) {
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "wrong magic or interface is not pmf\n");
1775
		return -EINVAL;
M
Merav Sicron 已提交
1776
	}
1777

Y
Yaniv Rosner 已提交
1778 1779 1780 1781
	ext_phy_config =
		SHMEM_RD(bp,
			 dev_info.port_hw_config[port].external_phy_config);

1782 1783 1784 1785 1786 1787 1788
	if (eeprom->magic == 0x50485950) {
		/* 'PHYP' (0x50485950): prepare phy for FW upgrade */
		bnx2x_stats_handle(bp, STATS_EVENT_STOP);

		bnx2x_acquire_phy_lock(bp);
		rc |= bnx2x_link_reset(&bp->link_params,
				       &bp->link_vars, 0);
Y
Yaniv Rosner 已提交
1789
		if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809
					PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
			bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
				       MISC_REGISTERS_GPIO_HIGH, port);
		bnx2x_release_phy_lock(bp);
		bnx2x_link_report(bp);

	} else if (eeprom->magic == 0x50485952) {
		/* 'PHYR' (0x50485952): re-init link after FW upgrade */
		if (bp->state == BNX2X_STATE_OPEN) {
			bnx2x_acquire_phy_lock(bp);
			rc |= bnx2x_link_reset(&bp->link_params,
					       &bp->link_vars, 1);

			rc |= bnx2x_phy_init(&bp->link_params,
					     &bp->link_vars);
			bnx2x_release_phy_lock(bp);
			bnx2x_calc_fc_adv(bp);
		}
	} else if (eeprom->magic == 0x53985943) {
		/* 'PHYC' (0x53985943): PHY FW upgrade completed */
Y
Yaniv Rosner 已提交
1810
		if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
1811 1812 1813 1814 1815 1816 1817 1818
				       PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {

			/* DSP Remove Download Mode */
			bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
				       MISC_REGISTERS_GPIO_LOW, port);

			bnx2x_acquire_phy_lock(bp);

Y
Yaniv Rosner 已提交
1819 1820
			bnx2x_sfx7101_sp_sw_reset(bp,
						&bp->link_params.phy[EXT_PHY1]);
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832

			/* wait 0.5 sec to allow it to run */
			msleep(500);
			bnx2x_ext_phy_hw_reset(bp, port);
			msleep(500);
			bnx2x_release_phy_lock(bp);
		}
	} else
		rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);

	return rc;
}
D
Dmitry Kravkov 已提交
1833

1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872
static int bnx2x_get_coalesce(struct net_device *dev,
			      struct ethtool_coalesce *coal)
{
	struct bnx2x *bp = netdev_priv(dev);

	memset(coal, 0, sizeof(struct ethtool_coalesce));

	coal->rx_coalesce_usecs = bp->rx_ticks;
	coal->tx_coalesce_usecs = bp->tx_ticks;

	return 0;
}

static int bnx2x_set_coalesce(struct net_device *dev,
			      struct ethtool_coalesce *coal)
{
	struct bnx2x *bp = netdev_priv(dev);

	bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
	if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
		bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;

	bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
	if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
		bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;

	if (netif_running(dev))
		bnx2x_update_coalesce(bp);

	return 0;
}

static void bnx2x_get_ringparam(struct net_device *dev,
				struct ethtool_ringparam *ering)
{
	struct bnx2x *bp = netdev_priv(dev);

	ering->rx_max_pending = MAX_RX_AVAIL;

1873 1874 1875
	if (bp->rx_ring_size)
		ering->rx_pending = bp->rx_ring_size;
	else
1876
		ering->rx_pending = MAX_RX_AVAIL;
1877

B
Barak Witkowski 已提交
1878
	ering->tx_max_pending = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1879 1880 1881 1882 1883 1884 1885 1886
	ering->tx_pending = bp->tx_ring_size;
}

static int bnx2x_set_ringparam(struct net_device *dev,
			       struct ethtool_ringparam *ering)
{
	struct bnx2x *bp = netdev_priv(dev);

1887 1888 1889 1890
	DP(BNX2X_MSG_ETHTOOL,
	   "set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
	   ering->rx_pending, ering->tx_pending);

1891 1892 1893 1894 1895 1896
	if (pci_num_vf(bp->pdev)) {
		DP(BNX2X_MSG_IOV,
		   "VFs are enabled, can not change ring parameters\n");
		return -EPERM;
	}

1897
	if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
M
Merav Sicron 已提交
1898 1899
		DP(BNX2X_MSG_ETHTOOL,
		   "Handling parity error recovery. Try again later\n");
1900 1901 1902 1903
		return -EAGAIN;
	}

	if ((ering->rx_pending > MAX_RX_AVAIL) ||
1904 1905
	    (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
						    MIN_RX_SIZE_TPA)) ||
1906
	    (ering->tx_pending > (IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL)) ||
M
Merav Sicron 已提交
1907 1908
	    (ering->tx_pending <= MAX_SKB_FRAGS + 4)) {
		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
1909
		return -EINVAL;
M
Merav Sicron 已提交
1910
	}
1911 1912 1913 1914

	bp->rx_ring_size = ering->rx_pending;
	bp->tx_ring_size = ering->tx_pending;

1915
	return bnx2x_reload_if_running(dev);
1916 1917 1918 1919 1920 1921
}

static void bnx2x_get_pauseparam(struct net_device *dev,
				 struct ethtool_pauseparam *epause)
{
	struct bnx2x *bp = netdev_priv(dev);
Y
Yaniv Rosner 已提交
1922
	int cfg_idx = bnx2x_get_link_cfg_idx(bp);
1923 1924
	int cfg_reg;

Y
Yaniv Rosner 已提交
1925 1926
	epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
			   BNX2X_FLOW_CTRL_AUTO);
1927

1928
	if (!epause->autoneg)
1929
		cfg_reg = bp->link_params.req_flow_ctrl[cfg_idx];
1930 1931 1932 1933
	else
		cfg_reg = bp->link_params.req_fc_auto_adv;

	epause->rx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_RX) ==
1934
			    BNX2X_FLOW_CTRL_RX);
1935
	epause->tx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_TX) ==
1936 1937
			    BNX2X_FLOW_CTRL_TX);

M
Merav Sicron 已提交
1938
	DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
1939
	   "  autoneg %d  rx_pause %d  tx_pause %d\n",
1940 1941 1942 1943 1944 1945 1946
	   epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
}

static int bnx2x_set_pauseparam(struct net_device *dev,
				struct ethtool_pauseparam *epause)
{
	struct bnx2x *bp = netdev_priv(dev);
Y
Yaniv Rosner 已提交
1947
	u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
D
Dmitry Kravkov 已提交
1948
	if (IS_MF(bp))
1949 1950
		return 0;

M
Merav Sicron 已提交
1951
	DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
1952
	   "  autoneg %d  rx_pause %d  tx_pause %d\n",
1953 1954
	   epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);

Y
Yaniv Rosner 已提交
1955
	bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
1956 1957

	if (epause->rx_pause)
Y
Yaniv Rosner 已提交
1958
		bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
1959 1960

	if (epause->tx_pause)
Y
Yaniv Rosner 已提交
1961
		bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
1962

Y
Yaniv Rosner 已提交
1963 1964
	if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
		bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
1965 1966

	if (epause->autoneg) {
Y
Yaniv Rosner 已提交
1967
		if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
M
Merav Sicron 已提交
1968
			DP(BNX2X_MSG_ETHTOOL, "autoneg not supported\n");
1969 1970 1971
			return -EINVAL;
		}

Y
Yaniv Rosner 已提交
1972 1973 1974 1975
		if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
			bp->link_params.req_flow_ctrl[cfg_idx] =
				BNX2X_FLOW_CTRL_AUTO;
		}
1976
		bp->link_params.req_fc_auto_adv = 0;
1977 1978 1979 1980 1981
		if (epause->rx_pause)
			bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_RX;

		if (epause->tx_pause)
			bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_TX;
1982 1983 1984

		if (!bp->link_params.req_fc_auto_adv)
			bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_NONE;
1985 1986
	}

M
Merav Sicron 已提交
1987
	DP(BNX2X_MSG_ETHTOOL,
Y
Yaniv Rosner 已提交
1988
	   "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
1989 1990 1991

	if (netif_running(dev)) {
		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1992
		bnx2x_force_link_reset(bp);
1993 1994 1995 1996 1997 1998
		bnx2x_link_set(bp);
	}

	return 0;
}

1999
static const char bnx2x_tests_str_arr[BNX2X_NUM_TESTS_SF][ETH_GSTRING_LEN] = {
2000 2001 2002 2003 2004 2005 2006
	"register_test (offline)    ",
	"memory_test (offline)      ",
	"int_loopback_test (offline)",
	"ext_loopback_test (offline)",
	"nvram_test (online)        ",
	"interrupt_test (online)    ",
	"link_test (online)         "
2007 2008
};

Y
Yuval Mintz 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
enum {
	BNX2X_PRI_FLAG_ISCSI,
	BNX2X_PRI_FLAG_FCOE,
	BNX2X_PRI_FLAG_STORAGE,
	BNX2X_PRI_FLAG_LEN,
};

static const char bnx2x_private_arr[BNX2X_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
	"iSCSI offload support",
	"FCoE offload support",
	"Storage only interface"
};

Y
Yuval Mintz 已提交
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058
static u32 bnx2x_eee_to_adv(u32 eee_adv)
{
	u32 modes = 0;

	if (eee_adv & SHMEM_EEE_100M_ADV)
		modes |= ADVERTISED_100baseT_Full;
	if (eee_adv & SHMEM_EEE_1G_ADV)
		modes |= ADVERTISED_1000baseT_Full;
	if (eee_adv & SHMEM_EEE_10G_ADV)
		modes |= ADVERTISED_10000baseT_Full;

	return modes;
}

static u32 bnx2x_adv_to_eee(u32 modes, u32 shift)
{
	u32 eee_adv = 0;
	if (modes & ADVERTISED_100baseT_Full)
		eee_adv |= SHMEM_EEE_100M_ADV;
	if (modes & ADVERTISED_1000baseT_Full)
		eee_adv |= SHMEM_EEE_1G_ADV;
	if (modes & ADVERTISED_10000baseT_Full)
		eee_adv |= SHMEM_EEE_10G_ADV;

	return eee_adv << shift;
}

static int bnx2x_get_eee(struct net_device *dev, struct ethtool_eee *edata)
{
	struct bnx2x *bp = netdev_priv(dev);
	u32 eee_cfg;

	if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
		DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
		return -EOPNOTSUPP;
	}

Y
Yuval Mintz 已提交
2059
	eee_cfg = bp->link_vars.eee_status;
Y
Yuval Mintz 已提交
2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095

	edata->supported =
		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_SUPPORTED_MASK) >>
				 SHMEM_EEE_SUPPORTED_SHIFT);

	edata->advertised =
		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_ADV_STATUS_MASK) >>
				 SHMEM_EEE_ADV_STATUS_SHIFT);
	edata->lp_advertised =
		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_LP_ADV_STATUS_MASK) >>
				 SHMEM_EEE_LP_ADV_STATUS_SHIFT);

	/* SHMEM value is in 16u units --> Convert to 1u units. */
	edata->tx_lpi_timer = (eee_cfg & SHMEM_EEE_TIMER_MASK) << 4;

	edata->eee_enabled    = (eee_cfg & SHMEM_EEE_REQUESTED_BIT)	? 1 : 0;
	edata->eee_active     = (eee_cfg & SHMEM_EEE_ACTIVE_BIT)	? 1 : 0;
	edata->tx_lpi_enabled = (eee_cfg & SHMEM_EEE_LPI_REQUESTED_BIT) ? 1 : 0;

	return 0;
}

static int bnx2x_set_eee(struct net_device *dev, struct ethtool_eee *edata)
{
	struct bnx2x *bp = netdev_priv(dev);
	u32 eee_cfg;
	u32 advertised;

	if (IS_MF(bp))
		return 0;

	if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
		DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
		return -EOPNOTSUPP;
	}

Y
Yuval Mintz 已提交
2096
	eee_cfg = bp->link_vars.eee_status;
Y
Yuval Mintz 已提交
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106

	if (!(eee_cfg & SHMEM_EEE_SUPPORTED_MASK)) {
		DP(BNX2X_MSG_ETHTOOL, "Board does not support EEE!\n");
		return -EOPNOTSUPP;
	}

	advertised = bnx2x_adv_to_eee(edata->advertised,
				      SHMEM_EEE_ADV_STATUS_SHIFT);
	if ((advertised != (eee_cfg & SHMEM_EEE_ADV_STATUS_MASK))) {
		DP(BNX2X_MSG_ETHTOOL,
2107
		   "Direct manipulation of EEE advertisement is not supported\n");
Y
Yuval Mintz 已提交
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141
		return -EINVAL;
	}

	if (edata->tx_lpi_timer > EEE_MODE_TIMER_MASK) {
		DP(BNX2X_MSG_ETHTOOL,
		   "Maximal Tx Lpi timer supported is %x(u)\n",
		   EEE_MODE_TIMER_MASK);
		return -EINVAL;
	}
	if (edata->tx_lpi_enabled &&
	    (edata->tx_lpi_timer < EEE_MODE_NVRAM_AGGRESSIVE_TIME)) {
		DP(BNX2X_MSG_ETHTOOL,
		   "Minimal Tx Lpi timer supported is %d(u)\n",
		   EEE_MODE_NVRAM_AGGRESSIVE_TIME);
		return -EINVAL;
	}

	/* All is well; Apply changes*/
	if (edata->eee_enabled)
		bp->link_params.eee_mode |= EEE_MODE_ADV_LPI;
	else
		bp->link_params.eee_mode &= ~EEE_MODE_ADV_LPI;

	if (edata->tx_lpi_enabled)
		bp->link_params.eee_mode |= EEE_MODE_ENABLE_LPI;
	else
		bp->link_params.eee_mode &= ~EEE_MODE_ENABLE_LPI;

	bp->link_params.eee_mode &= ~EEE_MODE_TIMER_MASK;
	bp->link_params.eee_mode |= (edata->tx_lpi_timer &
				    EEE_MODE_TIMER_MASK) |
				    EEE_MODE_OVERRIDE_NVRAM |
				    EEE_MODE_OUTPUT_TIME;

2142
	/* Restart link to propagate changes */
Y
Yuval Mintz 已提交
2143 2144
	if (netif_running(dev)) {
		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
Y
Yuval Mintz 已提交
2145
		bnx2x_force_link_reset(bp);
Y
Yuval Mintz 已提交
2146 2147 2148 2149 2150 2151
		bnx2x_link_set(bp);
	}

	return 0;
}

2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169
enum {
	BNX2X_CHIP_E1_OFST = 0,
	BNX2X_CHIP_E1H_OFST,
	BNX2X_CHIP_E2_OFST,
	BNX2X_CHIP_E3_OFST,
	BNX2X_CHIP_E3B0_OFST,
	BNX2X_CHIP_MAX_OFST
};

#define BNX2X_CHIP_MASK_E1	(1 << BNX2X_CHIP_E1_OFST)
#define BNX2X_CHIP_MASK_E1H	(1 << BNX2X_CHIP_E1H_OFST)
#define BNX2X_CHIP_MASK_E2	(1 << BNX2X_CHIP_E2_OFST)
#define BNX2X_CHIP_MASK_E3	(1 << BNX2X_CHIP_E3_OFST)
#define BNX2X_CHIP_MASK_E3B0	(1 << BNX2X_CHIP_E3B0_OFST)

#define BNX2X_CHIP_MASK_ALL	((1 << BNX2X_CHIP_MAX_OFST) - 1)
#define BNX2X_CHIP_MASK_E1X	(BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)

2170 2171 2172
static int bnx2x_test_registers(struct bnx2x *bp)
{
	int idx, i, rc = -ENODEV;
2173
	u32 wr_val = 0, hw;
2174 2175
	int port = BP_PORT(bp);
	static const struct {
2176
		u32 hw;
2177 2178 2179 2180
		u32 offset0;
		u32 offset1;
		u32 mask;
	} reg_tbl[] = {
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258
/* 0 */		{ BNX2X_CHIP_MASK_ALL,
			BRB1_REG_PAUSE_LOW_THRESHOLD_0,	4, 0x000003ff },
		{ BNX2X_CHIP_MASK_ALL,
			DORQ_REG_DB_ADDR0,		4, 0xffffffff },
		{ BNX2X_CHIP_MASK_E1X,
			HC_REG_AGG_INT_0,		4, 0x000003ff },
		{ BNX2X_CHIP_MASK_ALL,
			PBF_REG_MAC_IF0_ENABLE,		4, 0x00000001 },
		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2 | BNX2X_CHIP_MASK_E3,
			PBF_REG_P0_INIT_CRD,		4, 0x000007ff },
		{ BNX2X_CHIP_MASK_E3B0,
			PBF_REG_INIT_CRD_Q0,		4, 0x000007ff },
		{ BNX2X_CHIP_MASK_ALL,
			PRS_REG_CID_PORT_0,		4, 0x00ffffff },
		{ BNX2X_CHIP_MASK_ALL,
			PXP2_REG_PSWRQ_CDU0_L2P,	4, 0x000fffff },
		{ BNX2X_CHIP_MASK_ALL,
			PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
		{ BNX2X_CHIP_MASK_ALL,
			PXP2_REG_PSWRQ_TM0_L2P,		4, 0x000fffff },
/* 10 */	{ BNX2X_CHIP_MASK_ALL,
			PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
		{ BNX2X_CHIP_MASK_ALL,
			PXP2_REG_PSWRQ_TSDM0_L2P,	4, 0x000fffff },
		{ BNX2X_CHIP_MASK_ALL,
			QM_REG_CONNNUM_0,		4, 0x000fffff },
		{ BNX2X_CHIP_MASK_ALL,
			TM_REG_LIN0_MAX_ACTIVE_CID,	4, 0x0003ffff },
		{ BNX2X_CHIP_MASK_ALL,
			SRC_REG_KEYRSS0_0,		40, 0xffffffff },
		{ BNX2X_CHIP_MASK_ALL,
			SRC_REG_KEYRSS0_7,		40, 0xffffffff },
		{ BNX2X_CHIP_MASK_ALL,
			XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
		{ BNX2X_CHIP_MASK_ALL,
			XCM_REG_WU_DA_CNT_CMD00,	4, 0x00000003 },
		{ BNX2X_CHIP_MASK_ALL,
			XCM_REG_GLB_DEL_ACK_MAX_CNT_0,	4, 0x000000ff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_T_BIT,		4, 0x00000001 },
/* 20 */	{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
			NIG_REG_EMAC0_IN_EN,		4, 0x00000001 },
		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
			NIG_REG_BMAC0_IN_EN,		4, 0x00000001 },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_XCM0_OUT_EN,		4, 0x00000001 },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_BRB0_OUT_EN,		4, 0x00000001 },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_XCM_MASK,		4, 0x00000007 },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_ACPI_PAT_6_LEN,	68, 0x000000ff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_ACPI_PAT_0_CRC,	68, 0xffffffff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_DEST_MAC_0_0,	160, 0xffffffff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_DEST_IP_0_1,	160, 0xffffffff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_IPV4_IPV6_0,	160, 0x00000001 },
/* 30 */	{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_DEST_UDP_0,	160, 0x0000ffff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_DEST_TCP_0,	160, 0x0000ffff },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LLH0_VLAN_ID_0,	160, 0x00000fff },
		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
			NIG_REG_XGXS_SERDES0_MODE_SEL,	4, 0x00000001 },
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001},
		{ BNX2X_CHIP_MASK_ALL,
			NIG_REG_STATUS_INTERRUPT_PORT0,	4, 0x07ffffff },
		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
			NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
			NIG_REG_SERDES0_CTRL_PHY_ADDR,	16, 0x0000001f },

		{ BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
2259 2260
	};

2261
	if (!bnx2x_is_nvm_accessible(bp)) {
M
Merav Sicron 已提交
2262 2263
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
2264
		return rc;
M
Merav Sicron 已提交
2265
	}
2266

2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277
	if (CHIP_IS_E1(bp))
		hw = BNX2X_CHIP_MASK_E1;
	else if (CHIP_IS_E1H(bp))
		hw = BNX2X_CHIP_MASK_E1H;
	else if (CHIP_IS_E2(bp))
		hw = BNX2X_CHIP_MASK_E2;
	else if (CHIP_IS_E3B0(bp))
		hw = BNX2X_CHIP_MASK_E3B0;
	else /* e3 A0 */
		hw = BNX2X_CHIP_MASK_E3;

2278
	/* Repeat the test twice:
2279 2280
	 * First by writing 0x00000000, second by writing 0xffffffff
	 */
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293
	for (idx = 0; idx < 2; idx++) {

		switch (idx) {
		case 0:
			wr_val = 0;
			break;
		case 1:
			wr_val = 0xffffffff;
			break;
		}

		for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
			u32 offset, mask, save_val, val;
2294
			if (!(hw & reg_tbl[i].hw))
D
Dmitry Kravkov 已提交
2295
				continue;
2296 2297 2298 2299 2300 2301

			offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
			mask = reg_tbl[i].mask;

			save_val = REG_RD(bp, offset);

V
Vladislav Zolotarov 已提交
2302
			REG_WR(bp, offset, wr_val & mask);
D
Dmitry Kravkov 已提交
2303

2304 2305 2306 2307 2308 2309 2310
			val = REG_RD(bp, offset);

			/* Restore the original register's value */
			REG_WR(bp, offset, save_val);

			/* verify value is as expected */
			if ((val & mask) != (wr_val & mask)) {
M
Merav Sicron 已提交
2311
				DP(BNX2X_MSG_ETHTOOL,
2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
				   "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
				   offset, val, wr_val, mask);
				goto test_reg_exit;
			}
		}
	}

	rc = 0;

test_reg_exit:
	return rc;
}

static int bnx2x_test_memory(struct bnx2x *bp)
{
	int i, j, rc = -ENODEV;
2328
	u32 val, index;
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342
	static const struct {
		u32 offset;
		int size;
	} mem_tbl[] = {
		{ CCM_REG_XX_DESCR_TABLE,   CCM_REG_XX_DESCR_TABLE_SIZE },
		{ CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
		{ CFC_REG_LINK_LIST,        CFC_REG_LINK_LIST_SIZE },
		{ DMAE_REG_CMD_MEM,         DMAE_REG_CMD_MEM_SIZE },
		{ TCM_REG_XX_DESCR_TABLE,   TCM_REG_XX_DESCR_TABLE_SIZE },
		{ UCM_REG_XX_DESCR_TABLE,   UCM_REG_XX_DESCR_TABLE_SIZE },
		{ XCM_REG_XX_DESCR_TABLE,   XCM_REG_XX_DESCR_TABLE_SIZE },

		{ 0xffffffff, 0 }
	};
2343

2344 2345 2346
	static const struct {
		char *name;
		u32 offset;
2347
		u32 hw_mask[BNX2X_CHIP_MAX_OFST];
2348
	} prty_tbl[] = {
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
		{ "CCM_PRTY_STS",  CCM_REG_CCM_PRTY_STS,
			{0x3ffc0, 0,   0, 0} },
		{ "CFC_PRTY_STS",  CFC_REG_CFC_PRTY_STS,
			{0x2,     0x2, 0, 0} },
		{ "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS,
			{0,       0,   0, 0} },
		{ "TCM_PRTY_STS",  TCM_REG_TCM_PRTY_STS,
			{0x3ffc0, 0,   0, 0} },
		{ "UCM_PRTY_STS",  UCM_REG_UCM_PRTY_STS,
			{0x3ffc0, 0,   0, 0} },
		{ "XCM_PRTY_STS",  XCM_REG_XCM_PRTY_STS,
			{0x3ffc1, 0,   0, 0} },

		{ NULL, 0xffffffff, {0, 0, 0, 0} }
2363 2364
	};

2365
	if (!bnx2x_is_nvm_accessible(bp)) {
M
Merav Sicron 已提交
2366 2367
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
2368
		return rc;
M
Merav Sicron 已提交
2369
	}
2370

2371 2372 2373 2374 2375 2376 2377 2378 2379
	if (CHIP_IS_E1(bp))
		index = BNX2X_CHIP_E1_OFST;
	else if (CHIP_IS_E1H(bp))
		index = BNX2X_CHIP_E1H_OFST;
	else if (CHIP_IS_E2(bp))
		index = BNX2X_CHIP_E2_OFST;
	else /* e3 */
		index = BNX2X_CHIP_E3_OFST;

D
Dmitry Kravkov 已提交
2380 2381 2382
	/* pre-Check the parity status */
	for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
		val = REG_RD(bp, prty_tbl[i].offset);
2383
		if (val & ~(prty_tbl[i].hw_mask[index])) {
M
Merav Sicron 已提交
2384
			DP(BNX2X_MSG_ETHTOOL,
D
Dmitry Kravkov 已提交
2385 2386 2387 2388 2389
			   "%s is 0x%x\n", prty_tbl[i].name, val);
			goto test_mem_exit;
		}
	}

2390 2391 2392 2393 2394 2395 2396 2397
	/* Go through all the memories */
	for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
		for (j = 0; j < mem_tbl[i].size; j++)
			REG_RD(bp, mem_tbl[i].offset + j*4);

	/* Check the parity status */
	for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
		val = REG_RD(bp, prty_tbl[i].offset);
2398
		if (val & ~(prty_tbl[i].hw_mask[index])) {
M
Merav Sicron 已提交
2399
			DP(BNX2X_MSG_ETHTOOL,
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
			   "%s is 0x%x\n", prty_tbl[i].name, val);
			goto test_mem_exit;
		}
	}

	rc = 0;

test_mem_exit:
	return rc;
}

Y
Yaniv Rosner 已提交
2411
static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
2412
{
D
Dmitry Kravkov 已提交
2413
	int cnt = 1400;
2414

2415
	if (link_up) {
Y
Yaniv Rosner 已提交
2416
		while (bnx2x_link_test(bp, is_serdes) && cnt--)
2417 2418 2419
			msleep(20);

		if (cnt <= 0 && bnx2x_link_test(bp, is_serdes))
M
Merav Sicron 已提交
2420
			DP(BNX2X_MSG_ETHTOOL, "Timeout waiting for link up\n");
2421 2422 2423 2424 2425 2426 2427 2428

		cnt = 1400;
		while (!bp->link_vars.link_up && cnt--)
			msleep(20);

		if (cnt <= 0 && !bp->link_vars.link_up)
			DP(BNX2X_MSG_ETHTOOL,
			   "Timeout waiting for link init\n");
2429
	}
2430 2431
}

2432
static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode)
2433 2434 2435 2436 2437 2438
{
	unsigned int pkt_size, num_pkts, i;
	struct sk_buff *skb;
	unsigned char *packet;
	struct bnx2x_fastpath *fp_rx = &bp->fp[0];
	struct bnx2x_fastpath *fp_tx = &bp->fp[0];
2439
	struct bnx2x_fp_txdata *txdata = fp_tx->txdata_ptr[0];
2440 2441
	u16 tx_start_idx, tx_idx;
	u16 rx_start_idx, rx_idx;
2442
	u16 pkt_prod, bd_prod;
2443 2444 2445 2446
	struct sw_tx_bd *tx_buf;
	struct eth_tx_start_bd *tx_start_bd;
	dma_addr_t mapping;
	union eth_rx_cqe *cqe;
2447
	u8 cqe_fp_flags, cqe_fp_type;
2448 2449 2450
	struct sw_rx_bd *rx_buf;
	u16 len;
	int rc = -ENODEV;
2451
	u8 *data;
2452 2453
	struct netdev_queue *txq = netdev_get_tx_queue(bp->dev,
						       txdata->txq_index);
2454 2455 2456 2457

	/* check the loopback mode */
	switch (loopback_mode) {
	case BNX2X_PHY_LOOPBACK:
2458 2459
		if (bp->link_params.loopback_mode != LOOPBACK_XGXS) {
			DP(BNX2X_MSG_ETHTOOL, "PHY loopback not supported\n");
2460
			return -EINVAL;
2461
		}
2462 2463
		break;
	case BNX2X_MAC_LOOPBACK:
Y
Yaniv Rosner 已提交
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
		if (CHIP_IS_E3(bp)) {
			int cfg_idx = bnx2x_get_link_cfg_idx(bp);
			if (bp->port.supported[cfg_idx] &
			    (SUPPORTED_10000baseT_Full |
			     SUPPORTED_20000baseMLD2_Full |
			     SUPPORTED_20000baseKR2_Full))
				bp->link_params.loopback_mode = LOOPBACK_XMAC;
			else
				bp->link_params.loopback_mode = LOOPBACK_UMAC;
		} else
			bp->link_params.loopback_mode = LOOPBACK_BMAC;

2476 2477
		bnx2x_phy_init(&bp->link_params, &bp->link_vars);
		break;
2478 2479 2480 2481 2482 2483 2484
	case BNX2X_EXT_LOOPBACK:
		if (bp->link_params.loopback_mode != LOOPBACK_EXT) {
			DP(BNX2X_MSG_ETHTOOL,
			   "Can't configure external loopback\n");
			return -EINVAL;
		}
		break;
2485
	default:
M
Merav Sicron 已提交
2486
		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
2487 2488 2489 2490 2491 2492
		return -EINVAL;
	}

	/* prepare the loopback packet */
	pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
		     bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
2493
	skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
2494
	if (!skb) {
M
Merav Sicron 已提交
2495
		DP(BNX2X_MSG_ETHTOOL, "Can't allocate skb\n");
2496 2497 2498 2499 2500
		rc = -ENOMEM;
		goto test_loopback_exit;
	}
	packet = skb_put(skb, pkt_size);
	memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
2501
	eth_zero_addr(packet + ETH_ALEN);
2502 2503 2504
	memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
	for (i = ETH_HLEN; i < pkt_size; i++)
		packet[i] = (unsigned char) (i & 0xff);
2505 2506 2507 2508 2509
	mapping = dma_map_single(&bp->pdev->dev, skb->data,
				 skb_headlen(skb), DMA_TO_DEVICE);
	if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
		rc = -ENOMEM;
		dev_kfree_skb(skb);
M
Merav Sicron 已提交
2510
		DP(BNX2X_MSG_ETHTOOL, "Unable to map SKB\n");
2511 2512
		goto test_loopback_exit;
	}
2513 2514 2515

	/* send the loopback packet */
	num_pkts = 0;
2516
	tx_start_idx = le16_to_cpu(*txdata->tx_cons_sb);
2517 2518
	rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);

D
Dmitry Kravkov 已提交
2519 2520
	netdev_tx_sent_queue(txq, skb->len);

2521 2522 2523
	pkt_prod = txdata->tx_pkt_prod++;
	tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
	tx_buf->first_bd = txdata->tx_bd_prod;
2524 2525 2526
	tx_buf->skb = skb;
	tx_buf->flags = 0;

2527 2528
	bd_prod = TX_BD(txdata->tx_bd_prod);
	tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
2529 2530 2531 2532
	tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
	tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
	tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
	tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
2533
	tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
2534
	tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
2535 2536 2537
	SET_FLAG(tx_start_bd->general_data,
		 ETH_TX_START_BD_HDR_NBDS,
		 1);
Y
Yuval Mintz 已提交
2538 2539 2540
	SET_FLAG(tx_start_bd->general_data,
		 ETH_TX_START_BD_PARSE_NBDS,
		 0);
2541 2542 2543

	/* turn on parsing and get a BD */
	bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
D
Dmitry Kravkov 已提交
2544

Y
Yuval Mintz 已提交
2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561
	if (CHIP_IS_E1x(bp)) {
		u16 global_data = 0;
		struct eth_tx_parse_bd_e1x  *pbd_e1x =
			&txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
		memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
		SET_FLAG(global_data,
			 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, UNICAST_ADDRESS);
		pbd_e1x->global_data = cpu_to_le16(global_data);
	} else {
		u32 parsing_data = 0;
		struct eth_tx_parse_bd_e2  *pbd_e2 =
			&txdata->tx_desc_ring[bd_prod].parse_bd_e2;
		memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
		SET_FLAG(parsing_data,
			 ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE, UNICAST_ADDRESS);
		pbd_e2->parsing_data = cpu_to_le32(parsing_data);
	}
2562 2563
	wmb();

2564
	txdata->tx_db.data.prod += 2;
2565
	barrier();
2566
	DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
2567 2568

	mmiowb();
2569
	barrier();
2570 2571

	num_pkts++;
2572
	txdata->tx_bd_prod += 2; /* start + pbd */
2573 2574 2575

	udelay(100);

2576
	tx_idx = le16_to_cpu(*txdata->tx_cons_sb);
2577 2578 2579
	if (tx_idx != tx_start_idx + num_pkts)
		goto test_loopback_exit;

D
Dmitry Kravkov 已提交
2580 2581 2582 2583
	/* Unlike HC IGU won't generate an interrupt for status block
	 * updates that have been performed while interrupts were
	 * disabled.
	 */
2584 2585 2586 2587 2588 2589
	if (bp->common.int_block == INT_BLOCK_IGU) {
		/* Disable local BHes to prevent a dead-lock situation between
		 * sch_direct_xmit() and bnx2x_run_loopback() (calling
		 * bnx2x_tx_int()), as both are taking netif_tx_lock().
		 */
		local_bh_disable();
2590
		bnx2x_tx_int(bp, txdata);
2591 2592
		local_bh_enable();
	}
D
Dmitry Kravkov 已提交
2593

2594 2595 2596 2597
	rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
	if (rx_idx != rx_start_idx + num_pkts)
		goto test_loopback_exit;

2598
	cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
2599
	cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
2600 2601
	cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
	if (!CQE_TYPE_FAST(cqe_fp_type) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
2602 2603
		goto test_loopback_rx_exit;

D
Dmitry Kravkov 已提交
2604
	len = le16_to_cpu(cqe->fast_path_cqe.pkt_len_or_gro_seg_len);
2605 2606 2607 2608
	if (len != pkt_size)
		goto test_loopback_rx_exit;

	rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
2609
	dma_sync_single_for_cpu(&bp->pdev->dev,
2610 2611
				   dma_unmap_addr(rx_buf, mapping),
				   fp_rx->rx_buf_size, DMA_FROM_DEVICE);
2612
	data = rx_buf->data + NET_SKB_PAD + cqe->fast_path_cqe.placement_offset;
2613
	for (i = ETH_HLEN; i < pkt_size; i++)
2614
		if (*(data + i) != (unsigned char) (i & 0xff))
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635
			goto test_loopback_rx_exit;

	rc = 0;

test_loopback_rx_exit:

	fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
	fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
	fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
	fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);

	/* Update producers */
	bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
			     fp_rx->rx_sge_prod);

test_loopback_exit:
	bp->link_params.loopback_mode = LOOPBACK_NONE;

	return rc;
}

2636
static int bnx2x_test_loopback(struct bnx2x *bp)
2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648
{
	int rc = 0, res;

	if (BP_NOMCP(bp))
		return rc;

	if (!netif_running(bp->dev))
		return BNX2X_LOOPBACK_FAILED;

	bnx2x_netif_stop(bp, 1);
	bnx2x_acquire_phy_lock(bp);

2649
	res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK);
2650
	if (res) {
M
Merav Sicron 已提交
2651
		DP(BNX2X_MSG_ETHTOOL, "  PHY loopback failed  (res %d)\n", res);
2652 2653 2654
		rc |= BNX2X_PHY_LOOPBACK_FAILED;
	}

2655
	res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK);
2656
	if (res) {
M
Merav Sicron 已提交
2657
		DP(BNX2X_MSG_ETHTOOL, "  MAC loopback failed  (res %d)\n", res);
2658 2659 2660 2661 2662 2663 2664 2665 2666
		rc |= BNX2X_MAC_LOOPBACK_FAILED;
	}

	bnx2x_release_phy_lock(bp);
	bnx2x_netif_start(bp);

	return rc;
}

2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678
static int bnx2x_test_ext_loopback(struct bnx2x *bp)
{
	int rc;
	u8 is_serdes =
		(bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;

	if (BP_NOMCP(bp))
		return -ENODEV;

	if (!netif_running(bp->dev))
		return BNX2X_EXT_LOOPBACK_FAILED;

Y
Yuval Mintz 已提交
2679
	bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698
	rc = bnx2x_nic_load(bp, LOAD_LOOPBACK_EXT);
	if (rc) {
		DP(BNX2X_MSG_ETHTOOL,
		   "Can't perform self-test, nic_load (for external lb) failed\n");
		return -ENODEV;
	}
	bnx2x_wait_for_link(bp, 1, is_serdes);

	bnx2x_netif_stop(bp, 1);

	rc = bnx2x_run_loopback(bp, BNX2X_EXT_LOOPBACK);
	if (rc)
		DP(BNX2X_MSG_ETHTOOL, "EXT loopback failed  (res %d)\n", rc);

	bnx2x_netif_start(bp);

	return rc;
}

2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
struct code_entry {
	u32 sram_start_addr;
	u32 code_attribute;
#define CODE_IMAGE_TYPE_MASK			0xf0800003
#define CODE_IMAGE_VNTAG_PROFILES_DATA		0xd0000003
#define CODE_IMAGE_LENGTH_MASK			0x007ffffc
#define CODE_IMAGE_TYPE_EXTENDED_DIR		0xe0000000
	u32 nvm_start_addr;
};

#define CODE_ENTRY_MAX			16
#define CODE_ENTRY_EXTENDED_DIR_IDX	15
#define MAX_IMAGES_IN_EXTENDED_DIR	64
#define NVRAM_DIR_OFFSET		0x14

#define EXTENDED_DIR_EXISTS(code)					  \
	((code & CODE_IMAGE_TYPE_MASK) == CODE_IMAGE_TYPE_EXTENDED_DIR && \
	 (code & CODE_IMAGE_LENGTH_MASK) != 0)

2718
#define CRC32_RESIDUAL			0xdebb20e3
2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856
#define CRC_BUFF_SIZE			256

static int bnx2x_nvram_crc(struct bnx2x *bp,
			   int offset,
			   int size,
			   u8 *buff)
{
	u32 crc = ~0;
	int rc = 0, done = 0;

	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
	   "NVRAM CRC from 0x%08x to 0x%08x\n", offset, offset + size);

	while (done < size) {
		int count = min_t(int, size - done, CRC_BUFF_SIZE);

		rc = bnx2x_nvram_read(bp, offset + done, buff, count);

		if (rc)
			return rc;

		crc = crc32_le(crc, buff, count);
		done += count;
	}

	if (crc != CRC32_RESIDUAL)
		rc = -EINVAL;

	return rc;
}

static int bnx2x_test_nvram_dir(struct bnx2x *bp,
				struct code_entry *entry,
				u8 *buff)
{
	size_t size = entry->code_attribute & CODE_IMAGE_LENGTH_MASK;
	u32 type = entry->code_attribute & CODE_IMAGE_TYPE_MASK;
	int rc;

	/* Zero-length images and AFEX profiles do not have CRC */
	if (size == 0 || type == CODE_IMAGE_VNTAG_PROFILES_DATA)
		return 0;

	rc = bnx2x_nvram_crc(bp, entry->nvm_start_addr, size, buff);
	if (rc)
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "image %x has failed crc test (rc %d)\n", type, rc);

	return rc;
}

static int bnx2x_test_dir_entry(struct bnx2x *bp, u32 addr, u8 *buff)
{
	int rc;
	struct code_entry entry;

	rc = bnx2x_nvram_read32(bp, addr, (u32 *)&entry, sizeof(entry));
	if (rc)
		return rc;

	return bnx2x_test_nvram_dir(bp, &entry, buff);
}

static int bnx2x_test_nvram_ext_dirs(struct bnx2x *bp, u8 *buff)
{
	u32 rc, cnt, dir_offset = NVRAM_DIR_OFFSET;
	struct code_entry entry;
	int i;

	rc = bnx2x_nvram_read32(bp,
				dir_offset +
				sizeof(entry) * CODE_ENTRY_EXTENDED_DIR_IDX,
				(u32 *)&entry, sizeof(entry));
	if (rc)
		return rc;

	if (!EXTENDED_DIR_EXISTS(entry.code_attribute))
		return 0;

	rc = bnx2x_nvram_read32(bp, entry.nvm_start_addr,
				&cnt, sizeof(u32));
	if (rc)
		return rc;

	dir_offset = entry.nvm_start_addr + 8;

	for (i = 0; i < cnt && i < MAX_IMAGES_IN_EXTENDED_DIR; i++) {
		rc = bnx2x_test_dir_entry(bp, dir_offset +
					      sizeof(struct code_entry) * i,
					  buff);
		if (rc)
			return rc;
	}

	return 0;
}

static int bnx2x_test_nvram_dirs(struct bnx2x *bp, u8 *buff)
{
	u32 rc, dir_offset = NVRAM_DIR_OFFSET;
	int i;

	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "NVRAM DIRS CRC test-set\n");

	for (i = 0; i < CODE_ENTRY_EXTENDED_DIR_IDX; i++) {
		rc = bnx2x_test_dir_entry(bp, dir_offset +
					      sizeof(struct code_entry) * i,
					  buff);
		if (rc)
			return rc;
	}

	return bnx2x_test_nvram_ext_dirs(bp, buff);
}

struct crc_pair {
	int offset;
	int size;
};

static int bnx2x_test_nvram_tbl(struct bnx2x *bp,
				const struct crc_pair *nvram_tbl, u8 *buf)
{
	int i;

	for (i = 0; nvram_tbl[i].size; i++) {
		int rc = bnx2x_nvram_crc(bp, nvram_tbl[i].offset,
					 nvram_tbl[i].size, buf);
		if (rc) {
			DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
			   "nvram_tbl[%d] has failed crc test (rc %d)\n",
			   i, rc);
			return rc;
		}
	}

	return 0;
}
2857 2858 2859

static int bnx2x_test_nvram(struct bnx2x *bp)
{
2860
	const struct crc_pair nvram_tbl[] = {
2861 2862 2863 2864 2865 2866 2867 2868
		{     0,  0x14 }, /* bootstrap */
		{  0x14,  0xec }, /* dir */
		{ 0x100, 0x350 }, /* manuf_info */
		{ 0x450,  0xf0 }, /* feature_info */
		{ 0x640,  0x64 }, /* upgrade_key_info */
		{ 0x708,  0x70 }, /* manuf_key_info */
		{     0,     0 }
	};
2869 2870 2871 2872 2873 2874
	const struct crc_pair nvram_tbl2[] = {
		{ 0x7e8, 0x350 }, /* manuf_info2 */
		{ 0xb38,  0xf0 }, /* feature_info */
		{     0,     0 }
	};

2875
	u8 *buf;
2876 2877
	int rc;
	u32 magic;
2878 2879 2880 2881

	if (BP_NOMCP(bp))
		return 0;

2882
	buf = kmalloc(CRC_BUFF_SIZE, GFP_KERNEL);
2883
	if (!buf) {
M
Merav Sicron 已提交
2884
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "kmalloc failed\n");
2885 2886 2887 2888
		rc = -ENOMEM;
		goto test_nvram_exit;
	}

2889
	rc = bnx2x_nvram_read32(bp, 0, &magic, sizeof(magic));
2890
	if (rc) {
M
Merav Sicron 已提交
2891 2892
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "magic value read (rc %d)\n", rc);
2893 2894 2895 2896
		goto test_nvram_exit;
	}

	if (magic != 0x669955aa) {
M
Merav Sicron 已提交
2897 2898
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "wrong magic value (0x%08x)\n", magic);
2899 2900 2901 2902
		rc = -ENODEV;
		goto test_nvram_exit;
	}

2903 2904 2905 2906
	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "Port 0 CRC test-set\n");
	rc = bnx2x_test_nvram_tbl(bp, nvram_tbl, buf);
	if (rc)
		goto test_nvram_exit;
2907

2908 2909 2910
	if (!CHIP_IS_E1x(bp) && !CHIP_IS_57811xx(bp)) {
		u32 hide = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
			   SHARED_HW_CFG_HIDE_PORT1;
2911

2912
		if (!hide) {
M
Merav Sicron 已提交
2913
			DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2914 2915 2916 2917
			   "Port 1 CRC test-set\n");
			rc = bnx2x_test_nvram_tbl(bp, nvram_tbl2, buf);
			if (rc)
				goto test_nvram_exit;
2918 2919 2920
		}
	}

2921 2922
	rc = bnx2x_test_nvram_dirs(bp, buf);

2923
test_nvram_exit:
2924
	kfree(buf);
2925 2926 2927
	return rc;
}

2928
/* Send an EMPTY ramrod on the first queue */
2929 2930
static int bnx2x_test_intr(struct bnx2x *bp)
{
Y
Yuval Mintz 已提交
2931
	struct bnx2x_queue_state_params params = {NULL};
2932

M
Merav Sicron 已提交
2933 2934 2935
	if (!netif_running(bp->dev)) {
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
2936
		return -ENODEV;
M
Merav Sicron 已提交
2937
	}
2938

B
Barak Witkowski 已提交
2939
	params.q_obj = &bp->sp_objs->q_obj;
2940
	params.cmd = BNX2X_Q_CMD_EMPTY;
2941

2942 2943 2944
	__set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);

	return bnx2x_queue_state_change(bp, &params);
2945 2946 2947 2948 2949 2950
}

static void bnx2x_self_test(struct net_device *dev,
			    struct ethtool_test *etest, u64 *buf)
{
	struct bnx2x *bp = netdev_priv(dev);
2951 2952
	u8 is_serdes, link_up;
	int rc, cnt = 0;
2953

2954 2955 2956 2957 2958 2959
	if (pci_num_vf(bp->pdev)) {
		DP(BNX2X_MSG_IOV,
		   "VFs are enabled, can not perform self test\n");
		return;
	}

2960
	if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
M
Merav Sicron 已提交
2961 2962
		netdev_err(bp->dev,
			   "Handling parity error recovery. Try again later\n");
2963 2964 2965
		etest->flags |= ETH_TEST_FL_FAILED;
		return;
	}
Y
Yuval Mintz 已提交
2966

2967 2968 2969 2970
	DP(BNX2X_MSG_ETHTOOL,
	   "Self-test command parameters: offline = %d, external_lb = %d\n",
	   (etest->flags & ETH_TEST_FL_OFFLINE),
	   (etest->flags & ETH_TEST_FL_EXTERNAL_LB)>>2);
2971

2972
	memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS(bp));
2973

2974 2975 2976 2977 2978 2979 2980 2981
	if (bnx2x_test_nvram(bp) != 0) {
		if (!IS_MF(bp))
			buf[4] = 1;
		else
			buf[0] = 1;
		etest->flags |= ETH_TEST_FL_FAILED;
	}

2982
	if (!netif_running(dev)) {
2983
		DP(BNX2X_MSG_ETHTOOL, "Interface is down\n");
2984
		return;
2985
	}
2986

Y
Yaniv Rosner 已提交
2987
	is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
2988
	link_up = bp->link_vars.link_up;
2989 2990
	/* offline tests are not supported in MF mode */
	if ((etest->flags & ETH_TEST_FL_OFFLINE) && !IS_MF(bp)) {
2991 2992 2993 2994 2995 2996 2997 2998
		int port = BP_PORT(bp);
		u32 val;

		/* save current value of input enable for TX port IF */
		val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
		/* disable input for TX port IF */
		REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);

Y
Yuval Mintz 已提交
2999
		bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
3000 3001 3002 3003 3004 3005 3006 3007
		rc = bnx2x_nic_load(bp, LOAD_DIAG);
		if (rc) {
			etest->flags |= ETH_TEST_FL_FAILED;
			DP(BNX2X_MSG_ETHTOOL,
			   "Can't perform self-test, nic_load (for offline) failed\n");
			return;
		}

3008
		/* wait until link state is restored */
3009
		bnx2x_wait_for_link(bp, 1, is_serdes);
3010 3011 3012 3013 3014 3015 3016 3017 3018

		if (bnx2x_test_registers(bp) != 0) {
			buf[0] = 1;
			etest->flags |= ETH_TEST_FL_FAILED;
		}
		if (bnx2x_test_memory(bp) != 0) {
			buf[1] = 1;
			etest->flags |= ETH_TEST_FL_FAILED;
		}
D
Dmitry Kravkov 已提交
3019

3020
		buf[2] = bnx2x_test_loopback(bp); /* internal LB */
3021 3022 3023
		if (buf[2] != 0)
			etest->flags |= ETH_TEST_FL_FAILED;

3024 3025 3026 3027 3028 3029 3030
		if (etest->flags & ETH_TEST_FL_EXTERNAL_LB) {
			buf[3] = bnx2x_test_ext_loopback(bp); /* external LB */
			if (buf[3] != 0)
				etest->flags |= ETH_TEST_FL_FAILED;
			etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
		}

Y
Yuval Mintz 已提交
3031
		bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
3032 3033 3034

		/* restore input for TX port IF */
		REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
3035 3036 3037 3038 3039 3040 3041
		rc = bnx2x_nic_load(bp, LOAD_NORMAL);
		if (rc) {
			etest->flags |= ETH_TEST_FL_FAILED;
			DP(BNX2X_MSG_ETHTOOL,
			   "Can't perform self-test, nic_load (for online) failed\n");
			return;
		}
3042
		/* wait until link state is restored */
Y
Yaniv Rosner 已提交
3043
		bnx2x_wait_for_link(bp, link_up, is_serdes);
3044
	}
3045

3046
	if (bnx2x_test_intr(bp) != 0) {
3047 3048 3049 3050
		if (!IS_MF(bp))
			buf[5] = 1;
		else
			buf[1] = 1;
3051 3052
		etest->flags |= ETH_TEST_FL_FAILED;
	}
3053

3054 3055 3056 3057 3058 3059 3060
	if (link_up) {
		cnt = 100;
		while (bnx2x_link_test(bp, is_serdes) && --cnt)
			msleep(20);
	}

	if (!cnt) {
3061 3062 3063 3064
		if (!IS_MF(bp))
			buf[6] = 1;
		else
			buf[2] = 1;
3065 3066
		etest->flags |= ETH_TEST_FL_FAILED;
	}
3067 3068 3069 3070 3071
}

#define IS_PORT_STAT(i) \
	((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
#define IS_FUNC_STAT(i)		(bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
3072
#define HIDE_PORT_STAT(bp)	IS_VF(bp)
3073

3074 3075 3076
/* ethtool statistics are displayed for all regular ethernet queues and the
 * fcoe L2 queue if not disabled
 */
E
Eric Dumazet 已提交
3077
static int bnx2x_num_stat_queues(struct bnx2x *bp)
3078 3079 3080 3081
{
	return BNX2X_NUM_ETH_QUEUES(bp);
}

3082 3083 3084
static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
{
	struct bnx2x *bp = netdev_priv(dev);
Y
Yuval Mintz 已提交
3085
	int i, num_strings = 0;
3086 3087 3088 3089

	switch (stringset) {
	case ETH_SS_STATS:
		if (is_multi(bp)) {
Y
Yuval Mintz 已提交
3090 3091
			num_strings = bnx2x_num_stat_queues(bp) *
				      BNX2X_NUM_Q_STATS;
3092
		} else
Y
Yuval Mintz 已提交
3093
			num_strings = 0;
3094
		if (HIDE_PORT_STAT(bp)) {
3095 3096
			for (i = 0; i < BNX2X_NUM_STATS; i++)
				if (IS_FUNC_STAT(i))
Y
Yuval Mintz 已提交
3097
					num_strings++;
3098
		} else
Y
Yuval Mintz 已提交
3099
			num_strings += BNX2X_NUM_STATS;
3100

Y
Yuval Mintz 已提交
3101
		return num_strings;
3102 3103

	case ETH_SS_TEST:
3104
		return BNX2X_NUM_TESTS(bp);
3105

Y
Yuval Mintz 已提交
3106 3107 3108
	case ETH_SS_PRIV_FLAGS:
		return BNX2X_PRI_FLAG_LEN;

3109 3110 3111 3112 3113
	default:
		return -EINVAL;
	}
}

Y
Yuval Mintz 已提交
3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125
static u32 bnx2x_get_private_flags(struct net_device *dev)
{
	struct bnx2x *bp = netdev_priv(dev);
	u32 flags = 0;

	flags |= (!(bp->flags & NO_ISCSI_FLAG) ? 1 : 0) << BNX2X_PRI_FLAG_ISCSI;
	flags |= (!(bp->flags & NO_FCOE_FLAG)  ? 1 : 0) << BNX2X_PRI_FLAG_FCOE;
	flags |= (!!IS_MF_STORAGE_ONLY(bp)) << BNX2X_PRI_FLAG_STORAGE;

	return flags;
}

3126 3127 3128
static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
{
	struct bnx2x *bp = netdev_priv(dev);
3129
	int i, j, k, start;
V
Vladislav Zolotarov 已提交
3130
	char queue_name[MAX_QUEUE_NAME_LEN+1];
3131 3132 3133

	switch (stringset) {
	case ETH_SS_STATS:
3134
		k = 0;
3135
		if (is_multi(bp)) {
3136
			for_each_eth_queue(bp, i) {
V
Vladislav Zolotarov 已提交
3137
				memset(queue_name, 0, sizeof(queue_name));
3138
				sprintf(queue_name, "%d", i);
3139
				for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
V
Vladislav Zolotarov 已提交
3140 3141 3142 3143
					snprintf(buf + (k + j)*ETH_GSTRING_LEN,
						ETH_GSTRING_LEN,
						bnx2x_q_stats_arr[j].string,
						queue_name);
3144 3145 3146
				k += BNX2X_NUM_Q_STATS;
			}
		}
3147 3148

		for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
3149
			if (HIDE_PORT_STAT(bp) && IS_PORT_STAT(i))
3150 3151 3152 3153 3154 3155
				continue;
			strcpy(buf + (k + j)*ETH_GSTRING_LEN,
				   bnx2x_stats_arr[i].string);
			j++;
		}

3156 3157 3158
		break;

	case ETH_SS_TEST:
3159 3160 3161 3162 3163
		/* First 4 tests cannot be done in MF mode */
		if (!IS_MF(bp))
			start = 0;
		else
			start = 4;
3164 3165
		memcpy(buf, bnx2x_tests_str_arr + start,
		       ETH_GSTRING_LEN * BNX2X_NUM_TESTS(bp));
Y
Yuval Mintz 已提交
3166 3167 3168 3169 3170 3171
		break;

	case ETH_SS_PRIV_FLAGS:
		memcpy(buf, bnx2x_private_arr,
		       ETH_GSTRING_LEN * BNX2X_PRI_FLAG_LEN);
		break;
3172 3173 3174 3175 3176 3177 3178 3179
	}
}

static void bnx2x_get_ethtool_stats(struct net_device *dev,
				    struct ethtool_stats *stats, u64 *buf)
{
	struct bnx2x *bp = netdev_priv(dev);
	u32 *hw_stats, *offset;
3180
	int i, j, k = 0;
3181 3182

	if (is_multi(bp)) {
3183
		for_each_eth_queue(bp, i) {
B
Barak Witkowski 已提交
3184
			hw_stats = (u32 *)&bp->fp_stats[i].eth_q_stats;
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202
			for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
				if (bnx2x_q_stats_arr[j].size == 0) {
					/* skip this counter */
					buf[k + j] = 0;
					continue;
				}
				offset = (hw_stats +
					  bnx2x_q_stats_arr[j].offset);
				if (bnx2x_q_stats_arr[j].size == 4) {
					/* 4-byte counter */
					buf[k + j] = (u64) *offset;
					continue;
				}
				/* 8-byte counter */
				buf[k + j] = HILO_U64(*offset, *(offset + 1));
			}
			k += BNX2X_NUM_Q_STATS;
		}
3203 3204 3205 3206
	}

	hw_stats = (u32 *)&bp->eth_stats;
	for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
3207
		if (HIDE_PORT_STAT(bp) && IS_PORT_STAT(i))
3208 3209 3210 3211 3212 3213
			continue;
		if (bnx2x_stats_arr[i].size == 0) {
			/* skip this counter */
			buf[k + j] = 0;
			j++;
			continue;
3214
		}
3215 3216 3217 3218
		offset = (hw_stats + bnx2x_stats_arr[i].offset);
		if (bnx2x_stats_arr[i].size == 4) {
			/* 4-byte counter */
			buf[k + j] = (u64) *offset;
3219
			j++;
3220
			continue;
3221
		}
3222 3223 3224
		/* 8-byte counter */
		buf[k + j] = HILO_U64(*offset, *(offset + 1));
		j++;
3225 3226 3227
	}
}

3228 3229
static int bnx2x_set_phys_id(struct net_device *dev,
			     enum ethtool_phys_id_state state)
3230 3231 3232
{
	struct bnx2x *bp = netdev_priv(dev);

3233
	if (!bnx2x_is_nvm_accessible(bp)) {
M
Merav Sicron 已提交
3234 3235
		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
		   "cannot access eeprom when the interface is down\n");
3236
		return -EAGAIN;
M
Merav Sicron 已提交
3237
	}
3238

3239 3240
	switch (state) {
	case ETHTOOL_ID_ACTIVE:
3241
		return 1;	/* cycle on/off once per second */
3242

3243
	case ETHTOOL_ID_ON:
Y
Yaniv Rosner 已提交
3244
		bnx2x_acquire_phy_lock(bp);
3245
		bnx2x_set_led(&bp->link_params, &bp->link_vars,
3246
			      LED_MODE_ON, SPEED_1000);
Y
Yaniv Rosner 已提交
3247
		bnx2x_release_phy_lock(bp);
3248
		break;
3249

3250
	case ETHTOOL_ID_OFF:
Y
Yaniv Rosner 已提交
3251
		bnx2x_acquire_phy_lock(bp);
3252
		bnx2x_set_led(&bp->link_params, &bp->link_vars,
3253
			      LED_MODE_FRONT_PANEL_OFF, 0);
Y
Yaniv Rosner 已提交
3254
		bnx2x_release_phy_lock(bp);
3255 3256 3257
		break;

	case ETHTOOL_ID_INACTIVE:
Y
Yaniv Rosner 已提交
3258
		bnx2x_acquire_phy_lock(bp);
3259 3260 3261
		bnx2x_set_led(&bp->link_params, &bp->link_vars,
			      LED_MODE_OPER,
			      bp->link_vars.line_speed);
Y
Yaniv Rosner 已提交
3262
		bnx2x_release_phy_lock(bp);
3263
	}
3264 3265 3266 3267

	return 0;
}

3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301
static int bnx2x_get_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
{
	switch (info->flow_type) {
	case TCP_V4_FLOW:
	case TCP_V6_FLOW:
		info->data = RXH_IP_SRC | RXH_IP_DST |
			     RXH_L4_B_0_1 | RXH_L4_B_2_3;
		break;
	case UDP_V4_FLOW:
		if (bp->rss_conf_obj.udp_rss_v4)
			info->data = RXH_IP_SRC | RXH_IP_DST |
				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
		else
			info->data = RXH_IP_SRC | RXH_IP_DST;
		break;
	case UDP_V6_FLOW:
		if (bp->rss_conf_obj.udp_rss_v6)
			info->data = RXH_IP_SRC | RXH_IP_DST |
				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
		else
			info->data = RXH_IP_SRC | RXH_IP_DST;
		break;
	case IPV4_FLOW:
	case IPV6_FLOW:
		info->data = RXH_IP_SRC | RXH_IP_DST;
		break;
	default:
		info->data = 0;
		break;
	}

	return 0;
}

3302
static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
3303
			   u32 *rules __always_unused)
3304 3305 3306 3307 3308 3309 3310
{
	struct bnx2x *bp = netdev_priv(dev);

	switch (info->cmd) {
	case ETHTOOL_GRXRINGS:
		info->data = BNX2X_NUM_ETH_QUEUES(bp);
		return 0;
3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336
	case ETHTOOL_GRXFH:
		return bnx2x_get_rss_flags(bp, info);
	default:
		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
		return -EOPNOTSUPP;
	}
}

static int bnx2x_set_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
{
	int udp_rss_requested;

	DP(BNX2X_MSG_ETHTOOL,
	   "Set rss flags command parameters: flow type = %d, data = %llu\n",
	   info->flow_type, info->data);

	switch (info->flow_type) {
	case TCP_V4_FLOW:
	case TCP_V6_FLOW:
		/* For TCP only 4-tupple hash is supported */
		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
				  RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
			DP(BNX2X_MSG_ETHTOOL,
			   "Command parameters not supported\n");
			return -EINVAL;
		}
Y
Yuval Mintz 已提交
3337
		return 0;
3338 3339 3340 3341 3342

	case UDP_V4_FLOW:
	case UDP_V6_FLOW:
		/* For UDP either 2-tupple hash or 4-tupple hash is supported */
		if (info->data == (RXH_IP_SRC | RXH_IP_DST |
Y
Yuval Mintz 已提交
3343
				   RXH_L4_B_0_1 | RXH_L4_B_2_3))
3344 3345 3346 3347 3348
			udp_rss_requested = 1;
		else if (info->data == (RXH_IP_SRC | RXH_IP_DST))
			udp_rss_requested = 0;
		else
			return -EINVAL;
3349 3350 3351 3352 3353 3354 3355

		if (CHIP_IS_E1x(bp) && udp_rss_requested) {
			DP(BNX2X_MSG_ETHTOOL,
			   "57710, 57711 boards don't support RSS according to UDP 4-tuple\n");
			return -EINVAL;
		}

3356 3357 3358 3359 3360 3361
		if ((info->flow_type == UDP_V4_FLOW) &&
		    (bp->rss_conf_obj.udp_rss_v4 != udp_rss_requested)) {
			bp->rss_conf_obj.udp_rss_v4 = udp_rss_requested;
			DP(BNX2X_MSG_ETHTOOL,
			   "rss re-configured, UDP 4-tupple %s\n",
			   udp_rss_requested ? "enabled" : "disabled");
A
Ariel Elior 已提交
3362
			return bnx2x_rss(bp, &bp->rss_conf_obj, false, true);
3363 3364 3365 3366 3367 3368
		} else if ((info->flow_type == UDP_V6_FLOW) &&
			   (bp->rss_conf_obj.udp_rss_v6 != udp_rss_requested)) {
			bp->rss_conf_obj.udp_rss_v6 = udp_rss_requested;
			DP(BNX2X_MSG_ETHTOOL,
			   "rss re-configured, UDP 4-tupple %s\n",
			   udp_rss_requested ? "enabled" : "disabled");
A
Ariel Elior 已提交
3369
			return bnx2x_rss(bp, &bp->rss_conf_obj, false, true);
3370
		}
3371 3372
		return 0;

3373 3374 3375 3376 3377 3378 3379 3380
	case IPV4_FLOW:
	case IPV6_FLOW:
		/* For IP only 2-tupple hash is supported */
		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
			DP(BNX2X_MSG_ETHTOOL,
			   "Command parameters not supported\n");
			return -EINVAL;
		}
3381 3382
		return 0;

3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
	case SCTP_V4_FLOW:
	case AH_ESP_V4_FLOW:
	case AH_V4_FLOW:
	case ESP_V4_FLOW:
	case SCTP_V6_FLOW:
	case AH_ESP_V6_FLOW:
	case AH_V6_FLOW:
	case ESP_V6_FLOW:
	case IP_USER_FLOW:
	case ETHER_FLOW:
		/* RSS is not supported for these protocols */
		if (info->data) {
			DP(BNX2X_MSG_ETHTOOL,
			   "Command parameters not supported\n");
			return -EINVAL;
		}
3399 3400
		return 0;

3401 3402 3403 3404 3405 3406 3407 3408
	default:
		return -EINVAL;
	}
}

static int bnx2x_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
{
	struct bnx2x *bp = netdev_priv(dev);
3409

3410 3411 3412
	switch (info->cmd) {
	case ETHTOOL_SRXFH:
		return bnx2x_set_rss_flags(bp, info);
3413
	default:
M
Merav Sicron 已提交
3414
		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
3415 3416 3417 3418
		return -EOPNOTSUPP;
	}
}

3419 3420
static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
{
D
Dmitry Kravkov 已提交
3421
	return T_ETH_INDIRECTION_TABLE_SIZE;
3422 3423
}

3424 3425
static int bnx2x_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
			  u8 *hfunc)
3426 3427
{
	struct bnx2x *bp = netdev_priv(dev);
3428 3429
	u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
	size_t i;
3430

3431 3432 3433 3434 3435
	if (hfunc)
		*hfunc = ETH_RSS_HASH_TOP;
	if (!indir)
		return 0;

3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447
	/* Get the current configuration of the RSS indirection table */
	bnx2x_get_rss_ind_table(&bp->rss_conf_obj, ind_table);

	/*
	 * We can't use a memcpy() as an internal storage of an
	 * indirection table is a u8 array while indir->ring_index
	 * points to an array of u32.
	 *
	 * Indirection table contains the FW Client IDs, so we need to
	 * align the returned table to the Client ID of the leading RSS
	 * queue.
	 */
3448 3449
	for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
		indir[i] = ind_table[i] - bp->fp->cl_id;
3450

3451 3452 3453
	return 0;
}

3454
static int bnx2x_set_rxfh(struct net_device *dev, const u32 *indir,
3455
			  const u8 *key, const u8 hfunc)
3456 3457 3458
{
	struct bnx2x *bp = netdev_priv(dev);
	size_t i;
3459

3460 3461 3462 3463 3464 3465 3466 3467 3468 3469
	/* We require at least one supported parameter to be changed and no
	 * change in any of the unsupported parameters
	 */
	if (key ||
	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
		return -EOPNOTSUPP;

	if (!indir)
		return 0;

3470 3471
	for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
		/*
3472
		 * The same as in bnx2x_get_rxfh: we can't use a memcpy()
3473 3474 3475 3476 3477 3478 3479
		 * as an internal storage of an indirection table is a u8 array
		 * while indir->ring_index points to an array of u32.
		 *
		 * Indirection table contains the FW Client IDs, so we need to
		 * align the received table to the Client ID of the leading RSS
		 * queue
		 */
3480
		bp->rss_conf_obj.ind_table[i] = indir[i] + bp->fp->cl_id;
3481
	}
3482

3483
	return bnx2x_config_rss_eth(bp, false);
3484 3485
}

M
Merav Sicron 已提交
3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511
/**
 * bnx2x_get_channels - gets the number of RSS queues.
 *
 * @dev:		net device
 * @channels:		returns the number of max / current queues
 */
static void bnx2x_get_channels(struct net_device *dev,
			       struct ethtool_channels *channels)
{
	struct bnx2x *bp = netdev_priv(dev);

	channels->max_combined = BNX2X_MAX_RSS_COUNT(bp);
	channels->combined_count = BNX2X_NUM_ETH_QUEUES(bp);
}

/**
 * bnx2x_change_num_queues - change the number of RSS queues.
 *
 * @bp:			bnx2x private structure
 *
 * Re-configure interrupt mode to get the new number of MSI-X
 * vectors and re-add NAPI objects.
 */
static void bnx2x_change_num_queues(struct bnx2x *bp, int num_rss)
{
	bnx2x_disable_msi(bp);
3512 3513 3514
	bp->num_ethernet_queues = num_rss;
	bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
	BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
M
Merav Sicron 已提交
3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533
	bnx2x_set_int_mode(bp);
}

/**
 * bnx2x_set_channels - sets the number of RSS queues.
 *
 * @dev:		net device
 * @channels:		includes the number of queues requested
 */
static int bnx2x_set_channels(struct net_device *dev,
			      struct ethtool_channels *channels)
{
	struct bnx2x *bp = netdev_priv(dev);

	DP(BNX2X_MSG_ETHTOOL,
	   "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
	   channels->rx_count, channels->tx_count, channels->other_count,
	   channels->combined_count);

3534 3535 3536 3537 3538
	if (pci_num_vf(bp->pdev)) {
		DP(BNX2X_MSG_IOV, "VFs are enabled, can not set channels\n");
		return -EPERM;
	}

M
Merav Sicron 已提交
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562
	/* We don't support separate rx / tx channels.
	 * We don't allow setting 'other' channels.
	 */
	if (channels->rx_count || channels->tx_count || channels->other_count
	    || (channels->combined_count == 0) ||
	    (channels->combined_count > BNX2X_MAX_RSS_COUNT(bp))) {
		DP(BNX2X_MSG_ETHTOOL, "command parameters not supported\n");
		return -EINVAL;
	}

	/* Check if there was a change in the active parameters */
	if (channels->combined_count == BNX2X_NUM_ETH_QUEUES(bp)) {
		DP(BNX2X_MSG_ETHTOOL, "No change in active parameters\n");
		return 0;
	}

	/* Set the requested number of queues in bp context.
	 * Note that the actual number of queues created during load may be
	 * less than requested if memory is low.
	 */
	if (unlikely(!netif_running(dev))) {
		bnx2x_change_num_queues(bp, channels->combined_count);
		return 0;
	}
Y
Yuval Mintz 已提交
3563
	bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
M
Merav Sicron 已提交
3564 3565 3566 3567
	bnx2x_change_num_queues(bp, channels->combined_count);
	return bnx2x_nic_load(bp, LOAD_NORMAL);
}

3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588
static int bnx2x_get_ts_info(struct net_device *dev,
			     struct ethtool_ts_info *info)
{
	struct bnx2x *bp = netdev_priv(dev);

	if (bp->flags & PTP_SUPPORTED) {
		info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
					SOF_TIMESTAMPING_RX_SOFTWARE |
					SOF_TIMESTAMPING_SOFTWARE |
					SOF_TIMESTAMPING_TX_HARDWARE |
					SOF_TIMESTAMPING_RX_HARDWARE |
					SOF_TIMESTAMPING_RAW_HARDWARE;

		if (bp->ptp_clock)
			info->phc_index = ptp_clock_index(bp->ptp_clock);
		else
			info->phc_index = -1;

		info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
				   (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
				   (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
3589
				   (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
3590 3591 3592 3593 3594 3595 3596 3597 3598

		info->tx_types = (1 << HWTSTAMP_TX_OFF)|(1 << HWTSTAMP_TX_ON);

		return 0;
	}

	return ethtool_op_get_ts_info(dev, info);
}

3599 3600 3601 3602 3603 3604
static const struct ethtool_ops bnx2x_ethtool_ops = {
	.get_settings		= bnx2x_get_settings,
	.set_settings		= bnx2x_set_settings,
	.get_drvinfo		= bnx2x_get_drvinfo,
	.get_regs_len		= bnx2x_get_regs_len,
	.get_regs		= bnx2x_get_regs,
3605 3606 3607
	.get_dump_flag		= bnx2x_get_dump_flag,
	.get_dump_data		= bnx2x_get_dump_data,
	.set_dump		= bnx2x_set_dump,
3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624
	.get_wol		= bnx2x_get_wol,
	.set_wol		= bnx2x_set_wol,
	.get_msglevel		= bnx2x_get_msglevel,
	.set_msglevel		= bnx2x_set_msglevel,
	.nway_reset		= bnx2x_nway_reset,
	.get_link		= bnx2x_get_link,
	.get_eeprom_len		= bnx2x_get_eeprom_len,
	.get_eeprom		= bnx2x_get_eeprom,
	.set_eeprom		= bnx2x_set_eeprom,
	.get_coalesce		= bnx2x_get_coalesce,
	.set_coalesce		= bnx2x_set_coalesce,
	.get_ringparam		= bnx2x_get_ringparam,
	.set_ringparam		= bnx2x_set_ringparam,
	.get_pauseparam		= bnx2x_get_pauseparam,
	.set_pauseparam		= bnx2x_set_pauseparam,
	.self_test		= bnx2x_self_test,
	.get_sset_count		= bnx2x_get_sset_count,
Y
Yuval Mintz 已提交
3625
	.get_priv_flags		= bnx2x_get_private_flags,
3626
	.get_strings		= bnx2x_get_strings,
3627
	.set_phys_id		= bnx2x_set_phys_id,
3628
	.get_ethtool_stats	= bnx2x_get_ethtool_stats,
3629
	.get_rxnfc		= bnx2x_get_rxnfc,
3630
	.set_rxnfc		= bnx2x_set_rxnfc,
3631
	.get_rxfh_indir_size	= bnx2x_get_rxfh_indir_size,
3632 3633
	.get_rxfh		= bnx2x_get_rxfh,
	.set_rxfh		= bnx2x_set_rxfh,
M
Merav Sicron 已提交
3634 3635
	.get_channels		= bnx2x_get_channels,
	.set_channels		= bnx2x_set_channels,
Y
Yuval Mintz 已提交
3636 3637
	.get_module_info	= bnx2x_get_module_info,
	.get_module_eeprom	= bnx2x_get_module_eeprom,
Y
Yuval Mintz 已提交
3638 3639
	.get_eee		= bnx2x_get_eee,
	.set_eee		= bnx2x_set_eee,
3640
	.get_ts_info		= bnx2x_get_ts_info,
3641 3642
};

A
Ariel Elior 已提交
3643
static const struct ethtool_ops bnx2x_vf_ethtool_ops = {
D
Dmitry Kravkov 已提交
3644
	.get_settings		= bnx2x_get_vf_settings,
A
Ariel Elior 已提交
3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657
	.get_drvinfo		= bnx2x_get_drvinfo,
	.get_msglevel		= bnx2x_get_msglevel,
	.set_msglevel		= bnx2x_set_msglevel,
	.get_link		= bnx2x_get_link,
	.get_coalesce		= bnx2x_get_coalesce,
	.get_ringparam		= bnx2x_get_ringparam,
	.set_ringparam		= bnx2x_set_ringparam,
	.get_sset_count		= bnx2x_get_sset_count,
	.get_strings		= bnx2x_get_strings,
	.get_ethtool_stats	= bnx2x_get_ethtool_stats,
	.get_rxnfc		= bnx2x_get_rxnfc,
	.set_rxnfc		= bnx2x_set_rxnfc,
	.get_rxfh_indir_size	= bnx2x_get_rxfh_indir_size,
3658 3659
	.get_rxfh		= bnx2x_get_rxfh,
	.set_rxfh		= bnx2x_set_rxfh,
A
Ariel Elior 已提交
3660 3661 3662 3663 3664
	.get_channels		= bnx2x_get_channels,
	.set_channels		= bnx2x_set_channels,
};

void bnx2x_set_ethtool_ops(struct bnx2x *bp, struct net_device *netdev)
3665
{
3666 3667
	netdev->ethtool_ops = (IS_PF(bp)) ?
		&bnx2x_ethtool_ops : &bnx2x_vf_ethtool_ops;
3668
}