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#ifndef BNX2X_LINK_H
208c2ecf20Sopenharmony_ci#define BNX2X_LINK_H
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/***********************************************************/
258c2ecf20Sopenharmony_ci/*                         Defines                         */
268c2ecf20Sopenharmony_ci/***********************************************************/
278c2ecf20Sopenharmony_ci#define DEFAULT_PHY_DEV_ADDR	3
288c2ecf20Sopenharmony_ci#define E2_DEFAULT_PHY_DEV_ADDR	5
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define BNX2X_FLOW_CTRL_AUTO		PORT_FEATURE_FLOW_CONTROL_AUTO
338c2ecf20Sopenharmony_ci#define BNX2X_FLOW_CTRL_TX		PORT_FEATURE_FLOW_CONTROL_TX
348c2ecf20Sopenharmony_ci#define BNX2X_FLOW_CTRL_RX		PORT_FEATURE_FLOW_CONTROL_RX
358c2ecf20Sopenharmony_ci#define BNX2X_FLOW_CTRL_BOTH		PORT_FEATURE_FLOW_CONTROL_BOTH
368c2ecf20Sopenharmony_ci#define BNX2X_FLOW_CTRL_NONE		PORT_FEATURE_FLOW_CONTROL_NONE
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define NET_SERDES_IF_XFI		1
398c2ecf20Sopenharmony_ci#define NET_SERDES_IF_SFI		2
408c2ecf20Sopenharmony_ci#define NET_SERDES_IF_KR		3
418c2ecf20Sopenharmony_ci#define NET_SERDES_IF_DXGXS	4
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define SPEED_AUTO_NEG		0
448c2ecf20Sopenharmony_ci#define SPEED_20000		20000
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define I2C_DEV_ADDR_A0			0xa0
478c2ecf20Sopenharmony_ci#define I2C_DEV_ADDR_A2			0xa2
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define SFP_EEPROM_PAGE_SIZE			16
508c2ecf20Sopenharmony_ci#define SFP_EEPROM_VENDOR_NAME_ADDR		0x14
518c2ecf20Sopenharmony_ci#define SFP_EEPROM_VENDOR_NAME_SIZE		16
528c2ecf20Sopenharmony_ci#define SFP_EEPROM_VENDOR_OUI_ADDR		0x25
538c2ecf20Sopenharmony_ci#define SFP_EEPROM_VENDOR_OUI_SIZE		3
548c2ecf20Sopenharmony_ci#define SFP_EEPROM_PART_NO_ADDR			0x28
558c2ecf20Sopenharmony_ci#define SFP_EEPROM_PART_NO_SIZE			16
568c2ecf20Sopenharmony_ci#define SFP_EEPROM_REVISION_ADDR		0x38
578c2ecf20Sopenharmony_ci#define SFP_EEPROM_REVISION_SIZE		4
588c2ecf20Sopenharmony_ci#define SFP_EEPROM_SERIAL_ADDR			0x44
598c2ecf20Sopenharmony_ci#define SFP_EEPROM_SERIAL_SIZE			16
608c2ecf20Sopenharmony_ci#define SFP_EEPROM_DATE_ADDR			0x54 /* ASCII YYMMDD */
618c2ecf20Sopenharmony_ci#define SFP_EEPROM_DATE_SIZE			6
628c2ecf20Sopenharmony_ci#define SFP_EEPROM_DIAG_TYPE_ADDR		0x5c
638c2ecf20Sopenharmony_ci#define SFP_EEPROM_DIAG_TYPE_SIZE		1
648c2ecf20Sopenharmony_ci#define SFP_EEPROM_DIAG_ADDR_CHANGE_REQ		(1<<2)
658c2ecf20Sopenharmony_ci#define SFP_EEPROM_DDM_IMPLEMENTED		(1<<6)
668c2ecf20Sopenharmony_ci#define SFP_EEPROM_SFF_8472_COMP_ADDR		0x5e
678c2ecf20Sopenharmony_ci#define SFP_EEPROM_SFF_8472_COMP_SIZE		1
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define SFP_EEPROM_A2_CHECKSUM_RANGE		0x5e
708c2ecf20Sopenharmony_ci#define SFP_EEPROM_A2_CC_DMI_ADDR		0x5f
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define PWR_FLT_ERR_MSG_LEN			250
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define XGXS_EXT_PHY_TYPE(ext_phy_config) \
758c2ecf20Sopenharmony_ci		((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK)
768c2ecf20Sopenharmony_ci#define XGXS_EXT_PHY_ADDR(ext_phy_config) \
778c2ecf20Sopenharmony_ci		(((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK) >> \
788c2ecf20Sopenharmony_ci		 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT)
798c2ecf20Sopenharmony_ci#define SERDES_EXT_PHY_TYPE(ext_phy_config) \
808c2ecf20Sopenharmony_ci		((ext_phy_config) & PORT_HW_CFG_SERDES_EXT_PHY_TYPE_MASK)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* Single Media Direct board is the plain 577xx board with CX4/RJ45 jacks */
838c2ecf20Sopenharmony_ci#define SINGLE_MEDIA_DIRECT(params)	(params->num_phys == 1)
848c2ecf20Sopenharmony_ci/* Single Media board contains single external phy */
858c2ecf20Sopenharmony_ci#define SINGLE_MEDIA(params)		(params->num_phys == 2)
868c2ecf20Sopenharmony_ci/* Dual Media board contains two external phy with different media */
878c2ecf20Sopenharmony_ci#define DUAL_MEDIA(params)		(params->num_phys == 3)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define FW_PARAM_PHY_ADDR_MASK		0x000000FF
908c2ecf20Sopenharmony_ci#define FW_PARAM_PHY_TYPE_MASK		0x0000FF00
918c2ecf20Sopenharmony_ci#define FW_PARAM_MDIO_CTRL_MASK		0xFFFF0000
928c2ecf20Sopenharmony_ci#define FW_PARAM_MDIO_CTRL_OFFSET		16
938c2ecf20Sopenharmony_ci#define FW_PARAM_PHY_ADDR(fw_param) (fw_param & \
948c2ecf20Sopenharmony_ci					   FW_PARAM_PHY_ADDR_MASK)
958c2ecf20Sopenharmony_ci#define FW_PARAM_PHY_TYPE(fw_param) (fw_param & \
968c2ecf20Sopenharmony_ci					   FW_PARAM_PHY_TYPE_MASK)
978c2ecf20Sopenharmony_ci#define FW_PARAM_MDIO_CTRL(fw_param) ((fw_param & \
988c2ecf20Sopenharmony_ci					    FW_PARAM_MDIO_CTRL_MASK) >> \
998c2ecf20Sopenharmony_ci					    FW_PARAM_MDIO_CTRL_OFFSET)
1008c2ecf20Sopenharmony_ci#define FW_PARAM_SET(phy_addr, phy_type, mdio_access) \
1018c2ecf20Sopenharmony_ci	(phy_addr | phy_type | mdio_access << FW_PARAM_MDIO_CTRL_OFFSET)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define PFC_BRB_FULL_LB_XOFF_THRESHOLD				170
1058c2ecf20Sopenharmony_ci#define PFC_BRB_FULL_LB_XON_THRESHOLD				250
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define MAXVAL(a, b) (((a) > (b)) ? (a) : (b))
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define BMAC_CONTROL_RX_ENABLE		2
1108c2ecf20Sopenharmony_ci/***********************************************************/
1118c2ecf20Sopenharmony_ci/*                         Structs                         */
1128c2ecf20Sopenharmony_ci/***********************************************************/
1138c2ecf20Sopenharmony_ci#define INT_PHY		0
1148c2ecf20Sopenharmony_ci#define EXT_PHY1	1
1158c2ecf20Sopenharmony_ci#define EXT_PHY2	2
1168c2ecf20Sopenharmony_ci#define MAX_PHYS	3
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* Same configuration is shared between the XGXS and the first external phy */
1198c2ecf20Sopenharmony_ci#define LINK_CONFIG_SIZE (MAX_PHYS - 1)
1208c2ecf20Sopenharmony_ci#define LINK_CONFIG_IDX(_phy_idx) ((_phy_idx == INT_PHY) ? \
1218c2ecf20Sopenharmony_ci					 0 : (_phy_idx - 1))
1228c2ecf20Sopenharmony_ci/***********************************************************/
1238c2ecf20Sopenharmony_ci/*                      bnx2x_phy struct                     */
1248c2ecf20Sopenharmony_ci/*  Defines the required arguments and function per phy    */
1258c2ecf20Sopenharmony_ci/***********************************************************/
1268c2ecf20Sopenharmony_cistruct link_vars;
1278c2ecf20Sopenharmony_cistruct link_params;
1288c2ecf20Sopenharmony_cistruct bnx2x_phy;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_citypedef void (*config_init_t)(struct bnx2x_phy *phy, struct link_params *params,
1318c2ecf20Sopenharmony_ci			      struct link_vars *vars);
1328c2ecf20Sopenharmony_citypedef u8 (*read_status_t)(struct bnx2x_phy *phy, struct link_params *params,
1338c2ecf20Sopenharmony_ci			    struct link_vars *vars);
1348c2ecf20Sopenharmony_citypedef void (*link_reset_t)(struct bnx2x_phy *phy,
1358c2ecf20Sopenharmony_ci			     struct link_params *params);
1368c2ecf20Sopenharmony_citypedef void (*config_loopback_t)(struct bnx2x_phy *phy,
1378c2ecf20Sopenharmony_ci				  struct link_params *params);
1388c2ecf20Sopenharmony_citypedef int (*format_fw_ver_t)(u32 raw, u8 *str, u16 *len);
1398c2ecf20Sopenharmony_citypedef void (*hw_reset_t)(struct bnx2x_phy *phy, struct link_params *params);
1408c2ecf20Sopenharmony_citypedef void (*set_link_led_t)(struct bnx2x_phy *phy,
1418c2ecf20Sopenharmony_ci			       struct link_params *params, u8 mode);
1428c2ecf20Sopenharmony_citypedef void (*phy_specific_func_t)(struct bnx2x_phy *phy,
1438c2ecf20Sopenharmony_ci				    struct link_params *params, u32 action);
1448c2ecf20Sopenharmony_cistruct bnx2x_reg_set {
1458c2ecf20Sopenharmony_ci	u8  devad;
1468c2ecf20Sopenharmony_ci	u16 reg;
1478c2ecf20Sopenharmony_ci	u16 val;
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistruct bnx2x_phy {
1518c2ecf20Sopenharmony_ci	u32 type;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/* Loaded during init */
1548c2ecf20Sopenharmony_ci	u8 addr;
1558c2ecf20Sopenharmony_ci	u8 def_md_devad;
1568c2ecf20Sopenharmony_ci	u16 flags;
1578c2ecf20Sopenharmony_ci	/* No Over-Current detection */
1588c2ecf20Sopenharmony_ci#define FLAGS_NOC			(1<<1)
1598c2ecf20Sopenharmony_ci	/* Fan failure detection required */
1608c2ecf20Sopenharmony_ci#define FLAGS_FAN_FAILURE_DET_REQ	(1<<2)
1618c2ecf20Sopenharmony_ci	/* Initialize first the XGXS and only then the phy itself */
1628c2ecf20Sopenharmony_ci#define FLAGS_INIT_XGXS_FIRST		(1<<3)
1638c2ecf20Sopenharmony_ci#define FLAGS_WC_DUAL_MODE		(1<<4)
1648c2ecf20Sopenharmony_ci#define FLAGS_4_PORT_MODE		(1<<5)
1658c2ecf20Sopenharmony_ci#define FLAGS_REARM_LATCH_SIGNAL	(1<<6)
1668c2ecf20Sopenharmony_ci#define FLAGS_SFP_NOT_APPROVED		(1<<7)
1678c2ecf20Sopenharmony_ci#define FLAGS_MDC_MDIO_WA		(1<<8)
1688c2ecf20Sopenharmony_ci#define FLAGS_DUMMY_READ		(1<<9)
1698c2ecf20Sopenharmony_ci#define FLAGS_MDC_MDIO_WA_B0		(1<<10)
1708c2ecf20Sopenharmony_ci#define FLAGS_TX_ERROR_CHECK		(1<<12)
1718c2ecf20Sopenharmony_ci#define FLAGS_EEE			(1<<13)
1728c2ecf20Sopenharmony_ci#define FLAGS_MDC_MDIO_WA_G		(1<<15)
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	/* preemphasis values for the rx side */
1758c2ecf20Sopenharmony_ci	u16 rx_preemphasis[4];
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	/* preemphasis values for the tx side */
1788c2ecf20Sopenharmony_ci	u16 tx_preemphasis[4];
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	/* EMAC address for access MDIO */
1818c2ecf20Sopenharmony_ci	u32 mdio_ctrl;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	u32 supported;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	u32 media_type;
1868c2ecf20Sopenharmony_ci#define	ETH_PHY_UNSPECIFIED	0x0
1878c2ecf20Sopenharmony_ci#define	ETH_PHY_SFPP_10G_FIBER	0x1
1888c2ecf20Sopenharmony_ci#define	ETH_PHY_XFP_FIBER		0x2
1898c2ecf20Sopenharmony_ci#define	ETH_PHY_DA_TWINAX		0x3
1908c2ecf20Sopenharmony_ci#define	ETH_PHY_BASE_T		0x4
1918c2ecf20Sopenharmony_ci#define	ETH_PHY_SFP_1G_FIBER	0x5
1928c2ecf20Sopenharmony_ci#define	ETH_PHY_KR		0xf0
1938c2ecf20Sopenharmony_ci#define	ETH_PHY_CX4		0xf1
1948c2ecf20Sopenharmony_ci#define	ETH_PHY_NOT_PRESENT	0xff
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	/* The address in which version is located*/
1978c2ecf20Sopenharmony_ci	u32 ver_addr;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	u16 req_flow_ctrl;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	u16 req_line_speed;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	u32 speed_cap_mask;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	u16 req_duplex;
2068c2ecf20Sopenharmony_ci	u16 rsrv;
2078c2ecf20Sopenharmony_ci	/* Called per phy/port init, and it configures LASI, speed, autoneg,
2088c2ecf20Sopenharmony_ci	 duplex, flow control negotiation, etc. */
2098c2ecf20Sopenharmony_ci	config_init_t config_init;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	/* Called due to interrupt. It determines the link, speed */
2128c2ecf20Sopenharmony_ci	read_status_t read_status;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	/* Called when driver is unloading. Should reset the phy */
2158c2ecf20Sopenharmony_ci	link_reset_t link_reset;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	/* Set the loopback configuration for the phy */
2188c2ecf20Sopenharmony_ci	config_loopback_t config_loopback;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* Format the given raw number into str up to len */
2218c2ecf20Sopenharmony_ci	format_fw_ver_t format_fw_ver;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	/* Reset the phy (both ports) */
2248c2ecf20Sopenharmony_ci	hw_reset_t hw_reset;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	/* Set link led mode (on/off/oper)*/
2278c2ecf20Sopenharmony_ci	set_link_led_t set_link_led;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	/* PHY Specific tasks */
2308c2ecf20Sopenharmony_ci	phy_specific_func_t phy_specific_func;
2318c2ecf20Sopenharmony_ci#define DISABLE_TX	1
2328c2ecf20Sopenharmony_ci#define ENABLE_TX	2
2338c2ecf20Sopenharmony_ci#define PHY_INIT	3
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci/* Inputs parameters to the CLC */
2378c2ecf20Sopenharmony_cistruct link_params {
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	u8 port;
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	/* Default / User Configuration */
2428c2ecf20Sopenharmony_ci	u8 loopback_mode;
2438c2ecf20Sopenharmony_ci#define LOOPBACK_NONE		0
2448c2ecf20Sopenharmony_ci#define LOOPBACK_EMAC		1
2458c2ecf20Sopenharmony_ci#define LOOPBACK_BMAC		2
2468c2ecf20Sopenharmony_ci#define LOOPBACK_XGXS		3
2478c2ecf20Sopenharmony_ci#define LOOPBACK_EXT_PHY	4
2488c2ecf20Sopenharmony_ci#define LOOPBACK_EXT		5
2498c2ecf20Sopenharmony_ci#define LOOPBACK_UMAC		6
2508c2ecf20Sopenharmony_ci#define LOOPBACK_XMAC		7
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	/* Device parameters */
2538c2ecf20Sopenharmony_ci	u8 mac_addr[6];
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	u16 req_duplex[LINK_CONFIG_SIZE];
2568c2ecf20Sopenharmony_ci	u16 req_flow_ctrl[LINK_CONFIG_SIZE];
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	u16 req_line_speed[LINK_CONFIG_SIZE]; /* Also determine AutoNeg */
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	/* shmem parameters */
2618c2ecf20Sopenharmony_ci	u32 shmem_base;
2628c2ecf20Sopenharmony_ci	u32 shmem2_base;
2638c2ecf20Sopenharmony_ci	u32 speed_cap_mask[LINK_CONFIG_SIZE];
2648c2ecf20Sopenharmony_ci	u32 switch_cfg;
2658c2ecf20Sopenharmony_ci#define SWITCH_CFG_1G		PORT_FEATURE_CON_SWITCH_1G_SWITCH
2668c2ecf20Sopenharmony_ci#define SWITCH_CFG_10G		PORT_FEATURE_CON_SWITCH_10G_SWITCH
2678c2ecf20Sopenharmony_ci#define SWITCH_CFG_AUTO_DETECT	PORT_FEATURE_CON_SWITCH_AUTO_DETECT
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	u32 lane_config;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	/* Phy register parameter */
2728c2ecf20Sopenharmony_ci	u32 chip_id;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	/* features */
2758c2ecf20Sopenharmony_ci	u32 feature_config_flags;
2768c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED	(1<<0)
2778c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_PFC_ENABLED			(1<<1)
2788c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY		(1<<2)
2798c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY	(1<<3)
2808c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_AFEX			(1<<8)
2818c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_AUTOGREEEN_ENABLED			(1<<9)
2828c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED		(1<<10)
2838c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET		(1<<11)
2848c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_MT_SUPPORT			(1<<13)
2858c2ecf20Sopenharmony_ci#define FEATURE_CONFIG_BOOT_FROM_SAN			(1<<14)
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	/* Will be populated during common init */
2888c2ecf20Sopenharmony_ci	struct bnx2x_phy phy[MAX_PHYS];
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	/* Will be populated during common init */
2918c2ecf20Sopenharmony_ci	u8 num_phys;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	u8 rsrv;
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	/* Used to configure the EEE Tx LPI timer, has several modes of
2968c2ecf20Sopenharmony_ci	 * operation, according to bits 29:28 -
2978c2ecf20Sopenharmony_ci	 * 2'b00: Timer will be configured by nvram, output will be the value
2988c2ecf20Sopenharmony_ci	 *        from nvram.
2998c2ecf20Sopenharmony_ci	 * 2'b01: Timer will be configured by nvram, output will be in
3008c2ecf20Sopenharmony_ci	 *        microseconds.
3018c2ecf20Sopenharmony_ci	 * 2'b10: bits 1:0 contain an nvram value which will be used instead
3028c2ecf20Sopenharmony_ci	 *        of the one located in the nvram. Output will be that value.
3038c2ecf20Sopenharmony_ci	 * 2'b11: bits 19:0 contain the idle timer in microseconds; output
3048c2ecf20Sopenharmony_ci	 *        will be in microseconds.
3058c2ecf20Sopenharmony_ci	 * Bits 31:30 should be 2'b11 in order for EEE to be enabled.
3068c2ecf20Sopenharmony_ci	 */
3078c2ecf20Sopenharmony_ci	u32 eee_mode;
3088c2ecf20Sopenharmony_ci#define EEE_MODE_NVRAM_BALANCED_TIME		(0xa00)
3098c2ecf20Sopenharmony_ci#define EEE_MODE_NVRAM_AGGRESSIVE_TIME		(0x100)
3108c2ecf20Sopenharmony_ci#define EEE_MODE_NVRAM_LATENCY_TIME		(0x6000)
3118c2ecf20Sopenharmony_ci#define EEE_MODE_NVRAM_MASK		(0x3)
3128c2ecf20Sopenharmony_ci#define EEE_MODE_TIMER_MASK		(0xfffff)
3138c2ecf20Sopenharmony_ci#define EEE_MODE_OUTPUT_TIME		(1<<28)
3148c2ecf20Sopenharmony_ci#define EEE_MODE_OVERRIDE_NVRAM		(1<<29)
3158c2ecf20Sopenharmony_ci#define EEE_MODE_ENABLE_LPI		(1<<30)
3168c2ecf20Sopenharmony_ci#define EEE_MODE_ADV_LPI			(1<<31)
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	u16 hw_led_mode; /* part of the hw_config read from the shmem */
3198c2ecf20Sopenharmony_ci	u32 multi_phy_config;
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	/* Device pointer passed to all callback functions */
3228c2ecf20Sopenharmony_ci	struct bnx2x *bp;
3238c2ecf20Sopenharmony_ci	u16 req_fc_auto_adv; /* Should be set to TX / BOTH when
3248c2ecf20Sopenharmony_ci				req_flow_ctrl is set to AUTO */
3258c2ecf20Sopenharmony_ci	u16 link_flags;
3268c2ecf20Sopenharmony_ci#define LINK_FLAGS_INT_DISABLED		(1<<0)
3278c2ecf20Sopenharmony_ci#define PHY_INITIALIZED		(1<<1)
3288c2ecf20Sopenharmony_ci	u32 lfa_base;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	/* The same definitions as the shmem2 parameter */
3318c2ecf20Sopenharmony_ci	u32 link_attr_sync;
3328c2ecf20Sopenharmony_ci};
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci/* Output parameters */
3358c2ecf20Sopenharmony_cistruct link_vars {
3368c2ecf20Sopenharmony_ci	u8 phy_flags;
3378c2ecf20Sopenharmony_ci#define PHY_XGXS_FLAG			(1<<0)
3388c2ecf20Sopenharmony_ci#define PHY_SGMII_FLAG			(1<<1)
3398c2ecf20Sopenharmony_ci#define PHY_PHYSICAL_LINK_FLAG		(1<<2)
3408c2ecf20Sopenharmony_ci#define PHY_HALF_OPEN_CONN_FLAG		(1<<3)
3418c2ecf20Sopenharmony_ci#define PHY_OVER_CURRENT_FLAG		(1<<4)
3428c2ecf20Sopenharmony_ci#define PHY_SFP_TX_FAULT_FLAG		(1<<5)
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	u8 mac_type;
3458c2ecf20Sopenharmony_ci#define MAC_TYPE_NONE		0
3468c2ecf20Sopenharmony_ci#define MAC_TYPE_EMAC		1
3478c2ecf20Sopenharmony_ci#define MAC_TYPE_BMAC		2
3488c2ecf20Sopenharmony_ci#define MAC_TYPE_UMAC		3
3498c2ecf20Sopenharmony_ci#define MAC_TYPE_XMAC		4
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	u8 phy_link_up; /* internal phy link indication */
3528c2ecf20Sopenharmony_ci	u8 link_up;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	u16 line_speed;
3558c2ecf20Sopenharmony_ci	u16 duplex;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	u16 flow_ctrl;
3588c2ecf20Sopenharmony_ci	u16 ieee_fc;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* The same definitions as the shmem parameter */
3618c2ecf20Sopenharmony_ci	u32 link_status;
3628c2ecf20Sopenharmony_ci	u32 eee_status;
3638c2ecf20Sopenharmony_ci	u8 fault_detected;
3648c2ecf20Sopenharmony_ci	u8 check_kr2_recovery_cnt;
3658c2ecf20Sopenharmony_ci#define CHECK_KR2_RECOVERY_CNT	5
3668c2ecf20Sopenharmony_ci	u16 periodic_flags;
3678c2ecf20Sopenharmony_ci#define PERIODIC_FLAGS_LINK_EVENT	0x0001
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	u32 aeu_int_mask;
3708c2ecf20Sopenharmony_ci	u8 rx_tx_asic_rst;
3718c2ecf20Sopenharmony_ci	u8 turn_to_run_wc_rt;
3728c2ecf20Sopenharmony_ci	u16 rsrv2;
3738c2ecf20Sopenharmony_ci};
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci/***********************************************************/
3768c2ecf20Sopenharmony_ci/*                         Functions                       */
3778c2ecf20Sopenharmony_ci/***********************************************************/
3788c2ecf20Sopenharmony_ciint bnx2x_phy_init(struct link_params *params, struct link_vars *vars);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/* Reset the link. Should be called when driver or interface goes down
3818c2ecf20Sopenharmony_ci   Before calling phy firmware upgrade, the reset_ext_phy should be set
3828c2ecf20Sopenharmony_ci   to 0 */
3838c2ecf20Sopenharmony_ciint bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
3848c2ecf20Sopenharmony_ci		     u8 reset_ext_phy);
3858c2ecf20Sopenharmony_ciint bnx2x_lfa_reset(struct link_params *params, struct link_vars *vars);
3868c2ecf20Sopenharmony_ci/* bnx2x_link_update should be called upon link interrupt */
3878c2ecf20Sopenharmony_ciint bnx2x_link_update(struct link_params *params, struct link_vars *vars);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/* use the following phy functions to read/write from external_phy
3908c2ecf20Sopenharmony_ci  In order to use it to read/write internal phy registers, use
3918c2ecf20Sopenharmony_ci  DEFAULT_PHY_DEV_ADDR as devad, and (_bank + (_addr & 0xf)) as
3928c2ecf20Sopenharmony_ci  the register */
3938c2ecf20Sopenharmony_ciint bnx2x_phy_read(struct link_params *params, u8 phy_addr,
3948c2ecf20Sopenharmony_ci		   u8 devad, u16 reg, u16 *ret_val);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ciint bnx2x_phy_write(struct link_params *params, u8 phy_addr,
3978c2ecf20Sopenharmony_ci		    u8 devad, u16 reg, u16 val);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci/* Reads the link_status from the shmem,
4008c2ecf20Sopenharmony_ci   and update the link vars accordingly */
4018c2ecf20Sopenharmony_civoid bnx2x_link_status_update(struct link_params *input,
4028c2ecf20Sopenharmony_ci			    struct link_vars *output);
4038c2ecf20Sopenharmony_ci/* returns string representing the fw_version of the external phy */
4048c2ecf20Sopenharmony_ciint bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
4058c2ecf20Sopenharmony_ci				 u16 len);
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci/* Set/Unset the led
4088c2ecf20Sopenharmony_ci   Basically, the CLC takes care of the led for the link, but in case one needs
4098c2ecf20Sopenharmony_ci   to set/unset the led unnaturally, set the "mode" to LED_MODE_OPER to
4108c2ecf20Sopenharmony_ci   blink the led, and LED_MODE_OFF to set the led off.*/
4118c2ecf20Sopenharmony_ciint bnx2x_set_led(struct link_params *params,
4128c2ecf20Sopenharmony_ci		  struct link_vars *vars, u8 mode, u32 speed);
4138c2ecf20Sopenharmony_ci#define LED_MODE_OFF			0
4148c2ecf20Sopenharmony_ci#define LED_MODE_ON			1
4158c2ecf20Sopenharmony_ci#define LED_MODE_OPER			2
4168c2ecf20Sopenharmony_ci#define LED_MODE_FRONT_PANEL_OFF	3
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci/* bnx2x_handle_module_detect_int should be called upon module detection
4198c2ecf20Sopenharmony_ci   interrupt */
4208c2ecf20Sopenharmony_civoid bnx2x_handle_module_detect_int(struct link_params *params);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci/* Get the actual link status. In case it returns 0, link is up,
4238c2ecf20Sopenharmony_ci	otherwise link is down*/
4248c2ecf20Sopenharmony_ciint bnx2x_test_link(struct link_params *params, struct link_vars *vars,
4258c2ecf20Sopenharmony_ci		    u8 is_serdes);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci/* One-time initialization for external phy after power up */
4288c2ecf20Sopenharmony_ciint bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
4298c2ecf20Sopenharmony_ci			  u32 shmem2_base_path[], u32 chip_id);
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/* Reset the external PHY using GPIO */
4328c2ecf20Sopenharmony_civoid bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port);
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci/* Reset the external of SFX7101 */
4358c2ecf20Sopenharmony_civoid bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci/* Read "byte_cnt" bytes from address "addr" from the SFP+ EEPROM */
4388c2ecf20Sopenharmony_ciint bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4398c2ecf20Sopenharmony_ci				 struct link_params *params, u8 dev_addr,
4408c2ecf20Sopenharmony_ci				 u16 addr, u16 byte_cnt, u8 *o_buf);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_civoid bnx2x_hw_reset_phy(struct link_params *params);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci/* Check swap bit and adjust PHY order */
4458c2ecf20Sopenharmony_ciu32 bnx2x_phy_selection(struct link_params *params);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/* Probe the phys on board, and populate them in "params" */
4488c2ecf20Sopenharmony_ciint bnx2x_phy_probe(struct link_params *params);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/* Checks if fan failure detection is required on one of the phys on board */
4518c2ecf20Sopenharmony_ciu8 bnx2x_fan_failure_det_req(struct bnx2x *bp, u32 shmem_base,
4528c2ecf20Sopenharmony_ci			     u32 shmem2_base, u8 port);
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci/* Open / close the gate between the NIG and the BRB */
4558c2ecf20Sopenharmony_civoid bnx2x_set_rx_filter(struct link_params *params, u8 en);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci/* DCBX structs */
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci/* Number of maximum COS per chip */
4608c2ecf20Sopenharmony_ci#define DCBX_E2E3_MAX_NUM_COS		(2)
4618c2ecf20Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS_PORT0	(6)
4628c2ecf20Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS_PORT1	(3)
4638c2ecf20Sopenharmony_ci#define DCBX_E3B0_MAX_NUM_COS		( \
4648c2ecf20Sopenharmony_ci			MAXVAL(DCBX_E3B0_MAX_NUM_COS_PORT0, \
4658c2ecf20Sopenharmony_ci			    DCBX_E3B0_MAX_NUM_COS_PORT1))
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci#define DCBX_MAX_NUM_COS			( \
4688c2ecf20Sopenharmony_ci			MAXVAL(DCBX_E3B0_MAX_NUM_COS, \
4698c2ecf20Sopenharmony_ci			    DCBX_E2E3_MAX_NUM_COS))
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci/* PFC port configuration params */
4728c2ecf20Sopenharmony_cistruct bnx2x_nig_brb_pfc_port_params {
4738c2ecf20Sopenharmony_ci	/* NIG */
4748c2ecf20Sopenharmony_ci	u32 pause_enable;
4758c2ecf20Sopenharmony_ci	u32 llfc_out_en;
4768c2ecf20Sopenharmony_ci	u32 llfc_enable;
4778c2ecf20Sopenharmony_ci	u32 pkt_priority_to_cos;
4788c2ecf20Sopenharmony_ci	u8 num_of_rx_cos_priority_mask;
4798c2ecf20Sopenharmony_ci	u32 rx_cos_priority_mask[DCBX_MAX_NUM_COS];
4808c2ecf20Sopenharmony_ci	u32 llfc_high_priority_classes;
4818c2ecf20Sopenharmony_ci	u32 llfc_low_priority_classes;
4828c2ecf20Sopenharmony_ci};
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/* ETS port configuration params */
4868c2ecf20Sopenharmony_cistruct bnx2x_ets_bw_params {
4878c2ecf20Sopenharmony_ci	u8 bw;
4888c2ecf20Sopenharmony_ci};
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_cistruct bnx2x_ets_sp_params {
4918c2ecf20Sopenharmony_ci	/**
4928c2ecf20Sopenharmony_ci	 * valid values are 0 - 5. 0 is highest strict priority.
4938c2ecf20Sopenharmony_ci	 * There can't be two COS's with the same pri.
4948c2ecf20Sopenharmony_ci	 */
4958c2ecf20Sopenharmony_ci	u8 pri;
4968c2ecf20Sopenharmony_ci};
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_cienum bnx2x_cos_state {
4998c2ecf20Sopenharmony_ci	bnx2x_cos_state_strict = 0,
5008c2ecf20Sopenharmony_ci	bnx2x_cos_state_bw = 1,
5018c2ecf20Sopenharmony_ci};
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_cistruct bnx2x_ets_cos_params {
5048c2ecf20Sopenharmony_ci	enum bnx2x_cos_state state ;
5058c2ecf20Sopenharmony_ci	union {
5068c2ecf20Sopenharmony_ci		struct bnx2x_ets_bw_params bw_params;
5078c2ecf20Sopenharmony_ci		struct bnx2x_ets_sp_params sp_params;
5088c2ecf20Sopenharmony_ci	} params;
5098c2ecf20Sopenharmony_ci};
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_cistruct bnx2x_ets_params {
5128c2ecf20Sopenharmony_ci	u8 num_of_cos; /* Number of valid COS entries*/
5138c2ecf20Sopenharmony_ci	struct bnx2x_ets_cos_params cos[DCBX_MAX_NUM_COS];
5148c2ecf20Sopenharmony_ci};
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci/* Used to update the PFC attributes in EMAC, BMAC, NIG and BRB
5178c2ecf20Sopenharmony_ci * when link is already up
5188c2ecf20Sopenharmony_ci */
5198c2ecf20Sopenharmony_ciint bnx2x_update_pfc(struct link_params *params,
5208c2ecf20Sopenharmony_ci		      struct link_vars *vars,
5218c2ecf20Sopenharmony_ci		      struct bnx2x_nig_brb_pfc_port_params *pfc_params);
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci/* Used to configure the ETS to disable */
5258c2ecf20Sopenharmony_ciint bnx2x_ets_disabled(struct link_params *params,
5268c2ecf20Sopenharmony_ci		       struct link_vars *vars);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci/* Used to configure the ETS to BW limited */
5298c2ecf20Sopenharmony_civoid bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
5308c2ecf20Sopenharmony_ci			const u32 cos1_bw);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci/* Used to configure the ETS to strict */
5338c2ecf20Sopenharmony_ciint bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos);
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci/*  Configure the COS to ETS according to BW and SP settings.*/
5378c2ecf20Sopenharmony_ciint bnx2x_ets_e3b0_config(const struct link_params *params,
5388c2ecf20Sopenharmony_ci			 const struct link_vars *vars,
5398c2ecf20Sopenharmony_ci			 struct bnx2x_ets_params *ets_params);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_civoid bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
5428c2ecf20Sopenharmony_ci			    u32 chip_id, u32 shmem_base, u32 shmem2_base,
5438c2ecf20Sopenharmony_ci			    u8 port);
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_civoid bnx2x_period_func(struct link_params *params, struct link_vars *vars);
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci#endif /* BNX2X_LINK_H */
548