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 | |
| 28 | #include <osdep.h> |
| 29 | #include "a_types.h" |
| 30 | #include "athdefs.h" |
| 31 | #include "osapi_linux.h" |
| 32 | #include "targcfg.h" |
| 33 | #include "cdf_lock.h" |
| 34 | #include "cdf_status.h" |
| 35 | #include <cdf_atomic.h> /* cdf_atomic_read */ |
| 36 | #include <targaddrs.h> |
| 37 | #include <bmi_msg.h> |
| 38 | #include "hif_io32.h" |
| 39 | #include <hif.h> |
| 40 | #include <htc_services.h> |
| 41 | #include "regtable.h" |
| 42 | #define ATH_MODULE_NAME hif |
| 43 | #include <a_debug.h> |
| 44 | #include "hif_main.h" |
| 45 | #include "hif_hw_version.h" |
| 46 | #include "ce_api.h" |
| 47 | #include "ce_tasklet.h" |
| 48 | #include "cdf_trace.h" |
| 49 | #include "cdf_status.h" |
| 50 | #include "cds_api.h" |
| 51 | #ifdef CONFIG_CNSS |
| 52 | #include <net/cnss.h> |
| 53 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 54 | #include "epping_main.h" |
| 55 | #include "hif_debug.h" |
| 56 | #include "mp_dev.h" |
| 57 | #ifdef HIF_PCI |
| 58 | #include "icnss_stub.h" |
| 59 | #else |
| 60 | #include <soc/qcom/icnss.h> |
| 61 | #endif |
| 62 | |
Chandrasekaran, Manishekar | 681d137 | 2015-11-05 10:42:48 +0530 | [diff] [blame] | 63 | #include "cds_concurrency.h" |
| 64 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 65 | #define AGC_DUMP 1 |
| 66 | #define CHANINFO_DUMP 2 |
| 67 | #define BB_WATCHDOG_DUMP 3 |
| 68 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 69 | #define PCIE_ACCESS_DUMP 4 |
| 70 | #endif |
| 71 | |
| 72 | void hif_dump(struct ol_softc *scn, uint8_t cmd_id, bool start) |
| 73 | { |
| 74 | switch (cmd_id) { |
| 75 | case AGC_DUMP: |
| 76 | if (start) |
| 77 | priv_start_agc(scn); |
| 78 | else |
| 79 | priv_dump_agc(scn); |
| 80 | break; |
| 81 | |
| 82 | case CHANINFO_DUMP: |
| 83 | if (start) |
| 84 | priv_start_cap_chaninfo(scn); |
| 85 | else |
| 86 | priv_dump_chaninfo(scn); |
| 87 | break; |
| 88 | |
| 89 | case BB_WATCHDOG_DUMP: |
| 90 | priv_dump_bbwatchdog(scn); |
| 91 | break; |
| 92 | |
| 93 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 94 | case PCIE_ACCESS_DUMP: |
| 95 | hif_target_dump_access_log(); |
| 96 | break; |
| 97 | #endif |
| 98 | default: |
| 99 | HIF_ERROR("%s: Invalid htc dump command", __func__); |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * hif_shut_down_device() - hif_shut_down_device |
| 106 | * |
| 107 | * SThis fucntion shuts down the device |
| 108 | * |
| 109 | * @scn: ol_softc |
| 110 | * |
| 111 | * Return: void |
| 112 | */ |
| 113 | void hif_shut_down_device(struct ol_softc *scn) |
| 114 | { |
| 115 | if (scn && scn->hif_hdl) { |
| 116 | struct HIF_CE_state *hif_state = |
| 117 | (struct HIF_CE_state *)scn->hif_hdl; |
| 118 | |
| 119 | hif_stop(scn); |
| 120 | cdf_mem_free(hif_state); |
| 121 | scn->hif_hdl = NULL; |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | /** |
| 129 | * hif_cancel_deferred_target_sleep() - cancel deferred target sleep |
| 130 | * |
| 131 | * This function cancels the defered target sleep |
| 132 | * |
| 133 | * @scn: ol_softc |
| 134 | * |
| 135 | * Return: void |
| 136 | */ |
| 137 | void hif_cancel_deferred_target_sleep(struct ol_softc *scn) |
| 138 | { |
| 139 | hif_pci_cancel_deferred_target_sleep(scn); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * hif_get_target_id(): hif_get_target_id |
| 144 | * |
| 145 | * Return the virtual memory base address to the caller |
| 146 | * |
| 147 | * @scn: ol_softc |
| 148 | * |
| 149 | * Return: A_target_id_t |
| 150 | */ |
| 151 | A_target_id_t hif_get_target_id(struct ol_softc *scn) |
| 152 | { |
| 153 | return scn->mem; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * hif_set_target_sleep(): hif_set_target_sleep |
| 158 | * @scn: scn |
| 159 | * @sleep_ok: sleep_ok |
| 160 | * @wait_for_it: wait |
| 161 | * |
| 162 | * Return: void |
| 163 | */ |
| 164 | void hif_set_target_sleep(struct ol_softc *scn, |
| 165 | bool sleep_ok, bool wait_for_it) |
| 166 | { |
| 167 | hif_target_sleep_state_adjust(scn, |
| 168 | sleep_ok, wait_for_it); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * hif_target_forced_awake(): hif_target_forced_awake |
| 173 | * @scn: scn |
| 174 | * |
| 175 | * Return: bool |
| 176 | */ |
| 177 | bool hif_target_forced_awake(struct ol_softc *scn) |
| 178 | { |
| 179 | A_target_id_t addr = scn->mem; |
| 180 | bool awake; |
| 181 | bool forced_awake; |
| 182 | |
| 183 | awake = hif_targ_is_awake(scn, addr); |
| 184 | |
| 185 | forced_awake = |
| 186 | !!(hif_read32_mb |
| 187 | (addr + PCIE_LOCAL_BASE_ADDRESS + |
| 188 | PCIE_SOC_WAKE_ADDRESS) & PCIE_SOC_WAKE_V_MASK); |
| 189 | |
| 190 | return awake && forced_awake; |
| 191 | } |
| 192 | |
Houston Hoffman | 0dad509 | 2015-09-28 16:25:51 -0700 | [diff] [blame] | 193 | |
| 194 | static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state) |
| 195 | { |
| 196 | struct hif_msg_callbacks *msg_callbacks = |
| 197 | &hif_state->msg_callbacks_current; |
| 198 | |
| 199 | if (!msg_callbacks->fwEventHandler) |
| 200 | return; |
| 201 | |
| 202 | msg_callbacks->fwEventHandler(msg_callbacks->Context, |
| 203 | CDF_STATUS_E_FAILURE); |
| 204 | } |
| 205 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 206 | /** |
| 207 | * hif_fw_interrupt_handler(): FW interrupt handler |
| 208 | * |
| 209 | * This function is the FW interrupt handlder |
| 210 | * |
| 211 | * @irq: irq number |
| 212 | * @arg: the user pointer |
| 213 | * |
| 214 | * Return: bool |
| 215 | */ |
| 216 | #ifndef QCA_WIFI_3_0 |
| 217 | irqreturn_t hif_fw_interrupt_handler(int irq, void *arg) |
| 218 | { |
| 219 | struct ol_softc *scn = arg; |
| 220 | struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl; |
| 221 | uint32_t fw_indicator_address, fw_indicator; |
| 222 | |
| 223 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 224 | |
| 225 | fw_indicator_address = hif_state->fw_indicator_address; |
| 226 | /* For sudden unplug this will return ~0 */ |
| 227 | fw_indicator = A_TARGET_READ(scn, fw_indicator_address); |
| 228 | |
| 229 | if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) { |
| 230 | /* ACK: clear Target-side pending event */ |
| 231 | A_TARGET_WRITE(scn, fw_indicator_address, |
| 232 | fw_indicator & ~FW_IND_EVENT_PENDING); |
| 233 | A_TARGET_ACCESS_END_RET(scn); |
| 234 | |
| 235 | if (hif_state->started) { |
Houston Hoffman | 0dad509 | 2015-09-28 16:25:51 -0700 | [diff] [blame] | 236 | hif_fw_event_handler(hif_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 237 | } else { |
| 238 | /* |
| 239 | * Probable Target failure before we're prepared |
| 240 | * to handle it. Generally unexpected. |
| 241 | */ |
| 242 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 243 | ("%s: Early firmware event indicated\n", |
| 244 | __func__)); |
| 245 | } |
| 246 | } else { |
| 247 | A_TARGET_ACCESS_END_RET(scn); |
| 248 | } |
| 249 | |
| 250 | return ATH_ISR_SCHED; |
| 251 | } |
| 252 | #else |
| 253 | irqreturn_t hif_fw_interrupt_handler(int irq, void *arg) |
| 254 | { |
| 255 | return ATH_ISR_SCHED; |
| 256 | } |
| 257 | #endif /* #ifdef QCA_WIFI_3_0 */ |
| 258 | |
| 259 | /** |
| 260 | * hif_get_targetdef(): hif_get_targetdef |
| 261 | * @scn: scn |
| 262 | * |
| 263 | * Return: void * |
| 264 | */ |
| 265 | void *hif_get_targetdef(struct ol_softc *scn) |
| 266 | { |
| 267 | return scn->targetdef; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * hif_vote_link_down(): unvote for link up |
| 272 | * |
| 273 | * Call hif_vote_link_down to release a previous request made using |
| 274 | * hif_vote_link_up. A hif_vote_link_down call should only be made |
| 275 | * after a corresponding hif_vote_link_up, otherwise you could be |
| 276 | * negating a vote from another source. When no votes are present |
| 277 | * hif will not guarantee the linkstate after hif_bus_suspend. |
| 278 | * |
| 279 | * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread |
| 280 | * and initialization deinitialization sequencences. |
| 281 | * |
| 282 | * Return: n/a |
| 283 | */ |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 284 | void hif_vote_link_down(void *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 285 | { |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 286 | struct ol_softc *scn = hif_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 287 | CDF_BUG(scn); |
| 288 | |
| 289 | scn->linkstate_vote--; |
| 290 | if (scn->linkstate_vote == 0) |
Houston Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 291 | hif_bus_prevent_linkdown(scn, false); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * hif_vote_link_up(): vote to prevent bus from suspending |
| 296 | * |
| 297 | * Makes hif guarantee that fw can message the host normally |
| 298 | * durring suspend. |
| 299 | * |
| 300 | * SYNCHRONIZE WITH hif_vote_link_up by only calling in MC thread |
| 301 | * and initialization deinitialization sequencences. |
| 302 | * |
| 303 | * Return: n/a |
| 304 | */ |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 305 | void hif_vote_link_up(void *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 306 | { |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 307 | struct ol_softc *scn = hif_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 308 | CDF_BUG(scn); |
| 309 | |
| 310 | scn->linkstate_vote++; |
| 311 | if (scn->linkstate_vote == 1) |
Houston Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 312 | hif_bus_prevent_linkdown(scn, true); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
| 316 | * hif_can_suspend_link(): query if hif is permitted to suspend the link |
| 317 | * |
| 318 | * Hif will ensure that the link won't be suspended if the upperlayers |
| 319 | * don't want it to. |
| 320 | * |
| 321 | * SYNCHRONIZATION: MC thread is stopped before bus suspend thus |
| 322 | * we don't need extra locking to ensure votes dont change while |
| 323 | * we are in the process of suspending or resuming. |
| 324 | * |
| 325 | * Return: false if hif will guarantee link up durring suspend. |
| 326 | */ |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 327 | bool hif_can_suspend_link(void *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 328 | { |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 329 | struct ol_softc *scn = hif_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 330 | CDF_BUG(scn); |
| 331 | |
| 332 | return scn->linkstate_vote == 0; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * hif_hia_item_address(): hif_hia_item_address |
| 337 | * @target_type: target_type |
| 338 | * @item_offset: item_offset |
| 339 | * |
| 340 | * Return: n/a |
| 341 | */ |
| 342 | uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset) |
| 343 | { |
| 344 | switch (target_type) { |
| 345 | case TARGET_TYPE_AR6002: |
| 346 | return AR6002_HOST_INTEREST_ADDRESS + item_offset; |
| 347 | case TARGET_TYPE_AR6003: |
| 348 | return AR6003_HOST_INTEREST_ADDRESS + item_offset; |
| 349 | case TARGET_TYPE_AR6004: |
| 350 | return AR6004_HOST_INTEREST_ADDRESS + item_offset; |
| 351 | case TARGET_TYPE_AR6006: |
| 352 | return AR6006_HOST_INTEREST_ADDRESS + item_offset; |
| 353 | case TARGET_TYPE_AR9888: |
| 354 | return AR9888_HOST_INTEREST_ADDRESS + item_offset; |
| 355 | case TARGET_TYPE_AR6320: |
| 356 | case TARGET_TYPE_AR6320V2: |
| 357 | return AR6320_HOST_INTEREST_ADDRESS + item_offset; |
| 358 | case TARGET_TYPE_QCA6180: |
| 359 | return QCA6180_HOST_INTEREST_ADDRESS + item_offset; |
| 360 | case TARGET_TYPE_ADRASTEA: |
| 361 | /* ADRASTEA doesn't have a host interest address */ |
| 362 | ASSERT(0); |
| 363 | return 0; |
| 364 | default: |
| 365 | ASSERT(0); |
| 366 | return 0; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * hif_max_num_receives_reached() - check max receive is reached |
| 372 | * @count: unsigned int. |
| 373 | * |
| 374 | * Output check status as bool |
| 375 | * |
| 376 | * Return: bool |
| 377 | */ |
| 378 | bool hif_max_num_receives_reached(unsigned int count) |
| 379 | { |
| 380 | if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) |
| 381 | return count > 120; |
| 382 | else |
| 383 | return count > MAX_NUM_OF_RECEIVES; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * init_buffer_count() - initial buffer count |
| 388 | * @maxSize: cdf_size_t |
| 389 | * |
| 390 | * routine to modify the initial buffer count to be allocated on an os |
| 391 | * platform basis. Platform owner will need to modify this as needed |
| 392 | * |
| 393 | * Return: cdf_size_t |
| 394 | */ |
| 395 | cdf_size_t init_buffer_count(cdf_size_t maxSize) |
| 396 | { |
| 397 | return maxSize; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * hif_init_cdf_ctx(): hif_init_cdf_ctx |
| 402 | * @hif_ctx: hif_ctx |
| 403 | * |
| 404 | * Return: int |
| 405 | */ |
| 406 | int hif_init_cdf_ctx(void *hif_ctx) |
| 407 | { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 408 | struct ol_softc *scn = (struct ol_softc *)hif_ctx; |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 409 | cdf_device_t cdf_ctx = scn->cdf_dev; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 410 | |
| 411 | cdf_ctx->drv = &scn->aps_osdev; |
| 412 | cdf_ctx->drv_hdl = scn->aps_osdev.bdev; |
| 413 | cdf_ctx->dev = scn->aps_osdev.device; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * hif_deinit_cdf_ctx(): hif_deinit_cdf_ctx |
| 419 | * @hif_ctx: hif_ctx |
| 420 | * |
| 421 | * Return: void |
| 422 | */ |
| 423 | void hif_deinit_cdf_ctx(void *hif_ctx) |
| 424 | { |
| 425 | struct ol_softc *scn = (struct ol_softc *)hif_ctx; |
| 426 | |
| 427 | if (scn == NULL || !scn->cdf_dev) |
| 428 | return; |
| 429 | scn->cdf_dev = NULL; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * hif_save_htc_htt_config_endpoint(): |
| 434 | * hif_save_htc_htt_config_endpoint |
| 435 | * @htc_endpoint: htc_endpoint |
| 436 | * |
| 437 | * Return: void |
| 438 | */ |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 439 | void hif_save_htc_htt_config_endpoint(void *hif_ctx, int htc_endpoint) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 440 | { |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 441 | struct ol_softc *scn = hif_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 442 | |
| 443 | if (!scn) { |
| 444 | HIF_ERROR("%s: error: scn or scn->hif_sc is NULL!", |
| 445 | __func__); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | scn->htc_endpoint = htc_endpoint; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * hif_get_hw_name(): get a human readable name for the hardware |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 454 | * @info: Target Info |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 455 | * |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 456 | * Return: human readable name for the underlying wifi hardware. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 457 | */ |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 458 | static const char *hif_get_hw_name(struct hif_target_info *info) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 459 | { |
| 460 | int i; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 461 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 462 | for (i = 0; i < ARRAY_SIZE(qwlan_hw_list); i++) { |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 463 | if (info->target_version == qwlan_hw_list[i].id && |
| 464 | info->target_revision == qwlan_hw_list[i].subid) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 465 | return qwlan_hw_list[i].name; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | return "Unknown Device"; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * hif_get_hw_info(): hif_get_hw_info |
| 474 | * @scn: scn |
| 475 | * @version: version |
| 476 | * @revision: revision |
| 477 | * |
| 478 | * Return: n/a |
| 479 | */ |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 480 | void hif_get_hw_info(struct ol_softc *scn, u32 *version, u32 *revision, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 481 | const char **target_name) |
| 482 | { |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 483 | struct hif_target_info *info = hif_get_target_info_handle(scn); |
| 484 | *version = info->target_version; |
| 485 | *revision = info->target_revision; |
| 486 | *target_name = hif_get_hw_name(info); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
| 490 | * hif_open(): hif_open |
| 491 | * |
| 492 | * Return: scn |
| 493 | */ |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 494 | CDF_STATUS hif_open(cdf_device_t cdf_ctx, enum ath_hal_bus_type bus_type) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 495 | { |
| 496 | struct ol_softc *scn; |
| 497 | v_CONTEXT_t cds_context; |
| 498 | CDF_STATUS status = CDF_STATUS_SUCCESS; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 499 | struct hif_config_info *cfg; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 500 | |
| 501 | cds_context = cds_get_global_context(); |
| 502 | status = cds_alloc_context(cds_context, CDF_MODULE_ID_HIF, |
| 503 | (void **)&scn, sizeof(*scn)); |
| 504 | if (status != CDF_STATUS_SUCCESS) { |
| 505 | HIF_ERROR("%s: cannot alloc ol_sc", __func__); |
| 506 | return status; |
| 507 | } |
| 508 | |
| 509 | cdf_mem_zero(scn, sizeof(*scn)); |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 510 | scn->cdf_dev = cdf_ctx; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 511 | cfg = hif_get_ini_handle(scn); |
| 512 | cfg->max_no_of_peers = 1; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 513 | cdf_atomic_init(&scn->wow_done); |
| 514 | cdf_atomic_init(&scn->active_tasklet_cnt); |
| 515 | cdf_atomic_init(&scn->link_suspended); |
| 516 | cdf_atomic_init(&scn->tasklet_from_intr); |
| 517 | init_waitqueue_head(&scn->aps_osdev.event_queue); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 518 | scn->linkstate_vote = 0; |
Houston Hoffman | 3cfe686 | 2016-01-08 10:33:55 -0800 | [diff] [blame] | 519 | |
| 520 | status = hif_bus_open(scn, bus_type); |
| 521 | if (status != CDF_STATUS_SUCCESS) { |
| 522 | HIF_ERROR("%s: hif_bus_open error = %d, bus_type = %d", |
| 523 | __func__, status, bus_type); |
| 524 | cds_free_context(cds_context, CDF_MODULE_ID_HIF, scn); |
| 525 | } |
| 526 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 527 | return status; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * hif_close(): hif_close |
| 532 | * @hif_ctx: hif_ctx |
| 533 | * |
| 534 | * Return: n/a |
| 535 | */ |
| 536 | void hif_close(void *hif_ctx) |
| 537 | { |
| 538 | struct ol_softc *scn = hif_ctx; |
| 539 | |
| 540 | if (scn == NULL) { |
| 541 | HIF_ERROR("%s: ol_softc is NULL", __func__); |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | if (scn->athdiag_procfs_inited) { |
| 546 | athdiag_procfs_remove(); |
| 547 | scn->athdiag_procfs_inited = false; |
| 548 | } |
| 549 | |
| 550 | if (scn->hif_hdl) { |
| 551 | cdf_mem_free(scn->hif_hdl); |
| 552 | scn->hif_hdl = NULL; |
| 553 | } |
| 554 | hif_bus_close(scn); |
| 555 | cds_free_context(cds_get_global_context(), |
| 556 | CDF_MODULE_ID_HIF, hif_ctx); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * hif_enable(): hif_enable |
| 561 | * @hif_ctx: hif_ctx |
| 562 | * @dev: dev |
| 563 | * @bdev: bus dev |
| 564 | * @bid: bus ID |
| 565 | * @bus_type: bus type |
| 566 | * @type: enable type |
| 567 | * |
| 568 | * Return: CDF_STATUS |
| 569 | */ |
| 570 | CDF_STATUS hif_enable(void *hif_ctx, struct device *dev, |
| 571 | void *bdev, const hif_bus_id *bid, |
| 572 | enum ath_hal_bus_type bus_type, |
| 573 | enum hif_enable_type type) |
| 574 | { |
| 575 | CDF_STATUS status; |
| 576 | struct ol_softc *scn = hif_ctx; |
| 577 | |
| 578 | if (scn == NULL) { |
| 579 | HIF_ERROR("%s: hif_ctx = NULL", __func__); |
| 580 | return CDF_STATUS_E_NULL_VALUE; |
| 581 | } |
| 582 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 583 | status = hif_enable_bus(scn, dev, bdev, bid, type); |
| 584 | if (status != CDF_STATUS_SUCCESS) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 585 | HIF_ERROR("%s: hif_enable_bus error = %d", |
| 586 | __func__, status); |
| 587 | return status; |
| 588 | } |
| 589 | |
| 590 | if (ADRASTEA_BU) |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 591 | hif_vote_link_up(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 592 | |
| 593 | if (hif_config_ce(scn)) { |
| 594 | HIF_ERROR("%s: Target probe failed.", __func__); |
| 595 | hif_disable_bus(scn->aps_osdev.bdev); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 596 | status = CDF_STATUS_E_FAILURE; |
| 597 | return status; |
| 598 | } |
| 599 | /* |
| 600 | * Flag to avoid potential unallocated memory access from MSI |
| 601 | * interrupt handler which could get scheduled as soon as MSI |
| 602 | * is enabled, i.e to take care of the race due to the order |
| 603 | * in where MSI is enabled before the memory, that will be |
| 604 | * in interrupt handlers, is allocated. |
| 605 | */ |
| 606 | |
| 607 | #ifdef HIF_PCI |
| 608 | status = hif_configure_irq(scn->hif_sc); |
| 609 | if (status < 0) { |
| 610 | HIF_ERROR("%s: ERROR - configure_IRQ_and_CE failed, status = %d", |
| 611 | __func__, status); |
| 612 | return CDF_STATUS_E_FAILURE; |
| 613 | } |
| 614 | #endif |
| 615 | |
| 616 | scn->hif_init_done = true; |
| 617 | |
| 618 | HIF_TRACE("%s: X OK", __func__); |
| 619 | |
| 620 | return CDF_STATUS_SUCCESS; |
| 621 | } |
| 622 | |
| 623 | /** |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 624 | * hif_wlan_disable(): call the platform driver to disable wlan |
| 625 | * |
| 626 | * This function passes the con_mode to platform driver to disable |
| 627 | * wlan. |
| 628 | * |
| 629 | * Return: void |
| 630 | */ |
| 631 | void hif_wlan_disable(void) |
| 632 | { |
| 633 | enum icnss_driver_mode mode; |
| 634 | uint32_t con_mode = cds_get_conparam(); |
| 635 | |
Peng Xu | 7b96253 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 636 | if (CDF_GLOBAL_FTM_MODE == con_mode) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 637 | mode = ICNSS_FTM; |
Peng Xu | 7b96253 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 638 | else if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 639 | mode = ICNSS_EPPING; |
Peng Xu | 7b96253 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 640 | else |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 641 | mode = ICNSS_MISSION; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 642 | |
| 643 | icnss_wlan_disable(mode); |
| 644 | } |
| 645 | |
| 646 | void hif_disable(void *hif_ctx, enum hif_disable_type type) |
| 647 | { |
| 648 | struct ol_softc *scn = hif_ctx; |
| 649 | |
| 650 | if (!scn) |
| 651 | return; |
| 652 | |
| 653 | hif_nointrs(scn); |
| 654 | if (scn->hif_init_done == false) |
| 655 | hif_shut_down_device(scn); |
| 656 | else |
| 657 | hif_stop(scn); |
| 658 | |
| 659 | if (ADRASTEA_BU) |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame] | 660 | hif_vote_link_down(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 661 | |
| 662 | if (scn->aps_osdev.bdev) |
| 663 | hif_disable_bus(scn->aps_osdev.bdev); |
| 664 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 665 | hif_wlan_disable(); |
| 666 | |
| 667 | scn->notice_send = false; |
| 668 | |
| 669 | HIF_INFO("%s: X", __func__); |
| 670 | } |
| 671 | |
| 672 | |
| 673 | /** |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 674 | * hif_crash_shutdown_dump_bus_register() - dump bus registers |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 675 | * @hif_ctx: hif_ctx |
| 676 | * |
| 677 | * Return: n/a |
| 678 | */ |
| 679 | #if defined(TARGET_RAMDUMP_AFTER_KERNEL_PANIC) \ |
| 680 | && defined(HIF_PCI) && defined(DEBUG) |
| 681 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 682 | static void hif_crash_shutdown_dump_bus_register(void *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 683 | { |
| 684 | struct ol_softc *scn = hif_ctx; |
| 685 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 686 | if (hif_check_soc_status(scn)) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 687 | return; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 688 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 689 | if (hif_dump_registers(scn)) |
| 690 | HIF_ERROR("Failed to dump bus registers!"); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /** |
| 694 | * hif_crash_shutdown(): hif_crash_shutdown |
| 695 | * |
| 696 | * This function is called by the platform driver to dump CE registers |
| 697 | * |
| 698 | * @hif_ctx: hif_ctx |
| 699 | * |
| 700 | * Return: n/a |
| 701 | */ |
| 702 | void hif_crash_shutdown(void *hif_ctx) |
| 703 | { |
| 704 | struct ol_softc *scn = hif_ctx; |
| 705 | struct HIF_CE_state *hif_state; |
| 706 | |
| 707 | if (!scn) |
| 708 | return; |
| 709 | |
| 710 | hif_state = (struct HIF_CE_state *)scn->hif_hdl; |
| 711 | if (!hif_state) |
| 712 | return; |
| 713 | |
| 714 | |
| 715 | if (OL_TRGET_STATUS_RESET == scn->target_status) { |
| 716 | HIF_INFO_MED("%s: Target is already asserted, ignore!", |
| 717 | __func__); |
| 718 | return; |
| 719 | } |
| 720 | |
Rajeev Kumar | e3b4b4b | 2016-01-19 15:23:52 -0800 | [diff] [blame] | 721 | if (cds_is_load_or_unload_in_progress()) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 722 | HIF_ERROR("%s: Load/unload is in progress, ignore!", __func__); |
| 723 | return; |
| 724 | } |
| 725 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 726 | hif_crash_shutdown_dump_bus_register(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 727 | |
| 728 | if (ol_copy_ramdump(scn)) |
| 729 | goto out; |
| 730 | |
| 731 | HIF_INFO_MED("%s: RAM dump collecting completed!", __func__); |
| 732 | |
| 733 | out: |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 734 | return; |
| 735 | } |
| 736 | #else |
| 737 | void hif_crash_shutdown(void *hif_ctx) |
| 738 | { |
| 739 | HIF_INFO_MED("%s: Collecting target RAM dump disabled", |
| 740 | __func__); |
| 741 | return; |
| 742 | } |
| 743 | #endif /* TARGET_RAMDUMP_AFTER_KERNEL_PANIC */ |
| 744 | |
| 745 | #ifdef QCA_WIFI_3_0 |
| 746 | /** |
| 747 | * hif_check_fw_reg(): hif_check_fw_reg |
| 748 | * @scn: scn |
| 749 | * @state: |
| 750 | * |
| 751 | * Return: int |
| 752 | */ |
| 753 | int hif_check_fw_reg(struct ol_softc *scn) |
| 754 | { |
| 755 | return 0; |
| 756 | } |
| 757 | #endif |
| 758 | |
| 759 | #ifdef IPA_OFFLOAD |
| 760 | /** |
| 761 | * hif_read_phy_mem_base(): hif_read_phy_mem_base |
| 762 | * @scn: scn |
| 763 | * @phy_mem_base: physical mem base |
| 764 | * |
| 765 | * Return: n/a |
| 766 | */ |
| 767 | void hif_read_phy_mem_base(struct ol_softc *scn, cdf_dma_addr_t *phy_mem_base) |
| 768 | { |
| 769 | *phy_mem_base = scn->mem_pa; |
| 770 | } |
| 771 | #endif /* IPA_OFFLOAD */ |
| 772 | |
| 773 | /** |
| 774 | * hif_get_device_type(): hif_get_device_type |
| 775 | * @device_id: device_id |
| 776 | * @revision_id: revision_id |
| 777 | * @hif_type: returned hif_type |
| 778 | * @target_type: returned target_type |
| 779 | * |
| 780 | * Return: int |
| 781 | */ |
| 782 | int hif_get_device_type(uint32_t device_id, |
| 783 | uint32_t revision_id, |
| 784 | uint32_t *hif_type, uint32_t *target_type) |
| 785 | { |
| 786 | int ret = 0; |
| 787 | |
| 788 | switch (device_id) { |
| 789 | #ifdef QCA_WIFI_3_0_ADRASTEA |
| 790 | case ADRASTEA_DEVICE_ID: |
| 791 | case ADRASTEA_DEVICE_ID_P2_E12: |
| 792 | |
| 793 | *hif_type = HIF_TYPE_ADRASTEA; |
| 794 | *target_type = TARGET_TYPE_ADRASTEA; |
| 795 | break; |
| 796 | #else |
| 797 | case QCA6180_DEVICE_ID: |
| 798 | *hif_type = HIF_TYPE_QCA6180; |
| 799 | *target_type = TARGET_TYPE_QCA6180; |
| 800 | break; |
| 801 | #endif |
| 802 | |
| 803 | case AR9888_DEVICE_ID: |
| 804 | *hif_type = HIF_TYPE_AR9888; |
| 805 | *target_type = TARGET_TYPE_AR9888; |
| 806 | break; |
| 807 | |
| 808 | case AR6320_DEVICE_ID: |
| 809 | switch (revision_id) { |
| 810 | case AR6320_FW_1_1: |
| 811 | case AR6320_FW_1_3: |
| 812 | *hif_type = HIF_TYPE_AR6320; |
| 813 | *target_type = TARGET_TYPE_AR6320; |
| 814 | break; |
| 815 | |
| 816 | case AR6320_FW_2_0: |
| 817 | case AR6320_FW_3_0: |
| 818 | case AR6320_FW_3_2: |
| 819 | *hif_type = HIF_TYPE_AR6320V2; |
| 820 | *target_type = TARGET_TYPE_AR6320V2; |
| 821 | break; |
| 822 | |
| 823 | default: |
| 824 | HIF_ERROR("%s: error - dev_id = 0x%x, rev_id = 0x%x", |
| 825 | __func__, device_id, revision_id); |
| 826 | ret = -ENODEV; |
| 827 | goto end; |
| 828 | } |
| 829 | break; |
| 830 | |
| 831 | default: |
| 832 | HIF_ERROR("%s: Unsupported device ID!", __func__); |
| 833 | ret = -ENODEV; |
| 834 | break; |
| 835 | } |
| 836 | end: |
| 837 | return ret; |
| 838 | } |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 839 | |
| 840 | /** |
| 841 | * Target info and ini parameters are global to the driver |
| 842 | * Hence these structures are exposed to all the modules in |
| 843 | * the driver and they don't need to maintains multiple copies |
| 844 | * of the same info, instead get the handle from hif and |
| 845 | * modify them in hif |
| 846 | */ |
| 847 | |
| 848 | /** |
| 849 | * hif_get_ini_handle() - API to get hif_config_param handle |
| 850 | * @scn: HIF Context |
| 851 | * |
| 852 | * Return: pointer to hif_config_info |
| 853 | */ |
| 854 | struct hif_config_info *hif_get_ini_handle(struct ol_softc *scn) |
| 855 | { |
| 856 | return &scn->hif_config; |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * hif_get_target_info_handle() - API to get hif_target_info handle |
| 861 | * @scn: HIF context |
| 862 | * |
| 863 | * Return: Pointer to hif_target_info |
| 864 | */ |
| 865 | struct hif_target_info *hif_get_target_info_handle(struct ol_softc *scn) |
| 866 | { |
| 867 | return &scn->target_info; |
| 868 | } |
Komal Seelam | c92a0cf | 2016-02-22 20:43:52 +0530 | [diff] [blame^] | 869 | |
| 870 | #if defined(FEATURE_LRO) |
| 871 | /** |
| 872 | * hif_lro_flush_cb_register - API to register for LRO Flush Callback |
| 873 | * @scn: HIF Context |
| 874 | * @handler: Function pointer to be called by HIF |
| 875 | * @data: Private data to be used by the module registering to HIF |
| 876 | * |
| 877 | * Return: void |
| 878 | */ |
| 879 | void hif_lro_flush_cb_register(struct ol_softc *scn, |
| 880 | void (handler)(void *), void *data) |
| 881 | { |
| 882 | ce_lro_flush_cb_register(scn, handler, data); |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * hif_lro_flush_cb_deregister - API to deregister for LRO Flush Callbacks |
| 887 | * @scn: HIF Context |
| 888 | * |
| 889 | * Return: void |
| 890 | */ |
| 891 | void hif_lro_flush_cb_deregister(struct ol_softc *scn) |
| 892 | { |
| 893 | ce_lro_flush_cb_deregister(scn); |
| 894 | } |
| 895 | #endif |