Commit 8c512765 authored by Dan Williams's avatar Dan Williams Committed by David S. Miller

[PATCH] libertas: simplify and clean up data rate handling

Remove unused/duplicated fields and consolidate static data rate arrays,
for example the libertas_supported_rates[] and datarates[] arrays in
the bss_descriptor structure, and the libertas_supported_rates field
in the wlan_adapter structure.

Introduce libertas_fw_index_to_data_rate and libertas_data_rate_to_fw_index
functions and use them everywhere firmware requires a rate index rather
than a rate array.

The firmware requires the 4 basic rates to have the MSB set, but most
other stuff doesn't, like WEXT and mesh ioctls.  Therefore, only set the MSB
on basic rates when pushing rate arrays to firmware instead of doing a ton
of (rate & 0x7f) everywhere.
Signed-off-by: default avatarDan Williams <dcbw@redhat.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent e5241472
......@@ -607,17 +607,14 @@ static int wlan_cmd_802_11_data_rate(wlan_private * priv,
cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
S_DS_GEN);
cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
pdatarate->action = cpu_to_le16(cmd_action);
if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
pdatarate->rates[0] = libertas_data_rate_to_fw_index(adapter->cur_rate);
lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
adapter->datarate);
adapter->cur_rate);
} else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
lbs_deb_cmd("Setting FW for AUTO rate\n");
}
......
......@@ -430,21 +430,18 @@ static int wlan_ret_802_11_data_rate(wlan_private * priv,
{
struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate;
wlan_adapter *adapter = priv->adapter;
u8 dot11datarate;
lbs_deb_enter(LBS_DEB_CMD);
lbs_dbg_hex("DATA_RATE_RESP: data_rate- ",
(u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate));
lbs_dbg_hex("DATA_RATE_RESP: data_rate- ", (u8 *) pdatarate,
sizeof(struct cmd_ds_802_11_data_rate));
dot11datarate = pdatarate->datarate[0];
if (pdatarate->action == cpu_to_le16(CMD_ACT_GET_TX_RATE)) {
memcpy(adapter->libertas_supported_rates, pdatarate->datarate,
sizeof(adapter->libertas_supported_rates));
}
adapter->datarate = libertas_index_to_data_rate(dot11datarate);
/* FIXME: get actual rates FW can do if this command actually returns
* all data rates supported.
*/
adapter->cur_rate = libertas_fw_index_to_data_rate(pdatarate->rates[0]);
lbs_deb_enter(LBS_DEB_CMD);
lbs_deb_leave(LBS_DEB_CMD);
return 0;
}
......
......@@ -44,8 +44,8 @@ int libertas_execute_next_command(wlan_private * priv);
int libertas_process_event(wlan_private * priv);
void libertas_interrupt(struct net_device *);
int libertas_set_radio_control(wlan_private * priv);
u32 libertas_index_to_data_rate(u8 index);
u8 libertas_data_rate_to_index(u32 rate);
u32 libertas_fw_index_to_data_rate(u8 index);
u8 libertas_data_rate_to_fw_index(u32 rate);
void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen);
void libertas_upload_rx_packet(wlan_private * priv, struct sk_buff *skb);
......
......@@ -246,10 +246,7 @@ static inline void lbs_dbg_hex(char *prompt, u8 * buf, int len)
((((int)(AVG) * (N -1)) + ((u16)(SNRNF) * \
AVG_SCALE)) / N))
#define B_SUPPORTED_RATES 8
#define G_SUPPORTED_RATES 14
#define WLAN_SUPPORTED_RATES 14
#define MAX_RATES 14
#define MAX_LEDS 8
......@@ -263,11 +260,7 @@ typedef struct _wlan_adapter wlan_adapter;
extern const char libertas_driver_version[];
extern u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE];
extern u8 libertas_supported_rates[G_SUPPORTED_RATES];
extern u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES];
extern u8 libertas_adhoc_rates_b[4];
extern u8 libertas_bg_rates[MAX_RATES];
/** ENUM definition*/
/** SNRNF_TYPE */
......
......@@ -72,10 +72,8 @@ struct current_bss_params {
u8 band;
/** channel */
u8 channel;
/** number of rates supported */
int numofrates;
/** supported rates*/
u8 datarates[WLAN_SUPPORTED_RATES];
/** zero-terminated array of supported data rates */
u8 rates[MAX_RATES + 1];
};
/** sleep_params */
......@@ -296,9 +294,6 @@ struct _wlan_adapter {
u32 fragthsd;
u32 rtsthsd;
u32 datarate;
u8 is_datarate_auto;
u16 listeninterval;
u16 prescan;
u8 txretrycount;
......@@ -364,10 +359,9 @@ struct _wlan_adapter {
u8 radioon;
u32 preamble;
/** Multi bands Parameter*/
u8 libertas_supported_rates[G_SUPPORTED_RATES];
/** Blue Tooth Co-existence Arbitration */
/** data rate stuff */
u8 cur_rate;
u8 auto_rate;
/** sleep_params */
struct sleep_params sp;
......
......@@ -214,7 +214,10 @@ static void wlan_init_adapter(wlan_private * priv)
adapter->txantenna = RF_ANTENNA_2;
adapter->rxantenna = RF_ANTENNA_AUTO;
adapter->is_datarate_auto = 1;
adapter->auto_rate = 1;
adapter->cur_rate = 0;
adapter->adhoc_grate_enabled = 0;
adapter->beaconperiod = MRVDRV_BEACON_INTERVAL;
// set default capabilities
......@@ -229,10 +232,6 @@ static void wlan_init_adapter(wlan_private * priv)
adapter->needtowakeup = 0;
adapter->locallisteninterval = 0; /* default value in firmware will be used */
adapter->datarate = 0; // Initially indicate the rate as auto
adapter->adhoc_grate_enabled = 0;
adapter->intcounter = 0;
adapter->currenttxskb = NULL;
......
......@@ -428,8 +428,8 @@ struct PS_CMD_ConfirmSleep {
struct cmd_ds_802_11_data_rate {
__le16 action;
__le16 reserverd;
u8 datarate[G_SUPPORTED_RATES];
__le16 reserved;
u8 rates[MAX_RATES];
};
struct cmd_ds_802_11_rate_adapt_rateset {
......@@ -447,7 +447,7 @@ struct cmd_ds_802_11_ad_hoc_start {
union ieeetypes_phyparamset phyparamset;
__le16 probedelay;
__le16 capability;
u8 datarate[G_SUPPORTED_RATES];
u8 rates[MAX_RATES];
u8 tlv_memory_size_pad[100];
} __attribute__ ((packed));
......@@ -462,7 +462,7 @@ struct adhoc_bssdesc {
union ieeetypes_phyparamset phyparamset;
union IEEEtypes_ssparamset ssparamset;
__le16 capability;
u8 datarates[G_SUPPORTED_RATES];
u8 rates[MAX_RATES];
/* DO NOT ADD ANY FIELDS TO THIS STRUCTURE. It is used below in the
* Adhoc join command and will cause a binary layout mismatch with
......
This diff is collapsed.
......@@ -53,4 +53,6 @@ extern int libertas_do_adhocstop_ioctl(wlan_private * priv);
int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req);
void libertas_unset_basic_rate_flags(u8 * rates, size_t len);
#endif
......@@ -150,29 +150,60 @@ static struct region_cfp_table region_cfp_table[] = {
};
/**
* the rates supported
* the table to keep region code
*/
u8 libertas_supported_rates[G_SUPPORTED_RATES] =
{ 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
0 };
u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
{ 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
/**
* the rates supported for ad-hoc G mode
* 802.11b/g supported bitrates (in 500Kb/s units)
*/
u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] =
{ 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
0 };
u8 libertas_bg_rates[MAX_RATES] =
{ 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
0x00, 0x00 };
/**
* the rates supported for ad-hoc B mode
* FW rate table. FW refers to rates by their index in this table, not by the
* rate value itself. Values of 0x00 are
* reserved positions.
*/
u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 };
static u8 fw_data_rates[MAX_RATES] =
{ 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
};
/**
* the table to keep region code
* @brief use index to get the data rate
*
* @param idx The index of data rate
* @return data rate or 0
*/
u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
{ 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
u32 libertas_fw_index_to_data_rate(u8 idx)
{
if (idx >= sizeof(fw_data_rates))
idx = 0;
return fw_data_rates[idx];
}
/**
* @brief use rate to get the index
*
* @param rate data rate
* @return index or 0
*/
u8 libertas_data_rate_to_fw_index(u32 rate)
{
u8 i;
if (!rate)
return 0;
for (i = 0; i < sizeof(fw_data_rates); i++) {
if (rate == fw_data_rates[i])
return i;
}
return 0;
}
/**
* Attributes exported through sysfs
......
......@@ -260,8 +260,8 @@ int libertas_process_rxed_packet(wlan_private * priv, struct sk_buff *skb)
/* Take the data rate from the rxpd structure
* only if the rate is auto
*/
if (adapter->is_datarate_auto)
adapter->datarate = libertas_index_to_data_rate(p_rx_pd->rx_rate);
if (adapter->auto_rate)
adapter->cur_rate = libertas_fw_index_to_data_rate(p_rx_pd->rx_rate);
wlan_compute_rssi(priv, p_rx_pd);
......@@ -424,9 +424,8 @@ static int process_rxed_802_11_packet(wlan_private * priv, struct sk_buff *skb)
/* Take the data rate from the rxpd structure
* only if the rate is auto
*/
if (adapter->is_datarate_auto) {
adapter->datarate = libertas_index_to_data_rate(prxpd->rx_rate);
}
if (adapter->auto_rate)
adapter->cur_rate = libertas_fw_index_to_data_rate(prxpd->rx_rate);
wlan_compute_rssi(priv, prxpd);
......
......@@ -17,6 +17,7 @@
#include "decl.h"
#include "dev.h"
#include "scan.h"
#include "join.h"
//! Approximate amount of data needed to pass a scan result back to iwlist
#define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
......@@ -904,22 +905,14 @@ static int libertas_process_bss(struct bss_descriptor * bss,
struct ieeetypes_dsparamset *pDS;
struct ieeetypes_cfparamset *pCF;
struct ieeetypes_ibssparamset *pibss;
u8 *pos, *end;
u8 *pRate;
u8 bytestocopy;
u8 ratesize;
u16 beaconsize;
u8 founddatarateie;
int ret;
struct ieeetypes_countryinfoset *pcountryinfo;
u8 *pos, *end, *p;
u8 n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0;
u16 beaconsize = 0;
int ret;
lbs_deb_enter(LBS_DEB_ASSOC);
founddatarateie = 0;
ratesize = 0;
beaconsize = 0;
if (*bytesleft >= sizeof(beaconsize)) {
/* Extract & convert beacon size from the command buffer */
beaconsize = le16_to_cpup((void *)*pbeaconinfo);
......@@ -1005,11 +998,9 @@ static int libertas_process_bss(struct bss_descriptor * bss,
break;
case MFIE_TYPE_RATES:
memcpy(bss->datarates, elem->data, elem->len);
memmove(bss->libertas_supported_rates, elem->data,
elem->len);
ratesize = elem->len;
founddatarateie = 1;
n_basic_rates = min_t(u8, MAX_RATES, elem->len);
memcpy(bss->rates, elem->data, n_basic_rates);
got_basic_rates = 1;
break;
case MFIE_TYPE_FH_SET:
......@@ -1070,22 +1061,15 @@ static int libertas_process_bss(struct bss_descriptor * bss,
* already found. Data rate IE should come before
* extended supported rate IE
*/
if (!founddatarateie)
if (!got_basic_rates)
break;
if ((elem->len + ratesize) > WLAN_SUPPORTED_RATES) {
bytestocopy =
(WLAN_SUPPORTED_RATES - ratesize);
} else {
bytestocopy = elem->len;
}
n_ex_rates = elem->len;
if (n_basic_rates + n_ex_rates > MAX_RATES)
n_ex_rates = MAX_RATES - n_basic_rates;
pRate = (u8 *) bss->datarates;
pRate += ratesize;
memmove(pRate, elem->data, bytestocopy);
pRate = (u8 *) bss->libertas_supported_rates;
pRate += ratesize;
memmove(pRate, elem->data, bytestocopy);
p = bss->rates + n_basic_rates;
memcpy(p, elem->data, n_ex_rates);
break;
case MFIE_TYPE_GENERIC:
......@@ -1123,6 +1107,7 @@ static int libertas_process_bss(struct bss_descriptor * bss,
/* Timestamp */
bss->last_scanned = jiffies;
libertas_unset_basic_rate_flags(bss->rates, sizeof(bss->rates));
ret = 0;
......@@ -1530,12 +1515,9 @@ static inline char *libertas_translate_scan(wlan_private *priv,
iwe.u.bitrate.disabled = 0;
iwe.u.bitrate.value = 0;
for (j = 0; j < sizeof(bss->libertas_supported_rates); j++) {
u8 rate = bss->libertas_supported_rates[j];
if (rate == 0)
break; /* no more rates */
/* Bit rate given in 500 kb/s units (+ 0x80) */
iwe.u.bitrate.value = (rate & 0x7f) * 500000;
for (j = 0; bss->rates[j] && (j < sizeof(bss->rates)); j++) {
/* Bit rate given in 500 kb/s units */
iwe.u.bitrate.value = bss->rates[j] * 500000;
current_val = iwe_stream_add_value(start, current_val,
stop, &iwe, IW_EV_PARAM_LEN);
}
......
......@@ -152,14 +152,14 @@ struct bss_descriptor {
u32 atimwindow;
u8 mode;
u8 libertas_supported_rates[WLAN_SUPPORTED_RATES];
/* zero-terminated array of supported data rates */
u8 rates[MAX_RATES + 1];
__le64 timestamp; //!< TSF value included in the beacon/probe response
unsigned long last_scanned;
union ieeetypes_phyparamset phyparamset;
union IEEEtypes_ssparamset ssparamset;
u8 datarates[WLAN_SUPPORTED_RATES];
u64 networktsf; //!< TSF timestamp from the current firmware TSF
......
......@@ -21,14 +21,6 @@
#include "assoc.h"
/**
* the rates supported by the card
*/
static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
{ 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
};
/**
* @brief Convert mw value to dbm value
*
......@@ -187,57 +179,21 @@ int wlan_radio_ioctl(wlan_private * priv, u8 option)
}
/**
* @brief Copy rates
*
* @param dest A pointer to Dest Buf
* @param src A pointer to Src Buf
* @param len The len of Src Buf
* @return Number of rates copyed
*/
static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
{
int i;
for (i = 0; i < len && src[i]; i++, pos++) {
if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
break;
dest[pos] = src[i];
}
return pos;
}
/**
* @brief Get active data rates
* @brief Copy active data rates based on adapter mode and status
*
* @param adapter A pointer to wlan_adapter structure
* @param rate The buf to return the active rates
* @return The number of rates
*/
static int get_active_data_rates(wlan_adapter * adapter,
u8* rates)
static void copy_active_data_rates(wlan_adapter * adapter, u8 * rates)
{
int k = 0;
lbs_deb_enter(LBS_DEB_WEXT);
if (adapter->connect_status != LIBERTAS_CONNECTED) {
if (adapter->mode == IW_MODE_INFRA) {
lbs_deb_wext("infra\n");
k = copyrates(rates, k, libertas_supported_rates,
sizeof(libertas_supported_rates));
} else {
lbs_deb_wext("Adhoc G\n");
k = copyrates(rates, k, libertas_adhoc_rates_g,
sizeof(libertas_adhoc_rates_g));
}
} else {
k = copyrates(rates, 0, adapter->curbssparams.datarates,
adapter->curbssparams.numofrates);
}
if (adapter->connect_status != LIBERTAS_CONNECTED)
memcpy(rates, libertas_bg_rates, MAX_RATES);
else
memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
return k;
lbs_deb_leave(LBS_DEB_WEXT);
}
static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
......@@ -673,7 +629,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
wlan_adapter *adapter = priv->adapter;
struct iw_range *range = (struct iw_range *)extra;
struct chan_freq_power *cfp;
u8 rates[WLAN_SUPPORTED_RATES];
u8 rates[MAX_RATES + 1];
u8 flag = 0;
......@@ -686,12 +642,10 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
range->max_nwid = 0;
memset(rates, 0, sizeof(rates));
range->num_bitrates = get_active_data_rates(adapter, rates);
for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
i++) {
range->bitrate[i] = (rates[i] & 0x7f) * 500000;
}
copy_active_data_rates(adapter, rates);
range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
for (i = 0; i < range->num_bitrates; i++)
range->bitrate[i] = rates[i] * 500000;
range->num_bitrates = i;
lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
range->num_bitrates);
......@@ -1080,88 +1034,46 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
return ret;
}
/**
* @brief use index to get the data rate
*
* @param index The index of data rate
* @return data rate or 0
*/
u32 libertas_index_to_data_rate(u8 index)
{
if (index >= sizeof(libertas_wlan_data_rates))
index = 0;
return libertas_wlan_data_rates[index];
}
/**
* @brief use rate to get the index
*
* @param rate data rate
* @return index or 0
*/
u8 libertas_data_rate_to_index(u32 rate)
{
u8 *ptr;
if (rate)
if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
sizeof(libertas_wlan_data_rates))))
return (ptr - libertas_wlan_data_rates);
return 0;
}
static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
struct iw_param *vwrq, char *extra)
{
wlan_private *priv = dev->priv;
wlan_adapter *adapter = priv->adapter;
u32 data_rate;
u32 new_rate;
u16 action;
int ret = 0;
u8 rates[WLAN_SUPPORTED_RATES];
u8 *rate;
int ret = -EINVAL;
u8 rates[MAX_RATES + 1];
lbs_deb_enter(LBS_DEB_WEXT);
lbs_deb_wext("vwrq->value %d\n", vwrq->value);
/* Auto rate? */
if (vwrq->value == -1) {
action = CMD_ACT_SET_TX_AUTO; // Auto
adapter->is_datarate_auto = 1;
adapter->datarate = 0;
action = CMD_ACT_SET_TX_AUTO;
adapter->auto_rate = 1;
adapter->cur_rate = 0;
} else {
if (vwrq->value % 100000) {
return -EINVAL;
}
data_rate = vwrq->value / 500000;
if (vwrq->value % 100000)
goto out;
memset(rates, 0, sizeof(rates));
get_active_data_rates(adapter, rates);
rate = rates;
while (*rate) {
lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
data_rate);
if ((*rate & 0x7f) == (data_rate & 0x7f))
break;
rate++;
}
if (!*rate) {
lbs_pr_alert("fixed data rate 0x%X out "
"of range\n", data_rate);
return -EINVAL;
copy_active_data_rates(adapter, rates);
new_rate = vwrq->value / 500000;
if (!memchr(rates, new_rate, sizeof(rates))) {
lbs_pr_alert("fixed data rate 0x%X out of range\n",
new_rate);
goto out;
}
adapter->datarate = data_rate;
adapter->cur_rate = new_rate;
action = CMD_ACT_SET_TX_FIX_RATE;
adapter->is_datarate_auto = 0;
adapter->auto_rate = 0;
}
ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
action, CMD_OPTION_WAITFORRSP, 0, NULL);
out:
lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
return ret;
}
......@@ -1174,14 +1086,19 @@ static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
lbs_deb_enter(LBS_DEB_WEXT);
if (adapter->is_datarate_auto) {
vwrq->fixed = 0;
if (adapter->connect_status == LIBERTAS_CONNECTED) {
vwrq->value = adapter->cur_rate * 500000;
if (adapter->auto_rate)
vwrq->fixed = 0;
else
vwrq->fixed = 1;
} else {
vwrq->fixed = 1;
vwrq->fixed = 0;
vwrq->value = 0;
}
vwrq->value = adapter->datarate * 500000;
lbs_deb_leave(LBS_DEB_WEXT);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment