18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: ISC
28c2ecf20Sopenharmony_ci/* Copyright (C) 2020 MediaTek Inc. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "mt7915.h"
58c2ecf20Sopenharmony_ci#include "../dma.h"
68c2ecf20Sopenharmony_ci#include "mac.h"
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistatic int
98c2ecf20Sopenharmony_cimt7915_init_tx_queues(struct mt7915_dev *dev, int n_desc)
108c2ecf20Sopenharmony_ci{
118c2ecf20Sopenharmony_ci	struct mt76_queue *hwq;
128c2ecf20Sopenharmony_ci	int err, i;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	hwq = devm_kzalloc(dev->mt76.dev, sizeof(*hwq), GFP_KERNEL);
158c2ecf20Sopenharmony_ci	if (!hwq)
168c2ecf20Sopenharmony_ci		return -ENOMEM;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	err = mt76_queue_alloc(dev, hwq, MT7915_TXQ_BAND0, n_desc, 0,
198c2ecf20Sopenharmony_ci			       MT_TX_RING_BASE);
208c2ecf20Sopenharmony_ci	if (err < 0)
218c2ecf20Sopenharmony_ci		return err;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	for (i = 0; i < MT_TXQ_MCU; i++)
248c2ecf20Sopenharmony_ci		dev->mt76.q_tx[i] = hwq;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	return 0;
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic int
308c2ecf20Sopenharmony_cimt7915_init_mcu_queue(struct mt7915_dev *dev, int qid, int idx, int n_desc)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	struct mt76_queue *hwq;
338c2ecf20Sopenharmony_ci	int err;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	hwq = devm_kzalloc(dev->mt76.dev, sizeof(*hwq), GFP_KERNEL);
368c2ecf20Sopenharmony_ci	if (!hwq)
378c2ecf20Sopenharmony_ci		return -ENOMEM;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	err = mt76_queue_alloc(dev, hwq, idx, n_desc, 0, MT_TX_RING_BASE);
408c2ecf20Sopenharmony_ci	if (err < 0)
418c2ecf20Sopenharmony_ci		return err;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	dev->mt76.q_tx[qid] = hwq;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	return 0;
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_civoid mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
498c2ecf20Sopenharmony_ci			 struct sk_buff *skb)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
528c2ecf20Sopenharmony_ci	__le32 *rxd = (__le32 *)skb->data;
538c2ecf20Sopenharmony_ci	enum rx_pkt_type type;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	type = FIELD_GET(MT_RXD0_PKT_TYPE, le32_to_cpu(rxd[0]));
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	switch (type) {
588c2ecf20Sopenharmony_ci	case PKT_TYPE_TXRX_NOTIFY:
598c2ecf20Sopenharmony_ci		mt7915_mac_tx_free(dev, skb);
608c2ecf20Sopenharmony_ci		break;
618c2ecf20Sopenharmony_ci	case PKT_TYPE_RX_EVENT:
628c2ecf20Sopenharmony_ci		mt7915_mcu_rx_event(dev, skb);
638c2ecf20Sopenharmony_ci		break;
648c2ecf20Sopenharmony_ci	case PKT_TYPE_NORMAL:
658c2ecf20Sopenharmony_ci		if (!mt7915_mac_fill_rx(dev, skb)) {
668c2ecf20Sopenharmony_ci			mt76_rx(&dev->mt76, q, skb);
678c2ecf20Sopenharmony_ci			return;
688c2ecf20Sopenharmony_ci		}
698c2ecf20Sopenharmony_ci		fallthrough;
708c2ecf20Sopenharmony_ci	default:
718c2ecf20Sopenharmony_ci		dev_kfree_skb(skb);
728c2ecf20Sopenharmony_ci		break;
738c2ecf20Sopenharmony_ci	}
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic void
778c2ecf20Sopenharmony_cimt7915_tx_cleanup(struct mt7915_dev *dev)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	mt76_queue_tx_cleanup(dev, MT_TXQ_MCU, false);
808c2ecf20Sopenharmony_ci	mt76_queue_tx_cleanup(dev, MT_TXQ_MCU_WA, false);
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic int mt7915_poll_tx(struct napi_struct *napi, int budget)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	struct mt7915_dev *dev;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	dev = container_of(napi, struct mt7915_dev, mt76.tx_napi);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	mt7915_tx_cleanup(dev);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	if (napi_complete_done(napi, 0))
928c2ecf20Sopenharmony_ci		mt7915_irq_enable(dev, MT_INT_TX_DONE_MCU);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	return 0;
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_civoid mt7915_dma_prefetch(struct mt7915_dev *dev)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci#define PREFETCH(base, depth)	((base) << 16 | (depth))
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA0_RX_RING0_EXT_CTRL, PREFETCH(0x0, 0x4));
1028c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA0_RX_RING1_EXT_CTRL, PREFETCH(0x40, 0x4));
1038c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA0_RX_RING2_EXT_CTRL, PREFETCH(0x80, 0x0));
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING0_EXT_CTRL, PREFETCH(0x80, 0x4));
1068c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING1_EXT_CTRL, PREFETCH(0xc0, 0x4));
1078c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING2_EXT_CTRL, PREFETCH(0x100, 0x4));
1088c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING3_EXT_CTRL, PREFETCH(0x140, 0x4));
1098c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING4_EXT_CTRL, PREFETCH(0x180, 0x4));
1108c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING5_EXT_CTRL, PREFETCH(0x1c0, 0x4));
1118c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING6_EXT_CTRL, PREFETCH(0x200, 0x4));
1128c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING7_EXT_CTRL, PREFETCH(0x240, 0x4));
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING16_EXT_CTRL, PREFETCH(0x280, 0x4));
1158c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING17_EXT_CTRL, PREFETCH(0x2c0, 0x4));
1168c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING18_EXT_CTRL, PREFETCH(0x300, 0x4));
1178c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING19_EXT_CTRL, PREFETCH(0x340, 0x4));
1188c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING20_EXT_CTRL, PREFETCH(0x380, 0x4));
1198c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_TX_RING21_EXT_CTRL, PREFETCH(0x3c0, 0x0));
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_RX_RING0_EXT_CTRL, PREFETCH(0x3c0, 0x4));
1228c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_RX_RING1_EXT_CTRL, PREFETCH(0x400, 0x4));
1238c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_RX_RING2_EXT_CTRL, PREFETCH(0x440, 0x4));
1248c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_RX_RING3_EXT_CTRL, PREFETCH(0x480, 0x0));
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic u32 __mt7915_reg_addr(struct mt7915_dev *dev, u32 addr)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	static const struct {
1308c2ecf20Sopenharmony_ci		u32 phys;
1318c2ecf20Sopenharmony_ci		u32 mapped;
1328c2ecf20Sopenharmony_ci		u32 size;
1338c2ecf20Sopenharmony_ci	} fixed_map[] = {
1348c2ecf20Sopenharmony_ci		{ 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */
1358c2ecf20Sopenharmony_ci		{ 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */
1368c2ecf20Sopenharmony_ci		{ 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */
1378c2ecf20Sopenharmony_ci		{ 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */
1388c2ecf20Sopenharmony_ci		{ 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */
1398c2ecf20Sopenharmony_ci		{ 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */
1408c2ecf20Sopenharmony_ci		{ 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */
1418c2ecf20Sopenharmony_ci		{ 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */
1428c2ecf20Sopenharmony_ci		{ 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */
1438c2ecf20Sopenharmony_ci		{ 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */
1448c2ecf20Sopenharmony_ci		{ 0x820cc000, 0x0e000, 0x2000 }, /* WF_UMAC_TOP (PP) */
1458c2ecf20Sopenharmony_ci		{ 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */
1468c2ecf20Sopenharmony_ci		{ 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */
1478c2ecf20Sopenharmony_ci		{ 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
1488c2ecf20Sopenharmony_ci		{ 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */
1498c2ecf20Sopenharmony_ci		{ 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */
1508c2ecf20Sopenharmony_ci		{ 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */
1518c2ecf20Sopenharmony_ci		{ 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */
1528c2ecf20Sopenharmony_ci		{ 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
1538c2ecf20Sopenharmony_ci		{ 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */
1548c2ecf20Sopenharmony_ci		{ 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
1558c2ecf20Sopenharmony_ci		{ 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */
1568c2ecf20Sopenharmony_ci		{ 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */
1578c2ecf20Sopenharmony_ci		{ 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
1588c2ecf20Sopenharmony_ci		{ 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */
1598c2ecf20Sopenharmony_ci		{ 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
1608c2ecf20Sopenharmony_ci		{ 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */
1618c2ecf20Sopenharmony_ci		{ 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */
1628c2ecf20Sopenharmony_ci		{ 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */
1638c2ecf20Sopenharmony_ci		{ 0x820f3000, 0xa0c00, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */
1648c2ecf20Sopenharmony_ci		{ 0x820f4000, 0xa1000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */
1658c2ecf20Sopenharmony_ci		{ 0x820f5000, 0xa1400, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */
1668c2ecf20Sopenharmony_ci		{ 0x820f7000, 0xa1e00, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */
1678c2ecf20Sopenharmony_ci		{ 0x820f9000, 0xa3400, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */
1688c2ecf20Sopenharmony_ci		{ 0x820fa000, 0xa4000, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */
1698c2ecf20Sopenharmony_ci		{ 0x820fb000, 0xa4200, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */
1708c2ecf20Sopenharmony_ci		{ 0x820fc000, 0xa4600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_INT) */
1718c2ecf20Sopenharmony_ci		{ 0x820fd000, 0xa4800, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */
1728c2ecf20Sopenharmony_ci	};
1738c2ecf20Sopenharmony_ci	int i;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (addr < 0x100000)
1768c2ecf20Sopenharmony_ci		return addr;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(fixed_map); i++) {
1798c2ecf20Sopenharmony_ci		u32 ofs;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci		if (addr < fixed_map[i].phys)
1828c2ecf20Sopenharmony_ci			continue;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci		ofs = addr - fixed_map[i].phys;
1858c2ecf20Sopenharmony_ci		if (ofs > fixed_map[i].size)
1868c2ecf20Sopenharmony_ci			continue;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci		return fixed_map[i].mapped + ofs;
1898c2ecf20Sopenharmony_ci	}
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	if ((addr >= 0x18000000 && addr < 0x18c00000) ||
1928c2ecf20Sopenharmony_ci	    (addr >= 0x70000000 && addr < 0x78000000) ||
1938c2ecf20Sopenharmony_ci	    (addr >= 0x7c000000 && addr < 0x7c400000))
1948c2ecf20Sopenharmony_ci		return mt7915_reg_map_l1(dev, addr);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	return mt7915_reg_map_l2(dev, addr);
1978c2ecf20Sopenharmony_ci}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic u32 mt7915_rr(struct mt76_dev *mdev, u32 offset)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
2028c2ecf20Sopenharmony_ci	u32 addr = __mt7915_reg_addr(dev, offset);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	return dev->bus_ops->rr(mdev, addr);
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic void mt7915_wr(struct mt76_dev *mdev, u32 offset, u32 val)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
2108c2ecf20Sopenharmony_ci	u32 addr = __mt7915_reg_addr(dev, offset);
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	dev->bus_ops->wr(mdev, addr, val);
2138c2ecf20Sopenharmony_ci}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cistatic u32 mt7915_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
2188c2ecf20Sopenharmony_ci	u32 addr = __mt7915_reg_addr(dev, offset);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	return dev->bus_ops->rmw(mdev, addr, mask, val);
2218c2ecf20Sopenharmony_ci}
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciint mt7915_dma_init(struct mt7915_dev *dev)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	/* Increase buffer size to receive large VHT/HE MPDUs */
2268c2ecf20Sopenharmony_ci	struct mt76_bus_ops *bus_ops;
2278c2ecf20Sopenharmony_ci	int rx_buf_size = MT_RX_BUF_SIZE * 2;
2288c2ecf20Sopenharmony_ci	int ret;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	dev->bus_ops = dev->mt76.bus;
2318c2ecf20Sopenharmony_ci	bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops),
2328c2ecf20Sopenharmony_ci			       GFP_KERNEL);
2338c2ecf20Sopenharmony_ci	if (!bus_ops)
2348c2ecf20Sopenharmony_ci		return -ENOMEM;
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	bus_ops->rr = mt7915_rr;
2378c2ecf20Sopenharmony_ci	bus_ops->wr = mt7915_wr;
2388c2ecf20Sopenharmony_ci	bus_ops->rmw = mt7915_rmw;
2398c2ecf20Sopenharmony_ci	dev->mt76.bus = bus_ops;
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	mt76_dma_attach(&dev->mt76);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	/* configure global setting */
2448c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA1_GLO_CFG,
2458c2ecf20Sopenharmony_ci		 MT_WFDMA1_GLO_CFG_OMIT_TX_INFO |
2468c2ecf20Sopenharmony_ci		 MT_WFDMA1_GLO_CFG_OMIT_RX_INFO);
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/* configure perfetch settings */
2498c2ecf20Sopenharmony_ci	mt7915_dma_prefetch(dev);
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	/* reset dma idx */
2528c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA0_RST_DTX_PTR, ~0);
2538c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_RST_DTX_PTR, ~0);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	/* configure delay interrupt */
2568c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA0_PRI_DLY_INT_CFG0, 0);
2578c2ecf20Sopenharmony_ci	mt76_wr(dev, MT_WFDMA1_PRI_DLY_INT_CFG0, 0);
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/* init tx queue */
2608c2ecf20Sopenharmony_ci	ret = mt7915_init_tx_queues(dev, MT7915_TX_RING_SIZE);
2618c2ecf20Sopenharmony_ci	if (ret)
2628c2ecf20Sopenharmony_ci		return ret;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	/* command to WM */
2658c2ecf20Sopenharmony_ci	ret = mt7915_init_mcu_queue(dev, MT_TXQ_MCU, MT7915_TXQ_MCU_WM,
2668c2ecf20Sopenharmony_ci				    MT7915_TX_MCU_RING_SIZE);
2678c2ecf20Sopenharmony_ci	if (ret)
2688c2ecf20Sopenharmony_ci		return ret;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/* command to WA */
2718c2ecf20Sopenharmony_ci	ret = mt7915_init_mcu_queue(dev, MT_TXQ_MCU_WA, MT7915_TXQ_MCU_WA,
2728c2ecf20Sopenharmony_ci				    MT7915_TX_MCU_RING_SIZE);
2738c2ecf20Sopenharmony_ci	if (ret)
2748c2ecf20Sopenharmony_ci		return ret;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	/* firmware download */
2778c2ecf20Sopenharmony_ci	ret = mt7915_init_mcu_queue(dev, MT_TXQ_FWDL, MT7915_TXQ_FWDL,
2788c2ecf20Sopenharmony_ci				    MT7915_TX_FWDL_RING_SIZE);
2798c2ecf20Sopenharmony_ci	if (ret)
2808c2ecf20Sopenharmony_ci		return ret;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	/* event from WM */
2838c2ecf20Sopenharmony_ci	ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MCU],
2848c2ecf20Sopenharmony_ci			       MT7915_RXQ_MCU_WM, MT7915_RX_MCU_RING_SIZE,
2858c2ecf20Sopenharmony_ci			       rx_buf_size, MT_RX_EVENT_RING_BASE);
2868c2ecf20Sopenharmony_ci	if (ret)
2878c2ecf20Sopenharmony_ci		return ret;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	/* event from WA */
2908c2ecf20Sopenharmony_ci	ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MCU_WA],
2918c2ecf20Sopenharmony_ci			       MT7915_RXQ_MCU_WA, MT7915_RX_MCU_RING_SIZE,
2928c2ecf20Sopenharmony_ci			       rx_buf_size, MT_RX_EVENT_RING_BASE);
2938c2ecf20Sopenharmony_ci	if (ret)
2948c2ecf20Sopenharmony_ci		return ret;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	/* rx data */
2978c2ecf20Sopenharmony_ci	ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN], 0,
2988c2ecf20Sopenharmony_ci			       MT7915_RX_RING_SIZE, rx_buf_size,
2998c2ecf20Sopenharmony_ci			       MT_RX_DATA_RING_BASE);
3008c2ecf20Sopenharmony_ci	if (ret)
3018c2ecf20Sopenharmony_ci		return ret;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	ret = mt76_init_queues(dev);
3048c2ecf20Sopenharmony_ci	if (ret < 0)
3058c2ecf20Sopenharmony_ci		return ret;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	netif_tx_napi_add(&dev->mt76.napi_dev, &dev->mt76.tx_napi,
3088c2ecf20Sopenharmony_ci			  mt7915_poll_tx, NAPI_POLL_WEIGHT);
3098c2ecf20Sopenharmony_ci	napi_enable(&dev->mt76.tx_napi);
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	/* hif wait WFDMA idle */
3128c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA0_BUSY_ENA,
3138c2ecf20Sopenharmony_ci		 MT_WFDMA0_BUSY_ENA_TX_FIFO0 |
3148c2ecf20Sopenharmony_ci		 MT_WFDMA0_BUSY_ENA_TX_FIFO1 |
3158c2ecf20Sopenharmony_ci		 MT_WFDMA0_BUSY_ENA_RX_FIFO);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA1_BUSY_ENA,
3188c2ecf20Sopenharmony_ci		 MT_WFDMA1_BUSY_ENA_TX_FIFO0 |
3198c2ecf20Sopenharmony_ci		 MT_WFDMA1_BUSY_ENA_TX_FIFO1 |
3208c2ecf20Sopenharmony_ci		 MT_WFDMA1_BUSY_ENA_RX_FIFO);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA0_PCIE1_BUSY_ENA,
3238c2ecf20Sopenharmony_ci		 MT_WFDMA0_PCIE1_BUSY_ENA_TX_FIFO0 |
3248c2ecf20Sopenharmony_ci		 MT_WFDMA0_PCIE1_BUSY_ENA_TX_FIFO1 |
3258c2ecf20Sopenharmony_ci		 MT_WFDMA0_PCIE1_BUSY_ENA_RX_FIFO);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA1_PCIE1_BUSY_ENA,
3288c2ecf20Sopenharmony_ci		 MT_WFDMA1_PCIE1_BUSY_ENA_TX_FIFO0 |
3298c2ecf20Sopenharmony_ci		 MT_WFDMA1_PCIE1_BUSY_ENA_TX_FIFO1 |
3308c2ecf20Sopenharmony_ci		 MT_WFDMA1_PCIE1_BUSY_ENA_RX_FIFO);
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	mt76_poll(dev, MT_WFDMA_EXT_CSR_HIF_MISC,
3338c2ecf20Sopenharmony_ci		  MT_WFDMA_EXT_CSR_HIF_MISC_BUSY, 0, 1000);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	/* set WFDMA Tx/Rx */
3368c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA0_GLO_CFG,
3378c2ecf20Sopenharmony_ci		 MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN);
3388c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA1_GLO_CFG,
3398c2ecf20Sopenharmony_ci		 MT_WFDMA1_GLO_CFG_TX_DMA_EN | MT_WFDMA1_GLO_CFG_RX_DMA_EN);
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	/* enable interrupts for TX/RX rings */
3428c2ecf20Sopenharmony_ci	mt7915_irq_enable(dev, MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_MCU |
3438c2ecf20Sopenharmony_ci			  MT_INT_MCU_CMD);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	return 0;
3468c2ecf20Sopenharmony_ci}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_civoid mt7915_dma_cleanup(struct mt7915_dev *dev)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	/* disable */
3518c2ecf20Sopenharmony_ci	mt76_clear(dev, MT_WFDMA0_GLO_CFG,
3528c2ecf20Sopenharmony_ci		   MT_WFDMA0_GLO_CFG_TX_DMA_EN |
3538c2ecf20Sopenharmony_ci		   MT_WFDMA0_GLO_CFG_RX_DMA_EN);
3548c2ecf20Sopenharmony_ci	mt76_clear(dev, MT_WFDMA1_GLO_CFG,
3558c2ecf20Sopenharmony_ci		   MT_WFDMA1_GLO_CFG_TX_DMA_EN |
3568c2ecf20Sopenharmony_ci		   MT_WFDMA1_GLO_CFG_RX_DMA_EN);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	/* reset */
3598c2ecf20Sopenharmony_ci	mt76_clear(dev, MT_WFDMA1_RST,
3608c2ecf20Sopenharmony_ci		   MT_WFDMA1_RST_DMASHDL_ALL_RST |
3618c2ecf20Sopenharmony_ci		   MT_WFDMA1_RST_LOGIC_RST);
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA1_RST,
3648c2ecf20Sopenharmony_ci		 MT_WFDMA1_RST_DMASHDL_ALL_RST |
3658c2ecf20Sopenharmony_ci		 MT_WFDMA1_RST_LOGIC_RST);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	mt76_clear(dev, MT_WFDMA0_RST,
3688c2ecf20Sopenharmony_ci		   MT_WFDMA0_RST_DMASHDL_ALL_RST |
3698c2ecf20Sopenharmony_ci		   MT_WFDMA0_RST_LOGIC_RST);
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	mt76_set(dev, MT_WFDMA0_RST,
3728c2ecf20Sopenharmony_ci		 MT_WFDMA0_RST_DMASHDL_ALL_RST |
3738c2ecf20Sopenharmony_ci		 MT_WFDMA0_RST_LOGIC_RST);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	mt76_dma_cleanup(&dev->mt76);
3768c2ecf20Sopenharmony_ci}
377