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

📄 ich8lan.c

📁 grub源码分析文档
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************  Intel PRO/1000 Linux driver  Copyright(c) 1999 - 2008 Intel Corporation.  This program is free software; you can redistribute it and/or modify it  under the terms and conditions of the GNU General Public License,  version 2, as published by the Free Software Foundation.  This program is distributed in the hope it will be useful, but WITHOUT  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for  more details.  You should have received a copy of the GNU General Public License along with  this program; if not, write to the Free Software Foundation, Inc.,  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.  The full GNU General Public License is included in this distribution in  the file called "COPYING".  Contact Information:  Linux NICS <linux.nics@intel.com>  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497*******************************************************************************//* * 82562G-2 10/100 Network Connection * 82562GT 10/100 Network Connection * 82562GT-2 10/100 Network Connection * 82562V 10/100 Network Connection * 82562V-2 10/100 Network Connection * 82566DC-2 Gigabit Network Connection * 82566DC Gigabit Network Connection * 82566DM-2 Gigabit Network Connection * 82566DM Gigabit Network Connection * 82566MC Gigabit Network Connection * 82566MM Gigabit Network Connection * 82567LM Gigabit Network Connection * 82567LF Gigabit Network Connection */#include <linux/netdevice.h>#include <linux/ethtool.h>#include <linux/delay.h>#include <linux/pci.h>#include "e1000.h"#define ICH_FLASH_GFPREG		0x0000#define ICH_FLASH_HSFSTS		0x0004#define ICH_FLASH_HSFCTL		0x0006#define ICH_FLASH_FADDR			0x0008#define ICH_FLASH_FDATA0		0x0010#define ICH_FLASH_READ_COMMAND_TIMEOUT	500#define ICH_FLASH_WRITE_COMMAND_TIMEOUT	500#define ICH_FLASH_ERASE_COMMAND_TIMEOUT	3000000#define ICH_FLASH_LINEAR_ADDR_MASK	0x00FFFFFF#define ICH_FLASH_CYCLE_REPEAT_COUNT	10#define ICH_CYCLE_READ			0#define ICH_CYCLE_WRITE			2#define ICH_CYCLE_ERASE			3#define FLASH_GFPREG_BASE_MASK		0x1FFF#define FLASH_SECTOR_ADDR_SHIFT		12#define ICH_FLASH_SEG_SIZE_256		256#define ICH_FLASH_SEG_SIZE_4K		4096#define ICH_FLASH_SEG_SIZE_8K		8192#define ICH_FLASH_SEG_SIZE_64K		65536#define E1000_ICH_FWSM_RSPCIPHY	0x00000040 /* Reset PHY on PCI Reset */#define E1000_ICH_MNG_IAMT_MODE		0x2#define ID_LED_DEFAULT_ICH8LAN  ((ID_LED_DEF1_DEF2 << 12) | \				 (ID_LED_DEF1_OFF2 <<  8) | \				 (ID_LED_DEF1_ON2  <<  4) | \				 (ID_LED_DEF1_DEF2))#define E1000_ICH_NVM_SIG_WORD		0x13#define E1000_ICH_NVM_SIG_MASK		0xC000#define E1000_ICH8_LAN_INIT_TIMEOUT	1500#define E1000_FEXTNVM_SW_CONFIG		1#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */#define PCIE_ICH8_SNOOP_ALL		PCIE_NO_SNOOP_ALL#define E1000_ICH_RAR_ENTRIES		7#define IGP3_KMRN_DIAG  PHY_REG(770, 19) /* KMRN Diagnostic */#define IGP3_VR_CTRL    PHY_REG(776, 18) /* Voltage Regulator Control */#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS	0x0002#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300#define IGP3_VR_CTRL_MODE_SHUTDOWN	0x0200/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown *//* Offset 04h HSFSTS */union ich8_hws_flash_status {	struct ich8_hsfsts {		u16 flcdone    :1; /* bit 0 Flash Cycle Done */		u16 flcerr     :1; /* bit 1 Flash Cycle Error */		u16 dael       :1; /* bit 2 Direct Access error Log */		u16 berasesz   :2; /* bit 4:3 Sector Erase Size */		u16 flcinprog  :1; /* bit 5 flash cycle in Progress */		u16 reserved1  :2; /* bit 13:6 Reserved */		u16 reserved2  :6; /* bit 13:6 Reserved */		u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */		u16 flockdn    :1; /* bit 15 Flash Config Lock-Down */	} hsf_status;	u16 regval;};/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown *//* Offset 06h FLCTL */union ich8_hws_flash_ctrl {	struct ich8_hsflctl {		u16 flcgo      :1;   /* 0 Flash Cycle Go */		u16 flcycle    :2;   /* 2:1 Flash Cycle */		u16 reserved   :5;   /* 7:3 Reserved  */		u16 fldbcount  :2;   /* 9:8 Flash Data Byte Count */		u16 flockdn    :6;   /* 15:10 Reserved */	} hsf_ctrl;	u16 regval;};/* ICH Flash Region Access Permissions */union ich8_hws_flash_regacc {	struct ich8_flracc {		u32 grra      :8; /* 0:7 GbE region Read Access */		u32 grwa      :8; /* 8:15 GbE region Write Access */		u32 gmrag     :8; /* 23:16 GbE Master Read Access Grant */		u32 gmwag     :8; /* 31:24 GbE Master Write Access Grant */	} hsf_flregacc;	u16 regval;};static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,						u32 offset, u8 byte);static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,					 u16 *data);static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,					 u8 size, u16 *data);static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg){	return readw(hw->flash_address + reg);}static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg){	return readl(hw->flash_address + reg);}static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val){	writew(val, hw->flash_address + reg);}static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val){	writel(val, hw->flash_address + reg);}#define er16flash(reg)		__er16flash(hw, (reg))#define er32flash(reg)		__er32flash(hw, (reg))#define ew16flash(reg,val)	__ew16flash(hw, (reg), (val))#define ew32flash(reg,val)	__ew32flash(hw, (reg), (val))/** *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers *  @hw: pointer to the HW structure * *  Initialize family-specific PHY parameters and function pointers. **/static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 i = 0;	phy->addr			= 1;	phy->reset_delay_us		= 100;	/*	 * We may need to do this twice - once for IGP and if that fails,	 * we'll set BM func pointers and try again	 */	ret_val = e1000e_determine_phy_address(hw);	if (ret_val) {		hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;		hw->phy.ops.read_phy_reg  = e1000e_read_phy_reg_bm;		ret_val = e1000e_determine_phy_address(hw);		if (ret_val)			return ret_val;	}	phy->id = 0;	while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&	       (i++ < 100)) {		msleep(1);		ret_val = e1000e_get_phy_id(hw);		if (ret_val)			return ret_val;	}	/* Verify phy id */	switch (phy->id) {	case IGP03E1000_E_PHY_ID:		phy->type = e1000_phy_igp_3;		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;		break;	case IFE_E_PHY_ID:	case IFE_PLUS_E_PHY_ID:	case IFE_C_E_PHY_ID:		phy->type = e1000_phy_ife;		phy->autoneg_mask = E1000_ALL_NOT_GIG;		break;	case BME1000_E_PHY_ID:		phy->type = e1000_phy_bm;		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;		hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;		hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;		hw->phy.ops.commit_phy = e1000e_phy_sw_reset;		break;	default:		return -E1000_ERR_PHY;		break;	}	return 0;}/** *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers *  @hw: pointer to the HW structure * *  Initialize family-specific NVM parameters and function *  pointers. **/static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw){	struct e1000_nvm_info *nvm = &hw->nvm;	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;	u32 gfpreg;	u32 sector_base_addr;	u32 sector_end_addr;	u16 i;	/* Can't read flash registers if the register set isn't mapped. */	if (!hw->flash_address) {		hw_dbg(hw, "ERROR: Flash registers not mapped\n");		return -E1000_ERR_CONFIG;	}	nvm->type = e1000_nvm_flash_sw;	gfpreg = er32flash(ICH_FLASH_GFPREG);	/*	 * sector_X_addr is a "sector"-aligned address (4096 bytes)	 * Add 1 to sector_end_addr since this sector is included in	 * the overall size.	 */	sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;	sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;	/* flash_base_addr is byte-aligned */	nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;	/*	 * find total size of the NVM, then cut in half since the total	 * size represents two separate NVM banks.	 */	nvm->flash_bank_size = (sector_end_addr - sector_base_addr)				<< FLASH_SECTOR_ADDR_SHIFT;	nvm->flash_bank_size /= 2;	/* Adjust to word count */	nvm->flash_bank_size /= sizeof(u16);	nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;	/* Clear shadow ram */	for (i = 0; i < nvm->word_size; i++) {		dev_spec->shadow_ram[i].modified = 0;		dev_spec->shadow_ram[i].value    = 0xFFFF;	}	return 0;}/** *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers *  @hw: pointer to the HW structure * *  Initialize family-specific MAC parameters and function *  pointers. **/static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	struct e1000_mac_info *mac = &hw->mac;	/* Set media type function pointer */	hw->phy.media_type = e1000_media_type_copper;	/* Set mta register count */	mac->mta_reg_count = 32;	/* Set rar entry count */	mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;	if (mac->type == e1000_ich8lan)		mac->rar_entry_count--;	/* Set if manageability features are enabled. */	mac->arc_subsystem_valid = 1;	/* Enable PCS Lock-loss workaround for ICH8 */	if (mac->type == e1000_ich8lan)		e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 1);	return 0;}static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	s32 rc;	rc = e1000_init_mac_params_ich8lan(adapter);	if (rc)		return rc;	rc = e1000_init_nvm_params_ich8lan(hw);	if (rc)		return rc;	rc = e1000_init_phy_params_ich8lan(hw);	if (rc)		return rc;	if (adapter->hw.phy.type == e1000_phy_ife)		adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;	switch (adapter->hw.mac.type) {	case e1000_ich8lan:		if (adapter->hw.phy.type == e1000_phy_igp_3)			adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;		break;	default:		break;	}	return 0;}/** *  e1000_acquire_swflag_ich8lan - Acquire software control flag *  @hw: pointer to the HW structure * *  Acquires the software control flag for performing NVM and PHY *  operations.  This is a function pointer entry point only called by *  read/write routines for the PHY and NVM parts. **/static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw){	u32 extcnf_ctrl;	u32 timeout = PHY_CFG_TIMEOUT;	while (timeout) {		extcnf_ctrl = er32(EXTCNF_CTRL);		extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;		ew32(EXTCNF_CTRL, extcnf_ctrl);		extcnf_ctrl = er32(EXTCNF_CTRL);		if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)			break;		mdelay(1);		timeout--;	}	if (!timeout) {		hw_dbg(hw, "FW or HW has locked the resource for too long.\n");		extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;		ew32(EXTCNF_CTRL, extcnf_ctrl);		return -E1000_ERR_CONFIG;	}	return 0;}/** *  e1000_release_swflag_ich8lan - Release software control flag *  @hw: pointer to the HW structure * *  Releases the software control flag for performing NVM and PHY operations. *  This is a function pointer entry point only called by read/write *  routines for the PHY and NVM parts. **/static void e1000_release_swflag_ich8lan(struct e1000_hw *hw){	u32 extcnf_ctrl;	extcnf_ctrl = er32(EXTCNF_CTRL);	extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;	ew32(EXTCNF_CTRL, extcnf_ctrl);}/** *  e1000_check_reset_block_ich8lan - Check if PHY reset is blocked *  @hw: pointer to the HW structure * *  Checks if firmware is blocking the reset of the PHY. *  This is a function pointer entry point only called by *  reset routines. **/static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw){	u32 fwsm;	fwsm = er32(FWSM);	return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;}/** *  e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex *  @hw: pointer to the HW structure * *  Forces the speed and duplex settings of the PHY. *  This is a function pointer entry point only called by *  PHY setup routines. **/static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	s32 ret_val;	u16 data;	bool link;	if (phy->type != e1000_phy_ife) {		ret_val = e1000e_phy_force_speed_duplex_igp(hw);		return ret_val;	}	ret_val = e1e_rphy(hw, PHY_CONTROL, &data);	if (ret_val)		return ret_val;	e1000e_phy_force_speed_duplex_setup(hw, &data);	ret_val = e1e_wphy(hw, PHY_CONTROL, data);	if (ret_val)		return ret_val;	/* Disable MDI-X support for 10/100 */	ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);	if (ret_val)		return ret_val;	data &= ~IFE_PMC_AUTO_MDIX;	data &= ~IFE_PMC_FORCE_MDIX;

⌨️ 快捷键说明

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