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

📄 iwl-4965-rs.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");	memset(extra, 0, sizeof(*extra));	fc = le16_to_cpu(hdr->frame_control);	if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {		/* Send management frames and broadcast/multicast data using		 * lowest rate. */		/* TODO: this could probably be improved.. */		return rs_get_lowest_rate(local);	}	sta = sta_info_get(local, hdr->addr1);	if (!sta || !sta->rate_ctrl_priv) {		if (sta)			sta_info_put(sta);		return rs_get_lowest_rate(local);	}	lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;	i = sta->last_txrate;	if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) {		u8 sta_id = iwl_hw_find_station(priv, hdr->addr1);		DECLARE_MAC_BUF(mac);		if (sta_id == IWL_INVALID_STATION) {			IWL_DEBUG_RATE("LQ: ADD station %s\n",				       print_mac(mac, hdr->addr1));			sta_id = iwl_add_station(priv,						 hdr->addr1, 0, CMD_ASYNC);		}		if ((sta_id != IWL_INVALID_STATION)) {			lq->lq.sta_id = sta_id;			lq->lq.rs_table[0].rate_n_flags = 0;			lq->ibss_sta_added = 1;			rs_initialize_lq(priv, sta);		}		if (!lq->ibss_sta_added)			goto done;	} done:	sta_info_put(sta);	if ((i < 0) || (i > IWL_RATE_COUNT))		return rs_get_lowest_rate(local);	return &priv->ieee_rates[i];}static void *rs_alloc_sta(void *priv, gfp_t gfp){	struct iwl_rate_scale_priv *crl;	int i, j;	IWL_DEBUG_RATE("create station rate scale window\n");	crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp);	if (crl == NULL)		return NULL;	crl->lq.sta_id = 0xff;	for (j = 0; j < LQ_SIZE; j++)		for (i = 0; i < IWL_RATE_COUNT; i++)			rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));	return crl;}static void rs_rate_init(void *priv_rate, void *priv_sta,			 struct ieee80211_local *local,			 struct sta_info *sta){	int i, j;	struct ieee80211_hw_mode *mode = local->oper_hw_mode;	struct iwl_priv *priv = (struct iwl_priv *)priv_rate;	struct iwl_rate_scale_priv *crl = priv_sta;	crl->flush_timer = 0;	crl->supp_rates = sta->supp_rates;	sta->txrate = 3;	for (j = 0; j < LQ_SIZE; j++)		for (i = 0; i < IWL_RATE_COUNT; i++)			rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));	IWL_DEBUG_RATE("rate scale global init\n");	/* TODO: what is a good starting rate for STA? About middle? Maybe not	 * the lowest or the highest rate.. Could consider using RSSI from	 * previous packets? Need to have IEEE 802.1X auth succeed immediately	 * after assoc.. */	crl->ibss_sta_added = 0;	if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {		u8 sta_id = iwl_hw_find_station(priv, sta->addr);		DECLARE_MAC_BUF(mac);		/* for IBSS the call are from tasklet */		IWL_DEBUG_HT("LQ: ADD station %s\n",			     print_mac(mac, sta->addr));		if (sta_id == IWL_INVALID_STATION) {			IWL_DEBUG_RATE("LQ: ADD station %s\n",				       print_mac(mac, sta->addr));			sta_id = iwl_add_station(priv,						 sta->addr, 0, CMD_ASYNC);		}		if ((sta_id != IWL_INVALID_STATION)) {			crl->lq.sta_id = sta_id;			crl->lq.rs_table[0].rate_n_flags = 0;		}		/* FIXME: this is w/a remove it later */		priv->assoc_station_added = 1;	}	for (i = 0; i < mode->num_rates; i++) {		if ((sta->supp_rates & BIT(i)) &&		    (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))			sta->txrate = i;	}	sta->last_txrate = sta->txrate;	/* For MODE_IEEE80211A mode cck rate are at end	 * rate table	 */	if (local->hw.conf.phymode == MODE_IEEE80211A)		sta->last_txrate += IWL_FIRST_OFDM_RATE;	crl->is_dup = priv->is_dup;	crl->valid_antenna = priv->valid_antenna;	crl->antenna = priv->antenna;	crl->is_green = rs_use_green(priv);	crl->active_rate = priv->active_rate;	crl->active_rate &= ~(0x1000);	crl->active_rate_basic = priv->active_rate_basic;	crl->phymode = priv->phymode;#ifdef CONFIG_IWLWIFI_HT	crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1);	crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1);	crl->active_siso_rate &= ~((u16)0x2);	crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE;	crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1);	crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1);	crl->active_mimo_rate &= ~((u16)0x2);	crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE;	IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate,		     crl->active_mimo_rate);#endif /*CONFIG_IWLWIFI_HT*/#ifdef CONFIG_MAC80211_DEBUGFS	crl->drv = priv;#endif	if (priv->assoc_station_added)		priv->lq_mngr.lq_ready = 1;	rs_initialize_lq(priv, sta);}static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,			    struct iwl_rate *tx_mcs,			    struct iwl_link_quality_cmd *lq_cmd){	int index = 0;	int rate_idx;	int repeat_rate = 0;	u8 ant_toggle_count = 0;	u8 use_ht_possible = 1;	struct iwl_rate new_rate;	struct iwl_scale_tbl_info tbl_type = { 0 };	rs_dbgfs_set_mcs(lq_data, tx_mcs, index);	rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode,				  &tbl_type, &rate_idx);	if (is_legacy(tbl_type.lq_type)) {		ant_toggle_count = 1;		repeat_rate = IWL_NUMBER_TRY;	} else		repeat_rate = IWL_HT_NUMBER_TRY;	lq_cmd->general_params.mimo_delimiter =			is_mimo(tbl_type.lq_type) ? 1 : 0;	lq_cmd->rs_table[index].rate_n_flags =			cpu_to_le32(tx_mcs->rate_n_flags);	new_rate.rate_n_flags = tx_mcs->rate_n_flags;	if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))		lq_cmd->general_params.single_stream_ant_msk = 1;	else		lq_cmd->general_params.single_stream_ant_msk = 2;	index++;	repeat_rate--;	while (index < LINK_QUAL_MAX_RETRY_NUM) {		while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {			if (is_legacy(tbl_type.lq_type)) {				if (ant_toggle_count <				    NUM_TRY_BEFORE_ANTENNA_TOGGLE)					ant_toggle_count++;				else {					rs_toggle_antenna(&new_rate, &tbl_type);					ant_toggle_count = 1;				}			}			rs_dbgfs_set_mcs(lq_data, &new_rate, index);			lq_cmd->rs_table[index].rate_n_flags =					cpu_to_le32(new_rate.rate_n_flags);			repeat_rate--;			index++;		}		rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type,						&rate_idx);		if (is_mimo(tbl_type.lq_type))			lq_cmd->general_params.mimo_delimiter = index;		rs_get_lower_rate(lq_data, &tbl_type, rate_idx,				  use_ht_possible, &new_rate);		if (is_legacy(tbl_type.lq_type)) {			if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)				ant_toggle_count++;			else {				rs_toggle_antenna(&new_rate, &tbl_type);				ant_toggle_count = 1;			}			repeat_rate = IWL_NUMBER_TRY;		} else			repeat_rate = IWL_HT_NUMBER_TRY;		use_ht_possible = 0;		rs_dbgfs_set_mcs(lq_data, &new_rate, index);		lq_cmd->rs_table[index].rate_n_flags =				cpu_to_le32(new_rate.rate_n_flags);		index++;		repeat_rate--;	}	lq_cmd->general_params.dual_stream_ant_msk = 3;	lq_cmd->agg_params.agg_dis_start_th = 3;	lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);}static void *rs_alloc(struct ieee80211_local *local){	return local->hw.priv;}/* rate scale requires free function to be implemented */static void rs_free(void *priv_rate){	return;}static void rs_clear(void *priv_rate){	struct iwl_priv *priv = (struct iwl_priv *) priv_rate;	IWL_DEBUG_RATE("enter\n");	priv->lq_mngr.lq_ready = 0;#ifdef CONFIG_IWLWIFI_HT#ifdef CONFIG_IWLWIFI_HT_AGG	if (priv->lq_mngr.agg_ctrl.granted_ba)		iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);#endif /*CONFIG_IWLWIFI_HT_AGG */#endif /* CONFIG_IWLWIFI_HT */	IWL_DEBUG_RATE("leave\n");}static void rs_free_sta(void *priv, void *priv_sta){	struct iwl_rate_scale_priv *rs_priv = priv_sta;	IWL_DEBUG_RATE("enter\n");	kfree(rs_priv);	IWL_DEBUG_RATE("leave\n");}#ifdef CONFIG_MAC80211_DEBUGFSstatic int open_file_generic(struct inode *inode, struct file *file){	file->private_data = inode->i_private;	return 0;}static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,				struct iwl_rate *mcs, int index){	u32 base_rate;	if (rs_priv->phymode == (u8) MODE_IEEE80211A)		base_rate = 0x800D;	else		base_rate = 0x820A;	if (rs_priv->dbg_fixed.rate_n_flags) {		if (index < 12)			mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags;		else			mcs->rate_n_flags = base_rate;		IWL_DEBUG_RATE("Fixed rate ON\n");		return;	}	IWL_DEBUG_RATE("Fixed rate OFF\n");}static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,			const char __user *user_buf, size_t count, loff_t *ppos){	struct iwl_rate_scale_priv *rs_priv = file->private_data;	char buf[64];	int buf_size;	u32 parsed_rate;	memset(buf, 0, sizeof(buf));	buf_size = min(count, sizeof(buf) -  1);	if (copy_from_user(buf, user_buf, buf_size))		return -EFAULT;	if (sscanf(buf, "%x", &parsed_rate) == 1)		rs_priv->dbg_fixed.rate_n_flags = parsed_rate;	else		rs_priv->dbg_fixed.rate_n_flags = 0;	rs_priv->active_rate = 0x0FFF;	rs_priv->active_siso_rate = 0x1FD0;	rs_priv->active_mimo_rate = 0x1FD0;	IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",		rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags);	if (rs_priv->dbg_fixed.rate_n_flags) {		rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq);		rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC);	}	return count;}static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,			char __user *user_buf, size_t count, loff_t *ppos){	char buff[1024];	int desc = 0;	int i = 0;	struct iwl_rate_scale_priv *rs_priv = file->private_data;	desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id);	desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",			rs_priv->total_failed, rs_priv->total_success,			rs_priv->active_rate);	desc += sprintf(buff+desc, "fixed rate 0x%X\n",			rs_priv->dbg_fixed.rate_n_flags);	desc += sprintf(buff+desc, "general:"		"flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",		rs_priv->lq.general_params.flags,		rs_priv->lq.general_params.mimo_delimiter,		rs_priv->lq.general_params.single_stream_ant_msk,		rs_priv->lq.general_params.dual_stream_ant_msk);	desc += sprintf(buff+desc, "agg:"			"time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",			le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit),			rs_priv->lq.agg_params.agg_dis_start_th,			rs_priv->lq.agg_params.agg_frame_cnt_limit);	desc += sprintf(buff+desc,			"Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",			rs_priv->lq.general_params.start_rate_index[0],			rs_priv->lq.general_params.start_rate_index[1],			rs_priv->lq.general_params.start_rate_index[2],			rs_priv->lq.general_params.start_rate_index[3]);	for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)		desc += sprintf(buff+desc, " rate[%d] 0x%X\n",			i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags));	return simple_read_from_buffer(user_buf, count, ppos, buff, desc);}static const struct file_operations rs_sta_dbgfs_scale_table_ops = {	.write = rs_sta_dbgfs_scale_table_write,	.read = rs_sta_dbgfs_scale_table_read,	.open = open_file_generic,};static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,			char __user *user_buf, size_t count, loff_t *ppos){	char buff[1024];	int desc = 0;	int i, j;	struct iwl_rate_scale_priv *rs_priv = file->private_data;	for (i = 0; i < LQ_SIZE; i++) {		desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"				"rate=0x%X\n",				rs_priv->active_tbl == i?"*":"x",				rs_priv->lq_info[i].lq_type,				rs_priv->lq_info[i].is_SGI,				rs_priv->lq_info[i].is_fat,				rs_priv->lq_info[i].is_dup,				rs_priv->lq_info[i].current_rate.rate_n_flags);		for (j = 0; j < IWL_RATE_COUNT; j++) {			desc += sprintf(buff+desc,					"counter=%d success=%d %%=%d\n",					rs_priv->lq_info[i].win[j].counter,					rs_priv->lq_info[i].win[j].success_counter,					rs_priv->lq_info[i].win[j].success_ratio);		}	}	return simple_read_from_buffer(user_buf, count, ppos, buff, desc);}static const struct file_operations rs_sta_dbgfs_stats_table_ops = {	.read = rs_sta_dbgfs_stats_table_read,	.open = open_file_generic,};static void rs_add_debugfs(void *priv, void *priv_sta,					struct dentry *dir){	struct iwl_rate_scale_priv *rs_priv = priv_sta;	rs_priv->rs_sta_dbgfs_scale_table_file =		debugfs_create_file("rate_scale_table", 0600, dir,				rs_priv, &rs_sta_dbgfs_scale_table_ops);	rs_priv->rs_sta_dbgfs_stats_table_file =		debugfs_create_file("rate_stats_table", 0600, dir,			rs_priv, &rs_sta_dbgfs_stats_table_ops);}static void rs_remove_debugfs(void *priv, void *priv_sta){	struct iwl_rate_scale_priv *rs_priv = priv_sta;	debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file);	debugfs_remove(rs_priv->rs_sta_dbgfs_stats_table_file);}#endifstatic struct rate_control_ops rs_ops = {	.module = NULL,	.name = RS_NAME,	.tx_status = rs_tx_status,	.get_rate = rs_get_rate,	.rate_init = rs_rate_init,	.clear = rs_clear,	.alloc = rs_alloc,	.free = rs_free,	.alloc_sta = rs_alloc_sta,	.free_sta = rs_free_sta,#ifdef CONFIG_MAC80211_DEBUGFS	.add_sta_debugfs = rs_add_debugfs,	.remove_sta_debugfs = rs_remove_debugfs,#endif};int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id){	struct ieee80211_local *local = hw_to_local(hw);	struct iwl_priv *priv = hw->priv;	struct iwl_rate_scale_priv *rs_priv;	struct sta_info *sta;	int count = 0, i;	u32 samples = 0, success = 0, good = 0;	unsigned long now = jiffies;	u32 max_time = 0;	u8 lq_type, antenna;	sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);	if (!sta || !sta->rate_ctrl_priv) {		if (sta) {			sta_info_put(sta);			IWL_DEBUG_RATE("leave - no private rate data!\n");		} else			IWL_DEBUG_RATE("leave - no station!\n");		return sprintf(buf, "station %d not found\n", sta_id);	}	rs_priv = (void *)sta->rate_ctrl_priv;	lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type;	antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type;	if (is_legacy(lq_type))		i = IWL_RATE_54M_INDEX;	else		i = IWL_RATE_60M_INDEX;	while (1) {		u64 mask;		int j;		int active = rs_priv->active_tbl;		count +=		    sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2);		mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));		for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)			buf[count++] =				(rs_priv->lq_info[active].win[i].data & mask)				? '1' : '0';		samples += rs_priv->lq_info[active].win[i].counter;		good += rs_priv->lq_info[active].win[i].success_counter;		success += rs_priv->lq_info[active].win[i].success_counter *			   iwl_rates[i].ieee;		if (rs_priv->lq_info[active].win[i].stamp) {			int delta =				   jiffies_to_msecs(now -				   rs_priv->lq_info[active].win[i].stamp);			if (delta > max_time)				max_time = delta;			count += sprintf(&buf[count], "%5dms\n", delta);		} else			buf[count++] = '\n';		j = iwl_get_prev_ieee_rate(i);		if (j == i)			break;		i = j;	}	/* Display the average rate of all samples taken.	 *	 * NOTE:  We multiple # of samples by 2 since the IEEE measurement	 * added from iwl_rates is actually 2X the rate */	if (samples)		count += sprintf(&buf[count],			 "\nAverage rate is %3d.%02dMbs over last %4dms\n"			 "%3d%% success (%d good packets over %d tries)\n",			 success / (2 * samples), (success * 5 / samples) % 10,			 max_time, good * 100 / samples, good, samples);	else		count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");	count += sprintf(&buf[count], "\nrate scale type %d anntena %d "			 "active_search %d rate index %d\n", lq_type, antenna,			 rs_priv->search_better_tbl, sta->last_txrate);	sta_info_put(sta);	return count;}void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id){	struct iwl_priv *priv = hw->priv;	priv->lq_mngr.lq_ready = 1;}void iwl_rate_control_register(struct ieee80211_hw *hw){	ieee80211_rate_control_register(&rs_ops);}void iwl_rate_control_unregister(struct ieee80211_hw *hw){	ieee80211_rate_control_unregister(&rs_ops);}

⌨️ 快捷键说明

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