blob: 4f4f9c673990110dfeea00173c9d393393c74cbc [file] [log] [blame]
Houston Hoffman32bc8eb2016-03-14 21:11:34 -07001/*
2 * Copyright (c) 2016 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28
29/* this file dispatches functions to bus specific definitions */
30#include "hif_debug.h"
31#include "hif.h"
32#include "hif_main.h"
33#include "multibus.h"
Houston Hoffman162164c2016-03-14 21:12:10 -070034#include "ce_main.h"
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070035
36/**
37 * hif_intialize_default_ops() - intializes default operations values
38 *
39 * bus specific features should assign their dummy implementations here.
40 */
41static void hif_intialize_default_ops(struct hif_softc *hif_sc)
42{
43 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
44
45 /* must be filled in by hif_bus_open */
46 bus_ops->hif_bus_close = NULL;
47
48 /* dummy implementations */
49}
50
51#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
52
53/**
54 * hif_verify_basic_ops() - ensure required bus apis are defined
55 *
56 * all bus operations must be defined to avoid crashes
57 * itterate over the structure and ensure all function pointers
58 * are non null.
59 *
60 * Return: QDF_STATUS_SUCCESS if all the operations are defined
61 */
62static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
63{
64 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
65 void **ops_array = (void *)bus_ops;
66 QDF_STATUS status = QDF_STATUS_SUCCESS;
67 int i;
68
69 for (i = 0; i < NUM_OPS; i++) {
70 if (!ops_array[i]) {
71 HIF_ERROR("%s: function %d is null", __func__, i);
72 status = QDF_STATUS_E_NOSUPPORT;
73 }
74 }
75 return status;
76}
77
78/**
Houston Hoffman162164c2016-03-14 21:12:10 -070079 * hif_bus_get_context_size - API to return size of the bus specific structure
80 *
81 * Return: sizeof of hif_pci_softc
82 */
83int hif_bus_get_context_size(enum qdf_bus_type bus_type)
84{
85 switch (bus_type) {
86 case QDF_BUS_TYPE_PCI:
87 return hif_pci_get_context_size();
88 case QDF_BUS_TYPE_SNOC:
89 return hif_snoc_get_context_size();
90 default:
91 return 0;
92 }
93}
94
95/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070096 * hif_bus_open() - initialize the bus_ops and call the bus specific open
97 * hif_sc: hif_context
98 * bus_type: type of bus being enumerated
99 *
100 * Return: QDF_STATUS_SUCCESS or error
101 */
102QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
103 enum qdf_bus_type bus_type)
104{
105 QDF_STATUS status = QDF_STATUS_E_INVAL;
106
107 hif_intialize_default_ops(hif_sc);
108
109 switch (bus_type) {
110 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700111 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700112 break;
113 case QDF_BUS_TYPE_SNOC:
114 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
115 break;
116 default:
117 status = QDF_STATUS_E_NOSUPPORT;
118 break;
119 }
120
121 if (status != QDF_STATUS_SUCCESS) {
122 HIF_ERROR("%s: %d not supported", __func__, bus_type);
123 return status;
124 }
125
126 status = hif_verify_basic_ops(hif_sc);
127 if (status != QDF_STATUS_SUCCESS)
128 return status;
129
130 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
131}
132
133/**
134 * hif_bus_close() - close the bus
135 * @hif_sc: hif_context
136 */
137void hif_bus_close(struct hif_softc *hif_sc)
138{
139 hif_sc->bus_ops.hif_bus_close(hif_sc);
140}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700141
142/**
143 * hif_bus_prevent_linkdown() - prevent linkdown
144 * @hif_ctx: hif context
145 * @flag: true = keep bus alive false = let bus go to sleep
146 *
147 * Keeps the bus awake durring suspend.
148 */
149void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
150{
151 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
152}
153
154
155void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
156{
157 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
158 hif_sc->bus_ops.hif_reset_soc(hif_sc);
159}
160
161int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
162{
163 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
164 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
165}
166
167int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
168{
169 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
170 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
171}
172
173int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
174 bool sleep_ok, bool wait_for_it)
175{
176 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
177 sleep_ok, wait_for_it);
178}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700179
180void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
181{
182 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
183 hif_sc->bus_ops.hif_disable_isr(hif_sc);
184}
185
186void hif_nointrs(struct hif_softc *hif_sc)
187{
188 hif_sc->bus_ops.hif_nointrs(hif_sc);
189}
190
191QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
192 void *bdev, const hif_bus_id *bid,
193 enum hif_enable_type type)
194{
195 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
196}
197
198void hif_disable_bus(struct hif_softc *hif_sc)
199{
200 hif_sc->bus_ops.hif_disable_bus(hif_sc);
201}
202
203int hif_bus_configure(struct hif_softc *hif_sc)
204{
205 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
206}
207
208void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
209{
210 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
211}
212
213void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
214{
215 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
216}