blob: ee925c618535f464a213b59d35a0a4c8688da59f [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 Kaziord7fb47f2013-11-08 08:01:26 +010097static int ath10k_pci_wait_for_target_init(struct ath10k *ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +010098static int ath10k_pci_init_irq(struct ath10k *ar);
99static int ath10k_pci_deinit_irq(struct ath10k *ar);
100static int ath10k_pci_request_irq(struct ath10k *ar);
101static void ath10k_pci_free_irq(struct ath10k *ar);
Michal Kazior85622cd2013-11-25 14:06:22 +0100102static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
103 struct ath10k_ce_pipe *rx_pipe,
104 struct bmi_xfer *xfer);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +0530105static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar);
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530106static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530107static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530108static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
109static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530110static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530111static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300112
Ryan Hsu2727a742015-11-05 18:44:27 -0800113static struct ce_attr host_ce_config_wlan[] = {
Kalle Valo48e9c222013-09-01 10:01:32 +0300114 /* CE0: host->target HTC control and raw streams */
115 {
116 .flags = CE_ATTR_FLAGS,
117 .src_nentries = 16,
118 .src_sz_max = 256,
119 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530120 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300121 },
122
123 /* CE1: target->host HTT + HTC control */
124 {
125 .flags = CE_ATTR_FLAGS,
126 .src_nentries = 0,
Michal Kazior63838642015-02-09 15:04:55 +0100127 .src_sz_max = 2048,
Kalle Valo48e9c222013-09-01 10:01:32 +0300128 .dest_nentries = 512,
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530129 .recv_cb = ath10k_pci_htt_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300130 },
131
132 /* CE2: target->host WMI */
133 {
134 .flags = CE_ATTR_FLAGS,
135 .src_nentries = 0,
136 .src_sz_max = 2048,
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200137 .dest_nentries = 128,
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530138 .recv_cb = ath10k_pci_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300139 },
140
141 /* CE3: host->target WMI */
142 {
143 .flags = CE_ATTR_FLAGS,
144 .src_nentries = 32,
145 .src_sz_max = 2048,
146 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530147 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300148 },
149
150 /* CE4: host->target HTT */
151 {
152 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
153 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
154 .src_sz_max = 256,
155 .dest_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530156 .send_cb = ath10k_pci_htt_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300157 },
158
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530159 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valo48e9c222013-09-01 10:01:32 +0300160 {
161 .flags = CE_ATTR_FLAGS,
162 .src_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530163 .src_sz_max = 512,
164 .dest_nentries = 512,
165 .recv_cb = ath10k_pci_htt_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300166 },
167
168 /* CE6: target autonomous hif_memcpy */
169 {
170 .flags = CE_ATTR_FLAGS,
171 .src_nentries = 0,
172 .src_sz_max = 0,
173 .dest_nentries = 0,
174 },
175
176 /* CE7: ce_diag, the Diagnostic Window */
177 {
178 .flags = CE_ATTR_FLAGS,
179 .src_nentries = 2,
180 .src_sz_max = DIAG_TRANSFER_LIMIT,
181 .dest_nentries = 2,
182 },
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530183
184 /* CE8: target->host pktlog */
185 {
186 .flags = CE_ATTR_FLAGS,
187 .src_nentries = 0,
188 .src_sz_max = 2048,
189 .dest_nentries = 128,
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530190 .recv_cb = ath10k_pci_pktlog_rx_cb,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530191 },
192
193 /* CE9 target autonomous qcache memcpy */
194 {
195 .flags = CE_ATTR_FLAGS,
196 .src_nentries = 0,
197 .src_sz_max = 0,
198 .dest_nentries = 0,
199 },
200
201 /* CE10: target autonomous hif memcpy */
202 {
203 .flags = CE_ATTR_FLAGS,
204 .src_nentries = 0,
205 .src_sz_max = 0,
206 .dest_nentries = 0,
207 },
208
209 /* CE11: target autonomous hif memcpy */
210 {
211 .flags = CE_ATTR_FLAGS,
212 .src_nentries = 0,
213 .src_sz_max = 0,
214 .dest_nentries = 0,
215 },
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216};
217
218/* Target firmware's Copy Engine configuration. */
Ryan Hsu2727a742015-11-05 18:44:27 -0800219static struct ce_pipe_config target_ce_config_wlan[] = {
Kalle Valod88effb2013-09-01 10:01:39 +0300220 /* CE0: host->target HTC control and raw streams */
221 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300222 .pipenum = __cpu_to_le32(0),
223 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
224 .nentries = __cpu_to_le32(32),
225 .nbytes_max = __cpu_to_le32(256),
226 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
227 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300228 },
229
230 /* CE1: target->host HTT + HTC control */
231 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300232 .pipenum = __cpu_to_le32(1),
233 .pipedir = __cpu_to_le32(PIPEDIR_IN),
234 .nentries = __cpu_to_le32(32),
Michal Kazior63838642015-02-09 15:04:55 +0100235 .nbytes_max = __cpu_to_le32(2048),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300236 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
237 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300238 },
239
240 /* CE2: target->host WMI */
241 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300242 .pipenum = __cpu_to_le32(2),
243 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200244 .nentries = __cpu_to_le32(64),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300245 .nbytes_max = __cpu_to_le32(2048),
246 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
247 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300248 },
249
250 /* CE3: host->target WMI */
251 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300252 .pipenum = __cpu_to_le32(3),
253 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
254 .nentries = __cpu_to_le32(32),
255 .nbytes_max = __cpu_to_le32(2048),
256 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
257 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300258 },
259
260 /* CE4: host->target HTT */
261 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300262 .pipenum = __cpu_to_le32(4),
263 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
264 .nentries = __cpu_to_le32(256),
265 .nbytes_max = __cpu_to_le32(256),
266 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
267 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300268 },
269
Kalle Valo5e3dd152013-06-12 20:52:10 +0300270 /* NB: 50% of src nentries, since tx has 2 frags */
Kalle Valod88effb2013-09-01 10:01:39 +0300271
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530272 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valod88effb2013-09-01 10:01:39 +0300273 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300274 .pipenum = __cpu_to_le32(5),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530275 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300276 .nentries = __cpu_to_le32(32),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530277 .nbytes_max = __cpu_to_le32(512),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300278 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
279 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300280 },
281
282 /* CE6: Reserved for target autonomous hif_memcpy */
283 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300284 .pipenum = __cpu_to_le32(6),
285 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
286 .nentries = __cpu_to_le32(32),
287 .nbytes_max = __cpu_to_le32(4096),
288 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
289 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300290 },
291
Kalle Valo5e3dd152013-06-12 20:52:10 +0300292 /* CE7 used only by Host */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530293 {
294 .pipenum = __cpu_to_le32(7),
295 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
296 .nentries = __cpu_to_le32(0),
297 .nbytes_max = __cpu_to_le32(0),
298 .flags = __cpu_to_le32(0),
299 .reserved = __cpu_to_le32(0),
300 },
301
302 /* CE8 target->host packtlog */
303 {
304 .pipenum = __cpu_to_le32(8),
305 .pipedir = __cpu_to_le32(PIPEDIR_IN),
306 .nentries = __cpu_to_le32(64),
307 .nbytes_max = __cpu_to_le32(2048),
308 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
309 .reserved = __cpu_to_le32(0),
310 },
311
312 /* CE9 target autonomous qcache memcpy */
313 {
314 .pipenum = __cpu_to_le32(9),
315 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
316 .nentries = __cpu_to_le32(32),
317 .nbytes_max = __cpu_to_le32(2048),
318 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
319 .reserved = __cpu_to_le32(0),
320 },
321
322 /* It not necessary to send target wlan configuration for CE10 & CE11
323 * as these CEs are not actively used in target.
324 */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300325};
326
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300327/*
328 * Map from service/endpoint to Copy Engine.
329 * This table is derived from the CE_PCI TABLE, above.
330 * It is passed to the Target at startup for use by firmware.
331 */
Ryan Hsu2727a742015-11-05 18:44:27 -0800332static struct service_to_pipe target_service_to_ce_map_wlan[] = {
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300333 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300334 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
335 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
336 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300337 },
338 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300339 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
340 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
341 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300342 },
343 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300344 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
345 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
346 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300347 },
348 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300349 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
350 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
351 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300352 },
353 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300354 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
355 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
356 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300357 },
358 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300359 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
360 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
361 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300362 },
363 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300364 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
365 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
366 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300367 },
368 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300369 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
370 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
371 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300372 },
373 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300374 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
375 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
376 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300377 },
378 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300379 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
380 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
381 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300382 },
383 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300384 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
385 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
386 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300387 },
388 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300389 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
390 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
391 __cpu_to_le32(1),
392 },
393 { /* not used */
394 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
395 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
396 __cpu_to_le32(0),
397 },
398 { /* not used */
399 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
400 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
401 __cpu_to_le32(1),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300402 },
403 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300404 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
405 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
406 __cpu_to_le32(4),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300407 },
408 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300409 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
410 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530411 __cpu_to_le32(5),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300412 },
413
414 /* (Additions here) */
415
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300416 { /* must be last */
417 __cpu_to_le32(0),
418 __cpu_to_le32(0),
419 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300420 },
421};
422
Michal Kazior77258d42015-05-18 09:38:18 +0000423static bool ath10k_pci_is_awake(struct ath10k *ar)
424{
425 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
426 u32 val = ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
427 RTC_STATE_ADDRESS);
428
429 return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
430}
431
432static void __ath10k_pci_wake(struct ath10k *ar)
433{
434 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
435
436 lockdep_assert_held(&ar_pci->ps_lock);
437
438 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake reg refcount %lu awake %d\n",
439 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
440
441 iowrite32(PCIE_SOC_WAKE_V_MASK,
442 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
443 PCIE_SOC_WAKE_ADDRESS);
444}
445
446static void __ath10k_pci_sleep(struct ath10k *ar)
447{
448 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
449
450 lockdep_assert_held(&ar_pci->ps_lock);
451
452 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep reg refcount %lu awake %d\n",
453 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
454
455 iowrite32(PCIE_SOC_WAKE_RESET,
456 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
457 PCIE_SOC_WAKE_ADDRESS);
458 ar_pci->ps_awake = false;
459}
460
461static int ath10k_pci_wake_wait(struct ath10k *ar)
462{
463 int tot_delay = 0;
464 int curr_delay = 5;
465
466 while (tot_delay < PCIE_WAKE_TIMEOUT) {
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300467 if (ath10k_pci_is_awake(ar)) {
468 if (tot_delay > PCIE_WAKE_LATE_US)
469 ath10k_warn(ar, "device wakeup took %d ms which is unusally long, otherwise it works normally.\n",
470 tot_delay / 1000);
Michal Kazior77258d42015-05-18 09:38:18 +0000471 return 0;
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300472 }
Michal Kazior77258d42015-05-18 09:38:18 +0000473
474 udelay(curr_delay);
475 tot_delay += curr_delay;
476
477 if (curr_delay < 50)
478 curr_delay += 5;
479 }
480
481 return -ETIMEDOUT;
482}
483
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300484static int ath10k_pci_force_wake(struct ath10k *ar)
485{
486 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
487 unsigned long flags;
488 int ret = 0;
489
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +0200490 if (ar_pci->pci_ps)
491 return ret;
492
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300493 spin_lock_irqsave(&ar_pci->ps_lock, flags);
494
495 if (!ar_pci->ps_awake) {
496 iowrite32(PCIE_SOC_WAKE_V_MASK,
497 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
498 PCIE_SOC_WAKE_ADDRESS);
499
500 ret = ath10k_pci_wake_wait(ar);
501 if (ret == 0)
502 ar_pci->ps_awake = true;
503 }
504
505 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
506
507 return ret;
508}
509
510static void ath10k_pci_force_sleep(struct ath10k *ar)
511{
512 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
513 unsigned long flags;
514
515 spin_lock_irqsave(&ar_pci->ps_lock, flags);
516
517 iowrite32(PCIE_SOC_WAKE_RESET,
518 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
519 PCIE_SOC_WAKE_ADDRESS);
520 ar_pci->ps_awake = false;
521
522 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
523}
524
Michal Kazior77258d42015-05-18 09:38:18 +0000525static int ath10k_pci_wake(struct ath10k *ar)
526{
527 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
528 unsigned long flags;
529 int ret = 0;
530
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300531 if (ar_pci->pci_ps == 0)
532 return ret;
533
Michal Kazior77258d42015-05-18 09:38:18 +0000534 spin_lock_irqsave(&ar_pci->ps_lock, flags);
535
536 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake refcount %lu awake %d\n",
537 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
538
539 /* This function can be called very frequently. To avoid excessive
540 * CPU stalls for MMIO reads use a cache var to hold the device state.
541 */
542 if (!ar_pci->ps_awake) {
543 __ath10k_pci_wake(ar);
544
545 ret = ath10k_pci_wake_wait(ar);
546 if (ret == 0)
547 ar_pci->ps_awake = true;
548 }
549
550 if (ret == 0) {
551 ar_pci->ps_wake_refcount++;
552 WARN_ON(ar_pci->ps_wake_refcount == 0);
553 }
554
555 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
556
557 return ret;
558}
559
560static void ath10k_pci_sleep(struct ath10k *ar)
561{
562 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
563 unsigned long flags;
564
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300565 if (ar_pci->pci_ps == 0)
566 return;
567
Michal Kazior77258d42015-05-18 09:38:18 +0000568 spin_lock_irqsave(&ar_pci->ps_lock, flags);
569
570 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep refcount %lu awake %d\n",
571 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
572
573 if (WARN_ON(ar_pci->ps_wake_refcount == 0))
574 goto skip;
575
576 ar_pci->ps_wake_refcount--;
577
578 mod_timer(&ar_pci->ps_timer, jiffies +
579 msecs_to_jiffies(ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC));
580
581skip:
582 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
583}
584
585static void ath10k_pci_ps_timer(unsigned long ptr)
586{
587 struct ath10k *ar = (void *)ptr;
588 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
589 unsigned long flags;
590
591 spin_lock_irqsave(&ar_pci->ps_lock, flags);
592
593 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps timer refcount %lu awake %d\n",
594 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
595
596 if (ar_pci->ps_wake_refcount > 0)
597 goto skip;
598
599 __ath10k_pci_sleep(ar);
600
601skip:
602 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
603}
604
605static void ath10k_pci_sleep_sync(struct ath10k *ar)
606{
607 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
608 unsigned long flags;
609
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300610 if (ar_pci->pci_ps == 0) {
611 ath10k_pci_force_sleep(ar);
612 return;
613 }
614
Michal Kazior77258d42015-05-18 09:38:18 +0000615 del_timer_sync(&ar_pci->ps_timer);
616
617 spin_lock_irqsave(&ar_pci->ps_lock, flags);
618 WARN_ON(ar_pci->ps_wake_refcount > 0);
619 __ath10k_pci_sleep(ar);
620 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
621}
622
623void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value)
624{
625 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
626 int ret;
627
Michal Kazioraeae5b42015-06-15 14:46:42 +0300628 if (unlikely(offset + sizeof(value) > ar_pci->mem_len)) {
629 ath10k_warn(ar, "refusing to write mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
630 offset, offset + sizeof(value), ar_pci->mem_len);
631 return;
632 }
633
Michal Kazior77258d42015-05-18 09:38:18 +0000634 ret = ath10k_pci_wake(ar);
635 if (ret) {
636 ath10k_warn(ar, "failed to wake target for write32 of 0x%08x at 0x%08x: %d\n",
637 value, offset, ret);
638 return;
639 }
640
641 iowrite32(value, ar_pci->mem + offset);
642 ath10k_pci_sleep(ar);
643}
644
645u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
646{
647 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
648 u32 val;
649 int ret;
650
Michal Kazioraeae5b42015-06-15 14:46:42 +0300651 if (unlikely(offset + sizeof(val) > ar_pci->mem_len)) {
652 ath10k_warn(ar, "refusing to read mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
653 offset, offset + sizeof(val), ar_pci->mem_len);
654 return 0;
655 }
656
Michal Kazior77258d42015-05-18 09:38:18 +0000657 ret = ath10k_pci_wake(ar);
658 if (ret) {
659 ath10k_warn(ar, "failed to wake target for read32 at 0x%08x: %d\n",
660 offset, ret);
661 return 0xffffffff;
662 }
663
664 val = ioread32(ar_pci->mem + offset);
665 ath10k_pci_sleep(ar);
666
667 return val;
668}
669
670u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
671{
672 return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
673}
674
675void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
676{
677 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
678}
679
680u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
681{
682 return ath10k_pci_read32(ar, PCIE_LOCAL_BASE_ADDRESS + addr);
683}
684
685void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
686{
687 ath10k_pci_write32(ar, PCIE_LOCAL_BASE_ADDRESS + addr, val);
688}
689
Michal Kaziore5398872013-11-25 14:06:20 +0100690static bool ath10k_pci_irq_pending(struct ath10k *ar)
691{
692 u32 cause;
693
694 /* Check if the shared legacy irq is for us */
695 cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
696 PCIE_INTR_CAUSE_ADDRESS);
697 if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
698 return true;
699
700 return false;
701}
702
Michal Kazior26852182013-11-25 14:06:25 +0100703static void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
704{
705 /* IMPORTANT: INTR_CLR register has to be set after
706 * INTR_ENABLE is set to 0, otherwise interrupt can not be
707 * really cleared. */
708 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
709 0);
710 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
711 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
712
713 /* IMPORTANT: this extra read transaction is required to
714 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300715 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
716 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100717}
718
719static void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
720{
721 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
722 PCIE_INTR_ENABLE_ADDRESS,
723 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
724
725 /* IMPORTANT: this extra read transaction is required to
726 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300727 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
728 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100729}
730
Michal Kazior403d6272014-08-22 14:23:31 +0200731static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100732{
Michal Kaziorab977bd2013-11-25 14:06:26 +0100733 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
734
Michal Kazior403d6272014-08-22 14:23:31 +0200735 if (ar_pci->num_msi_intrs > 1)
736 return "msi-x";
Kalle Valod8bb26b2014-09-14 12:50:33 +0300737
738 if (ar_pci->num_msi_intrs == 1)
Michal Kazior403d6272014-08-22 14:23:31 +0200739 return "msi";
Kalle Valod8bb26b2014-09-14 12:50:33 +0300740
741 return "legacy";
Michal Kaziorab977bd2013-11-25 14:06:26 +0100742}
743
Michal Kazior728f95e2014-08-22 14:33:14 +0200744static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100745{
Michal Kazior728f95e2014-08-22 14:33:14 +0200746 struct ath10k *ar = pipe->hif_ce_state;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100747 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +0200748 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
749 struct sk_buff *skb;
750 dma_addr_t paddr;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100751 int ret;
752
Michal Kazior728f95e2014-08-22 14:33:14 +0200753 skb = dev_alloc_skb(pipe->buf_sz);
754 if (!skb)
755 return -ENOMEM;
756
757 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
758
759 paddr = dma_map_single(ar->dev, skb->data,
760 skb->len + skb_tailroom(skb),
761 DMA_FROM_DEVICE);
762 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200763 ath10k_warn(ar, "failed to dma map pci rx buf\n");
Michal Kazior728f95e2014-08-22 14:33:14 +0200764 dev_kfree_skb_any(skb);
765 return -EIO;
766 }
767
Michal Kazior8582bf32015-01-24 12:14:47 +0200768 ATH10K_SKB_RXCB(skb)->paddr = paddr;
Michal Kazior728f95e2014-08-22 14:33:14 +0200769
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300770 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200771 ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300772 spin_unlock_bh(&ar_pci->ce_lock);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100773 if (ret) {
Michal Kazior728f95e2014-08-22 14:33:14 +0200774 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
775 DMA_FROM_DEVICE);
776 dev_kfree_skb_any(skb);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100777 return ret;
778 }
779
780 return 0;
781}
782
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300783static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100784{
Michal Kazior728f95e2014-08-22 14:33:14 +0200785 struct ath10k *ar = pipe->hif_ce_state;
786 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
787 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
788 int ret, num;
789
Michal Kazior728f95e2014-08-22 14:33:14 +0200790 if (pipe->buf_sz == 0)
791 return;
792
793 if (!ce_pipe->dest_ring)
794 return;
795
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300796 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200797 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300798 spin_unlock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200799 while (num--) {
800 ret = __ath10k_pci_rx_post_buf(pipe);
801 if (ret) {
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300802 if (ret == -ENOSPC)
803 break;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200804 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
Michal Kazior728f95e2014-08-22 14:33:14 +0200805 mod_timer(&ar_pci->rx_post_retry, jiffies +
806 ATH10K_PCI_RX_POST_RETRY_MS);
807 break;
808 }
809 }
810}
811
Michal Kazior728f95e2014-08-22 14:33:14 +0200812static void ath10k_pci_rx_post(struct ath10k *ar)
813{
814 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
815 int i;
816
Michal Kazior728f95e2014-08-22 14:33:14 +0200817 for (i = 0; i < CE_COUNT; i++)
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300818 ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
Michal Kazior728f95e2014-08-22 14:33:14 +0200819}
820
821static void ath10k_pci_rx_replenish_retry(unsigned long ptr)
822{
823 struct ath10k *ar = (void *)ptr;
824
825 ath10k_pci_rx_post(ar);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100826}
827
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530828static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
829{
830 u32 val = 0;
831
832 switch (ar->hw_rev) {
833 case ATH10K_HW_QCA988X:
834 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +0100835 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530836 val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
837 CORE_CTRL_ADDRESS) &
Vasanthakumar Thiagarajan3c7e2562015-07-03 19:25:27 +0530838 0x7ff) << 21;
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530839 break;
840 case ATH10K_HW_QCA99X0:
841 val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
842 break;
843 }
844
845 val |= 0x100000 | (addr & 0xfffff);
846 return val;
847}
848
Kalle Valo5e3dd152013-06-12 20:52:10 +0300849/*
850 * Diagnostic read/write access is provided for startup/config/debug usage.
851 * Caller must guarantee proper alignment, when applicable, and single user
852 * at any moment.
853 */
854static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
855 int nbytes)
856{
857 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
858 int ret = 0;
859 u32 buf;
860 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
861 unsigned int id;
862 unsigned int flags;
Michal Kazior2aa39112013-08-27 13:08:02 +0200863 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300864 /* Host buffer address in CE space */
865 u32 ce_data;
866 dma_addr_t ce_data_base = 0;
867 void *data_buf = NULL;
868 int i;
869
Kalle Valoeef25402014-09-24 14:16:52 +0300870 spin_lock_bh(&ar_pci->ce_lock);
871
Kalle Valo5e3dd152013-06-12 20:52:10 +0300872 ce_diag = ar_pci->ce_diag;
873
874 /*
875 * Allocate a temporary bounce buffer to hold caller's data
876 * to be DMA'ed from Target. This guarantees
877 * 1) 4-byte alignment
878 * 2) Buffer in DMA-able space
879 */
880 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +0200881 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
882 orig_nbytes,
883 &ce_data_base,
884 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300885
886 if (!data_buf) {
887 ret = -ENOMEM;
888 goto done;
889 }
890 memset(data_buf, 0, orig_nbytes);
891
892 remaining_bytes = orig_nbytes;
893 ce_data = ce_data_base;
894 while (remaining_bytes) {
895 nbytes = min_t(unsigned int, remaining_bytes,
896 DIAG_TRANSFER_LIMIT);
897
Kalle Valoeef25402014-09-24 14:16:52 +0300898 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899 if (ret != 0)
900 goto done;
901
902 /* Request CE to send from Target(!) address to Host buffer */
903 /*
904 * The address supplied by the caller is in the
905 * Target CPU virtual address space.
906 *
907 * In order to use this address with the diagnostic CE,
908 * convert it from Target CPU virtual address space
909 * to CE address space
910 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530911 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300912
Kalle Valoeef25402014-09-24 14:16:52 +0300913 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
914 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300915 if (ret)
916 goto done;
917
918 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +0530919 while (ath10k_ce_completed_send_next_nolock(ce_diag,
920 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300921 mdelay(1);
922 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
923 ret = -EBUSY;
924 goto done;
925 }
926 }
927
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928 i = 0;
Kalle Valoeef25402014-09-24 14:16:52 +0300929 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
930 &completed_nbytes,
931 &id, &flags) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 mdelay(1);
933
934 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
935 ret = -EBUSY;
936 goto done;
937 }
938 }
939
940 if (nbytes != completed_nbytes) {
941 ret = -EIO;
942 goto done;
943 }
944
945 if (buf != ce_data) {
946 ret = -EIO;
947 goto done;
948 }
949
950 remaining_bytes -= nbytes;
951 address += nbytes;
952 ce_data += nbytes;
953 }
954
955done:
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300956 if (ret == 0)
957 memcpy(data, data_buf, orig_nbytes);
958 else
Michal Kazior7aa7a722014-08-25 12:09:38 +0200959 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +0200960 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300961
962 if (data_buf)
Michal Kazior68c03242014-03-28 10:02:35 +0200963 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
964 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300965
Kalle Valoeef25402014-09-24 14:16:52 +0300966 spin_unlock_bh(&ar_pci->ce_lock);
967
Kalle Valo5e3dd152013-06-12 20:52:10 +0300968 return ret;
969}
970
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300971static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
972{
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300973 __le32 val = 0;
974 int ret;
975
976 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
977 *value = __le32_to_cpu(val);
978
979 return ret;
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300980}
981
982static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
983 u32 src, u32 len)
984{
985 u32 host_addr, addr;
986 int ret;
987
988 host_addr = host_interest_item_address(src);
989
990 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
991 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200992 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300993 src, ret);
994 return ret;
995 }
996
997 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
998 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200999 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001000 addr, len, ret);
1001 return ret;
1002 }
1003
1004 return 0;
1005}
1006
1007#define ath10k_pci_diag_read_hi(ar, dest, src, len) \
Kalle Valo8cc7f262014-09-14 12:50:39 +03001008 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001009
Kalle Valo5e3dd152013-06-12 20:52:10 +03001010static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
1011 const void *data, int nbytes)
1012{
1013 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1014 int ret = 0;
1015 u32 buf;
1016 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
1017 unsigned int id;
1018 unsigned int flags;
Michal Kazior2aa39112013-08-27 13:08:02 +02001019 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001020 void *data_buf = NULL;
1021 u32 ce_data; /* Host buffer address in CE space */
1022 dma_addr_t ce_data_base = 0;
1023 int i;
1024
Kalle Valoeef25402014-09-24 14:16:52 +03001025 spin_lock_bh(&ar_pci->ce_lock);
1026
Kalle Valo5e3dd152013-06-12 20:52:10 +03001027 ce_diag = ar_pci->ce_diag;
1028
1029 /*
1030 * Allocate a temporary bounce buffer to hold caller's data
1031 * to be DMA'ed to Target. This guarantees
1032 * 1) 4-byte alignment
1033 * 2) Buffer in DMA-able space
1034 */
1035 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +02001036 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
1037 orig_nbytes,
1038 &ce_data_base,
1039 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001040 if (!data_buf) {
1041 ret = -ENOMEM;
1042 goto done;
1043 }
1044
1045 /* Copy caller's data to allocated DMA buf */
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001046 memcpy(data_buf, data, orig_nbytes);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001047
1048 /*
1049 * The address supplied by the caller is in the
1050 * Target CPU virtual address space.
1051 *
1052 * In order to use this address with the diagnostic CE,
1053 * convert it from
1054 * Target CPU virtual address space
1055 * to
1056 * CE address space
1057 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +05301058 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001059
1060 remaining_bytes = orig_nbytes;
1061 ce_data = ce_data_base;
1062 while (remaining_bytes) {
1063 /* FIXME: check cast */
1064 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
1065
1066 /* Set up to receive directly into Target(!) address */
Kalle Valoeef25402014-09-24 14:16:52 +03001067 ret = __ath10k_ce_rx_post_buf(ce_diag, NULL, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001068 if (ret != 0)
1069 goto done;
1070
1071 /*
1072 * Request CE to send caller-supplied data that
1073 * was copied to bounce buffer to Target(!) address.
1074 */
Kalle Valoeef25402014-09-24 14:16:52 +03001075 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
1076 nbytes, 0, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001077 if (ret != 0)
1078 goto done;
1079
1080 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301081 while (ath10k_ce_completed_send_next_nolock(ce_diag,
1082 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001083 mdelay(1);
1084
1085 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1086 ret = -EBUSY;
1087 goto done;
1088 }
1089 }
1090
Kalle Valo5e3dd152013-06-12 20:52:10 +03001091 i = 0;
Kalle Valoeef25402014-09-24 14:16:52 +03001092 while (ath10k_ce_completed_recv_next_nolock(ce_diag, NULL, &buf,
1093 &completed_nbytes,
1094 &id, &flags) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001095 mdelay(1);
1096
1097 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1098 ret = -EBUSY;
1099 goto done;
1100 }
1101 }
1102
1103 if (nbytes != completed_nbytes) {
1104 ret = -EIO;
1105 goto done;
1106 }
1107
1108 if (buf != address) {
1109 ret = -EIO;
1110 goto done;
1111 }
1112
1113 remaining_bytes -= nbytes;
1114 address += nbytes;
1115 ce_data += nbytes;
1116 }
1117
1118done:
1119 if (data_buf) {
Michal Kazior68c03242014-03-28 10:02:35 +02001120 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
1121 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 }
1123
1124 if (ret != 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001125 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +02001126 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001127
Kalle Valoeef25402014-09-24 14:16:52 +03001128 spin_unlock_bh(&ar_pci->ce_lock);
1129
Kalle Valo5e3dd152013-06-12 20:52:10 +03001130 return ret;
1131}
1132
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001133static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
1134{
1135 __le32 val = __cpu_to_le32(value);
1136
1137 return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
1138}
1139
Kalle Valo5e3dd152013-06-12 20:52:10 +03001140/* Called by lower (CE) layer when a send to Target completes. */
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301141static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001142{
1143 struct ath10k *ar = ce_state->ar;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001144 struct sk_buff_head list;
1145 struct sk_buff *skb;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001146
Michal Kazior1cb86d42014-11-27 11:09:38 +01001147 __skb_queue_head_init(&list);
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301148 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Michal Kaziora16942e2014-02-27 18:50:04 +02001149 /* no need to call tx completion for NULL pointers */
Michal Kazior1cb86d42014-11-27 11:09:38 +01001150 if (skb == NULL)
Michal Kazior726346f2014-02-27 18:50:04 +02001151 continue;
1152
Michal Kazior1cb86d42014-11-27 11:09:38 +01001153 __skb_queue_tail(&list, skb);
Michal Kazior5440ce22013-09-03 15:09:58 +02001154 }
Michal Kazior1cb86d42014-11-27 11:09:38 +01001155
1156 while ((skb = __skb_dequeue(&list)))
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301157 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001158}
1159
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301160static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
1161 void (*callback)(struct ath10k *ar,
1162 struct sk_buff *skb))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001163{
1164 struct ath10k *ar = ce_state->ar;
1165 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior87263e52013-08-27 13:08:01 +02001166 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001167 struct sk_buff *skb;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001168 struct sk_buff_head list;
Michal Kazior5440ce22013-09-03 15:09:58 +02001169 void *transfer_context;
1170 u32 ce_data;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001171 unsigned int nbytes, max_nbytes;
Michal Kazior5440ce22013-09-03 15:09:58 +02001172 unsigned int transfer_id;
1173 unsigned int flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174
Michal Kazior1cb86d42014-11-27 11:09:38 +01001175 __skb_queue_head_init(&list);
Michal Kazior5440ce22013-09-03 15:09:58 +02001176 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
1177 &ce_data, &nbytes, &transfer_id,
1178 &flags) == 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001179 skb = transfer_context;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001180 max_nbytes = skb->len + skb_tailroom(skb);
Michal Kazior8582bf32015-01-24 12:14:47 +02001181 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior2f5280d2014-02-27 18:50:05 +02001182 max_nbytes, DMA_FROM_DEVICE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001183
Michal Kazior2f5280d2014-02-27 18:50:05 +02001184 if (unlikely(max_nbytes < nbytes)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001185 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
Michal Kazior2f5280d2014-02-27 18:50:05 +02001186 nbytes, max_nbytes);
1187 dev_kfree_skb_any(skb);
1188 continue;
1189 }
1190
1191 skb_put(skb, nbytes);
Michal Kazior1cb86d42014-11-27 11:09:38 +01001192 __skb_queue_tail(&list, skb);
1193 }
Michal Kaziora360e542014-09-23 10:22:54 +02001194
Michal Kazior1cb86d42014-11-27 11:09:38 +01001195 while ((skb = __skb_dequeue(&list))) {
Michal Kaziora360e542014-09-23 10:22:54 +02001196 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1197 ce_state->id, skb->len);
1198 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1199 skb->data, skb->len);
1200
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301201 callback(ar, skb);
Michal Kazior2f5280d2014-02-27 18:50:05 +02001202 }
Michal Kaziorc29a3802014-07-21 21:03:10 +03001203
Michal Kazior728f95e2014-08-22 14:33:14 +02001204 ath10k_pci_rx_post_pipe(pipe_info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001205}
1206
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301207/* Called by lower (CE) layer when data is received from the Target. */
1208static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1209{
1210 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1211}
1212
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +05301213static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1214{
1215 /* CE4 polling needs to be done whenever CE pipe which transports
1216 * HTT Rx (target->host) is processed.
1217 */
1218 ath10k_ce_per_engine_service(ce_state->ar, 4);
1219
1220 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1221}
1222
Vivek Natarajanafb0bf72015-10-30 14:57:58 +05301223/* Called by lower (CE) layer when data is received from the Target.
1224 * Only 10.4 firmware uses separate CE to transfer pktlog data.
1225 */
1226static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
1227{
1228 ath10k_pci_process_rx_cb(ce_state,
1229 ath10k_htt_rx_pktlog_completion_handler);
1230}
1231
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301232/* Called by lower (CE) layer when a send to HTT Target completes. */
1233static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
1234{
1235 struct ath10k *ar = ce_state->ar;
1236 struct sk_buff *skb;
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301237
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301238 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301239 /* no need to call tx completion for NULL pointers */
1240 if (!skb)
1241 continue;
1242
1243 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1244 skb->len, DMA_TO_DEVICE);
1245 ath10k_htt_hif_tx_complete(ar, skb);
1246 }
1247}
1248
1249static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
1250{
1251 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
1252 ath10k_htt_t2h_msg_handler(ar, skb);
1253}
1254
1255/* Called by lower (CE) layer when HTT data is received from the Target. */
1256static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
1257{
1258 /* CE4 polling needs to be done whenever CE pipe which transports
1259 * HTT Rx (target->host) is processed.
1260 */
1261 ath10k_ce_per_engine_service(ce_state->ar, 4);
1262
1263 ath10k_pci_process_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
1264}
1265
Michal Kazior726346f2014-02-27 18:50:04 +02001266static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
1267 struct ath10k_hif_sg_item *items, int n_items)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001268{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001269 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior726346f2014-02-27 18:50:04 +02001270 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
1271 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
1272 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
Michal Kazior7147a132014-05-26 12:02:58 +02001273 unsigned int nentries_mask;
1274 unsigned int sw_index;
1275 unsigned int write_index;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001276 int err, i = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277
Michal Kazior726346f2014-02-27 18:50:04 +02001278 spin_lock_bh(&ar_pci->ce_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001279
Michal Kazior7147a132014-05-26 12:02:58 +02001280 nentries_mask = src_ring->nentries_mask;
1281 sw_index = src_ring->sw_index;
1282 write_index = src_ring->write_index;
1283
Michal Kazior726346f2014-02-27 18:50:04 +02001284 if (unlikely(CE_RING_DELTA(nentries_mask,
1285 write_index, sw_index - 1) < n_items)) {
1286 err = -ENOBUFS;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001287 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001288 }
1289
1290 for (i = 0; i < n_items - 1; i++) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001291 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001292 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1293 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001294 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001295 items[i].vaddr, items[i].len);
1296
1297 err = ath10k_ce_send_nolock(ce_pipe,
1298 items[i].transfer_context,
1299 items[i].paddr,
1300 items[i].len,
1301 items[i].transfer_id,
1302 CE_SEND_FLAG_GATHER);
1303 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001304 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001305 }
1306
1307 /* `i` is equal to `n_items -1` after for() */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308
Michal Kazior7aa7a722014-08-25 12:09:38 +02001309 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001310 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1311 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001312 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001313 items[i].vaddr, items[i].len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001314
Michal Kazior726346f2014-02-27 18:50:04 +02001315 err = ath10k_ce_send_nolock(ce_pipe,
1316 items[i].transfer_context,
1317 items[i].paddr,
1318 items[i].len,
1319 items[i].transfer_id,
1320 0);
1321 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001322 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001323
Michal Kazior08b8aa02014-05-26 12:02:59 +02001324 spin_unlock_bh(&ar_pci->ce_lock);
1325 return 0;
1326
1327err:
1328 for (; i > 0; i--)
1329 __ath10k_ce_send_revert(ce_pipe);
1330
Michal Kazior726346f2014-02-27 18:50:04 +02001331 spin_unlock_bh(&ar_pci->ce_lock);
1332 return err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001333}
1334
Kalle Valoeef25402014-09-24 14:16:52 +03001335static int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
1336 size_t buf_len)
1337{
1338 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
1339}
1340
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
1342{
1343 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001344
Michal Kazior7aa7a722014-08-25 12:09:38 +02001345 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001346
Michal Kazior3efcb3b2013-10-02 11:03:41 +02001347 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001348}
1349
Ben Greear384914b2014-08-25 08:37:32 +03001350static void ath10k_pci_dump_registers(struct ath10k *ar,
1351 struct ath10k_fw_crash_data *crash_data)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352{
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001353 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
1354 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355
Ben Greear384914b2014-08-25 08:37:32 +03001356 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001357
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001358 ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
1359 hi_failure_state,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001360 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001361 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001362 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001363 return;
1364 }
1365
1366 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
1367
Michal Kazior7aa7a722014-08-25 12:09:38 +02001368 ath10k_err(ar, "firmware register dump:\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001370 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 i,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001372 __le32_to_cpu(reg_dump_values[i]),
1373 __le32_to_cpu(reg_dump_values[i + 1]),
1374 __le32_to_cpu(reg_dump_values[i + 2]),
1375 __le32_to_cpu(reg_dump_values[i + 3]));
Michal Kazioraffd3212013-07-16 09:54:35 +02001376
Michal Kazior1bbb1192014-08-25 12:13:14 +02001377 if (!crash_data)
1378 return;
1379
Ben Greear384914b2014-08-25 08:37:32 +03001380 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001381 crash_data->registers[i] = reg_dump_values[i];
Ben Greear384914b2014-08-25 08:37:32 +03001382}
1383
Kalle Valo0e9848c2014-08-25 08:37:37 +03001384static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
Ben Greear384914b2014-08-25 08:37:32 +03001385{
1386 struct ath10k_fw_crash_data *crash_data;
1387 char uuid[50];
1388
1389 spin_lock_bh(&ar->data_lock);
1390
Ben Greearf51dbe72014-09-29 14:41:46 +03001391 ar->stats.fw_crash_counter++;
1392
Ben Greear384914b2014-08-25 08:37:32 +03001393 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
1394
1395 if (crash_data)
1396 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
1397 else
1398 scnprintf(uuid, sizeof(uuid), "n/a");
1399
Michal Kazior7aa7a722014-08-25 12:09:38 +02001400 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
Kalle Valo8a0c7972014-08-25 08:37:45 +03001401 ath10k_print_driver_info(ar);
Ben Greear384914b2014-08-25 08:37:32 +03001402 ath10k_pci_dump_registers(ar, crash_data);
1403
Ben Greear384914b2014-08-25 08:37:32 +03001404 spin_unlock_bh(&ar->data_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02001405
Michal Kazior5e90de82013-10-16 16:46:05 +03001406 queue_work(ar->workqueue, &ar->restart_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001407}
1408
1409static void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1410 int force)
1411{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001412 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001413
Kalle Valo5e3dd152013-06-12 20:52:10 +03001414 if (!force) {
1415 int resources;
1416 /*
1417 * Decide whether to actually poll for completions, or just
1418 * wait for a later chance.
1419 * If there seem to be plenty of resources left, then just wait
1420 * since checking involves reading a CE register, which is a
1421 * relatively expensive operation.
1422 */
1423 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1424
1425 /*
1426 * If at least 50% of the total resources are still available,
1427 * don't bother checking again yet.
1428 */
1429 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1430 return;
1431 }
1432 ath10k_ce_per_engine_service(ar, pipe);
1433}
1434
Michal Kazior96a9d0d2013-11-08 08:01:25 +01001435static void ath10k_pci_kill_tasklet(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436{
1437 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438 int i;
1439
Kalle Valo5e3dd152013-06-12 20:52:10 +03001440 tasklet_kill(&ar_pci->intr_tq);
Michal Kazior103d4f52013-11-08 08:01:24 +01001441 tasklet_kill(&ar_pci->msi_fw_err);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001442
1443 for (i = 0; i < CE_COUNT; i++)
1444 tasklet_kill(&ar_pci->pipe_info[i].intr);
Michal Kazior728f95e2014-08-22 14:33:14 +02001445
1446 del_timer_sync(&ar_pci->rx_post_retry);
Michal Kazior96a9d0d2013-11-08 08:01:25 +01001447}
1448
Rajkumar Manoharan400143e2015-10-12 18:27:06 +05301449static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
1450 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001451{
Michal Kazior7c6aa252014-08-26 19:14:03 +03001452 const struct service_to_pipe *entry;
1453 bool ul_set = false, dl_set = false;
1454 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001455
Michal Kazior7aa7a722014-08-25 12:09:38 +02001456 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001457
Michal Kazior7c6aa252014-08-26 19:14:03 +03001458 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1459 entry = &target_service_to_ce_map_wlan[i];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001460
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001461 if (__le32_to_cpu(entry->service_id) != service_id)
Michal Kazior7c6aa252014-08-26 19:14:03 +03001462 continue;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001463
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001464 switch (__le32_to_cpu(entry->pipedir)) {
Michal Kazior7c6aa252014-08-26 19:14:03 +03001465 case PIPEDIR_NONE:
1466 break;
1467 case PIPEDIR_IN:
1468 WARN_ON(dl_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001469 *dl_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001470 dl_set = true;
1471 break;
1472 case PIPEDIR_OUT:
1473 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001474 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001475 ul_set = true;
1476 break;
1477 case PIPEDIR_INOUT:
1478 WARN_ON(dl_set);
1479 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001480 *dl_pipe = __le32_to_cpu(entry->pipenum);
1481 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001482 dl_set = true;
1483 ul_set = true;
1484 break;
1485 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001486 }
Michal Kazior7c6aa252014-08-26 19:14:03 +03001487
1488 if (WARN_ON(!ul_set || !dl_set))
1489 return -ENOENT;
1490
Michal Kazior7c6aa252014-08-26 19:14:03 +03001491 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001492}
1493
1494static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03001495 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001496{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001497 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001498
Kalle Valo5e3dd152013-06-12 20:52:10 +03001499 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1500 ATH10K_HTC_SVC_ID_RSVD_CTRL,
Rajkumar Manoharan400143e2015-10-12 18:27:06 +05301501 ul_pipe, dl_pipe);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502}
1503
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001504static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1505{
1506 u32 val;
1507
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301508 switch (ar->hw_rev) {
1509 case ATH10K_HW_QCA988X:
1510 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001511 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301512 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1513 CORE_CTRL_ADDRESS);
1514 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1515 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1516 CORE_CTRL_ADDRESS, val);
1517 break;
1518 case ATH10K_HW_QCA99X0:
1519 /* TODO: Find appropriate register configuration for QCA99X0
1520 * to mask irq/MSI.
1521 */
1522 break;
1523 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001524}
1525
1526static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1527{
1528 u32 val;
1529
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301530 switch (ar->hw_rev) {
1531 case ATH10K_HW_QCA988X:
1532 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001533 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301534 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1535 CORE_CTRL_ADDRESS);
1536 val |= CORE_CTRL_PCIE_REG_31_MASK;
1537 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1538 CORE_CTRL_ADDRESS, val);
1539 break;
1540 case ATH10K_HW_QCA99X0:
1541 /* TODO: Find appropriate register configuration for QCA99X0
1542 * to unmask irq/MSI.
1543 */
1544 break;
1545 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001546}
1547
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001548static void ath10k_pci_irq_disable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001549{
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001550 ath10k_ce_disable_interrupts(ar);
1551 ath10k_pci_disable_and_clear_legacy_irq(ar);
1552 ath10k_pci_irq_msi_fw_mask(ar);
1553}
1554
1555static void ath10k_pci_irq_sync(struct ath10k *ar)
1556{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001557 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001558 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001559
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001560 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1561 synchronize_irq(ar_pci->pdev->irq + i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562}
1563
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001564static void ath10k_pci_irq_enable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001565{
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001566 ath10k_ce_enable_interrupts(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001567 ath10k_pci_enable_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001568 ath10k_pci_irq_msi_fw_unmask(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569}
1570
1571static int ath10k_pci_hif_start(struct ath10k *ar)
1572{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001573 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo9a149692015-10-05 17:56:36 +03001574
Michal Kazior7aa7a722014-08-25 12:09:38 +02001575 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001577 ath10k_pci_irq_enable(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +02001578 ath10k_pci_rx_post(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001579
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001580 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
1581 ar_pci->link_ctl);
1582
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 return 0;
1584}
1585
Michal Kazior099ac7c2014-10-28 10:32:05 +01001586static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587{
1588 struct ath10k *ar;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001589 struct ath10k_ce_pipe *ce_pipe;
1590 struct ath10k_ce_ring *ce_ring;
1591 struct sk_buff *skb;
1592 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001593
Michal Kazior099ac7c2014-10-28 10:32:05 +01001594 ar = pci_pipe->hif_ce_state;
1595 ce_pipe = pci_pipe->ce_hdl;
1596 ce_ring = ce_pipe->dest_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597
Michal Kazior099ac7c2014-10-28 10:32:05 +01001598 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 return;
1600
Michal Kazior099ac7c2014-10-28 10:32:05 +01001601 if (!pci_pipe->buf_sz)
1602 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603
Michal Kazior099ac7c2014-10-28 10:32:05 +01001604 for (i = 0; i < ce_ring->nentries; i++) {
1605 skb = ce_ring->per_transfer_context[i];
1606 if (!skb)
1607 continue;
1608
1609 ce_ring->per_transfer_context[i] = NULL;
1610
Michal Kazior8582bf32015-01-24 12:14:47 +02001611 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior099ac7c2014-10-28 10:32:05 +01001612 skb->len + skb_tailroom(skb),
Kalle Valo5e3dd152013-06-12 20:52:10 +03001613 DMA_FROM_DEVICE);
Michal Kazior099ac7c2014-10-28 10:32:05 +01001614 dev_kfree_skb_any(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 }
1616}
1617
Michal Kazior099ac7c2014-10-28 10:32:05 +01001618static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619{
1620 struct ath10k *ar;
1621 struct ath10k_pci *ar_pci;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001622 struct ath10k_ce_pipe *ce_pipe;
1623 struct ath10k_ce_ring *ce_ring;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001624 struct sk_buff *skb;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001625 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626
Michal Kazior099ac7c2014-10-28 10:32:05 +01001627 ar = pci_pipe->hif_ce_state;
1628 ar_pci = ath10k_pci_priv(ar);
1629 ce_pipe = pci_pipe->ce_hdl;
1630 ce_ring = ce_pipe->src_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631
Michal Kazior099ac7c2014-10-28 10:32:05 +01001632 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 return;
1634
Michal Kazior099ac7c2014-10-28 10:32:05 +01001635 if (!pci_pipe->buf_sz)
1636 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001637
Michal Kazior099ac7c2014-10-28 10:32:05 +01001638 for (i = 0; i < ce_ring->nentries; i++) {
1639 skb = ce_ring->per_transfer_context[i];
1640 if (!skb)
Michal Kazior2415fc12013-11-08 08:01:32 +01001641 continue;
Michal Kazior2415fc12013-11-08 08:01:32 +01001642
Michal Kazior099ac7c2014-10-28 10:32:05 +01001643 ce_ring->per_transfer_context[i] = NULL;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001644
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301645 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001646 }
1647}
1648
1649/*
1650 * Cleanup residual buffers for device shutdown:
1651 * buffers that were enqueued for receive
1652 * buffers that were to be sent
1653 * Note: Buffers that had completed but which were
1654 * not yet processed are on a completion queue. They
1655 * are handled when the completion thread shuts down.
1656 */
1657static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1658{
1659 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1660 int pipe_num;
1661
Michal Kaziorfad6ed72013-11-08 08:01:23 +01001662 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
Michal Kazior87263e52013-08-27 13:08:01 +02001663 struct ath10k_pci_pipe *pipe_info;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001664
1665 pipe_info = &ar_pci->pipe_info[pipe_num];
1666 ath10k_pci_rx_pipe_cleanup(pipe_info);
1667 ath10k_pci_tx_pipe_cleanup(pipe_info);
1668 }
1669}
1670
1671static void ath10k_pci_ce_deinit(struct ath10k *ar)
1672{
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001673 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001674
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001675 for (i = 0; i < CE_COUNT; i++)
1676 ath10k_ce_deinit_pipe(ar, i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677}
1678
Michal Kazior728f95e2014-08-22 14:33:14 +02001679static void ath10k_pci_flush(struct ath10k *ar)
1680{
1681 ath10k_pci_kill_tasklet(ar);
1682 ath10k_pci_buffer_cleanup(ar);
1683}
1684
Kalle Valo5e3dd152013-06-12 20:52:10 +03001685static void ath10k_pci_hif_stop(struct ath10k *ar)
1686{
Michal Kazior77258d42015-05-18 09:38:18 +00001687 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1688 unsigned long flags;
1689
Michal Kazior7aa7a722014-08-25 12:09:38 +02001690 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
Michal Kazior32270b62013-08-02 09:15:47 +02001691
Michal Kazior10d23db2014-08-22 14:33:15 +02001692 /* Most likely the device has HTT Rx ring configured. The only way to
1693 * prevent the device from accessing (and possible corrupting) host
1694 * memory is to reset the chip now.
Michal Kaziore75db4e2014-08-28 22:14:16 +03001695 *
1696 * There's also no known way of masking MSI interrupts on the device.
1697 * For ranged MSI the CE-related interrupts can be masked. However
1698 * regardless how many MSI interrupts are assigned the first one
1699 * is always used for firmware indications (crashes) and cannot be
1700 * masked. To prevent the device from asserting the interrupt reset it
1701 * before proceeding with cleanup.
Michal Kazior10d23db2014-08-22 14:33:15 +02001702 */
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301703 ath10k_pci_safe_chip_reset(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001704
1705 ath10k_pci_irq_disable(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001706 ath10k_pci_irq_sync(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001707 ath10k_pci_flush(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00001708
1709 spin_lock_irqsave(&ar_pci->ps_lock, flags);
1710 WARN_ON(ar_pci->ps_wake_refcount > 0);
1711 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001712}
1713
1714static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1715 void *req, u32 req_len,
1716 void *resp, u32 *resp_len)
1717{
1718 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior2aa39112013-08-27 13:08:02 +02001719 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1720 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1721 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1722 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001723 dma_addr_t req_paddr = 0;
1724 dma_addr_t resp_paddr = 0;
1725 struct bmi_xfer xfer = {};
1726 void *treq, *tresp = NULL;
1727 int ret = 0;
1728
Michal Kazior85622cd2013-11-25 14:06:22 +01001729 might_sleep();
1730
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 if (resp && !resp_len)
1732 return -EINVAL;
1733
1734 if (resp && resp_len && *resp_len == 0)
1735 return -EINVAL;
1736
1737 treq = kmemdup(req, req_len, GFP_KERNEL);
1738 if (!treq)
1739 return -ENOMEM;
1740
1741 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1742 ret = dma_mapping_error(ar->dev, req_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001743 if (ret) {
1744 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001745 goto err_dma;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001746 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001747
1748 if (resp && resp_len) {
1749 tresp = kzalloc(*resp_len, GFP_KERNEL);
1750 if (!tresp) {
1751 ret = -ENOMEM;
1752 goto err_req;
1753 }
1754
1755 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1756 DMA_FROM_DEVICE);
1757 ret = dma_mapping_error(ar->dev, resp_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001758 if (ret) {
1759 ret = EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001760 goto err_req;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001761 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001762
1763 xfer.wait_for_resp = true;
1764 xfer.resp_len = 0;
1765
Michal Kazior728f95e2014-08-22 14:33:14 +02001766 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767 }
1768
Kalle Valo5e3dd152013-06-12 20:52:10 +03001769 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1770 if (ret)
1771 goto err_resp;
1772
Michal Kazior85622cd2013-11-25 14:06:22 +01001773 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1774 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001775 u32 unused_buffer;
1776 unsigned int unused_nbytes;
1777 unsigned int unused_id;
1778
Kalle Valo5e3dd152013-06-12 20:52:10 +03001779 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1780 &unused_nbytes, &unused_id);
1781 } else {
1782 /* non-zero means we did not time out */
1783 ret = 0;
1784 }
1785
1786err_resp:
1787 if (resp) {
1788 u32 unused_buffer;
1789
1790 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1791 dma_unmap_single(ar->dev, resp_paddr,
1792 *resp_len, DMA_FROM_DEVICE);
1793 }
1794err_req:
1795 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1796
1797 if (ret == 0 && resp_len) {
1798 *resp_len = min(*resp_len, xfer.resp_len);
1799 memcpy(resp, tresp, xfer.resp_len);
1800 }
1801err_dma:
1802 kfree(treq);
1803 kfree(tresp);
1804
1805 return ret;
1806}
1807
Michal Kazior5440ce22013-09-03 15:09:58 +02001808static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001809{
Michal Kazior5440ce22013-09-03 15:09:58 +02001810 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001811
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301812 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
Michal Kazior5440ce22013-09-03 15:09:58 +02001813 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814
Michal Kazior2374b182014-07-14 16:25:25 +03001815 xfer->tx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816}
1817
Michal Kazior5440ce22013-09-03 15:09:58 +02001818static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 struct ath10k *ar = ce_state->ar;
Michal Kazior5440ce22013-09-03 15:09:58 +02001821 struct bmi_xfer *xfer;
1822 u32 ce_data;
1823 unsigned int nbytes;
1824 unsigned int transfer_id;
1825 unsigned int flags;
1826
1827 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data,
1828 &nbytes, &transfer_id, &flags))
1829 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830
Michal Kazior04ed9df2014-10-28 10:34:36 +01001831 if (WARN_ON_ONCE(!xfer))
1832 return;
1833
Kalle Valo5e3dd152013-06-12 20:52:10 +03001834 if (!xfer->wait_for_resp) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001835 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836 return;
1837 }
1838
1839 xfer->resp_len = nbytes;
Michal Kazior2374b182014-07-14 16:25:25 +03001840 xfer->rx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001841}
1842
Michal Kazior85622cd2013-11-25 14:06:22 +01001843static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1844 struct ath10k_ce_pipe *rx_pipe,
1845 struct bmi_xfer *xfer)
1846{
1847 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1848
1849 while (time_before_eq(jiffies, timeout)) {
1850 ath10k_pci_bmi_send_done(tx_pipe);
1851 ath10k_pci_bmi_recv_data(rx_pipe);
1852
Michal Kazior2374b182014-07-14 16:25:25 +03001853 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
Michal Kazior85622cd2013-11-25 14:06:22 +01001854 return 0;
1855
1856 schedule();
1857 }
1858
1859 return -ETIMEDOUT;
1860}
1861
Kalle Valo5e3dd152013-06-12 20:52:10 +03001862/*
Kalle Valo5e3dd152013-06-12 20:52:10 +03001863 * Send an interrupt to the device to wake up the Target CPU
1864 * so it has an opportunity to notice any changed state.
1865 */
1866static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1867{
Michal Kazior9e264942014-09-02 11:00:21 +03001868 u32 addr, val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869
Michal Kazior9e264942014-09-02 11:00:21 +03001870 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1871 val = ath10k_pci_read32(ar, addr);
1872 val |= CORE_CTRL_CPU_INTR_MASK;
1873 ath10k_pci_write32(ar, addr, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001874
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001875 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876}
1877
Michal Kaziord63955b2015-01-24 12:14:49 +02001878static int ath10k_pci_get_num_banks(struct ath10k *ar)
1879{
1880 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1881
1882 switch (ar_pci->pdev->device) {
1883 case QCA988X_2_0_DEVICE_ID:
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05301884 case QCA99X0_2_0_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001885 return 1;
Michal Kazior36582e52015-08-13 14:32:26 +02001886 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001887 case QCA6174_2_1_DEVICE_ID:
1888 switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
1889 case QCA6174_HW_1_0_CHIP_ID_REV:
1890 case QCA6174_HW_1_1_CHIP_ID_REV:
Michal Kazior11a002e2015-04-20 09:20:41 +00001891 case QCA6174_HW_2_1_CHIP_ID_REV:
1892 case QCA6174_HW_2_2_CHIP_ID_REV:
Michal Kaziord63955b2015-01-24 12:14:49 +02001893 return 3;
1894 case QCA6174_HW_1_3_CHIP_ID_REV:
1895 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001896 case QCA6174_HW_3_0_CHIP_ID_REV:
1897 case QCA6174_HW_3_1_CHIP_ID_REV:
1898 case QCA6174_HW_3_2_CHIP_ID_REV:
1899 return 9;
1900 }
1901 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01001902 case QCA9377_1_0_DEVICE_ID:
1903 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001904 }
1905
1906 ath10k_warn(ar, "unknown number of banks, assuming 1\n");
1907 return 1;
1908}
1909
Kalle Valo5e3dd152013-06-12 20:52:10 +03001910static int ath10k_pci_init_config(struct ath10k *ar)
1911{
1912 u32 interconnect_targ_addr;
1913 u32 pcie_state_targ_addr = 0;
1914 u32 pipe_cfg_targ_addr = 0;
1915 u32 svc_to_pipe_map = 0;
1916 u32 pcie_config_flags = 0;
1917 u32 ealloc_value;
1918 u32 ealloc_targ_addr;
1919 u32 flag2_value;
1920 u32 flag2_targ_addr;
1921 int ret = 0;
1922
1923 /* Download to Target the CE Config and the service-to-CE map */
1924 interconnect_targ_addr =
1925 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1926
1927 /* Supply Target-side CE configuration */
Michal Kazior9e264942014-09-02 11:00:21 +03001928 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
1929 &pcie_state_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001931 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001932 return ret;
1933 }
1934
1935 if (pcie_state_targ_addr == 0) {
1936 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001937 ath10k_err(ar, "Invalid pcie state addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 return ret;
1939 }
1940
Michal Kazior9e264942014-09-02 11:00:21 +03001941 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03001943 pipe_cfg_addr)),
1944 &pipe_cfg_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001946 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001947 return ret;
1948 }
1949
1950 if (pipe_cfg_targ_addr == 0) {
1951 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001952 ath10k_err(ar, "Invalid pipe cfg addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 return ret;
1954 }
1955
1956 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001957 target_ce_config_wlan,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05301958 sizeof(struct ce_pipe_config) *
1959 NUM_TARGET_CE_CONFIG_WLAN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960
1961 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001962 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001963 return ret;
1964 }
1965
Michal Kazior9e264942014-09-02 11:00:21 +03001966 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03001968 svc_to_pipe_map)),
1969 &svc_to_pipe_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001970 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001971 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972 return ret;
1973 }
1974
1975 if (svc_to_pipe_map == 0) {
1976 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001977 ath10k_err(ar, "Invalid svc_to_pipe map\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001978 return ret;
1979 }
1980
1981 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
Kalle Valo5b07e072014-09-14 12:50:06 +03001982 target_service_to_ce_map_wlan,
1983 sizeof(target_service_to_ce_map_wlan));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001985 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001986 return ret;
1987 }
1988
Michal Kazior9e264942014-09-02 11:00:21 +03001989 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03001991 config_flags)),
1992 &pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001993 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001994 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 return ret;
1996 }
1997
1998 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
1999
Michal Kazior9e264942014-09-02 11:00:21 +03002000 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
2001 offsetof(struct pcie_state,
2002 config_flags)),
2003 pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002005 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 return ret;
2007 }
2008
2009 /* configure early allocation */
2010 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
2011
Michal Kazior9e264942014-09-02 11:00:21 +03002012 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002014 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 return ret;
2016 }
2017
2018 /* first bank is switched to IRAM */
2019 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
2020 HI_EARLY_ALLOC_MAGIC_MASK);
Michal Kaziord63955b2015-01-24 12:14:49 +02002021 ealloc_value |= ((ath10k_pci_get_num_banks(ar) <<
2022 HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
2024
Michal Kazior9e264942014-09-02 11:00:21 +03002025 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002027 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 return ret;
2029 }
2030
2031 /* Tell Target to proceed with initialization */
2032 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
2033
Michal Kazior9e264942014-09-02 11:00:21 +03002034 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002035 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002036 ath10k_err(ar, "Failed to get option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002037 return ret;
2038 }
2039
2040 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
2041
Michal Kazior9e264942014-09-02 11:00:21 +03002042 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002044 ath10k_err(ar, "Failed to set option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 return ret;
2046 }
2047
2048 return 0;
2049}
2050
Ryan Hsu2727a742015-11-05 18:44:27 -08002051static void ath10k_pci_override_ce_config(struct ath10k *ar)
2052{
2053 struct ce_attr *attr;
2054 struct ce_pipe_config *config;
2055
2056 /* For QCA6174 we're overriding the Copy Engine 5 configuration,
2057 * since it is currently used for other feature.
2058 */
2059
2060 /* Override Host's Copy Engine 5 configuration */
2061 attr = &host_ce_config_wlan[5];
2062 attr->src_sz_max = 0;
2063 attr->dest_nentries = 0;
2064
2065 /* Override Target firmware's Copy Engine configuration */
2066 config = &target_ce_config_wlan[5];
2067 config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
2068 config->nbytes_max = __cpu_to_le32(2048);
2069
2070 /* Map from service/endpoint to Copy Engine */
2071 target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
2072}
2073
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002074static int ath10k_pci_alloc_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002075{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002076 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2077 struct ath10k_pci_pipe *pipe;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002078 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002080 for (i = 0; i < CE_COUNT; i++) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002081 pipe = &ar_pci->pipe_info[i];
2082 pipe->ce_hdl = &ar_pci->ce_states[i];
2083 pipe->pipe_num = i;
2084 pipe->hif_ce_state = ar;
2085
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +05302086 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002087 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002088 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002089 i, ret);
2090 return ret;
2091 }
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002092
2093 /* Last CE is Diagnostic Window */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302094 if (i == CE_DIAG_PIPE) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002095 ar_pci->ce_diag = pipe->ce_hdl;
2096 continue;
2097 }
2098
2099 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002100 }
2101
2102 return 0;
2103}
2104
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002105static void ath10k_pci_free_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002106{
2107 int i;
2108
2109 for (i = 0; i < CE_COUNT; i++)
2110 ath10k_ce_free_pipe(ar, i);
2111}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002112
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002113static int ath10k_pci_init_pipes(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002114{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002115 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002117 for (i = 0; i < CE_COUNT; i++) {
2118 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002119 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002120 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002121 i, ret);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002122 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002124 }
2125
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126 return 0;
2127}
2128
Michal Kazior5c771e72014-08-22 14:23:34 +02002129static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130{
Michal Kazior5c771e72014-08-22 14:23:34 +02002131 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
2132 FW_IND_EVENT_PENDING;
2133}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002134
Michal Kazior5c771e72014-08-22 14:23:34 +02002135static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
2136{
2137 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002138
Michal Kazior5c771e72014-08-22 14:23:34 +02002139 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2140 val &= ~FW_IND_EVENT_PENDING;
2141 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002142}
2143
Michal Kaziorde013572014-05-14 16:56:16 +03002144/* this function effectively clears target memory controller assert line */
2145static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
2146{
2147 u32 val;
2148
2149 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2150 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2151 val | SOC_RESET_CONTROL_SI0_RST_MASK);
2152 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2153
2154 msleep(10);
2155
2156 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2157 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2158 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
2159 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2160
2161 msleep(10);
2162}
2163
Michal Kazior61c16482014-10-28 10:32:06 +01002164static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002165{
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002166 u32 val;
2167
Kalle Valob39712c2014-03-28 09:32:46 +02002168 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002169
Michal Kazior61c16482014-10-28 10:32:06 +01002170 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2171 SOC_RESET_CONTROL_ADDRESS);
2172 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2173 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
2174}
2175
2176static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
2177{
2178 u32 val;
2179
2180 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2181 SOC_RESET_CONTROL_ADDRESS);
2182
2183 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2184 val | SOC_RESET_CONTROL_CE_RST_MASK);
2185 msleep(10);
2186 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2187 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
2188}
2189
2190static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
2191{
2192 u32 val;
2193
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002194 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2195 SOC_LF_TIMER_CONTROL0_ADDRESS);
2196 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
2197 SOC_LF_TIMER_CONTROL0_ADDRESS,
2198 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
Michal Kazior61c16482014-10-28 10:32:06 +01002199}
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002200
Michal Kazior61c16482014-10-28 10:32:06 +01002201static int ath10k_pci_warm_reset(struct ath10k *ar)
2202{
2203 int ret;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002204
Michal Kazior61c16482014-10-28 10:32:06 +01002205 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002206
Michal Kazior61c16482014-10-28 10:32:06 +01002207 spin_lock_bh(&ar->data_lock);
2208 ar->stats.fw_warm_reset_counter++;
2209 spin_unlock_bh(&ar->data_lock);
2210
2211 ath10k_pci_irq_disable(ar);
2212
2213 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
2214 * were to access copy engine while host performs copy engine reset
2215 * then it is possible for the device to confuse pci-e controller to
2216 * the point of bringing host system to a complete stop (i.e. hang).
2217 */
Michal Kaziorde013572014-05-14 16:56:16 +03002218 ath10k_pci_warm_reset_si0(ar);
Michal Kazior61c16482014-10-28 10:32:06 +01002219 ath10k_pci_warm_reset_cpu(ar);
2220 ath10k_pci_init_pipes(ar);
2221 ath10k_pci_wait_for_target_init(ar);
Michal Kaziorde013572014-05-14 16:56:16 +03002222
Michal Kazior61c16482014-10-28 10:32:06 +01002223 ath10k_pci_warm_reset_clear_lf(ar);
2224 ath10k_pci_warm_reset_ce(ar);
2225 ath10k_pci_warm_reset_cpu(ar);
2226 ath10k_pci_init_pipes(ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002227
Michal Kazior61c16482014-10-28 10:32:06 +01002228 ret = ath10k_pci_wait_for_target_init(ar);
2229 if (ret) {
2230 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
2231 return ret;
2232 }
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002233
Michal Kazior7aa7a722014-08-25 12:09:38 +02002234 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002235
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002236 return 0;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002237}
2238
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302239static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
2240{
2241 if (QCA_REV_988X(ar) || QCA_REV_6174(ar)) {
2242 return ath10k_pci_warm_reset(ar);
2243 } else if (QCA_REV_99X0(ar)) {
2244 ath10k_pci_irq_disable(ar);
2245 return ath10k_pci_qca99x0_chip_reset(ar);
2246 } else {
2247 return -ENOTSUPP;
2248 }
2249}
2250
Michal Kaziord63955b2015-01-24 12:14:49 +02002251static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
Michal Kazior0bc14d02014-10-28 10:32:07 +01002252{
2253 int i, ret;
2254 u32 val;
2255
Michal Kaziord63955b2015-01-24 12:14:49 +02002256 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002257
2258 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
2259 * It is thus preferred to use warm reset which is safer but may not be
2260 * able to recover the device from all possible fail scenarios.
2261 *
2262 * Warm reset doesn't always work on first try so attempt it a few
2263 * times before giving up.
2264 */
2265 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2266 ret = ath10k_pci_warm_reset(ar);
2267 if (ret) {
2268 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
2269 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
2270 ret);
2271 continue;
2272 }
2273
2274 /* FIXME: Sometimes copy engine doesn't recover after warm
2275 * reset. In most cases this needs cold reset. In some of these
2276 * cases the device is in such a state that a cold reset may
2277 * lock up the host.
2278 *
2279 * Reading any host interest register via copy engine is
2280 * sufficient to verify if device is capable of booting
2281 * firmware blob.
2282 */
2283 ret = ath10k_pci_init_pipes(ar);
2284 if (ret) {
2285 ath10k_warn(ar, "failed to init copy engine: %d\n",
2286 ret);
2287 continue;
2288 }
2289
2290 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
2291 &val);
2292 if (ret) {
2293 ath10k_warn(ar, "failed to poke copy engine: %d\n",
2294 ret);
2295 continue;
2296 }
2297
2298 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
2299 return 0;
2300 }
2301
2302 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
2303 ath10k_warn(ar, "refusing cold reset as requested\n");
2304 return -EPERM;
2305 }
2306
2307 ret = ath10k_pci_cold_reset(ar);
2308 if (ret) {
2309 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2310 return ret;
2311 }
2312
2313 ret = ath10k_pci_wait_for_target_init(ar);
2314 if (ret) {
2315 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2316 ret);
2317 return ret;
2318 }
2319
Michal Kaziord63955b2015-01-24 12:14:49 +02002320 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002321
2322 return 0;
2323}
2324
Michal Kaziord63955b2015-01-24 12:14:49 +02002325static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
2326{
2327 int ret;
2328
2329 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
2330
2331 /* FIXME: QCA6174 requires cold + warm reset to work. */
2332
2333 ret = ath10k_pci_cold_reset(ar);
2334 if (ret) {
2335 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2336 return ret;
2337 }
2338
2339 ret = ath10k_pci_wait_for_target_init(ar);
2340 if (ret) {
2341 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
Kalle Valo617b0f42015-10-05 17:56:35 +03002342 ret);
Michal Kaziord63955b2015-01-24 12:14:49 +02002343 return ret;
2344 }
2345
2346 ret = ath10k_pci_warm_reset(ar);
2347 if (ret) {
2348 ath10k_warn(ar, "failed to warm reset: %d\n", ret);
2349 return ret;
2350 }
2351
2352 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
2353
2354 return 0;
2355}
2356
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302357static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
2358{
2359 int ret;
2360
2361 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
2362
2363 ret = ath10k_pci_cold_reset(ar);
2364 if (ret) {
2365 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2366 return ret;
2367 }
2368
2369 ret = ath10k_pci_wait_for_target_init(ar);
2370 if (ret) {
2371 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2372 ret);
2373 return ret;
2374 }
2375
2376 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
2377
2378 return 0;
2379}
2380
Michal Kaziord63955b2015-01-24 12:14:49 +02002381static int ath10k_pci_chip_reset(struct ath10k *ar)
2382{
2383 if (QCA_REV_988X(ar))
2384 return ath10k_pci_qca988x_chip_reset(ar);
2385 else if (QCA_REV_6174(ar))
2386 return ath10k_pci_qca6174_chip_reset(ar);
Bartosz Markowskia226b512015-10-28 15:09:53 +01002387 else if (QCA_REV_9377(ar))
2388 return ath10k_pci_qca6174_chip_reset(ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302389 else if (QCA_REV_99X0(ar))
2390 return ath10k_pci_qca99x0_chip_reset(ar);
Michal Kaziord63955b2015-01-24 12:14:49 +02002391 else
2392 return -ENOTSUPP;
2393}
2394
Michal Kazior0bc14d02014-10-28 10:32:07 +01002395static int ath10k_pci_hif_power_up(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002396{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002397 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002398 int ret;
2399
Michal Kazior0bc14d02014-10-28 10:32:07 +01002400 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
2401
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002402 pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2403 &ar_pci->link_ctl);
2404 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2405 ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
2406
Michal Kazior8c5c5362013-07-16 09:38:50 +02002407 /*
2408 * Bring the target up cleanly.
2409 *
2410 * The target may be in an undefined state with an AUX-powered Target
2411 * and a Host in WoW mode. If the Host crashes, loses power, or is
2412 * restarted (without unloading the driver) then the Target is left
2413 * (aux) powered and running. On a subsequent driver load, the Target
2414 * is in an unexpected state. We try to catch that here in order to
2415 * reset the Target and retry the probe.
2416 */
Michal Kazior0bc14d02014-10-28 10:32:07 +01002417 ret = ath10k_pci_chip_reset(ar);
Michal Kazior5b2589f2013-11-08 08:01:30 +01002418 if (ret) {
Michal Kaziora2fa8802015-01-12 15:29:37 +01002419 if (ath10k_pci_has_fw_crashed(ar)) {
2420 ath10k_warn(ar, "firmware crashed during chip reset\n");
2421 ath10k_pci_fw_crashed_clear(ar);
2422 ath10k_pci_fw_crashed_dump(ar);
2423 }
2424
Michal Kazior0bc14d02014-10-28 10:32:07 +01002425 ath10k_err(ar, "failed to reset chip: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002426 goto err_sleep;
Michal Kazior5b2589f2013-11-08 08:01:30 +01002427 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002428
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002429 ret = ath10k_pci_init_pipes(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002430 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002431 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002432 goto err_sleep;
Michal Kaziorab977bd2013-11-25 14:06:26 +01002433 }
2434
Michal Kazior98563d52013-11-08 08:01:33 +01002435 ret = ath10k_pci_init_config(ar);
2436 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002437 ath10k_err(ar, "failed to setup init config: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002438 goto err_ce;
Michal Kazior98563d52013-11-08 08:01:33 +01002439 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002440
2441 ret = ath10k_pci_wake_target_cpu(ar);
2442 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002443 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002444 goto err_ce;
Michal Kazior8c5c5362013-07-16 09:38:50 +02002445 }
2446
2447 return 0;
2448
2449err_ce:
2450 ath10k_pci_ce_deinit(ar);
Michal Kazior0bc14d02014-10-28 10:32:07 +01002451
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002452err_sleep:
Michal Kazior8c5c5362013-07-16 09:38:50 +02002453 return ret;
2454}
2455
2456static void ath10k_pci_hif_power_down(struct ath10k *ar)
2457{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002458 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
Bartosz Markowski8cc8df92013-08-02 09:58:49 +02002459
Michal Kaziorc011b282014-10-28 10:32:08 +01002460 /* Currently hif_power_up performs effectively a reset and hif_stop
2461 * resets the chip as well so there's no point in resetting here.
2462 */
Michal Kazior8c5c5362013-07-16 09:38:50 +02002463}
2464
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002465#ifdef CONFIG_PM
2466
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002467static int ath10k_pci_hif_suspend(struct ath10k *ar)
2468{
Michal Kazior77258d42015-05-18 09:38:18 +00002469 /* The grace timer can still be counting down and ar->ps_awake be true.
2470 * It is known that the device may be asleep after resuming regardless
2471 * of the SoC powersave state before suspending. Hence make sure the
2472 * device is asleep before proceeding.
2473 */
2474 ath10k_pci_sleep_sync(ar);
Michal Kazior320e14b2015-03-02 13:22:13 +01002475
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002476 return 0;
2477}
2478
2479static int ath10k_pci_hif_resume(struct ath10k *ar)
2480{
2481 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2482 struct pci_dev *pdev = ar_pci->pdev;
2483 u32 val;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002484 int ret = 0;
2485
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002486 ret = ath10k_pci_force_wake(ar);
2487 if (ret) {
2488 ath10k_err(ar, "failed to wake up target: %d\n", ret);
2489 return ret;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002490 }
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002491
Michal Kazior9ff4be92015-03-02 13:22:14 +01002492 /* Suspend/Resume resets the PCI configuration space, so we have to
2493 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
2494 * from interfering with C3 CPU state. pci_restore_state won't help
2495 * here since it only restores the first 64 bytes pci config header.
2496 */
2497 pci_read_config_dword(pdev, 0x40, &val);
2498 if ((val & 0x0000ff00) != 0)
2499 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002500
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002501 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002502}
2503#endif
2504
Kalle Valo5e3dd152013-06-12 20:52:10 +03002505static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
Michal Kazior726346f2014-02-27 18:50:04 +02002506 .tx_sg = ath10k_pci_hif_tx_sg,
Kalle Valoeef25402014-09-24 14:16:52 +03002507 .diag_read = ath10k_pci_hif_diag_read,
Yanbo Li9f65ad22014-11-25 12:24:48 +02002508 .diag_write = ath10k_pci_diag_write_mem,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2510 .start = ath10k_pci_hif_start,
2511 .stop = ath10k_pci_hif_stop,
2512 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2513 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2514 .send_complete_check = ath10k_pci_hif_send_complete_check,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
Michal Kazior8c5c5362013-07-16 09:38:50 +02002516 .power_up = ath10k_pci_hif_power_up,
2517 .power_down = ath10k_pci_hif_power_down,
Yanbo Li077a3802014-11-25 12:24:33 +02002518 .read32 = ath10k_pci_read32,
2519 .write32 = ath10k_pci_write32,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002520#ifdef CONFIG_PM
2521 .suspend = ath10k_pci_hif_suspend,
2522 .resume = ath10k_pci_hif_resume,
2523#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03002524};
2525
2526static void ath10k_pci_ce_tasklet(unsigned long ptr)
2527{
Michal Kazior87263e52013-08-27 13:08:01 +02002528 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002529 struct ath10k_pci *ar_pci = pipe->ar_pci;
2530
2531 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
2532}
2533
2534static void ath10k_msi_err_tasklet(unsigned long data)
2535{
2536 struct ath10k *ar = (struct ath10k *)data;
2537
Michal Kazior5c771e72014-08-22 14:23:34 +02002538 if (!ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002539 ath10k_warn(ar, "received unsolicited fw crash interrupt\n");
Michal Kazior5c771e72014-08-22 14:23:34 +02002540 return;
2541 }
2542
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002543 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002544 ath10k_pci_fw_crashed_clear(ar);
2545 ath10k_pci_fw_crashed_dump(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002546}
2547
2548/*
2549 * Handler for a per-engine interrupt on a PARTICULAR CE.
2550 * This is used in cases where each CE has a private MSI interrupt.
2551 */
2552static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
2553{
2554 struct ath10k *ar = arg;
2555 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2556 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
2557
Dan Carpentere5742672013-06-18 10:28:46 +03002558 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002559 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
2560 ce_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002561 return IRQ_HANDLED;
2562 }
2563
2564 /*
2565 * NOTE: We are able to derive ce_id from irq because we
2566 * use a one-to-one mapping for CE's 0..5.
2567 * CE's 6 & 7 do not use interrupts at all.
2568 *
2569 * This mapping must be kept in sync with the mapping
2570 * used by firmware.
2571 */
2572 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
2573 return IRQ_HANDLED;
2574}
2575
2576static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
2577{
2578 struct ath10k *ar = arg;
2579 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2580
2581 tasklet_schedule(&ar_pci->msi_fw_err);
2582 return IRQ_HANDLED;
2583}
2584
2585/*
2586 * Top-level interrupt handler for all PCI interrupts from a Target.
2587 * When a block of MSI interrupts is allocated, this top-level handler
2588 * is not used; instead, we directly call the correct sub-handler.
2589 */
2590static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2591{
2592 struct ath10k *ar = arg;
2593 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002594 int ret;
2595
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002596 ret = ath10k_pci_force_wake(ar);
2597 if (ret) {
2598 ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
2599 return IRQ_NONE;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002600 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601
2602 if (ar_pci->num_msi_intrs == 0) {
Michal Kaziore5398872013-11-25 14:06:20 +01002603 if (!ath10k_pci_irq_pending(ar))
2604 return IRQ_NONE;
2605
Michal Kazior26852182013-11-25 14:06:25 +01002606 ath10k_pci_disable_and_clear_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002607 }
2608
2609 tasklet_schedule(&ar_pci->intr_tq);
2610
2611 return IRQ_HANDLED;
2612}
2613
2614static void ath10k_pci_tasklet(unsigned long data)
2615{
2616 struct ath10k *ar = (struct ath10k *)data;
2617 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2618
Michal Kazior5c771e72014-08-22 14:23:34 +02002619 if (ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002620 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002621 ath10k_pci_fw_crashed_clear(ar);
2622 ath10k_pci_fw_crashed_dump(ar);
2623 return;
2624 }
2625
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626 ath10k_ce_per_engine_service_any(ar);
2627
Michal Kazior26852182013-11-25 14:06:25 +01002628 /* Re-enable legacy irq that was disabled in the irq handler */
2629 if (ar_pci->num_msi_intrs == 0)
2630 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002631}
2632
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002633static int ath10k_pci_request_irq_msix(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002634{
2635 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002636 int ret, i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002637
2638 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2639 ath10k_pci_msi_fw_handler,
2640 IRQF_SHARED, "ath10k_pci", ar);
Michal Kazior591ecdb2013-07-31 10:55:15 +02002641 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002642 ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n",
Michal Kazior591ecdb2013-07-31 10:55:15 +02002643 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644 return ret;
Michal Kazior591ecdb2013-07-31 10:55:15 +02002645 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002646
2647 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2648 ret = request_irq(ar_pci->pdev->irq + i,
2649 ath10k_pci_per_engine_handler,
2650 IRQF_SHARED, "ath10k_pci", ar);
2651 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002652 ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002653 ar_pci->pdev->irq + i, ret);
2654
Michal Kazior87b14232013-06-26 08:50:50 +02002655 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2656 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657
Michal Kazior87b14232013-06-26 08:50:50 +02002658 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002659 return ret;
2660 }
2661 }
2662
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 return 0;
2664}
2665
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002666static int ath10k_pci_request_irq_msi(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002667{
2668 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2669 int ret;
2670
2671 ret = request_irq(ar_pci->pdev->irq,
2672 ath10k_pci_interrupt_handler,
2673 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002674 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002675 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002676 ar_pci->pdev->irq, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002677 return ret;
Kalle Valof3782742013-10-17 11:36:15 +03002678 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679
Kalle Valo5e3dd152013-06-12 20:52:10 +03002680 return 0;
2681}
2682
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002683static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002684{
2685 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002687
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002688 ret = request_irq(ar_pci->pdev->irq,
2689 ath10k_pci_interrupt_handler,
2690 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002691 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002692 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002693 ar_pci->pdev->irq, ret);
Kalle Valof3782742013-10-17 11:36:15 +03002694 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 }
2696
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002697 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002698}
2699
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002700static int ath10k_pci_request_irq(struct ath10k *ar)
2701{
2702 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2703
2704 switch (ar_pci->num_msi_intrs) {
2705 case 0:
2706 return ath10k_pci_request_irq_legacy(ar);
2707 case 1:
2708 return ath10k_pci_request_irq_msi(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002709 default:
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002710 return ath10k_pci_request_irq_msix(ar);
2711 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002712}
2713
2714static void ath10k_pci_free_irq(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002715{
2716 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2717 int i;
2718
2719 /* There's at least one interrupt irregardless whether its legacy INTR
2720 * or MSI or MSI-X */
2721 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2722 free_irq(ar_pci->pdev->irq + i, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002723}
2724
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002725static void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
2726{
2727 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2728 int i;
2729
2730 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2731 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2732 (unsigned long)ar);
2733
2734 for (i = 0; i < CE_COUNT; i++) {
2735 ar_pci->pipe_info[i].ar_pci = ar_pci;
2736 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2737 (unsigned long)&ar_pci->pipe_info[i]);
2738 }
2739}
2740
2741static int ath10k_pci_init_irq(struct ath10k *ar)
2742{
2743 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2744 int ret;
2745
2746 ath10k_pci_init_irq_tasklets(ar);
2747
Michal Kazior403d6272014-08-22 14:23:31 +02002748 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002749 ath10k_info(ar, "limiting irq mode to: %d\n",
2750 ath10k_pci_irq_mode);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002751
2752 /* Try MSI-X */
Michal Kazior0edf2572014-08-07 11:03:29 +02002753 if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) {
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002754 ar_pci->num_msi_intrs = MSI_ASSIGN_CE_MAX + 1;
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002755 ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs,
Kalle Valo5b07e072014-09-14 12:50:06 +03002756 ar_pci->num_msi_intrs);
Alexander Gordeev5ad68672014-02-13 17:50:02 +02002757 if (ret > 0)
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002758 return 0;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002759
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002760 /* fall-through */
2761 }
2762
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002763 /* Try MSI */
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002764 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
2765 ar_pci->num_msi_intrs = 1;
2766 ret = pci_enable_msi(ar_pci->pdev);
2767 if (ret == 0)
2768 return 0;
2769
2770 /* fall-through */
2771 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002772
2773 /* Try legacy irq
2774 *
2775 * A potential race occurs here: The CORE_BASE write
2776 * depends on target correctly decoding AXI address but
2777 * host won't know when target writes BAR to CORE_CTRL.
2778 * This write might get lost if target has NOT written BAR.
2779 * For now, fix the race by repeating the write in below
2780 * synchronization checking. */
2781 ar_pci->num_msi_intrs = 0;
2782
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002783 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2784 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002785
2786 return 0;
2787}
2788
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002789static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002790{
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002791 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2792 0);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002793}
2794
2795static int ath10k_pci_deinit_irq(struct ath10k *ar)
2796{
2797 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2798
2799 switch (ar_pci->num_msi_intrs) {
2800 case 0:
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002801 ath10k_pci_deinit_irq_legacy(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002802 break;
Alexander Gordeevbb8b6212014-02-13 17:50:01 +02002803 default:
2804 pci_disable_msi(ar_pci->pdev);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002805 break;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002806 }
2807
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002808 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002809}
2810
Michal Kaziord7fb47f2013-11-08 08:01:26 +01002811static int ath10k_pci_wait_for_target_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002812{
2813 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo0399eca2014-03-28 09:32:21 +02002814 unsigned long timeout;
Kalle Valo0399eca2014-03-28 09:32:21 +02002815 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002816
Michal Kazior7aa7a722014-08-25 12:09:38 +02002817 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002818
Kalle Valo0399eca2014-03-28 09:32:21 +02002819 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2820
2821 do {
2822 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2823
Michal Kazior7aa7a722014-08-25 12:09:38 +02002824 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2825 val);
Kalle Valo50f87a62014-03-28 09:32:52 +02002826
Kalle Valo0399eca2014-03-28 09:32:21 +02002827 /* target should never return this */
2828 if (val == 0xffffffff)
2829 continue;
2830
Michal Kazior7710cd22014-04-23 19:30:04 +03002831 /* the device has crashed so don't bother trying anymore */
2832 if (val & FW_IND_EVENT_PENDING)
2833 break;
2834
Kalle Valo0399eca2014-03-28 09:32:21 +02002835 if (val & FW_IND_INITIALIZED)
2836 break;
2837
Kalle Valo5e3dd152013-06-12 20:52:10 +03002838 if (ar_pci->num_msi_intrs == 0)
2839 /* Fix potential race by repeating CORE_BASE writes */
Michal Kaziora4282492014-10-20 14:14:37 +02002840 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002841
Kalle Valo0399eca2014-03-28 09:32:21 +02002842 mdelay(10);
2843 } while (time_before(jiffies, timeout));
2844
Michal Kaziora4282492014-10-20 14:14:37 +02002845 ath10k_pci_disable_and_clear_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02002846 ath10k_pci_irq_msi_fw_mask(ar);
Michal Kaziora4282492014-10-20 14:14:37 +02002847
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002848 if (val == 0xffffffff) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002849 ath10k_err(ar, "failed to read device register, device is gone\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002850 return -EIO;
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002851 }
2852
Michal Kazior7710cd22014-04-23 19:30:04 +03002853 if (val & FW_IND_EVENT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002854 ath10k_warn(ar, "device has crashed during init\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002855 return -ECOMM;
Michal Kazior7710cd22014-04-23 19:30:04 +03002856 }
2857
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002858 if (!(val & FW_IND_INITIALIZED)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002859 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
Kalle Valo0399eca2014-03-28 09:32:21 +02002860 val);
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002861 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002862 }
2863
Michal Kazior7aa7a722014-08-25 12:09:38 +02002864 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002865 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866}
2867
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002868static int ath10k_pci_cold_reset(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002870 u32 val;
2871
Michal Kazior7aa7a722014-08-25 12:09:38 +02002872 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873
Ben Greearf51dbe72014-09-29 14:41:46 +03002874 spin_lock_bh(&ar->data_lock);
2875
2876 ar->stats.fw_cold_reset_counter++;
2877
2878 spin_unlock_bh(&ar->data_lock);
2879
Kalle Valo5e3dd152013-06-12 20:52:10 +03002880 /* Put Target, including PCIe, into RESET. */
Kalle Valoe479ed42013-09-01 10:01:53 +03002881 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002882 val |= 1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002883 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002884
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302885 /* After writing into SOC_GLOBAL_RESET to put device into
2886 * reset and pulling out of reset pcie may not be stable
2887 * for any immediate pcie register access and cause bus error,
2888 * add delay before any pcie access request to fix this issue.
2889 */
2890 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002891
2892 /* Pull Target, including PCIe, out of RESET. */
2893 val &= ~1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002894 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002895
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302896 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002897
Michal Kazior7aa7a722014-08-25 12:09:38 +02002898 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02002899
Michal Kazior5b2589f2013-11-08 08:01:30 +01002900 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901}
2902
Michal Kazior2986e3e2014-08-07 11:03:30 +02002903static int ath10k_pci_claim(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904{
Michal Kazior2986e3e2014-08-07 11:03:30 +02002905 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2906 struct pci_dev *pdev = ar_pci->pdev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002907 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002908
2909 pci_set_drvdata(pdev, ar);
2910
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911 ret = pci_enable_device(pdev);
2912 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002913 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002914 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915 }
2916
Kalle Valo5e3dd152013-06-12 20:52:10 +03002917 ret = pci_request_region(pdev, BAR_NUM, "ath");
2918 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002919 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
Michal Kazior2986e3e2014-08-07 11:03:30 +02002920 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921 goto err_device;
2922 }
2923
Michal Kazior2986e3e2014-08-07 11:03:30 +02002924 /* Target expects 32 bit DMA. Enforce it. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2926 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002927 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928 goto err_region;
2929 }
2930
2931 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2932 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002933 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
Michal Kazior2986e3e2014-08-07 11:03:30 +02002934 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002935 goto err_region;
2936 }
2937
Kalle Valo5e3dd152013-06-12 20:52:10 +03002938 pci_set_master(pdev);
2939
Kalle Valo5e3dd152013-06-12 20:52:10 +03002940 /* Arrange for access to Target SoC registers. */
Michal Kazioraeae5b42015-06-15 14:46:42 +03002941 ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002942 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
2943 if (!ar_pci->mem) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002945 ret = -EIO;
2946 goto err_master;
2947 }
2948
Michal Kazior7aa7a722014-08-25 12:09:38 +02002949 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002950 return 0;
2951
2952err_master:
2953 pci_clear_master(pdev);
2954
2955err_region:
2956 pci_release_region(pdev, BAR_NUM);
2957
2958err_device:
2959 pci_disable_device(pdev);
2960
2961 return ret;
2962}
2963
2964static void ath10k_pci_release(struct ath10k *ar)
2965{
2966 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2967 struct pci_dev *pdev = ar_pci->pdev;
2968
2969 pci_iounmap(pdev, ar_pci->mem);
2970 pci_release_region(pdev, BAR_NUM);
2971 pci_clear_master(pdev);
2972 pci_disable_device(pdev);
2973}
2974
Michal Kazior7505f7c2014-12-02 10:55:54 +02002975static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
2976{
2977 const struct ath10k_pci_supp_chip *supp_chip;
2978 int i;
2979 u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
2980
2981 for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
2982 supp_chip = &ath10k_pci_supp_chips[i];
2983
2984 if (supp_chip->dev_id == dev_id &&
2985 supp_chip->rev_id == rev_id)
2986 return true;
2987 }
2988
2989 return false;
2990}
2991
Kalle Valo5e3dd152013-06-12 20:52:10 +03002992static int ath10k_pci_probe(struct pci_dev *pdev,
2993 const struct pci_device_id *pci_dev)
2994{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002995 int ret = 0;
2996 struct ath10k *ar;
2997 struct ath10k_pci *ar_pci;
Michal Kaziord63955b2015-01-24 12:14:49 +02002998 enum ath10k_hw_rev hw_rev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002999 u32 chip_id;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003000 bool pci_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001
Michal Kaziord63955b2015-01-24 12:14:49 +02003002 switch (pci_dev->device) {
3003 case QCA988X_2_0_DEVICE_ID:
3004 hw_rev = ATH10K_HW_QCA988X;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003005 pci_ps = false;
Michal Kaziord63955b2015-01-24 12:14:49 +02003006 break;
Michal Kazior36582e52015-08-13 14:32:26 +02003007 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02003008 case QCA6174_2_1_DEVICE_ID:
3009 hw_rev = ATH10K_HW_QCA6174;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003010 pci_ps = true;
Michal Kaziord63955b2015-01-24 12:14:49 +02003011 break;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303012 case QCA99X0_2_0_DEVICE_ID:
3013 hw_rev = ATH10K_HW_QCA99X0;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003014 pci_ps = false;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303015 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01003016 case QCA9377_1_0_DEVICE_ID:
3017 hw_rev = ATH10K_HW_QCA9377;
3018 pci_ps = true;
3019 break;
Michal Kaziord63955b2015-01-24 12:14:49 +02003020 default:
3021 WARN_ON(1);
3022 return -ENOTSUPP;
3023 }
3024
3025 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
3026 hw_rev, &ath10k_pci_hif_ops);
Michal Kaziore7b54192014-08-07 11:03:27 +02003027 if (!ar) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003028 dev_err(&pdev->dev, "failed to allocate core\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003029 return -ENOMEM;
Michal Kaziore7b54192014-08-07 11:03:27 +02003030 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003031
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003032 ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
3033 pdev->vendor, pdev->device,
3034 pdev->subsystem_vendor, pdev->subsystem_device);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003035
Michal Kaziore7b54192014-08-07 11:03:27 +02003036 ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003037 ar_pci->pdev = pdev;
3038 ar_pci->dev = &pdev->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003039 ar_pci->ar = ar;
Michal Kazior36582e52015-08-13 14:32:26 +02003040 ar->dev_id = pci_dev->device;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003041 ar_pci->pci_ps = pci_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003042
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003043 ar->id.vendor = pdev->vendor;
3044 ar->id.device = pdev->device;
3045 ar->id.subsystem_vendor = pdev->subsystem_vendor;
3046 ar->id.subsystem_device = pdev->subsystem_device;
Michal Kaziorde57e2c2015-04-17 09:19:17 +00003047
Kalle Valo5e3dd152013-06-12 20:52:10 +03003048 spin_lock_init(&ar_pci->ce_lock);
Michal Kazior77258d42015-05-18 09:38:18 +00003049 spin_lock_init(&ar_pci->ps_lock);
3050
Michal Kazior728f95e2014-08-22 14:33:14 +02003051 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
3052 (unsigned long)ar);
Michal Kazior77258d42015-05-18 09:38:18 +00003053 setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
3054 (unsigned long)ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003055
Michal Kazior2986e3e2014-08-07 11:03:30 +02003056 ret = ath10k_pci_claim(ar);
Kalle Valoe01ae682013-09-01 11:22:14 +03003057 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_err(ar, "failed to claim device: %d\n", ret);
Michal Kaziore7b54192014-08-07 11:03:27 +02003059 goto err_core_destroy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003060 }
3061
Ryan Hsu2727a742015-11-05 18:44:27 -08003062 if (QCA_REV_6174(ar))
3063 ath10k_pci_override_ce_config(ar);
3064
Michal Kazior84cbf3a2014-10-20 14:14:39 +02003065 ret = ath10k_pci_alloc_pipes(ar);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02003066 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003067 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
3068 ret);
Michal Kaziorc0c378f2014-08-07 11:03:28 +02003069 goto err_sleep;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02003070 }
3071
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02003072 ret = ath10k_pci_force_wake(ar);
3073 if (ret) {
3074 ath10k_warn(ar, "failed to wake up device : %d\n", ret);
3075 goto err_free_pipes;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003076 }
3077
Rajkumar Manoharanaa538ac2015-12-16 16:52:19 +02003078 ath10k_pci_ce_deinit(ar);
3079 ath10k_pci_irq_disable(ar);
3080
Michal Kazior403d6272014-08-22 14:23:31 +02003081 ret = ath10k_pci_init_irq(ar);
3082 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003083 ath10k_err(ar, "failed to init irqs: %d\n", ret);
Michal Kazior84cbf3a2014-10-20 14:14:39 +02003084 goto err_free_pipes;
Michal Kazior403d6272014-08-22 14:23:31 +02003085 }
3086
Michal Kazior7aa7a722014-08-25 12:09:38 +02003087 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
Michal Kazior403d6272014-08-22 14:23:31 +02003088 ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs,
3089 ath10k_pci_irq_mode, ath10k_pci_reset_mode);
3090
Michal Kazior5c771e72014-08-22 14:23:34 +02003091 ret = ath10k_pci_request_irq(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003092 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003093 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
Michal Kazior403d6272014-08-22 14:23:31 +02003094 goto err_deinit_irq;
3095 }
3096
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003097 ret = ath10k_pci_chip_reset(ar);
3098 if (ret) {
3099 ath10k_err(ar, "failed to reset chip: %d\n", ret);
3100 goto err_free_irq;
3101 }
3102
3103 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
3104 if (chip_id == 0xffffffff) {
3105 ath10k_err(ar, "failed to get chip id\n");
3106 goto err_free_irq;
3107 }
3108
3109 if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
3110 ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
3111 pdev->device, chip_id);
Michal Kaziord9585a92015-04-10 13:01:27 +00003112 goto err_free_irq;
Michal Kazior1a7fecb2015-01-24 12:14:48 +02003113 }
3114
Kalle Valoe01ae682013-09-01 11:22:14 +03003115 ret = ath10k_core_register(ar, chip_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003117 ath10k_err(ar, "failed to register driver core: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02003118 goto err_free_irq;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003119 }
3120
3121 return 0;
3122
Michal Kazior5c771e72014-08-22 14:23:34 +02003123err_free_irq:
3124 ath10k_pci_free_irq(ar);
Michal Kazior21396272014-08-28 10:24:40 +02003125 ath10k_pci_kill_tasklet(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003126
Michal Kazior403d6272014-08-22 14:23:31 +02003127err_deinit_irq:
3128 ath10k_pci_deinit_irq(ar);
3129
Michal Kazior84cbf3a2014-10-20 14:14:39 +02003130err_free_pipes:
3131 ath10k_pci_free_pipes(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003132
Michal Kaziorc0c378f2014-08-07 11:03:28 +02003133err_sleep:
Michal Kazior0bcbbe62015-05-29 07:35:24 +02003134 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003135 ath10k_pci_release(ar);
3136
Michal Kaziore7b54192014-08-07 11:03:27 +02003137err_core_destroy:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003138 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139
3140 return ret;
3141}
3142
3143static void ath10k_pci_remove(struct pci_dev *pdev)
3144{
3145 struct ath10k *ar = pci_get_drvdata(pdev);
3146 struct ath10k_pci *ar_pci;
3147
Michal Kazior7aa7a722014-08-25 12:09:38 +02003148 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003149
3150 if (!ar)
3151 return;
3152
3153 ar_pci = ath10k_pci_priv(ar);
3154
3155 if (!ar_pci)
3156 return;
3157
Kalle Valo5e3dd152013-06-12 20:52:10 +03003158 ath10k_core_unregister(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02003159 ath10k_pci_free_irq(ar);
Michal Kazior21396272014-08-28 10:24:40 +02003160 ath10k_pci_kill_tasklet(ar);
Michal Kazior403d6272014-08-22 14:23:31 +02003161 ath10k_pci_deinit_irq(ar);
3162 ath10k_pci_ce_deinit(ar);
Michal Kazior84cbf3a2014-10-20 14:14:39 +02003163 ath10k_pci_free_pipes(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00003164 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003165 ath10k_pci_release(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003166 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003167}
3168
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
3170
3171static struct pci_driver ath10k_pci_driver = {
3172 .name = "ath10k_pci",
3173 .id_table = ath10k_pci_id_table,
3174 .probe = ath10k_pci_probe,
3175 .remove = ath10k_pci_remove,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003176};
3177
3178static int __init ath10k_pci_init(void)
3179{
3180 int ret;
3181
3182 ret = pci_register_driver(&ath10k_pci_driver);
3183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003184 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
3185 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003186
3187 return ret;
3188}
3189module_init(ath10k_pci_init);
3190
3191static void __exit ath10k_pci_exit(void)
3192{
3193 pci_unregister_driver(&ath10k_pci_driver);
3194}
3195
3196module_exit(ath10k_pci_exit);
3197
3198MODULE_AUTHOR("Qualcomm Atheros");
3199MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
3200MODULE_LICENSE("Dual BSD/GPL");
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003201
3202/* QCA988x 2.0 firmware files */
Bartosz Markowski8026cae2014-10-06 14:16:41 +02003203MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
3204MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
3205MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003206MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Kalle Valo53513c32015-03-25 13:12:42 +02003207MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003209MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003210
3211/* QCA6174 2.1 firmware files */
3212MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003213MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003214MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003215MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003216
3217/* QCA6174 3.1 firmware files */
3218MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003219MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003220MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003221MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowskia226b512015-10-28 15:09:53 +01003222
3223/* QCA9377 1.0 firmware files */
3224MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3225MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);