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

📄 e1000_main.c

📁 linux系统的网卡驱动包
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	E1000_WRITE_REG(&adapter->hw, E1000_PBA, pba);	/* flow control settings */	/* The high water mark must be low enough to fit one full frame	 * (or the size used for early receive) above it in the Rx FIFO.	 * Set it to the lower of:	 * - 90% of the Rx FIFO size, and	 * - the full Rx FIFO size minus the early receive size (for parts	 *   with ERT support assuming ERT set to E1000_ERT_2048), or	 * - the full Rx FIFO size minus one full frame */	hwm = min(((pba << 10) * 9 / 10),	          ((mac->type == e1000_82573 || mac->type == e1000_ich9lan) ?	              (u16)((pba << 10) - (E1000_ERT_2048 << 3)) :	              ((pba << 10) - adapter->max_frame_size)));	fc->high_water = hwm & 0xFFF8;	/* 8-byte granularity */	fc->low_water = fc->high_water - 8;	if (mac->type == e1000_80003es2lan)		fc->pause_time = 0xFFFF;	else		fc->pause_time = E1000_FC_PAUSE_TIME;	fc->send_xon = 1;	fc->type = fc->original_type;	/* Allow time for pending master requests to run */	e1000_reset_hw(&adapter->hw);	/* For 82573 and ICHx if AMT is enabled, let the firmware know	 * that the network interface is in control */	if (((adapter->hw.mac.type == e1000_82573) ||	     (adapter->hw.mac.type == e1000_ich8lan) ||	     (adapter->hw.mac.type == e1000_ich9lan)) &&	    e1000_check_mng_mode(&adapter->hw))		e1000_get_hw_control(adapter);	if (mac->type >= e1000_82544)		E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0);	if (e1000_init_hw(&adapter->hw))		DPRINTK(PROBE, ERR, "Hardware Error\n");#ifdef NETIF_F_HW_VLAN_TX	e1000_update_mng_vlan(adapter);#endif	/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */	if (mac->type >= e1000_82544 &&	    mac->type <= e1000_82547_rev_2 &&	    mac->autoneg == 1 &&	    adapter->hw.phy.autoneg_advertised == ADVERTISE_1000_FULL) {		u32 ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL);		/* clear phy power management bit if we are in gig only mode,		 * which if enabled will attempt negotiation to 100Mb, which		 * can cause a loss of link at power off or driver unload */		ctrl &= ~E1000_CTRL_SWDPIN3;		E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl);	}#if defined(CONFIG_PPC64) || defined(CONFIG_PPC)#define E1000_GCR_DISABLE_TIMEOUT_MECHANISM 0x80000000	if (adapter->hw.mac.type == e1000_82571) {		/* work around pSeries hardware by disabling timeouts */		u32 gcr = E1000_READ_REG(&adapter->hw, E1000_GCR);		gcr |= E1000_GCR_DISABLE_TIMEOUT_MECHANISM;		E1000_WRITE_REG(&adapter->hw, E1000_GCR, gcr);	}#endif	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */	E1000_WRITE_REG(&adapter->hw, E1000_VET, ETHERNET_IEEE_VLAN_TYPE);	e1000_reset_adaptive(&adapter->hw);	e1000_get_phy_info(&adapter->hw);	if (!(adapter->flags & E1000_FLAG_SMART_POWER_DOWN) &&	    (mac->type == e1000_82571 || mac->type == e1000_82572)) {		u16 phy_data = 0;		/* speed up time to link by disabling smart power down, ignore		 * the return value of this function because there is nothing		 * different we would do if it failed */		e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,		                   &phy_data);		phy_data &= ~IGP02E1000_PM_SPD;		e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,		                    phy_data);	}	e1000_release_manageability(adapter);}/** * e1000_probe - Device Initialization Routine * @pdev: PCI device information struct * @ent: entry in e1000_pci_tbl * * Returns 0 on success, negative on failure * * e1000_probe initializes an adapter identified by a pci_dev structure. * The OS initialization, configuring of the adapter private structure, * and a hardware reset occur. **/static int __devinit e1000_probe(struct pci_dev *pdev,                                 const struct pci_device_id *ent){	struct net_device *netdev;	struct e1000_adapter *adapter;	static int cards_found = 0;	static int global_quad_port_a = 0; /* global ksp3 port a indication */	int i, err, pci_using_dac;	u16 eeprom_data = 0;	u16 eeprom_apme_mask = E1000_EEPROM_APME;	if ((err = pci_enable_device(pdev)))		return err;	if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&	    !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {		pci_using_dac = 1;	} else {		if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&		    (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {			E1000_ERR("No usable DMA configuration, aborting\n");			goto err_dma;		}		pci_using_dac = 0;	}	if ((err = pci_request_regions(pdev, e1000_driver_name)))		goto err_pci_reg;	pci_set_master(pdev);	err = -ENOMEM;#ifdef CONFIG_E1000_MQ	netdev = alloc_etherdev(sizeof(struct e1000_adapter) +		(sizeof(struct net_device_subqueue) * E1000_MAX_TX_QUEUES));#else	netdev = alloc_etherdev(sizeof(struct e1000_adapter));#endif	if (!netdev)		goto err_alloc_etherdev;	SET_MODULE_OWNER(netdev);	SET_NETDEV_DEV(netdev, &pdev->dev);	pci_set_drvdata(pdev, netdev);	adapter = netdev_priv(netdev);	adapter->netdev = netdev;	adapter->pdev = pdev;	adapter->hw.back = adapter;	adapter->msg_enable = (1 << debug) - 1;	err = -EIO;	adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),	                              pci_resource_len(pdev, BAR_0));	if (!adapter->hw.hw_addr)		goto err_ioremap;	for (i = BAR_1; i <= BAR_5; i++) {		if (pci_resource_len(pdev, i) == 0)			continue;		if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {			adapter->hw.io_base = pci_resource_start(pdev, i);			break;		}	}	netdev->open = &e1000_open;	netdev->stop = &e1000_close;	netdev->hard_start_xmit = &e1000_xmit_frame;#ifdef CONFIG_E1000_MQ	netdev->hard_start_subqueue_xmit = &e1000_subqueue_xmit_frame;#endif	netdev->get_stats = &e1000_get_stats;	netdev->set_multicast_list = &e1000_set_multi;	netdev->set_mac_address = &e1000_set_mac;	netdev->change_mtu = &e1000_change_mtu;	netdev->do_ioctl = &e1000_ioctl;	e1000_set_ethtool_ops(netdev);#ifdef HAVE_TX_TIMEOUT	netdev->tx_timeout = &e1000_tx_timeout;	netdev->watchdog_timeo = 5 * HZ;#endif#ifdef NETIF_F_HW_VLAN_TX	netdev->vlan_rx_register = e1000_vlan_rx_register;	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;#endif#ifdef CONFIG_NET_POLL_CONTROLLER	netdev->poll_controller = e1000_netpoll;#endif	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);	adapter->bd_number = cards_found;	/* setup the private structure */	if ((err = e1000_sw_init(adapter)))		goto err_sw_init;	err = -EIO;	/* Flash BAR mapping must happen after e1000_sw_init	 * because it depends on mac.type */	if (((adapter->hw.mac.type == e1000_ich8lan) ||	     (adapter->hw.mac.type == e1000_ich9lan)) &&	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {		adapter->hw.flash_address = ioremap(pci_resource_start(pdev, 1),		                                    pci_resource_len(pdev, 1));		if (!adapter->hw.flash_address)			goto err_flashmap;	}	if ((err = e1000_init_mac_params(&adapter->hw)))		goto err_hw_init;	if ((err = e1000_init_nvm_params(&adapter->hw)))		goto err_hw_init;	if ((err = e1000_init_phy_params(&adapter->hw)))		goto err_hw_init;	e1000_get_bus_info(&adapter->hw);	e1000_init_script_state_82541(&adapter->hw, TRUE);	e1000_set_tbi_compatibility_82543(&adapter->hw, TRUE);	adapter->hw.phy.autoneg_wait_to_complete = FALSE;	adapter->hw.mac.adaptive_ifs = TRUE;	/* Copper options */	if (adapter->hw.phy.media_type == e1000_media_type_copper) {		adapter->hw.phy.mdix = AUTO_ALL_MODES;		adapter->hw.phy.disable_polarity_correction = FALSE;		adapter->hw.phy.ms_type = E1000_MASTER_SLAVE;	}	if (e1000_check_reset_block(&adapter->hw))		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");#ifdef MAX_SKB_FRAGS	if (adapter->hw.mac.type >= e1000_82543) {#ifdef NETIF_F_HW_VLAN_TX		netdev->features = NETIF_F_SG |				   NETIF_F_HW_CSUM |				   NETIF_F_HW_VLAN_TX |				   NETIF_F_HW_VLAN_RX |				   NETIF_F_HW_VLAN_FILTER;		if ((adapter->hw.mac.type == e1000_ich8lan) ||		    (adapter->hw.mac.type == e1000_ich9lan))			netdev->features &= ~NETIF_F_HW_VLAN_FILTER;#else		netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM;#endif	}#ifdef NETIF_F_TSO	if ((adapter->hw.mac.type >= e1000_82544) &&	   (adapter->hw.mac.type != e1000_82547)) {		adapter->flags |= E1000_FLAG_HAS_TSO;		netdev->features |= NETIF_F_TSO;	}#ifdef NETIF_F_TSO6	if (adapter->hw.mac.type > e1000_82547_rev_2) {		adapter->flags |= E1000_FLAG_HAS_TSO6;		netdev->features |= NETIF_F_TSO6;	}#endif#endif	if (pci_using_dac)		netdev->features |= NETIF_F_HIGHDMA;#endif#ifdef NETIF_F_LLTX	netdev->features |= NETIF_F_LLTX;#endif	/* Hardware features, flags and workarounds */	if (adapter->hw.mac.type >= e1000_82571) {		adapter->flags |= E1000_FLAG_INT_ASSERT_AUTO_MASK;		adapter->flags |= E1000_FLAG_HAS_MSI;		adapter->flags |= E1000_FLAG_HAS_MANC2H;	}	if (adapter->hw.mac.type >= e1000_82540) {		adapter->flags |= E1000_FLAG_HAS_SMBUS;		adapter->flags |= E1000_FLAG_HAS_INTR_MODERATION;	}	if (adapter->hw.mac.type == e1000_82543)		adapter->flags |= E1000_FLAG_BAD_TX_CARRIER_STATS_FD;	/* In rare occasions, ESB2 systems would end up started without	 * the RX unit being turned on. */	if (adapter->hw.mac.type == e1000_80003es2lan)		adapter->flags |= E1000_FLAG_RX_NEEDS_RESTART;	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);	/* before reading the NVM, reset the controller to	 * put the device in a known good starting state */	e1000_reset_hw(&adapter->hw);	/* make sure we don't intercept ARP packets until we're up */	e1000_release_manageability(adapter);	/* make sure the NVM is good */	if (e1000_validate_nvm_checksum(&adapter->hw) < 0) {		DPRINTK(PROBE, ERR, "The NVM Checksum Is Not Valid\n");		err = -EIO;		goto err_eeprom;	}	/* copy the MAC address out of the NVM */	if (e1000_read_mac_addr(&adapter->hw))		DPRINTK(PROBE, ERR, "NVM Read Error\n");	memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);#ifdef ETHTOOL_GPERMADDR	memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);	if (!is_valid_ether_addr(netdev->perm_addr)) {#else	if (!is_valid_ether_addr(netdev->dev_addr)) {#endif		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");		err = -EIO;		goto err_eeprom;	}	init_timer(&adapter->tx_fifo_stall_timer);	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;	adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;	init_timer(&adapter->watchdog_timer);	adapter->watchdog_timer.function = &e1000_watchdog;	adapter->watchdog_timer.data = (unsigned long) adapter;	init_timer(&adapter->phy_info_timer);	adapter->phy_info_timer.function = &e1000_update_phy_info;	adapter->phy_info_timer.data = (unsigned long) adapter;	INIT_WORK(&adapter->reset_task, e1000_reset_task);	INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);	e1000_check_options(adapter);	/* Initial Wake on LAN setting	 * If APM wake is enabled in the EEPROM,	 * enable the ACPI Magic Packet filter	 */	switch (adapter->hw.mac.type) {	case e1000_82542:	case e1000_82543:		break;	case e1000_82544:		e1000_read_nvm(&adapter->hw,			NVM_INIT_CONTROL2_REG, 1, &eeprom_data);		eeprom_apme_mask = E1000_EEPROM_82544_APM;		break;	case e1000_ich8lan:	case e1000_ich9lan:		/* APME bit in EEPROM is mapped to WUC.APME */		eeprom_data = E1000_READ_REG(&adapter->hw, E1000_WUC);		eeprom_apme_mask = E1000_WUC_APME;		break;	case e1000_82546:	case e1000_82546_rev_3:	case e1000_82571:	case e1000_80003es2lan:		if (adapter->hw.bus.func == 1) {			e1000_read_nvm(&adapter->hw,				NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);			break;		}		/* Fall Through */	default:		e1000_read_nvm(&adapter->hw,			NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);		break;	}	if (eeprom_data & eeprom_apme_mask)		adapter->eeprom_wol |= E1000_WUFC_MAG;	/* now that we have the eeprom settings, apply the special cases	 * where the eeprom may be wrong or the board simply won't support	 * wake on lan on a particular port */	switch (pdev->device) {	case E1000_DEV_ID_82546GB_PCIE:	case E1000_DEV_ID_82571EB_SERDES_QUAD:		adapter->eeprom_wol = 0;		break;	case E1000_DEV_ID_82546EB_FIBER:	case E1000_DEV_ID_82546GB_FIBER:	case E1000_DEV_ID_82571EB_FIBER:		/* Wake events only supported on port A for dual fiber		 * regardless of eeprom setting */		if (E1000_READ_REG(&adapter->hw, E1000_STATUS) &		    E1000_STATUS_FUNC_1)			adapter->eeprom_wol = 0;		break;	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:	case E1000_DEV_ID_82571EB_QUAD_COPPER:	case E1000_DEV_ID_82571EB_QUAD_FIBER:	case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:	case E1000_DEV_ID_82571PT_QUAD_COPPER:		/* if quad port adapter, disable WoL on all but port A */		if (global_quad_port_a != 0)			adapter->eeprom_wol = 0;		else			adapter->flags |= E1000_FLAG_QUAD_PORT_A;		/* Reset for multiple quad port adapters */		if (++global_quad_port_a == 4)			global_quad_port_a = 0;

⌨️ 快捷键说明

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