Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 1 | /* |
| 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" |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 34 | #if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB) |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 35 | #include "ce_main.h" |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 36 | #endif |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 37 | #include "htc_services.h" |
| 38 | #include "a_types.h" |
Nirav Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame^] | 39 | #include "dummy.h" |
| 40 | |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 41 | /** |
| 42 | * hif_intialize_default_ops() - intializes default operations values |
| 43 | * |
| 44 | * bus specific features should assign their dummy implementations here. |
| 45 | */ |
| 46 | static void hif_intialize_default_ops(struct hif_softc *hif_sc) |
| 47 | { |
| 48 | struct hif_bus_ops *bus_ops = &hif_sc->bus_ops; |
| 49 | |
| 50 | /* must be filled in by hif_bus_open */ |
| 51 | bus_ops->hif_bus_close = NULL; |
| 52 | |
| 53 | /* dummy implementations */ |
Nirav Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame^] | 54 | bus_ops->hif_display_stats = |
| 55 | &hif_dummy_display_stats; |
| 56 | bus_ops->hif_clear_stats = |
| 57 | &hif_dummy_clear_stats; |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *)) |
| 61 | |
| 62 | /** |
| 63 | * hif_verify_basic_ops() - ensure required bus apis are defined |
| 64 | * |
| 65 | * all bus operations must be defined to avoid crashes |
| 66 | * itterate over the structure and ensure all function pointers |
| 67 | * are non null. |
| 68 | * |
| 69 | * Return: QDF_STATUS_SUCCESS if all the operations are defined |
| 70 | */ |
| 71 | static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc) |
| 72 | { |
| 73 | struct hif_bus_ops *bus_ops = &hif_sc->bus_ops; |
| 74 | void **ops_array = (void *)bus_ops; |
| 75 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 76 | int i; |
| 77 | |
| 78 | for (i = 0; i < NUM_OPS; i++) { |
| 79 | if (!ops_array[i]) { |
| 80 | HIF_ERROR("%s: function %d is null", __func__, i); |
| 81 | status = QDF_STATUS_E_NOSUPPORT; |
| 82 | } |
| 83 | } |
| 84 | return status; |
| 85 | } |
| 86 | |
| 87 | /** |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 88 | * hif_bus_get_context_size - API to return size of the bus specific structure |
| 89 | * |
| 90 | * Return: sizeof of hif_pci_softc |
| 91 | */ |
| 92 | int hif_bus_get_context_size(enum qdf_bus_type bus_type) |
| 93 | { |
| 94 | switch (bus_type) { |
| 95 | case QDF_BUS_TYPE_PCI: |
| 96 | return hif_pci_get_context_size(); |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 97 | case QDF_BUS_TYPE_AHB: |
| 98 | return hif_ahb_get_context_size(); |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 99 | case QDF_BUS_TYPE_SNOC: |
| 100 | return hif_snoc_get_context_size(); |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 101 | case QDF_BUS_TYPE_SDIO: |
| 102 | return hif_sdio_get_context_size(); |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 103 | default: |
| 104 | return 0; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 109 | * hif_bus_open() - initialize the bus_ops and call the bus specific open |
| 110 | * hif_sc: hif_context |
| 111 | * bus_type: type of bus being enumerated |
| 112 | * |
| 113 | * Return: QDF_STATUS_SUCCESS or error |
| 114 | */ |
| 115 | QDF_STATUS hif_bus_open(struct hif_softc *hif_sc, |
| 116 | enum qdf_bus_type bus_type) |
| 117 | { |
| 118 | QDF_STATUS status = QDF_STATUS_E_INVAL; |
| 119 | |
| 120 | hif_intialize_default_ops(hif_sc); |
| 121 | |
| 122 | switch (bus_type) { |
| 123 | case QDF_BUS_TYPE_PCI: |
Houston Hoffman | 54ef87d | 2016-03-14 21:11:58 -0700 | [diff] [blame] | 124 | status = hif_initialize_pci_ops(hif_sc); |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 125 | break; |
| 126 | case QDF_BUS_TYPE_SNOC: |
| 127 | status = hif_initialize_snoc_ops(&hif_sc->bus_ops); |
| 128 | break; |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 129 | case QDF_BUS_TYPE_AHB: |
| 130 | status = hif_initialize_ahb_ops(&hif_sc->bus_ops); |
| 131 | break; |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 132 | case QDF_BUS_TYPE_SDIO: |
| 133 | status = hif_initialize_sdio_ops(hif_sc); |
| 134 | break; |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 135 | default: |
| 136 | status = QDF_STATUS_E_NOSUPPORT; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | if (status != QDF_STATUS_SUCCESS) { |
| 141 | HIF_ERROR("%s: %d not supported", __func__, bus_type); |
| 142 | return status; |
| 143 | } |
| 144 | |
| 145 | status = hif_verify_basic_ops(hif_sc); |
| 146 | if (status != QDF_STATUS_SUCCESS) |
| 147 | return status; |
| 148 | |
| 149 | return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * hif_bus_close() - close the bus |
| 154 | * @hif_sc: hif_context |
| 155 | */ |
| 156 | void hif_bus_close(struct hif_softc *hif_sc) |
| 157 | { |
| 158 | hif_sc->bus_ops.hif_bus_close(hif_sc); |
| 159 | } |
Houston Hoffman | 4ca03b6 | 2016-03-14 21:11:51 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * hif_bus_prevent_linkdown() - prevent linkdown |
| 163 | * @hif_ctx: hif context |
| 164 | * @flag: true = keep bus alive false = let bus go to sleep |
| 165 | * |
| 166 | * Keeps the bus awake durring suspend. |
| 167 | */ |
| 168 | void hif_bus_prevent_linkdown(struct hif_softc *hif_sc, bool flag) |
| 169 | { |
| 170 | hif_sc->bus_ops.hif_bus_prevent_linkdown(hif_sc, flag); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void hif_reset_soc(struct hif_opaque_softc *hif_ctx) |
| 175 | { |
| 176 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 177 | hif_sc->bus_ops.hif_reset_soc(hif_sc); |
| 178 | } |
| 179 | |
| 180 | int hif_bus_suspend(struct hif_opaque_softc *hif_ctx) |
| 181 | { |
| 182 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 183 | return hif_sc->bus_ops.hif_bus_suspend(hif_sc); |
| 184 | } |
| 185 | |
| 186 | int hif_bus_resume(struct hif_opaque_softc *hif_ctx) |
| 187 | { |
| 188 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 189 | return hif_sc->bus_ops.hif_bus_resume(hif_sc); |
| 190 | } |
| 191 | |
| 192 | int hif_target_sleep_state_adjust(struct hif_softc *hif_sc, |
| 193 | bool sleep_ok, bool wait_for_it) |
| 194 | { |
| 195 | return hif_sc->bus_ops.hif_target_sleep_state_adjust(hif_sc, |
| 196 | sleep_ok, wait_for_it); |
| 197 | } |
Houston Hoffman | 8f239f6 | 2016-03-14 21:12:05 -0700 | [diff] [blame] | 198 | |
| 199 | void hif_disable_isr(struct hif_opaque_softc *hif_hdl) |
| 200 | { |
| 201 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 202 | hif_sc->bus_ops.hif_disable_isr(hif_sc); |
| 203 | } |
| 204 | |
| 205 | void hif_nointrs(struct hif_softc *hif_sc) |
| 206 | { |
| 207 | hif_sc->bus_ops.hif_nointrs(hif_sc); |
| 208 | } |
| 209 | |
| 210 | QDF_STATUS hif_enable_bus(struct hif_softc *hif_sc, struct device *dev, |
| 211 | void *bdev, const hif_bus_id *bid, |
| 212 | enum hif_enable_type type) |
| 213 | { |
| 214 | return hif_sc->bus_ops.hif_enable_bus(hif_sc, dev, bdev, bid, type); |
| 215 | } |
| 216 | |
| 217 | void hif_disable_bus(struct hif_softc *hif_sc) |
| 218 | { |
| 219 | hif_sc->bus_ops.hif_disable_bus(hif_sc); |
| 220 | } |
| 221 | |
| 222 | int hif_bus_configure(struct hif_softc *hif_sc) |
| 223 | { |
| 224 | return hif_sc->bus_ops.hif_bus_configure(hif_sc); |
| 225 | } |
| 226 | |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 227 | QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx, |
| 228 | int opcode, void *config, uint32_t config_len) |
| 229 | { |
| 230 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 231 | return hif_sc->bus_ops.hif_get_config_item(hif_sc, opcode, config, |
| 232 | config_len); |
| 233 | } |
| 234 | |
| 235 | void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx) |
| 236 | { |
| 237 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 238 | hif_sc->bus_ops.hif_set_mailbox_swap(hif_sc); |
| 239 | } |
| 240 | |
| 241 | void hif_claim_device(struct hif_opaque_softc *hif_ctx) |
| 242 | { |
| 243 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 244 | hif_sc->bus_ops.hif_claim_device(hif_sc); |
| 245 | } |
| 246 | |
| 247 | void hif_shutdown_device(struct hif_opaque_softc *hif_ctx) |
| 248 | { |
| 249 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 250 | hif_sc->bus_ops.hif_shutdown_device(hif_sc); |
| 251 | } |
| 252 | |
| 253 | void hif_stop(struct hif_opaque_softc *hif_ctx) |
| 254 | { |
| 255 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 256 | hif_sc->bus_ops.hif_stop(hif_sc); |
| 257 | } |
| 258 | |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 259 | void hif_cancel_deferred_target_sleep(struct hif_softc *hif_sc) |
| 260 | { |
| 261 | return hif_sc->bus_ops.hif_cancel_deferred_target_sleep(hif_sc); |
| 262 | } |
| 263 | |
Houston Hoffman | 8f239f6 | 2016-03-14 21:12:05 -0700 | [diff] [blame] | 264 | void hif_irq_enable(struct hif_softc *hif_sc, int irq_id) |
| 265 | { |
| 266 | hif_sc->bus_ops.hif_irq_enable(hif_sc, irq_id); |
| 267 | } |
| 268 | |
| 269 | void hif_irq_disable(struct hif_softc *hif_sc, int irq_id) |
| 270 | { |
| 271 | hif_sc->bus_ops.hif_irq_disable(hif_sc, irq_id); |
| 272 | } |
Houston Hoffman | 3c017e7 | 2016-03-14 21:12:11 -0700 | [diff] [blame] | 273 | |
| 274 | int hif_dump_registers(struct hif_opaque_softc *hif_hdl) |
| 275 | { |
| 276 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 277 | return hif_sc->bus_ops.hif_dump_registers(hif_sc); |
| 278 | } |
Houston Hoffman | b4149dd | 2016-03-23 15:55:41 -0700 | [diff] [blame] | 279 | |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 280 | void hif_dump_target_memory(struct hif_opaque_softc *hif_hdl, |
| 281 | void *ramdump_base, |
| 282 | uint32_t address, uint32_t size) |
| 283 | { |
| 284 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 285 | hif_sc->bus_ops.hif_dump_target_memory(hif_sc, ramdump_base, |
| 286 | address, size); |
| 287 | } |
| 288 | |
| 289 | void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_hdl, |
| 290 | qdf_dma_addr_t *ce_sr_base_paddr, |
| 291 | uint32_t *ce_sr_ring_size, |
| 292 | qdf_dma_addr_t *ce_reg_paddr) |
| 293 | { |
| 294 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 295 | hif_sc->bus_ops.hif_ipa_get_ce_resource(hif_sc, ce_sr_base_paddr, |
| 296 | ce_sr_ring_size, ce_reg_paddr); |
| 297 | } |
| 298 | |
| 299 | void hif_mask_interrupt_call(struct hif_opaque_softc *hif_hdl) |
| 300 | { |
| 301 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 302 | hif_sc->bus_ops.hif_mask_interrupt_call(hif_sc); |
| 303 | } |
| 304 | |
Nirav Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame^] | 305 | void hif_display_bus_stats(struct hif_opaque_softc *scn) |
| 306 | { |
| 307 | struct hif_softc *hif_sc = HIF_GET_SOFTC(scn); |
| 308 | |
| 309 | hif_sc->bus_ops.hif_display_stats(hif_sc); |
| 310 | } |
| 311 | |
| 312 | void hif_clear_bus_stats(struct hif_opaque_softc *scn) |
| 313 | { |
| 314 | struct hif_softc *hif_sc = HIF_GET_SOFTC(scn); |
| 315 | |
| 316 | hif_sc->bus_ops.hif_clear_stats(hif_sc); |
| 317 | } |
| 318 | |
Houston Hoffman | b4149dd | 2016-03-23 15:55:41 -0700 | [diff] [blame] | 319 | /** |
| 320 | * hif_enable_power_management() - enable power management after driver load |
| 321 | * @hif_hdl: opaque pointer to the hif context |
| 322 | * is_packet_log_enabled: true if packet log is enabled |
| 323 | * |
| 324 | * Driver load and firmware download are done in a high performance mode. |
| 325 | * Enable power management after the driver is loaded. |
| 326 | * packet log can require fewer power management features to be enabled. |
| 327 | */ |
| 328 | void hif_enable_power_management(struct hif_opaque_softc *hif_hdl, |
| 329 | bool is_packet_log_enabled) |
| 330 | { |
| 331 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 332 | hif_sc->bus_ops.hif_enable_power_management(hif_sc, |
| 333 | is_packet_log_enabled); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * hif_disable_power_management() - reset the bus power management |
| 338 | * @hif_hdl: opaque pointer to the hif context |
| 339 | * |
| 340 | * return the power management of the bus to its default state. |
| 341 | * This isn't necessarily a complete reversal of its counterpart. |
| 342 | * This should be called when unloading the driver. |
| 343 | */ |
| 344 | void hif_disable_power_management(struct hif_opaque_softc *hif_hdl) |
| 345 | { |
| 346 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_hdl); |
| 347 | hif_sc->bus_ops.hif_disable_power_management(hif_sc); |
| 348 | } |
| 349 | |