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

📄 netdev.c

📁 grub源码分析文档
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* Set the Tx Interrupt Delay register */	ew32(TIDV, adapter->tx_int_delay);	/* Tx irq moderation */	ew32(TADV, adapter->tx_abs_int_delay);	/* Program the Transmit Control Register */	tctl = er32(TCTL);	tctl &= ~E1000_TCTL_CT;	tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |		(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);	if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {		tarc = er32(TARC(0));		/*		 * 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;		ew32(TARC(0), tarc);	}	/* errata: program both queues to unweighted RR */	if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {		tarc = er32(TARC(0));		tarc |= 1;		ew32(TARC(0), tarc);		tarc = er32(TARC(1));		tarc |= 1;		ew32(TARC(1), tarc);	}	e1000e_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;	/* enable Report Status bit */	adapter->txd_cmd |= E1000_TXD_CMD_RS;	ew32(TCTL, tctl);	adapter->tx_queue_len = adapter->netdev->tx_queue_len;}/** * 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 void e1000_setup_rctl(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	u32 rctl, rfctl;	u32 psrctl = 0;	u32 pages = 0;	/* Program MC offset vector base */	rctl = er32(RCTL);	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |		(adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);	/* Do not Store bad packets */	rctl &= ~E1000_RCTL_SBP;	/* Enable Long Packet receive */	if (adapter->netdev->mtu <= ETH_DATA_LEN)		rctl &= ~E1000_RCTL_LPE;	else		rctl |= E1000_RCTL_LPE;	/* Enable hardware CRC frame stripping */	rctl |= E1000_RCTL_SECRC;	/* Setup buffer sizes */	rctl &= ~E1000_RCTL_SZ_4096;	rctl |= E1000_RCTL_BSEX;	switch (adapter->rx_buffer_len) {	case 256:		rctl |= E1000_RCTL_SZ_256;		rctl &= ~E1000_RCTL_BSEX;		break;	case 512:		rctl |= E1000_RCTL_SZ_512;		rctl &= ~E1000_RCTL_BSEX;		break;	case 1024:		rctl |= E1000_RCTL_SZ_1024;		rctl &= ~E1000_RCTL_BSEX;		break;	case 2048:	default:		rctl |= E1000_RCTL_SZ_2048;		rctl &= ~E1000_RCTL_BSEX;		break;	case 4096:		rctl |= E1000_RCTL_SZ_4096;		break;	case 8192:		rctl |= E1000_RCTL_SZ_8192;		break;	case 16384:		rctl |= E1000_RCTL_SZ_16384;		break;	}	/*	 * 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	 *	 * Using pages when the page size is greater than 16k wastes	 * a lot of memory, since we allocate 3 pages at all times	 * per packet.	 */	pages = PAGE_USE_COUNT(adapter->netdev->mtu);	if (!(adapter->flags & FLAG_IS_ICH) && (pages <= 3) &&	    (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))		adapter->rx_ps_pages = pages;	else		adapter->rx_ps_pages = 0;	if (adapter->rx_ps_pages) {		/* Configure extra packet-split registers */		rfctl = er32(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);		ew32(RFCTL, rfctl);		/* Enable Packet split descriptors */		rctl |= E1000_RCTL_DTYP_PS;		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;		}		ew32(PSRCTL, psrctl);	}	ew32(RCTL, rctl);	/* just started the receive unit, no need to restart */	adapter->flags &= ~FLAG_RX_RESTART_NOW;}/** * e1000_configure_rx - Configure Receive Unit after Reset * @adapter: board private structure * * Configure the Rx unit of the MAC after a reset. **/static void e1000_configure_rx(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	struct e1000_ring *rx_ring = adapter->rx_ring;	u64 rdba;	u32 rdlen, rctl, rxcsum, ctrl_ext;	if (adapter->rx_ps_pages) {		/* this is a 32 byte descriptor */		rdlen = rx_ring->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 if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {		rdlen = rx_ring->count * sizeof(struct e1000_rx_desc);		adapter->clean_rx = e1000_clean_jumbo_rx_irq;		adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;	} else {		rdlen = rx_ring->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 = er32(RCTL);	ew32(RCTL, rctl & ~E1000_RCTL_EN);	e1e_flush();	msleep(10);	/* set the Receive Delay Timer Register */	ew32(RDTR, adapter->rx_int_delay);	/* irq moderation */	ew32(RADV, adapter->rx_abs_int_delay);	if (adapter->itr_setting != 0)		ew32(ITR, 1000000000 / (adapter->itr * 256));	ctrl_ext = er32(CTRL_EXT);	/* Reset delay timers after every interrupt */	ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;	/* Auto-Mask interrupts upon ICR access */	ctrl_ext |= E1000_CTRL_EXT_IAME;	ew32(IAM, 0xffffffff);	ew32(CTRL_EXT, ctrl_ext);	e1e_flush();	/*	 * Setup the HW Rx Head and Tail Descriptor Pointers and	 * the Base and Length of the Rx Descriptor Ring	 */	rdba = rx_ring->dma;	ew32(RDBAL, (rdba & DMA_32BIT_MASK));	ew32(RDBAH, (rdba >> 32));	ew32(RDLEN, rdlen);	ew32(RDH, 0);	ew32(RDT, 0);	rx_ring->head = E1000_RDH;	rx_ring->tail = E1000_RDT;	/* Enable Receive Checksum Offload for TCP and UDP */	rxcsum = er32(RXCSUM);	if (adapter->flags & FLAG_RX_CSUM_ENABLED) {		rxcsum |= E1000_RXCSUM_TUOFL;		/*		 * IPv4 payload checksum for UDP fragments must be		 * used in conjunction with packet-split.		 */		if (adapter->rx_ps_pages)			rxcsum |= E1000_RXCSUM_IPPCSE;	} else {		rxcsum &= ~E1000_RXCSUM_TUOFL;		/* no need to clear IPPCSE as it defaults to 0 */	}	ew32(RXCSUM, rxcsum);	/*	 * Enable early receives on supported devices, only takes effect when	 * packet size is equal or larger than the specified value (in 8 byte	 * units), e.g. using jumbo frames when setting to E1000_ERT_2048	 */	if ((adapter->flags & FLAG_HAS_ERT) &&	    (adapter->netdev->mtu > ETH_DATA_LEN)) {		u32 rxdctl = er32(RXDCTL(0));		ew32(RXDCTL(0), rxdctl | 0x3);		ew32(ERT, E1000_ERT_2048 | (1 << 13));	}	/* Enable Receives */	ew32(RCTL, rctl);}/** *  e1000_update_mc_addr_list - Update Multicast addresses *  @hw: pointer to the HW structure *  @mc_addr_list: array of multicast addresses to program *  @mc_addr_count: number of multicast addresses to program *  @rar_used_count: the first RAR register free to program *  @rar_count: total number of supported Receive Address Registers * *  Updates the Receive Address Registers and Multicast Table Array. *  The caller must have a packed mc_addr_list of multicast addresses. *  The parameter rar_count will usually be hw->mac.rar_entry_count *  unless there are workarounds that change this.  Currently no func pointer *  exists and all implementations are handled in the generic version of this *  function. **/static void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,				      u32 mc_addr_count, u32 rar_used_count,				      u32 rar_count){	hw->mac.ops.update_mc_addr_list(hw, mc_addr_list, mc_addr_count,				        rar_used_count, rar_count);}/** * e1000_set_multi - Multicast and Promiscuous mode set * @netdev: network interface device structure * * The set_multi entry point is called whenever the multicast address * list or the network interface flags are updated.  This routine is * responsible for configuring the hardware for proper multicast, * promiscuous mode, and all-multi behavior. **/static void e1000_set_multi(struct net_device *netdev){	struct e1000_adapter *adapter = netdev_priv(netdev);	struct e1000_hw *hw = &adapter->hw;	struct e1000_mac_info *mac = &hw->mac;	struct dev_mc_list *mc_ptr;	u8  *mta_list;	u32 rctl;	int i;	/* Check for Promiscuous and All Multicast modes */	rctl = er32(RCTL);	if (netdev->flags & IFF_PROMISC) {		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);	} else if (netdev->flags & IFF_ALLMULTI) {		rctl |= E1000_RCTL_MPE;		rctl &= ~E1000_RCTL_UPE;	} else {		rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);	}	ew32(RCTL, rctl);	if (netdev->mc_count) {		mta_list = kmalloc(netdev->mc_count * 6, GFP_ATOMIC);		if (!mta_list)			return;		/* prepare a packed array of only addresses. */		mc_ptr = netdev->mc_list;		for (i = 0; i < netdev->mc_count; i++) {			if (!mc_ptr)				break;			memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr,			       ETH_ALEN);			mc_ptr = mc_ptr->next;		}		e1000_update_mc_addr_list(hw, mta_list, i, 1,					  mac->rar_entry_count);		kfree(mta_list);	} else {		/*		 * if we're called from probe, we might not have		 * anything to do here, so clear out the list		 */		e1000_update_mc_addr_list(hw, NULL, 0, 1, mac->rar_entry_count);	}}/** * e1000_configure - configure the hardware for Rx and Tx * @adapter: private board structure **/static void e1000_configure(struct e1000_adapter *adapter){	e1000_set_multi(adapter->netdev);	e1000_restore_vlan(adapter);	e1000_init_manageability(adapter);	e1000_configure_tx(adapter);	e1000_setup_rctl(adapter);	e1000_configure_rx(adapter);	adapter->alloc_rx_buf(adapter, e1000_desc_unused(adapter->rx_ring));}/** * e1000e_power_up_phy - restore link in case the phy was powered down * @adapter: address of board private structure * * The phy may be powered down to save power and turn off link when the * driver is unloaded and wake on lan is not enabled (among others) * *** this routine MUST be followed by a call to e1000e_reset *** **/void e1000e_power_up_phy(struct e1000_adapter *adapter){	u16 mii_reg = 0;	/* Just clear the power down bit to wake the phy back up */	if (adapter->hw.phy.media_type == e1000_media_type_copper) {		/*		 * According to the manual, the phy will retain its		 * settings across a power-down/up cycle		 */		e1e_rphy(&adapter->hw, PHY_CONTROL, &mii_reg);		mii_reg &= ~MII_CR_POWER_DOWN;		e1e_wphy(&adapter->hw, PHY_CONTROL, mii_reg);	}	adapter->hw.mac.ops.setup_link(&adapter->hw);}/** * e1000_power_down_phy - Power down the PHY * * Power down the PHY so no link is implied when interface is down * The PHY cannot be powered down is management or WoL is active */static void e1000_power_down_phy(struct e1000_adapter *adapter){	struct e1000_hw *hw = &adapter->hw;	u16 mii_reg;	/* WoL is enabled */	if (adapter->wol)		return;	/* non-copper PHY? */	if (adapter->hw.phy.media_type != e1000_media_type_copper)		return;	/* reset is blocked because of a SoL/IDER session */	if (e1000e_check_mng_mode(hw) || e1000_check_reset_block(hw))		return;	/* manageability (AMT) is enabled */	if (er32(MANC) & E1000_MANC_SMBUS_EN)		return;	/* power down the PHY */	e1e_rphy(hw, PHY_CONTROL, &mii_reg);	mii_reg |= MII_CR_POWER_DOWN;	e1e_wphy(hw, PHY_CONTROL, mii_reg);	mdelay(1);}/** * e1000e_reset - bring the hardware into a known good state * * This function boots the hardware and enables some settings that * require a configuration cycle of the hardware - those cannot be * set/changed during runtime. After reset the device needs to be * properly configured for Rx, Tx etc. */void e1000e_reset(struct e1000_adapter *adapter){	struct e1000_mac_info *mac = &adapter->hw.mac;	struct e1000_fc_info *fc = &adapter->hw.fc;	struct e1000_hw *hw = &adapter->hw;	u32 tx_space, min_tx_space, min_rx_space;	u32 pba = adapter->pba;	u16 hwm;	/* reset Packet Buffer Allocation to default */	ew32(PBA, pba);	if (adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN ) {		/*		 * 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 = er32(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 d

⌨️ 快捷键说明

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