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

📄 e1000_phy.c

📁 DELL755 Intel 网卡驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
s32 e1000_check_polarity_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data;	DEBUGFUNC("e1000_check_polarity_m88");	ret_val = phy->ops.read_reg(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;	DEBUGFUNC("e1000_check_polarity_igp");	/*	 * Polarity is determined based on the speed of	 * our connection.	 */	ret_val = phy->ops.read_reg(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 = phy->ops.read_reg(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_generic - 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. **/s32 e1000_wait_autoneg_generic(struct e1000_hw *hw){	s32 ret_val = E1000_SUCCESS;	u16 i, phy_status;	DEBUGFUNC("e1000_wait_autoneg_generic");	if (!(hw->phy.ops.read_reg))		return E1000_SUCCESS;	/* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */	for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		if (phy_status & MII_SR_AUTONEG_COMPLETE)			break;		msec_delay(100);	}	/*	 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation	 * has completed.	 */	return ret_val;}/** *  e1000_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 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,                               u32 usec_interval, bool *success){	s32 ret_val = E1000_SUCCESS;	u16 i, phy_status;	DEBUGFUNC("e1000_phy_has_link_generic");	if (!(hw->phy.ops.read_reg))		return E1000_SUCCESS;	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 = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);		if (ret_val)			break;		if (phy_status & MII_SR_LINK_STATUS)			break;		if (usec_interval >= 1000)			msec_delay_irq(usec_interval/1000);		else			usec_delay(usec_interval);	}	*success = (i < iterations) ? true : false;	return ret_val;}/** *  e1000_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 e1000_get_cable_length_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 phy_data, index;	DEBUGFUNC("e1000_get_cable_length_m88");	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);	if (ret_val)		goto out;	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;out:	return ret_val;}/** *  e1000_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 coarse and fine gain value, the value can be put *  into a lookup table to obtain the approximate cable length *  for each channel. **/s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val = E1000_SUCCESS;	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};	DEBUGFUNC("e1000_get_cable_length_igp_2");	/* Read the AGC registers for all channels */	for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {		ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);		if (ret_val)			goto out;		/*		 * Getting bits 15:9, which represent the combination of		 * coarse 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)) {			ret_val = -E1000_ERR_PHY;			goto out;		}		/* 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;out:	return ret_val;}/** *  e1000_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 e1000_get_phy_info_m88(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32  ret_val;	u16 phy_data;	bool link;	DEBUGFUNC("e1000_get_phy_info_m88");	if (hw->phy.media_type != e1000_media_type_copper) {		DEBUGOUT("Phy info is only valid for copper media\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);	if (ret_val)		goto out;	if (!link) {		DEBUGOUT("Phy info is only valid if link is up\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);	if (ret_val)		goto out;	phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)	                           ? true	                           : false;	ret_val = e1000_check_polarity_m88(hw);	if (ret_val)		goto out;	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);	if (ret_val)		goto out;	phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;	if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {		ret_val = hw->phy.ops.get_cable_length(hw);		if (ret_val)			goto out;		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);		if (ret_val)			goto out;		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;		phy->remote_rx = e1000_1000t_rx_status_undefined;	}out:	return ret_val;}/** *  e1000_get_phy_info_igp - Retrieve igp PHY information *  @hw: pointer to the HW structure * *  Read PHY status to determine if link is up.  If link is up, then *  set/determine 10base-T extended distance and polarity correction.  Read *  PHY port status to determine MDI/MDIx and speed.  Based on the speed, *  determine on the cable length, local and remote receiver. **/s32 e1000_get_phy_info_igp(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data;	bool link;	DEBUGFUNC("e1000_get_phy_info_igp");	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);	if (ret_val)		goto out;	if (!link) {		DEBUGOUT("Phy info is only valid if link is up\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	phy->polarity_correction = true;	ret_val = e1000_check_polarity_igp(hw);	if (ret_val)		goto out;	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);	if (ret_val)		goto out;	phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==	    IGP01E1000_PSSR_SPEED_1000MBPS) {		ret_val = hw->phy.ops.get_cable_length(hw);		if (ret_val)			goto out;		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);		if (ret_val)			goto out;		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)		                ? e1000_1000t_rx_status_ok		                : e1000_1000t_rx_status_not_ok;		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)		                 ? e1000_1000t_rx_status_ok		                 : e1000_1000t_rx_status_not_ok;	} else {		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;		phy->local_rx = e1000_1000t_rx_status_undefined;		phy->remote_rx = e1000_1000t_rx_status_undefined;	}out:	return ret_val;}/** *  e1000_phy_sw_reset_generic - PHY software reset *  @hw: pointer to the HW structure * *  Does a software reset of the PHY by reading the PHY control register and *  setting/write the control register reset bit to the PHY. **/s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw){	s32 ret_val = E1000_SUCCESS;	u16 phy_ctrl;	DEBUGFUNC("e1000_phy_sw_reset_generic");	if (!(hw->phy.ops.read_reg))		goto out;	ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);	if (ret_val)		goto out;	phy_ctrl |= MII_CR_RESET;	ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);	if (ret_val)		goto out;	usec_delay(1);out:	return ret_val;}/** *  e1000_phy_hw_reset_generic - PHY hardware reset *  @hw: pointer to the HW structure * *  Verify the reset block is not blocking us from resetting.  Acquire *  semaphore (if necessary) and read/set/write the device control reset *  bit in the PHY.  Wait the appropriate delay time for the device to *  reset and release the semaphore (if necessary). **/s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val = E1000_SUCCESS;	u32 ctrl;	DEBUGFUNC("e1000_phy_hw_reset_generic");	ret_val = phy->ops.check_reset_block(hw);	if (ret_val) {		ret_val = E1000_SUCCESS;		goto out;	}	ret_val = phy->ops.acquire(hw);	if (ret_val)		goto out;	ctrl = E1000_READ_REG(hw, E1000_CTRL);	E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);	E1000_WRITE_FLUSH(hw);	usec_delay(phy->reset_delay_us);	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);	E1000_WRITE_FLUSH(hw);	usec_delay(150);

⌨️ 快捷键说明

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