Commit 33051008 authored by Ming Yen Hsieh's avatar Ming Yen Hsieh Committed by Felix Fietkau
Browse files

wifi: mt76: mt7925: refactor regulatory notifier flow



Rename mt7925_regd_update() to mt7925_mcu_regd_update() to centralize
regd updates with error handling.

Signed-off-by: default avatarMing Yen Hsieh <mingyen.hsieh@mediatek.com>
Link: https://patch.msgid.link/20251031090352.1400079-4-mingyen.hsieh@mediatek.com


Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent e323b841
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -585,7 +585,7 @@ static int _mt7925_pci_resume(struct device *device, bool restore)
	if (!pm->ds_enable)
		mt7925_mcu_set_deep_sleep(dev, false);

	mt7925_regd_update(dev);
	mt7925_mcu_regd_update(dev, mdev->alpha2, dev->country_ie_env);
failed:
	pm->suspended = false;

+34 −15
Original line number Diff line number Diff line
@@ -111,29 +111,49 @@ mt7925_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev)
	}
}

void mt7925_regd_update(struct mt792x_dev *dev)
int mt7925_mcu_regd_update(struct mt792x_dev *dev, u8 *alpha2,
			   enum environment_cap country_ie_env)
{
	struct mt76_dev *mdev = &dev->mt76;
	struct ieee80211_hw *hw = mdev->hw;
	struct ieee80211_hw *hw = mt76_hw(dev);
	struct wiphy *wiphy = hw->wiphy;
	int ret = 0;

	dev->regd_in_progress = true;

	mt792x_mutex_acquire(dev);
	if (!dev->regd_change)
		return;
		goto err;

	ret = mt7925_mcu_set_clc(dev, alpha2, country_ie_env);
	if (ret < 0)
		goto err;

	mt7925_mcu_set_clc(dev, mdev->alpha2, dev->country_ie_env);
	mt7925_regd_channel_update(wiphy, dev);
	mt7925_mcu_set_channel_domain(hw->priv);
	mt7925_set_tx_sar_pwr(hw, NULL);

	ret = mt7925_mcu_set_channel_domain(hw->priv);
	if (ret < 0)
		goto err;

	ret = mt7925_set_tx_sar_pwr(hw, NULL);
	if (ret < 0)
		goto err;

err:
	mt792x_mutex_release(dev);
	dev->regd_change = false;
	dev->regd_in_progress = false;
	wake_up(&dev->wait);

	return ret;
}
EXPORT_SYMBOL_GPL(mt7925_regd_update);
EXPORT_SYMBOL_GPL(mt7925_mcu_regd_update);

void mt7925_regd_notifier(struct wiphy *wiphy, struct regulatory_request *req)
{
	struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
	struct mt792x_dev *dev = mt792x_hw_dev(hw);
	struct mt76_dev *mdev = &dev->mt76;
	struct mt76_connac_pm *pm = &dev->pm;
	struct mt76_dev *mdev = &dev->mt76;

	/* allow world regdom at the first boot only */
	if (!memcmp(req->alpha2, "00", 2) &&
@@ -148,15 +168,14 @@ void mt7925_regd_notifier(struct wiphy *wiphy, struct regulatory_request *req)
	memcpy(mdev->alpha2, req->alpha2, 2);
	mdev->region = req->dfs_region;
	dev->country_ie_env = req->country_ie_env;

	dev->regd_change = true;

	if (pm->suspended)
		/* postpone the mcu update to resume */
		return;

	dev->regd_in_progress = true;
	mt792x_mutex_acquire(dev);
	mt7925_regd_update(dev);
	mt792x_mutex_release(dev);
	dev->regd_in_progress = false;
	wake_up(&dev->wait);
	mt7925_mcu_regd_update(dev, req->alpha2,
			       req->country_ie_env);
	return;
}
+3 −1
Original line number Diff line number Diff line
@@ -6,8 +6,10 @@

#include "mt7925.h"

int mt7925_mcu_regd_update(struct mt792x_dev *dev, u8 *alpha2,
			   enum environment_cap country_ie_env);

void mt7925_regd_be_ctrl(struct mt792x_dev *dev, u8 *alpha2);
void mt7925_regd_update(struct mt792x_dev *dev);
void mt7925_regd_notifier(struct wiphy *wiphy, struct regulatory_request *req);
bool mt7925_regd_clc_supported(struct mt792x_dev *dev);