blob: d26de4228b9e440c61174ed0a8eca11dd1ea68ac [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"
Komal Seelam6ee55902016-04-11 17:11:07 +053035#include "htc_services.h"
36#include "a_types.h"
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070037/**
38 * hif_intialize_default_ops() - intializes default operations values
39 *
40 * bus specific features should assign their dummy implementations here.
41 */
42static void hif_intialize_default_ops(struct hif_softc *hif_sc)
43{
44 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
45
46 /* must be filled in by hif_bus_open */
47 bus_ops->hif_bus_close = NULL;
48
49 /* dummy implementations */
50}
51
52#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
53
54/**
55 * hif_verify_basic_ops() - ensure required bus apis are defined
56 *
57 * all bus operations must be defined to avoid crashes
58 * itterate over the structure and ensure all function pointers
59 * are non null.
60 *
61 * Return: QDF_STATUS_SUCCESS if all the operations are defined
62 */
63static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
64{
65 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
66 void **ops_array = (void *)bus_ops;
67 QDF_STATUS status = QDF_STATUS_SUCCESS;
68 int i;
69
70 for (i = 0; i < NUM_OPS; i++) {
71 if (!ops_array[i]) {
72 HIF_ERROR("%s: function %d is null", __func__, i);
73 status = QDF_STATUS_E_NOSUPPORT;
74 }
75 }
76 return status;
77}
78
79/**
Houston Hoffman162164c2016-03-14 21:12:10 -070080 * hif_bus_get_context_size - API to return size of the bus specific structure
81 *
82 * Return: sizeof of hif_pci_softc
83 */
84int hif_bus_get_context_size(enum qdf_bus_type bus_type)
85{
86 switch (bus_type) {
87 case QDF_BUS_TYPE_PCI:
88 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -070089 case QDF_BUS_TYPE_AHB:
90 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -070091 case QDF_BUS_TYPE_SNOC:
92 return hif_snoc_get_context_size();
93 default:
94 return 0;
95 }
96}
97
98/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070099 * hif_bus_open() - initialize the bus_ops and call the bus specific open
100 * hif_sc: hif_context
101 * bus_type: type of bus being enumerated
102 *
103 * Return: QDF_STATUS_SUCCESS or error
104 */
105QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
106 enum qdf_bus_type bus_type)
107{
108 QDF_STATUS status = QDF_STATUS_E_INVAL;
109
110 hif_intialize_default_ops(hif_sc);
111
112 switch (bus_type) {
113 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700114 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700115 break;
116 case QDF_BUS_TYPE_SNOC:
117 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
118 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700119 case QDF_BUS_TYPE_AHB:
120 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
121 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700122 default:
123 status = QDF_STATUS_E_NOSUPPORT;
124 break;
125 }
126
127 if (status != QDF_STATUS_SUCCESS) {
128 HIF_ERROR("%s: %d not supported", __func__, bus_type);
129 return status;
130 }
131
132 status = hif_verify_basic_ops(hif_sc);
133 if (status != QDF_STATUS_SUCCESS)
134 return status;
135
136 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
137}
138
139/**
140 * hif_bus_close() - close the bus
141 * @hif_sc: hif_context
142 */
143void hif_bus_close(struct hif_softc *hif_sc)
144{
145 hif_sc->bus_ops.hif_bus_close(hif_sc);
146}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700147
148/**
149 * hif_bus_prevent_linkdown() - prevent linkdown
150 * @hif_ctx: hif context
151 * @flag: true = keep bus alive false = let bus go to sleep
152 *
153 * Keeps the bus awake durring suspend.
154 */
155void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
156{
157 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
158}
159
160
161void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
162{
163 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
164 hif_sc->bus_ops.hif_reset_soc(hif_sc);
165}
166
167int hif_bus_suspend(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_suspend(hif_sc);
171}
172
173int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
174{
175 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
176 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
177}
178
179int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
180 bool sleep_ok, bool wait_for_it)
181{
182 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
183 sleep_ok, wait_for_it);
184}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700185
186void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
187{
188 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
189 hif_sc->bus_ops.hif_disable_isr(hif_sc);
190}
191
192void hif_nointrs(struct hif_softc *hif_sc)
193{
194 hif_sc->bus_ops.hif_nointrs(hif_sc);
195}
196
197QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
198 void *bdev, const hif_bus_id *bid,
199 enum hif_enable_type type)
200{
201 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
202}
203
204void hif_disable_bus(struct hif_softc *hif_sc)
205{
206 hif_sc->bus_ops.hif_disable_bus(hif_sc);
207}
208
209int hif_bus_configure(struct hif_softc *hif_sc)
210{
211 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
212}
213
214void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
215{
216 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
217}
218
219void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
220{
221 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
222}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700223
224int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
225{
226 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
227 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
228}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700229
230/**
231 * hif_enable_power_management() - enable power management after driver load
232 * @hif_hdl: opaque pointer to the hif context
233 * is_packet_log_enabled: true if packet log is enabled
234 *
235 * Driver load and firmware download are done in a high performance mode.
236 * Enable power management after the driver is loaded.
237 * packet log can require fewer power management features to be enabled.
238 */
239void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
240 bool is_packet_log_enabled)
241{
242 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
243 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
244 is_packet_log_enabled);
245}
246
247/**
248 * hif_disable_power_management() - reset the bus power management
249 * @hif_hdl: opaque pointer to the hif context
250 *
251 * return the power management of the bus to its default state.
252 * This isn't necessarily a complete reversal of its counterpart.
253 * This should be called when unloading the driver.
254 */
255void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
256{
257 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
258 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
259}
260