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

📄 ar5xxx.c

📁 无线网卡驱动 固件程序 There are currently 3 "programming generations" of Atheros 802.11 wireless devices (
💻 C
📖 第 1 页 / 共 4 页
字号:
	data = set == AH_TRUE ? 1 : ar5k_bitswap(data, bits);	return (data);}u_int32_t /*O.K.*/ar5k_rfregs_gainf_corr(struct ath_hal *hal){	u_int32_t mix, step;	u_int32_t *rf;	if (hal->ah_rf_banks == NULL)		return (0);	rf = hal->ah_rf_banks;	hal->ah_gain.g_f_corr = 0;	if (ar5k_rfregs_op(rf, hal->ah_offset[7], 0, 1, 36, 0, AH_FALSE) != 1)		return (0);	step = ar5k_rfregs_op(rf, hal->ah_offset[7], 0, 4, 32, 0, AH_FALSE);	mix = hal->ah_gain.g_step->gos_param[0];	switch (mix) {	case 3:		hal->ah_gain.g_f_corr = step * 2;		break;	case 2:		hal->ah_gain.g_f_corr = (step - 5) * 2;		break;	case 1:		hal->ah_gain.g_f_corr = step;		break;	default:		hal->ah_gain.g_f_corr = 0;		break;	}	return (hal->ah_gain.g_f_corr);}HAL_BOOL /*O.K.*/ar5k_rfregs_gain_readback(struct ath_hal *hal){	u_int32_t step, mix, level[4];	u_int32_t *rf;	if (hal->ah_rf_banks == NULL)		return (0);	rf = hal->ah_rf_banks;	if (hal->ah_radio == AR5K_AR5111) {		step = ar5k_rfregs_op(rf, hal->ah_offset[7],		    0, 6, 37, 0, AH_FALSE);		level[0] = 0;		level[1] = (step == 0x3f) ? 0x32 : step + 4;		level[2] = (step != 0x3f) ? 0x40 : level[0];		level[3] = level[2] + 0x32;		hal->ah_gain.g_high = level[3] -		    (step == 0x3f ? AR5K_GAIN_DYN_ADJUST_HI_MARGIN : -5);		hal->ah_gain.g_low = level[0] +		    (step == 0x3f ? AR5K_GAIN_DYN_ADJUST_LO_MARGIN : 0);	} else {		mix = ar5k_rfregs_op(rf, hal->ah_offset[7],		    0, 1, 36, 0, AH_FALSE);		level[0] = level[2] = 0;		if (mix == 1) {			level[1] = level[3] = 83;		} else {			level[1] = level[3] = 107;			hal->ah_gain.g_high = 55;		}	}	return ((hal->ah_gain.g_current >= level[0] &&	    hal->ah_gain.g_current <= level[1]) ||	    (hal->ah_gain.g_current >= level[2] &&	    hal->ah_gain.g_current <= level[3]));}int32_t /*O.K.*/ar5k_rfregs_gain_adjust(struct ath_hal *hal){	int ret = 0;	const struct ar5k_gain_opt *go;	go = hal->ah_radio == AR5K_AR5111 ?	    &ar5111_gain_opt : &ar5112_gain_opt;	hal->ah_gain.g_step = &go->go_step[hal->ah_gain.g_step_idx];	if (hal->ah_gain.g_current >= hal->ah_gain.g_high) {		if (hal->ah_gain.g_step_idx == 0)			return (-1);		for (hal->ah_gain.g_target = hal->ah_gain.g_current;		    hal->ah_gain.g_target >=  hal->ah_gain.g_high &&		    hal->ah_gain.g_step_idx > 0;		    hal->ah_gain.g_step =		    &go->go_step[hal->ah_gain.g_step_idx]) {			hal->ah_gain.g_target -= 2 *			    (go->go_step[--(hal->ah_gain.g_step_idx)].gos_gain -			    hal->ah_gain.g_step->gos_gain);		}		ret = 1;		goto done;	}	if (hal->ah_gain.g_current <= hal->ah_gain.g_low) {		if (hal->ah_gain.g_step_idx == (go->go_steps_count - 1))			return (-2);		for (hal->ah_gain.g_target = hal->ah_gain.g_current;		    hal->ah_gain.g_target <=  hal->ah_gain.g_low &&		    hal->ah_gain.g_step_idx < (go->go_steps_count - 1);		    hal->ah_gain.g_step =		    &go->go_step[hal->ah_gain.g_step_idx]) {			hal->ah_gain.g_target -= 2 *			    (go->go_step[++(hal->ah_gain.g_step_idx)].gos_gain -			    hal->ah_gain.g_step->gos_gain);		}		ret = 2;		goto done;	} done:#ifdef AR5K_DEBUG	AR5K_PRINTF("ret %d, gain step %u, current gain %u, target gain %u\n",	    ret,	    hal->ah_gain.g_step_idx,	    hal->ah_gain.g_current,	    hal->ah_gain.g_target);#endif	return (ret);}HAL_BOOL /*O.K.*/ar5k_rfregs(struct ath_hal *hal, HAL_CHANNEL *channel, u_int mode){	ar5k_rfgain_t *func = NULL;	HAL_BOOL ret;	if (hal->ah_radio == AR5K_AR5111) {		hal->ah_rf_banks_size = sizeof(ar5111_rf);		func = ar5k_ar5111_rfregs;	} else if (hal->ah_radio == AR5K_AR5112) {		if (hal->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A)			hal->ah_rf_banks_size = sizeof(ar5112a_rf);		else		hal->ah_rf_banks_size = sizeof(ar5112_rf);		func = ar5k_ar5112_rfregs;	} else		return (AH_FALSE);	if (hal->ah_rf_banks == NULL) {		/* XXX do extra checks? */		if ((hal->ah_rf_banks = malloc(hal->ah_rf_banks_size,		    M_DEVBUF, M_NOWAIT)) == NULL) {			AR5K_PRINT("out of memory\n");			return (AH_FALSE);		}	}	ret = (func)(hal, channel, mode);	if (ret == AH_TRUE)		hal->ah_rf_gain = HAL_RFGAIN_INACTIVE;	return (ret);}HAL_BOOL /*O.K*/ar5k_ar5111_rfregs(struct ath_hal *hal, HAL_CHANNEL *channel, u_int mode){	struct ar5k_eeprom_info *ee = &hal->ah_capabilities.cap_eeprom;	const u_int rf_size = AR5K_ELEMENTS(ar5111_rf);	u_int32_t *rf;	int i, obdb = -1, bank = -1;	u_int32_t ee_mode;	AR5K_ASSERT_ENTRY(mode, AR5K_INI_VAL_MAX);	rf = hal->ah_rf_banks;	/* Copy values to modify them */	for (i = 0; i < rf_size; i++) {		if (ar5111_rf[i].rf_bank >=		    AR5K_AR5111_INI_RF_MAX_BANKS) {			AR5K_PRINT("invalid bank\n");			return (AH_FALSE);		}		if (bank != ar5111_rf[i].rf_bank) {			bank = ar5111_rf[i].rf_bank;			hal->ah_offset[bank] = i;		}		rf[i] = ar5111_rf[i].rf_value[mode];	}	if (channel->c_channel_flags & IEEE80211_CHAN_2GHZ) {		if (channel->c_channel_flags & IEEE80211_CHAN_B)			ee_mode = AR5K_EEPROM_MODE_11B;		else			ee_mode = AR5K_EEPROM_MODE_11G;		obdb = 0;		if (!ar5k_rfregs_op(rf, hal->ah_offset[0],			ee->ee_ob[ee_mode][obdb], 3, 119, 0, AH_TRUE))			return (AH_FALSE);		if (!ar5k_rfregs_op(rf, hal->ah_offset[0],			ee->ee_ob[ee_mode][obdb], 3, 122, 0, AH_TRUE))			return (AH_FALSE);		obdb = 1;	} else {		/* For 11a, Turbo and XR */		ee_mode = AR5K_EEPROM_MODE_11A;		obdb = channel->c_channel >= 5725 ? 3 :		    (channel->c_channel >= 5500 ? 2 :			(channel->c_channel >= 5260 ? 1 :			    (channel->c_channel > 4000 ? 0 : -1)));		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_pwd_84, 1, 51, 3, AH_TRUE))			return (AH_FALSE);		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_pwd_90, 1, 45, 3, AH_TRUE))			return (AH_FALSE);	}	if (!ar5k_rfregs_op(rf, hal->ah_offset[6],		!ee->ee_xpd[ee_mode], 1, 95, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[6],		ee->ee_x_gain[ee_mode], 4, 96, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[6],		obdb >= 0 ? ee->ee_ob[ee_mode][obdb] : 0, 3, 104, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[6],		obdb >= 0 ? ee->ee_db[ee_mode][obdb] : 0, 3, 107, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[7],		ee->ee_i_gain[ee_mode], 6, 29, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[7],		ee->ee_xpd[ee_mode], 1, 4, 0, AH_TRUE))		return (AH_FALSE);	/* Write RF values */	for (i = 0; i < rf_size; i++) {		AR5K_REG_WAIT(i);		AR5K_REG_WRITE(ar5111_rf[i].rf_register, rf[i]);	}	return (AH_TRUE);}HAL_BOOL /*O.K*/ar5k_ar5112_rfregs(struct ath_hal *hal, HAL_CHANNEL *channel, u_int mode){	struct ar5k_eeprom_info *ee = &hal->ah_capabilities.cap_eeprom;	u_int rf_size;	u_int32_t *rf;	int i, obdb = -1, bank = -1;	u_int32_t ee_mode;	const struct ar5k_ini_rf *rf_ini;	AR5K_ASSERT_ENTRY(mode, AR5K_INI_VAL_MAX);	rf = hal->ah_rf_banks;	if (hal->ah_radio_5ghz_revision >= AR5K_SREV_RAD_5112A) {		rf_ini = ar5112a_rf;		rf_size = AR5K_ELEMENTS(ar5112a_rf);	} else {		rf_ini = ar5112_rf;		rf_size = AR5K_ELEMENTS(ar5112_rf);	}	/* Copy values to modify them */	for (i = 0; i < rf_size; i++) {		if (rf_ini[i].rf_bank >=		    AR5K_AR5112_INI_RF_MAX_BANKS) {			AR5K_PRINT("invalid bank\n");			return (AH_FALSE);		}		if (bank != rf_ini[i].rf_bank) {			bank = rf_ini[i].rf_bank;			hal->ah_offset[bank] = i;		}		rf[i] = rf_ini[i].rf_value[mode];	}	if (channel->c_channel_flags & IEEE80211_CHAN_2GHZ) {		if (channel->c_channel_flags & IEEE80211_CHAN_B)			ee_mode = AR5K_EEPROM_MODE_11B;		else			ee_mode = AR5K_EEPROM_MODE_11G;		obdb = 0;		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_ob[ee_mode][obdb], 3, 287, 0, AH_TRUE))			return (AH_FALSE);		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_ob[ee_mode][obdb], 3, 290, 0, AH_TRUE))			return (AH_FALSE);	} else {		/* For 11a, Turbo and XR */		ee_mode = AR5K_EEPROM_MODE_11A;		obdb = channel->c_channel >= 5725 ? 3 :		    (channel->c_channel >= 5500 ? 2 :			(channel->c_channel >= 5260 ? 1 :			    (channel->c_channel > 4000 ? 0 : -1)));		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_ob[ee_mode][obdb], 3, 279, 0, AH_TRUE))			return (AH_FALSE);		if (!ar5k_rfregs_op(rf, hal->ah_offset[6],			ee->ee_ob[ee_mode][obdb], 3, 282, 0, AH_TRUE))			return (AH_FALSE);	}#ifdef notyet	ar5k_rfregs_op(rf, hal->ah_offset[6],	    ee->ee_x_gain[ee_mode], 2, 270, 0, AH_TRUE);	ar5k_rfregs_op(rf, hal->ah_offset[6],	    ee->ee_x_gain[ee_mode], 2, 257, 0, AH_TRUE);#endif	if (!ar5k_rfregs_op(rf, hal->ah_offset[6],		ee->ee_xpd[ee_mode], 1, 302, 0, AH_TRUE))		return (AH_FALSE);	if (!ar5k_rfregs_op(rf, hal->ah_offset[7],		ee->ee_i_gain[ee_mode], 6, 14, 0, AH_TRUE))		return (AH_FALSE);	/* Write RF values */	for (i = 0; i < rf_size; i++)		AR5K_REG_WRITE(ar5112_rf[i].rf_register, rf[i]);	return (AH_TRUE);}HAL_BOOL /*O.K.*/ar5k_rfgain(struct ath_hal *hal, u_int phy, u_int freq){	int i;	switch (phy) {	case AR5K_INI_PHY_5111:	case AR5K_INI_PHY_5112:		break;	default:		return (AH_FALSE);	}	switch (freq) {	case AR5K_INI_RFGAIN_2GHZ:	case AR5K_INI_RFGAIN_5GHZ:		break;	default:		return (AH_FALSE);	}	for (i = 0; i < AR5K_ELEMENTS(ar5k_rfg); i++) {		AR5K_REG_WAIT(i);		AR5K_REG_WRITE((u_int32_t)ar5k_rfg[i].rfg_register,		    ar5k_rfg[i].rfg_value[phy][freq]);	}	return (AH_TRUE);}/* * Common TX power setup */void /*O.K.*/ar5k_txpower_table(struct ath_hal *hal, HAL_CHANNEL *channel, int16_t max_power){	u_int16_t txpower, *rates;	int i, min, max, n;	rates = hal->ah_txpower.txp_rates;	txpower = AR5K_TUNE_DEFAULT_TXPOWER * 2;	if (max_power > txpower) {		txpower = max_power > AR5K_TUNE_MAX_TXPOWER ?		    AR5K_TUNE_MAX_TXPOWER : max_power;	}	for (i = 0; i < AR5K_MAX_RATES; i++)		rates[i] = txpower;	/* XXX setup target powers by rate */	hal->ah_txpower.txp_min = rates[7];	hal->ah_txpower.txp_max = rates[0];	hal->ah_txpower.txp_ofdm = rates[0];	/* Calculate the power table */	n = AR5K_ELEMENTS(hal->ah_txpower.txp_pcdac);	min = AR5K_EEPROM_PCDAC_START;	max = AR5K_EEPROM_PCDAC_STOP;	for (i = 0; i < n; i += AR5K_EEPROM_PCDAC_STEP)		hal->ah_txpower.txp_pcdac[i] =#ifdef notyet		min + ((i * (max - min)) / n);#else		min;#endif}/* Functions not found in OpenBSD */u_int /*New*/ath_hal_getwirelessmodes(struct ath_hal *hal, HAL_CTRY_CODE country) {	switch(hal->ah_version){	case AR5K_AR5212:		return (HAL_MODE_108A|HAL_MODE_11B|HAL_MODE_108G);	case AR5K_AR5211:		return (HAL_MODE_11B|HAL_MODE_108G);	default :		return(HAL_MODE_11A);	}}

⌨️ 快捷键说明

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