16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /* Copyright (C) 2020 MediaTek Inc. */
36c92544dSBjoern A. Zeeb
46c92544dSBjoern A. Zeeb #include <linux/kernel.h>
56c92544dSBjoern A. Zeeb #include <linux/module.h>
66c92544dSBjoern A. Zeeb #include <linux/platform_device.h>
7*cbb3ec25SBjoern A. Zeeb #include <linux/rtnetlink.h>
86c92544dSBjoern A. Zeeb #include <linux/pci.h>
96c92544dSBjoern A. Zeeb
106c92544dSBjoern A. Zeeb #include "mt7915.h"
116c92544dSBjoern A. Zeeb #include "mac.h"
12*cbb3ec25SBjoern A. Zeeb #include "mcu.h"
136c92544dSBjoern A. Zeeb #include "../trace.h"
14*cbb3ec25SBjoern A. Zeeb #include "../dma.h"
15*cbb3ec25SBjoern A. Zeeb
16*cbb3ec25SBjoern A. Zeeb static bool wed_enable;
17*cbb3ec25SBjoern A. Zeeb module_param(wed_enable, bool, 0644);
18*cbb3ec25SBjoern A. Zeeb MODULE_PARM_DESC(wed_enable, "Enable Wireless Ethernet Dispatch support");
196c92544dSBjoern A. Zeeb
206c92544dSBjoern A. Zeeb static const u32 mt7915_reg[] = {
216c92544dSBjoern A. Zeeb [INT_SOURCE_CSR] = 0xd7010,
226c92544dSBjoern A. Zeeb [INT_MASK_CSR] = 0xd7014,
236c92544dSBjoern A. Zeeb [INT1_SOURCE_CSR] = 0xd7088,
246c92544dSBjoern A. Zeeb [INT1_MASK_CSR] = 0xd708c,
256c92544dSBjoern A. Zeeb [INT_MCU_CMD_SOURCE] = 0xd51f0,
266c92544dSBjoern A. Zeeb [INT_MCU_CMD_EVENT] = 0x3108,
276c92544dSBjoern A. Zeeb [WFDMA0_ADDR] = 0xd4000,
286c92544dSBjoern A. Zeeb [WFDMA0_PCIE1_ADDR] = 0xd8000,
296c92544dSBjoern A. Zeeb [WFDMA_EXT_CSR_ADDR] = 0xd7000,
306c92544dSBjoern A. Zeeb [CBTOP1_PHY_END] = 0x77ffffff,
316c92544dSBjoern A. Zeeb [INFRA_MCU_ADDR_END] = 0x7c3fffff,
32*cbb3ec25SBjoern A. Zeeb [FW_ASSERT_STAT_ADDR] = 0x219848,
33*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_TYPE_ADDR] = 0x21987c,
34*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_COUNT_ADDR] = 0x219848,
35*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_COUNT_ADDR] = 0x216f94,
36*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_IDX_ADDR] = 0x216ef8,
37*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_LISR_ADDR] = 0x2170ac,
38*cbb3ec25SBjoern A. Zeeb [FW_TASK_ID_ADDR] = 0x216f90,
39*cbb3ec25SBjoern A. Zeeb [FW_TASK_IDX_ADDR] = 0x216f9c,
40*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID1_ADDR] = 0x219680,
41*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID2_ADDR] = 0x219760,
42*cbb3ec25SBjoern A. Zeeb [FW_TASK_START_ADDR] = 0x219558,
43*cbb3ec25SBjoern A. Zeeb [FW_TASK_END_ADDR] = 0x219554,
44*cbb3ec25SBjoern A. Zeeb [FW_TASK_SIZE_ADDR] = 0x219560,
45*cbb3ec25SBjoern A. Zeeb [FW_LAST_MSG_ID_ADDR] = 0x216f70,
46*cbb3ec25SBjoern A. Zeeb [FW_EINT_INFO_ADDR] = 0x219818,
47*cbb3ec25SBjoern A. Zeeb [FW_SCHED_INFO_ADDR] = 0x219828,
486c92544dSBjoern A. Zeeb [SWDEF_BASE_ADDR] = 0x41f200,
49*cbb3ec25SBjoern A. Zeeb [TXQ_WED_RING_BASE] = 0xd7300,
50*cbb3ec25SBjoern A. Zeeb [RXQ_WED_RING_BASE] = 0xd7410,
51*cbb3ec25SBjoern A. Zeeb [RXQ_WED_DATA_RING_BASE] = 0xd4500,
526c92544dSBjoern A. Zeeb };
536c92544dSBjoern A. Zeeb
546c92544dSBjoern A. Zeeb static const u32 mt7916_reg[] = {
556c92544dSBjoern A. Zeeb [INT_SOURCE_CSR] = 0xd4200,
566c92544dSBjoern A. Zeeb [INT_MASK_CSR] = 0xd4204,
576c92544dSBjoern A. Zeeb [INT1_SOURCE_CSR] = 0xd8200,
586c92544dSBjoern A. Zeeb [INT1_MASK_CSR] = 0xd8204,
596c92544dSBjoern A. Zeeb [INT_MCU_CMD_SOURCE] = 0xd41f0,
606c92544dSBjoern A. Zeeb [INT_MCU_CMD_EVENT] = 0x2108,
616c92544dSBjoern A. Zeeb [WFDMA0_ADDR] = 0xd4000,
626c92544dSBjoern A. Zeeb [WFDMA0_PCIE1_ADDR] = 0xd8000,
636c92544dSBjoern A. Zeeb [WFDMA_EXT_CSR_ADDR] = 0xd7000,
646c92544dSBjoern A. Zeeb [CBTOP1_PHY_END] = 0x7fffffff,
656c92544dSBjoern A. Zeeb [INFRA_MCU_ADDR_END] = 0x7c085fff,
66*cbb3ec25SBjoern A. Zeeb [FW_ASSERT_STAT_ADDR] = 0x02204c14,
67*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_TYPE_ADDR] = 0x022051a4,
68*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_COUNT_ADDR] = 0x022050bc,
69*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_COUNT_ADDR] = 0x022001ac,
70*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_IDX_ADDR] = 0x02204f84,
71*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_LISR_ADDR] = 0x022050d0,
72*cbb3ec25SBjoern A. Zeeb [FW_TASK_ID_ADDR] = 0x0220406c,
73*cbb3ec25SBjoern A. Zeeb [FW_TASK_IDX_ADDR] = 0x0220500c,
74*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID1_ADDR] = 0x022028c8,
75*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID2_ADDR] = 0x02202a38,
76*cbb3ec25SBjoern A. Zeeb [FW_TASK_START_ADDR] = 0x0220286c,
77*cbb3ec25SBjoern A. Zeeb [FW_TASK_END_ADDR] = 0x02202870,
78*cbb3ec25SBjoern A. Zeeb [FW_TASK_SIZE_ADDR] = 0x02202878,
79*cbb3ec25SBjoern A. Zeeb [FW_LAST_MSG_ID_ADDR] = 0x02204fe8,
80*cbb3ec25SBjoern A. Zeeb [FW_EINT_INFO_ADDR] = 0x0220525c,
81*cbb3ec25SBjoern A. Zeeb [FW_SCHED_INFO_ADDR] = 0x0220516c,
826c92544dSBjoern A. Zeeb [SWDEF_BASE_ADDR] = 0x411400,
83*cbb3ec25SBjoern A. Zeeb [TXQ_WED_RING_BASE] = 0xd7300,
84*cbb3ec25SBjoern A. Zeeb [RXQ_WED_RING_BASE] = 0xd7410,
85*cbb3ec25SBjoern A. Zeeb [RXQ_WED_DATA_RING_BASE] = 0xd4540,
866c92544dSBjoern A. Zeeb };
876c92544dSBjoern A. Zeeb
886c92544dSBjoern A. Zeeb static const u32 mt7986_reg[] = {
896c92544dSBjoern A. Zeeb [INT_SOURCE_CSR] = 0x24200,
906c92544dSBjoern A. Zeeb [INT_MASK_CSR] = 0x24204,
916c92544dSBjoern A. Zeeb [INT1_SOURCE_CSR] = 0x28200,
926c92544dSBjoern A. Zeeb [INT1_MASK_CSR] = 0x28204,
936c92544dSBjoern A. Zeeb [INT_MCU_CMD_SOURCE] = 0x241f0,
946c92544dSBjoern A. Zeeb [INT_MCU_CMD_EVENT] = 0x54000108,
956c92544dSBjoern A. Zeeb [WFDMA0_ADDR] = 0x24000,
966c92544dSBjoern A. Zeeb [WFDMA0_PCIE1_ADDR] = 0x28000,
976c92544dSBjoern A. Zeeb [WFDMA_EXT_CSR_ADDR] = 0x27000,
986c92544dSBjoern A. Zeeb [CBTOP1_PHY_END] = 0x7fffffff,
996c92544dSBjoern A. Zeeb [INFRA_MCU_ADDR_END] = 0x7c085fff,
100*cbb3ec25SBjoern A. Zeeb [FW_ASSERT_STAT_ADDR] = 0x02204b54,
101*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_TYPE_ADDR] = 0x022050dc,
102*cbb3ec25SBjoern A. Zeeb [FW_EXCEPT_COUNT_ADDR] = 0x02204ffc,
103*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_COUNT_ADDR] = 0x022001ac,
104*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_IDX_ADDR] = 0x02204ec4,
105*cbb3ec25SBjoern A. Zeeb [FW_CIRQ_LISR_ADDR] = 0x02205010,
106*cbb3ec25SBjoern A. Zeeb [FW_TASK_ID_ADDR] = 0x02204fac,
107*cbb3ec25SBjoern A. Zeeb [FW_TASK_IDX_ADDR] = 0x02204f4c,
108*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID1_ADDR] = 0x02202814,
109*cbb3ec25SBjoern A. Zeeb [FW_TASK_QID2_ADDR] = 0x02202984,
110*cbb3ec25SBjoern A. Zeeb [FW_TASK_START_ADDR] = 0x022027b8,
111*cbb3ec25SBjoern A. Zeeb [FW_TASK_END_ADDR] = 0x022027bc,
112*cbb3ec25SBjoern A. Zeeb [FW_TASK_SIZE_ADDR] = 0x022027c4,
113*cbb3ec25SBjoern A. Zeeb [FW_LAST_MSG_ID_ADDR] = 0x02204f28,
114*cbb3ec25SBjoern A. Zeeb [FW_EINT_INFO_ADDR] = 0x02205194,
115*cbb3ec25SBjoern A. Zeeb [FW_SCHED_INFO_ADDR] = 0x022051a4,
1166c92544dSBjoern A. Zeeb [SWDEF_BASE_ADDR] = 0x411400,
117*cbb3ec25SBjoern A. Zeeb [TXQ_WED_RING_BASE] = 0x24420,
118*cbb3ec25SBjoern A. Zeeb [RXQ_WED_RING_BASE] = 0x24520,
119*cbb3ec25SBjoern A. Zeeb [RXQ_WED_DATA_RING_BASE] = 0x24540,
1206c92544dSBjoern A. Zeeb };
1216c92544dSBjoern A. Zeeb
1226c92544dSBjoern A. Zeeb static const u32 mt7915_offs[] = {
1236c92544dSBjoern A. Zeeb [TMAC_CDTR] = 0x090,
1246c92544dSBjoern A. Zeeb [TMAC_ODTR] = 0x094,
1256c92544dSBjoern A. Zeeb [TMAC_ATCR] = 0x098,
1266c92544dSBjoern A. Zeeb [TMAC_TRCR0] = 0x09c,
1276c92544dSBjoern A. Zeeb [TMAC_ICR0] = 0x0a4,
1286c92544dSBjoern A. Zeeb [TMAC_ICR1] = 0x0b4,
1296c92544dSBjoern A. Zeeb [TMAC_CTCR0] = 0x0f4,
1306c92544dSBjoern A. Zeeb [TMAC_TFCR0] = 0x1e0,
1316c92544dSBjoern A. Zeeb [MDP_BNRCFR0] = 0x070,
1326c92544dSBjoern A. Zeeb [MDP_BNRCFR1] = 0x074,
1336c92544dSBjoern A. Zeeb [ARB_DRNGR0] = 0x194,
1346c92544dSBjoern A. Zeeb [ARB_SCR] = 0x080,
1356c92544dSBjoern A. Zeeb [RMAC_MIB_AIRTIME14] = 0x3b8,
1366c92544dSBjoern A. Zeeb [AGG_AWSCR0] = 0x05c,
1376c92544dSBjoern A. Zeeb [AGG_PCR0] = 0x06c,
1386c92544dSBjoern A. Zeeb [AGG_ACR0] = 0x084,
1396c92544dSBjoern A. Zeeb [AGG_ACR4] = 0x08c,
1406c92544dSBjoern A. Zeeb [AGG_MRCR] = 0x098,
1416c92544dSBjoern A. Zeeb [AGG_ATCR1] = 0x0f0,
1426c92544dSBjoern A. Zeeb [AGG_ATCR3] = 0x0f4,
1436c92544dSBjoern A. Zeeb [LPON_UTTR0] = 0x080,
1446c92544dSBjoern A. Zeeb [LPON_UTTR1] = 0x084,
1456c92544dSBjoern A. Zeeb [LPON_FRCR] = 0x314,
1466c92544dSBjoern A. Zeeb [MIB_SDR3] = 0x014,
1476c92544dSBjoern A. Zeeb [MIB_SDR4] = 0x018,
1486c92544dSBjoern A. Zeeb [MIB_SDR5] = 0x01c,
1496c92544dSBjoern A. Zeeb [MIB_SDR7] = 0x024,
1506c92544dSBjoern A. Zeeb [MIB_SDR8] = 0x028,
1516c92544dSBjoern A. Zeeb [MIB_SDR9] = 0x02c,
1526c92544dSBjoern A. Zeeb [MIB_SDR10] = 0x030,
1536c92544dSBjoern A. Zeeb [MIB_SDR11] = 0x034,
1546c92544dSBjoern A. Zeeb [MIB_SDR12] = 0x038,
1556c92544dSBjoern A. Zeeb [MIB_SDR13] = 0x03c,
1566c92544dSBjoern A. Zeeb [MIB_SDR14] = 0x040,
1576c92544dSBjoern A. Zeeb [MIB_SDR15] = 0x044,
1586c92544dSBjoern A. Zeeb [MIB_SDR16] = 0x048,
1596c92544dSBjoern A. Zeeb [MIB_SDR17] = 0x04c,
1606c92544dSBjoern A. Zeeb [MIB_SDR18] = 0x050,
1616c92544dSBjoern A. Zeeb [MIB_SDR19] = 0x054,
1626c92544dSBjoern A. Zeeb [MIB_SDR20] = 0x058,
1636c92544dSBjoern A. Zeeb [MIB_SDR21] = 0x05c,
1646c92544dSBjoern A. Zeeb [MIB_SDR22] = 0x060,
1656c92544dSBjoern A. Zeeb [MIB_SDR23] = 0x064,
1666c92544dSBjoern A. Zeeb [MIB_SDR24] = 0x068,
1676c92544dSBjoern A. Zeeb [MIB_SDR25] = 0x06c,
1686c92544dSBjoern A. Zeeb [MIB_SDR27] = 0x074,
1696c92544dSBjoern A. Zeeb [MIB_SDR28] = 0x078,
1706c92544dSBjoern A. Zeeb [MIB_SDR29] = 0x07c,
1716c92544dSBjoern A. Zeeb [MIB_SDRVEC] = 0x080,
1726c92544dSBjoern A. Zeeb [MIB_SDR31] = 0x084,
1736c92544dSBjoern A. Zeeb [MIB_SDR32] = 0x088,
1746c92544dSBjoern A. Zeeb [MIB_SDRMUBF] = 0x090,
1756c92544dSBjoern A. Zeeb [MIB_DR8] = 0x0c0,
1766c92544dSBjoern A. Zeeb [MIB_DR9] = 0x0c4,
1776c92544dSBjoern A. Zeeb [MIB_DR11] = 0x0cc,
1786c92544dSBjoern A. Zeeb [MIB_MB_SDR0] = 0x100,
1796c92544dSBjoern A. Zeeb [MIB_MB_SDR1] = 0x104,
1806c92544dSBjoern A. Zeeb [TX_AGG_CNT] = 0x0a8,
1816c92544dSBjoern A. Zeeb [TX_AGG_CNT2] = 0x164,
1826c92544dSBjoern A. Zeeb [MIB_ARNG] = 0x4b8,
1836c92544dSBjoern A. Zeeb [WTBLON_TOP_WDUCR] = 0x0,
1846c92544dSBjoern A. Zeeb [WTBL_UPDATE] = 0x030,
1856c92544dSBjoern A. Zeeb [PLE_FL_Q_EMPTY] = 0x0b0,
1866c92544dSBjoern A. Zeeb [PLE_FL_Q_CTRL] = 0x1b0,
1876c92544dSBjoern A. Zeeb [PLE_AC_QEMPTY] = 0x500,
1886c92544dSBjoern A. Zeeb [PLE_FREEPG_CNT] = 0x100,
1896c92544dSBjoern A. Zeeb [PLE_FREEPG_HEAD_TAIL] = 0x104,
1906c92544dSBjoern A. Zeeb [PLE_PG_HIF_GROUP] = 0x110,
1916c92544dSBjoern A. Zeeb [PLE_HIF_PG_INFO] = 0x114,
1926c92544dSBjoern A. Zeeb [AC_OFFSET] = 0x040,
1936c92544dSBjoern A. Zeeb [ETBF_PAR_RPT0] = 0x068,
1946c92544dSBjoern A. Zeeb };
1956c92544dSBjoern A. Zeeb
1966c92544dSBjoern A. Zeeb static const u32 mt7916_offs[] = {
1976c92544dSBjoern A. Zeeb [TMAC_CDTR] = 0x0c8,
1986c92544dSBjoern A. Zeeb [TMAC_ODTR] = 0x0cc,
1996c92544dSBjoern A. Zeeb [TMAC_ATCR] = 0x00c,
2006c92544dSBjoern A. Zeeb [TMAC_TRCR0] = 0x010,
2016c92544dSBjoern A. Zeeb [TMAC_ICR0] = 0x014,
2026c92544dSBjoern A. Zeeb [TMAC_ICR1] = 0x018,
2036c92544dSBjoern A. Zeeb [TMAC_CTCR0] = 0x114,
2046c92544dSBjoern A. Zeeb [TMAC_TFCR0] = 0x0e4,
2056c92544dSBjoern A. Zeeb [MDP_BNRCFR0] = 0x090,
2066c92544dSBjoern A. Zeeb [MDP_BNRCFR1] = 0x094,
2076c92544dSBjoern A. Zeeb [ARB_DRNGR0] = 0x1e0,
2086c92544dSBjoern A. Zeeb [ARB_SCR] = 0x000,
2096c92544dSBjoern A. Zeeb [RMAC_MIB_AIRTIME14] = 0x0398,
2106c92544dSBjoern A. Zeeb [AGG_AWSCR0] = 0x030,
2116c92544dSBjoern A. Zeeb [AGG_PCR0] = 0x040,
2126c92544dSBjoern A. Zeeb [AGG_ACR0] = 0x054,
2136c92544dSBjoern A. Zeeb [AGG_ACR4] = 0x05c,
2146c92544dSBjoern A. Zeeb [AGG_MRCR] = 0x068,
2156c92544dSBjoern A. Zeeb [AGG_ATCR1] = 0x1a8,
2166c92544dSBjoern A. Zeeb [AGG_ATCR3] = 0x080,
2176c92544dSBjoern A. Zeeb [LPON_UTTR0] = 0x360,
2186c92544dSBjoern A. Zeeb [LPON_UTTR1] = 0x364,
2196c92544dSBjoern A. Zeeb [LPON_FRCR] = 0x37c,
2206c92544dSBjoern A. Zeeb [MIB_SDR3] = 0x698,
2216c92544dSBjoern A. Zeeb [MIB_SDR4] = 0x788,
2226c92544dSBjoern A. Zeeb [MIB_SDR5] = 0x780,
2236c92544dSBjoern A. Zeeb [MIB_SDR7] = 0x5a8,
2246c92544dSBjoern A. Zeeb [MIB_SDR8] = 0x78c,
2256c92544dSBjoern A. Zeeb [MIB_SDR9] = 0x024,
2266c92544dSBjoern A. Zeeb [MIB_SDR10] = 0x76c,
2276c92544dSBjoern A. Zeeb [MIB_SDR11] = 0x790,
2286c92544dSBjoern A. Zeeb [MIB_SDR12] = 0x558,
2296c92544dSBjoern A. Zeeb [MIB_SDR13] = 0x560,
2306c92544dSBjoern A. Zeeb [MIB_SDR14] = 0x564,
2316c92544dSBjoern A. Zeeb [MIB_SDR15] = 0x568,
2326c92544dSBjoern A. Zeeb [MIB_SDR16] = 0x7fc,
2336c92544dSBjoern A. Zeeb [MIB_SDR17] = 0x800,
2346c92544dSBjoern A. Zeeb [MIB_SDR18] = 0x030,
2356c92544dSBjoern A. Zeeb [MIB_SDR19] = 0x5ac,
2366c92544dSBjoern A. Zeeb [MIB_SDR20] = 0x5b0,
2376c92544dSBjoern A. Zeeb [MIB_SDR21] = 0x5b4,
2386c92544dSBjoern A. Zeeb [MIB_SDR22] = 0x770,
2396c92544dSBjoern A. Zeeb [MIB_SDR23] = 0x774,
2406c92544dSBjoern A. Zeeb [MIB_SDR24] = 0x778,
2416c92544dSBjoern A. Zeeb [MIB_SDR25] = 0x77c,
2426c92544dSBjoern A. Zeeb [MIB_SDR27] = 0x080,
2436c92544dSBjoern A. Zeeb [MIB_SDR28] = 0x084,
2446c92544dSBjoern A. Zeeb [MIB_SDR29] = 0x650,
2456c92544dSBjoern A. Zeeb [MIB_SDRVEC] = 0x5a8,
2466c92544dSBjoern A. Zeeb [MIB_SDR31] = 0x55c,
2476c92544dSBjoern A. Zeeb [MIB_SDR32] = 0x7a8,
2486c92544dSBjoern A. Zeeb [MIB_SDRMUBF] = 0x7ac,
2496c92544dSBjoern A. Zeeb [MIB_DR8] = 0x56c,
2506c92544dSBjoern A. Zeeb [MIB_DR9] = 0x570,
2516c92544dSBjoern A. Zeeb [MIB_DR11] = 0x574,
2526c92544dSBjoern A. Zeeb [MIB_MB_SDR0] = 0x688,
2536c92544dSBjoern A. Zeeb [MIB_MB_SDR1] = 0x690,
2546c92544dSBjoern A. Zeeb [TX_AGG_CNT] = 0x7dc,
2556c92544dSBjoern A. Zeeb [TX_AGG_CNT2] = 0x7ec,
2566c92544dSBjoern A. Zeeb [MIB_ARNG] = 0x0b0,
2576c92544dSBjoern A. Zeeb [WTBLON_TOP_WDUCR] = 0x200,
2586c92544dSBjoern A. Zeeb [WTBL_UPDATE] = 0x230,
2596c92544dSBjoern A. Zeeb [PLE_FL_Q_EMPTY] = 0x360,
2606c92544dSBjoern A. Zeeb [PLE_FL_Q_CTRL] = 0x3e0,
2616c92544dSBjoern A. Zeeb [PLE_AC_QEMPTY] = 0x600,
2626c92544dSBjoern A. Zeeb [PLE_FREEPG_CNT] = 0x380,
2636c92544dSBjoern A. Zeeb [PLE_FREEPG_HEAD_TAIL] = 0x384,
2646c92544dSBjoern A. Zeeb [PLE_PG_HIF_GROUP] = 0x00c,
2656c92544dSBjoern A. Zeeb [PLE_HIF_PG_INFO] = 0x388,
2666c92544dSBjoern A. Zeeb [AC_OFFSET] = 0x080,
2676c92544dSBjoern A. Zeeb [ETBF_PAR_RPT0] = 0x100,
2686c92544dSBjoern A. Zeeb };
2696c92544dSBjoern A. Zeeb
2706c92544dSBjoern A. Zeeb static const struct mt76_connac_reg_map mt7915_reg_map[] = {
2716c92544dSBjoern A. Zeeb { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */
2726c92544dSBjoern A. Zeeb { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure regs) */
2736c92544dSBjoern A. Zeeb { 0x40000000, 0x70000, 0x10000 }, /* WF_UMAC_SYSRAM */
2746c92544dSBjoern A. Zeeb { 0x54000000, 0x02000, 0x01000 }, /* WFDMA PCIE0 MCU DMA0 */
2756c92544dSBjoern A. Zeeb { 0x55000000, 0x03000, 0x01000 }, /* WFDMA PCIE0 MCU DMA1 */
2766c92544dSBjoern A. Zeeb { 0x58000000, 0x06000, 0x01000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */
2776c92544dSBjoern A. Zeeb { 0x59000000, 0x07000, 0x01000 }, /* WFDMA PCIE1 MCU DMA1 */
2786c92544dSBjoern A. Zeeb { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */
2796c92544dSBjoern A. Zeeb { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */
2806c92544dSBjoern A. Zeeb { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */
2816c92544dSBjoern A. Zeeb { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */
2826c92544dSBjoern A. Zeeb { 0x820c0000, 0x08000, 0x04000 }, /* WF_UMAC_TOP (PLE) */
2836c92544dSBjoern A. Zeeb { 0x820c8000, 0x0c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */
2846c92544dSBjoern A. Zeeb { 0x820cc000, 0x0e000, 0x02000 }, /* WF_UMAC_TOP (PP) */
2856c92544dSBjoern A. Zeeb { 0x820ce000, 0x21c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */
2866c92544dSBjoern A. Zeeb { 0x820cf000, 0x22000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */
2876c92544dSBjoern A. Zeeb { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
2886c92544dSBjoern A. Zeeb { 0x820e0000, 0x20000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */
2896c92544dSBjoern A. Zeeb { 0x820e1000, 0x20400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */
2906c92544dSBjoern A. Zeeb { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */
2916c92544dSBjoern A. Zeeb { 0x820e3000, 0x20c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */
2926c92544dSBjoern A. Zeeb { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
2936c92544dSBjoern A. Zeeb { 0x820e5000, 0x21400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */
2946c92544dSBjoern A. Zeeb { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
2956c92544dSBjoern A. Zeeb { 0x820e9000, 0x23400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */
2966c92544dSBjoern A. Zeeb { 0x820ea000, 0x24000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */
2976c92544dSBjoern A. Zeeb { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
2986c92544dSBjoern A. Zeeb { 0x820ec000, 0x24600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */
2996c92544dSBjoern A. Zeeb { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
3006c92544dSBjoern A. Zeeb { 0x820f0000, 0xa0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */
3016c92544dSBjoern A. Zeeb { 0x820f1000, 0xa0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */
3026c92544dSBjoern A. Zeeb { 0x820f2000, 0xa0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */
3036c92544dSBjoern A. Zeeb { 0x820f3000, 0xa0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */
3046c92544dSBjoern A. Zeeb { 0x820f4000, 0xa1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */
3056c92544dSBjoern A. Zeeb { 0x820f5000, 0xa1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */
3066c92544dSBjoern A. Zeeb { 0x820f7000, 0xa1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */
3076c92544dSBjoern A. Zeeb { 0x820f9000, 0xa3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */
3086c92544dSBjoern A. Zeeb { 0x820fa000, 0xa4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */
3096c92544dSBjoern A. Zeeb { 0x820fb000, 0xa4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */
3106c92544dSBjoern A. Zeeb { 0x820fc000, 0xa4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */
3116c92544dSBjoern A. Zeeb { 0x820fd000, 0xa4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */
3126c92544dSBjoern A. Zeeb { 0x0, 0x0, 0x0 }, /* imply end of search */
3136c92544dSBjoern A. Zeeb };
3146c92544dSBjoern A. Zeeb
3156c92544dSBjoern A. Zeeb static const struct mt76_connac_reg_map mt7916_reg_map[] = {
3166c92544dSBjoern A. Zeeb { 0x54000000, 0x02000, 0x01000 }, /* WFDMA_0 (PCIE0 MCU DMA0) */
3176c92544dSBjoern A. Zeeb { 0x55000000, 0x03000, 0x01000 }, /* WFDMA_1 (PCIE0 MCU DMA1) */
3186c92544dSBjoern A. Zeeb { 0x56000000, 0x04000, 0x01000 }, /* WFDMA_2 (Reserved) */
3196c92544dSBjoern A. Zeeb { 0x57000000, 0x05000, 0x01000 }, /* WFDMA_3 (MCU wrap CR) */
3206c92544dSBjoern A. Zeeb { 0x58000000, 0x06000, 0x01000 }, /* WFDMA_4 (PCIE1 MCU DMA0) */
3216c92544dSBjoern A. Zeeb { 0x59000000, 0x07000, 0x01000 }, /* WFDMA_5 (PCIE1 MCU DMA1) */
3226c92544dSBjoern A. Zeeb { 0x820c0000, 0x08000, 0x04000 }, /* WF_UMAC_TOP (PLE) */
3236c92544dSBjoern A. Zeeb { 0x820c8000, 0x0c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */
3246c92544dSBjoern A. Zeeb { 0x820cc000, 0x0e000, 0x02000 }, /* WF_UMAC_TOP (PP) */
3256c92544dSBjoern A. Zeeb { 0x820e0000, 0x20000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */
3266c92544dSBjoern A. Zeeb { 0x820e1000, 0x20400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */
3276c92544dSBjoern A. Zeeb { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */
3286c92544dSBjoern A. Zeeb { 0x820e3000, 0x20c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */
3296c92544dSBjoern A. Zeeb { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
3306c92544dSBjoern A. Zeeb { 0x820e5000, 0x21400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */
3316c92544dSBjoern A. Zeeb { 0x820ce000, 0x21c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */
3326c92544dSBjoern A. Zeeb { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
3336c92544dSBjoern A. Zeeb { 0x820cf000, 0x22000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */
3346c92544dSBjoern A. Zeeb { 0x820e9000, 0x23400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */
3356c92544dSBjoern A. Zeeb { 0x820ea000, 0x24000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */
3366c92544dSBjoern A. Zeeb { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
3376c92544dSBjoern A. Zeeb { 0x820ec000, 0x24600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */
3386c92544dSBjoern A. Zeeb { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
3396c92544dSBjoern A. Zeeb { 0x820ca000, 0x26000, 0x02000 }, /* WF_LMAC_TOP BN0 (WF_MUCOP) */
3406c92544dSBjoern A. Zeeb { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
3416c92544dSBjoern A. Zeeb { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */
3426c92544dSBjoern A. Zeeb { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure cr) */
3436c92544dSBjoern A. Zeeb { 0x820f0000, 0xa0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */
3446c92544dSBjoern A. Zeeb { 0x820f1000, 0xa0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */
3456c92544dSBjoern A. Zeeb { 0x820f2000, 0xa0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */
3466c92544dSBjoern A. Zeeb { 0x820f3000, 0xa0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */
3476c92544dSBjoern A. Zeeb { 0x820f4000, 0xa1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */
3486c92544dSBjoern A. Zeeb { 0x820f5000, 0xa1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */
3496c92544dSBjoern A. Zeeb { 0x820f7000, 0xa1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */
3506c92544dSBjoern A. Zeeb { 0x820f9000, 0xa3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */
3516c92544dSBjoern A. Zeeb { 0x820fa000, 0xa4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */
3526c92544dSBjoern A. Zeeb { 0x820fb000, 0xa4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */
3536c92544dSBjoern A. Zeeb { 0x820fc000, 0xa4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */
3546c92544dSBjoern A. Zeeb { 0x820fd000, 0xa4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */
3556c92544dSBjoern A. Zeeb { 0x820c4000, 0xa8000, 0x01000 }, /* WF_LMAC_TOP (WF_UWTBL ) */
3566c92544dSBjoern A. Zeeb { 0x820b0000, 0xae000, 0x01000 }, /* [APB2] WFSYS_ON */
3576c92544dSBjoern A. Zeeb { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */
3586c92544dSBjoern A. Zeeb { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */
3596c92544dSBjoern A. Zeeb { 0x0, 0x0, 0x0 }, /* imply end of search */
3606c92544dSBjoern A. Zeeb };
3616c92544dSBjoern A. Zeeb
3626c92544dSBjoern A. Zeeb static const struct mt76_connac_reg_map mt7986_reg_map[] = {
3636c92544dSBjoern A. Zeeb { 0x54000000, 0x402000, 0x01000 }, /* WFDMA_0 (PCIE0 MCU DMA0) */
3646c92544dSBjoern A. Zeeb { 0x55000000, 0x403000, 0x01000 }, /* WFDMA_1 (PCIE0 MCU DMA1) */
3656c92544dSBjoern A. Zeeb { 0x56000000, 0x404000, 0x01000 }, /* WFDMA_2 (Reserved) */
3666c92544dSBjoern A. Zeeb { 0x57000000, 0x405000, 0x01000 }, /* WFDMA_3 (MCU wrap CR) */
3676c92544dSBjoern A. Zeeb { 0x58000000, 0x406000, 0x01000 }, /* WFDMA_4 (PCIE1 MCU DMA0) */
3686c92544dSBjoern A. Zeeb { 0x59000000, 0x407000, 0x01000 }, /* WFDMA_5 (PCIE1 MCU DMA1) */
3696c92544dSBjoern A. Zeeb { 0x820c0000, 0x408000, 0x04000 }, /* WF_UMAC_TOP (PLE) */
3706c92544dSBjoern A. Zeeb { 0x820c8000, 0x40c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */
3716c92544dSBjoern A. Zeeb { 0x820cc000, 0x40e000, 0x02000 }, /* WF_UMAC_TOP (PP) */
3726c92544dSBjoern A. Zeeb { 0x820e0000, 0x420000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */
3736c92544dSBjoern A. Zeeb { 0x820e1000, 0x420400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */
3746c92544dSBjoern A. Zeeb { 0x820e2000, 0x420800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */
3756c92544dSBjoern A. Zeeb { 0x820e3000, 0x420c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */
3766c92544dSBjoern A. Zeeb { 0x820e4000, 0x421000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */
3776c92544dSBjoern A. Zeeb { 0x820e5000, 0x421400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */
3786c92544dSBjoern A. Zeeb { 0x820ce000, 0x421c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */
3796c92544dSBjoern A. Zeeb { 0x820e7000, 0x421e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */
3806c92544dSBjoern A. Zeeb { 0x820cf000, 0x422000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */
3816c92544dSBjoern A. Zeeb { 0x820e9000, 0x423400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */
3826c92544dSBjoern A. Zeeb { 0x820ea000, 0x424000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */
3836c92544dSBjoern A. Zeeb { 0x820eb000, 0x424200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */
3846c92544dSBjoern A. Zeeb { 0x820ec000, 0x424600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */
3856c92544dSBjoern A. Zeeb { 0x820ed000, 0x424800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */
3866c92544dSBjoern A. Zeeb { 0x820ca000, 0x426000, 0x02000 }, /* WF_LMAC_TOP BN0 (WF_MUCOP) */
3876c92544dSBjoern A. Zeeb { 0x820d0000, 0x430000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */
3886c92544dSBjoern A. Zeeb { 0x00400000, 0x480000, 0x10000 }, /* WF_MCU_SYSRAM */
3896c92544dSBjoern A. Zeeb { 0x00410000, 0x490000, 0x10000 }, /* WF_MCU_SYSRAM */
3906c92544dSBjoern A. Zeeb { 0x820f0000, 0x4a0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */
3916c92544dSBjoern A. Zeeb { 0x820f1000, 0x4a0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */
3926c92544dSBjoern A. Zeeb { 0x820f2000, 0x4a0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */
3936c92544dSBjoern A. Zeeb { 0x820f3000, 0x4a0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */
3946c92544dSBjoern A. Zeeb { 0x820f4000, 0x4a1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */
3956c92544dSBjoern A. Zeeb { 0x820f5000, 0x4a1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */
3966c92544dSBjoern A. Zeeb { 0x820f7000, 0x4a1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */
3976c92544dSBjoern A. Zeeb { 0x820f9000, 0x4a3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */
3986c92544dSBjoern A. Zeeb { 0x820fa000, 0x4a4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */
3996c92544dSBjoern A. Zeeb { 0x820fb000, 0x4a4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */
4006c92544dSBjoern A. Zeeb { 0x820fc000, 0x4a4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */
4016c92544dSBjoern A. Zeeb { 0x820fd000, 0x4a4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */
4026c92544dSBjoern A. Zeeb { 0x820c4000, 0x4a8000, 0x01000 }, /* WF_LMAC_TOP (WF_UWTBL ) */
4036c92544dSBjoern A. Zeeb { 0x820b0000, 0x4ae000, 0x01000 }, /* [APB2] WFSYS_ON */
4046c92544dSBjoern A. Zeeb { 0x80020000, 0x4b0000, 0x10000 }, /* WF_TOP_MISC_OFF */
4056c92544dSBjoern A. Zeeb { 0x81020000, 0x4c0000, 0x10000 }, /* WF_TOP_MISC_ON */
4066c92544dSBjoern A. Zeeb { 0x89000000, 0x4d0000, 0x01000 }, /* WF_MCU_CFG_ON */
4076c92544dSBjoern A. Zeeb { 0x89010000, 0x4d1000, 0x01000 }, /* WF_MCU_CIRQ */
4086c92544dSBjoern A. Zeeb { 0x89020000, 0x4d2000, 0x01000 }, /* WF_MCU_GPT */
4096c92544dSBjoern A. Zeeb { 0x89030000, 0x4d3000, 0x01000 }, /* WF_MCU_WDT */
4106c92544dSBjoern A. Zeeb { 0x80010000, 0x4d4000, 0x01000 }, /* WF_AXIDMA */
4116c92544dSBjoern A. Zeeb { 0x0, 0x0, 0x0 }, /* imply end of search */
4126c92544dSBjoern A. Zeeb };
4136c92544dSBjoern A. Zeeb
mt7915_reg_map_l1(struct mt7915_dev * dev,u32 addr)4146c92544dSBjoern A. Zeeb static u32 mt7915_reg_map_l1(struct mt7915_dev *dev, u32 addr)
4156c92544dSBjoern A. Zeeb {
4166c92544dSBjoern A. Zeeb u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr);
4176c92544dSBjoern A. Zeeb u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr);
4186c92544dSBjoern A. Zeeb u32 l1_remap;
4196c92544dSBjoern A. Zeeb
420*cbb3ec25SBjoern A. Zeeb if (is_mt798x(&dev->mt76))
4216c92544dSBjoern A. Zeeb return MT_CONN_INFRA_OFFSET(addr);
4226c92544dSBjoern A. Zeeb
4236c92544dSBjoern A. Zeeb l1_remap = is_mt7915(&dev->mt76) ?
4246c92544dSBjoern A. Zeeb MT_HIF_REMAP_L1 : MT_HIF_REMAP_L1_MT7916;
4256c92544dSBjoern A. Zeeb
4266c92544dSBjoern A. Zeeb dev->bus_ops->rmw(&dev->mt76, l1_remap,
4276c92544dSBjoern A. Zeeb MT_HIF_REMAP_L1_MASK,
4286c92544dSBjoern A. Zeeb FIELD_PREP(MT_HIF_REMAP_L1_MASK, base));
4296c92544dSBjoern A. Zeeb /* use read to push write */
4306c92544dSBjoern A. Zeeb dev->bus_ops->rr(&dev->mt76, l1_remap);
4316c92544dSBjoern A. Zeeb
4326c92544dSBjoern A. Zeeb return MT_HIF_REMAP_BASE_L1 + offset;
4336c92544dSBjoern A. Zeeb }
4346c92544dSBjoern A. Zeeb
mt7915_reg_map_l2(struct mt7915_dev * dev,u32 addr)4356c92544dSBjoern A. Zeeb static u32 mt7915_reg_map_l2(struct mt7915_dev *dev, u32 addr)
4366c92544dSBjoern A. Zeeb {
4376c92544dSBjoern A. Zeeb u32 offset, base;
4386c92544dSBjoern A. Zeeb
4396c92544dSBjoern A. Zeeb if (is_mt7915(&dev->mt76)) {
4406c92544dSBjoern A. Zeeb offset = FIELD_GET(MT_HIF_REMAP_L2_OFFSET, addr);
4416c92544dSBjoern A. Zeeb base = FIELD_GET(MT_HIF_REMAP_L2_BASE, addr);
4426c92544dSBjoern A. Zeeb
4436c92544dSBjoern A. Zeeb dev->bus_ops->rmw(&dev->mt76, MT_HIF_REMAP_L2,
4446c92544dSBjoern A. Zeeb MT_HIF_REMAP_L2_MASK,
4456c92544dSBjoern A. Zeeb FIELD_PREP(MT_HIF_REMAP_L2_MASK, base));
4466c92544dSBjoern A. Zeeb
4476c92544dSBjoern A. Zeeb /* use read to push write */
4486c92544dSBjoern A. Zeeb dev->bus_ops->rr(&dev->mt76, MT_HIF_REMAP_L2);
4496c92544dSBjoern A. Zeeb } else {
450*cbb3ec25SBjoern A. Zeeb u32 ofs = is_mt798x(&dev->mt76) ? 0x400000 : 0;
4516c92544dSBjoern A. Zeeb
4526c92544dSBjoern A. Zeeb offset = FIELD_GET(MT_HIF_REMAP_L2_OFFSET_MT7916, addr);
4536c92544dSBjoern A. Zeeb base = FIELD_GET(MT_HIF_REMAP_L2_BASE_MT7916, addr);
4546c92544dSBjoern A. Zeeb
4556c92544dSBjoern A. Zeeb dev->bus_ops->rmw(&dev->mt76, MT_HIF_REMAP_L2_MT7916 + ofs,
4566c92544dSBjoern A. Zeeb MT_HIF_REMAP_L2_MASK_MT7916,
4576c92544dSBjoern A. Zeeb FIELD_PREP(MT_HIF_REMAP_L2_MASK_MT7916, base));
4586c92544dSBjoern A. Zeeb
4596c92544dSBjoern A. Zeeb /* use read to push write */
4606c92544dSBjoern A. Zeeb dev->bus_ops->rr(&dev->mt76, MT_HIF_REMAP_L2_MT7916 + ofs);
4616c92544dSBjoern A. Zeeb
4626c92544dSBjoern A. Zeeb offset += (MT_HIF_REMAP_BASE_L2_MT7916 + ofs);
4636c92544dSBjoern A. Zeeb }
4646c92544dSBjoern A. Zeeb
4656c92544dSBjoern A. Zeeb return offset;
4666c92544dSBjoern A. Zeeb }
4676c92544dSBjoern A. Zeeb
__mt7915_reg_addr(struct mt7915_dev * dev,u32 addr)4686c92544dSBjoern A. Zeeb static u32 __mt7915_reg_addr(struct mt7915_dev *dev, u32 addr)
4696c92544dSBjoern A. Zeeb {
4706c92544dSBjoern A. Zeeb int i;
4716c92544dSBjoern A. Zeeb
4726c92544dSBjoern A. Zeeb if (addr < 0x100000)
4736c92544dSBjoern A. Zeeb return addr;
4746c92544dSBjoern A. Zeeb
4756c92544dSBjoern A. Zeeb if (!dev->reg.map) {
4766c92544dSBjoern A. Zeeb dev_err(dev->mt76.dev, "err: reg_map is null\n");
4776c92544dSBjoern A. Zeeb return addr;
4786c92544dSBjoern A. Zeeb }
4796c92544dSBjoern A. Zeeb
4806c92544dSBjoern A. Zeeb for (i = 0; i < dev->reg.map_size; i++) {
4816c92544dSBjoern A. Zeeb u32 ofs;
4826c92544dSBjoern A. Zeeb
4836c92544dSBjoern A. Zeeb if (addr < dev->reg.map[i].phys)
4846c92544dSBjoern A. Zeeb continue;
4856c92544dSBjoern A. Zeeb
4866c92544dSBjoern A. Zeeb ofs = addr - dev->reg.map[i].phys;
4876c92544dSBjoern A. Zeeb if (ofs > dev->reg.map[i].size)
4886c92544dSBjoern A. Zeeb continue;
4896c92544dSBjoern A. Zeeb
4906c92544dSBjoern A. Zeeb return dev->reg.map[i].maps + ofs;
4916c92544dSBjoern A. Zeeb }
4926c92544dSBjoern A. Zeeb
4936c92544dSBjoern A. Zeeb if ((addr >= MT_INFRA_BASE && addr < MT_WFSYS0_PHY_START) ||
4946c92544dSBjoern A. Zeeb (addr >= MT_WFSYS0_PHY_START && addr < MT_WFSYS1_PHY_START) ||
4956c92544dSBjoern A. Zeeb (addr >= MT_WFSYS1_PHY_START && addr <= MT_WFSYS1_PHY_END))
4966c92544dSBjoern A. Zeeb return mt7915_reg_map_l1(dev, addr);
4976c92544dSBjoern A. Zeeb
4986c92544dSBjoern A. Zeeb if (dev_is_pci(dev->mt76.dev) &&
4996c92544dSBjoern A. Zeeb ((addr >= MT_CBTOP1_PHY_START && addr <= MT_CBTOP1_PHY_END) ||
500*cbb3ec25SBjoern A. Zeeb addr >= MT_CBTOP2_PHY_START))
5016c92544dSBjoern A. Zeeb return mt7915_reg_map_l1(dev, addr);
5026c92544dSBjoern A. Zeeb
5036c92544dSBjoern A. Zeeb /* CONN_INFRA: covert to phyiscal addr and use layer 1 remap */
5046c92544dSBjoern A. Zeeb if (addr >= MT_INFRA_MCU_START && addr <= MT_INFRA_MCU_END) {
5056c92544dSBjoern A. Zeeb addr = addr - MT_INFRA_MCU_START + MT_INFRA_BASE;
5066c92544dSBjoern A. Zeeb return mt7915_reg_map_l1(dev, addr);
5076c92544dSBjoern A. Zeeb }
5086c92544dSBjoern A. Zeeb
5096c92544dSBjoern A. Zeeb return mt7915_reg_map_l2(dev, addr);
5106c92544dSBjoern A. Zeeb }
5116c92544dSBjoern A. Zeeb
mt7915_memcpy_fromio(struct mt7915_dev * dev,void * buf,u32 offset,size_t len)512*cbb3ec25SBjoern A. Zeeb void mt7915_memcpy_fromio(struct mt7915_dev *dev, void *buf, u32 offset,
513*cbb3ec25SBjoern A. Zeeb size_t len)
514*cbb3ec25SBjoern A. Zeeb {
515*cbb3ec25SBjoern A. Zeeb u32 addr = __mt7915_reg_addr(dev, offset);
516*cbb3ec25SBjoern A. Zeeb
517*cbb3ec25SBjoern A. Zeeb #if defined(__linux__)
518*cbb3ec25SBjoern A. Zeeb memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len);
519*cbb3ec25SBjoern A. Zeeb #elif defined(__FreeBSD__)
520*cbb3ec25SBjoern A. Zeeb memcpy_fromio(buf, (u8 *)dev->mt76.mmio.regs + addr, len);
521*cbb3ec25SBjoern A. Zeeb #endif
522*cbb3ec25SBjoern A. Zeeb }
523*cbb3ec25SBjoern A. Zeeb
mt7915_rr(struct mt76_dev * mdev,u32 offset)5246c92544dSBjoern A. Zeeb static u32 mt7915_rr(struct mt76_dev *mdev, u32 offset)
5256c92544dSBjoern A. Zeeb {
5266c92544dSBjoern A. Zeeb struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
5276c92544dSBjoern A. Zeeb u32 addr = __mt7915_reg_addr(dev, offset);
5286c92544dSBjoern A. Zeeb
5296c92544dSBjoern A. Zeeb return dev->bus_ops->rr(mdev, addr);
5306c92544dSBjoern A. Zeeb }
5316c92544dSBjoern A. Zeeb
mt7915_wr(struct mt76_dev * mdev,u32 offset,u32 val)5326c92544dSBjoern A. Zeeb static void mt7915_wr(struct mt76_dev *mdev, u32 offset, u32 val)
5336c92544dSBjoern A. Zeeb {
5346c92544dSBjoern A. Zeeb struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
5356c92544dSBjoern A. Zeeb u32 addr = __mt7915_reg_addr(dev, offset);
5366c92544dSBjoern A. Zeeb
5376c92544dSBjoern A. Zeeb dev->bus_ops->wr(mdev, addr, val);
5386c92544dSBjoern A. Zeeb }
5396c92544dSBjoern A. Zeeb
mt7915_rmw(struct mt76_dev * mdev,u32 offset,u32 mask,u32 val)5406c92544dSBjoern A. Zeeb static u32 mt7915_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
5416c92544dSBjoern A. Zeeb {
5426c92544dSBjoern A. Zeeb struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
5436c92544dSBjoern A. Zeeb u32 addr = __mt7915_reg_addr(dev, offset);
5446c92544dSBjoern A. Zeeb
5456c92544dSBjoern A. Zeeb return dev->bus_ops->rmw(mdev, addr, mask, val);
5466c92544dSBjoern A. Zeeb }
5476c92544dSBjoern A. Zeeb
548*cbb3ec25SBjoern A. Zeeb #ifdef CONFIG_NET_MEDIATEK_SOC_WED
mt7915_mmio_wed_offload_enable(struct mtk_wed_device * wed)549*cbb3ec25SBjoern A. Zeeb static int mt7915_mmio_wed_offload_enable(struct mtk_wed_device *wed)
550*cbb3ec25SBjoern A. Zeeb {
551*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev;
552*cbb3ec25SBjoern A. Zeeb
553*cbb3ec25SBjoern A. Zeeb dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
554*cbb3ec25SBjoern A. Zeeb
555*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.token_lock);
556*cbb3ec25SBjoern A. Zeeb dev->mt76.token_size = wed->wlan.token_start;
557*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.token_lock);
558*cbb3ec25SBjoern A. Zeeb
559*cbb3ec25SBjoern A. Zeeb return !wait_event_timeout(dev->mt76.tx_wait,
560*cbb3ec25SBjoern A. Zeeb !dev->mt76.wed_token_count, HZ);
561*cbb3ec25SBjoern A. Zeeb }
562*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_offload_disable(struct mtk_wed_device * wed)563*cbb3ec25SBjoern A. Zeeb static void mt7915_mmio_wed_offload_disable(struct mtk_wed_device *wed)
564*cbb3ec25SBjoern A. Zeeb {
565*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev;
566*cbb3ec25SBjoern A. Zeeb
567*cbb3ec25SBjoern A. Zeeb dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
568*cbb3ec25SBjoern A. Zeeb
569*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->mt76.token_lock);
570*cbb3ec25SBjoern A. Zeeb dev->mt76.token_size = MT7915_TOKEN_SIZE;
571*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->mt76.token_lock);
572*cbb3ec25SBjoern A. Zeeb }
573*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device * wed)574*cbb3ec25SBjoern A. Zeeb static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed)
575*cbb3ec25SBjoern A. Zeeb {
576*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev;
577*cbb3ec25SBjoern A. Zeeb int i;
578*cbb3ec25SBjoern A. Zeeb
579*cbb3ec25SBjoern A. Zeeb dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
580*cbb3ec25SBjoern A. Zeeb for (i = 0; i < dev->mt76.rx_token_size; i++) {
581*cbb3ec25SBjoern A. Zeeb struct mt76_txwi_cache *t;
582*cbb3ec25SBjoern A. Zeeb
583*cbb3ec25SBjoern A. Zeeb t = mt76_rx_token_release(&dev->mt76, i);
584*cbb3ec25SBjoern A. Zeeb if (!t || !t->ptr)
585*cbb3ec25SBjoern A. Zeeb continue;
586*cbb3ec25SBjoern A. Zeeb
587*cbb3ec25SBjoern A. Zeeb mt76_put_page_pool_buf(t->ptr, false);
588*cbb3ec25SBjoern A. Zeeb t->ptr = NULL;
589*cbb3ec25SBjoern A. Zeeb
590*cbb3ec25SBjoern A. Zeeb mt76_put_rxwi(&dev->mt76, t);
591*cbb3ec25SBjoern A. Zeeb }
592*cbb3ec25SBjoern A. Zeeb
593*cbb3ec25SBjoern A. Zeeb mt76_free_pending_rxwi(&dev->mt76);
594*cbb3ec25SBjoern A. Zeeb }
595*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device * wed,int size)596*cbb3ec25SBjoern A. Zeeb static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
597*cbb3ec25SBjoern A. Zeeb {
598*cbb3ec25SBjoern A. Zeeb struct mtk_rxbm_desc *desc = wed->rx_buf_ring.desc;
599*cbb3ec25SBjoern A. Zeeb struct mt76_txwi_cache *t = NULL;
600*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev;
601*cbb3ec25SBjoern A. Zeeb struct mt76_queue *q;
602*cbb3ec25SBjoern A. Zeeb int i, len;
603*cbb3ec25SBjoern A. Zeeb
604*cbb3ec25SBjoern A. Zeeb dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
605*cbb3ec25SBjoern A. Zeeb q = &dev->mt76.q_rx[MT_RXQ_MAIN];
606*cbb3ec25SBjoern A. Zeeb len = SKB_WITH_OVERHEAD(q->buf_size);
607*cbb3ec25SBjoern A. Zeeb
608*cbb3ec25SBjoern A. Zeeb for (i = 0; i < size; i++) {
609*cbb3ec25SBjoern A. Zeeb enum dma_data_direction dir;
610*cbb3ec25SBjoern A. Zeeb dma_addr_t addr;
611*cbb3ec25SBjoern A. Zeeb u32 offset;
612*cbb3ec25SBjoern A. Zeeb int token;
613*cbb3ec25SBjoern A. Zeeb void *buf;
614*cbb3ec25SBjoern A. Zeeb
615*cbb3ec25SBjoern A. Zeeb t = mt76_get_rxwi(&dev->mt76);
616*cbb3ec25SBjoern A. Zeeb if (!t)
617*cbb3ec25SBjoern A. Zeeb goto unmap;
618*cbb3ec25SBjoern A. Zeeb
619*cbb3ec25SBjoern A. Zeeb buf = mt76_get_page_pool_buf(q, &offset, q->buf_size);
620*cbb3ec25SBjoern A. Zeeb if (!buf)
621*cbb3ec25SBjoern A. Zeeb goto unmap;
622*cbb3ec25SBjoern A. Zeeb
623*cbb3ec25SBjoern A. Zeeb addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset;
624*cbb3ec25SBjoern A. Zeeb dir = page_pool_get_dma_dir(q->page_pool);
625*cbb3ec25SBjoern A. Zeeb dma_sync_single_for_device(dev->mt76.dma_dev, addr, len, dir);
626*cbb3ec25SBjoern A. Zeeb
627*cbb3ec25SBjoern A. Zeeb desc->buf0 = cpu_to_le32(addr);
628*cbb3ec25SBjoern A. Zeeb token = mt76_rx_token_consume(&dev->mt76, buf, t, addr);
629*cbb3ec25SBjoern A. Zeeb if (token < 0) {
630*cbb3ec25SBjoern A. Zeeb mt76_put_page_pool_buf(buf, false);
631*cbb3ec25SBjoern A. Zeeb goto unmap;
632*cbb3ec25SBjoern A. Zeeb }
633*cbb3ec25SBjoern A. Zeeb
634*cbb3ec25SBjoern A. Zeeb desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN,
635*cbb3ec25SBjoern A. Zeeb token));
636*cbb3ec25SBjoern A. Zeeb desc++;
637*cbb3ec25SBjoern A. Zeeb }
638*cbb3ec25SBjoern A. Zeeb
639*cbb3ec25SBjoern A. Zeeb return 0;
640*cbb3ec25SBjoern A. Zeeb
641*cbb3ec25SBjoern A. Zeeb unmap:
642*cbb3ec25SBjoern A. Zeeb if (t)
643*cbb3ec25SBjoern A. Zeeb mt76_put_rxwi(&dev->mt76, t);
644*cbb3ec25SBjoern A. Zeeb mt7915_mmio_wed_release_rx_buf(wed);
645*cbb3ec25SBjoern A. Zeeb return -ENOMEM;
646*cbb3ec25SBjoern A. Zeeb }
647*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device * wed,struct mtk_wed_wo_rx_stats * stats)648*cbb3ec25SBjoern A. Zeeb static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed,
649*cbb3ec25SBjoern A. Zeeb struct mtk_wed_wo_rx_stats *stats)
650*cbb3ec25SBjoern A. Zeeb {
651*cbb3ec25SBjoern A. Zeeb int idx = le16_to_cpu(stats->wlan_idx);
652*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev;
653*cbb3ec25SBjoern A. Zeeb struct mt76_wcid *wcid;
654*cbb3ec25SBjoern A. Zeeb
655*cbb3ec25SBjoern A. Zeeb dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed);
656*cbb3ec25SBjoern A. Zeeb
657*cbb3ec25SBjoern A. Zeeb if (idx >= mt7915_wtbl_size(dev))
658*cbb3ec25SBjoern A. Zeeb return;
659*cbb3ec25SBjoern A. Zeeb
660*cbb3ec25SBjoern A. Zeeb rcu_read_lock();
661*cbb3ec25SBjoern A. Zeeb
662*cbb3ec25SBjoern A. Zeeb wcid = rcu_dereference(dev->mt76.wcid[idx]);
663*cbb3ec25SBjoern A. Zeeb if (wcid) {
664*cbb3ec25SBjoern A. Zeeb wcid->stats.rx_bytes += le32_to_cpu(stats->rx_byte_cnt);
665*cbb3ec25SBjoern A. Zeeb wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt);
666*cbb3ec25SBjoern A. Zeeb wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt);
667*cbb3ec25SBjoern A. Zeeb wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt);
668*cbb3ec25SBjoern A. Zeeb }
669*cbb3ec25SBjoern A. Zeeb
670*cbb3ec25SBjoern A. Zeeb rcu_read_unlock();
671*cbb3ec25SBjoern A. Zeeb }
672*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_reset(struct mtk_wed_device * wed)673*cbb3ec25SBjoern A. Zeeb static int mt7915_mmio_wed_reset(struct mtk_wed_device *wed)
674*cbb3ec25SBjoern A. Zeeb {
675*cbb3ec25SBjoern A. Zeeb struct mt76_dev *mdev = container_of(wed, struct mt76_dev, mmio.wed);
676*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
677*cbb3ec25SBjoern A. Zeeb struct mt76_phy *mphy = &dev->mphy;
678*cbb3ec25SBjoern A. Zeeb int ret;
679*cbb3ec25SBjoern A. Zeeb
680*cbb3ec25SBjoern A. Zeeb ASSERT_RTNL();
681*cbb3ec25SBjoern A. Zeeb
682*cbb3ec25SBjoern A. Zeeb if (test_and_set_bit(MT76_STATE_WED_RESET, &mphy->state))
683*cbb3ec25SBjoern A. Zeeb return -EBUSY;
684*cbb3ec25SBjoern A. Zeeb
685*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_set_ser(dev, SER_RECOVER, SER_SET_RECOVER_L1,
686*cbb3ec25SBjoern A. Zeeb mphy->band_idx);
687*cbb3ec25SBjoern A. Zeeb if (ret)
688*cbb3ec25SBjoern A. Zeeb goto out;
689*cbb3ec25SBjoern A. Zeeb
690*cbb3ec25SBjoern A. Zeeb rtnl_unlock();
691*cbb3ec25SBjoern A. Zeeb if (!wait_for_completion_timeout(&mdev->mmio.wed_reset, 20 * HZ)) {
692*cbb3ec25SBjoern A. Zeeb dev_err(mdev->dev, "wed reset timeout\n");
693*cbb3ec25SBjoern A. Zeeb ret = -ETIMEDOUT;
694*cbb3ec25SBjoern A. Zeeb }
695*cbb3ec25SBjoern A. Zeeb rtnl_lock();
696*cbb3ec25SBjoern A. Zeeb out:
697*cbb3ec25SBjoern A. Zeeb clear_bit(MT76_STATE_WED_RESET, &mphy->state);
698*cbb3ec25SBjoern A. Zeeb
699*cbb3ec25SBjoern A. Zeeb return ret;
700*cbb3ec25SBjoern A. Zeeb }
701*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_reset_complete(struct mtk_wed_device * wed)702*cbb3ec25SBjoern A. Zeeb static void mt7915_mmio_wed_reset_complete(struct mtk_wed_device *wed)
703*cbb3ec25SBjoern A. Zeeb {
704*cbb3ec25SBjoern A. Zeeb struct mt76_dev *dev = container_of(wed, struct mt76_dev, mmio.wed);
705*cbb3ec25SBjoern A. Zeeb
706*cbb3ec25SBjoern A. Zeeb complete(&dev->mmio.wed_reset_complete);
707*cbb3ec25SBjoern A. Zeeb }
708*cbb3ec25SBjoern A. Zeeb #endif
709*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_wed_init(struct mt7915_dev * dev,void * pdev_ptr,bool pci,int * irq)710*cbb3ec25SBjoern A. Zeeb int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
711*cbb3ec25SBjoern A. Zeeb bool pci, int *irq)
712*cbb3ec25SBjoern A. Zeeb {
713*cbb3ec25SBjoern A. Zeeb #ifdef CONFIG_NET_MEDIATEK_SOC_WED
714*cbb3ec25SBjoern A. Zeeb struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
715*cbb3ec25SBjoern A. Zeeb int ret;
716*cbb3ec25SBjoern A. Zeeb
717*cbb3ec25SBjoern A. Zeeb if (!wed_enable)
718*cbb3ec25SBjoern A. Zeeb return 0;
719*cbb3ec25SBjoern A. Zeeb
720*cbb3ec25SBjoern A. Zeeb if (pci) {
721*cbb3ec25SBjoern A. Zeeb struct pci_dev *pci_dev = pdev_ptr;
722*cbb3ec25SBjoern A. Zeeb
723*cbb3ec25SBjoern A. Zeeb wed->wlan.pci_dev = pci_dev;
724*cbb3ec25SBjoern A. Zeeb wed->wlan.bus_type = MTK_WED_BUS_PCIE;
725*cbb3ec25SBjoern A. Zeeb wed->wlan.base = devm_ioremap(dev->mt76.dev,
726*cbb3ec25SBjoern A. Zeeb pci_resource_start(pci_dev, 0),
727*cbb3ec25SBjoern A. Zeeb pci_resource_len(pci_dev, 0));
728*cbb3ec25SBjoern A. Zeeb wed->wlan.phy_base = pci_resource_start(pci_dev, 0);
729*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_int = pci_resource_start(pci_dev, 0) +
730*cbb3ec25SBjoern A. Zeeb MT_INT_WED_SOURCE_CSR;
731*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_mask = pci_resource_start(pci_dev, 0) +
732*cbb3ec25SBjoern A. Zeeb MT_INT_WED_MASK_CSR;
733*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_phys = pci_resource_start(pci_dev, 0) +
734*cbb3ec25SBjoern A. Zeeb MT_WFDMA_EXT_CSR_BASE;
735*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_tx = pci_resource_start(pci_dev, 0) +
736*cbb3ec25SBjoern A. Zeeb MT_TXQ_WED_RING_BASE;
737*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_txfree = pci_resource_start(pci_dev, 0) +
738*cbb3ec25SBjoern A. Zeeb MT_RXQ_WED_RING_BASE;
739*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_rx_glo = pci_resource_start(pci_dev, 0) +
740*cbb3ec25SBjoern A. Zeeb MT_WPDMA_GLO_CFG;
741*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_rx = pci_resource_start(pci_dev, 0) +
742*cbb3ec25SBjoern A. Zeeb MT_RXQ_WED_DATA_RING_BASE;
743*cbb3ec25SBjoern A. Zeeb } else {
744*cbb3ec25SBjoern A. Zeeb struct platform_device *plat_dev = pdev_ptr;
745*cbb3ec25SBjoern A. Zeeb struct resource *res;
746*cbb3ec25SBjoern A. Zeeb
747*cbb3ec25SBjoern A. Zeeb res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
748*cbb3ec25SBjoern A. Zeeb if (!res)
749*cbb3ec25SBjoern A. Zeeb return -ENOMEM;
750*cbb3ec25SBjoern A. Zeeb
751*cbb3ec25SBjoern A. Zeeb wed->wlan.platform_dev = plat_dev;
752*cbb3ec25SBjoern A. Zeeb wed->wlan.bus_type = MTK_WED_BUS_AXI;
753*cbb3ec25SBjoern A. Zeeb wed->wlan.base = devm_ioremap(dev->mt76.dev, res->start,
754*cbb3ec25SBjoern A. Zeeb resource_size(res));
755*cbb3ec25SBjoern A. Zeeb wed->wlan.phy_base = res->start;
756*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_int = res->start + MT_INT_SOURCE_CSR;
757*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_mask = res->start + MT_INT_MASK_CSR;
758*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_tx = res->start + MT_TXQ_WED_RING_BASE;
759*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_txfree = res->start + MT_RXQ_WED_RING_BASE;
760*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_rx_glo = res->start + MT_WPDMA_GLO_CFG;
761*cbb3ec25SBjoern A. Zeeb wed->wlan.wpdma_rx = res->start + MT_RXQ_WED_DATA_RING_BASE;
762*cbb3ec25SBjoern A. Zeeb }
763*cbb3ec25SBjoern A. Zeeb wed->wlan.nbuf = MT7915_HW_TOKEN_SIZE;
764*cbb3ec25SBjoern A. Zeeb wed->wlan.tx_tbit[0] = is_mt7915(&dev->mt76) ? 4 : 30;
765*cbb3ec25SBjoern A. Zeeb wed->wlan.tx_tbit[1] = is_mt7915(&dev->mt76) ? 5 : 31;
766*cbb3ec25SBjoern A. Zeeb wed->wlan.txfree_tbit = is_mt798x(&dev->mt76) ? 2 : 1;
767*cbb3ec25SBjoern A. Zeeb wed->wlan.token_start = MT7915_TOKEN_SIZE - wed->wlan.nbuf;
768*cbb3ec25SBjoern A. Zeeb wed->wlan.wcid_512 = !is_mt7915(&dev->mt76);
769*cbb3ec25SBjoern A. Zeeb
770*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_nbuf = 65536;
771*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_npkt = MT7915_WED_RX_TOKEN_SIZE;
772*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_size = SKB_WITH_OVERHEAD(MT_RX_BUF_SIZE);
773*cbb3ec25SBjoern A. Zeeb if (is_mt7915(&dev->mt76)) {
774*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[0] = 16;
775*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[1] = 17;
776*cbb3ec25SBjoern A. Zeeb } else if (is_mt798x(&dev->mt76)) {
777*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[0] = 22;
778*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[1] = 23;
779*cbb3ec25SBjoern A. Zeeb } else {
780*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[0] = 18;
781*cbb3ec25SBjoern A. Zeeb wed->wlan.rx_tbit[1] = 19;
782*cbb3ec25SBjoern A. Zeeb }
783*cbb3ec25SBjoern A. Zeeb
784*cbb3ec25SBjoern A. Zeeb wed->wlan.init_buf = mt7915_wed_init_buf;
785*cbb3ec25SBjoern A. Zeeb wed->wlan.offload_enable = mt7915_mmio_wed_offload_enable;
786*cbb3ec25SBjoern A. Zeeb wed->wlan.offload_disable = mt7915_mmio_wed_offload_disable;
787*cbb3ec25SBjoern A. Zeeb wed->wlan.init_rx_buf = mt7915_mmio_wed_init_rx_buf;
788*cbb3ec25SBjoern A. Zeeb wed->wlan.release_rx_buf = mt7915_mmio_wed_release_rx_buf;
789*cbb3ec25SBjoern A. Zeeb wed->wlan.update_wo_rx_stats = mt7915_mmio_wed_update_rx_stats;
790*cbb3ec25SBjoern A. Zeeb wed->wlan.reset = mt7915_mmio_wed_reset;
791*cbb3ec25SBjoern A. Zeeb wed->wlan.reset_complete = mt7915_mmio_wed_reset_complete;
792*cbb3ec25SBjoern A. Zeeb
793*cbb3ec25SBjoern A. Zeeb dev->mt76.rx_token_size = wed->wlan.rx_npkt;
794*cbb3ec25SBjoern A. Zeeb
795*cbb3ec25SBjoern A. Zeeb if (mtk_wed_device_attach(wed))
796*cbb3ec25SBjoern A. Zeeb return 0;
797*cbb3ec25SBjoern A. Zeeb
798*cbb3ec25SBjoern A. Zeeb *irq = wed->irq;
799*cbb3ec25SBjoern A. Zeeb dev->mt76.dma_dev = wed->dev;
800*cbb3ec25SBjoern A. Zeeb
801*cbb3ec25SBjoern A. Zeeb ret = dma_set_mask(wed->dev, DMA_BIT_MASK(32));
802*cbb3ec25SBjoern A. Zeeb if (ret)
803*cbb3ec25SBjoern A. Zeeb return ret;
804*cbb3ec25SBjoern A. Zeeb
805*cbb3ec25SBjoern A. Zeeb return 1;
806*cbb3ec25SBjoern A. Zeeb #else
807*cbb3ec25SBjoern A. Zeeb return 0;
808*cbb3ec25SBjoern A. Zeeb #endif
809*cbb3ec25SBjoern A. Zeeb }
810*cbb3ec25SBjoern A. Zeeb
mt7915_mmio_init(struct mt76_dev * mdev,void __iomem * mem_base,u32 device_id)8116c92544dSBjoern A. Zeeb static int mt7915_mmio_init(struct mt76_dev *mdev,
8126c92544dSBjoern A. Zeeb void __iomem *mem_base,
8136c92544dSBjoern A. Zeeb u32 device_id)
8146c92544dSBjoern A. Zeeb {
8156c92544dSBjoern A. Zeeb struct mt76_bus_ops *bus_ops;
8166c92544dSBjoern A. Zeeb struct mt7915_dev *dev;
8176c92544dSBjoern A. Zeeb
8186c92544dSBjoern A. Zeeb dev = container_of(mdev, struct mt7915_dev, mt76);
8196c92544dSBjoern A. Zeeb mt76_mmio_init(&dev->mt76, mem_base);
8206c92544dSBjoern A. Zeeb
8216c92544dSBjoern A. Zeeb switch (device_id) {
8226c92544dSBjoern A. Zeeb case 0x7915:
8236c92544dSBjoern A. Zeeb dev->reg.reg_rev = mt7915_reg;
8246c92544dSBjoern A. Zeeb dev->reg.offs_rev = mt7915_offs;
8256c92544dSBjoern A. Zeeb dev->reg.map = mt7915_reg_map;
8266c92544dSBjoern A. Zeeb dev->reg.map_size = ARRAY_SIZE(mt7915_reg_map);
8276c92544dSBjoern A. Zeeb break;
8286c92544dSBjoern A. Zeeb case 0x7906:
8296c92544dSBjoern A. Zeeb dev->reg.reg_rev = mt7916_reg;
8306c92544dSBjoern A. Zeeb dev->reg.offs_rev = mt7916_offs;
8316c92544dSBjoern A. Zeeb dev->reg.map = mt7916_reg_map;
8326c92544dSBjoern A. Zeeb dev->reg.map_size = ARRAY_SIZE(mt7916_reg_map);
8336c92544dSBjoern A. Zeeb break;
834*cbb3ec25SBjoern A. Zeeb case 0x7981:
8356c92544dSBjoern A. Zeeb case 0x7986:
8366c92544dSBjoern A. Zeeb dev->reg.reg_rev = mt7986_reg;
8376c92544dSBjoern A. Zeeb dev->reg.offs_rev = mt7916_offs;
8386c92544dSBjoern A. Zeeb dev->reg.map = mt7986_reg_map;
8396c92544dSBjoern A. Zeeb dev->reg.map_size = ARRAY_SIZE(mt7986_reg_map);
8406c92544dSBjoern A. Zeeb break;
8416c92544dSBjoern A. Zeeb default:
8426c92544dSBjoern A. Zeeb return -EINVAL;
8436c92544dSBjoern A. Zeeb }
8446c92544dSBjoern A. Zeeb
8456c92544dSBjoern A. Zeeb dev->bus_ops = dev->mt76.bus;
8466c92544dSBjoern A. Zeeb bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops),
8476c92544dSBjoern A. Zeeb GFP_KERNEL);
8486c92544dSBjoern A. Zeeb if (!bus_ops)
8496c92544dSBjoern A. Zeeb return -ENOMEM;
8506c92544dSBjoern A. Zeeb
8516c92544dSBjoern A. Zeeb bus_ops->rr = mt7915_rr;
8526c92544dSBjoern A. Zeeb bus_ops->wr = mt7915_wr;
8536c92544dSBjoern A. Zeeb bus_ops->rmw = mt7915_rmw;
8546c92544dSBjoern A. Zeeb dev->mt76.bus = bus_ops;
8556c92544dSBjoern A. Zeeb
8566c92544dSBjoern A. Zeeb mdev->rev = (device_id << 16) |
8576c92544dSBjoern A. Zeeb (mt76_rr(dev, MT_HW_REV) & 0xff);
8586c92544dSBjoern A. Zeeb dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev);
8596c92544dSBjoern A. Zeeb
8606c92544dSBjoern A. Zeeb return 0;
8616c92544dSBjoern A. Zeeb }
8626c92544dSBjoern A. Zeeb
mt7915_dual_hif_set_irq_mask(struct mt7915_dev * dev,bool write_reg,u32 clear,u32 set)8636c92544dSBjoern A. Zeeb void mt7915_dual_hif_set_irq_mask(struct mt7915_dev *dev,
8646c92544dSBjoern A. Zeeb bool write_reg,
8656c92544dSBjoern A. Zeeb u32 clear, u32 set)
8666c92544dSBjoern A. Zeeb {
8676c92544dSBjoern A. Zeeb struct mt76_dev *mdev = &dev->mt76;
8686c92544dSBjoern A. Zeeb unsigned long flags;
8696c92544dSBjoern A. Zeeb
8706c92544dSBjoern A. Zeeb spin_lock_irqsave(&mdev->mmio.irq_lock, flags);
8716c92544dSBjoern A. Zeeb
8726c92544dSBjoern A. Zeeb mdev->mmio.irqmask &= ~clear;
8736c92544dSBjoern A. Zeeb mdev->mmio.irqmask |= set;
8746c92544dSBjoern A. Zeeb
8756c92544dSBjoern A. Zeeb if (write_reg) {
876*cbb3ec25SBjoern A. Zeeb if (mtk_wed_device_active(&mdev->mmio.wed))
877*cbb3ec25SBjoern A. Zeeb mtk_wed_device_irq_set_mask(&mdev->mmio.wed,
878*cbb3ec25SBjoern A. Zeeb mdev->mmio.irqmask);
879*cbb3ec25SBjoern A. Zeeb else
8806c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT_MASK_CSR, mdev->mmio.irqmask);
8816c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT1_MASK_CSR, mdev->mmio.irqmask);
8826c92544dSBjoern A. Zeeb }
8836c92544dSBjoern A. Zeeb
8846c92544dSBjoern A. Zeeb spin_unlock_irqrestore(&mdev->mmio.irq_lock, flags);
8856c92544dSBjoern A. Zeeb }
8866c92544dSBjoern A. Zeeb
mt7915_rx_poll_complete(struct mt76_dev * mdev,enum mt76_rxq_id q)8876c92544dSBjoern A. Zeeb static void mt7915_rx_poll_complete(struct mt76_dev *mdev,
8886c92544dSBjoern A. Zeeb enum mt76_rxq_id q)
8896c92544dSBjoern A. Zeeb {
8906c92544dSBjoern A. Zeeb struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
8916c92544dSBjoern A. Zeeb
8926c92544dSBjoern A. Zeeb mt7915_irq_enable(dev, MT_INT_RX(q));
8936c92544dSBjoern A. Zeeb }
8946c92544dSBjoern A. Zeeb
8956c92544dSBjoern A. Zeeb /* TODO: support 2/4/6/8 MSI-X vectors */
mt7915_irq_tasklet(struct tasklet_struct * t)8966c92544dSBjoern A. Zeeb static void mt7915_irq_tasklet(struct tasklet_struct *t)
8976c92544dSBjoern A. Zeeb {
898*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev = from_tasklet(dev, t, mt76.irq_tasklet);
8996c92544dSBjoern A. Zeeb struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
9006c92544dSBjoern A. Zeeb u32 intr, intr1, mask;
9016c92544dSBjoern A. Zeeb
9026c92544dSBjoern A. Zeeb if (mtk_wed_device_active(wed)) {
9036c92544dSBjoern A. Zeeb mtk_wed_device_irq_set_mask(wed, 0);
904*cbb3ec25SBjoern A. Zeeb if (dev->hif2)
905*cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_INT1_MASK_CSR, 0);
9066c92544dSBjoern A. Zeeb intr = mtk_wed_device_irq_get(wed, dev->mt76.mmio.irqmask);
9076c92544dSBjoern A. Zeeb } else {
9086c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT_MASK_CSR, 0);
9096c92544dSBjoern A. Zeeb if (dev->hif2)
9106c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT1_MASK_CSR, 0);
9116c92544dSBjoern A. Zeeb
9126c92544dSBjoern A. Zeeb intr = mt76_rr(dev, MT_INT_SOURCE_CSR);
9136c92544dSBjoern A. Zeeb intr &= dev->mt76.mmio.irqmask;
9146c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT_SOURCE_CSR, intr);
9156c92544dSBjoern A. Zeeb }
9166c92544dSBjoern A. Zeeb
9176c92544dSBjoern A. Zeeb if (dev->hif2) {
9186c92544dSBjoern A. Zeeb intr1 = mt76_rr(dev, MT_INT1_SOURCE_CSR);
9196c92544dSBjoern A. Zeeb intr1 &= dev->mt76.mmio.irqmask;
9206c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT1_SOURCE_CSR, intr1);
9216c92544dSBjoern A. Zeeb
9226c92544dSBjoern A. Zeeb intr |= intr1;
9236c92544dSBjoern A. Zeeb }
9246c92544dSBjoern A. Zeeb
9256c92544dSBjoern A. Zeeb trace_dev_irq(&dev->mt76, intr, dev->mt76.mmio.irqmask);
9266c92544dSBjoern A. Zeeb
9276c92544dSBjoern A. Zeeb mask = intr & MT_INT_RX_DONE_ALL;
9286c92544dSBjoern A. Zeeb if (intr & MT_INT_TX_DONE_MCU)
9296c92544dSBjoern A. Zeeb mask |= MT_INT_TX_DONE_MCU;
9306c92544dSBjoern A. Zeeb
9316c92544dSBjoern A. Zeeb mt7915_irq_disable(dev, mask);
9326c92544dSBjoern A. Zeeb
9336c92544dSBjoern A. Zeeb if (intr & MT_INT_TX_DONE_MCU)
9346c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.tx_napi);
9356c92544dSBjoern A. Zeeb
9366c92544dSBjoern A. Zeeb if (intr & MT_INT_RX(MT_RXQ_MAIN))
9376c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]);
9386c92544dSBjoern A. Zeeb
9396c92544dSBjoern A. Zeeb if (intr & MT_INT_RX(MT_RXQ_BAND1))
9406c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_BAND1]);
9416c92544dSBjoern A. Zeeb
9426c92544dSBjoern A. Zeeb if (intr & MT_INT_RX(MT_RXQ_MCU))
9436c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_MCU]);
9446c92544dSBjoern A. Zeeb
9456c92544dSBjoern A. Zeeb if (intr & MT_INT_RX(MT_RXQ_MCU_WA))
9466c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_MCU_WA]);
9476c92544dSBjoern A. Zeeb
9486c92544dSBjoern A. Zeeb if (!is_mt7915(&dev->mt76) &&
9496c92544dSBjoern A. Zeeb (intr & MT_INT_RX(MT_RXQ_MAIN_WA)))
9506c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN_WA]);
9516c92544dSBjoern A. Zeeb
9526c92544dSBjoern A. Zeeb if (intr & MT_INT_RX(MT_RXQ_BAND1_WA))
9536c92544dSBjoern A. Zeeb napi_schedule(&dev->mt76.napi[MT_RXQ_BAND1_WA]);
9546c92544dSBjoern A. Zeeb
9556c92544dSBjoern A. Zeeb if (intr & MT_INT_MCU_CMD) {
9566c92544dSBjoern A. Zeeb u32 val = mt76_rr(dev, MT_MCU_CMD);
9576c92544dSBjoern A. Zeeb
9586c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MCU_CMD, val);
959*cbb3ec25SBjoern A. Zeeb if (val & (MT_MCU_CMD_ERROR_MASK | MT_MCU_CMD_WDT_MASK)) {
960*cbb3ec25SBjoern A. Zeeb dev->recovery.state = val;
961*cbb3ec25SBjoern A. Zeeb mt7915_reset(dev);
9626c92544dSBjoern A. Zeeb }
9636c92544dSBjoern A. Zeeb }
9646c92544dSBjoern A. Zeeb }
9656c92544dSBjoern A. Zeeb
mt7915_irq_handler(int irq,void * dev_instance)9666c92544dSBjoern A. Zeeb irqreturn_t mt7915_irq_handler(int irq, void *dev_instance)
9676c92544dSBjoern A. Zeeb {
9686c92544dSBjoern A. Zeeb struct mt7915_dev *dev = dev_instance;
9696c92544dSBjoern A. Zeeb struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
9706c92544dSBjoern A. Zeeb
971*cbb3ec25SBjoern A. Zeeb if (mtk_wed_device_active(wed))
9726c92544dSBjoern A. Zeeb mtk_wed_device_irq_set_mask(wed, 0);
973*cbb3ec25SBjoern A. Zeeb else
9746c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT_MASK_CSR, 0);
975*cbb3ec25SBjoern A. Zeeb
9766c92544dSBjoern A. Zeeb if (dev->hif2)
9776c92544dSBjoern A. Zeeb mt76_wr(dev, MT_INT1_MASK_CSR, 0);
9786c92544dSBjoern A. Zeeb
9796c92544dSBjoern A. Zeeb if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state))
9806c92544dSBjoern A. Zeeb return IRQ_NONE;
9816c92544dSBjoern A. Zeeb
982*cbb3ec25SBjoern A. Zeeb tasklet_schedule(&dev->mt76.irq_tasklet);
9836c92544dSBjoern A. Zeeb
9846c92544dSBjoern A. Zeeb return IRQ_HANDLED;
9856c92544dSBjoern A. Zeeb }
9866c92544dSBjoern A. Zeeb
mt7915_mmio_probe(struct device * pdev,void __iomem * mem_base,u32 device_id)9876c92544dSBjoern A. Zeeb struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
9886c92544dSBjoern A. Zeeb void __iomem *mem_base, u32 device_id)
9896c92544dSBjoern A. Zeeb {
9906c92544dSBjoern A. Zeeb static const struct mt76_driver_ops drv_ops = {
9916c92544dSBjoern A. Zeeb /* txwi_size = txd size + txp size */
9926c92544dSBjoern A. Zeeb .txwi_size = MT_TXD_SIZE + sizeof(struct mt76_connac_fw_txp),
993*cbb3ec25SBjoern A. Zeeb .drv_flags = MT_DRV_TXWI_NO_FREE | MT_DRV_HW_MGMT_TXQ |
994*cbb3ec25SBjoern A. Zeeb MT_DRV_AMSDU_OFFLOAD,
9956c92544dSBjoern A. Zeeb .survey_flags = SURVEY_INFO_TIME_TX |
9966c92544dSBjoern A. Zeeb SURVEY_INFO_TIME_RX |
9976c92544dSBjoern A. Zeeb SURVEY_INFO_TIME_BSS_RX,
9986c92544dSBjoern A. Zeeb .token_size = MT7915_TOKEN_SIZE,
9996c92544dSBjoern A. Zeeb .tx_prepare_skb = mt7915_tx_prepare_skb,
10006c92544dSBjoern A. Zeeb .tx_complete_skb = mt76_connac_tx_complete_skb,
10016c92544dSBjoern A. Zeeb .rx_skb = mt7915_queue_rx_skb,
10026c92544dSBjoern A. Zeeb .rx_check = mt7915_rx_check,
10036c92544dSBjoern A. Zeeb .rx_poll_complete = mt7915_rx_poll_complete,
10046c92544dSBjoern A. Zeeb .sta_add = mt7915_mac_sta_add,
10056c92544dSBjoern A. Zeeb .sta_remove = mt7915_mac_sta_remove,
10066c92544dSBjoern A. Zeeb .update_survey = mt7915_update_channel,
10076c92544dSBjoern A. Zeeb };
10086c92544dSBjoern A. Zeeb struct mt7915_dev *dev;
10096c92544dSBjoern A. Zeeb struct mt76_dev *mdev;
10106c92544dSBjoern A. Zeeb int ret;
10116c92544dSBjoern A. Zeeb
10126c92544dSBjoern A. Zeeb mdev = mt76_alloc_device(pdev, sizeof(*dev), &mt7915_ops, &drv_ops);
10136c92544dSBjoern A. Zeeb if (!mdev)
10146c92544dSBjoern A. Zeeb return ERR_PTR(-ENOMEM);
10156c92544dSBjoern A. Zeeb
10166c92544dSBjoern A. Zeeb dev = container_of(mdev, struct mt7915_dev, mt76);
10176c92544dSBjoern A. Zeeb
10186c92544dSBjoern A. Zeeb ret = mt7915_mmio_init(mdev, mem_base, device_id);
10196c92544dSBjoern A. Zeeb if (ret)
10206c92544dSBjoern A. Zeeb goto error;
10216c92544dSBjoern A. Zeeb
1022*cbb3ec25SBjoern A. Zeeb tasklet_setup(&mdev->irq_tasklet, mt7915_irq_tasklet);
10236c92544dSBjoern A. Zeeb
10246c92544dSBjoern A. Zeeb return dev;
10256c92544dSBjoern A. Zeeb
10266c92544dSBjoern A. Zeeb error:
10276c92544dSBjoern A. Zeeb mt76_free_device(&dev->mt76);
10286c92544dSBjoern A. Zeeb
10296c92544dSBjoern A. Zeeb return ERR_PTR(ret);
10306c92544dSBjoern A. Zeeb }
10316c92544dSBjoern A. Zeeb
mt7915_init(void)10326c92544dSBjoern A. Zeeb static int __init mt7915_init(void)
10336c92544dSBjoern A. Zeeb {
10346c92544dSBjoern A. Zeeb int ret;
10356c92544dSBjoern A. Zeeb
10366c92544dSBjoern A. Zeeb ret = pci_register_driver(&mt7915_hif_driver);
10376c92544dSBjoern A. Zeeb if (ret)
10386c92544dSBjoern A. Zeeb return ret;
10396c92544dSBjoern A. Zeeb
10406c92544dSBjoern A. Zeeb ret = pci_register_driver(&mt7915_pci_driver);
10416c92544dSBjoern A. Zeeb if (ret)
10426c92544dSBjoern A. Zeeb goto error_pci;
10436c92544dSBjoern A. Zeeb
1044*cbb3ec25SBjoern A. Zeeb if (IS_ENABLED(CONFIG_MT798X_WMAC)) {
1045*cbb3ec25SBjoern A. Zeeb ret = platform_driver_register(&mt798x_wmac_driver);
10466c92544dSBjoern A. Zeeb if (ret)
10476c92544dSBjoern A. Zeeb goto error_wmac;
10486c92544dSBjoern A. Zeeb }
10496c92544dSBjoern A. Zeeb
10506c92544dSBjoern A. Zeeb return 0;
10516c92544dSBjoern A. Zeeb
10526c92544dSBjoern A. Zeeb error_wmac:
10536c92544dSBjoern A. Zeeb pci_unregister_driver(&mt7915_pci_driver);
10546c92544dSBjoern A. Zeeb error_pci:
10556c92544dSBjoern A. Zeeb pci_unregister_driver(&mt7915_hif_driver);
10566c92544dSBjoern A. Zeeb
10576c92544dSBjoern A. Zeeb return ret;
10586c92544dSBjoern A. Zeeb }
10596c92544dSBjoern A. Zeeb
mt7915_exit(void)10606c92544dSBjoern A. Zeeb static void __exit mt7915_exit(void)
10616c92544dSBjoern A. Zeeb {
1062*cbb3ec25SBjoern A. Zeeb if (IS_ENABLED(CONFIG_MT798X_WMAC))
1063*cbb3ec25SBjoern A. Zeeb platform_driver_unregister(&mt798x_wmac_driver);
10646c92544dSBjoern A. Zeeb
10656c92544dSBjoern A. Zeeb pci_unregister_driver(&mt7915_pci_driver);
10666c92544dSBjoern A. Zeeb pci_unregister_driver(&mt7915_hif_driver);
10676c92544dSBjoern A. Zeeb }
10686c92544dSBjoern A. Zeeb
10696c92544dSBjoern A. Zeeb module_init(mt7915_init);
10706c92544dSBjoern A. Zeeb module_exit(mt7915_exit);
10716c92544dSBjoern A. Zeeb MODULE_LICENSE("Dual BSD/GPL");
1072