mirror of
https://github.com/outbackdingo/mt76.git
synced 2026-10-24 13:26:48 +00:00
Fixes the following reported crash: [ 2.361127] BUG: spinlock bad magic on CPU#0, modprobe/456 [ 2.361583] lock: 0xffffa1287525b3b8, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0 [ 2.362250] CPU: 0 PID: 456 Comm: modprobe Not tainted 4.14.177 #5 [ 2.362751] Hardware name: HP Meep/Meep, BIOS Google_Meep.11297.75.0 06/17/2019 [ 2.363343] Call Trace: [ 2.363552] dump_stack+0x97/0xdb [ 2.363826] ? spin_bug+0xa6/0xb3 [ 2.364096] do_raw_spin_lock+0x6a/0x9a [ 2.364417] mt76_dma_rx_fill+0x44/0x1de [mt76] [ 2.364787] ? mt76_dma_kick_queue+0x18/0x18 [mt76] [ 2.365184] mt76_dma_init+0x53/0x85 [mt76] [ 2.365532] mt7615_dma_init+0x3d7/0x546 [mt7615e] [ 2.365928] mt7615_register_device+0xe6/0x1a0 [mt7615e] [ 2.366364] mt7615_mmio_probe+0x14b/0x171 [mt7615e] [ 2.366771] mt7615_pci_probe+0x118/0x13b [mt7615e] [ 2.367169] pci_device_probe+0xaf/0x13d [ 2.367491] driver_probe_device+0x284/0x2ca [ 2.367840] __driver_attach+0x7a/0x9e [ 2.368146] ? driver_attach+0x1f/0x1f [ 2.368451] bus_for_each_dev+0xa0/0xdb [ 2.368765] bus_add_driver+0x132/0x204 [ 2.369078] driver_register+0x8e/0xcd [ 2.369384] do_one_initcall+0x160/0x257 [ 2.369706] ? 0xffffffffc0240000 [ 2.369980] do_init_module+0x60/0x1bb [ 2.370286] load_module+0x18c2/0x1a2b [ 2.370596] ? kernel_read_file+0x141/0x1b9 [ 2.370937] ? kernel_read_file_from_fd+0x46/0x71 [ 2.371320] SyS_finit_module+0xcc/0xf0 [ 2.371636] do_syscall_64+0x6b/0xf7 [ 2.371930] entry_SYSCALL_64_after_hwframe+0x3d/0xa2 [ 2.372344] RIP: 0033:0x7da218ae4199 [ 2.372637] RSP: 002b:00007fffd0608398 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 2.373252] RAX: ffffffffffffffda RBX: 00005a705449df90 RCX: 00007da218ae4199 [ 2.373833] RDX: 0000000000000000 RSI: 00005a7052e73bd8 RDI: 0000000000000006 [ 2.374411] RBP: 00007fffd06083e0 R08: 0000000000000000 R09: 00005a705449d540 [ 2.374989] R10: 0000000000000006 R11: 0000000000000246 R12: 0000000000000000 [ 2.375569] R13: 00005a705449def0 R14: 00005a7052e73bd8 R15: 0000000000000000 Reported-by: Sean Wang <[email protected]> Fixes: d3377b78cec6 ("mt76: add HE phy modes and hardware queue") Signed-off-by: Felix Fietkau <[email protected]>
195 lines
4.4 KiB
C
195 lines
4.4 KiB
C
// SPDX-License-Identifier: ISC
|
|
/* Copyright (C) 2019 MediaTek Inc.
|
|
*
|
|
* Author: Ryder Lee <[email protected]>
|
|
* Felix Fietkau <[email protected]>
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include "mt7615.h"
|
|
|
|
static const struct pci_device_id mt7615_pci_device_table[] = {
|
|
{ PCI_DEVICE(0x14c3, 0x7615) },
|
|
{ PCI_DEVICE(0x14c3, 0x7663) },
|
|
{ PCI_DEVICE(0x14c3, 0x7611) },
|
|
{ },
|
|
};
|
|
|
|
static int mt7615_pci_probe(struct pci_dev *pdev,
|
|
const struct pci_device_id *id)
|
|
{
|
|
const u32 *map;
|
|
int ret;
|
|
|
|
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_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
|
|
if (ret)
|
|
goto error;
|
|
|
|
mt76_pci_disable_aspm(pdev);
|
|
|
|
map = id->device == 0x7663 ? mt7663e_reg_map : mt7615e_reg_map;
|
|
ret = mt7615_mmio_probe(&pdev->dev, pcim_iomap_table(pdev)[0],
|
|
pdev->irq, map);
|
|
if (ret)
|
|
goto error;
|
|
|
|
return 0;
|
|
error:
|
|
pci_free_irq_vectors(pdev);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void mt7615_pci_remove(struct pci_dev *pdev)
|
|
{
|
|
struct mt76_dev *mdev = pci_get_drvdata(pdev);
|
|
struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
|
|
|
|
mt7615_unregister_device(dev);
|
|
devm_free_irq(&pdev->dev, pdev->irq, dev);
|
|
pci_free_irq_vectors(pdev);
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static int mt7615_pci_suspend(struct pci_dev *pdev, pm_message_t state)
|
|
{
|
|
struct mt76_dev *mdev = pci_get_drvdata(pdev);
|
|
struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
|
|
bool hif_suspend;
|
|
int i, err;
|
|
|
|
hif_suspend = !test_bit(MT76_STATE_SUSPEND, &dev->mphy.state) &&
|
|
mt7615_firmware_offload(dev);
|
|
if (hif_suspend) {
|
|
err = mt7615_mcu_set_hif_suspend(dev, true);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
napi_disable(&mdev->tx_napi);
|
|
tasklet_kill(&mdev->tx_tasklet);
|
|
|
|
mt76_for_each_q_rx(mdev, i) {
|
|
napi_disable(&mdev->napi[i]);
|
|
}
|
|
tasklet_kill(&dev->irq_tasklet);
|
|
|
|
mt7615_dma_reset(dev);
|
|
|
|
err = mt7615_wait_pdma_busy(dev);
|
|
if (err)
|
|
goto restore;
|
|
|
|
if (is_mt7663(mdev)) {
|
|
mt76_set(dev, MT_PDMA_SLP_PROT, MT_PDMA_AXI_SLPPROT_ENABLE);
|
|
if (!mt76_poll_msec(dev, MT_PDMA_SLP_PROT,
|
|
MT_PDMA_AXI_SLPPROT_RDY,
|
|
MT_PDMA_AXI_SLPPROT_RDY, 1000)) {
|
|
dev_err(mdev->dev, "PDMA sleep protection failed\n");
|
|
err = -EIO;
|
|
goto restore;
|
|
}
|
|
}
|
|
|
|
pci_enable_wake(pdev, pci_choose_state(pdev, state), true);
|
|
pci_save_state(pdev);
|
|
err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
|
|
if (err)
|
|
goto restore;
|
|
|
|
err = mt7615_firmware_own(dev);
|
|
if (err)
|
|
goto restore;
|
|
|
|
return 0;
|
|
|
|
restore:
|
|
mt76_for_each_q_rx(mdev, i) {
|
|
napi_enable(&mdev->napi[i]);
|
|
}
|
|
napi_enable(&mdev->tx_napi);
|
|
if (hif_suspend)
|
|
mt7615_mcu_set_hif_suspend(dev, false);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int mt7615_pci_resume(struct pci_dev *pdev)
|
|
{
|
|
struct mt76_dev *mdev = pci_get_drvdata(pdev);
|
|
struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
|
|
bool pdma_reset;
|
|
int i, err;
|
|
|
|
err = mt7615_driver_own(dev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = pci_set_power_state(pdev, PCI_D0);
|
|
if (err)
|
|
return err;
|
|
|
|
pci_restore_state(pdev);
|
|
|
|
if (is_mt7663(&dev->mt76)) {
|
|
mt76_clear(dev, MT_PDMA_SLP_PROT, MT_PDMA_AXI_SLPPROT_ENABLE);
|
|
mt76_wr(dev, MT_PCIE_IRQ_ENABLE, 1);
|
|
}
|
|
|
|
pdma_reset = !mt76_rr(dev, MT_WPDMA_TX_RING0_CTRL0) &&
|
|
!mt76_rr(dev, MT_WPDMA_TX_RING0_CTRL1);
|
|
if (pdma_reset)
|
|
dev_err(mdev->dev, "PDMA engine must be reinitialized\n");
|
|
|
|
mt76_for_each_q_rx(mdev, i) {
|
|
napi_enable(&mdev->napi[i]);
|
|
napi_schedule(&mdev->napi[i]);
|
|
}
|
|
napi_enable(&mdev->tx_napi);
|
|
napi_schedule(&mdev->tx_napi);
|
|
|
|
if (!test_bit(MT76_STATE_SUSPEND, &dev->mphy.state) &&
|
|
mt7615_firmware_offload(dev))
|
|
err = mt7615_mcu_set_hif_suspend(dev, false);
|
|
|
|
return err;
|
|
}
|
|
#endif /* CONFIG_PM */
|
|
|
|
struct pci_driver mt7615_pci_driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.id_table = mt7615_pci_device_table,
|
|
.probe = mt7615_pci_probe,
|
|
.remove = mt7615_pci_remove,
|
|
#ifdef CONFIG_PM
|
|
.suspend = mt7615_pci_suspend,
|
|
.resume = mt7615_pci_resume,
|
|
#endif /* CONFIG_PM */
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, mt7615_pci_device_table);
|
|
MODULE_FIRMWARE(MT7615_FIRMWARE_CR4);
|
|
MODULE_FIRMWARE(MT7615_FIRMWARE_N9);
|
|
MODULE_FIRMWARE(MT7615_ROM_PATCH);
|
|
MODULE_FIRMWARE(MT7663_OFFLOAD_FIRMWARE_N9);
|
|
MODULE_FIRMWARE(MT7663_OFFLOAD_ROM_PATCH);
|
|
MODULE_FIRMWARE(MT7663_FIRMWARE_N9);
|
|
MODULE_FIRMWARE(MT7663_ROM_PATCH);
|