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

📄 e1000_main.c

📁 linux下的软件
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* 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.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_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);	/* If the controller is 82573 or ICH 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) &&	     (adapter->hw.mac.type != e1000_ich8lan) &&	     (adapter->hw.mac.type != e1000_ich9lan)) ||	    !e1000_check_mng_mode(&adapter->hw))		e1000_get_hw_control(adapter);	/* tell the stack to leave us alone until e1000_open() is called */	netif_carrier_off(netdev);	netif_stop_queue(netdev);#ifdef CONFIG_E1000_NAPI	netif_poll_disable(netdev);#endif	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:	e1000_release_hw_control(adapter);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);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. **/static void __devexit e1000_remove(struct pci_dev *pdev){	struct net_device *netdev = pci_get_drvdata(pdev);	struct e1000_adapter *adapter = netdev_priv(netdev);#ifdef CONFIG_E1000_NAPI	int i;#endif	/* 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);	/* Release control of h/w to f/w.  If f/w is AMT enabled, this	 * would have already happened in close and is redundant. */	e1000_release_hw_control(adapter);	unregister_netdev(netdev);#ifdef CONFIG_E1000_NAPI	for (i = 0; i < adapter->num_rx_queues; i++)		dev_put(&adapter->polling_netdev[i]);#endif	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);#ifdef CONFIG_E1000_NAPI	kfree(adapter->polling_netdev);#endif	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->rx_ps_bsize0 = E1000_RXBUFFER_128;	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;	}#ifdef CONFIG_E1000_MQ	/* Number of supported queues.	 * TODO: It's assumed num_rx_queues >= num_tx_queues, since multi-rx	 * queues are much more interesting.  Is it worth coding for the	 * possibility (however improbable) of num_tx_queues > num_rx_queues?	 */	switch (hw->mac.type) {	case e1000_82571:	case e1000_82572:	case e1000_82573:	case e1000_80003es2lan:		adapter->num_tx_queues = 2;		adapter->num_rx_queues = 2;		break;	case e1000_ich8lan:	case e1000_ich9lan:		if ((adapter->hw.device_id == E1000_DEV_ID_ICH8_IGP_AMT) ||		    (adapter->hw.device_id == E1000_DEV_ID_ICH8_IGP_M_AMT) ||		    (adapter->hw.device_id == E1000_DEV_ID_ICH9_IGP_AMT)) {			adapter->num_tx_queues = 2;			adapter->num_rx_queues = 2;			break;		}		/* Fall through - remaining ICH SKUs do not support MQ */	default:		/* All hardware before 82571 only have 1 queue each for Rx/Tx.		 * However, the 82571 family does not have MSI-X, so multi-		 * queue isn't enabled.		 * It'd be wise not to mess with this default case. :) */		adapter->num_tx_queues = 1;		adapter->num_rx_queues = 1;		netdev->egress_subqueue_count = 0;		break;	}	adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());	adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());	if ((adapter->num_tx_queues > 1) || (adapter->num_rx_queues > 1)) {		netdev->egress_subqueue = (struct net_device_subqueue *)		                           ((void *)adapter +		                            sizeof(struct e1000_adapter));		netdev->egress_subqueue_count = adapter->num_tx_queues;		DPRINTK(DRV, INFO, "Multiqueue Enabled: RX queues = %u, "		        "TX queues = %u\n", adapter->num_rx_queues,		        adapter->num_tx_queues);	}#else	adapter->num_tx_queues = 1;	adapter->num_rx_queues = 1;#endif	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++) {		adapter->polling_netdev[i].priv = adapter;		adapter->polling_netdev[i].poll = &e1000_clean;		adapter->polling_netdev[i].weight = 64;		dev_hold(&adapter->polling_netdev[i]);		set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);	}	spin_lock_init(&adapter->tx_queue_lock);#ifdef CONFIG_E1000_MQ	for (i = 0; i < adapter->num_tx_queues; i++)		spin_lock_init(&adapter->tx_ring[i].tx_queue_lock);#endif#endif	/* Explicitly disable IRQ since the NIC can be in any state. */	atomic_set(&adapter->irq_sem, 0);	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 * * We allocate one ring per queue at run-time since we don't know the * number of queues at compile-time.  The polling_netdev array is * intended for Multiqueue, but should work fine with a single queue. **/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;	}#ifdef CONFIG_E1000_NAPI	adapter->polling_netdev = kcalloc(adapter->num_rx_queues,	                                  sizeof(struct net_device),	                                  GFP_KERNEL);	if (!adapter->polling_netdev) {		kfree(adapter->tx_ring);		kfree(adapter->rx_ring);		return -ENOMEM;	}#endif#ifdef CONFIG_E1000_MQ	adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);#endif	return E1000_SUCCESS;}#ifdef CONFIG_E1000_MQstatic void e1000_setup_queue_mapping(struct e1000_adapter *adapter){	int i, cpu;	lock_cpu_hotplug();	i = 0;	for_each_online_cpu(cpu) {		*per_cpu_ptr(adapter->cpu_tx_ring, cpu) =		             &adapter->tx_ring[i % adapter->num_tx_queues];		i++;	}	unlock_cpu_hotplug();}#endif#ifdef CONFIG_PCI_MSI/** * e1000_intr_msi_test - Interrupt Handler * @irq: interrupt number * @data: pointer to a network interface device structure **/static irqreturn_t e1000_intr_msi_test(int irq, void *data){	struct net_device *netdev = data;	struct e1000_adapter *adapter = netdev_priv(netdev);	u32 icr = E1000_READ_REG(&adapter->hw, E1000_ICR);	DPRINTK(HW,INFO, "icr is %08X\n", icr);	if (icr & E1000_ICR_RXSEQ) {		adapter->flags.has_msi = 1;		wmb();	}		return IRQ_HANDLED;}/** * e1000_test_msi_interrupt - Returns 0 for successful test * @adapter: board private struct * * code flow taken from tg3.c **/static int e1000_test_msi_interrupt(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;

⌨️ 快捷键说明

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