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

📄 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 页
字号:
		E1000_WRITE_REG(hw, TDLEN, tdlen);		E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));		E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));		E1000_WRITE_REG(hw, TDT, 0);		E1000_WRITE_REG(hw, TDH, 0);		adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);		adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);		break;	}	/* Set the default values for the Tx Inter Packet Gap timer */	if (adapter->hw.mac_type <= e1000_82547_rev_2 &&	    (hw->media_type == e1000_media_type_fiber ||	     hw->media_type == e1000_media_type_internal_serdes))		tipg = DEFAULT_82543_TIPG_IPGT_FIBER;	else		tipg = DEFAULT_82543_TIPG_IPGT_COPPER;	switch (hw->mac_type) {	case e1000_82542_rev2_0:	case e1000_82542_rev2_1:		tipg = DEFAULT_82542_TIPG_IPGT;		ipgr1 = DEFAULT_82542_TIPG_IPGR1;		ipgr2 = DEFAULT_82542_TIPG_IPGR2;		break;	case e1000_80003es2lan:		ipgr1 = DEFAULT_82543_TIPG_IPGR1;		ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;		break;	default:		ipgr1 = DEFAULT_82543_TIPG_IPGR1;		ipgr2 = DEFAULT_82543_TIPG_IPGR2;		break;	}	tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;	tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;	E1000_WRITE_REG(hw, TIPG, tipg);	/* Set the Tx Interrupt Delay register */	E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);	if (hw->mac_type >= e1000_82540)		E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);	/* Program the Transmit Control Register */	tctl = E1000_READ_REG(hw, TCTL);	tctl &= ~E1000_TCTL_CT;	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);	if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {		tarc = E1000_READ_REG(hw, TARC0);		/* set the speed mode bit, we'll clear it if we're not at		 * gigabit link later */#define SPEED_MODE_BIT (1 << 21)		tarc |= SPEED_MODE_BIT;		E1000_WRITE_REG(hw, TARC0, tarc);	} else if (hw->mac_type == e1000_80003es2lan) {		tarc = E1000_READ_REG(hw, TARC0);		tarc |= 1;		E1000_WRITE_REG(hw, TARC0, tarc);		tarc = E1000_READ_REG(hw, TARC1);		tarc |= 1;		E1000_WRITE_REG(hw, TARC1, tarc);	}	e1000_config_collision_dist(hw);	/* Setup Transmit Descriptor Settings for eop descriptor */	adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;	/* only set IDE if we are delaying interrupts using the timers */	if (adapter->tx_int_delay)		adapter->txd_cmd |= E1000_TXD_CMD_IDE;	if (hw->mac_type < e1000_82543)		adapter->txd_cmd |= E1000_TXD_CMD_RPS;	else		adapter->txd_cmd |= E1000_TXD_CMD_RS;	/* Cache if we're 82544 running in PCI-X because we'll	 * need this to apply a workaround later in the send path. */	if (hw->mac_type == e1000_82544 &&	    hw->bus_type == e1000_bus_type_pcix)		adapter->pcix_82544 = 1;	E1000_WRITE_REG(hw, TCTL, tctl);}/** * e1000_setup_rx_resources - allocate Rx resources (Descriptors) * @adapter: board private structure * @rxdr:    rx descriptor ring (for a specific queue) to setup * * Returns 0 on success, negative on failure **/static inte1000_setup_rx_resources(struct e1000_adapter *adapter,                         struct e1000_rx_ring *rxdr){	struct pci_dev *pdev = adapter->pdev;	int size, desc_len;	size = sizeof(struct e1000_buffer) * rxdr->count;	rxdr->buffer_info = vmalloc(size);	if (!rxdr->buffer_info) {		DPRINTK(PROBE, ERR,		"Unable to allocate memory for the receive descriptor ring\n");		return -ENOMEM;	}	memset(rxdr->buffer_info, 0, size);	size = sizeof(struct e1000_ps_page) * rxdr->count;	rxdr->ps_page = kmalloc(size, GFP_KERNEL);	if (!rxdr->ps_page) {		vfree(rxdr->buffer_info);		DPRINTK(PROBE, ERR,		"Unable to allocate memory for the receive descriptor ring\n");		return -ENOMEM;	}	memset(rxdr->ps_page, 0, size);	size = sizeof(struct e1000_ps_page_dma) * rxdr->count;	rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);	if (!rxdr->ps_page_dma) {		vfree(rxdr->buffer_info);		kfree(rxdr->ps_page);		DPRINTK(PROBE, ERR,		"Unable to allocate memory for the receive descriptor ring\n");		return -ENOMEM;	}	memset(rxdr->ps_page_dma, 0, size);	if (adapter->hw.mac_type <= e1000_82547_rev_2)		desc_len = sizeof(struct e1000_rx_desc);	else		desc_len = sizeof(union e1000_rx_desc_packet_split);	/* Round up to nearest 4K */	rxdr->size = rxdr->count * desc_len;	E1000_ROUNDUP(rxdr->size, 4096);	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);	if (!rxdr->desc) {		DPRINTK(PROBE, ERR,		"Unable to allocate memory for the receive descriptor ring\n");setup_rx_desc_die:		vfree(rxdr->buffer_info);		kfree(rxdr->ps_page);		kfree(rxdr->ps_page_dma);		return -ENOMEM;	}	/* Fix for errata 23, can't cross 64kB boundary */	if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {		void *olddesc = rxdr->desc;		dma_addr_t olddma = rxdr->dma;		DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "				     "at %p\n", rxdr->size, rxdr->desc);		/* Try again, without freeing the previous */		rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);		/* Failed allocation, critical failure */		if (!rxdr->desc) {			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);			DPRINTK(PROBE, ERR,				"Unable to allocate memory "				"for the receive descriptor ring\n");			goto setup_rx_desc_die;		}		if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {			/* give up */			pci_free_consistent(pdev, rxdr->size, rxdr->desc,					    rxdr->dma);			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);			DPRINTK(PROBE, ERR,				"Unable to allocate aligned memory "				"for the receive descriptor ring\n");			goto setup_rx_desc_die;		} else {			/* Free old allocation, new allocation was successful */			pci_free_consistent(pdev, rxdr->size, olddesc, olddma);		}	}	memset(rxdr->desc, 0, rxdr->size);	rxdr->next_to_clean = 0;	rxdr->next_to_use = 0;	return 0;}/** * e1000_setup_all_rx_resources - wrapper to allocate Rx resources * 				  (Descriptors) for all queues * @adapter: board private structure * * Return 0 on success, negative on failure **/inte1000_setup_all_rx_resources(struct e1000_adapter *adapter){	int i, err = 0;	for (i = 0; i < adapter->num_rx_queues; i++) {		err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);		if (err) {			DPRINTK(PROBE, ERR,				"Allocation for Rx Queue %u failed\n", i);			for (i-- ; i >= 0; i--)				e1000_free_rx_resources(adapter,							&adapter->rx_ring[i]);			break;		}	}	return err;}/** * e1000_setup_rctl - configure the receive control registers * @adapter: Board private structure **/#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \			(((S) & (PAGE_SIZE - 1)) ? 1 : 0))static voide1000_setup_rctl(struct e1000_adapter *adapter){	uint32_t rctl, rfctl;	uint32_t psrctl = 0;#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT	uint32_t pages = 0;#endif	rctl = E1000_READ_REG(&adapter->hw, RCTL);	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |		(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);	/* disable the stripping of CRC because it breaks	 * BMC firmware connected over SMBUS	if (adapter->hw.mac_type > e1000_82543)		rctl |= E1000_RCTL_SECRC;	*/	if (adapter->hw.tbi_compatibility_on == 1)		rctl |= E1000_RCTL_SBP;	else		rctl &= ~E1000_RCTL_SBP;	if (adapter->netdev->mtu <= ETH_DATA_LEN)		rctl &= ~E1000_RCTL_LPE;	else		rctl |= E1000_RCTL_LPE;	/* Setup buffer sizes */	rctl &= ~E1000_RCTL_SZ_4096;	rctl |= E1000_RCTL_BSEX;	switch (adapter->rx_buffer_len) {		case E1000_RXBUFFER_256:			rctl |= E1000_RCTL_SZ_256;			rctl &= ~E1000_RCTL_BSEX;			break;		case E1000_RXBUFFER_512:			rctl |= E1000_RCTL_SZ_512;			rctl &= ~E1000_RCTL_BSEX;			break;		case E1000_RXBUFFER_1024:			rctl |= E1000_RCTL_SZ_1024;			rctl &= ~E1000_RCTL_BSEX;			break;		case E1000_RXBUFFER_2048:		default:			rctl |= E1000_RCTL_SZ_2048;			rctl &= ~E1000_RCTL_BSEX;			break;		case E1000_RXBUFFER_4096:			rctl |= E1000_RCTL_SZ_4096;			break;		case E1000_RXBUFFER_8192:			rctl |= E1000_RCTL_SZ_8192;			break;		case E1000_RXBUFFER_16384:			rctl |= E1000_RCTL_SZ_16384;			break;	}#ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT	/* 82571 and greater support packet-split where the protocol	 * header is placed in skb->data and the packet data is	 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.	 * In the case of a non-split, skb->data is linearly filled,	 * followed by the page buffers.  Therefore, skb->data is	 * sized to hold the largest protocol header.	 */	/* allocations using alloc_page take too long for regular MTU	 * so only enable packet split for jumbo frames */	pages = PAGE_USE_COUNT(adapter->netdev->mtu);	if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&	    PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))		adapter->rx_ps_pages = pages;	else		adapter->rx_ps_pages = 0;#endif	if (adapter->rx_ps_pages) {		/* Configure extra packet-split registers */		rfctl = E1000_READ_REG(&adapter->hw, RFCTL);		rfctl |= E1000_RFCTL_EXTEN;		/* disable packet split support for IPv6 extension headers,		 * because some malformed IPv6 headers can hang the RX */		rfctl |= (E1000_RFCTL_IPV6_EX_DIS |		          E1000_RFCTL_NEW_IPV6_EXT_DIS);		E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);		/* disable the stripping of CRC because it breaks		 * BMC firmware connected over SMBUS */		rctl |= E1000_RCTL_DTYP_PS /* | E1000_RCTL_SECRC */;		psrctl |= adapter->rx_ps_bsize0 >>			E1000_PSRCTL_BSIZE0_SHIFT;		switch (adapter->rx_ps_pages) {		case 3:			psrctl |= PAGE_SIZE <<				E1000_PSRCTL_BSIZE3_SHIFT;		case 2:			psrctl |= PAGE_SIZE <<				E1000_PSRCTL_BSIZE2_SHIFT;		case 1:			psrctl |= PAGE_SIZE >>				E1000_PSRCTL_BSIZE1_SHIFT;			break;		}		E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);	}	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);}/** * e1000_configure_rx - Configure 8254x Receive Unit after Reset * @adapter: board private structure * * Configure the Rx unit of the MAC after a reset. **/static voide1000_configure_rx(struct e1000_adapter *adapter){	uint64_t rdba;	struct e1000_hw *hw = &adapter->hw;	uint32_t rdlen, rctl, rxcsum, ctrl_ext;	if (adapter->rx_ps_pages) {		/* this is a 32 byte descriptor */		rdlen = adapter->rx_ring[0].count *			sizeof(union e1000_rx_desc_packet_split);		adapter->clean_rx = e1000_clean_rx_irq_ps;		adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;	} else {		rdlen = adapter->rx_ring[0].count *			sizeof(struct e1000_rx_desc);		adapter->clean_rx = e1000_clean_rx_irq;		adapter->alloc_rx_buf = e1000_alloc_rx_buffers;	}	/* disable receives while setting up the descriptors */	rctl = E1000_READ_REG(hw, RCTL);	E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);	/* set the Receive Delay Timer Register */	E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);	if (hw->mac_type >= e1000_82540) {		E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);		if (adapter->itr_setting != 0)			E1000_WRITE_REG(hw, ITR,				1000000000 / (adapter->itr * 256));	}	if (hw->mac_type >= e1000_82571) {		ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);		/* Reset delay timers after every interrupt */		ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;#ifdef CONFIG_E1000_NAPI		/* Auto-Mask interrupts upon ICR access */		ctrl_ext |= E1000_CTRL_EXT_IAME;		E1000_WRITE_REG(hw, IAM, 0xffffffff);#endif		E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);		E1000_WRITE_FLUSH(hw);	}	/* Setup the HW Rx Head and Tail Descriptor Pointers and	 * the Base and Length of the Rx Descriptor Ring */	switch (adapter->num_rx_queues) {	case 1:	default:		rdba = adapter->rx_ring[0].dma;		E1000_WRITE_REG(hw, RDLEN, rdlen);		E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));		E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));		E1000_WRITE_REG(hw, RDT, 0);		E1000_WRITE_REG(hw, RDH, 0);		adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);		adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);		break;	}	/* Enable 82543 Receive Checksum Offload for TCP and UDP */	if (hw->mac_type >= e1000_82543) {		rxcsum = E1000_READ_REG(hw, RXCSUM);		if (adapter->rx_csum == TRUE) {			rxcsum |= E1000_RXCSUM_TUOFL;			/* Enable 82571 IPv4 payload checksum for UDP fragments			 * Must be used in conjunction with packet-split. */			if ((hw->mac_type >= e1000_82571) &&			    (adapter->rx_ps_pages)) {				rxcsum |= E1000_RXCSUM_IPPCSE;			}		} else {			rxcsum &= ~E1000_RXCSUM_TUOFL;			/* don't need to clear IPPCSE as it defaults to 0 */		}		E1000_WRITE_REG(hw, RXCSUM, rxcsum);	}	/* enable early receives on 82573, only takes effect if using > 2048	

⌨️ 快捷键说明

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