Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Prashanth Bhatta | dfcae6b | 2015-12-04 11:56:47 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-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 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 27 | #include "targcfg.h" |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 28 | #include "qdf_lock.h" |
| 29 | #include "qdf_status.h" |
| 30 | #include "qdf_status.h" |
| 31 | #include <qdf_atomic.h> /* qdf_atomic_read */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 32 | #include <targaddrs.h> |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 33 | #include "hif_io32.h" |
| 34 | #include <hif.h> |
| 35 | #include "regtable.h" |
| 36 | #define ATH_MODULE_NAME hif |
| 37 | #include <a_debug.h> |
| 38 | #include "hif_main.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 39 | #include "ce_api.h" |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 40 | #include "qdf_trace.h" |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 41 | #include "pld_common.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 42 | #include "hif_debug.h" |
| 43 | #include "ce_internal.h" |
| 44 | #include "ce_reg.h" |
| 45 | #include "ce_assignment.h" |
| 46 | #include "ce_tasklet.h" |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 47 | #ifndef CONFIG_WIN |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 48 | #include "qwlan_version.h" |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 49 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 50 | |
| 51 | #define CE_POLL_TIMEOUT 10 /* ms */ |
| 52 | |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 53 | #define AGC_DUMP 1 |
| 54 | #define CHANINFO_DUMP 2 |
| 55 | #define BB_WATCHDOG_DUMP 3 |
| 56 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 57 | #define PCIE_ACCESS_DUMP 4 |
| 58 | #endif |
| 59 | #include "mp_dev.h" |
| 60 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 61 | /* Forward references */ |
| 62 | static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info); |
| 63 | |
| 64 | /* |
| 65 | * Fix EV118783, poll to check whether a BMI response comes |
| 66 | * other than waiting for the interruption which may be lost. |
| 67 | */ |
| 68 | /* #define BMI_RSP_POLLING */ |
| 69 | #define BMI_RSP_TO_MILLISEC 1000 |
| 70 | |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_BYPASS_QMI |
| 72 | #define BYPASS_QMI 1 |
| 73 | #else |
| 74 | #define BYPASS_QMI 0 |
| 75 | #endif |
| 76 | |
Houston Hoffman | abd0077 | 2016-05-06 17:02:48 -0700 | [diff] [blame] | 77 | #ifdef CONFIG_WIN |
Pratik Gandhi | 424c62e | 2016-08-23 19:47:09 +0530 | [diff] [blame] | 78 | #if ENABLE_10_4_FW_HDR |
Houston Hoffman | abd0077 | 2016-05-06 17:02:48 -0700 | [diff] [blame] | 79 | #define WDI_IPA_SERVICE_GROUP 5 |
| 80 | #define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0) |
| 81 | #define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1) |
| 82 | #define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2) |
Pratik Gandhi | 424c62e | 2016-08-23 19:47:09 +0530 | [diff] [blame] | 83 | #endif /* ENABLE_10_4_FW_HDR */ |
Houston Hoffman | abd0077 | 2016-05-06 17:02:48 -0700 | [diff] [blame] | 84 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 85 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 86 | static int hif_post_recv_buffers(struct hif_softc *scn); |
| 87 | static void hif_config_rri_on_ddr(struct hif_softc *scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 88 | |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 89 | /** |
| 90 | * hif_target_access_log_dump() - dump access log |
| 91 | * |
| 92 | * dump access log |
| 93 | * |
| 94 | * Return: n/a |
| 95 | */ |
| 96 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 97 | static void hif_target_access_log_dump(void) |
| 98 | { |
| 99 | hif_target_dump_access_log(); |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | |
| 104 | void hif_trigger_dump(struct hif_opaque_softc *hif_ctx, |
| 105 | uint8_t cmd_id, bool start) |
| 106 | { |
| 107 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 108 | |
| 109 | switch (cmd_id) { |
| 110 | case AGC_DUMP: |
| 111 | if (start) |
| 112 | priv_start_agc(scn); |
| 113 | else |
| 114 | priv_dump_agc(scn); |
| 115 | break; |
| 116 | case CHANINFO_DUMP: |
| 117 | if (start) |
| 118 | priv_start_cap_chaninfo(scn); |
| 119 | else |
| 120 | priv_dump_chaninfo(scn); |
| 121 | break; |
| 122 | case BB_WATCHDOG_DUMP: |
| 123 | priv_dump_bbwatchdog(scn); |
| 124 | break; |
| 125 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 126 | case PCIE_ACCESS_DUMP: |
| 127 | hif_target_access_log_dump(); |
| 128 | break; |
| 129 | #endif |
| 130 | default: |
| 131 | HIF_ERROR("%s: Invalid htc dump command", __func__); |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 136 | static void ce_poll_timeout(void *arg) |
| 137 | { |
| 138 | struct CE_state *CE_state = (struct CE_state *)arg; |
| 139 | if (CE_state->timer_inited) { |
| 140 | ce_per_engine_service(CE_state->scn, CE_state->id); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 141 | qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | static unsigned int roundup_pwr2(unsigned int n) |
| 146 | { |
| 147 | int i; |
| 148 | unsigned int test_pwr2; |
| 149 | |
| 150 | if (!(n & (n - 1))) |
| 151 | return n; /* already a power of 2 */ |
| 152 | |
| 153 | test_pwr2 = 4; |
| 154 | for (i = 0; i < 29; i++) { |
| 155 | if (test_pwr2 > n) |
| 156 | return test_pwr2; |
| 157 | test_pwr2 = test_pwr2 << 1; |
| 158 | } |
| 159 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 160 | QDF_ASSERT(0); /* n too large */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 164 | #define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C |
| 165 | #define ADRASTEA_DST_WR_INDEX_OFFSET 0x40 |
| 166 | |
| 167 | static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = { |
| 168 | { 0, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 169 | { 3, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 170 | { 4, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 171 | { 5, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 172 | { 7, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 173 | { 1, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 174 | { 2, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 175 | { 7, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 176 | { 8, ADRASTEA_DST_WR_INDEX_OFFSET}, |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 177 | #ifdef QCA_WIFI_3_0_ADRASTEA |
| 178 | { 9, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 179 | { 10, ADRASTEA_DST_WR_INDEX_OFFSET}, |
Nirav Shah | 75cc5c8 | 2016-05-25 10:52:38 +0530 | [diff] [blame] | 180 | { 11, ADRASTEA_DST_WR_INDEX_OFFSET}, |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 181 | #endif |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Vishwajith Upendra | 70efc75 | 2016-04-18 11:23:49 -0700 | [diff] [blame] | 184 | static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = { |
| 185 | { 0, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 186 | { 3, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 187 | { 4, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 188 | { 7, ADRASTEA_SRC_WR_INDEX_OFFSET}, |
| 189 | { 1, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 190 | { 2, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 191 | { 5, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 192 | { 7, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 193 | { 8, ADRASTEA_DST_WR_INDEX_OFFSET}, |
| 194 | }; |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 195 | |
| 196 | /* CE_PCI TABLE */ |
| 197 | /* |
| 198 | * NOTE: the table below is out of date, though still a useful reference. |
| 199 | * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual |
| 200 | * mapping of HTC services to HIF pipes. |
| 201 | */ |
| 202 | /* |
| 203 | * This authoritative table defines Copy Engine configuration and the mapping |
| 204 | * of services/endpoints to CEs. A subset of this information is passed to |
| 205 | * the Target during startup as a prerequisite to entering BMI phase. |
| 206 | * See: |
| 207 | * target_service_to_ce_map - Target-side mapping |
| 208 | * hif_map_service_to_pipe - Host-side mapping |
| 209 | * target_ce_config - Target-side configuration |
| 210 | * host_ce_config - Host-side configuration |
| 211 | ============================================================================ |
| 212 | Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer |
| 213 | | | | ctio | Size | Frequency |
| 214 | | | | n | | |
| 215 | ============================================================================ |
| 216 | tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent |
| 217 | descriptor | | | | O(100B) | and regular |
| 218 | download | | | | | |
| 219 | ---------------------------------------------------------------------------- |
| 220 | rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and |
| 221 | indication | | | | O(10B) | regular |
| 222 | upload | | | | | |
| 223 | ---------------------------------------------------------------------------- |
| 224 | MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare |
| 225 | upload | | | | O(1000B) | (frequent |
| 226 | e.g. noise | | | | | during IP1.0 |
| 227 | packets | | | | | testing) |
| 228 | ---------------------------------------------------------------------------- |
| 229 | MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare |
| 230 | download | | | | O(1000B) | (frequent |
| 231 | e.g. | | | | | during IP1.0 |
| 232 | misdirecte | | | | | testing) |
| 233 | d EAPOL | | | | | |
| 234 | packets | | | | | |
| 235 | ---------------------------------------------------------------------------- |
| 236 | n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?) |
| 237 | | DATA_VO (uplink) | | | | |
| 238 | ---------------------------------------------------------------------------- |
| 239 | n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?) |
| 240 | | DATA_VO (downlink) | | | | |
| 241 | ---------------------------------------------------------------------------- |
| 242 | WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent |
| 243 | | | | | O(100B) | |
| 244 | ---------------------------------------------------------------------------- |
| 245 | WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent |
| 246 | messages | (downlink) | | | O(100B) | |
| 247 | | | | | | |
| 248 | ---------------------------------------------------------------------------- |
| 249 | n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?) |
| 250 | | HTC_RAW_STREAMS | | | | |
| 251 | | (uplink) | | | | |
| 252 | ---------------------------------------------------------------------------- |
| 253 | n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?) |
| 254 | | HTC_RAW_STREAMS | | | | |
| 255 | | (downlink) | | | | |
| 256 | ---------------------------------------------------------------------------- |
| 257 | diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window |
| 258 | | | | | | infrequent |
| 259 | ============================================================================ |
| 260 | */ |
| 261 | |
| 262 | /* |
| 263 | * Map from service/endpoint to Copy Engine. |
| 264 | * This table is derived from the CE_PCI TABLE, above. |
| 265 | * It is passed to the Target at startup for use by firmware. |
| 266 | */ |
| 267 | static struct service_to_pipe target_service_to_ce_map_wlan[] = { |
| 268 | { |
| 269 | WMI_DATA_VO_SVC, |
| 270 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 271 | 3, |
| 272 | }, |
| 273 | { |
| 274 | WMI_DATA_VO_SVC, |
| 275 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 276 | 2, |
| 277 | }, |
| 278 | { |
| 279 | WMI_DATA_BK_SVC, |
| 280 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 281 | 3, |
| 282 | }, |
| 283 | { |
| 284 | WMI_DATA_BK_SVC, |
| 285 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 286 | 2, |
| 287 | }, |
| 288 | { |
| 289 | WMI_DATA_BE_SVC, |
| 290 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 291 | 3, |
| 292 | }, |
| 293 | { |
| 294 | WMI_DATA_BE_SVC, |
| 295 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 296 | 2, |
| 297 | }, |
| 298 | { |
| 299 | WMI_DATA_VI_SVC, |
| 300 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 301 | 3, |
| 302 | }, |
| 303 | { |
| 304 | WMI_DATA_VI_SVC, |
| 305 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 306 | 2, |
| 307 | }, |
| 308 | { |
| 309 | WMI_CONTROL_SVC, |
| 310 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 311 | 3, |
| 312 | }, |
| 313 | { |
| 314 | WMI_CONTROL_SVC, |
| 315 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 316 | 2, |
| 317 | }, |
| 318 | { |
| 319 | HTC_CTRL_RSVD_SVC, |
| 320 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 321 | 0, /* could be moved to 3 (share with WMI) */ |
| 322 | }, |
| 323 | { |
| 324 | HTC_CTRL_RSVD_SVC, |
| 325 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 326 | 2, |
| 327 | }, |
| 328 | { |
| 329 | HTC_RAW_STREAMS_SVC, /* not currently used */ |
| 330 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 331 | 0, |
| 332 | }, |
| 333 | { |
| 334 | HTC_RAW_STREAMS_SVC, /* not currently used */ |
| 335 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 336 | 2, |
| 337 | }, |
| 338 | { |
| 339 | HTT_DATA_MSG_SVC, |
| 340 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 341 | 4, |
| 342 | }, |
| 343 | { |
| 344 | HTT_DATA_MSG_SVC, |
| 345 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 346 | 1, |
| 347 | }, |
| 348 | { |
| 349 | WDI_IPA_TX_SVC, |
| 350 | PIPEDIR_OUT, /* in = DL = target -> host */ |
| 351 | 5, |
| 352 | }, |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 353 | #if defined(QCA_WIFI_3_0_ADRASTEA) |
| 354 | { |
| 355 | HTT_DATA2_MSG_SVC, |
| 356 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 357 | 9, |
| 358 | }, |
| 359 | { |
| 360 | HTT_DATA3_MSG_SVC, |
| 361 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 362 | 10, |
| 363 | }, |
Nirav Shah | 75cc5c8 | 2016-05-25 10:52:38 +0530 | [diff] [blame] | 364 | { |
| 365 | PACKET_LOG_SVC, |
| 366 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 367 | 11, |
| 368 | }, |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 369 | #endif |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 370 | /* (Additions here) */ |
| 371 | |
| 372 | { /* Must be last */ |
| 373 | 0, |
| 374 | 0, |
| 375 | 0, |
| 376 | }, |
| 377 | }; |
| 378 | |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 379 | static struct service_to_pipe target_service_to_ce_map_ar900b[] = { |
| 380 | { |
| 381 | WMI_DATA_VO_SVC, |
| 382 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 383 | 3, |
| 384 | }, |
| 385 | { |
| 386 | WMI_DATA_VO_SVC, |
| 387 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 388 | 2, |
| 389 | }, |
| 390 | { |
| 391 | WMI_DATA_BK_SVC, |
| 392 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 393 | 3, |
| 394 | }, |
| 395 | { |
| 396 | WMI_DATA_BK_SVC, |
| 397 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 398 | 2, |
| 399 | }, |
| 400 | { |
| 401 | WMI_DATA_BE_SVC, |
| 402 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 403 | 3, |
| 404 | }, |
| 405 | { |
| 406 | WMI_DATA_BE_SVC, |
| 407 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 408 | 2, |
| 409 | }, |
| 410 | { |
| 411 | WMI_DATA_VI_SVC, |
| 412 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 413 | 3, |
| 414 | }, |
| 415 | { |
| 416 | WMI_DATA_VI_SVC, |
| 417 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 418 | 2, |
| 419 | }, |
| 420 | { |
| 421 | WMI_CONTROL_SVC, |
| 422 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 423 | 3, |
| 424 | }, |
| 425 | { |
| 426 | WMI_CONTROL_SVC, |
| 427 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 428 | 2, |
| 429 | }, |
| 430 | { |
| 431 | HTC_CTRL_RSVD_SVC, |
| 432 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 433 | 0, /* could be moved to 3 (share with WMI) */ |
| 434 | }, |
| 435 | { |
| 436 | HTC_CTRL_RSVD_SVC, |
| 437 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 438 | 1, |
| 439 | }, |
| 440 | { |
| 441 | HTC_RAW_STREAMS_SVC, /* not currently used */ |
| 442 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 443 | 0, |
| 444 | }, |
| 445 | { |
| 446 | HTC_RAW_STREAMS_SVC, /* not currently used */ |
| 447 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 448 | 1, |
| 449 | }, |
| 450 | { |
| 451 | HTT_DATA_MSG_SVC, |
| 452 | PIPEDIR_OUT, /* out = UL = host -> target */ |
| 453 | 4, |
| 454 | }, |
| 455 | #if WLAN_FEATURE_FASTPATH |
| 456 | { |
| 457 | HTT_DATA_MSG_SVC, |
| 458 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 459 | 5, |
| 460 | }, |
| 461 | #else /* WLAN_FEATURE_FASTPATH */ |
| 462 | { |
| 463 | HTT_DATA_MSG_SVC, |
| 464 | PIPEDIR_IN, /* in = DL = target -> host */ |
| 465 | 1, |
| 466 | }, |
| 467 | #endif /* WLAN_FEATURE_FASTPATH */ |
| 468 | |
| 469 | /* (Additions here) */ |
| 470 | |
| 471 | { /* Must be last */ |
| 472 | 0, |
| 473 | 0, |
| 474 | 0, |
| 475 | }, |
| 476 | }; |
| 477 | |
| 478 | |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 479 | static struct service_to_pipe *target_service_to_ce_map = |
| 480 | target_service_to_ce_map_wlan; |
| 481 | static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan); |
| 482 | |
| 483 | static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map; |
| 484 | static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map); |
| 485 | |
| 486 | static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = { |
| 487 | {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */ |
| 488 | {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 489 | {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */ |
| 490 | {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */ |
| 491 | {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */ |
| 492 | {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 493 | {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */ |
| 494 | {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 495 | {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */ |
| 496 | {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 497 | {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */ |
| 498 | {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 499 | {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */ |
| 500 | {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */ |
| 501 | {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */ |
| 502 | {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */ |
| 503 | {0, 0, 0,}, /* Must be last */ |
| 504 | }; |
| 505 | |
| 506 | /** |
| 507 | * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly |
| 508 | * @ce_state : pointer to the state context of the CE |
| 509 | * |
| 510 | * Description: |
| 511 | * Sets htt_rx_data attribute of the state structure if the |
| 512 | * CE serves one of the HTT DATA services. |
| 513 | * |
| 514 | * Return: |
| 515 | * false (attribute set to false) |
| 516 | * true (attribute set to true); |
| 517 | */ |
| 518 | bool ce_mark_datapath(struct CE_state *ce_state) |
| 519 | { |
| 520 | struct service_to_pipe *svc_map; |
| 521 | size_t map_sz; |
| 522 | int i; |
| 523 | bool rc = false; |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 524 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(ce_state->scn); |
| 525 | struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl); |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 526 | |
| 527 | if (ce_state != NULL) { |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 528 | if (QDF_IS_EPPING_ENABLED(hif_get_conparam(ce_state->scn))) { |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 529 | svc_map = target_service_to_ce_map_wlan_epping; |
| 530 | map_sz = sizeof(target_service_to_ce_map_wlan_epping) / |
| 531 | sizeof(struct service_to_pipe); |
| 532 | } else { |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 533 | switch (tgt_info->target_type) { |
| 534 | default: |
| 535 | svc_map = target_service_to_ce_map_wlan; |
| 536 | map_sz = |
| 537 | sizeof(target_service_to_ce_map_wlan) / |
| 538 | sizeof(struct service_to_pipe); |
| 539 | break; |
| 540 | case TARGET_TYPE_AR900B: |
| 541 | case TARGET_TYPE_QCA9984: |
| 542 | case TARGET_TYPE_IPQ4019: |
| 543 | case TARGET_TYPE_QCA9888: |
| 544 | case TARGET_TYPE_AR9888: |
| 545 | case TARGET_TYPE_AR9888V2: |
| 546 | svc_map = target_service_to_ce_map_ar900b; |
| 547 | map_sz = |
| 548 | sizeof(target_service_to_ce_map_ar900b) |
| 549 | / sizeof(struct service_to_pipe); |
| 550 | break; |
| 551 | } |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 552 | } |
| 553 | for (i = 0; i < map_sz; i++) { |
| 554 | if ((svc_map[i].pipenum == ce_state->id) && |
| 555 | ((svc_map[i].service_id == HTT_DATA_MSG_SVC) || |
| 556 | (svc_map[i].service_id == HTT_DATA2_MSG_SVC) || |
| 557 | (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) { |
| 558 | /* HTT CEs are unidirectional */ |
| 559 | if (svc_map[i].pipedir == PIPEDIR_IN) |
| 560 | ce_state->htt_rx_data = true; |
| 561 | else |
| 562 | ce_state->htt_tx_data = true; |
| 563 | rc = true; |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | return rc; |
| 568 | } |
| 569 | |
Houston Hoffman | 4780817 | 2016-05-06 10:04:21 -0700 | [diff] [blame] | 570 | /** |
| 571 | * ce_ring_test_initial_indexes() - tests the initial ce ring indexes |
| 572 | * @ce_id: ce in question |
| 573 | * @ring: ring state being examined |
| 574 | * @type: "src_ring" or "dest_ring" string for identifying the ring |
| 575 | * |
| 576 | * Warns on non-zero index values. |
| 577 | * Causes a kernel panic if the ring is not empty durring initialization. |
| 578 | */ |
| 579 | static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring, |
| 580 | char *type) |
| 581 | { |
| 582 | if (ring->write_index != 0 || ring->sw_index != 0) |
| 583 | HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d", |
| 584 | ce_id, type, ring->sw_index, ring->write_index); |
| 585 | if (ring->write_index != ring->sw_index) |
| 586 | QDF_BUG(0); |
| 587 | } |
| 588 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 589 | /** |
| 590 | * ce_srng_based() - Does this target use srng |
| 591 | * @ce_state : pointer to the state context of the CE |
| 592 | * |
| 593 | * Description: |
| 594 | * returns true if the target is SRNG based |
| 595 | * |
| 596 | * Return: |
| 597 | * false (attribute set to false) |
| 598 | * true (attribute set to true); |
| 599 | */ |
| 600 | bool ce_srng_based(struct hif_softc *scn) |
| 601 | { |
| 602 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); |
| 603 | struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl); |
| 604 | |
| 605 | switch (tgt_info->target_type) { |
| 606 | #ifdef QCA_WIFI_QCA8074 |
| 607 | case TARGET_TYPE_QCA8074: |
| 608 | return true; |
| 609 | #endif |
| 610 | default: |
| 611 | return false; |
| 612 | } |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | struct ce_ops *ce_services_attach(struct hif_softc *scn) |
| 617 | { |
| 618 | #ifdef QCA_WIFI_QCA8074 |
| 619 | if (ce_srng_based(scn)) |
| 620 | return ce_services_srng(); |
| 621 | #endif |
| 622 | |
| 623 | return ce_services_legacy(); |
| 624 | } |
| 625 | |
| 626 | static inline uint32_t ce_get_desc_size(struct hif_softc *scn, |
| 627 | uint8_t ring_type) |
| 628 | { |
| 629 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 630 | |
| 631 | return hif_state->ce_services->ce_get_desc_size(ring_type); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state, |
| 636 | uint8_t ring_type, uint32_t nentries) |
| 637 | { |
| 638 | uint32_t ce_nbytes; |
| 639 | char *ptr; |
| 640 | qdf_dma_addr_t base_addr; |
| 641 | struct CE_ring_state *ce_ring; |
| 642 | uint32_t desc_size; |
| 643 | struct hif_softc *scn = CE_state->scn; |
| 644 | |
| 645 | ce_nbytes = sizeof(struct CE_ring_state) |
| 646 | + (nentries * sizeof(void *)); |
| 647 | ptr = qdf_mem_malloc(ce_nbytes); |
| 648 | if (!ptr) |
| 649 | return NULL; |
| 650 | |
| 651 | qdf_mem_zero(ptr, ce_nbytes); |
| 652 | |
| 653 | ce_ring = (struct CE_ring_state *)ptr; |
| 654 | ptr += sizeof(struct CE_ring_state); |
| 655 | ce_ring->nentries = nentries; |
| 656 | ce_ring->nentries_mask = nentries - 1; |
| 657 | |
| 658 | ce_ring->low_water_mark_nentries = 0; |
| 659 | ce_ring->high_water_mark_nentries = nentries; |
| 660 | ce_ring->per_transfer_context = (void **)ptr; |
| 661 | |
| 662 | desc_size = ce_get_desc_size(scn, ring_type); |
| 663 | |
| 664 | /* Legacy platforms that do not support cache |
| 665 | * coherent DMA are unsupported |
| 666 | */ |
| 667 | ce_ring->base_addr_owner_space_unaligned = |
| 668 | qdf_mem_alloc_consistent(scn->qdf_dev, |
| 669 | scn->qdf_dev->dev, |
| 670 | (nentries * |
| 671 | desc_size + |
| 672 | CE_DESC_RING_ALIGN), |
| 673 | &base_addr); |
| 674 | if (ce_ring->base_addr_owner_space_unaligned |
| 675 | == NULL) { |
| 676 | HIF_ERROR("%s: ring has no DMA mem", |
| 677 | __func__); |
| 678 | qdf_mem_free(ptr); |
| 679 | return NULL; |
| 680 | } |
| 681 | ce_ring->base_addr_CE_space_unaligned = base_addr; |
| 682 | |
| 683 | /* Correctly initialize memory to 0 to |
| 684 | * prevent garbage data crashing system |
| 685 | * when download firmware |
| 686 | */ |
| 687 | qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned, |
| 688 | nentries * desc_size + |
| 689 | CE_DESC_RING_ALIGN); |
| 690 | |
| 691 | if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) { |
| 692 | |
| 693 | ce_ring->base_addr_CE_space = |
| 694 | (ce_ring->base_addr_CE_space_unaligned + |
| 695 | CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1); |
| 696 | |
| 697 | ce_ring->base_addr_owner_space = (void *) |
| 698 | (((size_t) ce_ring->base_addr_owner_space_unaligned + |
| 699 | CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1)); |
| 700 | } else { |
| 701 | ce_ring->base_addr_CE_space = |
| 702 | ce_ring->base_addr_CE_space_unaligned; |
| 703 | ce_ring->base_addr_owner_space = |
| 704 | ce_ring->base_addr_owner_space_unaligned; |
| 705 | } |
| 706 | |
| 707 | return ce_ring; |
| 708 | } |
| 709 | |
| 710 | static void ce_ring_setup(struct hif_softc *scn, uint8_t ring_type, |
| 711 | uint32_t ce_id, struct CE_ring_state *ring, |
| 712 | struct CE_attr *attr) |
| 713 | { |
| 714 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 715 | |
| 716 | hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id, ring, attr); |
| 717 | } |
| 718 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 719 | /* |
| 720 | * Initialize a Copy Engine based on caller-supplied attributes. |
| 721 | * This may be called once to initialize both source and destination |
| 722 | * rings or it may be called twice for separate source and destination |
| 723 | * initialization. It may be that only one side or the other is |
| 724 | * initialized by software/firmware. |
Houston Hoffman | 233e909 | 2015-09-02 13:37:21 -0700 | [diff] [blame] | 725 | * |
| 726 | * This should be called durring the initialization sequence before |
| 727 | * interupts are enabled, so we don't have to worry about thread safety. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 728 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 729 | struct CE_handle *ce_init(struct hif_softc *scn, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 730 | unsigned int CE_id, struct CE_attr *attr) |
| 731 | { |
| 732 | struct CE_state *CE_state; |
| 733 | uint32_t ctrl_addr; |
| 734 | unsigned int nentries; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 735 | bool malloc_CE_state = false; |
| 736 | bool malloc_src_ring = false; |
| 737 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 738 | QDF_ASSERT(CE_id < scn->ce_count); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 739 | ctrl_addr = CE_BASE_ADDRESS(CE_id); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 740 | CE_state = scn->ce_id_to_state[CE_id]; |
| 741 | |
| 742 | if (!CE_state) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 743 | CE_state = |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 744 | (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 745 | if (!CE_state) { |
| 746 | HIF_ERROR("%s: CE_state has no mem", __func__); |
| 747 | return NULL; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 748 | } |
Houston Hoffman | 233e909 | 2015-09-02 13:37:21 -0700 | [diff] [blame] | 749 | malloc_CE_state = true; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 750 | qdf_mem_zero(CE_state, sizeof(*CE_state)); |
Houston Hoffman | 233e909 | 2015-09-02 13:37:21 -0700 | [diff] [blame] | 751 | scn->ce_id_to_state[CE_id] = CE_state; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 752 | qdf_spinlock_create(&CE_state->ce_index_lock); |
Houston Hoffman | 233e909 | 2015-09-02 13:37:21 -0700 | [diff] [blame] | 753 | |
| 754 | CE_state->id = CE_id; |
| 755 | CE_state->ctrl_addr = ctrl_addr; |
| 756 | CE_state->state = CE_RUNNING; |
| 757 | CE_state->attr_flags = attr->flags; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 758 | } |
| 759 | CE_state->scn = scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 760 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 761 | qdf_atomic_init(&CE_state->rx_pending); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 762 | if (attr == NULL) { |
| 763 | /* Already initialized; caller wants the handle */ |
| 764 | return (struct CE_handle *)CE_state; |
| 765 | } |
| 766 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 767 | if (CE_state->src_sz_max) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 768 | QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 769 | else |
| 770 | CE_state->src_sz_max = attr->src_sz_max; |
| 771 | |
Houston Hoffman | 68e837e | 2015-12-04 12:57:24 -0800 | [diff] [blame] | 772 | ce_init_ce_desc_event_log(CE_id, |
| 773 | attr->src_nentries + attr->dest_nentries); |
| 774 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 775 | /* source ring setup */ |
| 776 | nentries = attr->src_nentries; |
| 777 | if (nentries) { |
| 778 | struct CE_ring_state *src_ring; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 779 | nentries = roundup_pwr2(nentries); |
| 780 | if (CE_state->src_ring) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 781 | QDF_ASSERT(CE_state->src_ring->nentries == nentries); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 782 | } else { |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 783 | src_ring = CE_state->src_ring = |
| 784 | ce_alloc_ring_state(CE_state, |
| 785 | CE_RING_SRC, |
| 786 | nentries); |
| 787 | if (!src_ring) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 788 | /* cannot allocate src ring. If the |
| 789 | * CE_state is allocated locally free |
| 790 | * CE_State and return error. |
| 791 | */ |
| 792 | HIF_ERROR("%s: src ring has no mem", __func__); |
| 793 | if (malloc_CE_state) { |
| 794 | /* allocated CE_state locally */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 795 | scn->ce_id_to_state[CE_id] = NULL; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 796 | qdf_mem_free(CE_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 797 | malloc_CE_state = false; |
| 798 | } |
| 799 | return NULL; |
| 800 | } else { |
| 801 | /* we can allocate src ring. |
| 802 | * Mark that the src ring is |
| 803 | * allocated locally |
| 804 | */ |
| 805 | malloc_src_ring = true; |
| 806 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 807 | /* |
| 808 | * Also allocate a shadow src ring in |
| 809 | * regular mem to use for faster access. |
| 810 | */ |
| 811 | src_ring->shadow_base_unaligned = |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 812 | qdf_mem_malloc(nentries * |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 813 | sizeof(struct CE_src_desc) + |
| 814 | CE_DESC_RING_ALIGN); |
| 815 | if (src_ring->shadow_base_unaligned == NULL) { |
| 816 | HIF_ERROR("%s: src ring no shadow_base mem", |
| 817 | __func__); |
| 818 | goto error_no_dma_mem; |
| 819 | } |
| 820 | src_ring->shadow_base = (struct CE_src_desc *) |
| 821 | (((size_t) src_ring->shadow_base_unaligned + |
| 822 | CE_DESC_RING_ALIGN - 1) & |
| 823 | ~(CE_DESC_RING_ALIGN - 1)); |
| 824 | |
Houston Hoffman | 4411ad4 | 2016-03-14 21:12:04 -0700 | [diff] [blame] | 825 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 826 | goto error_target_access; |
Houston Hoffman | f789c66 | 2016-04-12 15:39:04 -0700 | [diff] [blame] | 827 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 828 | ce_ring_setup(scn, CE_RING_SRC, CE_id, src_ring, attr); |
| 829 | |
Houston Hoffman | 4411ad4 | 2016-03-14 21:12:04 -0700 | [diff] [blame] | 830 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 831 | goto error_target_access; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 832 | ce_ring_test_initial_indexes(CE_id, src_ring, |
| 833 | "src_ring"); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | |
| 837 | /* destination ring setup */ |
| 838 | nentries = attr->dest_nentries; |
| 839 | if (nentries) { |
| 840 | struct CE_ring_state *dest_ring; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 841 | |
| 842 | nentries = roundup_pwr2(nentries); |
| 843 | if (CE_state->dest_ring) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 844 | QDF_ASSERT(CE_state->dest_ring->nentries == nentries); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 845 | } else { |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 846 | dest_ring = CE_state->dest_ring = |
| 847 | ce_alloc_ring_state(CE_state, |
| 848 | CE_RING_DEST, |
| 849 | nentries); |
| 850 | if (!dest_ring) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 851 | /* cannot allocate dst ring. If the CE_state |
| 852 | * or src ring is allocated locally free |
| 853 | * CE_State and src ring and return error. |
| 854 | */ |
| 855 | HIF_ERROR("%s: dest ring has no mem", |
| 856 | __func__); |
| 857 | if (malloc_src_ring) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 858 | qdf_mem_free(CE_state->src_ring); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 859 | CE_state->src_ring = NULL; |
| 860 | malloc_src_ring = false; |
| 861 | } |
| 862 | if (malloc_CE_state) { |
| 863 | /* allocated CE_state locally */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 864 | scn->ce_id_to_state[CE_id] = NULL; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 865 | qdf_mem_free(CE_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 866 | malloc_CE_state = false; |
| 867 | } |
| 868 | return NULL; |
| 869 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 870 | |
Houston Hoffman | 4411ad4 | 2016-03-14 21:12:04 -0700 | [diff] [blame] | 871 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 872 | goto error_target_access; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 873 | |
| 874 | ce_ring_setup(scn, CE_RING_DEST, CE_id, dest_ring, attr); |
| 875 | |
| 876 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 877 | goto error_target_access; |
Houston Hoffman | 4780817 | 2016-05-06 10:04:21 -0700 | [diff] [blame] | 878 | |
| 879 | ce_ring_test_initial_indexes(CE_id, dest_ring, |
| 880 | "dest_ring"); |
| 881 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 882 | #ifdef QCA_WIFI_QCA8074 |
| 883 | /* For srng based target, init status ring here */ |
| 884 | if (ce_srng_based(CE_state->scn)) { |
| 885 | CE_state->status_ring = |
| 886 | ce_alloc_ring_state(CE_state, |
| 887 | CE_RING_STATUS, |
| 888 | nentries); |
| 889 | if (CE_state->status_ring == NULL) { |
| 890 | /*Allocation failed. Cleanup*/ |
| 891 | qdf_mem_free(CE_state->dest_ring); |
| 892 | if (malloc_src_ring) { |
| 893 | qdf_mem_free |
| 894 | (CE_state->src_ring); |
| 895 | CE_state->src_ring = NULL; |
| 896 | malloc_src_ring = false; |
| 897 | } |
| 898 | if (malloc_CE_state) { |
| 899 | /* allocated CE_state locally */ |
| 900 | scn->ce_id_to_state[CE_id] = |
| 901 | NULL; |
| 902 | qdf_mem_free(CE_state); |
| 903 | malloc_CE_state = false; |
| 904 | } |
Houston Hoffman | 4411ad4 | 2016-03-14 21:12:04 -0700 | [diff] [blame] | 905 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 906 | return NULL; |
| 907 | } |
| 908 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 909 | goto error_target_access; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 910 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 911 | ce_ring_setup(scn, CE_RING_STATUS, CE_id, |
| 912 | CE_state->status_ring, attr); |
| 913 | |
| 914 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 915 | goto error_target_access; |
| 916 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 917 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 918 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 919 | /* epping */ |
| 920 | /* poll timer */ |
| 921 | if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 922 | qdf_timer_init(scn->qdf_dev, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 923 | &CE_state->poll_timer, |
| 924 | ce_poll_timeout, |
| 925 | CE_state, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 926 | QDF_TIMER_TYPE_SW); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 927 | CE_state->timer_inited = true; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 928 | qdf_timer_mod(&CE_state->poll_timer, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 929 | CE_POLL_TIMEOUT); |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 934 | if (!ce_srng_based(scn)) { |
| 935 | /* Enable CE error interrupts */ |
| 936 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 937 | goto error_target_access; |
| 938 | CE_ERROR_INTR_ENABLE(scn, ctrl_addr); |
| 939 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 940 | goto error_target_access; |
| 941 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 942 | |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 943 | /* update the htt_data attribute */ |
| 944 | ce_mark_datapath(CE_state); |
| 945 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 946 | return (struct CE_handle *)CE_state; |
| 947 | |
Houston Hoffman | 4411ad4 | 2016-03-14 21:12:04 -0700 | [diff] [blame] | 948 | error_target_access: |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 949 | error_no_dma_mem: |
| 950 | ce_fini((struct CE_handle *)CE_state); |
| 951 | return NULL; |
| 952 | } |
| 953 | |
| 954 | #ifdef WLAN_FEATURE_FASTPATH |
| 955 | /** |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 956 | * hif_enable_fastpath() Update that we have enabled fastpath mode |
| 957 | * @hif_ctx: HIF context |
| 958 | * |
| 959 | * For use in data path |
| 960 | * |
| 961 | * Retrun: void |
| 962 | */ |
| 963 | void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx) |
| 964 | { |
| 965 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 966 | |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 967 | HIF_INFO("%s, Enabling fastpath mode", __func__); |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 968 | scn->fastpath_mode_on = true; |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled |
| 973 | * @hif_ctx: HIF Context |
| 974 | * |
| 975 | * For use in data path to skip HTC |
| 976 | * |
| 977 | * Return: bool |
| 978 | */ |
| 979 | bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx) |
| 980 | { |
| 981 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 982 | |
| 983 | return scn->fastpath_mode_on; |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * hif_get_ce_handle - API to get CE handle for FastPath mode |
| 988 | * @hif_ctx: HIF Context |
| 989 | * @id: CopyEngine Id |
| 990 | * |
| 991 | * API to return CE handle for fastpath mode |
| 992 | * |
| 993 | * Return: void |
| 994 | */ |
| 995 | void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id) |
| 996 | { |
| 997 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
| 998 | |
| 999 | return scn->ce_id_to_state[id]; |
| 1000 | } |
| 1001 | |
| 1002 | /** |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1003 | * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup. |
| 1004 | * No processing is required inside this function. |
| 1005 | * @ce_hdl: Cope engine handle |
| 1006 | * Using an assert, this function makes sure that, |
| 1007 | * the TX CE has been processed completely. |
Houston Hoffman | 9a831ef | 2015-09-03 14:42:40 -0700 | [diff] [blame] | 1008 | * |
| 1009 | * This is called while dismantling CE structures. No other thread |
| 1010 | * should be using these structures while dismantling is occuring |
| 1011 | * therfore no locking is needed. |
| 1012 | * |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1013 | * Return: none |
| 1014 | */ |
| 1015 | void |
| 1016 | ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl) |
| 1017 | { |
| 1018 | struct CE_state *ce_state = (struct CE_state *)ce_hdl; |
| 1019 | struct CE_ring_state *src_ring = ce_state->src_ring; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1020 | struct hif_softc *sc = ce_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1021 | uint32_t sw_index, write_index; |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1022 | if (hif_is_nss_wifi_enabled(sc)) |
| 1023 | return; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1024 | |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 1025 | if (sc->fastpath_mode_on && ce_state->htt_tx_data) { |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1026 | HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE", |
| 1027 | __func__, __LINE__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1028 | sw_index = src_ring->sw_index; |
| 1029 | write_index = src_ring->sw_index; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1030 | |
| 1031 | /* At this point Tx CE should be clean */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1032 | qdf_assert_always(sw_index == write_index); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1033 | } |
| 1034 | } |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1035 | |
| 1036 | /** |
| 1037 | * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue. |
| 1038 | * @ce_hdl: Handle to CE |
| 1039 | * |
| 1040 | * These buffers are never allocated on the fly, but |
| 1041 | * are allocated only once during HIF start and freed |
| 1042 | * only once during HIF stop. |
| 1043 | * NOTE: |
| 1044 | * The assumption here is there is no in-flight DMA in progress |
| 1045 | * currently, so that buffers can be freed up safely. |
| 1046 | * |
| 1047 | * Return: NONE |
| 1048 | */ |
| 1049 | void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl) |
| 1050 | { |
| 1051 | struct CE_state *ce_state = (struct CE_state *)ce_hdl; |
| 1052 | struct CE_ring_state *dst_ring = ce_state->dest_ring; |
| 1053 | qdf_nbuf_t nbuf; |
| 1054 | int i; |
| 1055 | |
| 1056 | if (!ce_state->fastpath_handler) |
| 1057 | return; |
| 1058 | /* |
| 1059 | * when fastpath_mode is on and for datapath CEs. Unlike other CE's, |
| 1060 | * this CE is completely full: does not leave one blank space, to |
| 1061 | * distinguish between empty queue & full queue. So free all the |
| 1062 | * entries. |
| 1063 | */ |
| 1064 | for (i = 0; i < dst_ring->nentries; i++) { |
| 1065 | nbuf = dst_ring->per_transfer_context[i]; |
| 1066 | |
| 1067 | /* |
| 1068 | * The reasons for doing this check are: |
| 1069 | * 1) Protect against calling cleanup before allocating buffers |
| 1070 | * 2) In a corner case, FASTPATH_mode_on may be set, but we |
| 1071 | * could have a partially filled ring, because of a memory |
| 1072 | * allocation failure in the middle of allocating ring. |
| 1073 | * This check accounts for that case, checking |
| 1074 | * fastpath_mode_on flag or started flag would not have |
| 1075 | * covered that case. This is not in performance path, |
| 1076 | * so OK to do this. |
| 1077 | */ |
| 1078 | if (nbuf) |
| 1079 | qdf_nbuf_free(nbuf); |
| 1080 | } |
| 1081 | } |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 1082 | |
| 1083 | /** |
| 1084 | * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1 |
| 1085 | * @scn: HIF handle |
| 1086 | * |
| 1087 | * Datapath Rx CEs are special case, where we reuse all the message buffers. |
| 1088 | * Hence we have to post all the entries in the pipe, even, in the beginning |
| 1089 | * unlike for other CE pipes where one less than dest_nentries are filled in |
| 1090 | * the beginning. |
| 1091 | * |
| 1092 | * Return: None |
| 1093 | */ |
| 1094 | static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn) |
| 1095 | { |
| 1096 | int pipe_num; |
| 1097 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 1098 | |
| 1099 | if (scn->fastpath_mode_on == false) |
| 1100 | return; |
| 1101 | |
| 1102 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 1103 | struct HIF_CE_pipe_info *pipe_info = |
| 1104 | &hif_state->pipe_info[pipe_num]; |
| 1105 | struct CE_state *ce_state = |
| 1106 | scn->ce_id_to_state[pipe_info->pipe_num]; |
| 1107 | |
| 1108 | if (ce_state->htt_rx_data) |
| 1109 | atomic_inc(&pipe_info->recv_bufs_needed); |
| 1110 | } |
| 1111 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1112 | #else |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 1113 | static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1114 | { |
| 1115 | } |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1116 | |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 1117 | static inline bool ce_is_fastpath_enabled(struct hif_softc *scn) |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1118 | { |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state) |
| 1123 | { |
| 1124 | return false; |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1125 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1126 | #endif /* WLAN_FEATURE_FASTPATH */ |
| 1127 | |
| 1128 | void ce_fini(struct CE_handle *copyeng) |
| 1129 | { |
| 1130 | struct CE_state *CE_state = (struct CE_state *)copyeng; |
| 1131 | unsigned int CE_id = CE_state->id; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1132 | struct hif_softc *scn = CE_state->scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1133 | |
| 1134 | CE_state->state = CE_UNUSED; |
| 1135 | scn->ce_id_to_state[CE_id] = NULL; |
| 1136 | if (CE_state->src_ring) { |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1137 | /* Cleanup the datapath Tx ring */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1138 | ce_h2t_tx_ce_cleanup(copyeng); |
| 1139 | |
| 1140 | if (CE_state->src_ring->shadow_base_unaligned) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1141 | qdf_mem_free(CE_state->src_ring->shadow_base_unaligned); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1142 | if (CE_state->src_ring->base_addr_owner_space_unaligned) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1143 | qdf_mem_free_consistent(scn->qdf_dev, |
| 1144 | scn->qdf_dev->dev, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1145 | (CE_state->src_ring->nentries * |
| 1146 | sizeof(struct CE_src_desc) + |
| 1147 | CE_DESC_RING_ALIGN), |
| 1148 | CE_state->src_ring-> |
| 1149 | base_addr_owner_space_unaligned, |
| 1150 | CE_state->src_ring-> |
| 1151 | base_addr_CE_space, 0); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1152 | qdf_mem_free(CE_state->src_ring); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1153 | } |
| 1154 | if (CE_state->dest_ring) { |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 1155 | /* Cleanup the datapath Rx ring */ |
| 1156 | ce_t2h_msg_ce_cleanup(copyeng); |
| 1157 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1158 | if (CE_state->dest_ring->base_addr_owner_space_unaligned) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1159 | qdf_mem_free_consistent(scn->qdf_dev, |
| 1160 | scn->qdf_dev->dev, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1161 | (CE_state->dest_ring->nentries * |
| 1162 | sizeof(struct CE_dest_desc) + |
| 1163 | CE_DESC_RING_ALIGN), |
| 1164 | CE_state->dest_ring-> |
| 1165 | base_addr_owner_space_unaligned, |
| 1166 | CE_state->dest_ring-> |
| 1167 | base_addr_CE_space, 0); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1168 | qdf_mem_free(CE_state->dest_ring); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1169 | |
| 1170 | /* epping */ |
| 1171 | if (CE_state->timer_inited) { |
| 1172 | CE_state->timer_inited = false; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1173 | qdf_timer_free(&CE_state->poll_timer); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1174 | } |
| 1175 | } |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 1176 | #ifdef QCA_WIFI_QCA8074 |
| 1177 | if (CE_state->status_ring) { |
| 1178 | /* Cleanup the datapath Tx ring */ |
| 1179 | ce_h2t_tx_ce_cleanup(copyeng); |
| 1180 | |
| 1181 | if (CE_state->status_ring->shadow_base_unaligned) |
| 1182 | qdf_mem_free( |
| 1183 | CE_state->status_ring->shadow_base_unaligned); |
| 1184 | |
| 1185 | if (CE_state->status_ring->base_addr_owner_space_unaligned) |
| 1186 | qdf_mem_free_consistent(scn->qdf_dev, |
| 1187 | scn->qdf_dev->dev, |
| 1188 | (CE_state->status_ring->nentries * |
| 1189 | sizeof(struct CE_src_desc) + |
| 1190 | CE_DESC_RING_ALIGN), |
| 1191 | CE_state->status_ring-> |
| 1192 | base_addr_owner_space_unaligned, |
| 1193 | CE_state->status_ring-> |
| 1194 | base_addr_CE_space, 0); |
| 1195 | qdf_mem_free(CE_state->status_ring); |
| 1196 | } |
| 1197 | #endif |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1198 | qdf_mem_free(CE_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1199 | } |
| 1200 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1201 | void hif_detach_htc(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1202 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1203 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1204 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1205 | qdf_mem_zero(&hif_state->msg_callbacks_pending, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1206 | sizeof(hif_state->msg_callbacks_pending)); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1207 | qdf_mem_zero(&hif_state->msg_callbacks_current, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1208 | sizeof(hif_state->msg_callbacks_current)); |
| 1209 | } |
| 1210 | |
| 1211 | /* Send the first nbytes bytes of the buffer */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1212 | QDF_STATUS |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1213 | hif_send_head(struct hif_opaque_softc *hif_ctx, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1214 | uint8_t pipe, unsigned int transfer_id, unsigned int nbytes, |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1215 | qdf_nbuf_t nbuf, unsigned int data_attr) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1216 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1217 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1218 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1219 | struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]); |
| 1220 | struct CE_handle *ce_hdl = pipe_info->ce_hdl; |
| 1221 | int bytes = nbytes, nfrags = 0; |
| 1222 | struct ce_sendlist sendlist; |
| 1223 | int status, i = 0; |
| 1224 | unsigned int mux_id = 0; |
| 1225 | |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1226 | QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1227 | |
| 1228 | transfer_id = |
| 1229 | (mux_id & MUX_ID_MASK) | |
| 1230 | (transfer_id & TRANSACTION_ID_MASK); |
| 1231 | data_attr &= DESC_DATA_FLAG_MASK; |
| 1232 | /* |
| 1233 | * The common case involves sending multiple fragments within a |
| 1234 | * single download (the tx descriptor and the tx frame header). |
| 1235 | * So, optimize for the case of multiple fragments by not even |
| 1236 | * checking whether it's necessary to use a sendlist. |
| 1237 | * The overhead of using a sendlist for a single buffer download |
| 1238 | * is not a big deal, since it happens rarely (for WMI messages). |
| 1239 | */ |
| 1240 | ce_sendlist_init(&sendlist); |
| 1241 | do { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1242 | qdf_dma_addr_t frag_paddr; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1243 | int frag_bytes; |
| 1244 | |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1245 | frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags); |
| 1246 | frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1247 | /* |
| 1248 | * Clear the packet offset for all but the first CE desc. |
| 1249 | */ |
| 1250 | if (i++ > 0) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1251 | data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1252 | |
| 1253 | status = ce_sendlist_buf_add(&sendlist, frag_paddr, |
| 1254 | frag_bytes > |
| 1255 | bytes ? bytes : frag_bytes, |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1256 | qdf_nbuf_get_frag_is_wordstream |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1257 | (nbuf, |
| 1258 | nfrags) ? 0 : |
| 1259 | CE_SEND_FLAG_SWAP_DISABLE, |
| 1260 | data_attr); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1261 | if (status != QDF_STATUS_SUCCESS) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1262 | HIF_ERROR("%s: error, frag_num %d larger than limit", |
| 1263 | __func__, nfrags); |
| 1264 | return status; |
| 1265 | } |
| 1266 | bytes -= frag_bytes; |
| 1267 | nfrags++; |
| 1268 | } while (bytes > 0); |
| 1269 | |
| 1270 | /* Make sure we have resources to handle this request */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1271 | qdf_spin_lock_bh(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1272 | if (pipe_info->num_sends_allowed < nfrags) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1273 | qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1274 | ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1275 | return QDF_STATUS_E_RESOURCES; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1276 | } |
| 1277 | pipe_info->num_sends_allowed -= nfrags; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1278 | qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1279 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1280 | if (qdf_unlikely(ce_hdl == NULL)) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1281 | HIF_ERROR("%s: error CE handle is null", __func__); |
| 1282 | return A_ERROR; |
| 1283 | } |
| 1284 | |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1285 | QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1286 | DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD, |
Nirav Shah | eaa20d8 | 2016-04-25 18:01:05 +0530 | [diff] [blame] | 1287 | qdf_nbuf_data_addr(nbuf), |
Nirav Shah | 29beae0 | 2016-04-26 22:58:54 +0530 | [diff] [blame] | 1288 | sizeof(qdf_nbuf_data(nbuf)), QDF_TX)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1289 | status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1290 | QDF_ASSERT(status == QDF_STATUS_SUCCESS); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1291 | |
| 1292 | return status; |
| 1293 | } |
| 1294 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1295 | void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe, |
| 1296 | int force) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1297 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1298 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1299 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1300 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1301 | if (!force) { |
| 1302 | int resources; |
| 1303 | /* |
| 1304 | * Decide whether to actually poll for completions, or just |
| 1305 | * wait for a later chance. If there seem to be plenty of |
| 1306 | * resources left, then just wait, since checking involves |
| 1307 | * reading a CE register, which is a relatively expensive |
| 1308 | * operation. |
| 1309 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1310 | resources = hif_get_free_queue_number(hif_ctx, pipe); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1311 | /* |
| 1312 | * If at least 50% of the total resources are still available, |
| 1313 | * don't bother checking again yet. |
| 1314 | */ |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1315 | if (resources > (hif_state->host_ce_config[pipe].src_nentries >> 1)) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1316 | return; |
| 1317 | } |
| 1318 | } |
Houston Hoffman | 56e0d70 | 2016-05-05 17:48:06 -0700 | [diff] [blame] | 1319 | #if ATH_11AC_TXCOMPACT |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1320 | ce_per_engine_servicereap(scn, pipe); |
| 1321 | #else |
| 1322 | ce_per_engine_service(scn, pipe); |
| 1323 | #endif |
| 1324 | } |
| 1325 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1326 | uint16_t |
| 1327 | hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1328 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1329 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1330 | struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]); |
| 1331 | uint16_t rv; |
| 1332 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1333 | qdf_spin_lock_bh(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1334 | rv = pipe_info->num_sends_allowed; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1335 | qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1336 | return rv; |
| 1337 | } |
| 1338 | |
| 1339 | /* Called by lower (CE) layer when a send to Target completes. */ |
| 1340 | void |
| 1341 | hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1342 | void *transfer_context, qdf_dma_addr_t CE_data, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1343 | unsigned int nbytes, unsigned int transfer_id, |
| 1344 | unsigned int sw_index, unsigned int hw_index, |
| 1345 | unsigned int toeplitz_hash_result) |
| 1346 | { |
| 1347 | struct HIF_CE_pipe_info *pipe_info = |
| 1348 | (struct HIF_CE_pipe_info *)ce_context; |
| 1349 | struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1350 | struct hif_softc *scn = HIF_GET_SOFTC(hif_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1351 | unsigned int sw_idx = sw_index, hw_idx = hw_index; |
Houston Hoffman | 8511851 | 2015-09-28 14:17:11 -0700 | [diff] [blame] | 1352 | struct hif_msg_callbacks *msg_callbacks = |
Venkateswara Swamy Bandaru | 26f6f1e | 2016-10-03 19:35:57 +0530 | [diff] [blame] | 1353 | &pipe_info->pipe_callbacks; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1354 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1355 | do { |
| 1356 | /* |
Houston Hoffman | 8511851 | 2015-09-28 14:17:11 -0700 | [diff] [blame] | 1357 | * The upper layer callback will be triggered |
| 1358 | * when last fragment is complteted. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1359 | */ |
Houston Hoffman | 8511851 | 2015-09-28 14:17:11 -0700 | [diff] [blame] | 1360 | if (transfer_context != CE_SENDLIST_ITEM_CTXT) { |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 1361 | if (scn->target_status == TARGET_STATUS_RESET) |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1362 | qdf_nbuf_free(transfer_context); |
Houston Hoffman | 49794a3 | 2015-12-21 12:14:56 -0800 | [diff] [blame] | 1363 | else |
| 1364 | msg_callbacks->txCompletionHandler( |
Houston Hoffman | 8511851 | 2015-09-28 14:17:11 -0700 | [diff] [blame] | 1365 | msg_callbacks->Context, |
| 1366 | transfer_context, transfer_id, |
| 1367 | toeplitz_hash_result); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1370 | qdf_spin_lock(&pipe_info->completion_freeq_lock); |
Houston Hoffman | 8511851 | 2015-09-28 14:17:11 -0700 | [diff] [blame] | 1371 | pipe_info->num_sends_allowed++; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1372 | qdf_spin_unlock(&pipe_info->completion_freeq_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1373 | } while (ce_completed_send_next(copyeng, |
| 1374 | &ce_context, &transfer_context, |
| 1375 | &CE_data, &nbytes, &transfer_id, |
| 1376 | &sw_idx, &hw_idx, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1377 | &toeplitz_hash_result) == QDF_STATUS_SUCCESS); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1380 | /** |
| 1381 | * hif_ce_do_recv(): send message from copy engine to upper layers |
| 1382 | * @msg_callbacks: structure containing callback and callback context |
| 1383 | * @netbuff: skb containing message |
| 1384 | * @nbytes: number of bytes in the message |
| 1385 | * @pipe_info: used for the pipe_number info |
| 1386 | * |
| 1387 | * Checks the packet length, configures the lenght in the netbuff, |
| 1388 | * and calls the upper layer callback. |
| 1389 | * |
| 1390 | * return: None |
| 1391 | */ |
| 1392 | static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks, |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1393 | qdf_nbuf_t netbuf, int nbytes, |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1394 | struct HIF_CE_pipe_info *pipe_info) { |
| 1395 | if (nbytes <= pipe_info->buf_sz) { |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1396 | qdf_nbuf_set_pktlen(netbuf, nbytes); |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1397 | msg_callbacks-> |
| 1398 | rxCompletionHandler(msg_callbacks->Context, |
| 1399 | netbuf, pipe_info->pipe_num); |
| 1400 | } else { |
| 1401 | HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d", |
| 1402 | __func__, netbuf, nbytes); |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1403 | qdf_nbuf_free(netbuf); |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1407 | /* Called by lower (CE) layer when data is received from the Target. */ |
| 1408 | void |
| 1409 | hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1410 | void *transfer_context, qdf_dma_addr_t CE_data, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1411 | unsigned int nbytes, unsigned int transfer_id, |
| 1412 | unsigned int flags) |
| 1413 | { |
| 1414 | struct HIF_CE_pipe_info *pipe_info = |
| 1415 | (struct HIF_CE_pipe_info *)ce_context; |
| 1416 | struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state; |
Houston Hoffman | 18c7fc5 | 2015-09-02 11:44:42 -0700 | [diff] [blame] | 1417 | struct CE_state *ce_state = (struct CE_state *) copyeng; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1418 | struct hif_softc *scn = HIF_GET_SOFTC(hif_state); |
Houston Hoffman | e02e12d | 2016-03-14 21:11:36 -0700 | [diff] [blame] | 1419 | #ifdef HIF_PCI |
| 1420 | struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state); |
| 1421 | #endif |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1422 | struct hif_msg_callbacks *msg_callbacks = |
Venkateswara Swamy Bandaru | 26f6f1e | 2016-10-03 19:35:57 +0530 | [diff] [blame] | 1423 | &pipe_info->pipe_callbacks; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1424 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1425 | do { |
Houston Hoffman | e02e12d | 2016-03-14 21:11:36 -0700 | [diff] [blame] | 1426 | #ifdef HIF_PCI |
| 1427 | hif_pm_runtime_mark_last_busy(hif_pci_sc->dev); |
| 1428 | #endif |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1429 | qdf_nbuf_unmap_single(scn->qdf_dev, |
| 1430 | (qdf_nbuf_t) transfer_context, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1431 | QDF_DMA_FROM_DEVICE); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1432 | |
Houston Hoffman | 910c626 | 2015-09-28 12:56:25 -0700 | [diff] [blame] | 1433 | atomic_inc(&pipe_info->recv_bufs_needed); |
| 1434 | hif_post_recv_buffers_for_pipe(pipe_info); |
Komal Seelam | 6ee5590 | 2016-04-11 17:11:07 +0530 | [diff] [blame] | 1435 | if (scn->target_status == TARGET_STATUS_RESET) |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1436 | qdf_nbuf_free(transfer_context); |
Houston Hoffman | 49794a3 | 2015-12-21 12:14:56 -0800 | [diff] [blame] | 1437 | else |
| 1438 | hif_ce_do_recv(msg_callbacks, transfer_context, |
Houston Hoffman | 9c0f80a | 2015-09-28 18:36:36 -0700 | [diff] [blame] | 1439 | nbytes, pipe_info); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1440 | |
| 1441 | /* Set up force_break flag if num of receices reaches |
| 1442 | * MAX_NUM_OF_RECEIVES */ |
Houston Hoffman | 5bf441a | 2015-09-02 11:52:10 -0700 | [diff] [blame] | 1443 | ce_state->receive_count++; |
Houston Hoffman | 0565272 | 2016-04-29 16:58:59 -0700 | [diff] [blame] | 1444 | if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) { |
Houston Hoffman | 18c7fc5 | 2015-09-02 11:44:42 -0700 | [diff] [blame] | 1445 | ce_state->force_break = 1; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1446 | break; |
| 1447 | } |
| 1448 | } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context, |
| 1449 | &CE_data, &nbytes, &transfer_id, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1450 | &flags) == QDF_STATUS_SUCCESS); |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 1451 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */ |
| 1455 | |
| 1456 | void |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1457 | hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1458 | struct hif_msg_callbacks *callbacks) |
| 1459 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1460 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1461 | |
| 1462 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 1463 | spin_lock_init(&pcie_access_log_lock); |
| 1464 | #endif |
| 1465 | /* Save callbacks for later installation */ |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1466 | qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1467 | sizeof(hif_state->msg_callbacks_pending)); |
| 1468 | |
| 1469 | } |
| 1470 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1471 | int hif_completion_thread_startup(struct HIF_CE_state *hif_state) |
| 1472 | { |
| 1473 | struct CE_handle *ce_diag = hif_state->ce_diag; |
| 1474 | int pipe_num; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1475 | struct hif_softc *scn = HIF_GET_SOFTC(hif_state); |
Houston Hoffman | 9c12f7f | 2015-09-28 16:52:14 -0700 | [diff] [blame] | 1476 | struct hif_msg_callbacks *hif_msg_callbacks = |
| 1477 | &hif_state->msg_callbacks_current; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1478 | |
| 1479 | /* daemonize("hif_compl_thread"); */ |
| 1480 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1481 | if (scn->ce_count == 0) { |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 1482 | HIF_ERROR("%s: Invalid ce_count", __func__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1483 | return -EINVAL; |
| 1484 | } |
Houston Hoffman | 9c12f7f | 2015-09-28 16:52:14 -0700 | [diff] [blame] | 1485 | |
| 1486 | if (!hif_msg_callbacks || |
| 1487 | !hif_msg_callbacks->rxCompletionHandler || |
| 1488 | !hif_msg_callbacks->txCompletionHandler) { |
| 1489 | HIF_ERROR("%s: no completion handler registered", __func__); |
| 1490 | return -EFAULT; |
| 1491 | } |
| 1492 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1493 | A_TARGET_ACCESS_LIKELY(scn); |
| 1494 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 1495 | struct CE_attr attr; |
| 1496 | struct HIF_CE_pipe_info *pipe_info; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1497 | |
| 1498 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 1499 | if (pipe_info->ce_hdl == ce_diag) { |
| 1500 | continue; /* Handle Diagnostic CE specially */ |
| 1501 | } |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1502 | attr = hif_state->host_ce_config[pipe_num]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1503 | if (attr.src_nentries) { |
| 1504 | /* pipe used to send to target */ |
| 1505 | HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p", |
| 1506 | __func__, pipe_num, pipe_info); |
| 1507 | ce_send_cb_register(pipe_info->ce_hdl, |
| 1508 | hif_pci_ce_send_done, pipe_info, |
| 1509 | attr.flags & CE_ATTR_DISABLE_INTR); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1510 | pipe_info->num_sends_allowed = attr.src_nentries - 1; |
| 1511 | } |
| 1512 | if (attr.dest_nentries) { |
| 1513 | /* pipe used to receive from target */ |
| 1514 | ce_recv_cb_register(pipe_info->ce_hdl, |
| 1515 | hif_pci_ce_recv_data, pipe_info, |
| 1516 | attr.flags & CE_ATTR_DISABLE_INTR); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1517 | } |
Houston Hoffman | 6666df7 | 2015-11-30 16:48:35 -0800 | [diff] [blame] | 1518 | |
| 1519 | if (attr.src_nentries) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1520 | qdf_spinlock_create(&pipe_info->completion_freeq_lock); |
Venkateswara Swamy Bandaru | 26f6f1e | 2016-10-03 19:35:57 +0530 | [diff] [blame] | 1521 | |
| 1522 | qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks, |
| 1523 | sizeof(pipe_info->pipe_callbacks)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1524 | } |
Houston Hoffman | 6666df7 | 2015-11-30 16:48:35 -0800 | [diff] [blame] | 1525 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1526 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1530 | /* |
| 1531 | * Install pending msg callbacks. |
| 1532 | * |
| 1533 | * TBDXXX: This hack is needed because upper layers install msg callbacks |
| 1534 | * for use with HTC before BMI is done; yet this HIF implementation |
| 1535 | * needs to continue to use BMI msg callbacks. Really, upper layers |
| 1536 | * should not register HTC callbacks until AFTER BMI phase. |
| 1537 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1538 | static void hif_msg_callbacks_install(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1539 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1540 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1541 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1542 | qdf_mem_copy(&hif_state->msg_callbacks_current, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1543 | &hif_state->msg_callbacks_pending, |
| 1544 | sizeof(hif_state->msg_callbacks_pending)); |
| 1545 | } |
| 1546 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1547 | void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe, |
| 1548 | uint8_t *DLPipe) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1549 | { |
| 1550 | int ul_is_polled, dl_is_polled; |
| 1551 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1552 | (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1553 | ULPipe, DLPipe, &ul_is_polled, &dl_is_polled); |
| 1554 | } |
| 1555 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1556 | /** |
| 1557 | * hif_dump_pipe_debug_count() - Log error count |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1558 | * @scn: hif_softc pointer. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1559 | * |
| 1560 | * Output the pipe error counts of each pipe to log file |
| 1561 | * |
| 1562 | * Return: N/A |
| 1563 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1564 | void hif_dump_pipe_debug_count(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1565 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1566 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1567 | int pipe_num; |
| 1568 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1569 | if (hif_state == NULL) { |
| 1570 | HIF_ERROR("%s hif_state is NULL", __func__); |
| 1571 | return; |
| 1572 | } |
| 1573 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 1574 | struct HIF_CE_pipe_info *pipe_info; |
| 1575 | |
| 1576 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 1577 | |
| 1578 | if (pipe_info->nbuf_alloc_err_count > 0 || |
| 1579 | pipe_info->nbuf_dma_err_count > 0 || |
| 1580 | pipe_info->nbuf_ce_enqueue_err_count) |
| 1581 | HIF_ERROR( |
| 1582 | "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u", |
| 1583 | __func__, pipe_info->pipe_num, |
| 1584 | atomic_read(&pipe_info->recv_bufs_needed), |
| 1585 | pipe_info->nbuf_alloc_err_count, |
| 1586 | pipe_info->nbuf_dma_err_count, |
| 1587 | pipe_info->nbuf_ce_enqueue_err_count); |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info) |
| 1592 | { |
| 1593 | struct CE_handle *ce_hdl; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1594 | qdf_size_t buf_sz; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1595 | struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1596 | QDF_STATUS ret; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1597 | uint32_t bufs_posted = 0; |
| 1598 | |
| 1599 | buf_sz = pipe_info->buf_sz; |
| 1600 | if (buf_sz == 0) { |
| 1601 | /* Unused Copy Engine */ |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | ce_hdl = pipe_info->ce_hdl; |
| 1606 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1607 | qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1608 | while (atomic_read(&pipe_info->recv_bufs_needed) > 0) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1609 | qdf_dma_addr_t CE_data; /* CE space buffer address */ |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1610 | qdf_nbuf_t nbuf; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1611 | int status; |
| 1612 | |
| 1613 | atomic_dec(&pipe_info->recv_bufs_needed); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1614 | qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1615 | |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1616 | nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1617 | if (!nbuf) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1618 | qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1619 | pipe_info->nbuf_alloc_err_count++; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1620 | qdf_spin_unlock_bh( |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1621 | &pipe_info->recv_bufs_needed_lock); |
| 1622 | HIF_ERROR( |
| 1623 | "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u", |
| 1624 | __func__, pipe_info->pipe_num, |
| 1625 | atomic_read(&pipe_info->recv_bufs_needed), |
| 1626 | pipe_info->nbuf_alloc_err_count); |
| 1627 | atomic_inc(&pipe_info->recv_bufs_needed); |
| 1628 | return 1; |
| 1629 | } |
| 1630 | |
| 1631 | /* |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1632 | * qdf_nbuf_peek_header(nbuf, &data, &unused); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1633 | * CE_data = dma_map_single(dev, data, buf_sz, ); |
| 1634 | * DMA_FROM_DEVICE); |
| 1635 | */ |
| 1636 | ret = |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1637 | qdf_nbuf_map_single(scn->qdf_dev, nbuf, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1638 | QDF_DMA_FROM_DEVICE); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1639 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1640 | if (unlikely(ret != QDF_STATUS_SUCCESS)) { |
| 1641 | qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1642 | pipe_info->nbuf_dma_err_count++; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1643 | qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1644 | HIF_ERROR( |
| 1645 | "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u", |
| 1646 | __func__, pipe_info->pipe_num, |
| 1647 | atomic_read(&pipe_info->recv_bufs_needed), |
| 1648 | pipe_info->nbuf_dma_err_count); |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1649 | qdf_nbuf_free(nbuf); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1650 | atomic_inc(&pipe_info->recv_bufs_needed); |
| 1651 | return 1; |
| 1652 | } |
| 1653 | |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1654 | CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1655 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1656 | qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1657 | buf_sz, DMA_FROM_DEVICE); |
| 1658 | status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1659 | QDF_ASSERT(status == QDF_STATUS_SUCCESS); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1660 | if (status != EOK) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1661 | qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1662 | pipe_info->nbuf_ce_enqueue_err_count++; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1663 | qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1664 | HIF_ERROR( |
| 1665 | "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u", |
| 1666 | __func__, pipe_info->pipe_num, |
| 1667 | atomic_read(&pipe_info->recv_bufs_needed), |
| 1668 | pipe_info->nbuf_ce_enqueue_err_count); |
Govind Singh | 4fcafd4 | 2016-08-08 12:37:31 +0530 | [diff] [blame] | 1669 | qdf_nbuf_unmap_single(scn->qdf_dev, nbuf, |
| 1670 | QDF_DMA_FROM_DEVICE); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1671 | atomic_inc(&pipe_info->recv_bufs_needed); |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1672 | qdf_nbuf_free(nbuf); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1673 | return 1; |
| 1674 | } |
| 1675 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1676 | qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1677 | bufs_posted++; |
| 1678 | } |
| 1679 | pipe_info->nbuf_alloc_err_count = |
Houston Hoffman | 5693683 | 2016-03-16 12:16:24 -0700 | [diff] [blame] | 1680 | (pipe_info->nbuf_alloc_err_count > bufs_posted) ? |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1681 | pipe_info->nbuf_alloc_err_count - bufs_posted : 0; |
| 1682 | pipe_info->nbuf_dma_err_count = |
Houston Hoffman | 5693683 | 2016-03-16 12:16:24 -0700 | [diff] [blame] | 1683 | (pipe_info->nbuf_dma_err_count > bufs_posted) ? |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1684 | pipe_info->nbuf_dma_err_count - bufs_posted : 0; |
| 1685 | pipe_info->nbuf_ce_enqueue_err_count = |
Houston Hoffman | 5693683 | 2016-03-16 12:16:24 -0700 | [diff] [blame] | 1686 | (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ? |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1687 | pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0; |
| 1688 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1689 | qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1690 | |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | /* |
| 1695 | * Try to post all desired receive buffers for all pipes. |
| 1696 | * Returns 0 if all desired buffers are posted, |
| 1697 | * non-zero if were were unable to completely |
| 1698 | * replenish receive buffers. |
| 1699 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1700 | static int hif_post_recv_buffers(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1701 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1702 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1703 | int pipe_num, rv = 0; |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1704 | struct CE_state *ce_state; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1705 | |
| 1706 | A_TARGET_ACCESS_LIKELY(scn); |
| 1707 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 1708 | struct HIF_CE_pipe_info *pipe_info; |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1709 | ce_state = scn->ce_id_to_state[pipe_num]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1710 | pipe_info = &hif_state->pipe_info[pipe_num]; |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1711 | |
| 1712 | if (hif_is_nss_wifi_enabled(scn) && |
| 1713 | ce_state && (ce_state->htt_rx_data)) { |
| 1714 | continue; |
| 1715 | } |
| 1716 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1717 | if (hif_post_recv_buffers_for_pipe(pipe_info)) { |
| 1718 | rv = 1; |
| 1719 | goto done; |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | done: |
| 1724 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 1725 | |
| 1726 | return rv; |
| 1727 | } |
| 1728 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1729 | QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1730 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1731 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1732 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1733 | |
Manjunathappa Prakash | 4a9c3a8 | 2016-04-14 01:12:14 -0700 | [diff] [blame] | 1734 | hif_update_fastpath_recv_bufs_cnt(scn); |
| 1735 | |
Houston Hoffman | 9c12f7f | 2015-09-28 16:52:14 -0700 | [diff] [blame] | 1736 | hif_msg_callbacks_install(scn); |
| 1737 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1738 | if (hif_completion_thread_startup(hif_state)) |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1739 | return QDF_STATUS_E_FAILURE; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1740 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1741 | /* Post buffers once to start things off. */ |
| 1742 | (void)hif_post_recv_buffers(scn); |
| 1743 | |
| 1744 | hif_state->started = true; |
| 1745 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1746 | return QDF_STATUS_SUCCESS; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1749 | void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info) |
| 1750 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1751 | struct hif_softc *scn; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1752 | struct CE_handle *ce_hdl; |
| 1753 | uint32_t buf_sz; |
| 1754 | struct HIF_CE_state *hif_state; |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1755 | qdf_nbuf_t netbuf; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1756 | qdf_dma_addr_t CE_data; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1757 | void *per_CE_context; |
| 1758 | |
| 1759 | buf_sz = pipe_info->buf_sz; |
| 1760 | if (buf_sz == 0) { |
| 1761 | /* Unused Copy Engine */ |
| 1762 | return; |
| 1763 | } |
| 1764 | |
| 1765 | hif_state = pipe_info->HIF_CE_state; |
| 1766 | if (!hif_state->started) { |
| 1767 | return; |
| 1768 | } |
| 1769 | |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1770 | scn = HIF_GET_SOFTC(hif_state); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1771 | ce_hdl = pipe_info->ce_hdl; |
| 1772 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1773 | if (scn->qdf_dev == NULL) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1774 | return; |
| 1775 | } |
| 1776 | while (ce_revoke_recv_next |
| 1777 | (ce_hdl, &per_CE_context, (void **)&netbuf, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1778 | &CE_data) == QDF_STATUS_SUCCESS) { |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1779 | qdf_nbuf_unmap_single(scn->qdf_dev, netbuf, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1780 | QDF_DMA_FROM_DEVICE); |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1781 | qdf_nbuf_free(netbuf); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info) |
| 1786 | { |
| 1787 | struct CE_handle *ce_hdl; |
| 1788 | struct HIF_CE_state *hif_state; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1789 | struct hif_softc *scn; |
Vishwajith Upendra | 70f8b6e | 2016-03-01 16:28:23 +0530 | [diff] [blame] | 1790 | qdf_nbuf_t netbuf; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1791 | void *per_CE_context; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1792 | qdf_dma_addr_t CE_data; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1793 | unsigned int nbytes; |
| 1794 | unsigned int id; |
| 1795 | uint32_t buf_sz; |
| 1796 | uint32_t toeplitz_hash_result; |
| 1797 | |
| 1798 | buf_sz = pipe_info->buf_sz; |
| 1799 | if (buf_sz == 0) { |
| 1800 | /* Unused Copy Engine */ |
| 1801 | return; |
| 1802 | } |
| 1803 | |
| 1804 | hif_state = pipe_info->HIF_CE_state; |
| 1805 | if (!hif_state->started) { |
| 1806 | return; |
| 1807 | } |
| 1808 | |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1809 | scn = HIF_GET_SOFTC(hif_state); |
| 1810 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1811 | ce_hdl = pipe_info->ce_hdl; |
| 1812 | |
| 1813 | while (ce_cancel_send_next |
| 1814 | (ce_hdl, &per_CE_context, |
| 1815 | (void **)&netbuf, &CE_data, &nbytes, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1816 | &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1817 | if (netbuf != CE_SENDLIST_ITEM_CTXT) { |
| 1818 | /* |
| 1819 | * Packets enqueued by htt_h2t_ver_req_msg() and |
| 1820 | * htt_h2t_rx_ring_cfg_msg_ll() have already been |
| 1821 | * freed in htt_htc_misc_pkt_pool_free() in |
| 1822 | * wlantl_close(), so do not free them here again |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1823 | * by checking whether it's the endpoint |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1824 | * which they are queued in. |
| 1825 | */ |
Nirav Shah | d7f9159 | 2016-04-21 14:18:43 +0530 | [diff] [blame] | 1826 | if (id == scn->htc_htt_tx_endpoint) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1827 | return; |
Nirav Shah | d7f9159 | 2016-04-21 14:18:43 +0530 | [diff] [blame] | 1828 | /* Indicate the completion to higher |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1829 | * layer to free the buffer */ |
Venkateswara Swamy Bandaru | 26f6f1e | 2016-10-03 19:35:57 +0530 | [diff] [blame] | 1830 | if (pipe_info->pipe_callbacks. |
Himanshu Agarwal | 8d0cdea | 2016-09-02 21:05:01 +0530 | [diff] [blame] | 1831 | txCompletionHandler) |
Venkateswara Swamy Bandaru | 26f6f1e | 2016-10-03 19:35:57 +0530 | [diff] [blame] | 1832 | pipe_info->pipe_callbacks. |
| 1833 | txCompletionHandler(pipe_info-> |
| 1834 | pipe_callbacks.Context, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1835 | netbuf, id, toeplitz_hash_result); |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * Cleanup residual buffers for device shutdown: |
| 1842 | * buffers that were enqueued for receive |
| 1843 | * buffers that were to be sent |
| 1844 | * Note: Buffers that had completed but which were |
| 1845 | * not yet processed are on a completion queue. They |
| 1846 | * are handled when the completion thread shuts down. |
| 1847 | */ |
| 1848 | void hif_buffer_cleanup(struct HIF_CE_state *hif_state) |
| 1849 | { |
| 1850 | int pipe_num; |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1851 | struct hif_softc *scn = HIF_GET_SOFTC(hif_state); |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1852 | struct CE_state *ce_state; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1853 | |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1854 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1855 | struct HIF_CE_pipe_info *pipe_info; |
| 1856 | |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 1857 | ce_state = scn->ce_id_to_state[pipe_num]; |
| 1858 | if (hif_is_nss_wifi_enabled(scn) && ce_state && |
| 1859 | ((ce_state->htt_tx_data) || |
| 1860 | (ce_state->htt_rx_data))) { |
| 1861 | continue; |
| 1862 | } |
| 1863 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1864 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 1865 | hif_recv_buffer_cleanup_on_pipe(pipe_info); |
| 1866 | hif_send_buffer_cleanup_on_pipe(pipe_info); |
| 1867 | } |
| 1868 | } |
| 1869 | |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 1870 | void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1871 | { |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1872 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 1873 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 1874 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1875 | hif_buffer_cleanup(hif_state); |
| 1876 | } |
| 1877 | |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 1878 | void hif_ce_stop(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1879 | { |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 1880 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1881 | int pipe_num; |
| 1882 | |
| 1883 | scn->hif_init_done = false; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1884 | |
| 1885 | /* |
| 1886 | * At this point, asynchronous threads are stopped, |
| 1887 | * The Target should not DMA nor interrupt, Host code may |
| 1888 | * not initiate anything more. So we just need to clean |
| 1889 | * up Host-side state. |
| 1890 | */ |
| 1891 | |
| 1892 | if (scn->athdiag_procfs_inited) { |
| 1893 | athdiag_procfs_remove(); |
| 1894 | scn->athdiag_procfs_inited = false; |
| 1895 | } |
| 1896 | |
| 1897 | hif_buffer_cleanup(hif_state); |
| 1898 | |
| 1899 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 1900 | struct HIF_CE_pipe_info *pipe_info; |
| 1901 | |
| 1902 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 1903 | if (pipe_info->ce_hdl) { |
| 1904 | ce_fini(pipe_info->ce_hdl); |
| 1905 | pipe_info->ce_hdl = NULL; |
| 1906 | pipe_info->buf_sz = 0; |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | if (hif_state->sleep_timer_init) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1911 | qdf_timer_stop(&hif_state->sleep_timer); |
| 1912 | qdf_timer_free(&hif_state->sleep_timer); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1913 | hif_state->sleep_timer_init = false; |
| 1914 | } |
| 1915 | |
| 1916 | hif_state->started = false; |
| 1917 | } |
| 1918 | |
Houston Hoffman | 854e67f | 2016-03-14 21:11:39 -0700 | [diff] [blame] | 1919 | /** |
| 1920 | * hif_get_target_ce_config() - get copy engine configuration |
| 1921 | * @target_ce_config_ret: basic copy engine configuration |
| 1922 | * @target_ce_config_sz_ret: size of the basic configuration in bytes |
| 1923 | * @target_service_to_ce_map_ret: service mapping for the copy engines |
| 1924 | * @target_service_to_ce_map_sz_ret: size of the mapping in bytes |
| 1925 | * @target_shadow_reg_cfg_ret: shadow register configuration |
| 1926 | * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes |
| 1927 | * |
| 1928 | * providing accessor to these values outside of this file. |
| 1929 | * currently these are stored in static pointers to const sections. |
| 1930 | * there are multiple configurations that are selected from at compile time. |
| 1931 | * Runtime selection would need to consider mode, target type and bus type. |
| 1932 | * |
| 1933 | * Return: return by parameter. |
| 1934 | */ |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1935 | void hif_get_target_ce_config(struct hif_softc *scn, |
| 1936 | struct CE_pipe_config **target_ce_config_ret, |
Houston Hoffman | 854e67f | 2016-03-14 21:11:39 -0700 | [diff] [blame] | 1937 | int *target_ce_config_sz_ret, |
| 1938 | struct service_to_pipe **target_service_to_ce_map_ret, |
| 1939 | int *target_service_to_ce_map_sz_ret, |
| 1940 | struct shadow_reg_cfg **target_shadow_reg_cfg_ret, |
| 1941 | int *shadow_cfg_sz_ret) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1942 | { |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1943 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 1944 | |
| 1945 | *target_ce_config_ret = hif_state->target_ce_config; |
| 1946 | *target_ce_config_sz_ret = hif_state->target_ce_config_sz; |
Houston Hoffman | 854e67f | 2016-03-14 21:11:39 -0700 | [diff] [blame] | 1947 | *target_service_to_ce_map_ret = target_service_to_ce_map; |
| 1948 | *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz; |
| 1949 | |
| 1950 | if (target_shadow_reg_cfg_ret) |
| 1951 | *target_shadow_reg_cfg_ret = target_shadow_reg_cfg; |
| 1952 | |
| 1953 | if (shadow_cfg_sz_ret) |
| 1954 | *shadow_cfg_sz_ret = shadow_cfg_sz; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1955 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1956 | |
| 1957 | /** |
| 1958 | * hif_wlan_enable(): call the platform driver to enable wlan |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 1959 | * @scn: HIF Context |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1960 | * |
| 1961 | * This function passes the con_mode and CE configuration to |
| 1962 | * platform driver to enable wlan. |
| 1963 | * |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 1964 | * Return: linux error code |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1965 | */ |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 1966 | int hif_wlan_enable(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1967 | { |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 1968 | struct pld_wlan_enable_cfg cfg; |
| 1969 | enum pld_driver_mode mode; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 1970 | uint32_t con_mode = hif_get_conparam(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1971 | |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 1972 | hif_get_target_ce_config(scn, |
| 1973 | (struct CE_pipe_config **)&cfg.ce_tgt_cfg, |
Houston Hoffman | 854e67f | 2016-03-14 21:11:39 -0700 | [diff] [blame] | 1974 | &cfg.num_ce_tgt_cfg, |
| 1975 | (struct service_to_pipe **)&cfg.ce_svc_cfg, |
| 1976 | &cfg.num_ce_svc_pipe_cfg, |
| 1977 | (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg, |
| 1978 | &cfg.num_shadow_reg_cfg); |
| 1979 | |
| 1980 | /* translate from structure size to array size */ |
| 1981 | cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config); |
| 1982 | cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe); |
| 1983 | cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1984 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 1985 | if (QDF_GLOBAL_FTM_MODE == con_mode) |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 1986 | mode = PLD_FTM; |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 1987 | else if (QDF_IS_EPPING_ENABLED(con_mode)) |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 1988 | mode = PLD_EPPING; |
Peng Xu | 7b96253 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 1989 | else |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 1990 | mode = PLD_MISSION; |
Peng Xu | 7b96253 | 2015-10-02 17:17:03 -0700 | [diff] [blame] | 1991 | |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 1992 | if (BYPASS_QMI) |
| 1993 | return 0; |
| 1994 | else |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 1995 | return pld_wlan_enable(scn->qdf_dev->dev, &cfg, |
| 1996 | mode, QWLAN_VERSIONSTR); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 1999 | #define CE_EPPING_USES_IRQ true |
| 2000 | |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2001 | /** |
| 2002 | * hif_ce_prepare_config() - load the correct static tables. |
| 2003 | * @scn: hif context |
| 2004 | * |
| 2005 | * Epping uses different static attribute tables than mission mode. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2006 | */ |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2007 | void hif_ce_prepare_config(struct hif_softc *scn) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2008 | { |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 2009 | uint32_t mode = hif_get_conparam(scn); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2010 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); |
| 2011 | struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl); |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2012 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2013 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2014 | /* if epping is enabled we need to use the epping configuration. */ |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 2015 | if (QDF_IS_EPPING_ENABLED(mode)) { |
| 2016 | if (CE_EPPING_USES_IRQ) |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2017 | hif_state->host_ce_config = host_ce_config_wlan_epping_irq; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2018 | else |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2019 | hif_state->host_ce_config = host_ce_config_wlan_epping_poll; |
| 2020 | hif_state->target_ce_config = target_ce_config_wlan_epping; |
| 2021 | hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2022 | target_service_to_ce_map = |
| 2023 | target_service_to_ce_map_wlan_epping; |
| 2024 | target_service_to_ce_map_sz = |
| 2025 | sizeof(target_service_to_ce_map_wlan_epping); |
Vishwajith Upendra | 70efc75 | 2016-04-18 11:23:49 -0700 | [diff] [blame] | 2026 | target_shadow_reg_cfg = target_shadow_reg_cfg_epping; |
| 2027 | shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2028 | } |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2029 | |
| 2030 | switch (tgt_info->target_type) { |
| 2031 | default: |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2032 | hif_state->host_ce_config = host_ce_config_wlan; |
| 2033 | hif_state->target_ce_config = target_ce_config_wlan; |
| 2034 | hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2035 | break; |
| 2036 | case TARGET_TYPE_AR900B: |
| 2037 | case TARGET_TYPE_QCA9984: |
| 2038 | case TARGET_TYPE_IPQ4019: |
| 2039 | case TARGET_TYPE_QCA9888: |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2040 | hif_state->host_ce_config = host_ce_config_wlan_ar900b; |
| 2041 | hif_state->target_ce_config = target_ce_config_wlan_ar900b; |
| 2042 | hif_state->target_ce_config_sz = |
| 2043 | sizeof(target_ce_config_wlan_ar900b); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2044 | |
| 2045 | target_service_to_ce_map = target_service_to_ce_map_ar900b; |
| 2046 | target_service_to_ce_map_sz = |
| 2047 | sizeof(target_service_to_ce_map_ar900b); |
| 2048 | break; |
| 2049 | |
| 2050 | case TARGET_TYPE_AR9888: |
| 2051 | case TARGET_TYPE_AR9888V2: |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2052 | hif_state->host_ce_config = host_ce_config_wlan_ar9888; |
| 2053 | hif_state->target_ce_config = target_ce_config_wlan_ar9888; |
| 2054 | hif_state->target_ce_config_sz = |
| 2055 | sizeof(target_ce_config_wlan_ar9888); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2056 | |
| 2057 | target_service_to_ce_map = target_service_to_ce_map_ar900b; |
| 2058 | target_service_to_ce_map_sz = |
| 2059 | sizeof(target_service_to_ce_map_ar900b); |
| 2060 | break; |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 2061 | #ifdef QCA_WIFI_QCA8074 |
| 2062 | case TARGET_TYPE_QCA8074: |
| 2063 | hif_state->host_ce_config = host_ce_config_wlan_qca8074; |
| 2064 | hif_state->target_ce_config = target_ce_config_wlan_qca8074; |
| 2065 | hif_state->target_ce_config_sz = |
| 2066 | sizeof(target_ce_config_wlan_qca8074); |
| 2067 | break; |
| 2068 | #endif |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2069 | } |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2070 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2071 | |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2072 | /** |
| 2073 | * hif_ce_open() - do ce specific allocations |
| 2074 | * @hif_sc: pointer to hif context |
| 2075 | * |
| 2076 | * return: 0 for success or QDF_STATUS_E_NOMEM |
| 2077 | */ |
| 2078 | QDF_STATUS hif_ce_open(struct hif_softc *hif_sc) |
| 2079 | { |
| 2080 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2081 | |
Venkateswara Swamy Bandaru | 9fd9af0 | 2016-09-20 20:27:31 +0530 | [diff] [blame] | 2082 | qdf_spinlock_create(&hif_state->irq_reg_lock); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2083 | qdf_spinlock_create(&hif_state->keep_awake_lock); |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2084 | return QDF_STATUS_SUCCESS; |
| 2085 | } |
| 2086 | |
| 2087 | /** |
| 2088 | * hif_ce_close() - do ce specific free |
| 2089 | * @hif_sc: pointer to hif context |
| 2090 | */ |
| 2091 | void hif_ce_close(struct hif_softc *hif_sc) |
| 2092 | { |
Venkateswara Swamy Bandaru | 9fd9af0 | 2016-09-20 20:27:31 +0530 | [diff] [blame] | 2093 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc); |
| 2094 | |
| 2095 | qdf_spinlock_destroy(&hif_state->irq_reg_lock); |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * hif_unconfig_ce() - ensure resources from hif_config_ce are freed |
| 2100 | * @hif_sc: hif context |
| 2101 | * |
| 2102 | * uses state variables to support cleaning up when hif_config_ce fails. |
| 2103 | */ |
| 2104 | void hif_unconfig_ce(struct hif_softc *hif_sc) |
| 2105 | { |
| 2106 | int pipe_num; |
| 2107 | struct HIF_CE_pipe_info *pipe_info; |
| 2108 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc); |
| 2109 | |
| 2110 | for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) { |
| 2111 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 2112 | if (pipe_info->ce_hdl) { |
| 2113 | ce_unregister_irq(hif_state, (1 << pipe_num)); |
| 2114 | hif_sc->request_irq_done = false; |
| 2115 | ce_fini(pipe_info->ce_hdl); |
| 2116 | pipe_info->ce_hdl = NULL; |
| 2117 | pipe_info->buf_sz = 0; |
| 2118 | } |
| 2119 | } |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2120 | if (hif_sc->athdiag_procfs_inited) { |
| 2121 | athdiag_procfs_remove(); |
| 2122 | hif_sc->athdiag_procfs_inited = false; |
| 2123 | } |
| 2124 | } |
| 2125 | |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 2126 | #ifdef CONFIG_BYPASS_QMI |
| 2127 | #define FW_SHARED_MEM (2 * 1024 * 1024) |
| 2128 | |
| 2129 | /** |
| 2130 | * hif_post_static_buf_to_target() - post static buffer to WLAN FW |
| 2131 | * @scn: pointer to HIF structure |
| 2132 | * |
| 2133 | * WLAN FW needs 2MB memory from DDR when QMI is disabled. |
| 2134 | * |
| 2135 | * Return: void |
| 2136 | */ |
| 2137 | static void hif_post_static_buf_to_target(struct hif_softc *scn) |
| 2138 | { |
Hardik Kantilal Patel | c5dc5f2 | 2016-04-21 14:11:33 -0700 | [diff] [blame] | 2139 | void *target_va; |
| 2140 | phys_addr_t target_pa; |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 2141 | |
Hardik Kantilal Patel | c5dc5f2 | 2016-04-21 14:11:33 -0700 | [diff] [blame] | 2142 | target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev, |
| 2143 | FW_SHARED_MEM, &target_pa); |
| 2144 | if (NULL == target_va) { |
| 2145 | HIF_TRACE("Memory allocation failed could not post target buf"); |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 2146 | return; |
| 2147 | } |
Hardik Kantilal Patel | c5dc5f2 | 2016-04-21 14:11:33 -0700 | [diff] [blame] | 2148 | hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa); |
| 2149 | HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa); |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 2150 | } |
| 2151 | #else |
| 2152 | static inline void hif_post_static_buf_to_target(struct hif_softc *scn) |
| 2153 | { |
| 2154 | return; |
| 2155 | } |
| 2156 | #endif |
| 2157 | |
Dustin Brown | 6bdbda5 | 2016-09-27 15:52:30 -0700 | [diff] [blame^] | 2158 | #ifdef WLAN_SUSPEND_RESUME_TEST |
| 2159 | static void hif_fake_apps_init_ctx(struct hif_softc *scn) |
| 2160 | { |
| 2161 | INIT_WORK(&scn->fake_apps_ctx.resume_work, |
| 2162 | hif_fake_apps_resume_work); |
| 2163 | } |
| 2164 | #else |
| 2165 | static inline void hif_fake_apps_init_ctx(struct hif_softc *scn) {} |
| 2166 | #endif |
| 2167 | |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2168 | /** |
| 2169 | * hif_config_ce() - configure copy engines |
| 2170 | * @scn: hif context |
| 2171 | * |
| 2172 | * Prepares fw, copy engine hardware and host sw according |
| 2173 | * to the attributes selected by hif_ce_prepare_config. |
| 2174 | * |
| 2175 | * also calls athdiag_procfs_init |
| 2176 | * |
| 2177 | * return: 0 for success nonzero for failure. |
| 2178 | */ |
| 2179 | int hif_config_ce(struct hif_softc *scn) |
| 2180 | { |
| 2181 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 2182 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); |
| 2183 | struct HIF_CE_pipe_info *pipe_info; |
| 2184 | int pipe_num; |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 2185 | struct CE_state *ce_state; |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2186 | #ifdef ADRASTEA_SHADOW_REGISTERS |
| 2187 | int i; |
| 2188 | #endif |
| 2189 | QDF_STATUS rv = QDF_STATUS_SUCCESS; |
| 2190 | |
| 2191 | scn->notice_send = true; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2192 | |
Yuanyuan Liu | a7a282f | 2016-04-15 12:55:04 -0700 | [diff] [blame] | 2193 | hif_post_static_buf_to_target(scn); |
| 2194 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2195 | hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS; |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2196 | |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2197 | hif_config_rri_on_ddr(scn); |
| 2198 | |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 2199 | hif_state->ce_services = ce_services_attach(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2200 | /* During CE initializtion */ |
| 2201 | scn->ce_count = HOST_CE_COUNT; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2202 | for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) { |
| 2203 | struct CE_attr *attr; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2204 | pipe_info = &hif_state->pipe_info[pipe_num]; |
| 2205 | pipe_info->pipe_num = pipe_num; |
| 2206 | pipe_info->HIF_CE_state = hif_state; |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2207 | attr = &hif_state->host_ce_config[pipe_num]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2208 | pipe_info->ce_hdl = ce_init(scn, pipe_num, attr); |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 2209 | ce_state = scn->ce_id_to_state[pipe_num]; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2210 | QDF_ASSERT(pipe_info->ce_hdl != NULL); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2211 | if (pipe_info->ce_hdl == NULL) { |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2212 | rv = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2213 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 2214 | goto err; |
| 2215 | } |
| 2216 | |
| 2217 | if (pipe_num == DIAG_CE_ID) { |
| 2218 | /* Reserve the ultimate CE for |
| 2219 | * Diagnostic Window support */ |
Houston Hoffman | c1d9a41 | 2016-03-30 21:07:57 -0700 | [diff] [blame] | 2220 | hif_state->ce_diag = pipe_info->ce_hdl; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2221 | continue; |
| 2222 | } |
| 2223 | |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 2224 | if (hif_is_nss_wifi_enabled(scn) && ce_state && |
| 2225 | (ce_state->htt_rx_data)) |
| 2226 | continue; |
| 2227 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2228 | pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max); |
| 2229 | qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2230 | if (attr->dest_nentries > 0) { |
| 2231 | atomic_set(&pipe_info->recv_bufs_needed, |
| 2232 | init_buffer_count(attr->dest_nentries - 1)); |
Kiran Venkatappa | f41ef2e | 2016-09-05 10:59:58 +0530 | [diff] [blame] | 2233 | /*SRNG based CE has one entry less */ |
| 2234 | if (ce_srng_based(scn)) |
| 2235 | atomic_dec(&pipe_info->recv_bufs_needed); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2236 | } else { |
| 2237 | atomic_set(&pipe_info->recv_bufs_needed, 0); |
| 2238 | } |
| 2239 | ce_tasklet_init(hif_state, (1 << pipe_num)); |
| 2240 | ce_register_irq(hif_state, (1 << pipe_num)); |
| 2241 | scn->request_irq_done = true; |
| 2242 | } |
| 2243 | |
| 2244 | if (athdiag_procfs_init(scn) != 0) { |
| 2245 | A_TARGET_ACCESS_UNLIKELY(scn); |
| 2246 | goto err; |
| 2247 | } |
| 2248 | scn->athdiag_procfs_inited = true; |
| 2249 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2250 | HIF_INFO_MED("%s: ce_init done", __func__); |
| 2251 | |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2252 | init_tasklet_workers(hif_hdl); |
Dustin Brown | 6bdbda5 | 2016-09-27 15:52:30 -0700 | [diff] [blame^] | 2253 | hif_fake_apps_init_ctx(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2254 | |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2255 | HIF_TRACE("%s: X, ret = %d", __func__, rv); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2256 | |
| 2257 | #ifdef ADRASTEA_SHADOW_REGISTERS |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2258 | HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2259 | for (i = 0; i < NUM_SHADOW_REGISTERS; i++) { |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2260 | HIF_INFO("%s Shadow Register%d is mapped to address %x", |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2261 | __func__, i, |
| 2262 | (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2)); |
| 2263 | } |
| 2264 | #endif |
| 2265 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2266 | return rv != QDF_STATUS_SUCCESS; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2267 | |
| 2268 | err: |
| 2269 | /* Failure, so clean up */ |
Houston Hoffman | 108da40 | 2016-03-14 21:11:24 -0700 | [diff] [blame] | 2270 | hif_unconfig_ce(scn); |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2271 | HIF_TRACE("%s: X, ret = %d", __func__, rv); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2272 | return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2273 | } |
| 2274 | |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2275 | #ifdef WLAN_FEATURE_FASTPATH |
| 2276 | /** |
| 2277 | * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler |
| 2278 | * @handler: Callback funtcion |
| 2279 | * @context: handle for callback function |
| 2280 | * |
| 2281 | * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE |
| 2282 | */ |
Houston Hoffman | 127467f | 2016-04-26 22:37:14 -0700 | [diff] [blame] | 2283 | int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx, |
| 2284 | fastpath_msg_handler handler, |
| 2285 | void *context) |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2286 | { |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2287 | struct CE_state *ce_state; |
Houston Hoffman | 127467f | 2016-04-26 22:37:14 -0700 | [diff] [blame] | 2288 | struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2289 | int i; |
| 2290 | |
Himanshu Agarwal | 2a92459 | 2016-06-30 18:04:14 +0530 | [diff] [blame] | 2291 | if (!scn) { |
| 2292 | HIF_ERROR("%s: scn is NULL", __func__); |
| 2293 | QDF_ASSERT(0); |
| 2294 | return QDF_STATUS_E_FAILURE; |
| 2295 | } |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2296 | |
| 2297 | if (!scn->fastpath_mode_on) { |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2298 | HIF_WARN("%s: Fastpath mode disabled", __func__); |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2299 | return QDF_STATUS_E_FAILURE; |
| 2300 | } |
| 2301 | |
Houston Hoffman | d6f946c | 2016-04-06 15:16:00 -0700 | [diff] [blame] | 2302 | for (i = 0; i < scn->ce_count; i++) { |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2303 | ce_state = scn->ce_id_to_state[i]; |
| 2304 | if (ce_state->htt_rx_data) { |
| 2305 | ce_state->fastpath_handler = handler; |
| 2306 | ce_state->context = context; |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | return QDF_STATUS_SUCCESS; |
| 2311 | } |
Manjunathappa Prakash | 7399f14 | 2016-04-13 23:38:16 -0700 | [diff] [blame] | 2312 | #endif |
| 2313 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2314 | #ifdef IPA_OFFLOAD |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 2315 | /** |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2316 | * hif_ce_ipa_get_ce_resource() - get uc resource on hif |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 2317 | * @scn: bus context |
| 2318 | * @ce_sr_base_paddr: copyengine source ring base physical address |
| 2319 | * @ce_sr_ring_size: copyengine source ring size |
| 2320 | * @ce_reg_paddr: copyengine register physical address |
| 2321 | * |
| 2322 | * IPA micro controller data path offload feature enabled, |
| 2323 | * HIF should release copy engine related resource information to IPA UC |
| 2324 | * IPA UC will access hardware resource with released information |
| 2325 | * |
| 2326 | * Return: None |
| 2327 | */ |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2328 | void hif_ce_ipa_get_ce_resource(struct hif_softc *scn, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2329 | qdf_dma_addr_t *ce_sr_base_paddr, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2330 | uint32_t *ce_sr_ring_size, |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2331 | qdf_dma_addr_t *ce_reg_paddr) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2332 | { |
Komal Seelam | 02cf2f8 | 2016-02-22 20:44:25 +0530 | [diff] [blame] | 2333 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2334 | struct HIF_CE_pipe_info *pipe_info = |
| 2335 | &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]); |
| 2336 | struct CE_handle *ce_hdl = pipe_info->ce_hdl; |
| 2337 | |
| 2338 | ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size, |
| 2339 | ce_reg_paddr); |
| 2340 | return; |
| 2341 | } |
| 2342 | #endif /* IPA_OFFLOAD */ |
| 2343 | |
| 2344 | |
| 2345 | #ifdef ADRASTEA_SHADOW_REGISTERS |
| 2346 | |
| 2347 | /* |
| 2348 | Current shadow register config |
| 2349 | |
| 2350 | ----------------------------------------------------------- |
| 2351 | Shadow Register | CE | src/dst write index |
| 2352 | ----------------------------------------------------------- |
| 2353 | 0 | 0 | src |
| 2354 | 1 No Config - Doesn't point to anything |
| 2355 | 2 No Config - Doesn't point to anything |
| 2356 | 3 | 3 | src |
| 2357 | 4 | 4 | src |
| 2358 | 5 | 5 | src |
| 2359 | 6 No Config - Doesn't point to anything |
| 2360 | 7 | 7 | src |
| 2361 | 8 No Config - Doesn't point to anything |
| 2362 | 9 No Config - Doesn't point to anything |
| 2363 | 10 No Config - Doesn't point to anything |
| 2364 | 11 No Config - Doesn't point to anything |
| 2365 | ----------------------------------------------------------- |
| 2366 | 12 No Config - Doesn't point to anything |
| 2367 | 13 | 1 | dst |
| 2368 | 14 | 2 | dst |
| 2369 | 15 No Config - Doesn't point to anything |
| 2370 | 16 No Config - Doesn't point to anything |
| 2371 | 17 No Config - Doesn't point to anything |
| 2372 | 18 No Config - Doesn't point to anything |
| 2373 | 19 | 7 | dst |
| 2374 | 20 | 8 | dst |
| 2375 | 21 No Config - Doesn't point to anything |
| 2376 | 22 No Config - Doesn't point to anything |
| 2377 | 23 No Config - Doesn't point to anything |
| 2378 | ----------------------------------------------------------- |
| 2379 | |
| 2380 | |
| 2381 | ToDo - Move shadow register config to following in the future |
| 2382 | This helps free up a block of shadow registers towards the end. |
| 2383 | Can be used for other purposes |
| 2384 | |
| 2385 | ----------------------------------------------------------- |
| 2386 | Shadow Register | CE | src/dst write index |
| 2387 | ----------------------------------------------------------- |
| 2388 | 0 | 0 | src |
| 2389 | 1 | 3 | src |
| 2390 | 2 | 4 | src |
| 2391 | 3 | 5 | src |
| 2392 | 4 | 7 | src |
| 2393 | ----------------------------------------------------------- |
| 2394 | 5 | 1 | dst |
| 2395 | 6 | 2 | dst |
| 2396 | 7 | 7 | dst |
| 2397 | 8 | 8 | dst |
| 2398 | ----------------------------------------------------------- |
| 2399 | 9 No Config - Doesn't point to anything |
| 2400 | 12 No Config - Doesn't point to anything |
| 2401 | 13 No Config - Doesn't point to anything |
| 2402 | 14 No Config - Doesn't point to anything |
| 2403 | 15 No Config - Doesn't point to anything |
| 2404 | 16 No Config - Doesn't point to anything |
| 2405 | 17 No Config - Doesn't point to anything |
| 2406 | 18 No Config - Doesn't point to anything |
| 2407 | 19 No Config - Doesn't point to anything |
| 2408 | 20 No Config - Doesn't point to anything |
| 2409 | 21 No Config - Doesn't point to anything |
| 2410 | 22 No Config - Doesn't point to anything |
| 2411 | 23 No Config - Doesn't point to anything |
| 2412 | ----------------------------------------------------------- |
| 2413 | */ |
| 2414 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2415 | u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2416 | { |
| 2417 | u32 addr = 0; |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2418 | u32 ce = COPY_ENGINE_ID(ctrl_addr); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2419 | |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2420 | switch (ce) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2421 | case 0: |
| 2422 | addr = SHADOW_VALUE0; |
| 2423 | break; |
| 2424 | case 3: |
| 2425 | addr = SHADOW_VALUE3; |
| 2426 | break; |
| 2427 | case 4: |
| 2428 | addr = SHADOW_VALUE4; |
| 2429 | break; |
| 2430 | case 5: |
| 2431 | addr = SHADOW_VALUE5; |
| 2432 | break; |
| 2433 | case 7: |
| 2434 | addr = SHADOW_VALUE7; |
| 2435 | break; |
| 2436 | default: |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2437 | HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2438 | QDF_ASSERT(0); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2439 | } |
| 2440 | return addr; |
| 2441 | |
| 2442 | } |
| 2443 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2444 | u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2445 | { |
| 2446 | u32 addr = 0; |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2447 | u32 ce = COPY_ENGINE_ID(ctrl_addr); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2448 | |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2449 | switch (ce) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2450 | case 1: |
| 2451 | addr = SHADOW_VALUE13; |
| 2452 | break; |
| 2453 | case 2: |
| 2454 | addr = SHADOW_VALUE14; |
| 2455 | break; |
Vishwajith Upendra | 70efc75 | 2016-04-18 11:23:49 -0700 | [diff] [blame] | 2456 | case 5: |
| 2457 | addr = SHADOW_VALUE17; |
| 2458 | break; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2459 | case 7: |
| 2460 | addr = SHADOW_VALUE19; |
| 2461 | break; |
| 2462 | case 8: |
| 2463 | addr = SHADOW_VALUE20; |
| 2464 | break; |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2465 | case 9: |
| 2466 | addr = SHADOW_VALUE21; |
| 2467 | break; |
| 2468 | case 10: |
| 2469 | addr = SHADOW_VALUE22; |
| 2470 | break; |
Nirav Shah | 75cc5c8 | 2016-05-25 10:52:38 +0530 | [diff] [blame] | 2471 | case 11: |
| 2472 | addr = SHADOW_VALUE23; |
| 2473 | break; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2474 | default: |
Houston Hoffman | e633044 | 2016-02-26 12:19:11 -0800 | [diff] [blame] | 2475 | HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2476 | QDF_ASSERT(0); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | return addr; |
| 2480 | |
| 2481 | } |
| 2482 | #endif |
| 2483 | |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2484 | #if defined(FEATURE_LRO) |
| 2485 | /** |
| 2486 | * ce_lro_flush_cb_register() - register the LRO flush |
| 2487 | * callback |
| 2488 | * @scn: HIF context |
| 2489 | * @handler: callback function |
| 2490 | * @data: opaque data pointer to be passed back |
| 2491 | * |
| 2492 | * Store the LRO flush callback provided |
| 2493 | * |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2494 | * Return: Number of instances the callback is registered for |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2495 | */ |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2496 | int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl, |
| 2497 | void (handler)(void *), void *data) |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2498 | { |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2499 | int rc = 0; |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 2500 | int i; |
| 2501 | struct CE_state *ce_state; |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 2502 | struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl); |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2503 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2504 | QDF_ASSERT(scn != NULL); |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2505 | |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2506 | if (scn != NULL) { |
| 2507 | for (i = 0; i < scn->ce_count; i++) { |
| 2508 | ce_state = scn->ce_id_to_state[i]; |
| 2509 | if ((ce_state != NULL) && (ce_state->htt_rx_data)) { |
| 2510 | ce_state->lro_flush_cb = handler; |
| 2511 | ce_state->lro_data = data; |
| 2512 | rc++; |
| 2513 | } |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 2514 | } |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2515 | } else { |
| 2516 | HIF_ERROR("%s: hif_state NULL!", __func__); |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2517 | } |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2518 | return rc; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 2519 | } |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2520 | |
| 2521 | /** |
| 2522 | * ce_lro_flush_cb_deregister() - deregister the LRO flush |
| 2523 | * callback |
| 2524 | * @scn: HIF context |
| 2525 | * |
| 2526 | * Remove the LRO flush callback |
| 2527 | * |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2528 | * Return: Number of instances the callback is de-registered |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2529 | */ |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2530 | int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl) |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2531 | { |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2532 | int rc = 0; |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 2533 | int i; |
| 2534 | struct CE_state *ce_state; |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 2535 | struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl); |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2536 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2537 | QDF_ASSERT(scn != NULL); |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2538 | if (scn != NULL) { |
| 2539 | for (i = 0; i < scn->ce_count; i++) { |
| 2540 | ce_state = scn->ce_id_to_state[i]; |
| 2541 | if ((ce_state != NULL) && (ce_state->htt_rx_data)) { |
| 2542 | ce_state->lro_flush_cb = NULL; |
| 2543 | ce_state->lro_data = NULL; |
| 2544 | rc++; |
| 2545 | } |
Houston Hoffman | c7d5429 | 2016-04-13 18:55:37 -0700 | [diff] [blame] | 2546 | } |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2547 | } else { |
| 2548 | HIF_ERROR("%s: hif_state NULL!", __func__); |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2549 | } |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2550 | return rc; |
Dhanashri Atre | 65b674f | 2015-10-30 15:12:03 -0700 | [diff] [blame] | 2551 | } |
| 2552 | #endif |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2553 | |
| 2554 | /** |
| 2555 | * hif_map_service_to_pipe() - returns the ce ids pertaining to |
| 2556 | * this service |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2557 | * @scn: hif_softc pointer. |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2558 | * @svc_id: Service ID for which the mapping is needed. |
| 2559 | * @ul_pipe: address of the container in which ul pipe is returned. |
| 2560 | * @dl_pipe: address of the container in which dl pipe is returned. |
| 2561 | * @ul_is_polled: address of the container in which a bool |
| 2562 | * indicating if the UL CE for this service |
| 2563 | * is polled is returned. |
| 2564 | * @dl_is_polled: address of the container in which a bool |
| 2565 | * indicating if the DL CE for this service |
| 2566 | * is polled is returned. |
| 2567 | * |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2568 | * Return: Indicates whether the service has been found in the table. |
| 2569 | * Upon return, ul_is_polled is updated only if ul_pipe is updated. |
| 2570 | * There will be warning logs if either leg has not been updated |
| 2571 | * because it missed the entry in the table (but this is not an err). |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2572 | */ |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 2573 | int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id, |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2574 | uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled, |
| 2575 | int *dl_is_polled) |
| 2576 | { |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2577 | int status = QDF_STATUS_E_INVAL; |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2578 | unsigned int i; |
| 2579 | struct service_to_pipe element; |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2580 | struct service_to_pipe *tgt_svc_map_to_use; |
| 2581 | size_t sz_tgt_svc_map_to_use; |
Komal Seelam | bd7c51d | 2016-02-24 10:27:30 +0530 | [diff] [blame] | 2582 | struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl); |
| 2583 | uint32_t mode = hif_get_conparam(scn); |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2584 | struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl); |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2585 | bool dl_updated = false; |
| 2586 | bool ul_updated = false; |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2587 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2588 | |
Houston Hoffman | 75ef5a5 | 2016-04-14 17:15:49 -0700 | [diff] [blame] | 2589 | if (QDF_IS_EPPING_ENABLED(mode)) { |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2590 | tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping; |
| 2591 | sz_tgt_svc_map_to_use = |
| 2592 | sizeof(target_service_to_ce_map_wlan_epping); |
| 2593 | } else { |
Houston Hoffman | fb698ef | 2016-05-05 19:50:44 -0700 | [diff] [blame] | 2594 | switch (tgt_info->target_type) { |
| 2595 | default: |
| 2596 | tgt_svc_map_to_use = target_service_to_ce_map_wlan; |
| 2597 | sz_tgt_svc_map_to_use = |
| 2598 | sizeof(target_service_to_ce_map_wlan); |
| 2599 | break; |
| 2600 | case TARGET_TYPE_AR900B: |
| 2601 | case TARGET_TYPE_QCA9984: |
| 2602 | case TARGET_TYPE_IPQ4019: |
| 2603 | case TARGET_TYPE_QCA9888: |
| 2604 | case TARGET_TYPE_AR9888: |
| 2605 | case TARGET_TYPE_AR9888V2: |
| 2606 | tgt_svc_map_to_use = target_service_to_ce_map_ar900b; |
| 2607 | sz_tgt_svc_map_to_use = |
| 2608 | sizeof(target_service_to_ce_map_ar900b); |
| 2609 | break; |
| 2610 | } |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | *dl_is_polled = 0; /* polling for received messages not supported */ |
| 2614 | |
| 2615 | for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) { |
| 2616 | |
| 2617 | memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element)); |
| 2618 | if (element.service_id == svc_id) { |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2619 | if (element.pipedir == PIPEDIR_OUT) { |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2620 | *ul_pipe = element.pipenum; |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2621 | *ul_is_polled = |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2622 | (hif_state->host_ce_config[*ul_pipe].flags & |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2623 | CE_ATTR_DISABLE_INTR) != 0; |
| 2624 | ul_updated = true; |
| 2625 | } else if (element.pipedir == PIPEDIR_IN) { |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2626 | *dl_pipe = element.pipenum; |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2627 | dl_updated = true; |
| 2628 | } |
| 2629 | status = QDF_STATUS_SUCCESS; |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } |
Manjunathappa Prakash | 32afe37 | 2016-04-29 11:12:41 -0700 | [diff] [blame] | 2632 | if (ul_updated == false) |
| 2633 | HIF_WARN("%s: ul pipe is NOT updated for service %d", |
| 2634 | __func__, svc_id); |
| 2635 | if (dl_updated == false) |
| 2636 | HIF_WARN("%s: dl pipe is NOT updated for service %d", |
| 2637 | __func__, svc_id); |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 2638 | |
| 2639 | return status; |
| 2640 | } |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2641 | |
| 2642 | #ifdef SHADOW_REG_DEBUG |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2643 | inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn, |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2644 | uint32_t CE_ctrl_addr) |
| 2645 | { |
| 2646 | uint32_t read_from_hw, srri_from_ddr = 0; |
| 2647 | |
| 2648 | read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS); |
| 2649 | |
| 2650 | srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr)); |
| 2651 | |
| 2652 | if (read_from_hw != srri_from_ddr) { |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2653 | HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x", |
| 2654 | __func__, srri_from_ddr, read_from_hw, |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2655 | CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr)); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2656 | QDF_ASSERT(0); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2657 | } |
| 2658 | return srri_from_ddr; |
| 2659 | } |
| 2660 | |
| 2661 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2662 | inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn, |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2663 | uint32_t CE_ctrl_addr) |
| 2664 | { |
| 2665 | uint32_t read_from_hw, drri_from_ddr = 0; |
| 2666 | |
| 2667 | read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS); |
| 2668 | |
| 2669 | drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr)); |
| 2670 | |
| 2671 | if (read_from_hw != drri_from_ddr) { |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2672 | HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x", |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2673 | drri_from_ddr, read_from_hw, |
| 2674 | CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr)); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2675 | QDF_ASSERT(0); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2676 | } |
| 2677 | return drri_from_ddr; |
| 2678 | } |
| 2679 | |
| 2680 | #endif |
| 2681 | |
Houston Hoffman | 3d0cda8 | 2015-12-03 13:25:05 -0800 | [diff] [blame] | 2682 | #ifdef ADRASTEA_RRI_ON_DDR |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2683 | /** |
| 2684 | * hif_get_src_ring_read_index(): Called to get the SRRI |
| 2685 | * |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2686 | * @scn: hif_softc pointer |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2687 | * @CE_ctrl_addr: base address of the CE whose RRI is to be read |
| 2688 | * |
| 2689 | * This function returns the SRRI to the caller. For CEs that |
| 2690 | * dont have interrupts enabled, we look at the DDR based SRRI |
| 2691 | * |
| 2692 | * Return: SRRI |
| 2693 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2694 | inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn, |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2695 | uint32_t CE_ctrl_addr) |
| 2696 | { |
| 2697 | struct CE_attr attr; |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2698 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2699 | |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2700 | attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)]; |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2701 | if (attr.flags & CE_ATTR_DISABLE_INTR) |
| 2702 | return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr); |
| 2703 | else |
| 2704 | return A_TARGET_READ(scn, |
| 2705 | (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS); |
| 2706 | } |
| 2707 | |
| 2708 | /** |
| 2709 | * hif_get_dst_ring_read_index(): Called to get the DRRI |
| 2710 | * |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2711 | * @scn: hif_softc pointer |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2712 | * @CE_ctrl_addr: base address of the CE whose RRI is to be read |
| 2713 | * |
| 2714 | * This function returns the DRRI to the caller. For CEs that |
| 2715 | * dont have interrupts enabled, we look at the DDR based DRRI |
| 2716 | * |
| 2717 | * Return: DRRI |
| 2718 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2719 | inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn, |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2720 | uint32_t CE_ctrl_addr) |
| 2721 | { |
| 2722 | struct CE_attr attr; |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2723 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2724 | |
Venkateswara Swamy Bandaru | 13164aa | 2016-09-20 20:24:54 +0530 | [diff] [blame] | 2725 | attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)]; |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2726 | |
| 2727 | if (attr.flags & CE_ATTR_DISABLE_INTR) |
| 2728 | return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr); |
| 2729 | else |
| 2730 | return A_TARGET_READ(scn, |
| 2731 | (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS); |
| 2732 | } |
| 2733 | |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2734 | /** |
| 2735 | * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism |
| 2736 | * |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2737 | * @scn: hif_softc pointer |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2738 | * |
| 2739 | * This function allocates non cached memory on ddr and sends |
| 2740 | * the physical address of this memory to the CE hardware. The |
| 2741 | * hardware updates the RRI on this particular location. |
| 2742 | * |
| 2743 | * Return: None |
| 2744 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2745 | static inline void hif_config_rri_on_ddr(struct hif_softc *scn) |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2746 | { |
| 2747 | unsigned int i; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2748 | qdf_dma_addr_t paddr_rri_on_ddr; |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2749 | uint32_t high_paddr, low_paddr; |
| 2750 | scn->vaddr_rri_on_ddr = |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2751 | (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev, |
| 2752 | scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)), |
| 2753 | &paddr_rri_on_ddr); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2754 | |
| 2755 | low_paddr = BITS0_TO_31(paddr_rri_on_ddr); |
| 2756 | high_paddr = BITS32_TO_35(paddr_rri_on_ddr); |
| 2757 | |
Houston Hoffman | c50572b | 2016-06-08 19:49:46 -0700 | [diff] [blame] | 2758 | HIF_INFO("%s using srri and drri from DDR", __func__); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2759 | |
| 2760 | WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr); |
| 2761 | WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr); |
| 2762 | |
| 2763 | for (i = 0; i < CE_COUNT; i++) |
| 2764 | CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i)); |
| 2765 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2766 | qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t)); |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2767 | |
| 2768 | return; |
| 2769 | } |
| 2770 | #else |
| 2771 | |
| 2772 | /** |
| 2773 | * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism |
| 2774 | * |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2775 | * @scn: hif_softc pointer |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2776 | * |
| 2777 | * This is a dummy implementation for platforms that don't |
| 2778 | * support this functionality. |
| 2779 | * |
| 2780 | * Return: None |
| 2781 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2782 | static inline void hif_config_rri_on_ddr(struct hif_softc *scn) |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 2783 | { |
| 2784 | return; |
| 2785 | } |
| 2786 | #endif |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2787 | |
| 2788 | /** |
| 2789 | * hif_dump_ce_registers() - dump ce registers |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 2790 | * @scn: hif_opaque_softc pointer. |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2791 | * |
| 2792 | * Output the copy engine registers |
| 2793 | * |
| 2794 | * Return: 0 for success or error code |
| 2795 | */ |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2796 | int hif_dump_ce_registers(struct hif_softc *scn) |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2797 | { |
Komal Seelam | 5584a7c | 2016-02-24 19:22:48 +0530 | [diff] [blame] | 2798 | struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2799 | uint32_t ce_reg_address = CE0_BASE_ADDRESS; |
Houston Hoffman | 6296c3e | 2016-07-12 18:43:32 -0700 | [diff] [blame] | 2800 | uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2]; |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2801 | uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2; |
| 2802 | uint16_t i; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2803 | QDF_STATUS status; |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2804 | |
Houston Hoffman | d6f946c | 2016-04-06 15:16:00 -0700 | [diff] [blame] | 2805 | for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) { |
| 2806 | if (scn->ce_id_to_state[i] == NULL) { |
| 2807 | HIF_DBG("CE%d not used.", i); |
| 2808 | continue; |
| 2809 | } |
| 2810 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 2811 | status = hif_diag_read_mem(hif_hdl, ce_reg_address, |
Houston Hoffman | 6296c3e | 2016-07-12 18:43:32 -0700 | [diff] [blame] | 2812 | (uint8_t *) &ce_reg_values[0], |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2813 | ce_reg_word_size * sizeof(uint32_t)); |
| 2814 | |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2815 | if (status != QDF_STATUS_SUCCESS) { |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2816 | HIF_ERROR("Dumping CE register failed!"); |
| 2817 | return -EACCES; |
| 2818 | } |
Venkateswara Swamy Bandaru | 772377c | 2016-10-03 14:17:28 +0530 | [diff] [blame] | 2819 | HIF_ERROR("CE%d=>\n", i); |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 2820 | qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG, |
Houston Hoffman | 6296c3e | 2016-07-12 18:43:32 -0700 | [diff] [blame] | 2821 | (uint8_t *) &ce_reg_values[0], |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2822 | ce_reg_word_size * sizeof(uint32_t)); |
Venkateswara Swamy Bandaru | 772377c | 2016-10-03 14:17:28 +0530 | [diff] [blame] | 2823 | qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address |
| 2824 | + SR_WR_INDEX_ADDRESS), |
| 2825 | ce_reg_values[SR_WR_INDEX_ADDRESS/4]); |
| 2826 | qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address |
| 2827 | + CURRENT_SRRI_ADDRESS), |
| 2828 | ce_reg_values[CURRENT_SRRI_ADDRESS/4]); |
| 2829 | qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address |
| 2830 | + DST_WR_INDEX_ADDRESS), |
| 2831 | ce_reg_values[DST_WR_INDEX_ADDRESS/4]); |
| 2832 | qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address |
| 2833 | + CURRENT_DRRI_ADDRESS), |
| 2834 | ce_reg_values[CURRENT_DRRI_ADDRESS/4]); |
| 2835 | qdf_print("---\n"); |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2836 | } |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 2837 | return 0; |
| 2838 | } |
Houston Hoffman | 8592507 | 2016-05-06 17:02:18 -0700 | [diff] [blame] | 2839 | #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT |
| 2840 | struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc, |
| 2841 | struct hif_pipe_addl_info *hif_info, uint32_t pipe) |
| 2842 | { |
| 2843 | struct hif_softc *scn = HIF_GET_SOFTC(osc); |
| 2844 | struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn); |
| 2845 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc); |
| 2846 | struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]); |
| 2847 | struct CE_handle *ce_hdl = pipe_info->ce_hdl; |
| 2848 | struct CE_state *ce_state = (struct CE_state *)ce_hdl; |
| 2849 | struct CE_ring_state *src_ring = ce_state->src_ring; |
| 2850 | struct CE_ring_state *dest_ring = ce_state->dest_ring; |
| 2851 | |
| 2852 | if (src_ring) { |
| 2853 | hif_info->ul_pipe.nentries = src_ring->nentries; |
| 2854 | hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask; |
| 2855 | hif_info->ul_pipe.sw_index = src_ring->sw_index; |
| 2856 | hif_info->ul_pipe.write_index = src_ring->write_index; |
| 2857 | hif_info->ul_pipe.hw_index = src_ring->hw_index; |
| 2858 | hif_info->ul_pipe.base_addr_CE_space = |
| 2859 | src_ring->base_addr_CE_space; |
| 2860 | hif_info->ul_pipe.base_addr_owner_space = |
| 2861 | src_ring->base_addr_owner_space; |
| 2862 | } |
| 2863 | |
| 2864 | |
| 2865 | if (dest_ring) { |
| 2866 | hif_info->dl_pipe.nentries = dest_ring->nentries; |
| 2867 | hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask; |
| 2868 | hif_info->dl_pipe.sw_index = dest_ring->sw_index; |
| 2869 | hif_info->dl_pipe.write_index = dest_ring->write_index; |
| 2870 | hif_info->dl_pipe.hw_index = dest_ring->hw_index; |
| 2871 | hif_info->dl_pipe.base_addr_CE_space = |
| 2872 | dest_ring->base_addr_CE_space; |
| 2873 | hif_info->dl_pipe.base_addr_owner_space = |
| 2874 | dest_ring->base_addr_owner_space; |
| 2875 | } |
| 2876 | |
| 2877 | hif_info->pci_mem = pci_resource_start(sc->pdev, 0); |
| 2878 | hif_info->ctrl_addr = ce_state->ctrl_addr; |
| 2879 | |
| 2880 | return hif_info; |
| 2881 | } |
| 2882 | |
| 2883 | uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode) |
| 2884 | { |
| 2885 | struct hif_softc *scn = HIF_GET_SOFTC(osc); |
| 2886 | |
| 2887 | scn->nss_wifi_ol_mode = mode; |
| 2888 | return 0; |
| 2889 | } |
| 2890 | |
| 2891 | #endif |
| 2892 | |
| 2893 | void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num) |
| 2894 | { |
| 2895 | struct hif_softc *scn = HIF_GET_SOFTC(osc); |
| 2896 | struct CE_state *CE_state = scn->ce_id_to_state[pipe_num]; |
| 2897 | uint32_t ctrl_addr = CE_state->ctrl_addr; |
| 2898 | |
| 2899 | Q_TARGET_ACCESS_BEGIN(scn); |
| 2900 | CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr); |
| 2901 | Q_TARGET_ACCESS_END(scn); |
| 2902 | } |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2903 | |
| 2904 | /** |
| 2905 | * hif_fw_event_handler() - hif fw event handler |
| 2906 | * @hif_state: pointer to hif ce state structure |
| 2907 | * |
| 2908 | * Process fw events and raise HTC callback to process fw events. |
| 2909 | * |
| 2910 | * Return: none |
| 2911 | */ |
| 2912 | static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state) |
| 2913 | { |
| 2914 | struct hif_msg_callbacks *msg_callbacks = |
| 2915 | &hif_state->msg_callbacks_current; |
| 2916 | |
| 2917 | if (!msg_callbacks->fwEventHandler) |
| 2918 | return; |
| 2919 | |
| 2920 | msg_callbacks->fwEventHandler(msg_callbacks->Context, |
| 2921 | QDF_STATUS_E_FAILURE); |
| 2922 | } |
| 2923 | |
| 2924 | #ifndef QCA_WIFI_3_0 |
| 2925 | /** |
| 2926 | * hif_fw_interrupt_handler() - FW interrupt handler |
| 2927 | * @irq: irq number |
| 2928 | * @arg: the user pointer |
| 2929 | * |
| 2930 | * Called from the PCI interrupt handler when a |
| 2931 | * firmware-generated interrupt to the Host. |
| 2932 | * |
| 2933 | * Return: status of handled irq |
| 2934 | */ |
| 2935 | irqreturn_t hif_fw_interrupt_handler(int irq, void *arg) |
| 2936 | { |
| 2937 | struct hif_softc *scn = arg; |
| 2938 | struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); |
| 2939 | uint32_t fw_indicator_address, fw_indicator; |
| 2940 | |
| 2941 | if (Q_TARGET_ACCESS_BEGIN(scn) < 0) |
| 2942 | return ATH_ISR_NOSCHED; |
| 2943 | |
| 2944 | fw_indicator_address = hif_state->fw_indicator_address; |
| 2945 | /* For sudden unplug this will return ~0 */ |
| 2946 | fw_indicator = A_TARGET_READ(scn, fw_indicator_address); |
| 2947 | |
| 2948 | if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) { |
| 2949 | /* ACK: clear Target-side pending event */ |
| 2950 | A_TARGET_WRITE(scn, fw_indicator_address, |
| 2951 | fw_indicator & ~FW_IND_EVENT_PENDING); |
| 2952 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 2953 | return ATH_ISR_SCHED; |
| 2954 | |
| 2955 | if (hif_state->started) { |
| 2956 | hif_fw_event_handler(hif_state); |
| 2957 | } else { |
| 2958 | /* |
| 2959 | * Probable Target failure before we're prepared |
| 2960 | * to handle it. Generally unexpected. |
| 2961 | */ |
| 2962 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 2963 | ("%s: Early firmware event indicated\n", |
| 2964 | __func__)); |
| 2965 | } |
| 2966 | } else { |
| 2967 | if (Q_TARGET_ACCESS_END(scn) < 0) |
| 2968 | return ATH_ISR_SCHED; |
| 2969 | } |
| 2970 | |
| 2971 | return ATH_ISR_SCHED; |
| 2972 | } |
| 2973 | #else |
| 2974 | irqreturn_t hif_fw_interrupt_handler(int irq, void *arg) |
| 2975 | { |
| 2976 | return ATH_ISR_SCHED; |
| 2977 | } |
| 2978 | #endif /* #ifdef QCA_WIFI_3_0 */ |
| 2979 | |
| 2980 | |
| 2981 | /** |
| 2982 | * hif_wlan_disable(): call the platform driver to disable wlan |
| 2983 | * @scn: HIF Context |
| 2984 | * |
| 2985 | * This function passes the con_mode to platform driver to disable |
| 2986 | * wlan. |
| 2987 | * |
| 2988 | * Return: void |
| 2989 | */ |
| 2990 | void hif_wlan_disable(struct hif_softc *scn) |
| 2991 | { |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 2992 | enum pld_driver_mode mode; |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2993 | uint32_t con_mode = hif_get_conparam(scn); |
| 2994 | |
| 2995 | if (QDF_GLOBAL_FTM_MODE == con_mode) |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 2996 | mode = PLD_FTM; |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2997 | else if (QDF_IS_EPPING_ENABLED(con_mode)) |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 2998 | mode = PLD_EPPING; |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 2999 | else |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 3000 | mode = PLD_MISSION; |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 3001 | |
Yuanyuan Liu | fd594c2 | 2016-04-25 13:59:19 -0700 | [diff] [blame] | 3002 | pld_wlan_disable(scn->qdf_dev->dev, mode); |
Poddar, Siddarth | e41943f | 2016-04-27 15:33:48 +0530 | [diff] [blame] | 3003 | } |
Dustin Brown | 6bdbda5 | 2016-09-27 15:52:30 -0700 | [diff] [blame^] | 3004 | |