2019-07-24 16:58:20 +08:00
|
|
|
// SPDX-License-Identifier: ISC
|
2018-09-06 11:18:53 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
|
|
|
#include "mt76x0.h"
|
2018-09-19 13:53:58 +02:00
|
|
|
#include "mcu.h"
|
2018-09-28 13:39:04 +02:00
|
|
|
|
|
|
|
static int mt76x0e_start(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 23:53:09 +02:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-09-28 13:39:05 +02:00
|
|
|
|
2018-10-05 10:28:36 +02:00
|
|
|
mt76x02_mac_start(dev);
|
2018-10-12 12:16:20 +02:00
|
|
|
mt76x0_phy_calibrate(dev, true);
|
2019-03-18 11:21:44 +01:00
|
|
|
ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mt76.mac_work,
|
2019-02-03 14:13:06 +01:00
|
|
|
MT_MAC_WORK_INTERVAL);
|
2018-09-28 13:39:05 +02:00
|
|
|
ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work,
|
|
|
|
MT_CALIBRATE_INTERVAL);
|
2019-10-16 12:09:22 +02:00
|
|
|
set_bit(MT76_STATE_RUNNING, &dev->mphy.state);
|
2018-09-28 13:39:05 +02:00
|
|
|
|
2018-09-28 13:39:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-04 23:53:09 +02:00
|
|
|
static void mt76x0e_stop_hw(struct mt76x02_dev *dev)
|
2018-09-28 13:39:04 +02:00
|
|
|
{
|
2018-09-28 13:39:05 +02:00
|
|
|
cancel_delayed_work_sync(&dev->cal_work);
|
2019-03-18 11:21:44 +01:00
|
|
|
cancel_delayed_work_sync(&dev->mt76.mac_work);
|
2020-02-16 16:08:58 +01:00
|
|
|
clear_bit(MT76_RESTART, &dev->mphy.state);
|
2018-09-28 13:39:05 +02:00
|
|
|
|
|
|
|
if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_BUSY,
|
|
|
|
0, 1000))
|
|
|
|
dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
|
|
|
|
mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_EN);
|
|
|
|
|
|
|
|
mt76x0_mac_stop(dev);
|
|
|
|
|
|
|
|
if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_RX_DMA_BUSY,
|
|
|
|
0, 1000))
|
|
|
|
dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
|
|
|
|
mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_RX_DMA_EN);
|
2018-10-01 10:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mt76x0e_stop(struct ieee80211_hw *hw)
|
|
|
|
{
|
2018-10-04 23:53:09 +02:00
|
|
|
struct mt76x02_dev *dev = hw->priv;
|
2018-09-28 13:39:05 +02:00
|
|
|
|
2019-10-16 12:09:22 +02:00
|
|
|
clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
|
2018-10-01 10:55:54 +02:00
|
|
|
mt76x0e_stop_hw(dev);
|
2018-09-28 13:39:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-20 12:13:32 +02:00
|
|
|
static void
|
|
|
|
mt76x0e_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
|
|
|
u32 queues, bool drop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-28 13:39:04 +02:00
|
|
|
static const struct ieee80211_ops mt76x0e_ops = {
|
2018-10-04 23:53:12 +02:00
|
|
|
.tx = mt76x02_tx,
|
2018-09-28 13:39:04 +02:00
|
|
|
.start = mt76x0e_start,
|
|
|
|
.stop = mt76x0e_stop,
|
|
|
|
.add_interface = mt76x02_add_interface,
|
|
|
|
.remove_interface = mt76x02_remove_interface,
|
2018-10-07 11:57:20 +02:00
|
|
|
.config = mt76x0_config,
|
2018-09-28 13:39:04 +02:00
|
|
|
.configure_filter = mt76x02_configure_filter,
|
2018-10-20 12:40:55 +02:00
|
|
|
.bss_info_changed = mt76x02_bss_info_changed,
|
2018-11-16 10:49:14 +01:00
|
|
|
.sta_state = mt76_sta_state,
|
2020-02-06 18:30:08 +01:00
|
|
|
.sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
|
2019-11-05 11:00:32 +01:00
|
|
|
.set_key = mt76x02_set_key,
|
2018-10-07 11:57:20 +02:00
|
|
|
.conf_tx = mt76x02_conf_tx,
|
2019-08-21 10:00:19 +02:00
|
|
|
.sw_scan_start = mt76_sw_scan,
|
2018-10-20 12:13:28 +02:00
|
|
|
.sw_scan_complete = mt76x02_sw_scan_complete,
|
2018-10-07 11:57:20 +02:00
|
|
|
.ampdu_action = mt76x02_ampdu_action,
|
|
|
|
.sta_rate_tbl_update = mt76x02_sta_rate_tbl_update,
|
|
|
|
.wake_tx_queue = mt76_wake_tx_queue,
|
2018-10-15 11:33:11 +02:00
|
|
|
.get_survey = mt76_get_survey,
|
2018-12-06 14:27:34 +01:00
|
|
|
.get_txpower = mt76_get_txpower,
|
2018-10-20 12:13:32 +02:00
|
|
|
.flush = mt76x0e_flush,
|
2019-03-19 11:37:46 +01:00
|
|
|
.set_tim = mt76_set_tim,
|
2018-10-20 12:13:32 +02:00
|
|
|
.release_buffered_frames = mt76_release_buffered_frames,
|
2018-10-20 12:40:52 +02:00
|
|
|
.set_coverage_class = mt76x02_set_coverage_class,
|
2018-10-20 12:40:54 +02:00
|
|
|
.set_rts_threshold = mt76x02_set_rts_threshold,
|
2019-11-14 17:12:07 +02:00
|
|
|
.get_antenna = mt76_get_antenna,
|
2020-02-16 16:08:58 +01:00
|
|
|
.reconfig_complete = mt76x02_reconfig_complete,
|
2018-09-28 13:39:04 +02:00
|
|
|
};
|
2018-09-28 13:39:01 +02:00
|
|
|
|
2018-10-04 23:53:09 +02:00
|
|
|
static int mt76x0e_register_device(struct mt76x02_dev *dev)
|
2018-09-28 13:39:01 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mt76x0_chip_onoff(dev, true, false);
|
|
|
|
if (!mt76x02_wait_for_mac(&dev->mt76))
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
2018-10-05 10:28:36 +02:00
|
|
|
mt76x02_dma_disable(dev);
|
2018-09-28 13:39:01 +02:00
|
|
|
err = mt76x0e_mcu_init(dev);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2018-10-05 10:28:36 +02:00
|
|
|
err = mt76x02_dma_init(dev);
|
2018-09-28 13:39:01 +02:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mt76x0_init_hardware(dev);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2019-03-19 11:37:36 +01:00
|
|
|
mt76x02e_init_beacon_config(dev);
|
|
|
|
|
2018-09-28 13:39:01 +02:00
|
|
|
if (mt76_chip(&dev->mt76) == 0x7610) {
|
|
|
|
u16 val;
|
|
|
|
|
|
|
|
mt76_clear(dev, MT_COEXCFG0, BIT(0));
|
2018-10-09 10:44:36 +02:00
|
|
|
|
2018-10-07 11:45:24 +02:00
|
|
|
val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0);
|
2018-10-09 10:44:36 +02:00
|
|
|
if (!(val & MT_EE_NIC_CONF_0_PA_IO_CURRENT))
|
|
|
|
mt76_set(dev, MT_XO_CTRL7, 0xc03);
|
2018-09-28 13:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mt76_clear(dev, 0x110, BIT(9));
|
|
|
|
mt76_set(dev, MT_MAX_LEN_CFG, BIT(13));
|
|
|
|
|
2018-10-07 11:57:22 +02:00
|
|
|
err = mt76x0_register_device(dev);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2019-10-16 12:09:22 +02:00
|
|
|
set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
|
2018-10-07 11:57:22 +02:00
|
|
|
|
2018-09-28 13:39:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-19 13:53:58 +02:00
|
|
|
|
2018-09-06 11:18:53 +02:00
|
|
|
static int
|
|
|
|
mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|
|
|
{
|
2018-10-07 11:57:22 +02:00
|
|
|
static const struct mt76_driver_ops drv_ops = {
|
|
|
|
.txwi_size = sizeof(struct mt76x02_txwi),
|
2019-09-04 17:45:02 +02:00
|
|
|
.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
|
|
|
|
MT_DRV_SW_RX_AIRTIME,
|
2019-09-06 10:19:19 +02:00
|
|
|
.survey_flags = SURVEY_INFO_TIME_TX,
|
2018-10-15 11:33:11 +02:00
|
|
|
.update_survey = mt76x02_update_channel,
|
2018-10-07 11:57:22 +02:00
|
|
|
.tx_prepare_skb = mt76x02_tx_prepare_skb,
|
|
|
|
.tx_complete_skb = mt76x02_tx_complete_skb,
|
|
|
|
.rx_skb = mt76x02_queue_rx_skb,
|
|
|
|
.rx_poll_complete = mt76x02_rx_poll_complete,
|
2018-10-20 12:13:30 +02:00
|
|
|
.sta_ps = mt76x02_sta_ps,
|
2018-11-16 10:49:14 +01:00
|
|
|
.sta_add = mt76x02_sta_add,
|
|
|
|
.sta_remove = mt76x02_sta_remove,
|
2018-10-07 11:57:22 +02:00
|
|
|
};
|
2018-10-04 23:53:09 +02:00
|
|
|
struct mt76x02_dev *dev;
|
2019-01-31 17:55:56 +01:00
|
|
|
struct mt76_dev *mdev;
|
2018-10-04 23:53:09 +02:00
|
|
|
int ret;
|
2018-09-06 11:18:53 +02:00
|
|
|
|
|
|
|
ret = pcim_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-01-31 17:55:56 +01:00
|
|
|
mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt76x0e_ops,
|
|
|
|
&drv_ops);
|
|
|
|
if (!mdev)
|
2018-09-06 11:18:53 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-01-31 17:55:56 +01:00
|
|
|
dev = container_of(mdev, struct mt76x02_dev, mt76);
|
|
|
|
mutex_init(&dev->phy_mutex);
|
2018-09-06 11:18:53 +02:00
|
|
|
|
2019-01-31 17:55:56 +01:00
|
|
|
mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]);
|
2018-09-06 11:18:53 +02:00
|
|
|
|
2019-01-31 17:55:56 +01:00
|
|
|
mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
|
|
|
|
dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);
|
|
|
|
|
2020-08-07 21:55:52 +02:00
|
|
|
mt76_wr(dev, MT_INT_MASK_CSR, 0);
|
|
|
|
|
2019-01-31 17:55:56 +01:00
|
|
|
ret = devm_request_irq(mdev->dev, pdev->irq, mt76x02_irq_handler,
|
2018-10-07 11:57:22 +02:00
|
|
|
IRQF_SHARED, KBUILD_MODNAME, dev);
|
|
|
|
if (ret)
|
|
|
|
goto error;
|
|
|
|
|
2018-09-28 13:39:01 +02:00
|
|
|
ret = mt76x0e_register_device(dev);
|
2018-09-19 13:53:58 +02:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2020-10-13 10:33:49 +02:00
|
|
|
mt76_free_device(&dev->mt76);
|
|
|
|
|
2018-09-06 11:18:53 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-04 23:53:09 +02:00
|
|
|
static void mt76x0e_cleanup(struct mt76x02_dev *dev)
|
2018-10-01 10:55:54 +02:00
|
|
|
{
|
2019-10-16 12:09:22 +02:00
|
|
|
clear_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
|
2019-04-30 15:12:01 +02:00
|
|
|
tasklet_disable(&dev->mt76.pre_tbtt_tasklet);
|
2018-10-01 10:55:54 +02:00
|
|
|
mt76x0_chip_onoff(dev, false, false);
|
|
|
|
mt76x0e_stop_hw(dev);
|
2020-07-24 16:11:52 +02:00
|
|
|
mt76_dma_cleanup(&dev->mt76);
|
2018-10-07 11:45:18 +02:00
|
|
|
mt76x02_mcu_cleanup(dev);
|
2018-10-01 10:55:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 11:18:53 +02:00
|
|
|
static void
|
|
|
|
mt76x0e_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct mt76_dev *mdev = pci_get_drvdata(pdev);
|
2018-10-04 23:53:09 +02:00
|
|
|
struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
|
2018-09-06 11:18:53 +02:00
|
|
|
|
|
|
|
mt76_unregister_device(mdev);
|
2018-10-01 10:55:54 +02:00
|
|
|
mt76x0e_cleanup(dev);
|
2019-03-27 12:41:03 +01:00
|
|
|
mt76_free_device(mdev);
|
2018-09-06 11:18:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pci_device_id mt76x0e_device_table[] = {
|
2020-03-25 06:55:23 +01:00
|
|
|
{ PCI_DEVICE(0x14c3, 0x7610) },
|
2018-09-06 11:18:53 +02:00
|
|
|
{ PCI_DEVICE(0x14c3, 0x7630) },
|
2018-09-19 13:42:44 +02:00
|
|
|
{ PCI_DEVICE(0x14c3, 0x7650) },
|
2018-09-06 11:18:53 +02:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, mt76x0e_device_table);
|
2018-10-19 00:57:32 +02:00
|
|
|
MODULE_FIRMWARE(MT7610E_FIRMWARE);
|
|
|
|
MODULE_FIRMWARE(MT7650E_FIRMWARE);
|
2018-09-06 11:18:53 +02:00
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
|
|
|
|
static struct pci_driver mt76x0e_driver = {
|
|
|
|
.name = KBUILD_MODNAME,
|
|
|
|
.id_table = mt76x0e_device_table,
|
|
|
|
.probe = mt76x0e_probe,
|
|
|
|
.remove = mt76x0e_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_pci_driver(mt76x0e_driver);
|