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

📄 e1000_main.c

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* Allow time for pending master requests to run */	e1000_reset_hw(&adapter->hw);	if (adapter->hw.mac_type >= e1000_82544)		E1000_WRITE_REG(&adapter->hw, 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 (adapter->hw.mac_type >= e1000_82544 &&	    adapter->hw.mac_type <= e1000_82547_rev_2 &&	    adapter->hw.autoneg == 1 &&	    adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {		uint32_t ctrl = E1000_READ_REG(&adapter->hw, 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, CTRL, ctrl);	}	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);	e1000_reset_adaptive(&adapter->hw);	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);	if (!adapter->smart_power_down &&	    (adapter->hw.mac_type == e1000_82571 ||	     adapter->hw.mac_type == e1000_82572)) {		uint16_t 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. **/#define SHOW_INTERFACE(d) printk("Interface mac_type=%d\n", d->hw.mac_type)static int __devinite1000_probe(struct pci_dev *pdev,            const struct pci_device_id *ent){	struct net_device *netdev;	struct e1000_adapter *adapter;	unsigned long mmio_start, mmio_len;	unsigned long flash_start, flash_len;	static int cards_found = 0;	static int global_quad_port_a = 0; /* global ksp3 port a indication */	int i, err, pci_using_dac;	uint16_t eeprom_data = 0;	uint16_t 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;	netdev = alloc_etherdev(sizeof(struct e1000_adapter));	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;	mmio_start = pci_resource_start(pdev, BAR_0);	mmio_len = pci_resource_len(pdev, BAR_0);	err = -EIO; 	SHOW_INTERFACE(adapter);	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);	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;	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 CONFIG_E1000_NAPI	netdev->poll = &e1000_clean;	netdev->weight = 64;#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        /* Click - polling extensions */        netdev->polling = 0;        netdev->rx_poll = e1000_rx_poll;        netdev->rx_refill = e1000_rx_refill;        netdev->tx_queue = e1000_tx_pqueue;        netdev->tx_eob = e1000_tx_eob;        netdev->tx_start = e1000_tx_start;        netdev->tx_clean = e1000_tx_clean;        netdev->poll_off = e1000_poll_off;        netdev->poll_on = e1000_poll_on;#ifdef CONFIG_NET_POLL_CONTROLLER	netdev->poll_controller = e1000_netpoll;#endif	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);	netdev->mem_start = mmio_start;	netdev->mem_end = mmio_start + mmio_len;	netdev->base_addr = adapter->hw.io_base;	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) &&	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {		flash_start = pci_resource_start(pdev, 1);		flash_len = pci_resource_len(pdev, 1);		adapter->hw.flash_address = ioremap(flash_start, flash_len);		if (!adapter->hw.flash_address)			goto err_flashmap;	}	if (e1000_check_phy_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)			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))		netdev->features |= NETIF_F_TSO;#ifdef CONFIG_DEBUG_SLAB	/* 82544's work arounds do not play nicely with DEBUG SLAB */	if (adapter->hw.mac_type == e1000_82544)		netdev->features &= ~NETIF_F_TSO;#endif#ifdef NETIF_F_TSO6	if (adapter->hw.mac_type > e1000_82547_rev_2)		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	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);	/* initialize eeprom parameters */	if (e1000_init_eeprom_params(&adapter->hw)) {		E1000_ERR("EEPROM initialization failed\n");		goto err_eeprom;	}	/* before reading the EEPROM, reset the controller to	 * put the device in a known good starting state */	e1000_reset_hw(&adapter->hw);	/* make sure the EEPROM is good */	if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");		goto err_eeprom;	}	/* copy the MAC address out of the EEPROM */	if (e1000_read_mac_addr(&adapter->hw))		DPRINTK(PROBE, ERR, "EEPROM Read Error\n");	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);	SHOW_INTERFACE(adapter);#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");		goto err_eeprom;	}	e1000_get_bus_info(&adapter->hw);	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,		(void (*)(void *))e1000_reset_task, netdev);	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_rev2_0:	case e1000_82542_rev2_1:	case e1000_82543:		break;	case e1000_82544:		e1000_read_eeprom(&adapter->hw,			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);		eeprom_apme_mask = E1000_EEPROM_82544_APM;		break;	case e1000_ich8lan:		e1000_read_eeprom(&adapter->hw,			EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);		eeprom_apme_mask = E1000_EEPROM_ICH8_APME;		break;	case e1000_82546:	case e1000_82546_rev_3:	case e1000_82571:	case e1000_80003es2lan:		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){			e1000_read_eeprom(&adapter->hw,				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);			break;		}		/* Fall Through */	default:		e1000_read_eeprom(&adapter->hw,			EEPROM_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:		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, 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_COPPER_LOWPROFILE:		/* if quad port adapter, disable WoL on all but port A */		if (global_quad_port_a != 0)			adapter->eeprom_wol = 0;		else			adapter->quad_port_a = 1;		/* Reset for multiple quad port adapters */		if (++global_quad_port_a == 4)			global_quad_port_a = 0;		break;	}	/* initialize the wol settings based on the eeprom settings */	adapter->wol = adapter->eeprom_wol;	/* print bus type/speed/width info */	{	struct e1000_hw *hw = &adapter->hw;	DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",		((hw->bus_type == e1000_bus_type_pcix) ? "-X" :		 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),		((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :		 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :		 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :		 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :		 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),		((hw->bus_width == e1000_bus_width_64) ? "64-bit" :		 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :		 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :		 "32-bit"));	}	for (i = 0; i < 6; i++)		printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');	/* reset the hardware with the new settings */	e1000_reset(adapter);	/* If the controller is 82573 and f/w is AMT, do not set	 * DRV_LOAD until the interface is up.  For all other cases,	 * let the f/w know that the h/w is now under the control	 * of the driver. */	if (adapter->hw.mac_type != e1000_82573 ||	    !e1000_check_mng_mode(&adapter->hw))		e1000_get_hw_control(adapter);	strcpy(netdev->name, "eth%d");	if ((err = register_netdev(netdev)))		goto err_register;	/* tell the stack to leave us alone until e1000_open() is called */	netif_carrier_off(netdev);	netif_stop_queue(netdev);	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");	cards_found++;	return 0;err_register:	e1000_release_hw_control(adapter);err_eeprom:	if (!e1000_check_phy_reset_block(&adapter->hw))		e1000_phy_hw_reset(&adapter->hw);	if (adapter->hw.flash_address)		iounmap(adapter->hw.flash_address);err_flashmap:#ifdef CONFIG_E1000_NAPI	for (i = 0; i < adapter->num_rx_queues; i++)		dev_put(&adapter->polling_netdev[i]);#endif	kfree(adapter->tx_ring);	kfree(adapter->rx_ring);#ifdef CONFIG_E1000_NAPI	kfree(adapter->polling_netdev);#endiferr_sw_init:	iounmap(adapter->hw.hw_addr);err_ioremap:	free_netdev(netdev);err_alloc_etherdev:	pci_release_regions(pdev);err_pci_reg:err_dma:	pci_disable_device(pdev);	return err;}/** * e1000_remove - Device Removal Routine * @pdev: PCI device information struct * * e1000_remove is called by the PCI subsystem to alert the driver * that it should release a PCI device.  The could be caused by a * Hot-Plug event, or because the driver is going to be removed from * memory.

⌨️ 快捷键说明

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