blob: cc667b5beddf4be1f55e165e1003d4bc286d00bb [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;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070069}
70
71#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
72
73/**
74 * hif_verify_basic_ops() - ensure required bus apis are defined
75 *
76 * all bus operations must be defined to avoid crashes
77 * itterate over the structure and ensure all function pointers
78 * are non null.
79 *
80 * Return: QDF_STATUS_SUCCESS if all the operations are defined
81 */
82static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
83{
84 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
85 void **ops_array = (void *)bus_ops;
86 QDF_STATUS status = QDF_STATUS_SUCCESS;
87 int i;
88
89 for (i = 0; i < NUM_OPS; i++) {
90 if (!ops_array[i]) {
91 HIF_ERROR("%s: function %d is null", __func__, i);
92 status = QDF_STATUS_E_NOSUPPORT;
93 }
94 }
95 return status;
96}
97
98/**
Houston Hoffman162164c2016-03-14 21:12:10 -070099 * hif_bus_get_context_size - API to return size of the bus specific structure
100 *
101 * Return: sizeof of hif_pci_softc
102 */
103int hif_bus_get_context_size(enum qdf_bus_type bus_type)
104{
105 switch (bus_type) {
106 case QDF_BUS_TYPE_PCI:
107 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -0700108 case QDF_BUS_TYPE_AHB:
109 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700110 case QDF_BUS_TYPE_SNOC:
111 return hif_snoc_get_context_size();
Nirav Shah3573f952016-05-12 18:37:03 +0530112 case QDF_BUS_TYPE_SDIO:
113 return hif_sdio_get_context_size();
Mohit Khanna1957ba92016-05-11 11:17:01 -0700114 case QDF_BUS_TYPE_USB:
115 return hif_usb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700116 default:
117 return 0;
118 }
119}
120
121/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700122 * hif_bus_open() - initialize the bus_ops and call the bus specific open
123 * hif_sc: hif_context
124 * bus_type: type of bus being enumerated
125 *
126 * Return: QDF_STATUS_SUCCESS or error
127 */
128QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
129 enum qdf_bus_type bus_type)
130{
131 QDF_STATUS status = QDF_STATUS_E_INVAL;
132
133 hif_intialize_default_ops(hif_sc);
134
135 switch (bus_type) {
136 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700137 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700138 break;
139 case QDF_BUS_TYPE_SNOC:
140 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
141 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700142 case QDF_BUS_TYPE_AHB:
143 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
144 break;
Nirav Shah3573f952016-05-12 18:37:03 +0530145 case QDF_BUS_TYPE_SDIO:
146 status = hif_initialize_sdio_ops(hif_sc);
Yu Wang1e487a52017-02-07 20:10:42 +0800147 break;
Mohit Khanna1957ba92016-05-11 11:17:01 -0700148 case QDF_BUS_TYPE_USB:
149 status = hif_initialize_usb_ops(&hif_sc->bus_ops);
Nirav Shah3573f952016-05-12 18:37:03 +0530150 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700151 default:
152 status = QDF_STATUS_E_NOSUPPORT;
153 break;
154 }
155
156 if (status != QDF_STATUS_SUCCESS) {
157 HIF_ERROR("%s: %d not supported", __func__, bus_type);
158 return status;
159 }
160
161 status = hif_verify_basic_ops(hif_sc);
162 if (status != QDF_STATUS_SUCCESS)
163 return status;
164
165 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
166}
167
168/**
169 * hif_bus_close() - close the bus
170 * @hif_sc: hif_context
171 */
172void hif_bus_close(struct hif_softc *hif_sc)
173{
174 hif_sc->bus_ops.hif_bus_close(hif_sc);
175}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700176
177/**
178 * hif_bus_prevent_linkdown() - prevent linkdown
179 * @hif_ctx: hif context
180 * @flag: true = keep bus alive false = let bus go to sleep
181 *
182 * Keeps the bus awake durring suspend.
183 */
184void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
185{
186 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
187}
188
189
190void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
191{
192 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
193 hif_sc->bus_ops.hif_reset_soc(hif_sc);
194}
195
Houston Hoffmancbcd8392017-02-08 17:43:13 -0800196int hif_bus_early_suspend(struct hif_opaque_softc *hif_ctx)
197{
198 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
199 return hif_sc->bus_ops.hif_bus_early_suspend(hif_sc);
200}
201
202int hif_bus_late_resume(struct hif_opaque_softc *hif_ctx)
203{
204 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
205 return hif_sc->bus_ops.hif_bus_late_resume(hif_sc);
206}
207
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700208int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
209{
210 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
211 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
212}
213
214int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
215{
216 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
217 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
218}
219
Houston Hoffman7fdff0c2016-08-29 12:31:58 -0700220int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx)
221{
222 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
223 return hif_sc->bus_ops.hif_bus_suspend_noirq(hif_sc);
224}
225
226int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx)
227{
228 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
229 return hif_sc->bus_ops.hif_bus_resume_noirq(hif_sc);
230}
231
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700232int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
233 bool sleep_ok, bool wait_for_it)
234{
235 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
236 sleep_ok, wait_for_it);
237}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700238
239void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
240{
241 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
242 hif_sc->bus_ops.hif_disable_isr(hif_sc);
243}
244
245void hif_nointrs(struct hif_softc *hif_sc)
246{
247 hif_sc->bus_ops.hif_nointrs(hif_sc);
248}
249
250QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
251 void *bdev, const hif_bus_id *bid,
252 enum hif_enable_type type)
253{
254 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
255}
256
257void hif_disable_bus(struct hif_softc *hif_sc)
258{
259 hif_sc->bus_ops.hif_disable_bus(hif_sc);
260}
261
262int hif_bus_configure(struct hif_softc *hif_sc)
263{
264 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
265}
266
Nirav Shah3573f952016-05-12 18:37:03 +0530267QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
268 int opcode, void *config, uint32_t config_len)
269{
270 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
271 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
272 config_len);
273}
274
275void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
276{
277 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
278 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
279}
280
281void hif_claim_device(struct hif_opaque_softc *hif_ctx)
282{
283 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
284 hif_sc->bus_ops.hif_claim_device(hif_sc);
285}
286
287void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
288{
289 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
290 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
291}
292
293void hif_stop(struct hif_opaque_softc *hif_ctx)
294{
295 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
296 hif_sc->bus_ops.hif_stop(hif_sc);
297}
298
Nirav Shah3573f952016-05-12 18:37:03 +0530299void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
300{
301 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
302}
303
Houston Hoffman8f239f62016-03-14 21:12:05 -0700304void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
305{
306 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
307}
308
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530309void hif_grp_irq_enable(struct hif_softc *hif_sc, uint32_t grp_id)
310{
311 hif_sc->bus_ops.hif_grp_irq_enable(hif_sc, grp_id);
312}
313
Houston Hoffman8f239f62016-03-14 21:12:05 -0700314void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
315{
316 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
317}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700318
Venkateswara Swamy Bandaru31108f32016-08-08 18:04:29 +0530319void hif_grp_irq_disable(struct hif_softc *hif_sc, uint32_t grp_id)
320{
321 hif_sc->bus_ops.hif_grp_irq_disable(hif_sc, grp_id);
322}
323
Houston Hoffman3c017e72016-03-14 21:12:11 -0700324int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
325{
326 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
327 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
328}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700329
Nirav Shah3573f952016-05-12 18:37:03 +0530330void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
331 void *ramdump_base,
332 uint32_t address, uint32_t size)
333{
334 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
335 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
336 address, size);
337}
338
339void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
340 qdf_dma_addr_t *ce_sr_base_paddr,
341 uint32_t *ce_sr_ring_size,
342 qdf_dma_addr_t *ce_reg_paddr)
343{
344 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
345 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
346 ce_sr_ring_size, ce_reg_paddr);
347}
348
349void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
350{
351 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
352 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
353}
354
Nirav Shahb70bd732016-05-25 14:31:51 +0530355void hif_display_bus_stats(struct hif_opaque_softc *scn)
356{
357 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
358
359 hif_sc->bus_ops.hif_display_stats(hif_sc);
360}
361
362void hif_clear_bus_stats(struct hif_opaque_softc *scn)
363{
364 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
365
366 hif_sc->bus_ops.hif_clear_stats(hif_sc);
367}
368
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700369/**
370 * hif_enable_power_management() - enable power management after driver load
371 * @hif_hdl: opaque pointer to the hif context
372 * is_packet_log_enabled: true if packet log is enabled
373 *
374 * Driver load and firmware download are done in a high performance mode.
375 * Enable power management after the driver is loaded.
376 * packet log can require fewer power management features to be enabled.
377 */
378void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
379 bool is_packet_log_enabled)
380{
381 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
382 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
383 is_packet_log_enabled);
384}
385
386/**
387 * hif_disable_power_management() - reset the bus power management
388 * @hif_hdl: opaque pointer to the hif context
389 *
390 * return the power management of the bus to its default state.
391 * This isn't necessarily a complete reversal of its counterpart.
392 * This should be called when unloading the driver.
393 */
394void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
395{
396 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
397 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
398}
399
Mohit Khanna1957ba92016-05-11 11:17:01 -0700400/**
401 * hif_set_bundle_mode() - enable bundling and set default rx bundle cnt
402 * @scn: pointer to hif_opaque_softc structure
403 * @enabled: flag to enable/disable bundling
404 * @rx_bundle_cnt: bundle count to be used for RX
405 *
406 * Return: none
407 */
408void hif_set_bundle_mode(struct hif_opaque_softc *scn, bool enabled,
409 int rx_bundle_cnt)
410{
411 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
412 hif_sc->bus_ops.hif_set_bundle_mode(hif_sc, enabled, rx_bundle_cnt);
413}
414
415/**
416 * hif_bus_reset_resume() - resume the bus after reset
417 * @scn: struct hif_opaque_softc
418 *
419 * This function is called to tell the driver that USB device has been resumed
420 * and it has also been reset. The driver should redo any necessary
421 * initialization. This function resets WLAN SOC.
422 *
423 * Return: int 0 for success, non zero for failure
424 */
425int hif_bus_reset_resume(struct hif_opaque_softc *scn)
426
427{
428 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
429 return hif_sc->bus_ops.hif_bus_reset_resume(hif_sc);
430}
Dustin Brown6834d322017-03-20 15:02:48 -0700431
432int hif_apps_irqs_disable(struct hif_opaque_softc *hif_ctx)
433{
434 struct hif_softc *scn;
435 int i;
436
437 scn = HIF_GET_SOFTC(hif_ctx);
438 if (!scn) {
439 QDF_BUG(0);
440 return -EINVAL;
441 }
442
443 for (i = 0; i < scn->ce_count; ++i)
444 disable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, i));
445
446 return 0;
447}
448
449int hif_apps_irqs_enable(struct hif_opaque_softc *hif_ctx)
450{
451 struct hif_softc *scn;
452 int i;
453
454 scn = HIF_GET_SOFTC(hif_ctx);
455 if (!scn) {
456 QDF_BUG(0);
457 return -EINVAL;
458 }
459
460 for (i = 0; i < scn->ce_count; ++i)
461 enable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, i));
462
463 return 0;
464}
465
466int hif_apps_wake_irq_disable(struct hif_opaque_softc *hif_ctx)
467{
468 int errno;
469 struct hif_softc *scn;
470 uint8_t wake_ce_id;
471
472 scn = HIF_GET_SOFTC(hif_ctx);
473 if (!scn) {
474 QDF_BUG(0);
475 return -EINVAL;
476 }
477
478 errno = hif_get_wake_ce_id(scn, &wake_ce_id);
479 if (errno) {
480 HIF_ERROR("%s: failed to get wake CE Id: %d", __func__, errno);
481 return errno;
482 }
483
484 disable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, wake_ce_id));
485
486 return 0;
487}
488
489int hif_apps_wake_irq_enable(struct hif_opaque_softc *hif_ctx)
490{
491 int errno;
492 struct hif_softc *scn;
493 uint8_t wake_ce_id;
494
495 scn = HIF_GET_SOFTC(hif_ctx);
496 if (!scn) {
497 QDF_BUG(0);
498 return -EINVAL;
499 }
500
501 errno = hif_get_wake_ce_id(scn, &wake_ce_id);
502 if (errno) {
503 HIF_ERROR("%s: failed to get wake CE Id: %d", __func__, errno);
504 return errno;
505 }
506
507 enable_irq(scn->bus_ops.hif_map_ce_to_irq(scn, wake_ce_id));
508
509 return 0;
510}