⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e1000_phy.c

📁 Intel 82546系列lan driver源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		/*		 * PHY will be set to 10H, 10F, 100H or 100F		 * depending on user settings.		 */		e_dbg("Forcing Speed and Duplex\n");		ret_val = hw->phy.ops.force_speed_duplex(hw);		if (ret_val) {			e_dbg("Error Forcing Speed and Duplex\n");			goto out;		}	}	/*	 * Check link status. Wait up to 100 microseconds for link to become	 * valid.	 */	ret_val = e1000e_phy_has_link_generic(hw,	                                     COPPER_LINK_UP_LIMIT,	                                     10,	                                     &link);	if (ret_val)		goto out;	if (link) {		e_dbg("Valid link established!!!\n");		e1000e_config_collision_dist(hw);		ret_val = e1000e_config_fc_after_link_up(hw);	} else {		e_dbg("Unable to establish link!!!\n");	}out:	return ret_val;}/** *  e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY *  @hw: pointer to the HW structure * *  Calls the PHY setup function to force speed and duplex.  Clears the *  auto-crossover to force MDI manually.  Waits for link and returns *  successful if link up is successful, else -E1000_ERR_PHY (-2). **/s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data;	bool link;	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);	if (ret_val)		goto out;	e1000e_phy_force_speed_duplex_setup(hw, &phy_data);	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);	if (ret_val)		goto out;	/*	 * Clear Auto-Crossover to force MDI manually.  IGP requires MDI	 * forced whenever speed and duplex are forced.	 */	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);	if (ret_val)		goto out;	phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;	phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;	ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);	if (ret_val)		goto out;	e_dbg("IGP PSCR: %X\n", phy_data);	udelay(1);	if (phy->autoneg_wait_to_complete) {		e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");		ret_val = e1000e_phy_has_link_generic(hw,		                                     PHY_FORCE_LIMIT,		                                     100000,		                                     &link);		if (ret_val)			goto out;		if (!link)			e_dbg("Link taking longer than expected.\n");		/* Try once more */		ret_val = e1000e_phy_has_link_generic(hw,		                                     PHY_FORCE_LIMIT,		                                     100000,		                                     &link);		if (ret_val)			goto out;	}out:	return ret_val;}/** *  e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY *  @hw: pointer to the HW structure * *  Calls the PHY setup function to force speed and duplex.  Clears the *  auto-crossover to force MDI manually.  Resets the PHY to commit the *  changes.  If time expires while waiting for link up, we reset the DSP. *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon *  successful completion, else return corresponding error code. **/s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data;	bool link;	/*	 * Clear Auto-Crossover to force MDI manually.  M88E1000 requires MDI	 * forced whenever speed and duplex are forced.	 */	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		goto out;	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);	if (ret_val)		goto out;	e_dbg("M88E1000 PSCR: %X\n", phy_data);	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);	if (ret_val)		goto out;	e1000e_phy_force_speed_duplex_setup(hw, &phy_data);	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);	if (ret_val)		goto out;	/* Reset the phy to commit changes. */	ret_val = e1000e_commit_phy(hw);	if (ret_val)		goto out;	if (phy->autoneg_wait_to_complete) {		e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");		ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,		                                     100000, &link);		if (ret_val)			goto out;		if (!link) {			/*			 * We didn't get link.			 * Reset the DSP and cross our fingers.			 */			ret_val = e1e_wphy(hw,			                              M88E1000_PHY_PAGE_SELECT,			                              0x001d);			if (ret_val)				goto out;			ret_val = e1000e_phy_reset_dsp(hw);			if (ret_val)				goto out;		}		/* Try once more */		ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,		                                     100000, &link);		if (ret_val)			goto out;	}	ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		goto out;	/*	 * Resetting the phy means we need to re-force TX_CLK in the	 * Extended PHY Specific Control Register to 25MHz clock from	 * the reset value of 2.5MHz.	 */	phy_data |= M88E1000_EPSCR_TX_CLK_25;	ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);	if (ret_val)		goto out;	/*	 * In addition, we must re-enable CRS on Tx for both half and full	 * duplex.	 */	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		goto out;	phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);out:	return ret_val;}/** *  e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex *  @hw: pointer to the HW structure *  @phy_ctrl: pointer to current value of PHY_CONTROL * *  Forces speed and duplex on the PHY by doing the following: disable flow *  control, force speed/duplex on the MAC, disable auto speed detection, *  disable auto-negotiation, configure duplex, configure speed, configure *  the collision distance, write configuration to CTRL register.  The *  caller must write to the PHY_CONTROL register for these settings to *  take affect. **/void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl){	struct e1000_mac_info *mac = &hw->mac;	u32 ctrl;	/* Turn off flow control when forcing speed/duplex */	hw->fc.current_mode = e1000_fc_none;	/* Force speed/duplex on the mac */	ctrl = er32(CTRL);	ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);	ctrl &= ~E1000_CTRL_SPD_SEL;	/* Disable Auto Speed Detection */	ctrl &= ~E1000_CTRL_ASDE;	/* Disable autoneg on the phy */	*phy_ctrl &= ~MII_CR_AUTO_NEG_EN;	/* Forcing Full or Half Duplex? */	if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {		ctrl &= ~E1000_CTRL_FD;		*phy_ctrl &= ~MII_CR_FULL_DUPLEX;		e_dbg("Half Duplex\n");	} else {		ctrl |= E1000_CTRL_FD;		*phy_ctrl |= MII_CR_FULL_DUPLEX;		e_dbg("Full Duplex\n");	}	/* Forcing 10mb or 100mb? */	if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {		ctrl |= E1000_CTRL_SPD_100;		*phy_ctrl |= MII_CR_SPEED_100;		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);		e_dbg("Forcing 100mb\n");	} else {		ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);		*phy_ctrl |= MII_CR_SPEED_10;		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);		e_dbg("Forcing 10mb\n");	}	e1000e_config_collision_dist(hw);	ew32(CTRL, ctrl);}/** *  e1000e_set_d3_lplu_state - Sets low power link up state for D3 *  @hw: pointer to the HW structure *  @active: boolean used to enable/disable lplu * *  Success returns 0, Failure returns 1 * *  The low power link up (lplu) state is set to the power management level D3 *  and SmartSpeed is disabled when active is true, else clear lplu for D3 *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU *  is used during Dx states where the power conservation is most important. *  During driver activity, SmartSpeed should be enabled so performance is *  maintained. **/s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val = E1000_SUCCESS;	u16 data;	if (!(hw->phy.ops.read_reg))		goto out;	ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);	if (ret_val)		goto out;	if (!active) {		data &= ~IGP02E1000_PM_D3_LPLU;		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT,		                             data);		if (ret_val)			goto out;		/*		 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used		 * during Dx states where the power conservation is most		 * important.  During driver activity we should enable		 * SmartSpeed, so performance is maintained.		 */		if (phy->smart_speed == e1000_smart_speed_on) {			ret_val = e1e_rphy(hw,			                            IGP01E1000_PHY_PORT_CONFIG,			                            &data);			if (ret_val)				goto out;			data |= IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1e_wphy(hw,			                             IGP01E1000_PHY_PORT_CONFIG,			                             data);			if (ret_val)				goto out;		} else if (phy->smart_speed == e1000_smart_speed_off) {			ret_val = e1e_rphy(hw,			                             IGP01E1000_PHY_PORT_CONFIG,			                             &data);			if (ret_val)				goto out;			data &= ~IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1e_wphy(hw,			                             IGP01E1000_PHY_PORT_CONFIG,			                             data);			if (ret_val)				goto out;		}	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||	           (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||	           (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {		data |= IGP02E1000_PM_D3_LPLU;		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT,		                              data);		if (ret_val)			goto out;		/* When LPLU is enabled, we should disable SmartSpeed */		ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,		                             &data);		if (ret_val)			goto out;		data &= ~IGP01E1000_PSCFR_SMART_SPEED;		ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,		                              data);	}out:	return ret_val;}/** *  e1000e_check_downshift - Checks whether a downshift in speed occurred *  @hw: pointer to the HW structure * *  Success returns 0, Failure returns 1 * *  A downshift is detected by querying the PHY link health. **/s32 e1000e_check_downshift(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data, offset, mask;	switch (phy->type) {	case e1000_phy_m88:	case e1000_phy_gg82563:	case e1000_phy_bm:		offset	= M88E1000_PHY_SPEC_STATUS;		mask	= M88E1000_PSSR_DOWNSHIFT;		break;	case e1000_phy_igp_2:	case e1000_phy_igp:	case e1000_phy_igp_3:		offset	= IGP01E1000_PHY_LINK_HEALTH;		mask	= IGP01E1000_PLHR_SS_DOWNGRADE;		break;	default:		/* speed downshift not supported */		phy->speed_downgraded = false;		ret_val = E1000_SUCCESS;		goto out;	}	ret_val = e1e_rphy(hw, offset, &phy_data);	if (!ret_val)		phy->speed_downgraded = (phy_data & mask) ? true : false;out:	return ret_val;}/** *  e1000_check_polarity_m88 - Checks the polarity. *  @hw: pointer to the HW structure * *  Success returns 0, Failure returns -E1000_ERR_PHY (-2) * *  Polarity is determined based on the PHY specific status register. **/s32 e1000_check_polarity_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data;	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);	if (!ret_val)		phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)		                      ? e1000_rev_polarity_reversed		                      : e1000_rev_polarity_normal;	return ret_val;}/** *  e1000_check_polarity_igp - Checks the polarity. *  @hw: pointer to the HW structure * *  Success returns 0, Failure returns -E1000_ERR_PHY (-2) * *  Polarity is determined based on the PHY port status register, and the *  current speed (since there is no polarity at 100Mbps). **/s32 e1000_check_polarity_igp(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data, offset, mask;	/*	 * Polarity is determined based on the speed of	 * our connection.	 */	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);	if (ret_val)		goto out;	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==	    IGP01E1000_PSSR_SPEED_1000MBPS) {		offset	= IGP01E1000_PHY_PCS_INIT_REG;		mask	= IGP01E1000_PHY_POLARITY_MASK;	} else {		/*		 * This really only applies to 10Mbps since		 * there is no polarity for 100Mbps (always 0).		 */		offset	= IGP01E1000_PHY_PORT_STATUS;		mask	= IGP01E1000_PSSR_POLARITY_REVERSED;	}	ret_val = e1e_rphy(hw, offset, &data);	if (!ret_val)		phy->cable_polarity = (data & mask)		                      ? e1000_rev_polarity_reversed		                      : e1000_rev_polarity_normal;out:	return ret_val;}/** *  e1000_wait_autoneg - Wait for auto-neg completion *  @hw: pointer to the HW structure * *  Waits for auto-negotiation to complete or for the auto-negotiation time *  limit to expire, which ever happens first. **/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -