Exemplo n.º 1
0
HAL_BOOL
ar9285RfAttach(struct ath_hal *ah, HAL_STATUS *status)
{
	if (ar9280RfAttach(ah, status) == AH_FALSE)
		return AH_FALSE;

	AH_PRIVATE(ah)->ah_getNoiseFloor = ar9285GetNoiseFloor;

	return AH_TRUE;
}
Exemplo n.º 2
0
/*
 * Attach for an AR9280 part.
 */
static struct ath_hal *
ar9280Attach(uint16_t devid, HAL_SOFTC sc,
	HAL_BUS_TAG st, HAL_BUS_HANDLE sh, uint16_t *eepromdata,
	HAL_STATUS *status)
{
	struct ath_hal_9280 *ahp9280;
	struct ath_hal_5212 *ahp;
	struct ath_hal *ah;
	uint32_t val;
	HAL_STATUS ecode;
	HAL_BOOL rfStatus;
	int8_t pwr_table_offset;
	uint8_t pwr;

	HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
	    __func__, sc, (void*) st, (void*) sh);

	/* NB: memory is returned zero'd */
	ahp9280 = ath_hal_malloc(sizeof (struct ath_hal_9280));
	if (ahp9280 == AH_NULL) {
		HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
		    "%s: cannot allocate memory for state block\n", __func__);
		*status = HAL_ENOMEM;
		return AH_NULL;
	}
	ahp = AH5212(ahp9280);
	ah = &ahp->ah_priv.h;

	ar5416InitState(AH5416(ah), devid, sc, st, sh, status);


	/*
	 * Use the "local" EEPROM data given to us by the higher layers.
	 * This is a private copy out of system flash. The Linux ath9k
	 * commit for the initial AR9130 support mentions MMIO flash
	 * access is "unreliable." -adrian
	 */
	if (eepromdata != AH_NULL) {
		AH_PRIVATE((ah))->ah_eepromRead = ath_hal_EepromDataRead;
		AH_PRIVATE((ah))->ah_eepromWrite = NULL;
		ah->ah_eepromdata = eepromdata;
	}

	/* XXX override with 9280 specific state */
	/* override 5416 methods for our needs */
	AH5416(ah)->ah_initPLL = ar9280InitPLL;

	ah->ah_setAntennaSwitch		= ar9280SetAntennaSwitch;
	ah->ah_configPCIE		= ar9280ConfigPCIE;

	AH5416(ah)->ah_cal.iqCalData.calData = &ar9280_iq_cal;
	AH5416(ah)->ah_cal.adcGainCalData.calData = &ar9280_adc_gain_cal;
	AH5416(ah)->ah_cal.adcDcCalData.calData = &ar9280_adc_dc_cal;
	AH5416(ah)->ah_cal.adcDcCalInitData.calData = &ar9280_adc_init_dc_cal;
	AH5416(ah)->ah_cal.suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;

	AH5416(ah)->ah_spurMitigate	= ar9280SpurMitigate;
	AH5416(ah)->ah_writeIni		= ar9280WriteIni;
	AH5416(ah)->ah_olcInit		= ar9280olcInit;
	AH5416(ah)->ah_olcTempCompensation = ar9280olcTemperatureCompensation;
	AH5416(ah)->ah_setPowerCalTable	= ar9280SetPowerCalTable;

	AH5416(ah)->ah_rx_chainmask	= AR9280_DEFAULT_RXCHAINMASK;
	AH5416(ah)->ah_tx_chainmask	= AR9280_DEFAULT_TXCHAINMASK;

	if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {
		/* reset chip */
		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n",
		    __func__);
		ecode = HAL_EIO;
		goto bad;
	}

	if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",
		    __func__);
		ecode = HAL_EIO;
		goto bad;
	}
	/* Read Revisions from Chips before taking out of reset */
	val = OS_REG_READ(ah, AR_SREV);
	HALDEBUG(ah, HAL_DEBUG_ATTACH,
	    "%s: ID 0x%x VERSION 0x%x TYPE 0x%x REVISION 0x%x\n",
	    __func__, MS(val, AR_XSREV_ID), MS(val, AR_XSREV_VERSION),
	    MS(val, AR_XSREV_TYPE), MS(val, AR_XSREV_REVISION));
	/* NB: include chip type to differentiate from pre-Sowl versions */
	AH_PRIVATE(ah)->ah_macVersion =
	    (val & AR_XSREV_VERSION) >> AR_XSREV_TYPE_S;
	AH_PRIVATE(ah)->ah_macRev = MS(val, AR_XSREV_REVISION);
	AH_PRIVATE(ah)->ah_ispcie = (val & AR_XSREV_TYPE_HOST_MODE) == 0;

	/* setup common ini data; rf backends handle remainder */
	if (AR_SREV_MERLIN_20_OR_LATER(ah)) {
		HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v2, 6);
		HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v2, 2);
		HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,
		    ar9280PciePhy_clkreq_always_on_L1_v2, 2);
		HAL_INI_INIT(&ahp9280->ah_ini_xmodes,
		    ar9280Modes_fast_clock_v2, 3);
	} else {
		HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v1, 6);
		HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v1, 2);
		HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,
		    ar9280PciePhy_v1, 2);
	}
	ar5416AttachPCIE(ah);

	ecode = ath_hal_v14EepromAttach(ah);
	if (ecode != HAL_OK)
		goto bad;

	if (!ar5416ChipReset(ah, AH_NULL)) {	/* reset chip */
		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
		ecode = HAL_EIO;
		goto bad;
	}

	AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);

	if (!ar5212ChipTest(ah)) {
		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
		    __func__);
		ecode = HAL_ESELFTEST;
		goto bad;
	}

	/*
	 * Set correct Baseband to analog shift
	 * setting to access analog chips.
	 */
	OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);

	/* Read Radio Chip Rev Extract */
	AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);
	switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
        case AR_RAD2133_SREV_MAJOR:	/* Sowl: 2G/3x3 */
	case AR_RAD5133_SREV_MAJOR:	/* Sowl: 2+5G/3x3 */
		break;
	default:
		if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
			AH_PRIVATE(ah)->ah_analog5GhzRev =
				AR_RAD5133_SREV_MAJOR;
			break;
		}
#ifdef AH_DEBUG
		HALDEBUG(ah, HAL_DEBUG_ANY,
		    "%s: 5G Radio Chip Rev 0x%02X is not supported by "
		    "this driver\n", __func__,
		    AH_PRIVATE(ah)->ah_analog5GhzRev);
		ecode = HAL_ENOTSUPP;
		goto bad;
#endif
	}
	rfStatus = ar9280RfAttach(ah, &ecode);
	if (!rfStatus) {
		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
		    __func__, ecode);
		goto bad;
	}

	/* Enable fixup for AR_AN_TOP2 if necessary */
	/*
	 * The v14 EEPROM layer returns HAL_EIO if PWDCLKIND isn't supported
	 * by the EEPROM version.
	 *
	 * ath9k checks the EEPROM minor version is >= 0x0a here, instead of
	 * the abstracted EEPROM access layer.
	 */
	ecode = ath_hal_eepromGet(ah, AR_EEP_PWDCLKIND, &pwr);
	if (AR_SREV_MERLIN_20_OR_LATER(ah) && ecode == HAL_OK && pwr == 0) {
		printf("[ath] enabling AN_TOP2_FIXUP\n");
		AH5416(ah)->ah_need_an_top2_fixup = 1;
	}

        /*
         * Check whether the power table offset isn't the default.
         * This can occur with eeprom minor V21 or greater on Merlin.
         */
	(void) ath_hal_eepromGet(ah, AR_EEP_PWR_TABLE_OFFSET, &pwr_table_offset);
	if (pwr_table_offset != AR5416_PWR_TABLE_OFFSET_DB)
		ath_hal_printf(ah, "[ath]: default pwr offset: %d dBm != EEPROM pwr offset: %d dBm; curves will be adjusted.\n",
		    AR5416_PWR_TABLE_OFFSET_DB, (int) pwr_table_offset);

	/* XXX check for >= minor ver 17 */
	if (AR_SREV_MERLIN_20(ah)) {
		/* setup rxgain table */
		switch (ath_hal_eepromGet(ah, AR_EEP_RXGAIN_TYPE, AH_NULL)) {
		case AR5416_EEP_RXGAIN_13dB_BACKOFF:
			HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
			    ar9280Modes_backoff_13db_rxgain_v2, 6);
			break;
		case AR5416_EEP_RXGAIN_23dB_BACKOFF:
			HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
			    ar9280Modes_backoff_23db_rxgain_v2, 6);
			break;
		case AR5416_EEP_RXGAIN_ORIG:
			HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
			    ar9280Modes_original_rxgain_v2, 6);
			break;
		default:
			HALASSERT(AH_FALSE);
			goto bad;		/* XXX ? try to continue */
		}
	}

	/* XXX check for >= minor ver 19 */
	if (AR_SREV_MERLIN_20(ah)) {
		/* setp txgain table */
		switch (ath_hal_eepromGet(ah, AR_EEP_TXGAIN_TYPE, AH_NULL)) {
		case AR5416_EEP_TXGAIN_HIGH_POWER:
			HAL_INI_INIT(&ahp9280->ah_ini_txgain,
			    ar9280Modes_high_power_tx_gain_v2, 6);
			break;
		case AR5416_EEP_TXGAIN_ORIG:
			HAL_INI_INIT(&ahp9280->ah_ini_txgain,
			    ar9280Modes_original_tx_gain_v2, 6);
			break;
		default:
			HALASSERT(AH_FALSE);
			goto bad;		/* XXX ? try to continue */
		}
	}

	/*
	 * Got everything we need now to setup the capabilities.
	 */
	if (!ar9280FillCapabilityInfo(ah)) {
		ecode = HAL_EEREAD;
		goto bad;
	}

	ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
	if (ecode != HAL_OK) {
		HALDEBUG(ah, HAL_DEBUG_ANY,
		    "%s: error getting mac address from EEPROM\n", __func__);
		goto bad;
        }
	/* XXX How about the serial number ? */
	/* Read Reg Domain */
	AH_PRIVATE(ah)->ah_currentRD =
	    ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);
	AH_PRIVATE(ah)->ah_currentRDext =
	    ath_hal_eepromGet(ah, AR_EEP_REGDMN_1, AH_NULL);

	/*
	 * ah_miscMode is populated by ar5416FillCapabilityInfo()
	 * starting from griffin. Set here to make sure that
	 * AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is
	 * placed into hardware.
	 */
	if (ahp->ah_miscMode != 0)
		OS_REG_WRITE(ah, AR_MISC_MODE, OS_REG_READ(ah, AR_MISC_MODE) | ahp->ah_miscMode);

	ar9280AniSetup(ah);			/* Anti Noise Immunity */

	/* Setup noise floor min/max/nominal values */
	AH5416(ah)->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_2GHZ;
	AH5416(ah)->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_2GHZ;
	AH5416(ah)->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9280_2GHZ;
	AH5416(ah)->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9280_5GHZ;
	AH5416(ah)->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9280_5GHZ;
	AH5416(ah)->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9280_5GHZ;

	ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);

	HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);

	return ah;
bad:
	if (ah != AH_NULL)
		ah->ah_detach(ah);
	if (status)
		*status = ecode;
	return AH_NULL;
}
Exemplo n.º 3
0
/*
 * Attach for an AR9280 part.
 */
static struct ath_hal *
ar9280Attach(uint16_t devid, HAL_SOFTC sc,
             HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
{
    struct ath_hal_9280 *ahp9280;
    struct ath_hal_5212 *ahp;
    struct ath_hal *ah;
    uint32_t val;
    HAL_STATUS ecode;
    HAL_BOOL rfStatus;

    HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
             __func__, sc, (void*) st, (void*) sh);

    /* NB: memory is returned zero'd */
    ahp9280 = ath_hal_malloc(sizeof (struct ath_hal_9280));
    if (ahp9280 == AH_NULL) {
        HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
                 "%s: cannot allocate memory for state block\n", __func__);
        *status = HAL_ENOMEM;
        return AH_NULL;
    }
    ahp = AH5212(ahp9280);
    ah = &ahp->ah_priv.h;

    ar5416InitState(AH5416(ah), devid, sc, st, sh, status);

    /* XXX override with 9280 specific state */
    /* override 5416 methods for our needs */
    ah->ah_setAntennaSwitch		= ar9280SetAntennaSwitch;
    ah->ah_configPCIE		= ar9280ConfigPCIE;

    AH5416(ah)->ah_cal.iqCalData.calData = &ar9280_iq_cal;
    AH5416(ah)->ah_cal.adcGainCalData.calData = &ar9280_adc_gain_cal;
    AH5416(ah)->ah_cal.adcDcCalData.calData = &ar9280_adc_dc_cal;
    AH5416(ah)->ah_cal.adcDcCalInitData.calData = &ar9280_adc_init_dc_cal;
    AH5416(ah)->ah_cal.suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;

    AH5416(ah)->ah_spurMitigate	= ar9280SpurMitigate;
    AH5416(ah)->ah_writeIni		= ar9280WriteIni;
    AH5416(ah)->ah_rx_chainmask	= AR9280_DEFAULT_RXCHAINMASK;
    AH5416(ah)->ah_tx_chainmask	= AR9280_DEFAULT_TXCHAINMASK;

    if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {
        /* reset chip */
        HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n",
                 __func__);
        ecode = HAL_EIO;
        goto bad;
    }

    if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
        HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",
                 __func__);
        ecode = HAL_EIO;
        goto bad;
    }
    /* Read Revisions from Chips before taking out of reset */
    val = OS_REG_READ(ah, AR_SREV);
    HALDEBUG(ah, HAL_DEBUG_ATTACH,
             "%s: ID 0x%x VERSION 0x%x TYPE 0x%x REVISION 0x%x\n",
             __func__, MS(val, AR_XSREV_ID), MS(val, AR_XSREV_VERSION),
             MS(val, AR_XSREV_TYPE), MS(val, AR_XSREV_REVISION));
    /* NB: include chip type to differentiate from pre-Sowl versions */
    AH_PRIVATE(ah)->ah_macVersion =
        (val & AR_XSREV_VERSION) >> AR_XSREV_TYPE_S;
    AH_PRIVATE(ah)->ah_macRev = MS(val, AR_XSREV_REVISION);
    AH_PRIVATE(ah)->ah_ispcie = (val & AR_XSREV_TYPE_HOST_MODE) == 0;

    /* setup common ini data; rf backends handle remainder */
    if (AR_SREV_MERLIN_20_OR_LATER(ah)) {
        HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v2, 6);
        HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v2, 2);
        HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,
                     ar9280PciePhy_clkreq_always_on_L1_v2, 2);
        HAL_INI_INIT(&ahp9280->ah_ini_xmodes,
                     ar9280Modes_fast_clock_v2, 3);
    } else {
        HAL_INI_INIT(&ahp->ah_ini_modes, ar9280Modes_v1, 6);
        HAL_INI_INIT(&ahp->ah_ini_common, ar9280Common_v1, 2);
        HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes,
                     ar9280PciePhy_v1, 2);
    }
    ar5416AttachPCIE(ah);

    ecode = ath_hal_v14EepromAttach(ah);
    if (ecode != HAL_OK)
        goto bad;

    if (!ar5416ChipReset(ah, AH_NULL)) {	/* reset chip */
        HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
        ecode = HAL_EIO;
        goto bad;
    }

    AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);

    if (!ar5212ChipTest(ah)) {
        HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
                 __func__);
        ecode = HAL_ESELFTEST;
        goto bad;
    }

    /*
     * Set correct Baseband to analog shift
     * setting to access analog chips.
     */
    OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);

    /* Read Radio Chip Rev Extract */
    AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);
    switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
    case AR_RAD2133_SREV_MAJOR:	/* Sowl: 2G/3x3 */
    case AR_RAD5133_SREV_MAJOR:	/* Sowl: 2+5G/3x3 */
        break;
    default:
        if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
            AH_PRIVATE(ah)->ah_analog5GhzRev =
                AR_RAD5133_SREV_MAJOR;
            break;
        }
#ifdef AH_DEBUG
        HALDEBUG(ah, HAL_DEBUG_ANY,
                 "%s: 5G Radio Chip Rev 0x%02X is not supported by "
                 "this driver\n", __func__,
                 AH_PRIVATE(ah)->ah_analog5GhzRev);
        ecode = HAL_ENOTSUPP;
        goto bad;
#endif
    }
    rfStatus = ar9280RfAttach(ah, &ecode);
    if (!rfStatus) {
        HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
                 __func__, ecode);
        goto bad;
    }

    if (AR_SREV_MERLIN_20_OR_LATER(ah)) {
        /* setup rxgain table */
        switch (ath_hal_eepromGet(ah, AR_EEP_RXGAIN_TYPE, AH_NULL)) {
        case AR5416_EEP_RXGAIN_13dB_BACKOFF:
            HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
                         ar9280Modes_backoff_13db_rxgain_v2, 6);
            break;
        case AR5416_EEP_RXGAIN_23dB_BACKOFF:
            HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
                         ar9280Modes_backoff_23db_rxgain_v2, 6);
            break;
        case AR5416_EEP_RXGAIN_ORIG:
            HAL_INI_INIT(&ahp9280->ah_ini_rxgain,
                         ar9280Modes_original_rxgain_v2, 6);
            break;
        default:
            HALASSERT(AH_FALSE);
            goto bad;		/* XXX ? try to continue */
        }
    }
    if (AR_SREV_MERLIN_20_OR_LATER(ah)) {
        /* setp txgain table */
        switch (ath_hal_eepromGet(ah, AR_EEP_TXGAIN_TYPE, AH_NULL)) {
        case AR5416_EEP_TXGAIN_HIGH_POWER:
            HAL_INI_INIT(&ahp9280->ah_ini_txgain,
                         ar9280Modes_high_power_tx_gain_v2, 6);
            break;
        case AR5416_EEP_TXGAIN_ORIG:
            HAL_INI_INIT(&ahp9280->ah_ini_txgain,
                         ar9280Modes_original_tx_gain_v2, 6);
            break;
        default:
            HALASSERT(AH_FALSE);
            goto bad;		/* XXX ? try to continue */
        }
    }

    /*
     * Got everything we need now to setup the capabilities.
     */
    if (!ar9280FillCapabilityInfo(ah)) {
        ecode = HAL_EEREAD;
        goto bad;
    }

    ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
    if (ecode != HAL_OK) {
        HALDEBUG(ah, HAL_DEBUG_ANY,
                 "%s: error getting mac address from EEPROM\n", __func__);
        goto bad;
    }
    /* XXX How about the serial number ? */
    /* Read Reg Domain */
    AH_PRIVATE(ah)->ah_currentRD =
        ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);

    /*
     * ah_miscMode is populated by ar5416FillCapabilityInfo()
     * starting from griffin. Set here to make sure that
     * AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is
     * placed into hardware.
     */
    if (ahp->ah_miscMode != 0)
        OS_REG_WRITE(ah, AR_MISC_MODE, ahp->ah_miscMode);

    ar9280AniSetup(ah);			/* Anti Noise Immunity */
    ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);

    HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);

    return ah;
bad:
    if (ah != AH_NULL)
        ah->ah_detach(ah);
    if (status)
        *status = ecode;
    return AH_NULL;
}