blob: 8fe9a3907384e6661be87362948236e3262f5a70 [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"
Nirav Shah3573f952016-05-12 18:37:03 +053034#if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB)
Houston Hoffman162164c2016-03-14 21:12:10 -070035#include "ce_main.h"
Nirav Shah3573f952016-05-12 18:37:03 +053036#endif
Komal Seelam6ee55902016-04-11 17:11:07 +053037#include "htc_services.h"
38#include "a_types.h"
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070039/**
40 * hif_intialize_default_ops() - intializes default operations values
41 *
42 * bus specific features should assign their dummy implementations here.
43 */
44static void hif_intialize_default_ops(struct hif_softc *hif_sc)
45{
46 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
47
48 /* must be filled in by hif_bus_open */
49 bus_ops->hif_bus_close = NULL;
50
51 /* dummy implementations */
52}
53
54#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
55
56/**
57 * hif_verify_basic_ops() - ensure required bus apis are defined
58 *
59 * all bus operations must be defined to avoid crashes
60 * itterate over the structure and ensure all function pointers
61 * are non null.
62 *
63 * Return: QDF_STATUS_SUCCESS if all the operations are defined
64 */
65static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
66{
67 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
68 void **ops_array = (void *)bus_ops;
69 QDF_STATUS status = QDF_STATUS_SUCCESS;
70 int i;
71
72 for (i = 0; i < NUM_OPS; i++) {
73 if (!ops_array[i]) {
74 HIF_ERROR("%s: function %d is null", __func__, i);
75 status = QDF_STATUS_E_NOSUPPORT;
76 }
77 }
78 return status;
79}
80
81/**
Houston Hoffman162164c2016-03-14 21:12:10 -070082 * hif_bus_get_context_size - API to return size of the bus specific structure
83 *
84 * Return: sizeof of hif_pci_softc
85 */
86int hif_bus_get_context_size(enum qdf_bus_type bus_type)
87{
88 switch (bus_type) {
89 case QDF_BUS_TYPE_PCI:
90 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -070091 case QDF_BUS_TYPE_AHB:
92 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -070093 case QDF_BUS_TYPE_SNOC:
94 return hif_snoc_get_context_size();
Nirav Shah3573f952016-05-12 18:37:03 +053095 case QDF_BUS_TYPE_SDIO:
96 return hif_sdio_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -070097 default:
98 return 0;
99 }
100}
101
102/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700103 * hif_bus_open() - initialize the bus_ops and call the bus specific open
104 * hif_sc: hif_context
105 * bus_type: type of bus being enumerated
106 *
107 * Return: QDF_STATUS_SUCCESS or error
108 */
109QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
110 enum qdf_bus_type bus_type)
111{
112 QDF_STATUS status = QDF_STATUS_E_INVAL;
113
114 hif_intialize_default_ops(hif_sc);
115
116 switch (bus_type) {
117 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700118 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700119 break;
120 case QDF_BUS_TYPE_SNOC:
121 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
122 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700123 case QDF_BUS_TYPE_AHB:
124 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
125 break;
Nirav Shah3573f952016-05-12 18:37:03 +0530126 case QDF_BUS_TYPE_SDIO:
127 status = hif_initialize_sdio_ops(hif_sc);
128 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700129 default:
130 status = QDF_STATUS_E_NOSUPPORT;
131 break;
132 }
133
134 if (status != QDF_STATUS_SUCCESS) {
135 HIF_ERROR("%s: %d not supported", __func__, bus_type);
136 return status;
137 }
138
139 status = hif_verify_basic_ops(hif_sc);
140 if (status != QDF_STATUS_SUCCESS)
141 return status;
142
143 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
144}
145
146/**
147 * hif_bus_close() - close the bus
148 * @hif_sc: hif_context
149 */
150void hif_bus_close(struct hif_softc *hif_sc)
151{
152 hif_sc->bus_ops.hif_bus_close(hif_sc);
153}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700154
155/**
156 * hif_bus_prevent_linkdown() - prevent linkdown
157 * @hif_ctx: hif context
158 * @flag: true = keep bus alive false = let bus go to sleep
159 *
160 * Keeps the bus awake durring suspend.
161 */
162void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
163{
164 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
165}
166
167
168void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
169{
170 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
171 hif_sc->bus_ops.hif_reset_soc(hif_sc);
172}
173
174int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
175{
176 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
177 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
178}
179
180int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
181{
182 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
183 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
184}
185
186int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
187 bool sleep_ok, bool wait_for_it)
188{
189 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
190 sleep_ok, wait_for_it);
191}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700192
193void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
194{
195 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
196 hif_sc->bus_ops.hif_disable_isr(hif_sc);
197}
198
199void hif_nointrs(struct hif_softc *hif_sc)
200{
201 hif_sc->bus_ops.hif_nointrs(hif_sc);
202}
203
204QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
205 void *bdev, const hif_bus_id *bid,
206 enum hif_enable_type type)
207{
208 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
209}
210
211void hif_disable_bus(struct hif_softc *hif_sc)
212{
213 hif_sc->bus_ops.hif_disable_bus(hif_sc);
214}
215
216int hif_bus_configure(struct hif_softc *hif_sc)
217{
218 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
219}
220
Nirav Shah3573f952016-05-12 18:37:03 +0530221QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
222 int opcode, void *config, uint32_t config_len)
223{
224 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
225 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
226 config_len);
227}
228
229void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
230{
231 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
232 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
233}
234
235void hif_claim_device(struct hif_opaque_softc *hif_ctx)
236{
237 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
238 hif_sc->bus_ops.hif_claim_device(hif_sc);
239}
240
241void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
242{
243 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
244 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
245}
246
247void hif_stop(struct hif_opaque_softc *hif_ctx)
248{
249 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
250 hif_sc->bus_ops.hif_stop(hif_sc);
251}
252
253void hif_bus_pkt_dl_len_set(struct hif_opaque_softc *hif_ctx,
254 u_int32_t pkt_download_len)
255{
256 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
257 hif_sc->bus_ops.hif_bus_pkt_dl_len_set(hif_sc, pkt_download_len);
258}
259
260void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
261{
262 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
263}
264
Houston Hoffman8f239f62016-03-14 21:12:05 -0700265void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
266{
267 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
268}
269
270void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
271{
272 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
273}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700274
275int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
276{
277 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
278 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
279}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700280
Nirav Shah3573f952016-05-12 18:37:03 +0530281void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
282 void *ramdump_base,
283 uint32_t address, uint32_t size)
284{
285 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
286 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
287 address, size);
288}
289
290void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
291 qdf_dma_addr_t *ce_sr_base_paddr,
292 uint32_t *ce_sr_ring_size,
293 qdf_dma_addr_t *ce_reg_paddr)
294{
295 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
296 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
297 ce_sr_ring_size, ce_reg_paddr);
298}
299
300void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
301{
302 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
303 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
304}
305
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700306/**
307 * hif_enable_power_management() - enable power management after driver load
308 * @hif_hdl: opaque pointer to the hif context
309 * is_packet_log_enabled: true if packet log is enabled
310 *
311 * Driver load and firmware download are done in a high performance mode.
312 * Enable power management after the driver is loaded.
313 * packet log can require fewer power management features to be enabled.
314 */
315void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
316 bool is_packet_log_enabled)
317{
318 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
319 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
320 is_packet_log_enabled);
321}
322
323/**
324 * hif_disable_power_management() - reset the bus power management
325 * @hif_hdl: opaque pointer to the hif context
326 *
327 * return the power management of the bus to its default state.
328 * This isn't necessarily a complete reversal of its counterpart.
329 * This should be called when unloading the driver.
330 */
331void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
332{
333 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
334 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
335}
336