blob: 87fb069af9d5a5662394262e3549a3b89c7d6663 [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"
Jeff Johnson6950fdb2016-10-07 13:00:59 -070033#include "hif_io32.h"
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070034#include "multibus.h"
Mohit Khanna1957ba92016-05-11 11:17:01 -070035#include "dummy.h"
Nirav Shah3573f952016-05-12 18:37:03 +053036#if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB)
Houston Hoffman162164c2016-03-14 21:12:10 -070037#include "ce_main.h"
Nirav Shah3573f952016-05-12 18:37:03 +053038#endif
Komal Seelam6ee55902016-04-11 17:11:07 +053039#include "htc_services.h"
40#include "a_types.h"
Nirav Shahb70bd732016-05-25 14:31:51 +053041#include "dummy.h"
42
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070043/**
44 * hif_intialize_default_ops() - intializes default operations values
45 *
46 * bus specific features should assign their dummy implementations here.
47 */
48static void hif_intialize_default_ops(struct hif_softc *hif_sc)
49{
50 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
51
52 /* must be filled in by hif_bus_open */
53 bus_ops->hif_bus_close = NULL;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070054 /* dummy implementations */
Nirav Shahb70bd732016-05-25 14:31:51 +053055 bus_ops->hif_display_stats =
56 &hif_dummy_display_stats;
57 bus_ops->hif_clear_stats =
58 &hif_dummy_clear_stats;
Houston Hoffman7fdff0c2016-08-29 12:31:58 -070059 bus_ops->hif_set_bundle_mode = &hif_dummy_set_bundle_mode;
60 bus_ops->hif_bus_reset_resume = &hif_dummy_bus_reset_resume;
61 bus_ops->hif_bus_suspend_noirq = &hif_dummy_bus_suspend_noirq;
62 bus_ops->hif_bus_resume_noirq = &hif_dummy_bus_resume_noirq;
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +053063 bus_ops->hif_grp_irq_disable = &hif_dummy_grp_irq_disable;
64 bus_ops->hif_grp_irq_enable = &hif_dummy_grp_irq_enable;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070065}
66
67#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
68
69/**
70 * hif_verify_basic_ops() - ensure required bus apis are defined
71 *
72 * all bus operations must be defined to avoid crashes
73 * itterate over the structure and ensure all function pointers
74 * are non null.
75 *
76 * Return: QDF_STATUS_SUCCESS if all the operations are defined
77 */
78static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
79{
80 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
81 void **ops_array = (void *)bus_ops;
82 QDF_STATUS status = QDF_STATUS_SUCCESS;
83 int i;
84
85 for (i = 0; i < NUM_OPS; i++) {
86 if (!ops_array[i]) {
87 HIF_ERROR("%s: function %d is null", __func__, i);
88 status = QDF_STATUS_E_NOSUPPORT;
89 }
90 }
91 return status;
92}
93
94/**
Houston Hoffman162164c2016-03-14 21:12:10 -070095 * hif_bus_get_context_size - API to return size of the bus specific structure
96 *
97 * Return: sizeof of hif_pci_softc
98 */
99int hif_bus_get_context_size(enum qdf_bus_type bus_type)
100{
101 switch (bus_type) {
102 case QDF_BUS_TYPE_PCI:
103 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -0700104 case QDF_BUS_TYPE_AHB:
105 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700106 case QDF_BUS_TYPE_SNOC:
107 return hif_snoc_get_context_size();
Nirav Shah3573f952016-05-12 18:37:03 +0530108 case QDF_BUS_TYPE_SDIO:
109 return hif_sdio_get_context_size();
Mohit Khanna1957ba92016-05-11 11:17:01 -0700110 case QDF_BUS_TYPE_USB:
111 return hif_usb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700112 default:
113 return 0;
114 }
115}
116
117/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700118 * hif_bus_open() - initialize the bus_ops and call the bus specific open
119 * hif_sc: hif_context
120 * bus_type: type of bus being enumerated
121 *
122 * Return: QDF_STATUS_SUCCESS or error
123 */
124QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
125 enum qdf_bus_type bus_type)
126{
127 QDF_STATUS status = QDF_STATUS_E_INVAL;
128
129 hif_intialize_default_ops(hif_sc);
130
131 switch (bus_type) {
132 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700133 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700134 break;
135 case QDF_BUS_TYPE_SNOC:
136 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
137 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700138 case QDF_BUS_TYPE_AHB:
139 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
140 break;
Nirav Shah3573f952016-05-12 18:37:03 +0530141 case QDF_BUS_TYPE_SDIO:
142 status = hif_initialize_sdio_ops(hif_sc);
Mohit Khanna1957ba92016-05-11 11:17:01 -0700143 case QDF_BUS_TYPE_USB:
144 status = hif_initialize_usb_ops(&hif_sc->bus_ops);
Nirav Shah3573f952016-05-12 18:37:03 +0530145 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700146 default:
147 status = QDF_STATUS_E_NOSUPPORT;
148 break;
149 }
150
151 if (status != QDF_STATUS_SUCCESS) {
152 HIF_ERROR("%s: %d not supported", __func__, bus_type);
153 return status;
154 }
155
156 status = hif_verify_basic_ops(hif_sc);
157 if (status != QDF_STATUS_SUCCESS)
158 return status;
159
160 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
161}
162
163/**
164 * hif_bus_close() - close the bus
165 * @hif_sc: hif_context
166 */
167void hif_bus_close(struct hif_softc *hif_sc)
168{
169 hif_sc->bus_ops.hif_bus_close(hif_sc);
170}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700171
172/**
173 * hif_bus_prevent_linkdown() - prevent linkdown
174 * @hif_ctx: hif context
175 * @flag: true = keep bus alive false = let bus go to sleep
176 *
177 * Keeps the bus awake durring suspend.
178 */
179void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
180{
181 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
182}
183
184
185void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
186{
187 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
188 hif_sc->bus_ops.hif_reset_soc(hif_sc);
189}
190
191int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
192{
193 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
194 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
195}
196
197int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
198{
199 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
200 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
201}
202
Houston Hoffman7fdff0c2016-08-29 12:31:58 -0700203int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx)
204{
205 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
206 return hif_sc->bus_ops.hif_bus_suspend_noirq(hif_sc);
207}
208
209int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx)
210{
211 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
212 return hif_sc->bus_ops.hif_bus_resume_noirq(hif_sc);
213}
214
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700215int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
216 bool sleep_ok, bool wait_for_it)
217{
218 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
219 sleep_ok, wait_for_it);
220}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700221
222void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
223{
224 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
225 hif_sc->bus_ops.hif_disable_isr(hif_sc);
226}
227
228void hif_nointrs(struct hif_softc *hif_sc)
229{
230 hif_sc->bus_ops.hif_nointrs(hif_sc);
231}
232
233QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
234 void *bdev, const hif_bus_id *bid,
235 enum hif_enable_type type)
236{
237 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
238}
239
240void hif_disable_bus(struct hif_softc *hif_sc)
241{
242 hif_sc->bus_ops.hif_disable_bus(hif_sc);
243}
244
245int hif_bus_configure(struct hif_softc *hif_sc)
246{
247 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
248}
249
Nirav Shah3573f952016-05-12 18:37:03 +0530250QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
251 int opcode, void *config, uint32_t config_len)
252{
253 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
254 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
255 config_len);
256}
257
258void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
259{
260 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
261 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
262}
263
264void hif_claim_device(struct hif_opaque_softc *hif_ctx)
265{
266 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
267 hif_sc->bus_ops.hif_claim_device(hif_sc);
268}
269
270void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
271{
272 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
273 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
274}
275
276void hif_stop(struct hif_opaque_softc *hif_ctx)
277{
278 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
279 hif_sc->bus_ops.hif_stop(hif_sc);
280}
281
Nirav Shah3573f952016-05-12 18:37:03 +0530282void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
283{
284 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
285}
286
Houston Hoffman8f239f62016-03-14 21:12:05 -0700287void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
288{
289 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
290}
291
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530292void hif_grp_irq_enable(struct hif_softc *hif_sc, uint32_t grp_id)
293{
294 hif_sc->bus_ops.hif_grp_irq_enable(hif_sc, grp_id);
295}
296
Houston Hoffman8f239f62016-03-14 21:12:05 -0700297void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
298{
299 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
300}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700301
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530302void hif_grp_irq_disable(struct hif_softc *hif_sc, uint32_t grp_id)
303{
304 hif_sc->bus_ops.hif_grp_irq_disable(hif_sc, grp_id);
305}
306
Houston Hoffman3c017e72016-03-14 21:12:11 -0700307int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
308{
309 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
310 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
311}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700312
Nirav Shah3573f952016-05-12 18:37:03 +0530313void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
314 void *ramdump_base,
315 uint32_t address, uint32_t size)
316{
317 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
318 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
319 address, size);
320}
321
322void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
323 qdf_dma_addr_t *ce_sr_base_paddr,
324 uint32_t *ce_sr_ring_size,
325 qdf_dma_addr_t *ce_reg_paddr)
326{
327 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
328 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
329 ce_sr_ring_size, ce_reg_paddr);
330}
331
332void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
333{
334 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
335 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
336}
337
Nirav Shahb70bd732016-05-25 14:31:51 +0530338void hif_display_bus_stats(struct hif_opaque_softc *scn)
339{
340 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
341
342 hif_sc->bus_ops.hif_display_stats(hif_sc);
343}
344
345void hif_clear_bus_stats(struct hif_opaque_softc *scn)
346{
347 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
348
349 hif_sc->bus_ops.hif_clear_stats(hif_sc);
350}
351
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700352/**
353 * hif_enable_power_management() - enable power management after driver load
354 * @hif_hdl: opaque pointer to the hif context
355 * is_packet_log_enabled: true if packet log is enabled
356 *
357 * Driver load and firmware download are done in a high performance mode.
358 * Enable power management after the driver is loaded.
359 * packet log can require fewer power management features to be enabled.
360 */
361void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
362 bool is_packet_log_enabled)
363{
364 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
365 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
366 is_packet_log_enabled);
367}
368
369/**
370 * hif_disable_power_management() - reset the bus power management
371 * @hif_hdl: opaque pointer to the hif context
372 *
373 * return the power management of the bus to its default state.
374 * This isn't necessarily a complete reversal of its counterpart.
375 * This should be called when unloading the driver.
376 */
377void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
378{
379 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
380 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
381}
382
Mohit Khanna1957ba92016-05-11 11:17:01 -0700383/**
384 * hif_set_bundle_mode() - enable bundling and set default rx bundle cnt
385 * @scn: pointer to hif_opaque_softc structure
386 * @enabled: flag to enable/disable bundling
387 * @rx_bundle_cnt: bundle count to be used for RX
388 *
389 * Return: none
390 */
391void hif_set_bundle_mode(struct hif_opaque_softc *scn, bool enabled,
392 int rx_bundle_cnt)
393{
394 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
395 hif_sc->bus_ops.hif_set_bundle_mode(hif_sc, enabled, rx_bundle_cnt);
396}
397
398/**
399 * hif_bus_reset_resume() - resume the bus after reset
400 * @scn: struct hif_opaque_softc
401 *
402 * This function is called to tell the driver that USB device has been resumed
403 * and it has also been reset. The driver should redo any necessary
404 * initialization. This function resets WLAN SOC.
405 *
406 * Return: int 0 for success, non zero for failure
407 */
408int hif_bus_reset_resume(struct hif_opaque_softc *scn)
409
410{
411 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
412 return hif_sc->bus_ops.hif_bus_reset_resume(hif_sc);
413}