1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
7 #include <linux/module.h>
20 #define ATH11K_PCI_BAR_NUM 0
21 #define ATH11K_PCI_DMA_MASK 36
22 #define ATH11K_PCI_COHERENT_DMA_MASK 32
24 #define TCSR_SOC_HW_VERSION 0x0224
25 #define TCSR_SOC_HW_VERSION_MAJOR_MASK GENMASK(11, 8)
26 #define TCSR_SOC_HW_VERSION_MINOR_MASK GENMASK(7, 0)
28 #define QCA6390_DEVICE_ID 0x1101
29 #define QCN9074_DEVICE_ID 0x1104
30 #define WCN6855_DEVICE_ID 0x1103
32 #define TCSR_SOC_HW_SUB_VER 0x1910010
34 static const struct pci_device_id ath11k_pci_id_table
[] = {
35 { PCI_VDEVICE(QCOM
, QCA6390_DEVICE_ID
) },
36 { PCI_VDEVICE(QCOM
, WCN6855_DEVICE_ID
) },
37 { PCI_VDEVICE(QCOM
, QCN9074_DEVICE_ID
) },
41 MODULE_DEVICE_TABLE(pci
, ath11k_pci_id_table
);
43 static int ath11k_pci_bus_wake_up(struct ath11k_base
*ab
)
45 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
47 return mhi_device_get_sync(ab_pci
->mhi_ctrl
->mhi_dev
);
50 static void ath11k_pci_bus_release(struct ath11k_base
*ab
)
52 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
54 mhi_device_put(ab_pci
->mhi_ctrl
->mhi_dev
);
57 static u32
ath11k_pci_get_window_start(struct ath11k_base
*ab
, u32 offset
)
59 if (!ab
->hw_params
.static_window_map
)
60 return ATH11K_PCI_WINDOW_START
;
62 if ((offset
^ HAL_SEQ_WCSS_UMAC_OFFSET
) < ATH11K_PCI_WINDOW_RANGE_MASK
)
63 /* if offset lies within DP register range, use 3rd window */
64 return 3 * ATH11K_PCI_WINDOW_START
;
65 else if ((offset
^ HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab
)) <
66 ATH11K_PCI_WINDOW_RANGE_MASK
)
67 /* if offset lies within CE register range, use 2nd window */
68 return 2 * ATH11K_PCI_WINDOW_START
;
70 return ATH11K_PCI_WINDOW_START
;
73 static inline void ath11k_pci_select_window(struct ath11k_pci
*ab_pci
, u32 offset
)
75 struct ath11k_base
*ab
= ab_pci
->ab
;
77 u32 window
= FIELD_GET(ATH11K_PCI_WINDOW_VALUE_MASK
, offset
);
79 lockdep_assert_held(&ab_pci
->window_lock
);
81 if (window
!= ab_pci
->register_window
) {
82 iowrite32(ATH11K_PCI_WINDOW_ENABLE_BIT
| window
,
83 ab
->mem
+ ATH11K_PCI_WINDOW_REG_ADDRESS
);
84 ioread32(ab
->mem
+ ATH11K_PCI_WINDOW_REG_ADDRESS
);
85 ab_pci
->register_window
= window
;
90 ath11k_pci_window_write32(struct ath11k_base
*ab
, u32 offset
, u32 value
)
92 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
95 window_start
= ath11k_pci_get_window_start(ab
, offset
);
97 if (window_start
== ATH11K_PCI_WINDOW_START
) {
98 spin_lock_bh(&ab_pci
->window_lock
);
99 ath11k_pci_select_window(ab_pci
, offset
);
100 iowrite32(value
, ab
->mem
+ window_start
+
101 (offset
& ATH11K_PCI_WINDOW_RANGE_MASK
));
102 spin_unlock_bh(&ab_pci
->window_lock
);
104 iowrite32(value
, ab
->mem
+ window_start
+
105 (offset
& ATH11K_PCI_WINDOW_RANGE_MASK
));
109 static u32
ath11k_pci_window_read32(struct ath11k_base
*ab
, u32 offset
)
111 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
112 u32 window_start
, val
;
114 window_start
= ath11k_pci_get_window_start(ab
, offset
);
116 if (window_start
== ATH11K_PCI_WINDOW_START
) {
117 spin_lock_bh(&ab_pci
->window_lock
);
118 ath11k_pci_select_window(ab_pci
, offset
);
119 val
= ioread32(ab
->mem
+ window_start
+
120 (offset
& ATH11K_PCI_WINDOW_RANGE_MASK
));
121 spin_unlock_bh(&ab_pci
->window_lock
);
123 val
= ioread32(ab
->mem
+ window_start
+
124 (offset
& ATH11K_PCI_WINDOW_RANGE_MASK
));
130 int ath11k_pci_get_msi_irq(struct ath11k_base
*ab
, unsigned int vector
)
132 struct pci_dev
*pci_dev
= to_pci_dev(ab
->dev
);
134 return pci_irq_vector(pci_dev
, vector
);
137 static const struct ath11k_pci_ops ath11k_pci_ops_qca6390
= {
138 .wakeup
= ath11k_pci_bus_wake_up
,
139 .release
= ath11k_pci_bus_release
,
140 .get_msi_irq
= ath11k_pci_get_msi_irq
,
141 .window_write32
= ath11k_pci_window_write32
,
142 .window_read32
= ath11k_pci_window_read32
,
145 static const struct ath11k_pci_ops ath11k_pci_ops_qcn9074
= {
148 .get_msi_irq
= ath11k_pci_get_msi_irq
,
149 .window_write32
= ath11k_pci_window_write32
,
150 .window_read32
= ath11k_pci_window_read32
,
153 static const struct ath11k_msi_config msi_config_one_msi
= {
156 .users
= (struct ath11k_msi_user
[]) {
157 { .name
= "MHI", .num_vectors
= 3, .base_vector
= 0 },
158 { .name
= "CE", .num_vectors
= 1, .base_vector
= 0 },
159 { .name
= "WAKE", .num_vectors
= 1, .base_vector
= 0 },
160 { .name
= "DP", .num_vectors
= 1, .base_vector
= 0 },
164 static inline void ath11k_pci_select_static_window(struct ath11k_pci
*ab_pci
)
170 umac_window
= FIELD_GET(ATH11K_PCI_WINDOW_VALUE_MASK
, HAL_SEQ_WCSS_UMAC_OFFSET
);
171 ce_window
= FIELD_GET(ATH11K_PCI_WINDOW_VALUE_MASK
, HAL_CE_WFSS_CE_REG_BASE
);
172 window
= (umac_window
<< 12) | (ce_window
<< 6);
174 iowrite32(ATH11K_PCI_WINDOW_ENABLE_BIT
| window
,
175 ab_pci
->ab
->mem
+ ATH11K_PCI_WINDOW_REG_ADDRESS
);
178 static void ath11k_pci_soc_global_reset(struct ath11k_base
*ab
)
182 val
= ath11k_pcic_read32(ab
, PCIE_SOC_GLOBAL_RESET
);
184 val
|= PCIE_SOC_GLOBAL_RESET_V
;
186 ath11k_pcic_write32(ab
, PCIE_SOC_GLOBAL_RESET
, val
);
188 /* TODO: exact time to sleep is uncertain */
192 /* Need to toggle V bit back otherwise stuck in reset status */
193 val
&= ~PCIE_SOC_GLOBAL_RESET_V
;
195 ath11k_pcic_write32(ab
, PCIE_SOC_GLOBAL_RESET
, val
);
199 val
= ath11k_pcic_read32(ab
, PCIE_SOC_GLOBAL_RESET
);
200 if (val
== 0xffffffff)
201 ath11k_warn(ab
, "link down error during global reset\n");
204 static void ath11k_pci_clear_dbg_registers(struct ath11k_base
*ab
)
209 val
= ath11k_pcic_read32(ab
, PCIE_Q6_COOKIE_ADDR
);
210 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "pcie_q6_cookie_addr 0x%x\n", val
);
212 val
= ath11k_pcic_read32(ab
, WLAON_WARM_SW_ENTRY
);
213 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "wlaon_warm_sw_entry 0x%x\n", val
);
215 /* TODO: exact time to sleep is uncertain */
218 /* write 0 to WLAON_WARM_SW_ENTRY to prevent Q6 from
219 * continuing warm path and entering dead loop.
221 ath11k_pcic_write32(ab
, WLAON_WARM_SW_ENTRY
, 0);
224 val
= ath11k_pcic_read32(ab
, WLAON_WARM_SW_ENTRY
);
225 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "wlaon_warm_sw_entry 0x%x\n", val
);
227 /* A read clear register. clear the register to prevent
228 * Q6 from entering wrong code path.
230 val
= ath11k_pcic_read32(ab
, WLAON_SOC_RESET_CAUSE_REG
);
231 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "soc reset cause %d\n", val
);
234 static int ath11k_pci_set_link_reg(struct ath11k_base
*ab
,
235 u32 offset
, u32 value
, u32 mask
)
240 v
= ath11k_pcic_read32(ab
, offset
);
241 if ((v
& mask
) == value
)
244 for (i
= 0; i
< 10; i
++) {
245 ath11k_pcic_write32(ab
, offset
, (v
& ~mask
) | value
);
247 v
= ath11k_pcic_read32(ab
, offset
);
248 if ((v
& mask
) == value
)
254 ath11k_warn(ab
, "failed to set pcie link register 0x%08x: 0x%08x != 0x%08x\n",
255 offset
, v
& mask
, value
);
260 static int ath11k_pci_fix_l1ss(struct ath11k_base
*ab
)
264 ret
= ath11k_pci_set_link_reg(ab
,
265 PCIE_QSERDES_COM_SYSCLK_EN_SEL_REG(ab
),
266 PCIE_QSERDES_COM_SYSCLK_EN_SEL_VAL
,
267 PCIE_QSERDES_COM_SYSCLK_EN_SEL_MSK
);
269 ath11k_warn(ab
, "failed to set sysclk: %d\n", ret
);
273 ret
= ath11k_pci_set_link_reg(ab
,
274 PCIE_PCS_OSC_DTCT_CONFIG1_REG(ab
),
275 PCIE_PCS_OSC_DTCT_CONFIG1_VAL
,
276 PCIE_PCS_OSC_DTCT_CONFIG_MSK
);
278 ath11k_warn(ab
, "failed to set dtct config1 error: %d\n", ret
);
282 ret
= ath11k_pci_set_link_reg(ab
,
283 PCIE_PCS_OSC_DTCT_CONFIG2_REG(ab
),
284 PCIE_PCS_OSC_DTCT_CONFIG2_VAL
,
285 PCIE_PCS_OSC_DTCT_CONFIG_MSK
);
287 ath11k_warn(ab
, "failed to set dtct config2: %d\n", ret
);
291 ret
= ath11k_pci_set_link_reg(ab
,
292 PCIE_PCS_OSC_DTCT_CONFIG4_REG(ab
),
293 PCIE_PCS_OSC_DTCT_CONFIG4_VAL
,
294 PCIE_PCS_OSC_DTCT_CONFIG_MSK
);
296 ath11k_warn(ab
, "failed to set dtct config4: %d\n", ret
);
303 static void ath11k_pci_enable_ltssm(struct ath11k_base
*ab
)
308 val
= ath11k_pcic_read32(ab
, PCIE_PCIE_PARF_LTSSM
);
310 /* PCIE link seems very unstable after the Hot Reset*/
311 for (i
= 0; val
!= PARM_LTSSM_VALUE
&& i
< 5; i
++) {
312 if (val
== 0xffffffff)
315 ath11k_pcic_write32(ab
, PCIE_PCIE_PARF_LTSSM
, PARM_LTSSM_VALUE
);
316 val
= ath11k_pcic_read32(ab
, PCIE_PCIE_PARF_LTSSM
);
319 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "ltssm 0x%x\n", val
);
321 val
= ath11k_pcic_read32(ab
, GCC_GCC_PCIE_HOT_RST
);
322 val
|= GCC_GCC_PCIE_HOT_RST_VAL
;
323 ath11k_pcic_write32(ab
, GCC_GCC_PCIE_HOT_RST
, val
);
324 val
= ath11k_pcic_read32(ab
, GCC_GCC_PCIE_HOT_RST
);
326 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "pcie_hot_rst 0x%x\n", val
);
331 static void ath11k_pci_clear_all_intrs(struct ath11k_base
*ab
)
333 /* This is a WAR for PCIE Hotreset.
334 * When target receive Hotreset, but will set the interrupt.
335 * So when download SBL again, SBL will open Interrupt and
336 * receive it, and crash immediately.
338 ath11k_pcic_write32(ab
, PCIE_PCIE_INT_ALL_CLEAR
, PCIE_INT_CLEAR_ALL
);
341 static void ath11k_pci_set_wlaon_pwr_ctrl(struct ath11k_base
*ab
)
345 val
= ath11k_pcic_read32(ab
, WLAON_QFPROM_PWR_CTRL_REG
);
346 val
&= ~QFPROM_PWR_CTRL_VDD4BLOW_MASK
;
347 ath11k_pcic_write32(ab
, WLAON_QFPROM_PWR_CTRL_REG
, val
);
350 static void ath11k_pci_force_wake(struct ath11k_base
*ab
)
352 ath11k_pcic_write32(ab
, PCIE_SOC_WAKE_PCIE_LOCAL_REG
, 1);
356 static void ath11k_pci_sw_reset(struct ath11k_base
*ab
, bool power_on
)
361 ath11k_pci_enable_ltssm(ab
);
362 ath11k_pci_clear_all_intrs(ab
);
363 ath11k_pci_set_wlaon_pwr_ctrl(ab
);
364 if (ab
->hw_params
.fix_l1ss
)
365 ath11k_pci_fix_l1ss(ab
);
368 ath11k_mhi_clear_vector(ab
);
369 ath11k_pci_clear_dbg_registers(ab
);
370 ath11k_pci_soc_global_reset(ab
);
371 ath11k_mhi_set_mhictrl_reset(ab
);
374 static void ath11k_pci_init_qmi_ce_config(struct ath11k_base
*ab
)
376 struct ath11k_qmi_ce_cfg
*cfg
= &ab
->qmi
.ce_cfg
;
378 cfg
->tgt_ce
= ab
->hw_params
.target_ce_config
;
379 cfg
->tgt_ce_len
= ab
->hw_params
.target_ce_count
;
381 cfg
->svc_to_ce_map
= ab
->hw_params
.svc_to_ce_map
;
382 cfg
->svc_to_ce_map_len
= ab
->hw_params
.svc_to_ce_map_len
;
383 ab
->qmi
.service_ins_id
= ab
->hw_params
.qmi_service_ins_id
;
385 ath11k_ce_get_shadow_config(ab
, &cfg
->shadow_reg_v2
,
386 &cfg
->shadow_reg_v2_len
);
389 static void ath11k_pci_msi_config(struct ath11k_pci
*ab_pci
, bool enable
)
391 struct pci_dev
*dev
= ab_pci
->pdev
;
394 pci_read_config_word(dev
, dev
->msi_cap
+ PCI_MSI_FLAGS
, &control
);
397 control
|= PCI_MSI_FLAGS_ENABLE
;
399 control
&= ~PCI_MSI_FLAGS_ENABLE
;
401 pci_write_config_word(dev
, dev
->msi_cap
+ PCI_MSI_FLAGS
, control
);
404 static void ath11k_pci_msi_enable(struct ath11k_pci
*ab_pci
)
406 ath11k_pci_msi_config(ab_pci
, true);
409 static void ath11k_pci_msi_disable(struct ath11k_pci
*ab_pci
)
411 ath11k_pci_msi_config(ab_pci
, false);
414 static int ath11k_pci_alloc_msi(struct ath11k_pci
*ab_pci
)
416 struct ath11k_base
*ab
= ab_pci
->ab
;
417 const struct ath11k_msi_config
*msi_config
= ab
->pci
.msi
.config
;
418 struct pci_dev
*pci_dev
= ab_pci
->pdev
;
419 struct msi_desc
*msi_desc
;
423 num_vectors
= pci_alloc_irq_vectors(pci_dev
,
424 msi_config
->total_vectors
,
425 msi_config
->total_vectors
,
427 if (num_vectors
== msi_config
->total_vectors
) {
428 set_bit(ATH11K_FLAG_MULTI_MSI_VECTORS
, &ab
->dev_flags
);
430 num_vectors
= pci_alloc_irq_vectors(ab_pci
->pdev
,
434 if (num_vectors
< 0) {
436 goto reset_msi_config
;
438 clear_bit(ATH11K_FLAG_MULTI_MSI_VECTORS
, &ab
->dev_flags
);
439 ab
->pci
.msi
.config
= &msi_config_one_msi
;
440 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "request one msi vector\n");
442 ath11k_info(ab
, "MSI vectors: %d\n", num_vectors
);
444 ath11k_pci_msi_disable(ab_pci
);
446 msi_desc
= irq_get_msi_desc(ab_pci
->pdev
->irq
);
448 ath11k_err(ab
, "msi_desc is NULL!\n");
450 goto free_msi_vector
;
453 ab
->pci
.msi
.ep_base_data
= msi_desc
->msg
.data
;
455 pci_read_config_dword(pci_dev
, pci_dev
->msi_cap
+ PCI_MSI_ADDRESS_LO
,
456 &ab
->pci
.msi
.addr_lo
);
458 if (msi_desc
->pci
.msi_attrib
.is_64
) {
459 pci_read_config_dword(pci_dev
, pci_dev
->msi_cap
+ PCI_MSI_ADDRESS_HI
,
460 &ab
->pci
.msi
.addr_hi
);
462 ab
->pci
.msi
.addr_hi
= 0;
465 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "msi base data is %d\n", ab
->pci
.msi
.ep_base_data
);
470 pci_free_irq_vectors(ab_pci
->pdev
);
476 static void ath11k_pci_free_msi(struct ath11k_pci
*ab_pci
)
478 pci_free_irq_vectors(ab_pci
->pdev
);
481 static int ath11k_pci_config_msi_data(struct ath11k_pci
*ab_pci
)
483 struct msi_desc
*msi_desc
;
485 msi_desc
= irq_get_msi_desc(ab_pci
->pdev
->irq
);
487 ath11k_err(ab_pci
->ab
, "msi_desc is NULL!\n");
488 pci_free_irq_vectors(ab_pci
->pdev
);
492 ab_pci
->ab
->pci
.msi
.ep_base_data
= msi_desc
->msg
.data
;
494 ath11k_dbg(ab_pci
->ab
, ATH11K_DBG_PCI
, "after request_irq msi_ep_base_data %d\n",
495 ab_pci
->ab
->pci
.msi
.ep_base_data
);
500 static int ath11k_pci_claim(struct ath11k_pci
*ab_pci
, struct pci_dev
*pdev
)
502 struct ath11k_base
*ab
= ab_pci
->ab
;
506 pci_read_config_word(pdev
, PCI_DEVICE_ID
, &device_id
);
507 if (device_id
!= ab_pci
->dev_id
) {
508 ath11k_err(ab
, "pci device id mismatch: 0x%x 0x%x\n",
509 device_id
, ab_pci
->dev_id
);
514 ret
= pci_assign_resource(pdev
, ATH11K_PCI_BAR_NUM
);
516 ath11k_err(ab
, "failed to assign pci resource: %d\n", ret
);
520 ret
= pci_enable_device(pdev
);
522 ath11k_err(ab
, "failed to enable pci device: %d\n", ret
);
526 ret
= pci_request_region(pdev
, ATH11K_PCI_BAR_NUM
, "ath11k_pci");
528 ath11k_err(ab
, "failed to request pci region: %d\n", ret
);
532 ret
= dma_set_mask(&pdev
->dev
,
533 DMA_BIT_MASK(ATH11K_PCI_DMA_MASK
));
535 ath11k_err(ab
, "failed to set pci dma mask to %d: %d\n",
536 ATH11K_PCI_DMA_MASK
, ret
);
540 ab_pci
->dma_mask
= DMA_BIT_MASK(ATH11K_PCI_DMA_MASK
);
542 ret
= dma_set_coherent_mask(&pdev
->dev
,
543 DMA_BIT_MASK(ATH11K_PCI_COHERENT_DMA_MASK
));
545 ath11k_err(ab
, "failed to set pci coherent dma mask to %d: %d\n",
546 ATH11K_PCI_COHERENT_DMA_MASK
, ret
);
550 pci_set_master(pdev
);
552 ab
->mem_len
= pci_resource_len(pdev
, ATH11K_PCI_BAR_NUM
);
553 ab
->mem
= pci_iomap(pdev
, ATH11K_PCI_BAR_NUM
, 0);
555 ath11k_err(ab
, "failed to map pci bar %d\n", ATH11K_PCI_BAR_NUM
);
560 ab
->mem_ce
= ab
->mem
;
562 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "pci_mem 0x%p\n", ab
->mem
);
566 pci_release_region(pdev
, ATH11K_PCI_BAR_NUM
);
568 pci_disable_device(pdev
);
573 static void ath11k_pci_free_region(struct ath11k_pci
*ab_pci
)
575 struct ath11k_base
*ab
= ab_pci
->ab
;
576 struct pci_dev
*pci_dev
= ab_pci
->pdev
;
578 pci_iounmap(pci_dev
, ab
->mem
);
580 pci_release_region(pci_dev
, ATH11K_PCI_BAR_NUM
);
581 if (pci_is_enabled(pci_dev
))
582 pci_disable_device(pci_dev
);
585 static void ath11k_pci_aspm_disable(struct ath11k_pci
*ab_pci
)
587 struct ath11k_base
*ab
= ab_pci
->ab
;
589 pcie_capability_read_word(ab_pci
->pdev
, PCI_EXP_LNKCTL
,
592 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "link_ctl 0x%04x L0s %d L1 %d\n",
594 u16_get_bits(ab_pci
->link_ctl
, PCI_EXP_LNKCTL_ASPM_L0S
),
595 u16_get_bits(ab_pci
->link_ctl
, PCI_EXP_LNKCTL_ASPM_L1
));
597 /* disable L0s and L1 */
598 pcie_capability_clear_word(ab_pci
->pdev
, PCI_EXP_LNKCTL
,
599 PCI_EXP_LNKCTL_ASPMC
);
601 set_bit(ATH11K_PCI_ASPM_RESTORE
, &ab_pci
->flags
);
604 static void ath11k_pci_aspm_restore(struct ath11k_pci
*ab_pci
)
606 if (test_and_clear_bit(ATH11K_PCI_ASPM_RESTORE
, &ab_pci
->flags
))
607 pcie_capability_clear_and_set_word(ab_pci
->pdev
, PCI_EXP_LNKCTL
,
608 PCI_EXP_LNKCTL_ASPMC
,
610 PCI_EXP_LNKCTL_ASPMC
);
613 static int ath11k_pci_power_up(struct ath11k_base
*ab
)
615 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
618 ab_pci
->register_window
= 0;
619 clear_bit(ATH11K_FLAG_DEVICE_INIT_DONE
, &ab
->dev_flags
);
620 ath11k_pci_sw_reset(ab_pci
->ab
, true);
622 /* Disable ASPM during firmware download due to problems switching
625 ath11k_pci_aspm_disable(ab_pci
);
627 ath11k_pci_msi_enable(ab_pci
);
629 ret
= ath11k_mhi_start(ab_pci
);
631 ath11k_err(ab
, "failed to start mhi: %d\n", ret
);
635 if (ab
->hw_params
.static_window_map
)
636 ath11k_pci_select_static_window(ab_pci
);
641 static void ath11k_pci_power_down(struct ath11k_base
*ab
)
643 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
645 /* restore aspm in case firmware bootup fails */
646 ath11k_pci_aspm_restore(ab_pci
);
648 ath11k_pci_force_wake(ab_pci
->ab
);
650 ath11k_pci_msi_disable(ab_pci
);
652 ath11k_mhi_stop(ab_pci
);
653 clear_bit(ATH11K_FLAG_DEVICE_INIT_DONE
, &ab
->dev_flags
);
654 ath11k_pci_sw_reset(ab_pci
->ab
, false);
657 static int ath11k_pci_hif_suspend(struct ath11k_base
*ab
)
659 struct ath11k_pci
*ar_pci
= ath11k_pci_priv(ab
);
661 return ath11k_mhi_suspend(ar_pci
);
664 static int ath11k_pci_hif_resume(struct ath11k_base
*ab
)
666 struct ath11k_pci
*ar_pci
= ath11k_pci_priv(ab
);
668 return ath11k_mhi_resume(ar_pci
);
671 static void ath11k_pci_hif_ce_irq_enable(struct ath11k_base
*ab
)
673 ath11k_pcic_ce_irqs_enable(ab
);
676 static void ath11k_pci_hif_ce_irq_disable(struct ath11k_base
*ab
)
678 ath11k_pcic_ce_irq_disable_sync(ab
);
681 static int ath11k_pci_start(struct ath11k_base
*ab
)
683 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
685 /* TODO: for now don't restore ASPM in case of single MSI
686 * vector as MHI register reading in M2 causes system hang.
688 if (test_bit(ATH11K_FLAG_MULTI_MSI_VECTORS
, &ab
->dev_flags
))
689 ath11k_pci_aspm_restore(ab_pci
);
691 ath11k_info(ab
, "leaving PCI ASPM disabled to avoid MHI M2 problems\n");
693 ath11k_pcic_start(ab
);
698 static const struct ath11k_hif_ops ath11k_pci_hif_ops
= {
699 .start
= ath11k_pci_start
,
700 .stop
= ath11k_pcic_stop
,
701 .read32
= ath11k_pcic_read32
,
702 .write32
= ath11k_pcic_write32
,
703 .read
= ath11k_pcic_read
,
704 .power_down
= ath11k_pci_power_down
,
705 .power_up
= ath11k_pci_power_up
,
706 .suspend
= ath11k_pci_hif_suspend
,
707 .resume
= ath11k_pci_hif_resume
,
708 .irq_enable
= ath11k_pcic_ext_irq_enable
,
709 .irq_disable
= ath11k_pcic_ext_irq_disable
,
710 .get_msi_address
= ath11k_pcic_get_msi_address
,
711 .get_user_msi_vector
= ath11k_pcic_get_user_msi_assignment
,
712 .map_service_to_pipe
= ath11k_pcic_map_service_to_pipe
,
713 .ce_irq_enable
= ath11k_pci_hif_ce_irq_enable
,
714 .ce_irq_disable
= ath11k_pci_hif_ce_irq_disable
,
715 .get_ce_msi_idx
= ath11k_pcic_get_ce_msi_idx
,
718 static void ath11k_pci_read_hw_version(struct ath11k_base
*ab
, u32
*major
, u32
*minor
)
722 soc_hw_version
= ath11k_pcic_read32(ab
, TCSR_SOC_HW_VERSION
);
723 *major
= FIELD_GET(TCSR_SOC_HW_VERSION_MAJOR_MASK
,
725 *minor
= FIELD_GET(TCSR_SOC_HW_VERSION_MINOR_MASK
,
728 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "tcsr_soc_hw_version major %d minor %d\n",
732 static int ath11k_pci_set_irq_affinity_hint(struct ath11k_pci
*ab_pci
,
733 const struct cpumask
*m
)
735 if (test_bit(ATH11K_FLAG_MULTI_MSI_VECTORS
, &ab_pci
->ab
->dev_flags
))
738 return irq_set_affinity_hint(ab_pci
->pdev
->irq
, m
);
741 static int ath11k_pci_probe(struct pci_dev
*pdev
,
742 const struct pci_device_id
*pci_dev
)
744 struct ath11k_base
*ab
;
745 struct ath11k_pci
*ab_pci
;
746 u32 soc_hw_version_major
, soc_hw_version_minor
, addr
;
750 ab
= ath11k_core_alloc(&pdev
->dev
, sizeof(*ab_pci
), ATH11K_BUS_PCI
);
753 dev_err(&pdev
->dev
, "failed to allocate ath11k base\n");
757 ab
->dev
= &pdev
->dev
;
758 pci_set_drvdata(pdev
, ab
);
759 ab_pci
= ath11k_pci_priv(ab
);
760 ab_pci
->dev_id
= pci_dev
->device
;
763 ab
->hif
.ops
= &ath11k_pci_hif_ops
;
764 ab
->fw_mode
= ATH11K_FIRMWARE_MODE_NORMAL
;
765 pci_set_drvdata(pdev
, ab
);
766 spin_lock_init(&ab_pci
->window_lock
);
768 /* Set fixed_mem_region to true for platforms support reserved memory
769 * from DT. If memory is reserved from DT for FW, ath11k driver need not
772 ret
= of_property_read_u32(ab
->dev
->of_node
, "memory-region", &addr
);
774 set_bit(ATH11K_FLAG_FIXED_MEM_RGN
, &ab
->dev_flags
);
776 ret
= ath11k_pci_claim(ab_pci
, pdev
);
778 ath11k_err(ab
, "failed to claim device: %d\n", ret
);
782 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "pci probe %04x:%04x %04x:%04x\n",
783 pdev
->vendor
, pdev
->device
,
784 pdev
->subsystem_vendor
, pdev
->subsystem_device
);
786 ab
->id
.vendor
= pdev
->vendor
;
787 ab
->id
.device
= pdev
->device
;
788 ab
->id
.subsystem_vendor
= pdev
->subsystem_vendor
;
789 ab
->id
.subsystem_device
= pdev
->subsystem_device
;
791 switch (pci_dev
->device
) {
792 case QCA6390_DEVICE_ID
:
793 ret
= ath11k_pcic_register_pci_ops(ab
, &ath11k_pci_ops_qca6390
);
795 ath11k_err(ab
, "failed to register PCI ops: %d\n", ret
);
796 goto err_pci_free_region
;
799 ath11k_pci_read_hw_version(ab
, &soc_hw_version_major
,
800 &soc_hw_version_minor
);
801 switch (soc_hw_version_major
) {
803 ab
->hw_rev
= ATH11K_HW_QCA6390_HW20
;
806 dev_err(&pdev
->dev
, "Unsupported QCA6390 SOC hardware version: %d %d\n",
807 soc_hw_version_major
, soc_hw_version_minor
);
809 goto err_pci_free_region
;
813 case QCN9074_DEVICE_ID
:
814 ret
= ath11k_pcic_register_pci_ops(ab
, &ath11k_pci_ops_qcn9074
);
816 ath11k_err(ab
, "failed to register PCI ops: %d\n", ret
);
817 goto err_pci_free_region
;
819 ab
->hw_rev
= ATH11K_HW_QCN9074_HW10
;
821 case WCN6855_DEVICE_ID
:
822 ret
= ath11k_pcic_register_pci_ops(ab
, &ath11k_pci_ops_qca6390
);
824 ath11k_err(ab
, "failed to register PCI ops: %d\n", ret
);
825 goto err_pci_free_region
;
827 ab
->id
.bdf_search
= ATH11K_BDF_SEARCH_BUS_AND_BOARD
;
828 ath11k_pci_read_hw_version(ab
, &soc_hw_version_major
,
829 &soc_hw_version_minor
);
830 switch (soc_hw_version_major
) {
832 switch (soc_hw_version_minor
) {
835 ab
->hw_rev
= ATH11K_HW_WCN6855_HW20
;
839 sub_version
= ath11k_pcic_read32(ab
, TCSR_SOC_HW_SUB_VER
);
840 ath11k_dbg(ab
, ATH11K_DBG_PCI
, "sub_version 0x%x\n",
842 switch (sub_version
) {
847 ab
->hw_rev
= ATH11K_HW_QCA2066_HW21
;
850 ab
->hw_rev
= ATH11K_HW_WCN6855_HW21
;
854 goto unsupported_wcn6855_soc
;
858 unsupported_wcn6855_soc
:
859 dev_err(&pdev
->dev
, "Unsupported WCN6855 SOC hardware version: %d %d\n",
860 soc_hw_version_major
, soc_hw_version_minor
);
862 goto err_pci_free_region
;
867 dev_err(&pdev
->dev
, "Unknown PCI device found: 0x%x\n",
870 goto err_pci_free_region
;
873 ret
= ath11k_pcic_init_msi_config(ab
);
875 ath11k_err(ab
, "failed to init msi config: %d\n", ret
);
876 goto err_pci_free_region
;
879 ret
= ath11k_pci_alloc_msi(ab_pci
);
881 ath11k_err(ab
, "failed to enable msi: %d\n", ret
);
882 goto err_pci_free_region
;
885 ret
= ath11k_core_pre_init(ab
);
887 goto err_pci_disable_msi
;
889 ret
= ath11k_pci_set_irq_affinity_hint(ab_pci
, cpumask_of(0));
891 ath11k_err(ab
, "failed to set irq affinity %d\n", ret
);
892 goto err_pci_disable_msi
;
895 ret
= ath11k_mhi_register(ab_pci
);
897 ath11k_err(ab
, "failed to register mhi: %d\n", ret
);
898 goto err_irq_affinity_cleanup
;
901 ret
= ath11k_hal_srng_init(ab
);
903 goto err_mhi_unregister
;
905 ret
= ath11k_ce_alloc_pipes(ab
);
907 ath11k_err(ab
, "failed to allocate ce pipes: %d\n", ret
);
908 goto err_hal_srng_deinit
;
911 ath11k_pci_init_qmi_ce_config(ab
);
913 ret
= ath11k_pcic_config_irq(ab
);
915 ath11k_err(ab
, "failed to config irq: %d\n", ret
);
919 /* kernel may allocate a dummy vector before request_irq and
920 * then allocate a real vector when request_irq is called.
921 * So get msi_data here again to avoid spurious interrupt
922 * as msi_data will configured to srngs.
924 ret
= ath11k_pci_config_msi_data(ab_pci
);
926 ath11k_err(ab
, "failed to config msi_data: %d\n", ret
);
930 ret
= ath11k_core_init(ab
);
932 ath11k_err(ab
, "failed to init core: %d\n", ret
);
935 ath11k_qmi_fwreset_from_cold_boot(ab
);
939 ath11k_pcic_free_irq(ab
);
942 ath11k_ce_free_pipes(ab
);
945 ath11k_hal_srng_deinit(ab
);
948 ath11k_mhi_unregister(ab_pci
);
950 err_irq_affinity_cleanup
:
951 ath11k_pci_set_irq_affinity_hint(ab_pci
, NULL
);
954 ath11k_pci_free_msi(ab_pci
);
957 ath11k_pci_free_region(ab_pci
);
960 ath11k_core_free(ab
);
965 static void ath11k_pci_remove(struct pci_dev
*pdev
)
967 struct ath11k_base
*ab
= pci_get_drvdata(pdev
);
968 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
970 ath11k_pci_set_irq_affinity_hint(ab_pci
, NULL
);
972 if (test_bit(ATH11K_FLAG_QMI_FAIL
, &ab
->dev_flags
)) {
973 ath11k_pci_power_down(ab
);
974 ath11k_debugfs_soc_destroy(ab
);
975 ath11k_qmi_deinit_service(ab
);
979 set_bit(ATH11K_FLAG_UNREGISTERING
, &ab
->dev_flags
);
981 ath11k_core_deinit(ab
);
984 ath11k_mhi_unregister(ab_pci
);
986 ath11k_pcic_free_irq(ab
);
987 ath11k_pci_free_msi(ab_pci
);
988 ath11k_pci_free_region(ab_pci
);
990 ath11k_hal_srng_deinit(ab
);
991 ath11k_ce_free_pipes(ab
);
992 ath11k_core_free(ab
);
995 static void ath11k_pci_shutdown(struct pci_dev
*pdev
)
997 struct ath11k_base
*ab
= pci_get_drvdata(pdev
);
998 struct ath11k_pci
*ab_pci
= ath11k_pci_priv(ab
);
1000 ath11k_pci_set_irq_affinity_hint(ab_pci
, NULL
);
1001 ath11k_pci_power_down(ab
);
1004 static __maybe_unused
int ath11k_pci_pm_suspend(struct device
*dev
)
1006 struct ath11k_base
*ab
= dev_get_drvdata(dev
);
1009 if (test_bit(ATH11K_FLAG_QMI_FAIL
, &ab
->dev_flags
)) {
1010 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "boot skipping pci suspend as qmi is not initialised\n");
1014 ret
= ath11k_core_suspend(ab
);
1016 ath11k_warn(ab
, "failed to suspend core: %d\n", ret
);
1021 static __maybe_unused
int ath11k_pci_pm_resume(struct device
*dev
)
1023 struct ath11k_base
*ab
= dev_get_drvdata(dev
);
1026 if (test_bit(ATH11K_FLAG_QMI_FAIL
, &ab
->dev_flags
)) {
1027 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "boot skipping pci resume as qmi is not initialised\n");
1031 ret
= ath11k_core_resume(ab
);
1033 ath11k_warn(ab
, "failed to resume core: %d\n", ret
);
1038 static SIMPLE_DEV_PM_OPS(ath11k_pci_pm_ops
,
1039 ath11k_pci_pm_suspend
,
1040 ath11k_pci_pm_resume
);
1042 static struct pci_driver ath11k_pci_driver
= {
1043 .name
= "ath11k_pci",
1044 .id_table
= ath11k_pci_id_table
,
1045 .probe
= ath11k_pci_probe
,
1046 .remove
= ath11k_pci_remove
,
1047 .shutdown
= ath11k_pci_shutdown
,
1049 .driver
.pm
= &ath11k_pci_pm_ops
,
1053 static int ath11k_pci_init(void)
1057 ret
= pci_register_driver(&ath11k_pci_driver
);
1059 pr_err("failed to register ath11k pci driver: %d\n",
1064 module_init(ath11k_pci_init
);
1066 static void ath11k_pci_exit(void)
1068 pci_unregister_driver(&ath11k_pci_driver
);
1071 module_exit(ath11k_pci_exit
);
1073 MODULE_DESCRIPTION("Driver support for Qualcomm Technologies PCIe 802.11ax WLAN devices");
1074 MODULE_LICENSE("Dual BSD/GPL");
1076 /* firmware files */
1077 MODULE_FIRMWARE(ATH11K_FW_DIR
"/QCA6390/hw2.0/*");
1078 MODULE_FIRMWARE(ATH11K_FW_DIR
"/QCN9074/hw1.0/*");
1079 MODULE_FIRMWARE(ATH11K_FW_DIR
"/WCN6855/hw2.0/*");
1080 MODULE_FIRMWARE(ATH11K_FW_DIR
"/WCN6855/hw2.1/*");