ath9k: Enable dynamic power save in ath9k.
PATCH 1/1 ath9k: Enable dynamic power save in ath9k.
This patch implements dynamic power save feature for ath9k.
--- drivers/net/wireless/ath9k/ath9k.h | 2 + drivers/net/wireless/ath9k/core.h | 19 ++++++++++++++++ drivers/net/wireless/ath9k/hw.c | 5 +-- drivers/net/wireless/ath9k/hw.h | 1 - drivers/net/wireless/ath9k/main.c | 42 +++++++++++++++++++++++++++++++++++- drivers/net/wireless/ath9k/recv.c | 6 +++++ 6 files changed, 70 insertions(+), 5 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +2 -0
@@ -790,6 +790,8 @@ struct ath_hal {u16 ah_currentRD5G;u16 ah_currentRD2G;char ah_iso[4 ]; +enum ath9k_power_mode ah_powerMode; +enum ath9k_power_mode ah_restoreMode;struct ath9k_channel ah_channels[150 ];struct ath9k_channel *ah_curchan;
drivers/net/wireless/ath9k/core.h +19 -0
@@ -692,6 +692,7 @@ enum PROT_MODE {#define SC_OP_RFKILL_REGISTERED BIT(11)#define SC_OP_RFKILL_SW_BLOCKED BIT(12)#define SC_OP_RFKILL_HW_BLOCKED BIT(13) +#define SC_OP_WAIT_FOR_BEACON BIT(14)struct ath_softc {struct ieee80211_hw *hw;
@@ -719,6 +720,8 @@ struct ath_softc {DECLARE_BITMAP (sc_keymap,ATH_KEYMAX );u8 sc_splitmic;u8 sc_protrix; +atomic_t ps_usecount; +enum ath9k_int sc_imask;enum PROT_MODE sc_protmode;enum ath9k_ht_extprotspacing sc_ht_extprotspacing;
@@ -751,4 +754,20 @@ int ath_get_hal_qnum(u16 queue, struct ath_softc *sc);int ath_get_mac80211_qnum (u32 queue,struct ath_softc *sc);int ath_cabq_update (struct ath_softc *); +#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \ + } \ + atomic_inc(&sc->ps_usecount); \ + } while (0); + +#define ATH9K_PS_RESTORE (sc) \ + do { \ + if (atomic_dec_and_test(&sc->ps_usecount) && \ + (sc->hw->conf.flags & IEEE80211_CONF_PS)) \ + ath9k_hw_setpower(sc->sc_ah, ah->ah_restoreMode); \ + } while (0);#endif /* CORE_H */
drivers/net/wireless/ath9k/hw.c +2 -3
@@ -2735,7 +2735,7 @@ bool ath9k_hw_setpower(struct ath_hal *ah,int status = true, setChip = true;DPRINTF (ah->ah_sc,ATH_DBG_POWER_MGMT ,"%s -> %s (%s)\n" , - modes[ahp->ah_powerMode], modes[mode], + modes[ah->ah_powerMode], modes[mode], setChip ?"set chip " :"" );switch (mode) {
@@ -2754,8 +2754,7 @@ bool ath9k_hw_setpower(struct ath_hal *ah, "Unknown power mode %u\n", mode);return false; } - ahp->ah_powerMode = mode; - + ah->ah_powerMode = mode;return status; }
drivers/net/wireless/ath9k/hw.h +0 -1
@@ -830,7 +830,6 @@ struct ath_hal_5416 {bool ah_chipFullSleep;u32 ah_atimWindow;u16 ah_antennaSwitchSwap; -enum ath9k_power_mode ah_powerMode;enum ath9k_ant_setting ah_diversityControl;/* Calibration */
drivers/net/wireless/ath9k/main.c +41 -1
140 lines not on this page · raw message
drivers/net/wireless/ath9k/recv.c +6 -0
@@ -622,6 +622,12 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush) }else { sc->rx.rxotherant =0 ; } + +if (ieee80211_is_beacon (hdr->frame_control) && + (sc->sc_flags &SC_OP_WAIT_FOR_BEACON )) { + sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON ; +ath9k_hw_setpower (sc->sc_ah,ATH9K_PM_NETWORK_SLEEP ); + } requeue:list_move_tail (&bf->list, &sc->rx.rxbuf);ath_rx_buf_link (sc, bf);
Signature · 1 line
1.6.0.1
Johannes Berg
maintainerQuoted 6 lines · Vivek Natarajan
drivers/net/wireless/ath9k/core.h +6
-0+#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \
drivers/net/wireless/ath9k/core.h int ath_get_hal_qnum(u16 queue, struct ath_softc *sc); · line 772
Quoted 10 lines
drivers/net/wireless/ath9k/core.h +10
-0+ } \ +atomic_inc (&sc->ps_usecount); \ + }while (0 ); + +#define ATH9K_PS_RESTORE (sc) \ + do { \ + if (atomic_dec_and_test(&sc->ps_usecount) && \ + (sc->hw->conf.flags & IEEE80211_CONF_PS)) \ + ath9k_hw_setpower(sc->sc_ah, ah->ah_restoreMode); \ + } while (0);
I think those would be better as static inlines rather than macros.
johannes
PS: Your clock seems to be off by 12.5 hours or so?
Johannes Berg
maintainerQuoted 11 lines · Johannes Berg
drivers/net/wireless/ath9k/core.h int ath_get_hal_qnum(u16 queue, struct ath_softc *sc); · line 765
Quoted 9 lines · Vivek Natarajan
drivers/net/wireless/ath9k/core.h +9
-0+#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \ + } \ + atomic_inc(&sc->ps_usecount); \ + } while (0);
Also, this seems racy, shouldn't it use something like if (atomic_inc_return() == 1) ?
johannes
Quoted 12 lines · On Monday 29 December 2008 13:11:00 Johannes Berg wrote:
Quoted 10 lines · Vivek Natarajan
drivers/net/wireless/ath9k/core.h +10
-0+#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \ + } \ + atomic_inc(&sc->ps_usecount); \ + } while (0); +
Quoted 8 lines
drivers/net/wireless/ath9k/core.h int ath_get_hal_qnum(u16 queue, struct ath_softc *sc); · line 772
Quoted 6 lines
drivers/net/wireless/ath9k/core.h +6
-0+#define ATH9K_PS_RESTORE (sc) \ + do { \ + if (atomic_dec_and_test(&sc->ps_usecount) && \ + (sc->hw->conf.flags & IEEE80211_CONF_PS)) \ + ath9k_hw_setpower(sc->sc_ah, ah->ah_restoreMode); \ + } while (0);I think those would be better as static inlines rather than macros.
And the do-while c-block-protection of the macro is buggy. It has an extra semicolon at the end, which defeats the whole purpose.
Signature · 1 line
Greetings, Michael.
Quoted 21 lines · Johannes Berg
Quoted 6 lines · Vivek Natarajan
drivers/net/wireless/ath9k/core.h +6
-0+#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \drivers/net/wireless/ath9k/core.h int ath_get_hal_qnum(u16 queue, struct ath_softc *sc); · line 772
Quoted 10 lines
drivers/net/wireless/ath9k/core.h +10
-0+ } \ +atomic_inc (&sc->ps_usecount); \ + }while (0 ); + +#define ATH9K_PS_RESTORE (sc) \ + do { \ + if (atomic_dec_and_test(&sc->ps_usecount) && \ + (sc->hw->conf.flags & IEEE80211_CONF_PS)) \ + ath9k_hw_setpower(sc->sc_ah, ah->ah_restoreMode); \ + } while (0);I think those would be better as static inlines rather than macros.
Quoted 1 line
johannes
Thanks Johannes. I'll change them.
Quoted 2 lines
Also, this seems racy, shouldn't it use something like if (
atomic_inc_return()== 1) ?
Thanks.This seems much better.
Vivek.
Quoted 23 lines · Vivek Natarajan
Quoted 21 lines · Johannes Berg
Quoted 6 lines · Vivek Natarajan
drivers/net/wireless/ath9k/core.h +6
-0+#define ATH9K_PS_WAKEUP (sc) \ + do { \ + if (!atomic_read(&sc->ps_usecount) && \ + (ah->ah_powerMode != ATH9K_PM_AWAKE)) { \ + ah->ah_restoreMode = ah->ah_powerMode; \ + ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); \drivers/net/wireless/ath9k/core.h int ath_get_hal_qnum(u16 queue, struct ath_softc *sc); · line 772
Quoted 10 lines
drivers/net/wireless/ath9k/core.h +10
-0+ } \ +atomic_inc (&sc->ps_usecount); \ + }while (0 ); + +#define ATH9K_PS_RESTORE (sc) \ + do { \ + if (atomic_dec_and_test(&sc->ps_usecount) && \ + (sc->hw->conf.flags & IEEE80211_CONF_PS)) \ + ath9k_hw_setpower(sc->sc_ah, ah->ah_restoreMode); \ + } while (0);I think those would be better as static inlines rather than macros.
Quoted 8 lines
Quoted 1 line
johannes
Thanks Johannes. I'll change them.
Quoted 2 lines
Also, this seems racy, shouldn't it use something like if (
atomic_inc_return()== 1) ?Thanks.This seems much better.
Did you repost this? I don't see it. Please (re?)send it to the list w/ the requested changes.
John
Signature · 2 lines
John W. Linville Linux should be at the core [email protected] of your literate lifestyle.