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" |
| 34 | |
| 35 | /** |
| 36 | * hif_intialize_default_ops() - intializes default operations values |
| 37 | * |
| 38 | * bus specific features should assign their dummy implementations here. |
| 39 | */ |
| 40 | static void hif_intialize_default_ops(struct hif_softc *hif_sc) |
| 41 | { |
| 42 | struct hif_bus_ops *bus_ops = &hif_sc->bus_ops; |
| 43 | |
| 44 | /* must be filled in by hif_bus_open */ |
| 45 | bus_ops->hif_bus_close = NULL; |
| 46 | |
| 47 | /* dummy implementations */ |
| 48 | } |
| 49 | |
| 50 | #define NUM_OPS (sizeof(struct hif_bus_ops) / sizeof(void *)) |
| 51 | |
| 52 | /** |
| 53 | * hif_verify_basic_ops() - ensure required bus apis are defined |
| 54 | * |
| 55 | * all bus operations must be defined to avoid crashes |
| 56 | * itterate over the structure and ensure all function pointers |
| 57 | * are non null. |
| 58 | * |
| 59 | * Return: QDF_STATUS_SUCCESS if all the operations are defined |
| 60 | */ |
| 61 | static QDF_STATUS hif_verify_basic_ops(struct hif_softc *hif_sc) |
| 62 | { |
| 63 | struct hif_bus_ops *bus_ops = &hif_sc->bus_ops; |
| 64 | void **ops_array = (void *)bus_ops; |
| 65 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 66 | int i; |
| 67 | |
| 68 | for (i = 0; i < NUM_OPS; i++) { |
| 69 | if (!ops_array[i]) { |
| 70 | HIF_ERROR("%s: function %d is null", __func__, i); |
| 71 | status = QDF_STATUS_E_NOSUPPORT; |
| 72 | } |
| 73 | } |
| 74 | return status; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * hif_bus_open() - initialize the bus_ops and call the bus specific open |
| 79 | * hif_sc: hif_context |
| 80 | * bus_type: type of bus being enumerated |
| 81 | * |
| 82 | * Return: QDF_STATUS_SUCCESS or error |
| 83 | */ |
| 84 | QDF_STATUS hif_bus_open(struct hif_softc *hif_sc, |
| 85 | enum qdf_bus_type bus_type) |
| 86 | { |
| 87 | QDF_STATUS status = QDF_STATUS_E_INVAL; |
| 88 | |
| 89 | hif_intialize_default_ops(hif_sc); |
| 90 | |
| 91 | switch (bus_type) { |
| 92 | case QDF_BUS_TYPE_PCI: |
| 93 | status = hif_initialize_pci_ops(&hif_sc->bus_ops); |
| 94 | break; |
| 95 | case QDF_BUS_TYPE_SNOC: |
| 96 | status = hif_initialize_snoc_ops(&hif_sc->bus_ops); |
| 97 | break; |
| 98 | default: |
| 99 | status = QDF_STATUS_E_NOSUPPORT; |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | if (status != QDF_STATUS_SUCCESS) { |
| 104 | HIF_ERROR("%s: %d not supported", __func__, bus_type); |
| 105 | return status; |
| 106 | } |
| 107 | |
| 108 | status = hif_verify_basic_ops(hif_sc); |
| 109 | if (status != QDF_STATUS_SUCCESS) |
| 110 | return status; |
| 111 | |
| 112 | return hif_sc->bus_ops.hif_bus_open(hif_sc, bus_type); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * hif_bus_close() - close the bus |
| 117 | * @hif_sc: hif_context |
| 118 | */ |
| 119 | void hif_bus_close(struct hif_softc *hif_sc) |
| 120 | { |
| 121 | hif_sc->bus_ops.hif_bus_close(hif_sc); |
| 122 | } |