162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright(c) 2007 - 2018 Intel Corporation. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _E1000_PHY_H_
562306a36Sopenharmony_ci#define _E1000_PHY_H_
662306a36Sopenharmony_ci
762306a36Sopenharmony_cienum e1000_ms_type {
862306a36Sopenharmony_ci	e1000_ms_hw_default = 0,
962306a36Sopenharmony_ci	e1000_ms_force_master,
1062306a36Sopenharmony_ci	e1000_ms_force_slave,
1162306a36Sopenharmony_ci	e1000_ms_auto
1262306a36Sopenharmony_ci};
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cienum e1000_smart_speed {
1562306a36Sopenharmony_ci	e1000_smart_speed_default = 0,
1662306a36Sopenharmony_ci	e1000_smart_speed_on,
1762306a36Sopenharmony_ci	e1000_smart_speed_off
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cis32  igb_check_downshift(struct e1000_hw *hw);
2162306a36Sopenharmony_cis32  igb_check_reset_block(struct e1000_hw *hw);
2262306a36Sopenharmony_cis32  igb_copper_link_setup_igp(struct e1000_hw *hw);
2362306a36Sopenharmony_cis32  igb_copper_link_setup_m88(struct e1000_hw *hw);
2462306a36Sopenharmony_cis32  igb_copper_link_setup_m88_gen2(struct e1000_hw *hw);
2562306a36Sopenharmony_cis32  igb_phy_force_speed_duplex_igp(struct e1000_hw *hw);
2662306a36Sopenharmony_cis32  igb_phy_force_speed_duplex_m88(struct e1000_hw *hw);
2762306a36Sopenharmony_cis32  igb_get_cable_length_m88(struct e1000_hw *hw);
2862306a36Sopenharmony_cis32  igb_get_cable_length_m88_gen2(struct e1000_hw *hw);
2962306a36Sopenharmony_cis32  igb_get_cable_length_igp_2(struct e1000_hw *hw);
3062306a36Sopenharmony_cis32  igb_get_phy_id(struct e1000_hw *hw);
3162306a36Sopenharmony_cis32  igb_get_phy_info_igp(struct e1000_hw *hw);
3262306a36Sopenharmony_cis32  igb_get_phy_info_m88(struct e1000_hw *hw);
3362306a36Sopenharmony_cis32  igb_phy_sw_reset(struct e1000_hw *hw);
3462306a36Sopenharmony_cis32  igb_phy_hw_reset(struct e1000_hw *hw);
3562306a36Sopenharmony_cis32  igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data);
3662306a36Sopenharmony_cis32  igb_set_d3_lplu_state(struct e1000_hw *hw, bool active);
3762306a36Sopenharmony_cis32  igb_setup_copper_link(struct e1000_hw *hw);
3862306a36Sopenharmony_cis32  igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data);
3962306a36Sopenharmony_cis32  igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
4062306a36Sopenharmony_ci				u32 usec_interval, bool *success);
4162306a36Sopenharmony_civoid igb_power_up_phy_copper(struct e1000_hw *hw);
4262306a36Sopenharmony_civoid igb_power_down_phy_copper(struct e1000_hw *hw);
4362306a36Sopenharmony_cis32  igb_phy_init_script_igp3(struct e1000_hw *hw);
4462306a36Sopenharmony_cis32  igb_initialize_M88E1512_phy(struct e1000_hw *hw);
4562306a36Sopenharmony_cis32  igb_initialize_M88E1543_phy(struct e1000_hw *hw);
4662306a36Sopenharmony_cis32  igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data);
4762306a36Sopenharmony_cis32  igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data);
4862306a36Sopenharmony_cis32  igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data);
4962306a36Sopenharmony_cis32  igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data);
5062306a36Sopenharmony_cis32  igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data);
5162306a36Sopenharmony_cis32  igb_copper_link_setup_82580(struct e1000_hw *hw);
5262306a36Sopenharmony_cis32  igb_get_phy_info_82580(struct e1000_hw *hw);
5362306a36Sopenharmony_cis32  igb_phy_force_speed_duplex_82580(struct e1000_hw *hw);
5462306a36Sopenharmony_cis32  igb_get_cable_length_82580(struct e1000_hw *hw);
5562306a36Sopenharmony_cis32  igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data);
5662306a36Sopenharmony_cis32  igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data);
5762306a36Sopenharmony_cis32  igb_check_polarity_m88(struct e1000_hw *hw);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/* IGP01E1000 Specific Registers */
6062306a36Sopenharmony_ci#define IGP01E1000_PHY_PORT_CONFIG        0x10 /* Port Config */
6162306a36Sopenharmony_ci#define IGP01E1000_PHY_PORT_STATUS        0x11 /* Status */
6262306a36Sopenharmony_ci#define IGP01E1000_PHY_PORT_CTRL          0x12 /* Control */
6362306a36Sopenharmony_ci#define IGP01E1000_PHY_LINK_HEALTH        0x13 /* PHY Link Health */
6462306a36Sopenharmony_ci#define IGP02E1000_PHY_POWER_MGMT         0x19 /* Power Management */
6562306a36Sopenharmony_ci#define IGP01E1000_PHY_PAGE_SELECT        0x1F /* Page Select */
6662306a36Sopenharmony_ci#define IGP01E1000_PHY_PCS_INIT_REG       0x00B4
6762306a36Sopenharmony_ci#define IGP01E1000_PHY_POLARITY_MASK      0x0078
6862306a36Sopenharmony_ci#define IGP01E1000_PSCR_AUTO_MDIX         0x1000
6962306a36Sopenharmony_ci#define IGP01E1000_PSCR_FORCE_MDI_MDIX    0x2000 /* 0=MDI, 1=MDIX */
7062306a36Sopenharmony_ci#define IGP01E1000_PSCFR_SMART_SPEED      0x0080
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define I82580_ADDR_REG                   16
7362306a36Sopenharmony_ci#define I82580_CFG_REG                    22
7462306a36Sopenharmony_ci#define I82580_CFG_ASSERT_CRS_ON_TX       BIT(15)
7562306a36Sopenharmony_ci#define I82580_CFG_ENABLE_DOWNSHIFT       (3u << 10) /* auto downshift 100/10 */
7662306a36Sopenharmony_ci#define I82580_CTRL_REG                   23
7762306a36Sopenharmony_ci#define I82580_CTRL_DOWNSHIFT_MASK        (7u << 10)
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/* 82580 specific PHY registers */
8062306a36Sopenharmony_ci#define I82580_PHY_CTRL_2            18
8162306a36Sopenharmony_ci#define I82580_PHY_LBK_CTRL          19
8262306a36Sopenharmony_ci#define I82580_PHY_STATUS_2          26
8362306a36Sopenharmony_ci#define I82580_PHY_DIAG_STATUS       31
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/* I82580 PHY Status 2 */
8662306a36Sopenharmony_ci#define I82580_PHY_STATUS2_REV_POLARITY   0x0400
8762306a36Sopenharmony_ci#define I82580_PHY_STATUS2_MDIX           0x0800
8862306a36Sopenharmony_ci#define I82580_PHY_STATUS2_SPEED_MASK     0x0300
8962306a36Sopenharmony_ci#define I82580_PHY_STATUS2_SPEED_1000MBPS 0x0200
9062306a36Sopenharmony_ci#define I82580_PHY_STATUS2_SPEED_100MBPS  0x0100
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* I82580 PHY Control 2 */
9362306a36Sopenharmony_ci#define I82580_PHY_CTRL2_MANUAL_MDIX      0x0200
9462306a36Sopenharmony_ci#define I82580_PHY_CTRL2_AUTO_MDI_MDIX    0x0400
9562306a36Sopenharmony_ci#define I82580_PHY_CTRL2_MDIX_CFG_MASK    0x0600
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* I82580 PHY Diagnostics Status */
9862306a36Sopenharmony_ci#define I82580_DSTATUS_CABLE_LENGTH       0x03FC
9962306a36Sopenharmony_ci#define I82580_DSTATUS_CABLE_LENGTH_SHIFT 2
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* 82580 PHY Power Management */
10262306a36Sopenharmony_ci#define E1000_82580_PHY_POWER_MGMT	0xE14
10362306a36Sopenharmony_ci#define E1000_82580_PM_SPD		0x0001 /* Smart Power Down */
10462306a36Sopenharmony_ci#define E1000_82580_PM_D0_LPLU		0x0002 /* For D0a states */
10562306a36Sopenharmony_ci#define E1000_82580_PM_D3_LPLU		0x0004 /* For all other states */
10662306a36Sopenharmony_ci#define E1000_82580_PM_GO_LINKD		0x0020 /* Go Link Disconnect */
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* Enable flexible speed on link-up */
10962306a36Sopenharmony_ci#define IGP02E1000_PM_D0_LPLU             0x0002 /* For D0a states */
11062306a36Sopenharmony_ci#define IGP02E1000_PM_D3_LPLU             0x0004 /* For all other states */
11162306a36Sopenharmony_ci#define IGP01E1000_PLHR_SS_DOWNGRADE      0x8000
11262306a36Sopenharmony_ci#define IGP01E1000_PSSR_POLARITY_REVERSED 0x0002
11362306a36Sopenharmony_ci#define IGP01E1000_PSSR_MDIX              0x0800
11462306a36Sopenharmony_ci#define IGP01E1000_PSSR_SPEED_MASK        0xC000
11562306a36Sopenharmony_ci#define IGP01E1000_PSSR_SPEED_1000MBPS    0xC000
11662306a36Sopenharmony_ci#define IGP02E1000_PHY_CHANNEL_NUM        4
11762306a36Sopenharmony_ci#define IGP02E1000_PHY_AGC_A              0x11B1
11862306a36Sopenharmony_ci#define IGP02E1000_PHY_AGC_B              0x12B1
11962306a36Sopenharmony_ci#define IGP02E1000_PHY_AGC_C              0x14B1
12062306a36Sopenharmony_ci#define IGP02E1000_PHY_AGC_D              0x18B1
12162306a36Sopenharmony_ci#define IGP02E1000_AGC_LENGTH_SHIFT       9   /* Course - 15:13, Fine - 12:9 */
12262306a36Sopenharmony_ci#define IGP02E1000_AGC_LENGTH_MASK        0x7F
12362306a36Sopenharmony_ci#define IGP02E1000_AGC_RANGE              15
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#define E1000_CABLE_LENGTH_UNDEFINED      0xFF
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/* SFP modules ID memory locations */
12862306a36Sopenharmony_ci#define E1000_SFF_IDENTIFIER_OFFSET	0x00
12962306a36Sopenharmony_ci#define E1000_SFF_IDENTIFIER_SFF	0x02
13062306a36Sopenharmony_ci#define E1000_SFF_IDENTIFIER_SFP	0x03
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define E1000_SFF_ETH_FLAGS_OFFSET	0x06
13362306a36Sopenharmony_ci/* Flags for SFP modules compatible with ETH up to 1Gb */
13462306a36Sopenharmony_cistruct e1000_sfp_flags {
13562306a36Sopenharmony_ci	u8 e1000_base_sx:1;
13662306a36Sopenharmony_ci	u8 e1000_base_lx:1;
13762306a36Sopenharmony_ci	u8 e1000_base_cx:1;
13862306a36Sopenharmony_ci	u8 e1000_base_t:1;
13962306a36Sopenharmony_ci	u8 e100_base_lx:1;
14062306a36Sopenharmony_ci	u8 e100_base_fx:1;
14162306a36Sopenharmony_ci	u8 e10_base_bx10:1;
14262306a36Sopenharmony_ci	u8 e10_base_px:1;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#endif
146