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

📄 e1000_main.c

📁 e1000 8.0.1 version.最新的e1000 linux下的驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* 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_82546:	case e1000_82546_rev_3:		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:		adapter->eeprom_wol = 0;		break;	case E1000_DEV_ID_82546EB_FIBER:	case E1000_DEV_ID_82546GB_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:		/* 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;		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_pcie_x4) ? "Width x4" :		 (hw->bus.width == e1000_bus_width_pcie_x1) ? "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);	/* tell the stack to leave us alone until e1000_open() is called */	netif_carrier_off(netdev);	netif_stop_queue(netdev);	strcpy(netdev->name, "eth%d");	err = register_netdev(netdev);	if (err)		goto err_register;	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");	cards_found++;	return 0;err_register:err_hw_init:err_eeprom:	if (!e1000_check_reset_block(&adapter->hw))		e1000_phy_hw_reset(&adapter->hw);	if (adapter->hw.flash_address)		iounmap(adapter->hw.flash_address);	e1000_remove_device(&adapter->hw);	kfree(adapter->tx_ring);	kfree(adapter->rx_ring);err_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. **/static void __devexit e1000_remove(struct pci_dev *pdev){	struct net_device *netdev = pci_get_drvdata(pdev);	struct e1000_adapter *adapter = netdev_priv(netdev);	/* flush_scheduled work may reschedule our watchdog task, so	 * explicitly disable watchdog tasks from being rescheduled  */	set_bit(__E1000_DOWN, &adapter->state);	del_timer_sync(&adapter->tx_fifo_stall_timer);	del_timer_sync(&adapter->watchdog_timer);	del_timer_sync(&adapter->phy_info_timer);	flush_scheduled_work();	e1000_release_manageability(adapter);	unregister_netdev(netdev);	if (!e1000_check_reset_block(&adapter->hw))		e1000_phy_hw_reset(&adapter->hw);	e1000_remove_device(&adapter->hw);	kfree(adapter->tx_ring);	kfree(adapter->rx_ring);	iounmap(adapter->hw.hw_addr);	if (adapter->hw.flash_address)		iounmap(adapter->hw.flash_address);	pci_release_regions(pdev);	free_netdev(netdev);	pci_disable_device(pdev);}/** * e1000_sw_init - Initialize general software structures (struct e1000_adapter) * @adapter: board private structure to initialize * * e1000_sw_init initializes the Adapter private data structure. * Fields are initialized based on PCI device information and * OS network device settings (MTU size). **/static int __devinit e1000_sw_init(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	struct net_device *netdev = adapter->netdev;	struct pci_dev *pdev = adapter->pdev;#ifdef CONFIG_E1000_NAPI	int i;#endif	/* PCI config space info */	hw->vendor_id = pdev->vendor;	hw->device_id = pdev->device;	hw->subsystem_vendor_id = pdev->subsystem_vendor;	hw->subsystem_device_id = pdev->subsystem_device;	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);	pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);	adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;	adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETHERNET_FCS_SIZE;	adapter->min_frame_size = ETH_ZLEN + ETHERNET_FCS_SIZE;	/* Initialize the hardware-specific values */	if (e1000_setup_init_funcs(hw, FALSE)) {		DPRINTK(PROBE, ERR, "Hardware Initialization Failure\n");		return -EIO;	}	adapter->num_tx_queues = 1;	adapter->num_rx_queues = 1;	if (e1000_alloc_queues(adapter)) {		DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");		return -ENOMEM;	}#ifdef CONFIG_E1000_NAPI	for (i = 0; i < adapter->num_rx_queues; i++) {		struct e1000_rx_ring *rx_ring = &adapter->rx_ring[i];		netif_napi_add(adapter->netdev, &rx_ring->napi, e1000_poll, 64);	}	spin_lock_init(&adapter->tx_queue_lock);#endif	/* Explicitly disable IRQ since the NIC can be in any state. */	e1000_irq_disable(adapter);	spin_lock_init(&adapter->stats_lock);	set_bit(__E1000_DOWN, &adapter->state);	return 0;}/** * e1000_alloc_queues - Allocate memory for all rings * @adapter: board private structure to initialize **/static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter){	adapter->tx_ring = kcalloc(adapter->num_tx_queues,	                           sizeof(struct e1000_tx_ring), GFP_KERNEL);	if (!adapter->tx_ring)		return -ENOMEM;	adapter->rx_ring = kcalloc(adapter->num_rx_queues,	                           sizeof(struct e1000_rx_ring), GFP_KERNEL);	if (!adapter->rx_ring) {		kfree(adapter->tx_ring);		return -ENOMEM;	}	return E1000_SUCCESS;}/** * e1000_open - Called when a network interface is made active * @netdev: network interface device structure * * Returns 0 on success, negative value on failure * * The open entry point is called when a network interface is made * active by the system (IFF_UP).  At this point all resources needed * for transmit and receive operations are allocated, the interrupt * handler is registered with the OS, the watchdog timer is started, * and the stack is notified that the interface is ready. **/static int e1000_open(struct net_device *netdev){	struct e1000_adapter *adapter = netdev_priv(netdev);	int err;	/* disallow open during test */	if (test_bit(__E1000_TESTING, &adapter->state))		return -EBUSY;	/* allocate transmit descriptors */	err = e1000_setup_all_tx_resources(adapter);	if (err)		goto err_setup_tx;	/* allocate receive descriptors */	err = e1000_setup_all_rx_resources(adapter);	if (err)		goto err_setup_rx;	if (adapter->hw.phy.media_type == e1000_media_type_copper)		e1000_power_up_phy(&adapter->hw);#ifdef NETIF_F_HW_VLAN_TX	adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;	if ((adapter->hw.mng_cookie.status &	     E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) {		e1000_update_mng_vlan(adapter);	}#endif	/* before we allocate an interrupt, we must be ready to handle it.	 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt	 * as soon as we call pci_request_irq, so we have to setup our	 * clean_rx handler before we do so.  */	e1000_configure(adapter);	err = e1000_request_irq(adapter);	if (err)		goto err_req_irq;	/* From here on the code is the same as e1000_up() */	clear_bit(__E1000_DOWN, &adapter->state);	e1000_napi_enable_all(adapter);	e1000_irq_enable(adapter);	/* fire a link status change interrupt to start the watchdog */	E1000_WRITE_REG(&adapter->hw, E1000_ICS, E1000_ICS_LSC);	return E1000_SUCCESS;err_req_irq:	/* Power down the PHY so no link is implied when interface is down *	 * The PHY cannot be powered down if any of the following is TRUE *	 * (a) WoL is enabled	 * (b) AMT is active	 * (c) SoL/IDER session is active */	if (!adapter->wol && adapter->hw.mac.type >= e1000_82540 &&	   adapter->hw.phy.media_type == e1000_media_type_copper)		e1000_power_down_phy(&adapter->hw);	e1000_free_all_rx_resources(adapter);err_setup_rx:	e1000_free_all_tx_resources(adapter);err_setup_tx:	e1000_reset(adapter);	return err;}/** * e1000_close - Disables a network interface * @netdev: network interface device structure * * Returns 0, this is not allowed to fail * * The close entry point is called when an interface is de-activated * by the OS.  The hardware is still under the drivers control, but * needs to be disabled.  A global MAC reset is issued to stop the * hardware, and all transmit and receive resources are freed. **/static int e1000_close(struct net_device *netdev){	struct e1000_adapter *adapter = netdev_priv(netdev);	WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));	e1000_down(adapter);	/* Power down the PHY so no link is implied when interface is down *	 * The PHY cannot be powered down if any of the following is TRUE *	 * (a) WoL is enabled	 * (b) AMT is active	 * (c) SoL/IDER session is active */	if (!adapter->wol && adapter->hw.mac.type >= e1000_82540 &&	   adapter->hw.phy.media_type == e1000_media_type_copper)		e1000_power_down_phy(&adapter->hw);	e1000_free_irq(adapter);	e1000_free_all_tx_resources(adapter);	e1000_free_all_rx_resources(adapter);#ifdef NETIF_F_HW_VLAN_TX	/* kill manageability vlan ID if supported, but not if a vlan with	 * the same ID is registered on the host OS (let 8021q kill it) */	if ((adapter->hw.mng_cookie.status &			  E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&	     !(adapter->vlgrp &&	       vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {		e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);	}#endif	return 0;}/** * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary * @adapter: address of board private structure * @start: address of beginning of memory * @len: length of memory **/static bool e1000_check_64k_bound(struct e1000_adapter *adapter,                                       void *start, unsigned long len){	unsigned long begin = (unsigned long) start;

⌨️ 快捷键说明

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