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

📄 e1000_ethtool.c

📁 COPE the first practical network coding scheme which is developped on click
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************    Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.    This program is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the Free   Software Foundation; either version 2 of the License, or (at your option)   any later version.    This program is distributed in the hope that 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., 59   Temple Place - Suite 330, Boston, MA  02111-1307, USA.    The full GNU General Public License is included in this distribution in the  file called LICENSE.    Contact Information:  Linux NICS <linux.nics@intel.com>  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497*******************************************************************************//* ethtool support for e1000 */#include "e1000.h"#ifdef	SIOCETHTOOL#include <asm/uaccess.h>extern char e1000_driver_name[];extern char e1000_driver_version[];extern int e1000_up(struct e1000_adapter *adapter);extern void e1000_down(struct e1000_adapter *adapter);extern void e1000_reset(struct e1000_adapter *adapter);static voide1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd){	struct e1000_hw *hw = &adapter->hw;	if(hw->media_type == e1000_media_type_copper) {		ecmd->supported = (SUPPORTED_10baseT_Half |		                   SUPPORTED_10baseT_Full |		                   SUPPORTED_100baseT_Half |		                   SUPPORTED_100baseT_Full |		                   SUPPORTED_1000baseT_Full|		                   SUPPORTED_Autoneg |		                   SUPPORTED_TP);		ecmd->advertising = ADVERTISED_TP;		if(hw->autoneg == 1) {			ecmd->advertising |= ADVERTISED_Autoneg;			/* the e1000 autoneg seems to match ethtool nicely */			ecmd->advertising |= hw->autoneg_advertised;		}		ecmd->port = PORT_TP;		ecmd->phy_address = hw->phy_addr;		if(hw->mac_type == e1000_82543)			ecmd->transceiver = XCVR_EXTERNAL;		else			ecmd->transceiver = XCVR_INTERNAL;	} else {		ecmd->supported   = (SUPPORTED_1000baseT_Full |				     SUPPORTED_FIBRE |				     SUPPORTED_Autoneg);		ecmd->advertising = (SUPPORTED_1000baseT_Full |				     SUPPORTED_FIBRE |				     SUPPORTED_Autoneg);		ecmd->port = PORT_FIBRE;		if(hw->mac_type >= e1000_82545)			ecmd->transceiver = XCVR_INTERNAL;		else			ecmd->transceiver = XCVR_EXTERNAL;	}	if(netif_carrier_ok(adapter->netdev)) {		e1000_get_speed_and_duplex(hw, &adapter->link_speed,		                                   &adapter->link_duplex);		ecmd->speed = adapter->link_speed;		/* unfortunatly FULL_DUPLEX != DUPLEX_FULL		 *          and HALF_DUPLEX != DUPLEX_HALF */		if(adapter->link_duplex == FULL_DUPLEX)			ecmd->duplex = DUPLEX_FULL;		else			ecmd->duplex = DUPLEX_HALF;	} else {		ecmd->speed = -1;		ecmd->duplex = -1;	}	ecmd->autoneg = (hw->autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);}static inte1000_ethtool_sset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd){	struct e1000_hw *hw = &adapter->hw;	if(ecmd->autoneg == AUTONEG_ENABLE) {		hw->autoneg = 1;		hw->autoneg_advertised = (ecmd->advertising & 0x002F);	} else {		hw->autoneg = 0;		switch(ecmd->speed + ecmd->duplex) {		case SPEED_10 + DUPLEX_HALF:			hw->forced_speed_duplex = e1000_10_half;			break;		case SPEED_10 + DUPLEX_FULL:			hw->forced_speed_duplex = e1000_10_full;			break;		case SPEED_100 + DUPLEX_HALF:			hw->forced_speed_duplex = e1000_100_half;			break;		case SPEED_100 + DUPLEX_FULL:			hw->forced_speed_duplex = e1000_100_full;			break;		case SPEED_1000 + DUPLEX_FULL:			hw->autoneg = 1;			hw->autoneg_advertised = ADVERTISE_1000_FULL;			break;		case SPEED_1000 + DUPLEX_HALF: /* not supported */		default:			return -EINVAL;		}	}	/* reset the link */	if(netif_running(adapter->netdev)) {		e1000_down(adapter);		e1000_up(adapter);	} else		e1000_reset(adapter);	return 0;}#ifdef	ETHTOOL_GEEPROMstatic inline inte1000_eeprom_size(struct e1000_hw *hw){	if((hw->mac_type > e1000_82544) &&	   (E1000_READ_REG(hw, EECD) & E1000_EECD_SIZE))		return 512;	else		return 128;}#endif	/* ETHTOOL_GEEPROM */#ifdef	ETHTOOL_GDRVINFOstatic voide1000_ethtool_gdrvinfo(struct e1000_adapter *adapter,                       struct ethtool_drvinfo *drvinfo){	strncpy(drvinfo->driver,  e1000_driver_name, 32);	strncpy(drvinfo->version, e1000_driver_version, 32);	strncpy(drvinfo->fw_version, "N/A", 32);	strncpy(drvinfo->bus_info, adapter->pdev->slot_name, 32);#ifdef	ETHTOOL_GEEPROM  /* GREGS broken in earlier ethtool.h */#ifdef	ETHTOOL_GREGS#define E1000_REGS_LEN 32	drvinfo->regdump_len  = E1000_REGS_LEN * sizeof(uint32_t);#endif	/* ETHTOOL_GREGS */#endif	/* ETHTOOL_GEEPROM */#ifdef	ETHTOOL_GEEPROM	drvinfo->eedump_len  = e1000_eeprom_size(&adapter->hw);#endif	/* ETHTOOL_GEEPROM */}#endif	/* ETHTOOL_GDRVINFO */#ifdef	ETHTOOL_GEEPROM  /* GREGS broken in earlier ethtool.h */#ifdef  ETHTOOL_GREGSstatic voide1000_ethtool_gregs(struct e1000_adapter *adapter,                    struct ethtool_regs *regs, uint32_t *regs_buff){	struct e1000_hw *hw = &adapter->hw;	regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;	regs_buff[0]  = E1000_READ_REG(hw, CTRL);	regs_buff[1]  = E1000_READ_REG(hw, STATUS);	regs_buff[2]  = E1000_READ_REG(hw, RCTL);	regs_buff[3]  = E1000_READ_REG(hw, RDLEN);	regs_buff[4]  = E1000_READ_REG(hw, RDH);	regs_buff[5]  = E1000_READ_REG(hw, RDT);	regs_buff[6]  = E1000_READ_REG(hw, RDTR);		regs_buff[7]  = E1000_READ_REG(hw, TCTL);	regs_buff[8]  = E1000_READ_REG(hw, TDLEN);	regs_buff[9]  = E1000_READ_REG(hw, TDH);	regs_buff[10] = E1000_READ_REG(hw, TDT);	regs_buff[11] = E1000_READ_REG(hw, TIDV);	return;}#endif  /* ETHTOOL_GREGS */#endif	/* ETHTOOL_GEEPROM */#ifdef	ETHTOOL_GEEPROMstatic voide1000_ethtool_geeprom(struct e1000_adapter *adapter,                      struct ethtool_eeprom *eeprom, uint16_t *eeprom_buff){	struct e1000_hw *hw = &adapter->hw;	int i, max_len, first_word, last_word;	if(eeprom->len == 0) return;	eeprom->magic = hw->vendor_id | (hw->device_id << 16);	max_len = e1000_eeprom_size(hw);	if((eeprom->offset + eeprom->len) > max_len)		eeprom->len = (max_len - eeprom->offset);	first_word = eeprom->offset >> 1;	last_word = (eeprom->offset + eeprom->len - 1) >> 1;	for(i = 0; i <= (last_word - first_word); i++)		e1000_read_eeprom(hw, first_word + i, &eeprom_buff[i]);}#endif	/* ETHTOOL_GEEPROM */#ifdef	ETHTOOL_SEEPROMstatic int e1000_ethtool_seeprom(struct e1000_adapter *adapter,                      struct ethtool_eeprom *eeprom, void *user_data){	struct e1000_hw *hw = &adapter->hw;	uint16_t eeprom_buff[256];	int i, max_len, first_word, last_word;	void *ptr;	if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))		return -EFAULT;	if(eeprom->len == 0) return 0;	max_len = e1000_eeprom_size(hw);	if((eeprom->offset + eeprom->len) > max_len)		eeprom->len = (max_len - eeprom->offset);	first_word = eeprom->offset >> 1;	last_word = (eeprom->offset + eeprom->len - 1) >> 1;	ptr = (void *)eeprom_buff;	if(eeprom->offset & 1) {		/* need read/modify/write of first changed EEPROM word */		/* only the second byte of the word is being modified */		e1000_read_eeprom(hw, first_word, &eeprom_buff[0]);		ptr++;	}	if((eeprom->offset + eeprom->len) & 1) {		/* need read/modify/write of last changed EEPROM word */		/* only the first byte of the word is being modified */		e1000_read_eeprom(hw, last_word,		                  &eeprom_buff[last_word - first_word]);	}	if(copy_from_user(ptr, user_data, eeprom->len))		return -EFAULT;	for(i = 0; i <= (last_word - first_word); i++)		e1000_write_eeprom(hw, first_word + i, eeprom_buff[i]);	/* Update the checksum over the first part of the EEPROM if needed */	if(first_word <= EEPROM_CHECKSUM_REG)		e1000_update_eeprom_checksum(hw);	return 0;}#endif	/* ETHTOOL_SEEPROM */

⌨️ 快捷键说明

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