Commit 10d8dd88 authored by Michael Buesch's avatar Michael Buesch Committed by John W. Linville

[PATCH] bcm43xx: split the channel helper functions, so that they can be used...

[PATCH] bcm43xx: split the channel helper functions, so that they can be used without a valid running core.
Signed-off-by: default avatarMichael Buesch <mbuesch@freenet.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent ad3f086c
...@@ -1169,7 +1169,7 @@ static void bcm43xx_geo_init(struct bcm43xx_private *bcm) ...@@ -1169,7 +1169,7 @@ static void bcm43xx_geo_init(struct bcm43xx_private *bcm)
if (have_a) { if (have_a) {
for (i = 0, channel = 0; channel < 201; channel++) { for (i = 0, channel = 0; channel < 201; channel++) {
chan = &geo.a[i++]; chan = &geo.a[i++];
chan->freq = bcm43xx_channel_to_freq(bcm, channel); chan->freq = bcm43xx_channel_to_freq_a(channel);
chan->channel = channel; chan->channel = channel;
} }
geo.a_channels = i; geo.a_channels = i;
...@@ -1177,7 +1177,7 @@ static void bcm43xx_geo_init(struct bcm43xx_private *bcm) ...@@ -1177,7 +1177,7 @@ static void bcm43xx_geo_init(struct bcm43xx_private *bcm)
if (have_bg) { if (have_bg) {
for (i = 0, channel = 1; channel < 15; channel++) { for (i = 0, channel = 1; channel < 15; channel++) {
chan = &geo.bg[i++]; chan = &geo.bg[i++];
chan->freq = bcm43xx_channel_to_freq(bcm, channel); chan->freq = bcm43xx_channel_to_freq_bg(channel);
chan->channel = channel; chan->channel = channel;
} }
geo.bg_channels = i; geo.bg_channels = i;
......
...@@ -187,58 +187,78 @@ struct bcm43xx_xmitstatus_queue { ...@@ -187,58 +187,78 @@ struct bcm43xx_xmitstatus_queue {
/* Lightweight function to convert a frequency (in Mhz) to a channel number. */ /* Lightweight function to convert a frequency (in Mhz) to a channel number. */
static inline static inline
u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm, u8 bcm43xx_freq_to_channel_a(int freq)
int freq) {
return ((freq - 5000) / 5);
}
static inline
u8 bcm43xx_freq_to_channel_bg(int freq)
{ {
u8 channel; u8 channel;
if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) { if (freq == 2484)
channel = (freq - 5000) / 5; channel = 14;
} else { else
if (freq == 2484) channel = (freq - 2407) / 5;
channel = 14;
else
channel = (freq - 2407) / 5;
}
return channel; return channel;
} }
static inline
u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
int freq)
{
if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
return bcm43xx_freq_to_channel_a(freq);
return bcm43xx_freq_to_channel_bg(freq);
}
/* Lightweight function to convert a channel number to a frequency (in Mhz). */ /* Lightweight function to convert a channel number to a frequency (in Mhz). */
static inline static inline
int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm, int bcm43xx_channel_to_freq_a(u8 channel)
u8 channel) {
return (5000 + (5 * channel));
}
static inline
int bcm43xx_channel_to_freq_bg(u8 channel)
{ {
int freq; int freq;
if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) { if (channel == 14)
freq = 5000 + (5 * channel); freq = 2484;
} else { else
if (channel == 14) freq = 2407 + (5 * channel);
freq = 2484;
else
freq = 2407 + (5 * channel);
}
return freq; return freq;
} }
static inline
int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
u8 channel)
{
if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
return bcm43xx_channel_to_freq_a(channel);
return bcm43xx_channel_to_freq_bg(channel);
}
/* Lightweight function to check if a channel number is valid. /* Lightweight function to check if a channel number is valid.
* Note that this does _NOT_ check for geographical restrictions! * Note that this does _NOT_ check for geographical restrictions!
*/ */
static inline static inline
int bcm43xx_is_valid_channel_a(u8 channel)
{
return (channel <= 200);
}
static inline
int bcm43xx_is_valid_channel_bg(u8 channel)
{
return (channel >= 1 && channel <= 14);
}
static inline
int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm, int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
u8 channel) u8 channel)
{ {
if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) { if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
if (channel <= 200) return bcm43xx_is_valid_channel_a(channel);
return 1; return bcm43xx_is_valid_channel_bg(channel);
} else {
if (channel >= 1 && channel <= 14)
return 1;
}
return 0;
} }
void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf); void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
......
...@@ -111,8 +111,9 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev, ...@@ -111,8 +111,9 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
unsigned long flags; unsigned long flags;
u8 channel; u8 channel;
int freq; int freq;
int err = 0; int err = -EINVAL;
spin_lock_irqsave(&bcm->lock, flags);
if ((data->freq.m >= 0) && (data->freq.m <= 1000)) { if ((data->freq.m >= 0) && (data->freq.m <= 1000)) {
channel = data->freq.m; channel = data->freq.m;
freq = bcm43xx_channel_to_freq(bcm, channel); freq = bcm43xx_channel_to_freq(bcm, channel);
...@@ -121,16 +122,17 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev, ...@@ -121,16 +122,17 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
freq = data->freq.m; freq = data->freq.m;
} }
if (!bcm43xx_is_valid_channel(bcm, channel)) if (!bcm43xx_is_valid_channel(bcm, channel))
return -EINVAL; goto out_unlock;
spin_lock_irqsave(&bcm->lock, flags);
if (bcm->initialized) { if (bcm->initialized) {
//ieee80211softmac_disassoc(softmac, $REASON); //ieee80211softmac_disassoc(softmac, $REASON);
bcm43xx_mac_suspend(bcm); bcm43xx_mac_suspend(bcm);
err = bcm43xx_radio_selectchannel(bcm, channel, 0); err = bcm43xx_radio_selectchannel(bcm, channel, 0);
bcm43xx_mac_enable(bcm); bcm43xx_mac_enable(bcm);
} else } else {
bcm->current_core->radio->initial_channel = channel; bcm->current_core->radio->initial_channel = channel;
err = 0;
}
out_unlock:
spin_unlock_irqrestore(&bcm->lock, flags); spin_unlock_irqrestore(&bcm->lock, flags);
return err; return err;
......
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