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