@@ -484,21 +484,18 @@ static int mt7915_txbf_init(struct mt7915_dev *dev)
484484 return mt7915_mcu_set_txbf (dev , MT_BF_TYPE_UPDATE );
485485}
486486
487- static int mt7915_register_ext_phy (struct mt7915_dev * dev )
487+ static struct mt7915_phy *
488+ mt7915_alloc_ext_phy (struct mt7915_dev * dev )
488489{
489- struct mt7915_phy * phy = mt7915_ext_phy ( dev ) ;
490+ struct mt7915_phy * phy ;
490491 struct mt76_phy * mphy ;
491- int ret ;
492492
493493 if (!dev -> dbdc_support )
494- return 0 ;
495-
496- if (phy )
497- return 0 ;
494+ return NULL ;
498495
499496 mphy = mt76_alloc_phy (& dev -> mt76 , sizeof (* phy ), & mt7915_ops );
500497 if (!mphy )
501- return - ENOMEM ;
498+ return ERR_PTR ( - ENOMEM ) ;
502499
503500 phy = mphy -> priv ;
504501 phy -> dev = dev ;
@@ -507,6 +504,15 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
507504 /* Bind main phy to band0 and ext_phy to band1 for dbdc case */
508505 phy -> band_idx = 1 ;
509506
507+ return phy ;
508+ }
509+
510+ static int
511+ mt7915_register_ext_phy (struct mt7915_dev * dev , struct mt7915_phy * phy )
512+ {
513+ struct mt76_phy * mphy = phy -> mt76 ;
514+ int ret ;
515+
510516 INIT_DELAYED_WORK (& mphy -> mac_work , mt7915_mac_work );
511517
512518 mt7915_eeprom_parse_hw_cap (dev , phy );
@@ -526,29 +532,22 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
526532
527533 /* init wiphy according to mphy and phy */
528534 mt7915_init_wiphy (mphy -> hw );
529- ret = mt7915_init_tx_queues (phy , MT_TXQ_ID (phy -> band_idx ),
530- MT7915_TX_RING_SIZE ,
531- MT_TXQ_RING_BASE (1 ));
532- if (ret )
533- goto error ;
534535
535536 ret = mt76_register_phy (mphy , true, mt76_rates ,
536537 ARRAY_SIZE (mt76_rates ));
537538 if (ret )
538- goto error ;
539+ return ret ;
539540
540541 ret = mt7915_thermal_init (phy );
541542 if (ret )
542- goto error ;
543+ goto unreg ;
543544
544- ret = mt7915_init_debugfs (phy );
545- if (ret )
546- goto error ;
545+ mt7915_init_debugfs (phy );
547546
548547 return 0 ;
549548
550- error :
551- ieee80211_free_hw (mphy -> hw );
549+ unreg :
550+ mt76_unregister_phy (mphy );
552551 return ret ;
553552}
554553
@@ -645,22 +644,21 @@ static bool mt7915_band_config(struct mt7915_dev *dev)
645644 return ret ;
646645}
647646
648- static int mt7915_init_hardware (struct mt7915_dev * dev )
647+ static int
648+ mt7915_init_hardware (struct mt7915_dev * dev , struct mt7915_phy * phy2 )
649649{
650650 int ret , idx ;
651651
652652 mt76_wr (dev , MT_INT_SOURCE_CSR , ~0 );
653653
654654 INIT_WORK (& dev -> init_work , mt7915_init_work );
655655
656- dev -> dbdc_support = mt7915_band_config (dev );
657-
658656 /* If MCU was already running, it is likely in a bad state */
659657 if (mt76_get_field (dev , MT_TOP_MISC , MT_TOP_MISC_FW_STATE ) >
660658 FW_STATE_FW_DOWNLOAD )
661659 mt7915_wfsys_reset (dev );
662660
663- ret = mt7915_dma_init (dev );
661+ ret = mt7915_dma_init (dev , phy2 );
664662 if (ret )
665663 return ret ;
666664
@@ -1048,9 +1046,22 @@ static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)
10481046 ieee80211_free_hw (mphy -> hw );
10491047}
10501048
1049+ static void mt7915_stop_hardware (struct mt7915_dev * dev )
1050+ {
1051+ mt7915_mcu_exit (dev );
1052+ mt7915_tx_token_put (dev );
1053+ mt7915_dma_cleanup (dev );
1054+ tasklet_disable (& dev -> irq_tasklet );
1055+
1056+ if (is_mt7986 (& dev -> mt76 ))
1057+ mt7986_wmac_disable (dev );
1058+ }
1059+
1060+
10511061int mt7915_register_device (struct mt7915_dev * dev )
10521062{
10531063 struct ieee80211_hw * hw = mt76_hw (dev );
1064+ struct mt7915_phy * phy2 ;
10541065 int ret ;
10551066
10561067 dev -> phy .dev = dev ;
@@ -1066,9 +1077,15 @@ int mt7915_register_device(struct mt7915_dev *dev)
10661077 init_waitqueue_head (& dev -> reset_wait );
10671078 INIT_WORK (& dev -> reset_work , mt7915_mac_reset_work );
10681079
1069- ret = mt7915_init_hardware (dev );
1080+ dev -> dbdc_support = mt7915_band_config (dev );
1081+
1082+ phy2 = mt7915_alloc_ext_phy (dev );
1083+ if (IS_ERR (phy2 ))
1084+ return PTR_ERR (phy2 );
1085+
1086+ ret = mt7915_init_hardware (dev , phy2 );
10701087 if (ret )
1071- return ret ;
1088+ goto free_phy2 ;
10721089
10731090 mt7915_init_wiphy (hw );
10741091
@@ -1085,33 +1102,42 @@ int mt7915_register_device(struct mt7915_dev *dev)
10851102 ret = mt76_register_device (& dev -> mt76 , true, mt76_rates ,
10861103 ARRAY_SIZE (mt76_rates ));
10871104 if (ret )
1088- return ret ;
1105+ goto stop_hw ;
10891106
10901107 ret = mt7915_thermal_init (& dev -> phy );
10911108 if (ret )
1092- return ret ;
1109+ goto unreg_dev ;
10931110
10941111 ieee80211_queue_work (mt76_hw (dev ), & dev -> init_work );
10951112
1096- ret = mt7915_register_ext_phy (dev );
1097- if (ret )
1098- return ret ;
1113+ if (phy2 ) {
1114+ ret = mt7915_register_ext_phy (dev , phy2 );
1115+ if (ret )
1116+ goto unreg_thermal ;
1117+ }
10991118
1100- return mt7915_init_debugfs (& dev -> phy );
1119+ mt7915_init_debugfs (& dev -> phy );
1120+
1121+ return 0 ;
1122+
1123+ unreg_thermal :
1124+ mt7915_unregister_thermal (& dev -> phy );
1125+ unreg_dev :
1126+ mt76_unregister_device (& dev -> mt76 );
1127+ stop_hw :
1128+ mt7915_stop_hardware (dev );
1129+ free_phy2 :
1130+ if (phy2 )
1131+ ieee80211_free_hw (phy2 -> mt76 -> hw );
1132+ return ret ;
11011133}
11021134
11031135void mt7915_unregister_device (struct mt7915_dev * dev )
11041136{
11051137 mt7915_unregister_ext_phy (dev );
11061138 mt7915_unregister_thermal (& dev -> phy );
11071139 mt76_unregister_device (& dev -> mt76 );
1108- mt7915_mcu_exit (dev );
1109- mt7915_tx_token_put (dev );
1110- mt7915_dma_cleanup (dev );
1111- tasklet_disable (& dev -> irq_tasklet );
1112-
1113- if (is_mt7986 (& dev -> mt76 ))
1114- mt7986_wmac_disable (dev );
1140+ mt7915_stop_hardware (dev );
11151141
11161142 mt76_free_device (& dev -> mt76 );
11171143}
0 commit comments