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

📄 e1000_hw.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
        hw->asf_firmware_present = TRUE;        break;    default:        break;    }    return E1000_SUCCESS;}/***************************************************************************** * Set media type and TBI compatibility. * * hw - Struct containing variables accessed by shared code * **************************************************************************/voide1000_set_media_type(struct e1000_hw *hw){    uint32_t status;    DEBUGFUNC("e1000_set_media_type");    if(hw->mac_type != e1000_82543) {        /* tbi_compatibility is only valid on 82543 */        hw->tbi_compatibility_en = FALSE;    }    switch (hw->device_id) {    case E1000_DEV_ID_82545GM_SERDES:    case E1000_DEV_ID_82546GB_SERDES:    case E1000_DEV_ID_82571EB_SERDES:    case E1000_DEV_ID_82572EI_SERDES:        hw->media_type = e1000_media_type_internal_serdes;        break;    default:        switch (hw->mac_type) {        case e1000_82542_rev2_0:        case e1000_82542_rev2_1:            hw->media_type = e1000_media_type_fiber;            break;        case e1000_82573:            /* The STATUS_TBIMODE bit is reserved or reused for the this             * device.             */            hw->media_type = e1000_media_type_copper;            break;        default:            status = E1000_READ_REG(hw, STATUS);            if (status & E1000_STATUS_TBIMODE) {                hw->media_type = e1000_media_type_fiber;                /* tbi_compatibility not valid on fiber */                hw->tbi_compatibility_en = FALSE;            } else {                hw->media_type = e1000_media_type_copper;            }            break;        }    }}/****************************************************************************** * Reset the transmit and receive units; mask and clear all interrupts. * * hw - Struct containing variables accessed by shared code *****************************************************************************/int32_te1000_reset_hw(struct e1000_hw *hw){    uint32_t ctrl;    uint32_t ctrl_ext;    uint32_t icr;    uint32_t manc;    uint32_t led_ctrl;    uint32_t timeout;    uint32_t extcnf_ctrl;    int32_t ret_val;    DEBUGFUNC("e1000_reset_hw");    /* For 82542 (rev 2.0), disable MWI before issuing a device reset */    if(hw->mac_type == e1000_82542_rev2_0) {        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");        e1000_pci_clear_mwi(hw);    }    if(hw->bus_type == e1000_bus_type_pci_express) {        /* Prevent the PCI-E bus from sticking if there is no TLP connection         * on the last TLP read/write transaction when MAC is reset.         */        if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {            DEBUGOUT("PCI-E Master disable polling has failed.\n");        }    }    /* Clear interrupt mask to stop board from generating interrupts */    DEBUGOUT("Masking off all interrupts\n");    E1000_WRITE_REG(hw, IMC, 0xffffffff);    /* Disable the Transmit and Receive units.  Then delay to allow     * any pending transactions to complete before we hit the MAC with     * the global reset.     */    E1000_WRITE_REG(hw, RCTL, 0);    E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);    E1000_WRITE_FLUSH(hw);    /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */    hw->tbi_compatibility_on = FALSE;    /* Delay to allow any outstanding PCI transactions to complete before     * resetting the device     */    msec_delay(10);    ctrl = E1000_READ_REG(hw, CTRL);    /* Must reset the PHY before resetting the MAC */    if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {        E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));        msec_delay(5);    }    /* Must acquire the MDIO ownership before MAC reset.     * Ownership defaults to firmware after a reset. */    if(hw->mac_type == e1000_82573) {        timeout = 10;        extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);        extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;        do {            E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);            extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);            if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)                break;            else                extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;            msec_delay(2);            timeout--;        } while(timeout);    }    /* Issue a global reset to the MAC.  This will reset the chip's     * transmit, receive, DMA, and link units.  It will not effect     * the current PCI configuration.  The global reset bit is self-     * clearing, and should clear within a microsecond.     */    DEBUGOUT("Issuing a global reset to MAC\n");    switch(hw->mac_type) {        case e1000_82544:        case e1000_82540:        case e1000_82545:        case e1000_82546:        case e1000_82541:        case e1000_82541_rev_2:            /* These controllers can't ack the 64-bit write when issuing the             * reset, so use IO-mapping as a workaround to issue the reset */            E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));            break;        case e1000_82545_rev_3:        case e1000_82546_rev_3:            /* Reset is performed on a shadow of the control register */            E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));            break;        default:            E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));            break;    }    /* After MAC reset, force reload of EEPROM to restore power-on settings to     * device.  Later controllers reload the EEPROM automatically, so just wait     * for reload to complete.     */    switch(hw->mac_type) {        case e1000_82542_rev2_0:        case e1000_82542_rev2_1:        case e1000_82543:        case e1000_82544:            /* Wait for reset to complete */            udelay(10);            ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);            ctrl_ext |= E1000_CTRL_EXT_EE_RST;            E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);            E1000_WRITE_FLUSH(hw);            /* Wait for EEPROM reload */            msec_delay(2);            break;        case e1000_82541:        case e1000_82541_rev_2:        case e1000_82547:        case e1000_82547_rev_2:            /* Wait for EEPROM reload */            msec_delay(20);            break;        case e1000_82573:            udelay(10);            ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);            ctrl_ext |= E1000_CTRL_EXT_EE_RST;            E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);            E1000_WRITE_FLUSH(hw);            /* fall through */        case e1000_82571:        case e1000_82572:            ret_val = e1000_get_auto_rd_done(hw);            if(ret_val)                /* We don't want to continue accessing MAC registers. */                return ret_val;            break;        default:            /* Wait for EEPROM reload (it happens automatically) */            msec_delay(5);            break;    }    /* Disable HW ARPs on ASF enabled adapters */    if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {        manc = E1000_READ_REG(hw, MANC);        manc &= ~(E1000_MANC_ARP_EN);        E1000_WRITE_REG(hw, MANC, manc);    }    if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {        e1000_phy_init_script(hw);        /* Configure activity LED after PHY reset */        led_ctrl = E1000_READ_REG(hw, LEDCTL);        led_ctrl &= IGP_ACTIVITY_LED_MASK;        led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);        E1000_WRITE_REG(hw, LEDCTL, led_ctrl);    }    /* Clear interrupt mask to stop board from generating interrupts */    DEBUGOUT("Masking off all interrupts\n");    E1000_WRITE_REG(hw, IMC, 0xffffffff);    /* Clear any pending interrupt events. */    icr = E1000_READ_REG(hw, ICR);    /* If MWI was previously enabled, reenable it. */    if(hw->mac_type == e1000_82542_rev2_0) {        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)            e1000_pci_set_mwi(hw);    }    return E1000_SUCCESS;}/****************************************************************************** * Performs basic configuration of the adapter. * * hw - Struct containing variables accessed by shared code * * Assumes that the controller has previously been reset and is in a * post-reset uninitialized state. Initializes the receive address registers, * multicast table, and VLAN filter table. Calls routines to setup link * configuration and flow control settings. Clears all on-chip counters. Leaves * the transmit and receive units disabled and uninitialized. *****************************************************************************/int32_te1000_init_hw(struct e1000_hw *hw){    uint32_t ctrl;    uint32_t i;    int32_t ret_val;    uint16_t pcix_cmd_word;    uint16_t pcix_stat_hi_word;    uint16_t cmd_mmrbc;    uint16_t stat_mmrbc;    uint32_t mta_size;    DEBUGFUNC("e1000_init_hw");    /* Initialize Identification LED */    ret_val = e1000_id_led_init(hw);    if(ret_val) {        DEBUGOUT("Error Initializing Identification LED\n");        return ret_val;    }    /* Set the media type and TBI compatibility */    e1000_set_media_type(hw);    /* Disabling VLAN filtering. */    DEBUGOUT("Initializing the IEEE VLAN\n");    if (hw->mac_type < e1000_82545_rev_3)        E1000_WRITE_REG(hw, VET, 0);    e1000_clear_vfta(hw);    /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */    if(hw->mac_type == e1000_82542_rev2_0) {        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");        e1000_pci_clear_mwi(hw);        E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);        E1000_WRITE_FLUSH(hw);        msec_delay(5);    }    /* Setup the receive address. This involves initializing all of the Receive     * Address Registers (RARs 0 - 15).     */    e1000_init_rx_addrs(hw);    /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */    if(hw->mac_type == e1000_82542_rev2_0) {        E1000_WRITE_REG(hw, RCTL, 0);        E1000_WRITE_FLUSH(hw);        msec_delay(1);        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)            e1000_pci_set_mwi(hw);    }    /* Zero out the Multicast HASH table */    DEBUGOUT("Zeroing the MTA\n");    mta_size = E1000_MC_TBL_SIZE;    for(i = 0; i < mta_size; i++)        E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);    /* Set the PCI priority bit correctly in the CTRL register.  This     * determines if the adapter gives priority to receives, or if it     * gives equal priority to transmits and receives.  Valid only on     * 82542 and 82543 silicon.     */    if(hw->dma_fairness && hw->mac_type <= e1000_82543) {        ctrl = E1000_READ_REG(hw, CTRL);        E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);    }    switch(hw->mac_type) {    case e1000_82545_rev_3:    case e1000_82546_rev_3:        break;    default:        /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */        if(hw->bus_type == e1000_bus_type_pcix) {            e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);            e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,                &pcix_stat_hi_word);            cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>                PCIX_COMMAND_MMRBC_SHIFT;            stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>                PCIX_STATUS_HI_MMRBC_SHIFT;            if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)                stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;            if(cmd_mmrbc > stat_mmrbc) {                pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;                pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;                e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,                    &pcix_cmd_word);            }        }        break;    }    /* Call a subroutine to configure the link and setup flow control. */    ret_val = e1000_setup_link(hw);    /* Set the transmit descriptor write-back policy */    if(hw->mac_type > e1000_82544) {        ctrl = E1000_READ_REG(hw, TXDCTL);        ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;        switch (hw->mac_type) {        default:            break;        case e1000_82571:        case e1000_82572:            ctrl |= (1 << 22);

⌨️ 快捷键说明

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