blob: 5643b6f05715fb46876e50f75a4e4e3a63ae9379 [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"
Mohit Khanna1957ba92016-05-11 11:17:01 -070034#include "dummy.h"
Nirav Shah3573f952016-05-12 18:37:03 +053035#if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB)
Houston Hoffman162164c2016-03-14 21:12:10 -070036#include "ce_main.h"
Nirav Shah3573f952016-05-12 18:37:03 +053037#endif
Komal Seelam6ee55902016-04-11 17:11:07 +053038#include "htc_services.h"
39#include "a_types.h"
Nirav Shahb70bd732016-05-25 14:31:51 +053040#include "dummy.h"
41
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070042/**
43 * hif_intialize_default_ops() - intializes default operations values
44 *
45 * bus specific features should assign their dummy implementations here.
46 */
47static void hif_intialize_default_ops(struct hif_softc *hif_sc)
48{
49 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
50
51 /* must be filled in by hif_bus_open */
52 bus_ops->hif_bus_close = NULL;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070053 /* dummy implementations */
Nirav Shahb70bd732016-05-25 14:31:51 +053054 bus_ops->hif_display_stats =
55 &hif_dummy_display_stats;
56 bus_ops->hif_clear_stats =
57 &hif_dummy_clear_stats;
Houston Hoffman7fdff0c2016-08-29 12:31:58 -070058 bus_ops->hif_set_bundle_mode = &hif_dummy_set_bundle_mode;
59 bus_ops->hif_bus_reset_resume = &hif_dummy_bus_reset_resume;
60 bus_ops->hif_bus_suspend_noirq = &hif_dummy_bus_suspend_noirq;
61 bus_ops->hif_bus_resume_noirq = &hif_dummy_bus_resume_noirq;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -070062}
63
64#define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *))
65
66/**
67 * hif_verify_basic_ops() - ensure required bus apis are defined
68 *
69 * all bus operations must be defined to avoid crashes
70 * itterate over the structure and ensure all function pointers
71 * are non null.
72 *
73 * Return: QDF_STATUS_SUCCESS if all the operations are defined
74 */
75static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc)
76{
77 struct hif_bus_ops *bus_ops = &hif_sc->bus_ops;
78 void **ops_array = (void *)bus_ops;
79 QDF_STATUS status = QDF_STATUS_SUCCESS;
80 int i;
81
82 for (i = 0; i < NUM_OPS; i++) {
83 if (!ops_array[i]) {
84 HIF_ERROR("%s: function %d is null", __func__, i);
85 status = QDF_STATUS_E_NOSUPPORT;
86 }
87 }
88 return status;
89}
90
91/**
Houston Hoffman162164c2016-03-14 21:12:10 -070092 * hif_bus_get_context_size - API to return size of the bus specific structure
93 *
94 * Return: sizeof of hif_pci_softc
95 */
96int hif_bus_get_context_size(enum qdf_bus_type bus_type)
97{
98 switch (bus_type) {
99 case QDF_BUS_TYPE_PCI:
100 return hif_pci_get_context_size();
Houston Hoffman3db96a42016-05-05 19:54:39 -0700101 case QDF_BUS_TYPE_AHB:
102 return hif_ahb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700103 case QDF_BUS_TYPE_SNOC:
104 return hif_snoc_get_context_size();
Nirav Shah3573f952016-05-12 18:37:03 +0530105 case QDF_BUS_TYPE_SDIO:
106 return hif_sdio_get_context_size();
Mohit Khanna1957ba92016-05-11 11:17:01 -0700107 case QDF_BUS_TYPE_USB:
108 return hif_usb_get_context_size();
Houston Hoffman162164c2016-03-14 21:12:10 -0700109 default:
110 return 0;
111 }
112}
113
114/**
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700115 * hif_bus_open() - initialize the bus_ops and call the bus specific open
116 * hif_sc: hif_context
117 * bus_type: type of bus being enumerated
118 *
119 * Return: QDF_STATUS_SUCCESS or error
120 */
121QDF_STATUS hif_bus_open(struct hif_softc *hif_sc,
122 enum qdf_bus_type bus_type)
123{
124 QDF_STATUS status = QDF_STATUS_E_INVAL;
125
126 hif_intialize_default_ops(hif_sc);
127
128 switch (bus_type) {
129 case QDF_BUS_TYPE_PCI:
Houston Hoffman54ef87d2016-03-14 21:11:58 -0700130 status = hif_initialize_pci_ops(hif_sc);
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700131 break;
132 case QDF_BUS_TYPE_SNOC:
133 status = hif_initialize_snoc_ops(&hif_sc->bus_ops);
134 break;
Houston Hoffman3db96a42016-05-05 19:54:39 -0700135 case QDF_BUS_TYPE_AHB:
136 status = hif_initialize_ahb_ops(&hif_sc->bus_ops);
137 break;
Nirav Shah3573f952016-05-12 18:37:03 +0530138 case QDF_BUS_TYPE_SDIO:
139 status = hif_initialize_sdio_ops(hif_sc);
Mohit Khanna1957ba92016-05-11 11:17:01 -0700140 case QDF_BUS_TYPE_USB:
141 status = hif_initialize_usb_ops(&hif_sc->bus_ops);
Nirav Shah3573f952016-05-12 18:37:03 +0530142 break;
Houston Hoffman32bc8eb2016-03-14 21:11:34 -0700143 default:
144 status = QDF_STATUS_E_NOSUPPORT;
145 break;
146 }
147
148 if (status != QDF_STATUS_SUCCESS) {
149 HIF_ERROR("%s: %d not supported", __func__, bus_type);
150 return status;
151 }
152
153 status = hif_verify_basic_ops(hif_sc);
154 if (status != QDF_STATUS_SUCCESS)
155 return status;
156
157 return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type);
158}
159
160/**
161 * hif_bus_close() - close the bus
162 * @hif_sc: hif_context
163 */
164void hif_bus_close(struct hif_softc *hif_sc)
165{
166 hif_sc->bus_ops.hif_bus_close(hif_sc);
167}
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700168
169/**
170 * hif_bus_prevent_linkdown() - prevent linkdown
171 * @hif_ctx: hif context
172 * @flag: true = keep bus alive false = let bus go to sleep
173 *
174 * Keeps the bus awake durring suspend.
175 */
176void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag)
177{
178 hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag);
179}
180
181
182void hif_reset_soc(struct hif_opaque_softc *hif_ctx)
183{
184 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
185 hif_sc->bus_ops.hif_reset_soc(hif_sc);
186}
187
188int hif_bus_suspend(struct hif_opaque_softc *hif_ctx)
189{
190 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
191 return hif_sc->bus_ops.hif_bus_suspend(hif_sc);
192}
193
194int hif_bus_resume(struct hif_opaque_softc *hif_ctx)
195{
196 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
197 return hif_sc->bus_ops.hif_bus_resume(hif_sc);
198}
199
Houston Hoffman7fdff0c2016-08-29 12:31:58 -0700200int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx)
201{
202 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
203 return hif_sc->bus_ops.hif_bus_suspend_noirq(hif_sc);
204}
205
206int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx)
207{
208 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
209 return hif_sc->bus_ops.hif_bus_resume_noirq(hif_sc);
210}
211
Houston Hoffman4ca03b62016-03-14 21:11:51 -0700212int hif_target_sleep_state_adjust(struct hif_softc *hif_sc,
213 bool sleep_ok, bool wait_for_it)
214{
215 return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc,
216 sleep_ok, wait_for_it);
217}
Houston Hoffman8f239f62016-03-14 21:12:05 -0700218
219void hif_disable_isr(struct hif_opaque_softc *hif_hdl)
220{
221 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
222 hif_sc->bus_ops.hif_disable_isr(hif_sc);
223}
224
225void hif_nointrs(struct hif_softc *hif_sc)
226{
227 hif_sc->bus_ops.hif_nointrs(hif_sc);
228}
229
230QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev,
231 void *bdev, const hif_bus_id *bid,
232 enum hif_enable_type type)
233{
234 return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type);
235}
236
237void hif_disable_bus(struct hif_softc *hif_sc)
238{
239 hif_sc->bus_ops.hif_disable_bus(hif_sc);
240}
241
242int hif_bus_configure(struct hif_softc *hif_sc)
243{
244 return hif_sc->bus_ops.hif_bus_configure(hif_sc);
245}
246
Nirav Shah3573f952016-05-12 18:37:03 +0530247QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
248 int opcode, void *config, uint32_t config_len)
249{
250 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
251 return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config,
252 config_len);
253}
254
255void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx)
256{
257 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
258 hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc);
259}
260
261void hif_claim_device(struct hif_opaque_softc *hif_ctx)
262{
263 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
264 hif_sc->bus_ops.hif_claim_device(hif_sc);
265}
266
267void hif_shutdown_device(struct hif_opaque_softc *hif_ctx)
268{
269 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
270 hif_sc->bus_ops.hif_shutdown_device(hif_sc);
271}
272
273void hif_stop(struct hif_opaque_softc *hif_ctx)
274{
275 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx);
276 hif_sc->bus_ops.hif_stop(hif_sc);
277}
278
Nirav Shah3573f952016-05-12 18:37:03 +0530279void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc)
280{
281 return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc);
282}
283
Houston Hoffman8f239f62016-03-14 21:12:05 -0700284void hif_irq_enable(struct hif_softc *hif_sc, int irq_id)
285{
286 hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id);
287}
288
289void hif_irq_disable(struct hif_softc *hif_sc, int irq_id)
290{
291 hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id);
292}
Houston Hoffman3c017e72016-03-14 21:12:11 -0700293
294int hif_dump_registers(struct hif_opaque_softc *hif_hdl)
295{
296 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
297 return hif_sc->bus_ops.hif_dump_registers(hif_sc);
298}
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700299
Nirav Shah3573f952016-05-12 18:37:03 +0530300void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl,
301 void *ramdump_base,
302 uint32_t address, uint32_t size)
303{
304 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
305 hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base,
306 address, size);
307}
308
309void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl,
310 qdf_dma_addr_t *ce_sr_base_paddr,
311 uint32_t *ce_sr_ring_size,
312 qdf_dma_addr_t *ce_reg_paddr)
313{
314 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
315 hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr,
316 ce_sr_ring_size, ce_reg_paddr);
317}
318
319void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl)
320{
321 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
322 hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc);
323}
324
Nirav Shahb70bd732016-05-25 14:31:51 +0530325void hif_display_bus_stats(struct hif_opaque_softc *scn)
326{
327 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
328
329 hif_sc->bus_ops.hif_display_stats(hif_sc);
330}
331
332void hif_clear_bus_stats(struct hif_opaque_softc *scn)
333{
334 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
335
336 hif_sc->bus_ops.hif_clear_stats(hif_sc);
337}
338
Houston Hoffmanb4149dd2016-03-23 15:55:41 -0700339/**
340 * hif_enable_power_management() - enable power management after driver load
341 * @hif_hdl: opaque pointer to the hif context
342 * is_packet_log_enabled: true if packet log is enabled
343 *
344 * Driver load and firmware download are done in a high performance mode.
345 * Enable power management after the driver is loaded.
346 * packet log can require fewer power management features to be enabled.
347 */
348void hif_enable_power_management(struct hif_opaque_softc *hif_hdl,
349 bool is_packet_log_enabled)
350{
351 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
352 hif_sc->bus_ops.hif_enable_power_management(hif_sc,
353 is_packet_log_enabled);
354}
355
356/**
357 * hif_disable_power_management() - reset the bus power management
358 * @hif_hdl: opaque pointer to the hif context
359 *
360 * return the power management of the bus to its default state.
361 * This isn't necessarily a complete reversal of its counterpart.
362 * This should be called when unloading the driver.
363 */
364void hif_disable_power_management(struct hif_opaque_softc *hif_hdl)
365{
366 struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl);
367 hif_sc->bus_ops.hif_disable_power_management(hif_sc);
368}
369
Mohit Khanna1957ba92016-05-11 11:17:01 -0700370/**
371 * hif_set_bundle_mode() - enable bundling and set default rx bundle cnt
372 * @scn: pointer to hif_opaque_softc structure
373 * @enabled: flag to enable/disable bundling
374 * @rx_bundle_cnt: bundle count to be used for RX
375 *
376 * Return: none
377 */
378void hif_set_bundle_mode(struct hif_opaque_softc *scn, bool enabled,
379 int rx_bundle_cnt)
380{
381 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
382 hif_sc->bus_ops.hif_set_bundle_mode(hif_sc, enabled, rx_bundle_cnt);
383}
384
385/**
386 * hif_bus_reset_resume() - resume the bus after reset
387 * @scn: struct hif_opaque_softc
388 *
389 * This function is called to tell the driver that USB device has been resumed
390 * and it has also been reset. The driver should redo any necessary
391 * initialization. This function resets WLAN SOC.
392 *
393 * Return: int 0 for success, non zero for failure
394 */
395int hif_bus_reset_resume(struct hif_opaque_softc *scn)
396
397{
398 struct hif_softc *hif_sc = HIF_GET_SOFTC(scn);
399 return hif_sc->bus_ops.hif_bus_reset_resume(hif_sc);
400}