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