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" |
Mohit Khanna | 1957ba9 | 2016-05-11 11:17:01 -0700 | [diff] [blame] | 34 | #include "dummy.h" |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 35 | #if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB) |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 36 | #include "ce_main.h" |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 37 | #endif |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 38 | #include "htc_services.h" |
| 39 | #include "a_types.h" |
Nirav Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame] | 40 | #include "dummy.h" |
| 41 | |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 42 | /** |
| 43 | * hif_intialize_default_ops() - intializes default operations values |
| 44 | * |
| 45 | * bus specific features should assign their dummy implementations here. |
| 46 | */ |
| 47 | static 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 Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 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 | 7fdff0c | 2016-08-29 12:31:58 -0700 | [diff] [blame^] | 58 | 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 Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 62 | } |
| 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 | */ |
| 75 | static 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 Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 92 | * hif_bus_get_context_size - API to return size of the bus specific structure |
| 93 | * |
| 94 | * Return: sizeof of hif_pci_softc |
| 95 | */ |
| 96 | int 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 Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 101 | case QDF_BUS_TYPE_AHB: |
| 102 | return hif_ahb_get_context_size(); |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 103 | case QDF_BUS_TYPE_SNOC: |
| 104 | return hif_snoc_get_context_size(); |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 105 | case QDF_BUS_TYPE_SDIO: |
| 106 | return hif_sdio_get_context_size(); |
Mohit Khanna | 1957ba9 | 2016-05-11 11:17:01 -0700 | [diff] [blame] | 107 | case QDF_BUS_TYPE_USB: |
| 108 | return hif_usb_get_context_size(); |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 109 | default: |
| 110 | return 0; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 115 | * 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 | */ |
| 121 | QDF_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 Hoffman | 54ef87d | 2016-03-14 21:11:58 -0700 | [diff] [blame] | 130 | status = hif_initialize_pci_ops(hif_sc); |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 131 | break; |
| 132 | case QDF_BUS_TYPE_SNOC: |
| 133 | status = hif_initialize_snoc_ops(&hif_sc->bus_ops); |
| 134 | break; |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 135 | case QDF_BUS_TYPE_AHB: |
| 136 | status = hif_initialize_ahb_ops(&hif_sc->bus_ops); |
| 137 | break; |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 138 | case QDF_BUS_TYPE_SDIO: |
| 139 | status = hif_initialize_sdio_ops(hif_sc); |
Mohit Khanna | 1957ba9 | 2016-05-11 11:17:01 -0700 | [diff] [blame] | 140 | case QDF_BUS_TYPE_USB: |
| 141 | status = hif_initialize_usb_ops(&hif_sc->bus_ops); |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 142 | break; |
Houston Hoffman | 32bc8eb | 2016-03-14 21:11:34 -0700 | [diff] [blame] | 143 | 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 | */ |
| 164 | void hif_bus_close(struct hif_softc *hif_sc) |
| 165 | { |
| 166 | hif_sc->bus_ops.hif_bus_close(hif_sc); |
| 167 | } |
Houston Hoffman | 4ca03b6 | 2016-03-14 21:11:51 -0700 | [diff] [blame] | 168 | |
| 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 | */ |
| 176 | void 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 | |
| 182 | void 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 | |
| 188 | int 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 | |
| 194 | int 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 Hoffman | 7fdff0c | 2016-08-29 12:31:58 -0700 | [diff] [blame^] | 200 | int 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 | |
| 206 | int 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 Hoffman | 4ca03b6 | 2016-03-14 21:11:51 -0700 | [diff] [blame] | 212 | int 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 Hoffman | 8f239f6 | 2016-03-14 21:12:05 -0700 | [diff] [blame] | 218 | |
| 219 | void 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 | |
| 225 | void hif_nointrs(struct hif_softc *hif_sc) |
| 226 | { |
| 227 | hif_sc->bus_ops.hif_nointrs(hif_sc); |
| 228 | } |
| 229 | |
| 230 | QDF_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 | |
| 237 | void hif_disable_bus(struct hif_softc *hif_sc) |
| 238 | { |
| 239 | hif_sc->bus_ops.hif_disable_bus(hif_sc); |
| 240 | } |
| 241 | |
| 242 | int hif_bus_configure(struct hif_softc *hif_sc) |
| 243 | { |
| 244 | return hif_sc->bus_ops.hif_bus_configure(hif_sc); |
| 245 | } |
| 246 | |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 247 | QDF_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 | |
| 255 | void 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 | |
| 261 | void 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 | |
| 267 | void 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 | |
| 273 | void 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 Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 279 | void 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 Hoffman | 8f239f6 | 2016-03-14 21:12:05 -0700 | [diff] [blame] | 284 | void 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 | |
| 289 | void 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 Hoffman | 3c017e7 | 2016-03-14 21:12:11 -0700 | [diff] [blame] | 293 | |
| 294 | int 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 Hoffman | b4149dd | 2016-03-23 15:55:41 -0700 | [diff] [blame] | 299 | |
Nirav Shah | 3573f95 | 2016-05-12 18:37:03 +0530 | [diff] [blame] | 300 | void 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 | |
| 309 | void 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 | |
| 319 | void 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 Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame] | 325 | void 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 | |
| 332 | void 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 Hoffman | b4149dd | 2016-03-23 15:55:41 -0700 | [diff] [blame] | 339 | /** |
| 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 | */ |
| 348 | void 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 | */ |
| 364 | void 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 Khanna | 1957ba9 | 2016-05-11 11:17:01 -0700 | [diff] [blame] | 370 | /** |
| 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 | */ |
| 378 | void 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 | */ |
| 395 | int 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 | } |