39d5a61d5a1ed82cf358fb138168102da67eade7
[openwrt/staging/jow.git] / package / kernel / mac80211 / patches / ath11k / 100-wifi-ath11k-use-unique-QRTR-instance-ID.patch
1 From 534a5f99d589cfa6b244b4433c192b6a278a67ff Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robimarko@gmail.com>
3 Date: Sat, 5 Nov 2022 20:15:40 +0100
4 Subject: [PATCH] wifi: ath11k: use unique QRTR instance ID
5
6 Currently, trying to use AHB + PCI/MHI cards or multiple PCI/MHI cards
7 will cause a clash in the QRTR instance node ID and prevent the driver
8 from talking via QMI to the card and thus initializing it with:
9 [ 9.836329] ath11k c000000.wifi: host capability request failed: 1 90
10 [ 9.842047] ath11k c000000.wifi: failed to send qmi host cap: -22
11
12 So, in order to allow for this combination of cards, especially AHB + PCI
13 cards like IPQ8074 + QCN9074 (Used by me and tested on) set the desired
14 QRTR instance ID offset by calculating a unique one based on PCI domain
15 and bus ID-s and writing it to bits 7-0 of BHI_ERRDBG2 MHI register by
16 using the SBL state callback that is added as part of the series.
17 We also have to make sure that new QRTR offset is added on top of the
18 default QRTR instance ID-s that are currently used in the driver.
19
20 This finally allows using AHB + PCI or multiple PCI cards on the same
21 system.
22
23 Since this is not supported on QCA6390 and like, its limited to QCN9074
24 which is known to support changing QRTR instance ID.
25
26 Before:
27 root@OpenWrt:/# qrtr-lookup
28 Service Version Instance Node Port
29 1054 1 0 7 1 <unknown>
30 69 1 2 7 3 ATH10k WLAN firmware service
31
32 After:
33 root@OpenWrt:/# qrtr-lookup
34 Service Version Instance Node Port
35 1054 1 0 7 1 <unknown>
36 69 1 2 7 3 ATH10k WLAN firmware service
37 15 1 0 8 1 Test service
38 69 1 8 8 2 ATH10k WLAN firmware service
39
40 Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.5.0.1-01208-QCAHKSWPL_SILICONZ-1
41 Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.5.0.1-01208-QCAHKSWPL_SILICONZ-1
42
43 Signed-off-by: Robert Marko <robimarko@gmail.com>
44 ---
45 drivers/net/wireless/ath/ath11k/mhi.c | 49 ++++++++++++++++++---------
46 drivers/net/wireless/ath/ath11k/mhi.h | 3 ++
47 drivers/net/wireless/ath/ath11k/pci.c | 9 ++++-
48 3 files changed, 44 insertions(+), 17 deletions(-)
49
50 --- a/drivers/net/wireless/ath/ath11k/mhi.c
51 +++ b/drivers/net/wireless/ath/ath11k/mhi.c
52 @@ -294,6 +294,34 @@ static void ath11k_mhi_op_runtime_put(st
53 {
54 }
55
56 +static int ath11k_mhi_op_read_reg(struct mhi_controller *mhi_cntrl,
57 + void __iomem *addr,
58 + u32 *out)
59 +{
60 + *out = readl(addr);
61 +
62 + return 0;
63 +}
64 +
65 +static void ath11k_mhi_op_write_reg(struct mhi_controller *mhi_cntrl,
66 + void __iomem *addr,
67 + u32 val)
68 +{
69 + writel(val, addr);
70 +}
71 +
72 +static void ath11k_mhi_qrtr_instance_set(struct mhi_controller *mhi_cntrl)
73 +{
74 + struct ath11k_base *ab = dev_get_drvdata(mhi_cntrl->cntrl_dev);
75 +
76 + if (ab->hw_rev == ATH11K_HW_QCN9074_HW10) {
77 + ath11k_mhi_op_write_reg(mhi_cntrl,
78 + mhi_cntrl->bhi + BHI_ERRDBG2,
79 + FIELD_PREP(QRTR_INSTANCE_MASK,
80 + ab->qmi.service_ins_id - ab->hw_params.qmi_service_ins_id));
81 + }
82 +}
83 +
84 static char *ath11k_mhi_op_callback_to_str(enum mhi_callback reason)
85 {
86 switch (reason) {
87 @@ -315,6 +343,8 @@ static char *ath11k_mhi_op_callback_to_s
88 return "MHI_CB_FATAL_ERROR";
89 case MHI_CB_BW_REQ:
90 return "MHI_CB_BW_REQ";
91 + case MHI_CB_EE_SBL_MODE:
92 + return "MHI_CB_EE_SBL_MODE";
93 default:
94 return "UNKNOWN";
95 }
96 @@ -336,27 +366,14 @@ static void ath11k_mhi_op_status_cb(stru
97 if (!(test_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags)))
98 queue_work(ab->workqueue_aux, &ab->reset_work);
99 break;
100 + case MHI_CB_EE_SBL_MODE:
101 + ath11k_mhi_qrtr_instance_set(mhi_cntrl);
102 + break;
103 default:
104 break;
105 }
106 }
107
108 -static int ath11k_mhi_op_read_reg(struct mhi_controller *mhi_cntrl,
109 - void __iomem *addr,
110 - u32 *out)
111 -{
112 - *out = readl(addr);
113 -
114 - return 0;
115 -}
116 -
117 -static void ath11k_mhi_op_write_reg(struct mhi_controller *mhi_cntrl,
118 - void __iomem *addr,
119 - u32 val)
120 -{
121 - writel(val, addr);
122 -}
123 -
124 static int ath11k_mhi_read_addr_from_dt(struct mhi_controller *mhi_ctrl)
125 {
126 struct device_node *np;
127 --- a/drivers/net/wireless/ath/ath11k/mhi.h
128 +++ b/drivers/net/wireless/ath/ath11k/mhi.h
129 @@ -16,6 +16,9 @@
130 #define MHICTRL 0x38
131 #define MHICTRL_RESET_MASK 0x2
132
133 +#define BHI_ERRDBG2 0x38
134 +#define QRTR_INSTANCE_MASK GENMASK(7, 0)
135 +
136 int ath11k_mhi_start(struct ath11k_pci *ar_pci);
137 void ath11k_mhi_stop(struct ath11k_pci *ar_pci);
138 int ath11k_mhi_register(struct ath11k_pci *ar_pci);
139 --- a/drivers/net/wireless/ath/ath11k/pci.c
140 +++ b/drivers/net/wireless/ath/ath11k/pci.c
141 @@ -370,13 +370,20 @@ static void ath11k_pci_sw_reset(struct a
142 static void ath11k_pci_init_qmi_ce_config(struct ath11k_base *ab)
143 {
144 struct ath11k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg;
145 + struct ath11k_pci *ab_pci = ath11k_pci_priv(ab);
146 + struct pci_bus *bus = ab_pci->pdev->bus;
147
148 cfg->tgt_ce = ab->hw_params.target_ce_config;
149 cfg->tgt_ce_len = ab->hw_params.target_ce_count;
150
151 cfg->svc_to_ce_map = ab->hw_params.svc_to_ce_map;
152 cfg->svc_to_ce_map_len = ab->hw_params.svc_to_ce_map_len;
153 - ab->qmi.service_ins_id = ab->hw_params.qmi_service_ins_id;
154 +
155 + if (ab->hw_rev == ATH11K_HW_QCN9074_HW10) {
156 + ab->qmi.service_ins_id = ab->hw_params.qmi_service_ins_id +
157 + (((pci_domain_nr(bus) & 0xF) << 4) | (bus->number & 0xF));
158 + } else
159 + ab->qmi.service_ins_id = ab->hw_params.qmi_service_ins_id;
160
161 ath11k_ce_get_shadow_config(ab, &cfg->shadow_reg_v2,
162 &cfg->shadow_reg_v2_len);