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 | */ |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 194 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 195 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 196 | ce_phy_addr = |
| 197 | TARG_CPU_SPACE_TO_CE_SPACE(scn->mem, address); |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 198 | if (Q_TARGET_ACCESS_END(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 199 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 200 | |
| 201 | status = |
| 202 | ce_send(ce_diag, NULL, ce_phy_addr, nbytes, |
| 203 | transaction_id, 0, user_flags); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 204 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 205 | goto done; |
| 206 | } |
| 207 | |
| 208 | i = 0; |
| 209 | while (ce_completed_send_next(ce_diag, NULL, NULL, &buf, |
| 210 | &completed_nbytes, &id, NULL, NULL, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 211 | &toeplitz_hash_result) != QDF_STATUS_SUCCESS) { |
| 212 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 213 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 214 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 215 | goto done; |
| 216 | } |
| 217 | } |
| 218 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 219 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 220 | goto done; |
| 221 | } |
| 222 | if (buf != ce_phy_addr) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 223 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 224 | goto done; |
| 225 | } |
| 226 | |
| 227 | i = 0; |
| 228 | while (ce_completed_recv_next |
| 229 | (ce_diag, NULL, NULL, &buf, |
| 230 | &completed_nbytes, &id, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 231 | &flags) != QDF_STATUS_SUCCESS) { |
| 232 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 233 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 234 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 235 | goto done; |
| 236 | } |
| 237 | } |
| 238 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 239 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 240 | goto done; |
| 241 | } |
| 242 | if (buf != CE_data) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 243 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 244 | goto done; |
| 245 | } |
| 246 | |
| 247 | remaining_bytes -= nbytes; |
| 248 | address += nbytes; |
| 249 | CE_data += nbytes; |
| 250 | } |
| 251 | |
| 252 | done: |
| 253 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 254 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 255 | if (status == QDF_STATUS_SUCCESS) |
| 256 | qdf_mem_copy(data, data_buf, orig_nbytes); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 257 | else |
| 258 | HIF_ERROR("%s failure (0x%x)", __func__, address); |
| 259 | |
| 260 | if (data_buf) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 261 | qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 262 | orig_nbytes, data_buf, CE_data_base, 0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 263 | |
| 264 | return status; |
| 265 | } |
| 266 | |
| 267 | /* Read 4-byte aligned data from Target memory or register */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 268 | QDF_STATUS hif_diag_read_access(struct hif_opaque_softc *hif_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 269 | uint32_t address, uint32_t *data) |
| 270 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 271 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 272 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 273 | if (address >= DRAM_BASE_ADDRESS) { |
| 274 | /* Assume range doesn't cross this boundary */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 275 | return hif_diag_read_mem(hif_ctx, address, (uint8_t *) data, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 276 | sizeof(uint32_t)); |
| 277 | } else { |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 278 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 279 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 280 | *data = A_TARGET_READ(scn, address); |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 281 | if (Q_TARGET_ACCESS_END(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 282 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 283 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 284 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 288 | QDF_STATUS hif_diag_write_mem(struct hif_opaque_softc *hif_ctx, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 289 | uint32_t address, uint8_t *data, int nbytes) |
| 290 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 291 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 292 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 293 | QDF_STATUS status = QDF_STATUS_SUCCESS; |
| 294 | qdf_dma_addr_t buf; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 295 | unsigned int completed_nbytes, orig_nbytes, remaining_bytes; |
| 296 | unsigned int id; |
| 297 | unsigned int flags; |
| 298 | struct CE_handle *ce_diag; |
| 299 | void *data_buf = NULL; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 300 | qdf_dma_addr_t CE_data; /* Host buffer address in CE space */ |
| 301 | qdf_dma_addr_t CE_data_base = 0; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 302 | int i; |
| 303 | unsigned int mux_id = 0; |
| 304 | unsigned int transaction_id = 0xffff; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 305 | qdf_dma_addr_t ce_phy_addr = address; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 306 | unsigned int toeplitz_hash_result; |
| 307 | unsigned int user_flags = 0; |
| 308 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 309 | ce_diag = hif_state->ce_diag; |
| 310 | transaction_id = (mux_id & MUX_ID_MASK) | |
| 311 | (transaction_id & TRANSACTION_ID_MASK); |
| 312 | #ifdef QCA_WIFI_3_0 |
| 313 | user_flags &= DESC_DATA_FLAG_MASK; |
| 314 | #endif |
| 315 | |
| 316 | A_TARGET_ACCESS_LIKELY(scn); |
| 317 | |
| 318 | /* |
| 319 | * Allocate a temporary bounce buffer to hold caller's data |
| 320 | * to be DMA'ed to Target. This guarantees |
| 321 | * 1) 4-byte alignment |
| 322 | * 2) Buffer in DMA-able space |
| 323 | */ |
| 324 | orig_nbytes = nbytes; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 325 | data_buf = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 326 | orig_nbytes, &CE_data_base); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 327 | if (!data_buf) { |
| 328 | status = A_NO_MEMORY; |
| 329 | goto done; |
| 330 | } |
| 331 | |
| 332 | /* Copy caller's data to allocated DMA buf */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 333 | qdf_mem_copy(data_buf, data, orig_nbytes); |
| 334 | 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] | 335 | orig_nbytes, DMA_TO_DEVICE); |
| 336 | |
| 337 | /* |
| 338 | * The address supplied by the caller is in the |
| 339 | * Target CPU virtual address space. |
| 340 | * |
| 341 | * In order to use this address with the diagnostic CE, |
| 342 | * convert it from |
| 343 | * Target CPU virtual address space |
| 344 | * to |
| 345 | * CE address space |
| 346 | */ |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 347 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 348 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 349 | ce_phy_addr = TARG_CPU_SPACE_TO_CE_SPACE(scn->mem, address); |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 350 | if (Q_TARGET_ACCESS_END(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 351 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 352 | |
| 353 | remaining_bytes = orig_nbytes; |
| 354 | CE_data = CE_data_base; |
| 355 | while (remaining_bytes) { |
| 356 | nbytes = min(remaining_bytes, DIAG_TRANSFER_LIMIT); |
| 357 | |
| 358 | { /* Set up to receive directly into Target(!) address */ |
| 359 | status = ce_recv_buf_enqueue(ce_diag, |
| 360 | NULL, ce_phy_addr); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 361 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 362 | goto done; |
| 363 | } |
| 364 | |
| 365 | { |
| 366 | /* |
| 367 | * Request CE to send caller-supplied data that |
| 368 | * was copied to bounce buffer to Target(!) address. |
| 369 | */ |
| 370 | status = |
| 371 | ce_send(ce_diag, NULL, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 372 | (qdf_dma_addr_t) CE_data, nbytes, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 373 | transaction_id, 0, user_flags); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 374 | if (status != QDF_STATUS_SUCCESS) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 375 | goto done; |
| 376 | } |
| 377 | |
| 378 | i = 0; |
| 379 | while (ce_completed_send_next(ce_diag, NULL, NULL, &buf, |
| 380 | &completed_nbytes, &id, |
| 381 | NULL, NULL, &toeplitz_hash_result) != |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 382 | QDF_STATUS_SUCCESS) { |
| 383 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 384 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 385 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 386 | goto done; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 391 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 392 | goto done; |
| 393 | } |
| 394 | |
| 395 | if (buf != CE_data) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 396 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 397 | goto done; |
| 398 | } |
| 399 | |
| 400 | i = 0; |
| 401 | while (ce_completed_recv_next |
| 402 | (ce_diag, NULL, NULL, &buf, |
| 403 | &completed_nbytes, &id, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 404 | &flags) != QDF_STATUS_SUCCESS) { |
| 405 | qdf_mdelay(1); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 406 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 407 | status = QDF_STATUS_E_BUSY; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 408 | goto done; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if (nbytes != completed_nbytes) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 413 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 414 | goto done; |
| 415 | } |
| 416 | |
| 417 | if (buf != ce_phy_addr) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 418 | status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 419 | goto done; |
| 420 | } |
| 421 | |
| 422 | remaining_bytes -= nbytes; |
| 423 | address += nbytes; |
| 424 | CE_data += nbytes; |
| 425 | } |
| 426 | |
| 427 | done: |
| 428 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 429 | |
| 430 | if (data_buf) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 431 | qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 432 | orig_nbytes, data_buf, CE_data_base, 0); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 435 | if (status != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 436 | HIF_ERROR("%s failure (0x%llu)", __func__, |
| 437 | (uint64_t)ce_phy_addr); |
| 438 | } |
| 439 | |
| 440 | return status; |
| 441 | } |
| 442 | |
| 443 | /* Write 4B data to Target memory or register */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 444 | QDF_STATUS hif_diag_write_access(struct hif_opaque_softc *hif_ctx, |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 445 | uint32_t address, uint32_t data) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 446 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 447 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 448 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 449 | if (address >= DRAM_BASE_ADDRESS) { |
| 450 | /* Assume range doesn't cross this boundary */ |
| 451 | uint32_t data_buf = data; |
| 452 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 453 | return hif_diag_write_mem(hif_ctx, address, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 454 | (uint8_t *) &data_buf, |
| 455 | sizeof(uint32_t)); |
| 456 | } else { |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 457 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 458 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 459 | A_TARGET_WRITE(scn, address, data); |
Houston Hoffman | 2c32cf6 | 2016-03-14 21:12:00 -0700 | [diff] [blame] | 460 | if (Q_TARGET_ACCESS_END(scn) < 0) |
Houston Hoffman | 987ab44 | 2016-03-14 21:12:02 -0700 | [diff] [blame^] | 461 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 462 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 463 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 464 | } |
| 465 | } |