2009-04-16 00:22:13

by Nick Kossifidis

[permalink] [raw]
Subject: [PATCH 1/7] ath5k: Allow user/driver to set txpower

* Now that we have regulatory control enable the driver to set txpower on hw
* Also use txpower table offset so that we can match power range set by user/driver with indices on power table.

Tested 2 different cards (a CM9 and an RF5112-based ubnt) and got the same output using a remote machine to measure
per-packet rssi (conected the cards using attenuators). I also switched between various tx power levels and i saw an
equal power change on the remote machine (so txpower changes as expected) and verified that we have the same output
on each rate.

Signed-off-by: Nick Kossifidis <[email protected]>

---
drivers/net/wireless/ath/ath5k/ath5k.h | 7 +++--
drivers/net/wireless/ath/ath5k/base.c | 10 ++++++-
drivers/net/wireless/ath/ath5k/phy.c | 45 ++++++++++++++++++++++++++-----
drivers/net/wireless/ath/ath5k/reset.c | 2 +-
4 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 60c6d2e..04b7345 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -1100,11 +1100,12 @@ struct ath5k_hw {
/* Values in 0.25dB units */
s16 txp_min_pwr;
s16 txp_max_pwr;
+ /* Values in 0.5dB units */
s16 txp_offset;
s16 txp_ofdm;
- /* Values in dB units */
- s16 txp_cck_ofdm_pwr_delta;
s16 txp_cck_ofdm_gainf_delta;
+ /* Value in dB units */
+ s16 txp_cck_ofdm_pwr_delta;
} ah_txpower;

struct {
@@ -1271,7 +1272,7 @@ extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah);
extern int ath5k_hw_phy_disable(struct ath5k_hw *ah);
/* TX power setup */
extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, u8 ee_mode, u8 txpower);
-extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 ee_mode, u8 txpower);
+extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower);

/*
* Functions used internaly
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index ff6d4f8..3390603 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -2768,13 +2768,21 @@ static int
ath5k_config(struct ieee80211_hw *hw, u32 changed)
{
struct ath5k_softc *sc = hw->priv;
+ struct ath5k_hw *ah = sc->ah;
struct ieee80211_conf *conf = &hw->conf;
int ret;

mutex_lock(&sc->lock);

sc->bintval = conf->beacon_int;
- sc->power_level = conf->power_level;
+
+ if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
+ (sc->power_level != conf->power_level)) {
+ sc->power_level = conf->power_level;
+
+ /* Half dB steps */
+ ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
+ }

ret = ath5k_chan_set(sc, conf->channel);

diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index b48b29d..bb61b8e 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -168,9 +168,6 @@ int ath5k_hw_rfgain_opt_init(struct ath5k_hw *ah)
* tx power and a Peak to Average Power Detector (PAPD) will try
* to measure the gain.
*
- * TODO: Use propper tx power setting for the probe packet so
- * that we don't observe a serious power drop on the receiver
- *
* XXX: How about forcing a tx packet (bypassing PCU arbitrator etc)
* just after we enable the probe so that we don't mess with
* standard traffic ? Maybe it's time to use sw interrupts and
@@ -186,7 +183,7 @@ static void ath5k_hw_request_rfgain_probe(struct ath5k_hw *ah)

/* Send the packet with 2dB below max power as
* patent doc suggest */
- ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max_pwr - 4,
+ ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_ofdm - 4,
AR5K_PHY_PAPD_PROBE_TXPOWER) |
AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE);

@@ -2482,8 +2479,19 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr,
for (i = 8; i <= 15; i++)
rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta;

- ah->ah_txpower.txp_min_pwr = rates[7];
- ah->ah_txpower.txp_max_pwr = rates[0];
+ /* Now that we have all rates setup use table offset to
+ * match the power range set by user with the power indices
+ * on PCDAC/PDADC table */
+ for (i = 0; i < 16; i++) {
+ rates[i] += ah->ah_txpower.txp_offset;
+ /* Don't get out of bounds */
+ if (rates[i] > 63)
+ rates[i] = 63;
+ }
+
+ /* Min/max in 0.25dB units */
+ ah->ah_txpower.txp_min_pwr = 2 * rates[7];
+ ah->ah_txpower.txp_max_pwr = 2 * rates[0];
ah->ah_txpower.txp_ofdm = rates[7];
}

@@ -2591,16 +2599,37 @@ ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel,
return 0;
}

-int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 mode, u8 txpower)
+int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower)
{
/*Just a try M.F.*/
struct ieee80211_channel *channel = &ah->ah_current_channel;
+ u8 ee_mode;

ATH5K_TRACE(ah->ah_sc);
+
+ switch (channel->hw_value & CHANNEL_MODES) {
+ case CHANNEL_A:
+ case CHANNEL_T:
+ case CHANNEL_XR:
+ ee_mode = AR5K_EEPROM_MODE_11A;
+ break;
+ case CHANNEL_G:
+ case CHANNEL_TG:
+ ee_mode = AR5K_EEPROM_MODE_11G;
+ break;
+ case CHANNEL_B:
+ ee_mode = AR5K_EEPROM_MODE_11B;
+ break;
+ default:
+ ATH5K_ERR(ah->ah_sc,
+ "invalid channel: %d\n", channel->center_freq);
+ return -EINVAL;
+ }
+
ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER,
"changing txpower to %d\n", txpower);

- return ath5k_hw_txpower(ah, channel, mode, txpower);
+ return ath5k_hw_txpower(ah, channel, ee_mode, txpower);
}

#undef _ATH5K_PHY
diff --git a/drivers/net/wireless/ath/ath5k/reset.c b/drivers/net/wireless/ath/ath5k/reset.c
index faede82..23d6fc8 100644
--- a/drivers/net/wireless/ath/ath5k/reset.c
+++ b/drivers/net/wireless/ath/ath5k/reset.c
@@ -1001,7 +1001,7 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
* Set TX power (FIXME)
*/
ret = ath5k_hw_txpower(ah, channel, ee_mode,
- AR5K_TUNE_DEFAULT_TXPOWER);
+ ah->ah_txpower.txp_max_pwr / 2);
if (ret)
return ret;



2009-04-28 16:46:05

by John W. Linville

[permalink] [raw]
Subject: Re: [PATCH 1/7] ath5k: Allow user/driver to set txpower

On Fri, Apr 24, 2009 at 12:01:43AM -0400, Bob Copeland wrote:
> On Thu, Apr 16, 2009 at 03:22:20AM +0300, Nick Kossifidis wrote:
> > * Now that we have regulatory control enable the driver to set txpower on hw
> > * Also use txpower table offset so that we can match power range set by user/driver with indices on power table.
>
> BTW I gave this patchset a spin on my rf 5413 and it works fine here,
> so feel free to add my Acked-By on the series. Does it need anything
> besides a reposting with 72-col changelogs?

The series seems fine, but I was waiting for a repost with the
narrower changelogs...?

John
--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

2009-04-29 16:48:37

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [ath5k-devel] [PATCH 1/7] ath5k: Allow user/driver to set txpower

2009/4/28 John W. Linville <[email protected]>:
> On Fri, Apr 24, 2009 at 12:01:43AM -0400, Bob Copeland wrote:
>> On Thu, Apr 16, 2009 at 03:22:20AM +0300, Nick Kossifidis wrote:
>> > =C2=A0* Now that we have regulatory control enable the driver to s=
et txpower on hw
>> > =C2=A0* Also use txpower table offset so that we can match power r=
ange set by user/driver with indices on power table.
>>
>> BTW I gave this patchset a spin on my rf 5413 and it works fine here=
,
>> so feel free to add my Acked-By on the series. =C2=A0Does it need an=
ything
>> besides a reposting with 72-col changelogs?
>
> The series seems fine, but I was waiting for a repost with the
> narrower changelogs...?
>
> John

Is this really needed ? I'm full right now ;-(
Can anyone else resend this plz ?



--=20
GPG ID: 0xD21DB2DB
As you read this post global entropy rises. Have Fun ;-)
Nick

2009-04-21 13:14:42

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [ath5k-devel] [PATCH 1/7] ath5k: Allow user/driver to set txpower

2009/4/19 Bob Copeland <[email protected]>:
> On Thu, Apr 16, 2009 at 03:22:20AM +0300, Nick Kossifidis wrote:
>> =C2=A0* Now that we have regulatory control enable the driver to set=
txpower on hw
>
> I assume this needs my patch for the CTLs (reproduced below). =C2=A0A=
ny
> objections to it?
>
> From: Bob Copeland <[email protected]>
> Subject: [PATCH] ath5k: use ctl settings based on current regdomain
>
> Update ath5k to use the ctl settings for tx power based on current
> regulatory domain.
>
> Signed-off-by: Bob Copeland <[email protected]>
> ---
> =C2=A0drivers/net/wireless/ath/ath5k/phy.c | =C2=A0 19 +++++++-------=
-----
> =C2=A01 files changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wirel=
ess/ath/ath5k/phy.c
> index 9e2faae..0ecd16f 100644
> --- a/drivers/net/wireless/ath/ath5k/phy.c
> +++ b/drivers/net/wireless/ath/ath5k/phy.c
> @@ -1743,8 +1743,6 @@ done:
> =C2=A0* Get the max edge power for this channel if
> =C2=A0* we have such data from EEPROM's Conformance Test
> =C2=A0* Limits (CTL), and limit max power if needed.
> - *
> - * FIXME: Only works for world regulatory domains
> =C2=A0*/
> =C2=A0static void
> =C2=A0ath5k_get_max_ctl_power(struct ath5k_hw *ah,
> @@ -1760,26 +1758,23 @@ ath5k_get_max_ctl_power(struct ath5k_hw *ah,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0u8 ctl_idx =3D 0xFF;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0u32 target =3D channel->center_freq;
>
> - =C2=A0 =C2=A0 =C2=A0 /* Find out a CTL for our mode that's not mapp=
ed
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0* on a specific reg domain.
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0*
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0* TODO: Map our current reg domain to on=
e of the 3 available
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0* reg domain ids so that we can support =
more CTLs. */
> + =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D ath_regd_get_band_ctl(&ah->ah_reg=
ulatory, channel->band);
> +
> =C2=A0 =C2=A0 =C2=A0 =C2=A0switch (channel->hw_value & CHANNEL_MODES)=
{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_A:
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D AR5K_=
CTL_11A | AR5K_CTL_NO_REGDOMAIN;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode |=3D AR5K=
_CTL_11A;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_G:
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D AR5K_=
CTL_11G | AR5K_CTL_NO_REGDOMAIN;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode |=3D AR5K=
_CTL_11G;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_B:
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D AR5K_=
CTL_11B | AR5K_CTL_NO_REGDOMAIN;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode |=3D AR5K=
_CTL_11B;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_T:
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D AR5K_=
CTL_TURBO | AR5K_CTL_NO_REGDOMAIN;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode |=3D AR5K=
_CTL_TURBO;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_TG:
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode =3D AR5K_=
CTL_TURBOG | AR5K_CTL_NO_REGDOMAIN;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ctl_mode |=3D AR5K=
_CTL_TURBOG;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0case CHANNEL_XR:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Fall throug=
h */


Acked-by: Nick Kossifidis <[email protected]>




--=20
GPG ID: 0xD21DB2DB
As you read this post global entropy rises. Have Fun ;-)
Nick

2009-04-24 04:02:34

by Bob Copeland

[permalink] [raw]
Subject: Re: [PATCH 1/7] ath5k: Allow user/driver to set txpower

On Thu, Apr 16, 2009 at 03:22:20AM +0300, Nick Kossifidis wrote:
> * Now that we have regulatory control enable the driver to set txpower on hw
> * Also use txpower table offset so that we can match power range set by user/driver with indices on power table.

BTW I gave this patchset a spin on my rf 5413 and it works fine here,
so feel free to add my Acked-By on the series. Does it need anything
besides a reposting with 72-col changelogs?

--
Bob Copeland %% http://www.bobcopeland.com


2009-04-19 14:47:30

by Bob Copeland

[permalink] [raw]
Subject: Re: [PATCH 1/7] ath5k: Allow user/driver to set txpower

On Thu, Apr 16, 2009 at 03:22:20AM +0300, Nick Kossifidis wrote:
> * Now that we have regulatory control enable the driver to set txpower on hw

I assume this needs my patch for the CTLs (reproduced below). Any
objections to it?

From: Bob Copeland <[email protected]>
Subject: [PATCH] ath5k: use ctl settings based on current regdomain

Update ath5k to use the ctl settings for tx power based on current
regulatory domain.

Signed-off-by: Bob Copeland <[email protected]>
---
drivers/net/wireless/ath/ath5k/phy.c | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index 9e2faae..0ecd16f 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -1743,8 +1743,6 @@ done:
* Get the max edge power for this channel if
* we have such data from EEPROM's Conformance Test
* Limits (CTL), and limit max power if needed.
- *
- * FIXME: Only works for world regulatory domains
*/
static void
ath5k_get_max_ctl_power(struct ath5k_hw *ah,
@@ -1760,26 +1758,23 @@ ath5k_get_max_ctl_power(struct ath5k_hw *ah,
u8 ctl_idx = 0xFF;
u32 target = channel->center_freq;

- /* Find out a CTL for our mode that's not mapped
- * on a specific reg domain.
- *
- * TODO: Map our current reg domain to one of the 3 available
- * reg domain ids so that we can support more CTLs. */
+ ctl_mode = ath_regd_get_band_ctl(&ah->ah_regulatory, channel->band);
+
switch (channel->hw_value & CHANNEL_MODES) {
case CHANNEL_A:
- ctl_mode = AR5K_CTL_11A | AR5K_CTL_NO_REGDOMAIN;
+ ctl_mode |= AR5K_CTL_11A;
break;
case CHANNEL_G:
- ctl_mode = AR5K_CTL_11G | AR5K_CTL_NO_REGDOMAIN;
+ ctl_mode |= AR5K_CTL_11G;
break;
case CHANNEL_B:
- ctl_mode = AR5K_CTL_11B | AR5K_CTL_NO_REGDOMAIN;
+ ctl_mode |= AR5K_CTL_11B;
break;
case CHANNEL_T:
- ctl_mode = AR5K_CTL_TURBO | AR5K_CTL_NO_REGDOMAIN;
+ ctl_mode |= AR5K_CTL_TURBO;
break;
case CHANNEL_TG:
- ctl_mode = AR5K_CTL_TURBOG | AR5K_CTL_NO_REGDOMAIN;
+ ctl_mode |= AR5K_CTL_TURBOG;
break;
case CHANNEL_XR:
/* Fall through */
--
1.6.0.6

--
Bob Copeland %% http://www.bobcopeland.com


2009-04-29 17:03:58

by Bob Copeland

[permalink] [raw]
Subject: Re: [ath5k-devel] [PATCH 1/7] ath5k: Allow user/driver to set txpower

On Wed, 29 Apr 2009 19:48:35 +0300, Nick Kossifidis wrote
> > The series seems fine, but I was waiting for a repost with the
> > narrower changelogs...?
> >
> > John
>
> Is this really needed ? I'm full right now ;-(
> Can anyone else resend this plz ?

No worries, I'll fix and resend them.

--
Bob Copeland %% http://www.bobcopeland.com