Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 2 | * Copyright (c) 2015-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 | #include <osdep.h> |
| 29 | #include "a_types.h" |
| 30 | #include "athdefs.h" |
| 31 | #include "osapi_linux.h" |
| 32 | #include "targcfg.h" |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 33 | #include "qdf_lock.h" |
| 34 | #include "qdf_status.h" |
| 35 | #include "qdf_status.h" |
| 36 | #include <qdf_atomic.h> /* qdf_atomic_read */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 37 | #include <targaddrs.h> |
| 38 | #include <bmi_msg.h> |
| 39 | #include "hif_io32.h" |
| 40 | #include <hif.h> |
| 41 | #include <htc_services.h> |
| 42 | #include "regtable.h" |
| 43 | #include <a_debug.h> |
| 44 | #include "hif_main.h" |
| 45 | #include "ce_api.h" |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 46 | #include "qdf_trace.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 47 | #ifdef CONFIG_CNSS |
| 48 | #include <net/cnss.h> |
| 49 | #endif |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 50 | #include "hif_debug.h" |
| 51 | #include "epping_main.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 52 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 53 | void |
| 54 | hif_dump_target_memory(struct hif_opaque_softc *hif_ctx, void *ramdump_base, |
| 55 | uint32_t address, uint32_t size) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 56 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 57 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 58 | uint32_t loc = address; |
| 59 | uint32_t val = 0; |
| 60 | uint32_t j = 0; |
| 61 | u8 *temp = ramdump_base; |
| 62 | |
| 63 | A_TARGET_ACCESS_BEGIN(scn); |
| 64 | while (j < size) { |
| 65 | val = hif_read32_mb(scn->mem + loc + j); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 66 | qdf_mem_copy(temp, &val, 4); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 67 | j += 4; |
| 68 | temp += 4; |
| 69 | } |
| 70 | A_TARGET_ACCESS_END(scn); |
| 71 | } |
| 72 | /* |
| 73 | * TBDXXX: Should be a function call specific to each Target-type. |
| 74 | * This convoluted macro converts from Target CPU Virtual Address |
| 75 | * Space to CE Address Space. As part of this process, we |
| 76 | * conservatively fetch the current PCIE_BAR. MOST of the time, |
| 77 | * this should match the upper bits of PCI space for this device; |
| 78 | * but that's not guaranteed. |
| 79 | */ |
| 80 | #ifdef QCA_WIFI_3_0 |
| 81 | #define TARG_CPU_SPACE_TO_CE_SPACE(pci_addr, addr) \ |
| 82 | (scn->mem_pa + addr) |
| 83 | #else |
| 84 | #define TARG_CPU_SPACE_TO_CE_SPACE(pci_addr, addr) \ |
| 85 | (((hif_read32_mb((pci_addr) + \ |
| 86 | (SOC_CORE_BASE_ADDRESS|CORE_CTRL_ADDRESS)) & 0x7ff) << 21) \ |
| 87 | | 0x100000 | ((addr) & 0xfffff)) |
| 88 | #endif |
| 89 | /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */ |
| 90 | #define DIAG_ACCESS_CE_TIMEOUT_MS 10 |
| 91 | |
| 92 | /* |
| 93 | * Diagnostic read/write access is provided for startup/config/debug usage. |
| 94 | * Caller must guarantee proper alignment, when applicable, and single user |
| 95 | * at any moment. |
| 96 | */ |
| 97 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 98 | QDF_STATUS |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 99 | hif_diag_read_mem(struct hif_opaque_softc *hif_ctx, uint32_t address, |
| 100 | uint8_t *data, int nbytes) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 101 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 102 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 103 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 104 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 105 | qdf_dma_addr_t buf; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 106 | unsigned int completed_nbytes, orig_nbytes, remaining_bytes; |
| 107 | unsigned int id; |
| 108 | unsigned int flags; |
| 109 | struct CE_handle *ce_diag; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 110 | qdf_dma_addr_t CE_data; /* Host buffer address in CE space */ |
| 111 | qdf_dma_addr_t CE_data_base = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 112 | void *data_buf = NULL; |
| 113 | int i; |
| 114 | unsigned int mux_id = 0; |
| 115 | unsigned int transaction_id = 0xffff; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 116 | qdf_dma_addr_t ce_phy_addr = address; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 117 | unsigned int toeplitz_hash_result; |
| 118 | unsigned int user_flags = 0; |
| 119 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 120 | transaction_id = (mux_id & MUX_ID_MASK) | |
| 121 | (transaction_id & TRANSACTION_ID_MASK); |
| 122 | #ifdef QCA_WIFI_3_0 |
| 123 | user_flags &= DESC_DATA_FLAG_MASK; |
| 124 | #endif |
| 125 | |
| 126 | /* This code cannot handle reads to non-memory space. Redirect to the |
| 127 | * register read fn but preserve the multi word read capability of |
| 128 | * this fn |
| 129 | */ |
| 130 | if (address < DRAM_BASE_ADDRESS) { |
| 131 | |
| 132 | if ((address & 0x3) || ((uintptr_t) data & 0x3)) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 133 | return QDF_STATUS_E_INVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 134 | |
| 135 | while ((nbytes >= 4) && |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 136 | (QDF_STATUS_SUCCESS == (status = |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 137 | hif_diag_read_access(hif_ctx, address, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 138 | (uint32_t *)data)))) { |
| 139 | |
| 140 | nbytes -= sizeof(uint32_t); |
| 141 | address += sizeof(uint32_t); |
| 142 | data += sizeof(uint32_t); |
| 143 | |
| 144 | } |
| 145 | |
| 146 | return status; |
| 147 | } |
| 148 | ce_diag = hif_state->ce_diag; |
| 149 | |
| 150 | A_TARGET_ACCESS_LIKELY(scn); |
| 151 | |
| 152 | /* |
| 153 | * Allocate a temporary bounce buffer to hold caller's data |
| 154 | * to be DMA'ed from Target. This guarantees |
| 155 | * 1) 4-byte alignment |
| 156 | * 2) Buffer in DMA-able space |
| 157 | */ |
| 158 | orig_nbytes = nbytes; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 159 | data_buf = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 160 | orig_nbytes, &CE_data_base); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 161 | if (!data_buf) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 162 | status = QDF_STATUS_E_NOMEM; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 163 | goto done; |
| 164 | } |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 165 | qdf_mem_set(data_buf, orig_nbytes, 0); |
| 166 | qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data_base, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 167 | orig_nbytes, DMA_FROM_DEVICE); |
| 168 | |
| 169 | remaining_bytes = orig_nbytes; |
| 170 | CE_data = CE_data_base; |
| 171 | while (remaining_bytes) { |
| 172 | nbytes = min(remaining_bytes, DIAG_TRANSFER_LIMIT); |
| 173 | { |
| 174 | status = ce_recv_buf_enqueue(ce_diag, NULL, CE_data); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 175 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 176 | goto done; |
| 177 | } |
| 178 | |
| 179 | { /* Request CE to send from Target(!) |
| 180 | * address to Host buffer */ |
| 181 | /* |
| 182 | * The address supplied by the caller is in the |
| 183 | * Target CPU virtual address space. |
| 184 | * |
| 185 | * In order to use this address with the diagnostic CE, |
| 186 | * convert it from |
| 187 | * Target CPU virtual address space |
| 188 | * to |
| 189 | * CE address space |
| 190 | */ |
| 191 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 192 | ce_phy_addr = |
| 193 | TARG_CPU_SPACE_TO_CE_SPACE(scn->mem, address); |
| 194 | A_TARGET_ACCESS_END_RET(scn); |
| 195 | |
| 196 | status = |
| 197 | ce_send(ce_diag, NULL, ce_phy_addr, nbytes, |
| 198 | transaction_id, 0, user_flags); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 199 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 200 | goto done; |
| 201 | } |
| 202 | |
| 203 | i = 0; |
| 204 | while (ce_completed_send_next(ce_diag, NULL, NULL, &buf, |
| 205 | &completed_nbytes, &id, NULL, NULL, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 206 | &toeplitz_hash_result) != QDF_STATUS_SUCCESS) { |
| 207 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 208 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 209 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 210 | goto done; |
| 211 | } |
| 212 | } |
| 213 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 214 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 215 | goto done; |
| 216 | } |
| 217 | if (buf != ce_phy_addr) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 218 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 219 | goto done; |
| 220 | } |
| 221 | |
| 222 | i = 0; |
| 223 | while (ce_completed_recv_next |
| 224 | (ce_diag, NULL, NULL, &buf, |
| 225 | &completed_nbytes, &id, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 226 | &flags) != QDF_STATUS_SUCCESS) { |
| 227 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 228 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 229 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 230 | goto done; |
| 231 | } |
| 232 | } |
| 233 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 234 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 235 | goto done; |
| 236 | } |
| 237 | if (buf != CE_data) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 238 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 239 | goto done; |
| 240 | } |
| 241 | |
| 242 | remaining_bytes -= nbytes; |
| 243 | address += nbytes; |
| 244 | CE_data += nbytes; |
| 245 | } |
| 246 | |
| 247 | done: |
| 248 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 249 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 250 | if (status == QDF_STATUS_SUCCESS) |
| 251 | qdf_mem_copy(data, data_buf, orig_nbytes); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 252 | else |
| 253 | HIF_ERROR("%s failure (0x%x)", __func__, address); |
| 254 | |
| 255 | if (data_buf) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 256 | qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 257 | orig_nbytes, data_buf, CE_data_base, 0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 258 | |
| 259 | return status; |
| 260 | } |
| 261 | |
| 262 | /* Read 4-byte aligned data from Target memory or register */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 263 | QDF_STATUS hif_diag_read_access(struct hif_opaque_softc *hif_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 264 | uint32_t address, uint32_t *data) |
| 265 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 266 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 267 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 268 | if (address >= DRAM_BASE_ADDRESS) { |
| 269 | /* Assume range doesn't cross this boundary */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 270 | return hif_diag_read_mem(hif_ctx, address, (uint8_t *) data, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 271 | sizeof(uint32_t)); |
| 272 | } else { |
| 273 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 274 | *data = A_TARGET_READ(scn, address); |
| 275 | A_TARGET_ACCESS_END_RET(scn); |
| 276 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 277 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 281 | QDF_STATUS hif_diag_write_mem(struct hif_opaque_softc *hif_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 282 | uint32_t address, uint8_t *data, int nbytes) |
| 283 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 284 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 285 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 286 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 287 | qdf_dma_addr_t buf; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 288 | unsigned int completed_nbytes, orig_nbytes, remaining_bytes; |
| 289 | unsigned int id; |
| 290 | unsigned int flags; |
| 291 | struct CE_handle *ce_diag; |
| 292 | void *data_buf = NULL; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 293 | qdf_dma_addr_t CE_data; /* Host buffer address in CE space */ |
| 294 | qdf_dma_addr_t CE_data_base = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 295 | int i; |
| 296 | unsigned int mux_id = 0; |
| 297 | unsigned int transaction_id = 0xffff; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 298 | qdf_dma_addr_t ce_phy_addr = address; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 299 | unsigned int toeplitz_hash_result; |
| 300 | unsigned int user_flags = 0; |
| 301 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 302 | ce_diag = hif_state->ce_diag; |
| 303 | transaction_id = (mux_id & MUX_ID_MASK) | |
| 304 | (transaction_id & TRANSACTION_ID_MASK); |
| 305 | #ifdef QCA_WIFI_3_0 |
| 306 | user_flags &= DESC_DATA_FLAG_MASK; |
| 307 | #endif |
| 308 | |
| 309 | A_TARGET_ACCESS_LIKELY(scn); |
| 310 | |
| 311 | /* |
| 312 | * Allocate a temporary bounce buffer to hold caller's data |
| 313 | * to be DMA'ed to Target. This guarantees |
| 314 | * 1) 4-byte alignment |
| 315 | * 2) Buffer in DMA-able space |
| 316 | */ |
| 317 | orig_nbytes = nbytes; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 318 | data_buf = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 319 | orig_nbytes, &CE_data_base); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 320 | if (!data_buf) { |
| 321 | status = A_NO_MEMORY; |
| 322 | goto done; |
| 323 | } |
| 324 | |
| 325 | /* Copy caller's data to allocated DMA buf */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 326 | qdf_mem_copy(data_buf, data, orig_nbytes); |
| 327 | qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data_base, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 328 | orig_nbytes, DMA_TO_DEVICE); |
| 329 | |
| 330 | /* |
| 331 | * The address supplied by the caller is in the |
| 332 | * Target CPU virtual address space. |
| 333 | * |
| 334 | * In order to use this address with the diagnostic CE, |
| 335 | * convert it from |
| 336 | * Target CPU virtual address space |
| 337 | * to |
| 338 | * CE address space |
| 339 | */ |
| 340 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 341 | ce_phy_addr = TARG_CPU_SPACE_TO_CE_SPACE(scn->mem, address); |
| 342 | A_TARGET_ACCESS_END_RET(scn); |
| 343 | |
| 344 | remaining_bytes = orig_nbytes; |
| 345 | CE_data = CE_data_base; |
| 346 | while (remaining_bytes) { |
| 347 | nbytes = min(remaining_bytes, DIAG_TRANSFER_LIMIT); |
| 348 | |
| 349 | { /* Set up to receive directly into Target(!) address */ |
| 350 | status = ce_recv_buf_enqueue(ce_diag, |
| 351 | NULL, ce_phy_addr); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 352 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 353 | goto done; |
| 354 | } |
| 355 | |
| 356 | { |
| 357 | /* |
| 358 | * Request CE to send caller-supplied data that |
| 359 | * was copied to bounce buffer to Target(!) address. |
| 360 | */ |
| 361 | status = |
| 362 | ce_send(ce_diag, NULL, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 363 | (qdf_dma_addr_t) CE_data, nbytes, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 364 | transaction_id, 0, user_flags); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 365 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 366 | goto done; |
| 367 | } |
| 368 | |
| 369 | i = 0; |
| 370 | while (ce_completed_send_next(ce_diag, NULL, NULL, &buf, |
| 371 | &completed_nbytes, &id, |
| 372 | NULL, NULL, &toeplitz_hash_result) != |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 373 | QDF_STATUS_SUCCESS) { |
| 374 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 375 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 376 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 377 | goto done; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 382 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 383 | goto done; |
| 384 | } |
| 385 | |
| 386 | if (buf != CE_data) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 387 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 388 | goto done; |
| 389 | } |
| 390 | |
| 391 | i = 0; |
| 392 | while (ce_completed_recv_next |
| 393 | (ce_diag, NULL, NULL, &buf, |
| 394 | &completed_nbytes, &id, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 395 | &flags) != QDF_STATUS_SUCCESS) { |
| 396 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 397 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 398 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 399 | goto done; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 404 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 405 | goto done; |
| 406 | } |
| 407 | |
| 408 | if (buf != ce_phy_addr) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 409 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 410 | goto done; |
| 411 | } |
| 412 | |
| 413 | remaining_bytes -= nbytes; |
| 414 | address += nbytes; |
| 415 | CE_data += nbytes; |
| 416 | } |
| 417 | |
| 418 | done: |
| 419 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 420 | |
| 421 | if (data_buf) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 422 | qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 423 | orig_nbytes, data_buf, CE_data_base, 0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 426 | if (status != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 427 | HIF_ERROR("%s failure (0x%llu)", __func__, |
| 428 | (uint64_t)ce_phy_addr); |
| 429 | } |
| 430 | |
| 431 | return status; |
| 432 | } |
| 433 | |
| 434 | /* Write 4B data to Target memory or register */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 435 | QDF_STATUS hif_diag_write_access(struct hif_opaque_softc *hif_ctx, |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 436 | uint32_t address, uint32_t data) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 437 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 438 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 439 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 440 | if (address >= DRAM_BASE_ADDRESS) { |
| 441 | /* Assume range doesn't cross this boundary */ |
| 442 | uint32_t data_buf = data; |
| 443 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 444 | return hif_diag_write_mem(hif_ctx, address, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 445 | (uint8_t *) &data_buf, |
| 446 | sizeof(uint32_t)); |
| 447 | } else { |
| 448 | A_TARGET_ACCESS_BEGIN_RET(scn); |
| 449 | A_TARGET_WRITE(scn, address, data); |
| 450 | A_TARGET_ACCESS_END_RET(scn); |
| 451 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame^] | 452 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 453 | } |
| 454 | } |