18c2ecf20Sopenharmony_ci/* Copyright 2008-2013 Broadcom Corporation
28c2ecf20Sopenharmony_ci * Copyright (c) 2014 QLogic Corporation
38c2ecf20Sopenharmony_ci * All rights reserved
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Unless you and QLogic execute a separate written software license
68c2ecf20Sopenharmony_ci * agreement governing use of this software, this software is licensed to you
78c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License version 2, available
88c2ecf20Sopenharmony_ci * at http://www.gnu.org/licenses/gpl-2.0.html (the "GPL").
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Notwithstanding the above, under no circumstances may you combine this
118c2ecf20Sopenharmony_ci * software in any way with any other Qlogic software provided under a
128c2ecf20Sopenharmony_ci * license other than the GPL, without Qlogic's express prior written
138c2ecf20Sopenharmony_ci * consent.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * Written by Yaniv Rosner
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <linux/kernel.h>
228c2ecf20Sopenharmony_ci#include <linux/errno.h>
238c2ecf20Sopenharmony_ci#include <linux/pci.h>
248c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
258c2ecf20Sopenharmony_ci#include <linux/delay.h>
268c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
278c2ecf20Sopenharmony_ci#include <linux/mutex.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include "bnx2x.h"
308c2ecf20Sopenharmony_ci#include "bnx2x_cmn.h"
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_citypedef int (*read_sfp_module_eeprom_func_p)(struct bnx2x_phy *phy,
338c2ecf20Sopenharmony_ci					     struct link_params *params,
348c2ecf20Sopenharmony_ci					     u8 dev_addr, u16 addr, u8 byte_cnt,
358c2ecf20Sopenharmony_ci					     u8 *o_buf, u8);
368c2ecf20Sopenharmony_ci/********************************************************/
378c2ecf20Sopenharmony_ci#define MDIO_ACCESS_TIMEOUT		1000
388c2ecf20Sopenharmony_ci#define WC_LANE_MAX			4
398c2ecf20Sopenharmony_ci#define I2C_SWITCH_WIDTH		2
408c2ecf20Sopenharmony_ci#define I2C_BSC0			0
418c2ecf20Sopenharmony_ci#define I2C_BSC1			1
428c2ecf20Sopenharmony_ci#define I2C_WA_RETRY_CNT		3
438c2ecf20Sopenharmony_ci#define I2C_WA_PWR_ITER			(I2C_WA_RETRY_CNT - 1)
448c2ecf20Sopenharmony_ci#define MCPR_IMC_COMMAND_READ_OP	1
458c2ecf20Sopenharmony_ci#define MCPR_IMC_COMMAND_WRITE_OP	2
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/* LED Blink rate that will achieve ~15.9Hz */
488c2ecf20Sopenharmony_ci#define LED_BLINK_RATE_VAL_E3		354
498c2ecf20Sopenharmony_ci#define LED_BLINK_RATE_VAL_E1X_E2	480
508c2ecf20Sopenharmony_ci/***********************************************************/
518c2ecf20Sopenharmony_ci/*			Shortcut definitions		   */
528c2ecf20Sopenharmony_ci/***********************************************************/
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define NIG_LATCH_BC_ENABLE_MI_INT 0
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define NIG_STATUS_EMAC0_MI_INT \
578c2ecf20Sopenharmony_ci		NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
588c2ecf20Sopenharmony_ci#define NIG_STATUS_XGXS0_LINK10G \
598c2ecf20Sopenharmony_ci		NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
608c2ecf20Sopenharmony_ci#define NIG_STATUS_XGXS0_LINK_STATUS \
618c2ecf20Sopenharmony_ci		NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
628c2ecf20Sopenharmony_ci#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
638c2ecf20Sopenharmony_ci		NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
648c2ecf20Sopenharmony_ci#define NIG_STATUS_SERDES0_LINK_STATUS \
658c2ecf20Sopenharmony_ci		NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
668c2ecf20Sopenharmony_ci#define NIG_MASK_MI_INT \
678c2ecf20Sopenharmony_ci		NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
688c2ecf20Sopenharmony_ci#define NIG_MASK_XGXS0_LINK10G \
698c2ecf20Sopenharmony_ci		NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
708c2ecf20Sopenharmony_ci#define NIG_MASK_XGXS0_LINK_STATUS \
718c2ecf20Sopenharmony_ci		NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
728c2ecf20Sopenharmony_ci#define NIG_MASK_SERDES0_LINK_STATUS \
738c2ecf20Sopenharmony_ci		NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define MDIO_AN_CL73_OR_37_COMPLETE \
768c2ecf20Sopenharmony_ci		(MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
778c2ecf20Sopenharmony_ci		 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define XGXS_RESET_BITS \
808c2ecf20Sopenharmony_ci	(MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW |   \
818c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ |      \
828c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN |    \
838c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
848c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define SERDES_RESET_BITS \
878c2ecf20Sopenharmony_ci	(MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
888c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ |    \
898c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN |  \
908c2ecf20Sopenharmony_ci	 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define AUTONEG_CL37		SHARED_HW_CFG_AN_ENABLE_CL37
938c2ecf20Sopenharmony_ci#define AUTONEG_CL73		SHARED_HW_CFG_AN_ENABLE_CL73
948c2ecf20Sopenharmony_ci#define AUTONEG_BAM		SHARED_HW_CFG_AN_ENABLE_BAM
958c2ecf20Sopenharmony_ci#define AUTONEG_PARALLEL \
968c2ecf20Sopenharmony_ci				SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
978c2ecf20Sopenharmony_ci#define AUTONEG_SGMII_FIBER_AUTODET \
988c2ecf20Sopenharmony_ci				SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
998c2ecf20Sopenharmony_ci#define AUTONEG_REMOTE_PHY	SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
1028c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
1038c2ecf20Sopenharmony_ci#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
1048c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
1058c2ecf20Sopenharmony_ci#define GP_STATUS_SPEED_MASK \
1068c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
1078c2ecf20Sopenharmony_ci#define GP_STATUS_10M	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
1088c2ecf20Sopenharmony_ci#define GP_STATUS_100M	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
1098c2ecf20Sopenharmony_ci#define GP_STATUS_1G	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
1108c2ecf20Sopenharmony_ci#define GP_STATUS_2_5G	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
1118c2ecf20Sopenharmony_ci#define GP_STATUS_5G	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
1128c2ecf20Sopenharmony_ci#define GP_STATUS_6G	MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
1138c2ecf20Sopenharmony_ci#define GP_STATUS_10G_HIG \
1148c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
1158c2ecf20Sopenharmony_ci#define GP_STATUS_10G_CX4 \
1168c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
1178c2ecf20Sopenharmony_ci#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
1188c2ecf20Sopenharmony_ci#define GP_STATUS_10G_KX4 \
1198c2ecf20Sopenharmony_ci			MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
1208c2ecf20Sopenharmony_ci#define	GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
1218c2ecf20Sopenharmony_ci#define	GP_STATUS_10G_XFI   MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
1228c2ecf20Sopenharmony_ci#define	GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
1238c2ecf20Sopenharmony_ci#define	GP_STATUS_10G_SFI   MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
1248c2ecf20Sopenharmony_ci#define	GP_STATUS_20G_KR2 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_KR2
1258c2ecf20Sopenharmony_ci#define LINK_10THD		LINK_STATUS_SPEED_AND_DUPLEX_10THD
1268c2ecf20Sopenharmony_ci#define LINK_10TFD		LINK_STATUS_SPEED_AND_DUPLEX_10TFD
1278c2ecf20Sopenharmony_ci#define LINK_100TXHD		LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
1288c2ecf20Sopenharmony_ci#define LINK_100T4		LINK_STATUS_SPEED_AND_DUPLEX_100T4
1298c2ecf20Sopenharmony_ci#define LINK_100TXFD		LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
1308c2ecf20Sopenharmony_ci#define LINK_1000THD		LINK_STATUS_SPEED_AND_DUPLEX_1000THD
1318c2ecf20Sopenharmony_ci#define LINK_1000TFD		LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
1328c2ecf20Sopenharmony_ci#define LINK_1000XFD		LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
1338c2ecf20Sopenharmony_ci#define LINK_2500THD		LINK_STATUS_SPEED_AND_DUPLEX_2500THD
1348c2ecf20Sopenharmony_ci#define LINK_2500TFD		LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
1358c2ecf20Sopenharmony_ci#define LINK_2500XFD		LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
1368c2ecf20Sopenharmony_ci#define LINK_10GTFD		LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
1378c2ecf20Sopenharmony_ci#define LINK_10GXFD		LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
1388c2ecf20Sopenharmony_ci#define LINK_20GTFD		LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
1398c2ecf20Sopenharmony_ci#define LINK_20GXFD		LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define LINK_UPDATE_MASK \
1428c2ecf20Sopenharmony_ci			(LINK_STATUS_SPEED_AND_DUPLEX_MASK | \
1438c2ecf20Sopenharmony_ci			 LINK_STATUS_LINK_UP | \
1448c2ecf20Sopenharmony_ci			 LINK_STATUS_PHYSICAL_LINK_FLAG | \
1458c2ecf20Sopenharmony_ci			 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE | \
1468c2ecf20Sopenharmony_ci			 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK | \
1478c2ecf20Sopenharmony_ci			 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK | \
1488c2ecf20Sopenharmony_ci			 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK | \
1498c2ecf20Sopenharmony_ci			 LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE | \
1508c2ecf20Sopenharmony_ci			 LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define SFP_EEPROM_CON_TYPE_ADDR		0x2
1538c2ecf20Sopenharmony_ci	#define SFP_EEPROM_CON_TYPE_VAL_UNKNOWN	0x0
1548c2ecf20Sopenharmony_ci	#define SFP_EEPROM_CON_TYPE_VAL_LC	0x7
1558c2ecf20Sopenharmony_ci	#define SFP_EEPROM_CON_TYPE_VAL_COPPER	0x21
1568c2ecf20Sopenharmony_ci	#define SFP_EEPROM_CON_TYPE_VAL_RJ45	0x22
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci#define SFP_EEPROM_10G_COMP_CODE_ADDR		0x3
1608c2ecf20Sopenharmony_ci	#define SFP_EEPROM_10G_COMP_CODE_SR_MASK	(1<<4)
1618c2ecf20Sopenharmony_ci	#define SFP_EEPROM_10G_COMP_CODE_LR_MASK	(1<<5)
1628c2ecf20Sopenharmony_ci	#define SFP_EEPROM_10G_COMP_CODE_LRM_MASK	(1<<6)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define SFP_EEPROM_1G_COMP_CODE_ADDR		0x6
1658c2ecf20Sopenharmony_ci	#define SFP_EEPROM_1G_COMP_CODE_SX	(1<<0)
1668c2ecf20Sopenharmony_ci	#define SFP_EEPROM_1G_COMP_CODE_LX	(1<<1)
1678c2ecf20Sopenharmony_ci	#define SFP_EEPROM_1G_COMP_CODE_CX	(1<<2)
1688c2ecf20Sopenharmony_ci	#define SFP_EEPROM_1G_COMP_CODE_BASE_T	(1<<3)
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define SFP_EEPROM_FC_TX_TECH_ADDR		0x8
1718c2ecf20Sopenharmony_ci	#define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
1728c2ecf20Sopenharmony_ci	#define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE  0x8
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#define SFP_EEPROM_OPTIONS_ADDR			0x40
1758c2ecf20Sopenharmony_ci	#define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
1768c2ecf20Sopenharmony_ci#define SFP_EEPROM_OPTIONS_SIZE			2
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define EDC_MODE_LINEAR				0x0022
1798c2ecf20Sopenharmony_ci#define EDC_MODE_LIMITING				0x0044
1808c2ecf20Sopenharmony_ci#define EDC_MODE_PASSIVE_DAC			0x0055
1818c2ecf20Sopenharmony_ci#define EDC_MODE_ACTIVE_DAC			0x0066
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* ETS defines*/
1848c2ecf20Sopenharmony_ci#define DCBX_INVALID_COS					(0xFF)
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND		(0x5000)
1878c2ecf20Sopenharmony_ci#define ETS_BW_LIMIT_CREDIT_WEIGHT		(0x5000)
1888c2ecf20Sopenharmony_ci#define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS		(1360)
1898c2ecf20Sopenharmony_ci#define ETS_E3B0_NIG_MIN_W_VAL_20GBPS			(2720)
1908c2ecf20Sopenharmony_ci#define ETS_E3B0_PBF_MIN_W_VAL				(10000)
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#define MAX_PACKET_SIZE					(9700)
1938c2ecf20Sopenharmony_ci#define MAX_KR_LINK_RETRY				4
1948c2ecf20Sopenharmony_ci#define DEFAULT_TX_DRV_BRDCT		2
1958c2ecf20Sopenharmony_ci#define DEFAULT_TX_DRV_IFIR		0
1968c2ecf20Sopenharmony_ci#define DEFAULT_TX_DRV_POST2		3
1978c2ecf20Sopenharmony_ci#define DEFAULT_TX_DRV_IPRE_DRIVER	6
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/**********************************************************/
2008c2ecf20Sopenharmony_ci/*                     INTERFACE                          */
2018c2ecf20Sopenharmony_ci/**********************************************************/
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
2048c2ecf20Sopenharmony_ci	bnx2x_cl45_write(_bp, _phy, \
2058c2ecf20Sopenharmony_ci		(_phy)->def_md_devad, \
2068c2ecf20Sopenharmony_ci		(_bank + (_addr & 0xf)), \
2078c2ecf20Sopenharmony_ci		_val)
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
2108c2ecf20Sopenharmony_ci	bnx2x_cl45_read(_bp, _phy, \
2118c2ecf20Sopenharmony_ci		(_phy)->def_md_devad, \
2128c2ecf20Sopenharmony_ci		(_bank + (_addr & 0xf)), \
2138c2ecf20Sopenharmony_ci		_val)
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cistatic int bnx2x_check_half_open_conn(struct link_params *params,
2168c2ecf20Sopenharmony_ci				      struct link_vars *vars, u8 notify);
2178c2ecf20Sopenharmony_cistatic int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
2188c2ecf20Sopenharmony_ci				      struct link_params *params);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	u32 val = REG_RD(bp, reg);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	val |= bits;
2258c2ecf20Sopenharmony_ci	REG_WR(bp, reg, val);
2268c2ecf20Sopenharmony_ci	return val;
2278c2ecf20Sopenharmony_ci}
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_cistatic u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci	u32 val = REG_RD(bp, reg);
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	val &= ~bits;
2348c2ecf20Sopenharmony_ci	REG_WR(bp, reg, val);
2358c2ecf20Sopenharmony_ci	return val;
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/*
2398c2ecf20Sopenharmony_ci * bnx2x_check_lfa - This function checks if link reinitialization is required,
2408c2ecf20Sopenharmony_ci *                   or link flap can be avoided.
2418c2ecf20Sopenharmony_ci *
2428c2ecf20Sopenharmony_ci * @params:	link parameters
2438c2ecf20Sopenharmony_ci * Returns 0 if Link Flap Avoidance conditions are met otherwise, the failed
2448c2ecf20Sopenharmony_ci *         condition code.
2458c2ecf20Sopenharmony_ci */
2468c2ecf20Sopenharmony_cistatic int bnx2x_check_lfa(struct link_params *params)
2478c2ecf20Sopenharmony_ci{
2488c2ecf20Sopenharmony_ci	u32 link_status, cfg_idx, lfa_mask, cfg_size;
2498c2ecf20Sopenharmony_ci	u32 cur_speed_cap_mask, cur_req_fc_auto_adv, additional_config;
2508c2ecf20Sopenharmony_ci	u32 saved_val, req_val, eee_status;
2518c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	additional_config =
2548c2ecf20Sopenharmony_ci		REG_RD(bp, params->lfa_base +
2558c2ecf20Sopenharmony_ci			   offsetof(struct shmem_lfa, additional_config));
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/* NOTE: must be first condition checked -
2588c2ecf20Sopenharmony_ci	* to verify DCC bit is cleared in any case!
2598c2ecf20Sopenharmony_ci	*/
2608c2ecf20Sopenharmony_ci	if (additional_config & NO_LFA_DUE_TO_DCC_MASK) {
2618c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "No LFA due to DCC flap after clp exit\n");
2628c2ecf20Sopenharmony_ci		REG_WR(bp, params->lfa_base +
2638c2ecf20Sopenharmony_ci			   offsetof(struct shmem_lfa, additional_config),
2648c2ecf20Sopenharmony_ci		       additional_config & ~NO_LFA_DUE_TO_DCC_MASK);
2658c2ecf20Sopenharmony_ci		return LFA_DCC_LFA_DISABLED;
2668c2ecf20Sopenharmony_ci	}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	/* Verify that link is up */
2698c2ecf20Sopenharmony_ci	link_status = REG_RD(bp, params->shmem_base +
2708c2ecf20Sopenharmony_ci			     offsetof(struct shmem_region,
2718c2ecf20Sopenharmony_ci				      port_mb[params->port].link_status));
2728c2ecf20Sopenharmony_ci	if (!(link_status & LINK_STATUS_LINK_UP))
2738c2ecf20Sopenharmony_ci		return LFA_LINK_DOWN;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	/* if loaded after BOOT from SAN, don't flap the link in any case and
2768c2ecf20Sopenharmony_ci	 * rely on link set by preboot driver
2778c2ecf20Sopenharmony_ci	 */
2788c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_BOOT_FROM_SAN)
2798c2ecf20Sopenharmony_ci		return 0;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	/* Verify that loopback mode is not set */
2828c2ecf20Sopenharmony_ci	if (params->loopback_mode)
2838c2ecf20Sopenharmony_ci		return LFA_LOOPBACK_ENABLED;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	/* Verify that MFW supports LFA */
2868c2ecf20Sopenharmony_ci	if (!params->lfa_base)
2878c2ecf20Sopenharmony_ci		return LFA_MFW_IS_TOO_OLD;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	if (params->num_phys == 3) {
2908c2ecf20Sopenharmony_ci		cfg_size = 2;
2918c2ecf20Sopenharmony_ci		lfa_mask = 0xffffffff;
2928c2ecf20Sopenharmony_ci	} else {
2938c2ecf20Sopenharmony_ci		cfg_size = 1;
2948c2ecf20Sopenharmony_ci		lfa_mask = 0xffff;
2958c2ecf20Sopenharmony_ci	}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	/* Compare Duplex */
2988c2ecf20Sopenharmony_ci	saved_val = REG_RD(bp, params->lfa_base +
2998c2ecf20Sopenharmony_ci			   offsetof(struct shmem_lfa, req_duplex));
3008c2ecf20Sopenharmony_ci	req_val = params->req_duplex[0] | (params->req_duplex[1] << 16);
3018c2ecf20Sopenharmony_ci	if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
3028c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Duplex mismatch %x vs. %x\n",
3038c2ecf20Sopenharmony_ci			       (saved_val & lfa_mask), (req_val & lfa_mask));
3048c2ecf20Sopenharmony_ci		return LFA_DUPLEX_MISMATCH;
3058c2ecf20Sopenharmony_ci	}
3068c2ecf20Sopenharmony_ci	/* Compare Flow Control */
3078c2ecf20Sopenharmony_ci	saved_val = REG_RD(bp, params->lfa_base +
3088c2ecf20Sopenharmony_ci			   offsetof(struct shmem_lfa, req_flow_ctrl));
3098c2ecf20Sopenharmony_ci	req_val = params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16);
3108c2ecf20Sopenharmony_ci	if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
3118c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Flow control mismatch %x vs. %x\n",
3128c2ecf20Sopenharmony_ci			       (saved_val & lfa_mask), (req_val & lfa_mask));
3138c2ecf20Sopenharmony_ci		return LFA_FLOW_CTRL_MISMATCH;
3148c2ecf20Sopenharmony_ci	}
3158c2ecf20Sopenharmony_ci	/* Compare Link Speed */
3168c2ecf20Sopenharmony_ci	saved_val = REG_RD(bp, params->lfa_base +
3178c2ecf20Sopenharmony_ci			   offsetof(struct shmem_lfa, req_line_speed));
3188c2ecf20Sopenharmony_ci	req_val = params->req_line_speed[0] | (params->req_line_speed[1] << 16);
3198c2ecf20Sopenharmony_ci	if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
3208c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Link speed mismatch %x vs. %x\n",
3218c2ecf20Sopenharmony_ci			       (saved_val & lfa_mask), (req_val & lfa_mask));
3228c2ecf20Sopenharmony_ci		return LFA_LINK_SPEED_MISMATCH;
3238c2ecf20Sopenharmony_ci	}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	for (cfg_idx = 0; cfg_idx < cfg_size; cfg_idx++) {
3268c2ecf20Sopenharmony_ci		cur_speed_cap_mask = REG_RD(bp, params->lfa_base +
3278c2ecf20Sopenharmony_ci					    offsetof(struct shmem_lfa,
3288c2ecf20Sopenharmony_ci						     speed_cap_mask[cfg_idx]));
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci		if (cur_speed_cap_mask != params->speed_cap_mask[cfg_idx]) {
3318c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Speed Cap mismatch %x vs. %x\n",
3328c2ecf20Sopenharmony_ci				       cur_speed_cap_mask,
3338c2ecf20Sopenharmony_ci				       params->speed_cap_mask[cfg_idx]);
3348c2ecf20Sopenharmony_ci			return LFA_SPEED_CAP_MISMATCH;
3358c2ecf20Sopenharmony_ci		}
3368c2ecf20Sopenharmony_ci	}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	cur_req_fc_auto_adv =
3398c2ecf20Sopenharmony_ci		REG_RD(bp, params->lfa_base +
3408c2ecf20Sopenharmony_ci		       offsetof(struct shmem_lfa, additional_config)) &
3418c2ecf20Sopenharmony_ci		REQ_FC_AUTO_ADV_MASK;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	if ((u16)cur_req_fc_auto_adv != params->req_fc_auto_adv) {
3448c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Flow Ctrl AN mismatch %x vs. %x\n",
3458c2ecf20Sopenharmony_ci			       cur_req_fc_auto_adv, params->req_fc_auto_adv);
3468c2ecf20Sopenharmony_ci		return LFA_FLOW_CTRL_MISMATCH;
3478c2ecf20Sopenharmony_ci	}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	eee_status = REG_RD(bp, params->shmem2_base +
3508c2ecf20Sopenharmony_ci			    offsetof(struct shmem2_region,
3518c2ecf20Sopenharmony_ci				     eee_status[params->port]));
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	if (((eee_status & SHMEM_EEE_LPI_REQUESTED_BIT) ^
3548c2ecf20Sopenharmony_ci	     (params->eee_mode & EEE_MODE_ENABLE_LPI)) ||
3558c2ecf20Sopenharmony_ci	    ((eee_status & SHMEM_EEE_REQUESTED_BIT) ^
3568c2ecf20Sopenharmony_ci	     (params->eee_mode & EEE_MODE_ADV_LPI))) {
3578c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "EEE mismatch %x vs. %x\n", params->eee_mode,
3588c2ecf20Sopenharmony_ci			       eee_status);
3598c2ecf20Sopenharmony_ci		return LFA_EEE_MISMATCH;
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	/* LFA conditions are met */
3638c2ecf20Sopenharmony_ci	return 0;
3648c2ecf20Sopenharmony_ci}
3658c2ecf20Sopenharmony_ci/******************************************************************/
3668c2ecf20Sopenharmony_ci/*			EPIO/GPIO section			  */
3678c2ecf20Sopenharmony_ci/******************************************************************/
3688c2ecf20Sopenharmony_cistatic void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	u32 epio_mask, gp_oenable;
3718c2ecf20Sopenharmony_ci	*en = 0;
3728c2ecf20Sopenharmony_ci	/* Sanity check */
3738c2ecf20Sopenharmony_ci	if (epio_pin > 31) {
3748c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
3758c2ecf20Sopenharmony_ci		return;
3768c2ecf20Sopenharmony_ci	}
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	epio_mask = 1 << epio_pin;
3798c2ecf20Sopenharmony_ci	/* Set this EPIO to output */
3808c2ecf20Sopenharmony_ci	gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
3818c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	*en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
3848c2ecf20Sopenharmony_ci}
3858c2ecf20Sopenharmony_cistatic void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	u32 epio_mask, gp_output, gp_oenable;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	/* Sanity check */
3908c2ecf20Sopenharmony_ci	if (epio_pin > 31) {
3918c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
3928c2ecf20Sopenharmony_ci		return;
3938c2ecf20Sopenharmony_ci	}
3948c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
3958c2ecf20Sopenharmony_ci	epio_mask = 1 << epio_pin;
3968c2ecf20Sopenharmony_ci	/* Set this EPIO to output */
3978c2ecf20Sopenharmony_ci	gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
3988c2ecf20Sopenharmony_ci	if (en)
3998c2ecf20Sopenharmony_ci		gp_output |= epio_mask;
4008c2ecf20Sopenharmony_ci	else
4018c2ecf20Sopenharmony_ci		gp_output &= ~epio_mask;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	/* Set the value for this EPIO */
4068c2ecf20Sopenharmony_ci	gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
4078c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
4088c2ecf20Sopenharmony_ci}
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_cistatic void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	if (pin_cfg == PIN_CFG_NA)
4138c2ecf20Sopenharmony_ci		return;
4148c2ecf20Sopenharmony_ci	if (pin_cfg >= PIN_CFG_EPIO0) {
4158c2ecf20Sopenharmony_ci		bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
4168c2ecf20Sopenharmony_ci	} else {
4178c2ecf20Sopenharmony_ci		u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
4188c2ecf20Sopenharmony_ci		u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
4198c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
4208c2ecf20Sopenharmony_ci	}
4218c2ecf20Sopenharmony_ci}
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_cistatic u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
4248c2ecf20Sopenharmony_ci{
4258c2ecf20Sopenharmony_ci	if (pin_cfg == PIN_CFG_NA)
4268c2ecf20Sopenharmony_ci		return -EINVAL;
4278c2ecf20Sopenharmony_ci	if (pin_cfg >= PIN_CFG_EPIO0) {
4288c2ecf20Sopenharmony_ci		bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
4298c2ecf20Sopenharmony_ci	} else {
4308c2ecf20Sopenharmony_ci		u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
4318c2ecf20Sopenharmony_ci		u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
4328c2ecf20Sopenharmony_ci		*val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
4338c2ecf20Sopenharmony_ci	}
4348c2ecf20Sopenharmony_ci	return 0;
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci/******************************************************************/
4388c2ecf20Sopenharmony_ci/*				ETS section			  */
4398c2ecf20Sopenharmony_ci/******************************************************************/
4408c2ecf20Sopenharmony_cistatic void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	/* ETS disabled configuration*/
4438c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	/* mapping between entry  priority to client number (0,1,2 -debug and
4488c2ecf20Sopenharmony_ci	 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
4498c2ecf20Sopenharmony_ci	 * 3bits client num.
4508c2ecf20Sopenharmony_ci	 *   PRI4    |    PRI3    |    PRI2    |    PRI1    |    PRI0
4518c2ecf20Sopenharmony_ci	 * cos1-100     cos0-011     dbg1-010     dbg0-001     MCP-000
4528c2ecf20Sopenharmony_ci	 */
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
4558c2ecf20Sopenharmony_ci	/* Bitmap of 5bits length. Each bit specifies whether the entry behaves
4568c2ecf20Sopenharmony_ci	 * as strict.  Bits 0,1,2 - debug and management entries, 3 -
4578c2ecf20Sopenharmony_ci	 * COS0 entry, 4 - COS1 entry.
4588c2ecf20Sopenharmony_ci	 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
4598c2ecf20Sopenharmony_ci	 * bit4   bit3	  bit2   bit1	  bit0
4608c2ecf20Sopenharmony_ci	 * MCP and debug are strict
4618c2ecf20Sopenharmony_ci	 */
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
4648c2ecf20Sopenharmony_ci	/* defines which entries (clients) are subjected to WFQ arbitration */
4658c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
4668c2ecf20Sopenharmony_ci	/* For strict priority entries defines the number of consecutive
4678c2ecf20Sopenharmony_ci	 * slots for the highest priority.
4688c2ecf20Sopenharmony_ci	 */
4698c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
4708c2ecf20Sopenharmony_ci	/* mapping between the CREDIT_WEIGHT registers and actual client
4718c2ecf20Sopenharmony_ci	 * numbers
4728c2ecf20Sopenharmony_ci	 */
4738c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
4748c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
4758c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
4788c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
4798c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
4808c2ecf20Sopenharmony_ci	/* ETS mode disable */
4818c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
4828c2ecf20Sopenharmony_ci	/* If ETS mode is enabled (there is no strict priority) defines a WFQ
4838c2ecf20Sopenharmony_ci	 * weight for COS0/COS1.
4848c2ecf20Sopenharmony_ci	 */
4858c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
4868c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
4878c2ecf20Sopenharmony_ci	/* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
4888c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
4898c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
4908c2ecf20Sopenharmony_ci	/* Defines the number of consecutive slots for the strict priority */
4918c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
4928c2ecf20Sopenharmony_ci}
4938c2ecf20Sopenharmony_ci/******************************************************************************
4948c2ecf20Sopenharmony_ci* Description:
4958c2ecf20Sopenharmony_ci*	Getting min_w_val will be set according to line speed .
4968c2ecf20Sopenharmony_ci*.
4978c2ecf20Sopenharmony_ci******************************************************************************/
4988c2ecf20Sopenharmony_cistatic u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
4998c2ecf20Sopenharmony_ci{
5008c2ecf20Sopenharmony_ci	u32 min_w_val = 0;
5018c2ecf20Sopenharmony_ci	/* Calculate min_w_val.*/
5028c2ecf20Sopenharmony_ci	if (vars->link_up) {
5038c2ecf20Sopenharmony_ci		if (vars->line_speed == SPEED_20000)
5048c2ecf20Sopenharmony_ci			min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
5058c2ecf20Sopenharmony_ci		else
5068c2ecf20Sopenharmony_ci			min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
5078c2ecf20Sopenharmony_ci	} else
5088c2ecf20Sopenharmony_ci		min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
5098c2ecf20Sopenharmony_ci	/* If the link isn't up (static configuration for example ) The
5108c2ecf20Sopenharmony_ci	 * link will be according to 20GBPS.
5118c2ecf20Sopenharmony_ci	 */
5128c2ecf20Sopenharmony_ci	return min_w_val;
5138c2ecf20Sopenharmony_ci}
5148c2ecf20Sopenharmony_ci/******************************************************************************
5158c2ecf20Sopenharmony_ci* Description:
5168c2ecf20Sopenharmony_ci*	Getting credit upper bound form min_w_val.
5178c2ecf20Sopenharmony_ci*.
5188c2ecf20Sopenharmony_ci******************************************************************************/
5198c2ecf20Sopenharmony_cistatic u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
5208c2ecf20Sopenharmony_ci{
5218c2ecf20Sopenharmony_ci	const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
5228c2ecf20Sopenharmony_ci						MAX_PACKET_SIZE);
5238c2ecf20Sopenharmony_ci	return credit_upper_bound;
5248c2ecf20Sopenharmony_ci}
5258c2ecf20Sopenharmony_ci/******************************************************************************
5268c2ecf20Sopenharmony_ci* Description:
5278c2ecf20Sopenharmony_ci*	Set credit upper bound for NIG.
5288c2ecf20Sopenharmony_ci*.
5298c2ecf20Sopenharmony_ci******************************************************************************/
5308c2ecf20Sopenharmony_cistatic void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
5318c2ecf20Sopenharmony_ci	const struct link_params *params,
5328c2ecf20Sopenharmony_ci	const u32 min_w_val)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
5358c2ecf20Sopenharmony_ci	const u8 port = params->port;
5368c2ecf20Sopenharmony_ci	const u32 credit_upper_bound =
5378c2ecf20Sopenharmony_ci	    bnx2x_ets_get_credit_upper_bound(min_w_val);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
5408c2ecf20Sopenharmony_ci		NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
5418c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
5428c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
5438c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
5448c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
5458c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
5468c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
5478c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
5488c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
5498c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
5508c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	if (!port) {
5538c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
5548c2ecf20Sopenharmony_ci			credit_upper_bound);
5558c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
5568c2ecf20Sopenharmony_ci			credit_upper_bound);
5578c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
5588c2ecf20Sopenharmony_ci			credit_upper_bound);
5598c2ecf20Sopenharmony_ci	}
5608c2ecf20Sopenharmony_ci}
5618c2ecf20Sopenharmony_ci/******************************************************************************
5628c2ecf20Sopenharmony_ci* Description:
5638c2ecf20Sopenharmony_ci*	Will return the NIG ETS registers to init values.Except
5648c2ecf20Sopenharmony_ci*	credit_upper_bound.
5658c2ecf20Sopenharmony_ci*	That isn't used in this configuration (No WFQ is enabled) and will be
5668c2ecf20Sopenharmony_ci*	configured according to spec
5678c2ecf20Sopenharmony_ci*.
5688c2ecf20Sopenharmony_ci******************************************************************************/
5698c2ecf20Sopenharmony_cistatic void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
5708c2ecf20Sopenharmony_ci					const struct link_vars *vars)
5718c2ecf20Sopenharmony_ci{
5728c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
5738c2ecf20Sopenharmony_ci	const u8 port = params->port;
5748c2ecf20Sopenharmony_ci	const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
5758c2ecf20Sopenharmony_ci	/* Mapping between entry  priority to client number (0,1,2 -debug and
5768c2ecf20Sopenharmony_ci	 * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
5778c2ecf20Sopenharmony_ci	 * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
5788c2ecf20Sopenharmony_ci	 * reset value or init tool
5798c2ecf20Sopenharmony_ci	 */
5808c2ecf20Sopenharmony_ci	if (port) {
5818c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
5828c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
5838c2ecf20Sopenharmony_ci	} else {
5848c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
5858c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
5868c2ecf20Sopenharmony_ci	}
5878c2ecf20Sopenharmony_ci	/* For strict priority entries defines the number of consecutive
5888c2ecf20Sopenharmony_ci	 * slots for the highest priority.
5898c2ecf20Sopenharmony_ci	 */
5908c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
5918c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
5928c2ecf20Sopenharmony_ci	/* Mapping between the CREDIT_WEIGHT registers and actual client
5938c2ecf20Sopenharmony_ci	 * numbers
5948c2ecf20Sopenharmony_ci	 */
5958c2ecf20Sopenharmony_ci	if (port) {
5968c2ecf20Sopenharmony_ci		/*Port 1 has 6 COS*/
5978c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
5988c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
5998c2ecf20Sopenharmony_ci	} else {
6008c2ecf20Sopenharmony_ci		/*Port 0 has 9 COS*/
6018c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
6028c2ecf20Sopenharmony_ci		       0x43210876);
6038c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
6048c2ecf20Sopenharmony_ci	}
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	/* Bitmap of 5bits length. Each bit specifies whether the entry behaves
6078c2ecf20Sopenharmony_ci	 * as strict.  Bits 0,1,2 - debug and management entries, 3 -
6088c2ecf20Sopenharmony_ci	 * COS0 entry, 4 - COS1 entry.
6098c2ecf20Sopenharmony_ci	 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
6108c2ecf20Sopenharmony_ci	 * bit4   bit3	  bit2   bit1	  bit0
6118c2ecf20Sopenharmony_ci	 * MCP and debug are strict
6128c2ecf20Sopenharmony_ci	 */
6138c2ecf20Sopenharmony_ci	if (port)
6148c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
6158c2ecf20Sopenharmony_ci	else
6168c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
6178c2ecf20Sopenharmony_ci	/* defines which entries (clients) are subjected to WFQ arbitration */
6188c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
6198c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	/* Please notice the register address are note continuous and a
6228c2ecf20Sopenharmony_ci	 * for here is note appropriate.In 2 port mode port0 only COS0-5
6238c2ecf20Sopenharmony_ci	 * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
6248c2ecf20Sopenharmony_ci	 * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
6258c2ecf20Sopenharmony_ci	 * are never used for WFQ
6268c2ecf20Sopenharmony_ci	 */
6278c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
6288c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
6298c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
6308c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
6318c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
6328c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
6338c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
6348c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
6358c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
6368c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
6378c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
6388c2ecf20Sopenharmony_ci		   NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
6398c2ecf20Sopenharmony_ci	if (!port) {
6408c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
6418c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
6428c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
6438c2ecf20Sopenharmony_ci	}
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
6468c2ecf20Sopenharmony_ci}
6478c2ecf20Sopenharmony_ci/******************************************************************************
6488c2ecf20Sopenharmony_ci* Description:
6498c2ecf20Sopenharmony_ci*	Set credit upper bound for PBF.
6508c2ecf20Sopenharmony_ci*.
6518c2ecf20Sopenharmony_ci******************************************************************************/
6528c2ecf20Sopenharmony_cistatic void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
6538c2ecf20Sopenharmony_ci	const struct link_params *params,
6548c2ecf20Sopenharmony_ci	const u32 min_w_val)
6558c2ecf20Sopenharmony_ci{
6568c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
6578c2ecf20Sopenharmony_ci	const u32 credit_upper_bound =
6588c2ecf20Sopenharmony_ci	    bnx2x_ets_get_credit_upper_bound(min_w_val);
6598c2ecf20Sopenharmony_ci	const u8 port = params->port;
6608c2ecf20Sopenharmony_ci	u32 base_upper_bound = 0;
6618c2ecf20Sopenharmony_ci	u8 max_cos = 0;
6628c2ecf20Sopenharmony_ci	u8 i = 0;
6638c2ecf20Sopenharmony_ci	/* In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
6648c2ecf20Sopenharmony_ci	 * port mode port1 has COS0-2 that can be used for WFQ.
6658c2ecf20Sopenharmony_ci	 */
6668c2ecf20Sopenharmony_ci	if (!port) {
6678c2ecf20Sopenharmony_ci		base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
6688c2ecf20Sopenharmony_ci		max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
6698c2ecf20Sopenharmony_ci	} else {
6708c2ecf20Sopenharmony_ci		base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
6718c2ecf20Sopenharmony_ci		max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
6728c2ecf20Sopenharmony_ci	}
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci	for (i = 0; i < max_cos; i++)
6758c2ecf20Sopenharmony_ci		REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
6768c2ecf20Sopenharmony_ci}
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci/******************************************************************************
6798c2ecf20Sopenharmony_ci* Description:
6808c2ecf20Sopenharmony_ci*	Will return the PBF ETS registers to init values.Except
6818c2ecf20Sopenharmony_ci*	credit_upper_bound.
6828c2ecf20Sopenharmony_ci*	That isn't used in this configuration (No WFQ is enabled) and will be
6838c2ecf20Sopenharmony_ci*	configured according to spec
6848c2ecf20Sopenharmony_ci*.
6858c2ecf20Sopenharmony_ci******************************************************************************/
6868c2ecf20Sopenharmony_cistatic void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
6878c2ecf20Sopenharmony_ci{
6888c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
6898c2ecf20Sopenharmony_ci	const u8 port = params->port;
6908c2ecf20Sopenharmony_ci	const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
6918c2ecf20Sopenharmony_ci	u8 i = 0;
6928c2ecf20Sopenharmony_ci	u32 base_weight = 0;
6938c2ecf20Sopenharmony_ci	u8 max_cos = 0;
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci	/* Mapping between entry  priority to client number 0 - COS0
6968c2ecf20Sopenharmony_ci	 * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
6978c2ecf20Sopenharmony_ci	 * TODO_ETS - Should be done by reset value or init tool
6988c2ecf20Sopenharmony_ci	 */
6998c2ecf20Sopenharmony_ci	if (port)
7008c2ecf20Sopenharmony_ci		/*  0x688 (|011|0 10|00 1|000) */
7018c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
7028c2ecf20Sopenharmony_ci	else
7038c2ecf20Sopenharmony_ci		/*  (10 1|100 |011|0 10|00 1|000) */
7048c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	/* TODO_ETS - Should be done by reset value or init tool */
7078c2ecf20Sopenharmony_ci	if (port)
7088c2ecf20Sopenharmony_ci		/* 0x688 (|011|0 10|00 1|000)*/
7098c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
7108c2ecf20Sopenharmony_ci	else
7118c2ecf20Sopenharmony_ci	/* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
7128c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
7158c2ecf20Sopenharmony_ci		   PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
7198c2ecf20Sopenharmony_ci		   PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
7228c2ecf20Sopenharmony_ci		   PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
7238c2ecf20Sopenharmony_ci	/* In 2 port mode port0 has COS0-5 that can be used for WFQ.
7248c2ecf20Sopenharmony_ci	 * In 4 port mode port1 has COS0-2 that can be used for WFQ.
7258c2ecf20Sopenharmony_ci	 */
7268c2ecf20Sopenharmony_ci	if (!port) {
7278c2ecf20Sopenharmony_ci		base_weight = PBF_REG_COS0_WEIGHT_P0;
7288c2ecf20Sopenharmony_ci		max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
7298c2ecf20Sopenharmony_ci	} else {
7308c2ecf20Sopenharmony_ci		base_weight = PBF_REG_COS0_WEIGHT_P1;
7318c2ecf20Sopenharmony_ci		max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
7328c2ecf20Sopenharmony_ci	}
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	for (i = 0; i < max_cos; i++)
7358c2ecf20Sopenharmony_ci		REG_WR(bp, base_weight + (0x4 * i), 0);
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
7388c2ecf20Sopenharmony_ci}
7398c2ecf20Sopenharmony_ci/******************************************************************************
7408c2ecf20Sopenharmony_ci* Description:
7418c2ecf20Sopenharmony_ci*	E3B0 disable will return basically the values to init values.
7428c2ecf20Sopenharmony_ci*.
7438c2ecf20Sopenharmony_ci******************************************************************************/
7448c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_disabled(const struct link_params *params,
7458c2ecf20Sopenharmony_ci				   const struct link_vars *vars)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3B0(bp)) {
7508c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
7518c2ecf20Sopenharmony_ci		   "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
7528c2ecf20Sopenharmony_ci		return -EINVAL;
7538c2ecf20Sopenharmony_ci	}
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_nig_disabled(params, vars);
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_pbf_disabled(params);
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_ci	return 0;
7608c2ecf20Sopenharmony_ci}
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci/******************************************************************************
7638c2ecf20Sopenharmony_ci* Description:
7648c2ecf20Sopenharmony_ci*	Disable will return basically the values to init values.
7658c2ecf20Sopenharmony_ci*
7668c2ecf20Sopenharmony_ci******************************************************************************/
7678c2ecf20Sopenharmony_ciint bnx2x_ets_disabled(struct link_params *params,
7688c2ecf20Sopenharmony_ci		      struct link_vars *vars)
7698c2ecf20Sopenharmony_ci{
7708c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
7718c2ecf20Sopenharmony_ci	int bnx2x_status = 0;
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci	if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
7748c2ecf20Sopenharmony_ci		bnx2x_ets_e2e3a0_disabled(params);
7758c2ecf20Sopenharmony_ci	else if (CHIP_IS_E3B0(bp))
7768c2ecf20Sopenharmony_ci		bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
7778c2ecf20Sopenharmony_ci	else {
7788c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
7798c2ecf20Sopenharmony_ci		return -EINVAL;
7808c2ecf20Sopenharmony_ci	}
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ci	return bnx2x_status;
7838c2ecf20Sopenharmony_ci}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci/******************************************************************************
7868c2ecf20Sopenharmony_ci* Description
7878c2ecf20Sopenharmony_ci*	Set the COS mappimg to SP and BW until this point all the COS are not
7888c2ecf20Sopenharmony_ci*	set as SP or BW.
7898c2ecf20Sopenharmony_ci******************************************************************************/
7908c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
7918c2ecf20Sopenharmony_ci				  const struct bnx2x_ets_params *ets_params,
7928c2ecf20Sopenharmony_ci				  const u8 cos_sp_bitmap,
7938c2ecf20Sopenharmony_ci				  const u8 cos_bw_bitmap)
7948c2ecf20Sopenharmony_ci{
7958c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
7968c2ecf20Sopenharmony_ci	const u8 port = params->port;
7978c2ecf20Sopenharmony_ci	const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
7988c2ecf20Sopenharmony_ci	const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
7998c2ecf20Sopenharmony_ci	const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
8008c2ecf20Sopenharmony_ci	const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
8038c2ecf20Sopenharmony_ci	       NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
8068c2ecf20Sopenharmony_ci	       PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
8098c2ecf20Sopenharmony_ci	       NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
8108c2ecf20Sopenharmony_ci	       nig_cli_subject2wfq_bitmap);
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci	REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
8138c2ecf20Sopenharmony_ci	       PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
8148c2ecf20Sopenharmony_ci	       pbf_cli_subject2wfq_bitmap);
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	return 0;
8178c2ecf20Sopenharmony_ci}
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci/******************************************************************************
8208c2ecf20Sopenharmony_ci* Description:
8218c2ecf20Sopenharmony_ci*	This function is needed because NIG ARB_CREDIT_WEIGHT_X are
8228c2ecf20Sopenharmony_ci*	not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
8238c2ecf20Sopenharmony_ci******************************************************************************/
8248c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
8258c2ecf20Sopenharmony_ci				     const u8 cos_entry,
8268c2ecf20Sopenharmony_ci				     const u32 min_w_val_nig,
8278c2ecf20Sopenharmony_ci				     const u32 min_w_val_pbf,
8288c2ecf20Sopenharmony_ci				     const u16 total_bw,
8298c2ecf20Sopenharmony_ci				     const u8 bw,
8308c2ecf20Sopenharmony_ci				     const u8 port)
8318c2ecf20Sopenharmony_ci{
8328c2ecf20Sopenharmony_ci	u32 nig_reg_adress_crd_weight = 0;
8338c2ecf20Sopenharmony_ci	u32 pbf_reg_adress_crd_weight = 0;
8348c2ecf20Sopenharmony_ci	/* Calculate and set BW for this COS - use 1 instead of 0 for BW */
8358c2ecf20Sopenharmony_ci	const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
8368c2ecf20Sopenharmony_ci	const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci	switch (cos_entry) {
8398c2ecf20Sopenharmony_ci	case 0:
8408c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight =
8418c2ecf20Sopenharmony_ci			(port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
8428c2ecf20Sopenharmony_ci			NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
8438c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = (port) ?
8448c2ecf20Sopenharmony_ci		    PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
8458c2ecf20Sopenharmony_ci		break;
8468c2ecf20Sopenharmony_ci	case 1:
8478c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight = (port) ?
8488c2ecf20Sopenharmony_ci			NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
8498c2ecf20Sopenharmony_ci			NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
8508c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = (port) ?
8518c2ecf20Sopenharmony_ci			PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
8528c2ecf20Sopenharmony_ci		break;
8538c2ecf20Sopenharmony_ci	case 2:
8548c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight = (port) ?
8558c2ecf20Sopenharmony_ci			NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
8568c2ecf20Sopenharmony_ci			NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = (port) ?
8598c2ecf20Sopenharmony_ci			PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
8608c2ecf20Sopenharmony_ci		break;
8618c2ecf20Sopenharmony_ci	case 3:
8628c2ecf20Sopenharmony_ci		if (port)
8638c2ecf20Sopenharmony_ci			return -EINVAL;
8648c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight = NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
8658c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = PBF_REG_COS3_WEIGHT_P0;
8668c2ecf20Sopenharmony_ci		break;
8678c2ecf20Sopenharmony_ci	case 4:
8688c2ecf20Sopenharmony_ci		if (port)
8698c2ecf20Sopenharmony_ci			return -EINVAL;
8708c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight = NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
8718c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
8728c2ecf20Sopenharmony_ci		break;
8738c2ecf20Sopenharmony_ci	case 5:
8748c2ecf20Sopenharmony_ci		if (port)
8758c2ecf20Sopenharmony_ci			return -EINVAL;
8768c2ecf20Sopenharmony_ci		nig_reg_adress_crd_weight = NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
8778c2ecf20Sopenharmony_ci		pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
8788c2ecf20Sopenharmony_ci		break;
8798c2ecf20Sopenharmony_ci	}
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci	REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci	return 0;
8868c2ecf20Sopenharmony_ci}
8878c2ecf20Sopenharmony_ci/******************************************************************************
8888c2ecf20Sopenharmony_ci* Description:
8898c2ecf20Sopenharmony_ci*	Calculate the total BW.A value of 0 isn't legal.
8908c2ecf20Sopenharmony_ci*
8918c2ecf20Sopenharmony_ci******************************************************************************/
8928c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_get_total_bw(
8938c2ecf20Sopenharmony_ci	const struct link_params *params,
8948c2ecf20Sopenharmony_ci	struct bnx2x_ets_params *ets_params,
8958c2ecf20Sopenharmony_ci	u16 *total_bw)
8968c2ecf20Sopenharmony_ci{
8978c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
8988c2ecf20Sopenharmony_ci	u8 cos_idx = 0;
8998c2ecf20Sopenharmony_ci	u8 is_bw_cos_exist = 0;
9008c2ecf20Sopenharmony_ci
9018c2ecf20Sopenharmony_ci	*total_bw = 0 ;
9028c2ecf20Sopenharmony_ci	/* Calculate total BW requested */
9038c2ecf20Sopenharmony_ci	for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
9048c2ecf20Sopenharmony_ci		if (ets_params->cos[cos_idx].state == bnx2x_cos_state_bw) {
9058c2ecf20Sopenharmony_ci			is_bw_cos_exist = 1;
9068c2ecf20Sopenharmony_ci			if (!ets_params->cos[cos_idx].params.bw_params.bw) {
9078c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config BW"
9088c2ecf20Sopenharmony_ci						   "was set to 0\n");
9098c2ecf20Sopenharmony_ci				/* This is to prevent a state when ramrods
9108c2ecf20Sopenharmony_ci				 * can't be sent
9118c2ecf20Sopenharmony_ci				 */
9128c2ecf20Sopenharmony_ci				ets_params->cos[cos_idx].params.bw_params.bw
9138c2ecf20Sopenharmony_ci					 = 1;
9148c2ecf20Sopenharmony_ci			}
9158c2ecf20Sopenharmony_ci			*total_bw +=
9168c2ecf20Sopenharmony_ci				ets_params->cos[cos_idx].params.bw_params.bw;
9178c2ecf20Sopenharmony_ci		}
9188c2ecf20Sopenharmony_ci	}
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci	/* Check total BW is valid */
9218c2ecf20Sopenharmony_ci	if ((is_bw_cos_exist == 1) && (*total_bw != 100)) {
9228c2ecf20Sopenharmony_ci		if (*total_bw == 0) {
9238c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
9248c2ecf20Sopenharmony_ci			   "bnx2x_ets_E3B0_config total BW shouldn't be 0\n");
9258c2ecf20Sopenharmony_ci			return -EINVAL;
9268c2ecf20Sopenharmony_ci		}
9278c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
9288c2ecf20Sopenharmony_ci		   "bnx2x_ets_E3B0_config total BW should be 100\n");
9298c2ecf20Sopenharmony_ci		/* We can handle a case whre the BW isn't 100 this can happen
9308c2ecf20Sopenharmony_ci		 * if the TC are joined.
9318c2ecf20Sopenharmony_ci		 */
9328c2ecf20Sopenharmony_ci	}
9338c2ecf20Sopenharmony_ci	return 0;
9348c2ecf20Sopenharmony_ci}
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci/******************************************************************************
9378c2ecf20Sopenharmony_ci* Description:
9388c2ecf20Sopenharmony_ci*	Invalidate all the sp_pri_to_cos.
9398c2ecf20Sopenharmony_ci*
9408c2ecf20Sopenharmony_ci******************************************************************************/
9418c2ecf20Sopenharmony_cistatic void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
9428c2ecf20Sopenharmony_ci{
9438c2ecf20Sopenharmony_ci	u8 pri = 0;
9448c2ecf20Sopenharmony_ci	for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
9458c2ecf20Sopenharmony_ci		sp_pri_to_cos[pri] = DCBX_INVALID_COS;
9468c2ecf20Sopenharmony_ci}
9478c2ecf20Sopenharmony_ci/******************************************************************************
9488c2ecf20Sopenharmony_ci* Description:
9498c2ecf20Sopenharmony_ci*	Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
9508c2ecf20Sopenharmony_ci*	according to sp_pri_to_cos.
9518c2ecf20Sopenharmony_ci*
9528c2ecf20Sopenharmony_ci******************************************************************************/
9538c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
9548c2ecf20Sopenharmony_ci					    u8 *sp_pri_to_cos, const u8 pri,
9558c2ecf20Sopenharmony_ci					    const u8 cos_entry)
9568c2ecf20Sopenharmony_ci{
9578c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
9588c2ecf20Sopenharmony_ci	const u8 port = params->port;
9598c2ecf20Sopenharmony_ci	const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
9608c2ecf20Sopenharmony_ci		DCBX_E3B0_MAX_NUM_COS_PORT0;
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	if (pri >= max_num_of_cos) {
9638c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
9648c2ecf20Sopenharmony_ci		   "parameter Illegal strict priority\n");
9658c2ecf20Sopenharmony_ci		return -EINVAL;
9668c2ecf20Sopenharmony_ci	}
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci	if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
9698c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
9708c2ecf20Sopenharmony_ci				   "parameter There can't be two COS's with "
9718c2ecf20Sopenharmony_ci				   "the same strict pri\n");
9728c2ecf20Sopenharmony_ci		return -EINVAL;
9738c2ecf20Sopenharmony_ci	}
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci	sp_pri_to_cos[pri] = cos_entry;
9768c2ecf20Sopenharmony_ci	return 0;
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_ci}
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci/******************************************************************************
9818c2ecf20Sopenharmony_ci* Description:
9828c2ecf20Sopenharmony_ci*	Returns the correct value according to COS and priority in
9838c2ecf20Sopenharmony_ci*	the sp_pri_cli register.
9848c2ecf20Sopenharmony_ci*
9858c2ecf20Sopenharmony_ci******************************************************************************/
9868c2ecf20Sopenharmony_cistatic u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
9878c2ecf20Sopenharmony_ci					 const u8 pri_set,
9888c2ecf20Sopenharmony_ci					 const u8 pri_offset,
9898c2ecf20Sopenharmony_ci					 const u8 entry_size)
9908c2ecf20Sopenharmony_ci{
9918c2ecf20Sopenharmony_ci	u64 pri_cli_nig = 0;
9928c2ecf20Sopenharmony_ci	pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
9938c2ecf20Sopenharmony_ci						    (pri_set + pri_offset));
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci	return pri_cli_nig;
9968c2ecf20Sopenharmony_ci}
9978c2ecf20Sopenharmony_ci/******************************************************************************
9988c2ecf20Sopenharmony_ci* Description:
9998c2ecf20Sopenharmony_ci*	Returns the correct value according to COS and priority in the
10008c2ecf20Sopenharmony_ci*	sp_pri_cli register for NIG.
10018c2ecf20Sopenharmony_ci*
10028c2ecf20Sopenharmony_ci******************************************************************************/
10038c2ecf20Sopenharmony_cistatic u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
10048c2ecf20Sopenharmony_ci{
10058c2ecf20Sopenharmony_ci	/* MCP Dbg0 and dbg1 are always with higher strict pri*/
10068c2ecf20Sopenharmony_ci	const u8 nig_cos_offset = 3;
10078c2ecf20Sopenharmony_ci	const u8 nig_pri_offset = 3;
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci	return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
10108c2ecf20Sopenharmony_ci		nig_pri_offset, 4);
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci}
10138c2ecf20Sopenharmony_ci/******************************************************************************
10148c2ecf20Sopenharmony_ci* Description:
10158c2ecf20Sopenharmony_ci*	Returns the correct value according to COS and priority in the
10168c2ecf20Sopenharmony_ci*	sp_pri_cli register for PBF.
10178c2ecf20Sopenharmony_ci*
10188c2ecf20Sopenharmony_ci******************************************************************************/
10198c2ecf20Sopenharmony_cistatic u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
10208c2ecf20Sopenharmony_ci{
10218c2ecf20Sopenharmony_ci	const u8 pbf_cos_offset = 0;
10228c2ecf20Sopenharmony_ci	const u8 pbf_pri_offset = 0;
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci	return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
10258c2ecf20Sopenharmony_ci		pbf_pri_offset, 3);
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci}
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci/******************************************************************************
10308c2ecf20Sopenharmony_ci* Description:
10318c2ecf20Sopenharmony_ci*	Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
10328c2ecf20Sopenharmony_ci*	according to sp_pri_to_cos.(which COS has higher priority)
10338c2ecf20Sopenharmony_ci*
10348c2ecf20Sopenharmony_ci******************************************************************************/
10358c2ecf20Sopenharmony_cistatic int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
10368c2ecf20Sopenharmony_ci					     u8 *sp_pri_to_cos)
10378c2ecf20Sopenharmony_ci{
10388c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
10398c2ecf20Sopenharmony_ci	u8 i = 0;
10408c2ecf20Sopenharmony_ci	const u8 port = params->port;
10418c2ecf20Sopenharmony_ci	/* MCP Dbg0 and dbg1 are always with higher strict pri*/
10428c2ecf20Sopenharmony_ci	u64 pri_cli_nig = 0x210;
10438c2ecf20Sopenharmony_ci	u32 pri_cli_pbf = 0x0;
10448c2ecf20Sopenharmony_ci	u8 pri_set = 0;
10458c2ecf20Sopenharmony_ci	u8 pri_bitmask = 0;
10468c2ecf20Sopenharmony_ci	const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
10478c2ecf20Sopenharmony_ci		DCBX_E3B0_MAX_NUM_COS_PORT0;
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_ci	u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
10508c2ecf20Sopenharmony_ci
10518c2ecf20Sopenharmony_ci	/* Set all the strict priority first */
10528c2ecf20Sopenharmony_ci	for (i = 0; i < max_num_of_cos; i++) {
10538c2ecf20Sopenharmony_ci		if (sp_pri_to_cos[i] != DCBX_INVALID_COS) {
10548c2ecf20Sopenharmony_ci			if (sp_pri_to_cos[i] >= DCBX_MAX_NUM_COS) {
10558c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
10568c2ecf20Sopenharmony_ci					   "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
10578c2ecf20Sopenharmony_ci					   "invalid cos entry\n");
10588c2ecf20Sopenharmony_ci				return -EINVAL;
10598c2ecf20Sopenharmony_ci			}
10608c2ecf20Sopenharmony_ci
10618c2ecf20Sopenharmony_ci			pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
10628c2ecf20Sopenharmony_ci			    sp_pri_to_cos[i], pri_set);
10638c2ecf20Sopenharmony_ci
10648c2ecf20Sopenharmony_ci			pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
10658c2ecf20Sopenharmony_ci			    sp_pri_to_cos[i], pri_set);
10668c2ecf20Sopenharmony_ci			pri_bitmask = 1 << sp_pri_to_cos[i];
10678c2ecf20Sopenharmony_ci			/* COS is used remove it from bitmap.*/
10688c2ecf20Sopenharmony_ci			if (!(pri_bitmask & cos_bit_to_set)) {
10698c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
10708c2ecf20Sopenharmony_ci					"bnx2x_ets_e3b0_sp_set_pri_cli_reg "
10718c2ecf20Sopenharmony_ci					"invalid There can't be two COS's with"
10728c2ecf20Sopenharmony_ci					" the same strict pri\n");
10738c2ecf20Sopenharmony_ci				return -EINVAL;
10748c2ecf20Sopenharmony_ci			}
10758c2ecf20Sopenharmony_ci			cos_bit_to_set &= ~pri_bitmask;
10768c2ecf20Sopenharmony_ci			pri_set++;
10778c2ecf20Sopenharmony_ci		}
10788c2ecf20Sopenharmony_ci	}
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci	/* Set all the Non strict priority i= COS*/
10818c2ecf20Sopenharmony_ci	for (i = 0; i < max_num_of_cos; i++) {
10828c2ecf20Sopenharmony_ci		pri_bitmask = 1 << i;
10838c2ecf20Sopenharmony_ci		/* Check if COS was already used for SP */
10848c2ecf20Sopenharmony_ci		if (pri_bitmask & cos_bit_to_set) {
10858c2ecf20Sopenharmony_ci			/* COS wasn't used for SP */
10868c2ecf20Sopenharmony_ci			pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
10878c2ecf20Sopenharmony_ci			    i, pri_set);
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci			pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
10908c2ecf20Sopenharmony_ci			    i, pri_set);
10918c2ecf20Sopenharmony_ci			/* COS is used remove it from bitmap.*/
10928c2ecf20Sopenharmony_ci			cos_bit_to_set &= ~pri_bitmask;
10938c2ecf20Sopenharmony_ci			pri_set++;
10948c2ecf20Sopenharmony_ci		}
10958c2ecf20Sopenharmony_ci	}
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_ci	if (pri_set != max_num_of_cos) {
10988c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
10998c2ecf20Sopenharmony_ci				   "entries were set\n");
11008c2ecf20Sopenharmony_ci		return -EINVAL;
11018c2ecf20Sopenharmony_ci	}
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	if (port) {
11048c2ecf20Sopenharmony_ci		/* Only 6 usable clients*/
11058c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
11068c2ecf20Sopenharmony_ci		       (u32)pri_cli_nig);
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
11098c2ecf20Sopenharmony_ci	} else {
11108c2ecf20Sopenharmony_ci		/* Only 9 usable clients*/
11118c2ecf20Sopenharmony_ci		const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
11128c2ecf20Sopenharmony_ci		const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
11158c2ecf20Sopenharmony_ci		       pri_cli_nig_lsb);
11168c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
11178c2ecf20Sopenharmony_ci		       pri_cli_nig_msb);
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
11208c2ecf20Sopenharmony_ci	}
11218c2ecf20Sopenharmony_ci	return 0;
11228c2ecf20Sopenharmony_ci}
11238c2ecf20Sopenharmony_ci
11248c2ecf20Sopenharmony_ci/******************************************************************************
11258c2ecf20Sopenharmony_ci* Description:
11268c2ecf20Sopenharmony_ci*	Configure the COS to ETS according to BW and SP settings.
11278c2ecf20Sopenharmony_ci******************************************************************************/
11288c2ecf20Sopenharmony_ciint bnx2x_ets_e3b0_config(const struct link_params *params,
11298c2ecf20Sopenharmony_ci			 const struct link_vars *vars,
11308c2ecf20Sopenharmony_ci			 struct bnx2x_ets_params *ets_params)
11318c2ecf20Sopenharmony_ci{
11328c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
11338c2ecf20Sopenharmony_ci	int bnx2x_status = 0;
11348c2ecf20Sopenharmony_ci	const u8 port = params->port;
11358c2ecf20Sopenharmony_ci	u16 total_bw = 0;
11368c2ecf20Sopenharmony_ci	const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
11378c2ecf20Sopenharmony_ci	const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
11388c2ecf20Sopenharmony_ci	u8 cos_bw_bitmap = 0;
11398c2ecf20Sopenharmony_ci	u8 cos_sp_bitmap = 0;
11408c2ecf20Sopenharmony_ci	u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
11418c2ecf20Sopenharmony_ci	const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
11428c2ecf20Sopenharmony_ci		DCBX_E3B0_MAX_NUM_COS_PORT0;
11438c2ecf20Sopenharmony_ci	u8 cos_entry = 0;
11448c2ecf20Sopenharmony_ci
11458c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3B0(bp)) {
11468c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
11478c2ecf20Sopenharmony_ci		   "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
11488c2ecf20Sopenharmony_ci		return -EINVAL;
11498c2ecf20Sopenharmony_ci	}
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci	if ((ets_params->num_of_cos > max_num_of_cos)) {
11528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
11538c2ecf20Sopenharmony_ci				   "isn't supported\n");
11548c2ecf20Sopenharmony_ci		return -EINVAL;
11558c2ecf20Sopenharmony_ci	}
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci	/* Prepare sp strict priority parameters*/
11588c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_ci	/* Prepare BW parameters*/
11618c2ecf20Sopenharmony_ci	bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
11628c2ecf20Sopenharmony_ci						   &total_bw);
11638c2ecf20Sopenharmony_ci	if (bnx2x_status) {
11648c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
11658c2ecf20Sopenharmony_ci		   "bnx2x_ets_E3B0_config get_total_bw failed\n");
11668c2ecf20Sopenharmony_ci		return -EINVAL;
11678c2ecf20Sopenharmony_ci	}
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci	/* Upper bound is set according to current link speed (min_w_val
11708c2ecf20Sopenharmony_ci	 * should be the same for upper bound and COS credit val).
11718c2ecf20Sopenharmony_ci	 */
11728c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
11738c2ecf20Sopenharmony_ci	bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci
11768c2ecf20Sopenharmony_ci	for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
11778c2ecf20Sopenharmony_ci		if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
11788c2ecf20Sopenharmony_ci			cos_bw_bitmap |= (1 << cos_entry);
11798c2ecf20Sopenharmony_ci			/* The function also sets the BW in HW(not the mappin
11808c2ecf20Sopenharmony_ci			 * yet)
11818c2ecf20Sopenharmony_ci			 */
11828c2ecf20Sopenharmony_ci			bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
11838c2ecf20Sopenharmony_ci				bp, cos_entry, min_w_val_nig, min_w_val_pbf,
11848c2ecf20Sopenharmony_ci				total_bw,
11858c2ecf20Sopenharmony_ci				ets_params->cos[cos_entry].params.bw_params.bw,
11868c2ecf20Sopenharmony_ci				 port);
11878c2ecf20Sopenharmony_ci		} else if (bnx2x_cos_state_strict ==
11888c2ecf20Sopenharmony_ci			ets_params->cos[cos_entry].state){
11898c2ecf20Sopenharmony_ci			cos_sp_bitmap |= (1 << cos_entry);
11908c2ecf20Sopenharmony_ci
11918c2ecf20Sopenharmony_ci			bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
11928c2ecf20Sopenharmony_ci				params,
11938c2ecf20Sopenharmony_ci				sp_pri_to_cos,
11948c2ecf20Sopenharmony_ci				ets_params->cos[cos_entry].params.sp_params.pri,
11958c2ecf20Sopenharmony_ci				cos_entry);
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci		} else {
11988c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
11998c2ecf20Sopenharmony_ci			   "bnx2x_ets_e3b0_config cos state not valid\n");
12008c2ecf20Sopenharmony_ci			return -EINVAL;
12018c2ecf20Sopenharmony_ci		}
12028c2ecf20Sopenharmony_ci		if (bnx2x_status) {
12038c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
12048c2ecf20Sopenharmony_ci			   "bnx2x_ets_e3b0_config set cos bw failed\n");
12058c2ecf20Sopenharmony_ci			return bnx2x_status;
12068c2ecf20Sopenharmony_ci		}
12078c2ecf20Sopenharmony_ci	}
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_ci	/* Set SP register (which COS has higher priority) */
12108c2ecf20Sopenharmony_ci	bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
12118c2ecf20Sopenharmony_ci							 sp_pri_to_cos);
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci	if (bnx2x_status) {
12148c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
12158c2ecf20Sopenharmony_ci		   "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
12168c2ecf20Sopenharmony_ci		return bnx2x_status;
12178c2ecf20Sopenharmony_ci	}
12188c2ecf20Sopenharmony_ci
12198c2ecf20Sopenharmony_ci	/* Set client mapping of BW and strict */
12208c2ecf20Sopenharmony_ci	bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
12218c2ecf20Sopenharmony_ci					      cos_sp_bitmap,
12228c2ecf20Sopenharmony_ci					      cos_bw_bitmap);
12238c2ecf20Sopenharmony_ci
12248c2ecf20Sopenharmony_ci	if (bnx2x_status) {
12258c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
12268c2ecf20Sopenharmony_ci		return bnx2x_status;
12278c2ecf20Sopenharmony_ci	}
12288c2ecf20Sopenharmony_ci	return 0;
12298c2ecf20Sopenharmony_ci}
12308c2ecf20Sopenharmony_cistatic void bnx2x_ets_bw_limit_common(const struct link_params *params)
12318c2ecf20Sopenharmony_ci{
12328c2ecf20Sopenharmony_ci	/* ETS disabled configuration */
12338c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
12348c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
12358c2ecf20Sopenharmony_ci	/* Defines which entries (clients) are subjected to WFQ arbitration
12368c2ecf20Sopenharmony_ci	 * COS0 0x8
12378c2ecf20Sopenharmony_ci	 * COS1 0x10
12388c2ecf20Sopenharmony_ci	 */
12398c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
12408c2ecf20Sopenharmony_ci	/* Mapping between the ARB_CREDIT_WEIGHT registers and actual
12418c2ecf20Sopenharmony_ci	 * client numbers (WEIGHT_0 does not actually have to represent
12428c2ecf20Sopenharmony_ci	 * client 0)
12438c2ecf20Sopenharmony_ci	 *    PRI4    |    PRI3    |    PRI2    |    PRI1    |    PRI0
12448c2ecf20Sopenharmony_ci	 *  cos1-001     cos0-000     dbg1-100     dbg0-011     MCP-010
12458c2ecf20Sopenharmony_ci	 */
12468c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
12478c2ecf20Sopenharmony_ci
12488c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
12498c2ecf20Sopenharmony_ci	       ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
12508c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
12518c2ecf20Sopenharmony_ci	       ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
12528c2ecf20Sopenharmony_ci
12538c2ecf20Sopenharmony_ci	/* ETS mode enabled*/
12548c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci	/* Defines the number of consecutive slots for the strict priority */
12578c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
12588c2ecf20Sopenharmony_ci	/* Bitmap of 5bits length. Each bit specifies whether the entry behaves
12598c2ecf20Sopenharmony_ci	 * as strict.  Bits 0,1,2 - debug and management entries, 3 - COS0
12608c2ecf20Sopenharmony_ci	 * entry, 4 - COS1 entry.
12618c2ecf20Sopenharmony_ci	 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
12628c2ecf20Sopenharmony_ci	 * bit4   bit3	  bit2     bit1	   bit0
12638c2ecf20Sopenharmony_ci	 * MCP and debug are strict
12648c2ecf20Sopenharmony_ci	 */
12658c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
12668c2ecf20Sopenharmony_ci
12678c2ecf20Sopenharmony_ci	/* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
12688c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
12698c2ecf20Sopenharmony_ci	       ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
12708c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
12718c2ecf20Sopenharmony_ci	       ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
12728c2ecf20Sopenharmony_ci}
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_civoid bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
12758c2ecf20Sopenharmony_ci			const u32 cos1_bw)
12768c2ecf20Sopenharmony_ci{
12778c2ecf20Sopenharmony_ci	/* ETS disabled configuration*/
12788c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
12798c2ecf20Sopenharmony_ci	const u32 total_bw = cos0_bw + cos1_bw;
12808c2ecf20Sopenharmony_ci	u32 cos0_credit_weight = 0;
12818c2ecf20Sopenharmony_ci	u32 cos1_credit_weight = 0;
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
12848c2ecf20Sopenharmony_ci
12858c2ecf20Sopenharmony_ci	if ((!total_bw) ||
12868c2ecf20Sopenharmony_ci	    (!cos0_bw) ||
12878c2ecf20Sopenharmony_ci	    (!cos1_bw)) {
12888c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
12898c2ecf20Sopenharmony_ci		return;
12908c2ecf20Sopenharmony_ci	}
12918c2ecf20Sopenharmony_ci
12928c2ecf20Sopenharmony_ci	cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
12938c2ecf20Sopenharmony_ci		total_bw;
12948c2ecf20Sopenharmony_ci	cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
12958c2ecf20Sopenharmony_ci		total_bw;
12968c2ecf20Sopenharmony_ci
12978c2ecf20Sopenharmony_ci	bnx2x_ets_bw_limit_common(params);
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
13008c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
13018c2ecf20Sopenharmony_ci
13028c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
13038c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
13048c2ecf20Sopenharmony_ci}
13058c2ecf20Sopenharmony_ci
13068c2ecf20Sopenharmony_ciint bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
13078c2ecf20Sopenharmony_ci{
13088c2ecf20Sopenharmony_ci	/* ETS disabled configuration*/
13098c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
13108c2ecf20Sopenharmony_ci	u32 val	= 0;
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
13138c2ecf20Sopenharmony_ci	/* Bitmap of 5bits length. Each bit specifies whether the entry behaves
13148c2ecf20Sopenharmony_ci	 * as strict.  Bits 0,1,2 - debug and management entries,
13158c2ecf20Sopenharmony_ci	 * 3 - COS0 entry, 4 - COS1 entry.
13168c2ecf20Sopenharmony_ci	 *  COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
13178c2ecf20Sopenharmony_ci	 *  bit4   bit3	  bit2      bit1     bit0
13188c2ecf20Sopenharmony_ci	 * MCP and debug are strict
13198c2ecf20Sopenharmony_ci	 */
13208c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
13218c2ecf20Sopenharmony_ci	/* For strict priority entries defines the number of consecutive slots
13228c2ecf20Sopenharmony_ci	 * for the highest priority.
13238c2ecf20Sopenharmony_ci	 */
13248c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
13258c2ecf20Sopenharmony_ci	/* ETS mode disable */
13268c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
13278c2ecf20Sopenharmony_ci	/* Defines the number of consecutive slots for the strict priority */
13288c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
13298c2ecf20Sopenharmony_ci
13308c2ecf20Sopenharmony_ci	/* Defines the number of consecutive slots for the strict priority */
13318c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	/* Mapping between entry  priority to client number (0,1,2 -debug and
13348c2ecf20Sopenharmony_ci	 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
13358c2ecf20Sopenharmony_ci	 * 3bits client num.
13368c2ecf20Sopenharmony_ci	 *   PRI4    |    PRI3    |    PRI2    |    PRI1    |    PRI0
13378c2ecf20Sopenharmony_ci	 * dbg0-010     dbg1-001     cos1-100     cos0-011     MCP-000
13388c2ecf20Sopenharmony_ci	 * dbg0-010     dbg1-001     cos0-011     cos1-100     MCP-000
13398c2ecf20Sopenharmony_ci	 */
13408c2ecf20Sopenharmony_ci	val = (!strict_cos) ? 0x2318 : 0x22E0;
13418c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	return 0;
13448c2ecf20Sopenharmony_ci}
13458c2ecf20Sopenharmony_ci
13468c2ecf20Sopenharmony_ci/******************************************************************/
13478c2ecf20Sopenharmony_ci/*			PFC section				  */
13488c2ecf20Sopenharmony_ci/******************************************************************/
13498c2ecf20Sopenharmony_cistatic void bnx2x_update_pfc_xmac(struct link_params *params,
13508c2ecf20Sopenharmony_ci				  struct link_vars *vars,
13518c2ecf20Sopenharmony_ci				  u8 is_lb)
13528c2ecf20Sopenharmony_ci{
13538c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
13548c2ecf20Sopenharmony_ci	u32 xmac_base;
13558c2ecf20Sopenharmony_ci	u32 pause_val, pfc0_val, pfc1_val;
13568c2ecf20Sopenharmony_ci
13578c2ecf20Sopenharmony_ci	/* XMAC base adrr */
13588c2ecf20Sopenharmony_ci	xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci	/* Initialize pause and pfc registers */
13618c2ecf20Sopenharmony_ci	pause_val = 0x18000;
13628c2ecf20Sopenharmony_ci	pfc0_val = 0xFFFF8000;
13638c2ecf20Sopenharmony_ci	pfc1_val = 0x2;
13648c2ecf20Sopenharmony_ci
13658c2ecf20Sopenharmony_ci	/* No PFC support */
13668c2ecf20Sopenharmony_ci	if (!(params->feature_config_flags &
13678c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED)) {
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci		/* RX flow control - Process pause frame in receive direction
13708c2ecf20Sopenharmony_ci		 */
13718c2ecf20Sopenharmony_ci		if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
13728c2ecf20Sopenharmony_ci			pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci		/* TX flow control - Send pause packet when buffer is full */
13758c2ecf20Sopenharmony_ci		if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
13768c2ecf20Sopenharmony_ci			pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
13778c2ecf20Sopenharmony_ci	} else {/* PFC support */
13788c2ecf20Sopenharmony_ci		pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
13798c2ecf20Sopenharmony_ci			XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
13808c2ecf20Sopenharmony_ci			XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
13818c2ecf20Sopenharmony_ci			XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
13828c2ecf20Sopenharmony_ci			XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
13838c2ecf20Sopenharmony_ci		/* Write pause and PFC registers */
13848c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
13858c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
13868c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
13878c2ecf20Sopenharmony_ci		pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
13888c2ecf20Sopenharmony_ci
13898c2ecf20Sopenharmony_ci	}
13908c2ecf20Sopenharmony_ci
13918c2ecf20Sopenharmony_ci	/* Write pause and PFC registers */
13928c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
13938c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
13948c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
13958c2ecf20Sopenharmony_ci
13968c2ecf20Sopenharmony_ci
13978c2ecf20Sopenharmony_ci	/* Set MAC address for source TX Pause/PFC frames */
13988c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
13998c2ecf20Sopenharmony_ci	       ((params->mac_addr[2] << 24) |
14008c2ecf20Sopenharmony_ci		(params->mac_addr[3] << 16) |
14018c2ecf20Sopenharmony_ci		(params->mac_addr[4] << 8) |
14028c2ecf20Sopenharmony_ci		(params->mac_addr[5])));
14038c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
14048c2ecf20Sopenharmony_ci	       ((params->mac_addr[0] << 8) |
14058c2ecf20Sopenharmony_ci		(params->mac_addr[1])));
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci	udelay(30);
14088c2ecf20Sopenharmony_ci}
14098c2ecf20Sopenharmony_ci
14108c2ecf20Sopenharmony_ci/******************************************************************/
14118c2ecf20Sopenharmony_ci/*			MAC/PBF section				  */
14128c2ecf20Sopenharmony_ci/******************************************************************/
14138c2ecf20Sopenharmony_cistatic void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id,
14148c2ecf20Sopenharmony_ci			       u32 emac_base)
14158c2ecf20Sopenharmony_ci{
14168c2ecf20Sopenharmony_ci	u32 new_mode, cur_mode;
14178c2ecf20Sopenharmony_ci	u32 clc_cnt;
14188c2ecf20Sopenharmony_ci	/* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
14198c2ecf20Sopenharmony_ci	 * (a value of 49==0x31) and make sure that the AUTO poll is off
14208c2ecf20Sopenharmony_ci	 */
14218c2ecf20Sopenharmony_ci	cur_mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci	if (USES_WARPCORE(bp))
14248c2ecf20Sopenharmony_ci		clc_cnt = 74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
14258c2ecf20Sopenharmony_ci	else
14268c2ecf20Sopenharmony_ci		clc_cnt = 49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
14278c2ecf20Sopenharmony_ci
14288c2ecf20Sopenharmony_ci	if (((cur_mode & EMAC_MDIO_MODE_CLOCK_CNT) == clc_cnt) &&
14298c2ecf20Sopenharmony_ci	    (cur_mode & (EMAC_MDIO_MODE_CLAUSE_45)))
14308c2ecf20Sopenharmony_ci		return;
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci	new_mode = cur_mode &
14338c2ecf20Sopenharmony_ci		~(EMAC_MDIO_MODE_AUTO_POLL | EMAC_MDIO_MODE_CLOCK_CNT);
14348c2ecf20Sopenharmony_ci	new_mode |= clc_cnt;
14358c2ecf20Sopenharmony_ci	new_mode |= (EMAC_MDIO_MODE_CLAUSE_45);
14368c2ecf20Sopenharmony_ci
14378c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Changing emac_mode from 0x%x to 0x%x\n",
14388c2ecf20Sopenharmony_ci	   cur_mode, new_mode);
14398c2ecf20Sopenharmony_ci	REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, new_mode);
14408c2ecf20Sopenharmony_ci	udelay(40);
14418c2ecf20Sopenharmony_ci}
14428c2ecf20Sopenharmony_ci
14438c2ecf20Sopenharmony_cistatic void bnx2x_set_mdio_emac_per_phy(struct bnx2x *bp,
14448c2ecf20Sopenharmony_ci					struct link_params *params)
14458c2ecf20Sopenharmony_ci{
14468c2ecf20Sopenharmony_ci	u8 phy_index;
14478c2ecf20Sopenharmony_ci	/* Set mdio clock per phy */
14488c2ecf20Sopenharmony_ci	for (phy_index = INT_PHY; phy_index < params->num_phys;
14498c2ecf20Sopenharmony_ci	      phy_index++)
14508c2ecf20Sopenharmony_ci		bnx2x_set_mdio_clk(bp, params->chip_id,
14518c2ecf20Sopenharmony_ci				   params->phy[phy_index].mdio_ctrl);
14528c2ecf20Sopenharmony_ci}
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_cistatic u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
14558c2ecf20Sopenharmony_ci{
14568c2ecf20Sopenharmony_ci	u32 port4mode_ovwr_val;
14578c2ecf20Sopenharmony_ci	/* Check 4-port override enabled */
14588c2ecf20Sopenharmony_ci	port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
14598c2ecf20Sopenharmony_ci	if (port4mode_ovwr_val & (1<<0)) {
14608c2ecf20Sopenharmony_ci		/* Return 4-port mode override value */
14618c2ecf20Sopenharmony_ci		return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
14628c2ecf20Sopenharmony_ci	}
14638c2ecf20Sopenharmony_ci	/* Return 4-port mode from input pin */
14648c2ecf20Sopenharmony_ci	return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
14658c2ecf20Sopenharmony_ci}
14668c2ecf20Sopenharmony_ci
14678c2ecf20Sopenharmony_cistatic void bnx2x_emac_init(struct link_params *params,
14688c2ecf20Sopenharmony_ci			    struct link_vars *vars)
14698c2ecf20Sopenharmony_ci{
14708c2ecf20Sopenharmony_ci	/* reset and unreset the emac core */
14718c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
14728c2ecf20Sopenharmony_ci	u8 port = params->port;
14738c2ecf20Sopenharmony_ci	u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
14748c2ecf20Sopenharmony_ci	u32 val;
14758c2ecf20Sopenharmony_ci	u16 timeout;
14768c2ecf20Sopenharmony_ci
14778c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
14788c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
14798c2ecf20Sopenharmony_ci	udelay(5);
14808c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
14818c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
14828c2ecf20Sopenharmony_ci
14838c2ecf20Sopenharmony_ci	/* init emac - use read-modify-write */
14848c2ecf20Sopenharmony_ci	/* self clear reset */
14858c2ecf20Sopenharmony_ci	val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
14868c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
14878c2ecf20Sopenharmony_ci
14888c2ecf20Sopenharmony_ci	timeout = 200;
14898c2ecf20Sopenharmony_ci	do {
14908c2ecf20Sopenharmony_ci		val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
14918c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
14928c2ecf20Sopenharmony_ci		if (!timeout) {
14938c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "EMAC timeout!\n");
14948c2ecf20Sopenharmony_ci			return;
14958c2ecf20Sopenharmony_ci		}
14968c2ecf20Sopenharmony_ci		timeout--;
14978c2ecf20Sopenharmony_ci	} while (val & EMAC_MODE_RESET);
14988c2ecf20Sopenharmony_ci
14998c2ecf20Sopenharmony_ci	bnx2x_set_mdio_emac_per_phy(bp, params);
15008c2ecf20Sopenharmony_ci	/* Set mac address */
15018c2ecf20Sopenharmony_ci	val = ((params->mac_addr[0] << 8) |
15028c2ecf20Sopenharmony_ci		params->mac_addr[1]);
15038c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
15048c2ecf20Sopenharmony_ci
15058c2ecf20Sopenharmony_ci	val = ((params->mac_addr[2] << 24) |
15068c2ecf20Sopenharmony_ci	       (params->mac_addr[3] << 16) |
15078c2ecf20Sopenharmony_ci	       (params->mac_addr[4] << 8) |
15088c2ecf20Sopenharmony_ci		params->mac_addr[5]);
15098c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
15108c2ecf20Sopenharmony_ci}
15118c2ecf20Sopenharmony_ci
15128c2ecf20Sopenharmony_cistatic void bnx2x_set_xumac_nig(struct link_params *params,
15138c2ecf20Sopenharmony_ci				u16 tx_pause_en,
15148c2ecf20Sopenharmony_ci				u8 enable)
15158c2ecf20Sopenharmony_ci{
15168c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_ci	REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
15198c2ecf20Sopenharmony_ci	       enable);
15208c2ecf20Sopenharmony_ci	REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
15218c2ecf20Sopenharmony_ci	       enable);
15228c2ecf20Sopenharmony_ci	REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
15238c2ecf20Sopenharmony_ci	       NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
15248c2ecf20Sopenharmony_ci}
15258c2ecf20Sopenharmony_ci
15268c2ecf20Sopenharmony_cistatic void bnx2x_set_umac_rxtx(struct link_params *params, u8 en)
15278c2ecf20Sopenharmony_ci{
15288c2ecf20Sopenharmony_ci	u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15298c2ecf20Sopenharmony_ci	u32 val;
15308c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
15318c2ecf20Sopenharmony_ci	if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
15328c2ecf20Sopenharmony_ci		   (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
15338c2ecf20Sopenharmony_ci		return;
15348c2ecf20Sopenharmony_ci	val = REG_RD(bp, umac_base + UMAC_REG_COMMAND_CONFIG);
15358c2ecf20Sopenharmony_ci	if (en)
15368c2ecf20Sopenharmony_ci		val |= (UMAC_COMMAND_CONFIG_REG_TX_ENA |
15378c2ecf20Sopenharmony_ci			UMAC_COMMAND_CONFIG_REG_RX_ENA);
15388c2ecf20Sopenharmony_ci	else
15398c2ecf20Sopenharmony_ci		val &= ~(UMAC_COMMAND_CONFIG_REG_TX_ENA |
15408c2ecf20Sopenharmony_ci			 UMAC_COMMAND_CONFIG_REG_RX_ENA);
15418c2ecf20Sopenharmony_ci	/* Disable RX and TX */
15428c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
15438c2ecf20Sopenharmony_ci}
15448c2ecf20Sopenharmony_ci
15458c2ecf20Sopenharmony_cistatic void bnx2x_umac_enable(struct link_params *params,
15468c2ecf20Sopenharmony_ci			    struct link_vars *vars, u8 lb)
15478c2ecf20Sopenharmony_ci{
15488c2ecf20Sopenharmony_ci	u32 val;
15498c2ecf20Sopenharmony_ci	u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
15508c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
15518c2ecf20Sopenharmony_ci	/* Reset UMAC */
15528c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
15538c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
15548c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
15558c2ecf20Sopenharmony_ci
15568c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
15578c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "enabling UMAC\n");
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_ci	/* This register opens the gate for the UMAC despite its name */
15628c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
15638c2ecf20Sopenharmony_ci
15648c2ecf20Sopenharmony_ci	val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
15658c2ecf20Sopenharmony_ci		UMAC_COMMAND_CONFIG_REG_PAD_EN |
15668c2ecf20Sopenharmony_ci		UMAC_COMMAND_CONFIG_REG_SW_RESET |
15678c2ecf20Sopenharmony_ci		UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
15688c2ecf20Sopenharmony_ci	switch (vars->line_speed) {
15698c2ecf20Sopenharmony_ci	case SPEED_10:
15708c2ecf20Sopenharmony_ci		val |= (0<<2);
15718c2ecf20Sopenharmony_ci		break;
15728c2ecf20Sopenharmony_ci	case SPEED_100:
15738c2ecf20Sopenharmony_ci		val |= (1<<2);
15748c2ecf20Sopenharmony_ci		break;
15758c2ecf20Sopenharmony_ci	case SPEED_1000:
15768c2ecf20Sopenharmony_ci		val |= (2<<2);
15778c2ecf20Sopenharmony_ci		break;
15788c2ecf20Sopenharmony_ci	case SPEED_2500:
15798c2ecf20Sopenharmony_ci		val |= (3<<2);
15808c2ecf20Sopenharmony_ci		break;
15818c2ecf20Sopenharmony_ci	default:
15828c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
15838c2ecf20Sopenharmony_ci			       vars->line_speed);
15848c2ecf20Sopenharmony_ci		break;
15858c2ecf20Sopenharmony_ci	}
15868c2ecf20Sopenharmony_ci	if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
15878c2ecf20Sopenharmony_ci		val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
15888c2ecf20Sopenharmony_ci
15898c2ecf20Sopenharmony_ci	if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
15908c2ecf20Sopenharmony_ci		val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
15918c2ecf20Sopenharmony_ci
15928c2ecf20Sopenharmony_ci	if (vars->duplex == DUPLEX_HALF)
15938c2ecf20Sopenharmony_ci		val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
15948c2ecf20Sopenharmony_ci
15958c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
15968c2ecf20Sopenharmony_ci	udelay(50);
15978c2ecf20Sopenharmony_ci
15988c2ecf20Sopenharmony_ci	/* Configure UMAC for EEE */
15998c2ecf20Sopenharmony_ci	if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
16008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "configured UMAC for EEE\n");
16018c2ecf20Sopenharmony_ci		REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL,
16028c2ecf20Sopenharmony_ci		       UMAC_UMAC_EEE_CTRL_REG_EEE_EN);
16038c2ecf20Sopenharmony_ci		REG_WR(bp, umac_base + UMAC_REG_EEE_WAKE_TIMER, 0x11);
16048c2ecf20Sopenharmony_ci	} else {
16058c2ecf20Sopenharmony_ci		REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL, 0x0);
16068c2ecf20Sopenharmony_ci	}
16078c2ecf20Sopenharmony_ci
16088c2ecf20Sopenharmony_ci	/* Set MAC address for source TX Pause/PFC frames (under SW reset) */
16098c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
16108c2ecf20Sopenharmony_ci	       ((params->mac_addr[2] << 24) |
16118c2ecf20Sopenharmony_ci		(params->mac_addr[3] << 16) |
16128c2ecf20Sopenharmony_ci		(params->mac_addr[4] << 8) |
16138c2ecf20Sopenharmony_ci		(params->mac_addr[5])));
16148c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
16158c2ecf20Sopenharmony_ci	       ((params->mac_addr[0] << 8) |
16168c2ecf20Sopenharmony_ci		(params->mac_addr[1])));
16178c2ecf20Sopenharmony_ci
16188c2ecf20Sopenharmony_ci	/* Enable RX and TX */
16198c2ecf20Sopenharmony_ci	val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
16208c2ecf20Sopenharmony_ci	val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
16218c2ecf20Sopenharmony_ci		UMAC_COMMAND_CONFIG_REG_RX_ENA;
16228c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
16238c2ecf20Sopenharmony_ci	udelay(50);
16248c2ecf20Sopenharmony_ci
16258c2ecf20Sopenharmony_ci	/* Remove SW Reset */
16268c2ecf20Sopenharmony_ci	val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
16278c2ecf20Sopenharmony_ci
16288c2ecf20Sopenharmony_ci	/* Check loopback mode */
16298c2ecf20Sopenharmony_ci	if (lb)
16308c2ecf20Sopenharmony_ci		val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
16318c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
16328c2ecf20Sopenharmony_ci
16338c2ecf20Sopenharmony_ci	/* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
16348c2ecf20Sopenharmony_ci	 * length used by the MAC receive logic to check frames.
16358c2ecf20Sopenharmony_ci	 */
16368c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
16378c2ecf20Sopenharmony_ci	bnx2x_set_xumac_nig(params,
16388c2ecf20Sopenharmony_ci			    ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
16398c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_UMAC;
16408c2ecf20Sopenharmony_ci
16418c2ecf20Sopenharmony_ci}
16428c2ecf20Sopenharmony_ci
16438c2ecf20Sopenharmony_ci/* Define the XMAC mode */
16448c2ecf20Sopenharmony_cistatic void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
16458c2ecf20Sopenharmony_ci{
16468c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
16478c2ecf20Sopenharmony_ci	u32 is_port4mode = bnx2x_is_4_port_mode(bp);
16488c2ecf20Sopenharmony_ci
16498c2ecf20Sopenharmony_ci	/* In 4-port mode, need to set the mode only once, so if XMAC is
16508c2ecf20Sopenharmony_ci	 * already out of reset, it means the mode has already been set,
16518c2ecf20Sopenharmony_ci	 * and it must not* reset the XMAC again, since it controls both
16528c2ecf20Sopenharmony_ci	 * ports of the path
16538c2ecf20Sopenharmony_ci	 */
16548c2ecf20Sopenharmony_ci
16558c2ecf20Sopenharmony_ci	if (((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) ||
16568c2ecf20Sopenharmony_ci	     (CHIP_NUM(bp) == CHIP_NUM_57840_2_20) ||
16578c2ecf20Sopenharmony_ci	     (CHIP_NUM(bp) == CHIP_NUM_57840_OBSOLETE)) &&
16588c2ecf20Sopenharmony_ci	    is_port4mode &&
16598c2ecf20Sopenharmony_ci	    (REG_RD(bp, MISC_REG_RESET_REG_2) &
16608c2ecf20Sopenharmony_ci	     MISC_REGISTERS_RESET_REG_2_XMAC)) {
16618c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
16628c2ecf20Sopenharmony_ci		   "XMAC already out of reset in 4-port mode\n");
16638c2ecf20Sopenharmony_ci		return;
16648c2ecf20Sopenharmony_ci	}
16658c2ecf20Sopenharmony_ci
16668c2ecf20Sopenharmony_ci	/* Hard reset */
16678c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
16688c2ecf20Sopenharmony_ci	       MISC_REGISTERS_RESET_REG_2_XMAC);
16698c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
16708c2ecf20Sopenharmony_ci
16718c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
16728c2ecf20Sopenharmony_ci	       MISC_REGISTERS_RESET_REG_2_XMAC);
16738c2ecf20Sopenharmony_ci	if (is_port4mode) {
16748c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
16758c2ecf20Sopenharmony_ci
16768c2ecf20Sopenharmony_ci		/* Set the number of ports on the system side to up to 2 */
16778c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci		/* Set the number of ports on the Warp Core to 10G */
16808c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
16818c2ecf20Sopenharmony_ci	} else {
16828c2ecf20Sopenharmony_ci		/* Set the number of ports on the system side to 1 */
16838c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
16848c2ecf20Sopenharmony_ci		if (max_speed == SPEED_10000) {
16858c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
16868c2ecf20Sopenharmony_ci			   "Init XMAC to 10G x 1 port per path\n");
16878c2ecf20Sopenharmony_ci			/* Set the number of ports on the Warp Core to 10G */
16888c2ecf20Sopenharmony_ci			REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
16898c2ecf20Sopenharmony_ci		} else {
16908c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
16918c2ecf20Sopenharmony_ci			   "Init XMAC to 20G x 2 ports per path\n");
16928c2ecf20Sopenharmony_ci			/* Set the number of ports on the Warp Core to 20G */
16938c2ecf20Sopenharmony_ci			REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
16948c2ecf20Sopenharmony_ci		}
16958c2ecf20Sopenharmony_ci	}
16968c2ecf20Sopenharmony_ci	/* Soft reset */
16978c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
16988c2ecf20Sopenharmony_ci	       MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
16998c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
17028c2ecf20Sopenharmony_ci	       MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
17038c2ecf20Sopenharmony_ci
17048c2ecf20Sopenharmony_ci}
17058c2ecf20Sopenharmony_ci
17068c2ecf20Sopenharmony_cistatic void bnx2x_set_xmac_rxtx(struct link_params *params, u8 en)
17078c2ecf20Sopenharmony_ci{
17088c2ecf20Sopenharmony_ci	u8 port = params->port;
17098c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
17108c2ecf20Sopenharmony_ci	u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
17118c2ecf20Sopenharmony_ci	u32 val;
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci	if (REG_RD(bp, MISC_REG_RESET_REG_2) &
17148c2ecf20Sopenharmony_ci	    MISC_REGISTERS_RESET_REG_2_XMAC) {
17158c2ecf20Sopenharmony_ci		/* Send an indication to change the state in the NIG back to XON
17168c2ecf20Sopenharmony_ci		 * Clearing this bit enables the next set of this bit to get
17178c2ecf20Sopenharmony_ci		 * rising edge
17188c2ecf20Sopenharmony_ci		 */
17198c2ecf20Sopenharmony_ci		pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
17208c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
17218c2ecf20Sopenharmony_ci		       (pfc_ctrl & ~(1<<1)));
17228c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
17238c2ecf20Sopenharmony_ci		       (pfc_ctrl | (1<<1)));
17248c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
17258c2ecf20Sopenharmony_ci		val = REG_RD(bp, xmac_base + XMAC_REG_CTRL);
17268c2ecf20Sopenharmony_ci		if (en)
17278c2ecf20Sopenharmony_ci			val |= (XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
17288c2ecf20Sopenharmony_ci		else
17298c2ecf20Sopenharmony_ci			val &= ~(XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
17308c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
17318c2ecf20Sopenharmony_ci	}
17328c2ecf20Sopenharmony_ci}
17338c2ecf20Sopenharmony_ci
17348c2ecf20Sopenharmony_cistatic int bnx2x_xmac_enable(struct link_params *params,
17358c2ecf20Sopenharmony_ci			     struct link_vars *vars, u8 lb)
17368c2ecf20Sopenharmony_ci{
17378c2ecf20Sopenharmony_ci	u32 val, xmac_base;
17388c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
17398c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "enabling XMAC\n");
17408c2ecf20Sopenharmony_ci
17418c2ecf20Sopenharmony_ci	xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
17428c2ecf20Sopenharmony_ci
17438c2ecf20Sopenharmony_ci	bnx2x_xmac_init(params, vars->line_speed);
17448c2ecf20Sopenharmony_ci
17458c2ecf20Sopenharmony_ci	/* This register determines on which events the MAC will assert
17468c2ecf20Sopenharmony_ci	 * error on the i/f to the NIG along w/ EOP.
17478c2ecf20Sopenharmony_ci	 */
17488c2ecf20Sopenharmony_ci
17498c2ecf20Sopenharmony_ci	/* This register tells the NIG whether to send traffic to UMAC
17508c2ecf20Sopenharmony_ci	 * or XMAC
17518c2ecf20Sopenharmony_ci	 */
17528c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
17538c2ecf20Sopenharmony_ci
17548c2ecf20Sopenharmony_ci	/* When XMAC is in XLGMII mode, disable sending idles for fault
17558c2ecf20Sopenharmony_ci	 * detection.
17568c2ecf20Sopenharmony_ci	 */
17578c2ecf20Sopenharmony_ci	if (!(params->phy[INT_PHY].flags & FLAGS_TX_ERROR_CHECK)) {
17588c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_RX_LSS_CTRL,
17598c2ecf20Sopenharmony_ci		       (XMAC_RX_LSS_CTRL_REG_LOCAL_FAULT_DISABLE |
17608c2ecf20Sopenharmony_ci			XMAC_RX_LSS_CTRL_REG_REMOTE_FAULT_DISABLE));
17618c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
17628c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
17638c2ecf20Sopenharmony_ci		       XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
17648c2ecf20Sopenharmony_ci		       XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
17658c2ecf20Sopenharmony_ci	}
17668c2ecf20Sopenharmony_ci	/* Set Max packet size */
17678c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
17688c2ecf20Sopenharmony_ci
17698c2ecf20Sopenharmony_ci	/* CRC append for Tx packets */
17708c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
17718c2ecf20Sopenharmony_ci
17728c2ecf20Sopenharmony_ci	/* update PFC */
17738c2ecf20Sopenharmony_ci	bnx2x_update_pfc_xmac(params, vars, 0);
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_ci	if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
17768c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting XMAC for EEE\n");
17778c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
17788c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
17798c2ecf20Sopenharmony_ci	} else {
17808c2ecf20Sopenharmony_ci		REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
17818c2ecf20Sopenharmony_ci	}
17828c2ecf20Sopenharmony_ci
17838c2ecf20Sopenharmony_ci	/* Enable TX and RX */
17848c2ecf20Sopenharmony_ci	val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
17858c2ecf20Sopenharmony_ci
17868c2ecf20Sopenharmony_ci	/* Set MAC in XLGMII mode for dual-mode */
17878c2ecf20Sopenharmony_ci	if ((vars->line_speed == SPEED_20000) &&
17888c2ecf20Sopenharmony_ci	    (params->phy[INT_PHY].supported &
17898c2ecf20Sopenharmony_ci	     SUPPORTED_20000baseKR2_Full))
17908c2ecf20Sopenharmony_ci		val |= XMAC_CTRL_REG_XLGMII_ALIGN_ENB;
17918c2ecf20Sopenharmony_ci
17928c2ecf20Sopenharmony_ci	/* Check loopback mode */
17938c2ecf20Sopenharmony_ci	if (lb)
17948c2ecf20Sopenharmony_ci		val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
17958c2ecf20Sopenharmony_ci	REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
17968c2ecf20Sopenharmony_ci	bnx2x_set_xumac_nig(params,
17978c2ecf20Sopenharmony_ci			    ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
17988c2ecf20Sopenharmony_ci
17998c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_XMAC;
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci	return 0;
18028c2ecf20Sopenharmony_ci}
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_cistatic int bnx2x_emac_enable(struct link_params *params,
18058c2ecf20Sopenharmony_ci			     struct link_vars *vars, u8 lb)
18068c2ecf20Sopenharmony_ci{
18078c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
18088c2ecf20Sopenharmony_ci	u8 port = params->port;
18098c2ecf20Sopenharmony_ci	u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
18108c2ecf20Sopenharmony_ci	u32 val;
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "enabling EMAC\n");
18138c2ecf20Sopenharmony_ci
18148c2ecf20Sopenharmony_ci	/* Disable BMAC */
18158c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
18168c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
18178c2ecf20Sopenharmony_ci
18188c2ecf20Sopenharmony_ci	/* enable emac and not bmac */
18198c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
18208c2ecf20Sopenharmony_ci
18218c2ecf20Sopenharmony_ci	/* ASIC */
18228c2ecf20Sopenharmony_ci	if (vars->phy_flags & PHY_XGXS_FLAG) {
18238c2ecf20Sopenharmony_ci		u32 ser_lane = ((params->lane_config &
18248c2ecf20Sopenharmony_ci				 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
18258c2ecf20Sopenharmony_ci				PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
18268c2ecf20Sopenharmony_ci
18278c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS\n");
18288c2ecf20Sopenharmony_ci		/* select the master lanes (out of 0-3) */
18298c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
18308c2ecf20Sopenharmony_ci		/* select XGXS */
18318c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
18328c2ecf20Sopenharmony_ci
18338c2ecf20Sopenharmony_ci	} else { /* SerDes */
18348c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "SerDes\n");
18358c2ecf20Sopenharmony_ci		/* select SerDes */
18368c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
18378c2ecf20Sopenharmony_ci	}
18388c2ecf20Sopenharmony_ci
18398c2ecf20Sopenharmony_ci	bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
18408c2ecf20Sopenharmony_ci		      EMAC_RX_MODE_RESET);
18418c2ecf20Sopenharmony_ci	bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
18428c2ecf20Sopenharmony_ci		      EMAC_TX_MODE_RESET);
18438c2ecf20Sopenharmony_ci
18448c2ecf20Sopenharmony_ci	/* pause enable/disable */
18458c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
18468c2ecf20Sopenharmony_ci		       EMAC_RX_MODE_FLOW_EN);
18478c2ecf20Sopenharmony_ci
18488c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp,  emac_base + EMAC_REG_EMAC_TX_MODE,
18498c2ecf20Sopenharmony_ci		       (EMAC_TX_MODE_EXT_PAUSE_EN |
18508c2ecf20Sopenharmony_ci			EMAC_TX_MODE_FLOW_EN));
18518c2ecf20Sopenharmony_ci	if (!(params->feature_config_flags &
18528c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED)) {
18538c2ecf20Sopenharmony_ci		if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
18548c2ecf20Sopenharmony_ci			bnx2x_bits_en(bp, emac_base +
18558c2ecf20Sopenharmony_ci				      EMAC_REG_EMAC_RX_MODE,
18568c2ecf20Sopenharmony_ci				      EMAC_RX_MODE_FLOW_EN);
18578c2ecf20Sopenharmony_ci
18588c2ecf20Sopenharmony_ci		if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
18598c2ecf20Sopenharmony_ci			bnx2x_bits_en(bp, emac_base +
18608c2ecf20Sopenharmony_ci				      EMAC_REG_EMAC_TX_MODE,
18618c2ecf20Sopenharmony_ci				      (EMAC_TX_MODE_EXT_PAUSE_EN |
18628c2ecf20Sopenharmony_ci				       EMAC_TX_MODE_FLOW_EN));
18638c2ecf20Sopenharmony_ci	} else
18648c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
18658c2ecf20Sopenharmony_ci			      EMAC_TX_MODE_FLOW_EN);
18668c2ecf20Sopenharmony_ci
18678c2ecf20Sopenharmony_ci	/* KEEP_VLAN_TAG, promiscuous */
18688c2ecf20Sopenharmony_ci	val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
18698c2ecf20Sopenharmony_ci	val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
18708c2ecf20Sopenharmony_ci
18718c2ecf20Sopenharmony_ci	/* Setting this bit causes MAC control frames (except for pause
18728c2ecf20Sopenharmony_ci	 * frames) to be passed on for processing. This setting has no
18738c2ecf20Sopenharmony_ci	 * affect on the operation of the pause frames. This bit effects
18748c2ecf20Sopenharmony_ci	 * all packets regardless of RX Parser packet sorting logic.
18758c2ecf20Sopenharmony_ci	 * Turn the PFC off to make sure we are in Xon state before
18768c2ecf20Sopenharmony_ci	 * enabling it.
18778c2ecf20Sopenharmony_ci	 */
18788c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
18798c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
18808c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "PFC is enabled\n");
18818c2ecf20Sopenharmony_ci		/* Enable PFC again */
18828c2ecf20Sopenharmony_ci		EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
18838c2ecf20Sopenharmony_ci			EMAC_REG_RX_PFC_MODE_RX_EN |
18848c2ecf20Sopenharmony_ci			EMAC_REG_RX_PFC_MODE_TX_EN |
18858c2ecf20Sopenharmony_ci			EMAC_REG_RX_PFC_MODE_PRIORITIES);
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ci		EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
18888c2ecf20Sopenharmony_ci			((0x0101 <<
18898c2ecf20Sopenharmony_ci			  EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
18908c2ecf20Sopenharmony_ci			 (0x00ff <<
18918c2ecf20Sopenharmony_ci			  EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
18928c2ecf20Sopenharmony_ci		val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
18938c2ecf20Sopenharmony_ci	}
18948c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
18958c2ecf20Sopenharmony_ci
18968c2ecf20Sopenharmony_ci	/* Set Loopback */
18978c2ecf20Sopenharmony_ci	val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
18988c2ecf20Sopenharmony_ci	if (lb)
18998c2ecf20Sopenharmony_ci		val |= 0x810;
19008c2ecf20Sopenharmony_ci	else
19018c2ecf20Sopenharmony_ci		val &= ~0x810;
19028c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
19038c2ecf20Sopenharmony_ci
19048c2ecf20Sopenharmony_ci	/* Enable emac */
19058c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
19068c2ecf20Sopenharmony_ci
19078c2ecf20Sopenharmony_ci	/* Enable emac for jumbo packets */
19088c2ecf20Sopenharmony_ci	EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
19098c2ecf20Sopenharmony_ci		(EMAC_RX_MTU_SIZE_JUMBO_ENA |
19108c2ecf20Sopenharmony_ci		 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD)));
19118c2ecf20Sopenharmony_ci
19128c2ecf20Sopenharmony_ci	/* Strip CRC */
19138c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
19148c2ecf20Sopenharmony_ci
19158c2ecf20Sopenharmony_ci	/* Disable the NIG in/out to the bmac */
19168c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
19178c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
19188c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
19198c2ecf20Sopenharmony_ci
19208c2ecf20Sopenharmony_ci	/* Enable the NIG in/out to the emac */
19218c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
19228c2ecf20Sopenharmony_ci	val = 0;
19238c2ecf20Sopenharmony_ci	if ((params->feature_config_flags &
19248c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED) ||
19258c2ecf20Sopenharmony_ci	    (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
19268c2ecf20Sopenharmony_ci		val = 1;
19278c2ecf20Sopenharmony_ci
19288c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
19298c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
19308c2ecf20Sopenharmony_ci
19318c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
19328c2ecf20Sopenharmony_ci
19338c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_EMAC;
19348c2ecf20Sopenharmony_ci	return 0;
19358c2ecf20Sopenharmony_ci}
19368c2ecf20Sopenharmony_ci
19378c2ecf20Sopenharmony_cistatic void bnx2x_update_pfc_bmac1(struct link_params *params,
19388c2ecf20Sopenharmony_ci				   struct link_vars *vars)
19398c2ecf20Sopenharmony_ci{
19408c2ecf20Sopenharmony_ci	u32 wb_data[2];
19418c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
19428c2ecf20Sopenharmony_ci	u32 bmac_addr =  params->port ? NIG_REG_INGRESS_BMAC1_MEM :
19438c2ecf20Sopenharmony_ci		NIG_REG_INGRESS_BMAC0_MEM;
19448c2ecf20Sopenharmony_ci
19458c2ecf20Sopenharmony_ci	u32 val = 0x14;
19468c2ecf20Sopenharmony_ci	if ((!(params->feature_config_flags &
19478c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED)) &&
19488c2ecf20Sopenharmony_ci		(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
19498c2ecf20Sopenharmony_ci		/* Enable BigMAC to react on received Pause packets */
19508c2ecf20Sopenharmony_ci		val |= (1<<5);
19518c2ecf20Sopenharmony_ci	wb_data[0] = val;
19528c2ecf20Sopenharmony_ci	wb_data[1] = 0;
19538c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
19548c2ecf20Sopenharmony_ci
19558c2ecf20Sopenharmony_ci	/* TX control */
19568c2ecf20Sopenharmony_ci	val = 0xc0;
19578c2ecf20Sopenharmony_ci	if (!(params->feature_config_flags &
19588c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED) &&
19598c2ecf20Sopenharmony_ci		(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
19608c2ecf20Sopenharmony_ci		val |= 0x800000;
19618c2ecf20Sopenharmony_ci	wb_data[0] = val;
19628c2ecf20Sopenharmony_ci	wb_data[1] = 0;
19638c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
19648c2ecf20Sopenharmony_ci}
19658c2ecf20Sopenharmony_ci
19668c2ecf20Sopenharmony_cistatic void bnx2x_update_pfc_bmac2(struct link_params *params,
19678c2ecf20Sopenharmony_ci				   struct link_vars *vars,
19688c2ecf20Sopenharmony_ci				   u8 is_lb)
19698c2ecf20Sopenharmony_ci{
19708c2ecf20Sopenharmony_ci	/* Set rx control: Strip CRC and enable BigMAC to relay
19718c2ecf20Sopenharmony_ci	 * control packets to the system as well
19728c2ecf20Sopenharmony_ci	 */
19738c2ecf20Sopenharmony_ci	u32 wb_data[2];
19748c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
19758c2ecf20Sopenharmony_ci	u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
19768c2ecf20Sopenharmony_ci		NIG_REG_INGRESS_BMAC0_MEM;
19778c2ecf20Sopenharmony_ci	u32 val = 0x14;
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_ci	if ((!(params->feature_config_flags &
19808c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED)) &&
19818c2ecf20Sopenharmony_ci		(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
19828c2ecf20Sopenharmony_ci		/* Enable BigMAC to react on received Pause packets */
19838c2ecf20Sopenharmony_ci		val |= (1<<5);
19848c2ecf20Sopenharmony_ci	wb_data[0] = val;
19858c2ecf20Sopenharmony_ci	wb_data[1] = 0;
19868c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
19878c2ecf20Sopenharmony_ci	udelay(30);
19888c2ecf20Sopenharmony_ci
19898c2ecf20Sopenharmony_ci	/* Tx control */
19908c2ecf20Sopenharmony_ci	val = 0xc0;
19918c2ecf20Sopenharmony_ci	if (!(params->feature_config_flags &
19928c2ecf20Sopenharmony_ci				FEATURE_CONFIG_PFC_ENABLED) &&
19938c2ecf20Sopenharmony_ci	    (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
19948c2ecf20Sopenharmony_ci		val |= 0x800000;
19958c2ecf20Sopenharmony_ci	wb_data[0] = val;
19968c2ecf20Sopenharmony_ci	wb_data[1] = 0;
19978c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
19988c2ecf20Sopenharmony_ci
19998c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
20008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "PFC is enabled\n");
20018c2ecf20Sopenharmony_ci		/* Enable PFC RX & TX & STATS and set 8 COS  */
20028c2ecf20Sopenharmony_ci		wb_data[0] = 0x0;
20038c2ecf20Sopenharmony_ci		wb_data[0] |= (1<<0);  /* RX */
20048c2ecf20Sopenharmony_ci		wb_data[0] |= (1<<1);  /* TX */
20058c2ecf20Sopenharmony_ci		wb_data[0] |= (1<<2);  /* Force initial Xon */
20068c2ecf20Sopenharmony_ci		wb_data[0] |= (1<<3);  /* 8 cos */
20078c2ecf20Sopenharmony_ci		wb_data[0] |= (1<<5);  /* STATS */
20088c2ecf20Sopenharmony_ci		wb_data[1] = 0;
20098c2ecf20Sopenharmony_ci		REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
20108c2ecf20Sopenharmony_ci			    wb_data, 2);
20118c2ecf20Sopenharmony_ci		/* Clear the force Xon */
20128c2ecf20Sopenharmony_ci		wb_data[0] &= ~(1<<2);
20138c2ecf20Sopenharmony_ci	} else {
20148c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "PFC is disabled\n");
20158c2ecf20Sopenharmony_ci		/* Disable PFC RX & TX & STATS and set 8 COS */
20168c2ecf20Sopenharmony_ci		wb_data[0] = 0x8;
20178c2ecf20Sopenharmony_ci		wb_data[1] = 0;
20188c2ecf20Sopenharmony_ci	}
20198c2ecf20Sopenharmony_ci
20208c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
20218c2ecf20Sopenharmony_ci
20228c2ecf20Sopenharmony_ci	/* Set Time (based unit is 512 bit time) between automatic
20238c2ecf20Sopenharmony_ci	 * re-sending of PP packets amd enable automatic re-send of
20248c2ecf20Sopenharmony_ci	 * Per-Priroity Packet as long as pp_gen is asserted and
20258c2ecf20Sopenharmony_ci	 * pp_disable is low.
20268c2ecf20Sopenharmony_ci	 */
20278c2ecf20Sopenharmony_ci	val = 0x8000;
20288c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
20298c2ecf20Sopenharmony_ci		val |= (1<<16); /* enable automatic re-send */
20308c2ecf20Sopenharmony_ci
20318c2ecf20Sopenharmony_ci	wb_data[0] = val;
20328c2ecf20Sopenharmony_ci	wb_data[1] = 0;
20338c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
20348c2ecf20Sopenharmony_ci		    wb_data, 2);
20358c2ecf20Sopenharmony_ci
20368c2ecf20Sopenharmony_ci	/* mac control */
20378c2ecf20Sopenharmony_ci	val = 0x3; /* Enable RX and TX */
20388c2ecf20Sopenharmony_ci	if (is_lb) {
20398c2ecf20Sopenharmony_ci		val |= 0x4; /* Local loopback */
20408c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "enable bmac loopback\n");
20418c2ecf20Sopenharmony_ci	}
20428c2ecf20Sopenharmony_ci	/* When PFC enabled, Pass pause frames towards the NIG. */
20438c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
20448c2ecf20Sopenharmony_ci		val |= ((1<<6)|(1<<5));
20458c2ecf20Sopenharmony_ci
20468c2ecf20Sopenharmony_ci	wb_data[0] = val;
20478c2ecf20Sopenharmony_ci	wb_data[1] = 0;
20488c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
20498c2ecf20Sopenharmony_ci}
20508c2ecf20Sopenharmony_ci
20518c2ecf20Sopenharmony_ci/******************************************************************************
20528c2ecf20Sopenharmony_ci* Description:
20538c2ecf20Sopenharmony_ci*  This function is needed because NIG ARB_CREDIT_WEIGHT_X are
20548c2ecf20Sopenharmony_ci*  not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
20558c2ecf20Sopenharmony_ci******************************************************************************/
20568c2ecf20Sopenharmony_cistatic int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
20578c2ecf20Sopenharmony_ci					   u8 cos_entry,
20588c2ecf20Sopenharmony_ci					   u32 priority_mask, u8 port)
20598c2ecf20Sopenharmony_ci{
20608c2ecf20Sopenharmony_ci	u32 nig_reg_rx_priority_mask_add = 0;
20618c2ecf20Sopenharmony_ci
20628c2ecf20Sopenharmony_ci	switch (cos_entry) {
20638c2ecf20Sopenharmony_ci	case 0:
20648c2ecf20Sopenharmony_ci	     nig_reg_rx_priority_mask_add = (port) ?
20658c2ecf20Sopenharmony_ci		 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
20668c2ecf20Sopenharmony_ci		 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
20678c2ecf20Sopenharmony_ci	     break;
20688c2ecf20Sopenharmony_ci	case 1:
20698c2ecf20Sopenharmony_ci	    nig_reg_rx_priority_mask_add = (port) ?
20708c2ecf20Sopenharmony_ci		NIG_REG_P1_RX_COS1_PRIORITY_MASK :
20718c2ecf20Sopenharmony_ci		NIG_REG_P0_RX_COS1_PRIORITY_MASK;
20728c2ecf20Sopenharmony_ci	    break;
20738c2ecf20Sopenharmony_ci	case 2:
20748c2ecf20Sopenharmony_ci	    nig_reg_rx_priority_mask_add = (port) ?
20758c2ecf20Sopenharmony_ci		NIG_REG_P1_RX_COS2_PRIORITY_MASK :
20768c2ecf20Sopenharmony_ci		NIG_REG_P0_RX_COS2_PRIORITY_MASK;
20778c2ecf20Sopenharmony_ci	    break;
20788c2ecf20Sopenharmony_ci	case 3:
20798c2ecf20Sopenharmony_ci	    if (port)
20808c2ecf20Sopenharmony_ci		return -EINVAL;
20818c2ecf20Sopenharmony_ci	    nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
20828c2ecf20Sopenharmony_ci	    break;
20838c2ecf20Sopenharmony_ci	case 4:
20848c2ecf20Sopenharmony_ci	    if (port)
20858c2ecf20Sopenharmony_ci		return -EINVAL;
20868c2ecf20Sopenharmony_ci	    nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
20878c2ecf20Sopenharmony_ci	    break;
20888c2ecf20Sopenharmony_ci	case 5:
20898c2ecf20Sopenharmony_ci	    if (port)
20908c2ecf20Sopenharmony_ci		return -EINVAL;
20918c2ecf20Sopenharmony_ci	    nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
20928c2ecf20Sopenharmony_ci	    break;
20938c2ecf20Sopenharmony_ci	}
20948c2ecf20Sopenharmony_ci
20958c2ecf20Sopenharmony_ci	REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
20968c2ecf20Sopenharmony_ci
20978c2ecf20Sopenharmony_ci	return 0;
20988c2ecf20Sopenharmony_ci}
20998c2ecf20Sopenharmony_cistatic void bnx2x_update_mng(struct link_params *params, u32 link_status)
21008c2ecf20Sopenharmony_ci{
21018c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
21028c2ecf20Sopenharmony_ci
21038c2ecf20Sopenharmony_ci	REG_WR(bp, params->shmem_base +
21048c2ecf20Sopenharmony_ci	       offsetof(struct shmem_region,
21058c2ecf20Sopenharmony_ci			port_mb[params->port].link_status), link_status);
21068c2ecf20Sopenharmony_ci}
21078c2ecf20Sopenharmony_ci
21088c2ecf20Sopenharmony_cistatic void bnx2x_update_link_attr(struct link_params *params, u32 link_attr)
21098c2ecf20Sopenharmony_ci{
21108c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
21118c2ecf20Sopenharmony_ci
21128c2ecf20Sopenharmony_ci	if (SHMEM2_HAS(bp, link_attr_sync))
21138c2ecf20Sopenharmony_ci		REG_WR(bp, params->shmem2_base +
21148c2ecf20Sopenharmony_ci		       offsetof(struct shmem2_region,
21158c2ecf20Sopenharmony_ci				link_attr_sync[params->port]), link_attr);
21168c2ecf20Sopenharmony_ci}
21178c2ecf20Sopenharmony_ci
21188c2ecf20Sopenharmony_cistatic void bnx2x_update_pfc_nig(struct link_params *params,
21198c2ecf20Sopenharmony_ci		struct link_vars *vars,
21208c2ecf20Sopenharmony_ci		struct bnx2x_nig_brb_pfc_port_params *nig_params)
21218c2ecf20Sopenharmony_ci{
21228c2ecf20Sopenharmony_ci	u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
21238c2ecf20Sopenharmony_ci	u32 llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
21248c2ecf20Sopenharmony_ci	u32 pkt_priority_to_cos = 0;
21258c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
21268c2ecf20Sopenharmony_ci	u8 port = params->port;
21278c2ecf20Sopenharmony_ci
21288c2ecf20Sopenharmony_ci	int set_pfc = params->feature_config_flags &
21298c2ecf20Sopenharmony_ci		FEATURE_CONFIG_PFC_ENABLED;
21308c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
21318c2ecf20Sopenharmony_ci
21328c2ecf20Sopenharmony_ci	/* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
21338c2ecf20Sopenharmony_ci	 * MAC control frames (that are not pause packets)
21348c2ecf20Sopenharmony_ci	 * will be forwarded to the XCM.
21358c2ecf20Sopenharmony_ci	 */
21368c2ecf20Sopenharmony_ci	xcm_mask = REG_RD(bp, port ? NIG_REG_LLH1_XCM_MASK :
21378c2ecf20Sopenharmony_ci			  NIG_REG_LLH0_XCM_MASK);
21388c2ecf20Sopenharmony_ci	/* NIG params will override non PFC params, since it's possible to
21398c2ecf20Sopenharmony_ci	 * do transition from PFC to SAFC
21408c2ecf20Sopenharmony_ci	 */
21418c2ecf20Sopenharmony_ci	if (set_pfc) {
21428c2ecf20Sopenharmony_ci		pause_enable = 0;
21438c2ecf20Sopenharmony_ci		llfc_out_en = 0;
21448c2ecf20Sopenharmony_ci		llfc_enable = 0;
21458c2ecf20Sopenharmony_ci		if (CHIP_IS_E3(bp))
21468c2ecf20Sopenharmony_ci			ppp_enable = 0;
21478c2ecf20Sopenharmony_ci		else
21488c2ecf20Sopenharmony_ci			ppp_enable = 1;
21498c2ecf20Sopenharmony_ci		xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
21508c2ecf20Sopenharmony_ci				     NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
21518c2ecf20Sopenharmony_ci		xcm_out_en = 0;
21528c2ecf20Sopenharmony_ci		hwpfc_enable = 1;
21538c2ecf20Sopenharmony_ci	} else  {
21548c2ecf20Sopenharmony_ci		if (nig_params) {
21558c2ecf20Sopenharmony_ci			llfc_out_en = nig_params->llfc_out_en;
21568c2ecf20Sopenharmony_ci			llfc_enable = nig_params->llfc_enable;
21578c2ecf20Sopenharmony_ci			pause_enable = nig_params->pause_enable;
21588c2ecf20Sopenharmony_ci		} else  /* Default non PFC mode - PAUSE */
21598c2ecf20Sopenharmony_ci			pause_enable = 1;
21608c2ecf20Sopenharmony_ci
21618c2ecf20Sopenharmony_ci		xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
21628c2ecf20Sopenharmony_ci			NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
21638c2ecf20Sopenharmony_ci		xcm_out_en = 1;
21648c2ecf20Sopenharmony_ci	}
21658c2ecf20Sopenharmony_ci
21668c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp))
21678c2ecf20Sopenharmony_ci		REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
21688c2ecf20Sopenharmony_ci		       NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
21698c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
21708c2ecf20Sopenharmony_ci	       NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
21718c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
21728c2ecf20Sopenharmony_ci	       NIG_REG_LLFC_ENABLE_0, llfc_enable);
21738c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
21748c2ecf20Sopenharmony_ci	       NIG_REG_PAUSE_ENABLE_0, pause_enable);
21758c2ecf20Sopenharmony_ci
21768c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
21778c2ecf20Sopenharmony_ci	       NIG_REG_PPP_ENABLE_0, ppp_enable);
21788c2ecf20Sopenharmony_ci
21798c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
21808c2ecf20Sopenharmony_ci	       NIG_REG_LLH0_XCM_MASK, xcm_mask);
21818c2ecf20Sopenharmony_ci
21828c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
21838c2ecf20Sopenharmony_ci	       NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
21848c2ecf20Sopenharmony_ci
21858c2ecf20Sopenharmony_ci	/* Output enable for RX_XCM # IF */
21868c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_XCM1_OUT_EN :
21878c2ecf20Sopenharmony_ci	       NIG_REG_XCM0_OUT_EN, xcm_out_en);
21888c2ecf20Sopenharmony_ci
21898c2ecf20Sopenharmony_ci	/* HW PFC TX enable */
21908c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_P1_HWPFC_ENABLE :
21918c2ecf20Sopenharmony_ci	       NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
21928c2ecf20Sopenharmony_ci
21938c2ecf20Sopenharmony_ci	if (nig_params) {
21948c2ecf20Sopenharmony_ci		u8 i = 0;
21958c2ecf20Sopenharmony_ci		pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
21968c2ecf20Sopenharmony_ci
21978c2ecf20Sopenharmony_ci		for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
21988c2ecf20Sopenharmony_ci			bnx2x_pfc_nig_rx_priority_mask(bp, i,
21998c2ecf20Sopenharmony_ci		nig_params->rx_cos_priority_mask[i], port);
22008c2ecf20Sopenharmony_ci
22018c2ecf20Sopenharmony_ci		REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
22028c2ecf20Sopenharmony_ci		       NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
22038c2ecf20Sopenharmony_ci		       nig_params->llfc_high_priority_classes);
22048c2ecf20Sopenharmony_ci
22058c2ecf20Sopenharmony_ci		REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
22068c2ecf20Sopenharmony_ci		       NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
22078c2ecf20Sopenharmony_ci		       nig_params->llfc_low_priority_classes);
22088c2ecf20Sopenharmony_ci	}
22098c2ecf20Sopenharmony_ci	REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
22108c2ecf20Sopenharmony_ci	       NIG_REG_P0_PKT_PRIORITY_TO_COS,
22118c2ecf20Sopenharmony_ci	       pkt_priority_to_cos);
22128c2ecf20Sopenharmony_ci}
22138c2ecf20Sopenharmony_ci
22148c2ecf20Sopenharmony_ciint bnx2x_update_pfc(struct link_params *params,
22158c2ecf20Sopenharmony_ci		      struct link_vars *vars,
22168c2ecf20Sopenharmony_ci		      struct bnx2x_nig_brb_pfc_port_params *pfc_params)
22178c2ecf20Sopenharmony_ci{
22188c2ecf20Sopenharmony_ci	/* The PFC and pause are orthogonal to one another, meaning when
22198c2ecf20Sopenharmony_ci	 * PFC is enabled, the pause are disabled, and when PFC is
22208c2ecf20Sopenharmony_ci	 * disabled, pause are set according to the pause result.
22218c2ecf20Sopenharmony_ci	 */
22228c2ecf20Sopenharmony_ci	u32 val;
22238c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
22248c2ecf20Sopenharmony_ci	u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
22258c2ecf20Sopenharmony_ci
22268c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
22278c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_PFC_ENABLED;
22288c2ecf20Sopenharmony_ci	else
22298c2ecf20Sopenharmony_ci		vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
22308c2ecf20Sopenharmony_ci
22318c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
22328c2ecf20Sopenharmony_ci
22338c2ecf20Sopenharmony_ci	/* Update NIG params */
22348c2ecf20Sopenharmony_ci	bnx2x_update_pfc_nig(params, vars, pfc_params);
22358c2ecf20Sopenharmony_ci
22368c2ecf20Sopenharmony_ci	if (!vars->link_up)
22378c2ecf20Sopenharmony_ci		return 0;
22388c2ecf20Sopenharmony_ci
22398c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
22408c2ecf20Sopenharmony_ci
22418c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
22428c2ecf20Sopenharmony_ci		if (vars->mac_type == MAC_TYPE_XMAC)
22438c2ecf20Sopenharmony_ci			bnx2x_update_pfc_xmac(params, vars, 0);
22448c2ecf20Sopenharmony_ci	} else {
22458c2ecf20Sopenharmony_ci		val = REG_RD(bp, MISC_REG_RESET_REG_2);
22468c2ecf20Sopenharmony_ci		if ((val &
22478c2ecf20Sopenharmony_ci		     (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
22488c2ecf20Sopenharmony_ci		    == 0) {
22498c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
22508c2ecf20Sopenharmony_ci			bnx2x_emac_enable(params, vars, 0);
22518c2ecf20Sopenharmony_ci			return 0;
22528c2ecf20Sopenharmony_ci		}
22538c2ecf20Sopenharmony_ci		if (CHIP_IS_E2(bp))
22548c2ecf20Sopenharmony_ci			bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
22558c2ecf20Sopenharmony_ci		else
22568c2ecf20Sopenharmony_ci			bnx2x_update_pfc_bmac1(params, vars);
22578c2ecf20Sopenharmony_ci
22588c2ecf20Sopenharmony_ci		val = 0;
22598c2ecf20Sopenharmony_ci		if ((params->feature_config_flags &
22608c2ecf20Sopenharmony_ci		     FEATURE_CONFIG_PFC_ENABLED) ||
22618c2ecf20Sopenharmony_ci		    (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
22628c2ecf20Sopenharmony_ci			val = 1;
22638c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
22648c2ecf20Sopenharmony_ci	}
22658c2ecf20Sopenharmony_ci	return 0;
22668c2ecf20Sopenharmony_ci}
22678c2ecf20Sopenharmony_ci
22688c2ecf20Sopenharmony_cistatic int bnx2x_bmac1_enable(struct link_params *params,
22698c2ecf20Sopenharmony_ci			      struct link_vars *vars,
22708c2ecf20Sopenharmony_ci			      u8 is_lb)
22718c2ecf20Sopenharmony_ci{
22728c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
22738c2ecf20Sopenharmony_ci	u8 port = params->port;
22748c2ecf20Sopenharmony_ci	u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
22758c2ecf20Sopenharmony_ci			       NIG_REG_INGRESS_BMAC0_MEM;
22768c2ecf20Sopenharmony_ci	u32 wb_data[2];
22778c2ecf20Sopenharmony_ci	u32 val;
22788c2ecf20Sopenharmony_ci
22798c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
22808c2ecf20Sopenharmony_ci
22818c2ecf20Sopenharmony_ci	/* XGXS control */
22828c2ecf20Sopenharmony_ci	wb_data[0] = 0x3c;
22838c2ecf20Sopenharmony_ci	wb_data[1] = 0;
22848c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
22858c2ecf20Sopenharmony_ci		    wb_data, 2);
22868c2ecf20Sopenharmony_ci
22878c2ecf20Sopenharmony_ci	/* TX MAC SA */
22888c2ecf20Sopenharmony_ci	wb_data[0] = ((params->mac_addr[2] << 24) |
22898c2ecf20Sopenharmony_ci		       (params->mac_addr[3] << 16) |
22908c2ecf20Sopenharmony_ci		       (params->mac_addr[4] << 8) |
22918c2ecf20Sopenharmony_ci			params->mac_addr[5]);
22928c2ecf20Sopenharmony_ci	wb_data[1] = ((params->mac_addr[0] << 8) |
22938c2ecf20Sopenharmony_ci			params->mac_addr[1]);
22948c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
22958c2ecf20Sopenharmony_ci
22968c2ecf20Sopenharmony_ci	/* MAC control */
22978c2ecf20Sopenharmony_ci	val = 0x3;
22988c2ecf20Sopenharmony_ci	if (is_lb) {
22998c2ecf20Sopenharmony_ci		val |= 0x4;
23008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "enable bmac loopback\n");
23018c2ecf20Sopenharmony_ci	}
23028c2ecf20Sopenharmony_ci	wb_data[0] = val;
23038c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23048c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
23058c2ecf20Sopenharmony_ci
23068c2ecf20Sopenharmony_ci	/* Set rx mtu */
23078c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD;
23088c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23098c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
23108c2ecf20Sopenharmony_ci
23118c2ecf20Sopenharmony_ci	bnx2x_update_pfc_bmac1(params, vars);
23128c2ecf20Sopenharmony_ci
23138c2ecf20Sopenharmony_ci	/* Set tx mtu */
23148c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD;
23158c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23168c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
23178c2ecf20Sopenharmony_ci
23188c2ecf20Sopenharmony_ci	/* Set cnt max size */
23198c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD;
23208c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23218c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
23228c2ecf20Sopenharmony_ci
23238c2ecf20Sopenharmony_ci	/* Configure SAFC */
23248c2ecf20Sopenharmony_ci	wb_data[0] = 0x1000200;
23258c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23268c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
23278c2ecf20Sopenharmony_ci		    wb_data, 2);
23288c2ecf20Sopenharmony_ci
23298c2ecf20Sopenharmony_ci	return 0;
23308c2ecf20Sopenharmony_ci}
23318c2ecf20Sopenharmony_ci
23328c2ecf20Sopenharmony_cistatic int bnx2x_bmac2_enable(struct link_params *params,
23338c2ecf20Sopenharmony_ci			      struct link_vars *vars,
23348c2ecf20Sopenharmony_ci			      u8 is_lb)
23358c2ecf20Sopenharmony_ci{
23368c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
23378c2ecf20Sopenharmony_ci	u8 port = params->port;
23388c2ecf20Sopenharmony_ci	u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
23398c2ecf20Sopenharmony_ci			       NIG_REG_INGRESS_BMAC0_MEM;
23408c2ecf20Sopenharmony_ci	u32 wb_data[2];
23418c2ecf20Sopenharmony_ci
23428c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
23438c2ecf20Sopenharmony_ci
23448c2ecf20Sopenharmony_ci	wb_data[0] = 0;
23458c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23468c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
23478c2ecf20Sopenharmony_ci	udelay(30);
23488c2ecf20Sopenharmony_ci
23498c2ecf20Sopenharmony_ci	/* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
23508c2ecf20Sopenharmony_ci	wb_data[0] = 0x3c;
23518c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23528c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
23538c2ecf20Sopenharmony_ci		    wb_data, 2);
23548c2ecf20Sopenharmony_ci
23558c2ecf20Sopenharmony_ci	udelay(30);
23568c2ecf20Sopenharmony_ci
23578c2ecf20Sopenharmony_ci	/* TX MAC SA */
23588c2ecf20Sopenharmony_ci	wb_data[0] = ((params->mac_addr[2] << 24) |
23598c2ecf20Sopenharmony_ci		       (params->mac_addr[3] << 16) |
23608c2ecf20Sopenharmony_ci		       (params->mac_addr[4] << 8) |
23618c2ecf20Sopenharmony_ci			params->mac_addr[5]);
23628c2ecf20Sopenharmony_ci	wb_data[1] = ((params->mac_addr[0] << 8) |
23638c2ecf20Sopenharmony_ci			params->mac_addr[1]);
23648c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
23658c2ecf20Sopenharmony_ci		    wb_data, 2);
23668c2ecf20Sopenharmony_ci
23678c2ecf20Sopenharmony_ci	udelay(30);
23688c2ecf20Sopenharmony_ci
23698c2ecf20Sopenharmony_ci	/* Configure SAFC */
23708c2ecf20Sopenharmony_ci	wb_data[0] = 0x1000200;
23718c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23728c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
23738c2ecf20Sopenharmony_ci		    wb_data, 2);
23748c2ecf20Sopenharmony_ci	udelay(30);
23758c2ecf20Sopenharmony_ci
23768c2ecf20Sopenharmony_ci	/* Set RX MTU */
23778c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD;
23788c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23798c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
23808c2ecf20Sopenharmony_ci	udelay(30);
23818c2ecf20Sopenharmony_ci
23828c2ecf20Sopenharmony_ci	/* Set TX MTU */
23838c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD;
23848c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23858c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
23868c2ecf20Sopenharmony_ci	udelay(30);
23878c2ecf20Sopenharmony_ci	/* Set cnt max size */
23888c2ecf20Sopenharmony_ci	wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVERHEAD - 2;
23898c2ecf20Sopenharmony_ci	wb_data[1] = 0;
23908c2ecf20Sopenharmony_ci	REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
23918c2ecf20Sopenharmony_ci	udelay(30);
23928c2ecf20Sopenharmony_ci	bnx2x_update_pfc_bmac2(params, vars, is_lb);
23938c2ecf20Sopenharmony_ci
23948c2ecf20Sopenharmony_ci	return 0;
23958c2ecf20Sopenharmony_ci}
23968c2ecf20Sopenharmony_ci
23978c2ecf20Sopenharmony_cistatic int bnx2x_bmac_enable(struct link_params *params,
23988c2ecf20Sopenharmony_ci			     struct link_vars *vars,
23998c2ecf20Sopenharmony_ci			     u8 is_lb, u8 reset_bmac)
24008c2ecf20Sopenharmony_ci{
24018c2ecf20Sopenharmony_ci	int rc = 0;
24028c2ecf20Sopenharmony_ci	u8 port = params->port;
24038c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
24048c2ecf20Sopenharmony_ci	u32 val;
24058c2ecf20Sopenharmony_ci	/* Reset and unreset the BigMac */
24068c2ecf20Sopenharmony_ci	if (reset_bmac) {
24078c2ecf20Sopenharmony_ci		REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
24088c2ecf20Sopenharmony_ci		       (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
24098c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
24108c2ecf20Sopenharmony_ci	}
24118c2ecf20Sopenharmony_ci
24128c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
24138c2ecf20Sopenharmony_ci	       (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
24148c2ecf20Sopenharmony_ci
24158c2ecf20Sopenharmony_ci	/* Enable access for bmac registers */
24168c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
24178c2ecf20Sopenharmony_ci
24188c2ecf20Sopenharmony_ci	/* Enable BMAC according to BMAC type*/
24198c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
24208c2ecf20Sopenharmony_ci		rc = bnx2x_bmac2_enable(params, vars, is_lb);
24218c2ecf20Sopenharmony_ci	else
24228c2ecf20Sopenharmony_ci		rc = bnx2x_bmac1_enable(params, vars, is_lb);
24238c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
24248c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
24258c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
24268c2ecf20Sopenharmony_ci	val = 0;
24278c2ecf20Sopenharmony_ci	if ((params->feature_config_flags &
24288c2ecf20Sopenharmony_ci	      FEATURE_CONFIG_PFC_ENABLED) ||
24298c2ecf20Sopenharmony_ci	    (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
24308c2ecf20Sopenharmony_ci		val = 1;
24318c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
24328c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
24338c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
24348c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
24358c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
24368c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
24378c2ecf20Sopenharmony_ci
24388c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_BMAC;
24398c2ecf20Sopenharmony_ci	return rc;
24408c2ecf20Sopenharmony_ci}
24418c2ecf20Sopenharmony_ci
24428c2ecf20Sopenharmony_cistatic void bnx2x_set_bmac_rx(struct bnx2x *bp, u32 chip_id, u8 port, u8 en)
24438c2ecf20Sopenharmony_ci{
24448c2ecf20Sopenharmony_ci	u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
24458c2ecf20Sopenharmony_ci			NIG_REG_INGRESS_BMAC0_MEM;
24468c2ecf20Sopenharmony_ci	u32 wb_data[2];
24478c2ecf20Sopenharmony_ci	u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
24488c2ecf20Sopenharmony_ci
24498c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
24508c2ecf20Sopenharmony_ci		bmac_addr += BIGMAC2_REGISTER_BMAC_CONTROL;
24518c2ecf20Sopenharmony_ci	else
24528c2ecf20Sopenharmony_ci		bmac_addr += BIGMAC_REGISTER_BMAC_CONTROL;
24538c2ecf20Sopenharmony_ci	/* Only if the bmac is out of reset */
24548c2ecf20Sopenharmony_ci	if (REG_RD(bp, MISC_REG_RESET_REG_2) &
24558c2ecf20Sopenharmony_ci			(MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
24568c2ecf20Sopenharmony_ci	    nig_bmac_enable) {
24578c2ecf20Sopenharmony_ci		/* Clear Rx Enable bit in BMAC_CONTROL register */
24588c2ecf20Sopenharmony_ci		REG_RD_DMAE(bp, bmac_addr, wb_data, 2);
24598c2ecf20Sopenharmony_ci		if (en)
24608c2ecf20Sopenharmony_ci			wb_data[0] |= BMAC_CONTROL_RX_ENABLE;
24618c2ecf20Sopenharmony_ci		else
24628c2ecf20Sopenharmony_ci			wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
24638c2ecf20Sopenharmony_ci		REG_WR_DMAE(bp, bmac_addr, wb_data, 2);
24648c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
24658c2ecf20Sopenharmony_ci	}
24668c2ecf20Sopenharmony_ci}
24678c2ecf20Sopenharmony_ci
24688c2ecf20Sopenharmony_cistatic int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
24698c2ecf20Sopenharmony_ci			    u32 line_speed)
24708c2ecf20Sopenharmony_ci{
24718c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
24728c2ecf20Sopenharmony_ci	u8 port = params->port;
24738c2ecf20Sopenharmony_ci	u32 init_crd, crd;
24748c2ecf20Sopenharmony_ci	u32 count = 1000;
24758c2ecf20Sopenharmony_ci
24768c2ecf20Sopenharmony_ci	/* Disable port */
24778c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
24788c2ecf20Sopenharmony_ci
24798c2ecf20Sopenharmony_ci	/* Wait for init credit */
24808c2ecf20Sopenharmony_ci	init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
24818c2ecf20Sopenharmony_ci	crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
24828c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "init_crd 0x%x  crd 0x%x\n", init_crd, crd);
24838c2ecf20Sopenharmony_ci
24848c2ecf20Sopenharmony_ci	while ((init_crd != crd) && count) {
24858c2ecf20Sopenharmony_ci		usleep_range(5000, 10000);
24868c2ecf20Sopenharmony_ci		crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
24878c2ecf20Sopenharmony_ci		count--;
24888c2ecf20Sopenharmony_ci	}
24898c2ecf20Sopenharmony_ci	crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
24908c2ecf20Sopenharmony_ci	if (init_crd != crd) {
24918c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
24928c2ecf20Sopenharmony_ci			  init_crd, crd);
24938c2ecf20Sopenharmony_ci		return -EINVAL;
24948c2ecf20Sopenharmony_ci	}
24958c2ecf20Sopenharmony_ci
24968c2ecf20Sopenharmony_ci	if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
24978c2ecf20Sopenharmony_ci	    line_speed == SPEED_10 ||
24988c2ecf20Sopenharmony_ci	    line_speed == SPEED_100 ||
24998c2ecf20Sopenharmony_ci	    line_speed == SPEED_1000 ||
25008c2ecf20Sopenharmony_ci	    line_speed == SPEED_2500) {
25018c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
25028c2ecf20Sopenharmony_ci		/* Update threshold */
25038c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
25048c2ecf20Sopenharmony_ci		/* Update init credit */
25058c2ecf20Sopenharmony_ci		init_crd = 778;		/* (800-18-4) */
25068c2ecf20Sopenharmony_ci
25078c2ecf20Sopenharmony_ci	} else {
25088c2ecf20Sopenharmony_ci		u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
25098c2ecf20Sopenharmony_ci			      ETH_OVERHEAD)/16;
25108c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
25118c2ecf20Sopenharmony_ci		/* Update threshold */
25128c2ecf20Sopenharmony_ci		REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
25138c2ecf20Sopenharmony_ci		/* Update init credit */
25148c2ecf20Sopenharmony_ci		switch (line_speed) {
25158c2ecf20Sopenharmony_ci		case SPEED_10000:
25168c2ecf20Sopenharmony_ci			init_crd = thresh + 553 - 22;
25178c2ecf20Sopenharmony_ci			break;
25188c2ecf20Sopenharmony_ci		default:
25198c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
25208c2ecf20Sopenharmony_ci				  line_speed);
25218c2ecf20Sopenharmony_ci			return -EINVAL;
25228c2ecf20Sopenharmony_ci		}
25238c2ecf20Sopenharmony_ci	}
25248c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
25258c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
25268c2ecf20Sopenharmony_ci		 line_speed, init_crd);
25278c2ecf20Sopenharmony_ci
25288c2ecf20Sopenharmony_ci	/* Probe the credit changes */
25298c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
25308c2ecf20Sopenharmony_ci	usleep_range(5000, 10000);
25318c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
25328c2ecf20Sopenharmony_ci
25338c2ecf20Sopenharmony_ci	/* Enable port */
25348c2ecf20Sopenharmony_ci	REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
25358c2ecf20Sopenharmony_ci	return 0;
25368c2ecf20Sopenharmony_ci}
25378c2ecf20Sopenharmony_ci
25388c2ecf20Sopenharmony_ci/**
25398c2ecf20Sopenharmony_ci * bnx2x_get_emac_base - retrive emac base address
25408c2ecf20Sopenharmony_ci *
25418c2ecf20Sopenharmony_ci * @bp:			driver handle
25428c2ecf20Sopenharmony_ci * @mdc_mdio_access:	access type
25438c2ecf20Sopenharmony_ci * @port:		port id
25448c2ecf20Sopenharmony_ci *
25458c2ecf20Sopenharmony_ci * This function selects the MDC/MDIO access (through emac0 or
25468c2ecf20Sopenharmony_ci * emac1) depend on the mdc_mdio_access, port, port swapped. Each
25478c2ecf20Sopenharmony_ci * phy has a default access mode, which could also be overridden
25488c2ecf20Sopenharmony_ci * by nvram configuration. This parameter, whether this is the
25498c2ecf20Sopenharmony_ci * default phy configuration, or the nvram overrun
25508c2ecf20Sopenharmony_ci * configuration, is passed here as mdc_mdio_access and selects
25518c2ecf20Sopenharmony_ci * the emac_base for the CL45 read/writes operations
25528c2ecf20Sopenharmony_ci */
25538c2ecf20Sopenharmony_cistatic u32 bnx2x_get_emac_base(struct bnx2x *bp,
25548c2ecf20Sopenharmony_ci			       u32 mdc_mdio_access, u8 port)
25558c2ecf20Sopenharmony_ci{
25568c2ecf20Sopenharmony_ci	u32 emac_base = 0;
25578c2ecf20Sopenharmony_ci	switch (mdc_mdio_access) {
25588c2ecf20Sopenharmony_ci	case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
25598c2ecf20Sopenharmony_ci		break;
25608c2ecf20Sopenharmony_ci	case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
25618c2ecf20Sopenharmony_ci		if (REG_RD(bp, NIG_REG_PORT_SWAP))
25628c2ecf20Sopenharmony_ci			emac_base = GRCBASE_EMAC1;
25638c2ecf20Sopenharmony_ci		else
25648c2ecf20Sopenharmony_ci			emac_base = GRCBASE_EMAC0;
25658c2ecf20Sopenharmony_ci		break;
25668c2ecf20Sopenharmony_ci	case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
25678c2ecf20Sopenharmony_ci		if (REG_RD(bp, NIG_REG_PORT_SWAP))
25688c2ecf20Sopenharmony_ci			emac_base = GRCBASE_EMAC0;
25698c2ecf20Sopenharmony_ci		else
25708c2ecf20Sopenharmony_ci			emac_base = GRCBASE_EMAC1;
25718c2ecf20Sopenharmony_ci		break;
25728c2ecf20Sopenharmony_ci	case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
25738c2ecf20Sopenharmony_ci		emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
25748c2ecf20Sopenharmony_ci		break;
25758c2ecf20Sopenharmony_ci	case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
25768c2ecf20Sopenharmony_ci		emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
25778c2ecf20Sopenharmony_ci		break;
25788c2ecf20Sopenharmony_ci	default:
25798c2ecf20Sopenharmony_ci		break;
25808c2ecf20Sopenharmony_ci	}
25818c2ecf20Sopenharmony_ci	return emac_base;
25828c2ecf20Sopenharmony_ci
25838c2ecf20Sopenharmony_ci}
25848c2ecf20Sopenharmony_ci
25858c2ecf20Sopenharmony_ci/******************************************************************/
25868c2ecf20Sopenharmony_ci/*			CL22 access functions			  */
25878c2ecf20Sopenharmony_ci/******************************************************************/
25888c2ecf20Sopenharmony_cistatic int bnx2x_cl22_write(struct bnx2x *bp,
25898c2ecf20Sopenharmony_ci				       struct bnx2x_phy *phy,
25908c2ecf20Sopenharmony_ci				       u16 reg, u16 val)
25918c2ecf20Sopenharmony_ci{
25928c2ecf20Sopenharmony_ci	u32 tmp, mode;
25938c2ecf20Sopenharmony_ci	u8 i;
25948c2ecf20Sopenharmony_ci	int rc = 0;
25958c2ecf20Sopenharmony_ci	/* Switch to CL22 */
25968c2ecf20Sopenharmony_ci	mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
25978c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
25988c2ecf20Sopenharmony_ci	       mode & ~EMAC_MDIO_MODE_CLAUSE_45);
25998c2ecf20Sopenharmony_ci
26008c2ecf20Sopenharmony_ci	/* Address */
26018c2ecf20Sopenharmony_ci	tmp = ((phy->addr << 21) | (reg << 16) | val |
26028c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_COMMAND_WRITE_22 |
26038c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_START_BUSY);
26048c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
26058c2ecf20Sopenharmony_ci
26068c2ecf20Sopenharmony_ci	for (i = 0; i < 50; i++) {
26078c2ecf20Sopenharmony_ci		udelay(10);
26088c2ecf20Sopenharmony_ci
26098c2ecf20Sopenharmony_ci		tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
26108c2ecf20Sopenharmony_ci		if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
26118c2ecf20Sopenharmony_ci			udelay(5);
26128c2ecf20Sopenharmony_ci			break;
26138c2ecf20Sopenharmony_ci		}
26148c2ecf20Sopenharmony_ci	}
26158c2ecf20Sopenharmony_ci	if (tmp & EMAC_MDIO_COMM_START_BUSY) {
26168c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "write phy register failed\n");
26178c2ecf20Sopenharmony_ci		rc = -EFAULT;
26188c2ecf20Sopenharmony_ci	}
26198c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
26208c2ecf20Sopenharmony_ci	return rc;
26218c2ecf20Sopenharmony_ci}
26228c2ecf20Sopenharmony_ci
26238c2ecf20Sopenharmony_cistatic int bnx2x_cl22_read(struct bnx2x *bp,
26248c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
26258c2ecf20Sopenharmony_ci				      u16 reg, u16 *ret_val)
26268c2ecf20Sopenharmony_ci{
26278c2ecf20Sopenharmony_ci	u32 val, mode;
26288c2ecf20Sopenharmony_ci	u16 i;
26298c2ecf20Sopenharmony_ci	int rc = 0;
26308c2ecf20Sopenharmony_ci
26318c2ecf20Sopenharmony_ci	/* Switch to CL22 */
26328c2ecf20Sopenharmony_ci	mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
26338c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
26348c2ecf20Sopenharmony_ci	       mode & ~EMAC_MDIO_MODE_CLAUSE_45);
26358c2ecf20Sopenharmony_ci
26368c2ecf20Sopenharmony_ci	/* Address */
26378c2ecf20Sopenharmony_ci	val = ((phy->addr << 21) | (reg << 16) |
26388c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_COMMAND_READ_22 |
26398c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_START_BUSY);
26408c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
26418c2ecf20Sopenharmony_ci
26428c2ecf20Sopenharmony_ci	for (i = 0; i < 50; i++) {
26438c2ecf20Sopenharmony_ci		udelay(10);
26448c2ecf20Sopenharmony_ci
26458c2ecf20Sopenharmony_ci		val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
26468c2ecf20Sopenharmony_ci		if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
26478c2ecf20Sopenharmony_ci			*ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
26488c2ecf20Sopenharmony_ci			udelay(5);
26498c2ecf20Sopenharmony_ci			break;
26508c2ecf20Sopenharmony_ci		}
26518c2ecf20Sopenharmony_ci	}
26528c2ecf20Sopenharmony_ci	if (val & EMAC_MDIO_COMM_START_BUSY) {
26538c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "read phy register failed\n");
26548c2ecf20Sopenharmony_ci
26558c2ecf20Sopenharmony_ci		*ret_val = 0;
26568c2ecf20Sopenharmony_ci		rc = -EFAULT;
26578c2ecf20Sopenharmony_ci	}
26588c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
26598c2ecf20Sopenharmony_ci	return rc;
26608c2ecf20Sopenharmony_ci}
26618c2ecf20Sopenharmony_ci
26628c2ecf20Sopenharmony_ci/******************************************************************/
26638c2ecf20Sopenharmony_ci/*			CL45 access functions			  */
26648c2ecf20Sopenharmony_ci/******************************************************************/
26658c2ecf20Sopenharmony_cistatic int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
26668c2ecf20Sopenharmony_ci			   u8 devad, u16 reg, u16 *ret_val)
26678c2ecf20Sopenharmony_ci{
26688c2ecf20Sopenharmony_ci	u32 val;
26698c2ecf20Sopenharmony_ci	u16 i;
26708c2ecf20Sopenharmony_ci	int rc = 0;
26718c2ecf20Sopenharmony_ci	u32 chip_id;
26728c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
26738c2ecf20Sopenharmony_ci		chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
26748c2ecf20Sopenharmony_ci			  ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
26758c2ecf20Sopenharmony_ci		bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
26768c2ecf20Sopenharmony_ci	}
26778c2ecf20Sopenharmony_ci
26788c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
26798c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
26808c2ecf20Sopenharmony_ci			      EMAC_MDIO_STATUS_10MB);
26818c2ecf20Sopenharmony_ci	/* Address */
26828c2ecf20Sopenharmony_ci	val = ((phy->addr << 21) | (devad << 16) | reg |
26838c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_COMMAND_ADDRESS |
26848c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_START_BUSY);
26858c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
26868c2ecf20Sopenharmony_ci
26878c2ecf20Sopenharmony_ci	for (i = 0; i < 50; i++) {
26888c2ecf20Sopenharmony_ci		udelay(10);
26898c2ecf20Sopenharmony_ci
26908c2ecf20Sopenharmony_ci		val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
26918c2ecf20Sopenharmony_ci		if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
26928c2ecf20Sopenharmony_ci			udelay(5);
26938c2ecf20Sopenharmony_ci			break;
26948c2ecf20Sopenharmony_ci		}
26958c2ecf20Sopenharmony_ci	}
26968c2ecf20Sopenharmony_ci	if (val & EMAC_MDIO_COMM_START_BUSY) {
26978c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "read phy register failed\n");
26988c2ecf20Sopenharmony_ci		netdev_err(bp->dev,  "MDC/MDIO access timeout\n");
26998c2ecf20Sopenharmony_ci		*ret_val = 0;
27008c2ecf20Sopenharmony_ci		rc = -EFAULT;
27018c2ecf20Sopenharmony_ci	} else {
27028c2ecf20Sopenharmony_ci		/* Data */
27038c2ecf20Sopenharmony_ci		val = ((phy->addr << 21) | (devad << 16) |
27048c2ecf20Sopenharmony_ci		       EMAC_MDIO_COMM_COMMAND_READ_45 |
27058c2ecf20Sopenharmony_ci		       EMAC_MDIO_COMM_START_BUSY);
27068c2ecf20Sopenharmony_ci		REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
27078c2ecf20Sopenharmony_ci
27088c2ecf20Sopenharmony_ci		for (i = 0; i < 50; i++) {
27098c2ecf20Sopenharmony_ci			udelay(10);
27108c2ecf20Sopenharmony_ci
27118c2ecf20Sopenharmony_ci			val = REG_RD(bp, phy->mdio_ctrl +
27128c2ecf20Sopenharmony_ci				     EMAC_REG_EMAC_MDIO_COMM);
27138c2ecf20Sopenharmony_ci			if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
27148c2ecf20Sopenharmony_ci				*ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
27158c2ecf20Sopenharmony_ci				break;
27168c2ecf20Sopenharmony_ci			}
27178c2ecf20Sopenharmony_ci		}
27188c2ecf20Sopenharmony_ci		if (val & EMAC_MDIO_COMM_START_BUSY) {
27198c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "read phy register failed\n");
27208c2ecf20Sopenharmony_ci			netdev_err(bp->dev,  "MDC/MDIO access timeout\n");
27218c2ecf20Sopenharmony_ci			*ret_val = 0;
27228c2ecf20Sopenharmony_ci			rc = -EFAULT;
27238c2ecf20Sopenharmony_ci		}
27248c2ecf20Sopenharmony_ci	}
27258c2ecf20Sopenharmony_ci	/* Work around for E3 A0 */
27268c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA) {
27278c2ecf20Sopenharmony_ci		phy->flags ^= FLAGS_DUMMY_READ;
27288c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_DUMMY_READ) {
27298c2ecf20Sopenharmony_ci			u16 temp_val;
27308c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
27318c2ecf20Sopenharmony_ci		}
27328c2ecf20Sopenharmony_ci	}
27338c2ecf20Sopenharmony_ci
27348c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
27358c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
27368c2ecf20Sopenharmony_ci			       EMAC_MDIO_STATUS_10MB);
27378c2ecf20Sopenharmony_ci	return rc;
27388c2ecf20Sopenharmony_ci}
27398c2ecf20Sopenharmony_ci
27408c2ecf20Sopenharmony_cistatic int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
27418c2ecf20Sopenharmony_ci			    u8 devad, u16 reg, u16 val)
27428c2ecf20Sopenharmony_ci{
27438c2ecf20Sopenharmony_ci	u32 tmp;
27448c2ecf20Sopenharmony_ci	u8 i;
27458c2ecf20Sopenharmony_ci	int rc = 0;
27468c2ecf20Sopenharmony_ci	u32 chip_id;
27478c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
27488c2ecf20Sopenharmony_ci		chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
27498c2ecf20Sopenharmony_ci			  ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
27508c2ecf20Sopenharmony_ci		bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
27518c2ecf20Sopenharmony_ci	}
27528c2ecf20Sopenharmony_ci
27538c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
27548c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
27558c2ecf20Sopenharmony_ci			      EMAC_MDIO_STATUS_10MB);
27568c2ecf20Sopenharmony_ci
27578c2ecf20Sopenharmony_ci	/* Address */
27588c2ecf20Sopenharmony_ci	tmp = ((phy->addr << 21) | (devad << 16) | reg |
27598c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_COMMAND_ADDRESS |
27608c2ecf20Sopenharmony_ci	       EMAC_MDIO_COMM_START_BUSY);
27618c2ecf20Sopenharmony_ci	REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
27628c2ecf20Sopenharmony_ci
27638c2ecf20Sopenharmony_ci	for (i = 0; i < 50; i++) {
27648c2ecf20Sopenharmony_ci		udelay(10);
27658c2ecf20Sopenharmony_ci
27668c2ecf20Sopenharmony_ci		tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
27678c2ecf20Sopenharmony_ci		if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
27688c2ecf20Sopenharmony_ci			udelay(5);
27698c2ecf20Sopenharmony_ci			break;
27708c2ecf20Sopenharmony_ci		}
27718c2ecf20Sopenharmony_ci	}
27728c2ecf20Sopenharmony_ci	if (tmp & EMAC_MDIO_COMM_START_BUSY) {
27738c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "write phy register failed\n");
27748c2ecf20Sopenharmony_ci		netdev_err(bp->dev,  "MDC/MDIO access timeout\n");
27758c2ecf20Sopenharmony_ci		rc = -EFAULT;
27768c2ecf20Sopenharmony_ci	} else {
27778c2ecf20Sopenharmony_ci		/* Data */
27788c2ecf20Sopenharmony_ci		tmp = ((phy->addr << 21) | (devad << 16) | val |
27798c2ecf20Sopenharmony_ci		       EMAC_MDIO_COMM_COMMAND_WRITE_45 |
27808c2ecf20Sopenharmony_ci		       EMAC_MDIO_COMM_START_BUSY);
27818c2ecf20Sopenharmony_ci		REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
27828c2ecf20Sopenharmony_ci
27838c2ecf20Sopenharmony_ci		for (i = 0; i < 50; i++) {
27848c2ecf20Sopenharmony_ci			udelay(10);
27858c2ecf20Sopenharmony_ci
27868c2ecf20Sopenharmony_ci			tmp = REG_RD(bp, phy->mdio_ctrl +
27878c2ecf20Sopenharmony_ci				     EMAC_REG_EMAC_MDIO_COMM);
27888c2ecf20Sopenharmony_ci			if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
27898c2ecf20Sopenharmony_ci				udelay(5);
27908c2ecf20Sopenharmony_ci				break;
27918c2ecf20Sopenharmony_ci			}
27928c2ecf20Sopenharmony_ci		}
27938c2ecf20Sopenharmony_ci		if (tmp & EMAC_MDIO_COMM_START_BUSY) {
27948c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "write phy register failed\n");
27958c2ecf20Sopenharmony_ci			netdev_err(bp->dev,  "MDC/MDIO access timeout\n");
27968c2ecf20Sopenharmony_ci			rc = -EFAULT;
27978c2ecf20Sopenharmony_ci		}
27988c2ecf20Sopenharmony_ci	}
27998c2ecf20Sopenharmony_ci	/* Work around for E3 A0 */
28008c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA) {
28018c2ecf20Sopenharmony_ci		phy->flags ^= FLAGS_DUMMY_READ;
28028c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_DUMMY_READ) {
28038c2ecf20Sopenharmony_ci			u16 temp_val;
28048c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
28058c2ecf20Sopenharmony_ci		}
28068c2ecf20Sopenharmony_ci	}
28078c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
28088c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
28098c2ecf20Sopenharmony_ci			       EMAC_MDIO_STATUS_10MB);
28108c2ecf20Sopenharmony_ci	return rc;
28118c2ecf20Sopenharmony_ci}
28128c2ecf20Sopenharmony_ci
28138c2ecf20Sopenharmony_ci/******************************************************************/
28148c2ecf20Sopenharmony_ci/*			EEE section				   */
28158c2ecf20Sopenharmony_ci/******************************************************************/
28168c2ecf20Sopenharmony_cistatic u8 bnx2x_eee_has_cap(struct link_params *params)
28178c2ecf20Sopenharmony_ci{
28188c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
28198c2ecf20Sopenharmony_ci
28208c2ecf20Sopenharmony_ci	if (REG_RD(bp, params->shmem2_base) <=
28218c2ecf20Sopenharmony_ci		   offsetof(struct shmem2_region, eee_status[params->port]))
28228c2ecf20Sopenharmony_ci		return 0;
28238c2ecf20Sopenharmony_ci
28248c2ecf20Sopenharmony_ci	return 1;
28258c2ecf20Sopenharmony_ci}
28268c2ecf20Sopenharmony_ci
28278c2ecf20Sopenharmony_cistatic int bnx2x_eee_nvram_to_time(u32 nvram_mode, u32 *idle_timer)
28288c2ecf20Sopenharmony_ci{
28298c2ecf20Sopenharmony_ci	switch (nvram_mode) {
28308c2ecf20Sopenharmony_ci	case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
28318c2ecf20Sopenharmony_ci		*idle_timer = EEE_MODE_NVRAM_BALANCED_TIME;
28328c2ecf20Sopenharmony_ci		break;
28338c2ecf20Sopenharmony_ci	case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
28348c2ecf20Sopenharmony_ci		*idle_timer = EEE_MODE_NVRAM_AGGRESSIVE_TIME;
28358c2ecf20Sopenharmony_ci		break;
28368c2ecf20Sopenharmony_ci	case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
28378c2ecf20Sopenharmony_ci		*idle_timer = EEE_MODE_NVRAM_LATENCY_TIME;
28388c2ecf20Sopenharmony_ci		break;
28398c2ecf20Sopenharmony_ci	default:
28408c2ecf20Sopenharmony_ci		*idle_timer = 0;
28418c2ecf20Sopenharmony_ci		break;
28428c2ecf20Sopenharmony_ci	}
28438c2ecf20Sopenharmony_ci
28448c2ecf20Sopenharmony_ci	return 0;
28458c2ecf20Sopenharmony_ci}
28468c2ecf20Sopenharmony_ci
28478c2ecf20Sopenharmony_cistatic int bnx2x_eee_time_to_nvram(u32 idle_timer, u32 *nvram_mode)
28488c2ecf20Sopenharmony_ci{
28498c2ecf20Sopenharmony_ci	switch (idle_timer) {
28508c2ecf20Sopenharmony_ci	case EEE_MODE_NVRAM_BALANCED_TIME:
28518c2ecf20Sopenharmony_ci		*nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
28528c2ecf20Sopenharmony_ci		break;
28538c2ecf20Sopenharmony_ci	case EEE_MODE_NVRAM_AGGRESSIVE_TIME:
28548c2ecf20Sopenharmony_ci		*nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
28558c2ecf20Sopenharmony_ci		break;
28568c2ecf20Sopenharmony_ci	case EEE_MODE_NVRAM_LATENCY_TIME:
28578c2ecf20Sopenharmony_ci		*nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
28588c2ecf20Sopenharmony_ci		break;
28598c2ecf20Sopenharmony_ci	default:
28608c2ecf20Sopenharmony_ci		*nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
28618c2ecf20Sopenharmony_ci		break;
28628c2ecf20Sopenharmony_ci	}
28638c2ecf20Sopenharmony_ci
28648c2ecf20Sopenharmony_ci	return 0;
28658c2ecf20Sopenharmony_ci}
28668c2ecf20Sopenharmony_ci
28678c2ecf20Sopenharmony_cistatic u32 bnx2x_eee_calc_timer(struct link_params *params)
28688c2ecf20Sopenharmony_ci{
28698c2ecf20Sopenharmony_ci	u32 eee_mode, eee_idle;
28708c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
28718c2ecf20Sopenharmony_ci
28728c2ecf20Sopenharmony_ci	if (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) {
28738c2ecf20Sopenharmony_ci		if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
28748c2ecf20Sopenharmony_ci			/* time value in eee_mode --> used directly*/
28758c2ecf20Sopenharmony_ci			eee_idle = params->eee_mode & EEE_MODE_TIMER_MASK;
28768c2ecf20Sopenharmony_ci		} else {
28778c2ecf20Sopenharmony_ci			/* hsi value in eee_mode --> time */
28788c2ecf20Sopenharmony_ci			if (bnx2x_eee_nvram_to_time(params->eee_mode &
28798c2ecf20Sopenharmony_ci						    EEE_MODE_NVRAM_MASK,
28808c2ecf20Sopenharmony_ci						    &eee_idle))
28818c2ecf20Sopenharmony_ci				return 0;
28828c2ecf20Sopenharmony_ci		}
28838c2ecf20Sopenharmony_ci	} else {
28848c2ecf20Sopenharmony_ci		/* hsi values in nvram --> time*/
28858c2ecf20Sopenharmony_ci		eee_mode = ((REG_RD(bp, params->shmem_base +
28868c2ecf20Sopenharmony_ci				    offsetof(struct shmem_region, dev_info.
28878c2ecf20Sopenharmony_ci				    port_feature_config[params->port].
28888c2ecf20Sopenharmony_ci				    eee_power_mode)) &
28898c2ecf20Sopenharmony_ci			     PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
28908c2ecf20Sopenharmony_ci			    PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
28918c2ecf20Sopenharmony_ci
28928c2ecf20Sopenharmony_ci		if (bnx2x_eee_nvram_to_time(eee_mode, &eee_idle))
28938c2ecf20Sopenharmony_ci			return 0;
28948c2ecf20Sopenharmony_ci	}
28958c2ecf20Sopenharmony_ci
28968c2ecf20Sopenharmony_ci	return eee_idle;
28978c2ecf20Sopenharmony_ci}
28988c2ecf20Sopenharmony_ci
28998c2ecf20Sopenharmony_cistatic int bnx2x_eee_set_timers(struct link_params *params,
29008c2ecf20Sopenharmony_ci				   struct link_vars *vars)
29018c2ecf20Sopenharmony_ci{
29028c2ecf20Sopenharmony_ci	u32 eee_idle = 0, eee_mode;
29038c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
29048c2ecf20Sopenharmony_ci
29058c2ecf20Sopenharmony_ci	eee_idle = bnx2x_eee_calc_timer(params);
29068c2ecf20Sopenharmony_ci
29078c2ecf20Sopenharmony_ci	if (eee_idle) {
29088c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
29098c2ecf20Sopenharmony_ci		       eee_idle);
29108c2ecf20Sopenharmony_ci	} else if ((params->eee_mode & EEE_MODE_ENABLE_LPI) &&
29118c2ecf20Sopenharmony_ci		   (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) &&
29128c2ecf20Sopenharmony_ci		   (params->eee_mode & EEE_MODE_OUTPUT_TIME)) {
29138c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Error: Tx LPI is enabled with timer 0\n");
29148c2ecf20Sopenharmony_ci		return -EINVAL;
29158c2ecf20Sopenharmony_ci	}
29168c2ecf20Sopenharmony_ci
29178c2ecf20Sopenharmony_ci	vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
29188c2ecf20Sopenharmony_ci	if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
29198c2ecf20Sopenharmony_ci		/* eee_idle in 1u --> eee_status in 16u */
29208c2ecf20Sopenharmony_ci		eee_idle >>= 4;
29218c2ecf20Sopenharmony_ci		vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
29228c2ecf20Sopenharmony_ci				    SHMEM_EEE_TIME_OUTPUT_BIT;
29238c2ecf20Sopenharmony_ci	} else {
29248c2ecf20Sopenharmony_ci		if (bnx2x_eee_time_to_nvram(eee_idle, &eee_mode))
29258c2ecf20Sopenharmony_ci			return -EINVAL;
29268c2ecf20Sopenharmony_ci		vars->eee_status |= eee_mode;
29278c2ecf20Sopenharmony_ci	}
29288c2ecf20Sopenharmony_ci
29298c2ecf20Sopenharmony_ci	return 0;
29308c2ecf20Sopenharmony_ci}
29318c2ecf20Sopenharmony_ci
29328c2ecf20Sopenharmony_cistatic int bnx2x_eee_initial_config(struct link_params *params,
29338c2ecf20Sopenharmony_ci				     struct link_vars *vars, u8 mode)
29348c2ecf20Sopenharmony_ci{
29358c2ecf20Sopenharmony_ci	vars->eee_status |= ((u32) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
29368c2ecf20Sopenharmony_ci
29378c2ecf20Sopenharmony_ci	/* Propagate params' bits --> vars (for migration exposure) */
29388c2ecf20Sopenharmony_ci	if (params->eee_mode & EEE_MODE_ENABLE_LPI)
29398c2ecf20Sopenharmony_ci		vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
29408c2ecf20Sopenharmony_ci	else
29418c2ecf20Sopenharmony_ci		vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
29428c2ecf20Sopenharmony_ci
29438c2ecf20Sopenharmony_ci	if (params->eee_mode & EEE_MODE_ADV_LPI)
29448c2ecf20Sopenharmony_ci		vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
29458c2ecf20Sopenharmony_ci	else
29468c2ecf20Sopenharmony_ci		vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
29478c2ecf20Sopenharmony_ci
29488c2ecf20Sopenharmony_ci	return bnx2x_eee_set_timers(params, vars);
29498c2ecf20Sopenharmony_ci}
29508c2ecf20Sopenharmony_ci
29518c2ecf20Sopenharmony_cistatic int bnx2x_eee_disable(struct bnx2x_phy *phy,
29528c2ecf20Sopenharmony_ci				struct link_params *params,
29538c2ecf20Sopenharmony_ci				struct link_vars *vars)
29548c2ecf20Sopenharmony_ci{
29558c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
29568c2ecf20Sopenharmony_ci
29578c2ecf20Sopenharmony_ci	/* Make Certain LPI is disabled */
29588c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
29598c2ecf20Sopenharmony_ci
29608c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
29618c2ecf20Sopenharmony_ci
29628c2ecf20Sopenharmony_ci	vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
29638c2ecf20Sopenharmony_ci
29648c2ecf20Sopenharmony_ci	return 0;
29658c2ecf20Sopenharmony_ci}
29668c2ecf20Sopenharmony_ci
29678c2ecf20Sopenharmony_cistatic int bnx2x_eee_advertise(struct bnx2x_phy *phy,
29688c2ecf20Sopenharmony_ci				  struct link_params *params,
29698c2ecf20Sopenharmony_ci				  struct link_vars *vars, u8 modes)
29708c2ecf20Sopenharmony_ci{
29718c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
29728c2ecf20Sopenharmony_ci	u16 val = 0;
29738c2ecf20Sopenharmony_ci
29748c2ecf20Sopenharmony_ci	/* Mask events preventing LPI generation */
29758c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
29768c2ecf20Sopenharmony_ci
29778c2ecf20Sopenharmony_ci	if (modes & SHMEM_EEE_10G_ADV) {
29788c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertise 10GBase-T EEE\n");
29798c2ecf20Sopenharmony_ci		val |= 0x8;
29808c2ecf20Sopenharmony_ci	}
29818c2ecf20Sopenharmony_ci	if (modes & SHMEM_EEE_1G_ADV) {
29828c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertise 1GBase-T EEE\n");
29838c2ecf20Sopenharmony_ci		val |= 0x4;
29848c2ecf20Sopenharmony_ci	}
29858c2ecf20Sopenharmony_ci
29868c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
29878c2ecf20Sopenharmony_ci
29888c2ecf20Sopenharmony_ci	vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
29898c2ecf20Sopenharmony_ci	vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
29908c2ecf20Sopenharmony_ci
29918c2ecf20Sopenharmony_ci	return 0;
29928c2ecf20Sopenharmony_ci}
29938c2ecf20Sopenharmony_ci
29948c2ecf20Sopenharmony_cistatic void bnx2x_update_mng_eee(struct link_params *params, u32 eee_status)
29958c2ecf20Sopenharmony_ci{
29968c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
29978c2ecf20Sopenharmony_ci
29988c2ecf20Sopenharmony_ci	if (bnx2x_eee_has_cap(params))
29998c2ecf20Sopenharmony_ci		REG_WR(bp, params->shmem2_base +
30008c2ecf20Sopenharmony_ci		       offsetof(struct shmem2_region,
30018c2ecf20Sopenharmony_ci				eee_status[params->port]), eee_status);
30028c2ecf20Sopenharmony_ci}
30038c2ecf20Sopenharmony_ci
30048c2ecf20Sopenharmony_cistatic void bnx2x_eee_an_resolve(struct bnx2x_phy *phy,
30058c2ecf20Sopenharmony_ci				  struct link_params *params,
30068c2ecf20Sopenharmony_ci				  struct link_vars *vars)
30078c2ecf20Sopenharmony_ci{
30088c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
30098c2ecf20Sopenharmony_ci	u16 adv = 0, lp = 0;
30108c2ecf20Sopenharmony_ci	u32 lp_adv = 0;
30118c2ecf20Sopenharmony_ci	u8 neg = 0;
30128c2ecf20Sopenharmony_ci
30138c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
30148c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
30158c2ecf20Sopenharmony_ci
30168c2ecf20Sopenharmony_ci	if (lp & 0x2) {
30178c2ecf20Sopenharmony_ci		lp_adv |= SHMEM_EEE_100M_ADV;
30188c2ecf20Sopenharmony_ci		if (adv & 0x2) {
30198c2ecf20Sopenharmony_ci			if (vars->line_speed == SPEED_100)
30208c2ecf20Sopenharmony_ci				neg = 1;
30218c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "EEE negotiated - 100M\n");
30228c2ecf20Sopenharmony_ci		}
30238c2ecf20Sopenharmony_ci	}
30248c2ecf20Sopenharmony_ci	if (lp & 0x14) {
30258c2ecf20Sopenharmony_ci		lp_adv |= SHMEM_EEE_1G_ADV;
30268c2ecf20Sopenharmony_ci		if (adv & 0x14) {
30278c2ecf20Sopenharmony_ci			if (vars->line_speed == SPEED_1000)
30288c2ecf20Sopenharmony_ci				neg = 1;
30298c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "EEE negotiated - 1G\n");
30308c2ecf20Sopenharmony_ci		}
30318c2ecf20Sopenharmony_ci	}
30328c2ecf20Sopenharmony_ci	if (lp & 0x68) {
30338c2ecf20Sopenharmony_ci		lp_adv |= SHMEM_EEE_10G_ADV;
30348c2ecf20Sopenharmony_ci		if (adv & 0x68) {
30358c2ecf20Sopenharmony_ci			if (vars->line_speed == SPEED_10000)
30368c2ecf20Sopenharmony_ci				neg = 1;
30378c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "EEE negotiated - 10G\n");
30388c2ecf20Sopenharmony_ci		}
30398c2ecf20Sopenharmony_ci	}
30408c2ecf20Sopenharmony_ci
30418c2ecf20Sopenharmony_ci	vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
30428c2ecf20Sopenharmony_ci	vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
30438c2ecf20Sopenharmony_ci
30448c2ecf20Sopenharmony_ci	if (neg) {
30458c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "EEE is active\n");
30468c2ecf20Sopenharmony_ci		vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
30478c2ecf20Sopenharmony_ci	}
30488c2ecf20Sopenharmony_ci
30498c2ecf20Sopenharmony_ci}
30508c2ecf20Sopenharmony_ci
30518c2ecf20Sopenharmony_ci/******************************************************************/
30528c2ecf20Sopenharmony_ci/*			BSC access functions from E3	          */
30538c2ecf20Sopenharmony_ci/******************************************************************/
30548c2ecf20Sopenharmony_cistatic void bnx2x_bsc_module_sel(struct link_params *params)
30558c2ecf20Sopenharmony_ci{
30568c2ecf20Sopenharmony_ci	int idx;
30578c2ecf20Sopenharmony_ci	u32 board_cfg, sfp_ctrl;
30588c2ecf20Sopenharmony_ci	u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
30598c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
30608c2ecf20Sopenharmony_ci	u8 port = params->port;
30618c2ecf20Sopenharmony_ci	/* Read I2C output PINs */
30628c2ecf20Sopenharmony_ci	board_cfg = REG_RD(bp, params->shmem_base +
30638c2ecf20Sopenharmony_ci			   offsetof(struct shmem_region,
30648c2ecf20Sopenharmony_ci				    dev_info.shared_hw_config.board));
30658c2ecf20Sopenharmony_ci	i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
30668c2ecf20Sopenharmony_ci	i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
30678c2ecf20Sopenharmony_ci			SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
30688c2ecf20Sopenharmony_ci
30698c2ecf20Sopenharmony_ci	/* Read I2C output value */
30708c2ecf20Sopenharmony_ci	sfp_ctrl = REG_RD(bp, params->shmem_base +
30718c2ecf20Sopenharmony_ci			  offsetof(struct shmem_region,
30728c2ecf20Sopenharmony_ci				 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
30738c2ecf20Sopenharmony_ci	i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
30748c2ecf20Sopenharmony_ci	i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
30758c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting BSC switch\n");
30768c2ecf20Sopenharmony_ci	for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
30778c2ecf20Sopenharmony_ci		bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
30788c2ecf20Sopenharmony_ci}
30798c2ecf20Sopenharmony_ci
30808c2ecf20Sopenharmony_cistatic int bnx2x_bsc_read(struct link_params *params,
30818c2ecf20Sopenharmony_ci			  struct bnx2x *bp,
30828c2ecf20Sopenharmony_ci			  u8 sl_devid,
30838c2ecf20Sopenharmony_ci			  u16 sl_addr,
30848c2ecf20Sopenharmony_ci			  u8 lc_addr,
30858c2ecf20Sopenharmony_ci			  u8 xfer_cnt,
30868c2ecf20Sopenharmony_ci			  u32 *data_array)
30878c2ecf20Sopenharmony_ci{
30888c2ecf20Sopenharmony_ci	u64 t0, delta;
30898c2ecf20Sopenharmony_ci	u32 val, i;
30908c2ecf20Sopenharmony_ci	int rc = 0;
30918c2ecf20Sopenharmony_ci
30928c2ecf20Sopenharmony_ci	if (xfer_cnt > 16) {
30938c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
30948c2ecf20Sopenharmony_ci					xfer_cnt);
30958c2ecf20Sopenharmony_ci		return -EINVAL;
30968c2ecf20Sopenharmony_ci	}
30978c2ecf20Sopenharmony_ci	bnx2x_bsc_module_sel(params);
30988c2ecf20Sopenharmony_ci
30998c2ecf20Sopenharmony_ci	xfer_cnt = 16 - lc_addr;
31008c2ecf20Sopenharmony_ci
31018c2ecf20Sopenharmony_ci	/* Enable the engine */
31028c2ecf20Sopenharmony_ci	val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
31038c2ecf20Sopenharmony_ci	val |= MCPR_IMC_COMMAND_ENABLE;
31048c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
31058c2ecf20Sopenharmony_ci
31068c2ecf20Sopenharmony_ci	/* Program slave device ID */
31078c2ecf20Sopenharmony_ci	val = (sl_devid << 16) | sl_addr;
31088c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
31098c2ecf20Sopenharmony_ci
31108c2ecf20Sopenharmony_ci	/* Start xfer with 0 byte to update the address pointer ???*/
31118c2ecf20Sopenharmony_ci	val = (MCPR_IMC_COMMAND_ENABLE) |
31128c2ecf20Sopenharmony_ci	      (MCPR_IMC_COMMAND_WRITE_OP <<
31138c2ecf20Sopenharmony_ci		MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
31148c2ecf20Sopenharmony_ci		(lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
31158c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
31168c2ecf20Sopenharmony_ci
31178c2ecf20Sopenharmony_ci	/* Poll for completion */
31188c2ecf20Sopenharmony_ci	t0 = ktime_get_ns();
31198c2ecf20Sopenharmony_ci	val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
31208c2ecf20Sopenharmony_ci	while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
31218c2ecf20Sopenharmony_ci		delta = ktime_get_ns() - t0;
31228c2ecf20Sopenharmony_ci		if (delta > 10 * NSEC_PER_MSEC) {
31238c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "wr 0 byte timed out after %Lu ns\n",
31248c2ecf20Sopenharmony_ci					   delta);
31258c2ecf20Sopenharmony_ci			rc = -EFAULT;
31268c2ecf20Sopenharmony_ci			break;
31278c2ecf20Sopenharmony_ci		}
31288c2ecf20Sopenharmony_ci		usleep_range(10, 20);
31298c2ecf20Sopenharmony_ci		val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
31308c2ecf20Sopenharmony_ci	}
31318c2ecf20Sopenharmony_ci	if (rc == -EFAULT)
31328c2ecf20Sopenharmony_ci		return rc;
31338c2ecf20Sopenharmony_ci
31348c2ecf20Sopenharmony_ci	/* Start xfer with read op */
31358c2ecf20Sopenharmony_ci	val = (MCPR_IMC_COMMAND_ENABLE) |
31368c2ecf20Sopenharmony_ci		(MCPR_IMC_COMMAND_READ_OP <<
31378c2ecf20Sopenharmony_ci		MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
31388c2ecf20Sopenharmony_ci		(lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
31398c2ecf20Sopenharmony_ci		  (xfer_cnt);
31408c2ecf20Sopenharmony_ci	REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
31418c2ecf20Sopenharmony_ci
31428c2ecf20Sopenharmony_ci	/* Poll for completion */
31438c2ecf20Sopenharmony_ci	t0 = ktime_get_ns();
31448c2ecf20Sopenharmony_ci	val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
31458c2ecf20Sopenharmony_ci	while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
31468c2ecf20Sopenharmony_ci		delta = ktime_get_ns() - t0;
31478c2ecf20Sopenharmony_ci		if (delta > 10 * NSEC_PER_MSEC) {
31488c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "rd op timed out after %Lu ns\n",
31498c2ecf20Sopenharmony_ci					   delta);
31508c2ecf20Sopenharmony_ci			rc = -EFAULT;
31518c2ecf20Sopenharmony_ci			break;
31528c2ecf20Sopenharmony_ci		}
31538c2ecf20Sopenharmony_ci		usleep_range(10, 20);
31548c2ecf20Sopenharmony_ci		val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
31558c2ecf20Sopenharmony_ci	}
31568c2ecf20Sopenharmony_ci	if (rc == -EFAULT)
31578c2ecf20Sopenharmony_ci		return rc;
31588c2ecf20Sopenharmony_ci
31598c2ecf20Sopenharmony_ci	for (i = (lc_addr >> 2); i < 4; i++) {
31608c2ecf20Sopenharmony_ci		data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
31618c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
31628c2ecf20Sopenharmony_ci		data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
31638c2ecf20Sopenharmony_ci				((data_array[i] & 0x0000ff00) << 8) |
31648c2ecf20Sopenharmony_ci				((data_array[i] & 0x00ff0000) >> 8) |
31658c2ecf20Sopenharmony_ci				((data_array[i] & 0xff000000) >> 24);
31668c2ecf20Sopenharmony_ci#endif
31678c2ecf20Sopenharmony_ci	}
31688c2ecf20Sopenharmony_ci	return rc;
31698c2ecf20Sopenharmony_ci}
31708c2ecf20Sopenharmony_ci
31718c2ecf20Sopenharmony_cistatic void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
31728c2ecf20Sopenharmony_ci				     u8 devad, u16 reg, u16 or_val)
31738c2ecf20Sopenharmony_ci{
31748c2ecf20Sopenharmony_ci	u16 val;
31758c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, devad, reg, &val);
31768c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
31778c2ecf20Sopenharmony_ci}
31788c2ecf20Sopenharmony_ci
31798c2ecf20Sopenharmony_cistatic void bnx2x_cl45_read_and_write(struct bnx2x *bp,
31808c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
31818c2ecf20Sopenharmony_ci				      u8 devad, u16 reg, u16 and_val)
31828c2ecf20Sopenharmony_ci{
31838c2ecf20Sopenharmony_ci	u16 val;
31848c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, devad, reg, &val);
31858c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, devad, reg, val & and_val);
31868c2ecf20Sopenharmony_ci}
31878c2ecf20Sopenharmony_ci
31888c2ecf20Sopenharmony_ciint bnx2x_phy_read(struct link_params *params, u8 phy_addr,
31898c2ecf20Sopenharmony_ci		   u8 devad, u16 reg, u16 *ret_val)
31908c2ecf20Sopenharmony_ci{
31918c2ecf20Sopenharmony_ci	u8 phy_index;
31928c2ecf20Sopenharmony_ci	/* Probe for the phy according to the given phy_addr, and execute
31938c2ecf20Sopenharmony_ci	 * the read request on it
31948c2ecf20Sopenharmony_ci	 */
31958c2ecf20Sopenharmony_ci	for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
31968c2ecf20Sopenharmony_ci		if (params->phy[phy_index].addr == phy_addr) {
31978c2ecf20Sopenharmony_ci			return bnx2x_cl45_read(params->bp,
31988c2ecf20Sopenharmony_ci					       &params->phy[phy_index], devad,
31998c2ecf20Sopenharmony_ci					       reg, ret_val);
32008c2ecf20Sopenharmony_ci		}
32018c2ecf20Sopenharmony_ci	}
32028c2ecf20Sopenharmony_ci	return -EINVAL;
32038c2ecf20Sopenharmony_ci}
32048c2ecf20Sopenharmony_ci
32058c2ecf20Sopenharmony_ciint bnx2x_phy_write(struct link_params *params, u8 phy_addr,
32068c2ecf20Sopenharmony_ci		    u8 devad, u16 reg, u16 val)
32078c2ecf20Sopenharmony_ci{
32088c2ecf20Sopenharmony_ci	u8 phy_index;
32098c2ecf20Sopenharmony_ci	/* Probe for the phy according to the given phy_addr, and execute
32108c2ecf20Sopenharmony_ci	 * the write request on it
32118c2ecf20Sopenharmony_ci	 */
32128c2ecf20Sopenharmony_ci	for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
32138c2ecf20Sopenharmony_ci		if (params->phy[phy_index].addr == phy_addr) {
32148c2ecf20Sopenharmony_ci			return bnx2x_cl45_write(params->bp,
32158c2ecf20Sopenharmony_ci						&params->phy[phy_index], devad,
32168c2ecf20Sopenharmony_ci						reg, val);
32178c2ecf20Sopenharmony_ci		}
32188c2ecf20Sopenharmony_ci	}
32198c2ecf20Sopenharmony_ci	return -EINVAL;
32208c2ecf20Sopenharmony_ci}
32218c2ecf20Sopenharmony_cistatic u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
32228c2ecf20Sopenharmony_ci				  struct link_params *params)
32238c2ecf20Sopenharmony_ci{
32248c2ecf20Sopenharmony_ci	u8 lane = 0;
32258c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
32268c2ecf20Sopenharmony_ci	u32 path_swap, path_swap_ovr;
32278c2ecf20Sopenharmony_ci	u8 path, port;
32288c2ecf20Sopenharmony_ci
32298c2ecf20Sopenharmony_ci	path = BP_PATH(bp);
32308c2ecf20Sopenharmony_ci	port = params->port;
32318c2ecf20Sopenharmony_ci
32328c2ecf20Sopenharmony_ci	if (bnx2x_is_4_port_mode(bp)) {
32338c2ecf20Sopenharmony_ci		u32 port_swap, port_swap_ovr;
32348c2ecf20Sopenharmony_ci
32358c2ecf20Sopenharmony_ci		/* Figure out path swap value */
32368c2ecf20Sopenharmony_ci		path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
32378c2ecf20Sopenharmony_ci		if (path_swap_ovr & 0x1)
32388c2ecf20Sopenharmony_ci			path_swap = (path_swap_ovr & 0x2);
32398c2ecf20Sopenharmony_ci		else
32408c2ecf20Sopenharmony_ci			path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
32418c2ecf20Sopenharmony_ci
32428c2ecf20Sopenharmony_ci		if (path_swap)
32438c2ecf20Sopenharmony_ci			path = path ^ 1;
32448c2ecf20Sopenharmony_ci
32458c2ecf20Sopenharmony_ci		/* Figure out port swap value */
32468c2ecf20Sopenharmony_ci		port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
32478c2ecf20Sopenharmony_ci		if (port_swap_ovr & 0x1)
32488c2ecf20Sopenharmony_ci			port_swap = (port_swap_ovr & 0x2);
32498c2ecf20Sopenharmony_ci		else
32508c2ecf20Sopenharmony_ci			port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
32518c2ecf20Sopenharmony_ci
32528c2ecf20Sopenharmony_ci		if (port_swap)
32538c2ecf20Sopenharmony_ci			port = port ^ 1;
32548c2ecf20Sopenharmony_ci
32558c2ecf20Sopenharmony_ci		lane = (port<<1) + path;
32568c2ecf20Sopenharmony_ci	} else { /* Two port mode - no port swap */
32578c2ecf20Sopenharmony_ci
32588c2ecf20Sopenharmony_ci		/* Figure out path swap value */
32598c2ecf20Sopenharmony_ci		path_swap_ovr =
32608c2ecf20Sopenharmony_ci			REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
32618c2ecf20Sopenharmony_ci		if (path_swap_ovr & 0x1) {
32628c2ecf20Sopenharmony_ci			path_swap = (path_swap_ovr & 0x2);
32638c2ecf20Sopenharmony_ci		} else {
32648c2ecf20Sopenharmony_ci			path_swap =
32658c2ecf20Sopenharmony_ci				REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
32668c2ecf20Sopenharmony_ci		}
32678c2ecf20Sopenharmony_ci		if (path_swap)
32688c2ecf20Sopenharmony_ci			path = path ^ 1;
32698c2ecf20Sopenharmony_ci
32708c2ecf20Sopenharmony_ci		lane = path << 1 ;
32718c2ecf20Sopenharmony_ci	}
32728c2ecf20Sopenharmony_ci	return lane;
32738c2ecf20Sopenharmony_ci}
32748c2ecf20Sopenharmony_ci
32758c2ecf20Sopenharmony_cistatic void bnx2x_set_aer_mmd(struct link_params *params,
32768c2ecf20Sopenharmony_ci			      struct bnx2x_phy *phy)
32778c2ecf20Sopenharmony_ci{
32788c2ecf20Sopenharmony_ci	u32 ser_lane;
32798c2ecf20Sopenharmony_ci	u16 offset, aer_val;
32808c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
32818c2ecf20Sopenharmony_ci	ser_lane = ((params->lane_config &
32828c2ecf20Sopenharmony_ci		     PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
32838c2ecf20Sopenharmony_ci		     PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
32848c2ecf20Sopenharmony_ci
32858c2ecf20Sopenharmony_ci	offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
32868c2ecf20Sopenharmony_ci		(phy->addr + ser_lane) : 0;
32878c2ecf20Sopenharmony_ci
32888c2ecf20Sopenharmony_ci	if (USES_WARPCORE(bp)) {
32898c2ecf20Sopenharmony_ci		aer_val = bnx2x_get_warpcore_lane(phy, params);
32908c2ecf20Sopenharmony_ci		/* In Dual-lane mode, two lanes are joined together,
32918c2ecf20Sopenharmony_ci		 * so in order to configure them, the AER broadcast method is
32928c2ecf20Sopenharmony_ci		 * used here.
32938c2ecf20Sopenharmony_ci		 * 0x200 is the broadcast address for lanes 0,1
32948c2ecf20Sopenharmony_ci		 * 0x201 is the broadcast address for lanes 2,3
32958c2ecf20Sopenharmony_ci		 */
32968c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_WC_DUAL_MODE)
32978c2ecf20Sopenharmony_ci			aer_val = (aer_val >> 1) | 0x200;
32988c2ecf20Sopenharmony_ci	} else if (CHIP_IS_E2(bp))
32998c2ecf20Sopenharmony_ci		aer_val = 0x3800 + offset - 1;
33008c2ecf20Sopenharmony_ci	else
33018c2ecf20Sopenharmony_ci		aer_val = 0x3800 + offset;
33028c2ecf20Sopenharmony_ci
33038c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
33048c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, aer_val);
33058c2ecf20Sopenharmony_ci
33068c2ecf20Sopenharmony_ci}
33078c2ecf20Sopenharmony_ci
33088c2ecf20Sopenharmony_ci/******************************************************************/
33098c2ecf20Sopenharmony_ci/*			Internal phy section			  */
33108c2ecf20Sopenharmony_ci/******************************************************************/
33118c2ecf20Sopenharmony_ci
33128c2ecf20Sopenharmony_cistatic void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
33138c2ecf20Sopenharmony_ci{
33148c2ecf20Sopenharmony_ci	u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
33158c2ecf20Sopenharmony_ci
33168c2ecf20Sopenharmony_ci	/* Set Clause 22 */
33178c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
33188c2ecf20Sopenharmony_ci	REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
33198c2ecf20Sopenharmony_ci	udelay(500);
33208c2ecf20Sopenharmony_ci	REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
33218c2ecf20Sopenharmony_ci	udelay(500);
33228c2ecf20Sopenharmony_ci	 /* Set Clause 45 */
33238c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
33248c2ecf20Sopenharmony_ci}
33258c2ecf20Sopenharmony_ci
33268c2ecf20Sopenharmony_cistatic void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
33278c2ecf20Sopenharmony_ci{
33288c2ecf20Sopenharmony_ci	u32 val;
33298c2ecf20Sopenharmony_ci
33308c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
33318c2ecf20Sopenharmony_ci
33328c2ecf20Sopenharmony_ci	val = SERDES_RESET_BITS << (port*16);
33338c2ecf20Sopenharmony_ci
33348c2ecf20Sopenharmony_ci	/* Reset and unreset the SerDes/XGXS */
33358c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
33368c2ecf20Sopenharmony_ci	udelay(500);
33378c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
33388c2ecf20Sopenharmony_ci
33398c2ecf20Sopenharmony_ci	bnx2x_set_serdes_access(bp, port);
33408c2ecf20Sopenharmony_ci
33418c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
33428c2ecf20Sopenharmony_ci	       DEFAULT_PHY_DEV_ADDR);
33438c2ecf20Sopenharmony_ci}
33448c2ecf20Sopenharmony_ci
33458c2ecf20Sopenharmony_cistatic void bnx2x_xgxs_specific_func(struct bnx2x_phy *phy,
33468c2ecf20Sopenharmony_ci				     struct link_params *params,
33478c2ecf20Sopenharmony_ci				     u32 action)
33488c2ecf20Sopenharmony_ci{
33498c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
33508c2ecf20Sopenharmony_ci	switch (action) {
33518c2ecf20Sopenharmony_ci	case PHY_INIT:
33528c2ecf20Sopenharmony_ci		/* Set correct devad */
33538c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + params->port*0x18, 0);
33548c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + params->port*0x18,
33558c2ecf20Sopenharmony_ci		       phy->def_md_devad);
33568c2ecf20Sopenharmony_ci		break;
33578c2ecf20Sopenharmony_ci	}
33588c2ecf20Sopenharmony_ci}
33598c2ecf20Sopenharmony_ci
33608c2ecf20Sopenharmony_cistatic void bnx2x_xgxs_deassert(struct link_params *params)
33618c2ecf20Sopenharmony_ci{
33628c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
33638c2ecf20Sopenharmony_ci	u8 port;
33648c2ecf20Sopenharmony_ci	u32 val;
33658c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
33668c2ecf20Sopenharmony_ci	port = params->port;
33678c2ecf20Sopenharmony_ci
33688c2ecf20Sopenharmony_ci	val = XGXS_RESET_BITS << (port*16);
33698c2ecf20Sopenharmony_ci
33708c2ecf20Sopenharmony_ci	/* Reset and unreset the SerDes/XGXS */
33718c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
33728c2ecf20Sopenharmony_ci	udelay(500);
33738c2ecf20Sopenharmony_ci	REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
33748c2ecf20Sopenharmony_ci	bnx2x_xgxs_specific_func(&params->phy[INT_PHY], params,
33758c2ecf20Sopenharmony_ci				 PHY_INIT);
33768c2ecf20Sopenharmony_ci}
33778c2ecf20Sopenharmony_ci
33788c2ecf20Sopenharmony_cistatic void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
33798c2ecf20Sopenharmony_ci				     struct link_params *params, u16 *ieee_fc)
33808c2ecf20Sopenharmony_ci{
33818c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
33828c2ecf20Sopenharmony_ci	*ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
33838c2ecf20Sopenharmony_ci	/* Resolve pause mode and advertisement Please refer to Table
33848c2ecf20Sopenharmony_ci	 * 28B-3 of the 802.3ab-1999 spec
33858c2ecf20Sopenharmony_ci	 */
33868c2ecf20Sopenharmony_ci
33878c2ecf20Sopenharmony_ci	switch (phy->req_flow_ctrl) {
33888c2ecf20Sopenharmony_ci	case BNX2X_FLOW_CTRL_AUTO:
33898c2ecf20Sopenharmony_ci		switch (params->req_fc_auto_adv) {
33908c2ecf20Sopenharmony_ci		case BNX2X_FLOW_CTRL_BOTH:
33918c2ecf20Sopenharmony_ci		case BNX2X_FLOW_CTRL_RX:
33928c2ecf20Sopenharmony_ci			*ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
33938c2ecf20Sopenharmony_ci			break;
33948c2ecf20Sopenharmony_ci		case BNX2X_FLOW_CTRL_TX:
33958c2ecf20Sopenharmony_ci			*ieee_fc |=
33968c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
33978c2ecf20Sopenharmony_ci			break;
33988c2ecf20Sopenharmony_ci		default:
33998c2ecf20Sopenharmony_ci			break;
34008c2ecf20Sopenharmony_ci		}
34018c2ecf20Sopenharmony_ci		break;
34028c2ecf20Sopenharmony_ci	case BNX2X_FLOW_CTRL_TX:
34038c2ecf20Sopenharmony_ci		*ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
34048c2ecf20Sopenharmony_ci		break;
34058c2ecf20Sopenharmony_ci
34068c2ecf20Sopenharmony_ci	case BNX2X_FLOW_CTRL_RX:
34078c2ecf20Sopenharmony_ci	case BNX2X_FLOW_CTRL_BOTH:
34088c2ecf20Sopenharmony_ci		*ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
34098c2ecf20Sopenharmony_ci		break;
34108c2ecf20Sopenharmony_ci
34118c2ecf20Sopenharmony_ci	case BNX2X_FLOW_CTRL_NONE:
34128c2ecf20Sopenharmony_ci	default:
34138c2ecf20Sopenharmony_ci		*ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
34148c2ecf20Sopenharmony_ci		break;
34158c2ecf20Sopenharmony_ci	}
34168c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
34178c2ecf20Sopenharmony_ci}
34188c2ecf20Sopenharmony_ci
34198c2ecf20Sopenharmony_cistatic void set_phy_vars(struct link_params *params,
34208c2ecf20Sopenharmony_ci			 struct link_vars *vars)
34218c2ecf20Sopenharmony_ci{
34228c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
34238c2ecf20Sopenharmony_ci	u8 actual_phy_idx, phy_index, link_cfg_idx;
34248c2ecf20Sopenharmony_ci	u8 phy_config_swapped = params->multi_phy_config &
34258c2ecf20Sopenharmony_ci			PORT_HW_CFG_PHY_SWAPPED_ENABLED;
34268c2ecf20Sopenharmony_ci	for (phy_index = INT_PHY; phy_index < params->num_phys;
34278c2ecf20Sopenharmony_ci	      phy_index++) {
34288c2ecf20Sopenharmony_ci		link_cfg_idx = LINK_CONFIG_IDX(phy_index);
34298c2ecf20Sopenharmony_ci		actual_phy_idx = phy_index;
34308c2ecf20Sopenharmony_ci		if (phy_config_swapped) {
34318c2ecf20Sopenharmony_ci			if (phy_index == EXT_PHY1)
34328c2ecf20Sopenharmony_ci				actual_phy_idx = EXT_PHY2;
34338c2ecf20Sopenharmony_ci			else if (phy_index == EXT_PHY2)
34348c2ecf20Sopenharmony_ci				actual_phy_idx = EXT_PHY1;
34358c2ecf20Sopenharmony_ci		}
34368c2ecf20Sopenharmony_ci		params->phy[actual_phy_idx].req_flow_ctrl =
34378c2ecf20Sopenharmony_ci			params->req_flow_ctrl[link_cfg_idx];
34388c2ecf20Sopenharmony_ci
34398c2ecf20Sopenharmony_ci		params->phy[actual_phy_idx].req_line_speed =
34408c2ecf20Sopenharmony_ci			params->req_line_speed[link_cfg_idx];
34418c2ecf20Sopenharmony_ci
34428c2ecf20Sopenharmony_ci		params->phy[actual_phy_idx].speed_cap_mask =
34438c2ecf20Sopenharmony_ci			params->speed_cap_mask[link_cfg_idx];
34448c2ecf20Sopenharmony_ci
34458c2ecf20Sopenharmony_ci		params->phy[actual_phy_idx].req_duplex =
34468c2ecf20Sopenharmony_ci			params->req_duplex[link_cfg_idx];
34478c2ecf20Sopenharmony_ci
34488c2ecf20Sopenharmony_ci		if (params->req_line_speed[link_cfg_idx] ==
34498c2ecf20Sopenharmony_ci		    SPEED_AUTO_NEG)
34508c2ecf20Sopenharmony_ci			vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
34518c2ecf20Sopenharmony_ci
34528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
34538c2ecf20Sopenharmony_ci			   " speed_cap_mask %x\n",
34548c2ecf20Sopenharmony_ci			   params->phy[actual_phy_idx].req_flow_ctrl,
34558c2ecf20Sopenharmony_ci			   params->phy[actual_phy_idx].req_line_speed,
34568c2ecf20Sopenharmony_ci			   params->phy[actual_phy_idx].speed_cap_mask);
34578c2ecf20Sopenharmony_ci	}
34588c2ecf20Sopenharmony_ci}
34598c2ecf20Sopenharmony_ci
34608c2ecf20Sopenharmony_cistatic void bnx2x_ext_phy_set_pause(struct link_params *params,
34618c2ecf20Sopenharmony_ci				    struct bnx2x_phy *phy,
34628c2ecf20Sopenharmony_ci				    struct link_vars *vars)
34638c2ecf20Sopenharmony_ci{
34648c2ecf20Sopenharmony_ci	u16 val;
34658c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
34668c2ecf20Sopenharmony_ci	/* Read modify write pause advertizing */
34678c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
34688c2ecf20Sopenharmony_ci
34698c2ecf20Sopenharmony_ci	val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
34708c2ecf20Sopenharmony_ci
34718c2ecf20Sopenharmony_ci	/* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
34728c2ecf20Sopenharmony_ci	bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
34738c2ecf20Sopenharmony_ci	if ((vars->ieee_fc &
34748c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
34758c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
34768c2ecf20Sopenharmony_ci		val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
34778c2ecf20Sopenharmony_ci	}
34788c2ecf20Sopenharmony_ci	if ((vars->ieee_fc &
34798c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
34808c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
34818c2ecf20Sopenharmony_ci		val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
34828c2ecf20Sopenharmony_ci	}
34838c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
34848c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
34858c2ecf20Sopenharmony_ci}
34868c2ecf20Sopenharmony_ci
34878c2ecf20Sopenharmony_cistatic void bnx2x_pause_resolve(struct bnx2x_phy *phy,
34888c2ecf20Sopenharmony_ci				struct link_params *params,
34898c2ecf20Sopenharmony_ci				struct link_vars *vars,
34908c2ecf20Sopenharmony_ci				u32 pause_result)
34918c2ecf20Sopenharmony_ci{
34928c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
34938c2ecf20Sopenharmony_ci						/*  LD	    LP	 */
34948c2ecf20Sopenharmony_ci	switch (pause_result) {			/* ASYM P ASYM P */
34958c2ecf20Sopenharmony_ci	case 0xb:				/*   1  0   1  1 */
34968c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Flow Control: TX only\n");
34978c2ecf20Sopenharmony_ci		vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
34988c2ecf20Sopenharmony_ci		break;
34998c2ecf20Sopenharmony_ci
35008c2ecf20Sopenharmony_ci	case 0xe:				/*   1  1   1  0 */
35018c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Flow Control: RX only\n");
35028c2ecf20Sopenharmony_ci		vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
35038c2ecf20Sopenharmony_ci		break;
35048c2ecf20Sopenharmony_ci
35058c2ecf20Sopenharmony_ci	case 0x5:				/*   0  1   0  1 */
35068c2ecf20Sopenharmony_ci	case 0x7:				/*   0  1   1  1 */
35078c2ecf20Sopenharmony_ci	case 0xd:				/*   1  1   0  1 */
35088c2ecf20Sopenharmony_ci	case 0xf:				/*   1  1   1  1 */
35098c2ecf20Sopenharmony_ci		/* If the user selected to advertise RX ONLY,
35108c2ecf20Sopenharmony_ci		 * although we advertised both, need to enable
35118c2ecf20Sopenharmony_ci		 * RX only.
35128c2ecf20Sopenharmony_ci		 */
35138c2ecf20Sopenharmony_ci		if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH) {
35148c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Flow Control: RX & TX\n");
35158c2ecf20Sopenharmony_ci			vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
35168c2ecf20Sopenharmony_ci		} else {
35178c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Flow Control: RX only\n");
35188c2ecf20Sopenharmony_ci			vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
35198c2ecf20Sopenharmony_ci		}
35208c2ecf20Sopenharmony_ci		break;
35218c2ecf20Sopenharmony_ci
35228c2ecf20Sopenharmony_ci	default:
35238c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Flow Control: None\n");
35248c2ecf20Sopenharmony_ci		vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
35258c2ecf20Sopenharmony_ci		break;
35268c2ecf20Sopenharmony_ci	}
35278c2ecf20Sopenharmony_ci	if (pause_result & (1<<0))
35288c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
35298c2ecf20Sopenharmony_ci	if (pause_result & (1<<1))
35308c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
35318c2ecf20Sopenharmony_ci
35328c2ecf20Sopenharmony_ci}
35338c2ecf20Sopenharmony_ci
35348c2ecf20Sopenharmony_cistatic void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
35358c2ecf20Sopenharmony_ci					struct link_params *params,
35368c2ecf20Sopenharmony_ci					struct link_vars *vars)
35378c2ecf20Sopenharmony_ci{
35388c2ecf20Sopenharmony_ci	u16 ld_pause;		/* local */
35398c2ecf20Sopenharmony_ci	u16 lp_pause;		/* link partner */
35408c2ecf20Sopenharmony_ci	u16 pause_result;
35418c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
35428c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
35438c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
35448c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
35458c2ecf20Sopenharmony_ci	} else if (CHIP_IS_E3(bp) &&
35468c2ecf20Sopenharmony_ci		SINGLE_MEDIA_DIRECT(params)) {
35478c2ecf20Sopenharmony_ci		u8 lane = bnx2x_get_warpcore_lane(phy, params);
35488c2ecf20Sopenharmony_ci		u16 gp_status, gp_mask;
35498c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
35508c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
35518c2ecf20Sopenharmony_ci				&gp_status);
35528c2ecf20Sopenharmony_ci		gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
35538c2ecf20Sopenharmony_ci			   MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
35548c2ecf20Sopenharmony_ci			lane;
35558c2ecf20Sopenharmony_ci		if ((gp_status & gp_mask) == gp_mask) {
35568c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
35578c2ecf20Sopenharmony_ci					MDIO_AN_REG_ADV_PAUSE, &ld_pause);
35588c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
35598c2ecf20Sopenharmony_ci					MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
35608c2ecf20Sopenharmony_ci		} else {
35618c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
35628c2ecf20Sopenharmony_ci					MDIO_AN_REG_CL37_FC_LD, &ld_pause);
35638c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
35648c2ecf20Sopenharmony_ci					MDIO_AN_REG_CL37_FC_LP, &lp_pause);
35658c2ecf20Sopenharmony_ci			ld_pause = ((ld_pause &
35668c2ecf20Sopenharmony_ci				     MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
35678c2ecf20Sopenharmony_ci				    << 3);
35688c2ecf20Sopenharmony_ci			lp_pause = ((lp_pause &
35698c2ecf20Sopenharmony_ci				     MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
35708c2ecf20Sopenharmony_ci				    << 3);
35718c2ecf20Sopenharmony_ci		}
35728c2ecf20Sopenharmony_ci	} else {
35738c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
35748c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
35758c2ecf20Sopenharmony_ci				MDIO_AN_REG_ADV_PAUSE, &ld_pause);
35768c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
35778c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
35788c2ecf20Sopenharmony_ci				MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
35798c2ecf20Sopenharmony_ci	}
35808c2ecf20Sopenharmony_ci	pause_result = (ld_pause &
35818c2ecf20Sopenharmony_ci			MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
35828c2ecf20Sopenharmony_ci	pause_result |= (lp_pause &
35838c2ecf20Sopenharmony_ci			 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
35848c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n", pause_result);
35858c2ecf20Sopenharmony_ci	bnx2x_pause_resolve(phy, params, vars, pause_result);
35868c2ecf20Sopenharmony_ci
35878c2ecf20Sopenharmony_ci}
35888c2ecf20Sopenharmony_ci
35898c2ecf20Sopenharmony_cistatic u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
35908c2ecf20Sopenharmony_ci				   struct link_params *params,
35918c2ecf20Sopenharmony_ci				   struct link_vars *vars)
35928c2ecf20Sopenharmony_ci{
35938c2ecf20Sopenharmony_ci	u8 ret = 0;
35948c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
35958c2ecf20Sopenharmony_ci	if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
35968c2ecf20Sopenharmony_ci		/* Update the advertised flow-controled of LD/LP in AN */
35978c2ecf20Sopenharmony_ci		if (phy->req_line_speed == SPEED_AUTO_NEG)
35988c2ecf20Sopenharmony_ci			bnx2x_ext_phy_update_adv_fc(phy, params, vars);
35998c2ecf20Sopenharmony_ci		/* But set the flow-control result as the requested one */
36008c2ecf20Sopenharmony_ci		vars->flow_ctrl = phy->req_flow_ctrl;
36018c2ecf20Sopenharmony_ci	} else if (phy->req_line_speed != SPEED_AUTO_NEG)
36028c2ecf20Sopenharmony_ci		vars->flow_ctrl = params->req_fc_auto_adv;
36038c2ecf20Sopenharmony_ci	else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
36048c2ecf20Sopenharmony_ci		ret = 1;
36058c2ecf20Sopenharmony_ci		bnx2x_ext_phy_update_adv_fc(phy, params, vars);
36068c2ecf20Sopenharmony_ci	}
36078c2ecf20Sopenharmony_ci	return ret;
36088c2ecf20Sopenharmony_ci}
36098c2ecf20Sopenharmony_ci/******************************************************************/
36108c2ecf20Sopenharmony_ci/*			Warpcore section			  */
36118c2ecf20Sopenharmony_ci/******************************************************************/
36128c2ecf20Sopenharmony_ci/* The init_internal_warpcore should mirror the xgxs,
36138c2ecf20Sopenharmony_ci * i.e. reset the lane (if needed), set aer for the
36148c2ecf20Sopenharmony_ci * init configuration, and set/clear SGMII flag. Internal
36158c2ecf20Sopenharmony_ci * phy init is done purely in phy_init stage.
36168c2ecf20Sopenharmony_ci */
36178c2ecf20Sopenharmony_ci#define WC_TX_DRIVER(post2, idriver, ipre, ifir) \
36188c2ecf20Sopenharmony_ci	((post2 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) | \
36198c2ecf20Sopenharmony_ci	 (idriver << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) | \
36208c2ecf20Sopenharmony_ci	 (ipre << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET) | \
36218c2ecf20Sopenharmony_ci	 (ifir << MDIO_WC_REG_TX0_TX_DRIVER_IFIR_OFFSET))
36228c2ecf20Sopenharmony_ci
36238c2ecf20Sopenharmony_ci#define WC_TX_FIR(post, main, pre) \
36248c2ecf20Sopenharmony_ci	((post << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) | \
36258c2ecf20Sopenharmony_ci	 (main << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) | \
36268c2ecf20Sopenharmony_ci	 (pre << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET))
36278c2ecf20Sopenharmony_ci
36288c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_enable_AN_KR2(struct bnx2x_phy *phy,
36298c2ecf20Sopenharmony_ci					 struct link_params *params,
36308c2ecf20Sopenharmony_ci					 struct link_vars *vars)
36318c2ecf20Sopenharmony_ci{
36328c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
36338c2ecf20Sopenharmony_ci	u16 i;
36348c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
36358c2ecf20Sopenharmony_ci		/* Step 1 - Program the TX/RX alignment markers */
36368c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0xa157},
36378c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xcbe2},
36388c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0x7537},
36398c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0xa157},
36408c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xcbe2},
36418c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0x7537},
36428c2ecf20Sopenharmony_ci		/* Step 2 - Configure the NP registers */
36438c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000a},
36448c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6400},
36458c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0620},
36468c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0157},
36478c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x6464},
36488c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x3150},
36498c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x3150},
36508c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0157},
36518c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0620}
36528c2ecf20Sopenharmony_ci	};
36538c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Enabling 20G-KR2\n");
36548c2ecf20Sopenharmony_ci
36558c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
36568c2ecf20Sopenharmony_ci				 MDIO_WC_REG_CL49_USERB0_CTRL, (3<<6));
36578c2ecf20Sopenharmony_ci
36588c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(reg_set); i++)
36598c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
36608c2ecf20Sopenharmony_ci				 reg_set[i].val);
36618c2ecf20Sopenharmony_ci
36628c2ecf20Sopenharmony_ci	/* Start KR2 work-around timer which handles BCM8073 link-parner */
36638c2ecf20Sopenharmony_ci	params->link_attr_sync |= LINK_ATTR_SYNC_KR2_ENABLE;
36648c2ecf20Sopenharmony_ci	bnx2x_update_link_attr(params, params->link_attr_sync);
36658c2ecf20Sopenharmony_ci}
36668c2ecf20Sopenharmony_ci
36678c2ecf20Sopenharmony_cistatic void bnx2x_disable_kr2(struct link_params *params,
36688c2ecf20Sopenharmony_ci			      struct link_vars *vars,
36698c2ecf20Sopenharmony_ci			      struct bnx2x_phy *phy)
36708c2ecf20Sopenharmony_ci{
36718c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
36728c2ecf20Sopenharmony_ci	int i;
36738c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
36748c2ecf20Sopenharmony_ci		/* Step 1 - Program the TX/RX alignment markers */
36758c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0x7690},
36768c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xe647},
36778c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0xc4f0},
36788c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0x7690},
36798c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xe647},
36808c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0xc4f0},
36818c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000c},
36828c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6000},
36838c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0000},
36848c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0002},
36858c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x0000},
36868c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x0af7},
36878c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x0af7},
36888c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0002},
36898c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0000}
36908c2ecf20Sopenharmony_ci	};
36918c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Disabling 20G-KR2\n");
36928c2ecf20Sopenharmony_ci
36938c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(reg_set); i++)
36948c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
36958c2ecf20Sopenharmony_ci				 reg_set[i].val);
36968c2ecf20Sopenharmony_ci	params->link_attr_sync &= ~LINK_ATTR_SYNC_KR2_ENABLE;
36978c2ecf20Sopenharmony_ci	bnx2x_update_link_attr(params, params->link_attr_sync);
36988c2ecf20Sopenharmony_ci
36998c2ecf20Sopenharmony_ci	vars->check_kr2_recovery_cnt = CHECK_KR2_RECOVERY_CNT;
37008c2ecf20Sopenharmony_ci}
37018c2ecf20Sopenharmony_ci
37028c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_lpi_passthrough(struct bnx2x_phy *phy,
37038c2ecf20Sopenharmony_ci					       struct link_params *params)
37048c2ecf20Sopenharmony_ci{
37058c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
37068c2ecf20Sopenharmony_ci
37078c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Configure WC for LPI pass through\n");
37088c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37098c2ecf20Sopenharmony_ci			 MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
37108c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
37118c2ecf20Sopenharmony_ci				 MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
37128c2ecf20Sopenharmony_ci}
37138c2ecf20Sopenharmony_ci
37148c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_restart_AN_KR(struct bnx2x_phy *phy,
37158c2ecf20Sopenharmony_ci					 struct link_params *params)
37168c2ecf20Sopenharmony_ci{
37178c2ecf20Sopenharmony_ci	/* Restart autoneg on the leading lane only */
37188c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
37198c2ecf20Sopenharmony_ci	u16 lane = bnx2x_get_warpcore_lane(phy, params);
37208c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
37218c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, lane);
37228c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
37238c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
37248c2ecf20Sopenharmony_ci
37258c2ecf20Sopenharmony_ci	/* Restore AER */
37268c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
37278c2ecf20Sopenharmony_ci}
37288c2ecf20Sopenharmony_ci
37298c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
37308c2ecf20Sopenharmony_ci					struct link_params *params,
37318c2ecf20Sopenharmony_ci					struct link_vars *vars) {
37328c2ecf20Sopenharmony_ci	u16 lane, i, cl72_ctrl, an_adv = 0, val;
37338c2ecf20Sopenharmony_ci	u32 wc_lane_config;
37348c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
37358c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
37368c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
37378c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
37388c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
37398c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
37408c2ecf20Sopenharmony_ci		/* Disable Autoneg: re-enable it after adv is done. */
37418c2ecf20Sopenharmony_ci		{MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0},
37428c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2},
37438c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0},
37448c2ecf20Sopenharmony_ci	};
37458c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
37468c2ecf20Sopenharmony_ci	/* Set to default registers that may be overriden by 10G force */
37478c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(reg_set); i++)
37488c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
37498c2ecf20Sopenharmony_ci				 reg_set[i].val);
37508c2ecf20Sopenharmony_ci
37518c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
37528c2ecf20Sopenharmony_ci			MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &cl72_ctrl);
37538c2ecf20Sopenharmony_ci	cl72_ctrl &= 0x08ff;
37548c2ecf20Sopenharmony_ci	cl72_ctrl |= 0x3800;
37558c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37568c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, cl72_ctrl);
37578c2ecf20Sopenharmony_ci
37588c2ecf20Sopenharmony_ci	/* Check adding advertisement for 1G KX */
37598c2ecf20Sopenharmony_ci	if (((vars->line_speed == SPEED_AUTO_NEG) &&
37608c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
37618c2ecf20Sopenharmony_ci	    (vars->line_speed == SPEED_1000)) {
37628c2ecf20Sopenharmony_ci		u16 addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
37638c2ecf20Sopenharmony_ci		an_adv |= (1<<5);
37648c2ecf20Sopenharmony_ci
37658c2ecf20Sopenharmony_ci		/* Enable CL37 1G Parallel Detect */
37668c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD, addr, 0x1);
37678c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertize 1G\n");
37688c2ecf20Sopenharmony_ci	}
37698c2ecf20Sopenharmony_ci	if (((vars->line_speed == SPEED_AUTO_NEG) &&
37708c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
37718c2ecf20Sopenharmony_ci	    (vars->line_speed ==  SPEED_10000)) {
37728c2ecf20Sopenharmony_ci		/* Check adding advertisement for 10G KR */
37738c2ecf20Sopenharmony_ci		an_adv |= (1<<7);
37748c2ecf20Sopenharmony_ci		/* Enable 10G Parallel Detect */
37758c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
37768c2ecf20Sopenharmony_ci				  MDIO_AER_BLOCK_AER_REG, 0);
37778c2ecf20Sopenharmony_ci
37788c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
37798c2ecf20Sopenharmony_ci				 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
37808c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
37818c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertize 10G\n");
37828c2ecf20Sopenharmony_ci	}
37838c2ecf20Sopenharmony_ci
37848c2ecf20Sopenharmony_ci	/* Set Transmit PMD settings */
37858c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
37868c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37878c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
37888c2ecf20Sopenharmony_ci			 WC_TX_DRIVER(0x02, 0x06, 0x09, 0));
37898c2ecf20Sopenharmony_ci	/* Configure the next lane if dual mode */
37908c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_WC_DUAL_MODE)
37918c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37928c2ecf20Sopenharmony_ci				 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*(lane+1),
37938c2ecf20Sopenharmony_ci				 WC_TX_DRIVER(0x02, 0x06, 0x09, 0));
37948c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37958c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
37968c2ecf20Sopenharmony_ci			 0x03f0);
37978c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
37988c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
37998c2ecf20Sopenharmony_ci			 0x03f0);
38008c2ecf20Sopenharmony_ci
38018c2ecf20Sopenharmony_ci	/* Advertised speeds */
38028c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
38038c2ecf20Sopenharmony_ci			 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, an_adv);
38048c2ecf20Sopenharmony_ci
38058c2ecf20Sopenharmony_ci	/* Advertised and set FEC (Forward Error Correction) */
38068c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
38078c2ecf20Sopenharmony_ci			 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
38088c2ecf20Sopenharmony_ci			 (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
38098c2ecf20Sopenharmony_ci			  MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
38108c2ecf20Sopenharmony_ci
38118c2ecf20Sopenharmony_ci	/* Enable CL37 BAM */
38128c2ecf20Sopenharmony_ci	if (REG_RD(bp, params->shmem_base +
38138c2ecf20Sopenharmony_ci		   offsetof(struct shmem_region, dev_info.
38148c2ecf20Sopenharmony_ci			    port_hw_config[params->port].default_cfg)) &
38158c2ecf20Sopenharmony_ci	    PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
38168c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
38178c2ecf20Sopenharmony_ci					 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
38188c2ecf20Sopenharmony_ci					 1);
38198c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
38208c2ecf20Sopenharmony_ci	}
38218c2ecf20Sopenharmony_ci
38228c2ecf20Sopenharmony_ci	/* Advertise pause */
38238c2ecf20Sopenharmony_ci	bnx2x_ext_phy_set_pause(params, phy, vars);
38248c2ecf20Sopenharmony_ci	vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
38258c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
38268c2ecf20Sopenharmony_ci				 MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
38278c2ecf20Sopenharmony_ci
38288c2ecf20Sopenharmony_ci	/* Over 1G - AN local device user page 1 */
38298c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
38308c2ecf20Sopenharmony_ci			MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
38318c2ecf20Sopenharmony_ci
38328c2ecf20Sopenharmony_ci	if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
38338c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
38348c2ecf20Sopenharmony_ci	    (phy->req_line_speed == SPEED_20000)) {
38358c2ecf20Sopenharmony_ci
38368c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
38378c2ecf20Sopenharmony_ci				  MDIO_AER_BLOCK_AER_REG, lane);
38388c2ecf20Sopenharmony_ci
38398c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
38408c2ecf20Sopenharmony_ci					 MDIO_WC_REG_RX1_PCI_CTRL + (0x10*lane),
38418c2ecf20Sopenharmony_ci					 (1<<11));
38428c2ecf20Sopenharmony_ci
38438c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
38448c2ecf20Sopenharmony_ci				 MDIO_WC_REG_XGXS_X2_CONTROL3, 0x7);
38458c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
38468c2ecf20Sopenharmony_ci
38478c2ecf20Sopenharmony_ci		bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
38488c2ecf20Sopenharmony_ci	} else {
38498c2ecf20Sopenharmony_ci		/* Enable Auto-Detect to support 1G over CL37 as well */
38508c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
38518c2ecf20Sopenharmony_ci				 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0x10);
38528c2ecf20Sopenharmony_ci		wc_lane_config = REG_RD(bp, params->shmem_base +
38538c2ecf20Sopenharmony_ci					offsetof(struct shmem_region, dev_info.
38548c2ecf20Sopenharmony_ci					shared_hw_config.wc_lane_config));
38558c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
38568c2ecf20Sopenharmony_ci				MDIO_WC_REG_RX0_PCI_CTRL + (lane << 4), &val);
38578c2ecf20Sopenharmony_ci		/* Force cl48 sync_status LOW to avoid getting stuck in CL73
38588c2ecf20Sopenharmony_ci		 * parallel-detect loop when CL73 and CL37 are enabled.
38598c2ecf20Sopenharmony_ci		 */
38608c2ecf20Sopenharmony_ci		val |= 1 << 11;
38618c2ecf20Sopenharmony_ci
38628c2ecf20Sopenharmony_ci		/* Restore Polarity settings in case it was run over by
38638c2ecf20Sopenharmony_ci		 * previous link owner
38648c2ecf20Sopenharmony_ci		 */
38658c2ecf20Sopenharmony_ci		if (wc_lane_config &
38668c2ecf20Sopenharmony_ci		    (SHARED_HW_CFG_RX_LANE0_POL_FLIP_ENABLED << lane))
38678c2ecf20Sopenharmony_ci			val |= 3 << 2;
38688c2ecf20Sopenharmony_ci		else
38698c2ecf20Sopenharmony_ci			val &= ~(3 << 2);
38708c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
38718c2ecf20Sopenharmony_ci				 MDIO_WC_REG_RX0_PCI_CTRL + (lane << 4),
38728c2ecf20Sopenharmony_ci				 val);
38738c2ecf20Sopenharmony_ci
38748c2ecf20Sopenharmony_ci		bnx2x_disable_kr2(params, vars, phy);
38758c2ecf20Sopenharmony_ci	}
38768c2ecf20Sopenharmony_ci
38778c2ecf20Sopenharmony_ci	/* Enable Autoneg: only on the main lane */
38788c2ecf20Sopenharmony_ci	bnx2x_warpcore_restart_AN_KR(phy, params);
38798c2ecf20Sopenharmony_ci}
38808c2ecf20Sopenharmony_ci
38818c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
38828c2ecf20Sopenharmony_ci				      struct link_params *params,
38838c2ecf20Sopenharmony_ci				      struct link_vars *vars)
38848c2ecf20Sopenharmony_ci{
38858c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
38868c2ecf20Sopenharmony_ci	u16 val16, i, lane;
38878c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
38888c2ecf20Sopenharmony_ci		/* Disable Autoneg */
38898c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
38908c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
38918c2ecf20Sopenharmony_ci			0x3f00},
38928c2ecf20Sopenharmony_ci		{MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
38938c2ecf20Sopenharmony_ci		{MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
38948c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
38958c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
38968c2ecf20Sopenharmony_ci		/* Leave cl72 training enable, needed for KR */
38978c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2}
38988c2ecf20Sopenharmony_ci	};
38998c2ecf20Sopenharmony_ci
39008c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(reg_set); i++)
39018c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
39028c2ecf20Sopenharmony_ci				 reg_set[i].val);
39038c2ecf20Sopenharmony_ci
39048c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
39058c2ecf20Sopenharmony_ci	/* Global registers */
39068c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
39078c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, 0);
39088c2ecf20Sopenharmony_ci	/* Disable CL36 PCS Tx */
39098c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
39108c2ecf20Sopenharmony_ci			MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
39118c2ecf20Sopenharmony_ci	val16 &= ~(0x0011 << lane);
39128c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39138c2ecf20Sopenharmony_ci			 MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
39148c2ecf20Sopenharmony_ci
39158c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
39168c2ecf20Sopenharmony_ci			MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
39178c2ecf20Sopenharmony_ci	val16 |= (0x0303 << (lane << 1));
39188c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39198c2ecf20Sopenharmony_ci			 MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
39208c2ecf20Sopenharmony_ci	/* Restore AER */
39218c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
39228c2ecf20Sopenharmony_ci	/* Set speed via PMA/PMD register */
39238c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
39248c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
39258c2ecf20Sopenharmony_ci
39268c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
39278c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
39288c2ecf20Sopenharmony_ci
39298c2ecf20Sopenharmony_ci	/* Enable encoded forced speed */
39308c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39318c2ecf20Sopenharmony_ci			 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
39328c2ecf20Sopenharmony_ci
39338c2ecf20Sopenharmony_ci	/* Turn TX scramble payload only the 64/66 scrambler */
39348c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39358c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX66_CONTROL, 0x9);
39368c2ecf20Sopenharmony_ci
39378c2ecf20Sopenharmony_ci	/* Turn RX scramble payload only the 64/66 scrambler */
39388c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
39398c2ecf20Sopenharmony_ci				 MDIO_WC_REG_RX66_CONTROL, 0xF9);
39408c2ecf20Sopenharmony_ci
39418c2ecf20Sopenharmony_ci	/* Set and clear loopback to cause a reset to 64/66 decoder */
39428c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39438c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
39448c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39458c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
39468c2ecf20Sopenharmony_ci
39478c2ecf20Sopenharmony_ci}
39488c2ecf20Sopenharmony_ci
39498c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
39508c2ecf20Sopenharmony_ci				       struct link_params *params,
39518c2ecf20Sopenharmony_ci				       u8 is_xfi)
39528c2ecf20Sopenharmony_ci{
39538c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
39548c2ecf20Sopenharmony_ci	u16 misc1_val, tap_val, tx_driver_val, lane, val;
39558c2ecf20Sopenharmony_ci	u32 cfg_tap_val, tx_drv_brdct, tx_equal;
39568c2ecf20Sopenharmony_ci	u32 ifir_val, ipost2_val, ipre_driver_val;
39578c2ecf20Sopenharmony_ci
39588c2ecf20Sopenharmony_ci	/* Hold rxSeqStart */
39598c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
39608c2ecf20Sopenharmony_ci				 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
39618c2ecf20Sopenharmony_ci
39628c2ecf20Sopenharmony_ci	/* Hold tx_fifo_reset */
39638c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
39648c2ecf20Sopenharmony_ci				 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
39658c2ecf20Sopenharmony_ci
39668c2ecf20Sopenharmony_ci	/* Disable CL73 AN */
39678c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
39688c2ecf20Sopenharmony_ci
39698c2ecf20Sopenharmony_ci	/* Disable 100FX Enable and Auto-Detect */
39708c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
39718c2ecf20Sopenharmony_ci				  MDIO_WC_REG_FX100_CTRL1, 0xFFFA);
39728c2ecf20Sopenharmony_ci
39738c2ecf20Sopenharmony_ci	/* Disable 100FX Idle detect */
39748c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
39758c2ecf20Sopenharmony_ci				 MDIO_WC_REG_FX100_CTRL3, 0x0080);
39768c2ecf20Sopenharmony_ci
39778c2ecf20Sopenharmony_ci	/* Set Block address to Remote PHY & Clear forced_speed[5] */
39788c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
39798c2ecf20Sopenharmony_ci				  MDIO_WC_REG_DIGITAL4_MISC3, 0xFF7F);
39808c2ecf20Sopenharmony_ci
39818c2ecf20Sopenharmony_ci	/* Turn off auto-detect & fiber mode */
39828c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
39838c2ecf20Sopenharmony_ci				  MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
39848c2ecf20Sopenharmony_ci				  0xFFEE);
39858c2ecf20Sopenharmony_ci
39868c2ecf20Sopenharmony_ci	/* Set filter_force_link, disable_false_link and parallel_detect */
39878c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
39888c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
39898c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
39908c2ecf20Sopenharmony_ci			 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
39918c2ecf20Sopenharmony_ci			 ((val | 0x0006) & 0xFFFE));
39928c2ecf20Sopenharmony_ci
39938c2ecf20Sopenharmony_ci	/* Set XFI / SFI */
39948c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
39958c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
39968c2ecf20Sopenharmony_ci
39978c2ecf20Sopenharmony_ci	misc1_val &= ~(0x1f);
39988c2ecf20Sopenharmony_ci
39998c2ecf20Sopenharmony_ci	if (is_xfi) {
40008c2ecf20Sopenharmony_ci		misc1_val |= 0x5;
40018c2ecf20Sopenharmony_ci		tap_val = WC_TX_FIR(0x08, 0x37, 0x00);
40028c2ecf20Sopenharmony_ci		tx_driver_val = WC_TX_DRIVER(0x00, 0x02, 0x03, 0);
40038c2ecf20Sopenharmony_ci	} else {
40048c2ecf20Sopenharmony_ci		cfg_tap_val = REG_RD(bp, params->shmem_base +
40058c2ecf20Sopenharmony_ci				     offsetof(struct shmem_region, dev_info.
40068c2ecf20Sopenharmony_ci					      port_hw_config[params->port].
40078c2ecf20Sopenharmony_ci					      sfi_tap_values));
40088c2ecf20Sopenharmony_ci
40098c2ecf20Sopenharmony_ci		tx_equal = cfg_tap_val & PORT_HW_CFG_TX_EQUALIZATION_MASK;
40108c2ecf20Sopenharmony_ci
40118c2ecf20Sopenharmony_ci		misc1_val |= 0x9;
40128c2ecf20Sopenharmony_ci
40138c2ecf20Sopenharmony_ci		/* TAP values are controlled by nvram, if value there isn't 0 */
40148c2ecf20Sopenharmony_ci		if (tx_equal)
40158c2ecf20Sopenharmony_ci			tap_val = (u16)tx_equal;
40168c2ecf20Sopenharmony_ci		else
40178c2ecf20Sopenharmony_ci			tap_val = WC_TX_FIR(0x0f, 0x2b, 0x02);
40188c2ecf20Sopenharmony_ci
40198c2ecf20Sopenharmony_ci		ifir_val = DEFAULT_TX_DRV_IFIR;
40208c2ecf20Sopenharmony_ci		ipost2_val = DEFAULT_TX_DRV_POST2;
40218c2ecf20Sopenharmony_ci		ipre_driver_val = DEFAULT_TX_DRV_IPRE_DRIVER;
40228c2ecf20Sopenharmony_ci		tx_drv_brdct = DEFAULT_TX_DRV_BRDCT;
40238c2ecf20Sopenharmony_ci
40248c2ecf20Sopenharmony_ci		/* If any of the IFIR/IPRE_DRIVER/POST@ is set, apply all
40258c2ecf20Sopenharmony_ci		 * configuration.
40268c2ecf20Sopenharmony_ci		 */
40278c2ecf20Sopenharmony_ci		if (cfg_tap_val & (PORT_HW_CFG_TX_DRV_IFIR_MASK |
40288c2ecf20Sopenharmony_ci				   PORT_HW_CFG_TX_DRV_IPREDRIVER_MASK |
40298c2ecf20Sopenharmony_ci				   PORT_HW_CFG_TX_DRV_POST2_MASK)) {
40308c2ecf20Sopenharmony_ci			ifir_val = (cfg_tap_val &
40318c2ecf20Sopenharmony_ci				    PORT_HW_CFG_TX_DRV_IFIR_MASK) >>
40328c2ecf20Sopenharmony_ci				PORT_HW_CFG_TX_DRV_IFIR_SHIFT;
40338c2ecf20Sopenharmony_ci			ipre_driver_val = (cfg_tap_val &
40348c2ecf20Sopenharmony_ci					   PORT_HW_CFG_TX_DRV_IPREDRIVER_MASK)
40358c2ecf20Sopenharmony_ci			>> PORT_HW_CFG_TX_DRV_IPREDRIVER_SHIFT;
40368c2ecf20Sopenharmony_ci			ipost2_val = (cfg_tap_val &
40378c2ecf20Sopenharmony_ci				      PORT_HW_CFG_TX_DRV_POST2_MASK) >>
40388c2ecf20Sopenharmony_ci				PORT_HW_CFG_TX_DRV_POST2_SHIFT;
40398c2ecf20Sopenharmony_ci		}
40408c2ecf20Sopenharmony_ci
40418c2ecf20Sopenharmony_ci		if (cfg_tap_val & PORT_HW_CFG_TX_DRV_BROADCAST_MASK) {
40428c2ecf20Sopenharmony_ci			tx_drv_brdct = (cfg_tap_val &
40438c2ecf20Sopenharmony_ci					PORT_HW_CFG_TX_DRV_BROADCAST_MASK) >>
40448c2ecf20Sopenharmony_ci				PORT_HW_CFG_TX_DRV_BROADCAST_SHIFT;
40458c2ecf20Sopenharmony_ci		}
40468c2ecf20Sopenharmony_ci
40478c2ecf20Sopenharmony_ci		tx_driver_val = WC_TX_DRIVER(ipost2_val, tx_drv_brdct,
40488c2ecf20Sopenharmony_ci					     ipre_driver_val, ifir_val);
40498c2ecf20Sopenharmony_ci	}
40508c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
40518c2ecf20Sopenharmony_ci			 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
40528c2ecf20Sopenharmony_ci
40538c2ecf20Sopenharmony_ci	/* Set Transmit PMD settings */
40548c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
40558c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
40568c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX_FIR_TAP,
40578c2ecf20Sopenharmony_ci			 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
40588c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
40598c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
40608c2ecf20Sopenharmony_ci			 tx_driver_val);
40618c2ecf20Sopenharmony_ci
40628c2ecf20Sopenharmony_ci	/* Enable fiber mode, enable and invert sig_det */
40638c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
40648c2ecf20Sopenharmony_ci				 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
40658c2ecf20Sopenharmony_ci
40668c2ecf20Sopenharmony_ci	/* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
40678c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
40688c2ecf20Sopenharmony_ci				 MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
40698c2ecf20Sopenharmony_ci
40708c2ecf20Sopenharmony_ci	bnx2x_warpcore_set_lpi_passthrough(phy, params);
40718c2ecf20Sopenharmony_ci
40728c2ecf20Sopenharmony_ci	/* 10G XFI Full Duplex */
40738c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
40748c2ecf20Sopenharmony_ci			 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
40758c2ecf20Sopenharmony_ci
40768c2ecf20Sopenharmony_ci	/* Release tx_fifo_reset */
40778c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
40788c2ecf20Sopenharmony_ci				  MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
40798c2ecf20Sopenharmony_ci				  0xFFFE);
40808c2ecf20Sopenharmony_ci	/* Release rxSeqStart */
40818c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
40828c2ecf20Sopenharmony_ci				  MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x7FFF);
40838c2ecf20Sopenharmony_ci}
40848c2ecf20Sopenharmony_ci
40858c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_20G_force_KR2(struct bnx2x_phy *phy,
40868c2ecf20Sopenharmony_ci					     struct link_params *params)
40878c2ecf20Sopenharmony_ci{
40888c2ecf20Sopenharmony_ci	u16 val;
40898c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
40908c2ecf20Sopenharmony_ci	/* Set global registers, so set AER lane to 0 */
40918c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
40928c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, 0);
40938c2ecf20Sopenharmony_ci
40948c2ecf20Sopenharmony_ci	/* Disable sequencer */
40958c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
40968c2ecf20Sopenharmony_ci				  MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, ~(1<<13));
40978c2ecf20Sopenharmony_ci
40988c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
40998c2ecf20Sopenharmony_ci
41008c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_PMA_DEVAD,
41018c2ecf20Sopenharmony_ci				  MDIO_WC_REG_PMD_KR_CONTROL, ~(1<<1));
41028c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
41038c2ecf20Sopenharmony_ci			 MDIO_AN_REG_CTRL, 0);
41048c2ecf20Sopenharmony_ci	/* Turn off CL73 */
41058c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
41068c2ecf20Sopenharmony_ci			MDIO_WC_REG_CL73_USERB0_CTRL, &val);
41078c2ecf20Sopenharmony_ci	val &= ~(1<<5);
41088c2ecf20Sopenharmony_ci	val |= (1<<6);
41098c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41108c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL73_USERB0_CTRL, val);
41118c2ecf20Sopenharmony_ci
41128c2ecf20Sopenharmony_ci	/* Set 20G KR2 force speed */
41138c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
41148c2ecf20Sopenharmony_ci				 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x1f);
41158c2ecf20Sopenharmony_ci
41168c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
41178c2ecf20Sopenharmony_ci				 MDIO_WC_REG_DIGITAL4_MISC3, (1<<7));
41188c2ecf20Sopenharmony_ci
41198c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
41208c2ecf20Sopenharmony_ci			MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &val);
41218c2ecf20Sopenharmony_ci	val &= ~(3<<14);
41228c2ecf20Sopenharmony_ci	val |= (1<<15);
41238c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41248c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, val);
41258c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41268c2ecf20Sopenharmony_ci			 MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0x835A);
41278c2ecf20Sopenharmony_ci
41288c2ecf20Sopenharmony_ci	/* Enable sequencer (over lane 0) */
41298c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
41308c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, 0);
41318c2ecf20Sopenharmony_ci
41328c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
41338c2ecf20Sopenharmony_ci				 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, (1<<13));
41348c2ecf20Sopenharmony_ci
41358c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
41368c2ecf20Sopenharmony_ci}
41378c2ecf20Sopenharmony_ci
41388c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
41398c2ecf20Sopenharmony_ci					 struct bnx2x_phy *phy,
41408c2ecf20Sopenharmony_ci					 u16 lane)
41418c2ecf20Sopenharmony_ci{
41428c2ecf20Sopenharmony_ci	/* Rx0 anaRxControl1G */
41438c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41448c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
41458c2ecf20Sopenharmony_ci
41468c2ecf20Sopenharmony_ci	/* Rx2 anaRxControl1G */
41478c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41488c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
41498c2ecf20Sopenharmony_ci
41508c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41518c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW0, 0xE070);
41528c2ecf20Sopenharmony_ci
41538c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41548c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
41558c2ecf20Sopenharmony_ci
41568c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41578c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
41588c2ecf20Sopenharmony_ci
41598c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41608c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW3, 0x8090);
41618c2ecf20Sopenharmony_ci
41628c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41638c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
41648c2ecf20Sopenharmony_ci
41658c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41668c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
41678c2ecf20Sopenharmony_ci
41688c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41698c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
41708c2ecf20Sopenharmony_ci
41718c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41728c2ecf20Sopenharmony_ci			 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
41738c2ecf20Sopenharmony_ci
41748c2ecf20Sopenharmony_ci	/* Serdes Digital Misc1 */
41758c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41768c2ecf20Sopenharmony_ci			 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
41778c2ecf20Sopenharmony_ci
41788c2ecf20Sopenharmony_ci	/* Serdes Digital4 Misc3 */
41798c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41808c2ecf20Sopenharmony_ci			 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
41818c2ecf20Sopenharmony_ci
41828c2ecf20Sopenharmony_ci	/* Set Transmit PMD settings */
41838c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41848c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX_FIR_TAP,
41858c2ecf20Sopenharmony_ci			 (WC_TX_FIR(0x12, 0x2d, 0x00) |
41868c2ecf20Sopenharmony_ci			  MDIO_WC_REG_TX_FIR_TAP_ENABLE));
41878c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
41888c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
41898c2ecf20Sopenharmony_ci			 WC_TX_DRIVER(0x02, 0x02, 0x02, 0));
41908c2ecf20Sopenharmony_ci}
41918c2ecf20Sopenharmony_ci
41928c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
41938c2ecf20Sopenharmony_ci					   struct link_params *params,
41948c2ecf20Sopenharmony_ci					   u8 fiber_mode,
41958c2ecf20Sopenharmony_ci					   u8 always_autoneg)
41968c2ecf20Sopenharmony_ci{
41978c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
41988c2ecf20Sopenharmony_ci	u16 val16, digctrl_kx1, digctrl_kx2;
41998c2ecf20Sopenharmony_ci
42008c2ecf20Sopenharmony_ci	/* Clear XFI clock comp in non-10G single lane mode. */
42018c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
42028c2ecf20Sopenharmony_ci				  MDIO_WC_REG_RX66_CONTROL, ~(3<<13));
42038c2ecf20Sopenharmony_ci
42048c2ecf20Sopenharmony_ci	bnx2x_warpcore_set_lpi_passthrough(phy, params);
42058c2ecf20Sopenharmony_ci
42068c2ecf20Sopenharmony_ci	if (always_autoneg || phy->req_line_speed == SPEED_AUTO_NEG) {
42078c2ecf20Sopenharmony_ci		/* SGMII Autoneg */
42088c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
42098c2ecf20Sopenharmony_ci					 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
42108c2ecf20Sopenharmony_ci					 0x1000);
42118c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
42128c2ecf20Sopenharmony_ci	} else {
42138c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42148c2ecf20Sopenharmony_ci				MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
42158c2ecf20Sopenharmony_ci		val16 &= 0xcebf;
42168c2ecf20Sopenharmony_ci		switch (phy->req_line_speed) {
42178c2ecf20Sopenharmony_ci		case SPEED_10:
42188c2ecf20Sopenharmony_ci			break;
42198c2ecf20Sopenharmony_ci		case SPEED_100:
42208c2ecf20Sopenharmony_ci			val16 |= 0x2000;
42218c2ecf20Sopenharmony_ci			break;
42228c2ecf20Sopenharmony_ci		case SPEED_1000:
42238c2ecf20Sopenharmony_ci			val16 |= 0x0040;
42248c2ecf20Sopenharmony_ci			break;
42258c2ecf20Sopenharmony_ci		default:
42268c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
42278c2ecf20Sopenharmony_ci			   "Speed not supported: 0x%x\n", phy->req_line_speed);
42288c2ecf20Sopenharmony_ci			return;
42298c2ecf20Sopenharmony_ci		}
42308c2ecf20Sopenharmony_ci
42318c2ecf20Sopenharmony_ci		if (phy->req_duplex == DUPLEX_FULL)
42328c2ecf20Sopenharmony_ci			val16 |= 0x0100;
42338c2ecf20Sopenharmony_ci
42348c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42358c2ecf20Sopenharmony_ci				MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
42368c2ecf20Sopenharmony_ci
42378c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
42388c2ecf20Sopenharmony_ci			       phy->req_line_speed);
42398c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42408c2ecf20Sopenharmony_ci				MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
42418c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "  (readback) %x\n", val16);
42428c2ecf20Sopenharmony_ci	}
42438c2ecf20Sopenharmony_ci
42448c2ecf20Sopenharmony_ci	/* SGMII Slave mode and disable signal detect */
42458c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42468c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
42478c2ecf20Sopenharmony_ci	if (fiber_mode)
42488c2ecf20Sopenharmony_ci		digctrl_kx1 = 1;
42498c2ecf20Sopenharmony_ci	else
42508c2ecf20Sopenharmony_ci		digctrl_kx1 &= 0xff4a;
42518c2ecf20Sopenharmony_ci
42528c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42538c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
42548c2ecf20Sopenharmony_ci			digctrl_kx1);
42558c2ecf20Sopenharmony_ci
42568c2ecf20Sopenharmony_ci	/* Turn off parallel detect */
42578c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42588c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
42598c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42608c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
42618c2ecf20Sopenharmony_ci			(digctrl_kx2 & ~(1<<2)));
42628c2ecf20Sopenharmony_ci
42638c2ecf20Sopenharmony_ci	/* Re-enable parallel detect */
42648c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42658c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
42668c2ecf20Sopenharmony_ci			(digctrl_kx2 | (1<<2)));
42678c2ecf20Sopenharmony_ci
42688c2ecf20Sopenharmony_ci	/* Enable autodet */
42698c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42708c2ecf20Sopenharmony_ci			MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
42718c2ecf20Sopenharmony_ci			(digctrl_kx1 | 0x10));
42728c2ecf20Sopenharmony_ci}
42738c2ecf20Sopenharmony_ci
42748c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
42758c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
42768c2ecf20Sopenharmony_ci				      u8 reset)
42778c2ecf20Sopenharmony_ci{
42788c2ecf20Sopenharmony_ci	u16 val;
42798c2ecf20Sopenharmony_ci	/* Take lane out of reset after configuration is finished */
42808c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42818c2ecf20Sopenharmony_ci			MDIO_WC_REG_DIGITAL5_MISC6, &val);
42828c2ecf20Sopenharmony_ci	if (reset)
42838c2ecf20Sopenharmony_ci		val |= 0xC000;
42848c2ecf20Sopenharmony_ci	else
42858c2ecf20Sopenharmony_ci		val &= 0x3FFF;
42868c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
42878c2ecf20Sopenharmony_ci			 MDIO_WC_REG_DIGITAL5_MISC6, val);
42888c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
42898c2ecf20Sopenharmony_ci			 MDIO_WC_REG_DIGITAL5_MISC6, &val);
42908c2ecf20Sopenharmony_ci}
42918c2ecf20Sopenharmony_ci/* Clear SFI/XFI link settings registers */
42928c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
42938c2ecf20Sopenharmony_ci				      struct link_params *params,
42948c2ecf20Sopenharmony_ci				      u16 lane)
42958c2ecf20Sopenharmony_ci{
42968c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
42978c2ecf20Sopenharmony_ci	u16 i;
42988c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set wc_regs[] = {
42998c2ecf20Sopenharmony_ci		{MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
43008c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
43018c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
43028c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
43038c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
43048c2ecf20Sopenharmony_ci			0x0195},
43058c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
43068c2ecf20Sopenharmony_ci			0x0007},
43078c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
43088c2ecf20Sopenharmony_ci			0x0002},
43098c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
43108c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
43118c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
43128c2ecf20Sopenharmony_ci		{MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
43138c2ecf20Sopenharmony_ci	};
43148c2ecf20Sopenharmony_ci	/* Set XFI clock comp as default. */
43158c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
43168c2ecf20Sopenharmony_ci				 MDIO_WC_REG_RX66_CONTROL, (3<<13));
43178c2ecf20Sopenharmony_ci
43188c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(wc_regs); i++)
43198c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, wc_regs[i].devad, wc_regs[i].reg,
43208c2ecf20Sopenharmony_ci				 wc_regs[i].val);
43218c2ecf20Sopenharmony_ci
43228c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
43238c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
43248c2ecf20Sopenharmony_ci			 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
43258c2ecf20Sopenharmony_ci
43268c2ecf20Sopenharmony_ci}
43278c2ecf20Sopenharmony_ci
43288c2ecf20Sopenharmony_cistatic int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
43298c2ecf20Sopenharmony_ci						u32 chip_id,
43308c2ecf20Sopenharmony_ci						u32 shmem_base, u8 port,
43318c2ecf20Sopenharmony_ci						u8 *gpio_num, u8 *gpio_port)
43328c2ecf20Sopenharmony_ci{
43338c2ecf20Sopenharmony_ci	u32 cfg_pin;
43348c2ecf20Sopenharmony_ci	*gpio_num = 0;
43358c2ecf20Sopenharmony_ci	*gpio_port = 0;
43368c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
43378c2ecf20Sopenharmony_ci		cfg_pin = (REG_RD(bp, shmem_base +
43388c2ecf20Sopenharmony_ci				offsetof(struct shmem_region,
43398c2ecf20Sopenharmony_ci				dev_info.port_hw_config[port].e3_sfp_ctrl)) &
43408c2ecf20Sopenharmony_ci				PORT_HW_CFG_E3_MOD_ABS_MASK) >>
43418c2ecf20Sopenharmony_ci				PORT_HW_CFG_E3_MOD_ABS_SHIFT;
43428c2ecf20Sopenharmony_ci
43438c2ecf20Sopenharmony_ci		/* Should not happen. This function called upon interrupt
43448c2ecf20Sopenharmony_ci		 * triggered by GPIO ( since EPIO can only generate interrupts
43458c2ecf20Sopenharmony_ci		 * to MCP).
43468c2ecf20Sopenharmony_ci		 * So if this function was called and none of the GPIOs was set,
43478c2ecf20Sopenharmony_ci		 * it means the shit hit the fan.
43488c2ecf20Sopenharmony_ci		 */
43498c2ecf20Sopenharmony_ci		if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
43508c2ecf20Sopenharmony_ci		    (cfg_pin > PIN_CFG_GPIO3_P1)) {
43518c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
43528c2ecf20Sopenharmony_ci			   "No cfg pin %x for module detect indication\n",
43538c2ecf20Sopenharmony_ci			   cfg_pin);
43548c2ecf20Sopenharmony_ci			return -EINVAL;
43558c2ecf20Sopenharmony_ci		}
43568c2ecf20Sopenharmony_ci
43578c2ecf20Sopenharmony_ci		*gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
43588c2ecf20Sopenharmony_ci		*gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
43598c2ecf20Sopenharmony_ci	} else {
43608c2ecf20Sopenharmony_ci		*gpio_num = MISC_REGISTERS_GPIO_3;
43618c2ecf20Sopenharmony_ci		*gpio_port = port;
43628c2ecf20Sopenharmony_ci	}
43638c2ecf20Sopenharmony_ci
43648c2ecf20Sopenharmony_ci	return 0;
43658c2ecf20Sopenharmony_ci}
43668c2ecf20Sopenharmony_ci
43678c2ecf20Sopenharmony_cistatic int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
43688c2ecf20Sopenharmony_ci				       struct link_params *params)
43698c2ecf20Sopenharmony_ci{
43708c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
43718c2ecf20Sopenharmony_ci	u8 gpio_num, gpio_port;
43728c2ecf20Sopenharmony_ci	u32 gpio_val;
43738c2ecf20Sopenharmony_ci	if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
43748c2ecf20Sopenharmony_ci				      params->shmem_base, params->port,
43758c2ecf20Sopenharmony_ci				      &gpio_num, &gpio_port) != 0)
43768c2ecf20Sopenharmony_ci		return 0;
43778c2ecf20Sopenharmony_ci	gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
43788c2ecf20Sopenharmony_ci
43798c2ecf20Sopenharmony_ci	/* Call the handling function in case module is detected */
43808c2ecf20Sopenharmony_ci	if (gpio_val == 0)
43818c2ecf20Sopenharmony_ci		return 1;
43828c2ecf20Sopenharmony_ci	else
43838c2ecf20Sopenharmony_ci		return 0;
43848c2ecf20Sopenharmony_ci}
43858c2ecf20Sopenharmony_cistatic int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
43868c2ecf20Sopenharmony_ci				     struct link_params *params)
43878c2ecf20Sopenharmony_ci{
43888c2ecf20Sopenharmony_ci	u16 gp2_status_reg0, lane;
43898c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
43908c2ecf20Sopenharmony_ci
43918c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
43928c2ecf20Sopenharmony_ci
43938c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
43948c2ecf20Sopenharmony_ci				 &gp2_status_reg0);
43958c2ecf20Sopenharmony_ci
43968c2ecf20Sopenharmony_ci	return (gp2_status_reg0 >> (8+lane)) & 0x1;
43978c2ecf20Sopenharmony_ci}
43988c2ecf20Sopenharmony_ci
43998c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
44008c2ecf20Sopenharmony_ci					  struct link_params *params,
44018c2ecf20Sopenharmony_ci					  struct link_vars *vars)
44028c2ecf20Sopenharmony_ci{
44038c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
44048c2ecf20Sopenharmony_ci	u32 serdes_net_if;
44058c2ecf20Sopenharmony_ci	u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
44068c2ecf20Sopenharmony_ci
44078c2ecf20Sopenharmony_ci	vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
44088c2ecf20Sopenharmony_ci
44098c2ecf20Sopenharmony_ci	if (!vars->turn_to_run_wc_rt)
44108c2ecf20Sopenharmony_ci		return;
44118c2ecf20Sopenharmony_ci
44128c2ecf20Sopenharmony_ci	if (vars->rx_tx_asic_rst) {
44138c2ecf20Sopenharmony_ci		u16 lane = bnx2x_get_warpcore_lane(phy, params);
44148c2ecf20Sopenharmony_ci		serdes_net_if = (REG_RD(bp, params->shmem_base +
44158c2ecf20Sopenharmony_ci				offsetof(struct shmem_region, dev_info.
44168c2ecf20Sopenharmony_ci				port_hw_config[params->port].default_cfg)) &
44178c2ecf20Sopenharmony_ci				PORT_HW_CFG_NET_SERDES_IF_MASK);
44188c2ecf20Sopenharmony_ci
44198c2ecf20Sopenharmony_ci		switch (serdes_net_if) {
44208c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_KR:
44218c2ecf20Sopenharmony_ci			/* Do we get link yet? */
44228c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
44238c2ecf20Sopenharmony_ci					&gp_status1);
44248c2ecf20Sopenharmony_ci			lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
44258c2ecf20Sopenharmony_ci				/*10G KR*/
44268c2ecf20Sopenharmony_ci			lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
44278c2ecf20Sopenharmony_ci
44288c2ecf20Sopenharmony_ci			if (lnkup_kr || lnkup) {
44298c2ecf20Sopenharmony_ci				vars->rx_tx_asic_rst = 0;
44308c2ecf20Sopenharmony_ci			} else {
44318c2ecf20Sopenharmony_ci				/* Reset the lane to see if link comes up.*/
44328c2ecf20Sopenharmony_ci				bnx2x_warpcore_reset_lane(bp, phy, 1);
44338c2ecf20Sopenharmony_ci				bnx2x_warpcore_reset_lane(bp, phy, 0);
44348c2ecf20Sopenharmony_ci
44358c2ecf20Sopenharmony_ci				/* Restart Autoneg */
44368c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
44378c2ecf20Sopenharmony_ci					MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
44388c2ecf20Sopenharmony_ci
44398c2ecf20Sopenharmony_ci				vars->rx_tx_asic_rst--;
44408c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "0x%x retry left\n",
44418c2ecf20Sopenharmony_ci				vars->rx_tx_asic_rst);
44428c2ecf20Sopenharmony_ci			}
44438c2ecf20Sopenharmony_ci			break;
44448c2ecf20Sopenharmony_ci
44458c2ecf20Sopenharmony_ci		default:
44468c2ecf20Sopenharmony_ci			break;
44478c2ecf20Sopenharmony_ci		}
44488c2ecf20Sopenharmony_ci
44498c2ecf20Sopenharmony_ci	} /*params->rx_tx_asic_rst*/
44508c2ecf20Sopenharmony_ci
44518c2ecf20Sopenharmony_ci}
44528c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_config_sfi(struct bnx2x_phy *phy,
44538c2ecf20Sopenharmony_ci				      struct link_params *params)
44548c2ecf20Sopenharmony_ci{
44558c2ecf20Sopenharmony_ci	u16 lane = bnx2x_get_warpcore_lane(phy, params);
44568c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
44578c2ecf20Sopenharmony_ci	bnx2x_warpcore_clear_regs(phy, params, lane);
44588c2ecf20Sopenharmony_ci	if ((params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)] ==
44598c2ecf20Sopenharmony_ci	     SPEED_10000) &&
44608c2ecf20Sopenharmony_ci	    (phy->media_type != ETH_PHY_SFP_1G_FIBER)) {
44618c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
44628c2ecf20Sopenharmony_ci		bnx2x_warpcore_set_10G_XFI(phy, params, 0);
44638c2ecf20Sopenharmony_ci	} else {
44648c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
44658c2ecf20Sopenharmony_ci		bnx2x_warpcore_set_sgmii_speed(phy, params, 1, 0);
44668c2ecf20Sopenharmony_ci	}
44678c2ecf20Sopenharmony_ci}
44688c2ecf20Sopenharmony_ci
44698c2ecf20Sopenharmony_cistatic void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
44708c2ecf20Sopenharmony_ci					 struct bnx2x_phy *phy,
44718c2ecf20Sopenharmony_ci					 u8 tx_en)
44728c2ecf20Sopenharmony_ci{
44738c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
44748c2ecf20Sopenharmony_ci	u32 cfg_pin;
44758c2ecf20Sopenharmony_ci	u8 port = params->port;
44768c2ecf20Sopenharmony_ci
44778c2ecf20Sopenharmony_ci	cfg_pin = REG_RD(bp, params->shmem_base +
44788c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region,
44798c2ecf20Sopenharmony_ci				  dev_info.port_hw_config[port].e3_sfp_ctrl)) &
44808c2ecf20Sopenharmony_ci		PORT_HW_CFG_E3_TX_LASER_MASK;
44818c2ecf20Sopenharmony_ci	/* Set the !tx_en since this pin is DISABLE_TX_LASER */
44828c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
44838c2ecf20Sopenharmony_ci
44848c2ecf20Sopenharmony_ci	/* For 20G, the expected pin to be used is 3 pins after the current */
44858c2ecf20Sopenharmony_ci	bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
44868c2ecf20Sopenharmony_ci	if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
44878c2ecf20Sopenharmony_ci		bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
44888c2ecf20Sopenharmony_ci}
44898c2ecf20Sopenharmony_ci
44908c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
44918c2ecf20Sopenharmony_ci				       struct link_params *params,
44928c2ecf20Sopenharmony_ci				       struct link_vars *vars)
44938c2ecf20Sopenharmony_ci{
44948c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
44958c2ecf20Sopenharmony_ci	u32 serdes_net_if;
44968c2ecf20Sopenharmony_ci	u8 fiber_mode;
44978c2ecf20Sopenharmony_ci	u16 lane = bnx2x_get_warpcore_lane(phy, params);
44988c2ecf20Sopenharmony_ci	serdes_net_if = (REG_RD(bp, params->shmem_base +
44998c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region, dev_info.
45008c2ecf20Sopenharmony_ci				  port_hw_config[params->port].default_cfg)) &
45018c2ecf20Sopenharmony_ci			 PORT_HW_CFG_NET_SERDES_IF_MASK);
45028c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
45038c2ecf20Sopenharmony_ci			   "serdes_net_if = 0x%x\n",
45048c2ecf20Sopenharmony_ci		       vars->line_speed, serdes_net_if);
45058c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
45068c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, phy, 1);
45078c2ecf20Sopenharmony_ci	vars->phy_flags |= PHY_XGXS_FLAG;
45088c2ecf20Sopenharmony_ci	if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
45098c2ecf20Sopenharmony_ci	    (phy->req_line_speed &&
45108c2ecf20Sopenharmony_ci	     ((phy->req_line_speed == SPEED_100) ||
45118c2ecf20Sopenharmony_ci	      (phy->req_line_speed == SPEED_10)))) {
45128c2ecf20Sopenharmony_ci		vars->phy_flags |= PHY_SGMII_FLAG;
45138c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
45148c2ecf20Sopenharmony_ci		bnx2x_warpcore_clear_regs(phy, params, lane);
45158c2ecf20Sopenharmony_ci		bnx2x_warpcore_set_sgmii_speed(phy, params, 0, 1);
45168c2ecf20Sopenharmony_ci	} else {
45178c2ecf20Sopenharmony_ci		switch (serdes_net_if) {
45188c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_KR:
45198c2ecf20Sopenharmony_ci			/* Enable KR Auto Neg */
45208c2ecf20Sopenharmony_ci			if (params->loopback_mode != LOOPBACK_EXT)
45218c2ecf20Sopenharmony_ci				bnx2x_warpcore_enable_AN_KR(phy, params, vars);
45228c2ecf20Sopenharmony_ci			else {
45238c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
45248c2ecf20Sopenharmony_ci				bnx2x_warpcore_set_10G_KR(phy, params, vars);
45258c2ecf20Sopenharmony_ci			}
45268c2ecf20Sopenharmony_ci			break;
45278c2ecf20Sopenharmony_ci
45288c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_XFI:
45298c2ecf20Sopenharmony_ci			bnx2x_warpcore_clear_regs(phy, params, lane);
45308c2ecf20Sopenharmony_ci			if (vars->line_speed == SPEED_10000) {
45318c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
45328c2ecf20Sopenharmony_ci				bnx2x_warpcore_set_10G_XFI(phy, params, 1);
45338c2ecf20Sopenharmony_ci			} else {
45348c2ecf20Sopenharmony_ci				if (SINGLE_MEDIA_DIRECT(params)) {
45358c2ecf20Sopenharmony_ci					DP(NETIF_MSG_LINK, "1G Fiber\n");
45368c2ecf20Sopenharmony_ci					fiber_mode = 1;
45378c2ecf20Sopenharmony_ci				} else {
45388c2ecf20Sopenharmony_ci					DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
45398c2ecf20Sopenharmony_ci					fiber_mode = 0;
45408c2ecf20Sopenharmony_ci				}
45418c2ecf20Sopenharmony_ci				bnx2x_warpcore_set_sgmii_speed(phy,
45428c2ecf20Sopenharmony_ci								params,
45438c2ecf20Sopenharmony_ci								fiber_mode,
45448c2ecf20Sopenharmony_ci								0);
45458c2ecf20Sopenharmony_ci			}
45468c2ecf20Sopenharmony_ci
45478c2ecf20Sopenharmony_ci			break;
45488c2ecf20Sopenharmony_ci
45498c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_SFI:
45508c2ecf20Sopenharmony_ci			/* Issue Module detection if module is plugged, or
45518c2ecf20Sopenharmony_ci			 * enabled transmitter to avoid current leakage in case
45528c2ecf20Sopenharmony_ci			 * no module is connected
45538c2ecf20Sopenharmony_ci			 */
45548c2ecf20Sopenharmony_ci			if ((params->loopback_mode == LOOPBACK_NONE) ||
45558c2ecf20Sopenharmony_ci			    (params->loopback_mode == LOOPBACK_EXT)) {
45568c2ecf20Sopenharmony_ci				if (bnx2x_is_sfp_module_plugged(phy, params))
45578c2ecf20Sopenharmony_ci					bnx2x_sfp_module_detection(phy, params);
45588c2ecf20Sopenharmony_ci				else
45598c2ecf20Sopenharmony_ci					bnx2x_sfp_e3_set_transmitter(params,
45608c2ecf20Sopenharmony_ci								     phy, 1);
45618c2ecf20Sopenharmony_ci			}
45628c2ecf20Sopenharmony_ci
45638c2ecf20Sopenharmony_ci			bnx2x_warpcore_config_sfi(phy, params);
45648c2ecf20Sopenharmony_ci			break;
45658c2ecf20Sopenharmony_ci
45668c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
45678c2ecf20Sopenharmony_ci			if (vars->line_speed != SPEED_20000) {
45688c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Speed not supported yet\n");
45698c2ecf20Sopenharmony_ci				return;
45708c2ecf20Sopenharmony_ci			}
45718c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
45728c2ecf20Sopenharmony_ci			bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
45738c2ecf20Sopenharmony_ci			/* Issue Module detection */
45748c2ecf20Sopenharmony_ci
45758c2ecf20Sopenharmony_ci			bnx2x_sfp_module_detection(phy, params);
45768c2ecf20Sopenharmony_ci			break;
45778c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_KR2:
45788c2ecf20Sopenharmony_ci			if (!params->loopback_mode) {
45798c2ecf20Sopenharmony_ci				bnx2x_warpcore_enable_AN_KR(phy, params, vars);
45808c2ecf20Sopenharmony_ci			} else {
45818c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Setting KR 20G-Force\n");
45828c2ecf20Sopenharmony_ci				bnx2x_warpcore_set_20G_force_KR2(phy, params);
45838c2ecf20Sopenharmony_ci			}
45848c2ecf20Sopenharmony_ci			break;
45858c2ecf20Sopenharmony_ci		default:
45868c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
45878c2ecf20Sopenharmony_ci			   "Unsupported Serdes Net Interface 0x%x\n",
45888c2ecf20Sopenharmony_ci			   serdes_net_if);
45898c2ecf20Sopenharmony_ci			return;
45908c2ecf20Sopenharmony_ci		}
45918c2ecf20Sopenharmony_ci	}
45928c2ecf20Sopenharmony_ci
45938c2ecf20Sopenharmony_ci	/* Take lane out of reset after configuration is finished */
45948c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, phy, 0);
45958c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Exit config init\n");
45968c2ecf20Sopenharmony_ci}
45978c2ecf20Sopenharmony_ci
45988c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
45998c2ecf20Sopenharmony_ci				      struct link_params *params)
46008c2ecf20Sopenharmony_ci{
46018c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
46028c2ecf20Sopenharmony_ci	u16 val16, lane;
46038c2ecf20Sopenharmony_ci	bnx2x_sfp_e3_set_transmitter(params, phy, 0);
46048c2ecf20Sopenharmony_ci	bnx2x_set_mdio_emac_per_phy(bp, params);
46058c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
46068c2ecf20Sopenharmony_ci	/* Global register */
46078c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, phy, 1);
46088c2ecf20Sopenharmony_ci
46098c2ecf20Sopenharmony_ci	/* Clear loopback settings (if any) */
46108c2ecf20Sopenharmony_ci	/* 10G & 20G */
46118c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
46128c2ecf20Sopenharmony_ci				  MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0xBFFF);
46138c2ecf20Sopenharmony_ci
46148c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
46158c2ecf20Sopenharmony_ci				  MDIO_WC_REG_IEEE0BLK_MIICNTL, 0xfffe);
46168c2ecf20Sopenharmony_ci
46178c2ecf20Sopenharmony_ci	/* Update those 1-copy registers */
46188c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
46198c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, 0);
46208c2ecf20Sopenharmony_ci	/* Enable 1G MDIO (1-copy) */
46218c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
46228c2ecf20Sopenharmony_ci				  MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
46238c2ecf20Sopenharmony_ci				  ~0x10);
46248c2ecf20Sopenharmony_ci
46258c2ecf20Sopenharmony_ci	bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
46268c2ecf20Sopenharmony_ci				  MDIO_WC_REG_XGXSBLK1_LANECTRL2, 0xff00);
46278c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
46288c2ecf20Sopenharmony_ci	/* Disable CL36 PCS Tx */
46298c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
46308c2ecf20Sopenharmony_ci			MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
46318c2ecf20Sopenharmony_ci	val16 |= (0x11 << lane);
46328c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_WC_DUAL_MODE)
46338c2ecf20Sopenharmony_ci		val16 |= (0x22 << lane);
46348c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
46358c2ecf20Sopenharmony_ci			 MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
46368c2ecf20Sopenharmony_ci
46378c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
46388c2ecf20Sopenharmony_ci			MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
46398c2ecf20Sopenharmony_ci	val16 &= ~(0x0303 << (lane << 1));
46408c2ecf20Sopenharmony_ci	val16 |= (0x0101 << (lane << 1));
46418c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_WC_DUAL_MODE) {
46428c2ecf20Sopenharmony_ci		val16 &= ~(0x0c0c << (lane << 1));
46438c2ecf20Sopenharmony_ci		val16 |= (0x0404 << (lane << 1));
46448c2ecf20Sopenharmony_ci	}
46458c2ecf20Sopenharmony_ci
46468c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
46478c2ecf20Sopenharmony_ci			 MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
46488c2ecf20Sopenharmony_ci	/* Restore AER */
46498c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
46508c2ecf20Sopenharmony_ci
46518c2ecf20Sopenharmony_ci}
46528c2ecf20Sopenharmony_ci
46538c2ecf20Sopenharmony_cistatic void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
46548c2ecf20Sopenharmony_ci					struct link_params *params)
46558c2ecf20Sopenharmony_ci{
46568c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
46578c2ecf20Sopenharmony_ci	u16 val16;
46588c2ecf20Sopenharmony_ci	u32 lane;
46598c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
46608c2ecf20Sopenharmony_ci		       params->loopback_mode, phy->req_line_speed);
46618c2ecf20Sopenharmony_ci
46628c2ecf20Sopenharmony_ci	if (phy->req_line_speed < SPEED_10000 ||
46638c2ecf20Sopenharmony_ci	    phy->supported & SUPPORTED_20000baseKR2_Full) {
46648c2ecf20Sopenharmony_ci		/* 10/100/1000/20G-KR2 */
46658c2ecf20Sopenharmony_ci
46668c2ecf20Sopenharmony_ci		/* Update those 1-copy registers */
46678c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
46688c2ecf20Sopenharmony_ci				  MDIO_AER_BLOCK_AER_REG, 0);
46698c2ecf20Sopenharmony_ci		/* Enable 1G MDIO (1-copy) */
46708c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
46718c2ecf20Sopenharmony_ci					 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
46728c2ecf20Sopenharmony_ci					 0x10);
46738c2ecf20Sopenharmony_ci		/* Set 1G loopback based on lane (1-copy) */
46748c2ecf20Sopenharmony_ci		lane = bnx2x_get_warpcore_lane(phy, params);
46758c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
46768c2ecf20Sopenharmony_ci				MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
46778c2ecf20Sopenharmony_ci		val16 |= (1<<lane);
46788c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_WC_DUAL_MODE)
46798c2ecf20Sopenharmony_ci			val16 |= (2<<lane);
46808c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
46818c2ecf20Sopenharmony_ci				 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
46828c2ecf20Sopenharmony_ci				 val16);
46838c2ecf20Sopenharmony_ci
46848c2ecf20Sopenharmony_ci		/* Switch back to 4-copy registers */
46858c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
46868c2ecf20Sopenharmony_ci	} else {
46878c2ecf20Sopenharmony_ci		/* 10G / 20G-DXGXS */
46888c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
46898c2ecf20Sopenharmony_ci					 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
46908c2ecf20Sopenharmony_ci					 0x4000);
46918c2ecf20Sopenharmony_ci		bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
46928c2ecf20Sopenharmony_ci					 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
46938c2ecf20Sopenharmony_ci	}
46948c2ecf20Sopenharmony_ci}
46958c2ecf20Sopenharmony_ci
46968c2ecf20Sopenharmony_ci
46978c2ecf20Sopenharmony_ci
46988c2ecf20Sopenharmony_cistatic void bnx2x_sync_link(struct link_params *params,
46998c2ecf20Sopenharmony_ci			     struct link_vars *vars)
47008c2ecf20Sopenharmony_ci{
47018c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
47028c2ecf20Sopenharmony_ci	u8 link_10g_plus;
47038c2ecf20Sopenharmony_ci	if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
47048c2ecf20Sopenharmony_ci		vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
47058c2ecf20Sopenharmony_ci	vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
47068c2ecf20Sopenharmony_ci	if (vars->link_up) {
47078c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "phy link up\n");
47088c2ecf20Sopenharmony_ci
47098c2ecf20Sopenharmony_ci		vars->phy_link_up = 1;
47108c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
47118c2ecf20Sopenharmony_ci		switch (vars->link_status &
47128c2ecf20Sopenharmony_ci			LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
47138c2ecf20Sopenharmony_ci		case LINK_10THD:
47148c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
47158c2ecf20Sopenharmony_ci			fallthrough;
47168c2ecf20Sopenharmony_ci		case LINK_10TFD:
47178c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10;
47188c2ecf20Sopenharmony_ci			break;
47198c2ecf20Sopenharmony_ci
47208c2ecf20Sopenharmony_ci		case LINK_100TXHD:
47218c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
47228c2ecf20Sopenharmony_ci			fallthrough;
47238c2ecf20Sopenharmony_ci		case LINK_100T4:
47248c2ecf20Sopenharmony_ci		case LINK_100TXFD:
47258c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_100;
47268c2ecf20Sopenharmony_ci			break;
47278c2ecf20Sopenharmony_ci
47288c2ecf20Sopenharmony_ci		case LINK_1000THD:
47298c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
47308c2ecf20Sopenharmony_ci			fallthrough;
47318c2ecf20Sopenharmony_ci		case LINK_1000TFD:
47328c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
47338c2ecf20Sopenharmony_ci			break;
47348c2ecf20Sopenharmony_ci
47358c2ecf20Sopenharmony_ci		case LINK_2500THD:
47368c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
47378c2ecf20Sopenharmony_ci			fallthrough;
47388c2ecf20Sopenharmony_ci		case LINK_2500TFD:
47398c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_2500;
47408c2ecf20Sopenharmony_ci			break;
47418c2ecf20Sopenharmony_ci
47428c2ecf20Sopenharmony_ci		case LINK_10GTFD:
47438c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10000;
47448c2ecf20Sopenharmony_ci			break;
47458c2ecf20Sopenharmony_ci		case LINK_20GTFD:
47468c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_20000;
47478c2ecf20Sopenharmony_ci			break;
47488c2ecf20Sopenharmony_ci		default:
47498c2ecf20Sopenharmony_ci			break;
47508c2ecf20Sopenharmony_ci		}
47518c2ecf20Sopenharmony_ci		vars->flow_ctrl = 0;
47528c2ecf20Sopenharmony_ci		if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
47538c2ecf20Sopenharmony_ci			vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
47548c2ecf20Sopenharmony_ci
47558c2ecf20Sopenharmony_ci		if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
47568c2ecf20Sopenharmony_ci			vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
47578c2ecf20Sopenharmony_ci
47588c2ecf20Sopenharmony_ci		if (!vars->flow_ctrl)
47598c2ecf20Sopenharmony_ci			vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
47608c2ecf20Sopenharmony_ci
47618c2ecf20Sopenharmony_ci		if (vars->line_speed &&
47628c2ecf20Sopenharmony_ci		    ((vars->line_speed == SPEED_10) ||
47638c2ecf20Sopenharmony_ci		     (vars->line_speed == SPEED_100))) {
47648c2ecf20Sopenharmony_ci			vars->phy_flags |= PHY_SGMII_FLAG;
47658c2ecf20Sopenharmony_ci		} else {
47668c2ecf20Sopenharmony_ci			vars->phy_flags &= ~PHY_SGMII_FLAG;
47678c2ecf20Sopenharmony_ci		}
47688c2ecf20Sopenharmony_ci		if (vars->line_speed &&
47698c2ecf20Sopenharmony_ci		    USES_WARPCORE(bp) &&
47708c2ecf20Sopenharmony_ci		    (vars->line_speed == SPEED_1000))
47718c2ecf20Sopenharmony_ci			vars->phy_flags |= PHY_SGMII_FLAG;
47728c2ecf20Sopenharmony_ci		/* Anything 10 and over uses the bmac */
47738c2ecf20Sopenharmony_ci		link_10g_plus = (vars->line_speed >= SPEED_10000);
47748c2ecf20Sopenharmony_ci
47758c2ecf20Sopenharmony_ci		if (link_10g_plus) {
47768c2ecf20Sopenharmony_ci			if (USES_WARPCORE(bp))
47778c2ecf20Sopenharmony_ci				vars->mac_type = MAC_TYPE_XMAC;
47788c2ecf20Sopenharmony_ci			else
47798c2ecf20Sopenharmony_ci				vars->mac_type = MAC_TYPE_BMAC;
47808c2ecf20Sopenharmony_ci		} else {
47818c2ecf20Sopenharmony_ci			if (USES_WARPCORE(bp))
47828c2ecf20Sopenharmony_ci				vars->mac_type = MAC_TYPE_UMAC;
47838c2ecf20Sopenharmony_ci			else
47848c2ecf20Sopenharmony_ci				vars->mac_type = MAC_TYPE_EMAC;
47858c2ecf20Sopenharmony_ci		}
47868c2ecf20Sopenharmony_ci	} else { /* Link down */
47878c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "phy link down\n");
47888c2ecf20Sopenharmony_ci
47898c2ecf20Sopenharmony_ci		vars->phy_link_up = 0;
47908c2ecf20Sopenharmony_ci
47918c2ecf20Sopenharmony_ci		vars->line_speed = 0;
47928c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
47938c2ecf20Sopenharmony_ci		vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
47948c2ecf20Sopenharmony_ci
47958c2ecf20Sopenharmony_ci		/* Indicate no mac active */
47968c2ecf20Sopenharmony_ci		vars->mac_type = MAC_TYPE_NONE;
47978c2ecf20Sopenharmony_ci		if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
47988c2ecf20Sopenharmony_ci			vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
47998c2ecf20Sopenharmony_ci		if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
48008c2ecf20Sopenharmony_ci			vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
48018c2ecf20Sopenharmony_ci	}
48028c2ecf20Sopenharmony_ci}
48038c2ecf20Sopenharmony_ci
48048c2ecf20Sopenharmony_civoid bnx2x_link_status_update(struct link_params *params,
48058c2ecf20Sopenharmony_ci			      struct link_vars *vars)
48068c2ecf20Sopenharmony_ci{
48078c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
48088c2ecf20Sopenharmony_ci	u8 port = params->port;
48098c2ecf20Sopenharmony_ci	u32 sync_offset, media_types;
48108c2ecf20Sopenharmony_ci	/* Update PHY configuration */
48118c2ecf20Sopenharmony_ci	set_phy_vars(params, vars);
48128c2ecf20Sopenharmony_ci
48138c2ecf20Sopenharmony_ci	vars->link_status = REG_RD(bp, params->shmem_base +
48148c2ecf20Sopenharmony_ci				   offsetof(struct shmem_region,
48158c2ecf20Sopenharmony_ci					    port_mb[port].link_status));
48168c2ecf20Sopenharmony_ci
48178c2ecf20Sopenharmony_ci	/* Force link UP in non LOOPBACK_EXT loopback mode(s) */
48188c2ecf20Sopenharmony_ci	if (params->loopback_mode != LOOPBACK_NONE &&
48198c2ecf20Sopenharmony_ci	    params->loopback_mode != LOOPBACK_EXT)
48208c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_LINK_UP;
48218c2ecf20Sopenharmony_ci
48228c2ecf20Sopenharmony_ci	if (bnx2x_eee_has_cap(params))
48238c2ecf20Sopenharmony_ci		vars->eee_status = REG_RD(bp, params->shmem2_base +
48248c2ecf20Sopenharmony_ci					  offsetof(struct shmem2_region,
48258c2ecf20Sopenharmony_ci						   eee_status[params->port]));
48268c2ecf20Sopenharmony_ci
48278c2ecf20Sopenharmony_ci	vars->phy_flags = PHY_XGXS_FLAG;
48288c2ecf20Sopenharmony_ci	bnx2x_sync_link(params, vars);
48298c2ecf20Sopenharmony_ci	/* Sync media type */
48308c2ecf20Sopenharmony_ci	sync_offset = params->shmem_base +
48318c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
48328c2ecf20Sopenharmony_ci				 dev_info.port_hw_config[port].media_type);
48338c2ecf20Sopenharmony_ci	media_types = REG_RD(bp, sync_offset);
48348c2ecf20Sopenharmony_ci
48358c2ecf20Sopenharmony_ci	params->phy[INT_PHY].media_type =
48368c2ecf20Sopenharmony_ci		(media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
48378c2ecf20Sopenharmony_ci		PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
48388c2ecf20Sopenharmony_ci	params->phy[EXT_PHY1].media_type =
48398c2ecf20Sopenharmony_ci		(media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
48408c2ecf20Sopenharmony_ci		PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
48418c2ecf20Sopenharmony_ci	params->phy[EXT_PHY2].media_type =
48428c2ecf20Sopenharmony_ci		(media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
48438c2ecf20Sopenharmony_ci		PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
48448c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
48458c2ecf20Sopenharmony_ci
48468c2ecf20Sopenharmony_ci	/* Sync AEU offset */
48478c2ecf20Sopenharmony_ci	sync_offset = params->shmem_base +
48488c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
48498c2ecf20Sopenharmony_ci				 dev_info.port_hw_config[port].aeu_int_mask);
48508c2ecf20Sopenharmony_ci
48518c2ecf20Sopenharmony_ci	vars->aeu_int_mask = REG_RD(bp, sync_offset);
48528c2ecf20Sopenharmony_ci
48538c2ecf20Sopenharmony_ci	/* Sync PFC status */
48548c2ecf20Sopenharmony_ci	if (vars->link_status & LINK_STATUS_PFC_ENABLED)
48558c2ecf20Sopenharmony_ci		params->feature_config_flags |=
48568c2ecf20Sopenharmony_ci					FEATURE_CONFIG_PFC_ENABLED;
48578c2ecf20Sopenharmony_ci	else
48588c2ecf20Sopenharmony_ci		params->feature_config_flags &=
48598c2ecf20Sopenharmony_ci					~FEATURE_CONFIG_PFC_ENABLED;
48608c2ecf20Sopenharmony_ci
48618c2ecf20Sopenharmony_ci	if (SHMEM2_HAS(bp, link_attr_sync))
48628c2ecf20Sopenharmony_ci		params->link_attr_sync = SHMEM2_RD(bp,
48638c2ecf20Sopenharmony_ci						 link_attr_sync[params->port]);
48648c2ecf20Sopenharmony_ci
48658c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "link_status 0x%x  phy_link_up %x int_mask 0x%x\n",
48668c2ecf20Sopenharmony_ci		 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
48678c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "line_speed %x  duplex %x  flow_ctrl 0x%x\n",
48688c2ecf20Sopenharmony_ci		 vars->line_speed, vars->duplex, vars->flow_ctrl);
48698c2ecf20Sopenharmony_ci}
48708c2ecf20Sopenharmony_ci
48718c2ecf20Sopenharmony_cistatic void bnx2x_set_master_ln(struct link_params *params,
48728c2ecf20Sopenharmony_ci				struct bnx2x_phy *phy)
48738c2ecf20Sopenharmony_ci{
48748c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
48758c2ecf20Sopenharmony_ci	u16 new_master_ln, ser_lane;
48768c2ecf20Sopenharmony_ci	ser_lane = ((params->lane_config &
48778c2ecf20Sopenharmony_ci		     PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
48788c2ecf20Sopenharmony_ci		    PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
48798c2ecf20Sopenharmony_ci
48808c2ecf20Sopenharmony_ci	/* Set the master_ln for AN */
48818c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
48828c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_XGXS_BLOCK2,
48838c2ecf20Sopenharmony_ci			  MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
48848c2ecf20Sopenharmony_ci			  &new_master_ln);
48858c2ecf20Sopenharmony_ci
48868c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
48878c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_XGXS_BLOCK2 ,
48888c2ecf20Sopenharmony_ci			  MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
48898c2ecf20Sopenharmony_ci			  (new_master_ln | ser_lane));
48908c2ecf20Sopenharmony_ci}
48918c2ecf20Sopenharmony_ci
48928c2ecf20Sopenharmony_cistatic int bnx2x_reset_unicore(struct link_params *params,
48938c2ecf20Sopenharmony_ci			       struct bnx2x_phy *phy,
48948c2ecf20Sopenharmony_ci			       u8 set_serdes)
48958c2ecf20Sopenharmony_ci{
48968c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
48978c2ecf20Sopenharmony_ci	u16 mii_control;
48988c2ecf20Sopenharmony_ci	u16 i;
48998c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
49008c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
49018c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
49028c2ecf20Sopenharmony_ci
49038c2ecf20Sopenharmony_ci	/* Reset the unicore */
49048c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
49058c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
49068c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL,
49078c2ecf20Sopenharmony_ci			  (mii_control |
49088c2ecf20Sopenharmony_ci			   MDIO_COMBO_IEEO_MII_CONTROL_RESET));
49098c2ecf20Sopenharmony_ci	if (set_serdes)
49108c2ecf20Sopenharmony_ci		bnx2x_set_serdes_access(bp, params->port);
49118c2ecf20Sopenharmony_ci
49128c2ecf20Sopenharmony_ci	/* Wait for the reset to self clear */
49138c2ecf20Sopenharmony_ci	for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
49148c2ecf20Sopenharmony_ci		udelay(5);
49158c2ecf20Sopenharmony_ci
49168c2ecf20Sopenharmony_ci		/* The reset erased the previous bank value */
49178c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
49188c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
49198c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_MII_CONTROL,
49208c2ecf20Sopenharmony_ci				  &mii_control);
49218c2ecf20Sopenharmony_ci
49228c2ecf20Sopenharmony_ci		if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
49238c2ecf20Sopenharmony_ci			udelay(5);
49248c2ecf20Sopenharmony_ci			return 0;
49258c2ecf20Sopenharmony_ci		}
49268c2ecf20Sopenharmony_ci	}
49278c2ecf20Sopenharmony_ci
49288c2ecf20Sopenharmony_ci	netdev_err(bp->dev,  "Warning: PHY was not initialized,"
49298c2ecf20Sopenharmony_ci			      " Port %d\n",
49308c2ecf20Sopenharmony_ci			 params->port);
49318c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
49328c2ecf20Sopenharmony_ci	return -EINVAL;
49338c2ecf20Sopenharmony_ci
49348c2ecf20Sopenharmony_ci}
49358c2ecf20Sopenharmony_ci
49368c2ecf20Sopenharmony_cistatic void bnx2x_set_swap_lanes(struct link_params *params,
49378c2ecf20Sopenharmony_ci				 struct bnx2x_phy *phy)
49388c2ecf20Sopenharmony_ci{
49398c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
49408c2ecf20Sopenharmony_ci	/* Each two bits represents a lane number:
49418c2ecf20Sopenharmony_ci	 * No swap is 0123 => 0x1b no need to enable the swap
49428c2ecf20Sopenharmony_ci	 */
49438c2ecf20Sopenharmony_ci	u16 rx_lane_swap, tx_lane_swap;
49448c2ecf20Sopenharmony_ci
49458c2ecf20Sopenharmony_ci	rx_lane_swap = ((params->lane_config &
49468c2ecf20Sopenharmony_ci			 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
49478c2ecf20Sopenharmony_ci			PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
49488c2ecf20Sopenharmony_ci	tx_lane_swap = ((params->lane_config &
49498c2ecf20Sopenharmony_ci			 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
49508c2ecf20Sopenharmony_ci			PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
49518c2ecf20Sopenharmony_ci
49528c2ecf20Sopenharmony_ci	if (rx_lane_swap != 0x1b) {
49538c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
49548c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_XGXS_BLOCK2,
49558c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_RX_LN_SWAP,
49568c2ecf20Sopenharmony_ci				  (rx_lane_swap |
49578c2ecf20Sopenharmony_ci				   MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
49588c2ecf20Sopenharmony_ci				   MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
49598c2ecf20Sopenharmony_ci	} else {
49608c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
49618c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_XGXS_BLOCK2,
49628c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
49638c2ecf20Sopenharmony_ci	}
49648c2ecf20Sopenharmony_ci
49658c2ecf20Sopenharmony_ci	if (tx_lane_swap != 0x1b) {
49668c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
49678c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_XGXS_BLOCK2,
49688c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_TX_LN_SWAP,
49698c2ecf20Sopenharmony_ci				  (tx_lane_swap |
49708c2ecf20Sopenharmony_ci				   MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
49718c2ecf20Sopenharmony_ci	} else {
49728c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
49738c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_XGXS_BLOCK2,
49748c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
49758c2ecf20Sopenharmony_ci	}
49768c2ecf20Sopenharmony_ci}
49778c2ecf20Sopenharmony_ci
49788c2ecf20Sopenharmony_cistatic void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
49798c2ecf20Sopenharmony_ci					 struct link_params *params)
49808c2ecf20Sopenharmony_ci{
49818c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
49828c2ecf20Sopenharmony_ci	u16 control2;
49838c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
49848c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
49858c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
49868c2ecf20Sopenharmony_ci			  &control2);
49878c2ecf20Sopenharmony_ci	if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
49888c2ecf20Sopenharmony_ci		control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
49898c2ecf20Sopenharmony_ci	else
49908c2ecf20Sopenharmony_ci		control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
49918c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
49928c2ecf20Sopenharmony_ci		phy->speed_cap_mask, control2);
49938c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
49948c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
49958c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
49968c2ecf20Sopenharmony_ci			  control2);
49978c2ecf20Sopenharmony_ci
49988c2ecf20Sopenharmony_ci	if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
49998c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask &
50008c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
50018c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS\n");
50028c2ecf20Sopenharmony_ci
50038c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
50048c2ecf20Sopenharmony_ci				 MDIO_REG_BANK_10G_PARALLEL_DETECT,
50058c2ecf20Sopenharmony_ci				 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
50068c2ecf20Sopenharmony_ci				 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
50078c2ecf20Sopenharmony_ci
50088c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
50098c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_10G_PARALLEL_DETECT,
50108c2ecf20Sopenharmony_ci				  MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
50118c2ecf20Sopenharmony_ci				  &control2);
50128c2ecf20Sopenharmony_ci
50138c2ecf20Sopenharmony_ci
50148c2ecf20Sopenharmony_ci		control2 |=
50158c2ecf20Sopenharmony_ci		    MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
50168c2ecf20Sopenharmony_ci
50178c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
50188c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_10G_PARALLEL_DETECT,
50198c2ecf20Sopenharmony_ci				  MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
50208c2ecf20Sopenharmony_ci				  control2);
50218c2ecf20Sopenharmony_ci
50228c2ecf20Sopenharmony_ci		/* Disable parallel detection of HiG */
50238c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
50248c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_XGXS_BLOCK2,
50258c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
50268c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
50278c2ecf20Sopenharmony_ci				  MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
50288c2ecf20Sopenharmony_ci	}
50298c2ecf20Sopenharmony_ci}
50308c2ecf20Sopenharmony_ci
50318c2ecf20Sopenharmony_cistatic void bnx2x_set_autoneg(struct bnx2x_phy *phy,
50328c2ecf20Sopenharmony_ci			      struct link_params *params,
50338c2ecf20Sopenharmony_ci			      struct link_vars *vars,
50348c2ecf20Sopenharmony_ci			      u8 enable_cl73)
50358c2ecf20Sopenharmony_ci{
50368c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
50378c2ecf20Sopenharmony_ci	u16 reg_val;
50388c2ecf20Sopenharmony_ci
50398c2ecf20Sopenharmony_ci	/* CL37 Autoneg */
50408c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
50418c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
50428c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
50438c2ecf20Sopenharmony_ci
50448c2ecf20Sopenharmony_ci	/* CL37 Autoneg Enabled */
50458c2ecf20Sopenharmony_ci	if (vars->line_speed == SPEED_AUTO_NEG)
50468c2ecf20Sopenharmony_ci		reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
50478c2ecf20Sopenharmony_ci	else /* CL37 Autoneg Disabled */
50488c2ecf20Sopenharmony_ci		reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
50498c2ecf20Sopenharmony_ci			     MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
50508c2ecf20Sopenharmony_ci
50518c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
50528c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
50538c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
50548c2ecf20Sopenharmony_ci
50558c2ecf20Sopenharmony_ci	/* Enable/Disable Autodetection */
50568c2ecf20Sopenharmony_ci
50578c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
50588c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
50598c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
50608c2ecf20Sopenharmony_ci	reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
50618c2ecf20Sopenharmony_ci		    MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
50628c2ecf20Sopenharmony_ci	reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
50638c2ecf20Sopenharmony_ci	if (vars->line_speed == SPEED_AUTO_NEG)
50648c2ecf20Sopenharmony_ci		reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
50658c2ecf20Sopenharmony_ci	else
50668c2ecf20Sopenharmony_ci		reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
50678c2ecf20Sopenharmony_ci
50688c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
50698c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
50708c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
50718c2ecf20Sopenharmony_ci
50728c2ecf20Sopenharmony_ci	/* Enable TetonII and BAM autoneg */
50738c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
50748c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_BAM_NEXT_PAGE,
50758c2ecf20Sopenharmony_ci			  MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
50768c2ecf20Sopenharmony_ci			  &reg_val);
50778c2ecf20Sopenharmony_ci	if (vars->line_speed == SPEED_AUTO_NEG) {
50788c2ecf20Sopenharmony_ci		/* Enable BAM aneg Mode and TetonII aneg Mode */
50798c2ecf20Sopenharmony_ci		reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
50808c2ecf20Sopenharmony_ci			    MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
50818c2ecf20Sopenharmony_ci	} else {
50828c2ecf20Sopenharmony_ci		/* TetonII and BAM Autoneg Disabled */
50838c2ecf20Sopenharmony_ci		reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
50848c2ecf20Sopenharmony_ci			     MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
50858c2ecf20Sopenharmony_ci	}
50868c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
50878c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_BAM_NEXT_PAGE,
50888c2ecf20Sopenharmony_ci			  MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
50898c2ecf20Sopenharmony_ci			  reg_val);
50908c2ecf20Sopenharmony_ci
50918c2ecf20Sopenharmony_ci	if (enable_cl73) {
50928c2ecf20Sopenharmony_ci		/* Enable Cl73 FSM status bits */
50938c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
50948c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_USERB0,
50958c2ecf20Sopenharmony_ci				  MDIO_CL73_USERB0_CL73_UCTRL,
50968c2ecf20Sopenharmony_ci				  0xe);
50978c2ecf20Sopenharmony_ci
50988c2ecf20Sopenharmony_ci		/* Enable BAM Station Manager*/
50998c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
51008c2ecf20Sopenharmony_ci			MDIO_REG_BANK_CL73_USERB0,
51018c2ecf20Sopenharmony_ci			MDIO_CL73_USERB0_CL73_BAM_CTRL1,
51028c2ecf20Sopenharmony_ci			MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
51038c2ecf20Sopenharmony_ci			MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
51048c2ecf20Sopenharmony_ci			MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
51058c2ecf20Sopenharmony_ci
51068c2ecf20Sopenharmony_ci		/* Advertise CL73 link speeds */
51078c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
51088c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB1,
51098c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB1_AN_ADV2,
51108c2ecf20Sopenharmony_ci				  &reg_val);
51118c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
51128c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
51138c2ecf20Sopenharmony_ci			reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
51148c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
51158c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
51168c2ecf20Sopenharmony_ci			reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
51178c2ecf20Sopenharmony_ci
51188c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
51198c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB1,
51208c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB1_AN_ADV2,
51218c2ecf20Sopenharmony_ci				  reg_val);
51228c2ecf20Sopenharmony_ci
51238c2ecf20Sopenharmony_ci		/* CL73 Autoneg Enabled */
51248c2ecf20Sopenharmony_ci		reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
51258c2ecf20Sopenharmony_ci
51268c2ecf20Sopenharmony_ci	} else /* CL73 Autoneg Disabled */
51278c2ecf20Sopenharmony_ci		reg_val = 0;
51288c2ecf20Sopenharmony_ci
51298c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
51308c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_CL73_IEEEB0,
51318c2ecf20Sopenharmony_ci			  MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
51328c2ecf20Sopenharmony_ci}
51338c2ecf20Sopenharmony_ci
51348c2ecf20Sopenharmony_ci/* Program SerDes, forced speed */
51358c2ecf20Sopenharmony_cistatic void bnx2x_program_serdes(struct bnx2x_phy *phy,
51368c2ecf20Sopenharmony_ci				 struct link_params *params,
51378c2ecf20Sopenharmony_ci				 struct link_vars *vars)
51388c2ecf20Sopenharmony_ci{
51398c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
51408c2ecf20Sopenharmony_ci	u16 reg_val;
51418c2ecf20Sopenharmony_ci
51428c2ecf20Sopenharmony_ci	/* Program duplex, disable autoneg and sgmii*/
51438c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
51448c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
51458c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
51468c2ecf20Sopenharmony_ci	reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
51478c2ecf20Sopenharmony_ci		     MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
51488c2ecf20Sopenharmony_ci		     MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
51498c2ecf20Sopenharmony_ci	if (phy->req_duplex == DUPLEX_FULL)
51508c2ecf20Sopenharmony_ci		reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
51518c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
51528c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
51538c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
51548c2ecf20Sopenharmony_ci
51558c2ecf20Sopenharmony_ci	/* Program speed
51568c2ecf20Sopenharmony_ci	 *  - needed only if the speed is greater than 1G (2.5G or 10G)
51578c2ecf20Sopenharmony_ci	 */
51588c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
51598c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
51608c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_MISC1, &reg_val);
51618c2ecf20Sopenharmony_ci	/* Clearing the speed value before setting the right speed */
51628c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
51638c2ecf20Sopenharmony_ci
51648c2ecf20Sopenharmony_ci	reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
51658c2ecf20Sopenharmony_ci		     MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
51668c2ecf20Sopenharmony_ci
51678c2ecf20Sopenharmony_ci	if (!((vars->line_speed == SPEED_1000) ||
51688c2ecf20Sopenharmony_ci	      (vars->line_speed == SPEED_100) ||
51698c2ecf20Sopenharmony_ci	      (vars->line_speed == SPEED_10))) {
51708c2ecf20Sopenharmony_ci
51718c2ecf20Sopenharmony_ci		reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
51728c2ecf20Sopenharmony_ci			    MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
51738c2ecf20Sopenharmony_ci		if (vars->line_speed == SPEED_10000)
51748c2ecf20Sopenharmony_ci			reg_val |=
51758c2ecf20Sopenharmony_ci				MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
51768c2ecf20Sopenharmony_ci	}
51778c2ecf20Sopenharmony_ci
51788c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
51798c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
51808c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_MISC1, reg_val);
51818c2ecf20Sopenharmony_ci
51828c2ecf20Sopenharmony_ci}
51838c2ecf20Sopenharmony_ci
51848c2ecf20Sopenharmony_cistatic void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
51858c2ecf20Sopenharmony_ci					      struct link_params *params)
51868c2ecf20Sopenharmony_ci{
51878c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
51888c2ecf20Sopenharmony_ci	u16 val = 0;
51898c2ecf20Sopenharmony_ci
51908c2ecf20Sopenharmony_ci	/* Set extended capabilities */
51918c2ecf20Sopenharmony_ci	if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
51928c2ecf20Sopenharmony_ci		val |= MDIO_OVER_1G_UP1_2_5G;
51938c2ecf20Sopenharmony_ci	if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
51948c2ecf20Sopenharmony_ci		val |= MDIO_OVER_1G_UP1_10G;
51958c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
51968c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_OVER_1G,
51978c2ecf20Sopenharmony_ci			  MDIO_OVER_1G_UP1, val);
51988c2ecf20Sopenharmony_ci
51998c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
52008c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_OVER_1G,
52018c2ecf20Sopenharmony_ci			  MDIO_OVER_1G_UP3, 0x400);
52028c2ecf20Sopenharmony_ci}
52038c2ecf20Sopenharmony_ci
52048c2ecf20Sopenharmony_cistatic void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
52058c2ecf20Sopenharmony_ci					      struct link_params *params,
52068c2ecf20Sopenharmony_ci					      u16 ieee_fc)
52078c2ecf20Sopenharmony_ci{
52088c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
52098c2ecf20Sopenharmony_ci	u16 val;
52108c2ecf20Sopenharmony_ci	/* For AN, we are always publishing full duplex */
52118c2ecf20Sopenharmony_ci
52128c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
52138c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_COMBO_IEEE0,
52148c2ecf20Sopenharmony_ci			  MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
52158c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
52168c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_CL73_IEEEB1,
52178c2ecf20Sopenharmony_ci			  MDIO_CL73_IEEEB1_AN_ADV1, &val);
52188c2ecf20Sopenharmony_ci	val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
52198c2ecf20Sopenharmony_ci	val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
52208c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
52218c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_CL73_IEEEB1,
52228c2ecf20Sopenharmony_ci			  MDIO_CL73_IEEEB1_AN_ADV1, val);
52238c2ecf20Sopenharmony_ci}
52248c2ecf20Sopenharmony_ci
52258c2ecf20Sopenharmony_cistatic void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
52268c2ecf20Sopenharmony_ci				  struct link_params *params,
52278c2ecf20Sopenharmony_ci				  u8 enable_cl73)
52288c2ecf20Sopenharmony_ci{
52298c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
52308c2ecf20Sopenharmony_ci	u16 mii_control;
52318c2ecf20Sopenharmony_ci
52328c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
52338c2ecf20Sopenharmony_ci	/* Enable and restart BAM/CL37 aneg */
52348c2ecf20Sopenharmony_ci
52358c2ecf20Sopenharmony_ci	if (enable_cl73) {
52368c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
52378c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB0,
52388c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
52398c2ecf20Sopenharmony_ci				  &mii_control);
52408c2ecf20Sopenharmony_ci
52418c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
52428c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB0,
52438c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
52448c2ecf20Sopenharmony_ci				  (mii_control |
52458c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
52468c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
52478c2ecf20Sopenharmony_ci	} else {
52488c2ecf20Sopenharmony_ci
52498c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
52508c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
52518c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_MII_CONTROL,
52528c2ecf20Sopenharmony_ci				  &mii_control);
52538c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
52548c2ecf20Sopenharmony_ci			 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
52558c2ecf20Sopenharmony_ci			 mii_control);
52568c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
52578c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
52588c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_MII_CONTROL,
52598c2ecf20Sopenharmony_ci				  (mii_control |
52608c2ecf20Sopenharmony_ci				   MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
52618c2ecf20Sopenharmony_ci				   MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
52628c2ecf20Sopenharmony_ci	}
52638c2ecf20Sopenharmony_ci}
52648c2ecf20Sopenharmony_ci
52658c2ecf20Sopenharmony_cistatic void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
52668c2ecf20Sopenharmony_ci					   struct link_params *params,
52678c2ecf20Sopenharmony_ci					   struct link_vars *vars)
52688c2ecf20Sopenharmony_ci{
52698c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
52708c2ecf20Sopenharmony_ci	u16 control1;
52718c2ecf20Sopenharmony_ci
52728c2ecf20Sopenharmony_ci	/* In SGMII mode, the unicore is always slave */
52738c2ecf20Sopenharmony_ci
52748c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
52758c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
52768c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
52778c2ecf20Sopenharmony_ci			  &control1);
52788c2ecf20Sopenharmony_ci	control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
52798c2ecf20Sopenharmony_ci	/* Set sgmii mode (and not fiber) */
52808c2ecf20Sopenharmony_ci	control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
52818c2ecf20Sopenharmony_ci		      MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
52828c2ecf20Sopenharmony_ci		      MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
52838c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
52848c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
52858c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
52868c2ecf20Sopenharmony_ci			  control1);
52878c2ecf20Sopenharmony_ci
52888c2ecf20Sopenharmony_ci	/* If forced speed */
52898c2ecf20Sopenharmony_ci	if (!(vars->line_speed == SPEED_AUTO_NEG)) {
52908c2ecf20Sopenharmony_ci		/* Set speed, disable autoneg */
52918c2ecf20Sopenharmony_ci		u16 mii_control;
52928c2ecf20Sopenharmony_ci
52938c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
52948c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
52958c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_MII_CONTROL,
52968c2ecf20Sopenharmony_ci				  &mii_control);
52978c2ecf20Sopenharmony_ci		mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
52988c2ecf20Sopenharmony_ci				 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
52998c2ecf20Sopenharmony_ci				 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
53008c2ecf20Sopenharmony_ci
53018c2ecf20Sopenharmony_ci		switch (vars->line_speed) {
53028c2ecf20Sopenharmony_ci		case SPEED_100:
53038c2ecf20Sopenharmony_ci			mii_control |=
53048c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
53058c2ecf20Sopenharmony_ci			break;
53068c2ecf20Sopenharmony_ci		case SPEED_1000:
53078c2ecf20Sopenharmony_ci			mii_control |=
53088c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
53098c2ecf20Sopenharmony_ci			break;
53108c2ecf20Sopenharmony_ci		case SPEED_10:
53118c2ecf20Sopenharmony_ci			/* There is nothing to set for 10M */
53128c2ecf20Sopenharmony_ci			break;
53138c2ecf20Sopenharmony_ci		default:
53148c2ecf20Sopenharmony_ci			/* Invalid speed for SGMII */
53158c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
53168c2ecf20Sopenharmony_ci				  vars->line_speed);
53178c2ecf20Sopenharmony_ci			break;
53188c2ecf20Sopenharmony_ci		}
53198c2ecf20Sopenharmony_ci
53208c2ecf20Sopenharmony_ci		/* Setting the full duplex */
53218c2ecf20Sopenharmony_ci		if (phy->req_duplex == DUPLEX_FULL)
53228c2ecf20Sopenharmony_ci			mii_control |=
53238c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
53248c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
53258c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
53268c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_MII_CONTROL,
53278c2ecf20Sopenharmony_ci				  mii_control);
53288c2ecf20Sopenharmony_ci
53298c2ecf20Sopenharmony_ci	} else { /* AN mode */
53308c2ecf20Sopenharmony_ci		/* Enable and restart AN */
53318c2ecf20Sopenharmony_ci		bnx2x_restart_autoneg(phy, params, 0);
53328c2ecf20Sopenharmony_ci	}
53338c2ecf20Sopenharmony_ci}
53348c2ecf20Sopenharmony_ci
53358c2ecf20Sopenharmony_ci/* Link management
53368c2ecf20Sopenharmony_ci */
53378c2ecf20Sopenharmony_cistatic int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
53388c2ecf20Sopenharmony_ci					     struct link_params *params)
53398c2ecf20Sopenharmony_ci{
53408c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
53418c2ecf20Sopenharmony_ci	u16 pd_10g, status2_1000x;
53428c2ecf20Sopenharmony_ci	if (phy->req_line_speed != SPEED_AUTO_NEG)
53438c2ecf20Sopenharmony_ci		return 0;
53448c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
53458c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
53468c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
53478c2ecf20Sopenharmony_ci			  &status2_1000x);
53488c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
53498c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_SERDES_DIGITAL,
53508c2ecf20Sopenharmony_ci			  MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
53518c2ecf20Sopenharmony_ci			  &status2_1000x);
53528c2ecf20Sopenharmony_ci	if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
53538c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
53548c2ecf20Sopenharmony_ci			 params->port);
53558c2ecf20Sopenharmony_ci		return 1;
53568c2ecf20Sopenharmony_ci	}
53578c2ecf20Sopenharmony_ci
53588c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
53598c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_10G_PARALLEL_DETECT,
53608c2ecf20Sopenharmony_ci			  MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
53618c2ecf20Sopenharmony_ci			  &pd_10g);
53628c2ecf20Sopenharmony_ci
53638c2ecf20Sopenharmony_ci	if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
53648c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
53658c2ecf20Sopenharmony_ci			 params->port);
53668c2ecf20Sopenharmony_ci		return 1;
53678c2ecf20Sopenharmony_ci	}
53688c2ecf20Sopenharmony_ci	return 0;
53698c2ecf20Sopenharmony_ci}
53708c2ecf20Sopenharmony_ci
53718c2ecf20Sopenharmony_cistatic void bnx2x_update_adv_fc(struct bnx2x_phy *phy,
53728c2ecf20Sopenharmony_ci				struct link_params *params,
53738c2ecf20Sopenharmony_ci				struct link_vars *vars,
53748c2ecf20Sopenharmony_ci				u32 gp_status)
53758c2ecf20Sopenharmony_ci{
53768c2ecf20Sopenharmony_ci	u16 ld_pause;   /* local driver */
53778c2ecf20Sopenharmony_ci	u16 lp_pause;   /* link partner */
53788c2ecf20Sopenharmony_ci	u16 pause_result;
53798c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
53808c2ecf20Sopenharmony_ci	if ((gp_status &
53818c2ecf20Sopenharmony_ci	     (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
53828c2ecf20Sopenharmony_ci	      MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
53838c2ecf20Sopenharmony_ci	    (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
53848c2ecf20Sopenharmony_ci	     MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
53858c2ecf20Sopenharmony_ci
53868c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
53878c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB1,
53888c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB1_AN_ADV1,
53898c2ecf20Sopenharmony_ci				  &ld_pause);
53908c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
53918c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB1,
53928c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB1_AN_LP_ADV1,
53938c2ecf20Sopenharmony_ci				  &lp_pause);
53948c2ecf20Sopenharmony_ci		pause_result = (ld_pause &
53958c2ecf20Sopenharmony_ci				MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
53968c2ecf20Sopenharmony_ci		pause_result |= (lp_pause &
53978c2ecf20Sopenharmony_ci				 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
53988c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n", pause_result);
53998c2ecf20Sopenharmony_ci	} else {
54008c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
54018c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_COMBO_IEEE0,
54028c2ecf20Sopenharmony_ci				  MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
54038c2ecf20Sopenharmony_ci				  &ld_pause);
54048c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
54058c2ecf20Sopenharmony_ci			MDIO_REG_BANK_COMBO_IEEE0,
54068c2ecf20Sopenharmony_ci			MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
54078c2ecf20Sopenharmony_ci			&lp_pause);
54088c2ecf20Sopenharmony_ci		pause_result = (ld_pause &
54098c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
54108c2ecf20Sopenharmony_ci		pause_result |= (lp_pause &
54118c2ecf20Sopenharmony_ci				 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
54128c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n", pause_result);
54138c2ecf20Sopenharmony_ci	}
54148c2ecf20Sopenharmony_ci	bnx2x_pause_resolve(phy, params, vars, pause_result);
54158c2ecf20Sopenharmony_ci
54168c2ecf20Sopenharmony_ci}
54178c2ecf20Sopenharmony_ci
54188c2ecf20Sopenharmony_cistatic void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
54198c2ecf20Sopenharmony_ci				    struct link_params *params,
54208c2ecf20Sopenharmony_ci				    struct link_vars *vars,
54218c2ecf20Sopenharmony_ci				    u32 gp_status)
54228c2ecf20Sopenharmony_ci{
54238c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
54248c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
54258c2ecf20Sopenharmony_ci
54268c2ecf20Sopenharmony_ci	/* Resolve from gp_status in case of AN complete and not sgmii */
54278c2ecf20Sopenharmony_ci	if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
54288c2ecf20Sopenharmony_ci		/* Update the advertised flow-controled of LD/LP in AN */
54298c2ecf20Sopenharmony_ci		if (phy->req_line_speed == SPEED_AUTO_NEG)
54308c2ecf20Sopenharmony_ci			bnx2x_update_adv_fc(phy, params, vars, gp_status);
54318c2ecf20Sopenharmony_ci		/* But set the flow-control result as the requested one */
54328c2ecf20Sopenharmony_ci		vars->flow_ctrl = phy->req_flow_ctrl;
54338c2ecf20Sopenharmony_ci	} else if (phy->req_line_speed != SPEED_AUTO_NEG)
54348c2ecf20Sopenharmony_ci		vars->flow_ctrl = params->req_fc_auto_adv;
54358c2ecf20Sopenharmony_ci	else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
54368c2ecf20Sopenharmony_ci		 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
54378c2ecf20Sopenharmony_ci		if (bnx2x_direct_parallel_detect_used(phy, params)) {
54388c2ecf20Sopenharmony_ci			vars->flow_ctrl = params->req_fc_auto_adv;
54398c2ecf20Sopenharmony_ci			return;
54408c2ecf20Sopenharmony_ci		}
54418c2ecf20Sopenharmony_ci		bnx2x_update_adv_fc(phy, params, vars, gp_status);
54428c2ecf20Sopenharmony_ci	}
54438c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
54448c2ecf20Sopenharmony_ci}
54458c2ecf20Sopenharmony_ci
54468c2ecf20Sopenharmony_cistatic void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
54478c2ecf20Sopenharmony_ci					 struct link_params *params)
54488c2ecf20Sopenharmony_ci{
54498c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
54508c2ecf20Sopenharmony_ci	u16 rx_status, ustat_val, cl37_fsm_received;
54518c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
54528c2ecf20Sopenharmony_ci	/* Step 1: Make sure signal is detected */
54538c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
54548c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_RX0,
54558c2ecf20Sopenharmony_ci			  MDIO_RX0_RX_STATUS,
54568c2ecf20Sopenharmony_ci			  &rx_status);
54578c2ecf20Sopenharmony_ci	if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
54588c2ecf20Sopenharmony_ci	    (MDIO_RX0_RX_STATUS_SIGDET)) {
54598c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
54608c2ecf20Sopenharmony_ci			     "rx_status(0x80b0) = 0x%x\n", rx_status);
54618c2ecf20Sopenharmony_ci		CL22_WR_OVER_CL45(bp, phy,
54628c2ecf20Sopenharmony_ci				  MDIO_REG_BANK_CL73_IEEEB0,
54638c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
54648c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
54658c2ecf20Sopenharmony_ci		return;
54668c2ecf20Sopenharmony_ci	}
54678c2ecf20Sopenharmony_ci	/* Step 2: Check CL73 state machine */
54688c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
54698c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_CL73_USERB0,
54708c2ecf20Sopenharmony_ci			  MDIO_CL73_USERB0_CL73_USTAT1,
54718c2ecf20Sopenharmony_ci			  &ustat_val);
54728c2ecf20Sopenharmony_ci	if ((ustat_val &
54738c2ecf20Sopenharmony_ci	     (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
54748c2ecf20Sopenharmony_ci	      MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
54758c2ecf20Sopenharmony_ci	    (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
54768c2ecf20Sopenharmony_ci	      MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
54778c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
54788c2ecf20Sopenharmony_ci			     "ustat_val(0x8371) = 0x%x\n", ustat_val);
54798c2ecf20Sopenharmony_ci		return;
54808c2ecf20Sopenharmony_ci	}
54818c2ecf20Sopenharmony_ci	/* Step 3: Check CL37 Message Pages received to indicate LP
54828c2ecf20Sopenharmony_ci	 * supports only CL37
54838c2ecf20Sopenharmony_ci	 */
54848c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
54858c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_REMOTE_PHY,
54868c2ecf20Sopenharmony_ci			  MDIO_REMOTE_PHY_MISC_RX_STATUS,
54878c2ecf20Sopenharmony_ci			  &cl37_fsm_received);
54888c2ecf20Sopenharmony_ci	if ((cl37_fsm_received &
54898c2ecf20Sopenharmony_ci	     (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
54908c2ecf20Sopenharmony_ci	     MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
54918c2ecf20Sopenharmony_ci	    (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
54928c2ecf20Sopenharmony_ci	      MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
54938c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
54948c2ecf20Sopenharmony_ci			     "misc_rx_status(0x8330) = 0x%x\n",
54958c2ecf20Sopenharmony_ci			 cl37_fsm_received);
54968c2ecf20Sopenharmony_ci		return;
54978c2ecf20Sopenharmony_ci	}
54988c2ecf20Sopenharmony_ci	/* The combined cl37/cl73 fsm state information indicating that
54998c2ecf20Sopenharmony_ci	 * we are connected to a device which does not support cl73, but
55008c2ecf20Sopenharmony_ci	 * does support cl37 BAM. In this case we disable cl73 and
55018c2ecf20Sopenharmony_ci	 * restart cl37 auto-neg
55028c2ecf20Sopenharmony_ci	 */
55038c2ecf20Sopenharmony_ci
55048c2ecf20Sopenharmony_ci	/* Disable CL73 */
55058c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy,
55068c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_CL73_IEEEB0,
55078c2ecf20Sopenharmony_ci			  MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
55088c2ecf20Sopenharmony_ci			  0);
55098c2ecf20Sopenharmony_ci	/* Restart CL37 autoneg */
55108c2ecf20Sopenharmony_ci	bnx2x_restart_autoneg(phy, params, 0);
55118c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
55128c2ecf20Sopenharmony_ci}
55138c2ecf20Sopenharmony_ci
55148c2ecf20Sopenharmony_cistatic void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
55158c2ecf20Sopenharmony_ci				  struct link_params *params,
55168c2ecf20Sopenharmony_ci				  struct link_vars *vars,
55178c2ecf20Sopenharmony_ci				  u32 gp_status)
55188c2ecf20Sopenharmony_ci{
55198c2ecf20Sopenharmony_ci	if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
55208c2ecf20Sopenharmony_ci		vars->link_status |=
55218c2ecf20Sopenharmony_ci			LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
55228c2ecf20Sopenharmony_ci
55238c2ecf20Sopenharmony_ci	if (bnx2x_direct_parallel_detect_used(phy, params))
55248c2ecf20Sopenharmony_ci		vars->link_status |=
55258c2ecf20Sopenharmony_ci			LINK_STATUS_PARALLEL_DETECTION_USED;
55268c2ecf20Sopenharmony_ci}
55278c2ecf20Sopenharmony_cistatic int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
55288c2ecf20Sopenharmony_ci				     struct link_params *params,
55298c2ecf20Sopenharmony_ci				      struct link_vars *vars,
55308c2ecf20Sopenharmony_ci				      u16 is_link_up,
55318c2ecf20Sopenharmony_ci				      u16 speed_mask,
55328c2ecf20Sopenharmony_ci				      u16 is_duplex)
55338c2ecf20Sopenharmony_ci{
55348c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
55358c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_AUTO_NEG)
55368c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
55378c2ecf20Sopenharmony_ci	if (is_link_up) {
55388c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "phy link up\n");
55398c2ecf20Sopenharmony_ci
55408c2ecf20Sopenharmony_ci		vars->phy_link_up = 1;
55418c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_LINK_UP;
55428c2ecf20Sopenharmony_ci
55438c2ecf20Sopenharmony_ci		switch (speed_mask) {
55448c2ecf20Sopenharmony_ci		case GP_STATUS_10M:
55458c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10;
55468c2ecf20Sopenharmony_ci			if (is_duplex == DUPLEX_FULL)
55478c2ecf20Sopenharmony_ci				vars->link_status |= LINK_10TFD;
55488c2ecf20Sopenharmony_ci			else
55498c2ecf20Sopenharmony_ci				vars->link_status |= LINK_10THD;
55508c2ecf20Sopenharmony_ci			break;
55518c2ecf20Sopenharmony_ci
55528c2ecf20Sopenharmony_ci		case GP_STATUS_100M:
55538c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_100;
55548c2ecf20Sopenharmony_ci			if (is_duplex == DUPLEX_FULL)
55558c2ecf20Sopenharmony_ci				vars->link_status |= LINK_100TXFD;
55568c2ecf20Sopenharmony_ci			else
55578c2ecf20Sopenharmony_ci				vars->link_status |= LINK_100TXHD;
55588c2ecf20Sopenharmony_ci			break;
55598c2ecf20Sopenharmony_ci
55608c2ecf20Sopenharmony_ci		case GP_STATUS_1G:
55618c2ecf20Sopenharmony_ci		case GP_STATUS_1G_KX:
55628c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
55638c2ecf20Sopenharmony_ci			if (is_duplex == DUPLEX_FULL)
55648c2ecf20Sopenharmony_ci				vars->link_status |= LINK_1000TFD;
55658c2ecf20Sopenharmony_ci			else
55668c2ecf20Sopenharmony_ci				vars->link_status |= LINK_1000THD;
55678c2ecf20Sopenharmony_ci			break;
55688c2ecf20Sopenharmony_ci
55698c2ecf20Sopenharmony_ci		case GP_STATUS_2_5G:
55708c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_2500;
55718c2ecf20Sopenharmony_ci			if (is_duplex == DUPLEX_FULL)
55728c2ecf20Sopenharmony_ci				vars->link_status |= LINK_2500TFD;
55738c2ecf20Sopenharmony_ci			else
55748c2ecf20Sopenharmony_ci				vars->link_status |= LINK_2500THD;
55758c2ecf20Sopenharmony_ci			break;
55768c2ecf20Sopenharmony_ci
55778c2ecf20Sopenharmony_ci		case GP_STATUS_5G:
55788c2ecf20Sopenharmony_ci		case GP_STATUS_6G:
55798c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
55808c2ecf20Sopenharmony_ci				 "link speed unsupported  gp_status 0x%x\n",
55818c2ecf20Sopenharmony_ci				  speed_mask);
55828c2ecf20Sopenharmony_ci			return -EINVAL;
55838c2ecf20Sopenharmony_ci
55848c2ecf20Sopenharmony_ci		case GP_STATUS_10G_KX4:
55858c2ecf20Sopenharmony_ci		case GP_STATUS_10G_HIG:
55868c2ecf20Sopenharmony_ci		case GP_STATUS_10G_CX4:
55878c2ecf20Sopenharmony_ci		case GP_STATUS_10G_KR:
55888c2ecf20Sopenharmony_ci		case GP_STATUS_10G_SFI:
55898c2ecf20Sopenharmony_ci		case GP_STATUS_10G_XFI:
55908c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10000;
55918c2ecf20Sopenharmony_ci			vars->link_status |= LINK_10GTFD;
55928c2ecf20Sopenharmony_ci			break;
55938c2ecf20Sopenharmony_ci		case GP_STATUS_20G_DXGXS:
55948c2ecf20Sopenharmony_ci		case GP_STATUS_20G_KR2:
55958c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_20000;
55968c2ecf20Sopenharmony_ci			vars->link_status |= LINK_20GTFD;
55978c2ecf20Sopenharmony_ci			break;
55988c2ecf20Sopenharmony_ci		default:
55998c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
56008c2ecf20Sopenharmony_ci				  "link speed unsupported gp_status 0x%x\n",
56018c2ecf20Sopenharmony_ci				  speed_mask);
56028c2ecf20Sopenharmony_ci			return -EINVAL;
56038c2ecf20Sopenharmony_ci		}
56048c2ecf20Sopenharmony_ci	} else { /* link_down */
56058c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "phy link down\n");
56068c2ecf20Sopenharmony_ci
56078c2ecf20Sopenharmony_ci		vars->phy_link_up = 0;
56088c2ecf20Sopenharmony_ci
56098c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
56108c2ecf20Sopenharmony_ci		vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
56118c2ecf20Sopenharmony_ci		vars->mac_type = MAC_TYPE_NONE;
56128c2ecf20Sopenharmony_ci	}
56138c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
56148c2ecf20Sopenharmony_ci		    vars->phy_link_up, vars->line_speed);
56158c2ecf20Sopenharmony_ci	return 0;
56168c2ecf20Sopenharmony_ci}
56178c2ecf20Sopenharmony_ci
56188c2ecf20Sopenharmony_cistatic u8 bnx2x_link_settings_status(struct bnx2x_phy *phy,
56198c2ecf20Sopenharmony_ci				     struct link_params *params,
56208c2ecf20Sopenharmony_ci				     struct link_vars *vars)
56218c2ecf20Sopenharmony_ci{
56228c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
56238c2ecf20Sopenharmony_ci
56248c2ecf20Sopenharmony_ci	u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
56258c2ecf20Sopenharmony_ci	int rc = 0;
56268c2ecf20Sopenharmony_ci
56278c2ecf20Sopenharmony_ci	/* Read gp_status */
56288c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
56298c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_GP_STATUS,
56308c2ecf20Sopenharmony_ci			  MDIO_GP_STATUS_TOP_AN_STATUS1,
56318c2ecf20Sopenharmony_ci			  &gp_status);
56328c2ecf20Sopenharmony_ci	if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
56338c2ecf20Sopenharmony_ci		duplex = DUPLEX_FULL;
56348c2ecf20Sopenharmony_ci	if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
56358c2ecf20Sopenharmony_ci		link_up = 1;
56368c2ecf20Sopenharmony_ci	speed_mask = gp_status & GP_STATUS_SPEED_MASK;
56378c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
56388c2ecf20Sopenharmony_ci		       gp_status, link_up, speed_mask);
56398c2ecf20Sopenharmony_ci	rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
56408c2ecf20Sopenharmony_ci					 duplex);
56418c2ecf20Sopenharmony_ci	if (rc == -EINVAL)
56428c2ecf20Sopenharmony_ci		return rc;
56438c2ecf20Sopenharmony_ci
56448c2ecf20Sopenharmony_ci	if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
56458c2ecf20Sopenharmony_ci		if (SINGLE_MEDIA_DIRECT(params)) {
56468c2ecf20Sopenharmony_ci			vars->duplex = duplex;
56478c2ecf20Sopenharmony_ci			bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
56488c2ecf20Sopenharmony_ci			if (phy->req_line_speed == SPEED_AUTO_NEG)
56498c2ecf20Sopenharmony_ci				bnx2x_xgxs_an_resolve(phy, params, vars,
56508c2ecf20Sopenharmony_ci						      gp_status);
56518c2ecf20Sopenharmony_ci		}
56528c2ecf20Sopenharmony_ci	} else { /* Link_down */
56538c2ecf20Sopenharmony_ci		if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
56548c2ecf20Sopenharmony_ci		    SINGLE_MEDIA_DIRECT(params)) {
56558c2ecf20Sopenharmony_ci			/* Check signal is detected */
56568c2ecf20Sopenharmony_ci			bnx2x_check_fallback_to_cl37(phy, params);
56578c2ecf20Sopenharmony_ci		}
56588c2ecf20Sopenharmony_ci	}
56598c2ecf20Sopenharmony_ci
56608c2ecf20Sopenharmony_ci	/* Read LP advertised speeds*/
56618c2ecf20Sopenharmony_ci	if (SINGLE_MEDIA_DIRECT(params) &&
56628c2ecf20Sopenharmony_ci	    (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
56638c2ecf20Sopenharmony_ci		u16 val;
56648c2ecf20Sopenharmony_ci
56658c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_CL73_IEEEB1,
56668c2ecf20Sopenharmony_ci				  MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
56678c2ecf20Sopenharmony_ci
56688c2ecf20Sopenharmony_ci		if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
56698c2ecf20Sopenharmony_ci			vars->link_status |=
56708c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
56718c2ecf20Sopenharmony_ci		if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
56728c2ecf20Sopenharmony_ci			   MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
56738c2ecf20Sopenharmony_ci			vars->link_status |=
56748c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
56758c2ecf20Sopenharmony_ci
56768c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_OVER_1G,
56778c2ecf20Sopenharmony_ci				  MDIO_OVER_1G_LP_UP1, &val);
56788c2ecf20Sopenharmony_ci
56798c2ecf20Sopenharmony_ci		if (val & MDIO_OVER_1G_UP1_2_5G)
56808c2ecf20Sopenharmony_ci			vars->link_status |=
56818c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
56828c2ecf20Sopenharmony_ci		if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
56838c2ecf20Sopenharmony_ci			vars->link_status |=
56848c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
56858c2ecf20Sopenharmony_ci	}
56868c2ecf20Sopenharmony_ci
56878c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "duplex %x  flow_ctrl 0x%x link_status 0x%x\n",
56888c2ecf20Sopenharmony_ci		   vars->duplex, vars->flow_ctrl, vars->link_status);
56898c2ecf20Sopenharmony_ci	return rc;
56908c2ecf20Sopenharmony_ci}
56918c2ecf20Sopenharmony_ci
56928c2ecf20Sopenharmony_cistatic u8 bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
56938c2ecf20Sopenharmony_ci				     struct link_params *params,
56948c2ecf20Sopenharmony_ci				     struct link_vars *vars)
56958c2ecf20Sopenharmony_ci{
56968c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
56978c2ecf20Sopenharmony_ci	u8 lane;
56988c2ecf20Sopenharmony_ci	u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
56998c2ecf20Sopenharmony_ci	int rc = 0;
57008c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
57018c2ecf20Sopenharmony_ci	/* Read gp_status */
57028c2ecf20Sopenharmony_ci	if ((params->loopback_mode) &&
57038c2ecf20Sopenharmony_ci	    (phy->flags & FLAGS_WC_DUAL_MODE)) {
57048c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57058c2ecf20Sopenharmony_ci				MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
57068c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57078c2ecf20Sopenharmony_ci				MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
57088c2ecf20Sopenharmony_ci		link_up &= 0x1;
57098c2ecf20Sopenharmony_ci	} else if ((phy->req_line_speed > SPEED_10000) &&
57108c2ecf20Sopenharmony_ci		(phy->supported & SUPPORTED_20000baseMLD2_Full)) {
57118c2ecf20Sopenharmony_ci		u16 temp_link_up;
57128c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57138c2ecf20Sopenharmony_ci				1, &temp_link_up);
57148c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57158c2ecf20Sopenharmony_ci				1, &link_up);
57168c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
57178c2ecf20Sopenharmony_ci			       temp_link_up, link_up);
57188c2ecf20Sopenharmony_ci		link_up &= (1<<2);
57198c2ecf20Sopenharmony_ci		if (link_up)
57208c2ecf20Sopenharmony_ci			bnx2x_ext_phy_resolve_fc(phy, params, vars);
57218c2ecf20Sopenharmony_ci	} else {
57228c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57238c2ecf20Sopenharmony_ci				MDIO_WC_REG_GP2_STATUS_GP_2_1,
57248c2ecf20Sopenharmony_ci				&gp_status1);
57258c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
57268c2ecf20Sopenharmony_ci		/* Check for either KR, 1G, or AN up. */
57278c2ecf20Sopenharmony_ci		link_up = ((gp_status1 >> 8) |
57288c2ecf20Sopenharmony_ci			   (gp_status1 >> 12) |
57298c2ecf20Sopenharmony_ci			   (gp_status1)) &
57308c2ecf20Sopenharmony_ci			(1 << lane);
57318c2ecf20Sopenharmony_ci		if (phy->supported & SUPPORTED_20000baseKR2_Full) {
57328c2ecf20Sopenharmony_ci			u16 an_link;
57338c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
57348c2ecf20Sopenharmony_ci					MDIO_AN_REG_STATUS, &an_link);
57358c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
57368c2ecf20Sopenharmony_ci					MDIO_AN_REG_STATUS, &an_link);
57378c2ecf20Sopenharmony_ci			link_up |= (an_link & (1<<2));
57388c2ecf20Sopenharmony_ci		}
57398c2ecf20Sopenharmony_ci		if (link_up && SINGLE_MEDIA_DIRECT(params)) {
57408c2ecf20Sopenharmony_ci			u16 pd, gp_status4;
57418c2ecf20Sopenharmony_ci			if (phy->req_line_speed == SPEED_AUTO_NEG) {
57428c2ecf20Sopenharmony_ci				/* Check Autoneg complete */
57438c2ecf20Sopenharmony_ci				bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57448c2ecf20Sopenharmony_ci						MDIO_WC_REG_GP2_STATUS_GP_2_4,
57458c2ecf20Sopenharmony_ci						&gp_status4);
57468c2ecf20Sopenharmony_ci				if (gp_status4 & ((1<<12)<<lane))
57478c2ecf20Sopenharmony_ci					vars->link_status |=
57488c2ecf20Sopenharmony_ci					LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
57498c2ecf20Sopenharmony_ci
57508c2ecf20Sopenharmony_ci				/* Check parallel detect used */
57518c2ecf20Sopenharmony_ci				bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57528c2ecf20Sopenharmony_ci						MDIO_WC_REG_PAR_DET_10G_STATUS,
57538c2ecf20Sopenharmony_ci						&pd);
57548c2ecf20Sopenharmony_ci				if (pd & (1<<15))
57558c2ecf20Sopenharmony_ci					vars->link_status |=
57568c2ecf20Sopenharmony_ci					LINK_STATUS_PARALLEL_DETECTION_USED;
57578c2ecf20Sopenharmony_ci			}
57588c2ecf20Sopenharmony_ci			bnx2x_ext_phy_resolve_fc(phy, params, vars);
57598c2ecf20Sopenharmony_ci			vars->duplex = duplex;
57608c2ecf20Sopenharmony_ci		}
57618c2ecf20Sopenharmony_ci	}
57628c2ecf20Sopenharmony_ci
57638c2ecf20Sopenharmony_ci	if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
57648c2ecf20Sopenharmony_ci	    SINGLE_MEDIA_DIRECT(params)) {
57658c2ecf20Sopenharmony_ci		u16 val;
57668c2ecf20Sopenharmony_ci
57678c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
57688c2ecf20Sopenharmony_ci				MDIO_AN_REG_LP_AUTO_NEG2, &val);
57698c2ecf20Sopenharmony_ci
57708c2ecf20Sopenharmony_ci		if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
57718c2ecf20Sopenharmony_ci			vars->link_status |=
57728c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
57738c2ecf20Sopenharmony_ci		if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
57748c2ecf20Sopenharmony_ci			   MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
57758c2ecf20Sopenharmony_ci			vars->link_status |=
57768c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
57778c2ecf20Sopenharmony_ci
57788c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57798c2ecf20Sopenharmony_ci				MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
57808c2ecf20Sopenharmony_ci
57818c2ecf20Sopenharmony_ci		if (val & MDIO_OVER_1G_UP1_2_5G)
57828c2ecf20Sopenharmony_ci			vars->link_status |=
57838c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
57848c2ecf20Sopenharmony_ci		if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
57858c2ecf20Sopenharmony_ci			vars->link_status |=
57868c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
57878c2ecf20Sopenharmony_ci
57888c2ecf20Sopenharmony_ci	}
57898c2ecf20Sopenharmony_ci
57908c2ecf20Sopenharmony_ci
57918c2ecf20Sopenharmony_ci	if (lane < 2) {
57928c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57938c2ecf20Sopenharmony_ci				MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
57948c2ecf20Sopenharmony_ci	} else {
57958c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
57968c2ecf20Sopenharmony_ci				MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
57978c2ecf20Sopenharmony_ci	}
57988c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
57998c2ecf20Sopenharmony_ci
58008c2ecf20Sopenharmony_ci	if ((lane & 1) == 0)
58018c2ecf20Sopenharmony_ci		gp_speed <<= 8;
58028c2ecf20Sopenharmony_ci	gp_speed &= 0x3f00;
58038c2ecf20Sopenharmony_ci	link_up = !!link_up;
58048c2ecf20Sopenharmony_ci
58058c2ecf20Sopenharmony_ci	rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
58068c2ecf20Sopenharmony_ci					 duplex);
58078c2ecf20Sopenharmony_ci
58088c2ecf20Sopenharmony_ci	/* In case of KR link down, start up the recovering procedure */
58098c2ecf20Sopenharmony_ci	if ((!link_up) && (phy->media_type == ETH_PHY_KR) &&
58108c2ecf20Sopenharmony_ci	    (!(phy->flags & FLAGS_WC_DUAL_MODE)))
58118c2ecf20Sopenharmony_ci		vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
58128c2ecf20Sopenharmony_ci
58138c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "duplex %x  flow_ctrl 0x%x link_status 0x%x\n",
58148c2ecf20Sopenharmony_ci		   vars->duplex, vars->flow_ctrl, vars->link_status);
58158c2ecf20Sopenharmony_ci	return rc;
58168c2ecf20Sopenharmony_ci}
58178c2ecf20Sopenharmony_cistatic void bnx2x_set_gmii_tx_driver(struct link_params *params)
58188c2ecf20Sopenharmony_ci{
58198c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
58208c2ecf20Sopenharmony_ci	struct bnx2x_phy *phy = &params->phy[INT_PHY];
58218c2ecf20Sopenharmony_ci	u16 lp_up2;
58228c2ecf20Sopenharmony_ci	u16 tx_driver;
58238c2ecf20Sopenharmony_ci	u16 bank;
58248c2ecf20Sopenharmony_ci
58258c2ecf20Sopenharmony_ci	/* Read precomp */
58268c2ecf20Sopenharmony_ci	CL22_RD_OVER_CL45(bp, phy,
58278c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_OVER_1G,
58288c2ecf20Sopenharmony_ci			  MDIO_OVER_1G_LP_UP2, &lp_up2);
58298c2ecf20Sopenharmony_ci
58308c2ecf20Sopenharmony_ci	/* Bits [10:7] at lp_up2, positioned at [15:12] */
58318c2ecf20Sopenharmony_ci	lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
58328c2ecf20Sopenharmony_ci		   MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
58338c2ecf20Sopenharmony_ci		  MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
58348c2ecf20Sopenharmony_ci
58358c2ecf20Sopenharmony_ci	if (lp_up2 == 0)
58368c2ecf20Sopenharmony_ci		return;
58378c2ecf20Sopenharmony_ci
58388c2ecf20Sopenharmony_ci	for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
58398c2ecf20Sopenharmony_ci	      bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
58408c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, phy,
58418c2ecf20Sopenharmony_ci				  bank,
58428c2ecf20Sopenharmony_ci				  MDIO_TX0_TX_DRIVER, &tx_driver);
58438c2ecf20Sopenharmony_ci
58448c2ecf20Sopenharmony_ci		/* Replace tx_driver bits [15:12] */
58458c2ecf20Sopenharmony_ci		if (lp_up2 !=
58468c2ecf20Sopenharmony_ci		    (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
58478c2ecf20Sopenharmony_ci			tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
58488c2ecf20Sopenharmony_ci			tx_driver |= lp_up2;
58498c2ecf20Sopenharmony_ci			CL22_WR_OVER_CL45(bp, phy,
58508c2ecf20Sopenharmony_ci					  bank,
58518c2ecf20Sopenharmony_ci					  MDIO_TX0_TX_DRIVER, tx_driver);
58528c2ecf20Sopenharmony_ci		}
58538c2ecf20Sopenharmony_ci	}
58548c2ecf20Sopenharmony_ci}
58558c2ecf20Sopenharmony_ci
58568c2ecf20Sopenharmony_cistatic int bnx2x_emac_program(struct link_params *params,
58578c2ecf20Sopenharmony_ci			      struct link_vars *vars)
58588c2ecf20Sopenharmony_ci{
58598c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
58608c2ecf20Sopenharmony_ci	u8 port = params->port;
58618c2ecf20Sopenharmony_ci	u16 mode = 0;
58628c2ecf20Sopenharmony_ci
58638c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
58648c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
58658c2ecf20Sopenharmony_ci		       EMAC_REG_EMAC_MODE,
58668c2ecf20Sopenharmony_ci		       (EMAC_MODE_25G_MODE |
58678c2ecf20Sopenharmony_ci			EMAC_MODE_PORT_MII_10M |
58688c2ecf20Sopenharmony_ci			EMAC_MODE_HALF_DUPLEX));
58698c2ecf20Sopenharmony_ci	switch (vars->line_speed) {
58708c2ecf20Sopenharmony_ci	case SPEED_10:
58718c2ecf20Sopenharmony_ci		mode |= EMAC_MODE_PORT_MII_10M;
58728c2ecf20Sopenharmony_ci		break;
58738c2ecf20Sopenharmony_ci
58748c2ecf20Sopenharmony_ci	case SPEED_100:
58758c2ecf20Sopenharmony_ci		mode |= EMAC_MODE_PORT_MII;
58768c2ecf20Sopenharmony_ci		break;
58778c2ecf20Sopenharmony_ci
58788c2ecf20Sopenharmony_ci	case SPEED_1000:
58798c2ecf20Sopenharmony_ci		mode |= EMAC_MODE_PORT_GMII;
58808c2ecf20Sopenharmony_ci		break;
58818c2ecf20Sopenharmony_ci
58828c2ecf20Sopenharmony_ci	case SPEED_2500:
58838c2ecf20Sopenharmony_ci		mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
58848c2ecf20Sopenharmony_ci		break;
58858c2ecf20Sopenharmony_ci
58868c2ecf20Sopenharmony_ci	default:
58878c2ecf20Sopenharmony_ci		/* 10G not valid for EMAC */
58888c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
58898c2ecf20Sopenharmony_ci			   vars->line_speed);
58908c2ecf20Sopenharmony_ci		return -EINVAL;
58918c2ecf20Sopenharmony_ci	}
58928c2ecf20Sopenharmony_ci
58938c2ecf20Sopenharmony_ci	if (vars->duplex == DUPLEX_HALF)
58948c2ecf20Sopenharmony_ci		mode |= EMAC_MODE_HALF_DUPLEX;
58958c2ecf20Sopenharmony_ci	bnx2x_bits_en(bp,
58968c2ecf20Sopenharmony_ci		      GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
58978c2ecf20Sopenharmony_ci		      mode);
58988c2ecf20Sopenharmony_ci
58998c2ecf20Sopenharmony_ci	bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
59008c2ecf20Sopenharmony_ci	return 0;
59018c2ecf20Sopenharmony_ci}
59028c2ecf20Sopenharmony_ci
59038c2ecf20Sopenharmony_cistatic void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
59048c2ecf20Sopenharmony_ci				  struct link_params *params)
59058c2ecf20Sopenharmony_ci{
59068c2ecf20Sopenharmony_ci
59078c2ecf20Sopenharmony_ci	u16 bank, i = 0;
59088c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
59098c2ecf20Sopenharmony_ci
59108c2ecf20Sopenharmony_ci	for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
59118c2ecf20Sopenharmony_ci	      bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
59128c2ecf20Sopenharmony_ci			CL22_WR_OVER_CL45(bp, phy,
59138c2ecf20Sopenharmony_ci					  bank,
59148c2ecf20Sopenharmony_ci					  MDIO_RX0_RX_EQ_BOOST,
59158c2ecf20Sopenharmony_ci					  phy->rx_preemphasis[i]);
59168c2ecf20Sopenharmony_ci	}
59178c2ecf20Sopenharmony_ci
59188c2ecf20Sopenharmony_ci	for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
59198c2ecf20Sopenharmony_ci		      bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
59208c2ecf20Sopenharmony_ci			CL22_WR_OVER_CL45(bp, phy,
59218c2ecf20Sopenharmony_ci					  bank,
59228c2ecf20Sopenharmony_ci					  MDIO_TX0_TX_DRIVER,
59238c2ecf20Sopenharmony_ci					  phy->tx_preemphasis[i]);
59248c2ecf20Sopenharmony_ci	}
59258c2ecf20Sopenharmony_ci}
59268c2ecf20Sopenharmony_ci
59278c2ecf20Sopenharmony_cistatic void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
59288c2ecf20Sopenharmony_ci				   struct link_params *params,
59298c2ecf20Sopenharmony_ci				   struct link_vars *vars)
59308c2ecf20Sopenharmony_ci{
59318c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
59328c2ecf20Sopenharmony_ci	u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
59338c2ecf20Sopenharmony_ci			  (params->loopback_mode == LOOPBACK_XGXS));
59348c2ecf20Sopenharmony_ci	if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
59358c2ecf20Sopenharmony_ci		if (SINGLE_MEDIA_DIRECT(params) &&
59368c2ecf20Sopenharmony_ci		    (params->feature_config_flags &
59378c2ecf20Sopenharmony_ci		     FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
59388c2ecf20Sopenharmony_ci			bnx2x_set_preemphasis(phy, params);
59398c2ecf20Sopenharmony_ci
59408c2ecf20Sopenharmony_ci		/* Forced speed requested? */
59418c2ecf20Sopenharmony_ci		if (vars->line_speed != SPEED_AUTO_NEG ||
59428c2ecf20Sopenharmony_ci		    (SINGLE_MEDIA_DIRECT(params) &&
59438c2ecf20Sopenharmony_ci		     params->loopback_mode == LOOPBACK_EXT)) {
59448c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
59458c2ecf20Sopenharmony_ci
59468c2ecf20Sopenharmony_ci			/* Disable autoneg */
59478c2ecf20Sopenharmony_ci			bnx2x_set_autoneg(phy, params, vars, 0);
59488c2ecf20Sopenharmony_ci
59498c2ecf20Sopenharmony_ci			/* Program speed and duplex */
59508c2ecf20Sopenharmony_ci			bnx2x_program_serdes(phy, params, vars);
59518c2ecf20Sopenharmony_ci
59528c2ecf20Sopenharmony_ci		} else { /* AN_mode */
59538c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "not SGMII, AN\n");
59548c2ecf20Sopenharmony_ci
59558c2ecf20Sopenharmony_ci			/* AN enabled */
59568c2ecf20Sopenharmony_ci			bnx2x_set_brcm_cl37_advertisement(phy, params);
59578c2ecf20Sopenharmony_ci
59588c2ecf20Sopenharmony_ci			/* Program duplex & pause advertisement (for aneg) */
59598c2ecf20Sopenharmony_ci			bnx2x_set_ieee_aneg_advertisement(phy, params,
59608c2ecf20Sopenharmony_ci							  vars->ieee_fc);
59618c2ecf20Sopenharmony_ci
59628c2ecf20Sopenharmony_ci			/* Enable autoneg */
59638c2ecf20Sopenharmony_ci			bnx2x_set_autoneg(phy, params, vars, enable_cl73);
59648c2ecf20Sopenharmony_ci
59658c2ecf20Sopenharmony_ci			/* Enable and restart AN */
59668c2ecf20Sopenharmony_ci			bnx2x_restart_autoneg(phy, params, enable_cl73);
59678c2ecf20Sopenharmony_ci		}
59688c2ecf20Sopenharmony_ci
59698c2ecf20Sopenharmony_ci	} else { /* SGMII mode */
59708c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "SGMII\n");
59718c2ecf20Sopenharmony_ci
59728c2ecf20Sopenharmony_ci		bnx2x_initialize_sgmii_process(phy, params, vars);
59738c2ecf20Sopenharmony_ci	}
59748c2ecf20Sopenharmony_ci}
59758c2ecf20Sopenharmony_ci
59768c2ecf20Sopenharmony_cistatic int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
59778c2ecf20Sopenharmony_ci			  struct link_params *params,
59788c2ecf20Sopenharmony_ci			  struct link_vars *vars)
59798c2ecf20Sopenharmony_ci{
59808c2ecf20Sopenharmony_ci	int rc;
59818c2ecf20Sopenharmony_ci	vars->phy_flags |= PHY_XGXS_FLAG;
59828c2ecf20Sopenharmony_ci	if ((phy->req_line_speed &&
59838c2ecf20Sopenharmony_ci	     ((phy->req_line_speed == SPEED_100) ||
59848c2ecf20Sopenharmony_ci	      (phy->req_line_speed == SPEED_10))) ||
59858c2ecf20Sopenharmony_ci	    (!phy->req_line_speed &&
59868c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask >=
59878c2ecf20Sopenharmony_ci	      PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
59888c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask <
59898c2ecf20Sopenharmony_ci	      PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
59908c2ecf20Sopenharmony_ci	    (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
59918c2ecf20Sopenharmony_ci		vars->phy_flags |= PHY_SGMII_FLAG;
59928c2ecf20Sopenharmony_ci	else
59938c2ecf20Sopenharmony_ci		vars->phy_flags &= ~PHY_SGMII_FLAG;
59948c2ecf20Sopenharmony_ci
59958c2ecf20Sopenharmony_ci	bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
59968c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
59978c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
59988c2ecf20Sopenharmony_ci		bnx2x_set_master_ln(params, phy);
59998c2ecf20Sopenharmony_ci
60008c2ecf20Sopenharmony_ci	rc = bnx2x_reset_unicore(params, phy, 0);
60018c2ecf20Sopenharmony_ci	/* Reset the SerDes and wait for reset bit return low */
60028c2ecf20Sopenharmony_ci	if (rc)
60038c2ecf20Sopenharmony_ci		return rc;
60048c2ecf20Sopenharmony_ci
60058c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
60068c2ecf20Sopenharmony_ci	/* Setting the masterLn_def again after the reset */
60078c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
60088c2ecf20Sopenharmony_ci		bnx2x_set_master_ln(params, phy);
60098c2ecf20Sopenharmony_ci		bnx2x_set_swap_lanes(params, phy);
60108c2ecf20Sopenharmony_ci	}
60118c2ecf20Sopenharmony_ci
60128c2ecf20Sopenharmony_ci	return rc;
60138c2ecf20Sopenharmony_ci}
60148c2ecf20Sopenharmony_ci
60158c2ecf20Sopenharmony_cistatic u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
60168c2ecf20Sopenharmony_ci				     struct bnx2x_phy *phy,
60178c2ecf20Sopenharmony_ci				     struct link_params *params)
60188c2ecf20Sopenharmony_ci{
60198c2ecf20Sopenharmony_ci	u16 cnt, ctrl;
60208c2ecf20Sopenharmony_ci	/* Wait for soft reset to get cleared up to 1 sec */
60218c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 1000; cnt++) {
60228c2ecf20Sopenharmony_ci		if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
60238c2ecf20Sopenharmony_ci			bnx2x_cl22_read(bp, phy,
60248c2ecf20Sopenharmony_ci				MDIO_PMA_REG_CTRL, &ctrl);
60258c2ecf20Sopenharmony_ci		else
60268c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
60278c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
60288c2ecf20Sopenharmony_ci				MDIO_PMA_REG_CTRL, &ctrl);
60298c2ecf20Sopenharmony_ci		if (!(ctrl & (1<<15)))
60308c2ecf20Sopenharmony_ci			break;
60318c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
60328c2ecf20Sopenharmony_ci	}
60338c2ecf20Sopenharmony_ci
60348c2ecf20Sopenharmony_ci	if (cnt == 1000)
60358c2ecf20Sopenharmony_ci		netdev_err(bp->dev,  "Warning: PHY was not initialized,"
60368c2ecf20Sopenharmony_ci				      " Port %d\n",
60378c2ecf20Sopenharmony_ci			 params->port);
60388c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
60398c2ecf20Sopenharmony_ci	return cnt;
60408c2ecf20Sopenharmony_ci}
60418c2ecf20Sopenharmony_ci
60428c2ecf20Sopenharmony_cistatic void bnx2x_link_int_enable(struct link_params *params)
60438c2ecf20Sopenharmony_ci{
60448c2ecf20Sopenharmony_ci	u8 port = params->port;
60458c2ecf20Sopenharmony_ci	u32 mask;
60468c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
60478c2ecf20Sopenharmony_ci
60488c2ecf20Sopenharmony_ci	/* Setting the status to report on link up for either XGXS or SerDes */
60498c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
60508c2ecf20Sopenharmony_ci		mask = NIG_MASK_XGXS0_LINK_STATUS;
60518c2ecf20Sopenharmony_ci		if (!(SINGLE_MEDIA_DIRECT(params)))
60528c2ecf20Sopenharmony_ci			mask |= NIG_MASK_MI_INT;
60538c2ecf20Sopenharmony_ci	} else if (params->switch_cfg == SWITCH_CFG_10G) {
60548c2ecf20Sopenharmony_ci		mask = (NIG_MASK_XGXS0_LINK10G |
60558c2ecf20Sopenharmony_ci			NIG_MASK_XGXS0_LINK_STATUS);
60568c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
60578c2ecf20Sopenharmony_ci		if (!(SINGLE_MEDIA_DIRECT(params)) &&
60588c2ecf20Sopenharmony_ci			params->phy[INT_PHY].type !=
60598c2ecf20Sopenharmony_ci				PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
60608c2ecf20Sopenharmony_ci			mask |= NIG_MASK_MI_INT;
60618c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "enabled external phy int\n");
60628c2ecf20Sopenharmony_ci		}
60638c2ecf20Sopenharmony_ci
60648c2ecf20Sopenharmony_ci	} else { /* SerDes */
60658c2ecf20Sopenharmony_ci		mask = NIG_MASK_SERDES0_LINK_STATUS;
60668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
60678c2ecf20Sopenharmony_ci		if (!(SINGLE_MEDIA_DIRECT(params)) &&
60688c2ecf20Sopenharmony_ci			params->phy[INT_PHY].type !=
60698c2ecf20Sopenharmony_ci				PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
60708c2ecf20Sopenharmony_ci			mask |= NIG_MASK_MI_INT;
60718c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "enabled external phy int\n");
60728c2ecf20Sopenharmony_ci		}
60738c2ecf20Sopenharmony_ci	}
60748c2ecf20Sopenharmony_ci	bnx2x_bits_en(bp,
60758c2ecf20Sopenharmony_ci		      NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
60768c2ecf20Sopenharmony_ci		      mask);
60778c2ecf20Sopenharmony_ci
60788c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
60798c2ecf20Sopenharmony_ci		 (params->switch_cfg == SWITCH_CFG_10G),
60808c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
60818c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
60828c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
60838c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
60848c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
60858c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
60868c2ecf20Sopenharmony_ci	   REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
60878c2ecf20Sopenharmony_ci	   REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
60888c2ecf20Sopenharmony_ci}
60898c2ecf20Sopenharmony_ci
60908c2ecf20Sopenharmony_cistatic void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
60918c2ecf20Sopenharmony_ci				     u8 exp_mi_int)
60928c2ecf20Sopenharmony_ci{
60938c2ecf20Sopenharmony_ci	u32 latch_status = 0;
60948c2ecf20Sopenharmony_ci
60958c2ecf20Sopenharmony_ci	/* Disable the MI INT ( external phy int ) by writing 1 to the
60968c2ecf20Sopenharmony_ci	 * status register. Link down indication is high-active-signal,
60978c2ecf20Sopenharmony_ci	 * so in this case we need to write the status to clear the XOR
60988c2ecf20Sopenharmony_ci	 */
60998c2ecf20Sopenharmony_ci	/* Read Latched signals */
61008c2ecf20Sopenharmony_ci	latch_status = REG_RD(bp,
61018c2ecf20Sopenharmony_ci				    NIG_REG_LATCH_STATUS_0 + port*8);
61028c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
61038c2ecf20Sopenharmony_ci	/* Handle only those with latched-signal=up.*/
61048c2ecf20Sopenharmony_ci	if (exp_mi_int)
61058c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp,
61068c2ecf20Sopenharmony_ci			      NIG_REG_STATUS_INTERRUPT_PORT0
61078c2ecf20Sopenharmony_ci			      + port*4,
61088c2ecf20Sopenharmony_ci			      NIG_STATUS_EMAC0_MI_INT);
61098c2ecf20Sopenharmony_ci	else
61108c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp,
61118c2ecf20Sopenharmony_ci			       NIG_REG_STATUS_INTERRUPT_PORT0
61128c2ecf20Sopenharmony_ci			       + port*4,
61138c2ecf20Sopenharmony_ci			       NIG_STATUS_EMAC0_MI_INT);
61148c2ecf20Sopenharmony_ci
61158c2ecf20Sopenharmony_ci	if (latch_status & 1) {
61168c2ecf20Sopenharmony_ci
61178c2ecf20Sopenharmony_ci		/* For all latched-signal=up : Re-Arm Latch signals */
61188c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
61198c2ecf20Sopenharmony_ci		       (latch_status & 0xfffe) | (latch_status & 1));
61208c2ecf20Sopenharmony_ci	}
61218c2ecf20Sopenharmony_ci	/* For all latched-signal=up,Write original_signal to status */
61228c2ecf20Sopenharmony_ci}
61238c2ecf20Sopenharmony_ci
61248c2ecf20Sopenharmony_cistatic void bnx2x_link_int_ack(struct link_params *params,
61258c2ecf20Sopenharmony_ci			       struct link_vars *vars, u8 is_10g_plus)
61268c2ecf20Sopenharmony_ci{
61278c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
61288c2ecf20Sopenharmony_ci	u8 port = params->port;
61298c2ecf20Sopenharmony_ci	u32 mask;
61308c2ecf20Sopenharmony_ci	/* First reset all status we assume only one line will be
61318c2ecf20Sopenharmony_ci	 * change at a time
61328c2ecf20Sopenharmony_ci	 */
61338c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
61348c2ecf20Sopenharmony_ci		       (NIG_STATUS_XGXS0_LINK10G |
61358c2ecf20Sopenharmony_ci			NIG_STATUS_XGXS0_LINK_STATUS |
61368c2ecf20Sopenharmony_ci			NIG_STATUS_SERDES0_LINK_STATUS));
61378c2ecf20Sopenharmony_ci	if (vars->phy_link_up) {
61388c2ecf20Sopenharmony_ci		if (USES_WARPCORE(bp))
61398c2ecf20Sopenharmony_ci			mask = NIG_STATUS_XGXS0_LINK_STATUS;
61408c2ecf20Sopenharmony_ci		else {
61418c2ecf20Sopenharmony_ci			if (is_10g_plus)
61428c2ecf20Sopenharmony_ci				mask = NIG_STATUS_XGXS0_LINK10G;
61438c2ecf20Sopenharmony_ci			else if (params->switch_cfg == SWITCH_CFG_10G) {
61448c2ecf20Sopenharmony_ci				/* Disable the link interrupt by writing 1 to
61458c2ecf20Sopenharmony_ci				 * the relevant lane in the status register
61468c2ecf20Sopenharmony_ci				 */
61478c2ecf20Sopenharmony_ci				u32 ser_lane =
61488c2ecf20Sopenharmony_ci					((params->lane_config &
61498c2ecf20Sopenharmony_ci				    PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
61508c2ecf20Sopenharmony_ci				    PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
61518c2ecf20Sopenharmony_ci				mask = ((1 << ser_lane) <<
61528c2ecf20Sopenharmony_ci				       NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
61538c2ecf20Sopenharmony_ci			} else
61548c2ecf20Sopenharmony_ci				mask = NIG_STATUS_SERDES0_LINK_STATUS;
61558c2ecf20Sopenharmony_ci		}
61568c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
61578c2ecf20Sopenharmony_ci			       mask);
61588c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp,
61598c2ecf20Sopenharmony_ci			      NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
61608c2ecf20Sopenharmony_ci			      mask);
61618c2ecf20Sopenharmony_ci	}
61628c2ecf20Sopenharmony_ci}
61638c2ecf20Sopenharmony_ci
61648c2ecf20Sopenharmony_cistatic int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
61658c2ecf20Sopenharmony_ci{
61668c2ecf20Sopenharmony_ci	str[0] = '\0';
61678c2ecf20Sopenharmony_ci	(*len)--;
61688c2ecf20Sopenharmony_ci	return 0;
61698c2ecf20Sopenharmony_ci}
61708c2ecf20Sopenharmony_ci
61718c2ecf20Sopenharmony_cistatic int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
61728c2ecf20Sopenharmony_ci{
61738c2ecf20Sopenharmony_ci	u16 ret;
61748c2ecf20Sopenharmony_ci
61758c2ecf20Sopenharmony_ci	if (*len < 10) {
61768c2ecf20Sopenharmony_ci		/* Need more than 10chars for this format */
61778c2ecf20Sopenharmony_ci		bnx2x_null_format_ver(num, str, len);
61788c2ecf20Sopenharmony_ci		return -EINVAL;
61798c2ecf20Sopenharmony_ci	}
61808c2ecf20Sopenharmony_ci
61818c2ecf20Sopenharmony_ci	ret = scnprintf(str, *len, "%hx.%hx", num >> 16, num);
61828c2ecf20Sopenharmony_ci	*len -= ret;
61838c2ecf20Sopenharmony_ci	return 0;
61848c2ecf20Sopenharmony_ci}
61858c2ecf20Sopenharmony_ci
61868c2ecf20Sopenharmony_cistatic int bnx2x_3_seq_format_ver(u32 num, u8 *str, u16 *len)
61878c2ecf20Sopenharmony_ci{
61888c2ecf20Sopenharmony_ci	u16 ret;
61898c2ecf20Sopenharmony_ci
61908c2ecf20Sopenharmony_ci	if (*len < 10) {
61918c2ecf20Sopenharmony_ci		/* Need more than 10chars for this format */
61928c2ecf20Sopenharmony_ci		bnx2x_null_format_ver(num, str, len);
61938c2ecf20Sopenharmony_ci		return -EINVAL;
61948c2ecf20Sopenharmony_ci	}
61958c2ecf20Sopenharmony_ci
61968c2ecf20Sopenharmony_ci	ret = scnprintf(str, *len, "%hhx.%hhx.%hhx", num >> 16, num >> 8, num);
61978c2ecf20Sopenharmony_ci	*len -= ret;
61988c2ecf20Sopenharmony_ci	return 0;
61998c2ecf20Sopenharmony_ci}
62008c2ecf20Sopenharmony_ci
62018c2ecf20Sopenharmony_ciint bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
62028c2ecf20Sopenharmony_ci				 u16 len)
62038c2ecf20Sopenharmony_ci{
62048c2ecf20Sopenharmony_ci	struct bnx2x *bp;
62058c2ecf20Sopenharmony_ci	u32 spirom_ver = 0;
62068c2ecf20Sopenharmony_ci	int status = 0;
62078c2ecf20Sopenharmony_ci	u8 *ver_p = version;
62088c2ecf20Sopenharmony_ci	u16 remain_len = len;
62098c2ecf20Sopenharmony_ci	if (version == NULL || params == NULL)
62108c2ecf20Sopenharmony_ci		return -EINVAL;
62118c2ecf20Sopenharmony_ci	bp = params->bp;
62128c2ecf20Sopenharmony_ci
62138c2ecf20Sopenharmony_ci	/* Extract first external phy*/
62148c2ecf20Sopenharmony_ci	version[0] = '\0';
62158c2ecf20Sopenharmony_ci	spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
62168c2ecf20Sopenharmony_ci
62178c2ecf20Sopenharmony_ci	if (params->phy[EXT_PHY1].format_fw_ver) {
62188c2ecf20Sopenharmony_ci		status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
62198c2ecf20Sopenharmony_ci							      ver_p,
62208c2ecf20Sopenharmony_ci							      &remain_len);
62218c2ecf20Sopenharmony_ci		ver_p += (len - remain_len);
62228c2ecf20Sopenharmony_ci	}
62238c2ecf20Sopenharmony_ci	if ((params->num_phys == MAX_PHYS) &&
62248c2ecf20Sopenharmony_ci	    (params->phy[EXT_PHY2].ver_addr != 0)) {
62258c2ecf20Sopenharmony_ci		spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
62268c2ecf20Sopenharmony_ci		if (params->phy[EXT_PHY2].format_fw_ver) {
62278c2ecf20Sopenharmony_ci			*ver_p = '/';
62288c2ecf20Sopenharmony_ci			ver_p++;
62298c2ecf20Sopenharmony_ci			remain_len--;
62308c2ecf20Sopenharmony_ci			status |= params->phy[EXT_PHY2].format_fw_ver(
62318c2ecf20Sopenharmony_ci				spirom_ver,
62328c2ecf20Sopenharmony_ci				ver_p,
62338c2ecf20Sopenharmony_ci				&remain_len);
62348c2ecf20Sopenharmony_ci			ver_p = version + (len - remain_len);
62358c2ecf20Sopenharmony_ci		}
62368c2ecf20Sopenharmony_ci	}
62378c2ecf20Sopenharmony_ci	*ver_p = '\0';
62388c2ecf20Sopenharmony_ci	return status;
62398c2ecf20Sopenharmony_ci}
62408c2ecf20Sopenharmony_ci
62418c2ecf20Sopenharmony_cistatic void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
62428c2ecf20Sopenharmony_ci				    struct link_params *params)
62438c2ecf20Sopenharmony_ci{
62448c2ecf20Sopenharmony_ci	u8 port = params->port;
62458c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
62468c2ecf20Sopenharmony_ci
62478c2ecf20Sopenharmony_ci	if (phy->req_line_speed != SPEED_1000) {
62488c2ecf20Sopenharmony_ci		u32 md_devad = 0;
62498c2ecf20Sopenharmony_ci
62508c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
62518c2ecf20Sopenharmony_ci
62528c2ecf20Sopenharmony_ci		if (!CHIP_IS_E3(bp)) {
62538c2ecf20Sopenharmony_ci			/* Change the uni_phy_addr in the nig */
62548c2ecf20Sopenharmony_ci			md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
62558c2ecf20Sopenharmony_ci					       port*0x18));
62568c2ecf20Sopenharmony_ci
62578c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
62588c2ecf20Sopenharmony_ci			       0x5);
62598c2ecf20Sopenharmony_ci		}
62608c2ecf20Sopenharmony_ci
62618c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
62628c2ecf20Sopenharmony_ci				 5,
62638c2ecf20Sopenharmony_ci				 (MDIO_REG_BANK_AER_BLOCK +
62648c2ecf20Sopenharmony_ci				  (MDIO_AER_BLOCK_AER_REG & 0xf)),
62658c2ecf20Sopenharmony_ci				 0x2800);
62668c2ecf20Sopenharmony_ci
62678c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
62688c2ecf20Sopenharmony_ci				 5,
62698c2ecf20Sopenharmony_ci				 (MDIO_REG_BANK_CL73_IEEEB0 +
62708c2ecf20Sopenharmony_ci				  (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
62718c2ecf20Sopenharmony_ci				 0x6041);
62728c2ecf20Sopenharmony_ci		msleep(200);
62738c2ecf20Sopenharmony_ci		/* Set aer mmd back */
62748c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
62758c2ecf20Sopenharmony_ci
62768c2ecf20Sopenharmony_ci		if (!CHIP_IS_E3(bp)) {
62778c2ecf20Sopenharmony_ci			/* And md_devad */
62788c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
62798c2ecf20Sopenharmony_ci			       md_devad);
62808c2ecf20Sopenharmony_ci		}
62818c2ecf20Sopenharmony_ci	} else {
62828c2ecf20Sopenharmony_ci		u16 mii_ctrl;
62838c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
62848c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, 5,
62858c2ecf20Sopenharmony_ci				(MDIO_REG_BANK_COMBO_IEEE0 +
62868c2ecf20Sopenharmony_ci				(MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
62878c2ecf20Sopenharmony_ci				&mii_ctrl);
62888c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, 5,
62898c2ecf20Sopenharmony_ci				 (MDIO_REG_BANK_COMBO_IEEE0 +
62908c2ecf20Sopenharmony_ci				 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
62918c2ecf20Sopenharmony_ci				 mii_ctrl |
62928c2ecf20Sopenharmony_ci				 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
62938c2ecf20Sopenharmony_ci	}
62948c2ecf20Sopenharmony_ci}
62958c2ecf20Sopenharmony_ci
62968c2ecf20Sopenharmony_ciint bnx2x_set_led(struct link_params *params,
62978c2ecf20Sopenharmony_ci		  struct link_vars *vars, u8 mode, u32 speed)
62988c2ecf20Sopenharmony_ci{
62998c2ecf20Sopenharmony_ci	u8 port = params->port;
63008c2ecf20Sopenharmony_ci	u16 hw_led_mode = params->hw_led_mode;
63018c2ecf20Sopenharmony_ci	int rc = 0;
63028c2ecf20Sopenharmony_ci	u8 phy_idx;
63038c2ecf20Sopenharmony_ci	u32 tmp;
63048c2ecf20Sopenharmony_ci	u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
63058c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
63068c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
63078c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
63088c2ecf20Sopenharmony_ci		 speed, hw_led_mode);
63098c2ecf20Sopenharmony_ci	/* In case */
63108c2ecf20Sopenharmony_ci	for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
63118c2ecf20Sopenharmony_ci		if (params->phy[phy_idx].set_link_led) {
63128c2ecf20Sopenharmony_ci			params->phy[phy_idx].set_link_led(
63138c2ecf20Sopenharmony_ci				&params->phy[phy_idx], params, mode);
63148c2ecf20Sopenharmony_ci		}
63158c2ecf20Sopenharmony_ci	}
63168c2ecf20Sopenharmony_ci
63178c2ecf20Sopenharmony_ci	switch (mode) {
63188c2ecf20Sopenharmony_ci	case LED_MODE_FRONT_PANEL_OFF:
63198c2ecf20Sopenharmony_ci	case LED_MODE_OFF:
63208c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
63218c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
63228c2ecf20Sopenharmony_ci		       SHARED_HW_CFG_LED_MAC1);
63238c2ecf20Sopenharmony_ci
63248c2ecf20Sopenharmony_ci		tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
63258c2ecf20Sopenharmony_ci		if (params->phy[EXT_PHY1].type ==
63268c2ecf20Sopenharmony_ci			PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
63278c2ecf20Sopenharmony_ci			tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
63288c2ecf20Sopenharmony_ci				EMAC_LED_100MB_OVERRIDE |
63298c2ecf20Sopenharmony_ci				EMAC_LED_10MB_OVERRIDE);
63308c2ecf20Sopenharmony_ci		else
63318c2ecf20Sopenharmony_ci			tmp |= EMAC_LED_OVERRIDE;
63328c2ecf20Sopenharmony_ci
63338c2ecf20Sopenharmony_ci		EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
63348c2ecf20Sopenharmony_ci		break;
63358c2ecf20Sopenharmony_ci
63368c2ecf20Sopenharmony_ci	case LED_MODE_OPER:
63378c2ecf20Sopenharmony_ci		/* For all other phys, OPER mode is same as ON, so in case
63388c2ecf20Sopenharmony_ci		 * link is down, do nothing
63398c2ecf20Sopenharmony_ci		 */
63408c2ecf20Sopenharmony_ci		if (!vars->link_up)
63418c2ecf20Sopenharmony_ci			break;
63428c2ecf20Sopenharmony_ci		fallthrough;
63438c2ecf20Sopenharmony_ci	case LED_MODE_ON:
63448c2ecf20Sopenharmony_ci		if (((params->phy[EXT_PHY1].type ==
63458c2ecf20Sopenharmony_ci			  PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
63468c2ecf20Sopenharmony_ci			 (params->phy[EXT_PHY1].type ==
63478c2ecf20Sopenharmony_ci			  PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
63488c2ecf20Sopenharmony_ci		    CHIP_IS_E2(bp) && params->num_phys == 2) {
63498c2ecf20Sopenharmony_ci			/* This is a work-around for E2+8727 Configurations */
63508c2ecf20Sopenharmony_ci			if (mode == LED_MODE_ON ||
63518c2ecf20Sopenharmony_ci				speed == SPEED_10000){
63528c2ecf20Sopenharmony_ci				REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
63538c2ecf20Sopenharmony_ci				REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
63548c2ecf20Sopenharmony_ci
63558c2ecf20Sopenharmony_ci				tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
63568c2ecf20Sopenharmony_ci				EMAC_WR(bp, EMAC_REG_EMAC_LED,
63578c2ecf20Sopenharmony_ci					(tmp | EMAC_LED_OVERRIDE));
63588c2ecf20Sopenharmony_ci				/* Return here without enabling traffic
63598c2ecf20Sopenharmony_ci				 * LED blink and setting rate in ON mode.
63608c2ecf20Sopenharmony_ci				 * In oper mode, enabling LED blink
63618c2ecf20Sopenharmony_ci				 * and setting rate is needed.
63628c2ecf20Sopenharmony_ci				 */
63638c2ecf20Sopenharmony_ci				if (mode == LED_MODE_ON)
63648c2ecf20Sopenharmony_ci					return rc;
63658c2ecf20Sopenharmony_ci			}
63668c2ecf20Sopenharmony_ci		} else if (SINGLE_MEDIA_DIRECT(params)) {
63678c2ecf20Sopenharmony_ci			/* This is a work-around for HW issue found when link
63688c2ecf20Sopenharmony_ci			 * is up in CL73
63698c2ecf20Sopenharmony_ci			 */
63708c2ecf20Sopenharmony_ci			if ((!CHIP_IS_E3(bp)) ||
63718c2ecf20Sopenharmony_ci			    (CHIP_IS_E3(bp) &&
63728c2ecf20Sopenharmony_ci			     mode == LED_MODE_ON))
63738c2ecf20Sopenharmony_ci				REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
63748c2ecf20Sopenharmony_ci
63758c2ecf20Sopenharmony_ci			if (CHIP_IS_E1x(bp) ||
63768c2ecf20Sopenharmony_ci			    CHIP_IS_E2(bp) ||
63778c2ecf20Sopenharmony_ci			    (mode == LED_MODE_ON))
63788c2ecf20Sopenharmony_ci				REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
63798c2ecf20Sopenharmony_ci			else
63808c2ecf20Sopenharmony_ci				REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
63818c2ecf20Sopenharmony_ci				       hw_led_mode);
63828c2ecf20Sopenharmony_ci		} else if ((params->phy[EXT_PHY1].type ==
63838c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
63848c2ecf20Sopenharmony_ci			   (mode == LED_MODE_ON)) {
63858c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
63868c2ecf20Sopenharmony_ci			tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
63878c2ecf20Sopenharmony_ci			EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
63888c2ecf20Sopenharmony_ci				EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
63898c2ecf20Sopenharmony_ci			/* Break here; otherwise, it'll disable the
63908c2ecf20Sopenharmony_ci			 * intended override.
63918c2ecf20Sopenharmony_ci			 */
63928c2ecf20Sopenharmony_ci			break;
63938c2ecf20Sopenharmony_ci		} else {
63948c2ecf20Sopenharmony_ci			u32 nig_led_mode = ((params->hw_led_mode <<
63958c2ecf20Sopenharmony_ci					     SHARED_HW_CFG_LED_MODE_SHIFT) ==
63968c2ecf20Sopenharmony_ci					    SHARED_HW_CFG_LED_EXTPHY2) ?
63978c2ecf20Sopenharmony_ci				(SHARED_HW_CFG_LED_PHY1 >>
63988c2ecf20Sopenharmony_ci				 SHARED_HW_CFG_LED_MODE_SHIFT) : hw_led_mode;
63998c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
64008c2ecf20Sopenharmony_ci			       nig_led_mode);
64018c2ecf20Sopenharmony_ci		}
64028c2ecf20Sopenharmony_ci
64038c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
64048c2ecf20Sopenharmony_ci		/* Set blinking rate to ~15.9Hz */
64058c2ecf20Sopenharmony_ci		if (CHIP_IS_E3(bp))
64068c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
64078c2ecf20Sopenharmony_ci			       LED_BLINK_RATE_VAL_E3);
64088c2ecf20Sopenharmony_ci		else
64098c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
64108c2ecf20Sopenharmony_ci			       LED_BLINK_RATE_VAL_E1X_E2);
64118c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
64128c2ecf20Sopenharmony_ci		       port*4, 1);
64138c2ecf20Sopenharmony_ci		tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
64148c2ecf20Sopenharmony_ci		EMAC_WR(bp, EMAC_REG_EMAC_LED,
64158c2ecf20Sopenharmony_ci			(tmp & (~EMAC_LED_OVERRIDE)));
64168c2ecf20Sopenharmony_ci
64178c2ecf20Sopenharmony_ci		if (CHIP_IS_E1(bp) &&
64188c2ecf20Sopenharmony_ci		    ((speed == SPEED_2500) ||
64198c2ecf20Sopenharmony_ci		     (speed == SPEED_1000) ||
64208c2ecf20Sopenharmony_ci		     (speed == SPEED_100) ||
64218c2ecf20Sopenharmony_ci		     (speed == SPEED_10))) {
64228c2ecf20Sopenharmony_ci			/* For speeds less than 10G LED scheme is different */
64238c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
64248c2ecf20Sopenharmony_ci			       + port*4, 1);
64258c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
64268c2ecf20Sopenharmony_ci			       port*4, 0);
64278c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
64288c2ecf20Sopenharmony_ci			       port*4, 1);
64298c2ecf20Sopenharmony_ci		}
64308c2ecf20Sopenharmony_ci		break;
64318c2ecf20Sopenharmony_ci
64328c2ecf20Sopenharmony_ci	default:
64338c2ecf20Sopenharmony_ci		rc = -EINVAL;
64348c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
64358c2ecf20Sopenharmony_ci			 mode);
64368c2ecf20Sopenharmony_ci		break;
64378c2ecf20Sopenharmony_ci	}
64388c2ecf20Sopenharmony_ci	return rc;
64398c2ecf20Sopenharmony_ci
64408c2ecf20Sopenharmony_ci}
64418c2ecf20Sopenharmony_ci
64428c2ecf20Sopenharmony_ci/* This function comes to reflect the actual link state read DIRECTLY from the
64438c2ecf20Sopenharmony_ci * HW
64448c2ecf20Sopenharmony_ci */
64458c2ecf20Sopenharmony_ciint bnx2x_test_link(struct link_params *params, struct link_vars *vars,
64468c2ecf20Sopenharmony_ci		    u8 is_serdes)
64478c2ecf20Sopenharmony_ci{
64488c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
64498c2ecf20Sopenharmony_ci	u16 gp_status = 0, phy_index = 0;
64508c2ecf20Sopenharmony_ci	u8 ext_phy_link_up = 0, serdes_phy_type;
64518c2ecf20Sopenharmony_ci	struct link_vars temp_vars;
64528c2ecf20Sopenharmony_ci	struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
64538c2ecf20Sopenharmony_ci
64548c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
64558c2ecf20Sopenharmony_ci		u16 link_up;
64568c2ecf20Sopenharmony_ci		if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
64578c2ecf20Sopenharmony_ci		    > SPEED_10000) {
64588c2ecf20Sopenharmony_ci			/* Check 20G link */
64598c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
64608c2ecf20Sopenharmony_ci					1, &link_up);
64618c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
64628c2ecf20Sopenharmony_ci					1, &link_up);
64638c2ecf20Sopenharmony_ci			link_up &= (1<<2);
64648c2ecf20Sopenharmony_ci		} else {
64658c2ecf20Sopenharmony_ci			/* Check 10G link and below*/
64668c2ecf20Sopenharmony_ci			u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
64678c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
64688c2ecf20Sopenharmony_ci					MDIO_WC_REG_GP2_STATUS_GP_2_1,
64698c2ecf20Sopenharmony_ci					&gp_status);
64708c2ecf20Sopenharmony_ci			gp_status = ((gp_status >> 8) & 0xf) |
64718c2ecf20Sopenharmony_ci				((gp_status >> 12) & 0xf);
64728c2ecf20Sopenharmony_ci			link_up = gp_status & (1 << lane);
64738c2ecf20Sopenharmony_ci		}
64748c2ecf20Sopenharmony_ci		if (!link_up)
64758c2ecf20Sopenharmony_ci			return -ESRCH;
64768c2ecf20Sopenharmony_ci	} else {
64778c2ecf20Sopenharmony_ci		CL22_RD_OVER_CL45(bp, int_phy,
64788c2ecf20Sopenharmony_ci			  MDIO_REG_BANK_GP_STATUS,
64798c2ecf20Sopenharmony_ci			  MDIO_GP_STATUS_TOP_AN_STATUS1,
64808c2ecf20Sopenharmony_ci			  &gp_status);
64818c2ecf20Sopenharmony_ci		/* Link is up only if both local phy and external phy are up */
64828c2ecf20Sopenharmony_ci		if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
64838c2ecf20Sopenharmony_ci			return -ESRCH;
64848c2ecf20Sopenharmony_ci	}
64858c2ecf20Sopenharmony_ci	/* In XGXS loopback mode, do not check external PHY */
64868c2ecf20Sopenharmony_ci	if (params->loopback_mode == LOOPBACK_XGXS)
64878c2ecf20Sopenharmony_ci		return 0;
64888c2ecf20Sopenharmony_ci
64898c2ecf20Sopenharmony_ci	switch (params->num_phys) {
64908c2ecf20Sopenharmony_ci	case 1:
64918c2ecf20Sopenharmony_ci		/* No external PHY */
64928c2ecf20Sopenharmony_ci		return 0;
64938c2ecf20Sopenharmony_ci	case 2:
64948c2ecf20Sopenharmony_ci		ext_phy_link_up = params->phy[EXT_PHY1].read_status(
64958c2ecf20Sopenharmony_ci			&params->phy[EXT_PHY1],
64968c2ecf20Sopenharmony_ci			params, &temp_vars);
64978c2ecf20Sopenharmony_ci		break;
64988c2ecf20Sopenharmony_ci	case 3: /* Dual Media */
64998c2ecf20Sopenharmony_ci		for (phy_index = EXT_PHY1; phy_index < params->num_phys;
65008c2ecf20Sopenharmony_ci		      phy_index++) {
65018c2ecf20Sopenharmony_ci			serdes_phy_type = ((params->phy[phy_index].media_type ==
65028c2ecf20Sopenharmony_ci					    ETH_PHY_SFPP_10G_FIBER) ||
65038c2ecf20Sopenharmony_ci					   (params->phy[phy_index].media_type ==
65048c2ecf20Sopenharmony_ci					    ETH_PHY_SFP_1G_FIBER) ||
65058c2ecf20Sopenharmony_ci					   (params->phy[phy_index].media_type ==
65068c2ecf20Sopenharmony_ci					    ETH_PHY_XFP_FIBER) ||
65078c2ecf20Sopenharmony_ci					   (params->phy[phy_index].media_type ==
65088c2ecf20Sopenharmony_ci					    ETH_PHY_DA_TWINAX));
65098c2ecf20Sopenharmony_ci
65108c2ecf20Sopenharmony_ci			if (is_serdes != serdes_phy_type)
65118c2ecf20Sopenharmony_ci				continue;
65128c2ecf20Sopenharmony_ci			if (params->phy[phy_index].read_status) {
65138c2ecf20Sopenharmony_ci				ext_phy_link_up |=
65148c2ecf20Sopenharmony_ci					params->phy[phy_index].read_status(
65158c2ecf20Sopenharmony_ci						&params->phy[phy_index],
65168c2ecf20Sopenharmony_ci						params, &temp_vars);
65178c2ecf20Sopenharmony_ci			}
65188c2ecf20Sopenharmony_ci		}
65198c2ecf20Sopenharmony_ci		break;
65208c2ecf20Sopenharmony_ci	}
65218c2ecf20Sopenharmony_ci	if (ext_phy_link_up)
65228c2ecf20Sopenharmony_ci		return 0;
65238c2ecf20Sopenharmony_ci	return -ESRCH;
65248c2ecf20Sopenharmony_ci}
65258c2ecf20Sopenharmony_ci
65268c2ecf20Sopenharmony_cistatic int bnx2x_link_initialize(struct link_params *params,
65278c2ecf20Sopenharmony_ci				 struct link_vars *vars)
65288c2ecf20Sopenharmony_ci{
65298c2ecf20Sopenharmony_ci	u8 phy_index, non_ext_phy;
65308c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
65318c2ecf20Sopenharmony_ci	/* In case of external phy existence, the line speed would be the
65328c2ecf20Sopenharmony_ci	 * line speed linked up by the external phy. In case it is direct
65338c2ecf20Sopenharmony_ci	 * only, then the line_speed during initialization will be
65348c2ecf20Sopenharmony_ci	 * equal to the req_line_speed
65358c2ecf20Sopenharmony_ci	 */
65368c2ecf20Sopenharmony_ci	vars->line_speed = params->phy[INT_PHY].req_line_speed;
65378c2ecf20Sopenharmony_ci
65388c2ecf20Sopenharmony_ci	/* Initialize the internal phy in case this is a direct board
65398c2ecf20Sopenharmony_ci	 * (no external phys), or this board has external phy which requires
65408c2ecf20Sopenharmony_ci	 * to first.
65418c2ecf20Sopenharmony_ci	 */
65428c2ecf20Sopenharmony_ci	if (!USES_WARPCORE(bp))
65438c2ecf20Sopenharmony_ci		bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
65448c2ecf20Sopenharmony_ci	/* init ext phy and enable link state int */
65458c2ecf20Sopenharmony_ci	non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
65468c2ecf20Sopenharmony_ci		       (params->loopback_mode == LOOPBACK_XGXS));
65478c2ecf20Sopenharmony_ci
65488c2ecf20Sopenharmony_ci	if (non_ext_phy ||
65498c2ecf20Sopenharmony_ci	    (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
65508c2ecf20Sopenharmony_ci	    (params->loopback_mode == LOOPBACK_EXT_PHY)) {
65518c2ecf20Sopenharmony_ci		struct bnx2x_phy *phy = &params->phy[INT_PHY];
65528c2ecf20Sopenharmony_ci		if (vars->line_speed == SPEED_AUTO_NEG &&
65538c2ecf20Sopenharmony_ci		    (CHIP_IS_E1x(bp) ||
65548c2ecf20Sopenharmony_ci		     CHIP_IS_E2(bp)))
65558c2ecf20Sopenharmony_ci			bnx2x_set_parallel_detection(phy, params);
65568c2ecf20Sopenharmony_ci		if (params->phy[INT_PHY].config_init)
65578c2ecf20Sopenharmony_ci			params->phy[INT_PHY].config_init(phy, params, vars);
65588c2ecf20Sopenharmony_ci	}
65598c2ecf20Sopenharmony_ci
65608c2ecf20Sopenharmony_ci	/* Re-read this value in case it was changed inside config_init due to
65618c2ecf20Sopenharmony_ci	 * limitations of optic module
65628c2ecf20Sopenharmony_ci	 */
65638c2ecf20Sopenharmony_ci	vars->line_speed = params->phy[INT_PHY].req_line_speed;
65648c2ecf20Sopenharmony_ci
65658c2ecf20Sopenharmony_ci	/* Init external phy*/
65668c2ecf20Sopenharmony_ci	if (non_ext_phy) {
65678c2ecf20Sopenharmony_ci		if (params->phy[INT_PHY].supported &
65688c2ecf20Sopenharmony_ci		    SUPPORTED_FIBRE)
65698c2ecf20Sopenharmony_ci			vars->link_status |= LINK_STATUS_SERDES_LINK;
65708c2ecf20Sopenharmony_ci	} else {
65718c2ecf20Sopenharmony_ci		for (phy_index = EXT_PHY1; phy_index < params->num_phys;
65728c2ecf20Sopenharmony_ci		      phy_index++) {
65738c2ecf20Sopenharmony_ci			/* No need to initialize second phy in case of first
65748c2ecf20Sopenharmony_ci			 * phy only selection. In case of second phy, we do
65758c2ecf20Sopenharmony_ci			 * need to initialize the first phy, since they are
65768c2ecf20Sopenharmony_ci			 * connected.
65778c2ecf20Sopenharmony_ci			 */
65788c2ecf20Sopenharmony_ci			if (params->phy[phy_index].supported &
65798c2ecf20Sopenharmony_ci			    SUPPORTED_FIBRE)
65808c2ecf20Sopenharmony_ci				vars->link_status |= LINK_STATUS_SERDES_LINK;
65818c2ecf20Sopenharmony_ci
65828c2ecf20Sopenharmony_ci			if (phy_index == EXT_PHY2 &&
65838c2ecf20Sopenharmony_ci			    (bnx2x_phy_selection(params) ==
65848c2ecf20Sopenharmony_ci			     PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
65858c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
65868c2ecf20Sopenharmony_ci				   "Not initializing second phy\n");
65878c2ecf20Sopenharmony_ci				continue;
65888c2ecf20Sopenharmony_ci			}
65898c2ecf20Sopenharmony_ci			params->phy[phy_index].config_init(
65908c2ecf20Sopenharmony_ci				&params->phy[phy_index],
65918c2ecf20Sopenharmony_ci				params, vars);
65928c2ecf20Sopenharmony_ci		}
65938c2ecf20Sopenharmony_ci	}
65948c2ecf20Sopenharmony_ci	/* Reset the interrupt indication after phy was initialized */
65958c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
65968c2ecf20Sopenharmony_ci		       params->port*4,
65978c2ecf20Sopenharmony_ci		       (NIG_STATUS_XGXS0_LINK10G |
65988c2ecf20Sopenharmony_ci			NIG_STATUS_XGXS0_LINK_STATUS |
65998c2ecf20Sopenharmony_ci			NIG_STATUS_SERDES0_LINK_STATUS |
66008c2ecf20Sopenharmony_ci			NIG_MASK_MI_INT));
66018c2ecf20Sopenharmony_ci	return 0;
66028c2ecf20Sopenharmony_ci}
66038c2ecf20Sopenharmony_ci
66048c2ecf20Sopenharmony_cistatic void bnx2x_int_link_reset(struct bnx2x_phy *phy,
66058c2ecf20Sopenharmony_ci				 struct link_params *params)
66068c2ecf20Sopenharmony_ci{
66078c2ecf20Sopenharmony_ci	/* Reset the SerDes/XGXS */
66088c2ecf20Sopenharmony_ci	REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
66098c2ecf20Sopenharmony_ci	       (0x1ff << (params->port*16)));
66108c2ecf20Sopenharmony_ci}
66118c2ecf20Sopenharmony_ci
66128c2ecf20Sopenharmony_cistatic void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
66138c2ecf20Sopenharmony_ci					struct link_params *params)
66148c2ecf20Sopenharmony_ci{
66158c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
66168c2ecf20Sopenharmony_ci	u8 gpio_port;
66178c2ecf20Sopenharmony_ci	/* HW reset */
66188c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
66198c2ecf20Sopenharmony_ci		gpio_port = BP_PATH(bp);
66208c2ecf20Sopenharmony_ci	else
66218c2ecf20Sopenharmony_ci		gpio_port = params->port;
66228c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
66238c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW,
66248c2ecf20Sopenharmony_ci		       gpio_port);
66258c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
66268c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW,
66278c2ecf20Sopenharmony_ci		       gpio_port);
66288c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "reset external PHY\n");
66298c2ecf20Sopenharmony_ci}
66308c2ecf20Sopenharmony_ci
66318c2ecf20Sopenharmony_cistatic int bnx2x_update_link_down(struct link_params *params,
66328c2ecf20Sopenharmony_ci				  struct link_vars *vars)
66338c2ecf20Sopenharmony_ci{
66348c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
66358c2ecf20Sopenharmony_ci	u8 port = params->port;
66368c2ecf20Sopenharmony_ci
66378c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
66388c2ecf20Sopenharmony_ci	bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
66398c2ecf20Sopenharmony_ci	vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
66408c2ecf20Sopenharmony_ci	/* Indicate no mac active */
66418c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_NONE;
66428c2ecf20Sopenharmony_ci
66438c2ecf20Sopenharmony_ci	/* Update shared memory */
66448c2ecf20Sopenharmony_ci	vars->link_status &= ~LINK_UPDATE_MASK;
66458c2ecf20Sopenharmony_ci	vars->line_speed = 0;
66468c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
66478c2ecf20Sopenharmony_ci
66488c2ecf20Sopenharmony_ci	/* Activate nig drain */
66498c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
66508c2ecf20Sopenharmony_ci
66518c2ecf20Sopenharmony_ci	/* Disable emac */
66528c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp))
66538c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
66548c2ecf20Sopenharmony_ci
66558c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
66568c2ecf20Sopenharmony_ci	/* Reset BigMac/Xmac */
66578c2ecf20Sopenharmony_ci	if (CHIP_IS_E1x(bp) ||
66588c2ecf20Sopenharmony_ci	    CHIP_IS_E2(bp))
66598c2ecf20Sopenharmony_ci		bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
66608c2ecf20Sopenharmony_ci
66618c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
66628c2ecf20Sopenharmony_ci		/* Prevent LPI Generation by chip */
66638c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
66648c2ecf20Sopenharmony_ci		       0);
66658c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
66668c2ecf20Sopenharmony_ci		       0);
66678c2ecf20Sopenharmony_ci		vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
66688c2ecf20Sopenharmony_ci				      SHMEM_EEE_ACTIVE_BIT);
66698c2ecf20Sopenharmony_ci
66708c2ecf20Sopenharmony_ci		bnx2x_update_mng_eee(params, vars->eee_status);
66718c2ecf20Sopenharmony_ci		bnx2x_set_xmac_rxtx(params, 0);
66728c2ecf20Sopenharmony_ci		bnx2x_set_umac_rxtx(params, 0);
66738c2ecf20Sopenharmony_ci	}
66748c2ecf20Sopenharmony_ci
66758c2ecf20Sopenharmony_ci	return 0;
66768c2ecf20Sopenharmony_ci}
66778c2ecf20Sopenharmony_ci
66788c2ecf20Sopenharmony_cistatic int bnx2x_update_link_up(struct link_params *params,
66798c2ecf20Sopenharmony_ci				struct link_vars *vars,
66808c2ecf20Sopenharmony_ci				u8 link_10g)
66818c2ecf20Sopenharmony_ci{
66828c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
66838c2ecf20Sopenharmony_ci	u8 phy_idx, port = params->port;
66848c2ecf20Sopenharmony_ci	int rc = 0;
66858c2ecf20Sopenharmony_ci
66868c2ecf20Sopenharmony_ci	vars->link_status |= (LINK_STATUS_LINK_UP |
66878c2ecf20Sopenharmony_ci			      LINK_STATUS_PHYSICAL_LINK_FLAG);
66888c2ecf20Sopenharmony_ci	vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
66898c2ecf20Sopenharmony_ci
66908c2ecf20Sopenharmony_ci	if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
66918c2ecf20Sopenharmony_ci		vars->link_status |=
66928c2ecf20Sopenharmony_ci			LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
66938c2ecf20Sopenharmony_ci
66948c2ecf20Sopenharmony_ci	if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
66958c2ecf20Sopenharmony_ci		vars->link_status |=
66968c2ecf20Sopenharmony_ci			LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
66978c2ecf20Sopenharmony_ci	if (USES_WARPCORE(bp)) {
66988c2ecf20Sopenharmony_ci		if (link_10g) {
66998c2ecf20Sopenharmony_ci			if (bnx2x_xmac_enable(params, vars, 0) ==
67008c2ecf20Sopenharmony_ci			    -ESRCH) {
67018c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
67028c2ecf20Sopenharmony_ci				vars->link_up = 0;
67038c2ecf20Sopenharmony_ci				vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
67048c2ecf20Sopenharmony_ci				vars->link_status &= ~LINK_STATUS_LINK_UP;
67058c2ecf20Sopenharmony_ci			}
67068c2ecf20Sopenharmony_ci		} else
67078c2ecf20Sopenharmony_ci			bnx2x_umac_enable(params, vars, 0);
67088c2ecf20Sopenharmony_ci		bnx2x_set_led(params, vars,
67098c2ecf20Sopenharmony_ci			      LED_MODE_OPER, vars->line_speed);
67108c2ecf20Sopenharmony_ci
67118c2ecf20Sopenharmony_ci		if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
67128c2ecf20Sopenharmony_ci		    (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
67138c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Enabling LPI assertion\n");
67148c2ecf20Sopenharmony_ci			REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
67158c2ecf20Sopenharmony_ci			       (params->port << 2), 1);
67168c2ecf20Sopenharmony_ci			REG_WR(bp, MISC_REG_CPMU_LP_DR_ENABLE, 1);
67178c2ecf20Sopenharmony_ci			REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 +
67188c2ecf20Sopenharmony_ci			       (params->port << 2), 0xfc20);
67198c2ecf20Sopenharmony_ci		}
67208c2ecf20Sopenharmony_ci	}
67218c2ecf20Sopenharmony_ci	if ((CHIP_IS_E1x(bp) ||
67228c2ecf20Sopenharmony_ci	     CHIP_IS_E2(bp))) {
67238c2ecf20Sopenharmony_ci		if (link_10g) {
67248c2ecf20Sopenharmony_ci			if (bnx2x_bmac_enable(params, vars, 0, 1) ==
67258c2ecf20Sopenharmony_ci			    -ESRCH) {
67268c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
67278c2ecf20Sopenharmony_ci				vars->link_up = 0;
67288c2ecf20Sopenharmony_ci				vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
67298c2ecf20Sopenharmony_ci				vars->link_status &= ~LINK_STATUS_LINK_UP;
67308c2ecf20Sopenharmony_ci			}
67318c2ecf20Sopenharmony_ci
67328c2ecf20Sopenharmony_ci			bnx2x_set_led(params, vars,
67338c2ecf20Sopenharmony_ci				      LED_MODE_OPER, SPEED_10000);
67348c2ecf20Sopenharmony_ci		} else {
67358c2ecf20Sopenharmony_ci			rc = bnx2x_emac_program(params, vars);
67368c2ecf20Sopenharmony_ci			bnx2x_emac_enable(params, vars, 0);
67378c2ecf20Sopenharmony_ci
67388c2ecf20Sopenharmony_ci			/* AN complete? */
67398c2ecf20Sopenharmony_ci			if ((vars->link_status &
67408c2ecf20Sopenharmony_ci			     LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
67418c2ecf20Sopenharmony_ci			    && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
67428c2ecf20Sopenharmony_ci			    SINGLE_MEDIA_DIRECT(params))
67438c2ecf20Sopenharmony_ci				bnx2x_set_gmii_tx_driver(params);
67448c2ecf20Sopenharmony_ci		}
67458c2ecf20Sopenharmony_ci	}
67468c2ecf20Sopenharmony_ci
67478c2ecf20Sopenharmony_ci	/* PBF - link up */
67488c2ecf20Sopenharmony_ci	if (CHIP_IS_E1x(bp))
67498c2ecf20Sopenharmony_ci		rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
67508c2ecf20Sopenharmony_ci				       vars->line_speed);
67518c2ecf20Sopenharmony_ci
67528c2ecf20Sopenharmony_ci	/* Disable drain */
67538c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
67548c2ecf20Sopenharmony_ci
67558c2ecf20Sopenharmony_ci	/* Update shared memory */
67568c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
67578c2ecf20Sopenharmony_ci	bnx2x_update_mng_eee(params, vars->eee_status);
67588c2ecf20Sopenharmony_ci	/* Check remote fault */
67598c2ecf20Sopenharmony_ci	for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
67608c2ecf20Sopenharmony_ci		if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
67618c2ecf20Sopenharmony_ci			bnx2x_check_half_open_conn(params, vars, 0);
67628c2ecf20Sopenharmony_ci			break;
67638c2ecf20Sopenharmony_ci		}
67648c2ecf20Sopenharmony_ci	}
67658c2ecf20Sopenharmony_ci	msleep(20);
67668c2ecf20Sopenharmony_ci	return rc;
67678c2ecf20Sopenharmony_ci}
67688c2ecf20Sopenharmony_ci
67698c2ecf20Sopenharmony_cistatic void bnx2x_chng_link_count(struct link_params *params, bool clear)
67708c2ecf20Sopenharmony_ci{
67718c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
67728c2ecf20Sopenharmony_ci	u32 addr, val;
67738c2ecf20Sopenharmony_ci
67748c2ecf20Sopenharmony_ci	/* Verify the link_change_count is supported by the MFW */
67758c2ecf20Sopenharmony_ci	if (!(SHMEM2_HAS(bp, link_change_count)))
67768c2ecf20Sopenharmony_ci		return;
67778c2ecf20Sopenharmony_ci
67788c2ecf20Sopenharmony_ci	addr = params->shmem2_base +
67798c2ecf20Sopenharmony_ci		offsetof(struct shmem2_region, link_change_count[params->port]);
67808c2ecf20Sopenharmony_ci	if (clear)
67818c2ecf20Sopenharmony_ci		val = 0;
67828c2ecf20Sopenharmony_ci	else
67838c2ecf20Sopenharmony_ci		val = REG_RD(bp, addr) + 1;
67848c2ecf20Sopenharmony_ci	REG_WR(bp, addr, val);
67858c2ecf20Sopenharmony_ci}
67868c2ecf20Sopenharmony_ci
67878c2ecf20Sopenharmony_ci/* The bnx2x_link_update function should be called upon link
67888c2ecf20Sopenharmony_ci * interrupt.
67898c2ecf20Sopenharmony_ci * Link is considered up as follows:
67908c2ecf20Sopenharmony_ci * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
67918c2ecf20Sopenharmony_ci *   to be up
67928c2ecf20Sopenharmony_ci * - SINGLE_MEDIA - The link between the 577xx and the external
67938c2ecf20Sopenharmony_ci *   phy (XGXS) need to up as well as the external link of the
67948c2ecf20Sopenharmony_ci *   phy (PHY_EXT1)
67958c2ecf20Sopenharmony_ci * - DUAL_MEDIA - The link between the 577xx and the first
67968c2ecf20Sopenharmony_ci *   external phy needs to be up, and at least one of the 2
67978c2ecf20Sopenharmony_ci *   external phy link must be up.
67988c2ecf20Sopenharmony_ci */
67998c2ecf20Sopenharmony_ciint bnx2x_link_update(struct link_params *params, struct link_vars *vars)
68008c2ecf20Sopenharmony_ci{
68018c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
68028c2ecf20Sopenharmony_ci	struct link_vars phy_vars[MAX_PHYS];
68038c2ecf20Sopenharmony_ci	u8 port = params->port;
68048c2ecf20Sopenharmony_ci	u8 link_10g_plus, phy_index;
68058c2ecf20Sopenharmony_ci	u32 prev_link_status = vars->link_status;
68068c2ecf20Sopenharmony_ci	u8 ext_phy_link_up = 0, cur_link_up;
68078c2ecf20Sopenharmony_ci	int rc = 0;
68088c2ecf20Sopenharmony_ci	u8 is_mi_int = 0;
68098c2ecf20Sopenharmony_ci	u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
68108c2ecf20Sopenharmony_ci	u8 active_external_phy = INT_PHY;
68118c2ecf20Sopenharmony_ci	vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
68128c2ecf20Sopenharmony_ci	vars->link_status &= ~LINK_UPDATE_MASK;
68138c2ecf20Sopenharmony_ci	for (phy_index = INT_PHY; phy_index < params->num_phys;
68148c2ecf20Sopenharmony_ci	      phy_index++) {
68158c2ecf20Sopenharmony_ci		phy_vars[phy_index].flow_ctrl = 0;
68168c2ecf20Sopenharmony_ci		phy_vars[phy_index].link_status = 0;
68178c2ecf20Sopenharmony_ci		phy_vars[phy_index].line_speed = 0;
68188c2ecf20Sopenharmony_ci		phy_vars[phy_index].duplex = DUPLEX_FULL;
68198c2ecf20Sopenharmony_ci		phy_vars[phy_index].phy_link_up = 0;
68208c2ecf20Sopenharmony_ci		phy_vars[phy_index].link_up = 0;
68218c2ecf20Sopenharmony_ci		phy_vars[phy_index].fault_detected = 0;
68228c2ecf20Sopenharmony_ci		/* different consideration, since vars holds inner state */
68238c2ecf20Sopenharmony_ci		phy_vars[phy_index].eee_status = vars->eee_status;
68248c2ecf20Sopenharmony_ci	}
68258c2ecf20Sopenharmony_ci
68268c2ecf20Sopenharmony_ci	if (USES_WARPCORE(bp))
68278c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
68288c2ecf20Sopenharmony_ci
68298c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
68308c2ecf20Sopenharmony_ci		 port, (vars->phy_flags & PHY_XGXS_FLAG),
68318c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
68328c2ecf20Sopenharmony_ci
68338c2ecf20Sopenharmony_ci	is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
68348c2ecf20Sopenharmony_ci				port*0x18) > 0);
68358c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
68368c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
68378c2ecf20Sopenharmony_ci		 is_mi_int,
68388c2ecf20Sopenharmony_ci		 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
68398c2ecf20Sopenharmony_ci
68408c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
68418c2ecf20Sopenharmony_ci	  REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
68428c2ecf20Sopenharmony_ci	  REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
68438c2ecf20Sopenharmony_ci
68448c2ecf20Sopenharmony_ci	/* Disable emac */
68458c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp))
68468c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
68478c2ecf20Sopenharmony_ci
68488c2ecf20Sopenharmony_ci	/* Step 1:
68498c2ecf20Sopenharmony_ci	 * Check external link change only for external phys, and apply
68508c2ecf20Sopenharmony_ci	 * priority selection between them in case the link on both phys
68518c2ecf20Sopenharmony_ci	 * is up. Note that instead of the common vars, a temporary
68528c2ecf20Sopenharmony_ci	 * vars argument is used since each phy may have different link/
68538c2ecf20Sopenharmony_ci	 * speed/duplex result
68548c2ecf20Sopenharmony_ci	 */
68558c2ecf20Sopenharmony_ci	for (phy_index = EXT_PHY1; phy_index < params->num_phys;
68568c2ecf20Sopenharmony_ci	      phy_index++) {
68578c2ecf20Sopenharmony_ci		struct bnx2x_phy *phy = &params->phy[phy_index];
68588c2ecf20Sopenharmony_ci		if (!phy->read_status)
68598c2ecf20Sopenharmony_ci			continue;
68608c2ecf20Sopenharmony_ci		/* Read link status and params of this ext phy */
68618c2ecf20Sopenharmony_ci		cur_link_up = phy->read_status(phy, params,
68628c2ecf20Sopenharmony_ci					       &phy_vars[phy_index]);
68638c2ecf20Sopenharmony_ci		if (cur_link_up) {
68648c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
68658c2ecf20Sopenharmony_ci				   phy_index);
68668c2ecf20Sopenharmony_ci		} else {
68678c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
68688c2ecf20Sopenharmony_ci				   phy_index);
68698c2ecf20Sopenharmony_ci			continue;
68708c2ecf20Sopenharmony_ci		}
68718c2ecf20Sopenharmony_ci
68728c2ecf20Sopenharmony_ci		if (!ext_phy_link_up) {
68738c2ecf20Sopenharmony_ci			ext_phy_link_up = 1;
68748c2ecf20Sopenharmony_ci			active_external_phy = phy_index;
68758c2ecf20Sopenharmony_ci		} else {
68768c2ecf20Sopenharmony_ci			switch (bnx2x_phy_selection(params)) {
68778c2ecf20Sopenharmony_ci			case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
68788c2ecf20Sopenharmony_ci			case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
68798c2ecf20Sopenharmony_ci			/* In this option, the first PHY makes sure to pass the
68808c2ecf20Sopenharmony_ci			 * traffic through itself only.
68818c2ecf20Sopenharmony_ci			 * It's not clear how to reset the link on the second
68828c2ecf20Sopenharmony_ci			 * phy.
68838c2ecf20Sopenharmony_ci			 */
68848c2ecf20Sopenharmony_ci				active_external_phy = EXT_PHY1;
68858c2ecf20Sopenharmony_ci				break;
68868c2ecf20Sopenharmony_ci			case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
68878c2ecf20Sopenharmony_ci			/* In this option, the first PHY makes sure to pass the
68888c2ecf20Sopenharmony_ci			 * traffic through the second PHY.
68898c2ecf20Sopenharmony_ci			 */
68908c2ecf20Sopenharmony_ci				active_external_phy = EXT_PHY2;
68918c2ecf20Sopenharmony_ci				break;
68928c2ecf20Sopenharmony_ci			default:
68938c2ecf20Sopenharmony_ci			/* Link indication on both PHYs with the following cases
68948c2ecf20Sopenharmony_ci			 * is invalid:
68958c2ecf20Sopenharmony_ci			 * - FIRST_PHY means that second phy wasn't initialized,
68968c2ecf20Sopenharmony_ci			 * hence its link is expected to be down
68978c2ecf20Sopenharmony_ci			 * - SECOND_PHY means that first phy should not be able
68988c2ecf20Sopenharmony_ci			 * to link up by itself (using configuration)
68998c2ecf20Sopenharmony_ci			 * - DEFAULT should be overridden during initialization
69008c2ecf20Sopenharmony_ci			 */
69018c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Invalid link indication"
69028c2ecf20Sopenharmony_ci					   "mpc=0x%x. DISABLING LINK !!!\n",
69038c2ecf20Sopenharmony_ci					   params->multi_phy_config);
69048c2ecf20Sopenharmony_ci				ext_phy_link_up = 0;
69058c2ecf20Sopenharmony_ci				break;
69068c2ecf20Sopenharmony_ci			}
69078c2ecf20Sopenharmony_ci		}
69088c2ecf20Sopenharmony_ci	}
69098c2ecf20Sopenharmony_ci	prev_line_speed = vars->line_speed;
69108c2ecf20Sopenharmony_ci	/* Step 2:
69118c2ecf20Sopenharmony_ci	 * Read the status of the internal phy. In case of
69128c2ecf20Sopenharmony_ci	 * DIRECT_SINGLE_MEDIA board, this link is the external link,
69138c2ecf20Sopenharmony_ci	 * otherwise this is the link between the 577xx and the first
69148c2ecf20Sopenharmony_ci	 * external phy
69158c2ecf20Sopenharmony_ci	 */
69168c2ecf20Sopenharmony_ci	if (params->phy[INT_PHY].read_status)
69178c2ecf20Sopenharmony_ci		params->phy[INT_PHY].read_status(
69188c2ecf20Sopenharmony_ci			&params->phy[INT_PHY],
69198c2ecf20Sopenharmony_ci			params, vars);
69208c2ecf20Sopenharmony_ci	/* The INT_PHY flow control reside in the vars. This include the
69218c2ecf20Sopenharmony_ci	 * case where the speed or flow control are not set to AUTO.
69228c2ecf20Sopenharmony_ci	 * Otherwise, the active external phy flow control result is set
69238c2ecf20Sopenharmony_ci	 * to the vars. The ext_phy_line_speed is needed to check if the
69248c2ecf20Sopenharmony_ci	 * speed is different between the internal phy and external phy.
69258c2ecf20Sopenharmony_ci	 * This case may be result of intermediate link speed change.
69268c2ecf20Sopenharmony_ci	 */
69278c2ecf20Sopenharmony_ci	if (active_external_phy > INT_PHY) {
69288c2ecf20Sopenharmony_ci		vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
69298c2ecf20Sopenharmony_ci		/* Link speed is taken from the XGXS. AN and FC result from
69308c2ecf20Sopenharmony_ci		 * the external phy.
69318c2ecf20Sopenharmony_ci		 */
69328c2ecf20Sopenharmony_ci		vars->link_status |= phy_vars[active_external_phy].link_status;
69338c2ecf20Sopenharmony_ci
69348c2ecf20Sopenharmony_ci		/* if active_external_phy is first PHY and link is up - disable
69358c2ecf20Sopenharmony_ci		 * disable TX on second external PHY
69368c2ecf20Sopenharmony_ci		 */
69378c2ecf20Sopenharmony_ci		if (active_external_phy == EXT_PHY1) {
69388c2ecf20Sopenharmony_ci			if (params->phy[EXT_PHY2].phy_specific_func) {
69398c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
69408c2ecf20Sopenharmony_ci				   "Disabling TX on EXT_PHY2\n");
69418c2ecf20Sopenharmony_ci				params->phy[EXT_PHY2].phy_specific_func(
69428c2ecf20Sopenharmony_ci					&params->phy[EXT_PHY2],
69438c2ecf20Sopenharmony_ci					params, DISABLE_TX);
69448c2ecf20Sopenharmony_ci			}
69458c2ecf20Sopenharmony_ci		}
69468c2ecf20Sopenharmony_ci
69478c2ecf20Sopenharmony_ci		ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
69488c2ecf20Sopenharmony_ci		vars->duplex = phy_vars[active_external_phy].duplex;
69498c2ecf20Sopenharmony_ci		if (params->phy[active_external_phy].supported &
69508c2ecf20Sopenharmony_ci		    SUPPORTED_FIBRE)
69518c2ecf20Sopenharmony_ci			vars->link_status |= LINK_STATUS_SERDES_LINK;
69528c2ecf20Sopenharmony_ci		else
69538c2ecf20Sopenharmony_ci			vars->link_status &= ~LINK_STATUS_SERDES_LINK;
69548c2ecf20Sopenharmony_ci
69558c2ecf20Sopenharmony_ci		vars->eee_status = phy_vars[active_external_phy].eee_status;
69568c2ecf20Sopenharmony_ci
69578c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
69588c2ecf20Sopenharmony_ci			   active_external_phy);
69598c2ecf20Sopenharmony_ci	}
69608c2ecf20Sopenharmony_ci
69618c2ecf20Sopenharmony_ci	for (phy_index = EXT_PHY1; phy_index < params->num_phys;
69628c2ecf20Sopenharmony_ci	      phy_index++) {
69638c2ecf20Sopenharmony_ci		if (params->phy[phy_index].flags &
69648c2ecf20Sopenharmony_ci		    FLAGS_REARM_LATCH_SIGNAL) {
69658c2ecf20Sopenharmony_ci			bnx2x_rearm_latch_signal(bp, port,
69668c2ecf20Sopenharmony_ci						 phy_index ==
69678c2ecf20Sopenharmony_ci						 active_external_phy);
69688c2ecf20Sopenharmony_ci			break;
69698c2ecf20Sopenharmony_ci		}
69708c2ecf20Sopenharmony_ci	}
69718c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
69728c2ecf20Sopenharmony_ci		   " ext_phy_line_speed = %d\n", vars->flow_ctrl,
69738c2ecf20Sopenharmony_ci		   vars->link_status, ext_phy_line_speed);
69748c2ecf20Sopenharmony_ci	/* Upon link speed change set the NIG into drain mode. Comes to
69758c2ecf20Sopenharmony_ci	 * deals with possible FIFO glitch due to clk change when speed
69768c2ecf20Sopenharmony_ci	 * is decreased without link down indicator
69778c2ecf20Sopenharmony_ci	 */
69788c2ecf20Sopenharmony_ci
69798c2ecf20Sopenharmony_ci	if (vars->phy_link_up) {
69808c2ecf20Sopenharmony_ci		if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
69818c2ecf20Sopenharmony_ci		    (ext_phy_line_speed != vars->line_speed)) {
69828c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Internal link speed %d is"
69838c2ecf20Sopenharmony_ci				   " different than the external"
69848c2ecf20Sopenharmony_ci				   " link speed %d\n", vars->line_speed,
69858c2ecf20Sopenharmony_ci				   ext_phy_line_speed);
69868c2ecf20Sopenharmony_ci			vars->phy_link_up = 0;
69878c2ecf20Sopenharmony_ci		} else if (prev_line_speed != vars->line_speed) {
69888c2ecf20Sopenharmony_ci			REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
69898c2ecf20Sopenharmony_ci			       0);
69908c2ecf20Sopenharmony_ci			usleep_range(1000, 2000);
69918c2ecf20Sopenharmony_ci		}
69928c2ecf20Sopenharmony_ci	}
69938c2ecf20Sopenharmony_ci
69948c2ecf20Sopenharmony_ci	/* Anything 10 and over uses the bmac */
69958c2ecf20Sopenharmony_ci	link_10g_plus = (vars->line_speed >= SPEED_10000);
69968c2ecf20Sopenharmony_ci
69978c2ecf20Sopenharmony_ci	bnx2x_link_int_ack(params, vars, link_10g_plus);
69988c2ecf20Sopenharmony_ci
69998c2ecf20Sopenharmony_ci	/* In case external phy link is up, and internal link is down
70008c2ecf20Sopenharmony_ci	 * (not initialized yet probably after link initialization, it
70018c2ecf20Sopenharmony_ci	 * needs to be initialized.
70028c2ecf20Sopenharmony_ci	 * Note that after link down-up as result of cable plug, the xgxs
70038c2ecf20Sopenharmony_ci	 * link would probably become up again without the need
70048c2ecf20Sopenharmony_ci	 * initialize it
70058c2ecf20Sopenharmony_ci	 */
70068c2ecf20Sopenharmony_ci	if (!(SINGLE_MEDIA_DIRECT(params))) {
70078c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
70088c2ecf20Sopenharmony_ci			   " init_preceding = %d\n", ext_phy_link_up,
70098c2ecf20Sopenharmony_ci			   vars->phy_link_up,
70108c2ecf20Sopenharmony_ci			   params->phy[EXT_PHY1].flags &
70118c2ecf20Sopenharmony_ci			   FLAGS_INIT_XGXS_FIRST);
70128c2ecf20Sopenharmony_ci		if (!(params->phy[EXT_PHY1].flags &
70138c2ecf20Sopenharmony_ci		      FLAGS_INIT_XGXS_FIRST)
70148c2ecf20Sopenharmony_ci		    && ext_phy_link_up && !vars->phy_link_up) {
70158c2ecf20Sopenharmony_ci			vars->line_speed = ext_phy_line_speed;
70168c2ecf20Sopenharmony_ci			if (vars->line_speed < SPEED_1000)
70178c2ecf20Sopenharmony_ci				vars->phy_flags |= PHY_SGMII_FLAG;
70188c2ecf20Sopenharmony_ci			else
70198c2ecf20Sopenharmony_ci				vars->phy_flags &= ~PHY_SGMII_FLAG;
70208c2ecf20Sopenharmony_ci
70218c2ecf20Sopenharmony_ci			if (params->phy[INT_PHY].config_init)
70228c2ecf20Sopenharmony_ci				params->phy[INT_PHY].config_init(
70238c2ecf20Sopenharmony_ci					&params->phy[INT_PHY], params,
70248c2ecf20Sopenharmony_ci						vars);
70258c2ecf20Sopenharmony_ci		}
70268c2ecf20Sopenharmony_ci	}
70278c2ecf20Sopenharmony_ci	/* Link is up only if both local phy and external phy (in case of
70288c2ecf20Sopenharmony_ci	 * non-direct board) are up and no fault detected on active PHY.
70298c2ecf20Sopenharmony_ci	 */
70308c2ecf20Sopenharmony_ci	vars->link_up = (vars->phy_link_up &&
70318c2ecf20Sopenharmony_ci			 (ext_phy_link_up ||
70328c2ecf20Sopenharmony_ci			  SINGLE_MEDIA_DIRECT(params)) &&
70338c2ecf20Sopenharmony_ci			 (phy_vars[active_external_phy].fault_detected == 0));
70348c2ecf20Sopenharmony_ci
70358c2ecf20Sopenharmony_ci	/* Update the PFC configuration in case it was changed */
70368c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
70378c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_PFC_ENABLED;
70388c2ecf20Sopenharmony_ci	else
70398c2ecf20Sopenharmony_ci		vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
70408c2ecf20Sopenharmony_ci
70418c2ecf20Sopenharmony_ci	if (vars->link_up)
70428c2ecf20Sopenharmony_ci		rc = bnx2x_update_link_up(params, vars, link_10g_plus);
70438c2ecf20Sopenharmony_ci	else
70448c2ecf20Sopenharmony_ci		rc = bnx2x_update_link_down(params, vars);
70458c2ecf20Sopenharmony_ci
70468c2ecf20Sopenharmony_ci	if ((prev_link_status ^ vars->link_status) & LINK_STATUS_LINK_UP)
70478c2ecf20Sopenharmony_ci		bnx2x_chng_link_count(params, false);
70488c2ecf20Sopenharmony_ci
70498c2ecf20Sopenharmony_ci	/* Update MCP link status was changed */
70508c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_BC_SUPPORTS_AFEX)
70518c2ecf20Sopenharmony_ci		bnx2x_fw_command(bp, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
70528c2ecf20Sopenharmony_ci
70538c2ecf20Sopenharmony_ci	return rc;
70548c2ecf20Sopenharmony_ci}
70558c2ecf20Sopenharmony_ci
70568c2ecf20Sopenharmony_ci/*****************************************************************************/
70578c2ecf20Sopenharmony_ci/*			    External Phy section			     */
70588c2ecf20Sopenharmony_ci/*****************************************************************************/
70598c2ecf20Sopenharmony_civoid bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
70608c2ecf20Sopenharmony_ci{
70618c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
70628c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
70638c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
70648c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
70658c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
70668c2ecf20Sopenharmony_ci}
70678c2ecf20Sopenharmony_ci
70688c2ecf20Sopenharmony_cistatic void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
70698c2ecf20Sopenharmony_ci				      u32 spirom_ver, u32 ver_addr)
70708c2ecf20Sopenharmony_ci{
70718c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
70728c2ecf20Sopenharmony_ci		 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
70738c2ecf20Sopenharmony_ci
70748c2ecf20Sopenharmony_ci	if (ver_addr)
70758c2ecf20Sopenharmony_ci		REG_WR(bp, ver_addr, spirom_ver);
70768c2ecf20Sopenharmony_ci}
70778c2ecf20Sopenharmony_ci
70788c2ecf20Sopenharmony_cistatic void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
70798c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
70808c2ecf20Sopenharmony_ci				      u8 port)
70818c2ecf20Sopenharmony_ci{
70828c2ecf20Sopenharmony_ci	u16 fw_ver1, fw_ver2;
70838c2ecf20Sopenharmony_ci
70848c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
70858c2ecf20Sopenharmony_ci			MDIO_PMA_REG_ROM_VER1, &fw_ver1);
70868c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
70878c2ecf20Sopenharmony_ci			MDIO_PMA_REG_ROM_VER2, &fw_ver2);
70888c2ecf20Sopenharmony_ci	bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
70898c2ecf20Sopenharmony_ci				  phy->ver_addr);
70908c2ecf20Sopenharmony_ci}
70918c2ecf20Sopenharmony_ci
70928c2ecf20Sopenharmony_cistatic void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
70938c2ecf20Sopenharmony_ci				       struct bnx2x_phy *phy,
70948c2ecf20Sopenharmony_ci				       struct link_vars *vars)
70958c2ecf20Sopenharmony_ci{
70968c2ecf20Sopenharmony_ci	u16 val;
70978c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
70988c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD,
70998c2ecf20Sopenharmony_ci			MDIO_AN_REG_STATUS, &val);
71008c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
71018c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD,
71028c2ecf20Sopenharmony_ci			MDIO_AN_REG_STATUS, &val);
71038c2ecf20Sopenharmony_ci	if (val & (1<<5))
71048c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
71058c2ecf20Sopenharmony_ci	if ((val & (1<<0)) == 0)
71068c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
71078c2ecf20Sopenharmony_ci}
71088c2ecf20Sopenharmony_ci
71098c2ecf20Sopenharmony_ci/******************************************************************/
71108c2ecf20Sopenharmony_ci/*		common BCM8073/BCM8727 PHY SECTION		  */
71118c2ecf20Sopenharmony_ci/******************************************************************/
71128c2ecf20Sopenharmony_cistatic void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
71138c2ecf20Sopenharmony_ci				  struct link_params *params,
71148c2ecf20Sopenharmony_ci				  struct link_vars *vars)
71158c2ecf20Sopenharmony_ci{
71168c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
71178c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_10 ||
71188c2ecf20Sopenharmony_ci	    phy->req_line_speed == SPEED_100) {
71198c2ecf20Sopenharmony_ci		vars->flow_ctrl = phy->req_flow_ctrl;
71208c2ecf20Sopenharmony_ci		return;
71218c2ecf20Sopenharmony_ci	}
71228c2ecf20Sopenharmony_ci
71238c2ecf20Sopenharmony_ci	if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
71248c2ecf20Sopenharmony_ci	    (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
71258c2ecf20Sopenharmony_ci		u16 pause_result;
71268c2ecf20Sopenharmony_ci		u16 ld_pause;		/* local */
71278c2ecf20Sopenharmony_ci		u16 lp_pause;		/* link partner */
71288c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
71298c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
71308c2ecf20Sopenharmony_ci				MDIO_AN_REG_CL37_FC_LD, &ld_pause);
71318c2ecf20Sopenharmony_ci
71328c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
71338c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
71348c2ecf20Sopenharmony_ci				MDIO_AN_REG_CL37_FC_LP, &lp_pause);
71358c2ecf20Sopenharmony_ci		pause_result = (ld_pause &
71368c2ecf20Sopenharmony_ci				MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
71378c2ecf20Sopenharmony_ci		pause_result |= (lp_pause &
71388c2ecf20Sopenharmony_ci				 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
71398c2ecf20Sopenharmony_ci
71408c2ecf20Sopenharmony_ci		bnx2x_pause_resolve(phy, params, vars, pause_result);
71418c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
71428c2ecf20Sopenharmony_ci			   pause_result);
71438c2ecf20Sopenharmony_ci	}
71448c2ecf20Sopenharmony_ci}
71458c2ecf20Sopenharmony_cistatic int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
71468c2ecf20Sopenharmony_ci					     struct bnx2x_phy *phy,
71478c2ecf20Sopenharmony_ci					     u8 port)
71488c2ecf20Sopenharmony_ci{
71498c2ecf20Sopenharmony_ci	u32 count = 0;
71508c2ecf20Sopenharmony_ci	u16 fw_ver1, fw_msgout;
71518c2ecf20Sopenharmony_ci	int rc = 0;
71528c2ecf20Sopenharmony_ci
71538c2ecf20Sopenharmony_ci	/* Boot port from external ROM  */
71548c2ecf20Sopenharmony_ci	/* EDC grst */
71558c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
71568c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
71578c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
71588c2ecf20Sopenharmony_ci			 0x0001);
71598c2ecf20Sopenharmony_ci
71608c2ecf20Sopenharmony_ci	/* Ucode reboot and rst */
71618c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
71628c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
71638c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
71648c2ecf20Sopenharmony_ci			 0x008c);
71658c2ecf20Sopenharmony_ci
71668c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
71678c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
71688c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
71698c2ecf20Sopenharmony_ci
71708c2ecf20Sopenharmony_ci	/* Reset internal microprocessor */
71718c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
71728c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
71738c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
71748c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
71758c2ecf20Sopenharmony_ci
71768c2ecf20Sopenharmony_ci	/* Release srst bit */
71778c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
71788c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
71798c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
71808c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
71818c2ecf20Sopenharmony_ci
71828c2ecf20Sopenharmony_ci	/* Delay 100ms per the PHY specifications */
71838c2ecf20Sopenharmony_ci	msleep(100);
71848c2ecf20Sopenharmony_ci
71858c2ecf20Sopenharmony_ci	/* 8073 sometimes taking longer to download */
71868c2ecf20Sopenharmony_ci	do {
71878c2ecf20Sopenharmony_ci		count++;
71888c2ecf20Sopenharmony_ci		if (count > 300) {
71898c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
71908c2ecf20Sopenharmony_ci				 "bnx2x_8073_8727_external_rom_boot port %x:"
71918c2ecf20Sopenharmony_ci				 "Download failed. fw version = 0x%x\n",
71928c2ecf20Sopenharmony_ci				 port, fw_ver1);
71938c2ecf20Sopenharmony_ci			rc = -EINVAL;
71948c2ecf20Sopenharmony_ci			break;
71958c2ecf20Sopenharmony_ci		}
71968c2ecf20Sopenharmony_ci
71978c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
71988c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
71998c2ecf20Sopenharmony_ci				MDIO_PMA_REG_ROM_VER1, &fw_ver1);
72008c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
72018c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
72028c2ecf20Sopenharmony_ci				MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
72038c2ecf20Sopenharmony_ci
72048c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
72058c2ecf20Sopenharmony_ci	} while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
72068c2ecf20Sopenharmony_ci			((fw_msgout & 0xff) != 0x03 && (phy->type ==
72078c2ecf20Sopenharmony_ci			PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
72088c2ecf20Sopenharmony_ci
72098c2ecf20Sopenharmony_ci	/* Clear ser_boot_ctl bit */
72108c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
72118c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
72128c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
72138c2ecf20Sopenharmony_ci	bnx2x_save_bcm_spirom_ver(bp, phy, port);
72148c2ecf20Sopenharmony_ci
72158c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK,
72168c2ecf20Sopenharmony_ci		 "bnx2x_8073_8727_external_rom_boot port %x:"
72178c2ecf20Sopenharmony_ci		 "Download complete. fw version = 0x%x\n",
72188c2ecf20Sopenharmony_ci		 port, fw_ver1);
72198c2ecf20Sopenharmony_ci
72208c2ecf20Sopenharmony_ci	return rc;
72218c2ecf20Sopenharmony_ci}
72228c2ecf20Sopenharmony_ci
72238c2ecf20Sopenharmony_ci/******************************************************************/
72248c2ecf20Sopenharmony_ci/*			BCM8073 PHY SECTION			  */
72258c2ecf20Sopenharmony_ci/******************************************************************/
72268c2ecf20Sopenharmony_cistatic int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
72278c2ecf20Sopenharmony_ci{
72288c2ecf20Sopenharmony_ci	/* This is only required for 8073A1, version 102 only */
72298c2ecf20Sopenharmony_ci	u16 val;
72308c2ecf20Sopenharmony_ci
72318c2ecf20Sopenharmony_ci	/* Read 8073 HW revision*/
72328c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
72338c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
72348c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8073_CHIP_REV, &val);
72358c2ecf20Sopenharmony_ci
72368c2ecf20Sopenharmony_ci	if (val != 1) {
72378c2ecf20Sopenharmony_ci		/* No need to workaround in 8073 A1 */
72388c2ecf20Sopenharmony_ci		return 0;
72398c2ecf20Sopenharmony_ci	}
72408c2ecf20Sopenharmony_ci
72418c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
72428c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
72438c2ecf20Sopenharmony_ci			MDIO_PMA_REG_ROM_VER2, &val);
72448c2ecf20Sopenharmony_ci
72458c2ecf20Sopenharmony_ci	/* SNR should be applied only for version 0x102 */
72468c2ecf20Sopenharmony_ci	if (val != 0x102)
72478c2ecf20Sopenharmony_ci		return 0;
72488c2ecf20Sopenharmony_ci
72498c2ecf20Sopenharmony_ci	return 1;
72508c2ecf20Sopenharmony_ci}
72518c2ecf20Sopenharmony_ci
72528c2ecf20Sopenharmony_cistatic int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
72538c2ecf20Sopenharmony_ci{
72548c2ecf20Sopenharmony_ci	u16 val, cnt, cnt1 ;
72558c2ecf20Sopenharmony_ci
72568c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
72578c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
72588c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8073_CHIP_REV, &val);
72598c2ecf20Sopenharmony_ci
72608c2ecf20Sopenharmony_ci	if (val > 0) {
72618c2ecf20Sopenharmony_ci		/* No need to workaround in 8073 A1 */
72628c2ecf20Sopenharmony_ci		return 0;
72638c2ecf20Sopenharmony_ci	}
72648c2ecf20Sopenharmony_ci	/* XAUI workaround in 8073 A0: */
72658c2ecf20Sopenharmony_ci
72668c2ecf20Sopenharmony_ci	/* After loading the boot ROM and restarting Autoneg, poll
72678c2ecf20Sopenharmony_ci	 * Dev1, Reg $C820:
72688c2ecf20Sopenharmony_ci	 */
72698c2ecf20Sopenharmony_ci
72708c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 1000; cnt++) {
72718c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
72728c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
72738c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
72748c2ecf20Sopenharmony_ci				&val);
72758c2ecf20Sopenharmony_ci		  /* If bit [14] = 0 or bit [13] = 0, continue on with
72768c2ecf20Sopenharmony_ci		   * system initialization (XAUI work-around not required, as
72778c2ecf20Sopenharmony_ci		   * these bits indicate 2.5G or 1G link up).
72788c2ecf20Sopenharmony_ci		   */
72798c2ecf20Sopenharmony_ci		if (!(val & (1<<14)) || !(val & (1<<13))) {
72808c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
72818c2ecf20Sopenharmony_ci			return 0;
72828c2ecf20Sopenharmony_ci		} else if (!(val & (1<<15))) {
72838c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "bit 15 went off\n");
72848c2ecf20Sopenharmony_ci			/* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
72858c2ecf20Sopenharmony_ci			 * MSB (bit15) goes to 1 (indicating that the XAUI
72868c2ecf20Sopenharmony_ci			 * workaround has completed), then continue on with
72878c2ecf20Sopenharmony_ci			 * system initialization.
72888c2ecf20Sopenharmony_ci			 */
72898c2ecf20Sopenharmony_ci			for (cnt1 = 0; cnt1 < 1000; cnt1++) {
72908c2ecf20Sopenharmony_ci				bnx2x_cl45_read(bp, phy,
72918c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
72928c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8073_XAUI_WA, &val);
72938c2ecf20Sopenharmony_ci				if (val & (1<<15)) {
72948c2ecf20Sopenharmony_ci					DP(NETIF_MSG_LINK,
72958c2ecf20Sopenharmony_ci					  "XAUI workaround has completed\n");
72968c2ecf20Sopenharmony_ci					return 0;
72978c2ecf20Sopenharmony_ci				}
72988c2ecf20Sopenharmony_ci				usleep_range(3000, 6000);
72998c2ecf20Sopenharmony_ci			}
73008c2ecf20Sopenharmony_ci			break;
73018c2ecf20Sopenharmony_ci		}
73028c2ecf20Sopenharmony_ci		usleep_range(3000, 6000);
73038c2ecf20Sopenharmony_ci	}
73048c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
73058c2ecf20Sopenharmony_ci	return -EINVAL;
73068c2ecf20Sopenharmony_ci}
73078c2ecf20Sopenharmony_ci
73088c2ecf20Sopenharmony_cistatic void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
73098c2ecf20Sopenharmony_ci{
73108c2ecf20Sopenharmony_ci	/* Force KR or KX */
73118c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
73128c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
73138c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
73148c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
73158c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
73168c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
73178c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
73188c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
73198c2ecf20Sopenharmony_ci}
73208c2ecf20Sopenharmony_ci
73218c2ecf20Sopenharmony_cistatic void bnx2x_8073_set_pause_cl37(struct link_params *params,
73228c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
73238c2ecf20Sopenharmony_ci				      struct link_vars *vars)
73248c2ecf20Sopenharmony_ci{
73258c2ecf20Sopenharmony_ci	u16 cl37_val;
73268c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
73278c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
73288c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
73298c2ecf20Sopenharmony_ci
73308c2ecf20Sopenharmony_ci	cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
73318c2ecf20Sopenharmony_ci	/* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
73328c2ecf20Sopenharmony_ci	bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
73338c2ecf20Sopenharmony_ci	if ((vars->ieee_fc &
73348c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
73358c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
73368c2ecf20Sopenharmony_ci		cl37_val |=  MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
73378c2ecf20Sopenharmony_ci	}
73388c2ecf20Sopenharmony_ci	if ((vars->ieee_fc &
73398c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
73408c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
73418c2ecf20Sopenharmony_ci		cl37_val |=  MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
73428c2ecf20Sopenharmony_ci	}
73438c2ecf20Sopenharmony_ci	if ((vars->ieee_fc &
73448c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
73458c2ecf20Sopenharmony_ci	    MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
73468c2ecf20Sopenharmony_ci		cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
73478c2ecf20Sopenharmony_ci	}
73488c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK,
73498c2ecf20Sopenharmony_ci		 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
73508c2ecf20Sopenharmony_ci
73518c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
73528c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
73538c2ecf20Sopenharmony_ci	msleep(500);
73548c2ecf20Sopenharmony_ci}
73558c2ecf20Sopenharmony_ci
73568c2ecf20Sopenharmony_cistatic void bnx2x_8073_specific_func(struct bnx2x_phy *phy,
73578c2ecf20Sopenharmony_ci				     struct link_params *params,
73588c2ecf20Sopenharmony_ci				     u32 action)
73598c2ecf20Sopenharmony_ci{
73608c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
73618c2ecf20Sopenharmony_ci	switch (action) {
73628c2ecf20Sopenharmony_ci	case PHY_INIT:
73638c2ecf20Sopenharmony_ci		/* Enable LASI */
73648c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
73658c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
73668c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
73678c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,  0x0004);
73688c2ecf20Sopenharmony_ci		break;
73698c2ecf20Sopenharmony_ci	}
73708c2ecf20Sopenharmony_ci}
73718c2ecf20Sopenharmony_ci
73728c2ecf20Sopenharmony_cistatic void bnx2x_8073_config_init(struct bnx2x_phy *phy,
73738c2ecf20Sopenharmony_ci				   struct link_params *params,
73748c2ecf20Sopenharmony_ci				   struct link_vars *vars)
73758c2ecf20Sopenharmony_ci{
73768c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
73778c2ecf20Sopenharmony_ci	u16 val = 0, tmp1;
73788c2ecf20Sopenharmony_ci	u8 gpio_port;
73798c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Init 8073\n");
73808c2ecf20Sopenharmony_ci
73818c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
73828c2ecf20Sopenharmony_ci		gpio_port = BP_PATH(bp);
73838c2ecf20Sopenharmony_ci	else
73848c2ecf20Sopenharmony_ci		gpio_port = params->port;
73858c2ecf20Sopenharmony_ci	/* Restore normal power mode*/
73868c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
73878c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
73888c2ecf20Sopenharmony_ci
73898c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
73908c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
73918c2ecf20Sopenharmony_ci
73928c2ecf20Sopenharmony_ci	bnx2x_8073_specific_func(phy, params, PHY_INIT);
73938c2ecf20Sopenharmony_ci	bnx2x_8073_set_pause_cl37(params, phy, vars);
73948c2ecf20Sopenharmony_ci
73958c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
73968c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
73978c2ecf20Sopenharmony_ci
73988c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
73998c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
74008c2ecf20Sopenharmony_ci
74018c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
74028c2ecf20Sopenharmony_ci
74038c2ecf20Sopenharmony_ci	/* Swap polarity if required - Must be done only in non-1G mode */
74048c2ecf20Sopenharmony_ci	if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
74058c2ecf20Sopenharmony_ci		/* Configure the 8073 to swap _P and _N of the KR lines */
74068c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
74078c2ecf20Sopenharmony_ci		/* 10G Rx/Tx and 1G Tx signal polarity swap */
74088c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
74098c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
74108c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
74118c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
74128c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
74138c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
74148c2ecf20Sopenharmony_ci				 (val | (3<<9)));
74158c2ecf20Sopenharmony_ci	}
74168c2ecf20Sopenharmony_ci
74178c2ecf20Sopenharmony_ci
74188c2ecf20Sopenharmony_ci	/* Enable CL37 BAM */
74198c2ecf20Sopenharmony_ci	if (REG_RD(bp, params->shmem_base +
74208c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region, dev_info.
74218c2ecf20Sopenharmony_ci				  port_hw_config[params->port].default_cfg)) &
74228c2ecf20Sopenharmony_ci	    PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
74238c2ecf20Sopenharmony_ci
74248c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
74258c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
74268c2ecf20Sopenharmony_ci				MDIO_AN_REG_8073_BAM, &val);
74278c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
74288c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD,
74298c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8073_BAM, val | 1);
74308c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
74318c2ecf20Sopenharmony_ci	}
74328c2ecf20Sopenharmony_ci	if (params->loopback_mode == LOOPBACK_EXT) {
74338c2ecf20Sopenharmony_ci		bnx2x_807x_force_10G(bp, phy);
74348c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
74358c2ecf20Sopenharmony_ci		return;
74368c2ecf20Sopenharmony_ci	} else {
74378c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
74388c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
74398c2ecf20Sopenharmony_ci	}
74408c2ecf20Sopenharmony_ci	if (phy->req_line_speed != SPEED_AUTO_NEG) {
74418c2ecf20Sopenharmony_ci		if (phy->req_line_speed == SPEED_10000) {
74428c2ecf20Sopenharmony_ci			val = (1<<7);
74438c2ecf20Sopenharmony_ci		} else if (phy->req_line_speed ==  SPEED_2500) {
74448c2ecf20Sopenharmony_ci			val = (1<<5);
74458c2ecf20Sopenharmony_ci			/* Note that 2.5G works only when used with 1G
74468c2ecf20Sopenharmony_ci			 * advertisement
74478c2ecf20Sopenharmony_ci			 */
74488c2ecf20Sopenharmony_ci		} else
74498c2ecf20Sopenharmony_ci			val = (1<<5);
74508c2ecf20Sopenharmony_ci	} else {
74518c2ecf20Sopenharmony_ci		val = 0;
74528c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
74538c2ecf20Sopenharmony_ci			PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
74548c2ecf20Sopenharmony_ci			val |= (1<<7);
74558c2ecf20Sopenharmony_ci
74568c2ecf20Sopenharmony_ci		/* Note that 2.5G works only when used with 1G advertisement */
74578c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
74588c2ecf20Sopenharmony_ci			(PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
74598c2ecf20Sopenharmony_ci			 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
74608c2ecf20Sopenharmony_ci			val |= (1<<5);
74618c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
74628c2ecf20Sopenharmony_ci	}
74638c2ecf20Sopenharmony_ci
74648c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
74658c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
74668c2ecf20Sopenharmony_ci
74678c2ecf20Sopenharmony_ci	if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
74688c2ecf20Sopenharmony_ci	     (phy->req_line_speed == SPEED_AUTO_NEG)) ||
74698c2ecf20Sopenharmony_ci	    (phy->req_line_speed == SPEED_2500)) {
74708c2ecf20Sopenharmony_ci		u16 phy_ver;
74718c2ecf20Sopenharmony_ci		/* Allow 2.5G for A1 and above */
74728c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
74738c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
74748c2ecf20Sopenharmony_ci				&phy_ver);
74758c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Add 2.5G\n");
74768c2ecf20Sopenharmony_ci		if (phy_ver > 0)
74778c2ecf20Sopenharmony_ci			tmp1 |= 1;
74788c2ecf20Sopenharmony_ci		else
74798c2ecf20Sopenharmony_ci			tmp1 &= 0xfffe;
74808c2ecf20Sopenharmony_ci	} else {
74818c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Disable 2.5G\n");
74828c2ecf20Sopenharmony_ci		tmp1 &= 0xfffe;
74838c2ecf20Sopenharmony_ci	}
74848c2ecf20Sopenharmony_ci
74858c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
74868c2ecf20Sopenharmony_ci	/* Add support for CL37 (passive mode) II */
74878c2ecf20Sopenharmony_ci
74888c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
74898c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
74908c2ecf20Sopenharmony_ci			 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
74918c2ecf20Sopenharmony_ci				  0x20 : 0x40)));
74928c2ecf20Sopenharmony_ci
74938c2ecf20Sopenharmony_ci	/* Add support for CL37 (passive mode) III */
74948c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
74958c2ecf20Sopenharmony_ci
74968c2ecf20Sopenharmony_ci	/* The SNR will improve about 2db by changing BW and FEE main
74978c2ecf20Sopenharmony_ci	 * tap. Rest commands are executed after link is up
74988c2ecf20Sopenharmony_ci	 * Change FFE main cursor to 5 in EDC register
74998c2ecf20Sopenharmony_ci	 */
75008c2ecf20Sopenharmony_ci	if (bnx2x_8073_is_snr_needed(bp, phy))
75018c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
75028c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
75038c2ecf20Sopenharmony_ci				 0xFB0C);
75048c2ecf20Sopenharmony_ci
75058c2ecf20Sopenharmony_ci	/* Enable FEC (Forware Error Correction) Request in the AN */
75068c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
75078c2ecf20Sopenharmony_ci	tmp1 |= (1<<15);
75088c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
75098c2ecf20Sopenharmony_ci
75108c2ecf20Sopenharmony_ci	bnx2x_ext_phy_set_pause(params, phy, vars);
75118c2ecf20Sopenharmony_ci
75128c2ecf20Sopenharmony_ci	/* Restart autoneg */
75138c2ecf20Sopenharmony_ci	msleep(500);
75148c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
75158c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
75168c2ecf20Sopenharmony_ci		   ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
75178c2ecf20Sopenharmony_ci}
75188c2ecf20Sopenharmony_ci
75198c2ecf20Sopenharmony_cistatic u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
75208c2ecf20Sopenharmony_ci				 struct link_params *params,
75218c2ecf20Sopenharmony_ci				 struct link_vars *vars)
75228c2ecf20Sopenharmony_ci{
75238c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
75248c2ecf20Sopenharmony_ci	u8 link_up = 0;
75258c2ecf20Sopenharmony_ci	u16 val1, val2;
75268c2ecf20Sopenharmony_ci	u16 link_status = 0;
75278c2ecf20Sopenharmony_ci	u16 an1000_status = 0;
75288c2ecf20Sopenharmony_ci
75298c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75308c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
75318c2ecf20Sopenharmony_ci
75328c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
75338c2ecf20Sopenharmony_ci
75348c2ecf20Sopenharmony_ci	/* Clear the interrupt LASI status register */
75358c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75368c2ecf20Sopenharmony_ci			MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
75378c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75388c2ecf20Sopenharmony_ci			MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
75398c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
75408c2ecf20Sopenharmony_ci	/* Clear MSG-OUT */
75418c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75428c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
75438c2ecf20Sopenharmony_ci
75448c2ecf20Sopenharmony_ci	/* Check the LASI */
75458c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75468c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
75478c2ecf20Sopenharmony_ci
75488c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
75498c2ecf20Sopenharmony_ci
75508c2ecf20Sopenharmony_ci	/* Check the link status */
75518c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75528c2ecf20Sopenharmony_ci			MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
75538c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
75548c2ecf20Sopenharmony_ci
75558c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75568c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
75578c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75588c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
75598c2ecf20Sopenharmony_ci	link_up = ((val1 & 4) == 4);
75608c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
75618c2ecf20Sopenharmony_ci
75628c2ecf20Sopenharmony_ci	if (link_up &&
75638c2ecf20Sopenharmony_ci	     ((phy->req_line_speed != SPEED_10000))) {
75648c2ecf20Sopenharmony_ci		if (bnx2x_8073_xaui_wa(bp, phy) != 0)
75658c2ecf20Sopenharmony_ci			return 0;
75668c2ecf20Sopenharmony_ci	}
75678c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75688c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
75698c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75708c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
75718c2ecf20Sopenharmony_ci
75728c2ecf20Sopenharmony_ci	/* Check the link status on 1.1.2 */
75738c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75748c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
75758c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75768c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
75778c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
75788c2ecf20Sopenharmony_ci		   "an_link_status=0x%x\n", val2, val1, an1000_status);
75798c2ecf20Sopenharmony_ci
75808c2ecf20Sopenharmony_ci	link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
75818c2ecf20Sopenharmony_ci	if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
75828c2ecf20Sopenharmony_ci		/* The SNR will improve about 2dbby changing the BW and FEE main
75838c2ecf20Sopenharmony_ci		 * tap. The 1st write to change FFE main tap is set before
75848c2ecf20Sopenharmony_ci		 * restart AN. Change PLL Bandwidth in EDC register
75858c2ecf20Sopenharmony_ci		 */
75868c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
75878c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
75888c2ecf20Sopenharmony_ci				 0x26BC);
75898c2ecf20Sopenharmony_ci
75908c2ecf20Sopenharmony_ci		/* Change CDR Bandwidth in EDC register */
75918c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
75928c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
75938c2ecf20Sopenharmony_ci				 0x0333);
75948c2ecf20Sopenharmony_ci	}
75958c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
75968c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
75978c2ecf20Sopenharmony_ci			&link_status);
75988c2ecf20Sopenharmony_ci
75998c2ecf20Sopenharmony_ci	/* Bits 0..2 --> speed detected, bits 13..15--> link is down */
76008c2ecf20Sopenharmony_ci	if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
76018c2ecf20Sopenharmony_ci		link_up = 1;
76028c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
76038c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
76048c2ecf20Sopenharmony_ci			   params->port);
76058c2ecf20Sopenharmony_ci	} else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
76068c2ecf20Sopenharmony_ci		link_up = 1;
76078c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_2500;
76088c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
76098c2ecf20Sopenharmony_ci			   params->port);
76108c2ecf20Sopenharmony_ci	} else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
76118c2ecf20Sopenharmony_ci		link_up = 1;
76128c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_1000;
76138c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
76148c2ecf20Sopenharmony_ci			   params->port);
76158c2ecf20Sopenharmony_ci	} else {
76168c2ecf20Sopenharmony_ci		link_up = 0;
76178c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link is down\n",
76188c2ecf20Sopenharmony_ci			   params->port);
76198c2ecf20Sopenharmony_ci	}
76208c2ecf20Sopenharmony_ci
76218c2ecf20Sopenharmony_ci	if (link_up) {
76228c2ecf20Sopenharmony_ci		/* Swap polarity if required */
76238c2ecf20Sopenharmony_ci		if (params->lane_config &
76248c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
76258c2ecf20Sopenharmony_ci			/* Configure the 8073 to swap P and N of the KR lines */
76268c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
76278c2ecf20Sopenharmony_ci					MDIO_XS_DEVAD,
76288c2ecf20Sopenharmony_ci					MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
76298c2ecf20Sopenharmony_ci			/* Set bit 3 to invert Rx in 1G mode and clear this bit
76308c2ecf20Sopenharmony_ci			 * when it`s in 10G mode.
76318c2ecf20Sopenharmony_ci			 */
76328c2ecf20Sopenharmony_ci			if (vars->line_speed == SPEED_1000) {
76338c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
76348c2ecf20Sopenharmony_ci					      "the 8073\n");
76358c2ecf20Sopenharmony_ci				val1 |= (1<<3);
76368c2ecf20Sopenharmony_ci			} else
76378c2ecf20Sopenharmony_ci				val1 &= ~(1<<3);
76388c2ecf20Sopenharmony_ci
76398c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
76408c2ecf20Sopenharmony_ci					 MDIO_XS_DEVAD,
76418c2ecf20Sopenharmony_ci					 MDIO_XS_REG_8073_RX_CTRL_PCIE,
76428c2ecf20Sopenharmony_ci					 val1);
76438c2ecf20Sopenharmony_ci		}
76448c2ecf20Sopenharmony_ci		bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
76458c2ecf20Sopenharmony_ci		bnx2x_8073_resolve_fc(phy, params, vars);
76468c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
76478c2ecf20Sopenharmony_ci	}
76488c2ecf20Sopenharmony_ci
76498c2ecf20Sopenharmony_ci	if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
76508c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
76518c2ecf20Sopenharmony_ci				MDIO_AN_REG_LP_AUTO_NEG2, &val1);
76528c2ecf20Sopenharmony_ci
76538c2ecf20Sopenharmony_ci		if (val1 & (1<<5))
76548c2ecf20Sopenharmony_ci			vars->link_status |=
76558c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
76568c2ecf20Sopenharmony_ci		if (val1 & (1<<7))
76578c2ecf20Sopenharmony_ci			vars->link_status |=
76588c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
76598c2ecf20Sopenharmony_ci	}
76608c2ecf20Sopenharmony_ci
76618c2ecf20Sopenharmony_ci	return link_up;
76628c2ecf20Sopenharmony_ci}
76638c2ecf20Sopenharmony_ci
76648c2ecf20Sopenharmony_cistatic void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
76658c2ecf20Sopenharmony_ci				  struct link_params *params)
76668c2ecf20Sopenharmony_ci{
76678c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
76688c2ecf20Sopenharmony_ci	u8 gpio_port;
76698c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
76708c2ecf20Sopenharmony_ci		gpio_port = BP_PATH(bp);
76718c2ecf20Sopenharmony_ci	else
76728c2ecf20Sopenharmony_ci		gpio_port = params->port;
76738c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
76748c2ecf20Sopenharmony_ci	   gpio_port);
76758c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
76768c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW,
76778c2ecf20Sopenharmony_ci		       gpio_port);
76788c2ecf20Sopenharmony_ci}
76798c2ecf20Sopenharmony_ci
76808c2ecf20Sopenharmony_ci/******************************************************************/
76818c2ecf20Sopenharmony_ci/*			BCM8705 PHY SECTION			  */
76828c2ecf20Sopenharmony_ci/******************************************************************/
76838c2ecf20Sopenharmony_cistatic void bnx2x_8705_config_init(struct bnx2x_phy *phy,
76848c2ecf20Sopenharmony_ci				   struct link_params *params,
76858c2ecf20Sopenharmony_ci				   struct link_vars *vars)
76868c2ecf20Sopenharmony_ci{
76878c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
76888c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "init 8705\n");
76898c2ecf20Sopenharmony_ci	/* Restore normal power mode*/
76908c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
76918c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
76928c2ecf20Sopenharmony_ci	/* HW reset */
76938c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, params->port);
76948c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
76958c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
76968c2ecf20Sopenharmony_ci
76978c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
76988c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
76998c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
77008c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
77018c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
77028c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
77038c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
77048c2ecf20Sopenharmony_ci			 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
77058c2ecf20Sopenharmony_ci	/* BCM8705 doesn't have microcode, hence the 0 */
77068c2ecf20Sopenharmony_ci	bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
77078c2ecf20Sopenharmony_ci}
77088c2ecf20Sopenharmony_ci
77098c2ecf20Sopenharmony_cistatic u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
77108c2ecf20Sopenharmony_ci				 struct link_params *params,
77118c2ecf20Sopenharmony_ci				 struct link_vars *vars)
77128c2ecf20Sopenharmony_ci{
77138c2ecf20Sopenharmony_ci	u8 link_up = 0;
77148c2ecf20Sopenharmony_ci	u16 val1, rx_sd;
77158c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
77168c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "read status 8705\n");
77178c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
77188c2ecf20Sopenharmony_ci		      MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
77198c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
77208c2ecf20Sopenharmony_ci
77218c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
77228c2ecf20Sopenharmony_ci		      MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
77238c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
77248c2ecf20Sopenharmony_ci
77258c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
77268c2ecf20Sopenharmony_ci		      MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
77278c2ecf20Sopenharmony_ci
77288c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
77298c2ecf20Sopenharmony_ci		      MDIO_PMA_DEVAD, 0xc809, &val1);
77308c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
77318c2ecf20Sopenharmony_ci		      MDIO_PMA_DEVAD, 0xc809, &val1);
77328c2ecf20Sopenharmony_ci
77338c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
77348c2ecf20Sopenharmony_ci	link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
77358c2ecf20Sopenharmony_ci	if (link_up) {
77368c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
77378c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
77388c2ecf20Sopenharmony_ci	}
77398c2ecf20Sopenharmony_ci	return link_up;
77408c2ecf20Sopenharmony_ci}
77418c2ecf20Sopenharmony_ci
77428c2ecf20Sopenharmony_ci/******************************************************************/
77438c2ecf20Sopenharmony_ci/*			SFP+ module Section			  */
77448c2ecf20Sopenharmony_ci/******************************************************************/
77458c2ecf20Sopenharmony_cistatic void bnx2x_set_disable_pmd_transmit(struct link_params *params,
77468c2ecf20Sopenharmony_ci					   struct bnx2x_phy *phy,
77478c2ecf20Sopenharmony_ci					   u8 pmd_dis)
77488c2ecf20Sopenharmony_ci{
77498c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
77508c2ecf20Sopenharmony_ci	/* Disable transmitter only for bootcodes which can enable it afterwards
77518c2ecf20Sopenharmony_ci	 * (for D3 link)
77528c2ecf20Sopenharmony_ci	 */
77538c2ecf20Sopenharmony_ci	if (pmd_dis) {
77548c2ecf20Sopenharmony_ci		if (params->feature_config_flags &
77558c2ecf20Sopenharmony_ci		     FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
77568c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
77578c2ecf20Sopenharmony_ci		else {
77588c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
77598c2ecf20Sopenharmony_ci			return;
77608c2ecf20Sopenharmony_ci		}
77618c2ecf20Sopenharmony_ci	} else
77628c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
77638c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
77648c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
77658c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_TX_DISABLE, pmd_dis);
77668c2ecf20Sopenharmony_ci}
77678c2ecf20Sopenharmony_ci
77688c2ecf20Sopenharmony_cistatic u8 bnx2x_get_gpio_port(struct link_params *params)
77698c2ecf20Sopenharmony_ci{
77708c2ecf20Sopenharmony_ci	u8 gpio_port;
77718c2ecf20Sopenharmony_ci	u32 swap_val, swap_override;
77728c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
77738c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
77748c2ecf20Sopenharmony_ci		gpio_port = BP_PATH(bp);
77758c2ecf20Sopenharmony_ci	else
77768c2ecf20Sopenharmony_ci		gpio_port = params->port;
77778c2ecf20Sopenharmony_ci	swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
77788c2ecf20Sopenharmony_ci	swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
77798c2ecf20Sopenharmony_ci	return gpio_port ^ (swap_val && swap_override);
77808c2ecf20Sopenharmony_ci}
77818c2ecf20Sopenharmony_ci
77828c2ecf20Sopenharmony_cistatic void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
77838c2ecf20Sopenharmony_ci					   struct bnx2x_phy *phy,
77848c2ecf20Sopenharmony_ci					   u8 tx_en)
77858c2ecf20Sopenharmony_ci{
77868c2ecf20Sopenharmony_ci	u16 val;
77878c2ecf20Sopenharmony_ci	u8 port = params->port;
77888c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
77898c2ecf20Sopenharmony_ci	u32 tx_en_mode;
77908c2ecf20Sopenharmony_ci
77918c2ecf20Sopenharmony_ci	/* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
77928c2ecf20Sopenharmony_ci	tx_en_mode = REG_RD(bp, params->shmem_base +
77938c2ecf20Sopenharmony_ci			    offsetof(struct shmem_region,
77948c2ecf20Sopenharmony_ci				     dev_info.port_hw_config[port].sfp_ctrl)) &
77958c2ecf20Sopenharmony_ci		PORT_HW_CFG_TX_LASER_MASK;
77968c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
77978c2ecf20Sopenharmony_ci			   "mode = %x\n", tx_en, port, tx_en_mode);
77988c2ecf20Sopenharmony_ci	switch (tx_en_mode) {
77998c2ecf20Sopenharmony_ci	case PORT_HW_CFG_TX_LASER_MDIO:
78008c2ecf20Sopenharmony_ci
78018c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
78028c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
78038c2ecf20Sopenharmony_ci				MDIO_PMA_REG_PHY_IDENTIFIER,
78048c2ecf20Sopenharmony_ci				&val);
78058c2ecf20Sopenharmony_ci
78068c2ecf20Sopenharmony_ci		if (tx_en)
78078c2ecf20Sopenharmony_ci			val &= ~(1<<15);
78088c2ecf20Sopenharmony_ci		else
78098c2ecf20Sopenharmony_ci			val |= (1<<15);
78108c2ecf20Sopenharmony_ci
78118c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
78128c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
78138c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_PHY_IDENTIFIER,
78148c2ecf20Sopenharmony_ci				 val);
78158c2ecf20Sopenharmony_ci	break;
78168c2ecf20Sopenharmony_ci	case PORT_HW_CFG_TX_LASER_GPIO0:
78178c2ecf20Sopenharmony_ci	case PORT_HW_CFG_TX_LASER_GPIO1:
78188c2ecf20Sopenharmony_ci	case PORT_HW_CFG_TX_LASER_GPIO2:
78198c2ecf20Sopenharmony_ci	case PORT_HW_CFG_TX_LASER_GPIO3:
78208c2ecf20Sopenharmony_ci	{
78218c2ecf20Sopenharmony_ci		u16 gpio_pin;
78228c2ecf20Sopenharmony_ci		u8 gpio_port, gpio_mode;
78238c2ecf20Sopenharmony_ci		if (tx_en)
78248c2ecf20Sopenharmony_ci			gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
78258c2ecf20Sopenharmony_ci		else
78268c2ecf20Sopenharmony_ci			gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
78278c2ecf20Sopenharmony_ci
78288c2ecf20Sopenharmony_ci		gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
78298c2ecf20Sopenharmony_ci		gpio_port = bnx2x_get_gpio_port(params);
78308c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
78318c2ecf20Sopenharmony_ci		break;
78328c2ecf20Sopenharmony_ci	}
78338c2ecf20Sopenharmony_ci	default:
78348c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
78358c2ecf20Sopenharmony_ci		break;
78368c2ecf20Sopenharmony_ci	}
78378c2ecf20Sopenharmony_ci}
78388c2ecf20Sopenharmony_ci
78398c2ecf20Sopenharmony_cistatic void bnx2x_sfp_set_transmitter(struct link_params *params,
78408c2ecf20Sopenharmony_ci				      struct bnx2x_phy *phy,
78418c2ecf20Sopenharmony_ci				      u8 tx_en)
78428c2ecf20Sopenharmony_ci{
78438c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
78448c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
78458c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp))
78468c2ecf20Sopenharmony_ci		bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
78478c2ecf20Sopenharmony_ci	else
78488c2ecf20Sopenharmony_ci		bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
78498c2ecf20Sopenharmony_ci}
78508c2ecf20Sopenharmony_ci
78518c2ecf20Sopenharmony_cistatic int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
78528c2ecf20Sopenharmony_ci					     struct link_params *params,
78538c2ecf20Sopenharmony_ci					     u8 dev_addr, u16 addr, u8 byte_cnt,
78548c2ecf20Sopenharmony_ci					     u8 *o_buf, u8 is_init)
78558c2ecf20Sopenharmony_ci{
78568c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
78578c2ecf20Sopenharmony_ci	u16 val = 0;
78588c2ecf20Sopenharmony_ci	u16 i;
78598c2ecf20Sopenharmony_ci	if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
78608c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
78618c2ecf20Sopenharmony_ci		   "Reading from eeprom is limited to 0xf\n");
78628c2ecf20Sopenharmony_ci		return -EINVAL;
78638c2ecf20Sopenharmony_ci	}
78648c2ecf20Sopenharmony_ci	/* Set the read command byte count */
78658c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
78668c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
78678c2ecf20Sopenharmony_ci			 (byte_cnt | (dev_addr << 8)));
78688c2ecf20Sopenharmony_ci
78698c2ecf20Sopenharmony_ci	/* Set the read command address */
78708c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
78718c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
78728c2ecf20Sopenharmony_ci			 addr);
78738c2ecf20Sopenharmony_ci
78748c2ecf20Sopenharmony_ci	/* Activate read command */
78758c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
78768c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
78778c2ecf20Sopenharmony_ci			 0x2c0f);
78788c2ecf20Sopenharmony_ci
78798c2ecf20Sopenharmony_ci	/* Wait up to 500us for command complete status */
78808c2ecf20Sopenharmony_ci	for (i = 0; i < 100; i++) {
78818c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
78828c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
78838c2ecf20Sopenharmony_ci				MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
78848c2ecf20Sopenharmony_ci		if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
78858c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
78868c2ecf20Sopenharmony_ci			break;
78878c2ecf20Sopenharmony_ci		udelay(5);
78888c2ecf20Sopenharmony_ci	}
78898c2ecf20Sopenharmony_ci
78908c2ecf20Sopenharmony_ci	if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
78918c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
78928c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
78938c2ecf20Sopenharmony_ci			 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
78948c2ecf20Sopenharmony_ci			 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
78958c2ecf20Sopenharmony_ci		return -EINVAL;
78968c2ecf20Sopenharmony_ci	}
78978c2ecf20Sopenharmony_ci
78988c2ecf20Sopenharmony_ci	/* Read the buffer */
78998c2ecf20Sopenharmony_ci	for (i = 0; i < byte_cnt; i++) {
79008c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
79018c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
79028c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
79038c2ecf20Sopenharmony_ci		o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
79048c2ecf20Sopenharmony_ci	}
79058c2ecf20Sopenharmony_ci
79068c2ecf20Sopenharmony_ci	for (i = 0; i < 100; i++) {
79078c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
79088c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
79098c2ecf20Sopenharmony_ci				MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
79108c2ecf20Sopenharmony_ci		if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
79118c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
79128c2ecf20Sopenharmony_ci			return 0;
79138c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
79148c2ecf20Sopenharmony_ci	}
79158c2ecf20Sopenharmony_ci	return -EINVAL;
79168c2ecf20Sopenharmony_ci}
79178c2ecf20Sopenharmony_ci
79188c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_power_module(struct link_params *params,
79198c2ecf20Sopenharmony_ci					u8 power)
79208c2ecf20Sopenharmony_ci{
79218c2ecf20Sopenharmony_ci	u32 pin_cfg;
79228c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
79238c2ecf20Sopenharmony_ci
79248c2ecf20Sopenharmony_ci	pin_cfg = (REG_RD(bp, params->shmem_base +
79258c2ecf20Sopenharmony_ci			  offsetof(struct shmem_region,
79268c2ecf20Sopenharmony_ci			dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
79278c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PWR_DIS_MASK) >>
79288c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PWR_DIS_SHIFT;
79298c2ecf20Sopenharmony_ci
79308c2ecf20Sopenharmony_ci	if (pin_cfg == PIN_CFG_NA)
79318c2ecf20Sopenharmony_ci		return;
79328c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
79338c2ecf20Sopenharmony_ci		       power, pin_cfg);
79348c2ecf20Sopenharmony_ci	/* Low ==> corresponding SFP+ module is powered
79358c2ecf20Sopenharmony_ci	 * high ==> the SFP+ module is powered down
79368c2ecf20Sopenharmony_ci	 */
79378c2ecf20Sopenharmony_ci	bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
79388c2ecf20Sopenharmony_ci}
79398c2ecf20Sopenharmony_cistatic int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
79408c2ecf20Sopenharmony_ci						 struct link_params *params,
79418c2ecf20Sopenharmony_ci						 u8 dev_addr,
79428c2ecf20Sopenharmony_ci						 u16 addr, u8 byte_cnt,
79438c2ecf20Sopenharmony_ci						 u8 *o_buf, u8 is_init)
79448c2ecf20Sopenharmony_ci{
79458c2ecf20Sopenharmony_ci	int rc = 0;
79468c2ecf20Sopenharmony_ci	u8 i, j = 0, cnt = 0;
79478c2ecf20Sopenharmony_ci	u32 data_array[4];
79488c2ecf20Sopenharmony_ci	u16 addr32;
79498c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
79508c2ecf20Sopenharmony_ci
79518c2ecf20Sopenharmony_ci	if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
79528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
79538c2ecf20Sopenharmony_ci		   "Reading from eeprom is limited to 16 bytes\n");
79548c2ecf20Sopenharmony_ci		return -EINVAL;
79558c2ecf20Sopenharmony_ci	}
79568c2ecf20Sopenharmony_ci
79578c2ecf20Sopenharmony_ci	/* 4 byte aligned address */
79588c2ecf20Sopenharmony_ci	addr32 = addr & (~0x3);
79598c2ecf20Sopenharmony_ci	do {
79608c2ecf20Sopenharmony_ci		if ((!is_init) && (cnt == I2C_WA_PWR_ITER)) {
79618c2ecf20Sopenharmony_ci			bnx2x_warpcore_power_module(params, 0);
79628c2ecf20Sopenharmony_ci			/* Note that 100us are not enough here */
79638c2ecf20Sopenharmony_ci			usleep_range(1000, 2000);
79648c2ecf20Sopenharmony_ci			bnx2x_warpcore_power_module(params, 1);
79658c2ecf20Sopenharmony_ci		}
79668c2ecf20Sopenharmony_ci		rc = bnx2x_bsc_read(params, bp, dev_addr, addr32, 0, byte_cnt,
79678c2ecf20Sopenharmony_ci				    data_array);
79688c2ecf20Sopenharmony_ci	} while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
79698c2ecf20Sopenharmony_ci
79708c2ecf20Sopenharmony_ci	if (rc == 0) {
79718c2ecf20Sopenharmony_ci		for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
79728c2ecf20Sopenharmony_ci			o_buf[j] = *((u8 *)data_array + i);
79738c2ecf20Sopenharmony_ci			j++;
79748c2ecf20Sopenharmony_ci		}
79758c2ecf20Sopenharmony_ci	}
79768c2ecf20Sopenharmony_ci
79778c2ecf20Sopenharmony_ci	return rc;
79788c2ecf20Sopenharmony_ci}
79798c2ecf20Sopenharmony_ci
79808c2ecf20Sopenharmony_cistatic int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
79818c2ecf20Sopenharmony_ci					     struct link_params *params,
79828c2ecf20Sopenharmony_ci					     u8 dev_addr, u16 addr, u8 byte_cnt,
79838c2ecf20Sopenharmony_ci					     u8 *o_buf, u8 is_init)
79848c2ecf20Sopenharmony_ci{
79858c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
79868c2ecf20Sopenharmony_ci	u16 val, i;
79878c2ecf20Sopenharmony_ci
79888c2ecf20Sopenharmony_ci	if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
79898c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
79908c2ecf20Sopenharmony_ci		   "Reading from eeprom is limited to 0xf\n");
79918c2ecf20Sopenharmony_ci		return -EINVAL;
79928c2ecf20Sopenharmony_ci	}
79938c2ecf20Sopenharmony_ci
79948c2ecf20Sopenharmony_ci	/* Set 2-wire transfer rate of SFP+ module EEPROM
79958c2ecf20Sopenharmony_ci	 * to 100Khz since some DACs(direct attached cables) do
79968c2ecf20Sopenharmony_ci	 * not work at 400Khz.
79978c2ecf20Sopenharmony_ci	 */
79988c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
79998c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
80008c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
80018c2ecf20Sopenharmony_ci			 ((dev_addr << 8) | 1));
80028c2ecf20Sopenharmony_ci
80038c2ecf20Sopenharmony_ci	/* Need to read from 1.8000 to clear it */
80048c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
80058c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
80068c2ecf20Sopenharmony_ci			MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
80078c2ecf20Sopenharmony_ci			&val);
80088c2ecf20Sopenharmony_ci
80098c2ecf20Sopenharmony_ci	/* Set the read command byte count */
80108c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
80118c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
80128c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
80138c2ecf20Sopenharmony_ci			 ((byte_cnt < 2) ? 2 : byte_cnt));
80148c2ecf20Sopenharmony_ci
80158c2ecf20Sopenharmony_ci	/* Set the read command address */
80168c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
80178c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
80188c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
80198c2ecf20Sopenharmony_ci			 addr);
80208c2ecf20Sopenharmony_ci	/* Set the destination address */
80218c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
80228c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
80238c2ecf20Sopenharmony_ci			 0x8004,
80248c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
80258c2ecf20Sopenharmony_ci
80268c2ecf20Sopenharmony_ci	/* Activate read command */
80278c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
80288c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
80298c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
80308c2ecf20Sopenharmony_ci			 0x8002);
80318c2ecf20Sopenharmony_ci	/* Wait appropriate time for two-wire command to finish before
80328c2ecf20Sopenharmony_ci	 * polling the status register
80338c2ecf20Sopenharmony_ci	 */
80348c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
80358c2ecf20Sopenharmony_ci
80368c2ecf20Sopenharmony_ci	/* Wait up to 500us for command complete status */
80378c2ecf20Sopenharmony_ci	for (i = 0; i < 100; i++) {
80388c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
80398c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
80408c2ecf20Sopenharmony_ci				MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
80418c2ecf20Sopenharmony_ci		if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
80428c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
80438c2ecf20Sopenharmony_ci			break;
80448c2ecf20Sopenharmony_ci		udelay(5);
80458c2ecf20Sopenharmony_ci	}
80468c2ecf20Sopenharmony_ci
80478c2ecf20Sopenharmony_ci	if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
80488c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
80498c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
80508c2ecf20Sopenharmony_ci			 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
80518c2ecf20Sopenharmony_ci			 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
80528c2ecf20Sopenharmony_ci		return -EFAULT;
80538c2ecf20Sopenharmony_ci	}
80548c2ecf20Sopenharmony_ci
80558c2ecf20Sopenharmony_ci	/* Read the buffer */
80568c2ecf20Sopenharmony_ci	for (i = 0; i < byte_cnt; i++) {
80578c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
80588c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
80598c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
80608c2ecf20Sopenharmony_ci		o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
80618c2ecf20Sopenharmony_ci	}
80628c2ecf20Sopenharmony_ci
80638c2ecf20Sopenharmony_ci	for (i = 0; i < 100; i++) {
80648c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
80658c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
80668c2ecf20Sopenharmony_ci				MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
80678c2ecf20Sopenharmony_ci		if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
80688c2ecf20Sopenharmony_ci		    MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
80698c2ecf20Sopenharmony_ci			return 0;
80708c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
80718c2ecf20Sopenharmony_ci	}
80728c2ecf20Sopenharmony_ci
80738c2ecf20Sopenharmony_ci	return -EINVAL;
80748c2ecf20Sopenharmony_ci}
80758c2ecf20Sopenharmony_ciint bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
80768c2ecf20Sopenharmony_ci				 struct link_params *params, u8 dev_addr,
80778c2ecf20Sopenharmony_ci				 u16 addr, u16 byte_cnt, u8 *o_buf)
80788c2ecf20Sopenharmony_ci{
80798c2ecf20Sopenharmony_ci	int rc = 0;
80808c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
80818c2ecf20Sopenharmony_ci	u8 xfer_size;
80828c2ecf20Sopenharmony_ci	u8 *user_data = o_buf;
80838c2ecf20Sopenharmony_ci	read_sfp_module_eeprom_func_p read_func;
80848c2ecf20Sopenharmony_ci
80858c2ecf20Sopenharmony_ci	if ((dev_addr != 0xa0) && (dev_addr != 0xa2)) {
80868c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "invalid dev_addr 0x%x\n", dev_addr);
80878c2ecf20Sopenharmony_ci		return -EINVAL;
80888c2ecf20Sopenharmony_ci	}
80898c2ecf20Sopenharmony_ci
80908c2ecf20Sopenharmony_ci	switch (phy->type) {
80918c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
80928c2ecf20Sopenharmony_ci		read_func = bnx2x_8726_read_sfp_module_eeprom;
80938c2ecf20Sopenharmony_ci		break;
80948c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
80958c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
80968c2ecf20Sopenharmony_ci		read_func = bnx2x_8727_read_sfp_module_eeprom;
80978c2ecf20Sopenharmony_ci		break;
80988c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
80998c2ecf20Sopenharmony_ci		read_func = bnx2x_warpcore_read_sfp_module_eeprom;
81008c2ecf20Sopenharmony_ci		break;
81018c2ecf20Sopenharmony_ci	default:
81028c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
81038c2ecf20Sopenharmony_ci	}
81048c2ecf20Sopenharmony_ci
81058c2ecf20Sopenharmony_ci	while (!rc && (byte_cnt > 0)) {
81068c2ecf20Sopenharmony_ci		xfer_size = (byte_cnt > SFP_EEPROM_PAGE_SIZE) ?
81078c2ecf20Sopenharmony_ci			SFP_EEPROM_PAGE_SIZE : byte_cnt;
81088c2ecf20Sopenharmony_ci		rc = read_func(phy, params, dev_addr, addr, xfer_size,
81098c2ecf20Sopenharmony_ci			       user_data, 0);
81108c2ecf20Sopenharmony_ci		byte_cnt -= xfer_size;
81118c2ecf20Sopenharmony_ci		user_data += xfer_size;
81128c2ecf20Sopenharmony_ci		addr += xfer_size;
81138c2ecf20Sopenharmony_ci	}
81148c2ecf20Sopenharmony_ci	return rc;
81158c2ecf20Sopenharmony_ci}
81168c2ecf20Sopenharmony_ci
81178c2ecf20Sopenharmony_cistatic int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
81188c2ecf20Sopenharmony_ci			      struct link_params *params,
81198c2ecf20Sopenharmony_ci			      u16 *edc_mode)
81208c2ecf20Sopenharmony_ci{
81218c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
81228c2ecf20Sopenharmony_ci	u32 sync_offset = 0, phy_idx, media_types;
81238c2ecf20Sopenharmony_ci	u8 val[SFP_EEPROM_FC_TX_TECH_ADDR + 1], check_limiting_mode = 0;
81248c2ecf20Sopenharmony_ci	*edc_mode = EDC_MODE_LIMITING;
81258c2ecf20Sopenharmony_ci	phy->media_type = ETH_PHY_UNSPECIFIED;
81268c2ecf20Sopenharmony_ci	/* First check for copper cable */
81278c2ecf20Sopenharmony_ci	if (bnx2x_read_sfp_module_eeprom(phy,
81288c2ecf20Sopenharmony_ci					 params,
81298c2ecf20Sopenharmony_ci					 I2C_DEV_ADDR_A0,
81308c2ecf20Sopenharmony_ci					 0,
81318c2ecf20Sopenharmony_ci					 SFP_EEPROM_FC_TX_TECH_ADDR + 1,
81328c2ecf20Sopenharmony_ci					 (u8 *)val) != 0) {
81338c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
81348c2ecf20Sopenharmony_ci		return -EINVAL;
81358c2ecf20Sopenharmony_ci	}
81368c2ecf20Sopenharmony_ci	params->link_attr_sync &= ~LINK_SFP_EEPROM_COMP_CODE_MASK;
81378c2ecf20Sopenharmony_ci	params->link_attr_sync |= val[SFP_EEPROM_10G_COMP_CODE_ADDR] <<
81388c2ecf20Sopenharmony_ci		LINK_SFP_EEPROM_COMP_CODE_SHIFT;
81398c2ecf20Sopenharmony_ci	bnx2x_update_link_attr(params, params->link_attr_sync);
81408c2ecf20Sopenharmony_ci	switch (val[SFP_EEPROM_CON_TYPE_ADDR]) {
81418c2ecf20Sopenharmony_ci	case SFP_EEPROM_CON_TYPE_VAL_COPPER:
81428c2ecf20Sopenharmony_ci	{
81438c2ecf20Sopenharmony_ci		u8 copper_module_type;
81448c2ecf20Sopenharmony_ci		phy->media_type = ETH_PHY_DA_TWINAX;
81458c2ecf20Sopenharmony_ci		/* Check if its active cable (includes SFP+ module)
81468c2ecf20Sopenharmony_ci		 * of passive cable
81478c2ecf20Sopenharmony_ci		 */
81488c2ecf20Sopenharmony_ci		copper_module_type = val[SFP_EEPROM_FC_TX_TECH_ADDR];
81498c2ecf20Sopenharmony_ci
81508c2ecf20Sopenharmony_ci		if (copper_module_type &
81518c2ecf20Sopenharmony_ci		    SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
81528c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
81538c2ecf20Sopenharmony_ci			if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
81548c2ecf20Sopenharmony_ci				*edc_mode = EDC_MODE_ACTIVE_DAC;
81558c2ecf20Sopenharmony_ci			else
81568c2ecf20Sopenharmony_ci				check_limiting_mode = 1;
81578c2ecf20Sopenharmony_ci		} else {
81588c2ecf20Sopenharmony_ci			*edc_mode = EDC_MODE_PASSIVE_DAC;
81598c2ecf20Sopenharmony_ci			/* Even in case PASSIVE_DAC indication is not set,
81608c2ecf20Sopenharmony_ci			 * treat it as a passive DAC cable, since some cables
81618c2ecf20Sopenharmony_ci			 * don't have this indication.
81628c2ecf20Sopenharmony_ci			 */
81638c2ecf20Sopenharmony_ci			if (copper_module_type &
81648c2ecf20Sopenharmony_ci			    SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
81658c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
81668c2ecf20Sopenharmony_ci				   "Passive Copper cable detected\n");
81678c2ecf20Sopenharmony_ci			} else {
81688c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK,
81698c2ecf20Sopenharmony_ci				   "Unknown copper-cable-type\n");
81708c2ecf20Sopenharmony_ci			}
81718c2ecf20Sopenharmony_ci		}
81728c2ecf20Sopenharmony_ci		break;
81738c2ecf20Sopenharmony_ci	}
81748c2ecf20Sopenharmony_ci	case SFP_EEPROM_CON_TYPE_VAL_UNKNOWN:
81758c2ecf20Sopenharmony_ci	case SFP_EEPROM_CON_TYPE_VAL_LC:
81768c2ecf20Sopenharmony_ci	case SFP_EEPROM_CON_TYPE_VAL_RJ45:
81778c2ecf20Sopenharmony_ci		check_limiting_mode = 1;
81788c2ecf20Sopenharmony_ci		if (((val[SFP_EEPROM_10G_COMP_CODE_ADDR] &
81798c2ecf20Sopenharmony_ci		     (SFP_EEPROM_10G_COMP_CODE_SR_MASK |
81808c2ecf20Sopenharmony_ci		      SFP_EEPROM_10G_COMP_CODE_LR_MASK |
81818c2ecf20Sopenharmony_ci		       SFP_EEPROM_10G_COMP_CODE_LRM_MASK)) == 0) &&
81828c2ecf20Sopenharmony_ci		    (val[SFP_EEPROM_1G_COMP_CODE_ADDR] != 0)) {
81838c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "1G SFP module detected\n");
81848c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_SFP_1G_FIBER;
81858c2ecf20Sopenharmony_ci			if (phy->req_line_speed != SPEED_1000) {
81868c2ecf20Sopenharmony_ci				u8 gport = params->port;
81878c2ecf20Sopenharmony_ci				phy->req_line_speed = SPEED_1000;
81888c2ecf20Sopenharmony_ci				if (!CHIP_IS_E1x(bp)) {
81898c2ecf20Sopenharmony_ci					gport = BP_PATH(bp) +
81908c2ecf20Sopenharmony_ci					(params->port << 1);
81918c2ecf20Sopenharmony_ci				}
81928c2ecf20Sopenharmony_ci				netdev_err(bp->dev,
81938c2ecf20Sopenharmony_ci					   "Warning: Link speed was forced to 1000Mbps. Current SFP module in port %d is not compliant with 10G Ethernet\n",
81948c2ecf20Sopenharmony_ci					   gport);
81958c2ecf20Sopenharmony_ci			}
81968c2ecf20Sopenharmony_ci			if (val[SFP_EEPROM_1G_COMP_CODE_ADDR] &
81978c2ecf20Sopenharmony_ci			    SFP_EEPROM_1G_COMP_CODE_BASE_T) {
81988c2ecf20Sopenharmony_ci				bnx2x_sfp_set_transmitter(params, phy, 0);
81998c2ecf20Sopenharmony_ci				msleep(40);
82008c2ecf20Sopenharmony_ci				bnx2x_sfp_set_transmitter(params, phy, 1);
82018c2ecf20Sopenharmony_ci			}
82028c2ecf20Sopenharmony_ci		} else {
82038c2ecf20Sopenharmony_ci			int idx, cfg_idx = 0;
82048c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "10G Optic module detected\n");
82058c2ecf20Sopenharmony_ci			for (idx = INT_PHY; idx < MAX_PHYS; idx++) {
82068c2ecf20Sopenharmony_ci				if (params->phy[idx].type == phy->type) {
82078c2ecf20Sopenharmony_ci					cfg_idx = LINK_CONFIG_IDX(idx);
82088c2ecf20Sopenharmony_ci					break;
82098c2ecf20Sopenharmony_ci				}
82108c2ecf20Sopenharmony_ci			}
82118c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_SFPP_10G_FIBER;
82128c2ecf20Sopenharmony_ci			phy->req_line_speed = params->req_line_speed[cfg_idx];
82138c2ecf20Sopenharmony_ci		}
82148c2ecf20Sopenharmony_ci		break;
82158c2ecf20Sopenharmony_ci	default:
82168c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
82178c2ecf20Sopenharmony_ci			 val[SFP_EEPROM_CON_TYPE_ADDR]);
82188c2ecf20Sopenharmony_ci		return -EINVAL;
82198c2ecf20Sopenharmony_ci	}
82208c2ecf20Sopenharmony_ci	sync_offset = params->shmem_base +
82218c2ecf20Sopenharmony_ci		offsetof(struct shmem_region,
82228c2ecf20Sopenharmony_ci			 dev_info.port_hw_config[params->port].media_type);
82238c2ecf20Sopenharmony_ci	media_types = REG_RD(bp, sync_offset);
82248c2ecf20Sopenharmony_ci	/* Update media type for non-PMF sync */
82258c2ecf20Sopenharmony_ci	for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
82268c2ecf20Sopenharmony_ci		if (&(params->phy[phy_idx]) == phy) {
82278c2ecf20Sopenharmony_ci			media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
82288c2ecf20Sopenharmony_ci				(PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
82298c2ecf20Sopenharmony_ci			media_types |= ((phy->media_type &
82308c2ecf20Sopenharmony_ci					PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
82318c2ecf20Sopenharmony_ci				(PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
82328c2ecf20Sopenharmony_ci			break;
82338c2ecf20Sopenharmony_ci		}
82348c2ecf20Sopenharmony_ci	}
82358c2ecf20Sopenharmony_ci	REG_WR(bp, sync_offset, media_types);
82368c2ecf20Sopenharmony_ci	if (check_limiting_mode) {
82378c2ecf20Sopenharmony_ci		u8 options[SFP_EEPROM_OPTIONS_SIZE];
82388c2ecf20Sopenharmony_ci		if (bnx2x_read_sfp_module_eeprom(phy,
82398c2ecf20Sopenharmony_ci						 params,
82408c2ecf20Sopenharmony_ci						 I2C_DEV_ADDR_A0,
82418c2ecf20Sopenharmony_ci						 SFP_EEPROM_OPTIONS_ADDR,
82428c2ecf20Sopenharmony_ci						 SFP_EEPROM_OPTIONS_SIZE,
82438c2ecf20Sopenharmony_ci						 options) != 0) {
82448c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
82458c2ecf20Sopenharmony_ci			   "Failed to read Option field from module EEPROM\n");
82468c2ecf20Sopenharmony_ci			return -EINVAL;
82478c2ecf20Sopenharmony_ci		}
82488c2ecf20Sopenharmony_ci		if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
82498c2ecf20Sopenharmony_ci			*edc_mode = EDC_MODE_LINEAR;
82508c2ecf20Sopenharmony_ci		else
82518c2ecf20Sopenharmony_ci			*edc_mode = EDC_MODE_LIMITING;
82528c2ecf20Sopenharmony_ci	}
82538c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
82548c2ecf20Sopenharmony_ci	return 0;
82558c2ecf20Sopenharmony_ci}
82568c2ecf20Sopenharmony_ci/* This function read the relevant field from the module (SFP+), and verify it
82578c2ecf20Sopenharmony_ci * is compliant with this board
82588c2ecf20Sopenharmony_ci */
82598c2ecf20Sopenharmony_cistatic int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
82608c2ecf20Sopenharmony_ci				   struct link_params *params)
82618c2ecf20Sopenharmony_ci{
82628c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
82638c2ecf20Sopenharmony_ci	u32 val, cmd;
82648c2ecf20Sopenharmony_ci	u32 fw_resp, fw_cmd_param;
82658c2ecf20Sopenharmony_ci	char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
82668c2ecf20Sopenharmony_ci	char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
82678c2ecf20Sopenharmony_ci	phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
82688c2ecf20Sopenharmony_ci	val = REG_RD(bp, params->shmem_base +
82698c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region, dev_info.
82708c2ecf20Sopenharmony_ci				  port_feature_config[params->port].config));
82718c2ecf20Sopenharmony_ci	if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
82728c2ecf20Sopenharmony_ci	    PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
82738c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
82748c2ecf20Sopenharmony_ci		return 0;
82758c2ecf20Sopenharmony_ci	}
82768c2ecf20Sopenharmony_ci
82778c2ecf20Sopenharmony_ci	if (params->feature_config_flags &
82788c2ecf20Sopenharmony_ci	    FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
82798c2ecf20Sopenharmony_ci		/* Use specific phy request */
82808c2ecf20Sopenharmony_ci		cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
82818c2ecf20Sopenharmony_ci	} else if (params->feature_config_flags &
82828c2ecf20Sopenharmony_ci		   FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
82838c2ecf20Sopenharmony_ci		/* Use first phy request only in case of non-dual media*/
82848c2ecf20Sopenharmony_ci		if (DUAL_MEDIA(params)) {
82858c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
82868c2ecf20Sopenharmony_ci			   "FW does not support OPT MDL verification\n");
82878c2ecf20Sopenharmony_ci			return -EINVAL;
82888c2ecf20Sopenharmony_ci		}
82898c2ecf20Sopenharmony_ci		cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
82908c2ecf20Sopenharmony_ci	} else {
82918c2ecf20Sopenharmony_ci		/* No support in OPT MDL detection */
82928c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
82938c2ecf20Sopenharmony_ci		   "FW does not support OPT MDL verification\n");
82948c2ecf20Sopenharmony_ci		return -EINVAL;
82958c2ecf20Sopenharmony_ci	}
82968c2ecf20Sopenharmony_ci
82978c2ecf20Sopenharmony_ci	fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
82988c2ecf20Sopenharmony_ci	fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
82998c2ecf20Sopenharmony_ci	if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
83008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Approved module\n");
83018c2ecf20Sopenharmony_ci		return 0;
83028c2ecf20Sopenharmony_ci	}
83038c2ecf20Sopenharmony_ci
83048c2ecf20Sopenharmony_ci	/* Format the warning message */
83058c2ecf20Sopenharmony_ci	if (bnx2x_read_sfp_module_eeprom(phy,
83068c2ecf20Sopenharmony_ci					 params,
83078c2ecf20Sopenharmony_ci					 I2C_DEV_ADDR_A0,
83088c2ecf20Sopenharmony_ci					 SFP_EEPROM_VENDOR_NAME_ADDR,
83098c2ecf20Sopenharmony_ci					 SFP_EEPROM_VENDOR_NAME_SIZE,
83108c2ecf20Sopenharmony_ci					 (u8 *)vendor_name))
83118c2ecf20Sopenharmony_ci		vendor_name[0] = '\0';
83128c2ecf20Sopenharmony_ci	else
83138c2ecf20Sopenharmony_ci		vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
83148c2ecf20Sopenharmony_ci	if (bnx2x_read_sfp_module_eeprom(phy,
83158c2ecf20Sopenharmony_ci					 params,
83168c2ecf20Sopenharmony_ci					 I2C_DEV_ADDR_A0,
83178c2ecf20Sopenharmony_ci					 SFP_EEPROM_PART_NO_ADDR,
83188c2ecf20Sopenharmony_ci					 SFP_EEPROM_PART_NO_SIZE,
83198c2ecf20Sopenharmony_ci					 (u8 *)vendor_pn))
83208c2ecf20Sopenharmony_ci		vendor_pn[0] = '\0';
83218c2ecf20Sopenharmony_ci	else
83228c2ecf20Sopenharmony_ci		vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
83238c2ecf20Sopenharmony_ci
83248c2ecf20Sopenharmony_ci	netdev_err(bp->dev,  "Warning: Unqualified SFP+ module detected,"
83258c2ecf20Sopenharmony_ci			      " Port %d from %s part number %s\n",
83268c2ecf20Sopenharmony_ci			 params->port, vendor_name, vendor_pn);
83278c2ecf20Sopenharmony_ci	if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
83288c2ecf20Sopenharmony_ci	    PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
83298c2ecf20Sopenharmony_ci		phy->flags |= FLAGS_SFP_NOT_APPROVED;
83308c2ecf20Sopenharmony_ci	return -EINVAL;
83318c2ecf20Sopenharmony_ci}
83328c2ecf20Sopenharmony_ci
83338c2ecf20Sopenharmony_cistatic int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
83348c2ecf20Sopenharmony_ci						 struct link_params *params)
83358c2ecf20Sopenharmony_ci
83368c2ecf20Sopenharmony_ci{
83378c2ecf20Sopenharmony_ci	u8 val;
83388c2ecf20Sopenharmony_ci	int rc;
83398c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
83408c2ecf20Sopenharmony_ci	u16 timeout;
83418c2ecf20Sopenharmony_ci	/* Initialization time after hot-plug may take up to 300ms for
83428c2ecf20Sopenharmony_ci	 * some phys type ( e.g. JDSU )
83438c2ecf20Sopenharmony_ci	 */
83448c2ecf20Sopenharmony_ci
83458c2ecf20Sopenharmony_ci	for (timeout = 0; timeout < 60; timeout++) {
83468c2ecf20Sopenharmony_ci		if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
83478c2ecf20Sopenharmony_ci			rc = bnx2x_warpcore_read_sfp_module_eeprom(
83488c2ecf20Sopenharmony_ci				phy, params, I2C_DEV_ADDR_A0, 1, 1, &val,
83498c2ecf20Sopenharmony_ci				1);
83508c2ecf20Sopenharmony_ci		else
83518c2ecf20Sopenharmony_ci			rc = bnx2x_read_sfp_module_eeprom(phy, params,
83528c2ecf20Sopenharmony_ci							  I2C_DEV_ADDR_A0,
83538c2ecf20Sopenharmony_ci							  1, 1, &val);
83548c2ecf20Sopenharmony_ci		if (rc == 0) {
83558c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
83568c2ecf20Sopenharmony_ci			   "SFP+ module initialization took %d ms\n",
83578c2ecf20Sopenharmony_ci			   timeout * 5);
83588c2ecf20Sopenharmony_ci			return 0;
83598c2ecf20Sopenharmony_ci		}
83608c2ecf20Sopenharmony_ci		usleep_range(5000, 10000);
83618c2ecf20Sopenharmony_ci	}
83628c2ecf20Sopenharmony_ci	rc = bnx2x_read_sfp_module_eeprom(phy, params, I2C_DEV_ADDR_A0,
83638c2ecf20Sopenharmony_ci					  1, 1, &val);
83648c2ecf20Sopenharmony_ci	return rc;
83658c2ecf20Sopenharmony_ci}
83668c2ecf20Sopenharmony_ci
83678c2ecf20Sopenharmony_cistatic void bnx2x_8727_power_module(struct bnx2x *bp,
83688c2ecf20Sopenharmony_ci				    struct bnx2x_phy *phy,
83698c2ecf20Sopenharmony_ci				    u8 is_power_up) {
83708c2ecf20Sopenharmony_ci	/* Make sure GPIOs are not using for LED mode */
83718c2ecf20Sopenharmony_ci	u16 val;
83728c2ecf20Sopenharmony_ci	/* In the GPIO register, bit 4 is use to determine if the GPIOs are
83738c2ecf20Sopenharmony_ci	 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
83748c2ecf20Sopenharmony_ci	 * output
83758c2ecf20Sopenharmony_ci	 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
83768c2ecf20Sopenharmony_ci	 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
83778c2ecf20Sopenharmony_ci	 * where the 1st bit is the over-current(only input), and 2nd bit is
83788c2ecf20Sopenharmony_ci	 * for power( only output )
83798c2ecf20Sopenharmony_ci	 *
83808c2ecf20Sopenharmony_ci	 * In case of NOC feature is disabled and power is up, set GPIO control
83818c2ecf20Sopenharmony_ci	 *  as input to enable listening of over-current indication
83828c2ecf20Sopenharmony_ci	 */
83838c2ecf20Sopenharmony_ci	if (phy->flags & FLAGS_NOC)
83848c2ecf20Sopenharmony_ci		return;
83858c2ecf20Sopenharmony_ci	if (is_power_up)
83868c2ecf20Sopenharmony_ci		val = (1<<4);
83878c2ecf20Sopenharmony_ci	else
83888c2ecf20Sopenharmony_ci		/* Set GPIO control to OUTPUT, and set the power bit
83898c2ecf20Sopenharmony_ci		 * to according to the is_power_up
83908c2ecf20Sopenharmony_ci		 */
83918c2ecf20Sopenharmony_ci		val = (1<<1);
83928c2ecf20Sopenharmony_ci
83938c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
83948c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
83958c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8727_GPIO_CTRL,
83968c2ecf20Sopenharmony_ci			 val);
83978c2ecf20Sopenharmony_ci}
83988c2ecf20Sopenharmony_ci
83998c2ecf20Sopenharmony_cistatic int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
84008c2ecf20Sopenharmony_ci					struct bnx2x_phy *phy,
84018c2ecf20Sopenharmony_ci					u16 edc_mode)
84028c2ecf20Sopenharmony_ci{
84038c2ecf20Sopenharmony_ci	u16 cur_limiting_mode;
84048c2ecf20Sopenharmony_ci
84058c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
84068c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
84078c2ecf20Sopenharmony_ci			MDIO_PMA_REG_ROM_VER2,
84088c2ecf20Sopenharmony_ci			&cur_limiting_mode);
84098c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
84108c2ecf20Sopenharmony_ci		 cur_limiting_mode);
84118c2ecf20Sopenharmony_ci
84128c2ecf20Sopenharmony_ci	if (edc_mode == EDC_MODE_LIMITING) {
84138c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
84148c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84158c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
84168c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_ROM_VER2,
84178c2ecf20Sopenharmony_ci				 EDC_MODE_LIMITING);
84188c2ecf20Sopenharmony_ci	} else { /* LRM mode ( default )*/
84198c2ecf20Sopenharmony_ci
84208c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
84218c2ecf20Sopenharmony_ci
84228c2ecf20Sopenharmony_ci		/* Changing to LRM mode takes quite few seconds. So do it only
84238c2ecf20Sopenharmony_ci		 * if current mode is limiting (default is LRM)
84248c2ecf20Sopenharmony_ci		 */
84258c2ecf20Sopenharmony_ci		if (cur_limiting_mode != EDC_MODE_LIMITING)
84268c2ecf20Sopenharmony_ci			return 0;
84278c2ecf20Sopenharmony_ci
84288c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84298c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
84308c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_LRM_MODE,
84318c2ecf20Sopenharmony_ci				 0);
84328c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84338c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
84348c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_ROM_VER2,
84358c2ecf20Sopenharmony_ci				 0x128);
84368c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84378c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
84388c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_MISC_CTRL0,
84398c2ecf20Sopenharmony_ci				 0x4008);
84408c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84418c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
84428c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_LRM_MODE,
84438c2ecf20Sopenharmony_ci				 0xaaaa);
84448c2ecf20Sopenharmony_ci	}
84458c2ecf20Sopenharmony_ci	return 0;
84468c2ecf20Sopenharmony_ci}
84478c2ecf20Sopenharmony_ci
84488c2ecf20Sopenharmony_cistatic int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
84498c2ecf20Sopenharmony_ci					struct bnx2x_phy *phy,
84508c2ecf20Sopenharmony_ci					u16 edc_mode)
84518c2ecf20Sopenharmony_ci{
84528c2ecf20Sopenharmony_ci	u16 phy_identifier;
84538c2ecf20Sopenharmony_ci	u16 rom_ver2_val;
84548c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
84558c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
84568c2ecf20Sopenharmony_ci			MDIO_PMA_REG_PHY_IDENTIFIER,
84578c2ecf20Sopenharmony_ci			&phy_identifier);
84588c2ecf20Sopenharmony_ci
84598c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
84608c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
84618c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_PHY_IDENTIFIER,
84628c2ecf20Sopenharmony_ci			 (phy_identifier & ~(1<<9)));
84638c2ecf20Sopenharmony_ci
84648c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
84658c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
84668c2ecf20Sopenharmony_ci			MDIO_PMA_REG_ROM_VER2,
84678c2ecf20Sopenharmony_ci			&rom_ver2_val);
84688c2ecf20Sopenharmony_ci	/* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
84698c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
84708c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
84718c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_ROM_VER2,
84728c2ecf20Sopenharmony_ci			 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
84738c2ecf20Sopenharmony_ci
84748c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
84758c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
84768c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_PHY_IDENTIFIER,
84778c2ecf20Sopenharmony_ci			 (phy_identifier | (1<<9)));
84788c2ecf20Sopenharmony_ci
84798c2ecf20Sopenharmony_ci	return 0;
84808c2ecf20Sopenharmony_ci}
84818c2ecf20Sopenharmony_ci
84828c2ecf20Sopenharmony_cistatic void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
84838c2ecf20Sopenharmony_ci				     struct link_params *params,
84848c2ecf20Sopenharmony_ci				     u32 action)
84858c2ecf20Sopenharmony_ci{
84868c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
84878c2ecf20Sopenharmony_ci	u16 val;
84888c2ecf20Sopenharmony_ci	switch (action) {
84898c2ecf20Sopenharmony_ci	case DISABLE_TX:
84908c2ecf20Sopenharmony_ci		bnx2x_sfp_set_transmitter(params, phy, 0);
84918c2ecf20Sopenharmony_ci		break;
84928c2ecf20Sopenharmony_ci	case ENABLE_TX:
84938c2ecf20Sopenharmony_ci		if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
84948c2ecf20Sopenharmony_ci			bnx2x_sfp_set_transmitter(params, phy, 1);
84958c2ecf20Sopenharmony_ci		break;
84968c2ecf20Sopenharmony_ci	case PHY_INIT:
84978c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
84988c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
84998c2ecf20Sopenharmony_ci				 (1<<2) | (1<<5));
85008c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
85018c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
85028c2ecf20Sopenharmony_ci				 0);
85038c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
85048c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0006);
85058c2ecf20Sopenharmony_ci		/* Make MOD_ABS give interrupt on change */
85068c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
85078c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8727_PCS_OPT_CTRL,
85088c2ecf20Sopenharmony_ci				&val);
85098c2ecf20Sopenharmony_ci		val |= (1<<12);
85108c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_NOC)
85118c2ecf20Sopenharmony_ci			val |= (3<<5);
85128c2ecf20Sopenharmony_ci		/* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
85138c2ecf20Sopenharmony_ci		 * status which reflect SFP+ module over-current
85148c2ecf20Sopenharmony_ci		 */
85158c2ecf20Sopenharmony_ci		if (!(phy->flags & FLAGS_NOC))
85168c2ecf20Sopenharmony_ci			val &= 0xff8f; /* Reset bits 4-6 */
85178c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
85188c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
85198c2ecf20Sopenharmony_ci				 val);
85208c2ecf20Sopenharmony_ci		break;
85218c2ecf20Sopenharmony_ci	default:
85228c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
85238c2ecf20Sopenharmony_ci		   action);
85248c2ecf20Sopenharmony_ci		return;
85258c2ecf20Sopenharmony_ci	}
85268c2ecf20Sopenharmony_ci}
85278c2ecf20Sopenharmony_ci
85288c2ecf20Sopenharmony_cistatic void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
85298c2ecf20Sopenharmony_ci					   u8 gpio_mode)
85308c2ecf20Sopenharmony_ci{
85318c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
85328c2ecf20Sopenharmony_ci
85338c2ecf20Sopenharmony_ci	u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
85348c2ecf20Sopenharmony_ci			    offsetof(struct shmem_region,
85358c2ecf20Sopenharmony_ci			dev_info.port_hw_config[params->port].sfp_ctrl)) &
85368c2ecf20Sopenharmony_ci		PORT_HW_CFG_FAULT_MODULE_LED_MASK;
85378c2ecf20Sopenharmony_ci	switch (fault_led_gpio) {
85388c2ecf20Sopenharmony_ci	case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
85398c2ecf20Sopenharmony_ci		return;
85408c2ecf20Sopenharmony_ci	case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
85418c2ecf20Sopenharmony_ci	case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
85428c2ecf20Sopenharmony_ci	case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
85438c2ecf20Sopenharmony_ci	case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
85448c2ecf20Sopenharmony_ci	{
85458c2ecf20Sopenharmony_ci		u8 gpio_port = bnx2x_get_gpio_port(params);
85468c2ecf20Sopenharmony_ci		u16 gpio_pin = fault_led_gpio -
85478c2ecf20Sopenharmony_ci			PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
85488c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Set fault module-detected led "
85498c2ecf20Sopenharmony_ci				   "pin %x port %x mode %x\n",
85508c2ecf20Sopenharmony_ci			       gpio_pin, gpio_port, gpio_mode);
85518c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
85528c2ecf20Sopenharmony_ci	}
85538c2ecf20Sopenharmony_ci	break;
85548c2ecf20Sopenharmony_ci	default:
85558c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
85568c2ecf20Sopenharmony_ci			       fault_led_gpio);
85578c2ecf20Sopenharmony_ci	}
85588c2ecf20Sopenharmony_ci}
85598c2ecf20Sopenharmony_ci
85608c2ecf20Sopenharmony_cistatic void bnx2x_set_e3_module_fault_led(struct link_params *params,
85618c2ecf20Sopenharmony_ci					  u8 gpio_mode)
85628c2ecf20Sopenharmony_ci{
85638c2ecf20Sopenharmony_ci	u32 pin_cfg;
85648c2ecf20Sopenharmony_ci	u8 port = params->port;
85658c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
85668c2ecf20Sopenharmony_ci	pin_cfg = (REG_RD(bp, params->shmem_base +
85678c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region,
85688c2ecf20Sopenharmony_ci				  dev_info.port_hw_config[port].e3_sfp_ctrl)) &
85698c2ecf20Sopenharmony_ci		PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
85708c2ecf20Sopenharmony_ci		PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
85718c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
85728c2ecf20Sopenharmony_ci		       gpio_mode, pin_cfg);
85738c2ecf20Sopenharmony_ci	bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
85748c2ecf20Sopenharmony_ci}
85758c2ecf20Sopenharmony_ci
85768c2ecf20Sopenharmony_cistatic void bnx2x_set_sfp_module_fault_led(struct link_params *params,
85778c2ecf20Sopenharmony_ci					   u8 gpio_mode)
85788c2ecf20Sopenharmony_ci{
85798c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
85808c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
85818c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
85828c2ecf20Sopenharmony_ci		/* Low ==> if SFP+ module is supported otherwise
85838c2ecf20Sopenharmony_ci		 * High ==> if SFP+ module is not on the approved vendor list
85848c2ecf20Sopenharmony_ci		 */
85858c2ecf20Sopenharmony_ci		bnx2x_set_e3_module_fault_led(params, gpio_mode);
85868c2ecf20Sopenharmony_ci	} else
85878c2ecf20Sopenharmony_ci		bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
85888c2ecf20Sopenharmony_ci}
85898c2ecf20Sopenharmony_ci
85908c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
85918c2ecf20Sopenharmony_ci				    struct link_params *params)
85928c2ecf20Sopenharmony_ci{
85938c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
85948c2ecf20Sopenharmony_ci	bnx2x_warpcore_power_module(params, 0);
85958c2ecf20Sopenharmony_ci	/* Put Warpcore in low power mode */
85968c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_WC0_RESET, 0x0c0e);
85978c2ecf20Sopenharmony_ci
85988c2ecf20Sopenharmony_ci	/* Put LCPLL in low power mode */
85998c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_LCPLL_E40_PWRDWN, 1);
86008c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
86018c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
86028c2ecf20Sopenharmony_ci}
86038c2ecf20Sopenharmony_ci
86048c2ecf20Sopenharmony_cistatic void bnx2x_power_sfp_module(struct link_params *params,
86058c2ecf20Sopenharmony_ci				   struct bnx2x_phy *phy,
86068c2ecf20Sopenharmony_ci				   u8 power)
86078c2ecf20Sopenharmony_ci{
86088c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
86098c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
86108c2ecf20Sopenharmony_ci
86118c2ecf20Sopenharmony_ci	switch (phy->type) {
86128c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
86138c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
86148c2ecf20Sopenharmony_ci		bnx2x_8727_power_module(params->bp, phy, power);
86158c2ecf20Sopenharmony_ci		break;
86168c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
86178c2ecf20Sopenharmony_ci		bnx2x_warpcore_power_module(params, power);
86188c2ecf20Sopenharmony_ci		break;
86198c2ecf20Sopenharmony_ci	default:
86208c2ecf20Sopenharmony_ci		break;
86218c2ecf20Sopenharmony_ci	}
86228c2ecf20Sopenharmony_ci}
86238c2ecf20Sopenharmony_cistatic void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
86248c2ecf20Sopenharmony_ci					     struct bnx2x_phy *phy,
86258c2ecf20Sopenharmony_ci					     u16 edc_mode)
86268c2ecf20Sopenharmony_ci{
86278c2ecf20Sopenharmony_ci	u16 val = 0;
86288c2ecf20Sopenharmony_ci	u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
86298c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
86308c2ecf20Sopenharmony_ci
86318c2ecf20Sopenharmony_ci	u8 lane = bnx2x_get_warpcore_lane(phy, params);
86328c2ecf20Sopenharmony_ci	/* This is a global register which controls all lanes */
86338c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
86348c2ecf20Sopenharmony_ci			MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
86358c2ecf20Sopenharmony_ci	val &= ~(0xf << (lane << 2));
86368c2ecf20Sopenharmony_ci
86378c2ecf20Sopenharmony_ci	switch (edc_mode) {
86388c2ecf20Sopenharmony_ci	case EDC_MODE_LINEAR:
86398c2ecf20Sopenharmony_ci	case EDC_MODE_LIMITING:
86408c2ecf20Sopenharmony_ci		mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
86418c2ecf20Sopenharmony_ci		break;
86428c2ecf20Sopenharmony_ci	case EDC_MODE_PASSIVE_DAC:
86438c2ecf20Sopenharmony_ci	case EDC_MODE_ACTIVE_DAC:
86448c2ecf20Sopenharmony_ci		mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
86458c2ecf20Sopenharmony_ci		break;
86468c2ecf20Sopenharmony_ci	default:
86478c2ecf20Sopenharmony_ci		break;
86488c2ecf20Sopenharmony_ci	}
86498c2ecf20Sopenharmony_ci
86508c2ecf20Sopenharmony_ci	val |= (mode << (lane << 2));
86518c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
86528c2ecf20Sopenharmony_ci			 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
86538c2ecf20Sopenharmony_ci	/* A must read */
86548c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
86558c2ecf20Sopenharmony_ci			MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
86568c2ecf20Sopenharmony_ci
86578c2ecf20Sopenharmony_ci	/* Restart microcode to re-read the new mode */
86588c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, phy, 1);
86598c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, phy, 0);
86608c2ecf20Sopenharmony_ci
86618c2ecf20Sopenharmony_ci}
86628c2ecf20Sopenharmony_ci
86638c2ecf20Sopenharmony_cistatic void bnx2x_set_limiting_mode(struct link_params *params,
86648c2ecf20Sopenharmony_ci				    struct bnx2x_phy *phy,
86658c2ecf20Sopenharmony_ci				    u16 edc_mode)
86668c2ecf20Sopenharmony_ci{
86678c2ecf20Sopenharmony_ci	switch (phy->type) {
86688c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
86698c2ecf20Sopenharmony_ci		bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
86708c2ecf20Sopenharmony_ci		break;
86718c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
86728c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
86738c2ecf20Sopenharmony_ci		bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
86748c2ecf20Sopenharmony_ci		break;
86758c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
86768c2ecf20Sopenharmony_ci		bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
86778c2ecf20Sopenharmony_ci		break;
86788c2ecf20Sopenharmony_ci	}
86798c2ecf20Sopenharmony_ci}
86808c2ecf20Sopenharmony_ci
86818c2ecf20Sopenharmony_cistatic int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
86828c2ecf20Sopenharmony_ci				      struct link_params *params)
86838c2ecf20Sopenharmony_ci{
86848c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
86858c2ecf20Sopenharmony_ci	u16 edc_mode;
86868c2ecf20Sopenharmony_ci	int rc = 0;
86878c2ecf20Sopenharmony_ci
86888c2ecf20Sopenharmony_ci	u32 val = REG_RD(bp, params->shmem_base +
86898c2ecf20Sopenharmony_ci			     offsetof(struct shmem_region, dev_info.
86908c2ecf20Sopenharmony_ci				     port_feature_config[params->port].config));
86918c2ecf20Sopenharmony_ci	/* Enabled transmitter by default */
86928c2ecf20Sopenharmony_ci	bnx2x_sfp_set_transmitter(params, phy, 1);
86938c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
86948c2ecf20Sopenharmony_ci		 params->port);
86958c2ecf20Sopenharmony_ci	/* Power up module */
86968c2ecf20Sopenharmony_ci	bnx2x_power_sfp_module(params, phy, 1);
86978c2ecf20Sopenharmony_ci	if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
86988c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
86998c2ecf20Sopenharmony_ci		return -EINVAL;
87008c2ecf20Sopenharmony_ci	} else if (bnx2x_verify_sfp_module(phy, params) != 0) {
87018c2ecf20Sopenharmony_ci		/* Check SFP+ module compatibility */
87028c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Module verification failed!!\n");
87038c2ecf20Sopenharmony_ci		rc = -EINVAL;
87048c2ecf20Sopenharmony_ci		/* Turn on fault module-detected led */
87058c2ecf20Sopenharmony_ci		bnx2x_set_sfp_module_fault_led(params,
87068c2ecf20Sopenharmony_ci					       MISC_REGISTERS_GPIO_HIGH);
87078c2ecf20Sopenharmony_ci
87088c2ecf20Sopenharmony_ci		/* Check if need to power down the SFP+ module */
87098c2ecf20Sopenharmony_ci		if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
87108c2ecf20Sopenharmony_ci		     PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
87118c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
87128c2ecf20Sopenharmony_ci			bnx2x_power_sfp_module(params, phy, 0);
87138c2ecf20Sopenharmony_ci			return rc;
87148c2ecf20Sopenharmony_ci		}
87158c2ecf20Sopenharmony_ci	} else {
87168c2ecf20Sopenharmony_ci		/* Turn off fault module-detected led */
87178c2ecf20Sopenharmony_ci		bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
87188c2ecf20Sopenharmony_ci	}
87198c2ecf20Sopenharmony_ci
87208c2ecf20Sopenharmony_ci	/* Check and set limiting mode / LRM mode on 8726. On 8727 it
87218c2ecf20Sopenharmony_ci	 * is done automatically
87228c2ecf20Sopenharmony_ci	 */
87238c2ecf20Sopenharmony_ci	bnx2x_set_limiting_mode(params, phy, edc_mode);
87248c2ecf20Sopenharmony_ci
87258c2ecf20Sopenharmony_ci	/* Disable transmit for this module if the module is not approved, and
87268c2ecf20Sopenharmony_ci	 * laser needs to be disabled.
87278c2ecf20Sopenharmony_ci	 */
87288c2ecf20Sopenharmony_ci	if ((rc) &&
87298c2ecf20Sopenharmony_ci	    ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
87308c2ecf20Sopenharmony_ci	     PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER))
87318c2ecf20Sopenharmony_ci		bnx2x_sfp_set_transmitter(params, phy, 0);
87328c2ecf20Sopenharmony_ci
87338c2ecf20Sopenharmony_ci	return rc;
87348c2ecf20Sopenharmony_ci}
87358c2ecf20Sopenharmony_ci
87368c2ecf20Sopenharmony_civoid bnx2x_handle_module_detect_int(struct link_params *params)
87378c2ecf20Sopenharmony_ci{
87388c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
87398c2ecf20Sopenharmony_ci	struct bnx2x_phy *phy;
87408c2ecf20Sopenharmony_ci	u32 gpio_val;
87418c2ecf20Sopenharmony_ci	u8 gpio_num, gpio_port;
87428c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
87438c2ecf20Sopenharmony_ci		phy = &params->phy[INT_PHY];
87448c2ecf20Sopenharmony_ci		/* Always enable TX laser,will be disabled in case of fault */
87458c2ecf20Sopenharmony_ci		bnx2x_sfp_set_transmitter(params, phy, 1);
87468c2ecf20Sopenharmony_ci	} else {
87478c2ecf20Sopenharmony_ci		phy = &params->phy[EXT_PHY1];
87488c2ecf20Sopenharmony_ci	}
87498c2ecf20Sopenharmony_ci	if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
87508c2ecf20Sopenharmony_ci				      params->port, &gpio_num, &gpio_port) ==
87518c2ecf20Sopenharmony_ci	    -EINVAL) {
87528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
87538c2ecf20Sopenharmony_ci		return;
87548c2ecf20Sopenharmony_ci	}
87558c2ecf20Sopenharmony_ci
87568c2ecf20Sopenharmony_ci	/* Set valid module led off */
87578c2ecf20Sopenharmony_ci	bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
87588c2ecf20Sopenharmony_ci
87598c2ecf20Sopenharmony_ci	/* Get current gpio val reflecting module plugged in / out*/
87608c2ecf20Sopenharmony_ci	gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
87618c2ecf20Sopenharmony_ci
87628c2ecf20Sopenharmony_ci	/* Call the handling function in case module is detected */
87638c2ecf20Sopenharmony_ci	if (gpio_val == 0) {
87648c2ecf20Sopenharmony_ci		bnx2x_set_mdio_emac_per_phy(bp, params);
87658c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
87668c2ecf20Sopenharmony_ci
87678c2ecf20Sopenharmony_ci		bnx2x_power_sfp_module(params, phy, 1);
87688c2ecf20Sopenharmony_ci		bnx2x_set_gpio_int(bp, gpio_num,
87698c2ecf20Sopenharmony_ci				   MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
87708c2ecf20Sopenharmony_ci				   gpio_port);
87718c2ecf20Sopenharmony_ci		if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0) {
87728c2ecf20Sopenharmony_ci			bnx2x_sfp_module_detection(phy, params);
87738c2ecf20Sopenharmony_ci			if (CHIP_IS_E3(bp)) {
87748c2ecf20Sopenharmony_ci				u16 rx_tx_in_reset;
87758c2ecf20Sopenharmony_ci				/* In case WC is out of reset, reconfigure the
87768c2ecf20Sopenharmony_ci				 * link speed while taking into account 1G
87778c2ecf20Sopenharmony_ci				 * module limitation.
87788c2ecf20Sopenharmony_ci				 */
87798c2ecf20Sopenharmony_ci				bnx2x_cl45_read(bp, phy,
87808c2ecf20Sopenharmony_ci						MDIO_WC_DEVAD,
87818c2ecf20Sopenharmony_ci						MDIO_WC_REG_DIGITAL5_MISC6,
87828c2ecf20Sopenharmony_ci						&rx_tx_in_reset);
87838c2ecf20Sopenharmony_ci				if ((!rx_tx_in_reset) &&
87848c2ecf20Sopenharmony_ci				    (params->link_flags &
87858c2ecf20Sopenharmony_ci				     PHY_INITIALIZED)) {
87868c2ecf20Sopenharmony_ci					bnx2x_warpcore_reset_lane(bp, phy, 1);
87878c2ecf20Sopenharmony_ci					bnx2x_warpcore_config_sfi(phy, params);
87888c2ecf20Sopenharmony_ci					bnx2x_warpcore_reset_lane(bp, phy, 0);
87898c2ecf20Sopenharmony_ci				}
87908c2ecf20Sopenharmony_ci			}
87918c2ecf20Sopenharmony_ci		} else {
87928c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
87938c2ecf20Sopenharmony_ci		}
87948c2ecf20Sopenharmony_ci	} else {
87958c2ecf20Sopenharmony_ci		bnx2x_set_gpio_int(bp, gpio_num,
87968c2ecf20Sopenharmony_ci				   MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
87978c2ecf20Sopenharmony_ci				   gpio_port);
87988c2ecf20Sopenharmony_ci		/* Module was plugged out.
87998c2ecf20Sopenharmony_ci		 * Disable transmit for this module
88008c2ecf20Sopenharmony_ci		 */
88018c2ecf20Sopenharmony_ci		phy->media_type = ETH_PHY_NOT_PRESENT;
88028c2ecf20Sopenharmony_ci	}
88038c2ecf20Sopenharmony_ci}
88048c2ecf20Sopenharmony_ci
88058c2ecf20Sopenharmony_ci/******************************************************************/
88068c2ecf20Sopenharmony_ci/*		Used by 8706 and 8727                             */
88078c2ecf20Sopenharmony_ci/******************************************************************/
88088c2ecf20Sopenharmony_cistatic void bnx2x_sfp_mask_fault(struct bnx2x *bp,
88098c2ecf20Sopenharmony_ci				 struct bnx2x_phy *phy,
88108c2ecf20Sopenharmony_ci				 u16 alarm_status_offset,
88118c2ecf20Sopenharmony_ci				 u16 alarm_ctrl_offset)
88128c2ecf20Sopenharmony_ci{
88138c2ecf20Sopenharmony_ci	u16 alarm_status, val;
88148c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88158c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, alarm_status_offset,
88168c2ecf20Sopenharmony_ci			&alarm_status);
88178c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88188c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, alarm_status_offset,
88198c2ecf20Sopenharmony_ci			&alarm_status);
88208c2ecf20Sopenharmony_ci	/* Mask or enable the fault event. */
88218c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
88228c2ecf20Sopenharmony_ci	if (alarm_status & (1<<0))
88238c2ecf20Sopenharmony_ci		val &= ~(1<<0);
88248c2ecf20Sopenharmony_ci	else
88258c2ecf20Sopenharmony_ci		val |= (1<<0);
88268c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
88278c2ecf20Sopenharmony_ci}
88288c2ecf20Sopenharmony_ci/******************************************************************/
88298c2ecf20Sopenharmony_ci/*		common BCM8706/BCM8726 PHY SECTION		  */
88308c2ecf20Sopenharmony_ci/******************************************************************/
88318c2ecf20Sopenharmony_cistatic u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
88328c2ecf20Sopenharmony_ci				      struct link_params *params,
88338c2ecf20Sopenharmony_ci				      struct link_vars *vars)
88348c2ecf20Sopenharmony_ci{
88358c2ecf20Sopenharmony_ci	u8 link_up = 0;
88368c2ecf20Sopenharmony_ci	u16 val1, val2, rx_sd, pcs_status;
88378c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
88388c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
88398c2ecf20Sopenharmony_ci	/* Clear RX Alarm*/
88408c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88418c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
88428c2ecf20Sopenharmony_ci
88438c2ecf20Sopenharmony_ci	bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
88448c2ecf20Sopenharmony_ci			     MDIO_PMA_LASI_TXCTRL);
88458c2ecf20Sopenharmony_ci
88468c2ecf20Sopenharmony_ci	/* Clear LASI indication*/
88478c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88488c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
88498c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88508c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
88518c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
88528c2ecf20Sopenharmony_ci
88538c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88548c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
88558c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88568c2ecf20Sopenharmony_ci			MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
88578c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88588c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
88598c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
88608c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
88618c2ecf20Sopenharmony_ci
88628c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
88638c2ecf20Sopenharmony_ci			" link_status 0x%x\n", rx_sd, pcs_status, val2);
88648c2ecf20Sopenharmony_ci	/* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
88658c2ecf20Sopenharmony_ci	 * are set, or if the autoneg bit 1 is set
88668c2ecf20Sopenharmony_ci	 */
88678c2ecf20Sopenharmony_ci	link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
88688c2ecf20Sopenharmony_ci	if (link_up) {
88698c2ecf20Sopenharmony_ci		if (val2 & (1<<1))
88708c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
88718c2ecf20Sopenharmony_ci		else
88728c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10000;
88738c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
88748c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
88758c2ecf20Sopenharmony_ci	}
88768c2ecf20Sopenharmony_ci
88778c2ecf20Sopenharmony_ci	/* Capture 10G link fault. Read twice to clear stale value. */
88788c2ecf20Sopenharmony_ci	if (vars->line_speed == SPEED_10000) {
88798c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
88808c2ecf20Sopenharmony_ci			    MDIO_PMA_LASI_TXSTAT, &val1);
88818c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
88828c2ecf20Sopenharmony_ci			    MDIO_PMA_LASI_TXSTAT, &val1);
88838c2ecf20Sopenharmony_ci		if (val1 & (1<<0))
88848c2ecf20Sopenharmony_ci			vars->fault_detected = 1;
88858c2ecf20Sopenharmony_ci	}
88868c2ecf20Sopenharmony_ci
88878c2ecf20Sopenharmony_ci	return link_up;
88888c2ecf20Sopenharmony_ci}
88898c2ecf20Sopenharmony_ci
88908c2ecf20Sopenharmony_ci/******************************************************************/
88918c2ecf20Sopenharmony_ci/*			BCM8706 PHY SECTION			  */
88928c2ecf20Sopenharmony_ci/******************************************************************/
88938c2ecf20Sopenharmony_cistatic void bnx2x_8706_config_init(struct bnx2x_phy *phy,
88948c2ecf20Sopenharmony_ci				   struct link_params *params,
88958c2ecf20Sopenharmony_ci				   struct link_vars *vars)
88968c2ecf20Sopenharmony_ci{
88978c2ecf20Sopenharmony_ci	u32 tx_en_mode;
88988c2ecf20Sopenharmony_ci	u16 cnt, val, tmp1;
88998c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
89008c2ecf20Sopenharmony_ci
89018c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
89028c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
89038c2ecf20Sopenharmony_ci	/* HW reset */
89048c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, params->port);
89058c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
89068c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
89078c2ecf20Sopenharmony_ci
89088c2ecf20Sopenharmony_ci	/* Wait until fw is loaded */
89098c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 100; cnt++) {
89108c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
89118c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
89128c2ecf20Sopenharmony_ci		if (val)
89138c2ecf20Sopenharmony_ci			break;
89148c2ecf20Sopenharmony_ci		usleep_range(10000, 20000);
89158c2ecf20Sopenharmony_ci	}
89168c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
89178c2ecf20Sopenharmony_ci	if ((params->feature_config_flags &
89188c2ecf20Sopenharmony_ci	     FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
89198c2ecf20Sopenharmony_ci		u8 i;
89208c2ecf20Sopenharmony_ci		u16 reg;
89218c2ecf20Sopenharmony_ci		for (i = 0; i < 4; i++) {
89228c2ecf20Sopenharmony_ci			reg = MDIO_XS_8706_REG_BANK_RX0 +
89238c2ecf20Sopenharmony_ci				i*(MDIO_XS_8706_REG_BANK_RX1 -
89248c2ecf20Sopenharmony_ci				   MDIO_XS_8706_REG_BANK_RX0);
89258c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
89268c2ecf20Sopenharmony_ci			/* Clear first 3 bits of the control */
89278c2ecf20Sopenharmony_ci			val &= ~0x7;
89288c2ecf20Sopenharmony_ci			/* Set control bits according to configuration */
89298c2ecf20Sopenharmony_ci			val |= (phy->rx_preemphasis[i] & 0x7);
89308c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
89318c2ecf20Sopenharmony_ci				   " reg 0x%x <-- val 0x%x\n", reg, val);
89328c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
89338c2ecf20Sopenharmony_ci		}
89348c2ecf20Sopenharmony_ci	}
89358c2ecf20Sopenharmony_ci	/* Force speed */
89368c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_10000) {
89378c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
89388c2ecf20Sopenharmony_ci
89398c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89408c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
89418c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
89428c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89438c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
89448c2ecf20Sopenharmony_ci				 0);
89458c2ecf20Sopenharmony_ci		/* Arm LASI for link and Tx fault. */
89468c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89478c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
89488c2ecf20Sopenharmony_ci	} else {
89498c2ecf20Sopenharmony_ci		/* Force 1Gbps using autoneg with 1G advertisement */
89508c2ecf20Sopenharmony_ci
89518c2ecf20Sopenharmony_ci		/* Allow CL37 through CL73 */
89528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
89538c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89548c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
89558c2ecf20Sopenharmony_ci
89568c2ecf20Sopenharmony_ci		/* Enable Full-Duplex advertisement on CL37 */
89578c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89588c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
89598c2ecf20Sopenharmony_ci		/* Enable CL37 AN */
89608c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89618c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
89628c2ecf20Sopenharmony_ci		/* 1G support */
89638c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89648c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
89658c2ecf20Sopenharmony_ci
89668c2ecf20Sopenharmony_ci		/* Enable clause 73 AN */
89678c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89688c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
89698c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89708c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
89718c2ecf20Sopenharmony_ci				 0x0400);
89728c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89738c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
89748c2ecf20Sopenharmony_ci				 0x0004);
89758c2ecf20Sopenharmony_ci	}
89768c2ecf20Sopenharmony_ci	bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
89778c2ecf20Sopenharmony_ci
89788c2ecf20Sopenharmony_ci	/* If TX Laser is controlled by GPIO_0, do not let PHY go into low
89798c2ecf20Sopenharmony_ci	 * power mode, if TX Laser is disabled
89808c2ecf20Sopenharmony_ci	 */
89818c2ecf20Sopenharmony_ci
89828c2ecf20Sopenharmony_ci	tx_en_mode = REG_RD(bp, params->shmem_base +
89838c2ecf20Sopenharmony_ci			    offsetof(struct shmem_region,
89848c2ecf20Sopenharmony_ci				dev_info.port_hw_config[params->port].sfp_ctrl))
89858c2ecf20Sopenharmony_ci			& PORT_HW_CFG_TX_LASER_MASK;
89868c2ecf20Sopenharmony_ci
89878c2ecf20Sopenharmony_ci	if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
89888c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
89898c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
89908c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
89918c2ecf20Sopenharmony_ci		tmp1 |= 0x1;
89928c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
89938c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
89948c2ecf20Sopenharmony_ci	}
89958c2ecf20Sopenharmony_ci}
89968c2ecf20Sopenharmony_ci
89978c2ecf20Sopenharmony_cistatic u8 bnx2x_8706_read_status(struct bnx2x_phy *phy,
89988c2ecf20Sopenharmony_ci				 struct link_params *params,
89998c2ecf20Sopenharmony_ci				 struct link_vars *vars)
90008c2ecf20Sopenharmony_ci{
90018c2ecf20Sopenharmony_ci	return bnx2x_8706_8726_read_status(phy, params, vars);
90028c2ecf20Sopenharmony_ci}
90038c2ecf20Sopenharmony_ci
90048c2ecf20Sopenharmony_ci/******************************************************************/
90058c2ecf20Sopenharmony_ci/*			BCM8726 PHY SECTION			  */
90068c2ecf20Sopenharmony_ci/******************************************************************/
90078c2ecf20Sopenharmony_cistatic void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
90088c2ecf20Sopenharmony_ci				       struct link_params *params)
90098c2ecf20Sopenharmony_ci{
90108c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
90118c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
90128c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
90138c2ecf20Sopenharmony_ci}
90148c2ecf20Sopenharmony_ci
90158c2ecf20Sopenharmony_cistatic void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
90168c2ecf20Sopenharmony_ci					 struct link_params *params)
90178c2ecf20Sopenharmony_ci{
90188c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
90198c2ecf20Sopenharmony_ci	/* Need to wait 100ms after reset */
90208c2ecf20Sopenharmony_ci	msleep(100);
90218c2ecf20Sopenharmony_ci
90228c2ecf20Sopenharmony_ci	/* Micro controller re-boot */
90238c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
90248c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
90258c2ecf20Sopenharmony_ci
90268c2ecf20Sopenharmony_ci	/* Set soft reset */
90278c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
90288c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
90298c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
90308c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
90318c2ecf20Sopenharmony_ci
90328c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
90338c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
90348c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
90358c2ecf20Sopenharmony_ci
90368c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
90378c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
90388c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL,
90398c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
90408c2ecf20Sopenharmony_ci
90418c2ecf20Sopenharmony_ci	/* Wait for 150ms for microcode load */
90428c2ecf20Sopenharmony_ci	msleep(150);
90438c2ecf20Sopenharmony_ci
90448c2ecf20Sopenharmony_ci	/* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
90458c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
90468c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
90478c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
90488c2ecf20Sopenharmony_ci
90498c2ecf20Sopenharmony_ci	msleep(200);
90508c2ecf20Sopenharmony_ci	bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
90518c2ecf20Sopenharmony_ci}
90528c2ecf20Sopenharmony_ci
90538c2ecf20Sopenharmony_cistatic u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
90548c2ecf20Sopenharmony_ci				 struct link_params *params,
90558c2ecf20Sopenharmony_ci				 struct link_vars *vars)
90568c2ecf20Sopenharmony_ci{
90578c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
90588c2ecf20Sopenharmony_ci	u16 val1;
90598c2ecf20Sopenharmony_ci	u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
90608c2ecf20Sopenharmony_ci	if (link_up) {
90618c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
90628c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
90638c2ecf20Sopenharmony_ci				&val1);
90648c2ecf20Sopenharmony_ci		if (val1 & (1<<15)) {
90658c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Tx is disabled\n");
90668c2ecf20Sopenharmony_ci			link_up = 0;
90678c2ecf20Sopenharmony_ci			vars->line_speed = 0;
90688c2ecf20Sopenharmony_ci		}
90698c2ecf20Sopenharmony_ci	}
90708c2ecf20Sopenharmony_ci	return link_up;
90718c2ecf20Sopenharmony_ci}
90728c2ecf20Sopenharmony_ci
90738c2ecf20Sopenharmony_ci
90748c2ecf20Sopenharmony_cistatic void bnx2x_8726_config_init(struct bnx2x_phy *phy,
90758c2ecf20Sopenharmony_ci				   struct link_params *params,
90768c2ecf20Sopenharmony_ci				   struct link_vars *vars)
90778c2ecf20Sopenharmony_ci{
90788c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
90798c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
90808c2ecf20Sopenharmony_ci
90818c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
90828c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
90838c2ecf20Sopenharmony_ci
90848c2ecf20Sopenharmony_ci	bnx2x_8726_external_rom_boot(phy, params);
90858c2ecf20Sopenharmony_ci
90868c2ecf20Sopenharmony_ci	/* Need to call module detected on initialization since the module
90878c2ecf20Sopenharmony_ci	 * detection triggered by actual module insertion might occur before
90888c2ecf20Sopenharmony_ci	 * driver is loaded, and when driver is loaded, it reset all
90898c2ecf20Sopenharmony_ci	 * registers, including the transmitter
90908c2ecf20Sopenharmony_ci	 */
90918c2ecf20Sopenharmony_ci	bnx2x_sfp_module_detection(phy, params);
90928c2ecf20Sopenharmony_ci
90938c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_1000) {
90948c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 1G force\n");
90958c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
90968c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
90978c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
90988c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
90998c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91008c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
91018c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91028c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
91038c2ecf20Sopenharmony_ci				 0x400);
91048c2ecf20Sopenharmony_ci	} else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
91058c2ecf20Sopenharmony_ci		   (phy->speed_cap_mask &
91068c2ecf20Sopenharmony_ci		      PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
91078c2ecf20Sopenharmony_ci		   ((phy->speed_cap_mask &
91088c2ecf20Sopenharmony_ci		      PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
91098c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
91108c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
91118c2ecf20Sopenharmony_ci		/* Set Flow control */
91128c2ecf20Sopenharmony_ci		bnx2x_ext_phy_set_pause(params, phy, vars);
91138c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91148c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
91158c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91168c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
91178c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91188c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
91198c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91208c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
91218c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91228c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
91238c2ecf20Sopenharmony_ci		/* Enable RX-ALARM control to receive interrupt for 1G speed
91248c2ecf20Sopenharmony_ci		 * change
91258c2ecf20Sopenharmony_ci		 */
91268c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91278c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
91288c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91298c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
91308c2ecf20Sopenharmony_ci				 0x400);
91318c2ecf20Sopenharmony_ci
91328c2ecf20Sopenharmony_ci	} else { /* Default 10G. Set only LASI control */
91338c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91348c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
91358c2ecf20Sopenharmony_ci	}
91368c2ecf20Sopenharmony_ci
91378c2ecf20Sopenharmony_ci	/* Set TX PreEmphasis if needed */
91388c2ecf20Sopenharmony_ci	if ((params->feature_config_flags &
91398c2ecf20Sopenharmony_ci	     FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
91408c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
91418c2ecf20Sopenharmony_ci		   "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
91428c2ecf20Sopenharmony_ci			 phy->tx_preemphasis[0],
91438c2ecf20Sopenharmony_ci			 phy->tx_preemphasis[1]);
91448c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91458c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
91468c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_8726_TX_CTRL1,
91478c2ecf20Sopenharmony_ci				 phy->tx_preemphasis[0]);
91488c2ecf20Sopenharmony_ci
91498c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
91508c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
91518c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_8726_TX_CTRL2,
91528c2ecf20Sopenharmony_ci				 phy->tx_preemphasis[1]);
91538c2ecf20Sopenharmony_ci	}
91548c2ecf20Sopenharmony_ci}
91558c2ecf20Sopenharmony_ci
91568c2ecf20Sopenharmony_cistatic void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
91578c2ecf20Sopenharmony_ci				  struct link_params *params)
91588c2ecf20Sopenharmony_ci{
91598c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
91608c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
91618c2ecf20Sopenharmony_ci	/* Set serial boot control for external load */
91628c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
91638c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
91648c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_GEN_CTRL, 0x0001);
91658c2ecf20Sopenharmony_ci}
91668c2ecf20Sopenharmony_ci
91678c2ecf20Sopenharmony_ci/******************************************************************/
91688c2ecf20Sopenharmony_ci/*			BCM8727 PHY SECTION			  */
91698c2ecf20Sopenharmony_ci/******************************************************************/
91708c2ecf20Sopenharmony_ci
91718c2ecf20Sopenharmony_cistatic void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
91728c2ecf20Sopenharmony_ci				    struct link_params *params, u8 mode)
91738c2ecf20Sopenharmony_ci{
91748c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
91758c2ecf20Sopenharmony_ci	u16 led_mode_bitmask = 0;
91768c2ecf20Sopenharmony_ci	u16 gpio_pins_bitmask = 0;
91778c2ecf20Sopenharmony_ci	u16 val;
91788c2ecf20Sopenharmony_ci	/* Only NOC flavor requires to set the LED specifically */
91798c2ecf20Sopenharmony_ci	if (!(phy->flags & FLAGS_NOC))
91808c2ecf20Sopenharmony_ci		return;
91818c2ecf20Sopenharmony_ci	switch (mode) {
91828c2ecf20Sopenharmony_ci	case LED_MODE_FRONT_PANEL_OFF:
91838c2ecf20Sopenharmony_ci	case LED_MODE_OFF:
91848c2ecf20Sopenharmony_ci		led_mode_bitmask = 0;
91858c2ecf20Sopenharmony_ci		gpio_pins_bitmask = 0x03;
91868c2ecf20Sopenharmony_ci		break;
91878c2ecf20Sopenharmony_ci	case LED_MODE_ON:
91888c2ecf20Sopenharmony_ci		led_mode_bitmask = 0;
91898c2ecf20Sopenharmony_ci		gpio_pins_bitmask = 0x02;
91908c2ecf20Sopenharmony_ci		break;
91918c2ecf20Sopenharmony_ci	case LED_MODE_OPER:
91928c2ecf20Sopenharmony_ci		led_mode_bitmask = 0x60;
91938c2ecf20Sopenharmony_ci		gpio_pins_bitmask = 0x11;
91948c2ecf20Sopenharmony_ci		break;
91958c2ecf20Sopenharmony_ci	}
91968c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
91978c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
91988c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8727_PCS_OPT_CTRL,
91998c2ecf20Sopenharmony_ci			&val);
92008c2ecf20Sopenharmony_ci	val &= 0xff8f;
92018c2ecf20Sopenharmony_ci	val |= led_mode_bitmask;
92028c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
92038c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
92048c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
92058c2ecf20Sopenharmony_ci			 val);
92068c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
92078c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
92088c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8727_GPIO_CTRL,
92098c2ecf20Sopenharmony_ci			&val);
92108c2ecf20Sopenharmony_ci	val &= 0xffe0;
92118c2ecf20Sopenharmony_ci	val |= gpio_pins_bitmask;
92128c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
92138c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
92148c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8727_GPIO_CTRL,
92158c2ecf20Sopenharmony_ci			 val);
92168c2ecf20Sopenharmony_ci}
92178c2ecf20Sopenharmony_cistatic void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
92188c2ecf20Sopenharmony_ci				struct link_params *params) {
92198c2ecf20Sopenharmony_ci	u32 swap_val, swap_override;
92208c2ecf20Sopenharmony_ci	u8 port;
92218c2ecf20Sopenharmony_ci	/* The PHY reset is controlled by GPIO 1. Fake the port number
92228c2ecf20Sopenharmony_ci	 * to cancel the swap done in set_gpio()
92238c2ecf20Sopenharmony_ci	 */
92248c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
92258c2ecf20Sopenharmony_ci	swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
92268c2ecf20Sopenharmony_ci	swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
92278c2ecf20Sopenharmony_ci	port = (swap_val && swap_override) ^ 1;
92288c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
92298c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
92308c2ecf20Sopenharmony_ci}
92318c2ecf20Sopenharmony_ci
92328c2ecf20Sopenharmony_cistatic void bnx2x_8727_config_speed(struct bnx2x_phy *phy,
92338c2ecf20Sopenharmony_ci				    struct link_params *params)
92348c2ecf20Sopenharmony_ci{
92358c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
92368c2ecf20Sopenharmony_ci	u16 tmp1, val;
92378c2ecf20Sopenharmony_ci	/* Set option 1G speed */
92388c2ecf20Sopenharmony_ci	if ((phy->req_line_speed == SPEED_1000) ||
92398c2ecf20Sopenharmony_ci	    (phy->media_type == ETH_PHY_SFP_1G_FIBER)) {
92408c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 1G force\n");
92418c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92428c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
92438c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92448c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
92458c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
92468c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
92478c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
92488c2ecf20Sopenharmony_ci		/* Power down the XAUI until link is up in case of dual-media
92498c2ecf20Sopenharmony_ci		 * and 1G
92508c2ecf20Sopenharmony_ci		 */
92518c2ecf20Sopenharmony_ci		if (DUAL_MEDIA(params)) {
92528c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
92538c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
92548c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8727_PCS_GP, &val);
92558c2ecf20Sopenharmony_ci			val |= (3<<10);
92568c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
92578c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
92588c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8727_PCS_GP, val);
92598c2ecf20Sopenharmony_ci		}
92608c2ecf20Sopenharmony_ci	} else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
92618c2ecf20Sopenharmony_ci		   ((phy->speed_cap_mask &
92628c2ecf20Sopenharmony_ci		     PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
92638c2ecf20Sopenharmony_ci		   ((phy->speed_cap_mask &
92648c2ecf20Sopenharmony_ci		      PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
92658c2ecf20Sopenharmony_ci		   PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
92668c2ecf20Sopenharmony_ci
92678c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
92688c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92698c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
92708c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92718c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
92728c2ecf20Sopenharmony_ci	} else {
92738c2ecf20Sopenharmony_ci		/* Since the 8727 has only single reset pin, need to set the 10G
92748c2ecf20Sopenharmony_ci		 * registers although it is default
92758c2ecf20Sopenharmony_ci		 */
92768c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92778c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
92788c2ecf20Sopenharmony_ci				 0x0020);
92798c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92808c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
92818c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92828c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
92838c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
92848c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
92858c2ecf20Sopenharmony_ci				 0x0008);
92868c2ecf20Sopenharmony_ci	}
92878c2ecf20Sopenharmony_ci}
92888c2ecf20Sopenharmony_ci
92898c2ecf20Sopenharmony_cistatic void bnx2x_8727_config_init(struct bnx2x_phy *phy,
92908c2ecf20Sopenharmony_ci				   struct link_params *params,
92918c2ecf20Sopenharmony_ci				   struct link_vars *vars)
92928c2ecf20Sopenharmony_ci{
92938c2ecf20Sopenharmony_ci	u32 tx_en_mode;
92948c2ecf20Sopenharmony_ci	u16 tmp1, mod_abs, tmp2;
92958c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
92968c2ecf20Sopenharmony_ci	/* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
92978c2ecf20Sopenharmony_ci
92988c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
92998c2ecf20Sopenharmony_ci
93008c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
93018c2ecf20Sopenharmony_ci
93028c2ecf20Sopenharmony_ci	bnx2x_8727_specific_func(phy, params, PHY_INIT);
93038c2ecf20Sopenharmony_ci	/* Initially configure MOD_ABS to interrupt when module is
93048c2ecf20Sopenharmony_ci	 * presence( bit 8)
93058c2ecf20Sopenharmony_ci	 */
93068c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
93078c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
93088c2ecf20Sopenharmony_ci	/* Set EDC off by setting OPTXLOS signal input to low (bit 9).
93098c2ecf20Sopenharmony_ci	 * When the EDC is off it locks onto a reference clock and avoids
93108c2ecf20Sopenharmony_ci	 * becoming 'lost'
93118c2ecf20Sopenharmony_ci	 */
93128c2ecf20Sopenharmony_ci	mod_abs &= ~(1<<8);
93138c2ecf20Sopenharmony_ci	if (!(phy->flags & FLAGS_NOC))
93148c2ecf20Sopenharmony_ci		mod_abs &= ~(1<<9);
93158c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
93168c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
93178c2ecf20Sopenharmony_ci
93188c2ecf20Sopenharmony_ci	/* Enable/Disable PHY transmitter output */
93198c2ecf20Sopenharmony_ci	bnx2x_set_disable_pmd_transmit(params, phy, 0);
93208c2ecf20Sopenharmony_ci
93218c2ecf20Sopenharmony_ci	bnx2x_8727_power_module(bp, phy, 1);
93228c2ecf20Sopenharmony_ci
93238c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
93248c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
93258c2ecf20Sopenharmony_ci
93268c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
93278c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
93288c2ecf20Sopenharmony_ci
93298c2ecf20Sopenharmony_ci	bnx2x_8727_config_speed(phy, params);
93308c2ecf20Sopenharmony_ci
93318c2ecf20Sopenharmony_ci
93328c2ecf20Sopenharmony_ci	/* Set TX PreEmphasis if needed */
93338c2ecf20Sopenharmony_ci	if ((params->feature_config_flags &
93348c2ecf20Sopenharmony_ci	     FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
93358c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
93368c2ecf20Sopenharmony_ci			   phy->tx_preemphasis[0],
93378c2ecf20Sopenharmony_ci			   phy->tx_preemphasis[1]);
93388c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
93398c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
93408c2ecf20Sopenharmony_ci				 phy->tx_preemphasis[0]);
93418c2ecf20Sopenharmony_ci
93428c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
93438c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
93448c2ecf20Sopenharmony_ci				 phy->tx_preemphasis[1]);
93458c2ecf20Sopenharmony_ci	}
93468c2ecf20Sopenharmony_ci
93478c2ecf20Sopenharmony_ci	/* If TX Laser is controlled by GPIO_0, do not let PHY go into low
93488c2ecf20Sopenharmony_ci	 * power mode, if TX Laser is disabled
93498c2ecf20Sopenharmony_ci	 */
93508c2ecf20Sopenharmony_ci	tx_en_mode = REG_RD(bp, params->shmem_base +
93518c2ecf20Sopenharmony_ci			    offsetof(struct shmem_region,
93528c2ecf20Sopenharmony_ci				dev_info.port_hw_config[params->port].sfp_ctrl))
93538c2ecf20Sopenharmony_ci			& PORT_HW_CFG_TX_LASER_MASK;
93548c2ecf20Sopenharmony_ci
93558c2ecf20Sopenharmony_ci	if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
93568c2ecf20Sopenharmony_ci
93578c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
93588c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
93598c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
93608c2ecf20Sopenharmony_ci		tmp2 |= 0x1000;
93618c2ecf20Sopenharmony_ci		tmp2 &= 0xFFEF;
93628c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
93638c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
93648c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
93658c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
93668c2ecf20Sopenharmony_ci				&tmp2);
93678c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
93688c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
93698c2ecf20Sopenharmony_ci				 (tmp2 & 0x7fff));
93708c2ecf20Sopenharmony_ci	}
93718c2ecf20Sopenharmony_ci}
93728c2ecf20Sopenharmony_ci
93738c2ecf20Sopenharmony_cistatic void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
93748c2ecf20Sopenharmony_ci				      struct link_params *params)
93758c2ecf20Sopenharmony_ci{
93768c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
93778c2ecf20Sopenharmony_ci	u16 mod_abs, rx_alarm_status;
93788c2ecf20Sopenharmony_ci	u32 val = REG_RD(bp, params->shmem_base +
93798c2ecf20Sopenharmony_ci			     offsetof(struct shmem_region, dev_info.
93808c2ecf20Sopenharmony_ci				      port_feature_config[params->port].
93818c2ecf20Sopenharmony_ci				      config));
93828c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
93838c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
93848c2ecf20Sopenharmony_ci			MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
93858c2ecf20Sopenharmony_ci	if (mod_abs & (1<<8)) {
93868c2ecf20Sopenharmony_ci
93878c2ecf20Sopenharmony_ci		/* Module is absent */
93888c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
93898c2ecf20Sopenharmony_ci		   "MOD_ABS indication show module is absent\n");
93908c2ecf20Sopenharmony_ci		phy->media_type = ETH_PHY_NOT_PRESENT;
93918c2ecf20Sopenharmony_ci		/* 1. Set mod_abs to detect next module
93928c2ecf20Sopenharmony_ci		 *    presence event
93938c2ecf20Sopenharmony_ci		 * 2. Set EDC off by setting OPTXLOS signal input to low
93948c2ecf20Sopenharmony_ci		 *    (bit 9).
93958c2ecf20Sopenharmony_ci		 *    When the EDC is off it locks onto a reference clock and
93968c2ecf20Sopenharmony_ci		 *    avoids becoming 'lost'.
93978c2ecf20Sopenharmony_ci		 */
93988c2ecf20Sopenharmony_ci		mod_abs &= ~(1<<8);
93998c2ecf20Sopenharmony_ci		if (!(phy->flags & FLAGS_NOC))
94008c2ecf20Sopenharmony_ci			mod_abs &= ~(1<<9);
94018c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
94028c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
94038c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
94048c2ecf20Sopenharmony_ci
94058c2ecf20Sopenharmony_ci		/* Clear RX alarm since it stays up as long as
94068c2ecf20Sopenharmony_ci		 * the mod_abs wasn't changed
94078c2ecf20Sopenharmony_ci		 */
94088c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
94098c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
94108c2ecf20Sopenharmony_ci				MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
94118c2ecf20Sopenharmony_ci
94128c2ecf20Sopenharmony_ci	} else {
94138c2ecf20Sopenharmony_ci		/* Module is present */
94148c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
94158c2ecf20Sopenharmony_ci		   "MOD_ABS indication show module is present\n");
94168c2ecf20Sopenharmony_ci		/* First disable transmitter, and if the module is ok, the
94178c2ecf20Sopenharmony_ci		 * module_detection will enable it
94188c2ecf20Sopenharmony_ci		 * 1. Set mod_abs to detect next module absent event ( bit 8)
94198c2ecf20Sopenharmony_ci		 * 2. Restore the default polarity of the OPRXLOS signal and
94208c2ecf20Sopenharmony_ci		 * this signal will then correctly indicate the presence or
94218c2ecf20Sopenharmony_ci		 * absence of the Rx signal. (bit 9)
94228c2ecf20Sopenharmony_ci		 */
94238c2ecf20Sopenharmony_ci		mod_abs |= (1<<8);
94248c2ecf20Sopenharmony_ci		if (!(phy->flags & FLAGS_NOC))
94258c2ecf20Sopenharmony_ci			mod_abs |= (1<<9);
94268c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
94278c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
94288c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
94298c2ecf20Sopenharmony_ci
94308c2ecf20Sopenharmony_ci		/* Clear RX alarm since it stays up as long as the mod_abs
94318c2ecf20Sopenharmony_ci		 * wasn't changed. This is need to be done before calling the
94328c2ecf20Sopenharmony_ci		 * module detection, otherwise it will clear* the link update
94338c2ecf20Sopenharmony_ci		 * alarm
94348c2ecf20Sopenharmony_ci		 */
94358c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
94368c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
94378c2ecf20Sopenharmony_ci				MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
94388c2ecf20Sopenharmony_ci
94398c2ecf20Sopenharmony_ci
94408c2ecf20Sopenharmony_ci		if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
94418c2ecf20Sopenharmony_ci		    PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
94428c2ecf20Sopenharmony_ci			bnx2x_sfp_set_transmitter(params, phy, 0);
94438c2ecf20Sopenharmony_ci
94448c2ecf20Sopenharmony_ci		if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
94458c2ecf20Sopenharmony_ci			bnx2x_sfp_module_detection(phy, params);
94468c2ecf20Sopenharmony_ci		else
94478c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
94488c2ecf20Sopenharmony_ci
94498c2ecf20Sopenharmony_ci		/* Reconfigure link speed based on module type limitations */
94508c2ecf20Sopenharmony_ci		bnx2x_8727_config_speed(phy, params);
94518c2ecf20Sopenharmony_ci	}
94528c2ecf20Sopenharmony_ci
94538c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
94548c2ecf20Sopenharmony_ci		   rx_alarm_status);
94558c2ecf20Sopenharmony_ci	/* No need to check link status in case of module plugged in/out */
94568c2ecf20Sopenharmony_ci}
94578c2ecf20Sopenharmony_ci
94588c2ecf20Sopenharmony_cistatic u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
94598c2ecf20Sopenharmony_ci				 struct link_params *params,
94608c2ecf20Sopenharmony_ci				 struct link_vars *vars)
94618c2ecf20Sopenharmony_ci
94628c2ecf20Sopenharmony_ci{
94638c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
94648c2ecf20Sopenharmony_ci	u8 link_up = 0, oc_port = params->port;
94658c2ecf20Sopenharmony_ci	u16 link_status = 0;
94668c2ecf20Sopenharmony_ci	u16 rx_alarm_status, lasi_ctrl, val1;
94678c2ecf20Sopenharmony_ci
94688c2ecf20Sopenharmony_ci	/* If PHY is not initialized, do not check link status */
94698c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
94708c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
94718c2ecf20Sopenharmony_ci			&lasi_ctrl);
94728c2ecf20Sopenharmony_ci	if (!lasi_ctrl)
94738c2ecf20Sopenharmony_ci		return 0;
94748c2ecf20Sopenharmony_ci
94758c2ecf20Sopenharmony_ci	/* Check the LASI on Rx */
94768c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
94778c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
94788c2ecf20Sopenharmony_ci			&rx_alarm_status);
94798c2ecf20Sopenharmony_ci	vars->line_speed = 0;
94808c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS  0x%x\n", rx_alarm_status);
94818c2ecf20Sopenharmony_ci
94828c2ecf20Sopenharmony_ci	bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
94838c2ecf20Sopenharmony_ci			     MDIO_PMA_LASI_TXCTRL);
94848c2ecf20Sopenharmony_ci
94858c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
94868c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
94878c2ecf20Sopenharmony_ci
94888c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
94898c2ecf20Sopenharmony_ci
94908c2ecf20Sopenharmony_ci	/* Clear MSG-OUT */
94918c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
94928c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
94938c2ecf20Sopenharmony_ci
94948c2ecf20Sopenharmony_ci	/* If a module is present and there is need to check
94958c2ecf20Sopenharmony_ci	 * for over current
94968c2ecf20Sopenharmony_ci	 */
94978c2ecf20Sopenharmony_ci	if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
94988c2ecf20Sopenharmony_ci		/* Check over-current using 8727 GPIO0 input*/
94998c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
95008c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
95018c2ecf20Sopenharmony_ci				&val1);
95028c2ecf20Sopenharmony_ci
95038c2ecf20Sopenharmony_ci		if ((val1 & (1<<8)) == 0) {
95048c2ecf20Sopenharmony_ci			if (!CHIP_IS_E1x(bp))
95058c2ecf20Sopenharmony_ci				oc_port = BP_PATH(bp) + (params->port << 1);
95068c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
95078c2ecf20Sopenharmony_ci			   "8727 Power fault has been detected on port %d\n",
95088c2ecf20Sopenharmony_ci			   oc_port);
95098c2ecf20Sopenharmony_ci			netdev_err(bp->dev, "Error: Power fault on Port %d has "
95108c2ecf20Sopenharmony_ci					    "been detected and the power to "
95118c2ecf20Sopenharmony_ci					    "that SFP+ module has been removed "
95128c2ecf20Sopenharmony_ci					    "to prevent failure of the card. "
95138c2ecf20Sopenharmony_ci					    "Please remove the SFP+ module and "
95148c2ecf20Sopenharmony_ci					    "restart the system to clear this "
95158c2ecf20Sopenharmony_ci					    "error.\n",
95168c2ecf20Sopenharmony_ci			 oc_port);
95178c2ecf20Sopenharmony_ci			/* Disable all RX_ALARMs except for mod_abs */
95188c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
95198c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
95208c2ecf20Sopenharmony_ci					 MDIO_PMA_LASI_RXCTRL, (1<<5));
95218c2ecf20Sopenharmony_ci
95228c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
95238c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
95248c2ecf20Sopenharmony_ci					MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
95258c2ecf20Sopenharmony_ci			/* Wait for module_absent_event */
95268c2ecf20Sopenharmony_ci			val1 |= (1<<8);
95278c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
95288c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
95298c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
95308c2ecf20Sopenharmony_ci			/* Clear RX alarm */
95318c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
95328c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
95338c2ecf20Sopenharmony_ci				MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
95348c2ecf20Sopenharmony_ci			bnx2x_8727_power_module(params->bp, phy, 0);
95358c2ecf20Sopenharmony_ci			return 0;
95368c2ecf20Sopenharmony_ci		}
95378c2ecf20Sopenharmony_ci	} /* Over current check */
95388c2ecf20Sopenharmony_ci
95398c2ecf20Sopenharmony_ci	/* When module absent bit is set, check module */
95408c2ecf20Sopenharmony_ci	if (rx_alarm_status & (1<<5)) {
95418c2ecf20Sopenharmony_ci		bnx2x_8727_handle_mod_abs(phy, params);
95428c2ecf20Sopenharmony_ci		/* Enable all mod_abs and link detection bits */
95438c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
95448c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
95458c2ecf20Sopenharmony_ci				 ((1<<5) | (1<<2)));
95468c2ecf20Sopenharmony_ci	}
95478c2ecf20Sopenharmony_ci
95488c2ecf20Sopenharmony_ci	if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
95498c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
95508c2ecf20Sopenharmony_ci		bnx2x_sfp_set_transmitter(params, phy, 1);
95518c2ecf20Sopenharmony_ci	} else {
95528c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Tx is disabled\n");
95538c2ecf20Sopenharmony_ci		return 0;
95548c2ecf20Sopenharmony_ci	}
95558c2ecf20Sopenharmony_ci
95568c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
95578c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
95588c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
95598c2ecf20Sopenharmony_ci
95608c2ecf20Sopenharmony_ci	/* Bits 0..2 --> speed detected,
95618c2ecf20Sopenharmony_ci	 * Bits 13..15--> link is down
95628c2ecf20Sopenharmony_ci	 */
95638c2ecf20Sopenharmony_ci	if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
95648c2ecf20Sopenharmony_ci		link_up = 1;
95658c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
95668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
95678c2ecf20Sopenharmony_ci			   params->port);
95688c2ecf20Sopenharmony_ci	} else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
95698c2ecf20Sopenharmony_ci		link_up = 1;
95708c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_1000;
95718c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
95728c2ecf20Sopenharmony_ci			   params->port);
95738c2ecf20Sopenharmony_ci	} else {
95748c2ecf20Sopenharmony_ci		link_up = 0;
95758c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "port %x: External link is down\n",
95768c2ecf20Sopenharmony_ci			   params->port);
95778c2ecf20Sopenharmony_ci	}
95788c2ecf20Sopenharmony_ci
95798c2ecf20Sopenharmony_ci	/* Capture 10G link fault. */
95808c2ecf20Sopenharmony_ci	if (vars->line_speed == SPEED_10000) {
95818c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
95828c2ecf20Sopenharmony_ci			    MDIO_PMA_LASI_TXSTAT, &val1);
95838c2ecf20Sopenharmony_ci
95848c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
95858c2ecf20Sopenharmony_ci			    MDIO_PMA_LASI_TXSTAT, &val1);
95868c2ecf20Sopenharmony_ci
95878c2ecf20Sopenharmony_ci		if (val1 & (1<<0)) {
95888c2ecf20Sopenharmony_ci			vars->fault_detected = 1;
95898c2ecf20Sopenharmony_ci		}
95908c2ecf20Sopenharmony_ci	}
95918c2ecf20Sopenharmony_ci
95928c2ecf20Sopenharmony_ci	if (link_up) {
95938c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
95948c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
95958c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
95968c2ecf20Sopenharmony_ci	}
95978c2ecf20Sopenharmony_ci
95988c2ecf20Sopenharmony_ci	if ((DUAL_MEDIA(params)) &&
95998c2ecf20Sopenharmony_ci	    (phy->req_line_speed == SPEED_1000)) {
96008c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
96018c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
96028c2ecf20Sopenharmony_ci				MDIO_PMA_REG_8727_PCS_GP, &val1);
96038c2ecf20Sopenharmony_ci		/* In case of dual-media board and 1G, power up the XAUI side,
96048c2ecf20Sopenharmony_ci		 * otherwise power it down. For 10G it is done automatically
96058c2ecf20Sopenharmony_ci		 */
96068c2ecf20Sopenharmony_ci		if (link_up)
96078c2ecf20Sopenharmony_ci			val1 &= ~(3<<10);
96088c2ecf20Sopenharmony_ci		else
96098c2ecf20Sopenharmony_ci			val1 |= (3<<10);
96108c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
96118c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
96128c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_8727_PCS_GP, val1);
96138c2ecf20Sopenharmony_ci	}
96148c2ecf20Sopenharmony_ci	return link_up;
96158c2ecf20Sopenharmony_ci}
96168c2ecf20Sopenharmony_ci
96178c2ecf20Sopenharmony_cistatic void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
96188c2ecf20Sopenharmony_ci				  struct link_params *params)
96198c2ecf20Sopenharmony_ci{
96208c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
96218c2ecf20Sopenharmony_ci
96228c2ecf20Sopenharmony_ci	/* Enable/Disable PHY transmitter output */
96238c2ecf20Sopenharmony_ci	bnx2x_set_disable_pmd_transmit(params, phy, 1);
96248c2ecf20Sopenharmony_ci
96258c2ecf20Sopenharmony_ci	/* Disable Transmitter */
96268c2ecf20Sopenharmony_ci	bnx2x_sfp_set_transmitter(params, phy, 0);
96278c2ecf20Sopenharmony_ci	/* Clear LASI */
96288c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
96298c2ecf20Sopenharmony_ci
96308c2ecf20Sopenharmony_ci}
96318c2ecf20Sopenharmony_ci
96328c2ecf20Sopenharmony_ci/******************************************************************/
96338c2ecf20Sopenharmony_ci/*		BCM8481/BCM84823/BCM84833 PHY SECTION	          */
96348c2ecf20Sopenharmony_ci/******************************************************************/
96358c2ecf20Sopenharmony_cistatic int bnx2x_is_8483x_8485x(struct bnx2x_phy *phy)
96368c2ecf20Sopenharmony_ci{
96378c2ecf20Sopenharmony_ci	return ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
96388c2ecf20Sopenharmony_ci		(phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) ||
96398c2ecf20Sopenharmony_ci		(phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858));
96408c2ecf20Sopenharmony_ci}
96418c2ecf20Sopenharmony_ci
96428c2ecf20Sopenharmony_cistatic void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
96438c2ecf20Sopenharmony_ci					    struct bnx2x *bp,
96448c2ecf20Sopenharmony_ci					    u8 port)
96458c2ecf20Sopenharmony_ci{
96468c2ecf20Sopenharmony_ci	u16 val, fw_ver2, cnt, i;
96478c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
96488c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, 0xA819, 0x0014},
96498c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, 0xA81A, 0xc200},
96508c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, 0xA81B, 0x0000},
96518c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, 0xA81C, 0x0300},
96528c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, 0xA817, 0x0009}
96538c2ecf20Sopenharmony_ci	};
96548c2ecf20Sopenharmony_ci	u16 fw_ver1;
96558c2ecf20Sopenharmony_ci
96568c2ecf20Sopenharmony_ci	if (bnx2x_is_8483x_8485x(phy)) {
96578c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
96588c2ecf20Sopenharmony_ci		if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
96598c2ecf20Sopenharmony_ci			fw_ver1 &= 0xfff;
96608c2ecf20Sopenharmony_ci		bnx2x_save_spirom_version(bp, port, fw_ver1, phy->ver_addr);
96618c2ecf20Sopenharmony_ci	} else {
96628c2ecf20Sopenharmony_ci		/* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
96638c2ecf20Sopenharmony_ci		/* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
96648c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(reg_set); i++)
96658c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy, reg_set[i].devad,
96668c2ecf20Sopenharmony_ci					 reg_set[i].reg, reg_set[i].val);
96678c2ecf20Sopenharmony_ci
96688c2ecf20Sopenharmony_ci		for (cnt = 0; cnt < 100; cnt++) {
96698c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
96708c2ecf20Sopenharmony_ci			if (val & 1)
96718c2ecf20Sopenharmony_ci				break;
96728c2ecf20Sopenharmony_ci			udelay(5);
96738c2ecf20Sopenharmony_ci		}
96748c2ecf20Sopenharmony_ci		if (cnt == 100) {
96758c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Unable to read 848xx "
96768c2ecf20Sopenharmony_ci					"phy fw version(1)\n");
96778c2ecf20Sopenharmony_ci			bnx2x_save_spirom_version(bp, port, 0,
96788c2ecf20Sopenharmony_ci						  phy->ver_addr);
96798c2ecf20Sopenharmony_ci			return;
96808c2ecf20Sopenharmony_ci		}
96818c2ecf20Sopenharmony_ci
96828c2ecf20Sopenharmony_ci
96838c2ecf20Sopenharmony_ci		/* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
96848c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
96858c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
96868c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
96878c2ecf20Sopenharmony_ci		for (cnt = 0; cnt < 100; cnt++) {
96888c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
96898c2ecf20Sopenharmony_ci			if (val & 1)
96908c2ecf20Sopenharmony_ci				break;
96918c2ecf20Sopenharmony_ci			udelay(5);
96928c2ecf20Sopenharmony_ci		}
96938c2ecf20Sopenharmony_ci		if (cnt == 100) {
96948c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw "
96958c2ecf20Sopenharmony_ci					"version(2)\n");
96968c2ecf20Sopenharmony_ci			bnx2x_save_spirom_version(bp, port, 0,
96978c2ecf20Sopenharmony_ci						  phy->ver_addr);
96988c2ecf20Sopenharmony_ci			return;
96998c2ecf20Sopenharmony_ci		}
97008c2ecf20Sopenharmony_ci
97018c2ecf20Sopenharmony_ci		/* lower 16 bits of the register SPI_FW_STATUS */
97028c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
97038c2ecf20Sopenharmony_ci		/* upper 16 bits of register SPI_FW_STATUS */
97048c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
97058c2ecf20Sopenharmony_ci
97068c2ecf20Sopenharmony_ci		bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
97078c2ecf20Sopenharmony_ci					  phy->ver_addr);
97088c2ecf20Sopenharmony_ci	}
97098c2ecf20Sopenharmony_ci
97108c2ecf20Sopenharmony_ci}
97118c2ecf20Sopenharmony_cistatic void bnx2x_848xx_set_led(struct bnx2x *bp,
97128c2ecf20Sopenharmony_ci				struct bnx2x_phy *phy)
97138c2ecf20Sopenharmony_ci{
97148c2ecf20Sopenharmony_ci	u16 val, led3_blink_rate, offset, i;
97158c2ecf20Sopenharmony_ci	static struct bnx2x_reg_set reg_set[] = {
97168c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED1_MASK, 0x0080},
97178c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED2_MASK, 0x0018},
97188c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_MASK, 0x0006},
97198c2ecf20Sopenharmony_ci		{MDIO_PMA_DEVAD, MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
97208c2ecf20Sopenharmony_ci			MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ},
97218c2ecf20Sopenharmony_ci		{MDIO_AN_DEVAD, 0xFFFB, 0xFFFD}
97228c2ecf20Sopenharmony_ci	};
97238c2ecf20Sopenharmony_ci
97248c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
97258c2ecf20Sopenharmony_ci		/* Set LED5 source */
97268c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
97278c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
97288c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_8481_LED5_MASK,
97298c2ecf20Sopenharmony_ci				 0x90);
97308c2ecf20Sopenharmony_ci		led3_blink_rate = 0x000f;
97318c2ecf20Sopenharmony_ci	} else {
97328c2ecf20Sopenharmony_ci		led3_blink_rate = 0x0000;
97338c2ecf20Sopenharmony_ci	}
97348c2ecf20Sopenharmony_ci	/* Set LED3 BLINK */
97358c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
97368c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
97378c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8481_LED3_BLINK,
97388c2ecf20Sopenharmony_ci			 led3_blink_rate);
97398c2ecf20Sopenharmony_ci
97408c2ecf20Sopenharmony_ci	/* PHYC_CTL_LED_CTL */
97418c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
97428c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
97438c2ecf20Sopenharmony_ci			MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
97448c2ecf20Sopenharmony_ci	val &= 0xFE00;
97458c2ecf20Sopenharmony_ci	val |= 0x0092;
97468c2ecf20Sopenharmony_ci
97478c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
97488c2ecf20Sopenharmony_ci		val |= 2 << 12; /* LED5 ON based on source */
97498c2ecf20Sopenharmony_ci
97508c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
97518c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
97528c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
97538c2ecf20Sopenharmony_ci
97548c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(reg_set); i++)
97558c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
97568c2ecf20Sopenharmony_ci				 reg_set[i].val);
97578c2ecf20Sopenharmony_ci
97588c2ecf20Sopenharmony_ci	if (bnx2x_is_8483x_8485x(phy))
97598c2ecf20Sopenharmony_ci		offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
97608c2ecf20Sopenharmony_ci	else
97618c2ecf20Sopenharmony_ci		offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
97628c2ecf20Sopenharmony_ci
97638c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
97648c2ecf20Sopenharmony_ci		val = MDIO_PMA_REG_84858_ALLOW_GPHY_ACT |
97658c2ecf20Sopenharmony_ci		      MDIO_PMA_REG_84823_LED3_STRETCH_EN;
97668c2ecf20Sopenharmony_ci	else
97678c2ecf20Sopenharmony_ci		val = MDIO_PMA_REG_84823_LED3_STRETCH_EN;
97688c2ecf20Sopenharmony_ci
97698c2ecf20Sopenharmony_ci	/* stretch_en for LEDs */
97708c2ecf20Sopenharmony_ci	bnx2x_cl45_read_or_write(bp, phy,
97718c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
97728c2ecf20Sopenharmony_ci				 offset,
97738c2ecf20Sopenharmony_ci				 val);
97748c2ecf20Sopenharmony_ci}
97758c2ecf20Sopenharmony_ci
97768c2ecf20Sopenharmony_cistatic void bnx2x_848xx_specific_func(struct bnx2x_phy *phy,
97778c2ecf20Sopenharmony_ci				      struct link_params *params,
97788c2ecf20Sopenharmony_ci				      u32 action)
97798c2ecf20Sopenharmony_ci{
97808c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
97818c2ecf20Sopenharmony_ci	switch (action) {
97828c2ecf20Sopenharmony_ci	case PHY_INIT:
97838c2ecf20Sopenharmony_ci		if (bnx2x_is_8483x_8485x(phy)) {
97848c2ecf20Sopenharmony_ci			/* Save spirom version */
97858c2ecf20Sopenharmony_ci			bnx2x_save_848xx_spirom_version(phy, bp, params->port);
97868c2ecf20Sopenharmony_ci		}
97878c2ecf20Sopenharmony_ci		/* This phy uses the NIG latch mechanism since link indication
97888c2ecf20Sopenharmony_ci		 * arrives through its LED4 and not via its LASI signal, so we
97898c2ecf20Sopenharmony_ci		 * get steady signal instead of clear on read
97908c2ecf20Sopenharmony_ci		 */
97918c2ecf20Sopenharmony_ci		bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
97928c2ecf20Sopenharmony_ci			      1 << NIG_LATCH_BC_ENABLE_MI_INT);
97938c2ecf20Sopenharmony_ci
97948c2ecf20Sopenharmony_ci		bnx2x_848xx_set_led(bp, phy);
97958c2ecf20Sopenharmony_ci		break;
97968c2ecf20Sopenharmony_ci	}
97978c2ecf20Sopenharmony_ci}
97988c2ecf20Sopenharmony_ci
97998c2ecf20Sopenharmony_cistatic int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
98008c2ecf20Sopenharmony_ci				       struct link_params *params,
98018c2ecf20Sopenharmony_ci				       struct link_vars *vars)
98028c2ecf20Sopenharmony_ci{
98038c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
98048c2ecf20Sopenharmony_ci	u16 autoneg_val, an_1000_val, an_10_100_val;
98058c2ecf20Sopenharmony_ci
98068c2ecf20Sopenharmony_ci	bnx2x_848xx_specific_func(phy, params, PHY_INIT);
98078c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
98088c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
98098c2ecf20Sopenharmony_ci
98108c2ecf20Sopenharmony_ci	/* set 1000 speed advertisement */
98118c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
98128c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
98138c2ecf20Sopenharmony_ci			&an_1000_val);
98148c2ecf20Sopenharmony_ci
98158c2ecf20Sopenharmony_ci	bnx2x_ext_phy_set_pause(params, phy, vars);
98168c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
98178c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD,
98188c2ecf20Sopenharmony_ci			MDIO_AN_REG_8481_LEGACY_AN_ADV,
98198c2ecf20Sopenharmony_ci			&an_10_100_val);
98208c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
98218c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
98228c2ecf20Sopenharmony_ci			&autoneg_val);
98238c2ecf20Sopenharmony_ci	/* Disable forced speed */
98248c2ecf20Sopenharmony_ci	autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
98258c2ecf20Sopenharmony_ci	an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
98268c2ecf20Sopenharmony_ci
98278c2ecf20Sopenharmony_ci	if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
98288c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask &
98298c2ecf20Sopenharmony_ci	     PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
98308c2ecf20Sopenharmony_ci	    (phy->req_line_speed == SPEED_1000)) {
98318c2ecf20Sopenharmony_ci		an_1000_val |= (1<<8);
98328c2ecf20Sopenharmony_ci		autoneg_val |= (1<<9 | 1<<12);
98338c2ecf20Sopenharmony_ci		if (phy->req_duplex == DUPLEX_FULL)
98348c2ecf20Sopenharmony_ci			an_1000_val |= (1<<9);
98358c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertising 1G\n");
98368c2ecf20Sopenharmony_ci	} else
98378c2ecf20Sopenharmony_ci		an_1000_val &= ~((1<<8) | (1<<9));
98388c2ecf20Sopenharmony_ci
98398c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
98408c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
98418c2ecf20Sopenharmony_ci			 an_1000_val);
98428c2ecf20Sopenharmony_ci
98438c2ecf20Sopenharmony_ci	/* Set 10/100 speed advertisement */
98448c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_AUTO_NEG) {
98458c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
98468c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
98478c2ecf20Sopenharmony_ci			/* Enable autoneg and restart autoneg for legacy speeds
98488c2ecf20Sopenharmony_ci			 */
98498c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
98508c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<8);
98518c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 100M-FD\n");
98528c2ecf20Sopenharmony_ci		}
98538c2ecf20Sopenharmony_ci
98548c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
98558c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
98568c2ecf20Sopenharmony_ci			/* Enable autoneg and restart autoneg for legacy speeds
98578c2ecf20Sopenharmony_ci			 */
98588c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
98598c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<7);
98608c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 100M-HD\n");
98618c2ecf20Sopenharmony_ci		}
98628c2ecf20Sopenharmony_ci
98638c2ecf20Sopenharmony_ci		if ((phy->speed_cap_mask &
98648c2ecf20Sopenharmony_ci		     PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
98658c2ecf20Sopenharmony_ci		    (phy->supported & SUPPORTED_10baseT_Full)) {
98668c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<6);
98678c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
98688c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 10M-FD\n");
98698c2ecf20Sopenharmony_ci		}
98708c2ecf20Sopenharmony_ci
98718c2ecf20Sopenharmony_ci		if ((phy->speed_cap_mask &
98728c2ecf20Sopenharmony_ci		     PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) &&
98738c2ecf20Sopenharmony_ci		    (phy->supported & SUPPORTED_10baseT_Half)) {
98748c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<5);
98758c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
98768c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 10M-HD\n");
98778c2ecf20Sopenharmony_ci		}
98788c2ecf20Sopenharmony_ci	}
98798c2ecf20Sopenharmony_ci
98808c2ecf20Sopenharmony_ci	/* Only 10/100 are allowed to work in FORCE mode */
98818c2ecf20Sopenharmony_ci	if ((phy->req_line_speed == SPEED_100) &&
98828c2ecf20Sopenharmony_ci	    (phy->supported &
98838c2ecf20Sopenharmony_ci	     (SUPPORTED_100baseT_Half |
98848c2ecf20Sopenharmony_ci	      SUPPORTED_100baseT_Full))) {
98858c2ecf20Sopenharmony_ci		autoneg_val |= (1<<13);
98868c2ecf20Sopenharmony_ci		/* Enabled AUTO-MDIX when autoneg is disabled */
98878c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
98888c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
98898c2ecf20Sopenharmony_ci				 (1<<15 | 1<<9 | 7<<0));
98908c2ecf20Sopenharmony_ci		/* The PHY needs this set even for forced link. */
98918c2ecf20Sopenharmony_ci		an_10_100_val |= (1<<8) | (1<<7);
98928c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 100M force\n");
98938c2ecf20Sopenharmony_ci	}
98948c2ecf20Sopenharmony_ci	if ((phy->req_line_speed == SPEED_10) &&
98958c2ecf20Sopenharmony_ci	    (phy->supported &
98968c2ecf20Sopenharmony_ci	     (SUPPORTED_10baseT_Half |
98978c2ecf20Sopenharmony_ci	      SUPPORTED_10baseT_Full))) {
98988c2ecf20Sopenharmony_ci		/* Enabled AUTO-MDIX when autoneg is disabled */
98998c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
99008c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
99018c2ecf20Sopenharmony_ci				 (1<<15 | 1<<9 | 7<<0));
99028c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 10M force\n");
99038c2ecf20Sopenharmony_ci	}
99048c2ecf20Sopenharmony_ci
99058c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
99068c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
99078c2ecf20Sopenharmony_ci			 an_10_100_val);
99088c2ecf20Sopenharmony_ci
99098c2ecf20Sopenharmony_ci	if (phy->req_duplex == DUPLEX_FULL)
99108c2ecf20Sopenharmony_ci		autoneg_val |= (1<<8);
99118c2ecf20Sopenharmony_ci
99128c2ecf20Sopenharmony_ci	/* Always write this if this is not 84833/4.
99138c2ecf20Sopenharmony_ci	 * For 84833/4, write it only when it's a forced speed.
99148c2ecf20Sopenharmony_ci	 */
99158c2ecf20Sopenharmony_ci	if (!bnx2x_is_8483x_8485x(phy) ||
99168c2ecf20Sopenharmony_ci	    ((autoneg_val & (1<<12)) == 0))
99178c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
99188c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD,
99198c2ecf20Sopenharmony_ci			 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
99208c2ecf20Sopenharmony_ci
99218c2ecf20Sopenharmony_ci	if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
99228c2ecf20Sopenharmony_ci	    (phy->speed_cap_mask &
99238c2ecf20Sopenharmony_ci	     PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
99248c2ecf20Sopenharmony_ci		(phy->req_line_speed == SPEED_10000)) {
99258c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 10G\n");
99268c2ecf20Sopenharmony_ci			/* Restart autoneg for 10G*/
99278c2ecf20Sopenharmony_ci
99288c2ecf20Sopenharmony_ci			bnx2x_cl45_read_or_write(
99298c2ecf20Sopenharmony_ci				bp, phy,
99308c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
99318c2ecf20Sopenharmony_ci				MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
99328c2ecf20Sopenharmony_ci				0x1000);
99338c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
99348c2ecf20Sopenharmony_ci					 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
99358c2ecf20Sopenharmony_ci					 0x3200);
99368c2ecf20Sopenharmony_ci	} else
99378c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
99388c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD,
99398c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
99408c2ecf20Sopenharmony_ci				 1);
99418c2ecf20Sopenharmony_ci
99428c2ecf20Sopenharmony_ci	return 0;
99438c2ecf20Sopenharmony_ci}
99448c2ecf20Sopenharmony_ci
99458c2ecf20Sopenharmony_cistatic void bnx2x_8481_config_init(struct bnx2x_phy *phy,
99468c2ecf20Sopenharmony_ci				   struct link_params *params,
99478c2ecf20Sopenharmony_ci				   struct link_vars *vars)
99488c2ecf20Sopenharmony_ci{
99498c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
99508c2ecf20Sopenharmony_ci	/* Restore normal power mode*/
99518c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
99528c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
99538c2ecf20Sopenharmony_ci
99548c2ecf20Sopenharmony_ci	/* HW reset */
99558c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, params->port);
99568c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
99578c2ecf20Sopenharmony_ci
99588c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
99598c2ecf20Sopenharmony_ci	bnx2x_848xx_cmn_config_init(phy, params, vars);
99608c2ecf20Sopenharmony_ci}
99618c2ecf20Sopenharmony_ci
99628c2ecf20Sopenharmony_ci#define PHY848xx_CMDHDLR_WAIT 300
99638c2ecf20Sopenharmony_ci#define PHY848xx_CMDHDLR_MAX_ARGS 5
99648c2ecf20Sopenharmony_ci
99658c2ecf20Sopenharmony_cistatic int bnx2x_84858_cmd_hdlr(struct bnx2x_phy *phy,
99668c2ecf20Sopenharmony_ci				struct link_params *params,
99678c2ecf20Sopenharmony_ci				u16 fw_cmd,
99688c2ecf20Sopenharmony_ci				u16 cmd_args[], int argc)
99698c2ecf20Sopenharmony_ci{
99708c2ecf20Sopenharmony_ci	int idx;
99718c2ecf20Sopenharmony_ci	u16 val;
99728c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
99738c2ecf20Sopenharmony_ci
99748c2ecf20Sopenharmony_ci	/* Step 1: Poll the STATUS register to see whether the previous command
99758c2ecf20Sopenharmony_ci	 * is in progress or the system is busy (CMD_IN_PROGRESS or
99768c2ecf20Sopenharmony_ci	 * SYSTEM_BUSY). If previous command is in progress or system is busy,
99778c2ecf20Sopenharmony_ci	 * check again until the previous command finishes execution and the
99788c2ecf20Sopenharmony_ci	 * system is available for taking command
99798c2ecf20Sopenharmony_ci	 */
99808c2ecf20Sopenharmony_ci
99818c2ecf20Sopenharmony_ci	for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
99828c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
99838c2ecf20Sopenharmony_ci				MDIO_848xx_CMD_HDLR_STATUS, &val);
99848c2ecf20Sopenharmony_ci		if ((val != PHY84858_STATUS_CMD_IN_PROGRESS) &&
99858c2ecf20Sopenharmony_ci		    (val != PHY84858_STATUS_CMD_SYSTEM_BUSY))
99868c2ecf20Sopenharmony_ci			break;
99878c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
99888c2ecf20Sopenharmony_ci	}
99898c2ecf20Sopenharmony_ci	if (idx >= PHY848xx_CMDHDLR_WAIT) {
99908c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
99918c2ecf20Sopenharmony_ci		return -EINVAL;
99928c2ecf20Sopenharmony_ci	}
99938c2ecf20Sopenharmony_ci
99948c2ecf20Sopenharmony_ci	/* Step2: If any parameters are required for the function, write them
99958c2ecf20Sopenharmony_ci	 * to the required DATA registers
99968c2ecf20Sopenharmony_ci	 */
99978c2ecf20Sopenharmony_ci
99988c2ecf20Sopenharmony_ci	for (idx = 0; idx < argc; idx++) {
99998c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100008c2ecf20Sopenharmony_ci				 MDIO_848xx_CMD_HDLR_DATA1 + idx,
100018c2ecf20Sopenharmony_ci				 cmd_args[idx]);
100028c2ecf20Sopenharmony_ci	}
100038c2ecf20Sopenharmony_ci
100048c2ecf20Sopenharmony_ci	/* Step3: When the firmware is ready for commands, write the 'Command
100058c2ecf20Sopenharmony_ci	 * code' to the CMD register
100068c2ecf20Sopenharmony_ci	 */
100078c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100088c2ecf20Sopenharmony_ci			 MDIO_848xx_CMD_HDLR_COMMAND, fw_cmd);
100098c2ecf20Sopenharmony_ci
100108c2ecf20Sopenharmony_ci	/* Step4: Once the command has been written, poll the STATUS register
100118c2ecf20Sopenharmony_ci	 * to check whether the command has completed (CMD_COMPLETED_PASS/
100128c2ecf20Sopenharmony_ci	 * CMD_FOR_CMDS or CMD_COMPLETED_ERROR).
100138c2ecf20Sopenharmony_ci	 */
100148c2ecf20Sopenharmony_ci
100158c2ecf20Sopenharmony_ci	for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
100168c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
100178c2ecf20Sopenharmony_ci				MDIO_848xx_CMD_HDLR_STATUS, &val);
100188c2ecf20Sopenharmony_ci		if ((val == PHY84858_STATUS_CMD_COMPLETE_PASS) ||
100198c2ecf20Sopenharmony_ci		    (val == PHY84858_STATUS_CMD_COMPLETE_ERROR))
100208c2ecf20Sopenharmony_ci			break;
100218c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
100228c2ecf20Sopenharmony_ci	}
100238c2ecf20Sopenharmony_ci	if ((idx >= PHY848xx_CMDHDLR_WAIT) ||
100248c2ecf20Sopenharmony_ci	    (val == PHY84858_STATUS_CMD_COMPLETE_ERROR)) {
100258c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "FW cmd failed.\n");
100268c2ecf20Sopenharmony_ci		return -EINVAL;
100278c2ecf20Sopenharmony_ci	}
100288c2ecf20Sopenharmony_ci	/* Step5: Once the command has completed, read the specficied DATA
100298c2ecf20Sopenharmony_ci	 * registers for any saved results for the command, if applicable
100308c2ecf20Sopenharmony_ci	 */
100318c2ecf20Sopenharmony_ci
100328c2ecf20Sopenharmony_ci	/* Gather returning data */
100338c2ecf20Sopenharmony_ci	for (idx = 0; idx < argc; idx++) {
100348c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
100358c2ecf20Sopenharmony_ci				MDIO_848xx_CMD_HDLR_DATA1 + idx,
100368c2ecf20Sopenharmony_ci				&cmd_args[idx]);
100378c2ecf20Sopenharmony_ci	}
100388c2ecf20Sopenharmony_ci
100398c2ecf20Sopenharmony_ci	return 0;
100408c2ecf20Sopenharmony_ci}
100418c2ecf20Sopenharmony_ci
100428c2ecf20Sopenharmony_cistatic int bnx2x_84833_cmd_hdlr(struct bnx2x_phy *phy,
100438c2ecf20Sopenharmony_ci				struct link_params *params, u16 fw_cmd,
100448c2ecf20Sopenharmony_ci				u16 cmd_args[], int argc, int process)
100458c2ecf20Sopenharmony_ci{
100468c2ecf20Sopenharmony_ci	int idx;
100478c2ecf20Sopenharmony_ci	u16 val;
100488c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
100498c2ecf20Sopenharmony_ci	int rc = 0;
100508c2ecf20Sopenharmony_ci
100518c2ecf20Sopenharmony_ci	if (process == PHY84833_MB_PROCESS2) {
100528c2ecf20Sopenharmony_ci		/* Write CMD_OPEN_OVERRIDE to STATUS reg */
100538c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100548c2ecf20Sopenharmony_ci				 MDIO_848xx_CMD_HDLR_STATUS,
100558c2ecf20Sopenharmony_ci				 PHY84833_STATUS_CMD_OPEN_OVERRIDE);
100568c2ecf20Sopenharmony_ci	}
100578c2ecf20Sopenharmony_ci
100588c2ecf20Sopenharmony_ci	for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
100598c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
100608c2ecf20Sopenharmony_ci				MDIO_848xx_CMD_HDLR_STATUS, &val);
100618c2ecf20Sopenharmony_ci		if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
100628c2ecf20Sopenharmony_ci			break;
100638c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
100648c2ecf20Sopenharmony_ci	}
100658c2ecf20Sopenharmony_ci	if (idx >= PHY848xx_CMDHDLR_WAIT) {
100668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
100678c2ecf20Sopenharmony_ci		/* if the status is CMD_COMPLETE_PASS or CMD_COMPLETE_ERROR
100688c2ecf20Sopenharmony_ci		 * clear the status to CMD_CLEAR_COMPLETE
100698c2ecf20Sopenharmony_ci		 */
100708c2ecf20Sopenharmony_ci		if (val == PHY84833_STATUS_CMD_COMPLETE_PASS ||
100718c2ecf20Sopenharmony_ci		    val == PHY84833_STATUS_CMD_COMPLETE_ERROR) {
100728c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100738c2ecf20Sopenharmony_ci					 MDIO_848xx_CMD_HDLR_STATUS,
100748c2ecf20Sopenharmony_ci					 PHY84833_STATUS_CMD_CLEAR_COMPLETE);
100758c2ecf20Sopenharmony_ci		}
100768c2ecf20Sopenharmony_ci		return -EINVAL;
100778c2ecf20Sopenharmony_ci	}
100788c2ecf20Sopenharmony_ci	if (process == PHY84833_MB_PROCESS1 ||
100798c2ecf20Sopenharmony_ci	    process == PHY84833_MB_PROCESS2) {
100808c2ecf20Sopenharmony_ci		/* Prepare argument(s) */
100818c2ecf20Sopenharmony_ci		for (idx = 0; idx < argc; idx++) {
100828c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100838c2ecf20Sopenharmony_ci					 MDIO_848xx_CMD_HDLR_DATA1 + idx,
100848c2ecf20Sopenharmony_ci					 cmd_args[idx]);
100858c2ecf20Sopenharmony_ci		}
100868c2ecf20Sopenharmony_ci	}
100878c2ecf20Sopenharmony_ci
100888c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
100898c2ecf20Sopenharmony_ci			MDIO_848xx_CMD_HDLR_COMMAND, fw_cmd);
100908c2ecf20Sopenharmony_ci	for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
100918c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
100928c2ecf20Sopenharmony_ci				MDIO_848xx_CMD_HDLR_STATUS, &val);
100938c2ecf20Sopenharmony_ci		if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
100948c2ecf20Sopenharmony_ci		    (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
100958c2ecf20Sopenharmony_ci			break;
100968c2ecf20Sopenharmony_ci		usleep_range(1000, 2000);
100978c2ecf20Sopenharmony_ci	}
100988c2ecf20Sopenharmony_ci	if ((idx >= PHY848xx_CMDHDLR_WAIT) ||
100998c2ecf20Sopenharmony_ci	    (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
101008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "FW cmd failed.\n");
101018c2ecf20Sopenharmony_ci		rc = -EINVAL;
101028c2ecf20Sopenharmony_ci	}
101038c2ecf20Sopenharmony_ci	if (process == PHY84833_MB_PROCESS3 && rc == 0) {
101048c2ecf20Sopenharmony_ci		/* Gather returning data */
101058c2ecf20Sopenharmony_ci		for (idx = 0; idx < argc; idx++) {
101068c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
101078c2ecf20Sopenharmony_ci					MDIO_848xx_CMD_HDLR_DATA1 + idx,
101088c2ecf20Sopenharmony_ci					&cmd_args[idx]);
101098c2ecf20Sopenharmony_ci		}
101108c2ecf20Sopenharmony_ci	}
101118c2ecf20Sopenharmony_ci	if (val == PHY84833_STATUS_CMD_COMPLETE_ERROR ||
101128c2ecf20Sopenharmony_ci	    val == PHY84833_STATUS_CMD_COMPLETE_PASS) {
101138c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
101148c2ecf20Sopenharmony_ci				 MDIO_848xx_CMD_HDLR_STATUS,
101158c2ecf20Sopenharmony_ci				 PHY84833_STATUS_CMD_CLEAR_COMPLETE);
101168c2ecf20Sopenharmony_ci	}
101178c2ecf20Sopenharmony_ci	return rc;
101188c2ecf20Sopenharmony_ci}
101198c2ecf20Sopenharmony_ci
101208c2ecf20Sopenharmony_cistatic int bnx2x_848xx_cmd_hdlr(struct bnx2x_phy *phy,
101218c2ecf20Sopenharmony_ci				struct link_params *params,
101228c2ecf20Sopenharmony_ci				u16 fw_cmd,
101238c2ecf20Sopenharmony_ci					   u16 cmd_args[], int argc,
101248c2ecf20Sopenharmony_ci					   int process)
101258c2ecf20Sopenharmony_ci{
101268c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
101278c2ecf20Sopenharmony_ci
101288c2ecf20Sopenharmony_ci	if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) ||
101298c2ecf20Sopenharmony_ci	    (REG_RD(bp, params->shmem2_base +
101308c2ecf20Sopenharmony_ci		    offsetof(struct shmem2_region,
101318c2ecf20Sopenharmony_ci			     link_attr_sync[params->port])) &
101328c2ecf20Sopenharmony_ci	     LINK_ATTR_84858)) {
101338c2ecf20Sopenharmony_ci		return bnx2x_84858_cmd_hdlr(phy, params, fw_cmd, cmd_args,
101348c2ecf20Sopenharmony_ci					    argc);
101358c2ecf20Sopenharmony_ci	} else {
101368c2ecf20Sopenharmony_ci		return bnx2x_84833_cmd_hdlr(phy, params, fw_cmd, cmd_args,
101378c2ecf20Sopenharmony_ci					    argc, process);
101388c2ecf20Sopenharmony_ci	}
101398c2ecf20Sopenharmony_ci}
101408c2ecf20Sopenharmony_ci
101418c2ecf20Sopenharmony_cistatic int bnx2x_848xx_pair_swap_cfg(struct bnx2x_phy *phy,
101428c2ecf20Sopenharmony_ci				     struct link_params *params,
101438c2ecf20Sopenharmony_ci				     struct link_vars *vars)
101448c2ecf20Sopenharmony_ci{
101458c2ecf20Sopenharmony_ci	u32 pair_swap;
101468c2ecf20Sopenharmony_ci	u16 data[PHY848xx_CMDHDLR_MAX_ARGS];
101478c2ecf20Sopenharmony_ci	int status;
101488c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
101498c2ecf20Sopenharmony_ci
101508c2ecf20Sopenharmony_ci	/* Check for configuration. */
101518c2ecf20Sopenharmony_ci	pair_swap = REG_RD(bp, params->shmem_base +
101528c2ecf20Sopenharmony_ci			   offsetof(struct shmem_region,
101538c2ecf20Sopenharmony_ci			dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
101548c2ecf20Sopenharmony_ci		PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
101558c2ecf20Sopenharmony_ci
101568c2ecf20Sopenharmony_ci	if (pair_swap == 0)
101578c2ecf20Sopenharmony_ci		return 0;
101588c2ecf20Sopenharmony_ci
101598c2ecf20Sopenharmony_ci	/* Only the second argument is used for this command */
101608c2ecf20Sopenharmony_ci	data[1] = (u16)pair_swap;
101618c2ecf20Sopenharmony_ci
101628c2ecf20Sopenharmony_ci	status = bnx2x_848xx_cmd_hdlr(phy, params,
101638c2ecf20Sopenharmony_ci				      PHY848xx_CMD_SET_PAIR_SWAP, data,
101648c2ecf20Sopenharmony_ci				      2, PHY84833_MB_PROCESS2);
101658c2ecf20Sopenharmony_ci	if (status == 0)
101668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data[1]);
101678c2ecf20Sopenharmony_ci
101688c2ecf20Sopenharmony_ci	return status;
101698c2ecf20Sopenharmony_ci}
101708c2ecf20Sopenharmony_ci
101718c2ecf20Sopenharmony_cistatic u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
101728c2ecf20Sopenharmony_ci				      u32 shmem_base_path[],
101738c2ecf20Sopenharmony_ci				      u32 chip_id)
101748c2ecf20Sopenharmony_ci{
101758c2ecf20Sopenharmony_ci	u32 reset_pin[2];
101768c2ecf20Sopenharmony_ci	u32 idx;
101778c2ecf20Sopenharmony_ci	u8 reset_gpios;
101788c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
101798c2ecf20Sopenharmony_ci		/* Assume that these will be GPIOs, not EPIOs. */
101808c2ecf20Sopenharmony_ci		for (idx = 0; idx < 2; idx++) {
101818c2ecf20Sopenharmony_ci			/* Map config param to register bit. */
101828c2ecf20Sopenharmony_ci			reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
101838c2ecf20Sopenharmony_ci				offsetof(struct shmem_region,
101848c2ecf20Sopenharmony_ci				dev_info.port_hw_config[0].e3_cmn_pin_cfg));
101858c2ecf20Sopenharmony_ci			reset_pin[idx] = (reset_pin[idx] &
101868c2ecf20Sopenharmony_ci				PORT_HW_CFG_E3_PHY_RESET_MASK) >>
101878c2ecf20Sopenharmony_ci				PORT_HW_CFG_E3_PHY_RESET_SHIFT;
101888c2ecf20Sopenharmony_ci			reset_pin[idx] -= PIN_CFG_GPIO0_P0;
101898c2ecf20Sopenharmony_ci			reset_pin[idx] = (1 << reset_pin[idx]);
101908c2ecf20Sopenharmony_ci		}
101918c2ecf20Sopenharmony_ci		reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
101928c2ecf20Sopenharmony_ci	} else {
101938c2ecf20Sopenharmony_ci		/* E2, look from diff place of shmem. */
101948c2ecf20Sopenharmony_ci		for (idx = 0; idx < 2; idx++) {
101958c2ecf20Sopenharmony_ci			reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
101968c2ecf20Sopenharmony_ci				offsetof(struct shmem_region,
101978c2ecf20Sopenharmony_ci				dev_info.port_hw_config[0].default_cfg));
101988c2ecf20Sopenharmony_ci			reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
101998c2ecf20Sopenharmony_ci			reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
102008c2ecf20Sopenharmony_ci			reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
102018c2ecf20Sopenharmony_ci			reset_pin[idx] = (1 << reset_pin[idx]);
102028c2ecf20Sopenharmony_ci		}
102038c2ecf20Sopenharmony_ci		reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
102048c2ecf20Sopenharmony_ci	}
102058c2ecf20Sopenharmony_ci
102068c2ecf20Sopenharmony_ci	return reset_gpios;
102078c2ecf20Sopenharmony_ci}
102088c2ecf20Sopenharmony_ci
102098c2ecf20Sopenharmony_cistatic void bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
102108c2ecf20Sopenharmony_ci				     struct link_params *params)
102118c2ecf20Sopenharmony_ci{
102128c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
102138c2ecf20Sopenharmony_ci	u8 reset_gpios;
102148c2ecf20Sopenharmony_ci	u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
102158c2ecf20Sopenharmony_ci				offsetof(struct shmem2_region,
102168c2ecf20Sopenharmony_ci				other_shmem_base_addr));
102178c2ecf20Sopenharmony_ci
102188c2ecf20Sopenharmony_ci	u32 shmem_base_path[2];
102198c2ecf20Sopenharmony_ci
102208c2ecf20Sopenharmony_ci	/* Work around for 84833 LED failure inside RESET status */
102218c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
102228c2ecf20Sopenharmony_ci		MDIO_AN_REG_8481_LEGACY_MII_CTRL,
102238c2ecf20Sopenharmony_ci		MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
102248c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
102258c2ecf20Sopenharmony_ci		MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
102268c2ecf20Sopenharmony_ci		MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
102278c2ecf20Sopenharmony_ci
102288c2ecf20Sopenharmony_ci	shmem_base_path[0] = params->shmem_base;
102298c2ecf20Sopenharmony_ci	shmem_base_path[1] = other_shmem_base_addr;
102308c2ecf20Sopenharmony_ci
102318c2ecf20Sopenharmony_ci	reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
102328c2ecf20Sopenharmony_ci						  params->chip_id);
102338c2ecf20Sopenharmony_ci
102348c2ecf20Sopenharmony_ci	bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
102358c2ecf20Sopenharmony_ci	udelay(10);
102368c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
102378c2ecf20Sopenharmony_ci		reset_gpios);
102388c2ecf20Sopenharmony_ci}
102398c2ecf20Sopenharmony_ci
102408c2ecf20Sopenharmony_cistatic int bnx2x_8483x_disable_eee(struct bnx2x_phy *phy,
102418c2ecf20Sopenharmony_ci				   struct link_params *params,
102428c2ecf20Sopenharmony_ci				   struct link_vars *vars)
102438c2ecf20Sopenharmony_ci{
102448c2ecf20Sopenharmony_ci	int rc;
102458c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
102468c2ecf20Sopenharmony_ci	u16 cmd_args = 0;
102478c2ecf20Sopenharmony_ci
102488c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Don't Advertise 10GBase-T EEE\n");
102498c2ecf20Sopenharmony_ci
102508c2ecf20Sopenharmony_ci	/* Prevent Phy from working in EEE and advertising it */
102518c2ecf20Sopenharmony_ci	rc = bnx2x_848xx_cmd_hdlr(phy, params, PHY848xx_CMD_SET_EEE_MODE,
102528c2ecf20Sopenharmony_ci				  &cmd_args, 1, PHY84833_MB_PROCESS1);
102538c2ecf20Sopenharmony_ci	if (rc) {
102548c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "EEE disable failed.\n");
102558c2ecf20Sopenharmony_ci		return rc;
102568c2ecf20Sopenharmony_ci	}
102578c2ecf20Sopenharmony_ci
102588c2ecf20Sopenharmony_ci	return bnx2x_eee_disable(phy, params, vars);
102598c2ecf20Sopenharmony_ci}
102608c2ecf20Sopenharmony_ci
102618c2ecf20Sopenharmony_cistatic int bnx2x_8483x_enable_eee(struct bnx2x_phy *phy,
102628c2ecf20Sopenharmony_ci				   struct link_params *params,
102638c2ecf20Sopenharmony_ci				   struct link_vars *vars)
102648c2ecf20Sopenharmony_ci{
102658c2ecf20Sopenharmony_ci	int rc;
102668c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
102678c2ecf20Sopenharmony_ci	u16 cmd_args = 1;
102688c2ecf20Sopenharmony_ci
102698c2ecf20Sopenharmony_ci	rc = bnx2x_848xx_cmd_hdlr(phy, params, PHY848xx_CMD_SET_EEE_MODE,
102708c2ecf20Sopenharmony_ci				  &cmd_args, 1, PHY84833_MB_PROCESS1);
102718c2ecf20Sopenharmony_ci	if (rc) {
102728c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "EEE enable failed.\n");
102738c2ecf20Sopenharmony_ci		return rc;
102748c2ecf20Sopenharmony_ci	}
102758c2ecf20Sopenharmony_ci
102768c2ecf20Sopenharmony_ci	return bnx2x_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
102778c2ecf20Sopenharmony_ci}
102788c2ecf20Sopenharmony_ci
102798c2ecf20Sopenharmony_ci#define PHY84833_CONSTANT_LATENCY 1193
102808c2ecf20Sopenharmony_cistatic void bnx2x_848x3_config_init(struct bnx2x_phy *phy,
102818c2ecf20Sopenharmony_ci				    struct link_params *params,
102828c2ecf20Sopenharmony_ci				    struct link_vars *vars)
102838c2ecf20Sopenharmony_ci{
102848c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
102858c2ecf20Sopenharmony_ci	u8 port, initialize = 1;
102868c2ecf20Sopenharmony_ci	u16 val;
102878c2ecf20Sopenharmony_ci	u32 actual_phy_selection;
102888c2ecf20Sopenharmony_ci	u16 cmd_args[PHY848xx_CMDHDLR_MAX_ARGS];
102898c2ecf20Sopenharmony_ci	int rc = 0;
102908c2ecf20Sopenharmony_ci
102918c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
102928c2ecf20Sopenharmony_ci
102938c2ecf20Sopenharmony_ci	if (!(CHIP_IS_E1x(bp)))
102948c2ecf20Sopenharmony_ci		port = BP_PATH(bp);
102958c2ecf20Sopenharmony_ci	else
102968c2ecf20Sopenharmony_ci		port = params->port;
102978c2ecf20Sopenharmony_ci
102988c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
102998c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
103008c2ecf20Sopenharmony_ci			       MISC_REGISTERS_GPIO_OUTPUT_HIGH,
103018c2ecf20Sopenharmony_ci			       port);
103028c2ecf20Sopenharmony_ci	} else {
103038c2ecf20Sopenharmony_ci		/* MDIO reset */
103048c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
103058c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
103068c2ecf20Sopenharmony_ci				MDIO_PMA_REG_CTRL, 0x8000);
103078c2ecf20Sopenharmony_ci	}
103088c2ecf20Sopenharmony_ci
103098c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
103108c2ecf20Sopenharmony_ci
103118c2ecf20Sopenharmony_ci	/* Wait for GPHY to come out of reset */
103128c2ecf20Sopenharmony_ci	msleep(50);
103138c2ecf20Sopenharmony_ci	if (!bnx2x_is_8483x_8485x(phy)) {
103148c2ecf20Sopenharmony_ci		/* BCM84823 requires that XGXS links up first @ 10G for normal
103158c2ecf20Sopenharmony_ci		 * behavior.
103168c2ecf20Sopenharmony_ci		 */
103178c2ecf20Sopenharmony_ci		u16 temp;
103188c2ecf20Sopenharmony_ci		temp = vars->line_speed;
103198c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
103208c2ecf20Sopenharmony_ci		bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
103218c2ecf20Sopenharmony_ci		bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
103228c2ecf20Sopenharmony_ci		vars->line_speed = temp;
103238c2ecf20Sopenharmony_ci	}
103248c2ecf20Sopenharmony_ci	/* Check if this is actually BCM84858 */
103258c2ecf20Sopenharmony_ci	if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
103268c2ecf20Sopenharmony_ci		u16 hw_rev;
103278c2ecf20Sopenharmony_ci
103288c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
103298c2ecf20Sopenharmony_ci				MDIO_AN_REG_848xx_ID_MSB, &hw_rev);
103308c2ecf20Sopenharmony_ci		if (hw_rev == BCM84858_PHY_ID) {
103318c2ecf20Sopenharmony_ci			params->link_attr_sync |= LINK_ATTR_84858;
103328c2ecf20Sopenharmony_ci			bnx2x_update_link_attr(params, params->link_attr_sync);
103338c2ecf20Sopenharmony_ci		}
103348c2ecf20Sopenharmony_ci	}
103358c2ecf20Sopenharmony_ci
103368c2ecf20Sopenharmony_ci	/* Set dual-media configuration according to configuration */
103378c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
103388c2ecf20Sopenharmony_ci			MDIO_CTL_REG_84823_MEDIA, &val);
103398c2ecf20Sopenharmony_ci	val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
103408c2ecf20Sopenharmony_ci		 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
103418c2ecf20Sopenharmony_ci		 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
103428c2ecf20Sopenharmony_ci		 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
103438c2ecf20Sopenharmony_ci		 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
103448c2ecf20Sopenharmony_ci
103458c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
103468c2ecf20Sopenharmony_ci		val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
103478c2ecf20Sopenharmony_ci			 MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
103488c2ecf20Sopenharmony_ci	} else {
103498c2ecf20Sopenharmony_ci		val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
103508c2ecf20Sopenharmony_ci			MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
103518c2ecf20Sopenharmony_ci	}
103528c2ecf20Sopenharmony_ci
103538c2ecf20Sopenharmony_ci	actual_phy_selection = bnx2x_phy_selection(params);
103548c2ecf20Sopenharmony_ci
103558c2ecf20Sopenharmony_ci	switch (actual_phy_selection) {
103568c2ecf20Sopenharmony_ci	case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
103578c2ecf20Sopenharmony_ci		/* Do nothing. Essentially this is like the priority copper */
103588c2ecf20Sopenharmony_ci		break;
103598c2ecf20Sopenharmony_ci	case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
103608c2ecf20Sopenharmony_ci		val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
103618c2ecf20Sopenharmony_ci		break;
103628c2ecf20Sopenharmony_ci	case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
103638c2ecf20Sopenharmony_ci		val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
103648c2ecf20Sopenharmony_ci		break;
103658c2ecf20Sopenharmony_ci	case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
103668c2ecf20Sopenharmony_ci		/* Do nothing here. The first PHY won't be initialized at all */
103678c2ecf20Sopenharmony_ci		break;
103688c2ecf20Sopenharmony_ci	case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
103698c2ecf20Sopenharmony_ci		val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
103708c2ecf20Sopenharmony_ci		initialize = 0;
103718c2ecf20Sopenharmony_ci		break;
103728c2ecf20Sopenharmony_ci	}
103738c2ecf20Sopenharmony_ci	if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
103748c2ecf20Sopenharmony_ci		val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
103758c2ecf20Sopenharmony_ci
103768c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
103778c2ecf20Sopenharmony_ci			 MDIO_CTL_REG_84823_MEDIA, val);
103788c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
103798c2ecf20Sopenharmony_ci		   params->multi_phy_config, val);
103808c2ecf20Sopenharmony_ci
103818c2ecf20Sopenharmony_ci	if (bnx2x_is_8483x_8485x(phy)) {
103828c2ecf20Sopenharmony_ci		bnx2x_848xx_pair_swap_cfg(phy, params, vars);
103838c2ecf20Sopenharmony_ci
103848c2ecf20Sopenharmony_ci		/* Keep AutogrEEEn disabled. */
103858c2ecf20Sopenharmony_ci		cmd_args[0] = 0x0;
103868c2ecf20Sopenharmony_ci		cmd_args[1] = 0x0;
103878c2ecf20Sopenharmony_ci		cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
103888c2ecf20Sopenharmony_ci		cmd_args[3] = PHY84833_CONSTANT_LATENCY;
103898c2ecf20Sopenharmony_ci		rc = bnx2x_848xx_cmd_hdlr(phy, params,
103908c2ecf20Sopenharmony_ci					  PHY848xx_CMD_SET_EEE_MODE, cmd_args,
103918c2ecf20Sopenharmony_ci					  4, PHY84833_MB_PROCESS1);
103928c2ecf20Sopenharmony_ci		if (rc)
103938c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Cfg AutogrEEEn failed.\n");
103948c2ecf20Sopenharmony_ci	}
103958c2ecf20Sopenharmony_ci	if (initialize)
103968c2ecf20Sopenharmony_ci		rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
103978c2ecf20Sopenharmony_ci	else
103988c2ecf20Sopenharmony_ci		bnx2x_save_848xx_spirom_version(phy, bp, params->port);
103998c2ecf20Sopenharmony_ci	/* 84833 PHY has a better feature and doesn't need to support this. */
104008c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
104018c2ecf20Sopenharmony_ci		u32 cms_enable = REG_RD(bp, params->shmem_base +
104028c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
104038c2ecf20Sopenharmony_ci			dev_info.port_hw_config[params->port].default_cfg)) &
104048c2ecf20Sopenharmony_ci			PORT_HW_CFG_ENABLE_CMS_MASK;
104058c2ecf20Sopenharmony_ci
104068c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
104078c2ecf20Sopenharmony_ci				MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
104088c2ecf20Sopenharmony_ci		if (cms_enable)
104098c2ecf20Sopenharmony_ci			val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
104108c2ecf20Sopenharmony_ci		else
104118c2ecf20Sopenharmony_ci			val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
104128c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
104138c2ecf20Sopenharmony_ci				 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
104148c2ecf20Sopenharmony_ci	}
104158c2ecf20Sopenharmony_ci
104168c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
104178c2ecf20Sopenharmony_ci			MDIO_84833_TOP_CFG_FW_REV, &val);
104188c2ecf20Sopenharmony_ci
104198c2ecf20Sopenharmony_ci	/* Configure EEE support */
104208c2ecf20Sopenharmony_ci	if ((val >= MDIO_84833_TOP_CFG_FW_EEE) &&
104218c2ecf20Sopenharmony_ci	    (val != MDIO_84833_TOP_CFG_FW_NO_EEE) &&
104228c2ecf20Sopenharmony_ci	    bnx2x_eee_has_cap(params)) {
104238c2ecf20Sopenharmony_ci		rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
104248c2ecf20Sopenharmony_ci		if (rc) {
104258c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
104268c2ecf20Sopenharmony_ci			bnx2x_8483x_disable_eee(phy, params, vars);
104278c2ecf20Sopenharmony_ci			return;
104288c2ecf20Sopenharmony_ci		}
104298c2ecf20Sopenharmony_ci
104308c2ecf20Sopenharmony_ci		if ((phy->req_duplex == DUPLEX_FULL) &&
104318c2ecf20Sopenharmony_ci		    (params->eee_mode & EEE_MODE_ADV_LPI) &&
104328c2ecf20Sopenharmony_ci		    (bnx2x_eee_calc_timer(params) ||
104338c2ecf20Sopenharmony_ci		     !(params->eee_mode & EEE_MODE_ENABLE_LPI)))
104348c2ecf20Sopenharmony_ci			rc = bnx2x_8483x_enable_eee(phy, params, vars);
104358c2ecf20Sopenharmony_ci		else
104368c2ecf20Sopenharmony_ci			rc = bnx2x_8483x_disable_eee(phy, params, vars);
104378c2ecf20Sopenharmony_ci		if (rc) {
104388c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Failed to set EEE advertisement\n");
104398c2ecf20Sopenharmony_ci			return;
104408c2ecf20Sopenharmony_ci		}
104418c2ecf20Sopenharmony_ci	} else {
104428c2ecf20Sopenharmony_ci		vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
104438c2ecf20Sopenharmony_ci	}
104448c2ecf20Sopenharmony_ci
104458c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
104468c2ecf20Sopenharmony_ci		/* Additional settings for jumbo packets in 1000BASE-T mode */
104478c2ecf20Sopenharmony_ci		/* Allow rx extended length */
104488c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
104498c2ecf20Sopenharmony_ci				MDIO_AN_REG_8481_AUX_CTRL, &val);
104508c2ecf20Sopenharmony_ci		val |= 0x4000;
104518c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
104528c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_AUX_CTRL, val);
104538c2ecf20Sopenharmony_ci		/* TX FIFO Elasticity LSB */
104548c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
104558c2ecf20Sopenharmony_ci				MDIO_AN_REG_8481_1G_100T_EXT_CTRL, &val);
104568c2ecf20Sopenharmony_ci		val |= 0x1;
104578c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
104588c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_1G_100T_EXT_CTRL, val);
104598c2ecf20Sopenharmony_ci		/* TX FIFO Elasticity MSB */
104608c2ecf20Sopenharmony_ci		/* Enable expansion register 0x46 (Pattern Generator status) */
104618c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
104628c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf46);
104638c2ecf20Sopenharmony_ci
104648c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
104658c2ecf20Sopenharmony_ci				MDIO_AN_REG_8481_EXPANSION_REG_RD_RW, &val);
104668c2ecf20Sopenharmony_ci		val |= 0x4000;
104678c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
104688c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW, val);
104698c2ecf20Sopenharmony_ci	}
104708c2ecf20Sopenharmony_ci
104718c2ecf20Sopenharmony_ci	if (bnx2x_is_8483x_8485x(phy)) {
104728c2ecf20Sopenharmony_ci		/* Bring PHY out of super isolate mode as the final step. */
104738c2ecf20Sopenharmony_ci		bnx2x_cl45_read_and_write(bp, phy,
104748c2ecf20Sopenharmony_ci					  MDIO_CTL_DEVAD,
104758c2ecf20Sopenharmony_ci					  MDIO_84833_TOP_CFG_XGPHY_STRAP1,
104768c2ecf20Sopenharmony_ci					  (u16)~MDIO_84833_SUPER_ISOLATE);
104778c2ecf20Sopenharmony_ci	}
104788c2ecf20Sopenharmony_ci}
104798c2ecf20Sopenharmony_ci
104808c2ecf20Sopenharmony_cistatic u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
104818c2ecf20Sopenharmony_ci				  struct link_params *params,
104828c2ecf20Sopenharmony_ci				  struct link_vars *vars)
104838c2ecf20Sopenharmony_ci{
104848c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
104858c2ecf20Sopenharmony_ci	u16 val, val1, val2;
104868c2ecf20Sopenharmony_ci	u8 link_up = 0;
104878c2ecf20Sopenharmony_ci
104888c2ecf20Sopenharmony_ci
104898c2ecf20Sopenharmony_ci	/* Check 10G-BaseT link status */
104908c2ecf20Sopenharmony_ci	/* Check PMD signal ok */
104918c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
104928c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, 0xFFFA, &val1);
104938c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
104948c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
104958c2ecf20Sopenharmony_ci			&val2);
104968c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
104978c2ecf20Sopenharmony_ci
104988c2ecf20Sopenharmony_ci	/* Check link 10G */
104998c2ecf20Sopenharmony_ci	if (val2 & (1<<11)) {
105008c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
105018c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
105028c2ecf20Sopenharmony_ci		link_up = 1;
105038c2ecf20Sopenharmony_ci		bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
105048c2ecf20Sopenharmony_ci	} else { /* Check Legacy speed link */
105058c2ecf20Sopenharmony_ci		u16 legacy_status, legacy_speed;
105068c2ecf20Sopenharmony_ci
105078c2ecf20Sopenharmony_ci		/* Enable expansion register 0x42 (Operation mode status) */
105088c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
105098c2ecf20Sopenharmony_ci				 MDIO_AN_DEVAD,
105108c2ecf20Sopenharmony_ci				 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
105118c2ecf20Sopenharmony_ci
105128c2ecf20Sopenharmony_ci		/* Get legacy speed operation status */
105138c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
105148c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD,
105158c2ecf20Sopenharmony_ci				MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
105168c2ecf20Sopenharmony_ci				&legacy_status);
105178c2ecf20Sopenharmony_ci
105188c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
105198c2ecf20Sopenharmony_ci		   legacy_status);
105208c2ecf20Sopenharmony_ci		link_up = ((legacy_status & (1<<11)) == (1<<11));
105218c2ecf20Sopenharmony_ci		legacy_speed = (legacy_status & (3<<9));
105228c2ecf20Sopenharmony_ci		if (legacy_speed == (0<<9))
105238c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10;
105248c2ecf20Sopenharmony_ci		else if (legacy_speed == (1<<9))
105258c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_100;
105268c2ecf20Sopenharmony_ci		else if (legacy_speed == (2<<9))
105278c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
105288c2ecf20Sopenharmony_ci		else { /* Should not happen: Treat as link down */
105298c2ecf20Sopenharmony_ci			vars->line_speed = 0;
105308c2ecf20Sopenharmony_ci			link_up = 0;
105318c2ecf20Sopenharmony_ci		}
105328c2ecf20Sopenharmony_ci
105338c2ecf20Sopenharmony_ci		if (link_up) {
105348c2ecf20Sopenharmony_ci			if (legacy_status & (1<<8))
105358c2ecf20Sopenharmony_ci				vars->duplex = DUPLEX_FULL;
105368c2ecf20Sopenharmony_ci			else
105378c2ecf20Sopenharmony_ci				vars->duplex = DUPLEX_HALF;
105388c2ecf20Sopenharmony_ci
105398c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK,
105408c2ecf20Sopenharmony_ci			   "Link is up in %dMbps, is_duplex_full= %d\n",
105418c2ecf20Sopenharmony_ci			   vars->line_speed,
105428c2ecf20Sopenharmony_ci			   (vars->duplex == DUPLEX_FULL));
105438c2ecf20Sopenharmony_ci			/* Check legacy speed AN resolution */
105448c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
105458c2ecf20Sopenharmony_ci					MDIO_AN_DEVAD,
105468c2ecf20Sopenharmony_ci					MDIO_AN_REG_8481_LEGACY_MII_STATUS,
105478c2ecf20Sopenharmony_ci					&val);
105488c2ecf20Sopenharmony_ci			if (val & (1<<5))
105498c2ecf20Sopenharmony_ci				vars->link_status |=
105508c2ecf20Sopenharmony_ci					LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
105518c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
105528c2ecf20Sopenharmony_ci					MDIO_AN_DEVAD,
105538c2ecf20Sopenharmony_ci					MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
105548c2ecf20Sopenharmony_ci					&val);
105558c2ecf20Sopenharmony_ci			if ((val & (1<<0)) == 0)
105568c2ecf20Sopenharmony_ci				vars->link_status |=
105578c2ecf20Sopenharmony_ci					LINK_STATUS_PARALLEL_DETECTION_USED;
105588c2ecf20Sopenharmony_ci		}
105598c2ecf20Sopenharmony_ci	}
105608c2ecf20Sopenharmony_ci	if (link_up) {
105618c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "BCM848x3: link speed is %d\n",
105628c2ecf20Sopenharmony_ci			   vars->line_speed);
105638c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
105648c2ecf20Sopenharmony_ci
105658c2ecf20Sopenharmony_ci		/* Read LP advertised speeds */
105668c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
105678c2ecf20Sopenharmony_ci				MDIO_AN_REG_CL37_FC_LP, &val);
105688c2ecf20Sopenharmony_ci		if (val & (1<<5))
105698c2ecf20Sopenharmony_ci			vars->link_status |=
105708c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
105718c2ecf20Sopenharmony_ci		if (val & (1<<6))
105728c2ecf20Sopenharmony_ci			vars->link_status |=
105738c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
105748c2ecf20Sopenharmony_ci		if (val & (1<<7))
105758c2ecf20Sopenharmony_ci			vars->link_status |=
105768c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
105778c2ecf20Sopenharmony_ci		if (val & (1<<8))
105788c2ecf20Sopenharmony_ci			vars->link_status |=
105798c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
105808c2ecf20Sopenharmony_ci		if (val & (1<<9))
105818c2ecf20Sopenharmony_ci			vars->link_status |=
105828c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
105838c2ecf20Sopenharmony_ci
105848c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
105858c2ecf20Sopenharmony_ci				MDIO_AN_REG_1000T_STATUS, &val);
105868c2ecf20Sopenharmony_ci
105878c2ecf20Sopenharmony_ci		if (val & (1<<10))
105888c2ecf20Sopenharmony_ci			vars->link_status |=
105898c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
105908c2ecf20Sopenharmony_ci		if (val & (1<<11))
105918c2ecf20Sopenharmony_ci			vars->link_status |=
105928c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
105938c2ecf20Sopenharmony_ci
105948c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
105958c2ecf20Sopenharmony_ci				MDIO_AN_REG_MASTER_STATUS, &val);
105968c2ecf20Sopenharmony_ci
105978c2ecf20Sopenharmony_ci		if (val & (1<<11))
105988c2ecf20Sopenharmony_ci			vars->link_status |=
105998c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
106008c2ecf20Sopenharmony_ci
106018c2ecf20Sopenharmony_ci		/* Determine if EEE was negotiated */
106028c2ecf20Sopenharmony_ci		if (bnx2x_is_8483x_8485x(phy))
106038c2ecf20Sopenharmony_ci			bnx2x_eee_an_resolve(phy, params, vars);
106048c2ecf20Sopenharmony_ci	}
106058c2ecf20Sopenharmony_ci
106068c2ecf20Sopenharmony_ci	return link_up;
106078c2ecf20Sopenharmony_ci}
106088c2ecf20Sopenharmony_ci
106098c2ecf20Sopenharmony_cistatic int bnx2x_8485x_format_ver(u32 raw_ver, u8 *str, u16 *len)
106108c2ecf20Sopenharmony_ci{
106118c2ecf20Sopenharmony_ci	u32 num;
106128c2ecf20Sopenharmony_ci
106138c2ecf20Sopenharmony_ci	num = ((raw_ver & 0xF80) >> 7) << 16 | ((raw_ver & 0x7F) << 8) |
106148c2ecf20Sopenharmony_ci	      ((raw_ver & 0xF000) >> 12);
106158c2ecf20Sopenharmony_ci	return bnx2x_3_seq_format_ver(num, str, len);
106168c2ecf20Sopenharmony_ci}
106178c2ecf20Sopenharmony_ci
106188c2ecf20Sopenharmony_cistatic int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
106198c2ecf20Sopenharmony_ci{
106208c2ecf20Sopenharmony_ci	u32 spirom_ver;
106218c2ecf20Sopenharmony_ci
106228c2ecf20Sopenharmony_ci	spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
106238c2ecf20Sopenharmony_ci	return bnx2x_format_ver(spirom_ver, str, len);
106248c2ecf20Sopenharmony_ci}
106258c2ecf20Sopenharmony_ci
106268c2ecf20Sopenharmony_cistatic void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
106278c2ecf20Sopenharmony_ci				struct link_params *params)
106288c2ecf20Sopenharmony_ci{
106298c2ecf20Sopenharmony_ci	bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
106308c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
106318c2ecf20Sopenharmony_ci	bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
106328c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
106338c2ecf20Sopenharmony_ci}
106348c2ecf20Sopenharmony_ci
106358c2ecf20Sopenharmony_cistatic void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
106368c2ecf20Sopenharmony_ci					struct link_params *params)
106378c2ecf20Sopenharmony_ci{
106388c2ecf20Sopenharmony_ci	bnx2x_cl45_write(params->bp, phy,
106398c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
106408c2ecf20Sopenharmony_ci	bnx2x_cl45_write(params->bp, phy,
106418c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
106428c2ecf20Sopenharmony_ci}
106438c2ecf20Sopenharmony_ci
106448c2ecf20Sopenharmony_cistatic void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
106458c2ecf20Sopenharmony_ci				   struct link_params *params)
106468c2ecf20Sopenharmony_ci{
106478c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
106488c2ecf20Sopenharmony_ci	u8 port;
106498c2ecf20Sopenharmony_ci	u16 val16;
106508c2ecf20Sopenharmony_ci
106518c2ecf20Sopenharmony_ci	if (!(CHIP_IS_E1x(bp)))
106528c2ecf20Sopenharmony_ci		port = BP_PATH(bp);
106538c2ecf20Sopenharmony_ci	else
106548c2ecf20Sopenharmony_ci		port = params->port;
106558c2ecf20Sopenharmony_ci
106568c2ecf20Sopenharmony_ci	if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
106578c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
106588c2ecf20Sopenharmony_ci			       MISC_REGISTERS_GPIO_OUTPUT_LOW,
106598c2ecf20Sopenharmony_ci			       port);
106608c2ecf20Sopenharmony_ci	} else {
106618c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
106628c2ecf20Sopenharmony_ci				MDIO_CTL_DEVAD,
106638c2ecf20Sopenharmony_ci				MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
106648c2ecf20Sopenharmony_ci		val16 |= MDIO_84833_SUPER_ISOLATE;
106658c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
106668c2ecf20Sopenharmony_ci				 MDIO_CTL_DEVAD,
106678c2ecf20Sopenharmony_ci				 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
106688c2ecf20Sopenharmony_ci	}
106698c2ecf20Sopenharmony_ci}
106708c2ecf20Sopenharmony_ci
106718c2ecf20Sopenharmony_cistatic void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
106728c2ecf20Sopenharmony_ci				     struct link_params *params, u8 mode)
106738c2ecf20Sopenharmony_ci{
106748c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
106758c2ecf20Sopenharmony_ci	u16 val;
106768c2ecf20Sopenharmony_ci	u8 port;
106778c2ecf20Sopenharmony_ci
106788c2ecf20Sopenharmony_ci	if (!(CHIP_IS_E1x(bp)))
106798c2ecf20Sopenharmony_ci		port = BP_PATH(bp);
106808c2ecf20Sopenharmony_ci	else
106818c2ecf20Sopenharmony_ci		port = params->port;
106828c2ecf20Sopenharmony_ci
106838c2ecf20Sopenharmony_ci	switch (mode) {
106848c2ecf20Sopenharmony_ci	case LED_MODE_OFF:
106858c2ecf20Sopenharmony_ci
106868c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
106878c2ecf20Sopenharmony_ci
106888c2ecf20Sopenharmony_ci		if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
106898c2ecf20Sopenharmony_ci		    SHARED_HW_CFG_LED_EXTPHY1) {
106908c2ecf20Sopenharmony_ci
106918c2ecf20Sopenharmony_ci			/* Set LED masks */
106928c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
106938c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
106948c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LED1_MASK,
106958c2ecf20Sopenharmony_ci					0x0);
106968c2ecf20Sopenharmony_ci
106978c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
106988c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
106998c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LED2_MASK,
107008c2ecf20Sopenharmony_ci					0x0);
107018c2ecf20Sopenharmony_ci
107028c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107038c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
107048c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LED3_MASK,
107058c2ecf20Sopenharmony_ci					0x0);
107068c2ecf20Sopenharmony_ci
107078c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107088c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
107098c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LED5_MASK,
107108c2ecf20Sopenharmony_ci					0x0);
107118c2ecf20Sopenharmony_ci
107128c2ecf20Sopenharmony_ci		} else {
107138c2ecf20Sopenharmony_ci			/* LED 1 OFF */
107148c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107158c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107168c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
107178c2ecf20Sopenharmony_ci					 0x0);
107188c2ecf20Sopenharmony_ci
107198c2ecf20Sopenharmony_ci			if (phy->type ==
107208c2ecf20Sopenharmony_ci				PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
107218c2ecf20Sopenharmony_ci				/* LED 2 OFF */
107228c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
107238c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
107248c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED2_MASK,
107258c2ecf20Sopenharmony_ci						 0x0);
107268c2ecf20Sopenharmony_ci				/* LED 3 OFF */
107278c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
107288c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
107298c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED3_MASK,
107308c2ecf20Sopenharmony_ci						 0x0);
107318c2ecf20Sopenharmony_ci			}
107328c2ecf20Sopenharmony_ci		}
107338c2ecf20Sopenharmony_ci		break;
107348c2ecf20Sopenharmony_ci	case LED_MODE_FRONT_PANEL_OFF:
107358c2ecf20Sopenharmony_ci
107368c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
107378c2ecf20Sopenharmony_ci		   port);
107388c2ecf20Sopenharmony_ci
107398c2ecf20Sopenharmony_ci		if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
107408c2ecf20Sopenharmony_ci		    SHARED_HW_CFG_LED_EXTPHY1) {
107418c2ecf20Sopenharmony_ci
107428c2ecf20Sopenharmony_ci			/* Set LED masks */
107438c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107448c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107458c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
107468c2ecf20Sopenharmony_ci					 0x0);
107478c2ecf20Sopenharmony_ci
107488c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107498c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107508c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED2_MASK,
107518c2ecf20Sopenharmony_ci					 0x0);
107528c2ecf20Sopenharmony_ci
107538c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107548c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107558c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED3_MASK,
107568c2ecf20Sopenharmony_ci					 0x0);
107578c2ecf20Sopenharmony_ci
107588c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107598c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107608c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED5_MASK,
107618c2ecf20Sopenharmony_ci					 0x20);
107628c2ecf20Sopenharmony_ci
107638c2ecf20Sopenharmony_ci		} else {
107648c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
107658c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
107668c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
107678c2ecf20Sopenharmony_ci					 0x0);
107688c2ecf20Sopenharmony_ci			if (phy->type ==
107698c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
107708c2ecf20Sopenharmony_ci				/* Disable MI_INT interrupt before setting LED4
107718c2ecf20Sopenharmony_ci				 * source to constant off.
107728c2ecf20Sopenharmony_ci				 */
107738c2ecf20Sopenharmony_ci				if (REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
107748c2ecf20Sopenharmony_ci					   params->port*4) &
107758c2ecf20Sopenharmony_ci				    NIG_MASK_MI_INT) {
107768c2ecf20Sopenharmony_ci					params->link_flags |=
107778c2ecf20Sopenharmony_ci					LINK_FLAGS_INT_DISABLED;
107788c2ecf20Sopenharmony_ci
107798c2ecf20Sopenharmony_ci					bnx2x_bits_dis(
107808c2ecf20Sopenharmony_ci						bp,
107818c2ecf20Sopenharmony_ci						NIG_REG_MASK_INTERRUPT_PORT0 +
107828c2ecf20Sopenharmony_ci						params->port*4,
107838c2ecf20Sopenharmony_ci						NIG_MASK_MI_INT);
107848c2ecf20Sopenharmony_ci				}
107858c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
107868c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
107878c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_SIGNAL_MASK,
107888c2ecf20Sopenharmony_ci						 0x0);
107898c2ecf20Sopenharmony_ci			}
107908c2ecf20Sopenharmony_ci			if (phy->type ==
107918c2ecf20Sopenharmony_ci				PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
107928c2ecf20Sopenharmony_ci				/* LED 2 OFF */
107938c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
107948c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
107958c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED2_MASK,
107968c2ecf20Sopenharmony_ci						 0x0);
107978c2ecf20Sopenharmony_ci				/* LED 3 OFF */
107988c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
107998c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
108008c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED3_MASK,
108018c2ecf20Sopenharmony_ci						 0x0);
108028c2ecf20Sopenharmony_ci			}
108038c2ecf20Sopenharmony_ci		}
108048c2ecf20Sopenharmony_ci		break;
108058c2ecf20Sopenharmony_ci	case LED_MODE_ON:
108068c2ecf20Sopenharmony_ci
108078c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
108088c2ecf20Sopenharmony_ci
108098c2ecf20Sopenharmony_ci		if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
108108c2ecf20Sopenharmony_ci		    SHARED_HW_CFG_LED_EXTPHY1) {
108118c2ecf20Sopenharmony_ci			/* Set control reg */
108128c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
108138c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
108148c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LINK_SIGNAL,
108158c2ecf20Sopenharmony_ci					&val);
108168c2ecf20Sopenharmony_ci			val &= 0x8000;
108178c2ecf20Sopenharmony_ci			val |= 0x2492;
108188c2ecf20Sopenharmony_ci
108198c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108208c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108218c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LINK_SIGNAL,
108228c2ecf20Sopenharmony_ci					 val);
108238c2ecf20Sopenharmony_ci
108248c2ecf20Sopenharmony_ci			/* Set LED masks */
108258c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108268c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108278c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
108288c2ecf20Sopenharmony_ci					 0x0);
108298c2ecf20Sopenharmony_ci
108308c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108318c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108328c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED2_MASK,
108338c2ecf20Sopenharmony_ci					 0x20);
108348c2ecf20Sopenharmony_ci
108358c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108368c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108378c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED3_MASK,
108388c2ecf20Sopenharmony_ci					 0x20);
108398c2ecf20Sopenharmony_ci
108408c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108418c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108428c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED5_MASK,
108438c2ecf20Sopenharmony_ci					 0x0);
108448c2ecf20Sopenharmony_ci		} else {
108458c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
108468c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
108478c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
108488c2ecf20Sopenharmony_ci					 0x20);
108498c2ecf20Sopenharmony_ci			if (phy->type ==
108508c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
108518c2ecf20Sopenharmony_ci				/* Disable MI_INT interrupt before setting LED4
108528c2ecf20Sopenharmony_ci				 * source to constant on.
108538c2ecf20Sopenharmony_ci				 */
108548c2ecf20Sopenharmony_ci				if (REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
108558c2ecf20Sopenharmony_ci					   params->port*4) &
108568c2ecf20Sopenharmony_ci				    NIG_MASK_MI_INT) {
108578c2ecf20Sopenharmony_ci					params->link_flags |=
108588c2ecf20Sopenharmony_ci					LINK_FLAGS_INT_DISABLED;
108598c2ecf20Sopenharmony_ci
108608c2ecf20Sopenharmony_ci					bnx2x_bits_dis(
108618c2ecf20Sopenharmony_ci						bp,
108628c2ecf20Sopenharmony_ci						NIG_REG_MASK_INTERRUPT_PORT0 +
108638c2ecf20Sopenharmony_ci						params->port*4,
108648c2ecf20Sopenharmony_ci						NIG_MASK_MI_INT);
108658c2ecf20Sopenharmony_ci				}
108668c2ecf20Sopenharmony_ci			}
108678c2ecf20Sopenharmony_ci			if (phy->type ==
108688c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
108698c2ecf20Sopenharmony_ci				/* Tell LED3 to constant on */
108708c2ecf20Sopenharmony_ci				bnx2x_cl45_read(bp, phy,
108718c2ecf20Sopenharmony_ci						MDIO_PMA_DEVAD,
108728c2ecf20Sopenharmony_ci						MDIO_PMA_REG_8481_LINK_SIGNAL,
108738c2ecf20Sopenharmony_ci						&val);
108748c2ecf20Sopenharmony_ci				val &= ~(7<<6);
108758c2ecf20Sopenharmony_ci				val |= (2<<6);  /* A83B[8:6]= 2 */
108768c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
108778c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
108788c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LINK_SIGNAL,
108798c2ecf20Sopenharmony_ci						 val);
108808c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
108818c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
108828c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED3_MASK,
108838c2ecf20Sopenharmony_ci						 0x20);
108848c2ecf20Sopenharmony_ci			} else {
108858c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
108868c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
108878c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_SIGNAL_MASK,
108888c2ecf20Sopenharmony_ci						 0x20);
108898c2ecf20Sopenharmony_ci			}
108908c2ecf20Sopenharmony_ci		}
108918c2ecf20Sopenharmony_ci		break;
108928c2ecf20Sopenharmony_ci
108938c2ecf20Sopenharmony_ci	case LED_MODE_OPER:
108948c2ecf20Sopenharmony_ci
108958c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
108968c2ecf20Sopenharmony_ci
108978c2ecf20Sopenharmony_ci		if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
108988c2ecf20Sopenharmony_ci		    SHARED_HW_CFG_LED_EXTPHY1) {
108998c2ecf20Sopenharmony_ci
109008c2ecf20Sopenharmony_ci			/* Set control reg */
109018c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
109028c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
109038c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LINK_SIGNAL,
109048c2ecf20Sopenharmony_ci					&val);
109058c2ecf20Sopenharmony_ci
109068c2ecf20Sopenharmony_ci			if (!((val &
109078c2ecf20Sopenharmony_ci			       MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
109088c2ecf20Sopenharmony_ci			  >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
109098c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
109108c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
109118c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
109128c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LINK_SIGNAL,
109138c2ecf20Sopenharmony_ci						 0xa492);
109148c2ecf20Sopenharmony_ci			}
109158c2ecf20Sopenharmony_ci
109168c2ecf20Sopenharmony_ci			/* Set LED masks */
109178c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109188c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109198c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
109208c2ecf20Sopenharmony_ci					 0x10);
109218c2ecf20Sopenharmony_ci
109228c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109238c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109248c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED2_MASK,
109258c2ecf20Sopenharmony_ci					 0x80);
109268c2ecf20Sopenharmony_ci
109278c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109288c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109298c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED3_MASK,
109308c2ecf20Sopenharmony_ci					 0x98);
109318c2ecf20Sopenharmony_ci
109328c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109338c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109348c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED5_MASK,
109358c2ecf20Sopenharmony_ci					 0x40);
109368c2ecf20Sopenharmony_ci
109378c2ecf20Sopenharmony_ci		} else {
109388c2ecf20Sopenharmony_ci			/* EXTPHY2 LED mode indicate that the 100M/1G/10G LED
109398c2ecf20Sopenharmony_ci			 * sources are all wired through LED1, rather than only
109408c2ecf20Sopenharmony_ci			 * 10G in other modes.
109418c2ecf20Sopenharmony_ci			 */
109428c2ecf20Sopenharmony_ci			val = ((params->hw_led_mode <<
109438c2ecf20Sopenharmony_ci				SHARED_HW_CFG_LED_MODE_SHIFT) ==
109448c2ecf20Sopenharmony_ci			       SHARED_HW_CFG_LED_EXTPHY2) ? 0x98 : 0x80;
109458c2ecf20Sopenharmony_ci
109468c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109478c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109488c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LED1_MASK,
109498c2ecf20Sopenharmony_ci					 val);
109508c2ecf20Sopenharmony_ci
109518c2ecf20Sopenharmony_ci			/* Tell LED3 to blink on source */
109528c2ecf20Sopenharmony_ci			bnx2x_cl45_read(bp, phy,
109538c2ecf20Sopenharmony_ci					MDIO_PMA_DEVAD,
109548c2ecf20Sopenharmony_ci					MDIO_PMA_REG_8481_LINK_SIGNAL,
109558c2ecf20Sopenharmony_ci					&val);
109568c2ecf20Sopenharmony_ci			val &= ~(7<<6);
109578c2ecf20Sopenharmony_ci			val |= (1<<6); /* A83B[8:6]= 1 */
109588c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy,
109598c2ecf20Sopenharmony_ci					 MDIO_PMA_DEVAD,
109608c2ecf20Sopenharmony_ci					 MDIO_PMA_REG_8481_LINK_SIGNAL,
109618c2ecf20Sopenharmony_ci					 val);
109628c2ecf20Sopenharmony_ci			if (phy->type ==
109638c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
109648c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
109658c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
109668c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED2_MASK,
109678c2ecf20Sopenharmony_ci						 0x18);
109688c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
109698c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
109708c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_LED3_MASK,
109718c2ecf20Sopenharmony_ci						 0x06);
109728c2ecf20Sopenharmony_ci			}
109738c2ecf20Sopenharmony_ci			if (phy->type ==
109748c2ecf20Sopenharmony_ci			    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
109758c2ecf20Sopenharmony_ci				/* Restore LED4 source to external link,
109768c2ecf20Sopenharmony_ci				 * and re-enable interrupts.
109778c2ecf20Sopenharmony_ci				 */
109788c2ecf20Sopenharmony_ci				bnx2x_cl45_write(bp, phy,
109798c2ecf20Sopenharmony_ci						 MDIO_PMA_DEVAD,
109808c2ecf20Sopenharmony_ci						 MDIO_PMA_REG_8481_SIGNAL_MASK,
109818c2ecf20Sopenharmony_ci						 0x40);
109828c2ecf20Sopenharmony_ci				if (params->link_flags &
109838c2ecf20Sopenharmony_ci				    LINK_FLAGS_INT_DISABLED) {
109848c2ecf20Sopenharmony_ci					bnx2x_link_int_enable(params);
109858c2ecf20Sopenharmony_ci					params->link_flags &=
109868c2ecf20Sopenharmony_ci						~LINK_FLAGS_INT_DISABLED;
109878c2ecf20Sopenharmony_ci				}
109888c2ecf20Sopenharmony_ci			}
109898c2ecf20Sopenharmony_ci		}
109908c2ecf20Sopenharmony_ci		break;
109918c2ecf20Sopenharmony_ci	}
109928c2ecf20Sopenharmony_ci
109938c2ecf20Sopenharmony_ci	/* This is a workaround for E3+84833 until autoneg
109948c2ecf20Sopenharmony_ci	 * restart is fixed in f/w
109958c2ecf20Sopenharmony_ci	 */
109968c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
109978c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
109988c2ecf20Sopenharmony_ci				MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
109998c2ecf20Sopenharmony_ci	}
110008c2ecf20Sopenharmony_ci}
110018c2ecf20Sopenharmony_ci
110028c2ecf20Sopenharmony_ci/******************************************************************/
110038c2ecf20Sopenharmony_ci/*			54618SE PHY SECTION			  */
110048c2ecf20Sopenharmony_ci/******************************************************************/
110058c2ecf20Sopenharmony_cistatic void bnx2x_54618se_specific_func(struct bnx2x_phy *phy,
110068c2ecf20Sopenharmony_ci					struct link_params *params,
110078c2ecf20Sopenharmony_ci					u32 action)
110088c2ecf20Sopenharmony_ci{
110098c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
110108c2ecf20Sopenharmony_ci	u16 temp;
110118c2ecf20Sopenharmony_ci	switch (action) {
110128c2ecf20Sopenharmony_ci	case PHY_INIT:
110138c2ecf20Sopenharmony_ci		/* Configure LED4: set to INTR (0x6). */
110148c2ecf20Sopenharmony_ci		/* Accessing shadow register 0xe. */
110158c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy,
110168c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_SHADOW,
110178c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_SHADOW_LED_SEL2);
110188c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy,
110198c2ecf20Sopenharmony_ci				MDIO_REG_GPHY_SHADOW,
110208c2ecf20Sopenharmony_ci				&temp);
110218c2ecf20Sopenharmony_ci		temp &= ~(0xf << 4);
110228c2ecf20Sopenharmony_ci		temp |= (0x6 << 4);
110238c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy,
110248c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_SHADOW,
110258c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
110268c2ecf20Sopenharmony_ci		/* Configure INTR based on link status change. */
110278c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy,
110288c2ecf20Sopenharmony_ci				 MDIO_REG_INTR_MASK,
110298c2ecf20Sopenharmony_ci				 ~MDIO_REG_INTR_MASK_LINK_STATUS);
110308c2ecf20Sopenharmony_ci		break;
110318c2ecf20Sopenharmony_ci	}
110328c2ecf20Sopenharmony_ci}
110338c2ecf20Sopenharmony_ci
110348c2ecf20Sopenharmony_cistatic void bnx2x_54618se_config_init(struct bnx2x_phy *phy,
110358c2ecf20Sopenharmony_ci				      struct link_params *params,
110368c2ecf20Sopenharmony_ci				      struct link_vars *vars)
110378c2ecf20Sopenharmony_ci{
110388c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
110398c2ecf20Sopenharmony_ci	u8 port;
110408c2ecf20Sopenharmony_ci	u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
110418c2ecf20Sopenharmony_ci	u32 cfg_pin;
110428c2ecf20Sopenharmony_ci
110438c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "54618SE cfg init\n");
110448c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
110458c2ecf20Sopenharmony_ci
110468c2ecf20Sopenharmony_ci	/* This works with E3 only, no need to check the chip
110478c2ecf20Sopenharmony_ci	 * before determining the port.
110488c2ecf20Sopenharmony_ci	 */
110498c2ecf20Sopenharmony_ci	port = params->port;
110508c2ecf20Sopenharmony_ci
110518c2ecf20Sopenharmony_ci	cfg_pin = (REG_RD(bp, params->shmem_base +
110528c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
110538c2ecf20Sopenharmony_ci			dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
110548c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PHY_RESET_MASK) >>
110558c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PHY_RESET_SHIFT;
110568c2ecf20Sopenharmony_ci
110578c2ecf20Sopenharmony_ci	/* Drive pin high to bring the GPHY out of reset. */
110588c2ecf20Sopenharmony_ci	bnx2x_set_cfg_pin(bp, cfg_pin, 1);
110598c2ecf20Sopenharmony_ci
110608c2ecf20Sopenharmony_ci	/* wait for GPHY to reset */
110618c2ecf20Sopenharmony_ci	msleep(50);
110628c2ecf20Sopenharmony_ci
110638c2ecf20Sopenharmony_ci	/* reset phy */
110648c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
110658c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_CTRL, 0x8000);
110668c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
110678c2ecf20Sopenharmony_ci
110688c2ecf20Sopenharmony_ci	/* Wait for GPHY to reset */
110698c2ecf20Sopenharmony_ci	msleep(50);
110708c2ecf20Sopenharmony_ci
110718c2ecf20Sopenharmony_ci
110728c2ecf20Sopenharmony_ci	bnx2x_54618se_specific_func(phy, params, PHY_INIT);
110738c2ecf20Sopenharmony_ci	/* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
110748c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
110758c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_SHADOW,
110768c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
110778c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
110788c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_SHADOW,
110798c2ecf20Sopenharmony_ci			&temp);
110808c2ecf20Sopenharmony_ci	temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
110818c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
110828c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_SHADOW,
110838c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
110848c2ecf20Sopenharmony_ci
110858c2ecf20Sopenharmony_ci	/* Set up fc */
110868c2ecf20Sopenharmony_ci	/* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
110878c2ecf20Sopenharmony_ci	bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
110888c2ecf20Sopenharmony_ci	fc_val = 0;
110898c2ecf20Sopenharmony_ci	if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
110908c2ecf20Sopenharmony_ci			MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
110918c2ecf20Sopenharmony_ci		fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
110928c2ecf20Sopenharmony_ci
110938c2ecf20Sopenharmony_ci	if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
110948c2ecf20Sopenharmony_ci			MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
110958c2ecf20Sopenharmony_ci		fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
110968c2ecf20Sopenharmony_ci
110978c2ecf20Sopenharmony_ci	/* Read all advertisement */
110988c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
110998c2ecf20Sopenharmony_ci			0x09,
111008c2ecf20Sopenharmony_ci			&an_1000_val);
111018c2ecf20Sopenharmony_ci
111028c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
111038c2ecf20Sopenharmony_ci			0x04,
111048c2ecf20Sopenharmony_ci			&an_10_100_val);
111058c2ecf20Sopenharmony_ci
111068c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
111078c2ecf20Sopenharmony_ci			MDIO_PMA_REG_CTRL,
111088c2ecf20Sopenharmony_ci			&autoneg_val);
111098c2ecf20Sopenharmony_ci
111108c2ecf20Sopenharmony_ci	/* Disable forced speed */
111118c2ecf20Sopenharmony_ci	autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
111128c2ecf20Sopenharmony_ci	an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
111138c2ecf20Sopenharmony_ci			   (1<<11));
111148c2ecf20Sopenharmony_ci
111158c2ecf20Sopenharmony_ci	if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
111168c2ecf20Sopenharmony_ci	     (phy->speed_cap_mask &
111178c2ecf20Sopenharmony_ci	      PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
111188c2ecf20Sopenharmony_ci	    (phy->req_line_speed == SPEED_1000)) {
111198c2ecf20Sopenharmony_ci		an_1000_val |= (1<<8);
111208c2ecf20Sopenharmony_ci		autoneg_val |= (1<<9 | 1<<12);
111218c2ecf20Sopenharmony_ci		if (phy->req_duplex == DUPLEX_FULL)
111228c2ecf20Sopenharmony_ci			an_1000_val |= (1<<9);
111238c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Advertising 1G\n");
111248c2ecf20Sopenharmony_ci	} else
111258c2ecf20Sopenharmony_ci		an_1000_val &= ~((1<<8) | (1<<9));
111268c2ecf20Sopenharmony_ci
111278c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
111288c2ecf20Sopenharmony_ci			0x09,
111298c2ecf20Sopenharmony_ci			an_1000_val);
111308c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
111318c2ecf20Sopenharmony_ci			0x09,
111328c2ecf20Sopenharmony_ci			&an_1000_val);
111338c2ecf20Sopenharmony_ci
111348c2ecf20Sopenharmony_ci	/* Advertise 10/100 link speed */
111358c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_AUTO_NEG) {
111368c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
111378c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) {
111388c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<5);
111398c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
111408c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 10M-HD\n");
111418c2ecf20Sopenharmony_ci		}
111428c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
111438c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) {
111448c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<6);
111458c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
111468c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 10M-FD\n");
111478c2ecf20Sopenharmony_ci		}
111488c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
111498c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
111508c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<7);
111518c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
111528c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 100M-HD\n");
111538c2ecf20Sopenharmony_ci		}
111548c2ecf20Sopenharmony_ci		if (phy->speed_cap_mask &
111558c2ecf20Sopenharmony_ci		    PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
111568c2ecf20Sopenharmony_ci			an_10_100_val |= (1<<8);
111578c2ecf20Sopenharmony_ci			autoneg_val |= (1<<9 | 1<<12);
111588c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Advertising 100M-FD\n");
111598c2ecf20Sopenharmony_ci		}
111608c2ecf20Sopenharmony_ci	}
111618c2ecf20Sopenharmony_ci
111628c2ecf20Sopenharmony_ci	/* Only 10/100 are allowed to work in FORCE mode */
111638c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_100) {
111648c2ecf20Sopenharmony_ci		autoneg_val |= (1<<13);
111658c2ecf20Sopenharmony_ci		/* Enabled AUTO-MDIX when autoneg is disabled */
111668c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy,
111678c2ecf20Sopenharmony_ci				0x18,
111688c2ecf20Sopenharmony_ci				(1<<15 | 1<<9 | 7<<0));
111698c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 100M force\n");
111708c2ecf20Sopenharmony_ci	}
111718c2ecf20Sopenharmony_ci	if (phy->req_line_speed == SPEED_10) {
111728c2ecf20Sopenharmony_ci		/* Enabled AUTO-MDIX when autoneg is disabled */
111738c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy,
111748c2ecf20Sopenharmony_ci				0x18,
111758c2ecf20Sopenharmony_ci				(1<<15 | 1<<9 | 7<<0));
111768c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Setting 10M force\n");
111778c2ecf20Sopenharmony_ci	}
111788c2ecf20Sopenharmony_ci
111798c2ecf20Sopenharmony_ci	if ((phy->flags & FLAGS_EEE) && bnx2x_eee_has_cap(params)) {
111808c2ecf20Sopenharmony_ci		int rc;
111818c2ecf20Sopenharmony_ci
111828c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS,
111838c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_EXP_ACCESS_TOP |
111848c2ecf20Sopenharmony_ci				 MDIO_REG_GPHY_EXP_TOP_2K_BUF);
111858c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, &temp);
111868c2ecf20Sopenharmony_ci		temp &= 0xfffe;
111878c2ecf20Sopenharmony_ci		bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, temp);
111888c2ecf20Sopenharmony_ci
111898c2ecf20Sopenharmony_ci		rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_1G_ADV);
111908c2ecf20Sopenharmony_ci		if (rc) {
111918c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
111928c2ecf20Sopenharmony_ci			bnx2x_eee_disable(phy, params, vars);
111938c2ecf20Sopenharmony_ci		} else if ((params->eee_mode & EEE_MODE_ADV_LPI) &&
111948c2ecf20Sopenharmony_ci			   (phy->req_duplex == DUPLEX_FULL) &&
111958c2ecf20Sopenharmony_ci			   (bnx2x_eee_calc_timer(params) ||
111968c2ecf20Sopenharmony_ci			    !(params->eee_mode & EEE_MODE_ENABLE_LPI))) {
111978c2ecf20Sopenharmony_ci			/* Need to advertise EEE only when requested,
111988c2ecf20Sopenharmony_ci			 * and either no LPI assertion was requested,
111998c2ecf20Sopenharmony_ci			 * or it was requested and a valid timer was set.
112008c2ecf20Sopenharmony_ci			 * Also notice full duplex is required for EEE.
112018c2ecf20Sopenharmony_ci			 */
112028c2ecf20Sopenharmony_ci			bnx2x_eee_advertise(phy, params, vars,
112038c2ecf20Sopenharmony_ci					    SHMEM_EEE_1G_ADV);
112048c2ecf20Sopenharmony_ci		} else {
112058c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Don't Advertise 1GBase-T EEE\n");
112068c2ecf20Sopenharmony_ci			bnx2x_eee_disable(phy, params, vars);
112078c2ecf20Sopenharmony_ci		}
112088c2ecf20Sopenharmony_ci	} else {
112098c2ecf20Sopenharmony_ci		vars->eee_status &= ~SHMEM_EEE_1G_ADV <<
112108c2ecf20Sopenharmony_ci				    SHMEM_EEE_SUPPORTED_SHIFT;
112118c2ecf20Sopenharmony_ci
112128c2ecf20Sopenharmony_ci		if (phy->flags & FLAGS_EEE) {
112138c2ecf20Sopenharmony_ci			/* Handle legacy auto-grEEEn */
112148c2ecf20Sopenharmony_ci			if (params->feature_config_flags &
112158c2ecf20Sopenharmony_ci			    FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
112168c2ecf20Sopenharmony_ci				temp = 6;
112178c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
112188c2ecf20Sopenharmony_ci			} else {
112198c2ecf20Sopenharmony_ci				temp = 0;
112208c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Don't Adv. EEE\n");
112218c2ecf20Sopenharmony_ci			}
112228c2ecf20Sopenharmony_ci			bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
112238c2ecf20Sopenharmony_ci					 MDIO_AN_REG_EEE_ADV, temp);
112248c2ecf20Sopenharmony_ci		}
112258c2ecf20Sopenharmony_ci	}
112268c2ecf20Sopenharmony_ci
112278c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
112288c2ecf20Sopenharmony_ci			0x04,
112298c2ecf20Sopenharmony_ci			an_10_100_val | fc_val);
112308c2ecf20Sopenharmony_ci
112318c2ecf20Sopenharmony_ci	if (phy->req_duplex == DUPLEX_FULL)
112328c2ecf20Sopenharmony_ci		autoneg_val |= (1<<8);
112338c2ecf20Sopenharmony_ci
112348c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
112358c2ecf20Sopenharmony_ci			MDIO_PMA_REG_CTRL, autoneg_val);
112368c2ecf20Sopenharmony_ci}
112378c2ecf20Sopenharmony_ci
112388c2ecf20Sopenharmony_ci
112398c2ecf20Sopenharmony_cistatic void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
112408c2ecf20Sopenharmony_ci				       struct link_params *params, u8 mode)
112418c2ecf20Sopenharmony_ci{
112428c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
112438c2ecf20Sopenharmony_ci	u16 temp;
112448c2ecf20Sopenharmony_ci
112458c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
112468c2ecf20Sopenharmony_ci		MDIO_REG_GPHY_SHADOW,
112478c2ecf20Sopenharmony_ci		MDIO_REG_GPHY_SHADOW_LED_SEL1);
112488c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
112498c2ecf20Sopenharmony_ci		MDIO_REG_GPHY_SHADOW,
112508c2ecf20Sopenharmony_ci		&temp);
112518c2ecf20Sopenharmony_ci	temp &= 0xff00;
112528c2ecf20Sopenharmony_ci
112538c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
112548c2ecf20Sopenharmony_ci	switch (mode) {
112558c2ecf20Sopenharmony_ci	case LED_MODE_FRONT_PANEL_OFF:
112568c2ecf20Sopenharmony_ci	case LED_MODE_OFF:
112578c2ecf20Sopenharmony_ci		temp |= 0x00ee;
112588c2ecf20Sopenharmony_ci		break;
112598c2ecf20Sopenharmony_ci	case LED_MODE_OPER:
112608c2ecf20Sopenharmony_ci		temp |= 0x0001;
112618c2ecf20Sopenharmony_ci		break;
112628c2ecf20Sopenharmony_ci	case LED_MODE_ON:
112638c2ecf20Sopenharmony_ci		temp |= 0x00ff;
112648c2ecf20Sopenharmony_ci		break;
112658c2ecf20Sopenharmony_ci	default:
112668c2ecf20Sopenharmony_ci		break;
112678c2ecf20Sopenharmony_ci	}
112688c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy,
112698c2ecf20Sopenharmony_ci		MDIO_REG_GPHY_SHADOW,
112708c2ecf20Sopenharmony_ci		MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
112718c2ecf20Sopenharmony_ci	return;
112728c2ecf20Sopenharmony_ci}
112738c2ecf20Sopenharmony_ci
112748c2ecf20Sopenharmony_ci
112758c2ecf20Sopenharmony_cistatic void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
112768c2ecf20Sopenharmony_ci				     struct link_params *params)
112778c2ecf20Sopenharmony_ci{
112788c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
112798c2ecf20Sopenharmony_ci	u32 cfg_pin;
112808c2ecf20Sopenharmony_ci	u8 port;
112818c2ecf20Sopenharmony_ci
112828c2ecf20Sopenharmony_ci	/* In case of no EPIO routed to reset the GPHY, put it
112838c2ecf20Sopenharmony_ci	 * in low power mode.
112848c2ecf20Sopenharmony_ci	 */
112858c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
112868c2ecf20Sopenharmony_ci	/* This works with E3 only, no need to check the chip
112878c2ecf20Sopenharmony_ci	 * before determining the port.
112888c2ecf20Sopenharmony_ci	 */
112898c2ecf20Sopenharmony_ci	port = params->port;
112908c2ecf20Sopenharmony_ci	cfg_pin = (REG_RD(bp, params->shmem_base +
112918c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
112928c2ecf20Sopenharmony_ci			dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
112938c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PHY_RESET_MASK) >>
112948c2ecf20Sopenharmony_ci			PORT_HW_CFG_E3_PHY_RESET_SHIFT;
112958c2ecf20Sopenharmony_ci
112968c2ecf20Sopenharmony_ci	/* Drive pin low to put GPHY in reset. */
112978c2ecf20Sopenharmony_ci	bnx2x_set_cfg_pin(bp, cfg_pin, 0);
112988c2ecf20Sopenharmony_ci}
112998c2ecf20Sopenharmony_ci
113008c2ecf20Sopenharmony_cistatic u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
113018c2ecf20Sopenharmony_ci				    struct link_params *params,
113028c2ecf20Sopenharmony_ci				    struct link_vars *vars)
113038c2ecf20Sopenharmony_ci{
113048c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
113058c2ecf20Sopenharmony_ci	u16 val;
113068c2ecf20Sopenharmony_ci	u8 link_up = 0;
113078c2ecf20Sopenharmony_ci	u16 legacy_status, legacy_speed;
113088c2ecf20Sopenharmony_ci
113098c2ecf20Sopenharmony_ci	/* Get speed operation status */
113108c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
113118c2ecf20Sopenharmony_ci			MDIO_REG_GPHY_AUX_STATUS,
113128c2ecf20Sopenharmony_ci			&legacy_status);
113138c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
113148c2ecf20Sopenharmony_ci
113158c2ecf20Sopenharmony_ci	/* Read status to clear the PHY interrupt. */
113168c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy,
113178c2ecf20Sopenharmony_ci			MDIO_REG_INTR_STATUS,
113188c2ecf20Sopenharmony_ci			&val);
113198c2ecf20Sopenharmony_ci
113208c2ecf20Sopenharmony_ci	link_up = ((legacy_status & (1<<2)) == (1<<2));
113218c2ecf20Sopenharmony_ci
113228c2ecf20Sopenharmony_ci	if (link_up) {
113238c2ecf20Sopenharmony_ci		legacy_speed = (legacy_status & (7<<8));
113248c2ecf20Sopenharmony_ci		if (legacy_speed == (7<<8)) {
113258c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
113268c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_FULL;
113278c2ecf20Sopenharmony_ci		} else if (legacy_speed == (6<<8)) {
113288c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_1000;
113298c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
113308c2ecf20Sopenharmony_ci		} else if (legacy_speed == (5<<8)) {
113318c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_100;
113328c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_FULL;
113338c2ecf20Sopenharmony_ci		}
113348c2ecf20Sopenharmony_ci		/* Omitting 100Base-T4 for now */
113358c2ecf20Sopenharmony_ci		else if (legacy_speed == (3<<8)) {
113368c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_100;
113378c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
113388c2ecf20Sopenharmony_ci		} else if (legacy_speed == (2<<8)) {
113398c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10;
113408c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_FULL;
113418c2ecf20Sopenharmony_ci		} else if (legacy_speed == (1<<8)) {
113428c2ecf20Sopenharmony_ci			vars->line_speed = SPEED_10;
113438c2ecf20Sopenharmony_ci			vars->duplex = DUPLEX_HALF;
113448c2ecf20Sopenharmony_ci		} else /* Should not happen */
113458c2ecf20Sopenharmony_ci			vars->line_speed = 0;
113468c2ecf20Sopenharmony_ci
113478c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
113488c2ecf20Sopenharmony_ci		   "Link is up in %dMbps, is_duplex_full= %d\n",
113498c2ecf20Sopenharmony_ci		   vars->line_speed,
113508c2ecf20Sopenharmony_ci		   (vars->duplex == DUPLEX_FULL));
113518c2ecf20Sopenharmony_ci
113528c2ecf20Sopenharmony_ci		/* Check legacy speed AN resolution */
113538c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy,
113548c2ecf20Sopenharmony_ci				0x01,
113558c2ecf20Sopenharmony_ci				&val);
113568c2ecf20Sopenharmony_ci		if (val & (1<<5))
113578c2ecf20Sopenharmony_ci			vars->link_status |=
113588c2ecf20Sopenharmony_ci				LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
113598c2ecf20Sopenharmony_ci		bnx2x_cl22_read(bp, phy,
113608c2ecf20Sopenharmony_ci				0x06,
113618c2ecf20Sopenharmony_ci				&val);
113628c2ecf20Sopenharmony_ci		if ((val & (1<<0)) == 0)
113638c2ecf20Sopenharmony_ci			vars->link_status |=
113648c2ecf20Sopenharmony_ci				LINK_STATUS_PARALLEL_DETECTION_USED;
113658c2ecf20Sopenharmony_ci
113668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
113678c2ecf20Sopenharmony_ci			   vars->line_speed);
113688c2ecf20Sopenharmony_ci
113698c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
113708c2ecf20Sopenharmony_ci
113718c2ecf20Sopenharmony_ci		if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
113728c2ecf20Sopenharmony_ci			/* Report LP advertised speeds */
113738c2ecf20Sopenharmony_ci			bnx2x_cl22_read(bp, phy, 0x5, &val);
113748c2ecf20Sopenharmony_ci
113758c2ecf20Sopenharmony_ci			if (val & (1<<5))
113768c2ecf20Sopenharmony_ci				vars->link_status |=
113778c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
113788c2ecf20Sopenharmony_ci			if (val & (1<<6))
113798c2ecf20Sopenharmony_ci				vars->link_status |=
113808c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
113818c2ecf20Sopenharmony_ci			if (val & (1<<7))
113828c2ecf20Sopenharmony_ci				vars->link_status |=
113838c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
113848c2ecf20Sopenharmony_ci			if (val & (1<<8))
113858c2ecf20Sopenharmony_ci				vars->link_status |=
113868c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
113878c2ecf20Sopenharmony_ci			if (val & (1<<9))
113888c2ecf20Sopenharmony_ci				vars->link_status |=
113898c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
113908c2ecf20Sopenharmony_ci
113918c2ecf20Sopenharmony_ci			bnx2x_cl22_read(bp, phy, 0xa, &val);
113928c2ecf20Sopenharmony_ci			if (val & (1<<10))
113938c2ecf20Sopenharmony_ci				vars->link_status |=
113948c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
113958c2ecf20Sopenharmony_ci			if (val & (1<<11))
113968c2ecf20Sopenharmony_ci				vars->link_status |=
113978c2ecf20Sopenharmony_ci				  LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
113988c2ecf20Sopenharmony_ci
113998c2ecf20Sopenharmony_ci			if ((phy->flags & FLAGS_EEE) &&
114008c2ecf20Sopenharmony_ci			    bnx2x_eee_has_cap(params))
114018c2ecf20Sopenharmony_ci				bnx2x_eee_an_resolve(phy, params, vars);
114028c2ecf20Sopenharmony_ci		}
114038c2ecf20Sopenharmony_ci	}
114048c2ecf20Sopenharmony_ci	return link_up;
114058c2ecf20Sopenharmony_ci}
114068c2ecf20Sopenharmony_ci
114078c2ecf20Sopenharmony_cistatic void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
114088c2ecf20Sopenharmony_ci					  struct link_params *params)
114098c2ecf20Sopenharmony_ci{
114108c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
114118c2ecf20Sopenharmony_ci	u16 val;
114128c2ecf20Sopenharmony_ci	u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
114138c2ecf20Sopenharmony_ci
114148c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
114158c2ecf20Sopenharmony_ci
114168c2ecf20Sopenharmony_ci	/* Enable master/slave manual mmode and set to master */
114178c2ecf20Sopenharmony_ci	/* mii write 9 [bits set 11 12] */
114188c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
114198c2ecf20Sopenharmony_ci
114208c2ecf20Sopenharmony_ci	/* forced 1G and disable autoneg */
114218c2ecf20Sopenharmony_ci	/* set val [mii read 0] */
114228c2ecf20Sopenharmony_ci	/* set val [expr $val & [bits clear 6 12 13]] */
114238c2ecf20Sopenharmony_ci	/* set val [expr $val | [bits set 6 8]] */
114248c2ecf20Sopenharmony_ci	/* mii write 0 $val */
114258c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy, 0x00, &val);
114268c2ecf20Sopenharmony_ci	val &= ~((1<<6) | (1<<12) | (1<<13));
114278c2ecf20Sopenharmony_ci	val |= (1<<6) | (1<<8);
114288c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy, 0x00, val);
114298c2ecf20Sopenharmony_ci
114308c2ecf20Sopenharmony_ci	/* Set external loopback and Tx using 6dB coding */
114318c2ecf20Sopenharmony_ci	/* mii write 0x18 7 */
114328c2ecf20Sopenharmony_ci	/* set val [mii read 0x18] */
114338c2ecf20Sopenharmony_ci	/* mii write 0x18 [expr $val | [bits set 10 15]] */
114348c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy, 0x18, 7);
114358c2ecf20Sopenharmony_ci	bnx2x_cl22_read(bp, phy, 0x18, &val);
114368c2ecf20Sopenharmony_ci	bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
114378c2ecf20Sopenharmony_ci
114388c2ecf20Sopenharmony_ci	/* This register opens the gate for the UMAC despite its name */
114398c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
114408c2ecf20Sopenharmony_ci
114418c2ecf20Sopenharmony_ci	/* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
114428c2ecf20Sopenharmony_ci	 * length used by the MAC receive logic to check frames.
114438c2ecf20Sopenharmony_ci	 */
114448c2ecf20Sopenharmony_ci	REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
114458c2ecf20Sopenharmony_ci}
114468c2ecf20Sopenharmony_ci
114478c2ecf20Sopenharmony_ci/******************************************************************/
114488c2ecf20Sopenharmony_ci/*			SFX7101 PHY SECTION			  */
114498c2ecf20Sopenharmony_ci/******************************************************************/
114508c2ecf20Sopenharmony_cistatic void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
114518c2ecf20Sopenharmony_ci				       struct link_params *params)
114528c2ecf20Sopenharmony_ci{
114538c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
114548c2ecf20Sopenharmony_ci	/* SFX7101_XGXS_TEST1 */
114558c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
114568c2ecf20Sopenharmony_ci			 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
114578c2ecf20Sopenharmony_ci}
114588c2ecf20Sopenharmony_ci
114598c2ecf20Sopenharmony_cistatic void bnx2x_7101_config_init(struct bnx2x_phy *phy,
114608c2ecf20Sopenharmony_ci				   struct link_params *params,
114618c2ecf20Sopenharmony_ci				   struct link_vars *vars)
114628c2ecf20Sopenharmony_ci{
114638c2ecf20Sopenharmony_ci	u16 fw_ver1, fw_ver2, val;
114648c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
114658c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
114668c2ecf20Sopenharmony_ci
114678c2ecf20Sopenharmony_ci	/* Restore normal power mode*/
114688c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
114698c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
114708c2ecf20Sopenharmony_ci	/* HW reset */
114718c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, params->port);
114728c2ecf20Sopenharmony_ci	bnx2x_wait_reset_complete(bp, phy, params);
114738c2ecf20Sopenharmony_ci
114748c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
114758c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
114768c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
114778c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
114788c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
114798c2ecf20Sopenharmony_ci
114808c2ecf20Sopenharmony_ci	bnx2x_ext_phy_set_pause(params, phy, vars);
114818c2ecf20Sopenharmony_ci	/* Restart autoneg */
114828c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
114838c2ecf20Sopenharmony_ci			MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
114848c2ecf20Sopenharmony_ci	val |= 0x200;
114858c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
114868c2ecf20Sopenharmony_ci			 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
114878c2ecf20Sopenharmony_ci
114888c2ecf20Sopenharmony_ci	/* Save spirom version */
114898c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
114908c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
114918c2ecf20Sopenharmony_ci
114928c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
114938c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
114948c2ecf20Sopenharmony_ci	bnx2x_save_spirom_version(bp, params->port,
114958c2ecf20Sopenharmony_ci				  (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
114968c2ecf20Sopenharmony_ci}
114978c2ecf20Sopenharmony_ci
114988c2ecf20Sopenharmony_cistatic u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
114998c2ecf20Sopenharmony_ci				 struct link_params *params,
115008c2ecf20Sopenharmony_ci				 struct link_vars *vars)
115018c2ecf20Sopenharmony_ci{
115028c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
115038c2ecf20Sopenharmony_ci	u8 link_up;
115048c2ecf20Sopenharmony_ci	u16 val1, val2;
115058c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
115068c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
115078c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
115088c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
115098c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
115108c2ecf20Sopenharmony_ci		   val2, val1);
115118c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
115128c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
115138c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
115148c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
115158c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
115168c2ecf20Sopenharmony_ci		   val2, val1);
115178c2ecf20Sopenharmony_ci	link_up = ((val1 & 4) == 4);
115188c2ecf20Sopenharmony_ci	/* If link is up print the AN outcome of the SFX7101 PHY */
115198c2ecf20Sopenharmony_ci	if (link_up) {
115208c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
115218c2ecf20Sopenharmony_ci				MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
115228c2ecf20Sopenharmony_ci				&val2);
115238c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
115248c2ecf20Sopenharmony_ci		vars->duplex = DUPLEX_FULL;
115258c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
115268c2ecf20Sopenharmony_ci			   val2, (val2 & (1<<14)));
115278c2ecf20Sopenharmony_ci		bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
115288c2ecf20Sopenharmony_ci		bnx2x_ext_phy_resolve_fc(phy, params, vars);
115298c2ecf20Sopenharmony_ci
115308c2ecf20Sopenharmony_ci		/* Read LP advertised speeds */
115318c2ecf20Sopenharmony_ci		if (val2 & (1<<11))
115328c2ecf20Sopenharmony_ci			vars->link_status |=
115338c2ecf20Sopenharmony_ci				LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
115348c2ecf20Sopenharmony_ci	}
115358c2ecf20Sopenharmony_ci	return link_up;
115368c2ecf20Sopenharmony_ci}
115378c2ecf20Sopenharmony_ci
115388c2ecf20Sopenharmony_cistatic int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
115398c2ecf20Sopenharmony_ci{
115408c2ecf20Sopenharmony_ci	if (*len < 5)
115418c2ecf20Sopenharmony_ci		return -EINVAL;
115428c2ecf20Sopenharmony_ci	str[0] = (spirom_ver & 0xFF);
115438c2ecf20Sopenharmony_ci	str[1] = (spirom_ver & 0xFF00) >> 8;
115448c2ecf20Sopenharmony_ci	str[2] = (spirom_ver & 0xFF0000) >> 16;
115458c2ecf20Sopenharmony_ci	str[3] = (spirom_ver & 0xFF000000) >> 24;
115468c2ecf20Sopenharmony_ci	str[4] = '\0';
115478c2ecf20Sopenharmony_ci	*len -= 5;
115488c2ecf20Sopenharmony_ci	return 0;
115498c2ecf20Sopenharmony_ci}
115508c2ecf20Sopenharmony_ci
115518c2ecf20Sopenharmony_civoid bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
115528c2ecf20Sopenharmony_ci{
115538c2ecf20Sopenharmony_ci	u16 val, cnt;
115548c2ecf20Sopenharmony_ci
115558c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy,
115568c2ecf20Sopenharmony_ci			MDIO_PMA_DEVAD,
115578c2ecf20Sopenharmony_ci			MDIO_PMA_REG_7101_RESET, &val);
115588c2ecf20Sopenharmony_ci
115598c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < 10; cnt++) {
115608c2ecf20Sopenharmony_ci		msleep(50);
115618c2ecf20Sopenharmony_ci		/* Writes a self-clearing reset */
115628c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy,
115638c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
115648c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_7101_RESET,
115658c2ecf20Sopenharmony_ci				 (val | (1<<15)));
115668c2ecf20Sopenharmony_ci		/* Wait for clear */
115678c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy,
115688c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
115698c2ecf20Sopenharmony_ci				MDIO_PMA_REG_7101_RESET, &val);
115708c2ecf20Sopenharmony_ci
115718c2ecf20Sopenharmony_ci		if ((val & (1<<15)) == 0)
115728c2ecf20Sopenharmony_ci			break;
115738c2ecf20Sopenharmony_ci	}
115748c2ecf20Sopenharmony_ci}
115758c2ecf20Sopenharmony_ci
115768c2ecf20Sopenharmony_cistatic void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
115778c2ecf20Sopenharmony_ci				struct link_params *params) {
115788c2ecf20Sopenharmony_ci	/* Low power mode is controlled by GPIO 2 */
115798c2ecf20Sopenharmony_ci	bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
115808c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
115818c2ecf20Sopenharmony_ci	/* The PHY reset is controlled by GPIO 1 */
115828c2ecf20Sopenharmony_ci	bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
115838c2ecf20Sopenharmony_ci		       MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
115848c2ecf20Sopenharmony_ci}
115858c2ecf20Sopenharmony_ci
115868c2ecf20Sopenharmony_cistatic void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
115878c2ecf20Sopenharmony_ci				    struct link_params *params, u8 mode)
115888c2ecf20Sopenharmony_ci{
115898c2ecf20Sopenharmony_ci	u16 val = 0;
115908c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
115918c2ecf20Sopenharmony_ci	switch (mode) {
115928c2ecf20Sopenharmony_ci	case LED_MODE_FRONT_PANEL_OFF:
115938c2ecf20Sopenharmony_ci	case LED_MODE_OFF:
115948c2ecf20Sopenharmony_ci		val = 2;
115958c2ecf20Sopenharmony_ci		break;
115968c2ecf20Sopenharmony_ci	case LED_MODE_ON:
115978c2ecf20Sopenharmony_ci		val = 1;
115988c2ecf20Sopenharmony_ci		break;
115998c2ecf20Sopenharmony_ci	case LED_MODE_OPER:
116008c2ecf20Sopenharmony_ci		val = 0;
116018c2ecf20Sopenharmony_ci		break;
116028c2ecf20Sopenharmony_ci	}
116038c2ecf20Sopenharmony_ci	bnx2x_cl45_write(bp, phy,
116048c2ecf20Sopenharmony_ci			 MDIO_PMA_DEVAD,
116058c2ecf20Sopenharmony_ci			 MDIO_PMA_REG_7107_LINK_LED_CNTL,
116068c2ecf20Sopenharmony_ci			 val);
116078c2ecf20Sopenharmony_ci}
116088c2ecf20Sopenharmony_ci
116098c2ecf20Sopenharmony_ci/******************************************************************/
116108c2ecf20Sopenharmony_ci/*			STATIC PHY DECLARATION			  */
116118c2ecf20Sopenharmony_ci/******************************************************************/
116128c2ecf20Sopenharmony_ci
116138c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_null = {
116148c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
116158c2ecf20Sopenharmony_ci	.addr		= 0,
116168c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
116178c2ecf20Sopenharmony_ci	.flags		= FLAGS_INIT_XGXS_FIRST,
116188c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116198c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116208c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
116218c2ecf20Sopenharmony_ci	.supported	= 0,
116228c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_NOT_PRESENT,
116238c2ecf20Sopenharmony_ci	.ver_addr	= 0,
116248c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
116258c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
116268c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
116278c2ecf20Sopenharmony_ci	.req_duplex	= 0,
116288c2ecf20Sopenharmony_ci	.rsrv		= 0,
116298c2ecf20Sopenharmony_ci	.config_init	= NULL,
116308c2ecf20Sopenharmony_ci	.read_status	= NULL,
116318c2ecf20Sopenharmony_ci	.link_reset	= NULL,
116328c2ecf20Sopenharmony_ci	.config_loopback = NULL,
116338c2ecf20Sopenharmony_ci	.format_fw_ver	= NULL,
116348c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
116358c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
116368c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
116378c2ecf20Sopenharmony_ci};
116388c2ecf20Sopenharmony_ci
116398c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_serdes = {
116408c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
116418c2ecf20Sopenharmony_ci	.addr		= 0xff,
116428c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
116438c2ecf20Sopenharmony_ci	.flags		= 0,
116448c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116458c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116468c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
116478c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
116488c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
116498c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
116508c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
116518c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
116528c2ecf20Sopenharmony_ci			   SUPPORTED_2500baseX_Full |
116538c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
116548c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
116558c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
116568c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
116578c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
116588c2ecf20Sopenharmony_ci	.ver_addr	= 0,
116598c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
116608c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
116618c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
116628c2ecf20Sopenharmony_ci	.req_duplex	= 0,
116638c2ecf20Sopenharmony_ci	.rsrv		= 0,
116648c2ecf20Sopenharmony_ci	.config_init	= bnx2x_xgxs_config_init,
116658c2ecf20Sopenharmony_ci	.read_status	= bnx2x_link_settings_status,
116668c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_int_link_reset,
116678c2ecf20Sopenharmony_ci	.config_loopback = NULL,
116688c2ecf20Sopenharmony_ci	.format_fw_ver	= NULL,
116698c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
116708c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
116718c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
116728c2ecf20Sopenharmony_ci};
116738c2ecf20Sopenharmony_ci
116748c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_xgxs = {
116758c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
116768c2ecf20Sopenharmony_ci	.addr		= 0xff,
116778c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
116788c2ecf20Sopenharmony_ci	.flags		= 0,
116798c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116808c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
116818c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
116828c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
116838c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
116848c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
116858c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
116868c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
116878c2ecf20Sopenharmony_ci			   SUPPORTED_2500baseX_Full |
116888c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
116898c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
116908c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
116918c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
116928c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
116938c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_CX4,
116948c2ecf20Sopenharmony_ci	.ver_addr	= 0,
116958c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
116968c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
116978c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
116988c2ecf20Sopenharmony_ci	.req_duplex	= 0,
116998c2ecf20Sopenharmony_ci	.rsrv		= 0,
117008c2ecf20Sopenharmony_ci	.config_init	= bnx2x_xgxs_config_init,
117018c2ecf20Sopenharmony_ci	.read_status	= bnx2x_link_settings_status,
117028c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_int_link_reset,
117038c2ecf20Sopenharmony_ci	.config_loopback = bnx2x_set_xgxs_loopback,
117048c2ecf20Sopenharmony_ci	.format_fw_ver	= NULL,
117058c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
117068c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
117078c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_xgxs_specific_func
117088c2ecf20Sopenharmony_ci};
117098c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_warpcore = {
117108c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
117118c2ecf20Sopenharmony_ci	.addr		= 0xff,
117128c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
117138c2ecf20Sopenharmony_ci	.flags		= FLAGS_TX_ERROR_CHECK,
117148c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117158c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117168c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
117178c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
117188c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
117198c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
117208c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
117218c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
117228c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseKX_Full |
117238c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
117248c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseKR_Full |
117258c2ecf20Sopenharmony_ci			   SUPPORTED_20000baseKR2_Full |
117268c2ecf20Sopenharmony_ci			   SUPPORTED_20000baseMLD2_Full |
117278c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
117288c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
117298c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
117308c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
117318c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_UNSPECIFIED,
117328c2ecf20Sopenharmony_ci	.ver_addr	= 0,
117338c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
117348c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
117358c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
117368c2ecf20Sopenharmony_ci	/* req_duplex = */0,
117378c2ecf20Sopenharmony_ci	/* rsrv = */0,
117388c2ecf20Sopenharmony_ci	.config_init	= bnx2x_warpcore_config_init,
117398c2ecf20Sopenharmony_ci	.read_status	= bnx2x_warpcore_read_status,
117408c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_warpcore_link_reset,
117418c2ecf20Sopenharmony_ci	.config_loopback = bnx2x_set_warpcore_loopback,
117428c2ecf20Sopenharmony_ci	.format_fw_ver	= NULL,
117438c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_warpcore_hw_reset,
117448c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
117458c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
117468c2ecf20Sopenharmony_ci};
117478c2ecf20Sopenharmony_ci
117488c2ecf20Sopenharmony_ci
117498c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_7101 = {
117508c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
117518c2ecf20Sopenharmony_ci	.addr		= 0xff,
117528c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
117538c2ecf20Sopenharmony_ci	.flags		= FLAGS_FAN_FAILURE_DET_REQ,
117548c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117558c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117568c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
117578c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
117588c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
117598c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
117608c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
117618c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
117628c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
117638c2ecf20Sopenharmony_ci	.ver_addr	= 0,
117648c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
117658c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
117668c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
117678c2ecf20Sopenharmony_ci	.req_duplex	= 0,
117688c2ecf20Sopenharmony_ci	.rsrv		= 0,
117698c2ecf20Sopenharmony_ci	.config_init	= bnx2x_7101_config_init,
117708c2ecf20Sopenharmony_ci	.read_status	= bnx2x_7101_read_status,
117718c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_common_ext_link_reset,
117728c2ecf20Sopenharmony_ci	.config_loopback = bnx2x_7101_config_loopback,
117738c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_7101_format_ver,
117748c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_7101_hw_reset,
117758c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_7101_set_link_led,
117768c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
117778c2ecf20Sopenharmony_ci};
117788c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8073 = {
117798c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
117808c2ecf20Sopenharmony_ci	.addr		= 0xff,
117818c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
117828c2ecf20Sopenharmony_ci	.flags		= 0,
117838c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117848c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
117858c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
117868c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
117878c2ecf20Sopenharmony_ci			   SUPPORTED_2500baseX_Full |
117888c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
117898c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
117908c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
117918c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
117928c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
117938c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_KR,
117948c2ecf20Sopenharmony_ci	.ver_addr	= 0,
117958c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
117968c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
117978c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
117988c2ecf20Sopenharmony_ci	.req_duplex	= 0,
117998c2ecf20Sopenharmony_ci	.rsrv		= 0,
118008c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8073_config_init,
118018c2ecf20Sopenharmony_ci	.read_status	= bnx2x_8073_read_status,
118028c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_8073_link_reset,
118038c2ecf20Sopenharmony_ci	.config_loopback = NULL,
118048c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_format_ver,
118058c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
118068c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
118078c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_8073_specific_func
118088c2ecf20Sopenharmony_ci};
118098c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8705 = {
118108c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
118118c2ecf20Sopenharmony_ci	.addr		= 0xff,
118128c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
118138c2ecf20Sopenharmony_ci	.flags		= FLAGS_INIT_XGXS_FIRST,
118148c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118158c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118168c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
118178c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
118188c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
118198c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
118208c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
118218c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_XFP_FIBER,
118228c2ecf20Sopenharmony_ci	.ver_addr	= 0,
118238c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
118248c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
118258c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
118268c2ecf20Sopenharmony_ci	.req_duplex	= 0,
118278c2ecf20Sopenharmony_ci	.rsrv		= 0,
118288c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8705_config_init,
118298c2ecf20Sopenharmony_ci	.read_status	= bnx2x_8705_read_status,
118308c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_common_ext_link_reset,
118318c2ecf20Sopenharmony_ci	.config_loopback = NULL,
118328c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_null_format_ver,
118338c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
118348c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
118358c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
118368c2ecf20Sopenharmony_ci};
118378c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8706 = {
118388c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
118398c2ecf20Sopenharmony_ci	.addr		= 0xff,
118408c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
118418c2ecf20Sopenharmony_ci	.flags		= FLAGS_INIT_XGXS_FIRST,
118428c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118438c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118448c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
118458c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
118468c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
118478c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
118488c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
118498c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
118508c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_SFPP_10G_FIBER,
118518c2ecf20Sopenharmony_ci	.ver_addr	= 0,
118528c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
118538c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
118548c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
118558c2ecf20Sopenharmony_ci	.req_duplex	= 0,
118568c2ecf20Sopenharmony_ci	.rsrv		= 0,
118578c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8706_config_init,
118588c2ecf20Sopenharmony_ci	.read_status	= bnx2x_8706_read_status,
118598c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_common_ext_link_reset,
118608c2ecf20Sopenharmony_ci	.config_loopback = NULL,
118618c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_format_ver,
118628c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
118638c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
118648c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
118658c2ecf20Sopenharmony_ci};
118668c2ecf20Sopenharmony_ci
118678c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8726 = {
118688c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
118698c2ecf20Sopenharmony_ci	.addr		= 0xff,
118708c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
118718c2ecf20Sopenharmony_ci	.flags		= (FLAGS_INIT_XGXS_FIRST |
118728c2ecf20Sopenharmony_ci			   FLAGS_TX_ERROR_CHECK),
118738c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118748c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
118758c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
118768c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
118778c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
118788c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
118798c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
118808c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
118818c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
118828c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_NOT_PRESENT,
118838c2ecf20Sopenharmony_ci	.ver_addr	= 0,
118848c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
118858c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
118868c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
118878c2ecf20Sopenharmony_ci	.req_duplex	= 0,
118888c2ecf20Sopenharmony_ci	.rsrv		= 0,
118898c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8726_config_init,
118908c2ecf20Sopenharmony_ci	.read_status	= bnx2x_8726_read_status,
118918c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_8726_link_reset,
118928c2ecf20Sopenharmony_ci	.config_loopback = bnx2x_8726_config_loopback,
118938c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_format_ver,
118948c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
118958c2ecf20Sopenharmony_ci	.set_link_led	= NULL,
118968c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
118978c2ecf20Sopenharmony_ci};
118988c2ecf20Sopenharmony_ci
118998c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8727 = {
119008c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
119018c2ecf20Sopenharmony_ci	.addr		= 0xff,
119028c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
119038c2ecf20Sopenharmony_ci	.flags		= (FLAGS_FAN_FAILURE_DET_REQ |
119048c2ecf20Sopenharmony_ci			   FLAGS_TX_ERROR_CHECK),
119058c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119068c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119078c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
119088c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10000baseT_Full |
119098c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
119108c2ecf20Sopenharmony_ci			   SUPPORTED_FIBRE |
119118c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
119128c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
119138c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_NOT_PRESENT,
119148c2ecf20Sopenharmony_ci	.ver_addr	= 0,
119158c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
119168c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
119178c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
119188c2ecf20Sopenharmony_ci	.req_duplex	= 0,
119198c2ecf20Sopenharmony_ci	.rsrv		= 0,
119208c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8727_config_init,
119218c2ecf20Sopenharmony_ci	.read_status	= bnx2x_8727_read_status,
119228c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_8727_link_reset,
119238c2ecf20Sopenharmony_ci	.config_loopback = NULL,
119248c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_format_ver,
119258c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_8727_hw_reset,
119268c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_8727_set_link_led,
119278c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_8727_specific_func
119288c2ecf20Sopenharmony_ci};
119298c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_8481 = {
119308c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
119318c2ecf20Sopenharmony_ci	.addr		= 0xff,
119328c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
119338c2ecf20Sopenharmony_ci	.flags		= FLAGS_FAN_FAILURE_DET_REQ |
119348c2ecf20Sopenharmony_ci			  FLAGS_REARM_LATCH_SIGNAL,
119358c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119368c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119378c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
119388c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
119398c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
119408c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
119418c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
119428c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
119438c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
119448c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
119458c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
119468c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
119478c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
119488c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
119498c2ecf20Sopenharmony_ci	.ver_addr	= 0,
119508c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
119518c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
119528c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
119538c2ecf20Sopenharmony_ci	.req_duplex	= 0,
119548c2ecf20Sopenharmony_ci	.rsrv		= 0,
119558c2ecf20Sopenharmony_ci	.config_init	= bnx2x_8481_config_init,
119568c2ecf20Sopenharmony_ci	.read_status	= bnx2x_848xx_read_status,
119578c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_8481_link_reset,
119588c2ecf20Sopenharmony_ci	.config_loopback = NULL,
119598c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_848xx_format_ver,
119608c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_8481_hw_reset,
119618c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_848xx_set_link_led,
119628c2ecf20Sopenharmony_ci	.phy_specific_func = NULL
119638c2ecf20Sopenharmony_ci};
119648c2ecf20Sopenharmony_ci
119658c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_84823 = {
119668c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
119678c2ecf20Sopenharmony_ci	.addr		= 0xff,
119688c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
119698c2ecf20Sopenharmony_ci	.flags		= (FLAGS_FAN_FAILURE_DET_REQ |
119708c2ecf20Sopenharmony_ci			   FLAGS_REARM_LATCH_SIGNAL |
119718c2ecf20Sopenharmony_ci			   FLAGS_TX_ERROR_CHECK),
119728c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119738c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
119748c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
119758c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
119768c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
119778c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
119788c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
119798c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
119808c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
119818c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
119828c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
119838c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
119848c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
119858c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
119868c2ecf20Sopenharmony_ci	.ver_addr	= 0,
119878c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
119888c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
119898c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
119908c2ecf20Sopenharmony_ci	.req_duplex	= 0,
119918c2ecf20Sopenharmony_ci	.rsrv		= 0,
119928c2ecf20Sopenharmony_ci	.config_init	= bnx2x_848x3_config_init,
119938c2ecf20Sopenharmony_ci	.read_status	= bnx2x_848xx_read_status,
119948c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_848x3_link_reset,
119958c2ecf20Sopenharmony_ci	.config_loopback = NULL,
119968c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_848xx_format_ver,
119978c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
119988c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_848xx_set_link_led,
119998c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_848xx_specific_func
120008c2ecf20Sopenharmony_ci};
120018c2ecf20Sopenharmony_ci
120028c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_84833 = {
120038c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
120048c2ecf20Sopenharmony_ci	.addr		= 0xff,
120058c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
120068c2ecf20Sopenharmony_ci	.flags		= (FLAGS_FAN_FAILURE_DET_REQ |
120078c2ecf20Sopenharmony_ci			   FLAGS_REARM_LATCH_SIGNAL |
120088c2ecf20Sopenharmony_ci			   FLAGS_TX_ERROR_CHECK),
120098c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120108c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120118c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
120128c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_100baseT_Half |
120138c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
120148c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
120158c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
120168c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
120178c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
120188c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
120198c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
120208c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
120218c2ecf20Sopenharmony_ci	.ver_addr	= 0,
120228c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
120238c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
120248c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
120258c2ecf20Sopenharmony_ci	.req_duplex	= 0,
120268c2ecf20Sopenharmony_ci	.rsrv		= 0,
120278c2ecf20Sopenharmony_ci	.config_init	= bnx2x_848x3_config_init,
120288c2ecf20Sopenharmony_ci	.read_status	= bnx2x_848xx_read_status,
120298c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_848x3_link_reset,
120308c2ecf20Sopenharmony_ci	.config_loopback = NULL,
120318c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_848xx_format_ver,
120328c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_84833_hw_reset_phy,
120338c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_848xx_set_link_led,
120348c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_848xx_specific_func
120358c2ecf20Sopenharmony_ci};
120368c2ecf20Sopenharmony_ci
120378c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_84834 = {
120388c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834,
120398c2ecf20Sopenharmony_ci	.addr		= 0xff,
120408c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
120418c2ecf20Sopenharmony_ci	.flags		= FLAGS_FAN_FAILURE_DET_REQ |
120428c2ecf20Sopenharmony_ci			    FLAGS_REARM_LATCH_SIGNAL,
120438c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120448c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120458c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
120468c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_100baseT_Half |
120478c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
120488c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
120498c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
120508c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
120518c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
120528c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
120538c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
120548c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
120558c2ecf20Sopenharmony_ci	.ver_addr	= 0,
120568c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
120578c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
120588c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
120598c2ecf20Sopenharmony_ci	.req_duplex	= 0,
120608c2ecf20Sopenharmony_ci	.rsrv		= 0,
120618c2ecf20Sopenharmony_ci	.config_init	= bnx2x_848x3_config_init,
120628c2ecf20Sopenharmony_ci	.read_status	= bnx2x_848xx_read_status,
120638c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_848x3_link_reset,
120648c2ecf20Sopenharmony_ci	.config_loopback = NULL,
120658c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_848xx_format_ver,
120668c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_84833_hw_reset_phy,
120678c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_848xx_set_link_led,
120688c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_848xx_specific_func
120698c2ecf20Sopenharmony_ci};
120708c2ecf20Sopenharmony_ci
120718c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_84858 = {
120728c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858,
120738c2ecf20Sopenharmony_ci	.addr		= 0xff,
120748c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
120758c2ecf20Sopenharmony_ci	.flags		= FLAGS_FAN_FAILURE_DET_REQ |
120768c2ecf20Sopenharmony_ci			    FLAGS_REARM_LATCH_SIGNAL,
120778c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120788c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
120798c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
120808c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_100baseT_Half |
120818c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
120828c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
120838c2ecf20Sopenharmony_ci			   SUPPORTED_10000baseT_Full |
120848c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
120858c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
120868c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
120878c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
120888c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
120898c2ecf20Sopenharmony_ci	.ver_addr	= 0,
120908c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
120918c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
120928c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
120938c2ecf20Sopenharmony_ci	.req_duplex	= 0,
120948c2ecf20Sopenharmony_ci	.rsrv		= 0,
120958c2ecf20Sopenharmony_ci	.config_init	= bnx2x_848x3_config_init,
120968c2ecf20Sopenharmony_ci	.read_status	= bnx2x_848xx_read_status,
120978c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_848x3_link_reset,
120988c2ecf20Sopenharmony_ci	.config_loopback = NULL,
120998c2ecf20Sopenharmony_ci	.format_fw_ver	= bnx2x_8485x_format_ver,
121008c2ecf20Sopenharmony_ci	.hw_reset	= bnx2x_84833_hw_reset_phy,
121018c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_848xx_set_link_led,
121028c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_848xx_specific_func
121038c2ecf20Sopenharmony_ci};
121048c2ecf20Sopenharmony_ci
121058c2ecf20Sopenharmony_cistatic const struct bnx2x_phy phy_54618se = {
121068c2ecf20Sopenharmony_ci	.type		= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
121078c2ecf20Sopenharmony_ci	.addr		= 0xff,
121088c2ecf20Sopenharmony_ci	.def_md_devad	= 0,
121098c2ecf20Sopenharmony_ci	.flags		= FLAGS_INIT_XGXS_FIRST,
121108c2ecf20Sopenharmony_ci	.rx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
121118c2ecf20Sopenharmony_ci	.tx_preemphasis	= {0xffff, 0xffff, 0xffff, 0xffff},
121128c2ecf20Sopenharmony_ci	.mdio_ctrl	= 0,
121138c2ecf20Sopenharmony_ci	.supported	= (SUPPORTED_10baseT_Half |
121148c2ecf20Sopenharmony_ci			   SUPPORTED_10baseT_Full |
121158c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Half |
121168c2ecf20Sopenharmony_ci			   SUPPORTED_100baseT_Full |
121178c2ecf20Sopenharmony_ci			   SUPPORTED_1000baseT_Full |
121188c2ecf20Sopenharmony_ci			   SUPPORTED_TP |
121198c2ecf20Sopenharmony_ci			   SUPPORTED_Autoneg |
121208c2ecf20Sopenharmony_ci			   SUPPORTED_Pause |
121218c2ecf20Sopenharmony_ci			   SUPPORTED_Asym_Pause),
121228c2ecf20Sopenharmony_ci	.media_type	= ETH_PHY_BASE_T,
121238c2ecf20Sopenharmony_ci	.ver_addr	= 0,
121248c2ecf20Sopenharmony_ci	.req_flow_ctrl	= 0,
121258c2ecf20Sopenharmony_ci	.req_line_speed	= 0,
121268c2ecf20Sopenharmony_ci	.speed_cap_mask	= 0,
121278c2ecf20Sopenharmony_ci	/* req_duplex = */0,
121288c2ecf20Sopenharmony_ci	/* rsrv = */0,
121298c2ecf20Sopenharmony_ci	.config_init	= bnx2x_54618se_config_init,
121308c2ecf20Sopenharmony_ci	.read_status	= bnx2x_54618se_read_status,
121318c2ecf20Sopenharmony_ci	.link_reset	= bnx2x_54618se_link_reset,
121328c2ecf20Sopenharmony_ci	.config_loopback = bnx2x_54618se_config_loopback,
121338c2ecf20Sopenharmony_ci	.format_fw_ver	= NULL,
121348c2ecf20Sopenharmony_ci	.hw_reset	= NULL,
121358c2ecf20Sopenharmony_ci	.set_link_led	= bnx2x_5461x_set_link_led,
121368c2ecf20Sopenharmony_ci	.phy_specific_func = bnx2x_54618se_specific_func
121378c2ecf20Sopenharmony_ci};
121388c2ecf20Sopenharmony_ci/*****************************************************************/
121398c2ecf20Sopenharmony_ci/*                                                               */
121408c2ecf20Sopenharmony_ci/* Populate the phy according. Main function: bnx2x_populate_phy   */
121418c2ecf20Sopenharmony_ci/*                                                               */
121428c2ecf20Sopenharmony_ci/*****************************************************************/
121438c2ecf20Sopenharmony_ci
121448c2ecf20Sopenharmony_cistatic void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
121458c2ecf20Sopenharmony_ci				     struct bnx2x_phy *phy, u8 port,
121468c2ecf20Sopenharmony_ci				     u8 phy_index)
121478c2ecf20Sopenharmony_ci{
121488c2ecf20Sopenharmony_ci	/* Get the 4 lanes xgxs config rx and tx */
121498c2ecf20Sopenharmony_ci	u32 rx = 0, tx = 0, i;
121508c2ecf20Sopenharmony_ci	for (i = 0; i < 2; i++) {
121518c2ecf20Sopenharmony_ci		/* INT_PHY and EXT_PHY1 share the same value location in
121528c2ecf20Sopenharmony_ci		 * the shmem. When num_phys is greater than 1, than this value
121538c2ecf20Sopenharmony_ci		 * applies only to EXT_PHY1
121548c2ecf20Sopenharmony_ci		 */
121558c2ecf20Sopenharmony_ci		if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
121568c2ecf20Sopenharmony_ci			rx = REG_RD(bp, shmem_base +
121578c2ecf20Sopenharmony_ci				    offsetof(struct shmem_region,
121588c2ecf20Sopenharmony_ci			  dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
121598c2ecf20Sopenharmony_ci
121608c2ecf20Sopenharmony_ci			tx = REG_RD(bp, shmem_base +
121618c2ecf20Sopenharmony_ci				    offsetof(struct shmem_region,
121628c2ecf20Sopenharmony_ci			  dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
121638c2ecf20Sopenharmony_ci		} else {
121648c2ecf20Sopenharmony_ci			rx = REG_RD(bp, shmem_base +
121658c2ecf20Sopenharmony_ci				    offsetof(struct shmem_region,
121668c2ecf20Sopenharmony_ci			 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
121678c2ecf20Sopenharmony_ci
121688c2ecf20Sopenharmony_ci			tx = REG_RD(bp, shmem_base +
121698c2ecf20Sopenharmony_ci				    offsetof(struct shmem_region,
121708c2ecf20Sopenharmony_ci			 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
121718c2ecf20Sopenharmony_ci		}
121728c2ecf20Sopenharmony_ci
121738c2ecf20Sopenharmony_ci		phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
121748c2ecf20Sopenharmony_ci		phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
121758c2ecf20Sopenharmony_ci
121768c2ecf20Sopenharmony_ci		phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
121778c2ecf20Sopenharmony_ci		phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
121788c2ecf20Sopenharmony_ci	}
121798c2ecf20Sopenharmony_ci}
121808c2ecf20Sopenharmony_ci
121818c2ecf20Sopenharmony_cistatic u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
121828c2ecf20Sopenharmony_ci				    u8 phy_index, u8 port)
121838c2ecf20Sopenharmony_ci{
121848c2ecf20Sopenharmony_ci	u32 ext_phy_config = 0;
121858c2ecf20Sopenharmony_ci	switch (phy_index) {
121868c2ecf20Sopenharmony_ci	case EXT_PHY1:
121878c2ecf20Sopenharmony_ci		ext_phy_config = REG_RD(bp, shmem_base +
121888c2ecf20Sopenharmony_ci					      offsetof(struct shmem_region,
121898c2ecf20Sopenharmony_ci			dev_info.port_hw_config[port].external_phy_config));
121908c2ecf20Sopenharmony_ci		break;
121918c2ecf20Sopenharmony_ci	case EXT_PHY2:
121928c2ecf20Sopenharmony_ci		ext_phy_config = REG_RD(bp, shmem_base +
121938c2ecf20Sopenharmony_ci					      offsetof(struct shmem_region,
121948c2ecf20Sopenharmony_ci			dev_info.port_hw_config[port].external_phy_config2));
121958c2ecf20Sopenharmony_ci		break;
121968c2ecf20Sopenharmony_ci	default:
121978c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
121988c2ecf20Sopenharmony_ci		return -EINVAL;
121998c2ecf20Sopenharmony_ci	}
122008c2ecf20Sopenharmony_ci
122018c2ecf20Sopenharmony_ci	return ext_phy_config;
122028c2ecf20Sopenharmony_ci}
122038c2ecf20Sopenharmony_cistatic int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
122048c2ecf20Sopenharmony_ci				  struct bnx2x_phy *phy)
122058c2ecf20Sopenharmony_ci{
122068c2ecf20Sopenharmony_ci	u32 phy_addr;
122078c2ecf20Sopenharmony_ci	u32 chip_id;
122088c2ecf20Sopenharmony_ci	u32 switch_cfg = (REG_RD(bp, shmem_base +
122098c2ecf20Sopenharmony_ci				       offsetof(struct shmem_region,
122108c2ecf20Sopenharmony_ci			dev_info.port_feature_config[port].link_config)) &
122118c2ecf20Sopenharmony_ci			  PORT_FEATURE_CONNECTED_SWITCH_MASK);
122128c2ecf20Sopenharmony_ci	chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
122138c2ecf20Sopenharmony_ci		((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
122148c2ecf20Sopenharmony_ci
122158c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
122168c2ecf20Sopenharmony_ci	if (USES_WARPCORE(bp)) {
122178c2ecf20Sopenharmony_ci		u32 serdes_net_if;
122188c2ecf20Sopenharmony_ci		phy_addr = REG_RD(bp,
122198c2ecf20Sopenharmony_ci				  MISC_REG_WC0_CTRL_PHY_ADDR);
122208c2ecf20Sopenharmony_ci		*phy = phy_warpcore;
122218c2ecf20Sopenharmony_ci		if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
122228c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_4_PORT_MODE;
122238c2ecf20Sopenharmony_ci		else
122248c2ecf20Sopenharmony_ci			phy->flags &= ~FLAGS_4_PORT_MODE;
122258c2ecf20Sopenharmony_ci			/* Check Dual mode */
122268c2ecf20Sopenharmony_ci		serdes_net_if = (REG_RD(bp, shmem_base +
122278c2ecf20Sopenharmony_ci					offsetof(struct shmem_region, dev_info.
122288c2ecf20Sopenharmony_ci					port_hw_config[port].default_cfg)) &
122298c2ecf20Sopenharmony_ci				 PORT_HW_CFG_NET_SERDES_IF_MASK);
122308c2ecf20Sopenharmony_ci		/* Set the appropriate supported and flags indications per
122318c2ecf20Sopenharmony_ci		 * interface type of the chip
122328c2ecf20Sopenharmony_ci		 */
122338c2ecf20Sopenharmony_ci		switch (serdes_net_if) {
122348c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_SGMII:
122358c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_10baseT_Half |
122368c2ecf20Sopenharmony_ci					   SUPPORTED_10baseT_Full |
122378c2ecf20Sopenharmony_ci					   SUPPORTED_100baseT_Half |
122388c2ecf20Sopenharmony_ci					   SUPPORTED_100baseT_Full |
122398c2ecf20Sopenharmony_ci					   SUPPORTED_1000baseT_Full |
122408c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122418c2ecf20Sopenharmony_ci					   SUPPORTED_Autoneg |
122428c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122438c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122448c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_BASE_T;
122458c2ecf20Sopenharmony_ci			break;
122468c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_XFI:
122478c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_1000baseT_Full |
122488c2ecf20Sopenharmony_ci					   SUPPORTED_10000baseT_Full |
122498c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122508c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122518c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122528c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_XFP_FIBER;
122538c2ecf20Sopenharmony_ci			break;
122548c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_SFI:
122558c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_1000baseT_Full |
122568c2ecf20Sopenharmony_ci					   SUPPORTED_10000baseT_Full |
122578c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122588c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122598c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122608c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_SFPP_10G_FIBER;
122618c2ecf20Sopenharmony_ci			break;
122628c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_KR:
122638c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_KR;
122648c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_1000baseKX_Full |
122658c2ecf20Sopenharmony_ci					   SUPPORTED_10000baseKR_Full |
122668c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122678c2ecf20Sopenharmony_ci					   SUPPORTED_Autoneg |
122688c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122698c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122708c2ecf20Sopenharmony_ci			break;
122718c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
122728c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_KR;
122738c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_WC_DUAL_MODE;
122748c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_20000baseMLD2_Full |
122758c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122768c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122778c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122788c2ecf20Sopenharmony_ci			break;
122798c2ecf20Sopenharmony_ci		case PORT_HW_CFG_NET_SERDES_IF_KR2:
122808c2ecf20Sopenharmony_ci			phy->media_type = ETH_PHY_KR;
122818c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_WC_DUAL_MODE;
122828c2ecf20Sopenharmony_ci			phy->supported &= (SUPPORTED_20000baseKR2_Full |
122838c2ecf20Sopenharmony_ci					   SUPPORTED_10000baseKR_Full |
122848c2ecf20Sopenharmony_ci					   SUPPORTED_1000baseKX_Full |
122858c2ecf20Sopenharmony_ci					   SUPPORTED_Autoneg |
122868c2ecf20Sopenharmony_ci					   SUPPORTED_FIBRE |
122878c2ecf20Sopenharmony_ci					   SUPPORTED_Pause |
122888c2ecf20Sopenharmony_ci					   SUPPORTED_Asym_Pause);
122898c2ecf20Sopenharmony_ci			phy->flags &= ~FLAGS_TX_ERROR_CHECK;
122908c2ecf20Sopenharmony_ci			break;
122918c2ecf20Sopenharmony_ci		default:
122928c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
122938c2ecf20Sopenharmony_ci				       serdes_net_if);
122948c2ecf20Sopenharmony_ci			break;
122958c2ecf20Sopenharmony_ci		}
122968c2ecf20Sopenharmony_ci
122978c2ecf20Sopenharmony_ci		/* Enable MDC/MDIO work-around for E3 A0 since free running MDC
122988c2ecf20Sopenharmony_ci		 * was not set as expected. For B0, ECO will be enabled so there
122998c2ecf20Sopenharmony_ci		 * won't be an issue there
123008c2ecf20Sopenharmony_ci		 */
123018c2ecf20Sopenharmony_ci		if (CHIP_REV(bp) == CHIP_REV_Ax)
123028c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_MDC_MDIO_WA;
123038c2ecf20Sopenharmony_ci		else
123048c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_MDC_MDIO_WA_B0;
123058c2ecf20Sopenharmony_ci	} else {
123068c2ecf20Sopenharmony_ci		switch (switch_cfg) {
123078c2ecf20Sopenharmony_ci		case SWITCH_CFG_1G:
123088c2ecf20Sopenharmony_ci			phy_addr = REG_RD(bp,
123098c2ecf20Sopenharmony_ci					  NIG_REG_SERDES0_CTRL_PHY_ADDR +
123108c2ecf20Sopenharmony_ci					  port * 0x10);
123118c2ecf20Sopenharmony_ci			*phy = phy_serdes;
123128c2ecf20Sopenharmony_ci			break;
123138c2ecf20Sopenharmony_ci		case SWITCH_CFG_10G:
123148c2ecf20Sopenharmony_ci			phy_addr = REG_RD(bp,
123158c2ecf20Sopenharmony_ci					  NIG_REG_XGXS0_CTRL_PHY_ADDR +
123168c2ecf20Sopenharmony_ci					  port * 0x18);
123178c2ecf20Sopenharmony_ci			*phy = phy_xgxs;
123188c2ecf20Sopenharmony_ci			break;
123198c2ecf20Sopenharmony_ci		default:
123208c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
123218c2ecf20Sopenharmony_ci			return -EINVAL;
123228c2ecf20Sopenharmony_ci		}
123238c2ecf20Sopenharmony_ci	}
123248c2ecf20Sopenharmony_ci	phy->addr = (u8)phy_addr;
123258c2ecf20Sopenharmony_ci	phy->mdio_ctrl = bnx2x_get_emac_base(bp,
123268c2ecf20Sopenharmony_ci					    SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
123278c2ecf20Sopenharmony_ci					    port);
123288c2ecf20Sopenharmony_ci	if (CHIP_IS_E2(bp))
123298c2ecf20Sopenharmony_ci		phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
123308c2ecf20Sopenharmony_ci	else
123318c2ecf20Sopenharmony_ci		phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
123328c2ecf20Sopenharmony_ci
123338c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
123348c2ecf20Sopenharmony_ci		   port, phy->addr, phy->mdio_ctrl);
123358c2ecf20Sopenharmony_ci
123368c2ecf20Sopenharmony_ci	bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
123378c2ecf20Sopenharmony_ci	return 0;
123388c2ecf20Sopenharmony_ci}
123398c2ecf20Sopenharmony_ci
123408c2ecf20Sopenharmony_cistatic int bnx2x_populate_ext_phy(struct bnx2x *bp,
123418c2ecf20Sopenharmony_ci				  u8 phy_index,
123428c2ecf20Sopenharmony_ci				  u32 shmem_base,
123438c2ecf20Sopenharmony_ci				  u32 shmem2_base,
123448c2ecf20Sopenharmony_ci				  u8 port,
123458c2ecf20Sopenharmony_ci				  struct bnx2x_phy *phy)
123468c2ecf20Sopenharmony_ci{
123478c2ecf20Sopenharmony_ci	u32 ext_phy_config, phy_type, config2;
123488c2ecf20Sopenharmony_ci	u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
123498c2ecf20Sopenharmony_ci	ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
123508c2ecf20Sopenharmony_ci						  phy_index, port);
123518c2ecf20Sopenharmony_ci	phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
123528c2ecf20Sopenharmony_ci	/* Select the phy type */
123538c2ecf20Sopenharmony_ci	switch (phy_type) {
123548c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
123558c2ecf20Sopenharmony_ci		mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
123568c2ecf20Sopenharmony_ci		*phy = phy_8073;
123578c2ecf20Sopenharmony_ci		break;
123588c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
123598c2ecf20Sopenharmony_ci		*phy = phy_8705;
123608c2ecf20Sopenharmony_ci		break;
123618c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
123628c2ecf20Sopenharmony_ci		*phy = phy_8706;
123638c2ecf20Sopenharmony_ci		break;
123648c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
123658c2ecf20Sopenharmony_ci		mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
123668c2ecf20Sopenharmony_ci		*phy = phy_8726;
123678c2ecf20Sopenharmony_ci		break;
123688c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
123698c2ecf20Sopenharmony_ci		/* BCM8727_NOC => BCM8727 no over current */
123708c2ecf20Sopenharmony_ci		mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
123718c2ecf20Sopenharmony_ci		*phy = phy_8727;
123728c2ecf20Sopenharmony_ci		phy->flags |= FLAGS_NOC;
123738c2ecf20Sopenharmony_ci		break;
123748c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
123758c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
123768c2ecf20Sopenharmony_ci		mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
123778c2ecf20Sopenharmony_ci		*phy = phy_8727;
123788c2ecf20Sopenharmony_ci		break;
123798c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
123808c2ecf20Sopenharmony_ci		*phy = phy_8481;
123818c2ecf20Sopenharmony_ci		break;
123828c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
123838c2ecf20Sopenharmony_ci		*phy = phy_84823;
123848c2ecf20Sopenharmony_ci		break;
123858c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
123868c2ecf20Sopenharmony_ci		*phy = phy_84833;
123878c2ecf20Sopenharmony_ci		break;
123888c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
123898c2ecf20Sopenharmony_ci		*phy = phy_84834;
123908c2ecf20Sopenharmony_ci		break;
123918c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858:
123928c2ecf20Sopenharmony_ci		*phy = phy_84858;
123938c2ecf20Sopenharmony_ci		break;
123948c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
123958c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
123968c2ecf20Sopenharmony_ci		*phy = phy_54618se;
123978c2ecf20Sopenharmony_ci		if (phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
123988c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_EEE;
123998c2ecf20Sopenharmony_ci		break;
124008c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
124018c2ecf20Sopenharmony_ci		*phy = phy_7101;
124028c2ecf20Sopenharmony_ci		break;
124038c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
124048c2ecf20Sopenharmony_ci		*phy = phy_null;
124058c2ecf20Sopenharmony_ci		return -EINVAL;
124068c2ecf20Sopenharmony_ci	default:
124078c2ecf20Sopenharmony_ci		*phy = phy_null;
124088c2ecf20Sopenharmony_ci		/* In case external PHY wasn't found */
124098c2ecf20Sopenharmony_ci		if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
124108c2ecf20Sopenharmony_ci		    (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
124118c2ecf20Sopenharmony_ci			return -EINVAL;
124128c2ecf20Sopenharmony_ci		return 0;
124138c2ecf20Sopenharmony_ci	}
124148c2ecf20Sopenharmony_ci
124158c2ecf20Sopenharmony_ci	phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
124168c2ecf20Sopenharmony_ci	bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
124178c2ecf20Sopenharmony_ci
124188c2ecf20Sopenharmony_ci	/* The shmem address of the phy version is located on different
124198c2ecf20Sopenharmony_ci	 * structures. In case this structure is too old, do not set
124208c2ecf20Sopenharmony_ci	 * the address
124218c2ecf20Sopenharmony_ci	 */
124228c2ecf20Sopenharmony_ci	config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
124238c2ecf20Sopenharmony_ci					dev_info.shared_hw_config.config2));
124248c2ecf20Sopenharmony_ci	if (phy_index == EXT_PHY1) {
124258c2ecf20Sopenharmony_ci		phy->ver_addr = shmem_base + offsetof(struct shmem_region,
124268c2ecf20Sopenharmony_ci				port_mb[port].ext_phy_fw_version);
124278c2ecf20Sopenharmony_ci
124288c2ecf20Sopenharmony_ci		/* Check specific mdc mdio settings */
124298c2ecf20Sopenharmony_ci		if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
124308c2ecf20Sopenharmony_ci			mdc_mdio_access = config2 &
124318c2ecf20Sopenharmony_ci			SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
124328c2ecf20Sopenharmony_ci	} else {
124338c2ecf20Sopenharmony_ci		u32 size = REG_RD(bp, shmem2_base);
124348c2ecf20Sopenharmony_ci
124358c2ecf20Sopenharmony_ci		if (size >
124368c2ecf20Sopenharmony_ci		    offsetof(struct shmem2_region, ext_phy_fw_version2)) {
124378c2ecf20Sopenharmony_ci			phy->ver_addr = shmem2_base +
124388c2ecf20Sopenharmony_ci			    offsetof(struct shmem2_region,
124398c2ecf20Sopenharmony_ci				     ext_phy_fw_version2[port]);
124408c2ecf20Sopenharmony_ci		}
124418c2ecf20Sopenharmony_ci		/* Check specific mdc mdio settings */
124428c2ecf20Sopenharmony_ci		if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
124438c2ecf20Sopenharmony_ci			mdc_mdio_access = (config2 &
124448c2ecf20Sopenharmony_ci			SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
124458c2ecf20Sopenharmony_ci			(SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
124468c2ecf20Sopenharmony_ci			 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
124478c2ecf20Sopenharmony_ci	}
124488c2ecf20Sopenharmony_ci	phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
124498c2ecf20Sopenharmony_ci
124508c2ecf20Sopenharmony_ci	if (bnx2x_is_8483x_8485x(phy) && (phy->ver_addr)) {
124518c2ecf20Sopenharmony_ci		/* Remove 100Mb link supported for BCM84833/4 when phy fw
124528c2ecf20Sopenharmony_ci		 * version lower than or equal to 1.39
124538c2ecf20Sopenharmony_ci		 */
124548c2ecf20Sopenharmony_ci		u32 raw_ver = REG_RD(bp, phy->ver_addr);
124558c2ecf20Sopenharmony_ci		if (((raw_ver & 0x7F) <= 39) &&
124568c2ecf20Sopenharmony_ci		    (((raw_ver & 0xF80) >> 7) <= 1))
124578c2ecf20Sopenharmony_ci			phy->supported &= ~(SUPPORTED_100baseT_Half |
124588c2ecf20Sopenharmony_ci					    SUPPORTED_100baseT_Full);
124598c2ecf20Sopenharmony_ci	}
124608c2ecf20Sopenharmony_ci
124618c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
124628c2ecf20Sopenharmony_ci		   phy_type, port, phy_index);
124638c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "             addr=0x%x, mdio_ctl=0x%x\n",
124648c2ecf20Sopenharmony_ci		   phy->addr, phy->mdio_ctrl);
124658c2ecf20Sopenharmony_ci	return 0;
124668c2ecf20Sopenharmony_ci}
124678c2ecf20Sopenharmony_ci
124688c2ecf20Sopenharmony_cistatic int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
124698c2ecf20Sopenharmony_ci			      u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
124708c2ecf20Sopenharmony_ci{
124718c2ecf20Sopenharmony_ci	phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
124728c2ecf20Sopenharmony_ci	if (phy_index == INT_PHY)
124738c2ecf20Sopenharmony_ci		return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
124748c2ecf20Sopenharmony_ci
124758c2ecf20Sopenharmony_ci	return bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
124768c2ecf20Sopenharmony_ci					port, phy);
124778c2ecf20Sopenharmony_ci}
124788c2ecf20Sopenharmony_ci
124798c2ecf20Sopenharmony_cistatic void bnx2x_phy_def_cfg(struct link_params *params,
124808c2ecf20Sopenharmony_ci			      struct bnx2x_phy *phy,
124818c2ecf20Sopenharmony_ci			      u8 phy_index)
124828c2ecf20Sopenharmony_ci{
124838c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
124848c2ecf20Sopenharmony_ci	u32 link_config;
124858c2ecf20Sopenharmony_ci	/* Populate the default phy configuration for MF mode */
124868c2ecf20Sopenharmony_ci	if (phy_index == EXT_PHY2) {
124878c2ecf20Sopenharmony_ci		link_config = REG_RD(bp, params->shmem_base +
124888c2ecf20Sopenharmony_ci				     offsetof(struct shmem_region, dev_info.
124898c2ecf20Sopenharmony_ci			port_feature_config[params->port].link_config2));
124908c2ecf20Sopenharmony_ci		phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
124918c2ecf20Sopenharmony_ci					     offsetof(struct shmem_region,
124928c2ecf20Sopenharmony_ci						      dev_info.
124938c2ecf20Sopenharmony_ci			port_hw_config[params->port].speed_capability_mask2));
124948c2ecf20Sopenharmony_ci	} else {
124958c2ecf20Sopenharmony_ci		link_config = REG_RD(bp, params->shmem_base +
124968c2ecf20Sopenharmony_ci				     offsetof(struct shmem_region, dev_info.
124978c2ecf20Sopenharmony_ci				port_feature_config[params->port].link_config));
124988c2ecf20Sopenharmony_ci		phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
124998c2ecf20Sopenharmony_ci					     offsetof(struct shmem_region,
125008c2ecf20Sopenharmony_ci						      dev_info.
125018c2ecf20Sopenharmony_ci			port_hw_config[params->port].speed_capability_mask));
125028c2ecf20Sopenharmony_ci	}
125038c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK,
125048c2ecf20Sopenharmony_ci	   "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
125058c2ecf20Sopenharmony_ci	   phy_index, link_config, phy->speed_cap_mask);
125068c2ecf20Sopenharmony_ci
125078c2ecf20Sopenharmony_ci	phy->req_duplex = DUPLEX_FULL;
125088c2ecf20Sopenharmony_ci	switch (link_config  & PORT_FEATURE_LINK_SPEED_MASK) {
125098c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_10M_HALF:
125108c2ecf20Sopenharmony_ci		phy->req_duplex = DUPLEX_HALF;
125118c2ecf20Sopenharmony_ci		fallthrough;
125128c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_10M_FULL:
125138c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_10;
125148c2ecf20Sopenharmony_ci		break;
125158c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_100M_HALF:
125168c2ecf20Sopenharmony_ci		phy->req_duplex = DUPLEX_HALF;
125178c2ecf20Sopenharmony_ci		fallthrough;
125188c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_100M_FULL:
125198c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_100;
125208c2ecf20Sopenharmony_ci		break;
125218c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_1G:
125228c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_1000;
125238c2ecf20Sopenharmony_ci		break;
125248c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_2_5G:
125258c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_2500;
125268c2ecf20Sopenharmony_ci		break;
125278c2ecf20Sopenharmony_ci	case PORT_FEATURE_LINK_SPEED_10G_CX4:
125288c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_10000;
125298c2ecf20Sopenharmony_ci		break;
125308c2ecf20Sopenharmony_ci	default:
125318c2ecf20Sopenharmony_ci		phy->req_line_speed = SPEED_AUTO_NEG;
125328c2ecf20Sopenharmony_ci		break;
125338c2ecf20Sopenharmony_ci	}
125348c2ecf20Sopenharmony_ci
125358c2ecf20Sopenharmony_ci	switch (link_config  & PORT_FEATURE_FLOW_CONTROL_MASK) {
125368c2ecf20Sopenharmony_ci	case PORT_FEATURE_FLOW_CONTROL_AUTO:
125378c2ecf20Sopenharmony_ci		phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
125388c2ecf20Sopenharmony_ci		break;
125398c2ecf20Sopenharmony_ci	case PORT_FEATURE_FLOW_CONTROL_TX:
125408c2ecf20Sopenharmony_ci		phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
125418c2ecf20Sopenharmony_ci		break;
125428c2ecf20Sopenharmony_ci	case PORT_FEATURE_FLOW_CONTROL_RX:
125438c2ecf20Sopenharmony_ci		phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
125448c2ecf20Sopenharmony_ci		break;
125458c2ecf20Sopenharmony_ci	case PORT_FEATURE_FLOW_CONTROL_BOTH:
125468c2ecf20Sopenharmony_ci		phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
125478c2ecf20Sopenharmony_ci		break;
125488c2ecf20Sopenharmony_ci	default:
125498c2ecf20Sopenharmony_ci		phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
125508c2ecf20Sopenharmony_ci		break;
125518c2ecf20Sopenharmony_ci	}
125528c2ecf20Sopenharmony_ci}
125538c2ecf20Sopenharmony_ci
125548c2ecf20Sopenharmony_ciu32 bnx2x_phy_selection(struct link_params *params)
125558c2ecf20Sopenharmony_ci{
125568c2ecf20Sopenharmony_ci	u32 phy_config_swapped, prio_cfg;
125578c2ecf20Sopenharmony_ci	u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
125588c2ecf20Sopenharmony_ci
125598c2ecf20Sopenharmony_ci	phy_config_swapped = params->multi_phy_config &
125608c2ecf20Sopenharmony_ci		PORT_HW_CFG_PHY_SWAPPED_ENABLED;
125618c2ecf20Sopenharmony_ci
125628c2ecf20Sopenharmony_ci	prio_cfg = params->multi_phy_config &
125638c2ecf20Sopenharmony_ci			PORT_HW_CFG_PHY_SELECTION_MASK;
125648c2ecf20Sopenharmony_ci
125658c2ecf20Sopenharmony_ci	if (phy_config_swapped) {
125668c2ecf20Sopenharmony_ci		switch (prio_cfg) {
125678c2ecf20Sopenharmony_ci		case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
125688c2ecf20Sopenharmony_ci		     return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
125698c2ecf20Sopenharmony_ci		     break;
125708c2ecf20Sopenharmony_ci		case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
125718c2ecf20Sopenharmony_ci		     return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
125728c2ecf20Sopenharmony_ci		     break;
125738c2ecf20Sopenharmony_ci		case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
125748c2ecf20Sopenharmony_ci		     return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
125758c2ecf20Sopenharmony_ci		     break;
125768c2ecf20Sopenharmony_ci		case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
125778c2ecf20Sopenharmony_ci		     return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
125788c2ecf20Sopenharmony_ci		     break;
125798c2ecf20Sopenharmony_ci		}
125808c2ecf20Sopenharmony_ci	} else
125818c2ecf20Sopenharmony_ci		return_cfg = prio_cfg;
125828c2ecf20Sopenharmony_ci
125838c2ecf20Sopenharmony_ci	return return_cfg;
125848c2ecf20Sopenharmony_ci}
125858c2ecf20Sopenharmony_ci
125868c2ecf20Sopenharmony_ciint bnx2x_phy_probe(struct link_params *params)
125878c2ecf20Sopenharmony_ci{
125888c2ecf20Sopenharmony_ci	u8 phy_index, actual_phy_idx;
125898c2ecf20Sopenharmony_ci	u32 phy_config_swapped, sync_offset, media_types;
125908c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
125918c2ecf20Sopenharmony_ci	struct bnx2x_phy *phy;
125928c2ecf20Sopenharmony_ci	params->num_phys = 0;
125938c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Begin phy probe\n");
125948c2ecf20Sopenharmony_ci	phy_config_swapped = params->multi_phy_config &
125958c2ecf20Sopenharmony_ci		PORT_HW_CFG_PHY_SWAPPED_ENABLED;
125968c2ecf20Sopenharmony_ci
125978c2ecf20Sopenharmony_ci	for (phy_index = INT_PHY; phy_index < MAX_PHYS;
125988c2ecf20Sopenharmony_ci	      phy_index++) {
125998c2ecf20Sopenharmony_ci		actual_phy_idx = phy_index;
126008c2ecf20Sopenharmony_ci		if (phy_config_swapped) {
126018c2ecf20Sopenharmony_ci			if (phy_index == EXT_PHY1)
126028c2ecf20Sopenharmony_ci				actual_phy_idx = EXT_PHY2;
126038c2ecf20Sopenharmony_ci			else if (phy_index == EXT_PHY2)
126048c2ecf20Sopenharmony_ci				actual_phy_idx = EXT_PHY1;
126058c2ecf20Sopenharmony_ci		}
126068c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
126078c2ecf20Sopenharmony_ci			       " actual_phy_idx %x\n", phy_config_swapped,
126088c2ecf20Sopenharmony_ci			   phy_index, actual_phy_idx);
126098c2ecf20Sopenharmony_ci		phy = &params->phy[actual_phy_idx];
126108c2ecf20Sopenharmony_ci		if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
126118c2ecf20Sopenharmony_ci				       params->shmem2_base, params->port,
126128c2ecf20Sopenharmony_ci				       phy) != 0) {
126138c2ecf20Sopenharmony_ci			params->num_phys = 0;
126148c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
126158c2ecf20Sopenharmony_ci				   phy_index);
126168c2ecf20Sopenharmony_ci			for (phy_index = INT_PHY;
126178c2ecf20Sopenharmony_ci			      phy_index < MAX_PHYS;
126188c2ecf20Sopenharmony_ci			      phy_index++)
126198c2ecf20Sopenharmony_ci				*phy = phy_null;
126208c2ecf20Sopenharmony_ci			return -EINVAL;
126218c2ecf20Sopenharmony_ci		}
126228c2ecf20Sopenharmony_ci		if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
126238c2ecf20Sopenharmony_ci			break;
126248c2ecf20Sopenharmony_ci
126258c2ecf20Sopenharmony_ci		if (params->feature_config_flags &
126268c2ecf20Sopenharmony_ci		    FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
126278c2ecf20Sopenharmony_ci			phy->flags &= ~FLAGS_TX_ERROR_CHECK;
126288c2ecf20Sopenharmony_ci
126298c2ecf20Sopenharmony_ci		if (!(params->feature_config_flags &
126308c2ecf20Sopenharmony_ci		      FEATURE_CONFIG_MT_SUPPORT))
126318c2ecf20Sopenharmony_ci			phy->flags |= FLAGS_MDC_MDIO_WA_G;
126328c2ecf20Sopenharmony_ci
126338c2ecf20Sopenharmony_ci		sync_offset = params->shmem_base +
126348c2ecf20Sopenharmony_ci			offsetof(struct shmem_region,
126358c2ecf20Sopenharmony_ci			dev_info.port_hw_config[params->port].media_type);
126368c2ecf20Sopenharmony_ci		media_types = REG_RD(bp, sync_offset);
126378c2ecf20Sopenharmony_ci
126388c2ecf20Sopenharmony_ci		/* Update media type for non-PMF sync only for the first time
126398c2ecf20Sopenharmony_ci		 * In case the media type changes afterwards, it will be updated
126408c2ecf20Sopenharmony_ci		 * using the update_status function
126418c2ecf20Sopenharmony_ci		 */
126428c2ecf20Sopenharmony_ci		if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
126438c2ecf20Sopenharmony_ci				    (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
126448c2ecf20Sopenharmony_ci				     actual_phy_idx))) == 0) {
126458c2ecf20Sopenharmony_ci			media_types |= ((phy->media_type &
126468c2ecf20Sopenharmony_ci					PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
126478c2ecf20Sopenharmony_ci				(PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
126488c2ecf20Sopenharmony_ci				 actual_phy_idx));
126498c2ecf20Sopenharmony_ci		}
126508c2ecf20Sopenharmony_ci		REG_WR(bp, sync_offset, media_types);
126518c2ecf20Sopenharmony_ci
126528c2ecf20Sopenharmony_ci		bnx2x_phy_def_cfg(params, phy, phy_index);
126538c2ecf20Sopenharmony_ci		params->num_phys++;
126548c2ecf20Sopenharmony_ci	}
126558c2ecf20Sopenharmony_ci
126568c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
126578c2ecf20Sopenharmony_ci	return 0;
126588c2ecf20Sopenharmony_ci}
126598c2ecf20Sopenharmony_ci
126608c2ecf20Sopenharmony_cistatic void bnx2x_init_bmac_loopback(struct link_params *params,
126618c2ecf20Sopenharmony_ci				     struct link_vars *vars)
126628c2ecf20Sopenharmony_ci{
126638c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
126648c2ecf20Sopenharmony_ci	vars->link_up = 1;
126658c2ecf20Sopenharmony_ci	vars->line_speed = SPEED_10000;
126668c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
126678c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
126688c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_BMAC;
126698c2ecf20Sopenharmony_ci
126708c2ecf20Sopenharmony_ci	vars->phy_flags = PHY_XGXS_FLAG;
126718c2ecf20Sopenharmony_ci
126728c2ecf20Sopenharmony_ci	bnx2x_xgxs_deassert(params);
126738c2ecf20Sopenharmony_ci
126748c2ecf20Sopenharmony_ci	/* Set bmac loopback */
126758c2ecf20Sopenharmony_ci	bnx2x_bmac_enable(params, vars, 1, 1);
126768c2ecf20Sopenharmony_ci
126778c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
126788c2ecf20Sopenharmony_ci}
126798c2ecf20Sopenharmony_ci
126808c2ecf20Sopenharmony_cistatic void bnx2x_init_emac_loopback(struct link_params *params,
126818c2ecf20Sopenharmony_ci				     struct link_vars *vars)
126828c2ecf20Sopenharmony_ci{
126838c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
126848c2ecf20Sopenharmony_ci	vars->link_up = 1;
126858c2ecf20Sopenharmony_ci	vars->line_speed = SPEED_1000;
126868c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
126878c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
126888c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_EMAC;
126898c2ecf20Sopenharmony_ci
126908c2ecf20Sopenharmony_ci	vars->phy_flags = PHY_XGXS_FLAG;
126918c2ecf20Sopenharmony_ci
126928c2ecf20Sopenharmony_ci	bnx2x_xgxs_deassert(params);
126938c2ecf20Sopenharmony_ci	/* Set bmac loopback */
126948c2ecf20Sopenharmony_ci	bnx2x_emac_enable(params, vars, 1);
126958c2ecf20Sopenharmony_ci	bnx2x_emac_program(params, vars);
126968c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
126978c2ecf20Sopenharmony_ci}
126988c2ecf20Sopenharmony_ci
126998c2ecf20Sopenharmony_cistatic void bnx2x_init_xmac_loopback(struct link_params *params,
127008c2ecf20Sopenharmony_ci				     struct link_vars *vars)
127018c2ecf20Sopenharmony_ci{
127028c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
127038c2ecf20Sopenharmony_ci	vars->link_up = 1;
127048c2ecf20Sopenharmony_ci	if (!params->req_line_speed[0])
127058c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
127068c2ecf20Sopenharmony_ci	else
127078c2ecf20Sopenharmony_ci		vars->line_speed = params->req_line_speed[0];
127088c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
127098c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
127108c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_XMAC;
127118c2ecf20Sopenharmony_ci	vars->phy_flags = PHY_XGXS_FLAG;
127128c2ecf20Sopenharmony_ci	/* Set WC to loopback mode since link is required to provide clock
127138c2ecf20Sopenharmony_ci	 * to the XMAC in 20G mode
127148c2ecf20Sopenharmony_ci	 */
127158c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, &params->phy[0]);
127168c2ecf20Sopenharmony_ci	bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
127178c2ecf20Sopenharmony_ci	params->phy[INT_PHY].config_loopback(
127188c2ecf20Sopenharmony_ci			&params->phy[INT_PHY],
127198c2ecf20Sopenharmony_ci			params);
127208c2ecf20Sopenharmony_ci
127218c2ecf20Sopenharmony_ci	bnx2x_xmac_enable(params, vars, 1);
127228c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
127238c2ecf20Sopenharmony_ci}
127248c2ecf20Sopenharmony_ci
127258c2ecf20Sopenharmony_cistatic void bnx2x_init_umac_loopback(struct link_params *params,
127268c2ecf20Sopenharmony_ci				     struct link_vars *vars)
127278c2ecf20Sopenharmony_ci{
127288c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
127298c2ecf20Sopenharmony_ci	vars->link_up = 1;
127308c2ecf20Sopenharmony_ci	vars->line_speed = SPEED_1000;
127318c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
127328c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
127338c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_UMAC;
127348c2ecf20Sopenharmony_ci	vars->phy_flags = PHY_XGXS_FLAG;
127358c2ecf20Sopenharmony_ci	bnx2x_umac_enable(params, vars, 1);
127368c2ecf20Sopenharmony_ci
127378c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
127388c2ecf20Sopenharmony_ci}
127398c2ecf20Sopenharmony_ci
127408c2ecf20Sopenharmony_cistatic void bnx2x_init_xgxs_loopback(struct link_params *params,
127418c2ecf20Sopenharmony_ci				     struct link_vars *vars)
127428c2ecf20Sopenharmony_ci{
127438c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
127448c2ecf20Sopenharmony_ci	struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
127458c2ecf20Sopenharmony_ci	vars->link_up = 1;
127468c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
127478c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
127488c2ecf20Sopenharmony_ci	if (params->req_line_speed[0] == SPEED_1000)
127498c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_1000;
127508c2ecf20Sopenharmony_ci	else if ((params->req_line_speed[0] == SPEED_20000) ||
127518c2ecf20Sopenharmony_ci		 (int_phy->flags & FLAGS_WC_DUAL_MODE))
127528c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_20000;
127538c2ecf20Sopenharmony_ci	else
127548c2ecf20Sopenharmony_ci		vars->line_speed = SPEED_10000;
127558c2ecf20Sopenharmony_ci
127568c2ecf20Sopenharmony_ci	if (!USES_WARPCORE(bp))
127578c2ecf20Sopenharmony_ci		bnx2x_xgxs_deassert(params);
127588c2ecf20Sopenharmony_ci	bnx2x_link_initialize(params, vars);
127598c2ecf20Sopenharmony_ci
127608c2ecf20Sopenharmony_ci	if (params->req_line_speed[0] == SPEED_1000) {
127618c2ecf20Sopenharmony_ci		if (USES_WARPCORE(bp))
127628c2ecf20Sopenharmony_ci			bnx2x_umac_enable(params, vars, 0);
127638c2ecf20Sopenharmony_ci		else {
127648c2ecf20Sopenharmony_ci			bnx2x_emac_program(params, vars);
127658c2ecf20Sopenharmony_ci			bnx2x_emac_enable(params, vars, 0);
127668c2ecf20Sopenharmony_ci		}
127678c2ecf20Sopenharmony_ci	} else {
127688c2ecf20Sopenharmony_ci		if (USES_WARPCORE(bp))
127698c2ecf20Sopenharmony_ci			bnx2x_xmac_enable(params, vars, 0);
127708c2ecf20Sopenharmony_ci		else
127718c2ecf20Sopenharmony_ci			bnx2x_bmac_enable(params, vars, 0, 1);
127728c2ecf20Sopenharmony_ci	}
127738c2ecf20Sopenharmony_ci
127748c2ecf20Sopenharmony_ci	if (params->loopback_mode == LOOPBACK_XGXS) {
127758c2ecf20Sopenharmony_ci		/* Set 10G XGXS loopback */
127768c2ecf20Sopenharmony_ci		int_phy->config_loopback(int_phy, params);
127778c2ecf20Sopenharmony_ci	} else {
127788c2ecf20Sopenharmony_ci		/* Set external phy loopback */
127798c2ecf20Sopenharmony_ci		u8 phy_index;
127808c2ecf20Sopenharmony_ci		for (phy_index = EXT_PHY1;
127818c2ecf20Sopenharmony_ci		      phy_index < params->num_phys; phy_index++)
127828c2ecf20Sopenharmony_ci			if (params->phy[phy_index].config_loopback)
127838c2ecf20Sopenharmony_ci				params->phy[phy_index].config_loopback(
127848c2ecf20Sopenharmony_ci					&params->phy[phy_index],
127858c2ecf20Sopenharmony_ci					params);
127868c2ecf20Sopenharmony_ci	}
127878c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
127888c2ecf20Sopenharmony_ci
127898c2ecf20Sopenharmony_ci	bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
127908c2ecf20Sopenharmony_ci}
127918c2ecf20Sopenharmony_ci
127928c2ecf20Sopenharmony_civoid bnx2x_set_rx_filter(struct link_params *params, u8 en)
127938c2ecf20Sopenharmony_ci{
127948c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
127958c2ecf20Sopenharmony_ci	u8 val = en * 0x1F;
127968c2ecf20Sopenharmony_ci
127978c2ecf20Sopenharmony_ci	/* Open / close the gate between the NIG and the BRB */
127988c2ecf20Sopenharmony_ci	if (!CHIP_IS_E1x(bp))
127998c2ecf20Sopenharmony_ci		val |= en * 0x20;
128008c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + params->port*4, val);
128018c2ecf20Sopenharmony_ci
128028c2ecf20Sopenharmony_ci	if (!CHIP_IS_E1(bp)) {
128038c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + params->port*4,
128048c2ecf20Sopenharmony_ci		       en*0x3);
128058c2ecf20Sopenharmony_ci	}
128068c2ecf20Sopenharmony_ci
128078c2ecf20Sopenharmony_ci	REG_WR(bp, (params->port ? NIG_REG_LLH1_BRB1_NOT_MCP :
128088c2ecf20Sopenharmony_ci		    NIG_REG_LLH0_BRB1_NOT_MCP), en);
128098c2ecf20Sopenharmony_ci}
128108c2ecf20Sopenharmony_cistatic int bnx2x_avoid_link_flap(struct link_params *params,
128118c2ecf20Sopenharmony_ci					    struct link_vars *vars)
128128c2ecf20Sopenharmony_ci{
128138c2ecf20Sopenharmony_ci	u32 phy_idx;
128148c2ecf20Sopenharmony_ci	u32 dont_clear_stat, lfa_sts;
128158c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
128168c2ecf20Sopenharmony_ci
128178c2ecf20Sopenharmony_ci	bnx2x_set_mdio_emac_per_phy(bp, params);
128188c2ecf20Sopenharmony_ci	/* Sync the link parameters */
128198c2ecf20Sopenharmony_ci	bnx2x_link_status_update(params, vars);
128208c2ecf20Sopenharmony_ci
128218c2ecf20Sopenharmony_ci	/*
128228c2ecf20Sopenharmony_ci	 * The module verification was already done by previous link owner,
128238c2ecf20Sopenharmony_ci	 * so this call is meant only to get warning message
128248c2ecf20Sopenharmony_ci	 */
128258c2ecf20Sopenharmony_ci
128268c2ecf20Sopenharmony_ci	for (phy_idx = INT_PHY; phy_idx < params->num_phys; phy_idx++) {
128278c2ecf20Sopenharmony_ci		struct bnx2x_phy *phy = &params->phy[phy_idx];
128288c2ecf20Sopenharmony_ci		if (phy->phy_specific_func) {
128298c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Calling PHY specific func\n");
128308c2ecf20Sopenharmony_ci			phy->phy_specific_func(phy, params, PHY_INIT);
128318c2ecf20Sopenharmony_ci		}
128328c2ecf20Sopenharmony_ci		if ((phy->media_type == ETH_PHY_SFPP_10G_FIBER) ||
128338c2ecf20Sopenharmony_ci		    (phy->media_type == ETH_PHY_SFP_1G_FIBER) ||
128348c2ecf20Sopenharmony_ci		    (phy->media_type == ETH_PHY_DA_TWINAX))
128358c2ecf20Sopenharmony_ci			bnx2x_verify_sfp_module(phy, params);
128368c2ecf20Sopenharmony_ci	}
128378c2ecf20Sopenharmony_ci	lfa_sts = REG_RD(bp, params->lfa_base +
128388c2ecf20Sopenharmony_ci			 offsetof(struct shmem_lfa,
128398c2ecf20Sopenharmony_ci				  lfa_sts));
128408c2ecf20Sopenharmony_ci
128418c2ecf20Sopenharmony_ci	dont_clear_stat = lfa_sts & SHMEM_LFA_DONT_CLEAR_STAT;
128428c2ecf20Sopenharmony_ci
128438c2ecf20Sopenharmony_ci	/* Re-enable the NIG/MAC */
128448c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
128458c2ecf20Sopenharmony_ci		if (!dont_clear_stat) {
128468c2ecf20Sopenharmony_ci			REG_WR(bp, GRCBASE_MISC +
128478c2ecf20Sopenharmony_ci			       MISC_REGISTERS_RESET_REG_2_CLEAR,
128488c2ecf20Sopenharmony_ci			       (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
128498c2ecf20Sopenharmony_ci				params->port));
128508c2ecf20Sopenharmony_ci			REG_WR(bp, GRCBASE_MISC +
128518c2ecf20Sopenharmony_ci			       MISC_REGISTERS_RESET_REG_2_SET,
128528c2ecf20Sopenharmony_ci			       (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
128538c2ecf20Sopenharmony_ci				params->port));
128548c2ecf20Sopenharmony_ci		}
128558c2ecf20Sopenharmony_ci		if (vars->line_speed < SPEED_10000)
128568c2ecf20Sopenharmony_ci			bnx2x_umac_enable(params, vars, 0);
128578c2ecf20Sopenharmony_ci		else
128588c2ecf20Sopenharmony_ci			bnx2x_xmac_enable(params, vars, 0);
128598c2ecf20Sopenharmony_ci	} else {
128608c2ecf20Sopenharmony_ci		if (vars->line_speed < SPEED_10000)
128618c2ecf20Sopenharmony_ci			bnx2x_emac_enable(params, vars, 0);
128628c2ecf20Sopenharmony_ci		else
128638c2ecf20Sopenharmony_ci			bnx2x_bmac_enable(params, vars, 0, !dont_clear_stat);
128648c2ecf20Sopenharmony_ci	}
128658c2ecf20Sopenharmony_ci
128668c2ecf20Sopenharmony_ci	/* Increment LFA count */
128678c2ecf20Sopenharmony_ci	lfa_sts = ((lfa_sts & ~LINK_FLAP_AVOIDANCE_COUNT_MASK) |
128688c2ecf20Sopenharmony_ci		   (((((lfa_sts & LINK_FLAP_AVOIDANCE_COUNT_MASK) >>
128698c2ecf20Sopenharmony_ci		       LINK_FLAP_AVOIDANCE_COUNT_OFFSET) + 1) & 0xff)
128708c2ecf20Sopenharmony_ci		    << LINK_FLAP_AVOIDANCE_COUNT_OFFSET));
128718c2ecf20Sopenharmony_ci	/* Clear link flap reason */
128728c2ecf20Sopenharmony_ci	lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
128738c2ecf20Sopenharmony_ci
128748c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
128758c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
128768c2ecf20Sopenharmony_ci
128778c2ecf20Sopenharmony_ci	/* Disable NIG DRAIN */
128788c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
128798c2ecf20Sopenharmony_ci
128808c2ecf20Sopenharmony_ci	/* Enable interrupts */
128818c2ecf20Sopenharmony_ci	bnx2x_link_int_enable(params);
128828c2ecf20Sopenharmony_ci	return 0;
128838c2ecf20Sopenharmony_ci}
128848c2ecf20Sopenharmony_ci
128858c2ecf20Sopenharmony_cistatic void bnx2x_cannot_avoid_link_flap(struct link_params *params,
128868c2ecf20Sopenharmony_ci					 struct link_vars *vars,
128878c2ecf20Sopenharmony_ci					 int lfa_status)
128888c2ecf20Sopenharmony_ci{
128898c2ecf20Sopenharmony_ci	u32 lfa_sts, cfg_idx, tmp_val;
128908c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
128918c2ecf20Sopenharmony_ci
128928c2ecf20Sopenharmony_ci	bnx2x_link_reset(params, vars, 1);
128938c2ecf20Sopenharmony_ci
128948c2ecf20Sopenharmony_ci	if (!params->lfa_base)
128958c2ecf20Sopenharmony_ci		return;
128968c2ecf20Sopenharmony_ci	/* Store the new link parameters */
128978c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
128988c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, req_duplex),
128998c2ecf20Sopenharmony_ci	       params->req_duplex[0] | (params->req_duplex[1] << 16));
129008c2ecf20Sopenharmony_ci
129018c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
129028c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, req_flow_ctrl),
129038c2ecf20Sopenharmony_ci	       params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16));
129048c2ecf20Sopenharmony_ci
129058c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
129068c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, req_line_speed),
129078c2ecf20Sopenharmony_ci	       params->req_line_speed[0] | (params->req_line_speed[1] << 16));
129088c2ecf20Sopenharmony_ci
129098c2ecf20Sopenharmony_ci	for (cfg_idx = 0; cfg_idx < SHMEM_LINK_CONFIG_SIZE; cfg_idx++) {
129108c2ecf20Sopenharmony_ci		REG_WR(bp, params->lfa_base +
129118c2ecf20Sopenharmony_ci		       offsetof(struct shmem_lfa,
129128c2ecf20Sopenharmony_ci				speed_cap_mask[cfg_idx]),
129138c2ecf20Sopenharmony_ci		       params->speed_cap_mask[cfg_idx]);
129148c2ecf20Sopenharmony_ci	}
129158c2ecf20Sopenharmony_ci
129168c2ecf20Sopenharmony_ci	tmp_val = REG_RD(bp, params->lfa_base +
129178c2ecf20Sopenharmony_ci			 offsetof(struct shmem_lfa, additional_config));
129188c2ecf20Sopenharmony_ci	tmp_val &= ~REQ_FC_AUTO_ADV_MASK;
129198c2ecf20Sopenharmony_ci	tmp_val |= params->req_fc_auto_adv;
129208c2ecf20Sopenharmony_ci
129218c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
129228c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, additional_config), tmp_val);
129238c2ecf20Sopenharmony_ci
129248c2ecf20Sopenharmony_ci	lfa_sts = REG_RD(bp, params->lfa_base +
129258c2ecf20Sopenharmony_ci			 offsetof(struct shmem_lfa, lfa_sts));
129268c2ecf20Sopenharmony_ci
129278c2ecf20Sopenharmony_ci	/* Clear the "Don't Clear Statistics" bit, and set reason */
129288c2ecf20Sopenharmony_ci	lfa_sts &= ~SHMEM_LFA_DONT_CLEAR_STAT;
129298c2ecf20Sopenharmony_ci
129308c2ecf20Sopenharmony_ci	/* Set link flap reason */
129318c2ecf20Sopenharmony_ci	lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
129328c2ecf20Sopenharmony_ci	lfa_sts |= ((lfa_status & LFA_LINK_FLAP_REASON_MASK) <<
129338c2ecf20Sopenharmony_ci		    LFA_LINK_FLAP_REASON_OFFSET);
129348c2ecf20Sopenharmony_ci
129358c2ecf20Sopenharmony_ci	/* Increment link flap counter */
129368c2ecf20Sopenharmony_ci	lfa_sts = ((lfa_sts & ~LINK_FLAP_COUNT_MASK) |
129378c2ecf20Sopenharmony_ci		   (((((lfa_sts & LINK_FLAP_COUNT_MASK) >>
129388c2ecf20Sopenharmony_ci		       LINK_FLAP_COUNT_OFFSET) + 1) & 0xff)
129398c2ecf20Sopenharmony_ci		    << LINK_FLAP_COUNT_OFFSET));
129408c2ecf20Sopenharmony_ci	REG_WR(bp, params->lfa_base +
129418c2ecf20Sopenharmony_ci	       offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
129428c2ecf20Sopenharmony_ci	/* Proceed with regular link initialization */
129438c2ecf20Sopenharmony_ci}
129448c2ecf20Sopenharmony_ci
129458c2ecf20Sopenharmony_ciint bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
129468c2ecf20Sopenharmony_ci{
129478c2ecf20Sopenharmony_ci	int lfa_status;
129488c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
129498c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Phy Initialization started\n");
129508c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
129518c2ecf20Sopenharmony_ci		   params->req_line_speed[0], params->req_flow_ctrl[0]);
129528c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
129538c2ecf20Sopenharmony_ci		   params->req_line_speed[1], params->req_flow_ctrl[1]);
129548c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "req_adv_flow_ctrl 0x%x\n", params->req_fc_auto_adv);
129558c2ecf20Sopenharmony_ci	vars->link_status = 0;
129568c2ecf20Sopenharmony_ci	vars->phy_link_up = 0;
129578c2ecf20Sopenharmony_ci	vars->link_up = 0;
129588c2ecf20Sopenharmony_ci	vars->line_speed = 0;
129598c2ecf20Sopenharmony_ci	vars->duplex = DUPLEX_FULL;
129608c2ecf20Sopenharmony_ci	vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
129618c2ecf20Sopenharmony_ci	vars->mac_type = MAC_TYPE_NONE;
129628c2ecf20Sopenharmony_ci	vars->phy_flags = 0;
129638c2ecf20Sopenharmony_ci	vars->check_kr2_recovery_cnt = 0;
129648c2ecf20Sopenharmony_ci	params->link_flags = PHY_INITIALIZED;
129658c2ecf20Sopenharmony_ci	/* Driver opens NIG-BRB filters */
129668c2ecf20Sopenharmony_ci	bnx2x_set_rx_filter(params, 1);
129678c2ecf20Sopenharmony_ci	bnx2x_chng_link_count(params, true);
129688c2ecf20Sopenharmony_ci	/* Check if link flap can be avoided */
129698c2ecf20Sopenharmony_ci	lfa_status = bnx2x_check_lfa(params);
129708c2ecf20Sopenharmony_ci
129718c2ecf20Sopenharmony_ci	if (lfa_status == 0) {
129728c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Link Flap Avoidance in progress\n");
129738c2ecf20Sopenharmony_ci		return bnx2x_avoid_link_flap(params, vars);
129748c2ecf20Sopenharmony_ci	}
129758c2ecf20Sopenharmony_ci
129768c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Cannot avoid link flap lfa_sta=0x%x\n",
129778c2ecf20Sopenharmony_ci		       lfa_status);
129788c2ecf20Sopenharmony_ci	bnx2x_cannot_avoid_link_flap(params, vars, lfa_status);
129798c2ecf20Sopenharmony_ci
129808c2ecf20Sopenharmony_ci	/* Disable attentions */
129818c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
129828c2ecf20Sopenharmony_ci		       (NIG_MASK_XGXS0_LINK_STATUS |
129838c2ecf20Sopenharmony_ci			NIG_MASK_XGXS0_LINK10G |
129848c2ecf20Sopenharmony_ci			NIG_MASK_SERDES0_LINK_STATUS |
129858c2ecf20Sopenharmony_ci			NIG_MASK_MI_INT));
129868c2ecf20Sopenharmony_ci
129878c2ecf20Sopenharmony_ci	bnx2x_emac_init(params, vars);
129888c2ecf20Sopenharmony_ci
129898c2ecf20Sopenharmony_ci	if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
129908c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_PFC_ENABLED;
129918c2ecf20Sopenharmony_ci
129928c2ecf20Sopenharmony_ci	if (params->num_phys == 0) {
129938c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
129948c2ecf20Sopenharmony_ci		return -EINVAL;
129958c2ecf20Sopenharmony_ci	}
129968c2ecf20Sopenharmony_ci	set_phy_vars(params, vars);
129978c2ecf20Sopenharmony_ci
129988c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
129998c2ecf20Sopenharmony_ci	switch (params->loopback_mode) {
130008c2ecf20Sopenharmony_ci	case LOOPBACK_BMAC:
130018c2ecf20Sopenharmony_ci		bnx2x_init_bmac_loopback(params, vars);
130028c2ecf20Sopenharmony_ci		break;
130038c2ecf20Sopenharmony_ci	case LOOPBACK_EMAC:
130048c2ecf20Sopenharmony_ci		bnx2x_init_emac_loopback(params, vars);
130058c2ecf20Sopenharmony_ci		break;
130068c2ecf20Sopenharmony_ci	case LOOPBACK_XMAC:
130078c2ecf20Sopenharmony_ci		bnx2x_init_xmac_loopback(params, vars);
130088c2ecf20Sopenharmony_ci		break;
130098c2ecf20Sopenharmony_ci	case LOOPBACK_UMAC:
130108c2ecf20Sopenharmony_ci		bnx2x_init_umac_loopback(params, vars);
130118c2ecf20Sopenharmony_ci		break;
130128c2ecf20Sopenharmony_ci	case LOOPBACK_XGXS:
130138c2ecf20Sopenharmony_ci	case LOOPBACK_EXT_PHY:
130148c2ecf20Sopenharmony_ci		bnx2x_init_xgxs_loopback(params, vars);
130158c2ecf20Sopenharmony_ci		break;
130168c2ecf20Sopenharmony_ci	default:
130178c2ecf20Sopenharmony_ci		if (!CHIP_IS_E3(bp)) {
130188c2ecf20Sopenharmony_ci			if (params->switch_cfg == SWITCH_CFG_10G)
130198c2ecf20Sopenharmony_ci				bnx2x_xgxs_deassert(params);
130208c2ecf20Sopenharmony_ci			else
130218c2ecf20Sopenharmony_ci				bnx2x_serdes_deassert(bp, params->port);
130228c2ecf20Sopenharmony_ci		}
130238c2ecf20Sopenharmony_ci		bnx2x_link_initialize(params, vars);
130248c2ecf20Sopenharmony_ci		msleep(30);
130258c2ecf20Sopenharmony_ci		bnx2x_link_int_enable(params);
130268c2ecf20Sopenharmony_ci		break;
130278c2ecf20Sopenharmony_ci	}
130288c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
130298c2ecf20Sopenharmony_ci
130308c2ecf20Sopenharmony_ci	bnx2x_update_mng_eee(params, vars->eee_status);
130318c2ecf20Sopenharmony_ci	return 0;
130328c2ecf20Sopenharmony_ci}
130338c2ecf20Sopenharmony_ci
130348c2ecf20Sopenharmony_ciint bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
130358c2ecf20Sopenharmony_ci		     u8 reset_ext_phy)
130368c2ecf20Sopenharmony_ci{
130378c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
130388c2ecf20Sopenharmony_ci	u8 phy_index, port = params->port, clear_latch_ind = 0;
130398c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
130408c2ecf20Sopenharmony_ci	/* Disable attentions */
130418c2ecf20Sopenharmony_ci	vars->link_status = 0;
130428c2ecf20Sopenharmony_ci	bnx2x_chng_link_count(params, true);
130438c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
130448c2ecf20Sopenharmony_ci	vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
130458c2ecf20Sopenharmony_ci			      SHMEM_EEE_ACTIVE_BIT);
130468c2ecf20Sopenharmony_ci	bnx2x_update_mng_eee(params, vars->eee_status);
130478c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
130488c2ecf20Sopenharmony_ci		       (NIG_MASK_XGXS0_LINK_STATUS |
130498c2ecf20Sopenharmony_ci			NIG_MASK_XGXS0_LINK10G |
130508c2ecf20Sopenharmony_ci			NIG_MASK_SERDES0_LINK_STATUS |
130518c2ecf20Sopenharmony_ci			NIG_MASK_MI_INT));
130528c2ecf20Sopenharmony_ci
130538c2ecf20Sopenharmony_ci	/* Activate nig drain */
130548c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
130558c2ecf20Sopenharmony_ci
130568c2ecf20Sopenharmony_ci	/* Disable nig egress interface */
130578c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp)) {
130588c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
130598c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
130608c2ecf20Sopenharmony_ci	}
130618c2ecf20Sopenharmony_ci
130628c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp)) {
130638c2ecf20Sopenharmony_ci		bnx2x_set_bmac_rx(bp, params->chip_id, port, 0);
130648c2ecf20Sopenharmony_ci	} else {
130658c2ecf20Sopenharmony_ci		bnx2x_set_xmac_rxtx(params, 0);
130668c2ecf20Sopenharmony_ci		bnx2x_set_umac_rxtx(params, 0);
130678c2ecf20Sopenharmony_ci	}
130688c2ecf20Sopenharmony_ci	/* Disable emac */
130698c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp))
130708c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
130718c2ecf20Sopenharmony_ci
130728c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
130738c2ecf20Sopenharmony_ci	/* The PHY reset is controlled by GPIO 1
130748c2ecf20Sopenharmony_ci	 * Hold it as vars low
130758c2ecf20Sopenharmony_ci	 */
130768c2ecf20Sopenharmony_ci	 /* Clear link led */
130778c2ecf20Sopenharmony_ci	bnx2x_set_mdio_emac_per_phy(bp, params);
130788c2ecf20Sopenharmony_ci	bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
130798c2ecf20Sopenharmony_ci
130808c2ecf20Sopenharmony_ci	if (reset_ext_phy) {
130818c2ecf20Sopenharmony_ci		for (phy_index = EXT_PHY1; phy_index < params->num_phys;
130828c2ecf20Sopenharmony_ci		      phy_index++) {
130838c2ecf20Sopenharmony_ci			if (params->phy[phy_index].link_reset) {
130848c2ecf20Sopenharmony_ci				bnx2x_set_aer_mmd(params,
130858c2ecf20Sopenharmony_ci						  &params->phy[phy_index]);
130868c2ecf20Sopenharmony_ci				params->phy[phy_index].link_reset(
130878c2ecf20Sopenharmony_ci					&params->phy[phy_index],
130888c2ecf20Sopenharmony_ci					params);
130898c2ecf20Sopenharmony_ci			}
130908c2ecf20Sopenharmony_ci			if (params->phy[phy_index].flags &
130918c2ecf20Sopenharmony_ci			    FLAGS_REARM_LATCH_SIGNAL)
130928c2ecf20Sopenharmony_ci				clear_latch_ind = 1;
130938c2ecf20Sopenharmony_ci		}
130948c2ecf20Sopenharmony_ci	}
130958c2ecf20Sopenharmony_ci
130968c2ecf20Sopenharmony_ci	if (clear_latch_ind) {
130978c2ecf20Sopenharmony_ci		/* Clear latching indication */
130988c2ecf20Sopenharmony_ci		bnx2x_rearm_latch_signal(bp, port, 0);
130998c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
131008c2ecf20Sopenharmony_ci			       1 << NIG_LATCH_BC_ENABLE_MI_INT);
131018c2ecf20Sopenharmony_ci	}
131028c2ecf20Sopenharmony_ci	if (params->phy[INT_PHY].link_reset)
131038c2ecf20Sopenharmony_ci		params->phy[INT_PHY].link_reset(
131048c2ecf20Sopenharmony_ci			&params->phy[INT_PHY], params);
131058c2ecf20Sopenharmony_ci
131068c2ecf20Sopenharmony_ci	/* Disable nig ingress interface */
131078c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp)) {
131088c2ecf20Sopenharmony_ci		/* Reset BigMac */
131098c2ecf20Sopenharmony_ci		REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
131108c2ecf20Sopenharmony_ci		       (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
131118c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
131128c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
131138c2ecf20Sopenharmony_ci	} else {
131148c2ecf20Sopenharmony_ci		u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
131158c2ecf20Sopenharmony_ci		bnx2x_set_xumac_nig(params, 0, 0);
131168c2ecf20Sopenharmony_ci		if (REG_RD(bp, MISC_REG_RESET_REG_2) &
131178c2ecf20Sopenharmony_ci		    MISC_REGISTERS_RESET_REG_2_XMAC)
131188c2ecf20Sopenharmony_ci			REG_WR(bp, xmac_base + XMAC_REG_CTRL,
131198c2ecf20Sopenharmony_ci			       XMAC_CTRL_REG_SOFT_RESET);
131208c2ecf20Sopenharmony_ci	}
131218c2ecf20Sopenharmony_ci	vars->link_up = 0;
131228c2ecf20Sopenharmony_ci	vars->phy_flags = 0;
131238c2ecf20Sopenharmony_ci	return 0;
131248c2ecf20Sopenharmony_ci}
131258c2ecf20Sopenharmony_ciint bnx2x_lfa_reset(struct link_params *params,
131268c2ecf20Sopenharmony_ci			       struct link_vars *vars)
131278c2ecf20Sopenharmony_ci{
131288c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
131298c2ecf20Sopenharmony_ci	vars->link_up = 0;
131308c2ecf20Sopenharmony_ci	vars->phy_flags = 0;
131318c2ecf20Sopenharmony_ci	params->link_flags &= ~PHY_INITIALIZED;
131328c2ecf20Sopenharmony_ci	if (!params->lfa_base)
131338c2ecf20Sopenharmony_ci		return bnx2x_link_reset(params, vars, 1);
131348c2ecf20Sopenharmony_ci	/*
131358c2ecf20Sopenharmony_ci	 * Activate NIG drain so that during this time the device won't send
131368c2ecf20Sopenharmony_ci	 * anything while it is unable to response.
131378c2ecf20Sopenharmony_ci	 */
131388c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
131398c2ecf20Sopenharmony_ci
131408c2ecf20Sopenharmony_ci	/*
131418c2ecf20Sopenharmony_ci	 * Close gracefully the gate from BMAC to NIG such that no half packets
131428c2ecf20Sopenharmony_ci	 * are passed.
131438c2ecf20Sopenharmony_ci	 */
131448c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp))
131458c2ecf20Sopenharmony_ci		bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
131468c2ecf20Sopenharmony_ci
131478c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
131488c2ecf20Sopenharmony_ci		bnx2x_set_xmac_rxtx(params, 0);
131498c2ecf20Sopenharmony_ci		bnx2x_set_umac_rxtx(params, 0);
131508c2ecf20Sopenharmony_ci	}
131518c2ecf20Sopenharmony_ci	/* Wait 10ms for the pipe to clean up*/
131528c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
131538c2ecf20Sopenharmony_ci
131548c2ecf20Sopenharmony_ci	/* Clean the NIG-BRB using the network filters in a way that will
131558c2ecf20Sopenharmony_ci	 * not cut a packet in the middle.
131568c2ecf20Sopenharmony_ci	 */
131578c2ecf20Sopenharmony_ci	bnx2x_set_rx_filter(params, 0);
131588c2ecf20Sopenharmony_ci
131598c2ecf20Sopenharmony_ci	/*
131608c2ecf20Sopenharmony_ci	 * Re-open the gate between the BMAC and the NIG, after verifying the
131618c2ecf20Sopenharmony_ci	 * gate to the BRB is closed, otherwise packets may arrive to the
131628c2ecf20Sopenharmony_ci	 * firmware before driver had initialized it. The target is to achieve
131638c2ecf20Sopenharmony_ci	 * minimum management protocol down time.
131648c2ecf20Sopenharmony_ci	 */
131658c2ecf20Sopenharmony_ci	if (!CHIP_IS_E3(bp))
131668c2ecf20Sopenharmony_ci		bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 1);
131678c2ecf20Sopenharmony_ci
131688c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
131698c2ecf20Sopenharmony_ci		bnx2x_set_xmac_rxtx(params, 1);
131708c2ecf20Sopenharmony_ci		bnx2x_set_umac_rxtx(params, 1);
131718c2ecf20Sopenharmony_ci	}
131728c2ecf20Sopenharmony_ci	/* Disable NIG drain */
131738c2ecf20Sopenharmony_ci	REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
131748c2ecf20Sopenharmony_ci	return 0;
131758c2ecf20Sopenharmony_ci}
131768c2ecf20Sopenharmony_ci
131778c2ecf20Sopenharmony_ci/****************************************************************************/
131788c2ecf20Sopenharmony_ci/*				Common function				    */
131798c2ecf20Sopenharmony_ci/****************************************************************************/
131808c2ecf20Sopenharmony_cistatic int bnx2x_8073_common_init_phy(struct bnx2x *bp,
131818c2ecf20Sopenharmony_ci				      u32 shmem_base_path[],
131828c2ecf20Sopenharmony_ci				      u32 shmem2_base_path[], u8 phy_index,
131838c2ecf20Sopenharmony_ci				      u32 chip_id)
131848c2ecf20Sopenharmony_ci{
131858c2ecf20Sopenharmony_ci	struct bnx2x_phy phy[PORT_MAX];
131868c2ecf20Sopenharmony_ci	struct bnx2x_phy *phy_blk[PORT_MAX];
131878c2ecf20Sopenharmony_ci	u16 val;
131888c2ecf20Sopenharmony_ci	s8 port = 0;
131898c2ecf20Sopenharmony_ci	s8 port_of_path = 0;
131908c2ecf20Sopenharmony_ci	u32 swap_val, swap_override;
131918c2ecf20Sopenharmony_ci	swap_val = REG_RD(bp,  NIG_REG_PORT_SWAP);
131928c2ecf20Sopenharmony_ci	swap_override = REG_RD(bp,  NIG_REG_STRAP_OVERRIDE);
131938c2ecf20Sopenharmony_ci	port ^= (swap_val && swap_override);
131948c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, port);
131958c2ecf20Sopenharmony_ci	/* PART1 - Reset both phys */
131968c2ecf20Sopenharmony_ci	for (port = PORT_MAX - 1; port >= PORT_0; port--) {
131978c2ecf20Sopenharmony_ci		u32 shmem_base, shmem2_base;
131988c2ecf20Sopenharmony_ci		/* In E2, same phy is using for port0 of the two paths */
131998c2ecf20Sopenharmony_ci		if (CHIP_IS_E1x(bp)) {
132008c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[0];
132018c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[0];
132028c2ecf20Sopenharmony_ci			port_of_path = port;
132038c2ecf20Sopenharmony_ci		} else {
132048c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[port];
132058c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[port];
132068c2ecf20Sopenharmony_ci			port_of_path = 0;
132078c2ecf20Sopenharmony_ci		}
132088c2ecf20Sopenharmony_ci
132098c2ecf20Sopenharmony_ci		/* Extract the ext phy address for the port */
132108c2ecf20Sopenharmony_ci		if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
132118c2ecf20Sopenharmony_ci				       port_of_path, &phy[port]) !=
132128c2ecf20Sopenharmony_ci		    0) {
132138c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "populate_phy failed\n");
132148c2ecf20Sopenharmony_ci			return -EINVAL;
132158c2ecf20Sopenharmony_ci		}
132168c2ecf20Sopenharmony_ci		/* Disable attentions */
132178c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
132188c2ecf20Sopenharmony_ci			       port_of_path*4,
132198c2ecf20Sopenharmony_ci			       (NIG_MASK_XGXS0_LINK_STATUS |
132208c2ecf20Sopenharmony_ci				NIG_MASK_XGXS0_LINK10G |
132218c2ecf20Sopenharmony_ci				NIG_MASK_SERDES0_LINK_STATUS |
132228c2ecf20Sopenharmony_ci				NIG_MASK_MI_INT));
132238c2ecf20Sopenharmony_ci
132248c2ecf20Sopenharmony_ci		/* Need to take the phy out of low power mode in order
132258c2ecf20Sopenharmony_ci		 * to write to access its registers
132268c2ecf20Sopenharmony_ci		 */
132278c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
132288c2ecf20Sopenharmony_ci			       MISC_REGISTERS_GPIO_OUTPUT_HIGH,
132298c2ecf20Sopenharmony_ci			       port);
132308c2ecf20Sopenharmony_ci
132318c2ecf20Sopenharmony_ci		/* Reset the phy */
132328c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, &phy[port],
132338c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
132348c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_CTRL,
132358c2ecf20Sopenharmony_ci				 1<<15);
132368c2ecf20Sopenharmony_ci	}
132378c2ecf20Sopenharmony_ci
132388c2ecf20Sopenharmony_ci	/* Add delay of 150ms after reset */
132398c2ecf20Sopenharmony_ci	msleep(150);
132408c2ecf20Sopenharmony_ci
132418c2ecf20Sopenharmony_ci	if (phy[PORT_0].addr & 0x1) {
132428c2ecf20Sopenharmony_ci		phy_blk[PORT_0] = &(phy[PORT_1]);
132438c2ecf20Sopenharmony_ci		phy_blk[PORT_1] = &(phy[PORT_0]);
132448c2ecf20Sopenharmony_ci	} else {
132458c2ecf20Sopenharmony_ci		phy_blk[PORT_0] = &(phy[PORT_0]);
132468c2ecf20Sopenharmony_ci		phy_blk[PORT_1] = &(phy[PORT_1]);
132478c2ecf20Sopenharmony_ci	}
132488c2ecf20Sopenharmony_ci
132498c2ecf20Sopenharmony_ci	/* PART2 - Download firmware to both phys */
132508c2ecf20Sopenharmony_ci	for (port = PORT_MAX - 1; port >= PORT_0; port--) {
132518c2ecf20Sopenharmony_ci		if (CHIP_IS_E1x(bp))
132528c2ecf20Sopenharmony_ci			port_of_path = port;
132538c2ecf20Sopenharmony_ci		else
132548c2ecf20Sopenharmony_ci			port_of_path = 0;
132558c2ecf20Sopenharmony_ci
132568c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
132578c2ecf20Sopenharmony_ci			   phy_blk[port]->addr);
132588c2ecf20Sopenharmony_ci		if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
132598c2ecf20Sopenharmony_ci						      port_of_path))
132608c2ecf20Sopenharmony_ci			return -EINVAL;
132618c2ecf20Sopenharmony_ci
132628c2ecf20Sopenharmony_ci		/* Only set bit 10 = 1 (Tx power down) */
132638c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy_blk[port],
132648c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
132658c2ecf20Sopenharmony_ci				MDIO_PMA_REG_TX_POWER_DOWN, &val);
132668c2ecf20Sopenharmony_ci
132678c2ecf20Sopenharmony_ci		/* Phase1 of TX_POWER_DOWN reset */
132688c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy_blk[port],
132698c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
132708c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_TX_POWER_DOWN,
132718c2ecf20Sopenharmony_ci				 (val | 1<<10));
132728c2ecf20Sopenharmony_ci	}
132738c2ecf20Sopenharmony_ci
132748c2ecf20Sopenharmony_ci	/* Toggle Transmitter: Power down and then up with 600ms delay
132758c2ecf20Sopenharmony_ci	 * between
132768c2ecf20Sopenharmony_ci	 */
132778c2ecf20Sopenharmony_ci	msleep(600);
132788c2ecf20Sopenharmony_ci
132798c2ecf20Sopenharmony_ci	/* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
132808c2ecf20Sopenharmony_ci	for (port = PORT_MAX - 1; port >= PORT_0; port--) {
132818c2ecf20Sopenharmony_ci		/* Phase2 of POWER_DOWN_RESET */
132828c2ecf20Sopenharmony_ci		/* Release bit 10 (Release Tx power down) */
132838c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy_blk[port],
132848c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
132858c2ecf20Sopenharmony_ci				MDIO_PMA_REG_TX_POWER_DOWN, &val);
132868c2ecf20Sopenharmony_ci
132878c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy_blk[port],
132888c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
132898c2ecf20Sopenharmony_ci				MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
132908c2ecf20Sopenharmony_ci		usleep_range(15000, 30000);
132918c2ecf20Sopenharmony_ci
132928c2ecf20Sopenharmony_ci		/* Read modify write the SPI-ROM version select register */
132938c2ecf20Sopenharmony_ci		bnx2x_cl45_read(bp, phy_blk[port],
132948c2ecf20Sopenharmony_ci				MDIO_PMA_DEVAD,
132958c2ecf20Sopenharmony_ci				MDIO_PMA_REG_EDC_FFE_MAIN, &val);
132968c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy_blk[port],
132978c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
132988c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
132998c2ecf20Sopenharmony_ci
133008c2ecf20Sopenharmony_ci		/* set GPIO2 back to LOW */
133018c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
133028c2ecf20Sopenharmony_ci			       MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
133038c2ecf20Sopenharmony_ci	}
133048c2ecf20Sopenharmony_ci	return 0;
133058c2ecf20Sopenharmony_ci}
133068c2ecf20Sopenharmony_cistatic int bnx2x_8726_common_init_phy(struct bnx2x *bp,
133078c2ecf20Sopenharmony_ci				      u32 shmem_base_path[],
133088c2ecf20Sopenharmony_ci				      u32 shmem2_base_path[], u8 phy_index,
133098c2ecf20Sopenharmony_ci				      u32 chip_id)
133108c2ecf20Sopenharmony_ci{
133118c2ecf20Sopenharmony_ci	u32 val;
133128c2ecf20Sopenharmony_ci	s8 port;
133138c2ecf20Sopenharmony_ci	struct bnx2x_phy phy;
133148c2ecf20Sopenharmony_ci	/* Use port1 because of the static port-swap */
133158c2ecf20Sopenharmony_ci	/* Enable the module detection interrupt */
133168c2ecf20Sopenharmony_ci	val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
133178c2ecf20Sopenharmony_ci	val |= ((1<<MISC_REGISTERS_GPIO_3)|
133188c2ecf20Sopenharmony_ci		(1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
133198c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
133208c2ecf20Sopenharmony_ci
133218c2ecf20Sopenharmony_ci	bnx2x_ext_phy_hw_reset(bp, 0);
133228c2ecf20Sopenharmony_ci	usleep_range(5000, 10000);
133238c2ecf20Sopenharmony_ci	for (port = 0; port < PORT_MAX; port++) {
133248c2ecf20Sopenharmony_ci		u32 shmem_base, shmem2_base;
133258c2ecf20Sopenharmony_ci
133268c2ecf20Sopenharmony_ci		/* In E2, same phy is using for port0 of the two paths */
133278c2ecf20Sopenharmony_ci		if (CHIP_IS_E1x(bp)) {
133288c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[0];
133298c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[0];
133308c2ecf20Sopenharmony_ci		} else {
133318c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[port];
133328c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[port];
133338c2ecf20Sopenharmony_ci		}
133348c2ecf20Sopenharmony_ci		/* Extract the ext phy address for the port */
133358c2ecf20Sopenharmony_ci		if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
133368c2ecf20Sopenharmony_ci				       port, &phy) !=
133378c2ecf20Sopenharmony_ci		    0) {
133388c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "populate phy failed\n");
133398c2ecf20Sopenharmony_ci			return -EINVAL;
133408c2ecf20Sopenharmony_ci		}
133418c2ecf20Sopenharmony_ci
133428c2ecf20Sopenharmony_ci		/* Reset phy*/
133438c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, &phy,
133448c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
133458c2ecf20Sopenharmony_ci
133468c2ecf20Sopenharmony_ci
133478c2ecf20Sopenharmony_ci		/* Set fault module detected LED on */
133488c2ecf20Sopenharmony_ci		bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
133498c2ecf20Sopenharmony_ci			       MISC_REGISTERS_GPIO_HIGH,
133508c2ecf20Sopenharmony_ci			       port);
133518c2ecf20Sopenharmony_ci	}
133528c2ecf20Sopenharmony_ci
133538c2ecf20Sopenharmony_ci	return 0;
133548c2ecf20Sopenharmony_ci}
133558c2ecf20Sopenharmony_cistatic void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
133568c2ecf20Sopenharmony_ci					 u8 *io_gpio, u8 *io_port)
133578c2ecf20Sopenharmony_ci{
133588c2ecf20Sopenharmony_ci
133598c2ecf20Sopenharmony_ci	u32 phy_gpio_reset = REG_RD(bp, shmem_base +
133608c2ecf20Sopenharmony_ci					  offsetof(struct shmem_region,
133618c2ecf20Sopenharmony_ci				dev_info.port_hw_config[PORT_0].default_cfg));
133628c2ecf20Sopenharmony_ci	switch (phy_gpio_reset) {
133638c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
133648c2ecf20Sopenharmony_ci		*io_gpio = 0;
133658c2ecf20Sopenharmony_ci		*io_port = 0;
133668c2ecf20Sopenharmony_ci		break;
133678c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
133688c2ecf20Sopenharmony_ci		*io_gpio = 1;
133698c2ecf20Sopenharmony_ci		*io_port = 0;
133708c2ecf20Sopenharmony_ci		break;
133718c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
133728c2ecf20Sopenharmony_ci		*io_gpio = 2;
133738c2ecf20Sopenharmony_ci		*io_port = 0;
133748c2ecf20Sopenharmony_ci		break;
133758c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
133768c2ecf20Sopenharmony_ci		*io_gpio = 3;
133778c2ecf20Sopenharmony_ci		*io_port = 0;
133788c2ecf20Sopenharmony_ci		break;
133798c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
133808c2ecf20Sopenharmony_ci		*io_gpio = 0;
133818c2ecf20Sopenharmony_ci		*io_port = 1;
133828c2ecf20Sopenharmony_ci		break;
133838c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
133848c2ecf20Sopenharmony_ci		*io_gpio = 1;
133858c2ecf20Sopenharmony_ci		*io_port = 1;
133868c2ecf20Sopenharmony_ci		break;
133878c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
133888c2ecf20Sopenharmony_ci		*io_gpio = 2;
133898c2ecf20Sopenharmony_ci		*io_port = 1;
133908c2ecf20Sopenharmony_ci		break;
133918c2ecf20Sopenharmony_ci	case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
133928c2ecf20Sopenharmony_ci		*io_gpio = 3;
133938c2ecf20Sopenharmony_ci		*io_port = 1;
133948c2ecf20Sopenharmony_ci		break;
133958c2ecf20Sopenharmony_ci	default:
133968c2ecf20Sopenharmony_ci		/* Don't override the io_gpio and io_port */
133978c2ecf20Sopenharmony_ci		break;
133988c2ecf20Sopenharmony_ci	}
133998c2ecf20Sopenharmony_ci}
134008c2ecf20Sopenharmony_ci
134018c2ecf20Sopenharmony_cistatic int bnx2x_8727_common_init_phy(struct bnx2x *bp,
134028c2ecf20Sopenharmony_ci				      u32 shmem_base_path[],
134038c2ecf20Sopenharmony_ci				      u32 shmem2_base_path[], u8 phy_index,
134048c2ecf20Sopenharmony_ci				      u32 chip_id)
134058c2ecf20Sopenharmony_ci{
134068c2ecf20Sopenharmony_ci	s8 port, reset_gpio;
134078c2ecf20Sopenharmony_ci	u32 swap_val, swap_override;
134088c2ecf20Sopenharmony_ci	struct bnx2x_phy phy[PORT_MAX];
134098c2ecf20Sopenharmony_ci	struct bnx2x_phy *phy_blk[PORT_MAX];
134108c2ecf20Sopenharmony_ci	s8 port_of_path;
134118c2ecf20Sopenharmony_ci	swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
134128c2ecf20Sopenharmony_ci	swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
134138c2ecf20Sopenharmony_ci
134148c2ecf20Sopenharmony_ci	reset_gpio = MISC_REGISTERS_GPIO_1;
134158c2ecf20Sopenharmony_ci	port = 1;
134168c2ecf20Sopenharmony_ci
134178c2ecf20Sopenharmony_ci	/* Retrieve the reset gpio/port which control the reset.
134188c2ecf20Sopenharmony_ci	 * Default is GPIO1, PORT1
134198c2ecf20Sopenharmony_ci	 */
134208c2ecf20Sopenharmony_ci	bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
134218c2ecf20Sopenharmony_ci				     (u8 *)&reset_gpio, (u8 *)&port);
134228c2ecf20Sopenharmony_ci
134238c2ecf20Sopenharmony_ci	/* Calculate the port based on port swap */
134248c2ecf20Sopenharmony_ci	port ^= (swap_val && swap_override);
134258c2ecf20Sopenharmony_ci
134268c2ecf20Sopenharmony_ci	/* Initiate PHY reset*/
134278c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
134288c2ecf20Sopenharmony_ci		       port);
134298c2ecf20Sopenharmony_ci	usleep_range(1000, 2000);
134308c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
134318c2ecf20Sopenharmony_ci		       port);
134328c2ecf20Sopenharmony_ci
134338c2ecf20Sopenharmony_ci	usleep_range(5000, 10000);
134348c2ecf20Sopenharmony_ci
134358c2ecf20Sopenharmony_ci	/* PART1 - Reset both phys */
134368c2ecf20Sopenharmony_ci	for (port = PORT_MAX - 1; port >= PORT_0; port--) {
134378c2ecf20Sopenharmony_ci		u32 shmem_base, shmem2_base;
134388c2ecf20Sopenharmony_ci
134398c2ecf20Sopenharmony_ci		/* In E2, same phy is using for port0 of the two paths */
134408c2ecf20Sopenharmony_ci		if (CHIP_IS_E1x(bp)) {
134418c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[0];
134428c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[0];
134438c2ecf20Sopenharmony_ci			port_of_path = port;
134448c2ecf20Sopenharmony_ci		} else {
134458c2ecf20Sopenharmony_ci			shmem_base = shmem_base_path[port];
134468c2ecf20Sopenharmony_ci			shmem2_base = shmem2_base_path[port];
134478c2ecf20Sopenharmony_ci			port_of_path = 0;
134488c2ecf20Sopenharmony_ci		}
134498c2ecf20Sopenharmony_ci
134508c2ecf20Sopenharmony_ci		/* Extract the ext phy address for the port */
134518c2ecf20Sopenharmony_ci		if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
134528c2ecf20Sopenharmony_ci				       port_of_path, &phy[port]) !=
134538c2ecf20Sopenharmony_ci				       0) {
134548c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "populate phy failed\n");
134558c2ecf20Sopenharmony_ci			return -EINVAL;
134568c2ecf20Sopenharmony_ci		}
134578c2ecf20Sopenharmony_ci		/* disable attentions */
134588c2ecf20Sopenharmony_ci		bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
134598c2ecf20Sopenharmony_ci			       port_of_path*4,
134608c2ecf20Sopenharmony_ci			       (NIG_MASK_XGXS0_LINK_STATUS |
134618c2ecf20Sopenharmony_ci				NIG_MASK_XGXS0_LINK10G |
134628c2ecf20Sopenharmony_ci				NIG_MASK_SERDES0_LINK_STATUS |
134638c2ecf20Sopenharmony_ci				NIG_MASK_MI_INT));
134648c2ecf20Sopenharmony_ci
134658c2ecf20Sopenharmony_ci
134668c2ecf20Sopenharmony_ci		/* Reset the phy */
134678c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, &phy[port],
134688c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
134698c2ecf20Sopenharmony_ci	}
134708c2ecf20Sopenharmony_ci
134718c2ecf20Sopenharmony_ci	/* Add delay of 150ms after reset */
134728c2ecf20Sopenharmony_ci	msleep(150);
134738c2ecf20Sopenharmony_ci	if (phy[PORT_0].addr & 0x1) {
134748c2ecf20Sopenharmony_ci		phy_blk[PORT_0] = &(phy[PORT_1]);
134758c2ecf20Sopenharmony_ci		phy_blk[PORT_1] = &(phy[PORT_0]);
134768c2ecf20Sopenharmony_ci	} else {
134778c2ecf20Sopenharmony_ci		phy_blk[PORT_0] = &(phy[PORT_0]);
134788c2ecf20Sopenharmony_ci		phy_blk[PORT_1] = &(phy[PORT_1]);
134798c2ecf20Sopenharmony_ci	}
134808c2ecf20Sopenharmony_ci	/* PART2 - Download firmware to both phys */
134818c2ecf20Sopenharmony_ci	for (port = PORT_MAX - 1; port >= PORT_0; port--) {
134828c2ecf20Sopenharmony_ci		if (CHIP_IS_E1x(bp))
134838c2ecf20Sopenharmony_ci			port_of_path = port;
134848c2ecf20Sopenharmony_ci		else
134858c2ecf20Sopenharmony_ci			port_of_path = 0;
134868c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
134878c2ecf20Sopenharmony_ci			   phy_blk[port]->addr);
134888c2ecf20Sopenharmony_ci		if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
134898c2ecf20Sopenharmony_ci						      port_of_path))
134908c2ecf20Sopenharmony_ci			return -EINVAL;
134918c2ecf20Sopenharmony_ci		/* Disable PHY transmitter output */
134928c2ecf20Sopenharmony_ci		bnx2x_cl45_write(bp, phy_blk[port],
134938c2ecf20Sopenharmony_ci				 MDIO_PMA_DEVAD,
134948c2ecf20Sopenharmony_ci				 MDIO_PMA_REG_TX_DISABLE, 1);
134958c2ecf20Sopenharmony_ci
134968c2ecf20Sopenharmony_ci	}
134978c2ecf20Sopenharmony_ci	return 0;
134988c2ecf20Sopenharmony_ci}
134998c2ecf20Sopenharmony_ci
135008c2ecf20Sopenharmony_cistatic int bnx2x_84833_common_init_phy(struct bnx2x *bp,
135018c2ecf20Sopenharmony_ci						u32 shmem_base_path[],
135028c2ecf20Sopenharmony_ci						u32 shmem2_base_path[],
135038c2ecf20Sopenharmony_ci						u8 phy_index,
135048c2ecf20Sopenharmony_ci						u32 chip_id)
135058c2ecf20Sopenharmony_ci{
135068c2ecf20Sopenharmony_ci	u8 reset_gpios;
135078c2ecf20Sopenharmony_ci	reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
135088c2ecf20Sopenharmony_ci	bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
135098c2ecf20Sopenharmony_ci	udelay(10);
135108c2ecf20Sopenharmony_ci	bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
135118c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
135128c2ecf20Sopenharmony_ci		reset_gpios);
135138c2ecf20Sopenharmony_ci	return 0;
135148c2ecf20Sopenharmony_ci}
135158c2ecf20Sopenharmony_ci
135168c2ecf20Sopenharmony_cistatic int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
135178c2ecf20Sopenharmony_ci				     u32 shmem2_base_path[], u8 phy_index,
135188c2ecf20Sopenharmony_ci				     u32 ext_phy_type, u32 chip_id)
135198c2ecf20Sopenharmony_ci{
135208c2ecf20Sopenharmony_ci	int rc = 0;
135218c2ecf20Sopenharmony_ci
135228c2ecf20Sopenharmony_ci	switch (ext_phy_type) {
135238c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
135248c2ecf20Sopenharmony_ci		rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
135258c2ecf20Sopenharmony_ci						shmem2_base_path,
135268c2ecf20Sopenharmony_ci						phy_index, chip_id);
135278c2ecf20Sopenharmony_ci		break;
135288c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
135298c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
135308c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
135318c2ecf20Sopenharmony_ci		rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
135328c2ecf20Sopenharmony_ci						shmem2_base_path,
135338c2ecf20Sopenharmony_ci						phy_index, chip_id);
135348c2ecf20Sopenharmony_ci		break;
135358c2ecf20Sopenharmony_ci
135368c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
135378c2ecf20Sopenharmony_ci		/* GPIO1 affects both ports, so there's need to pull
135388c2ecf20Sopenharmony_ci		 * it for single port alone
135398c2ecf20Sopenharmony_ci		 */
135408c2ecf20Sopenharmony_ci		rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
135418c2ecf20Sopenharmony_ci						shmem2_base_path,
135428c2ecf20Sopenharmony_ci						phy_index, chip_id);
135438c2ecf20Sopenharmony_ci		break;
135448c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
135458c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
135468c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858:
135478c2ecf20Sopenharmony_ci		/* GPIO3's are linked, and so both need to be toggled
135488c2ecf20Sopenharmony_ci		 * to obtain required 2us pulse.
135498c2ecf20Sopenharmony_ci		 */
135508c2ecf20Sopenharmony_ci		rc = bnx2x_84833_common_init_phy(bp, shmem_base_path,
135518c2ecf20Sopenharmony_ci						shmem2_base_path,
135528c2ecf20Sopenharmony_ci						phy_index, chip_id);
135538c2ecf20Sopenharmony_ci		break;
135548c2ecf20Sopenharmony_ci	case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
135558c2ecf20Sopenharmony_ci		rc = -EINVAL;
135568c2ecf20Sopenharmony_ci		break;
135578c2ecf20Sopenharmony_ci	default:
135588c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK,
135598c2ecf20Sopenharmony_ci			   "ext_phy 0x%x common init not required\n",
135608c2ecf20Sopenharmony_ci			   ext_phy_type);
135618c2ecf20Sopenharmony_ci		break;
135628c2ecf20Sopenharmony_ci	}
135638c2ecf20Sopenharmony_ci
135648c2ecf20Sopenharmony_ci	if (rc)
135658c2ecf20Sopenharmony_ci		netdev_err(bp->dev,  "Warning: PHY was not initialized,"
135668c2ecf20Sopenharmony_ci				      " Port %d\n",
135678c2ecf20Sopenharmony_ci			 0);
135688c2ecf20Sopenharmony_ci	return rc;
135698c2ecf20Sopenharmony_ci}
135708c2ecf20Sopenharmony_ci
135718c2ecf20Sopenharmony_ciint bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
135728c2ecf20Sopenharmony_ci			  u32 shmem2_base_path[], u32 chip_id)
135738c2ecf20Sopenharmony_ci{
135748c2ecf20Sopenharmony_ci	int rc = 0;
135758c2ecf20Sopenharmony_ci	u32 phy_ver, val;
135768c2ecf20Sopenharmony_ci	u8 phy_index = 0;
135778c2ecf20Sopenharmony_ci	u32 ext_phy_type, ext_phy_config;
135788c2ecf20Sopenharmony_ci
135798c2ecf20Sopenharmony_ci	bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC0);
135808c2ecf20Sopenharmony_ci	bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC1);
135818c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Begin common phy init\n");
135828c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
135838c2ecf20Sopenharmony_ci		/* Enable EPIO */
135848c2ecf20Sopenharmony_ci		val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
135858c2ecf20Sopenharmony_ci		REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
135868c2ecf20Sopenharmony_ci	}
135878c2ecf20Sopenharmony_ci	/* Check if common init was already done */
135888c2ecf20Sopenharmony_ci	phy_ver = REG_RD(bp, shmem_base_path[0] +
135898c2ecf20Sopenharmony_ci			 offsetof(struct shmem_region,
135908c2ecf20Sopenharmony_ci				  port_mb[PORT_0].ext_phy_fw_version));
135918c2ecf20Sopenharmony_ci	if (phy_ver) {
135928c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
135938c2ecf20Sopenharmony_ci			       phy_ver);
135948c2ecf20Sopenharmony_ci		return 0;
135958c2ecf20Sopenharmony_ci	}
135968c2ecf20Sopenharmony_ci
135978c2ecf20Sopenharmony_ci	/* Read the ext_phy_type for arbitrary port(0) */
135988c2ecf20Sopenharmony_ci	for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
135998c2ecf20Sopenharmony_ci	      phy_index++) {
136008c2ecf20Sopenharmony_ci		ext_phy_config = bnx2x_get_ext_phy_config(bp,
136018c2ecf20Sopenharmony_ci							  shmem_base_path[0],
136028c2ecf20Sopenharmony_ci							  phy_index, 0);
136038c2ecf20Sopenharmony_ci		ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
136048c2ecf20Sopenharmony_ci		rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
136058c2ecf20Sopenharmony_ci						shmem2_base_path,
136068c2ecf20Sopenharmony_ci						phy_index, ext_phy_type,
136078c2ecf20Sopenharmony_ci						chip_id);
136088c2ecf20Sopenharmony_ci	}
136098c2ecf20Sopenharmony_ci	return rc;
136108c2ecf20Sopenharmony_ci}
136118c2ecf20Sopenharmony_ci
136128c2ecf20Sopenharmony_cistatic void bnx2x_check_over_curr(struct link_params *params,
136138c2ecf20Sopenharmony_ci				  struct link_vars *vars)
136148c2ecf20Sopenharmony_ci{
136158c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
136168c2ecf20Sopenharmony_ci	u32 cfg_pin;
136178c2ecf20Sopenharmony_ci	u8 port = params->port;
136188c2ecf20Sopenharmony_ci	u32 pin_val;
136198c2ecf20Sopenharmony_ci
136208c2ecf20Sopenharmony_ci	cfg_pin = (REG_RD(bp, params->shmem_base +
136218c2ecf20Sopenharmony_ci			  offsetof(struct shmem_region,
136228c2ecf20Sopenharmony_ci			       dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
136238c2ecf20Sopenharmony_ci		   PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
136248c2ecf20Sopenharmony_ci		PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
136258c2ecf20Sopenharmony_ci
136268c2ecf20Sopenharmony_ci	/* Ignore check if no external input PIN available */
136278c2ecf20Sopenharmony_ci	if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
136288c2ecf20Sopenharmony_ci		return;
136298c2ecf20Sopenharmony_ci
136308c2ecf20Sopenharmony_ci	if (!pin_val) {
136318c2ecf20Sopenharmony_ci		if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
136328c2ecf20Sopenharmony_ci			netdev_err(bp->dev, "Error:  Power fault on Port %d has"
136338c2ecf20Sopenharmony_ci					    " been detected and the power to "
136348c2ecf20Sopenharmony_ci					    "that SFP+ module has been removed"
136358c2ecf20Sopenharmony_ci					    " to prevent failure of the card."
136368c2ecf20Sopenharmony_ci					    " Please remove the SFP+ module and"
136378c2ecf20Sopenharmony_ci					    " restart the system to clear this"
136388c2ecf20Sopenharmony_ci					    " error.\n",
136398c2ecf20Sopenharmony_ci			 params->port);
136408c2ecf20Sopenharmony_ci			vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
136418c2ecf20Sopenharmony_ci			bnx2x_warpcore_power_module(params, 0);
136428c2ecf20Sopenharmony_ci		}
136438c2ecf20Sopenharmony_ci	} else
136448c2ecf20Sopenharmony_ci		vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
136458c2ecf20Sopenharmony_ci}
136468c2ecf20Sopenharmony_ci
136478c2ecf20Sopenharmony_ci/* Returns 0 if no change occurred since last check; 1 otherwise. */
136488c2ecf20Sopenharmony_cistatic u8 bnx2x_analyze_link_error(struct link_params *params,
136498c2ecf20Sopenharmony_ci				    struct link_vars *vars, u32 status,
136508c2ecf20Sopenharmony_ci				    u32 phy_flag, u32 link_flag, u8 notify)
136518c2ecf20Sopenharmony_ci{
136528c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
136538c2ecf20Sopenharmony_ci	/* Compare new value with previous value */
136548c2ecf20Sopenharmony_ci	u8 led_mode;
136558c2ecf20Sopenharmony_ci	u32 old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
136568c2ecf20Sopenharmony_ci
136578c2ecf20Sopenharmony_ci	if ((status ^ old_status) == 0)
136588c2ecf20Sopenharmony_ci		return 0;
136598c2ecf20Sopenharmony_ci
136608c2ecf20Sopenharmony_ci	/* If values differ */
136618c2ecf20Sopenharmony_ci	switch (phy_flag) {
136628c2ecf20Sopenharmony_ci	case PHY_HALF_OPEN_CONN_FLAG:
136638c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Analyze Remote Fault\n");
136648c2ecf20Sopenharmony_ci		break;
136658c2ecf20Sopenharmony_ci	case PHY_SFP_TX_FAULT_FLAG:
136668c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Analyze TX Fault\n");
136678c2ecf20Sopenharmony_ci		break;
136688c2ecf20Sopenharmony_ci	default:
136698c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Analyze UNKNOWN\n");
136708c2ecf20Sopenharmony_ci	}
136718c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Link changed:[%x %x]->%x\n", vars->link_up,
136728c2ecf20Sopenharmony_ci	   old_status, status);
136738c2ecf20Sopenharmony_ci
136748c2ecf20Sopenharmony_ci	/* Do not touch the link in case physical link down */
136758c2ecf20Sopenharmony_ci	if ((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0)
136768c2ecf20Sopenharmony_ci		return 1;
136778c2ecf20Sopenharmony_ci
136788c2ecf20Sopenharmony_ci	/* a. Update shmem->link_status accordingly
136798c2ecf20Sopenharmony_ci	 * b. Update link_vars->link_up
136808c2ecf20Sopenharmony_ci	 */
136818c2ecf20Sopenharmony_ci	if (status) {
136828c2ecf20Sopenharmony_ci		vars->link_status &= ~LINK_STATUS_LINK_UP;
136838c2ecf20Sopenharmony_ci		vars->link_status |= link_flag;
136848c2ecf20Sopenharmony_ci		vars->link_up = 0;
136858c2ecf20Sopenharmony_ci		vars->phy_flags |= phy_flag;
136868c2ecf20Sopenharmony_ci
136878c2ecf20Sopenharmony_ci		/* activate nig drain */
136888c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
136898c2ecf20Sopenharmony_ci		/* Set LED mode to off since the PHY doesn't know about these
136908c2ecf20Sopenharmony_ci		 * errors
136918c2ecf20Sopenharmony_ci		 */
136928c2ecf20Sopenharmony_ci		led_mode = LED_MODE_OFF;
136938c2ecf20Sopenharmony_ci	} else {
136948c2ecf20Sopenharmony_ci		vars->link_status |= LINK_STATUS_LINK_UP;
136958c2ecf20Sopenharmony_ci		vars->link_status &= ~link_flag;
136968c2ecf20Sopenharmony_ci		vars->link_up = 1;
136978c2ecf20Sopenharmony_ci		vars->phy_flags &= ~phy_flag;
136988c2ecf20Sopenharmony_ci		led_mode = LED_MODE_OPER;
136998c2ecf20Sopenharmony_ci
137008c2ecf20Sopenharmony_ci		/* Clear nig drain */
137018c2ecf20Sopenharmony_ci		REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
137028c2ecf20Sopenharmony_ci	}
137038c2ecf20Sopenharmony_ci	bnx2x_sync_link(params, vars);
137048c2ecf20Sopenharmony_ci	/* Update the LED according to the link state */
137058c2ecf20Sopenharmony_ci	bnx2x_set_led(params, vars, led_mode, SPEED_10000);
137068c2ecf20Sopenharmony_ci
137078c2ecf20Sopenharmony_ci	/* Update link status in the shared memory */
137088c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, vars->link_status);
137098c2ecf20Sopenharmony_ci
137108c2ecf20Sopenharmony_ci	/* C. Trigger General Attention */
137118c2ecf20Sopenharmony_ci	vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
137128c2ecf20Sopenharmony_ci	if (notify)
137138c2ecf20Sopenharmony_ci		bnx2x_notify_link_changed(bp);
137148c2ecf20Sopenharmony_ci
137158c2ecf20Sopenharmony_ci	return 1;
137168c2ecf20Sopenharmony_ci}
137178c2ecf20Sopenharmony_ci
137188c2ecf20Sopenharmony_ci/******************************************************************************
137198c2ecf20Sopenharmony_ci* Description:
137208c2ecf20Sopenharmony_ci*	This function checks for half opened connection change indication.
137218c2ecf20Sopenharmony_ci*	When such change occurs, it calls the bnx2x_analyze_link_error
137228c2ecf20Sopenharmony_ci*	to check if Remote Fault is set or cleared. Reception of remote fault
137238c2ecf20Sopenharmony_ci*	status message in the MAC indicates that the peer's MAC has detected
137248c2ecf20Sopenharmony_ci*	a fault, for example, due to break in the TX side of fiber.
137258c2ecf20Sopenharmony_ci*
137268c2ecf20Sopenharmony_ci******************************************************************************/
137278c2ecf20Sopenharmony_cistatic int bnx2x_check_half_open_conn(struct link_params *params,
137288c2ecf20Sopenharmony_ci				      struct link_vars *vars,
137298c2ecf20Sopenharmony_ci				      u8 notify)
137308c2ecf20Sopenharmony_ci{
137318c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
137328c2ecf20Sopenharmony_ci	u32 lss_status = 0;
137338c2ecf20Sopenharmony_ci	u32 mac_base;
137348c2ecf20Sopenharmony_ci	/* In case link status is physically up @ 10G do */
137358c2ecf20Sopenharmony_ci	if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
137368c2ecf20Sopenharmony_ci	    (REG_RD(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4)))
137378c2ecf20Sopenharmony_ci		return 0;
137388c2ecf20Sopenharmony_ci
137398c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp) &&
137408c2ecf20Sopenharmony_ci	    (REG_RD(bp, MISC_REG_RESET_REG_2) &
137418c2ecf20Sopenharmony_ci	      (MISC_REGISTERS_RESET_REG_2_XMAC))) {
137428c2ecf20Sopenharmony_ci		/* Check E3 XMAC */
137438c2ecf20Sopenharmony_ci		/* Note that link speed cannot be queried here, since it may be
137448c2ecf20Sopenharmony_ci		 * zero while link is down. In case UMAC is active, LSS will
137458c2ecf20Sopenharmony_ci		 * simply not be set
137468c2ecf20Sopenharmony_ci		 */
137478c2ecf20Sopenharmony_ci		mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
137488c2ecf20Sopenharmony_ci
137498c2ecf20Sopenharmony_ci		/* Clear stick bits (Requires rising edge) */
137508c2ecf20Sopenharmony_ci		REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
137518c2ecf20Sopenharmony_ci		REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
137528c2ecf20Sopenharmony_ci		       XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
137538c2ecf20Sopenharmony_ci		       XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
137548c2ecf20Sopenharmony_ci		if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
137558c2ecf20Sopenharmony_ci			lss_status = 1;
137568c2ecf20Sopenharmony_ci
137578c2ecf20Sopenharmony_ci		bnx2x_analyze_link_error(params, vars, lss_status,
137588c2ecf20Sopenharmony_ci					 PHY_HALF_OPEN_CONN_FLAG,
137598c2ecf20Sopenharmony_ci					 LINK_STATUS_NONE, notify);
137608c2ecf20Sopenharmony_ci	} else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
137618c2ecf20Sopenharmony_ci		   (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
137628c2ecf20Sopenharmony_ci		/* Check E1X / E2 BMAC */
137638c2ecf20Sopenharmony_ci		u32 lss_status_reg;
137648c2ecf20Sopenharmony_ci		u32 wb_data[2];
137658c2ecf20Sopenharmony_ci		mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
137668c2ecf20Sopenharmony_ci			NIG_REG_INGRESS_BMAC0_MEM;
137678c2ecf20Sopenharmony_ci		/*  Read BIGMAC_REGISTER_RX_LSS_STATUS */
137688c2ecf20Sopenharmony_ci		if (CHIP_IS_E2(bp))
137698c2ecf20Sopenharmony_ci			lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
137708c2ecf20Sopenharmony_ci		else
137718c2ecf20Sopenharmony_ci			lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
137728c2ecf20Sopenharmony_ci
137738c2ecf20Sopenharmony_ci		REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
137748c2ecf20Sopenharmony_ci		lss_status = (wb_data[0] > 0);
137758c2ecf20Sopenharmony_ci
137768c2ecf20Sopenharmony_ci		bnx2x_analyze_link_error(params, vars, lss_status,
137778c2ecf20Sopenharmony_ci					 PHY_HALF_OPEN_CONN_FLAG,
137788c2ecf20Sopenharmony_ci					 LINK_STATUS_NONE, notify);
137798c2ecf20Sopenharmony_ci	}
137808c2ecf20Sopenharmony_ci	return 0;
137818c2ecf20Sopenharmony_ci}
137828c2ecf20Sopenharmony_cistatic void bnx2x_sfp_tx_fault_detection(struct bnx2x_phy *phy,
137838c2ecf20Sopenharmony_ci					 struct link_params *params,
137848c2ecf20Sopenharmony_ci					 struct link_vars *vars)
137858c2ecf20Sopenharmony_ci{
137868c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
137878c2ecf20Sopenharmony_ci	u32 cfg_pin, value = 0;
137888c2ecf20Sopenharmony_ci	u8 led_change, port = params->port;
137898c2ecf20Sopenharmony_ci
137908c2ecf20Sopenharmony_ci	/* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
137918c2ecf20Sopenharmony_ci	cfg_pin = (REG_RD(bp, params->shmem_base + offsetof(struct shmem_region,
137928c2ecf20Sopenharmony_ci			  dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
137938c2ecf20Sopenharmony_ci		   PORT_HW_CFG_E3_TX_FAULT_MASK) >>
137948c2ecf20Sopenharmony_ci		  PORT_HW_CFG_E3_TX_FAULT_SHIFT;
137958c2ecf20Sopenharmony_ci
137968c2ecf20Sopenharmony_ci	if (bnx2x_get_cfg_pin(bp, cfg_pin, &value)) {
137978c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "Failed to read pin 0x%02x\n", cfg_pin);
137988c2ecf20Sopenharmony_ci		return;
137998c2ecf20Sopenharmony_ci	}
138008c2ecf20Sopenharmony_ci
138018c2ecf20Sopenharmony_ci	led_change = bnx2x_analyze_link_error(params, vars, value,
138028c2ecf20Sopenharmony_ci					      PHY_SFP_TX_FAULT_FLAG,
138038c2ecf20Sopenharmony_ci					      LINK_STATUS_SFP_TX_FAULT, 1);
138048c2ecf20Sopenharmony_ci
138058c2ecf20Sopenharmony_ci	if (led_change) {
138068c2ecf20Sopenharmony_ci		/* Change TX_Fault led, set link status for further syncs */
138078c2ecf20Sopenharmony_ci		u8 led_mode;
138088c2ecf20Sopenharmony_ci
138098c2ecf20Sopenharmony_ci		if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
138108c2ecf20Sopenharmony_ci			led_mode = MISC_REGISTERS_GPIO_HIGH;
138118c2ecf20Sopenharmony_ci			vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
138128c2ecf20Sopenharmony_ci		} else {
138138c2ecf20Sopenharmony_ci			led_mode = MISC_REGISTERS_GPIO_LOW;
138148c2ecf20Sopenharmony_ci			vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
138158c2ecf20Sopenharmony_ci		}
138168c2ecf20Sopenharmony_ci
138178c2ecf20Sopenharmony_ci		/* If module is unapproved, led should be on regardless */
138188c2ecf20Sopenharmony_ci		if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
138198c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "Change TX_Fault LED: ->%x\n",
138208c2ecf20Sopenharmony_ci			   led_mode);
138218c2ecf20Sopenharmony_ci			bnx2x_set_e3_module_fault_led(params, led_mode);
138228c2ecf20Sopenharmony_ci		}
138238c2ecf20Sopenharmony_ci	}
138248c2ecf20Sopenharmony_ci}
138258c2ecf20Sopenharmony_cistatic void bnx2x_kr2_recovery(struct link_params *params,
138268c2ecf20Sopenharmony_ci			       struct link_vars *vars,
138278c2ecf20Sopenharmony_ci			       struct bnx2x_phy *phy)
138288c2ecf20Sopenharmony_ci{
138298c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
138308c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "KR2 recovery\n");
138318c2ecf20Sopenharmony_ci	bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
138328c2ecf20Sopenharmony_ci	bnx2x_warpcore_restart_AN_KR(phy, params);
138338c2ecf20Sopenharmony_ci}
138348c2ecf20Sopenharmony_ci
138358c2ecf20Sopenharmony_cistatic void bnx2x_check_kr2_wa(struct link_params *params,
138368c2ecf20Sopenharmony_ci			       struct link_vars *vars,
138378c2ecf20Sopenharmony_ci			       struct bnx2x_phy *phy)
138388c2ecf20Sopenharmony_ci{
138398c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
138408c2ecf20Sopenharmony_ci	u16 base_page, next_page, not_kr2_device, lane;
138418c2ecf20Sopenharmony_ci	int sigdet;
138428c2ecf20Sopenharmony_ci
138438c2ecf20Sopenharmony_ci	/* Once KR2 was disabled, wait 5 seconds before checking KR2 recovery
138448c2ecf20Sopenharmony_ci	 * Since some switches tend to reinit the AN process and clear the
138458c2ecf20Sopenharmony_ci	 * the advertised BP/NP after ~2 seconds causing the KR2 to be disabled
138468c2ecf20Sopenharmony_ci	 * and recovered many times
138478c2ecf20Sopenharmony_ci	 */
138488c2ecf20Sopenharmony_ci	if (vars->check_kr2_recovery_cnt > 0) {
138498c2ecf20Sopenharmony_ci		vars->check_kr2_recovery_cnt--;
138508c2ecf20Sopenharmony_ci		return;
138518c2ecf20Sopenharmony_ci	}
138528c2ecf20Sopenharmony_ci
138538c2ecf20Sopenharmony_ci	sigdet = bnx2x_warpcore_get_sigdet(phy, params);
138548c2ecf20Sopenharmony_ci	if (!sigdet) {
138558c2ecf20Sopenharmony_ci		if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
138568c2ecf20Sopenharmony_ci			bnx2x_kr2_recovery(params, vars, phy);
138578c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "No sigdet\n");
138588c2ecf20Sopenharmony_ci		}
138598c2ecf20Sopenharmony_ci		return;
138608c2ecf20Sopenharmony_ci	}
138618c2ecf20Sopenharmony_ci
138628c2ecf20Sopenharmony_ci	lane = bnx2x_get_warpcore_lane(phy, params);
138638c2ecf20Sopenharmony_ci	CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
138648c2ecf20Sopenharmony_ci			  MDIO_AER_BLOCK_AER_REG, lane);
138658c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
138668c2ecf20Sopenharmony_ci			MDIO_AN_REG_LP_AUTO_NEG, &base_page);
138678c2ecf20Sopenharmony_ci	bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
138688c2ecf20Sopenharmony_ci			MDIO_AN_REG_LP_AUTO_NEG2, &next_page);
138698c2ecf20Sopenharmony_ci	bnx2x_set_aer_mmd(params, phy);
138708c2ecf20Sopenharmony_ci
138718c2ecf20Sopenharmony_ci	/* CL73 has not begun yet */
138728c2ecf20Sopenharmony_ci	if (base_page == 0) {
138738c2ecf20Sopenharmony_ci		if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
138748c2ecf20Sopenharmony_ci			bnx2x_kr2_recovery(params, vars, phy);
138758c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "No BP\n");
138768c2ecf20Sopenharmony_ci		}
138778c2ecf20Sopenharmony_ci		return;
138788c2ecf20Sopenharmony_ci	}
138798c2ecf20Sopenharmony_ci
138808c2ecf20Sopenharmony_ci	/* In case NP bit is not set in the BasePage, or it is set,
138818c2ecf20Sopenharmony_ci	 * but only KX is advertised, declare this link partner as non-KR2
138828c2ecf20Sopenharmony_ci	 * device.
138838c2ecf20Sopenharmony_ci	 */
138848c2ecf20Sopenharmony_ci	not_kr2_device = (((base_page & 0x8000) == 0) ||
138858c2ecf20Sopenharmony_ci			  (((base_page & 0x8000) &&
138868c2ecf20Sopenharmony_ci			    ((next_page & 0xe0) == 0x20))));
138878c2ecf20Sopenharmony_ci
138888c2ecf20Sopenharmony_ci	/* In case KR2 is already disabled, check if we need to re-enable it */
138898c2ecf20Sopenharmony_ci	if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
138908c2ecf20Sopenharmony_ci		if (!not_kr2_device) {
138918c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page,
138928c2ecf20Sopenharmony_ci			   next_page);
138938c2ecf20Sopenharmony_ci			bnx2x_kr2_recovery(params, vars, phy);
138948c2ecf20Sopenharmony_ci		}
138958c2ecf20Sopenharmony_ci		return;
138968c2ecf20Sopenharmony_ci	}
138978c2ecf20Sopenharmony_ci	/* KR2 is enabled, but not KR2 device */
138988c2ecf20Sopenharmony_ci	if (not_kr2_device) {
138998c2ecf20Sopenharmony_ci		/* Disable KR2 on both lanes */
139008c2ecf20Sopenharmony_ci		DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page, next_page);
139018c2ecf20Sopenharmony_ci		bnx2x_disable_kr2(params, vars, phy);
139028c2ecf20Sopenharmony_ci		/* Restart AN on leading lane */
139038c2ecf20Sopenharmony_ci		bnx2x_warpcore_restart_AN_KR(phy, params);
139048c2ecf20Sopenharmony_ci		return;
139058c2ecf20Sopenharmony_ci	}
139068c2ecf20Sopenharmony_ci}
139078c2ecf20Sopenharmony_ci
139088c2ecf20Sopenharmony_civoid bnx2x_period_func(struct link_params *params, struct link_vars *vars)
139098c2ecf20Sopenharmony_ci{
139108c2ecf20Sopenharmony_ci	u16 phy_idx;
139118c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
139128c2ecf20Sopenharmony_ci	for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
139138c2ecf20Sopenharmony_ci		if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
139148c2ecf20Sopenharmony_ci			bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
139158c2ecf20Sopenharmony_ci			if (bnx2x_check_half_open_conn(params, vars, 1) !=
139168c2ecf20Sopenharmony_ci			    0)
139178c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "Fault detection failed\n");
139188c2ecf20Sopenharmony_ci			break;
139198c2ecf20Sopenharmony_ci		}
139208c2ecf20Sopenharmony_ci	}
139218c2ecf20Sopenharmony_ci
139228c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
139238c2ecf20Sopenharmony_ci		struct bnx2x_phy *phy = &params->phy[INT_PHY];
139248c2ecf20Sopenharmony_ci		bnx2x_set_aer_mmd(params, phy);
139258c2ecf20Sopenharmony_ci		if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
139268c2ecf20Sopenharmony_ci		     (phy->speed_cap_mask &
139278c2ecf20Sopenharmony_ci		      PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
139288c2ecf20Sopenharmony_ci		    (phy->req_line_speed == SPEED_20000))
139298c2ecf20Sopenharmony_ci			bnx2x_check_kr2_wa(params, vars, phy);
139308c2ecf20Sopenharmony_ci		bnx2x_check_over_curr(params, vars);
139318c2ecf20Sopenharmony_ci		if (vars->rx_tx_asic_rst)
139328c2ecf20Sopenharmony_ci			bnx2x_warpcore_config_runtime(phy, params, vars);
139338c2ecf20Sopenharmony_ci
139348c2ecf20Sopenharmony_ci		if ((REG_RD(bp, params->shmem_base +
139358c2ecf20Sopenharmony_ci			    offsetof(struct shmem_region, dev_info.
139368c2ecf20Sopenharmony_ci				port_hw_config[params->port].default_cfg))
139378c2ecf20Sopenharmony_ci		    & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
139388c2ecf20Sopenharmony_ci		    PORT_HW_CFG_NET_SERDES_IF_SFI) {
139398c2ecf20Sopenharmony_ci			if (bnx2x_is_sfp_module_plugged(phy, params)) {
139408c2ecf20Sopenharmony_ci				bnx2x_sfp_tx_fault_detection(phy, params, vars);
139418c2ecf20Sopenharmony_ci			} else if (vars->link_status &
139428c2ecf20Sopenharmony_ci				LINK_STATUS_SFP_TX_FAULT) {
139438c2ecf20Sopenharmony_ci				/* Clean trail, interrupt corrects the leds */
139448c2ecf20Sopenharmony_ci				vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
139458c2ecf20Sopenharmony_ci				vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
139468c2ecf20Sopenharmony_ci				/* Update link status in the shared memory */
139478c2ecf20Sopenharmony_ci				bnx2x_update_mng(params, vars->link_status);
139488c2ecf20Sopenharmony_ci			}
139498c2ecf20Sopenharmony_ci		}
139508c2ecf20Sopenharmony_ci	}
139518c2ecf20Sopenharmony_ci}
139528c2ecf20Sopenharmony_ci
139538c2ecf20Sopenharmony_ciu8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
139548c2ecf20Sopenharmony_ci			     u32 shmem_base,
139558c2ecf20Sopenharmony_ci			     u32 shmem2_base,
139568c2ecf20Sopenharmony_ci			     u8 port)
139578c2ecf20Sopenharmony_ci{
139588c2ecf20Sopenharmony_ci	u8 phy_index, fan_failure_det_req = 0;
139598c2ecf20Sopenharmony_ci	struct bnx2x_phy phy;
139608c2ecf20Sopenharmony_ci	for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
139618c2ecf20Sopenharmony_ci	      phy_index++) {
139628c2ecf20Sopenharmony_ci		if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
139638c2ecf20Sopenharmony_ci				       port, &phy)
139648c2ecf20Sopenharmony_ci		    != 0) {
139658c2ecf20Sopenharmony_ci			DP(NETIF_MSG_LINK, "populate phy failed\n");
139668c2ecf20Sopenharmony_ci			return 0;
139678c2ecf20Sopenharmony_ci		}
139688c2ecf20Sopenharmony_ci		fan_failure_det_req |= (phy.flags &
139698c2ecf20Sopenharmony_ci					FLAGS_FAN_FAILURE_DET_REQ);
139708c2ecf20Sopenharmony_ci	}
139718c2ecf20Sopenharmony_ci	return fan_failure_det_req;
139728c2ecf20Sopenharmony_ci}
139738c2ecf20Sopenharmony_ci
139748c2ecf20Sopenharmony_civoid bnx2x_hw_reset_phy(struct link_params *params)
139758c2ecf20Sopenharmony_ci{
139768c2ecf20Sopenharmony_ci	u8 phy_index;
139778c2ecf20Sopenharmony_ci	struct bnx2x *bp = params->bp;
139788c2ecf20Sopenharmony_ci	bnx2x_update_mng(params, 0);
139798c2ecf20Sopenharmony_ci	bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
139808c2ecf20Sopenharmony_ci		       (NIG_MASK_XGXS0_LINK_STATUS |
139818c2ecf20Sopenharmony_ci			NIG_MASK_XGXS0_LINK10G |
139828c2ecf20Sopenharmony_ci			NIG_MASK_SERDES0_LINK_STATUS |
139838c2ecf20Sopenharmony_ci			NIG_MASK_MI_INT));
139848c2ecf20Sopenharmony_ci
139858c2ecf20Sopenharmony_ci	for (phy_index = INT_PHY; phy_index < MAX_PHYS;
139868c2ecf20Sopenharmony_ci	      phy_index++) {
139878c2ecf20Sopenharmony_ci		if (params->phy[phy_index].hw_reset) {
139888c2ecf20Sopenharmony_ci			params->phy[phy_index].hw_reset(
139898c2ecf20Sopenharmony_ci				&params->phy[phy_index],
139908c2ecf20Sopenharmony_ci				params);
139918c2ecf20Sopenharmony_ci			params->phy[phy_index] = phy_null;
139928c2ecf20Sopenharmony_ci		}
139938c2ecf20Sopenharmony_ci	}
139948c2ecf20Sopenharmony_ci}
139958c2ecf20Sopenharmony_ci
139968c2ecf20Sopenharmony_civoid bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
139978c2ecf20Sopenharmony_ci			    u32 chip_id, u32 shmem_base, u32 shmem2_base,
139988c2ecf20Sopenharmony_ci			    u8 port)
139998c2ecf20Sopenharmony_ci{
140008c2ecf20Sopenharmony_ci	u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
140018c2ecf20Sopenharmony_ci	u32 val;
140028c2ecf20Sopenharmony_ci	u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
140038c2ecf20Sopenharmony_ci	if (CHIP_IS_E3(bp)) {
140048c2ecf20Sopenharmony_ci		if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
140058c2ecf20Sopenharmony_ci					      shmem_base,
140068c2ecf20Sopenharmony_ci					      port,
140078c2ecf20Sopenharmony_ci					      &gpio_num,
140088c2ecf20Sopenharmony_ci					      &gpio_port) != 0)
140098c2ecf20Sopenharmony_ci			return;
140108c2ecf20Sopenharmony_ci	} else {
140118c2ecf20Sopenharmony_ci		struct bnx2x_phy phy;
140128c2ecf20Sopenharmony_ci		for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
140138c2ecf20Sopenharmony_ci		      phy_index++) {
140148c2ecf20Sopenharmony_ci			if (bnx2x_populate_phy(bp, phy_index, shmem_base,
140158c2ecf20Sopenharmony_ci					       shmem2_base, port, &phy)
140168c2ecf20Sopenharmony_ci			    != 0) {
140178c2ecf20Sopenharmony_ci				DP(NETIF_MSG_LINK, "populate phy failed\n");
140188c2ecf20Sopenharmony_ci				return;
140198c2ecf20Sopenharmony_ci			}
140208c2ecf20Sopenharmony_ci			if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
140218c2ecf20Sopenharmony_ci				gpio_num = MISC_REGISTERS_GPIO_3;
140228c2ecf20Sopenharmony_ci				gpio_port = port;
140238c2ecf20Sopenharmony_ci				break;
140248c2ecf20Sopenharmony_ci			}
140258c2ecf20Sopenharmony_ci		}
140268c2ecf20Sopenharmony_ci	}
140278c2ecf20Sopenharmony_ci
140288c2ecf20Sopenharmony_ci	if (gpio_num == 0xff)
140298c2ecf20Sopenharmony_ci		return;
140308c2ecf20Sopenharmony_ci
140318c2ecf20Sopenharmony_ci	/* Set GPIO3 to trigger SFP+ module insertion/removal */
140328c2ecf20Sopenharmony_ci	bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
140338c2ecf20Sopenharmony_ci
140348c2ecf20Sopenharmony_ci	swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
140358c2ecf20Sopenharmony_ci	swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
140368c2ecf20Sopenharmony_ci	gpio_port ^= (swap_val && swap_override);
140378c2ecf20Sopenharmony_ci
140388c2ecf20Sopenharmony_ci	vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
140398c2ecf20Sopenharmony_ci		(gpio_num + (gpio_port << 2));
140408c2ecf20Sopenharmony_ci
140418c2ecf20Sopenharmony_ci	sync_offset = shmem_base +
140428c2ecf20Sopenharmony_ci		offsetof(struct shmem_region,
140438c2ecf20Sopenharmony_ci			 dev_info.port_hw_config[port].aeu_int_mask);
140448c2ecf20Sopenharmony_ci	REG_WR(bp, sync_offset, vars->aeu_int_mask);
140458c2ecf20Sopenharmony_ci
140468c2ecf20Sopenharmony_ci	DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
140478c2ecf20Sopenharmony_ci		       gpio_num, gpio_port, vars->aeu_int_mask);
140488c2ecf20Sopenharmony_ci
140498c2ecf20Sopenharmony_ci	if (port == 0)
140508c2ecf20Sopenharmony_ci		offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
140518c2ecf20Sopenharmony_ci	else
140528c2ecf20Sopenharmony_ci		offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
140538c2ecf20Sopenharmony_ci
140548c2ecf20Sopenharmony_ci	/* Open appropriate AEU for interrupts */
140558c2ecf20Sopenharmony_ci	aeu_mask = REG_RD(bp, offset);
140568c2ecf20Sopenharmony_ci	aeu_mask |= vars->aeu_int_mask;
140578c2ecf20Sopenharmony_ci	REG_WR(bp, offset, aeu_mask);
140588c2ecf20Sopenharmony_ci
140598c2ecf20Sopenharmony_ci	/* Enable the GPIO to trigger interrupt */
140608c2ecf20Sopenharmony_ci	val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
140618c2ecf20Sopenharmony_ci	val |= 1 << (gpio_num + (gpio_port << 2));
140628c2ecf20Sopenharmony_ci	REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
140638c2ecf20Sopenharmony_ci}
14064