aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/init.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c116
1 files changed, 40 insertions, 76 deletions
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index f69ef5d48c7b..4b1abc7da98c 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/ath9k_platform.h> 21#include <linux/ath9k_platform.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/relay.h>
23 24
24#include "ath9k.h" 25#include "ath9k.h"
25 26
@@ -302,16 +303,15 @@ static void setup_ht_cap(struct ath_softc *sc,
302 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; 303 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
303} 304}
304 305
305static int ath9k_reg_notifier(struct wiphy *wiphy, 306static void ath9k_reg_notifier(struct wiphy *wiphy,
306 struct regulatory_request *request) 307 struct regulatory_request *request)
307{ 308{
308 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 309 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
309 struct ath_softc *sc = hw->priv; 310 struct ath_softc *sc = hw->priv;
310 struct ath_hw *ah = sc->sc_ah; 311 struct ath_hw *ah = sc->sc_ah;
311 struct ath_regulatory *reg = ath9k_hw_regulatory(ah); 312 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
312 int ret;
313 313
314 ret = ath_reg_notifier_apply(wiphy, request, reg); 314 ath_reg_notifier_apply(wiphy, request, reg);
315 315
316 /* Set tx power */ 316 /* Set tx power */
317 if (ah->curchan) { 317 if (ah->curchan) {
@@ -321,8 +321,6 @@ static int ath9k_reg_notifier(struct wiphy *wiphy,
321 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit; 321 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
322 ath9k_ps_restore(sc); 322 ath9k_ps_restore(sc);
323 } 323 }
324
325 return ret;
326} 324}
327 325
328/* 326/*
@@ -337,7 +335,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
337 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 335 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
338 u8 *ds; 336 u8 *ds;
339 struct ath_buf *bf; 337 struct ath_buf *bf;
340 int i, bsize, error, desc_len; 338 int i, bsize, desc_len;
341 339
342 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n", 340 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
343 name, nbuf, ndesc); 341 name, nbuf, ndesc);
@@ -353,8 +351,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
353 if ((desc_len % 4) != 0) { 351 if ((desc_len % 4) != 0) {
354 ath_err(common, "ath_desc not DWORD aligned\n"); 352 ath_err(common, "ath_desc not DWORD aligned\n");
355 BUG_ON((desc_len % 4) != 0); 353 BUG_ON((desc_len % 4) != 0);
356 error = -ENOMEM; 354 return -ENOMEM;
357 goto fail;
358 } 355 }
359 356
360 dd->dd_desc_len = desc_len * nbuf * ndesc; 357 dd->dd_desc_len = desc_len * nbuf * ndesc;
@@ -378,12 +375,11 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
378 } 375 }
379 376
380 /* allocate descriptors */ 377 /* allocate descriptors */
381 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len, 378 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
382 &dd->dd_desc_paddr, GFP_KERNEL); 379 &dd->dd_desc_paddr, GFP_KERNEL);
383 if (dd->dd_desc == NULL) { 380 if (!dd->dd_desc)
384 error = -ENOMEM; 381 return -ENOMEM;
385 goto fail; 382
386 }
387 ds = (u8 *) dd->dd_desc; 383 ds = (u8 *) dd->dd_desc;
388 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n", 384 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
389 name, ds, (u32) dd->dd_desc_len, 385 name, ds, (u32) dd->dd_desc_len,
@@ -391,12 +387,9 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
391 387
392 /* allocate buffers */ 388 /* allocate buffers */
393 bsize = sizeof(struct ath_buf) * nbuf; 389 bsize = sizeof(struct ath_buf) * nbuf;
394 bf = kzalloc(bsize, GFP_KERNEL); 390 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
395 if (bf == NULL) { 391 if (!bf)
396 error = -ENOMEM; 392 return -ENOMEM;
397 goto fail2;
398 }
399 dd->dd_bufptr = bf;
400 393
401 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) { 394 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
402 bf->bf_desc = ds; 395 bf->bf_desc = ds;
@@ -422,12 +415,6 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
422 list_add_tail(&bf->list, head); 415 list_add_tail(&bf->list, head);
423 } 416 }
424 return 0; 417 return 0;
425fail2:
426 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
427 dd->dd_desc_paddr);
428fail:
429 memset(dd, 0, sizeof(*dd));
430 return error;
431} 418}
432 419
433static int ath9k_init_queues(struct ath_softc *sc) 420static int ath9k_init_queues(struct ath_softc *sc)
@@ -457,11 +444,13 @@ static int ath9k_init_channels_rates(struct ath_softc *sc)
457 ATH9K_NUM_CHANNELS); 444 ATH9K_NUM_CHANNELS);
458 445
459 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) { 446 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
460 channels = kmemdup(ath9k_2ghz_chantable, 447 channels = devm_kzalloc(sc->dev,
461 sizeof(ath9k_2ghz_chantable), GFP_KERNEL); 448 sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
462 if (!channels) 449 if (!channels)
463 return -ENOMEM; 450 return -ENOMEM;
464 451
452 memcpy(channels, ath9k_2ghz_chantable,
453 sizeof(ath9k_2ghz_chantable));
465 sc->sbands[IEEE80211_BAND_2GHZ].channels = channels; 454 sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
466 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ; 455 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
467 sc->sbands[IEEE80211_BAND_2GHZ].n_channels = 456 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
@@ -472,14 +461,13 @@ static int ath9k_init_channels_rates(struct ath_softc *sc)
472 } 461 }
473 462
474 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) { 463 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
475 channels = kmemdup(ath9k_5ghz_chantable, 464 channels = devm_kzalloc(sc->dev,
476 sizeof(ath9k_5ghz_chantable), GFP_KERNEL); 465 sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
477 if (!channels) { 466 if (!channels)
478 if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
479 kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
480 return -ENOMEM; 467 return -ENOMEM;
481 }
482 468
469 memcpy(channels, ath9k_5ghz_chantable,
470 sizeof(ath9k_5ghz_chantable));
483 sc->sbands[IEEE80211_BAND_5GHZ].channels = channels; 471 sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
484 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ; 472 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
485 sc->sbands[IEEE80211_BAND_5GHZ].n_channels = 473 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
@@ -565,10 +553,11 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
565 int ret = 0, i; 553 int ret = 0, i;
566 int csz = 0; 554 int csz = 0;
567 555
568 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); 556 ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
569 if (!ah) 557 if (!ah)
570 return -ENOMEM; 558 return -ENOMEM;
571 559
560 ah->dev = sc->dev;
572 ah->hw = sc->hw; 561 ah->hw = sc->hw;
573 ah->hw_version.devid = devid; 562 ah->hw_version.devid = devid;
574 ah->reg_ops.read = ath9k_ioread32; 563 ah->reg_ops.read = ath9k_ioread32;
@@ -636,7 +625,7 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
636 if (pdata && pdata->eeprom_name) { 625 if (pdata && pdata->eeprom_name) {
637 ret = ath9k_eeprom_request(sc, pdata->eeprom_name); 626 ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
638 if (ret) 627 if (ret)
639 goto err_eeprom; 628 return ret;
640 } 629 }
641 630
642 /* Initializes the hardware for all supported chipsets */ 631 /* Initializes the hardware for all supported chipsets */
@@ -676,10 +665,6 @@ err_queues:
676 ath9k_hw_deinit(ah); 665 ath9k_hw_deinit(ah);
677err_hw: 666err_hw:
678 ath9k_eeprom_release(sc); 667 ath9k_eeprom_release(sc);
679err_eeprom:
680 kfree(ah);
681 sc->sc_ah = NULL;
682
683 return ret; 668 return ret;
684} 669}
685 670
@@ -844,8 +829,8 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
844 829
845 /* Bring up device */ 830 /* Bring up device */
846 error = ath9k_init_softc(devid, sc, bus_ops); 831 error = ath9k_init_softc(devid, sc, bus_ops);
847 if (error != 0) 832 if (error)
848 goto error_init; 833 return error;
849 834
850 ah = sc->sc_ah; 835 ah = sc->sc_ah;
851 common = ath9k_hw_common(ah); 836 common = ath9k_hw_common(ah);
@@ -855,19 +840,19 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
855 error = ath_regd_init(&common->regulatory, sc->hw->wiphy, 840 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
856 ath9k_reg_notifier); 841 ath9k_reg_notifier);
857 if (error) 842 if (error)
858 goto error_regd; 843 goto deinit;
859 844
860 reg = &common->regulatory; 845 reg = &common->regulatory;
861 846
862 /* Setup TX DMA */ 847 /* Setup TX DMA */
863 error = ath_tx_init(sc, ATH_TXBUF); 848 error = ath_tx_init(sc, ATH_TXBUF);
864 if (error != 0) 849 if (error != 0)
865 goto error_tx; 850 goto deinit;
866 851
867 /* Setup RX DMA */ 852 /* Setup RX DMA */
868 error = ath_rx_init(sc, ATH_RXBUF); 853 error = ath_rx_init(sc, ATH_RXBUF);
869 if (error != 0) 854 if (error != 0)
870 goto error_rx; 855 goto deinit;
871 856
872 ath9k_init_txpower_limits(sc); 857 ath9k_init_txpower_limits(sc);
873 858
@@ -881,19 +866,19 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
881 /* Register with mac80211 */ 866 /* Register with mac80211 */
882 error = ieee80211_register_hw(hw); 867 error = ieee80211_register_hw(hw);
883 if (error) 868 if (error)
884 goto error_register; 869 goto rx_cleanup;
885 870
886 error = ath9k_init_debug(ah); 871 error = ath9k_init_debug(ah);
887 if (error) { 872 if (error) {
888 ath_err(common, "Unable to create debugfs files\n"); 873 ath_err(common, "Unable to create debugfs files\n");
889 goto error_world; 874 goto unregister;
890 } 875 }
891 876
892 /* Handle world regulatory */ 877 /* Handle world regulatory */
893 if (!ath_is_world_regd(reg)) { 878 if (!ath_is_world_regd(reg)) {
894 error = regulatory_hint(hw->wiphy, reg->alpha2); 879 error = regulatory_hint(hw->wiphy, reg->alpha2);
895 if (error) 880 if (error)
896 goto error_world; 881 goto unregister;
897 } 882 }
898 883
899 ath_init_leds(sc); 884 ath_init_leds(sc);
@@ -901,17 +886,12 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
901 886
902 return 0; 887 return 0;
903 888
904error_world: 889unregister:
905 ieee80211_unregister_hw(hw); 890 ieee80211_unregister_hw(hw);
906error_register: 891rx_cleanup:
907 ath_rx_cleanup(sc); 892 ath_rx_cleanup(sc);
908error_rx: 893deinit:
909 ath_tx_cleanup(sc);
910error_tx:
911 /* Nothing */
912error_regd:
913 ath9k_deinit_softc(sc); 894 ath9k_deinit_softc(sc);
914error_init:
915 return error; 895 return error;
916} 896}
917 897
@@ -923,12 +903,6 @@ static void ath9k_deinit_softc(struct ath_softc *sc)
923{ 903{
924 int i = 0; 904 int i = 0;
925 905
926 if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
927 kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
928
929 if (sc->sbands[IEEE80211_BAND_5GHZ].channels)
930 kfree(sc->sbands[IEEE80211_BAND_5GHZ].channels);
931
932 ath9k_deinit_btcoex(sc); 906 ath9k_deinit_btcoex(sc);
933 907
934 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) 908 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
@@ -940,8 +914,11 @@ static void ath9k_deinit_softc(struct ath_softc *sc)
940 sc->dfs_detector->exit(sc->dfs_detector); 914 sc->dfs_detector->exit(sc->dfs_detector);
941 915
942 ath9k_eeprom_release(sc); 916 ath9k_eeprom_release(sc);
943 kfree(sc->sc_ah); 917
944 sc->sc_ah = NULL; 918 if (sc->rfs_chan_spec_scan) {
919 relay_close(sc->rfs_chan_spec_scan);
920 sc->rfs_chan_spec_scan = NULL;
921 }
945} 922}
946 923
947void ath9k_deinit_device(struct ath_softc *sc) 924void ath9k_deinit_device(struct ath_softc *sc)
@@ -957,22 +934,9 @@ void ath9k_deinit_device(struct ath_softc *sc)
957 934
958 ieee80211_unregister_hw(hw); 935 ieee80211_unregister_hw(hw);
959 ath_rx_cleanup(sc); 936 ath_rx_cleanup(sc);
960 ath_tx_cleanup(sc);
961 ath9k_deinit_softc(sc); 937 ath9k_deinit_softc(sc);
962} 938}
963 939
964void ath_descdma_cleanup(struct ath_softc *sc,
965 struct ath_descdma *dd,
966 struct list_head *head)
967{
968 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
969 dd->dd_desc_paddr);
970
971 INIT_LIST_HEAD(head);
972 kfree(dd->dd_bufptr);
973 memset(dd, 0, sizeof(*dd));
974}
975
976/************************/ 940/************************/
977/* Module Hooks */ 941/* Module Hooks */
978/************************/ 942/************************/