Commit 4f3acf81 authored by Luis R. Rodriguez's avatar Luis R. Rodriguez Committed by John W. Linville

ath9k: move memory allocation of ath_hw to ath_init()

This lets us simplify attach code and arguments passed.
Signed-off-by: default avatarLuis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 7819ac84
...@@ -437,20 +437,9 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah) ...@@ -437,20 +437,9 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah)
ah->config.serialize_regmode = SER_REG_MODE_AUTO; ah->config.serialize_regmode = SER_REG_MODE_AUTO;
} }
static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc, static void ath9k_hw_newstate(u16 devid,
int *status) struct ath_hw *ah)
{ {
struct ath_hw *ah;
ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
if (ah == NULL) {
DPRINTF(sc, ATH_DBG_FATAL,
"Cannot allocate memory for state block\n");
*status = -ENOMEM;
return NULL;
}
ah->ah_sc = sc;
ah->hw_version.magic = AR5416_MAGIC; ah->hw_version.magic = AR5416_MAGIC;
ah->regulatory.country_code = CTRY_DEFAULT; ah->regulatory.country_code = CTRY_DEFAULT;
ah->hw_version.devid = devid; ah->hw_version.devid = devid;
...@@ -479,8 +468,6 @@ static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc, ...@@ -479,8 +468,6 @@ static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc,
ah->gbeacon_rate = 0; ah->gbeacon_rate = 0;
ah->power_mode = ATH9K_PM_UNDEFINED; ah->power_mode = ATH9K_PM_UNDEFINED;
return ah;
} }
static int ath9k_hw_rfattach(struct ath_hw *ah) static int ath9k_hw_rfattach(struct ath_hw *ah)
...@@ -623,28 +610,25 @@ static int ath9k_hw_post_attach(struct ath_hw *ah) ...@@ -623,28 +610,25 @@ static int ath9k_hw_post_attach(struct ath_hw *ah)
return 0; return 0;
} }
static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, static int ath9k_hw_do_attach(struct ath_hw *ah,
int *status) u16 devid,
struct ath_softc *sc)
{ {
struct ath_hw *ah; int r;
int ecode;
u32 i, j; u32 i, j;
ah = ath9k_hw_newstate(devid, sc, status); ath9k_hw_newstate(devid, ah);
if (ah == NULL)
return NULL;
ath9k_hw_set_defaults(ah); ath9k_hw_set_defaults(ah);
if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
DPRINTF(sc, ATH_DBG_FATAL, "Couldn't reset chip\n"); DPRINTF(sc, ATH_DBG_FATAL, "Couldn't reset chip\n");
ecode = -EIO; r = -EIO;
goto bad; goto bad;
} }
if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
DPRINTF(sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); DPRINTF(sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
ecode = -EIO; r = -EIO;
goto bad; goto bad;
} }
...@@ -676,7 +660,7 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, ...@@ -676,7 +660,7 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
"Mac Chip Rev 0x%02x.%x is not supported by " "Mac Chip Rev 0x%02x.%x is not supported by "
"this driver\n", ah->hw_version.macVersion, "this driver\n", ah->hw_version.macVersion,
ah->hw_version.macRev); ah->hw_version.macRev);
ecode = -EOPNOTSUPP; r = -EOPNOTSUPP;
goto bad; goto bad;
} }
...@@ -878,8 +862,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, ...@@ -878,8 +862,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
else else
ath9k_hw_disablepcie(ah); ath9k_hw_disablepcie(ah);
ecode = ath9k_hw_post_attach(ah); r = ath9k_hw_post_attach(ah);
if (ecode != 0) if (r)
goto bad; goto bad;
if (AR_SREV_9287_11(ah)) if (AR_SREV_9287_11(ah))
...@@ -939,8 +923,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, ...@@ -939,8 +923,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
} }
} }
ecode = ath9k_hw_init_macaddr(ah); r = ath9k_hw_init_macaddr(ah);
if (ecode != 0) { if (r) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Failed to initialize MAC address\n"); "Failed to initialize MAC address\n");
goto bad; goto bad;
...@@ -953,14 +937,10 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, ...@@ -953,14 +937,10 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
ath9k_init_nfcal_hist_buffer(ah); ath9k_init_nfcal_hist_buffer(ah);
return ah; return 0;
bad: bad:
if (ah) ath9k_hw_detach(ah);
ath9k_hw_detach(ah); return r;
if (status)
*status = ecode;
return NULL;
} }
static void ath9k_hw_init_bb(struct ath_hw *ah, static void ath9k_hw_init_bb(struct ath_hw *ah,
...@@ -1206,10 +1186,8 @@ void ath9k_hw_detach(struct ath_hw *ah) ...@@ -1206,10 +1186,8 @@ void ath9k_hw_detach(struct ath_hw *ah)
kfree(ah); kfree(ah);
} }
struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error) int ath9k_hw_attach(struct ath_hw *ah, u16 devid, struct ath_softc *sc)
{ {
struct ath_hw *ah = NULL;
switch (devid) { switch (devid) {
case AR5416_DEVID_PCI: case AR5416_DEVID_PCI:
case AR5416_DEVID_PCIE: case AR5416_DEVID_PCIE:
...@@ -1220,14 +1198,11 @@ struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error) ...@@ -1220,14 +1198,11 @@ struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error)
case AR9285_DEVID_PCIE: case AR9285_DEVID_PCIE:
case AR5416_DEVID_AR9287_PCI: case AR5416_DEVID_AR9287_PCI:
case AR5416_DEVID_AR9287_PCIE: case AR5416_DEVID_AR9287_PCIE:
ah = ath9k_hw_do_attach(devid, sc, error); return ath9k_hw_do_attach(ah, devid, sc);
break;
default: default:
*error = -EOPNOTSUPP;
break; break;
} }
return -EOPNOTSUPP;
return ah;
} }
/*******/ /*******/
......
...@@ -544,7 +544,7 @@ struct ath_hw { ...@@ -544,7 +544,7 @@ struct ath_hw {
/* Attach, Detach, Reset */ /* Attach, Detach, Reset */
const char *ath9k_hw_probe(u16 vendorid, u16 devid); const char *ath9k_hw_probe(u16 vendorid, u16 devid);
void ath9k_hw_detach(struct ath_hw *ah); void ath9k_hw_detach(struct ath_hw *ah);
struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error); int ath9k_hw_attach(struct ath_hw *ah, u16 devid, struct ath_softc *sc);
void ath9k_hw_rfdetach(struct ath_hw *ah); void ath9k_hw_rfdetach(struct ath_hw *ah);
int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
bool bChannelChange); bool bChannelChange);
......
...@@ -1295,7 +1295,7 @@ static int ath9k_reg_notifier(struct wiphy *wiphy, ...@@ -1295,7 +1295,7 @@ static int ath9k_reg_notifier(struct wiphy *wiphy,
static int ath_init(u16 devid, struct ath_softc *sc) static int ath_init(u16 devid, struct ath_softc *sc)
{ {
struct ath_hw *ah = NULL; struct ath_hw *ah = NULL;
int error = 0, i; int r = 0, i;
int csz = 0; int csz = 0;
/* XXX: hardware will not be ready until ath_open() being called */ /* XXX: hardware will not be ready until ath_open() being called */
...@@ -1322,11 +1322,21 @@ static int ath_init(u16 devid, struct ath_softc *sc) ...@@ -1322,11 +1322,21 @@ static int ath_init(u16 devid, struct ath_softc *sc)
/* XXX assert csz is non-zero */ /* XXX assert csz is non-zero */
sc->cachelsz = csz << 2; /* convert to bytes */ sc->cachelsz = csz << 2; /* convert to bytes */
ah = ath9k_hw_attach(devid, sc, &error); ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
if (ah == NULL) { if (!ah) {
DPRINTF(sc, ATH_DBG_FATAL,
"Cannot allocate memory for state block\n");
r = -ENOMEM;
goto bad_no_ah;
}
ah->ah_sc = sc;
r = ath9k_hw_attach(ah, devid, sc);
if (r) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to attach hardware; " "Unable to attach hardware; "
"initialization status: %d\n", error); "initialization status: %d\n", r);
goto bad; goto bad;
} }
sc->sc_ah = ah; sc->sc_ah = ah;
...@@ -1347,7 +1357,7 @@ static int ath_init(u16 devid, struct ath_softc *sc) ...@@ -1347,7 +1357,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
for (i = 0; i < sc->keymax; i++) for (i = 0; i < sc->keymax; i++)
ath9k_hw_keyreset(ah, (u16) i); ath9k_hw_keyreset(ah, (u16) i);
if (error) if (r)
goto bad; goto bad;
/* default to MONITOR mode */ /* default to MONITOR mode */
...@@ -1369,14 +1379,14 @@ static int ath_init(u16 devid, struct ath_softc *sc) ...@@ -1369,14 +1379,14 @@ static int ath_init(u16 devid, struct ath_softc *sc)
if (sc->beacon.beaconq == -1) { if (sc->beacon.beaconq == -1) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup a beacon xmit queue\n"); "Unable to setup a beacon xmit queue\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0); sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
if (sc->beacon.cabq == NULL) { if (sc->beacon.cabq == NULL) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup CAB xmit queue\n"); "Unable to setup CAB xmit queue\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
...@@ -1391,26 +1401,26 @@ static int ath_init(u16 devid, struct ath_softc *sc) ...@@ -1391,26 +1401,26 @@ static int ath_init(u16 devid, struct ath_softc *sc)
if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) { if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup xmit queue for BK traffic\n"); "Unable to setup xmit queue for BK traffic\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) { if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup xmit queue for BE traffic\n"); "Unable to setup xmit queue for BE traffic\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) { if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup xmit queue for VI traffic\n"); "Unable to setup xmit queue for VI traffic\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) { if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
DPRINTF(sc, ATH_DBG_FATAL, DPRINTF(sc, ATH_DBG_FATAL,
"Unable to setup xmit queue for VO traffic\n"); "Unable to setup xmit queue for VO traffic\n");
error = -EIO; r = -EIO;
goto bad2; goto bad2;
} }
...@@ -1506,9 +1516,10 @@ static int ath_init(u16 devid, struct ath_softc *sc) ...@@ -1506,9 +1516,10 @@ static int ath_init(u16 devid, struct ath_softc *sc)
bad: bad:
if (ah) if (ah)
ath9k_hw_detach(ah); ath9k_hw_detach(ah);
bad_no_ah:
ath9k_exit_debug(sc); ath9k_exit_debug(sc);
return error; return r;
} }
void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
......
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