// SPDX-License-Identifier: ISC
/* Copyright (C) 2019 MediaTek Inc.
*
* Author: Roy Luo <royluo@google.com>
* Ryder Lee <ryder.lee@mediatek.com>
* Felix Fietkau <nbd@nbd.name>
* Lorenzo Bianconi <lorenzo@kernel.org>
*/
#include <linux/etherdevice.h>
#include <linux/module.h>
#include "mt7615.h"
#include "mcu.h"
static bool mt7615_dev_running(struct mt7615_dev *dev)
{
struct mt7615_phy *phy;
if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
return true;
phy = mt7615_ext_phy(dev);
return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
}
static int mt7615_start(struct ieee80211_hw *hw)
{
struct mt7615_dev *dev = mt7615_hw_dev(hw);
struct mt7615_phy *phy = mt7615_hw_phy(hw);
unsigned long timeout;
bool running;
int ret;
if (!mt7615_wait_for_mcu_init(dev))
return -EIO;
mt7615_mutex_acquire(dev);
running = mt7615_dev_running(dev);
if (!running) {
ret = mt7615_mcu_set_pm(dev, 0, 0);
if (ret)
goto out;
ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 0, true, false);
if (ret)
goto out;
mt7615_mac_enable_nf(dev, 0);
}
if (phy != &dev->phy) {
ret = mt7615_mcu_set_pm(dev, 1, 0);
if (ret)
goto out;
ret = mt76_connac_mcu_set_mac_enable(&dev->mt76, 1, true, false);
if (ret)
goto out;
mt7615_mac_enable_nf(dev, 1);
}
if (mt7615_firmware_offload(dev)) {
ret = mt76_connac_mcu_set_channel_domain(phy->mt76);
if (ret)
goto out;
ret = mt76_connac_mcu_set_rate_txpower(phy->mt76);
if (ret)
goto out;
}
ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
if (ret)
goto out;
set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
timeout = mt7615_get_macwork_timeout(