blob: 6109293e1213e95c7cbb1e854162df1a9fe3f7a6 [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
Kalle Valo35098462014-03-28 09:32:27 +020036enum ath10k_pci_reset_mode {
37 ATH10K_PCI_RESET_AUTO = 0,
38 ATH10K_PCI_RESET_WARM_ONLY = 1,
39};
40
Michal Kaziorcfe9c452013-11-25 14:06:27 +010041static unsigned int ath10k_pci_irq_mode = ATH10K_PCI_IRQ_AUTO;
Kalle Valo35098462014-03-28 09:32:27 +020042static unsigned int ath10k_pci_reset_mode = ATH10K_PCI_RESET_AUTO;
Michal Kaziorcfe9c452013-11-25 14:06:27 +010043
Michal Kaziorcfe9c452013-11-25 14:06:27 +010044module_param_named(irq_mode, ath10k_pci_irq_mode, uint, 0644);
45MODULE_PARM_DESC(irq_mode, "0: auto, 1: legacy, 2: msi (default: 0)");
46
Kalle Valo35098462014-03-28 09:32:27 +020047module_param_named(reset_mode, ath10k_pci_reset_mode, uint, 0644);
48MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)");
49
Kalle Valo0399eca2014-03-28 09:32:21 +020050/* how long wait to wait for target to initialise, in ms */
51#define ATH10K_PCI_TARGET_WAIT 3000
Michal Kazior61c95ce2014-05-14 16:56:16 +030052#define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3
Kalle Valo0399eca2014-03-28 09:32:21 +020053
Benoit Taine9baa3c32014-08-08 15:56:03 +020054static const struct pci_device_id ath10k_pci_id_table[] = {
Kalle Valo5e3dd152013-06-12 20:52:10 +030055 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
Michal Kazior36582e52015-08-13 14:32:26 +020056 { PCI_VDEVICE(ATHEROS, QCA6164_2_1_DEVICE_ID) }, /* PCI-E QCA6164 V2.1 */
Michal Kaziord63955b2015-01-24 12:14:49 +020057 { PCI_VDEVICE(ATHEROS, QCA6174_2_1_DEVICE_ID) }, /* PCI-E QCA6174 V2.1 */
Vasanthakumar Thiagarajan8a055a82015-07-29 11:40:39 +030058 { PCI_VDEVICE(ATHEROS, QCA99X0_2_0_DEVICE_ID) }, /* PCI-E QCA99X0 V2 */
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +030059 { PCI_VDEVICE(ATHEROS, QCA9984_1_0_DEVICE_ID) }, /* PCI-E QCA9984 V1 */
Bartosz Markowskia226b512015-10-28 15:09:53 +010060 { PCI_VDEVICE(ATHEROS, QCA9377_1_0_DEVICE_ID) }, /* PCI-E QCA9377 V1 */
Kalle Valo5e3dd152013-06-12 20:52:10 +030061 {0}
62};
63
Michal Kazior7505f7c2014-12-02 10:55:54 +020064static const struct ath10k_pci_supp_chip ath10k_pci_supp_chips[] = {
65 /* QCA988X pre 2.0 chips are not supported because they need some nasty
66 * hacks. ath10k doesn't have them and these devices crash horribly
67 * because of that.
68 */
69 { QCA988X_2_0_DEVICE_ID, QCA988X_HW_2_0_CHIP_ID_REV },
Michal Kazior36582e52015-08-13 14:32:26 +020070
71 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
72 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
73 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
74 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
75 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
76
Michal Kaziord63955b2015-01-24 12:14:49 +020077 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
78 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
79 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
80 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
81 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
Michal Kazior36582e52015-08-13 14:32:26 +020082
Vasanthakumar Thiagarajan8a055a82015-07-29 11:40:39 +030083 { QCA99X0_2_0_DEVICE_ID, QCA99X0_HW_2_0_CHIP_ID_REV },
Bartosz Markowski034074f2015-11-05 09:50:43 +010084
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +030085 { QCA9984_1_0_DEVICE_ID, QCA9984_HW_1_0_CHIP_ID_REV },
86
Bartosz Markowski034074f2015-11-05 09:50:43 +010087 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_0_CHIP_ID_REV },
Bartosz Markowski12551ce2015-11-05 09:50:40 +010088 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_1_CHIP_ID_REV },
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +030089
Michal Kazior7505f7c2014-12-02 10:55:54 +020090};
91
Michal Kazior728f95e2014-08-22 14:33:14 +020092static void ath10k_pci_buffer_cleanup(struct ath10k *ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +010093static int ath10k_pci_cold_reset(struct ath10k *ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +053094static int ath10k_pci_safe_chip_reset(struct ath10k *ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +010095static int ath10k_pci_init_irq(struct ath10k *ar);
96static int ath10k_pci_deinit_irq(struct ath10k *ar);
97static int ath10k_pci_request_irq(struct ath10k *ar);
98static void ath10k_pci_free_irq(struct ath10k *ar);
Michal Kazior85622cd2013-11-25 14:06:22 +010099static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
100 struct ath10k_ce_pipe *rx_pipe,
101 struct bmi_xfer *xfer);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +0530102static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar);
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530103static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530104static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530105static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
106static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530107static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530108static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300109
Ryan Hsu2727a742015-11-05 18:44:27 -0800110static struct ce_attr host_ce_config_wlan[] = {
Kalle Valo48e9c222013-09-01 10:01:32 +0300111 /* CE0: host->target HTC control and raw streams */
112 {
113 .flags = CE_ATTR_FLAGS,
114 .src_nentries = 16,
115 .src_sz_max = 256,
116 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530117 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300118 },
119
120 /* CE1: target->host HTT + HTC control */
121 {
122 .flags = CE_ATTR_FLAGS,
123 .src_nentries = 0,
Michal Kazior63838642015-02-09 15:04:55 +0100124 .src_sz_max = 2048,
Kalle Valo48e9c222013-09-01 10:01:32 +0300125 .dest_nentries = 512,
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +0530126 .recv_cb = ath10k_pci_htt_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300127 },
128
129 /* CE2: target->host WMI */
130 {
131 .flags = CE_ATTR_FLAGS,
132 .src_nentries = 0,
133 .src_sz_max = 2048,
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200134 .dest_nentries = 128,
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +0530135 .recv_cb = ath10k_pci_htc_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300136 },
137
138 /* CE3: host->target WMI */
139 {
140 .flags = CE_ATTR_FLAGS,
141 .src_nentries = 32,
142 .src_sz_max = 2048,
143 .dest_nentries = 0,
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +0530144 .send_cb = ath10k_pci_htc_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300145 },
146
147 /* CE4: host->target HTT */
148 {
149 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
150 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
151 .src_sz_max = 256,
152 .dest_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530153 .send_cb = ath10k_pci_htt_tx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300154 },
155
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530156 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valo48e9c222013-09-01 10:01:32 +0300157 {
158 .flags = CE_ATTR_FLAGS,
159 .src_nentries = 0,
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530160 .src_sz_max = 512,
161 .dest_nentries = 512,
162 .recv_cb = ath10k_pci_htt_rx_cb,
Kalle Valo48e9c222013-09-01 10:01:32 +0300163 },
164
165 /* CE6: target autonomous hif_memcpy */
166 {
167 .flags = CE_ATTR_FLAGS,
168 .src_nentries = 0,
169 .src_sz_max = 0,
170 .dest_nentries = 0,
171 },
172
173 /* CE7: ce_diag, the Diagnostic Window */
174 {
175 .flags = CE_ATTR_FLAGS,
176 .src_nentries = 2,
177 .src_sz_max = DIAG_TRANSFER_LIMIT,
178 .dest_nentries = 2,
179 },
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530180
181 /* CE8: target->host pktlog */
182 {
183 .flags = CE_ATTR_FLAGS,
184 .src_nentries = 0,
185 .src_sz_max = 2048,
186 .dest_nentries = 128,
Vivek Natarajanafb0bf72015-10-30 14:57:58 +0530187 .recv_cb = ath10k_pci_pktlog_rx_cb,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530188 },
189
190 /* CE9 target autonomous qcache memcpy */
191 {
192 .flags = CE_ATTR_FLAGS,
193 .src_nentries = 0,
194 .src_sz_max = 0,
195 .dest_nentries = 0,
196 },
197
198 /* CE10: target autonomous hif memcpy */
199 {
200 .flags = CE_ATTR_FLAGS,
201 .src_nentries = 0,
202 .src_sz_max = 0,
203 .dest_nentries = 0,
204 },
205
206 /* CE11: target autonomous hif memcpy */
207 {
208 .flags = CE_ATTR_FLAGS,
209 .src_nentries = 0,
210 .src_sz_max = 0,
211 .dest_nentries = 0,
212 },
Kalle Valo5e3dd152013-06-12 20:52:10 +0300213};
214
215/* Target firmware's Copy Engine configuration. */
Ryan Hsu2727a742015-11-05 18:44:27 -0800216static struct ce_pipe_config target_ce_config_wlan[] = {
Kalle Valod88effb2013-09-01 10:01:39 +0300217 /* CE0: host->target HTC control and raw streams */
218 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300219 .pipenum = __cpu_to_le32(0),
220 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
221 .nentries = __cpu_to_le32(32),
222 .nbytes_max = __cpu_to_le32(256),
223 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
224 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300225 },
226
227 /* CE1: target->host HTT + HTC control */
228 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300229 .pipenum = __cpu_to_le32(1),
230 .pipedir = __cpu_to_le32(PIPEDIR_IN),
231 .nentries = __cpu_to_le32(32),
Michal Kazior63838642015-02-09 15:04:55 +0100232 .nbytes_max = __cpu_to_le32(2048),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300233 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
234 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300235 },
236
237 /* CE2: target->host WMI */
238 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300239 .pipenum = __cpu_to_le32(2),
240 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Rajkumar Manoharan30abb332015-03-04 15:43:44 +0200241 .nentries = __cpu_to_le32(64),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300242 .nbytes_max = __cpu_to_le32(2048),
243 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
244 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300245 },
246
247 /* CE3: host->target WMI */
248 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300249 .pipenum = __cpu_to_le32(3),
250 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
251 .nentries = __cpu_to_le32(32),
252 .nbytes_max = __cpu_to_le32(2048),
253 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
254 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300255 },
256
257 /* CE4: host->target HTT */
258 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300259 .pipenum = __cpu_to_le32(4),
260 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
261 .nentries = __cpu_to_le32(256),
262 .nbytes_max = __cpu_to_le32(256),
263 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
264 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300265 },
266
Kalle Valo5e3dd152013-06-12 20:52:10 +0300267 /* NB: 50% of src nentries, since tx has 2 frags */
Kalle Valod88effb2013-09-01 10:01:39 +0300268
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530269 /* CE5: target->host HTT (HIF->HTT) */
Kalle Valod88effb2013-09-01 10:01:39 +0300270 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300271 .pipenum = __cpu_to_le32(5),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530272 .pipedir = __cpu_to_le32(PIPEDIR_IN),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300273 .nentries = __cpu_to_le32(32),
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530274 .nbytes_max = __cpu_to_le32(512),
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300275 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
276 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300277 },
278
279 /* CE6: Reserved for target autonomous hif_memcpy */
280 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300281 .pipenum = __cpu_to_le32(6),
282 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
283 .nentries = __cpu_to_le32(32),
284 .nbytes_max = __cpu_to_le32(4096),
285 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
286 .reserved = __cpu_to_le32(0),
Kalle Valod88effb2013-09-01 10:01:39 +0300287 },
288
Kalle Valo5e3dd152013-06-12 20:52:10 +0300289 /* CE7 used only by Host */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +0530290 {
291 .pipenum = __cpu_to_le32(7),
292 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
293 .nentries = __cpu_to_le32(0),
294 .nbytes_max = __cpu_to_le32(0),
295 .flags = __cpu_to_le32(0),
296 .reserved = __cpu_to_le32(0),
297 },
298
299 /* CE8 target->host packtlog */
300 {
301 .pipenum = __cpu_to_le32(8),
302 .pipedir = __cpu_to_le32(PIPEDIR_IN),
303 .nentries = __cpu_to_le32(64),
304 .nbytes_max = __cpu_to_le32(2048),
305 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
306 .reserved = __cpu_to_le32(0),
307 },
308
309 /* CE9 target autonomous qcache memcpy */
310 {
311 .pipenum = __cpu_to_le32(9),
312 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
313 .nentries = __cpu_to_le32(32),
314 .nbytes_max = __cpu_to_le32(2048),
315 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
316 .reserved = __cpu_to_le32(0),
317 },
318
319 /* It not necessary to send target wlan configuration for CE10 & CE11
320 * as these CEs are not actively used in target.
321 */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300322};
323
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300324/*
325 * Map from service/endpoint to Copy Engine.
326 * This table is derived from the CE_PCI TABLE, above.
327 * It is passed to the Target at startup for use by firmware.
328 */
Ryan Hsu2727a742015-11-05 18:44:27 -0800329static struct service_to_pipe target_service_to_ce_map_wlan[] = {
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300330 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300331 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
332 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
333 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300334 },
335 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300336 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
337 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
338 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300339 },
340 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300341 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
342 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
343 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300344 },
345 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300346 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
347 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
348 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300349 },
350 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300351 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
352 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
353 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300354 },
355 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300356 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
357 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
358 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300359 },
360 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300361 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
362 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
363 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300364 },
365 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300366 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
367 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
368 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300369 },
370 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300371 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
372 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
373 __cpu_to_le32(3),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300374 },
375 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300376 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
377 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
378 __cpu_to_le32(2),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300379 },
380 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300381 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
382 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
383 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300384 },
385 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300386 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
387 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
388 __cpu_to_le32(1),
389 },
390 { /* not used */
391 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
392 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
393 __cpu_to_le32(0),
394 },
395 { /* not used */
396 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
397 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
398 __cpu_to_le32(1),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300399 },
400 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300401 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
402 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
403 __cpu_to_le32(4),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300404 },
405 {
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300406 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
407 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
Rajkumar Manoharana70587b2015-10-12 18:27:04 +0530408 __cpu_to_le32(5),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300409 },
410
411 /* (Additions here) */
412
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300413 { /* must be last */
414 __cpu_to_le32(0),
415 __cpu_to_le32(0),
416 __cpu_to_le32(0),
Michal Kaziord7bfb7a2014-08-26 19:14:02 +0300417 },
418};
419
Michal Kazior77258d42015-05-18 09:38:18 +0000420static bool ath10k_pci_is_awake(struct ath10k *ar)
421{
422 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
423 u32 val = ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
424 RTC_STATE_ADDRESS);
425
426 return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
427}
428
429static void __ath10k_pci_wake(struct ath10k *ar)
430{
431 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
432
433 lockdep_assert_held(&ar_pci->ps_lock);
434
435 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake reg refcount %lu awake %d\n",
436 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
437
438 iowrite32(PCIE_SOC_WAKE_V_MASK,
439 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
440 PCIE_SOC_WAKE_ADDRESS);
441}
442
443static void __ath10k_pci_sleep(struct ath10k *ar)
444{
445 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
446
447 lockdep_assert_held(&ar_pci->ps_lock);
448
449 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep reg refcount %lu awake %d\n",
450 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
451
452 iowrite32(PCIE_SOC_WAKE_RESET,
453 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
454 PCIE_SOC_WAKE_ADDRESS);
455 ar_pci->ps_awake = false;
456}
457
458static int ath10k_pci_wake_wait(struct ath10k *ar)
459{
460 int tot_delay = 0;
461 int curr_delay = 5;
462
463 while (tot_delay < PCIE_WAKE_TIMEOUT) {
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300464 if (ath10k_pci_is_awake(ar)) {
465 if (tot_delay > PCIE_WAKE_LATE_US)
466 ath10k_warn(ar, "device wakeup took %d ms which is unusally long, otherwise it works normally.\n",
467 tot_delay / 1000);
Michal Kazior77258d42015-05-18 09:38:18 +0000468 return 0;
Maharaja Kennadyrajan39b91b82015-10-06 15:19:28 +0300469 }
Michal Kazior77258d42015-05-18 09:38:18 +0000470
471 udelay(curr_delay);
472 tot_delay += curr_delay;
473
474 if (curr_delay < 50)
475 curr_delay += 5;
476 }
477
478 return -ETIMEDOUT;
479}
480
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300481static int ath10k_pci_force_wake(struct ath10k *ar)
482{
483 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
484 unsigned long flags;
485 int ret = 0;
486
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +0200487 if (ar_pci->pci_ps)
488 return ret;
489
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300490 spin_lock_irqsave(&ar_pci->ps_lock, flags);
491
492 if (!ar_pci->ps_awake) {
493 iowrite32(PCIE_SOC_WAKE_V_MASK,
494 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
495 PCIE_SOC_WAKE_ADDRESS);
496
497 ret = ath10k_pci_wake_wait(ar);
498 if (ret == 0)
499 ar_pci->ps_awake = true;
500 }
501
502 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
503
504 return ret;
505}
506
507static void ath10k_pci_force_sleep(struct ath10k *ar)
508{
509 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
510 unsigned long flags;
511
512 spin_lock_irqsave(&ar_pci->ps_lock, flags);
513
514 iowrite32(PCIE_SOC_WAKE_RESET,
515 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
516 PCIE_SOC_WAKE_ADDRESS);
517 ar_pci->ps_awake = false;
518
519 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
520}
521
Michal Kazior77258d42015-05-18 09:38:18 +0000522static int ath10k_pci_wake(struct ath10k *ar)
523{
524 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
525 unsigned long flags;
526 int ret = 0;
527
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300528 if (ar_pci->pci_ps == 0)
529 return ret;
530
Michal Kazior77258d42015-05-18 09:38:18 +0000531 spin_lock_irqsave(&ar_pci->ps_lock, flags);
532
533 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake refcount %lu awake %d\n",
534 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
535
536 /* This function can be called very frequently. To avoid excessive
537 * CPU stalls for MMIO reads use a cache var to hold the device state.
538 */
539 if (!ar_pci->ps_awake) {
540 __ath10k_pci_wake(ar);
541
542 ret = ath10k_pci_wake_wait(ar);
543 if (ret == 0)
544 ar_pci->ps_awake = true;
545 }
546
547 if (ret == 0) {
548 ar_pci->ps_wake_refcount++;
549 WARN_ON(ar_pci->ps_wake_refcount == 0);
550 }
551
552 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
553
554 return ret;
555}
556
557static void ath10k_pci_sleep(struct ath10k *ar)
558{
559 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
560 unsigned long flags;
561
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300562 if (ar_pci->pci_ps == 0)
563 return;
564
Michal Kazior77258d42015-05-18 09:38:18 +0000565 spin_lock_irqsave(&ar_pci->ps_lock, flags);
566
567 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep refcount %lu awake %d\n",
568 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
569
570 if (WARN_ON(ar_pci->ps_wake_refcount == 0))
571 goto skip;
572
573 ar_pci->ps_wake_refcount--;
574
575 mod_timer(&ar_pci->ps_timer, jiffies +
576 msecs_to_jiffies(ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC));
577
578skip:
579 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
580}
581
582static void ath10k_pci_ps_timer(unsigned long ptr)
583{
584 struct ath10k *ar = (void *)ptr;
585 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
586 unsigned long flags;
587
588 spin_lock_irqsave(&ar_pci->ps_lock, flags);
589
590 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps timer refcount %lu awake %d\n",
591 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
592
593 if (ar_pci->ps_wake_refcount > 0)
594 goto skip;
595
596 __ath10k_pci_sleep(ar);
597
598skip:
599 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
600}
601
602static void ath10k_pci_sleep_sync(struct ath10k *ar)
603{
604 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
605 unsigned long flags;
606
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +0300607 if (ar_pci->pci_ps == 0) {
608 ath10k_pci_force_sleep(ar);
609 return;
610 }
611
Michal Kazior77258d42015-05-18 09:38:18 +0000612 del_timer_sync(&ar_pci->ps_timer);
613
614 spin_lock_irqsave(&ar_pci->ps_lock, flags);
615 WARN_ON(ar_pci->ps_wake_refcount > 0);
616 __ath10k_pci_sleep(ar);
617 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
618}
619
Raja Mani4ddb3292016-01-27 15:24:23 +0530620static void ath10k_bus_pci_write32(struct ath10k *ar, u32 offset, u32 value)
Michal Kazior77258d42015-05-18 09:38:18 +0000621{
622 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
623 int ret;
624
Michal Kazioraeae5b42015-06-15 14:46:42 +0300625 if (unlikely(offset + sizeof(value) > ar_pci->mem_len)) {
626 ath10k_warn(ar, "refusing to write mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
627 offset, offset + sizeof(value), ar_pci->mem_len);
628 return;
629 }
630
Michal Kazior77258d42015-05-18 09:38:18 +0000631 ret = ath10k_pci_wake(ar);
632 if (ret) {
633 ath10k_warn(ar, "failed to wake target for write32 of 0x%08x at 0x%08x: %d\n",
634 value, offset, ret);
635 return;
636 }
637
638 iowrite32(value, ar_pci->mem + offset);
639 ath10k_pci_sleep(ar);
640}
641
Raja Mani4ddb3292016-01-27 15:24:23 +0530642static u32 ath10k_bus_pci_read32(struct ath10k *ar, u32 offset)
Michal Kazior77258d42015-05-18 09:38:18 +0000643{
644 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
645 u32 val;
646 int ret;
647
Michal Kazioraeae5b42015-06-15 14:46:42 +0300648 if (unlikely(offset + sizeof(val) > ar_pci->mem_len)) {
649 ath10k_warn(ar, "refusing to read mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
650 offset, offset + sizeof(val), ar_pci->mem_len);
651 return 0;
652 }
653
Michal Kazior77258d42015-05-18 09:38:18 +0000654 ret = ath10k_pci_wake(ar);
655 if (ret) {
656 ath10k_warn(ar, "failed to wake target for read32 at 0x%08x: %d\n",
657 offset, ret);
658 return 0xffffffff;
659 }
660
661 val = ioread32(ar_pci->mem + offset);
662 ath10k_pci_sleep(ar);
663
664 return val;
665}
666
Raja Mani4ddb3292016-01-27 15:24:23 +0530667inline void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value)
668{
669 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
670
671 ar_pci->bus_ops->write32(ar, offset, value);
672}
673
674inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
675{
676 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
677
678 return ar_pci->bus_ops->read32(ar, offset);
679}
680
Michal Kazior77258d42015-05-18 09:38:18 +0000681u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
682{
683 return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
684}
685
686void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
687{
688 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
689}
690
691u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
692{
693 return ath10k_pci_read32(ar, PCIE_LOCAL_BASE_ADDRESS + addr);
694}
695
696void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
697{
698 ath10k_pci_write32(ar, PCIE_LOCAL_BASE_ADDRESS + addr, val);
699}
700
Raja Manif52f5172016-01-27 15:24:22 +0530701bool ath10k_pci_irq_pending(struct ath10k *ar)
Michal Kaziore5398872013-11-25 14:06:20 +0100702{
703 u32 cause;
704
705 /* Check if the shared legacy irq is for us */
706 cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
707 PCIE_INTR_CAUSE_ADDRESS);
708 if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
709 return true;
710
711 return false;
712}
713
Raja Manif52f5172016-01-27 15:24:22 +0530714void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
Michal Kazior26852182013-11-25 14:06:25 +0100715{
716 /* IMPORTANT: INTR_CLR register has to be set after
717 * INTR_ENABLE is set to 0, otherwise interrupt can not be
718 * really cleared. */
719 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
720 0);
721 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
722 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
723
724 /* IMPORTANT: this extra read transaction is required to
725 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300726 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
727 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100728}
729
Raja Manif52f5172016-01-27 15:24:22 +0530730void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
Michal Kazior26852182013-11-25 14:06:25 +0100731{
732 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
733 PCIE_INTR_ENABLE_ADDRESS,
734 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
735
736 /* IMPORTANT: this extra read transaction is required to
737 * flush the posted write buffer. */
Kalle Valocfbc06a2014-09-14 12:50:23 +0300738 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
739 PCIE_INTR_ENABLE_ADDRESS);
Michal Kazior26852182013-11-25 14:06:25 +0100740}
741
Michal Kazior403d6272014-08-22 14:23:31 +0200742static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100743{
Michal Kaziorab977bd2013-11-25 14:06:26 +0100744 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
745
Rajkumar Manoharancfe90112016-04-07 12:10:58 +0530746 if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_MSI)
Michal Kazior403d6272014-08-22 14:23:31 +0200747 return "msi";
Kalle Valod8bb26b2014-09-14 12:50:33 +0300748
749 return "legacy";
Michal Kaziorab977bd2013-11-25 14:06:26 +0100750}
751
Michal Kazior728f95e2014-08-22 14:33:14 +0200752static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100753{
Michal Kazior728f95e2014-08-22 14:33:14 +0200754 struct ath10k *ar = pipe->hif_ce_state;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100755 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +0200756 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
757 struct sk_buff *skb;
758 dma_addr_t paddr;
Michal Kaziorab977bd2013-11-25 14:06:26 +0100759 int ret;
760
Michal Kazior728f95e2014-08-22 14:33:14 +0200761 skb = dev_alloc_skb(pipe->buf_sz);
762 if (!skb)
763 return -ENOMEM;
764
765 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
766
767 paddr = dma_map_single(ar->dev, skb->data,
768 skb->len + skb_tailroom(skb),
769 DMA_FROM_DEVICE);
770 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200771 ath10k_warn(ar, "failed to dma map pci rx buf\n");
Michal Kazior728f95e2014-08-22 14:33:14 +0200772 dev_kfree_skb_any(skb);
773 return -EIO;
774 }
775
Michal Kazior8582bf32015-01-24 12:14:47 +0200776 ATH10K_SKB_RXCB(skb)->paddr = paddr;
Michal Kazior728f95e2014-08-22 14:33:14 +0200777
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300778 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200779 ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300780 spin_unlock_bh(&ar_pci->ce_lock);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100781 if (ret) {
Michal Kazior728f95e2014-08-22 14:33:14 +0200782 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
783 DMA_FROM_DEVICE);
784 dev_kfree_skb_any(skb);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100785 return ret;
786 }
787
788 return 0;
789}
790
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300791static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
Michal Kaziorab977bd2013-11-25 14:06:26 +0100792{
Michal Kazior728f95e2014-08-22 14:33:14 +0200793 struct ath10k *ar = pipe->hif_ce_state;
794 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
795 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
796 int ret, num;
797
Michal Kazior728f95e2014-08-22 14:33:14 +0200798 if (pipe->buf_sz == 0)
799 return;
800
801 if (!ce_pipe->dest_ring)
802 return;
803
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300804 spin_lock_bh(&ar_pci->ce_lock);
Michal Kazior728f95e2014-08-22 14:33:14 +0200805 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300806 spin_unlock_bh(&ar_pci->ce_lock);
Rajkumar Manoharan128abd02016-03-22 17:22:18 +0530807
808 while (num >= 0) {
Michal Kazior728f95e2014-08-22 14:33:14 +0200809 ret = __ath10k_pci_rx_post_buf(pipe);
810 if (ret) {
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300811 if (ret == -ENOSPC)
812 break;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200813 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
Michal Kazior728f95e2014-08-22 14:33:14 +0200814 mod_timer(&ar_pci->rx_post_retry, jiffies +
815 ATH10K_PCI_RX_POST_RETRY_MS);
816 break;
817 }
Rajkumar Manoharan128abd02016-03-22 17:22:18 +0530818 num--;
Michal Kazior728f95e2014-08-22 14:33:14 +0200819 }
820}
821
Raja Manif52f5172016-01-27 15:24:22 +0530822void ath10k_pci_rx_post(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +0200823{
824 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
825 int i;
826
Michal Kazior728f95e2014-08-22 14:33:14 +0200827 for (i = 0; i < CE_COUNT; i++)
Rajkumar Manoharanab4e3db2015-10-06 15:19:33 +0300828 ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
Michal Kazior728f95e2014-08-22 14:33:14 +0200829}
830
Raja Manif52f5172016-01-27 15:24:22 +0530831void ath10k_pci_rx_replenish_retry(unsigned long ptr)
Michal Kazior728f95e2014-08-22 14:33:14 +0200832{
833 struct ath10k *ar = (void *)ptr;
834
835 ath10k_pci_rx_post(ar);
Michal Kaziorab977bd2013-11-25 14:06:26 +0100836}
837
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530838static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
839{
840 u32 val = 0;
841
842 switch (ar->hw_rev) {
843 case ATH10K_HW_QCA988X:
844 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +0100845 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530846 val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
847 CORE_CTRL_ADDRESS) &
Vasanthakumar Thiagarajan3c7e2562015-07-03 19:25:27 +0530848 0x7ff) << 21;
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530849 break;
850 case ATH10K_HW_QCA99X0:
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +0300851 case ATH10K_HW_QCA9984:
Raja Mani0b523ce2016-01-27 15:24:25 +0530852 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530853 val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
854 break;
855 }
856
857 val |= 0x100000 | (addr & 0xfffff);
858 return val;
859}
860
Kalle Valo5e3dd152013-06-12 20:52:10 +0300861/*
862 * Diagnostic read/write access is provided for startup/config/debug usage.
863 * Caller must guarantee proper alignment, when applicable, and single user
864 * at any moment.
865 */
866static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
867 int nbytes)
868{
869 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
870 int ret = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530871 u32 *buf;
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300872 unsigned int completed_nbytes, alloc_nbytes, remaining_bytes;
Michal Kazior2aa39112013-08-27 13:08:02 +0200873 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300874 /* Host buffer address in CE space */
875 u32 ce_data;
876 dma_addr_t ce_data_base = 0;
877 void *data_buf = NULL;
878 int i;
879
Kalle Valoeef25402014-09-24 14:16:52 +0300880 spin_lock_bh(&ar_pci->ce_lock);
881
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 ce_diag = ar_pci->ce_diag;
883
884 /*
885 * Allocate a temporary bounce buffer to hold caller's data
886 * to be DMA'ed from Target. This guarantees
887 * 1) 4-byte alignment
888 * 2) Buffer in DMA-able space
889 */
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300890 alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT);
891
Michal Kazior68c03242014-03-28 10:02:35 +0200892 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300893 alloc_nbytes,
Michal Kazior68c03242014-03-28 10:02:35 +0200894 &ce_data_base,
895 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300896
897 if (!data_buf) {
898 ret = -ENOMEM;
899 goto done;
900 }
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300901 memset(data_buf, 0, alloc_nbytes);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300902
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300903 remaining_bytes = nbytes;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300904 ce_data = ce_data_base;
905 while (remaining_bytes) {
906 nbytes = min_t(unsigned int, remaining_bytes,
907 DIAG_TRANSFER_LIMIT);
908
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530909 ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, ce_data);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300910 if (ret != 0)
911 goto done;
912
913 /* Request CE to send from Target(!) address to Host buffer */
914 /*
915 * The address supplied by the caller is in the
916 * Target CPU virtual address space.
917 *
918 * In order to use this address with the diagnostic CE,
919 * convert it from Target CPU virtual address space
920 * to CE address space
921 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +0530922 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300923
Kalle Valoeef25402014-09-24 14:16:52 +0300924 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
925 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926 if (ret)
927 goto done;
928
929 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +0530930 while (ath10k_ce_completed_send_next_nolock(ce_diag,
931 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 mdelay(1);
933 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
934 ret = -EBUSY;
935 goto done;
936 }
937 }
938
Kalle Valo5e3dd152013-06-12 20:52:10 +0300939 i = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530940 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
941 (void **)&buf,
942 &completed_nbytes)
943 != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944 mdelay(1);
945
946 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
947 ret = -EBUSY;
948 goto done;
949 }
950 }
951
952 if (nbytes != completed_nbytes) {
953 ret = -EIO;
954 goto done;
955 }
956
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +0530957 if (*buf != ce_data) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300958 ret = -EIO;
959 goto done;
960 }
961
962 remaining_bytes -= nbytes;
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300963
964 if (ret) {
965 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
966 address, ret);
967 break;
968 }
969 memcpy(data, data_buf, nbytes);
970
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 address += nbytes;
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300972 data += nbytes;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300973 }
974
975done:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300976
977 if (data_buf)
Ashok Raj Nagarajan1e56d512016-05-28 11:25:40 +0300978 dma_free_coherent(ar->dev, alloc_nbytes, data_buf,
Michal Kazior68c03242014-03-28 10:02:35 +0200979 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980
Kalle Valoeef25402014-09-24 14:16:52 +0300981 spin_unlock_bh(&ar_pci->ce_lock);
982
Kalle Valo5e3dd152013-06-12 20:52:10 +0300983 return ret;
984}
985
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300986static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
987{
Michal Kazior0fdc14e42014-08-26 19:14:03 +0300988 __le32 val = 0;
989 int ret;
990
991 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
992 *value = __le32_to_cpu(val);
993
994 return ret;
Kalle Valo3d29a3e2014-08-25 08:37:26 +0300995}
996
997static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
998 u32 src, u32 len)
999{
1000 u32 host_addr, addr;
1001 int ret;
1002
1003 host_addr = host_interest_item_address(src);
1004
1005 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
1006 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001007 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001008 src, ret);
1009 return ret;
1010 }
1011
1012 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
1013 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001014 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001015 addr, len, ret);
1016 return ret;
1017 }
1018
1019 return 0;
1020}
1021
1022#define ath10k_pci_diag_read_hi(ar, dest, src, len) \
Kalle Valo8cc7f262014-09-14 12:50:39 +03001023 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001024
Raja Manif52f5172016-01-27 15:24:22 +05301025int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
1026 const void *data, int nbytes)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001027{
1028 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1029 int ret = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301030 u32 *buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001031 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
Michal Kazior2aa39112013-08-27 13:08:02 +02001032 struct ath10k_ce_pipe *ce_diag;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001033 void *data_buf = NULL;
1034 u32 ce_data; /* Host buffer address in CE space */
1035 dma_addr_t ce_data_base = 0;
1036 int i;
1037
Kalle Valoeef25402014-09-24 14:16:52 +03001038 spin_lock_bh(&ar_pci->ce_lock);
1039
Kalle Valo5e3dd152013-06-12 20:52:10 +03001040 ce_diag = ar_pci->ce_diag;
1041
1042 /*
1043 * Allocate a temporary bounce buffer to hold caller's data
1044 * to be DMA'ed to Target. This guarantees
1045 * 1) 4-byte alignment
1046 * 2) Buffer in DMA-able space
1047 */
1048 orig_nbytes = nbytes;
Michal Kazior68c03242014-03-28 10:02:35 +02001049 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
1050 orig_nbytes,
1051 &ce_data_base,
1052 GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001053 if (!data_buf) {
1054 ret = -ENOMEM;
1055 goto done;
1056 }
1057
1058 /* Copy caller's data to allocated DMA buf */
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001059 memcpy(data_buf, data, orig_nbytes);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001060
1061 /*
1062 * The address supplied by the caller is in the
1063 * Target CPU virtual address space.
1064 *
1065 * In order to use this address with the diagnostic CE,
1066 * convert it from
1067 * Target CPU virtual address space
1068 * to
1069 * CE address space
1070 */
Vasanthakumar Thiagarajan418ca592015-06-18 12:31:05 +05301071 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001072
1073 remaining_bytes = orig_nbytes;
1074 ce_data = ce_data_base;
1075 while (remaining_bytes) {
1076 /* FIXME: check cast */
1077 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
1078
1079 /* Set up to receive directly into Target(!) address */
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301080 ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001081 if (ret != 0)
1082 goto done;
1083
1084 /*
1085 * Request CE to send caller-supplied data that
1086 * was copied to bounce buffer to Target(!) address.
1087 */
Kalle Valoeef25402014-09-24 14:16:52 +03001088 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
1089 nbytes, 0, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090 if (ret != 0)
1091 goto done;
1092
1093 i = 0;
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301094 while (ath10k_ce_completed_send_next_nolock(ce_diag,
1095 NULL) != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001096 mdelay(1);
1097
1098 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1099 ret = -EBUSY;
1100 goto done;
1101 }
1102 }
1103
Kalle Valo5e3dd152013-06-12 20:52:10 +03001104 i = 0;
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301105 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
1106 (void **)&buf,
1107 &completed_nbytes)
1108 != 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001109 mdelay(1);
1110
1111 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1112 ret = -EBUSY;
1113 goto done;
1114 }
1115 }
1116
1117 if (nbytes != completed_nbytes) {
1118 ret = -EIO;
1119 goto done;
1120 }
1121
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301122 if (*buf != address) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 ret = -EIO;
1124 goto done;
1125 }
1126
1127 remaining_bytes -= nbytes;
1128 address += nbytes;
1129 ce_data += nbytes;
1130 }
1131
1132done:
1133 if (data_buf) {
Michal Kazior68c03242014-03-28 10:02:35 +02001134 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
1135 ce_data_base);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 }
1137
1138 if (ret != 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001139 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
Kalle Valo50f87a62014-03-28 09:32:52 +02001140 address, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001141
Kalle Valoeef25402014-09-24 14:16:52 +03001142 spin_unlock_bh(&ar_pci->ce_lock);
1143
Kalle Valo5e3dd152013-06-12 20:52:10 +03001144 return ret;
1145}
1146
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001147static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
1148{
1149 __le32 val = __cpu_to_le32(value);
1150
1151 return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
1152}
1153
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154/* Called by lower (CE) layer when a send to Target completes. */
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301155static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001156{
1157 struct ath10k *ar = ce_state->ar;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001158 struct sk_buff_head list;
1159 struct sk_buff *skb;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001160
Michal Kazior1cb86d42014-11-27 11:09:38 +01001161 __skb_queue_head_init(&list);
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301162 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Michal Kaziora16942e2014-02-27 18:50:04 +02001163 /* no need to call tx completion for NULL pointers */
Michal Kazior1cb86d42014-11-27 11:09:38 +01001164 if (skb == NULL)
Michal Kazior726346f2014-02-27 18:50:04 +02001165 continue;
1166
Michal Kazior1cb86d42014-11-27 11:09:38 +01001167 __skb_queue_tail(&list, skb);
Michal Kazior5440ce22013-09-03 15:09:58 +02001168 }
Michal Kazior1cb86d42014-11-27 11:09:38 +01001169
1170 while ((skb = __skb_dequeue(&list)))
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301171 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172}
1173
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301174static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
1175 void (*callback)(struct ath10k *ar,
1176 struct sk_buff *skb))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177{
1178 struct ath10k *ar = ce_state->ar;
1179 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior87263e52013-08-27 13:08:01 +02001180 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001181 struct sk_buff *skb;
Michal Kazior1cb86d42014-11-27 11:09:38 +01001182 struct sk_buff_head list;
Michal Kazior5440ce22013-09-03 15:09:58 +02001183 void *transfer_context;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001184 unsigned int nbytes, max_nbytes;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001185
Michal Kazior1cb86d42014-11-27 11:09:38 +01001186 __skb_queue_head_init(&list);
Michal Kazior5440ce22013-09-03 15:09:58 +02001187 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301188 &nbytes) == 0) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189 skb = transfer_context;
Michal Kazior2f5280d2014-02-27 18:50:05 +02001190 max_nbytes = skb->len + skb_tailroom(skb);
Michal Kazior8582bf32015-01-24 12:14:47 +02001191 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior2f5280d2014-02-27 18:50:05 +02001192 max_nbytes, DMA_FROM_DEVICE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193
Michal Kazior2f5280d2014-02-27 18:50:05 +02001194 if (unlikely(max_nbytes < nbytes)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001195 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
Michal Kazior2f5280d2014-02-27 18:50:05 +02001196 nbytes, max_nbytes);
1197 dev_kfree_skb_any(skb);
1198 continue;
1199 }
1200
1201 skb_put(skb, nbytes);
Michal Kazior1cb86d42014-11-27 11:09:38 +01001202 __skb_queue_tail(&list, skb);
1203 }
Michal Kaziora360e542014-09-23 10:22:54 +02001204
Michal Kazior1cb86d42014-11-27 11:09:38 +01001205 while ((skb = __skb_dequeue(&list))) {
Michal Kaziora360e542014-09-23 10:22:54 +02001206 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1207 ce_state->id, skb->len);
1208 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1209 skb->data, skb->len);
1210
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301211 callback(ar, skb);
Michal Kazior2f5280d2014-02-27 18:50:05 +02001212 }
Michal Kaziorc29a3802014-07-21 21:03:10 +03001213
Michal Kazior728f95e2014-08-22 14:33:14 +02001214 ath10k_pci_rx_post_pipe(pipe_info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001215}
1216
Rajkumar Manoharan128abd02016-03-22 17:22:18 +05301217static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
1218 void (*callback)(struct ath10k *ar,
1219 struct sk_buff *skb))
1220{
1221 struct ath10k *ar = ce_state->ar;
1222 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1223 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
1224 struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
1225 struct sk_buff *skb;
1226 struct sk_buff_head list;
1227 void *transfer_context;
1228 unsigned int nbytes, max_nbytes, nentries;
1229 int orig_len;
1230
1231 /* No need to aquire ce_lock for CE5, since this is the only place CE5
1232 * is processed other than init and deinit. Before releasing CE5
1233 * buffers, interrupts are disabled. Thus CE5 access is serialized.
1234 */
1235 __skb_queue_head_init(&list);
1236 while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
1237 &nbytes) == 0) {
1238 skb = transfer_context;
1239 max_nbytes = skb->len + skb_tailroom(skb);
1240
1241 if (unlikely(max_nbytes < nbytes)) {
1242 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
1243 nbytes, max_nbytes);
1244 continue;
1245 }
1246
1247 dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1248 max_nbytes, DMA_FROM_DEVICE);
1249 skb_put(skb, nbytes);
1250 __skb_queue_tail(&list, skb);
1251 }
1252
1253 nentries = skb_queue_len(&list);
1254 while ((skb = __skb_dequeue(&list))) {
1255 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1256 ce_state->id, skb->len);
1257 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1258 skb->data, skb->len);
1259
1260 orig_len = skb->len;
1261 callback(ar, skb);
1262 skb_push(skb, orig_len - skb->len);
1263 skb_reset_tail_pointer(skb);
1264 skb_trim(skb, 0);
1265
1266 /*let device gain the buffer again*/
1267 dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1268 skb->len + skb_tailroom(skb),
1269 DMA_FROM_DEVICE);
1270 }
1271 ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
1272}
1273
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301274/* Called by lower (CE) layer when data is received from the Target. */
1275static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1276{
1277 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1278}
1279
Rajkumar Manoharan6419fdb2015-11-11 17:31:26 +05301280static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1281{
1282 /* CE4 polling needs to be done whenever CE pipe which transports
1283 * HTT Rx (target->host) is processed.
1284 */
1285 ath10k_ce_per_engine_service(ce_state->ar, 4);
1286
1287 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1288}
1289
Vivek Natarajanafb0bf72015-10-30 14:57:58 +05301290/* Called by lower (CE) layer when data is received from the Target.
1291 * Only 10.4 firmware uses separate CE to transfer pktlog data.
1292 */
1293static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
1294{
1295 ath10k_pci_process_rx_cb(ce_state,
1296 ath10k_htt_rx_pktlog_completion_handler);
1297}
1298
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301299/* Called by lower (CE) layer when a send to HTT Target completes. */
1300static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
1301{
1302 struct ath10k *ar = ce_state->ar;
1303 struct sk_buff *skb;
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301304
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301305 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301306 /* no need to call tx completion for NULL pointers */
1307 if (!skb)
1308 continue;
1309
1310 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1311 skb->len, DMA_TO_DEVICE);
1312 ath10k_htt_hif_tx_complete(ar, skb);
1313 }
1314}
1315
1316static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
1317{
1318 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
1319 ath10k_htt_t2h_msg_handler(ar, skb);
1320}
1321
1322/* Called by lower (CE) layer when HTT data is received from the Target. */
1323static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
1324{
1325 /* CE4 polling needs to be done whenever CE pipe which transports
1326 * HTT Rx (target->host) is processed.
1327 */
1328 ath10k_ce_per_engine_service(ce_state->ar, 4);
1329
Rajkumar Manoharan128abd02016-03-22 17:22:18 +05301330 ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
Rajkumar Manoharana70587b2015-10-12 18:27:04 +05301331}
1332
Raja Manif52f5172016-01-27 15:24:22 +05301333int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
1334 struct ath10k_hif_sg_item *items, int n_items)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior726346f2014-02-27 18:50:04 +02001337 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
1338 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
1339 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
Michal Kazior7147a132014-05-26 12:02:58 +02001340 unsigned int nentries_mask;
1341 unsigned int sw_index;
1342 unsigned int write_index;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001343 int err, i = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344
Michal Kazior726346f2014-02-27 18:50:04 +02001345 spin_lock_bh(&ar_pci->ce_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346
Michal Kazior7147a132014-05-26 12:02:58 +02001347 nentries_mask = src_ring->nentries_mask;
1348 sw_index = src_ring->sw_index;
1349 write_index = src_ring->write_index;
1350
Michal Kazior726346f2014-02-27 18:50:04 +02001351 if (unlikely(CE_RING_DELTA(nentries_mask,
1352 write_index, sw_index - 1) < n_items)) {
1353 err = -ENOBUFS;
Michal Kazior08b8aa02014-05-26 12:02:59 +02001354 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001355 }
1356
1357 for (i = 0; i < n_items - 1; i++) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001358 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001359 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1360 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001361 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001362 items[i].vaddr, items[i].len);
1363
1364 err = ath10k_ce_send_nolock(ce_pipe,
1365 items[i].transfer_context,
1366 items[i].paddr,
1367 items[i].len,
1368 items[i].transfer_id,
1369 CE_SEND_FLAG_GATHER);
1370 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001371 goto err;
Michal Kazior726346f2014-02-27 18:50:04 +02001372 }
1373
1374 /* `i` is equal to `n_items -1` after for() */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001375
Michal Kazior7aa7a722014-08-25 12:09:38 +02001376 ath10k_dbg(ar, ATH10K_DBG_PCI,
Michal Kazior726346f2014-02-27 18:50:04 +02001377 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1378 i, items[i].paddr, items[i].len, n_items);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001379 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
Michal Kazior726346f2014-02-27 18:50:04 +02001380 items[i].vaddr, items[i].len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381
Michal Kazior726346f2014-02-27 18:50:04 +02001382 err = ath10k_ce_send_nolock(ce_pipe,
1383 items[i].transfer_context,
1384 items[i].paddr,
1385 items[i].len,
1386 items[i].transfer_id,
1387 0);
1388 if (err)
Michal Kazior08b8aa02014-05-26 12:02:59 +02001389 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390
Michal Kazior08b8aa02014-05-26 12:02:59 +02001391 spin_unlock_bh(&ar_pci->ce_lock);
1392 return 0;
1393
1394err:
1395 for (; i > 0; i--)
1396 __ath10k_ce_send_revert(ce_pipe);
1397
Michal Kazior726346f2014-02-27 18:50:04 +02001398 spin_unlock_bh(&ar_pci->ce_lock);
1399 return err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400}
1401
Raja Manif52f5172016-01-27 15:24:22 +05301402int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
1403 size_t buf_len)
Kalle Valoeef25402014-09-24 14:16:52 +03001404{
1405 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
1406}
1407
Raja Manif52f5172016-01-27 15:24:22 +05301408u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409{
1410 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001411
Michal Kazior7aa7a722014-08-25 12:09:38 +02001412 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001413
Michal Kazior3efcb3b2013-10-02 11:03:41 +02001414 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001415}
1416
Ben Greear384914b2014-08-25 08:37:32 +03001417static void ath10k_pci_dump_registers(struct ath10k *ar,
1418 struct ath10k_fw_crash_data *crash_data)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001419{
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001420 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
1421 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001422
Ben Greear384914b2014-08-25 08:37:32 +03001423 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001424
Kalle Valo3d29a3e2014-08-25 08:37:26 +03001425 ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
1426 hi_failure_state,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001427 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001429 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001430 return;
1431 }
1432
1433 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
1434
Michal Kazior7aa7a722014-08-25 12:09:38 +02001435 ath10k_err(ar, "firmware register dump:\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001437 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438 i,
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001439 __le32_to_cpu(reg_dump_values[i]),
1440 __le32_to_cpu(reg_dump_values[i + 1]),
1441 __le32_to_cpu(reg_dump_values[i + 2]),
1442 __le32_to_cpu(reg_dump_values[i + 3]));
Michal Kazioraffd3212013-07-16 09:54:35 +02001443
Michal Kazior1bbb1192014-08-25 12:13:14 +02001444 if (!crash_data)
1445 return;
1446
Ben Greear384914b2014-08-25 08:37:32 +03001447 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001448 crash_data->registers[i] = reg_dump_values[i];
Ben Greear384914b2014-08-25 08:37:32 +03001449}
1450
Kalle Valo0e9848c2014-08-25 08:37:37 +03001451static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
Ben Greear384914b2014-08-25 08:37:32 +03001452{
1453 struct ath10k_fw_crash_data *crash_data;
1454 char uuid[50];
1455
1456 spin_lock_bh(&ar->data_lock);
1457
Ben Greearf51dbe72014-09-29 14:41:46 +03001458 ar->stats.fw_crash_counter++;
1459
Ben Greear384914b2014-08-25 08:37:32 +03001460 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
1461
1462 if (crash_data)
1463 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
1464 else
1465 scnprintf(uuid, sizeof(uuid), "n/a");
1466
Michal Kazior7aa7a722014-08-25 12:09:38 +02001467 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
Kalle Valo8a0c7972014-08-25 08:37:45 +03001468 ath10k_print_driver_info(ar);
Ben Greear384914b2014-08-25 08:37:32 +03001469 ath10k_pci_dump_registers(ar, crash_data);
1470
Ben Greear384914b2014-08-25 08:37:32 +03001471 spin_unlock_bh(&ar->data_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02001472
Michal Kazior5e90de82013-10-16 16:46:05 +03001473 queue_work(ar->workqueue, &ar->restart_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474}
1475
Raja Manif52f5172016-01-27 15:24:22 +05301476void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1477 int force)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001479 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001480
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481 if (!force) {
1482 int resources;
1483 /*
1484 * Decide whether to actually poll for completions, or just
1485 * wait for a later chance.
1486 * If there seem to be plenty of resources left, then just wait
1487 * since checking involves reading a CE register, which is a
1488 * relatively expensive operation.
1489 */
1490 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1491
1492 /*
1493 * If at least 50% of the total resources are still available,
1494 * don't bother checking again yet.
1495 */
1496 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1497 return;
1498 }
1499 ath10k_ce_per_engine_service(ar, pipe);
1500}
1501
Raja Manif52f5172016-01-27 15:24:22 +05301502void ath10k_pci_kill_tasklet(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001503{
1504 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001505
Kalle Valo5e3dd152013-06-12 20:52:10 +03001506 tasklet_kill(&ar_pci->intr_tq);
Michal Kazior728f95e2014-08-22 14:33:14 +02001507
1508 del_timer_sync(&ar_pci->rx_post_retry);
Michal Kazior96a9d0d2013-11-08 08:01:25 +01001509}
1510
Raja Manif52f5172016-01-27 15:24:22 +05301511int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
1512 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513{
Michal Kazior7c6aa252014-08-26 19:14:03 +03001514 const struct service_to_pipe *entry;
1515 bool ul_set = false, dl_set = false;
1516 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001517
Michal Kazior7aa7a722014-08-25 12:09:38 +02001518 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001519
Michal Kazior7c6aa252014-08-26 19:14:03 +03001520 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1521 entry = &target_service_to_ce_map_wlan[i];
Kalle Valo5e3dd152013-06-12 20:52:10 +03001522
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001523 if (__le32_to_cpu(entry->service_id) != service_id)
Michal Kazior7c6aa252014-08-26 19:14:03 +03001524 continue;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001525
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001526 switch (__le32_to_cpu(entry->pipedir)) {
Michal Kazior7c6aa252014-08-26 19:14:03 +03001527 case PIPEDIR_NONE:
1528 break;
1529 case PIPEDIR_IN:
1530 WARN_ON(dl_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001531 *dl_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001532 dl_set = true;
1533 break;
1534 case PIPEDIR_OUT:
1535 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001536 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001537 ul_set = true;
1538 break;
1539 case PIPEDIR_INOUT:
1540 WARN_ON(dl_set);
1541 WARN_ON(ul_set);
Michal Kazior0fdc14e42014-08-26 19:14:03 +03001542 *dl_pipe = __le32_to_cpu(entry->pipenum);
1543 *ul_pipe = __le32_to_cpu(entry->pipenum);
Michal Kazior7c6aa252014-08-26 19:14:03 +03001544 dl_set = true;
1545 ul_set = true;
1546 break;
1547 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 }
Michal Kazior7c6aa252014-08-26 19:14:03 +03001549
1550 if (WARN_ON(!ul_set || !dl_set))
1551 return -ENOENT;
1552
Michal Kazior7c6aa252014-08-26 19:14:03 +03001553 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554}
1555
Raja Manif52f5172016-01-27 15:24:22 +05301556void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1557 u8 *ul_pipe, u8 *dl_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001559 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02001560
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1562 ATH10K_HTC_SVC_ID_RSVD_CTRL,
Rajkumar Manoharan400143e2015-10-12 18:27:06 +05301563 ul_pipe, dl_pipe);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001564}
1565
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001566static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1567{
1568 u32 val;
1569
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301570 switch (ar->hw_rev) {
1571 case ATH10K_HW_QCA988X:
1572 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001573 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301574 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1575 CORE_CTRL_ADDRESS);
1576 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1577 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1578 CORE_CTRL_ADDRESS, val);
1579 break;
1580 case ATH10K_HW_QCA99X0:
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +03001581 case ATH10K_HW_QCA9984:
Raja Mani0b523ce2016-01-27 15:24:25 +05301582 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301583 /* TODO: Find appropriate register configuration for QCA99X0
1584 * to mask irq/MSI.
1585 */
1586 break;
1587 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001588}
1589
1590static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1591{
1592 u32 val;
1593
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301594 switch (ar->hw_rev) {
1595 case ATH10K_HW_QCA988X:
1596 case ATH10K_HW_QCA6174:
Bartosz Markowskia226b512015-10-28 15:09:53 +01001597 case ATH10K_HW_QCA9377:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301598 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1599 CORE_CTRL_ADDRESS);
1600 val |= CORE_CTRL_PCIE_REG_31_MASK;
1601 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1602 CORE_CTRL_ADDRESS, val);
1603 break;
1604 case ATH10K_HW_QCA99X0:
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +03001605 case ATH10K_HW_QCA9984:
Raja Mani0b523ce2016-01-27 15:24:25 +05301606 case ATH10K_HW_QCA4019:
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301607 /* TODO: Find appropriate register configuration for QCA99X0
1608 * to unmask irq/MSI.
1609 */
1610 break;
1611 }
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001612}
1613
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001614static void ath10k_pci_irq_disable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615{
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001616 ath10k_ce_disable_interrupts(ar);
1617 ath10k_pci_disable_and_clear_legacy_irq(ar);
1618 ath10k_pci_irq_msi_fw_mask(ar);
1619}
1620
1621static void ath10k_pci_irq_sync(struct ath10k *ar)
1622{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05301625 synchronize_irq(ar_pci->pdev->irq);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626}
1627
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001628static void ath10k_pci_irq_enable(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629{
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001630 ath10k_ce_enable_interrupts(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001631 ath10k_pci_enable_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001632 ath10k_pci_irq_msi_fw_unmask(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633}
1634
1635static int ath10k_pci_hif_start(struct ath10k *ar)
1636{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001637 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo9a149692015-10-05 17:56:36 +03001638
Michal Kazior7aa7a722014-08-25 12:09:38 +02001639 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640
Michal Kaziorec5ba4d2014-08-22 14:23:33 +02001641 ath10k_pci_irq_enable(ar);
Michal Kazior728f95e2014-08-22 14:33:14 +02001642 ath10k_pci_rx_post(ar);
Kalle Valo50f87a62014-03-28 09:32:52 +02001643
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00001644 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
1645 ar_pci->link_ctl);
1646
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 return 0;
1648}
1649
Michal Kazior099ac7c2014-10-28 10:32:05 +01001650static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001651{
1652 struct ath10k *ar;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001653 struct ath10k_ce_pipe *ce_pipe;
1654 struct ath10k_ce_ring *ce_ring;
1655 struct sk_buff *skb;
1656 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001657
Michal Kazior099ac7c2014-10-28 10:32:05 +01001658 ar = pci_pipe->hif_ce_state;
1659 ce_pipe = pci_pipe->ce_hdl;
1660 ce_ring = ce_pipe->dest_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661
Michal Kazior099ac7c2014-10-28 10:32:05 +01001662 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001663 return;
1664
Michal Kazior099ac7c2014-10-28 10:32:05 +01001665 if (!pci_pipe->buf_sz)
1666 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001667
Michal Kazior099ac7c2014-10-28 10:32:05 +01001668 for (i = 0; i < ce_ring->nentries; i++) {
1669 skb = ce_ring->per_transfer_context[i];
1670 if (!skb)
1671 continue;
1672
1673 ce_ring->per_transfer_context[i] = NULL;
1674
Michal Kazior8582bf32015-01-24 12:14:47 +02001675 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
Michal Kazior099ac7c2014-10-28 10:32:05 +01001676 skb->len + skb_tailroom(skb),
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677 DMA_FROM_DEVICE);
Michal Kazior099ac7c2014-10-28 10:32:05 +01001678 dev_kfree_skb_any(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 }
1680}
1681
Michal Kazior099ac7c2014-10-28 10:32:05 +01001682static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683{
1684 struct ath10k *ar;
1685 struct ath10k_pci *ar_pci;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001686 struct ath10k_ce_pipe *ce_pipe;
1687 struct ath10k_ce_ring *ce_ring;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001688 struct sk_buff *skb;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001689 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690
Michal Kazior099ac7c2014-10-28 10:32:05 +01001691 ar = pci_pipe->hif_ce_state;
1692 ar_pci = ath10k_pci_priv(ar);
1693 ce_pipe = pci_pipe->ce_hdl;
1694 ce_ring = ce_pipe->src_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
Michal Kazior099ac7c2014-10-28 10:32:05 +01001696 if (!ce_ring)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 return;
1698
Michal Kazior099ac7c2014-10-28 10:32:05 +01001699 if (!pci_pipe->buf_sz)
1700 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701
Michal Kazior099ac7c2014-10-28 10:32:05 +01001702 for (i = 0; i < ce_ring->nentries; i++) {
1703 skb = ce_ring->per_transfer_context[i];
1704 if (!skb)
Michal Kazior2415fc12013-11-08 08:01:32 +01001705 continue;
Michal Kazior2415fc12013-11-08 08:01:32 +01001706
Michal Kazior099ac7c2014-10-28 10:32:05 +01001707 ce_ring->per_transfer_context[i] = NULL;
Michal Kazior099ac7c2014-10-28 10:32:05 +01001708
Rajkumar Manoharan0e5b2952015-10-12 18:27:01 +05301709 ath10k_htc_tx_completion_handler(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001710 }
1711}
1712
1713/*
1714 * Cleanup residual buffers for device shutdown:
1715 * buffers that were enqueued for receive
1716 * buffers that were to be sent
1717 * Note: Buffers that had completed but which were
1718 * not yet processed are on a completion queue. They
1719 * are handled when the completion thread shuts down.
1720 */
1721static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1722{
1723 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1724 int pipe_num;
1725
Michal Kaziorfad6ed72013-11-08 08:01:23 +01001726 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
Michal Kazior87263e52013-08-27 13:08:01 +02001727 struct ath10k_pci_pipe *pipe_info;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001728
1729 pipe_info = &ar_pci->pipe_info[pipe_num];
1730 ath10k_pci_rx_pipe_cleanup(pipe_info);
1731 ath10k_pci_tx_pipe_cleanup(pipe_info);
1732 }
1733}
1734
Raja Manif52f5172016-01-27 15:24:22 +05301735void ath10k_pci_ce_deinit(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736{
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001737 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738
Michal Kazior25d0dbc2014-03-28 10:02:38 +02001739 for (i = 0; i < CE_COUNT; i++)
1740 ath10k_ce_deinit_pipe(ar, i);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001741}
1742
Raja Manif52f5172016-01-27 15:24:22 +05301743void ath10k_pci_flush(struct ath10k *ar)
Michal Kazior728f95e2014-08-22 14:33:14 +02001744{
1745 ath10k_pci_kill_tasklet(ar);
1746 ath10k_pci_buffer_cleanup(ar);
1747}
1748
Kalle Valo5e3dd152013-06-12 20:52:10 +03001749static void ath10k_pci_hif_stop(struct ath10k *ar)
1750{
Michal Kazior77258d42015-05-18 09:38:18 +00001751 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1752 unsigned long flags;
1753
Michal Kazior7aa7a722014-08-25 12:09:38 +02001754 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
Michal Kazior32270b62013-08-02 09:15:47 +02001755
Michal Kazior10d23db2014-08-22 14:33:15 +02001756 /* Most likely the device has HTT Rx ring configured. The only way to
1757 * prevent the device from accessing (and possible corrupting) host
1758 * memory is to reset the chip now.
Michal Kaziore75db4e2014-08-28 22:14:16 +03001759 *
1760 * There's also no known way of masking MSI interrupts on the device.
1761 * For ranged MSI the CE-related interrupts can be masked. However
1762 * regardless how many MSI interrupts are assigned the first one
1763 * is always used for firmware indications (crashes) and cannot be
1764 * masked. To prevent the device from asserting the interrupt reset it
1765 * before proceeding with cleanup.
Michal Kazior10d23db2014-08-22 14:33:15 +02001766 */
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05301767 ath10k_pci_safe_chip_reset(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001768
1769 ath10k_pci_irq_disable(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02001770 ath10k_pci_irq_sync(ar);
Michal Kaziore75db4e2014-08-28 22:14:16 +03001771 ath10k_pci_flush(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00001772
1773 spin_lock_irqsave(&ar_pci->ps_lock, flags);
1774 WARN_ON(ar_pci->ps_wake_refcount > 0);
1775 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776}
1777
Raja Manif52f5172016-01-27 15:24:22 +05301778int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1779 void *req, u32 req_len,
1780 void *resp, u32 *resp_len)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781{
1782 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior2aa39112013-08-27 13:08:02 +02001783 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1784 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1785 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1786 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787 dma_addr_t req_paddr = 0;
1788 dma_addr_t resp_paddr = 0;
1789 struct bmi_xfer xfer = {};
1790 void *treq, *tresp = NULL;
1791 int ret = 0;
1792
Michal Kazior85622cd2013-11-25 14:06:22 +01001793 might_sleep();
1794
Kalle Valo5e3dd152013-06-12 20:52:10 +03001795 if (resp && !resp_len)
1796 return -EINVAL;
1797
1798 if (resp && resp_len && *resp_len == 0)
1799 return -EINVAL;
1800
1801 treq = kmemdup(req, req_len, GFP_KERNEL);
1802 if (!treq)
1803 return -ENOMEM;
1804
1805 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1806 ret = dma_mapping_error(ar->dev, req_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001807 if (ret) {
1808 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001809 goto err_dma;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001810 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001811
1812 if (resp && resp_len) {
1813 tresp = kzalloc(*resp_len, GFP_KERNEL);
1814 if (!tresp) {
1815 ret = -ENOMEM;
1816 goto err_req;
1817 }
1818
1819 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1820 DMA_FROM_DEVICE);
1821 ret = dma_mapping_error(ar->dev, resp_paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001822 if (ret) {
Anton Protopopov22baa982016-02-10 11:58:55 -05001823 ret = -EIO;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001824 goto err_req;
Michal Kazior5e55e3c2015-08-19 13:10:43 +02001825 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001826
1827 xfer.wait_for_resp = true;
1828 xfer.resp_len = 0;
1829
Michal Kazior728f95e2014-08-22 14:33:14 +02001830 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001831 }
1832
Kalle Valo5e3dd152013-06-12 20:52:10 +03001833 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1834 if (ret)
1835 goto err_resp;
1836
Michal Kazior85622cd2013-11-25 14:06:22 +01001837 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1838 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839 u32 unused_buffer;
1840 unsigned int unused_nbytes;
1841 unsigned int unused_id;
1842
Kalle Valo5e3dd152013-06-12 20:52:10 +03001843 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1844 &unused_nbytes, &unused_id);
1845 } else {
1846 /* non-zero means we did not time out */
1847 ret = 0;
1848 }
1849
1850err_resp:
1851 if (resp) {
1852 u32 unused_buffer;
1853
1854 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1855 dma_unmap_single(ar->dev, resp_paddr,
1856 *resp_len, DMA_FROM_DEVICE);
1857 }
1858err_req:
1859 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1860
1861 if (ret == 0 && resp_len) {
1862 *resp_len = min(*resp_len, xfer.resp_len);
1863 memcpy(resp, tresp, xfer.resp_len);
1864 }
1865err_dma:
1866 kfree(treq);
1867 kfree(tresp);
1868
1869 return ret;
1870}
1871
Michal Kazior5440ce22013-09-03 15:09:58 +02001872static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001873{
Michal Kazior5440ce22013-09-03 15:09:58 +02001874 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001875
Rajkumar Manoharan765952e2015-10-23 18:01:05 +05301876 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
Michal Kazior5440ce22013-09-03 15:09:58 +02001877 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878
Michal Kazior2374b182014-07-14 16:25:25 +03001879 xfer->tx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001880}
1881
Michal Kazior5440ce22013-09-03 15:09:58 +02001882static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001883{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001884 struct ath10k *ar = ce_state->ar;
Michal Kazior5440ce22013-09-03 15:09:58 +02001885 struct bmi_xfer *xfer;
Michal Kazior5440ce22013-09-03 15:09:58 +02001886 unsigned int nbytes;
Michal Kazior5440ce22013-09-03 15:09:58 +02001887
Rajkumar Manoharan24d9ef52016-03-22 17:22:17 +05301888 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer,
1889 &nbytes))
Michal Kazior5440ce22013-09-03 15:09:58 +02001890 return;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001891
Michal Kazior04ed9df2014-10-28 10:34:36 +01001892 if (WARN_ON_ONCE(!xfer))
1893 return;
1894
Kalle Valo5e3dd152013-06-12 20:52:10 +03001895 if (!xfer->wait_for_resp) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001896 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001897 return;
1898 }
1899
1900 xfer->resp_len = nbytes;
Michal Kazior2374b182014-07-14 16:25:25 +03001901 xfer->rx_done = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001902}
1903
Michal Kazior85622cd2013-11-25 14:06:22 +01001904static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1905 struct ath10k_ce_pipe *rx_pipe,
1906 struct bmi_xfer *xfer)
1907{
1908 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1909
1910 while (time_before_eq(jiffies, timeout)) {
1911 ath10k_pci_bmi_send_done(tx_pipe);
1912 ath10k_pci_bmi_recv_data(rx_pipe);
1913
Michal Kazior2374b182014-07-14 16:25:25 +03001914 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
Michal Kazior85622cd2013-11-25 14:06:22 +01001915 return 0;
1916
1917 schedule();
1918 }
1919
1920 return -ETIMEDOUT;
1921}
1922
Kalle Valo5e3dd152013-06-12 20:52:10 +03001923/*
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 * Send an interrupt to the device to wake up the Target CPU
1925 * so it has an opportunity to notice any changed state.
1926 */
1927static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1928{
Michal Kazior9e264942014-09-02 11:00:21 +03001929 u32 addr, val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930
Michal Kazior9e264942014-09-02 11:00:21 +03001931 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1932 val = ath10k_pci_read32(ar, addr);
1933 val |= CORE_CTRL_CPU_INTR_MASK;
1934 ath10k_pci_write32(ar, addr, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935
Michal Kazior1d2b48d2013-11-08 08:01:34 +01001936 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937}
1938
Michal Kaziord63955b2015-01-24 12:14:49 +02001939static int ath10k_pci_get_num_banks(struct ath10k *ar)
1940{
1941 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1942
1943 switch (ar_pci->pdev->device) {
1944 case QCA988X_2_0_DEVICE_ID:
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05301945 case QCA99X0_2_0_DEVICE_ID:
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +03001946 case QCA9984_1_0_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001947 return 1;
Michal Kazior36582e52015-08-13 14:32:26 +02001948 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02001949 case QCA6174_2_1_DEVICE_ID:
1950 switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
1951 case QCA6174_HW_1_0_CHIP_ID_REV:
1952 case QCA6174_HW_1_1_CHIP_ID_REV:
Michal Kazior11a002e2015-04-20 09:20:41 +00001953 case QCA6174_HW_2_1_CHIP_ID_REV:
1954 case QCA6174_HW_2_2_CHIP_ID_REV:
Michal Kaziord63955b2015-01-24 12:14:49 +02001955 return 3;
1956 case QCA6174_HW_1_3_CHIP_ID_REV:
1957 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001958 case QCA6174_HW_3_0_CHIP_ID_REV:
1959 case QCA6174_HW_3_1_CHIP_ID_REV:
1960 case QCA6174_HW_3_2_CHIP_ID_REV:
1961 return 9;
1962 }
1963 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01001964 case QCA9377_1_0_DEVICE_ID:
1965 return 2;
Michal Kaziord63955b2015-01-24 12:14:49 +02001966 }
1967
1968 ath10k_warn(ar, "unknown number of banks, assuming 1\n");
1969 return 1;
1970}
1971
Raja Mani4ddb3292016-01-27 15:24:23 +05301972static int ath10k_bus_get_num_banks(struct ath10k *ar)
1973{
1974 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1975
1976 return ar_pci->bus_ops->get_num_banks(ar);
1977}
1978
Raja Manif52f5172016-01-27 15:24:22 +05301979int ath10k_pci_init_config(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980{
1981 u32 interconnect_targ_addr;
1982 u32 pcie_state_targ_addr = 0;
1983 u32 pipe_cfg_targ_addr = 0;
1984 u32 svc_to_pipe_map = 0;
1985 u32 pcie_config_flags = 0;
1986 u32 ealloc_value;
1987 u32 ealloc_targ_addr;
1988 u32 flag2_value;
1989 u32 flag2_targ_addr;
1990 int ret = 0;
1991
1992 /* Download to Target the CE Config and the service-to-CE map */
1993 interconnect_targ_addr =
1994 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1995
1996 /* Supply Target-side CE configuration */
Michal Kazior9e264942014-09-02 11:00:21 +03001997 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
1998 &pcie_state_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002000 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 return ret;
2002 }
2003
2004 if (pcie_state_targ_addr == 0) {
2005 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002006 ath10k_err(ar, "Invalid pcie state addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002007 return ret;
2008 }
2009
Michal Kazior9e264942014-09-02 11:00:21 +03002010 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002012 pipe_cfg_addr)),
2013 &pipe_cfg_targ_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002014 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002015 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002016 return ret;
2017 }
2018
2019 if (pipe_cfg_targ_addr == 0) {
2020 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002021 ath10k_err(ar, "Invalid pipe cfg addr\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002022 return ret;
2023 }
2024
2025 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002026 target_ce_config_wlan,
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302027 sizeof(struct ce_pipe_config) *
2028 NUM_TARGET_CE_CONFIG_WLAN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002029
2030 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002031 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002032 return ret;
2033 }
2034
Michal Kazior9e264942014-09-02 11:00:21 +03002035 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002037 svc_to_pipe_map)),
2038 &svc_to_pipe_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002040 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002041 return ret;
2042 }
2043
2044 if (svc_to_pipe_map == 0) {
2045 ret = -EIO;
Michal Kazior7aa7a722014-08-25 12:09:38 +02002046 ath10k_err(ar, "Invalid svc_to_pipe map\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047 return ret;
2048 }
2049
2050 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
Kalle Valo5b07e072014-09-14 12:50:06 +03002051 target_service_to_ce_map_wlan,
2052 sizeof(target_service_to_ce_map_wlan));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002053 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002054 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055 return ret;
2056 }
2057
Michal Kazior9e264942014-09-02 11:00:21 +03002058 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
Kalle Valo5e3dd152013-06-12 20:52:10 +03002059 offsetof(struct pcie_state,
Michal Kazior9e264942014-09-02 11:00:21 +03002060 config_flags)),
2061 &pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002062 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002063 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002064 return ret;
2065 }
2066
2067 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
2068
Michal Kazior9e264942014-09-02 11:00:21 +03002069 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
2070 offsetof(struct pcie_state,
2071 config_flags)),
2072 pcie_config_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002073 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002074 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075 return ret;
2076 }
2077
2078 /* configure early allocation */
2079 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
2080
Michal Kazior9e264942014-09-02 11:00:21 +03002081 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002083 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002084 return ret;
2085 }
2086
2087 /* first bank is switched to IRAM */
2088 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
2089 HI_EARLY_ALLOC_MAGIC_MASK);
Raja Mani4ddb3292016-01-27 15:24:23 +05302090 ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
Michal Kaziord63955b2015-01-24 12:14:49 +02002091 HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
Kalle Valo5e3dd152013-06-12 20:52:10 +03002092 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
2093
Michal Kazior9e264942014-09-02 11:00:21 +03002094 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002096 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002097 return ret;
2098 }
2099
2100 /* Tell Target to proceed with initialization */
2101 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
2102
Michal Kazior9e264942014-09-02 11:00:21 +03002103 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002105 ath10k_err(ar, "Failed to get option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002106 return ret;
2107 }
2108
2109 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
2110
Michal Kazior9e264942014-09-02 11:00:21 +03002111 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002112 if (ret != 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002113 ath10k_err(ar, "Failed to set option val: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002114 return ret;
2115 }
2116
2117 return 0;
2118}
2119
Ryan Hsu2727a742015-11-05 18:44:27 -08002120static void ath10k_pci_override_ce_config(struct ath10k *ar)
2121{
2122 struct ce_attr *attr;
2123 struct ce_pipe_config *config;
2124
2125 /* For QCA6174 we're overriding the Copy Engine 5 configuration,
2126 * since it is currently used for other feature.
2127 */
2128
2129 /* Override Host's Copy Engine 5 configuration */
2130 attr = &host_ce_config_wlan[5];
2131 attr->src_sz_max = 0;
2132 attr->dest_nentries = 0;
2133
2134 /* Override Target firmware's Copy Engine configuration */
2135 config = &target_ce_config_wlan[5];
2136 config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
2137 config->nbytes_max = __cpu_to_le32(2048);
2138
2139 /* Map from service/endpoint to Copy Engine */
2140 target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
2141}
2142
Raja Manif52f5172016-01-27 15:24:22 +05302143int ath10k_pci_alloc_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002144{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002145 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2146 struct ath10k_pci_pipe *pipe;
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002147 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002148
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002149 for (i = 0; i < CE_COUNT; i++) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002150 pipe = &ar_pci->pipe_info[i];
2151 pipe->ce_hdl = &ar_pci->ce_states[i];
2152 pipe->pipe_num = i;
2153 pipe->hif_ce_state = ar;
2154
Rajkumar Manoharan9d9bdbb2015-10-12 18:27:02 +05302155 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002156 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002157 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002158 i, ret);
2159 return ret;
2160 }
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002161
2162 /* Last CE is Diagnostic Window */
Vasanthakumar Thiagarajan050af062015-06-18 12:31:04 +05302163 if (i == CE_DIAG_PIPE) {
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002164 ar_pci->ce_diag = pipe->ce_hdl;
2165 continue;
2166 }
2167
2168 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002169 }
2170
2171 return 0;
2172}
2173
Raja Manif52f5172016-01-27 15:24:22 +05302174void ath10k_pci_free_pipes(struct ath10k *ar)
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002175{
2176 int i;
2177
2178 for (i = 0; i < CE_COUNT; i++)
2179 ath10k_ce_free_pipe(ar, i);
2180}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002181
Raja Manif52f5172016-01-27 15:24:22 +05302182int ath10k_pci_init_pipes(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183{
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002184 int i, ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002186 for (i = 0; i < CE_COUNT; i++) {
2187 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002188 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002189 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002190 i, ret);
Michal Kazior25d0dbc2014-03-28 10:02:38 +02002191 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193 }
2194
Kalle Valo5e3dd152013-06-12 20:52:10 +03002195 return 0;
2196}
2197
Michal Kazior5c771e72014-08-22 14:23:34 +02002198static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199{
Michal Kazior5c771e72014-08-22 14:23:34 +02002200 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
2201 FW_IND_EVENT_PENDING;
2202}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203
Michal Kazior5c771e72014-08-22 14:23:34 +02002204static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
2205{
2206 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002207
Michal Kazior5c771e72014-08-22 14:23:34 +02002208 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2209 val &= ~FW_IND_EVENT_PENDING;
2210 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211}
2212
Michal Kaziorde013572014-05-14 16:56:16 +03002213/* this function effectively clears target memory controller assert line */
2214static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
2215{
2216 u32 val;
2217
2218 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2219 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2220 val | SOC_RESET_CONTROL_SI0_RST_MASK);
2221 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2222
2223 msleep(10);
2224
2225 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2226 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2227 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
2228 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2229
2230 msleep(10);
2231}
2232
Michal Kazior61c16482014-10-28 10:32:06 +01002233static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002234{
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002235 u32 val;
2236
Kalle Valob39712c2014-03-28 09:32:46 +02002237 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002238
Michal Kazior61c16482014-10-28 10:32:06 +01002239 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2240 SOC_RESET_CONTROL_ADDRESS);
2241 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2242 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
2243}
2244
2245static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
2246{
2247 u32 val;
2248
2249 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2250 SOC_RESET_CONTROL_ADDRESS);
2251
2252 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2253 val | SOC_RESET_CONTROL_CE_RST_MASK);
2254 msleep(10);
2255 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2256 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
2257}
2258
2259static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
2260{
2261 u32 val;
2262
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002263 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2264 SOC_LF_TIMER_CONTROL0_ADDRESS);
2265 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
2266 SOC_LF_TIMER_CONTROL0_ADDRESS,
2267 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
Michal Kazior61c16482014-10-28 10:32:06 +01002268}
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002269
Michal Kazior61c16482014-10-28 10:32:06 +01002270static int ath10k_pci_warm_reset(struct ath10k *ar)
2271{
2272 int ret;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002273
Michal Kazior61c16482014-10-28 10:32:06 +01002274 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002275
Michal Kazior61c16482014-10-28 10:32:06 +01002276 spin_lock_bh(&ar->data_lock);
2277 ar->stats.fw_warm_reset_counter++;
2278 spin_unlock_bh(&ar->data_lock);
2279
2280 ath10k_pci_irq_disable(ar);
2281
2282 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
2283 * were to access copy engine while host performs copy engine reset
2284 * then it is possible for the device to confuse pci-e controller to
2285 * the point of bringing host system to a complete stop (i.e. hang).
2286 */
Michal Kaziorde013572014-05-14 16:56:16 +03002287 ath10k_pci_warm_reset_si0(ar);
Michal Kazior61c16482014-10-28 10:32:06 +01002288 ath10k_pci_warm_reset_cpu(ar);
2289 ath10k_pci_init_pipes(ar);
2290 ath10k_pci_wait_for_target_init(ar);
Michal Kaziorde013572014-05-14 16:56:16 +03002291
Michal Kazior61c16482014-10-28 10:32:06 +01002292 ath10k_pci_warm_reset_clear_lf(ar);
2293 ath10k_pci_warm_reset_ce(ar);
2294 ath10k_pci_warm_reset_cpu(ar);
2295 ath10k_pci_init_pipes(ar);
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002296
Michal Kazior61c16482014-10-28 10:32:06 +01002297 ret = ath10k_pci_wait_for_target_init(ar);
2298 if (ret) {
2299 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
2300 return ret;
2301 }
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002302
Michal Kazior7aa7a722014-08-25 12:09:38 +02002303 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002304
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002305 return 0;
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002306}
2307
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002308static int ath10k_pci_qca99x0_soft_chip_reset(struct ath10k *ar)
2309{
2310 ath10k_pci_irq_disable(ar);
2311 return ath10k_pci_qca99x0_chip_reset(ar);
2312}
2313
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302314static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
2315{
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002316 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2317
2318 if (!ar_pci->pci_soft_reset)
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302319 return -ENOTSUPP;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002320
2321 return ar_pci->pci_soft_reset(ar);
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302322}
2323
Michal Kaziord63955b2015-01-24 12:14:49 +02002324static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
Michal Kazior0bc14d02014-10-28 10:32:07 +01002325{
2326 int i, ret;
2327 u32 val;
2328
Michal Kaziord63955b2015-01-24 12:14:49 +02002329 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002330
2331 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
2332 * It is thus preferred to use warm reset which is safer but may not be
2333 * able to recover the device from all possible fail scenarios.
2334 *
2335 * Warm reset doesn't always work on first try so attempt it a few
2336 * times before giving up.
2337 */
2338 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2339 ret = ath10k_pci_warm_reset(ar);
2340 if (ret) {
2341 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
2342 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
2343 ret);
2344 continue;
2345 }
2346
2347 /* FIXME: Sometimes copy engine doesn't recover after warm
2348 * reset. In most cases this needs cold reset. In some of these
2349 * cases the device is in such a state that a cold reset may
2350 * lock up the host.
2351 *
2352 * Reading any host interest register via copy engine is
2353 * sufficient to verify if device is capable of booting
2354 * firmware blob.
2355 */
2356 ret = ath10k_pci_init_pipes(ar);
2357 if (ret) {
2358 ath10k_warn(ar, "failed to init copy engine: %d\n",
2359 ret);
2360 continue;
2361 }
2362
2363 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
2364 &val);
2365 if (ret) {
2366 ath10k_warn(ar, "failed to poke copy engine: %d\n",
2367 ret);
2368 continue;
2369 }
2370
2371 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
2372 return 0;
2373 }
2374
2375 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
2376 ath10k_warn(ar, "refusing cold reset as requested\n");
2377 return -EPERM;
2378 }
2379
2380 ret = ath10k_pci_cold_reset(ar);
2381 if (ret) {
2382 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2383 return ret;
2384 }
2385
2386 ret = ath10k_pci_wait_for_target_init(ar);
2387 if (ret) {
2388 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2389 ret);
2390 return ret;
2391 }
2392
Michal Kaziord63955b2015-01-24 12:14:49 +02002393 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
Michal Kazior0bc14d02014-10-28 10:32:07 +01002394
2395 return 0;
2396}
2397
Michal Kaziord63955b2015-01-24 12:14:49 +02002398static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
2399{
2400 int ret;
2401
2402 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
2403
2404 /* FIXME: QCA6174 requires cold + warm reset to work. */
2405
2406 ret = ath10k_pci_cold_reset(ar);
2407 if (ret) {
2408 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2409 return ret;
2410 }
2411
2412 ret = ath10k_pci_wait_for_target_init(ar);
2413 if (ret) {
2414 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
Kalle Valo617b0f42015-10-05 17:56:35 +03002415 ret);
Michal Kaziord63955b2015-01-24 12:14:49 +02002416 return ret;
2417 }
2418
2419 ret = ath10k_pci_warm_reset(ar);
2420 if (ret) {
2421 ath10k_warn(ar, "failed to warm reset: %d\n", ret);
2422 return ret;
2423 }
2424
2425 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
2426
2427 return 0;
2428}
2429
Vasanthakumar Thiagarajan6e4202c2015-06-18 12:31:06 +05302430static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
2431{
2432 int ret;
2433
2434 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
2435
2436 ret = ath10k_pci_cold_reset(ar);
2437 if (ret) {
2438 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2439 return ret;
2440 }
2441
2442 ret = ath10k_pci_wait_for_target_init(ar);
2443 if (ret) {
2444 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2445 ret);
2446 return ret;
2447 }
2448
2449 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
2450
2451 return 0;
2452}
2453
Michal Kaziord63955b2015-01-24 12:14:49 +02002454static int ath10k_pci_chip_reset(struct ath10k *ar)
2455{
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002456 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2457
2458 if (WARN_ON(!ar_pci->pci_hard_reset))
Michal Kaziord63955b2015-01-24 12:14:49 +02002459 return -ENOTSUPP;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002460
2461 return ar_pci->pci_hard_reset(ar);
Michal Kaziord63955b2015-01-24 12:14:49 +02002462}
2463
Michal Kazior0bc14d02014-10-28 10:32:07 +01002464static int ath10k_pci_hif_power_up(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002465{
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002466 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002467 int ret;
2468
Michal Kazior0bc14d02014-10-28 10:32:07 +01002469 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
2470
Janusz Dziedzic76d870e2015-05-18 09:38:16 +00002471 pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2472 &ar_pci->link_ctl);
2473 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2474 ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
2475
Michal Kazior8c5c5362013-07-16 09:38:50 +02002476 /*
2477 * Bring the target up cleanly.
2478 *
2479 * The target may be in an undefined state with an AUX-powered Target
2480 * and a Host in WoW mode. If the Host crashes, loses power, or is
2481 * restarted (without unloading the driver) then the Target is left
2482 * (aux) powered and running. On a subsequent driver load, the Target
2483 * is in an unexpected state. We try to catch that here in order to
2484 * reset the Target and retry the probe.
2485 */
Michal Kazior0bc14d02014-10-28 10:32:07 +01002486 ret = ath10k_pci_chip_reset(ar);
Michal Kazior5b2589f2013-11-08 08:01:30 +01002487 if (ret) {
Michal Kaziora2fa8802015-01-12 15:29:37 +01002488 if (ath10k_pci_has_fw_crashed(ar)) {
2489 ath10k_warn(ar, "firmware crashed during chip reset\n");
2490 ath10k_pci_fw_crashed_clear(ar);
2491 ath10k_pci_fw_crashed_dump(ar);
2492 }
2493
Michal Kazior0bc14d02014-10-28 10:32:07 +01002494 ath10k_err(ar, "failed to reset chip: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002495 goto err_sleep;
Michal Kazior5b2589f2013-11-08 08:01:30 +01002496 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002497
Michal Kazior84cbf3a2014-10-20 14:14:39 +02002498 ret = ath10k_pci_init_pipes(ar);
Michal Kazior8c5c5362013-07-16 09:38:50 +02002499 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002500 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002501 goto err_sleep;
Michal Kaziorab977bd2013-11-25 14:06:26 +01002502 }
2503
Michal Kazior98563d52013-11-08 08:01:33 +01002504 ret = ath10k_pci_init_config(ar);
2505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002506 ath10k_err(ar, "failed to setup init config: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002507 goto err_ce;
Michal Kazior98563d52013-11-08 08:01:33 +01002508 }
Michal Kazior8c5c5362013-07-16 09:38:50 +02002509
2510 ret = ath10k_pci_wake_target_cpu(ar);
2511 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002512 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
Michal Kazior5c771e72014-08-22 14:23:34 +02002513 goto err_ce;
Michal Kazior8c5c5362013-07-16 09:38:50 +02002514 }
2515
2516 return 0;
2517
2518err_ce:
2519 ath10k_pci_ce_deinit(ar);
Michal Kazior0bc14d02014-10-28 10:32:07 +01002520
Bartosz Markowski707b1bbd2014-10-31 09:03:43 +01002521err_sleep:
Michal Kazior8c5c5362013-07-16 09:38:50 +02002522 return ret;
2523}
2524
Raja Manif52f5172016-01-27 15:24:22 +05302525void ath10k_pci_hif_power_down(struct ath10k *ar)
Michal Kazior8c5c5362013-07-16 09:38:50 +02002526{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002527 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
Bartosz Markowski8cc8df92013-08-02 09:58:49 +02002528
Michal Kaziorc011b282014-10-28 10:32:08 +01002529 /* Currently hif_power_up performs effectively a reset and hif_stop
2530 * resets the chip as well so there's no point in resetting here.
2531 */
Michal Kazior8c5c5362013-07-16 09:38:50 +02002532}
2533
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002534#ifdef CONFIG_PM
2535
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002536static int ath10k_pci_hif_suspend(struct ath10k *ar)
2537{
Michal Kazior77258d42015-05-18 09:38:18 +00002538 /* The grace timer can still be counting down and ar->ps_awake be true.
2539 * It is known that the device may be asleep after resuming regardless
2540 * of the SoC powersave state before suspending. Hence make sure the
2541 * device is asleep before proceeding.
2542 */
2543 ath10k_pci_sleep_sync(ar);
Michal Kazior320e14b2015-03-02 13:22:13 +01002544
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002545 return 0;
2546}
2547
2548static int ath10k_pci_hif_resume(struct ath10k *ar)
2549{
2550 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2551 struct pci_dev *pdev = ar_pci->pdev;
2552 u32 val;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002553 int ret = 0;
2554
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002555 ret = ath10k_pci_force_wake(ar);
2556 if (ret) {
2557 ath10k_err(ar, "failed to wake up target: %d\n", ret);
2558 return ret;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002559 }
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002560
Michal Kazior9ff4be92015-03-02 13:22:14 +01002561 /* Suspend/Resume resets the PCI configuration space, so we have to
2562 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
2563 * from interfering with C3 CPU state. pci_restore_state won't help
2564 * here since it only restores the first 64 bytes pci config header.
2565 */
2566 pci_read_config_dword(pdev, 0x40, &val);
2567 if ((val & 0x0000ff00) != 0)
2568 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002569
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002570 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002571}
2572#endif
2573
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
Michal Kazior726346f2014-02-27 18:50:04 +02002575 .tx_sg = ath10k_pci_hif_tx_sg,
Kalle Valoeef25402014-09-24 14:16:52 +03002576 .diag_read = ath10k_pci_hif_diag_read,
Yanbo Li9f65ad22014-11-25 12:24:48 +02002577 .diag_write = ath10k_pci_diag_write_mem,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002578 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2579 .start = ath10k_pci_hif_start,
2580 .stop = ath10k_pci_hif_stop,
2581 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2582 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2583 .send_complete_check = ath10k_pci_hif_send_complete_check,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
Michal Kazior8c5c5362013-07-16 09:38:50 +02002585 .power_up = ath10k_pci_hif_power_up,
2586 .power_down = ath10k_pci_hif_power_down,
Yanbo Li077a3802014-11-25 12:24:33 +02002587 .read32 = ath10k_pci_read32,
2588 .write32 = ath10k_pci_write32,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002589#ifdef CONFIG_PM
2590 .suspend = ath10k_pci_hif_suspend,
2591 .resume = ath10k_pci_hif_resume,
2592#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03002593};
2594
Kalle Valo5e3dd152013-06-12 20:52:10 +03002595/*
2596 * Top-level interrupt handler for all PCI interrupts from a Target.
2597 * When a block of MSI interrupts is allocated, this top-level handler
2598 * is not used; instead, we directly call the correct sub-handler.
2599 */
2600static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2601{
2602 struct ath10k *ar = arg;
2603 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002604 int ret;
2605
Rajkumar Manoharand9d6a5a2015-12-16 16:52:19 +02002606 ret = ath10k_pci_force_wake(ar);
2607 if (ret) {
2608 ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
2609 return IRQ_NONE;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002610 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002611
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302612 if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY) {
Michal Kaziore5398872013-11-25 14:06:20 +01002613 if (!ath10k_pci_irq_pending(ar))
2614 return IRQ_NONE;
2615
Michal Kazior26852182013-11-25 14:06:25 +01002616 ath10k_pci_disable_and_clear_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002617 }
2618
2619 tasklet_schedule(&ar_pci->intr_tq);
2620
2621 return IRQ_HANDLED;
2622}
2623
2624static void ath10k_pci_tasklet(unsigned long data)
2625{
2626 struct ath10k *ar = (struct ath10k *)data;
2627 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2628
Michal Kazior5c771e72014-08-22 14:23:34 +02002629 if (ath10k_pci_has_fw_crashed(ar)) {
Michal Kazior6f3b7ff2015-01-24 12:14:52 +02002630 ath10k_pci_irq_disable(ar);
Michal Kazior5c771e72014-08-22 14:23:34 +02002631 ath10k_pci_fw_crashed_clear(ar);
2632 ath10k_pci_fw_crashed_dump(ar);
2633 return;
2634 }
2635
Kalle Valo5e3dd152013-06-12 20:52:10 +03002636 ath10k_ce_per_engine_service_any(ar);
2637
Michal Kazior26852182013-11-25 14:06:25 +01002638 /* Re-enable legacy irq that was disabled in the irq handler */
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302639 if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
Michal Kazior26852182013-11-25 14:06:25 +01002640 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002641}
2642
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002643static int ath10k_pci_request_irq_msi(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644{
2645 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2646 int ret;
2647
2648 ret = request_irq(ar_pci->pdev->irq,
2649 ath10k_pci_interrupt_handler,
2650 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002651 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002652 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002653 ar_pci->pdev->irq, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002654 return ret;
Kalle Valof3782742013-10-17 11:36:15 +03002655 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002656
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657 return 0;
2658}
2659
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002660static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002661{
2662 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002664
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002665 ret = request_irq(ar_pci->pdev->irq,
2666 ath10k_pci_interrupt_handler,
2667 IRQF_SHARED, "ath10k_pci", ar);
Kalle Valof3782742013-10-17 11:36:15 +03002668 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002669 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002670 ar_pci->pdev->irq, ret);
Kalle Valof3782742013-10-17 11:36:15 +03002671 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002672 }
2673
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002674 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002675}
2676
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002677static int ath10k_pci_request_irq(struct ath10k *ar)
2678{
2679 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2680
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302681 switch (ar_pci->oper_irq_mode) {
2682 case ATH10K_PCI_IRQ_LEGACY:
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002683 return ath10k_pci_request_irq_legacy(ar);
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302684 case ATH10K_PCI_IRQ_MSI:
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002685 return ath10k_pci_request_irq_msi(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002686 default:
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302687 return -EINVAL;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002688 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002689}
2690
2691static void ath10k_pci_free_irq(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692{
2693 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002694
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302695 free_irq(ar_pci->pdev->irq, ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696}
2697
Raja Manif52f5172016-01-27 15:24:22 +05302698void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002699{
2700 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002701
2702 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002703}
2704
2705static int ath10k_pci_init_irq(struct ath10k *ar)
2706{
2707 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2708 int ret;
2709
2710 ath10k_pci_init_irq_tasklets(ar);
2711
Michal Kazior403d6272014-08-22 14:23:31 +02002712 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002713 ath10k_info(ar, "limiting irq mode to: %d\n",
2714 ath10k_pci_irq_mode);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002715
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002716 /* Try MSI */
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002717 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302718 ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_MSI;
Michal Kaziorcfe9c452013-11-25 14:06:27 +01002719 ret = pci_enable_msi(ar_pci->pdev);
2720 if (ret == 0)
2721 return 0;
2722
2723 /* fall-through */
2724 }
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002725
2726 /* Try legacy irq
2727 *
2728 * A potential race occurs here: The CORE_BASE write
2729 * depends on target correctly decoding AXI address but
2730 * host won't know when target writes BAR to CORE_CTRL.
2731 * This write might get lost if target has NOT written BAR.
2732 * For now, fix the race by repeating the write in below
2733 * synchronization checking. */
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302734 ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_LEGACY;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002735
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002736 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2737 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002738
2739 return 0;
2740}
2741
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002742static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002743{
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002744 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2745 0);
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002746}
2747
2748static int ath10k_pci_deinit_irq(struct ath10k *ar)
2749{
2750 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2751
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302752 switch (ar_pci->oper_irq_mode) {
2753 case ATH10K_PCI_IRQ_LEGACY:
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002754 ath10k_pci_deinit_irq_legacy(ar);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002755 break;
Alexander Gordeevbb8b6212014-02-13 17:50:01 +02002756 default:
2757 pci_disable_msi(ar_pci->pdev);
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002758 break;
Michal Kaziorfc15ca12013-11-25 14:06:21 +01002759 }
2760
Janusz Dziedzicb8402d82015-09-17 08:17:33 +02002761 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762}
2763
Raja Manif52f5172016-01-27 15:24:22 +05302764int ath10k_pci_wait_for_target_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002765{
2766 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
Kalle Valo0399eca2014-03-28 09:32:21 +02002767 unsigned long timeout;
Kalle Valo0399eca2014-03-28 09:32:21 +02002768 u32 val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002769
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771
Kalle Valo0399eca2014-03-28 09:32:21 +02002772 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2773
2774 do {
2775 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2776
Michal Kazior7aa7a722014-08-25 12:09:38 +02002777 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2778 val);
Kalle Valo50f87a62014-03-28 09:32:52 +02002779
Kalle Valo0399eca2014-03-28 09:32:21 +02002780 /* target should never return this */
2781 if (val == 0xffffffff)
2782 continue;
2783
Michal Kazior7710cd22014-04-23 19:30:04 +03002784 /* the device has crashed so don't bother trying anymore */
2785 if (val & FW_IND_EVENT_PENDING)
2786 break;
2787
Kalle Valo0399eca2014-03-28 09:32:21 +02002788 if (val & FW_IND_INITIALIZED)
2789 break;
2790
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05302791 if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792 /* Fix potential race by repeating CORE_BASE writes */
Michal Kaziora4282492014-10-20 14:14:37 +02002793 ath10k_pci_enable_legacy_irq(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794
Kalle Valo0399eca2014-03-28 09:32:21 +02002795 mdelay(10);
2796 } while (time_before(jiffies, timeout));
2797
Michal Kaziora4282492014-10-20 14:14:37 +02002798 ath10k_pci_disable_and_clear_legacy_irq(ar);
Michal Kazior7c0f0e32014-10-20 14:14:38 +02002799 ath10k_pci_irq_msi_fw_mask(ar);
Michal Kaziora4282492014-10-20 14:14:37 +02002800
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002801 if (val == 0xffffffff) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002802 ath10k_err(ar, "failed to read device register, device is gone\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002803 return -EIO;
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002804 }
2805
Michal Kazior7710cd22014-04-23 19:30:04 +03002806 if (val & FW_IND_EVENT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002807 ath10k_warn(ar, "device has crashed during init\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002808 return -ECOMM;
Michal Kazior7710cd22014-04-23 19:30:04 +03002809 }
2810
Michal Kazior6a4f6e12014-04-23 19:30:03 +03002811 if (!(val & FW_IND_INITIALIZED)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002812 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
Kalle Valo0399eca2014-03-28 09:32:21 +02002813 val);
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002814 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815 }
2816
Michal Kazior7aa7a722014-08-25 12:09:38 +02002817 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
Michal Kaziorc0c378f2014-08-07 11:03:28 +02002818 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002819}
2820
Michal Kaziorfc36e3f2014-02-10 17:14:22 +01002821static int ath10k_pci_cold_reset(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002822{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002823 u32 val;
2824
Michal Kazior7aa7a722014-08-25 12:09:38 +02002825 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002826
Ben Greearf51dbe72014-09-29 14:41:46 +03002827 spin_lock_bh(&ar->data_lock);
2828
2829 ar->stats.fw_cold_reset_counter++;
2830
2831 spin_unlock_bh(&ar->data_lock);
2832
Kalle Valo5e3dd152013-06-12 20:52:10 +03002833 /* Put Target, including PCIe, into RESET. */
Kalle Valoe479ed42013-09-01 10:01:53 +03002834 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835 val |= 1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002836 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002837
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302838 /* After writing into SOC_GLOBAL_RESET to put device into
2839 * reset and pulling out of reset pcie may not be stable
2840 * for any immediate pcie register access and cause bus error,
2841 * add delay before any pcie access request to fix this issue.
2842 */
2843 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002844
2845 /* Pull Target, including PCIe, out of RESET. */
2846 val &= ~1;
Kalle Valoe479ed42013-09-01 10:01:53 +03002847 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002848
Vasanthakumar Thiagarajanacd19582015-07-10 14:31:20 +05302849 msleep(20);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850
Michal Kazior7aa7a722014-08-25 12:09:38 +02002851 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
Kalle Valo50f87a62014-03-28 09:32:52 +02002852
Michal Kazior5b2589f2013-11-08 08:01:30 +01002853 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854}
2855
Michal Kazior2986e3e2014-08-07 11:03:30 +02002856static int ath10k_pci_claim(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002857{
Michal Kazior2986e3e2014-08-07 11:03:30 +02002858 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2859 struct pci_dev *pdev = ar_pci->pdev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002860 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861
2862 pci_set_drvdata(pdev, ar);
2863
Kalle Valo5e3dd152013-06-12 20:52:10 +03002864 ret = pci_enable_device(pdev);
2865 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002866 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002867 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002868 }
2869
Kalle Valo5e3dd152013-06-12 20:52:10 +03002870 ret = pci_request_region(pdev, BAR_NUM, "ath");
2871 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002872 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
Michal Kazior2986e3e2014-08-07 11:03:30 +02002873 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874 goto err_device;
2875 }
2876
Michal Kazior2986e3e2014-08-07 11:03:30 +02002877 /* Target expects 32 bit DMA. Enforce it. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002878 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2879 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002880 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002881 goto err_region;
2882 }
2883
2884 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002886 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
Michal Kazior2986e3e2014-08-07 11:03:30 +02002887 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002888 goto err_region;
2889 }
2890
Kalle Valo5e3dd152013-06-12 20:52:10 +03002891 pci_set_master(pdev);
2892
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 /* Arrange for access to Target SoC registers. */
Michal Kazioraeae5b42015-06-15 14:46:42 +03002894 ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002895 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
2896 if (!ar_pci->mem) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002897 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002898 ret = -EIO;
2899 goto err_master;
2900 }
2901
Michal Kazior7aa7a722014-08-25 12:09:38 +02002902 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
Michal Kazior2986e3e2014-08-07 11:03:30 +02002903 return 0;
2904
2905err_master:
2906 pci_clear_master(pdev);
2907
2908err_region:
2909 pci_release_region(pdev, BAR_NUM);
2910
2911err_device:
2912 pci_disable_device(pdev);
2913
2914 return ret;
2915}
2916
2917static void ath10k_pci_release(struct ath10k *ar)
2918{
2919 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2920 struct pci_dev *pdev = ar_pci->pdev;
2921
2922 pci_iounmap(pdev, ar_pci->mem);
2923 pci_release_region(pdev, BAR_NUM);
2924 pci_clear_master(pdev);
2925 pci_disable_device(pdev);
2926}
2927
Michal Kazior7505f7c2014-12-02 10:55:54 +02002928static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
2929{
2930 const struct ath10k_pci_supp_chip *supp_chip;
2931 int i;
2932 u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
2933
2934 for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
2935 supp_chip = &ath10k_pci_supp_chips[i];
2936
2937 if (supp_chip->dev_id == dev_id &&
2938 supp_chip->rev_id == rev_id)
2939 return true;
2940 }
2941
2942 return false;
2943}
2944
Raja Mani90188f82016-01-27 15:24:24 +05302945int ath10k_pci_setup_resource(struct ath10k *ar)
2946{
2947 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2948 int ret;
2949
2950 spin_lock_init(&ar_pci->ce_lock);
2951 spin_lock_init(&ar_pci->ps_lock);
2952
2953 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
2954 (unsigned long)ar);
2955
2956 if (QCA_REV_6174(ar))
2957 ath10k_pci_override_ce_config(ar);
2958
2959 ret = ath10k_pci_alloc_pipes(ar);
2960 if (ret) {
2961 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
2962 ret);
2963 return ret;
2964 }
2965
2966 return 0;
2967}
2968
2969void ath10k_pci_release_resource(struct ath10k *ar)
2970{
2971 ath10k_pci_kill_tasklet(ar);
2972 ath10k_pci_ce_deinit(ar);
2973 ath10k_pci_free_pipes(ar);
2974}
2975
Raja Mani4ddb3292016-01-27 15:24:23 +05302976static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
2977 .read32 = ath10k_bus_pci_read32,
2978 .write32 = ath10k_bus_pci_write32,
2979 .get_num_banks = ath10k_pci_get_num_banks,
2980};
2981
Kalle Valo5e3dd152013-06-12 20:52:10 +03002982static int ath10k_pci_probe(struct pci_dev *pdev,
2983 const struct pci_device_id *pci_dev)
2984{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002985 int ret = 0;
2986 struct ath10k *ar;
2987 struct ath10k_pci *ar_pci;
Michal Kaziord63955b2015-01-24 12:14:49 +02002988 enum ath10k_hw_rev hw_rev;
Michal Kazior2986e3e2014-08-07 11:03:30 +02002989 u32 chip_id;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002990 bool pci_ps;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002991 int (*pci_soft_reset)(struct ath10k *ar);
2992 int (*pci_hard_reset)(struct ath10k *ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002993
Michal Kaziord63955b2015-01-24 12:14:49 +02002994 switch (pci_dev->device) {
2995 case QCA988X_2_0_DEVICE_ID:
2996 hw_rev = ATH10K_HW_QCA988X;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03002997 pci_ps = false;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03002998 pci_soft_reset = ath10k_pci_warm_reset;
2999 pci_hard_reset = ath10k_pci_qca988x_chip_reset;
Michal Kaziord63955b2015-01-24 12:14:49 +02003000 break;
Michal Kazior36582e52015-08-13 14:32:26 +02003001 case QCA6164_2_1_DEVICE_ID:
Michal Kaziord63955b2015-01-24 12:14:49 +02003002 case QCA6174_2_1_DEVICE_ID:
3003 hw_rev = ATH10K_HW_QCA6174;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003004 pci_ps = true;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03003005 pci_soft_reset = ath10k_pci_warm_reset;
3006 pci_hard_reset = ath10k_pci_qca6174_chip_reset;
Michal Kaziord63955b2015-01-24 12:14:49 +02003007 break;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303008 case QCA99X0_2_0_DEVICE_ID:
3009 hw_rev = ATH10K_HW_QCA99X0;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003010 pci_ps = false;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03003011 pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
3012 pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
Vasanthakumar Thiagarajan8bd47022015-06-18 12:31:03 +05303013 break;
Vasanthakumar Thiagarajan651b4cd2016-05-23 23:12:45 +03003014 case QCA9984_1_0_DEVICE_ID:
3015 hw_rev = ATH10K_HW_QCA9984;
3016 pci_ps = false;
3017 pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
3018 pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
3019 break;
Bartosz Markowskia226b512015-10-28 15:09:53 +01003020 case QCA9377_1_0_DEVICE_ID:
3021 hw_rev = ATH10K_HW_QCA9377;
3022 pci_ps = true;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03003023 pci_soft_reset = NULL;
3024 pci_hard_reset = ath10k_pci_qca6174_chip_reset;
Bartosz Markowskia226b512015-10-28 15:09:53 +01003025 break;
Michal Kaziord63955b2015-01-24 12:14:49 +02003026 default:
3027 WARN_ON(1);
3028 return -ENOTSUPP;
3029 }
3030
3031 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
3032 hw_rev, &ath10k_pci_hif_ops);
Michal Kaziore7b54192014-08-07 11:03:27 +02003033 if (!ar) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003034 dev_err(&pdev->dev, "failed to allocate core\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003035 return -ENOMEM;
Michal Kaziore7b54192014-08-07 11:03:27 +02003036 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003037
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003038 ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
3039 pdev->vendor, pdev->device,
3040 pdev->subsystem_vendor, pdev->subsystem_device);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003041
Michal Kaziore7b54192014-08-07 11:03:27 +02003042 ar_pci = ath10k_pci_priv(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003043 ar_pci->pdev = pdev;
3044 ar_pci->dev = &pdev->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045 ar_pci->ar = ar;
Michal Kazior36582e52015-08-13 14:32:26 +02003046 ar->dev_id = pci_dev->device;
Anilkumar Kolli1aaf8ef2015-10-16 15:54:51 +03003047 ar_pci->pci_ps = pci_ps;
Raja Mani4ddb3292016-01-27 15:24:23 +05303048 ar_pci->bus_ops = &ath10k_pci_bus_ops;
Vasanthakumar Thiagarajan0fc7e272016-05-23 23:12:43 +03003049 ar_pci->pci_soft_reset = pci_soft_reset;
3050 ar_pci->pci_hard_reset = pci_hard_reset;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003051
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003052 ar->id.vendor = pdev->vendor;
3053 ar->id.device = pdev->device;
3054 ar->id.subsystem_vendor = pdev->subsystem_vendor;
3055 ar->id.subsystem_device = pdev->subsystem_device;
Michal Kaziorde57e2c2015-04-17 09:19:17 +00003056
Michal Kazior77258d42015-05-18 09:38:18 +00003057 setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
3058 (unsigned long)ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003059
Raja Mani90188f82016-01-27 15:24:24 +05303060 ret = ath10k_pci_setup_resource(ar);
3061 if (ret) {
3062 ath10k_err(ar, "failed to setup resource: %d\n", ret);
3063 goto err_core_destroy;
3064 }
3065
Michal Kazior2986e3e2014-08-07 11:03:30 +02003066 ret = ath10k_pci_claim(ar);
Kalle Valoe01ae682013-09-01 11:22:14 +03003067 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003068 ath10k_err(ar, "failed to claim device: %d\n", ret);
Raja Mani90188f82016-01-27 15:24:24 +05303069 goto err_free_pipes;
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);
Raja Mani90188f82016-01-27 15:24:24 +05303075 goto err_sleep;
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);
Raja Mani90188f82016-01-27 15:24:24 +05303084 goto err_sleep;
Michal Kazior403d6272014-08-22 14:23:31 +02003085 }
3086
Rajkumar Manoharancfe90112016-04-07 12:10:58 +05303087 ath10k_info(ar, "pci irq %s oper_irq_mode %d irq_mode %d reset_mode %d\n",
3088 ath10k_pci_get_irq_method(ar), ar_pci->oper_irq_mode,
Michal Kazior403d6272014-08-22 14:23:31 +02003089 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 Kaziorc0c378f2014-08-07 11:03:28 +02003130err_sleep:
Michal Kazior0bcbbe62015-05-29 07:35:24 +02003131 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003132 ath10k_pci_release(ar);
3133
Raja Mani90188f82016-01-27 15:24:24 +05303134err_free_pipes:
3135 ath10k_pci_free_pipes(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 Kazior403d6272014-08-22 14:23:31 +02003160 ath10k_pci_deinit_irq(ar);
Raja Mani90188f82016-01-27 15:24:24 +05303161 ath10k_pci_release_resource(ar);
Michal Kazior77258d42015-05-18 09:38:18 +00003162 ath10k_pci_sleep_sync(ar);
Michal Kazior2986e3e2014-08-07 11:03:30 +02003163 ath10k_pci_release(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164 ath10k_core_destroy(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003165}
3166
Kalle Valo5e3dd152013-06-12 20:52:10 +03003167MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
3168
3169static struct pci_driver ath10k_pci_driver = {
3170 .name = "ath10k_pci",
3171 .id_table = ath10k_pci_id_table,
3172 .probe = ath10k_pci_probe,
3173 .remove = ath10k_pci_remove,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003174};
3175
3176static int __init ath10k_pci_init(void)
3177{
3178 int ret;
3179
3180 ret = pci_register_driver(&ath10k_pci_driver);
3181 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003182 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
3183 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184
Raja Mani0b523ce2016-01-27 15:24:25 +05303185 ret = ath10k_ahb_init();
3186 if (ret)
3187 printk(KERN_ERR "ahb init failed: %d\n", ret);
3188
Kalle Valo5e3dd152013-06-12 20:52:10 +03003189 return ret;
3190}
3191module_init(ath10k_pci_init);
3192
3193static void __exit ath10k_pci_exit(void)
3194{
3195 pci_unregister_driver(&ath10k_pci_driver);
Raja Mani0b523ce2016-01-27 15:24:25 +05303196 ath10k_ahb_exit();
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197}
3198
3199module_exit(ath10k_pci_exit);
3200
3201MODULE_AUTHOR("Qualcomm Atheros");
3202MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
3203MODULE_LICENSE("Dual BSD/GPL");
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003204
3205/* QCA988x 2.0 firmware files */
Bartosz Markowski8026cae2014-10-06 14:16:41 +02003206MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
3207MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003208MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Kalle Valo53513c32015-03-25 13:12:42 +02003209MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003211MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003212
3213/* QCA6174 2.1 firmware files */
3214MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003215MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003216MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003217MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003218
3219/* QCA6174 3.1 firmware files */
3220MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
Michal Kaziore451c1d2015-05-26 13:09:22 +02003221MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
Bartosz Markowski5c427f52015-02-18 13:16:37 +01003222MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
Manikanta Pubbisetty0a51b342015-10-09 11:55:58 +03003223MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
Bartosz Markowskia226b512015-10-28 15:09:53 +01003224
3225/* QCA9377 1.0 firmware files */
3226MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3227MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);