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

📄 e1000_ich8lan.c

📁 linux系统的网卡驱动包
💻 C
📖 第 1 页 / 共 5 页
字号:
/** *  e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state *  @hw: pointer to the HW structure *  @active: TRUE to enable LPLU, FALSE to disable * *  Sets the LPLU D3 state according to the active flag.  When *  activating LPLU this function also disables smart speed *  and vice versa.  LPLU will not be activated unless the *  device autonegotiation advertisement meets standards of *  either 10 or 10/100 or 10/100/1000 at all duplexes. *  This is a function pointer entry point only called by *  PHY setup routines. **/static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,                                           bool active){	struct e1000_phy_info *phy = &hw->phy;	u32 phy_ctrl;	s32 ret_val = E1000_SUCCESS;	u16 data;	DEBUGFUNC("e1000_set_d3_lplu_state_ich8lan");	phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);	if (!active) {		phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);		/*		 * 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 = e1000_read_phy_reg(hw,			                            IGP01E1000_PHY_PORT_CONFIG,			                            &data);			if (ret_val)				goto out;			data |= IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1000_write_phy_reg(hw,			                             IGP01E1000_PHY_PORT_CONFIG,			                             data);			if (ret_val)				goto out;		} else if (phy->smart_speed == e1000_smart_speed_off) {			ret_val = e1000_read_phy_reg(hw,			                            IGP01E1000_PHY_PORT_CONFIG,			                            &data);			if (ret_val)				goto out;			data &= ~IGP01E1000_PSCFR_SMART_SPEED;			ret_val = e1000_write_phy_reg(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)) {		phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);		/*		 * Call gig speed drop workaround on LPLU before accessing		 * any PHY registers		 */		if ((hw->mac.type == e1000_ich8lan) &&		    (hw->phy.type == e1000_phy_igp_3))			e1000_gig_downshift_workaround_ich8lan(hw);		/* When LPLU is enabled, we should disable SmartSpeed */		ret_val = e1000_read_phy_reg(hw,		                            IGP01E1000_PHY_PORT_CONFIG,		                            &data);		if (ret_val)			goto out;		data &= ~IGP01E1000_PSCFR_SMART_SPEED;		ret_val = e1000_write_phy_reg(hw,		                             IGP01E1000_PHY_PORT_CONFIG,		                             data);	}out:	return ret_val;}/** *  e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1 *  @hw: pointer to the HW structure *  @bank:  pointer to the variable that returns the active bank * *  Reads signature byte from the NVM using the flash access registers. **/static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank){	s32 ret_val = E1000_SUCCESS;	if (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_SEC1VAL)		*bank = 1;	else		*bank = 0;		return ret_val;}/** *  e1000_read_nvm_ich8lan - Read word(s) from the NVM *  @hw: pointer to the HW structure *  @offset: The offset (in bytes) of the word(s) to read. *  @words: Size of data to read in words *  @data: Pointer to the word(s) to read at offset. * *  Reads a word(s) from the NVM using the flash access registers. **/static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,                                  u16 *data){	struct e1000_nvm_info *nvm = &hw->nvm;	struct e1000_dev_spec_ich8lan *dev_spec;	u32 act_offset;	s32 ret_val = E1000_SUCCESS;	u32 bank = 0;	u16 i, word;	DEBUGFUNC("e1000_read_nvm_ich8lan");	dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;	if (!dev_spec) {		DEBUGOUT("dev_spec pointer is set to NULL.\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||	    (words == 0)) {		DEBUGOUT("nvm parameter(s) out of bounds\n");		ret_val = -E1000_ERR_NVM;		goto out;	}	ret_val = e1000_acquire_nvm(hw);	if (ret_val)		goto out;	ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);	if (ret_val != E1000_SUCCESS)		goto out;	act_offset = (bank) ? nvm->flash_bank_size : 0;	act_offset += offset;	for (i = 0; i < words; i++) {		if ((dev_spec->shadow_ram) &&		    (dev_spec->shadow_ram[offset+i].modified)) {			data[i] = dev_spec->shadow_ram[offset+i].value;		} else {			ret_val = e1000_read_flash_word_ich8lan(hw,			                                        act_offset + i,			                                        &word);			if (ret_val)				break;			data[i] = word;		}	}	e1000_release_nvm(hw);out:	return ret_val;}/** *  e1000_flash_cycle_init_ich8lan - Initialize flash *  @hw: pointer to the HW structure * *  This function does initial flash setup so that a new read/write/erase cycle *  can be started. **/static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw){	union ich8_hws_flash_status hsfsts;	s32 ret_val = -E1000_ERR_NVM;	s32 i = 0;	DEBUGFUNC("e1000_flash_cycle_init_ich8lan");	hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);	/* Check if the flash descriptor is valid */	if (hsfsts.hsf_status.fldesvalid == 0) {		DEBUGOUT("Flash descriptor invalid.  "		         "SW Sequencing must be used.");		goto out;	}	/* Clear FCERR and DAEL in hw status by writing 1 */	hsfsts.hsf_status.flcerr = 1;	hsfsts.hsf_status.dael = 1;	E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);	/*	 * Either we should have a hardware SPI cycle in progress	 * bit to check against, in order to start a new cycle or	 * FDONE bit should be changed in the hardware so that it	 * is 1 after harware reset, which can then be used as an	 * indication whether a cycle is in progress or has been	 * completed.	 */	if (hsfsts.hsf_status.flcinprog == 0) {		/*		 * There is no cycle running at present,		 * so we can start a cycle.		 * Begin by setting Flash Cycle Done.		 */		hsfsts.hsf_status.flcdone = 1;		E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);		ret_val = E1000_SUCCESS;	} else {		/*		 * Otherwise poll for sometime so the current		 * cycle has a chance to end before giving up.		 */		for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {			hsfsts.regval = E1000_READ_FLASH_REG16(hw,			                                      ICH_FLASH_HSFSTS);			if (hsfsts.hsf_status.flcinprog == 0) {				ret_val = E1000_SUCCESS;				break;			}			usec_delay(1);		}		if (ret_val == E1000_SUCCESS) {			/*			 * Successful in waiting for previous cycle to timeout,			 * now set the Flash Cycle Done.			 */			hsfsts.hsf_status.flcdone = 1;			E1000_WRITE_FLASH_REG16(hw,			                        ICH_FLASH_HSFSTS,			                        hsfsts.regval);		} else {			DEBUGOUT("Flash controller busy, cannot get access");		}	}out:	return ret_val;}/** *  e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase) *  @hw: pointer to the HW structure *  @timeout: maximum time to wait for completion * *  This function starts a flash cycle and waits for its completion. **/static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout){	union ich8_hws_flash_ctrl hsflctl;	union ich8_hws_flash_status hsfsts;	s32 ret_val = -E1000_ERR_NVM;	u32 i = 0;	DEBUGFUNC("e1000_flash_cycle_ich8lan");	/* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */	hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);	hsflctl.hsf_ctrl.flcgo = 1;	E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);	/* wait till FDONE bit is set to 1 */	do {		hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);		if (hsfsts.hsf_status.flcdone == 1)			break;		usec_delay(1);	} while (i++ < timeout);	if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)		ret_val = E1000_SUCCESS;	return ret_val;}/** *  e1000_read_flash_word_ich8lan - Read word from flash *  @hw: pointer to the HW structure *  @offset: offset to data location *  @data: pointer to the location for storing the data * *  Reads the flash word at offset into data.  Offset is converted *  to bytes before read. **/static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,                                         u16 *data){	s32 ret_val;	DEBUGFUNC("e1000_read_flash_word_ich8lan");	if (!data) {		ret_val = -E1000_ERR_NVM;		goto out;	}	/* Must convert offset into bytes. */	offset <<= 1;	ret_val = e1000_read_flash_data_ich8lan(hw, offset, 2, data);out:	return ret_val;}/** *  e1000_read_flash_data_ich8lan - Read byte or word from NVM *  @hw: pointer to the HW structure *  @offset: The offset (in bytes) of the byte or word to read. *  @size: Size of data to read, 1=byte 2=word *  @data: Pointer to the word to store the value read. * *  Reads a byte or word from the NVM using the flash access registers. **/static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,                                         u8 size, u16* data){	union ich8_hws_flash_status hsfsts;	union ich8_hws_flash_ctrl hsflctl;	u32 flash_linear_addr;	u32 flash_data = 0;	s32 ret_val = -E1000_ERR_NVM;	u8 count = 0;	DEBUGFUNC("e1000_read_flash_data_ich8lan");	if (size < 1  || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)		goto out;	flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +	                    hw->nvm.flash_base_addr;	do {		usec_delay(1);		/* Steps */		ret_val = e1000_flash_cycle_init_ich8lan(hw);		if (ret_val != E1000_SUCCESS)			break;		hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);		/* 0b/1b corresponds to 1 or 2 byte size, respectively. */		hsflctl.hsf_ctrl.fldbcount = size - 1;		hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;		E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);		ret_val = e1000_flash_cycle_ich8lan(hw,		                                ICH_FLASH_READ_COMMAND_TIMEOUT);		/*		 * Check if FCERR is set to 1, if set to 1, clear it		 * and try the whole sequence a few more times, else		 * read in (shift in) the Flash Data0, the order is		 * least significant byte first msb to lsb		 */		if (ret_val == E1000_SUCCESS) {			flash_data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);			if (size == 1) {				*data = (u8)(flash_data & 0x000000FF);			} else if (size == 2) {				*data = (u16)(flash_data & 0x0000FFFF);			}			break;		} else {			/*			 * If we've gotten here, then things are probably			 * completely hosed, but if the error condition is			 * detected, it won't hurt to give it another try...			 * ICH_FLASH_CYCLE_REPEAT_COUNT times.			 */			hsfsts.regval = E1000_READ_FLASH_REG16(hw,			                                      ICH_FLASH_HSFSTS);			if (hsfsts.hsf_status.flcerr == 1) {				/* Repeat for some time before giving up. */				continue;			} else if (hsfsts.hsf_status.flcdone == 0) {				DEBUGOUT("Timeout error - flash cycle "				         "did not complete.");				break;			}		}	} while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);out:	return ret_val;}/** *  e1000_write_nvm_ich8lan - Write word(s) to the NVM *  @hw: pointer to the HW structure *  @offset: The offset (in bytes) of the word(s) to write. *  @words: Size of data to write in words *  @data: Pointer to the word(s) to write at offset. * *  Writes a byte or word to the NVM using the flash access registers. **/static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,                                   u16 *data){	struct e1000_nvm_info *nvm = &hw->nvm;	struct e1000_dev_spec_ich8lan *dev_spec;	s32 ret_val = E1000_SUCCESS;	u16 i;	DEBUGFUNC("e1000_write_nvm_ich8lan");	dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;	if (!dev_spec) {		DEBUGOUT("dev_spec pointer is set to NULL.\n");		ret_val = -E1000_ERR_CONFIG;		goto out;	}	if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||	    (words == 0)) {		DEBUGOUT("nvm parameter(s) out of bounds\n");		ret_val = -E1000_ERR_NVM;		goto out;	}	ret_val = e1000_acquire_nvm(hw);	if (ret_val)		goto out;	for (i = 0; i < words; i++) {		dev_spec->shadow_ram[offset+i].modified = TRUE;		dev_spec->shadow_ram[offset+i].value = data[i];	}

⌨️ 快捷键说明

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