1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #include <linux/kernel.h> 5 #include <linux/module.h> 6 #include <linux/platform_device.h> 7 #include <linux/pci.h> 8 9 #include "mt7915.h" 10 #include "mac.h" 11 #include "../trace.h" 12 #include "../dma.h" 13 14 static bool wed_enable; 15 module_param(wed_enable, bool, 0644); 16 MODULE_PARM_DESC(wed_enable, "Enable Wireless Ethernet Dispatch support"); 17 18 static const u32 mt7915_reg[] = { 19 [INT_SOURCE_CSR] = 0xd7010, 20 [INT_MASK_CSR] = 0xd7014, 21 [INT1_SOURCE_CSR] = 0xd7088, 22 [INT1_MASK_CSR] = 0xd708c, 23 [INT_MCU_CMD_SOURCE] = 0xd51f0, 24 [INT_MCU_CMD_EVENT] = 0x3108, 25 [WFDMA0_ADDR] = 0xd4000, 26 [WFDMA0_PCIE1_ADDR] = 0xd8000, 27 [WFDMA_EXT_CSR_ADDR] = 0xd7000, 28 [CBTOP1_PHY_END] = 0x77ffffff, 29 [INFRA_MCU_ADDR_END] = 0x7c3fffff, 30 [FW_ASSERT_STAT_ADDR] = 0x219848, 31 [FW_EXCEPT_TYPE_ADDR] = 0x21987c, 32 [FW_EXCEPT_COUNT_ADDR] = 0x219848, 33 [FW_CIRQ_COUNT_ADDR] = 0x216f94, 34 [FW_CIRQ_IDX_ADDR] = 0x216ef8, 35 [FW_CIRQ_LISR_ADDR] = 0x2170ac, 36 [FW_TASK_ID_ADDR] = 0x216f90, 37 [FW_TASK_IDX_ADDR] = 0x216f9c, 38 [FW_TASK_QID1_ADDR] = 0x219680, 39 [FW_TASK_QID2_ADDR] = 0x219760, 40 [FW_TASK_START_ADDR] = 0x219558, 41 [FW_TASK_END_ADDR] = 0x219554, 42 [FW_TASK_SIZE_ADDR] = 0x219560, 43 [FW_LAST_MSG_ID_ADDR] = 0x216f70, 44 [FW_EINT_INFO_ADDR] = 0x219818, 45 [FW_SCHED_INFO_ADDR] = 0x219828, 46 [SWDEF_BASE_ADDR] = 0x41f200, 47 [TXQ_WED_RING_BASE] = 0xd7300, 48 [RXQ_WED_RING_BASE] = 0xd7410, 49 [RXQ_WED_DATA_RING_BASE] = 0xd4500, 50 }; 51 52 static const u32 mt7916_reg[] = { 53 [INT_SOURCE_CSR] = 0xd4200, 54 [INT_MASK_CSR] = 0xd4204, 55 [INT1_SOURCE_CSR] = 0xd8200, 56 [INT1_MASK_CSR] = 0xd8204, 57 [INT_MCU_CMD_SOURCE] = 0xd41f0, 58 [INT_MCU_CMD_EVENT] = 0x2108, 59 [WFDMA0_ADDR] = 0xd4000, 60 [WFDMA0_PCIE1_ADDR] = 0xd8000, 61 [WFDMA_EXT_CSR_ADDR] = 0xd7000, 62 [CBTOP1_PHY_END] = 0x7fffffff, 63 [INFRA_MCU_ADDR_END] = 0x7c085fff, 64 [FW_ASSERT_STAT_ADDR] = 0x02204c14, 65 [FW_EXCEPT_TYPE_ADDR] = 0x022051a4, 66 [FW_EXCEPT_COUNT_ADDR] = 0x022050bc, 67 [FW_CIRQ_COUNT_ADDR] = 0x022001ac, 68 [FW_CIRQ_IDX_ADDR] = 0x02204f84, 69 [FW_CIRQ_LISR_ADDR] = 0x022050d0, 70 [FW_TASK_ID_ADDR] = 0x0220406c, 71 [FW_TASK_IDX_ADDR] = 0x0220500c, 72 [FW_TASK_QID1_ADDR] = 0x022028c8, 73 [FW_TASK_QID2_ADDR] = 0x02202a38, 74 [FW_TASK_START_ADDR] = 0x0220286c, 75 [FW_TASK_END_ADDR] = 0x02202870, 76 [FW_TASK_SIZE_ADDR] = 0x02202878, 77 [FW_LAST_MSG_ID_ADDR] = 0x02204fe8, 78 [FW_EINT_INFO_ADDR] = 0x0220525c, 79 [FW_SCHED_INFO_ADDR] = 0x0220516c, 80 [SWDEF_BASE_ADDR] = 0x411400, 81 [TXQ_WED_RING_BASE] = 0xd7300, 82 [RXQ_WED_RING_BASE] = 0xd7410, 83 [RXQ_WED_DATA_RING_BASE] = 0xd4540, 84 }; 85 86 static const u32 mt7986_reg[] = { 87 [INT_SOURCE_CSR] = 0x24200, 88 [INT_MASK_CSR] = 0x24204, 89 [INT1_SOURCE_CSR] = 0x28200, 90 [INT1_MASK_CSR] = 0x28204, 91 [INT_MCU_CMD_SOURCE] = 0x241f0, 92 [INT_MCU_CMD_EVENT] = 0x54000108, 93 [WFDMA0_ADDR] = 0x24000, 94 [WFDMA0_PCIE1_ADDR] = 0x28000, 95 [WFDMA_EXT_CSR_ADDR] = 0x27000, 96 [CBTOP1_PHY_END] = 0x7fffffff, 97 [INFRA_MCU_ADDR_END] = 0x7c085fff, 98 [FW_ASSERT_STAT_ADDR] = 0x02204b54, 99 [FW_EXCEPT_TYPE_ADDR] = 0x022050dc, 100 [FW_EXCEPT_COUNT_ADDR] = 0x02204ffc, 101 [FW_CIRQ_COUNT_ADDR] = 0x022001ac, 102 [FW_CIRQ_IDX_ADDR] = 0x02204ec4, 103 [FW_CIRQ_LISR_ADDR] = 0x02205010, 104 [FW_TASK_ID_ADDR] = 0x02204fac, 105 [FW_TASK_IDX_ADDR] = 0x02204f4c, 106 [FW_TASK_QID1_ADDR] = 0x02202814, 107 [FW_TASK_QID2_ADDR] = 0x02202984, 108 [FW_TASK_START_ADDR] = 0x022027b8, 109 [FW_TASK_END_ADDR] = 0x022027bc, 110 [FW_TASK_SIZE_ADDR] = 0x022027c4, 111 [FW_LAST_MSG_ID_ADDR] = 0x02204f28, 112 [FW_EINT_INFO_ADDR] = 0x02205194, 113 [FW_SCHED_INFO_ADDR] = 0x022051a4, 114 [SWDEF_BASE_ADDR] = 0x411400, 115 [TXQ_WED_RING_BASE] = 0x24420, 116 [RXQ_WED_RING_BASE] = 0x24520, 117 [RXQ_WED_DATA_RING_BASE] = 0x24540, 118 }; 119 120 static const u32 mt7915_offs[] = { 121 [TMAC_CDTR] = 0x090, 122 [TMAC_ODTR] = 0x094, 123 [TMAC_ATCR] = 0x098, 124 [TMAC_TRCR0] = 0x09c, 125 [TMAC_ICR0] = 0x0a4, 126 [TMAC_ICR1] = 0x0b4, 127 [TMAC_CTCR0] = 0x0f4, 128 [TMAC_TFCR0] = 0x1e0, 129 [MDP_BNRCFR0] = 0x070, 130 [MDP_BNRCFR1] = 0x074, 131 [ARB_DRNGR0] = 0x194, 132 [ARB_SCR] = 0x080, 133 [RMAC_MIB_AIRTIME14] = 0x3b8, 134 [AGG_AWSCR0] = 0x05c, 135 [AGG_PCR0] = 0x06c, 136 [AGG_ACR0] = 0x084, 137 [AGG_ACR4] = 0x08c, 138 [AGG_MRCR] = 0x098, 139 [AGG_ATCR1] = 0x0f0, 140 [AGG_ATCR3] = 0x0f4, 141 [LPON_UTTR0] = 0x080, 142 [LPON_UTTR1] = 0x084, 143 [LPON_FRCR] = 0x314, 144 [MIB_SDR3] = 0x014, 145 [MIB_SDR4] = 0x018, 146 [MIB_SDR5] = 0x01c, 147 [MIB_SDR7] = 0x024, 148 [MIB_SDR8] = 0x028, 149 [MIB_SDR9] = 0x02c, 150 [MIB_SDR10] = 0x030, 151 [MIB_SDR11] = 0x034, 152 [MIB_SDR12] = 0x038, 153 [MIB_SDR13] = 0x03c, 154 [MIB_SDR14] = 0x040, 155 [MIB_SDR15] = 0x044, 156 [MIB_SDR16] = 0x048, 157 [MIB_SDR17] = 0x04c, 158 [MIB_SDR18] = 0x050, 159 [MIB_SDR19] = 0x054, 160 [MIB_SDR20] = 0x058, 161 [MIB_SDR21] = 0x05c, 162 [MIB_SDR22] = 0x060, 163 [MIB_SDR23] = 0x064, 164 [MIB_SDR24] = 0x068, 165 [MIB_SDR25] = 0x06c, 166 [MIB_SDR27] = 0x074, 167 [MIB_SDR28] = 0x078, 168 [MIB_SDR29] = 0x07c, 169 [MIB_SDRVEC] = 0x080, 170 [MIB_SDR31] = 0x084, 171 [MIB_SDR32] = 0x088, 172 [MIB_SDRMUBF] = 0x090, 173 [MIB_DR8] = 0x0c0, 174 [MIB_DR9] = 0x0c4, 175 [MIB_DR11] = 0x0cc, 176 [MIB_MB_SDR0] = 0x100, 177 [MIB_MB_SDR1] = 0x104, 178 [TX_AGG_CNT] = 0x0a8, 179 [TX_AGG_CNT2] = 0x164, 180 [MIB_ARNG] = 0x4b8, 181 [WTBLON_TOP_WDUCR] = 0x0, 182 [WTBL_UPDATE] = 0x030, 183 [PLE_FL_Q_EMPTY] = 0x0b0, 184 [PLE_FL_Q_CTRL] = 0x1b0, 185 [PLE_AC_QEMPTY] = 0x500, 186 [PLE_FREEPG_CNT] = 0x100, 187 [PLE_FREEPG_HEAD_TAIL] = 0x104, 188 [PLE_PG_HIF_GROUP] = 0x110, 189 [PLE_HIF_PG_INFO] = 0x114, 190 [AC_OFFSET] = 0x040, 191 [ETBF_PAR_RPT0] = 0x068, 192 }; 193 194 static const u32 mt7916_offs[] = { 195 [TMAC_CDTR] = 0x0c8, 196 [TMAC_ODTR] = 0x0cc, 197 [TMAC_ATCR] = 0x00c, 198 [TMAC_TRCR0] = 0x010, 199 [TMAC_ICR0] = 0x014, 200 [TMAC_ICR1] = 0x018, 201 [TMAC_CTCR0] = 0x114, 202 [TMAC_TFCR0] = 0x0e4, 203 [MDP_BNRCFR0] = 0x090, 204 [MDP_BNRCFR1] = 0x094, 205 [ARB_DRNGR0] = 0x1e0, 206 [ARB_SCR] = 0x000, 207 [RMAC_MIB_AIRTIME14] = 0x0398, 208 [AGG_AWSCR0] = 0x030, 209 [AGG_PCR0] = 0x040, 210 [AGG_ACR0] = 0x054, 211 [AGG_ACR4] = 0x05c, 212 [AGG_MRCR] = 0x068, 213 [AGG_ATCR1] = 0x1a8, 214 [AGG_ATCR3] = 0x080, 215 [LPON_UTTR0] = 0x360, 216 [LPON_UTTR1] = 0x364, 217 [LPON_FRCR] = 0x37c, 218 [MIB_SDR3] = 0x698, 219 [MIB_SDR4] = 0x788, 220 [MIB_SDR5] = 0x780, 221 [MIB_SDR7] = 0x5a8, 222 [MIB_SDR8] = 0x78c, 223 [MIB_SDR9] = 0x024, 224 [MIB_SDR10] = 0x76c, 225 [MIB_SDR11] = 0x790, 226 [MIB_SDR12] = 0x558, 227 [MIB_SDR13] = 0x560, 228 [MIB_SDR14] = 0x564, 229 [MIB_SDR15] = 0x568, 230 [MIB_SDR16] = 0x7fc, 231 [MIB_SDR17] = 0x800, 232 [MIB_SDR18] = 0x030, 233 [MIB_SDR19] = 0x5ac, 234 [MIB_SDR20] = 0x5b0, 235 [MIB_SDR21] = 0x5b4, 236 [MIB_SDR22] = 0x770, 237 [MIB_SDR23] = 0x774, 238 [MIB_SDR24] = 0x778, 239 [MIB_SDR25] = 0x77c, 240 [MIB_SDR27] = 0x080, 241 [MIB_SDR28] = 0x084, 242 [MIB_SDR29] = 0x650, 243 [MIB_SDRVEC] = 0x5a8, 244 [MIB_SDR31] = 0x55c, 245 [MIB_SDR32] = 0x7a8, 246 [MIB_SDRMUBF] = 0x7ac, 247 [MIB_DR8] = 0x56c, 248 [MIB_DR9] = 0x570, 249 [MIB_DR11] = 0x574, 250 [MIB_MB_SDR0] = 0x688, 251 [MIB_MB_SDR1] = 0x690, 252 [TX_AGG_CNT] = 0x7dc, 253 [TX_AGG_CNT2] = 0x7ec, 254 [MIB_ARNG] = 0x0b0, 255 [WTBLON_TOP_WDUCR] = 0x200, 256 [WTBL_UPDATE] = 0x230, 257 [PLE_FL_Q_EMPTY] = 0x360, 258 [PLE_FL_Q_CTRL] = 0x3e0, 259 [PLE_AC_QEMPTY] = 0x600, 260 [PLE_FREEPG_CNT] = 0x380, 261 [PLE_FREEPG_HEAD_TAIL] = 0x384, 262 [PLE_PG_HIF_GROUP] = 0x00c, 263 [PLE_HIF_PG_INFO] = 0x388, 264 [AC_OFFSET] = 0x080, 265 [ETBF_PAR_RPT0] = 0x100, 266 }; 267 268 static const struct mt76_connac_reg_map mt7915_reg_map[] = { 269 { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */ 270 { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure regs) */ 271 { 0x40000000, 0x70000, 0x10000 }, /* WF_UMAC_SYSRAM */ 272 { 0x54000000, 0x02000, 0x01000 }, /* WFDMA PCIE0 MCU DMA0 */ 273 { 0x55000000, 0x03000, 0x01000 }, /* WFDMA PCIE0 MCU DMA1 */ 274 { 0x58000000, 0x06000, 0x01000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ 275 { 0x59000000, 0x07000, 0x01000 }, /* WFDMA PCIE1 MCU DMA1 */ 276 { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ 277 { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ 278 { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ 279 { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ 280 { 0x820c0000, 0x08000, 0x04000 }, /* WF_UMAC_TOP (PLE) */ 281 { 0x820c8000, 0x0c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */ 282 { 0x820cc000, 0x0e000, 0x02000 }, /* WF_UMAC_TOP (PP) */ 283 { 0x820ce000, 0x21c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */ 284 { 0x820cf000, 0x22000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */ 285 { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ 286 { 0x820e0000, 0x20000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ 287 { 0x820e1000, 0x20400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ 288 { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ 289 { 0x820e3000, 0x20c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ 290 { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ 291 { 0x820e5000, 0x21400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ 292 { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ 293 { 0x820e9000, 0x23400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ 294 { 0x820ea000, 0x24000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ 295 { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ 296 { 0x820ec000, 0x24600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ 297 { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ 298 { 0x820f0000, 0xa0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ 299 { 0x820f1000, 0xa0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ 300 { 0x820f2000, 0xa0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ 301 { 0x820f3000, 0xa0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ 302 { 0x820f4000, 0xa1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ 303 { 0x820f5000, 0xa1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ 304 { 0x820f7000, 0xa1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ 305 { 0x820f9000, 0xa3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ 306 { 0x820fa000, 0xa4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ 307 { 0x820fb000, 0xa4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ 308 { 0x820fc000, 0xa4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ 309 { 0x820fd000, 0xa4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ 310 { 0x0, 0x0, 0x0 }, /* imply end of search */ 311 }; 312 313 static const struct mt76_connac_reg_map mt7916_reg_map[] = { 314 { 0x54000000, 0x02000, 0x01000 }, /* WFDMA_0 (PCIE0 MCU DMA0) */ 315 { 0x55000000, 0x03000, 0x01000 }, /* WFDMA_1 (PCIE0 MCU DMA1) */ 316 { 0x56000000, 0x04000, 0x01000 }, /* WFDMA_2 (Reserved) */ 317 { 0x57000000, 0x05000, 0x01000 }, /* WFDMA_3 (MCU wrap CR) */ 318 { 0x58000000, 0x06000, 0x01000 }, /* WFDMA_4 (PCIE1 MCU DMA0) */ 319 { 0x59000000, 0x07000, 0x01000 }, /* WFDMA_5 (PCIE1 MCU DMA1) */ 320 { 0x820c0000, 0x08000, 0x04000 }, /* WF_UMAC_TOP (PLE) */ 321 { 0x820c8000, 0x0c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */ 322 { 0x820cc000, 0x0e000, 0x02000 }, /* WF_UMAC_TOP (PP) */ 323 { 0x820e0000, 0x20000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ 324 { 0x820e1000, 0x20400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ 325 { 0x820e2000, 0x20800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ 326 { 0x820e3000, 0x20c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ 327 { 0x820e4000, 0x21000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ 328 { 0x820e5000, 0x21400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ 329 { 0x820ce000, 0x21c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */ 330 { 0x820e7000, 0x21e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ 331 { 0x820cf000, 0x22000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */ 332 { 0x820e9000, 0x23400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ 333 { 0x820ea000, 0x24000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ 334 { 0x820eb000, 0x24200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ 335 { 0x820ec000, 0x24600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ 336 { 0x820ed000, 0x24800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ 337 { 0x820ca000, 0x26000, 0x02000 }, /* WF_LMAC_TOP BN0 (WF_MUCOP) */ 338 { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ 339 { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */ 340 { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure cr) */ 341 { 0x820f0000, 0xa0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ 342 { 0x820f1000, 0xa0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ 343 { 0x820f2000, 0xa0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ 344 { 0x820f3000, 0xa0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ 345 { 0x820f4000, 0xa1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ 346 { 0x820f5000, 0xa1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ 347 { 0x820f7000, 0xa1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ 348 { 0x820f9000, 0xa3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ 349 { 0x820fa000, 0xa4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ 350 { 0x820fb000, 0xa4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ 351 { 0x820fc000, 0xa4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ 352 { 0x820fd000, 0xa4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ 353 { 0x820c4000, 0xa8000, 0x01000 }, /* WF_LMAC_TOP (WF_UWTBL ) */ 354 { 0x820b0000, 0xae000, 0x01000 }, /* [APB2] WFSYS_ON */ 355 { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ 356 { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ 357 { 0x0, 0x0, 0x0 }, /* imply end of search */ 358 }; 359 360 static const struct mt76_connac_reg_map mt7986_reg_map[] = { 361 { 0x54000000, 0x402000, 0x01000 }, /* WFDMA_0 (PCIE0 MCU DMA0) */ 362 { 0x55000000, 0x403000, 0x01000 }, /* WFDMA_1 (PCIE0 MCU DMA1) */ 363 { 0x56000000, 0x404000, 0x01000 }, /* WFDMA_2 (Reserved) */ 364 { 0x57000000, 0x405000, 0x01000 }, /* WFDMA_3 (MCU wrap CR) */ 365 { 0x58000000, 0x406000, 0x01000 }, /* WFDMA_4 (PCIE1 MCU DMA0) */ 366 { 0x59000000, 0x407000, 0x01000 }, /* WFDMA_5 (PCIE1 MCU DMA1) */ 367 { 0x820c0000, 0x408000, 0x04000 }, /* WF_UMAC_TOP (PLE) */ 368 { 0x820c8000, 0x40c000, 0x02000 }, /* WF_UMAC_TOP (PSE) */ 369 { 0x820cc000, 0x40e000, 0x02000 }, /* WF_UMAC_TOP (PP) */ 370 { 0x820e0000, 0x420000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ 371 { 0x820e1000, 0x420400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ 372 { 0x820e2000, 0x420800, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ 373 { 0x820e3000, 0x420c00, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ 374 { 0x820e4000, 0x421000, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ 375 { 0x820e5000, 0x421400, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ 376 { 0x820ce000, 0x421c00, 0x00200 }, /* WF_LMAC_TOP (WF_SEC) */ 377 { 0x820e7000, 0x421e00, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ 378 { 0x820cf000, 0x422000, 0x01000 }, /* WF_LMAC_TOP (WF_PF) */ 379 { 0x820e9000, 0x423400, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ 380 { 0x820ea000, 0x424000, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ 381 { 0x820eb000, 0x424200, 0x00400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ 382 { 0x820ec000, 0x424600, 0x00200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ 383 { 0x820ed000, 0x424800, 0x00800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ 384 { 0x820ca000, 0x426000, 0x02000 }, /* WF_LMAC_TOP BN0 (WF_MUCOP) */ 385 { 0x820d0000, 0x430000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ 386 { 0x00400000, 0x480000, 0x10000 }, /* WF_MCU_SYSRAM */ 387 { 0x00410000, 0x490000, 0x10000 }, /* WF_MCU_SYSRAM */ 388 { 0x820f0000, 0x4a0000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ 389 { 0x820f1000, 0x4a0600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ 390 { 0x820f2000, 0x4a0800, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ 391 { 0x820f3000, 0x4a0c00, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ 392 { 0x820f4000, 0x4a1000, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ 393 { 0x820f5000, 0x4a1400, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ 394 { 0x820f7000, 0x4a1e00, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ 395 { 0x820f9000, 0x4a3400, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ 396 { 0x820fa000, 0x4a4000, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ 397 { 0x820fb000, 0x4a4200, 0x00400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ 398 { 0x820fc000, 0x4a4600, 0x00200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ 399 { 0x820fd000, 0x4a4800, 0x00800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ 400 { 0x820c4000, 0x4a8000, 0x01000 }, /* WF_LMAC_TOP (WF_UWTBL ) */ 401 { 0x820b0000, 0x4ae000, 0x01000 }, /* [APB2] WFSYS_ON */ 402 { 0x80020000, 0x4b0000, 0x10000 }, /* WF_TOP_MISC_OFF */ 403 { 0x81020000, 0x4c0000, 0x10000 }, /* WF_TOP_MISC_ON */ 404 { 0x89000000, 0x4d0000, 0x01000 }, /* WF_MCU_CFG_ON */ 405 { 0x89010000, 0x4d1000, 0x01000 }, /* WF_MCU_CIRQ */ 406 { 0x89020000, 0x4d2000, 0x01000 }, /* WF_MCU_GPT */ 407 { 0x89030000, 0x4d3000, 0x01000 }, /* WF_MCU_WDT */ 408 { 0x80010000, 0x4d4000, 0x01000 }, /* WF_AXIDMA */ 409 { 0x0, 0x0, 0x0 }, /* imply end of search */ 410 }; 411 412 static u32 mt7915_reg_map_l1(struct mt7915_dev *dev, u32 addr) 413 { 414 u32 offset = FIELD_GET(MT_HIF_REMAP_L1_OFFSET, addr); 415 u32 base = FIELD_GET(MT_HIF_REMAP_L1_BASE, addr); 416 u32 l1_remap; 417 418 if (is_mt7986(&dev->mt76)) 419 return MT_CONN_INFRA_OFFSET(addr); 420 421 l1_remap = is_mt7915(&dev->mt76) ? 422 MT_HIF_REMAP_L1 : MT_HIF_REMAP_L1_MT7916; 423 424 dev->bus_ops->rmw(&dev->mt76, l1_remap, 425 MT_HIF_REMAP_L1_MASK, 426 FIELD_PREP(MT_HIF_REMAP_L1_MASK, base)); 427 /* use read to push write */ 428 dev->bus_ops->rr(&dev->mt76, l1_remap); 429 430 return MT_HIF_REMAP_BASE_L1 + offset; 431 } 432 433 static u32 mt7915_reg_map_l2(struct mt7915_dev *dev, u32 addr) 434 { 435 u32 offset, base; 436 437 if (is_mt7915(&dev->mt76)) { 438 offset = FIELD_GET(MT_HIF_REMAP_L2_OFFSET, addr); 439 base = FIELD_GET(MT_HIF_REMAP_L2_BASE, addr); 440 441 dev->bus_ops->rmw(&dev->mt76, MT_HIF_REMAP_L2, 442 MT_HIF_REMAP_L2_MASK, 443 FIELD_PREP(MT_HIF_REMAP_L2_MASK, base)); 444 445 /* use read to push write */ 446 dev->bus_ops->rr(&dev->mt76, MT_HIF_REMAP_L2); 447 } else { 448 u32 ofs = is_mt7986(&dev->mt76) ? 0x400000 : 0; 449 450 offset = FIELD_GET(MT_HIF_REMAP_L2_OFFSET_MT7916, addr); 451 base = FIELD_GET(MT_HIF_REMAP_L2_BASE_MT7916, addr); 452 453 dev->bus_ops->rmw(&dev->mt76, MT_HIF_REMAP_L2_MT7916 + ofs, 454 MT_HIF_REMAP_L2_MASK_MT7916, 455 FIELD_PREP(MT_HIF_REMAP_L2_MASK_MT7916, base)); 456 457 /* use read to push write */ 458 dev->bus_ops->rr(&dev->mt76, MT_HIF_REMAP_L2_MT7916 + ofs); 459 460 offset += (MT_HIF_REMAP_BASE_L2_MT7916 + ofs); 461 } 462 463 return offset; 464 } 465 466 static u32 __mt7915_reg_addr(struct mt7915_dev *dev, u32 addr) 467 { 468 int i; 469 470 if (addr < 0x100000) 471 return addr; 472 473 if (!dev->reg.map) { 474 dev_err(dev->mt76.dev, "err: reg_map is null\n"); 475 return addr; 476 } 477 478 for (i = 0; i < dev->reg.map_size; i++) { 479 u32 ofs; 480 481 if (addr < dev->reg.map[i].phys) 482 continue; 483 484 ofs = addr - dev->reg.map[i].phys; 485 if (ofs > dev->reg.map[i].size) 486 continue; 487 488 return dev->reg.map[i].maps + ofs; 489 } 490 491 if ((addr >= MT_INFRA_BASE && addr < MT_WFSYS0_PHY_START) || 492 (addr >= MT_WFSYS0_PHY_START && addr < MT_WFSYS1_PHY_START) || 493 (addr >= MT_WFSYS1_PHY_START && addr <= MT_WFSYS1_PHY_END)) 494 return mt7915_reg_map_l1(dev, addr); 495 496 if (dev_is_pci(dev->mt76.dev) && 497 ((addr >= MT_CBTOP1_PHY_START && addr <= MT_CBTOP1_PHY_END) || 498 addr >= MT_CBTOP2_PHY_START)) 499 return mt7915_reg_map_l1(dev, addr); 500 501 /* CONN_INFRA: covert to phyiscal addr and use layer 1 remap */ 502 if (addr >= MT_INFRA_MCU_START && addr <= MT_INFRA_MCU_END) { 503 addr = addr - MT_INFRA_MCU_START + MT_INFRA_BASE; 504 return mt7915_reg_map_l1(dev, addr); 505 } 506 507 return mt7915_reg_map_l2(dev, addr); 508 } 509 510 void mt7915_memcpy_fromio(struct mt7915_dev *dev, void *buf, u32 offset, 511 size_t len) 512 { 513 u32 addr = __mt7915_reg_addr(dev, offset); 514 515 memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len); 516 } 517 518 static u32 mt7915_rr(struct mt76_dev *mdev, u32 offset) 519 { 520 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); 521 u32 addr = __mt7915_reg_addr(dev, offset); 522 523 return dev->bus_ops->rr(mdev, addr); 524 } 525 526 static void mt7915_wr(struct mt76_dev *mdev, u32 offset, u32 val) 527 { 528 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); 529 u32 addr = __mt7915_reg_addr(dev, offset); 530 531 dev->bus_ops->wr(mdev, addr, val); 532 } 533 534 static u32 mt7915_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) 535 { 536 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); 537 u32 addr = __mt7915_reg_addr(dev, offset); 538 539 return dev->bus_ops->rmw(mdev, addr, mask, val); 540 } 541 542 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 543 static int mt7915_mmio_wed_offload_enable(struct mtk_wed_device *wed) 544 { 545 struct mt7915_dev *dev; 546 struct mt7915_phy *phy; 547 int ret; 548 549 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); 550 551 spin_lock_bh(&dev->mt76.token_lock); 552 dev->mt76.token_size = wed->wlan.token_start; 553 spin_unlock_bh(&dev->mt76.token_lock); 554 555 ret = wait_event_timeout(dev->mt76.tx_wait, 556 !dev->mt76.wed_token_count, HZ); 557 if (!ret) 558 return -EAGAIN; 559 560 phy = &dev->phy; 561 mt76_set(dev, MT_AGG_ACR4(phy->mt76->band_idx), MT_AGG_ACR_PPDU_TXS2H); 562 563 phy = dev->mt76.phys[MT_BAND1] ? dev->mt76.phys[MT_BAND1]->priv : NULL; 564 if (phy) 565 mt76_set(dev, MT_AGG_ACR4(phy->mt76->band_idx), 566 MT_AGG_ACR_PPDU_TXS2H); 567 568 return 0; 569 } 570 571 static void mt7915_mmio_wed_offload_disable(struct mtk_wed_device *wed) 572 { 573 struct mt7915_dev *dev; 574 struct mt7915_phy *phy; 575 576 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); 577 578 spin_lock_bh(&dev->mt76.token_lock); 579 dev->mt76.token_size = MT7915_TOKEN_SIZE; 580 spin_unlock_bh(&dev->mt76.token_lock); 581 582 /* MT_TXD5_TX_STATUS_HOST (MPDU format) has higher priority than 583 * MT_AGG_ACR_PPDU_TXS2H (PPDU format) even though ACR bit is set. 584 */ 585 phy = &dev->phy; 586 mt76_clear(dev, MT_AGG_ACR4(phy->mt76->band_idx), MT_AGG_ACR_PPDU_TXS2H); 587 588 phy = dev->mt76.phys[MT_BAND1] ? dev->mt76.phys[MT_BAND1]->priv : NULL; 589 if (phy) 590 mt76_clear(dev, MT_AGG_ACR4(phy->mt76->band_idx), 591 MT_AGG_ACR_PPDU_TXS2H); 592 } 593 594 static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed) 595 { 596 struct mt7915_dev *dev; 597 u32 length; 598 int i; 599 600 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); 601 length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size + 602 sizeof(struct skb_shared_info)); 603 604 for (i = 0; i < dev->mt76.rx_token_size; i++) { 605 struct mt76_txwi_cache *t; 606 607 t = mt76_rx_token_release(&dev->mt76, i); 608 if (!t || !t->ptr) 609 continue; 610 611 dma_unmap_single(dev->mt76.dma_dev, t->dma_addr, 612 wed->wlan.rx_size, DMA_FROM_DEVICE); 613 __free_pages(virt_to_page(t->ptr), get_order(length)); 614 t->ptr = NULL; 615 616 mt76_put_rxwi(&dev->mt76, t); 617 } 618 } 619 620 static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) 621 { 622 struct mtk_rxbm_desc *desc = wed->rx_buf_ring.desc; 623 struct mt7915_dev *dev; 624 u32 length; 625 int i; 626 627 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); 628 length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size + 629 sizeof(struct skb_shared_info)); 630 631 for (i = 0; i < size; i++) { 632 struct mt76_txwi_cache *t = mt76_get_rxwi(&dev->mt76); 633 dma_addr_t phy_addr; 634 struct page *page; 635 int token; 636 void *ptr; 637 638 page = __dev_alloc_pages(GFP_KERNEL, get_order(length)); 639 if (!page) 640 goto unmap; 641 642 ptr = page_address(page); 643 phy_addr = dma_map_single(dev->mt76.dma_dev, ptr, 644 wed->wlan.rx_size, 645 DMA_TO_DEVICE); 646 if (unlikely(dma_mapping_error(dev->mt76.dev, phy_addr))) { 647 __free_pages(page, get_order(length)); 648 goto unmap; 649 } 650 651 desc->buf0 = cpu_to_le32(phy_addr); 652 token = mt76_rx_token_consume(&dev->mt76, ptr, t, phy_addr); 653 if (token < 0) { 654 dma_unmap_single(dev->mt76.dma_dev, phy_addr, 655 wed->wlan.rx_size, DMA_TO_DEVICE); 656 __free_pages(page, get_order(length)); 657 goto unmap; 658 } 659 660 desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN, 661 token)); 662 desc++; 663 } 664 665 return 0; 666 667 unmap: 668 mt7915_mmio_wed_release_rx_buf(wed); 669 return -ENOMEM; 670 } 671 672 static void mt7915_mmio_wed_update_rx_stats(struct mtk_wed_device *wed, 673 struct mtk_wed_wo_rx_stats *stats) 674 { 675 int idx = le16_to_cpu(stats->wlan_idx); 676 struct mt7915_dev *dev; 677 struct mt76_wcid *wcid; 678 679 dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); 680 681 if (idx >= mt7915_wtbl_size(dev)) 682 return; 683 684 rcu_read_lock(); 685 686 wcid = rcu_dereference(dev->mt76.wcid[idx]); 687 if (wcid) { 688 wcid->stats.rx_bytes += le32_to_cpu(stats->rx_byte_cnt); 689 wcid->stats.rx_packets += le32_to_cpu(stats->rx_pkt_cnt); 690 wcid->stats.rx_errors += le32_to_cpu(stats->rx_err_cnt); 691 wcid->stats.rx_drops += le32_to_cpu(stats->rx_drop_cnt); 692 } 693 694 rcu_read_unlock(); 695 } 696 #endif 697 698 int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr, 699 bool pci, int *irq) 700 { 701 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 702 struct mtk_wed_device *wed = &dev->mt76.mmio.wed; 703 int ret; 704 705 if (!wed_enable) 706 return 0; 707 708 if (pci) { 709 struct pci_dev *pci_dev = pdev_ptr; 710 711 wed->wlan.pci_dev = pci_dev; 712 wed->wlan.bus_type = MTK_WED_BUS_PCIE; 713 wed->wlan.base = devm_ioremap(dev->mt76.dev, 714 pci_resource_start(pci_dev, 0), 715 pci_resource_len(pci_dev, 0)); 716 wed->wlan.phy_base = pci_resource_start(pci_dev, 0); 717 wed->wlan.wpdma_int = pci_resource_start(pci_dev, 0) + 718 MT_INT_WED_SOURCE_CSR; 719 wed->wlan.wpdma_mask = pci_resource_start(pci_dev, 0) + 720 MT_INT_WED_MASK_CSR; 721 wed->wlan.wpdma_phys = pci_resource_start(pci_dev, 0) + 722 MT_WFDMA_EXT_CSR_BASE; 723 wed->wlan.wpdma_tx = pci_resource_start(pci_dev, 0) + 724 MT_TXQ_WED_RING_BASE; 725 wed->wlan.wpdma_txfree = pci_resource_start(pci_dev, 0) + 726 MT_RXQ_WED_RING_BASE; 727 wed->wlan.wpdma_rx_glo = pci_resource_start(pci_dev, 0) + 728 MT_WPDMA_GLO_CFG; 729 wed->wlan.wpdma_rx = pci_resource_start(pci_dev, 0) + 730 MT_RXQ_WED_DATA_RING_BASE; 731 } else { 732 struct platform_device *plat_dev = pdev_ptr; 733 struct resource *res; 734 735 res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); 736 if (!res) 737 return -ENOMEM; 738 739 wed->wlan.platform_dev = plat_dev; 740 wed->wlan.bus_type = MTK_WED_BUS_AXI; 741 wed->wlan.base = devm_ioremap(dev->mt76.dev, res->start, 742 resource_size(res)); 743 wed->wlan.phy_base = res->start; 744 wed->wlan.wpdma_int = res->start + MT_INT_SOURCE_CSR; 745 wed->wlan.wpdma_mask = res->start + MT_INT_MASK_CSR; 746 wed->wlan.wpdma_tx = res->start + MT_TXQ_WED_RING_BASE; 747 wed->wlan.wpdma_txfree = res->start + MT_RXQ_WED_RING_BASE; 748 wed->wlan.wpdma_rx_glo = res->start + MT_WPDMA_GLO_CFG; 749 wed->wlan.wpdma_rx = res->start + MT_RXQ_WED_DATA_RING_BASE; 750 } 751 wed->wlan.nbuf = 4096; 752 wed->wlan.tx_tbit[0] = is_mt7915(&dev->mt76) ? 4 : 30; 753 wed->wlan.tx_tbit[1] = is_mt7915(&dev->mt76) ? 5 : 31; 754 wed->wlan.txfree_tbit = is_mt7986(&dev->mt76) ? 2 : 1; 755 wed->wlan.token_start = MT7915_TOKEN_SIZE - wed->wlan.nbuf; 756 wed->wlan.wcid_512 = !is_mt7915(&dev->mt76); 757 758 wed->wlan.rx_nbuf = 65536; 759 wed->wlan.rx_npkt = MT7915_WED_RX_TOKEN_SIZE; 760 wed->wlan.rx_size = SKB_WITH_OVERHEAD(MT_RX_BUF_SIZE); 761 if (is_mt7915(&dev->mt76)) { 762 wed->wlan.rx_tbit[0] = 16; 763 wed->wlan.rx_tbit[1] = 17; 764 } else if (is_mt7986(&dev->mt76)) { 765 wed->wlan.rx_tbit[0] = 22; 766 wed->wlan.rx_tbit[1] = 23; 767 } else { 768 wed->wlan.rx_tbit[0] = 18; 769 wed->wlan.rx_tbit[1] = 19; 770 } 771 772 wed->wlan.init_buf = mt7915_wed_init_buf; 773 wed->wlan.offload_enable = mt7915_mmio_wed_offload_enable; 774 wed->wlan.offload_disable = mt7915_mmio_wed_offload_disable; 775 wed->wlan.init_rx_buf = mt7915_mmio_wed_init_rx_buf; 776 wed->wlan.release_rx_buf = mt7915_mmio_wed_release_rx_buf; 777 wed->wlan.update_wo_rx_stats = mt7915_mmio_wed_update_rx_stats; 778 779 dev->mt76.rx_token_size = wed->wlan.rx_npkt; 780 781 if (mtk_wed_device_attach(wed)) 782 return 0; 783 784 *irq = wed->irq; 785 dev->mt76.dma_dev = wed->dev; 786 787 ret = dma_set_mask(wed->dev, DMA_BIT_MASK(32)); 788 if (ret) 789 return ret; 790 791 return 1; 792 #else 793 return 0; 794 #endif 795 } 796 797 static int mt7915_mmio_init(struct mt76_dev *mdev, 798 void __iomem *mem_base, 799 u32 device_id) 800 { 801 struct mt76_bus_ops *bus_ops; 802 struct mt7915_dev *dev; 803 804 dev = container_of(mdev, struct mt7915_dev, mt76); 805 mt76_mmio_init(&dev->mt76, mem_base); 806 807 switch (device_id) { 808 case 0x7915: 809 dev->reg.reg_rev = mt7915_reg; 810 dev->reg.offs_rev = mt7915_offs; 811 dev->reg.map = mt7915_reg_map; 812 dev->reg.map_size = ARRAY_SIZE(mt7915_reg_map); 813 break; 814 case 0x7906: 815 dev->reg.reg_rev = mt7916_reg; 816 dev->reg.offs_rev = mt7916_offs; 817 dev->reg.map = mt7916_reg_map; 818 dev->reg.map_size = ARRAY_SIZE(mt7916_reg_map); 819 break; 820 case 0x7986: 821 dev->reg.reg_rev = mt7986_reg; 822 dev->reg.offs_rev = mt7916_offs; 823 dev->reg.map = mt7986_reg_map; 824 dev->reg.map_size = ARRAY_SIZE(mt7986_reg_map); 825 break; 826 default: 827 return -EINVAL; 828 } 829 830 dev->bus_ops = dev->mt76.bus; 831 bus_ops = devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), 832 GFP_KERNEL); 833 if (!bus_ops) 834 return -ENOMEM; 835 836 bus_ops->rr = mt7915_rr; 837 bus_ops->wr = mt7915_wr; 838 bus_ops->rmw = mt7915_rmw; 839 dev->mt76.bus = bus_ops; 840 841 mdev->rev = (device_id << 16) | 842 (mt76_rr(dev, MT_HW_REV) & 0xff); 843 dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev); 844 845 return 0; 846 } 847 848 void mt7915_dual_hif_set_irq_mask(struct mt7915_dev *dev, 849 bool write_reg, 850 u32 clear, u32 set) 851 { 852 struct mt76_dev *mdev = &dev->mt76; 853 unsigned long flags; 854 855 spin_lock_irqsave(&mdev->mmio.irq_lock, flags); 856 857 mdev->mmio.irqmask &= ~clear; 858 mdev->mmio.irqmask |= set; 859 860 if (write_reg) { 861 if (mtk_wed_device_active(&mdev->mmio.wed)) 862 mtk_wed_device_irq_set_mask(&mdev->mmio.wed, 863 mdev->mmio.irqmask); 864 else 865 mt76_wr(dev, MT_INT_MASK_CSR, mdev->mmio.irqmask); 866 mt76_wr(dev, MT_INT1_MASK_CSR, mdev->mmio.irqmask); 867 } 868 869 spin_unlock_irqrestore(&mdev->mmio.irq_lock, flags); 870 } 871 872 static void mt7915_rx_poll_complete(struct mt76_dev *mdev, 873 enum mt76_rxq_id q) 874 { 875 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); 876 877 mt7915_irq_enable(dev, MT_INT_RX(q)); 878 } 879 880 /* TODO: support 2/4/6/8 MSI-X vectors */ 881 static void mt7915_irq_tasklet(struct tasklet_struct *t) 882 { 883 struct mt7915_dev *dev = from_tasklet(dev, t, irq_tasklet); 884 struct mtk_wed_device *wed = &dev->mt76.mmio.wed; 885 u32 intr, intr1, mask; 886 887 if (mtk_wed_device_active(wed)) { 888 mtk_wed_device_irq_set_mask(wed, 0); 889 if (dev->hif2) 890 mt76_wr(dev, MT_INT1_MASK_CSR, 0); 891 intr = mtk_wed_device_irq_get(wed, dev->mt76.mmio.irqmask); 892 } else { 893 mt76_wr(dev, MT_INT_MASK_CSR, 0); 894 if (dev->hif2) 895 mt76_wr(dev, MT_INT1_MASK_CSR, 0); 896 897 intr = mt76_rr(dev, MT_INT_SOURCE_CSR); 898 intr &= dev->mt76.mmio.irqmask; 899 mt76_wr(dev, MT_INT_SOURCE_CSR, intr); 900 } 901 902 if (dev->hif2) { 903 intr1 = mt76_rr(dev, MT_INT1_SOURCE_CSR); 904 intr1 &= dev->mt76.mmio.irqmask; 905 mt76_wr(dev, MT_INT1_SOURCE_CSR, intr1); 906 907 intr |= intr1; 908 } 909 910 trace_dev_irq(&dev->mt76, intr, dev->mt76.mmio.irqmask); 911 912 mask = intr & MT_INT_RX_DONE_ALL; 913 if (intr & MT_INT_TX_DONE_MCU) 914 mask |= MT_INT_TX_DONE_MCU; 915 916 mt7915_irq_disable(dev, mask); 917 918 if (intr & MT_INT_TX_DONE_MCU) 919 napi_schedule(&dev->mt76.tx_napi); 920 921 if (intr & MT_INT_RX(MT_RXQ_MAIN)) 922 napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]); 923 924 if (intr & MT_INT_RX(MT_RXQ_BAND1)) 925 napi_schedule(&dev->mt76.napi[MT_RXQ_BAND1]); 926 927 if (intr & MT_INT_RX(MT_RXQ_MCU)) 928 napi_schedule(&dev->mt76.napi[MT_RXQ_MCU]); 929 930 if (intr & MT_INT_RX(MT_RXQ_MCU_WA)) 931 napi_schedule(&dev->mt76.napi[MT_RXQ_MCU_WA]); 932 933 if (!is_mt7915(&dev->mt76) && 934 (intr & MT_INT_RX(MT_RXQ_MAIN_WA))) 935 napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN_WA]); 936 937 if (intr & MT_INT_RX(MT_RXQ_BAND1_WA)) 938 napi_schedule(&dev->mt76.napi[MT_RXQ_BAND1_WA]); 939 940 if (intr & MT_INT_MCU_CMD) { 941 u32 val = mt76_rr(dev, MT_MCU_CMD); 942 943 mt76_wr(dev, MT_MCU_CMD, val); 944 if (val & (MT_MCU_CMD_ERROR_MASK | MT_MCU_CMD_WDT_MASK)) { 945 dev->recovery.state = val; 946 mt7915_reset(dev); 947 } 948 } 949 } 950 951 irqreturn_t mt7915_irq_handler(int irq, void *dev_instance) 952 { 953 struct mt7915_dev *dev = dev_instance; 954 struct mtk_wed_device *wed = &dev->mt76.mmio.wed; 955 956 if (mtk_wed_device_active(wed)) { 957 mtk_wed_device_irq_set_mask(wed, 0); 958 } else { 959 mt76_wr(dev, MT_INT_MASK_CSR, 0); 960 if (dev->hif2) 961 mt76_wr(dev, MT_INT1_MASK_CSR, 0); 962 } 963 964 if (!test_bit(MT76_STATE_INITIALIZED, &dev->mphy.state)) 965 return IRQ_NONE; 966 967 tasklet_schedule(&dev->irq_tasklet); 968 969 return IRQ_HANDLED; 970 } 971 972 struct mt7915_dev *mt7915_mmio_probe(struct device *pdev, 973 void __iomem *mem_base, u32 device_id) 974 { 975 static const struct mt76_driver_ops drv_ops = { 976 /* txwi_size = txd size + txp size */ 977 .txwi_size = MT_TXD_SIZE + sizeof(struct mt76_connac_fw_txp), 978 .drv_flags = MT_DRV_TXWI_NO_FREE | MT_DRV_HW_MGMT_TXQ | 979 MT_DRV_AMSDU_OFFLOAD, 980 .survey_flags = SURVEY_INFO_TIME_TX | 981 SURVEY_INFO_TIME_RX | 982 SURVEY_INFO_TIME_BSS_RX, 983 .token_size = MT7915_TOKEN_SIZE, 984 .tx_prepare_skb = mt7915_tx_prepare_skb, 985 .tx_complete_skb = mt76_connac_tx_complete_skb, 986 .rx_skb = mt7915_queue_rx_skb, 987 .rx_check = mt7915_rx_check, 988 .rx_poll_complete = mt7915_rx_poll_complete, 989 .sta_ps = mt7915_sta_ps, 990 .sta_add = mt7915_mac_sta_add, 991 .sta_remove = mt7915_mac_sta_remove, 992 .update_survey = mt7915_update_channel, 993 }; 994 struct mt7915_dev *dev; 995 struct mt76_dev *mdev; 996 int ret; 997 998 mdev = mt76_alloc_device(pdev, sizeof(*dev), &mt7915_ops, &drv_ops); 999 if (!mdev) 1000 return ERR_PTR(-ENOMEM); 1001 1002 dev = container_of(mdev, struct mt7915_dev, mt76); 1003 1004 ret = mt7915_mmio_init(mdev, mem_base, device_id); 1005 if (ret) 1006 goto error; 1007 1008 tasklet_setup(&dev->irq_tasklet, mt7915_irq_tasklet); 1009 1010 return dev; 1011 1012 error: 1013 mt76_free_device(&dev->mt76); 1014 1015 return ERR_PTR(ret); 1016 } 1017 1018 static int __init mt7915_init(void) 1019 { 1020 int ret; 1021 1022 ret = pci_register_driver(&mt7915_hif_driver); 1023 if (ret) 1024 return ret; 1025 1026 ret = pci_register_driver(&mt7915_pci_driver); 1027 if (ret) 1028 goto error_pci; 1029 1030 if (IS_ENABLED(CONFIG_MT7986_WMAC)) { 1031 ret = platform_driver_register(&mt7986_wmac_driver); 1032 if (ret) 1033 goto error_wmac; 1034 } 1035 1036 return 0; 1037 1038 error_wmac: 1039 pci_unregister_driver(&mt7915_pci_driver); 1040 error_pci: 1041 pci_unregister_driver(&mt7915_hif_driver); 1042 1043 return ret; 1044 } 1045 1046 static void __exit mt7915_exit(void) 1047 { 1048 if (IS_ENABLED(CONFIG_MT7986_WMAC)) 1049 platform_driver_unregister(&mt7986_wmac_driver); 1050 1051 pci_unregister_driver(&mt7915_pci_driver); 1052 pci_unregister_driver(&mt7915_hif_driver); 1053 } 1054 1055 module_init(mt7915_init); 1056 module_exit(mt7915_exit); 1057 MODULE_LICENSE("Dual BSD/GPL"); 1058