xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/snoc/if_ahb.c (revision f28396d060cff5c6519f883cb28ae0116ce479f1)
1 /*
2  * Copyright (c) 2013-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: if_ahb.c
21  *
22  * c file for ahb specific implementations.
23  */
24 
25 #include "hif.h"
26 #include "target_type.h"
27 #include "hif_main.h"
28 #include "hif_debug.h"
29 #include "hif_io32.h"
30 #include "ce_main.h"
31 #include "ce_api.h"
32 #include "ce_tasklet.h"
33 #include "if_ahb.h"
34 #include "if_pci.h"
35 #include "ahb_api.h"
36 #include "pci_api.h"
37 #include "hif_napi.h"
38 #include "qal_vbus_dev.h"
39 
40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
41 #define IRQF_DISABLED 0x00000020
42 #endif
43 
44 #define HIF_IC_CE0_IRQ_OFFSET 4
45 #define HIF_IC_MAX_IRQ 52
46 
47 static uint8_t ic_irqnum[HIF_IC_MAX_IRQ];
48 /* integrated chip irq names */
49 const char *ic_irqname[HIF_IC_MAX_IRQ] = {
50 "misc-pulse1",
51 "misc-latch",
52 "sw-exception",
53 "watchdog",
54 "ce0",
55 "ce1",
56 "ce2",
57 "ce3",
58 "ce4",
59 "ce5",
60 "ce6",
61 "ce7",
62 "ce8",
63 "ce9",
64 "ce10",
65 "ce11",
66 "host2wbm-desc-feed",
67 "host2reo-re-injection",
68 "host2reo-command",
69 "host2rxdma-monitor-ring3",
70 "host2rxdma-monitor-ring2",
71 "host2rxdma-monitor-ring1",
72 "reo2ost-exception",
73 "wbm2host-rx-release",
74 "reo2host-status",
75 "reo2host-destination-ring4",
76 "reo2host-destination-ring3",
77 "reo2host-destination-ring2",
78 "reo2host-destination-ring1",
79 "rxdma2host-monitor-destination-mac3",
80 "rxdma2host-monitor-destination-mac2",
81 "rxdma2host-monitor-destination-mac1",
82 "ppdu-end-interrupts-mac3",
83 "ppdu-end-interrupts-mac2",
84 "ppdu-end-interrupts-mac1",
85 "rxdma2host-monitor-status-ring-mac3",
86 "rxdma2host-monitor-status-ring-mac2",
87 "rxdma2host-monitor-status-ring-mac1",
88 "host2rxdma-host-buf-ring-mac3",
89 "host2rxdma-host-buf-ring-mac2",
90 "host2rxdma-host-buf-ring-mac1",
91 "rxdma2host-destination-ring-mac3",
92 "rxdma2host-destination-ring-mac2",
93 "rxdma2host-destination-ring-mac1",
94 "host2tcl-input-ring4",
95 "host2tcl-input-ring3",
96 "host2tcl-input-ring2",
97 "host2tcl-input-ring1",
98 "wbm2host-tx-completions-ring3",
99 "wbm2host-tx-completions-ring2",
100 "wbm2host-tx-completions-ring1",
101 "tcl2host-status-ring",
102 };
103 
104 /** hif_ahb_get_irq_name() - get irqname
105  * This function gives irqnumber to irqname
106  * mapping.
107  *
108  * @irq_no: irq number
109  *
110  * Return: irq name
111  */
112 const char *hif_ahb_get_irq_name(int irq_no)
113 {
114 	return ic_irqname[irq_no];
115 }
116 
117 /**
118  * hif_disable_isr() - disable isr
119  *
120  * This function disables isr and kills tasklets
121  *
122  * @hif_ctx: struct hif_softc
123  *
124  * Return: void
125  */
126 void hif_ahb_disable_isr(struct hif_softc *scn)
127 {
128 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
129 
130 	hif_exec_kill(&scn->osc);
131 	hif_nointrs(scn);
132 	ce_tasklet_kill(scn);
133 	tasklet_kill(&sc->intr_tq);
134 	qdf_atomic_set(&scn->active_tasklet_cnt, 0);
135 	qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0);
136 }
137 
138 /**
139  * hif_dump_registers() - dump bus debug registers
140  * @scn: struct hif_opaque_softc
141  *
142  * This function dumps hif bus debug registers
143  *
144  * Return: 0 for success or error code
145  */
146 int hif_ahb_dump_registers(struct hif_softc *hif_ctx)
147 {
148 	int status;
149 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
150 
151 	status = hif_dump_ce_registers(scn);
152 	if (status)
153 		HIF_ERROR("%s: Dump CE Registers Failed status %d", __func__,
154 							status);
155 
156 	return 0;
157 }
158 
159 /**
160  * hif_ahb_close() - hif_bus_close
161  * @scn: pointer to the hif context.
162  *
163  * This is a callback function for hif_bus_close.
164  *
165  *
166  * Return: n/a
167  */
168 void hif_ahb_close(struct hif_softc *scn)
169 {
170 	hif_ce_close(scn);
171 }
172 
173 /**
174  * hif_bus_open() - hif_ahb open
175  * @hif_ctx: hif context
176  * @bus_type: bus type
177  *
178  * This is a callback function for hif_bus_open.
179  *
180  * Return: n/a
181  */
182 QDF_STATUS hif_ahb_open(struct hif_softc *hif_ctx, enum qdf_bus_type bus_type)
183 {
184 
185 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(hif_ctx);
186 
187 	qdf_spinlock_create(&sc->irq_lock);
188 	return hif_ce_open(hif_ctx);
189 }
190 
191 /**
192  * hif_bus_configure() - Configure the bus
193  * @scn: pointer to the hif context.
194  *
195  * This function configure the ahb bus
196  *
197  * return: 0 for success. nonzero for failure.
198  */
199 int hif_ahb_bus_configure(struct hif_softc *scn)
200 {
201 	return hif_pci_bus_configure(scn);
202 }
203 
204 /**
205  * hif_configure_msi_ahb - Configure MSI interrupts
206  * @sc : pointer to the hif context
207  *
208  * return: 0 for success. nonzero for failure.
209  */
210 
211 int hif_configure_msi_ahb(struct hif_pci_softc *sc)
212 {
213 	return 0;
214 }
215 
216 /**
217  * hif_ahb_configure_legacy_irq() - Configure Legacy IRQ
218  * @sc: pointer to the hif context.
219  *
220  * This function registers the irq handler and enables legacy interrupts
221  *
222  * return: 0 for success. nonzero for failure.
223  */
224 int hif_ahb_configure_legacy_irq(struct hif_pci_softc *sc)
225 {
226 	int ret = 0;
227 	struct hif_softc *scn = HIF_GET_SOFTC(sc);
228 	struct platform_device *pdev = (struct platform_device *)sc->pdev;
229 	int irq = 0;
230 
231 	/* do not support MSI or MSI IRQ failed */
232 	tasklet_init(&sc->intr_tq, wlan_tasklet, (unsigned long)sc);
233 	qal_vbus_get_irq((struct qdf_pfm_hndl *)pdev, "legacy", &irq);
234 	if (irq < 0) {
235 		dev_err(&pdev->dev, "Unable to get irq\n");
236 		ret = -EFAULT;
237 		goto end;
238 	}
239 	ret = request_irq(irq, hif_pci_legacy_ce_interrupt_handler,
240 				IRQF_DISABLED, "wlan_ahb", sc);
241 	if (ret) {
242 		dev_err(&pdev->dev, "ath_request_irq failed\n");
243 		ret = -EFAULT;
244 		goto end;
245 	}
246 	sc->irq = irq;
247 
248 	/* Use Legacy PCI Interrupts */
249 	hif_write32_mb(sc, sc->mem + (SOC_CORE_BASE_ADDRESS |
250 				PCIE_INTR_ENABLE_ADDRESS),
251 			PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
252 	/* read once to flush */
253 	hif_read32_mb(sc, sc->mem + (SOC_CORE_BASE_ADDRESS |
254 				PCIE_INTR_ENABLE_ADDRESS));
255 
256 end:
257 	return ret;
258 }
259 
260 int hif_ahb_configure_irq(struct hif_pci_softc *sc)
261 {
262 	int ret = 0;
263 	struct hif_softc *scn = HIF_GET_SOFTC(sc);
264 	struct platform_device *pdev = (struct platform_device *)sc->pdev;
265 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
266 	struct CE_attr *host_ce_conf = hif_state->host_ce_config;
267 	int irq = 0;
268 	int i;
269 
270 	/* configure per CE interrupts */
271 	for (i = 0; i < scn->ce_count; i++) {
272 		if (host_ce_conf[i].flags & CE_ATTR_DISABLE_INTR)
273 			continue;
274 		ret = pfrm_get_irq(&pdev->dev, (struct qdf_pfm_hndl *)pdev,
275 				   ic_irqname[HIF_IC_CE0_IRQ_OFFSET + i],
276 				   HIF_IC_CE0_IRQ_OFFSET + i, &irq);
277 		if (ret) {
278 			dev_err(&pdev->dev, "get irq failed\n");
279 			ret = -EFAULT;
280 			goto end;
281 		}
282 
283 		ic_irqnum[HIF_IC_CE0_IRQ_OFFSET + i] = irq;
284 		ret = pfrm_request_irq(&pdev->dev, irq,
285 				       hif_ahb_interrupt_handler,
286 				       IRQF_TRIGGER_RISING,
287 				       ic_irqname[HIF_IC_CE0_IRQ_OFFSET + i],
288 				       &hif_state->tasklets[i]);
289 		if (ret) {
290 			dev_err(&pdev->dev, "ath_request_irq failed\n");
291 			ret = -EFAULT;
292 			goto end;
293 		}
294 		hif_ahb_irq_enable(scn, i);
295 	}
296 
297 end:
298 	return ret;
299 }
300 
301 int hif_ahb_configure_grp_irq(struct hif_softc *scn,
302 			      struct hif_exec_context *hif_ext_group)
303 {
304 	int ret = 0;
305 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
306 	struct platform_device *pdev = (struct platform_device *)sc->pdev;
307 	int irq = 0;
308 	int j;
309 
310 	/* configure external interrupts */
311 	hif_ext_group->irq_enable = &hif_ahb_exec_grp_irq_enable;
312 	hif_ext_group->irq_disable = &hif_ahb_exec_grp_irq_disable;
313 	hif_ext_group->irq_name = &hif_ahb_get_irq_name;
314 	hif_ext_group->work_complete = &hif_dummy_grp_done;
315 
316 	for (j = 0; j < hif_ext_group->numirq; j++) {
317 		ret = pfrm_get_irq(&pdev->dev, (struct qdf_pfm_hndl *)pdev,
318 				   ic_irqname[hif_ext_group->irq[j]],
319 				   hif_ext_group->irq[j], &irq);
320 		if (ret) {
321 			dev_err(&pdev->dev, "get irq failed\n");
322 			ret = -EFAULT;
323 			goto end;
324 		}
325 		ic_irqnum[hif_ext_group->irq[j]] = irq;
326 		hif_ext_group->os_irq[j] = irq;
327 	}
328 
329 	qdf_spin_lock_irqsave(&hif_ext_group->irq_lock);
330 
331 	for (j = 0; j < hif_ext_group->numirq; j++) {
332 		irq = hif_ext_group->os_irq[j];
333 		irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY);
334 		ret = pfrm_request_irq(scn->qdf_dev->dev,
335 				       irq, hif_ext_group_interrupt_handler,
336 				       IRQF_TRIGGER_RISING,
337 				       ic_irqname[hif_ext_group->irq[j]],
338 				       hif_ext_group);
339 		if (ret) {
340 			dev_err(&pdev->dev, "ath_request_irq failed\n");
341 			ret = -EFAULT;
342 			goto end;
343 		}
344 	}
345 	qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock);
346 
347 	qdf_spin_lock_irqsave(&hif_ext_group->irq_lock);
348 	hif_ext_group->irq_requested = true;
349 
350 end:
351 	qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock);
352 	return ret;
353 }
354 
355 void hif_ahb_deconfigure_grp_irq(struct hif_softc *scn)
356 {
357 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
358 	struct hif_exec_context *hif_ext_group;
359 	int i, j;
360 	int irq = 0;
361 
362 	/* configure external interrupts */
363 	for (i = 0; i < hif_state->hif_num_extgroup; i++) {
364 		hif_ext_group = hif_state->hif_ext_group[i];
365 		if (hif_ext_group->irq_requested == true) {
366 			qdf_spin_lock_irqsave(&hif_ext_group->irq_lock);
367 			hif_ext_group->irq_requested = false;
368 			for (j = 0; j < hif_ext_group->numirq; j++) {
369 				irq = hif_ext_group->os_irq[j];
370 				hif_ext_group->irq_enabled = false;
371 				irq_clear_status_flags(irq,
372 						       IRQ_DISABLE_UNLAZY);
373 			}
374 			qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock);
375 
376 			/* Avoid holding the irq_lock while freeing the irq
377 			 * as the same lock is being held by the irq handler
378 			 * while disabling the irq. This causes a deadlock
379 			 * between free_irq and irq_handler.
380 			 */
381 			for (j = 0; j < hif_ext_group->numirq; j++) {
382 				irq = hif_ext_group->os_irq[j];
383 				pfrm_free_irq(scn->qdf_dev->dev,
384 					      irq, hif_ext_group);
385 			}
386 		}
387 	}
388 }
389 
390 irqreturn_t hif_ahb_interrupt_handler(int irq, void *context)
391 {
392 	struct ce_tasklet_entry *tasklet_entry = context;
393 	return ce_dispatch_interrupt(tasklet_entry->ce_id, tasklet_entry);
394 }
395 
396 /**
397  * hif_target_sync() : ensure the target is ready
398  * @scn: hif control structure
399  *
400  * Informs fw that we plan to use legacy interupts so that
401  * it can begin booting. Ensures that the fw finishes booting
402  * before continuing. Should be called before trying to write
403  * to the targets other registers for the first time.
404  *
405  * Return: none
406  */
407 int hif_target_sync_ahb(struct hif_softc *scn)
408 {
409 	int val = 0;
410 	int limit = 0;
411 
412 	while (limit < 50) {
413 		hif_write32_mb(scn, scn->mem +
414 			(SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS),
415 			PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
416 		qdf_mdelay(10);
417 		val = hif_read32_mb(scn, scn->mem +
418 			(SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS));
419 		if (val == 0)
420 			break;
421 		limit++;
422 	}
423 	hif_write32_mb(scn, scn->mem +
424 		(SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS),
425 		PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
426 	hif_write32_mb(scn, scn->mem + FW_INDICATOR_ADDRESS, FW_IND_HOST_READY);
427 	if (HAS_FW_INDICATOR) {
428 		int wait_limit = 500;
429 		int fw_ind = 0;
430 
431 		while (1) {
432 			fw_ind = hif_read32_mb(scn, scn->mem +
433 					FW_INDICATOR_ADDRESS);
434 			if (fw_ind & FW_IND_INITIALIZED)
435 				break;
436 			if (wait_limit-- < 0)
437 				break;
438 			hif_write32_mb(scn, scn->mem + (SOC_CORE_BASE_ADDRESS |
439 				PCIE_INTR_ENABLE_ADDRESS),
440 				PCIE_INTR_FIRMWARE_MASK);
441 			qdf_mdelay(10);
442 		}
443 		if (wait_limit < 0) {
444 			HIF_TRACE("%s: FW signal timed out", __func__);
445 			return -EIO;
446 		}
447 		HIF_TRACE("%s: Got FW signal, retries = %x", __func__,
448 							500-wait_limit);
449 	}
450 
451 	return 0;
452 }
453 
454 /**
455  * hif_disable_bus() - Disable the bus
456  * @scn : pointer to the hif context
457  *
458  * This function disables the bus and helds the target in reset state
459  *
460  * Return: none
461  */
462 void hif_ahb_disable_bus(struct hif_softc *scn)
463 {
464 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
465 	void __iomem *mem;
466 	struct platform_device *pdev = (struct platform_device *)sc->pdev;
467 	struct resource *memres = NULL;
468 	int mem_pa_size = 0;
469 	struct hif_target_info *tgt_info = NULL;
470 	struct qdf_vbus_resource *vmres = NULL;
471 	QDF_STATUS status;
472 
473 	tgt_info = &scn->target_info;
474 	/*Disable WIFI clock input*/
475 	if (sc->mem) {
476 		status = pfrm_platform_get_resource(
477 				scn->qdf_dev->dev,
478 				(struct qdf_pfm_hndl *)pdev, &vmres,
479 				IORESOURCE_MEM, 0);
480 		if (QDF_IS_STATUS_ERROR(status)) {
481 			HIF_INFO("%s: Failed to get IORESOURCE_MEM\n",
482 				 __func__);
483 			return;
484 		}
485 		memres = (struct resource *)vmres;
486 		if (memres)
487 			mem_pa_size = memres->end - memres->start + 1;
488 
489 		/* Should not be executed on 8074 platform */
490 		if ((tgt_info->target_type != TARGET_TYPE_QCA8074) &&
491 		    (tgt_info->target_type != TARGET_TYPE_QCA8074V2) &&
492 		    (tgt_info->target_type != TARGET_TYPE_QCA6018)) {
493 			hif_ahb_clk_enable_disable(&pdev->dev, 0);
494 
495 			hif_ahb_device_reset(scn);
496 		}
497 		mem = (void __iomem *)sc->mem;
498 		if (mem) {
499 			pfrm_devm_iounmap(&pdev->dev, mem);
500 			pfrm_devm_release_mem_region(&pdev->dev, scn->mem_pa,
501 						     mem_pa_size);
502 			sc->mem = NULL;
503 		}
504 	}
505 	scn->mem = NULL;
506 }
507 
508 /**
509  * hif_enable_bus() - Enable the bus
510  * @dev: dev
511  * @bdev: bus dev
512  * @bid: bus id
513  * @type: bus type
514  *
515  * This function enables the radio bus by enabling necessary
516  * clocks and waits for the target to get ready to proceed futher
517  *
518  * Return: QDF_STATUS
519  */
520 QDF_STATUS hif_ahb_enable_bus(struct hif_softc *ol_sc,
521 		struct device *dev, void *bdev,
522 		const struct hif_bus_id *bid,
523 		enum hif_enable_type type)
524 {
525 	int ret = 0;
526 	int hif_type;
527 	int target_type;
528 	const struct platform_device_id *id = (struct platform_device_id *)bid;
529 	struct platform_device *pdev = bdev;
530 	struct hif_target_info *tgt_info = NULL;
531 	struct resource *memres = NULL;
532 	void __iomem *mem = NULL;
533 	uint32_t revision_id = 0;
534 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(ol_sc);
535 	QDF_STATUS status;
536 	struct qdf_vbus_resource *vmres = NULL;
537 
538 	sc->pdev = (struct pci_dev *)pdev;
539 	sc->dev = &pdev->dev;
540 	sc->devid = id->driver_data;
541 
542 	ret = hif_get_device_type(id->driver_data, revision_id,
543 			&hif_type, &target_type);
544 	if (ret < 0) {
545 		HIF_ERROR("%s: invalid device  ret %d id %d revision_id %d",
546 			__func__, ret, (int)id->driver_data, revision_id);
547 		return QDF_STATUS_E_FAILURE;
548 	}
549 
550 	status = pfrm_platform_get_resource(&pdev->dev,
551 					    (struct qdf_pfm_hndl *)pdev,
552 					    &vmres,
553 					    IORESOURCE_MEM, 0);
554 	if (QDF_IS_STATUS_ERROR(status)) {
555 		HIF_INFO("%s: Failed to get IORESOURCE_MEM\n", __func__);
556 		return -EIO;
557 	}
558 	memres = (struct resource *)vmres;
559 	if (!memres) {
560 		HIF_INFO("%s: Failed to get IORESOURCE_MEM\n", __func__);
561 		return -EIO;
562 	}
563 
564 	ret = pfrm_dma_set_mask(dev, 32);
565 	if (ret) {
566 		HIF_INFO("ath: 32-bit DMA not available\n");
567 		goto err_cleanup1;
568 	}
569 
570 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
571 	ret = pfrm_dma_set_mask_and_coherent(dev, 32);
572 #else
573 	ret = pfrm_dma_set_coherent_mask(dev, 32);
574 #endif
575 	if (ret) {
576 		HIF_ERROR("%s: failed to set dma mask error = %d",
577 				__func__, ret);
578 		return ret;
579 	}
580 
581 	/* Arrange for access to Target SoC registers. */
582 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
583 	status = pfrm_devm_ioremap_resource(dev,
584 					    (struct qdf_vbus_resource *)memres,
585 					    &mem);
586 #else
587 	status = pfrm_devm_request_and_ioremap(
588 					dev,
589 					(struct qdf_vbus_resource *)memres,
590 					&mem);
591 #endif
592 	if (QDF_IS_STATUS_ERROR(status)) {
593 		HIF_INFO("ath: ioremap error\n");
594 		ret = PTR_ERR(mem);
595 		goto err_cleanup1;
596 	}
597 
598 	sc->mem = mem;
599 	ol_sc->mem = mem;
600 	ol_sc->mem_pa = memres->start;
601 
602 	tgt_info = hif_get_target_info_handle((struct hif_opaque_softc *)ol_sc);
603 
604 	tgt_info->target_type = target_type;
605 	hif_register_tbl_attach(ol_sc, hif_type);
606 	hif_target_register_tbl_attach(ol_sc, target_type);
607 
608 	if ((tgt_info->target_type != TARGET_TYPE_QCA8074) &&
609 	    (tgt_info->target_type != TARGET_TYPE_QCA8074V2) &&
610 	    (tgt_info->target_type != TARGET_TYPE_QCA6018)) {
611 		if (hif_ahb_enable_radio(sc, pdev, id) != 0) {
612 			HIF_INFO("error in enabling soc\n");
613 			return -EIO;
614 		}
615 
616 		if (hif_target_sync_ahb(ol_sc) < 0) {
617 			ret = -EIO;
618 			goto err_target_sync;
619 		}
620 	}
621 	HIF_TRACE("%s: X - hif_type = 0x%x, target_type = 0x%x",
622 			__func__, hif_type, target_type);
623 
624 	return QDF_STATUS_SUCCESS;
625 err_target_sync:
626 	if ((tgt_info->target_type != TARGET_TYPE_QCA8074) &&
627 	    (tgt_info->target_type != TARGET_TYPE_QCA8074V2) &&
628 	    (tgt_info->target_type != TARGET_TYPE_QCA6018)) {
629 		HIF_INFO("Error: Disabling target\n");
630 		hif_ahb_disable_bus(ol_sc);
631 	}
632 err_cleanup1:
633 	return ret;
634 }
635 
636 
637 /**
638  * hif_reset_soc() - reset soc
639  *
640  * @hif_ctx: HIF context
641  *
642  * This function resets soc and helds the
643  * target in reset state
644  *
645  * Return: void
646  */
647 /* Function to reset SoC */
648 void hif_ahb_reset_soc(struct hif_softc *hif_ctx)
649 {
650 	hif_ahb_device_reset(hif_ctx);
651 }
652 
653 
654 /**
655  * hif_nointrs() - disable IRQ
656  *
657  * @scn: struct hif_softc
658  *
659  * This function stops interrupt(s)
660  *
661  * Return: none
662  */
663 void hif_ahb_nointrs(struct hif_softc *scn)
664 {
665 	int i;
666 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
667 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
668 	struct CE_attr *host_ce_conf = hif_state->host_ce_config;
669 
670 	ce_unregister_irq(hif_state, CE_ALL_BITMAP);
671 
672 	if (scn->request_irq_done == false)
673 		return;
674 
675 	if (sc->num_msi_intrs > 0) {
676 		/* MSI interrupt(s) */
677 		for (i = 0; i < sc->num_msi_intrs; i++) {
678 			pfrm_free_irq(scn->qdf_dev->dev, sc->irq + i, sc);
679 		}
680 		sc->num_msi_intrs = 0;
681 	} else {
682 		if (!scn->per_ce_irq) {
683 			pfrm_free_irq(scn->qdf_dev->dev, sc->irq, sc);
684 		} else {
685 			for (i = 0; i < scn->ce_count; i++) {
686 				if (host_ce_conf[i].flags
687 						& CE_ATTR_DISABLE_INTR)
688 					continue;
689 
690 				pfrm_free_irq(
691 					scn->qdf_dev->dev,
692 					ic_irqnum[HIF_IC_CE0_IRQ_OFFSET + i],
693 					&hif_state->tasklets[i]);
694 			}
695 			hif_ahb_deconfigure_grp_irq(scn);
696 		}
697 	}
698 	scn->request_irq_done = false;
699 
700 }
701 
702 /**
703  * ce_irq_enable() - enable copy engine IRQ
704  * @scn: struct hif_softc
705  * @ce_id: ce_id
706  *
707  * This function enables the interrupt for the radio.
708  *
709  * Return: N/A
710  */
711 void hif_ahb_irq_enable(struct hif_softc *scn, int ce_id)
712 {
713 	uint32_t regval;
714 	uint32_t reg_offset = 0;
715 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
716 	struct CE_pipe_config *target_ce_conf = &hif_state->target_ce_config[ce_id];
717 	struct hif_target_info *tgt_info = &scn->target_info;
718 
719 	if (scn->per_ce_irq) {
720 		if (target_ce_conf->pipedir & PIPEDIR_OUT) {
721 			reg_offset = HOST_IE_ADDRESS;
722 			qdf_spin_lock_irqsave(&hif_state->irq_reg_lock);
723 			regval = hif_read32_mb(scn, scn->mem + reg_offset);
724 			regval |= HOST_IE_REG1_CE_BIT(ce_id);
725 			hif_write32_mb(scn, scn->mem + reg_offset, regval);
726 			qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock);
727 		}
728 		if (target_ce_conf->pipedir & PIPEDIR_IN) {
729 			reg_offset = HOST_IE_ADDRESS_2;
730 			qdf_spin_lock_irqsave(&hif_state->irq_reg_lock);
731 			regval = hif_read32_mb(scn, scn->mem + reg_offset);
732 			regval |= HOST_IE_REG2_CE_BIT(ce_id);
733 			hif_write32_mb(scn, scn->mem + reg_offset, regval);
734 			if (tgt_info->target_type == TARGET_TYPE_QCA8074 ||
735 			    tgt_info->target_type == TARGET_TYPE_QCA8074V2 ||
736 			    tgt_info->target_type == TARGET_TYPE_QCA6018) {
737 				/* Enable destination ring interrupts for
738 				 * 8074, 8074V2 and 6018
739 				 */
740 				regval = hif_read32_mb(scn, scn->mem +
741 					HOST_IE_ADDRESS_3);
742 				regval |= HOST_IE_REG3_CE_BIT(ce_id);
743 
744 				hif_write32_mb(scn, scn->mem +
745 					       HOST_IE_ADDRESS_3, regval);
746 			}
747 			qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock);
748 		}
749 	} else {
750 		hif_pci_irq_enable(scn, ce_id);
751 	}
752 }
753 
754 /**
755  * ce_irq_disable() - disable copy engine IRQ
756  * @scn: struct hif_softc
757  * @ce_id: ce_id
758  *
759  * Return: N/A
760  */
761 void hif_ahb_irq_disable(struct hif_softc *scn, int ce_id)
762 {
763 	uint32_t regval;
764 	uint32_t reg_offset = 0;
765 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
766 	struct CE_pipe_config *target_ce_conf = &hif_state->target_ce_config[ce_id];
767 	struct hif_target_info *tgt_info = &scn->target_info;
768 
769 	if (scn->per_ce_irq) {
770 		if (target_ce_conf->pipedir & PIPEDIR_OUT) {
771 			reg_offset = HOST_IE_ADDRESS;
772 			qdf_spin_lock_irqsave(&hif_state->irq_reg_lock);
773 			regval = hif_read32_mb(scn, scn->mem + reg_offset);
774 			regval &= ~HOST_IE_REG1_CE_BIT(ce_id);
775 			hif_write32_mb(scn, scn->mem + reg_offset, regval);
776 			qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock);
777 		}
778 		if (target_ce_conf->pipedir & PIPEDIR_IN) {
779 			reg_offset = HOST_IE_ADDRESS_2;
780 			qdf_spin_lock_irqsave(&hif_state->irq_reg_lock);
781 			regval = hif_read32_mb(scn, scn->mem + reg_offset);
782 			regval &= ~HOST_IE_REG2_CE_BIT(ce_id);
783 			hif_write32_mb(scn, scn->mem + reg_offset, regval);
784 			if (tgt_info->target_type == TARGET_TYPE_QCA8074 ||
785 			    tgt_info->target_type == TARGET_TYPE_QCA8074V2 ||
786 			    tgt_info->target_type == TARGET_TYPE_QCA6018) {
787 				/* Disable destination ring interrupts for
788 				 * 8074, 8074V2 and 6018
789 				 */
790 				regval = hif_read32_mb(scn, scn->mem +
791 					HOST_IE_ADDRESS_3);
792 				regval &= ~HOST_IE_REG3_CE_BIT(ce_id);
793 
794 				hif_write32_mb(scn, scn->mem +
795 					       HOST_IE_ADDRESS_3, regval);
796 			}
797 			qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock);
798 		}
799 	}
800 }
801 
802 void hif_ahb_exec_grp_irq_disable(struct hif_exec_context *hif_ext_group)
803 {
804 	int i;
805 
806 	qdf_spin_lock_irqsave(&hif_ext_group->irq_lock);
807 	if (hif_ext_group->irq_enabled) {
808 		for (i = 0; i < hif_ext_group->numirq; i++) {
809 			disable_irq_nosync(hif_ext_group->os_irq[i]);
810 		}
811 		hif_ext_group->irq_enabled = false;
812 	}
813 	qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock);
814 }
815 
816 void hif_ahb_exec_grp_irq_enable(struct hif_exec_context *hif_ext_group)
817 {
818 	int i;
819 
820 	qdf_spin_lock_irqsave(&hif_ext_group->irq_lock);
821 	if (hif_ext_group->irq_requested && !hif_ext_group->irq_enabled) {
822 		for (i = 0; i < hif_ext_group->numirq; i++) {
823 			enable_irq(hif_ext_group->os_irq[i]);
824 		}
825 		hif_ext_group->irq_enabled = true;
826 	}
827 	qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock);
828 }
829 
830 /**
831  * hif_ahb_needs_bmi() - return true if the soc needs bmi through the driver
832  * @scn: hif context
833  *
834  * Return: true if soc needs driver bmi otherwise false
835  */
836 bool hif_ahb_needs_bmi(struct hif_softc *scn)
837 {
838 	return !ce_srng_based(scn);
839 }
840 
841 void hif_ahb_display_stats(struct hif_softc *scn)
842 {
843 	if (!scn) {
844 		HIF_ERROR("%s, hif_scn null", __func__);
845 		return;
846 	}
847 	hif_display_ce_stats(scn);
848 }
849 
850 void hif_ahb_clear_stats(struct hif_softc *scn)
851 {
852 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
853 
854 	if (!hif_state) {
855 		HIF_ERROR("%s, hif_state null", __func__);
856 		return;
857 	}
858 	hif_clear_ce_stats(hif_state);
859 }
860