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