ixgb_main.c

来自「linux 内核源代码」· C语言 代码 · 共 2,360 行 · 第 1/5 页

C
2,360
字号
		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");		err = -EIO;		goto err_eeprom;	}	ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);	memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);	if(!is_valid_ether_addr(netdev->perm_addr)) {		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");		err = -EIO;		goto err_eeprom;	}	adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);	init_timer(&adapter->watchdog_timer);	adapter->watchdog_timer.function = &ixgb_watchdog;	adapter->watchdog_timer.data = (unsigned long)adapter;	INIT_WORK(&adapter->tx_timeout_task, ixgb_tx_timeout_task);	strcpy(netdev->name, "eth%d");	if((err = register_netdev(netdev)))		goto err_register;	/* we're going to reset, so assume we have no link for now */	netif_carrier_off(netdev);	netif_stop_queue(netdev);	DPRINTK(PROBE, INFO, "Intel(R) PRO/10GbE Network Connection\n");	ixgb_check_options(adapter);	/* reset the hardware with the new settings */	ixgb_reset(adapter);	cards_found++;	return 0;err_register:err_sw_init:err_eeprom:	iounmap(adapter->hw.hw_addr);err_ioremap:	free_netdev(netdev);err_alloc_etherdev:	pci_release_regions(pdev);err_request_regions:err_dma_mask:	pci_disable_device(pdev);	return err;}/** * ixgb_remove - Device Removal Routine * @pdev: PCI device information struct * * ixgb_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 __devexitixgb_remove(struct pci_dev *pdev){	struct net_device *netdev = pci_get_drvdata(pdev);	struct ixgb_adapter *adapter = netdev_priv(netdev);	unregister_netdev(netdev);	iounmap(adapter->hw.hw_addr);	pci_release_regions(pdev);	free_netdev(netdev);}/** * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter) * @adapter: board private structure to initialize * * ixgb_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 __devinitixgb_sw_init(struct ixgb_adapter *adapter){	struct ixgb_hw *hw = &adapter->hw;	struct net_device *netdev = adapter->netdev;	struct pci_dev *pdev = adapter->pdev;	/* PCI config space info */	hw->vendor_id = pdev->vendor;	hw->device_id = pdev->device;	hw->subsystem_vendor_id = pdev->subsystem_vendor;	hw->subsystem_id = pdev->subsystem_device;	hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;	adapter->rx_buffer_len = hw->max_frame_size;	if((hw->device_id == IXGB_DEVICE_ID_82597EX)	   || (hw->device_id == IXGB_DEVICE_ID_82597EX_CX4)	   || (hw->device_id == IXGB_DEVICE_ID_82597EX_LR)	   || (hw->device_id == IXGB_DEVICE_ID_82597EX_SR))			hw->mac_type = ixgb_82597;	else {		/* should never have loaded on this device */		DPRINTK(PROBE, ERR, "unsupported device id\n");	}	/* enable flow control to be programmed */	hw->fc.send_xon = 1;	atomic_set(&adapter->irq_sem, 1);	spin_lock_init(&adapter->tx_lock);	return 0;}/** * ixgb_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 intixgb_open(struct net_device *netdev){	struct ixgb_adapter *adapter = netdev_priv(netdev);	int err;	/* allocate transmit descriptors */	if((err = ixgb_setup_tx_resources(adapter)))		goto err_setup_tx;	/* allocate receive descriptors */	if((err = ixgb_setup_rx_resources(adapter)))		goto err_setup_rx;	if((err = ixgb_up(adapter)))		goto err_up;	return 0;err_up:	ixgb_free_rx_resources(adapter);err_setup_rx:	ixgb_free_tx_resources(adapter);err_setup_tx:	ixgb_reset(adapter);	return err;}/** * ixgb_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 intixgb_close(struct net_device *netdev){	struct ixgb_adapter *adapter = netdev_priv(netdev);	ixgb_down(adapter, TRUE);	ixgb_free_tx_resources(adapter);	ixgb_free_rx_resources(adapter);	return 0;}/** * ixgb_setup_tx_resources - allocate Tx resources (Descriptors) * @adapter: board private structure * * Return 0 on success, negative on failure **/intixgb_setup_tx_resources(struct ixgb_adapter *adapter){	struct ixgb_desc_ring *txdr = &adapter->tx_ring;	struct pci_dev *pdev = adapter->pdev;	int size;	size = sizeof(struct ixgb_buffer) * txdr->count;	txdr->buffer_info = vmalloc(size);	if(!txdr->buffer_info) {		DPRINTK(PROBE, ERR,		 "Unable to allocate transmit descriptor ring memory\n");		return -ENOMEM;	}	memset(txdr->buffer_info, 0, size);	/* round up to nearest 4K */	txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);	txdr->size = ALIGN(txdr->size, 4096);	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);	if(!txdr->desc) {		vfree(txdr->buffer_info);		DPRINTK(PROBE, ERR,		 "Unable to allocate transmit descriptor memory\n");		return -ENOMEM;	}	memset(txdr->desc, 0, txdr->size);	txdr->next_to_use = 0;	txdr->next_to_clean = 0;	return 0;}/** * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset. * @adapter: board private structure * * Configure the Tx unit of the MAC after a reset. **/static voidixgb_configure_tx(struct ixgb_adapter *adapter){	uint64_t tdba = adapter->tx_ring.dma;	uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);	uint32_t tctl;	struct ixgb_hw *hw = &adapter->hw;	/* Setup the Base and Length of the Tx Descriptor Ring 	 * tx_ring.dma can be either a 32 or 64 bit value 	 */	IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));	IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));	IXGB_WRITE_REG(hw, TDLEN, tdlen);	/* Setup the HW Tx Head and Tail descriptor pointers */	IXGB_WRITE_REG(hw, TDH, 0);	IXGB_WRITE_REG(hw, TDT, 0);	/* don't set up txdctl, it induces performance problems if configured	 * incorrectly */	/* Set the Tx Interrupt Delay register */	IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);	/* Program the Transmit Control Register */	tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;	IXGB_WRITE_REG(hw, TCTL, tctl);	/* Setup Transmit Descriptor Settings for this adapter */	adapter->tx_cmd_type =		IXGB_TX_DESC_TYPE 		| (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);}/** * ixgb_setup_rx_resources - allocate Rx resources (Descriptors) * @adapter: board private structure * * Returns 0 on success, negative on failure **/intixgb_setup_rx_resources(struct ixgb_adapter *adapter){	struct ixgb_desc_ring *rxdr = &adapter->rx_ring;	struct pci_dev *pdev = adapter->pdev;	int size;	size = sizeof(struct ixgb_buffer) * rxdr->count;	rxdr->buffer_info = vmalloc(size);	if(!rxdr->buffer_info) {		DPRINTK(PROBE, ERR,		 "Unable to allocate receive descriptor ring\n");		return -ENOMEM;	}	memset(rxdr->buffer_info, 0, size);	/* Round up to nearest 4K */	rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);	rxdr->size = ALIGN(rxdr->size, 4096);	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);	if(!rxdr->desc) {		vfree(rxdr->buffer_info);		DPRINTK(PROBE, ERR,		 "Unable to allocate receive descriptors\n");		return -ENOMEM;	}	memset(rxdr->desc, 0, rxdr->size);	rxdr->next_to_clean = 0;	rxdr->next_to_use = 0;	return 0;}/** * ixgb_setup_rctl - configure the receive control register * @adapter: Board private structure **/static voidixgb_setup_rctl(struct ixgb_adapter *adapter){	uint32_t rctl;	rctl = IXGB_READ_REG(&adapter->hw, RCTL);	rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);	rctl |=		IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | 		IXGB_RCTL_RXEN | IXGB_RCTL_CFF | 		(adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);	rctl |= IXGB_RCTL_SECRC;	if (adapter->rx_buffer_len <= IXGB_RXBUFFER_2048)		rctl |= IXGB_RCTL_BSIZE_2048;	else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_4096)		rctl |= IXGB_RCTL_BSIZE_4096;	else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_8192)		rctl |= IXGB_RCTL_BSIZE_8192;	else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_16384)		rctl |= IXGB_RCTL_BSIZE_16384;	IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);}/** * ixgb_configure_rx - Configure 82597 Receive Unit after Reset. * @adapter: board private structure * * Configure the Rx unit of the MAC after a reset. **/static voidixgb_configure_rx(struct ixgb_adapter *adapter){	uint64_t rdba = adapter->rx_ring.dma;	uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);	struct ixgb_hw *hw = &adapter->hw;	uint32_t rctl;	uint32_t rxcsum;	uint32_t rxdctl;	/* make sure receives are disabled while setting up the descriptors */	rctl = IXGB_READ_REG(hw, RCTL);	IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);	/* set the Receive Delay Timer Register */	IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);	/* Setup the Base and Length of the Rx Descriptor Ring */	IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));	IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));	IXGB_WRITE_REG(hw, RDLEN, rdlen);	/* Setup the HW Rx Head and Tail Descriptor Pointers */	IXGB_WRITE_REG(hw, RDH, 0);	IXGB_WRITE_REG(hw, RDT, 0);	/* set up pre-fetching of receive buffers so we get some before we	 * run out (default hardware behavior is to run out before fetching	 * more).  This sets up to fetch if HTHRESH rx descriptors are avail	 * and the descriptors in hw cache are below PTHRESH.  This avoids	 * the hardware behavior of fetching <=512 descriptors in a single	 * burst that pre-empts all other activity, usually causing fifo	 * overflows. */	/* use WTHRESH to burst write 16 descriptors or burst when RXT0 */	rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |	         RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |	         RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;	IXGB_WRITE_REG(hw, RXDCTL, rxdctl);	/* Enable Receive Checksum Offload for TCP and UDP */	if(adapter->rx_csum == TRUE) {		rxcsum = IXGB_READ_REG(hw, RXCSUM);		rxcsum |= IXGB_RXCSUM_TUOFL;		IXGB_WRITE_REG(hw, RXCSUM, rxcsum);	}	/* Enable Receives */	IXGB_WRITE_REG(hw, RCTL, rctl);}/** * ixgb_free_tx_resources - Free Tx Resources * @adapter: board private structure * * Free all transmit software resources **/voidixgb_free_tx_resources(struct ixgb_adapter *adapter){	struct pci_dev *pdev = adapter->pdev;	ixgb_clean_tx_ring(adapter);	vfree(adapter->tx_ring.buffer_info);	adapter->tx_ring.buffer_info = NULL;	pci_free_consistent(pdev, adapter->tx_ring.size,			    adapter->tx_ring.desc, adapter->tx_ring.dma);	adapter->tx_ring.desc = NULL;}static voidixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,					struct ixgb_buffer *buffer_info){	struct pci_dev *pdev = adapter->pdev;	if (buffer_info->dma)		pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,		               PCI_DMA_TODEVICE);	if (buffer_info->skb)		dev_kfree_skb_any(buffer_info->skb);	buffer_info->skb = NULL;	buffer_info->dma = 0;	buffer_info->time_stamp = 0;	/* these fields must always be initialized in tx	 * buffer_info->length = 0;	 * buffer_info->next_to_watch = 0; */}/** * ixgb_clean_tx_ring - Free Tx Buffers * @adapter: board private structure **/static voidixgb_clean_tx_ring(struct ixgb_adapter *adapter){

⌨️ 快捷键说明

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