blob: 8f361582dcc99516e3890bbaffcce02319ad0d35 [file] [log] [blame]
Houston Hoffman32bc8eb2016-03-14 21:11:34 -07001/*
Yu Wang1e487a52017-02-07 20:10:42 +08002 * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
Houston Hoffman32bc8eb2016-03-14 21:11:34 -07003 *
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);
Yu Wang1e487a52017-02-07 20:10:42 +0800143 break;
Mohit Khanna1957ba92016-05-11 11:17:01 -0700144 case QDF_BUS_TYPE_USB:
145 status = hif_initialize_usb_ops(&hif_sc->bus_ops);
Nirav Shah3573f952016-05-12 18:37:03 +0530146 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700147 default:
148 status = QDF_STATUS_E_NOSUPPORT;
149 break;
150 }
151
152 if (status != QDF_STATUS_SUCCESS) {
153 HIF_ERROR("%s: %d not supported", __func__, bus_type);
154 return status;
155 }
156
157 status = hif_verify_basic_ops(hif_sc);
158 if (status != QDF_STATUS_SUCCESS)
159 return status;
160
161 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
162}
163
164/**
165 * hif_bus_close() - close the bus
166 * @hif_sc: hif_context
167 */
168void hif_bus_close(struct hif_softc *hif_sc)
169{
170 hif_sc->bus_ops.hif_bus_close(hif_sc);
171}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700172
173/**
174 * hif_bus_prevent_linkdown() - prevent linkdown
175 * @hif_ctx: hif context
176 * @flag: true = keep bus alive false = let bus go to sleep
177 *
178 * Keeps the bus awake durring suspend.
179 */
180void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
181{
182 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
183}
184
185
186void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
187{
188 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
189 hif_sc->bus_ops.hif_reset_soc(hif_sc);
190}
191
192int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
193{
194 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
195 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
196}
197
198int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
199{
200 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
201 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
202}
203
Houston Hoffman7fdff0c2016-08-29 12:31:58 -0700204int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx)
205{
206 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
207 return hif_sc->bus_ops.hif_bus_suspend_noirq(hif_sc);
208}
209
210int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx)
211{
212 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
213 return hif_sc->bus_ops.hif_bus_resume_noirq(hif_sc);
214}
215
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700216int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
217 bool sleep_ok, bool wait_for_it)
218{
219 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
220 sleep_ok, wait_for_it);
221}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700222
223void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
224{
225 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
226 hif_sc->bus_ops.hif_disable_isr(hif_sc);
227}
228
229void hif_nointrs(struct hif_softc *hif_sc)
230{
231 hif_sc->bus_ops.hif_nointrs(hif_sc);
232}
233
234QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
235 void *bdev, const hif_bus_id *bid,
236 enum hif_enable_type type)
237{
238 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
239}
240
241void hif_disable_bus(struct hif_softc *hif_sc)
242{
243 hif_sc->bus_ops.hif_disable_bus(hif_sc);
244}
245
246int hif_bus_configure(struct hif_softc *hif_sc)
247{
248 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
249}
250
Nirav Shah3573f952016-05-12 18:37:03 +0530251QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
252 int opcode, void *config, uint32_t config_len)
253{
254 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
255 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
256 config_len);
257}
258
259void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
260{
261 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
262 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
263}
264
265void hif_claim_device(struct hif_opaque_softc *hif_ctx)
266{
267 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
268 hif_sc->bus_ops.hif_claim_device(hif_sc);
269}
270
271void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
272{
273 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
274 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
275}
276
277void hif_stop(struct hif_opaque_softc *hif_ctx)
278{
279 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
280 hif_sc->bus_ops.hif_stop(hif_sc);
281}
282
Nirav Shah3573f952016-05-12 18:37:03 +0530283void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
284{
285 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
286}
287
Houston Hoffman8f239f62016-03-14 21:12:05 -0700288void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
289{
290 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
291}
292
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530293void hif_grp_irq_enable(struct hif_softc *hif_sc, uint32_t grp_id)
294{
295 hif_sc->bus_ops.hif_grp_irq_enable(hif_sc, grp_id);
296}
297
Houston Hoffman8f239f62016-03-14 21:12:05 -0700298void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
299{
300 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
301}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700302
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530303void hif_grp_irq_disable(struct hif_softc *hif_sc, uint32_t grp_id)
304{
305 hif_sc->bus_ops.hif_grp_irq_disable(hif_sc, grp_id);
306}
307
Houston Hoffman3c017e72016-03-14 21:12:11 -0700308int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
309{
310 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
311 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
312}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700313
Nirav Shah3573f952016-05-12 18:37:03 +0530314void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
315 void *ramdump_base,
316 uint32_t address, uint32_t size)
317{
318 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
319 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
320 address, size);
321}
322
323void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
324 qdf_dma_addr_t *ce_sr_base_paddr,
325 uint32_t *ce_sr_ring_size,
326 qdf_dma_addr_t *ce_reg_paddr)
327{
328 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
329 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
330 ce_sr_ring_size, ce_reg_paddr);
331}
332
333void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
334{
335 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
336 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
337}
338
Nirav Shahb70bd732016-05-25 14:31:51 +0530339void hif_display_bus_stats(struct hif_opaque_softc *scn)
340{
341 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
342
343 hif_sc->bus_ops.hif_display_stats(hif_sc);
344}
345
346void hif_clear_bus_stats(struct hif_opaque_softc *scn)
347{
348 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
349
350 hif_sc->bus_ops.hif_clear_stats(hif_sc);
351}
352
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700353/**
354 * hif_enable_power_management() - enable power management after driver load
355 * @hif_hdl: opaque pointer to the hif context
356 * is_packet_log_enabled: true if packet log is enabled
357 *
358 * Driver load and firmware download are done in a high performance mode.
359 * Enable power management after the driver is loaded.
360 * packet log can require fewer power management features to be enabled.
361 */
362void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
363 bool is_packet_log_enabled)
364{
365 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
366 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
367 is_packet_log_enabled);
368}
369
370/**
371 * hif_disable_power_management() - reset the bus power management
372 * @hif_hdl: opaque pointer to the hif context
373 *
374 * return the power management of the bus to its default state.
375 * This isn't necessarily a complete reversal of its counterpart.
376 * This should be called when unloading the driver.
377 */
378void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
379{
380 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
381 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
382}
383
Mohit Khanna1957ba92016-05-11 11:17:01 -0700384/**
385 * hif_set_bundle_mode() - enable bundling and set default rx bundle cnt
386 * @scn: pointer to hif_opaque_softc structure
387 * @enabled: flag to enable/disable bundling
388 * @rx_bundle_cnt: bundle count to be used for RX
389 *
390 * Return: none
391 */
392void hif_set_bundle_mode(struct hif_opaque_softc *scn, bool enabled,
393 int rx_bundle_cnt)
394{
395 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
396 hif_sc->bus_ops.hif_set_bundle_mode(hif_sc, enabled, rx_bundle_cnt);
397}
398
399/**
400 * hif_bus_reset_resume() - resume the bus after reset
401 * @scn: struct hif_opaque_softc
402 *
403 * This function is called to tell the driver that USB device has been resumed
404 * and it has also been reset. The driver should redo any necessary
405 * initialization. This function resets WLAN SOC.
406 *
407 * Return: int 0 for success, non zero for failure
408 */
409int hif_bus_reset_resume(struct hif_opaque_softc *scn)
410
411{
412 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
413 return hif_sc->bus_ops.hif_bus_reset_resume(hif_sc);
414}