1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
5 * Felix Fietkau <nbd@nbd.name>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
15 static const struct pci_device_id mt7615_pci_device_table
[] = {
16 { PCI_DEVICE(0x14c3, 0x7615) },
20 u32
mt7615_reg_map(struct mt7615_dev
*dev
, u32 addr
)
22 u32 base
= addr
& MT_MCU_PCIE_REMAP_2_BASE
;
23 u32 offset
= addr
& MT_MCU_PCIE_REMAP_2_OFFSET
;
25 mt76_wr(dev
, MT_MCU_PCIE_REMAP_2
, base
);
27 return MT_PCIE_REMAP_BASE_2
+ offset
;
31 mt7615_rx_poll_complete(struct mt76_dev
*mdev
, enum mt76_rxq_id q
)
33 struct mt7615_dev
*dev
= container_of(mdev
, struct mt7615_dev
, mt76
);
35 mt7615_irq_enable(dev
, MT_INT_RX_DONE(q
));
38 static irqreturn_t
mt7615_irq_handler(int irq
, void *dev_instance
)
40 struct mt7615_dev
*dev
= dev_instance
;
43 intr
= mt76_rr(dev
, MT_INT_SOURCE_CSR
);
44 mt76_wr(dev
, MT_INT_SOURCE_CSR
, intr
);
46 if (!test_bit(MT76_STATE_INITIALIZED
, &dev
->mt76
.state
))
49 intr
&= dev
->mt76
.mmio
.irqmask
;
51 if (intr
& MT_INT_TX_DONE_ALL
) {
52 mt7615_irq_disable(dev
, MT_INT_TX_DONE_ALL
);
53 napi_schedule(&dev
->mt76
.tx_napi
);
56 if (intr
& MT_INT_RX_DONE(0)) {
57 mt7615_irq_disable(dev
, MT_INT_RX_DONE(0));
58 napi_schedule(&dev
->mt76
.napi
[0]);
61 if (intr
& MT_INT_RX_DONE(1)) {
62 mt7615_irq_disable(dev
, MT_INT_RX_DONE(1));
63 napi_schedule(&dev
->mt76
.napi
[1]);
69 static int mt7615_pci_probe(struct pci_dev
*pdev
,
70 const struct pci_device_id
*id
)
72 static const struct mt76_driver_ops drv_ops
= {
73 /* txwi_size = txd size + txp size */
74 .txwi_size
= MT_TXD_SIZE
+ sizeof(struct mt7615_txp
),
75 .drv_flags
= MT_DRV_TXWI_NO_FREE
,
76 .survey_flags
= SURVEY_INFO_TIME_TX
|
78 SURVEY_INFO_TIME_BSS_RX
,
79 .tx_prepare_skb
= mt7615_tx_prepare_skb
,
80 .tx_complete_skb
= mt7615_tx_complete_skb
,
81 .rx_skb
= mt7615_queue_rx_skb
,
82 .rx_poll_complete
= mt7615_rx_poll_complete
,
83 .sta_ps
= mt7615_sta_ps
,
84 .sta_add
= mt7615_sta_add
,
85 .sta_assoc
= mt7615_sta_assoc
,
86 .sta_remove
= mt7615_sta_remove
,
87 .update_survey
= mt7615_update_channel
,
89 struct mt7615_dev
*dev
;
90 struct mt76_dev
*mdev
;
93 ret
= pcim_enable_device(pdev
);
97 ret
= pcim_iomap_regions(pdev
, BIT(0), pci_name(pdev
));
101 pci_set_master(pdev
);
103 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
107 mdev
= mt76_alloc_device(&pdev
->dev
, sizeof(*dev
), &mt7615_ops
,
112 dev
= container_of(mdev
, struct mt7615_dev
, mt76
);
113 mt76_mmio_init(&dev
->mt76
, pcim_iomap_table(pdev
)[0]);
115 mdev
->rev
= (mt76_rr(dev
, MT_HW_CHIPID
) << 16) |
116 (mt76_rr(dev
, MT_HW_REV
) & 0xff);
117 dev_dbg(mdev
->dev
, "ASIC revision: %04x\n", mdev
->rev
);
119 ret
= devm_request_irq(mdev
->dev
, pdev
->irq
, mt7615_irq_handler
,
120 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
124 ret
= mt7615_register_device(dev
);
130 ieee80211_free_hw(mt76_hw(dev
));
134 static void mt7615_pci_remove(struct pci_dev
*pdev
)
136 struct mt76_dev
*mdev
= pci_get_drvdata(pdev
);
137 struct mt7615_dev
*dev
= container_of(mdev
, struct mt7615_dev
, mt76
);
139 mt7615_unregister_device(dev
);
142 struct pci_driver mt7615_pci_driver
= {
143 .name
= KBUILD_MODNAME
,
144 .id_table
= mt7615_pci_device_table
,
145 .probe
= mt7615_pci_probe
,
146 .remove
= mt7615_pci_remove
,
149 module_pci_driver(mt7615_pci_driver
);
151 MODULE_DEVICE_TABLE(pci
, mt7615_pci_device_table
);
152 MODULE_FIRMWARE(MT7615_FIRMWARE_CR4
);
153 MODULE_FIRMWARE(MT7615_FIRMWARE_N9
);
154 MODULE_FIRMWARE(MT7615_ROM_PATCH
);
155 MODULE_LICENSE("Dual BSD/GPL");