rem: DEBUGOUT("Error configuring MAC to PHY settings\n");
add: HW_DEBUGOUT("Error configuring MAC to PHY settings");
context: em_check_for_link(struct em_hw *hw){    uint32_t rxcw;    uint32_t ctrl;    uint32_t status;    uint32_t rctl;    uint32_t signal = 0;    int32_t ret_val;    uint16_t phy_data;    DEBUGFUNC("em_check_for_link");    /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be     * set when the optics detect a signal. On older adapters, it will be     * cleared when there is a signal.  This applies to fiber media only.     */    if(hw->media_type == em_media_type_fiber)        signal = (hw->mac_type > em_82544) ? E1000_CTRL_SWDPIN1 : 0;    ctrl = E1000_READ_REG(hw, CTRL);    status = E1000_READ_REG(hw, STATUS);    rxcw = E1000_READ_REG(hw, RXCW);    /* If we have a copper PHY then we only want to go out to the PHY     * registers to see if Auto-Neg has completed and/or if our link     * status has changed.  The get_link_status flag will be set if we     * receive a Link Status Change interrupt or we have Rx Sequence     * Errors.     */    if((hw->media_type == em_media_type_copper) && hw->get_link_status) {        /* First we want to see if the MII Status Register reports         * link.  If so, then we want to get the current speed/duplex         * of the PHY.         * Read the register twice since the link bit is sticky.         */        if((ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data)))            return ret_val;        if((ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data)))            return ret_val;        if(phy_data & MII_SR_LINK_STATUS) {            hw->get_link_status = FALSE;            /* Check if there was DownShift, must be checked immediately after             * link-up */            em_check_downshift(hw);        } else {            /* No link detected */            em_config_dsp_after_link_change(hw, FALSE);            return 0;        }        /* If we are forcing speed/duplex, then we simply return since         * we have already determined whether we have link or not.         */        if(!hw->autoneg) return -E1000_ERR_CONFIG;        /* optimize the dsp settings for the igp phy */        em_config_dsp_after_link_change(hw, TRUE);        /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we         * have Si on board that is 82544 or newer, Auto         * Speed Detection takes care of MAC speed/duplex         * configuration.  So we only need to configure Collision         * Distance in the MAC.  Otherwise, we need to force         * speed/duplex on the MAC to the current PHY speed/duplex         * settings.         */        if(hw->mac_type >= em_82544)            em_config_collision_dist(hw);        else {            if((ret_val = em_config_mac_to_phy(hw))) {                DEBUGOUT("Error configuring MAC to PHY settings\n");                return ret_val;            }        }        /* Configure Flow Control now that Auto-Neg has completed. First, we         * need to restore the desired flow control settings because we may         * have had to re-autoneg with a different link partner.         */        if((ret_val = em_config_fc_after_link_up(hw))) {            DEBUGOUT("Error configuring flow control\n");            return ret_val;        }        /* At this point we know that we are on copper and we have         * auto-negotiated link.  These are conditions for checking the link         * partner capability register.  We use the link speed to determine if         * TBI compatibility needs to be turned on or off.  If the link is not         * at gigabit speed, then TBI compatibility is not needed.  If we are         * at gigabit speed, we turn on TBI compatibility.         */	if(hw->tbi_compatibility_en) {            uint16_t speed, duplex;            em_get_speed_and_duplex(hw, &speed, &duplex);            if(speed != SPEED_1000) {                /* If link speed is not set to gigabit speed, we do not need                 * to enable TBI compatibility.                 */                if(hw->tbi_compatibility_on) {                    /* If we previously were in the mode, turn it off. */                    rctl = E1000_READ_REG(hw, RCTL);                    rctl &= ~E1000_RCTL_SBP;                    E1000_WRITE_REG(hw, RCTL, rctl);                    hw->tbi_compatibility_on = FALSE;                }            } else {                /* If TBI compatibility is was previously off, turn it on. For                 * compatibility with a TBI link partner, we will store bad                 * packets. Some frames have an additional byte on the end and                 * will look like CRC errors to to the hardware.                 */                if(!hw->tbi_compatibility_on) {                    hw->tbi_compatibility_on = TRUE;                    rctl = E1000_READ_REG(hw, RCTL);                    rctl |= E1000_RCTL_SBP;                    E1000_WRITE_REG(hw, RCTL, rctl);                }            }        }    }    /* If we don't have link (auto-negotiation failed or link partner cannot     * auto-negotiate), the cable is plugged in (we have signal), and our     * link partner is not trying to auto-negotiate with us (we are receiving     * idles or data), we need to force link up. We also need to give     * auto-negotiation time to complete, in case the cable was just plugged     * in. The autoneg_failed flag does this.     */    else if((((hw->media_type == em_media_type_fiber) &&            ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||            (hw->media_type == em_media_type_internal_serdes)) &&            (!(status & E1000_STATUS_LU)) &&            (!(rxcw & E1000_RXCW_C))) {        if(hw->autoneg_failed == 0) {            hw->autoneg_failed = 1;            return 0;        }        DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");        /* Disable auto-negotiation in the TXCW register */        E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));        /* Force link-up and also force full-duplex. */        ctrl = E1000_READ_REG(hw, CTRL);        ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);        E1000_WRITE_REG(hw, CTRL, ctrl);        /* Configure Flow Control after forcing link up. */        if((ret_val = em_config_fc_after_link_up(hw))) {            DEBUGOUT("Error configuring flow control\n");            return ret_val;        }    }    /* If we are forcing link and we are receiving /C/ ordered sets, re-enable     * auto-negotiation in the TXCW register and disable forced link in the     * Device Control register in an attempt to auto-negotiate with our link     * partner.     */    else if(((hw->media_type == em_media_type_fiber) ||             (hw->media_type == em_media_type_internal_serdes)) &&              (ctrl & E1000_CTRL_SLU) &&              (rxcw & E1000_RXCW_C)) {        DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");        E1000_WRITE_REG(hw, TXCW, hw->txcw);        E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));        hw->serdes_link_down = FALSE;    }    /* If we force link for non-auto-negotiation switch, check link status     * based on MAC synchronization for internal serdes media type.     */    else if((hw->media_type == em_media_type_internal_serdes) &&            !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {        /* SYNCH bit and IV bit are sticky. */        usec_delay(10);        if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {            if(!(rxcw & E1000_RXCW_IV)) {                hw->serdes_link_down = FALSE;                DEBUGOUT("SERDES: Link is up.\n");            }        } else {            hw->serdes_link_down = TRUE;            DEBUGOUT("SERDES: Link is down.\n");        }    }    if((hw->media_type == em_media_type_internal_serdes) &&       (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {        hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));    }    return E1000_SUCCESS;}