📄 e1000_main.c
字号:
unsigned long end = begin + len; /* First rev 82545 and 82546 need to not allow any memory * write location to cross 64k boundary due to errata 23 */ if (adapter->hw.mac.type == e1000_82545 || adapter->hw.mac.type == e1000_82546) { return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; } return TRUE;}/** * e1000_setup_tx_resources - allocate Tx resources (Descriptors) * @adapter: board private structure * @tx_ring: tx descriptor ring (for a specific queue) to setup * * Return 0 on success, negative on failure **/static int e1000_setup_tx_resources(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring){ struct pci_dev *pdev = adapter->pdev; int size; size = sizeof(struct e1000_buffer) * tx_ring->count; tx_ring->buffer_info = vmalloc(size); if (!tx_ring->buffer_info) { DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit descriptor ring\n"); return -ENOMEM; } memset(tx_ring->buffer_info, 0, size); /* round up to nearest 4K */ tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); tx_ring->size = ALIGN(tx_ring->size, 4096); tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, &tx_ring->dma); if (!tx_ring->desc) {setup_tx_desc_die: vfree(tx_ring->buffer_info); DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit descriptor ring\n"); return -ENOMEM; } /* Fix for errata 23, can't cross 64kB boundary */ if (!e1000_check_64k_bound(adapter, tx_ring->desc, tx_ring->size)) { void *olddesc = tx_ring->desc; dma_addr_t olddma = tx_ring->dma; DPRINTK(TX_ERR, ERR, "tx_ring align check failed: %u bytes " "at %p\n", tx_ring->size, tx_ring->desc); /* Try again, without freeing the previous */ tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, &tx_ring->dma); /* Failed allocation, critical failure */ if (!tx_ring->desc) { pci_free_consistent(pdev, tx_ring->size, olddesc, olddma); goto setup_tx_desc_die; } if (!e1000_check_64k_bound(adapter, tx_ring->desc, tx_ring->size)) { /* give up */ pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); pci_free_consistent(pdev, tx_ring->size, olddesc, olddma); DPRINTK(PROBE, ERR, "Unable to allocate aligned memory " "for the transmit descriptor ring\n"); vfree(tx_ring->buffer_info); return -ENOMEM; } else { /* Free old allocation, new allocation was successful */ pci_free_consistent(pdev, tx_ring->size, olddesc, olddma); } } memset(tx_ring->desc, 0, tx_ring->size); tx_ring->next_to_use = 0; tx_ring->next_to_clean = 0; spin_lock_init(&tx_ring->tx_lock); return 0;}/** * e1000_setup_all_tx_resources - wrapper to allocate Tx resources * @adapter: board private structure * * this allocates tx resources for all queues, return 0 on success, negative * on failure **/int e1000_setup_all_tx_resources(struct e1000_adapter *adapter){ int i, err = 0; for (i = 0; i < adapter->num_tx_queues; i++) { err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); if (err) { DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); for (i-- ; i >= 0; i--) e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); break; } } return err;}/** * e1000_configure_tx - Configure 8254x Transmit Unit after Reset * @adapter: board private structure * * Configure the Tx unit of the MAC after a reset. **/static void e1000_configure_tx(struct e1000_adapter *adapter){ u64 tdba; struct e1000_hw *hw = &adapter->hw; u32 tdlen, tctl, tipg; u32 ipgr1, ipgr2; int i; /* Setup the HW Tx Head and Tail descriptor pointers */ for (i = 0; i < adapter->num_tx_queues; i++) { tdba = adapter->tx_ring[i].dma; tdlen = adapter->tx_ring[i].count * sizeof(struct e1000_tx_desc); E1000_WRITE_REG(hw, E1000_TDBAL(i), (tdba & 0x00000000ffffffffULL)); E1000_WRITE_REG(hw, E1000_TDBAH(i), (tdba >> 32)); E1000_WRITE_REG(hw, E1000_TDLEN(i), tdlen); E1000_WRITE_REG(hw, E1000_TDH(i), 0); E1000_WRITE_REG(hw, E1000_TDT(i), 0); adapter->tx_ring[i].tdh = E1000_REGISTER(hw, E1000_TDH(i)); adapter->tx_ring[i].tdt = E1000_REGISTER(hw, E1000_TDT(i)); } /* Set the default values for the Tx Inter Packet Gap timer */ if (adapter->hw.mac.type <= e1000_82547_rev_2 && (hw->phy.media_type == e1000_media_type_fiber || hw->phy.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: tipg = DEFAULT_82542_TIPG_IPGT; ipgr1 = DEFAULT_82542_TIPG_IPGR1; ipgr2 = DEFAULT_82542_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, E1000_TIPG, tipg); /* Set the Tx Interrupt Delay register */ E1000_WRITE_REG(hw, E1000_TIDV, adapter->tx_int_delay); if (adapter->flags & E1000_FLAG_HAS_INTR_MODERATION) E1000_WRITE_REG(hw, E1000_TADV, adapter->tx_abs_int_delay); /* Program the Transmit Control Register */ tctl = E1000_READ_REG(hw, E1000_TCTL); tctl &= ~E1000_TCTL_CT; tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); 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, E1000_TCTL, tctl);}/** * e1000_setup_rx_resources - allocate Rx resources (Descriptors) * @adapter: board private structure * @rx_ring: rx descriptor ring (for a specific queue) to setup * * Returns 0 on success, negative on failure **/static int e1000_setup_rx_resources(struct e1000_adapter *adapter, struct e1000_rx_ring *rx_ring){ struct pci_dev *pdev = adapter->pdev; int size, desc_len; size = sizeof(struct e1000_rx_buffer) * rx_ring->count; rx_ring->buffer_info = vmalloc(size); if (!rx_ring->buffer_info) { DPRINTK(PROBE, ERR, "Unable to allocate memory for the receive descriptor ring\n"); return -ENOMEM; } memset(rx_ring->buffer_info, 0, size); desc_len = sizeof(struct e1000_rx_desc); /* Round up to nearest 4K */ rx_ring->size = rx_ring->count * desc_len; rx_ring->size = ALIGN(rx_ring->size, 4096); rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma); if (!rx_ring->desc) { DPRINTK(PROBE, ERR, "Unable to allocate memory for the receive descriptor ring\n");setup_rx_desc_die: vfree(rx_ring->buffer_info); return -ENOMEM; } /* Fix for errata 23, can't cross 64kB boundary */ if (!e1000_check_64k_bound(adapter, rx_ring->desc, rx_ring->size)) { void *olddesc = rx_ring->desc; dma_addr_t olddma = rx_ring->dma; DPRINTK(RX_ERR, ERR, "rx_ring align check failed: %u bytes " "at %p\n", rx_ring->size, rx_ring->desc); /* Try again, without freeing the previous */ rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma); /* Failed allocation, critical failure */ if (!rx_ring->desc) { pci_free_consistent(pdev, rx_ring->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, rx_ring->desc, rx_ring->size)) { /* give up */ pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); pci_free_consistent(pdev, rx_ring->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, rx_ring->size, olddesc, olddma); } } memset(rx_ring->desc, 0, rx_ring->size); /* set up ring defaults */ rx_ring->next_to_clean = 0; rx_ring->next_to_use = 0; rx_ring->rx_skb_top = NULL; rx_ring->adapter = adapter; return 0;}/** * e1000_setup_all_rx_resources - wrapper to allocate Rx resources * @adapter: board private structure * * this allocates rx resources for all queues, return 0 on success, negative * on failure **/int e1000_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;}#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ (((S) & (PAGE_SIZE - 1)) ? 1 : 0))/** * e1000_setup_rctl - configure the receive control registers * @adapter: Board private structure **/static void e1000_setup_rctl(struct e1000_adapter *adapter){ u32 rctl; rctl = E1000_READ_REG(&adapter->hw, E1000_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); /* 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 (e1000_tbi_sbp_enabled_82543(&adapter->hw)) 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; } E1000_WRITE_REG(&adapter->hw, E1000_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 void e1000_configure_rx(struct e1000_adapter *adapter){ u64 rdba; struct e1000_hw *hw = &adapter->hw; u32 rdlen, rctl, rxcsum; int i;#ifdef CONFIG_E1000_NAPI if (adapter->netdev->mtu > MAXIMUM_ETHERNET_VLAN_SIZE) { rdlen = adapter->rx_ring[0].count * sizeof(struct e1000_rx_desc); adapter->clean_rx = e1000_clean_jumbo_rx_irq; adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; } else#endif /* CONFIG_E1000_NAPI */ { 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, E1000_RCTL); E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN); E1000_WRITE_FLUSH(hw); mdelay(10); /* set the Receive Delay Timer Register */ E1000_WRITE_REG(hw, E1000_RDTR, adapter->rx_int_delay); if (adapter->flags & E1000_FLAG_HAS_INTR_MODERATION) { E1000_WRITE_REG(hw, E1000_RADV, adapter->rx_abs_int_delay); if (adapter->itr_setting != 0) E1000_WRITE_REG(hw, E1000_ITR, 1000000000 / (adapter->itr * 256)); } /* Setup the HW Rx Head and Tail Descriptor Pointers and * the Base and Length of the Rx Descriptor Ring */ for (i = 0; i < adapter->num_rx_queues; i++) { rdba = adapter->rx_ring[i].dma; E1000_WRITE_REG(hw, E1000_RDBAL(i), (rdba & 0x00000000ffffffffULL)); E1000_WRITE_REG(hw, E1000_RDBAH(i), (rdba >> 32));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -