1 /* 2 * Copyright 2012-15 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #include "dm_services.h" 27 #include "core_types.h" 28 #include "dce_aux.h" 29 #include "dce/dce_11_0_d.h" 30 #include "dce/dce_11_0_sh_mask.h" 31 #include "dm_event_log.h" 32 #include "dm_helpers.h" 33 #include "dmub/inc/dmub_cmd.h" 34 35 #define CTX \ 36 aux110->base.ctx 37 #define REG(reg_name)\ 38 (aux110->regs->reg_name) 39 40 #define DC_LOGGER \ 41 engine->ctx->logger 42 43 #define DC_TRACE_LEVEL_MESSAGE(...) do { } while (0) 44 #define IS_DC_I2CAUX_LOGGING_ENABLED() (false) 45 #define LOG_FLAG_Error_I2cAux LOG_ERROR 46 #define LOG_FLAG_I2cAux_DceAux LOG_I2C_AUX 47 48 #include "reg_helper.h" 49 50 #undef FN 51 #define FN(reg_name, field_name) \ 52 aux110->shift->field_name, aux110->mask->field_name 53 54 #define FROM_AUX_ENGINE(ptr) \ 55 container_of((ptr), struct aux_engine_dce110, base) 56 57 #define FROM_ENGINE(ptr) \ 58 FROM_AUX_ENGINE(container_of((ptr), struct dce_aux, base)) 59 60 #define FROM_AUX_ENGINE_ENGINE(ptr) \ 61 container_of((ptr), struct dce_aux, base) 62 enum { 63 AUX_INVALID_REPLY_RETRY_COUNTER = 1, 64 AUX_TIMED_OUT_RETRY_COUNTER = 2, 65 AUX_DEFER_RETRY_COUNTER = 6 66 }; 67 68 #define TIME_OUT_INCREMENT 1016 69 #define TIME_OUT_MULTIPLIER_8 8 70 #define TIME_OUT_MULTIPLIER_16 16 71 #define TIME_OUT_MULTIPLIER_32 32 72 #define TIME_OUT_MULTIPLIER_64 64 73 #define MAX_TIMEOUT_LENGTH 127 74 #define DEFAULT_AUX_ENGINE_MULT 0 75 #define DEFAULT_AUX_ENGINE_LENGTH 69 76 77 #define DC_TRACE_LEVEL_MESSAGE(...) do { } while (0) 78 79 static void release_engine( 80 struct dce_aux *engine) 81 { 82 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 83 84 dal_ddc_close(engine->ddc); 85 86 engine->ddc = NULL; 87 88 REG_UPDATE_2(AUX_ARB_CONTROL, AUX_SW_DONE_USING_AUX_REG, 1, 89 AUX_SW_USE_AUX_REG_REQ, 0); 90 } 91 92 #define SW_CAN_ACCESS_AUX 1 93 #define DMCU_CAN_ACCESS_AUX 2 94 95 static bool is_engine_available( 96 struct dce_aux *engine) 97 { 98 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 99 100 uint32_t value = REG_READ(AUX_ARB_CONTROL); 101 uint32_t field = get_reg_field_value( 102 value, 103 AUX_ARB_CONTROL, 104 AUX_REG_RW_CNTL_STATUS); 105 106 return (field != DMCU_CAN_ACCESS_AUX); 107 } 108 static bool acquire_engine( 109 struct dce_aux *engine) 110 { 111 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 112 113 uint32_t value = REG_READ(AUX_ARB_CONTROL); 114 uint32_t field = get_reg_field_value( 115 value, 116 AUX_ARB_CONTROL, 117 AUX_REG_RW_CNTL_STATUS); 118 if (field == DMCU_CAN_ACCESS_AUX) 119 return false; 120 /* enable AUX before request SW to access AUX */ 121 value = REG_READ(AUX_CONTROL); 122 field = get_reg_field_value(value, 123 AUX_CONTROL, 124 AUX_EN); 125 126 if (field == 0) { 127 set_reg_field_value( 128 value, 129 1, 130 AUX_CONTROL, 131 AUX_EN); 132 133 if (REG(AUX_RESET_MASK)) { 134 /*DP_AUX block as part of the enable sequence*/ 135 set_reg_field_value( 136 value, 137 1, 138 AUX_CONTROL, 139 AUX_RESET); 140 } 141 142 REG_WRITE(AUX_CONTROL, value); 143 144 if (REG(AUX_RESET_MASK)) { 145 /*poll HW to make sure reset it done*/ 146 147 REG_WAIT(AUX_CONTROL, AUX_RESET_DONE, 1, 148 1, 11); 149 150 set_reg_field_value( 151 value, 152 0, 153 AUX_CONTROL, 154 AUX_RESET); 155 156 REG_WRITE(AUX_CONTROL, value); 157 158 REG_WAIT(AUX_CONTROL, AUX_RESET_DONE, 0, 159 1, 11); 160 } 161 } /*if (field)*/ 162 163 /* request SW to access AUX */ 164 REG_UPDATE(AUX_ARB_CONTROL, AUX_SW_USE_AUX_REG_REQ, 1); 165 166 value = REG_READ(AUX_ARB_CONTROL); 167 field = get_reg_field_value( 168 value, 169 AUX_ARB_CONTROL, 170 AUX_REG_RW_CNTL_STATUS); 171 172 return (field == SW_CAN_ACCESS_AUX); 173 } 174 175 #define COMPOSE_AUX_SW_DATA_16_20(command, address) \ 176 ((command) | ((0xF0000 & (address)) >> 16)) 177 178 #define COMPOSE_AUX_SW_DATA_8_15(address) \ 179 ((0xFF00 & (address)) >> 8) 180 181 #define COMPOSE_AUX_SW_DATA_0_7(address) \ 182 (0xFF & (address)) 183 184 static void submit_channel_request( 185 struct dce_aux *engine, 186 struct aux_request_transaction_data *request) 187 { 188 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 189 uint32_t value; 190 uint32_t length; 191 192 bool is_write = 193 ((request->type == AUX_TRANSACTION_TYPE_DP) && 194 (request->action == I2CAUX_TRANSACTION_ACTION_DP_WRITE)) || 195 ((request->type == AUX_TRANSACTION_TYPE_I2C) && 196 ((request->action == I2CAUX_TRANSACTION_ACTION_I2C_WRITE) || 197 (request->action == I2CAUX_TRANSACTION_ACTION_I2C_WRITE_MOT))); 198 if (REG(AUXN_IMPCAL)) { 199 /* clear_aux_error */ 200 REG_UPDATE_SEQ_2(AUXN_IMPCAL, 201 AUXN_CALOUT_ERROR_AK, 1, 202 AUXN_CALOUT_ERROR_AK, 0); 203 204 REG_UPDATE_SEQ_2(AUXP_IMPCAL, 205 AUXP_CALOUT_ERROR_AK, 1, 206 AUXP_CALOUT_ERROR_AK, 0); 207 208 /* force_default_calibrate */ 209 REG_UPDATE_SEQ_2(AUXN_IMPCAL, 210 AUXN_IMPCAL_ENABLE, 1, 211 AUXN_IMPCAL_OVERRIDE_ENABLE, 0); 212 213 /* bug? why AUXN update EN and OVERRIDE_EN 1 by 1 while AUX P toggles OVERRIDE? */ 214 215 REG_UPDATE_SEQ_2(AUXP_IMPCAL, 216 AUXP_IMPCAL_OVERRIDE_ENABLE, 1, 217 AUXP_IMPCAL_OVERRIDE_ENABLE, 0); 218 } 219 220 REG_UPDATE(AUX_INTERRUPT_CONTROL, AUX_SW_DONE_ACK, 1); 221 222 REG_WAIT(AUX_SW_STATUS, AUX_SW_DONE, 0, 223 10, aux110->polling_timeout_period/10); 224 225 /* set the delay and the number of bytes to write */ 226 227 /* The length include 228 * the 4 bit header and the 20 bit address 229 * (that is 3 byte). 230 * If the requested length is non zero this means 231 * an addition byte specifying the length is required. 232 */ 233 234 length = request->length ? 4 : 3; 235 if (is_write) 236 length += request->length; 237 238 REG_UPDATE_2(AUX_SW_CONTROL, 239 AUX_SW_START_DELAY, request->delay, 240 AUX_SW_WR_BYTES, length); 241 242 /* program action and address and payload data (if 'is_write') */ 243 value = REG_UPDATE_4(AUX_SW_DATA, 244 AUX_SW_INDEX, 0, 245 AUX_SW_DATA_RW, 0, 246 AUX_SW_AUTOINCREMENT_DISABLE, 1, 247 AUX_SW_DATA, COMPOSE_AUX_SW_DATA_16_20(request->action, request->address)); 248 249 value = REG_SET_2(AUX_SW_DATA, value, 250 AUX_SW_AUTOINCREMENT_DISABLE, 0, 251 AUX_SW_DATA, COMPOSE_AUX_SW_DATA_8_15(request->address)); 252 253 value = REG_SET(AUX_SW_DATA, value, 254 AUX_SW_DATA, COMPOSE_AUX_SW_DATA_0_7(request->address)); 255 256 if (request->length) { 257 value = REG_SET(AUX_SW_DATA, value, 258 AUX_SW_DATA, request->length - 1); 259 } 260 261 if (is_write) { 262 /* Load the HW buffer with the Data to be sent. 263 * This is relevant for write operation. 264 * For read, the data recived data will be 265 * processed in process_channel_reply(). 266 */ 267 uint32_t i = 0; 268 269 while (i < request->length) { 270 value = REG_SET(AUX_SW_DATA, value, 271 AUX_SW_DATA, request->data[i]); 272 273 ++i; 274 } 275 } 276 277 REG_UPDATE(AUX_SW_CONTROL, AUX_SW_GO, 1); 278 279 if (engine->ddc) { 280 EVENT_LOG_AUX_REQ(engine->ddc->pin_data->en, EVENT_LOG_AUX_ORIGIN_NATIVE, 281 request->action, request->address, request->length, request->data); 282 } else { 283 EVENT_LOG_AUX_REQ(engine->inst, EVENT_LOG_AUX_ORIGIN_NATIVE, 284 request->action, request->address, request->length, request->data); 285 } 286 } 287 288 static int read_channel_reply(struct dce_aux *engine, uint32_t size, 289 uint8_t *buffer, uint8_t *reply_result, 290 uint32_t *sw_status) 291 { 292 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 293 uint32_t bytes_replied; 294 uint32_t reply_result_32; 295 296 *sw_status = REG_GET(AUX_SW_STATUS, AUX_SW_REPLY_BYTE_COUNT, 297 &bytes_replied); 298 299 /* In case HPD is LOW, exit AUX transaction */ 300 if ((*sw_status & AUX_SW_STATUS__AUX_SW_HPD_DISCON_MASK)) 301 return -1; 302 303 /* Need at least the status byte */ 304 if (!bytes_replied) 305 return -1; 306 307 REG_UPDATE_SEQ_3(AUX_SW_DATA, 308 AUX_SW_INDEX, 0, 309 AUX_SW_AUTOINCREMENT_DISABLE, 1, 310 AUX_SW_DATA_RW, 1); 311 312 REG_GET(AUX_SW_DATA, AUX_SW_DATA, &reply_result_32); 313 reply_result_32 = reply_result_32 >> 4; 314 if (reply_result != NULL) 315 *reply_result = (uint8_t)reply_result_32; 316 317 if (reply_result_32 == 0) { /* ACK */ 318 uint32_t i = 0; 319 320 /* First byte was already used to get the command status */ 321 --bytes_replied; 322 323 /* Do not overflow buffer */ 324 if (bytes_replied > size) 325 return -1; 326 327 while (i < bytes_replied) { 328 uint32_t aux_sw_data_val; 329 330 REG_GET(AUX_SW_DATA, AUX_SW_DATA, &aux_sw_data_val); 331 buffer[i] = (uint8_t)aux_sw_data_val; 332 ++i; 333 } 334 335 return i; 336 } 337 338 return 0; 339 } 340 341 static enum aux_return_code_type get_channel_status( 342 struct dce_aux *engine, 343 uint8_t *returned_bytes) 344 { 345 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(engine); 346 347 uint32_t value; 348 349 if (returned_bytes == NULL) { 350 /*caller pass NULL pointer*/ 351 ASSERT_CRITICAL(false); 352 return AUX_RET_ERROR_UNKNOWN; 353 } 354 *returned_bytes = 0; 355 356 /* poll to make sure that SW_DONE is asserted */ 357 REG_WAIT(AUX_SW_STATUS, AUX_SW_DONE, 1, 358 10, aux110->polling_timeout_period/10); 359 360 value = REG_READ(AUX_SW_STATUS); 361 /* in case HPD is LOW, exit AUX transaction */ 362 if ((value & AUX_SW_STATUS__AUX_SW_HPD_DISCON_MASK)) 363 return AUX_RET_ERROR_HPD_DISCON; 364 365 /* Note that the following bits are set in 'status.bits' 366 * during CTS 4.2.1.2 (FW 3.3.1): 367 * AUX_SW_RX_MIN_COUNT_VIOL, AUX_SW_RX_INVALID_STOP, 368 * AUX_SW_RX_RECV_NO_DET, AUX_SW_RX_RECV_INVALID_H. 369 * 370 * AUX_SW_RX_MIN_COUNT_VIOL is an internal, 371 * HW debugging bit and should be ignored. 372 */ 373 if (value & AUX_SW_STATUS__AUX_SW_DONE_MASK) { 374 if ((value & AUX_SW_STATUS__AUX_SW_RX_TIMEOUT_STATE_MASK) || 375 (value & AUX_SW_STATUS__AUX_SW_RX_TIMEOUT_MASK)) 376 return AUX_RET_ERROR_TIMEOUT; 377 378 else if ((value & AUX_SW_STATUS__AUX_SW_RX_INVALID_STOP_MASK) || 379 (value & AUX_SW_STATUS__AUX_SW_RX_RECV_NO_DET_MASK) || 380 (value & 381 AUX_SW_STATUS__AUX_SW_RX_RECV_INVALID_H_MASK) || 382 (value & AUX_SW_STATUS__AUX_SW_RX_RECV_INVALID_L_MASK)) 383 return AUX_RET_ERROR_INVALID_REPLY; 384 385 *returned_bytes = (uint8_t)get_reg_field_value(value, 386 AUX_SW_STATUS, 387 AUX_SW_REPLY_BYTE_COUNT); 388 389 if (*returned_bytes == 0) 390 return 391 AUX_RET_ERROR_INVALID_REPLY; 392 else { 393 *returned_bytes -= 1; 394 return AUX_RET_SUCCESS; 395 } 396 } else { 397 /*time_elapsed >= aux_engine->timeout_period 398 * AUX_SW_STATUS__AUX_SW_HPD_DISCON = at this point 399 */ 400 ASSERT_CRITICAL(false); 401 return AUX_RET_ERROR_TIMEOUT; 402 } 403 } 404 405 static bool acquire( 406 struct dce_aux *engine, 407 struct ddc *ddc) 408 { 409 enum gpio_result result; 410 411 if ((engine == NULL) || !is_engine_available(engine)) 412 return false; 413 414 result = dal_ddc_open(ddc, GPIO_MODE_HARDWARE, 415 GPIO_DDC_CONFIG_TYPE_MODE_AUX); 416 417 if (result != GPIO_RESULT_OK) 418 return false; 419 420 if (!acquire_engine(engine)) { 421 engine->ddc = ddc; 422 release_engine(engine); 423 return false; 424 } 425 426 engine->ddc = ddc; 427 428 return true; 429 } 430 431 static bool acquire_aux_engine_without_ddc_pin( 432 struct dce_aux *engine, 433 struct ddc *ddc) 434 { 435 if ((engine == NULL) || !is_engine_available(engine)) 436 return false; 437 438 /* Open the DDC in AUX mode so the I3C PAD set_config hook runs and 439 * enables the PAD RX (disabled by default); otherwise DPCD reads time 440 * out even though the connector has no native I2C/DDC pin. */ 441 if (ddc != NULL && 442 dal_ddc_open(ddc, GPIO_MODE_HARDWARE, 443 GPIO_DDC_CONFIG_TYPE_MODE_AUX) != GPIO_RESULT_OK) 444 return false; 445 446 if (!acquire_engine(engine)) { 447 engine->ddc = ddc; 448 release_engine(engine); 449 return false; 450 } 451 452 engine->ddc = ddc; 453 return true; 454 } 455 456 void dce110_engine_destroy(struct dce_aux **engine) 457 { 458 459 struct aux_engine_dce110 *engine110 = FROM_AUX_ENGINE(*engine); 460 461 kfree(engine110); 462 *engine = NULL; 463 464 } 465 466 static uint32_t dce_aux_configure_timeout_without_ddc_pin(struct ddc_service *ddc, 467 uint32_t timeout_in_us) 468 { 469 uint32_t multiplier = 0; 470 uint32_t length = 0; 471 uint32_t prev_length = 0; 472 uint32_t prev_mult = 0; 473 uint32_t prev_timeout_val = 0; 474 struct dce_aux *aux_engine = ddc->ctx->dc->res_pool->engines[ddc->link->aux_hw_inst]; 475 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(aux_engine); 476 477 /* 1-Update polling timeout period */ 478 aux110->polling_timeout_period = timeout_in_us * SW_AUX_TIMEOUT_PERIOD_MULTIPLIER; 479 480 /* 2-Update aux timeout period length and multiplier */ 481 if (timeout_in_us == 0) { 482 multiplier = DEFAULT_AUX_ENGINE_MULT; 483 length = DEFAULT_AUX_ENGINE_LENGTH; 484 } else if (timeout_in_us <= TIME_OUT_INCREMENT) { 485 multiplier = 0; 486 length = timeout_in_us / TIME_OUT_MULTIPLIER_8; 487 if (timeout_in_us % TIME_OUT_MULTIPLIER_8 != 0) 488 length++; 489 } else if (timeout_in_us <= 2 * TIME_OUT_INCREMENT) { 490 multiplier = 1; 491 length = timeout_in_us / TIME_OUT_MULTIPLIER_16; 492 if (timeout_in_us % TIME_OUT_MULTIPLIER_16 != 0) 493 length++; 494 } else if (timeout_in_us <= 4 * TIME_OUT_INCREMENT) { 495 multiplier = 2; 496 length = timeout_in_us / TIME_OUT_MULTIPLIER_32; 497 if (timeout_in_us % TIME_OUT_MULTIPLIER_32 != 0) 498 length++; 499 } else if (timeout_in_us > 4 * TIME_OUT_INCREMENT) { 500 multiplier = 3; 501 length = timeout_in_us / TIME_OUT_MULTIPLIER_64; 502 if (timeout_in_us % TIME_OUT_MULTIPLIER_64 != 0) 503 length++; 504 } 505 506 length = (length < MAX_TIMEOUT_LENGTH) ? length : MAX_TIMEOUT_LENGTH; 507 508 REG_GET_2(AUX_DPHY_RX_CONTROL1, AUX_RX_TIMEOUT_LEN, &prev_length, AUX_RX_TIMEOUT_LEN_MUL, &prev_mult); 509 510 switch (prev_mult) { 511 case 0: 512 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_8; 513 break; 514 case 1: 515 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_16; 516 break; 517 case 2: 518 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_32; 519 break; 520 case 3: 521 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_64; 522 break; 523 default: 524 prev_timeout_val = DEFAULT_AUX_ENGINE_LENGTH * TIME_OUT_MULTIPLIER_8; 525 break; 526 } 527 528 REG_UPDATE_SEQ_2(AUX_DPHY_RX_CONTROL1, AUX_RX_TIMEOUT_LEN, length, AUX_RX_TIMEOUT_LEN_MUL, multiplier); 529 530 return prev_timeout_val; 531 } 532 533 static uint32_t dce_aux_configure_timeout(struct ddc_service *ddc, 534 uint32_t timeout_in_us) 535 { 536 uint32_t multiplier = 0; 537 uint32_t length = 0; 538 uint32_t prev_length = 0; 539 uint32_t prev_mult = 0; 540 uint32_t prev_timeout_val = 0; 541 struct ddc *ddc_pin = ddc->ddc_pin; 542 543 if (ddc->link->force_to_use_aux) 544 return dce_aux_configure_timeout_without_ddc_pin(ddc, timeout_in_us); 545 546 struct dce_aux *aux_engine = ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]; 547 struct aux_engine_dce110 *aux110 = FROM_AUX_ENGINE(aux_engine); 548 549 /* 1-Update polling timeout period */ 550 aux110->polling_timeout_period = timeout_in_us * SW_AUX_TIMEOUT_PERIOD_MULTIPLIER; 551 552 /* 2-Update aux timeout period length and multiplier */ 553 if (timeout_in_us == 0) { 554 multiplier = DEFAULT_AUX_ENGINE_MULT; 555 length = DEFAULT_AUX_ENGINE_LENGTH; 556 } else if (timeout_in_us <= TIME_OUT_INCREMENT) { 557 multiplier = 0; 558 length = timeout_in_us/TIME_OUT_MULTIPLIER_8; 559 if (timeout_in_us % TIME_OUT_MULTIPLIER_8 != 0) 560 length++; 561 } else if (timeout_in_us <= 2 * TIME_OUT_INCREMENT) { 562 multiplier = 1; 563 length = timeout_in_us/TIME_OUT_MULTIPLIER_16; 564 if (timeout_in_us % TIME_OUT_MULTIPLIER_16 != 0) 565 length++; 566 } else if (timeout_in_us <= 4 * TIME_OUT_INCREMENT) { 567 multiplier = 2; 568 length = timeout_in_us/TIME_OUT_MULTIPLIER_32; 569 if (timeout_in_us % TIME_OUT_MULTIPLIER_32 != 0) 570 length++; 571 } else if (timeout_in_us > 4 * TIME_OUT_INCREMENT) { 572 multiplier = 3; 573 length = timeout_in_us/TIME_OUT_MULTIPLIER_64; 574 if (timeout_in_us % TIME_OUT_MULTIPLIER_64 != 0) 575 length++; 576 } 577 578 length = (length < MAX_TIMEOUT_LENGTH) ? length : MAX_TIMEOUT_LENGTH; 579 580 REG_GET_2(AUX_DPHY_RX_CONTROL1, AUX_RX_TIMEOUT_LEN, &prev_length, AUX_RX_TIMEOUT_LEN_MUL, &prev_mult); 581 582 switch (prev_mult) { 583 case 0: 584 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_8; 585 break; 586 case 1: 587 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_16; 588 break; 589 case 2: 590 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_32; 591 break; 592 case 3: 593 prev_timeout_val = prev_length * TIME_OUT_MULTIPLIER_64; 594 break; 595 default: 596 prev_timeout_val = DEFAULT_AUX_ENGINE_LENGTH * TIME_OUT_MULTIPLIER_8; 597 break; 598 } 599 600 REG_UPDATE_SEQ_2(AUX_DPHY_RX_CONTROL1, AUX_RX_TIMEOUT_LEN, length, AUX_RX_TIMEOUT_LEN_MUL, multiplier); 601 602 return prev_timeout_val; 603 } 604 605 static struct dce_aux_funcs aux_functions = { 606 .configure_timeout = NULL, 607 .destroy = NULL, 608 }; 609 610 struct dce_aux *dce110_aux_engine_construct(struct aux_engine_dce110 *aux_engine110, 611 struct dc_context *ctx, 612 uint32_t inst, 613 uint32_t timeout_period, 614 const struct dce110_aux_registers *regs, 615 const struct dce110_aux_registers_mask *mask, 616 const struct dce110_aux_registers_shift *shift, 617 bool is_ext_aux_timeout_configurable) 618 { 619 aux_engine110->base.ddc = NULL; 620 aux_engine110->base.ctx = ctx; 621 aux_engine110->base.delay = 0; 622 aux_engine110->base.max_defer_write_retry = 0; 623 aux_engine110->base.inst = inst; 624 aux_engine110->polling_timeout_period = timeout_period; 625 aux_engine110->regs = regs; 626 627 aux_engine110->mask = mask; 628 aux_engine110->shift = shift; 629 aux_engine110->base.funcs = &aux_functions; 630 if (is_ext_aux_timeout_configurable) 631 aux_engine110->base.funcs->configure_timeout = &dce_aux_configure_timeout; 632 633 return &aux_engine110->base; 634 } 635 636 static enum i2caux_transaction_action i2caux_action_from_payload(struct aux_payload *payload) 637 { 638 if (payload->i2c_over_aux) { 639 if (payload->write_status_update) { 640 if (payload->mot) 641 return I2CAUX_TRANSACTION_ACTION_I2C_STATUS_REQUEST_MOT; 642 else 643 return I2CAUX_TRANSACTION_ACTION_I2C_STATUS_REQUEST; 644 } 645 if (payload->write) { 646 if (payload->mot) 647 return I2CAUX_TRANSACTION_ACTION_I2C_WRITE_MOT; 648 else 649 return I2CAUX_TRANSACTION_ACTION_I2C_WRITE; 650 } 651 if (payload->mot) 652 return I2CAUX_TRANSACTION_ACTION_I2C_READ_MOT; 653 654 return I2CAUX_TRANSACTION_ACTION_I2C_READ; 655 } 656 if (payload->write) 657 return I2CAUX_TRANSACTION_ACTION_DP_WRITE; 658 659 return I2CAUX_TRANSACTION_ACTION_DP_READ; 660 } 661 662 int dce_aux_transfer_raw(struct ddc_service *ddc, 663 struct aux_payload *payload, 664 enum aux_return_code_type *operation_result) 665 { 666 if (ddc->link->force_to_use_aux) { 667 /* Check whether aux to be processed via dmub or dcn directly */ 668 if (ddc->ctx->dc->debug.enable_dmub_aux_for_legacy_ddc) { 669 return dce_aux_transfer_dmub_raw(ddc, payload, operation_result); 670 } else { 671 return dce_aux_transfer_raw_without_ddc_pin(ddc, payload, operation_result); 672 } 673 } else { 674 if (ddc->ctx->dc->debug.enable_dmub_aux_for_legacy_ddc || 675 !ddc->ddc_pin) { 676 return dce_aux_transfer_dmub_raw(ddc, payload, operation_result); 677 } else { 678 return dce_aux_transfer_raw_with_ddc_pin(ddc, payload, operation_result); 679 } 680 } 681 } 682 683 int dce_aux_transfer_raw_with_ddc_pin(struct ddc_service *ddc, 684 struct aux_payload *payload, 685 enum aux_return_code_type *operation_result) 686 { 687 struct ddc *ddc_pin = ddc->ddc_pin; 688 struct dce_aux *aux_engine; 689 struct aux_request_transaction_data aux_req; 690 uint8_t returned_bytes = 0; 691 int res = -1; 692 uint32_t status; 693 694 memset(&aux_req, 0, sizeof(aux_req)); 695 696 if (ddc_pin == NULL) { 697 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE; 698 return -1; 699 } 700 701 aux_engine = ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]; 702 if (!acquire(aux_engine, ddc_pin)) { 703 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE; 704 return -1; 705 } 706 707 if (payload->i2c_over_aux) 708 aux_req.type = AUX_TRANSACTION_TYPE_I2C; 709 else 710 aux_req.type = AUX_TRANSACTION_TYPE_DP; 711 712 aux_req.action = i2caux_action_from_payload(payload); 713 714 aux_req.address = payload->address; 715 aux_req.delay = 0; 716 aux_req.length = payload->length; 717 aux_req.data = payload->data; 718 719 submit_channel_request(aux_engine, &aux_req); 720 *operation_result = get_channel_status(aux_engine, &returned_bytes); 721 722 if (*operation_result == AUX_RET_SUCCESS) { 723 int __maybe_unused bytes_replied = 0; 724 725 bytes_replied = read_channel_reply(aux_engine, payload->length, 726 payload->data, payload->reply, 727 &status); 728 EVENT_LOG_AUX_REP(aux_engine->ddc->pin_data->en, 729 EVENT_LOG_AUX_ORIGIN_NATIVE, *payload->reply, 730 bytes_replied, payload->data); 731 res = returned_bytes; 732 } else { 733 res = -1; 734 } 735 736 release_engine(aux_engine); 737 return res; 738 } 739 740 int dce_aux_transfer_raw_without_ddc_pin(struct ddc_service *ddc, 741 struct aux_payload *payload, 742 enum aux_return_code_type *operation_result) 743 { 744 struct ddc *ddc_pin = ddc->ddc_pin; 745 struct dce_aux *aux_engine; 746 struct aux_request_transaction_data aux_req; 747 uint8_t returned_bytes = 0; 748 int res = -1; 749 uint32_t status; 750 751 memset(&aux_req, 0, sizeof(aux_req)); 752 753 aux_engine = ddc->ctx->dc->res_pool->engines[ddc->link->aux_hw_inst]; 754 755 if (!acquire_aux_engine_without_ddc_pin(aux_engine, ddc_pin)) { 756 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE; 757 return -1; 758 } 759 760 if (payload->i2c_over_aux) 761 aux_req.type = AUX_TRANSACTION_TYPE_I2C; 762 else 763 aux_req.type = AUX_TRANSACTION_TYPE_DP; 764 765 aux_req.action = i2caux_action_from_payload(payload); 766 767 aux_req.address = payload->address; 768 aux_req.delay = 0; 769 aux_req.length = payload->length; 770 aux_req.data = payload->data; 771 772 submit_channel_request(aux_engine, &aux_req); 773 *operation_result = get_channel_status(aux_engine, &returned_bytes); 774 775 if (*operation_result == AUX_RET_SUCCESS) { 776 int __maybe_unused bytes_replied = 0; 777 778 bytes_replied = read_channel_reply(aux_engine, payload->length, 779 payload->data, payload->reply, 780 &status); 781 EVENT_LOG_AUX_REP(aux_engine->inst, 782 EVENT_LOG_AUX_ORIGIN_NATIVE, *payload->reply, 783 bytes_replied, payload->data); 784 res = returned_bytes; 785 } else { 786 res = -1; 787 } 788 789 release_engine(aux_engine); 790 return res; 791 } 792 793 int dce_aux_transfer_dmub_raw(struct ddc_service *ddc, 794 struct aux_payload *payload, 795 enum aux_return_code_type *operation_result) 796 { 797 struct ddc *ddc_pin = ddc->ddc_pin; 798 799 if (ddc_pin != NULL) { 800 struct dce_aux *aux_engine = ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]; 801 /* XXX: Workaround to configure ddc channels for aux transactions */ 802 if (!acquire(aux_engine, ddc_pin)) { 803 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE; 804 return -1; 805 } 806 release_engine(aux_engine); 807 } 808 809 if (ddc->link->force_to_use_aux) { 810 struct dce_aux *aux_engine = ddc->ctx->dc->res_pool->engines[ddc->link->aux_hw_inst]; 811 812 if (!acquire_aux_engine_without_ddc_pin(aux_engine, ddc_pin)) { 813 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE; 814 return -1; 815 } 816 release_engine(aux_engine); 817 } 818 819 return dm_helper_dmub_aux_transfer_sync(ddc->ctx, ddc->link, payload, operation_result); 820 } 821 822 #define AUX_MAX_RETRIES 7 823 #define AUX_MIN_DEFER_RETRIES 7 824 #define AUX_MAX_DEFER_TIMEOUT_MS 50 825 #define AUX_MAX_I2C_DEFER_RETRIES 7 826 #define AUX_MAX_INVALID_REPLY_RETRIES 2 827 #define AUX_MAX_TIMEOUT_RETRIES 3 828 #define AUX_DEFER_DELAY_FOR_DPIA 4 /*ms*/ 829 830 static void dce_aux_log_payload(const char *payload_name, 831 unsigned char *payload, uint32_t length, uint32_t max_length_to_log) 832 { 833 if (!IS_DC_I2CAUX_LOGGING_ENABLED()) 834 return; 835 836 if (payload && length) { 837 char hex_str[128] = {0}; 838 char *hex_str_ptr = &hex_str[0]; 839 uint32_t hex_str_remaining = sizeof(hex_str); 840 unsigned char *payload_ptr = payload; 841 unsigned char *payload_max_to_log_ptr = payload_ptr + min(max_length_to_log, length); 842 unsigned int count; 843 char *padding = ""; 844 845 while (payload_ptr < payload_max_to_log_ptr) { 846 count = snprintf_count(hex_str_ptr, hex_str_remaining, "%s%02X", padding, *payload_ptr); 847 padding = " "; 848 hex_str_remaining -= count; 849 hex_str_ptr += count; 850 payload_ptr++; 851 } 852 853 count = snprintf_count(hex_str_ptr, hex_str_remaining, " "); 854 hex_str_remaining -= count; 855 hex_str_ptr += count; 856 857 payload_ptr = payload; 858 while (payload_ptr < payload_max_to_log_ptr) { 859 count = snprintf_count(hex_str_ptr, hex_str_remaining, "%c", 860 *payload_ptr >= ' ' ? *payload_ptr : '.'); 861 hex_str_remaining -= count; 862 hex_str_ptr += count; 863 payload_ptr++; 864 } 865 866 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_VERBOSE, 867 LOG_FLAG_I2cAux_DceAux, 868 "dce_aux_log_payload: %s: length=%u: data: %s%s", 869 payload_name, 870 length, 871 hex_str, 872 (length > max_length_to_log ? " (...)" : " ")); 873 } else { 874 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_VERBOSE, 875 LOG_FLAG_I2cAux_DceAux, 876 "dce_aux_log_payload: %s: length=%u: data: <empty payload>", 877 payload_name, 878 length); 879 } 880 } 881 882 bool dce_aux_transfer_with_retries(struct ddc_service *ddc, 883 struct aux_payload *payload) 884 { 885 int i, ret = 0; 886 uint8_t reply; 887 bool payload_reply = true; 888 enum aux_return_code_type operation_result; 889 bool retry_on_defer = false; 890 struct ddc *ddc_pin = ddc->ddc_pin; 891 struct dce_aux *aux_engine = NULL; 892 struct aux_engine_dce110 *aux110 = NULL; 893 uint32_t defer_time_in_ms = 0; 894 895 int aux_ack_retries = 0, 896 aux_defer_retries = 0, 897 aux_i2c_defer_retries = 0, 898 aux_timeout_retries = 0, 899 aux_invalid_reply_retries = 0, 900 aux_ack_m_retries = 0; 901 902 if (ddc_pin) { 903 aux_engine = ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]; 904 aux110 = FROM_AUX_ENGINE(aux_engine); 905 } 906 907 if (ddc->link->force_to_use_aux) { 908 aux_engine = ddc->ctx->dc->res_pool->engines[ddc->link->aux_hw_inst]; 909 aux110 = FROM_AUX_ENGINE(aux_engine); 910 } 911 912 if (!payload->reply) { 913 payload_reply = false; 914 payload->reply = &reply; 915 } 916 917 for (i = 0; i < AUX_MAX_RETRIES; i++) { 918 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 919 LOG_FLAG_I2cAux_DceAux, 920 "dce_aux_transfer_with_retries: link_index=%u: START: retry %d of %d: " 921 "address=0x%04x length=%u write=%d mot=%d is_i2c=%d is_dpia=%d ddc_hw_inst=%d", 922 ddc && ddc->link ? ddc->link->link_index : UINT_MAX, 923 i + 1, 924 (int)AUX_MAX_RETRIES, 925 payload->address, 926 payload->length, 927 (unsigned int) payload->write, 928 (unsigned int) payload->mot, 929 payload->i2c_over_aux, 930 (ddc->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ? true : false, 931 ddc->link->ddc_hw_inst); 932 if (payload->write) 933 dce_aux_log_payload(" write", payload->data, payload->length, 16); 934 935 ret = dce_aux_transfer_raw(ddc, payload, &operation_result); 936 937 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 938 LOG_FLAG_I2cAux_DceAux, 939 "dce_aux_transfer_with_retries: link_index=%u: END: retry %d of %d: " 940 "address=0x%04x length=%u write=%d mot=%d: ret=%d operation_result=%d " 941 "payload->reply=%u is_i2c=%d is_dpia=%d ddc_hw_inst=%d", 942 ddc && ddc->link ? ddc->link->link_index : UINT_MAX, 943 i + 1, 944 (int)AUX_MAX_RETRIES, 945 payload->address, 946 payload->length, 947 (unsigned int) payload->write, 948 (unsigned int) payload->mot, 949 ret, 950 (int)operation_result, 951 (unsigned int) *payload->reply, 952 payload->i2c_over_aux, 953 (ddc->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ? true : false, 954 ddc->link->ddc_hw_inst); 955 if (!payload->write) 956 dce_aux_log_payload(" read", payload->data, ret > 0 ? ret : 0, 16); 957 958 switch (operation_result) { 959 case AUX_RET_SUCCESS: 960 aux_timeout_retries = 0; 961 aux_invalid_reply_retries = 0; 962 963 switch (*payload->reply) { 964 case AUX_TRANSACTION_REPLY_AUX_ACK: 965 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 966 LOG_FLAG_I2cAux_DceAux, 967 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_AUX_ACK"); 968 if (!payload->write && payload->length != ret) { 969 if (++aux_ack_retries >= AUX_MAX_RETRIES) { 970 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 971 LOG_FLAG_Error_I2cAux, 972 "dce_aux_transfer_with_retries: FAILURE: aux_ack_retries=%d >= AUX_MAX_RETRIES=%d", 973 aux_defer_retries, 974 AUX_MAX_RETRIES); 975 goto fail; 976 } else 977 udelay(300); 978 } else if (payload->write && ret > 0) { 979 /* sink requested more time to complete the write via AUX_ACKM */ 980 if (++aux_ack_m_retries >= AUX_MAX_RETRIES) { 981 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 982 LOG_FLAG_Error_I2cAux, 983 "dce_aux_transfer_with_retries: FAILURE: aux_ack_m_retries=%d >= AUX_MAX_RETRIES=%d", 984 aux_ack_m_retries, 985 AUX_MAX_RETRIES); 986 goto fail; 987 } 988 989 /* retry reading the write status until complete 990 * NOTE: payload is modified here 991 */ 992 payload->write = false; 993 payload->write_status_update = true; 994 payload->length = 0; 995 udelay(300); 996 } else 997 return true; 998 break; 999 1000 case AUX_TRANSACTION_REPLY_AUX_DEFER: 1001 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1002 LOG_FLAG_I2cAux_DceAux, 1003 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_AUX_DEFER"); 1004 1005 /* polling_timeout_period is in us */ 1006 if (aux110) 1007 defer_time_in_ms += aux110->polling_timeout_period / 1000; 1008 else 1009 defer_time_in_ms += AUX_DEFER_DELAY_FOR_DPIA; 1010 ++aux_defer_retries; 1011 fallthrough; 1012 case AUX_TRANSACTION_REPLY_I2C_OVER_AUX_DEFER: 1013 if (*payload->reply == AUX_TRANSACTION_REPLY_I2C_OVER_AUX_DEFER) 1014 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1015 LOG_FLAG_I2cAux_DceAux, 1016 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_I2C_OVER_AUX_DEFER"); 1017 1018 retry_on_defer = true; 1019 1020 if (aux_defer_retries >= AUX_MIN_DEFER_RETRIES 1021 && defer_time_in_ms >= AUX_MAX_DEFER_TIMEOUT_MS) { 1022 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1023 LOG_FLAG_Error_I2cAux, 1024 "dce_aux_transfer_with_retries: FAILURE: aux_defer_retries=%d >= AUX_MIN_DEFER_RETRIES=%d && defer_time_in_ms=%d >= AUX_MAX_DEFER_TIMEOUT_MS=%d", 1025 aux_defer_retries, 1026 AUX_MIN_DEFER_RETRIES, 1027 defer_time_in_ms, 1028 AUX_MAX_DEFER_TIMEOUT_MS); 1029 goto fail; 1030 } else { 1031 if ((*payload->reply == AUX_TRANSACTION_REPLY_AUX_DEFER) || 1032 (*payload->reply == AUX_TRANSACTION_REPLY_I2C_OVER_AUX_DEFER)) { 1033 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1034 LOG_FLAG_I2cAux_DceAux, 1035 "dce_aux_transfer_with_retries: payload->defer_delay=%u", 1036 payload->defer_delay); 1037 fsleep(payload->defer_delay * 1000); 1038 defer_time_in_ms += payload->defer_delay; 1039 } 1040 } 1041 break; 1042 case AUX_TRANSACTION_REPLY_I2C_OVER_AUX_NACK: 1043 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1044 LOG_FLAG_I2cAux_DceAux, 1045 "dce_aux_transfer_with_retries: FAILURE: AUX_TRANSACTION_REPLY_I2C_OVER_AUX_NACK"); 1046 goto fail; 1047 case AUX_TRANSACTION_REPLY_I2C_DEFER: 1048 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1049 LOG_FLAG_I2cAux_DceAux, 1050 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_I2C_DEFER"); 1051 1052 aux_defer_retries = 0; 1053 if (++aux_i2c_defer_retries >= AUX_MAX_I2C_DEFER_RETRIES) { 1054 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1055 LOG_FLAG_Error_I2cAux, 1056 "dce_aux_transfer_with_retries: FAILURE: aux_i2c_defer_retries=%d >= AUX_MAX_I2C_DEFER_RETRIES=%d", 1057 aux_i2c_defer_retries, 1058 AUX_MAX_I2C_DEFER_RETRIES); 1059 goto fail; 1060 } 1061 break; 1062 1063 case AUX_TRANSACTION_REPLY_AUX_NACK: 1064 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1065 LOG_FLAG_I2cAux_DceAux, 1066 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_AUX_NACK"); 1067 goto fail; 1068 1069 case AUX_TRANSACTION_REPLY_HPD_DISCON: 1070 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1071 LOG_FLAG_I2cAux_DceAux, 1072 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: AUX_TRANSACTION_REPLY_HPD_DISCON"); 1073 goto fail; 1074 1075 default: 1076 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1077 LOG_FLAG_Error_I2cAux, 1078 "dce_aux_transfer_with_retries: AUX_RET_SUCCESS: FAILURE: AUX_TRANSACTION_REPLY_* unknown, default case. Reply: %d", *payload->reply); 1079 goto fail; 1080 } 1081 break; 1082 1083 case AUX_RET_ERROR_INVALID_REPLY: 1084 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1085 LOG_FLAG_I2cAux_DceAux, 1086 "dce_aux_transfer_with_retries: AUX_RET_ERROR_INVALID_REPLY"); 1087 if (++aux_invalid_reply_retries >= AUX_MAX_INVALID_REPLY_RETRIES) { 1088 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1089 LOG_FLAG_Error_I2cAux, 1090 "dce_aux_transfer_with_retries: FAILURE: aux_invalid_reply_retries=%d >= AUX_MAX_INVALID_REPLY_RETRIES=%d", 1091 aux_invalid_reply_retries, 1092 AUX_MAX_INVALID_REPLY_RETRIES); 1093 goto fail; 1094 } else 1095 udelay(400); 1096 break; 1097 1098 case AUX_RET_ERROR_TIMEOUT: 1099 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1100 LOG_FLAG_I2cAux_DceAux, 1101 "dce_aux_transfer_with_retries: AUX_RET_ERROR_TIMEOUT"); 1102 // Check whether a DEFER had occurred before the timeout. 1103 // If so, treat timeout as a DEFER. 1104 if (retry_on_defer) { 1105 if (++aux_defer_retries >= AUX_MIN_DEFER_RETRIES) { 1106 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1107 LOG_FLAG_Error_I2cAux, 1108 "dce_aux_transfer_with_retries: FAILURE: aux_defer_retries=%d >= AUX_MIN_DEFER_RETRIES=%d", 1109 aux_defer_retries, 1110 AUX_MIN_DEFER_RETRIES); 1111 goto fail; 1112 } else if (payload->defer_delay > 0) { 1113 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION, 1114 LOG_FLAG_I2cAux_DceAux, 1115 "dce_aux_transfer_with_retries: payload->defer_delay=%u", 1116 payload->defer_delay); 1117 msleep(payload->defer_delay); 1118 } 1119 } else { 1120 if (++aux_timeout_retries >= AUX_MAX_TIMEOUT_RETRIES) { 1121 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1122 LOG_FLAG_Error_I2cAux, 1123 "dce_aux_transfer_with_retries: FAILURE: aux_timeout_retries=%d >= AUX_MAX_TIMEOUT_RETRIES=%d", 1124 aux_timeout_retries, 1125 AUX_MAX_TIMEOUT_RETRIES); 1126 goto fail; 1127 } else { 1128 /* 1129 * DP 1.4, 2.8.2: AUX Transaction Response/Reply Timeouts 1130 * According to the DP spec there should be 3 retries total 1131 * with a 400us wait inbetween each. Hardware already waits 1132 * for 550us therefore no wait is required here. 1133 */ 1134 } 1135 } 1136 break; 1137 1138 case AUX_RET_ERROR_HPD_DISCON: 1139 case AUX_RET_ERROR_ENGINE_ACQUIRE: 1140 case AUX_RET_ERROR_UNKNOWN: 1141 default: 1142 goto fail; 1143 } 1144 } 1145 1146 fail: 1147 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_ERROR, 1148 LOG_FLAG_Error_I2cAux, 1149 "%s: Failure: operation_result=%d", 1150 __func__, 1151 (int)operation_result); 1152 if (!payload_reply) 1153 payload->reply = NULL; 1154 1155 return false; 1156 } 1157