Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Govind Singh | 0a60e55 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -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 | * Internal BMI Header File |
| 29 | */ |
| 30 | |
| 31 | #ifndef _I_BMI_H_ |
| 32 | #define _I_BMI_H_ |
| 33 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 34 | #include "hif.h" |
| 35 | #include "bmi_msg.h" |
| 36 | #include "bmi.h" |
| 37 | #include "ol_fw.h" |
Yuanyuan Liu | eaa6b6e | 2016-04-26 12:40:26 -0700 | [diff] [blame] | 38 | #include "pld_common.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 39 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 40 | /* |
| 41 | * Note that not all the register locations are accessible. |
| 42 | * A list of accessible target registers are specified with |
| 43 | * their start and end addresses in a table for given target |
| 44 | * version. We should NOT access other locations as either |
| 45 | * they are invalid locations or host does not have read |
| 46 | * access to it or the value of the particular register |
| 47 | * read might change |
| 48 | */ |
| 49 | #define REGISTER_LOCATION 0x00000800 |
| 50 | |
| 51 | #define DRAM_LOCATION 0x00400000 |
| 52 | #define DRAM_SIZE 0x000a8000 |
| 53 | /* The local base addr is used to read the target dump using pcie I/O reads */ |
| 54 | #define DRAM_LOCAL_BASE_ADDR (0x100000) |
| 55 | |
| 56 | #define IRAM_LOCATION 0x00980000 |
| 57 | #define IRAM_SIZE 0x00038000 |
| 58 | |
| 59 | #define AXI_LOCATION 0x000a0000 |
| 60 | #define AXI_SIZE 0x00018000 |
| 61 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 62 | #define TOTAL_DUMP_SIZE 0x00200000 |
| 63 | #define PCIE_READ_LIMIT 0x00005000 |
| 64 | |
| 65 | #define SHA256_DIGEST_SIZE 32 |
| 66 | |
| 67 | /* BMI LOGGING WRAPPERS */ |
| 68 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 69 | #define BMI_LOG(level, args...) QDF_TRACE(QDF_MODULE_ID_BMI, \ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 70 | level, ##args) |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 71 | #define BMI_ERR(args ...) BMI_LOG(QDF_TRACE_LEVEL_ERROR, args) |
| 72 | #define BMI_DBG(args ...) BMI_LOG(QDF_TRACE_LEVEL_DEBUG, args) |
| 73 | #define BMI_WARN(args ...) BMI_LOG(QDF_TRACE_LEVEL_WARN, args) |
| 74 | #define BMI_INFO(args ...) BMI_LOG(QDF_TRACE_LEVEL_INFO, args) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 75 | /* End of BMI Logging Wrappers */ |
| 76 | |
| 77 | /* BMI Assert Wrappers */ |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 78 | #define bmi_assert QDF_BUG |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 79 | /* |
| 80 | * Although we had envisioned BMI to run on top of HTC, this is not how the |
| 81 | * final implementation ended up. On the Target side, BMI is a part of the BSP |
| 82 | * and does not use the HTC protocol nor even DMA -- it is intentionally kept |
| 83 | * very simple. |
| 84 | */ |
| 85 | |
| 86 | #define MAX_BMI_CMDBUF_SZ (BMI_DATASZ_MAX + \ |
| 87 | sizeof(uint32_t) /* cmd */ + \ |
| 88 | sizeof(uint32_t) /* addr */ + \ |
| 89 | sizeof(uint32_t)) /* length */ |
| 90 | #define BMI_COMMAND_FITS(sz) ((sz) <= MAX_BMI_CMDBUF_SZ) |
| 91 | #define BMI_EXCHANGE_TIMEOUT_MS 1000 |
| 92 | |
| 93 | struct hash_fw { |
| 94 | u8 qwlan[SHA256_DIGEST_SIZE]; |
| 95 | u8 otp[SHA256_DIGEST_SIZE]; |
| 96 | u8 bdwlan[SHA256_DIGEST_SIZE]; |
| 97 | u8 utf[SHA256_DIGEST_SIZE]; |
| 98 | }; |
| 99 | |
| 100 | typedef enum _ATH_BIN_FILE { |
| 101 | ATH_OTP_FILE, |
| 102 | ATH_FIRMWARE_FILE, |
| 103 | ATH_PATCH_FILE, |
| 104 | ATH_BOARD_DATA_FILE, |
| 105 | ATH_FLASH_FILE, |
| 106 | ATH_SETUP_FILE, |
| 107 | } ATH_BIN_FILE; |
| 108 | |
Houston Hoffman | 6ccc86a | 2015-12-16 18:43:34 -0800 | [diff] [blame] | 109 | #if defined(QCA_WIFI_3_0_ADRASTEA) |
| 110 | #define NO_BMI 1 |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 111 | #else |
Houston Hoffman | 6ccc86a | 2015-12-16 18:43:34 -0800 | [diff] [blame] | 112 | #define NO_BMI 0 |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 113 | #endif |
| 114 | |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 115 | /** |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 116 | * struct bmi_info - Structure to hold BMI Specific information |
| 117 | * @bmi_cmd_buff - BMI Command Buffer |
| 118 | * @bmi_rsp_buff - BMI Response Buffer |
| 119 | * @bmi_cmd_da - BMI Command Physical address |
| 120 | * @bmi_rsp_da - BMI Response Physical address |
| 121 | * @bmi_done - Flag to check if BMI Phase is complete |
| 122 | * @fw_files - FW files |
| 123 | * |
| 124 | */ |
| 125 | struct bmi_info { |
| 126 | uint8_t *bmi_cmd_buff; |
| 127 | uint8_t *bmi_rsp_buff; |
| 128 | dma_addr_t bmi_cmd_da; |
| 129 | dma_addr_t bmi_rsp_da; |
| 130 | bool bmi_done; |
Yuanyuan Liu | eaa6b6e | 2016-04-26 12:40:26 -0700 | [diff] [blame] | 131 | struct pld_fw_files fw_files; |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /** |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 135 | * struct ol_context - Structure to hold OL context |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 136 | * @bmi: BMI info |
| 137 | * @cal_in_flash: For Firmware Flash Download |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 138 | * @qdf_dev: QDF Device |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 139 | * @scn: HIF Context |
Yuanyuan Liu | eaa6b6e | 2016-04-26 12:40:26 -0700 | [diff] [blame] | 140 | * @ramdump_work: Work for Ramdump collection |
| 141 | * @fw_indication_work: Work for Fw inciation |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 142 | * @tgt_def: Target Defnition pointer |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 143 | * |
| 144 | * Structure to hold all ol BMI/Ramdump info |
| 145 | */ |
| 146 | struct ol_context { |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 147 | struct bmi_info bmi; |
Komal Seelam | ec702b0 | 2016-02-24 18:42:16 +0530 | [diff] [blame] | 148 | struct ol_config_info cfg_info; |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 149 | uint8_t *cal_in_flash; |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 150 | qdf_device_t qdf_dev; |
Anurag Chouhan | df2b268 | 2016-02-29 14:15:27 +0530 | [diff] [blame] | 151 | qdf_work_t ramdump_work; |
Yuanyuan Liu | eaa6b6e | 2016-04-26 12:40:26 -0700 | [diff] [blame] | 152 | qdf_work_t fw_indication_work; |
Komal Seelam | 3d20286 | 2016-02-24 18:43:24 +0530 | [diff] [blame] | 153 | struct hif_opaque_softc *scn; |
Komal Seelam | 42c16a1 | 2016-02-16 18:09:10 +0530 | [diff] [blame] | 154 | struct targetdef_t { |
| 155 | struct targetdef_s *targetdef; |
| 156 | } tgt_def; |
Komal Seelam | d910649 | 2016-02-15 10:31:44 +0530 | [diff] [blame] | 157 | }; |
| 158 | |
Komal Seelam | 9ef9458 | 2016-02-24 18:14:55 +0530 | [diff] [blame] | 159 | #define GET_BMI_CONTEXT(ol_ctx) ((struct bmi_info *)ol_ctx) |
| 160 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 161 | QDF_STATUS bmi_execute(uint32_t address, uint32_t *param, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 162 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 163 | QDF_STATUS bmi_init(struct ol_context *ol_ctx); |
| 164 | QDF_STATUS bmi_no_command(struct ol_context *ol_ctx); |
| 165 | QDF_STATUS bmi_read_memory(uint32_t address, uint8_t *buffer, uint32_t length, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 166 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 167 | QDF_STATUS bmi_write_memory(uint32_t address, uint8_t *buffer, uint32_t length, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 168 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 169 | QDF_STATUS bmi_fast_download(uint32_t address, uint8_t *buffer, uint32_t length, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 170 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 171 | QDF_STATUS bmi_read_soc_register(uint32_t address, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 172 | uint32_t *param, struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 173 | QDF_STATUS bmi_write_soc_register(uint32_t address, uint32_t param, |
Komal Seelam | 5a6e508 | 2016-02-24 17:59:09 +0530 | [diff] [blame] | 174 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 175 | QDF_STATUS bmi_get_target_info(struct bmi_target_info *targ_info, |
Komal Seelam | 0863349 | 2016-02-24 18:05:07 +0530 | [diff] [blame] | 176 | struct ol_context *ol_ctx); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 177 | QDF_STATUS bmi_firmware_download(struct ol_context *ol_ctx); |
| 178 | QDF_STATUS bmi_done_local(struct ol_context *ol_ctx); |
| 179 | QDF_STATUS ol_download_firmware(struct ol_context *ol_ctx); |
| 180 | QDF_STATUS ol_configure_target(struct ol_context *ol_ctx); |
Houston Hoffman | ea4c79c | 2016-04-21 20:20:31 -0700 | [diff] [blame] | 181 | QDF_STATUS bmi_sign_stream_start(uint32_t address, uint8_t *buffer, |
| 182 | uint32_t length, struct ol_context *ol_ctx); |
Komal Seelam | 0863349 | 2016-02-24 18:05:07 +0530 | [diff] [blame] | 183 | void ramdump_work_handler(void *arg); |
Yuanyuan Liu | eaa6b6e | 2016-04-26 12:40:26 -0700 | [diff] [blame] | 184 | void fw_indication_work_handler(void *arg); |
Komal Seelam | ec702b0 | 2016-02-24 18:42:16 +0530 | [diff] [blame] | 185 | struct ol_config_info *ol_get_ini_handle(struct ol_context *ol_ctx); |
Poddar, Siddarth | ef1f302 | 2016-05-10 20:10:43 +0530 | [diff] [blame^] | 186 | |
| 187 | #ifdef HIF_SDIO |
| 188 | QDF_STATUS hif_reg_based_get_target_info(struct hif_opaque_softc *hif_ctx, |
| 189 | struct bmi_target_info *targ_info); |
| 190 | #endif |
| 191 | #if defined(HIF_PCI) || defined(SNOC) || defined(HIF_AHB) |
| 192 | static inline QDF_STATUS |
| 193 | hif_reg_based_get_target_info(struct hif_opaque_softc *hif_ctx, |
| 194 | struct bmi_target_info *targ_info) |
| 195 | { |
| 196 | return QDF_STATUS_SUCCESS; |
| 197 | } |
| 198 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 199 | #endif |