162306a36Sopenharmony_ci/* Copyright 2008-2013 Broadcom Corporation
262306a36Sopenharmony_ci * Copyright (c) 2014 QLogic Corporation
362306a36Sopenharmony_ci * All rights reserved
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Unless you and QLogic execute a separate written software license
662306a36Sopenharmony_ci * agreement governing use of this software, this software is licensed to you
762306a36Sopenharmony_ci * under the terms of the GNU General Public License version 2, available
862306a36Sopenharmony_ci * at http://www.gnu.org/licenses/gpl-2.0.html (the "GPL").
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Notwithstanding the above, under no circumstances may you combine this
1162306a36Sopenharmony_ci * software in any way with any other Qlogic software provided under a
1262306a36Sopenharmony_ci * license other than the GPL, without Qlogic's express prior written
1362306a36Sopenharmony_ci * consent.
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * Written by Yaniv Rosner
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifndef BNX2X_LINK_H
2062306a36Sopenharmony_ci#define BNX2X_LINK_H
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/***********************************************************/
2562306a36Sopenharmony_ci/*                         Defines                         */
2662306a36Sopenharmony_ci/***********************************************************/
2762306a36Sopenharmony_ci#define DEFAULT_PHY_DEV_ADDR	3
2862306a36Sopenharmony_ci#define E2_DEFAULT_PHY_DEV_ADDR	5
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define BNX2X_FLOW_CTRL_AUTO		PORT_FEATURE_FLOW_CONTROL_AUTO
3362306a36Sopenharmony_ci#define BNX2X_FLOW_CTRL_TX		PORT_FEATURE_FLOW_CONTROL_TX
3462306a36Sopenharmony_ci#define BNX2X_FLOW_CTRL_RX		PORT_FEATURE_FLOW_CONTROL_RX
3562306a36Sopenharmony_ci#define BNX2X_FLOW_CTRL_BOTH		PORT_FEATURE_FLOW_CONTROL_BOTH
3662306a36Sopenharmony_ci#define BNX2X_FLOW_CTRL_NONE		PORT_FEATURE_FLOW_CONTROL_NONE
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define NET_SERDES_IF_XFI		1
3962306a36Sopenharmony_ci#define NET_SERDES_IF_SFI		2
4062306a36Sopenharmony_ci#define NET_SERDES_IF_KR		3
4162306a36Sopenharmony_ci#define NET_SERDES_IF_DXGXS	4
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define SPEED_AUTO_NEG		0
4462306a36Sopenharmony_ci#define SPEED_20000		20000
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define I2C_DEV_ADDR_A0			0xa0
4762306a36Sopenharmony_ci#define I2C_DEV_ADDR_A2			0xa2
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define SFP_EEPROM_PAGE_SIZE			16
5062306a36Sopenharmony_ci#define SFP_EEPROM_VENDOR_NAME_ADDR		0x14
5162306a36Sopenharmony_ci#define SFP_EEPROM_VENDOR_NAME_SIZE		16
5262306a36Sopenharmony_ci#define SFP_EEPROM_VENDOR_OUI_ADDR		0x25
5362306a36Sopenharmony_ci#define SFP_EEPROM_VENDOR_OUI_SIZE		3
5462306a36Sopenharmony_ci#define SFP_EEPROM_PART_NO_ADDR			0x28
5562306a36Sopenharmony_ci#define SFP_EEPROM_PART_NO_SIZE			16
5662306a36Sopenharmony_ci#define SFP_EEPROM_REVISION_ADDR		0x38
5762306a36Sopenharmony_ci#define SFP_EEPROM_REVISION_SIZE		4
5862306a36Sopenharmony_ci#define SFP_EEPROM_SERIAL_ADDR			0x44
5962306a36Sopenharmony_ci#define SFP_EEPROM_SERIAL_SIZE			16
6062306a36Sopenharmony_ci#define SFP_EEPROM_DATE_ADDR			0x54 /* ASCII YYMMDD */
6162306a36Sopenharmony_ci#define SFP_EEPROM_DATE_SIZE			6
6262306a36Sopenharmony_ci#define SFP_EEPROM_DIAG_TYPE_ADDR		0x5c
6362306a36Sopenharmony_ci#define SFP_EEPROM_DIAG_TYPE_SIZE		1
6462306a36Sopenharmony_ci#define SFP_EEPROM_DIAG_ADDR_CHANGE_REQ		(1<<2)
6562306a36Sopenharmony_ci#define SFP_EEPROM_DDM_IMPLEMENTED		(1<<6)
6662306a36Sopenharmony_ci#define SFP_EEPROM_SFF_8472_COMP_ADDR		0x5e
6762306a36Sopenharmony_ci#define SFP_EEPROM_SFF_8472_COMP_SIZE		1
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define SFP_EEPROM_A2_CHECKSUM_RANGE		0x5e
7062306a36Sopenharmony_ci#define SFP_EEPROM_A2_CC_DMI_ADDR		0x5f
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define PWR_FLT_ERR_MSG_LEN			250
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define XGXS_EXT_PHY_TYPE(ext_phy_config) \
7562306a36Sopenharmony_ci		((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK)
7662306a36Sopenharmony_ci#define XGXS_EXT_PHY_ADDR(ext_phy_config) \
7762306a36Sopenharmony_ci		(((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK) >> \
7862306a36Sopenharmony_ci		 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT)
7962306a36Sopenharmony_ci#define SERDES_EXT_PHY_TYPE(ext_phy_config) \
8062306a36Sopenharmony_ci		((ext_phy_config) & PORT_HW_CFG_SERDES_EXT_PHY_TYPE_MASK)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* Single Media Direct board is the plain 577xx board with CX4/RJ45 jacks */
8362306a36Sopenharmony_ci#define SINGLE_MEDIA_DIRECT(params)	(params->num_phys == 1)
8462306a36Sopenharmony_ci/* Single Media board contains single external phy */
8562306a36Sopenharmony_ci#define SINGLE_MEDIA(params)		(params->num_phys == 2)
8662306a36Sopenharmony_ci/* Dual Media board contains two external phy with different media */
8762306a36Sopenharmony_ci#define DUAL_MEDIA(params)		(params->num_phys == 3)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define FW_PARAM_PHY_ADDR_MASK		0x000000FF
9062306a36Sopenharmony_ci#define FW_PARAM_PHY_TYPE_MASK		0x0000FF00
9162306a36Sopenharmony_ci#define FW_PARAM_MDIO_CTRL_MASK		0xFFFF0000
9262306a36Sopenharmony_ci#define FW_PARAM_MDIO_CTRL_OFFSET		16
9362306a36Sopenharmony_ci#define FW_PARAM_PHY_ADDR(fw_param) (fw_param & \
9462306a36Sopenharmony_ci					   FW_PARAM_PHY_ADDR_MASK)
9562306a36Sopenharmony_ci#define FW_PARAM_PHY_TYPE(fw_param) (fw_param & \
9662306a36Sopenharmony_ci					   FW_PARAM_PHY_TYPE_MASK)
9762306a36Sopenharmony_ci#define FW_PARAM_MDIO_CTRL(fw_param) ((fw_param & \
9862306a36Sopenharmony_ci					    FW_PARAM_MDIO_CTRL_MASK) >> \
9962306a36Sopenharmony_ci					    FW_PARAM_MDIO_CTRL_OFFSET)
10062306a36Sopenharmony_ci#define FW_PARAM_SET(phy_addr, phy_type, mdio_access) \
10162306a36Sopenharmony_ci	(phy_addr | phy_type | mdio_access << FW_PARAM_MDIO_CTRL_OFFSET)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define PFC_BRB_FULL_LB_XOFF_THRESHOLD				170
10562306a36Sopenharmony_ci#define PFC_BRB_FULL_LB_XON_THRESHOLD				250
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define MAXVAL(a, b) (((a) > (b)) ? (a) : (b))
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#define BMAC_CONTROL_RX_ENABLE		2
11062306a36Sopenharmony_ci/***********************************************************/
11162306a36Sopenharmony_ci/*                         Structs                         */
11262306a36Sopenharmony_ci/***********************************************************/
11362306a36Sopenharmony_ci#define INT_PHY		0
11462306a36Sopenharmony_ci#define EXT_PHY1	1
11562306a36Sopenharmony_ci#define EXT_PHY2	2
11662306a36Sopenharmony_ci#define MAX_PHYS	3
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* Same configuration is shared between the XGXS and the first external phy */
11962306a36Sopenharmony_ci#define LINK_CONFIG_SIZE (MAX_PHYS - 1)
12062306a36Sopenharmony_ci#define LINK_CONFIG_IDX(_phy_idx) ((_phy_idx == INT_PHY) ? \
12162306a36Sopenharmony_ci					 0 : (_phy_idx - 1))
12262306a36Sopenharmony_ci/***********************************************************/
12362306a36Sopenharmony_ci/*                      bnx2x_phy struct                     */
12462306a36Sopenharmony_ci/*  Defines the required arguments and function per phy    */
12562306a36Sopenharmony_ci/***********************************************************/
12662306a36Sopenharmony_cistruct link_vars;
12762306a36Sopenharmony_cistruct link_params;
12862306a36Sopenharmony_cistruct bnx2x_phy;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_citypedef void (*config_init_t)(struct bnx2x_phy *phy, struct link_params *params,
13162306a36Sopenharmony_ci			      struct link_vars *vars);
13262306a36Sopenharmony_citypedef u8 (*read_status_t)(struct bnx2x_phy *phy, struct link_params *params,
13362306a36Sopenharmony_ci			    struct link_vars *vars);
13462306a36Sopenharmony_citypedef void (*link_reset_t)(struct bnx2x_phy *phy,
13562306a36Sopenharmony_ci			     struct link_params *params);
13662306a36Sopenharmony_citypedef void (*config_loopback_t)(struct bnx2x_phy *phy,
13762306a36Sopenharmony_ci				  struct link_params *params);
13862306a36Sopenharmony_citypedef int (*format_fw_ver_t)(u32 raw, u8 *str, u16 *len);
13962306a36Sopenharmony_citypedef void (*hw_reset_t)(struct bnx2x_phy *phy, struct link_params *params);
14062306a36Sopenharmony_citypedef void (*set_link_led_t)(struct bnx2x_phy *phy,
14162306a36Sopenharmony_ci			       struct link_params *params, u8 mode);
14262306a36Sopenharmony_citypedef void (*phy_specific_func_t)(struct bnx2x_phy *phy,
14362306a36Sopenharmony_ci				    struct link_params *params, u32 action);
14462306a36Sopenharmony_cistruct bnx2x_reg_set {
14562306a36Sopenharmony_ci	u8  devad;
14662306a36Sopenharmony_ci	u16 reg;
14762306a36Sopenharmony_ci	u16 val;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistruct bnx2x_phy {
15162306a36Sopenharmony_ci	u32 type;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	/* Loaded during init */
15462306a36Sopenharmony_ci	u8 addr;
15562306a36Sopenharmony_ci	u8 def_md_devad;
15662306a36Sopenharmony_ci	u16 flags;
15762306a36Sopenharmony_ci	/* No Over-Current detection */
15862306a36Sopenharmony_ci#define FLAGS_NOC			(1<<1)
15962306a36Sopenharmony_ci	/* Fan failure detection required */
16062306a36Sopenharmony_ci#define FLAGS_FAN_FAILURE_DET_REQ	(1<<2)
16162306a36Sopenharmony_ci	/* Initialize first the XGXS and only then the phy itself */
16262306a36Sopenharmony_ci#define FLAGS_INIT_XGXS_FIRST		(1<<3)
16362306a36Sopenharmony_ci#define FLAGS_WC_DUAL_MODE		(1<<4)
16462306a36Sopenharmony_ci#define FLAGS_4_PORT_MODE		(1<<5)
16562306a36Sopenharmony_ci#define FLAGS_REARM_LATCH_SIGNAL	(1<<6)
16662306a36Sopenharmony_ci#define FLAGS_SFP_NOT_APPROVED		(1<<7)
16762306a36Sopenharmony_ci#define FLAGS_MDC_MDIO_WA		(1<<8)
16862306a36Sopenharmony_ci#define FLAGS_DUMMY_READ		(1<<9)
16962306a36Sopenharmony_ci#define FLAGS_MDC_MDIO_WA_B0		(1<<10)
17062306a36Sopenharmony_ci#define FLAGS_TX_ERROR_CHECK		(1<<12)
17162306a36Sopenharmony_ci#define FLAGS_EEE			(1<<13)
17262306a36Sopenharmony_ci#define FLAGS_MDC_MDIO_WA_G		(1<<15)
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci	/* preemphasis values for the rx side */
17562306a36Sopenharmony_ci	u16 rx_preemphasis[4];
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	/* preemphasis values for the tx side */
17862306a36Sopenharmony_ci	u16 tx_preemphasis[4];
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	/* EMAC address for access MDIO */
18162306a36Sopenharmony_ci	u32 mdio_ctrl;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	u32 supported;
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	u32 media_type;
18662306a36Sopenharmony_ci#define	ETH_PHY_UNSPECIFIED	0x0
18762306a36Sopenharmony_ci#define	ETH_PHY_SFPP_10G_FIBER	0x1
18862306a36Sopenharmony_ci#define	ETH_PHY_XFP_FIBER		0x2
18962306a36Sopenharmony_ci#define	ETH_PHY_DA_TWINAX		0x3
19062306a36Sopenharmony_ci#define	ETH_PHY_BASE_T		0x4
19162306a36Sopenharmony_ci#define	ETH_PHY_SFP_1G_FIBER	0x5
19262306a36Sopenharmony_ci#define	ETH_PHY_KR		0xf0
19362306a36Sopenharmony_ci#define	ETH_PHY_CX4		0xf1
19462306a36Sopenharmony_ci#define	ETH_PHY_NOT_PRESENT	0xff
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci	/* The address in which version is located*/
19762306a36Sopenharmony_ci	u32 ver_addr;
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci	u16 req_flow_ctrl;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	u16 req_line_speed;
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci	u32 speed_cap_mask;
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	u16 req_duplex;
20662306a36Sopenharmony_ci	u16 rsrv;
20762306a36Sopenharmony_ci	/* Called per phy/port init, and it configures LASI, speed, autoneg,
20862306a36Sopenharmony_ci	 duplex, flow control negotiation, etc. */
20962306a36Sopenharmony_ci	config_init_t config_init;
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci	/* Called due to interrupt. It determines the link, speed */
21262306a36Sopenharmony_ci	read_status_t read_status;
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci	/* Called when driver is unloading. Should reset the phy */
21562306a36Sopenharmony_ci	link_reset_t link_reset;
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci	/* Set the loopback configuration for the phy */
21862306a36Sopenharmony_ci	config_loopback_t config_loopback;
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci	/* Format the given raw number into str up to len */
22162306a36Sopenharmony_ci	format_fw_ver_t format_fw_ver;
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	/* Reset the phy (both ports) */
22462306a36Sopenharmony_ci	hw_reset_t hw_reset;
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	/* Set link led mode (on/off/oper)*/
22762306a36Sopenharmony_ci	set_link_led_t set_link_led;
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	/* PHY Specific tasks */
23062306a36Sopenharmony_ci	phy_specific_func_t phy_specific_func;
23162306a36Sopenharmony_ci#define DISABLE_TX	1
23262306a36Sopenharmony_ci#define ENABLE_TX	2
23362306a36Sopenharmony_ci#define PHY_INIT	3
23462306a36Sopenharmony_ci};
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci/* Inputs parameters to the CLC */
23762306a36Sopenharmony_cistruct link_params {
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	u8 port;
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	/* Default / User Configuration */
24262306a36Sopenharmony_ci	u8 loopback_mode;
24362306a36Sopenharmony_ci#define LOOPBACK_NONE		0
24462306a36Sopenharmony_ci#define LOOPBACK_EMAC		1
24562306a36Sopenharmony_ci#define LOOPBACK_BMAC		2
24662306a36Sopenharmony_ci#define LOOPBACK_XGXS		3
24762306a36Sopenharmony_ci#define LOOPBACK_EXT_PHY	4
24862306a36Sopenharmony_ci#define LOOPBACK_EXT		5
24962306a36Sopenharmony_ci#define LOOPBACK_UMAC		6
25062306a36Sopenharmony_ci#define LOOPBACK_XMAC		7
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	/* Device parameters */
25362306a36Sopenharmony_ci	u8 mac_addr[6];
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	u16 req_duplex[LINK_CONFIG_SIZE];
25662306a36Sopenharmony_ci	u16 req_flow_ctrl[LINK_CONFIG_SIZE];
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci	u16 req_line_speed[LINK_CONFIG_SIZE]; /* Also determine AutoNeg */
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci	/* shmem parameters */
26162306a36Sopenharmony_ci	u32 shmem_base;
26262306a36Sopenharmony_ci	u32 shmem2_base;
26362306a36Sopenharmony_ci	u32 speed_cap_mask[LINK_CONFIG_SIZE];
26462306a36Sopenharmony_ci	u32 switch_cfg;
26562306a36Sopenharmony_ci#define SWITCH_CFG_1G		PORT_FEATURE_CON_SWITCH_1G_SWITCH
26662306a36Sopenharmony_ci#define SWITCH_CFG_10G		PORT_FEATURE_CON_SWITCH_10G_SWITCH
26762306a36Sopenharmony_ci#define SWITCH_CFG_AUTO_DETECT	PORT_FEATURE_CON_SWITCH_AUTO_DETECT
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci	u32 lane_config;
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci	/* Phy register parameter */
27262306a36Sopenharmony_ci	u32 chip_id;
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	/* features */
27562306a36Sopenharmony_ci	u32 feature_config_flags;
27662306a36Sopenharmony_ci#define FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED	(1<<0)
27762306a36Sopenharmony_ci#define FEATURE_CONFIG_PFC_ENABLED			(1<<1)
27862306a36Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY		(1<<2)
27962306a36Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY	(1<<3)
28062306a36Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_AFEX			(1<<8)
28162306a36Sopenharmony_ci#define FEATURE_CONFIG_AUTOGREEEN_ENABLED			(1<<9)
28262306a36Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED		(1<<10)
28362306a36Sopenharmony_ci#define FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET		(1<<11)
28462306a36Sopenharmony_ci#define FEATURE_CONFIG_MT_SUPPORT			(1<<13)
28562306a36Sopenharmony_ci#define FEATURE_CONFIG_BOOT_FROM_SAN			(1<<14)
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	/* Will be populated during common init */
28862306a36Sopenharmony_ci	struct bnx2x_phy phy[MAX_PHYS];
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci	/* Will be populated during common init */
29162306a36Sopenharmony_ci	u8 num_phys;
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	u8 rsrv;
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci	/* Used to configure the EEE Tx LPI timer, has several modes of
29662306a36Sopenharmony_ci	 * operation, according to bits 29:28 -
29762306a36Sopenharmony_ci	 * 2'b00: Timer will be configured by nvram, output will be the value
29862306a36Sopenharmony_ci	 *        from nvram.
29962306a36Sopenharmony_ci	 * 2'b01: Timer will be configured by nvram, output will be in
30062306a36Sopenharmony_ci	 *        microseconds.
30162306a36Sopenharmony_ci	 * 2'b10: bits 1:0 contain an nvram value which will be used instead
30262306a36Sopenharmony_ci	 *        of the one located in the nvram. Output will be that value.
30362306a36Sopenharmony_ci	 * 2'b11: bits 19:0 contain the idle timer in microseconds; output
30462306a36Sopenharmony_ci	 *        will be in microseconds.
30562306a36Sopenharmony_ci	 * Bits 31:30 should be 2'b11 in order for EEE to be enabled.
30662306a36Sopenharmony_ci	 */
30762306a36Sopenharmony_ci	u32 eee_mode;
30862306a36Sopenharmony_ci#define EEE_MODE_NVRAM_BALANCED_TIME		(0xa00)
30962306a36Sopenharmony_ci#define EEE_MODE_NVRAM_AGGRESSIVE_TIME		(0x100)
31062306a36Sopenharmony_ci#define EEE_MODE_NVRAM_LATENCY_TIME		(0x6000)
31162306a36Sopenharmony_ci#define EEE_MODE_NVRAM_MASK		(0x3)
31262306a36Sopenharmony_ci#define EEE_MODE_TIMER_MASK		(0xfffff)
31362306a36Sopenharmony_ci#define EEE_MODE_OUTPUT_TIME		(1<<28)
31462306a36Sopenharmony_ci#define EEE_MODE_OVERRIDE_NVRAM		(1<<29)
31562306a36Sopenharmony_ci#define EEE_MODE_ENABLE_LPI		(1<<30)
31662306a36Sopenharmony_ci#define EEE_MODE_ADV_LPI			(1<<31)
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	u16 hw_led_mode; /* part of the hw_config read from the shmem */
31962306a36Sopenharmony_ci	u32 multi_phy_config;
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci	/* Device pointer passed to all callback functions */
32262306a36Sopenharmony_ci	struct bnx2x *bp;
32362306a36Sopenharmony_ci	u16 req_fc_auto_adv; /* Should be set to TX / BOTH when
32462306a36Sopenharmony_ci				req_flow_ctrl is set to AUTO */
32562306a36Sopenharmony_ci	u16 link_flags;
32662306a36Sopenharmony_ci#define LINK_FLAGS_INT_DISABLED		(1<<0)
32762306a36Sopenharmony_ci#define PHY_INITIALIZED		(1<<1)
32862306a36Sopenharmony_ci	u32 lfa_base;
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	/* The same definitions as the shmem2 parameter */
33162306a36Sopenharmony_ci	u32 link_attr_sync;
33262306a36Sopenharmony_ci};
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci/* Output parameters */
33562306a36Sopenharmony_cistruct link_vars {
33662306a36Sopenharmony_ci	u8 phy_flags;
33762306a36Sopenharmony_ci#define PHY_XGXS_FLAG			(1<<0)
33862306a36Sopenharmony_ci#define PHY_SGMII_FLAG			(1<<1)
33962306a36Sopenharmony_ci#define PHY_PHYSICAL_LINK_FLAG		(1<<2)
34062306a36Sopenharmony_ci#define PHY_HALF_OPEN_CONN_FLAG		(1<<3)
34162306a36Sopenharmony_ci#define PHY_OVER_CURRENT_FLAG		(1<<4)
34262306a36Sopenharmony_ci#define PHY_SFP_TX_FAULT_FLAG		(1<<5)
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci	u8 mac_type;
34562306a36Sopenharmony_ci#define MAC_TYPE_NONE		0
34662306a36Sopenharmony_ci#define MAC_TYPE_EMAC		1
34762306a36Sopenharmony_ci#define MAC_TYPE_BMAC		2
34862306a36Sopenharmony_ci#define MAC_TYPE_UMAC		3
34962306a36Sopenharmony_ci#define MAC_TYPE_XMAC		4
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	u8 phy_link_up; /* internal phy link indication */
35262306a36Sopenharmony_ci	u8 link_up;
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci	u16 line_speed;
35562306a36Sopenharmony_ci	u16 duplex;
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci	u16 flow_ctrl;
35862306a36Sopenharmony_ci	u16 ieee_fc;
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	/* The same definitions as the shmem parameter */
36162306a36Sopenharmony_ci	u32 link_status;
36262306a36Sopenharmony_ci	u32 eee_status;
36362306a36Sopenharmony_ci	u8 fault_detected;
36462306a36Sopenharmony_ci	u8 check_kr2_recovery_cnt;
36562306a36Sopenharmony_ci#define CHECK_KR2_RECOVERY_CNT	5
36662306a36Sopenharmony_ci	u16 periodic_flags;
36762306a36Sopenharmony_ci#define PERIODIC_FLAGS_LINK_EVENT	0x0001
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci	u32 aeu_int_mask;
37062306a36Sopenharmony_ci	u8 rx_tx_asic_rst;
37162306a36Sopenharmony_ci	u8 turn_to_run_wc_rt;
37262306a36Sopenharmony_ci	u16 rsrv2;
37362306a36Sopenharmony_ci};
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci/***********************************************************/
37662306a36Sopenharmony_ci/*                         Functions                       */
37762306a36Sopenharmony_ci/***********************************************************/
37862306a36Sopenharmony_ciint bnx2x_phy_init(struct link_params *params, struct link_vars *vars);
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci/* Reset the link. Should be called when driver or interface goes down
38162306a36Sopenharmony_ci   Before calling phy firmware upgrade, the reset_ext_phy should be set
38262306a36Sopenharmony_ci   to 0 */
38362306a36Sopenharmony_ciint bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
38462306a36Sopenharmony_ci		     u8 reset_ext_phy);
38562306a36Sopenharmony_ciint bnx2x_lfa_reset(struct link_params *params, struct link_vars *vars);
38662306a36Sopenharmony_ci/* bnx2x_link_update should be called upon link interrupt */
38762306a36Sopenharmony_ciint bnx2x_link_update(struct link_params *params, struct link_vars *vars);
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci/* use the following phy functions to read/write from external_phy
39062306a36Sopenharmony_ci  In order to use it to read/write internal phy registers, use
39162306a36Sopenharmony_ci  DEFAULT_PHY_DEV_ADDR as devad, and (_bank + (_addr & 0xf)) as
39262306a36Sopenharmony_ci  the register */
39362306a36Sopenharmony_ciint bnx2x_phy_read(struct link_params *params, u8 phy_addr,
39462306a36Sopenharmony_ci		   u8 devad, u16 reg, u16 *ret_val);
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ciint bnx2x_phy_write(struct link_params *params, u8 phy_addr,
39762306a36Sopenharmony_ci		    u8 devad, u16 reg, u16 val);
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ci/* Reads the link_status from the shmem,
40062306a36Sopenharmony_ci   and update the link vars accordingly */
40162306a36Sopenharmony_civoid bnx2x_link_status_update(struct link_params *input,
40262306a36Sopenharmony_ci			    struct link_vars *output);
40362306a36Sopenharmony_ci/* returns string representing the fw_version of the external phy */
40462306a36Sopenharmony_ciint bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
40562306a36Sopenharmony_ci				 u16 len);
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci/* Set/Unset the led
40862306a36Sopenharmony_ci   Basically, the CLC takes care of the led for the link, but in case one needs
40962306a36Sopenharmony_ci   to set/unset the led unnaturally, set the "mode" to LED_MODE_OPER to
41062306a36Sopenharmony_ci   blink the led, and LED_MODE_OFF to set the led off.*/
41162306a36Sopenharmony_ciint bnx2x_set_led(struct link_params *params,
41262306a36Sopenharmony_ci		  struct link_vars *vars, u8 mode, u32 speed);
41362306a36Sopenharmony_ci#define LED_MODE_OFF			0
41462306a36Sopenharmony_ci#define LED_MODE_ON			1
41562306a36Sopenharmony_ci#define LED_MODE_OPER			2
41662306a36Sopenharmony_ci#define LED_MODE_FRONT_PANEL_OFF	3
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_ci/* bnx2x_handle_module_detect_int should be called upon module detection
41962306a36Sopenharmony_ci   interrupt */
42062306a36Sopenharmony_civoid bnx2x_handle_module_detect_int(struct link_params *params);
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci/* Get the actual link status. In case it returns 0, link is up,
42362306a36Sopenharmony_ci	otherwise link is down*/
42462306a36Sopenharmony_ciint bnx2x_test_link(struct link_params *params, struct link_vars *vars,
42562306a36Sopenharmony_ci		    u8 is_serdes);
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci/* One-time initialization for external phy after power up */
42862306a36Sopenharmony_ciint bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
42962306a36Sopenharmony_ci			  u32 shmem2_base_path[], u32 chip_id);
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci/* Reset the external PHY using GPIO */
43262306a36Sopenharmony_civoid bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port);
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci/* Reset the external of SFX7101 */
43562306a36Sopenharmony_civoid bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy);
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci/* Read "byte_cnt" bytes from address "addr" from the SFP+ EEPROM */
43862306a36Sopenharmony_ciint bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
43962306a36Sopenharmony_ci				 struct link_params *params, u8 dev_addr,
44062306a36Sopenharmony_ci				 u16 addr, u16 byte_cnt, u8 *o_buf);
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_civoid bnx2x_hw_reset_phy(struct link_params *params);
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci/* Check swap bit and adjust PHY order */
44562306a36Sopenharmony_ciu32 bnx2x_phy_selection(struct link_params *params);
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_ci/* Probe the phys on board, and populate them in "params" */
44862306a36Sopenharmony_ciint bnx2x_phy_probe(struct link_params *params);
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ci/* Checks if fan failure detection is required on one of the phys on board */
45162306a36Sopenharmony_ciu8 bnx2x_fan_failure_det_req(struct bnx2x *bp, u32 shmem_base,
45262306a36Sopenharmony_ci			     u32 shmem2_base, u8 port);
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci/* Open / close the gate between the NIG and the BRB */
45562306a36Sopenharmony_civoid bnx2x_set_rx_filter(struct link_params *params, u8 en);
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci/* DCBX structs */
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci/* Number of maximum COS per chip */
46062306a36Sopenharmony_ci#define DCBX_E2E3_MAX_NUM_COS		(2)
46162306a36Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS_PORT0	(6)
46262306a36Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS_PORT1	(3)
46362306a36Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS		( \
46462306a36Sopenharmony_ci			MAXVAL(DCBX_E3B0_MAX_NUM_COS_PORT0, \
46562306a36Sopenharmony_ci			    DCBX_E3B0_MAX_NUM_COS_PORT1))
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ci#define DCBX_MAX_NUM_COS			( \
46862306a36Sopenharmony_ci			MAXVAL(DCBX_E3B0_MAX_NUM_COS, \
46962306a36Sopenharmony_ci			    DCBX_E2E3_MAX_NUM_COS))
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci/* PFC port configuration params */
47262306a36Sopenharmony_cistruct bnx2x_nig_brb_pfc_port_params {
47362306a36Sopenharmony_ci	/* NIG */
47462306a36Sopenharmony_ci	u32 pause_enable;
47562306a36Sopenharmony_ci	u32 llfc_out_en;
47662306a36Sopenharmony_ci	u32 llfc_enable;
47762306a36Sopenharmony_ci	u32 pkt_priority_to_cos;
47862306a36Sopenharmony_ci	u8 num_of_rx_cos_priority_mask;
47962306a36Sopenharmony_ci	u32 rx_cos_priority_mask[DCBX_MAX_NUM_COS];
48062306a36Sopenharmony_ci	u32 llfc_high_priority_classes;
48162306a36Sopenharmony_ci	u32 llfc_low_priority_classes;
48262306a36Sopenharmony_ci};
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci/* ETS port configuration params */
48662306a36Sopenharmony_cistruct bnx2x_ets_bw_params {
48762306a36Sopenharmony_ci	u8 bw;
48862306a36Sopenharmony_ci};
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_cistruct bnx2x_ets_sp_params {
49162306a36Sopenharmony_ci	/**
49262306a36Sopenharmony_ci	 * valid values are 0 - 5. 0 is highest strict priority.
49362306a36Sopenharmony_ci	 * There can't be two COS's with the same pri.
49462306a36Sopenharmony_ci	 */
49562306a36Sopenharmony_ci	u8 pri;
49662306a36Sopenharmony_ci};
49762306a36Sopenharmony_ci
49862306a36Sopenharmony_cienum bnx2x_cos_state {
49962306a36Sopenharmony_ci	bnx2x_cos_state_strict = 0,
50062306a36Sopenharmony_ci	bnx2x_cos_state_bw = 1,
50162306a36Sopenharmony_ci};
50262306a36Sopenharmony_ci
50362306a36Sopenharmony_cistruct bnx2x_ets_cos_params {
50462306a36Sopenharmony_ci	enum bnx2x_cos_state state ;
50562306a36Sopenharmony_ci	union {
50662306a36Sopenharmony_ci		struct bnx2x_ets_bw_params bw_params;
50762306a36Sopenharmony_ci		struct bnx2x_ets_sp_params sp_params;
50862306a36Sopenharmony_ci	} params;
50962306a36Sopenharmony_ci};
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_cistruct bnx2x_ets_params {
51262306a36Sopenharmony_ci	u8 num_of_cos; /* Number of valid COS entries*/
51362306a36Sopenharmony_ci	struct bnx2x_ets_cos_params cos[DCBX_MAX_NUM_COS];
51462306a36Sopenharmony_ci};
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci/* Used to update the PFC attributes in EMAC, BMAC, NIG and BRB
51762306a36Sopenharmony_ci * when link is already up
51862306a36Sopenharmony_ci */
51962306a36Sopenharmony_ciint bnx2x_update_pfc(struct link_params *params,
52062306a36Sopenharmony_ci		      struct link_vars *vars,
52162306a36Sopenharmony_ci		      struct bnx2x_nig_brb_pfc_port_params *pfc_params);
52262306a36Sopenharmony_ci
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ci/* Used to configure the ETS to disable */
52562306a36Sopenharmony_ciint bnx2x_ets_disabled(struct link_params *params,
52662306a36Sopenharmony_ci		       struct link_vars *vars);
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_ci/* Used to configure the ETS to BW limited */
52962306a36Sopenharmony_civoid bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
53062306a36Sopenharmony_ci			const u32 cos1_bw);
53162306a36Sopenharmony_ci
53262306a36Sopenharmony_ci/* Used to configure the ETS to strict */
53362306a36Sopenharmony_ciint bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos);
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ci
53662306a36Sopenharmony_ci/*  Configure the COS to ETS according to BW and SP settings.*/
53762306a36Sopenharmony_ciint bnx2x_ets_e3b0_config(const struct link_params *params,
53862306a36Sopenharmony_ci			 const struct link_vars *vars,
53962306a36Sopenharmony_ci			 struct bnx2x_ets_params *ets_params);
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_civoid bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
54262306a36Sopenharmony_ci			    u32 chip_id, u32 shmem_base, u32 shmem2_base,
54362306a36Sopenharmony_ci			    u8 port);
54462306a36Sopenharmony_ci
54562306a36Sopenharmony_civoid bnx2x_period_func(struct link_params *params, struct link_vars *vars);
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci#endif /* BNX2X_LINK_H */
548