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

📄 e1000_82541.c

📁 linux下的网卡驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************  Intel PRO/1000 Linux driver  Copyright(c) 1999 - 2007 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*******************************************************************************//* e1000_82541 * e1000_82547 * e1000_82541_rev_2 * e1000_82547_rev_2 */#include "e1000_api.h"#include "e1000_82541.h"void e1000_init_function_pointers_82541(struct e1000_hw *hw);static s32  e1000_init_phy_params_82541(struct e1000_hw *hw);static s32  e1000_init_nvm_params_82541(struct e1000_hw *hw);static s32  e1000_init_mac_params_82541(struct e1000_hw *hw);static s32  e1000_reset_hw_82541(struct e1000_hw *hw);static s32  e1000_init_hw_82541(struct e1000_hw *hw);static s32  e1000_get_link_up_info_82541(struct e1000_hw *hw, u16 *speed,                                         u16 *duplex);static s32  e1000_phy_hw_reset_82541(struct e1000_hw *hw);static s32  e1000_setup_copper_link_82541(struct e1000_hw *hw);static s32  e1000_check_for_link_82541(struct e1000_hw *hw);static s32  e1000_get_cable_length_igp_82541(struct e1000_hw *hw);static s32  e1000_set_d3_lplu_state_82541(struct e1000_hw *hw,                                          boolean_t active);static s32  e1000_setup_led_82541(struct e1000_hw *hw);static s32  e1000_cleanup_led_82541(struct e1000_hw *hw);static void e1000_clear_hw_cntrs_82541(struct e1000_hw *hw);static s32  e1000_config_dsp_after_link_change_82541(struct e1000_hw *hw,                                                     boolean_t link_up);static s32  e1000_phy_init_script_82541(struct e1000_hw *hw);static const u16 e1000_igp_cable_length_table[] =    { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,      5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,      25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,      40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,      60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,      90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,      100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,      110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};#define IGP01E1000_AGC_LENGTH_TABLE_SIZE \                (sizeof(e1000_igp_cable_length_table) / \                 sizeof(e1000_igp_cable_length_table[0]))struct e1000_dev_spec_82541 {	e1000_dsp_config dsp_config;	e1000_ffe_config ffe_config;	u16 spd_default;	boolean_t phy_init_script;};/** *  e1000_init_phy_params_82541 - Init PHY func ptrs. *  @hw: pointer to the HW structure * *  This is a function pointer entry point called by the api module. **/static s32 e1000_init_phy_params_82541(struct e1000_hw *hw){	struct e1000_phy_info *phy = &hw->phy;	struct e1000_functions *func = &hw->func;	s32 ret_val = E1000_SUCCESS;	DEBUGFUNC("e1000_init_phy_params_82541");	phy->addr                       = 1;	phy->autoneg_mask               = AUTONEG_ADVERTISE_SPEED_DEFAULT;	phy->reset_delay_us             = 10000;	phy->type                       = e1000_phy_igp;	/* Function Pointers */	func->check_polarity            = e1000_check_polarity_igp;	func->force_speed_duplex        = e1000_phy_force_speed_duplex_igp;	func->get_cable_length          = e1000_get_cable_length_igp_82541;	func->get_cfg_done              = e1000_get_cfg_done_generic;	func->get_phy_info              = e1000_get_phy_info_igp;	func->read_phy_reg              = e1000_read_phy_reg_igp;	func->reset_phy                 = e1000_phy_hw_reset_82541;	func->set_d3_lplu_state         = e1000_set_d3_lplu_state_82541;	func->write_phy_reg             = e1000_write_phy_reg_igp;	ret_val = e1000_get_phy_id(hw);	if (ret_val)		goto out;	/* Verify phy id */	if (phy->id != IGP01E1000_I_PHY_ID) {		ret_val = -E1000_ERR_PHY;		goto out;	}out:	return ret_val;}/** *  e1000_init_nvm_params_82541 - Init NVM func ptrs. *  @hw: pointer to the HW structure * *  This is a function pointer entry point called by the api module. **/static s32 e1000_init_nvm_params_82541(struct e1000_hw *hw){	struct   e1000_nvm_info *nvm = &hw->nvm;	struct e1000_functions *func = &hw->func;	s32  ret_val = E1000_SUCCESS;	u32 eecd = E1000_READ_REG(hw, E1000_EECD);	u16 size;	DEBUGFUNC("e1000_init_nvm_params_82541");	switch (nvm->override) {	case e1000_nvm_override_spi_large:		nvm->type = e1000_nvm_eeprom_spi;		eecd |= E1000_EECD_ADDR_BITS;		break;	case e1000_nvm_override_spi_small:		nvm->type = e1000_nvm_eeprom_spi;		eecd &= ~E1000_EECD_ADDR_BITS;		break;	case e1000_nvm_override_microwire_large:		nvm->type = e1000_nvm_eeprom_microwire;		eecd |= E1000_EECD_SIZE;		break;	case e1000_nvm_override_microwire_small:		nvm->type = e1000_nvm_eeprom_microwire;		eecd &= ~E1000_EECD_SIZE;		break;	default:		nvm->type = eecd & E1000_EECD_TYPE		            ? e1000_nvm_eeprom_spi		            : e1000_nvm_eeprom_microwire;		break;	}	if (nvm->type == e1000_nvm_eeprom_spi) {		nvm->address_bits       = (eecd & E1000_EECD_ADDR_BITS)		                          ? 16 : 8;		nvm->delay_usec         = 1;		nvm->opcode_bits        = 8;		nvm->page_size          = (eecd & E1000_EECD_ADDR_BITS)		                          ? 32 : 8;		/* Function Pointers */		func->acquire_nvm       = e1000_acquire_nvm_generic;		func->read_nvm          = e1000_read_nvm_spi;		func->release_nvm       = e1000_release_nvm_generic;		func->update_nvm        = e1000_update_nvm_checksum_generic;		func->valid_led_default = e1000_valid_led_default_generic;		func->validate_nvm      = e1000_validate_nvm_checksum_generic;		func->write_nvm         = e1000_write_nvm_spi;		/* nvm->word_size must be discovered after the pointers		 * are set so we can verify the size from the nvm image		 * itself.  Temporarily set it to a dummy value so the		 * read will work.		 */		nvm->word_size = 64;		ret_val = e1000_read_nvm(hw, NVM_CFG, 1, &size);		if (ret_val)			goto out;		size = (size & NVM_SIZE_MASK) >> NVM_SIZE_SHIFT;		/* if size != 0, it can be added to a constant and become		 * the left-shift value to set the word_size.  Otherwise,		 * word_size stays at 64.		 */		if (size) {			size += NVM_WORD_SIZE_BASE_SHIFT_82541;			nvm->word_size = 1 << size;		}	} else {		nvm->address_bits       = (eecd & E1000_EECD_ADDR_BITS)		                          ? 8 : 6;		nvm->delay_usec         = 50;		nvm->opcode_bits        = 3;		nvm->word_size          = (eecd & E1000_EECD_ADDR_BITS)		                          ? 256 : 64;		/* Function Pointers */		func->acquire_nvm       = e1000_acquire_nvm_generic;		func->read_nvm          = e1000_read_nvm_microwire;		func->release_nvm       = e1000_release_nvm_generic;		func->update_nvm        = e1000_update_nvm_checksum_generic;		func->valid_led_default = e1000_valid_led_default_generic;		func->validate_nvm      = e1000_validate_nvm_checksum_generic;		func->write_nvm         = e1000_write_nvm_microwire;	}out:	return ret_val;}/** *  e1000_init_mac_params_82541 - Init MAC func ptrs. *  @hw: pointer to the HW structure * *  This is a function pointer entry point called by the api module. **/static s32 e1000_init_mac_params_82541(struct e1000_hw *hw){	struct e1000_mac_info *mac = &hw->mac;	struct e1000_functions *func = &hw->func;	s32 ret_val;	DEBUGFUNC("e1000_init_mac_params_82541");	/* Set media type */	hw->media_type = e1000_media_type_copper;	/* Set mta register count */	mac->mta_reg_count = 128;	/* Set rar entry count */	mac->rar_entry_count = E1000_RAR_ENTRIES;	/* Set if part includes ASF firmware */	mac->asf_firmware_present = TRUE;	/* Function Pointers */	/* bus type/speed/width */	func->get_bus_info = e1000_get_bus_info_pci_generic;	/* reset */	func->reset_hw = e1000_reset_hw_82541;	/* hw initialization */	func->init_hw = e1000_init_hw_82541;	/* link setup */	func->setup_link = e1000_setup_link_generic;	/* physical interface link setup */	func->setup_physical_interface = e1000_setup_copper_link_82541;	/* check for link */	func->check_for_link = e1000_check_for_link_82541;	/* link info */	func->get_link_up_info = e1000_get_link_up_info_82541;	/* multicast address update */	func->mc_addr_list_update = e1000_mc_addr_list_update_generic;	/* writing VFTA */	func->write_vfta = e1000_write_vfta_generic;	/* clearing VFTA */	func->clear_vfta = e1000_clear_vfta_generic;	/* setting MTA */	func->mta_set = e1000_mta_set_generic;	/* setup LED */	func->setup_led = e1000_setup_led_82541;	/* cleanup LED */	func->cleanup_led = e1000_cleanup_led_82541;	/* turn on/off LED */	func->led_on = e1000_led_on_generic;	func->led_off = e1000_led_off_generic;	/* remove device */	func->remove_device = e1000_remove_device_generic;	/* clear hardware counters */	func->clear_hw_cntrs = e1000_clear_hw_cntrs_82541;	hw->dev_spec_size = sizeof(struct e1000_dev_spec_82541);	/* Device-specific structure allocation */	ret_val = e1000_alloc_zeroed_dev_spec_struct(hw, hw->dev_spec_size);	return ret_val;}/** *  e1000_init_function_pointers_82541 - Init func ptrs. *  @hw: pointer to the HW structure * *  The only function explicitly called by the api module to initialize *  all function pointers and parameters. **/void e1000_init_function_pointers_82541(struct e1000_hw *hw){	DEBUGFUNC("e1000_init_function_pointers_82541");	hw->func.init_mac_params = e1000_init_mac_params_82541;	hw->func.init_nvm_params = e1000_init_nvm_params_82541;	hw->func.init_phy_params = e1000_init_phy_params_82541;}/** *  e1000_reset_hw_82541 - Reset hardware *  @hw: pointer to the HW structure * *  This resets the hardware into a known state.  This is a *  function pointer entry point called by the api module. **/static s32 e1000_reset_hw_82541(struct e1000_hw *hw){	u32 ledctl, ctrl, icr, manc;	DEBUGFUNC("e1000_reset_hw_82541");	DEBUGOUT("Masking off all interrupts\n");	E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);	E1000_WRITE_REG(hw, E1000_RCTL, 0);	E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);	E1000_WRITE_FLUSH(hw);	/* Delay to allow any outstanding PCI transactions to complete	 * before resetting the device.	 */	msec_delay(10);	ctrl = E1000_READ_REG(hw, E1000_CTRL);	/* Must reset the Phy before resetting the MAC */	if ((hw->mac.type == e1000_82541) || (hw->mac.type == e1000_82547)) {		E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_PHY_RST));		msec_delay(5);	}	DEBUGOUT("Issuing a global reset to 82541/82547 MAC\n");	switch (hw->mac.type) {	case e1000_82541:	case e1000_82541_rev_2:		/* These controllers can't ack the 64-bit write when		 * issuing the reset, so we use IO-mapping as a		 * workaround to issue the reset.		 */		E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);		break;	default:		E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);		break;	}	/* Wait for NVM reload */	msec_delay(20);	/* Disable HW ARPs on ASF enabled adapters */	manc = E1000_READ_REG(hw, E1000_MANC);	manc &= ~E1000_MANC_ARP_EN;	E1000_WRITE_REG(hw, E1000_MANC, manc);	if ((hw->mac.type == e1000_82541) || (hw->mac.type == e1000_82547)) {		e1000_phy_init_script_82541(hw);		/* Configure activity LED after Phy reset */		ledctl = E1000_READ_REG(hw, E1000_LEDCTL);		ledctl &= IGP_ACTIVITY_LED_MASK;		ledctl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);		E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);	}	/* Once again, mask the interrupts */	DEBUGOUT("Masking off all interrupts\n");	E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);	/* Clear any pending interrupt events. */	icr = E1000_READ_REG(hw, E1000_ICR);	return E1000_SUCCESS;}/** *  e1000_init_hw_82541 - Initialize hardware *  @hw: pointer to the HW structure * *  This inits the hardware readying it for operation.  This is a *  function pointer entry point called by the api module. **/static s32 e1000_init_hw_82541(struct e1000_hw *hw){	struct e1000_mac_info *mac = &hw->mac;	u32 i, txdctl;	s32 ret_val;	DEBUGFUNC("e1000_init_hw_82541");	/* Initialize identification LED */	ret_val = e1000_id_led_init_generic(hw);	if (ret_val) {		DEBUGOUT("Error initializing identification LED\n");		goto out;	}	/* Disabling VLAN filtering */	DEBUGOUT("Initializing the IEEE VLAN\n");	e1000_clear_vfta(hw);	/* Setup the receive address. */	e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);	/* Zero out the Multicast HASH table */	DEBUGOUT("Zeroing the MTA\n");	for (i = 0; i < mac->mta_reg_count; i++) {		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);		/* Avoid back to back register writes by adding the register		 * read (flush).  This is to protect against some strange		 * bridge configurations that may issue Memory Write Block		 * (MWB) to our register space.		 */		E1000_WRITE_FLUSH(hw);	}	/* Setup link and flow control */	ret_val = e1000_setup_link(hw);	txdctl = E1000_READ_REG(hw, E1000_TXDCTL);	txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |	         E1000_TXDCTL_FULL_TX_DESC_WB;	E1000_WRITE_REG(hw, E1000_TXDCTL, txdctl);	/* Clear all of the statistics registers (clear on read).  It is	 * important that we do this after we have tried to establish link	 * because the symbol error count will increment wildly if there

⌨️ 快捷键说明

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