b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: ISC |
| 2 | /* |
| 3 | * Copyright (c) 2018 The Linux Foundation. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/bits.h> |
| 7 | #include <linux/clk.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/of.h> |
| 11 | #include <linux/of_device.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/regulator/consumer.h> |
| 14 | |
| 15 | #include "ce.h" |
| 16 | #include "debug.h" |
| 17 | #include "hif.h" |
| 18 | #include "htc.h" |
| 19 | #include "snoc.h" |
| 20 | |
| 21 | #define ATH10K_SNOC_RX_POST_RETRY_MS 50 |
| 22 | #define CE_POLL_PIPE 4 |
| 23 | #define ATH10K_SNOC_WAKE_IRQ 2 |
| 24 | |
| 25 | static char *const ce_name[] = { |
| 26 | "WLAN_CE_0", |
| 27 | "WLAN_CE_1", |
| 28 | "WLAN_CE_2", |
| 29 | "WLAN_CE_3", |
| 30 | "WLAN_CE_4", |
| 31 | "WLAN_CE_5", |
| 32 | "WLAN_CE_6", |
| 33 | "WLAN_CE_7", |
| 34 | "WLAN_CE_8", |
| 35 | "WLAN_CE_9", |
| 36 | "WLAN_CE_10", |
| 37 | "WLAN_CE_11", |
| 38 | }; |
| 39 | |
| 40 | static struct ath10k_vreg_info vreg_cfg[] = { |
| 41 | {NULL, "vdd-0.8-cx-mx", 800000, 850000, 0, 0, false}, |
| 42 | {NULL, "vdd-1.8-xo", 1800000, 1850000, 0, 0, false}, |
| 43 | {NULL, "vdd-1.3-rfa", 1300000, 1350000, 0, 0, false}, |
| 44 | {NULL, "vdd-3.3-ch0", 3300000, 3350000, 0, 0, false}, |
| 45 | }; |
| 46 | |
| 47 | static struct ath10k_clk_info clk_cfg[] = { |
| 48 | {NULL, "cxo_ref_clk_pin", 0, false}, |
| 49 | }; |
| 50 | |
| 51 | static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state); |
| 52 | static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state); |
| 53 | static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state); |
| 54 | static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state); |
| 55 | static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state); |
| 56 | static void ath10k_snoc_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state); |
| 57 | |
| 58 | static const struct ath10k_snoc_drv_priv drv_priv = { |
| 59 | .hw_rev = ATH10K_HW_WCN3990, |
| 60 | .dma_mask = DMA_BIT_MASK(35), |
| 61 | .msa_size = 0x100000, |
| 62 | }; |
| 63 | |
| 64 | #define WCN3990_SRC_WR_IDX_OFFSET 0x3C |
| 65 | #define WCN3990_DST_WR_IDX_OFFSET 0x40 |
| 66 | |
| 67 | static struct ath10k_shadow_reg_cfg target_shadow_reg_cfg_map[] = { |
| 68 | { |
| 69 | .ce_id = __cpu_to_le16(0), |
| 70 | .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET), |
| 71 | }, |
| 72 | |
| 73 | { |
| 74 | .ce_id = __cpu_to_le16(3), |
| 75 | .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET), |
| 76 | }, |
| 77 | |
| 78 | { |
| 79 | .ce_id = __cpu_to_le16(4), |
| 80 | .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET), |
| 81 | }, |
| 82 | |
| 83 | { |
| 84 | .ce_id = __cpu_to_le16(5), |
| 85 | .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET), |
| 86 | }, |
| 87 | |
| 88 | { |
| 89 | .ce_id = __cpu_to_le16(7), |
| 90 | .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET), |
| 91 | }, |
| 92 | |
| 93 | { |
| 94 | .ce_id = __cpu_to_le16(1), |
| 95 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 96 | }, |
| 97 | |
| 98 | { |
| 99 | .ce_id = __cpu_to_le16(2), |
| 100 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 101 | }, |
| 102 | |
| 103 | { |
| 104 | .ce_id = __cpu_to_le16(7), |
| 105 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 106 | }, |
| 107 | |
| 108 | { |
| 109 | .ce_id = __cpu_to_le16(8), |
| 110 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 111 | }, |
| 112 | |
| 113 | { |
| 114 | .ce_id = __cpu_to_le16(9), |
| 115 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 116 | }, |
| 117 | |
| 118 | { |
| 119 | .ce_id = __cpu_to_le16(10), |
| 120 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 121 | }, |
| 122 | |
| 123 | { |
| 124 | .ce_id = __cpu_to_le16(11), |
| 125 | .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET), |
| 126 | }, |
| 127 | }; |
| 128 | |
| 129 | static struct ce_attr host_ce_config_wlan[] = { |
| 130 | /* CE0: host->target HTC control streams */ |
| 131 | { |
| 132 | .flags = CE_ATTR_FLAGS, |
| 133 | .src_nentries = 16, |
| 134 | .src_sz_max = 2048, |
| 135 | .dest_nentries = 0, |
| 136 | .send_cb = ath10k_snoc_htc_tx_cb, |
| 137 | }, |
| 138 | |
| 139 | /* CE1: target->host HTT + HTC control */ |
| 140 | { |
| 141 | .flags = CE_ATTR_FLAGS, |
| 142 | .src_nentries = 0, |
| 143 | .src_sz_max = 2048, |
| 144 | .dest_nentries = 512, |
| 145 | .recv_cb = ath10k_snoc_htt_htc_rx_cb, |
| 146 | }, |
| 147 | |
| 148 | /* CE2: target->host WMI */ |
| 149 | { |
| 150 | .flags = CE_ATTR_FLAGS, |
| 151 | .src_nentries = 0, |
| 152 | .src_sz_max = 2048, |
| 153 | .dest_nentries = 64, |
| 154 | .recv_cb = ath10k_snoc_htc_rx_cb, |
| 155 | }, |
| 156 | |
| 157 | /* CE3: host->target WMI */ |
| 158 | { |
| 159 | .flags = CE_ATTR_FLAGS, |
| 160 | .src_nentries = 32, |
| 161 | .src_sz_max = 2048, |
| 162 | .dest_nentries = 0, |
| 163 | .send_cb = ath10k_snoc_htc_tx_cb, |
| 164 | }, |
| 165 | |
| 166 | /* CE4: host->target HTT */ |
| 167 | { |
| 168 | .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR, |
| 169 | .src_nentries = 2048, |
| 170 | .src_sz_max = 256, |
| 171 | .dest_nentries = 0, |
| 172 | .send_cb = ath10k_snoc_htt_tx_cb, |
| 173 | }, |
| 174 | |
| 175 | /* CE5: target->host HTT (ipa_uc->target ) */ |
| 176 | { |
| 177 | .flags = CE_ATTR_FLAGS, |
| 178 | .src_nentries = 0, |
| 179 | .src_sz_max = 512, |
| 180 | .dest_nentries = 512, |
| 181 | .recv_cb = ath10k_snoc_htt_rx_cb, |
| 182 | }, |
| 183 | |
| 184 | /* CE6: target autonomous hif_memcpy */ |
| 185 | { |
| 186 | .flags = CE_ATTR_FLAGS, |
| 187 | .src_nentries = 0, |
| 188 | .src_sz_max = 0, |
| 189 | .dest_nentries = 0, |
| 190 | }, |
| 191 | |
| 192 | /* CE7: ce_diag, the Diagnostic Window */ |
| 193 | { |
| 194 | .flags = CE_ATTR_FLAGS, |
| 195 | .src_nentries = 2, |
| 196 | .src_sz_max = 2048, |
| 197 | .dest_nentries = 2, |
| 198 | }, |
| 199 | |
| 200 | /* CE8: Target to uMC */ |
| 201 | { |
| 202 | .flags = CE_ATTR_FLAGS, |
| 203 | .src_nentries = 0, |
| 204 | .src_sz_max = 2048, |
| 205 | .dest_nentries = 128, |
| 206 | }, |
| 207 | |
| 208 | /* CE9 target->host HTT */ |
| 209 | { |
| 210 | .flags = CE_ATTR_FLAGS, |
| 211 | .src_nentries = 0, |
| 212 | .src_sz_max = 2048, |
| 213 | .dest_nentries = 512, |
| 214 | .recv_cb = ath10k_snoc_htt_htc_rx_cb, |
| 215 | }, |
| 216 | |
| 217 | /* CE10: target->host HTT */ |
| 218 | { |
| 219 | .flags = CE_ATTR_FLAGS, |
| 220 | .src_nentries = 0, |
| 221 | .src_sz_max = 2048, |
| 222 | .dest_nentries = 512, |
| 223 | .recv_cb = ath10k_snoc_htt_htc_rx_cb, |
| 224 | }, |
| 225 | |
| 226 | /* CE11: target -> host PKTLOG */ |
| 227 | { |
| 228 | .flags = CE_ATTR_FLAGS, |
| 229 | .src_nentries = 0, |
| 230 | .src_sz_max = 2048, |
| 231 | .dest_nentries = 512, |
| 232 | .recv_cb = ath10k_snoc_pktlog_rx_cb, |
| 233 | }, |
| 234 | }; |
| 235 | |
| 236 | static struct ce_pipe_config target_ce_config_wlan[] = { |
| 237 | /* CE0: host->target HTC control and raw streams */ |
| 238 | { |
| 239 | .pipenum = __cpu_to_le32(0), |
| 240 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 241 | .nentries = __cpu_to_le32(32), |
| 242 | .nbytes_max = __cpu_to_le32(2048), |
| 243 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 244 | .reserved = __cpu_to_le32(0), |
| 245 | }, |
| 246 | |
| 247 | /* CE1: target->host HTT + HTC control */ |
| 248 | { |
| 249 | .pipenum = __cpu_to_le32(1), |
| 250 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 251 | .nentries = __cpu_to_le32(32), |
| 252 | .nbytes_max = __cpu_to_le32(2048), |
| 253 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 254 | .reserved = __cpu_to_le32(0), |
| 255 | }, |
| 256 | |
| 257 | /* CE2: target->host WMI */ |
| 258 | { |
| 259 | .pipenum = __cpu_to_le32(2), |
| 260 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 261 | .nentries = __cpu_to_le32(64), |
| 262 | .nbytes_max = __cpu_to_le32(2048), |
| 263 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 264 | .reserved = __cpu_to_le32(0), |
| 265 | }, |
| 266 | |
| 267 | /* CE3: host->target WMI */ |
| 268 | { |
| 269 | .pipenum = __cpu_to_le32(3), |
| 270 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 271 | .nentries = __cpu_to_le32(32), |
| 272 | .nbytes_max = __cpu_to_le32(2048), |
| 273 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 274 | .reserved = __cpu_to_le32(0), |
| 275 | }, |
| 276 | |
| 277 | /* CE4: host->target HTT */ |
| 278 | { |
| 279 | .pipenum = __cpu_to_le32(4), |
| 280 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 281 | .nentries = __cpu_to_le32(256), |
| 282 | .nbytes_max = __cpu_to_le32(256), |
| 283 | .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR), |
| 284 | .reserved = __cpu_to_le32(0), |
| 285 | }, |
| 286 | |
| 287 | /* CE5: target->host HTT (HIF->HTT) */ |
| 288 | { |
| 289 | .pipenum = __cpu_to_le32(5), |
| 290 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 291 | .nentries = __cpu_to_le32(1024), |
| 292 | .nbytes_max = __cpu_to_le32(64), |
| 293 | .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR), |
| 294 | .reserved = __cpu_to_le32(0), |
| 295 | }, |
| 296 | |
| 297 | /* CE6: Reserved for target autonomous hif_memcpy */ |
| 298 | { |
| 299 | .pipenum = __cpu_to_le32(6), |
| 300 | .pipedir = __cpu_to_le32(PIPEDIR_INOUT), |
| 301 | .nentries = __cpu_to_le32(32), |
| 302 | .nbytes_max = __cpu_to_le32(16384), |
| 303 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 304 | .reserved = __cpu_to_le32(0), |
| 305 | }, |
| 306 | |
| 307 | /* CE7 used only by Host */ |
| 308 | { |
| 309 | .pipenum = __cpu_to_le32(7), |
| 310 | .pipedir = __cpu_to_le32(4), |
| 311 | .nentries = __cpu_to_le32(0), |
| 312 | .nbytes_max = __cpu_to_le32(0), |
| 313 | .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR), |
| 314 | .reserved = __cpu_to_le32(0), |
| 315 | }, |
| 316 | |
| 317 | /* CE8 Target to uMC */ |
| 318 | { |
| 319 | .pipenum = __cpu_to_le32(8), |
| 320 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 321 | .nentries = __cpu_to_le32(32), |
| 322 | .nbytes_max = __cpu_to_le32(2048), |
| 323 | .flags = __cpu_to_le32(0), |
| 324 | .reserved = __cpu_to_le32(0), |
| 325 | }, |
| 326 | |
| 327 | /* CE9 target->host HTT */ |
| 328 | { |
| 329 | .pipenum = __cpu_to_le32(9), |
| 330 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 331 | .nentries = __cpu_to_le32(32), |
| 332 | .nbytes_max = __cpu_to_le32(2048), |
| 333 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 334 | .reserved = __cpu_to_le32(0), |
| 335 | }, |
| 336 | |
| 337 | /* CE10 target->host HTT */ |
| 338 | { |
| 339 | .pipenum = __cpu_to_le32(10), |
| 340 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 341 | .nentries = __cpu_to_le32(32), |
| 342 | .nbytes_max = __cpu_to_le32(2048), |
| 343 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 344 | .reserved = __cpu_to_le32(0), |
| 345 | }, |
| 346 | |
| 347 | /* CE11 target autonomous qcache memcpy */ |
| 348 | { |
| 349 | .pipenum = __cpu_to_le32(11), |
| 350 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 351 | .nentries = __cpu_to_le32(32), |
| 352 | .nbytes_max = __cpu_to_le32(2048), |
| 353 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 354 | .reserved = __cpu_to_le32(0), |
| 355 | }, |
| 356 | }; |
| 357 | |
| 358 | static struct service_to_pipe target_service_to_ce_map_wlan[] = { |
| 359 | { |
| 360 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO), |
| 361 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 362 | __cpu_to_le32(3), |
| 363 | }, |
| 364 | { |
| 365 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO), |
| 366 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 367 | __cpu_to_le32(2), |
| 368 | }, |
| 369 | { |
| 370 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK), |
| 371 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 372 | __cpu_to_le32(3), |
| 373 | }, |
| 374 | { |
| 375 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK), |
| 376 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 377 | __cpu_to_le32(2), |
| 378 | }, |
| 379 | { |
| 380 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE), |
| 381 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 382 | __cpu_to_le32(3), |
| 383 | }, |
| 384 | { |
| 385 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE), |
| 386 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 387 | __cpu_to_le32(2), |
| 388 | }, |
| 389 | { |
| 390 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI), |
| 391 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 392 | __cpu_to_le32(3), |
| 393 | }, |
| 394 | { |
| 395 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI), |
| 396 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 397 | __cpu_to_le32(2), |
| 398 | }, |
| 399 | { |
| 400 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL), |
| 401 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 402 | __cpu_to_le32(3), |
| 403 | }, |
| 404 | { |
| 405 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL), |
| 406 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 407 | __cpu_to_le32(2), |
| 408 | }, |
| 409 | { |
| 410 | __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL), |
| 411 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 412 | __cpu_to_le32(0), |
| 413 | }, |
| 414 | { |
| 415 | __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL), |
| 416 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 417 | __cpu_to_le32(2), |
| 418 | }, |
| 419 | { /* not used */ |
| 420 | __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS), |
| 421 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 422 | __cpu_to_le32(0), |
| 423 | }, |
| 424 | { /* not used */ |
| 425 | __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS), |
| 426 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 427 | __cpu_to_le32(2), |
| 428 | }, |
| 429 | { |
| 430 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG), |
| 431 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 432 | __cpu_to_le32(4), |
| 433 | }, |
| 434 | { |
| 435 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG), |
| 436 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 437 | __cpu_to_le32(1), |
| 438 | }, |
| 439 | { /* not used */ |
| 440 | __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS), |
| 441 | __cpu_to_le32(PIPEDIR_OUT), |
| 442 | __cpu_to_le32(5), |
| 443 | }, |
| 444 | { /* in = DL = target -> host */ |
| 445 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA2_MSG), |
| 446 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 447 | __cpu_to_le32(9), |
| 448 | }, |
| 449 | { /* in = DL = target -> host */ |
| 450 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA3_MSG), |
| 451 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 452 | __cpu_to_le32(10), |
| 453 | }, |
| 454 | { /* in = DL = target -> host pktlog */ |
| 455 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_LOG_MSG), |
| 456 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 457 | __cpu_to_le32(11), |
| 458 | }, |
| 459 | /* (Additions here) */ |
| 460 | |
| 461 | { /* must be last */ |
| 462 | __cpu_to_le32(0), |
| 463 | __cpu_to_le32(0), |
| 464 | __cpu_to_le32(0), |
| 465 | }, |
| 466 | }; |
| 467 | |
| 468 | static void ath10k_snoc_write32(struct ath10k *ar, u32 offset, u32 value) |
| 469 | { |
| 470 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 471 | |
| 472 | iowrite32(value, ar_snoc->mem + offset); |
| 473 | } |
| 474 | |
| 475 | static u32 ath10k_snoc_read32(struct ath10k *ar, u32 offset) |
| 476 | { |
| 477 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 478 | u32 val; |
| 479 | |
| 480 | val = ioread32(ar_snoc->mem + offset); |
| 481 | |
| 482 | return val; |
| 483 | } |
| 484 | |
| 485 | static int __ath10k_snoc_rx_post_buf(struct ath10k_snoc_pipe *pipe) |
| 486 | { |
| 487 | struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl; |
| 488 | struct ath10k *ar = pipe->hif_ce_state; |
| 489 | struct ath10k_ce *ce = ath10k_ce_priv(ar); |
| 490 | struct sk_buff *skb; |
| 491 | dma_addr_t paddr; |
| 492 | int ret; |
| 493 | |
| 494 | skb = dev_alloc_skb(pipe->buf_sz); |
| 495 | if (!skb) |
| 496 | return -ENOMEM; |
| 497 | |
| 498 | WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb"); |
| 499 | |
| 500 | paddr = dma_map_single(ar->dev, skb->data, |
| 501 | skb->len + skb_tailroom(skb), |
| 502 | DMA_FROM_DEVICE); |
| 503 | if (unlikely(dma_mapping_error(ar->dev, paddr))) { |
| 504 | ath10k_warn(ar, "failed to dma map snoc rx buf\n"); |
| 505 | dev_kfree_skb_any(skb); |
| 506 | return -EIO; |
| 507 | } |
| 508 | |
| 509 | ATH10K_SKB_RXCB(skb)->paddr = paddr; |
| 510 | |
| 511 | spin_lock_bh(&ce->ce_lock); |
| 512 | ret = ce_pipe->ops->ce_rx_post_buf(ce_pipe, skb, paddr); |
| 513 | spin_unlock_bh(&ce->ce_lock); |
| 514 | if (ret) { |
| 515 | dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb), |
| 516 | DMA_FROM_DEVICE); |
| 517 | dev_kfree_skb_any(skb); |
| 518 | return ret; |
| 519 | } |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | static void ath10k_snoc_rx_post_pipe(struct ath10k_snoc_pipe *pipe) |
| 525 | { |
| 526 | struct ath10k *ar = pipe->hif_ce_state; |
| 527 | struct ath10k_ce *ce = ath10k_ce_priv(ar); |
| 528 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 529 | struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl; |
| 530 | int ret, num; |
| 531 | |
| 532 | if (pipe->buf_sz == 0) |
| 533 | return; |
| 534 | |
| 535 | if (!ce_pipe->dest_ring) |
| 536 | return; |
| 537 | |
| 538 | spin_lock_bh(&ce->ce_lock); |
| 539 | num = __ath10k_ce_rx_num_free_bufs(ce_pipe); |
| 540 | spin_unlock_bh(&ce->ce_lock); |
| 541 | while (num--) { |
| 542 | ret = __ath10k_snoc_rx_post_buf(pipe); |
| 543 | if (ret) { |
| 544 | if (ret == -ENOSPC) |
| 545 | break; |
| 546 | ath10k_warn(ar, "failed to post rx buf: %d\n", ret); |
| 547 | mod_timer(&ar_snoc->rx_post_retry, jiffies + |
| 548 | ATH10K_SNOC_RX_POST_RETRY_MS); |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | static void ath10k_snoc_rx_post(struct ath10k *ar) |
| 555 | { |
| 556 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 557 | int i; |
| 558 | |
| 559 | for (i = 0; i < CE_COUNT; i++) |
| 560 | ath10k_snoc_rx_post_pipe(&ar_snoc->pipe_info[i]); |
| 561 | } |
| 562 | |
| 563 | static void ath10k_snoc_process_rx_cb(struct ath10k_ce_pipe *ce_state, |
| 564 | void (*callback)(struct ath10k *ar, |
| 565 | struct sk_buff *skb)) |
| 566 | { |
| 567 | struct ath10k *ar = ce_state->ar; |
| 568 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 569 | struct ath10k_snoc_pipe *pipe_info = &ar_snoc->pipe_info[ce_state->id]; |
| 570 | struct sk_buff *skb; |
| 571 | struct sk_buff_head list; |
| 572 | void *transfer_context; |
| 573 | unsigned int nbytes, max_nbytes; |
| 574 | |
| 575 | __skb_queue_head_init(&list); |
| 576 | while (ath10k_ce_completed_recv_next(ce_state, &transfer_context, |
| 577 | &nbytes) == 0) { |
| 578 | skb = transfer_context; |
| 579 | max_nbytes = skb->len + skb_tailroom(skb); |
| 580 | dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr, |
| 581 | max_nbytes, DMA_FROM_DEVICE); |
| 582 | |
| 583 | if (unlikely(max_nbytes < nbytes)) { |
| 584 | ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)", |
| 585 | nbytes, max_nbytes); |
| 586 | dev_kfree_skb_any(skb); |
| 587 | continue; |
| 588 | } |
| 589 | |
| 590 | skb_put(skb, nbytes); |
| 591 | __skb_queue_tail(&list, skb); |
| 592 | } |
| 593 | |
| 594 | while ((skb = __skb_dequeue(&list))) { |
| 595 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc rx ce pipe %d len %d\n", |
| 596 | ce_state->id, skb->len); |
| 597 | |
| 598 | callback(ar, skb); |
| 599 | } |
| 600 | |
| 601 | ath10k_snoc_rx_post_pipe(pipe_info); |
| 602 | } |
| 603 | |
| 604 | static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state) |
| 605 | { |
| 606 | ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler); |
| 607 | } |
| 608 | |
| 609 | static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state) |
| 610 | { |
| 611 | /* CE4 polling needs to be done whenever CE pipe which transports |
| 612 | * HTT Rx (target->host) is processed. |
| 613 | */ |
| 614 | ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE); |
| 615 | |
| 616 | ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler); |
| 617 | } |
| 618 | |
| 619 | /* Called by lower (CE) layer when data is received from the Target. |
| 620 | * WCN3990 firmware uses separate CE(CE11) to transfer pktlog data. |
| 621 | */ |
| 622 | static void ath10k_snoc_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state) |
| 623 | { |
| 624 | ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler); |
| 625 | } |
| 626 | |
| 627 | static void ath10k_snoc_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb) |
| 628 | { |
| 629 | skb_pull(skb, sizeof(struct ath10k_htc_hdr)); |
| 630 | ath10k_htt_t2h_msg_handler(ar, skb); |
| 631 | } |
| 632 | |
| 633 | static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state) |
| 634 | { |
| 635 | ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE); |
| 636 | ath10k_snoc_process_rx_cb(ce_state, ath10k_snoc_htt_rx_deliver); |
| 637 | } |
| 638 | |
| 639 | static void ath10k_snoc_rx_replenish_retry(struct timer_list *t) |
| 640 | { |
| 641 | struct ath10k_snoc *ar_snoc = from_timer(ar_snoc, t, rx_post_retry); |
| 642 | struct ath10k *ar = ar_snoc->ar; |
| 643 | |
| 644 | ath10k_snoc_rx_post(ar); |
| 645 | } |
| 646 | |
| 647 | static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state) |
| 648 | { |
| 649 | struct ath10k *ar = ce_state->ar; |
| 650 | struct sk_buff_head list; |
| 651 | struct sk_buff *skb; |
| 652 | |
| 653 | __skb_queue_head_init(&list); |
| 654 | while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) { |
| 655 | if (!skb) |
| 656 | continue; |
| 657 | |
| 658 | __skb_queue_tail(&list, skb); |
| 659 | } |
| 660 | |
| 661 | while ((skb = __skb_dequeue(&list))) |
| 662 | ath10k_htc_tx_completion_handler(ar, skb); |
| 663 | } |
| 664 | |
| 665 | static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state) |
| 666 | { |
| 667 | struct ath10k *ar = ce_state->ar; |
| 668 | struct sk_buff *skb; |
| 669 | |
| 670 | while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) { |
| 671 | if (!skb) |
| 672 | continue; |
| 673 | |
| 674 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr, |
| 675 | skb->len, DMA_TO_DEVICE); |
| 676 | ath10k_htt_hif_tx_complete(ar, skb); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | static int ath10k_snoc_hif_tx_sg(struct ath10k *ar, u8 pipe_id, |
| 681 | struct ath10k_hif_sg_item *items, int n_items) |
| 682 | { |
| 683 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 684 | struct ath10k_ce *ce = ath10k_ce_priv(ar); |
| 685 | struct ath10k_snoc_pipe *snoc_pipe; |
| 686 | struct ath10k_ce_pipe *ce_pipe; |
| 687 | int err, i = 0; |
| 688 | |
| 689 | snoc_pipe = &ar_snoc->pipe_info[pipe_id]; |
| 690 | ce_pipe = snoc_pipe->ce_hdl; |
| 691 | spin_lock_bh(&ce->ce_lock); |
| 692 | |
| 693 | for (i = 0; i < n_items - 1; i++) { |
| 694 | ath10k_dbg(ar, ATH10K_DBG_SNOC, |
| 695 | "snoc tx item %d paddr %pad len %d n_items %d\n", |
| 696 | i, &items[i].paddr, items[i].len, n_items); |
| 697 | |
| 698 | err = ath10k_ce_send_nolock(ce_pipe, |
| 699 | items[i].transfer_context, |
| 700 | items[i].paddr, |
| 701 | items[i].len, |
| 702 | items[i].transfer_id, |
| 703 | CE_SEND_FLAG_GATHER); |
| 704 | if (err) |
| 705 | goto err; |
| 706 | } |
| 707 | |
| 708 | ath10k_dbg(ar, ATH10K_DBG_SNOC, |
| 709 | "snoc tx item %d paddr %pad len %d n_items %d\n", |
| 710 | i, &items[i].paddr, items[i].len, n_items); |
| 711 | |
| 712 | err = ath10k_ce_send_nolock(ce_pipe, |
| 713 | items[i].transfer_context, |
| 714 | items[i].paddr, |
| 715 | items[i].len, |
| 716 | items[i].transfer_id, |
| 717 | 0); |
| 718 | if (err) |
| 719 | goto err; |
| 720 | |
| 721 | spin_unlock_bh(&ce->ce_lock); |
| 722 | |
| 723 | return 0; |
| 724 | |
| 725 | err: |
| 726 | for (; i > 0; i--) |
| 727 | __ath10k_ce_send_revert(ce_pipe); |
| 728 | |
| 729 | spin_unlock_bh(&ce->ce_lock); |
| 730 | return err; |
| 731 | } |
| 732 | |
| 733 | static int ath10k_snoc_hif_get_target_info(struct ath10k *ar, |
| 734 | struct bmi_target_info *target_info) |
| 735 | { |
| 736 | target_info->version = ATH10K_HW_WCN3990; |
| 737 | target_info->type = ATH10K_HW_WCN3990; |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | static u16 ath10k_snoc_hif_get_free_queue_number(struct ath10k *ar, u8 pipe) |
| 743 | { |
| 744 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 745 | |
| 746 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "hif get free queue number\n"); |
| 747 | |
| 748 | return ath10k_ce_num_free_src_entries(ar_snoc->pipe_info[pipe].ce_hdl); |
| 749 | } |
| 750 | |
| 751 | static void ath10k_snoc_hif_send_complete_check(struct ath10k *ar, u8 pipe, |
| 752 | int force) |
| 753 | { |
| 754 | int resources; |
| 755 | |
| 756 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif send complete check\n"); |
| 757 | |
| 758 | if (!force) { |
| 759 | resources = ath10k_snoc_hif_get_free_queue_number(ar, pipe); |
| 760 | |
| 761 | if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1)) |
| 762 | return; |
| 763 | } |
| 764 | ath10k_ce_per_engine_service(ar, pipe); |
| 765 | } |
| 766 | |
| 767 | static int ath10k_snoc_hif_map_service_to_pipe(struct ath10k *ar, |
| 768 | u16 service_id, |
| 769 | u8 *ul_pipe, u8 *dl_pipe) |
| 770 | { |
| 771 | const struct service_to_pipe *entry; |
| 772 | bool ul_set = false, dl_set = false; |
| 773 | int i; |
| 774 | |
| 775 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif map service\n"); |
| 776 | |
| 777 | for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) { |
| 778 | entry = &target_service_to_ce_map_wlan[i]; |
| 779 | |
| 780 | if (__le32_to_cpu(entry->service_id) != service_id) |
| 781 | continue; |
| 782 | |
| 783 | switch (__le32_to_cpu(entry->pipedir)) { |
| 784 | case PIPEDIR_NONE: |
| 785 | break; |
| 786 | case PIPEDIR_IN: |
| 787 | WARN_ON(dl_set); |
| 788 | *dl_pipe = __le32_to_cpu(entry->pipenum); |
| 789 | dl_set = true; |
| 790 | break; |
| 791 | case PIPEDIR_OUT: |
| 792 | WARN_ON(ul_set); |
| 793 | *ul_pipe = __le32_to_cpu(entry->pipenum); |
| 794 | ul_set = true; |
| 795 | break; |
| 796 | case PIPEDIR_INOUT: |
| 797 | WARN_ON(dl_set); |
| 798 | WARN_ON(ul_set); |
| 799 | *dl_pipe = __le32_to_cpu(entry->pipenum); |
| 800 | *ul_pipe = __le32_to_cpu(entry->pipenum); |
| 801 | dl_set = true; |
| 802 | ul_set = true; |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | if (!ul_set || !dl_set) |
| 808 | return -ENOENT; |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static void ath10k_snoc_hif_get_default_pipe(struct ath10k *ar, |
| 814 | u8 *ul_pipe, u8 *dl_pipe) |
| 815 | { |
| 816 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif get default pipe\n"); |
| 817 | |
| 818 | (void)ath10k_snoc_hif_map_service_to_pipe(ar, |
| 819 | ATH10K_HTC_SVC_ID_RSVD_CTRL, |
| 820 | ul_pipe, dl_pipe); |
| 821 | } |
| 822 | |
| 823 | static inline void ath10k_snoc_irq_disable(struct ath10k *ar) |
| 824 | { |
| 825 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 826 | int id; |
| 827 | |
| 828 | for (id = 0; id < CE_COUNT_MAX; id++) |
| 829 | disable_irq(ar_snoc->ce_irqs[id].irq_line); |
| 830 | } |
| 831 | |
| 832 | static inline void ath10k_snoc_irq_enable(struct ath10k *ar) |
| 833 | { |
| 834 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 835 | int id; |
| 836 | |
| 837 | for (id = 0; id < CE_COUNT_MAX; id++) |
| 838 | enable_irq(ar_snoc->ce_irqs[id].irq_line); |
| 839 | } |
| 840 | |
| 841 | static void ath10k_snoc_rx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe) |
| 842 | { |
| 843 | struct ath10k_ce_pipe *ce_pipe; |
| 844 | struct ath10k_ce_ring *ce_ring; |
| 845 | struct sk_buff *skb; |
| 846 | struct ath10k *ar; |
| 847 | int i; |
| 848 | |
| 849 | ar = snoc_pipe->hif_ce_state; |
| 850 | ce_pipe = snoc_pipe->ce_hdl; |
| 851 | ce_ring = ce_pipe->dest_ring; |
| 852 | |
| 853 | if (!ce_ring) |
| 854 | return; |
| 855 | |
| 856 | if (!snoc_pipe->buf_sz) |
| 857 | return; |
| 858 | |
| 859 | for (i = 0; i < ce_ring->nentries; i++) { |
| 860 | skb = ce_ring->per_transfer_context[i]; |
| 861 | if (!skb) |
| 862 | continue; |
| 863 | |
| 864 | ce_ring->per_transfer_context[i] = NULL; |
| 865 | |
| 866 | dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr, |
| 867 | skb->len + skb_tailroom(skb), |
| 868 | DMA_FROM_DEVICE); |
| 869 | dev_kfree_skb_any(skb); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | static void ath10k_snoc_tx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe) |
| 874 | { |
| 875 | struct ath10k_ce_pipe *ce_pipe; |
| 876 | struct ath10k_ce_ring *ce_ring; |
| 877 | struct sk_buff *skb; |
| 878 | struct ath10k *ar; |
| 879 | int i; |
| 880 | |
| 881 | ar = snoc_pipe->hif_ce_state; |
| 882 | ce_pipe = snoc_pipe->ce_hdl; |
| 883 | ce_ring = ce_pipe->src_ring; |
| 884 | |
| 885 | if (!ce_ring) |
| 886 | return; |
| 887 | |
| 888 | if (!snoc_pipe->buf_sz) |
| 889 | return; |
| 890 | |
| 891 | for (i = 0; i < ce_ring->nentries; i++) { |
| 892 | skb = ce_ring->per_transfer_context[i]; |
| 893 | if (!skb) |
| 894 | continue; |
| 895 | |
| 896 | ce_ring->per_transfer_context[i] = NULL; |
| 897 | |
| 898 | ath10k_htc_tx_completion_handler(ar, skb); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | static void ath10k_snoc_buffer_cleanup(struct ath10k *ar) |
| 903 | { |
| 904 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 905 | struct ath10k_snoc_pipe *pipe_info; |
| 906 | int pipe_num; |
| 907 | |
| 908 | del_timer_sync(&ar_snoc->rx_post_retry); |
| 909 | for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) { |
| 910 | pipe_info = &ar_snoc->pipe_info[pipe_num]; |
| 911 | ath10k_snoc_rx_pipe_cleanup(pipe_info); |
| 912 | ath10k_snoc_tx_pipe_cleanup(pipe_info); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | static void ath10k_snoc_hif_stop(struct ath10k *ar) |
| 917 | { |
| 918 | if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
| 919 | ath10k_snoc_irq_disable(ar); |
| 920 | |
| 921 | napi_synchronize(&ar->napi); |
| 922 | napi_disable(&ar->napi); |
| 923 | ath10k_snoc_buffer_cleanup(ar); |
| 924 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n"); |
| 925 | } |
| 926 | |
| 927 | static int ath10k_snoc_hif_start(struct ath10k *ar) |
| 928 | { |
| 929 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 930 | |
| 931 | bitmap_clear(ar_snoc->pending_ce_irqs, 0, CE_COUNT_MAX); |
| 932 | napi_enable(&ar->napi); |
| 933 | ath10k_snoc_irq_enable(ar); |
| 934 | ath10k_snoc_rx_post(ar); |
| 935 | |
| 936 | clear_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags); |
| 937 | |
| 938 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n"); |
| 939 | |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | static int ath10k_snoc_init_pipes(struct ath10k *ar) |
| 944 | { |
| 945 | int i, ret; |
| 946 | |
| 947 | for (i = 0; i < CE_COUNT; i++) { |
| 948 | ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]); |
| 949 | if (ret) { |
| 950 | ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n", |
| 951 | i, ret); |
| 952 | return ret; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | static int ath10k_snoc_wlan_enable(struct ath10k *ar, |
| 960 | enum ath10k_firmware_mode fw_mode) |
| 961 | { |
| 962 | struct ath10k_tgt_pipe_cfg tgt_cfg[CE_COUNT_MAX]; |
| 963 | struct ath10k_qmi_wlan_enable_cfg cfg; |
| 964 | enum wlfw_driver_mode_enum_v01 mode; |
| 965 | int pipe_num; |
| 966 | |
| 967 | for (pipe_num = 0; pipe_num < CE_COUNT_MAX; pipe_num++) { |
| 968 | tgt_cfg[pipe_num].pipe_num = |
| 969 | target_ce_config_wlan[pipe_num].pipenum; |
| 970 | tgt_cfg[pipe_num].pipe_dir = |
| 971 | target_ce_config_wlan[pipe_num].pipedir; |
| 972 | tgt_cfg[pipe_num].nentries = |
| 973 | target_ce_config_wlan[pipe_num].nentries; |
| 974 | tgt_cfg[pipe_num].nbytes_max = |
| 975 | target_ce_config_wlan[pipe_num].nbytes_max; |
| 976 | tgt_cfg[pipe_num].flags = |
| 977 | target_ce_config_wlan[pipe_num].flags; |
| 978 | tgt_cfg[pipe_num].reserved = 0; |
| 979 | } |
| 980 | |
| 981 | cfg.num_ce_tgt_cfg = sizeof(target_ce_config_wlan) / |
| 982 | sizeof(struct ath10k_tgt_pipe_cfg); |
| 983 | cfg.ce_tgt_cfg = (struct ath10k_tgt_pipe_cfg *) |
| 984 | &tgt_cfg; |
| 985 | cfg.num_ce_svc_pipe_cfg = sizeof(target_service_to_ce_map_wlan) / |
| 986 | sizeof(struct ath10k_svc_pipe_cfg); |
| 987 | cfg.ce_svc_cfg = (struct ath10k_svc_pipe_cfg *) |
| 988 | &target_service_to_ce_map_wlan; |
| 989 | cfg.num_shadow_reg_cfg = sizeof(target_shadow_reg_cfg_map) / |
| 990 | sizeof(struct ath10k_shadow_reg_cfg); |
| 991 | cfg.shadow_reg_cfg = (struct ath10k_shadow_reg_cfg *) |
| 992 | &target_shadow_reg_cfg_map; |
| 993 | |
| 994 | switch (fw_mode) { |
| 995 | case ATH10K_FIRMWARE_MODE_NORMAL: |
| 996 | mode = QMI_WLFW_MISSION_V01; |
| 997 | break; |
| 998 | case ATH10K_FIRMWARE_MODE_UTF: |
| 999 | mode = QMI_WLFW_FTM_V01; |
| 1000 | break; |
| 1001 | default: |
| 1002 | ath10k_err(ar, "invalid firmware mode %d\n", fw_mode); |
| 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
| 1006 | return ath10k_qmi_wlan_enable(ar, &cfg, mode, |
| 1007 | NULL); |
| 1008 | } |
| 1009 | |
| 1010 | static void ath10k_snoc_wlan_disable(struct ath10k *ar) |
| 1011 | { |
| 1012 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1013 | |
| 1014 | /* If both ATH10K_FLAG_CRASH_FLUSH and ATH10K_SNOC_FLAG_RECOVERY |
| 1015 | * flags are not set, it means that the driver has restarted |
| 1016 | * due to a crash inject via debugfs. In this case, the driver |
| 1017 | * needs to restart the firmware and hence send qmi wlan disable, |
| 1018 | * during the driver restart sequence. |
| 1019 | */ |
| 1020 | if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags) || |
| 1021 | !test_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags)) |
| 1022 | ath10k_qmi_wlan_disable(ar); |
| 1023 | } |
| 1024 | |
| 1025 | static void ath10k_snoc_hif_power_down(struct ath10k *ar) |
| 1026 | { |
| 1027 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n"); |
| 1028 | |
| 1029 | ath10k_snoc_wlan_disable(ar); |
| 1030 | ath10k_ce_free_rri(ar); |
| 1031 | } |
| 1032 | |
| 1033 | static int ath10k_snoc_hif_power_up(struct ath10k *ar, |
| 1034 | enum ath10k_firmware_mode fw_mode) |
| 1035 | { |
| 1036 | int ret; |
| 1037 | |
| 1038 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "%s:WCN3990 driver state = %d\n", |
| 1039 | __func__, ar->state); |
| 1040 | |
| 1041 | ret = ath10k_snoc_wlan_enable(ar, fw_mode); |
| 1042 | if (ret) { |
| 1043 | ath10k_err(ar, "failed to enable wcn3990: %d\n", ret); |
| 1044 | return ret; |
| 1045 | } |
| 1046 | |
| 1047 | ath10k_ce_alloc_rri(ar); |
| 1048 | |
| 1049 | ret = ath10k_snoc_init_pipes(ar); |
| 1050 | if (ret) { |
| 1051 | ath10k_err(ar, "failed to initialize CE: %d\n", ret); |
| 1052 | goto err_free_rri; |
| 1053 | } |
| 1054 | |
| 1055 | ath10k_ce_enable_interrupts(ar); |
| 1056 | |
| 1057 | return 0; |
| 1058 | |
| 1059 | err_free_rri: |
| 1060 | ath10k_ce_free_rri(ar); |
| 1061 | ath10k_snoc_wlan_disable(ar); |
| 1062 | |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
| 1066 | static int ath10k_snoc_hif_set_target_log_mode(struct ath10k *ar, |
| 1067 | u8 fw_log_mode) |
| 1068 | { |
| 1069 | u8 fw_dbg_mode; |
| 1070 | |
| 1071 | if (fw_log_mode) |
| 1072 | fw_dbg_mode = ATH10K_ENABLE_FW_LOG_CE; |
| 1073 | else |
| 1074 | fw_dbg_mode = ATH10K_ENABLE_FW_LOG_DIAG; |
| 1075 | |
| 1076 | return ath10k_qmi_set_fw_log_mode(ar, fw_dbg_mode); |
| 1077 | } |
| 1078 | |
| 1079 | #ifdef CONFIG_PM |
| 1080 | static int ath10k_snoc_hif_suspend(struct ath10k *ar) |
| 1081 | { |
| 1082 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1083 | int ret; |
| 1084 | |
| 1085 | if (!device_may_wakeup(ar->dev)) |
| 1086 | return -EPERM; |
| 1087 | |
| 1088 | ret = enable_irq_wake(ar_snoc->ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line); |
| 1089 | if (ret) { |
| 1090 | ath10k_err(ar, "failed to enable wakeup irq :%d\n", ret); |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
| 1094 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device suspended\n"); |
| 1095 | |
| 1096 | return ret; |
| 1097 | } |
| 1098 | |
| 1099 | static int ath10k_snoc_hif_resume(struct ath10k *ar) |
| 1100 | { |
| 1101 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1102 | int ret; |
| 1103 | |
| 1104 | if (!device_may_wakeup(ar->dev)) |
| 1105 | return -EPERM; |
| 1106 | |
| 1107 | ret = disable_irq_wake(ar_snoc->ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line); |
| 1108 | if (ret) { |
| 1109 | ath10k_err(ar, "failed to disable wakeup irq: %d\n", ret); |
| 1110 | return ret; |
| 1111 | } |
| 1112 | |
| 1113 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device resumed\n"); |
| 1114 | |
| 1115 | return ret; |
| 1116 | } |
| 1117 | #endif |
| 1118 | |
| 1119 | static const struct ath10k_hif_ops ath10k_snoc_hif_ops = { |
| 1120 | .read32 = ath10k_snoc_read32, |
| 1121 | .write32 = ath10k_snoc_write32, |
| 1122 | .start = ath10k_snoc_hif_start, |
| 1123 | .stop = ath10k_snoc_hif_stop, |
| 1124 | .map_service_to_pipe = ath10k_snoc_hif_map_service_to_pipe, |
| 1125 | .get_default_pipe = ath10k_snoc_hif_get_default_pipe, |
| 1126 | .power_up = ath10k_snoc_hif_power_up, |
| 1127 | .power_down = ath10k_snoc_hif_power_down, |
| 1128 | .tx_sg = ath10k_snoc_hif_tx_sg, |
| 1129 | .send_complete_check = ath10k_snoc_hif_send_complete_check, |
| 1130 | .get_free_queue_number = ath10k_snoc_hif_get_free_queue_number, |
| 1131 | .get_target_info = ath10k_snoc_hif_get_target_info, |
| 1132 | .set_target_log_mode = ath10k_snoc_hif_set_target_log_mode, |
| 1133 | |
| 1134 | #ifdef CONFIG_PM |
| 1135 | .suspend = ath10k_snoc_hif_suspend, |
| 1136 | .resume = ath10k_snoc_hif_resume, |
| 1137 | #endif |
| 1138 | }; |
| 1139 | |
| 1140 | static const struct ath10k_bus_ops ath10k_snoc_bus_ops = { |
| 1141 | .read32 = ath10k_snoc_read32, |
| 1142 | .write32 = ath10k_snoc_write32, |
| 1143 | }; |
| 1144 | |
| 1145 | static int ath10k_snoc_get_ce_id_from_irq(struct ath10k *ar, int irq) |
| 1146 | { |
| 1147 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1148 | int i; |
| 1149 | |
| 1150 | for (i = 0; i < CE_COUNT_MAX; i++) { |
| 1151 | if (ar_snoc->ce_irqs[i].irq_line == irq) |
| 1152 | return i; |
| 1153 | } |
| 1154 | ath10k_err(ar, "No matching CE id for irq %d\n", irq); |
| 1155 | |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | |
| 1159 | static irqreturn_t ath10k_snoc_per_engine_handler(int irq, void *arg) |
| 1160 | { |
| 1161 | struct ath10k *ar = arg; |
| 1162 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1163 | int ce_id = ath10k_snoc_get_ce_id_from_irq(ar, irq); |
| 1164 | |
| 1165 | if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_snoc->pipe_info)) { |
| 1166 | ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq, |
| 1167 | ce_id); |
| 1168 | return IRQ_HANDLED; |
| 1169 | } |
| 1170 | |
| 1171 | ath10k_ce_disable_interrupt(ar, ce_id); |
| 1172 | set_bit(ce_id, ar_snoc->pending_ce_irqs); |
| 1173 | |
| 1174 | napi_schedule(&ar->napi); |
| 1175 | |
| 1176 | return IRQ_HANDLED; |
| 1177 | } |
| 1178 | |
| 1179 | static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget) |
| 1180 | { |
| 1181 | struct ath10k *ar = container_of(ctx, struct ath10k, napi); |
| 1182 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1183 | int done = 0; |
| 1184 | int ce_id; |
| 1185 | |
| 1186 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) { |
| 1187 | napi_complete(ctx); |
| 1188 | return done; |
| 1189 | } |
| 1190 | |
| 1191 | for (ce_id = 0; ce_id < CE_COUNT; ce_id++) |
| 1192 | if (test_and_clear_bit(ce_id, ar_snoc->pending_ce_irqs)) { |
| 1193 | ath10k_ce_per_engine_service(ar, ce_id); |
| 1194 | ath10k_ce_enable_interrupt(ar, ce_id); |
| 1195 | } |
| 1196 | |
| 1197 | done = ath10k_htt_txrx_compl_task(ar, budget); |
| 1198 | |
| 1199 | if (done < budget) |
| 1200 | napi_complete(ctx); |
| 1201 | |
| 1202 | return done; |
| 1203 | } |
| 1204 | |
| 1205 | static void ath10k_snoc_init_napi(struct ath10k *ar) |
| 1206 | { |
| 1207 | netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll, |
| 1208 | ATH10K_NAPI_BUDGET); |
| 1209 | } |
| 1210 | |
| 1211 | static int ath10k_snoc_request_irq(struct ath10k *ar) |
| 1212 | { |
| 1213 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1214 | int ret, id; |
| 1215 | |
| 1216 | for (id = 0; id < CE_COUNT_MAX; id++) { |
| 1217 | ret = request_irq(ar_snoc->ce_irqs[id].irq_line, |
| 1218 | ath10k_snoc_per_engine_handler, |
| 1219 | IRQF_NO_AUTOEN, ce_name[id], ar); |
| 1220 | if (ret) { |
| 1221 | ath10k_err(ar, |
| 1222 | "failed to register IRQ handler for CE %d: %d", |
| 1223 | id, ret); |
| 1224 | goto err_irq; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | return 0; |
| 1229 | |
| 1230 | err_irq: |
| 1231 | for (id -= 1; id >= 0; id--) |
| 1232 | free_irq(ar_snoc->ce_irqs[id].irq_line, ar); |
| 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | static void ath10k_snoc_free_irq(struct ath10k *ar) |
| 1238 | { |
| 1239 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1240 | int id; |
| 1241 | |
| 1242 | for (id = 0; id < CE_COUNT_MAX; id++) |
| 1243 | free_irq(ar_snoc->ce_irqs[id].irq_line, ar); |
| 1244 | } |
| 1245 | |
| 1246 | static int ath10k_snoc_resource_init(struct ath10k *ar) |
| 1247 | { |
| 1248 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1249 | struct platform_device *pdev; |
| 1250 | struct resource *res; |
| 1251 | int i, ret = 0; |
| 1252 | |
| 1253 | pdev = ar_snoc->dev; |
| 1254 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "membase"); |
| 1255 | if (!res) { |
| 1256 | ath10k_err(ar, "Memory base not found in DT\n"); |
| 1257 | return -EINVAL; |
| 1258 | } |
| 1259 | |
| 1260 | ar_snoc->mem_pa = res->start; |
| 1261 | ar_snoc->mem = devm_ioremap(&pdev->dev, ar_snoc->mem_pa, |
| 1262 | resource_size(res)); |
| 1263 | if (!ar_snoc->mem) { |
| 1264 | ath10k_err(ar, "Memory base ioremap failed with physical address %pa\n", |
| 1265 | &ar_snoc->mem_pa); |
| 1266 | return -EINVAL; |
| 1267 | } |
| 1268 | |
| 1269 | for (i = 0; i < CE_COUNT; i++) { |
| 1270 | res = platform_get_resource(ar_snoc->dev, IORESOURCE_IRQ, i); |
| 1271 | if (!res) { |
| 1272 | ath10k_err(ar, "failed to get IRQ%d\n", i); |
| 1273 | ret = -ENODEV; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | ar_snoc->ce_irqs[i].irq_line = res->start; |
| 1277 | } |
| 1278 | |
| 1279 | out: |
| 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | static void ath10k_snoc_quirks_init(struct ath10k *ar) |
| 1284 | { |
| 1285 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1286 | struct device *dev = &ar_snoc->dev->dev; |
| 1287 | |
| 1288 | if (of_property_read_bool(dev->of_node, "qcom,snoc-host-cap-8bit-quirk")) |
| 1289 | set_bit(ATH10K_SNOC_FLAG_8BIT_HOST_CAP_QUIRK, &ar_snoc->flags); |
| 1290 | } |
| 1291 | |
| 1292 | int ath10k_snoc_fw_indication(struct ath10k *ar, u64 type) |
| 1293 | { |
| 1294 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1295 | struct ath10k_bus_params bus_params = {}; |
| 1296 | int ret; |
| 1297 | |
| 1298 | if (test_bit(ATH10K_SNOC_FLAG_UNREGISTERING, &ar_snoc->flags)) |
| 1299 | return 0; |
| 1300 | |
| 1301 | switch (type) { |
| 1302 | case ATH10K_QMI_EVENT_FW_READY_IND: |
| 1303 | if (test_bit(ATH10K_SNOC_FLAG_REGISTERED, &ar_snoc->flags)) { |
| 1304 | queue_work(ar->workqueue, &ar->restart_work); |
| 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | bus_params.dev_type = ATH10K_DEV_TYPE_LL; |
| 1309 | bus_params.chip_id = ar_snoc->target_info.soc_version; |
| 1310 | ret = ath10k_core_register(ar, &bus_params); |
| 1311 | if (ret) { |
| 1312 | ath10k_err(ar, "Failed to register driver core: %d\n", |
| 1313 | ret); |
| 1314 | return ret; |
| 1315 | } |
| 1316 | set_bit(ATH10K_SNOC_FLAG_REGISTERED, &ar_snoc->flags); |
| 1317 | break; |
| 1318 | case ATH10K_QMI_EVENT_FW_DOWN_IND: |
| 1319 | set_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags); |
| 1320 | set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags); |
| 1321 | break; |
| 1322 | default: |
| 1323 | ath10k_err(ar, "invalid fw indication: %llx\n", type); |
| 1324 | return -EINVAL; |
| 1325 | } |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
| 1330 | static int ath10k_snoc_setup_resource(struct ath10k *ar) |
| 1331 | { |
| 1332 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1333 | struct ath10k_ce *ce = ath10k_ce_priv(ar); |
| 1334 | struct ath10k_snoc_pipe *pipe; |
| 1335 | int i, ret; |
| 1336 | |
| 1337 | timer_setup(&ar_snoc->rx_post_retry, ath10k_snoc_rx_replenish_retry, 0); |
| 1338 | spin_lock_init(&ce->ce_lock); |
| 1339 | for (i = 0; i < CE_COUNT; i++) { |
| 1340 | pipe = &ar_snoc->pipe_info[i]; |
| 1341 | pipe->ce_hdl = &ce->ce_states[i]; |
| 1342 | pipe->pipe_num = i; |
| 1343 | pipe->hif_ce_state = ar; |
| 1344 | |
| 1345 | ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]); |
| 1346 | if (ret) { |
| 1347 | ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n", |
| 1348 | i, ret); |
| 1349 | return ret; |
| 1350 | } |
| 1351 | |
| 1352 | pipe->buf_sz = host_ce_config_wlan[i].src_sz_max; |
| 1353 | } |
| 1354 | ath10k_snoc_init_napi(ar); |
| 1355 | |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | static void ath10k_snoc_release_resource(struct ath10k *ar) |
| 1360 | { |
| 1361 | int i; |
| 1362 | |
| 1363 | netif_napi_del(&ar->napi); |
| 1364 | for (i = 0; i < CE_COUNT; i++) |
| 1365 | ath10k_ce_free_pipe(ar, i); |
| 1366 | } |
| 1367 | |
| 1368 | static int ath10k_get_vreg_info(struct ath10k *ar, struct device *dev, |
| 1369 | struct ath10k_vreg_info *vreg_info) |
| 1370 | { |
| 1371 | struct regulator *reg; |
| 1372 | int ret = 0; |
| 1373 | |
| 1374 | reg = devm_regulator_get_optional(dev, vreg_info->name); |
| 1375 | |
| 1376 | if (IS_ERR(reg)) { |
| 1377 | ret = PTR_ERR(reg); |
| 1378 | |
| 1379 | if (ret == -EPROBE_DEFER) { |
| 1380 | ath10k_err(ar, "EPROBE_DEFER for regulator: %s\n", |
| 1381 | vreg_info->name); |
| 1382 | return ret; |
| 1383 | } |
| 1384 | if (vreg_info->required) { |
| 1385 | ath10k_err(ar, "Regulator %s doesn't exist: %d\n", |
| 1386 | vreg_info->name, ret); |
| 1387 | return ret; |
| 1388 | } |
| 1389 | ath10k_dbg(ar, ATH10K_DBG_SNOC, |
| 1390 | "Optional regulator %s doesn't exist: %d\n", |
| 1391 | vreg_info->name, ret); |
| 1392 | goto done; |
| 1393 | } |
| 1394 | |
| 1395 | vreg_info->reg = reg; |
| 1396 | |
| 1397 | done: |
| 1398 | ath10k_dbg(ar, ATH10K_DBG_SNOC, |
| 1399 | "snog vreg %s min_v %u max_v %u load_ua %u settle_delay %lu\n", |
| 1400 | vreg_info->name, vreg_info->min_v, vreg_info->max_v, |
| 1401 | vreg_info->load_ua, vreg_info->settle_delay); |
| 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static int ath10k_get_clk_info(struct ath10k *ar, struct device *dev, |
| 1407 | struct ath10k_clk_info *clk_info) |
| 1408 | { |
| 1409 | struct clk *handle; |
| 1410 | int ret = 0; |
| 1411 | |
| 1412 | handle = devm_clk_get(dev, clk_info->name); |
| 1413 | if (IS_ERR(handle)) { |
| 1414 | ret = PTR_ERR(handle); |
| 1415 | if (clk_info->required) { |
| 1416 | ath10k_err(ar, "snoc clock %s isn't available: %d\n", |
| 1417 | clk_info->name, ret); |
| 1418 | return ret; |
| 1419 | } |
| 1420 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc ignoring clock %s: %d\n", |
| 1421 | clk_info->name, |
| 1422 | ret); |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
| 1426 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s freq %u\n", |
| 1427 | clk_info->name, clk_info->freq); |
| 1428 | |
| 1429 | clk_info->handle = handle; |
| 1430 | |
| 1431 | return ret; |
| 1432 | } |
| 1433 | |
| 1434 | static int __ath10k_snoc_vreg_on(struct ath10k *ar, |
| 1435 | struct ath10k_vreg_info *vreg_info) |
| 1436 | { |
| 1437 | int ret; |
| 1438 | |
| 1439 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being enabled\n", |
| 1440 | vreg_info->name); |
| 1441 | |
| 1442 | ret = regulator_set_voltage(vreg_info->reg, vreg_info->min_v, |
| 1443 | vreg_info->max_v); |
| 1444 | if (ret) { |
| 1445 | ath10k_err(ar, |
| 1446 | "failed to set regulator %s voltage-min: %d voltage-max: %d\n", |
| 1447 | vreg_info->name, vreg_info->min_v, vreg_info->max_v); |
| 1448 | return ret; |
| 1449 | } |
| 1450 | |
| 1451 | if (vreg_info->load_ua) { |
| 1452 | ret = regulator_set_load(vreg_info->reg, vreg_info->load_ua); |
| 1453 | if (ret < 0) { |
| 1454 | ath10k_err(ar, "failed to set regulator %s load: %d\n", |
| 1455 | vreg_info->name, vreg_info->load_ua); |
| 1456 | goto err_set_load; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | ret = regulator_enable(vreg_info->reg); |
| 1461 | if (ret) { |
| 1462 | ath10k_err(ar, "failed to enable regulator %s\n", |
| 1463 | vreg_info->name); |
| 1464 | goto err_enable; |
| 1465 | } |
| 1466 | |
| 1467 | if (vreg_info->settle_delay) |
| 1468 | udelay(vreg_info->settle_delay); |
| 1469 | |
| 1470 | return 0; |
| 1471 | |
| 1472 | err_enable: |
| 1473 | regulator_set_load(vreg_info->reg, 0); |
| 1474 | err_set_load: |
| 1475 | regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v); |
| 1476 | |
| 1477 | return ret; |
| 1478 | } |
| 1479 | |
| 1480 | static int __ath10k_snoc_vreg_off(struct ath10k *ar, |
| 1481 | struct ath10k_vreg_info *vreg_info) |
| 1482 | { |
| 1483 | int ret; |
| 1484 | |
| 1485 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being disabled\n", |
| 1486 | vreg_info->name); |
| 1487 | |
| 1488 | ret = regulator_disable(vreg_info->reg); |
| 1489 | if (ret) |
| 1490 | ath10k_err(ar, "failed to disable regulator %s\n", |
| 1491 | vreg_info->name); |
| 1492 | |
| 1493 | ret = regulator_set_load(vreg_info->reg, 0); |
| 1494 | if (ret < 0) |
| 1495 | ath10k_err(ar, "failed to set load %s\n", vreg_info->name); |
| 1496 | |
| 1497 | ret = regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v); |
| 1498 | if (ret) |
| 1499 | ath10k_err(ar, "failed to set voltage %s\n", vreg_info->name); |
| 1500 | |
| 1501 | return ret; |
| 1502 | } |
| 1503 | |
| 1504 | static int ath10k_snoc_vreg_on(struct ath10k *ar) |
| 1505 | { |
| 1506 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1507 | struct ath10k_vreg_info *vreg_info; |
| 1508 | int ret = 0; |
| 1509 | int i; |
| 1510 | |
| 1511 | for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) { |
| 1512 | vreg_info = &ar_snoc->vreg[i]; |
| 1513 | |
| 1514 | if (!vreg_info->reg) |
| 1515 | continue; |
| 1516 | |
| 1517 | ret = __ath10k_snoc_vreg_on(ar, vreg_info); |
| 1518 | if (ret) |
| 1519 | goto err_reg_config; |
| 1520 | } |
| 1521 | |
| 1522 | return 0; |
| 1523 | |
| 1524 | err_reg_config: |
| 1525 | for (i = i - 1; i >= 0; i--) { |
| 1526 | vreg_info = &ar_snoc->vreg[i]; |
| 1527 | |
| 1528 | if (!vreg_info->reg) |
| 1529 | continue; |
| 1530 | |
| 1531 | __ath10k_snoc_vreg_off(ar, vreg_info); |
| 1532 | } |
| 1533 | |
| 1534 | return ret; |
| 1535 | } |
| 1536 | |
| 1537 | static int ath10k_snoc_vreg_off(struct ath10k *ar) |
| 1538 | { |
| 1539 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1540 | struct ath10k_vreg_info *vreg_info; |
| 1541 | int ret = 0; |
| 1542 | int i; |
| 1543 | |
| 1544 | for (i = ARRAY_SIZE(vreg_cfg) - 1; i >= 0; i--) { |
| 1545 | vreg_info = &ar_snoc->vreg[i]; |
| 1546 | |
| 1547 | if (!vreg_info->reg) |
| 1548 | continue; |
| 1549 | |
| 1550 | ret = __ath10k_snoc_vreg_off(ar, vreg_info); |
| 1551 | } |
| 1552 | |
| 1553 | return ret; |
| 1554 | } |
| 1555 | |
| 1556 | static int ath10k_snoc_clk_init(struct ath10k *ar) |
| 1557 | { |
| 1558 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1559 | struct ath10k_clk_info *clk_info; |
| 1560 | int ret = 0; |
| 1561 | int i; |
| 1562 | |
| 1563 | for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) { |
| 1564 | clk_info = &ar_snoc->clk[i]; |
| 1565 | |
| 1566 | if (!clk_info->handle) |
| 1567 | continue; |
| 1568 | |
| 1569 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being enabled\n", |
| 1570 | clk_info->name); |
| 1571 | |
| 1572 | if (clk_info->freq) { |
| 1573 | ret = clk_set_rate(clk_info->handle, clk_info->freq); |
| 1574 | |
| 1575 | if (ret) { |
| 1576 | ath10k_err(ar, "failed to set clock %s freq %u\n", |
| 1577 | clk_info->name, clk_info->freq); |
| 1578 | goto err_clock_config; |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | ret = clk_prepare_enable(clk_info->handle); |
| 1583 | if (ret) { |
| 1584 | ath10k_err(ar, "failed to enable clock %s\n", |
| 1585 | clk_info->name); |
| 1586 | goto err_clock_config; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | return 0; |
| 1591 | |
| 1592 | err_clock_config: |
| 1593 | for (i = i - 1; i >= 0; i--) { |
| 1594 | clk_info = &ar_snoc->clk[i]; |
| 1595 | |
| 1596 | if (!clk_info->handle) |
| 1597 | continue; |
| 1598 | |
| 1599 | clk_disable_unprepare(clk_info->handle); |
| 1600 | } |
| 1601 | |
| 1602 | return ret; |
| 1603 | } |
| 1604 | |
| 1605 | static int ath10k_snoc_clk_deinit(struct ath10k *ar) |
| 1606 | { |
| 1607 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1608 | struct ath10k_clk_info *clk_info; |
| 1609 | int i; |
| 1610 | |
| 1611 | for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) { |
| 1612 | clk_info = &ar_snoc->clk[i]; |
| 1613 | |
| 1614 | if (!clk_info->handle) |
| 1615 | continue; |
| 1616 | |
| 1617 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being disabled\n", |
| 1618 | clk_info->name); |
| 1619 | |
| 1620 | clk_disable_unprepare(clk_info->handle); |
| 1621 | } |
| 1622 | |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | static int ath10k_hw_power_on(struct ath10k *ar) |
| 1627 | { |
| 1628 | int ret; |
| 1629 | |
| 1630 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power on\n"); |
| 1631 | |
| 1632 | ret = ath10k_snoc_vreg_on(ar); |
| 1633 | if (ret) |
| 1634 | return ret; |
| 1635 | |
| 1636 | ret = ath10k_snoc_clk_init(ar); |
| 1637 | if (ret) |
| 1638 | goto vreg_off; |
| 1639 | |
| 1640 | return ret; |
| 1641 | |
| 1642 | vreg_off: |
| 1643 | ath10k_snoc_vreg_off(ar); |
| 1644 | return ret; |
| 1645 | } |
| 1646 | |
| 1647 | static int ath10k_hw_power_off(struct ath10k *ar) |
| 1648 | { |
| 1649 | int ret; |
| 1650 | |
| 1651 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power off\n"); |
| 1652 | |
| 1653 | ath10k_snoc_clk_deinit(ar); |
| 1654 | |
| 1655 | ret = ath10k_snoc_vreg_off(ar); |
| 1656 | |
| 1657 | return ret; |
| 1658 | } |
| 1659 | |
| 1660 | static const struct of_device_id ath10k_snoc_dt_match[] = { |
| 1661 | { .compatible = "qcom,wcn3990-wifi", |
| 1662 | .data = &drv_priv, |
| 1663 | }, |
| 1664 | { } |
| 1665 | }; |
| 1666 | MODULE_DEVICE_TABLE(of, ath10k_snoc_dt_match); |
| 1667 | |
| 1668 | static int ath10k_snoc_probe(struct platform_device *pdev) |
| 1669 | { |
| 1670 | const struct ath10k_snoc_drv_priv *drv_data; |
| 1671 | const struct of_device_id *of_id; |
| 1672 | struct ath10k_snoc *ar_snoc; |
| 1673 | struct device *dev; |
| 1674 | struct ath10k *ar; |
| 1675 | u32 msa_size; |
| 1676 | int ret; |
| 1677 | u32 i; |
| 1678 | |
| 1679 | of_id = of_match_device(ath10k_snoc_dt_match, &pdev->dev); |
| 1680 | if (!of_id) { |
| 1681 | dev_err(&pdev->dev, "failed to find matching device tree id\n"); |
| 1682 | return -EINVAL; |
| 1683 | } |
| 1684 | |
| 1685 | drv_data = of_id->data; |
| 1686 | dev = &pdev->dev; |
| 1687 | |
| 1688 | ret = dma_set_mask_and_coherent(dev, drv_data->dma_mask); |
| 1689 | if (ret) { |
| 1690 | dev_err(dev, "failed to set dma mask: %d", ret); |
| 1691 | return ret; |
| 1692 | } |
| 1693 | |
| 1694 | ar = ath10k_core_create(sizeof(*ar_snoc), dev, ATH10K_BUS_SNOC, |
| 1695 | drv_data->hw_rev, &ath10k_snoc_hif_ops); |
| 1696 | if (!ar) { |
| 1697 | dev_err(dev, "failed to allocate core\n"); |
| 1698 | return -ENOMEM; |
| 1699 | } |
| 1700 | |
| 1701 | ar_snoc = ath10k_snoc_priv(ar); |
| 1702 | ar_snoc->dev = pdev; |
| 1703 | platform_set_drvdata(pdev, ar); |
| 1704 | ar_snoc->ar = ar; |
| 1705 | ar_snoc->ce.bus_ops = &ath10k_snoc_bus_ops; |
| 1706 | ar->ce_priv = &ar_snoc->ce; |
| 1707 | msa_size = drv_data->msa_size; |
| 1708 | |
| 1709 | ath10k_snoc_quirks_init(ar); |
| 1710 | |
| 1711 | ret = ath10k_snoc_resource_init(ar); |
| 1712 | if (ret) { |
| 1713 | ath10k_warn(ar, "failed to initialize resource: %d\n", ret); |
| 1714 | goto err_core_destroy; |
| 1715 | } |
| 1716 | |
| 1717 | ret = ath10k_snoc_setup_resource(ar); |
| 1718 | if (ret) { |
| 1719 | ath10k_warn(ar, "failed to setup resource: %d\n", ret); |
| 1720 | goto err_core_destroy; |
| 1721 | } |
| 1722 | ret = ath10k_snoc_request_irq(ar); |
| 1723 | if (ret) { |
| 1724 | ath10k_warn(ar, "failed to request irqs: %d\n", ret); |
| 1725 | goto err_release_resource; |
| 1726 | } |
| 1727 | |
| 1728 | ar_snoc->vreg = vreg_cfg; |
| 1729 | for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) { |
| 1730 | ret = ath10k_get_vreg_info(ar, dev, &ar_snoc->vreg[i]); |
| 1731 | if (ret) |
| 1732 | goto err_free_irq; |
| 1733 | } |
| 1734 | |
| 1735 | ar_snoc->clk = clk_cfg; |
| 1736 | for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) { |
| 1737 | ret = ath10k_get_clk_info(ar, dev, &ar_snoc->clk[i]); |
| 1738 | if (ret) |
| 1739 | goto err_free_irq; |
| 1740 | } |
| 1741 | |
| 1742 | ret = ath10k_hw_power_on(ar); |
| 1743 | if (ret) { |
| 1744 | ath10k_err(ar, "failed to power on device: %d\n", ret); |
| 1745 | goto err_free_irq; |
| 1746 | } |
| 1747 | |
| 1748 | ret = ath10k_qmi_init(ar, msa_size); |
| 1749 | if (ret) { |
| 1750 | ath10k_warn(ar, "failed to register wlfw qmi client: %d\n", ret); |
| 1751 | goto err_power_off; |
| 1752 | } |
| 1753 | |
| 1754 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc probe\n"); |
| 1755 | |
| 1756 | return 0; |
| 1757 | |
| 1758 | err_power_off: |
| 1759 | ath10k_hw_power_off(ar); |
| 1760 | |
| 1761 | err_free_irq: |
| 1762 | ath10k_snoc_free_irq(ar); |
| 1763 | |
| 1764 | err_release_resource: |
| 1765 | ath10k_snoc_release_resource(ar); |
| 1766 | |
| 1767 | err_core_destroy: |
| 1768 | ath10k_core_destroy(ar); |
| 1769 | |
| 1770 | return ret; |
| 1771 | } |
| 1772 | |
| 1773 | static int ath10k_snoc_remove(struct platform_device *pdev) |
| 1774 | { |
| 1775 | struct ath10k *ar = platform_get_drvdata(pdev); |
| 1776 | struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar); |
| 1777 | |
| 1778 | ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc remove\n"); |
| 1779 | |
| 1780 | reinit_completion(&ar->driver_recovery); |
| 1781 | |
| 1782 | if (test_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags)) |
| 1783 | wait_for_completion_timeout(&ar->driver_recovery, 3 * HZ); |
| 1784 | |
| 1785 | set_bit(ATH10K_SNOC_FLAG_UNREGISTERING, &ar_snoc->flags); |
| 1786 | |
| 1787 | ath10k_core_unregister(ar); |
| 1788 | ath10k_hw_power_off(ar); |
| 1789 | ath10k_snoc_free_irq(ar); |
| 1790 | ath10k_snoc_release_resource(ar); |
| 1791 | ath10k_qmi_deinit(ar); |
| 1792 | ath10k_core_destroy(ar); |
| 1793 | |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | static struct platform_driver ath10k_snoc_driver = { |
| 1798 | .probe = ath10k_snoc_probe, |
| 1799 | .remove = ath10k_snoc_remove, |
| 1800 | .driver = { |
| 1801 | .name = "ath10k_snoc", |
| 1802 | .of_match_table = ath10k_snoc_dt_match, |
| 1803 | }, |
| 1804 | }; |
| 1805 | module_platform_driver(ath10k_snoc_driver); |
| 1806 | |
| 1807 | MODULE_AUTHOR("Qualcomm"); |
| 1808 | MODULE_LICENSE("Dual BSD/GPL"); |
| 1809 | MODULE_DESCRIPTION("Driver support for Atheros WCN3990 SNOC devices"); |