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

📄 ixgbe_82598.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************  Intel 10 Gigabit PCI Express 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*******************************************************************************/#include <linux/pci.h>#include <linux/delay.h>#include <linux/sched.h>#include "ixgbe.h"#include "ixgbe_phy.h"#define IXGBE_82598_MAX_TX_QUEUES 32#define IXGBE_82598_MAX_RX_QUEUES 64#define IXGBE_82598_RAR_ENTRIES   16static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw);static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,					 bool *autoneg);static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,						u32 *speed, bool *autoneg);static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw);static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw);static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,				      bool *link_up);static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw, u32 speed,					    bool autoneg,					    bool autoneg_wait_to_complete);static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw);static s32 ixgbe_check_copper_link_82598(struct ixgbe_hw *hw, u32 *speed,					 bool *link_up);static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,					       bool autoneg,					       bool autoneg_wait_to_complete);static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw){	hw->mac.num_rx_queues = IXGBE_82598_MAX_TX_QUEUES;	hw->mac.num_tx_queues = IXGBE_82598_MAX_RX_QUEUES;	hw->mac.num_rx_addrs = IXGBE_82598_RAR_ENTRIES;	return 0;}/** *  ixgbe_get_link_settings_82598 - Determines default link settings *  @hw: pointer to hardware structure *  @speed: pointer to link speed *  @autoneg: boolean auto-negotiation value * *  Determines the default link settings by reading the AUTOC register. **/static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,					 bool *autoneg){	s32 status = 0;	s32 autoc_reg;	autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);	if (hw->mac.link_settings_loaded) {		autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;		autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;		autoc_reg |= hw->mac.link_attach_type;		autoc_reg |= hw->mac.link_mode_select;	}	switch (autoc_reg & IXGBE_AUTOC_LMS_MASK) {	case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:		*speed = IXGBE_LINK_SPEED_1GB_FULL;		*autoneg = false;		break;	case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:		*speed = IXGBE_LINK_SPEED_10GB_FULL;		*autoneg = false;		break;	case IXGBE_AUTOC_LMS_1G_AN:		*speed = IXGBE_LINK_SPEED_1GB_FULL;		*autoneg = true;		break;	case IXGBE_AUTOC_LMS_KX4_AN:	case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:		*speed = IXGBE_LINK_SPEED_UNKNOWN;		if (autoc_reg & IXGBE_AUTOC_KX4_SUPP)			*speed |= IXGBE_LINK_SPEED_10GB_FULL;		if (autoc_reg & IXGBE_AUTOC_KX_SUPP)			*speed |= IXGBE_LINK_SPEED_1GB_FULL;		*autoneg = true;		break;	default:		status = IXGBE_ERR_LINK_SETUP;		break;	}	return status;}/** *  ixgbe_get_copper_link_settings_82598 - Determines default link settings *  @hw: pointer to hardware structure *  @speed: pointer to link speed *  @autoneg: boolean auto-negotiation value * *  Determines the default link settings by reading the AUTOC register. **/static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,						u32 *speed, bool *autoneg){	s32 status = IXGBE_ERR_LINK_SETUP;	u16 speed_ability;	*speed = 0;	*autoneg = true;	status = ixgbe_read_phy_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,				    IXGBE_MDIO_PMA_PMD_DEV_TYPE,				    &speed_ability);	if (status == 0) {		if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)		    *speed |= IXGBE_LINK_SPEED_10GB_FULL;		if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)		    *speed |= IXGBE_LINK_SPEED_1GB_FULL;	}	return status;}/** *  ixgbe_get_media_type_82598 - Determines media type *  @hw: pointer to hardware structure * *  Returns the media type (fiber, copper, backplane) **/static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw){	enum ixgbe_media_type media_type;	/* Media type for I82598 is based on device ID */	switch (hw->device_id) {	case IXGBE_DEV_ID_82598AF_DUAL_PORT:	case IXGBE_DEV_ID_82598AF_SINGLE_PORT:	case IXGBE_DEV_ID_82598EB_CX4:		media_type = ixgbe_media_type_fiber;		break;	case IXGBE_DEV_ID_82598AT_DUAL_PORT:		media_type = ixgbe_media_type_copper;		break;	default:		media_type = ixgbe_media_type_unknown;		break;	}	return media_type;}/** *  ixgbe_setup_mac_link_82598 - Configures MAC link settings *  @hw: pointer to hardware structure * *  Configures link settings based on values in the ixgbe_hw struct. *  Restarts the link.  Performs autonegotiation if needed. **/static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw){	u32 autoc_reg;	u32 links_reg;	u32 i;	s32 status = 0;	autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);	if (hw->mac.link_settings_loaded) {		autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;		autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;		autoc_reg |= hw->mac.link_attach_type;		autoc_reg |= hw->mac.link_mode_select;		IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);		msleep(50);	}	/* Restart link */	autoc_reg |= IXGBE_AUTOC_AN_RESTART;	IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);	/* Only poll for autoneg to complete if specified to do so */	if (hw->phy.autoneg_wait_to_complete) {		if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||		    hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {			links_reg = 0; /* Just in case Autoneg time = 0 */			for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {				links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);				if (links_reg & IXGBE_LINKS_KX_AN_COMP)					break;				msleep(100);			}			if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {				status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;				hw_dbg(hw,				       "Autonegotiation did not complete.\n");			}		}	}	/*	 * We want to save off the original Flow Control configuration just in	 * case we get disconnected and then reconnected into a different hub	 * or switch with different Flow Control capabilities.	 */	hw->fc.type = hw->fc.original_type;	ixgbe_setup_fc(hw, 0);	/* Add delay to filter out noises during initial link setup */	msleep(50);	return status;}/** *  ixgbe_check_mac_link_82598 - Get link/speed status *  @hw: pointer to hardware structure *  @speed: pointer to link speed *  @link_up: true is link is up, false otherwise * *  Reads the links register to determine if link is up and the current speed **/static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,				      bool *link_up){	u32 links_reg;	links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);	if (links_reg & IXGBE_LINKS_UP)		*link_up = true;	else		*link_up = false;	if (links_reg & IXGBE_LINKS_SPEED)		*speed = IXGBE_LINK_SPEED_10GB_FULL;	else		*speed = IXGBE_LINK_SPEED_1GB_FULL;	return 0;}/** *  ixgbe_setup_mac_link_speed_82598 - Set MAC link speed *  @hw: pointer to hardware structure *  @speed: new link speed *  @autoneg: true if auto-negotiation enabled *  @autoneg_wait_to_complete: true if waiting is needed to complete * *  Set the link speed in the AUTOC register and restarts link. **/static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,					    u32 speed, bool autoneg,					    bool autoneg_wait_to_complete){	s32 status = 0;	/* If speed is 10G, then check for CX4 or XAUI. */	if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&	    (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4)))		hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;

⌨️ 快捷键说明

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