Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Houston Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 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 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 28 | #include "targcfg.h" |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 29 | #include "qdf_lock.h" |
| 30 | #include "qdf_status.h" |
| 31 | #include "qdf_status.h" |
| 32 | #include <qdf_atomic.h> /* qdf_atomic_read */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 33 | #include <targaddrs.h> |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 34 | #include "hif_io32.h" |
| 35 | #include <hif.h> |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 36 | #include "regtable.h" |
| 37 | #define ATH_MODULE_NAME hif |
| 38 | #include <a_debug.h> |
| 39 | #include "hif_main.h" |
| 40 | #include "hif_hw_version.h" |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 41 | #if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 42 | #include "ce_tasklet.h" |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 43 | #endif |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 44 | #include "qdf_trace.h" |
| 45 | #include "qdf_status.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 46 | #include "hif_debug.h" |
| 47 | #include "mp_dev.h" |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 48 | #include "ce_api.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 49 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 50 | void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t cmd_id, bool start) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 51 | { |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 52 | hif_trigger_dump(hif_ctx, cmd_id, start); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 55 | /** |
| 56 | * hif_get_target_id(): hif_get_target_id |
| 57 | * |
| 58 | * Return the virtual memory base address to the caller |
| 59 | * |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 60 | * @scn: hif_softc |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 61 | * |
| 62 | * Return: A_target_id_t |
| 63 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 64 | A_target_id_t hif_get_target_id(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 65 | { |
| 66 | return scn->mem; |
| 67 | } |
| 68 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 69 | /** |
| 70 | * hif_get_targetdef(): hif_get_targetdef |
| 71 | * @scn: scn |
| 72 | * |
| 73 | * Return: void * |
| 74 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 75 | void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 76 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 77 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 78 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 79 | return scn->targetdef; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * hif_vote_link_down(): unvote for link up |
| 84 | * |
| 85 | * Call hif_vote_link_down to release a previous request made using |
| 86 | * hif_vote_link_up. A hif_vote_link_down call should only be made |
| 87 | * after a corresponding hif_vote_link_up, otherwise you could be |
| 88 | * negating a vote from another source. When no votes are present |
| 89 | * hif will not guarantee the linkstate after hif_bus_suspend. |
| 90 | * |
| 91 | * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread |
| 92 | * and initialization deinitialization sequencences. |
| 93 | * |
| 94 | * Return: n/a |
| 95 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 96 | void hif_vote_link_down(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 97 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 98 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 99 | QDF_BUG(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 100 | |
| 101 | scn->linkstate_vote--; |
| 102 | if (scn->linkstate_vote == 0) |
Houston Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 103 | hif_bus_prevent_linkdown(scn, false); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * hif_vote_link_up(): vote to prevent bus from suspending |
| 108 | * |
| 109 | * Makes hif guarantee that fw can message the host normally |
| 110 | * durring suspend. |
| 111 | * |
| 112 | * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread |
| 113 | * and initialization deinitialization sequencences. |
| 114 | * |
| 115 | * Return: n/a |
| 116 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 117 | void hif_vote_link_up(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 118 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 119 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 120 | QDF_BUG(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 121 | |
| 122 | scn->linkstate_vote++; |
| 123 | if (scn->linkstate_vote == 1) |
Houston Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 124 | hif_bus_prevent_linkdown(scn, true); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * hif_can_suspend_link(): query if hif is permitted to suspend the link |
| 129 | * |
| 130 | * Hif will ensure that the link won't be suspended if the upperlayers |
| 131 | * don't want it to. |
| 132 | * |
| 133 | * SYNCHRONIZATION: MC thread is stopped before bus suspend thus |
| 134 | * we don't need extra locking to ensure votes dont change while |
| 135 | * we are in the process of suspending or resuming. |
| 136 | * |
| 137 | * Return: false if hif will guarantee link up durring suspend. |
| 138 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 139 | bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 140 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 141 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 142 | QDF_BUG(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 143 | |
| 144 | return scn->linkstate_vote == 0; |
| 145 | } |
| 146 | |
Houston Hoffman | 4f52998 | 2016-05-05 16:11:04 -0700 | [diff] [blame] | 147 | #ifndef CONFIG_WIN |
| 148 | #define QCA9984_HOST_INTEREST_ADDRESS -1 |
| 149 | #define QCA9888_HOST_INTEREST_ADDRESS -1 |
| 150 | #define IPQ4019_HOST_INTEREST_ADDRESS -1 |
| 151 | #endif |
| 152 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 153 | /** |
| 154 | * hif_hia_item_address(): hif_hia_item_address |
| 155 | * @target_type: target_type |
| 156 | * @item_offset: item_offset |
| 157 | * |
| 158 | * Return: n/a |
| 159 | */ |
| 160 | uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset) |
| 161 | { |
| 162 | switch (target_type) { |
| 163 | case TARGET_TYPE_AR6002: |
| 164 | return AR6002_HOST_INTEREST_ADDRESS + item_offset; |
| 165 | case TARGET_TYPE_AR6003: |
| 166 | return AR6003_HOST_INTEREST_ADDRESS + item_offset; |
| 167 | case TARGET_TYPE_AR6004: |
| 168 | return AR6004_HOST_INTEREST_ADDRESS + item_offset; |
| 169 | case TARGET_TYPE_AR6006: |
| 170 | return AR6006_HOST_INTEREST_ADDRESS + item_offset; |
| 171 | case TARGET_TYPE_AR9888: |
| 172 | return AR9888_HOST_INTEREST_ADDRESS + item_offset; |
| 173 | case TARGET_TYPE_AR6320: |
| 174 | case TARGET_TYPE_AR6320V2: |
| 175 | return AR6320_HOST_INTEREST_ADDRESS + item_offset; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 176 | case TARGET_TYPE_ADRASTEA: |
| 177 | /* ADRASTEA doesn't have a host interest address */ |
| 178 | ASSERT(0); |
| 179 | return 0; |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 180 | case TARGET_TYPE_AR900B: |
| 181 | return AR900B_HOST_INTEREST_ADDRESS + item_offset; |
| 182 | case TARGET_TYPE_QCA9984: |
| 183 | return QCA9984_HOST_INTEREST_ADDRESS + item_offset; |
| 184 | case TARGET_TYPE_QCA9888: |
| 185 | return QCA9888_HOST_INTEREST_ADDRESS + item_offset; |
| 186 | case TARGET_TYPE_IPQ4019: |
| 187 | return IPQ4019_HOST_INTEREST_ADDRESS + item_offset; |
| 188 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 189 | default: |
| 190 | ASSERT(0); |
| 191 | return 0; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * hif_max_num_receives_reached() - check max receive is reached |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 197 | * @scn: HIF Context |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 198 | * @count: unsigned int. |
| 199 | * |
| 200 | * Output check status as bool |
| 201 | * |
| 202 | * Return: bool |
| 203 | */ |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 204 | bool hif_max_num_receives_reached(struct hif_softc *scn, unsigned int count) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 205 | { |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 206 | if (QDF_IS_EPPING_ENABLED(hif_get_conparam(scn))) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 207 | return count > 120; |
| 208 | else |
| 209 | return count > MAX_NUM_OF_RECEIVES; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * init_buffer_count() - initial buffer count |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 214 | * @maxSize: qdf_size_t |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 215 | * |
| 216 | * routine to modify the initial buffer count to be allocated on an os |
| 217 | * platform basis. Platform owner will need to modify this as needed |
| 218 | * |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 219 | * Return: qdf_size_t |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 220 | */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 221 | qdf_size_t init_buffer_count(qdf_size_t maxSize) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 222 | { |
| 223 | return maxSize; |
| 224 | } |
| 225 | |
| 226 | /** |
Nirav Shah | d7f9159 | 2016-04-21 14:18:43 +0530 | [diff] [blame] | 227 | * hif_save_htc_htt_config_endpoint() - save htt_tx_endpoint |
| 228 | * @hif_ctx: hif context |
| 229 | * @htc_htt_tx_endpoint: htt_tx_endpoint |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 230 | * |
| 231 | * Return: void |
| 232 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 233 | void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx, |
Nirav Shah | d7f9159 | 2016-04-21 14:18:43 +0530 | [diff] [blame] | 234 | int htc_htt_tx_endpoint) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 235 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 236 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 237 | |
| 238 | if (!scn) { |
| 239 | HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!", |
| 240 | __func__); |
| 241 | return; |
| 242 | } |
| 243 | |
Nirav Shah | d7f9159 | 2016-04-21 14:18:43 +0530 | [diff] [blame] | 244 | scn->htc_htt_tx_endpoint = htc_htt_tx_endpoint; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Houston Hoffman | ec93ab0 | 2016-05-03 20:09:55 -0700 | [diff] [blame] | 247 | static const struct qwlan_hw qwlan_hw_list[] = { |
| 248 | { |
| 249 | .id = AR6320_REV1_VERSION, |
| 250 | .subid = 0, |
| 251 | .name = "QCA6174_REV1", |
| 252 | }, |
| 253 | { |
| 254 | .id = AR6320_REV1_1_VERSION, |
| 255 | .subid = 0x1, |
| 256 | .name = "QCA6174_REV1_1", |
| 257 | }, |
| 258 | { |
| 259 | .id = AR6320_REV1_3_VERSION, |
| 260 | .subid = 0x2, |
| 261 | .name = "QCA6174_REV1_3", |
| 262 | }, |
| 263 | { |
| 264 | .id = AR6320_REV2_1_VERSION, |
| 265 | .subid = 0x4, |
| 266 | .name = "QCA6174_REV2_1", |
| 267 | }, |
| 268 | { |
| 269 | .id = AR6320_REV2_1_VERSION, |
| 270 | .subid = 0x5, |
| 271 | .name = "QCA6174_REV2_2", |
| 272 | }, |
| 273 | { |
| 274 | .id = AR6320_REV3_VERSION, |
| 275 | .subid = 0x6, |
| 276 | .name = "QCA6174_REV2.3", |
| 277 | }, |
| 278 | { |
| 279 | .id = AR6320_REV3_VERSION, |
| 280 | .subid = 0x8, |
| 281 | .name = "QCA6174_REV3", |
| 282 | }, |
| 283 | { |
| 284 | .id = AR6320_REV3_VERSION, |
| 285 | .subid = 0x9, |
| 286 | .name = "QCA6174_REV3_1", |
| 287 | }, |
| 288 | { |
| 289 | .id = AR6320_REV3_2_VERSION, |
| 290 | .subid = 0xA, |
| 291 | .name = "AR6320_REV3_2_VERSION", |
Houston Hoffman | cd0884a | 2016-08-24 15:30:09 -0700 | [diff] [blame] | 292 | }, |
| 293 | { |
| 294 | .id = WCN3990_v1, |
| 295 | .subid = 0x0, |
| 296 | .name = "WCN3990_V1", |
Houston Hoffman | ec93ab0 | 2016-05-03 20:09:55 -0700 | [diff] [blame] | 297 | } |
| 298 | }; |
| 299 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 300 | /** |
| 301 | * hif_get_hw_name(): get a human readable name for the hardware |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 302 | * @info: Target Info |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 303 | * |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 304 | * Return: human readable name for the underlying wifi hardware. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 305 | */ |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 306 | static const char *hif_get_hw_name(struct hif_target_info *info) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 307 | { |
| 308 | int i; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 309 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 310 | for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) { |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 311 | if (info->target_version == qwlan_hw_list[i].id && |
| 312 | info->target_revision == qwlan_hw_list[i].subid) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 313 | return qwlan_hw_list[i].name; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | return "Unknown Device"; |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * hif_get_hw_info(): hif_get_hw_info |
| 322 | * @scn: scn |
| 323 | * @version: version |
| 324 | * @revision: revision |
| 325 | * |
| 326 | * Return: n/a |
| 327 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 328 | void hif_get_hw_info(struct hif_opaque_softc *scn, u32 *version, u32 *revision, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 329 | const char **target_name) |
| 330 | { |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 331 | struct hif_target_info *info = hif_get_target_info_handle(scn); |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 332 | struct hif_softc *sc = HIF_GET_SOFTC(scn); |
| 333 | |
| 334 | if (sc->bus_type == QDF_BUS_TYPE_USB) |
| 335 | hif_usb_get_hw_info(sc); |
| 336 | |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 337 | *version = info->target_version; |
| 338 | *revision = info->target_revision; |
| 339 | *target_name = hif_get_hw_name(info); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
| 343 | * hif_open(): hif_open |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 344 | * @qdf_ctx: QDF Context |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 345 | * @mode: Driver Mode |
| 346 | * @bus_type: Bus Type |
| 347 | * @cbk: CDS Callbacks |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 348 | * |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 349 | * API to open HIF Context |
| 350 | * |
| 351 | * Return: HIF Opaque Pointer |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 352 | */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 353 | struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode, |
| 354 | enum qdf_bus_type bus_type, |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 355 | struct hif_driver_state_callbacks *cbk) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 356 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 357 | struct hif_softc *scn; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 358 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
Houston Hoffman | 162164c | 2016-03-14 21:12:10 -0700 | [diff] [blame] | 359 | int bus_context_size = hif_bus_get_context_size(bus_type); |
| 360 | |
| 361 | if (bus_context_size == 0) { |
| 362 | HIF_ERROR("%s: context size 0 not allowed", __func__); |
| 363 | return NULL; |
| 364 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 365 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 366 | scn = (struct hif_softc *)qdf_mem_malloc(bus_context_size); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 367 | if (!scn) { |
| 368 | HIF_ERROR("%s: cannot alloc memory for HIF context of size:%d", |
| 369 | __func__, bus_context_size); |
| 370 | return GET_HIF_OPAQUE_HDL(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 373 | qdf_mem_zero(scn, bus_context_size); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 374 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 375 | scn->qdf_dev = qdf_ctx; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 376 | scn->hif_con_param = mode; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 377 | qdf_atomic_init(&scn->active_tasklet_cnt); |
| 378 | qdf_atomic_init(&scn->link_suspended); |
| 379 | qdf_atomic_init(&scn->tasklet_from_intr); |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 380 | qdf_mem_copy(&scn->callbacks, cbk, sizeof(struct hif_driver_state_callbacks)); |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 381 | scn->bus_type = bus_type; |
Houston Hoffman | 3cfe686 | 2016-01-08 10:33:55 -0800 | [diff] [blame] | 382 | status = hif_bus_open(scn, bus_type); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 383 | if (status != QDF_STATUS_SUCCESS) { |
Houston Hoffman | 3cfe686 | 2016-01-08 10:33:55 -0800 | [diff] [blame] | 384 | HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d", |
| 385 | __func__, status, bus_type); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 386 | qdf_mem_free(scn); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 387 | scn = NULL; |
Houston Hoffman | 3cfe686 | 2016-01-08 10:33:55 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 390 | return GET_HIF_OPAQUE_HDL(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /** |
| 394 | * hif_close(): hif_close |
| 395 | * @hif_ctx: hif_ctx |
| 396 | * |
| 397 | * Return: n/a |
| 398 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 399 | void hif_close(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 400 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 401 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 402 | |
| 403 | if (scn == NULL) { |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 404 | HIF_ERROR("%s: hif_opaque_softc is NULL", __func__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 405 | return; |
| 406 | } |
| 407 | |
| 408 | if (scn->athdiag_procfs_inited) { |
| 409 | athdiag_procfs_remove(); |
| 410 | scn->athdiag_procfs_inited = false; |
| 411 | } |
| 412 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 413 | hif_bus_close(scn); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 414 | qdf_mem_free(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
| 418 | * hif_enable(): hif_enable |
| 419 | * @hif_ctx: hif_ctx |
| 420 | * @dev: dev |
| 421 | * @bdev: bus dev |
| 422 | * @bid: bus ID |
| 423 | * @bus_type: bus type |
| 424 | * @type: enable type |
| 425 | * |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 426 | * Return: QDF_STATUS |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 427 | */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 428 | QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 429 | void *bdev, const hif_bus_id *bid, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 430 | enum qdf_bus_type bus_type, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 431 | enum hif_enable_type type) |
| 432 | { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 433 | QDF_STATUS status; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 434 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 435 | |
| 436 | if (scn == NULL) { |
| 437 | HIF_ERROR("%s: hif_ctx = NULL", __func__); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 438 | return QDF_STATUS_E_NULL_VALUE; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 441 | status = hif_enable_bus(scn, dev, bdev, bid, type); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 442 | if (status != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 443 | HIF_ERROR("%s: hif_enable_bus error = %d", |
| 444 | __func__, status); |
| 445 | return status; |
| 446 | } |
| 447 | |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 448 | if (hif_bus_configure(scn)) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 449 | HIF_ERROR("%s: Target probe failed.", __func__); |
Vishwajith Upendra | 3f78aa6 | 2016-02-09 17:53:02 +0530 | [diff] [blame] | 450 | hif_disable_bus(scn); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 451 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 452 | return status; |
| 453 | } |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 454 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 455 | /* |
| 456 | * Flag to avoid potential unallocated memory access from MSI |
| 457 | * interrupt handler which could get scheduled as soon as MSI |
| 458 | * is enabled, i.e to take care of the race due to the order |
| 459 | * in where MSI is enabled before the memory, that will be |
| 460 | * in interrupt handlers, is allocated. |
| 461 | */ |
| 462 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 463 | scn->hif_init_done = true; |
| 464 | |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 465 | HIF_TRACE("%s: OK", __func__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 466 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 467 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 470 | void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 471 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 472 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 473 | |
| 474 | if (!scn) |
| 475 | return; |
| 476 | |
| 477 | hif_nointrs(scn); |
| 478 | if (scn->hif_init_done == false) |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 479 | hif_shutdown_device(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 480 | else |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 481 | hif_stop(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 482 | |
Vishwajith Upendra | 3f78aa6 | 2016-02-09 17:53:02 +0530 | [diff] [blame] | 483 | hif_disable_bus(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 484 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 485 | hif_wlan_disable(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 486 | |
| 487 | scn->notice_send = false; |
| 488 | |
| 489 | HIF_INFO("%s: X", __func__); |
| 490 | } |
| 491 | |
Nirav Shah | b70bd73 | 2016-05-25 14:31:51 +0530 | [diff] [blame] | 492 | void hif_display_stats(struct hif_opaque_softc *hif_ctx) |
| 493 | { |
| 494 | hif_display_bus_stats(hif_ctx); |
| 495 | } |
| 496 | |
| 497 | void hif_clear_stats(struct hif_opaque_softc *hif_ctx) |
| 498 | { |
| 499 | hif_clear_bus_stats(hif_ctx); |
| 500 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 501 | |
| 502 | /** |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 503 | * hif_crash_shutdown_dump_bus_register() - dump bus registers |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 504 | * @hif_ctx: hif_ctx |
| 505 | * |
| 506 | * Return: n/a |
| 507 | */ |
| 508 | #if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \ |
Houston Hoffman | bc69349 | 2016-03-14 21:11:41 -0700 | [diff] [blame] | 509 | && defined(DEBUG) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 510 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 511 | static void hif_crash_shutdown_dump_bus_register(void *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 512 | { |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 513 | struct hif_opaque_softc *scn = hif_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 514 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 515 | if (hif_check_soc_status(scn)) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 516 | return; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 517 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 518 | if (hif_dump_registers(scn)) |
| 519 | HIF_ERROR("Failed to dump bus registers!"); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /** |
| 523 | * hif_crash_shutdown(): hif_crash_shutdown |
| 524 | * |
| 525 | * This function is called by the platform driver to dump CE registers |
| 526 | * |
| 527 | * @hif_ctx: hif_ctx |
| 528 | * |
| 529 | * Return: n/a |
| 530 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 531 | void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 532 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 533 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 534 | |
Houston Hoffman | bc69349 | 2016-03-14 21:11:41 -0700 | [diff] [blame] | 535 | if (!hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 536 | return; |
| 537 | |
Houston Hoffman | bc69349 | 2016-03-14 21:11:41 -0700 | [diff] [blame] | 538 | if (scn->bus_type == QDF_BUS_TYPE_SNOC) { |
| 539 | HIF_INFO_MED("%s: RAM dump disabled for bustype %d", |
| 540 | __func__, scn->bus_type); |
| 541 | return; |
| 542 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 543 | |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 544 | if (TARGET_STATUS_RESET == scn->target_status) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 545 | HIF_INFO_MED("%s: Target is already asserted, ignore!", |
| 546 | __func__); |
| 547 | return; |
| 548 | } |
| 549 | |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 550 | if (hif_is_load_or_unload_in_progress(scn)) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 551 | HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__); |
| 552 | return; |
| 553 | } |
| 554 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 555 | hif_crash_shutdown_dump_bus_register(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 556 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 557 | if (ol_copy_ramdump(hif_ctx)) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 558 | goto out; |
| 559 | |
| 560 | HIF_INFO_MED("%s: RAM dump collecting completed!", __func__); |
| 561 | |
| 562 | out: |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 563 | return; |
| 564 | } |
| 565 | #else |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 566 | void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 567 | { |
| 568 | HIF_INFO_MED("%s: Collecting target RAM dump disabled", |
| 569 | __func__); |
| 570 | return; |
| 571 | } |
| 572 | #endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */ |
| 573 | |
| 574 | #ifdef QCA_WIFI_3_0 |
| 575 | /** |
| 576 | * hif_check_fw_reg(): hif_check_fw_reg |
| 577 | * @scn: scn |
| 578 | * @state: |
| 579 | * |
| 580 | * Return: int |
| 581 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 582 | int hif_check_fw_reg(struct hif_opaque_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 583 | { |
| 584 | return 0; |
| 585 | } |
| 586 | #endif |
| 587 | |
| 588 | #ifdef IPA_OFFLOAD |
| 589 | /** |
| 590 | * hif_read_phy_mem_base(): hif_read_phy_mem_base |
| 591 | * @scn: scn |
| 592 | * @phy_mem_base: physical mem base |
| 593 | * |
| 594 | * Return: n/a |
| 595 | */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 596 | void hif_read_phy_mem_base(struct hif_softc *scn, qdf_dma_addr_t *phy_mem_base) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 597 | { |
| 598 | *phy_mem_base = scn->mem_pa; |
| 599 | } |
| 600 | #endif /* IPA_OFFLOAD */ |
| 601 | |
| 602 | /** |
| 603 | * hif_get_device_type(): hif_get_device_type |
| 604 | * @device_id: device_id |
| 605 | * @revision_id: revision_id |
| 606 | * @hif_type: returned hif_type |
| 607 | * @target_type: returned target_type |
| 608 | * |
| 609 | * Return: int |
| 610 | */ |
| 611 | int hif_get_device_type(uint32_t device_id, |
| 612 | uint32_t revision_id, |
| 613 | uint32_t *hif_type, uint32_t *target_type) |
| 614 | { |
| 615 | int ret = 0; |
| 616 | |
| 617 | switch (device_id) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 618 | case ADRASTEA_DEVICE_ID: |
| 619 | case ADRASTEA_DEVICE_ID_P2_E12: |
| 620 | |
| 621 | *hif_type = HIF_TYPE_ADRASTEA; |
| 622 | *target_type = TARGET_TYPE_ADRASTEA; |
| 623 | break; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 624 | |
| 625 | case AR9888_DEVICE_ID: |
| 626 | *hif_type = HIF_TYPE_AR9888; |
| 627 | *target_type = TARGET_TYPE_AR9888; |
| 628 | break; |
| 629 | |
| 630 | case AR6320_DEVICE_ID: |
| 631 | switch (revision_id) { |
| 632 | case AR6320_FW_1_1: |
| 633 | case AR6320_FW_1_3: |
| 634 | *hif_type = HIF_TYPE_AR6320; |
| 635 | *target_type = TARGET_TYPE_AR6320; |
| 636 | break; |
| 637 | |
| 638 | case AR6320_FW_2_0: |
| 639 | case AR6320_FW_3_0: |
| 640 | case AR6320_FW_3_2: |
| 641 | *hif_type = HIF_TYPE_AR6320V2; |
| 642 | *target_type = TARGET_TYPE_AR6320V2; |
| 643 | break; |
| 644 | |
| 645 | default: |
| 646 | HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x", |
| 647 | __func__, device_id, revision_id); |
| 648 | ret = -ENODEV; |
| 649 | goto end; |
| 650 | } |
| 651 | break; |
| 652 | |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 653 | case AR9887_DEVICE_ID: |
| 654 | *hif_type = HIF_TYPE_AR9888; |
| 655 | *target_type = TARGET_TYPE_AR9888; |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 656 | HIF_INFO(" *********** AR9887 **************"); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case QCA9984_DEVICE_ID: |
| 660 | *hif_type = HIF_TYPE_QCA9984; |
| 661 | *target_type = TARGET_TYPE_QCA9984; |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 662 | HIF_INFO(" *********** QCA9984 *************"); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case QCA9888_DEVICE_ID: |
| 666 | *hif_type = HIF_TYPE_QCA9888; |
| 667 | *target_type = TARGET_TYPE_QCA9888; |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 668 | HIF_INFO(" *********** QCA9888 *************"); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case AR900B_DEVICE_ID: |
| 672 | *hif_type = HIF_TYPE_AR900B; |
| 673 | *target_type = TARGET_TYPE_AR900B; |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 674 | HIF_INFO(" *********** AR900B *************"); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 675 | break; |
| 676 | |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 677 | case IPQ4019_DEVICE_ID: |
| 678 | *hif_type = HIF_TYPE_IPQ4019; |
| 679 | *target_type = TARGET_TYPE_IPQ4019; |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 680 | HIF_INFO(" *********** IPQ4019 *************"); |
Houston Hoffman | 3db96a4 | 2016-05-05 19:54:39 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
Venkateswara Swamy Bandaru | 9fd9af0 | 2016-09-20 20:27:31 +0530 | [diff] [blame^] | 683 | case QCA8074_DEVICE_ID: |
| 684 | *hif_type = HIF_TYPE_QCA8074; |
| 685 | *target_type = TARGET_TYPE_QCA8074; |
| 686 | HIF_INFO(" *********** QCA8074 *************\n"); |
| 687 | break; |
| 688 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 689 | default: |
| 690 | HIF_ERROR("%s: Unsupported device ID!", __func__); |
| 691 | ret = -ENODEV; |
| 692 | break; |
| 693 | } |
| 694 | end: |
| 695 | return ret; |
| 696 | } |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 697 | |
| 698 | /** |
Houston Hoffman | 2635259 | 2016-03-14 21:11:43 -0700 | [diff] [blame] | 699 | * hif_needs_bmi() - return true if the soc needs bmi through the driver |
| 700 | * @hif_ctx: hif context |
| 701 | * |
| 702 | * Return: true if the soc needs driver bmi otherwise false |
| 703 | */ |
| 704 | bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx) |
| 705 | { |
| 706 | struct hif_softc *hif_sc = HIF_GET_SOFTC(hif_ctx); |
| 707 | return hif_sc->bus_type != QDF_BUS_TYPE_SNOC; |
| 708 | } |
| 709 | |
| 710 | /** |
Houston Hoffman | 60a1eeb | 2016-03-14 21:11:44 -0700 | [diff] [blame] | 711 | * hif_get_bus_type() - return the bus type |
| 712 | * |
| 713 | * Return: enum qdf_bus_type |
| 714 | */ |
| 715 | enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl) |
| 716 | { |
| 717 | struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl); |
| 718 | return scn->bus_type; |
| 719 | } |
| 720 | |
| 721 | /** |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 722 | * Target info and ini parameters are global to the driver |
| 723 | * Hence these structures are exposed to all the modules in |
| 724 | * the driver and they don't need to maintains multiple copies |
| 725 | * of the same info, instead get the handle from hif and |
| 726 | * modify them in hif |
| 727 | */ |
| 728 | |
| 729 | /** |
| 730 | * hif_get_ini_handle() - API to get hif_config_param handle |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 731 | * @hif_ctx: HIF Context |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 732 | * |
| 733 | * Return: pointer to hif_config_info |
| 734 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 735 | struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx) |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 736 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 737 | struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx); |
| 738 | |
| 739 | return &sc->hif_config; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /** |
| 743 | * hif_get_target_info_handle() - API to get hif_target_info handle |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 744 | * @hif_ctx: HIF context |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 745 | * |
| 746 | * Return: Pointer to hif_target_info |
| 747 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 748 | struct hif_target_info *hif_get_target_info_handle( |
| 749 | struct hif_opaque_softc *hif_ctx) |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 750 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 751 | struct hif_softc *sc = HIF_GET_SOFTC(hif_ctx); |
| 752 | |
| 753 | return &sc->target_info; |
| 754 | |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 755 | } |
Komal Seelam | c92a0cf | 2016-02-22 20:43:52 +0530 | [diff] [blame] | 756 | |
| 757 | #if defined(FEATURE_LRO) |
| 758 | /** |
| 759 | * hif_lro_flush_cb_register - API to register for LRO Flush Callback |
| 760 | * @scn: HIF Context |
| 761 | * @handler: Function pointer to be called by HIF |
| 762 | * @data: Private data to be used by the module registering to HIF |
| 763 | * |
| 764 | * Return: void |
| 765 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 766 | void hif_lro_flush_cb_register(struct hif_opaque_softc *scn, |
| 767 | void (handler)(void *), void *data) |
Komal Seelam | c92a0cf | 2016-02-22 20:43:52 +0530 | [diff] [blame] | 768 | { |
| 769 | ce_lro_flush_cb_register(scn, handler, data); |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks |
| 774 | * @scn: HIF Context |
| 775 | * |
| 776 | * Return: void |
| 777 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 778 | void hif_lro_flush_cb_deregister(struct hif_opaque_softc *scn) |
Komal Seelam | c92a0cf | 2016-02-22 20:43:52 +0530 | [diff] [blame] | 779 | { |
| 780 | ce_lro_flush_cb_deregister(scn); |
| 781 | } |
| 782 | #endif |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 783 | |
| 784 | /** |
| 785 | * hif_get_target_status - API to get target status |
| 786 | * @hif_ctx: HIF Context |
| 787 | * |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 788 | * Return: enum hif_target_status |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 789 | */ |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 790 | enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx) |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 791 | { |
| 792 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 793 | |
| 794 | return scn->target_status; |
| 795 | } |
| 796 | |
| 797 | /** |
Komal Seelam | a5911d3 | 2016-02-24 19:21:59 +0530 | [diff] [blame] | 798 | * hif_set_target_status() - API to set target status |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 799 | * @hif_ctx: HIF Context |
| 800 | * @status: Target Status |
| 801 | * |
| 802 | * Return: void |
| 803 | */ |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 804 | void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum |
| 805 | hif_target_status status) |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 806 | { |
| 807 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 808 | |
| 809 | scn->target_status = status; |
| 810 | } |
Komal Seelam | a5911d3 | 2016-02-24 19:21:59 +0530 | [diff] [blame] | 811 | |
| 812 | /** |
| 813 | * hif_init_ini_config() - API to initialize HIF configuration parameters |
| 814 | * @hif_ctx: HIF Context |
| 815 | * @cfg: HIF Configuration |
| 816 | * |
| 817 | * Return: void |
| 818 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 819 | void hif_init_ini_config(struct hif_opaque_softc *hif_ctx, |
| 820 | struct hif_config_info *cfg) |
Komal Seelam | a5911d3 | 2016-02-24 19:21:59 +0530 | [diff] [blame] | 821 | { |
| 822 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 823 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 824 | qdf_mem_copy(&scn->hif_config, cfg, sizeof(struct hif_config_info)); |
Komal Seelam | a5911d3 | 2016-02-24 19:21:59 +0530 | [diff] [blame] | 825 | } |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 826 | |
| 827 | /** |
| 828 | * hif_get_conparam() - API to get driver mode in HIF |
| 829 | * @scn: HIF Context |
| 830 | * |
| 831 | * Return: driver mode of operation |
| 832 | */ |
| 833 | uint32_t hif_get_conparam(struct hif_softc *scn) |
| 834 | { |
| 835 | if (!scn) |
| 836 | return 0; |
| 837 | |
| 838 | return scn->hif_con_param; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * hif_get_callbacks_handle() - API to get callbacks Handle |
| 843 | * @scn: HIF Context |
| 844 | * |
| 845 | * Return: pointer to HIF Callbacks |
| 846 | */ |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 847 | struct hif_driver_state_callbacks *hif_get_callbacks_handle(struct hif_softc *scn) |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 848 | { |
| 849 | return &scn->callbacks; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * hif_is_driver_unloading() - API to query upper layers if driver is unloading |
| 854 | * @scn: HIF Context |
| 855 | * |
| 856 | * Return: True/False |
| 857 | */ |
| 858 | bool hif_is_driver_unloading(struct hif_softc *scn) |
| 859 | { |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 860 | struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 861 | |
| 862 | if (cbk && cbk->is_driver_unloading) |
| 863 | return cbk->is_driver_unloading(cbk->context); |
| 864 | |
| 865 | return false; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * hif_is_load_or_unload_in_progress() - API to query upper layers if |
| 870 | * load/unload in progress |
| 871 | * @scn: HIF Context |
| 872 | * |
| 873 | * Return: True/False |
| 874 | */ |
| 875 | bool hif_is_load_or_unload_in_progress(struct hif_softc *scn) |
| 876 | { |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 877 | struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 878 | |
| 879 | if (cbk && cbk->is_load_unload_in_progress) |
| 880 | return cbk->is_load_unload_in_progress(cbk->context); |
| 881 | |
| 882 | return false; |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * hif_is_recovery_in_progress() - API to query upper layers if recovery in |
| 887 | * progress |
| 888 | * @scn: HIF Context |
| 889 | * |
| 890 | * Return: True/False |
| 891 | */ |
| 892 | bool hif_is_recovery_in_progress(struct hif_softc *scn) |
| 893 | { |
Komal Seelam | 7508012 | 2016-03-02 15:18:25 +0530 | [diff] [blame] | 894 | struct hif_driver_state_callbacks *cbk = hif_get_callbacks_handle(scn); |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 895 | |
| 896 | if (cbk && cbk->is_recovery_in_progress) |
| 897 | return cbk->is_recovery_in_progress(cbk->context); |
| 898 | |
| 899 | return false; |
| 900 | } |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 901 | #if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB) |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 902 | /** |
| 903 | * hif_batch_send() - API to access hif specific function |
| 904 | * ce_batch_send. |
| 905 | * @osc: HIF Context |
| 906 | * @msdu : list of msdus to be sent |
| 907 | * @transfer_id : transfer id |
| 908 | * @len : donwloaded length |
| 909 | * |
| 910 | * Return: list of msds not sent |
| 911 | */ |
| 912 | qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, |
| 913 | uint32_t transfer_id, u_int32_t len, uint32_t sendhead) |
| 914 | { |
| 915 | void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE); |
| 916 | return ce_batch_send((struct CE_handle *)ce_tx_hdl, msdu, transfer_id, |
| 917 | len, sendhead); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * hif_update_tx_ring() - API to access hif specific function |
| 922 | * ce_update_tx_ring. |
| 923 | * @osc: HIF Context |
| 924 | * @num_htt_cmpls : number of htt compl received. |
| 925 | * |
| 926 | * Return: void |
| 927 | */ |
| 928 | void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls) |
| 929 | { |
| 930 | void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE); |
| 931 | ce_update_tx_ring(ce_tx_hdl, num_htt_cmpls); |
| 932 | } |
| 933 | |
| 934 | |
| 935 | /** |
| 936 | * hif_send_single() - API to access hif specific function |
| 937 | * ce_send_single. |
| 938 | * @osc: HIF Context |
| 939 | * @msdu : msdu to be sent |
| 940 | * @transfer_id: transfer id |
| 941 | * @len : downloaded length |
| 942 | * |
| 943 | * Return: msdu sent status |
| 944 | */ |
| 945 | int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t |
| 946 | transfer_id, u_int32_t len) |
| 947 | { |
| 948 | void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE); |
| 949 | return ce_send_single((struct CE_handle *)ce_tx_hdl, msdu, transfer_id, |
| 950 | len); |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * hif_send_fast() - API to access hif specific function |
| 955 | * ce_send_fast. |
| 956 | * @osc: HIF Context |
| 957 | * @msdu : array of msdus to be sent |
| 958 | * @num_msdus : number of msdus in an array |
| 959 | * @transfer_id: transfer id |
Nirav Shah | da0881a | 2016-05-16 10:45:16 +0530 | [diff] [blame] | 960 | * @download_len: download length |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 961 | * |
| 962 | * Return: No. of packets that could be sent |
| 963 | */ |
Nirav Shah | da0881a | 2016-05-16 10:45:16 +0530 | [diff] [blame] | 964 | int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf, |
| 965 | uint32_t transfer_id, uint32_t download_len) |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 966 | { |
| 967 | void *ce_tx_hdl = hif_get_ce_handle(osc, CE_HTT_TX_CE); |
Nirav Shah | da0881a | 2016-05-16 10:45:16 +0530 | [diff] [blame] | 968 | return ce_send_fast((struct CE_handle *)ce_tx_hdl, nbuf, |
| 969 | transfer_id, download_len); |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 970 | } |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 971 | #endif |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 972 | |
| 973 | /** |
| 974 | * hif_reg_write() - API to access hif specific function |
| 975 | * hif_write32_mb. |
| 976 | * @hif_ctx : HIF Context |
| 977 | * @offset : offset on which value has to be written |
| 978 | * @value : value to be written |
| 979 | * |
| 980 | * Return: None |
| 981 | */ |
| 982 | void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset, |
| 983 | uint32_t value) |
| 984 | { |
| 985 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 986 | hif_write32_mb(scn->mem + offset, value); |
| 987 | |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * hif_reg_read() - API to access hif specific function |
| 992 | * hif_read32_mb. |
| 993 | * @hif_ctx : HIF Context |
| 994 | * @offset : offset from which value has to be read |
| 995 | * |
| 996 | * Return: Read value |
| 997 | */ |
| 998 | uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset) |
| 999 | { |
| 1000 | |
| 1001 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 1002 | return hif_read32_mb(scn->mem + offset); |
| 1003 | } |
Mohit Khanna | 440c529 | 2016-05-12 11:05:06 -0700 | [diff] [blame] | 1004 | |
| 1005 | #if defined(HIF_USB) |
| 1006 | /** |
| 1007 | * hif_ramdump_handler(): generic ramdump handler |
| 1008 | * @scn: struct hif_opaque_softc |
| 1009 | * |
| 1010 | * Return: None |
| 1011 | */ |
| 1012 | |
| 1013 | void hif_ramdump_handler(struct hif_opaque_softc *scn) |
| 1014 | |
| 1015 | { |
| 1016 | if (hif_get_bus_type == QDF_BUS_TYPE_USB) |
| 1017 | hif_usb_ramdump_handler(); |
| 1018 | } |
| 1019 | #endif |