diff options
author | Luis R. Rodriguez <lrodriguez@atheros.com> | 2009-08-03 15:24:36 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-08-04 16:44:27 -0400 |
commit | 4f3acf81f2a47244f7403353784f528c92e98a6c (patch) | |
tree | 1db1b17c5779da0370b5e1e61723468eefe8721a /drivers | |
parent | 7819ac84b689b61340f29af6233fa1d15b76a6ef (diff) |
ath9k: move memory allocation of ath_hw to ath_init()
This lets us simplify attach code and arguments passed.
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/hw.c | 65 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/hw.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/main.c | 35 |
3 files changed, 44 insertions, 58 deletions
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c index 2e09204fc8ac..fcefea8461f6 100644 --- a/drivers/net/wireless/ath/ath9k/hw.c +++ b/drivers/net/wireless/ath/ath9k/hw.c | |||
@@ -437,20 +437,9 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah) | |||
437 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; | 437 | ah->config.serialize_regmode = SER_REG_MODE_AUTO; |
438 | } | 438 | } |
439 | 439 | ||
440 | static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc, | 440 | static void ath9k_hw_newstate(u16 devid, |
441 | int *status) | 441 | struct ath_hw *ah) |
442 | { | 442 | { |
443 | struct ath_hw *ah; | ||
444 | |||
445 | ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); | ||
446 | if (ah == NULL) { | ||
447 | DPRINTF(sc, ATH_DBG_FATAL, | ||
448 | "Cannot allocate memory for state block\n"); | ||
449 | *status = -ENOMEM; | ||
450 | return NULL; | ||
451 | } | ||
452 | |||
453 | ah->ah_sc = sc; | ||
454 | ah->hw_version.magic = AR5416_MAGIC; | 443 | ah->hw_version.magic = AR5416_MAGIC; |
455 | ah->regulatory.country_code = CTRY_DEFAULT; | 444 | ah->regulatory.country_code = CTRY_DEFAULT; |
456 | ah->hw_version.devid = devid; | 445 | ah->hw_version.devid = devid; |
@@ -479,8 +468,6 @@ static struct ath_hw *ath9k_hw_newstate(u16 devid, struct ath_softc *sc, | |||
479 | ah->gbeacon_rate = 0; | 468 | ah->gbeacon_rate = 0; |
480 | 469 | ||
481 | ah->power_mode = ATH9K_PM_UNDEFINED; | 470 | ah->power_mode = ATH9K_PM_UNDEFINED; |
482 | |||
483 | return ah; | ||
484 | } | 471 | } |
485 | 472 | ||
486 | static int ath9k_hw_rfattach(struct ath_hw *ah) | 473 | static int ath9k_hw_rfattach(struct ath_hw *ah) |
@@ -623,28 +610,25 @@ static int ath9k_hw_post_attach(struct ath_hw *ah) | |||
623 | return 0; | 610 | return 0; |
624 | } | 611 | } |
625 | 612 | ||
626 | static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, | 613 | static int ath9k_hw_do_attach(struct ath_hw *ah, |
627 | int *status) | 614 | u16 devid, |
615 | struct ath_softc *sc) | ||
628 | { | 616 | { |
629 | struct ath_hw *ah; | 617 | int r; |
630 | int ecode; | ||
631 | u32 i, j; | 618 | u32 i, j; |
632 | 619 | ||
633 | ah = ath9k_hw_newstate(devid, sc, status); | 620 | ath9k_hw_newstate(devid, ah); |
634 | if (ah == NULL) | ||
635 | return NULL; | ||
636 | |||
637 | ath9k_hw_set_defaults(ah); | 621 | ath9k_hw_set_defaults(ah); |
638 | 622 | ||
639 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { | 623 | if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { |
640 | DPRINTF(sc, ATH_DBG_FATAL, "Couldn't reset chip\n"); | 624 | DPRINTF(sc, ATH_DBG_FATAL, "Couldn't reset chip\n"); |
641 | ecode = -EIO; | 625 | r = -EIO; |
642 | goto bad; | 626 | goto bad; |
643 | } | 627 | } |
644 | 628 | ||
645 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { | 629 | if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { |
646 | DPRINTF(sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); | 630 | DPRINTF(sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n"); |
647 | ecode = -EIO; | 631 | r = -EIO; |
648 | goto bad; | 632 | goto bad; |
649 | } | 633 | } |
650 | 634 | ||
@@ -676,7 +660,7 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, | |||
676 | "Mac Chip Rev 0x%02x.%x is not supported by " | 660 | "Mac Chip Rev 0x%02x.%x is not supported by " |
677 | "this driver\n", ah->hw_version.macVersion, | 661 | "this driver\n", ah->hw_version.macVersion, |
678 | ah->hw_version.macRev); | 662 | ah->hw_version.macRev); |
679 | ecode = -EOPNOTSUPP; | 663 | r = -EOPNOTSUPP; |
680 | goto bad; | 664 | goto bad; |
681 | } | 665 | } |
682 | 666 | ||
@@ -878,8 +862,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, | |||
878 | else | 862 | else |
879 | ath9k_hw_disablepcie(ah); | 863 | ath9k_hw_disablepcie(ah); |
880 | 864 | ||
881 | ecode = ath9k_hw_post_attach(ah); | 865 | r = ath9k_hw_post_attach(ah); |
882 | if (ecode != 0) | 866 | if (r) |
883 | goto bad; | 867 | goto bad; |
884 | 868 | ||
885 | if (AR_SREV_9287_11(ah)) | 869 | 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 | } | 923 | } |
940 | } | 924 | } |
941 | 925 | ||
942 | ecode = ath9k_hw_init_macaddr(ah); | 926 | r = ath9k_hw_init_macaddr(ah); |
943 | if (ecode != 0) { | 927 | if (r) { |
944 | DPRINTF(sc, ATH_DBG_FATAL, | 928 | DPRINTF(sc, ATH_DBG_FATAL, |
945 | "Failed to initialize MAC address\n"); | 929 | "Failed to initialize MAC address\n"); |
946 | goto bad; | 930 | goto bad; |
@@ -953,14 +937,10 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc, | |||
953 | 937 | ||
954 | ath9k_init_nfcal_hist_buffer(ah); | 938 | ath9k_init_nfcal_hist_buffer(ah); |
955 | 939 | ||
956 | return ah; | 940 | return 0; |
957 | bad: | 941 | bad: |
958 | if (ah) | 942 | ath9k_hw_detach(ah); |
959 | ath9k_hw_detach(ah); | 943 | return r; |
960 | if (status) | ||
961 | *status = ecode; | ||
962 | |||
963 | return NULL; | ||
964 | } | 944 | } |
965 | 945 | ||
966 | static void ath9k_hw_init_bb(struct ath_hw *ah, | 946 | static void ath9k_hw_init_bb(struct ath_hw *ah, |
@@ -1206,10 +1186,8 @@ void ath9k_hw_detach(struct ath_hw *ah) | |||
1206 | kfree(ah); | 1186 | kfree(ah); |
1207 | } | 1187 | } |
1208 | 1188 | ||
1209 | struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error) | 1189 | int ath9k_hw_attach(struct ath_hw *ah, u16 devid, struct ath_softc *sc) |
1210 | { | 1190 | { |
1211 | struct ath_hw *ah = NULL; | ||
1212 | |||
1213 | switch (devid) { | 1191 | switch (devid) { |
1214 | case AR5416_DEVID_PCI: | 1192 | case AR5416_DEVID_PCI: |
1215 | case AR5416_DEVID_PCIE: | 1193 | case AR5416_DEVID_PCIE: |
@@ -1220,14 +1198,11 @@ struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error) | |||
1220 | case AR9285_DEVID_PCIE: | 1198 | case AR9285_DEVID_PCIE: |
1221 | case AR5416_DEVID_AR9287_PCI: | 1199 | case AR5416_DEVID_AR9287_PCI: |
1222 | case AR5416_DEVID_AR9287_PCIE: | 1200 | case AR5416_DEVID_AR9287_PCIE: |
1223 | ah = ath9k_hw_do_attach(devid, sc, error); | 1201 | return ath9k_hw_do_attach(ah, devid, sc); |
1224 | break; | ||
1225 | default: | 1202 | default: |
1226 | *error = -EOPNOTSUPP; | ||
1227 | break; | 1203 | break; |
1228 | } | 1204 | } |
1229 | 1205 | return -EOPNOTSUPP; | |
1230 | return ah; | ||
1231 | } | 1206 | } |
1232 | 1207 | ||
1233 | /*******/ | 1208 | /*******/ |
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h index 93a89302e79e..4a0d5f202a7e 100644 --- a/drivers/net/wireless/ath/ath9k/hw.h +++ b/drivers/net/wireless/ath/ath9k/hw.h | |||
@@ -544,7 +544,7 @@ struct ath_hw { | |||
544 | /* Attach, Detach, Reset */ | 544 | /* Attach, Detach, Reset */ |
545 | const char *ath9k_hw_probe(u16 vendorid, u16 devid); | 545 | const char *ath9k_hw_probe(u16 vendorid, u16 devid); |
546 | void ath9k_hw_detach(struct ath_hw *ah); | 546 | void ath9k_hw_detach(struct ath_hw *ah); |
547 | struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error); | 547 | int ath9k_hw_attach(struct ath_hw *ah, u16 devid, struct ath_softc *sc); |
548 | void ath9k_hw_rfdetach(struct ath_hw *ah); | 548 | void ath9k_hw_rfdetach(struct ath_hw *ah); |
549 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, | 549 | int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, |
550 | bool bChannelChange); | 550 | bool bChannelChange); |
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c index ada5fef924c8..c2b9974aa094 100644 --- a/drivers/net/wireless/ath/ath9k/main.c +++ b/drivers/net/wireless/ath/ath9k/main.c | |||
@@ -1295,7 +1295,7 @@ static int ath9k_reg_notifier(struct wiphy *wiphy, | |||
1295 | static int ath_init(u16 devid, struct ath_softc *sc) | 1295 | static int ath_init(u16 devid, struct ath_softc *sc) |
1296 | { | 1296 | { |
1297 | struct ath_hw *ah = NULL; | 1297 | struct ath_hw *ah = NULL; |
1298 | int error = 0, i; | 1298 | int r = 0, i; |
1299 | int csz = 0; | 1299 | int csz = 0; |
1300 | 1300 | ||
1301 | /* XXX: hardware will not be ready until ath_open() being called */ | 1301 | /* 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 | /* XXX assert csz is non-zero */ | 1322 | /* XXX assert csz is non-zero */ |
1323 | sc->cachelsz = csz << 2; /* convert to bytes */ | 1323 | sc->cachelsz = csz << 2; /* convert to bytes */ |
1324 | 1324 | ||
1325 | ah = ath9k_hw_attach(devid, sc, &error); | 1325 | ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); |
1326 | if (ah == NULL) { | 1326 | if (!ah) { |
1327 | DPRINTF(sc, ATH_DBG_FATAL, | ||
1328 | "Cannot allocate memory for state block\n"); | ||
1329 | r = -ENOMEM; | ||
1330 | goto bad_no_ah; | ||
1331 | } | ||
1332 | |||
1333 | ah->ah_sc = sc; | ||
1334 | |||
1335 | r = ath9k_hw_attach(ah, devid, sc); | ||
1336 | if (r) { | ||
1327 | DPRINTF(sc, ATH_DBG_FATAL, | 1337 | DPRINTF(sc, ATH_DBG_FATAL, |
1328 | "Unable to attach hardware; " | 1338 | "Unable to attach hardware; " |
1329 | "initialization status: %d\n", error); | 1339 | "initialization status: %d\n", r); |
1330 | goto bad; | 1340 | goto bad; |
1331 | } | 1341 | } |
1332 | sc->sc_ah = ah; | 1342 | sc->sc_ah = ah; |
@@ -1347,7 +1357,7 @@ static int ath_init(u16 devid, struct ath_softc *sc) | |||
1347 | for (i = 0; i < sc->keymax; i++) | 1357 | for (i = 0; i < sc->keymax; i++) |
1348 | ath9k_hw_keyreset(ah, (u16) i); | 1358 | ath9k_hw_keyreset(ah, (u16) i); |
1349 | 1359 | ||
1350 | if (error) | 1360 | if (r) |
1351 | goto bad; | 1361 | goto bad; |
1352 | 1362 | ||
1353 | /* default to MONITOR mode */ | 1363 | /* default to MONITOR mode */ |
@@ -1369,14 +1379,14 @@ static int ath_init(u16 devid, struct ath_softc *sc) | |||
1369 | if (sc->beacon.beaconq == -1) { | 1379 | if (sc->beacon.beaconq == -1) { |
1370 | DPRINTF(sc, ATH_DBG_FATAL, | 1380 | DPRINTF(sc, ATH_DBG_FATAL, |
1371 | "Unable to setup a beacon xmit queue\n"); | 1381 | "Unable to setup a beacon xmit queue\n"); |
1372 | error = -EIO; | 1382 | r = -EIO; |
1373 | goto bad2; | 1383 | goto bad2; |
1374 | } | 1384 | } |
1375 | sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0); | 1385 | sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0); |
1376 | if (sc->beacon.cabq == NULL) { | 1386 | if (sc->beacon.cabq == NULL) { |
1377 | DPRINTF(sc, ATH_DBG_FATAL, | 1387 | DPRINTF(sc, ATH_DBG_FATAL, |
1378 | "Unable to setup CAB xmit queue\n"); | 1388 | "Unable to setup CAB xmit queue\n"); |
1379 | error = -EIO; | 1389 | r = -EIO; |
1380 | goto bad2; | 1390 | goto bad2; |
1381 | } | 1391 | } |
1382 | 1392 | ||
@@ -1391,26 +1401,26 @@ static int ath_init(u16 devid, struct ath_softc *sc) | |||
1391 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) { | 1401 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) { |
1392 | DPRINTF(sc, ATH_DBG_FATAL, | 1402 | DPRINTF(sc, ATH_DBG_FATAL, |
1393 | "Unable to setup xmit queue for BK traffic\n"); | 1403 | "Unable to setup xmit queue for BK traffic\n"); |
1394 | error = -EIO; | 1404 | r = -EIO; |
1395 | goto bad2; | 1405 | goto bad2; |
1396 | } | 1406 | } |
1397 | 1407 | ||
1398 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) { | 1408 | if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) { |
1399 | DPRINTF(sc, ATH_DBG_FATAL, | 1409 | DPRINTF(sc, ATH_DBG_FATAL, |
1400 | "Unable to setup xmit queue for BE traffic\n"); | 1410 | "Unable to setup xmit queue for BE traffic\n"); |
1401 | error = -EIO; | 1411 | r = -EIO; |
1402 | goto bad2; | 1412 | goto bad2; |
1403 | } | 1413 | } |
1404 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) { | 1414 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) { |
1405 | DPRINTF(sc, ATH_DBG_FATAL, | 1415 | DPRINTF(sc, ATH_DBG_FATAL, |
1406 | "Unable to setup xmit queue for VI traffic\n"); | 1416 | "Unable to setup xmit queue for VI traffic\n"); |
1407 | error = -EIO; | 1417 | r = -EIO; |
1408 | goto bad2; | 1418 | goto bad2; |
1409 | } | 1419 | } |
1410 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) { | 1420 | if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) { |
1411 | DPRINTF(sc, ATH_DBG_FATAL, | 1421 | DPRINTF(sc, ATH_DBG_FATAL, |
1412 | "Unable to setup xmit queue for VO traffic\n"); | 1422 | "Unable to setup xmit queue for VO traffic\n"); |
1413 | error = -EIO; | 1423 | r = -EIO; |
1414 | goto bad2; | 1424 | goto bad2; |
1415 | } | 1425 | } |
1416 | 1426 | ||
@@ -1506,9 +1516,10 @@ bad2: | |||
1506 | bad: | 1516 | bad: |
1507 | if (ah) | 1517 | if (ah) |
1508 | ath9k_hw_detach(ah); | 1518 | ath9k_hw_detach(ah); |
1519 | bad_no_ah: | ||
1509 | ath9k_exit_debug(sc); | 1520 | ath9k_exit_debug(sc); |
1510 | 1521 | ||
1511 | return error; | 1522 | return r; |
1512 | } | 1523 | } |
1513 | 1524 | ||
1514 | void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) | 1525 | void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) |