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

📄 phy.c

📁 grub源码分析文档
💻 C
📖 第 1 页 / 共 4 页
字号:
		ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,						     100000, &link);		if (ret_val)			return ret_val;	}	ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		return ret_val;	/*	 * 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)		return ret_val;	/*	 * 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)		return ret_val;	phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);	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.type = 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;		hw_dbg(hw, "Half Duplex\n");	} else {		ctrl |= E1000_CTRL_FD;		*phy_ctrl |= MII_CR_FULL_DUPLEX;		hw_dbg(hw, "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);		hw_dbg(hw, "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);		hw_dbg(hw, "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;	u16 data;	ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);	if (ret_val)		return ret_val;	if (!active) {		data &= ~IGP02E1000_PM_D3_LPLU;		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);		if (ret_val)			return ret_val;		/*		 * 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)				return ret_val;			data |= IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,					   data);			if (ret_val)				return ret_val;		} else if (phy->smart_speed == e1000_smart_speed_off) {			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,					   &data);			if (ret_val)				return ret_val;			data &= ~IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,					   data);			if (ret_val)				return ret_val;		}	} 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)			return ret_val;		/* When LPLU is enabled, we should disable SmartSpeed */		ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);		if (ret_val)			return ret_val;		data &= ~IGP01E1000_PSCFR_SMART_SPEED;		ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);	}	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:		offset	= M88E1000_PHY_SPEC_STATUS;		mask	= M88E1000_PSSR_DOWNSHIFT;		break;	case e1000_phy_igp_2:	case e1000_phy_igp_3:		offset	= IGP01E1000_PHY_LINK_HEALTH;		mask	= IGP01E1000_PLHR_SS_DOWNGRADE;		break;	default:		/* speed downshift not supported */		phy->speed_downgraded = 0;		return 0;	}	ret_val = e1e_rphy(hw, offset, &phy_data);	if (!ret_val)		phy->speed_downgraded = (phy_data & mask);	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. **/static 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). **/static 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)		return ret_val;	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;	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. **/static s32 e1000_wait_autoneg(struct e1000_hw *hw){	s32 ret_val = 0;	u16 i, phy_status;	/* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */	for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		if (phy_status & MII_SR_AUTONEG_COMPLETE)			break;		msleep(100);	}	/*	 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation	 * has completed.	 */	return ret_val;}/** *  e1000e_phy_has_link_generic - Polls PHY for link *  @hw: pointer to the HW structure *  @iterations: number of times to poll for link *  @usec_interval: delay between polling attempts *  @success: pointer to whether polling was successful or not * *  Polls the PHY status register for link, 'iterations' number of times. **/s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,			       u32 usec_interval, bool *success){	s32 ret_val = 0;	u16 i, phy_status;	for (i = 0; i < iterations; i++) {		/*		 * Some PHYs require the PHY_STATUS register to be read		 * twice due to the link bit being sticky.  No harm doing		 * it across the board.		 */		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		if (phy_status & MII_SR_LINK_STATUS)			break;		if (usec_interval >= 1000)			mdelay(usec_interval/1000);		else			udelay(usec_interval);	}	*success = (i < iterations);	return ret_val;}/** *  e1000e_get_cable_length_m88 - Determine cable length for m88 PHY *  @hw: pointer to the HW structure * *  Reads the PHY specific status register to retrieve the cable length *  information.  The cable length is determined by averaging the minimum and *  maximum values to get the "average" cable length.  The m88 PHY has four *  possible cable length values, which are: *	Register Value		Cable Length *	0			< 50 meters *	1			50 - 80 meters *	2			80 - 110 meters *	3			110 - 140 meters *	4			> 140 meters **/s32 e1000e_get_cable_length_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data, index;	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);	if (ret_val)		return ret_val;	index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>		M88E1000_PSSR_CABLE_LENGTH_SHIFT;	phy->min_cable_length = e1000_m88_cable_length_table[index];	phy->max_cable_length = e1000_m88_cable_length_table[index+1];	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;	return ret_val;}/** *  e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY *  @hw: pointer to the HW structure * *  The automatic gain control (agc) normalizes the amplitude of the *  received signal, adjusting for the attenuation produced by the *  cable.  By reading the AGC registers, which represent the *  combination of course and fine gain value, the value can be put *  into a lookup table to obtain the approximate cable length *  for each channel. **/s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data, i, agc_value = 0;	u16 cur_agc_index, max_agc_index = 0;	u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;	u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =							 {IGP02E1000_PHY_AGC_A,							  IGP02E1000_PHY_AGC_B,							  IGP02E1000_PHY_AGC_C,							  IGP02E1000_PHY_AGC_D};	/* Read the AGC registers for all channels */	for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {		ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);		if (ret_val)			return ret_val;		/*		 * Getting bits 15:9, which represent the combination of		 * course and fine gain values.  The result is a number		 * that can be put into the lookup table to obtain the		 * approximate cable length.		 */		cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &				IGP02E1000_AGC_LENGTH_MASK;		/* Array index bound check. */		if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||		    (cur_agc_index == 0))			return -E1000_ERR_PHY;		/* Remove min & max AGC values from calculation. */		if (e1000_igp_2_cable_length_table[min_agc_index] >		    e1000_igp_2_cable_length_table[cur_agc_index])			min_agc_index = cur_agc_index;		if (e1000_igp_2_cable_length_table[max_agc_index] <		    e1000_igp_2_cable_length_table[cur_agc_index])			max_agc_index = cur_agc_index;		agc_value += e1000_igp_2_cable_length_table[cur_agc_index];	}	agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +		      e1000_igp_2_cable_length_table[max_agc_index]);	agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);	/* Calculate cable length with the error range of +/- 10 meters. */	phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?				 (agc_value - IGP02E1000_AGC_RANGE) : 0;	phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;	return ret_val;}/** *  e1000e_get_phy_info_m88 - Retrieve PHY information *  @hw: pointer to the HW structure * *  Valid for only copper links.  Read the PHY status register (sticky read) *  to verify that link is up.  Read the PHY special control register to *  determine the polarity and 10base-T extended distance.  Read the PHY *  special status register to determine MDI/MDIx and current speed.  If *  speed is 1000, then determine cable length, local and remote receiver. **/s32 e1000e_get_phy_info_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32  ret_val;	u16 phy_data;	bool link;	if (hw->phy.media_type != e1000_media_type_copper) {		hw_dbg(hw, "Phy info is only valid for copper media\n");		return -E1000_ERR_CONFIG;	}	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);	if (ret_val)		return ret_val;	if (!link) {		hw_dbg(hw, "Phy info is only valid if link is up\n");		return -E1000_ERR_CONFIG;	}	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		return ret_val;	phy->polarity_correction = (phy_data &				    M88E1000_PSCR_POLARITY_REVERSAL);	ret_val = e1000_check_polarity_m88(hw);	if (ret_val)		return ret_val;	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);	if (ret_val)		return ret_val;	phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);	if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {		ret_val = e1000_get_cable_length(hw);		if (ret_val)			return ret_val;		ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);		if (ret_val)			return ret_val;		phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)				? e1000_1000t_rx_status_ok				: e1000_1000t_rx_status_not_ok;		phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)				 ? e1000_1000t_rx_status_ok				 : e1000_1000t_rx_status_not_ok;	} else {		/* Set values to "undefined" */		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;		phy->local_rx = e1000_1000t_rx_status_undefined;

⌨️ 快捷键说明

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