blob: b3cff1d3364aad85151b4abd54d05bee0d2e02a3 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <linux/pci.h>
19#include <linux/module.h>
20#include <linux/interrupt.h>
21#include <linux/spinlock.h>
Kalle Valo650b91f2013-11-20 10:00:49 +020022#include <linux/bitops.h>
Kalle Valo5e3dd152013-06-12 20:52:10 +030023
24#include "core.h"
25#include "debug.h"
26
27#include "targaddrs.h"
28#include "bmi.h"
29
30#include "hif.h"
31#include "htc.h"
32
33#include "ce.h"
34#include "pci.h"
35
Michal Kaziorcfe9c452013-11-25 14:06:27 +010036enum ath10k_pci_irq_mode {
37 ATH10K_PCI_IRQ_AUTO = 0,
38 ATH10K_PCI_IRQ_LEGACY = 1,
39 ATH10K_PCI_IRQ_MSI = 2,
40};
41
Kalle Valo35098462014-03-28 09:32:27 +020042enum ath10k_pci_reset_mode {
43 ATH10K_PCI_RESET_AUTO = 0,
44 ATH10K_PCI_RESET_WARM_ONLY = 1,
45};
46
Michal Kaziorcfe9c452013-11-25 14:06:27 +010047static unsigned int ath10k_pci_irq_mode = ATH10K_PCI_IRQ_AUTO;
Kalle Valo35098462014-03-28 09:32:27 +020048static unsigned int ath10k_pci_reset_mode = ATH10K_PCI_RESET_AUTO;
Michal Kaziorcfe9c452013-11-25 14:06:27 +010049
Michal Kaziorcfe9c452013-11-25 14:06:27 +010050module_param_named(irq_mode, ath10k_pci_irq_mode, uint, 0644);
51MODULE_PARM_DESC(irq_mode, "0: auto, 1: legacy, 2: msi (default: 0)");
52
Kalle Valo35098462014-03-28 09:32:27 +020053module_param_named(reset_mode, ath10k_pci_reset_mode, uint, 0644);
54MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)");
55
Kalle Valo0399eca2014-03-28 09:32:21 +020056/* how long wait to wait for target to initialise, in ms */
57#define ATH10K_PCI_TARGET_WAIT 3000
Michal Kazior61c95ce2014-05-14 16:56:16 +030058#define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3
Kalle Valo0399eca2014-03-28 09:32:21 +020059
Benoit Taine9baa3c32014-08-08 15:56:03 +020060static const struct pci_device_id ath10k_pci_id_table[] = {
Kalle Valo5e3dd152013-06-12 20:52:10 +030061 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
Michal Kazior36582e52015-08-13 14:32:26 +020062 { PCI_VDEVICE(ATHEROS, QCA6164_2_1_DEVICE_ID) }, /* PCI-E QCA6164 V2.1 */
Michal Kaziord63955b2015-01-24 12:14:49 +020063 { PCI_VDEVICE(ATHEROS, QCA6174_2_1_DEVICE_ID) }, /* PCI-E QCA6174 V2.1 */
Vasanthakumar Thiagarajan8a055a82015-07-29 11:40:39 +030064 { PCI_VDEVICE(ATHEROS, QCA99X0_2_0_DEVICE_ID) }, /* PCI-E QCA99X0 V2 */
Bartosz Markowskia226b512015-10-28 15:09:53 +010065 { PCI_VDEVICE(ATHEROS, QCA9377_1_0_DEVICE_ID) }, /* PCI-E QCA9377 V1 */
Kalle Valo5e3dd152013-06-12 20:52:10 +030066 {0}
67};
68
Michal Kazior7505f7c2014-12-02 10:55:54 +020069static const struct ath10k_pci_supp_chip ath10k_pci_supp_chips[] = {
70 /* QCA988X pre 2.0 chips are not supported because they need some nasty
71 * hacks. ath10k doesn't have them and these devices crash horribly
72 * because of that.
73 */
74 { QCA988X_2_0_DEVICE_ID, QCA988X_HW_2_0_CHIP_ID_REV },
Michal Kazior36582e52015-08-13 14:32:26 +020075
76 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
77 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
78 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
79 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
80 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
81
Michal Kaziord63955b2015-01-24 12:14:49 +020082 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
83 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
84 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
85 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
86 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
Michal Kazior36582e52015-08-13 14:32:26 +020087
Vasanthakumar Thiagarajan8a055a82015-07-29 11:40:39 +030088 { QCA99X0_2_0_DEVICE_ID, QCA99X0_HW_2_0_CHIP_ID_REV },
Bartosz Markowski034074f2015-11-05 09:50:43 +010089
90 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_0_CHIP_ID_REV },
Bartosz Markowski12551ce2015-11-05 09:50:40 +010091 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_1_CHIP_ID_REV },
Michal Kazior7505f7c2014-12-02 10:55:54 +020092};
93
Michal Kazior728f95e2014-08-22 14:33:14 +020094static void ath10k_pci_buffer_cleanup(struct ath10k *ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +010095static int ath10k_pci_cold_reset(struct ath10k *ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +053096static int ath10k_pci_safe_chip_reset(struct ath10k *ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +010097static int ath10k_pci_init_irq(struct ath10k *ar);
98static int ath10k_pci_deinit_irq(struct ath10k *ar);
99static int ath10k_pci_request_irq(struct ath10k *ar);
100static void ath10k_pci_free_irq(struct ath10k *ar);
Michal Kazior85622cd2013-11-25 14:06:22 +0100101static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
102 struct ath10k_ce_pipe *rx_pipe,
103 struct bmi_xfer *xfer);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +0530104static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar);
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530105static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530106static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530107static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
108static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530109static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530110static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300111
Ryan Hsu2727a742015-11-05 18:44:27 -0800112static struct ce_attr host_ce_config_wlan[] = {
Kalle Valo48e9c222013-09-01 10:01:32 +0300113 /* CE0: host->target HTC control and raw streams */
114 {
115 .flags = CE_ATTR_FLAGS,
116 .src_nentries = 16,
117 .src_sz_max = 256,
118 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530119 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300120 },
121
122 /* CE1: target->host HTT + HTC control */
123 {
124 .flags = CE_ATTR_FLAGS,
125 .src_nentries = 0,
Michal Kazior63838642015-02-09 15:04:55 +0100126 .src_sz_max = 2048,
Kalle Valo48e9c222013-09-01 10:01:32 +0300127 .dest_nentries = 512,
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530128 .recv_cb = ath10k_pci_htt_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300129 },
130
131 /* CE2: target->host WMI */
132 {
133 .flags = CE_ATTR_FLAGS,
134 .src_nentries = 0,
135 .src_sz_max = 2048,
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200136 .dest_nentries = 128,
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530137 .recv_cb = ath10k_pci_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300138 },
139
140 /* CE3: host->target WMI */
141 {
142 .flags = CE_ATTR_FLAGS,
143 .src_nentries = 32,
144 .src_sz_max = 2048,
145 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530146 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300147 },
148
149 /* CE4: host->target HTT */
150 {
151 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
152 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
153 .src_sz_max = 256,
154 .dest_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530155 .send_cb = ath10k_pci_htt_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300156 },
157
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530158 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valo48e9c222013-09-01 10:01:32 +0300159 {
160 .flags = CE_ATTR_FLAGS,
161 .src_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530162 .src_sz_max = 512,
163 .dest_nentries = 512,
164 .recv_cb = ath10k_pci_htt_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300165 },
166
167 /* CE6: target autonomous hif_memcpy */
168 {
169 .flags = CE_ATTR_FLAGS,
170 .src_nentries = 0,
171 .src_sz_max = 0,
172 .dest_nentries = 0,
173 },
174
175 /* CE7: ce_diag, the Diagnostic Window */
176 {
177 .flags = CE_ATTR_FLAGS,
178 .src_nentries = 2,
179 .src_sz_max = DIAG_TRANSFER_LIMIT,
180 .dest_nentries = 2,
181 },
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530182
183 /* CE8: target->host pktlog */
184 {
185 .flags = CE_ATTR_FLAGS,
186 .src_nentries = 0,
187 .src_sz_max = 2048,
188 .dest_nentries = 128,
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530189 .recv_cb = ath10k_pci_pktlog_rx_cb,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530190 },
191
192 /* CE9 target autonomous qcache memcpy */
193 {
194 .flags = CE_ATTR_FLAGS,
195 .src_nentries = 0,
196 .src_sz_max = 0,
197 .dest_nentries = 0,
198 },
199
200 /* CE10: target autonomous hif memcpy */
201 {
202 .flags = CE_ATTR_FLAGS,
203 .src_nentries = 0,
204 .src_sz_max = 0,
205 .dest_nentries = 0,
206 },
207
208 /* CE11: target autonomous hif memcpy */
209 {
210 .flags = CE_ATTR_FLAGS,
211 .src_nentries = 0,
212 .src_sz_max = 0,
213 .dest_nentries = 0,
214 },
Kalle Valo5e3dd152013-06-12 20:52:10 +0300215};
216
217/* Target firmware's Copy Engine configuration. */
Ryan Hsu2727a742015-11-05 18:44:27 -0800218static struct ce_pipe_config target_ce_config_wlan[] = {
Kalle Valod88effb2013-09-01 10:01:39 +0300219 /* CE0: host->target HTC control and raw streams */
220 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300221 .pipenum = __cpu_to_le32(0),
222 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
223 .nentries = __cpu_to_le32(32),
224 .nbytes_max = __cpu_to_le32(256),
225 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
226 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300227 },
228
229 /* CE1: target->host HTT + HTC control */
230 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300231 .pipenum = __cpu_to_le32(1),
232 .pipedir = __cpu_to_le32(PIPEDIR_IN),
233 .nentries = __cpu_to_le32(32),
Michal Kazior63838642015-02-09 15:04:55 +0100234 .nbytes_max = __cpu_to_le32(2048),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300235 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
236 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300237 },
238
239 /* CE2: target->host WMI */
240 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300241 .pipenum = __cpu_to_le32(2),
242 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200243 .nentries = __cpu_to_le32(64),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300244 .nbytes_max = __cpu_to_le32(2048),
245 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
246 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300247 },
248
249 /* CE3: host->target WMI */
250 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300251 .pipenum = __cpu_to_le32(3),
252 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
253 .nentries = __cpu_to_le32(32),
254 .nbytes_max = __cpu_to_le32(2048),
255 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
256 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300257 },
258
259 /* CE4: host->target HTT */
260 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300261 .pipenum = __cpu_to_le32(4),
262 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
263 .nentries = __cpu_to_le32(256),
264 .nbytes_max = __cpu_to_le32(256),
265 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
266 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300267 },
268
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 /* NB: 50% of src nentries, since tx has 2 frags */
Kalle Valod88effb2013-09-01 10:01:39 +0300270
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530271 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valod88effb2013-09-01 10:01:39 +0300272 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300273 .pipenum = __cpu_to_le32(5),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530274 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300275 .nentries = __cpu_to_le32(32),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530276 .nbytes_max = __cpu_to_le32(512),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300277 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
278 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300279 },
280
281 /* CE6: Reserved for target autonomous hif_memcpy */
282 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300283 .pipenum = __cpu_to_le32(6),
284 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
285 .nentries = __cpu_to_le32(32),
286 .nbytes_max = __cpu_to_le32(4096),
287 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
288 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300289 },
290
Kalle Valo5e3dd152013-06-12 20:52:10 +0300291 /* CE7 used only by Host */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530292 {
293 .pipenum = __cpu_to_le32(7),
294 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
295 .nentries = __cpu_to_le32(0),
296 .nbytes_max = __cpu_to_le32(0),
297 .flags = __cpu_to_le32(0),
298 .reserved = __cpu_to_le32(0),
299 },
300
301 /* CE8 target->host packtlog */
302 {
303 .pipenum = __cpu_to_le32(8),
304 .pipedir = __cpu_to_le32(PIPEDIR_IN),
305 .nentries = __cpu_to_le32(64),
306 .nbytes_max = __cpu_to_le32(2048),
307 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
308 .reserved = __cpu_to_le32(0),
309 },
310
311 /* CE9 target autonomous qcache memcpy */
312 {
313 .pipenum = __cpu_to_le32(9),
314 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
315 .nentries = __cpu_to_le32(32),
316 .nbytes_max = __cpu_to_le32(2048),
317 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
318 .reserved = __cpu_to_le32(0),
319 },
320
321 /* It not necessary to send target wlan configuration for CE10 & CE11
322 * as these CEs are not actively used in target.
323 */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300324};
325
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300326/*
327 * Map from service/endpoint to Copy Engine.
328 * This table is derived from the CE_PCI TABLE, above.
329 * It is passed to the Target at startup for use by firmware.
330 */
Ryan Hsu2727a742015-11-05 18:44:27 -0800331static struct service_to_pipe target_service_to_ce_map_wlan[] = {
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300332 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300333 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
334 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
335 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300336 },
337 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300338 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
339 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
340 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300341 },
342 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300343 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
344 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
345 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300346 },
347 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300348 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
349 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
350 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300351 },
352 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300353 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
354 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
355 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300356 },
357 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300358 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
359 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
360 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300361 },
362 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300363 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
364 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
365 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300366 },
367 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300368 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
369 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
370 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300371 },
372 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300373 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
374 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
375 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300376 },
377 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300378 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
379 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
380 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300381 },
382 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300383 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
384 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
385 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300386 },
387 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300388 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
389 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
390 __cpu_to_le32(1),
391 },
392 { /* not used */
393 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
394 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
395 __cpu_to_le32(0),
396 },
397 { /* not used */
398 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
399 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
400 __cpu_to_le32(1),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300401 },
402 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300403 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
404 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
405 __cpu_to_le32(4),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300406 },
407 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300408 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
409 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530410 __cpu_to_le32(5),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300411 },
412
413 /* (Additions here) */
414
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300415 { /* must be last */
416 __cpu_to_le32(0),
417 __cpu_to_le32(0),
418 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300419 },
420};
421
Michal Kazior77258d42015-05-18 09:38:18 +0000422static bool ath10k_pci_is_awake(struct ath10k *ar)
423{
424 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
425 u32 val = ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
426 RTC_STATE_ADDRESS);
427
428 return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
429}
430
431static void __ath10k_pci_wake(struct ath10k *ar)
432{
433 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
434
435 lockdep_assert_held(&ar_pci->ps_lock);
436
437 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake reg refcount %lu awake %d\n",
438 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
439
440 iowrite32(PCIE_SOC_WAKE_V_MASK,
441 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
442 PCIE_SOC_WAKE_ADDRESS);
443}
444
445static void __ath10k_pci_sleep(struct ath10k *ar)
446{
447 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
448
449 lockdep_assert_held(&ar_pci->ps_lock);
450
451 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep reg refcount %lu awake %d\n",
452 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
453
454 iowrite32(PCIE_SOC_WAKE_RESET,
455 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
456 PCIE_SOC_WAKE_ADDRESS);
457 ar_pci->ps_awake = false;
458}
459
460static int ath10k_pci_wake_wait(struct ath10k *ar)
461{
462 int tot_delay = 0;
463 int curr_delay = 5;
464
465 while (tot_delay < PCIE_WAKE_TIMEOUT) {
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300466 if (ath10k_pci_is_awake(ar)) {
467 if (tot_delay > PCIE_WAKE_LATE_US)
468 ath10k_warn(ar, "device wakeup took %d ms which is unusally long, otherwise it works normally.\n",
469 tot_delay / 1000);
Michal Kazior77258d42015-05-18 09:38:18 +0000470 return 0;
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300471 }
Michal Kazior77258d42015-05-18 09:38:18 +0000472
473 udelay(curr_delay);
474 tot_delay += curr_delay;
475
476 if (curr_delay < 50)
477 curr_delay += 5;
478 }
479
480 return -ETIMEDOUT;
481}
482
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300483static int ath10k_pci_force_wake(struct ath10k *ar)
484{
485 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
486 unsigned long flags;
487 int ret = 0;
488
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +0200489 if (ar_pci->pci_ps)
490 return ret;
491
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300492 spin_lock_irqsave(&ar_pci->ps_lock, flags);
493
494 if (!ar_pci->ps_awake) {
495 iowrite32(PCIE_SOC_WAKE_V_MASK,
496 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
497 PCIE_SOC_WAKE_ADDRESS);
498
499 ret = ath10k_pci_wake_wait(ar);
500 if (ret == 0)
501 ar_pci->ps_awake = true;
502 }
503
504 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
505
506 return ret;
507}
508
509static void ath10k_pci_force_sleep(struct ath10k *ar)
510{
511 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
512 unsigned long flags;
513
514 spin_lock_irqsave(&ar_pci->ps_lock, flags);
515
516 iowrite32(PCIE_SOC_WAKE_RESET,
517 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
518 PCIE_SOC_WAKE_ADDRESS);
519 ar_pci->ps_awake = false;
520
521 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
522}
523
Michal Kazior77258d42015-05-18 09:38:18 +0000524static int ath10k_pci_wake(struct ath10k *ar)
525{
526 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
527 unsigned long flags;
528 int ret = 0;
529
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300530 if (ar_pci->pci_ps == 0)
531 return ret;
532
Michal Kazior77258d42015-05-18 09:38:18 +0000533 spin_lock_irqsave(&ar_pci->ps_lock, flags);
534
535 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake refcount %lu awake %d\n",
536 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
537
538 /* This function can be called very frequently. To avoid excessive
539 * CPU stalls for MMIO reads use a cache var to hold the device state.
540 */
541 if (!ar_pci->ps_awake) {
542 __ath10k_pci_wake(ar);
543
544 ret = ath10k_pci_wake_wait(ar);
545 if (ret == 0)
546 ar_pci->ps_awake = true;
547 }
548
549 if (ret == 0) {
550 ar_pci->ps_wake_refcount++;
551 WARN_ON(ar_pci->ps_wake_refcount == 0);
552 }
553
554 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
555
556 return ret;
557}
558
559static void ath10k_pci_sleep(struct ath10k *ar)
560{
561 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
562 unsigned long flags;
563
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300564 if (ar_pci->pci_ps == 0)
565 return;
566
Michal Kazior77258d42015-05-18 09:38:18 +0000567 spin_lock_irqsave(&ar_pci->ps_lock, flags);
568
569 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep refcount %lu awake %d\n",
570 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
571
572 if (WARN_ON(ar_pci->ps_wake_refcount == 0))
573 goto skip;
574
575 ar_pci->ps_wake_refcount--;
576
577 mod_timer(&ar_pci->ps_timer, jiffies +
578 msecs_to_jiffies(ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC));
579
580skip:
581 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
582}
583
584static void ath10k_pci_ps_timer(unsigned long ptr)
585{
586 struct ath10k *ar = (void *)ptr;
587 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
588 unsigned long flags;
589
590 spin_lock_irqsave(&ar_pci->ps_lock, flags);
591
592 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps timer refcount %lu awake %d\n",
593 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
594
595 if (ar_pci->ps_wake_refcount > 0)
596 goto skip;
597
598 __ath10k_pci_sleep(ar);
599
600skip:
601 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
602}
603
604static void ath10k_pci_sleep_sync(struct ath10k *ar)
605{
606 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
607 unsigned long flags;
608
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300609 if (ar_pci->pci_ps == 0) {
610 ath10k_pci_force_sleep(ar);
611 return;
612 }
613
Michal Kazior77258d42015-05-18 09:38:18 +0000614 del_timer_sync(&ar_pci->ps_timer);
615
616 spin_lock_irqsave(&ar_pci->ps_lock, flags);
617 WARN_ON(ar_pci->ps_wake_refcount > 0);
618 __ath10k_pci_sleep(ar);
619 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
620}
621
Raja Mani4ddb3292016-01-27 15:24:23 +0530622static void ath10k_bus_pci_write32(struct ath10k *ar, u32 offset, u32 value)
Michal Kazior77258d42015-05-18 09:38:18 +0000623{
624 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
625 int ret;
626
Michal Kazioraeae5b42015-06-15 14:46:42 +0300627 if (unlikely(offset + sizeof(value) > ar_pci->mem_len)) {
628 ath10k_warn(ar, "refusing to write mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
629 offset, offset + sizeof(value), ar_pci->mem_len);
630 return;
631 }
632
Michal Kazior77258d42015-05-18 09:38:18 +0000633 ret = ath10k_pci_wake(ar);
634 if (ret) {
635 ath10k_warn(ar, "failed to wake target for write32 of 0x%08x at 0x%08x: %d\n",
636 value, offset, ret);
637 return;
638 }
639
640 iowrite32(value, ar_pci->mem + offset);
641 ath10k_pci_sleep(ar);
642}
643
Raja Mani4ddb3292016-01-27 15:24:23 +0530644static u32 ath10k_bus_pci_read32(struct ath10k *ar, u32 offset)
Michal Kazior77258d42015-05-18 09:38:18 +0000645{
646 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
647 u32 val;
648 int ret;
649
Michal Kazioraeae5b42015-06-15 14:46:42 +0300650 if (unlikely(offset + sizeof(val) > ar_pci->mem_len)) {
651 ath10k_warn(ar, "refusing to read mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
652 offset, offset + sizeof(val), ar_pci->mem_len);
653 return 0;
654 }
655
Michal Kazior77258d42015-05-18 09:38:18 +0000656 ret = ath10k_pci_wake(ar);
657 if (ret) {
658 ath10k_warn(ar, "failed to wake target for read32 at 0x%08x: %d\n",
659 offset, ret);
660 return 0xffffffff;
661 }
662
663 val = ioread32(ar_pci->mem + offset);
664 ath10k_pci_sleep(ar);
665
666 return val;
667}
668
Raja Mani4ddb3292016-01-27 15:24:23 +0530669inline void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value)
670{
671 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
672
673 ar_pci->bus_ops->write32(ar, offset, value);
674}
675
676inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
677{
678 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
679
680 return ar_pci->bus_ops->read32(ar, offset);
681}
682
Michal Kazior77258d42015-05-18 09:38:18 +0000683u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
684{
685 return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
686}
687
688void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
689{
690 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
691}
692
693u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
694{
695 return ath10k_pci_read32(ar, PCIE_LOCAL_BASE_ADDRESS + addr);
696}
697
698void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
699{
700 ath10k_pci_write32(ar, PCIE_LOCAL_BASE_ADDRESS + addr, val);
701}
702
Raja Manif52f5172016-01-27 15:24:22 +0530703bool ath10k_pci_irq_pending(struct ath10k *ar)
Michal Kaziore5398872013-11-25 14:06:20 +0100704{
705 u32 cause;
706
707 /* Check if the shared legacy irq is for us */
708 cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
709 PCIE_INTR_CAUSE_ADDRESS);
710 if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
711 return true;
712
713 return false;
714}
715
Raja Manif52f5172016-01-27 15:24:22 +0530716void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
Michal Kazior26852182013-11-25 14:06:25 +0100717{
718 /* IMPORTANT: INTR_CLR register has to be set after
719 * INTR_ENABLE is set to 0, otherwise interrupt can not be
720 * really cleared. */
721 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
722 0);
723 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
724 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
725
726 /* IMPORTANT: this extra read transaction is required to
727 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300728 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
729 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100730}
731
Raja Manif52f5172016-01-27 15:24:22 +0530732void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
Michal Kazior26852182013-11-25 14:06:25 +0100733{
734 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
735 PCIE_INTR_ENABLE_ADDRESS,
736 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
737
738 /* IMPORTANT: this extra read transaction is required to
739 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300740 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
741 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100742}
743
Michal Kazior403d6272014-08-22 14:23:31 +0200744static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100745{
Michal Kaziorab977bd2013-11-25 14:06:26 +0100746 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
747
Michal Kazior403d6272014-08-22 14:23:31 +0200748 if (ar_pci->num_msi_intrs > 1)
749 return "msi-x";
Kalle Valod8bb26b2014-09-14 12:50:33 +0300750
751 if (ar_pci->num_msi_intrs == 1)
Michal Kazior403d6272014-08-22 14:23:31 +0200752 return "msi";
Kalle Valod8bb26b2014-09-14 12:50:33 +0300753
754 return "legacy";
Michal Kaziorab977bd2013-11-25 14:06:26 +0100755}
756
Michal Kazior728f95e2014-08-22 14:33:14 +0200757static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100758{
Michal Kazior728f95e2014-08-22 14:33:14 +0200759 struct ath10k *ar = pipe->hif_ce_state;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100760 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +0200761 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
762 struct sk_buff *skb;
763 dma_addr_t paddr;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100764 int ret;
765
Michal Kazior728f95e2014-08-22 14:33:14 +0200766 skb = dev_alloc_skb(pipe->buf_sz);
767 if (!skb)
768 return -ENOMEM;
769
770 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
771
772 paddr = dma_map_single(ar->dev, skb->data,
773 skb->len + skb_tailroom(skb),
774 DMA_FROM_DEVICE);
775 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200776 ath10k_warn(ar, "failed to dma map pci rx buf\n");
Michal Kazior728f95e2014-08-22 14:33:14 +0200777 dev_kfree_skb_any(skb);
778 return -EIO;
779 }
780
Michal Kazior8582bf32015-01-24 12:14:47 +0200781 ATH10K_SKB_RXCB(skb)->paddr = paddr;
Michal Kazior728f95e2014-08-22 14:33:14 +0200782
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300783 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200784 ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300785 spin_unlock_bh(&ar_pci->ce_lock);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100786 if (ret) {
Michal Kazior728f95e2014-08-22 14:33:14 +0200787 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
788 DMA_FROM_DEVICE);
789 dev_kfree_skb_any(skb);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100790 return ret;
791 }
792
793 return 0;
794}
795
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300796static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100797{
Michal Kazior728f95e2014-08-22 14:33:14 +0200798 struct ath10k *ar = pipe->hif_ce_state;
799 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
800 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
801 int ret, num;
802
Michal Kazior728f95e2014-08-22 14:33:14 +0200803 if (pipe->buf_sz == 0)
804 return;
805
806 if (!ce_pipe->dest_ring)
807 return;
808
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300809 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200810 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300811 spin_unlock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200812 while (num--) {
813 ret = __ath10k_pci_rx_post_buf(pipe);
814 if (ret) {
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300815 if (ret == -ENOSPC)
816 break;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200817 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
Michal Kazior728f95e2014-08-22 14:33:14 +0200818 mod_timer(&ar_pci->rx_post_retry, jiffies +
819 ATH10K_PCI_RX_POST_RETRY_MS);
820 break;
821 }
822 }
823}
824
Raja Manif52f5172016-01-27 15:24:22 +0530825void ath10k_pci_rx_post(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +0200826{
827 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
828 int i;
829
Michal Kazior728f95e2014-08-22 14:33:14 +0200830 for (i = 0; i < CE_COUNT; i++)
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300831 ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
Michal Kazior728f95e2014-08-22 14:33:14 +0200832}
833
Raja Manif52f5172016-01-27 15:24:22 +0530834void ath10k_pci_rx_replenish_retry(unsigned long ptr)
Michal Kazior728f95e2014-08-22 14:33:14 +0200835{
836 struct ath10k *ar = (void *)ptr;
837
838 ath10k_pci_rx_post(ar);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100839}
840
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530841static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
842{
843 u32 val = 0;
844
845 switch (ar->hw_rev) {
846 case ATH10K_HW_QCA988X:
847 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +0100848 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530849 val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
850 CORE_CTRL_ADDRESS) &
Vasanthakumar Thiagarajan3c7e2562015-07-03 19:25:27 +0530851 0x7ff) << 21;
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530852 break;
853 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +0530854 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530855 val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
856 break;
857 }
858
859 val |= 0x100000 | (addr & 0xfffff);
860 return val;
861}
862
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863/*
864 * Diagnostic read/write access is provided for startup/config/debug usage.
865 * Caller must guarantee proper alignment, when applicable, and single user
866 * at any moment.
867 */
868static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
869 int nbytes)
870{
871 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
872 int ret = 0;
873 u32 buf;
874 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
875 unsigned int id;
876 unsigned int flags;
Michal Kazior2aa39112013-08-27 13:08:02 +0200877 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300878 /* Host buffer address in CE space */
879 u32 ce_data;
880 dma_addr_t ce_data_base = 0;
881 void *data_buf = NULL;
882 int i;
883
Kalle Valoeef25402014-09-24 14:16:52 +0300884 spin_lock_bh(&ar_pci->ce_lock);
885
Kalle Valo5e3dd152013-06-12 20:52:10 +0300886 ce_diag = ar_pci->ce_diag;
887
888 /*
889 * Allocate a temporary bounce buffer to hold caller's data
890 * to be DMA'ed from Target. This guarantees
891 * 1) 4-byte alignment
892 * 2) Buffer in DMA-able space
893 */
894 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +0200895 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
896 orig_nbytes,
897 &ce_data_base,
898 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899
900 if (!data_buf) {
901 ret = -ENOMEM;
902 goto done;
903 }
904 memset(data_buf, 0, orig_nbytes);
905
906 remaining_bytes = orig_nbytes;
907 ce_data = ce_data_base;
908 while (remaining_bytes) {
909 nbytes = min_t(unsigned int, remaining_bytes,
910 DIAG_TRANSFER_LIMIT);
911
Kalle Valoeef25402014-09-24 14:16:52 +0300912 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913 if (ret != 0)
914 goto done;
915
916 /* Request CE to send from Target(!) address to Host buffer */
917 /*
918 * The address supplied by the caller is in the
919 * Target CPU virtual address space.
920 *
921 * In order to use this address with the diagnostic CE,
922 * convert it from Target CPU virtual address space
923 * to CE address space
924 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530925 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926
Kalle Valoeef25402014-09-24 14:16:52 +0300927 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
928 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929 if (ret)
930 goto done;
931
932 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +0530933 while (ath10k_ce_completed_send_next_nolock(ce_diag,
934 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935 mdelay(1);
936 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
937 ret = -EBUSY;
938 goto done;
939 }
940 }
941
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942 i = 0;
Kalle Valoeef25402014-09-24 14:16:52 +0300943 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
944 &completed_nbytes,
945 &id, &flags) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300946 mdelay(1);
947
948 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
949 ret = -EBUSY;
950 goto done;
951 }
952 }
953
954 if (nbytes != completed_nbytes) {
955 ret = -EIO;
956 goto done;
957 }
958
959 if (buf != ce_data) {
960 ret = -EIO;
961 goto done;
962 }
963
964 remaining_bytes -= nbytes;
965 address += nbytes;
966 ce_data += nbytes;
967 }
968
969done:
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300970 if (ret == 0)
971 memcpy(data, data_buf, orig_nbytes);
972 else
Michal Kazior7aa7a722014-08-25 12:09:38 +0200973 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +0200974 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300975
976 if (data_buf)
Michal Kazior68c03242014-03-28 10:02:35 +0200977 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
978 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300979
Kalle Valoeef25402014-09-24 14:16:52 +0300980 spin_unlock_bh(&ar_pci->ce_lock);
981
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982 return ret;
983}
984
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300985static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
986{
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300987 __le32 val = 0;
988 int ret;
989
990 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
991 *value = __le32_to_cpu(val);
992
993 return ret;
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300994}
995
996static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
997 u32 src, u32 len)
998{
999 u32 host_addr, addr;
1000 int ret;
1001
1002 host_addr = host_interest_item_address(src);
1003
1004 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
1005 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001006 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001007 src, ret);
1008 return ret;
1009 }
1010
1011 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
1012 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001013 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001014 addr, len, ret);
1015 return ret;
1016 }
1017
1018 return 0;
1019}
1020
1021#define ath10k_pci_diag_read_hi(ar, dest, src, len) \
Kalle Valo8cc7f262014-09-14 12:50:39 +03001022 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001023
Raja Manif52f5172016-01-27 15:24:22 +05301024int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
1025 const void *data, int nbytes)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001026{
1027 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1028 int ret = 0;
1029 u32 buf;
1030 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
1031 unsigned int id;
1032 unsigned int flags;
Michal Kazior2aa39112013-08-27 13:08:02 +02001033 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001034 void *data_buf = NULL;
1035 u32 ce_data; /* Host buffer address in CE space */
1036 dma_addr_t ce_data_base = 0;
1037 int i;
1038
Kalle Valoeef25402014-09-24 14:16:52 +03001039 spin_lock_bh(&ar_pci->ce_lock);
1040
Kalle Valo5e3dd152013-06-12 20:52:10 +03001041 ce_diag = ar_pci->ce_diag;
1042
1043 /*
1044 * Allocate a temporary bounce buffer to hold caller's data
1045 * to be DMA'ed to Target. This guarantees
1046 * 1) 4-byte alignment
1047 * 2) Buffer in DMA-able space
1048 */
1049 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +02001050 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
1051 orig_nbytes,
1052 &ce_data_base,
1053 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001054 if (!data_buf) {
1055 ret = -ENOMEM;
1056 goto done;
1057 }
1058
1059 /* Copy caller's data to allocated DMA buf */
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001060 memcpy(data_buf, data, orig_nbytes);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001061
1062 /*
1063 * The address supplied by the caller is in the
1064 * Target CPU virtual address space.
1065 *
1066 * In order to use this address with the diagnostic CE,
1067 * convert it from
1068 * Target CPU virtual address space
1069 * to
1070 * CE address space
1071 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +05301072 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001073
1074 remaining_bytes = orig_nbytes;
1075 ce_data = ce_data_base;
1076 while (remaining_bytes) {
1077 /* FIXME: check cast */
1078 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
1079
1080 /* Set up to receive directly into Target(!) address */
Kalle Valoeef25402014-09-24 14:16:52 +03001081 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001082 if (ret != 0)
1083 goto done;
1084
1085 /*
1086 * Request CE to send caller-supplied data that
1087 * was copied to bounce buffer to Target(!) address.
1088 */
Kalle Valoeef25402014-09-24 14:16:52 +03001089 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
1090 nbytes, 0, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001091 if (ret != 0)
1092 goto done;
1093
1094 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301095 while (ath10k_ce_completed_send_next_nolock(ce_diag,
1096 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001097 mdelay(1);
1098
1099 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1100 ret = -EBUSY;
1101 goto done;
1102 }
1103 }
1104
Kalle Valo5e3dd152013-06-12 20:52:10 +03001105 i = 0;
Kalle Valoeef25402014-09-24 14:16:52 +03001106 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
1107 &completed_nbytes,
1108 &id, &flags) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001109 mdelay(1);
1110
1111 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1112 ret = -EBUSY;
1113 goto done;
1114 }
1115 }
1116
1117 if (nbytes != completed_nbytes) {
1118 ret = -EIO;
1119 goto done;
1120 }
1121
1122 if (buf != address) {
1123 ret = -EIO;
1124 goto done;
1125 }
1126
1127 remaining_bytes -= nbytes;
1128 address += nbytes;
1129 ce_data += nbytes;
1130 }
1131
1132done:
1133 if (data_buf) {
Michal Kazior68c03242014-03-28 10:02:35 +02001134 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
1135 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 }
1137
1138 if (ret != 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001139 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +02001140 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001141
Kalle Valoeef25402014-09-24 14:16:52 +03001142 spin_unlock_bh(&ar_pci->ce_lock);
1143
Kalle Valo5e3dd152013-06-12 20:52:10 +03001144 return ret;
1145}
1146
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001147static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
1148{
1149 __le32 val = __cpu_to_le32(value);
1150
1151 return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
1152}
1153
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154/* Called by lower (CE) layer when a send to Target completes. */
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301155static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001156{
1157 struct ath10k *ar = ce_state->ar;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001158 struct sk_buff_head list;
1159 struct sk_buff *skb;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001160
Michal Kazior1cb86d42014-11-27 11:09:38 +01001161 __skb_queue_head_init(&list);
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301162 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Michal Kaziora16942e2014-02-27 18:50:04 +02001163 /* no need to call tx completion for NULL pointers */
Michal Kazior1cb86d42014-11-27 11:09:38 +01001164 if (skb == NULL)
Michal Kazior726346f2014-02-27 18:50:04 +02001165 continue;
1166
Michal Kazior1cb86d42014-11-27 11:09:38 +01001167 __skb_queue_tail(&list, skb);
Michal Kazior5440ce22013-09-03 15:09:58 +02001168 }
Michal Kazior1cb86d42014-11-27 11:09:38 +01001169
1170 while ((skb = __skb_dequeue(&list)))
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301171 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172}
1173
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301174static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
1175 void (*callback)(struct ath10k *ar,
1176 struct sk_buff *skb))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177{
1178 struct ath10k *ar = ce_state->ar;
1179 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior87263e52013-08-27 13:08:01 +02001180 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001181 struct sk_buff *skb;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001182 struct sk_buff_head list;
Michal Kazior5440ce22013-09-03 15:09:58 +02001183 void *transfer_context;
1184 u32 ce_data;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001185 unsigned int nbytes, max_nbytes;
Michal Kazior5440ce22013-09-03 15:09:58 +02001186 unsigned int transfer_id;
1187 unsigned int flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001188
Michal Kazior1cb86d42014-11-27 11:09:38 +01001189 __skb_queue_head_init(&list);
Michal Kazior5440ce22013-09-03 15:09:58 +02001190 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
1191 &ce_data, &nbytes, &transfer_id,
1192 &flags) == 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193 skb = transfer_context;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001194 max_nbytes = skb->len + skb_tailroom(skb);
Michal Kazior8582bf32015-01-24 12:14:47 +02001195 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior2f5280d2014-02-27 18:50:05 +02001196 max_nbytes, DMA_FROM_DEVICE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197
Michal Kazior2f5280d2014-02-27 18:50:05 +02001198 if (unlikely(max_nbytes < nbytes)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001199 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
Michal Kazior2f5280d2014-02-27 18:50:05 +02001200 nbytes, max_nbytes);
1201 dev_kfree_skb_any(skb);
1202 continue;
1203 }
1204
1205 skb_put(skb, nbytes);
Michal Kazior1cb86d42014-11-27 11:09:38 +01001206 __skb_queue_tail(&list, skb);
1207 }
Michal Kaziora360e542014-09-23 10:22:54 +02001208
Michal Kazior1cb86d42014-11-27 11:09:38 +01001209 while ((skb = __skb_dequeue(&list))) {
Michal Kaziora360e542014-09-23 10:22:54 +02001210 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1211 ce_state->id, skb->len);
1212 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1213 skb->data, skb->len);
1214
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301215 callback(ar, skb);
Michal Kazior2f5280d2014-02-27 18:50:05 +02001216 }
Michal Kaziorc29a3802014-07-21 21:03:10 +03001217
Michal Kazior728f95e2014-08-22 14:33:14 +02001218 ath10k_pci_rx_post_pipe(pipe_info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001219}
1220
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301221/* Called by lower (CE) layer when data is received from the Target. */
1222static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1223{
1224 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1225}
1226
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +05301227static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1228{
1229 /* CE4 polling needs to be done whenever CE pipe which transports
1230 * HTT Rx (target->host) is processed.
1231 */
1232 ath10k_ce_per_engine_service(ce_state->ar, 4);
1233
1234 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1235}
1236
Vivek Natarajanafb0bf72015-10-30 14:57:58 +05301237/* Called by lower (CE) layer when data is received from the Target.
1238 * Only 10.4 firmware uses separate CE to transfer pktlog data.
1239 */
1240static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
1241{
1242 ath10k_pci_process_rx_cb(ce_state,
1243 ath10k_htt_rx_pktlog_completion_handler);
1244}
1245
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301246/* Called by lower (CE) layer when a send to HTT Target completes. */
1247static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
1248{
1249 struct ath10k *ar = ce_state->ar;
1250 struct sk_buff *skb;
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301251
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301252 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301253 /* no need to call tx completion for NULL pointers */
1254 if (!skb)
1255 continue;
1256
1257 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1258 skb->len, DMA_TO_DEVICE);
1259 ath10k_htt_hif_tx_complete(ar, skb);
1260 }
1261}
1262
1263static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
1264{
1265 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
1266 ath10k_htt_t2h_msg_handler(ar, skb);
1267}
1268
1269/* Called by lower (CE) layer when HTT data is received from the Target. */
1270static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
1271{
1272 /* CE4 polling needs to be done whenever CE pipe which transports
1273 * HTT Rx (target->host) is processed.
1274 */
1275 ath10k_ce_per_engine_service(ce_state->ar, 4);
1276
1277 ath10k_pci_process_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
1278}
1279
Raja Manif52f5172016-01-27 15:24:22 +05301280int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
1281 struct ath10k_hif_sg_item *items, int n_items)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001282{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior726346f2014-02-27 18:50:04 +02001284 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
1285 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
1286 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
Michal Kazior7147a132014-05-26 12:02:58 +02001287 unsigned int nentries_mask;
1288 unsigned int sw_index;
1289 unsigned int write_index;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001290 int err, i = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001291
Michal Kazior726346f2014-02-27 18:50:04 +02001292 spin_lock_bh(&ar_pci->ce_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001293
Michal Kazior7147a132014-05-26 12:02:58 +02001294 nentries_mask = src_ring->nentries_mask;
1295 sw_index = src_ring->sw_index;
1296 write_index = src_ring->write_index;
1297
Michal Kazior726346f2014-02-27 18:50:04 +02001298 if (unlikely(CE_RING_DELTA(nentries_mask,
1299 write_index, sw_index - 1) < n_items)) {
1300 err = -ENOBUFS;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001301 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001302 }
1303
1304 for (i = 0; i < n_items - 1; i++) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001305 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001306 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1307 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001308 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001309 items[i].vaddr, items[i].len);
1310
1311 err = ath10k_ce_send_nolock(ce_pipe,
1312 items[i].transfer_context,
1313 items[i].paddr,
1314 items[i].len,
1315 items[i].transfer_id,
1316 CE_SEND_FLAG_GATHER);
1317 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001318 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001319 }
1320
1321 /* `i` is equal to `n_items -1` after for() */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001322
Michal Kazior7aa7a722014-08-25 12:09:38 +02001323 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001324 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1325 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001326 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001327 items[i].vaddr, items[i].len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001328
Michal Kazior726346f2014-02-27 18:50:04 +02001329 err = ath10k_ce_send_nolock(ce_pipe,
1330 items[i].transfer_context,
1331 items[i].paddr,
1332 items[i].len,
1333 items[i].transfer_id,
1334 0);
1335 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001336 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001337
Michal Kazior08b8aa02014-05-26 12:02:59 +02001338 spin_unlock_bh(&ar_pci->ce_lock);
1339 return 0;
1340
1341err:
1342 for (; i > 0; i--)
1343 __ath10k_ce_send_revert(ce_pipe);
1344
Michal Kazior726346f2014-02-27 18:50:04 +02001345 spin_unlock_bh(&ar_pci->ce_lock);
1346 return err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347}
1348
Raja Manif52f5172016-01-27 15:24:22 +05301349int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
1350 size_t buf_len)
Kalle Valoeef25402014-09-24 14:16:52 +03001351{
1352 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
1353}
1354
Raja Manif52f5172016-01-27 15:24:22 +05301355u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356{
1357 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001358
Michal Kazior7aa7a722014-08-25 12:09:38 +02001359 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001360
Michal Kazior3efcb3b2013-10-02 11:03:41 +02001361 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362}
1363
Ben Greear384914b2014-08-25 08:37:32 +03001364static void ath10k_pci_dump_registers(struct ath10k *ar,
1365 struct ath10k_fw_crash_data *crash_data)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366{
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001367 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
1368 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369
Ben Greear384914b2014-08-25 08:37:32 +03001370 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001372 ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
1373 hi_failure_state,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001374 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001375 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001376 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 return;
1378 }
1379
1380 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
1381
Michal Kazior7aa7a722014-08-25 12:09:38 +02001382 ath10k_err(ar, "firmware register dump:\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001384 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 i,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001386 __le32_to_cpu(reg_dump_values[i]),
1387 __le32_to_cpu(reg_dump_values[i + 1]),
1388 __le32_to_cpu(reg_dump_values[i + 2]),
1389 __le32_to_cpu(reg_dump_values[i + 3]));
Michal Kazioraffd3212013-07-16 09:54:35 +02001390
Michal Kazior1bbb1192014-08-25 12:13:14 +02001391 if (!crash_data)
1392 return;
1393
Ben Greear384914b2014-08-25 08:37:32 +03001394 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001395 crash_data->registers[i] = reg_dump_values[i];
Ben Greear384914b2014-08-25 08:37:32 +03001396}
1397
Kalle Valo0e9848c2014-08-25 08:37:37 +03001398static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
Ben Greear384914b2014-08-25 08:37:32 +03001399{
1400 struct ath10k_fw_crash_data *crash_data;
1401 char uuid[50];
1402
1403 spin_lock_bh(&ar->data_lock);
1404
Ben Greearf51dbe72014-09-29 14:41:46 +03001405 ar->stats.fw_crash_counter++;
1406
Ben Greear384914b2014-08-25 08:37:32 +03001407 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
1408
1409 if (crash_data)
1410 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
1411 else
1412 scnprintf(uuid, sizeof(uuid), "n/a");
1413
Michal Kazior7aa7a722014-08-25 12:09:38 +02001414 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
Kalle Valo8a0c7972014-08-25 08:37:45 +03001415 ath10k_print_driver_info(ar);
Ben Greear384914b2014-08-25 08:37:32 +03001416 ath10k_pci_dump_registers(ar, crash_data);
1417
Ben Greear384914b2014-08-25 08:37:32 +03001418 spin_unlock_bh(&ar->data_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02001419
Michal Kazior5e90de82013-10-16 16:46:05 +03001420 queue_work(ar->workqueue, &ar->restart_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001421}
1422
Raja Manif52f5172016-01-27 15:24:22 +05301423void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1424 int force)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001425{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001426 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001427
Kalle Valo5e3dd152013-06-12 20:52:10 +03001428 if (!force) {
1429 int resources;
1430 /*
1431 * Decide whether to actually poll for completions, or just
1432 * wait for a later chance.
1433 * If there seem to be plenty of resources left, then just wait
1434 * since checking involves reading a CE register, which is a
1435 * relatively expensive operation.
1436 */
1437 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1438
1439 /*
1440 * If at least 50% of the total resources are still available,
1441 * don't bother checking again yet.
1442 */
1443 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1444 return;
1445 }
1446 ath10k_ce_per_engine_service(ar, pipe);
1447}
1448
Raja Manif52f5172016-01-27 15:24:22 +05301449void ath10k_pci_kill_tasklet(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001450{
1451 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452 int i;
1453
Kalle Valo5e3dd152013-06-12 20:52:10 +03001454 tasklet_kill(&ar_pci->intr_tq);
Michal Kazior103d4f52013-11-08 08:01:24 +01001455 tasklet_kill(&ar_pci->msi_fw_err);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001456
1457 for (i = 0; i < CE_COUNT; i++)
1458 tasklet_kill(&ar_pci->pipe_info[i].intr);
Michal Kazior728f95e2014-08-22 14:33:14 +02001459
1460 del_timer_sync(&ar_pci->rx_post_retry);
Michal Kazior96a9d0d2013-11-08 08:01:25 +01001461}
1462
Raja Manif52f5172016-01-27 15:24:22 +05301463int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
1464 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001465{
Michal Kazior7c6aa252014-08-26 19:14:03 +03001466 const struct service_to_pipe *entry;
1467 bool ul_set = false, dl_set = false;
1468 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001469
Michal Kazior7aa7a722014-08-25 12:09:38 +02001470 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001471
Michal Kazior7c6aa252014-08-26 19:14:03 +03001472 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1473 entry = &target_service_to_ce_map_wlan[i];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001475 if (__le32_to_cpu(entry->service_id) != service_id)
Michal Kazior7c6aa252014-08-26 19:14:03 +03001476 continue;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001477
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001478 switch (__le32_to_cpu(entry->pipedir)) {
Michal Kazior7c6aa252014-08-26 19:14:03 +03001479 case PIPEDIR_NONE:
1480 break;
1481 case PIPEDIR_IN:
1482 WARN_ON(dl_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001483 *dl_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001484 dl_set = true;
1485 break;
1486 case PIPEDIR_OUT:
1487 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001488 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001489 ul_set = true;
1490 break;
1491 case PIPEDIR_INOUT:
1492 WARN_ON(dl_set);
1493 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001494 *dl_pipe = __le32_to_cpu(entry->pipenum);
1495 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001496 dl_set = true;
1497 ul_set = true;
1498 break;
1499 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001500 }
Michal Kazior7c6aa252014-08-26 19:14:03 +03001501
1502 if (WARN_ON(!ul_set || !dl_set))
1503 return -ENOENT;
1504
Michal Kazior7c6aa252014-08-26 19:14:03 +03001505 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001506}
1507
Raja Manif52f5172016-01-27 15:24:22 +05301508void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1509 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001510{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001511 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001512
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1514 ATH10K_HTC_SVC_ID_RSVD_CTRL,
Rajkumar Manoharan400143e2015-10-12 18:27:06 +05301515 ul_pipe, dl_pipe);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001516}
1517
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001518static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1519{
1520 u32 val;
1521
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301522 switch (ar->hw_rev) {
1523 case ATH10K_HW_QCA988X:
1524 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001525 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301526 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1527 CORE_CTRL_ADDRESS);
1528 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1529 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1530 CORE_CTRL_ADDRESS, val);
1531 break;
1532 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +05301533 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301534 /* TODO: Find appropriate register configuration for QCA99X0
1535 * to mask irq/MSI.
1536 */
1537 break;
1538 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001539}
1540
1541static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1542{
1543 u32 val;
1544
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301545 switch (ar->hw_rev) {
1546 case ATH10K_HW_QCA988X:
1547 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001548 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301549 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1550 CORE_CTRL_ADDRESS);
1551 val |= CORE_CTRL_PCIE_REG_31_MASK;
1552 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1553 CORE_CTRL_ADDRESS, val);
1554 break;
1555 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +05301556 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301557 /* TODO: Find appropriate register configuration for QCA99X0
1558 * to unmask irq/MSI.
1559 */
1560 break;
1561 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001562}
1563
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001564static void ath10k_pci_irq_disable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001565{
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001566 ath10k_ce_disable_interrupts(ar);
1567 ath10k_pci_disable_and_clear_legacy_irq(ar);
1568 ath10k_pci_irq_msi_fw_mask(ar);
1569}
1570
1571static void ath10k_pci_irq_sync(struct ath10k *ar)
1572{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001574 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001576 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1577 synchronize_irq(ar_pci->pdev->irq + i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001578}
1579
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001580static void ath10k_pci_irq_enable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581{
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001582 ath10k_ce_enable_interrupts(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001583 ath10k_pci_enable_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001584 ath10k_pci_irq_msi_fw_unmask(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001585}
1586
1587static int ath10k_pci_hif_start(struct ath10k *ar)
1588{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001589 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo9a149692015-10-05 17:56:36 +03001590
Michal Kazior7aa7a722014-08-25 12:09:38 +02001591 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001593 ath10k_pci_irq_enable(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +02001594 ath10k_pci_rx_post(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001595
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001596 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
1597 ar_pci->link_ctl);
1598
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 return 0;
1600}
1601
Michal Kazior099ac7c2014-10-28 10:32:05 +01001602static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603{
1604 struct ath10k *ar;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001605 struct ath10k_ce_pipe *ce_pipe;
1606 struct ath10k_ce_ring *ce_ring;
1607 struct sk_buff *skb;
1608 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609
Michal Kazior099ac7c2014-10-28 10:32:05 +01001610 ar = pci_pipe->hif_ce_state;
1611 ce_pipe = pci_pipe->ce_hdl;
1612 ce_ring = ce_pipe->dest_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001613
Michal Kazior099ac7c2014-10-28 10:32:05 +01001614 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 return;
1616
Michal Kazior099ac7c2014-10-28 10:32:05 +01001617 if (!pci_pipe->buf_sz)
1618 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619
Michal Kazior099ac7c2014-10-28 10:32:05 +01001620 for (i = 0; i < ce_ring->nentries; i++) {
1621 skb = ce_ring->per_transfer_context[i];
1622 if (!skb)
1623 continue;
1624
1625 ce_ring->per_transfer_context[i] = NULL;
1626
Michal Kazior8582bf32015-01-24 12:14:47 +02001627 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior099ac7c2014-10-28 10:32:05 +01001628 skb->len + skb_tailroom(skb),
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 DMA_FROM_DEVICE);
Michal Kazior099ac7c2014-10-28 10:32:05 +01001630 dev_kfree_skb_any(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 }
1632}
1633
Michal Kazior099ac7c2014-10-28 10:32:05 +01001634static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635{
1636 struct ath10k *ar;
1637 struct ath10k_pci *ar_pci;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001638 struct ath10k_ce_pipe *ce_pipe;
1639 struct ath10k_ce_ring *ce_ring;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001640 struct sk_buff *skb;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001641 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001642
Michal Kazior099ac7c2014-10-28 10:32:05 +01001643 ar = pci_pipe->hif_ce_state;
1644 ar_pci = ath10k_pci_priv(ar);
1645 ce_pipe = pci_pipe->ce_hdl;
1646 ce_ring = ce_pipe->src_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647
Michal Kazior099ac7c2014-10-28 10:32:05 +01001648 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001649 return;
1650
Michal Kazior099ac7c2014-10-28 10:32:05 +01001651 if (!pci_pipe->buf_sz)
1652 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653
Michal Kazior099ac7c2014-10-28 10:32:05 +01001654 for (i = 0; i < ce_ring->nentries; i++) {
1655 skb = ce_ring->per_transfer_context[i];
1656 if (!skb)
Michal Kazior2415fc12013-11-08 08:01:32 +01001657 continue;
Michal Kazior2415fc12013-11-08 08:01:32 +01001658
Michal Kazior099ac7c2014-10-28 10:32:05 +01001659 ce_ring->per_transfer_context[i] = NULL;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001660
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301661 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 }
1663}
1664
1665/*
1666 * Cleanup residual buffers for device shutdown:
1667 * buffers that were enqueued for receive
1668 * buffers that were to be sent
1669 * Note: Buffers that had completed but which were
1670 * not yet processed are on a completion queue. They
1671 * are handled when the completion thread shuts down.
1672 */
1673static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1674{
1675 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1676 int pipe_num;
1677
Michal Kaziorfad6ed72013-11-08 08:01:23 +01001678 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
Michal Kazior87263e52013-08-27 13:08:01 +02001679 struct ath10k_pci_pipe *pipe_info;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001680
1681 pipe_info = &ar_pci->pipe_info[pipe_num];
1682 ath10k_pci_rx_pipe_cleanup(pipe_info);
1683 ath10k_pci_tx_pipe_cleanup(pipe_info);
1684 }
1685}
1686
Raja Manif52f5172016-01-27 15:24:22 +05301687void ath10k_pci_ce_deinit(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001688{
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001689 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001691 for (i = 0; i < CE_COUNT; i++)
1692 ath10k_ce_deinit_pipe(ar, i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001693}
1694
Raja Manif52f5172016-01-27 15:24:22 +05301695void ath10k_pci_flush(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +02001696{
1697 ath10k_pci_kill_tasklet(ar);
1698 ath10k_pci_buffer_cleanup(ar);
1699}
1700
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701static void ath10k_pci_hif_stop(struct ath10k *ar)
1702{
Michal Kazior77258d42015-05-18 09:38:18 +00001703 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1704 unsigned long flags;
1705
Michal Kazior7aa7a722014-08-25 12:09:38 +02001706 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
Michal Kazior32270b62013-08-02 09:15:47 +02001707
Michal Kazior10d23db2014-08-22 14:33:15 +02001708 /* Most likely the device has HTT Rx ring configured. The only way to
1709 * prevent the device from accessing (and possible corrupting) host
1710 * memory is to reset the chip now.
Michal Kaziore75db4e2014-08-28 22:14:16 +03001711 *
1712 * There's also no known way of masking MSI interrupts on the device.
1713 * For ranged MSI the CE-related interrupts can be masked. However
1714 * regardless how many MSI interrupts are assigned the first one
1715 * is always used for firmware indications (crashes) and cannot be
1716 * masked. To prevent the device from asserting the interrupt reset it
1717 * before proceeding with cleanup.
Michal Kazior10d23db2014-08-22 14:33:15 +02001718 */
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301719 ath10k_pci_safe_chip_reset(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001720
1721 ath10k_pci_irq_disable(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001722 ath10k_pci_irq_sync(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001723 ath10k_pci_flush(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00001724
1725 spin_lock_irqsave(&ar_pci->ps_lock, flags);
1726 WARN_ON(ar_pci->ps_wake_refcount > 0);
1727 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001728}
1729
Raja Manif52f5172016-01-27 15:24:22 +05301730int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1731 void *req, u32 req_len,
1732 void *resp, u32 *resp_len)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733{
1734 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior2aa39112013-08-27 13:08:02 +02001735 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1736 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1737 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1738 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001739 dma_addr_t req_paddr = 0;
1740 dma_addr_t resp_paddr = 0;
1741 struct bmi_xfer xfer = {};
1742 void *treq, *tresp = NULL;
1743 int ret = 0;
1744
Michal Kazior85622cd2013-11-25 14:06:22 +01001745 might_sleep();
1746
Kalle Valo5e3dd152013-06-12 20:52:10 +03001747 if (resp && !resp_len)
1748 return -EINVAL;
1749
1750 if (resp && resp_len && *resp_len == 0)
1751 return -EINVAL;
1752
1753 treq = kmemdup(req, req_len, GFP_KERNEL);
1754 if (!treq)
1755 return -ENOMEM;
1756
1757 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1758 ret = dma_mapping_error(ar->dev, req_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001759 if (ret) {
1760 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001761 goto err_dma;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001762 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763
1764 if (resp && resp_len) {
1765 tresp = kzalloc(*resp_len, GFP_KERNEL);
1766 if (!tresp) {
1767 ret = -ENOMEM;
1768 goto err_req;
1769 }
1770
1771 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1772 DMA_FROM_DEVICE);
1773 ret = dma_mapping_error(ar->dev, resp_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001774 if (ret) {
Anton Protopopov22baa982016-02-10 11:58:55 -05001775 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776 goto err_req;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001777 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778
1779 xfer.wait_for_resp = true;
1780 xfer.resp_len = 0;
1781
Michal Kazior728f95e2014-08-22 14:33:14 +02001782 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783 }
1784
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1786 if (ret)
1787 goto err_resp;
1788
Michal Kazior85622cd2013-11-25 14:06:22 +01001789 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1790 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791 u32 unused_buffer;
1792 unsigned int unused_nbytes;
1793 unsigned int unused_id;
1794
Kalle Valo5e3dd152013-06-12 20:52:10 +03001795 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1796 &unused_nbytes, &unused_id);
1797 } else {
1798 /* non-zero means we did not time out */
1799 ret = 0;
1800 }
1801
1802err_resp:
1803 if (resp) {
1804 u32 unused_buffer;
1805
1806 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1807 dma_unmap_single(ar->dev, resp_paddr,
1808 *resp_len, DMA_FROM_DEVICE);
1809 }
1810err_req:
1811 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1812
1813 if (ret == 0 && resp_len) {
1814 *resp_len = min(*resp_len, xfer.resp_len);
1815 memcpy(resp, tresp, xfer.resp_len);
1816 }
1817err_dma:
1818 kfree(treq);
1819 kfree(tresp);
1820
1821 return ret;
1822}
1823
Michal Kazior5440ce22013-09-03 15:09:58 +02001824static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001825{
Michal Kazior5440ce22013-09-03 15:09:58 +02001826 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001827
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301828 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
Michal Kazior5440ce22013-09-03 15:09:58 +02001829 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830
Michal Kazior2374b182014-07-14 16:25:25 +03001831 xfer->tx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001832}
1833
Michal Kazior5440ce22013-09-03 15:09:58 +02001834static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001836 struct ath10k *ar = ce_state->ar;
Michal Kazior5440ce22013-09-03 15:09:58 +02001837 struct bmi_xfer *xfer;
1838 u32 ce_data;
1839 unsigned int nbytes;
1840 unsigned int transfer_id;
1841 unsigned int flags;
1842
1843 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data,
1844 &nbytes, &transfer_id, &flags))
1845 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001846
Michal Kazior04ed9df2014-10-28 10:34:36 +01001847 if (WARN_ON_ONCE(!xfer))
1848 return;
1849
Kalle Valo5e3dd152013-06-12 20:52:10 +03001850 if (!xfer->wait_for_resp) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001851 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001852 return;
1853 }
1854
1855 xfer->resp_len = nbytes;
Michal Kazior2374b182014-07-14 16:25:25 +03001856 xfer->rx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001857}
1858
Michal Kazior85622cd2013-11-25 14:06:22 +01001859static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1860 struct ath10k_ce_pipe *rx_pipe,
1861 struct bmi_xfer *xfer)
1862{
1863 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1864
1865 while (time_before_eq(jiffies, timeout)) {
1866 ath10k_pci_bmi_send_done(tx_pipe);
1867 ath10k_pci_bmi_recv_data(rx_pipe);
1868
Michal Kazior2374b182014-07-14 16:25:25 +03001869 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
Michal Kazior85622cd2013-11-25 14:06:22 +01001870 return 0;
1871
1872 schedule();
1873 }
1874
1875 return -ETIMEDOUT;
1876}
1877
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878/*
Kalle Valo5e3dd152013-06-12 20:52:10 +03001879 * Send an interrupt to the device to wake up the Target CPU
1880 * so it has an opportunity to notice any changed state.
1881 */
1882static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1883{
Michal Kazior9e264942014-09-02 11:00:21 +03001884 u32 addr, val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885
Michal Kazior9e264942014-09-02 11:00:21 +03001886 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1887 val = ath10k_pci_read32(ar, addr);
1888 val |= CORE_CTRL_CPU_INTR_MASK;
1889 ath10k_pci_write32(ar, addr, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001890
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001891 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892}
1893
Michal Kaziord63955b2015-01-24 12:14:49 +02001894static int ath10k_pci_get_num_banks(struct ath10k *ar)
1895{
1896 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1897
1898 switch (ar_pci->pdev->device) {
1899 case QCA988X_2_0_DEVICE_ID:
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05301900 case QCA99X0_2_0_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001901 return 1;
Michal Kazior36582e52015-08-13 14:32:26 +02001902 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001903 case QCA6174_2_1_DEVICE_ID:
1904 switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
1905 case QCA6174_HW_1_0_CHIP_ID_REV:
1906 case QCA6174_HW_1_1_CHIP_ID_REV:
Michal Kazior11a002e2015-04-20 09:20:41 +00001907 case QCA6174_HW_2_1_CHIP_ID_REV:
1908 case QCA6174_HW_2_2_CHIP_ID_REV:
Michal Kaziord63955b2015-01-24 12:14:49 +02001909 return 3;
1910 case QCA6174_HW_1_3_CHIP_ID_REV:
1911 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001912 case QCA6174_HW_3_0_CHIP_ID_REV:
1913 case QCA6174_HW_3_1_CHIP_ID_REV:
1914 case QCA6174_HW_3_2_CHIP_ID_REV:
1915 return 9;
1916 }
1917 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01001918 case QCA9377_1_0_DEVICE_ID:
1919 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001920 }
1921
1922 ath10k_warn(ar, "unknown number of banks, assuming 1\n");
1923 return 1;
1924}
1925
Raja Mani4ddb3292016-01-27 15:24:23 +05301926static int ath10k_bus_get_num_banks(struct ath10k *ar)
1927{
1928 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1929
1930 return ar_pci->bus_ops->get_num_banks(ar);
1931}
1932
Raja Manif52f5172016-01-27 15:24:22 +05301933int ath10k_pci_init_config(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001934{
1935 u32 interconnect_targ_addr;
1936 u32 pcie_state_targ_addr = 0;
1937 u32 pipe_cfg_targ_addr = 0;
1938 u32 svc_to_pipe_map = 0;
1939 u32 pcie_config_flags = 0;
1940 u32 ealloc_value;
1941 u32 ealloc_targ_addr;
1942 u32 flag2_value;
1943 u32 flag2_targ_addr;
1944 int ret = 0;
1945
1946 /* Download to Target the CE Config and the service-to-CE map */
1947 interconnect_targ_addr =
1948 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1949
1950 /* Supply Target-side CE configuration */
Michal Kazior9e264942014-09-02 11:00:21 +03001951 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
1952 &pcie_state_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001954 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955 return ret;
1956 }
1957
1958 if (pcie_state_targ_addr == 0) {
1959 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001960 ath10k_err(ar, "Invalid pcie state addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001961 return ret;
1962 }
1963
Michal Kazior9e264942014-09-02 11:00:21 +03001964 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03001966 pipe_cfg_addr)),
1967 &pipe_cfg_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001969 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001970 return ret;
1971 }
1972
1973 if (pipe_cfg_targ_addr == 0) {
1974 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001975 ath10k_err(ar, "Invalid pipe cfg addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 return ret;
1977 }
1978
1979 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001980 target_ce_config_wlan,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05301981 sizeof(struct ce_pipe_config) *
1982 NUM_TARGET_CE_CONFIG_WLAN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001983
1984 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001985 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001986 return ret;
1987 }
1988
Michal Kazior9e264942014-09-02 11:00:21 +03001989 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03001991 svc_to_pipe_map)),
1992 &svc_to_pipe_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001993 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001994 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 return ret;
1996 }
1997
1998 if (svc_to_pipe_map == 0) {
1999 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002000 ath10k_err(ar, "Invalid svc_to_pipe map\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 return ret;
2002 }
2003
2004 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
Kalle Valo5b07e072014-09-14 12:50:06 +03002005 target_service_to_ce_map_wlan,
2006 sizeof(target_service_to_ce_map_wlan));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002007 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002008 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002009 return ret;
2010 }
2011
Michal Kazior9e264942014-09-02 11:00:21 +03002012 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002014 config_flags)),
2015 &pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002016 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002017 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002018 return ret;
2019 }
2020
2021 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
2022
Michal Kazior9e264942014-09-02 11:00:21 +03002023 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
2024 offsetof(struct pcie_state,
2025 config_flags)),
2026 pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002028 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002029 return ret;
2030 }
2031
2032 /* configure early allocation */
2033 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
2034
Michal Kazior9e264942014-09-02 11:00:21 +03002035 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002037 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038 return ret;
2039 }
2040
2041 /* first bank is switched to IRAM */
2042 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
2043 HI_EARLY_ALLOC_MAGIC_MASK);
Raja Mani4ddb3292016-01-27 15:24:23 +05302044 ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
Michal Kaziord63955b2015-01-24 12:14:49 +02002045 HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
Kalle Valo5e3dd152013-06-12 20:52:10 +03002046 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
2047
Michal Kazior9e264942014-09-02 11:00:21 +03002048 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002049 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002050 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051 return ret;
2052 }
2053
2054 /* Tell Target to proceed with initialization */
2055 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
2056
Michal Kazior9e264942014-09-02 11:00:21 +03002057 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002058 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002059 ath10k_err(ar, "Failed to get option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002060 return ret;
2061 }
2062
2063 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
2064
Michal Kazior9e264942014-09-02 11:00:21 +03002065 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002066 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002067 ath10k_err(ar, "Failed to set option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 return ret;
2069 }
2070
2071 return 0;
2072}
2073
Ryan Hsu2727a742015-11-05 18:44:27 -08002074static void ath10k_pci_override_ce_config(struct ath10k *ar)
2075{
2076 struct ce_attr *attr;
2077 struct ce_pipe_config *config;
2078
2079 /* For QCA6174 we're overriding the Copy Engine 5 configuration,
2080 * since it is currently used for other feature.
2081 */
2082
2083 /* Override Host's Copy Engine 5 configuration */
2084 attr = &host_ce_config_wlan[5];
2085 attr->src_sz_max = 0;
2086 attr->dest_nentries = 0;
2087
2088 /* Override Target firmware's Copy Engine configuration */
2089 config = &target_ce_config_wlan[5];
2090 config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
2091 config->nbytes_max = __cpu_to_le32(2048);
2092
2093 /* Map from service/endpoint to Copy Engine */
2094 target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
2095}
2096
Raja Manif52f5172016-01-27 15:24:22 +05302097int ath10k_pci_alloc_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002098{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002099 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2100 struct ath10k_pci_pipe *pipe;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002101 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002102
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002103 for (i = 0; i < CE_COUNT; i++) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002104 pipe = &ar_pci->pipe_info[i];
2105 pipe->ce_hdl = &ar_pci->ce_states[i];
2106 pipe->pipe_num = i;
2107 pipe->hif_ce_state = ar;
2108
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +05302109 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002110 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002111 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002112 i, ret);
2113 return ret;
2114 }
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002115
2116 /* Last CE is Diagnostic Window */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302117 if (i == CE_DIAG_PIPE) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002118 ar_pci->ce_diag = pipe->ce_hdl;
2119 continue;
2120 }
2121
2122 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002123 }
2124
2125 return 0;
2126}
2127
Raja Manif52f5172016-01-27 15:24:22 +05302128void ath10k_pci_free_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002129{
2130 int i;
2131
2132 for (i = 0; i < CE_COUNT; i++)
2133 ath10k_ce_free_pipe(ar, i);
2134}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135
Raja Manif52f5172016-01-27 15:24:22 +05302136int ath10k_pci_init_pipes(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002138 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002139
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002140 for (i = 0; i < CE_COUNT; i++) {
2141 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002142 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002143 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002144 i, ret);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002145 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002147 }
2148
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149 return 0;
2150}
2151
Michal Kazior5c771e72014-08-22 14:23:34 +02002152static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153{
Michal Kazior5c771e72014-08-22 14:23:34 +02002154 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
2155 FW_IND_EVENT_PENDING;
2156}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157
Michal Kazior5c771e72014-08-22 14:23:34 +02002158static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
2159{
2160 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002161
Michal Kazior5c771e72014-08-22 14:23:34 +02002162 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2163 val &= ~FW_IND_EVENT_PENDING;
2164 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002165}
2166
Michal Kaziorde013572014-05-14 16:56:16 +03002167/* this function effectively clears target memory controller assert line */
2168static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
2169{
2170 u32 val;
2171
2172 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2173 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2174 val | SOC_RESET_CONTROL_SI0_RST_MASK);
2175 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2176
2177 msleep(10);
2178
2179 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2180 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2181 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
2182 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2183
2184 msleep(10);
2185}
2186
Michal Kazior61c16482014-10-28 10:32:06 +01002187static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002188{
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002189 u32 val;
2190
Kalle Valob39712c2014-03-28 09:32:46 +02002191 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002192
Michal Kazior61c16482014-10-28 10:32:06 +01002193 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2194 SOC_RESET_CONTROL_ADDRESS);
2195 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2196 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
2197}
2198
2199static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
2200{
2201 u32 val;
2202
2203 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2204 SOC_RESET_CONTROL_ADDRESS);
2205
2206 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2207 val | SOC_RESET_CONTROL_CE_RST_MASK);
2208 msleep(10);
2209 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2210 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
2211}
2212
2213static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
2214{
2215 u32 val;
2216
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002217 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2218 SOC_LF_TIMER_CONTROL0_ADDRESS);
2219 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
2220 SOC_LF_TIMER_CONTROL0_ADDRESS,
2221 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
Michal Kazior61c16482014-10-28 10:32:06 +01002222}
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002223
Michal Kazior61c16482014-10-28 10:32:06 +01002224static int ath10k_pci_warm_reset(struct ath10k *ar)
2225{
2226 int ret;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002227
Michal Kazior61c16482014-10-28 10:32:06 +01002228 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002229
Michal Kazior61c16482014-10-28 10:32:06 +01002230 spin_lock_bh(&ar->data_lock);
2231 ar->stats.fw_warm_reset_counter++;
2232 spin_unlock_bh(&ar->data_lock);
2233
2234 ath10k_pci_irq_disable(ar);
2235
2236 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
2237 * were to access copy engine while host performs copy engine reset
2238 * then it is possible for the device to confuse pci-e controller to
2239 * the point of bringing host system to a complete stop (i.e. hang).
2240 */
Michal Kaziorde013572014-05-14 16:56:16 +03002241 ath10k_pci_warm_reset_si0(ar);
Michal Kazior61c16482014-10-28 10:32:06 +01002242 ath10k_pci_warm_reset_cpu(ar);
2243 ath10k_pci_init_pipes(ar);
2244 ath10k_pci_wait_for_target_init(ar);
Michal Kaziorde013572014-05-14 16:56:16 +03002245
Michal Kazior61c16482014-10-28 10:32:06 +01002246 ath10k_pci_warm_reset_clear_lf(ar);
2247 ath10k_pci_warm_reset_ce(ar);
2248 ath10k_pci_warm_reset_cpu(ar);
2249 ath10k_pci_init_pipes(ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002250
Michal Kazior61c16482014-10-28 10:32:06 +01002251 ret = ath10k_pci_wait_for_target_init(ar);
2252 if (ret) {
2253 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
2254 return ret;
2255 }
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002256
Michal Kazior7aa7a722014-08-25 12:09:38 +02002257 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002258
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002259 return 0;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002260}
2261
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302262static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
2263{
2264 if (QCA_REV_988X(ar) || QCA_REV_6174(ar)) {
2265 return ath10k_pci_warm_reset(ar);
2266 } else if (QCA_REV_99X0(ar)) {
2267 ath10k_pci_irq_disable(ar);
2268 return ath10k_pci_qca99x0_chip_reset(ar);
2269 } else {
2270 return -ENOTSUPP;
2271 }
2272}
2273
Michal Kaziord63955b2015-01-24 12:14:49 +02002274static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
Michal Kazior0bc14d02014-10-28 10:32:07 +01002275{
2276 int i, ret;
2277 u32 val;
2278
Michal Kaziord63955b2015-01-24 12:14:49 +02002279 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002280
2281 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
2282 * It is thus preferred to use warm reset which is safer but may not be
2283 * able to recover the device from all possible fail scenarios.
2284 *
2285 * Warm reset doesn't always work on first try so attempt it a few
2286 * times before giving up.
2287 */
2288 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2289 ret = ath10k_pci_warm_reset(ar);
2290 if (ret) {
2291 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
2292 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
2293 ret);
2294 continue;
2295 }
2296
2297 /* FIXME: Sometimes copy engine doesn't recover after warm
2298 * reset. In most cases this needs cold reset. In some of these
2299 * cases the device is in such a state that a cold reset may
2300 * lock up the host.
2301 *
2302 * Reading any host interest register via copy engine is
2303 * sufficient to verify if device is capable of booting
2304 * firmware blob.
2305 */
2306 ret = ath10k_pci_init_pipes(ar);
2307 if (ret) {
2308 ath10k_warn(ar, "failed to init copy engine: %d\n",
2309 ret);
2310 continue;
2311 }
2312
2313 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
2314 &val);
2315 if (ret) {
2316 ath10k_warn(ar, "failed to poke copy engine: %d\n",
2317 ret);
2318 continue;
2319 }
2320
2321 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
2322 return 0;
2323 }
2324
2325 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
2326 ath10k_warn(ar, "refusing cold reset as requested\n");
2327 return -EPERM;
2328 }
2329
2330 ret = ath10k_pci_cold_reset(ar);
2331 if (ret) {
2332 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2333 return ret;
2334 }
2335
2336 ret = ath10k_pci_wait_for_target_init(ar);
2337 if (ret) {
2338 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2339 ret);
2340 return ret;
2341 }
2342
Michal Kaziord63955b2015-01-24 12:14:49 +02002343 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002344
2345 return 0;
2346}
2347
Michal Kaziord63955b2015-01-24 12:14:49 +02002348static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
2349{
2350 int ret;
2351
2352 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
2353
2354 /* FIXME: QCA6174 requires cold + warm reset to work. */
2355
2356 ret = ath10k_pci_cold_reset(ar);
2357 if (ret) {
2358 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2359 return ret;
2360 }
2361
2362 ret = ath10k_pci_wait_for_target_init(ar);
2363 if (ret) {
2364 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
Kalle Valo617b0f42015-10-05 17:56:35 +03002365 ret);
Michal Kaziord63955b2015-01-24 12:14:49 +02002366 return ret;
2367 }
2368
2369 ret = ath10k_pci_warm_reset(ar);
2370 if (ret) {
2371 ath10k_warn(ar, "failed to warm reset: %d\n", ret);
2372 return ret;
2373 }
2374
2375 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
2376
2377 return 0;
2378}
2379
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302380static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
2381{
2382 int ret;
2383
2384 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
2385
2386 ret = ath10k_pci_cold_reset(ar);
2387 if (ret) {
2388 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2389 return ret;
2390 }
2391
2392 ret = ath10k_pci_wait_for_target_init(ar);
2393 if (ret) {
2394 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2395 ret);
2396 return ret;
2397 }
2398
2399 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
2400
2401 return 0;
2402}
2403
Michal Kaziord63955b2015-01-24 12:14:49 +02002404static int ath10k_pci_chip_reset(struct ath10k *ar)
2405{
2406 if (QCA_REV_988X(ar))
2407 return ath10k_pci_qca988x_chip_reset(ar);
2408 else if (QCA_REV_6174(ar))
2409 return ath10k_pci_qca6174_chip_reset(ar);
Bartosz Markowskia226b512015-10-28 15:09:53 +01002410 else if (QCA_REV_9377(ar))
2411 return ath10k_pci_qca6174_chip_reset(ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302412 else if (QCA_REV_99X0(ar))
2413 return ath10k_pci_qca99x0_chip_reset(ar);
Michal Kaziord63955b2015-01-24 12:14:49 +02002414 else
2415 return -ENOTSUPP;
2416}
2417
Michal Kazior0bc14d02014-10-28 10:32:07 +01002418static int ath10k_pci_hif_power_up(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002419{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002420 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002421 int ret;
2422
Michal Kazior0bc14d02014-10-28 10:32:07 +01002423 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
2424
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002425 pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2426 &ar_pci->link_ctl);
2427 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2428 ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
2429
Michal Kazior8c5c5362013-07-16 09:38:50 +02002430 /*
2431 * Bring the target up cleanly.
2432 *
2433 * The target may be in an undefined state with an AUX-powered Target
2434 * and a Host in WoW mode. If the Host crashes, loses power, or is
2435 * restarted (without unloading the driver) then the Target is left
2436 * (aux) powered and running. On a subsequent driver load, the Target
2437 * is in an unexpected state. We try to catch that here in order to
2438 * reset the Target and retry the probe.
2439 */
Michal Kazior0bc14d02014-10-28 10:32:07 +01002440 ret = ath10k_pci_chip_reset(ar);
Michal Kazior5b2589f2013-11-08 08:01:30 +01002441 if (ret) {
Michal Kaziora2fa8802015-01-12 15:29:37 +01002442 if (ath10k_pci_has_fw_crashed(ar)) {
2443 ath10k_warn(ar, "firmware crashed during chip reset\n");
2444 ath10k_pci_fw_crashed_clear(ar);
2445 ath10k_pci_fw_crashed_dump(ar);
2446 }
2447
Michal Kazior0bc14d02014-10-28 10:32:07 +01002448 ath10k_err(ar, "failed to reset chip: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002449 goto err_sleep;
Michal Kazior5b2589f2013-11-08 08:01:30 +01002450 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002451
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002452 ret = ath10k_pci_init_pipes(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002453 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002454 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002455 goto err_sleep;
Michal Kaziorab977bd2013-11-25 14:06:26 +01002456 }
2457
Michal Kazior98563d52013-11-08 08:01:33 +01002458 ret = ath10k_pci_init_config(ar);
2459 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002460 ath10k_err(ar, "failed to setup init config: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002461 goto err_ce;
Michal Kazior98563d52013-11-08 08:01:33 +01002462 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002463
2464 ret = ath10k_pci_wake_target_cpu(ar);
2465 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002466 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002467 goto err_ce;
Michal Kazior8c5c5362013-07-16 09:38:50 +02002468 }
2469
2470 return 0;
2471
2472err_ce:
2473 ath10k_pci_ce_deinit(ar);
Michal Kazior0bc14d02014-10-28 10:32:07 +01002474
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002475err_sleep:
Michal Kazior8c5c5362013-07-16 09:38:50 +02002476 return ret;
2477}
2478
Raja Manif52f5172016-01-27 15:24:22 +05302479void ath10k_pci_hif_power_down(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002480{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002481 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
Bartosz Markowski8cc8df92013-08-02 09:58:49 +02002482
Michal Kaziorc011b282014-10-28 10:32:08 +01002483 /* Currently hif_power_up performs effectively a reset and hif_stop
2484 * resets the chip as well so there's no point in resetting here.
2485 */
Michal Kazior8c5c5362013-07-16 09:38:50 +02002486}
2487
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002488#ifdef CONFIG_PM
2489
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002490static int ath10k_pci_hif_suspend(struct ath10k *ar)
2491{
Michal Kazior77258d42015-05-18 09:38:18 +00002492 /* The grace timer can still be counting down and ar->ps_awake be true.
2493 * It is known that the device may be asleep after resuming regardless
2494 * of the SoC powersave state before suspending. Hence make sure the
2495 * device is asleep before proceeding.
2496 */
2497 ath10k_pci_sleep_sync(ar);
Michal Kazior320e14b2015-03-02 13:22:13 +01002498
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002499 return 0;
2500}
2501
2502static int ath10k_pci_hif_resume(struct ath10k *ar)
2503{
2504 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2505 struct pci_dev *pdev = ar_pci->pdev;
2506 u32 val;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002507 int ret = 0;
2508
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002509 ret = ath10k_pci_force_wake(ar);
2510 if (ret) {
2511 ath10k_err(ar, "failed to wake up target: %d\n", ret);
2512 return ret;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002513 }
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002514
Michal Kazior9ff4be92015-03-02 13:22:14 +01002515 /* Suspend/Resume resets the PCI configuration space, so we have to
2516 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
2517 * from interfering with C3 CPU state. pci_restore_state won't help
2518 * here since it only restores the first 64 bytes pci config header.
2519 */
2520 pci_read_config_dword(pdev, 0x40, &val);
2521 if ((val & 0x0000ff00) != 0)
2522 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002523
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002524 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002525}
2526#endif
2527
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
Michal Kazior726346f2014-02-27 18:50:04 +02002529 .tx_sg = ath10k_pci_hif_tx_sg,
Kalle Valoeef25402014-09-24 14:16:52 +03002530 .diag_read = ath10k_pci_hif_diag_read,
Yanbo Li9f65ad22014-11-25 12:24:48 +02002531 .diag_write = ath10k_pci_diag_write_mem,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002532 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2533 .start = ath10k_pci_hif_start,
2534 .stop = ath10k_pci_hif_stop,
2535 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2536 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2537 .send_complete_check = ath10k_pci_hif_send_complete_check,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002538 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
Michal Kazior8c5c5362013-07-16 09:38:50 +02002539 .power_up = ath10k_pci_hif_power_up,
2540 .power_down = ath10k_pci_hif_power_down,
Yanbo Li077a3802014-11-25 12:24:33 +02002541 .read32 = ath10k_pci_read32,
2542 .write32 = ath10k_pci_write32,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002543#ifdef CONFIG_PM
2544 .suspend = ath10k_pci_hif_suspend,
2545 .resume = ath10k_pci_hif_resume,
2546#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03002547};
2548
2549static void ath10k_pci_ce_tasklet(unsigned long ptr)
2550{
Michal Kazior87263e52013-08-27 13:08:01 +02002551 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 struct ath10k_pci *ar_pci = pipe->ar_pci;
2553
2554 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
2555}
2556
2557static void ath10k_msi_err_tasklet(unsigned long data)
2558{
2559 struct ath10k *ar = (struct ath10k *)data;
2560
Michal Kazior5c771e72014-08-22 14:23:34 +02002561 if (!ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002562 ath10k_warn(ar, "received unsolicited fw crash interrupt\n");
Michal Kazior5c771e72014-08-22 14:23:34 +02002563 return;
2564 }
2565
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002566 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002567 ath10k_pci_fw_crashed_clear(ar);
2568 ath10k_pci_fw_crashed_dump(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002569}
2570
2571/*
2572 * Handler for a per-engine interrupt on a PARTICULAR CE.
2573 * This is used in cases where each CE has a private MSI interrupt.
2574 */
2575static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
2576{
2577 struct ath10k *ar = arg;
2578 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2579 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
2580
Dan Carpentere5742672013-06-18 10:28:46 +03002581 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002582 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
2583 ce_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 return IRQ_HANDLED;
2585 }
2586
2587 /*
2588 * NOTE: We are able to derive ce_id from irq because we
2589 * use a one-to-one mapping for CE's 0..5.
2590 * CE's 6 & 7 do not use interrupts at all.
2591 *
2592 * This mapping must be kept in sync with the mapping
2593 * used by firmware.
2594 */
2595 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
2596 return IRQ_HANDLED;
2597}
2598
2599static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
2600{
2601 struct ath10k *ar = arg;
2602 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2603
2604 tasklet_schedule(&ar_pci->msi_fw_err);
2605 return IRQ_HANDLED;
2606}
2607
2608/*
2609 * Top-level interrupt handler for all PCI interrupts from a Target.
2610 * When a block of MSI interrupts is allocated, this top-level handler
2611 * is not used; instead, we directly call the correct sub-handler.
2612 */
2613static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2614{
2615 struct ath10k *ar = arg;
2616 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002617 int ret;
2618
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002619 ret = ath10k_pci_force_wake(ar);
2620 if (ret) {
2621 ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
2622 return IRQ_NONE;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002623 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624
2625 if (ar_pci->num_msi_intrs == 0) {
Michal Kaziore5398872013-11-25 14:06:20 +01002626 if (!ath10k_pci_irq_pending(ar))
2627 return IRQ_NONE;
2628
Michal Kazior26852182013-11-25 14:06:25 +01002629 ath10k_pci_disable_and_clear_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002630 }
2631
2632 tasklet_schedule(&ar_pci->intr_tq);
2633
2634 return IRQ_HANDLED;
2635}
2636
2637static void ath10k_pci_tasklet(unsigned long data)
2638{
2639 struct ath10k *ar = (struct ath10k *)data;
2640 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2641
Michal Kazior5c771e72014-08-22 14:23:34 +02002642 if (ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002643 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002644 ath10k_pci_fw_crashed_clear(ar);
2645 ath10k_pci_fw_crashed_dump(ar);
2646 return;
2647 }
2648
Kalle Valo5e3dd152013-06-12 20:52:10 +03002649 ath10k_ce_per_engine_service_any(ar);
2650
Michal Kazior26852182013-11-25 14:06:25 +01002651 /* Re-enable legacy irq that was disabled in the irq handler */
2652 if (ar_pci->num_msi_intrs == 0)
2653 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002654}
2655
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002656static int ath10k_pci_request_irq_msix(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657{
2658 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002659 int ret, i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660
2661 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2662 ath10k_pci_msi_fw_handler,
2663 IRQF_SHARED, "ath10k_pci", ar);
Michal Kazior591ecdb2013-07-31 10:55:15 +02002664 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002665 ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n",
Michal Kazior591ecdb2013-07-31 10:55:15 +02002666 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002667 return ret;
Michal Kazior591ecdb2013-07-31 10:55:15 +02002668 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669
2670 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2671 ret = request_irq(ar_pci->pdev->irq + i,
2672 ath10k_pci_per_engine_handler,
2673 IRQF_SHARED, "ath10k_pci", ar);
2674 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002675 ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002676 ar_pci->pdev->irq + i, ret);
2677
Michal Kazior87b14232013-06-26 08:50:50 +02002678 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2679 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002680
Michal Kazior87b14232013-06-26 08:50:50 +02002681 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 return ret;
2683 }
2684 }
2685
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686 return 0;
2687}
2688
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002689static int ath10k_pci_request_irq_msi(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690{
2691 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2692 int ret;
2693
2694 ret = request_irq(ar_pci->pdev->irq,
2695 ath10k_pci_interrupt_handler,
2696 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002697 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002698 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002699 ar_pci->pdev->irq, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700 return ret;
Kalle Valof3782742013-10-17 11:36:15 +03002701 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002702
Kalle Valo5e3dd152013-06-12 20:52:10 +03002703 return 0;
2704}
2705
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002706static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002707{
2708 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002709 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002710
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002711 ret = request_irq(ar_pci->pdev->irq,
2712 ath10k_pci_interrupt_handler,
2713 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002714 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002715 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002716 ar_pci->pdev->irq, ret);
Kalle Valof3782742013-10-17 11:36:15 +03002717 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002718 }
2719
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002720 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002721}
2722
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002723static int ath10k_pci_request_irq(struct ath10k *ar)
2724{
2725 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2726
2727 switch (ar_pci->num_msi_intrs) {
2728 case 0:
2729 return ath10k_pci_request_irq_legacy(ar);
2730 case 1:
2731 return ath10k_pci_request_irq_msi(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002732 default:
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002733 return ath10k_pci_request_irq_msix(ar);
2734 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002735}
2736
2737static void ath10k_pci_free_irq(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002738{
2739 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2740 int i;
2741
2742 /* There's at least one interrupt irregardless whether its legacy INTR
2743 * or MSI or MSI-X */
2744 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2745 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002746}
2747
Raja Manif52f5172016-01-27 15:24:22 +05302748void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002749{
2750 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2751 int i;
2752
2753 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2754 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2755 (unsigned long)ar);
2756
2757 for (i = 0; i < CE_COUNT; i++) {
2758 ar_pci->pipe_info[i].ar_pci = ar_pci;
2759 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2760 (unsigned long)&ar_pci->pipe_info[i]);
2761 }
2762}
2763
2764static int ath10k_pci_init_irq(struct ath10k *ar)
2765{
2766 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2767 int ret;
2768
2769 ath10k_pci_init_irq_tasklets(ar);
2770
Michal Kazior403d6272014-08-22 14:23:31 +02002771 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002772 ath10k_info(ar, "limiting irq mode to: %d\n",
2773 ath10k_pci_irq_mode);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002774
2775 /* Try MSI-X */
Michal Kazior0edf2572014-08-07 11:03:29 +02002776 if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) {
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002777 ar_pci->num_msi_intrs = MSI_ASSIGN_CE_MAX + 1;
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002778 ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs,
Kalle Valo5b07e072014-09-14 12:50:06 +03002779 ar_pci->num_msi_intrs);
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002780 if (ret > 0)
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002781 return 0;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002782
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002783 /* fall-through */
2784 }
2785
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002786 /* Try MSI */
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002787 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
2788 ar_pci->num_msi_intrs = 1;
2789 ret = pci_enable_msi(ar_pci->pdev);
2790 if (ret == 0)
2791 return 0;
2792
2793 /* fall-through */
2794 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002795
2796 /* Try legacy irq
2797 *
2798 * A potential race occurs here: The CORE_BASE write
2799 * depends on target correctly decoding AXI address but
2800 * host won't know when target writes BAR to CORE_CTRL.
2801 * This write might get lost if target has NOT written BAR.
2802 * For now, fix the race by repeating the write in below
2803 * synchronization checking. */
2804 ar_pci->num_msi_intrs = 0;
2805
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002806 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2807 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002808
2809 return 0;
2810}
2811
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002812static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002813{
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002814 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2815 0);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002816}
2817
2818static int ath10k_pci_deinit_irq(struct ath10k *ar)
2819{
2820 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2821
2822 switch (ar_pci->num_msi_intrs) {
2823 case 0:
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002824 ath10k_pci_deinit_irq_legacy(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002825 break;
Alexander Gordeevbb8b6212014-02-13 17:50:01 +02002826 default:
2827 pci_disable_msi(ar_pci->pdev);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002828 break;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002829 }
2830
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002831 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002832}
2833
Raja Manif52f5172016-01-27 15:24:22 +05302834int ath10k_pci_wait_for_target_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835{
2836 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo0399eca2014-03-28 09:32:21 +02002837 unsigned long timeout;
Kalle Valo0399eca2014-03-28 09:32:21 +02002838 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002839
Michal Kazior7aa7a722014-08-25 12:09:38 +02002840 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002841
Kalle Valo0399eca2014-03-28 09:32:21 +02002842 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2843
2844 do {
2845 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2846
Michal Kazior7aa7a722014-08-25 12:09:38 +02002847 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2848 val);
Kalle Valo50f87a62014-03-28 09:32:52 +02002849
Kalle Valo0399eca2014-03-28 09:32:21 +02002850 /* target should never return this */
2851 if (val == 0xffffffff)
2852 continue;
2853
Michal Kazior7710cd22014-04-23 19:30:04 +03002854 /* the device has crashed so don't bother trying anymore */
2855 if (val & FW_IND_EVENT_PENDING)
2856 break;
2857
Kalle Valo0399eca2014-03-28 09:32:21 +02002858 if (val & FW_IND_INITIALIZED)
2859 break;
2860
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861 if (ar_pci->num_msi_intrs == 0)
2862 /* Fix potential race by repeating CORE_BASE writes */
Michal Kaziora4282492014-10-20 14:14:37 +02002863 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002864
Kalle Valo0399eca2014-03-28 09:32:21 +02002865 mdelay(10);
2866 } while (time_before(jiffies, timeout));
2867
Michal Kaziora4282492014-10-20 14:14:37 +02002868 ath10k_pci_disable_and_clear_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02002869 ath10k_pci_irq_msi_fw_mask(ar);
Michal Kaziora4282492014-10-20 14:14:37 +02002870
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002871 if (val == 0xffffffff) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002872 ath10k_err(ar, "failed to read device register, device is gone\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002873 return -EIO;
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002874 }
2875
Michal Kazior7710cd22014-04-23 19:30:04 +03002876 if (val & FW_IND_EVENT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002877 ath10k_warn(ar, "device has crashed during init\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002878 return -ECOMM;
Michal Kazior7710cd22014-04-23 19:30:04 +03002879 }
2880
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002881 if (!(val & FW_IND_INITIALIZED)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002882 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
Kalle Valo0399eca2014-03-28 09:32:21 +02002883 val);
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002884 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002885 }
2886
Michal Kazior7aa7a722014-08-25 12:09:38 +02002887 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002888 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889}
2890
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002891static int ath10k_pci_cold_reset(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002892{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 u32 val;
2894
Michal Kazior7aa7a722014-08-25 12:09:38 +02002895 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002896
Ben Greearf51dbe72014-09-29 14:41:46 +03002897 spin_lock_bh(&ar->data_lock);
2898
2899 ar->stats.fw_cold_reset_counter++;
2900
2901 spin_unlock_bh(&ar->data_lock);
2902
Kalle Valo5e3dd152013-06-12 20:52:10 +03002903 /* Put Target, including PCIe, into RESET. */
Kalle Valoe479ed42013-09-01 10:01:53 +03002904 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905 val |= 1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002906 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302908 /* After writing into SOC_GLOBAL_RESET to put device into
2909 * reset and pulling out of reset pcie may not be stable
2910 * for any immediate pcie register access and cause bus error,
2911 * add delay before any pcie access request to fix this issue.
2912 */
2913 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002914
2915 /* Pull Target, including PCIe, out of RESET. */
2916 val &= ~1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002917 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302919 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002920
Michal Kazior7aa7a722014-08-25 12:09:38 +02002921 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02002922
Michal Kazior5b2589f2013-11-08 08:01:30 +01002923 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002924}
2925
Michal Kazior2986e3e2014-08-07 11:03:30 +02002926static int ath10k_pci_claim(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002927{
Michal Kazior2986e3e2014-08-07 11:03:30 +02002928 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2929 struct pci_dev *pdev = ar_pci->pdev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002930 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002931
2932 pci_set_drvdata(pdev, ar);
2933
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934 ret = pci_enable_device(pdev);
2935 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002936 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002937 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002938 }
2939
Kalle Valo5e3dd152013-06-12 20:52:10 +03002940 ret = pci_request_region(pdev, BAR_NUM, "ath");
2941 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002942 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
Michal Kazior2986e3e2014-08-07 11:03:30 +02002943 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002944 goto err_device;
2945 }
2946
Michal Kazior2986e3e2014-08-07 11:03:30 +02002947 /* Target expects 32 bit DMA. Enforce it. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002948 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2949 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002950 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002951 goto err_region;
2952 }
2953
2954 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2955 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002956 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
Michal Kazior2986e3e2014-08-07 11:03:30 +02002957 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002958 goto err_region;
2959 }
2960
Kalle Valo5e3dd152013-06-12 20:52:10 +03002961 pci_set_master(pdev);
2962
Kalle Valo5e3dd152013-06-12 20:52:10 +03002963 /* Arrange for access to Target SoC registers. */
Michal Kazioraeae5b42015-06-15 14:46:42 +03002964 ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002965 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
2966 if (!ar_pci->mem) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002967 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968 ret = -EIO;
2969 goto err_master;
2970 }
2971
Michal Kazior7aa7a722014-08-25 12:09:38 +02002972 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002973 return 0;
2974
2975err_master:
2976 pci_clear_master(pdev);
2977
2978err_region:
2979 pci_release_region(pdev, BAR_NUM);
2980
2981err_device:
2982 pci_disable_device(pdev);
2983
2984 return ret;
2985}
2986
2987static void ath10k_pci_release(struct ath10k *ar)
2988{
2989 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2990 struct pci_dev *pdev = ar_pci->pdev;
2991
2992 pci_iounmap(pdev, ar_pci->mem);
2993 pci_release_region(pdev, BAR_NUM);
2994 pci_clear_master(pdev);
2995 pci_disable_device(pdev);
2996}
2997
Michal Kazior7505f7c2014-12-02 10:55:54 +02002998static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
2999{
3000 const struct ath10k_pci_supp_chip *supp_chip;
3001 int i;
3002 u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
3003
3004 for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
3005 supp_chip = &ath10k_pci_supp_chips[i];
3006
3007 if (supp_chip->dev_id == dev_id &&
3008 supp_chip->rev_id == rev_id)
3009 return true;
3010 }
3011
3012 return false;
3013}
3014
Raja Mani90188f82016-01-27 15:24:24 +05303015int ath10k_pci_setup_resource(struct ath10k *ar)
3016{
3017 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
3018 int ret;
3019
3020 spin_lock_init(&ar_pci->ce_lock);
3021 spin_lock_init(&ar_pci->ps_lock);
3022
3023 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
3024 (unsigned long)ar);
3025
3026 if (QCA_REV_6174(ar))
3027 ath10k_pci_override_ce_config(ar);
3028
3029 ret = ath10k_pci_alloc_pipes(ar);
3030 if (ret) {
3031 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
3032 ret);
3033 return ret;
3034 }
3035
3036 return 0;
3037}
3038
3039void ath10k_pci_release_resource(struct ath10k *ar)
3040{
3041 ath10k_pci_kill_tasklet(ar);
3042 ath10k_pci_ce_deinit(ar);
3043 ath10k_pci_free_pipes(ar);
3044}
3045
Raja Mani4ddb3292016-01-27 15:24:23 +05303046static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
3047 .read32 = ath10k_bus_pci_read32,
3048 .write32 = ath10k_bus_pci_write32,
3049 .get_num_banks = ath10k_pci_get_num_banks,
3050};
3051
Kalle Valo5e3dd152013-06-12 20:52:10 +03003052static int ath10k_pci_probe(struct pci_dev *pdev,
3053 const struct pci_device_id *pci_dev)
3054{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003055 int ret = 0;
3056 struct ath10k *ar;
3057 struct ath10k_pci *ar_pci;
Michal Kaziord63955b2015-01-24 12:14:49 +02003058 enum ath10k_hw_rev hw_rev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02003059 u32 chip_id;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003060 bool pci_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003061
Michal Kaziord63955b2015-01-24 12:14:49 +02003062 switch (pci_dev->device) {
3063 case QCA988X_2_0_DEVICE_ID:
3064 hw_rev = ATH10K_HW_QCA988X;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003065 pci_ps = false;
Michal Kaziord63955b2015-01-24 12:14:49 +02003066 break;
Michal Kazior36582e52015-08-13 14:32:26 +02003067 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02003068 case QCA6174_2_1_DEVICE_ID:
3069 hw_rev = ATH10K_HW_QCA6174;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003070 pci_ps = true;
Michal Kaziord63955b2015-01-24 12:14:49 +02003071 break;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303072 case QCA99X0_2_0_DEVICE_ID:
3073 hw_rev = ATH10K_HW_QCA99X0;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003074 pci_ps = false;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303075 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01003076 case QCA9377_1_0_DEVICE_ID:
3077 hw_rev = ATH10K_HW_QCA9377;
3078 pci_ps = true;
3079 break;
Michal Kaziord63955b2015-01-24 12:14:49 +02003080 default:
3081 WARN_ON(1);
3082 return -ENOTSUPP;
3083 }
3084
3085 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
3086 hw_rev, &ath10k_pci_hif_ops);
Michal Kaziore7b54192014-08-07 11:03:27 +02003087 if (!ar) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003088 dev_err(&pdev->dev, "failed to allocate core\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089 return -ENOMEM;
Michal Kaziore7b54192014-08-07 11:03:27 +02003090 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003091
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003092 ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
3093 pdev->vendor, pdev->device,
3094 pdev->subsystem_vendor, pdev->subsystem_device);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003095
Michal Kaziore7b54192014-08-07 11:03:27 +02003096 ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003097 ar_pci->pdev = pdev;
3098 ar_pci->dev = &pdev->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 ar_pci->ar = ar;
Michal Kazior36582e52015-08-13 14:32:26 +02003100 ar->dev_id = pci_dev->device;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003101 ar_pci->pci_ps = pci_ps;
Raja Mani4ddb3292016-01-27 15:24:23 +05303102 ar_pci->bus_ops = &ath10k_pci_bus_ops;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003103
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003104 ar->id.vendor = pdev->vendor;
3105 ar->id.device = pdev->device;
3106 ar->id.subsystem_vendor = pdev->subsystem_vendor;
3107 ar->id.subsystem_device = pdev->subsystem_device;
Michal Kaziorde57e2c2015-04-17 09:19:17 +00003108
Michal Kazior77258d42015-05-18 09:38:18 +00003109 setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
3110 (unsigned long)ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003111
Raja Mani90188f82016-01-27 15:24:24 +05303112 ret = ath10k_pci_setup_resource(ar);
3113 if (ret) {
3114 ath10k_err(ar, "failed to setup resource: %d\n", ret);
3115 goto err_core_destroy;
3116 }
3117
Michal Kazior2986e3e2014-08-07 11:03:30 +02003118 ret = ath10k_pci_claim(ar);
Kalle Valoe01ae682013-09-01 11:22:14 +03003119 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003120 ath10k_err(ar, "failed to claim device: %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303121 goto err_free_pipes;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02003122 }
3123
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02003124 ret = ath10k_pci_force_wake(ar);
3125 if (ret) {
3126 ath10k_warn(ar, "failed to wake up device : %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303127 goto err_sleep;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003128 }
3129
Rajkumar Manoharanaa538ac2015-12-16 16:52:19 +02003130 ath10k_pci_ce_deinit(ar);
3131 ath10k_pci_irq_disable(ar);
3132
Michal Kazior403d6272014-08-22 14:23:31 +02003133 ret = ath10k_pci_init_irq(ar);
3134 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003135 ath10k_err(ar, "failed to init irqs: %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303136 goto err_sleep;
Michal Kazior403d6272014-08-22 14:23:31 +02003137 }
3138
Michal Kazior7aa7a722014-08-25 12:09:38 +02003139 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
Michal Kazior403d6272014-08-22 14:23:31 +02003140 ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs,
3141 ath10k_pci_irq_mode, ath10k_pci_reset_mode);
3142
Michal Kazior5c771e72014-08-22 14:23:34 +02003143 ret = ath10k_pci_request_irq(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003144 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003145 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
Michal Kazior403d6272014-08-22 14:23:31 +02003146 goto err_deinit_irq;
3147 }
3148
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003149 ret = ath10k_pci_chip_reset(ar);
3150 if (ret) {
3151 ath10k_err(ar, "failed to reset chip: %d\n", ret);
3152 goto err_free_irq;
3153 }
3154
3155 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
3156 if (chip_id == 0xffffffff) {
3157 ath10k_err(ar, "failed to get chip id\n");
3158 goto err_free_irq;
3159 }
3160
3161 if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
3162 ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
3163 pdev->device, chip_id);
Michal Kaziord9585a92015-04-10 13:01:27 +00003164 goto err_free_irq;
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003165 }
3166
Kalle Valoe01ae682013-09-01 11:22:14 +03003167 ret = ath10k_core_register(ar, chip_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003169 ath10k_err(ar, "failed to register driver core: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02003170 goto err_free_irq;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003171 }
3172
3173 return 0;
3174
Michal Kazior5c771e72014-08-22 14:23:34 +02003175err_free_irq:
3176 ath10k_pci_free_irq(ar);
Michal Kazior21396272014-08-28 10:24:40 +02003177 ath10k_pci_kill_tasklet(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003178
Michal Kazior403d6272014-08-22 14:23:31 +02003179err_deinit_irq:
3180 ath10k_pci_deinit_irq(ar);
3181
Michal Kaziorc0c378f2014-08-07 11:03:28 +02003182err_sleep:
Michal Kazior0bcbbe62015-05-29 07:35:24 +02003183 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003184 ath10k_pci_release(ar);
3185
Raja Mani90188f82016-01-27 15:24:24 +05303186err_free_pipes:
3187 ath10k_pci_free_pipes(ar);
3188
Michal Kaziore7b54192014-08-07 11:03:27 +02003189err_core_destroy:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003191
3192 return ret;
3193}
3194
3195static void ath10k_pci_remove(struct pci_dev *pdev)
3196{
3197 struct ath10k *ar = pci_get_drvdata(pdev);
3198 struct ath10k_pci *ar_pci;
3199
Michal Kazior7aa7a722014-08-25 12:09:38 +02003200 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003201
3202 if (!ar)
3203 return;
3204
3205 ar_pci = ath10k_pci_priv(ar);
3206
3207 if (!ar_pci)
3208 return;
3209
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210 ath10k_core_unregister(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003211 ath10k_pci_free_irq(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003212 ath10k_pci_deinit_irq(ar);
Raja Mani90188f82016-01-27 15:24:24 +05303213 ath10k_pci_release_resource(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00003214 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003215 ath10k_pci_release(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003217}
3218
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
3220
3221static struct pci_driver ath10k_pci_driver = {
3222 .name = "ath10k_pci",
3223 .id_table = ath10k_pci_id_table,
3224 .probe = ath10k_pci_probe,
3225 .remove = ath10k_pci_remove,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003226};
3227
3228static int __init ath10k_pci_init(void)
3229{
3230 int ret;
3231
3232 ret = pci_register_driver(&ath10k_pci_driver);
3233 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003234 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
3235 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236
Raja Mani0b523ce2016-01-27 15:24:25 +05303237 ret = ath10k_ahb_init();
3238 if (ret)
3239 printk(KERN_ERR "ahb init failed: %d\n", ret);
3240
Kalle Valo5e3dd152013-06-12 20:52:10 +03003241 return ret;
3242}
3243module_init(ath10k_pci_init);
3244
3245static void __exit ath10k_pci_exit(void)
3246{
3247 pci_unregister_driver(&ath10k_pci_driver);
Raja Mani0b523ce2016-01-27 15:24:25 +05303248 ath10k_ahb_exit();
Kalle Valo5e3dd152013-06-12 20:52:10 +03003249}
3250
3251module_exit(ath10k_pci_exit);
3252
3253MODULE_AUTHOR("Qualcomm Atheros");
3254MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
3255MODULE_LICENSE("Dual BSD/GPL");
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003256
3257/* QCA988x 2.0 firmware files */
Bartosz Markowski8026cae2014-10-06 14:16:41 +02003258MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
3259MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
3260MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003261MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Kalle Valo53513c32015-03-25 13:12:42 +02003262MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003264MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003265
3266/* QCA6174 2.1 firmware files */
3267MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003268MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003269MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003270MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003271
3272/* QCA6174 3.1 firmware files */
3273MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003274MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003275MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003276MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowskia226b512015-10-28 15:09:53 +01003277
3278/* QCA9377 1.0 firmware files */
3279MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3280MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);