blob: 4a8f7e77058e29b121b4290aa92427f79730404f [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"
Dustin Brown6834d322017-03-20 15:02:48 -070038#include "ce_api.h"
39#include "ce_internal.h"
Nirav Shah3573f952016-05-12 18:37:03 +053040#endif
Komal Seelam6ee55902016-04-11 17:11:07 +053041#include "htc_services.h"
42#include "a_types.h"
Nirav Shahb70bd732016-05-25 14:31:51 +053043#include "dummy.h"
44
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070045/**
46 * hif_intialize_default_ops() - intializes default operations values
47 *
48 * bus specific features should assign their dummy implementations here.
49 */
50static void hif_intialize_default_ops(struct hif_softc *hif_sc)
51{
52 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
53
54 /* must be filled in by hif_bus_open */
55 bus_ops->hif_bus_close = NULL;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070056 /* dummy implementations */
Nirav Shahb70bd732016-05-25 14:31:51 +053057 bus_ops->hif_display_stats =
58 &hif_dummy_display_stats;
59 bus_ops->hif_clear_stats =
60 &hif_dummy_clear_stats;
Houston Hoffman7fdff0c2016-08-29 12:31:58 -070061 bus_ops->hif_set_bundle_mode = &hif_dummy_set_bundle_mode;
62 bus_ops->hif_bus_reset_resume = &hif_dummy_bus_reset_resume;
63 bus_ops->hif_bus_suspend_noirq = &hif_dummy_bus_suspend_noirq;
64 bus_ops->hif_bus_resume_noirq = &hif_dummy_bus_resume_noirq;
Houston Hoffmancbcd8392017-02-08 17:43:13 -080065 bus_ops->hif_bus_early_suspend = &hif_dummy_bus_suspend;
66 bus_ops->hif_bus_late_resume = &hif_dummy_bus_resume;
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +053067 bus_ops->hif_grp_irq_disable = &hif_dummy_grp_irq_disable;
68 bus_ops->hif_grp_irq_enable = &hif_dummy_grp_irq_enable;
Dustin Brown07d24be2017-04-03 10:20:49 -070069 bus_ops->hif_map_ce_to_irq = &hif_dummy_map_ce_to_irq;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070070}
71
72#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
73
74/**
75 * hif_verify_basic_ops() - ensure required bus apis are defined
76 *
77 * all bus operations must be defined to avoid crashes
78 * itterate over the structure and ensure all function pointers
79 * are non null.
80 *
81 * Return: QDF_STATUS_SUCCESS if all the operations are defined
82 */
83static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
84{
85 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
86 void **ops_array = (void *)bus_ops;
87 QDF_STATUS status = QDF_STATUS_SUCCESS;
88 int i;
89
90 for (i = 0; i < NUM_OPS; i++) {
91 if (!ops_array[i]) {
92 HIF_ERROR("%s: function %d is null", __func__, i);
93 status = QDF_STATUS_E_NOSUPPORT;
94 }
95 }
96 return status;
97}
98
99/**
Houston Hoffman162164c2016-03-14 21:12:10 -0700100 * hif_bus_get_context_size - API to return size of the bus specific structure
101 *
102 * Return: sizeof of hif_pci_softc
103 */
104int hif_bus_get_context_size(enum qdf_bus_type bus_type)
105{
106 switch (bus_type) {
107 case QDF_BUS_TYPE_PCI:
108 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -0700109 case QDF_BUS_TYPE_AHB:
110 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700111 case QDF_BUS_TYPE_SNOC:
112 return hif_snoc_get_context_size();
Nirav Shah3573f952016-05-12 18:37:03 +0530113 case QDF_BUS_TYPE_SDIO:
114 return hif_sdio_get_context_size();
Mohit Khanna1957ba92016-05-11 11:17:01 -0700115 case QDF_BUS_TYPE_USB:
116 return hif_usb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700117 default:
118 return 0;
119 }
120}
121
122/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700123 * hif_bus_open() - initialize the bus_ops and call the bus specific open
124 * hif_sc: hif_context
125 * bus_type: type of bus being enumerated
126 *
127 * Return: QDF_STATUS_SUCCESS or error
128 */
129QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
130 enum qdf_bus_type bus_type)
131{
132 QDF_STATUS status = QDF_STATUS_E_INVAL;
133
134 hif_intialize_default_ops(hif_sc);
135
136 switch (bus_type) {
137 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700138 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700139 break;
140 case QDF_BUS_TYPE_SNOC:
141 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
142 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700143 case QDF_BUS_TYPE_AHB:
144 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
145 break;
Nirav Shah3573f952016-05-12 18:37:03 +0530146 case QDF_BUS_TYPE_SDIO:
147 status = hif_initialize_sdio_ops(hif_sc);
Yu Wang1e487a52017-02-07 20:10:42 +0800148 break;
Mohit Khanna1957ba92016-05-11 11:17:01 -0700149 case QDF_BUS_TYPE_USB:
150 status = hif_initialize_usb_ops(&hif_sc->bus_ops);
Nirav Shah3573f952016-05-12 18:37:03 +0530151 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700152 default:
153 status = QDF_STATUS_E_NOSUPPORT;
154 break;
155 }
156
157 if (status != QDF_STATUS_SUCCESS) {
158 HIF_ERROR("%s: %d not supported", __func__, bus_type);
159 return status;
160 }
161
162 status = hif_verify_basic_ops(hif_sc);
163 if (status != QDF_STATUS_SUCCESS)
164 return status;
165
166 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
167}
168
169/**
170 * hif_bus_close() - close the bus
171 * @hif_sc: hif_context
172 */
173void hif_bus_close(struct hif_softc *hif_sc)
174{
175 hif_sc->bus_ops.hif_bus_close(hif_sc);
176}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700177
178/**
179 * hif_bus_prevent_linkdown() - prevent linkdown
180 * @hif_ctx: hif context
181 * @flag: true = keep bus alive false = let bus go to sleep
182 *
183 * Keeps the bus awake durring suspend.
184 */
185void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
186{
187 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
188}
189
190
191void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
192{
193 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
194 hif_sc->bus_ops.hif_reset_soc(hif_sc);
195}
196
Houston Hoffmancbcd8392017-02-08 17:43:13 -0800197int hif_bus_early_suspend(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_early_suspend(hif_sc);
201}
202
203int hif_bus_late_resume(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_late_resume(hif_sc);
207}
208
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700209int hif_bus_suspend(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_suspend(hif_sc);
213}
214
215int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
216{
217 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
218 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
219}
220
Houston Hoffman7fdff0c2016-08-29 12:31:58 -0700221int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx)
222{
223 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
224 return hif_sc->bus_ops.hif_bus_suspend_noirq(hif_sc);
225}
226
227int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx)
228{
229 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
230 return hif_sc->bus_ops.hif_bus_resume_noirq(hif_sc);
231}
232
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700233int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
234 bool sleep_ok, bool wait_for_it)
235{
236 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
237 sleep_ok, wait_for_it);
238}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700239
240void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
241{
242 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
243 hif_sc->bus_ops.hif_disable_isr(hif_sc);
244}
245
246void hif_nointrs(struct hif_softc *hif_sc)
247{
248 hif_sc->bus_ops.hif_nointrs(hif_sc);
249}
250
251QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
252 void *bdev, const hif_bus_id *bid,
253 enum hif_enable_type type)
254{
255 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
256}
257
258void hif_disable_bus(struct hif_softc *hif_sc)
259{
260 hif_sc->bus_ops.hif_disable_bus(hif_sc);
261}
262
263int hif_bus_configure(struct hif_softc *hif_sc)
264{
265 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
266}
267
Nirav Shah3573f952016-05-12 18:37:03 +0530268QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
269 int opcode, void *config, uint32_t config_len)
270{
271 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
272 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
273 config_len);
274}
275
276void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
277{
278 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
279 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
280}
281
282void hif_claim_device(struct hif_opaque_softc *hif_ctx)
283{
284 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
285 hif_sc->bus_ops.hif_claim_device(hif_sc);
286}
287
288void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
289{
290 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
291 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
292}
293
294void hif_stop(struct hif_opaque_softc *hif_ctx)
295{
296 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
297 hif_sc->bus_ops.hif_stop(hif_sc);
298}
299
Nirav Shah3573f952016-05-12 18:37:03 +0530300void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
301{
302 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
303}
304
Houston Hoffman8f239f62016-03-14 21:12:05 -0700305void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
306{
307 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
308}
309
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530310void hif_grp_irq_enable(struct hif_softc *hif_sc, uint32_t grp_id)
311{
312 hif_sc->bus_ops.hif_grp_irq_enable(hif_sc, grp_id);
313}
314
Houston Hoffman8f239f62016-03-14 21:12:05 -0700315void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
316{
317 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
318}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700319
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530320void hif_grp_irq_disable(struct hif_softc *hif_sc, uint32_t grp_id)
321{
322 hif_sc->bus_ops.hif_grp_irq_disable(hif_sc, grp_id);
323}
324
Houston Hoffman3c017e72016-03-14 21:12:11 -0700325int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
326{
327 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
328 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
329}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700330
Nirav Shah3573f952016-05-12 18:37:03 +0530331void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
332 void *ramdump_base,
333 uint32_t address, uint32_t size)
334{
335 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
336 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
337 address, size);
338}
339
340void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
341 qdf_dma_addr_t *ce_sr_base_paddr,
342 uint32_t *ce_sr_ring_size,
343 qdf_dma_addr_t *ce_reg_paddr)
344{
345 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
346 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
347 ce_sr_ring_size, ce_reg_paddr);
348}
349
350void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
351{
352 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
353 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
354}
355
Nirav Shahb70bd732016-05-25 14:31:51 +0530356void hif_display_bus_stats(struct hif_opaque_softc *scn)
357{
358 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
359
360 hif_sc->bus_ops.hif_display_stats(hif_sc);
361}
362
363void hif_clear_bus_stats(struct hif_opaque_softc *scn)
364{
365 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
366
367 hif_sc->bus_ops.hif_clear_stats(hif_sc);
368}
369
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700370/**
371 * hif_enable_power_management() - enable power management after driver load
372 * @hif_hdl: opaque pointer to the hif context
373 * is_packet_log_enabled: true if packet log is enabled
374 *
375 * Driver load and firmware download are done in a high performance mode.
376 * Enable power management after the driver is loaded.
377 * packet log can require fewer power management features to be enabled.
378 */
379void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
380 bool is_packet_log_enabled)
381{
382 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
383 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
384 is_packet_log_enabled);
385}
386
387/**
388 * hif_disable_power_management() - reset the bus power management
389 * @hif_hdl: opaque pointer to the hif context
390 *
391 * return the power management of the bus to its default state.
392 * This isn't necessarily a complete reversal of its counterpart.
393 * This should be called when unloading the driver.
394 */
395void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
396{
397 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
398 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
399}
400
Mohit Khanna1957ba92016-05-11 11:17:01 -0700401/**
402 * hif_set_bundle_mode() - enable bundling and set default rx bundle cnt
403 * @scn: pointer to hif_opaque_softc structure
404 * @enabled: flag to enable/disable bundling
405 * @rx_bundle_cnt: bundle count to be used for RX
406 *
407 * Return: none
408 */
409void hif_set_bundle_mode(struct hif_opaque_softc *scn, bool enabled,
410 int rx_bundle_cnt)
411{
412 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
413 hif_sc->bus_ops.hif_set_bundle_mode(hif_sc, enabled, rx_bundle_cnt);
414}
415
416/**
417 * hif_bus_reset_resume() - resume the bus after reset
418 * @scn: struct hif_opaque_softc
419 *
420 * This function is called to tell the driver that USB device has been resumed
421 * and it has also been reset. The driver should redo any necessary
422 * initialization. This function resets WLAN SOC.
423 *
424 * Return: int 0 for success, non zero for failure
425 */
426int hif_bus_reset_resume(struct hif_opaque_softc *scn)
427
428{
429 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
430 return hif_sc->bus_ops.hif_bus_reset_resume(hif_sc);
431}
Dustin Brown6834d322017-03-20 15:02:48 -0700432
433int hif_apps_irqs_disable(struct hif_opaque_softc *hif_ctx)
434{
435 struct hif_softc *scn;
436 int i;
437
438 scn = HIF_GET_SOFTC(hif_ctx);
439 if (!scn) {
440 QDF_BUG(0);
441 return -EINVAL;
442 }
443
444 for (i = 0; i < scn->ce_count; ++i)
445 disable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, i));
446
447 return 0;
448}
449
450int hif_apps_irqs_enable(struct hif_opaque_softc *hif_ctx)
451{
452 struct hif_softc *scn;
453 int i;
454
455 scn = HIF_GET_SOFTC(hif_ctx);
456 if (!scn) {
457 QDF_BUG(0);
458 return -EINVAL;
459 }
460
461 for (i = 0; i < scn->ce_count; ++i)
462 enable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, i));
463
464 return 0;
465}
466
467int hif_apps_wake_irq_disable(struct hif_opaque_softc *hif_ctx)
468{
469 int errno;
470 struct hif_softc *scn;
471 uint8_t wake_ce_id;
472
473 scn = HIF_GET_SOFTC(hif_ctx);
474 if (!scn) {
475 QDF_BUG(0);
476 return -EINVAL;
477 }
478
479 errno = hif_get_wake_ce_id(scn, &wake_ce_id);
480 if (errno) {
481 HIF_ERROR("%s: failed to get wake CE Id: %d", __func__, errno);
482 return errno;
483 }
484
485 disable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, wake_ce_id));
486
487 return 0;
488}
489
490int hif_apps_wake_irq_enable(struct hif_opaque_softc *hif_ctx)
491{
492 int errno;
493 struct hif_softc *scn;
494 uint8_t wake_ce_id;
495
496 scn = HIF_GET_SOFTC(hif_ctx);
497 if (!scn) {
498 QDF_BUG(0);
499 return -EINVAL;
500 }
501
502 errno = hif_get_wake_ce_id(scn, &wake_ce_id);
503 if (errno) {
504 HIF_ERROR("%s: failed to get wake CE Id: %d", __func__, errno);
505 return errno;
506 }
507
508 enable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, wake_ce_id));
509
510 return 0;
511}