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