blob: 0b305efe6c946fd900cae31a8020cc89a292f178 [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);
Rajkumar Manoharan128abd02016-03-22 17:22:18 +0530812
813 while (num >= 0) {
Michal Kazior728f95e2014-08-22 14:33:14 +0200814 ret = __ath10k_pci_rx_post_buf(pipe);
815 if (ret) {
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300816 if (ret == -ENOSPC)
817 break;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200818 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
Michal Kazior728f95e2014-08-22 14:33:14 +0200819 mod_timer(&ar_pci->rx_post_retry, jiffies +
820 ATH10K_PCI_RX_POST_RETRY_MS);
821 break;
822 }
Rajkumar Manoharan128abd02016-03-22 17:22:18 +0530823 num--;
Michal Kazior728f95e2014-08-22 14:33:14 +0200824 }
825}
826
Raja Manif52f5172016-01-27 15:24:22 +0530827void ath10k_pci_rx_post(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +0200828{
829 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
830 int i;
831
Michal Kazior728f95e2014-08-22 14:33:14 +0200832 for (i = 0; i < CE_COUNT; i++)
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300833 ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
Michal Kazior728f95e2014-08-22 14:33:14 +0200834}
835
Raja Manif52f5172016-01-27 15:24:22 +0530836void ath10k_pci_rx_replenish_retry(unsigned long ptr)
Michal Kazior728f95e2014-08-22 14:33:14 +0200837{
838 struct ath10k *ar = (void *)ptr;
839
840 ath10k_pci_rx_post(ar);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100841}
842
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530843static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
844{
845 u32 val = 0;
846
847 switch (ar->hw_rev) {
848 case ATH10K_HW_QCA988X:
849 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +0100850 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530851 val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
852 CORE_CTRL_ADDRESS) &
Vasanthakumar Thiagarajan3c7e2562015-07-03 19:25:27 +0530853 0x7ff) << 21;
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530854 break;
855 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +0530856 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530857 val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
858 break;
859 }
860
861 val |= 0x100000 | (addr & 0xfffff);
862 return val;
863}
864
Kalle Valo5e3dd152013-06-12 20:52:10 +0300865/*
866 * Diagnostic read/write access is provided for startup/config/debug usage.
867 * Caller must guarantee proper alignment, when applicable, and single user
868 * at any moment.
869 */
870static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
871 int nbytes)
872{
873 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
874 int ret = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530875 u32 *buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300876 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
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
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530912 ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, 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;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530943 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
944 (void **)&buf,
945 &completed_nbytes)
946 != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300947 mdelay(1);
948
949 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
950 ret = -EBUSY;
951 goto done;
952 }
953 }
954
955 if (nbytes != completed_nbytes) {
956 ret = -EIO;
957 goto done;
958 }
959
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530960 if (*buf != ce_data) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300961 ret = -EIO;
962 goto done;
963 }
964
965 remaining_bytes -= nbytes;
966 address += nbytes;
967 ce_data += nbytes;
968 }
969
970done:
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300971 if (ret == 0)
972 memcpy(data, data_buf, orig_nbytes);
973 else
Michal Kazior7aa7a722014-08-25 12:09:38 +0200974 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +0200975 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300976
977 if (data_buf)
Michal Kazior68c03242014-03-28 10:02:35 +0200978 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
979 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980
Kalle Valoeef25402014-09-24 14:16:52 +0300981 spin_unlock_bh(&ar_pci->ce_lock);
982
Kalle Valo5e3dd152013-06-12 20:52:10 +0300983 return ret;
984}
985
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300986static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
987{
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300988 __le32 val = 0;
989 int ret;
990
991 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
992 *value = __le32_to_cpu(val);
993
994 return ret;
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300995}
996
997static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
998 u32 src, u32 len)
999{
1000 u32 host_addr, addr;
1001 int ret;
1002
1003 host_addr = host_interest_item_address(src);
1004
1005 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
1006 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001007 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001008 src, ret);
1009 return ret;
1010 }
1011
1012 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
1013 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001014 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001015 addr, len, ret);
1016 return ret;
1017 }
1018
1019 return 0;
1020}
1021
1022#define ath10k_pci_diag_read_hi(ar, dest, src, len) \
Kalle Valo8cc7f262014-09-14 12:50:39 +03001023 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001024
Raja Manif52f5172016-01-27 15:24:22 +05301025int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
1026 const void *data, int nbytes)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001027{
1028 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1029 int ret = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301030 u32 *buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001031 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
Michal Kazior2aa39112013-08-27 13:08:02 +02001032 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001033 void *data_buf = NULL;
1034 u32 ce_data; /* Host buffer address in CE space */
1035 dma_addr_t ce_data_base = 0;
1036 int i;
1037
Kalle Valoeef25402014-09-24 14:16:52 +03001038 spin_lock_bh(&ar_pci->ce_lock);
1039
Kalle Valo5e3dd152013-06-12 20:52:10 +03001040 ce_diag = ar_pci->ce_diag;
1041
1042 /*
1043 * Allocate a temporary bounce buffer to hold caller's data
1044 * to be DMA'ed to Target. This guarantees
1045 * 1) 4-byte alignment
1046 * 2) Buffer in DMA-able space
1047 */
1048 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +02001049 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
1050 orig_nbytes,
1051 &ce_data_base,
1052 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001053 if (!data_buf) {
1054 ret = -ENOMEM;
1055 goto done;
1056 }
1057
1058 /* Copy caller's data to allocated DMA buf */
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001059 memcpy(data_buf, data, orig_nbytes);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001060
1061 /*
1062 * The address supplied by the caller is in the
1063 * Target CPU virtual address space.
1064 *
1065 * In order to use this address with the diagnostic CE,
1066 * convert it from
1067 * Target CPU virtual address space
1068 * to
1069 * CE address space
1070 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +05301071 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001072
1073 remaining_bytes = orig_nbytes;
1074 ce_data = ce_data_base;
1075 while (remaining_bytes) {
1076 /* FIXME: check cast */
1077 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
1078
1079 /* Set up to receive directly into Target(!) address */
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301080 ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001081 if (ret != 0)
1082 goto done;
1083
1084 /*
1085 * Request CE to send caller-supplied data that
1086 * was copied to bounce buffer to Target(!) address.
1087 */
Kalle Valoeef25402014-09-24 14:16:52 +03001088 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
1089 nbytes, 0, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090 if (ret != 0)
1091 goto done;
1092
1093 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301094 while (ath10k_ce_completed_send_next_nolock(ce_diag,
1095 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001096 mdelay(1);
1097
1098 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1099 ret = -EBUSY;
1100 goto done;
1101 }
1102 }
1103
Kalle Valo5e3dd152013-06-12 20:52:10 +03001104 i = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301105 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
1106 (void **)&buf,
1107 &completed_nbytes)
1108 != 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
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301122 if (*buf != address) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 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;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001184 unsigned int nbytes, max_nbytes;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001185
Michal Kazior1cb86d42014-11-27 11:09:38 +01001186 __skb_queue_head_init(&list);
Michal Kazior5440ce22013-09-03 15:09:58 +02001187 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301188 &nbytes) == 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189 skb = transfer_context;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001190 max_nbytes = skb->len + skb_tailroom(skb);
Michal Kazior8582bf32015-01-24 12:14:47 +02001191 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior2f5280d2014-02-27 18:50:05 +02001192 max_nbytes, DMA_FROM_DEVICE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193
Michal Kazior2f5280d2014-02-27 18:50:05 +02001194 if (unlikely(max_nbytes < nbytes)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001195 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
Michal Kazior2f5280d2014-02-27 18:50:05 +02001196 nbytes, max_nbytes);
1197 dev_kfree_skb_any(skb);
1198 continue;
1199 }
1200
1201 skb_put(skb, nbytes);
Michal Kazior1cb86d42014-11-27 11:09:38 +01001202 __skb_queue_tail(&list, skb);
1203 }
Michal Kaziora360e542014-09-23 10:22:54 +02001204
Michal Kazior1cb86d42014-11-27 11:09:38 +01001205 while ((skb = __skb_dequeue(&list))) {
Michal Kaziora360e542014-09-23 10:22:54 +02001206 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1207 ce_state->id, skb->len);
1208 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1209 skb->data, skb->len);
1210
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301211 callback(ar, skb);
Michal Kazior2f5280d2014-02-27 18:50:05 +02001212 }
Michal Kaziorc29a3802014-07-21 21:03:10 +03001213
Michal Kazior728f95e2014-08-22 14:33:14 +02001214 ath10k_pci_rx_post_pipe(pipe_info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001215}
1216
Rajkumar Manoharan128abd02016-03-22 17:22:18 +05301217static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
1218 void (*callback)(struct ath10k *ar,
1219 struct sk_buff *skb))
1220{
1221 struct ath10k *ar = ce_state->ar;
1222 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1223 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
1224 struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
1225 struct sk_buff *skb;
1226 struct sk_buff_head list;
1227 void *transfer_context;
1228 unsigned int nbytes, max_nbytes, nentries;
1229 int orig_len;
1230
1231 /* No need to aquire ce_lock for CE5, since this is the only place CE5
1232 * is processed other than init and deinit. Before releasing CE5
1233 * buffers, interrupts are disabled. Thus CE5 access is serialized.
1234 */
1235 __skb_queue_head_init(&list);
1236 while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
1237 &nbytes) == 0) {
1238 skb = transfer_context;
1239 max_nbytes = skb->len + skb_tailroom(skb);
1240
1241 if (unlikely(max_nbytes < nbytes)) {
1242 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
1243 nbytes, max_nbytes);
1244 continue;
1245 }
1246
1247 dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1248 max_nbytes, DMA_FROM_DEVICE);
1249 skb_put(skb, nbytes);
1250 __skb_queue_tail(&list, skb);
1251 }
1252
1253 nentries = skb_queue_len(&list);
1254 while ((skb = __skb_dequeue(&list))) {
1255 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1256 ce_state->id, skb->len);
1257 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1258 skb->data, skb->len);
1259
1260 orig_len = skb->len;
1261 callback(ar, skb);
1262 skb_push(skb, orig_len - skb->len);
1263 skb_reset_tail_pointer(skb);
1264 skb_trim(skb, 0);
1265
1266 /*let device gain the buffer again*/
1267 dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1268 skb->len + skb_tailroom(skb),
1269 DMA_FROM_DEVICE);
1270 }
1271 ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
1272}
1273
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301274/* Called by lower (CE) layer when data is received from the Target. */
1275static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1276{
1277 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1278}
1279
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +05301280static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1281{
1282 /* CE4 polling needs to be done whenever CE pipe which transports
1283 * HTT Rx (target->host) is processed.
1284 */
1285 ath10k_ce_per_engine_service(ce_state->ar, 4);
1286
1287 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1288}
1289
Vivek Natarajanafb0bf72015-10-30 14:57:58 +05301290/* Called by lower (CE) layer when data is received from the Target.
1291 * Only 10.4 firmware uses separate CE to transfer pktlog data.
1292 */
1293static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
1294{
1295 ath10k_pci_process_rx_cb(ce_state,
1296 ath10k_htt_rx_pktlog_completion_handler);
1297}
1298
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301299/* Called by lower (CE) layer when a send to HTT Target completes. */
1300static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
1301{
1302 struct ath10k *ar = ce_state->ar;
1303 struct sk_buff *skb;
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301304
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301305 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301306 /* no need to call tx completion for NULL pointers */
1307 if (!skb)
1308 continue;
1309
1310 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1311 skb->len, DMA_TO_DEVICE);
1312 ath10k_htt_hif_tx_complete(ar, skb);
1313 }
1314}
1315
1316static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
1317{
1318 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
1319 ath10k_htt_t2h_msg_handler(ar, skb);
1320}
1321
1322/* Called by lower (CE) layer when HTT data is received from the Target. */
1323static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
1324{
1325 /* CE4 polling needs to be done whenever CE pipe which transports
1326 * HTT Rx (target->host) is processed.
1327 */
1328 ath10k_ce_per_engine_service(ce_state->ar, 4);
1329
Rajkumar Manoharan128abd02016-03-22 17:22:18 +05301330 ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301331}
1332
Raja Manif52f5172016-01-27 15:24:22 +05301333int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
1334 struct ath10k_hif_sg_item *items, int n_items)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior726346f2014-02-27 18:50:04 +02001337 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
1338 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
1339 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
Michal Kazior7147a132014-05-26 12:02:58 +02001340 unsigned int nentries_mask;
1341 unsigned int sw_index;
1342 unsigned int write_index;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001343 int err, i = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344
Michal Kazior726346f2014-02-27 18:50:04 +02001345 spin_lock_bh(&ar_pci->ce_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346
Michal Kazior7147a132014-05-26 12:02:58 +02001347 nentries_mask = src_ring->nentries_mask;
1348 sw_index = src_ring->sw_index;
1349 write_index = src_ring->write_index;
1350
Michal Kazior726346f2014-02-27 18:50:04 +02001351 if (unlikely(CE_RING_DELTA(nentries_mask,
1352 write_index, sw_index - 1) < n_items)) {
1353 err = -ENOBUFS;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001354 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001355 }
1356
1357 for (i = 0; i < n_items - 1; i++) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001358 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001359 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1360 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001361 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001362 items[i].vaddr, items[i].len);
1363
1364 err = ath10k_ce_send_nolock(ce_pipe,
1365 items[i].transfer_context,
1366 items[i].paddr,
1367 items[i].len,
1368 items[i].transfer_id,
1369 CE_SEND_FLAG_GATHER);
1370 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001371 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001372 }
1373
1374 /* `i` is equal to `n_items -1` after for() */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001375
Michal Kazior7aa7a722014-08-25 12:09:38 +02001376 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001377 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1378 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001379 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001380 items[i].vaddr, items[i].len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381
Michal Kazior726346f2014-02-27 18:50:04 +02001382 err = ath10k_ce_send_nolock(ce_pipe,
1383 items[i].transfer_context,
1384 items[i].paddr,
1385 items[i].len,
1386 items[i].transfer_id,
1387 0);
1388 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001389 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390
Michal Kazior08b8aa02014-05-26 12:02:59 +02001391 spin_unlock_bh(&ar_pci->ce_lock);
1392 return 0;
1393
1394err:
1395 for (; i > 0; i--)
1396 __ath10k_ce_send_revert(ce_pipe);
1397
Michal Kazior726346f2014-02-27 18:50:04 +02001398 spin_unlock_bh(&ar_pci->ce_lock);
1399 return err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400}
1401
Raja Manif52f5172016-01-27 15:24:22 +05301402int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
1403 size_t buf_len)
Kalle Valoeef25402014-09-24 14:16:52 +03001404{
1405 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
1406}
1407
Raja Manif52f5172016-01-27 15:24:22 +05301408u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409{
1410 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001411
Michal Kazior7aa7a722014-08-25 12:09:38 +02001412 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001413
Michal Kazior3efcb3b2013-10-02 11:03:41 +02001414 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001415}
1416
Ben Greear384914b2014-08-25 08:37:32 +03001417static void ath10k_pci_dump_registers(struct ath10k *ar,
1418 struct ath10k_fw_crash_data *crash_data)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001419{
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001420 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
1421 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001422
Ben Greear384914b2014-08-25 08:37:32 +03001423 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001424
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001425 ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
1426 hi_failure_state,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001427 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001429 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001430 return;
1431 }
1432
1433 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
1434
Michal Kazior7aa7a722014-08-25 12:09:38 +02001435 ath10k_err(ar, "firmware register dump:\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001437 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438 i,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001439 __le32_to_cpu(reg_dump_values[i]),
1440 __le32_to_cpu(reg_dump_values[i + 1]),
1441 __le32_to_cpu(reg_dump_values[i + 2]),
1442 __le32_to_cpu(reg_dump_values[i + 3]));
Michal Kazioraffd3212013-07-16 09:54:35 +02001443
Michal Kazior1bbb1192014-08-25 12:13:14 +02001444 if (!crash_data)
1445 return;
1446
Ben Greear384914b2014-08-25 08:37:32 +03001447 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001448 crash_data->registers[i] = reg_dump_values[i];
Ben Greear384914b2014-08-25 08:37:32 +03001449}
1450
Kalle Valo0e9848c2014-08-25 08:37:37 +03001451static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
Ben Greear384914b2014-08-25 08:37:32 +03001452{
1453 struct ath10k_fw_crash_data *crash_data;
1454 char uuid[50];
1455
1456 spin_lock_bh(&ar->data_lock);
1457
Ben Greearf51dbe72014-09-29 14:41:46 +03001458 ar->stats.fw_crash_counter++;
1459
Ben Greear384914b2014-08-25 08:37:32 +03001460 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
1461
1462 if (crash_data)
1463 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
1464 else
1465 scnprintf(uuid, sizeof(uuid), "n/a");
1466
Michal Kazior7aa7a722014-08-25 12:09:38 +02001467 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
Kalle Valo8a0c7972014-08-25 08:37:45 +03001468 ath10k_print_driver_info(ar);
Ben Greear384914b2014-08-25 08:37:32 +03001469 ath10k_pci_dump_registers(ar, crash_data);
1470
Ben Greear384914b2014-08-25 08:37:32 +03001471 spin_unlock_bh(&ar->data_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02001472
Michal Kazior5e90de82013-10-16 16:46:05 +03001473 queue_work(ar->workqueue, &ar->restart_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474}
1475
Raja Manif52f5172016-01-27 15:24:22 +05301476void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1477 int force)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001479 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001480
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481 if (!force) {
1482 int resources;
1483 /*
1484 * Decide whether to actually poll for completions, or just
1485 * wait for a later chance.
1486 * If there seem to be plenty of resources left, then just wait
1487 * since checking involves reading a CE register, which is a
1488 * relatively expensive operation.
1489 */
1490 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1491
1492 /*
1493 * If at least 50% of the total resources are still available,
1494 * don't bother checking again yet.
1495 */
1496 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1497 return;
1498 }
1499 ath10k_ce_per_engine_service(ar, pipe);
1500}
1501
Raja Manif52f5172016-01-27 15:24:22 +05301502void ath10k_pci_kill_tasklet(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001503{
1504 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001505 int i;
1506
Kalle Valo5e3dd152013-06-12 20:52:10 +03001507 tasklet_kill(&ar_pci->intr_tq);
Michal Kazior103d4f52013-11-08 08:01:24 +01001508 tasklet_kill(&ar_pci->msi_fw_err);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001509
1510 for (i = 0; i < CE_COUNT; i++)
1511 tasklet_kill(&ar_pci->pipe_info[i].intr);
Michal Kazior728f95e2014-08-22 14:33:14 +02001512
1513 del_timer_sync(&ar_pci->rx_post_retry);
Michal Kazior96a9d0d2013-11-08 08:01:25 +01001514}
1515
Raja Manif52f5172016-01-27 15:24:22 +05301516int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
1517 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518{
Michal Kazior7c6aa252014-08-26 19:14:03 +03001519 const struct service_to_pipe *entry;
1520 bool ul_set = false, dl_set = false;
1521 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001522
Michal Kazior7aa7a722014-08-25 12:09:38 +02001523 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001524
Michal Kazior7c6aa252014-08-26 19:14:03 +03001525 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1526 entry = &target_service_to_ce_map_wlan[i];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001527
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001528 if (__le32_to_cpu(entry->service_id) != service_id)
Michal Kazior7c6aa252014-08-26 19:14:03 +03001529 continue;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001530
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001531 switch (__le32_to_cpu(entry->pipedir)) {
Michal Kazior7c6aa252014-08-26 19:14:03 +03001532 case PIPEDIR_NONE:
1533 break;
1534 case PIPEDIR_IN:
1535 WARN_ON(dl_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001536 *dl_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001537 dl_set = true;
1538 break;
1539 case PIPEDIR_OUT:
1540 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001541 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001542 ul_set = true;
1543 break;
1544 case PIPEDIR_INOUT:
1545 WARN_ON(dl_set);
1546 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001547 *dl_pipe = __le32_to_cpu(entry->pipenum);
1548 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001549 dl_set = true;
1550 ul_set = true;
1551 break;
1552 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553 }
Michal Kazior7c6aa252014-08-26 19:14:03 +03001554
1555 if (WARN_ON(!ul_set || !dl_set))
1556 return -ENOENT;
1557
Michal Kazior7c6aa252014-08-26 19:14:03 +03001558 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001559}
1560
Raja Manif52f5172016-01-27 15:24:22 +05301561void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1562 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001563{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001564 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001565
Kalle Valo5e3dd152013-06-12 20:52:10 +03001566 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1567 ATH10K_HTC_SVC_ID_RSVD_CTRL,
Rajkumar Manoharan400143e2015-10-12 18:27:06 +05301568 ul_pipe, dl_pipe);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569}
1570
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001571static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1572{
1573 u32 val;
1574
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301575 switch (ar->hw_rev) {
1576 case ATH10K_HW_QCA988X:
1577 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001578 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301579 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1580 CORE_CTRL_ADDRESS);
1581 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1582 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1583 CORE_CTRL_ADDRESS, val);
1584 break;
1585 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +05301586 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301587 /* TODO: Find appropriate register configuration for QCA99X0
1588 * to mask irq/MSI.
1589 */
1590 break;
1591 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001592}
1593
1594static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1595{
1596 u32 val;
1597
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301598 switch (ar->hw_rev) {
1599 case ATH10K_HW_QCA988X:
1600 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001601 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301602 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1603 CORE_CTRL_ADDRESS);
1604 val |= CORE_CTRL_PCIE_REG_31_MASK;
1605 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1606 CORE_CTRL_ADDRESS, val);
1607 break;
1608 case ATH10K_HW_QCA99X0:
Raja Mani0b523ce2016-01-27 15:24:25 +05301609 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301610 /* TODO: Find appropriate register configuration for QCA99X0
1611 * to unmask irq/MSI.
1612 */
1613 break;
1614 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001615}
1616
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001617static void ath10k_pci_irq_disable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618{
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001619 ath10k_ce_disable_interrupts(ar);
1620 ath10k_pci_disable_and_clear_legacy_irq(ar);
1621 ath10k_pci_irq_msi_fw_mask(ar);
1622}
1623
1624static void ath10k_pci_irq_sync(struct ath10k *ar)
1625{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001627 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001628
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001629 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1630 synchronize_irq(ar_pci->pdev->irq + i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631}
1632
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001633static void ath10k_pci_irq_enable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001634{
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001635 ath10k_ce_enable_interrupts(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001636 ath10k_pci_enable_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001637 ath10k_pci_irq_msi_fw_unmask(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001638}
1639
1640static int ath10k_pci_hif_start(struct ath10k *ar)
1641{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001642 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo9a149692015-10-05 17:56:36 +03001643
Michal Kazior7aa7a722014-08-25 12:09:38 +02001644 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001645
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001646 ath10k_pci_irq_enable(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +02001647 ath10k_pci_rx_post(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001648
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001649 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
1650 ar_pci->link_ctl);
1651
Kalle Valo5e3dd152013-06-12 20:52:10 +03001652 return 0;
1653}
1654
Michal Kazior099ac7c2014-10-28 10:32:05 +01001655static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001656{
1657 struct ath10k *ar;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001658 struct ath10k_ce_pipe *ce_pipe;
1659 struct ath10k_ce_ring *ce_ring;
1660 struct sk_buff *skb;
1661 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662
Michal Kazior099ac7c2014-10-28 10:32:05 +01001663 ar = pci_pipe->hif_ce_state;
1664 ce_pipe = pci_pipe->ce_hdl;
1665 ce_ring = ce_pipe->dest_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666
Michal Kazior099ac7c2014-10-28 10:32:05 +01001667 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668 return;
1669
Michal Kazior099ac7c2014-10-28 10:32:05 +01001670 if (!pci_pipe->buf_sz)
1671 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001672
Michal Kazior099ac7c2014-10-28 10:32:05 +01001673 for (i = 0; i < ce_ring->nentries; i++) {
1674 skb = ce_ring->per_transfer_context[i];
1675 if (!skb)
1676 continue;
1677
1678 ce_ring->per_transfer_context[i] = NULL;
1679
Michal Kazior8582bf32015-01-24 12:14:47 +02001680 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior099ac7c2014-10-28 10:32:05 +01001681 skb->len + skb_tailroom(skb),
Kalle Valo5e3dd152013-06-12 20:52:10 +03001682 DMA_FROM_DEVICE);
Michal Kazior099ac7c2014-10-28 10:32:05 +01001683 dev_kfree_skb_any(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001684 }
1685}
1686
Michal Kazior099ac7c2014-10-28 10:32:05 +01001687static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001688{
1689 struct ath10k *ar;
1690 struct ath10k_pci *ar_pci;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001691 struct ath10k_ce_pipe *ce_pipe;
1692 struct ath10k_ce_ring *ce_ring;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001693 struct sk_buff *skb;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001694 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
Michal Kazior099ac7c2014-10-28 10:32:05 +01001696 ar = pci_pipe->hif_ce_state;
1697 ar_pci = ath10k_pci_priv(ar);
1698 ce_pipe = pci_pipe->ce_hdl;
1699 ce_ring = ce_pipe->src_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700
Michal Kazior099ac7c2014-10-28 10:32:05 +01001701 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001702 return;
1703
Michal Kazior099ac7c2014-10-28 10:32:05 +01001704 if (!pci_pipe->buf_sz)
1705 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706
Michal Kazior099ac7c2014-10-28 10:32:05 +01001707 for (i = 0; i < ce_ring->nentries; i++) {
1708 skb = ce_ring->per_transfer_context[i];
1709 if (!skb)
Michal Kazior2415fc12013-11-08 08:01:32 +01001710 continue;
Michal Kazior2415fc12013-11-08 08:01:32 +01001711
Michal Kazior099ac7c2014-10-28 10:32:05 +01001712 ce_ring->per_transfer_context[i] = NULL;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001713
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301714 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001715 }
1716}
1717
1718/*
1719 * Cleanup residual buffers for device shutdown:
1720 * buffers that were enqueued for receive
1721 * buffers that were to be sent
1722 * Note: Buffers that had completed but which were
1723 * not yet processed are on a completion queue. They
1724 * are handled when the completion thread shuts down.
1725 */
1726static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1727{
1728 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1729 int pipe_num;
1730
Michal Kaziorfad6ed72013-11-08 08:01:23 +01001731 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
Michal Kazior87263e52013-08-27 13:08:01 +02001732 struct ath10k_pci_pipe *pipe_info;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733
1734 pipe_info = &ar_pci->pipe_info[pipe_num];
1735 ath10k_pci_rx_pipe_cleanup(pipe_info);
1736 ath10k_pci_tx_pipe_cleanup(pipe_info);
1737 }
1738}
1739
Raja Manif52f5172016-01-27 15:24:22 +05301740void ath10k_pci_ce_deinit(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001741{
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001742 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001744 for (i = 0; i < CE_COUNT; i++)
1745 ath10k_ce_deinit_pipe(ar, i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746}
1747
Raja Manif52f5172016-01-27 15:24:22 +05301748void ath10k_pci_flush(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +02001749{
1750 ath10k_pci_kill_tasklet(ar);
1751 ath10k_pci_buffer_cleanup(ar);
1752}
1753
Kalle Valo5e3dd152013-06-12 20:52:10 +03001754static void ath10k_pci_hif_stop(struct ath10k *ar)
1755{
Michal Kazior77258d42015-05-18 09:38:18 +00001756 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1757 unsigned long flags;
1758
Michal Kazior7aa7a722014-08-25 12:09:38 +02001759 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
Michal Kazior32270b62013-08-02 09:15:47 +02001760
Michal Kazior10d23db2014-08-22 14:33:15 +02001761 /* Most likely the device has HTT Rx ring configured. The only way to
1762 * prevent the device from accessing (and possible corrupting) host
1763 * memory is to reset the chip now.
Michal Kaziore75db4e2014-08-28 22:14:16 +03001764 *
1765 * There's also no known way of masking MSI interrupts on the device.
1766 * For ranged MSI the CE-related interrupts can be masked. However
1767 * regardless how many MSI interrupts are assigned the first one
1768 * is always used for firmware indications (crashes) and cannot be
1769 * masked. To prevent the device from asserting the interrupt reset it
1770 * before proceeding with cleanup.
Michal Kazior10d23db2014-08-22 14:33:15 +02001771 */
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301772 ath10k_pci_safe_chip_reset(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001773
1774 ath10k_pci_irq_disable(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001775 ath10k_pci_irq_sync(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001776 ath10k_pci_flush(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00001777
1778 spin_lock_irqsave(&ar_pci->ps_lock, flags);
1779 WARN_ON(ar_pci->ps_wake_refcount > 0);
1780 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781}
1782
Raja Manif52f5172016-01-27 15:24:22 +05301783int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1784 void *req, u32 req_len,
1785 void *resp, u32 *resp_len)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786{
1787 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior2aa39112013-08-27 13:08:02 +02001788 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1789 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1790 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1791 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001792 dma_addr_t req_paddr = 0;
1793 dma_addr_t resp_paddr = 0;
1794 struct bmi_xfer xfer = {};
1795 void *treq, *tresp = NULL;
1796 int ret = 0;
1797
Michal Kazior85622cd2013-11-25 14:06:22 +01001798 might_sleep();
1799
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800 if (resp && !resp_len)
1801 return -EINVAL;
1802
1803 if (resp && resp_len && *resp_len == 0)
1804 return -EINVAL;
1805
1806 treq = kmemdup(req, req_len, GFP_KERNEL);
1807 if (!treq)
1808 return -ENOMEM;
1809
1810 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1811 ret = dma_mapping_error(ar->dev, req_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001812 if (ret) {
1813 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814 goto err_dma;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001815 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816
1817 if (resp && resp_len) {
1818 tresp = kzalloc(*resp_len, GFP_KERNEL);
1819 if (!tresp) {
1820 ret = -ENOMEM;
1821 goto err_req;
1822 }
1823
1824 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1825 DMA_FROM_DEVICE);
1826 ret = dma_mapping_error(ar->dev, resp_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001827 if (ret) {
Anton Protopopov22baa982016-02-10 11:58:55 -05001828 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001829 goto err_req;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001830 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001831
1832 xfer.wait_for_resp = true;
1833 xfer.resp_len = 0;
1834
Michal Kazior728f95e2014-08-22 14:33:14 +02001835 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836 }
1837
Kalle Valo5e3dd152013-06-12 20:52:10 +03001838 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1839 if (ret)
1840 goto err_resp;
1841
Michal Kazior85622cd2013-11-25 14:06:22 +01001842 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1843 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001844 u32 unused_buffer;
1845 unsigned int unused_nbytes;
1846 unsigned int unused_id;
1847
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1849 &unused_nbytes, &unused_id);
1850 } else {
1851 /* non-zero means we did not time out */
1852 ret = 0;
1853 }
1854
1855err_resp:
1856 if (resp) {
1857 u32 unused_buffer;
1858
1859 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1860 dma_unmap_single(ar->dev, resp_paddr,
1861 *resp_len, DMA_FROM_DEVICE);
1862 }
1863err_req:
1864 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1865
1866 if (ret == 0 && resp_len) {
1867 *resp_len = min(*resp_len, xfer.resp_len);
1868 memcpy(resp, tresp, xfer.resp_len);
1869 }
1870err_dma:
1871 kfree(treq);
1872 kfree(tresp);
1873
1874 return ret;
1875}
1876
Michal Kazior5440ce22013-09-03 15:09:58 +02001877static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878{
Michal Kazior5440ce22013-09-03 15:09:58 +02001879 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001880
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301881 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
Michal Kazior5440ce22013-09-03 15:09:58 +02001882 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001883
Michal Kazior2374b182014-07-14 16:25:25 +03001884 xfer->tx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885}
1886
Michal Kazior5440ce22013-09-03 15:09:58 +02001887static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001888{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001889 struct ath10k *ar = ce_state->ar;
Michal Kazior5440ce22013-09-03 15:09:58 +02001890 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001891 unsigned int nbytes;
Michal Kazior5440ce22013-09-03 15:09:58 +02001892
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301893 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer,
1894 &nbytes))
Michal Kazior5440ce22013-09-03 15:09:58 +02001895 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896
Michal Kazior04ed9df2014-10-28 10:34:36 +01001897 if (WARN_ON_ONCE(!xfer))
1898 return;
1899
Kalle Valo5e3dd152013-06-12 20:52:10 +03001900 if (!xfer->wait_for_resp) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001901 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001902 return;
1903 }
1904
1905 xfer->resp_len = nbytes;
Michal Kazior2374b182014-07-14 16:25:25 +03001906 xfer->rx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001907}
1908
Michal Kazior85622cd2013-11-25 14:06:22 +01001909static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1910 struct ath10k_ce_pipe *rx_pipe,
1911 struct bmi_xfer *xfer)
1912{
1913 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1914
1915 while (time_before_eq(jiffies, timeout)) {
1916 ath10k_pci_bmi_send_done(tx_pipe);
1917 ath10k_pci_bmi_recv_data(rx_pipe);
1918
Michal Kazior2374b182014-07-14 16:25:25 +03001919 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
Michal Kazior85622cd2013-11-25 14:06:22 +01001920 return 0;
1921
1922 schedule();
1923 }
1924
1925 return -ETIMEDOUT;
1926}
1927
Kalle Valo5e3dd152013-06-12 20:52:10 +03001928/*
Kalle Valo5e3dd152013-06-12 20:52:10 +03001929 * Send an interrupt to the device to wake up the Target CPU
1930 * so it has an opportunity to notice any changed state.
1931 */
1932static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1933{
Michal Kazior9e264942014-09-02 11:00:21 +03001934 u32 addr, val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935
Michal Kazior9e264942014-09-02 11:00:21 +03001936 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1937 val = ath10k_pci_read32(ar, addr);
1938 val |= CORE_CTRL_CPU_INTR_MASK;
1939 ath10k_pci_write32(ar, addr, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001941 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942}
1943
Michal Kaziord63955b2015-01-24 12:14:49 +02001944static int ath10k_pci_get_num_banks(struct ath10k *ar)
1945{
1946 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1947
1948 switch (ar_pci->pdev->device) {
1949 case QCA988X_2_0_DEVICE_ID:
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05301950 case QCA99X0_2_0_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001951 return 1;
Michal Kazior36582e52015-08-13 14:32:26 +02001952 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001953 case QCA6174_2_1_DEVICE_ID:
1954 switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
1955 case QCA6174_HW_1_0_CHIP_ID_REV:
1956 case QCA6174_HW_1_1_CHIP_ID_REV:
Michal Kazior11a002e2015-04-20 09:20:41 +00001957 case QCA6174_HW_2_1_CHIP_ID_REV:
1958 case QCA6174_HW_2_2_CHIP_ID_REV:
Michal Kaziord63955b2015-01-24 12:14:49 +02001959 return 3;
1960 case QCA6174_HW_1_3_CHIP_ID_REV:
1961 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001962 case QCA6174_HW_3_0_CHIP_ID_REV:
1963 case QCA6174_HW_3_1_CHIP_ID_REV:
1964 case QCA6174_HW_3_2_CHIP_ID_REV:
1965 return 9;
1966 }
1967 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01001968 case QCA9377_1_0_DEVICE_ID:
1969 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001970 }
1971
1972 ath10k_warn(ar, "unknown number of banks, assuming 1\n");
1973 return 1;
1974}
1975
Raja Mani4ddb3292016-01-27 15:24:23 +05301976static int ath10k_bus_get_num_banks(struct ath10k *ar)
1977{
1978 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1979
1980 return ar_pci->bus_ops->get_num_banks(ar);
1981}
1982
Raja Manif52f5172016-01-27 15:24:22 +05301983int ath10k_pci_init_config(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984{
1985 u32 interconnect_targ_addr;
1986 u32 pcie_state_targ_addr = 0;
1987 u32 pipe_cfg_targ_addr = 0;
1988 u32 svc_to_pipe_map = 0;
1989 u32 pcie_config_flags = 0;
1990 u32 ealloc_value;
1991 u32 ealloc_targ_addr;
1992 u32 flag2_value;
1993 u32 flag2_targ_addr;
1994 int ret = 0;
1995
1996 /* Download to Target the CE Config and the service-to-CE map */
1997 interconnect_targ_addr =
1998 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1999
2000 /* Supply Target-side CE configuration */
Michal Kazior9e264942014-09-02 11:00:21 +03002001 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
2002 &pcie_state_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002003 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002004 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002005 return ret;
2006 }
2007
2008 if (pcie_state_targ_addr == 0) {
2009 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002010 ath10k_err(ar, "Invalid pcie state addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011 return ret;
2012 }
2013
Michal Kazior9e264942014-09-02 11:00:21 +03002014 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002016 pipe_cfg_addr)),
2017 &pipe_cfg_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002018 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002019 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002020 return ret;
2021 }
2022
2023 if (pipe_cfg_targ_addr == 0) {
2024 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002025 ath10k_err(ar, "Invalid pipe cfg addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 return ret;
2027 }
2028
2029 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002030 target_ce_config_wlan,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302031 sizeof(struct ce_pipe_config) *
2032 NUM_TARGET_CE_CONFIG_WLAN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002033
2034 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002035 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 return ret;
2037 }
2038
Michal Kazior9e264942014-09-02 11:00:21 +03002039 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002040 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002041 svc_to_pipe_map)),
2042 &svc_to_pipe_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002044 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 return ret;
2046 }
2047
2048 if (svc_to_pipe_map == 0) {
2049 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002050 ath10k_err(ar, "Invalid svc_to_pipe map\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051 return ret;
2052 }
2053
2054 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
Kalle Valo5b07e072014-09-14 12:50:06 +03002055 target_service_to_ce_map_wlan,
2056 sizeof(target_service_to_ce_map_wlan));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002058 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002059 return ret;
2060 }
2061
Michal Kazior9e264942014-09-02 11:00:21 +03002062 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002063 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002064 config_flags)),
2065 &pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002066 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002067 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 return ret;
2069 }
2070
2071 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
2072
Michal Kazior9e264942014-09-02 11:00:21 +03002073 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
2074 offsetof(struct pcie_state,
2075 config_flags)),
2076 pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002078 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079 return ret;
2080 }
2081
2082 /* configure early allocation */
2083 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
2084
Michal Kazior9e264942014-09-02 11:00:21 +03002085 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002086 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002087 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002088 return ret;
2089 }
2090
2091 /* first bank is switched to IRAM */
2092 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
2093 HI_EARLY_ALLOC_MAGIC_MASK);
Raja Mani4ddb3292016-01-27 15:24:23 +05302094 ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
Michal Kaziord63955b2015-01-24 12:14:49 +02002095 HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
2097
Michal Kazior9e264942014-09-02 11:00:21 +03002098 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002099 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002100 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101 return ret;
2102 }
2103
2104 /* Tell Target to proceed with initialization */
2105 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
2106
Michal Kazior9e264942014-09-02 11:00:21 +03002107 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002108 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002109 ath10k_err(ar, "Failed to get option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 return ret;
2111 }
2112
2113 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
2114
Michal Kazior9e264942014-09-02 11:00:21 +03002115 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002117 ath10k_err(ar, "Failed to set option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002118 return ret;
2119 }
2120
2121 return 0;
2122}
2123
Ryan Hsu2727a742015-11-05 18:44:27 -08002124static void ath10k_pci_override_ce_config(struct ath10k *ar)
2125{
2126 struct ce_attr *attr;
2127 struct ce_pipe_config *config;
2128
2129 /* For QCA6174 we're overriding the Copy Engine 5 configuration,
2130 * since it is currently used for other feature.
2131 */
2132
2133 /* Override Host's Copy Engine 5 configuration */
2134 attr = &host_ce_config_wlan[5];
2135 attr->src_sz_max = 0;
2136 attr->dest_nentries = 0;
2137
2138 /* Override Target firmware's Copy Engine configuration */
2139 config = &target_ce_config_wlan[5];
2140 config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
2141 config->nbytes_max = __cpu_to_le32(2048);
2142
2143 /* Map from service/endpoint to Copy Engine */
2144 target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
2145}
2146
Raja Manif52f5172016-01-27 15:24:22 +05302147int ath10k_pci_alloc_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002148{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002149 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2150 struct ath10k_pci_pipe *pipe;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002151 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002152
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002153 for (i = 0; i < CE_COUNT; i++) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002154 pipe = &ar_pci->pipe_info[i];
2155 pipe->ce_hdl = &ar_pci->ce_states[i];
2156 pipe->pipe_num = i;
2157 pipe->hif_ce_state = ar;
2158
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +05302159 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002160 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002161 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002162 i, ret);
2163 return ret;
2164 }
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002165
2166 /* Last CE is Diagnostic Window */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302167 if (i == CE_DIAG_PIPE) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002168 ar_pci->ce_diag = pipe->ce_hdl;
2169 continue;
2170 }
2171
2172 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002173 }
2174
2175 return 0;
2176}
2177
Raja Manif52f5172016-01-27 15:24:22 +05302178void ath10k_pci_free_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002179{
2180 int i;
2181
2182 for (i = 0; i < CE_COUNT; i++)
2183 ath10k_ce_free_pipe(ar, i);
2184}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185
Raja Manif52f5172016-01-27 15:24:22 +05302186int ath10k_pci_init_pipes(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002188 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002190 for (i = 0; i < CE_COUNT; i++) {
2191 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002192 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002193 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002194 i, ret);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002195 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002196 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197 }
2198
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199 return 0;
2200}
2201
Michal Kazior5c771e72014-08-22 14:23:34 +02002202static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203{
Michal Kazior5c771e72014-08-22 14:23:34 +02002204 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
2205 FW_IND_EVENT_PENDING;
2206}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002207
Michal Kazior5c771e72014-08-22 14:23:34 +02002208static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
2209{
2210 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211
Michal Kazior5c771e72014-08-22 14:23:34 +02002212 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2213 val &= ~FW_IND_EVENT_PENDING;
2214 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215}
2216
Michal Kaziorde013572014-05-14 16:56:16 +03002217/* this function effectively clears target memory controller assert line */
2218static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
2219{
2220 u32 val;
2221
2222 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2223 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2224 val | SOC_RESET_CONTROL_SI0_RST_MASK);
2225 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2226
2227 msleep(10);
2228
2229 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2230 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2231 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
2232 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2233
2234 msleep(10);
2235}
2236
Michal Kazior61c16482014-10-28 10:32:06 +01002237static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002238{
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002239 u32 val;
2240
Kalle Valob39712c2014-03-28 09:32:46 +02002241 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002242
Michal Kazior61c16482014-10-28 10:32:06 +01002243 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2244 SOC_RESET_CONTROL_ADDRESS);
2245 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2246 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
2247}
2248
2249static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
2250{
2251 u32 val;
2252
2253 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2254 SOC_RESET_CONTROL_ADDRESS);
2255
2256 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2257 val | SOC_RESET_CONTROL_CE_RST_MASK);
2258 msleep(10);
2259 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2260 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
2261}
2262
2263static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
2264{
2265 u32 val;
2266
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002267 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2268 SOC_LF_TIMER_CONTROL0_ADDRESS);
2269 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
2270 SOC_LF_TIMER_CONTROL0_ADDRESS,
2271 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
Michal Kazior61c16482014-10-28 10:32:06 +01002272}
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002273
Michal Kazior61c16482014-10-28 10:32:06 +01002274static int ath10k_pci_warm_reset(struct ath10k *ar)
2275{
2276 int ret;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002277
Michal Kazior61c16482014-10-28 10:32:06 +01002278 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002279
Michal Kazior61c16482014-10-28 10:32:06 +01002280 spin_lock_bh(&ar->data_lock);
2281 ar->stats.fw_warm_reset_counter++;
2282 spin_unlock_bh(&ar->data_lock);
2283
2284 ath10k_pci_irq_disable(ar);
2285
2286 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
2287 * were to access copy engine while host performs copy engine reset
2288 * then it is possible for the device to confuse pci-e controller to
2289 * the point of bringing host system to a complete stop (i.e. hang).
2290 */
Michal Kaziorde013572014-05-14 16:56:16 +03002291 ath10k_pci_warm_reset_si0(ar);
Michal Kazior61c16482014-10-28 10:32:06 +01002292 ath10k_pci_warm_reset_cpu(ar);
2293 ath10k_pci_init_pipes(ar);
2294 ath10k_pci_wait_for_target_init(ar);
Michal Kaziorde013572014-05-14 16:56:16 +03002295
Michal Kazior61c16482014-10-28 10:32:06 +01002296 ath10k_pci_warm_reset_clear_lf(ar);
2297 ath10k_pci_warm_reset_ce(ar);
2298 ath10k_pci_warm_reset_cpu(ar);
2299 ath10k_pci_init_pipes(ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002300
Michal Kazior61c16482014-10-28 10:32:06 +01002301 ret = ath10k_pci_wait_for_target_init(ar);
2302 if (ret) {
2303 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
2304 return ret;
2305 }
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002306
Michal Kazior7aa7a722014-08-25 12:09:38 +02002307 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002308
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002309 return 0;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002310}
2311
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302312static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
2313{
2314 if (QCA_REV_988X(ar) || QCA_REV_6174(ar)) {
2315 return ath10k_pci_warm_reset(ar);
2316 } else if (QCA_REV_99X0(ar)) {
2317 ath10k_pci_irq_disable(ar);
2318 return ath10k_pci_qca99x0_chip_reset(ar);
2319 } else {
2320 return -ENOTSUPP;
2321 }
2322}
2323
Michal Kaziord63955b2015-01-24 12:14:49 +02002324static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
Michal Kazior0bc14d02014-10-28 10:32:07 +01002325{
2326 int i, ret;
2327 u32 val;
2328
Michal Kaziord63955b2015-01-24 12:14:49 +02002329 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002330
2331 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
2332 * It is thus preferred to use warm reset which is safer but may not be
2333 * able to recover the device from all possible fail scenarios.
2334 *
2335 * Warm reset doesn't always work on first try so attempt it a few
2336 * times before giving up.
2337 */
2338 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2339 ret = ath10k_pci_warm_reset(ar);
2340 if (ret) {
2341 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
2342 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
2343 ret);
2344 continue;
2345 }
2346
2347 /* FIXME: Sometimes copy engine doesn't recover after warm
2348 * reset. In most cases this needs cold reset. In some of these
2349 * cases the device is in such a state that a cold reset may
2350 * lock up the host.
2351 *
2352 * Reading any host interest register via copy engine is
2353 * sufficient to verify if device is capable of booting
2354 * firmware blob.
2355 */
2356 ret = ath10k_pci_init_pipes(ar);
2357 if (ret) {
2358 ath10k_warn(ar, "failed to init copy engine: %d\n",
2359 ret);
2360 continue;
2361 }
2362
2363 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
2364 &val);
2365 if (ret) {
2366 ath10k_warn(ar, "failed to poke copy engine: %d\n",
2367 ret);
2368 continue;
2369 }
2370
2371 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
2372 return 0;
2373 }
2374
2375 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
2376 ath10k_warn(ar, "refusing cold reset as requested\n");
2377 return -EPERM;
2378 }
2379
2380 ret = ath10k_pci_cold_reset(ar);
2381 if (ret) {
2382 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2383 return ret;
2384 }
2385
2386 ret = ath10k_pci_wait_for_target_init(ar);
2387 if (ret) {
2388 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2389 ret);
2390 return ret;
2391 }
2392
Michal Kaziord63955b2015-01-24 12:14:49 +02002393 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002394
2395 return 0;
2396}
2397
Michal Kaziord63955b2015-01-24 12:14:49 +02002398static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
2399{
2400 int ret;
2401
2402 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
2403
2404 /* FIXME: QCA6174 requires cold + warm reset to work. */
2405
2406 ret = ath10k_pci_cold_reset(ar);
2407 if (ret) {
2408 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2409 return ret;
2410 }
2411
2412 ret = ath10k_pci_wait_for_target_init(ar);
2413 if (ret) {
2414 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
Kalle Valo617b0f42015-10-05 17:56:35 +03002415 ret);
Michal Kaziord63955b2015-01-24 12:14:49 +02002416 return ret;
2417 }
2418
2419 ret = ath10k_pci_warm_reset(ar);
2420 if (ret) {
2421 ath10k_warn(ar, "failed to warm reset: %d\n", ret);
2422 return ret;
2423 }
2424
2425 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
2426
2427 return 0;
2428}
2429
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302430static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
2431{
2432 int ret;
2433
2434 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
2435
2436 ret = ath10k_pci_cold_reset(ar);
2437 if (ret) {
2438 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2439 return ret;
2440 }
2441
2442 ret = ath10k_pci_wait_for_target_init(ar);
2443 if (ret) {
2444 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2445 ret);
2446 return ret;
2447 }
2448
2449 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
2450
2451 return 0;
2452}
2453
Michal Kaziord63955b2015-01-24 12:14:49 +02002454static int ath10k_pci_chip_reset(struct ath10k *ar)
2455{
2456 if (QCA_REV_988X(ar))
2457 return ath10k_pci_qca988x_chip_reset(ar);
2458 else if (QCA_REV_6174(ar))
2459 return ath10k_pci_qca6174_chip_reset(ar);
Bartosz Markowskia226b512015-10-28 15:09:53 +01002460 else if (QCA_REV_9377(ar))
2461 return ath10k_pci_qca6174_chip_reset(ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302462 else if (QCA_REV_99X0(ar))
2463 return ath10k_pci_qca99x0_chip_reset(ar);
Michal Kaziord63955b2015-01-24 12:14:49 +02002464 else
2465 return -ENOTSUPP;
2466}
2467
Michal Kazior0bc14d02014-10-28 10:32:07 +01002468static int ath10k_pci_hif_power_up(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002469{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002470 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002471 int ret;
2472
Michal Kazior0bc14d02014-10-28 10:32:07 +01002473 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
2474
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002475 pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2476 &ar_pci->link_ctl);
2477 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2478 ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
2479
Michal Kazior8c5c5362013-07-16 09:38:50 +02002480 /*
2481 * Bring the target up cleanly.
2482 *
2483 * The target may be in an undefined state with an AUX-powered Target
2484 * and a Host in WoW mode. If the Host crashes, loses power, or is
2485 * restarted (without unloading the driver) then the Target is left
2486 * (aux) powered and running. On a subsequent driver load, the Target
2487 * is in an unexpected state. We try to catch that here in order to
2488 * reset the Target and retry the probe.
2489 */
Michal Kazior0bc14d02014-10-28 10:32:07 +01002490 ret = ath10k_pci_chip_reset(ar);
Michal Kazior5b2589f2013-11-08 08:01:30 +01002491 if (ret) {
Michal Kaziora2fa8802015-01-12 15:29:37 +01002492 if (ath10k_pci_has_fw_crashed(ar)) {
2493 ath10k_warn(ar, "firmware crashed during chip reset\n");
2494 ath10k_pci_fw_crashed_clear(ar);
2495 ath10k_pci_fw_crashed_dump(ar);
2496 }
2497
Michal Kazior0bc14d02014-10-28 10:32:07 +01002498 ath10k_err(ar, "failed to reset chip: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002499 goto err_sleep;
Michal Kazior5b2589f2013-11-08 08:01:30 +01002500 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002501
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002502 ret = ath10k_pci_init_pipes(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002503 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002504 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002505 goto err_sleep;
Michal Kaziorab977bd2013-11-25 14:06:26 +01002506 }
2507
Michal Kazior98563d52013-11-08 08:01:33 +01002508 ret = ath10k_pci_init_config(ar);
2509 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002510 ath10k_err(ar, "failed to setup init config: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002511 goto err_ce;
Michal Kazior98563d52013-11-08 08:01:33 +01002512 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002513
2514 ret = ath10k_pci_wake_target_cpu(ar);
2515 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002516 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002517 goto err_ce;
Michal Kazior8c5c5362013-07-16 09:38:50 +02002518 }
2519
2520 return 0;
2521
2522err_ce:
2523 ath10k_pci_ce_deinit(ar);
Michal Kazior0bc14d02014-10-28 10:32:07 +01002524
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002525err_sleep:
Michal Kazior8c5c5362013-07-16 09:38:50 +02002526 return ret;
2527}
2528
Raja Manif52f5172016-01-27 15:24:22 +05302529void ath10k_pci_hif_power_down(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002530{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002531 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
Bartosz Markowski8cc8df92013-08-02 09:58:49 +02002532
Michal Kaziorc011b282014-10-28 10:32:08 +01002533 /* Currently hif_power_up performs effectively a reset and hif_stop
2534 * resets the chip as well so there's no point in resetting here.
2535 */
Michal Kazior8c5c5362013-07-16 09:38:50 +02002536}
2537
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002538#ifdef CONFIG_PM
2539
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002540static int ath10k_pci_hif_suspend(struct ath10k *ar)
2541{
Michal Kazior77258d42015-05-18 09:38:18 +00002542 /* The grace timer can still be counting down and ar->ps_awake be true.
2543 * It is known that the device may be asleep after resuming regardless
2544 * of the SoC powersave state before suspending. Hence make sure the
2545 * device is asleep before proceeding.
2546 */
2547 ath10k_pci_sleep_sync(ar);
Michal Kazior320e14b2015-03-02 13:22:13 +01002548
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002549 return 0;
2550}
2551
2552static int ath10k_pci_hif_resume(struct ath10k *ar)
2553{
2554 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2555 struct pci_dev *pdev = ar_pci->pdev;
2556 u32 val;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002557 int ret = 0;
2558
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002559 ret = ath10k_pci_force_wake(ar);
2560 if (ret) {
2561 ath10k_err(ar, "failed to wake up target: %d\n", ret);
2562 return ret;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002563 }
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002564
Michal Kazior9ff4be92015-03-02 13:22:14 +01002565 /* Suspend/Resume resets the PCI configuration space, so we have to
2566 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
2567 * from interfering with C3 CPU state. pci_restore_state won't help
2568 * here since it only restores the first 64 bytes pci config header.
2569 */
2570 pci_read_config_dword(pdev, 0x40, &val);
2571 if ((val & 0x0000ff00) != 0)
2572 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002573
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002574 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002575}
2576#endif
2577
Kalle Valo5e3dd152013-06-12 20:52:10 +03002578static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
Michal Kazior726346f2014-02-27 18:50:04 +02002579 .tx_sg = ath10k_pci_hif_tx_sg,
Kalle Valoeef25402014-09-24 14:16:52 +03002580 .diag_read = ath10k_pci_hif_diag_read,
Yanbo Li9f65ad22014-11-25 12:24:48 +02002581 .diag_write = ath10k_pci_diag_write_mem,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2583 .start = ath10k_pci_hif_start,
2584 .stop = ath10k_pci_hif_stop,
2585 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2586 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2587 .send_complete_check = ath10k_pci_hif_send_complete_check,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
Michal Kazior8c5c5362013-07-16 09:38:50 +02002589 .power_up = ath10k_pci_hif_power_up,
2590 .power_down = ath10k_pci_hif_power_down,
Yanbo Li077a3802014-11-25 12:24:33 +02002591 .read32 = ath10k_pci_read32,
2592 .write32 = ath10k_pci_write32,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002593#ifdef CONFIG_PM
2594 .suspend = ath10k_pci_hif_suspend,
2595 .resume = ath10k_pci_hif_resume,
2596#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597};
2598
2599static void ath10k_pci_ce_tasklet(unsigned long ptr)
2600{
Michal Kazior87263e52013-08-27 13:08:01 +02002601 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002602 struct ath10k_pci *ar_pci = pipe->ar_pci;
2603
2604 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
2605}
2606
2607static void ath10k_msi_err_tasklet(unsigned long data)
2608{
2609 struct ath10k *ar = (struct ath10k *)data;
2610
Michal Kazior5c771e72014-08-22 14:23:34 +02002611 if (!ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002612 ath10k_warn(ar, "received unsolicited fw crash interrupt\n");
Michal Kazior5c771e72014-08-22 14:23:34 +02002613 return;
2614 }
2615
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002616 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002617 ath10k_pci_fw_crashed_clear(ar);
2618 ath10k_pci_fw_crashed_dump(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002619}
2620
2621/*
2622 * Handler for a per-engine interrupt on a PARTICULAR CE.
2623 * This is used in cases where each CE has a private MSI interrupt.
2624 */
2625static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
2626{
2627 struct ath10k *ar = arg;
2628 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2629 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
2630
Dan Carpentere5742672013-06-18 10:28:46 +03002631 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002632 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
2633 ce_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002634 return IRQ_HANDLED;
2635 }
2636
2637 /*
2638 * NOTE: We are able to derive ce_id from irq because we
2639 * use a one-to-one mapping for CE's 0..5.
2640 * CE's 6 & 7 do not use interrupts at all.
2641 *
2642 * This mapping must be kept in sync with the mapping
2643 * used by firmware.
2644 */
2645 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
2646 return IRQ_HANDLED;
2647}
2648
2649static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
2650{
2651 struct ath10k *ar = arg;
2652 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2653
2654 tasklet_schedule(&ar_pci->msi_fw_err);
2655 return IRQ_HANDLED;
2656}
2657
2658/*
2659 * Top-level interrupt handler for all PCI interrupts from a Target.
2660 * When a block of MSI interrupts is allocated, this top-level handler
2661 * is not used; instead, we directly call the correct sub-handler.
2662 */
2663static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2664{
2665 struct ath10k *ar = arg;
2666 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002667 int ret;
2668
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002669 ret = ath10k_pci_force_wake(ar);
2670 if (ret) {
2671 ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
2672 return IRQ_NONE;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002673 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674
2675 if (ar_pci->num_msi_intrs == 0) {
Michal Kaziore5398872013-11-25 14:06:20 +01002676 if (!ath10k_pci_irq_pending(ar))
2677 return IRQ_NONE;
2678
Michal Kazior26852182013-11-25 14:06:25 +01002679 ath10k_pci_disable_and_clear_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002680 }
2681
2682 tasklet_schedule(&ar_pci->intr_tq);
2683
2684 return IRQ_HANDLED;
2685}
2686
2687static void ath10k_pci_tasklet(unsigned long data)
2688{
2689 struct ath10k *ar = (struct ath10k *)data;
2690 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2691
Michal Kazior5c771e72014-08-22 14:23:34 +02002692 if (ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002693 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002694 ath10k_pci_fw_crashed_clear(ar);
2695 ath10k_pci_fw_crashed_dump(ar);
2696 return;
2697 }
2698
Kalle Valo5e3dd152013-06-12 20:52:10 +03002699 ath10k_ce_per_engine_service_any(ar);
2700
Michal Kazior26852182013-11-25 14:06:25 +01002701 /* Re-enable legacy irq that was disabled in the irq handler */
2702 if (ar_pci->num_msi_intrs == 0)
2703 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704}
2705
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002706static int ath10k_pci_request_irq_msix(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002707{
2708 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002709 int ret, i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002710
2711 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2712 ath10k_pci_msi_fw_handler,
2713 IRQF_SHARED, "ath10k_pci", ar);
Michal Kazior591ecdb2013-07-31 10:55:15 +02002714 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002715 ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n",
Michal Kazior591ecdb2013-07-31 10:55:15 +02002716 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717 return ret;
Michal Kazior591ecdb2013-07-31 10:55:15 +02002718 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002719
2720 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2721 ret = request_irq(ar_pci->pdev->irq + i,
2722 ath10k_pci_per_engine_handler,
2723 IRQF_SHARED, "ath10k_pci", ar);
2724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002725 ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002726 ar_pci->pdev->irq + i, ret);
2727
Michal Kazior87b14232013-06-26 08:50:50 +02002728 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2729 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002730
Michal Kazior87b14232013-06-26 08:50:50 +02002731 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002732 return ret;
2733 }
2734 }
2735
Kalle Valo5e3dd152013-06-12 20:52:10 +03002736 return 0;
2737}
2738
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002739static int ath10k_pci_request_irq_msi(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002740{
2741 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2742 int ret;
2743
2744 ret = request_irq(ar_pci->pdev->irq,
2745 ath10k_pci_interrupt_handler,
2746 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002747 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002748 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002749 ar_pci->pdev->irq, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750 return ret;
Kalle Valof3782742013-10-17 11:36:15 +03002751 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002752
Kalle Valo5e3dd152013-06-12 20:52:10 +03002753 return 0;
2754}
2755
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002756static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757{
2758 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002760
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002761 ret = request_irq(ar_pci->pdev->irq,
2762 ath10k_pci_interrupt_handler,
2763 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002765 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002766 ar_pci->pdev->irq, ret);
Kalle Valof3782742013-10-17 11:36:15 +03002767 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002768 }
2769
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002770 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771}
2772
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002773static int ath10k_pci_request_irq(struct ath10k *ar)
2774{
2775 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2776
2777 switch (ar_pci->num_msi_intrs) {
2778 case 0:
2779 return ath10k_pci_request_irq_legacy(ar);
2780 case 1:
2781 return ath10k_pci_request_irq_msi(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002782 default:
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002783 return ath10k_pci_request_irq_msix(ar);
2784 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002785}
2786
2787static void ath10k_pci_free_irq(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002788{
2789 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2790 int i;
2791
2792 /* There's at least one interrupt irregardless whether its legacy INTR
2793 * or MSI or MSI-X */
2794 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2795 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002796}
2797
Raja Manif52f5172016-01-27 15:24:22 +05302798void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002799{
2800 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2801 int i;
2802
2803 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2804 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2805 (unsigned long)ar);
2806
2807 for (i = 0; i < CE_COUNT; i++) {
2808 ar_pci->pipe_info[i].ar_pci = ar_pci;
2809 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2810 (unsigned long)&ar_pci->pipe_info[i]);
2811 }
2812}
2813
2814static int ath10k_pci_init_irq(struct ath10k *ar)
2815{
2816 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2817 int ret;
2818
2819 ath10k_pci_init_irq_tasklets(ar);
2820
Michal Kazior403d6272014-08-22 14:23:31 +02002821 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002822 ath10k_info(ar, "limiting irq mode to: %d\n",
2823 ath10k_pci_irq_mode);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002824
2825 /* Try MSI-X */
Michal Kazior0edf2572014-08-07 11:03:29 +02002826 if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) {
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002827 ar_pci->num_msi_intrs = MSI_ASSIGN_CE_MAX + 1;
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002828 ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs,
Kalle Valo5b07e072014-09-14 12:50:06 +03002829 ar_pci->num_msi_intrs);
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002830 if (ret > 0)
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002831 return 0;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002832
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002833 /* fall-through */
2834 }
2835
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002836 /* Try MSI */
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002837 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
2838 ar_pci->num_msi_intrs = 1;
2839 ret = pci_enable_msi(ar_pci->pdev);
2840 if (ret == 0)
2841 return 0;
2842
2843 /* fall-through */
2844 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002845
2846 /* Try legacy irq
2847 *
2848 * A potential race occurs here: The CORE_BASE write
2849 * depends on target correctly decoding AXI address but
2850 * host won't know when target writes BAR to CORE_CTRL.
2851 * This write might get lost if target has NOT written BAR.
2852 * For now, fix the race by repeating the write in below
2853 * synchronization checking. */
2854 ar_pci->num_msi_intrs = 0;
2855
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002856 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2857 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002858
2859 return 0;
2860}
2861
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002862static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002863{
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002864 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2865 0);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002866}
2867
2868static int ath10k_pci_deinit_irq(struct ath10k *ar)
2869{
2870 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2871
2872 switch (ar_pci->num_msi_intrs) {
2873 case 0:
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002874 ath10k_pci_deinit_irq_legacy(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002875 break;
Alexander Gordeevbb8b6212014-02-13 17:50:01 +02002876 default:
2877 pci_disable_msi(ar_pci->pdev);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002878 break;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002879 }
2880
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002881 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002882}
2883
Raja Manif52f5172016-01-27 15:24:22 +05302884int ath10k_pci_wait_for_target_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002885{
2886 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo0399eca2014-03-28 09:32:21 +02002887 unsigned long timeout;
Kalle Valo0399eca2014-03-28 09:32:21 +02002888 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889
Michal Kazior7aa7a722014-08-25 12:09:38 +02002890 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002891
Kalle Valo0399eca2014-03-28 09:32:21 +02002892 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2893
2894 do {
2895 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2896
Michal Kazior7aa7a722014-08-25 12:09:38 +02002897 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2898 val);
Kalle Valo50f87a62014-03-28 09:32:52 +02002899
Kalle Valo0399eca2014-03-28 09:32:21 +02002900 /* target should never return this */
2901 if (val == 0xffffffff)
2902 continue;
2903
Michal Kazior7710cd22014-04-23 19:30:04 +03002904 /* the device has crashed so don't bother trying anymore */
2905 if (val & FW_IND_EVENT_PENDING)
2906 break;
2907
Kalle Valo0399eca2014-03-28 09:32:21 +02002908 if (val & FW_IND_INITIALIZED)
2909 break;
2910
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911 if (ar_pci->num_msi_intrs == 0)
2912 /* Fix potential race by repeating CORE_BASE writes */
Michal Kaziora4282492014-10-20 14:14:37 +02002913 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002914
Kalle Valo0399eca2014-03-28 09:32:21 +02002915 mdelay(10);
2916 } while (time_before(jiffies, timeout));
2917
Michal Kaziora4282492014-10-20 14:14:37 +02002918 ath10k_pci_disable_and_clear_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02002919 ath10k_pci_irq_msi_fw_mask(ar);
Michal Kaziora4282492014-10-20 14:14:37 +02002920
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002921 if (val == 0xffffffff) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002922 ath10k_err(ar, "failed to read device register, device is gone\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002923 return -EIO;
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002924 }
2925
Michal Kazior7710cd22014-04-23 19:30:04 +03002926 if (val & FW_IND_EVENT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002927 ath10k_warn(ar, "device has crashed during init\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002928 return -ECOMM;
Michal Kazior7710cd22014-04-23 19:30:04 +03002929 }
2930
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002931 if (!(val & FW_IND_INITIALIZED)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002932 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
Kalle Valo0399eca2014-03-28 09:32:21 +02002933 val);
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002934 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002935 }
2936
Michal Kazior7aa7a722014-08-25 12:09:38 +02002937 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002938 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002939}
2940
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002941static int ath10k_pci_cold_reset(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002943 u32 val;
2944
Michal Kazior7aa7a722014-08-25 12:09:38 +02002945 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002946
Ben Greearf51dbe72014-09-29 14:41:46 +03002947 spin_lock_bh(&ar->data_lock);
2948
2949 ar->stats.fw_cold_reset_counter++;
2950
2951 spin_unlock_bh(&ar->data_lock);
2952
Kalle Valo5e3dd152013-06-12 20:52:10 +03002953 /* Put Target, including PCIe, into RESET. */
Kalle Valoe479ed42013-09-01 10:01:53 +03002954 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955 val |= 1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002956 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002957
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302958 /* After writing into SOC_GLOBAL_RESET to put device into
2959 * reset and pulling out of reset pcie may not be stable
2960 * for any immediate pcie register access and cause bus error,
2961 * add delay before any pcie access request to fix this issue.
2962 */
2963 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002964
2965 /* Pull Target, including PCIe, out of RESET. */
2966 val &= ~1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002967 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302969 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002970
Michal Kazior7aa7a722014-08-25 12:09:38 +02002971 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02002972
Michal Kazior5b2589f2013-11-08 08:01:30 +01002973 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002974}
2975
Michal Kazior2986e3e2014-08-07 11:03:30 +02002976static int ath10k_pci_claim(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002977{
Michal Kazior2986e3e2014-08-07 11:03:30 +02002978 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2979 struct pci_dev *pdev = ar_pci->pdev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002980 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002981
2982 pci_set_drvdata(pdev, ar);
2983
Kalle Valo5e3dd152013-06-12 20:52:10 +03002984 ret = pci_enable_device(pdev);
2985 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002986 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002987 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002988 }
2989
Kalle Valo5e3dd152013-06-12 20:52:10 +03002990 ret = pci_request_region(pdev, BAR_NUM, "ath");
2991 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002992 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
Michal Kazior2986e3e2014-08-07 11:03:30 +02002993 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002994 goto err_device;
2995 }
2996
Michal Kazior2986e3e2014-08-07 11:03:30 +02002997 /* Target expects 32 bit DMA. Enforce it. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002998 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003000 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001 goto err_region;
3002 }
3003
3004 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
3005 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003006 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
Michal Kazior2986e3e2014-08-07 11:03:30 +02003007 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003008 goto err_region;
3009 }
3010
Kalle Valo5e3dd152013-06-12 20:52:10 +03003011 pci_set_master(pdev);
3012
Kalle Valo5e3dd152013-06-12 20:52:10 +03003013 /* Arrange for access to Target SoC registers. */
Michal Kazioraeae5b42015-06-15 14:46:42 +03003014 ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003015 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
3016 if (!ar_pci->mem) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003017 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003018 ret = -EIO;
3019 goto err_master;
3020 }
3021
Michal Kazior7aa7a722014-08-25 12:09:38 +02003022 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003023 return 0;
3024
3025err_master:
3026 pci_clear_master(pdev);
3027
3028err_region:
3029 pci_release_region(pdev, BAR_NUM);
3030
3031err_device:
3032 pci_disable_device(pdev);
3033
3034 return ret;
3035}
3036
3037static void ath10k_pci_release(struct ath10k *ar)
3038{
3039 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
3040 struct pci_dev *pdev = ar_pci->pdev;
3041
3042 pci_iounmap(pdev, ar_pci->mem);
3043 pci_release_region(pdev, BAR_NUM);
3044 pci_clear_master(pdev);
3045 pci_disable_device(pdev);
3046}
3047
Michal Kazior7505f7c2014-12-02 10:55:54 +02003048static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
3049{
3050 const struct ath10k_pci_supp_chip *supp_chip;
3051 int i;
3052 u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
3053
3054 for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
3055 supp_chip = &ath10k_pci_supp_chips[i];
3056
3057 if (supp_chip->dev_id == dev_id &&
3058 supp_chip->rev_id == rev_id)
3059 return true;
3060 }
3061
3062 return false;
3063}
3064
Raja Mani90188f82016-01-27 15:24:24 +05303065int ath10k_pci_setup_resource(struct ath10k *ar)
3066{
3067 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
3068 int ret;
3069
3070 spin_lock_init(&ar_pci->ce_lock);
3071 spin_lock_init(&ar_pci->ps_lock);
3072
3073 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
3074 (unsigned long)ar);
3075
3076 if (QCA_REV_6174(ar))
3077 ath10k_pci_override_ce_config(ar);
3078
3079 ret = ath10k_pci_alloc_pipes(ar);
3080 if (ret) {
3081 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
3082 ret);
3083 return ret;
3084 }
3085
3086 return 0;
3087}
3088
3089void ath10k_pci_release_resource(struct ath10k *ar)
3090{
3091 ath10k_pci_kill_tasklet(ar);
3092 ath10k_pci_ce_deinit(ar);
3093 ath10k_pci_free_pipes(ar);
3094}
3095
Raja Mani4ddb3292016-01-27 15:24:23 +05303096static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
3097 .read32 = ath10k_bus_pci_read32,
3098 .write32 = ath10k_bus_pci_write32,
3099 .get_num_banks = ath10k_pci_get_num_banks,
3100};
3101
Kalle Valo5e3dd152013-06-12 20:52:10 +03003102static int ath10k_pci_probe(struct pci_dev *pdev,
3103 const struct pci_device_id *pci_dev)
3104{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003105 int ret = 0;
3106 struct ath10k *ar;
3107 struct ath10k_pci *ar_pci;
Michal Kaziord63955b2015-01-24 12:14:49 +02003108 enum ath10k_hw_rev hw_rev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02003109 u32 chip_id;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003110 bool pci_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003111
Michal Kaziord63955b2015-01-24 12:14:49 +02003112 switch (pci_dev->device) {
3113 case QCA988X_2_0_DEVICE_ID:
3114 hw_rev = ATH10K_HW_QCA988X;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003115 pci_ps = false;
Michal Kaziord63955b2015-01-24 12:14:49 +02003116 break;
Michal Kazior36582e52015-08-13 14:32:26 +02003117 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02003118 case QCA6174_2_1_DEVICE_ID:
3119 hw_rev = ATH10K_HW_QCA6174;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003120 pci_ps = true;
Michal Kaziord63955b2015-01-24 12:14:49 +02003121 break;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303122 case QCA99X0_2_0_DEVICE_ID:
3123 hw_rev = ATH10K_HW_QCA99X0;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003124 pci_ps = false;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303125 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01003126 case QCA9377_1_0_DEVICE_ID:
3127 hw_rev = ATH10K_HW_QCA9377;
3128 pci_ps = true;
3129 break;
Michal Kaziord63955b2015-01-24 12:14:49 +02003130 default:
3131 WARN_ON(1);
3132 return -ENOTSUPP;
3133 }
3134
3135 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
3136 hw_rev, &ath10k_pci_hif_ops);
Michal Kaziore7b54192014-08-07 11:03:27 +02003137 if (!ar) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003138 dev_err(&pdev->dev, "failed to allocate core\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139 return -ENOMEM;
Michal Kaziore7b54192014-08-07 11:03:27 +02003140 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003141
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003142 ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
3143 pdev->vendor, pdev->device,
3144 pdev->subsystem_vendor, pdev->subsystem_device);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003145
Michal Kaziore7b54192014-08-07 11:03:27 +02003146 ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003147 ar_pci->pdev = pdev;
3148 ar_pci->dev = &pdev->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003149 ar_pci->ar = ar;
Michal Kazior36582e52015-08-13 14:32:26 +02003150 ar->dev_id = pci_dev->device;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003151 ar_pci->pci_ps = pci_ps;
Raja Mani4ddb3292016-01-27 15:24:23 +05303152 ar_pci->bus_ops = &ath10k_pci_bus_ops;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003153
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003154 ar->id.vendor = pdev->vendor;
3155 ar->id.device = pdev->device;
3156 ar->id.subsystem_vendor = pdev->subsystem_vendor;
3157 ar->id.subsystem_device = pdev->subsystem_device;
Michal Kaziorde57e2c2015-04-17 09:19:17 +00003158
Michal Kazior77258d42015-05-18 09:38:18 +00003159 setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
3160 (unsigned long)ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003161
Raja Mani90188f82016-01-27 15:24:24 +05303162 ret = ath10k_pci_setup_resource(ar);
3163 if (ret) {
3164 ath10k_err(ar, "failed to setup resource: %d\n", ret);
3165 goto err_core_destroy;
3166 }
3167
Michal Kazior2986e3e2014-08-07 11:03:30 +02003168 ret = ath10k_pci_claim(ar);
Kalle Valoe01ae682013-09-01 11:22:14 +03003169 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003170 ath10k_err(ar, "failed to claim device: %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303171 goto err_free_pipes;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02003172 }
3173
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02003174 ret = ath10k_pci_force_wake(ar);
3175 if (ret) {
3176 ath10k_warn(ar, "failed to wake up device : %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303177 goto err_sleep;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003178 }
3179
Rajkumar Manoharanaa538ac2015-12-16 16:52:19 +02003180 ath10k_pci_ce_deinit(ar);
3181 ath10k_pci_irq_disable(ar);
3182
Michal Kazior403d6272014-08-22 14:23:31 +02003183 ret = ath10k_pci_init_irq(ar);
3184 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003185 ath10k_err(ar, "failed to init irqs: %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303186 goto err_sleep;
Michal Kazior403d6272014-08-22 14:23:31 +02003187 }
3188
Michal Kazior7aa7a722014-08-25 12:09:38 +02003189 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
Michal Kazior403d6272014-08-22 14:23:31 +02003190 ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs,
3191 ath10k_pci_irq_mode, ath10k_pci_reset_mode);
3192
Michal Kazior5c771e72014-08-22 14:23:34 +02003193 ret = ath10k_pci_request_irq(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003194 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003195 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
Michal Kazior403d6272014-08-22 14:23:31 +02003196 goto err_deinit_irq;
3197 }
3198
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003199 ret = ath10k_pci_chip_reset(ar);
3200 if (ret) {
3201 ath10k_err(ar, "failed to reset chip: %d\n", ret);
3202 goto err_free_irq;
3203 }
3204
3205 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
3206 if (chip_id == 0xffffffff) {
3207 ath10k_err(ar, "failed to get chip id\n");
3208 goto err_free_irq;
3209 }
3210
3211 if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
3212 ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
3213 pdev->device, chip_id);
Michal Kaziord9585a92015-04-10 13:01:27 +00003214 goto err_free_irq;
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003215 }
3216
Kalle Valoe01ae682013-09-01 11:22:14 +03003217 ret = ath10k_core_register(ar, chip_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003218 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003219 ath10k_err(ar, "failed to register driver core: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02003220 goto err_free_irq;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003221 }
3222
3223 return 0;
3224
Michal Kazior5c771e72014-08-22 14:23:34 +02003225err_free_irq:
3226 ath10k_pci_free_irq(ar);
Michal Kazior21396272014-08-28 10:24:40 +02003227 ath10k_pci_kill_tasklet(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003228
Michal Kazior403d6272014-08-22 14:23:31 +02003229err_deinit_irq:
3230 ath10k_pci_deinit_irq(ar);
3231
Michal Kaziorc0c378f2014-08-07 11:03:28 +02003232err_sleep:
Michal Kazior0bcbbe62015-05-29 07:35:24 +02003233 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003234 ath10k_pci_release(ar);
3235
Raja Mani90188f82016-01-27 15:24:24 +05303236err_free_pipes:
3237 ath10k_pci_free_pipes(ar);
3238
Michal Kaziore7b54192014-08-07 11:03:27 +02003239err_core_destroy:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003241
3242 return ret;
3243}
3244
3245static void ath10k_pci_remove(struct pci_dev *pdev)
3246{
3247 struct ath10k *ar = pci_get_drvdata(pdev);
3248 struct ath10k_pci *ar_pci;
3249
Michal Kazior7aa7a722014-08-25 12:09:38 +02003250 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003251
3252 if (!ar)
3253 return;
3254
3255 ar_pci = ath10k_pci_priv(ar);
3256
3257 if (!ar_pci)
3258 return;
3259
Kalle Valo5e3dd152013-06-12 20:52:10 +03003260 ath10k_core_unregister(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003261 ath10k_pci_free_irq(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003262 ath10k_pci_deinit_irq(ar);
Raja Mani90188f82016-01-27 15:24:24 +05303263 ath10k_pci_release_resource(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00003264 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003265 ath10k_pci_release(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003266 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267}
3268
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
3270
3271static struct pci_driver ath10k_pci_driver = {
3272 .name = "ath10k_pci",
3273 .id_table = ath10k_pci_id_table,
3274 .probe = ath10k_pci_probe,
3275 .remove = ath10k_pci_remove,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003276};
3277
3278static int __init ath10k_pci_init(void)
3279{
3280 int ret;
3281
3282 ret = pci_register_driver(&ath10k_pci_driver);
3283 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003284 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
3285 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003286
Raja Mani0b523ce2016-01-27 15:24:25 +05303287 ret = ath10k_ahb_init();
3288 if (ret)
3289 printk(KERN_ERR "ahb init failed: %d\n", ret);
3290
Kalle Valo5e3dd152013-06-12 20:52:10 +03003291 return ret;
3292}
3293module_init(ath10k_pci_init);
3294
3295static void __exit ath10k_pci_exit(void)
3296{
3297 pci_unregister_driver(&ath10k_pci_driver);
Raja Mani0b523ce2016-01-27 15:24:25 +05303298 ath10k_ahb_exit();
Kalle Valo5e3dd152013-06-12 20:52:10 +03003299}
3300
3301module_exit(ath10k_pci_exit);
3302
3303MODULE_AUTHOR("Qualcomm Atheros");
3304MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
3305MODULE_LICENSE("Dual BSD/GPL");
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003306
3307/* QCA988x 2.0 firmware files */
Bartosz Markowski8026cae2014-10-06 14:16:41 +02003308MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
3309MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
3310MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003311MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Kalle Valo53513c32015-03-25 13:12:42 +02003312MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003313MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003314MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003315
3316/* QCA6174 2.1 firmware files */
3317MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003318MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003319MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003320MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003321
3322/* QCA6174 3.1 firmware files */
3323MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003324MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003325MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003326MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowskia226b512015-10-28 15:09:53 +01003327
3328/* QCA9377 1.0 firmware files */
3329MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3330MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);