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

📄 e1000_phy.c

📁 Intel 82546系列lan driver源码
💻 C
📖 第 1 页 / 共 5 页
字号:
s32 e1000_wait_autoneg(struct e1000_hw *hw){	s32 ret_val = E1000_SUCCESS;	u16 i, phy_status;	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 = 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 = E1000_SUCCESS;	u16 i, phy_status;	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 = 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) ? true : false;	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)		goto out;	index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>	        M88E1000_PSSR_CABLE_LENGTH_SHIFT;	if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE + 1) {		ret_val = E1000_ERR_PHY;		goto out;	}	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;}/** *  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 coarse 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 = 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};	/* 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)			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;}/** *  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) {		e_dbg("Phy info is only valid for copper media\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);	if (ret_val)		goto out;	if (!link) {		e_dbg("Phy info is only valid if link is up\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	ret_val = e1e_rphy(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 = e1e_rphy(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 = e1000_get_cable_length(hw);		if (ret_val)			goto out;		ret_val = e1e_rphy(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;}/** *  e1000e_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 e1000e_get_phy_info_igp(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data;	bool link;	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);	if (ret_val)		goto out;	if (!link) {		e_dbg("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 = e1e_rphy(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 = e1000_get_cable_length(hw);		if (ret_val)			goto out;		ret_val = e1e_rphy(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;}/** *  e1000e_phy_sw_reset - 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 e1000e_phy_sw_reset(struct e1000_hw *hw){	s32 ret_val = E1000_SUCCESS;	u16 phy_ctrl;	if (!(hw->phy.ops.read_reg))		goto out;	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);	if (ret_val)		goto out;	phy_ctrl |= MII_CR_RESET;	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);	if (ret_val)		goto out;	udelay(1);out:	return ret_val;}/** *  e1000e_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 e1000e_phy_hw_reset_generic(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val = E1000_SUCCESS;	u32 ctrl;	ret_val = e1000_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 = er32(CTRL);	ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);	e1e_flush();	udelay(phy->reset_delay_us);	ew32(CTRL, ctrl);	e1e_flush();	udelay(150);	phy->ops.release(hw);	ret_val = phy->ops.get_cfg_done(hw);out:	return ret_val;}/** *  e1000e_get_cfg_done - Generic configuration done *  @hw: pointer to the HW structure * *  Generic function to wait 10 milli-seconds for configuration to complete *  and return success. **/s32 e1000e_get_cfg_done(struct e1000_hw *hw){	mdelay(10);	return E1000_SUCCESS;}/** *  e1000_phy_init_script_igp3 - Inits the IGP3 PHY *  @hw: pointer to the HW structure * *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present. **/s32 e1000_phy_init_script_igp3(struct e1000_hw *hw){	e_dbg("Running IGP 3 PHY init script\n");	/* PHY init IGP 3 */	/* Enable rise/fall, 10-mode work in class-A */	e1e_wphy(hw, 0x2F5B, 0x9018);	/* Remove all caps from Replica path filter */	e1e_wphy(hw, 0x2F52, 0x0000);	/* Bias trimming for ADC, AFE and Driver (Default) */	e1e_wphy(hw, 0x2FB1, 0x8B24);	/* Increase Hybrid poly bias */	e1e_wphy(hw, 0x2FB2, 0xF8F0);	/* Add 4% to Tx amplitude in Gig mode */	e1e_wphy(hw, 0x2010, 0x10B0);	/* Disable trimming (TTT) */	e1e_wphy(hw, 0x2011, 0x0000);	/* Poly DC correction to 94.6% + 2% for all channels */	e1e_wphy(hw, 0x20DD, 0x249A);	/* ABS DC correction to 95.9% */	e1e_wphy(hw, 0x20DE, 0x00D3);	/* BG temp curve trim */	e1e_wphy(hw, 0x28B4, 0x04CE);	/* Increasing ADC OPAMP stage 1 currents to max */	e1e_wphy(hw, 0x2F70, 0x29E4);	/* Force 1000 ( required for enabling PHY regs configuration) */	e1e_wphy(hw, 0x0000, 0x0140);	/* Set upd_freq to 6 */	e1e_wphy(hw, 0x1F30, 0x1606);	/* Disable NPDFE */	e1e_wphy(hw, 0x1F31, 0xB814);	/* Disable adaptive fixed FFE (Default) */	e1e_wphy(hw, 0x1F35, 0x002A);	/* Enable FFE hysteresis */	e1e_wphy(hw, 0x1F3E, 0x0067);	/* Fixed FFE for short cable lengths */	e1e_wphy(hw, 0x1F54, 0x0065);	/* Fixed FFE for medium cable lengths */	e1e_wphy(hw, 0x1F55, 0x002A);	/* Fixed FFE for long cable lengths */	e1e_wphy(hw, 0x1F56, 0x002A);	/* Enable Adaptive Clip Threshold */	e1e_wphy(hw, 0x1F72, 0x3FB0);	/* AHT reset limit to 1 */	e1e_wphy(hw, 0x1F76, 0xC0FF);	/* Set AHT master delay to 127 msec */	e1e_wphy(hw, 0x1F77, 0x1DEC);	/* Set scan bits for AHT */	e1e_wphy(hw, 0x1F78, 0xF9EF);	/* Set AHT Preset bits */	e1e_wphy(hw, 0x1F79, 0x0210);	/* Change integ_factor of channel A to 3 */	e1e_wphy(hw, 0x1895, 0x0003);	/* Change prop_factor of channels BCD to 8 */	e1e_wphy(hw, 0x1796, 0x0008);	/* Change cg_icount + enable integbp for channels BCD */	e1e_wphy(hw, 0x1798, 0xD008);	/*	 * Change cg_icount + enable integbp + change prop_factor_master	 * to 8 for channel A	 */	e1e_wphy(hw, 0x1898, 0xD918);

⌨️ 快捷键说明

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