Skip to content

Commit a24f891

Browse files
committed
wifi: mt76: add support for allocating a phy without hw
Preparation for supporting a single hw with multiple radios Link: https://patch.msgid.link/[email protected] Signed-off-by: Felix Fietkau <[email protected]>
1 parent 31083e3 commit a24f891

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

drivers/net/wireless/mediatek/mt76/mac80211.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,15 @@ mt76_check_sband(struct mt76_phy *phy, struct mt76_sband *msband,
411411
}
412412

413413
if (found) {
414-
phy->chandef.chan = &sband->channels[0];
414+
cfg80211_chandef_create(&phy->chandef, &sband->channels[0],
415+
NL80211_CHAN_HT20);
415416
phy->chan_state = &msband->chan[0];
416417
return;
417418
}
418419

419420
sband->n_channels = 0;
420-
phy->hw->wiphy->bands[band] = NULL;
421+
if (phy->hw->wiphy->bands[band] == sband)
422+
phy->hw->wiphy->bands[band] = NULL;
421423
}
422424

423425
static int
@@ -429,6 +431,9 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
429431
INIT_LIST_HEAD(&phy->tx_list);
430432
spin_lock_init(&phy->tx_lock);
431433

434+
if ((void *)phy != hw->priv)
435+
return 0;
436+
432437
SET_IEEE80211_DEV(hw, dev->dev);
433438
SET_IEEE80211_PERM_ADDR(hw, phy->macaddr);
434439

@@ -480,6 +485,28 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
480485
return 0;
481486
}
482487

488+
struct mt76_phy *
489+
mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size,
490+
u8 band_idx)
491+
{
492+
struct ieee80211_hw *hw = dev->phy.hw;
493+
unsigned int phy_size;
494+
struct mt76_phy *phy;
495+
496+
phy_size = ALIGN(sizeof(*phy), 8);
497+
phy = devm_kzalloc(dev->dev, size + phy_size, GFP_KERNEL);
498+
if (!phy)
499+
return NULL;
500+
501+
phy->dev = dev;
502+
phy->hw = hw;
503+
phy->priv = (void *)phy + phy_size;
504+
phy->band_idx = band_idx;
505+
506+
return phy;
507+
}
508+
EXPORT_SYMBOL_GPL(mt76_alloc_radio_phy);
509+
483510
struct mt76_phy *
484511
mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
485512
const struct ieee80211_ops *ops, u8 band_idx)
@@ -552,9 +579,11 @@ int mt76_register_phy(struct mt76_phy *phy, bool vht,
552579
mt76_check_sband(phy, &phy->sband_5g, NL80211_BAND_5GHZ);
553580
mt76_check_sband(phy, &phy->sband_6g, NL80211_BAND_6GHZ);
554581

555-
ret = ieee80211_register_hw(phy->hw);
556-
if (ret)
557-
return ret;
582+
if ((void *)phy == phy->hw->priv) {
583+
ret = ieee80211_register_hw(phy->hw);
584+
if (ret)
585+
return ret;
586+
}
558587

559588
set_bit(MT76_STATE_REGISTERED, &phy->state);
560589
phy->dev->phys[phy->band_idx] = phy;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,8 @@ void mt76_unregister_device(struct mt76_dev *dev);
11771177
void mt76_free_device(struct mt76_dev *dev);
11781178
void mt76_unregister_phy(struct mt76_phy *phy);
11791179

1180+
struct mt76_phy *mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size,
1181+
u8 band_idx);
11801182
struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
11811183
const struct ieee80211_ops *ops,
11821184
u8 band_idx);

0 commit comments

Comments
 (0)