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

📄 e1000_main.c

📁 linux系统的网卡驱动包
💻 C
📖 第 1 页 / 共 5 页
字号:
 **/static void e1000_irq_disable(struct e1000_adapter *adapter){	atomic_inc(&adapter->irq_sem);	E1000_WRITE_REG(&adapter->hw, E1000_IMC, ~0);	E1000_WRITE_FLUSH(&adapter->hw);	synchronize_irq(adapter->pdev->irq);}/** * e1000_irq_enable - Enable default interrupt generation settings * @adapter: board private structure **/static void e1000_irq_enable(struct e1000_adapter *adapter){	if (likely(atomic_dec_and_test(&adapter->irq_sem))) {		E1000_WRITE_REG(&adapter->hw, E1000_IMS, IMS_ENABLE_MASK);		E1000_WRITE_FLUSH(&adapter->hw);	}}#ifdef NETIF_F_HW_VLAN_TXstatic void e1000_update_mng_vlan(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	u16 vid = adapter->hw.mng_cookie.vlan_id;	u16 old_vid = adapter->mng_vlan_id;	if (adapter->vlgrp) {		if (!vlan_group_get_device(adapter->vlgrp, vid)) {			if (adapter->hw.mng_cookie.status &				E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {				e1000_vlan_rx_add_vid(netdev, vid);				adapter->mng_vlan_id = vid;			} else {				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;			}			if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&					(vid != old_vid) &&			    !vlan_group_get_device(adapter->vlgrp, old_vid))				e1000_vlan_rx_kill_vid(netdev, old_vid);		} else {			adapter->mng_vlan_id = vid;		}	}}#endif/** * e1000_release_hw_control - release control of the h/w to f/w * @adapter: address of board private structure * * e1000_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that the * driver is no longer loaded. For AMT version (only with 82573) i * of the f/w this means that the network i/f is closed. * **/static void e1000_release_hw_control(struct e1000_adapter *adapter){	u32 ctrl_ext;	u32 swsm;	/* Let firmware taken over control of h/w */	switch (adapter->hw.mac.type) {	case e1000_82573:		swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM);		E1000_WRITE_REG(&adapter->hw, E1000_SWSM,				swsm & ~E1000_SWSM_DRV_LOAD);		break;	case e1000_82571:	case e1000_82572:	case e1000_80003es2lan:	case e1000_ich8lan:	case e1000_ich9lan:		ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT);		E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT,				ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);		break;	default:		break;	}}/** * e1000_get_hw_control - get control of the h/w from f/w * @adapter: address of board private structure * * e1000_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that * the driver is loaded. For AMT version (only with 82573) * of the f/w this means that the network i/f is open. * **/static void e1000_get_hw_control(struct e1000_adapter *adapter){	u32 ctrl_ext;	u32 swsm;	/* Let firmware know the driver has taken over */	switch (adapter->hw.mac.type) {	case e1000_82573:		swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM);		E1000_WRITE_REG(&adapter->hw, E1000_SWSM,				swsm | E1000_SWSM_DRV_LOAD);		break;	case e1000_82571:	case e1000_82572:	case e1000_80003es2lan:	case e1000_ich8lan:	case e1000_ich9lan:		ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT);		E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT,				ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);		break;	default:		break;	}}static void e1000_init_manageability(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	if (adapter->en_mng_pt) {		u32 manc = E1000_READ_REG(hw, E1000_MANC);		/* disable hardware interception of ARP, only valid to do on		 * PCI/PCI-X hardware */		if (hw->mac.type < e1000_82571)			manc &= ~(E1000_MANC_ARP_EN);		/* enable receiving management packets to the host */		/* this will probably generate destination unreachable messages		 * from the host OS, but the packets will be handled on SMBUS */		if (adapter->flags & E1000_FLAG_HAS_MANC2H) {			u32 manc2h = E1000_READ_REG(hw, E1000_MANC2H);			manc |= E1000_MANC_EN_MNG2HOST;#define E1000_MNG2HOST_PORT_623 (1 << 5)#define E1000_MNG2HOST_PORT_664 (1 << 6)			manc2h |= E1000_MNG2HOST_PORT_623;			manc2h |= E1000_MNG2HOST_PORT_664;			E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);		}		E1000_WRITE_REG(hw, E1000_MANC, manc);	}}static void e1000_release_manageability(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	if (adapter->en_mng_pt) {		u32 manc = E1000_READ_REG(hw, E1000_MANC);		/* re-enable hardware interception of ARP */		if (hw->mac.type < e1000_82571)			manc |= E1000_MANC_ARP_EN;		/* This is asymmetric with init_manageability, as we want to		 * ensure that MNG2HOST filters are still enabled after this		 * driver is unloaded as other host drivers such as PXE also		 * may require these filters. */		/* XXX stop the hardware watchdog ? */		E1000_WRITE_REG(hw, E1000_MANC, manc);	}}/** * e1000_configure - configure the hardware for RX and TX * @adapter: private board structure **/static void e1000_configure(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	int i;	e1000_set_multi(netdev);#ifdef NETIF_F_HW_VLAN_TX	e1000_restore_vlan(adapter);#endif	e1000_init_manageability(adapter);	e1000_configure_tx(adapter);	e1000_setup_rctl(adapter);	e1000_configure_rx(adapter);	/* call E1000_DESC_UNUSED which always leaves	 * at least 1 descriptor unused to make sure	 * next_to_use != next_to_clean */	for (i = 0; i < adapter->num_rx_queues; i++) {		struct e1000_rx_ring *ring = &adapter->rx_ring[i];		adapter->alloc_rx_buf(adapter, ring,		                      E1000_DESC_UNUSED(ring));	}#ifdef CONFIG_E1000_MQ	e1000_setup_queue_mapping(adapter);#endif	adapter->tx_queue_len = netdev->tx_queue_len;}static void e1000_napi_enable_all(struct e1000_adapter *adapter){#ifdef CONFIG_E1000_NAPI	int i;	for (i = 0; i < adapter->num_rx_queues; i++)		napi_enable(&adapter->rx_ring[i].napi);#endif}static void e1000_napi_disable_all(struct e1000_adapter *adapter){#ifdef CONFIG_E1000_NAPI	int i;	for (i = 0; i < adapter->num_rx_queues; i++)		napi_disable(&adapter->rx_ring[i].napi);#endif}int e1000_up(struct e1000_adapter *adapter){	/* hardware has been reset, we need to reload some things */	e1000_configure(adapter);	clear_bit(__E1000_DOWN, &adapter->state);	e1000_napi_enable_all(adapter);	e1000_irq_enable(adapter);	/* fire a link change interrupt to start the watchdog */	E1000_WRITE_REG(&adapter->hw, E1000_ICS, E1000_ICS_LSC);	return 0;}void e1000_down(struct e1000_adapter *adapter){	struct net_device *netdev = adapter->netdev;	u32 tctl, rctl;	/* signal that we're down so the interrupt handler does not	 * reschedule our watchdog timer */	set_bit(__E1000_DOWN, &adapter->state);	/* disable receives in the hardware */	rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);	E1000_WRITE_REG(&adapter->hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);	/* flush and sleep below */#ifdef NETIF_F_LLTX	netif_stop_queue(netdev);#else	netif_tx_disable(netdev);#endif	/* disable transmits in the hardware */	tctl = E1000_READ_REG(&adapter->hw, E1000_TCTL);	tctl &= ~E1000_TCTL_EN;	E1000_WRITE_REG(&adapter->hw, E1000_TCTL, tctl);	/* flush both disables and wait for them to finish */	E1000_WRITE_FLUSH(&adapter->hw);	msleep(10);	e1000_napi_disable_all(adapter);	e1000_irq_disable(adapter);	del_timer_sync(&adapter->tx_fifo_stall_timer);	del_timer_sync(&adapter->watchdog_timer);	del_timer_sync(&adapter->phy_info_timer);	netdev->tx_queue_len = adapter->tx_queue_len;	netif_carrier_off(netdev);	adapter->link_speed = 0;	adapter->link_duplex = 0;	e1000_reset(adapter);	e1000_clean_all_tx_rings(adapter);	e1000_clean_all_rx_rings(adapter);}void e1000_reinit_locked(struct e1000_adapter *adapter){	WARN_ON(in_interrupt());	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))		msleep(1);	e1000_down(adapter);	e1000_up(adapter);	clear_bit(__E1000_RESETTING, &adapter->state);}void e1000_reset(struct e1000_adapter *adapter){	struct e1000_mac_info *mac = &adapter->hw.mac;	struct e1000_fc_info *fc = &adapter->hw.fc;	u32 pba = 0, tx_space, min_tx_space, min_rx_space;	bool legacy_pba_adjust = FALSE;	u16 hwm;	/* Repartition Pba for greater than 9k mtu	 * To take effect CTRL.RST is required.	 */	switch (mac->type) {	case e1000_82542:	case e1000_82543:	case e1000_82544:	case e1000_82540:	case e1000_82541:	case e1000_82541_rev_2:		legacy_pba_adjust = TRUE;		pba = E1000_PBA_48K;		break;	case e1000_82545:	case e1000_82545_rev_3:	case e1000_82546:	case e1000_82546_rev_3:		pba = E1000_PBA_48K;		break;	case e1000_82547:	case e1000_82547_rev_2:		legacy_pba_adjust = TRUE;		pba = E1000_PBA_30K;		break;	case e1000_82571:	case e1000_82572:	case e1000_80003es2lan:		pba = E1000_PBA_38K;		break;	case e1000_82573:		pba = E1000_PBA_20K;		break;	case e1000_ich8lan:		pba = E1000_PBA_8K;		break;	case e1000_ich9lan:#define E1000_PBA_10K 0x000A		pba = E1000_PBA_10K;		break;	case e1000_undefined:	case e1000_num_macs:		break;	}	if (legacy_pba_adjust == TRUE) {		if (adapter->max_frame_size > E1000_RXBUFFER_8192)			pba -= 8; /* allocate more FIFO for Tx */		if (mac->type == e1000_82547) {			adapter->tx_fifo_head = 0;			adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;			adapter->tx_fifo_size =				(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;			atomic_set(&adapter->tx_fifo_stall, 0);		}	} else if (adapter->max_frame_size > ETH_FRAME_LEN + ETHERNET_FCS_SIZE) {		/* adjust PBA for jumbo frames */		E1000_WRITE_REG(&adapter->hw, E1000_PBA, pba);		/* To maintain wire speed transmits, the Tx FIFO should be		 * large enough to accommodate two full transmit packets,		 * rounded up to the next 1KB and expressed in KB.  Likewise,		 * the Rx FIFO should be large enough to accommodate at least		 * one full receive packet and is similarly rounded up and		 * expressed in KB. */		pba = E1000_READ_REG(&adapter->hw, E1000_PBA);		/* upper 16 bits has Tx packet buffer allocation size in KB */		tx_space = pba >> 16;		/* lower 16 bits has Rx packet buffer allocation size in KB */		pba &= 0xffff;		/* the tx fifo also stores 16 bytes of information about the tx		 * but don't include ethernet FCS because hardware appends it */		min_tx_space = (adapter->max_frame_size +		                sizeof(struct e1000_tx_desc) -		                ETHERNET_FCS_SIZE) * 2;		min_tx_space = ALIGN(min_tx_space, 1024);		min_tx_space >>= 10;		/* software strips receive CRC, so leave room for it */		min_rx_space = adapter->max_frame_size;		min_rx_space = ALIGN(min_rx_space, 1024);		min_rx_space >>= 10;		/* If current Tx allocation is less than the min Tx FIFO size,		 * and the min Tx FIFO size is less than the current Rx FIFO		 * allocation, take space away from current Rx allocation */		if (tx_space < min_tx_space &&		    ((min_tx_space - tx_space) < pba)) {			pba = pba - (min_tx_space - tx_space);			/* PCI/PCIx hardware has PBA alignment constraints */			switch (mac->type) {			case e1000_82545 ... e1000_82546_rev_3:				pba &= ~(E1000_PBA_8K - 1);				break;			default:				break;			}			/* if short on rx space, rx wins and must trump tx			 * adjustment or use Early Receive if available */			if (pba < min_rx_space) {				switch (mac->type) {				case e1000_82573:				case e1000_ich9lan:					/* ERT enabled in e1000_configure_rx */					break;				default:					pba = min_rx_space;					break;				}			}		}

⌨️ 快捷键说明

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