Skip to content

Commit 7b8e1ae

Browse files
committed
mt76: mt7915: rework hardware/phy initialization
Clean up and fix error paths in mt7915_register_device Initialize second DBDC tx queue in mt7915_dma_init Signed-off-by: Felix Fietkau <[email protected]>
1 parent 96c7777 commit 7b8e1ae

File tree

3 files changed

+78
-43
lines changed

3 files changed

+78
-43
lines changed

drivers/net/wireless/mediatek/mt76/mt7915/dma.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "../dma.h"
66
#include "mac.h"
77

8-
int mt7915_init_tx_queues(struct mt7915_phy *phy, int idx, int n_desc, int ring_base)
8+
static int
9+
mt7915_init_tx_queues(struct mt7915_phy *phy, int idx, int n_desc, int ring_base)
910
{
1011
int i, err;
1112

@@ -323,7 +324,7 @@ static int mt7915_dma_enable(struct mt7915_dev *dev)
323324
return 0;
324325
}
325326

326-
int mt7915_dma_init(struct mt7915_dev *dev)
327+
int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2)
327328
{
328329
struct mt76_dev *mdev = &dev->mt76;
329330
u32 hif1_ofs = 0;
@@ -346,6 +347,15 @@ int mt7915_dma_init(struct mt7915_dev *dev)
346347
if (ret)
347348
return ret;
348349

350+
if (phy2) {
351+
ret = mt7915_init_tx_queues(phy2,
352+
MT_TXQ_ID(phy2->band_idx),
353+
MT7915_TX_RING_SIZE,
354+
MT_TXQ_RING_BASE(1));
355+
if (ret)
356+
return ret;
357+
}
358+
349359
/* command to WM */
350360
ret = mt76_init_mcu_queue(&dev->mt76, MT_MCUQ_WM,
351361
MT_MCUQ_ID(MT_MCUQ_WM),

drivers/net/wireless/mediatek/mt76/mt7915/init.c

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10511061
int 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

11031135
void 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
}

drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ int mt7915_eeprom_get_target_power(struct mt7915_dev *dev,
440440
struct ieee80211_channel *chan,
441441
u8 chain_idx);
442442
s8 mt7915_eeprom_get_power_delta(struct mt7915_dev *dev, int band);
443-
int mt7915_dma_init(struct mt7915_dev *dev);
443+
int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2);
444444
void mt7915_dma_prefetch(struct mt7915_dev *dev);
445445
void mt7915_dma_cleanup(struct mt7915_dev *dev);
446446
int mt7915_mcu_init(struct mt7915_dev *dev);
@@ -572,7 +572,6 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
572572
struct mt76_tx_info *tx_info);
573573
void mt7915_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e);
574574
void mt7915_tx_token_put(struct mt7915_dev *dev);
575-
int mt7915_init_tx_queues(struct mt7915_phy *phy, int idx, int n_desc, int ring_base);
576575
void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
577576
struct sk_buff *skb);
578577
bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len);

0 commit comments

Comments
 (0)